Files
t3code/packages/client-runtime/src/state/threadCommands.ts
T
Theo BrowneandClaude Fable 5 ad171b3f42 Add workflow run visibility: live agent tree, script view, transcripts
Surface Claude Agent SDK workflow runs (the Workflow orchestration tool)
end to end in the desktop app:

- Contracts: WorkflowProgressEntry schemas, run handles, workflow
  inspection RPCs, thread.task.stop command + task-stop-requested event
- ClaudeAdapter: normalize the SDK's undocumented workflow_progress
  snapshot (size-capped, tolerant), forward workflow identity on task
  events, emit task.workflowMeta from Workflow tool results, stopTask
- Ingestion: upsert workflow snapshots under a stable per-task activity
  id so projections and reconnect payloads stay one row per run
- WorkflowInspectionService: path-validated, size-capped reads of the
  run's script, journal, and per-agent transcripts (realpath containment
  under ~/.claude/projects)
- Web: WorkflowRunCard inline in the chat timeline, a workflow right-
  panel surface with Run/Script/Logs tabs, cursor-paged transcript
  polling, stop + resume affordances; remote runs link to their cloud
  session

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-07-02 03:26:48 -07:00

150 lines
5.1 KiB
TypeScript

import * as Crypto from "effect/Crypto";
import { Atom } from "effect/unstable/reactivity";
import { createAtomCommandScheduler, createEnvironmentCommand } from "./runtime.ts";
import {
type ArchiveThreadInput,
type CreateThreadInput,
type DeleteThreadInput,
type InterruptThreadTurnInput,
type RespondToThreadApprovalInput,
type RespondToThreadUserInputInput,
type RevertThreadCheckpointInput,
type SetThreadInteractionModeInput,
type SetThreadRuntimeModeInput,
type StartThreadTurnInput,
type StopThreadSessionInput,
type StopThreadTaskInput,
type UnarchiveThreadInput,
type UpdateThreadMetadataInput,
archiveThread,
createThread,
deleteThread,
interruptThreadTurn,
stopThreadTask,
respondToThreadApproval,
respondToThreadUserInput,
revertThreadCheckpoint,
setThreadInteractionMode,
setThreadRuntimeMode,
startThreadTurn,
stopThreadSession,
unarchiveThread,
updateThreadMetadata,
} from "../operations/commands.ts";
import type { EnvironmentRegistry } from "../connection/registry.ts";
export type {
ArchiveThreadInput,
CreateThreadInput,
DeleteThreadInput,
InterruptThreadTurnInput,
RespondToThreadApprovalInput,
RespondToThreadUserInputInput,
RevertThreadCheckpointInput,
SetThreadInteractionModeInput,
SetThreadRuntimeModeInput,
StartThreadTurnInput,
StopThreadSessionInput,
StopThreadTaskInput,
UnarchiveThreadInput,
UpdateThreadMetadataInput,
} from "../operations/commands.ts";
export function createThreadEnvironmentAtoms<R, E>(
runtime: Atom.AtomRuntime<EnvironmentRegistry | Crypto.Crypto | R, E>,
) {
const scheduler = createAtomCommandScheduler();
const concurrency = {
mode: "serial" as const,
key: ({ environmentId, input }: { environmentId: string; input: { threadId: string } }) =>
JSON.stringify([environmentId, input.threadId]),
};
return {
create: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:create",
execute: (input: CreateThreadInput) => createThread(input),
scheduler,
concurrency,
}),
delete: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:delete",
execute: (input: DeleteThreadInput) => deleteThread(input),
scheduler,
concurrency,
}),
archive: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:archive",
execute: (input: ArchiveThreadInput) => archiveThread(input),
scheduler,
concurrency,
}),
unarchive: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:unarchive",
execute: (input: UnarchiveThreadInput) => unarchiveThread(input),
scheduler,
concurrency,
}),
updateMetadata: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:update-metadata",
execute: (input: UpdateThreadMetadataInput) => updateThreadMetadata(input),
scheduler,
concurrency,
}),
setRuntimeMode: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:set-runtime-mode",
execute: (input: SetThreadRuntimeModeInput) => setThreadRuntimeMode(input),
scheduler,
concurrency,
}),
setInteractionMode: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:set-interaction-mode",
execute: (input: SetThreadInteractionModeInput) => setThreadInteractionMode(input),
scheduler,
concurrency,
}),
startTurn: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:start-turn",
execute: (input: StartThreadTurnInput) => startThreadTurn(input),
scheduler,
concurrency,
}),
interruptTurn: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:interrupt-turn",
execute: (input: InterruptThreadTurnInput) => interruptThreadTurn(input),
scheduler,
concurrency,
}),
respondToApproval: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:respond-to-approval",
execute: (input: RespondToThreadApprovalInput) => respondToThreadApproval(input),
scheduler,
concurrency,
}),
respondToUserInput: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:respond-to-user-input",
execute: (input: RespondToThreadUserInputInput) => respondToThreadUserInput(input),
scheduler,
concurrency,
}),
revertCheckpoint: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:revert-checkpoint",
execute: (input: RevertThreadCheckpointInput) => revertThreadCheckpoint(input),
scheduler,
concurrency,
}),
stopSession: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:stop-session",
execute: (input: StopThreadSessionInput) => stopThreadSession(input),
scheduler,
concurrency,
}),
stopTask: createEnvironmentCommand(runtime, {
label: "environment-data:commands:thread:stop-task",
execute: (input: StopThreadTaskInput) => stopThreadTask(input),
scheduler,
concurrency,
}),
};
}