Files
Codeman/src/types/tools.ts
T
Codeman maintainer cbc54fc98d feat(files): play video and audio from outside the workspace too
A clip an agent wrote inside the workspace played with a working scrub bar,
while the same file in /tmp was refused as an unsupported type. The workspace
preview classified media with its own inline extension sets and the attachment
allowlist had no media at all, so the two paths disagreed about what a video is.

- VIDEO_ATTACHMENT_EXTENSIONS and AUDIO_ATTACHMENT_EXTENSIONS now live in
  attachment-registry.ts and are imported by file-content's classification, so
  both paths answer the same. mp4/webm/mov/m4v/ogv and
  mp3/wav/ogg/oga/m4a/aac/flac/opus join the attachment allowlist.
- Real MIME types for those extensions. Without one the raw route falls back to
  application/octet-stream, which a <video> refuses to decode: the player
  renders and then does nothing.
- getAttachmentType() gained the video and audio members of
  AttachmentDetectedType. Attachment cards have no per-type CSS and their
  thumbnail falls back to the type label, since the thumbnailer has no media
  branch and answers 204 rather than spawning a converter.
- The preview overlay's by-id branch renders <video>/<audio> with the same
  markup as the workspace branch, playsinline included. Serving was already
  range-aware, so seeking works.

The image-watcher keeps its own narrow detection list (png/pdf/docx/pptx), so
this does not start popping cards for every video an agent writes. Text types
that are not md or txt (.json, .log, code files) remain out of the allowlist by
choice and still report what is previewable instead.

Verified on an isolated instance: an external mp4 and mp3 both play, seek, and
report the right duration, matching the in-workspace clip exactly, and a click
on an external mp4 in the terminal opens the player with no attachment card.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-16 17:35:43 +02:00

108 lines
3.5 KiB
TypeScript

/**
* @fileoverview Tool-related type definitions.
*
* Types for tracking Claude's tool invocations in real-time.
*
* Key exports:
* - ActiveBashTool — a live bash command with extracted file paths and status
* - ActiveBashToolStatus — 'running' | 'completed'
* - ImageDetectedEvent — screenshot/image file detection trigger for UI popup
* - AttachmentDetectedEvent — document/image file detection trigger for attachment cards
*
* Cross-domain relationships:
* - ActiveBashTool.sessionId links to SessionState.id (session domain)
* - ImageDetectedEvent.sessionId links to SessionState.id (session domain)
*
* Both types are in-memory only (not persisted). Broadcast via SSE events
* `subagent:tool_call`, `image:detected`, and `attachment:detected`. Parsed by BashToolParser
* (`src/bash-tool-parser.ts`).
*/
/**
* Status of an active Bash tool command.
*/
export type ActiveBashToolStatus = 'running' | 'completed';
/**
* Represents an active Bash tool command detected in Claude's output.
* Used to display clickable file paths for file-viewing commands.
*/
export interface ActiveBashTool {
/** Unique identifier for this tool invocation */
id: string;
/** The full command being executed */
command: string;
/** Extracted file paths from the command (clickable) */
filePaths: string[];
/** Timeout string if specified (e.g., "16m 0s") */
timeout?: string;
/** Timestamp when the tool started */
startedAt: number;
/** Current status */
status: ActiveBashToolStatus;
/** Session ID this tool belongs to */
sessionId: string;
}
/**
* Event emitted when a new image file is detected in a session's working directory.
* Used to trigger automatic image popup display in the web UI.
*/
export interface ImageDetectedEvent {
/** Codeman session ID where the image was detected */
sessionId: string;
/** Full path to the detected image file */
filePath: string;
/** Path relative to the session's working directory (for file-raw endpoint) */
relativePath: string;
/** Image file name (basename) */
fileName: string;
/** Timestamp when the image was detected */
timestamp: number;
/** File size in bytes */
size: number;
}
export type AttachmentDetectedType =
| 'image'
| 'video'
| 'audio'
| 'pdf'
| 'document'
| 'presentation'
| 'markdown'
| 'text';
/**
* Event emitted when a new previewable attachment file is detected in a session's
* working directory. Used to render a compact attachment card in the web UI.
*/
export interface AttachmentDetectedEvent {
/** Codeman session ID where the attachment was detected */
sessionId: string;
/** Full path to the detected attachment file */
filePath: string;
/** Path relative to the session's working directory (for file-raw/file-preview endpoints) */
relativePath: string;
/** Attachment file name (basename) */
fileName: string;
/** Lowercase extension without a leading dot */
extension: string;
/** Viewer category used by the web UI */
attachmentType: AttachmentDetectedType;
/** Timestamp when the attachment was detected */
timestamp: number;
/** File size in bytes */
size: number;
/** Registered attachment id for explicit live external attachments */
attachmentId?: string;
/** Source of the attachment card request */
source?: 'detected' | 'external';
/** Raw file route for explicit attachments */
rawUrl?: string;
/** Inline preview route for explicit attachments */
previewUrl?: string;
/** First-page thumbnail route for card previews */
thumbnailUrl?: string;
}