Files
Codeman/test/claude-conversation-report-docker.test.ts
T
Michael GrundbergandClaude Opus 5.5 c6fff5e6a8 feat(web): a chat view shows a Claude session's conversation, rendered and live
A local or Docker Claude session can show its conversation as rendered text,
the way the Response Viewer draws it, in place of the terminal. The terminal
stays attached and sized underneath, so switching views never resizes the pane,
and the user still types in the terminal. Discussion #858 has the background.

- A Chat / Terminal switch and Alt+Shift+C change the view, and each session
  remembers its choice on this device until the session is gone. Two per-device
  settings pick the default view and hide the switch. Phones, remote and
  adopted sessions keep the terminal.
- The server broadcasts `transcript:update`, at most one per 750 ms per session,
  and the view re-reads the conversation on it, so an answer fills in mid-turn.
- The server keeps each transcript's parse and the byte offset it reached, so a
  read parses only the bytes appended since the last one, in chunks with an await
  between them. Overlapping reads of one file share one pass. The Response
  Viewer and the Discord bridge read through it too.
- A full conversation read starts a transcript watcher for a session that has
  none, such as one picked up after a server restart.
- A Docker session's hook reports the container's transcript path, and the
  server watches the host's copy of that file.
- After `/clear`, Claude Code runs the statusline command with the new
  conversation's id and transcript path. The statusline exporter posts them, and
  the server follows the new conversation the way it follows a hook's report.
- Keep-warm turns are hidden, long prompts fold, a "Working" line shows the turn's
  running time, and a pending dialog shows a notice that opens the terminal.

The design note, docs/chat-view-plan.md, covers this and the four steps that
follow it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 10:18:29 +01:00

52 lines
2.4 KiB
TypeScript

/**
* @fileoverview A Docker session's reported transcript path is watched on the host
* (src/web/claude-conversation-report.ts).
*
* Claude in a Docker case runs with `HOME=/home/agent`, so a hook or the statusline reports a
* transcript under `/home/agent/.claude/projects`, which does not exist on the host. The case
* mounts the host's `~/.claude/projects` there, so the watcher must follow the host's copy.
*/
import { homedir } from 'node:os';
import { join } from 'node:path';
import { describe, expect, it, vi } from 'vitest';
import { hostTranscriptPath, noteClaudeConversationReport } from '../src/web/claude-conversation-report.js';
import { CONTAINER_CLAUDE_DIR } from '../src/docker-hosts.js';
import type { Session } from '../src/session.js';
const docker = { docker: { containerName: 'codeman-case' } } as unknown as Pick<Session, 'docker'>;
const reported = `${CONTAINER_CLAUDE_DIR}/projects/-workspace-app/abc.jsonl`;
describe('hostTranscriptPath', () => {
it("maps a Docker session's container path into the host's projects folder", () => {
expect(hostTranscriptPath(docker, reported)).toBe(
join(homedir(), '.claude', 'projects', '-workspace-app', 'abc.jsonl')
);
});
it('leaves a local session, a path outside the projects folder and a path with `..` as reported', () => {
expect(hostTranscriptPath({ docker: undefined }, reported)).toBe(reported);
expect(hostTranscriptPath(undefined, reported)).toBe(reported);
expect(hostTranscriptPath(docker, '/home/agent/elsewhere/abc.jsonl')).toBe('/home/agent/elsewhere/abc.jsonl');
const escape = `${CONTAINER_CLAUDE_DIR}/projects/../../.ssh/id_rsa`;
expect(hostTranscriptPath(docker, escape)).toBe(escape);
});
});
describe('noteClaudeConversationReport', () => {
it("starts a Docker session's watcher on the host path", () => {
const startTranscriptWatcher = vi.fn();
const session = { ...docker, claudeSessionChain: [], adoptClaudeSessionId: vi.fn() };
const ctx = {
sessions: new Map([['s1', session]]),
startTranscriptWatcher,
persistSessionState: vi.fn(),
} as unknown as Parameters<typeof noteClaudeConversationReport>[0];
noteClaudeConversationReport(ctx, 's1', { transcript_path: reported });
expect(startTranscriptWatcher).toHaveBeenCalledWith(
's1',
join(homedir(), '.claude', 'projects', '-workspace-app', 'abc.jsonl')
);
});
});