@norman-else/dsh-claude 0.1.38 → 0.1.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.mjs +86 -47
- package/lib/index.mjs.map +1 -1
- package/package.json +1 -1
package/lib/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["record","string","record","string","record","claudeQuery","query","claudeQuery","MAX_TEXT_CHARS","MAX_PATH_CHARS","safeMessage","MAX_SESSION_ID_CHARS","MAX_OUTPUT_BYTES","GIT_TIMEOUT_MS","GH_TIMEOUT_MS","collect","record","MAX_REPLY_CHARS","claudeQuery","MAX_OUTPUT_BYTES","GIT_TIMEOUT_MS","MAX_PATH_CHARS","collect","MAX_OUTPUT_BYTES","GIT_TIMEOUT_MS","collect","MAX_BODY_BYTES","record","readJson","string","optionalString","ndjson","MAX_BODY_BYTES","MAX_SESSION_ID_CHARS","record","readJson","sessionId","string","MAX_OUTPUT_BYTES","MAX_SESSION_ID_CHARS","MAX_REPLY_CHARS","record","MAX_SESSION_ID_CHARS","MAX_BODY_BYTES","record","readJson","MAX_PATH_CHARS","record","MAX_BODY_BYTES","record","readJson","record","MAX_BODY_BYTES","MAX_SESSION_ID_CHARS","record","MAX_BODY_BYTES","MAX_SESSION_ID_CHARS","record","readJson","safeMessage"],"sources":["../src/rewind.ts","../src/sidecar.ts","../src/async-queue.ts","../src/permission.ts","../src/user-question.ts","../src/sdk-messages.ts","../src/plan-usage.ts","../src/spawn.ts","../src/supervisor.ts","../src/review-comments.ts","../src/adapter.ts","../src/plugin-budget.ts","../src/http.ts","../src/doctor-routes.ts","../src/projection-routes.ts","../src/repository-status.ts","../src/branch-name.ts","../src/repository-setup.ts","../src/repository-actions.ts","../src/repository-setup-routes.ts","../src/repository-action-routes.ts","../src/editor-open.ts","../src/editor-open-routes.ts","../src/github-url.ts","../src/pr-feedback.ts","../src/pr-feedback-routes.ts","../src/repository-status-routes.ts","../src/repository-file-routes.ts","../src/jira.ts","../src/jira-routes.ts","../src/ask.ts","../src/ask-routes.ts","../src/review-comment-routes.ts","../src/client-diagnostics-routes.ts","../src/rewind-routes.ts","../src/update-routes.ts","../src/plan-usage-routes.ts","../src/global-settings.ts","../src/index.ts"],"sourcesContent":["/** Rewind: drop one user message and everything after it.\n *\n * Two halves, because the two sides of a Claude session are owned by\n * different processes:\n *\n * - Claude's own transcript is rewound for real. Every completed DSH turn\n * records the last chain-entry uuid Claude emitted for it, so the next\n * spawn resumes at the kept turn's anchor (`resumeSessionAt`) and the model\n * genuinely forgets the discarded turns.\n * - The DSH session log is append-only and the Host renders every event it\n * holds — even compaction keeps the shadowed conversation on screen — so the\n * discarded rows are recorded here as hidden seq ranges and suppressed by\n * the browser instead of deleted.\n */\nimport type { SessionEvent } from '@deepseek-ai/dsh-session'\n\n/** One inclusive span of hidden surface seqs. */\nexport interface ClaudeRewindRange {\n readonly start: number\n readonly end: number\n}\n\n/** The last Claude chain entry of one completed DSH turn. */\nexport interface ClaudeRewindAnchor {\n readonly turn: number\n readonly uuid: string\n}\n\n/** Fork target for the next Claude spawn; `fresh` starts an empty session. */\nexport type ClaudeRewindResume = { readonly resumeAt: string } | { readonly fresh: true }\n\nexport interface ClaudeRewindState {\n /** Hidden seq ranges, ascending and non-overlapping. */\n readonly ranges: readonly ClaudeRewindRange[]\n /** Chain anchors of the turns Claude still holds, ascending by turn. */\n readonly anchors: readonly ClaudeRewindAnchor[]\n /** Armed once by a rewind, consumed by the next Claude spawn. */\n readonly pending?: ClaudeRewindResume\n}\n\nexport const EMPTY_REWIND_STATE: ClaudeRewindState = { ranges: [], anchors: [] }\n\n/** Sessions outlive their rewinds; both lists stay bounded. */\nexport const MAX_REWIND_RANGES = 200\nexport const MAX_REWIND_ANCHORS = 2_000\n\n/** Absorb one span into an ascending, non-overlapping range list. Adjacent\n * spans merge so a rewind of a rewind reads as one hidden block. */\nexport function mergeRewindRanges(\n ranges: readonly ClaudeRewindRange[],\n addition: ClaudeRewindRange,\n): ClaudeRewindRange[] {\n const merged: ClaudeRewindRange[] = []\n let { start, end } = addition\n for (const range of [...ranges].sort((left, right) => left.start - right.start)) {\n if (range.end + 1 < start) merged.push(range)\n else if (range.start > end + 1) {\n merged.push({ start, end })\n start = range.start\n end = range.end\n } else {\n start = Math.min(start, range.start)\n end = Math.max(end, range.end)\n }\n }\n merged.push({ start, end })\n return merged.slice(-MAX_REWIND_RANGES)\n}\n\nexport function isRewound(ranges: readonly ClaudeRewindRange[], seq: number): boolean {\n return ranges.some(range => seq >= range.start && seq <= range.end)\n}\n\n/** Record one completed turn's last chain entry, replacing a re-run turn. */\nexport function recordRewindAnchor(\n state: ClaudeRewindState,\n anchor: ClaudeRewindAnchor,\n): ClaudeRewindState {\n const anchors = [...state.anchors.filter(item => item.turn !== anchor.turn), anchor]\n .sort((left, right) => left.turn - right.turn)\n .slice(-MAX_REWIND_ANCHORS)\n return { ...state, anchors }\n}\n\n/** The turn a surface seq belongs to: the first turn opened at or after it.\n * A message accepted but never run belongs to no logged turn, so nothing\n * Claude holds is discarded and every anchor stays valid. */\nexport function turnAtOrAfter(events: readonly SessionEvent[], seq: number): number | undefined {\n for (const event of events) {\n if (event.seq >= seq && event.type === 'turn/start') return event.data.turn\n }\n return undefined\n}\n\n/** Plan one rewind at `seq`, or undefined when the seq is not in the log.\n * Anchors of the discarded turns go with them: after this rewind Claude no\n * longer holds those entries, so a later rewind must never fork at one. */\nexport function planRewind(\n state: ClaudeRewindState,\n events: readonly SessionEvent[],\n seq: number,\n): ClaudeRewindState | undefined {\n const last = events.at(-1)?.seq\n if (last === undefined || seq > last) return undefined\n const turn = turnAtOrAfter(events, seq) ?? Number.MAX_SAFE_INTEGER\n const anchors = state.anchors.filter(anchor => anchor.turn < turn)\n const kept = anchors.at(-1)\n return {\n ranges: mergeRewindRanges(state.ranges, { start: seq, end: last }),\n anchors,\n pending: kept === undefined ? { fresh: true } : { resumeAt: kept.uuid },\n }\n}\n","import { randomUUID } from 'node:crypto'\nimport { chmod, mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises'\nimport { join } from 'node:path'\nimport { dshHomePath } from '@deepseek-ai/dsh-home-paths'\nimport type { SessionEvent } from '@deepseek-ai/dsh-session'\nimport {\n latestClaudeContextUsage,\n latestClaudeSessionBinding,\n latestClaudeTasks,\n normalizeActivity,\n normalizeContextUsage,\n normalizeTasksEvent,\n redactText,\n type ClaudeActivityEvent,\n type ClaudeActivityInput,\n type ClaudeContextUsageEvent,\n type ClaudeContextUsageInput,\n type ClaudeSessionBoundEvent,\n type ClaudeTaskInfo,\n type ClaudeTasksEvent,\n} from './events.ts'\nimport { CLAUDE_ACTIVITY_EVENT, SDK_VERSION, type ClaudeRenderMode } from './constants.ts'\nimport {\n EMPTY_REWIND_STATE,\n MAX_REWIND_ANCHORS,\n MAX_REWIND_RANGES,\n recordRewindAnchor,\n type ClaudeRewindAnchor,\n type ClaudeRewindRange,\n type ClaudeRewindState,\n} from './rewind.ts'\n\nconst SIDECAR_SCHEMA_VERSION = 1\nconst MAX_ACTIVITIES = 10_000\n/** Trailing window that coalesces per-token transcript persistence into one\n * atomic disk write; live subscribers are notified synchronously regardless. */\nconst TEXT_FLUSH_MS = 150\n\nexport interface ClaudeSidecarProjection {\n readonly schemaVersion: typeof SIDECAR_SCHEMA_VERSION\n readonly revision: number\n readonly binding?: ClaudeSessionBoundEvent\n readonly activities: readonly ClaudeActivityEvent[]\n readonly contextUsage?: ClaudeContextUsageEvent\n readonly tasks?: ClaudeTasksEvent\n readonly rewind?: ClaudeRewindState\n}\n\n/** Change notification published to live subscribers after each accepted write.\n *\n * `checkpoint` is the one kind that carries no change: it restates where the\n * stream stands so a reader can notice it is behind. See {@link ClaudeSidecarRepository.checkpoint}. */\nexport type ClaudeSidecarDelta =\n | { kind: 'text'; turn: number; step: number; ordinal: number; append?: string; text?: string; renderer?: ClaudeRenderMode }\n | { kind: 'activity'; activity: ClaudeActivityEvent }\n | { kind: 'contextUsage'; value: ClaudeContextUsageEvent }\n | { kind: 'tasks'; value: ClaudeTasksEvent }\n | { kind: 'sync' }\n | { kind: 'checkpoint' }\n\n/** One delta as subscribers see it: numbered, so a reader that applies them in\n * order can tell a missing one from a slow one.\n *\n * The projection's own `revision` cannot do this job. Streaming prose notifies\n * subscribers without touching disk (see {@link ClaudeSidecarRepository.appendTranscriptText}),\n * so revisions and notifications advance on different clocks; this counter\n * advances once per notification and nothing else reads it. */\nexport type ClaudeSidecarNotification = ClaudeSidecarDelta & { readonly seq: number }\n\nexport interface ClaudeSidecarRepositoryOptions {\n readonly root?: string\n readonly legacyRoot?: string\n}\n\nfunction emptyProjection(): ClaudeSidecarProjection {\n return { schemaVersion: SIDECAR_SCHEMA_VERSION, revision: 0, activities: [] }\n}\n\nfunction record(value: unknown): Record<string, unknown> | undefined {\n return value !== null && typeof value === 'object' && !Array.isArray(value)\n ? value as Record<string, unknown>\n : undefined\n}\n\nfunction finiteInteger(value: unknown): value is number {\n return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0\n}\n\nfunction string(value: unknown, max: number): value is string {\n return typeof value === 'string' && value.length > 0 && value.length <= max\n}\n\nfunction binding(value: unknown): ClaudeSessionBoundEvent | undefined {\n const input = record(value)\n if (input === undefined\n || !string(input.claudeSessionId, 512)\n || !string(input.sdkVersion, 128)\n || !string(input.cwd, 4_096)\n || (input.cliVersion !== undefined && !string(input.cliVersion, 128))) return undefined\n return {\n claudeSessionId: input.claudeSessionId,\n sdkVersion: input.sdkVersion,\n cwd: input.cwd,\n ...(input.cliVersion === undefined ? {} : { cliVersion: input.cliVersion }),\n }\n}\n\nconst ACTIVITY_KINDS = new Set(['text', 'status', 'compaction', 'thinking', 'tool-call', 'tool-result', 'permission', 'question', 'subagent', 'usage', 'warning', 'error'])\nconst ACTIVITY_PHASES = new Set(['started', 'updated', 'completed', 'denied', 'failed'])\n\nfunction activity(value: unknown): ClaudeActivityEvent | undefined {\n const input = record(value)\n if (input === undefined\n || !finiteInteger(input.turn)\n || !finiteInteger(input.step)\n || !finiteInteger(input.ordinal)\n || typeof input.kind !== 'string'\n || !ACTIVITY_KINDS.has(input.kind)\n || (input.phase !== undefined && (typeof input.phase !== 'string' || !ACTIVITY_PHASES.has(input.phase)))) return undefined\n return normalizeActivity(input as unknown as ClaudeActivityEvent)\n}\n\nfunction contextUsage(value: unknown): ClaudeContextUsageEvent | undefined {\n const input = record(value)\n if (input === undefined || !Array.isArray(input.categories)) return undefined\n return normalizeContextUsage(input as unknown as ClaudeContextUsageInput)\n}\n\nfunction rewind(value: unknown): ClaudeRewindState | undefined {\n const input = record(value)\n if (input === undefined\n || !Array.isArray(input.ranges) || input.ranges.length > MAX_REWIND_RANGES\n || !Array.isArray(input.anchors) || input.anchors.length > MAX_REWIND_ANCHORS) return undefined\n const ranges: ClaudeRewindRange[] = []\n for (const item of input.ranges) {\n const range = record(item)\n if (range === undefined || !finiteInteger(range.start) || !finiteInteger(range.end) || range.end < range.start) return undefined\n ranges.push({ start: range.start, end: range.end })\n }\n const anchors: ClaudeRewindAnchor[] = []\n for (const item of input.anchors) {\n const anchor = record(item)\n if (anchor === undefined || !finiteInteger(anchor.turn) || !string(anchor.uuid, 128)) return undefined\n anchors.push({ turn: anchor.turn, uuid: anchor.uuid })\n }\n const pending = record(input.pending)\n if (input.pending !== undefined && pending === undefined) return undefined\n if (pending === undefined) return { ranges, anchors }\n if (pending.fresh === true) return { ranges, anchors, pending: { fresh: true } }\n if (!string(pending.resumeAt, 128)) return undefined\n return { ranges, anchors, pending: { resumeAt: pending.resumeAt } }\n}\n\nfunction tasks(value: unknown): ClaudeTasksEvent | undefined {\n const input = record(value)\n if (input === undefined || !Array.isArray(input.tasks)) return undefined\n return normalizeTasksEvent(input.tasks as ClaudeTaskInfo[])\n}\n\nexport function parseClaudeSidecar(value: unknown): ClaudeSidecarProjection {\n const input = record(value)\n if (input === undefined\n || input.schemaVersion !== SIDECAR_SCHEMA_VERSION\n || !finiteInteger(input.revision)\n || !Array.isArray(input.activities)\n || input.activities.length > MAX_ACTIVITIES) {\n throw new Error('dsh-claude: invalid sidecar document')\n }\n const activities = input.activities.map(activity)\n if (activities.some(item => item === undefined)) throw new Error('dsh-claude: invalid sidecar activity')\n const parsedBinding = input.binding === undefined ? undefined : binding(input.binding)\n const parsedUsage = input.contextUsage === undefined ? undefined : contextUsage(input.contextUsage)\n const parsedTasks = input.tasks === undefined ? undefined : tasks(input.tasks)\n const parsedRewind = input.rewind === undefined ? undefined : rewind(input.rewind)\n if ((input.binding !== undefined && parsedBinding === undefined)\n || (input.contextUsage !== undefined && parsedUsage === undefined)\n || (input.tasks !== undefined && parsedTasks === undefined)\n || (input.rewind !== undefined && parsedRewind === undefined)) {\n throw new Error('dsh-claude: invalid sidecar projection')\n }\n return {\n schemaVersion: SIDECAR_SCHEMA_VERSION,\n revision: input.revision,\n activities: activities as ClaudeActivityEvent[],\n ...(parsedBinding === undefined ? {} : { binding: parsedBinding }),\n ...(parsedUsage === undefined ? {} : { contextUsage: parsedUsage }),\n ...(parsedTasks === undefined ? {} : { tasks: parsedTasks }),\n ...(parsedRewind === undefined ? {} : { rewind: parsedRewind }),\n }\n}\n\nfunction compareActivity(left: ClaudeActivityEvent, right: ClaudeActivityEvent): number {\n return left.turn - right.turn || left.step - right.step || left.ordinal - right.ordinal\n}\n\nfunction activityKey(value: ClaudeActivityEvent): string {\n return `${value.turn}:${value.step}:${value.ordinal}`\n}\n\nfunction mergeActivities(\n existing: readonly ClaudeActivityEvent[],\n additions: readonly ClaudeActivityEvent[],\n): ClaudeActivityEvent[] {\n const merged = new Map(existing.map(item => [activityKey(item), item]))\n for (const item of additions) merged.set(activityKey(item), item)\n return [...merged.values()].sort(compareActivity).slice(-MAX_ACTIVITIES)\n}\n\nfunction normalizeBinding(\n input: Omit<ClaudeSessionBoundEvent, 'sdkVersion'> & { sdkVersion?: string },\n): ClaudeSessionBoundEvent {\n return {\n claudeSessionId: redactText(input.claudeSessionId, 512),\n sdkVersion: redactText(input.sdkVersion ?? SDK_VERSION, 128),\n cwd: redactText(input.cwd, 4_096),\n ...(input.cliVersion === undefined ? {} : { cliVersion: redactText(input.cliVersion, 128) }),\n }\n}\n\nexport class ClaudeSidecarRepository {\n readonly root: string\n readonly legacyRoot: string | undefined\n readonly #pending = new Map<string, Promise<unknown>>()\n /** Latest durable projection per session; disk is read once and written through. */\n readonly #latest = new Map<string, ClaudeSidecarProjection>()\n readonly #listeners = new Map<string, Set<(delta: ClaudeSidecarNotification) => void>>()\n /** Notifications published per session, so a reader can spot a hole. */\n readonly #seq = new Map<string, number>()\n /** Streaming transcript segments not yet persisted, keyed by activity key. */\n readonly #live = new Map<string, Map<string, ClaudeActivityEvent>>()\n /** Monotonic revision boost so merged reads advance while text stays in memory. */\n readonly #boost = new Map<string, number>()\n readonly #flushTimers = new Map<string, ReturnType<typeof setTimeout>>()\n\n constructor(options: ClaudeSidecarRepositoryOptions = {}) {\n this.root = options.root ?? dshHomePath('plugins', 'dsh-claude', 'sessions')\n this.legacyRoot = options.legacyRoot\n ?? (options.root === undefined ? dshHomePath('plugins', 'dsh-claude-code', 'sessions') : undefined)\n }\n\n async read(sessionId: string): Promise<ClaudeSidecarProjection> {\n await this.#pending.get(sessionId)?.catch(() => undefined)\n return this.#merged(sessionId, await this.#base(sessionId))\n }\n\n /** Observe accepted changes for one session; returns the unsubscriber. */\n subscribe(sessionId: string, listener: (delta: ClaudeSidecarNotification) => void): () => void {\n let set = this.#listeners.get(sessionId)\n if (set === undefined) {\n set = new Set()\n this.#listeners.set(sessionId, set)\n }\n set.add(listener)\n return () => {\n set.delete(listener)\n if (set.size === 0) this.#listeners.delete(sessionId)\n }\n }\n\n /** Record streaming assistant prose without touching the disk on the hot\n * path: subscribers are notified synchronously (as an append when the\n * redacted text grows in place) and persistence is coalesced. */\n appendTranscriptText(\n sessionId: string,\n value: { turn: number; step: number; ordinal: number; text: string; renderer?: ClaudeRenderMode },\n ): void {\n const normalized = normalizeActivity({ kind: 'text', phase: 'updated', ...value })\n const key = activityKey(normalized)\n let overlay = this.#live.get(sessionId)\n if (overlay === undefined) {\n overlay = new Map()\n this.#live.set(sessionId, overlay)\n }\n const previous = overlay.get(key)\n overlay.set(key, normalized)\n this.#boost.set(sessionId, (this.#boost.get(sessionId) ?? 0) + 1)\n const text = normalized.text ?? ''\n const base = {\n turn: normalized.turn,\n step: normalized.step,\n ordinal: normalized.ordinal,\n ...(normalized.renderer === undefined ? {} : { renderer: normalized.renderer }),\n }\n // Redaction may rewrite earlier characters once a secret completes, so a\n // non-prefix update falls back to a full-text replacement.\n this.#notify(sessionId, previous?.text !== undefined && text.startsWith(previous.text)\n ? { kind: 'text', ...base, append: text.slice(previous.text.length) }\n : { kind: 'text', ...base, text })\n this.#scheduleTextFlush(sessionId)\n }\n\n /** Persist any pending streaming transcript now (segment close, turn end). */\n flushTranscriptText(sessionId: string): Promise<void> {\n const timer = this.#flushTimers.get(sessionId)\n if (timer !== undefined) {\n clearTimeout(timer)\n this.#flushTimers.delete(sessionId)\n }\n return this.#flushLive(sessionId)\n }\n\n /** How many notifications this session has published. */\n sequence(sessionId: string): number {\n return this.#seq.get(sessionId) ?? 0\n }\n\n /** Restate where the stream stands without changing anything.\n *\n * A reader detects a lost delta from the hole the NEXT one leaves, which\n * never comes when the lost delta was the last of a turn -- exactly the\n * case that leaves a finished tool group pulsing forever. Called at turn\n * settlement, this gives that reader the one line it needs to disagree. */\n checkpoint(sessionId: string): void {\n this.#deliver(sessionId, { kind: 'checkpoint', seq: this.sequence(sessionId) })\n }\n\n #notify(sessionId: string, delta: ClaudeSidecarDelta): void {\n const seq = this.sequence(sessionId) + 1\n this.#seq.set(sessionId, seq)\n this.#deliver(sessionId, { ...delta, seq } as ClaudeSidecarNotification)\n }\n\n #deliver(sessionId: string, notification: ClaudeSidecarNotification): void {\n const set = this.#listeners.get(sessionId)\n if (set === undefined) return\n for (const listener of [...set]) {\n try {\n listener(notification)\n } catch {\n // A subscriber failure must never affect durable state.\n }\n }\n }\n\n #merged(sessionId: string, base: ClaudeSidecarProjection): ClaudeSidecarProjection {\n const overlay = this.#live.get(sessionId)\n const boost = this.#boost.get(sessionId) ?? 0\n if ((overlay === undefined || overlay.size === 0) && boost === 0) return base\n return {\n ...base,\n revision: base.revision + boost,\n ...(overlay === undefined || overlay.size === 0\n ? {}\n : { activities: mergeActivities(base.activities, [...overlay.values()]) }),\n }\n }\n\n async #base(sessionId: string): Promise<ClaudeSidecarProjection> {\n const cached = this.#latest.get(sessionId)\n if (cached !== undefined) return cached\n const loaded = await this.#readNow(sessionId)\n this.#latest.set(sessionId, loaded)\n return loaded\n }\n\n #scheduleTextFlush(sessionId: string): void {\n if (this.#flushTimers.has(sessionId)) return\n const timer = setTimeout(() => {\n this.#flushTimers.delete(sessionId)\n void this.#flushLive(sessionId)\n }, TEXT_FLUSH_MS)\n timer.unref?.()\n this.#flushTimers.set(sessionId, timer)\n }\n\n async #flushLive(sessionId: string): Promise<void> {\n const overlay = this.#live.get(sessionId)\n if (overlay === undefined || overlay.size === 0) return\n const entries = [...overlay.entries()]\n try {\n await this.#update(sessionId, current => ({\n ...current,\n activities: mergeActivities(current.activities, entries.map(([, value]) => value)),\n }))\n } catch {\n // Keep the overlay; the next append or flush retries persistence.\n return\n }\n for (const [key, value] of entries) {\n if (overlay.get(key) === value) overlay.delete(key)\n }\n if (overlay.size === 0) this.#live.delete(sessionId)\n }\n\n writeBinding(\n sessionId: string,\n value: Omit<ClaudeSessionBoundEvent, 'sdkVersion'> & { sdkVersion?: string },\n ): Promise<ClaudeSidecarProjection> {\n const normalized = normalizeBinding(value)\n return this.#update(sessionId, current => ({ ...current, binding: normalized }))\n }\n\n appendActivity(\n sessionId: string,\n value: ClaudeActivityInput & { turn: number; step: number; ordinal: number },\n ): Promise<ClaudeSidecarProjection> {\n const normalized = normalizeActivity(value)\n return this.#update(sessionId, current => ({\n ...current,\n activities: mergeActivities(current.activities, [normalized]),\n }), false, { kind: 'activity', activity: normalized })\n }\n\n writeContextUsage(sessionId: string, value: ClaudeContextUsageInput): Promise<ClaudeSidecarProjection> {\n const normalized = normalizeContextUsage(value)\n return this.#update(sessionId, current => ({ ...current, contextUsage: normalized }), false, { kind: 'contextUsage', value: normalized })\n }\n\n writeTasks(sessionId: string, value: readonly ClaudeTaskInfo[]): Promise<ClaudeSidecarProjection> {\n const normalized = normalizeTasksEvent(value)\n return this.#update(sessionId, current => ({ ...current, tasks: normalized }), false, { kind: 'tasks', value: normalized })\n }\n\n /** Land one planned rewind: hidden ranges, surviving anchors, and the fork\n * target the next Claude spawn consumes. */\n writeRewind(sessionId: string, value: ClaudeRewindState): Promise<ClaudeSidecarProjection> {\n return this.#update(sessionId, current => ({ ...current, rewind: value }), false, { kind: 'sync' })\n }\n\n /** Remember where Claude's chain ended for one completed DSH turn. */\n recordRewindAnchor(sessionId: string, turn: number, uuid: string): Promise<ClaudeSidecarProjection> {\n return this.#update(sessionId, current => ({\n ...current,\n rewind: recordRewindAnchor(current.rewind ?? EMPTY_REWIND_STATE, { turn, uuid }),\n }))\n }\n\n /** Disarm the fork target once a Claude process has resumed at it, so a\n * later respawn continues the rewound session instead of re-truncating it. */\n clearRewindPending(sessionId: string): Promise<ClaudeSidecarProjection> {\n return this.#update(sessionId, current => (current.rewind?.pending === undefined ? current : {\n ...current,\n rewind: { ranges: current.rewind.ranges, anchors: current.rewind.anchors },\n }))\n }\n\n importLegacy(sessionId: string, events: readonly SessionEvent[]): Promise<ClaudeSidecarProjection> {\n const importedActivities = events\n .filter(event => event.type === CLAUDE_ACTIVITY_EVENT)\n .map(event => activity(event.data))\n .filter((item): item is ClaudeActivityEvent => item !== undefined)\n const importedBinding = latestClaudeSessionBinding(events)\n const importedUsage = latestClaudeContextUsage(events)\n const importedTasks = latestClaudeTasks(events)\n return this.#update(sessionId, current => ({\n ...current,\n activities: mergeActivities(importedActivities, current.activities),\n ...(current.binding !== undefined || importedBinding === undefined ? {} : { binding: normalizeBinding(importedBinding) }),\n ...(current.contextUsage !== undefined || importedUsage === undefined ? {} : { contextUsage: normalizeContextUsage(importedUsage) }),\n ...(current.tasks !== undefined || importedTasks === undefined ? {} : { tasks: normalizeTasksEvent(importedTasks.tasks) }),\n }), true, { kind: 'sync' })\n }\n\n #path(sessionId: string, root = this.root): string {\n if (sessionId.length === 0 || sessionId.length > 1_024) throw new Error('dsh-claude: invalid session id')\n return join(root, `${Buffer.from(sessionId).toString('base64url')}.json`)\n }\n\n #update(\n sessionId: string,\n change: (current: ClaudeSidecarProjection) => Omit<ClaudeSidecarProjection, 'revision' | 'schemaVersion'> & Partial<Pick<ClaudeSidecarProjection, 'revision' | 'schemaVersion'>>,\n skipUnchanged = false,\n delta?: ClaudeSidecarDelta,\n ): Promise<ClaudeSidecarProjection> {\n const previous = this.#pending.get(sessionId) ?? Promise.resolve()\n const operation = previous.catch(() => undefined).then(async () => {\n const current = await this.#base(sessionId)\n const changed = parseClaudeSidecar({\n ...change(current),\n schemaVersion: SIDECAR_SCHEMA_VERSION,\n revision: current.revision,\n })\n if (skipUnchanged && JSON.stringify(changed) === JSON.stringify(current)) return current\n const next = { ...changed, revision: current.revision + 1 }\n await this.#writeNow(sessionId, next)\n this.#latest.set(sessionId, next)\n if (delta !== undefined) this.#notify(sessionId, delta)\n return next\n })\n this.#pending.set(sessionId, operation)\n void operation.finally(() => {\n if (this.#pending.get(sessionId) === operation) this.#pending.delete(sessionId)\n }).catch(() => undefined)\n return operation\n }\n\n async #readNow(sessionId: string): Promise<ClaudeSidecarProjection> {\n try {\n return parseClaudeSidecar(JSON.parse(await readFile(this.#path(sessionId), 'utf8')))\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error\n }\n if (this.legacyRoot === undefined) return emptyProjection()\n try {\n return parseClaudeSidecar(JSON.parse(await readFile(this.#path(sessionId, this.legacyRoot), 'utf8')))\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') return emptyProjection()\n throw error\n }\n }\n\n async #writeNow(sessionId: string, projection: ClaudeSidecarProjection): Promise<void> {\n await mkdir(this.root, { recursive: true, mode: 0o700 })\n await chmod(this.root, 0o700)\n const target = this.#path(sessionId)\n const temporary = `${target}.${process.pid}.${randomUUID()}.tmp`\n try {\n await writeFile(temporary, `${JSON.stringify(projection)}\\n`, { mode: 0o600, flag: 'wx' })\n await chmod(temporary, 0o600)\n await rename(temporary, target)\n await chmod(target, 0o600)\n } finally {\n await rm(temporary, { force: true }).catch(() => undefined)\n }\n }\n}\n","export class AsyncQueueClosedError extends Error {\n constructor() {\n super('Async queue is closed')\n this.name = 'AsyncQueueClosedError'\n }\n}\n\ninterface Pending<T> {\n resolve: (result: IteratorResult<T>) => void\n reject: (error: unknown) => void\n}\n\nexport class AsyncQueue<T> implements AsyncIterable<T>, AsyncIterator<T> {\n readonly #values: T[] = []\n readonly #pending: Pending<T>[] = []\n #closed = false\n #failure: unknown\n\n get closed(): boolean {\n return this.#closed\n }\n\n push(value: T): void {\n if (this.#closed) throw new AsyncQueueClosedError()\n const waiter = this.#pending.shift()\n if (waiter !== undefined) waiter.resolve({ value, done: false })\n else this.#values.push(value)\n }\n\n close(): void {\n if (this.#closed) return\n this.#closed = true\n for (const waiter of this.#pending.splice(0)) waiter.resolve({ value: undefined, done: true })\n }\n\n fail(error: unknown): void {\n if (this.#closed) return\n this.#closed = true\n this.#failure = error\n for (const waiter of this.#pending.splice(0)) waiter.reject(error)\n }\n\n discard(error?: unknown): void {\n this.#values.splice(0)\n if (this.#closed) return\n this.#closed = true\n if (error === undefined) {\n for (const waiter of this.#pending.splice(0)) waiter.resolve({ value: undefined, done: true })\n return\n }\n this.#failure = error\n for (const waiter of this.#pending.splice(0)) waiter.resolve({ value: undefined, done: true })\n }\n\n next(): Promise<IteratorResult<T>> {\n const value = this.#values.shift()\n if (value !== undefined) return Promise.resolve({ value, done: false })\n if (this.#closed) {\n return this.#failure === undefined\n ? Promise.resolve({ value: undefined, done: true })\n : Promise.reject(this.#failure)\n }\n return new Promise<IteratorResult<T>>((resolve, reject) => {\n this.#pending.push({ resolve, reject })\n })\n }\n\n return(): Promise<IteratorResult<T>> {\n this.close()\n return Promise.resolve({ value: undefined, done: true })\n }\n\n [Symbol.asyncIterator](): AsyncIterator<T> {\n return this\n }\n}\n","import type { CanUseTool, PermissionResult } from '@anthropic-ai/claude-agent-sdk'\nimport type { Agent } from '@deepseek-ai/dsh-agent'\nimport type { ApprovalOutcome, ApprovalService } from '@deepseek-ai/dsh-user-approval'\nimport {\n boundText,\n safeDetail,\n type ClaudeActivityInput,\n type ClaudeActivityCursor,\n} from './events.ts'\nimport type { UserQuestionBridge } from './user-question.ts'\n\nexport type ApprovalRequester = Pick<ApprovalService, 'request'>\n\nexport interface ActivePermissionContext {\n agent: Agent\n cursor: ClaudeActivityCursor\n markActivity?: () => void\n recordDenial?: (toolUseId: string) => void\n hasFullAccess?: () => Promise<boolean>\n appendActivity: (activity: ClaudeActivityInput) => Promise<void>\n}\n\nexport type ActivePermissionContextProvider = () => ActivePermissionContext | undefined\n\nfunction denialMessage(outcome: ApprovalOutcome): string {\n switch (outcome) {\n case 'rejected': return 'The user rejected this action in DeepSeek Harness.'\n case 'cancelled': return 'The permission request was cancelled in DeepSeek Harness.'\n case 'unavailable': return 'No DeepSeek Harness approval surface was available; the action was denied.'\n case 'allowed-once': return ''\n }\n}\n\nexport function permissionReason(\n toolName: string,\n input: Readonly<Record<string, unknown>>,\n options: Parameters<CanUseTool>[2],\n): string {\n const prompt = options.title ?? options.description ?? options.decisionReason ?? `Claude Code wants to use ${toolName}.`\n const detail = safeDetail(input)\n return boundText(detail === undefined ? prompt : `${prompt}\\nInput: ${detail}`, 1_200)\n}\n\nexport function mapApprovalOutcome(\n outcome: ApprovalOutcome,\n input: Record<string, unknown>,\n toolUseID: string,\n): PermissionResult {\n if (outcome === 'allowed-once') {\n return {\n behavior: 'allow',\n updatedInput: input,\n toolUseID,\n decisionClassification: 'user_temporary',\n }\n }\n return {\n behavior: 'deny',\n message: denialMessage(outcome),\n toolUseID,\n decisionClassification: 'user_reject',\n }\n}\n\nexport function createPermissionBridge(\n approval: ApprovalRequester,\n activeContext: ActivePermissionContextProvider,\n userQuestion?: UserQuestionBridge,\n): CanUseTool {\n return async (toolName, input, options) => {\n if (toolName === 'AskUserQuestion') {\n return userQuestion === undefined\n ? {\n behavior: 'deny',\n message: 'DeepSeek Harness user questions are unavailable; the question was cancelled.',\n toolUseID: options.toolUseID,\n decisionClassification: 'user_reject',\n }\n : userQuestion(input, options)\n }\n const active = activeContext()\n if (active === undefined) {\n return {\n behavior: 'deny',\n message: 'No active DeepSeek Harness turn owns this Claude Code action.',\n toolUseID: options.toolUseID,\n decisionClassification: 'user_reject',\n }\n }\n\n active.markActivity?.()\n const reason = permissionReason(toolName, input, options)\n try {\n await active.appendActivity({\n kind: 'permission',\n phase: 'started',\n toolUseId: options.toolUseID,\n toolName,\n title: options.displayName ?? toolName,\n summary: options.title ?? options.description ?? reason,\n detail: input,\n })\n const alreadyFullAccess = await active.hasFullAccess?.() === true\n const outcome = alreadyFullAccess\n ? 'allowed-once'\n : await approval.request({\n agent: active.agent,\n toolName,\n reason,\n signal: options.signal,\n })\n // The access selector can change while the approval UI is open. Re-read\n // its durable state so an explicit Full access choice wins over the stale\n // request being closed as rejected/cancelled by that mode transition.\n const fullAccess = alreadyFullAccess || await active.hasFullAccess?.() === true\n const effectiveOutcome = fullAccess ? 'allowed-once' : outcome\n const result = mapApprovalOutcome(effectiveOutcome, input, options.toolUseID)\n if (result.behavior === 'deny') active.recordDenial?.(options.toolUseID)\n await active.appendActivity({\n kind: 'permission',\n phase: effectiveOutcome === 'allowed-once' ? 'completed' : 'denied',\n toolUseId: options.toolUseID,\n toolName,\n title: options.displayName ?? toolName,\n summary: fullAccess\n ? 'Allowed by Full access in DeepSeek Harness'\n : effectiveOutcome === 'allowed-once'\n ? 'Allowed once in DeepSeek Harness'\n : denialMessage(effectiveOutcome),\n })\n return result\n } catch (error) {\n const message = options.signal.aborted\n ? 'The permission request was cancelled in DeepSeek Harness.'\n : 'DeepSeek Harness could not record or answer the permission request; the action was denied.'\n try {\n await active.appendActivity({\n kind: 'permission',\n phase: 'failed',\n toolUseId: options.toolUseID,\n toolName,\n title: options.displayName ?? toolName,\n summary: message,\n isError: true,\n detail: error,\n })\n } catch {\n // The permission path is already fail-closed; a second audit failure cannot widen it.\n }\n return {\n behavior: 'deny',\n message,\n toolUseID: options.toolUseID,\n decisionClassification: 'user_reject',\n }\n }\n }\n}\n","import type { CanUseTool, PermissionResult } from '@anthropic-ai/claude-agent-sdk'\nimport type { Agent } from '@deepseek-ai/dsh-agent'\nimport type {\n AskUserQuestionAnswerItem,\n AskUserQuestionItem,\n UserQuestionService,\n} from '@deepseek-ai/dsh-user-questions'\nimport type { ClaudeActivityInput, ClaudeActivityCursor } from './events.ts'\n\nexport type UserQuestionRequester = Pick<UserQuestionService, 'ask'>\n\nexport interface ActiveUserQuestionContext {\n agent: Agent\n cursor: ClaudeActivityCursor\n markActivity?: () => void\n appendActivity: (activity: ClaudeActivityInput) => Promise<void>\n}\n\nexport type ActiveUserQuestionContextProvider = () => ActiveUserQuestionContext | undefined\nexport type UserQuestionBridge = (\n input: Record<string, unknown>,\n options: Parameters<CanUseTool>[2],\n) => Promise<PermissionResult>\n\nconst FAILURE_MESSAGE = 'DeepSeek Harness could not collect an answer; the question was cancelled.'\nconst INVALID_MESSAGE = 'Claude Code sent an invalid user-question request; the question was cancelled.'\n\nfunction failureMessage(error: unknown): string {\n const code = error !== null && typeof error === 'object' && 'code' in error\n ? (error as { code?: unknown }).code\n : undefined\n return typeof code === 'string' && /^[A-Z][A-Z0-9_]*$/.test(code)\n ? `${FAILURE_MESSAGE} (${code})`\n : FAILURE_MESSAGE\n}\n\nfunction deny(message: string, toolUseID: string): PermissionResult {\n return {\n behavior: 'deny',\n message,\n toolUseID,\n decisionClassification: 'user_reject',\n }\n}\n\nfunction optionalText(value: unknown): string | undefined {\n return typeof value === 'string' && value.length > 0 ? value : undefined\n}\n\nfunction parseQuestions(input: Record<string, unknown>, toolUseID: string): AskUserQuestionItem[] | undefined {\n if (!Array.isArray(input.questions) || input.questions.length === 0 || input.questions.length > 20) return undefined\n const seen = new Set<string>()\n const questions: AskUserQuestionItem[] = []\n for (const [index, value] of input.questions.entries()) {\n if (value === null || typeof value !== 'object' || Array.isArray(value)) return undefined\n const item = value as Record<string, unknown>\n if (typeof item.question !== 'string' || item.question.length === 0 || seen.has(item.question)) return undefined\n seen.add(item.question)\n if (item.options !== undefined && !Array.isArray(item.options)) return undefined\n const options = (item.options ?? []).map(option => {\n if (option === null || typeof option !== 'object' || Array.isArray(option)) return undefined\n const record = option as Record<string, unknown>\n if (typeof record.label !== 'string' || record.label.length === 0) return undefined\n const description = optionalText(record.description)\n return { label: record.label, ...(description === undefined ? {} : { description }) }\n })\n if (options.some(option => option === undefined)) return undefined\n const header = optionalText(item.header)\n questions.push({\n id: `${toolUseID}:${index}`,\n question: item.question,\n ...(header === undefined ? {} : { header }),\n options: options as NonNullable<AskUserQuestionItem['options']>,\n multiSelect: item.multiSelect === true,\n })\n }\n return questions\n}\n\nfunction answerText(answer: AskUserQuestionAnswerItem | undefined, multiSelect: boolean): string {\n if (answer === undefined) return ''\n const custom = optionalText(answer.custom)\n if (!multiSelect && custom !== undefined) return custom\n return [...answer.selected, ...(custom === undefined ? [] : [custom])].join(', ')\n}\n\nexport function createUserQuestionBridge(\n userQuestions: UserQuestionRequester,\n activeContext: ActiveUserQuestionContextProvider,\n): UserQuestionBridge {\n return async (input, options) => {\n const active = activeContext()\n if (active === undefined) return deny('No active DeepSeek Harness turn owns this Claude Code question.', options.toolUseID)\n\n const questions = parseQuestions(input, options.toolUseID)\n if (questions === undefined) return deny(INVALID_MESSAGE, options.toolUseID)\n\n active.markActivity?.()\n try {\n await active.appendActivity({\n kind: 'question',\n phase: 'started',\n toolUseId: options.toolUseID,\n toolName: 'AskUserQuestion',\n title: 'Claude asked a question',\n summary: questions.length === 1 ? questions[0]!.question : `Claude asked ${questions.length} questions`,\n })\n const response = await userQuestions.ask({\n questions,\n agent: active.agent,\n signal: options.signal,\n })\n const answersById = new Map(response.answers.map(answer => [answer.id, answer]))\n const answers = Object.fromEntries(questions.map(question => [\n question.question,\n answerText(answersById.get(question.id), question.multiSelect === true),\n ]))\n await active.appendActivity({\n kind: 'question',\n phase: 'completed',\n toolUseId: options.toolUseID,\n toolName: 'AskUserQuestion',\n title: 'Claude asked a question',\n summary: 'Answered in DeepSeek Harness',\n })\n return {\n behavior: 'allow',\n updatedInput: { ...input, answers },\n toolUseID: options.toolUseID,\n decisionClassification: 'user_temporary',\n }\n } catch (error) {\n const message = failureMessage(error)\n try {\n await active.appendActivity({\n kind: 'question',\n phase: 'failed',\n toolUseId: options.toolUseID,\n toolName: 'AskUserQuestion',\n title: 'Claude asked a question',\n summary: message,\n isError: true,\n })\n } catch {\n // The question path is fail-closed; a second audit failure cannot widen it.\n }\n return deny(message, options.toolUseID)\n }\n }\n}\n","import type { SDKMessage } from '@anthropic-ai/claude-agent-sdk'\nimport type { ClaudeUsage } from './events.ts'\n\nexport type NormalizedSdkMessage =\n | { kind: 'init'; sessionId: string; cliVersion: string; cwd: string }\n | { kind: 'text-delta'; text: string; parentToolUseId?: string }\n | { kind: 'assistant-text'; text: string; parentToolUseId?: string }\n | { kind: 'thinking'; text: string; phase: 'updated' | 'completed'; parentToolUseId?: string }\n | { kind: 'tool-call'; toolUseId: string; toolName: string; input: unknown; parentToolUseId?: string }\n | { kind: 'tool-result'; toolUseId: string; output: unknown; isError: boolean; parentToolUseId?: string }\n | {\n kind: 'subagent'\n title: string\n summary?: string\n detail?: unknown\n phase: 'started' | 'updated' | 'completed' | 'failed'\n /** Structured task-board fields for task_started/progress/updated/notification. */\n taskId?: string\n taskStatus?: 'running' | 'completed' | 'failed' | 'stopped' | 'killed'\n description?: string\n subagentType?: string\n taskType?: string\n lastToolName?: string\n usage?: { totalTokens?: number; toolUses?: number; durationMs?: number }\n /** Ambient/housekeeping task: hide from chat rows, keep on the task board. */\n skipTranscript?: boolean\n }\n | {\n /** Level signal: full live background-task set (REPLACE semantics). */\n kind: 'background-tasks'\n tasks: readonly { taskId: string; taskType?: string; description: string }[]\n }\n | {\n /** Context compaction boundary. The CLI compacts locally without running a\n * model turn, so this is the only evidence the conversation was rewritten;\n * `trigger` stays absent when the CLI does not name one. */\n kind: 'compaction'\n trigger?: 'manual' | 'auto'\n preTokens?: number\n postTokens?: number\n durationMs?: number\n }\n | {\n /** Prompt-side accounting for ONE provider call, read off an assistant\n * message. Distinct from the `result` usage, which sums every call the\n * turn made — see `ClaudeSupervisor#reportedUsage`. */\n kind: 'request-usage'\n usage: ClaudeUsage\n parentToolUseId?: string\n }\n | { kind: 'status'; title: string; summary?: string; detail?: unknown }\n | { kind: 'warning'; title: string; summary?: string; detail?: unknown }\n | { kind: 'permission-denied'; toolUseId: string; toolName: string; summary: string }\n | { kind: 'result'; success: boolean; text?: string; errors?: readonly string[]; usage: ClaudeUsage; sessionId: string; userMessageUuid?: string; terminalReason?: string; permissionDenials?: readonly { toolName: string; toolUseId: string }[] }\n | { kind: 'protocol-error'; title: string; detail: unknown }\n | { kind: 'unknown'; title: string; detail: unknown }\n\nfunction record(value: unknown): Record<string, unknown> | undefined {\n return value !== null && typeof value === 'object' ? value as Record<string, unknown> : undefined\n}\n\nfunction string(value: unknown): string | undefined {\n return typeof value === 'string' ? value : undefined\n}\n\nfunction finiteNumber(value: unknown): number | undefined {\n return typeof value === 'number' && Number.isFinite(value) ? value : undefined\n}\n\nfunction contentText(content: unknown): string {\n if (typeof content === 'string') return content\n if (!Array.isArray(content)) return ''\n return content.map(item => {\n const block = record(item)\n if (block?.type === 'text') return string(block.text) ?? ''\n return ''\n }).join('')\n}\n\nfunction taskUsageOf(usage: Record<string, unknown> | undefined): { totalTokens?: number; toolUses?: number; durationMs?: number } | undefined {\n if (usage === undefined) return undefined\n const normalized: { totalTokens?: number; toolUses?: number; durationMs?: number } = {}\n if (typeof usage.total_tokens === 'number') normalized.totalTokens = usage.total_tokens\n if (typeof usage.tool_uses === 'number') normalized.toolUses = usage.tool_uses\n if (typeof usage.duration_ms === 'number') normalized.durationMs = usage.duration_ms\n return Object.keys(normalized).length === 0 ? undefined : normalized\n}\n\n/** Read one Anthropic `usage` envelope. Shared by the per-call sample on an\n * assistant message and the turn total on a result message. */\nfunction usageOf(usage: Record<string, unknown> | undefined): ClaudeUsage {\n const normalized: ClaudeUsage = {}\n if (usage === undefined) return normalized\n if (typeof usage.input_tokens === 'number') normalized.inputTokens = usage.input_tokens\n if (typeof usage.output_tokens === 'number') normalized.outputTokens = usage.output_tokens\n if (typeof usage.cache_read_input_tokens === 'number') normalized.cacheReadTokens = usage.cache_read_input_tokens\n if (typeof usage.cache_creation_input_tokens === 'number') normalized.cacheCreationTokens = usage.cache_creation_input_tokens\n return normalized\n}\n\nfunction hasUsageCounts(usage: ClaudeUsage): boolean {\n return usage.inputTokens !== undefined\n || usage.outputTokens !== undefined\n || usage.cacheReadTokens !== undefined\n || usage.cacheCreationTokens !== undefined\n}\n\nfunction resultUsage(message: Record<string, unknown>): ClaudeUsage {\n const normalized = usageOf(record(message.usage))\n if (typeof message.total_cost_usd === 'number') normalized.cumulativeCostUsd = message.total_cost_usd\n return normalized\n}\n\nfunction normalizeAssistant(message: Record<string, unknown>): NormalizedSdkMessage[] {\n const envelope = record(message.message)\n const content = envelope?.content\n if (!Array.isArray(content)) return [{ kind: 'protocol-error', title: 'Malformed Claude assistant message', detail: message }]\n const parentToolUseId = string(message.parent_tool_use_id)\n const normalized: NormalizedSdkMessage[] = []\n for (const item of content) {\n const block = record(item)\n if (block === undefined) continue\n if (block.type === 'text') {\n const text = string(block.text)\n if (text !== undefined && text.length > 0) normalized.push({ kind: 'assistant-text', text, ...(parentToolUseId === undefined ? {} : { parentToolUseId }) })\n } else if (block.type === 'thinking') {\n const text = string(block.thinking)\n if (text !== undefined && text.length > 0) normalized.push({ kind: 'thinking', text, phase: 'completed', ...(parentToolUseId === undefined ? {} : { parentToolUseId }) })\n } else if (block.type === 'tool_use') {\n const toolUseId = string(block.id)\n const toolName = string(block.name)\n if (toolUseId !== undefined && toolName !== undefined) {\n normalized.push({\n kind: 'tool-call',\n toolUseId,\n toolName,\n input: block.input,\n ...(parentToolUseId === undefined ? {} : { parentToolUseId }),\n })\n }\n }\n }\n const usage = usageOf(record(envelope?.usage))\n if (hasUsageCounts(usage)) {\n normalized.push({ kind: 'request-usage', usage, ...(parentToolUseId === undefined ? {} : { parentToolUseId }) })\n }\n return normalized\n}\n\nfunction normalizeUser(message: Record<string, unknown>): NormalizedSdkMessage[] {\n // CLI ≥ 2.1.238 replays prior user messages (including local-command output\n // echoes with plain string content) when resuming a session. Replays and\n // block-less string echoes carry no tool results; they are not protocol\n // failures and must never kill the session.\n if (message.isReplay === true) return []\n const envelope = record(message.message)\n const content = envelope?.content\n if (typeof content === 'string') return []\n if (!Array.isArray(content)) return [{ kind: 'protocol-error', title: 'Malformed Claude user message', detail: message }]\n const parentToolUseId = string(message.parent_tool_use_id)\n const normalized: NormalizedSdkMessage[] = []\n for (const item of content) {\n const block = record(item)\n if (block?.type !== 'tool_result') continue\n const toolUseId = string(block.tool_use_id)\n if (toolUseId === undefined) continue\n normalized.push({\n kind: 'tool-result',\n toolUseId,\n output: message.tool_use_result ?? block.content,\n isError: block.is_error === true,\n ...(parentToolUseId === undefined ? {} : { parentToolUseId }),\n })\n }\n return normalized\n}\n\nfunction normalizeSystem(message: Record<string, unknown>): NormalizedSdkMessage[] {\n const subtype = string(message.subtype)\n if (subtype === 'init') {\n const sessionId = string(message.session_id)\n const cliVersion = string(message.claude_code_version)\n const cwd = string(message.cwd)\n return sessionId !== undefined && cliVersion !== undefined && cwd !== undefined\n ? [{ kind: 'init', sessionId, cliVersion, cwd }]\n : [{ kind: 'protocol-error', title: 'Malformed Claude initialization message', detail: message }]\n }\n if (subtype === 'status') {\n const status = message.status\n if (status === null) return [{ kind: 'status', title: 'Claude Code is ready' }]\n return [{ kind: 'status', title: `Claude Code ${String(status)}`, detail: message }]\n }\n if (subtype === 'session_state_changed') {\n return [{ kind: 'status', title: `Claude session ${String(message.state)}` }]\n }\n if (subtype === 'permission_denied') {\n const toolUseId = string(message.tool_use_id)\n const toolName = string(message.tool_name)\n if (toolUseId !== undefined && toolName !== undefined) {\n return [{\n kind: 'permission-denied',\n toolUseId,\n toolName,\n summary: string(message.message) ?? 'Claude Code denied the action',\n }]\n }\n }\n if (subtype === 'task_started') {\n const taskId = string(message.task_id)\n const description = string(message.description)\n const subagentType = string(message.subagent_type)\n const taskType = string(message.task_type)\n return [{\n kind: 'subagent',\n title: description ?? taskId ?? 'Claude subagent started',\n phase: 'started',\n detail: message,\n ...(taskId === undefined ? {} : { taskId }),\n taskStatus: 'running' as const,\n ...(description === undefined ? {} : { description }),\n ...(subagentType === undefined ? {} : { subagentType }),\n ...(taskType === undefined ? {} : { taskType }),\n ...(message.skip_transcript === true ? { skipTranscript: true } : {}),\n }]\n }\n if (subtype === 'task_progress') {\n const taskId = string(message.task_id)\n const description = string(message.description)\n const summary = string(message.summary)\n const subagentType = string(message.subagent_type)\n const lastToolName = string(message.last_tool_name)\n const usage = taskUsageOf(record(message.usage))\n return [{\n kind: 'subagent',\n title: summary ?? description ?? 'Claude subagent update',\n phase: 'updated',\n detail: message,\n ...(taskId === undefined ? {} : { taskId }),\n taskStatus: 'running' as const,\n ...(description === undefined ? {} : { description }),\n ...(subagentType === undefined ? {} : { subagentType }),\n ...(lastToolName === undefined ? {} : { lastToolName }),\n ...(summary === undefined ? {} : { summary }),\n ...(usage === undefined ? {} : { usage }),\n }]\n }\n if (subtype === 'task_updated') {\n const patch = record(message.patch)\n const status = string(patch?.status)\n const taskId = string(message.task_id)\n const description = string(patch?.description)\n const error = string(patch?.error)\n const taskStatus = status === undefined\n ? undefined\n : status === 'killed'\n ? 'killed' as const\n : status === 'completed'\n ? 'completed' as const\n : status === 'failed'\n ? 'failed' as const\n : 'running' as const\n return [{\n kind: 'subagent',\n title: description ?? 'Claude subagent update',\n phase: status === 'failed' || status === 'killed' ? 'failed' : status === 'completed' ? 'completed' : 'updated',\n detail: message,\n ...(taskId === undefined ? {} : { taskId }),\n ...(taskStatus === undefined ? {} : { taskStatus }),\n ...(description === undefined ? {} : { description }),\n ...(error === undefined ? {} : { summary: error }),\n }]\n }\n if (subtype === 'task_notification') {\n const failed = message.status === 'failed'\n const stopped = message.status === 'stopped' || message.status === 'cancelled'\n const taskId = string(message.task_id)\n const summary = string(message.summary)\n const taskStatus = failed ? 'failed' as const : stopped ? 'stopped' as const : 'completed' as const\n const usage = taskUsageOf(record(message.usage))\n return [{\n kind: 'subagent',\n title: summary ?? taskId ?? 'Claude subagent finished',\n phase: failed || stopped ? 'failed' : 'completed',\n detail: message,\n ...(taskId === undefined ? {} : { taskId }),\n taskStatus,\n ...(summary === undefined ? {} : { summary }),\n ...(usage === undefined ? {} : { usage }),\n }]\n }\n if (subtype === 'background_tasks_changed') {\n const tasks = Array.isArray(message.tasks) ? message.tasks : []\n return [{\n kind: 'background-tasks',\n tasks: tasks.flatMap(item => {\n const entry = record(item)\n const taskId = string(entry?.task_id)\n const description = string(entry?.description)\n const taskType = string(entry?.task_type)\n if (taskId === undefined || description === undefined) return []\n return [{\n taskId,\n description,\n ...(taskType === undefined ? {} : { taskType }),\n }]\n }),\n }]\n }\n if (subtype === 'api_retry') {\n return [{ kind: 'warning', title: 'Claude API retry', detail: message }]\n }\n if (subtype === 'compact_boundary') {\n // `/compact` runs entirely inside the CLI: no assistant turn, and the\n // `Compacted` echo arrives as a block-less user message that\n // `normalizeUser` drops. Without this branch the boundary fell through to\n // the generic fallback below and became audit-only 'status', so a\n // compacted conversation showed nothing at all.\n const metadata = record(message.compact_metadata)\n const trigger = metadata?.trigger === 'auto' || metadata?.trigger === 'manual' ? metadata.trigger : undefined\n const preTokens = finiteNumber(metadata?.pre_tokens)\n const postTokens = finiteNumber(metadata?.post_tokens)\n const durationMs = finiteNumber(metadata?.duration_ms)\n return [{\n kind: 'compaction',\n ...(trigger === undefined ? {} : { trigger }),\n ...(preTokens === undefined ? {} : { preTokens }),\n ...(postTokens === undefined ? {} : { postTokens }),\n ...(durationMs === undefined ? {} : { durationMs }),\n }]\n }\n if (subtype === 'informational' || subtype === 'notification' || subtype === 'local_command_output') {\n return [{\n kind: message.level === 'warning' ? 'warning' : 'status',\n title: string(message.content) ?? string(message.text) ?? 'Claude Code notice',\n detail: message,\n }]\n }\n if (subtype?.startsWith('hook_') === true || subtype === 'plugin_install') {\n return [{ kind: 'status', title: `Claude Code ${subtype.replaceAll('_', ' ')}`, detail: message }]\n }\n if (subtype !== undefined) {\n // Preserve unknown system lifecycle evidence (background tasks, resets,\n // worker/mirror lifecycle) as a bounded activity instead of silently\n // dropping it; the activity layer redacts and bounds the detail.\n return [{ kind: 'status', title: `Claude Code ${subtype.replaceAll('_', ' ')}`, detail: message }]\n }\n return []\n}\n\nconst RESULT_ERROR_SUBTYPES = new Set([\n 'error_during_execution',\n 'error_max_turns',\n 'error_max_budget_usd',\n 'error_max_structured_output_retries',\n])\n\nexport function normalizeSdkMessage(message: SDKMessage): NormalizedSdkMessage[] {\n const value = message as unknown as Record<string, unknown>\n if (value.type === 'stream_event') {\n const event = record(value.event)\n const parentToolUseId = string(value.parent_tool_use_id)\n if (event?.type === 'content_block_delta') {\n const delta = record(event.delta)\n if (delta?.type === 'text_delta') {\n const text = string(delta.text)\n return text === undefined ? [] : [{ kind: 'text-delta', text, ...(parentToolUseId === undefined ? {} : { parentToolUseId }) }]\n }\n if (delta?.type === 'thinking_delta') {\n const text = string(delta.thinking)\n return text === undefined ? [] : [{ kind: 'thinking', text, phase: 'updated', ...(parentToolUseId === undefined ? {} : { parentToolUseId }) }]\n }\n }\n return []\n }\n if (value.type === 'assistant') return normalizeAssistant(value)\n if (value.type === 'user') return normalizeUser(value)\n if (value.type === 'system') return normalizeSystem(value)\n if (value.type === 'result') {\n const sessionId = string(value.session_id)\n if (sessionId === undefined || (value.subtype !== 'success' && !RESULT_ERROR_SUBTYPES.has(String(value.subtype)))) {\n return [{ kind: 'protocol-error', title: 'Malformed Claude result message', detail: value }]\n }\n // A result is a success only when it is not flagged as an error. Local\n // 2.1.233 emits subtype:\"success\" with is_error:true for API/auth failures\n // (e.g. terminal_reason:\"api_error\"), so subtype alone is not authoritative.\n const success = value.subtype === 'success' && value.is_error !== true\n const errors = Array.isArray(value.errors)\n ? value.errors.filter((item): item is string => typeof item === 'string')\n : undefined\n const terminalReason = string(value.terminal_reason)\n const userMessageUuid = string(value.user_message_uuid)\n const permissionDenials = Array.isArray(value.permission_denials)\n ? value.permission_denials\n .map(item => record(item))\n .filter((item): item is Record<string, unknown> => item !== undefined)\n .map(item => {\n const toolName = string(item.tool_name)\n const toolUseId = string(item.tool_use_id)\n return toolName === undefined || toolUseId === undefined ? undefined : { toolName, toolUseId }\n })\n .filter((item): item is { toolName: string; toolUseId: string } => item !== undefined)\n .slice(0, 40)\n : undefined\n return [{\n kind: 'result',\n success,\n ...(success && typeof value.result === 'string' ? { text: value.result } : {}),\n ...(errors === undefined ? {} : { errors }),\n ...(terminalReason === undefined ? {} : { terminalReason }),\n ...(permissionDenials === undefined || permissionDenials.length === 0 ? {} : { permissionDenials }),\n usage: resultUsage(value),\n sessionId,\n ...(userMessageUuid === undefined ? {} : { userMessageUuid }),\n }]\n }\n if (value.type === 'auth_status') {\n return [{\n kind: value.error === undefined ? 'status' : 'warning',\n title: value.error === undefined ? 'Claude authentication status changed' : 'Claude authentication failed',\n detail: value.error ?? value.output,\n }]\n }\n if (value.type === 'rate_limit_event') {\n // The CLI pushes subscription-quota status after API activity. Every\n // update stays audit-only ('status' never enters the conversation flow);\n // a blocking state surfaces through the repository status bar badge that\n // reads these titles from the projection instead.\n const info = record(value.rate_limit_info)\n const status = string(info?.status)\n const blocking = status !== undefined && status !== 'allowed'\n return [{\n kind: 'status',\n title: blocking ? 'Claude rate limit is blocking requests' : 'Claude rate limit status changed',\n detail: value.rate_limit_info,\n }]\n }\n return [{ kind: 'unknown', title: `Unknown Claude SDK message: ${String(value.type)}`, detail: value }]\n}\n\nexport function extractSdkContentText(content: unknown): string {\n return contentText(content)\n}\n","/** Claude.ai plan rate-limit windows behind the CLI's `/usage` panel.\n *\n * The Agent SDK exposes them through an experimental query method whose name\n * advertises its own instability, so every read is guarded: a missing method,\n * a shape change, or an API-key session all degrade to `available: false`\n * instead of breaking the settings page. */\nimport { query as claudeQuery, type Options as ClaudeOptions, type Query, type SDKUserMessage } from '@anthropic-ai/claude-agent-sdk'\n\n/** The SDK's own name for the unstable `/usage` control request; it is\n * documented to change when the API stabilizes, so it lives in one place. */\nexport const PLAN_USAGE_METHOD = 'usage_EXPERIMENTAL_MAY_CHANGE_DO_NOT_RELY_ON_THIS_API_YET'\n\n/** A throwaway probe should not outlive a wedged control request. */\nexport const PLAN_USAGE_TIMEOUT_MS = 20_000\n\n/** Invoke the experimental usage control request, or say why we cannot. */\nexport function readPlanUsageFrom(query: Query): Promise<unknown> {\n const read = (query as Partial<Record<typeof PLAN_USAGE_METHOD, () => Promise<unknown>>>)[PLAN_USAGE_METHOD]\n if (typeof read !== 'function') throw new Error('dsh-claude: this Claude Agent SDK build exposes no plan usage API')\n return read.call(query)\n}\n\n/** One utilization window. `label` is only set for server-named model buckets\n * (e.g. 'Fable'); the fixed windows are translated client-side from `id`. */\nexport interface PlanUsageWindow {\n readonly id: string\n readonly label?: string\n readonly utilization?: number\n readonly resetsAt?: string\n}\n\nexport interface PlanUsageReport {\n readonly available: boolean\n readonly subscription?: string\n readonly windows: readonly PlanUsageWindow[]\n readonly fetchedAt: number\n readonly message?: string\n}\n\n/** Fixed windows in display order; the SDK omits the ones a plan does not have. */\nconst FIXED_WINDOWS = ['five_hour', 'seven_day', 'seven_day_opus', 'seven_day_sonnet'] as const\n\nfunction record(value: unknown): Record<string, unknown> | undefined {\n return typeof value === 'object' && value !== null && !Array.isArray(value) ? value as Record<string, unknown> : undefined\n}\n\n/** Utilization is documented as 0-100; clamp so a server glitch cannot render\n * a bar wider than its track or a negative width. */\nfunction utilization(value: unknown): number | undefined {\n return typeof value === 'number' && Number.isFinite(value) ? Math.min(100, Math.max(0, value)) : undefined\n}\n\nfunction resetsAt(value: unknown): string | undefined {\n return typeof value === 'string' && value.length > 0 ? value : undefined\n}\n\nfunction window(id: string, source: unknown, label?: string): PlanUsageWindow | undefined {\n const entry = record(source)\n if (entry === undefined) return undefined\n const used = utilization(entry.utilization)\n const reset = resetsAt(entry.resets_at)\n if (used === undefined && reset === undefined) return undefined\n return {\n id,\n ...(label === undefined ? {} : { label }),\n ...(used === undefined ? {} : { utilization: used }),\n ...(reset === undefined ? {} : { resetsAt: reset }),\n }\n}\n\n/** Project the SDK's `/usage` response onto the windows the settings card shows. */\nexport function normalizePlanUsage(value: unknown, fetchedAt: number): PlanUsageReport {\n const response = record(value)\n const subscription = typeof response?.subscription_type === 'string' ? response.subscription_type : undefined\n const limits = record(response?.rate_limits)\n if (response?.rate_limits_available !== true || limits === undefined) {\n return {\n available: false,\n ...(subscription === undefined ? {} : { subscription }),\n windows: [],\n fetchedAt,\n }\n }\n const windows = [\n ...FIXED_WINDOWS.map(id => window(id, limits[id])),\n ...(Array.isArray(limits.model_scoped) ? limits.model_scoped : []).map((entry: unknown, index: number) => {\n const name = record(entry)?.display_name\n return window(`model:${typeof name === 'string' ? name : index}`, entry, typeof name === 'string' ? name : undefined)\n }),\n ].filter((entry): entry is PlanUsageWindow => entry !== undefined)\n return {\n available: windows.length > 0,\n ...(subscription === undefined ? {} : { subscription }),\n windows,\n fetchedAt,\n }\n}\n\n/** Read plan limits from a throwaway Claude process.\n *\n * Deliberately NOT routed through the supervisor. Borrowing a session's\n * process fails outright while that session is mid-turn, and for a session\n * with no process yet it would resume the whole conversation — and possibly\n * evict another idle session to make room — just to read three numbers. This\n * query carries no tools, no permission bridge, and no session binding: it\n * starts, answers one control request, and is killed. */\nexport async function probePlanUsage(\n executablePath: string,\n fetchedAt: number,\n factory: (params: { prompt: AsyncIterable<SDKUserMessage>; options: ClaudeOptions }) => Query = claudeQuery,\n): Promise<PlanUsageReport> {\n const lifetime = new AbortController()\n const timer = setTimeout(() => lifetime.abort(), PLAN_USAGE_TIMEOUT_MS)\n timer.unref?.()\n // The SDK ends a query as soon as its prompt stream closes, so hold the\n // stream open and let the abort below tear the process down instead.\n const prompt = (async function* (): AsyncGenerator<SDKUserMessage> {\n await new Promise<never>(() => {})\n })()\n const query = factory({\n prompt,\n options: {\n cwd: process.cwd(),\n abortController: lifetime,\n ...(executablePath.length === 0 ? {} : { pathToClaudeCodeExecutable: executablePath }),\n },\n })\n try {\n // Control responses only arrive while the message stream is pumped.\n void (async () => { for await (const _ of query) { /* drain */ } })().catch(() => undefined)\n // Aborting tears the probe process down, but the SDK's pending control\n // request is not documented to settle with it — and an unsettled one hangs\n // the route (and the browser connection serving it) for the life of the\n // Host. The deadline is therefore enforced here too, not only on the\n // process.\n const read = await Promise.race([\n readPlanUsageFrom(query),\n new Promise<never>((_resolve, reject) => {\n const deadline = setTimeout(() => reject(new Error('dsh-claude: the plan usage request did not answer in time')), PLAN_USAGE_TIMEOUT_MS)\n deadline.unref?.()\n }),\n ])\n return normalizePlanUsage(read, fetchedAt)\n } finally {\n clearTimeout(timer)\n lifetime.abort()\n }\n}\n\n// ponytail: a module-level latest-value cache, not a store class. The plugin\n// runs one supervisor per Host process and the report is global to the Claude\n// account, so per-session state would buy nothing. Promote to a keyed store\n// only if the plugin ever serves more than one Claude account at a time.\nlet latest: PlanUsageReport | undefined\n\nexport function recordPlanUsage(report: PlanUsageReport): void {\n latest = report\n}\n\nexport function latestPlanUsage(): PlanUsageReport | undefined {\n return latest\n}\n\n/** Test seam: drop the cached report. */\nexport function resetPlanUsage(): void {\n latest = undefined\n}\n","import { EventEmitter } from 'node:events'\nimport type { Readable, Writable } from 'node:stream'\nimport type { SpawnOptions, SpawnedProcess } from '@anthropic-ai/claude-agent-sdk'\nimport {\n DSH_ENV_PREFIX,\n SENSITIVE_ENV_PATTERN,\n type SubprocessHandle,\n type SubprocessRuntime,\n} from '@deepseek-ai/dsh-subprocess'\n\nexport const CLAUDE_PROCESS_GRACE_MS = 2_000\nexport const CLAUDE_STDERR_TAIL_BYTES = 32 * 1024\n\nconst ADDITIONAL_SENSITIVE_ENV_PATTERN = /(?:authorization|cookie|credential|database[_-]?url|private[_-]?key|netrc)/iu\n\nexport function scrubClaudeSpawnEnv(env: Readonly<Record<string, string | undefined>>): NodeJS.ProcessEnv {\n const safe: NodeJS.ProcessEnv = {}\n for (const [key, value] of Object.entries(env)) {\n if (value === undefined) continue\n if (key.toUpperCase().startsWith(DSH_ENV_PREFIX)) continue\n if (SENSITIVE_ENV_PATTERN.test(key)) continue\n if (ADDITIONAL_SENSITIVE_ENV_PATTERN.test(key)) continue\n safe[key] = value\n }\n return safe\n}\n\nexport class ManagedClaudeProcess extends EventEmitter implements SpawnedProcess {\n readonly stdin: Writable\n readonly stdout: Readable\n readonly handle: SubprocessHandle\n #killed = false\n #exitCode: number | null = null\n #signalCode: NodeJS.Signals | null = null\n\n constructor(handle: SubprocessHandle) {\n super()\n if (handle.stdin === undefined || handle.stdout === undefined) {\n throw new Error('dsh-claude: managed Claude process requires piped stdin/stdout')\n }\n this.handle = handle\n this.stdin = handle.stdin\n this.stdout = handle.stdout\n void handle.done.then(\n outcome => {\n this.#exitCode = outcome.exitCode\n this.#signalCode = outcome.signal\n this.emit('exit', outcome.exitCode, outcome.signal)\n },\n error => {\n this.emit('error', error instanceof Error ? error : new Error(String(error)))\n },\n )\n }\n\n get killed(): boolean {\n return this.#killed\n }\n\n get exitCode(): number | null {\n return this.#exitCode\n }\n\n get signalCode(): NodeJS.Signals | null {\n return this.#signalCode\n }\n\n kill(signal: NodeJS.Signals): boolean {\n if (this.#exitCode !== null || this.#signalCode !== null) return false\n this.#killed = true\n this.handle.terminate()\n return true\n }\n\n stderrTail(): string {\n return this.handle.collected.stderr?.readFrom(0).text ?? ''\n }\n}\n\nexport type SpawnObserver = (process: ManagedClaudeProcess, options: SpawnOptions) => void\n\nexport function createManagedClaudeSpawner(\n runtime: Pick<SubprocessRuntime, 'spawn'>,\n executablePath: string,\n observe?: SpawnObserver,\n): (options: SpawnOptions) => SpawnedProcess {\n return options => {\n if (options.command !== executablePath) {\n throw new Error(`dsh-claude: SDK requested unexpected executable ${JSON.stringify(options.command)}`)\n }\n const handle = runtime.spawn({\n argv: [executablePath, ...options.args],\n cwd: options.cwd ?? process.cwd(),\n stdio: {\n stdin: 'pipe',\n stdout: 'pipe',\n stderr: { maxBytes: CLAUDE_STDERR_TAIL_BYTES },\n },\n graceMs: CLAUDE_PROCESS_GRACE_MS,\n signal: options.signal,\n env: scrubClaudeSpawnEnv(options.env),\n })\n const managed = new ManagedClaudeProcess(handle)\n observe?.(managed, options)\n return managed\n }\n}\n","import { randomUUID } from 'node:crypto'\nimport {\n query as claudeQuery,\n type EffortLevel,\n type Options as ClaudeOptions,\n type PermissionMode,\n type Query,\n type SDKControlGetContextUsageResponse,\n type SDKMessage,\n type SDKUserMessage,\n type Settings as ClaudeSettings,\n type SlashCommand,\n} from '@anthropic-ai/claude-agent-sdk'\nimport type { Agent } from '@deepseek-ai/dsh-agent'\nimport { ToolCallId, createToolResultMessage } from '@deepseek-ai/dsh-llm'\nimport type { ApprovalService } from '@deepseek-ai/dsh-user-approval'\nimport type { UserQuestionService } from '@deepseek-ai/dsh-user-questions'\nimport type { SubprocessRuntime } from '@deepseek-ai/dsh-subprocess'\nimport { AsyncQueue } from './async-queue.ts'\nimport { DEFAULT_CLAUDE_RENDER_MODE, TASK_TOOL_NAMES, type ClaudeRenderMode } from './constants.ts'\nimport {\n currentClaudeActivityCursor,\n redactText,\n safeDetail,\n type ClaudeActivityCursor,\n type ClaudeActivityInput,\n type ClaudeTaskInfo,\n type ClaudeUsage,\n} from './events.ts'\nimport { createPermissionBridge } from './permission.ts'\nimport { createUserQuestionBridge } from './user-question.ts'\nimport { ClaudeSidecarRepository } from './sidecar.ts'\nimport { CLAUDE_PRESENTER_NAMES, dynamicPresenterDefinition } from './presenters.ts'\nimport { normalizeSdkMessage, type NormalizedSdkMessage } from './sdk-messages.ts'\nimport { readPlanUsageFrom } from './plan-usage.ts'\nimport { createManagedClaudeSpawner, type ManagedClaudeProcess } from './spawn.ts'\n\nexport const CLAUDE_INITIALIZATION_TIMEOUT_MS = 30_000\nexport const CLAUDE_INTERRUPT_TIMEOUT_MS = 5_000\n/** Control requests must settle; a wedged one must not clog the metadata chain. */\nexport const CLAUDE_METADATA_TIMEOUT_MS = 15_000\n\nexport type ClaudeSupervisorState =\n | 'starting'\n | 'idle'\n | 'running'\n | 'interrupting'\n | 'disconnected'\n | 'outcome-unknown'\n | 'disposed'\n\nexport interface ClaudeSupervisorConfig {\n executablePath: string\n idleTimeoutMs: number\n maxProcesses: number\n defaultModel: string\n /** Which renderer the visible turn is produced for; read per message so a\n * Settings change lands on the next turn without a Host restart. */\n renderMode?: ClaudeRenderMode\n}\n\nexport type ClaudeTurnStreamEvent =\n | { type: 'text-delta'; text: string }\n /** One settled Claude thinking block, forwarded only for the native\n * renderer, which draws it as a DSH reasoning block. */\n | { type: 'thinking'; text: string }\n | { type: 'usage'; usage: ClaudeUsage }\n | { type: 'segment-complete'; text: string }\n | { type: 'complete'; text: string }\n\nexport type ClaudeThinkingMode = 'off' | 'ultracode' | EffortLevel\n\nexport type DshSandboxMode = 'read-only' | 'workspace-write' | 'danger-full-access'\n\nconst CLAUDE_MODE_BY_SANDBOX: Readonly<Record<DshSandboxMode, PermissionMode>> = {\n 'read-only': 'plan',\n 'workspace-write': 'acceptEdits',\n 'danger-full-access': 'bypassPermissions',\n}\n\n/** Fold DSH's native access selector into Claude Code's closest permission mode. */\nexport function claudePermissionMode(events: readonly { type: string; data: unknown }[]): PermissionMode {\n for (let index = events.length - 1; index >= 0; index -= 1) {\n const event = events[index]\n if (event?.type !== 'sandbox/mode') continue\n const mode = (event.data as { mode?: unknown }).mode\n return typeof mode === 'string' && mode in CLAUDE_MODE_BY_SANDBOX\n ? CLAUDE_MODE_BY_SANDBOX[mode as DshSandboxMode]\n : 'plan'\n }\n return 'plan'\n}\n\nexport interface ClaudeTurnRequest {\n agent: Agent\n prompt: SDKUserMessage['message']['content']\n model?: string\n thinkingMode?: ClaudeThinkingMode\n signal?: AbortSignal\n}\n\nexport interface ClaudeSupervisorSnapshot {\n sessionId: string\n claudeSessionId?: string\n state: ClaudeSupervisorState\n cwd: string\n model: string\n thinkingMode?: ClaudeThinkingMode\n lastUsedAt: number\n pid?: number\n}\n\nexport class ClaudeTurnBusyError extends Error {\n constructor(sessionId: string) {\n super(`Claude Code session ${sessionId} already has an active or interrupting turn`)\n this.name = 'ClaudeTurnBusyError'\n }\n}\n\nexport class ClaudeOutcomeUnknownError extends Error {\n constructor(message = 'Claude Code exited after activity; side-effect outcome is unknown and the prompt was not replayed') {\n super(message)\n this.name = 'ClaudeOutcomeUnknownError'\n }\n}\n\nexport class ClaudeProtocolError extends Error {\n constructor(message: string) {\n super(message)\n this.name = 'ClaudeProtocolError'\n }\n}\n\nexport class ClaudeProcessLimitError extends Error {\n constructor(maxProcesses: number) {\n super(`Claude Code process limit reached (${maxProcesses}) and no idle session can be evicted`)\n this.name = 'ClaudeProcessLimitError'\n }\n}\n\nexport type ClaudeQueryFactory = (params: {\n prompt: AsyncIterable<SDKUserMessage>\n options: ClaudeOptions\n}) => Query\n\ninterface ActiveTurn {\n agent: Agent\n cursor: ClaudeActivityCursor\n output: AsyncQueue<ClaudeTurnStreamEvent>\n promptUuid: ReturnType<typeof randomUUID>\n phase: 'primary' | 'waiting-tasks' | 'follow-up'\n sawActivity: boolean\n sawTextDelta: boolean\n text: string\n /** Visible prose for the current top-level assistant segment. */\n transcriptText: string\n /** Stable sidecar ordinal reused while the current assistant segment grows. */\n transcriptTextOrdinal: number | undefined\n thinking: string\n /** Newest single-call prompt accounting; what DSH's context meter divides. */\n requestUsage: ClaudeUsage | undefined\n /** When this turn was admitted, and when it first put a token on screen.\n * The transcript has no other clock: activities carry no timestamps. */\n startedAt: number\n firstOutputAt: number | undefined\n aborted: boolean\n deniedToolUseIds: Set<string>\n /** Root tool calls still waiting for their result, by toolUseId, with the\n * tool name a result carries none of. Emptied as results arrive, so what\n * remains when a turn ends is exactly what never got an answer. */\n openCalls: Map<string, string>\n signal?: AbortSignal\n abortListener?: () => void\n}\n\ninterface SupervisorEntry {\n sessionId: string\n ownerAgent: Agent\n cwd: string\n model: string\n thinkingMode: ClaudeThinkingMode | undefined\n permissionMode: PermissionMode\n state: ClaudeSupervisorState\n lastUsedAt: number\n input: AsyncQueue<SDKUserMessage>\n query: Query\n /** Official SDK initialization control request; no stdin nudge is required. */\n sdkInitialization: Promise<void>\n lifetime: AbortController\n process: ManagedClaudeProcess | undefined\n claudeSessionId: string | undefined\n active: ActiveTurn | undefined\n idleTimer: ReturnType<typeof setTimeout> | undefined\n /** Whether the message stream has emitted system/init for session binding. */\n initialized: boolean\n expectedResume: string | undefined\n /** Newest main-chain entry uuid Claude emitted; the anchor a rewind of the\n * next turn forks at. Sidechain (subagent) entries are not chain entries. */\n lastChainUuid: string | undefined\n /** Whether this process consumed an armed rewind fork target at spawn. */\n consumedRewind: boolean\n /** Live Claude task board (subagents and background tasks), keyed by task id. */\n tasks: Map<string, ClaudeTaskInfo>\n /** Last time a task snapshot was persisted (progress throttling). */\n taskSnapshotAt: number\n /** Pending throttled snapshot flush timer. */\n taskSnapshotTimer: ReturnType<typeof setTimeout> | undefined\n pump: Promise<void>\n}\n\nfunction abortFailure(): Error {\n const error = new Error('Claude Code turn aborted')\n error.name = 'AbortError'\n return error\n}\n\nfunction signalAborted(signal: AbortSignal | undefined): boolean {\n return signal?.aborted === true\n}\n\nasync function withTimeout<T>(operation: Promise<T>, timeoutMs: number, label: string): Promise<T> {\n let timer: ReturnType<typeof setTimeout> | undefined\n try {\n return await Promise.race([\n operation,\n new Promise<never>((_resolve, reject) => {\n timer = setTimeout(() => reject(new Error(`${label} timed out after ${timeoutMs}ms`)), timeoutMs)\n timer.unref?.()\n }),\n ])\n } finally {\n if (timer !== undefined) clearTimeout(timer)\n }\n}\n\n/** The uuid of one main-chain transcript entry, or undefined for anything a\n * rewind must not fork at: stream partials, results, and sidechain traffic. */\nfunction chainEntryUuid(message: SDKMessage): string | undefined {\n if (message.type !== 'assistant' && message.type !== 'user') return undefined\n const envelope = message as { uuid?: unknown; parent_tool_use_id?: unknown }\n if (typeof envelope.parent_tool_use_id === 'string') return undefined\n return typeof envelope.uuid === 'string' && envelope.uuid.length > 0 ? envelope.uuid : undefined\n}\n\nfunction sdkUserMessage(prompt: SDKUserMessage['message']['content'], uuid: ReturnType<typeof randomUUID>): SDKUserMessage {\n return {\n type: 'user',\n message: { role: 'user', content: prompt },\n parent_tool_use_id: null,\n uuid,\n }\n}\n\nconst BACKGROUND_TASK_REPORT_PROMPT = [\n 'The background tasks launched by your preceding response have now all settled.',\n 'Report their final completed or failed outcomes concisely to the user.',\n 'Do not start new tools or tasks, and do not repeat the earlier progress update.',\n].join(' ')\n\nfunction usageSummary(usage: ClaudeUsage): string {\n const input = usage.inputTokens ?? 0\n const output = usage.outputTokens ?? 0\n const cost = usage.cumulativeCostUsd === undefined\n ? ''\n : ` · $${usage.cumulativeCostUsd.toFixed(4)} cumulative`\n return `${input} input / ${output} output tokens${cost}`\n}\n\nfunction errorSummary(error: unknown): string {\n return error instanceof Error ? error.message : String(error)\n}\n\n/** Root-call activity summary; subagent dispatches lead with Claude's own task description. */\nfunction rootCallSummary(toolName: string, input: unknown): string {\n if (TASK_TOOL_NAMES.has(toolName)) {\n const description = input !== null && typeof input === 'object'\n ? (input as Record<string, unknown>).description\n : undefined\n if (typeof description === 'string' && description.length > 0) return description\n return 'Claude dispatched a subagent'\n }\n return `Claude called ${toolName}`\n}\n\nexport class ClaudeSupervisor {\n readonly #entries = new Map<string, SupervisorEntry>()\n readonly #interruptions = new Map<string, Promise<void>>()\n readonly #runtime: Pick<SubprocessRuntime, 'spawn'>\n readonly #approval: Pick<ApprovalService, 'request'>\n readonly #userQuestions: Pick<UserQuestionService, 'ask'>\n readonly #config: ClaudeSupervisorConfig\n readonly #queryFactory: ClaudeQueryFactory\n readonly #runDetached: <T>(operation: () => T) => T\n readonly #sidecar: ClaudeSidecarRepository\n readonly #dynamicPresenterNames = new WeakMap<Agent, Set<string>>()\n readonly #contextWindows = new Map<string, number>()\n #disposed = false\n #admissionGate: Promise<void> = Promise.resolve()\n\n constructor(dependencies: {\n runtime: Pick<SubprocessRuntime, 'spawn'>\n approval: Pick<ApprovalService, 'request'>\n userQuestions: Pick<UserQuestionService, 'ask'>\n config: ClaudeSupervisorConfig\n queryFactory?: ClaudeQueryFactory\n runDetached?: <T>(operation: () => T) => T\n sidecar?: ClaudeSidecarRepository\n }) {\n this.#runtime = dependencies.runtime\n this.#approval = dependencies.approval\n this.#userQuestions = dependencies.userQuestions\n this.#config = dependencies.config\n this.#queryFactory = dependencies.queryFactory ?? (params => claudeQuery(params))\n this.#runDetached = dependencies.runDetached ?? (operation => operation())\n this.#sidecar = dependencies.sidecar ?? new ClaudeSidecarRepository()\n }\n\n snapshots(): ClaudeSupervisorSnapshot[] {\n return [...this.#entries.values()].map(entry => ({\n sessionId: entry.sessionId,\n ...(entry.claudeSessionId === undefined ? {} : { claudeSessionId: entry.claudeSessionId }),\n state: entry.state,\n cwd: entry.cwd,\n model: entry.model,\n ...(entry.thinkingMode === undefined ? {} : { thinkingMode: entry.thinkingMode }),\n lastUsedAt: entry.lastUsedAt,\n ...(entry.process === undefined ? {} : { pid: entry.process.handle.pid }),\n }))\n }\n\n supportedCommands(agent: Agent, model = this.#config.defaultModel): Promise<readonly SlashCommand[]> {\n return this.#runMetadata(agent, model, query => query.supportedCommands())\n }\n\n async contextUsage(agent: Agent, model = this.#config.defaultModel): Promise<SDKControlGetContextUsageResponse> {\n const usage = await this.#runMetadata(agent, model, query => query.getContextUsage())\n this.#recordContextWindow(model, usage)\n return usage\n }\n\n /** Cache a window under both the selector id the caller asked for and the\n * concrete model the CLI reports, so either name resolves it later. */\n #recordContextWindow(model: string, usage: SDKControlGetContextUsageResponse): void {\n const contextWindow = usage.rawMaxTokens > 0 ? usage.rawMaxTokens : usage.maxTokens\n if (contextWindow <= 0) return\n this.#contextWindows.set(model, contextWindow)\n this.#contextWindows.set(usage.model, contextWindow)\n }\n\n /** Learn a model's context window the first time a turn finishes on it.\n *\n * DSH hides its context meter entirely unless the route publishes a\n * capacity, and these numbers move with Claude releases — so none are\n * hardcoded; the CLI is asked over the session's own live process.\n *\n * Turn completion is the earliest honest moment to ask. `entry.model` is\n * already the model that just ran, so no model switch is provoked — which\n * rules out asking from `resolveModel`, since DSH resolves every model in\n * the catalog to build its picker and `#metadataEntry` would switch the live\n * session once per entry. And nothing is lost by waiting: the meter needs a\n * usage sample too, and no turn has reported one before the first turn ends.\n *\n * Best-effort — a failure leaves the window unknown (the meter stays hidden,\n * exactly as before) and the next completed turn tries again. */\n async #learnContextWindow(entry: SupervisorEntry): Promise<void> {\n if (this.#contextWindows.has(entry.model)) return\n try {\n const usage = await withTimeout(\n entry.query.getContextUsage(),\n CLAUDE_METADATA_TIMEOUT_MS,\n 'Claude context window probe',\n )\n this.#recordContextWindow(entry.model, usage)\n } catch {\n // Intentionally silent: this is opportunistic chrome, never turn-critical.\n }\n }\n\n contextWindow(model: string): number | undefined {\n return this.#contextWindows.get(model)\n }\n\n /** Raw `/usage` payload, read over a session's existing process. Only the\n * idle-time metadata bridge uses this; a user-triggered refresh runs\n * probePlanUsage instead so it never waits on, or perturbs, a session. */\n planUsage(agent: Agent, model = this.#config.defaultModel): Promise<unknown> {\n return this.#runMetadata(agent, model, query => readPlanUsageFrom(query))\n }\n\n runTurn(request: ClaudeTurnRequest): Promise<AsyncIterable<ClaudeTurnStreamEvent>> {\n const interruption = this.#interruptions.get(request.agent.id as string)\n if (interruption !== undefined) return interruption.then(() => this.runTurn(request))\n const operation = this.#admissionGate.then(() => this.#runTurnAdmitted(request))\n this.#admissionGate = operation.then(() => undefined, () => undefined)\n return operation\n }\n\n async #runTurnAdmitted(request: ClaudeTurnRequest): Promise<AsyncIterable<ClaudeTurnStreamEvent>> {\n if (this.#disposed) throw new Error('dsh-claude: supervisor is disposed')\n if (signalAborted(request.signal)) throw abortFailure()\n const sessionId = request.agent.id as string\n let entry = this.#entries.get(sessionId)\n if (entry?.state === 'disposed' || entry?.state === 'disconnected' || entry?.state === 'outcome-unknown') {\n this.#entries.delete(sessionId)\n await this.#disposeEntry(entry)\n entry = undefined\n }\n if (entry === undefined) {\n await this.#makeRoom()\n entry = await this.#createEntry(request.agent, request.model ?? this.#config.defaultModel, request.thinkingMode)\n this.#entries.set(sessionId, entry)\n }\n if (entry.ownerAgent !== request.agent) {\n throw new Error(`dsh-claude: live agent identity changed for session ${sessionId}`)\n }\n if (entry.active !== undefined || entry.state === 'interrupting') throw new ClaudeTurnBusyError(sessionId)\n await entry.sdkInitialization\n\n if (entry.idleTimer !== undefined) {\n clearTimeout(entry.idleTimer)\n entry.idleTimer = undefined\n }\n const model = request.model ?? this.#config.defaultModel\n if (request.thinkingMode !== entry.thinkingMode) {\n // The SDK only accepts effort/thinking at query start, so rebuild the\n // query; the persisted Claude session binding keeps the context.\n this.#entries.delete(sessionId)\n await this.#disposeEntry(entry)\n entry = await this.#createEntry(request.agent, model, request.thinkingMode)\n this.#entries.set(sessionId, entry)\n await entry.sdkInitialization\n } else {\n await this.#syncPermissionMode(entry)\n if (model !== entry.model) {\n await this.#control(entry, entry.query.setModel(model), 'Claude Code model switch')\n entry.model = model\n }\n }\n\n const promptUuid = randomUUID()\n const cursor = currentClaudeActivityCursor(request.agent.session.events)\n const projection = await this.#sidecar.read(sessionId)\n cursor.nextOrdinal = projection.activities.reduce((next, activity) => (\n activity.turn === cursor.turn && activity.step === cursor.step\n ? Math.max(next, activity.ordinal + 1)\n : next\n ), 0)\n const active: ActiveTurn = {\n agent: request.agent,\n cursor,\n output: new AsyncQueue<ClaudeTurnStreamEvent>(),\n promptUuid,\n phase: 'primary',\n sawActivity: false,\n sawTextDelta: false,\n text: '',\n transcriptText: '',\n transcriptTextOrdinal: undefined,\n thinking: '',\n requestUsage: undefined,\n startedAt: Date.now(),\n firstOutputAt: undefined,\n aborted: false,\n deniedToolUseIds: new Set(),\n openCalls: new Map(),\n ...(request.signal === undefined ? {} : { signal: request.signal }),\n }\n entry.active = active\n entry.state = 'running'\n entry.lastUsedAt = Date.now()\n try {\n await this.#appendActivity(active, {\n kind: 'status',\n phase: 'started',\n title: 'Claude Code turn started',\n })\n } catch (error) {\n active.output.fail(error)\n entry.active = undefined\n if (this.#entries.get(sessionId) === entry) this.#entries.delete(sessionId)\n await this.#disposeEntry(entry)\n throw error\n }\n if (signalAborted(request.signal)) {\n active.aborted = true\n active.output.fail(abortFailure())\n await this.#appendActivity(active, {\n kind: 'status',\n phase: 'failed',\n title: 'Claude Code turn cancelled before submission',\n })\n entry.active = undefined\n entry.state = 'idle'\n entry.lastUsedAt = Date.now()\n this.#armIdleTimer(entry)\n return active.output\n }\n if (request.signal !== undefined) {\n const abortListener = () => { void this.#startInterrupt(entry as SupervisorEntry) }\n active.abortListener = abortListener\n request.signal.addEventListener('abort', abortListener, { once: true })\n }\n entry.input.push(sdkUserMessage(request.prompt, promptUuid))\n return active.output\n }\n\n #runMetadata<T>(\n agent: Agent,\n model: string,\n operation: (query: Query, entry: SupervisorEntry) => Promise<T>,\n ): Promise<T> {\n const admitted = this.#admissionGate.then(async () => {\n if (this.#disposed) throw new Error('dsh-claude: supervisor is disposed')\n const entry = await this.#metadataEntry(agent, model)\n try {\n // Use the SDK's initialize control request. system/init is emitted only\n // after the first real stdin message and is reserved for session binding.\n await entry.sdkInitialization\n return await this.#control(entry, operation(entry.query, entry), 'Claude metadata request')\n } finally {\n entry.lastUsedAt = Date.now()\n if (entry.active === undefined && entry.state === 'idle') this.#armIdleTimer(entry)\n }\n })\n this.#admissionGate = admitted.then(() => undefined, () => undefined)\n return admitted\n }\n\n async #metadataEntry(agent: Agent, model: string): Promise<SupervisorEntry> {\n const sessionId = agent.id as string\n let entry = this.#entries.get(sessionId)\n if (entry?.state === 'disposed' || entry?.state === 'disconnected' || entry?.state === 'outcome-unknown') {\n this.#entries.delete(sessionId)\n await this.#disposeEntry(entry)\n entry = undefined\n }\n if (entry === undefined) {\n await this.#makeRoom()\n entry = await this.#createEntry(agent, model)\n this.#entries.set(sessionId, entry)\n }\n if (entry.ownerAgent !== agent) {\n throw new Error(`dsh-claude: live agent identity changed for session ${sessionId}`)\n }\n if (entry.active !== undefined || entry.state === 'interrupting') throw new ClaudeTurnBusyError(sessionId)\n if (entry.idleTimer !== undefined) {\n clearTimeout(entry.idleTimer)\n entry.idleTimer = undefined\n }\n await this.#syncPermissionMode(entry)\n if (model !== entry.model) {\n await this.#control(entry, entry.query.setModel(model), 'Claude Code model switch')\n entry.model = model\n }\n return entry\n }\n\n /** Run one SDK control request against a live entry, and discard the entry if\n * it does not answer.\n *\n * Turn admission and every metadata read share one process-wide gate, so an\n * unbounded control request stalls every session until the Host restarts.\n * Bounding it is only half the cure: a timeout also proves this query has\n * stopped answering, and keeping the entry means the next caller reuses the\n * same dead process — timing out again, forever. Discarding it lets the next\n * attempt spawn a fresh one. Every control request goes through here so a\n * new call site cannot quietly reintroduce either half. */\n async #control<T>(\n entry: SupervisorEntry,\n operation: Promise<T>,\n label: string,\n timeoutMs = CLAUDE_METADATA_TIMEOUT_MS,\n ): Promise<T> {\n try {\n return await withTimeout(operation, timeoutMs, label)\n } catch (error) {\n if (this.#entries.get(entry.sessionId) === entry) this.#entries.delete(entry.sessionId)\n await this.#disposeEntry(entry)\n throw error\n }\n }\n\n async #syncPermissionMode(entry: SupervisorEntry): Promise<void> {\n const mode = claudePermissionMode(entry.ownerAgent.session.events)\n if (mode === entry.permissionMode) return\n await this.#control(entry, entry.query.setPermissionMode(mode), 'Claude Code permission mode switch')\n entry.permissionMode = mode\n }\n\n async disposeSession(sessionId: string): Promise<void> {\n const entry = this.#entries.get(sessionId)\n if (entry === undefined) return\n this.#entries.delete(sessionId)\n await this.#disposeEntry(entry)\n }\n\n async dispose(): Promise<void> {\n if (this.#disposed) return\n this.#disposed = true\n const entries = [...this.#entries.values()]\n this.#entries.clear()\n await Promise.allSettled(entries.map(entry => this.#disposeEntry(entry)))\n }\n\n async #makeRoom(): Promise<void> {\n if (this.#entries.size < this.#config.maxProcesses) return\n const idle = [...this.#entries.values()]\n .filter(entry => entry.active === undefined && entry.state === 'idle')\n .sort((left, right) => left.lastUsedAt - right.lastUsedAt)[0]\n if (idle === undefined) throw new ClaudeProcessLimitError(this.#config.maxProcesses)\n this.#entries.delete(idle.sessionId)\n await this.#disposeEntry(idle)\n }\n\n async #createEntry(agent: Agent, model: string, thinkingMode?: ClaudeThinkingMode): Promise<SupervisorEntry> {\n const sessionId = agent.id as string\n const cwd = agent.session.header.cwd ?? process.cwd()\n const input = new AsyncQueue<SDKUserMessage>()\n const lifetime = new AbortController()\n const projection = await this.#sidecar.importLegacy(sessionId, agent.session.events)\n const binding = projection.binding\n // A rewound session resumes at the kept turn's chain anchor, or drops its\n // binding entirely when the rewind discarded every turn. The truncating\n // resume may land in a different Claude session id, so the identity guard\n // stands down for exactly this spawn and re-binds from system/init.\n const pendingRewind = projection.rewind?.pending\n const forkAt = pendingRewind !== undefined && 'resumeAt' in pendingRewind ? pendingRewind.resumeAt : undefined\n const startFresh = pendingRewind !== undefined && 'fresh' in pendingRewind\n const permissionMode = claudePermissionMode(agent.session.events)\n const entry = {\n sessionId,\n ownerAgent: agent,\n cwd,\n model,\n thinkingMode,\n permissionMode,\n state: 'starting' as ClaudeSupervisorState,\n lastUsedAt: Date.now(),\n input,\n lifetime,\n claudeSessionId: startFresh ? undefined : binding?.claudeSessionId,\n expectedResume: startFresh || forkAt !== undefined ? undefined : binding?.claudeSessionId,\n lastChainUuid: undefined,\n consumedRewind: pendingRewind !== undefined,\n initialized: false,\n idleTimer: undefined,\n tasks: new Map<string, ClaudeTaskInfo>(),\n taskSnapshotAt: 0,\n taskSnapshotTimer: undefined,\n } as SupervisorEntry\n\n const activeInteraction = () => {\n const active = entry.active\n return active === undefined ? undefined : {\n agent: active.agent,\n cursor: active.cursor,\n markActivity: () => { active.sawActivity = true },\n recordDenial: (toolUseId: string) => { active.deniedToolUseIds.add(toolUseId) },\n hasFullAccess: async () => {\n await this.#syncPermissionMode(entry)\n return entry.permissionMode === 'bypassPermissions'\n },\n appendActivity: (activity: ClaudeActivityInput) => this.#appendActivity(active, activity),\n }\n }\n const userQuestion = createUserQuestionBridge(this.#userQuestions, activeInteraction)\n const canUseTool = createPermissionBridge(this.#approval, activeInteraction, userQuestion)\n const options: ClaudeOptions = {\n pathToClaudeCodeExecutable: this.#config.executablePath,\n cwd,\n settingSources: ['user', 'project', 'local'],\n systemPrompt: { type: 'preset', preset: 'claude_code' },\n tools: { type: 'preset', preset: 'claude_code' },\n includePartialMessages: true,\n permissionMode,\n allowDangerouslySkipPermissions: true,\n canUseTool,\n abortController: lifetime,\n spawnClaudeCodeProcess: createManagedClaudeSpawner(this.#runtime, this.#config.executablePath, process => {\n entry.process = process\n }),\n ...(binding === undefined || startFresh ? {} : {\n resume: binding.claudeSessionId,\n ...(forkAt === undefined ? {} : { resumeSessionAt: forkAt }),\n }),\n model,\n ...(thinkingMode === undefined\n ? {}\n : thinkingMode === 'off'\n ? { thinking: { type: 'disabled' } as const }\n : thinkingMode === 'ultracode'\n ? { settings: { ultracode: true } satisfies ClaudeSettings }\n : { effort: thinkingMode }),\n }\n entry.query = this.#queryFactory({ prompt: input, options })\n entry.pump = this.#runDetached(() => this.#pump(entry))\n entry.sdkInitialization = withTimeout(\n entry.query.initializationResult(),\n CLAUDE_INITIALIZATION_TIMEOUT_MS,\n 'Claude SDK initialization',\n ).then(() => {\n if (entry.state === 'starting') entry.state = 'idle'\n })\n void entry.sdkInitialization.catch(error => this.#handleDisconnect(entry, error))\n return entry\n }\n\n async #pump(entry: SupervisorEntry): Promise<void> {\n try {\n for await (const sdkMessage of entry.query) {\n const chainUuid = chainEntryUuid(sdkMessage as SDKMessage)\n if (chainUuid !== undefined) entry.lastChainUuid = chainUuid\n for (const message of normalizeSdkMessage(sdkMessage as SDKMessage)) {\n await this.#handleMessage(entry, message)\n }\n }\n if (entry.state !== 'disposed') await this.#handleDisconnect(entry, new Error('Claude Code stream ended'))\n } catch (error) {\n if (entry.state !== 'disposed') await this.#handleDisconnect(entry, error)\n }\n }\n\n async #handleMessage(entry: SupervisorEntry, message: NormalizedSdkMessage): Promise<void> {\n if (message.kind === 'init') {\n // Claude Code can re-emit system/init across turns in long-lived\n // streaming-input mode (e.g. the auth-error path). Treat it idempotently:\n // refresh the session id/version and negotiated state, and only reject a\n // genuine identity/cwd mismatch.\n const firstInitialization = !entry.initialized\n if (entry.expectedResume !== undefined && message.sessionId !== entry.expectedResume) {\n throw new ClaudeProtocolError(`Claude Code resumed unexpected session ${message.sessionId}; expected ${entry.expectedResume}`)\n }\n if (message.cwd !== entry.cwd) {\n throw new ClaudeProtocolError(`Claude Code initialized in unexpected cwd ${message.cwd}; expected ${entry.cwd}`)\n }\n entry.initialized = true\n entry.claudeSessionId = message.sessionId\n entry.state = entry.active === undefined ? 'idle' : 'running'\n // A newly created Query cannot retain tasks from the previous process,\n // but repeated init messages from this same long-lived Query are only\n // protocol refreshes and must not erase background work still running.\n if (firstInitialization && entry.tasks.size > 0) {\n entry.tasks.clear()\n await this.#flushTasksSnapshot(entry)\n }\n await this.#sidecar.writeBinding(entry.sessionId, {\n claudeSessionId: message.sessionId,\n cliVersion: message.cliVersion,\n cwd: message.cwd,\n })\n // The fork target is spent the moment Claude resumes at it; leaving it\n // armed would re-truncate the session on the next respawn.\n if (entry.consumedRewind) {\n entry.consumedRewind = false\n await this.#sidecar.clearRewindPending(entry.sessionId)\n }\n return\n }\n\n // Task lifecycle is session-scoped, not turn-scoped: background tasks and\n // subagents settle while no DSH turn is active, and their notifications\n // must still reach the task board instead of being dropped with turn-less\n // messages below.\n const taskId = message.kind === 'subagent' ? message.taskId : undefined\n if (message.kind === 'subagent' && taskId !== undefined) {\n await this.#trackTask(entry, message, taskId, entry.active?.cursor.turn)\n } else if (message.kind === 'background-tasks') {\n await this.#trackBackgroundLevel(entry, message.tasks, entry.active?.cursor.turn)\n }\n\n const active = entry.active\n if (active === undefined) return\n if (message.kind === 'result') {\n if (entry.claudeSessionId === undefined) {\n throw new ClaudeProtocolError('Claude Code sent a result before initialization')\n }\n if (message.sessionId !== entry.claudeSessionId) {\n throw new ClaudeProtocolError(`Claude Code result session ${message.sessionId} does not match ${entry.claudeSessionId}`)\n }\n if (active.phase === 'waiting-tasks') {\n // The CLI may automatically react to each completed background task and\n // emit a top-level result, correlated or not. Publish that prose as a\n // completed progress block, but keep the original DSH turn open until\n // every owned task settles and the explicit final report returns.\n await this.#completeProgressSegment(active, message)\n return\n }\n if (message.userMessageUuid !== undefined && message.userMessageUuid !== active.promptUuid) {\n // A stale internal continuation must not settle the explicit final\n // report request. Primary-turn mismatches remain protocol failures.\n if (active.phase === 'follow-up') return\n throw new ClaudeProtocolError(`Claude Code result for user message ${message.userMessageUuid} does not match active request ${active.promptUuid}`)\n }\n await this.#completeTurn(entry, active, message)\n return\n }\n if (message.kind === 'protocol-error') {\n throw new ClaudeProtocolError(`${message.title}: ${JSON.stringify(message.detail).slice(0, 1_000)}`)\n }\n active.sawActivity = true\n\n switch (message.kind) {\n case 'text-delta':\n if (message.parentToolUseId !== undefined) return\n active.sawTextDelta = true\n active.text += message.text\n active.transcriptText += message.text\n await this.#upsertTranscriptText(active)\n active.firstOutputAt ??= Date.now()\n active.output.push({ type: 'text-delta', text: message.text })\n return\n case 'assistant-text':\n if (message.parentToolUseId !== undefined) return\n if (!active.sawTextDelta) {\n // Complete assistant text is the fallback when no partial text delta\n // streamed. Mark text-delta seen so that additional complete\n // assistant records sharing the same message.id (one per completed\n // content block) do not duplicate the text.\n active.sawTextDelta = true\n active.text += message.text\n active.transcriptText += message.text\n await this.#upsertTranscriptText(active)\n active.firstOutputAt ??= Date.now()\n active.output.push({ type: 'text-delta', text: message.text })\n }\n return\n case 'thinking':\n if (message.parentToolUseId !== undefined) return\n if (message.phase === 'updated') {\n active.thinking += message.text\n return\n }\n active.thinking = message.text\n await this.#appendActivity(active, {\n kind: 'thinking',\n phase: 'completed',\n title: 'Claude thinking',\n summary: message.text,\n })\n // The plugin transcript reads thinking off the sidecar; the native\n // renderer needs it on the stream to build a reasoning block.\n if (this.#nativeRendering()) active.output.push({ type: 'thinking', text: message.text })\n return\n case 'tool-call':\n if (message.parentToolUseId === undefined) this.#closeTranscriptTextSegment(active)\n await this.#appendActivity(active, {\n kind: message.parentToolUseId === undefined ? 'tool-call' : 'subagent',\n phase: 'started',\n toolUseId: message.toolUseId,\n ...(message.parentToolUseId === undefined ? {} : { parentToolUseId: message.parentToolUseId }),\n toolName: message.toolName,\n title: message.toolName,\n summary: message.parentToolUseId === undefined ? rootCallSummary(message.toolName, message.input) : `Subagent called ${message.toolName}`,\n detail: message.input,\n })\n if (message.parentToolUseId === undefined) {\n active.openCalls.set(message.toolUseId, message.toolName)\n // Only root calls are mirrored: a subagent's nested tools belong to\n // the Task card that dispatched them, and the native channel has no\n // nesting to hang them under.\n if (this.#nativeRendering()) {\n this.#ensureDynamicPresenter(active.agent, message.toolName)\n await this.#appendNativeToolCall(active, message)\n }\n }\n return\n case 'tool-result':\n active.openCalls.delete(message.toolUseId)\n await this.#appendActivity(active, {\n kind: message.parentToolUseId === undefined ? 'tool-result' : 'subagent',\n phase: message.isError ? 'failed' : 'completed',\n toolUseId: message.toolUseId,\n ...(message.parentToolUseId === undefined ? {} : { parentToolUseId: message.parentToolUseId }),\n title: message.isError ? 'Tool failed' : 'Tool completed',\n detail: message.output,\n isError: message.isError,\n })\n if (message.parentToolUseId === undefined && this.#nativeRendering()) {\n await this.#appendNativeToolResult(active, message)\n }\n return\n case 'subagent':\n await this.#appendActivity(active, {\n kind: 'subagent',\n phase: message.phase,\n ...(message.taskId === undefined ? {} : { taskId: message.taskId }),\n title: message.title,\n summary: message.summary,\n detail: message.detail,\n isError: message.phase === 'failed',\n })\n return\n case 'request-usage':\n // A subagent call bills against its own context, so it never stands in\n // for the main conversation's size.\n if (message.parentToolUseId === undefined) active.requestUsage = message.usage\n return\n case 'compaction':\n // Close the open prose span first: compaction sits *between* what was\n // said before and after it, never inside one text segment.\n this.#closeTranscriptTextSegment(active)\n await this.#appendActivity(active, {\n kind: 'compaction',\n phase: 'completed',\n title: 'Claude compacted the conversation',\n detail: {\n ...(message.trigger === undefined ? {} : { trigger: message.trigger }),\n ...(message.preTokens === undefined ? {} : { preTokens: message.preTokens }),\n ...(message.postTokens === undefined ? {} : { postTokens: message.postTokens }),\n ...(message.durationMs === undefined ? {} : { durationMs: message.durationMs }),\n },\n })\n return\n case 'status':\n case 'warning':\n case 'unknown':\n await this.#appendActivity(active, {\n kind: message.kind === 'status' ? 'status' : 'warning',\n phase: 'updated',\n title: message.title,\n ...('summary' in message ? { summary: message.summary } : {}),\n ...('detail' in message ? { detail: message.detail } : {}),\n })\n return\n case 'permission-denied':\n await this.#appendActivity(active, {\n kind: 'permission',\n phase: 'denied',\n toolUseId: message.toolUseId,\n toolName: message.toolName,\n title: message.toolName,\n summary: message.summary,\n })\n // A denied call never produces a tool result, so the native card would\n // stay pending forever. Settle it as the failure it is.\n if (this.#nativeRendering()) {\n await this.#appendNativeToolResult(active, {\n kind: 'tool-result',\n toolUseId: message.toolUseId,\n output: message.summary,\n isError: true,\n })\n }\n return\n }\n }\n\n /** The turn's accounting with its wall clock attached. The transcript draws\n * this line itself under the plugin renderer: activities carry no\n * timestamps, so a duration it did not measure is a duration nobody has. */\n #timedUsage(active: ActiveTurn, usage: ClaudeUsage): ClaudeUsage {\n const now = Date.now()\n return {\n ...usage,\n durationMs: Math.max(0, now - active.startedAt),\n ...(active.firstOutputAt === undefined ? {} : { ttftMs: Math.max(0, active.firstOutputAt - active.startedAt) }),\n }\n }\n\n #nativeRendering(): boolean {\n return (this.#config.renderMode ?? DEFAULT_CLAUDE_RENDER_MODE) === 'native'\n }\n\n /** Register one presenter-only mirror for a tool name the static preset\n * registry does not cover (MCP tools, newly added built-ins). Runs in the\n * agent scope so the mirror is visible only to this preset's sessions and\n * unwinds with the agent; failure keeps the generic card, never the turn. */\n #ensureDynamicPresenter(agent: Agent, name: string): void {\n if (CLAUDE_PRESENTER_NAMES.has(name)) return\n let known = this.#dynamicPresenterNames.get(agent)\n if (known === undefined) {\n known = new Set<string>()\n this.#dynamicPresenterNames.set(agent, known)\n }\n if (known.has(name)) return\n try {\n agent.ctx.tools.register(dynamicPresenterDefinition(name))\n known.add(name)\n } catch {\n // A late or disposed agent keeps the generic card; presentation must\n // never unsettle the Claude turn.\n }\n }\n\n /** Mirror one root Claude tool call into the durable native tool channel so\n * the host's tool presentation renders it exactly like a DSH-executed call.\n * Presentation duplication is best-effort and never unsettles the turn. */\n async #appendNativeToolCall(\n active: ActiveTurn,\n message: Extract<NormalizedSdkMessage, { kind: 'tool-call' }>,\n ): Promise<void> {\n try {\n await active.agent.session.append('tool/call', {\n turn: active.cursor.turn,\n step: active.cursor.step,\n callId: ToolCallId(message.toolUseId),\n name: message.toolName,\n arguments: safeDetail(message.input) ?? '{}',\n })\n } catch {\n // Presentation duplication must never unsettle the Claude turn.\n }\n }\n\n async #appendNativeToolResult(\n active: ActiveTurn,\n message: Pick<Extract<NormalizedSdkMessage, { kind: 'tool-result' }>, 'kind' | 'toolUseId' | 'output' | 'isError'>,\n ): Promise<void> {\n const text = typeof message.output === 'string' ? redactText(message.output) : safeDetail(message.output) ?? ''\n try {\n await active.agent.session.append('tool/result', {\n turn: active.cursor.turn,\n step: active.cursor.step,\n message: createToolResultMessage({\n callId: ToolCallId(message.toolUseId),\n content: [{ type: 'text', text }],\n isError: message.isError,\n }),\n }, { surfaceOp: 'append' })\n } catch {\n // Presentation duplication must never unsettle the Claude turn.\n }\n }\n\n /** Merge one task lifecycle message into the session's task board. */\n async #trackTask(\n entry: SupervisorEntry,\n message: Extract<NormalizedSdkMessage, { kind: 'subagent' }>,\n taskId: string,\n originTurn: number | undefined,\n ): Promise<void> {\n const previous = entry.tasks.get(taskId)\n const next: ClaudeTaskInfo = {\n taskId,\n description: message.description ?? previous?.description ?? message.title,\n status: message.taskStatus ?? previous?.status ?? 'running',\n }\n const resolvedOriginTurn = previous?.originTurn ?? originTurn\n if (resolvedOriginTurn !== undefined) next.originTurn = resolvedOriginTurn\n const subagentType = message.subagentType ?? previous?.subagentType\n if (subagentType !== undefined) next.subagentType = subagentType\n const taskType = message.taskType ?? previous?.taskType\n if (taskType !== undefined) next.taskType = taskType\n const lastToolName = message.lastToolName ?? previous?.lastToolName\n if (lastToolName !== undefined) next.lastToolName = lastToolName\n const summary = message.summary ?? previous?.summary\n if (summary !== undefined) next.summary = summary\n const usage = message.usage ?? previous?.usage\n if (usage !== undefined) next.usage = usage\n if (previous?.backgrounded === true) next.backgrounded = true\n entry.tasks.set(taskId, next)\n const settled = next.status !== 'running'\n await this.#scheduleTasksSnapshot(entry, settled)\n if (settled) await this.#continueAfterTasks(entry)\n }\n\n /** Fold the background-task level signal into the board (REPLACE semantics\n * for the backgrounded flag: only the listed tasks are detached). */\n async #trackBackgroundLevel(\n entry: SupervisorEntry,\n tasks: readonly { taskId: string; taskType?: string; description: string }[],\n originTurn: number | undefined,\n ): Promise<void> {\n const live = new Set(tasks.map(task => task.taskId))\n let changed = false\n for (const task of tasks) {\n const existing = entry.tasks.get(task.taskId)\n if (existing === undefined) {\n entry.tasks.set(task.taskId, {\n taskId: task.taskId,\n description: task.description,\n status: 'running',\n ...(originTurn === undefined ? {} : { originTurn }),\n ...(task.taskType === undefined ? {} : { taskType: task.taskType }),\n backgrounded: true,\n })\n changed = true\n } else if (existing.backgrounded !== true || existing.status !== 'running') {\n entry.tasks.set(task.taskId, { ...existing, status: 'running', backgrounded: true })\n changed = true\n }\n }\n for (const task of entry.tasks.values()) {\n if (task.backgrounded === true && task.status === 'running' && !live.has(task.taskId)) {\n entry.tasks.set(task.taskId, { ...task, status: 'completed' })\n changed = true\n }\n }\n if (changed) {\n await this.#scheduleTasksSnapshot(entry, true)\n await this.#continueAfterTasks(entry)\n }\n }\n\n #hasRunningTasks(entry: SupervisorEntry, active: ActiveTurn): boolean {\n return [...entry.tasks.values()].some(task => (\n task.originTurn === active.cursor.turn && task.backgrounded === true && task.status === 'running'\n ))\n }\n\n async #continueAfterTasks(entry: SupervisorEntry): Promise<void> {\n const active = entry.active\n if (active === undefined || active.phase !== 'waiting-tasks' || this.#hasRunningTasks(entry, active)) return\n active.phase = 'follow-up'\n active.promptUuid = randomUUID()\n active.sawTextDelta = false\n active.text = ''\n this.#closeTranscriptTextSegment(active)\n active.thinking = ''\n await this.#appendSafely(active, {\n kind: 'status',\n phase: 'updated',\n title: 'Claude Code is reporting background task results',\n })\n entry.input.push(sdkUserMessage(BACKGROUND_TASK_REPORT_PROMPT, active.promptUuid))\n }\n\n /** Persist the task board. Settled transitions flush immediately; progress\n * ticks throttle to one snapshot per second to bound log volume. */\n async #scheduleTasksSnapshot(entry: SupervisorEntry, immediate: boolean): Promise<void> {\n const THROTTLE_MS = 1_000\n const elapsed = Date.now() - entry.taskSnapshotAt\n if (!immediate && elapsed < THROTTLE_MS) {\n if (entry.taskSnapshotTimer === undefined) {\n entry.taskSnapshotTimer = setTimeout(() => {\n entry.taskSnapshotTimer = undefined\n void this.#flushTasksSnapshot(entry)\n }, THROTTLE_MS - elapsed)\n entry.taskSnapshotTimer.unref?.()\n }\n return\n }\n await this.#flushTasksSnapshot(entry)\n }\n\n async #flushTasksSnapshot(entry: SupervisorEntry): Promise<void> {\n if (entry.taskSnapshotTimer !== undefined) {\n clearTimeout(entry.taskSnapshotTimer)\n entry.taskSnapshotTimer = undefined\n }\n entry.taskSnapshotAt = Date.now()\n // Snapshot persistence is best-effort: the in-memory board stays\n // authoritative and the next change re-flushes.\n await this.#sidecar.writeTasks(entry.sessionId, [...entry.tasks.values()]).catch(() => undefined)\n }\n\n /** What DSH is told about token usage: newest call's prompt, whole turn's output.\n *\n * `TokenUsage` is documented as \"token accounting for ONE model call\", and\n * DSH's token meter divides `uncachedInput + cacheRead + cacheWrite` by the\n * context window to draw context pressure. One Claude turn makes many calls\n * and the CLI's result usage sums all of them, so reporting that sum pinned\n * the meter at 100%: a 35-call turn reads the same prompt from cache 35\n * times, which sums past the window without the conversation ever growing.\n * The newest single call answers \"how big is this conversation now\".\n *\n * Output is deliberately excluded from that pressure sum, so the same\n * argument never applied to it — and taking it from the newest call reported\n * whatever the wrap-up message happened to cost, which is a couple of tokens\n * after a turn that wrote thousands. The turn total is the honest figure.\n *\n * The sidecar activity keeps the whole turn total for both — that is the\n * audit and cost record, and nothing divides it by a window. */\n #reportedUsage(\n active: ActiveTurn,\n result: Extract<NormalizedSdkMessage, { kind: 'result' }>,\n ): ClaudeUsage {\n const prompt = active.requestUsage\n if (prompt === undefined) return result.usage\n return {\n ...prompt,\n ...(result.usage.outputTokens === undefined ? {} : { outputTokens: result.usage.outputTokens }),\n }\n }\n\n async #completeProgressSegment(\n active: ActiveTurn,\n result: Extract<NormalizedSdkMessage, { kind: 'result' }>,\n recordUsage = true,\n ): Promise<void> {\n if (recordUsage && (result.usage.inputTokens !== undefined || result.usage.outputTokens !== undefined || result.usage.cumulativeCostUsd !== undefined)) {\n await this.#appendSafely(active, {\n kind: 'usage',\n phase: 'completed',\n title: 'Claude usage',\n summary: usageSummary(result.usage),\n usage: this.#timedUsage(active, result.usage),\n })\n active.output.push({ type: 'usage', usage: this.#reportedUsage(active, result) })\n }\n if (!active.sawTextDelta && active.text.length === 0 && result.text !== undefined) {\n active.text = result.text\n active.transcriptText = result.text\n await this.#upsertTranscriptText(active)\n active.output.push({ type: 'text-delta', text: result.text })\n }\n await this.#upsertTranscriptText(active)\n active.output.push({ type: 'segment-complete', text: active.text })\n active.sawTextDelta = false\n active.text = ''\n this.#closeTranscriptTextSegment(active)\n active.thinking = ''\n }\n\n async #completeTurn(\n entry: SupervisorEntry,\n active: ActiveTurn,\n result: Extract<NormalizedSdkMessage, { kind: 'result' }>,\n ): Promise<void> {\n if (entry.active !== active) return\n if (active.aborted) {\n await this.#upsertTranscriptText(active)\n await this.#flushTranscript(active)\n await this.#settleOpenCalls(active, 'Cancelled with the turn')\n await this.#appendSafely(active, {\n kind: 'status',\n phase: 'failed',\n title: 'Claude Code turn cancelled',\n })\n entry.active = undefined\n entry.state = 'idle'\n entry.lastUsedAt = Date.now()\n await this.#recordChainAnchor(entry, active)\n this.#checkpointProjection(entry)\n this.#armIdleTimer(entry)\n return\n }\n if (result.usage.inputTokens !== undefined || result.usage.outputTokens !== undefined || result.usage.cumulativeCostUsd !== undefined) {\n await this.#appendSafely(active, {\n kind: 'usage',\n phase: 'completed',\n title: 'Claude usage',\n summary: usageSummary(result.usage),\n usage: this.#timedUsage(active, result.usage),\n })\n active.output.push({ type: 'usage', usage: this.#reportedUsage(active, result) })\n }\n const unmatchedDenials = (result.permissionDenials ?? [])\n .filter(denial => !active.deniedToolUseIds.has(denial.toolUseId))\n if (unmatchedDenials.length > 0) {\n await this.#appendSafely(active, {\n kind: 'permission',\n phase: 'denied',\n title: 'Claude Code auto-denied tool calls',\n summary: unmatchedDenials.map(denial => denial.toolName).join(', '),\n })\n }\n if (!result.success) {\n if (!active.sawTextDelta && active.text.length === 0 && result.text !== undefined) {\n active.text = result.text\n active.transcriptText = result.text\n await this.#upsertTranscriptText(active)\n active.output.push({ type: 'text-delta', text: result.text })\n }\n await this.#upsertTranscriptText(active)\n await this.#flushTranscript(active)\n const message = result.errors?.join('\\n')\n ?? (result.terminalReason !== undefined ? `Claude Code failed the turn (${result.terminalReason})` : 'Claude Code failed the turn')\n await this.#appendSafely(active, {\n kind: 'error',\n phase: 'failed',\n title: 'Claude Code turn failed',\n summary: message,\n isError: true,\n })\n active.output.fail(new Error(message))\n } else {\n if (!active.sawTextDelta && active.text.length === 0 && result.text !== undefined) {\n active.text = result.text\n active.transcriptText = result.text\n await this.#upsertTranscriptText(active)\n active.output.push({ type: 'text-delta', text: result.text })\n }\n await this.#upsertTranscriptText(active)\n if (active.phase === 'primary' && this.#hasRunningTasks(entry, active)) {\n active.phase = 'waiting-tasks'\n await this.#appendSafely(active, {\n kind: 'status',\n phase: 'updated',\n title: 'Claude Code is waiting for background tasks',\n })\n await this.#completeProgressSegment(active, result, false)\n return\n }\n await this.#appendSafely(active, {\n kind: 'status',\n phase: 'completed',\n title: 'Claude Code turn completed',\n })\n await this.#flushTranscript(active)\n active.output.push({ type: 'complete', text: active.text })\n active.output.close()\n }\n if (active.signal !== undefined && active.abortListener !== undefined) {\n active.signal.removeEventListener('abort', active.abortListener)\n }\n entry.active = undefined\n entry.state = 'idle'\n entry.lastUsedAt = Date.now()\n await this.#recordChainAnchor(entry, active)\n await this.#learnContextWindow(entry)\n this.#checkpointProjection(entry)\n this.#armIdleTimer(entry)\n }\n\n /** Tell every reader where this session's delta stream ended.\n *\n * A reader that lost the turn's last delta has nothing later to reveal the\n * hole, and a settled turn produces nothing further -- so a finished tool\n * group would keep pulsing until the session was reopened by hand. Last\n * line of the turn, best effort: presentation must never unsettle it. */\n #checkpointProjection(entry: SupervisorEntry): void {\n try {\n this.#sidecar.checkpoint(entry.sessionId)\n } catch {\n // A reader that misses the checkpoint is no worse off than before it.\n }\n }\n\n /** Pin where Claude's chain ended for the DSH turn that just settled, so a\n * later rewind of the following turn can fork exactly here. Best effort:\n * a missing anchor only makes a rewind fall back to an earlier turn. */\n async #recordChainAnchor(entry: SupervisorEntry, active: ActiveTurn): Promise<void> {\n const uuid = entry.lastChainUuid\n if (uuid === undefined) return\n try {\n await this.#sidecar.recordRewindAnchor(entry.sessionId, active.cursor.turn, uuid)\n } catch {\n // The sidecar is advisory; a failed anchor never fails the turn.\n }\n }\n\n async #upsertTranscriptText(active: ActiveTurn): Promise<void> {\n if (active.transcriptText.length === 0) return\n const ordinal = active.transcriptTextOrdinal ?? active.cursor.nextOrdinal++\n active.transcriptTextOrdinal = ordinal\n try {\n // Hot path: notify live subscribers synchronously; disk persistence is\n // coalesced inside the repository and flushed at segment/turn edges.\n this.#sidecar.appendTranscriptText(active.agent.id as string, {\n text: active.transcriptText,\n ...(this.#nativeRendering() ? { renderer: 'native' as const } : {}),\n turn: active.cursor.turn,\n step: active.cursor.step,\n ordinal,\n })\n } catch {\n // Transcript persistence is presentational and must not change a Claude outcome.\n }\n }\n\n async #flushTranscript(active: ActiveTurn): Promise<void> {\n await this.#sidecar.flushTranscriptText(active.agent.id as string).catch(() => undefined)\n }\n\n #closeTranscriptTextSegment(active: ActiveTurn): void {\n void this.#flushTranscript(active)\n active.transcriptText = ''\n active.transcriptTextOrdinal = undefined\n }\n\n async #appendActivity(active: ActiveTurn, activity: ClaudeActivityInput): Promise<void> {\n const ordinal = active.cursor.nextOrdinal++\n await this.#sidecar.appendActivity(active.agent.id as string, {\n ...activity,\n // Stamp the renderer this record was produced for. The Client reads it\n // back per step, so a step drawn natively is never also drawn by the\n // plugin transcript -- and history keeps whichever renderer produced it.\n ...(this.#nativeRendering() ? { renderer: 'native' as const } : {}),\n turn: active.cursor.turn,\n step: active.cursor.step,\n ordinal,\n })\n }\n\n /** Persist durable activity without letting a storage failure unsettle the\n * in-memory turn or leak process ownership. Audit failure is best-effort. */\n async #appendSafely(active: ActiveTurn, activity: ClaudeActivityInput): Promise<void> {\n await this.#appendActivity(active, activity).catch(() => undefined)\n }\n\n #startInterrupt(entry: SupervisorEntry): Promise<void> {\n const existing = this.#interruptions.get(entry.sessionId)\n if (existing !== undefined) return existing\n const interruption = this.#interrupt(entry).finally(() => {\n this.#interruptions.delete(entry.sessionId)\n })\n this.#interruptions.set(entry.sessionId, interruption)\n return interruption\n }\n\n /** Close out the root tool calls a turn is ending without answers for.\n *\n * A tool result is the only thing that ever settles a call, and a turn that\n * is cancelled or disconnected produces none: the transcript would keep\n * drawing those calls as running for as long as the session lives, and no\n * later event would ever correct it. Written as the failures they are. */\n async #settleOpenCalls(active: ActiveTurn, summary: string): Promise<void> {\n const open = [...active.openCalls]\n active.openCalls.clear()\n for (const [toolUseId, toolName] of open) {\n await this.#appendSafely(active, {\n kind: 'tool-result',\n phase: 'failed',\n toolUseId,\n toolName,\n title: 'Tool cancelled',\n summary,\n isError: true,\n })\n // The native card has the same hole, and the same fix as a denied call.\n if (this.#nativeRendering()) {\n await this.#appendNativeToolResult(active, {\n kind: 'tool-result',\n toolUseId,\n output: summary,\n isError: true,\n })\n }\n }\n }\n\n async #interrupt(entry: SupervisorEntry): Promise<void> {\n const active = entry.active\n if (active === undefined || entry.state === 'interrupting') return\n entry.state = 'interrupting'\n active.aborted = true\n active.output.fail(abortFailure())\n await this.#upsertTranscriptText(active)\n let interruptError: unknown\n try {\n const receipt = await withTimeout(entry.query.interrupt(), CLAUDE_INTERRUPT_TIMEOUT_MS, 'Claude Code interrupt')\n const queued = receipt?.still_queued ?? []\n if (queued.includes(active.promptUuid)) {\n throw new Error(`Claude Code interrupt left submitted prompt ${active.promptUuid} queued`)\n }\n } catch (error) {\n interruptError = error\n }\n await this.#settleOpenCalls(active, 'Cancelled with the turn').catch(() => undefined)\n try {\n await this.#appendActivity(active, {\n kind: 'status',\n phase: 'failed',\n title: interruptError === undefined ? 'Claude Code turn cancelled' : 'Claude Code cancelled; process entry reset',\n ...(interruptError === undefined ? {} : { summary: errorSummary(interruptError) }),\n })\n } catch {\n // The active output is already aborted; process cleanup cannot wait for audit availability.\n }\n if (this.#entries.get(entry.sessionId) === entry) this.#entries.delete(entry.sessionId)\n await this.#disposeEntry(entry)\n }\n\n async #handleDisconnect(entry: SupervisorEntry, error: unknown): Promise<void> {\n const active = entry.active\n const stderr = entry.process?.stderrTail()\n if (active !== undefined) {\n await this.#upsertTranscriptText(active)\n await this.#flushTranscript(active)\n if (active.signal !== undefined && active.abortListener !== undefined) {\n active.signal.removeEventListener('abort', active.abortListener)\n }\n const unknown = active.sawActivity\n entry.state = unknown ? 'outcome-unknown' : 'disconnected'\n const failure = unknown\n ? new ClaudeOutcomeUnknownError(stderr === undefined || stderr.length === 0 ? undefined : `Claude Code exited after activity; outcome unknown. ${stderr}`)\n : new Error(stderr === undefined || stderr.length === 0 ? errorSummary(error) : stderr)\n await this.#settleOpenCalls(active, 'Claude Code stopped before the tool answered').catch(() => undefined)\n await this.#appendSafely(active, {\n kind: 'error',\n phase: 'failed',\n title: unknown ? 'Claude Code outcome unknown' : 'Claude Code disconnected',\n summary: failure.message,\n isError: true,\n detail: error,\n })\n active.output.fail(failure)\n entry.active = undefined\n } else {\n entry.state = 'disconnected'\n }\n this.#entries.delete(entry.sessionId)\n await this.#disposeEntry(entry)\n }\n\n #armIdleTimer(entry: SupervisorEntry): void {\n if (this.#config.idleTimeoutMs <= 0) return\n const timer = setTimeout(() => {\n if (entry.active !== undefined || entry.state !== 'idle') return\n this.#entries.delete(entry.sessionId)\n void this.#disposeEntry(entry)\n }, this.#config.idleTimeoutMs)\n timer.unref?.()\n entry.idleTimer = timer\n }\n\n async #disposeEntry(entry: SupervisorEntry): Promise<void> {\n if (entry.state === 'disposed') return\n if (entry.idleTimer !== undefined) clearTimeout(entry.idleTimer)\n entry.state = 'disposed'\n entry.input.discard(abortFailure())\n entry.query.close()\n entry.lifetime.abort()\n if (entry.active !== undefined) entry.active.output.fail(abortFailure())\n entry.process?.kill('SIGTERM')\n if (entry.process !== undefined) {\n try {\n await entry.process.handle.waitForExit(AbortSignal.timeout(5_000))\n } catch {\n // The DSH subprocess owner still holds the tree and will finish escalation.\n }\n }\n }\n}\n","import { randomUUID } from 'node:crypto'\n\nconst MAX_COMMENTS_PER_SESSION = 50\nconst MAX_TEXT_CHARS = 2_000\nconst MAX_PATH_CHARS = 1_024\nconst MAX_LINE = 10_000_000\n\nexport type ReviewCommentSide = 'old' | 'new'\n\nexport interface ReviewComment {\n readonly id: string\n readonly path: string\n /** Last (anchor) line of the comment. */\n readonly line: number\n /** First line when the comment spans a range; absent for single-line comments. */\n readonly startLine?: number\n readonly side: ReviewCommentSide\n readonly text: string\n}\n\nexport class ReviewCommentError extends Error {\n readonly code: string\n\n constructor(code: string, message: string) {\n super(message)\n this.name = 'ReviewCommentError'\n this.code = code\n }\n}\n\nfunction validSide(value: unknown): value is ReviewCommentSide {\n return value === 'old' || value === 'new'\n}\n\n/** Pending line comments queued per session until the next user turn drains them. */\nexport class ReviewCommentStore {\n readonly #comments = new Map<string, ReviewComment[]>()\n\n add(sessionId: string, input: { path: unknown; line: unknown; startLine?: unknown; side: unknown; text: unknown }): ReviewComment {\n const path = typeof input.path === 'string' ? input.path.trim() : ''\n const text = typeof input.text === 'string' ? input.text.trim() : ''\n if (path.length === 0 || path.length > MAX_PATH_CHARS || /[\\0\\r\\n]/u.test(path)) {\n throw new ReviewCommentError('invalid-request', 'The comment path is invalid.')\n }\n if (text.length === 0 || text.length > MAX_TEXT_CHARS || text.includes('\\0')) {\n throw new ReviewCommentError('invalid-request', 'The comment text is invalid.')\n }\n if (typeof input.line !== 'number' || !Number.isSafeInteger(input.line) || input.line < 1 || input.line > MAX_LINE) {\n throw new ReviewCommentError('invalid-request', 'The comment line is invalid.')\n }\n if (!validSide(input.side)) throw new ReviewCommentError('invalid-request', 'The comment side is invalid.')\n const startLine = input.startLine === undefined || input.startLine === null ? undefined : input.startLine\n if (startLine !== undefined && (typeof startLine !== 'number' || !Number.isSafeInteger(startLine) || startLine < 1 || startLine > input.line)) {\n throw new ReviewCommentError('invalid-request', 'The comment start line is invalid.')\n }\n const existing = this.#comments.get(sessionId) ?? []\n if (existing.length >= MAX_COMMENTS_PER_SESSION) {\n throw new ReviewCommentError('too-many-comments', 'Too many pending review comments. Remove one before adding another.')\n }\n const comment: ReviewComment = { id: randomUUID(), path, line: input.line, ...(startLine === undefined || startLine === input.line ? {} : { startLine }), side: input.side, text }\n this.#comments.set(sessionId, [...existing, comment])\n return comment\n }\n\n remove(sessionId: string, id: string): boolean {\n const existing = this.#comments.get(sessionId)\n if (existing === undefined) return false\n const next = existing.filter(comment => comment.id !== id)\n if (next.length === existing.length) return false\n if (next.length === 0) this.#comments.delete(sessionId)\n else this.#comments.set(sessionId, next)\n return true\n }\n\n list(sessionId: string): readonly ReviewComment[] {\n return this.#comments.get(sessionId) ?? []\n }\n\n /** Remove and return every pending comment; called when a user turn consumes them. */\n drain(sessionId: string): readonly ReviewComment[] {\n const existing = this.#comments.get(sessionId) ?? []\n this.#comments.delete(sessionId)\n return existing\n }\n\n disposeSession(sessionId: string): void {\n this.#comments.delete(sessionId)\n }\n\n dispose(): void {\n this.#comments.clear()\n }\n}\n\n/** Render drained comments as the prompt block preceding the user's message text. */\nexport function formatReviewComments(comments: readonly ReviewComment[]): string {\n const lines = comments.map((comment, index) => (\n `${index + 1}. ${comment.path}:${comment.startLine === undefined ? comment.line : `${comment.startLine}-${comment.line}`}${comment.side === 'old' ? ' (old side)' : ''} — ${comment.text}`\n ))\n return [\n '<user-review-comments>',\n 'The user attached these code review comments to this message. Each references a file and line (or line range) from the current working tree diff:',\n ...lines,\n '</user-review-comments>',\n ].join('\\n')\n}\n","import {\n LlmAdapter,\n ReasoningEffortId,\n type GenerateOptions,\n type LlmModelInfo,\n type LlmProviderInfo,\n type LlmResolvedModelInfo,\n type PreparedAdapterCall,\n type ResolvedRetryPolicy,\n type StreamChunk,\n type TokenUsage,\n} from '@deepseek-ai/dsh-llm'\nimport type { Agent, AgentRegistry } from '@deepseek-ai/dsh-agent'\nimport type { AttachmentStore, ImageAttachmentRef, ImageMediaType } from '@deepseek-ai/dsh-attachment'\nimport type { SDKUserMessage } from '@anthropic-ai/claude-agent-sdk'\nimport { CLAUDE_CODE_PRESET_ID, CLAUDE_CODE_PROVIDER, DEFAULT_CLAUDE_RENDER_MODE, type ClaudeRenderMode } from './constants.ts'\nimport type { ClaudeSupervisor, ClaudeThinkingMode } from './supervisor.ts'\nimport type { ClaudeUsage } from './events.ts'\nimport { formatReviewComments, type ReviewComment } from './review-comments.ts'\n\nconst MODELS = [\n { id: 'default', name: 'Default (recommended)', description: '' },\n { id: 'opus[1m]', name: 'Opus (1M context)', description: '', contextWindow: 1_000_000 },\n { id: 'fable', name: 'Fable', description: '' },\n { id: 'sonnet', name: 'Sonnet', description: '' },\n { id: 'haiku', name: 'Haiku', description: '' },\n] as const\n\nconst THINKING_MODES = [\n { id: 'off', name: 'Off', description: 'No extended thinking.' },\n { id: 'low', name: 'Low', description: 'Minimal thinking, fastest responses.' },\n { id: 'medium', name: 'Medium', description: 'Moderate thinking.' },\n { id: 'high', name: 'High', description: 'Deep reasoning (Claude Code default).' },\n { id: 'xhigh', name: 'Extra High', description: 'Deeper than high; unsupported models silently downgrade to high.' },\n { id: 'max', name: 'Max', description: 'Maximum effort; unsupported models silently downgrade.' },\n { id: 'ultracode', name: 'Ultracode', description: 'Extra-high effort plus standing dynamic-workflow orchestration; requires an xhigh-capable model.' },\n] as const\n\nexport function thinkingModeFor(effort: ReasoningEffortId | undefined): ClaudeThinkingMode | undefined {\n if (effort === undefined) return undefined\n if (THINKING_MODES.some(mode => mode.id === (effort as string))) return effort as unknown as ClaudeThinkingMode\n throw new Error(`dsh-claude: unsupported reasoning effort ${JSON.stringify(effort)}`)\n}\n\nconst NO_RETRY_POLICY: ResolvedRetryPolicy = Object.freeze({\n mode: 'normal',\n maxRetries: 0,\n retryableCodes: Object.freeze([]),\n initialDelayMs: 500,\n maxDelayMs: 10_000,\n jitterRatio: 0.1,\n})\n\ntype ClaudePrompt = SDKUserMessage['message']['content']\ntype ClaudePromptBlock = Exclude<ClaudePrompt, string>[number]\ntype AttachmentReader = Pick<AttachmentStore, 'imageLimits' | 'readImage'>\n\nfunction abortIfRequested(signal: AbortSignal | undefined): void {\n if (signal?.aborted !== true) return\n if (signal.reason instanceof Error) throw signal.reason\n const error = new Error('Claude Code input resolution aborted')\n error.name = 'AbortError'\n throw error\n}\n\nfunction finiteNonNegative(value: unknown): value is number {\n return typeof value === 'number' && Number.isFinite(value) && value >= 0\n}\n\nfunction validateImageRef(ref: ImageAttachmentRef, attachments: AttachmentReader, imageIndex: number): void {\n const limits = attachments.imageLimits\n if (!limits.mediaTypes.includes(ref.mediaType)) {\n throw new Error(`dsh-claude: image ${imageIndex} has an unsupported media type`)\n }\n if (!finiteNonNegative(ref.bytes) || ref.bytes > limits.maxImageBytes) {\n throw new Error(`dsh-claude: image ${imageIndex} exceeds the configured byte limit`)\n }\n const maxDimension = 'maxImageDimension' in limits && finiteNonNegative(limits.maxImageDimension)\n ? limits.maxImageDimension\n : undefined\n if (!finiteNonNegative(ref.width) || !finiteNonNegative(ref.height)\n || ref.width * ref.height > limits.maxImagePixels\n || (maxDimension !== undefined && (ref.width > maxDimension || ref.height > maxDimension))) {\n throw new Error(`dsh-claude: image ${imageIndex} exceeds the configured dimension limit`)\n }\n}\n\n/**\n * Prepend the session's pending diff-review comments to the outgoing user\n * prompt. The comments are drained once per turn: they are formatted into one\n * `<user-review-comments>` block placed ahead of the user's own text (or as a\n * leading text block for multi-part prompts) so Claude reads them in the same\n * turn that consumed them.\n */\nexport function injectReviewComments(prompt: ClaudePrompt, comments: readonly ReviewComment[]): ClaudePrompt {\n if (comments.length === 0) return prompt\n const block = formatReviewComments(comments)\n if (typeof prompt === 'string') return `${block}\\n\\n${prompt}`\n return [{ type: 'text', text: block }, ...prompt]\n}\n\nfunction imageBlock(data: Uint8Array, mediaType: ImageMediaType): ClaudePromptBlock {\n return {\n type: 'image',\n source: {\n type: 'base64',\n media_type: mediaType,\n data: Buffer.from(data.buffer, data.byteOffset, data.byteLength).toString('base64'),\n },\n }\n}\n\n/** Resolve only the newest direct human message; Claude's session owns history. */\nexport async function resolveDirectUserPrompt(\n messages: GenerateOptions['messages'],\n attachments: AttachmentReader,\n signal?: AbortSignal,\n): Promise<ClaudePrompt> {\n const message = [...messages].reverse().find(candidate => (\n candidate.role === 'user' && candidate.source.kind === 'user'\n ))\n if (message === undefined) {\n throw new Error('dsh-claude: no direct human input was present in this model step')\n }\n\n const imageRefs = message.content\n .filter((block): block is Extract<typeof block, { type: 'image' }> => block.type === 'image')\n .map(block => block.attachment)\n const limits = attachments.imageLimits\n if (imageRefs.length > limits.maxImagesPerMessage) {\n throw new Error('dsh-claude: prompt exceeds the configured image-count limit')\n }\n let declaredBytes = 0\n imageRefs.forEach((ref, index) => {\n validateImageRef(ref, attachments, index + 1)\n declaredBytes += ref.bytes\n if (!Number.isSafeInteger(declaredBytes) || declaredBytes > limits.maxMessageImageBytes) {\n throw new Error('dsh-claude: prompt exceeds the configured aggregate image-byte limit')\n }\n })\n\n if (imageRefs.length === 0) {\n const text = message.content\n .filter((block): block is Extract<typeof block, { type: 'text' }> => block.type === 'text')\n .map(block => block.text)\n .join('\\n')\n .trim()\n if (text.length > 0) return text\n throw new Error('dsh-claude: the newest direct human message has no supported content')\n }\n\n const content: ClaudePromptBlock[] = []\n let imageIndex = 0\n let verifiedBytes = 0\n for (const block of message.content) {\n abortIfRequested(signal)\n if (block.type === 'text') {\n content.push({ type: 'text', text: block.text })\n continue\n }\n if (block.type !== 'image') continue\n imageIndex += 1\n let stored: Awaited<ReturnType<AttachmentStore['readImage']>>\n try {\n stored = await attachments.readImage(block.attachment, signal)\n } catch {\n abortIfRequested(signal)\n throw new Error(`dsh-claude: image ${imageIndex} could not be read or verified`)\n }\n abortIfRequested(signal)\n validateImageRef(stored.ref, attachments, imageIndex)\n if (stored.data.byteLength !== stored.ref.bytes || stored.ref.mediaType !== block.attachment.mediaType) {\n throw new Error(`dsh-claude: image ${imageIndex} failed attachment verification`)\n }\n verifiedBytes += stored.data.byteLength\n if (!Number.isSafeInteger(verifiedBytes) || verifiedBytes > limits.maxMessageImageBytes) {\n throw new Error('dsh-claude: prompt exceeds the configured aggregate image-byte limit')\n }\n content.push(imageBlock(stored.data, stored.ref.mediaType))\n }\n if (content.length === 0) {\n throw new Error('dsh-claude: the newest direct human message has no supported content')\n }\n return content\n}\n\nfunction tokenUsage(usage: ClaudeUsage): TokenUsage {\n const normalized: TokenUsage = {\n inputTokens: usage.inputTokens ?? 0,\n outputTokens: usage.outputTokens ?? 0,\n }\n if (usage.cacheReadTokens !== undefined) normalized.cacheReadTokens = usage.cacheReadTokens\n if (usage.cacheCreationTokens !== undefined) normalized.cacheWriteTokens = usage.cacheCreationTokens\n return normalized\n}\n\nfunction resolveAgent(agents: Pick<AgentRegistry, 'currentInitiator' | 'get'>, options: GenerateOptions): Agent {\n const initiator = agents.currentInitiator()\n if (initiator !== undefined) return initiator\n if (options.sessionId !== undefined) {\n const agent = agents.get(options.sessionId)\n if (agent !== undefined) return agent\n }\n throw new Error('dsh-claude: the model request has no live owning DSH agent')\n}\n\nexport class ClaudeCodeAdapter extends LlmAdapter {\n readonly #supervisor: ClaudeSupervisor\n readonly #agents: Pick<AgentRegistry, 'currentInitiator' | 'get'>\n readonly #attachments: AttachmentReader\n readonly #presetIdFor: (agent: Agent) => string | undefined\n readonly #drainReviewComments: (sessionId: string) => readonly ReviewComment[]\n readonly #renderMode: () => ClaudeRenderMode\n\n constructor(\n supervisor: ClaudeSupervisor,\n agents: Pick<AgentRegistry, 'currentInitiator' | 'get'>,\n attachments: AttachmentReader,\n presetIdFor: (agent: Agent) => string | undefined,\n drainReviewComments: (sessionId: string) => readonly ReviewComment[] = () => [],\n renderMode: () => ClaudeRenderMode = () => DEFAULT_CLAUDE_RENDER_MODE,\n ) {\n super()\n this.#supervisor = supervisor\n this.#agents = agents\n this.#attachments = attachments\n this.#presetIdFor = presetIdFor\n this.#drainReviewComments = drainReviewComments\n this.#renderMode = renderMode\n }\n\n override providerInfo(provider: string): LlmProviderInfo {\n return { id: provider, name: 'Claude Code' }\n }\n\n override providerRetryPolicy(): ResolvedRetryPolicy {\n return NO_RETRY_POLICY\n }\n\n override async listModels(provider: string): Promise<readonly LlmModelInfo[]> {\n return MODELS.map(model => ({\n provider,\n id: model.id,\n name: model.name,\n description: model.description,\n inputModalities: ['text', 'image'],\n }))\n }\n\n override async resolveModel(provider: string, model: string, _signal?: AbortSignal): Promise<LlmResolvedModelInfo> {\n const known = MODELS.find(item => item.id === model)\n const observedContextWindow = this.#supervisor.contextWindow(model)\n const contextWindow = observedContextWindow ?? (known !== undefined && 'contextWindow' in known ? known.contextWindow : undefined)\n return {\n provider,\n id: model,\n name: known?.name ?? `Claude Code ${model}`,\n ...(known === undefined ? {} : { description: known.description }),\n ...(contextWindow === undefined ? {} : { context: { contextWindow } }),\n inputModalities: ['text', 'image'],\n reasoning: {\n efforts: THINKING_MODES.map(mode => ({\n id: ReasoningEffortId(mode.id),\n name: mode.name,\n description: mode.description,\n })),\n },\n }\n }\n\n override async prepareCall(\n provider: string,\n model: string,\n signal?: AbortSignal,\n ): Promise<PreparedAdapterCall> {\n return {\n model: await this.resolveModel(provider, model, signal),\n stream: options => this.stream(options),\n }\n }\n\n override async *stream(options: GenerateOptions): AsyncIterable<StreamChunk> {\n if (options.purpose !== undefined) {\n throw new Error(`dsh-claude: auxiliary ${options.purpose} calls are not routed into the Claude session`)\n }\n const agent = resolveAgent(this.#agents, options)\n if (this.#presetIdFor(agent) !== CLAUDE_CODE_PRESET_ID) {\n throw new Error(`dsh-claude: provider ${CLAUDE_CODE_PROVIDER} is available only to the ${CLAUDE_CODE_PRESET_ID} preset`)\n }\n const thinkingMode = thinkingModeFor(options.reasoningEffort)\n let prompt: ClaudePrompt\n try {\n prompt = await resolveDirectUserPrompt(options.messages, this.#attachments, options.signal)\n } catch (error) {\n if ((error as Error).name !== 'AbortError') throw error\n yield {\n type: 'finish',\n reason: {\n kind: 'aborted',\n failure: { code: 'aborted', message: error instanceof Error ? error.message : 'Claude Code input resolution aborted' },\n },\n }\n return\n }\n const events = await this.#supervisor.runTurn({\n agent,\n prompt: injectReviewComments(prompt, this.#drainReviewComments(agent.id as string)),\n model: options.model,\n ...(thinkingMode === undefined ? {} : { thinkingMode }),\n ...(options.signal === undefined ? {} : { signal: options.signal }),\n })\n\n // The plugin renderer draws the visible transcript from the sidecar, so\n // prose and Claude tool groups share one exact ordinal stream and DSH\n // receives only an empty assistant completion anchor plus usage/lifecycle\n // metadata. The native renderer needs the opposite: every visible span\n // arrives as ordinary DSH content blocks.\n const native = this.#renderMode() === 'native'\n let pendingUsage: TokenUsage | undefined\n let completed = false\n let blockIndex = 0\n let text = ''\n /** Settle the buffered prose as one text block. Each Claude result is one\n * block so tool activity stays ahead of the prose it explains and a\n * background-task report can follow in a block of its own. */\n function* flushText(): Generator<StreamChunk> {\n if (text.length === 0) return\n const settled = text\n text = ''\n yield { type: 'block-start', index: blockIndex, blockType: 'text' }\n yield { type: 'text-delta', index: blockIndex, text: settled }\n yield { type: 'block-end', index: blockIndex, block: { type: 'text', text: settled } }\n blockIndex += 1\n }\n try {\n for await (const event of events) {\n if (event.type === 'usage') {\n pendingUsage = tokenUsage(event.usage)\n continue\n }\n if (event.type === 'text-delta') {\n if (native) text += event.text\n continue\n }\n if (event.type === 'thinking') {\n if (!native) continue\n // Thinking settles before the prose it precedes, so nothing is\n // buffered yet; flush anyway to keep block order faithful when a\n // model interleaves the two.\n yield* flushText()\n yield { type: 'block-start', index: blockIndex, blockType: 'reasoning' }\n yield { type: 'reasoning-delta', index: blockIndex, text: event.text }\n yield { type: 'block-end', index: blockIndex, block: { type: 'reasoning', text: event.text } }\n blockIndex += 1\n continue\n }\n yield* flushText()\n if (event.type === 'segment-complete') continue\n completed = true\n if (pendingUsage !== undefined) yield { type: 'usage', usage: pendingUsage }\n yield { type: 'finish', reason: { kind: 'stop' } }\n }\n } catch (error) {\n if ((error as Error).name === 'AbortError') {\n completed = true\n yield* flushText()\n yield {\n type: 'finish',\n reason: {\n kind: 'aborted',\n failure: { code: 'aborted', message: error instanceof Error ? error.message : 'Claude Code turn aborted' },\n },\n }\n return\n }\n throw error\n }\n if (!completed) throw new Error('dsh-claude: Claude turn stream ended without a result')\n }\n}\n\nexport function createClaudeCodeAdapter(\n supervisor: ClaudeSupervisor,\n agents: Pick<AgentRegistry, 'currentInitiator' | 'get'>,\n attachments: AttachmentReader,\n presetIdFor: (agent: Agent) => string | undefined,\n drainReviewComments: (sessionId: string) => readonly ReviewComment[] = () => [],\n renderMode: () => ClaudeRenderMode = () => DEFAULT_CLAUDE_RENDER_MODE,\n): ClaudeCodeAdapter {\n return new ClaudeCodeAdapter(supervisor, agents, attachments, presetIdFor, drainReviewComments, renderMode)\n}\n","/**\n * The plugin's connection budget, in one table.\n *\n * A browser opens a small fixed number of connections to one origin — six for\n * HTTP/1.1 in Chromium — and shares them with the Host's own traffic. Every\n * response this plugin holds open costs one of them for its lifetime, and a\n * request that cannot get one waits in the browser's queue where no server-side\n * deadline can reach it. When the pool is exhausted the panels that would\n * *diagnose* the problem are the first thing to stop answering, which is how\n * this failure has always presented: four settings cards timing out at once\n * against a Host that is demonstrably healthy.\n *\n * So the budget is a fixed constant rather than a function of how much work is\n * in flight. Steady state is one connection (the multiplexed projection\n * carrier); the peak is `PLUGIN_GLOBAL_PERMITS`, whatever the session count.\n *\n * Both halves read this file, which is the point: a route declares a budget\n * class and the client derives its wait from the same entry, so a server\n * deadline can never be quietly longer than the client's patience.\n */\n\n/** Server-side budget classes. A route declares a class, never a number. */\nexport const ROUTE_BUDGET_MS = {\n /** Answers from memory or a single bounded probe. */\n fast: 5_000,\n /** Chains local Git work. */\n git: 45_000,\n /** Reaches the network: remote Git, `gh`, the npm registry. */\n remote: 150_000,\n} as const\n\nexport type RouteBudget = keyof typeof ROUTE_BUDGET_MS\n\n/** The client waits one round trip longer, so the route's own 504 wins the\n * race and the caller learns which budget elapsed instead of guessing. */\nexport const CLIENT_GRACE_MS = 3_000\n\nexport function clientBudgetMs(budget: RouteBudget): number {\n return ROUTE_BUDGET_MS[budget] + CLIENT_GRACE_MS\n}\n\n/** A request that never got a permit fails fast and says so, rather than\n * spending its whole budget queued behind work it cannot see. */\nexport const QUEUE_WAIT_BUDGET_MS = 4_000\n\n/** Connections this plugin may hold at once, across every lane. */\nexport const PLUGIN_GLOBAL_PERMITS = 4\n\n/** Per-lane ceilings inside the global budget.\n *\n * The projection carrier holds a permanently reserved permit outside these,\n * so three remain. `write + stream <= 2` leaves one permit that only a read\n * can take: a diagnostic read always has somewhere to go, however many slow\n * actions are in flight. That invariant is what stops a 150s repository\n * action from reproducing the original symptom through a new mechanism. */\nexport const PLUGIN_LANE_CAPS = { read: 2, write: 1, stream: 1 } as const\n\nexport type PluginLane = keyof typeof PLUGIN_LANE_CAPS\n\n/** Both halves cap the multiplex at the same number. */\nexport const MAX_MULTIPLEX_SESSIONS = 16\n","import type { IncomingMessage, ServerResponse } from 'node:http'\nimport type { Context } from '@deepseek-ai/cordis'\nimport type { WebRouteKind } from '@deepseek-ai/dsh-host-webserver'\nimport { deadline } from '@deepseek-ai/dsh-timeout'\nimport { ROUTE_BUDGET_MS, type RouteBudget } from './plugin-budget.ts'\n\n/** Accept only loopback, same-origin browser requests to plugin-private routes. */\nexport function trustedRequest(req: IncomingMessage): boolean {\n const remote = req.socket.remoteAddress\n if (remote !== '127.0.0.1' && remote !== '::1' && remote !== '::ffff:127.0.0.1') return false\n const site = req.headers['sec-fetch-site']\n if (site === 'cross-site') return false\n const host = req.headers.host\n if (host === undefined) return false\n const authority = /^(?:127\\.0\\.0\\.1|\\[?::1\\]?|localhost)(?::\\d+)?$/i\n if (!authority.test(host)) return false\n const origin = req.headers.origin\n if (origin === undefined) return true\n try {\n const originUrl = new URL(origin)\n return originUrl.host === host && authority.test(originUrl.host)\n } catch {\n return false\n }\n}\n\n/** Send a non-cacheable JSON response with MIME sniffing disabled. */\nexport function json(res: ServerResponse, status: number, value: unknown): void {\n res.writeHead(status, {\n 'content-type': 'application/json; charset=utf-8',\n 'cache-control': 'no-store',\n 'x-content-type-options': 'nosniff',\n })\n res.end(JSON.stringify(value))\n}\n\nconst ROUTE_TIMEOUT_CODE = 'DSH_CLAUDE_ROUTE'\nconst DEFAULT_BODY_BYTES = 1024 * 1024\n\nexport type PluginMethod = 'GET' | 'POST' | 'PATCH' | 'DELETE'\n\n/** What a route handler is given. Deliberately not the `ServerResponse`: a\n * unary handler that cannot reach the socket cannot hold it open. */\nexport interface PluginRouteIo {\n /** Aborts on client disconnect OR when the route's budget elapses. */\n readonly signal: AbortSignal\n readonly method: PluginMethod\n readonly url: URL\n /** Read the request body once, byte-capped, as JSON. */\n body<T = Record<string, unknown>>(maxBytes?: number): Promise<T>\n}\n\nexport interface PluginUnaryRoute {\n mode: 'unary'\n kind: WebRouteKind\n path: string\n methods: readonly PluginMethod[]\n budget: RouteBudget\n /** No `ServerResponse` in scope, by construction. */\n handler: (io: PluginRouteIo) => Promise<{ status: number; value: unknown }>\n}\n\nexport interface PluginStreamRoute {\n mode: 'stream'\n kind: WebRouteKind\n path: string\n methods: readonly PluginMethod[]\n /** Hard ceiling on live responses for this path; the oldest is evicted. */\n maxConcurrent: number\n /** Dedupe identity; a second open with the same key supersedes the first. */\n streamKey: (url: URL) => string\n handler: (res: ServerResponse, io: PluginRouteIo) => Promise<void>\n}\n\nexport type PluginRoute = PluginUnaryRoute | PluginStreamRoute\n\n/** Bounds live streaming responses per path, so a teardown bug cannot become a\n * permanent connection leak. Registration is per path, not global, because a\n * wedged projection stream must not evict an in-flight repository setup. */\nclass StreamRegistry {\n readonly #open = new Map<string, Map<string, () => void>>()\n\n admit(path: string, key: string, max: number, close: () => void): () => void {\n let live = this.#open.get(path)\n if (live === undefined) {\n live = new Map()\n this.#open.set(path, live)\n }\n // A reopen under the same identity is the client reconnecting; the older\n // response is the stale one, so it goes rather than the new arrival.\n live.get(key)?.()\n live.set(key, close)\n while (live.size > max) {\n const oldest = live.keys().next()\n if (oldest.done === true) break\n const evict = live.get(oldest.value)\n live.delete(oldest.value)\n evict?.()\n }\n return () => {\n const current = this.#open.get(path)\n if (current?.get(key) === close) current.delete(key)\n }\n }\n}\n\nconst streams = new StreamRegistry()\n\nfunction isPluginMethod(value: string | undefined): value is PluginMethod {\n return value === 'GET' || value === 'POST' || value === 'PATCH' || value === 'DELETE'\n}\n\n/** Distinguishable so the wrapper can answer 413 rather than folding an\n * oversized body into whatever generic failure the handler reports. */\nexport class PluginBodyTooLargeError extends Error {\n constructor() {\n super('Request body is too large')\n this.name = 'PluginBodyTooLargeError'\n }\n}\n\nasync function readBody(req: IncomingMessage, maxBytes: number): Promise<unknown> {\n const declared = Number(req.headers['content-length'] ?? 0)\n if (!Number.isFinite(declared) || declared < 0 || declared > maxBytes) throw new PluginBodyTooLargeError()\n const chunks: Buffer[] = []\n let bytes = 0\n for await (const chunk of req) {\n const data = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk as Uint8Array)\n bytes += data.byteLength\n if (bytes > maxBytes) throw new PluginBodyTooLargeError()\n chunks.push(data)\n }\n if (bytes === 0) return {}\n return JSON.parse(Buffer.concat(chunks).toString('utf8')) as unknown\n}\n\nfunction rejectOn(signal: AbortSignal): Promise<never> {\n return new Promise((_resolve, reject) => {\n if (signal.aborted) {\n reject(signal.reason as Error)\n return\n }\n signal.addEventListener('abort', () => reject(signal.reason as Error), { once: true })\n })\n}\n\n/**\n * Register one plugin route.\n *\n * This is the only place in the package that calls `ctx.webServer.register`,\n * and the ordering inside it is the fix rather than an implementation detail:\n * the disconnect listeners are attached before the first `await`, so a client\n * that goes away while the handler is still assembling its first response\n * still tears the route's work down. The previous per-route code attached\n * `res.on('close')` after awaiting an unbounded repository probe, which is how\n * the projection stream reached 53 opens against 33 closes.\n */\nexport function registerPluginRoute(ctx: Context, route: PluginRoute): void {\n const label = `dsh-claude: ${route.path}`\n ctx.effect(() => ctx.webServer.register({\n kind: route.kind,\n path: route.path,\n handler: async (req, res) => {\n const method = req.method\n if (!isPluginMethod(method) || !route.methods.includes(method)) {\n return json(res, 405, { error: 'method not allowed' })\n }\n if (!trustedRequest(req)) return json(res, 403, { error: 'forbidden' })\n // Before any await: a disconnect during setup must still cancel.\n const aborted = new AbortController()\n const abort = (): void => { aborted.abort() }\n // `req` emits 'close' when the request is COMPLETE, not only when the\n // client vanishes — so reading a body fires it, and an unguarded abort\n // here cancels every POST route the instant it parses its own input.\n // `complete` is what tells the two apart.\n req.on('close', () => { if (!req.complete) abort() })\n res.on('close', abort)\n const url = new URL(req.url ?? '/', 'http://localhost')\n if (route.mode === 'stream') {\n const release = streams.admit(route.path, route.streamKey(url), route.maxConcurrent, abort)\n const io: PluginRouteIo = {\n signal: aborted.signal,\n method,\n url,\n body: async <T,>(maxBytes = DEFAULT_BODY_BYTES) => await readBody(req, maxBytes) as T,\n }\n try {\n await route.handler(res, io)\n } catch (error) {\n if (!res.headersSent) json(res, 500, { error: 'stream-failed' })\n ctx.logger.warn(`dsh-claude: ${route.path} stream failed: ${error instanceof Error ? error.message : String(error)}`)\n } finally {\n release()\n res.end()\n }\n return\n }\n const budgetMs = ROUTE_BUDGET_MS[route.budget]\n const bounded = deadline(aborted.signal, budgetMs, ROUTE_TIMEOUT_CODE)\n const io: PluginRouteIo = {\n signal: bounded.signal,\n method,\n url,\n body: async <T,>(maxBytes = DEFAULT_BODY_BYTES) => await readBody(req, maxBytes) as T,\n }\n try {\n const result = await Promise.race([route.handler(io), rejectOn(bounded.signal)])\n if (!res.writableEnded) json(res, result.status, result.value)\n } catch (error) {\n if (res.writableEnded || res.headersSent) return\n if (bounded.signal.aborted && !aborted.signal.aborted) {\n return json(res, 504, { error: 'deadline', budget: route.budget, ms: budgetMs })\n }\n if (aborted.signal.aborted) return\n if (error instanceof PluginBodyTooLargeError) {\n return json(res, 413, { error: 'body-too-large', message: 'The request body is too large.' })\n }\n json(res, 400, { error: error instanceof Error ? error.message : 'request failed' })\n } finally {\n bounded[Symbol.dispose]()\n }\n },\n }), label)\n}\n\n/**\n * Memoise an executable lookup with a deadline, dropping the cache when it\n * fails.\n *\n * A route budget frees the socket but does nothing about a cached promise that\n * never settles: one hung PATH probe otherwise poisons every later request for\n * the life of the process, and the route deadline just turns that into a\n * steady stream of 504s. Caching only the resolved value keeps the retry.\n */\nexport function memoizeExecutable(\n resolve: (signal: AbortSignal) => Promise<string>,\n timeoutMs: number,\n): () => Promise<string> {\n let pending: Promise<string> | undefined\n return () => {\n if (pending !== undefined) return pending\n const bounded = deadline(undefined, timeoutMs, ROUTE_TIMEOUT_CODE)\n const attempt = resolve(bounded.signal)\n .finally(() => { bounded[Symbol.dispose]() })\n .catch((error: unknown) => {\n pending = undefined\n throw error\n })\n pending = attempt\n return attempt\n }\n}\n","import type { Context } from '@deepseek-ai/cordis'\nimport type { Agent } from '@deepseek-ai/dsh-agent'\nimport type {} from '@deepseek-ai/dsh-agent-presets'\nimport type {} from '@deepseek-ai/dsh-commands'\nimport type {} from '@deepseek-ai/dsh-host-webserver'\nimport { CLAUDE_DOCTOR_PATH } from './constants.ts'\nimport { runClaudeDoctor, type ExecutableRuntime } from './executable.ts'\nimport type { ClaudeSupervisor, ClaudeSupervisorConfig } from './supervisor.ts'\nimport { redactText } from './events.ts'\nimport { registerPluginRoute } from './http.ts'\n\nexport const CLAUDE_DOCTOR_PROBE_TIMEOUT_MS = 15_000\n\n/** Live metadata-bridge state per agent, maintained by the host plugin. */\nexport interface ClaudeBridgeDiagnostic {\n attempts: number\n lastError?: string\n lastCatalog?: number\n registered?: string[]\n}\n\nexport const claudeBridgeDiagnostics = new WeakMap<Agent, ClaudeBridgeDiagnostic>()\n\nfunction safeMessage(error: unknown): string {\n return redactText(error instanceof Error ? error.message : String(error), 1_000)\n}\n\n/** Live command-bridge diagnostics: which agents exist, their presets, and how\n * many slash commands each agent's registry layer resolves. */\nfunction commandDiagnostics(ctx: Context): unknown {\n try {\n const agents = ctx.agents.list()\n return {\n total: agents.length,\n agents: agents.map(agent => {\n const info: { id: string; preset?: string; commandCount?: number; sample?: string[]; error?: string; bridge?: ClaudeBridgeDiagnostic } = { id: String(agent.id) }\n try {\n const preset = ctx.agentPresets.composedPreset(agent.ctx)\n if (preset !== undefined) info.preset = preset\n } catch (error) {\n info.error = safeMessage(error)\n }\n try {\n const list = ctx.commands.list(agent)\n info.commandCount = list.length\n info.sample = list.slice(0, 10).map(command => command.name)\n } catch (error) {\n info.error = info.error === undefined ? safeMessage(error) : `${info.error}; ${safeMessage(error)}`\n }\n const bridge = claudeBridgeDiagnostics.get(agent)\n if (bridge !== undefined) info.bridge = bridge\n return info\n }),\n }\n } catch (error) {\n return { error: safeMessage(error) }\n }\n}\n\nexport function registerClaudeDoctorRoutes(\n ctx: Context,\n runtime: ExecutableRuntime,\n supervisor: ClaudeSupervisor,\n config: ClaudeSupervisorConfig,\n resolutionError?: unknown,\n): void {\n registerPluginRoute(ctx, {\n mode: 'unary',\n kind: 'exact',\n path: CLAUDE_DOCTOR_PATH,\n methods: ['GET'],\n budget: 'git',\n handler: async io => {\n try {\n if (resolutionError !== undefined) {\n return { status: 200, value: {\n executable: {\n status: 'missing',\n searched: config.executablePath.length > 0 ? [config.executablePath] : ['claude', '~/.local/bin/claude', '/opt/homebrew/bin/claude', '/usr/local/bin/claude'],\n },\n version: { status: 'not-run' },\n authentication: { status: 'not-run' },\n handshake: 'not-run',\n message: safeMessage(resolutionError),\n limits: {\n idleTimeoutMs: config.idleTimeoutMs,\n maxProcesses: config.maxProcesses,\n },\n processes: { count: 0, active: 0 },\n } }\n }\n const report = await runClaudeDoctor(runtime, {\n configuredPath: config.executablePath,\n cwd: process.cwd(),\n // Threaded so freeing the socket also stops the probe, rather than\n // leaving a spawn nobody is waiting for; the ceiling stays its own.\n signal: AbortSignal.any([io.signal, AbortSignal.timeout(CLAUDE_DOCTOR_PROBE_TIMEOUT_MS)]),\n })\n const processes = supervisor.snapshots()\n if (processes.some(process => process.claudeSessionId !== undefined)) report.handshake = 'ok'\n return { status: 200, value: {\n ...report,\n limits: {\n idleTimeoutMs: config.idleTimeoutMs,\n maxProcesses: config.maxProcesses,\n },\n processes: {\n count: processes.length,\n active: processes.filter(process => process.state === 'running' || process.state === 'starting').length,\n },\n commandBridge: commandDiagnostics(ctx),\n } }\n } catch (error) {\n return { status: 500, value: { error: safeMessage(error) } }\n }\n },\n })\n}\n","import type { Context } from '@deepseek-ai/cordis'\nimport type {} from '@deepseek-ai/dsh-host-webserver'\nimport type { ServerResponse } from 'node:http'\nimport { CLAUDE_PROJECTION_PATH } from './constants.ts'\nimport { registerPluginRoute, type PluginRouteIo } from './http.ts'\nimport { MAX_MULTIPLEX_SESSIONS } from './plugin-budget.ts'\nimport type { ClaudeSidecarProjection, ClaudeSidecarRepository } from './sidecar.ts'\nimport type { ClaudeCommandView } from './command-bridge.ts'\nimport type { RepositoryStatus } from './repository-status.ts'\nimport type { ReviewComment } from './review-comments.ts'\n\nconst MAX_SESSION_ID_CHARS = 1_024\n/** Slow-moving metadata refresh and stream heartbeat cadence; deliberately off\n * the transcript hot path so git/gh latency never delays visible text. */\nconst META_REFRESH_MS = 5_000\n/** The multiplexed carrier's path segment. Session ids are `session-<uuid>`,\n * so this cannot collide with one. */\nconst MULTI_SEGMENT = 'multi'\n\ntype ProjectionTarget =\n | { readonly kind: 'snapshot'; readonly sessionId: string }\n | { readonly kind: 'multi'; readonly sessionIds: readonly string[] }\n\nfunction validSessionId(value: string): boolean {\n return value.length > 0 && value.length <= MAX_SESSION_ID_CHARS\n}\n\nfunction targetFromUrl(url: URL): ProjectionTarget | undefined {\n const prefix = `${CLAUDE_PROJECTION_PATH}/`\n if (!url.pathname.startsWith(prefix)) return undefined\n const encoded = url.pathname.slice(prefix.length)\n if (encoded.length === 0 || encoded.includes('/')) return undefined\n if (encoded === MULTI_SEGMENT) {\n const raw = url.searchParams.get('sessions')\n if (raw === null) return undefined\n const sessionIds = [...new Set(raw.split(',').filter(id => id.length > 0))]\n if (sessionIds.length === 0 || sessionIds.length > MAX_MULTIPLEX_SESSIONS) return undefined\n if (!sessionIds.every(validSessionId)) return undefined\n return { kind: 'multi', sessionIds }\n }\n try {\n const sessionId = decodeURIComponent(encoded)\n return validSessionId(sessionId) ? { kind: 'snapshot', sessionId } : undefined\n } catch {\n return undefined\n }\n}\n\ninterface ProjectionMeta {\n readonly owned: boolean\n readonly commands: readonly ClaudeCommandView[]\n readonly repository?: RepositoryStatus\n readonly reviewComments: readonly ReviewComment[]\n}\n\nfunction envelope(projection: ClaudeSidecarProjection, meta: ProjectionMeta): Record<string, unknown> {\n return {\n schemaVersion: projection.schemaVersion,\n revision: projection.revision,\n owned: meta.owned,\n commands: meta.commands,\n activities: projection.activities,\n ...(projection.contextUsage === undefined ? {} : { contextUsage: projection.contextUsage }),\n ...(projection.tasks === undefined ? {} : { tasks: projection.tasks }),\n ...(meta.repository === undefined ? {} : { repository: meta.repository }),\n reviewComments: meta.reviewComments,\n // Ranges only: the chain anchors behind a rewind are Claude transcript\n // identities and stay on this side of the boundary.\n ...(projection.rewind === undefined ? {} : { rewind: { ranges: projection.rewind.ranges } }),\n }\n}\n\n/** Register the browser-readable, credential-free sidecar projection endpoint.\n *\n * `GET <path>/:sessionId` returns one snapshot. `GET <path>/multi?sessions=a,b`\n * returns ONE NDJSON stream carrying every listed session, each line stamped\n * with its `session`.\n *\n * There is deliberately no per-session stream URL. The browser shares a small\n * fixed connection budget between this plugin and the Host, and a stream per\n * session spent it in proportion to how many Claude sessions existed — which\n * is what left the settings panel unable to get a connection at all. One\n * carrier is one connection, whatever the session count. */\nexport function registerClaudeProjectionRoute(\n ctx: Context,\n sidecar: ClaudeSidecarRepository,\n ownsSession: (sessionId: string) => boolean,\n commandsForSession: (sessionId: string) => readonly ClaudeCommandView[] = () => [],\n repositoryForSession: (sessionId: string) => Promise<RepositoryStatus | undefined> = async () => undefined,\n reviewCommentsForSession: (sessionId: string) => readonly ReviewComment[] = () => [],\n): void {\n const info = (message: string): void => {\n ctx.logger?.info?.(message)\n }\n\n /** Everything the host already knows, without touching the repository. */\n const localMeta = (sessionId: string): ProjectionMeta => {\n const owned = ownsSession(sessionId)\n return {\n owned,\n commands: commandsForSession(sessionId),\n reviewComments: owned ? reviewCommentsForSession(sessionId) : [],\n }\n }\n\n const assembleMeta = async (sessionId: string): Promise<ProjectionMeta> => {\n const meta = localMeta(sessionId)\n const repository = meta.owned ? await repositoryForSession(sessionId) : undefined\n return { ...meta, ...(repository === undefined ? {} : { repository }) }\n }\n\n const streamMulti = async (res: ServerResponse, io: PluginRouteIo, sessionIds: readonly string[]): Promise<void> => {\n info(`dsh-claude: projection stream opened for ${sessionIds.length} session(s)`)\n let textDeltas = 0\n let textBytes = 0\n let textSince = Date.now()\n // Headers first, before any await. One session whose repository probe is\n // slow must not delay every other session's first paint — and until the\n // headers are out the client cannot even tell the carrier is alive.\n // `no-transform` keeps a compressing proxy from buffering the sole carrier.\n res.writeHead(200, {\n 'content-type': 'application/x-ndjson; charset=utf-8',\n 'cache-control': 'no-store, no-transform',\n 'x-content-type-options': 'nosniff',\n })\n res.flushHeaders?.()\n let closed = false\n const writeLine = (value: unknown): void => {\n if (closed) return\n try {\n res.write(`${JSON.stringify(value)}\\n`)\n } catch {\n closed = true\n }\n }\n const metas = new Map<string, ProjectionMeta>()\n const writeMeta = (sessionId: string, meta: ProjectionMeta): void => {\n metas.set(sessionId, meta)\n writeLine({\n type: 'meta',\n session: sessionId,\n owned: meta.owned,\n commands: meta.commands,\n ...(meta.repository === undefined ? {} : { repository: meta.repository }),\n reviewComments: meta.reviewComments,\n })\n }\n const writeSnapshot = async (sessionId: string): Promise<void> => {\n const projection = await sidecar.read(sessionId)\n // The repository probe runs a chain of git commands and a `gh pr view`\n // over the network -- seconds, where the transcript is already in\n // memory. It rides a later meta line so the prose paints first.\n const meta = metas.get(sessionId) ?? localMeta(sessionId)\n metas.set(sessionId, meta)\n // Where the notification stream stands as of this read, so the first\n // delta after this line has a number to be contiguous with.\n writeLine({ type: 'snapshot', session: sessionId, seq: sidecar.sequence(sessionId), ...envelope(projection, meta) })\n const probed = await assembleMeta(sessionId)\n if (closed || JSON.stringify(probed) === JSON.stringify(metas.get(sessionId))) return\n writeMeta(sessionId, probed)\n }\n // Subscribe every lane synchronously, before the first await: a delta that\n // lands while the snapshots are still assembling belongs to this carrier.\n const unsubscribes = sessionIds.map(sessionId => sidecar.subscribe(sessionId, delta => {\n switch (delta.kind) {\n case 'text':\n textDeltas += 1\n textBytes += (delta.append ?? delta.text ?? '').length\n if (textDeltas % 25 === 0) {\n const elapsed = Date.now() - textSince\n info(`dsh-claude: stream 25 text deltas ${textBytes}B in ${elapsed}ms`)\n textBytes = 0\n textSince = Date.now()\n }\n writeLine({\n type: 'text',\n session: sessionId,\n turn: delta.turn,\n step: delta.step,\n ordinal: delta.ordinal,\n ...(delta.append === undefined ? {} : { append: delta.append }),\n ...(delta.text === undefined ? {} : { text: delta.text }),\n ...(delta.renderer === undefined ? {} : { renderer: delta.renderer }),\n seq: delta.seq,\n })\n return\n case 'activity':\n writeLine({ type: 'activity', session: sessionId, activity: delta.activity, seq: delta.seq })\n return\n case 'contextUsage':\n writeLine({ type: 'contextUsage', session: sessionId, value: delta.value, seq: delta.seq })\n return\n case 'tasks':\n writeLine({ type: 'tasks', session: sessionId, value: delta.value, seq: delta.seq })\n return\n case 'checkpoint':\n writeLine({ type: 'checkpoint', session: sessionId, seq: delta.seq })\n return\n case 'sync':\n void writeSnapshot(sessionId).catch(() => undefined)\n }\n }))\n // Per-session, in parallel: a wedged repository probe costs its own lane\n // its first paint, not everyone else's.\n for (const sessionId of sessionIds) {\n void writeSnapshot(sessionId).catch(() => undefined)\n }\n const timer = setInterval(() => {\n void (async () => {\n for (const sessionId of sessionIds) {\n if (closed) return\n const next = await assembleMeta(sessionId)\n if (closed) return\n if (JSON.stringify(next) === JSON.stringify(metas.get(sessionId))) continue\n writeMeta(sessionId, next)\n }\n writeLine({ type: 'ping' })\n })().catch(() => undefined)\n }, META_REFRESH_MS)\n timer.unref?.()\n // Teardown rides the wrapper's signal, which is armed before any await —\n // the previous hand-written `res.on('close')` was attached only after the\n // first metadata probe resolved, so a client that gave up during that\n // window left the interval and every subscription running for good.\n await new Promise<void>(resolve => {\n const finish = (): void => {\n if (closed) return\n closed = true\n clearInterval(timer)\n for (const unsubscribe of unsubscribes) unsubscribe()\n info(`dsh-claude: projection stream closed after ${textDeltas} text deltas`)\n resolve()\n }\n if (io.signal.aborted) finish()\n else io.signal.addEventListener('abort', finish, { once: true })\n })\n }\n\n registerPluginRoute(ctx, {\n mode: 'stream',\n kind: 'prefix',\n path: CLAUDE_PROJECTION_PATH,\n methods: ['GET'],\n // One carrier. A reconnect supersedes the old one rather than stacking.\n maxConcurrent: 1,\n streamKey: () => MULTI_SEGMENT,\n handler: async (res, io) => {\n const target = targetFromUrl(io.url)\n if (target === undefined) {\n res.writeHead(400, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' })\n res.write(JSON.stringify({ error: 'invalid session id' }))\n return\n }\n if (target.kind === 'multi') return await streamMulti(res, io, target.sessionIds)\n // A steady 2s cadence here means a stale (pre-streaming) client bundle.\n info(`dsh-claude: projection poll for ${target.sessionId.slice(0, 64)}`)\n try {\n const projection = await sidecar.read(target.sessionId)\n const body = envelope(projection, await assembleMeta(target.sessionId))\n res.writeHead(200, {\n 'content-type': 'application/json; charset=utf-8',\n 'cache-control': 'no-store',\n 'x-content-type-options': 'nosniff',\n })\n res.write(JSON.stringify(body))\n } catch {\n if (res.headersSent) return\n res.writeHead(500, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' })\n res.write(JSON.stringify({ error: 'projection unavailable' }))\n }\n },\n })\n}\n","import { readFile } from 'node:fs/promises'\nimport { isAbsolute, resolve, sep } from 'node:path'\nimport type { SubprocessHandle, SubprocessRuntime } from '@deepseek-ai/dsh-subprocess'\n\nconst MAX_OUTPUT_BYTES = 64 * 1024\nconst MAX_DIFF_BYTES = 256 * 1024\nconst MAX_FILE_BYTES = 8 * 1024 * 1024\nexport const MAX_FILE_LINES_PER_REQUEST = 500\nconst MAX_UNTRACKED_DIFFS = 50\nconst GIT_TIMEOUT_MS = 5_000\nconst GH_TIMEOUT_MS = 8_000\nconst CACHE_TTL_MS = 5_000\nconst MAX_TEXT_CHARS = 1_024\n\nexport type RepositoryCheckState = 'passing' | 'pending' | 'failing' | 'none'\nexport type RepositoryReviewState = 'approved' | 'changes-requested' | 'review-required' | 'none'\n\nexport interface RepositoryPullRequestStatus {\n readonly number: number\n readonly title: string\n readonly url: string\n readonly state: 'open' | 'closed' | 'merged'\n readonly draft: boolean\n readonly review: RepositoryReviewState\n readonly checks: RepositoryCheckState\n readonly mergeState?: string\n readonly author?: string\n readonly createdAt?: string\n readonly mergedAt?: string\n readonly baseBranch?: string\n}\n\nexport interface RepositoryDiffStatus {\n readonly additions: number\n readonly deletions: number\n readonly files: number\n readonly patch?: string\n readonly truncated: boolean\n}\n\nexport interface RepositoryStatus {\n readonly status: 'ready' | 'not-repository' | 'unavailable'\n readonly cwd: string\n readonly root?: string\n readonly branch?: string\n readonly detached?: boolean\n readonly worktree?: boolean\n readonly dirty?: boolean\n readonly upstream?: boolean\n readonly ahead?: number\n readonly behind?: number\n readonly remote?: string\n readonly pullRequest?: RepositoryPullRequestStatus\n readonly diff?: RepositoryDiffStatus\n /** Commits on origin/<base> that are not on HEAD, for open pull requests. */\n readonly baseBehind?: number\n}\n\ntype RepositoryRuntime = Pick<SubprocessRuntime, 'resolveExecutable' | 'spawn'>\n\ninterface CommandResult {\n readonly exitCode: number | null\n readonly stdout: string\n readonly lossy: boolean\n}\n\nfunction bounded(value: string): string {\n return value.trim().slice(0, MAX_TEXT_CHARS)\n}\n\nasync function collect(handle: SubprocessHandle): Promise<CommandResult> {\n const outcome = await handle.done\n const stdout = handle.collected.stdout?.readFrom(0)\n return {\n exitCode: outcome.exitCode,\n stdout: stdout?.text ?? '',\n lossy: stdout?.lossy === true,\n }\n}\n\nasync function run(\n runtime: RepositoryRuntime,\n executable: string,\n args: readonly string[],\n cwd: string,\n timeoutMs: number,\n maxBytes = MAX_OUTPUT_BYTES,\n): Promise<CommandResult> {\n const signal = AbortSignal.timeout(timeoutMs)\n return collect(runtime.spawn({\n argv: [executable, ...args],\n cwd,\n stdio: {\n stdin: 'ignore',\n stdout: { maxBytes },\n stderr: { maxBytes: MAX_OUTPUT_BYTES },\n },\n graceMs: 1_000,\n signal,\n env: {},\n }))\n}\n\nfunction normalizedPath(value: string): string {\n return value.replaceAll('\\\\', '/').replace(/\\/+$/u, '').toLocaleLowerCase('en-US')\n}\n\nexport function parseGitStatus(output: string): {\n branch?: string\n detached: boolean\n dirty: boolean\n upstream: boolean\n ahead?: number\n behind?: number\n} {\n let branch: string | undefined\n let detached = false\n let dirty = false\n let upstream = false\n let ahead: number | undefined\n let behind: number | undefined\n for (const line of output.split(/\\r?\\n/u)) {\n if (line.startsWith('# branch.head ')) {\n const head = bounded(line.slice('# branch.head '.length))\n if (head === '(detached)') detached = true\n else if (head.length > 0 && head !== '(unknown)') branch = head\n continue\n }\n if (line.startsWith('# branch.upstream ')) {\n upstream = true\n continue\n }\n if (line.startsWith('# branch.ab ')) {\n const counts = /^# branch\\.ab \\+(\\d+) -(\\d+)$/u.exec(line)\n if (counts !== null) {\n ahead = Number(counts[1])\n behind = Number(counts[2])\n }\n continue\n }\n if (line.length > 0 && !line.startsWith('# ')) dirty = true\n }\n return {\n ...(branch === undefined ? {} : { branch }),\n detached,\n dirty,\n upstream,\n ...(ahead === undefined ? {} : { ahead }),\n ...(behind === undefined ? {} : { behind }),\n }\n}\n\nexport function parseDiffNumstat(value: string): Omit<RepositoryDiffStatus, 'patch' | 'truncated'> {\n let additions = 0\n let deletions = 0\n let files = 0\n for (const line of value.split(/\\r?\\n/u)) {\n if (line.length === 0) continue\n const [added, deleted] = line.split('\\t')\n files += 1\n if (added !== undefined && /^\\d+$/u.test(added)) additions += Number(added)\n if (deleted !== undefined && /^\\d+$/u.test(deleted)) deletions += Number(deleted)\n }\n return { additions, deletions, files }\n}\n\nexport function parseGitHubRemote(value: string): string | undefined {\n const remote = bounded(value)\n const match = /^(?:https:\\/\\/github\\.com\\/|git@github\\.com:|ssh:\\/\\/git@github\\.com\\/)([^/\\s]+)\\/([^/\\s]+?)(?:\\.git)?$/iu.exec(remote)\n if (match?.[1] === undefined || match[2] === undefined) return undefined\n return `${match[1]}/${match[2]}`\n}\n\nfunction record(value: unknown): Record<string, unknown> | undefined {\n return value !== null && typeof value === 'object' && !Array.isArray(value)\n ? value as Record<string, unknown>\n : undefined\n}\n\nexport function aggregateChecks(value: unknown): RepositoryCheckState {\n if (!Array.isArray(value) || value.length === 0) return 'none'\n let pending = false\n for (const item of value) {\n const check = record(item)\n if (check === undefined) continue\n const conclusion = typeof check.conclusion === 'string' ? check.conclusion.toUpperCase() : undefined\n const status = typeof check.status === 'string' ? check.status.toUpperCase() : undefined\n const state = typeof check.state === 'string' ? check.state.toUpperCase() : undefined\n if (['FAILURE', 'ERROR', 'CANCELLED', 'TIMED_OUT', 'ACTION_REQUIRED'].includes(conclusion ?? state ?? '')) return 'failing'\n if (status !== undefined && status !== 'COMPLETED') pending = true\n if (['PENDING', 'EXPECTED'].includes(state ?? '')) pending = true\n }\n return pending ? 'pending' : 'passing'\n}\n\nfunction reviewState(value: unknown): RepositoryReviewState {\n if (value === 'APPROVED') return 'approved'\n if (value === 'CHANGES_REQUESTED') return 'changes-requested'\n if (value === 'REVIEW_REQUIRED') return 'review-required'\n return 'none'\n}\n\nexport function parsePullRequest(value: unknown): RepositoryPullRequestStatus | undefined {\n const input = record(value)\n if (input === undefined\n || !Number.isSafeInteger(input.number)\n || Number(input.number) <= 0\n || typeof input.title !== 'string'\n || typeof input.url !== 'string') return undefined\n let url: URL\n try {\n url = new URL(input.url)\n } catch {\n return undefined\n }\n if (url.protocol !== 'https:' || url.hostname !== 'github.com') return undefined\n const rawState = typeof input.state === 'string' ? input.state.toUpperCase() : ''\n const state = input.mergedAt !== undefined && input.mergedAt !== null\n ? 'merged'\n : rawState === 'OPEN' ? 'open' : rawState === 'CLOSED' ? 'closed' : undefined\n if (state === undefined) return undefined\n return {\n number: Number(input.number),\n title: bounded(input.title),\n url: url.href,\n state,\n draft: input.isDraft === true,\n review: reviewState(input.reviewDecision),\n checks: aggregateChecks(input.statusCheckRollup),\n ...(typeof input.mergeStateStatus === 'string'\n ? { mergeState: bounded(input.mergeStateStatus) }\n : {}),\n ...(typeof record(input.author)?.login === 'string'\n ? { author: bounded(String(record(input.author)?.login)) }\n : {}),\n ...(typeof input.createdAt === 'string' && Number.isFinite(Date.parse(input.createdAt))\n ? { createdAt: new Date(input.createdAt).toISOString() }\n : {}),\n ...(typeof input.mergedAt === 'string' && Number.isFinite(Date.parse(input.mergedAt))\n ? { mergedAt: new Date(input.mergedAt).toISOString() }\n : {}),\n ...(typeof input.baseRefName === 'string' && bounded(input.baseRefName).length > 0\n ? { baseBranch: bounded(input.baseRefName) }\n : {}),\n }\n}\n\nexport interface RepositoryFileLines {\n /** Requested 1-based inclusive slice of the working-tree file, clipped to its end. */\n readonly lines: readonly string[]\n /** Total line count of the file. */\n readonly total: number\n}\n\nexport class RepositoryFileError extends Error {\n readonly code: string\n\n constructor(code: string, message: string) {\n super(message)\n this.name = 'RepositoryFileError'\n this.code = code\n }\n}\n\nexport class RepositoryStatusService {\n readonly #runtime: RepositoryRuntime\n readonly #cacheTtlMs: number\n readonly #cache = new Map<string, { expiresAt: number; value: Promise<RepositoryStatus> }>()\n readonly #lastReady = new Map<string, RepositoryStatus>()\n #gitExecutable?: Promise<string>\n #ghExecutable?: Promise<string | undefined>\n\n constructor(runtime: RepositoryRuntime, cacheTtlMs = CACHE_TTL_MS) {\n this.#runtime = runtime\n this.#cacheTtlMs = cacheTtlMs\n }\n\n /** `signal` bounds the scan itself, not just the caller's patience: the\n * untracked-file diff below is a serial spawn loop that can outlive any\n * route budget, and work nobody is waiting for still occupies the process. */\n inspect(cwd: string, signal?: AbortSignal): Promise<RepositoryStatus> {\n const current = this.#cache.get(cwd)\n if (current !== undefined && current.expiresAt > Date.now()) return current.value\n const value = this.#inspect(cwd, signal).then(next => this.#stabilize(cwd, next))\n this.#cache.set(cwd, { expiresAt: Date.now() + this.#cacheTtlMs, value })\n void value.catch(() => this.#cache.delete(cwd))\n return value\n }\n\n invalidate(cwd: string): void {\n this.#cache.delete(cwd)\n this.#lastReady.delete(cwd)\n }\n\n dispose(): void {\n this.#cache.clear()\n this.#lastReady.clear()\n }\n\n #stabilize(cwd: string, next: RepositoryStatus): RepositoryStatus {\n const previous = this.#lastReady.get(cwd)\n if (next.status !== 'ready') return previous ?? next\n const sameCheckout = previous?.status === 'ready'\n && previous.root === next.root\n && previous.branch === next.branch\n const stable = sameCheckout\n ? {\n ...next,\n ...(next.pullRequest === undefined && previous.pullRequest !== undefined ? { pullRequest: previous.pullRequest } : {}),\n ...(next.pullRequest === undefined && previous.pullRequest !== undefined && previous.diff !== undefined\n ? { diff: previous.diff }\n : next.diff === undefined && previous.diff !== undefined ? { diff: previous.diff } : {}),\n }\n : next\n this.#lastReady.set(cwd, stable)\n return stable\n }\n\n /** Lines [from, to] of a working-tree file, used to expand unmodified context around diff hunks. */\n async fileLines(cwd: string, relativePath: string, from: number, to: number): Promise<RepositoryFileLines> {\n if (relativePath.length === 0 || isAbsolute(relativePath) || relativePath.includes('\\0') || relativePath.split(/[\\\\/]/u).includes('..')) {\n throw new RepositoryFileError('invalid-request', 'The file path must be relative to the repository.')\n }\n if (!Number.isSafeInteger(from) || !Number.isSafeInteger(to) || from < 1 || to < from || to - from >= MAX_FILE_LINES_PER_REQUEST) {\n throw new RepositoryFileError('invalid-request', 'The requested line range is invalid.')\n }\n const git = await this.#git()\n const top = await run(this.#runtime, git, ['rev-parse', '--path-format=absolute', '--show-toplevel'], cwd, GIT_TIMEOUT_MS)\n if (top.exitCode !== 0) throw new RepositoryFileError('not-repository', 'The directory is not inside a git repository.')\n const root = resolve(top.stdout.trim())\n const target = resolve(root, relativePath)\n if (target !== root && !target.startsWith(root + sep)) throw new RepositoryFileError('invalid-request', 'The file path escapes the repository.')\n const content = await readFile(target, 'utf8')\n if (content.length > MAX_FILE_BYTES) throw new RepositoryFileError('too-large', 'The file is too large to expand.')\n const all = content.split(/\\r?\\n/u)\n if (all.at(-1) === '') all.pop()\n return { lines: all.slice(from - 1, to), total: all.length }\n }\n\n async #git(): Promise<string> {\n this.#gitExecutable ??= this.#runtime.resolveExecutable('git')\n return this.#gitExecutable\n }\n\n async #gh(): Promise<string | undefined> {\n this.#ghExecutable ??= this.#runtime.resolveExecutable('gh').catch(() => undefined)\n return this.#ghExecutable\n }\n\n async #inspect(cwd: string, signal?: AbortSignal): Promise<RepositoryStatus> {\n const safeCwd = bounded(cwd)\n let git: string\n try {\n git = await this.#git()\n } catch {\n return { status: 'unavailable', cwd: safeCwd }\n }\n try {\n const paths = await run(this.#runtime, git, [\n 'rev-parse', '--path-format=absolute', '--show-toplevel', '--absolute-git-dir', '--git-common-dir',\n ], cwd, GIT_TIMEOUT_MS)\n if (paths.exitCode !== 0) return { status: 'not-repository', cwd: safeCwd }\n const [rootValue, gitDirValue, commonDirValue] = paths.stdout.split(/\\r?\\n/u)\n const root = bounded(rootValue ?? '')\n const gitDir = bounded(gitDirValue ?? '')\n const commonDir = bounded(commonDirValue ?? '')\n if (root.length === 0 || gitDir.length === 0 || commonDir.length === 0) return { status: 'unavailable', cwd: safeCwd }\n const statusResult = await run(this.#runtime, git, ['status', '--porcelain=v2', '--branch', '--untracked-files=normal'], cwd, GIT_TIMEOUT_MS)\n if (statusResult.exitCode !== 0) return { status: 'unavailable', cwd: safeCwd }\n const status = parseGitStatus(statusResult.stdout)\n const remoteResult = await run(this.#runtime, git, ['remote', 'get-url', 'origin'], cwd, GIT_TIMEOUT_MS)\n const remote = remoteResult.exitCode === 0 ? parseGitHubRemote(remoteResult.stdout) : undefined\n const pullRequest = status.branch === undefined || remote === undefined\n ? undefined\n : await this.#pullRequest(cwd, remote, status.branch)\n const diffBase = pullRequest?.baseBranch === undefined\n ? 'HEAD'\n : await this.#mergeBase(cwd, git, pullRequest.baseBranch) ?? 'HEAD'\n const diff = status.dirty || diffBase !== 'HEAD'\n ? await this.#diff(cwd, git, diffBase, signal)\n : { additions: 0, deletions: 0, files: 0, truncated: false }\n const baseBehind = pullRequest?.state === 'open' && pullRequest.baseBranch !== undefined\n ? await this.#baseBehind(cwd, git, pullRequest.baseBranch)\n : undefined\n return {\n status: 'ready',\n cwd: safeCwd,\n root,\n ...status,\n worktree: normalizedPath(gitDir) !== normalizedPath(commonDir),\n ...(remote === undefined ? {} : { remote }),\n ...(pullRequest === undefined ? {} : { pullRequest }),\n ...(diff === undefined ? {} : { diff }),\n ...(baseBehind === undefined ? {} : { baseBehind }),\n }\n } catch {\n return { status: 'unavailable', cwd: safeCwd }\n }\n }\n\n async #baseBehind(cwd: string, git: string, baseBranch: string): Promise<number | undefined> {\n try {\n const result = await run(this.#runtime, git, ['rev-list', '--count', `HEAD..refs/remotes/origin/${baseBranch}`, '--'], cwd, GIT_TIMEOUT_MS)\n if (result.exitCode !== 0 || result.lossy) return undefined\n const count = Number(bounded(result.stdout))\n return Number.isSafeInteger(count) && count >= 0 ? count : undefined\n } catch {\n return undefined\n }\n }\n\n async #mergeBase(cwd: string, git: string, baseBranch: string): Promise<string | undefined> {\n try {\n const result = await run(this.#runtime, git, ['merge-base', 'HEAD', `refs/remotes/origin/${baseBranch}`], cwd, GIT_TIMEOUT_MS)\n if (result.exitCode !== 0 || result.lossy) return undefined\n const oid = bounded(result.stdout)\n return /^[0-9a-f]{40}$/iu.test(oid) ? oid : undefined\n } catch {\n return undefined\n }\n }\n\n async #diff(cwd: string, git: string, base: string, signal?: AbortSignal): Promise<RepositoryDiffStatus | undefined> {\n try {\n const numstat = await run(this.#runtime, git, ['diff', '--no-ext-diff', '--numstat', base, '--'], cwd, GIT_TIMEOUT_MS)\n if (numstat.exitCode !== 0 || numstat.lossy) return undefined\n const summary = parseDiffNumstat(numstat.stdout)\n const patch = await run(this.#runtime, git, ['diff', '--no-ext-diff', '--no-color', '--unified=3', base, '--'], cwd, GIT_TIMEOUT_MS, MAX_DIFF_BYTES)\n if (patch.exitCode !== 0) return { ...summary, truncated: true }\n const untracked = await this.#untrackedDiff(cwd, git, signal)\n const combinedPatch = `${patch.stdout}${untracked.patch}`\n return {\n additions: summary.additions + untracked.additions,\n deletions: summary.deletions,\n files: summary.files + untracked.files,\n ...(patch.lossy ? {} : { patch: combinedPatch.slice(0, MAX_DIFF_BYTES) }),\n truncated: patch.lossy || untracked.truncated || combinedPatch.length > MAX_DIFF_BYTES,\n }\n } catch {\n return undefined\n }\n }\n\n async #untrackedDiff(cwd: string, git: string, signal?: AbortSignal): Promise<{ additions: number; files: number; patch: string; truncated: boolean }> {\n const listed = await run(this.#runtime, git, ['ls-files', '--others', '--exclude-standard', '-z'], cwd, GIT_TIMEOUT_MS)\n if (listed.exitCode !== 0 || listed.lossy) return { additions: 0, files: 0, patch: '', truncated: listed.lossy }\n const paths = listed.stdout.split('\\0').filter(path => path.length > 0)\n let additions = 0\n let patch = ''\n let truncated = paths.length > MAX_UNTRACKED_DIFFS\n for (const path of paths.slice(0, MAX_UNTRACKED_DIFFS)) {\n // The caller is gone or the route budget elapsed: stop spawning.\n if (signal?.aborted === true) return { additions, files: paths.length, patch, truncated: true }\n const result = await run(this.#runtime, git, [\n 'diff', '--no-ext-diff', '--no-color', '--unified=3', '--numstat', '--patch', '--no-index', '--', '/dev/null', path,\n ], cwd, GIT_TIMEOUT_MS, MAX_DIFF_BYTES)\n if (result.exitCode !== 0 && result.exitCode !== 1) {\n truncated = true\n continue\n }\n const start = result.stdout.indexOf('diff --git ')\n additions += parseDiffNumstat(start >= 0 ? result.stdout.slice(0, start) : result.stdout).additions\n if (result.lossy) truncated = true\n else if (start >= 0) patch += result.stdout.slice(start)\n }\n return { additions, files: paths.length, patch, truncated }\n }\n\n async #pullRequest(cwd: string, repository: string, branch: string): Promise<RepositoryPullRequestStatus | undefined> {\n const gh = await this.#gh()\n if (gh === undefined) return undefined\n try {\n const result = await run(this.#runtime, gh, [\n 'pr', 'view', branch,\n '--repo', repository,\n '--json', 'number,title,url,state,isDraft,reviewDecision,mergeStateStatus,mergedAt,statusCheckRollup,author,createdAt,baseRefName',\n ], cwd, GH_TIMEOUT_MS)\n if (result.exitCode !== 0) return undefined\n return parsePullRequest(JSON.parse(result.stdout))\n } catch {\n return undefined\n }\n }\n}\n","/** Name a generated worktree branch after what the user is about to ask for.\n *\n * The composer draft is the only description of the work that exists before\n * the session starts, and it is usually not English and never branch-safe, so\n * a throwaway Haiku turn compresses it into a slug. Naming is a nicety: every\n * failure here returns `undefined` and the caller keeps its timestamped name. */\nimport { query as claudeQuery, type Options as ClaudeOptions, type Query } from '@anthropic-ai/claude-agent-sdk'\n\n/** Cheapest model that can translate and compress a sentence. */\nexport const BRANCH_SUMMARY_MODEL = 'haiku'\n\n/** A branch name is not worth blocking worktree creation on for long. */\nexport const BRANCH_SUMMARY_TIMEOUT_MS = 15_000\n\nconst MAX_INTENT_CHARS = 2_000\n/** A compliant reply is one short fragment; anything longer is prose. */\nconst MAX_REPLY_CHARS = 80\n/** More words than this is a sentence, not the fragment we asked for. */\nconst MAX_SLUG_WORDS = 6\nconst MAX_SLUG_CHARS = 48\n\nexport function branchSummaryPrompt(intent: string): string {\n return [\n 'Summarize this software task as a Git branch name fragment.',\n 'Reply with 2-5 lowercase English words joined by hyphens and nothing else:',\n 'no quotes, no slashes, no prefix, no punctuation, no explanation.',\n 'Translate the task to English if it is written in another language.',\n '',\n 'Task:',\n `\"\"\"\\n${intent.replaceAll('\"\"\"', '\" \" \"')}\\n\"\"\"`,\n ].join('\\n')\n}\n\n/** Branch-safe slug for a model reply, or `undefined` when the reply is not\n * the fragment we asked for. Mangling a refusal or a paragraph into a slug\n * would produce a worse name than the timestamped fallback. */\nexport function branchSlug(reply: string): string | undefined {\n const line = reply.trim()\n if (line.length === 0 || line.length > MAX_REPLY_CHARS || /[\\r\\n]/u.test(line)) return undefined\n const words = line.toLocaleLowerCase('en-US')\n .replace(/[^a-z0-9]+/gu, '-')\n .split('-')\n .filter(word => word.length > 0)\n if (words.length === 0 || words.length > MAX_SLUG_WORDS) return undefined\n // ponytail: a long fragment is cut mid-word; six short words almost never\n // reach 48 characters, and a branch name is allowed to be blunt.\n const slug = words.join('-').slice(0, MAX_SLUG_CHARS).replace(/-+$/u, '')\n return slug.length === 0 ? undefined : slug\n}\n\n/** First free name in `<candidate>`, `<candidate>-2`, `<candidate>-3`, … */\nexport function uniqueBranchName(candidate: string, taken: readonly string[]): string {\n const existing = new Set(taken)\n if (!existing.has(candidate)) return candidate\n for (let index = 2; index < 100; index += 1) {\n const name = `${candidate}-${index}`\n if (!existing.has(name)) return name\n }\n return candidate\n}\n\n/** Compress a composer draft into a branch slug with a throwaway Claude turn.\n *\n * Deliberately NOT routed through the supervisor, for the same reasons as the\n * plan-usage probe: there is no session to borrow yet. The turn is isolated\n * from filesystem settings as well, because a CLAUDE.md instruction (\"always\n * reply in the user's language\") turns the answer into an unusable slug. */\nexport async function summarizeBranchSlug(\n executablePath: string,\n intent: string,\n factory: (params: { prompt: string; options: ClaudeOptions }) => Query = claudeQuery,\n): Promise<string | undefined> {\n const task = intent.trim().slice(0, MAX_INTENT_CHARS)\n if (task.length === 0) return undefined\n const lifetime = new AbortController()\n const timer = setTimeout(() => lifetime.abort(), BRANCH_SUMMARY_TIMEOUT_MS)\n timer.unref?.()\n try {\n const query = factory({\n prompt: branchSummaryPrompt(task),\n options: {\n cwd: process.cwd(),\n abortController: lifetime,\n model: BRANCH_SUMMARY_MODEL,\n allowedTools: [],\n settingSources: [],\n maxTurns: 1,\n ...(executablePath.length === 0 ? {} : { pathToClaudeCodeExecutable: executablePath }),\n },\n })\n for await (const message of query) {\n if (message.type === 'result' && message.subtype === 'success') return branchSlug(message.result)\n }\n return undefined\n } catch {\n return undefined\n } finally {\n clearTimeout(timer)\n lifetime.abort()\n }\n}\n","import { randomUUID } from 'node:crypto'\nimport { mkdir, readdir, readFile, rename, rm, stat, writeFile } from 'node:fs/promises'\nimport { basename, isAbsolute, join, resolve } from 'node:path'\nimport { dshHomePath } from '@deepseek-ai/dsh-home-paths'\nimport type { SubprocessHandle, SubprocessRuntime } from '@deepseek-ai/dsh-subprocess'\nimport { uniqueBranchName } from './branch-name.ts'\n\nconst MAX_OUTPUT_BYTES = 128 * 1024\nconst GIT_TIMEOUT_MS = 10_000\nconst GIT_FETCH_TIMEOUT_MS = 60_000\nconst MAX_PATH_CHARS = 4_096\nconst MAX_BRANCH_CHARS = 512\nconst LEASE_SCHEMA_VERSION = 1\n// ponytail: grace only needs to outlive the worktree-create -> workspace-register\n// hop (seconds); two minutes keeps deletion feeling prompt while staying safe.\nconst CLEANUP_GRACE_MS = 2 * 60_000\n\ntype RepositorySetupRuntime = Pick<SubprocessRuntime, 'resolveExecutable' | 'spawn'>\n\ninterface CommandResult {\n readonly exitCode: number | null\n readonly stdout: string\n readonly stderr: string\n readonly lossy: boolean\n}\n\nexport interface RepositoryBranchList {\n readonly root: string\n readonly current?: string\n readonly dirty: boolean\n readonly branches: readonly string[]\n readonly remoteBranches: readonly string[]\n}\n\nexport type RepositorySetupStage = 'inspecting' | 'fetching' | 'summarizing' | 'creating-worktree' | 'saving-worktree' | 'switching-branch'\nexport type RepositorySetupProgress = (stage: RepositorySetupStage) => void\n\nexport interface RepositorySetupResult {\n readonly mode: 'checkout' | 'worktree'\n readonly root: string\n readonly path: string\n readonly branch: string\n readonly leaseId?: string\n}\n\nexport interface RepositoryCleanupResult {\n readonly mode: 'checkout' | 'worktree'\n readonly root: string\n readonly branch: string\n}\n\ninterface WorktreeLease {\n readonly id: string\n readonly root: string\n readonly path: string\n readonly branch: string\n readonly createdAt: string\n readonly pluginGeneratedBranch: boolean\n readonly sessionId?: string\n}\n\ninterface LeaseDocument {\n readonly schemaVersion: typeof LEASE_SCHEMA_VERSION\n readonly leases: readonly WorktreeLease[]\n}\n\nexport interface RepositorySetupServiceOptions {\n readonly leasePath?: string\n readonly worktreeRoot?: string\n readonly branchPrefix?: () => Promise<string>\n readonly cleanupGraceMs?: number\n /** Compress the composer draft into a branch slug; `undefined` result (or an\n * omitted option) falls back to the timestamped name. */\n readonly summarizeBranch?: (intent: string) => Promise<string | undefined>\n}\n\nexport class RepositorySetupError extends Error {\n readonly code: string\n\n constructor(code: string, message: string) {\n super(message)\n this.name = 'RepositorySetupError'\n this.code = code\n }\n}\n\nasync function collect(handle: SubprocessHandle): Promise<CommandResult> {\n const outcome = await handle.done\n const stdout = handle.collected.stdout?.readFrom(0)\n const stderr = handle.collected.stderr?.readFrom(0)\n return {\n exitCode: outcome.exitCode,\n stdout: stdout?.text ?? '',\n stderr: stderr?.text ?? '',\n lossy: stdout?.lossy === true || stderr?.lossy === true,\n }\n}\n\nfunction safePath(value: string): string {\n if (value.length === 0 || value.length > MAX_PATH_CHARS || !isAbsolute(value) || value.includes('\\0')) {\n throw new RepositorySetupError('invalid-path', 'The workspace path is invalid.')\n }\n return resolve(value)\n}\n\nfunction safeBranch(value: string): string {\n if (value.length === 0 || value.length > MAX_BRANCH_CHARS || value.trim() !== value || /[\\0\\r\\n]/u.test(value)) {\n throw new RepositorySetupError('invalid-branch', 'The branch name is invalid.')\n }\n return value\n}\n\nfunction parseCurrentBranch(value: string): string | undefined {\n const branch = value.trim()\n return branch.length === 0 || branch === 'HEAD' ? undefined : branch\n}\n\nexport function parseWorktreeBranches(value: string): ReadonlyMap<string, string> {\n const occupied = new Map<string, string>()\n let path: string | undefined\n for (const line of `${value}\\n`.split(/\\r?\\n/u)) {\n if (line.startsWith('worktree ')) path = line.slice('worktree '.length)\n else if (line.startsWith('branch refs/heads/') && path !== undefined) {\n occupied.set(line.slice('branch refs/heads/'.length), path)\n } else if (line.length === 0) path = undefined\n }\n return occupied\n}\n\nfunction slug(value: string, fallback: string): string {\n const normalized = value.toLocaleLowerCase('en-US').replace(/[^a-z0-9._-]+/gu, '-').replace(/^-+|-+$/gu, '')\n return normalized.slice(0, 48) || fallback\n}\n\n/** Comparable form for path identity: resolved, forward slashes, case-folded\n * so Windows drive-letter or case spelling differences cannot hide a match. */\nexport function comparablePath(value: string): string {\n return resolve(value).replaceAll('\\\\', '/').toLocaleLowerCase('en-US')\n}\n\nfunction pathExists(value: string): Promise<boolean> {\n return stat(value).then(() => true, () => false)\n}\n\nfunction lease(value: unknown): WorktreeLease | undefined {\n if (value === null || typeof value !== 'object' || Array.isArray(value)) return undefined\n const input = value as Record<string, unknown>\n if (typeof input.id !== 'string' || typeof input.root !== 'string' || typeof input.path !== 'string'\n || typeof input.branch !== 'string' || typeof input.createdAt !== 'string'\n || (input.pluginGeneratedBranch !== undefined && typeof input.pluginGeneratedBranch !== 'boolean')\n || (input.sessionId !== undefined && typeof input.sessionId !== 'string')) return undefined\n return {\n id: input.id,\n root: input.root,\n path: input.path,\n branch: input.branch,\n createdAt: input.createdAt,\n pluginGeneratedBranch: input.pluginGeneratedBranch === true,\n ...(input.sessionId === undefined ? {} : { sessionId: input.sessionId }),\n }\n}\n\nexport class RepositorySetupService {\n readonly #runtime: RepositorySetupRuntime\n readonly #leasePath: string\n readonly #worktreeRoot: string\n readonly #branchPrefix: () => Promise<string>\n readonly #summarizeBranch: (intent: string) => Promise<string | undefined>\n readonly #cleanupGraceMs: number\n #gitPath: Promise<string> | undefined\n #pending: Promise<unknown> = Promise.resolve()\n\n constructor(runtime: RepositorySetupRuntime, options: RepositorySetupServiceOptions = {}) {\n this.#runtime = runtime\n this.#leasePath = options.leasePath ?? dshHomePath('plugins', 'dsh-claude', 'worktrees.json')\n this.#worktreeRoot = options.worktreeRoot ?? dshHomePath('plugins', 'dsh-claude', 'worktrees')\n this.#branchPrefix = options.branchPrefix ?? (async () => 'claude')\n this.#summarizeBranch = options.summarizeBranch ?? (async () => undefined)\n this.#cleanupGraceMs = options.cleanupGraceMs ?? CLEANUP_GRACE_MS\n }\n\n async listBranches(cwd: string): Promise<RepositoryBranchList> {\n const git = await this.#git()\n return this.#listBranches(git, await this.#repositoryRoot(git, safePath(cwd)))\n }\n\n /** Refresh remote-tracking refs before listing: a branch pushed after this\n * checkout last fetched has no local ref, so the picker cannot offer it. */\n async refreshBranches(cwd: string): Promise<RepositoryBranchList> {\n const git = await this.#git()\n const root = await this.#repositoryRoot(git, safePath(cwd))\n await this.#fetchRemotes(git, root)\n return this.#listBranches(git, root)\n }\n\n async #listBranches(git: string, root: string): Promise<RepositoryBranchList> {\n const [status, refs, remoteRefs] = await Promise.all([\n this.#run(git, ['status', '--porcelain=v2', '--branch', '--untracked-files=normal'], root),\n this.#run(git, ['for-each-ref', '--format=%(refname:short)', 'refs/heads'], root),\n this.#run(git, ['for-each-ref', '--format=%(refname:short) %(symref)', 'refs/remotes'], root),\n ])\n if (status.exitCode !== 0 || status.lossy || refs.exitCode !== 0 || refs.lossy\n || remoteRefs.exitCode !== 0 || remoteRefs.lossy) {\n throw new RepositorySetupError('repository-unavailable', 'The repository state is unavailable.')\n }\n const current = status.stdout.split(/\\r?\\n/u)\n .find(line => line.startsWith('# branch.head '))\n ?.slice('# branch.head '.length)\n const branches = refs.stdout.split(/\\r?\\n/u).filter(Boolean).sort((left, right) => left.localeCompare(right))\n const remoteBranches = remoteRefs.stdout.split(/\\r?\\n/u)\n .map(line => line.trim().split(/\\s+/u))\n .filter(parts => parts[0] !== undefined && parts[0].length > 0 && parts.length === 1)\n .map(parts => parts[0]!)\n .sort((left, right) => left.localeCompare(right))\n const currentBranch = current === undefined ? undefined : parseCurrentBranch(current)\n return {\n root,\n ...(currentBranch === undefined ? {} : { current: currentBranch }),\n dirty: status.stdout.split(/\\r?\\n/u).some(line => line.length > 0 && !line.startsWith('# ')),\n branches,\n remoteBranches,\n }\n }\n\n async setup(\n cwd: string,\n branchValue: string,\n useWorktree: boolean,\n explicitBranchName?: string,\n progress: RepositorySetupProgress = () => {},\n intent?: string,\n ): Promise<RepositorySetupResult> {\n progress('inspecting')\n const branch = safeBranch(branchValue)\n const info = await this.listBranches(cwd)\n const local = info.branches.includes(branch)\n const remote = info.remoteBranches.includes(branch)\n if (!local && !remote) {\n throw new RepositorySetupError('branch-not-found', 'The selected local or remote-tracking branch does not exist.')\n }\n const requestedBranch = explicitBranchName === undefined ? undefined : safeBranch(explicitBranchName)\n if (useWorktree) {\n return this.#createWorktree(\n info,\n branch,\n local ? `refs/heads/${branch}` : `refs/remotes/${branch}`,\n requestedBranch,\n requestedBranch !== undefined && info.branches.includes(requestedBranch),\n progress,\n intent,\n )\n }\n progress('switching-branch')\n return !local && remote ? this.#checkoutRemote(info, branch) : this.#checkout(info, branch)\n }\n\n /** Tear down a merged branch: remove a plugin worktree (and its lease and\n * branch), or switch a plain checkout back to the base branch and delete\n * the merged branch. Refuses dirty trees. */\n async cleanupMerged(pathValue: string, baseBranch: string): Promise<RepositoryCleanupResult> {\n const path = safePath(pathValue)\n const base = safeBranch(baseBranch)\n const git = await this.#git()\n const status = await this.#run(git, ['status', '--porcelain=v1', '--untracked-files=normal'], path)\n if (status.exitCode !== 0 || status.lossy) throw new RepositorySetupError('repository-unavailable', 'The repository state is unavailable.')\n if (status.stdout.trim().length > 0) throw new RepositorySetupError('dirty-workspace', 'Commit or stash workspace changes before cleaning up.')\n const lease = (await this.#readLeases()).find(item => comparablePath(item.path) === comparablePath(path))\n if (lease !== undefined) {\n return this.#serialize(async () => {\n const removed = await this.#run(git, ['worktree', 'remove', '--', lease.path], lease.root)\n if (removed.exitCode !== 0) throw new RepositorySetupError('worktree-remove-failed', 'Git could not remove the worktree.')\n await this.#run(git, ['branch', '-D', '--', lease.branch], lease.root).catch(() => undefined)\n const current = await this.#readLeases()\n await this.#writeLeases(current.filter(item => item.id !== lease.id))\n return { mode: 'worktree' as const, root: lease.root, branch: lease.branch }\n })\n }\n const root = await this.#repositoryRoot(git, path)\n const head = await this.#run(git, ['symbolic-ref', '--quiet', '--short', 'HEAD'], root)\n const branch = head.exitCode === 0 ? head.stdout.trim() : ''\n if (branch.length === 0 || branch === base) throw new RepositorySetupError('nothing-to-clean', 'The checkout is already on the base branch.')\n const switched = await this.#run(git, ['switch', '--', base], root)\n if (switched.exitCode !== 0) throw new RepositorySetupError('checkout-failed', 'Git could not switch to the base branch.')\n await this.#run(git, ['branch', '-D', '--', branch], root).catch(() => undefined)\n await this.#run(git, ['pull', '--ff-only'], root, GIT_FETCH_TIMEOUT_MS).catch(() => undefined)\n return { mode: 'checkout', root, branch }\n }\n\n bindLease(leaseId: string, sessionId: string): Promise<void> {\n if (leaseId.length === 0 || leaseId.length > 128 || sessionId.length === 0 || sessionId.length > 1_024) {\n return Promise.reject(new RepositorySetupError('invalid-lease', 'The worktree lease is invalid.'))\n }\n return this.#serialize(async () => {\n const leases = await this.#readLeases()\n const index = leases.findIndex(item => item.id === leaseId)\n if (index < 0) throw new RepositorySetupError('lease-not-found', 'The worktree lease no longer exists.')\n const existing = leases[index]\n if (existing === undefined) throw new RepositorySetupError('lease-not-found', 'The worktree lease no longer exists.')\n leases[index] = { ...existing, sessionId }\n await this.#writeLeases(leases)\n })\n }\n\n /** Reconcile leases against the set of directories still referenced by a\n * workspace. Deleting a workspace is the user saying they are done with it,\n * so an unreferenced worktree goes even with uncommitted changes; its\n * sessions are archived first, through `archiveSessions`, or the Host\n * rebuilds the deleted workspace from their headers on the next boot.\n * Fresh leases are retained for a grace period so a worktree created\n * moments ago cannot be swept before its workspace registration lands.\n *\n * Every command runs from the repository root, never from the worktree\n * being removed: spawning in a directory that is already gone throws\n * ENOENT, which used to strand the lease forever. */\n cleanupOrphans(\n activePaths: readonly string[],\n archiveSessions?: (worktreePath: string) => Promise<void>,\n ): Promise<void> {\n const active = new Set(activePaths.map(comparablePath))\n return this.#serialize(async () => {\n const leases = await this.#readLeases()\n const retained: WorktreeLease[] = []\n let changed = false\n const git = await this.#git()\n const now = Date.now()\n for (const item of leases) {\n const age = now - Date.parse(item.createdAt)\n if (active.has(comparablePath(item.path)) || !(age >= this.#cleanupGraceMs)) {\n retained.push(item)\n continue\n }\n try {\n // Best effort: a Host that cannot archive must not strand the lease,\n // and the worktree removal below is what the user asked for.\n await archiveSessions?.(item.path).catch(() => undefined)\n if (await pathExists(item.path)) {\n const removed = await this.#run(git, ['worktree', 'remove', '--force', '--', item.path], item.root)\n if (removed.exitCode !== 0) {\n retained.push(item)\n continue\n }\n } else {\n // The directory is already gone; let Git forget the stale\n // worktree registration before the lease follows it.\n await this.#run(git, ['worktree', 'prune'], item.root).catch(() => undefined)\n }\n if (item.pluginGeneratedBranch) {\n await this.#run(git, ['branch', '-D', '--', item.branch], item.root).catch(() => undefined)\n }\n changed = true\n } catch {\n if (await pathExists(item.root)) retained.push(item)\n else changed = true // the repository itself is gone; the lease is dead weight\n }\n }\n if (changed) await this.#writeLeases(retained)\n await this.#removeUnleasedDirectories(retained, active, now, archiveSessions)\n })\n }\n\n /** Remove directories under the plugin's own worktree root that no lease and\n * no workspace claims. A lease file lost to a crash, or a worktree whose\n * lease write failed, otherwise leaves a directory nothing will ever sweep.\n * The grace period covers the gap between `worktree add` and the lease\n * write, so a worktree being created right now is never taken. */\n async #removeUnleasedDirectories(\n retained: readonly WorktreeLease[],\n active: ReadonlySet<string>,\n now: number,\n archiveSessions?: (worktreePath: string) => Promise<void>,\n ): Promise<void> {\n const leased = new Set(retained.map(item => comparablePath(item.path)))\n let entries: string[]\n try {\n entries = await readdir(this.#worktreeRoot)\n } catch {\n return // no worktree root yet, or it is unreadable; nothing to sweep\n }\n for (const entry of entries) {\n const path = join(this.#worktreeRoot, entry)\n const key = comparablePath(path)\n if (leased.has(key) || active.has(key)) continue\n try {\n const info = await stat(path)\n if (!info.isDirectory()) continue\n const created = info.birthtimeMs > 0 ? info.birthtimeMs : info.mtimeMs\n // Date.now() truncates to whole milliseconds while birthtime carries a\n // fraction, so a directory created moments ago can read as newer than\n // the clock; clamp rather than let that skip a sweep.\n if (Math.max(0, now - created) < this.#cleanupGraceMs) continue\n // A lost lease is still the user's deleted workspace: its sessions\n // have to be archived here too, or the Host rebuilds the workspace\n // from their headers on the next boot.\n await archiveSessions?.(path).catch(() => undefined)\n await rm(path, { recursive: true, force: true })\n } catch {\n // A directory that vanished under us, or one we may not remove; the\n // next pass sees it again.\n }\n }\n }\n\n async #checkoutRemote(info: RepositoryBranchList, remoteBranch: string): Promise<RepositorySetupResult> {\n const separator = remoteBranch.indexOf('/')\n if (separator <= 0 || separator === remoteBranch.length - 1) {\n throw new RepositorySetupError('invalid-branch', 'The remote-tracking branch name is invalid.')\n }\n const localBranch = safeBranch(remoteBranch.slice(separator + 1))\n if (info.branches.includes(localBranch)) {\n const git = await this.#git()\n const upstream = await this.#run(git, ['for-each-ref', '--format=%(upstream:short)', `refs/heads/${localBranch}`], info.root)\n if (upstream.exitCode !== 0 || upstream.lossy) {\n throw new RepositorySetupError('repository-unavailable', 'The local branch tracking state is unavailable.')\n }\n if (upstream.stdout.trim() !== remoteBranch) {\n throw new RepositorySetupError('branch-tracking-conflict', `The local branch ${localBranch} does not track ${remoteBranch}.`)\n }\n return this.#checkout(info, localBranch)\n }\n if (info.dirty) throw new RepositorySetupError('dirty-workspace', 'Commit or stash workspace changes before switching branches.')\n const git = await this.#git()\n const switched = await this.#run(git, ['switch', '--track', '-c', localBranch, `refs/remotes/${remoteBranch}`], info.root)\n if (switched.exitCode !== 0) throw new RepositorySetupError('checkout-failed', 'Git could not create the local tracking branch.')\n return { mode: 'checkout', root: info.root, path: info.root, branch: localBranch }\n }\n\n async #fetchRemotes(git: string, root: string): Promise<void> {\n const fetched = await this.#run(\n git,\n ['-c', 'credential.interactive=never', 'fetch', '--all', '--prune'],\n root,\n GIT_FETCH_TIMEOUT_MS,\n )\n if (fetched.exitCode !== 0 || fetched.lossy) {\n throw new RepositorySetupError('fetch-failed', 'Git could not refresh remote references.')\n }\n }\n\n async #checkout(info: RepositoryBranchList, branch: string): Promise<RepositorySetupResult> {\n if (info.current !== branch) {\n if (info.dirty) throw new RepositorySetupError('dirty-workspace', 'Commit or stash workspace changes before switching branches.')\n const git = await this.#git()\n const worktrees = await this.#run(git, ['worktree', 'list', '--porcelain'], info.root)\n if (worktrees.exitCode !== 0 || worktrees.lossy) throw new RepositorySetupError('repository-unavailable', 'Worktree state is unavailable.')\n const occupiedPath = parseWorktreeBranches(worktrees.stdout).get(branch)\n if (occupiedPath !== undefined && resolve(occupiedPath) !== info.root) {\n throw new RepositorySetupError('branch-occupied', 'The selected branch is already checked out in another worktree.')\n }\n const switched = await this.#run(git, ['switch', '--', branch], info.root)\n if (switched.exitCode !== 0) throw new RepositorySetupError('checkout-failed', 'Git could not switch to the selected branch.')\n }\n return { mode: 'checkout', root: info.root, path: info.root, branch }\n }\n\n async #createWorktree(\n info: RepositoryBranchList,\n baseBranch: string,\n baseRef: string,\n explicitBranchName: string | undefined,\n reuseExistingBranch: boolean,\n progress: RepositorySetupProgress,\n intent: string | undefined,\n ): Promise<RepositorySetupResult> {\n const { root } = info\n const git = await this.#git()\n progress('fetching')\n await this.#fetchRemotes(git, root)\n const suffix = randomUUID().slice(0, 8)\n const stamp = new Date().toISOString().replace(/[-:]/gu, '').replace(/\\.\\d{3}Z$/u, 'Z')\n const branch = explicitBranchName ?? await this.#generatedBranch(info, baseBranch, intent, stamp, suffix, progress)\n const path = join(this.#worktreeRoot, `${slug(basename(root), 'repository')}-${stamp}-${suffix}`)\n progress('creating-worktree')\n await mkdir(this.#worktreeRoot, { recursive: true })\n // A stale registration from a deleted worktree directory would keep the\n // existing branch \"checked out\" and block reusing it.\n if (reuseExistingBranch) await this.#run(git, ['worktree', 'prune'], root).catch(() => undefined)\n const created = await this.#run(\n git,\n reuseExistingBranch ? ['worktree', 'add', '--', path, branch] : ['worktree', 'add', '-b', branch, path, baseRef],\n root,\n )\n if (created.exitCode !== 0) {\n const detail = created.stderr.split(/\\r?\\n/u).map(line => line.trim()).filter(line => line.length > 0).at(-1)\n throw new RepositorySetupError('worktree-failed', detail === undefined ? 'Git could not create the worktree.' : `Git could not create the worktree: ${detail}`)\n }\n const item: WorktreeLease = {\n id: randomUUID(),\n root,\n path,\n branch,\n createdAt: new Date().toISOString(),\n pluginGeneratedBranch: explicitBranchName === undefined,\n }\n progress('saving-worktree')\n try {\n await this.#serialize(async () => {\n const leases = await this.#readLeases()\n await this.#writeLeases([...leases, item])\n })\n } catch (error) {\n await this.#run(git, ['worktree', 'remove', '--force', '--', path], root).catch(() => undefined)\n if (!reuseExistingBranch) await this.#run(git, ['branch', '-D', '--', branch], root).catch(() => undefined)\n throw error\n }\n return { mode: 'worktree', root, path, branch, leaseId: item.id }\n }\n\n /** `<prefix>/<what the draft is about>`, falling back to\n * `<prefix>/<base branch>-<stamp>-<random>` whenever the summary is missing\n * or unusable. The prefix and the fallback shape are unchanged. */\n async #generatedBranch(\n info: RepositoryBranchList,\n baseBranch: string,\n intent: string | undefined,\n stamp: string,\n suffix: string,\n progress: RepositorySetupProgress,\n ): Promise<string> {\n const prefix = safeBranch(await this.#branchPrefix())\n if (intent !== undefined && intent.trim().length > 0) {\n progress('summarizing')\n // The summary is a convenience, never a reason to fail the worktree.\n const summary = await this.#summarizeBranch(intent).catch(() => undefined)\n if (summary !== undefined) return uniqueBranchName(`${prefix}/${summary}`, info.branches)\n }\n return `${prefix}/${slug(baseBranch, 'branch')}-${stamp}-${suffix}`\n }\n\n async #repositoryRoot(git: string, cwd: string): Promise<string> {\n const result = await this.#run(git, ['rev-parse', '--path-format=absolute', '--show-toplevel'], cwd)\n const root = result.stdout.trim()\n if (result.exitCode !== 0 || result.lossy || root.length === 0 || !isAbsolute(root)) {\n throw new RepositorySetupError('not-repository', 'The workspace is not a Git repository.')\n }\n return resolve(root)\n }\n\n #git(): Promise<string> {\n // A cached pending or rejected lookup would wedge every later request, so\n // bound it and drop the cache on failure.\n this.#gitPath ??= this.#runtime.resolveExecutable('git', undefined, AbortSignal.timeout(GIT_TIMEOUT_MS))\n .catch((error: unknown) => {\n this.#gitPath = undefined\n throw error\n })\n return this.#gitPath\n }\n\n\n async #run(executable: string, args: readonly string[], cwd: string, timeoutMs = GIT_TIMEOUT_MS): Promise<CommandResult> {\n return collect(this.#runtime.spawn({\n argv: [executable, ...args],\n cwd,\n stdio: {\n stdin: 'ignore',\n stdout: { maxBytes: MAX_OUTPUT_BYTES },\n stderr: { maxBytes: MAX_OUTPUT_BYTES },\n },\n graceMs: 1_000,\n signal: AbortSignal.timeout(timeoutMs),\n env: {},\n }))\n }\n\n async #readLeases(): Promise<WorktreeLease[]> {\n try {\n const parsed = JSON.parse(await readFile(this.#leasePath, 'utf8')) as unknown\n if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) return []\n const input = parsed as Record<string, unknown>\n if (input.schemaVersion !== LEASE_SCHEMA_VERSION || !Array.isArray(input.leases)) return []\n return input.leases.map(lease).filter((item): item is WorktreeLease => item !== undefined)\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') return []\n throw error\n }\n }\n\n async #writeLeases(leases: readonly WorktreeLease[]): Promise<void> {\n await mkdir(resolve(this.#leasePath, '..'), { recursive: true })\n const temporary = `${this.#leasePath}.${process.pid}.${randomUUID()}.tmp`\n const document: LeaseDocument = { schemaVersion: LEASE_SCHEMA_VERSION, leases }\n try {\n await writeFile(temporary, `${JSON.stringify(document, null, 2)}\\n`, { mode: 0o600 })\n await rename(temporary, this.#leasePath)\n } finally {\n await rm(temporary, { force: true }).catch(() => undefined)\n }\n }\n\n #serialize<T>(operation: () => Promise<T>): Promise<T> {\n const result = this.#pending.then(operation, operation)\n this.#pending = result.then(() => undefined, () => undefined)\n return result\n }\n}\n","import { createHash } from 'node:crypto'\nimport { basename } from 'node:path'\nimport type { SubprocessHandle, SubprocessRuntime } from '@deepseek-ai/dsh-subprocess'\n\nconst MAX_OUTPUT_BYTES = 256 * 1024\nconst MAX_PATCH_CHARS = 64 * 1024\nconst MAX_MESSAGE_CHARS = 512\nconst MAX_PR_TEXT_CHARS = 8 * 1024\nconst MAX_UNPUSHED_COMMITS = 20\nconst GIT_TIMEOUT_MS = 15_000\nconst REMOTE_TIMEOUT_MS = 60_000\nconst GENERATE_TIMEOUT_MS = 60_000\n/** One cold `claude -p` per generation, so everything the subject line cannot\n * use is cost: MCP servers (which `ask` already skips for the same reason,\n * and which stall for as long as an unreachable one takes to give up) and the\n * user's own hooks and settings. Project settings stay: a repository's commit\n * conventions belong in the message. `--tools ''` keeps `--output-format`\n * between it and the prompt -- both flags are variadic. */\nconst GENERATE_ARGUMENTS: readonly string[] = [\n '-p',\n '--strict-mcp-config', '--mcp-config', '{\"mcpServers\":{}}',\n '--setting-sources', 'project,local',\n '--tools', '', '--output-format', 'text',\n]\n\ntype RepositoryActionRuntime = Pick<SubprocessRuntime, 'resolveExecutable' | 'spawn'>\nexport type RepositoryActionKind = 'commit' | 'commit-push' | 'push' | 'create-pr' | 'merge-pr' | 'update-branch'\nexport type RepositoryMergeMethod = 'merge' | 'squash' | 'rebase'\n\ninterface CommandResult {\n readonly exitCode: number | null\n readonly stdout: string\n readonly stderr: string\n readonly lossy: boolean\n}\n\nexport interface RepositoryActionFile {\n readonly path: string\n readonly staged: boolean\n readonly unstaged: boolean\n readonly untracked: boolean\n}\n\nexport interface RepositoryActionCommit {\n readonly hash: string\n readonly subject: string\n}\n\nexport interface RepositoryActionPreview {\n readonly root: string\n readonly branch: string\n readonly head: string\n readonly fingerprint: string\n readonly files: readonly RepositoryActionFile[]\n readonly patch: string\n readonly truncated: boolean\n readonly hasStaged: boolean\n readonly hasUnstaged: boolean\n readonly hasUntracked: boolean\n readonly upstream?: string\n readonly unpushedCommits: readonly RepositoryActionCommit[]\n readonly unpushedTruncated: boolean\n}\n\nexport interface RepositoryActionRequest {\n readonly action: RepositoryActionKind\n readonly fingerprint: string\n readonly message: string\n readonly includeUnstaged: boolean\n readonly prTitle?: string\n readonly prBody?: string\n readonly baseBranch?: string\n readonly draft?: boolean\n readonly mergeMethod?: RepositoryMergeMethod\n}\n\nexport interface RepositoryActionResult {\n readonly commit: string\n readonly pushed: boolean\n readonly pullRequestUrl?: string\n /** Conflicted paths left in the working tree by an update-branch merge or rebase. */\n readonly conflicts?: readonly string[]\n}\n\nexport class RepositoryActionError extends Error {\n readonly code: string\n readonly commit?: string\n\n constructor(code: string, message: string, commit?: string) {\n super(message)\n this.name = 'RepositoryActionError'\n this.code = code\n if (commit !== undefined) this.commit = commit\n }\n}\n\nasync function collect(handle: SubprocessHandle): Promise<CommandResult> {\n const outcome = await handle.done\n const stdout = handle.collected.stdout?.readFrom(0)\n const stderr = handle.collected.stderr?.readFrom(0)\n return {\n exitCode: outcome.exitCode,\n stdout: stdout?.text ?? '',\n stderr: stderr?.text ?? '',\n lossy: stdout?.lossy === true || stderr?.lossy === true,\n }\n}\n\nfunction safeText(value: string, maximum: number, label: string): string {\n const text = value.trim()\n if (text.length === 0 || text.length > maximum || /[\\0\\r]/u.test(text)) {\n throw new RepositoryActionError('invalid-request', `${label} is invalid.`)\n }\n return text\n}\n\nexport function isProtectedWarpPath(path: string): boolean {\n return basename(path.replaceAll('\\\\', '/')).toLocaleLowerCase('en-US') === 'warp.md'\n}\n\nexport function parseRepositoryActionStatus(output: string): readonly RepositoryActionFile[] {\n const files = new Map<string, RepositoryActionFile>()\n const records = output.includes('\\0') ? output.split('\\0') : output.split(/\\r?\\n/u)\n for (let position = 0; position < records.length; position += 1) {\n const line = records[position] ?? ''\n if (line.length < 4) continue\n const index = line[0] ?? ' '\n const worktree = line[1] ?? ' '\n let path = line.slice(3)\n const rename = path.lastIndexOf(' -> ')\n if (rename >= 0) path = path.slice(rename + 4)\n if (output.includes('\\0') && (index === 'R' || index === 'C' || worktree === 'R' || worktree === 'C')) position += 1\n if (path.length === 0 || path.includes('\\0') || isProtectedWarpPath(path)) continue\n files.set(path, {\n path,\n staged: index !== ' ' && index !== '?',\n unstaged: worktree !== ' ' && worktree !== '?',\n untracked: index === '?' && worktree === '?',\n })\n }\n return [...files.values()].sort((left, right) => left.path.localeCompare(right.path))\n}\n\nfunction fallbackCommitMessage(files: readonly RepositoryActionFile[]): string {\n if (files.length === 1) return `Update ${files[0]?.path ?? 'repository files'}`\n return `Update ${files.length} repository files`\n}\n\nfunction normalizedGeneratedMessage(value: string, fallback: string): string {\n const first = value.split(/\\r?\\n/u).map(line => line.trim()).find(Boolean)\n if (first === undefined) return fallback\n const message = first.replace(/^['\"`]+|['\"`]+$/gu, '').replace(/[\\0\\r\\n]/gu, ' ').trim()\n return message.length === 0 || message.length > 72 ? fallback : message\n}\n\nfunction validPrUrl(value: string): string | undefined {\n try {\n const url = new URL(value.trim())\n return url.protocol === 'https:' && url.hostname === 'github.com' ? url.href : undefined\n } catch {\n return undefined\n }\n}\n\nexport function validPullRequestBody(value: string): boolean {\n const body = value.trim()\n const match = /^Summary:\\s+([^\\r\\n]+)\\r?\\n\\r?\\nChanges:\\s*\\r?\\n([\\s\\S]+)$/u.exec(body)\n const summary = match?.[1]?.trim()\n const changes = match?.[2]?.trim()\n if (summary === undefined || summary.length === 0 || changes === undefined || changes.length === 0) return false\n return !/^#{1,6}\\s|^[A-Za-z][A-Za-z ]+:\\s*$/mu.test(changes)\n}\n\nexport class RepositoryActionService {\n readonly #runtime: RepositoryActionRuntime\n readonly #claudeExecutable: string\n readonly #invalidate: (cwd: string) => void\n #gitExecutable?: Promise<string>\n #ghExecutable?: Promise<string>\n #pending: Promise<unknown> = Promise.resolve()\n\n constructor(runtime: RepositoryActionRuntime, claudeExecutable: string, invalidate: (cwd: string) => void = () => {}) {\n this.#runtime = runtime\n this.#claudeExecutable = claudeExecutable\n this.#invalidate = invalidate\n }\n\n preview(cwd: string): Promise<RepositoryActionPreview> {\n return this.#preview(cwd)\n }\n\n async generateMessage(cwd: string, fingerprint: string): Promise<string> {\n const preview = await this.#preview(cwd)\n if (preview.fingerprint !== fingerprint) throw new RepositoryActionError('repository-changed', 'Repository changes have changed. Refresh the commit panel.')\n const fallback = fallbackCommitMessage(preview.files)\n const prompt = [\n 'Write one concise English git commit subject (imperative mood, maximum 72 characters).',\n 'Return only the subject without quotes, markdown, body, or explanation.',\n `Files: ${preview.files.map(file => file.path).join(', ')}`,\n `Diff:\\n${preview.patch.slice(0, 24 * 1024)}`,\n ].join('\\n')\n try {\n const result = await this.#run(this.#claudeExecutable, GENERATE_ARGUMENTS.concat(prompt), preview.root, GENERATE_TIMEOUT_MS)\n return result.exitCode === 0 && !result.lossy ? normalizedGeneratedMessage(result.stdout, fallback) : fallback\n } catch {\n return fallback\n }\n }\n\n execute(cwd: string, request: RepositoryActionRequest): Promise<RepositoryActionResult> {\n const operation = this.#pending.then(() => this.#execute(cwd, request))\n this.#pending = operation.then(() => undefined, () => undefined)\n return operation\n }\n\n async #execute(cwd: string, request: RepositoryActionRequest): Promise<RepositoryActionResult> {\n const before = await this.#preview(cwd)\n if (before.fingerprint !== request.fingerprint) throw new RepositoryActionError('repository-changed', 'Repository changes have changed. Refresh the commit panel.')\n if (request.action === 'push') {\n const git = await this.#git()\n try {\n await this.#push(git, before.root, before.branch)\n } catch (error) {\n throw new RepositoryActionError('push-failed', error instanceof Error ? error.message : 'Git push failed.')\n }\n this.#invalidate(before.root)\n return { commit: before.head, pushed: true }\n }\n if (request.action === 'merge-pr') {\n const method = request.mergeMethod\n if (method !== 'merge' && method !== 'squash' && method !== 'rebase') {\n throw new RepositoryActionError('invalid-request', 'The merge method is invalid.')\n }\n let gh: string\n try {\n gh = await this.#gh()\n } catch (error) {\n throw new RepositoryActionError('gh-unavailable', error instanceof Error ? error.message : 'GitHub CLI is unavailable.')\n }\n const merged = await this.#run(gh, ['pr', 'merge', `--${method}`], before.root, REMOTE_TIMEOUT_MS)\n if (merged.exitCode !== 0 || merged.lossy) {\n const reason = merged.stderr.split(/\\r?\\n/u).map(line => line.trim()).filter(line => line.length > 0).at(-1)\n throw new RepositoryActionError('merge-failed', reason === undefined || reason.length === 0 ? 'The pull request could not be merged.' : reason)\n }\n this.#invalidate(before.root)\n return { commit: before.head, pushed: true }\n }\n if (request.action === 'update-branch') {\n const base = safeText(request.baseBranch ?? '', 512, 'Base branch')\n if (before.files.length > 0) {\n throw new RepositoryActionError('dirty-workspace', 'Commit or stash workspace changes before updating the branch.')\n }\n const method = request.mergeMethod ?? 'rebase'\n if (method !== 'merge' && method !== 'rebase') throw new RepositoryActionError('invalid-request', 'Update branch supports merge or rebase.')\n const git = await this.#git()\n await this.#mustRun(git, ['fetch', 'origin', '--', base], before.root, REMOTE_TIMEOUT_MS, 'fetch-failed', 'Git could not fetch the base branch.')\n const merged = await this.#run(git, method === 'rebase' ? ['rebase', '--', `origin/${base}`] : ['merge', '--no-edit', '--', `origin/${base}`], before.root, REMOTE_TIMEOUT_MS)\n if (merged.exitCode !== 0 || merged.lossy) {\n const conflicted = await this.#run(git, ['diff', '--name-only', '--diff-filter=U', '--'], before.root, GIT_TIMEOUT_MS)\n const conflicts = conflicted.exitCode === 0 && !conflicted.lossy\n ? conflicted.stdout.split(/\\r?\\n/u).filter(line => line.length > 0).slice(0, 100)\n : []\n if (conflicts.length === 0) {\n await this.#run(git, [method, '--abort'], before.root, GIT_TIMEOUT_MS).catch(() => undefined)\n throw new RepositoryActionError('merge-failed', `Git could not ${method} the base branch.`)\n }\n // Leave the conflicted tree in place: resolving it is the next step.\n this.#invalidate(before.root)\n return { commit: before.head, pushed: false, conflicts }\n }\n const mergedHead = (await this.#mustRun(git, ['rev-parse', 'HEAD'], before.root, GIT_TIMEOUT_MS, 'merge-failed', 'The updated commit could not be verified.')).stdout.trim()\n try {\n // A rebase rewrites the branch, so the push must replace the remote ref; --force-with-lease still refuses if someone else pushed.\n await this.#push(git, before.root, before.branch, method === 'rebase')\n } catch (error) {\n throw new RepositoryActionError('push-failed', error instanceof Error ? error.message : 'Git push failed.', mergedHead)\n }\n this.#invalidate(before.root)\n return { commit: mergedHead, pushed: true }\n }\n const message = safeText(request.message, MAX_MESSAGE_CHARS, 'Commit message')\n if (before.files.length === 0 && request.action !== 'create-pr') {\n throw new RepositoryActionError('nothing-to-commit', 'There are no changes to commit.')\n }\n const git = await this.#git()\n let oid = before.head\n if (before.files.length > 0) {\n await this.#rejectStagedWarp(git, before.root)\n if (request.includeUnstaged) {\n const paths = before.files.filter(file => file.unstaged || file.untracked).map(file => file.path)\n if (paths.length > 0) await this.#mustRun(git, ['add', '--', ...paths], before.root, GIT_TIMEOUT_MS, 'stage-failed', 'Changes could not be staged.')\n }\n await this.#rejectStagedWarp(git, before.root)\n const staged = await this.#run(git, ['diff', '--cached', '--quiet', '--exit-code', '--'], before.root, GIT_TIMEOUT_MS)\n if (staged.exitCode === 0) throw new RepositoryActionError('nothing-to-commit', 'There are no staged changes to commit.')\n if (staged.exitCode !== 1) throw new RepositoryActionError('repository-unavailable', 'The staged changes could not be verified.')\n await this.#mustRun(git, ['commit', '-m', message, '--'], before.root, GIT_TIMEOUT_MS, 'commit-failed', 'Git commit failed.')\n oid = (await this.#mustRun(git, ['rev-parse', 'HEAD'], before.root, GIT_TIMEOUT_MS, 'commit-failed', 'The new commit could not be verified.')).stdout.trim()\n this.#invalidate(before.root)\n if (request.action === 'commit') return { commit: oid, pushed: false }\n }\n try {\n await this.#push(git, before.root, before.branch)\n } catch (error) {\n throw new RepositoryActionError('push-failed', error instanceof Error ? error.message : 'Git push failed.', oid)\n }\n this.#invalidate(before.root)\n if (request.action === 'commit-push') return { commit: oid, pushed: true }\n const title = safeText(request.prTitle ?? message, 256, 'Pull request title')\n const body = safeText(request.prBody ?? '', MAX_PR_TEXT_CHARS, 'Pull request description')\n if (!validPullRequestBody(body)) {\n throw new RepositoryActionError('invalid-pr-description', 'Pull request description must contain only Summary and Changes sections.', oid)\n }\n let gh: string\n try {\n gh = await this.#gh()\n } catch (error) {\n throw new RepositoryActionError('gh-unavailable', error instanceof Error ? error.message : 'GitHub CLI is unavailable.', oid)\n }\n const args = ['pr', 'create', '--title', title, '--body', body]\n if (request.draft !== false) args.push('--draft')\n if (request.baseBranch !== undefined) args.push('--base', safeText(request.baseBranch, 512, 'Base branch'))\n const created = await this.#run(gh, args, before.root, REMOTE_TIMEOUT_MS)\n const url = created.exitCode === 0 && !created.lossy ? validPrUrl(created.stdout) : undefined\n if (url === undefined) throw new RepositoryActionError('pr-failed', 'The pull request could not be created.', oid)\n return { commit: oid, pushed: true, pullRequestUrl: url }\n }\n\n async #preview(cwd: string): Promise<RepositoryActionPreview> {\n const git = await this.#git()\n const rootResult = await this.#mustRun(git, ['rev-parse', '--path-format=absolute', '--show-toplevel'], cwd, GIT_TIMEOUT_MS, 'not-repository', 'The session directory is not a Git repository.')\n const root = rootResult.stdout.trim()\n const [branchResult, headResult, statusResult, stagedPatch, unstagedPatch] = await Promise.all([\n this.#run(git, ['symbolic-ref', '--quiet', '--short', 'HEAD'], root, GIT_TIMEOUT_MS),\n this.#run(git, ['rev-parse', 'HEAD'], root, GIT_TIMEOUT_MS),\n this.#run(git, ['status', '--porcelain=v1', '-z', '--untracked-files=all'], root, GIT_TIMEOUT_MS),\n this.#run(git, ['diff', '--cached', '--no-ext-diff', '--no-color', '--unified=3', '--', ':(exclude)WARP.md', ':(exclude)**/WARP.md'], root, GIT_TIMEOUT_MS, MAX_OUTPUT_BYTES),\n this.#run(git, ['diff', '--no-ext-diff', '--no-color', '--unified=3', '--', ':(exclude)WARP.md', ':(exclude)**/WARP.md'], root, GIT_TIMEOUT_MS, MAX_OUTPUT_BYTES),\n ])\n if (branchResult.exitCode !== 0) throw new RepositoryActionError('detached-head', 'A detached HEAD cannot be committed from this panel.')\n if (headResult.exitCode !== 0 || statusResult.exitCode !== 0 || statusResult.lossy) throw new RepositoryActionError('repository-unavailable', 'Repository state is unavailable.')\n const files = parseRepositoryActionStatus(statusResult.stdout)\n const patch = `${stagedPatch.stdout}${stagedPatch.stdout.length > 0 && unstagedPatch.stdout.length > 0 ? '\\n' : ''}${unstagedPatch.stdout}`.slice(0, MAX_PATCH_CHARS)\n const branch = branchResult.stdout.trim()\n const head = headResult.stdout.trim()\n const fingerprint = createHash('sha256').update([head, branch, statusResult.stdout, stagedPatch.stdout, unstagedPatch.stdout].join('\\0')).digest('hex')\n const upstreamResult = await this.#run(git, ['rev-parse', '--abbrev-ref', '--symbolic-full-name', '@{upstream}'], root, GIT_TIMEOUT_MS)\n const upstream = upstreamResult.exitCode === 0 && !upstreamResult.lossy ? upstreamResult.stdout.trim() : undefined\n const logResult = await this.#run(git, [\n 'log', '--format=%H%x09%s', `-n`, String(MAX_UNPUSHED_COMMITS + 1), upstream === undefined ? 'HEAD' : '@{upstream}..HEAD', '--',\n ], root, GIT_TIMEOUT_MS)\n const commitLines = logResult.exitCode === 0 && !logResult.lossy\n ? logResult.stdout.split(/\\r?\\n/u).filter(line => line.includes('\\t'))\n : []\n const unpushedCommits = commitLines.slice(0, MAX_UNPUSHED_COMMITS).flatMap(line => {\n const tab = line.indexOf('\\t')\n const hash = line.slice(0, tab)\n return /^[0-9a-f]{40}$/iu.test(hash) ? [{ hash, subject: line.slice(tab + 1).slice(0, 140) }] : []\n })\n return {\n root,\n branch,\n head,\n fingerprint,\n files,\n patch,\n truncated: stagedPatch.lossy || unstagedPatch.lossy || stagedPatch.stdout.length + unstagedPatch.stdout.length > MAX_PATCH_CHARS,\n hasStaged: files.some(file => file.staged),\n hasUnstaged: files.some(file => file.unstaged),\n hasUntracked: files.some(file => file.untracked),\n ...(upstream === undefined ? {} : { upstream }),\n unpushedCommits,\n unpushedTruncated: commitLines.length > MAX_UNPUSHED_COMMITS,\n }\n }\n\n async #rejectStagedWarp(git: string, cwd: string): Promise<void> {\n const staged = await this.#run(git, ['diff', '--cached', '--name-only', '--'], cwd, GIT_TIMEOUT_MS)\n if (staged.exitCode !== 0 || staged.lossy) throw new RepositoryActionError('repository-unavailable', 'Staged files could not be verified.')\n if (staged.stdout.split(/\\r?\\n/u).some(path => path.length > 0 && isProtectedWarpPath(path))) {\n throw new RepositoryActionError('protected-warp-file', 'WARP.md files cannot be committed. Unstage them before continuing.')\n }\n }\n\n async #push(git: string, cwd: string, branch: string, forceWithLease = false): Promise<void> {\n const upstream = await this.#run(git, ['rev-parse', '--abbrev-ref', '--symbolic-full-name', '@{upstream}'], cwd, GIT_TIMEOUT_MS)\n const args = upstream.exitCode === 0 ? ['push', ...(forceWithLease ? ['--force-with-lease'] : [])] : ['push', '--set-upstream', 'origin', branch]\n await this.#mustRun(git, args, cwd, REMOTE_TIMEOUT_MS, 'push-failed', 'Git push failed.')\n }\n\n #git(): Promise<string> {\n this.#gitExecutable ??= this.#runtime.resolveExecutable('git')\n return this.#gitExecutable\n }\n\n #gh(): Promise<string> {\n this.#ghExecutable ??= this.#runtime.resolveExecutable('gh').catch(() => { throw new RepositoryActionError('gh-unavailable', 'GitHub CLI is unavailable.') })\n return this.#ghExecutable\n }\n\n async #mustRun(executable: string, args: readonly string[], cwd: string, timeoutMs: number, code: string, message: string): Promise<CommandResult> {\n const result = await this.#run(executable, args, cwd, timeoutMs)\n if (result.exitCode !== 0 || result.lossy) throw new RepositoryActionError(code, message)\n return result\n }\n\n #run(executable: string, args: readonly string[], cwd: string, timeoutMs: number, maxBytes = MAX_OUTPUT_BYTES): Promise<CommandResult> {\n return collect(this.#runtime.spawn({\n argv: [executable, ...args],\n cwd,\n stdio: { stdin: 'ignore', stdout: { maxBytes }, stderr: { maxBytes: MAX_OUTPUT_BYTES } },\n graceMs: 1_000,\n signal: AbortSignal.timeout(timeoutMs),\n env: {},\n }))\n }\n}\n","import type { ServerResponse } from 'node:http'\nimport type { Context } from '@deepseek-ai/cordis'\nimport type {} from '@deepseek-ai/dsh-host-webserver'\nimport { CLAUDE_REPOSITORY_SETUP_PATH } from './constants.ts'\nimport { json, registerPluginRoute, type PluginRouteIo } from './http.ts'\nimport {\n RepositorySetupError,\n type RepositorySetupResult,\n type RepositorySetupService,\n type RepositorySetupStage,\n} from './repository-setup.ts'\n\nconst MAX_BODY_BYTES = 16 * 1024\n\nfunction record(value: unknown): Record<string, unknown> | undefined {\n return value !== null && typeof value === 'object' && !Array.isArray(value)\n ? value as Record<string, unknown>\n : undefined\n}\n\nasync function readJson(io: PluginRouteIo): Promise<Record<string, unknown>> {\n let parsed: unknown\n try {\n parsed = await io.body<unknown>(MAX_BODY_BYTES)\n } catch (error) {\n if (error instanceof SyntaxError) throw error\n throw new RepositorySetupError('body-too-large', 'The request body is too large.')\n }\n const value = record(parsed)\n if (value === undefined) throw new RepositorySetupError('invalid-request', 'The request body is invalid.')\n return value\n}\n\nfunction string(input: Record<string, unknown>, key: string): string {\n const value = input[key]\n if (typeof value !== 'string') throw new RepositorySetupError('invalid-request', `The ${key} field is required.`)\n return value\n}\n\nfunction optionalString(input: Record<string, unknown>, key: string): string | undefined {\n const value = input[key]\n if (value === undefined) return undefined\n if (typeof value !== 'string') throw new RepositorySetupError('invalid-request', `The ${key} field must be a string.`)\n return value\n}\n\nfunction ndjsonHeaders(res: ServerResponse): void {\n res.writeHead(200, {\n 'content-type': 'application/x-ndjson; charset=utf-8',\n 'cache-control': 'no-store',\n 'x-content-type-options': 'nosniff',\n })\n res.flushHeaders?.()\n}\n\nfunction ndjson(res: ServerResponse, value: unknown): void {\n res.write(`${JSON.stringify(value)}\\n`)\n}\n\n// `RepositorySetupService.setup` takes no signal, so the route's disconnect\n// abort cannot reach the Git work it drives; the stream registration is still\n// what bounds how many of these may be live at once.\nasync function streamSetup(\n res: ServerResponse,\n service: RepositorySetupService,\n input: Record<string, unknown>,\n): Promise<void> {\n ndjsonHeaders(res)\n let ended = false\n try {\n const result: RepositorySetupResult = await service.setup(\n string(input, 'cwd'),\n string(input, 'branch'),\n input.worktree as boolean,\n optionalString(input, 'branchName'),\n (stage: RepositorySetupStage) => { if (!ended) ndjson(res, { type: 'progress', stage }) },\n optionalString(input, 'intent'),\n )\n ndjson(res, { type: 'complete', result })\n } catch (error) {\n const setupError = error instanceof RepositorySetupError ? error : undefined\n ndjson(res, {\n type: 'error',\n code: setupError?.code ?? 'repository-setup-unavailable',\n message: setupError?.message ?? 'Repository setup is unavailable.',\n })\n } finally {\n ended = true\n res.end()\n }\n}\n\n/** Register trusted browser routes for safe pre-session Git setup.\n *\n * The prefix is registered as a stream because the setup POST holds its\n * connection open for the whole worktree build; the short sibling paths ride\n * the same registration and answer with `json` before releasing it. */\nexport function registerRepositorySetupRoute(\n ctx: Context,\n service: RepositorySetupService,\n /** Kick the worktree/workspace reconciliation, when the Host exposes one. */\n sweep?: () => void,\n): void {\n registerPluginRoute(ctx, {\n mode: 'stream',\n kind: 'prefix',\n path: CLAUDE_REPOSITORY_SETUP_PATH,\n methods: ['GET', 'POST'],\n maxConcurrent: 2,\n // Only the branch paths name their checkout in the URL; the setup POST\n // carries it in the body, so it keys on its path alone and a reopen\n // supersedes the response it is replacing.\n streamKey: url => `${url.pathname}?${url.searchParams.get('cwd') ?? url.searchParams.get('branch') ?? ''}`,\n handler: async (res, io) => {\n const pathname = io.url.pathname\n try {\n // Not a GET: --prune rewrites this checkout's remote-tracking refs.\n if (pathname === `${CLAUDE_REPOSITORY_SETUP_PATH}/branches/refresh`) {\n if (io.method !== 'POST') return json(res, 405, { error: 'method not allowed' })\n const input = await readJson(io)\n return json(res, 200, await service.refreshBranches(string(input, 'cwd')))\n }\n if (pathname === `${CLAUDE_REPOSITORY_SETUP_PATH}/branches`) {\n if (io.method !== 'GET') return json(res, 405, { error: 'method not allowed' })\n const cwd = io.url.searchParams.get('cwd')\n if (cwd === null) throw new RepositorySetupError('invalid-request', 'The cwd query parameter is required.')\n return json(res, 200, await service.listBranches(cwd))\n }\n if (pathname === CLAUDE_REPOSITORY_SETUP_PATH) {\n if (io.method !== 'POST') return json(res, 405, { error: 'method not allowed' })\n const input = await readJson(io)\n if (typeof input.worktree !== 'boolean') throw new RepositorySetupError('invalid-request', 'The worktree field is required.')\n await streamSetup(res, service, input)\n return\n }\n if (pathname === `${CLAUDE_REPOSITORY_SETUP_PATH}/cleanup`) {\n if (io.method !== 'POST') return json(res, 405, { error: 'method not allowed' })\n const input = await readJson(io)\n return json(res, 200, await service.cleanupMerged(string(input, 'path'), string(input, 'baseBranch')))\n }\n // The Host's own workspace deletion publishes no server-side event, so\n // the Client kicks the sweep the moment a workspace leaves its list.\n // Carries no payload: the sweep re-reads the registry itself.\n if (pathname === `${CLAUDE_REPOSITORY_SETUP_PATH}/sweep`) {\n if (io.method !== 'POST') return json(res, 405, { error: 'method not allowed' })\n sweep?.()\n return json(res, 200, { ok: true })\n }\n if (pathname === `${CLAUDE_REPOSITORY_SETUP_PATH}/bind`) {\n if (io.method !== 'POST') return json(res, 405, { error: 'method not allowed' })\n const input = await readJson(io)\n await service.bindLease(string(input, 'leaseId'), string(input, 'sessionId'))\n return json(res, 200, { ok: true })\n }\n return json(res, 404, { error: 'not found' })\n } catch (error) {\n if (error instanceof RepositorySetupError) return json(res, 409, { error: error.code, message: error.message })\n if (error instanceof SyntaxError) return json(res, 400, { error: 'invalid json' })\n return json(res, 500, { error: 'repository setup unavailable' })\n }\n },\n })\n}\n","import type { Context } from '@deepseek-ai/cordis'\nimport type {} from '@deepseek-ai/dsh-host-webserver'\nimport { CLAUDE_REPOSITORY_ACTION_PATH } from './constants.ts'\nimport { registerPluginRoute, type PluginRouteIo } from './http.ts'\nimport {\n RepositoryActionError,\n type RepositoryActionKind,\n type RepositoryActionRequest,\n type RepositoryMergeMethod,\n type RepositoryActionService,\n} from './repository-actions.ts'\n\nconst MAX_BODY_BYTES = 16 * 1024\nconst MAX_SESSION_ID_CHARS = 1_024\nconst ACTIONS = new Set<RepositoryActionKind>(['commit', 'commit-push', 'push', 'create-pr', 'merge-pr', 'update-branch'])\n\nfunction record(value: unknown): Record<string, unknown> | undefined {\n return value !== null && typeof value === 'object' && !Array.isArray(value) ? value as Record<string, unknown> : undefined\n}\n\nasync function readJson(io: PluginRouteIo): Promise<Record<string, unknown>> {\n let parsed: unknown\n try {\n parsed = await io.body<unknown>(MAX_BODY_BYTES)\n } catch (error) {\n // Malformed JSON keeps its own 400; the cap is the only other refusal the\n // transport raises, and the panel already knows that code.\n if (error instanceof SyntaxError) throw error\n throw new RepositoryActionError('body-too-large', 'The request body is too large.')\n }\n const value = record(parsed)\n if (value === undefined) throw new RepositoryActionError('invalid-request', 'The request body is invalid.')\n return value\n}\n\nfunction sessionId(url: URL): string {\n const value = url.searchParams.get('sessionId')\n if (value === null || value.length === 0 || value.length > MAX_SESSION_ID_CHARS) {\n throw new RepositoryActionError('invalid-session', 'The session is invalid.')\n }\n return value\n}\n\nfunction string(input: Record<string, unknown>, key: string): string {\n const value = input[key]\n if (typeof value !== 'string') throw new RepositoryActionError('invalid-request', `The ${key} field is required.`)\n return value\n}\n\nfunction optionalString(input: Record<string, unknown>, key: string): string | undefined {\n const value = input[key]\n if (value === undefined) return undefined\n if (typeof value !== 'string') throw new RepositoryActionError('invalid-request', `The ${key} field must be a string.`)\n return value\n}\n\nfunction actionRequest(input: Record<string, unknown>): RepositoryActionRequest {\n const action = input.action\n if (typeof action !== 'string' || !ACTIONS.has(action as RepositoryActionKind)\n || typeof input.includeUnstaged !== 'boolean') {\n throw new RepositoryActionError('invalid-request', 'The repository action is invalid.')\n }\n return {\n action: action as RepositoryActionKind,\n fingerprint: string(input, 'fingerprint'),\n message: action === 'push' || action === 'merge-pr' || action === 'update-branch' ? optionalString(input, 'message') ?? '' : string(input, 'message'),\n includeUnstaged: input.includeUnstaged,\n ...(optionalString(input, 'prTitle') === undefined ? {} : { prTitle: optionalString(input, 'prTitle')! }),\n ...(optionalString(input, 'prBody') === undefined ? {} : { prBody: optionalString(input, 'prBody')! }),\n ...(optionalString(input, 'baseBranch') === undefined ? {} : { baseBranch: optionalString(input, 'baseBranch')! }),\n ...(input.draft === undefined ? {} : typeof input.draft === 'boolean' ? { draft: input.draft } : (() => { throw new RepositoryActionError('invalid-request', 'The draft field must be a boolean.') })()),\n ...(input.mergeMethod === undefined\n ? {}\n : input.mergeMethod === 'merge' || input.mergeMethod === 'squash' || input.mergeMethod === 'rebase'\n ? { mergeMethod: input.mergeMethod as RepositoryMergeMethod }\n : (() => { throw new RepositoryActionError('invalid-request', 'The mergeMethod field is invalid.') })()),\n }\n}\n\n/** One prefix serves the local-Git preview and the POST arms that push, open\n * and merge pull requests, so the registration takes the wider of the two\n * budgets: a `remote` arm cut short at the `git` deadline would abandon work\n * that had already reached GitHub. */\nexport function registerRepositoryActionRoute(\n ctx: Context,\n service: RepositoryActionService,\n cwdForSession: (sessionId: string) => string | undefined,\n): void {\n registerPluginRoute(ctx, {\n mode: 'unary',\n kind: 'prefix',\n path: CLAUDE_REPOSITORY_ACTION_PATH,\n methods: ['GET', 'POST'],\n budget: 'remote',\n handler: async io => {\n const url = io.url\n try {\n const id = sessionId(url)\n const cwd = cwdForSession(id)\n if (cwd === undefined) throw new RepositoryActionError('session-unavailable', 'The Claude session is unavailable.')\n if (url.pathname === `${CLAUDE_REPOSITORY_ACTION_PATH}/preview`) {\n if (io.method !== 'GET') return { status: 405, value: { error: 'method not allowed' } }\n return { status: 200, value: await service.preview(cwd) }\n }\n if (url.pathname === `${CLAUDE_REPOSITORY_ACTION_PATH}/message`) {\n if (io.method !== 'POST') return { status: 405, value: { error: 'method not allowed' } }\n const input = await readJson(io)\n return { status: 200, value: { message: await service.generateMessage(cwd, string(input, 'fingerprint')) } }\n }\n if (url.pathname === CLAUDE_REPOSITORY_ACTION_PATH) {\n if (io.method !== 'POST') return { status: 405, value: { error: 'method not allowed' } }\n return { status: 200, value: await service.execute(cwd, actionRequest(await readJson(io))) }\n }\n return { status: 404, value: { error: 'not found' } }\n } catch (error) {\n if (error instanceof RepositoryActionError) {\n return {\n status: 409,\n value: {\n error: error.code,\n message: error.message,\n ...(error.commit === undefined ? {} : { commit: error.commit }),\n },\n }\n }\n if (error instanceof SyntaxError) return { status: 400, value: { error: 'invalid-json' } }\n return { status: 500, value: { error: 'repository-action-unavailable', message: 'Repository action is unavailable.' } }\n }\n },\n })\n}\n","import type { SubprocessHandle, SubprocessRuntime } from '@deepseek-ai/dsh-subprocess'\n\nconst MAX_OUTPUT_BYTES = 8 * 1024\n/** Long enough for a launcher shim to fail loudly, short enough that the\n * request returns while the IDE is still booting. On Windows and Linux the\n * IDE binary IS the launched process, so still running past this is success. */\nconst SETTLE_MS = 1_500\n\nexport type EditorId = 'cursor' | 'idea'\nexport const EDITOR_IDS: ReadonlySet<string> = new Set<EditorId>(['cursor', 'idea'])\n\n/** Launch commands tried in order, first success wins. macOS keeps `open -a`\n * behind the CLI shim because both shims are opt-in installs there, while\n * `open -a` finds the bundle wherever Toolbox or the DMG dropped it. */\nconst LAUNCHERS: Record<EditorId, Partial<Record<NodeJS.Platform, readonly (readonly string[])[]>>> = {\n cursor: {\n darwin: [['cursor'], ['open', '-a', 'Cursor']],\n win32: [['cursor']],\n linux: [['cursor']],\n },\n idea: {\n darwin: [['idea'], ['open', '-a', 'IntelliJ IDEA'], ['open', '-a', 'IntelliJ IDEA CE']],\n win32: [['idea'], ['idea64.exe']],\n linux: [['idea'], ['idea.sh']],\n },\n}\n\n/** cmd.exe re-interprets these, and a mis-parsed path opens the wrong project\n * rather than failing. Refuse instead of guessing. */\nconst WINDOWS_UNSAFE = /[\"&|<>^%]/u\n\nexport class EditorOpenError extends Error {\n readonly code: string\n\n constructor(code: string, message: string) {\n super(message)\n this.name = 'EditorOpenError'\n this.code = code\n }\n}\n\n/** Open a session's working directory in a desktop editor. */\nexport class EditorOpenService {\n readonly #runtime: Pick<SubprocessRuntime, 'resolveExecutable' | 'spawn'>\n readonly #platform: NodeJS.Platform\n readonly #settleMs: number\n\n constructor(\n runtime: Pick<SubprocessRuntime, 'resolveExecutable' | 'spawn'>,\n platform: NodeJS.Platform = process.platform,\n settleMs: number = SETTLE_MS,\n ) {\n this.#runtime = runtime\n this.#platform = platform\n this.#settleMs = settleMs\n }\n\n async open(cwd: string, editor: EditorId): Promise<void> {\n if (this.#platform === 'win32' && WINDOWS_UNSAFE.test(cwd)) {\n throw new EditorOpenError('unsupported-path', 'The project path cannot be opened through the Windows shell.')\n }\n const candidates = LAUNCHERS[editor][this.#platform] ?? LAUNCHERS[editor].linux ?? []\n let found = false\n for (const candidate of candidates) {\n const argv = await this.#argv(candidate, cwd)\n if (argv === undefined) continue\n found = true\n if (await this.#launch(argv, cwd)) return\n }\n throw found\n ? new EditorOpenError('launch-failed', 'The editor refused to open the project.')\n : new EditorOpenError('editor-unavailable', 'The editor was not found on PATH.')\n }\n\n async #argv(candidate: readonly string[], cwd: string): Promise<readonly string[] | undefined> {\n const [program, ...rest] = candidate\n if (program === undefined) return undefined\n // Windows launcher shims are `.cmd` files, which Node refuses to spawn\n // directly; cmd.exe runs those and plain `.exe` entries alike, and does\n // its own PATH/PATHEXT lookup — so no resolution step here.\n if (this.#platform === 'win32') return ['cmd.exe', '/d', '/s', '/c', program, ...rest, cwd]\n try {\n return [await this.#runtime.resolveExecutable(program), ...rest, cwd]\n } catch {\n return undefined\n }\n }\n\n /** True once the editor is launched: either the shim exited cleanly or the\n * process is still alive past the settle window. */\n async #launch(argv: readonly string[], cwd: string): Promise<boolean> {\n let handle: SubprocessHandle\n try {\n // No abort signal on purpose — the editor must outlive this request.\n // ponytail: on platforms whose launcher does not fork (idea64.exe) the\n // IDE stays a child of the host; detach if that ever orphans badly.\n handle = this.#runtime.spawn({\n argv,\n cwd,\n stdio: { stdin: 'ignore', stdout: { maxBytes: MAX_OUTPUT_BYTES }, stderr: { maxBytes: MAX_OUTPUT_BYTES } },\n graceMs: 1_000,\n env: {},\n })\n } catch {\n return false\n }\n return await Promise.race([\n handle.done.then(outcome => outcome.exitCode === 0),\n new Promise<boolean>(resolve => {\n const timer = setTimeout(() => resolve(true), this.#settleMs)\n timer.unref?.()\n }),\n ])\n }\n}\n","import type { Context } from '@deepseek-ai/cordis'\nimport type {} from '@deepseek-ai/dsh-host-webserver'\nimport { CLAUDE_EDITOR_OPEN_PATH } from './constants.ts'\nimport { registerPluginRoute } from './http.ts'\nimport { EDITOR_IDS, EditorOpenError, type EditorId, type EditorOpenService } from './editor-open.ts'\n\nconst MAX_SESSION_ID_CHARS = 1_024\n\n/** Open the session's working directory in a desktop editor. Query-only: the\n * request carries two enum-ish values, so there is no body to parse. */\nexport function registerEditorOpenRoute(\n ctx: Context,\n service: Pick<EditorOpenService, 'open'>,\n cwdForSession: (sessionId: string) => string | undefined,\n): void {\n registerPluginRoute(ctx, {\n mode: 'unary',\n kind: 'exact',\n path: CLAUDE_EDITOR_OPEN_PATH,\n methods: ['POST'],\n budget: 'fast',\n handler: async io => {\n const params = io.url.searchParams\n const id = params.get('sessionId')\n const editor = params.get('editor')\n if (id === null || id.length === 0 || id.length > MAX_SESSION_ID_CHARS) {\n return { status: 400, value: { error: 'invalid-session', message: 'The session is invalid.' } }\n }\n if (editor === null || !EDITOR_IDS.has(editor)) {\n return { status: 400, value: { error: 'invalid-editor', message: 'The editor is invalid.' } }\n }\n const cwd = cwdForSession(id)\n if (cwd === undefined) return { status: 409, value: { error: 'session-unavailable', message: 'The Claude session is unavailable.' } }\n try {\n await service.open(cwd, editor as EditorId)\n return { status: 200, value: { opened: true } }\n } catch (error) {\n if (error instanceof EditorOpenError) return { status: 409, value: { error: error.code, message: error.message } }\n return { status: 500, value: { error: 'editor-open-unavailable', message: 'The editor could not be launched.' } }\n }\n },\n })\n}\n","/** Only GitHub's own image hosts; the browser loads these directly, so a URL\n * the API did not vouch for must never become an outbound request. */\nexport function githubAvatarUrl(value: unknown): string | undefined {\n if (typeof value !== 'string' || value.length === 0 || value.length > 1_024) return undefined\n try {\n const url = new URL(value)\n const allowed = url.hostname === 'github.com' || url.hostname === 'githubusercontent.com' || url.hostname.endsWith('.githubusercontent.com')\n return url.protocol === 'https:' && allowed ? url.href : undefined\n } catch {\n return undefined\n }\n}\n","import type { SubprocessHandle, SubprocessRuntime } from '@deepseek-ai/dsh-subprocess'\nimport { githubAvatarUrl } from './github-url.ts'\nimport { parseGitHubRemote } from './repository-status.ts'\n\nexport { githubAvatarUrl } from './github-url.ts'\n\nconst MAX_OUTPUT_BYTES = 512 * 1024\nconst GIT_TIMEOUT_MS = 10_000\nconst GH_TIMEOUT_MS = 60_000\nconst MAX_COMMENTS = 100\nconst MAX_THREADS = 100\nconst MAX_MENTIONABLE_USERS = 20\nconst MAX_REPLY_CHARS = 2_000\nconst MAX_COMMENT_CHARS = 4_096\nconst MAX_FAILING_CHECKS = 3\nconst MAX_LOG_CHARS = 8 * 1024\n\ntype FeedbackRuntime = Pick<SubprocessRuntime, 'resolveExecutable' | 'spawn'>\n\ninterface CommandResult {\n readonly exitCode: number | null\n readonly stdout: string\n readonly lossy: boolean\n}\n\nexport interface PullRequestReviewComment {\n readonly id: number\n readonly path: string\n readonly line?: number\n readonly side: 'new' | 'old'\n readonly author: string\n /** GitHub-hosted avatar of the comment's author, when the API named one. */\n readonly avatarUrl?: string\n readonly body: string\n readonly url: string\n /** ISO timestamp GitHub reports; the panel shows it the way GitHub does. */\n readonly createdAt?: string\n /** App account. GraphQL reports it as an actor type; REST spells the login\n * `name[bot]`. Either way the panel shows a Bot pill, like GitHub. */\n readonly bot?: boolean\n}\n\n/** One GitHub review conversation: the comments share an anchor, and Resolve\n * acts on the thread rather than on any single comment. */\nexport interface PullRequestReviewThread {\n /** GraphQL node id — the only handle the resolve mutations accept. */\n readonly id: string\n readonly path: string\n readonly line?: number\n readonly side: 'new' | 'old'\n readonly resolved: boolean\n readonly outdated: boolean\n readonly comments: readonly PullRequestReviewComment[]\n}\n\n/** A user GitHub will notify when the reply names them. */\nexport interface MentionableUser {\n readonly login: string\n readonly avatarUrl?: string\n}\n\nexport interface FailingCheck {\n readonly name: string\n readonly link?: string\n readonly description?: string\n readonly log?: string\n}\n\nexport class PullRequestFeedbackError extends Error {\n readonly code: string\n\n constructor(code: string, message: string) {\n super(message)\n this.name = 'PullRequestFeedbackError'\n this.code = code\n }\n}\n\n/** Threads carry the anchor; comments carry the prose. `isOutdated` marks a\n * thread whose lines the branch has since moved past. */\nconst REVIEW_THREADS_QUERY = `query($owner:String!,$name:String!,$number:Int!){\n repository(owner:$owner,name:$name){\n pullRequest(number:$number){\n reviewThreads(first:100){\n nodes{\n id isResolved isOutdated path line originalLine diffSide\n comments(first:50){ nodes{ databaseId body url createdAt author{ __typename login avatarUrl } } }\n }\n }\n }\n }\n}`\n\nconst RESOLVE_MUTATION = `mutation($threadId:ID!){\n resolveReviewThread(input:{threadId:$threadId}){ thread{ isResolved } }\n}`\n\nconst UNRESOLVE_MUTATION = `mutation($threadId:ID!){\n unresolveReviewThread(input:{threadId:$threadId}){ thread{ isResolved } }\n}`\n\nconst MENTIONABLE_USERS_QUERY = `query($owner:String!,$name:String!,$q:String!){\n repository(owner:$owner,name:$name){\n mentionableUsers(first:20,query:$q){ nodes{ login avatarUrl } }\n }\n}`\n\nasync function collect(handle: SubprocessHandle): Promise<CommandResult> {\n const outcome = await handle.done\n const stdout = handle.collected.stdout?.readFrom(0)\n return { exitCode: outcome.exitCode, stdout: stdout?.text ?? '', lossy: stdout?.lossy === true }\n}\n\nfunction record(value: unknown): Record<string, unknown> | undefined {\n return value !== null && typeof value === 'object' && !Array.isArray(value) ? value as Record<string, unknown> : undefined\n}\n\n/** Read `repository.pullRequest.reviewThreads.nodes` out of a GraphQL response.\n * A payload carrying `errors` instead of data yields nothing rather than\n * throwing: the caller distinguishes \"no threads\" from \"call failed\" by the\n * process exit code. */\nexport function parseReviewThreads(value: unknown): readonly PullRequestReviewThread[] {\n const nodes = record(record(record(record(record(value)?.data)?.repository)?.pullRequest)?.reviewThreads)?.nodes\n if (!Array.isArray(nodes)) return []\n const threads: PullRequestReviewThread[] = []\n let total = 0\n for (const item of nodes) {\n const input = record(item)\n if (input === undefined || typeof input.id !== 'string' || input.id.length === 0) continue\n const path = typeof input.path === 'string' ? input.path : ''\n if (path.length === 0) continue\n const line = Number.isSafeInteger(input.line)\n ? Number(input.line)\n : Number.isSafeInteger(input.originalLine) ? Number(input.originalLine) : undefined\n const side = input.diffSide === 'LEFT' ? 'old' as const : 'new' as const\n const anchor = { path, ...(line === undefined ? {} : { line }), side }\n const comments: PullRequestReviewComment[] = []\n const commentNodes = record(input.comments)?.nodes\n for (const node of Array.isArray(commentNodes) ? commentNodes : []) {\n if (total >= MAX_COMMENTS) break\n const comment = record(node)\n if (comment === undefined || !Number.isSafeInteger(comment.databaseId)) continue\n const body = typeof comment.body === 'string' ? comment.body.trim() : ''\n if (body.length === 0) continue\n const author = record(comment.author)\n const avatarUrl = githubAvatarUrl(author?.avatarUrl)\n const login = typeof author?.login === 'string' ? author.login : 'unknown'\n comments.push({\n id: Number(comment.databaseId),\n ...anchor,\n author: login,\n ...(author?.__typename === 'Bot' || login.endsWith('[bot]') ? { bot: true } : {}),\n ...(avatarUrl === undefined ? {} : { avatarUrl }),\n body: body.slice(0, MAX_COMMENT_CHARS),\n url: typeof comment.url === 'string' ? comment.url : '',\n ...(typeof comment.createdAt === 'string' ? { createdAt: comment.createdAt } : {}),\n })\n total += 1\n }\n // A thread with nothing readable left is not worth an anchor in the diff.\n if (comments.length === 0) continue\n threads.push({\n id: input.id,\n ...anchor,\n resolved: input.isResolved === true,\n outdated: input.isOutdated === true,\n comments,\n })\n if (threads.length >= MAX_THREADS || total >= MAX_COMMENTS) break\n }\n return threads\n}\n\n/** One posted reply, shaped like the thread comments it joins. */\nexport function parseReplyComment(value: unknown, anchor: { path: string; line?: number; side: 'new' | 'old' }): PullRequestReviewComment | undefined {\n const input = record(value)\n if (input === undefined || !Number.isSafeInteger(input.id)) return undefined\n const body = typeof input.body === 'string' ? input.body.trim() : ''\n if (body.length === 0) return undefined\n const user = record(input.user)\n const avatarUrl = githubAvatarUrl(user?.avatar_url)\n const login = typeof user?.login === 'string' ? user.login : 'unknown'\n return {\n id: Number(input.id),\n ...anchor,\n author: login,\n ...(user?.type === 'Bot' || login.endsWith('[bot]') ? { bot: true } : {}),\n ...(avatarUrl === undefined ? {} : { avatarUrl }),\n body: body.slice(0, MAX_COMMENT_CHARS),\n url: typeof input.html_url === 'string' ? input.html_url : '',\n ...(typeof input.created_at === 'string' ? { createdAt: input.created_at } : {}),\n }\n}\n\nexport function parseMentionableUsers(value: unknown): readonly MentionableUser[] {\n const nodes = record(record(record(record(value)?.data)?.repository)?.mentionableUsers)?.nodes\n if (!Array.isArray(nodes)) return []\n const users: MentionableUser[] = []\n for (const item of nodes) {\n const input = record(item)\n if (input === undefined || typeof input.login !== 'string' || input.login.length === 0) continue\n const avatarUrl = githubAvatarUrl(input.avatarUrl)\n users.push({ login: input.login, ...(avatarUrl === undefined ? {} : { avatarUrl }) })\n if (users.length >= MAX_MENTIONABLE_USERS) break\n }\n return users\n}\n\n/** Extract the Actions job id from a check run link, when it is one. */\nexport function actionsJobId(link: string | undefined): string | undefined {\n if (link === undefined) return undefined\n return /\\/actions\\/runs\\/\\d+\\/jobs?\\/(\\d+)/u.exec(link)?.[1]\n}\n\nexport function parseFailingChecks(value: unknown): readonly FailingCheck[] {\n if (!Array.isArray(value)) return []\n const failing: FailingCheck[] = []\n for (const item of value) {\n const input = record(item)\n if (input === undefined || input.bucket !== 'fail' || typeof input.name !== 'string') continue\n failing.push({\n name: input.name,\n ...(typeof input.link === 'string' && input.link.length > 0 ? { link: input.link } : {}),\n ...(typeof input.description === 'string' && input.description.length > 0 ? { description: input.description } : {}),\n })\n }\n return failing\n}\n\n/** Keep the informative end of a failed-job log within the size budget. */\nexport function boundedLogTail(value: string): string {\n const text = value.replaceAll('\\0', '').trimEnd()\n return text.length <= MAX_LOG_CHARS ? text : text.slice(text.length - MAX_LOG_CHARS)\n}\n\nexport class PullRequestFeedbackService {\n readonly #runtime: FeedbackRuntime\n #gitExecutable?: Promise<string>\n #ghExecutable?: Promise<string>\n\n constructor(runtime: FeedbackRuntime) {\n this.#runtime = runtime\n }\n\n async threads(cwd: string, pullNumber: number): Promise<readonly PullRequestReviewThread[]> {\n const { owner, name } = await this.#repositoryParts(cwd)\n const gh = await this.#gh()\n const result = await this.#run(gh, [\n 'api', 'graphql',\n '-f', `owner=${owner}`, '-f', `name=${name}`, '-F', `number=${pullNumber}`,\n '-f', `query=${REVIEW_THREADS_QUERY}`,\n ], cwd, GH_TIMEOUT_MS)\n if (result.exitCode !== 0) throw new PullRequestFeedbackError('comments-unavailable', 'Pull request comments could not be loaded.')\n try {\n return parseReviewThreads(JSON.parse(result.stdout))\n } catch {\n throw new PullRequestFeedbackError('comments-unavailable', 'Pull request comments could not be parsed.')\n }\n }\n\n /** Post a reply into the thread the given comment belongs to. GitHub parses\n * `@login` in the body server-side, so mentions need nothing from us. */\n async reply(cwd: string, pullNumber: number, commentId: number, body: string): Promise<PullRequestReviewComment> {\n const text = body.trim()\n if (text.length === 0 || text.length > MAX_REPLY_CHARS) {\n throw new PullRequestFeedbackError('invalid-request', 'The reply body is invalid.')\n }\n const repository = await this.#repository(cwd)\n const gh = await this.#gh()\n const result = await this.#run(\n gh,\n ['api', '-X', 'POST', `repos/${repository}/pulls/${pullNumber}/comments/${commentId}/replies`, '--input', '-'],\n cwd,\n GH_TIMEOUT_MS,\n JSON.stringify({ body: text }),\n )\n if (result.exitCode !== 0) throw new PullRequestFeedbackError('reply-failed', 'The reply could not be posted.')\n let posted: PullRequestReviewComment | undefined\n try {\n const parsed = JSON.parse(result.stdout) as unknown\n const path = typeof record(parsed)?.path === 'string' ? String(record(parsed)?.path) : ''\n const line = Number.isSafeInteger(record(parsed)?.line) ? Number(record(parsed)?.line) : undefined\n posted = parseReplyComment(parsed, {\n path,\n ...(line === undefined ? {} : { line }),\n side: record(parsed)?.side === 'LEFT' ? 'old' : 'new',\n })\n } catch {\n posted = undefined\n }\n if (posted === undefined) throw new PullRequestFeedbackError('reply-failed', 'The posted reply could not be read back.')\n return posted\n }\n\n /** Resolve or reopen a thread. Returns the state GitHub reports afterwards. */\n async setResolved(cwd: string, threadId: string, resolved: boolean): Promise<boolean> {\n const gh = await this.#gh()\n const result = await this.#run(gh, [\n 'api', 'graphql',\n '-f', `threadId=${threadId}`,\n '-f', `query=${resolved ? RESOLVE_MUTATION : UNRESOLVE_MUTATION}`,\n ], cwd, GH_TIMEOUT_MS)\n if (result.exitCode !== 0) throw new PullRequestFeedbackError('resolve-failed', 'The thread could not be updated.')\n try {\n const data = record(record(JSON.parse(result.stdout) as unknown)?.data)\n const thread = record(record(data?.[resolved ? 'resolveReviewThread' : 'unresolveReviewThread'])?.thread)\n if (typeof thread?.isResolved !== 'boolean') throw new Error('missing state')\n return thread.isResolved\n } catch {\n throw new PullRequestFeedbackError('resolve-failed', 'The thread state could not be read back.')\n }\n }\n\n /** Logins GitHub would notify from this repository, for the reply composer. */\n async mentionables(cwd: string, query: string): Promise<readonly MentionableUser[]> {\n const { owner, name } = await this.#repositoryParts(cwd)\n const gh = await this.#gh()\n const result = await this.#run(gh, [\n 'api', 'graphql',\n '-f', `owner=${owner}`, '-f', `name=${name}`, '-f', `q=${query}`,\n '-f', `query=${MENTIONABLE_USERS_QUERY}`,\n ], cwd, GH_TIMEOUT_MS)\n if (result.exitCode !== 0) return []\n try {\n return parseMentionableUsers(JSON.parse(result.stdout))\n } catch {\n return []\n }\n }\n\n /** `signal` bounds the log fetches below: each is capped on its own, but they\n * run one after another, so the honest worst case is their sum rather than\n * any single ceiling — more than a route is allowed to hold a connection. */\n async failingChecks(cwd: string, pullNumber: number, signal?: AbortSignal): Promise<readonly FailingCheck[]> {\n const gh = await this.#gh()\n const result = await this.#run(gh, [\n 'pr', 'checks', String(pullNumber), '--json', 'name,state,link,description,bucket',\n ], cwd, GH_TIMEOUT_MS)\n // gh pr checks exits non-zero when checks are failing; that IS our case.\n let checks: readonly FailingCheck[]\n try {\n checks = parseFailingChecks(JSON.parse(result.stdout))\n } catch {\n throw new PullRequestFeedbackError('checks-unavailable', 'Pull request checks could not be loaded.')\n }\n const detailed: FailingCheck[] = []\n for (const check of checks) {\n const jobId = detailed.length < MAX_FAILING_CHECKS ? actionsJobId(check.link) : undefined\n if (jobId === undefined) {\n detailed.push(check)\n continue\n }\n if (signal?.aborted === true) {\n detailed.push(check)\n continue\n }\n const log = await this.#run(gh, ['run', 'view', '--job', jobId, '--log-failed'], cwd, GH_TIMEOUT_MS)\n detailed.push(log.exitCode === 0 && log.stdout.trim().length > 0 ? { ...check, log: boundedLogTail(log.stdout) } : check)\n }\n return detailed\n }\n\n async #repository(cwd: string): Promise<string> {\n const git = await this.#git()\n const remote = await this.#run(git, ['remote', 'get-url', 'origin'], cwd, GIT_TIMEOUT_MS)\n const repository = remote.exitCode === 0 ? parseGitHubRemote(remote.stdout) : undefined\n if (repository === undefined) throw new PullRequestFeedbackError('no-github-remote', 'The repository has no GitHub origin remote.')\n return repository\n }\n\n /** GraphQL takes the owner and the name as separate variables, so they never\n * reach the query text itself. */\n async #repositoryParts(cwd: string): Promise<{ owner: string; name: string }> {\n const [owner, name] = (await this.#repository(cwd)).split('/')\n if (owner === undefined || name === undefined || owner.length === 0 || name.length === 0) {\n throw new PullRequestFeedbackError('no-github-remote', 'The repository has no GitHub origin remote.')\n }\n return { owner, name }\n }\n\n #git(): Promise<string> {\n this.#gitExecutable ??= this.#runtime.resolveExecutable('git')\n return this.#gitExecutable\n }\n\n #gh(): Promise<string> {\n this.#ghExecutable ??= this.#runtime.resolveExecutable('gh').catch(() => {\n throw new PullRequestFeedbackError('gh-unavailable', 'GitHub CLI is unavailable.')\n })\n return this.#ghExecutable\n }\n\n #run(executable: string, args: readonly string[], cwd: string, timeoutMs: number, input?: string): Promise<CommandResult> {\n const handle = this.#runtime.spawn({\n argv: [executable, ...args],\n cwd,\n stdio: {\n stdin: input === undefined ? 'ignore' : 'pipe',\n stdout: { maxBytes: MAX_OUTPUT_BYTES },\n stderr: { maxBytes: 64 * 1024 },\n },\n graceMs: 1_000,\n signal: AbortSignal.timeout(timeoutMs),\n env: {},\n })\n if (input !== undefined) handle.stdin?.end(input)\n return collect(handle)\n }\n}\n","import type { Context } from '@deepseek-ai/cordis'\nimport type {} from '@deepseek-ai/dsh-host-webserver'\nimport { CLAUDE_REPOSITORY_FEEDBACK_PATH } from './constants.ts'\nimport { registerPluginRoute, type PluginRouteIo } from './http.ts'\nimport { PullRequestFeedbackError, type PullRequestFeedbackService } from './pr-feedback.ts'\n\nconst MAX_SESSION_ID_CHARS = 1_024\nconst MAX_BODY_BYTES = 16 * 1024\nconst MAX_REPLY_CHARS = 2_000\nconst MAX_THREAD_ID_CHARS = 512\nconst MAX_MENTION_QUERY_CHARS = 64\n\nfunction record(value: unknown): Record<string, unknown> | undefined {\n return value !== null && typeof value === 'object' && !Array.isArray(value) ? value as Record<string, unknown> : undefined\n}\n\nasync function readJson(io: PluginRouteIo): Promise<Record<string, unknown>> {\n let parsed: unknown\n try {\n parsed = await io.body<unknown>(MAX_BODY_BYTES)\n } catch (error) {\n // Malformed JSON keeps its own 400; the cap is the only other refusal the\n // transport raises, and the panel already knows that code.\n if (error instanceof SyntaxError) throw error\n throw new PullRequestFeedbackError('body-too-large', 'The request body is too large.')\n }\n const value = record(parsed)\n if (value === undefined) throw new PullRequestFeedbackError('invalid-request', 'The request body is invalid.')\n return value\n}\n\nfunction replyBody(input: Record<string, unknown>): string {\n const body = typeof input.body === 'string' ? input.body.trim() : ''\n if (body.length === 0 || body.length > MAX_REPLY_CHARS || body.includes('\\0')) {\n throw new PullRequestFeedbackError('invalid-request', 'The reply body is invalid.')\n }\n return body\n}\n\nfunction commentId(input: Record<string, unknown>): number {\n const value = input.commentId\n if (typeof value !== 'number' || !Number.isSafeInteger(value) || value <= 0) {\n throw new PullRequestFeedbackError('invalid-request', 'The comment id is invalid.')\n }\n return value\n}\n\nfunction threadId(input: Record<string, unknown>): string {\n const value = input.threadId\n if (typeof value !== 'string' || value.length === 0 || value.length > MAX_THREAD_ID_CHARS) {\n throw new PullRequestFeedbackError('invalid-request', 'The thread id is invalid.')\n }\n return value\n}\n\nfunction sessionId(url: URL): string {\n const value = url.searchParams.get('sessionId')\n if (value === null || value.length === 0 || value.length > MAX_SESSION_ID_CHARS) {\n throw new PullRequestFeedbackError('invalid-session', 'The session is invalid.')\n }\n return value\n}\n\nfunction pullNumber(url: URL): number {\n const value = Number(url.searchParams.get('number'))\n if (!Number.isSafeInteger(value) || value <= 0 || value > 1_000_000_000) {\n throw new PullRequestFeedbackError('invalid-request', 'The pull request number is invalid.')\n }\n return value\n}\n\n/** Every arm shells out to `gh`, so the whole prefix carries the network budget. */\nexport function registerPullRequestFeedbackRoute(\n ctx: Context,\n service: PullRequestFeedbackService,\n cwdForSession: (sessionId: string) => string | undefined,\n): void {\n registerPluginRoute(ctx, {\n mode: 'unary',\n kind: 'prefix',\n path: CLAUDE_REPOSITORY_FEEDBACK_PATH,\n methods: ['GET', 'POST'],\n budget: 'remote',\n handler: async io => {\n const url = io.url\n const reads = io.method === 'GET'\n const writes = io.method === 'POST'\n try {\n const cwd = cwdForSession(sessionId(url))\n if (cwd === undefined) throw new PullRequestFeedbackError('session-unavailable', 'The Claude session is unavailable.')\n if (url.pathname === `${CLAUDE_REPOSITORY_FEEDBACK_PATH}/comments`) {\n if (!reads) return { status: 405, value: { error: 'method not allowed' } }\n return { status: 200, value: { threads: await service.threads(cwd, pullNumber(url)) } }\n }\n if (url.pathname === `${CLAUDE_REPOSITORY_FEEDBACK_PATH}/checks`) {\n if (!reads) return { status: 405, value: { error: 'method not allowed' } }\n return { status: 200, value: { checks: await service.failingChecks(cwd, pullNumber(url), io.signal) } }\n }\n if (url.pathname === `${CLAUDE_REPOSITORY_FEEDBACK_PATH}/mentionables`) {\n if (!reads) return { status: 405, value: { error: 'method not allowed' } }\n const query = (url.searchParams.get('q') ?? '').slice(0, MAX_MENTION_QUERY_CHARS)\n return { status: 200, value: { users: await service.mentionables(cwd, query) } }\n }\n if (url.pathname === `${CLAUDE_REPOSITORY_FEEDBACK_PATH}/reply`) {\n if (!writes) return { status: 405, value: { error: 'method not allowed' } }\n const input = await readJson(io)\n const comment = await service.reply(cwd, pullNumber(url), commentId(input), replyBody(input))\n return { status: 200, value: { comment } }\n }\n if (url.pathname === `${CLAUDE_REPOSITORY_FEEDBACK_PATH}/resolve`) {\n if (!writes) return { status: 405, value: { error: 'method not allowed' } }\n const input = await readJson(io)\n if (typeof input.resolved !== 'boolean') {\n throw new PullRequestFeedbackError('invalid-request', 'The resolved field is required.')\n }\n return { status: 200, value: { resolved: await service.setResolved(cwd, threadId(input), input.resolved) } }\n }\n return { status: 404, value: { error: 'not found' } }\n } catch (error) {\n if (error instanceof PullRequestFeedbackError) {\n return { status: 409, value: { error: error.code, message: error.message } }\n }\n if (error instanceof SyntaxError) return { status: 400, value: { error: 'invalid-json' } }\n return { status: 500, value: { error: 'pr-feedback-unavailable', message: 'Pull request feedback is unavailable.' } }\n }\n },\n })\n}\n","import { isAbsolute } from 'node:path'\nimport type { Context } from '@deepseek-ai/cordis'\nimport type {} from '@deepseek-ai/dsh-host-webserver'\nimport { CLAUDE_REPOSITORY_STATUS_PATH } from './constants.ts'\nimport { registerPluginRoute } from './http.ts'\nimport type { RepositoryStatusService } from './repository-status.ts'\n\nconst MAX_PATH_CHARS = 4_096\n\n/** Read-only repository status for an arbitrary directory (the overview panel\n * aggregates every Claude session's checkout through this).\n *\n * The route signal is threaded into the service because this is the one read\n * the overview polls per distinct checkout every 30 seconds: freeing the\n * socket at the budget while the Host kept scanning would just grow a queue\n * of work nobody is waiting for any more. */\nexport function registerRepositoryStatusRoute(ctx: Context, service: RepositoryStatusService): void {\n registerPluginRoute(ctx, {\n mode: 'unary',\n kind: 'exact',\n path: CLAUDE_REPOSITORY_STATUS_PATH,\n methods: ['GET'],\n budget: 'git',\n handler: async io => {\n const cwd = io.url.searchParams.get('cwd')\n if (cwd === null || cwd.length === 0 || cwd.length > MAX_PATH_CHARS || !isAbsolute(cwd) || cwd.includes('\\0')) {\n return { status: 400, value: { error: 'invalid-request', message: 'The cwd query parameter is invalid.' } }\n }\n try {\n return { status: 200, value: await service.inspect(cwd, io.signal) }\n } catch {\n return { status: 500, value: { error: 'repository-status-unavailable', message: 'Repository status is unavailable.' } }\n }\n },\n })\n}\n","import { isAbsolute } from 'node:path'\nimport type { Context } from '@deepseek-ai/cordis'\nimport type {} from '@deepseek-ai/dsh-host-webserver'\nimport { CLAUDE_REPOSITORY_FILE_PATH } from './constants.ts'\nimport { registerPluginRoute } from './http.ts'\nimport { RepositoryFileError, type RepositoryStatusService } from './repository-status.ts'\n\nconst MAX_PATH_CHARS = 4_096\n\n/** Read-only slice of a working-tree file so the diff panel can expand unmodified lines around hunks. */\nexport function registerRepositoryFileRoute(ctx: Context, service: Pick<RepositoryStatusService, 'fileLines'>): void {\n registerPluginRoute(ctx, {\n mode: 'unary',\n kind: 'exact',\n path: CLAUDE_REPOSITORY_FILE_PATH,\n methods: ['GET'],\n // One bounded read of a file already on disk.\n budget: 'git',\n handler: async io => {\n const params = io.url.searchParams\n const cwd = params.get('cwd')\n const path = params.get('path')\n const from = Number(params.get('from'))\n const to = Number(params.get('to'))\n if (cwd === null || cwd.length === 0 || cwd.length > MAX_PATH_CHARS || !isAbsolute(cwd) || cwd.includes('\\0')) {\n return { status: 400, value: { error: 'invalid-request', message: 'The cwd query parameter is invalid.' } }\n }\n if (path === null || path.length === 0 || path.length > MAX_PATH_CHARS) {\n return { status: 400, value: { error: 'invalid-request', message: 'The path query parameter is invalid.' } }\n }\n try {\n return { status: 200, value: await service.fileLines(cwd, path, from, to) }\n } catch (error) {\n if (error instanceof RepositoryFileError) {\n return { status: error.code === 'invalid-request' ? 400 : 409, value: { error: error.code, message: error.message } }\n }\n return { status: 500, value: { error: 'repository-file-unavailable', message: 'The file could not be read.' } }\n }\n },\n })\n}\n","import { randomUUID } from 'node:crypto'\nimport { chmod, mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises'\nimport { dirname } from 'node:path'\nimport { dshHomePath } from '@deepseek-ai/dsh-home-paths'\n\nconst REQUEST_TIMEOUT_MS = 15_000\nconst MAX_RESULTS = 20\nconst MAX_QUERY_CHARS = 200\nconst MAX_STORE_BYTES = 64 * 1024\n\nexport interface JiraConnectionInput {\n readonly siteUrl: string\n readonly email: string\n readonly apiToken: string\n}\n\ninterface JiraStore extends JiraConnectionInput {\n readonly displayName?: string\n readonly accountId?: string\n}\n\n/** Connection state exposed to the browser; never carries the token. */\nexport interface JiraStatus {\n readonly connected: boolean\n readonly siteUrl?: string\n readonly email?: string\n readonly displayName?: string\n}\n\nexport interface JiraTicket {\n readonly key: string\n readonly summary: string\n readonly url: string\n readonly status?: string\n readonly type?: string\n}\n\nexport interface JiraServiceOptions {\n readonly storePath?: string\n readonly fetch?: typeof fetch\n}\n\nexport class JiraError extends Error {\n readonly code: string\n\n constructor(code: string, message: string) {\n super(message)\n this.name = 'JiraError'\n this.code = code\n }\n}\n\nfunction record(value: unknown): Record<string, unknown> | undefined {\n return value !== null && typeof value === 'object' && !Array.isArray(value) ? value as Record<string, unknown> : undefined\n}\n\n/** Jira Cloud sites are origins; Data Center may carry a context path. */\nexport function normalizeSiteUrl(value: string): string {\n let url: URL\n try {\n url = new URL(value.trim())\n } catch {\n throw new JiraError('invalid-site', 'The Jira site URL is invalid.')\n }\n if (url.protocol !== 'https:') throw new JiraError('invalid-site', 'The Jira site URL must use https.')\n return `${url.origin}${url.pathname.replace(/\\/+$/u, '')}`\n}\n\nexport function ticketKeyOf(query: string): string | undefined {\n const match = /^([A-Za-z][A-Za-z0-9_]*)-(\\d+)$/u.exec(query.trim())\n return match === null ? undefined : `${match[1]!.toUpperCase()}-${match[2]!}`\n}\n\n/** Jira's text index carries summary, description and comments -- never the\n * issue key -- so a bare ticket number (\"5697\") can never reach PSOS-5697\n * through `text ~`. The issue picker is the endpoint behind Jira's own quick\n * search and does match keys; its hits become the key filter the normal\n * search then reads the display fields from. */\nexport function pickerKeys(value: unknown, number: string): readonly string[] {\n const sections = record(value)?.sections\n if (!Array.isArray(sections)) return []\n const keys: string[] = []\n for (const section of sections) {\n const issues = record(section)?.issues\n if (!Array.isArray(issues)) continue\n for (const issue of issues) {\n const raw = record(issue)?.key\n const key = ticketKeyOf(typeof raw === 'string' ? raw : '')\n if (key !== undefined && key.endsWith(`-${number}`) && !keys.includes(key)) keys.push(key)\n }\n }\n return keys\n}\n\n/** Keys arrive validated by `ticketKeyOf`, so they cannot break out of the quotes. */\nexport function keyJql(keys: readonly string[]): string {\n return `key in (${keys.map(key => `\"${key}\"`).join(', ')}) ORDER BY updated DESC`\n}\n\nexport function buildJql(query: string): string {\n const trimmed = query.trim().slice(0, MAX_QUERY_CHARS)\n if (trimmed.length === 0) return 'statusCategory != Done ORDER BY updated DESC'\n const key = ticketKeyOf(trimmed)\n if (key !== undefined) return `key = \"${key}\"`\n const escaped = trimmed.replaceAll('\\\\', '\\\\\\\\').replaceAll('\"', '\\\\\"')\n return `text ~ \"${escaped}*\" ORDER BY updated DESC`\n}\n\nexport function parseTickets(value: unknown, siteUrl: string): readonly JiraTicket[] {\n const issues = record(value)?.issues\n if (!Array.isArray(issues)) return []\n const tickets: JiraTicket[] = []\n for (const item of issues) {\n const issue = record(item)\n const fields = record(issue?.fields)\n if (issue === undefined || typeof issue.key !== 'string' || fields === undefined) continue\n const status = record(fields.status)?.name\n const type = record(fields.issuetype)?.name\n tickets.push({\n key: issue.key,\n summary: typeof fields.summary === 'string' ? fields.summary.slice(0, 256) : '',\n url: `${siteUrl}/browse/${issue.key}`,\n ...(typeof status === 'string' ? { status } : {}),\n ...(typeof type === 'string' ? { type } : {}),\n })\n if (tickets.length >= MAX_RESULTS) break\n }\n return tickets\n}\n\nfunction statusOf(store: JiraStore | undefined): JiraStatus {\n if (store === undefined) return { connected: false }\n return {\n connected: true,\n siteUrl: store.siteUrl,\n email: store.email,\n ...(store.displayName === undefined ? {} : { displayName: store.displayName }),\n }\n}\n\n/** Jira Cloud access through the user's API token (Basic auth). */\nexport class JiraService {\n readonly #storePath: string\n readonly #fetch: typeof fetch\n\n constructor(options: JiraServiceOptions = {}) {\n this.#storePath = options.storePath ?? dshHomePath('plugins', 'dsh-claude', 'jira.json')\n this.#fetch = options.fetch ?? globalThis.fetch\n }\n\n async status(): Promise<JiraStatus> {\n return statusOf(await this.#read())\n }\n\n async connect(input: JiraConnectionInput): Promise<JiraStatus> {\n const siteUrl = normalizeSiteUrl(input.siteUrl)\n const email = input.email.trim()\n const apiToken = input.apiToken.trim()\n if (email.length === 0 || email.length > 320 || apiToken.length === 0 || apiToken.length > 4_096) {\n throw new JiraError('invalid-credentials', 'An account email and API token are required.')\n }\n const connection = { siteUrl, email, apiToken }\n const myself = record(await this.#json(connection, '/rest/api/3/myself'))\n const displayName = typeof myself?.displayName === 'string' ? myself.displayName : undefined\n const accountId = typeof myself?.accountId === 'string' ? myself.accountId : undefined\n const store: JiraStore = {\n ...connection,\n ...(displayName === undefined ? {} : { displayName }),\n ...(accountId === undefined ? {} : { accountId }),\n }\n await this.#write(store)\n return statusOf(store)\n }\n\n /** Assign a ticket to the connected account (used once a ticket's worktree exists). */\n async assignToMe(key: string): Promise<void> {\n const store = await this.#read()\n if (store === undefined) throw new JiraError('not-connected', 'Connect Jira in Settings first.')\n const ticket = ticketKeyOf(key)\n if (ticket === undefined) throw new JiraError('invalid-request', 'The ticket key is invalid.')\n let accountId = store.accountId\n if (accountId === undefined) {\n const myself = record(await this.#json(store, '/rest/api/3/myself'))\n if (typeof myself?.accountId !== 'string') throw new JiraError('jira-failed', 'The Jira account id is unavailable.')\n accountId = myself.accountId\n await this.#write({ ...store, accountId })\n }\n await this.#json(store, `/rest/api/3/issue/${ticket}/assignee`, { method: 'PUT', body: { accountId } })\n }\n\n async disconnect(): Promise<void> {\n await rm(this.#storePath, { force: true })\n }\n\n async search(query: string): Promise<readonly JiraTicket[]> {\n const store = await this.#read()\n if (store === undefined) throw new JiraError('not-connected', 'Connect Jira in Settings first.')\n const params = new URLSearchParams({\n jql: await this.#searchJql(store, query.trim().slice(0, MAX_QUERY_CHARS)),\n maxResults: String(MAX_RESULTS),\n fields: 'summary,status,issuetype',\n })\n let body: unknown\n try {\n body = await this.#json(store, `/rest/api/3/search/jql?${params.toString()}`)\n } catch (error) {\n // Older deployments only serve the classic search endpoint.\n if (!(error instanceof JiraError && error.code === 'not-found')) throw error\n body = await this.#json(store, `/rest/api/3/search?${params.toString()}`)\n }\n return parseTickets(body, store.siteUrl)\n }\n\n /** A bare ticket number resolves through the picker; everything else is JQL.\n * A site that cannot serve the picker falls back to the text search rather\n * than failing the whole lookup. */\n async #searchJql(store: JiraStore, query: string): Promise<string> {\n if (!/^\\d+$/u.test(query)) return buildJql(query)\n const keys = await this.#json(store, `/rest/api/3/issue/picker?query=${encodeURIComponent(query)}`)\n .then(body => pickerKeys(body, query), () => [])\n return keys.length === 0 ? buildJql(query) : keyJql(keys)\n }\n\n async #json(connection: JiraConnectionInput, path: string, init: { method?: 'GET' | 'PUT'; body?: unknown } = {}): Promise<unknown> {\n let response: Response\n try {\n response = await this.#fetch(`${connection.siteUrl}${path}`, {\n method: init.method ?? 'GET',\n headers: {\n accept: 'application/json',\n authorization: `Basic ${Buffer.from(`${connection.email}:${connection.apiToken}`).toString('base64')}`,\n ...(init.body === undefined ? {} : { 'content-type': 'application/json' }),\n },\n ...(init.body === undefined ? {} : { body: JSON.stringify(init.body) }),\n signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),\n })\n } catch {\n throw new JiraError('unreachable', 'The Jira site could not be reached.')\n }\n if (response.status === 401 || response.status === 403) throw new JiraError('unauthorized', 'Jira rejected the credentials.')\n if (response.status === 404) throw new JiraError('not-found', 'The Jira endpoint was not found.')\n if (!response.ok) throw new JiraError('jira-failed', `Jira responded with HTTP ${response.status}.`)\n if (response.status === 204) return undefined\n try {\n return await response.json() as unknown\n } catch {\n throw new JiraError('jira-failed', 'Jira returned an invalid response.')\n }\n }\n\n async #read(): Promise<JiraStore | undefined> {\n let text: string\n try {\n text = await readFile(this.#storePath, 'utf8')\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') return undefined\n throw error\n }\n if (Buffer.byteLength(text) > MAX_STORE_BYTES) return undefined\n const input = record(JSON.parse(text))\n if (input === undefined || typeof input.siteUrl !== 'string' || typeof input.email !== 'string' || typeof input.apiToken !== 'string') return undefined\n return {\n siteUrl: input.siteUrl,\n email: input.email,\n apiToken: input.apiToken,\n ...(typeof input.displayName === 'string' ? { displayName: input.displayName } : {}),\n ...(typeof input.accountId === 'string' ? { accountId: input.accountId } : {}),\n }\n }\n\n async #write(store: JiraStore): Promise<void> {\n await mkdir(dirname(this.#storePath), { recursive: true, mode: 0o700 })\n const temporary = `${this.#storePath}.${process.pid}.${randomUUID()}.tmp`\n try {\n await writeFile(temporary, `${JSON.stringify(store, null, 2)}\\n`, { encoding: 'utf8', mode: 0o600, flag: 'wx' })\n await chmod(temporary, 0o600)\n await rename(temporary, this.#storePath)\n } finally {\n await rm(temporary, { force: true }).catch(() => undefined)\n }\n }\n}\n","import type { Context } from '@deepseek-ai/cordis'\nimport type {} from '@deepseek-ai/dsh-host-webserver'\nimport { CLAUDE_JIRA_PATH } from './constants.ts'\nimport { registerPluginRoute, type PluginRouteIo } from './http.ts'\nimport { JiraError, type JiraService } from './jira.ts'\n\nconst MAX_BODY_BYTES = 8 * 1024\n\nfunction record(value: unknown): Record<string, unknown> | undefined {\n return value !== null && typeof value === 'object' && !Array.isArray(value) ? value as Record<string, unknown> : undefined\n}\n\n/** The wrapper enforces the byte cap; its plain rejection is translated back\n * into the JiraError shape the panel already knows how to render. */\nasync function readJson(io: PluginRouteIo): Promise<Record<string, unknown>> {\n let body: unknown\n try {\n body = await io.body(MAX_BODY_BYTES)\n } catch (error) {\n if (error instanceof SyntaxError) throw error\n throw new JiraError('body-too-large', 'The request body is too large.')\n }\n const value = record(body)\n if (value === undefined) throw new JiraError('invalid-request', 'The request body is invalid.')\n return value\n}\n\nfunction string(input: Record<string, unknown>, key: string): string {\n const value = input[key]\n if (typeof value !== 'string') throw new JiraError('invalid-request', `The ${key} field is required.`)\n return value\n}\n\nexport function registerJiraRoute(ctx: Context, service: JiraService): void {\n registerPluginRoute(ctx, {\n mode: 'unary',\n kind: 'prefix',\n path: CLAUDE_JIRA_PATH,\n methods: ['GET', 'POST'],\n budget: 'git',\n handler: async io => {\n const url = io.url\n try {\n if (url.pathname === `${CLAUDE_JIRA_PATH}/status`) {\n if (io.method !== 'GET') return { status: 405, value: { error: 'method not allowed' } }\n return { status: 200, value: await service.status() }\n }\n if (url.pathname === `${CLAUDE_JIRA_PATH}/connect`) {\n if (io.method !== 'POST') return { status: 405, value: { error: 'method not allowed' } }\n const input = await readJson(io)\n return {\n status: 200,\n value: await service.connect({\n siteUrl: string(input, 'siteUrl'),\n email: string(input, 'email'),\n apiToken: string(input, 'apiToken'),\n }),\n }\n }\n if (url.pathname === `${CLAUDE_JIRA_PATH}/disconnect`) {\n if (io.method !== 'POST') return { status: 405, value: { error: 'method not allowed' } }\n await service.disconnect()\n return { status: 200, value: { connected: false } }\n }\n if (url.pathname === `${CLAUDE_JIRA_PATH}/assign`) {\n if (io.method !== 'POST') return { status: 405, value: { error: 'method not allowed' } }\n const input = await readJson(io)\n await service.assignToMe(string(input, 'key'))\n return { status: 200, value: { assigned: true } }\n }\n if (url.pathname === `${CLAUDE_JIRA_PATH}/search`) {\n if (io.method !== 'GET') return { status: 405, value: { error: 'method not allowed' } }\n return { status: 200, value: { tickets: await service.search(url.searchParams.get('query') ?? '') } }\n }\n return { status: 404, value: { error: 'not found' } }\n } catch (error) {\n if (error instanceof JiraError) return { status: 409, value: { error: error.code, message: error.message } }\n if (error instanceof SyntaxError) return { status: 400, value: { error: 'invalid-json' } }\n return { status: 500, value: { error: 'jira-unavailable', message: 'Jira is unavailable.' } }\n }\n },\n })\n}\n","import { StringDecoder } from 'node:string_decoder'\nimport type { SubprocessRuntime } from '@deepseek-ai/dsh-subprocess'\n\nconst MAX_SELECTION_CHARS = 8_000\nconst MAX_CONTEXT_CHARS = 16_000\nconst MAX_QUESTION_CHARS = 2_000\nconst ASK_TIMEOUT_MS = 180_000\nconst MAX_STDERR_BYTES = 64 * 1024\nconst MAX_TOOL_SUMMARY_CHARS = 160\nexport const READ_ONLY_TOOLS = ['Read', 'Grep', 'Glob'] as const\n\ntype AskRuntime = Pick<SubprocessRuntime, 'spawn'>\n\nexport interface AskRequest {\n readonly selection: string\n readonly context?: string\n readonly question: string\n}\n\n/** Model and effort the session last ran with; mirrored onto the side query. */\nexport interface AskPreferences {\n readonly model?: string\n readonly thinkingMode?: string\n}\n\nexport class AskError extends Error {\n readonly code: string\n\n constructor(code: string, message: string) {\n super(message)\n this.name = 'AskError'\n this.code = code\n }\n}\n\nfunction fence(value: string): string {\n return `\"\"\"\\n${value.replaceAll('\"\"\"', '\" \" \"')}\\n\"\"\"`\n}\n\nexport function askPrompt(request: AskRequest): string {\n const selection = request.selection.trim().slice(0, MAX_SELECTION_CHARS)\n const context = (request.context ?? '').trim().slice(0, MAX_CONTEXT_CHARS)\n const question = request.question.trim().slice(0, MAX_QUESTION_CHARS)\n return [\n 'You are answering a follow-up question about part of an earlier assistant reply in this project.',\n '',\n 'Selected passage:',\n fence(selection),\n ...(context.length === 0 || context === selection ? [] : ['', 'Surrounding reply, for context only:', fence(context)]),\n '',\n `Question: ${question}`,\n '',\n 'Answer the question directly and concisely, in the same language as the question. Use Markdown.',\n 'Only the read-only tools Read, Grep, and Glob are available; use them when the answer depends on project code, otherwise answer from the passage.',\n ].join('\\n')\n}\n\n/** CLI effort for a session thinking mode; `off` and unknown modes send nothing. */\nexport function effortFor(thinkingMode: string | undefined): string | undefined {\n if (thinkingMode === undefined || thinkingMode === 'off') return undefined\n if (thinkingMode === 'ultracode') return 'max'\n return ['low', 'medium', 'high', 'max'].includes(thinkingMode) ? thinkingMode : undefined\n}\n\nexport function askArguments(preferences: AskPreferences): readonly string[] {\n const effort = effortFor(preferences.thinkingMode)\n return [\n '-p', '--output-format', 'stream-json', '--verbose', '--include-partial-messages',\n // No MCP servers: a follow-up question never needs them and connecting\n // them roughly doubles cold start.\n '--strict-mcp-config', '--mcp-config', '{\"mcpServers\":{}}',\n ...(preferences.model === undefined || preferences.model === 'default' ? [] : ['--model', preferences.model]),\n ...(effort === undefined ? [] : ['--effort', effort]),\n // Read-only inspection only; both flags are variadic, so they stay last\n // and the prompt travels over stdin.\n '--tools', ...READ_ONLY_TOOLS, '--allowedTools', ...READ_ONLY_TOOLS,\n ]\n}\n\nfunction record(value: unknown): Record<string, unknown> | undefined {\n return value !== null && typeof value === 'object' && !Array.isArray(value) ? value as Record<string, unknown> : undefined\n}\n\n/** What one stream-json line contributes: streamed answer text, streamed\n * thinking, or the final result (used only when no text streamed). */\nexport type AskToolPhase = 'start' | 'input' | 'done'\n\nexport type AskStreamEvent =\n | { readonly type: 'text'; readonly text: string }\n | { readonly type: 'thinking'; readonly text: string }\n | { readonly type: 'status'; readonly text: string }\n | { readonly type: 'tool'; readonly id: string; readonly phase: AskToolPhase; readonly name?: string; readonly summary?: string; readonly error?: boolean }\n | { readonly type: 'result'; readonly text: string }\n\n/** One-line description of a tool call, mirroring the main window's step titles. */\nexport function toolSummary(input: unknown): string | undefined {\n const fields = record(input)\n if (fields === undefined) return undefined\n const candidate = [fields.command, fields.pattern, fields.file_path, fields.path, fields.query].find(value => typeof value === 'string' && value.length > 0)\n const text = typeof candidate === 'string' ? candidate : JSON.stringify(fields)\n return text.replaceAll(/\\s+/gu, ' ').trim().slice(0, MAX_TOOL_SUMMARY_CHARS)\n}\n\nexport function eventsOfStreamLine(line: string): readonly AskStreamEvent[] {\n let parsed: Record<string, unknown> | undefined\n try {\n parsed = record(JSON.parse(line))\n } catch {\n return []\n }\n if (parsed === undefined) return []\n if (parsed.type === 'system' && parsed.subtype === 'init') return [{ type: 'status', text: 'ready' }]\n if (parsed.type === 'stream_event') {\n const event = record(parsed.event)\n if (event?.type === 'content_block_start') {\n const block = record(event.content_block)\n if (block?.type === 'tool_use' && typeof block.id === 'string' && typeof block.name === 'string') {\n return [{ type: 'tool', id: block.id, phase: 'start', name: block.name }]\n }\n return []\n }\n const delta = record(event?.delta)\n if (event?.type !== 'content_block_delta' || delta === undefined) return []\n if (delta.type === 'text_delta' && typeof delta.text === 'string') return [{ type: 'text', text: delta.text }]\n if (delta.type === 'thinking_delta' && typeof delta.thinking === 'string') return [{ type: 'thinking', text: delta.thinking }]\n return []\n }\n if (parsed.type === 'assistant' || parsed.type === 'user') {\n const content = record(parsed.message)?.content\n if (!Array.isArray(content)) return []\n const events: AskStreamEvent[] = []\n for (const item of content) {\n const block = record(item)\n if (block?.type === 'tool_use' && typeof block.id === 'string' && typeof block.name === 'string') {\n const summary = toolSummary(block.input)\n events.push({ type: 'tool', id: block.id, phase: 'input', name: block.name, ...(summary === undefined ? {} : { summary }) })\n } else if (block?.type === 'tool_result' && typeof block.tool_use_id === 'string') {\n events.push({ type: 'tool', id: block.tool_use_id, phase: 'done', ...(block.is_error === true ? { error: true } : {}) })\n }\n }\n return events\n }\n if (parsed.type === 'result' && typeof parsed.result === 'string') return [{ type: 'result', text: parsed.result }]\n return []\n}\n\nexport type AskProgressEvent = Exclude<AskStreamEvent, { type: 'result' }>\n\n/** One-shot Claude Code query answering a question about selected reply text. */\nexport class AskService {\n readonly #runtime: AskRuntime\n readonly #executablePath: string\n\n constructor(runtime: AskRuntime, executablePath: string) {\n this.#runtime = runtime\n this.#executablePath = executablePath\n }\n\n async ask(cwd: string, request: AskRequest, preferences: AskPreferences, onEvent: (event: AskProgressEvent) => void, signal?: AbortSignal): Promise<void> {\n if (request.question.trim().length === 0 || request.selection.trim().length === 0) {\n throw new AskError('invalid-request', 'A selection and a question are required.')\n }\n if (this.#executablePath.length === 0) throw new AskError('claude-unavailable', 'Claude Code is unavailable.')\n const timeout = AbortSignal.timeout(ASK_TIMEOUT_MS)\n // The prompt rides stdin: `--tools ''` is variadic and would swallow a\n // trailing positional prompt argument.\n const handle = this.#runtime.spawn({\n argv: [this.#executablePath, ...askArguments(preferences)],\n cwd,\n stdio: { stdin: { data: askPrompt(request) }, stdout: 'pipe', stderr: { maxBytes: MAX_STDERR_BYTES } },\n graceMs: 1_000,\n signal: signal === undefined ? timeout : AbortSignal.any([signal, timeout]),\n env: {},\n })\n const stdout = handle.stdout\n if (stdout === undefined) throw new AskError('ask-failed', 'Claude output is unavailable.')\n const decoder = new StringDecoder('utf8')\n let buffer = ''\n let emitted = false\n let result: string | undefined\n const consume = (line: string): void => {\n for (const event of eventsOfStreamLine(line)) {\n if (event.type === 'result') {\n result = event.text\n continue\n }\n if (event.type !== 'tool' && event.text.length === 0) continue\n if (event.type === 'text') emitted = true\n onEvent(event)\n }\n }\n for await (const chunk of stdout) {\n buffer += typeof chunk === 'string' ? chunk : decoder.write(chunk as Buffer)\n const lines = buffer.split('\\n')\n buffer = lines.pop() ?? ''\n for (const line of lines) if (line.trim().length > 0) consume(line)\n }\n buffer += decoder.end()\n if (buffer.trim().length > 0) consume(buffer)\n const outcome = await handle.done\n if (!emitted && result !== undefined && result.length > 0) {\n emitted = true\n onEvent({ type: 'text', text: result })\n }\n if (!emitted) {\n if (signal?.aborted === true) throw new AskError('aborted', 'The question was cancelled.')\n if (timeout.aborted) throw new AskError('timeout', 'Claude took too long to answer.')\n const stderr = handle.collected.stderr?.readFrom(0).text.trim().split(/\\r?\\n/u).filter(line => line.length > 0).at(-1)\n throw new AskError('ask-failed', stderr !== undefined && stderr.length > 0 ? stderr : `Claude exited with code ${String(outcome.exitCode)}.`)\n }\n }\n}\n","import type { ServerResponse } from 'node:http'\nimport type { Context } from '@deepseek-ai/cordis'\nimport type {} from '@deepseek-ai/dsh-host-webserver'\nimport { AskError, type AskPreferences, type AskRequest, type AskService } from './ask.ts'\nimport { CLAUDE_ASK_PATH } from './constants.ts'\nimport { json, registerPluginRoute } from './http.ts'\n\nconst MAX_BODY_BYTES = 128 * 1024\nconst MAX_SESSION_ID_CHARS = 1_024\n/** Two sessions may await an answer at once; a third evicts the oldest. */\nconst MAX_CONCURRENT_ASKS = 2\n\nfunction record(value: unknown): Record<string, unknown> | undefined {\n return value !== null && typeof value === 'object' && !Array.isArray(value) ? value as Record<string, unknown> : undefined\n}\n\nfunction askRequest(input: Record<string, unknown>): AskRequest {\n if (typeof input.selection !== 'string' || typeof input.question !== 'string' || (input.context !== undefined && typeof input.context !== 'string')) {\n throw new AskError('invalid-request', 'The selection and question fields are required.')\n }\n return { selection: input.selection, question: input.question, ...(typeof input.context === 'string' ? { context: input.context } : {}) }\n}\n\nfunction ndjson(res: ServerResponse, value: unknown): void {\n res.write(`${JSON.stringify(value)}\\n`)\n}\n\n/** A stream route rather than a unary one: the answer is written as it arrives,\n * so the deadline stays where the work is — `ASK_TIMEOUT_MS` inside the\n * service, fused there with the disconnect signal — instead of a route budget\n * that would cut a legitimate long answer off mid-sentence. */\nexport function registerAskRoute(\n ctx: Context,\n service: AskService,\n cwdForSession: (sessionId: string) => string | undefined,\n preferencesFor: (sessionId: string) => AskPreferences | undefined,\n): void {\n registerPluginRoute(ctx, {\n mode: 'stream',\n kind: 'exact',\n path: CLAUDE_ASK_PATH,\n methods: ['POST'],\n maxConcurrent: MAX_CONCURRENT_ASKS,\n streamKey: url => url.searchParams.get('sessionId') ?? '',\n handler: async (res, io) => {\n let cwd: string\n let request: AskRequest\n let sessionId: string\n try {\n const value = io.url.searchParams.get('sessionId')\n if (value === null || value.length === 0 || value.length > MAX_SESSION_ID_CHARS) throw new AskError('invalid-session', 'The session is invalid.')\n sessionId = value\n const resolved = cwdForSession(sessionId)\n if (resolved === undefined) throw new AskError('session-unavailable', 'The Claude session is unavailable.')\n cwd = resolved\n const body = record(await io.body(MAX_BODY_BYTES))\n if (body === undefined) throw new AskError('invalid-request', 'The request body is invalid.')\n request = askRequest(body)\n } catch (error) {\n if (error instanceof AskError) return json(res, 409, { error: error.code, message: error.message })\n if (error instanceof SyntaxError) return json(res, 400, { error: 'invalid-json' })\n return json(res, 500, { error: 'ask-unavailable', message: 'The question could not be sent.' })\n }\n res.writeHead(200, {\n 'content-type': 'application/x-ndjson; charset=utf-8',\n 'cache-control': 'no-store',\n 'x-content-type-options': 'nosniff',\n })\n res.flushHeaders?.()\n try {\n await service.ask(cwd, request, preferencesFor(sessionId) ?? {}, event => { ndjson(res, event.type === 'text' ? { type: 'delta', text: event.text } : event) }, io.signal)\n ndjson(res, { type: 'done' })\n } catch (error) {\n ndjson(res, {\n type: 'error',\n code: error instanceof AskError ? error.code : 'ask-unavailable',\n message: error instanceof AskError ? error.message : 'The question could not be answered.',\n })\n }\n },\n })\n}\n","import type { Context } from '@deepseek-ai/cordis'\nimport type {} from '@deepseek-ai/dsh-host-webserver'\nimport { CLAUDE_REVIEW_COMMENT_PATH } from './constants.ts'\nimport { registerPluginRoute, type PluginRouteIo } from './http.ts'\nimport { ReviewCommentError, type ReviewCommentStore } from './review-comments.ts'\n\nconst MAX_BODY_BYTES = 16 * 1024\nconst MAX_SESSION_ID_CHARS = 1_024\n\nfunction record(value: unknown): Record<string, unknown> | undefined {\n return value !== null && typeof value === 'object' && !Array.isArray(value) ? value as Record<string, unknown> : undefined\n}\n\nasync function readJson(io: PluginRouteIo): Promise<Record<string, unknown>> {\n let parsed: unknown\n try {\n parsed = await io.body<unknown>(MAX_BODY_BYTES)\n } catch (error) {\n if (error instanceof SyntaxError) throw error\n throw new ReviewCommentError('body-too-large', 'The request body is too large.')\n }\n const value = record(parsed)\n if (value === undefined) throw new ReviewCommentError('invalid-request', 'The request body is invalid.')\n return value\n}\n\nfunction sessionIdFromUrl(url: URL): string {\n const value = url.searchParams.get('sessionId')\n if (value === null || value.length === 0 || value.length > MAX_SESSION_ID_CHARS) {\n throw new ReviewCommentError('invalid-session', 'The session is invalid.')\n }\n return value\n}\n\nexport function registerReviewCommentRoute(\n ctx: Context,\n store: ReviewCommentStore,\n ownsSession: (sessionId: string) => boolean,\n): void {\n registerPluginRoute(ctx, {\n mode: 'unary',\n kind: 'prefix',\n path: CLAUDE_REVIEW_COMMENT_PATH,\n methods: ['POST'],\n // The comment store is in memory; only reading the body can wait.\n budget: 'fast',\n handler: async io => {\n try {\n const sessionId = sessionIdFromUrl(io.url)\n if (!ownsSession(sessionId)) throw new ReviewCommentError('session-unavailable', 'The Claude session is unavailable.')\n const pathname = io.url.pathname\n if (pathname === CLAUDE_REVIEW_COMMENT_PATH) {\n const input = await readJson(io)\n const comment = store.add(sessionId, {\n path: input.path,\n line: input.line,\n startLine: input.startLine,\n side: input.side,\n text: input.text,\n })\n return { status: 200, value: { comment } }\n }\n if (pathname === `${CLAUDE_REVIEW_COMMENT_PATH}/clear`) {\n return { status: 200, value: { removed: store.drain(sessionId).length } }\n }\n if (pathname === `${CLAUDE_REVIEW_COMMENT_PATH}/remove`) {\n const input = await readJson(io)\n if (typeof input.id !== 'string' || input.id.length === 0 || input.id.length > 128) {\n throw new ReviewCommentError('invalid-request', 'The comment id is invalid.')\n }\n return { status: 200, value: { removed: store.remove(sessionId, input.id) } }\n }\n return { status: 404, value: { error: 'not found' } }\n } catch (error) {\n if (error instanceof ReviewCommentError) return { status: 409, value: { error: error.code, message: error.message } }\n if (error instanceof SyntaxError) return { status: 400, value: { error: 'invalid-json' } }\n return { status: 500, value: { error: 'review-comment-unavailable', message: 'Review comments are unavailable.' } }\n }\n },\n })\n}\n","import type { Context } from '@deepseek-ai/cordis'\nimport type {} from '@deepseek-ai/dsh-host-webserver'\nimport { CLAUDE_CLIENT_DIAGNOSTICS_PATH } from './constants.ts'\nimport { redactText } from './events.ts'\nimport { registerPluginRoute } from './http.ts'\n\n/** Enough for a message plus a trimmed stack; the client caps its own volume. */\nconst MAX_DIAGNOSTIC_BYTES = 8 * 1024\nconst MAX_DETAIL_CHARS = 2_000\nconst MAX_KIND_CHARS = 60\n\n/** `POST <path>` with `{ kind, detail }`: write one renderer finding to the Host log.\n *\n * The renderer has no other way to speak. A Slot entry that throws is caught\n * by the Host's Slot system and dropped, the shipped Desktop opens no\n * DevTools, and startup still reports `rendererStatus: \"healthy\"` — so a\n * plugin whose UI died silently is indistinguishable from a working one.\n * Every finding here is data written by this package's own client half, but\n * it is still bounded and redacted like any other untrusted input. */\nexport function registerClaudeClientDiagnosticsRoute(ctx: Context): void {\n registerPluginRoute(ctx, {\n mode: 'unary',\n kind: 'exact',\n path: CLAUDE_CLIENT_DIAGNOSTICS_PATH,\n methods: ['POST'],\n budget: 'fast',\n handler: async io => {\n try {\n const body = await io.body<{ kind?: unknown; detail?: unknown } | null>(MAX_DIAGNOSTIC_BYTES)\n const kind = typeof body?.kind === 'string' ? body.kind.slice(0, MAX_KIND_CHARS) : 'unknown'\n const detail = typeof body?.detail === 'string' ? body.detail : ''\n if (detail === '') return { status: 400, value: { error: 'invalid-request' } }\n ctx.logger.warn(`dsh-claude client [${kind}]: ${redactText(detail, MAX_DETAIL_CHARS)}`)\n return { status: 200, value: { ok: true } }\n } catch (error) {\n if (error instanceof SyntaxError) return { status: 400, value: { error: 'invalid-json' } }\n return { status: 400, value: { error: 'invalid-request' } }\n }\n },\n })\n}\n","import type { Context } from '@deepseek-ai/cordis'\nimport type { SessionEvent } from '@deepseek-ai/dsh-session'\nimport type {} from '@deepseek-ai/dsh-host-webserver'\nimport { CLAUDE_REWIND_PATH } from './constants.ts'\nimport { registerPluginRoute, type PluginRouteIo } from './http.ts'\nimport { EMPTY_REWIND_STATE, planRewind } from './rewind.ts'\nimport type { ClaudeSidecarRepository } from './sidecar.ts'\n\nconst MAX_BODY_BYTES = 4 * 1024\nconst MAX_SESSION_ID_CHARS = 1_024\n\nexport interface ClaudeRewindSessionAccess {\n /** The session log of one plugin-owned session, or undefined for any other. */\n eventsFor: (sessionId: string) => readonly SessionEvent[] | undefined\n /** Whether a turn is in flight; rewinding one would cut it mid-run. */\n busy: (sessionId: string) => boolean\n /** Drop the live Claude process so the next turn resumes at the fork target. */\n reset: (sessionId: string) => Promise<void>\n}\n\nfunction record(value: unknown): Record<string, unknown> | undefined {\n return value !== null && typeof value === 'object' && !Array.isArray(value) ? value as Record<string, unknown> : undefined\n}\n\n/** An oversized body fails the same field checks as a missing one; only\n * malformed JSON is worth reporting separately. */\nasync function readJson(io: PluginRouteIo): Promise<Record<string, unknown> | undefined> {\n try {\n return record(await io.body<unknown>(MAX_BODY_BYTES))\n } catch (error) {\n if (error instanceof SyntaxError) throw error\n return undefined\n }\n}\n\n/** `POST <path>` with `{ sessionId, seq }`: hide that surface event and every\n * later one, and arm Claude to resume before the turn it opened. */\nexport function registerClaudeRewindRoute(\n ctx: Context,\n sidecar: ClaudeSidecarRepository,\n access: ClaudeRewindSessionAccess,\n): void {\n registerPluginRoute(ctx, {\n mode: 'unary',\n kind: 'exact',\n path: CLAUDE_REWIND_PATH,\n methods: ['POST'],\n // The session log is already in memory; the sidecar write is local.\n budget: 'git',\n handler: async io => {\n try {\n const input = await readJson(io)\n const sessionId = input?.sessionId\n const seq = input?.seq\n if (typeof sessionId !== 'string' || sessionId.length === 0 || sessionId.length > MAX_SESSION_ID_CHARS\n || typeof seq !== 'number' || !Number.isSafeInteger(seq) || seq < 0) {\n return { status: 400, value: { error: 'invalid-request' } }\n }\n const events = access.eventsFor(sessionId)\n if (events === undefined) return { status: 409, value: { error: 'session-unavailable' } }\n if (access.busy(sessionId)) return { status: 409, value: { error: 'session-busy' } }\n const current = (await sidecar.read(sessionId)).rewind ?? EMPTY_REWIND_STATE\n const planned = planRewind(current, events, seq)\n if (planned === undefined) return { status: 409, value: { error: 'seq-unavailable' } }\n await sidecar.writeRewind(sessionId, planned)\n await access.reset(sessionId)\n return { status: 200, value: { ranges: planned.ranges } }\n } catch (error) {\n if (error instanceof SyntaxError) return { status: 400, value: { error: 'invalid-json' } }\n return { status: 500, value: { error: 'rewind-unavailable' } }\n }\n },\n })\n}\n","import type { Context } from '@deepseek-ai/cordis'\nimport type {} from '@deepseek-ai/dsh-host-webserver'\nimport type { SubprocessRuntime } from '@deepseek-ai/dsh-subprocess'\nimport { resolveDshHome } from '@deepseek-ai/dsh-home-paths'\nimport { opendir, readFile, realpath } from 'node:fs/promises'\nimport { dirname, join, resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport { CLAUDE_UPDATE_CHECK_PATH, CLAUDE_UPDATE_PATH } from './constants.ts'\nimport { redactText } from './events.ts'\nimport { registerPluginRoute, type PluginMethod } from './http.ts'\n\nexport const PLUGIN_PACKAGE_NAME = '@norman-else/dsh-claude'\nconst MAX_MANIFEST_BYTES = 256 * 1024\nconst MAX_UPDATE_OUTPUT_BYTES = 32 * 1024\nconst SEMVER = /^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-([0-9A-Za-z.-]+))?(?:\\+[0-9A-Za-z.-]+)?$/\nconst PROFILE_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/\n\nexport type InstallSource = 'registry' | 'link' | 'unsupported' | 'unknown'\nexport type UpdateState = 'current' | 'available' | 'linked' | 'unsupported' | 'unavailable' | 'error'\n\nexport interface PluginUpdateStatus {\n currentVersion: string\n latestVersion?: string\n source: InstallSource\n state: UpdateState\n canUpdate: boolean\n restartRequired: boolean\n message?: string\n}\n\ninterface PackageManifest {\n name?: unknown\n version?: unknown\n dependencies?: unknown\n}\n\nexport interface Installation {\n profile: string\n profileDir: string\n source: InstallSource\n spec: string\n}\n\nexport interface UpdateDependencies {\n packageDir?: string\n dshHome?: string\n fetchLatest?: (signal: AbortSignal) => Promise<string>\n resolveExecutable?: (name: string, env?: Readonly<Record<string, string>>, signal?: AbortSignal) => Promise<string>\n spawn?: SubprocessRuntime['spawn']\n requestRestart?: () => void\n}\n\n/** The route owns the deadline now. A direct caller with nothing to cancel\n * against gets a signal that never fires, rather than a second timeout\n * competing with the budget the route already declared. */\nconst NEVER_ABORTS = new AbortController().signal\n\nfunction safeMessage(error: unknown): string {\n return redactText(error instanceof Error ? error.message : String(error), 500)\n}\n\nasync function readManifest(path: string): Promise<PackageManifest> {\n const text = await readFile(path, 'utf8')\n if (Buffer.byteLength(text) > MAX_MANIFEST_BYTES) throw new Error('package manifest is too large')\n const value = JSON.parse(text) as unknown\n if (typeof value !== 'object' || value === null || Array.isArray(value)) throw new Error('package manifest is invalid')\n return value as PackageManifest\n}\n\nfunction dependencySpec(manifest: PackageManifest): string | undefined {\n if (typeof manifest.dependencies !== 'object' || manifest.dependencies === null || Array.isArray(manifest.dependencies)) return undefined\n const value = (manifest.dependencies as Record<string, unknown>)[PLUGIN_PACKAGE_NAME]\n return typeof value === 'string' && value.length <= 2_000 ? value : undefined\n}\n\nexport function classifyInstallSpec(spec: string): InstallSource {\n if (/^(?:link|file|workspace):/i.test(spec)) return 'link'\n if (/^(?:git(?:\\+[^:]+)?:|github:|https?:|npm:)/i.test(spec) || /\\.git(?:#|$)/i.test(spec)) return 'unsupported'\n return /^(?:\\^|~|>=?|<=?|=)?\\s*v?\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?(?:\\s*\\|\\|\\s*(?:\\^|~|>=?|<=?|=)?\\s*v?\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?)*$/.test(spec.trim())\n ? 'registry'\n : 'unsupported'\n}\n\nasync function samePath(left: string, right: string): Promise<boolean> {\n try {\n const [a, b] = await Promise.all([realpath(left), realpath(right)])\n return process.platform === 'win32' ? a.toLowerCase() === b.toLowerCase() : a === b\n } catch {\n return false\n }\n}\n\nfunction linkedTarget(profileDir: string, spec: string): string | undefined {\n const match = /^(?:link|file):(.*)$/i.exec(spec)\n return match?.[1] === undefined ? undefined : resolve(profileDir, match[1])\n}\n\nexport async function discoverInstallation(dshHome: string, packageDir: string): Promise<Installation | undefined> {\n const profilesDir = join(dshHome, 'profiles')\n const matches: Installation[] = []\n let profiles\n try {\n profiles = await opendir(profilesDir)\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') return undefined\n throw error\n }\n for await (const entry of profiles) {\n if (!entry.isDirectory() || !PROFILE_NAME.test(entry.name)) continue\n const profileDir = join(profilesDir, entry.name)\n let manifest: PackageManifest\n try {\n manifest = await readManifest(join(profileDir, 'package.json'))\n } catch {\n continue\n }\n const spec = dependencySpec(manifest)\n if (spec === undefined) continue\n const source = classifyInstallSpec(spec)\n const matchesPackage = source === 'link'\n ? linkedTarget(profileDir, spec) !== undefined && await samePath(linkedTarget(profileDir, spec)!, packageDir)\n : await samePath(join(profileDir, 'node_modules', ...PLUGIN_PACKAGE_NAME.split('/')), packageDir)\n if (matchesPackage) matches.push({ profile: entry.name, profileDir, source, spec })\n }\n return matches.length === 1 ? matches[0] : undefined\n}\n\nfunction parseVersion(version: string): RegExpExecArray {\n const match = SEMVER.exec(version)\n if (match === null) throw new Error('package version is not valid semver')\n return match\n}\n\nexport function compareVersions(left: string, right: string): number {\n const a = parseVersion(left)\n const b = parseVersion(right)\n for (const index of [1, 2, 3]) {\n const difference = Number(a[index]) - Number(b[index])\n if (difference !== 0) return Math.sign(difference)\n }\n const aPre = a[4]\n const bPre = b[4]\n if (aPre === undefined) return bPre === undefined ? 0 : 1\n if (bPre === undefined) return -1\n return aPre.localeCompare(bPre, 'en', { numeric: true })\n}\n\nasync function registryLatest(signal: AbortSignal): Promise<string> {\n const response = await fetch('https://registry.npmjs.org/%40norman-else%2Fdsh-claude', {\n headers: { accept: 'application/vnd.npm.install-v1+json' },\n signal,\n })\n if (!response.ok) throw new Error(`npm registry returned HTTP ${response.status}`)\n const payload = await response.json() as { 'dist-tags'?: { latest?: unknown } }\n const latest = payload['dist-tags']?.latest\n if (typeof latest !== 'string') throw new Error('npm registry response has no latest version')\n parseVersion(latest)\n return latest\n}\n\nasync function resolvePackageContextDir(configured?: string): Promise<{ packageDir: string; manifest: PackageManifest }> {\n const moduleDir = dirname(fileURLToPath(import.meta.url))\n const candidates = configured === undefined ? [moduleDir, dirname(moduleDir)] : [configured]\n for (const packageDir of candidates) {\n try {\n const manifest = await readManifest(join(packageDir, 'package.json'))\n if (manifest.name === PLUGIN_PACKAGE_NAME) return { packageDir, manifest }\n } catch {\n // Continue until the owning package manifest is found.\n }\n }\n throw new Error('plugin package manifest is invalid')\n}\n\nasync function packageContext(deps: UpdateDependencies): Promise<{ version: string; installation?: Installation }> {\n const { packageDir, manifest } = await resolvePackageContextDir(deps.packageDir)\n if (typeof manifest.version !== 'string') throw new Error('plugin package manifest is invalid')\n parseVersion(manifest.version)\n const home = deps.dshHome ?? resolveDshHome()\n const installation = await discoverInstallation(home, packageDir)\n return { version: manifest.version, ...(installation === undefined ? {} : { installation }) }\n}\n\nexport async function checkPluginUpdate(deps: UpdateDependencies = {}, signal: AbortSignal = NEVER_ABORTS): Promise<PluginUpdateStatus> {\n try {\n const { version, installation } = await packageContext(deps)\n if (installation === undefined) return { currentVersion: version, source: 'unknown', state: 'unavailable', canUpdate: false, restartRequired: false, message: 'Active DSH profile could not be identified uniquely' }\n if (installation.source === 'link') return { currentVersion: version, source: 'link', state: 'linked', canUpdate: false, restartRequired: false, message: 'Local development link; updates come from the linked checkout' }\n if (installation.source !== 'registry') return { currentVersion: version, source: installation.source, state: 'unsupported', canUpdate: false, restartRequired: false, message: 'This installation source cannot be updated from the npm registry' }\n const latest = await (deps.fetchLatest ?? registryLatest)(signal)\n const comparison = compareVersions(version, latest)\n return {\n currentVersion: version,\n latestVersion: latest,\n source: 'registry',\n state: comparison < 0 ? 'available' : 'current',\n canUpdate: comparison < 0,\n restartRequired: comparison < 0,\n }\n } catch (error) {\n return { currentVersion: 'unknown', source: 'unknown', state: 'error', canUpdate: false, restartRequired: false, message: safeMessage(error) }\n }\n}\n\nasync function verifyInstalledVersion(installation: Installation, expectedVersion: string): Promise<void> {\n const profileManifest = await readManifest(join(installation.profileDir, 'package.json'))\n if (dependencySpec(profileManifest) !== expectedVersion) {\n throw new Error('DSH plugin update completed without updating the profile dependency')\n }\n const installedManifest = await readManifest(join(\n installation.profileDir,\n 'node_modules',\n ...PLUGIN_PACKAGE_NAME.split('/'),\n 'package.json',\n ))\n if (installedManifest.name !== PLUGIN_PACKAGE_NAME || installedManifest.version !== expectedVersion) {\n throw new Error('DSH plugin update completed without installing the requested version')\n }\n}\n\nexport async function updatePlugin(deps: UpdateDependencies = {}, signal: AbortSignal = NEVER_ABORTS): Promise<PluginUpdateStatus> {\n const { version, installation } = await packageContext(deps)\n if (installation === undefined || installation.source !== 'registry') throw new Error('Plugin update is unavailable for this installation')\n const latest = await (deps.fetchLatest ?? registryLatest)(signal)\n if (compareVersions(version, latest) >= 0) return { currentVersion: version, latestVersion: latest, source: 'registry', state: 'current', canUpdate: false, restartRequired: false }\n const resolveExecutable = deps.resolveExecutable\n const spawn = deps.spawn\n if (resolveExecutable === undefined || spawn === undefined) throw new Error('DSH update runtime is unavailable')\n const executable = await resolveExecutable('dsh', {}, signal)\n const handle = spawn({\n argv: [executable, 'plugin', '--profile', installation.profile, 'add', `${PLUGIN_PACKAGE_NAME}@${latest}`],\n cwd: installation.profileDir,\n env: {},\n stdio: { stdin: 'ignore', stdout: { maxBytes: MAX_UPDATE_OUTPUT_BYTES }, stderr: { maxBytes: MAX_UPDATE_OUTPUT_BYTES } },\n graceMs: 2_000,\n signal,\n })\n const outcome = await handle.done\n if (outcome.exitCode !== 0) {\n const detail = handle.collected.stderr?.readFrom(0).text ?? ''\n throw new Error(`DSH plugin update failed (${outcome.exitCode ?? outcome.signal ?? 'unknown exit'}): ${safeMessage(detail)}`)\n }\n await verifyInstalledVersion(installation, latest)\n if (deps.requestRestart !== undefined) setTimeout(() => deps.requestRestart?.(), 100).unref?.()\n return {\n currentVersion: latest,\n latestVersion: latest,\n source: 'registry',\n state: 'current',\n canUpdate: false,\n restartRequired: deps.requestRestart === undefined,\n message: deps.requestRestart === undefined\n ? 'Update installed; restart DSH Desktop to load it'\n : 'Update installed; DSH Desktop is restarting to load it',\n }\n}\n\nexport function registerClaudeUpdateRoutes(ctx: Context, runtime: Pick<SubprocessRuntime, 'resolveExecutable' | 'spawn'>, deps: UpdateDependencies = {}): void {\n const shared: UpdateDependencies = { ...deps, resolveExecutable: runtime.resolveExecutable.bind(runtime), spawn: runtime.spawn.bind(runtime) }\n const routes: readonly { path: string; method: PluginMethod; run: (signal: AbortSignal) => Promise<PluginUpdateStatus> }[] = [\n { path: CLAUDE_UPDATE_CHECK_PATH, method: 'GET', run: signal => checkPluginUpdate(shared, signal) },\n { path: CLAUDE_UPDATE_PATH, method: 'POST', run: signal => updatePlugin(shared, signal) },\n ]\n for (const route of routes) {\n registerPluginRoute(ctx, {\n mode: 'unary',\n kind: 'exact',\n path: route.path,\n methods: [route.method],\n // The npm registry, then `dsh plugin add`, then a manifest re-read.\n budget: 'remote',\n handler: async io => {\n try {\n return { status: 200, value: await route.run(io.signal) }\n } catch (error) {\n return { status: 500, value: { error: safeMessage(error) } }\n }\n },\n })\n }\n}\n","import type { Context } from '@deepseek-ai/cordis'\nimport type {} from '@deepseek-ai/dsh-host-webserver'\nimport { CLAUDE_USAGE_PATH } from './constants.ts'\nimport { redactText } from './events.ts'\nimport { registerPluginRoute } from './http.ts'\nimport { latestPlanUsage, recordPlanUsage, type PlanUsageReport } from './plan-usage.ts'\n\nconst EMPTY: PlanUsageReport = { available: false, windows: [], fetchedAt: 0 }\n\nfunction safeMessage(error: unknown): string {\n return redactText(error instanceof Error ? error.message : String(error), 1_000)\n}\n\n/** Plan usage: GET serves the value the metadata bridge last cached (free —\n * it rides an already-running session), POST reads fresh numbers from a\n * throwaway probe process so a refresh never depends on, or disturbs, a live\n * Claude session. */\nexport function registerPlanUsageRoute(\n ctx: Context,\n probe: (fetchedAt: number) => Promise<PlanUsageReport>,\n now: () => number = Date.now,\n): void {\n registerPluginRoute(ctx, {\n mode: 'unary',\n kind: 'exact',\n path: CLAUDE_USAGE_PATH,\n methods: ['GET', 'POST'],\n // The probe spawns a throwaway CLI; the cached GET answers from memory.\n budget: 'git',\n handler: async io => {\n if (io.method === 'GET') return { status: 200, value: latestPlanUsage() ?? EMPTY }\n try {\n const report = await probe(now())\n recordPlanUsage(report)\n return { status: 200, value: report }\n } catch (error) {\n return { status: 500, value: { error: safeMessage(error) } }\n }\n },\n })\n}\n","import { randomUUID } from 'node:crypto'\nimport { homedir } from 'node:os'\nimport { chmod, mkdir, opendir, readFile, rename, rm, writeFile } from 'node:fs/promises'\nimport { dirname, extname, join } from 'node:path'\nimport type { Context } from '@deepseek-ai/cordis'\nimport type {} from '@deepseek-ai/dsh-host-webserver'\nimport { dshHomePath } from '@deepseek-ai/dsh-home-paths'\nimport {\n CLAUDE_GLOBAL_SETTINGS_PATH,\n CLAUDE_RENDER_MODES,\n CLAUDE_PROSE_MODES,\n DEFAULT_CLAUDE_PROSE_MODE,\n DEFAULT_CLAUDE_RENDER_MODE,\n isClaudeProseMode,\n isClaudeRenderMode,\n type ClaudeRenderMode,\n} from './constants.ts'\nimport { registerPluginRoute, type PluginRouteIo } from './http.ts'\n\nconst MAX_SETTINGS_BYTES = 256 * 1024\nconst MAX_REQUEST_BYTES = 8 * 1024\nconst MAX_STYLE_BYTES = 64 * 1024\nconst MAX_STYLE_FILES = 256\nconst BUILTIN_OUTPUT_STYLES = ['Default', 'Proactive', 'Concise', 'Explanatory', 'Learning'] as const\nconst STYLE_NAME = /^[\\p{L}\\p{N}][\\p{L}\\p{N} ._()\\[\\]-]{0,127}$/u\nconst DEFAULT_WORKTREE_BRANCH_PREFIX = 'claude'\nconst MAX_BRANCH_PREFIX_CHARS = 128\nconst MAX_PROCESSES_LIMIT = 16\nconst MAX_IDLE_TIMEOUT_MINUTES = 24 * 60\nconst DEFAULT_LIMITS: SupervisorLimits = { maxProcesses: 4, idleTimeoutMs: 30 * 60_000 }\n\ntype JsonObject = Record<string, unknown>\nexport type GlobalSettingEffect = 'immediate' | 'new-session' | 'next-turn' | 'next-worktree' | 'restart'\n\nexport interface GlobalSettingOption {\n value: string\n label: string\n source: 'built-in' | 'user' | 'configured'\n}\n\nexport type GlobalSettingView = {\n key: string\n kind: 'select'\n value: string\n options: readonly GlobalSettingOption[]\n effect: GlobalSettingEffect\n} | {\n key: string\n kind: 'text'\n value: string\n maxLength: number\n effect: GlobalSettingEffect\n}\n\nexport interface GlobalSettingsView {\n settings: readonly GlobalSettingView[]\n}\n\ninterface GlobalSettingsPaths {\n settingsFile: string\n outputStylesDir: string\n pluginSettingsFile: string\n}\n\n/** Effective supervisor limits: the plugin config values unless overridden in Settings. */\nexport interface SupervisorLimits {\n maxProcesses: number\n idleTimeoutMs: number\n}\n\nexport interface GlobalSettingsDependencies {\n paths?: Partial<GlobalSettingsPaths>\n /** Limits from the plugin config, shown when Settings holds no override. */\n defaultLimits?: SupervisorLimits\n /** Invoked after a successful update so live runtime state can follow. */\n onUpdated?: () => void | Promise<void>\n}\n\ninterface SelectSettingDescriptor {\n key: string\n kind: 'select'\n document: 'claude' | 'plugin'\n effect: GlobalSettingEffect\n options(paths: GlobalSettingsPaths): Promise<readonly GlobalSettingOption[]>\n read(document: JsonObject, options: readonly GlobalSettingOption[]): string\n apply(document: JsonObject, value: unknown, options: readonly GlobalSettingOption[]): void\n}\n\ninterface TextSettingDescriptor {\n key: string\n kind: 'text'\n document: 'claude' | 'plugin'\n effect: GlobalSettingEffect\n maxLength: number\n read(document: JsonObject, defaults?: SupervisorLimits): string\n apply(document: JsonObject, value: unknown): void\n}\n\ntype SettingDescriptor = SelectSettingDescriptor | TextSettingDescriptor\n\nfunction pathsFor(deps: GlobalSettingsDependencies): GlobalSettingsPaths {\n const root = join(homedir(), '.claude')\n return {\n settingsFile: deps.paths?.settingsFile ?? join(root, 'settings.json'),\n outputStylesDir: deps.paths?.outputStylesDir ?? join(root, 'output-styles'),\n pluginSettingsFile: deps.paths?.pluginSettingsFile ?? dshHomePath('plugins', 'dsh-claude', 'settings.json'),\n }\n}\n\nfunction object(value: unknown): JsonObject | undefined {\n return value !== null && typeof value === 'object' && !Array.isArray(value)\n ? value as JsonObject\n : undefined\n}\n\nasync function readDocument(path: string): Promise<JsonObject> {\n try {\n const text = await readFile(path, 'utf8')\n if (Buffer.byteLength(text) > MAX_SETTINGS_BYTES) throw new Error('Claude Code settings file is too large')\n const parsed = object(JSON.parse(text))\n if (parsed === undefined) throw new Error('Claude Code settings file must contain a JSON object')\n return parsed\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') return {}\n throw error\n }\n}\n\nfunction frontmatterName(text: string): string | undefined {\n if (!text.startsWith('---\\n') && !text.startsWith('---\\r\\n')) return undefined\n const normalized = text.replaceAll('\\r\\n', '\\n')\n const end = normalized.indexOf('\\n---\\n', 4)\n if (end < 0) return undefined\n for (const line of normalized.slice(4, end).split('\\n')) {\n const match = /^name:\\s*(.+?)\\s*$/.exec(line)\n if (match?.[1] === undefined) continue\n const raw = match[1]\n const value = (raw.startsWith('\"') && raw.endsWith('\"')) || (raw.startsWith(\"'\") && raw.endsWith(\"'\"))\n ? raw.slice(1, -1)\n : raw\n return STYLE_NAME.test(value) ? value : undefined\n }\n return undefined\n}\n\nasync function userOutputStyleOptions(directory: string): Promise<GlobalSettingOption[]> {\n const options: GlobalSettingOption[] = []\n let entries\n try {\n entries = await opendir(directory)\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') return options\n throw error\n }\n for await (const entry of entries) {\n if (options.length >= MAX_STYLE_FILES) break\n if (!entry.isFile() || extname(entry.name).toLowerCase() !== '.md') continue\n try {\n const text = await readFile(join(directory, entry.name), 'utf8')\n if (Buffer.byteLength(text) > MAX_STYLE_BYTES) continue\n const name = frontmatterName(text) ?? entry.name.slice(0, -3)\n if (STYLE_NAME.test(name)) options.push({ value: name, label: name, source: 'user' })\n } catch {\n // Ignore unreadable or malformed optional style files.\n }\n }\n return options\n}\n\nconst OUTPUT_STYLE: SettingDescriptor = {\n key: 'outputStyle',\n kind: 'select',\n document: 'claude',\n effect: 'new-session',\n async options(paths) {\n const builtIn = BUILTIN_OUTPUT_STYLES.map(value => ({ value, label: value, source: 'built-in' as const }))\n const user = await userOutputStyleOptions(paths.outputStylesDir)\n const seen = new Set<string>(builtIn.map(option => option.value))\n return [...builtIn, ...user.filter(option => !seen.has(option.value)).sort((a, b) => a.label.localeCompare(b.label))]\n },\n read(document, options) {\n const value = document.outputStyle\n return typeof value === 'string' && STYLE_NAME.test(value) ? value : 'Default'\n },\n apply(document, value, options) {\n if (typeof value !== 'string' || !options.some(option => option.value === value)) {\n throw new Error('Invalid value for global setting outputStyle')\n }\n if (value === 'Default') delete document.outputStyle\n else document.outputStyle = value\n },\n}\n\nexport function isValidWorktreeBranchPrefix(value: string): boolean {\n return value.length > 0\n && value.length <= MAX_BRANCH_PREFIX_CHARS\n && value.trim() === value\n && !value.startsWith('/')\n && !value.endsWith('/')\n && !value.includes('//')\n && !value.includes('..')\n && !value.includes('@{')\n && !/[\\0-\\x20\\x7f~^:?*[\\\\]/u.test(value)\n && value.split('/').every(segment => segment.length > 0 && !segment.startsWith('.') && !segment.endsWith('.lock'))\n}\n\nconst WORKTREE_BRANCH_PREFIX: TextSettingDescriptor = {\n key: 'worktreeBranchPrefix',\n kind: 'text',\n document: 'plugin',\n effect: 'next-worktree',\n maxLength: MAX_BRANCH_PREFIX_CHARS,\n read(document) {\n const value = document.worktreeBranchPrefix\n return typeof value === 'string' && isValidWorktreeBranchPrefix(value) ? value : DEFAULT_WORKTREE_BRANCH_PREFIX\n },\n apply(document, value) {\n if (typeof value !== 'string' || !isValidWorktreeBranchPrefix(value)) {\n throw new Error('Invalid value for global setting worktreeBranchPrefix')\n }\n if (value === DEFAULT_WORKTREE_BRANCH_PREFIX) delete document.worktreeBranchPrefix\n else document.worktreeBranchPrefix = value\n },\n}\n\n/** Which renderer draws Claude's visible output. Plugin settings, not Claude's:\n * the CLI has no opinion about how DSH paints a turn. The option labels stay\n * machine-readable ids; the Client translates the two known values. */\nconst RENDERER: SelectSettingDescriptor = {\n key: 'renderer',\n kind: 'select',\n document: 'plugin',\n // The Host reads this per message and stamps every record it writes with the\n // renderer that produced it, so the switch lands on the next turn and a turn\n // already recorded keeps the renderer it was recorded with.\n effect: 'next-turn',\n async options() {\n return CLAUDE_RENDER_MODES.map(value => ({ value, label: value, source: 'built-in' as const }))\n },\n read(document) {\n const value = document.renderer\n return isClaudeRenderMode(value) ? value : DEFAULT_CLAUDE_RENDER_MODE\n },\n apply(document, value) {\n if (!isClaudeRenderMode(value)) throw new Error('Invalid value for global setting renderer')\n if (value === DEFAULT_CLAUDE_RENDER_MODE) delete document.renderer\n else document.renderer = value\n },\n}\n\n/** Whether Claude's prose gets the highlight palette. Presentation only: no\n * record carries it and nothing on the server reads it back, so unlike\n * {@link RENDERER} the switch lands the moment the Client rewrites its own\n * stylesheet — hence 'immediate' rather than 'next-turn'. */\nconst PROSE: SelectSettingDescriptor = {\n key: 'prose',\n kind: 'select',\n document: 'plugin',\n effect: 'immediate',\n async options() {\n return CLAUDE_PROSE_MODES.map(value => ({ value, label: value, source: 'built-in' as const }))\n },\n read(document) {\n const value = document.prose\n return isClaudeProseMode(value) ? value : DEFAULT_CLAUDE_PROSE_MODE\n },\n apply(document, value) {\n if (!isClaudeProseMode(value)) throw new Error('Invalid value for global setting prose')\n if (value === DEFAULT_CLAUDE_PROSE_MODE) delete document.prose\n else document.prose = value\n },\n}\n\nfunction isBoundedInteger(value: unknown, min: number, max: number): value is number {\n return typeof value === 'number' && Number.isInteger(value) && value >= min && value <= max\n}\n\nfunction integerSetting(\n key: 'maxProcesses' | 'idleTimeoutMinutes',\n min: number,\n max: number,\n defaultFor: (limits: SupervisorLimits) => number,\n): TextSettingDescriptor {\n return {\n key,\n kind: 'text',\n document: 'plugin',\n effect: 'new-session',\n maxLength: String(max).length,\n read(document, defaults = DEFAULT_LIMITS) {\n const value = document[key]\n return String(isBoundedInteger(value, min, max) ? value : defaultFor(defaults))\n },\n apply(document, value) {\n const parsed = typeof value === 'string' && /^\\d{1,6}$/u.test(value.trim()) ? Number(value.trim()) : value\n if (!isBoundedInteger(parsed, min, max)) throw new Error(`Invalid value for global setting ${key}`)\n document[key] = parsed\n },\n }\n}\n\nconst MAX_PROCESSES = integerSetting('maxProcesses', 1, MAX_PROCESSES_LIMIT, limits => limits.maxProcesses)\nconst IDLE_TIMEOUT_MINUTES = integerSetting('idleTimeoutMinutes', 1, MAX_IDLE_TIMEOUT_MINUTES, limits => Math.max(1, Math.round(limits.idleTimeoutMs / 60_000)))\n\nconst DESCRIPTORS: readonly SettingDescriptor[] = [OUTPUT_STYLE, RENDERER, PROSE, WORKTREE_BRANCH_PREFIX, MAX_PROCESSES, IDLE_TIMEOUT_MINUTES]\nconst DESCRIPTOR_BY_KEY = new Map(DESCRIPTORS.map(descriptor => [descriptor.key, descriptor]))\nlet pendingWrite: Promise<unknown> = Promise.resolve()\n\nfunction documentFor(descriptor: SettingDescriptor, documents: { claude: JsonObject; plugin: JsonObject }): JsonObject {\n return documents[descriptor.document]\n}\n\nasync function views(documents: { claude: JsonObject; plugin: JsonObject }, paths: GlobalSettingsPaths, defaults: SupervisorLimits): Promise<GlobalSettingsView> {\n return {\n settings: await Promise.all(DESCRIPTORS.map(async descriptor => {\n const document = documentFor(descriptor, documents)\n if (descriptor.kind === 'text') {\n return {\n key: descriptor.key,\n kind: descriptor.kind,\n value: descriptor.read(document, defaults),\n maxLength: descriptor.maxLength,\n effect: descriptor.effect,\n }\n }\n const discovered = await descriptor.options(paths)\n const value = descriptor.read(document, discovered)\n const options = discovered.some(option => option.value === value)\n ? discovered\n : [...discovered, { value, label: value, source: 'configured' as const }]\n return {\n key: descriptor.key,\n kind: descriptor.kind,\n value,\n options,\n effect: descriptor.effect,\n }\n })),\n }\n}\n\nasync function readDocuments(paths: GlobalSettingsPaths): Promise<{ claude: JsonObject; plugin: JsonObject }> {\n const [claude, plugin] = await Promise.all([readDocument(paths.settingsFile), readDocument(paths.pluginSettingsFile)])\n return { claude, plugin }\n}\n\nexport async function readGlobalSettings(deps: GlobalSettingsDependencies = {}): Promise<GlobalSettingsView> {\n const paths = pathsFor(deps)\n return views(await readDocuments(paths), paths, deps.defaultLimits ?? DEFAULT_LIMITS)\n}\n\n/** Supervisor limits the user overrode in Settings; absent keys fall back to the plugin config. */\nexport async function readSupervisorLimitOverrides(deps: GlobalSettingsDependencies = {}): Promise<Partial<SupervisorLimits>> {\n let document: JsonObject\n try {\n document = await readDocument(pathsFor(deps).pluginSettingsFile)\n } catch {\n return {}\n }\n const maxProcesses = document.maxProcesses\n const idleTimeoutMinutes = document.idleTimeoutMinutes\n return {\n ...(isBoundedInteger(maxProcesses, 1, MAX_PROCESSES_LIMIT) ? { maxProcesses } : {}),\n ...(isBoundedInteger(idleTimeoutMinutes, 1, MAX_IDLE_TIMEOUT_MINUTES) ? { idleTimeoutMs: idleTimeoutMinutes * 60_000 } : {}),\n }\n}\n\n/** The renderer the Host should produce output for. A missing, unreadable, or\n * malformed plugin settings file keeps today's plugin-owned transcript. */\nexport async function readRenderMode(deps: GlobalSettingsDependencies = {}): Promise<ClaudeRenderMode> {\n let document: JsonObject\n try {\n document = await readDocument(pathsFor(deps).pluginSettingsFile)\n } catch {\n return DEFAULT_CLAUDE_RENDER_MODE\n }\n return isClaudeRenderMode(document.renderer) ? document.renderer : DEFAULT_CLAUDE_RENDER_MODE\n}\n\nexport async function readWorktreeBranchPrefix(deps: GlobalSettingsDependencies = {}): Promise<string> {\n const paths = pathsFor(deps)\n return WORKTREE_BRANCH_PREFIX.read(await readDocument(paths.pluginSettingsFile))\n}\n\nasync function atomicWrite(path: string, document: JsonObject): Promise<void> {\n await mkdir(dirname(path), { recursive: true, mode: 0o700 })\n const temporary = `${path}.${process.pid}.${randomUUID()}.tmp`\n try {\n await writeFile(temporary, `${JSON.stringify(document, null, 2)}\\n`, { encoding: 'utf8', mode: 0o600, flag: 'wx' })\n await chmod(temporary, 0o600)\n await rename(temporary, path)\n await chmod(path, 0o600)\n } finally {\n await rm(temporary, { force: true }).catch(() => undefined)\n }\n}\n\nexport function updateGlobalSettings(changes: unknown, deps: GlobalSettingsDependencies = {}): Promise<GlobalSettingsView> {\n const changeObject = object(changes)\n if (changeObject === undefined || Object.keys(changeObject).length === 0) {\n return Promise.reject(new Error('Global settings changes must be a non-empty object'))\n }\n for (const key of Object.keys(changeObject)) {\n if (!DESCRIPTOR_BY_KEY.has(key)) return Promise.reject(new Error(`Unsupported global setting: ${key}`))\n }\n const paths = pathsFor(deps)\n const operation = pendingWrite.catch(() => undefined).then(async () => {\n const documents = await readDocuments(paths)\n const changedDocuments = new Set<'claude' | 'plugin'>()\n for (const [key, value] of Object.entries(changeObject)) {\n const descriptor = DESCRIPTOR_BY_KEY.get(key)!\n const document = documentFor(descriptor, documents)\n if (descriptor.kind === 'select') descriptor.apply(document, value, await descriptor.options(paths))\n else descriptor.apply(document, value)\n changedDocuments.add(descriptor.document)\n }\n if (changedDocuments.has('claude')) await atomicWrite(paths.settingsFile, documents.claude)\n if (changedDocuments.has('plugin')) await atomicWrite(paths.pluginSettingsFile, documents.plugin)\n return views(documents, paths, deps.defaultLimits ?? DEFAULT_LIMITS)\n })\n pendingWrite = operation\n return operation\n}\n\nasync function requestJson(io: PluginRouteIo): Promise<unknown> {\n const body = object(await io.body(MAX_REQUEST_BYTES))\n if (body === undefined || Object.keys(body).some(key => key !== 'changes')) throw new Error('Invalid global settings request')\n return body.changes\n}\n\nexport function registerClaudeGlobalSettingsRoute(ctx: Context, deps: GlobalSettingsDependencies = {}): void {\n registerPluginRoute(ctx, {\n mode: 'unary',\n kind: 'exact',\n path: CLAUDE_GLOBAL_SETTINGS_PATH,\n methods: ['GET', 'PATCH'],\n // Reads and writes two small JSON files under the home directory.\n budget: 'fast',\n handler: async io => {\n try {\n const result = io.method === 'GET'\n ? await readGlobalSettings(deps)\n : await updateGlobalSettings(await requestJson(io), deps)\n if (io.method === 'PATCH') await deps.onUpdated?.()\n return { status: 200, value: result }\n } catch (error) {\n return { status: 400, value: { error: error instanceof Error ? error.message : 'Invalid global settings request' } }\n }\n },\n })\n}\n","import type { Context } from '@deepseek-ai/cordis'\nimport type {} from '@deepseek-ai/dsh-attachment'\nimport z from '@deepseek-ai/schemastery'\nimport type { Agent } from '@deepseek-ai/dsh-agent'\nimport type {} from '@deepseek-ai/dsh-commands'\nimport type {} from '@deepseek-ai/dsh-agent-presets'\nimport type {} from '@deepseek-ai/dsh-host-webserver'\nimport type {} from '@deepseek-ai/dsh-subprocess'\nimport type {} from '@deepseek-ai/dsh-user-approval'\nimport type {} from '@deepseek-ai/dsh-user-questions'\nimport { CLAUDE_CODE_PRESET_ID, CLAUDE_CODE_PROVIDER_IDS, DEFAULT_CLAUDE_RENDER_MODE } from './constants.ts'\nimport { CLAUDE_COMMANDS_SERVICE, projectClaudeCommands, type ClaudeAgentCommandService, type ClaudeCommandView } from './command-bridge.ts'\nimport { ClaudeSidecarRepository } from './sidecar.ts'\nimport { resolveClaudeExecutable } from './executable.ts'\nimport { ClaudeSupervisor } from './supervisor.ts'\nimport { createClaudeCodeAdapter } from './adapter.ts'\nimport { ensureManagedPreset, ManagedPresetConflictError } from './preset-installer.ts'\nimport { claudeBridgeDiagnostics, registerClaudeDoctorRoutes, type ClaudeBridgeDiagnostic } from './doctor-routes.ts'\nimport { registerClaudeProjectionRoute } from './projection-routes.ts'\nimport { RepositoryStatusService } from './repository-status.ts'\nimport { comparablePath, RepositorySetupService } from './repository-setup.ts'\nimport { summarizeBranchSlug } from './branch-name.ts'\nimport { RepositoryActionService } from './repository-actions.ts'\nimport { registerRepositorySetupRoute } from './repository-setup-routes.ts'\nimport { registerRepositoryActionRoute } from './repository-action-routes.ts'\nimport { registerEditorOpenRoute } from './editor-open-routes.ts'\nimport { EditorOpenService } from './editor-open.ts'\nimport { PullRequestFeedbackService } from './pr-feedback.ts'\nimport { registerPullRequestFeedbackRoute } from './pr-feedback-routes.ts'\nimport { registerRepositoryStatusRoute } from './repository-status-routes.ts'\nimport { registerRepositoryFileRoute } from './repository-file-routes.ts'\nimport { JiraService } from './jira.ts'\nimport { registerJiraRoute } from './jira-routes.ts'\nimport { AskService } from './ask.ts'\nimport { registerAskRoute } from './ask-routes.ts'\nimport { registerReviewCommentRoute } from './review-comment-routes.ts'\nimport { registerClaudeClientDiagnosticsRoute } from './client-diagnostics-routes.ts'\nimport { registerClaudeRewindRoute } from './rewind-routes.ts'\nimport { ReviewCommentStore } from './review-comments.ts'\nimport { registerClaudeUpdateRoutes } from './update-routes.ts'\nimport { normalizePlanUsage, probePlanUsage, recordPlanUsage } from './plan-usage.ts'\nimport { registerPlanUsageRoute } from './plan-usage-routes.ts'\nimport { readRenderMode, readSupervisorLimitOverrides, readWorktreeBranchPrefix, registerClaudeGlobalSettingsRoute } from './global-settings.ts'\n\nexport const name = 'llm-claude'\nexport const inject = ['llm', 'agents', 'agentPresets', 'commands', 'subprocess', 'approval', 'userQuestions', 'attachments']\n\nexport interface Config {\n executablePath?: string\n model?: string\n idleTimeoutMs?: number\n maxProcesses?: number\n}\n\nexport const Config: z<Config> = z.object({\n executablePath: z.string().default(''),\n model: z.string().default('default'),\n idleTimeoutMs: z.number().min(1_000).max(2_147_483_647).default(30 * 60 * 1_000),\n maxProcesses: z.number().step(1).min(1).default(4),\n})\n\nconst CLAUDE_SCOPE_UNAVAILABLE_MESSAGE = 'agent command scope unavailable (preset route not mounted?)'\nconst CATALOG_RETRY_MS = 5_000\nconst SCOPE_RETRY_MS = 500\nconst MAX_CATALOG_RETRIES = 3\nconst MAX_SCOPE_RETRIES = 24\n\nexport function mountClaudeMetadata(\n ctx: Context,\n supervisor: ClaudeSupervisor,\n agent: Agent,\n model: string,\n sidecar: ClaudeSidecarRepository,\n publishCommands: (commands: readonly ClaudeCommandView[]) => void = () => {},\n // IMPORTANT: call through the injected agentPresets SERVICE, never an\n // imported serviceForAgent() — a linked plugin resolves peer packages from\n // its own node_modules, which creates a second module instance with empty\n // module-level mount state. The service method runs on the app's instance.\n resolveCommands: () => ClaudeAgentCommandService | undefined =\n () => ctx.agentPresets.serviceFor(agent, CLAUDE_COMMANDS_SERVICE),\n): (() => Promise<void>) | undefined {\n if (ctx.agentPresets.composedPreset(agent.ctx) !== CLAUDE_CODE_PRESET_ID) return undefined\n\n let stopped = false\n let pending = Promise.resolve()\n let commandScope: ClaudeAgentCommandService | undefined\n\n // The commands service is unreachable from this host view of agent.ctx;\n // the preset route plugin provides it as an isolated per-session service.\n const scopedCommands = () => {\n const scoped = commandScope ?? resolveCommands()\n if (scoped === undefined) throw new Error(CLAUDE_SCOPE_UNAVAILABLE_MESSAGE)\n commandScope = scoped\n return scoped\n }\n\n const commandTarget = {\n list: () => scopedCommands().list(agent),\n }\n\n const warn = (area: string, error: unknown) => {\n ctx.logger.warn(`dsh-claude: ${area} refresh failed for ${String(agent.id)}: ${error instanceof Error ? error.message : String(error)}`)\n }\n\n const isScopeUnavailable = (error: unknown): boolean => {\n if (error instanceof Error) return error.message === CLAUDE_SCOPE_UNAVAILABLE_MESSAGE\n return String(error) === CLAUDE_SCOPE_UNAVAILABLE_MESSAGE\n }\n\n const diagnostic: ClaudeBridgeDiagnostic = claudeBridgeDiagnostics.get(agent) ?? { attempts: 0 }\n claudeBridgeDiagnostics.set(agent, diagnostic)\n\n // A fresh session's first catalog fetch races CLI startup (skills/plugins\n // can make init slow); retry with backoff so the command palette still\n // populates without waiting for the first completed turn.\n let catalogRetries = 0\n let scopeRetries = 0\n let retryTimer: ReturnType<typeof setTimeout> | undefined\n\n const scheduleRetry = (area: 'command catalog' | 'command scope', attempt: number) => {\n if (retryTimer !== undefined) clearTimeout(retryTimer)\n const delay = area === 'command catalog' ? CATALOG_RETRY_MS * attempt : Math.min(SCOPE_RETRY_MS * 2 ** attempt, 5_000)\n retryTimer = setTimeout(() => {\n if (!stopped) refresh()\n }, delay)\n retryTimer.unref?.()\n }\n\n const refresh = () => {\n pending = pending.then(async () => {\n if (stopped) return\n diagnostic.attempts += 1\n\n let catalog: Awaited<ReturnType<ClaudeSupervisor['supportedCommands']>> | undefined\n\n try {\n const result = await supervisor.supportedCommands(agent, model)\n catalog = result\n catalogRetries = 0\n scopeRetries = 0\n diagnostic.lastCatalog = catalog.length\n delete diagnostic.lastError\n } catch (error) {\n diagnostic.lastError = error instanceof Error ? error.message : String(error)\n warn('command catalog', error)\n if (!stopped && catalogRetries < MAX_CATALOG_RETRIES) {\n catalogRetries += 1\n scheduleRetry('command catalog', catalogRetries)\n }\n }\n\n if (stopped || catalog === undefined) return\n\n try {\n const commands = projectClaudeCommands(catalog, commandTarget)\n publishCommands(commands)\n diagnostic.registered = commands.map(view => view.publicName)\n if (!stopped) scopeRetries = 0\n } catch (error) {\n diagnostic.lastError = error instanceof Error ? error.message : String(error)\n warn('command catalog', error)\n if (!stopped && isScopeUnavailable(error) && scopeRetries < MAX_SCOPE_RETRIES) {\n scopeRetries += 1\n scheduleRetry('command scope', scopeRetries)\n }\n }\n\n if (stopped) return\n try {\n const usage = await supervisor.contextUsage(agent, model)\n if (!stopped) await sidecar.writeContextUsage(agent.id as string, usage)\n } catch (error) {\n warn('context usage', error)\n }\n\n if (stopped) return\n // Plan limits belong to the account, not the session, so any idle Claude\n // agent can refresh the cache the (session-less) settings page reads.\n try {\n const plan = await supervisor.planUsage(agent, model)\n if (!stopped) recordPlanUsage(normalizePlanUsage(plan, Date.now()))\n } catch (error) {\n warn('plan usage', error)\n }\n })\n }\n\n return agent.ctx.effect(() => {\n const stopStatus = agent.ctx.on('agent/status', ({ status }) => {\n if (status === 'idle') refresh()\n })\n\n refresh()\n\n return async () => {\n stopped = true\n publishCommands([])\n if (retryTimer !== undefined) clearTimeout(retryTimer)\n stopStatus()\n await pending\n }\n }, 'dsh-claude: agent metadata bridge')\n}\n\nexport async function installManagedPresetCompatibility(\n logger: Pick<Context['logger'], 'warn'>,\n install: typeof ensureManagedPreset = ensureManagedPreset,\n): Promise<'installed' | 'unchanged' | 'conflict'> {\n try {\n return await install()\n } catch (error) {\n if (!(error instanceof ManagedPresetConflictError)) throw error\n logger.warn(`dsh-claude: preserving user-modified preset at ${error.path}`)\n return 'conflict'\n }\n}\n\nexport async function apply(ctx: Context, config: Config): Promise<void> {\n // DSH Desktop 2.0.4 does not retain third-party preset roots from bundle\n // patches, so keep a guarded user-root copy. Its bare route specifier resolves\n // through the profile package factory and does not create a second Loader source.\n await installManagedPresetCompatibility(ctx.logger)\n const defaultLimits = {\n idleTimeoutMs: config.idleTimeoutMs ?? 30 * 60 * 1_000,\n maxProcesses: config.maxProcesses ?? 4,\n }\n const supervisorConfig = {\n executablePath: '',\n defaultModel: config.model ?? 'default',\n renderMode: DEFAULT_CLAUDE_RENDER_MODE,\n ...defaultLimits,\n }\n // Settings overrides win over the plugin config; the supervisor reads the\n // shared config object on every admission, idle schedule, and rendered\n // message, so updates take effect without a restart. The Client still\n // decides its own conversation nodes at boot, which is why the renderer\n // setting is declared as restart-scoped.\n const applySettingsOverrides = async (): Promise<void> => {\n const overrides = await readSupervisorLimitOverrides()\n supervisorConfig.idleTimeoutMs = overrides.idleTimeoutMs ?? defaultLimits.idleTimeoutMs\n supervisorConfig.maxProcesses = overrides.maxProcesses ?? defaultLimits.maxProcesses\n supervisorConfig.renderMode = await readRenderMode()\n }\n await applySettingsOverrides()\n const sidecar = new ClaudeSidecarRepository()\n const repositoryStatus = new RepositoryStatusService(ctx.subprocess)\n const repositorySetup = new RepositorySetupService(ctx.subprocess, {\n branchPrefix: () => readWorktreeBranchPrefix(),\n // Read at call time: the executable is resolved after this service exists.\n summarizeBranch: intent => summarizeBranchSlug(supervisorConfig.executablePath, intent),\n })\n const reviewComments = new ReviewCommentStore()\n const commandCatalogs = new Map<string, readonly ClaudeCommandView[]>()\n const supervisor = new ClaudeSupervisor({\n runtime: ctx.subprocess,\n approval: ctx.approval,\n userQuestions: ctx.userQuestions,\n config: supervisorConfig,\n runDetached: operation => ctx.agents.withoutInitiator(operation),\n sidecar,\n })\n let resolutionError: unknown\n try {\n const resolution = await resolveClaudeExecutable(\n ctx.subprocess,\n config.executablePath === undefined || config.executablePath.length === 0\n ? undefined\n : config.executablePath,\n )\n supervisorConfig.executablePath = resolution.path\n ctx.llm.registerAdapter(\n [...CLAUDE_CODE_PROVIDER_IDS],\n createClaudeCodeAdapter(supervisor, ctx.agents, ctx.attachments, agent => ctx.agentPresets.composedPreset(agent.ctx), sessionId => reviewComments.drain(sessionId), () => supervisorConfig.renderMode),\n )\n ctx.effect(() => {\n const mounted = new Map<Agent, () => Promise<void>>()\n const pending = new Set<Agent>()\n const MOUNT_RETRY_MS = 200\n const MOUNT_RETRY_LIMIT = 50\n const mount = (agent: Agent) => {\n if (mounted.has(agent)) return\n const sessionId = agent.id as string\n const dispose = mountClaudeMetadata(\n ctx,\n supervisor,\n agent,\n supervisorConfig.defaultModel,\n sidecar,\n commands => {\n if (commands.length === 0) commandCatalogs.delete(sessionId)\n else commandCatalogs.set(sessionId, commands)\n },\n )\n if (dispose !== undefined) mounted.set(agent, dispose)\n pending.delete(agent)\n }\n // The standing preset mount lands AFTER agent/created (the PresetTree is\n // applied asynchronously), so composedPreset is still undefined at that\n // point. Poll briefly until the join settles, then decide.\n const mountWhenPresetSettles = (agent: Agent) => {\n if (mounted.has(agent) || pending.has(agent)) return\n if (ctx.agentPresets.composedPreset(agent.ctx) !== undefined) {\n mount(agent)\n return\n }\n pending.add(agent)\n let attempts = 0\n const retry = () => {\n if (mounted.has(agent) || !pending.has(agent)) return\n if (ctx.agentPresets.composedPreset(agent.ctx) !== undefined) {\n mount(agent)\n return\n }\n attempts += 1\n if (attempts >= MOUNT_RETRY_LIMIT) {\n pending.delete(agent)\n return\n }\n const timer = setTimeout(retry, MOUNT_RETRY_MS)\n timer.unref?.()\n }\n const timer = setTimeout(retry, MOUNT_RETRY_MS)\n timer.unref?.()\n }\n const stopCreated = ctx.on('agent/created', ({ agent }) => { mountWhenPresetSettles(agent) })\n // Belt and suspenders: the session records its preset selection as a\n // durable event, which agent-presets republishes as agent-preset/selected.\n // agent-preset/selected is emitted by dsh-agent-presets but is not part\n // of the typed host event map yet; subscribe through a typed escape hatch.\n const onPresetSelected = ctx.on as (event: 'agent-preset/selected', handler: (sessionId: string, preset: string) => void) => () => void\n const stopSelected = onPresetSelected('agent-preset/selected', (sessionId, preset) => {\n if (preset !== CLAUDE_CODE_PRESET_ID) return\n const agent = ctx.agents.get(sessionId as never)\n if (agent !== undefined) mountWhenPresetSettles(agent)\n })\n for (const agent of ctx.agents.list()) mountWhenPresetSettles(agent)\n return async () => {\n stopCreated()\n stopSelected()\n pending.clear()\n await Promise.allSettled([...mounted.values()].map(dispose => dispose()))\n mounted.clear()\n }\n }, 'dsh-claude: metadata bridges')\n } catch (error) {\n resolutionError = error\n }\n ctx.on('agent/disposed', async ({ agent }) => {\n reviewComments.disposeSession(agent.id as string)\n await supervisor.disposeSession(agent.id as string)\n })\n // Set once the reconciliation below is wired; the Client's sweep route kicks\n // it so a deleted workspace does not wait out the interval.\n let sweepWorktrees: (() => void) | undefined\n // Deleting a workspace from the sidebar is a durable-registry mutation with\n // no agent lifecycle edge, so worktree cleanup reconciles leases against\n // the workspace registry instead: unreferenced clean worktrees are removed\n // on boot, on the Client's deletion kick, and on a slow interval.\n // workspaceRegistry is not part of this plugin's typed host surface yet;\n // inject through an untyped escape hatch so older Hosts without the service\n // simply never start the sweep.\n const injectWorkspaceRegistry = ctx.inject as unknown as (\n deps: readonly string[],\n callback: (sweepCtx: Context & {\n workspaceRegistry: {\n list(): readonly { readonly path: string }[]\n archiveSession(sessionId: string): Promise<void>\n }\n }) => void,\n ) => void\n injectWorkspaceRegistry(['workspaceRegistry'], sweepCtx => {\n // Deleting a workspace only drops its registration: the Host keeps every\n // session log, and rebuilds the workspace from those headers on the next\n // boot. Archiving the sessions that lived in the worktree is what makes\n // the deletion stick. Resolved per sweep rather than injected so a Host\n // without the service still gets worktree cleanup.\n const archiveSessions = async (worktreePath: string): Promise<void> => {\n const persistence = sweepCtx.get('sessionPersistence') as {\n list(): Promise<readonly { readonly id?: unknown; readonly cwd?: unknown }[]>\n } | undefined\n if (persistence === undefined) return\n const target = comparablePath(worktreePath)\n for (const header of await persistence.list()) {\n if (typeof header.id !== 'string' || typeof header.cwd !== 'string') continue\n if (comparablePath(header.cwd) !== target) continue\n await sweepCtx.workspaceRegistry.archiveSession(header.id).catch(() => undefined)\n }\n }\n const sweep = (): void => {\n try {\n const paths = sweepCtx.workspaceRegistry.list().map(workspace => workspace.path)\n void repositorySetup.cleanupOrphans(paths, archiveSessions).catch(() => undefined)\n } catch {\n // The registry can be mid-teardown; skip this pass.\n }\n }\n sweepCtx.effect(() => {\n sweep()\n sweepWorktrees = sweep\n // The kick covers the deletion the user is watching; this poll is the\n // backstop for a Client that never sent one. A pass with nothing to\n // reconcile is one small file read.\n const timer = setInterval(sweep, 60_000)\n timer.unref?.()\n return () => {\n sweepWorktrees = undefined\n clearInterval(timer)\n }\n }, 'dsh-claude: worktree reconciliation')\n })\n ctx.effect(() => () => reviewComments.dispose(), 'dsh-claude: review comments store')\n ctx.effect(() => () => supervisor.dispose(), 'dsh-claude: process supervisor')\n ctx.effect(() => () => repositoryStatus.dispose(), 'dsh-claude: repository status cache')\n ctx.inject(['webServer'], webCtx => {\n registerClaudeClientDiagnosticsRoute(webCtx)\n registerClaudeDoctorRoutes(webCtx, webCtx.subprocess, supervisor, supervisorConfig, resolutionError)\n const desktopActions = webCtx.get('desktopActions') as { requestRestart?: () => void } | undefined\n registerClaudeUpdateRoutes(webCtx, webCtx.subprocess, {\n ...(typeof desktopActions?.requestRestart === 'function'\n ? { requestRestart: desktopActions.requestRestart.bind(desktopActions) }\n : {}),\n })\n registerClaudeGlobalSettingsRoute(webCtx, { defaultLimits, onUpdated: applySettingsOverrides })\n registerRepositorySetupRoute(webCtx, repositorySetup, () => sweepWorktrees?.())\n registerRepositoryStatusRoute(webCtx, repositoryStatus)\n registerRepositoryFileRoute(webCtx, repositoryStatus)\n registerJiraRoute(webCtx, new JiraService())\n const repositoryActions = new RepositoryActionService(webCtx.subprocess, supervisorConfig.executablePath, cwd => repositoryStatus.invalidate(cwd))\n const cwdForClaudeSession = (sessionId: string): string | undefined => {\n const agent = webCtx.agents.get(sessionId as never)\n if (agent === undefined || webCtx.agentPresets.composedPreset(agent.ctx) !== CLAUDE_CODE_PRESET_ID) return undefined\n return agent.session.header.cwd\n }\n registerRepositoryActionRoute(webCtx, repositoryActions, cwdForClaudeSession)\n registerEditorOpenRoute(webCtx, new EditorOpenService(webCtx.subprocess), cwdForClaudeSession)\n registerPullRequestFeedbackRoute(webCtx, new PullRequestFeedbackService(webCtx.subprocess), cwdForClaudeSession)\n registerAskRoute(webCtx, new AskService(webCtx.subprocess, supervisorConfig.executablePath), cwdForClaudeSession, sessionId => {\n const snapshot = supervisor.snapshots().find(item => item.sessionId === sessionId)\n return snapshot === undefined ? undefined : { model: snapshot.model, ...(snapshot.thinkingMode === undefined ? {} : { thinkingMode: snapshot.thinkingMode }) }\n })\n const ownsClaudeSession = (sessionId: string): boolean => {\n const agent = webCtx.agents.get(sessionId as never)\n return agent !== undefined && webCtx.agentPresets.composedPreset(agent.ctx) === CLAUDE_CODE_PRESET_ID\n }\n registerReviewCommentRoute(webCtx, reviewComments, ownsClaudeSession)\n registerClaudeRewindRoute(webCtx, sidecar, {\n eventsFor: sessionId => {\n const agent = webCtx.agents.get(sessionId as never)\n return agent === undefined || webCtx.agentPresets.composedPreset(agent.ctx) !== CLAUDE_CODE_PRESET_ID\n ? undefined\n : agent.session.events\n },\n busy: sessionId => supervisor.snapshots().some(item => (\n item.sessionId === sessionId && (item.state === 'running' || item.state === 'interrupting')\n )),\n reset: sessionId => supervisor.disposeSession(sessionId),\n })\n registerPlanUsageRoute(webCtx, fetchedAt => probePlanUsage(supervisorConfig.executablePath, fetchedAt))\n registerClaudeProjectionRoute(webCtx, sidecar, ownsClaudeSession, sessionId => commandCatalogs.get(sessionId) ?? [], async sessionId => {\n const agent = webCtx.agents.get(sessionId as never)\n if (agent === undefined || webCtx.agentPresets.composedPreset(agent.ctx) !== CLAUDE_CODE_PRESET_ID) return undefined\n const cwd = agent.session.header.cwd\n return cwd === undefined ? undefined : repositoryStatus.inspect(cwd)\n }, sessionId => reviewComments.list(sessionId))\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAwCA,MAAa,qBAAwC;CAAE,QAAQ,CAAC;CAAG,SAAS,CAAC;AAAE;;;AAQ/E,SAAgB,kBACd,QACA,UACqB;CACrB,MAAM,SAA8B,CAAC;CACrC,IAAI,EAAE,OAAO,QAAQ;CACrB,KAAK,MAAM,SAAS,CAAC,GAAG,MAAM,CAAC,CAAC,MAAM,MAAM,UAAU,KAAK,QAAQ,MAAM,KAAK,GAC5E,IAAI,MAAM,MAAM,IAAI,OAAO,OAAO,KAAK,KAAK;MACvC,IAAI,MAAM,QAAQ,MAAM,GAAG;EAC9B,OAAO,KAAK;GAAE;GAAO;EAAI,CAAC;EAC1B,QAAQ,MAAM;EACd,MAAM,MAAM;CACd,OAAO;EACL,QAAQ,KAAK,IAAI,OAAO,MAAM,KAAK;EACnC,MAAM,KAAK,IAAI,KAAK,MAAM,GAAG;CAC/B;CAEF,OAAO,KAAK;EAAE;EAAO;CAAI,CAAC;CAC1B,OAAO,OAAO,MAAM,IAAkB;AACxC;;AAOA,SAAgB,mBACd,OACA,QACmB;CACnB,MAAM,UAAU,CAAC,GAAG,MAAM,QAAQ,QAAO,SAAQ,KAAK,SAAS,OAAO,IAAI,GAAG,MAAM,CAAC,CACjF,MAAM,MAAM,UAAU,KAAK,OAAO,MAAM,IAAI,CAAC,CAC7C,MAAM,IAAmB;CAC5B,OAAO;EAAE,GAAG;EAAO;CAAQ;AAC7B;;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C;EACD,uBAAuB,SAAQ,cAAa,eAAe,iBAAiB,gBAAgB,SAAS,CAAC;EACtG,8BAA8B,QAAQ,SAAS,oBAAmB,cAAa,gBAAgB,IAAI,SAAS,KAAK,CAAC,GAAG,OAAM,cAAa;GACtI,MAAM,QAAQ,OAAO,OAAO,IAAI,SAAkB;GAClD,IAAI,UAAU,KAAA,KAAa,OAAO,aAAa,eAAe,MAAM,GAAG,MAAA,UAA6B,OAAO,KAAA;GAC3G,MAAM,MAAM,MAAM,QAAQ,OAAO;GACjC,OAAO,QAAQ,KAAA,IAAY,KAAA,IAAY,iBAAiB,QAAQ,GAAG;EACrE,IAAG,cAAa,eAAe,KAAK,SAAS,CAAC;CAChD,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["record","string","record","string","latest","record","claudeQuery","query","claudeQuery","MAX_TEXT_CHARS","MAX_PATH_CHARS","safeMessage","MAX_SESSION_ID_CHARS","MAX_OUTPUT_BYTES","GIT_TIMEOUT_MS","GH_TIMEOUT_MS","collect","record","MAX_REPLY_CHARS","claudeQuery","MAX_OUTPUT_BYTES","GIT_TIMEOUT_MS","MAX_PATH_CHARS","collect","MAX_OUTPUT_BYTES","GIT_TIMEOUT_MS","collect","MAX_BODY_BYTES","record","readJson","string","optionalString","ndjson","MAX_BODY_BYTES","MAX_SESSION_ID_CHARS","record","readJson","sessionId","string","MAX_OUTPUT_BYTES","MAX_SESSION_ID_CHARS","MAX_REPLY_CHARS","record","MAX_SESSION_ID_CHARS","MAX_BODY_BYTES","record","readJson","MAX_PATH_CHARS","record","MAX_BODY_BYTES","record","readJson","record","MAX_BODY_BYTES","MAX_SESSION_ID_CHARS","record","MAX_BODY_BYTES","MAX_SESSION_ID_CHARS","record","readJson","safeMessage"],"sources":["../src/rewind.ts","../src/sidecar.ts","../src/async-queue.ts","../src/permission.ts","../src/user-question.ts","../src/sdk-messages.ts","../src/model-catalog.ts","../src/plan-usage.ts","../src/spawn.ts","../src/supervisor.ts","../src/review-comments.ts","../src/adapter.ts","../src/plugin-budget.ts","../src/http.ts","../src/doctor-routes.ts","../src/projection-routes.ts","../src/repository-status.ts","../src/branch-name.ts","../src/repository-setup.ts","../src/repository-actions.ts","../src/repository-setup-routes.ts","../src/repository-action-routes.ts","../src/editor-open.ts","../src/editor-open-routes.ts","../src/github-url.ts","../src/pr-feedback.ts","../src/pr-feedback-routes.ts","../src/repository-status-routes.ts","../src/repository-file-routes.ts","../src/jira.ts","../src/jira-routes.ts","../src/ask.ts","../src/ask-routes.ts","../src/review-comment-routes.ts","../src/client-diagnostics-routes.ts","../src/rewind-routes.ts","../src/update-routes.ts","../src/plan-usage-routes.ts","../src/global-settings.ts","../src/index.ts"],"sourcesContent":["/** Rewind: drop one user message and everything after it.\n *\n * Two halves, because the two sides of a Claude session are owned by\n * different processes:\n *\n * - Claude's own transcript is rewound for real. Every completed DSH turn\n * records the last chain-entry uuid Claude emitted for it, so the next\n * spawn resumes at the kept turn's anchor (`resumeSessionAt`) and the model\n * genuinely forgets the discarded turns.\n * - The DSH session log is append-only and the Host renders every event it\n * holds — even compaction keeps the shadowed conversation on screen — so the\n * discarded rows are recorded here as hidden seq ranges and suppressed by\n * the browser instead of deleted.\n */\nimport type { SessionEvent } from '@deepseek-ai/dsh-session'\n\n/** One inclusive span of hidden surface seqs. */\nexport interface ClaudeRewindRange {\n readonly start: number\n readonly end: number\n}\n\n/** The last Claude chain entry of one completed DSH turn. */\nexport interface ClaudeRewindAnchor {\n readonly turn: number\n readonly uuid: string\n}\n\n/** Fork target for the next Claude spawn; `fresh` starts an empty session. */\nexport type ClaudeRewindResume = { readonly resumeAt: string } | { readonly fresh: true }\n\nexport interface ClaudeRewindState {\n /** Hidden seq ranges, ascending and non-overlapping. */\n readonly ranges: readonly ClaudeRewindRange[]\n /** Chain anchors of the turns Claude still holds, ascending by turn. */\n readonly anchors: readonly ClaudeRewindAnchor[]\n /** Armed once by a rewind, consumed by the next Claude spawn. */\n readonly pending?: ClaudeRewindResume\n}\n\nexport const EMPTY_REWIND_STATE: ClaudeRewindState = { ranges: [], anchors: [] }\n\n/** Sessions outlive their rewinds; both lists stay bounded. */\nexport const MAX_REWIND_RANGES = 200\nexport const MAX_REWIND_ANCHORS = 2_000\n\n/** Absorb one span into an ascending, non-overlapping range list. Adjacent\n * spans merge so a rewind of a rewind reads as one hidden block. */\nexport function mergeRewindRanges(\n ranges: readonly ClaudeRewindRange[],\n addition: ClaudeRewindRange,\n): ClaudeRewindRange[] {\n const merged: ClaudeRewindRange[] = []\n let { start, end } = addition\n for (const range of [...ranges].sort((left, right) => left.start - right.start)) {\n if (range.end + 1 < start) merged.push(range)\n else if (range.start > end + 1) {\n merged.push({ start, end })\n start = range.start\n end = range.end\n } else {\n start = Math.min(start, range.start)\n end = Math.max(end, range.end)\n }\n }\n merged.push({ start, end })\n return merged.slice(-MAX_REWIND_RANGES)\n}\n\nexport function isRewound(ranges: readonly ClaudeRewindRange[], seq: number): boolean {\n return ranges.some(range => seq >= range.start && seq <= range.end)\n}\n\n/** Record one completed turn's last chain entry, replacing a re-run turn. */\nexport function recordRewindAnchor(\n state: ClaudeRewindState,\n anchor: ClaudeRewindAnchor,\n): ClaudeRewindState {\n const anchors = [...state.anchors.filter(item => item.turn !== anchor.turn), anchor]\n .sort((left, right) => left.turn - right.turn)\n .slice(-MAX_REWIND_ANCHORS)\n return { ...state, anchors }\n}\n\n/** The turn a surface seq belongs to: the first turn opened at or after it.\n * A message accepted but never run belongs to no logged turn, so nothing\n * Claude holds is discarded and every anchor stays valid. */\nexport function turnAtOrAfter(events: readonly SessionEvent[], seq: number): number | undefined {\n for (const event of events) {\n if (event.seq >= seq && event.type === 'turn/start') return event.data.turn\n }\n return undefined\n}\n\n/** Plan one rewind at `seq`, or undefined when the seq is not in the log.\n * Anchors of the discarded turns go with them: after this rewind Claude no\n * longer holds those entries, so a later rewind must never fork at one. */\nexport function planRewind(\n state: ClaudeRewindState,\n events: readonly SessionEvent[],\n seq: number,\n): ClaudeRewindState | undefined {\n const last = events.at(-1)?.seq\n if (last === undefined || seq > last) return undefined\n const turn = turnAtOrAfter(events, seq) ?? Number.MAX_SAFE_INTEGER\n const anchors = state.anchors.filter(anchor => anchor.turn < turn)\n const kept = anchors.at(-1)\n return {\n ranges: mergeRewindRanges(state.ranges, { start: seq, end: last }),\n anchors,\n pending: kept === undefined ? { fresh: true } : { resumeAt: kept.uuid },\n }\n}\n","import { randomUUID } from 'node:crypto'\nimport { chmod, mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises'\nimport { join } from 'node:path'\nimport { dshHomePath } from '@deepseek-ai/dsh-home-paths'\nimport type { SessionEvent } from '@deepseek-ai/dsh-session'\nimport {\n latestClaudeContextUsage,\n latestClaudeSessionBinding,\n latestClaudeTasks,\n normalizeActivity,\n normalizeContextUsage,\n normalizeTasksEvent,\n redactText,\n type ClaudeActivityEvent,\n type ClaudeActivityInput,\n type ClaudeContextUsageEvent,\n type ClaudeContextUsageInput,\n type ClaudeSessionBoundEvent,\n type ClaudeTaskInfo,\n type ClaudeTasksEvent,\n} from './events.ts'\nimport { CLAUDE_ACTIVITY_EVENT, SDK_VERSION, type ClaudeRenderMode } from './constants.ts'\nimport {\n EMPTY_REWIND_STATE,\n MAX_REWIND_ANCHORS,\n MAX_REWIND_RANGES,\n recordRewindAnchor,\n type ClaudeRewindAnchor,\n type ClaudeRewindRange,\n type ClaudeRewindState,\n} from './rewind.ts'\n\nconst SIDECAR_SCHEMA_VERSION = 1\nconst MAX_ACTIVITIES = 10_000\n/** Trailing window that coalesces per-token transcript persistence into one\n * atomic disk write; live subscribers are notified synchronously regardless. */\nconst TEXT_FLUSH_MS = 150\n\nexport interface ClaudeSidecarProjection {\n readonly schemaVersion: typeof SIDECAR_SCHEMA_VERSION\n readonly revision: number\n readonly binding?: ClaudeSessionBoundEvent\n readonly activities: readonly ClaudeActivityEvent[]\n readonly contextUsage?: ClaudeContextUsageEvent\n readonly tasks?: ClaudeTasksEvent\n readonly rewind?: ClaudeRewindState\n}\n\n/** Change notification published to live subscribers after each accepted write.\n *\n * `checkpoint` is the one kind that carries no change: it restates where the\n * stream stands so a reader can notice it is behind. See {@link ClaudeSidecarRepository.checkpoint}. */\nexport type ClaudeSidecarDelta =\n | { kind: 'text'; turn: number; step: number; ordinal: number; append?: string; text?: string; renderer?: ClaudeRenderMode }\n | { kind: 'activity'; activity: ClaudeActivityEvent }\n | { kind: 'contextUsage'; value: ClaudeContextUsageEvent }\n | { kind: 'tasks'; value: ClaudeTasksEvent }\n | { kind: 'sync' }\n | { kind: 'checkpoint' }\n\n/** One delta as subscribers see it: numbered, so a reader that applies them in\n * order can tell a missing one from a slow one.\n *\n * The projection's own `revision` cannot do this job. Streaming prose notifies\n * subscribers without touching disk (see {@link ClaudeSidecarRepository.appendTranscriptText}),\n * so revisions and notifications advance on different clocks; this counter\n * advances once per notification and nothing else reads it. */\nexport type ClaudeSidecarNotification = ClaudeSidecarDelta & { readonly seq: number }\n\nexport interface ClaudeSidecarRepositoryOptions {\n readonly root?: string\n readonly legacyRoot?: string\n}\n\nfunction emptyProjection(): ClaudeSidecarProjection {\n return { schemaVersion: SIDECAR_SCHEMA_VERSION, revision: 0, activities: [] }\n}\n\nfunction record(value: unknown): Record<string, unknown> | undefined {\n return value !== null && typeof value === 'object' && !Array.isArray(value)\n ? value as Record<string, unknown>\n : undefined\n}\n\nfunction finiteInteger(value: unknown): value is number {\n return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0\n}\n\nfunction string(value: unknown, max: number): value is string {\n return typeof value === 'string' && value.length > 0 && value.length <= max\n}\n\nfunction binding(value: unknown): ClaudeSessionBoundEvent | undefined {\n const input = record(value)\n if (input === undefined\n || !string(input.claudeSessionId, 512)\n || !string(input.sdkVersion, 128)\n || !string(input.cwd, 4_096)\n || (input.cliVersion !== undefined && !string(input.cliVersion, 128))) return undefined\n return {\n claudeSessionId: input.claudeSessionId,\n sdkVersion: input.sdkVersion,\n cwd: input.cwd,\n ...(input.cliVersion === undefined ? {} : { cliVersion: input.cliVersion }),\n }\n}\n\nconst ACTIVITY_KINDS = new Set(['text', 'status', 'compaction', 'thinking', 'tool-call', 'tool-result', 'permission', 'question', 'subagent', 'usage', 'warning', 'error'])\nconst ACTIVITY_PHASES = new Set(['started', 'updated', 'completed', 'denied', 'failed'])\n\nfunction activity(value: unknown): ClaudeActivityEvent | undefined {\n const input = record(value)\n if (input === undefined\n || !finiteInteger(input.turn)\n || !finiteInteger(input.step)\n || !finiteInteger(input.ordinal)\n || typeof input.kind !== 'string'\n || !ACTIVITY_KINDS.has(input.kind)\n || (input.phase !== undefined && (typeof input.phase !== 'string' || !ACTIVITY_PHASES.has(input.phase)))) return undefined\n return normalizeActivity(input as unknown as ClaudeActivityEvent)\n}\n\nfunction contextUsage(value: unknown): ClaudeContextUsageEvent | undefined {\n const input = record(value)\n if (input === undefined || !Array.isArray(input.categories)) return undefined\n return normalizeContextUsage(input as unknown as ClaudeContextUsageInput)\n}\n\nfunction rewind(value: unknown): ClaudeRewindState | undefined {\n const input = record(value)\n if (input === undefined\n || !Array.isArray(input.ranges) || input.ranges.length > MAX_REWIND_RANGES\n || !Array.isArray(input.anchors) || input.anchors.length > MAX_REWIND_ANCHORS) return undefined\n const ranges: ClaudeRewindRange[] = []\n for (const item of input.ranges) {\n const range = record(item)\n if (range === undefined || !finiteInteger(range.start) || !finiteInteger(range.end) || range.end < range.start) return undefined\n ranges.push({ start: range.start, end: range.end })\n }\n const anchors: ClaudeRewindAnchor[] = []\n for (const item of input.anchors) {\n const anchor = record(item)\n if (anchor === undefined || !finiteInteger(anchor.turn) || !string(anchor.uuid, 128)) return undefined\n anchors.push({ turn: anchor.turn, uuid: anchor.uuid })\n }\n const pending = record(input.pending)\n if (input.pending !== undefined && pending === undefined) return undefined\n if (pending === undefined) return { ranges, anchors }\n if (pending.fresh === true) return { ranges, anchors, pending: { fresh: true } }\n if (!string(pending.resumeAt, 128)) return undefined\n return { ranges, anchors, pending: { resumeAt: pending.resumeAt } }\n}\n\nfunction tasks(value: unknown): ClaudeTasksEvent | undefined {\n const input = record(value)\n if (input === undefined || !Array.isArray(input.tasks)) return undefined\n return normalizeTasksEvent(input.tasks as ClaudeTaskInfo[])\n}\n\nexport function parseClaudeSidecar(value: unknown): ClaudeSidecarProjection {\n const input = record(value)\n if (input === undefined\n || input.schemaVersion !== SIDECAR_SCHEMA_VERSION\n || !finiteInteger(input.revision)\n || !Array.isArray(input.activities)\n || input.activities.length > MAX_ACTIVITIES) {\n throw new Error('dsh-claude: invalid sidecar document')\n }\n const activities = input.activities.map(activity)\n if (activities.some(item => item === undefined)) throw new Error('dsh-claude: invalid sidecar activity')\n const parsedBinding = input.binding === undefined ? undefined : binding(input.binding)\n const parsedUsage = input.contextUsage === undefined ? undefined : contextUsage(input.contextUsage)\n const parsedTasks = input.tasks === undefined ? undefined : tasks(input.tasks)\n const parsedRewind = input.rewind === undefined ? undefined : rewind(input.rewind)\n if ((input.binding !== undefined && parsedBinding === undefined)\n || (input.contextUsage !== undefined && parsedUsage === undefined)\n || (input.tasks !== undefined && parsedTasks === undefined)\n || (input.rewind !== undefined && parsedRewind === undefined)) {\n throw new Error('dsh-claude: invalid sidecar projection')\n }\n return {\n schemaVersion: SIDECAR_SCHEMA_VERSION,\n revision: input.revision,\n activities: activities as ClaudeActivityEvent[],\n ...(parsedBinding === undefined ? {} : { binding: parsedBinding }),\n ...(parsedUsage === undefined ? {} : { contextUsage: parsedUsage }),\n ...(parsedTasks === undefined ? {} : { tasks: parsedTasks }),\n ...(parsedRewind === undefined ? {} : { rewind: parsedRewind }),\n }\n}\n\nfunction compareActivity(left: ClaudeActivityEvent, right: ClaudeActivityEvent): number {\n return left.turn - right.turn || left.step - right.step || left.ordinal - right.ordinal\n}\n\nfunction activityKey(value: ClaudeActivityEvent): string {\n return `${value.turn}:${value.step}:${value.ordinal}`\n}\n\nfunction mergeActivities(\n existing: readonly ClaudeActivityEvent[],\n additions: readonly ClaudeActivityEvent[],\n): ClaudeActivityEvent[] {\n const merged = new Map(existing.map(item => [activityKey(item), item]))\n for (const item of additions) merged.set(activityKey(item), item)\n return [...merged.values()].sort(compareActivity).slice(-MAX_ACTIVITIES)\n}\n\nfunction normalizeBinding(\n input: Omit<ClaudeSessionBoundEvent, 'sdkVersion'> & { sdkVersion?: string },\n): ClaudeSessionBoundEvent {\n return {\n claudeSessionId: redactText(input.claudeSessionId, 512),\n sdkVersion: redactText(input.sdkVersion ?? SDK_VERSION, 128),\n cwd: redactText(input.cwd, 4_096),\n ...(input.cliVersion === undefined ? {} : { cliVersion: redactText(input.cliVersion, 128) }),\n }\n}\n\nexport class ClaudeSidecarRepository {\n readonly root: string\n readonly legacyRoot: string | undefined\n readonly #pending = new Map<string, Promise<unknown>>()\n /** Latest durable projection per session; disk is read once and written through. */\n readonly #latest = new Map<string, ClaudeSidecarProjection>()\n readonly #listeners = new Map<string, Set<(delta: ClaudeSidecarNotification) => void>>()\n /** Notifications published per session, so a reader can spot a hole. */\n readonly #seq = new Map<string, number>()\n /** Streaming transcript segments not yet persisted, keyed by activity key. */\n readonly #live = new Map<string, Map<string, ClaudeActivityEvent>>()\n /** Monotonic revision boost so merged reads advance while text stays in memory. */\n readonly #boost = new Map<string, number>()\n readonly #flushTimers = new Map<string, ReturnType<typeof setTimeout>>()\n\n constructor(options: ClaudeSidecarRepositoryOptions = {}) {\n this.root = options.root ?? dshHomePath('plugins', 'dsh-claude', 'sessions')\n this.legacyRoot = options.legacyRoot\n ?? (options.root === undefined ? dshHomePath('plugins', 'dsh-claude-code', 'sessions') : undefined)\n }\n\n async read(sessionId: string): Promise<ClaudeSidecarProjection> {\n await this.#pending.get(sessionId)?.catch(() => undefined)\n return this.#merged(sessionId, await this.#base(sessionId))\n }\n\n /** Observe accepted changes for one session; returns the unsubscriber. */\n subscribe(sessionId: string, listener: (delta: ClaudeSidecarNotification) => void): () => void {\n let set = this.#listeners.get(sessionId)\n if (set === undefined) {\n set = new Set()\n this.#listeners.set(sessionId, set)\n }\n set.add(listener)\n return () => {\n set.delete(listener)\n if (set.size === 0) this.#listeners.delete(sessionId)\n }\n }\n\n /** Record streaming assistant prose without touching the disk on the hot\n * path: subscribers are notified synchronously (as an append when the\n * redacted text grows in place) and persistence is coalesced. */\n appendTranscriptText(\n sessionId: string,\n value: { turn: number; step: number; ordinal: number; text: string; renderer?: ClaudeRenderMode },\n ): void {\n const normalized = normalizeActivity({ kind: 'text', phase: 'updated', ...value })\n const key = activityKey(normalized)\n let overlay = this.#live.get(sessionId)\n if (overlay === undefined) {\n overlay = new Map()\n this.#live.set(sessionId, overlay)\n }\n const previous = overlay.get(key)\n overlay.set(key, normalized)\n this.#boost.set(sessionId, (this.#boost.get(sessionId) ?? 0) + 1)\n const text = normalized.text ?? ''\n const base = {\n turn: normalized.turn,\n step: normalized.step,\n ordinal: normalized.ordinal,\n ...(normalized.renderer === undefined ? {} : { renderer: normalized.renderer }),\n }\n // Redaction may rewrite earlier characters once a secret completes, so a\n // non-prefix update falls back to a full-text replacement.\n this.#notify(sessionId, previous?.text !== undefined && text.startsWith(previous.text)\n ? { kind: 'text', ...base, append: text.slice(previous.text.length) }\n : { kind: 'text', ...base, text })\n this.#scheduleTextFlush(sessionId)\n }\n\n /** Persist any pending streaming transcript now (segment close, turn end). */\n flushTranscriptText(sessionId: string): Promise<void> {\n const timer = this.#flushTimers.get(sessionId)\n if (timer !== undefined) {\n clearTimeout(timer)\n this.#flushTimers.delete(sessionId)\n }\n return this.#flushLive(sessionId)\n }\n\n /** How many notifications this session has published. */\n sequence(sessionId: string): number {\n return this.#seq.get(sessionId) ?? 0\n }\n\n /** Restate where the stream stands without changing anything.\n *\n * A reader detects a lost delta from the hole the NEXT one leaves, which\n * never comes when the lost delta was the last of a turn -- exactly the\n * case that leaves a finished tool group pulsing forever. Called at turn\n * settlement, this gives that reader the one line it needs to disagree. */\n checkpoint(sessionId: string): void {\n this.#deliver(sessionId, { kind: 'checkpoint', seq: this.sequence(sessionId) })\n }\n\n #notify(sessionId: string, delta: ClaudeSidecarDelta): void {\n const seq = this.sequence(sessionId) + 1\n this.#seq.set(sessionId, seq)\n this.#deliver(sessionId, { ...delta, seq } as ClaudeSidecarNotification)\n }\n\n #deliver(sessionId: string, notification: ClaudeSidecarNotification): void {\n const set = this.#listeners.get(sessionId)\n if (set === undefined) return\n for (const listener of [...set]) {\n try {\n listener(notification)\n } catch {\n // A subscriber failure must never affect durable state.\n }\n }\n }\n\n #merged(sessionId: string, base: ClaudeSidecarProjection): ClaudeSidecarProjection {\n const overlay = this.#live.get(sessionId)\n const boost = this.#boost.get(sessionId) ?? 0\n if ((overlay === undefined || overlay.size === 0) && boost === 0) return base\n return {\n ...base,\n revision: base.revision + boost,\n ...(overlay === undefined || overlay.size === 0\n ? {}\n : { activities: mergeActivities(base.activities, [...overlay.values()]) }),\n }\n }\n\n async #base(sessionId: string): Promise<ClaudeSidecarProjection> {\n const cached = this.#latest.get(sessionId)\n if (cached !== undefined) return cached\n const loaded = await this.#readNow(sessionId)\n this.#latest.set(sessionId, loaded)\n return loaded\n }\n\n #scheduleTextFlush(sessionId: string): void {\n if (this.#flushTimers.has(sessionId)) return\n const timer = setTimeout(() => {\n this.#flushTimers.delete(sessionId)\n void this.#flushLive(sessionId)\n }, TEXT_FLUSH_MS)\n timer.unref?.()\n this.#flushTimers.set(sessionId, timer)\n }\n\n async #flushLive(sessionId: string): Promise<void> {\n const overlay = this.#live.get(sessionId)\n if (overlay === undefined || overlay.size === 0) return\n const entries = [...overlay.entries()]\n try {\n await this.#update(sessionId, current => ({\n ...current,\n activities: mergeActivities(current.activities, entries.map(([, value]) => value)),\n }))\n } catch {\n // Keep the overlay; the next append or flush retries persistence.\n return\n }\n for (const [key, value] of entries) {\n if (overlay.get(key) === value) overlay.delete(key)\n }\n if (overlay.size === 0) this.#live.delete(sessionId)\n }\n\n writeBinding(\n sessionId: string,\n value: Omit<ClaudeSessionBoundEvent, 'sdkVersion'> & { sdkVersion?: string },\n ): Promise<ClaudeSidecarProjection> {\n const normalized = normalizeBinding(value)\n return this.#update(sessionId, current => ({ ...current, binding: normalized }))\n }\n\n appendActivity(\n sessionId: string,\n value: ClaudeActivityInput & { turn: number; step: number; ordinal: number },\n ): Promise<ClaudeSidecarProjection> {\n const normalized = normalizeActivity(value)\n return this.#update(sessionId, current => ({\n ...current,\n activities: mergeActivities(current.activities, [normalized]),\n }), false, { kind: 'activity', activity: normalized })\n }\n\n writeContextUsage(sessionId: string, value: ClaudeContextUsageInput): Promise<ClaudeSidecarProjection> {\n const normalized = normalizeContextUsage(value)\n return this.#update(sessionId, current => ({ ...current, contextUsage: normalized }), false, { kind: 'contextUsage', value: normalized })\n }\n\n writeTasks(sessionId: string, value: readonly ClaudeTaskInfo[]): Promise<ClaudeSidecarProjection> {\n const normalized = normalizeTasksEvent(value)\n return this.#update(sessionId, current => ({ ...current, tasks: normalized }), false, { kind: 'tasks', value: normalized })\n }\n\n /** Land one planned rewind: hidden ranges, surviving anchors, and the fork\n * target the next Claude spawn consumes. */\n writeRewind(sessionId: string, value: ClaudeRewindState): Promise<ClaudeSidecarProjection> {\n return this.#update(sessionId, current => ({ ...current, rewind: value }), false, { kind: 'sync' })\n }\n\n /** Remember where Claude's chain ended for one completed DSH turn. */\n recordRewindAnchor(sessionId: string, turn: number, uuid: string): Promise<ClaudeSidecarProjection> {\n return this.#update(sessionId, current => ({\n ...current,\n rewind: recordRewindAnchor(current.rewind ?? EMPTY_REWIND_STATE, { turn, uuid }),\n }))\n }\n\n /** Disarm the fork target once a Claude process has resumed at it, so a\n * later respawn continues the rewound session instead of re-truncating it. */\n clearRewindPending(sessionId: string): Promise<ClaudeSidecarProjection> {\n return this.#update(sessionId, current => (current.rewind?.pending === undefined ? current : {\n ...current,\n rewind: { ranges: current.rewind.ranges, anchors: current.rewind.anchors },\n }))\n }\n\n importLegacy(sessionId: string, events: readonly SessionEvent[]): Promise<ClaudeSidecarProjection> {\n const importedActivities = events\n .filter(event => event.type === CLAUDE_ACTIVITY_EVENT)\n .map(event => activity(event.data))\n .filter((item): item is ClaudeActivityEvent => item !== undefined)\n const importedBinding = latestClaudeSessionBinding(events)\n const importedUsage = latestClaudeContextUsage(events)\n const importedTasks = latestClaudeTasks(events)\n return this.#update(sessionId, current => ({\n ...current,\n activities: mergeActivities(importedActivities, current.activities),\n ...(current.binding !== undefined || importedBinding === undefined ? {} : { binding: normalizeBinding(importedBinding) }),\n ...(current.contextUsage !== undefined || importedUsage === undefined ? {} : { contextUsage: normalizeContextUsage(importedUsage) }),\n ...(current.tasks !== undefined || importedTasks === undefined ? {} : { tasks: normalizeTasksEvent(importedTasks.tasks) }),\n }), true, { kind: 'sync' })\n }\n\n #path(sessionId: string, root = this.root): string {\n if (sessionId.length === 0 || sessionId.length > 1_024) throw new Error('dsh-claude: invalid session id')\n return join(root, `${Buffer.from(sessionId).toString('base64url')}.json`)\n }\n\n #update(\n sessionId: string,\n change: (current: ClaudeSidecarProjection) => Omit<ClaudeSidecarProjection, 'revision' | 'schemaVersion'> & Partial<Pick<ClaudeSidecarProjection, 'revision' | 'schemaVersion'>>,\n skipUnchanged = false,\n delta?: ClaudeSidecarDelta,\n ): Promise<ClaudeSidecarProjection> {\n const previous = this.#pending.get(sessionId) ?? Promise.resolve()\n const operation = previous.catch(() => undefined).then(async () => {\n const current = await this.#base(sessionId)\n const changed = parseClaudeSidecar({\n ...change(current),\n schemaVersion: SIDECAR_SCHEMA_VERSION,\n revision: current.revision,\n })\n if (skipUnchanged && JSON.stringify(changed) === JSON.stringify(current)) return current\n const next = { ...changed, revision: current.revision + 1 }\n await this.#writeNow(sessionId, next)\n this.#latest.set(sessionId, next)\n if (delta !== undefined) this.#notify(sessionId, delta)\n return next\n })\n this.#pending.set(sessionId, operation)\n void operation.finally(() => {\n if (this.#pending.get(sessionId) === operation) this.#pending.delete(sessionId)\n }).catch(() => undefined)\n return operation\n }\n\n async #readNow(sessionId: string): Promise<ClaudeSidecarProjection> {\n try {\n return parseClaudeSidecar(JSON.parse(await readFile(this.#path(sessionId), 'utf8')))\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error\n }\n if (this.legacyRoot === undefined) return emptyProjection()\n try {\n return parseClaudeSidecar(JSON.parse(await readFile(this.#path(sessionId, this.legacyRoot), 'utf8')))\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') return emptyProjection()\n throw error\n }\n }\n\n async #writeNow(sessionId: string, projection: ClaudeSidecarProjection): Promise<void> {\n await mkdir(this.root, { recursive: true, mode: 0o700 })\n await chmod(this.root, 0o700)\n const target = this.#path(sessionId)\n const temporary = `${target}.${process.pid}.${randomUUID()}.tmp`\n try {\n await writeFile(temporary, `${JSON.stringify(projection)}\\n`, { mode: 0o600, flag: 'wx' })\n await chmod(temporary, 0o600)\n await rename(temporary, target)\n await chmod(target, 0o600)\n } finally {\n await rm(temporary, { force: true }).catch(() => undefined)\n }\n }\n}\n","export class AsyncQueueClosedError extends Error {\n constructor() {\n super('Async queue is closed')\n this.name = 'AsyncQueueClosedError'\n }\n}\n\ninterface Pending<T> {\n resolve: (result: IteratorResult<T>) => void\n reject: (error: unknown) => void\n}\n\nexport class AsyncQueue<T> implements AsyncIterable<T>, AsyncIterator<T> {\n readonly #values: T[] = []\n readonly #pending: Pending<T>[] = []\n #closed = false\n #failure: unknown\n\n get closed(): boolean {\n return this.#closed\n }\n\n push(value: T): void {\n if (this.#closed) throw new AsyncQueueClosedError()\n const waiter = this.#pending.shift()\n if (waiter !== undefined) waiter.resolve({ value, done: false })\n else this.#values.push(value)\n }\n\n close(): void {\n if (this.#closed) return\n this.#closed = true\n for (const waiter of this.#pending.splice(0)) waiter.resolve({ value: undefined, done: true })\n }\n\n fail(error: unknown): void {\n if (this.#closed) return\n this.#closed = true\n this.#failure = error\n for (const waiter of this.#pending.splice(0)) waiter.reject(error)\n }\n\n discard(error?: unknown): void {\n this.#values.splice(0)\n if (this.#closed) return\n this.#closed = true\n if (error === undefined) {\n for (const waiter of this.#pending.splice(0)) waiter.resolve({ value: undefined, done: true })\n return\n }\n this.#failure = error\n for (const waiter of this.#pending.splice(0)) waiter.resolve({ value: undefined, done: true })\n }\n\n next(): Promise<IteratorResult<T>> {\n const value = this.#values.shift()\n if (value !== undefined) return Promise.resolve({ value, done: false })\n if (this.#closed) {\n return this.#failure === undefined\n ? Promise.resolve({ value: undefined, done: true })\n : Promise.reject(this.#failure)\n }\n return new Promise<IteratorResult<T>>((resolve, reject) => {\n this.#pending.push({ resolve, reject })\n })\n }\n\n return(): Promise<IteratorResult<T>> {\n this.close()\n return Promise.resolve({ value: undefined, done: true })\n }\n\n [Symbol.asyncIterator](): AsyncIterator<T> {\n return this\n }\n}\n","import type { CanUseTool, PermissionResult } from '@anthropic-ai/claude-agent-sdk'\nimport type { Agent } from '@deepseek-ai/dsh-agent'\nimport type { ApprovalOutcome, ApprovalService } from '@deepseek-ai/dsh-user-approval'\nimport {\n boundText,\n safeDetail,\n type ClaudeActivityInput,\n type ClaudeActivityCursor,\n} from './events.ts'\nimport type { UserQuestionBridge } from './user-question.ts'\n\nexport type ApprovalRequester = Pick<ApprovalService, 'request'>\n\nexport interface ActivePermissionContext {\n agent: Agent\n cursor: ClaudeActivityCursor\n markActivity?: () => void\n recordDenial?: (toolUseId: string) => void\n hasFullAccess?: () => Promise<boolean>\n appendActivity: (activity: ClaudeActivityInput) => Promise<void>\n}\n\nexport type ActivePermissionContextProvider = () => ActivePermissionContext | undefined\n\nfunction denialMessage(outcome: ApprovalOutcome): string {\n switch (outcome) {\n case 'rejected': return 'The user rejected this action in DeepSeek Harness.'\n case 'cancelled': return 'The permission request was cancelled in DeepSeek Harness.'\n case 'unavailable': return 'No DeepSeek Harness approval surface was available; the action was denied.'\n case 'allowed-once': return ''\n }\n}\n\nexport function permissionReason(\n toolName: string,\n input: Readonly<Record<string, unknown>>,\n options: Parameters<CanUseTool>[2],\n): string {\n const prompt = options.title ?? options.description ?? options.decisionReason ?? `Claude Code wants to use ${toolName}.`\n const detail = safeDetail(input)\n return boundText(detail === undefined ? prompt : `${prompt}\\nInput: ${detail}`, 1_200)\n}\n\nexport function mapApprovalOutcome(\n outcome: ApprovalOutcome,\n input: Record<string, unknown>,\n toolUseID: string,\n): PermissionResult {\n if (outcome === 'allowed-once') {\n return {\n behavior: 'allow',\n updatedInput: input,\n toolUseID,\n decisionClassification: 'user_temporary',\n }\n }\n return {\n behavior: 'deny',\n message: denialMessage(outcome),\n toolUseID,\n decisionClassification: 'user_reject',\n }\n}\n\nexport function createPermissionBridge(\n approval: ApprovalRequester,\n activeContext: ActivePermissionContextProvider,\n userQuestion?: UserQuestionBridge,\n): CanUseTool {\n return async (toolName, input, options) => {\n if (toolName === 'AskUserQuestion') {\n return userQuestion === undefined\n ? {\n behavior: 'deny',\n message: 'DeepSeek Harness user questions are unavailable; the question was cancelled.',\n toolUseID: options.toolUseID,\n decisionClassification: 'user_reject',\n }\n : userQuestion(input, options)\n }\n const active = activeContext()\n if (active === undefined) {\n return {\n behavior: 'deny',\n message: 'No active DeepSeek Harness turn owns this Claude Code action.',\n toolUseID: options.toolUseID,\n decisionClassification: 'user_reject',\n }\n }\n\n active.markActivity?.()\n const reason = permissionReason(toolName, input, options)\n try {\n await active.appendActivity({\n kind: 'permission',\n phase: 'started',\n toolUseId: options.toolUseID,\n toolName,\n title: options.displayName ?? toolName,\n summary: options.title ?? options.description ?? reason,\n detail: input,\n })\n const alreadyFullAccess = await active.hasFullAccess?.() === true\n const outcome = alreadyFullAccess\n ? 'allowed-once'\n : await approval.request({\n agent: active.agent,\n toolName,\n reason,\n signal: options.signal,\n })\n // The access selector can change while the approval UI is open. Re-read\n // its durable state so an explicit Full access choice wins over the stale\n // request being closed as rejected/cancelled by that mode transition.\n const fullAccess = alreadyFullAccess || await active.hasFullAccess?.() === true\n const effectiveOutcome = fullAccess ? 'allowed-once' : outcome\n const result = mapApprovalOutcome(effectiveOutcome, input, options.toolUseID)\n if (result.behavior === 'deny') active.recordDenial?.(options.toolUseID)\n await active.appendActivity({\n kind: 'permission',\n phase: effectiveOutcome === 'allowed-once' ? 'completed' : 'denied',\n toolUseId: options.toolUseID,\n toolName,\n title: options.displayName ?? toolName,\n summary: fullAccess\n ? 'Allowed by Full access in DeepSeek Harness'\n : effectiveOutcome === 'allowed-once'\n ? 'Allowed once in DeepSeek Harness'\n : denialMessage(effectiveOutcome),\n })\n return result\n } catch (error) {\n const message = options.signal.aborted\n ? 'The permission request was cancelled in DeepSeek Harness.'\n : 'DeepSeek Harness could not record or answer the permission request; the action was denied.'\n try {\n await active.appendActivity({\n kind: 'permission',\n phase: 'failed',\n toolUseId: options.toolUseID,\n toolName,\n title: options.displayName ?? toolName,\n summary: message,\n isError: true,\n detail: error,\n })\n } catch {\n // The permission path is already fail-closed; a second audit failure cannot widen it.\n }\n return {\n behavior: 'deny',\n message,\n toolUseID: options.toolUseID,\n decisionClassification: 'user_reject',\n }\n }\n }\n}\n","import type { CanUseTool, PermissionResult } from '@anthropic-ai/claude-agent-sdk'\nimport type { Agent } from '@deepseek-ai/dsh-agent'\nimport type {\n AskUserQuestionAnswerItem,\n AskUserQuestionItem,\n UserQuestionService,\n} from '@deepseek-ai/dsh-user-questions'\nimport type { ClaudeActivityInput, ClaudeActivityCursor } from './events.ts'\n\nexport type UserQuestionRequester = Pick<UserQuestionService, 'ask'>\n\nexport interface ActiveUserQuestionContext {\n agent: Agent\n cursor: ClaudeActivityCursor\n markActivity?: () => void\n appendActivity: (activity: ClaudeActivityInput) => Promise<void>\n}\n\nexport type ActiveUserQuestionContextProvider = () => ActiveUserQuestionContext | undefined\nexport type UserQuestionBridge = (\n input: Record<string, unknown>,\n options: Parameters<CanUseTool>[2],\n) => Promise<PermissionResult>\n\nconst FAILURE_MESSAGE = 'DeepSeek Harness could not collect an answer; the question was cancelled.'\nconst INVALID_MESSAGE = 'Claude Code sent an invalid user-question request; the question was cancelled.'\n\nfunction failureMessage(error: unknown): string {\n const code = error !== null && typeof error === 'object' && 'code' in error\n ? (error as { code?: unknown }).code\n : undefined\n return typeof code === 'string' && /^[A-Z][A-Z0-9_]*$/.test(code)\n ? `${FAILURE_MESSAGE} (${code})`\n : FAILURE_MESSAGE\n}\n\nfunction deny(message: string, toolUseID: string): PermissionResult {\n return {\n behavior: 'deny',\n message,\n toolUseID,\n decisionClassification: 'user_reject',\n }\n}\n\nfunction optionalText(value: unknown): string | undefined {\n return typeof value === 'string' && value.length > 0 ? value : undefined\n}\n\nfunction parseQuestions(input: Record<string, unknown>, toolUseID: string): AskUserQuestionItem[] | undefined {\n if (!Array.isArray(input.questions) || input.questions.length === 0 || input.questions.length > 20) return undefined\n const seen = new Set<string>()\n const questions: AskUserQuestionItem[] = []\n for (const [index, value] of input.questions.entries()) {\n if (value === null || typeof value !== 'object' || Array.isArray(value)) return undefined\n const item = value as Record<string, unknown>\n if (typeof item.question !== 'string' || item.question.length === 0 || seen.has(item.question)) return undefined\n seen.add(item.question)\n if (item.options !== undefined && !Array.isArray(item.options)) return undefined\n const options = (item.options ?? []).map(option => {\n if (option === null || typeof option !== 'object' || Array.isArray(option)) return undefined\n const record = option as Record<string, unknown>\n if (typeof record.label !== 'string' || record.label.length === 0) return undefined\n const description = optionalText(record.description)\n return { label: record.label, ...(description === undefined ? {} : { description }) }\n })\n if (options.some(option => option === undefined)) return undefined\n const header = optionalText(item.header)\n questions.push({\n id: `${toolUseID}:${index}`,\n question: item.question,\n ...(header === undefined ? {} : { header }),\n options: options as NonNullable<AskUserQuestionItem['options']>,\n multiSelect: item.multiSelect === true,\n })\n }\n return questions\n}\n\nfunction answerText(answer: AskUserQuestionAnswerItem | undefined, multiSelect: boolean): string {\n if (answer === undefined) return ''\n const custom = optionalText(answer.custom)\n if (!multiSelect && custom !== undefined) return custom\n return [...answer.selected, ...(custom === undefined ? [] : [custom])].join(', ')\n}\n\nexport function createUserQuestionBridge(\n userQuestions: UserQuestionRequester,\n activeContext: ActiveUserQuestionContextProvider,\n): UserQuestionBridge {\n return async (input, options) => {\n const active = activeContext()\n if (active === undefined) return deny('No active DeepSeek Harness turn owns this Claude Code question.', options.toolUseID)\n\n const questions = parseQuestions(input, options.toolUseID)\n if (questions === undefined) return deny(INVALID_MESSAGE, options.toolUseID)\n\n active.markActivity?.()\n try {\n await active.appendActivity({\n kind: 'question',\n phase: 'started',\n toolUseId: options.toolUseID,\n toolName: 'AskUserQuestion',\n title: 'Claude asked a question',\n summary: questions.length === 1 ? questions[0]!.question : `Claude asked ${questions.length} questions`,\n })\n const response = await userQuestions.ask({\n questions,\n agent: active.agent,\n signal: options.signal,\n })\n const answersById = new Map(response.answers.map(answer => [answer.id, answer]))\n const answers = Object.fromEntries(questions.map(question => [\n question.question,\n answerText(answersById.get(question.id), question.multiSelect === true),\n ]))\n await active.appendActivity({\n kind: 'question',\n phase: 'completed',\n toolUseId: options.toolUseID,\n toolName: 'AskUserQuestion',\n title: 'Claude asked a question',\n summary: 'Answered in DeepSeek Harness',\n })\n return {\n behavior: 'allow',\n updatedInput: { ...input, answers },\n toolUseID: options.toolUseID,\n decisionClassification: 'user_temporary',\n }\n } catch (error) {\n const message = failureMessage(error)\n try {\n await active.appendActivity({\n kind: 'question',\n phase: 'failed',\n toolUseId: options.toolUseID,\n toolName: 'AskUserQuestion',\n title: 'Claude asked a question',\n summary: message,\n isError: true,\n })\n } catch {\n // The question path is fail-closed; a second audit failure cannot widen it.\n }\n return deny(message, options.toolUseID)\n }\n }\n}\n","import type { SDKMessage } from '@anthropic-ai/claude-agent-sdk'\nimport type { ClaudeUsage } from './events.ts'\n\nexport type NormalizedSdkMessage =\n | { kind: 'init'; sessionId: string; cliVersion: string; cwd: string }\n | { kind: 'text-delta'; text: string; parentToolUseId?: string }\n | { kind: 'assistant-text'; text: string; parentToolUseId?: string }\n | { kind: 'thinking'; text: string; phase: 'updated' | 'completed'; parentToolUseId?: string }\n | { kind: 'tool-call'; toolUseId: string; toolName: string; input: unknown; parentToolUseId?: string }\n | { kind: 'tool-result'; toolUseId: string; output: unknown; isError: boolean; parentToolUseId?: string }\n | {\n kind: 'subagent'\n title: string\n summary?: string\n detail?: unknown\n phase: 'started' | 'updated' | 'completed' | 'failed'\n /** Structured task-board fields for task_started/progress/updated/notification. */\n taskId?: string\n taskStatus?: 'running' | 'completed' | 'failed' | 'stopped' | 'killed'\n description?: string\n subagentType?: string\n taskType?: string\n lastToolName?: string\n usage?: { totalTokens?: number; toolUses?: number; durationMs?: number }\n /** Ambient/housekeeping task: hide from chat rows, keep on the task board. */\n skipTranscript?: boolean\n }\n | {\n /** Level signal: full live background-task set (REPLACE semantics). */\n kind: 'background-tasks'\n tasks: readonly { taskId: string; taskType?: string; description: string }[]\n }\n | {\n /** Context compaction boundary. The CLI compacts locally without running a\n * model turn, so this is the only evidence the conversation was rewritten;\n * `trigger` stays absent when the CLI does not name one. */\n kind: 'compaction'\n trigger?: 'manual' | 'auto'\n preTokens?: number\n postTokens?: number\n durationMs?: number\n }\n | {\n /** Prompt-side accounting for ONE provider call, read off an assistant\n * message. Distinct from the `result` usage, which sums every call the\n * turn made — see `ClaudeSupervisor#reportedUsage`. */\n kind: 'request-usage'\n usage: ClaudeUsage\n parentToolUseId?: string\n }\n | { kind: 'status'; title: string; summary?: string; detail?: unknown }\n | { kind: 'warning'; title: string; summary?: string; detail?: unknown }\n | { kind: 'permission-denied'; toolUseId: string; toolName: string; summary: string }\n | { kind: 'result'; success: boolean; text?: string; errors?: readonly string[]; usage: ClaudeUsage; sessionId: string; userMessageUuid?: string; terminalReason?: string; permissionDenials?: readonly { toolName: string; toolUseId: string }[] }\n | { kind: 'protocol-error'; title: string; detail: unknown }\n | { kind: 'unknown'; title: string; detail: unknown }\n\nfunction record(value: unknown): Record<string, unknown> | undefined {\n return value !== null && typeof value === 'object' ? value as Record<string, unknown> : undefined\n}\n\nfunction string(value: unknown): string | undefined {\n return typeof value === 'string' ? value : undefined\n}\n\nfunction finiteNumber(value: unknown): number | undefined {\n return typeof value === 'number' && Number.isFinite(value) ? value : undefined\n}\n\nfunction contentText(content: unknown): string {\n if (typeof content === 'string') return content\n if (!Array.isArray(content)) return ''\n return content.map(item => {\n const block = record(item)\n if (block?.type === 'text') return string(block.text) ?? ''\n return ''\n }).join('')\n}\n\nfunction taskUsageOf(usage: Record<string, unknown> | undefined): { totalTokens?: number; toolUses?: number; durationMs?: number } | undefined {\n if (usage === undefined) return undefined\n const normalized: { totalTokens?: number; toolUses?: number; durationMs?: number } = {}\n if (typeof usage.total_tokens === 'number') normalized.totalTokens = usage.total_tokens\n if (typeof usage.tool_uses === 'number') normalized.toolUses = usage.tool_uses\n if (typeof usage.duration_ms === 'number') normalized.durationMs = usage.duration_ms\n return Object.keys(normalized).length === 0 ? undefined : normalized\n}\n\n/** Read one Anthropic `usage` envelope. Shared by the per-call sample on an\n * assistant message and the turn total on a result message. */\nfunction usageOf(usage: Record<string, unknown> | undefined): ClaudeUsage {\n const normalized: ClaudeUsage = {}\n if (usage === undefined) return normalized\n if (typeof usage.input_tokens === 'number') normalized.inputTokens = usage.input_tokens\n if (typeof usage.output_tokens === 'number') normalized.outputTokens = usage.output_tokens\n if (typeof usage.cache_read_input_tokens === 'number') normalized.cacheReadTokens = usage.cache_read_input_tokens\n if (typeof usage.cache_creation_input_tokens === 'number') normalized.cacheCreationTokens = usage.cache_creation_input_tokens\n return normalized\n}\n\nfunction hasUsageCounts(usage: ClaudeUsage): boolean {\n return usage.inputTokens !== undefined\n || usage.outputTokens !== undefined\n || usage.cacheReadTokens !== undefined\n || usage.cacheCreationTokens !== undefined\n}\n\nfunction resultUsage(message: Record<string, unknown>): ClaudeUsage {\n const normalized = usageOf(record(message.usage))\n if (typeof message.total_cost_usd === 'number') normalized.cumulativeCostUsd = message.total_cost_usd\n return normalized\n}\n\nfunction normalizeAssistant(message: Record<string, unknown>): NormalizedSdkMessage[] {\n const envelope = record(message.message)\n const content = envelope?.content\n if (!Array.isArray(content)) return [{ kind: 'protocol-error', title: 'Malformed Claude assistant message', detail: message }]\n const parentToolUseId = string(message.parent_tool_use_id)\n const normalized: NormalizedSdkMessage[] = []\n for (const item of content) {\n const block = record(item)\n if (block === undefined) continue\n if (block.type === 'text') {\n const text = string(block.text)\n if (text !== undefined && text.length > 0) normalized.push({ kind: 'assistant-text', text, ...(parentToolUseId === undefined ? {} : { parentToolUseId }) })\n } else if (block.type === 'thinking') {\n const text = string(block.thinking)\n if (text !== undefined && text.length > 0) normalized.push({ kind: 'thinking', text, phase: 'completed', ...(parentToolUseId === undefined ? {} : { parentToolUseId }) })\n } else if (block.type === 'tool_use') {\n const toolUseId = string(block.id)\n const toolName = string(block.name)\n if (toolUseId !== undefined && toolName !== undefined) {\n normalized.push({\n kind: 'tool-call',\n toolUseId,\n toolName,\n input: block.input,\n ...(parentToolUseId === undefined ? {} : { parentToolUseId }),\n })\n }\n }\n }\n const usage = usageOf(record(envelope?.usage))\n if (hasUsageCounts(usage)) {\n normalized.push({ kind: 'request-usage', usage, ...(parentToolUseId === undefined ? {} : { parentToolUseId }) })\n }\n return normalized\n}\n\nfunction normalizeUser(message: Record<string, unknown>): NormalizedSdkMessage[] {\n // CLI ≥ 2.1.238 replays prior user messages (including local-command output\n // echoes with plain string content) when resuming a session. Replays and\n // block-less string echoes carry no tool results; they are not protocol\n // failures and must never kill the session.\n if (message.isReplay === true) return []\n const envelope = record(message.message)\n const content = envelope?.content\n if (typeof content === 'string') return []\n if (!Array.isArray(content)) return [{ kind: 'protocol-error', title: 'Malformed Claude user message', detail: message }]\n const parentToolUseId = string(message.parent_tool_use_id)\n const normalized: NormalizedSdkMessage[] = []\n for (const item of content) {\n const block = record(item)\n if (block?.type !== 'tool_result') continue\n const toolUseId = string(block.tool_use_id)\n if (toolUseId === undefined) continue\n normalized.push({\n kind: 'tool-result',\n toolUseId,\n output: message.tool_use_result ?? block.content,\n isError: block.is_error === true,\n ...(parentToolUseId === undefined ? {} : { parentToolUseId }),\n })\n }\n return normalized\n}\n\nfunction normalizeSystem(message: Record<string, unknown>): NormalizedSdkMessage[] {\n const subtype = string(message.subtype)\n if (subtype === 'init') {\n const sessionId = string(message.session_id)\n const cliVersion = string(message.claude_code_version)\n const cwd = string(message.cwd)\n return sessionId !== undefined && cliVersion !== undefined && cwd !== undefined\n ? [{ kind: 'init', sessionId, cliVersion, cwd }]\n : [{ kind: 'protocol-error', title: 'Malformed Claude initialization message', detail: message }]\n }\n if (subtype === 'status') {\n const status = message.status\n if (status === null) return [{ kind: 'status', title: 'Claude Code is ready' }]\n return [{ kind: 'status', title: `Claude Code ${String(status)}`, detail: message }]\n }\n if (subtype === 'session_state_changed') {\n return [{ kind: 'status', title: `Claude session ${String(message.state)}` }]\n }\n if (subtype === 'permission_denied') {\n const toolUseId = string(message.tool_use_id)\n const toolName = string(message.tool_name)\n if (toolUseId !== undefined && toolName !== undefined) {\n return [{\n kind: 'permission-denied',\n toolUseId,\n toolName,\n summary: string(message.message) ?? 'Claude Code denied the action',\n }]\n }\n }\n if (subtype === 'task_started') {\n const taskId = string(message.task_id)\n const description = string(message.description)\n const subagentType = string(message.subagent_type)\n const taskType = string(message.task_type)\n return [{\n kind: 'subagent',\n title: description ?? taskId ?? 'Claude subagent started',\n phase: 'started',\n detail: message,\n ...(taskId === undefined ? {} : { taskId }),\n taskStatus: 'running' as const,\n ...(description === undefined ? {} : { description }),\n ...(subagentType === undefined ? {} : { subagentType }),\n ...(taskType === undefined ? {} : { taskType }),\n ...(message.skip_transcript === true ? { skipTranscript: true } : {}),\n }]\n }\n if (subtype === 'task_progress') {\n const taskId = string(message.task_id)\n const description = string(message.description)\n const summary = string(message.summary)\n const subagentType = string(message.subagent_type)\n const lastToolName = string(message.last_tool_name)\n const usage = taskUsageOf(record(message.usage))\n return [{\n kind: 'subagent',\n title: summary ?? description ?? 'Claude subagent update',\n phase: 'updated',\n detail: message,\n ...(taskId === undefined ? {} : { taskId }),\n taskStatus: 'running' as const,\n ...(description === undefined ? {} : { description }),\n ...(subagentType === undefined ? {} : { subagentType }),\n ...(lastToolName === undefined ? {} : { lastToolName }),\n ...(summary === undefined ? {} : { summary }),\n ...(usage === undefined ? {} : { usage }),\n }]\n }\n if (subtype === 'task_updated') {\n const patch = record(message.patch)\n const status = string(patch?.status)\n const taskId = string(message.task_id)\n const description = string(patch?.description)\n const error = string(patch?.error)\n const taskStatus = status === undefined\n ? undefined\n : status === 'killed'\n ? 'killed' as const\n : status === 'completed'\n ? 'completed' as const\n : status === 'failed'\n ? 'failed' as const\n : 'running' as const\n return [{\n kind: 'subagent',\n title: description ?? 'Claude subagent update',\n phase: status === 'failed' || status === 'killed' ? 'failed' : status === 'completed' ? 'completed' : 'updated',\n detail: message,\n ...(taskId === undefined ? {} : { taskId }),\n ...(taskStatus === undefined ? {} : { taskStatus }),\n ...(description === undefined ? {} : { description }),\n ...(error === undefined ? {} : { summary: error }),\n }]\n }\n if (subtype === 'task_notification') {\n const failed = message.status === 'failed'\n const stopped = message.status === 'stopped' || message.status === 'cancelled'\n const taskId = string(message.task_id)\n const summary = string(message.summary)\n const taskStatus = failed ? 'failed' as const : stopped ? 'stopped' as const : 'completed' as const\n const usage = taskUsageOf(record(message.usage))\n return [{\n kind: 'subagent',\n title: summary ?? taskId ?? 'Claude subagent finished',\n phase: failed || stopped ? 'failed' : 'completed',\n detail: message,\n ...(taskId === undefined ? {} : { taskId }),\n taskStatus,\n ...(summary === undefined ? {} : { summary }),\n ...(usage === undefined ? {} : { usage }),\n }]\n }\n if (subtype === 'background_tasks_changed') {\n const tasks = Array.isArray(message.tasks) ? message.tasks : []\n return [{\n kind: 'background-tasks',\n tasks: tasks.flatMap(item => {\n const entry = record(item)\n const taskId = string(entry?.task_id)\n const description = string(entry?.description)\n const taskType = string(entry?.task_type)\n if (taskId === undefined || description === undefined) return []\n return [{\n taskId,\n description,\n ...(taskType === undefined ? {} : { taskType }),\n }]\n }),\n }]\n }\n if (subtype === 'api_retry') {\n return [{ kind: 'warning', title: 'Claude API retry', detail: message }]\n }\n if (subtype === 'compact_boundary') {\n // `/compact` runs entirely inside the CLI: no assistant turn, and the\n // `Compacted` echo arrives as a block-less user message that\n // `normalizeUser` drops. Without this branch the boundary fell through to\n // the generic fallback below and became audit-only 'status', so a\n // compacted conversation showed nothing at all.\n const metadata = record(message.compact_metadata)\n const trigger = metadata?.trigger === 'auto' || metadata?.trigger === 'manual' ? metadata.trigger : undefined\n const preTokens = finiteNumber(metadata?.pre_tokens)\n const postTokens = finiteNumber(metadata?.post_tokens)\n const durationMs = finiteNumber(metadata?.duration_ms)\n return [{\n kind: 'compaction',\n ...(trigger === undefined ? {} : { trigger }),\n ...(preTokens === undefined ? {} : { preTokens }),\n ...(postTokens === undefined ? {} : { postTokens }),\n ...(durationMs === undefined ? {} : { durationMs }),\n }]\n }\n if (subtype === 'informational' || subtype === 'notification' || subtype === 'local_command_output') {\n return [{\n kind: message.level === 'warning' ? 'warning' : 'status',\n title: string(message.content) ?? string(message.text) ?? 'Claude Code notice',\n detail: message,\n }]\n }\n if (subtype?.startsWith('hook_') === true || subtype === 'plugin_install') {\n return [{ kind: 'status', title: `Claude Code ${subtype.replaceAll('_', ' ')}`, detail: message }]\n }\n if (subtype !== undefined) {\n // Preserve unknown system lifecycle evidence (background tasks, resets,\n // worker/mirror lifecycle) as a bounded activity instead of silently\n // dropping it; the activity layer redacts and bounds the detail.\n return [{ kind: 'status', title: `Claude Code ${subtype.replaceAll('_', ' ')}`, detail: message }]\n }\n return []\n}\n\nconst RESULT_ERROR_SUBTYPES = new Set([\n 'error_during_execution',\n 'error_max_turns',\n 'error_max_budget_usd',\n 'error_max_structured_output_retries',\n])\n\nexport function normalizeSdkMessage(message: SDKMessage): NormalizedSdkMessage[] {\n const value = message as unknown as Record<string, unknown>\n if (value.type === 'stream_event') {\n const event = record(value.event)\n const parentToolUseId = string(value.parent_tool_use_id)\n if (event?.type === 'content_block_delta') {\n const delta = record(event.delta)\n if (delta?.type === 'text_delta') {\n const text = string(delta.text)\n return text === undefined ? [] : [{ kind: 'text-delta', text, ...(parentToolUseId === undefined ? {} : { parentToolUseId }) }]\n }\n if (delta?.type === 'thinking_delta') {\n const text = string(delta.thinking)\n return text === undefined ? [] : [{ kind: 'thinking', text, phase: 'updated', ...(parentToolUseId === undefined ? {} : { parentToolUseId }) }]\n }\n }\n return []\n }\n if (value.type === 'assistant') return normalizeAssistant(value)\n if (value.type === 'user') return normalizeUser(value)\n if (value.type === 'system') return normalizeSystem(value)\n if (value.type === 'result') {\n const sessionId = string(value.session_id)\n if (sessionId === undefined || (value.subtype !== 'success' && !RESULT_ERROR_SUBTYPES.has(String(value.subtype)))) {\n return [{ kind: 'protocol-error', title: 'Malformed Claude result message', detail: value }]\n }\n // A result is a success only when it is not flagged as an error. Local\n // 2.1.233 emits subtype:\"success\" with is_error:true for API/auth failures\n // (e.g. terminal_reason:\"api_error\"), so subtype alone is not authoritative.\n const success = value.subtype === 'success' && value.is_error !== true\n const errors = Array.isArray(value.errors)\n ? value.errors.filter((item): item is string => typeof item === 'string')\n : undefined\n const terminalReason = string(value.terminal_reason)\n const userMessageUuid = string(value.user_message_uuid)\n const permissionDenials = Array.isArray(value.permission_denials)\n ? value.permission_denials\n .map(item => record(item))\n .filter((item): item is Record<string, unknown> => item !== undefined)\n .map(item => {\n const toolName = string(item.tool_name)\n const toolUseId = string(item.tool_use_id)\n return toolName === undefined || toolUseId === undefined ? undefined : { toolName, toolUseId }\n })\n .filter((item): item is { toolName: string; toolUseId: string } => item !== undefined)\n .slice(0, 40)\n : undefined\n return [{\n kind: 'result',\n success,\n ...(success && typeof value.result === 'string' ? { text: value.result } : {}),\n ...(errors === undefined ? {} : { errors }),\n ...(terminalReason === undefined ? {} : { terminalReason }),\n ...(permissionDenials === undefined || permissionDenials.length === 0 ? {} : { permissionDenials }),\n usage: resultUsage(value),\n sessionId,\n ...(userMessageUuid === undefined ? {} : { userMessageUuid }),\n }]\n }\n if (value.type === 'auth_status') {\n return [{\n kind: value.error === undefined ? 'status' : 'warning',\n title: value.error === undefined ? 'Claude authentication status changed' : 'Claude authentication failed',\n detail: value.error ?? value.output,\n }]\n }\n if (value.type === 'rate_limit_event') {\n // The CLI pushes subscription-quota status after API activity. Every\n // update stays audit-only ('status' never enters the conversation flow);\n // a blocking state surfaces through the repository status bar badge that\n // reads these titles from the projection instead.\n const info = record(value.rate_limit_info)\n const status = string(info?.status)\n const blocking = status !== undefined && status !== 'allowed'\n return [{\n kind: 'status',\n title: blocking ? 'Claude rate limit is blocking requests' : 'Claude rate limit status changed',\n detail: value.rate_limit_info,\n }]\n }\n return [{ kind: 'unknown', title: `Unknown Claude SDK message: ${String(value.type)}`, detail: value }]\n}\n\nexport function extractSdkContentText(content: unknown): string {\n return contentText(content)\n}\n","/** The Claude Code model lineup, read from the running CLI instead of pinned\n * here.\n *\n * Anthropic ships models between releases of this plugin -- Fable arrived in a\n * CLI update, not in one of ours -- so a table maintained here is stale the day\n * it is written, and a model the user can already pick in `/model` is missing\n * from the DSH selector until someone edits an array. The CLI answers the same\n * question itself: every session's initialize response carries the lineup it\n * would show in `/model`, already narrowed to the logged-in account's plan and\n * to any `availableModels` restriction the settings cascade imposes.\n */\nimport type { ModelInfo } from '@anthropic-ai/claude-agent-sdk'\n\n/** One selectable model, in the shape the adapter advertises to DSH. */\nexport interface ClaudeModelRow {\n readonly id: string\n readonly name: string\n readonly description: string\n readonly contextWindow?: number\n}\n\n/** What the selector shows before any session has initialized in this Host\n * process -- a fresh app launch lands here. `default` is the only id that is\n * valid on every release and plan; the aliases after it are the stable\n * `/model` spellings Claude Code has kept across releases, so the menu is\n * usable at first paint instead of a single row. The first initialize\n * response replaces the whole list with the CLI's own lineup. */\nconst SEED: readonly ClaudeModelRow[] = [\n { id: 'default', name: 'Default (recommended)', description: '' },\n { id: 'opus[1m]', name: 'Opus (1M context)', description: '', contextWindow: 1_000_000 },\n { id: 'fable', name: 'Fable', description: '' },\n { id: 'sonnet', name: 'Sonnet', description: '' },\n { id: 'haiku', name: 'Haiku', description: '' },\n]\n\n/** A 1M-context route spells it in the id (`opus[1m]`, `claude-fable-5[1m]`),\n * so this needs no capacity table either. It is only a floor: the supervisor\n * overrides it with the window the CLI reports once a turn has run. */\nfunction declaredContextWindow(row: ModelInfo): number | undefined {\n return /\\[1m\\]$/u.test(row.resolvedModel ?? row.value) ? 1_000_000 : undefined\n}\n\nfunction projectModel(row: ModelInfo): ClaudeModelRow {\n const contextWindow = declaredContextWindow(row)\n return {\n id: row.value,\n name: row.displayName,\n description: row.description,\n ...(contextWindow === undefined ? {} : { contextWindow }),\n }\n}\n\n// ponytail: a module-level latest-value cache, mirroring plan usage. The plugin\n// runs one supervisor per Host process and the lineup is account-wide, so\n// per-session state would buy nothing.\nlet latest: readonly ClaudeModelRow[] | undefined\n\n/**\n * Learn the lineup from one session's initialize response.\n * @param models - the CLI's own `/model` rows; an empty list is ignored so a\n * CLI that answers without a catalog cannot blank the selector.\n */\nexport function recordClaudeModels(models: readonly ModelInfo[]): void {\n if (models.length === 0) return\n latest = models.map(projectModel)\n}\n\n/** The lineup to advertise: whatever the CLI last reported, else the seed. */\nexport function latestClaudeModels(): readonly ClaudeModelRow[] {\n return latest ?? SEED\n}\n\n/**\n * Look one id up in the current lineup.\n * @param id - the id DSH persisted on the session, which may name a model the\n * running CLI no longer lists.\n * @returns the row, or undefined when the lineup does not cover the id.\n */\nexport function claudeModelRow(id: string): ClaudeModelRow | undefined {\n return latestClaudeModels().find(row => row.id === id)\n}\n\n/** Test seam: drop the learned lineup. */\nexport function resetClaudeModels(): void {\n latest = undefined\n}\n","/** Claude.ai plan rate-limit windows behind the CLI's `/usage` panel.\n *\n * The Agent SDK exposes them through an experimental query method whose name\n * advertises its own instability, so every read is guarded: a missing method,\n * a shape change, or an API-key session all degrade to `available: false`\n * instead of breaking the settings page. */\nimport { query as claudeQuery, type Options as ClaudeOptions, type Query, type SDKUserMessage } from '@anthropic-ai/claude-agent-sdk'\n\n/** The SDK's own name for the unstable `/usage` control request; it is\n * documented to change when the API stabilizes, so it lives in one place. */\nexport const PLAN_USAGE_METHOD = 'usage_EXPERIMENTAL_MAY_CHANGE_DO_NOT_RELY_ON_THIS_API_YET'\n\n/** A throwaway probe should not outlive a wedged control request. */\nexport const PLAN_USAGE_TIMEOUT_MS = 20_000\n\n/** Invoke the experimental usage control request, or say why we cannot. */\nexport function readPlanUsageFrom(query: Query): Promise<unknown> {\n const read = (query as Partial<Record<typeof PLAN_USAGE_METHOD, () => Promise<unknown>>>)[PLAN_USAGE_METHOD]\n if (typeof read !== 'function') throw new Error('dsh-claude: this Claude Agent SDK build exposes no plan usage API')\n return read.call(query)\n}\n\n/** One utilization window. `label` is only set for server-named model buckets\n * (e.g. 'Fable'); the fixed windows are translated client-side from `id`. */\nexport interface PlanUsageWindow {\n readonly id: string\n readonly label?: string\n readonly utilization?: number\n readonly resetsAt?: string\n}\n\nexport interface PlanUsageReport {\n readonly available: boolean\n readonly subscription?: string\n readonly windows: readonly PlanUsageWindow[]\n readonly fetchedAt: number\n readonly message?: string\n}\n\n/** Fixed windows in display order; the SDK omits the ones a plan does not have. */\nconst FIXED_WINDOWS = ['five_hour', 'seven_day', 'seven_day_opus', 'seven_day_sonnet'] as const\n\nfunction record(value: unknown): Record<string, unknown> | undefined {\n return typeof value === 'object' && value !== null && !Array.isArray(value) ? value as Record<string, unknown> : undefined\n}\n\n/** Utilization is documented as 0-100; clamp so a server glitch cannot render\n * a bar wider than its track or a negative width. */\nfunction utilization(value: unknown): number | undefined {\n return typeof value === 'number' && Number.isFinite(value) ? Math.min(100, Math.max(0, value)) : undefined\n}\n\nfunction resetsAt(value: unknown): string | undefined {\n return typeof value === 'string' && value.length > 0 ? value : undefined\n}\n\nfunction window(id: string, source: unknown, label?: string): PlanUsageWindow | undefined {\n const entry = record(source)\n if (entry === undefined) return undefined\n const used = utilization(entry.utilization)\n const reset = resetsAt(entry.resets_at)\n if (used === undefined && reset === undefined) return undefined\n return {\n id,\n ...(label === undefined ? {} : { label }),\n ...(used === undefined ? {} : { utilization: used }),\n ...(reset === undefined ? {} : { resetsAt: reset }),\n }\n}\n\n/** Project the SDK's `/usage` response onto the windows the settings card shows. */\nexport function normalizePlanUsage(value: unknown, fetchedAt: number): PlanUsageReport {\n const response = record(value)\n const subscription = typeof response?.subscription_type === 'string' ? response.subscription_type : undefined\n const limits = record(response?.rate_limits)\n if (response?.rate_limits_available !== true || limits === undefined) {\n return {\n available: false,\n ...(subscription === undefined ? {} : { subscription }),\n windows: [],\n fetchedAt,\n }\n }\n const windows = [\n ...FIXED_WINDOWS.map(id => window(id, limits[id])),\n ...(Array.isArray(limits.model_scoped) ? limits.model_scoped : []).map((entry: unknown, index: number) => {\n const name = record(entry)?.display_name\n return window(`model:${typeof name === 'string' ? name : index}`, entry, typeof name === 'string' ? name : undefined)\n }),\n ].filter((entry): entry is PlanUsageWindow => entry !== undefined)\n return {\n available: windows.length > 0,\n ...(subscription === undefined ? {} : { subscription }),\n windows,\n fetchedAt,\n }\n}\n\n/** Read plan limits from a throwaway Claude process.\n *\n * Deliberately NOT routed through the supervisor. Borrowing a session's\n * process fails outright while that session is mid-turn, and for a session\n * with no process yet it would resume the whole conversation — and possibly\n * evict another idle session to make room — just to read three numbers. This\n * query carries no tools, no permission bridge, and no session binding: it\n * starts, answers one control request, and is killed. */\nexport async function probePlanUsage(\n executablePath: string,\n fetchedAt: number,\n factory: (params: { prompt: AsyncIterable<SDKUserMessage>; options: ClaudeOptions }) => Query = claudeQuery,\n): Promise<PlanUsageReport> {\n const lifetime = new AbortController()\n const timer = setTimeout(() => lifetime.abort(), PLAN_USAGE_TIMEOUT_MS)\n timer.unref?.()\n // The SDK ends a query as soon as its prompt stream closes, so hold the\n // stream open and let the abort below tear the process down instead.\n const prompt = (async function* (): AsyncGenerator<SDKUserMessage> {\n await new Promise<never>(() => {})\n })()\n const query = factory({\n prompt,\n options: {\n cwd: process.cwd(),\n abortController: lifetime,\n ...(executablePath.length === 0 ? {} : { pathToClaudeCodeExecutable: executablePath }),\n },\n })\n try {\n // Control responses only arrive while the message stream is pumped.\n void (async () => { for await (const _ of query) { /* drain */ } })().catch(() => undefined)\n // Aborting tears the probe process down, but the SDK's pending control\n // request is not documented to settle with it — and an unsettled one hangs\n // the route (and the browser connection serving it) for the life of the\n // Host. The deadline is therefore enforced here too, not only on the\n // process.\n const read = await Promise.race([\n readPlanUsageFrom(query),\n new Promise<never>((_resolve, reject) => {\n const deadline = setTimeout(() => reject(new Error('dsh-claude: the plan usage request did not answer in time')), PLAN_USAGE_TIMEOUT_MS)\n deadline.unref?.()\n }),\n ])\n return normalizePlanUsage(read, fetchedAt)\n } finally {\n clearTimeout(timer)\n lifetime.abort()\n }\n}\n\n// ponytail: a module-level latest-value cache, not a store class. The plugin\n// runs one supervisor per Host process and the report is global to the Claude\n// account, so per-session state would buy nothing. Promote to a keyed store\n// only if the plugin ever serves more than one Claude account at a time.\nlet latest: PlanUsageReport | undefined\n\nexport function recordPlanUsage(report: PlanUsageReport): void {\n latest = report\n}\n\nexport function latestPlanUsage(): PlanUsageReport | undefined {\n return latest\n}\n\n/** Test seam: drop the cached report. */\nexport function resetPlanUsage(): void {\n latest = undefined\n}\n","import { EventEmitter } from 'node:events'\nimport type { Readable, Writable } from 'node:stream'\nimport type { SpawnOptions, SpawnedProcess } from '@anthropic-ai/claude-agent-sdk'\nimport {\n DSH_ENV_PREFIX,\n SENSITIVE_ENV_PATTERN,\n type SubprocessHandle,\n type SubprocessRuntime,\n} from '@deepseek-ai/dsh-subprocess'\n\nexport const CLAUDE_PROCESS_GRACE_MS = 2_000\nexport const CLAUDE_STDERR_TAIL_BYTES = 32 * 1024\n\nconst ADDITIONAL_SENSITIVE_ENV_PATTERN = /(?:authorization|cookie|credential|database[_-]?url|private[_-]?key|netrc)/iu\n\nexport function scrubClaudeSpawnEnv(env: Readonly<Record<string, string | undefined>>): NodeJS.ProcessEnv {\n const safe: NodeJS.ProcessEnv = {}\n for (const [key, value] of Object.entries(env)) {\n if (value === undefined) continue\n if (key.toUpperCase().startsWith(DSH_ENV_PREFIX)) continue\n if (SENSITIVE_ENV_PATTERN.test(key)) continue\n if (ADDITIONAL_SENSITIVE_ENV_PATTERN.test(key)) continue\n safe[key] = value\n }\n return safe\n}\n\nexport class ManagedClaudeProcess extends EventEmitter implements SpawnedProcess {\n readonly stdin: Writable\n readonly stdout: Readable\n readonly handle: SubprocessHandle\n #killed = false\n #exitCode: number | null = null\n #signalCode: NodeJS.Signals | null = null\n\n constructor(handle: SubprocessHandle) {\n super()\n if (handle.stdin === undefined || handle.stdout === undefined) {\n throw new Error('dsh-claude: managed Claude process requires piped stdin/stdout')\n }\n this.handle = handle\n this.stdin = handle.stdin\n this.stdout = handle.stdout\n void handle.done.then(\n outcome => {\n this.#exitCode = outcome.exitCode\n this.#signalCode = outcome.signal\n this.emit('exit', outcome.exitCode, outcome.signal)\n },\n error => {\n this.emit('error', error instanceof Error ? error : new Error(String(error)))\n },\n )\n }\n\n get killed(): boolean {\n return this.#killed\n }\n\n get exitCode(): number | null {\n return this.#exitCode\n }\n\n get signalCode(): NodeJS.Signals | null {\n return this.#signalCode\n }\n\n kill(signal: NodeJS.Signals): boolean {\n if (this.#exitCode !== null || this.#signalCode !== null) return false\n this.#killed = true\n this.handle.terminate()\n return true\n }\n\n stderrTail(): string {\n return this.handle.collected.stderr?.readFrom(0).text ?? ''\n }\n}\n\nexport type SpawnObserver = (process: ManagedClaudeProcess, options: SpawnOptions) => void\n\nexport function createManagedClaudeSpawner(\n runtime: Pick<SubprocessRuntime, 'spawn'>,\n executablePath: string,\n observe?: SpawnObserver,\n): (options: SpawnOptions) => SpawnedProcess {\n return options => {\n if (options.command !== executablePath) {\n throw new Error(`dsh-claude: SDK requested unexpected executable ${JSON.stringify(options.command)}`)\n }\n const handle = runtime.spawn({\n argv: [executablePath, ...options.args],\n cwd: options.cwd ?? process.cwd(),\n stdio: {\n stdin: 'pipe',\n stdout: 'pipe',\n stderr: { maxBytes: CLAUDE_STDERR_TAIL_BYTES },\n },\n graceMs: CLAUDE_PROCESS_GRACE_MS,\n signal: options.signal,\n env: scrubClaudeSpawnEnv(options.env),\n })\n const managed = new ManagedClaudeProcess(handle)\n observe?.(managed, options)\n return managed\n }\n}\n","import { randomUUID } from 'node:crypto'\nimport {\n query as claudeQuery,\n type EffortLevel,\n type Options as ClaudeOptions,\n type PermissionMode,\n type Query,\n type SDKControlGetContextUsageResponse,\n type SDKMessage,\n type SDKUserMessage,\n type Settings as ClaudeSettings,\n type SlashCommand,\n} from '@anthropic-ai/claude-agent-sdk'\nimport type { Agent } from '@deepseek-ai/dsh-agent'\nimport { ToolCallId, createToolResultMessage } from '@deepseek-ai/dsh-llm'\nimport type { ApprovalService } from '@deepseek-ai/dsh-user-approval'\nimport type { UserQuestionService } from '@deepseek-ai/dsh-user-questions'\nimport type { SubprocessRuntime } from '@deepseek-ai/dsh-subprocess'\nimport { AsyncQueue } from './async-queue.ts'\nimport { DEFAULT_CLAUDE_RENDER_MODE, TASK_TOOL_NAMES, type ClaudeRenderMode } from './constants.ts'\nimport {\n currentClaudeActivityCursor,\n redactText,\n safeDetail,\n type ClaudeActivityCursor,\n type ClaudeActivityInput,\n type ClaudeTaskInfo,\n type ClaudeUsage,\n} from './events.ts'\nimport { createPermissionBridge } from './permission.ts'\nimport { createUserQuestionBridge } from './user-question.ts'\nimport { ClaudeSidecarRepository } from './sidecar.ts'\nimport { CLAUDE_PRESENTER_NAMES, dynamicPresenterDefinition } from './presenters.ts'\nimport { normalizeSdkMessage, type NormalizedSdkMessage } from './sdk-messages.ts'\nimport { recordClaudeModels } from './model-catalog.ts'\nimport { readPlanUsageFrom } from './plan-usage.ts'\nimport { createManagedClaudeSpawner, type ManagedClaudeProcess } from './spawn.ts'\n\nexport const CLAUDE_INITIALIZATION_TIMEOUT_MS = 30_000\nexport const CLAUDE_INTERRUPT_TIMEOUT_MS = 5_000\n/** Control requests must settle; a wedged one must not clog the metadata chain. */\nexport const CLAUDE_METADATA_TIMEOUT_MS = 15_000\n\nexport type ClaudeSupervisorState =\n | 'starting'\n | 'idle'\n | 'running'\n | 'interrupting'\n | 'disconnected'\n | 'outcome-unknown'\n | 'disposed'\n\nexport interface ClaudeSupervisorConfig {\n executablePath: string\n idleTimeoutMs: number\n maxProcesses: number\n defaultModel: string\n /** Which renderer the visible turn is produced for; read per message so a\n * Settings change lands on the next turn without a Host restart. */\n renderMode?: ClaudeRenderMode\n}\n\nexport type ClaudeTurnStreamEvent =\n | { type: 'text-delta'; text: string }\n /** One settled Claude thinking block, forwarded only for the native\n * renderer, which draws it as a DSH reasoning block. */\n | { type: 'thinking'; text: string }\n | { type: 'usage'; usage: ClaudeUsage }\n | { type: 'segment-complete'; text: string }\n | { type: 'complete'; text: string }\n\nexport type ClaudeThinkingMode = 'off' | 'ultracode' | EffortLevel\n\nexport type DshSandboxMode = 'read-only' | 'workspace-write' | 'danger-full-access'\n\nconst CLAUDE_MODE_BY_SANDBOX: Readonly<Record<DshSandboxMode, PermissionMode>> = {\n 'read-only': 'plan',\n 'workspace-write': 'acceptEdits',\n 'danger-full-access': 'bypassPermissions',\n}\n\n/** Fold DSH's native access selector into Claude Code's closest permission mode. */\nexport function claudePermissionMode(events: readonly { type: string; data: unknown }[]): PermissionMode {\n for (let index = events.length - 1; index >= 0; index -= 1) {\n const event = events[index]\n if (event?.type !== 'sandbox/mode') continue\n const mode = (event.data as { mode?: unknown }).mode\n return typeof mode === 'string' && mode in CLAUDE_MODE_BY_SANDBOX\n ? CLAUDE_MODE_BY_SANDBOX[mode as DshSandboxMode]\n : 'plan'\n }\n return 'plan'\n}\n\nexport interface ClaudeTurnRequest {\n agent: Agent\n prompt: SDKUserMessage['message']['content']\n model?: string\n thinkingMode?: ClaudeThinkingMode\n signal?: AbortSignal\n}\n\nexport interface ClaudeSupervisorSnapshot {\n sessionId: string\n claudeSessionId?: string\n state: ClaudeSupervisorState\n cwd: string\n model: string\n thinkingMode?: ClaudeThinkingMode\n lastUsedAt: number\n pid?: number\n}\n\nexport class ClaudeTurnBusyError extends Error {\n constructor(sessionId: string) {\n super(`Claude Code session ${sessionId} already has an active or interrupting turn`)\n this.name = 'ClaudeTurnBusyError'\n }\n}\n\nexport class ClaudeOutcomeUnknownError extends Error {\n constructor(message = 'Claude Code exited after activity; side-effect outcome is unknown and the prompt was not replayed') {\n super(message)\n this.name = 'ClaudeOutcomeUnknownError'\n }\n}\n\nexport class ClaudeProtocolError extends Error {\n constructor(message: string) {\n super(message)\n this.name = 'ClaudeProtocolError'\n }\n}\n\nexport class ClaudeProcessLimitError extends Error {\n constructor(maxProcesses: number) {\n super(`Claude Code process limit reached (${maxProcesses}) and no idle session can be evicted`)\n this.name = 'ClaudeProcessLimitError'\n }\n}\n\nexport type ClaudeQueryFactory = (params: {\n prompt: AsyncIterable<SDKUserMessage>\n options: ClaudeOptions\n}) => Query\n\ninterface ActiveTurn {\n agent: Agent\n cursor: ClaudeActivityCursor\n output: AsyncQueue<ClaudeTurnStreamEvent>\n promptUuid: ReturnType<typeof randomUUID>\n phase: 'primary' | 'waiting-tasks' | 'follow-up'\n sawActivity: boolean\n sawTextDelta: boolean\n text: string\n /** Visible prose for the current top-level assistant segment. */\n transcriptText: string\n /** Stable sidecar ordinal reused while the current assistant segment grows. */\n transcriptTextOrdinal: number | undefined\n thinking: string\n /** Newest single-call prompt accounting; what DSH's context meter divides. */\n requestUsage: ClaudeUsage | undefined\n /** When this turn was admitted, and when it first put a token on screen.\n * The transcript has no other clock: activities carry no timestamps. */\n startedAt: number\n firstOutputAt: number | undefined\n aborted: boolean\n deniedToolUseIds: Set<string>\n /** Root tool calls still waiting for their result, by toolUseId, with the\n * tool name a result carries none of. Emptied as results arrive, so what\n * remains when a turn ends is exactly what never got an answer. */\n openCalls: Map<string, string>\n signal?: AbortSignal\n abortListener?: () => void\n}\n\ninterface SupervisorEntry {\n sessionId: string\n ownerAgent: Agent\n cwd: string\n model: string\n thinkingMode: ClaudeThinkingMode | undefined\n permissionMode: PermissionMode\n state: ClaudeSupervisorState\n lastUsedAt: number\n input: AsyncQueue<SDKUserMessage>\n query: Query\n /** Official SDK initialization control request; no stdin nudge is required. */\n sdkInitialization: Promise<void>\n lifetime: AbortController\n process: ManagedClaudeProcess | undefined\n claudeSessionId: string | undefined\n active: ActiveTurn | undefined\n idleTimer: ReturnType<typeof setTimeout> | undefined\n /** Whether the message stream has emitted system/init for session binding. */\n initialized: boolean\n expectedResume: string | undefined\n /** Newest main-chain entry uuid Claude emitted; the anchor a rewind of the\n * next turn forks at. Sidechain (subagent) entries are not chain entries. */\n lastChainUuid: string | undefined\n /** Whether this process consumed an armed rewind fork target at spawn. */\n consumedRewind: boolean\n /** Live Claude task board (subagents and background tasks), keyed by task id. */\n tasks: Map<string, ClaudeTaskInfo>\n /** Last time a task snapshot was persisted (progress throttling). */\n taskSnapshotAt: number\n /** Pending throttled snapshot flush timer. */\n taskSnapshotTimer: ReturnType<typeof setTimeout> | undefined\n pump: Promise<void>\n}\n\nfunction abortFailure(): Error {\n const error = new Error('Claude Code turn aborted')\n error.name = 'AbortError'\n return error\n}\n\nfunction signalAborted(signal: AbortSignal | undefined): boolean {\n return signal?.aborted === true\n}\n\nasync function withTimeout<T>(operation: Promise<T>, timeoutMs: number, label: string): Promise<T> {\n let timer: ReturnType<typeof setTimeout> | undefined\n try {\n return await Promise.race([\n operation,\n new Promise<never>((_resolve, reject) => {\n timer = setTimeout(() => reject(new Error(`${label} timed out after ${timeoutMs}ms`)), timeoutMs)\n timer.unref?.()\n }),\n ])\n } finally {\n if (timer !== undefined) clearTimeout(timer)\n }\n}\n\n/** The uuid of one main-chain transcript entry, or undefined for anything a\n * rewind must not fork at: stream partials, results, and sidechain traffic. */\nfunction chainEntryUuid(message: SDKMessage): string | undefined {\n if (message.type !== 'assistant' && message.type !== 'user') return undefined\n const envelope = message as { uuid?: unknown; parent_tool_use_id?: unknown }\n if (typeof envelope.parent_tool_use_id === 'string') return undefined\n return typeof envelope.uuid === 'string' && envelope.uuid.length > 0 ? envelope.uuid : undefined\n}\n\nfunction sdkUserMessage(prompt: SDKUserMessage['message']['content'], uuid: ReturnType<typeof randomUUID>): SDKUserMessage {\n return {\n type: 'user',\n message: { role: 'user', content: prompt },\n parent_tool_use_id: null,\n uuid,\n }\n}\n\nconst BACKGROUND_TASK_REPORT_PROMPT = [\n 'The background tasks launched by your preceding response have now all settled.',\n 'Report their final completed or failed outcomes concisely to the user.',\n 'Do not start new tools or tasks, and do not repeat the earlier progress update.',\n].join(' ')\n\nfunction usageSummary(usage: ClaudeUsage): string {\n const input = usage.inputTokens ?? 0\n const output = usage.outputTokens ?? 0\n const cost = usage.cumulativeCostUsd === undefined\n ? ''\n : ` · $${usage.cumulativeCostUsd.toFixed(4)} cumulative`\n return `${input} input / ${output} output tokens${cost}`\n}\n\nfunction errorSummary(error: unknown): string {\n return error instanceof Error ? error.message : String(error)\n}\n\n/** Root-call activity summary; subagent dispatches lead with Claude's own task description. */\nfunction rootCallSummary(toolName: string, input: unknown): string {\n if (TASK_TOOL_NAMES.has(toolName)) {\n const description = input !== null && typeof input === 'object'\n ? (input as Record<string, unknown>).description\n : undefined\n if (typeof description === 'string' && description.length > 0) return description\n return 'Claude dispatched a subagent'\n }\n return `Claude called ${toolName}`\n}\n\nexport class ClaudeSupervisor {\n readonly #entries = new Map<string, SupervisorEntry>()\n readonly #interruptions = new Map<string, Promise<void>>()\n readonly #runtime: Pick<SubprocessRuntime, 'spawn'>\n readonly #approval: Pick<ApprovalService, 'request'>\n readonly #userQuestions: Pick<UserQuestionService, 'ask'>\n readonly #config: ClaudeSupervisorConfig\n readonly #queryFactory: ClaudeQueryFactory\n readonly #runDetached: <T>(operation: () => T) => T\n readonly #sidecar: ClaudeSidecarRepository\n readonly #dynamicPresenterNames = new WeakMap<Agent, Set<string>>()\n readonly #contextWindows = new Map<string, number>()\n #disposed = false\n #admissionGate: Promise<void> = Promise.resolve()\n\n constructor(dependencies: {\n runtime: Pick<SubprocessRuntime, 'spawn'>\n approval: Pick<ApprovalService, 'request'>\n userQuestions: Pick<UserQuestionService, 'ask'>\n config: ClaudeSupervisorConfig\n queryFactory?: ClaudeQueryFactory\n runDetached?: <T>(operation: () => T) => T\n sidecar?: ClaudeSidecarRepository\n }) {\n this.#runtime = dependencies.runtime\n this.#approval = dependencies.approval\n this.#userQuestions = dependencies.userQuestions\n this.#config = dependencies.config\n this.#queryFactory = dependencies.queryFactory ?? (params => claudeQuery(params))\n this.#runDetached = dependencies.runDetached ?? (operation => operation())\n this.#sidecar = dependencies.sidecar ?? new ClaudeSidecarRepository()\n }\n\n snapshots(): ClaudeSupervisorSnapshot[] {\n return [...this.#entries.values()].map(entry => ({\n sessionId: entry.sessionId,\n ...(entry.claudeSessionId === undefined ? {} : { claudeSessionId: entry.claudeSessionId }),\n state: entry.state,\n cwd: entry.cwd,\n model: entry.model,\n ...(entry.thinkingMode === undefined ? {} : { thinkingMode: entry.thinkingMode }),\n lastUsedAt: entry.lastUsedAt,\n ...(entry.process === undefined ? {} : { pid: entry.process.handle.pid }),\n }))\n }\n\n supportedCommands(agent: Agent, model = this.#config.defaultModel): Promise<readonly SlashCommand[]> {\n return this.#runMetadata(agent, model, query => query.supportedCommands())\n }\n\n async contextUsage(agent: Agent, model = this.#config.defaultModel): Promise<SDKControlGetContextUsageResponse> {\n return this.#runMetadata(agent, model, async (query, entry) => {\n const usage = await query.getContextUsage()\n this.#recordContextWindow(entry.model, usage)\n return usage\n })\n }\n\n /** Cache a window under both the selector id the caller asked for and the\n * concrete model the CLI reports, so either name resolves it later. */\n #recordContextWindow(model: string, usage: SDKControlGetContextUsageResponse): void {\n const contextWindow = usage.rawMaxTokens > 0 ? usage.rawMaxTokens : usage.maxTokens\n if (contextWindow <= 0) return\n this.#contextWindows.set(model, contextWindow)\n this.#contextWindows.set(usage.model, contextWindow)\n }\n\n /** Learn a model's context window the first time a turn finishes on it.\n *\n * DSH hides its context meter entirely unless the route publishes a\n * capacity, and these numbers move with Claude releases — so none are\n * hardcoded; the CLI is asked over the session's own live process.\n *\n * Turn completion is the earliest honest moment to ask. `entry.model` is\n * already the model that just ran, so no model switch is provoked — which\n * rules out asking from `resolveModel`, since DSH resolves every model in\n * the catalog to build its picker and `#metadataEntry` would switch the live\n * session once per entry. And nothing is lost by waiting: the meter needs a\n * usage sample too, and no turn has reported one before the first turn ends.\n *\n * Best-effort — a failure leaves the window unknown (the meter stays hidden,\n * exactly as before) and the next completed turn tries again. */\n async #learnContextWindow(entry: SupervisorEntry): Promise<void> {\n if (this.#contextWindows.has(entry.model)) return\n try {\n const usage = await withTimeout(\n entry.query.getContextUsage(),\n CLAUDE_METADATA_TIMEOUT_MS,\n 'Claude context window probe',\n )\n this.#recordContextWindow(entry.model, usage)\n } catch {\n // Intentionally silent: this is opportunistic chrome, never turn-critical.\n }\n }\n\n contextWindow(model: string): number | undefined {\n return this.#contextWindows.get(model)\n }\n\n /** Raw `/usage` payload, read over a session's existing process. Only the\n * idle-time metadata bridge uses this; a user-triggered refresh runs\n * probePlanUsage instead so it never waits on, or perturbs, a session. */\n planUsage(agent: Agent, model = this.#config.defaultModel): Promise<unknown> {\n return this.#runMetadata(agent, model, query => readPlanUsageFrom(query))\n }\n\n runTurn(request: ClaudeTurnRequest): Promise<AsyncIterable<ClaudeTurnStreamEvent>> {\n const interruption = this.#interruptions.get(request.agent.id as string)\n if (interruption !== undefined) return interruption.then(() => this.runTurn(request))\n const operation = this.#admissionGate.then(() => this.#runTurnAdmitted(request))\n this.#admissionGate = operation.then(() => undefined, () => undefined)\n return operation\n }\n\n async #runTurnAdmitted(request: ClaudeTurnRequest): Promise<AsyncIterable<ClaudeTurnStreamEvent>> {\n if (this.#disposed) throw new Error('dsh-claude: supervisor is disposed')\n if (signalAborted(request.signal)) throw abortFailure()\n const sessionId = request.agent.id as string\n let entry = this.#entries.get(sessionId)\n if (entry?.state === 'disposed' || entry?.state === 'disconnected' || entry?.state === 'outcome-unknown') {\n this.#entries.delete(sessionId)\n await this.#disposeEntry(entry)\n entry = undefined\n }\n if (entry === undefined) {\n await this.#makeRoom()\n entry = await this.#createEntry(request.agent, request.model ?? this.#config.defaultModel, request.thinkingMode)\n this.#entries.set(sessionId, entry)\n }\n if (entry.ownerAgent !== request.agent) {\n throw new Error(`dsh-claude: live agent identity changed for session ${sessionId}`)\n }\n if (entry.active !== undefined || entry.state === 'interrupting') throw new ClaudeTurnBusyError(sessionId)\n await entry.sdkInitialization\n\n if (entry.idleTimer !== undefined) {\n clearTimeout(entry.idleTimer)\n entry.idleTimer = undefined\n }\n const model = request.model ?? this.#config.defaultModel\n if (request.thinkingMode !== entry.thinkingMode || model !== entry.model) {\n // The SDK only accepts effort/thinking at query start, and a live\n // setModel is not enough for the model either: the CLI freezes its\n // system prompt (including the \"you are powered by\" line) at the first\n // context-usage request, which the metadata refresh issues on every new\n // process, so a switched session answers as the old model. Rebuild the\n // query; the persisted Claude session binding keeps the context.\n this.#entries.delete(sessionId)\n await this.#disposeEntry(entry)\n entry = await this.#createEntry(request.agent, model, request.thinkingMode)\n this.#entries.set(sessionId, entry)\n await entry.sdkInitialization\n } else {\n await this.#syncPermissionMode(entry)\n }\n\n const promptUuid = randomUUID()\n const cursor = currentClaudeActivityCursor(request.agent.session.events)\n const projection = await this.#sidecar.read(sessionId)\n cursor.nextOrdinal = projection.activities.reduce((next, activity) => (\n activity.turn === cursor.turn && activity.step === cursor.step\n ? Math.max(next, activity.ordinal + 1)\n : next\n ), 0)\n const active: ActiveTurn = {\n agent: request.agent,\n cursor,\n output: new AsyncQueue<ClaudeTurnStreamEvent>(),\n promptUuid,\n phase: 'primary',\n sawActivity: false,\n sawTextDelta: false,\n text: '',\n transcriptText: '',\n transcriptTextOrdinal: undefined,\n thinking: '',\n requestUsage: undefined,\n startedAt: Date.now(),\n firstOutputAt: undefined,\n aborted: false,\n deniedToolUseIds: new Set(),\n openCalls: new Map(),\n ...(request.signal === undefined ? {} : { signal: request.signal }),\n }\n entry.active = active\n entry.state = 'running'\n entry.lastUsedAt = Date.now()\n try {\n await this.#appendActivity(active, {\n kind: 'status',\n phase: 'started',\n title: 'Claude Code turn started',\n })\n } catch (error) {\n active.output.fail(error)\n entry.active = undefined\n if (this.#entries.get(sessionId) === entry) this.#entries.delete(sessionId)\n await this.#disposeEntry(entry)\n throw error\n }\n if (signalAborted(request.signal)) {\n active.aborted = true\n active.output.fail(abortFailure())\n await this.#appendActivity(active, {\n kind: 'status',\n phase: 'failed',\n title: 'Claude Code turn cancelled before submission',\n })\n entry.active = undefined\n entry.state = 'idle'\n entry.lastUsedAt = Date.now()\n this.#armIdleTimer(entry)\n return active.output\n }\n if (request.signal !== undefined) {\n const abortListener = () => { void this.#startInterrupt(entry as SupervisorEntry) }\n active.abortListener = abortListener\n request.signal.addEventListener('abort', abortListener, { once: true })\n }\n entry.input.push(sdkUserMessage(request.prompt, promptUuid))\n return active.output\n }\n\n #runMetadata<T>(\n agent: Agent,\n model: string,\n operation: (query: Query, entry: SupervisorEntry) => Promise<T>,\n ): Promise<T> {\n const admitted = this.#admissionGate.then(async () => {\n if (this.#disposed) throw new Error('dsh-claude: supervisor is disposed')\n const entry = await this.#metadataEntry(agent, model)\n try {\n // Use the SDK's initialize control request. system/init is emitted only\n // after the first real stdin message and is reserved for session binding.\n await entry.sdkInitialization\n return await this.#control(entry, operation(entry.query, entry), 'Claude metadata request')\n } finally {\n entry.lastUsedAt = Date.now()\n if (entry.active === undefined && entry.state === 'idle') this.#armIdleTimer(entry)\n }\n })\n this.#admissionGate = admitted.then(() => undefined, () => undefined)\n return admitted\n }\n\n async #metadataEntry(agent: Agent, model: string): Promise<SupervisorEntry> {\n const sessionId = agent.id as string\n let entry = this.#entries.get(sessionId)\n if (entry?.state === 'disposed' || entry?.state === 'disconnected' || entry?.state === 'outcome-unknown') {\n this.#entries.delete(sessionId)\n await this.#disposeEntry(entry)\n entry = undefined\n }\n if (entry === undefined) {\n await this.#makeRoom()\n entry = await this.#createEntry(agent, model)\n this.#entries.set(sessionId, entry)\n }\n if (entry.ownerAgent !== agent) {\n throw new Error(`dsh-claude: live agent identity changed for session ${sessionId}`)\n }\n if (entry.active !== undefined || entry.state === 'interrupting') throw new ClaudeTurnBusyError(sessionId)\n if (entry.idleTimer !== undefined) {\n clearTimeout(entry.idleTimer)\n entry.idleTimer = undefined\n }\n await this.#syncPermissionMode(entry)\n // Never switch a live entry here: `model` is only the seed for a fresh\n // process. The idle metadata refresh runs with the plugin default, and\n // letting it call setModel raced runTurn's own switch -- a session the user\n // set to Fable answered on Opus whenever the refresh landed last.\n return entry\n }\n\n /** Run one SDK control request against a live entry, and discard the entry if\n * it does not answer.\n *\n * Turn admission and every metadata read share one process-wide gate, so an\n * unbounded control request stalls every session until the Host restarts.\n * Bounding it is only half the cure: a timeout also proves this query has\n * stopped answering, and keeping the entry means the next caller reuses the\n * same dead process — timing out again, forever. Discarding it lets the next\n * attempt spawn a fresh one. Every control request goes through here so a\n * new call site cannot quietly reintroduce either half. */\n async #control<T>(\n entry: SupervisorEntry,\n operation: Promise<T>,\n label: string,\n timeoutMs = CLAUDE_METADATA_TIMEOUT_MS,\n ): Promise<T> {\n try {\n return await withTimeout(operation, timeoutMs, label)\n } catch (error) {\n if (this.#entries.get(entry.sessionId) === entry) this.#entries.delete(entry.sessionId)\n await this.#disposeEntry(entry)\n throw error\n }\n }\n\n async #syncPermissionMode(entry: SupervisorEntry): Promise<void> {\n const mode = claudePermissionMode(entry.ownerAgent.session.events)\n if (mode === entry.permissionMode) return\n await this.#control(entry, entry.query.setPermissionMode(mode), 'Claude Code permission mode switch')\n entry.permissionMode = mode\n }\n\n async disposeSession(sessionId: string): Promise<void> {\n const entry = this.#entries.get(sessionId)\n if (entry === undefined) return\n this.#entries.delete(sessionId)\n await this.#disposeEntry(entry)\n }\n\n async dispose(): Promise<void> {\n if (this.#disposed) return\n this.#disposed = true\n const entries = [...this.#entries.values()]\n this.#entries.clear()\n await Promise.allSettled(entries.map(entry => this.#disposeEntry(entry)))\n }\n\n async #makeRoom(): Promise<void> {\n if (this.#entries.size < this.#config.maxProcesses) return\n const idle = [...this.#entries.values()]\n .filter(entry => entry.active === undefined && entry.state === 'idle')\n .sort((left, right) => left.lastUsedAt - right.lastUsedAt)[0]\n if (idle === undefined) throw new ClaudeProcessLimitError(this.#config.maxProcesses)\n this.#entries.delete(idle.sessionId)\n await this.#disposeEntry(idle)\n }\n\n async #createEntry(agent: Agent, model: string, thinkingMode?: ClaudeThinkingMode): Promise<SupervisorEntry> {\n const sessionId = agent.id as string\n const cwd = agent.session.header.cwd ?? process.cwd()\n const input = new AsyncQueue<SDKUserMessage>()\n const lifetime = new AbortController()\n const projection = await this.#sidecar.importLegacy(sessionId, agent.session.events)\n const binding = projection.binding\n // A rewound session resumes at the kept turn's chain anchor, or drops its\n // binding entirely when the rewind discarded every turn. The truncating\n // resume may land in a different Claude session id, so the identity guard\n // stands down for exactly this spawn and re-binds from system/init.\n const pendingRewind = projection.rewind?.pending\n const forkAt = pendingRewind !== undefined && 'resumeAt' in pendingRewind ? pendingRewind.resumeAt : undefined\n const startFresh = pendingRewind !== undefined && 'fresh' in pendingRewind\n const permissionMode = claudePermissionMode(agent.session.events)\n const entry = {\n sessionId,\n ownerAgent: agent,\n cwd,\n model,\n thinkingMode,\n permissionMode,\n state: 'starting' as ClaudeSupervisorState,\n lastUsedAt: Date.now(),\n input,\n lifetime,\n claudeSessionId: startFresh ? undefined : binding?.claudeSessionId,\n expectedResume: startFresh || forkAt !== undefined ? undefined : binding?.claudeSessionId,\n lastChainUuid: undefined,\n consumedRewind: pendingRewind !== undefined,\n initialized: false,\n idleTimer: undefined,\n tasks: new Map<string, ClaudeTaskInfo>(),\n taskSnapshotAt: 0,\n taskSnapshotTimer: undefined,\n } as SupervisorEntry\n\n const activeInteraction = () => {\n const active = entry.active\n return active === undefined ? undefined : {\n agent: active.agent,\n cursor: active.cursor,\n markActivity: () => { active.sawActivity = true },\n recordDenial: (toolUseId: string) => { active.deniedToolUseIds.add(toolUseId) },\n hasFullAccess: async () => {\n await this.#syncPermissionMode(entry)\n return entry.permissionMode === 'bypassPermissions'\n },\n appendActivity: (activity: ClaudeActivityInput) => this.#appendActivity(active, activity),\n }\n }\n const userQuestion = createUserQuestionBridge(this.#userQuestions, activeInteraction)\n const canUseTool = createPermissionBridge(this.#approval, activeInteraction, userQuestion)\n const options: ClaudeOptions = {\n pathToClaudeCodeExecutable: this.#config.executablePath,\n cwd,\n settingSources: ['user', 'project', 'local'],\n systemPrompt: { type: 'preset', preset: 'claude_code' },\n tools: { type: 'preset', preset: 'claude_code' },\n includePartialMessages: true,\n permissionMode,\n allowDangerouslySkipPermissions: true,\n canUseTool,\n abortController: lifetime,\n spawnClaudeCodeProcess: createManagedClaudeSpawner(this.#runtime, this.#config.executablePath, process => {\n entry.process = process\n }),\n ...(binding === undefined || startFresh ? {} : {\n resume: binding.claudeSessionId,\n ...(forkAt === undefined ? {} : { resumeSessionAt: forkAt }),\n }),\n model,\n ...(thinkingMode === undefined\n ? {}\n : thinkingMode === 'off'\n ? { thinking: { type: 'disabled' } as const }\n : thinkingMode === 'ultracode'\n ? { settings: { ultracode: true } satisfies ClaudeSettings }\n : { effort: thinkingMode }),\n }\n entry.query = this.#queryFactory({ prompt: input, options })\n entry.pump = this.#runDetached(() => this.#pump(entry))\n entry.sdkInitialization = withTimeout(\n entry.query.initializationResult(),\n CLAUDE_INITIALIZATION_TIMEOUT_MS,\n 'Claude SDK initialization',\n ).then((initialization) => {\n // The CLI's own /model lineup rides along on initialize, so the selector\n // tracks whatever Claude Code ships without a table in this plugin and\n // without a control request of its own.\n recordClaudeModels(initialization.models)\n if (entry.state === 'starting') entry.state = 'idle'\n })\n void entry.sdkInitialization.catch(error => this.#handleDisconnect(entry, error))\n return entry\n }\n\n async #pump(entry: SupervisorEntry): Promise<void> {\n try {\n for await (const sdkMessage of entry.query) {\n const chainUuid = chainEntryUuid(sdkMessage as SDKMessage)\n if (chainUuid !== undefined) entry.lastChainUuid = chainUuid\n for (const message of normalizeSdkMessage(sdkMessage as SDKMessage)) {\n await this.#handleMessage(entry, message)\n }\n }\n if (entry.state !== 'disposed') await this.#handleDisconnect(entry, new Error('Claude Code stream ended'))\n } catch (error) {\n if (entry.state !== 'disposed') await this.#handleDisconnect(entry, error)\n }\n }\n\n async #handleMessage(entry: SupervisorEntry, message: NormalizedSdkMessage): Promise<void> {\n if (message.kind === 'init') {\n // Claude Code can re-emit system/init across turns in long-lived\n // streaming-input mode (e.g. the auth-error path). Treat it idempotently:\n // refresh the session id/version and negotiated state, and only reject a\n // genuine identity/cwd mismatch.\n const firstInitialization = !entry.initialized\n if (entry.expectedResume !== undefined && message.sessionId !== entry.expectedResume) {\n throw new ClaudeProtocolError(`Claude Code resumed unexpected session ${message.sessionId}; expected ${entry.expectedResume}`)\n }\n if (message.cwd !== entry.cwd) {\n throw new ClaudeProtocolError(`Claude Code initialized in unexpected cwd ${message.cwd}; expected ${entry.cwd}`)\n }\n entry.initialized = true\n entry.claudeSessionId = message.sessionId\n entry.state = entry.active === undefined ? 'idle' : 'running'\n // A newly created Query cannot retain tasks from the previous process,\n // but repeated init messages from this same long-lived Query are only\n // protocol refreshes and must not erase background work still running.\n if (firstInitialization && entry.tasks.size > 0) {\n entry.tasks.clear()\n await this.#flushTasksSnapshot(entry)\n }\n await this.#sidecar.writeBinding(entry.sessionId, {\n claudeSessionId: message.sessionId,\n cliVersion: message.cliVersion,\n cwd: message.cwd,\n })\n // The fork target is spent the moment Claude resumes at it; leaving it\n // armed would re-truncate the session on the next respawn.\n if (entry.consumedRewind) {\n entry.consumedRewind = false\n await this.#sidecar.clearRewindPending(entry.sessionId)\n }\n return\n }\n\n // Task lifecycle is session-scoped, not turn-scoped: background tasks and\n // subagents settle while no DSH turn is active, and their notifications\n // must still reach the task board instead of being dropped with turn-less\n // messages below.\n const taskId = message.kind === 'subagent' ? message.taskId : undefined\n if (message.kind === 'subagent' && taskId !== undefined) {\n await this.#trackTask(entry, message, taskId, entry.active?.cursor.turn)\n } else if (message.kind === 'background-tasks') {\n await this.#trackBackgroundLevel(entry, message.tasks, entry.active?.cursor.turn)\n }\n\n const active = entry.active\n if (active === undefined) return\n if (message.kind === 'result') {\n if (entry.claudeSessionId === undefined) {\n throw new ClaudeProtocolError('Claude Code sent a result before initialization')\n }\n if (message.sessionId !== entry.claudeSessionId) {\n throw new ClaudeProtocolError(`Claude Code result session ${message.sessionId} does not match ${entry.claudeSessionId}`)\n }\n if (active.phase === 'waiting-tasks') {\n // The CLI may automatically react to each completed background task and\n // emit a top-level result, correlated or not. Publish that prose as a\n // completed progress block, but keep the original DSH turn open until\n // every owned task settles and the explicit final report returns.\n await this.#completeProgressSegment(active, message)\n return\n }\n if (message.userMessageUuid !== undefined && message.userMessageUuid !== active.promptUuid) {\n // A stale internal continuation must not settle the explicit final\n // report request. Primary-turn mismatches remain protocol failures.\n if (active.phase === 'follow-up') return\n throw new ClaudeProtocolError(`Claude Code result for user message ${message.userMessageUuid} does not match active request ${active.promptUuid}`)\n }\n await this.#completeTurn(entry, active, message)\n return\n }\n if (message.kind === 'protocol-error') {\n throw new ClaudeProtocolError(`${message.title}: ${JSON.stringify(message.detail).slice(0, 1_000)}`)\n }\n active.sawActivity = true\n\n switch (message.kind) {\n case 'text-delta':\n if (message.parentToolUseId !== undefined) return\n active.sawTextDelta = true\n active.text += message.text\n active.transcriptText += message.text\n await this.#upsertTranscriptText(active)\n active.firstOutputAt ??= Date.now()\n active.output.push({ type: 'text-delta', text: message.text })\n return\n case 'assistant-text':\n if (message.parentToolUseId !== undefined) return\n if (!active.sawTextDelta) {\n // Complete assistant text is the fallback when no partial text delta\n // streamed. Mark text-delta seen so that additional complete\n // assistant records sharing the same message.id (one per completed\n // content block) do not duplicate the text.\n active.sawTextDelta = true\n active.text += message.text\n active.transcriptText += message.text\n await this.#upsertTranscriptText(active)\n active.firstOutputAt ??= Date.now()\n active.output.push({ type: 'text-delta', text: message.text })\n }\n return\n case 'thinking':\n if (message.parentToolUseId !== undefined) return\n if (message.phase === 'updated') {\n active.thinking += message.text\n return\n }\n active.thinking = message.text\n await this.#appendActivity(active, {\n kind: 'thinking',\n phase: 'completed',\n title: 'Claude thinking',\n summary: message.text,\n })\n // The plugin transcript reads thinking off the sidecar; the native\n // renderer needs it on the stream to build a reasoning block.\n if (this.#nativeRendering()) active.output.push({ type: 'thinking', text: message.text })\n return\n case 'tool-call':\n if (message.parentToolUseId === undefined) this.#closeTranscriptTextSegment(active)\n await this.#appendActivity(active, {\n kind: message.parentToolUseId === undefined ? 'tool-call' : 'subagent',\n phase: 'started',\n toolUseId: message.toolUseId,\n ...(message.parentToolUseId === undefined ? {} : { parentToolUseId: message.parentToolUseId }),\n toolName: message.toolName,\n title: message.toolName,\n summary: message.parentToolUseId === undefined ? rootCallSummary(message.toolName, message.input) : `Subagent called ${message.toolName}`,\n detail: message.input,\n })\n if (message.parentToolUseId === undefined) {\n active.openCalls.set(message.toolUseId, message.toolName)\n // Only root calls are mirrored: a subagent's nested tools belong to\n // the Task card that dispatched them, and the native channel has no\n // nesting to hang them under.\n if (this.#nativeRendering()) {\n this.#ensureDynamicPresenter(active.agent, message.toolName)\n await this.#appendNativeToolCall(active, message)\n }\n }\n return\n case 'tool-result':\n active.openCalls.delete(message.toolUseId)\n await this.#appendActivity(active, {\n kind: message.parentToolUseId === undefined ? 'tool-result' : 'subagent',\n phase: message.isError ? 'failed' : 'completed',\n toolUseId: message.toolUseId,\n ...(message.parentToolUseId === undefined ? {} : { parentToolUseId: message.parentToolUseId }),\n title: message.isError ? 'Tool failed' : 'Tool completed',\n detail: message.output,\n isError: message.isError,\n })\n if (message.parentToolUseId === undefined && this.#nativeRendering()) {\n await this.#appendNativeToolResult(active, message)\n }\n return\n case 'subagent':\n await this.#appendActivity(active, {\n kind: 'subagent',\n phase: message.phase,\n ...(message.taskId === undefined ? {} : { taskId: message.taskId }),\n title: message.title,\n summary: message.summary,\n detail: message.detail,\n isError: message.phase === 'failed',\n })\n return\n case 'request-usage':\n // A subagent call bills against its own context, so it never stands in\n // for the main conversation's size.\n if (message.parentToolUseId === undefined) active.requestUsage = message.usage\n return\n case 'compaction':\n // Close the open prose span first: compaction sits *between* what was\n // said before and after it, never inside one text segment.\n this.#closeTranscriptTextSegment(active)\n await this.#appendActivity(active, {\n kind: 'compaction',\n phase: 'completed',\n title: 'Claude compacted the conversation',\n detail: {\n ...(message.trigger === undefined ? {} : { trigger: message.trigger }),\n ...(message.preTokens === undefined ? {} : { preTokens: message.preTokens }),\n ...(message.postTokens === undefined ? {} : { postTokens: message.postTokens }),\n ...(message.durationMs === undefined ? {} : { durationMs: message.durationMs }),\n },\n })\n return\n case 'status':\n case 'warning':\n case 'unknown':\n await this.#appendActivity(active, {\n kind: message.kind === 'status' ? 'status' : 'warning',\n phase: 'updated',\n title: message.title,\n ...('summary' in message ? { summary: message.summary } : {}),\n ...('detail' in message ? { detail: message.detail } : {}),\n })\n return\n case 'permission-denied':\n await this.#appendActivity(active, {\n kind: 'permission',\n phase: 'denied',\n toolUseId: message.toolUseId,\n toolName: message.toolName,\n title: message.toolName,\n summary: message.summary,\n })\n // A denied call never produces a tool result, so the native card would\n // stay pending forever. Settle it as the failure it is.\n if (this.#nativeRendering()) {\n await this.#appendNativeToolResult(active, {\n kind: 'tool-result',\n toolUseId: message.toolUseId,\n output: message.summary,\n isError: true,\n })\n }\n return\n }\n }\n\n /** The turn's accounting with its wall clock attached. The transcript draws\n * this line itself under the plugin renderer: activities carry no\n * timestamps, so a duration it did not measure is a duration nobody has. */\n #timedUsage(active: ActiveTurn, usage: ClaudeUsage): ClaudeUsage {\n const now = Date.now()\n return {\n ...usage,\n durationMs: Math.max(0, now - active.startedAt),\n ...(active.firstOutputAt === undefined ? {} : { ttftMs: Math.max(0, active.firstOutputAt - active.startedAt) }),\n }\n }\n\n #nativeRendering(): boolean {\n return (this.#config.renderMode ?? DEFAULT_CLAUDE_RENDER_MODE) === 'native'\n }\n\n /** Register one presenter-only mirror for a tool name the static preset\n * registry does not cover (MCP tools, newly added built-ins). Runs in the\n * agent scope so the mirror is visible only to this preset's sessions and\n * unwinds with the agent; failure keeps the generic card, never the turn. */\n #ensureDynamicPresenter(agent: Agent, name: string): void {\n if (CLAUDE_PRESENTER_NAMES.has(name)) return\n let known = this.#dynamicPresenterNames.get(agent)\n if (known === undefined) {\n known = new Set<string>()\n this.#dynamicPresenterNames.set(agent, known)\n }\n if (known.has(name)) return\n try {\n agent.ctx.tools.register(dynamicPresenterDefinition(name))\n known.add(name)\n } catch {\n // A late or disposed agent keeps the generic card; presentation must\n // never unsettle the Claude turn.\n }\n }\n\n /** Mirror one root Claude tool call into the durable native tool channel so\n * the host's tool presentation renders it exactly like a DSH-executed call.\n * Presentation duplication is best-effort and never unsettles the turn. */\n async #appendNativeToolCall(\n active: ActiveTurn,\n message: Extract<NormalizedSdkMessage, { kind: 'tool-call' }>,\n ): Promise<void> {\n try {\n await active.agent.session.append('tool/call', {\n turn: active.cursor.turn,\n step: active.cursor.step,\n callId: ToolCallId(message.toolUseId),\n name: message.toolName,\n arguments: safeDetail(message.input) ?? '{}',\n })\n } catch {\n // Presentation duplication must never unsettle the Claude turn.\n }\n }\n\n async #appendNativeToolResult(\n active: ActiveTurn,\n message: Pick<Extract<NormalizedSdkMessage, { kind: 'tool-result' }>, 'kind' | 'toolUseId' | 'output' | 'isError'>,\n ): Promise<void> {\n const text = typeof message.output === 'string' ? redactText(message.output) : safeDetail(message.output) ?? ''\n try {\n await active.agent.session.append('tool/result', {\n turn: active.cursor.turn,\n step: active.cursor.step,\n message: createToolResultMessage({\n callId: ToolCallId(message.toolUseId),\n content: [{ type: 'text', text }],\n isError: message.isError,\n }),\n }, { surfaceOp: 'append' })\n } catch {\n // Presentation duplication must never unsettle the Claude turn.\n }\n }\n\n /** Merge one task lifecycle message into the session's task board. */\n async #trackTask(\n entry: SupervisorEntry,\n message: Extract<NormalizedSdkMessage, { kind: 'subagent' }>,\n taskId: string,\n originTurn: number | undefined,\n ): Promise<void> {\n const previous = entry.tasks.get(taskId)\n const next: ClaudeTaskInfo = {\n taskId,\n description: message.description ?? previous?.description ?? message.title,\n status: message.taskStatus ?? previous?.status ?? 'running',\n }\n const resolvedOriginTurn = previous?.originTurn ?? originTurn\n if (resolvedOriginTurn !== undefined) next.originTurn = resolvedOriginTurn\n const subagentType = message.subagentType ?? previous?.subagentType\n if (subagentType !== undefined) next.subagentType = subagentType\n const taskType = message.taskType ?? previous?.taskType\n if (taskType !== undefined) next.taskType = taskType\n const lastToolName = message.lastToolName ?? previous?.lastToolName\n if (lastToolName !== undefined) next.lastToolName = lastToolName\n const summary = message.summary ?? previous?.summary\n if (summary !== undefined) next.summary = summary\n const usage = message.usage ?? previous?.usage\n if (usage !== undefined) next.usage = usage\n if (previous?.backgrounded === true) next.backgrounded = true\n entry.tasks.set(taskId, next)\n const settled = next.status !== 'running'\n await this.#scheduleTasksSnapshot(entry, settled)\n if (settled) await this.#continueAfterTasks(entry)\n }\n\n /** Fold the background-task level signal into the board (REPLACE semantics\n * for the backgrounded flag: only the listed tasks are detached). */\n async #trackBackgroundLevel(\n entry: SupervisorEntry,\n tasks: readonly { taskId: string; taskType?: string; description: string }[],\n originTurn: number | undefined,\n ): Promise<void> {\n const live = new Set(tasks.map(task => task.taskId))\n let changed = false\n for (const task of tasks) {\n const existing = entry.tasks.get(task.taskId)\n if (existing === undefined) {\n entry.tasks.set(task.taskId, {\n taskId: task.taskId,\n description: task.description,\n status: 'running',\n ...(originTurn === undefined ? {} : { originTurn }),\n ...(task.taskType === undefined ? {} : { taskType: task.taskType }),\n backgrounded: true,\n })\n changed = true\n } else if (existing.backgrounded !== true || existing.status !== 'running') {\n entry.tasks.set(task.taskId, { ...existing, status: 'running', backgrounded: true })\n changed = true\n }\n }\n for (const task of entry.tasks.values()) {\n if (task.backgrounded === true && task.status === 'running' && !live.has(task.taskId)) {\n entry.tasks.set(task.taskId, { ...task, status: 'completed' })\n changed = true\n }\n }\n if (changed) {\n await this.#scheduleTasksSnapshot(entry, true)\n await this.#continueAfterTasks(entry)\n }\n }\n\n #hasRunningTasks(entry: SupervisorEntry, active: ActiveTurn): boolean {\n return [...entry.tasks.values()].some(task => (\n task.originTurn === active.cursor.turn && task.backgrounded === true && task.status === 'running'\n ))\n }\n\n async #continueAfterTasks(entry: SupervisorEntry): Promise<void> {\n const active = entry.active\n if (active === undefined || active.phase !== 'waiting-tasks' || this.#hasRunningTasks(entry, active)) return\n active.phase = 'follow-up'\n active.promptUuid = randomUUID()\n active.sawTextDelta = false\n active.text = ''\n this.#closeTranscriptTextSegment(active)\n active.thinking = ''\n await this.#appendSafely(active, {\n kind: 'status',\n phase: 'updated',\n title: 'Claude Code is reporting background task results',\n })\n entry.input.push(sdkUserMessage(BACKGROUND_TASK_REPORT_PROMPT, active.promptUuid))\n }\n\n /** Persist the task board. Settled transitions flush immediately; progress\n * ticks throttle to one snapshot per second to bound log volume. */\n async #scheduleTasksSnapshot(entry: SupervisorEntry, immediate: boolean): Promise<void> {\n const THROTTLE_MS = 1_000\n const elapsed = Date.now() - entry.taskSnapshotAt\n if (!immediate && elapsed < THROTTLE_MS) {\n if (entry.taskSnapshotTimer === undefined) {\n entry.taskSnapshotTimer = setTimeout(() => {\n entry.taskSnapshotTimer = undefined\n void this.#flushTasksSnapshot(entry)\n }, THROTTLE_MS - elapsed)\n entry.taskSnapshotTimer.unref?.()\n }\n return\n }\n await this.#flushTasksSnapshot(entry)\n }\n\n async #flushTasksSnapshot(entry: SupervisorEntry): Promise<void> {\n if (entry.taskSnapshotTimer !== undefined) {\n clearTimeout(entry.taskSnapshotTimer)\n entry.taskSnapshotTimer = undefined\n }\n entry.taskSnapshotAt = Date.now()\n // Snapshot persistence is best-effort: the in-memory board stays\n // authoritative and the next change re-flushes.\n await this.#sidecar.writeTasks(entry.sessionId, [...entry.tasks.values()]).catch(() => undefined)\n }\n\n /** What DSH is told about token usage: newest call's prompt, whole turn's output.\n *\n * `TokenUsage` is documented as \"token accounting for ONE model call\", and\n * DSH's token meter divides `uncachedInput + cacheRead + cacheWrite` by the\n * context window to draw context pressure. One Claude turn makes many calls\n * and the CLI's result usage sums all of them, so reporting that sum pinned\n * the meter at 100%: a 35-call turn reads the same prompt from cache 35\n * times, which sums past the window without the conversation ever growing.\n * The newest single call answers \"how big is this conversation now\".\n *\n * Output is deliberately excluded from that pressure sum, so the same\n * argument never applied to it — and taking it from the newest call reported\n * whatever the wrap-up message happened to cost, which is a couple of tokens\n * after a turn that wrote thousands. The turn total is the honest figure.\n *\n * The sidecar activity keeps the whole turn total for both — that is the\n * audit and cost record, and nothing divides it by a window. */\n #reportedUsage(\n active: ActiveTurn,\n result: Extract<NormalizedSdkMessage, { kind: 'result' }>,\n ): ClaudeUsage {\n const prompt = active.requestUsage\n if (prompt === undefined) return result.usage\n return {\n ...prompt,\n ...(result.usage.outputTokens === undefined ? {} : { outputTokens: result.usage.outputTokens }),\n }\n }\n\n async #completeProgressSegment(\n active: ActiveTurn,\n result: Extract<NormalizedSdkMessage, { kind: 'result' }>,\n recordUsage = true,\n ): Promise<void> {\n if (recordUsage && (result.usage.inputTokens !== undefined || result.usage.outputTokens !== undefined || result.usage.cumulativeCostUsd !== undefined)) {\n await this.#appendSafely(active, {\n kind: 'usage',\n phase: 'completed',\n title: 'Claude usage',\n summary: usageSummary(result.usage),\n usage: this.#timedUsage(active, result.usage),\n })\n active.output.push({ type: 'usage', usage: this.#reportedUsage(active, result) })\n }\n if (!active.sawTextDelta && active.text.length === 0 && result.text !== undefined) {\n active.text = result.text\n active.transcriptText = result.text\n await this.#upsertTranscriptText(active)\n active.output.push({ type: 'text-delta', text: result.text })\n }\n await this.#upsertTranscriptText(active)\n active.output.push({ type: 'segment-complete', text: active.text })\n active.sawTextDelta = false\n active.text = ''\n this.#closeTranscriptTextSegment(active)\n active.thinking = ''\n }\n\n async #completeTurn(\n entry: SupervisorEntry,\n active: ActiveTurn,\n result: Extract<NormalizedSdkMessage, { kind: 'result' }>,\n ): Promise<void> {\n if (entry.active !== active) return\n if (active.aborted) {\n await this.#upsertTranscriptText(active)\n await this.#flushTranscript(active)\n await this.#settleOpenCalls(active, 'Cancelled with the turn')\n await this.#appendSafely(active, {\n kind: 'status',\n phase: 'failed',\n title: 'Claude Code turn cancelled',\n })\n entry.active = undefined\n entry.state = 'idle'\n entry.lastUsedAt = Date.now()\n await this.#recordChainAnchor(entry, active)\n this.#checkpointProjection(entry)\n this.#armIdleTimer(entry)\n return\n }\n if (result.usage.inputTokens !== undefined || result.usage.outputTokens !== undefined || result.usage.cumulativeCostUsd !== undefined) {\n await this.#appendSafely(active, {\n kind: 'usage',\n phase: 'completed',\n title: 'Claude usage',\n summary: usageSummary(result.usage),\n usage: this.#timedUsage(active, result.usage),\n })\n active.output.push({ type: 'usage', usage: this.#reportedUsage(active, result) })\n }\n const unmatchedDenials = (result.permissionDenials ?? [])\n .filter(denial => !active.deniedToolUseIds.has(denial.toolUseId))\n if (unmatchedDenials.length > 0) {\n await this.#appendSafely(active, {\n kind: 'permission',\n phase: 'denied',\n title: 'Claude Code auto-denied tool calls',\n summary: unmatchedDenials.map(denial => denial.toolName).join(', '),\n })\n }\n if (!result.success) {\n if (!active.sawTextDelta && active.text.length === 0 && result.text !== undefined) {\n active.text = result.text\n active.transcriptText = result.text\n await this.#upsertTranscriptText(active)\n active.output.push({ type: 'text-delta', text: result.text })\n }\n await this.#upsertTranscriptText(active)\n await this.#flushTranscript(active)\n const message = result.errors?.join('\\n')\n ?? (result.terminalReason !== undefined ? `Claude Code failed the turn (${result.terminalReason})` : 'Claude Code failed the turn')\n await this.#appendSafely(active, {\n kind: 'error',\n phase: 'failed',\n title: 'Claude Code turn failed',\n summary: message,\n isError: true,\n })\n active.output.fail(new Error(message))\n } else {\n if (!active.sawTextDelta && active.text.length === 0 && result.text !== undefined) {\n active.text = result.text\n active.transcriptText = result.text\n await this.#upsertTranscriptText(active)\n active.output.push({ type: 'text-delta', text: result.text })\n }\n await this.#upsertTranscriptText(active)\n if (active.phase === 'primary' && this.#hasRunningTasks(entry, active)) {\n active.phase = 'waiting-tasks'\n await this.#appendSafely(active, {\n kind: 'status',\n phase: 'updated',\n title: 'Claude Code is waiting for background tasks',\n })\n await this.#completeProgressSegment(active, result, false)\n return\n }\n await this.#appendSafely(active, {\n kind: 'status',\n phase: 'completed',\n title: 'Claude Code turn completed',\n })\n await this.#flushTranscript(active)\n active.output.push({ type: 'complete', text: active.text })\n active.output.close()\n }\n if (active.signal !== undefined && active.abortListener !== undefined) {\n active.signal.removeEventListener('abort', active.abortListener)\n }\n entry.active = undefined\n entry.state = 'idle'\n entry.lastUsedAt = Date.now()\n await this.#recordChainAnchor(entry, active)\n await this.#learnContextWindow(entry)\n this.#checkpointProjection(entry)\n this.#armIdleTimer(entry)\n }\n\n /** Tell every reader where this session's delta stream ended.\n *\n * A reader that lost the turn's last delta has nothing later to reveal the\n * hole, and a settled turn produces nothing further -- so a finished tool\n * group would keep pulsing until the session was reopened by hand. Last\n * line of the turn, best effort: presentation must never unsettle it. */\n #checkpointProjection(entry: SupervisorEntry): void {\n try {\n this.#sidecar.checkpoint(entry.sessionId)\n } catch {\n // A reader that misses the checkpoint is no worse off than before it.\n }\n }\n\n /** Pin where Claude's chain ended for the DSH turn that just settled, so a\n * later rewind of the following turn can fork exactly here. Best effort:\n * a missing anchor only makes a rewind fall back to an earlier turn. */\n async #recordChainAnchor(entry: SupervisorEntry, active: ActiveTurn): Promise<void> {\n const uuid = entry.lastChainUuid\n if (uuid === undefined) return\n try {\n await this.#sidecar.recordRewindAnchor(entry.sessionId, active.cursor.turn, uuid)\n } catch {\n // The sidecar is advisory; a failed anchor never fails the turn.\n }\n }\n\n async #upsertTranscriptText(active: ActiveTurn): Promise<void> {\n if (active.transcriptText.length === 0) return\n const ordinal = active.transcriptTextOrdinal ?? active.cursor.nextOrdinal++\n active.transcriptTextOrdinal = ordinal\n try {\n // Hot path: notify live subscribers synchronously; disk persistence is\n // coalesced inside the repository and flushed at segment/turn edges.\n this.#sidecar.appendTranscriptText(active.agent.id as string, {\n text: active.transcriptText,\n ...(this.#nativeRendering() ? { renderer: 'native' as const } : {}),\n turn: active.cursor.turn,\n step: active.cursor.step,\n ordinal,\n })\n } catch {\n // Transcript persistence is presentational and must not change a Claude outcome.\n }\n }\n\n async #flushTranscript(active: ActiveTurn): Promise<void> {\n await this.#sidecar.flushTranscriptText(active.agent.id as string).catch(() => undefined)\n }\n\n #closeTranscriptTextSegment(active: ActiveTurn): void {\n void this.#flushTranscript(active)\n active.transcriptText = ''\n active.transcriptTextOrdinal = undefined\n }\n\n async #appendActivity(active: ActiveTurn, activity: ClaudeActivityInput): Promise<void> {\n const ordinal = active.cursor.nextOrdinal++\n await this.#sidecar.appendActivity(active.agent.id as string, {\n ...activity,\n // Stamp the renderer this record was produced for. The Client reads it\n // back per step, so a step drawn natively is never also drawn by the\n // plugin transcript -- and history keeps whichever renderer produced it.\n ...(this.#nativeRendering() ? { renderer: 'native' as const } : {}),\n turn: active.cursor.turn,\n step: active.cursor.step,\n ordinal,\n })\n }\n\n /** Persist durable activity without letting a storage failure unsettle the\n * in-memory turn or leak process ownership. Audit failure is best-effort. */\n async #appendSafely(active: ActiveTurn, activity: ClaudeActivityInput): Promise<void> {\n await this.#appendActivity(active, activity).catch(() => undefined)\n }\n\n #startInterrupt(entry: SupervisorEntry): Promise<void> {\n const existing = this.#interruptions.get(entry.sessionId)\n if (existing !== undefined) return existing\n const interruption = this.#interrupt(entry).finally(() => {\n this.#interruptions.delete(entry.sessionId)\n })\n this.#interruptions.set(entry.sessionId, interruption)\n return interruption\n }\n\n /** Close out the root tool calls a turn is ending without answers for.\n *\n * A tool result is the only thing that ever settles a call, and a turn that\n * is cancelled or disconnected produces none: the transcript would keep\n * drawing those calls as running for as long as the session lives, and no\n * later event would ever correct it. Written as the failures they are. */\n async #settleOpenCalls(active: ActiveTurn, summary: string): Promise<void> {\n const open = [...active.openCalls]\n active.openCalls.clear()\n for (const [toolUseId, toolName] of open) {\n await this.#appendSafely(active, {\n kind: 'tool-result',\n phase: 'failed',\n toolUseId,\n toolName,\n title: 'Tool cancelled',\n summary,\n isError: true,\n })\n // The native card has the same hole, and the same fix as a denied call.\n if (this.#nativeRendering()) {\n await this.#appendNativeToolResult(active, {\n kind: 'tool-result',\n toolUseId,\n output: summary,\n isError: true,\n })\n }\n }\n }\n\n async #interrupt(entry: SupervisorEntry): Promise<void> {\n const active = entry.active\n if (active === undefined || entry.state === 'interrupting') return\n entry.state = 'interrupting'\n active.aborted = true\n active.output.fail(abortFailure())\n await this.#upsertTranscriptText(active)\n let interruptError: unknown\n try {\n const receipt = await withTimeout(entry.query.interrupt(), CLAUDE_INTERRUPT_TIMEOUT_MS, 'Claude Code interrupt')\n const queued = receipt?.still_queued ?? []\n if (queued.includes(active.promptUuid)) {\n throw new Error(`Claude Code interrupt left submitted prompt ${active.promptUuid} queued`)\n }\n } catch (error) {\n interruptError = error\n }\n await this.#settleOpenCalls(active, 'Cancelled with the turn').catch(() => undefined)\n try {\n await this.#appendActivity(active, {\n kind: 'status',\n phase: 'failed',\n title: interruptError === undefined ? 'Claude Code turn cancelled' : 'Claude Code cancelled; process entry reset',\n ...(interruptError === undefined ? {} : { summary: errorSummary(interruptError) }),\n })\n } catch {\n // The active output is already aborted; process cleanup cannot wait for audit availability.\n }\n if (this.#entries.get(entry.sessionId) === entry) this.#entries.delete(entry.sessionId)\n await this.#disposeEntry(entry)\n }\n\n async #handleDisconnect(entry: SupervisorEntry, error: unknown): Promise<void> {\n const active = entry.active\n const stderr = entry.process?.stderrTail()\n if (active !== undefined) {\n await this.#upsertTranscriptText(active)\n await this.#flushTranscript(active)\n if (active.signal !== undefined && active.abortListener !== undefined) {\n active.signal.removeEventListener('abort', active.abortListener)\n }\n const unknown = active.sawActivity\n entry.state = unknown ? 'outcome-unknown' : 'disconnected'\n const failure = unknown\n ? new ClaudeOutcomeUnknownError(stderr === undefined || stderr.length === 0 ? undefined : `Claude Code exited after activity; outcome unknown. ${stderr}`)\n : new Error(stderr === undefined || stderr.length === 0 ? errorSummary(error) : stderr)\n await this.#settleOpenCalls(active, 'Claude Code stopped before the tool answered').catch(() => undefined)\n await this.#appendSafely(active, {\n kind: 'error',\n phase: 'failed',\n title: unknown ? 'Claude Code outcome unknown' : 'Claude Code disconnected',\n summary: failure.message,\n isError: true,\n detail: error,\n })\n active.output.fail(failure)\n entry.active = undefined\n } else {\n entry.state = 'disconnected'\n }\n this.#entries.delete(entry.sessionId)\n await this.#disposeEntry(entry)\n }\n\n #armIdleTimer(entry: SupervisorEntry): void {\n if (this.#config.idleTimeoutMs <= 0) return\n const timer = setTimeout(() => {\n if (entry.active !== undefined || entry.state !== 'idle') return\n this.#entries.delete(entry.sessionId)\n void this.#disposeEntry(entry)\n }, this.#config.idleTimeoutMs)\n timer.unref?.()\n entry.idleTimer = timer\n }\n\n async #disposeEntry(entry: SupervisorEntry): Promise<void> {\n if (entry.state === 'disposed') return\n if (entry.idleTimer !== undefined) clearTimeout(entry.idleTimer)\n entry.state = 'disposed'\n entry.input.discard(abortFailure())\n entry.query.close()\n entry.lifetime.abort()\n if (entry.active !== undefined) entry.active.output.fail(abortFailure())\n entry.process?.kill('SIGTERM')\n if (entry.process !== undefined) {\n try {\n await entry.process.handle.waitForExit(AbortSignal.timeout(5_000))\n } catch {\n // The DSH subprocess owner still holds the tree and will finish escalation.\n }\n }\n }\n}\n","import { randomUUID } from 'node:crypto'\n\nconst MAX_COMMENTS_PER_SESSION = 50\nconst MAX_TEXT_CHARS = 2_000\nconst MAX_PATH_CHARS = 1_024\nconst MAX_LINE = 10_000_000\n\nexport type ReviewCommentSide = 'old' | 'new'\n\nexport interface ReviewComment {\n readonly id: string\n readonly path: string\n /** Last (anchor) line of the comment. */\n readonly line: number\n /** First line when the comment spans a range; absent for single-line comments. */\n readonly startLine?: number\n readonly side: ReviewCommentSide\n readonly text: string\n}\n\nexport class ReviewCommentError extends Error {\n readonly code: string\n\n constructor(code: string, message: string) {\n super(message)\n this.name = 'ReviewCommentError'\n this.code = code\n }\n}\n\nfunction validSide(value: unknown): value is ReviewCommentSide {\n return value === 'old' || value === 'new'\n}\n\n/** Pending line comments queued per session until the next user turn drains them. */\nexport class ReviewCommentStore {\n readonly #comments = new Map<string, ReviewComment[]>()\n\n add(sessionId: string, input: { path: unknown; line: unknown; startLine?: unknown; side: unknown; text: unknown }): ReviewComment {\n const path = typeof input.path === 'string' ? input.path.trim() : ''\n const text = typeof input.text === 'string' ? input.text.trim() : ''\n if (path.length === 0 || path.length > MAX_PATH_CHARS || /[\\0\\r\\n]/u.test(path)) {\n throw new ReviewCommentError('invalid-request', 'The comment path is invalid.')\n }\n if (text.length === 0 || text.length > MAX_TEXT_CHARS || text.includes('\\0')) {\n throw new ReviewCommentError('invalid-request', 'The comment text is invalid.')\n }\n if (typeof input.line !== 'number' || !Number.isSafeInteger(input.line) || input.line < 1 || input.line > MAX_LINE) {\n throw new ReviewCommentError('invalid-request', 'The comment line is invalid.')\n }\n if (!validSide(input.side)) throw new ReviewCommentError('invalid-request', 'The comment side is invalid.')\n const startLine = input.startLine === undefined || input.startLine === null ? undefined : input.startLine\n if (startLine !== undefined && (typeof startLine !== 'number' || !Number.isSafeInteger(startLine) || startLine < 1 || startLine > input.line)) {\n throw new ReviewCommentError('invalid-request', 'The comment start line is invalid.')\n }\n const existing = this.#comments.get(sessionId) ?? []\n if (existing.length >= MAX_COMMENTS_PER_SESSION) {\n throw new ReviewCommentError('too-many-comments', 'Too many pending review comments. Remove one before adding another.')\n }\n const comment: ReviewComment = { id: randomUUID(), path, line: input.line, ...(startLine === undefined || startLine === input.line ? {} : { startLine }), side: input.side, text }\n this.#comments.set(sessionId, [...existing, comment])\n return comment\n }\n\n remove(sessionId: string, id: string): boolean {\n const existing = this.#comments.get(sessionId)\n if (existing === undefined) return false\n const next = existing.filter(comment => comment.id !== id)\n if (next.length === existing.length) return false\n if (next.length === 0) this.#comments.delete(sessionId)\n else this.#comments.set(sessionId, next)\n return true\n }\n\n list(sessionId: string): readonly ReviewComment[] {\n return this.#comments.get(sessionId) ?? []\n }\n\n /** Remove and return every pending comment; called when a user turn consumes them. */\n drain(sessionId: string): readonly ReviewComment[] {\n const existing = this.#comments.get(sessionId) ?? []\n this.#comments.delete(sessionId)\n return existing\n }\n\n disposeSession(sessionId: string): void {\n this.#comments.delete(sessionId)\n }\n\n dispose(): void {\n this.#comments.clear()\n }\n}\n\n/** Render drained comments as the prompt block preceding the user's message text. */\nexport function formatReviewComments(comments: readonly ReviewComment[]): string {\n const lines = comments.map((comment, index) => (\n `${index + 1}. ${comment.path}:${comment.startLine === undefined ? comment.line : `${comment.startLine}-${comment.line}`}${comment.side === 'old' ? ' (old side)' : ''} — ${comment.text}`\n ))\n return [\n '<user-review-comments>',\n 'The user attached these code review comments to this message. Each references a file and line (or line range) from the current working tree diff:',\n ...lines,\n '</user-review-comments>',\n ].join('\\n')\n}\n","import {\n LlmAdapter,\n ReasoningEffortId,\n type GenerateOptions,\n type LlmModelInfo,\n type LlmProviderInfo,\n type LlmResolvedModelInfo,\n type PreparedAdapterCall,\n type ResolvedRetryPolicy,\n type StreamChunk,\n type TokenUsage,\n} from '@deepseek-ai/dsh-llm'\nimport type { Agent, AgentRegistry } from '@deepseek-ai/dsh-agent'\nimport type { AttachmentStore, ImageAttachmentRef, ImageMediaType } from '@deepseek-ai/dsh-attachment'\nimport type { SDKUserMessage } from '@anthropic-ai/claude-agent-sdk'\nimport { CLAUDE_CODE_PRESET_ID, CLAUDE_CODE_PROVIDER, DEFAULT_CLAUDE_RENDER_MODE, type ClaudeRenderMode } from './constants.ts'\nimport type { ClaudeSupervisor, ClaudeThinkingMode } from './supervisor.ts'\nimport type { ClaudeUsage } from './events.ts'\nimport { claudeModelRow, latestClaudeModels } from './model-catalog.ts'\nimport { formatReviewComments, type ReviewComment } from './review-comments.ts'\n\nconst THINKING_MODES = [\n { id: 'off', name: 'Off', description: 'No extended thinking.' },\n { id: 'low', name: 'Low', description: 'Minimal thinking, fastest responses.' },\n { id: 'medium', name: 'Medium', description: 'Moderate thinking.' },\n { id: 'high', name: 'High', description: 'Deep reasoning (Claude Code default).' },\n { id: 'xhigh', name: 'Extra High', description: 'Deeper than high; unsupported models silently downgrade to high.' },\n { id: 'max', name: 'Max', description: 'Maximum effort; unsupported models silently downgrade.' },\n { id: 'ultracode', name: 'Ultracode', description: 'Extra-high effort plus standing dynamic-workflow orchestration; requires an xhigh-capable model.' },\n] as const\n\nexport function thinkingModeFor(effort: ReasoningEffortId | undefined): ClaudeThinkingMode | undefined {\n if (effort === undefined) return undefined\n if (THINKING_MODES.some(mode => mode.id === (effort as string))) return effort as unknown as ClaudeThinkingMode\n throw new Error(`dsh-claude: unsupported reasoning effort ${JSON.stringify(effort)}`)\n}\n\nconst NO_RETRY_POLICY: ResolvedRetryPolicy = Object.freeze({\n mode: 'normal',\n maxRetries: 0,\n retryableCodes: Object.freeze([]),\n initialDelayMs: 500,\n maxDelayMs: 10_000,\n jitterRatio: 0.1,\n})\n\ntype ClaudePrompt = SDKUserMessage['message']['content']\ntype ClaudePromptBlock = Exclude<ClaudePrompt, string>[number]\ntype AttachmentReader = Pick<AttachmentStore, 'imageLimits' | 'readImage'>\n\nfunction abortIfRequested(signal: AbortSignal | undefined): void {\n if (signal?.aborted !== true) return\n if (signal.reason instanceof Error) throw signal.reason\n const error = new Error('Claude Code input resolution aborted')\n error.name = 'AbortError'\n throw error\n}\n\nfunction finiteNonNegative(value: unknown): value is number {\n return typeof value === 'number' && Number.isFinite(value) && value >= 0\n}\n\nfunction validateImageRef(ref: ImageAttachmentRef, attachments: AttachmentReader, imageIndex: number): void {\n const limits = attachments.imageLimits\n if (!limits.mediaTypes.includes(ref.mediaType)) {\n throw new Error(`dsh-claude: image ${imageIndex} has an unsupported media type`)\n }\n if (!finiteNonNegative(ref.bytes) || ref.bytes > limits.maxImageBytes) {\n throw new Error(`dsh-claude: image ${imageIndex} exceeds the configured byte limit`)\n }\n const maxDimension = 'maxImageDimension' in limits && finiteNonNegative(limits.maxImageDimension)\n ? limits.maxImageDimension\n : undefined\n if (!finiteNonNegative(ref.width) || !finiteNonNegative(ref.height)\n || ref.width * ref.height > limits.maxImagePixels\n || (maxDimension !== undefined && (ref.width > maxDimension || ref.height > maxDimension))) {\n throw new Error(`dsh-claude: image ${imageIndex} exceeds the configured dimension limit`)\n }\n}\n\n/**\n * Prepend the session's pending diff-review comments to the outgoing user\n * prompt. The comments are drained once per turn: they are formatted into one\n * `<user-review-comments>` block placed ahead of the user's own text (or as a\n * leading text block for multi-part prompts) so Claude reads them in the same\n * turn that consumed them.\n */\nexport function injectReviewComments(prompt: ClaudePrompt, comments: readonly ReviewComment[]): ClaudePrompt {\n if (comments.length === 0) return prompt\n const block = formatReviewComments(comments)\n if (typeof prompt === 'string') return `${block}\\n\\n${prompt}`\n return [{ type: 'text', text: block }, ...prompt]\n}\n\nfunction imageBlock(data: Uint8Array, mediaType: ImageMediaType): ClaudePromptBlock {\n return {\n type: 'image',\n source: {\n type: 'base64',\n media_type: mediaType,\n data: Buffer.from(data.buffer, data.byteOffset, data.byteLength).toString('base64'),\n },\n }\n}\n\n/** Resolve only the newest direct human message; Claude's session owns history. */\nexport async function resolveDirectUserPrompt(\n messages: GenerateOptions['messages'],\n attachments: AttachmentReader,\n signal?: AbortSignal,\n): Promise<ClaudePrompt> {\n const message = [...messages].reverse().find(candidate => (\n candidate.role === 'user' && candidate.source.kind === 'user'\n ))\n if (message === undefined) {\n throw new Error('dsh-claude: no direct human input was present in this model step')\n }\n\n const imageRefs = message.content\n .filter((block): block is Extract<typeof block, { type: 'image' }> => block.type === 'image')\n .map(block => block.attachment)\n const limits = attachments.imageLimits\n if (imageRefs.length > limits.maxImagesPerMessage) {\n throw new Error('dsh-claude: prompt exceeds the configured image-count limit')\n }\n let declaredBytes = 0\n imageRefs.forEach((ref, index) => {\n validateImageRef(ref, attachments, index + 1)\n declaredBytes += ref.bytes\n if (!Number.isSafeInteger(declaredBytes) || declaredBytes > limits.maxMessageImageBytes) {\n throw new Error('dsh-claude: prompt exceeds the configured aggregate image-byte limit')\n }\n })\n\n if (imageRefs.length === 0) {\n const text = message.content\n .filter((block): block is Extract<typeof block, { type: 'text' }> => block.type === 'text')\n .map(block => block.text)\n .join('\\n')\n .trim()\n if (text.length > 0) return text\n throw new Error('dsh-claude: the newest direct human message has no supported content')\n }\n\n const content: ClaudePromptBlock[] = []\n let imageIndex = 0\n let verifiedBytes = 0\n for (const block of message.content) {\n abortIfRequested(signal)\n if (block.type === 'text') {\n content.push({ type: 'text', text: block.text })\n continue\n }\n if (block.type !== 'image') continue\n imageIndex += 1\n let stored: Awaited<ReturnType<AttachmentStore['readImage']>>\n try {\n stored = await attachments.readImage(block.attachment, signal)\n } catch {\n abortIfRequested(signal)\n throw new Error(`dsh-claude: image ${imageIndex} could not be read or verified`)\n }\n abortIfRequested(signal)\n validateImageRef(stored.ref, attachments, imageIndex)\n if (stored.data.byteLength !== stored.ref.bytes || stored.ref.mediaType !== block.attachment.mediaType) {\n throw new Error(`dsh-claude: image ${imageIndex} failed attachment verification`)\n }\n verifiedBytes += stored.data.byteLength\n if (!Number.isSafeInteger(verifiedBytes) || verifiedBytes > limits.maxMessageImageBytes) {\n throw new Error('dsh-claude: prompt exceeds the configured aggregate image-byte limit')\n }\n content.push(imageBlock(stored.data, stored.ref.mediaType))\n }\n if (content.length === 0) {\n throw new Error('dsh-claude: the newest direct human message has no supported content')\n }\n return content\n}\n\nfunction tokenUsage(usage: ClaudeUsage): TokenUsage {\n const normalized: TokenUsage = {\n inputTokens: usage.inputTokens ?? 0,\n outputTokens: usage.outputTokens ?? 0,\n }\n if (usage.cacheReadTokens !== undefined) normalized.cacheReadTokens = usage.cacheReadTokens\n if (usage.cacheCreationTokens !== undefined) normalized.cacheWriteTokens = usage.cacheCreationTokens\n return normalized\n}\n\nfunction resolveAgent(agents: Pick<AgentRegistry, 'currentInitiator' | 'get'>, options: GenerateOptions): Agent {\n const initiator = agents.currentInitiator()\n if (initiator !== undefined) return initiator\n if (options.sessionId !== undefined) {\n const agent = agents.get(options.sessionId)\n if (agent !== undefined) return agent\n }\n throw new Error('dsh-claude: the model request has no live owning DSH agent')\n}\n\nexport class ClaudeCodeAdapter extends LlmAdapter {\n readonly #supervisor: ClaudeSupervisor\n readonly #agents: Pick<AgentRegistry, 'currentInitiator' | 'get'>\n readonly #attachments: AttachmentReader\n readonly #presetIdFor: (agent: Agent) => string | undefined\n readonly #drainReviewComments: (sessionId: string) => readonly ReviewComment[]\n readonly #renderMode: () => ClaudeRenderMode\n\n constructor(\n supervisor: ClaudeSupervisor,\n agents: Pick<AgentRegistry, 'currentInitiator' | 'get'>,\n attachments: AttachmentReader,\n presetIdFor: (agent: Agent) => string | undefined,\n drainReviewComments: (sessionId: string) => readonly ReviewComment[] = () => [],\n renderMode: () => ClaudeRenderMode = () => DEFAULT_CLAUDE_RENDER_MODE,\n ) {\n super()\n this.#supervisor = supervisor\n this.#agents = agents\n this.#attachments = attachments\n this.#presetIdFor = presetIdFor\n this.#drainReviewComments = drainReviewComments\n this.#renderMode = renderMode\n }\n\n override providerInfo(provider: string): LlmProviderInfo {\n return { id: provider, name: 'Claude Code' }\n }\n\n override providerRetryPolicy(): ResolvedRetryPolicy {\n return NO_RETRY_POLICY\n }\n\n override async listModels(provider: string): Promise<readonly LlmModelInfo[]> {\n return latestClaudeModels().map(model => ({\n provider,\n id: model.id,\n name: model.name,\n description: model.description,\n inputModalities: ['text', 'image'],\n }))\n }\n\n override async resolveModel(provider: string, model: string, _signal?: AbortSignal): Promise<LlmResolvedModelInfo> {\n const known = claudeModelRow(model)\n const contextWindow = this.#supervisor.contextWindow(model) ?? known?.contextWindow\n return {\n provider,\n id: model,\n name: known?.name ?? `Claude Code ${model}`,\n ...(known === undefined ? {} : { description: known.description }),\n ...(contextWindow === undefined ? {} : { context: { contextWindow } }),\n inputModalities: ['text', 'image'],\n reasoning: {\n efforts: THINKING_MODES.map(mode => ({\n id: ReasoningEffortId(mode.id),\n name: mode.name,\n description: mode.description,\n })),\n },\n }\n }\n\n override async prepareCall(\n provider: string,\n model: string,\n signal?: AbortSignal,\n ): Promise<PreparedAdapterCall> {\n return {\n model: await this.resolveModel(provider, model, signal),\n stream: options => this.stream(options),\n }\n }\n\n override async *stream(options: GenerateOptions): AsyncIterable<StreamChunk> {\n if (options.purpose !== undefined) {\n throw new Error(`dsh-claude: auxiliary ${options.purpose} calls are not routed into the Claude session`)\n }\n const agent = resolveAgent(this.#agents, options)\n if (this.#presetIdFor(agent) !== CLAUDE_CODE_PRESET_ID) {\n throw new Error(`dsh-claude: provider ${CLAUDE_CODE_PROVIDER} is available only to the ${CLAUDE_CODE_PRESET_ID} preset`)\n }\n const thinkingMode = thinkingModeFor(options.reasoningEffort)\n let prompt: ClaudePrompt\n try {\n prompt = await resolveDirectUserPrompt(options.messages, this.#attachments, options.signal)\n } catch (error) {\n if ((error as Error).name !== 'AbortError') throw error\n yield {\n type: 'finish',\n reason: {\n kind: 'aborted',\n failure: { code: 'aborted', message: error instanceof Error ? error.message : 'Claude Code input resolution aborted' },\n },\n }\n return\n }\n const events = await this.#supervisor.runTurn({\n agent,\n prompt: injectReviewComments(prompt, this.#drainReviewComments(agent.id as string)),\n model: options.model,\n ...(thinkingMode === undefined ? {} : { thinkingMode }),\n ...(options.signal === undefined ? {} : { signal: options.signal }),\n })\n\n // The plugin renderer draws the visible transcript from the sidecar, so\n // prose and Claude tool groups share one exact ordinal stream and DSH\n // receives only an empty assistant completion anchor plus usage/lifecycle\n // metadata. The native renderer needs the opposite: every visible span\n // arrives as ordinary DSH content blocks.\n const native = this.#renderMode() === 'native'\n let pendingUsage: TokenUsage | undefined\n let completed = false\n let blockIndex = 0\n let text = ''\n /** Settle the buffered prose as one text block. Each Claude result is one\n * block so tool activity stays ahead of the prose it explains and a\n * background-task report can follow in a block of its own. */\n function* flushText(): Generator<StreamChunk> {\n if (text.length === 0) return\n const settled = text\n text = ''\n yield { type: 'block-start', index: blockIndex, blockType: 'text' }\n yield { type: 'text-delta', index: blockIndex, text: settled }\n yield { type: 'block-end', index: blockIndex, block: { type: 'text', text: settled } }\n blockIndex += 1\n }\n try {\n for await (const event of events) {\n if (event.type === 'usage') {\n pendingUsage = tokenUsage(event.usage)\n continue\n }\n if (event.type === 'text-delta') {\n if (native) text += event.text\n continue\n }\n if (event.type === 'thinking') {\n if (!native) continue\n // Thinking settles before the prose it precedes, so nothing is\n // buffered yet; flush anyway to keep block order faithful when a\n // model interleaves the two.\n yield* flushText()\n yield { type: 'block-start', index: blockIndex, blockType: 'reasoning' }\n yield { type: 'reasoning-delta', index: blockIndex, text: event.text }\n yield { type: 'block-end', index: blockIndex, block: { type: 'reasoning', text: event.text } }\n blockIndex += 1\n continue\n }\n yield* flushText()\n if (event.type === 'segment-complete') continue\n completed = true\n if (pendingUsage !== undefined) yield { type: 'usage', usage: pendingUsage }\n yield { type: 'finish', reason: { kind: 'stop' } }\n }\n } catch (error) {\n if ((error as Error).name === 'AbortError') {\n completed = true\n yield* flushText()\n yield {\n type: 'finish',\n reason: {\n kind: 'aborted',\n failure: { code: 'aborted', message: error instanceof Error ? error.message : 'Claude Code turn aborted' },\n },\n }\n return\n }\n throw error\n }\n if (!completed) throw new Error('dsh-claude: Claude turn stream ended without a result')\n }\n}\n\nexport function createClaudeCodeAdapter(\n supervisor: ClaudeSupervisor,\n agents: Pick<AgentRegistry, 'currentInitiator' | 'get'>,\n attachments: AttachmentReader,\n presetIdFor: (agent: Agent) => string | undefined,\n drainReviewComments: (sessionId: string) => readonly ReviewComment[] = () => [],\n renderMode: () => ClaudeRenderMode = () => DEFAULT_CLAUDE_RENDER_MODE,\n): ClaudeCodeAdapter {\n return new ClaudeCodeAdapter(supervisor, agents, attachments, presetIdFor, drainReviewComments, renderMode)\n}\n","/**\n * The plugin's connection budget, in one table.\n *\n * A browser opens a small fixed number of connections to one origin — six for\n * HTTP/1.1 in Chromium — and shares them with the Host's own traffic. Every\n * response this plugin holds open costs one of them for its lifetime, and a\n * request that cannot get one waits in the browser's queue where no server-side\n * deadline can reach it. When the pool is exhausted the panels that would\n * *diagnose* the problem are the first thing to stop answering, which is how\n * this failure has always presented: four settings cards timing out at once\n * against a Host that is demonstrably healthy.\n *\n * So the budget is a fixed constant rather than a function of how much work is\n * in flight. Steady state is one connection (the multiplexed projection\n * carrier); the peak is `PLUGIN_GLOBAL_PERMITS`, whatever the session count.\n *\n * Both halves read this file, which is the point: a route declares a budget\n * class and the client derives its wait from the same entry, so a server\n * deadline can never be quietly longer than the client's patience.\n */\n\n/** Server-side budget classes. A route declares a class, never a number. */\nexport const ROUTE_BUDGET_MS = {\n /** Answers from memory or a single bounded probe. */\n fast: 5_000,\n /** Chains local Git work. */\n git: 45_000,\n /** Reaches the network: remote Git, `gh`, the npm registry. */\n remote: 150_000,\n} as const\n\nexport type RouteBudget = keyof typeof ROUTE_BUDGET_MS\n\n/** The client waits one round trip longer, so the route's own 504 wins the\n * race and the caller learns which budget elapsed instead of guessing. */\nexport const CLIENT_GRACE_MS = 3_000\n\nexport function clientBudgetMs(budget: RouteBudget): number {\n return ROUTE_BUDGET_MS[budget] + CLIENT_GRACE_MS\n}\n\n/** A request that never got a permit fails fast and says so, rather than\n * spending its whole budget queued behind work it cannot see. */\nexport const QUEUE_WAIT_BUDGET_MS = 4_000\n\n/** Connections this plugin may hold at once, across every lane. */\nexport const PLUGIN_GLOBAL_PERMITS = 4\n\n/** Per-lane ceilings inside the global budget.\n *\n * The projection carrier holds a permanently reserved permit outside these,\n * so three remain. `write + stream <= 2` leaves one permit that only a read\n * can take: a diagnostic read always has somewhere to go, however many slow\n * actions are in flight. That invariant is what stops a 150s repository\n * action from reproducing the original symptom through a new mechanism. */\nexport const PLUGIN_LANE_CAPS = { read: 2, write: 1, stream: 1 } as const\n\nexport type PluginLane = keyof typeof PLUGIN_LANE_CAPS\n\n/** Both halves cap the multiplex at the same number. */\nexport const MAX_MULTIPLEX_SESSIONS = 16\n","import type { IncomingMessage, ServerResponse } from 'node:http'\nimport type { Context } from '@deepseek-ai/cordis'\nimport type { WebRouteKind } from '@deepseek-ai/dsh-host-webserver'\nimport { deadline } from '@deepseek-ai/dsh-timeout'\nimport { ROUTE_BUDGET_MS, type RouteBudget } from './plugin-budget.ts'\n\n/** Accept only loopback, same-origin browser requests to plugin-private routes. */\nexport function trustedRequest(req: IncomingMessage): boolean {\n const remote = req.socket.remoteAddress\n if (remote !== '127.0.0.1' && remote !== '::1' && remote !== '::ffff:127.0.0.1') return false\n const site = req.headers['sec-fetch-site']\n if (site === 'cross-site') return false\n const host = req.headers.host\n if (host === undefined) return false\n const authority = /^(?:127\\.0\\.0\\.1|\\[?::1\\]?|localhost)(?::\\d+)?$/i\n if (!authority.test(host)) return false\n const origin = req.headers.origin\n if (origin === undefined) return true\n try {\n const originUrl = new URL(origin)\n return originUrl.host === host && authority.test(originUrl.host)\n } catch {\n return false\n }\n}\n\n/** Send a non-cacheable JSON response with MIME sniffing disabled. */\nexport function json(res: ServerResponse, status: number, value: unknown): void {\n res.writeHead(status, {\n 'content-type': 'application/json; charset=utf-8',\n 'cache-control': 'no-store',\n 'x-content-type-options': 'nosniff',\n })\n res.end(JSON.stringify(value))\n}\n\nconst ROUTE_TIMEOUT_CODE = 'DSH_CLAUDE_ROUTE'\nconst DEFAULT_BODY_BYTES = 1024 * 1024\n\nexport type PluginMethod = 'GET' | 'POST' | 'PATCH' | 'DELETE'\n\n/** What a route handler is given. Deliberately not the `ServerResponse`: a\n * unary handler that cannot reach the socket cannot hold it open. */\nexport interface PluginRouteIo {\n /** Aborts on client disconnect OR when the route's budget elapses. */\n readonly signal: AbortSignal\n readonly method: PluginMethod\n readonly url: URL\n /** Read the request body once, byte-capped, as JSON. */\n body<T = Record<string, unknown>>(maxBytes?: number): Promise<T>\n}\n\nexport interface PluginUnaryRoute {\n mode: 'unary'\n kind: WebRouteKind\n path: string\n methods: readonly PluginMethod[]\n budget: RouteBudget\n /** No `ServerResponse` in scope, by construction. */\n handler: (io: PluginRouteIo) => Promise<{ status: number; value: unknown }>\n}\n\nexport interface PluginStreamRoute {\n mode: 'stream'\n kind: WebRouteKind\n path: string\n methods: readonly PluginMethod[]\n /** Hard ceiling on live responses for this path; the oldest is evicted. */\n maxConcurrent: number\n /** Dedupe identity; a second open with the same key supersedes the first. */\n streamKey: (url: URL) => string\n handler: (res: ServerResponse, io: PluginRouteIo) => Promise<void>\n}\n\nexport type PluginRoute = PluginUnaryRoute | PluginStreamRoute\n\n/** Bounds live streaming responses per path, so a teardown bug cannot become a\n * permanent connection leak. Registration is per path, not global, because a\n * wedged projection stream must not evict an in-flight repository setup. */\nclass StreamRegistry {\n readonly #open = new Map<string, Map<string, () => void>>()\n\n admit(path: string, key: string, max: number, close: () => void): () => void {\n let live = this.#open.get(path)\n if (live === undefined) {\n live = new Map()\n this.#open.set(path, live)\n }\n // A reopen under the same identity is the client reconnecting; the older\n // response is the stale one, so it goes rather than the new arrival.\n live.get(key)?.()\n live.set(key, close)\n while (live.size > max) {\n const oldest = live.keys().next()\n if (oldest.done === true) break\n const evict = live.get(oldest.value)\n live.delete(oldest.value)\n evict?.()\n }\n return () => {\n const current = this.#open.get(path)\n if (current?.get(key) === close) current.delete(key)\n }\n }\n}\n\nconst streams = new StreamRegistry()\n\nfunction isPluginMethod(value: string | undefined): value is PluginMethod {\n return value === 'GET' || value === 'POST' || value === 'PATCH' || value === 'DELETE'\n}\n\n/** Distinguishable so the wrapper can answer 413 rather than folding an\n * oversized body into whatever generic failure the handler reports. */\nexport class PluginBodyTooLargeError extends Error {\n constructor() {\n super('Request body is too large')\n this.name = 'PluginBodyTooLargeError'\n }\n}\n\nasync function readBody(req: IncomingMessage, maxBytes: number): Promise<unknown> {\n const declared = Number(req.headers['content-length'] ?? 0)\n if (!Number.isFinite(declared) || declared < 0 || declared > maxBytes) throw new PluginBodyTooLargeError()\n const chunks: Buffer[] = []\n let bytes = 0\n for await (const chunk of req) {\n const data = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk as Uint8Array)\n bytes += data.byteLength\n if (bytes > maxBytes) throw new PluginBodyTooLargeError()\n chunks.push(data)\n }\n if (bytes === 0) return {}\n return JSON.parse(Buffer.concat(chunks).toString('utf8')) as unknown\n}\n\nfunction rejectOn(signal: AbortSignal): Promise<never> {\n return new Promise((_resolve, reject) => {\n if (signal.aborted) {\n reject(signal.reason as Error)\n return\n }\n signal.addEventListener('abort', () => reject(signal.reason as Error), { once: true })\n })\n}\n\n/**\n * Register one plugin route.\n *\n * This is the only place in the package that calls `ctx.webServer.register`,\n * and the ordering inside it is the fix rather than an implementation detail:\n * the disconnect listeners are attached before the first `await`, so a client\n * that goes away while the handler is still assembling its first response\n * still tears the route's work down. The previous per-route code attached\n * `res.on('close')` after awaiting an unbounded repository probe, which is how\n * the projection stream reached 53 opens against 33 closes.\n */\nexport function registerPluginRoute(ctx: Context, route: PluginRoute): void {\n const label = `dsh-claude: ${route.path}`\n ctx.effect(() => ctx.webServer.register({\n kind: route.kind,\n path: route.path,\n handler: async (req, res) => {\n const method = req.method\n if (!isPluginMethod(method) || !route.methods.includes(method)) {\n return json(res, 405, { error: 'method not allowed' })\n }\n if (!trustedRequest(req)) return json(res, 403, { error: 'forbidden' })\n // Before any await: a disconnect during setup must still cancel.\n const aborted = new AbortController()\n const abort = (): void => { aborted.abort() }\n // `req` emits 'close' when the request is COMPLETE, not only when the\n // client vanishes — so reading a body fires it, and an unguarded abort\n // here cancels every POST route the instant it parses its own input.\n // `complete` is what tells the two apart.\n req.on('close', () => { if (!req.complete) abort() })\n res.on('close', abort)\n const url = new URL(req.url ?? '/', 'http://localhost')\n if (route.mode === 'stream') {\n const release = streams.admit(route.path, route.streamKey(url), route.maxConcurrent, abort)\n const io: PluginRouteIo = {\n signal: aborted.signal,\n method,\n url,\n body: async <T,>(maxBytes = DEFAULT_BODY_BYTES) => await readBody(req, maxBytes) as T,\n }\n try {\n await route.handler(res, io)\n } catch (error) {\n if (!res.headersSent) json(res, 500, { error: 'stream-failed' })\n ctx.logger.warn(`dsh-claude: ${route.path} stream failed: ${error instanceof Error ? error.message : String(error)}`)\n } finally {\n release()\n res.end()\n }\n return\n }\n const budgetMs = ROUTE_BUDGET_MS[route.budget]\n const bounded = deadline(aborted.signal, budgetMs, ROUTE_TIMEOUT_CODE)\n const io: PluginRouteIo = {\n signal: bounded.signal,\n method,\n url,\n body: async <T,>(maxBytes = DEFAULT_BODY_BYTES) => await readBody(req, maxBytes) as T,\n }\n try {\n const result = await Promise.race([route.handler(io), rejectOn(bounded.signal)])\n if (!res.writableEnded) json(res, result.status, result.value)\n } catch (error) {\n if (res.writableEnded || res.headersSent) return\n if (bounded.signal.aborted && !aborted.signal.aborted) {\n return json(res, 504, { error: 'deadline', budget: route.budget, ms: budgetMs })\n }\n if (aborted.signal.aborted) return\n if (error instanceof PluginBodyTooLargeError) {\n return json(res, 413, { error: 'body-too-large', message: 'The request body is too large.' })\n }\n json(res, 400, { error: error instanceof Error ? error.message : 'request failed' })\n } finally {\n bounded[Symbol.dispose]()\n }\n },\n }), label)\n}\n\n/**\n * Memoise an executable lookup with a deadline, dropping the cache when it\n * fails.\n *\n * A route budget frees the socket but does nothing about a cached promise that\n * never settles: one hung PATH probe otherwise poisons every later request for\n * the life of the process, and the route deadline just turns that into a\n * steady stream of 504s. Caching only the resolved value keeps the retry.\n */\nexport function memoizeExecutable(\n resolve: (signal: AbortSignal) => Promise<string>,\n timeoutMs: number,\n): () => Promise<string> {\n let pending: Promise<string> | undefined\n return () => {\n if (pending !== undefined) return pending\n const bounded = deadline(undefined, timeoutMs, ROUTE_TIMEOUT_CODE)\n const attempt = resolve(bounded.signal)\n .finally(() => { bounded[Symbol.dispose]() })\n .catch((error: unknown) => {\n pending = undefined\n throw error\n })\n pending = attempt\n return attempt\n }\n}\n","import type { Context } from '@deepseek-ai/cordis'\nimport type { Agent } from '@deepseek-ai/dsh-agent'\nimport type {} from '@deepseek-ai/dsh-agent-presets'\nimport type {} from '@deepseek-ai/dsh-commands'\nimport type {} from '@deepseek-ai/dsh-host-webserver'\nimport { CLAUDE_DOCTOR_PATH } from './constants.ts'\nimport { runClaudeDoctor, type ExecutableRuntime } from './executable.ts'\nimport type { ClaudeSupervisor, ClaudeSupervisorConfig } from './supervisor.ts'\nimport { redactText } from './events.ts'\nimport { registerPluginRoute } from './http.ts'\n\nexport const CLAUDE_DOCTOR_PROBE_TIMEOUT_MS = 15_000\n\n/** Live metadata-bridge state per agent, maintained by the host plugin. */\nexport interface ClaudeBridgeDiagnostic {\n attempts: number\n lastError?: string\n lastCatalog?: number\n registered?: string[]\n}\n\nexport const claudeBridgeDiagnostics = new WeakMap<Agent, ClaudeBridgeDiagnostic>()\n\nfunction safeMessage(error: unknown): string {\n return redactText(error instanceof Error ? error.message : String(error), 1_000)\n}\n\n/** Live command-bridge diagnostics: which agents exist, their presets, and how\n * many slash commands each agent's registry layer resolves. */\nfunction commandDiagnostics(ctx: Context): unknown {\n try {\n const agents = ctx.agents.list()\n return {\n total: agents.length,\n agents: agents.map(agent => {\n const info: { id: string; preset?: string; commandCount?: number; sample?: string[]; error?: string; bridge?: ClaudeBridgeDiagnostic } = { id: String(agent.id) }\n try {\n const preset = ctx.agentPresets.composedPreset(agent.ctx)\n if (preset !== undefined) info.preset = preset\n } catch (error) {\n info.error = safeMessage(error)\n }\n try {\n const list = ctx.commands.list(agent)\n info.commandCount = list.length\n info.sample = list.slice(0, 10).map(command => command.name)\n } catch (error) {\n info.error = info.error === undefined ? safeMessage(error) : `${info.error}; ${safeMessage(error)}`\n }\n const bridge = claudeBridgeDiagnostics.get(agent)\n if (bridge !== undefined) info.bridge = bridge\n return info\n }),\n }\n } catch (error) {\n return { error: safeMessage(error) }\n }\n}\n\nexport function registerClaudeDoctorRoutes(\n ctx: Context,\n runtime: ExecutableRuntime,\n supervisor: ClaudeSupervisor,\n config: ClaudeSupervisorConfig,\n resolutionError?: unknown,\n): void {\n registerPluginRoute(ctx, {\n mode: 'unary',\n kind: 'exact',\n path: CLAUDE_DOCTOR_PATH,\n methods: ['GET'],\n budget: 'git',\n handler: async io => {\n try {\n if (resolutionError !== undefined) {\n return { status: 200, value: {\n executable: {\n status: 'missing',\n searched: config.executablePath.length > 0 ? [config.executablePath] : ['claude', '~/.local/bin/claude', '/opt/homebrew/bin/claude', '/usr/local/bin/claude'],\n },\n version: { status: 'not-run' },\n authentication: { status: 'not-run' },\n handshake: 'not-run',\n message: safeMessage(resolutionError),\n limits: {\n idleTimeoutMs: config.idleTimeoutMs,\n maxProcesses: config.maxProcesses,\n },\n processes: { count: 0, active: 0 },\n } }\n }\n const report = await runClaudeDoctor(runtime, {\n configuredPath: config.executablePath,\n cwd: process.cwd(),\n // Threaded so freeing the socket also stops the probe, rather than\n // leaving a spawn nobody is waiting for; the ceiling stays its own.\n signal: AbortSignal.any([io.signal, AbortSignal.timeout(CLAUDE_DOCTOR_PROBE_TIMEOUT_MS)]),\n })\n const processes = supervisor.snapshots()\n if (processes.some(process => process.claudeSessionId !== undefined)) report.handshake = 'ok'\n return { status: 200, value: {\n ...report,\n limits: {\n idleTimeoutMs: config.idleTimeoutMs,\n maxProcesses: config.maxProcesses,\n },\n processes: {\n count: processes.length,\n active: processes.filter(process => process.state === 'running' || process.state === 'starting').length,\n },\n commandBridge: commandDiagnostics(ctx),\n } }\n } catch (error) {\n return { status: 500, value: { error: safeMessage(error) } }\n }\n },\n })\n}\n","import type { Context } from '@deepseek-ai/cordis'\nimport type {} from '@deepseek-ai/dsh-host-webserver'\nimport type { ServerResponse } from 'node:http'\nimport { CLAUDE_PROJECTION_PATH } from './constants.ts'\nimport { registerPluginRoute, type PluginRouteIo } from './http.ts'\nimport { MAX_MULTIPLEX_SESSIONS } from './plugin-budget.ts'\nimport type { ClaudeSidecarProjection, ClaudeSidecarRepository } from './sidecar.ts'\nimport type { ClaudeCommandView } from './command-bridge.ts'\nimport type { RepositoryStatus } from './repository-status.ts'\nimport type { ReviewComment } from './review-comments.ts'\n\nconst MAX_SESSION_ID_CHARS = 1_024\n/** Slow-moving metadata refresh and stream heartbeat cadence; deliberately off\n * the transcript hot path so git/gh latency never delays visible text. */\nconst META_REFRESH_MS = 5_000\n/** The multiplexed carrier's path segment. Session ids are `session-<uuid>`,\n * so this cannot collide with one. */\nconst MULTI_SEGMENT = 'multi'\n\ntype ProjectionTarget =\n | { readonly kind: 'snapshot'; readonly sessionId: string }\n | { readonly kind: 'multi'; readonly sessionIds: readonly string[] }\n\nfunction validSessionId(value: string): boolean {\n return value.length > 0 && value.length <= MAX_SESSION_ID_CHARS\n}\n\nfunction targetFromUrl(url: URL): ProjectionTarget | undefined {\n const prefix = `${CLAUDE_PROJECTION_PATH}/`\n if (!url.pathname.startsWith(prefix)) return undefined\n const encoded = url.pathname.slice(prefix.length)\n if (encoded.length === 0 || encoded.includes('/')) return undefined\n if (encoded === MULTI_SEGMENT) {\n const raw = url.searchParams.get('sessions')\n if (raw === null) return undefined\n const sessionIds = [...new Set(raw.split(',').filter(id => id.length > 0))]\n if (sessionIds.length === 0 || sessionIds.length > MAX_MULTIPLEX_SESSIONS) return undefined\n if (!sessionIds.every(validSessionId)) return undefined\n return { kind: 'multi', sessionIds }\n }\n try {\n const sessionId = decodeURIComponent(encoded)\n return validSessionId(sessionId) ? { kind: 'snapshot', sessionId } : undefined\n } catch {\n return undefined\n }\n}\n\ninterface ProjectionMeta {\n readonly owned: boolean\n readonly commands: readonly ClaudeCommandView[]\n readonly repository?: RepositoryStatus\n readonly reviewComments: readonly ReviewComment[]\n}\n\nfunction envelope(projection: ClaudeSidecarProjection, meta: ProjectionMeta): Record<string, unknown> {\n return {\n schemaVersion: projection.schemaVersion,\n revision: projection.revision,\n owned: meta.owned,\n commands: meta.commands,\n activities: projection.activities,\n ...(projection.contextUsage === undefined ? {} : { contextUsage: projection.contextUsage }),\n ...(projection.tasks === undefined ? {} : { tasks: projection.tasks }),\n ...(meta.repository === undefined ? {} : { repository: meta.repository }),\n reviewComments: meta.reviewComments,\n // Ranges only: the chain anchors behind a rewind are Claude transcript\n // identities and stay on this side of the boundary.\n ...(projection.rewind === undefined ? {} : { rewind: { ranges: projection.rewind.ranges } }),\n }\n}\n\n/** Register the browser-readable, credential-free sidecar projection endpoint.\n *\n * `GET <path>/:sessionId` returns one snapshot. `GET <path>/multi?sessions=a,b`\n * returns ONE NDJSON stream carrying every listed session, each line stamped\n * with its `session`.\n *\n * There is deliberately no per-session stream URL. The browser shares a small\n * fixed connection budget between this plugin and the Host, and a stream per\n * session spent it in proportion to how many Claude sessions existed — which\n * is what left the settings panel unable to get a connection at all. One\n * carrier is one connection, whatever the session count. */\nexport function registerClaudeProjectionRoute(\n ctx: Context,\n sidecar: ClaudeSidecarRepository,\n ownsSession: (sessionId: string) => boolean,\n commandsForSession: (sessionId: string) => readonly ClaudeCommandView[] = () => [],\n repositoryForSession: (sessionId: string) => Promise<RepositoryStatus | undefined> = async () => undefined,\n reviewCommentsForSession: (sessionId: string) => readonly ReviewComment[] = () => [],\n): void {\n const info = (message: string): void => {\n ctx.logger?.info?.(message)\n }\n\n /** Everything the host already knows, without touching the repository. */\n const localMeta = (sessionId: string): ProjectionMeta => {\n const owned = ownsSession(sessionId)\n return {\n owned,\n commands: commandsForSession(sessionId),\n reviewComments: owned ? reviewCommentsForSession(sessionId) : [],\n }\n }\n\n const assembleMeta = async (sessionId: string): Promise<ProjectionMeta> => {\n const meta = localMeta(sessionId)\n const repository = meta.owned ? await repositoryForSession(sessionId) : undefined\n return { ...meta, ...(repository === undefined ? {} : { repository }) }\n }\n\n const streamMulti = async (res: ServerResponse, io: PluginRouteIo, sessionIds: readonly string[]): Promise<void> => {\n info(`dsh-claude: projection stream opened for ${sessionIds.length} session(s)`)\n let textDeltas = 0\n let textBytes = 0\n let textSince = Date.now()\n // Headers first, before any await. One session whose repository probe is\n // slow must not delay every other session's first paint — and until the\n // headers are out the client cannot even tell the carrier is alive.\n // `no-transform` keeps a compressing proxy from buffering the sole carrier.\n res.writeHead(200, {\n 'content-type': 'application/x-ndjson; charset=utf-8',\n 'cache-control': 'no-store, no-transform',\n 'x-content-type-options': 'nosniff',\n })\n res.flushHeaders?.()\n let closed = false\n const writeLine = (value: unknown): void => {\n if (closed) return\n try {\n res.write(`${JSON.stringify(value)}\\n`)\n } catch {\n closed = true\n }\n }\n const metas = new Map<string, ProjectionMeta>()\n const writeMeta = (sessionId: string, meta: ProjectionMeta): void => {\n metas.set(sessionId, meta)\n writeLine({\n type: 'meta',\n session: sessionId,\n owned: meta.owned,\n commands: meta.commands,\n ...(meta.repository === undefined ? {} : { repository: meta.repository }),\n reviewComments: meta.reviewComments,\n })\n }\n const writeSnapshot = async (sessionId: string): Promise<void> => {\n const projection = await sidecar.read(sessionId)\n // The repository probe runs a chain of git commands and a `gh pr view`\n // over the network -- seconds, where the transcript is already in\n // memory. It rides a later meta line so the prose paints first.\n const meta = metas.get(sessionId) ?? localMeta(sessionId)\n metas.set(sessionId, meta)\n // Where the notification stream stands as of this read, so the first\n // delta after this line has a number to be contiguous with.\n writeLine({ type: 'snapshot', session: sessionId, seq: sidecar.sequence(sessionId), ...envelope(projection, meta) })\n const probed = await assembleMeta(sessionId)\n if (closed || JSON.stringify(probed) === JSON.stringify(metas.get(sessionId))) return\n writeMeta(sessionId, probed)\n }\n // Subscribe every lane synchronously, before the first await: a delta that\n // lands while the snapshots are still assembling belongs to this carrier.\n const unsubscribes = sessionIds.map(sessionId => sidecar.subscribe(sessionId, delta => {\n switch (delta.kind) {\n case 'text':\n textDeltas += 1\n textBytes += (delta.append ?? delta.text ?? '').length\n if (textDeltas % 25 === 0) {\n const elapsed = Date.now() - textSince\n info(`dsh-claude: stream 25 text deltas ${textBytes}B in ${elapsed}ms`)\n textBytes = 0\n textSince = Date.now()\n }\n writeLine({\n type: 'text',\n session: sessionId,\n turn: delta.turn,\n step: delta.step,\n ordinal: delta.ordinal,\n ...(delta.append === undefined ? {} : { append: delta.append }),\n ...(delta.text === undefined ? {} : { text: delta.text }),\n ...(delta.renderer === undefined ? {} : { renderer: delta.renderer }),\n seq: delta.seq,\n })\n return\n case 'activity':\n writeLine({ type: 'activity', session: sessionId, activity: delta.activity, seq: delta.seq })\n return\n case 'contextUsage':\n writeLine({ type: 'contextUsage', session: sessionId, value: delta.value, seq: delta.seq })\n return\n case 'tasks':\n writeLine({ type: 'tasks', session: sessionId, value: delta.value, seq: delta.seq })\n return\n case 'checkpoint':\n writeLine({ type: 'checkpoint', session: sessionId, seq: delta.seq })\n return\n case 'sync':\n void writeSnapshot(sessionId).catch(() => undefined)\n }\n }))\n // Per-session, in parallel: a wedged repository probe costs its own lane\n // its first paint, not everyone else's.\n for (const sessionId of sessionIds) {\n void writeSnapshot(sessionId).catch(() => undefined)\n }\n const timer = setInterval(() => {\n void (async () => {\n for (const sessionId of sessionIds) {\n if (closed) return\n const next = await assembleMeta(sessionId)\n if (closed) return\n if (JSON.stringify(next) === JSON.stringify(metas.get(sessionId))) continue\n writeMeta(sessionId, next)\n }\n writeLine({ type: 'ping' })\n })().catch(() => undefined)\n }, META_REFRESH_MS)\n timer.unref?.()\n // Teardown rides the wrapper's signal, which is armed before any await —\n // the previous hand-written `res.on('close')` was attached only after the\n // first metadata probe resolved, so a client that gave up during that\n // window left the interval and every subscription running for good.\n await new Promise<void>(resolve => {\n const finish = (): void => {\n if (closed) return\n closed = true\n clearInterval(timer)\n for (const unsubscribe of unsubscribes) unsubscribe()\n info(`dsh-claude: projection stream closed after ${textDeltas} text deltas`)\n resolve()\n }\n if (io.signal.aborted) finish()\n else io.signal.addEventListener('abort', finish, { once: true })\n })\n }\n\n registerPluginRoute(ctx, {\n mode: 'stream',\n kind: 'prefix',\n path: CLAUDE_PROJECTION_PATH,\n methods: ['GET'],\n // One carrier. A reconnect supersedes the old one rather than stacking.\n maxConcurrent: 1,\n streamKey: () => MULTI_SEGMENT,\n handler: async (res, io) => {\n const target = targetFromUrl(io.url)\n if (target === undefined) {\n res.writeHead(400, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' })\n res.write(JSON.stringify({ error: 'invalid session id' }))\n return\n }\n if (target.kind === 'multi') return await streamMulti(res, io, target.sessionIds)\n // A steady 2s cadence here means a stale (pre-streaming) client bundle.\n info(`dsh-claude: projection poll for ${target.sessionId.slice(0, 64)}`)\n try {\n const projection = await sidecar.read(target.sessionId)\n const body = envelope(projection, await assembleMeta(target.sessionId))\n res.writeHead(200, {\n 'content-type': 'application/json; charset=utf-8',\n 'cache-control': 'no-store',\n 'x-content-type-options': 'nosniff',\n })\n res.write(JSON.stringify(body))\n } catch {\n if (res.headersSent) return\n res.writeHead(500, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' })\n res.write(JSON.stringify({ error: 'projection unavailable' }))\n }\n },\n })\n}\n","import { readFile } from 'node:fs/promises'\nimport { isAbsolute, resolve, sep } from 'node:path'\nimport type { SubprocessHandle, SubprocessRuntime } from '@deepseek-ai/dsh-subprocess'\n\nconst MAX_OUTPUT_BYTES = 64 * 1024\nconst MAX_DIFF_BYTES = 256 * 1024\nconst MAX_FILE_BYTES = 8 * 1024 * 1024\nexport const MAX_FILE_LINES_PER_REQUEST = 500\nconst MAX_UNTRACKED_DIFFS = 50\nconst GIT_TIMEOUT_MS = 5_000\nconst GH_TIMEOUT_MS = 8_000\nconst CACHE_TTL_MS = 5_000\nconst MAX_TEXT_CHARS = 1_024\n\nexport type RepositoryCheckState = 'passing' | 'pending' | 'failing' | 'none'\nexport type RepositoryReviewState = 'approved' | 'changes-requested' | 'review-required' | 'none'\n\nexport interface RepositoryPullRequestStatus {\n readonly number: number\n readonly title: string\n readonly url: string\n readonly state: 'open' | 'closed' | 'merged'\n readonly draft: boolean\n readonly review: RepositoryReviewState\n readonly checks: RepositoryCheckState\n readonly mergeState?: string\n readonly author?: string\n readonly createdAt?: string\n readonly mergedAt?: string\n readonly baseBranch?: string\n}\n\nexport interface RepositoryDiffStatus {\n readonly additions: number\n readonly deletions: number\n readonly files: number\n readonly patch?: string\n readonly truncated: boolean\n}\n\nexport interface RepositoryStatus {\n readonly status: 'ready' | 'not-repository' | 'unavailable'\n readonly cwd: string\n readonly root?: string\n readonly branch?: string\n readonly detached?: boolean\n readonly worktree?: boolean\n readonly dirty?: boolean\n readonly upstream?: boolean\n readonly ahead?: number\n readonly behind?: number\n readonly remote?: string\n readonly pullRequest?: RepositoryPullRequestStatus\n readonly diff?: RepositoryDiffStatus\n /** Commits on origin/<base> that are not on HEAD, for open pull requests. */\n readonly baseBehind?: number\n}\n\ntype RepositoryRuntime = Pick<SubprocessRuntime, 'resolveExecutable' | 'spawn'>\n\ninterface CommandResult {\n readonly exitCode: number | null\n readonly stdout: string\n readonly lossy: boolean\n}\n\nfunction bounded(value: string): string {\n return value.trim().slice(0, MAX_TEXT_CHARS)\n}\n\nasync function collect(handle: SubprocessHandle): Promise<CommandResult> {\n const outcome = await handle.done\n const stdout = handle.collected.stdout?.readFrom(0)\n return {\n exitCode: outcome.exitCode,\n stdout: stdout?.text ?? '',\n lossy: stdout?.lossy === true,\n }\n}\n\nasync function run(\n runtime: RepositoryRuntime,\n executable: string,\n args: readonly string[],\n cwd: string,\n timeoutMs: number,\n maxBytes = MAX_OUTPUT_BYTES,\n): Promise<CommandResult> {\n const signal = AbortSignal.timeout(timeoutMs)\n return collect(runtime.spawn({\n argv: [executable, ...args],\n cwd,\n stdio: {\n stdin: 'ignore',\n stdout: { maxBytes },\n stderr: { maxBytes: MAX_OUTPUT_BYTES },\n },\n graceMs: 1_000,\n signal,\n env: {},\n }))\n}\n\nfunction normalizedPath(value: string): string {\n return value.replaceAll('\\\\', '/').replace(/\\/+$/u, '').toLocaleLowerCase('en-US')\n}\n\nexport function parseGitStatus(output: string): {\n branch?: string\n detached: boolean\n dirty: boolean\n upstream: boolean\n ahead?: number\n behind?: number\n} {\n let branch: string | undefined\n let detached = false\n let dirty = false\n let upstream = false\n let ahead: number | undefined\n let behind: number | undefined\n for (const line of output.split(/\\r?\\n/u)) {\n if (line.startsWith('# branch.head ')) {\n const head = bounded(line.slice('# branch.head '.length))\n if (head === '(detached)') detached = true\n else if (head.length > 0 && head !== '(unknown)') branch = head\n continue\n }\n if (line.startsWith('# branch.upstream ')) {\n upstream = true\n continue\n }\n if (line.startsWith('# branch.ab ')) {\n const counts = /^# branch\\.ab \\+(\\d+) -(\\d+)$/u.exec(line)\n if (counts !== null) {\n ahead = Number(counts[1])\n behind = Number(counts[2])\n }\n continue\n }\n if (line.length > 0 && !line.startsWith('# ')) dirty = true\n }\n return {\n ...(branch === undefined ? {} : { branch }),\n detached,\n dirty,\n upstream,\n ...(ahead === undefined ? {} : { ahead }),\n ...(behind === undefined ? {} : { behind }),\n }\n}\n\nexport function parseDiffNumstat(value: string): Omit<RepositoryDiffStatus, 'patch' | 'truncated'> {\n let additions = 0\n let deletions = 0\n let files = 0\n for (const line of value.split(/\\r?\\n/u)) {\n if (line.length === 0) continue\n const [added, deleted] = line.split('\\t')\n files += 1\n if (added !== undefined && /^\\d+$/u.test(added)) additions += Number(added)\n if (deleted !== undefined && /^\\d+$/u.test(deleted)) deletions += Number(deleted)\n }\n return { additions, deletions, files }\n}\n\nexport function parseGitHubRemote(value: string): string | undefined {\n const remote = bounded(value)\n const match = /^(?:https:\\/\\/github\\.com\\/|git@github\\.com:|ssh:\\/\\/git@github\\.com\\/)([^/\\s]+)\\/([^/\\s]+?)(?:\\.git)?$/iu.exec(remote)\n if (match?.[1] === undefined || match[2] === undefined) return undefined\n return `${match[1]}/${match[2]}`\n}\n\nfunction record(value: unknown): Record<string, unknown> | undefined {\n return value !== null && typeof value === 'object' && !Array.isArray(value)\n ? value as Record<string, unknown>\n : undefined\n}\n\nexport function aggregateChecks(value: unknown): RepositoryCheckState {\n if (!Array.isArray(value) || value.length === 0) return 'none'\n let pending = false\n for (const item of value) {\n const check = record(item)\n if (check === undefined) continue\n const conclusion = typeof check.conclusion === 'string' ? check.conclusion.toUpperCase() : undefined\n const status = typeof check.status === 'string' ? check.status.toUpperCase() : undefined\n const state = typeof check.state === 'string' ? check.state.toUpperCase() : undefined\n if (['FAILURE', 'ERROR', 'CANCELLED', 'TIMED_OUT', 'ACTION_REQUIRED'].includes(conclusion ?? state ?? '')) return 'failing'\n if (status !== undefined && status !== 'COMPLETED') pending = true\n if (['PENDING', 'EXPECTED'].includes(state ?? '')) pending = true\n }\n return pending ? 'pending' : 'passing'\n}\n\nfunction reviewState(value: unknown): RepositoryReviewState {\n if (value === 'APPROVED') return 'approved'\n if (value === 'CHANGES_REQUESTED') return 'changes-requested'\n if (value === 'REVIEW_REQUIRED') return 'review-required'\n return 'none'\n}\n\nexport function parsePullRequest(value: unknown): RepositoryPullRequestStatus | undefined {\n const input = record(value)\n if (input === undefined\n || !Number.isSafeInteger(input.number)\n || Number(input.number) <= 0\n || typeof input.title !== 'string'\n || typeof input.url !== 'string') return undefined\n let url: URL\n try {\n url = new URL(input.url)\n } catch {\n return undefined\n }\n if (url.protocol !== 'https:' || url.hostname !== 'github.com') return undefined\n const rawState = typeof input.state === 'string' ? input.state.toUpperCase() : ''\n const state = input.mergedAt !== undefined && input.mergedAt !== null\n ? 'merged'\n : rawState === 'OPEN' ? 'open' : rawState === 'CLOSED' ? 'closed' : undefined\n if (state === undefined) return undefined\n return {\n number: Number(input.number),\n title: bounded(input.title),\n url: url.href,\n state,\n draft: input.isDraft === true,\n review: reviewState(input.reviewDecision),\n checks: aggregateChecks(input.statusCheckRollup),\n ...(typeof input.mergeStateStatus === 'string'\n ? { mergeState: bounded(input.mergeStateStatus) }\n : {}),\n ...(typeof record(input.author)?.login === 'string'\n ? { author: bounded(String(record(input.author)?.login)) }\n : {}),\n ...(typeof input.createdAt === 'string' && Number.isFinite(Date.parse(input.createdAt))\n ? { createdAt: new Date(input.createdAt).toISOString() }\n : {}),\n ...(typeof input.mergedAt === 'string' && Number.isFinite(Date.parse(input.mergedAt))\n ? { mergedAt: new Date(input.mergedAt).toISOString() }\n : {}),\n ...(typeof input.baseRefName === 'string' && bounded(input.baseRefName).length > 0\n ? { baseBranch: bounded(input.baseRefName) }\n : {}),\n }\n}\n\nexport interface RepositoryFileLines {\n /** Requested 1-based inclusive slice of the working-tree file, clipped to its end. */\n readonly lines: readonly string[]\n /** Total line count of the file. */\n readonly total: number\n}\n\nexport class RepositoryFileError extends Error {\n readonly code: string\n\n constructor(code: string, message: string) {\n super(message)\n this.name = 'RepositoryFileError'\n this.code = code\n }\n}\n\nexport class RepositoryStatusService {\n readonly #runtime: RepositoryRuntime\n readonly #cacheTtlMs: number\n readonly #cache = new Map<string, { expiresAt: number; value: Promise<RepositoryStatus> }>()\n readonly #lastReady = new Map<string, RepositoryStatus>()\n #gitExecutable?: Promise<string>\n #ghExecutable?: Promise<string | undefined>\n\n constructor(runtime: RepositoryRuntime, cacheTtlMs = CACHE_TTL_MS) {\n this.#runtime = runtime\n this.#cacheTtlMs = cacheTtlMs\n }\n\n /** `signal` bounds the scan itself, not just the caller's patience: the\n * untracked-file diff below is a serial spawn loop that can outlive any\n * route budget, and work nobody is waiting for still occupies the process. */\n inspect(cwd: string, signal?: AbortSignal): Promise<RepositoryStatus> {\n const current = this.#cache.get(cwd)\n if (current !== undefined && current.expiresAt > Date.now()) return current.value\n const value = this.#inspect(cwd, signal).then(next => this.#stabilize(cwd, next))\n this.#cache.set(cwd, { expiresAt: Date.now() + this.#cacheTtlMs, value })\n void value.catch(() => this.#cache.delete(cwd))\n return value\n }\n\n invalidate(cwd: string): void {\n this.#cache.delete(cwd)\n this.#lastReady.delete(cwd)\n }\n\n dispose(): void {\n this.#cache.clear()\n this.#lastReady.clear()\n }\n\n #stabilize(cwd: string, next: RepositoryStatus): RepositoryStatus {\n const previous = this.#lastReady.get(cwd)\n if (next.status !== 'ready') return previous ?? next\n const sameCheckout = previous?.status === 'ready'\n && previous.root === next.root\n && previous.branch === next.branch\n const stable = sameCheckout\n ? {\n ...next,\n ...(next.pullRequest === undefined && previous.pullRequest !== undefined ? { pullRequest: previous.pullRequest } : {}),\n ...(next.pullRequest === undefined && previous.pullRequest !== undefined && previous.diff !== undefined\n ? { diff: previous.diff }\n : next.diff === undefined && previous.diff !== undefined ? { diff: previous.diff } : {}),\n }\n : next\n this.#lastReady.set(cwd, stable)\n return stable\n }\n\n /** Lines [from, to] of a working-tree file, used to expand unmodified context around diff hunks. */\n async fileLines(cwd: string, relativePath: string, from: number, to: number): Promise<RepositoryFileLines> {\n if (relativePath.length === 0 || isAbsolute(relativePath) || relativePath.includes('\\0') || relativePath.split(/[\\\\/]/u).includes('..')) {\n throw new RepositoryFileError('invalid-request', 'The file path must be relative to the repository.')\n }\n if (!Number.isSafeInteger(from) || !Number.isSafeInteger(to) || from < 1 || to < from || to - from >= MAX_FILE_LINES_PER_REQUEST) {\n throw new RepositoryFileError('invalid-request', 'The requested line range is invalid.')\n }\n const git = await this.#git()\n const top = await run(this.#runtime, git, ['rev-parse', '--path-format=absolute', '--show-toplevel'], cwd, GIT_TIMEOUT_MS)\n if (top.exitCode !== 0) throw new RepositoryFileError('not-repository', 'The directory is not inside a git repository.')\n const root = resolve(top.stdout.trim())\n const target = resolve(root, relativePath)\n if (target !== root && !target.startsWith(root + sep)) throw new RepositoryFileError('invalid-request', 'The file path escapes the repository.')\n const content = await readFile(target, 'utf8')\n if (content.length > MAX_FILE_BYTES) throw new RepositoryFileError('too-large', 'The file is too large to expand.')\n const all = content.split(/\\r?\\n/u)\n if (all.at(-1) === '') all.pop()\n return { lines: all.slice(from - 1, to), total: all.length }\n }\n\n async #git(): Promise<string> {\n this.#gitExecutable ??= this.#runtime.resolveExecutable('git')\n return this.#gitExecutable\n }\n\n async #gh(): Promise<string | undefined> {\n this.#ghExecutable ??= this.#runtime.resolveExecutable('gh').catch(() => undefined)\n return this.#ghExecutable\n }\n\n async #inspect(cwd: string, signal?: AbortSignal): Promise<RepositoryStatus> {\n const safeCwd = bounded(cwd)\n let git: string\n try {\n git = await this.#git()\n } catch {\n return { status: 'unavailable', cwd: safeCwd }\n }\n try {\n const paths = await run(this.#runtime, git, [\n 'rev-parse', '--path-format=absolute', '--show-toplevel', '--absolute-git-dir', '--git-common-dir',\n ], cwd, GIT_TIMEOUT_MS)\n if (paths.exitCode !== 0) return { status: 'not-repository', cwd: safeCwd }\n const [rootValue, gitDirValue, commonDirValue] = paths.stdout.split(/\\r?\\n/u)\n const root = bounded(rootValue ?? '')\n const gitDir = bounded(gitDirValue ?? '')\n const commonDir = bounded(commonDirValue ?? '')\n if (root.length === 0 || gitDir.length === 0 || commonDir.length === 0) return { status: 'unavailable', cwd: safeCwd }\n const statusResult = await run(this.#runtime, git, ['status', '--porcelain=v2', '--branch', '--untracked-files=normal'], cwd, GIT_TIMEOUT_MS)\n if (statusResult.exitCode !== 0) return { status: 'unavailable', cwd: safeCwd }\n const status = parseGitStatus(statusResult.stdout)\n const remoteResult = await run(this.#runtime, git, ['remote', 'get-url', 'origin'], cwd, GIT_TIMEOUT_MS)\n const remote = remoteResult.exitCode === 0 ? parseGitHubRemote(remoteResult.stdout) : undefined\n const pullRequest = status.branch === undefined || remote === undefined\n ? undefined\n : await this.#pullRequest(cwd, remote, status.branch)\n const diffBase = pullRequest?.baseBranch === undefined\n ? 'HEAD'\n : await this.#mergeBase(cwd, git, pullRequest.baseBranch) ?? 'HEAD'\n const diff = status.dirty || diffBase !== 'HEAD'\n ? await this.#diff(cwd, git, diffBase, signal)\n : { additions: 0, deletions: 0, files: 0, truncated: false }\n const baseBehind = pullRequest?.state === 'open' && pullRequest.baseBranch !== undefined\n ? await this.#baseBehind(cwd, git, pullRequest.baseBranch)\n : undefined\n return {\n status: 'ready',\n cwd: safeCwd,\n root,\n ...status,\n worktree: normalizedPath(gitDir) !== normalizedPath(commonDir),\n ...(remote === undefined ? {} : { remote }),\n ...(pullRequest === undefined ? {} : { pullRequest }),\n ...(diff === undefined ? {} : { diff }),\n ...(baseBehind === undefined ? {} : { baseBehind }),\n }\n } catch {\n return { status: 'unavailable', cwd: safeCwd }\n }\n }\n\n async #baseBehind(cwd: string, git: string, baseBranch: string): Promise<number | undefined> {\n try {\n const result = await run(this.#runtime, git, ['rev-list', '--count', `HEAD..refs/remotes/origin/${baseBranch}`, '--'], cwd, GIT_TIMEOUT_MS)\n if (result.exitCode !== 0 || result.lossy) return undefined\n const count = Number(bounded(result.stdout))\n return Number.isSafeInteger(count) && count >= 0 ? count : undefined\n } catch {\n return undefined\n }\n }\n\n async #mergeBase(cwd: string, git: string, baseBranch: string): Promise<string | undefined> {\n try {\n const result = await run(this.#runtime, git, ['merge-base', 'HEAD', `refs/remotes/origin/${baseBranch}`], cwd, GIT_TIMEOUT_MS)\n if (result.exitCode !== 0 || result.lossy) return undefined\n const oid = bounded(result.stdout)\n return /^[0-9a-f]{40}$/iu.test(oid) ? oid : undefined\n } catch {\n return undefined\n }\n }\n\n async #diff(cwd: string, git: string, base: string, signal?: AbortSignal): Promise<RepositoryDiffStatus | undefined> {\n try {\n const numstat = await run(this.#runtime, git, ['diff', '--no-ext-diff', '--numstat', base, '--'], cwd, GIT_TIMEOUT_MS)\n if (numstat.exitCode !== 0 || numstat.lossy) return undefined\n const summary = parseDiffNumstat(numstat.stdout)\n const patch = await run(this.#runtime, git, ['diff', '--no-ext-diff', '--no-color', '--unified=3', base, '--'], cwd, GIT_TIMEOUT_MS, MAX_DIFF_BYTES)\n if (patch.exitCode !== 0) return { ...summary, truncated: true }\n const untracked = await this.#untrackedDiff(cwd, git, signal)\n const combinedPatch = `${patch.stdout}${untracked.patch}`\n return {\n additions: summary.additions + untracked.additions,\n deletions: summary.deletions,\n files: summary.files + untracked.files,\n ...(patch.lossy ? {} : { patch: combinedPatch.slice(0, MAX_DIFF_BYTES) }),\n truncated: patch.lossy || untracked.truncated || combinedPatch.length > MAX_DIFF_BYTES,\n }\n } catch {\n return undefined\n }\n }\n\n async #untrackedDiff(cwd: string, git: string, signal?: AbortSignal): Promise<{ additions: number; files: number; patch: string; truncated: boolean }> {\n const listed = await run(this.#runtime, git, ['ls-files', '--others', '--exclude-standard', '-z'], cwd, GIT_TIMEOUT_MS)\n if (listed.exitCode !== 0 || listed.lossy) return { additions: 0, files: 0, patch: '', truncated: listed.lossy }\n const paths = listed.stdout.split('\\0').filter(path => path.length > 0)\n let additions = 0\n let patch = ''\n let truncated = paths.length > MAX_UNTRACKED_DIFFS\n for (const path of paths.slice(0, MAX_UNTRACKED_DIFFS)) {\n // The caller is gone or the route budget elapsed: stop spawning.\n if (signal?.aborted === true) return { additions, files: paths.length, patch, truncated: true }\n const result = await run(this.#runtime, git, [\n 'diff', '--no-ext-diff', '--no-color', '--unified=3', '--numstat', '--patch', '--no-index', '--', '/dev/null', path,\n ], cwd, GIT_TIMEOUT_MS, MAX_DIFF_BYTES)\n if (result.exitCode !== 0 && result.exitCode !== 1) {\n truncated = true\n continue\n }\n const start = result.stdout.indexOf('diff --git ')\n additions += parseDiffNumstat(start >= 0 ? result.stdout.slice(0, start) : result.stdout).additions\n if (result.lossy) truncated = true\n else if (start >= 0) patch += result.stdout.slice(start)\n }\n return { additions, files: paths.length, patch, truncated }\n }\n\n async #pullRequest(cwd: string, repository: string, branch: string): Promise<RepositoryPullRequestStatus | undefined> {\n const gh = await this.#gh()\n if (gh === undefined) return undefined\n try {\n const result = await run(this.#runtime, gh, [\n 'pr', 'view', branch,\n '--repo', repository,\n '--json', 'number,title,url,state,isDraft,reviewDecision,mergeStateStatus,mergedAt,statusCheckRollup,author,createdAt,baseRefName',\n ], cwd, GH_TIMEOUT_MS)\n if (result.exitCode !== 0) return undefined\n return parsePullRequest(JSON.parse(result.stdout))\n } catch {\n return undefined\n }\n }\n}\n","/** Name a generated worktree branch after what the user is about to ask for.\n *\n * The composer draft is the only description of the work that exists before\n * the session starts, and it is usually not English and never branch-safe, so\n * a throwaway Haiku turn compresses it into a slug. Naming is a nicety: every\n * failure here returns `undefined` and the caller keeps its timestamped name. */\nimport { query as claudeQuery, type Options as ClaudeOptions, type Query } from '@anthropic-ai/claude-agent-sdk'\n\n/** Cheapest model that can translate and compress a sentence. */\nexport const BRANCH_SUMMARY_MODEL = 'haiku'\n\n/** A branch name is not worth blocking worktree creation on for long. */\nexport const BRANCH_SUMMARY_TIMEOUT_MS = 15_000\n\nconst MAX_INTENT_CHARS = 2_000\n/** A compliant reply is one short fragment; anything longer is prose. */\nconst MAX_REPLY_CHARS = 80\n/** More words than this is a sentence, not the fragment we asked for. */\nconst MAX_SLUG_WORDS = 6\nconst MAX_SLUG_CHARS = 48\n\nexport function branchSummaryPrompt(intent: string): string {\n return [\n 'Summarize this software task as a Git branch name fragment.',\n 'Reply with 2-5 lowercase English words joined by hyphens and nothing else:',\n 'no quotes, no slashes, no prefix, no punctuation, no explanation.',\n 'Translate the task to English if it is written in another language.',\n '',\n 'Task:',\n `\"\"\"\\n${intent.replaceAll('\"\"\"', '\" \" \"')}\\n\"\"\"`,\n ].join('\\n')\n}\n\n/** Branch-safe slug for a model reply, or `undefined` when the reply is not\n * the fragment we asked for. Mangling a refusal or a paragraph into a slug\n * would produce a worse name than the timestamped fallback. */\nexport function branchSlug(reply: string): string | undefined {\n const line = reply.trim()\n if (line.length === 0 || line.length > MAX_REPLY_CHARS || /[\\r\\n]/u.test(line)) return undefined\n const words = line.toLocaleLowerCase('en-US')\n .replace(/[^a-z0-9]+/gu, '-')\n .split('-')\n .filter(word => word.length > 0)\n if (words.length === 0 || words.length > MAX_SLUG_WORDS) return undefined\n // ponytail: a long fragment is cut mid-word; six short words almost never\n // reach 48 characters, and a branch name is allowed to be blunt.\n const slug = words.join('-').slice(0, MAX_SLUG_CHARS).replace(/-+$/u, '')\n return slug.length === 0 ? undefined : slug\n}\n\n/** First free name in `<candidate>`, `<candidate>-2`, `<candidate>-3`, … */\nexport function uniqueBranchName(candidate: string, taken: readonly string[]): string {\n const existing = new Set(taken)\n if (!existing.has(candidate)) return candidate\n for (let index = 2; index < 100; index += 1) {\n const name = `${candidate}-${index}`\n if (!existing.has(name)) return name\n }\n return candidate\n}\n\n/** Compress a composer draft into a branch slug with a throwaway Claude turn.\n *\n * Deliberately NOT routed through the supervisor, for the same reasons as the\n * plan-usage probe: there is no session to borrow yet. The turn is isolated\n * from filesystem settings as well, because a CLAUDE.md instruction (\"always\n * reply in the user's language\") turns the answer into an unusable slug. */\nexport async function summarizeBranchSlug(\n executablePath: string,\n intent: string,\n factory: (params: { prompt: string; options: ClaudeOptions }) => Query = claudeQuery,\n): Promise<string | undefined> {\n const task = intent.trim().slice(0, MAX_INTENT_CHARS)\n if (task.length === 0) return undefined\n const lifetime = new AbortController()\n const timer = setTimeout(() => lifetime.abort(), BRANCH_SUMMARY_TIMEOUT_MS)\n timer.unref?.()\n try {\n const query = factory({\n prompt: branchSummaryPrompt(task),\n options: {\n cwd: process.cwd(),\n abortController: lifetime,\n model: BRANCH_SUMMARY_MODEL,\n allowedTools: [],\n settingSources: [],\n maxTurns: 1,\n ...(executablePath.length === 0 ? {} : { pathToClaudeCodeExecutable: executablePath }),\n },\n })\n for await (const message of query) {\n if (message.type === 'result' && message.subtype === 'success') return branchSlug(message.result)\n }\n return undefined\n } catch {\n return undefined\n } finally {\n clearTimeout(timer)\n lifetime.abort()\n }\n}\n","import { randomUUID } from 'node:crypto'\nimport { mkdir, readdir, readFile, rename, rm, stat, writeFile } from 'node:fs/promises'\nimport { basename, isAbsolute, join, resolve } from 'node:path'\nimport { dshHomePath } from '@deepseek-ai/dsh-home-paths'\nimport type { SubprocessHandle, SubprocessRuntime } from '@deepseek-ai/dsh-subprocess'\nimport { uniqueBranchName } from './branch-name.ts'\n\nconst MAX_OUTPUT_BYTES = 128 * 1024\nconst GIT_TIMEOUT_MS = 10_000\nconst GIT_FETCH_TIMEOUT_MS = 60_000\nconst MAX_PATH_CHARS = 4_096\nconst MAX_BRANCH_CHARS = 512\nconst LEASE_SCHEMA_VERSION = 1\n// ponytail: grace only needs to outlive the worktree-create -> workspace-register\n// hop (seconds); two minutes keeps deletion feeling prompt while staying safe.\nconst CLEANUP_GRACE_MS = 2 * 60_000\n\ntype RepositorySetupRuntime = Pick<SubprocessRuntime, 'resolveExecutable' | 'spawn'>\n\ninterface CommandResult {\n readonly exitCode: number | null\n readonly stdout: string\n readonly stderr: string\n readonly lossy: boolean\n}\n\nexport interface RepositoryBranchList {\n readonly root: string\n readonly current?: string\n readonly dirty: boolean\n readonly branches: readonly string[]\n readonly remoteBranches: readonly string[]\n}\n\nexport type RepositorySetupStage = 'inspecting' | 'fetching' | 'summarizing' | 'creating-worktree' | 'saving-worktree' | 'switching-branch'\nexport type RepositorySetupProgress = (stage: RepositorySetupStage) => void\n\nexport interface RepositorySetupResult {\n readonly mode: 'checkout' | 'worktree'\n readonly root: string\n readonly path: string\n readonly branch: string\n readonly leaseId?: string\n}\n\nexport interface RepositoryCleanupResult {\n readonly mode: 'checkout' | 'worktree'\n readonly root: string\n readonly branch: string\n}\n\ninterface WorktreeLease {\n readonly id: string\n readonly root: string\n readonly path: string\n readonly branch: string\n readonly createdAt: string\n readonly pluginGeneratedBranch: boolean\n readonly sessionId?: string\n}\n\ninterface LeaseDocument {\n readonly schemaVersion: typeof LEASE_SCHEMA_VERSION\n readonly leases: readonly WorktreeLease[]\n}\n\nexport interface RepositorySetupServiceOptions {\n readonly leasePath?: string\n readonly worktreeRoot?: string\n readonly branchPrefix?: () => Promise<string>\n readonly cleanupGraceMs?: number\n /** Compress the composer draft into a branch slug; `undefined` result (or an\n * omitted option) falls back to the timestamped name. */\n readonly summarizeBranch?: (intent: string) => Promise<string | undefined>\n}\n\nexport class RepositorySetupError extends Error {\n readonly code: string\n\n constructor(code: string, message: string) {\n super(message)\n this.name = 'RepositorySetupError'\n this.code = code\n }\n}\n\nasync function collect(handle: SubprocessHandle): Promise<CommandResult> {\n const outcome = await handle.done\n const stdout = handle.collected.stdout?.readFrom(0)\n const stderr = handle.collected.stderr?.readFrom(0)\n return {\n exitCode: outcome.exitCode,\n stdout: stdout?.text ?? '',\n stderr: stderr?.text ?? '',\n lossy: stdout?.lossy === true || stderr?.lossy === true,\n }\n}\n\nfunction safePath(value: string): string {\n if (value.length === 0 || value.length > MAX_PATH_CHARS || !isAbsolute(value) || value.includes('\\0')) {\n throw new RepositorySetupError('invalid-path', 'The workspace path is invalid.')\n }\n return resolve(value)\n}\n\nfunction safeBranch(value: string): string {\n if (value.length === 0 || value.length > MAX_BRANCH_CHARS || value.trim() !== value || /[\\0\\r\\n]/u.test(value)) {\n throw new RepositorySetupError('invalid-branch', 'The branch name is invalid.')\n }\n return value\n}\n\nfunction parseCurrentBranch(value: string): string | undefined {\n const branch = value.trim()\n return branch.length === 0 || branch === 'HEAD' ? undefined : branch\n}\n\nexport function parseWorktreeBranches(value: string): ReadonlyMap<string, string> {\n const occupied = new Map<string, string>()\n let path: string | undefined\n for (const line of `${value}\\n`.split(/\\r?\\n/u)) {\n if (line.startsWith('worktree ')) path = line.slice('worktree '.length)\n else if (line.startsWith('branch refs/heads/') && path !== undefined) {\n occupied.set(line.slice('branch refs/heads/'.length), path)\n } else if (line.length === 0) path = undefined\n }\n return occupied\n}\n\nfunction slug(value: string, fallback: string): string {\n const normalized = value.toLocaleLowerCase('en-US').replace(/[^a-z0-9._-]+/gu, '-').replace(/^-+|-+$/gu, '')\n return normalized.slice(0, 48) || fallback\n}\n\n/** Comparable form for path identity: resolved, forward slashes, case-folded\n * so Windows drive-letter or case spelling differences cannot hide a match. */\nexport function comparablePath(value: string): string {\n return resolve(value).replaceAll('\\\\', '/').toLocaleLowerCase('en-US')\n}\n\nfunction pathExists(value: string): Promise<boolean> {\n return stat(value).then(() => true, () => false)\n}\n\nfunction lease(value: unknown): WorktreeLease | undefined {\n if (value === null || typeof value !== 'object' || Array.isArray(value)) return undefined\n const input = value as Record<string, unknown>\n if (typeof input.id !== 'string' || typeof input.root !== 'string' || typeof input.path !== 'string'\n || typeof input.branch !== 'string' || typeof input.createdAt !== 'string'\n || (input.pluginGeneratedBranch !== undefined && typeof input.pluginGeneratedBranch !== 'boolean')\n || (input.sessionId !== undefined && typeof input.sessionId !== 'string')) return undefined\n return {\n id: input.id,\n root: input.root,\n path: input.path,\n branch: input.branch,\n createdAt: input.createdAt,\n pluginGeneratedBranch: input.pluginGeneratedBranch === true,\n ...(input.sessionId === undefined ? {} : { sessionId: input.sessionId }),\n }\n}\n\nexport class RepositorySetupService {\n readonly #runtime: RepositorySetupRuntime\n readonly #leasePath: string\n readonly #worktreeRoot: string\n readonly #branchPrefix: () => Promise<string>\n readonly #summarizeBranch: (intent: string) => Promise<string | undefined>\n readonly #cleanupGraceMs: number\n #gitPath: Promise<string> | undefined\n #pending: Promise<unknown> = Promise.resolve()\n\n constructor(runtime: RepositorySetupRuntime, options: RepositorySetupServiceOptions = {}) {\n this.#runtime = runtime\n this.#leasePath = options.leasePath ?? dshHomePath('plugins', 'dsh-claude', 'worktrees.json')\n this.#worktreeRoot = options.worktreeRoot ?? dshHomePath('plugins', 'dsh-claude', 'worktrees')\n this.#branchPrefix = options.branchPrefix ?? (async () => 'claude')\n this.#summarizeBranch = options.summarizeBranch ?? (async () => undefined)\n this.#cleanupGraceMs = options.cleanupGraceMs ?? CLEANUP_GRACE_MS\n }\n\n async listBranches(cwd: string): Promise<RepositoryBranchList> {\n const git = await this.#git()\n return this.#listBranches(git, await this.#repositoryRoot(git, safePath(cwd)))\n }\n\n /** Refresh remote-tracking refs before listing: a branch pushed after this\n * checkout last fetched has no local ref, so the picker cannot offer it. */\n async refreshBranches(cwd: string): Promise<RepositoryBranchList> {\n const git = await this.#git()\n const root = await this.#repositoryRoot(git, safePath(cwd))\n await this.#fetchRemotes(git, root)\n return this.#listBranches(git, root)\n }\n\n async #listBranches(git: string, root: string): Promise<RepositoryBranchList> {\n const [status, refs, remoteRefs] = await Promise.all([\n this.#run(git, ['status', '--porcelain=v2', '--branch', '--untracked-files=normal'], root),\n this.#run(git, ['for-each-ref', '--format=%(refname:short)', 'refs/heads'], root),\n this.#run(git, ['for-each-ref', '--format=%(refname:short) %(symref)', 'refs/remotes'], root),\n ])\n if (status.exitCode !== 0 || status.lossy || refs.exitCode !== 0 || refs.lossy\n || remoteRefs.exitCode !== 0 || remoteRefs.lossy) {\n throw new RepositorySetupError('repository-unavailable', 'The repository state is unavailable.')\n }\n const current = status.stdout.split(/\\r?\\n/u)\n .find(line => line.startsWith('# branch.head '))\n ?.slice('# branch.head '.length)\n const branches = refs.stdout.split(/\\r?\\n/u).filter(Boolean).sort((left, right) => left.localeCompare(right))\n const remoteBranches = remoteRefs.stdout.split(/\\r?\\n/u)\n .map(line => line.trim().split(/\\s+/u))\n .filter(parts => parts[0] !== undefined && parts[0].length > 0 && parts.length === 1)\n .map(parts => parts[0]!)\n .sort((left, right) => left.localeCompare(right))\n const currentBranch = current === undefined ? undefined : parseCurrentBranch(current)\n return {\n root,\n ...(currentBranch === undefined ? {} : { current: currentBranch }),\n dirty: status.stdout.split(/\\r?\\n/u).some(line => line.length > 0 && !line.startsWith('# ')),\n branches,\n remoteBranches,\n }\n }\n\n async setup(\n cwd: string,\n branchValue: string,\n useWorktree: boolean,\n explicitBranchName?: string,\n progress: RepositorySetupProgress = () => {},\n intent?: string,\n ): Promise<RepositorySetupResult> {\n progress('inspecting')\n const branch = safeBranch(branchValue)\n const info = await this.listBranches(cwd)\n const local = info.branches.includes(branch)\n const remote = info.remoteBranches.includes(branch)\n if (!local && !remote) {\n throw new RepositorySetupError('branch-not-found', 'The selected local or remote-tracking branch does not exist.')\n }\n const requestedBranch = explicitBranchName === undefined ? undefined : safeBranch(explicitBranchName)\n if (useWorktree) {\n return this.#createWorktree(\n info,\n branch,\n local ? `refs/heads/${branch}` : `refs/remotes/${branch}`,\n requestedBranch,\n requestedBranch !== undefined && info.branches.includes(requestedBranch),\n progress,\n intent,\n )\n }\n progress('switching-branch')\n return !local && remote ? this.#checkoutRemote(info, branch) : this.#checkout(info, branch)\n }\n\n /** Tear down a merged branch: remove a plugin worktree (and its lease and\n * branch), or switch a plain checkout back to the base branch and delete\n * the merged branch. Refuses dirty trees. */\n async cleanupMerged(pathValue: string, baseBranch: string): Promise<RepositoryCleanupResult> {\n const path = safePath(pathValue)\n const base = safeBranch(baseBranch)\n const git = await this.#git()\n const status = await this.#run(git, ['status', '--porcelain=v1', '--untracked-files=normal'], path)\n if (status.exitCode !== 0 || status.lossy) throw new RepositorySetupError('repository-unavailable', 'The repository state is unavailable.')\n if (status.stdout.trim().length > 0) throw new RepositorySetupError('dirty-workspace', 'Commit or stash workspace changes before cleaning up.')\n const lease = (await this.#readLeases()).find(item => comparablePath(item.path) === comparablePath(path))\n if (lease !== undefined) {\n return this.#serialize(async () => {\n const removed = await this.#run(git, ['worktree', 'remove', '--', lease.path], lease.root)\n if (removed.exitCode !== 0) throw new RepositorySetupError('worktree-remove-failed', 'Git could not remove the worktree.')\n await this.#run(git, ['branch', '-D', '--', lease.branch], lease.root).catch(() => undefined)\n const current = await this.#readLeases()\n await this.#writeLeases(current.filter(item => item.id !== lease.id))\n return { mode: 'worktree' as const, root: lease.root, branch: lease.branch }\n })\n }\n const root = await this.#repositoryRoot(git, path)\n const head = await this.#run(git, ['symbolic-ref', '--quiet', '--short', 'HEAD'], root)\n const branch = head.exitCode === 0 ? head.stdout.trim() : ''\n if (branch.length === 0 || branch === base) throw new RepositorySetupError('nothing-to-clean', 'The checkout is already on the base branch.')\n const switched = await this.#run(git, ['switch', '--', base], root)\n if (switched.exitCode !== 0) throw new RepositorySetupError('checkout-failed', 'Git could not switch to the base branch.')\n await this.#run(git, ['branch', '-D', '--', branch], root).catch(() => undefined)\n await this.#run(git, ['pull', '--ff-only'], root, GIT_FETCH_TIMEOUT_MS).catch(() => undefined)\n return { mode: 'checkout', root, branch }\n }\n\n bindLease(leaseId: string, sessionId: string): Promise<void> {\n if (leaseId.length === 0 || leaseId.length > 128 || sessionId.length === 0 || sessionId.length > 1_024) {\n return Promise.reject(new RepositorySetupError('invalid-lease', 'The worktree lease is invalid.'))\n }\n return this.#serialize(async () => {\n const leases = await this.#readLeases()\n const index = leases.findIndex(item => item.id === leaseId)\n if (index < 0) throw new RepositorySetupError('lease-not-found', 'The worktree lease no longer exists.')\n const existing = leases[index]\n if (existing === undefined) throw new RepositorySetupError('lease-not-found', 'The worktree lease no longer exists.')\n leases[index] = { ...existing, sessionId }\n await this.#writeLeases(leases)\n })\n }\n\n /** Reconcile leases against the set of directories still referenced by a\n * workspace. Deleting a workspace is the user saying they are done with it,\n * so an unreferenced worktree goes even with uncommitted changes; its\n * sessions are archived first, through `archiveSessions`, or the Host\n * rebuilds the deleted workspace from their headers on the next boot.\n * Fresh leases are retained for a grace period so a worktree created\n * moments ago cannot be swept before its workspace registration lands.\n *\n * Every command runs from the repository root, never from the worktree\n * being removed: spawning in a directory that is already gone throws\n * ENOENT, which used to strand the lease forever. */\n cleanupOrphans(\n activePaths: readonly string[],\n archiveSessions?: (worktreePath: string) => Promise<void>,\n ): Promise<void> {\n const active = new Set(activePaths.map(comparablePath))\n return this.#serialize(async () => {\n const leases = await this.#readLeases()\n const retained: WorktreeLease[] = []\n let changed = false\n const git = await this.#git()\n const now = Date.now()\n for (const item of leases) {\n const age = now - Date.parse(item.createdAt)\n if (active.has(comparablePath(item.path)) || !(age >= this.#cleanupGraceMs)) {\n retained.push(item)\n continue\n }\n try {\n // Best effort: a Host that cannot archive must not strand the lease,\n // and the worktree removal below is what the user asked for.\n await archiveSessions?.(item.path).catch(() => undefined)\n if (await pathExists(item.path)) {\n const removed = await this.#run(git, ['worktree', 'remove', '--force', '--', item.path], item.root)\n if (removed.exitCode !== 0) {\n retained.push(item)\n continue\n }\n } else {\n // The directory is already gone; let Git forget the stale\n // worktree registration before the lease follows it.\n await this.#run(git, ['worktree', 'prune'], item.root).catch(() => undefined)\n }\n if (item.pluginGeneratedBranch) {\n await this.#run(git, ['branch', '-D', '--', item.branch], item.root).catch(() => undefined)\n }\n changed = true\n } catch {\n if (await pathExists(item.root)) retained.push(item)\n else changed = true // the repository itself is gone; the lease is dead weight\n }\n }\n if (changed) await this.#writeLeases(retained)\n await this.#removeUnleasedDirectories(retained, active, now, archiveSessions)\n })\n }\n\n /** Remove directories under the plugin's own worktree root that no lease and\n * no workspace claims. A lease file lost to a crash, or a worktree whose\n * lease write failed, otherwise leaves a directory nothing will ever sweep.\n * The grace period covers the gap between `worktree add` and the lease\n * write, so a worktree being created right now is never taken. */\n async #removeUnleasedDirectories(\n retained: readonly WorktreeLease[],\n active: ReadonlySet<string>,\n now: number,\n archiveSessions?: (worktreePath: string) => Promise<void>,\n ): Promise<void> {\n const leased = new Set(retained.map(item => comparablePath(item.path)))\n let entries: string[]\n try {\n entries = await readdir(this.#worktreeRoot)\n } catch {\n return // no worktree root yet, or it is unreadable; nothing to sweep\n }\n for (const entry of entries) {\n const path = join(this.#worktreeRoot, entry)\n const key = comparablePath(path)\n if (leased.has(key) || active.has(key)) continue\n try {\n const info = await stat(path)\n if (!info.isDirectory()) continue\n const created = info.birthtimeMs > 0 ? info.birthtimeMs : info.mtimeMs\n // Date.now() truncates to whole milliseconds while birthtime carries a\n // fraction, so a directory created moments ago can read as newer than\n // the clock; clamp rather than let that skip a sweep.\n if (Math.max(0, now - created) < this.#cleanupGraceMs) continue\n // A lost lease is still the user's deleted workspace: its sessions\n // have to be archived here too, or the Host rebuilds the workspace\n // from their headers on the next boot.\n await archiveSessions?.(path).catch(() => undefined)\n await rm(path, { recursive: true, force: true })\n } catch {\n // A directory that vanished under us, or one we may not remove; the\n // next pass sees it again.\n }\n }\n }\n\n async #checkoutRemote(info: RepositoryBranchList, remoteBranch: string): Promise<RepositorySetupResult> {\n const separator = remoteBranch.indexOf('/')\n if (separator <= 0 || separator === remoteBranch.length - 1) {\n throw new RepositorySetupError('invalid-branch', 'The remote-tracking branch name is invalid.')\n }\n const localBranch = safeBranch(remoteBranch.slice(separator + 1))\n if (info.branches.includes(localBranch)) {\n const git = await this.#git()\n const upstream = await this.#run(git, ['for-each-ref', '--format=%(upstream:short)', `refs/heads/${localBranch}`], info.root)\n if (upstream.exitCode !== 0 || upstream.lossy) {\n throw new RepositorySetupError('repository-unavailable', 'The local branch tracking state is unavailable.')\n }\n if (upstream.stdout.trim() !== remoteBranch) {\n throw new RepositorySetupError('branch-tracking-conflict', `The local branch ${localBranch} does not track ${remoteBranch}.`)\n }\n return this.#checkout(info, localBranch)\n }\n if (info.dirty) throw new RepositorySetupError('dirty-workspace', 'Commit or stash workspace changes before switching branches.')\n const git = await this.#git()\n const switched = await this.#run(git, ['switch', '--track', '-c', localBranch, `refs/remotes/${remoteBranch}`], info.root)\n if (switched.exitCode !== 0) throw new RepositorySetupError('checkout-failed', 'Git could not create the local tracking branch.')\n return { mode: 'checkout', root: info.root, path: info.root, branch: localBranch }\n }\n\n async #fetchRemotes(git: string, root: string): Promise<void> {\n const fetched = await this.#run(\n git,\n ['-c', 'credential.interactive=never', 'fetch', '--all', '--prune'],\n root,\n GIT_FETCH_TIMEOUT_MS,\n )\n if (fetched.exitCode !== 0 || fetched.lossy) {\n throw new RepositorySetupError('fetch-failed', 'Git could not refresh remote references.')\n }\n }\n\n async #checkout(info: RepositoryBranchList, branch: string): Promise<RepositorySetupResult> {\n if (info.current !== branch) {\n if (info.dirty) throw new RepositorySetupError('dirty-workspace', 'Commit or stash workspace changes before switching branches.')\n const git = await this.#git()\n const worktrees = await this.#run(git, ['worktree', 'list', '--porcelain'], info.root)\n if (worktrees.exitCode !== 0 || worktrees.lossy) throw new RepositorySetupError('repository-unavailable', 'Worktree state is unavailable.')\n const occupiedPath = parseWorktreeBranches(worktrees.stdout).get(branch)\n if (occupiedPath !== undefined && resolve(occupiedPath) !== info.root) {\n throw new RepositorySetupError('branch-occupied', 'The selected branch is already checked out in another worktree.')\n }\n const switched = await this.#run(git, ['switch', '--', branch], info.root)\n if (switched.exitCode !== 0) throw new RepositorySetupError('checkout-failed', 'Git could not switch to the selected branch.')\n }\n return { mode: 'checkout', root: info.root, path: info.root, branch }\n }\n\n async #createWorktree(\n info: RepositoryBranchList,\n baseBranch: string,\n baseRef: string,\n explicitBranchName: string | undefined,\n reuseExistingBranch: boolean,\n progress: RepositorySetupProgress,\n intent: string | undefined,\n ): Promise<RepositorySetupResult> {\n const { root } = info\n const git = await this.#git()\n progress('fetching')\n await this.#fetchRemotes(git, root)\n const suffix = randomUUID().slice(0, 8)\n const stamp = new Date().toISOString().replace(/[-:]/gu, '').replace(/\\.\\d{3}Z$/u, 'Z')\n const branch = explicitBranchName ?? await this.#generatedBranch(info, baseBranch, intent, stamp, suffix, progress)\n const path = join(this.#worktreeRoot, `${slug(basename(root), 'repository')}-${stamp}-${suffix}`)\n progress('creating-worktree')\n await mkdir(this.#worktreeRoot, { recursive: true })\n // A stale registration from a deleted worktree directory would keep the\n // existing branch \"checked out\" and block reusing it.\n if (reuseExistingBranch) await this.#run(git, ['worktree', 'prune'], root).catch(() => undefined)\n const created = await this.#run(\n git,\n reuseExistingBranch ? ['worktree', 'add', '--', path, branch] : ['worktree', 'add', '-b', branch, path, baseRef],\n root,\n )\n if (created.exitCode !== 0) {\n const detail = created.stderr.split(/\\r?\\n/u).map(line => line.trim()).filter(line => line.length > 0).at(-1)\n throw new RepositorySetupError('worktree-failed', detail === undefined ? 'Git could not create the worktree.' : `Git could not create the worktree: ${detail}`)\n }\n const item: WorktreeLease = {\n id: randomUUID(),\n root,\n path,\n branch,\n createdAt: new Date().toISOString(),\n pluginGeneratedBranch: explicitBranchName === undefined,\n }\n progress('saving-worktree')\n try {\n await this.#serialize(async () => {\n const leases = await this.#readLeases()\n await this.#writeLeases([...leases, item])\n })\n } catch (error) {\n await this.#run(git, ['worktree', 'remove', '--force', '--', path], root).catch(() => undefined)\n if (!reuseExistingBranch) await this.#run(git, ['branch', '-D', '--', branch], root).catch(() => undefined)\n throw error\n }\n return { mode: 'worktree', root, path, branch, leaseId: item.id }\n }\n\n /** `<prefix>/<what the draft is about>`, falling back to\n * `<prefix>/<base branch>-<stamp>-<random>` whenever the summary is missing\n * or unusable. The prefix and the fallback shape are unchanged. */\n async #generatedBranch(\n info: RepositoryBranchList,\n baseBranch: string,\n intent: string | undefined,\n stamp: string,\n suffix: string,\n progress: RepositorySetupProgress,\n ): Promise<string> {\n const prefix = safeBranch(await this.#branchPrefix())\n if (intent !== undefined && intent.trim().length > 0) {\n progress('summarizing')\n // The summary is a convenience, never a reason to fail the worktree.\n const summary = await this.#summarizeBranch(intent).catch(() => undefined)\n if (summary !== undefined) return uniqueBranchName(`${prefix}/${summary}`, info.branches)\n }\n return `${prefix}/${slug(baseBranch, 'branch')}-${stamp}-${suffix}`\n }\n\n async #repositoryRoot(git: string, cwd: string): Promise<string> {\n const result = await this.#run(git, ['rev-parse', '--path-format=absolute', '--show-toplevel'], cwd)\n const root = result.stdout.trim()\n if (result.exitCode !== 0 || result.lossy || root.length === 0 || !isAbsolute(root)) {\n throw new RepositorySetupError('not-repository', 'The workspace is not a Git repository.')\n }\n return resolve(root)\n }\n\n #git(): Promise<string> {\n // A cached pending or rejected lookup would wedge every later request, so\n // bound it and drop the cache on failure.\n this.#gitPath ??= this.#runtime.resolveExecutable('git', undefined, AbortSignal.timeout(GIT_TIMEOUT_MS))\n .catch((error: unknown) => {\n this.#gitPath = undefined\n throw error\n })\n return this.#gitPath\n }\n\n\n async #run(executable: string, args: readonly string[], cwd: string, timeoutMs = GIT_TIMEOUT_MS): Promise<CommandResult> {\n return collect(this.#runtime.spawn({\n argv: [executable, ...args],\n cwd,\n stdio: {\n stdin: 'ignore',\n stdout: { maxBytes: MAX_OUTPUT_BYTES },\n stderr: { maxBytes: MAX_OUTPUT_BYTES },\n },\n graceMs: 1_000,\n signal: AbortSignal.timeout(timeoutMs),\n env: {},\n }))\n }\n\n async #readLeases(): Promise<WorktreeLease[]> {\n try {\n const parsed = JSON.parse(await readFile(this.#leasePath, 'utf8')) as unknown\n if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) return []\n const input = parsed as Record<string, unknown>\n if (input.schemaVersion !== LEASE_SCHEMA_VERSION || !Array.isArray(input.leases)) return []\n return input.leases.map(lease).filter((item): item is WorktreeLease => item !== undefined)\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') return []\n throw error\n }\n }\n\n async #writeLeases(leases: readonly WorktreeLease[]): Promise<void> {\n await mkdir(resolve(this.#leasePath, '..'), { recursive: true })\n const temporary = `${this.#leasePath}.${process.pid}.${randomUUID()}.tmp`\n const document: LeaseDocument = { schemaVersion: LEASE_SCHEMA_VERSION, leases }\n try {\n await writeFile(temporary, `${JSON.stringify(document, null, 2)}\\n`, { mode: 0o600 })\n await rename(temporary, this.#leasePath)\n } finally {\n await rm(temporary, { force: true }).catch(() => undefined)\n }\n }\n\n #serialize<T>(operation: () => Promise<T>): Promise<T> {\n const result = this.#pending.then(operation, operation)\n this.#pending = result.then(() => undefined, () => undefined)\n return result\n }\n}\n","import { createHash } from 'node:crypto'\nimport { basename } from 'node:path'\nimport type { SubprocessHandle, SubprocessRuntime } from '@deepseek-ai/dsh-subprocess'\n\nconst MAX_OUTPUT_BYTES = 256 * 1024\nconst MAX_PATCH_CHARS = 64 * 1024\nconst MAX_MESSAGE_CHARS = 512\nconst MAX_PR_TEXT_CHARS = 8 * 1024\nconst MAX_UNPUSHED_COMMITS = 20\nconst GIT_TIMEOUT_MS = 15_000\nconst REMOTE_TIMEOUT_MS = 60_000\nconst GENERATE_TIMEOUT_MS = 60_000\n/** One cold `claude -p` per generation, so everything the subject line cannot\n * use is cost: MCP servers (which `ask` already skips for the same reason,\n * and which stall for as long as an unreachable one takes to give up) and the\n * user's own hooks and settings. Project settings stay: a repository's commit\n * conventions belong in the message. `--tools ''` keeps `--output-format`\n * between it and the prompt -- both flags are variadic. */\nconst GENERATE_ARGUMENTS: readonly string[] = [\n '-p',\n '--strict-mcp-config', '--mcp-config', '{\"mcpServers\":{}}',\n '--setting-sources', 'project,local',\n '--tools', '', '--output-format', 'text',\n]\n\ntype RepositoryActionRuntime = Pick<SubprocessRuntime, 'resolveExecutable' | 'spawn'>\nexport type RepositoryActionKind = 'commit' | 'commit-push' | 'push' | 'create-pr' | 'merge-pr' | 'update-branch'\nexport type RepositoryMergeMethod = 'merge' | 'squash' | 'rebase'\n\ninterface CommandResult {\n readonly exitCode: number | null\n readonly stdout: string\n readonly stderr: string\n readonly lossy: boolean\n}\n\nexport interface RepositoryActionFile {\n readonly path: string\n readonly staged: boolean\n readonly unstaged: boolean\n readonly untracked: boolean\n}\n\nexport interface RepositoryActionCommit {\n readonly hash: string\n readonly subject: string\n}\n\nexport interface RepositoryActionPreview {\n readonly root: string\n readonly branch: string\n readonly head: string\n readonly fingerprint: string\n readonly files: readonly RepositoryActionFile[]\n readonly patch: string\n readonly truncated: boolean\n readonly hasStaged: boolean\n readonly hasUnstaged: boolean\n readonly hasUntracked: boolean\n readonly upstream?: string\n readonly unpushedCommits: readonly RepositoryActionCommit[]\n readonly unpushedTruncated: boolean\n}\n\nexport interface RepositoryActionRequest {\n readonly action: RepositoryActionKind\n readonly fingerprint: string\n readonly message: string\n readonly includeUnstaged: boolean\n readonly prTitle?: string\n readonly prBody?: string\n readonly baseBranch?: string\n readonly draft?: boolean\n readonly mergeMethod?: RepositoryMergeMethod\n}\n\nexport interface RepositoryActionResult {\n readonly commit: string\n readonly pushed: boolean\n readonly pullRequestUrl?: string\n /** Conflicted paths left in the working tree by an update-branch merge or rebase. */\n readonly conflicts?: readonly string[]\n}\n\nexport class RepositoryActionError extends Error {\n readonly code: string\n readonly commit?: string\n\n constructor(code: string, message: string, commit?: string) {\n super(message)\n this.name = 'RepositoryActionError'\n this.code = code\n if (commit !== undefined) this.commit = commit\n }\n}\n\nasync function collect(handle: SubprocessHandle): Promise<CommandResult> {\n const outcome = await handle.done\n const stdout = handle.collected.stdout?.readFrom(0)\n const stderr = handle.collected.stderr?.readFrom(0)\n return {\n exitCode: outcome.exitCode,\n stdout: stdout?.text ?? '',\n stderr: stderr?.text ?? '',\n lossy: stdout?.lossy === true || stderr?.lossy === true,\n }\n}\n\nfunction safeText(value: string, maximum: number, label: string): string {\n const text = value.trim()\n if (text.length === 0 || text.length > maximum || /[\\0\\r]/u.test(text)) {\n throw new RepositoryActionError('invalid-request', `${label} is invalid.`)\n }\n return text\n}\n\nexport function isProtectedWarpPath(path: string): boolean {\n return basename(path.replaceAll('\\\\', '/')).toLocaleLowerCase('en-US') === 'warp.md'\n}\n\nexport function parseRepositoryActionStatus(output: string): readonly RepositoryActionFile[] {\n const files = new Map<string, RepositoryActionFile>()\n const records = output.includes('\\0') ? output.split('\\0') : output.split(/\\r?\\n/u)\n for (let position = 0; position < records.length; position += 1) {\n const line = records[position] ?? ''\n if (line.length < 4) continue\n const index = line[0] ?? ' '\n const worktree = line[1] ?? ' '\n let path = line.slice(3)\n const rename = path.lastIndexOf(' -> ')\n if (rename >= 0) path = path.slice(rename + 4)\n if (output.includes('\\0') && (index === 'R' || index === 'C' || worktree === 'R' || worktree === 'C')) position += 1\n if (path.length === 0 || path.includes('\\0') || isProtectedWarpPath(path)) continue\n files.set(path, {\n path,\n staged: index !== ' ' && index !== '?',\n unstaged: worktree !== ' ' && worktree !== '?',\n untracked: index === '?' && worktree === '?',\n })\n }\n return [...files.values()].sort((left, right) => left.path.localeCompare(right.path))\n}\n\nfunction fallbackCommitMessage(files: readonly RepositoryActionFile[]): string {\n if (files.length === 1) return `Update ${files[0]?.path ?? 'repository files'}`\n return `Update ${files.length} repository files`\n}\n\nfunction normalizedGeneratedMessage(value: string, fallback: string): string {\n const first = value.split(/\\r?\\n/u).map(line => line.trim()).find(Boolean)\n if (first === undefined) return fallback\n const message = first.replace(/^['\"`]+|['\"`]+$/gu, '').replace(/[\\0\\r\\n]/gu, ' ').trim()\n return message.length === 0 || message.length > 72 ? fallback : message\n}\n\nfunction validPrUrl(value: string): string | undefined {\n try {\n const url = new URL(value.trim())\n return url.protocol === 'https:' && url.hostname === 'github.com' ? url.href : undefined\n } catch {\n return undefined\n }\n}\n\nexport function validPullRequestBody(value: string): boolean {\n const body = value.trim()\n const match = /^Summary:\\s+([^\\r\\n]+)\\r?\\n\\r?\\nChanges:\\s*\\r?\\n([\\s\\S]+)$/u.exec(body)\n const summary = match?.[1]?.trim()\n const changes = match?.[2]?.trim()\n if (summary === undefined || summary.length === 0 || changes === undefined || changes.length === 0) return false\n return !/^#{1,6}\\s|^[A-Za-z][A-Za-z ]+:\\s*$/mu.test(changes)\n}\n\nexport class RepositoryActionService {\n readonly #runtime: RepositoryActionRuntime\n readonly #claudeExecutable: string\n readonly #invalidate: (cwd: string) => void\n #gitExecutable?: Promise<string>\n #ghExecutable?: Promise<string>\n #pending: Promise<unknown> = Promise.resolve()\n\n constructor(runtime: RepositoryActionRuntime, claudeExecutable: string, invalidate: (cwd: string) => void = () => {}) {\n this.#runtime = runtime\n this.#claudeExecutable = claudeExecutable\n this.#invalidate = invalidate\n }\n\n preview(cwd: string): Promise<RepositoryActionPreview> {\n return this.#preview(cwd)\n }\n\n async generateMessage(cwd: string, fingerprint: string): Promise<string> {\n const preview = await this.#preview(cwd)\n if (preview.fingerprint !== fingerprint) throw new RepositoryActionError('repository-changed', 'Repository changes have changed. Refresh the commit panel.')\n const fallback = fallbackCommitMessage(preview.files)\n const prompt = [\n 'Write one concise English git commit subject (imperative mood, maximum 72 characters).',\n 'Return only the subject without quotes, markdown, body, or explanation.',\n `Files: ${preview.files.map(file => file.path).join(', ')}`,\n `Diff:\\n${preview.patch.slice(0, 24 * 1024)}`,\n ].join('\\n')\n try {\n const result = await this.#run(this.#claudeExecutable, GENERATE_ARGUMENTS.concat(prompt), preview.root, GENERATE_TIMEOUT_MS)\n return result.exitCode === 0 && !result.lossy ? normalizedGeneratedMessage(result.stdout, fallback) : fallback\n } catch {\n return fallback\n }\n }\n\n execute(cwd: string, request: RepositoryActionRequest): Promise<RepositoryActionResult> {\n const operation = this.#pending.then(() => this.#execute(cwd, request))\n this.#pending = operation.then(() => undefined, () => undefined)\n return operation\n }\n\n async #execute(cwd: string, request: RepositoryActionRequest): Promise<RepositoryActionResult> {\n const before = await this.#preview(cwd)\n if (before.fingerprint !== request.fingerprint) throw new RepositoryActionError('repository-changed', 'Repository changes have changed. Refresh the commit panel.')\n if (request.action === 'push') {\n const git = await this.#git()\n try {\n await this.#push(git, before.root, before.branch)\n } catch (error) {\n throw new RepositoryActionError('push-failed', error instanceof Error ? error.message : 'Git push failed.')\n }\n this.#invalidate(before.root)\n return { commit: before.head, pushed: true }\n }\n if (request.action === 'merge-pr') {\n const method = request.mergeMethod\n if (method !== 'merge' && method !== 'squash' && method !== 'rebase') {\n throw new RepositoryActionError('invalid-request', 'The merge method is invalid.')\n }\n let gh: string\n try {\n gh = await this.#gh()\n } catch (error) {\n throw new RepositoryActionError('gh-unavailable', error instanceof Error ? error.message : 'GitHub CLI is unavailable.')\n }\n const merged = await this.#run(gh, ['pr', 'merge', `--${method}`], before.root, REMOTE_TIMEOUT_MS)\n if (merged.exitCode !== 0 || merged.lossy) {\n const reason = merged.stderr.split(/\\r?\\n/u).map(line => line.trim()).filter(line => line.length > 0).at(-1)\n throw new RepositoryActionError('merge-failed', reason === undefined || reason.length === 0 ? 'The pull request could not be merged.' : reason)\n }\n this.#invalidate(before.root)\n return { commit: before.head, pushed: true }\n }\n if (request.action === 'update-branch') {\n const base = safeText(request.baseBranch ?? '', 512, 'Base branch')\n if (before.files.length > 0) {\n throw new RepositoryActionError('dirty-workspace', 'Commit or stash workspace changes before updating the branch.')\n }\n const method = request.mergeMethod ?? 'rebase'\n if (method !== 'merge' && method !== 'rebase') throw new RepositoryActionError('invalid-request', 'Update branch supports merge or rebase.')\n const git = await this.#git()\n await this.#mustRun(git, ['fetch', 'origin', '--', base], before.root, REMOTE_TIMEOUT_MS, 'fetch-failed', 'Git could not fetch the base branch.')\n const merged = await this.#run(git, method === 'rebase' ? ['rebase', '--', `origin/${base}`] : ['merge', '--no-edit', '--', `origin/${base}`], before.root, REMOTE_TIMEOUT_MS)\n if (merged.exitCode !== 0 || merged.lossy) {\n const conflicted = await this.#run(git, ['diff', '--name-only', '--diff-filter=U', '--'], before.root, GIT_TIMEOUT_MS)\n const conflicts = conflicted.exitCode === 0 && !conflicted.lossy\n ? conflicted.stdout.split(/\\r?\\n/u).filter(line => line.length > 0).slice(0, 100)\n : []\n if (conflicts.length === 0) {\n await this.#run(git, [method, '--abort'], before.root, GIT_TIMEOUT_MS).catch(() => undefined)\n throw new RepositoryActionError('merge-failed', `Git could not ${method} the base branch.`)\n }\n // Leave the conflicted tree in place: resolving it is the next step.\n this.#invalidate(before.root)\n return { commit: before.head, pushed: false, conflicts }\n }\n const mergedHead = (await this.#mustRun(git, ['rev-parse', 'HEAD'], before.root, GIT_TIMEOUT_MS, 'merge-failed', 'The updated commit could not be verified.')).stdout.trim()\n try {\n // A rebase rewrites the branch, so the push must replace the remote ref; --force-with-lease still refuses if someone else pushed.\n await this.#push(git, before.root, before.branch, method === 'rebase')\n } catch (error) {\n throw new RepositoryActionError('push-failed', error instanceof Error ? error.message : 'Git push failed.', mergedHead)\n }\n this.#invalidate(before.root)\n return { commit: mergedHead, pushed: true }\n }\n const message = safeText(request.message, MAX_MESSAGE_CHARS, 'Commit message')\n if (before.files.length === 0 && request.action !== 'create-pr') {\n throw new RepositoryActionError('nothing-to-commit', 'There are no changes to commit.')\n }\n const git = await this.#git()\n let oid = before.head\n if (before.files.length > 0) {\n await this.#rejectStagedWarp(git, before.root)\n if (request.includeUnstaged) {\n const paths = before.files.filter(file => file.unstaged || file.untracked).map(file => file.path)\n if (paths.length > 0) await this.#mustRun(git, ['add', '--', ...paths], before.root, GIT_TIMEOUT_MS, 'stage-failed', 'Changes could not be staged.')\n }\n await this.#rejectStagedWarp(git, before.root)\n const staged = await this.#run(git, ['diff', '--cached', '--quiet', '--exit-code', '--'], before.root, GIT_TIMEOUT_MS)\n if (staged.exitCode === 0) throw new RepositoryActionError('nothing-to-commit', 'There are no staged changes to commit.')\n if (staged.exitCode !== 1) throw new RepositoryActionError('repository-unavailable', 'The staged changes could not be verified.')\n await this.#mustRun(git, ['commit', '-m', message, '--'], before.root, GIT_TIMEOUT_MS, 'commit-failed', 'Git commit failed.')\n oid = (await this.#mustRun(git, ['rev-parse', 'HEAD'], before.root, GIT_TIMEOUT_MS, 'commit-failed', 'The new commit could not be verified.')).stdout.trim()\n this.#invalidate(before.root)\n if (request.action === 'commit') return { commit: oid, pushed: false }\n }\n try {\n await this.#push(git, before.root, before.branch)\n } catch (error) {\n throw new RepositoryActionError('push-failed', error instanceof Error ? error.message : 'Git push failed.', oid)\n }\n this.#invalidate(before.root)\n if (request.action === 'commit-push') return { commit: oid, pushed: true }\n const title = safeText(request.prTitle ?? message, 256, 'Pull request title')\n const body = safeText(request.prBody ?? '', MAX_PR_TEXT_CHARS, 'Pull request description')\n if (!validPullRequestBody(body)) {\n throw new RepositoryActionError('invalid-pr-description', 'Pull request description must contain only Summary and Changes sections.', oid)\n }\n let gh: string\n try {\n gh = await this.#gh()\n } catch (error) {\n throw new RepositoryActionError('gh-unavailable', error instanceof Error ? error.message : 'GitHub CLI is unavailable.', oid)\n }\n const args = ['pr', 'create', '--title', title, '--body', body]\n if (request.draft !== false) args.push('--draft')\n if (request.baseBranch !== undefined) args.push('--base', safeText(request.baseBranch, 512, 'Base branch'))\n const created = await this.#run(gh, args, before.root, REMOTE_TIMEOUT_MS)\n const url = created.exitCode === 0 && !created.lossy ? validPrUrl(created.stdout) : undefined\n if (url === undefined) throw new RepositoryActionError('pr-failed', 'The pull request could not be created.', oid)\n return { commit: oid, pushed: true, pullRequestUrl: url }\n }\n\n async #preview(cwd: string): Promise<RepositoryActionPreview> {\n const git = await this.#git()\n const rootResult = await this.#mustRun(git, ['rev-parse', '--path-format=absolute', '--show-toplevel'], cwd, GIT_TIMEOUT_MS, 'not-repository', 'The session directory is not a Git repository.')\n const root = rootResult.stdout.trim()\n const [branchResult, headResult, statusResult, stagedPatch, unstagedPatch] = await Promise.all([\n this.#run(git, ['symbolic-ref', '--quiet', '--short', 'HEAD'], root, GIT_TIMEOUT_MS),\n this.#run(git, ['rev-parse', 'HEAD'], root, GIT_TIMEOUT_MS),\n this.#run(git, ['status', '--porcelain=v1', '-z', '--untracked-files=all'], root, GIT_TIMEOUT_MS),\n this.#run(git, ['diff', '--cached', '--no-ext-diff', '--no-color', '--unified=3', '--', ':(exclude)WARP.md', ':(exclude)**/WARP.md'], root, GIT_TIMEOUT_MS, MAX_OUTPUT_BYTES),\n this.#run(git, ['diff', '--no-ext-diff', '--no-color', '--unified=3', '--', ':(exclude)WARP.md', ':(exclude)**/WARP.md'], root, GIT_TIMEOUT_MS, MAX_OUTPUT_BYTES),\n ])\n if (branchResult.exitCode !== 0) throw new RepositoryActionError('detached-head', 'A detached HEAD cannot be committed from this panel.')\n if (headResult.exitCode !== 0 || statusResult.exitCode !== 0 || statusResult.lossy) throw new RepositoryActionError('repository-unavailable', 'Repository state is unavailable.')\n const files = parseRepositoryActionStatus(statusResult.stdout)\n const patch = `${stagedPatch.stdout}${stagedPatch.stdout.length > 0 && unstagedPatch.stdout.length > 0 ? '\\n' : ''}${unstagedPatch.stdout}`.slice(0, MAX_PATCH_CHARS)\n const branch = branchResult.stdout.trim()\n const head = headResult.stdout.trim()\n const fingerprint = createHash('sha256').update([head, branch, statusResult.stdout, stagedPatch.stdout, unstagedPatch.stdout].join('\\0')).digest('hex')\n const upstreamResult = await this.#run(git, ['rev-parse', '--abbrev-ref', '--symbolic-full-name', '@{upstream}'], root, GIT_TIMEOUT_MS)\n const upstream = upstreamResult.exitCode === 0 && !upstreamResult.lossy ? upstreamResult.stdout.trim() : undefined\n const logResult = await this.#run(git, [\n 'log', '--format=%H%x09%s', `-n`, String(MAX_UNPUSHED_COMMITS + 1), upstream === undefined ? 'HEAD' : '@{upstream}..HEAD', '--',\n ], root, GIT_TIMEOUT_MS)\n const commitLines = logResult.exitCode === 0 && !logResult.lossy\n ? logResult.stdout.split(/\\r?\\n/u).filter(line => line.includes('\\t'))\n : []\n const unpushedCommits = commitLines.slice(0, MAX_UNPUSHED_COMMITS).flatMap(line => {\n const tab = line.indexOf('\\t')\n const hash = line.slice(0, tab)\n return /^[0-9a-f]{40}$/iu.test(hash) ? [{ hash, subject: line.slice(tab + 1).slice(0, 140) }] : []\n })\n return {\n root,\n branch,\n head,\n fingerprint,\n files,\n patch,\n truncated: stagedPatch.lossy || unstagedPatch.lossy || stagedPatch.stdout.length + unstagedPatch.stdout.length > MAX_PATCH_CHARS,\n hasStaged: files.some(file => file.staged),\n hasUnstaged: files.some(file => file.unstaged),\n hasUntracked: files.some(file => file.untracked),\n ...(upstream === undefined ? {} : { upstream }),\n unpushedCommits,\n unpushedTruncated: commitLines.length > MAX_UNPUSHED_COMMITS,\n }\n }\n\n async #rejectStagedWarp(git: string, cwd: string): Promise<void> {\n const staged = await this.#run(git, ['diff', '--cached', '--name-only', '--'], cwd, GIT_TIMEOUT_MS)\n if (staged.exitCode !== 0 || staged.lossy) throw new RepositoryActionError('repository-unavailable', 'Staged files could not be verified.')\n if (staged.stdout.split(/\\r?\\n/u).some(path => path.length > 0 && isProtectedWarpPath(path))) {\n throw new RepositoryActionError('protected-warp-file', 'WARP.md files cannot be committed. Unstage them before continuing.')\n }\n }\n\n async #push(git: string, cwd: string, branch: string, forceWithLease = false): Promise<void> {\n const upstream = await this.#run(git, ['rev-parse', '--abbrev-ref', '--symbolic-full-name', '@{upstream}'], cwd, GIT_TIMEOUT_MS)\n const args = upstream.exitCode === 0 ? ['push', ...(forceWithLease ? ['--force-with-lease'] : [])] : ['push', '--set-upstream', 'origin', branch]\n await this.#mustRun(git, args, cwd, REMOTE_TIMEOUT_MS, 'push-failed', 'Git push failed.')\n }\n\n #git(): Promise<string> {\n this.#gitExecutable ??= this.#runtime.resolveExecutable('git')\n return this.#gitExecutable\n }\n\n #gh(): Promise<string> {\n this.#ghExecutable ??= this.#runtime.resolveExecutable('gh').catch(() => { throw new RepositoryActionError('gh-unavailable', 'GitHub CLI is unavailable.') })\n return this.#ghExecutable\n }\n\n async #mustRun(executable: string, args: readonly string[], cwd: string, timeoutMs: number, code: string, message: string): Promise<CommandResult> {\n const result = await this.#run(executable, args, cwd, timeoutMs)\n if (result.exitCode !== 0 || result.lossy) throw new RepositoryActionError(code, message)\n return result\n }\n\n #run(executable: string, args: readonly string[], cwd: string, timeoutMs: number, maxBytes = MAX_OUTPUT_BYTES): Promise<CommandResult> {\n return collect(this.#runtime.spawn({\n argv: [executable, ...args],\n cwd,\n stdio: { stdin: 'ignore', stdout: { maxBytes }, stderr: { maxBytes: MAX_OUTPUT_BYTES } },\n graceMs: 1_000,\n signal: AbortSignal.timeout(timeoutMs),\n env: {},\n }))\n }\n}\n","import type { ServerResponse } from 'node:http'\nimport type { Context } from '@deepseek-ai/cordis'\nimport type {} from '@deepseek-ai/dsh-host-webserver'\nimport { CLAUDE_REPOSITORY_SETUP_PATH } from './constants.ts'\nimport { json, registerPluginRoute, type PluginRouteIo } from './http.ts'\nimport {\n RepositorySetupError,\n type RepositorySetupResult,\n type RepositorySetupService,\n type RepositorySetupStage,\n} from './repository-setup.ts'\n\nconst MAX_BODY_BYTES = 16 * 1024\n\nfunction record(value: unknown): Record<string, unknown> | undefined {\n return value !== null && typeof value === 'object' && !Array.isArray(value)\n ? value as Record<string, unknown>\n : undefined\n}\n\nasync function readJson(io: PluginRouteIo): Promise<Record<string, unknown>> {\n let parsed: unknown\n try {\n parsed = await io.body<unknown>(MAX_BODY_BYTES)\n } catch (error) {\n if (error instanceof SyntaxError) throw error\n throw new RepositorySetupError('body-too-large', 'The request body is too large.')\n }\n const value = record(parsed)\n if (value === undefined) throw new RepositorySetupError('invalid-request', 'The request body is invalid.')\n return value\n}\n\nfunction string(input: Record<string, unknown>, key: string): string {\n const value = input[key]\n if (typeof value !== 'string') throw new RepositorySetupError('invalid-request', `The ${key} field is required.`)\n return value\n}\n\nfunction optionalString(input: Record<string, unknown>, key: string): string | undefined {\n const value = input[key]\n if (value === undefined) return undefined\n if (typeof value !== 'string') throw new RepositorySetupError('invalid-request', `The ${key} field must be a string.`)\n return value\n}\n\nfunction ndjsonHeaders(res: ServerResponse): void {\n res.writeHead(200, {\n 'content-type': 'application/x-ndjson; charset=utf-8',\n 'cache-control': 'no-store',\n 'x-content-type-options': 'nosniff',\n })\n res.flushHeaders?.()\n}\n\nfunction ndjson(res: ServerResponse, value: unknown): void {\n res.write(`${JSON.stringify(value)}\\n`)\n}\n\n// `RepositorySetupService.setup` takes no signal, so the route's disconnect\n// abort cannot reach the Git work it drives; the stream registration is still\n// what bounds how many of these may be live at once.\nasync function streamSetup(\n res: ServerResponse,\n service: RepositorySetupService,\n input: Record<string, unknown>,\n): Promise<void> {\n ndjsonHeaders(res)\n let ended = false\n try {\n const result: RepositorySetupResult = await service.setup(\n string(input, 'cwd'),\n string(input, 'branch'),\n input.worktree as boolean,\n optionalString(input, 'branchName'),\n (stage: RepositorySetupStage) => { if (!ended) ndjson(res, { type: 'progress', stage }) },\n optionalString(input, 'intent'),\n )\n ndjson(res, { type: 'complete', result })\n } catch (error) {\n const setupError = error instanceof RepositorySetupError ? error : undefined\n ndjson(res, {\n type: 'error',\n code: setupError?.code ?? 'repository-setup-unavailable',\n message: setupError?.message ?? 'Repository setup is unavailable.',\n })\n } finally {\n ended = true\n res.end()\n }\n}\n\n/** Register trusted browser routes for safe pre-session Git setup.\n *\n * The prefix is registered as a stream because the setup POST holds its\n * connection open for the whole worktree build; the short sibling paths ride\n * the same registration and answer with `json` before releasing it. */\nexport function registerRepositorySetupRoute(\n ctx: Context,\n service: RepositorySetupService,\n /** Kick the worktree/workspace reconciliation, when the Host exposes one. */\n sweep?: () => void,\n): void {\n registerPluginRoute(ctx, {\n mode: 'stream',\n kind: 'prefix',\n path: CLAUDE_REPOSITORY_SETUP_PATH,\n methods: ['GET', 'POST'],\n maxConcurrent: 2,\n // Only the branch paths name their checkout in the URL; the setup POST\n // carries it in the body, so it keys on its path alone and a reopen\n // supersedes the response it is replacing.\n streamKey: url => `${url.pathname}?${url.searchParams.get('cwd') ?? url.searchParams.get('branch') ?? ''}`,\n handler: async (res, io) => {\n const pathname = io.url.pathname\n try {\n // Not a GET: --prune rewrites this checkout's remote-tracking refs.\n if (pathname === `${CLAUDE_REPOSITORY_SETUP_PATH}/branches/refresh`) {\n if (io.method !== 'POST') return json(res, 405, { error: 'method not allowed' })\n const input = await readJson(io)\n return json(res, 200, await service.refreshBranches(string(input, 'cwd')))\n }\n if (pathname === `${CLAUDE_REPOSITORY_SETUP_PATH}/branches`) {\n if (io.method !== 'GET') return json(res, 405, { error: 'method not allowed' })\n const cwd = io.url.searchParams.get('cwd')\n if (cwd === null) throw new RepositorySetupError('invalid-request', 'The cwd query parameter is required.')\n return json(res, 200, await service.listBranches(cwd))\n }\n if (pathname === CLAUDE_REPOSITORY_SETUP_PATH) {\n if (io.method !== 'POST') return json(res, 405, { error: 'method not allowed' })\n const input = await readJson(io)\n if (typeof input.worktree !== 'boolean') throw new RepositorySetupError('invalid-request', 'The worktree field is required.')\n await streamSetup(res, service, input)\n return\n }\n if (pathname === `${CLAUDE_REPOSITORY_SETUP_PATH}/cleanup`) {\n if (io.method !== 'POST') return json(res, 405, { error: 'method not allowed' })\n const input = await readJson(io)\n return json(res, 200, await service.cleanupMerged(string(input, 'path'), string(input, 'baseBranch')))\n }\n // The Host's own workspace deletion publishes no server-side event, so\n // the Client kicks the sweep the moment a workspace leaves its list.\n // Carries no payload: the sweep re-reads the registry itself.\n if (pathname === `${CLAUDE_REPOSITORY_SETUP_PATH}/sweep`) {\n if (io.method !== 'POST') return json(res, 405, { error: 'method not allowed' })\n sweep?.()\n return json(res, 200, { ok: true })\n }\n if (pathname === `${CLAUDE_REPOSITORY_SETUP_PATH}/bind`) {\n if (io.method !== 'POST') return json(res, 405, { error: 'method not allowed' })\n const input = await readJson(io)\n await service.bindLease(string(input, 'leaseId'), string(input, 'sessionId'))\n return json(res, 200, { ok: true })\n }\n return json(res, 404, { error: 'not found' })\n } catch (error) {\n if (error instanceof RepositorySetupError) return json(res, 409, { error: error.code, message: error.message })\n if (error instanceof SyntaxError) return json(res, 400, { error: 'invalid json' })\n return json(res, 500, { error: 'repository setup unavailable' })\n }\n },\n })\n}\n","import type { Context } from '@deepseek-ai/cordis'\nimport type {} from '@deepseek-ai/dsh-host-webserver'\nimport { CLAUDE_REPOSITORY_ACTION_PATH } from './constants.ts'\nimport { registerPluginRoute, type PluginRouteIo } from './http.ts'\nimport {\n RepositoryActionError,\n type RepositoryActionKind,\n type RepositoryActionRequest,\n type RepositoryMergeMethod,\n type RepositoryActionService,\n} from './repository-actions.ts'\n\nconst MAX_BODY_BYTES = 16 * 1024\nconst MAX_SESSION_ID_CHARS = 1_024\nconst ACTIONS = new Set<RepositoryActionKind>(['commit', 'commit-push', 'push', 'create-pr', 'merge-pr', 'update-branch'])\n\nfunction record(value: unknown): Record<string, unknown> | undefined {\n return value !== null && typeof value === 'object' && !Array.isArray(value) ? value as Record<string, unknown> : undefined\n}\n\nasync function readJson(io: PluginRouteIo): Promise<Record<string, unknown>> {\n let parsed: unknown\n try {\n parsed = await io.body<unknown>(MAX_BODY_BYTES)\n } catch (error) {\n // Malformed JSON keeps its own 400; the cap is the only other refusal the\n // transport raises, and the panel already knows that code.\n if (error instanceof SyntaxError) throw error\n throw new RepositoryActionError('body-too-large', 'The request body is too large.')\n }\n const value = record(parsed)\n if (value === undefined) throw new RepositoryActionError('invalid-request', 'The request body is invalid.')\n return value\n}\n\nfunction sessionId(url: URL): string {\n const value = url.searchParams.get('sessionId')\n if (value === null || value.length === 0 || value.length > MAX_SESSION_ID_CHARS) {\n throw new RepositoryActionError('invalid-session', 'The session is invalid.')\n }\n return value\n}\n\nfunction string(input: Record<string, unknown>, key: string): string {\n const value = input[key]\n if (typeof value !== 'string') throw new RepositoryActionError('invalid-request', `The ${key} field is required.`)\n return value\n}\n\nfunction optionalString(input: Record<string, unknown>, key: string): string | undefined {\n const value = input[key]\n if (value === undefined) return undefined\n if (typeof value !== 'string') throw new RepositoryActionError('invalid-request', `The ${key} field must be a string.`)\n return value\n}\n\nfunction actionRequest(input: Record<string, unknown>): RepositoryActionRequest {\n const action = input.action\n if (typeof action !== 'string' || !ACTIONS.has(action as RepositoryActionKind)\n || typeof input.includeUnstaged !== 'boolean') {\n throw new RepositoryActionError('invalid-request', 'The repository action is invalid.')\n }\n return {\n action: action as RepositoryActionKind,\n fingerprint: string(input, 'fingerprint'),\n message: action === 'push' || action === 'merge-pr' || action === 'update-branch' ? optionalString(input, 'message') ?? '' : string(input, 'message'),\n includeUnstaged: input.includeUnstaged,\n ...(optionalString(input, 'prTitle') === undefined ? {} : { prTitle: optionalString(input, 'prTitle')! }),\n ...(optionalString(input, 'prBody') === undefined ? {} : { prBody: optionalString(input, 'prBody')! }),\n ...(optionalString(input, 'baseBranch') === undefined ? {} : { baseBranch: optionalString(input, 'baseBranch')! }),\n ...(input.draft === undefined ? {} : typeof input.draft === 'boolean' ? { draft: input.draft } : (() => { throw new RepositoryActionError('invalid-request', 'The draft field must be a boolean.') })()),\n ...(input.mergeMethod === undefined\n ? {}\n : input.mergeMethod === 'merge' || input.mergeMethod === 'squash' || input.mergeMethod === 'rebase'\n ? { mergeMethod: input.mergeMethod as RepositoryMergeMethod }\n : (() => { throw new RepositoryActionError('invalid-request', 'The mergeMethod field is invalid.') })()),\n }\n}\n\n/** One prefix serves the local-Git preview and the POST arms that push, open\n * and merge pull requests, so the registration takes the wider of the two\n * budgets: a `remote` arm cut short at the `git` deadline would abandon work\n * that had already reached GitHub. */\nexport function registerRepositoryActionRoute(\n ctx: Context,\n service: RepositoryActionService,\n cwdForSession: (sessionId: string) => string | undefined,\n): void {\n registerPluginRoute(ctx, {\n mode: 'unary',\n kind: 'prefix',\n path: CLAUDE_REPOSITORY_ACTION_PATH,\n methods: ['GET', 'POST'],\n budget: 'remote',\n handler: async io => {\n const url = io.url\n try {\n const id = sessionId(url)\n const cwd = cwdForSession(id)\n if (cwd === undefined) throw new RepositoryActionError('session-unavailable', 'The Claude session is unavailable.')\n if (url.pathname === `${CLAUDE_REPOSITORY_ACTION_PATH}/preview`) {\n if (io.method !== 'GET') return { status: 405, value: { error: 'method not allowed' } }\n return { status: 200, value: await service.preview(cwd) }\n }\n if (url.pathname === `${CLAUDE_REPOSITORY_ACTION_PATH}/message`) {\n if (io.method !== 'POST') return { status: 405, value: { error: 'method not allowed' } }\n const input = await readJson(io)\n return { status: 200, value: { message: await service.generateMessage(cwd, string(input, 'fingerprint')) } }\n }\n if (url.pathname === CLAUDE_REPOSITORY_ACTION_PATH) {\n if (io.method !== 'POST') return { status: 405, value: { error: 'method not allowed' } }\n return { status: 200, value: await service.execute(cwd, actionRequest(await readJson(io))) }\n }\n return { status: 404, value: { error: 'not found' } }\n } catch (error) {\n if (error instanceof RepositoryActionError) {\n return {\n status: 409,\n value: {\n error: error.code,\n message: error.message,\n ...(error.commit === undefined ? {} : { commit: error.commit }),\n },\n }\n }\n if (error instanceof SyntaxError) return { status: 400, value: { error: 'invalid-json' } }\n return { status: 500, value: { error: 'repository-action-unavailable', message: 'Repository action is unavailable.' } }\n }\n },\n })\n}\n","import type { SubprocessHandle, SubprocessRuntime } from '@deepseek-ai/dsh-subprocess'\n\nconst MAX_OUTPUT_BYTES = 8 * 1024\n/** Long enough for a launcher shim to fail loudly, short enough that the\n * request returns while the IDE is still booting. On Windows and Linux the\n * IDE binary IS the launched process, so still running past this is success. */\nconst SETTLE_MS = 1_500\n\nexport type EditorId = 'cursor' | 'idea'\nexport const EDITOR_IDS: ReadonlySet<string> = new Set<EditorId>(['cursor', 'idea'])\n\n/** Launch commands tried in order, first success wins. macOS keeps `open -a`\n * behind the CLI shim because both shims are opt-in installs there, while\n * `open -a` finds the bundle wherever Toolbox or the DMG dropped it. */\nconst LAUNCHERS: Record<EditorId, Partial<Record<NodeJS.Platform, readonly (readonly string[])[]>>> = {\n cursor: {\n darwin: [['cursor'], ['open', '-a', 'Cursor']],\n win32: [['cursor']],\n linux: [['cursor']],\n },\n idea: {\n darwin: [['idea'], ['open', '-a', 'IntelliJ IDEA'], ['open', '-a', 'IntelliJ IDEA CE']],\n win32: [['idea'], ['idea64.exe']],\n linux: [['idea'], ['idea.sh']],\n },\n}\n\n/** cmd.exe re-interprets these, and a mis-parsed path opens the wrong project\n * rather than failing. Refuse instead of guessing. */\nconst WINDOWS_UNSAFE = /[\"&|<>^%]/u\n\nexport class EditorOpenError extends Error {\n readonly code: string\n\n constructor(code: string, message: string) {\n super(message)\n this.name = 'EditorOpenError'\n this.code = code\n }\n}\n\n/** Open a session's working directory in a desktop editor. */\nexport class EditorOpenService {\n readonly #runtime: Pick<SubprocessRuntime, 'resolveExecutable' | 'spawn'>\n readonly #platform: NodeJS.Platform\n readonly #settleMs: number\n\n constructor(\n runtime: Pick<SubprocessRuntime, 'resolveExecutable' | 'spawn'>,\n platform: NodeJS.Platform = process.platform,\n settleMs: number = SETTLE_MS,\n ) {\n this.#runtime = runtime\n this.#platform = platform\n this.#settleMs = settleMs\n }\n\n async open(cwd: string, editor: EditorId): Promise<void> {\n if (this.#platform === 'win32' && WINDOWS_UNSAFE.test(cwd)) {\n throw new EditorOpenError('unsupported-path', 'The project path cannot be opened through the Windows shell.')\n }\n const candidates = LAUNCHERS[editor][this.#platform] ?? LAUNCHERS[editor].linux ?? []\n let found = false\n for (const candidate of candidates) {\n const argv = await this.#argv(candidate, cwd)\n if (argv === undefined) continue\n found = true\n if (await this.#launch(argv, cwd)) return\n }\n throw found\n ? new EditorOpenError('launch-failed', 'The editor refused to open the project.')\n : new EditorOpenError('editor-unavailable', 'The editor was not found on PATH.')\n }\n\n async #argv(candidate: readonly string[], cwd: string): Promise<readonly string[] | undefined> {\n const [program, ...rest] = candidate\n if (program === undefined) return undefined\n // Windows launcher shims are `.cmd` files, which Node refuses to spawn\n // directly; cmd.exe runs those and plain `.exe` entries alike, and does\n // its own PATH/PATHEXT lookup — so no resolution step here.\n if (this.#platform === 'win32') return ['cmd.exe', '/d', '/s', '/c', program, ...rest, cwd]\n try {\n return [await this.#runtime.resolveExecutable(program), ...rest, cwd]\n } catch {\n return undefined\n }\n }\n\n /** True once the editor is launched: either the shim exited cleanly or the\n * process is still alive past the settle window. */\n async #launch(argv: readonly string[], cwd: string): Promise<boolean> {\n let handle: SubprocessHandle\n try {\n // No abort signal on purpose — the editor must outlive this request.\n // ponytail: on platforms whose launcher does not fork (idea64.exe) the\n // IDE stays a child of the host; detach if that ever orphans badly.\n handle = this.#runtime.spawn({\n argv,\n cwd,\n stdio: { stdin: 'ignore', stdout: { maxBytes: MAX_OUTPUT_BYTES }, stderr: { maxBytes: MAX_OUTPUT_BYTES } },\n graceMs: 1_000,\n env: {},\n })\n } catch {\n return false\n }\n return await Promise.race([\n handle.done.then(outcome => outcome.exitCode === 0),\n new Promise<boolean>(resolve => {\n const timer = setTimeout(() => resolve(true), this.#settleMs)\n timer.unref?.()\n }),\n ])\n }\n}\n","import type { Context } from '@deepseek-ai/cordis'\nimport type {} from '@deepseek-ai/dsh-host-webserver'\nimport { CLAUDE_EDITOR_OPEN_PATH } from './constants.ts'\nimport { registerPluginRoute } from './http.ts'\nimport { EDITOR_IDS, EditorOpenError, type EditorId, type EditorOpenService } from './editor-open.ts'\n\nconst MAX_SESSION_ID_CHARS = 1_024\n\n/** Open the session's working directory in a desktop editor. Query-only: the\n * request carries two enum-ish values, so there is no body to parse. */\nexport function registerEditorOpenRoute(\n ctx: Context,\n service: Pick<EditorOpenService, 'open'>,\n cwdForSession: (sessionId: string) => string | undefined,\n): void {\n registerPluginRoute(ctx, {\n mode: 'unary',\n kind: 'exact',\n path: CLAUDE_EDITOR_OPEN_PATH,\n methods: ['POST'],\n budget: 'fast',\n handler: async io => {\n const params = io.url.searchParams\n const id = params.get('sessionId')\n const editor = params.get('editor')\n if (id === null || id.length === 0 || id.length > MAX_SESSION_ID_CHARS) {\n return { status: 400, value: { error: 'invalid-session', message: 'The session is invalid.' } }\n }\n if (editor === null || !EDITOR_IDS.has(editor)) {\n return { status: 400, value: { error: 'invalid-editor', message: 'The editor is invalid.' } }\n }\n const cwd = cwdForSession(id)\n if (cwd === undefined) return { status: 409, value: { error: 'session-unavailable', message: 'The Claude session is unavailable.' } }\n try {\n await service.open(cwd, editor as EditorId)\n return { status: 200, value: { opened: true } }\n } catch (error) {\n if (error instanceof EditorOpenError) return { status: 409, value: { error: error.code, message: error.message } }\n return { status: 500, value: { error: 'editor-open-unavailable', message: 'The editor could not be launched.' } }\n }\n },\n })\n}\n","/** Only GitHub's own image hosts; the browser loads these directly, so a URL\n * the API did not vouch for must never become an outbound request. */\nexport function githubAvatarUrl(value: unknown): string | undefined {\n if (typeof value !== 'string' || value.length === 0 || value.length > 1_024) return undefined\n try {\n const url = new URL(value)\n const allowed = url.hostname === 'github.com' || url.hostname === 'githubusercontent.com' || url.hostname.endsWith('.githubusercontent.com')\n return url.protocol === 'https:' && allowed ? url.href : undefined\n } catch {\n return undefined\n }\n}\n","import type { SubprocessHandle, SubprocessRuntime } from '@deepseek-ai/dsh-subprocess'\nimport { githubAvatarUrl } from './github-url.ts'\nimport { parseGitHubRemote } from './repository-status.ts'\n\nexport { githubAvatarUrl } from './github-url.ts'\n\nconst MAX_OUTPUT_BYTES = 512 * 1024\nconst GIT_TIMEOUT_MS = 10_000\nconst GH_TIMEOUT_MS = 60_000\nconst MAX_COMMENTS = 100\nconst MAX_THREADS = 100\nconst MAX_MENTIONABLE_USERS = 20\nconst MAX_REPLY_CHARS = 2_000\nconst MAX_COMMENT_CHARS = 4_096\nconst MAX_FAILING_CHECKS = 3\nconst MAX_LOG_CHARS = 8 * 1024\n\ntype FeedbackRuntime = Pick<SubprocessRuntime, 'resolveExecutable' | 'spawn'>\n\ninterface CommandResult {\n readonly exitCode: number | null\n readonly stdout: string\n readonly lossy: boolean\n}\n\nexport interface PullRequestReviewComment {\n readonly id: number\n readonly path: string\n readonly line?: number\n readonly side: 'new' | 'old'\n readonly author: string\n /** GitHub-hosted avatar of the comment's author, when the API named one. */\n readonly avatarUrl?: string\n readonly body: string\n readonly url: string\n /** ISO timestamp GitHub reports; the panel shows it the way GitHub does. */\n readonly createdAt?: string\n /** App account. GraphQL reports it as an actor type; REST spells the login\n * `name[bot]`. Either way the panel shows a Bot pill, like GitHub. */\n readonly bot?: boolean\n}\n\n/** One GitHub review conversation: the comments share an anchor, and Resolve\n * acts on the thread rather than on any single comment. */\nexport interface PullRequestReviewThread {\n /** GraphQL node id — the only handle the resolve mutations accept. */\n readonly id: string\n readonly path: string\n readonly line?: number\n readonly side: 'new' | 'old'\n readonly resolved: boolean\n readonly outdated: boolean\n readonly comments: readonly PullRequestReviewComment[]\n}\n\n/** A user GitHub will notify when the reply names them. */\nexport interface MentionableUser {\n readonly login: string\n readonly avatarUrl?: string\n}\n\nexport interface FailingCheck {\n readonly name: string\n readonly link?: string\n readonly description?: string\n readonly log?: string\n}\n\nexport class PullRequestFeedbackError extends Error {\n readonly code: string\n\n constructor(code: string, message: string) {\n super(message)\n this.name = 'PullRequestFeedbackError'\n this.code = code\n }\n}\n\n/** Threads carry the anchor; comments carry the prose. `isOutdated` marks a\n * thread whose lines the branch has since moved past. */\nconst REVIEW_THREADS_QUERY = `query($owner:String!,$name:String!,$number:Int!){\n repository(owner:$owner,name:$name){\n pullRequest(number:$number){\n reviewThreads(first:100){\n nodes{\n id isResolved isOutdated path line originalLine diffSide\n comments(first:50){ nodes{ databaseId body url createdAt author{ __typename login avatarUrl } } }\n }\n }\n }\n }\n}`\n\nconst RESOLVE_MUTATION = `mutation($threadId:ID!){\n resolveReviewThread(input:{threadId:$threadId}){ thread{ isResolved } }\n}`\n\nconst UNRESOLVE_MUTATION = `mutation($threadId:ID!){\n unresolveReviewThread(input:{threadId:$threadId}){ thread{ isResolved } }\n}`\n\nconst MENTIONABLE_USERS_QUERY = `query($owner:String!,$name:String!,$q:String!){\n repository(owner:$owner,name:$name){\n mentionableUsers(first:20,query:$q){ nodes{ login avatarUrl } }\n }\n}`\n\nasync function collect(handle: SubprocessHandle): Promise<CommandResult> {\n const outcome = await handle.done\n const stdout = handle.collected.stdout?.readFrom(0)\n return { exitCode: outcome.exitCode, stdout: stdout?.text ?? '', lossy: stdout?.lossy === true }\n}\n\nfunction record(value: unknown): Record<string, unknown> | undefined {\n return value !== null && typeof value === 'object' && !Array.isArray(value) ? value as Record<string, unknown> : undefined\n}\n\n/** Read `repository.pullRequest.reviewThreads.nodes` out of a GraphQL response.\n * A payload carrying `errors` instead of data yields nothing rather than\n * throwing: the caller distinguishes \"no threads\" from \"call failed\" by the\n * process exit code. */\nexport function parseReviewThreads(value: unknown): readonly PullRequestReviewThread[] {\n const nodes = record(record(record(record(record(value)?.data)?.repository)?.pullRequest)?.reviewThreads)?.nodes\n if (!Array.isArray(nodes)) return []\n const threads: PullRequestReviewThread[] = []\n let total = 0\n for (const item of nodes) {\n const input = record(item)\n if (input === undefined || typeof input.id !== 'string' || input.id.length === 0) continue\n const path = typeof input.path === 'string' ? input.path : ''\n if (path.length === 0) continue\n const line = Number.isSafeInteger(input.line)\n ? Number(input.line)\n : Number.isSafeInteger(input.originalLine) ? Number(input.originalLine) : undefined\n const side = input.diffSide === 'LEFT' ? 'old' as const : 'new' as const\n const anchor = { path, ...(line === undefined ? {} : { line }), side }\n const comments: PullRequestReviewComment[] = []\n const commentNodes = record(input.comments)?.nodes\n for (const node of Array.isArray(commentNodes) ? commentNodes : []) {\n if (total >= MAX_COMMENTS) break\n const comment = record(node)\n if (comment === undefined || !Number.isSafeInteger(comment.databaseId)) continue\n const body = typeof comment.body === 'string' ? comment.body.trim() : ''\n if (body.length === 0) continue\n const author = record(comment.author)\n const avatarUrl = githubAvatarUrl(author?.avatarUrl)\n const login = typeof author?.login === 'string' ? author.login : 'unknown'\n comments.push({\n id: Number(comment.databaseId),\n ...anchor,\n author: login,\n ...(author?.__typename === 'Bot' || login.endsWith('[bot]') ? { bot: true } : {}),\n ...(avatarUrl === undefined ? {} : { avatarUrl }),\n body: body.slice(0, MAX_COMMENT_CHARS),\n url: typeof comment.url === 'string' ? comment.url : '',\n ...(typeof comment.createdAt === 'string' ? { createdAt: comment.createdAt } : {}),\n })\n total += 1\n }\n // A thread with nothing readable left is not worth an anchor in the diff.\n if (comments.length === 0) continue\n threads.push({\n id: input.id,\n ...anchor,\n resolved: input.isResolved === true,\n outdated: input.isOutdated === true,\n comments,\n })\n if (threads.length >= MAX_THREADS || total >= MAX_COMMENTS) break\n }\n return threads\n}\n\n/** One posted reply, shaped like the thread comments it joins. */\nexport function parseReplyComment(value: unknown, anchor: { path: string; line?: number; side: 'new' | 'old' }): PullRequestReviewComment | undefined {\n const input = record(value)\n if (input === undefined || !Number.isSafeInteger(input.id)) return undefined\n const body = typeof input.body === 'string' ? input.body.trim() : ''\n if (body.length === 0) return undefined\n const user = record(input.user)\n const avatarUrl = githubAvatarUrl(user?.avatar_url)\n const login = typeof user?.login === 'string' ? user.login : 'unknown'\n return {\n id: Number(input.id),\n ...anchor,\n author: login,\n ...(user?.type === 'Bot' || login.endsWith('[bot]') ? { bot: true } : {}),\n ...(avatarUrl === undefined ? {} : { avatarUrl }),\n body: body.slice(0, MAX_COMMENT_CHARS),\n url: typeof input.html_url === 'string' ? input.html_url : '',\n ...(typeof input.created_at === 'string' ? { createdAt: input.created_at } : {}),\n }\n}\n\nexport function parseMentionableUsers(value: unknown): readonly MentionableUser[] {\n const nodes = record(record(record(record(value)?.data)?.repository)?.mentionableUsers)?.nodes\n if (!Array.isArray(nodes)) return []\n const users: MentionableUser[] = []\n for (const item of nodes) {\n const input = record(item)\n if (input === undefined || typeof input.login !== 'string' || input.login.length === 0) continue\n const avatarUrl = githubAvatarUrl(input.avatarUrl)\n users.push({ login: input.login, ...(avatarUrl === undefined ? {} : { avatarUrl }) })\n if (users.length >= MAX_MENTIONABLE_USERS) break\n }\n return users\n}\n\n/** Extract the Actions job id from a check run link, when it is one. */\nexport function actionsJobId(link: string | undefined): string | undefined {\n if (link === undefined) return undefined\n return /\\/actions\\/runs\\/\\d+\\/jobs?\\/(\\d+)/u.exec(link)?.[1]\n}\n\nexport function parseFailingChecks(value: unknown): readonly FailingCheck[] {\n if (!Array.isArray(value)) return []\n const failing: FailingCheck[] = []\n for (const item of value) {\n const input = record(item)\n if (input === undefined || input.bucket !== 'fail' || typeof input.name !== 'string') continue\n failing.push({\n name: input.name,\n ...(typeof input.link === 'string' && input.link.length > 0 ? { link: input.link } : {}),\n ...(typeof input.description === 'string' && input.description.length > 0 ? { description: input.description } : {}),\n })\n }\n return failing\n}\n\n/** Keep the informative end of a failed-job log within the size budget. */\nexport function boundedLogTail(value: string): string {\n const text = value.replaceAll('\\0', '').trimEnd()\n return text.length <= MAX_LOG_CHARS ? text : text.slice(text.length - MAX_LOG_CHARS)\n}\n\nexport class PullRequestFeedbackService {\n readonly #runtime: FeedbackRuntime\n #gitExecutable?: Promise<string>\n #ghExecutable?: Promise<string>\n\n constructor(runtime: FeedbackRuntime) {\n this.#runtime = runtime\n }\n\n async threads(cwd: string, pullNumber: number): Promise<readonly PullRequestReviewThread[]> {\n const { owner, name } = await this.#repositoryParts(cwd)\n const gh = await this.#gh()\n const result = await this.#run(gh, [\n 'api', 'graphql',\n '-f', `owner=${owner}`, '-f', `name=${name}`, '-F', `number=${pullNumber}`,\n '-f', `query=${REVIEW_THREADS_QUERY}`,\n ], cwd, GH_TIMEOUT_MS)\n if (result.exitCode !== 0) throw new PullRequestFeedbackError('comments-unavailable', 'Pull request comments could not be loaded.')\n try {\n return parseReviewThreads(JSON.parse(result.stdout))\n } catch {\n throw new PullRequestFeedbackError('comments-unavailable', 'Pull request comments could not be parsed.')\n }\n }\n\n /** Post a reply into the thread the given comment belongs to. GitHub parses\n * `@login` in the body server-side, so mentions need nothing from us. */\n async reply(cwd: string, pullNumber: number, commentId: number, body: string): Promise<PullRequestReviewComment> {\n const text = body.trim()\n if (text.length === 0 || text.length > MAX_REPLY_CHARS) {\n throw new PullRequestFeedbackError('invalid-request', 'The reply body is invalid.')\n }\n const repository = await this.#repository(cwd)\n const gh = await this.#gh()\n const result = await this.#run(\n gh,\n ['api', '-X', 'POST', `repos/${repository}/pulls/${pullNumber}/comments/${commentId}/replies`, '--input', '-'],\n cwd,\n GH_TIMEOUT_MS,\n JSON.stringify({ body: text }),\n )\n if (result.exitCode !== 0) throw new PullRequestFeedbackError('reply-failed', 'The reply could not be posted.')\n let posted: PullRequestReviewComment | undefined\n try {\n const parsed = JSON.parse(result.stdout) as unknown\n const path = typeof record(parsed)?.path === 'string' ? String(record(parsed)?.path) : ''\n const line = Number.isSafeInteger(record(parsed)?.line) ? Number(record(parsed)?.line) : undefined\n posted = parseReplyComment(parsed, {\n path,\n ...(line === undefined ? {} : { line }),\n side: record(parsed)?.side === 'LEFT' ? 'old' : 'new',\n })\n } catch {\n posted = undefined\n }\n if (posted === undefined) throw new PullRequestFeedbackError('reply-failed', 'The posted reply could not be read back.')\n return posted\n }\n\n /** Resolve or reopen a thread. Returns the state GitHub reports afterwards. */\n async setResolved(cwd: string, threadId: string, resolved: boolean): Promise<boolean> {\n const gh = await this.#gh()\n const result = await this.#run(gh, [\n 'api', 'graphql',\n '-f', `threadId=${threadId}`,\n '-f', `query=${resolved ? RESOLVE_MUTATION : UNRESOLVE_MUTATION}`,\n ], cwd, GH_TIMEOUT_MS)\n if (result.exitCode !== 0) throw new PullRequestFeedbackError('resolve-failed', 'The thread could not be updated.')\n try {\n const data = record(record(JSON.parse(result.stdout) as unknown)?.data)\n const thread = record(record(data?.[resolved ? 'resolveReviewThread' : 'unresolveReviewThread'])?.thread)\n if (typeof thread?.isResolved !== 'boolean') throw new Error('missing state')\n return thread.isResolved\n } catch {\n throw new PullRequestFeedbackError('resolve-failed', 'The thread state could not be read back.')\n }\n }\n\n /** Logins GitHub would notify from this repository, for the reply composer. */\n async mentionables(cwd: string, query: string): Promise<readonly MentionableUser[]> {\n const { owner, name } = await this.#repositoryParts(cwd)\n const gh = await this.#gh()\n const result = await this.#run(gh, [\n 'api', 'graphql',\n '-f', `owner=${owner}`, '-f', `name=${name}`, '-f', `q=${query}`,\n '-f', `query=${MENTIONABLE_USERS_QUERY}`,\n ], cwd, GH_TIMEOUT_MS)\n if (result.exitCode !== 0) return []\n try {\n return parseMentionableUsers(JSON.parse(result.stdout))\n } catch {\n return []\n }\n }\n\n /** `signal` bounds the log fetches below: each is capped on its own, but they\n * run one after another, so the honest worst case is their sum rather than\n * any single ceiling — more than a route is allowed to hold a connection. */\n async failingChecks(cwd: string, pullNumber: number, signal?: AbortSignal): Promise<readonly FailingCheck[]> {\n const gh = await this.#gh()\n const result = await this.#run(gh, [\n 'pr', 'checks', String(pullNumber), '--json', 'name,state,link,description,bucket',\n ], cwd, GH_TIMEOUT_MS)\n // gh pr checks exits non-zero when checks are failing; that IS our case.\n let checks: readonly FailingCheck[]\n try {\n checks = parseFailingChecks(JSON.parse(result.stdout))\n } catch {\n throw new PullRequestFeedbackError('checks-unavailable', 'Pull request checks could not be loaded.')\n }\n const detailed: FailingCheck[] = []\n for (const check of checks) {\n const jobId = detailed.length < MAX_FAILING_CHECKS ? actionsJobId(check.link) : undefined\n if (jobId === undefined) {\n detailed.push(check)\n continue\n }\n if (signal?.aborted === true) {\n detailed.push(check)\n continue\n }\n const log = await this.#run(gh, ['run', 'view', '--job', jobId, '--log-failed'], cwd, GH_TIMEOUT_MS)\n detailed.push(log.exitCode === 0 && log.stdout.trim().length > 0 ? { ...check, log: boundedLogTail(log.stdout) } : check)\n }\n return detailed\n }\n\n async #repository(cwd: string): Promise<string> {\n const git = await this.#git()\n const remote = await this.#run(git, ['remote', 'get-url', 'origin'], cwd, GIT_TIMEOUT_MS)\n const repository = remote.exitCode === 0 ? parseGitHubRemote(remote.stdout) : undefined\n if (repository === undefined) throw new PullRequestFeedbackError('no-github-remote', 'The repository has no GitHub origin remote.')\n return repository\n }\n\n /** GraphQL takes the owner and the name as separate variables, so they never\n * reach the query text itself. */\n async #repositoryParts(cwd: string): Promise<{ owner: string; name: string }> {\n const [owner, name] = (await this.#repository(cwd)).split('/')\n if (owner === undefined || name === undefined || owner.length === 0 || name.length === 0) {\n throw new PullRequestFeedbackError('no-github-remote', 'The repository has no GitHub origin remote.')\n }\n return { owner, name }\n }\n\n #git(): Promise<string> {\n this.#gitExecutable ??= this.#runtime.resolveExecutable('git')\n return this.#gitExecutable\n }\n\n #gh(): Promise<string> {\n this.#ghExecutable ??= this.#runtime.resolveExecutable('gh').catch(() => {\n throw new PullRequestFeedbackError('gh-unavailable', 'GitHub CLI is unavailable.')\n })\n return this.#ghExecutable\n }\n\n #run(executable: string, args: readonly string[], cwd: string, timeoutMs: number, input?: string): Promise<CommandResult> {\n const handle = this.#runtime.spawn({\n argv: [executable, ...args],\n cwd,\n stdio: {\n stdin: input === undefined ? 'ignore' : 'pipe',\n stdout: { maxBytes: MAX_OUTPUT_BYTES },\n stderr: { maxBytes: 64 * 1024 },\n },\n graceMs: 1_000,\n signal: AbortSignal.timeout(timeoutMs),\n env: {},\n })\n if (input !== undefined) handle.stdin?.end(input)\n return collect(handle)\n }\n}\n","import type { Context } from '@deepseek-ai/cordis'\nimport type {} from '@deepseek-ai/dsh-host-webserver'\nimport { CLAUDE_REPOSITORY_FEEDBACK_PATH } from './constants.ts'\nimport { registerPluginRoute, type PluginRouteIo } from './http.ts'\nimport { PullRequestFeedbackError, type PullRequestFeedbackService } from './pr-feedback.ts'\n\nconst MAX_SESSION_ID_CHARS = 1_024\nconst MAX_BODY_BYTES = 16 * 1024\nconst MAX_REPLY_CHARS = 2_000\nconst MAX_THREAD_ID_CHARS = 512\nconst MAX_MENTION_QUERY_CHARS = 64\n\nfunction record(value: unknown): Record<string, unknown> | undefined {\n return value !== null && typeof value === 'object' && !Array.isArray(value) ? value as Record<string, unknown> : undefined\n}\n\nasync function readJson(io: PluginRouteIo): Promise<Record<string, unknown>> {\n let parsed: unknown\n try {\n parsed = await io.body<unknown>(MAX_BODY_BYTES)\n } catch (error) {\n // Malformed JSON keeps its own 400; the cap is the only other refusal the\n // transport raises, and the panel already knows that code.\n if (error instanceof SyntaxError) throw error\n throw new PullRequestFeedbackError('body-too-large', 'The request body is too large.')\n }\n const value = record(parsed)\n if (value === undefined) throw new PullRequestFeedbackError('invalid-request', 'The request body is invalid.')\n return value\n}\n\nfunction replyBody(input: Record<string, unknown>): string {\n const body = typeof input.body === 'string' ? input.body.trim() : ''\n if (body.length === 0 || body.length > MAX_REPLY_CHARS || body.includes('\\0')) {\n throw new PullRequestFeedbackError('invalid-request', 'The reply body is invalid.')\n }\n return body\n}\n\nfunction commentId(input: Record<string, unknown>): number {\n const value = input.commentId\n if (typeof value !== 'number' || !Number.isSafeInteger(value) || value <= 0) {\n throw new PullRequestFeedbackError('invalid-request', 'The comment id is invalid.')\n }\n return value\n}\n\nfunction threadId(input: Record<string, unknown>): string {\n const value = input.threadId\n if (typeof value !== 'string' || value.length === 0 || value.length > MAX_THREAD_ID_CHARS) {\n throw new PullRequestFeedbackError('invalid-request', 'The thread id is invalid.')\n }\n return value\n}\n\nfunction sessionId(url: URL): string {\n const value = url.searchParams.get('sessionId')\n if (value === null || value.length === 0 || value.length > MAX_SESSION_ID_CHARS) {\n throw new PullRequestFeedbackError('invalid-session', 'The session is invalid.')\n }\n return value\n}\n\nfunction pullNumber(url: URL): number {\n const value = Number(url.searchParams.get('number'))\n if (!Number.isSafeInteger(value) || value <= 0 || value > 1_000_000_000) {\n throw new PullRequestFeedbackError('invalid-request', 'The pull request number is invalid.')\n }\n return value\n}\n\n/** Every arm shells out to `gh`, so the whole prefix carries the network budget. */\nexport function registerPullRequestFeedbackRoute(\n ctx: Context,\n service: PullRequestFeedbackService,\n cwdForSession: (sessionId: string) => string | undefined,\n): void {\n registerPluginRoute(ctx, {\n mode: 'unary',\n kind: 'prefix',\n path: CLAUDE_REPOSITORY_FEEDBACK_PATH,\n methods: ['GET', 'POST'],\n budget: 'remote',\n handler: async io => {\n const url = io.url\n const reads = io.method === 'GET'\n const writes = io.method === 'POST'\n try {\n const cwd = cwdForSession(sessionId(url))\n if (cwd === undefined) throw new PullRequestFeedbackError('session-unavailable', 'The Claude session is unavailable.')\n if (url.pathname === `${CLAUDE_REPOSITORY_FEEDBACK_PATH}/comments`) {\n if (!reads) return { status: 405, value: { error: 'method not allowed' } }\n return { status: 200, value: { threads: await service.threads(cwd, pullNumber(url)) } }\n }\n if (url.pathname === `${CLAUDE_REPOSITORY_FEEDBACK_PATH}/checks`) {\n if (!reads) return { status: 405, value: { error: 'method not allowed' } }\n return { status: 200, value: { checks: await service.failingChecks(cwd, pullNumber(url), io.signal) } }\n }\n if (url.pathname === `${CLAUDE_REPOSITORY_FEEDBACK_PATH}/mentionables`) {\n if (!reads) return { status: 405, value: { error: 'method not allowed' } }\n const query = (url.searchParams.get('q') ?? '').slice(0, MAX_MENTION_QUERY_CHARS)\n return { status: 200, value: { users: await service.mentionables(cwd, query) } }\n }\n if (url.pathname === `${CLAUDE_REPOSITORY_FEEDBACK_PATH}/reply`) {\n if (!writes) return { status: 405, value: { error: 'method not allowed' } }\n const input = await readJson(io)\n const comment = await service.reply(cwd, pullNumber(url), commentId(input), replyBody(input))\n return { status: 200, value: { comment } }\n }\n if (url.pathname === `${CLAUDE_REPOSITORY_FEEDBACK_PATH}/resolve`) {\n if (!writes) return { status: 405, value: { error: 'method not allowed' } }\n const input = await readJson(io)\n if (typeof input.resolved !== 'boolean') {\n throw new PullRequestFeedbackError('invalid-request', 'The resolved field is required.')\n }\n return { status: 200, value: { resolved: await service.setResolved(cwd, threadId(input), input.resolved) } }\n }\n return { status: 404, value: { error: 'not found' } }\n } catch (error) {\n if (error instanceof PullRequestFeedbackError) {\n return { status: 409, value: { error: error.code, message: error.message } }\n }\n if (error instanceof SyntaxError) return { status: 400, value: { error: 'invalid-json' } }\n return { status: 500, value: { error: 'pr-feedback-unavailable', message: 'Pull request feedback is unavailable.' } }\n }\n },\n })\n}\n","import { isAbsolute } from 'node:path'\nimport type { Context } from '@deepseek-ai/cordis'\nimport type {} from '@deepseek-ai/dsh-host-webserver'\nimport { CLAUDE_REPOSITORY_STATUS_PATH } from './constants.ts'\nimport { registerPluginRoute } from './http.ts'\nimport type { RepositoryStatusService } from './repository-status.ts'\n\nconst MAX_PATH_CHARS = 4_096\n\n/** Read-only repository status for an arbitrary directory (the overview panel\n * aggregates every Claude session's checkout through this).\n *\n * The route signal is threaded into the service because this is the one read\n * the overview polls per distinct checkout every 30 seconds: freeing the\n * socket at the budget while the Host kept scanning would just grow a queue\n * of work nobody is waiting for any more. */\nexport function registerRepositoryStatusRoute(ctx: Context, service: RepositoryStatusService): void {\n registerPluginRoute(ctx, {\n mode: 'unary',\n kind: 'exact',\n path: CLAUDE_REPOSITORY_STATUS_PATH,\n methods: ['GET'],\n budget: 'git',\n handler: async io => {\n const cwd = io.url.searchParams.get('cwd')\n if (cwd === null || cwd.length === 0 || cwd.length > MAX_PATH_CHARS || !isAbsolute(cwd) || cwd.includes('\\0')) {\n return { status: 400, value: { error: 'invalid-request', message: 'The cwd query parameter is invalid.' } }\n }\n try {\n return { status: 200, value: await service.inspect(cwd, io.signal) }\n } catch {\n return { status: 500, value: { error: 'repository-status-unavailable', message: 'Repository status is unavailable.' } }\n }\n },\n })\n}\n","import { isAbsolute } from 'node:path'\nimport type { Context } from '@deepseek-ai/cordis'\nimport type {} from '@deepseek-ai/dsh-host-webserver'\nimport { CLAUDE_REPOSITORY_FILE_PATH } from './constants.ts'\nimport { registerPluginRoute } from './http.ts'\nimport { RepositoryFileError, type RepositoryStatusService } from './repository-status.ts'\n\nconst MAX_PATH_CHARS = 4_096\n\n/** Read-only slice of a working-tree file so the diff panel can expand unmodified lines around hunks. */\nexport function registerRepositoryFileRoute(ctx: Context, service: Pick<RepositoryStatusService, 'fileLines'>): void {\n registerPluginRoute(ctx, {\n mode: 'unary',\n kind: 'exact',\n path: CLAUDE_REPOSITORY_FILE_PATH,\n methods: ['GET'],\n // One bounded read of a file already on disk.\n budget: 'git',\n handler: async io => {\n const params = io.url.searchParams\n const cwd = params.get('cwd')\n const path = params.get('path')\n const from = Number(params.get('from'))\n const to = Number(params.get('to'))\n if (cwd === null || cwd.length === 0 || cwd.length > MAX_PATH_CHARS || !isAbsolute(cwd) || cwd.includes('\\0')) {\n return { status: 400, value: { error: 'invalid-request', message: 'The cwd query parameter is invalid.' } }\n }\n if (path === null || path.length === 0 || path.length > MAX_PATH_CHARS) {\n return { status: 400, value: { error: 'invalid-request', message: 'The path query parameter is invalid.' } }\n }\n try {\n return { status: 200, value: await service.fileLines(cwd, path, from, to) }\n } catch (error) {\n if (error instanceof RepositoryFileError) {\n return { status: error.code === 'invalid-request' ? 400 : 409, value: { error: error.code, message: error.message } }\n }\n return { status: 500, value: { error: 'repository-file-unavailable', message: 'The file could not be read.' } }\n }\n },\n })\n}\n","import { randomUUID } from 'node:crypto'\nimport { chmod, mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises'\nimport { dirname } from 'node:path'\nimport { dshHomePath } from '@deepseek-ai/dsh-home-paths'\n\nconst REQUEST_TIMEOUT_MS = 15_000\nconst MAX_RESULTS = 20\nconst MAX_QUERY_CHARS = 200\nconst MAX_STORE_BYTES = 64 * 1024\n\nexport interface JiraConnectionInput {\n readonly siteUrl: string\n readonly email: string\n readonly apiToken: string\n}\n\ninterface JiraStore extends JiraConnectionInput {\n readonly displayName?: string\n readonly accountId?: string\n}\n\n/** Connection state exposed to the browser; never carries the token. */\nexport interface JiraStatus {\n readonly connected: boolean\n readonly siteUrl?: string\n readonly email?: string\n readonly displayName?: string\n}\n\nexport interface JiraTicket {\n readonly key: string\n readonly summary: string\n readonly url: string\n readonly status?: string\n readonly type?: string\n}\n\nexport interface JiraServiceOptions {\n readonly storePath?: string\n readonly fetch?: typeof fetch\n}\n\nexport class JiraError extends Error {\n readonly code: string\n\n constructor(code: string, message: string) {\n super(message)\n this.name = 'JiraError'\n this.code = code\n }\n}\n\nfunction record(value: unknown): Record<string, unknown> | undefined {\n return value !== null && typeof value === 'object' && !Array.isArray(value) ? value as Record<string, unknown> : undefined\n}\n\n/** Jira Cloud sites are origins; Data Center may carry a context path. */\nexport function normalizeSiteUrl(value: string): string {\n let url: URL\n try {\n url = new URL(value.trim())\n } catch {\n throw new JiraError('invalid-site', 'The Jira site URL is invalid.')\n }\n if (url.protocol !== 'https:') throw new JiraError('invalid-site', 'The Jira site URL must use https.')\n return `${url.origin}${url.pathname.replace(/\\/+$/u, '')}`\n}\n\nexport function ticketKeyOf(query: string): string | undefined {\n const match = /^([A-Za-z][A-Za-z0-9_]*)-(\\d+)$/u.exec(query.trim())\n return match === null ? undefined : `${match[1]!.toUpperCase()}-${match[2]!}`\n}\n\n/** Jira's text index carries summary, description and comments -- never the\n * issue key -- so a bare ticket number (\"5697\") can never reach PSOS-5697\n * through `text ~`. The issue picker is the endpoint behind Jira's own quick\n * search and does match keys; its hits become the key filter the normal\n * search then reads the display fields from. */\nexport function pickerKeys(value: unknown, number: string): readonly string[] {\n const sections = record(value)?.sections\n if (!Array.isArray(sections)) return []\n const keys: string[] = []\n for (const section of sections) {\n const issues = record(section)?.issues\n if (!Array.isArray(issues)) continue\n for (const issue of issues) {\n const raw = record(issue)?.key\n const key = ticketKeyOf(typeof raw === 'string' ? raw : '')\n if (key !== undefined && key.endsWith(`-${number}`) && !keys.includes(key)) keys.push(key)\n }\n }\n return keys\n}\n\n/** Keys arrive validated by `ticketKeyOf`, so they cannot break out of the quotes. */\nexport function keyJql(keys: readonly string[]): string {\n return `key in (${keys.map(key => `\"${key}\"`).join(', ')}) ORDER BY updated DESC`\n}\n\nexport function buildJql(query: string): string {\n const trimmed = query.trim().slice(0, MAX_QUERY_CHARS)\n if (trimmed.length === 0) return 'statusCategory != Done ORDER BY updated DESC'\n const key = ticketKeyOf(trimmed)\n if (key !== undefined) return `key = \"${key}\"`\n const escaped = trimmed.replaceAll('\\\\', '\\\\\\\\').replaceAll('\"', '\\\\\"')\n return `text ~ \"${escaped}*\" ORDER BY updated DESC`\n}\n\nexport function parseTickets(value: unknown, siteUrl: string): readonly JiraTicket[] {\n const issues = record(value)?.issues\n if (!Array.isArray(issues)) return []\n const tickets: JiraTicket[] = []\n for (const item of issues) {\n const issue = record(item)\n const fields = record(issue?.fields)\n if (issue === undefined || typeof issue.key !== 'string' || fields === undefined) continue\n const status = record(fields.status)?.name\n const type = record(fields.issuetype)?.name\n tickets.push({\n key: issue.key,\n summary: typeof fields.summary === 'string' ? fields.summary.slice(0, 256) : '',\n url: `${siteUrl}/browse/${issue.key}`,\n ...(typeof status === 'string' ? { status } : {}),\n ...(typeof type === 'string' ? { type } : {}),\n })\n if (tickets.length >= MAX_RESULTS) break\n }\n return tickets\n}\n\nfunction statusOf(store: JiraStore | undefined): JiraStatus {\n if (store === undefined) return { connected: false }\n return {\n connected: true,\n siteUrl: store.siteUrl,\n email: store.email,\n ...(store.displayName === undefined ? {} : { displayName: store.displayName }),\n }\n}\n\n/** Jira Cloud access through the user's API token (Basic auth). */\nexport class JiraService {\n readonly #storePath: string\n readonly #fetch: typeof fetch\n\n constructor(options: JiraServiceOptions = {}) {\n this.#storePath = options.storePath ?? dshHomePath('plugins', 'dsh-claude', 'jira.json')\n this.#fetch = options.fetch ?? globalThis.fetch\n }\n\n async status(): Promise<JiraStatus> {\n return statusOf(await this.#read())\n }\n\n async connect(input: JiraConnectionInput): Promise<JiraStatus> {\n const siteUrl = normalizeSiteUrl(input.siteUrl)\n const email = input.email.trim()\n const apiToken = input.apiToken.trim()\n if (email.length === 0 || email.length > 320 || apiToken.length === 0 || apiToken.length > 4_096) {\n throw new JiraError('invalid-credentials', 'An account email and API token are required.')\n }\n const connection = { siteUrl, email, apiToken }\n const myself = record(await this.#json(connection, '/rest/api/3/myself'))\n const displayName = typeof myself?.displayName === 'string' ? myself.displayName : undefined\n const accountId = typeof myself?.accountId === 'string' ? myself.accountId : undefined\n const store: JiraStore = {\n ...connection,\n ...(displayName === undefined ? {} : { displayName }),\n ...(accountId === undefined ? {} : { accountId }),\n }\n await this.#write(store)\n return statusOf(store)\n }\n\n /** Assign a ticket to the connected account (used once a ticket's worktree exists). */\n async assignToMe(key: string): Promise<void> {\n const store = await this.#read()\n if (store === undefined) throw new JiraError('not-connected', 'Connect Jira in Settings first.')\n const ticket = ticketKeyOf(key)\n if (ticket === undefined) throw new JiraError('invalid-request', 'The ticket key is invalid.')\n let accountId = store.accountId\n if (accountId === undefined) {\n const myself = record(await this.#json(store, '/rest/api/3/myself'))\n if (typeof myself?.accountId !== 'string') throw new JiraError('jira-failed', 'The Jira account id is unavailable.')\n accountId = myself.accountId\n await this.#write({ ...store, accountId })\n }\n await this.#json(store, `/rest/api/3/issue/${ticket}/assignee`, { method: 'PUT', body: { accountId } })\n }\n\n async disconnect(): Promise<void> {\n await rm(this.#storePath, { force: true })\n }\n\n async search(query: string): Promise<readonly JiraTicket[]> {\n const store = await this.#read()\n if (store === undefined) throw new JiraError('not-connected', 'Connect Jira in Settings first.')\n const params = new URLSearchParams({\n jql: await this.#searchJql(store, query.trim().slice(0, MAX_QUERY_CHARS)),\n maxResults: String(MAX_RESULTS),\n fields: 'summary,status,issuetype',\n })\n let body: unknown\n try {\n body = await this.#json(store, `/rest/api/3/search/jql?${params.toString()}`)\n } catch (error) {\n // Older deployments only serve the classic search endpoint.\n if (!(error instanceof JiraError && error.code === 'not-found')) throw error\n body = await this.#json(store, `/rest/api/3/search?${params.toString()}`)\n }\n return parseTickets(body, store.siteUrl)\n }\n\n /** A bare ticket number resolves through the picker; everything else is JQL.\n * A site that cannot serve the picker falls back to the text search rather\n * than failing the whole lookup. */\n async #searchJql(store: JiraStore, query: string): Promise<string> {\n if (!/^\\d+$/u.test(query)) return buildJql(query)\n const keys = await this.#json(store, `/rest/api/3/issue/picker?query=${encodeURIComponent(query)}`)\n .then(body => pickerKeys(body, query), () => [])\n return keys.length === 0 ? buildJql(query) : keyJql(keys)\n }\n\n async #json(connection: JiraConnectionInput, path: string, init: { method?: 'GET' | 'PUT'; body?: unknown } = {}): Promise<unknown> {\n let response: Response\n try {\n response = await this.#fetch(`${connection.siteUrl}${path}`, {\n method: init.method ?? 'GET',\n headers: {\n accept: 'application/json',\n authorization: `Basic ${Buffer.from(`${connection.email}:${connection.apiToken}`).toString('base64')}`,\n ...(init.body === undefined ? {} : { 'content-type': 'application/json' }),\n },\n ...(init.body === undefined ? {} : { body: JSON.stringify(init.body) }),\n signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),\n })\n } catch {\n throw new JiraError('unreachable', 'The Jira site could not be reached.')\n }\n if (response.status === 401 || response.status === 403) throw new JiraError('unauthorized', 'Jira rejected the credentials.')\n if (response.status === 404) throw new JiraError('not-found', 'The Jira endpoint was not found.')\n if (!response.ok) throw new JiraError('jira-failed', `Jira responded with HTTP ${response.status}.`)\n if (response.status === 204) return undefined\n try {\n return await response.json() as unknown\n } catch {\n throw new JiraError('jira-failed', 'Jira returned an invalid response.')\n }\n }\n\n async #read(): Promise<JiraStore | undefined> {\n let text: string\n try {\n text = await readFile(this.#storePath, 'utf8')\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') return undefined\n throw error\n }\n if (Buffer.byteLength(text) > MAX_STORE_BYTES) return undefined\n const input = record(JSON.parse(text))\n if (input === undefined || typeof input.siteUrl !== 'string' || typeof input.email !== 'string' || typeof input.apiToken !== 'string') return undefined\n return {\n siteUrl: input.siteUrl,\n email: input.email,\n apiToken: input.apiToken,\n ...(typeof input.displayName === 'string' ? { displayName: input.displayName } : {}),\n ...(typeof input.accountId === 'string' ? { accountId: input.accountId } : {}),\n }\n }\n\n async #write(store: JiraStore): Promise<void> {\n await mkdir(dirname(this.#storePath), { recursive: true, mode: 0o700 })\n const temporary = `${this.#storePath}.${process.pid}.${randomUUID()}.tmp`\n try {\n await writeFile(temporary, `${JSON.stringify(store, null, 2)}\\n`, { encoding: 'utf8', mode: 0o600, flag: 'wx' })\n await chmod(temporary, 0o600)\n await rename(temporary, this.#storePath)\n } finally {\n await rm(temporary, { force: true }).catch(() => undefined)\n }\n }\n}\n","import type { Context } from '@deepseek-ai/cordis'\nimport type {} from '@deepseek-ai/dsh-host-webserver'\nimport { CLAUDE_JIRA_PATH } from './constants.ts'\nimport { registerPluginRoute, type PluginRouteIo } from './http.ts'\nimport { JiraError, type JiraService } from './jira.ts'\n\nconst MAX_BODY_BYTES = 8 * 1024\n\nfunction record(value: unknown): Record<string, unknown> | undefined {\n return value !== null && typeof value === 'object' && !Array.isArray(value) ? value as Record<string, unknown> : undefined\n}\n\n/** The wrapper enforces the byte cap; its plain rejection is translated back\n * into the JiraError shape the panel already knows how to render. */\nasync function readJson(io: PluginRouteIo): Promise<Record<string, unknown>> {\n let body: unknown\n try {\n body = await io.body(MAX_BODY_BYTES)\n } catch (error) {\n if (error instanceof SyntaxError) throw error\n throw new JiraError('body-too-large', 'The request body is too large.')\n }\n const value = record(body)\n if (value === undefined) throw new JiraError('invalid-request', 'The request body is invalid.')\n return value\n}\n\nfunction string(input: Record<string, unknown>, key: string): string {\n const value = input[key]\n if (typeof value !== 'string') throw new JiraError('invalid-request', `The ${key} field is required.`)\n return value\n}\n\nexport function registerJiraRoute(ctx: Context, service: JiraService): void {\n registerPluginRoute(ctx, {\n mode: 'unary',\n kind: 'prefix',\n path: CLAUDE_JIRA_PATH,\n methods: ['GET', 'POST'],\n budget: 'git',\n handler: async io => {\n const url = io.url\n try {\n if (url.pathname === `${CLAUDE_JIRA_PATH}/status`) {\n if (io.method !== 'GET') return { status: 405, value: { error: 'method not allowed' } }\n return { status: 200, value: await service.status() }\n }\n if (url.pathname === `${CLAUDE_JIRA_PATH}/connect`) {\n if (io.method !== 'POST') return { status: 405, value: { error: 'method not allowed' } }\n const input = await readJson(io)\n return {\n status: 200,\n value: await service.connect({\n siteUrl: string(input, 'siteUrl'),\n email: string(input, 'email'),\n apiToken: string(input, 'apiToken'),\n }),\n }\n }\n if (url.pathname === `${CLAUDE_JIRA_PATH}/disconnect`) {\n if (io.method !== 'POST') return { status: 405, value: { error: 'method not allowed' } }\n await service.disconnect()\n return { status: 200, value: { connected: false } }\n }\n if (url.pathname === `${CLAUDE_JIRA_PATH}/assign`) {\n if (io.method !== 'POST') return { status: 405, value: { error: 'method not allowed' } }\n const input = await readJson(io)\n await service.assignToMe(string(input, 'key'))\n return { status: 200, value: { assigned: true } }\n }\n if (url.pathname === `${CLAUDE_JIRA_PATH}/search`) {\n if (io.method !== 'GET') return { status: 405, value: { error: 'method not allowed' } }\n return { status: 200, value: { tickets: await service.search(url.searchParams.get('query') ?? '') } }\n }\n return { status: 404, value: { error: 'not found' } }\n } catch (error) {\n if (error instanceof JiraError) return { status: 409, value: { error: error.code, message: error.message } }\n if (error instanceof SyntaxError) return { status: 400, value: { error: 'invalid-json' } }\n return { status: 500, value: { error: 'jira-unavailable', message: 'Jira is unavailable.' } }\n }\n },\n })\n}\n","import { StringDecoder } from 'node:string_decoder'\nimport type { SubprocessRuntime } from '@deepseek-ai/dsh-subprocess'\n\nconst MAX_SELECTION_CHARS = 8_000\nconst MAX_CONTEXT_CHARS = 16_000\nconst MAX_QUESTION_CHARS = 2_000\nconst ASK_TIMEOUT_MS = 180_000\nconst MAX_STDERR_BYTES = 64 * 1024\nconst MAX_TOOL_SUMMARY_CHARS = 160\nexport const READ_ONLY_TOOLS = ['Read', 'Grep', 'Glob'] as const\n\ntype AskRuntime = Pick<SubprocessRuntime, 'spawn'>\n\nexport interface AskRequest {\n readonly selection: string\n readonly context?: string\n readonly question: string\n}\n\n/** Model and effort the session last ran with; mirrored onto the side query. */\nexport interface AskPreferences {\n readonly model?: string\n readonly thinkingMode?: string\n}\n\nexport class AskError extends Error {\n readonly code: string\n\n constructor(code: string, message: string) {\n super(message)\n this.name = 'AskError'\n this.code = code\n }\n}\n\nfunction fence(value: string): string {\n return `\"\"\"\\n${value.replaceAll('\"\"\"', '\" \" \"')}\\n\"\"\"`\n}\n\nexport function askPrompt(request: AskRequest): string {\n const selection = request.selection.trim().slice(0, MAX_SELECTION_CHARS)\n const context = (request.context ?? '').trim().slice(0, MAX_CONTEXT_CHARS)\n const question = request.question.trim().slice(0, MAX_QUESTION_CHARS)\n return [\n 'You are answering a follow-up question about part of an earlier assistant reply in this project.',\n '',\n 'Selected passage:',\n fence(selection),\n ...(context.length === 0 || context === selection ? [] : ['', 'Surrounding reply, for context only:', fence(context)]),\n '',\n `Question: ${question}`,\n '',\n 'Answer the question directly and concisely, in the same language as the question. Use Markdown.',\n 'Only the read-only tools Read, Grep, and Glob are available; use them when the answer depends on project code, otherwise answer from the passage.',\n ].join('\\n')\n}\n\n/** CLI effort for a session thinking mode; `off` and unknown modes send nothing. */\nexport function effortFor(thinkingMode: string | undefined): string | undefined {\n if (thinkingMode === undefined || thinkingMode === 'off') return undefined\n if (thinkingMode === 'ultracode') return 'max'\n return ['low', 'medium', 'high', 'max'].includes(thinkingMode) ? thinkingMode : undefined\n}\n\nexport function askArguments(preferences: AskPreferences): readonly string[] {\n const effort = effortFor(preferences.thinkingMode)\n return [\n '-p', '--output-format', 'stream-json', '--verbose', '--include-partial-messages',\n // No MCP servers: a follow-up question never needs them and connecting\n // them roughly doubles cold start.\n '--strict-mcp-config', '--mcp-config', '{\"mcpServers\":{}}',\n ...(preferences.model === undefined || preferences.model === 'default' ? [] : ['--model', preferences.model]),\n ...(effort === undefined ? [] : ['--effort', effort]),\n // Read-only inspection only; both flags are variadic, so they stay last\n // and the prompt travels over stdin.\n '--tools', ...READ_ONLY_TOOLS, '--allowedTools', ...READ_ONLY_TOOLS,\n ]\n}\n\nfunction record(value: unknown): Record<string, unknown> | undefined {\n return value !== null && typeof value === 'object' && !Array.isArray(value) ? value as Record<string, unknown> : undefined\n}\n\n/** What one stream-json line contributes: streamed answer text, streamed\n * thinking, or the final result (used only when no text streamed). */\nexport type AskToolPhase = 'start' | 'input' | 'done'\n\nexport type AskStreamEvent =\n | { readonly type: 'text'; readonly text: string }\n | { readonly type: 'thinking'; readonly text: string }\n | { readonly type: 'status'; readonly text: string }\n | { readonly type: 'tool'; readonly id: string; readonly phase: AskToolPhase; readonly name?: string; readonly summary?: string; readonly error?: boolean }\n | { readonly type: 'result'; readonly text: string }\n\n/** One-line description of a tool call, mirroring the main window's step titles. */\nexport function toolSummary(input: unknown): string | undefined {\n const fields = record(input)\n if (fields === undefined) return undefined\n const candidate = [fields.command, fields.pattern, fields.file_path, fields.path, fields.query].find(value => typeof value === 'string' && value.length > 0)\n const text = typeof candidate === 'string' ? candidate : JSON.stringify(fields)\n return text.replaceAll(/\\s+/gu, ' ').trim().slice(0, MAX_TOOL_SUMMARY_CHARS)\n}\n\nexport function eventsOfStreamLine(line: string): readonly AskStreamEvent[] {\n let parsed: Record<string, unknown> | undefined\n try {\n parsed = record(JSON.parse(line))\n } catch {\n return []\n }\n if (parsed === undefined) return []\n if (parsed.type === 'system' && parsed.subtype === 'init') return [{ type: 'status', text: 'ready' }]\n if (parsed.type === 'stream_event') {\n const event = record(parsed.event)\n if (event?.type === 'content_block_start') {\n const block = record(event.content_block)\n if (block?.type === 'tool_use' && typeof block.id === 'string' && typeof block.name === 'string') {\n return [{ type: 'tool', id: block.id, phase: 'start', name: block.name }]\n }\n return []\n }\n const delta = record(event?.delta)\n if (event?.type !== 'content_block_delta' || delta === undefined) return []\n if (delta.type === 'text_delta' && typeof delta.text === 'string') return [{ type: 'text', text: delta.text }]\n if (delta.type === 'thinking_delta' && typeof delta.thinking === 'string') return [{ type: 'thinking', text: delta.thinking }]\n return []\n }\n if (parsed.type === 'assistant' || parsed.type === 'user') {\n const content = record(parsed.message)?.content\n if (!Array.isArray(content)) return []\n const events: AskStreamEvent[] = []\n for (const item of content) {\n const block = record(item)\n if (block?.type === 'tool_use' && typeof block.id === 'string' && typeof block.name === 'string') {\n const summary = toolSummary(block.input)\n events.push({ type: 'tool', id: block.id, phase: 'input', name: block.name, ...(summary === undefined ? {} : { summary }) })\n } else if (block?.type === 'tool_result' && typeof block.tool_use_id === 'string') {\n events.push({ type: 'tool', id: block.tool_use_id, phase: 'done', ...(block.is_error === true ? { error: true } : {}) })\n }\n }\n return events\n }\n if (parsed.type === 'result' && typeof parsed.result === 'string') return [{ type: 'result', text: parsed.result }]\n return []\n}\n\nexport type AskProgressEvent = Exclude<AskStreamEvent, { type: 'result' }>\n\n/** One-shot Claude Code query answering a question about selected reply text. */\nexport class AskService {\n readonly #runtime: AskRuntime\n readonly #executablePath: string\n\n constructor(runtime: AskRuntime, executablePath: string) {\n this.#runtime = runtime\n this.#executablePath = executablePath\n }\n\n async ask(cwd: string, request: AskRequest, preferences: AskPreferences, onEvent: (event: AskProgressEvent) => void, signal?: AbortSignal): Promise<void> {\n if (request.question.trim().length === 0 || request.selection.trim().length === 0) {\n throw new AskError('invalid-request', 'A selection and a question are required.')\n }\n if (this.#executablePath.length === 0) throw new AskError('claude-unavailable', 'Claude Code is unavailable.')\n const timeout = AbortSignal.timeout(ASK_TIMEOUT_MS)\n // The prompt rides stdin: `--tools ''` is variadic and would swallow a\n // trailing positional prompt argument.\n const handle = this.#runtime.spawn({\n argv: [this.#executablePath, ...askArguments(preferences)],\n cwd,\n stdio: { stdin: { data: askPrompt(request) }, stdout: 'pipe', stderr: { maxBytes: MAX_STDERR_BYTES } },\n graceMs: 1_000,\n signal: signal === undefined ? timeout : AbortSignal.any([signal, timeout]),\n env: {},\n })\n const stdout = handle.stdout\n if (stdout === undefined) throw new AskError('ask-failed', 'Claude output is unavailable.')\n const decoder = new StringDecoder('utf8')\n let buffer = ''\n let emitted = false\n let result: string | undefined\n const consume = (line: string): void => {\n for (const event of eventsOfStreamLine(line)) {\n if (event.type === 'result') {\n result = event.text\n continue\n }\n if (event.type !== 'tool' && event.text.length === 0) continue\n if (event.type === 'text') emitted = true\n onEvent(event)\n }\n }\n for await (const chunk of stdout) {\n buffer += typeof chunk === 'string' ? chunk : decoder.write(chunk as Buffer)\n const lines = buffer.split('\\n')\n buffer = lines.pop() ?? ''\n for (const line of lines) if (line.trim().length > 0) consume(line)\n }\n buffer += decoder.end()\n if (buffer.trim().length > 0) consume(buffer)\n const outcome = await handle.done\n if (!emitted && result !== undefined && result.length > 0) {\n emitted = true\n onEvent({ type: 'text', text: result })\n }\n if (!emitted) {\n if (signal?.aborted === true) throw new AskError('aborted', 'The question was cancelled.')\n if (timeout.aborted) throw new AskError('timeout', 'Claude took too long to answer.')\n const stderr = handle.collected.stderr?.readFrom(0).text.trim().split(/\\r?\\n/u).filter(line => line.length > 0).at(-1)\n throw new AskError('ask-failed', stderr !== undefined && stderr.length > 0 ? stderr : `Claude exited with code ${String(outcome.exitCode)}.`)\n }\n }\n}\n","import type { ServerResponse } from 'node:http'\nimport type { Context } from '@deepseek-ai/cordis'\nimport type {} from '@deepseek-ai/dsh-host-webserver'\nimport { AskError, type AskPreferences, type AskRequest, type AskService } from './ask.ts'\nimport { CLAUDE_ASK_PATH } from './constants.ts'\nimport { json, registerPluginRoute } from './http.ts'\n\nconst MAX_BODY_BYTES = 128 * 1024\nconst MAX_SESSION_ID_CHARS = 1_024\n/** Two sessions may await an answer at once; a third evicts the oldest. */\nconst MAX_CONCURRENT_ASKS = 2\n\nfunction record(value: unknown): Record<string, unknown> | undefined {\n return value !== null && typeof value === 'object' && !Array.isArray(value) ? value as Record<string, unknown> : undefined\n}\n\nfunction askRequest(input: Record<string, unknown>): AskRequest {\n if (typeof input.selection !== 'string' || typeof input.question !== 'string' || (input.context !== undefined && typeof input.context !== 'string')) {\n throw new AskError('invalid-request', 'The selection and question fields are required.')\n }\n return { selection: input.selection, question: input.question, ...(typeof input.context === 'string' ? { context: input.context } : {}) }\n}\n\nfunction ndjson(res: ServerResponse, value: unknown): void {\n res.write(`${JSON.stringify(value)}\\n`)\n}\n\n/** A stream route rather than a unary one: the answer is written as it arrives,\n * so the deadline stays where the work is — `ASK_TIMEOUT_MS` inside the\n * service, fused there with the disconnect signal — instead of a route budget\n * that would cut a legitimate long answer off mid-sentence. */\nexport function registerAskRoute(\n ctx: Context,\n service: AskService,\n cwdForSession: (sessionId: string) => string | undefined,\n preferencesFor: (sessionId: string) => AskPreferences | undefined,\n): void {\n registerPluginRoute(ctx, {\n mode: 'stream',\n kind: 'exact',\n path: CLAUDE_ASK_PATH,\n methods: ['POST'],\n maxConcurrent: MAX_CONCURRENT_ASKS,\n streamKey: url => url.searchParams.get('sessionId') ?? '',\n handler: async (res, io) => {\n let cwd: string\n let request: AskRequest\n let sessionId: string\n try {\n const value = io.url.searchParams.get('sessionId')\n if (value === null || value.length === 0 || value.length > MAX_SESSION_ID_CHARS) throw new AskError('invalid-session', 'The session is invalid.')\n sessionId = value\n const resolved = cwdForSession(sessionId)\n if (resolved === undefined) throw new AskError('session-unavailable', 'The Claude session is unavailable.')\n cwd = resolved\n const body = record(await io.body(MAX_BODY_BYTES))\n if (body === undefined) throw new AskError('invalid-request', 'The request body is invalid.')\n request = askRequest(body)\n } catch (error) {\n if (error instanceof AskError) return json(res, 409, { error: error.code, message: error.message })\n if (error instanceof SyntaxError) return json(res, 400, { error: 'invalid-json' })\n return json(res, 500, { error: 'ask-unavailable', message: 'The question could not be sent.' })\n }\n res.writeHead(200, {\n 'content-type': 'application/x-ndjson; charset=utf-8',\n 'cache-control': 'no-store',\n 'x-content-type-options': 'nosniff',\n })\n res.flushHeaders?.()\n try {\n await service.ask(cwd, request, preferencesFor(sessionId) ?? {}, event => { ndjson(res, event.type === 'text' ? { type: 'delta', text: event.text } : event) }, io.signal)\n ndjson(res, { type: 'done' })\n } catch (error) {\n ndjson(res, {\n type: 'error',\n code: error instanceof AskError ? error.code : 'ask-unavailable',\n message: error instanceof AskError ? error.message : 'The question could not be answered.',\n })\n }\n },\n })\n}\n","import type { Context } from '@deepseek-ai/cordis'\nimport type {} from '@deepseek-ai/dsh-host-webserver'\nimport { CLAUDE_REVIEW_COMMENT_PATH } from './constants.ts'\nimport { registerPluginRoute, type PluginRouteIo } from './http.ts'\nimport { ReviewCommentError, type ReviewCommentStore } from './review-comments.ts'\n\nconst MAX_BODY_BYTES = 16 * 1024\nconst MAX_SESSION_ID_CHARS = 1_024\n\nfunction record(value: unknown): Record<string, unknown> | undefined {\n return value !== null && typeof value === 'object' && !Array.isArray(value) ? value as Record<string, unknown> : undefined\n}\n\nasync function readJson(io: PluginRouteIo): Promise<Record<string, unknown>> {\n let parsed: unknown\n try {\n parsed = await io.body<unknown>(MAX_BODY_BYTES)\n } catch (error) {\n if (error instanceof SyntaxError) throw error\n throw new ReviewCommentError('body-too-large', 'The request body is too large.')\n }\n const value = record(parsed)\n if (value === undefined) throw new ReviewCommentError('invalid-request', 'The request body is invalid.')\n return value\n}\n\nfunction sessionIdFromUrl(url: URL): string {\n const value = url.searchParams.get('sessionId')\n if (value === null || value.length === 0 || value.length > MAX_SESSION_ID_CHARS) {\n throw new ReviewCommentError('invalid-session', 'The session is invalid.')\n }\n return value\n}\n\nexport function registerReviewCommentRoute(\n ctx: Context,\n store: ReviewCommentStore,\n ownsSession: (sessionId: string) => boolean,\n): void {\n registerPluginRoute(ctx, {\n mode: 'unary',\n kind: 'prefix',\n path: CLAUDE_REVIEW_COMMENT_PATH,\n methods: ['POST'],\n // The comment store is in memory; only reading the body can wait.\n budget: 'fast',\n handler: async io => {\n try {\n const sessionId = sessionIdFromUrl(io.url)\n if (!ownsSession(sessionId)) throw new ReviewCommentError('session-unavailable', 'The Claude session is unavailable.')\n const pathname = io.url.pathname\n if (pathname === CLAUDE_REVIEW_COMMENT_PATH) {\n const input = await readJson(io)\n const comment = store.add(sessionId, {\n path: input.path,\n line: input.line,\n startLine: input.startLine,\n side: input.side,\n text: input.text,\n })\n return { status: 200, value: { comment } }\n }\n if (pathname === `${CLAUDE_REVIEW_COMMENT_PATH}/clear`) {\n return { status: 200, value: { removed: store.drain(sessionId).length } }\n }\n if (pathname === `${CLAUDE_REVIEW_COMMENT_PATH}/remove`) {\n const input = await readJson(io)\n if (typeof input.id !== 'string' || input.id.length === 0 || input.id.length > 128) {\n throw new ReviewCommentError('invalid-request', 'The comment id is invalid.')\n }\n return { status: 200, value: { removed: store.remove(sessionId, input.id) } }\n }\n return { status: 404, value: { error: 'not found' } }\n } catch (error) {\n if (error instanceof ReviewCommentError) return { status: 409, value: { error: error.code, message: error.message } }\n if (error instanceof SyntaxError) return { status: 400, value: { error: 'invalid-json' } }\n return { status: 500, value: { error: 'review-comment-unavailable', message: 'Review comments are unavailable.' } }\n }\n },\n })\n}\n","import type { Context } from '@deepseek-ai/cordis'\nimport type {} from '@deepseek-ai/dsh-host-webserver'\nimport { CLAUDE_CLIENT_DIAGNOSTICS_PATH } from './constants.ts'\nimport { redactText } from './events.ts'\nimport { registerPluginRoute } from './http.ts'\n\n/** Enough for a message plus a trimmed stack; the client caps its own volume. */\nconst MAX_DIAGNOSTIC_BYTES = 8 * 1024\nconst MAX_DETAIL_CHARS = 2_000\nconst MAX_KIND_CHARS = 60\n\n/** `POST <path>` with `{ kind, detail }`: write one renderer finding to the Host log.\n *\n * The renderer has no other way to speak. A Slot entry that throws is caught\n * by the Host's Slot system and dropped, the shipped Desktop opens no\n * DevTools, and startup still reports `rendererStatus: \"healthy\"` — so a\n * plugin whose UI died silently is indistinguishable from a working one.\n * Every finding here is data written by this package's own client half, but\n * it is still bounded and redacted like any other untrusted input. */\nexport function registerClaudeClientDiagnosticsRoute(ctx: Context): void {\n registerPluginRoute(ctx, {\n mode: 'unary',\n kind: 'exact',\n path: CLAUDE_CLIENT_DIAGNOSTICS_PATH,\n methods: ['POST'],\n budget: 'fast',\n handler: async io => {\n try {\n const body = await io.body<{ kind?: unknown; detail?: unknown } | null>(MAX_DIAGNOSTIC_BYTES)\n const kind = typeof body?.kind === 'string' ? body.kind.slice(0, MAX_KIND_CHARS) : 'unknown'\n const detail = typeof body?.detail === 'string' ? body.detail : ''\n if (detail === '') return { status: 400, value: { error: 'invalid-request' } }\n ctx.logger.warn(`dsh-claude client [${kind}]: ${redactText(detail, MAX_DETAIL_CHARS)}`)\n return { status: 200, value: { ok: true } }\n } catch (error) {\n if (error instanceof SyntaxError) return { status: 400, value: { error: 'invalid-json' } }\n return { status: 400, value: { error: 'invalid-request' } }\n }\n },\n })\n}\n","import type { Context } from '@deepseek-ai/cordis'\nimport type { SessionEvent } from '@deepseek-ai/dsh-session'\nimport type {} from '@deepseek-ai/dsh-host-webserver'\nimport { CLAUDE_REWIND_PATH } from './constants.ts'\nimport { registerPluginRoute, type PluginRouteIo } from './http.ts'\nimport { EMPTY_REWIND_STATE, planRewind } from './rewind.ts'\nimport type { ClaudeSidecarRepository } from './sidecar.ts'\n\nconst MAX_BODY_BYTES = 4 * 1024\nconst MAX_SESSION_ID_CHARS = 1_024\n\nexport interface ClaudeRewindSessionAccess {\n /** The session log of one plugin-owned session, or undefined for any other. */\n eventsFor: (sessionId: string) => readonly SessionEvent[] | undefined\n /** Whether a turn is in flight; rewinding one would cut it mid-run. */\n busy: (sessionId: string) => boolean\n /** Drop the live Claude process so the next turn resumes at the fork target. */\n reset: (sessionId: string) => Promise<void>\n}\n\nfunction record(value: unknown): Record<string, unknown> | undefined {\n return value !== null && typeof value === 'object' && !Array.isArray(value) ? value as Record<string, unknown> : undefined\n}\n\n/** An oversized body fails the same field checks as a missing one; only\n * malformed JSON is worth reporting separately. */\nasync function readJson(io: PluginRouteIo): Promise<Record<string, unknown> | undefined> {\n try {\n return record(await io.body<unknown>(MAX_BODY_BYTES))\n } catch (error) {\n if (error instanceof SyntaxError) throw error\n return undefined\n }\n}\n\n/** `POST <path>` with `{ sessionId, seq }`: hide that surface event and every\n * later one, and arm Claude to resume before the turn it opened. */\nexport function registerClaudeRewindRoute(\n ctx: Context,\n sidecar: ClaudeSidecarRepository,\n access: ClaudeRewindSessionAccess,\n): void {\n registerPluginRoute(ctx, {\n mode: 'unary',\n kind: 'exact',\n path: CLAUDE_REWIND_PATH,\n methods: ['POST'],\n // The session log is already in memory; the sidecar write is local.\n budget: 'git',\n handler: async io => {\n try {\n const input = await readJson(io)\n const sessionId = input?.sessionId\n const seq = input?.seq\n if (typeof sessionId !== 'string' || sessionId.length === 0 || sessionId.length > MAX_SESSION_ID_CHARS\n || typeof seq !== 'number' || !Number.isSafeInteger(seq) || seq < 0) {\n return { status: 400, value: { error: 'invalid-request' } }\n }\n const events = access.eventsFor(sessionId)\n if (events === undefined) return { status: 409, value: { error: 'session-unavailable' } }\n if (access.busy(sessionId)) return { status: 409, value: { error: 'session-busy' } }\n const current = (await sidecar.read(sessionId)).rewind ?? EMPTY_REWIND_STATE\n const planned = planRewind(current, events, seq)\n if (planned === undefined) return { status: 409, value: { error: 'seq-unavailable' } }\n await sidecar.writeRewind(sessionId, planned)\n await access.reset(sessionId)\n return { status: 200, value: { ranges: planned.ranges } }\n } catch (error) {\n if (error instanceof SyntaxError) return { status: 400, value: { error: 'invalid-json' } }\n return { status: 500, value: { error: 'rewind-unavailable' } }\n }\n },\n })\n}\n","import type { Context } from '@deepseek-ai/cordis'\nimport type {} from '@deepseek-ai/dsh-host-webserver'\nimport type { SubprocessRuntime } from '@deepseek-ai/dsh-subprocess'\nimport { resolveDshHome } from '@deepseek-ai/dsh-home-paths'\nimport { opendir, readFile, realpath } from 'node:fs/promises'\nimport { dirname, join, resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport { CLAUDE_UPDATE_CHECK_PATH, CLAUDE_UPDATE_PATH } from './constants.ts'\nimport { redactText } from './events.ts'\nimport { registerPluginRoute, type PluginMethod } from './http.ts'\n\nexport const PLUGIN_PACKAGE_NAME = '@norman-else/dsh-claude'\nconst MAX_MANIFEST_BYTES = 256 * 1024\nconst MAX_UPDATE_OUTPUT_BYTES = 32 * 1024\nconst SEMVER = /^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-([0-9A-Za-z.-]+))?(?:\\+[0-9A-Za-z.-]+)?$/\nconst PROFILE_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/\n\nexport type InstallSource = 'registry' | 'link' | 'unsupported' | 'unknown'\nexport type UpdateState = 'current' | 'available' | 'linked' | 'unsupported' | 'unavailable' | 'error'\n\nexport interface PluginUpdateStatus {\n currentVersion: string\n latestVersion?: string\n source: InstallSource\n state: UpdateState\n canUpdate: boolean\n restartRequired: boolean\n message?: string\n}\n\ninterface PackageManifest {\n name?: unknown\n version?: unknown\n dependencies?: unknown\n}\n\nexport interface Installation {\n profile: string\n profileDir: string\n source: InstallSource\n spec: string\n}\n\nexport interface UpdateDependencies {\n packageDir?: string\n dshHome?: string\n fetchLatest?: (signal: AbortSignal) => Promise<string>\n resolveExecutable?: (name: string, env?: Readonly<Record<string, string>>, signal?: AbortSignal) => Promise<string>\n spawn?: SubprocessRuntime['spawn']\n requestRestart?: () => void\n}\n\n/** The route owns the deadline now. A direct caller with nothing to cancel\n * against gets a signal that never fires, rather than a second timeout\n * competing with the budget the route already declared. */\nconst NEVER_ABORTS = new AbortController().signal\n\nfunction safeMessage(error: unknown): string {\n return redactText(error instanceof Error ? error.message : String(error), 500)\n}\n\nasync function readManifest(path: string): Promise<PackageManifest> {\n const text = await readFile(path, 'utf8')\n if (Buffer.byteLength(text) > MAX_MANIFEST_BYTES) throw new Error('package manifest is too large')\n const value = JSON.parse(text) as unknown\n if (typeof value !== 'object' || value === null || Array.isArray(value)) throw new Error('package manifest is invalid')\n return value as PackageManifest\n}\n\nfunction dependencySpec(manifest: PackageManifest): string | undefined {\n if (typeof manifest.dependencies !== 'object' || manifest.dependencies === null || Array.isArray(manifest.dependencies)) return undefined\n const value = (manifest.dependencies as Record<string, unknown>)[PLUGIN_PACKAGE_NAME]\n return typeof value === 'string' && value.length <= 2_000 ? value : undefined\n}\n\nexport function classifyInstallSpec(spec: string): InstallSource {\n if (/^(?:link|file|workspace):/i.test(spec)) return 'link'\n if (/^(?:git(?:\\+[^:]+)?:|github:|https?:|npm:)/i.test(spec) || /\\.git(?:#|$)/i.test(spec)) return 'unsupported'\n return /^(?:\\^|~|>=?|<=?|=)?\\s*v?\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?(?:\\s*\\|\\|\\s*(?:\\^|~|>=?|<=?|=)?\\s*v?\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?)*$/.test(spec.trim())\n ? 'registry'\n : 'unsupported'\n}\n\nasync function samePath(left: string, right: string): Promise<boolean> {\n try {\n const [a, b] = await Promise.all([realpath(left), realpath(right)])\n return process.platform === 'win32' ? a.toLowerCase() === b.toLowerCase() : a === b\n } catch {\n return false\n }\n}\n\nfunction linkedTarget(profileDir: string, spec: string): string | undefined {\n const match = /^(?:link|file):(.*)$/i.exec(spec)\n return match?.[1] === undefined ? undefined : resolve(profileDir, match[1])\n}\n\nexport async function discoverInstallation(dshHome: string, packageDir: string): Promise<Installation | undefined> {\n const profilesDir = join(dshHome, 'profiles')\n const matches: Installation[] = []\n let profiles\n try {\n profiles = await opendir(profilesDir)\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') return undefined\n throw error\n }\n for await (const entry of profiles) {\n if (!entry.isDirectory() || !PROFILE_NAME.test(entry.name)) continue\n const profileDir = join(profilesDir, entry.name)\n let manifest: PackageManifest\n try {\n manifest = await readManifest(join(profileDir, 'package.json'))\n } catch {\n continue\n }\n const spec = dependencySpec(manifest)\n if (spec === undefined) continue\n const source = classifyInstallSpec(spec)\n const matchesPackage = source === 'link'\n ? linkedTarget(profileDir, spec) !== undefined && await samePath(linkedTarget(profileDir, spec)!, packageDir)\n : await samePath(join(profileDir, 'node_modules', ...PLUGIN_PACKAGE_NAME.split('/')), packageDir)\n if (matchesPackage) matches.push({ profile: entry.name, profileDir, source, spec })\n }\n return matches.length === 1 ? matches[0] : undefined\n}\n\nfunction parseVersion(version: string): RegExpExecArray {\n const match = SEMVER.exec(version)\n if (match === null) throw new Error('package version is not valid semver')\n return match\n}\n\nexport function compareVersions(left: string, right: string): number {\n const a = parseVersion(left)\n const b = parseVersion(right)\n for (const index of [1, 2, 3]) {\n const difference = Number(a[index]) - Number(b[index])\n if (difference !== 0) return Math.sign(difference)\n }\n const aPre = a[4]\n const bPre = b[4]\n if (aPre === undefined) return bPre === undefined ? 0 : 1\n if (bPre === undefined) return -1\n return aPre.localeCompare(bPre, 'en', { numeric: true })\n}\n\nasync function registryLatest(signal: AbortSignal): Promise<string> {\n const response = await fetch('https://registry.npmjs.org/%40norman-else%2Fdsh-claude', {\n headers: { accept: 'application/vnd.npm.install-v1+json' },\n signal,\n })\n if (!response.ok) throw new Error(`npm registry returned HTTP ${response.status}`)\n const payload = await response.json() as { 'dist-tags'?: { latest?: unknown } }\n const latest = payload['dist-tags']?.latest\n if (typeof latest !== 'string') throw new Error('npm registry response has no latest version')\n parseVersion(latest)\n return latest\n}\n\nasync function resolvePackageContextDir(configured?: string): Promise<{ packageDir: string; manifest: PackageManifest }> {\n const moduleDir = dirname(fileURLToPath(import.meta.url))\n const candidates = configured === undefined ? [moduleDir, dirname(moduleDir)] : [configured]\n for (const packageDir of candidates) {\n try {\n const manifest = await readManifest(join(packageDir, 'package.json'))\n if (manifest.name === PLUGIN_PACKAGE_NAME) return { packageDir, manifest }\n } catch {\n // Continue until the owning package manifest is found.\n }\n }\n throw new Error('plugin package manifest is invalid')\n}\n\nasync function packageContext(deps: UpdateDependencies): Promise<{ version: string; installation?: Installation }> {\n const { packageDir, manifest } = await resolvePackageContextDir(deps.packageDir)\n if (typeof manifest.version !== 'string') throw new Error('plugin package manifest is invalid')\n parseVersion(manifest.version)\n const home = deps.dshHome ?? resolveDshHome()\n const installation = await discoverInstallation(home, packageDir)\n return { version: manifest.version, ...(installation === undefined ? {} : { installation }) }\n}\n\nexport async function checkPluginUpdate(deps: UpdateDependencies = {}, signal: AbortSignal = NEVER_ABORTS): Promise<PluginUpdateStatus> {\n try {\n const { version, installation } = await packageContext(deps)\n if (installation === undefined) return { currentVersion: version, source: 'unknown', state: 'unavailable', canUpdate: false, restartRequired: false, message: 'Active DSH profile could not be identified uniquely' }\n if (installation.source === 'link') return { currentVersion: version, source: 'link', state: 'linked', canUpdate: false, restartRequired: false, message: 'Local development link; updates come from the linked checkout' }\n if (installation.source !== 'registry') return { currentVersion: version, source: installation.source, state: 'unsupported', canUpdate: false, restartRequired: false, message: 'This installation source cannot be updated from the npm registry' }\n const latest = await (deps.fetchLatest ?? registryLatest)(signal)\n const comparison = compareVersions(version, latest)\n return {\n currentVersion: version,\n latestVersion: latest,\n source: 'registry',\n state: comparison < 0 ? 'available' : 'current',\n canUpdate: comparison < 0,\n restartRequired: comparison < 0,\n }\n } catch (error) {\n return { currentVersion: 'unknown', source: 'unknown', state: 'error', canUpdate: false, restartRequired: false, message: safeMessage(error) }\n }\n}\n\nasync function verifyInstalledVersion(installation: Installation, expectedVersion: string): Promise<void> {\n const profileManifest = await readManifest(join(installation.profileDir, 'package.json'))\n if (dependencySpec(profileManifest) !== expectedVersion) {\n throw new Error('DSH plugin update completed without updating the profile dependency')\n }\n const installedManifest = await readManifest(join(\n installation.profileDir,\n 'node_modules',\n ...PLUGIN_PACKAGE_NAME.split('/'),\n 'package.json',\n ))\n if (installedManifest.name !== PLUGIN_PACKAGE_NAME || installedManifest.version !== expectedVersion) {\n throw new Error('DSH plugin update completed without installing the requested version')\n }\n}\n\nexport async function updatePlugin(deps: UpdateDependencies = {}, signal: AbortSignal = NEVER_ABORTS): Promise<PluginUpdateStatus> {\n const { version, installation } = await packageContext(deps)\n if (installation === undefined || installation.source !== 'registry') throw new Error('Plugin update is unavailable for this installation')\n const latest = await (deps.fetchLatest ?? registryLatest)(signal)\n if (compareVersions(version, latest) >= 0) return { currentVersion: version, latestVersion: latest, source: 'registry', state: 'current', canUpdate: false, restartRequired: false }\n const resolveExecutable = deps.resolveExecutable\n const spawn = deps.spawn\n if (resolveExecutable === undefined || spawn === undefined) throw new Error('DSH update runtime is unavailable')\n const executable = await resolveExecutable('dsh', {}, signal)\n const handle = spawn({\n argv: [executable, 'plugin', '--profile', installation.profile, 'add', `${PLUGIN_PACKAGE_NAME}@${latest}`],\n cwd: installation.profileDir,\n env: {},\n stdio: { stdin: 'ignore', stdout: { maxBytes: MAX_UPDATE_OUTPUT_BYTES }, stderr: { maxBytes: MAX_UPDATE_OUTPUT_BYTES } },\n graceMs: 2_000,\n signal,\n })\n const outcome = await handle.done\n if (outcome.exitCode !== 0) {\n const detail = handle.collected.stderr?.readFrom(0).text ?? ''\n throw new Error(`DSH plugin update failed (${outcome.exitCode ?? outcome.signal ?? 'unknown exit'}): ${safeMessage(detail)}`)\n }\n await verifyInstalledVersion(installation, latest)\n if (deps.requestRestart !== undefined) setTimeout(() => deps.requestRestart?.(), 100).unref?.()\n return {\n currentVersion: latest,\n latestVersion: latest,\n source: 'registry',\n state: 'current',\n canUpdate: false,\n restartRequired: deps.requestRestart === undefined,\n message: deps.requestRestart === undefined\n ? 'Update installed; restart DSH Desktop to load it'\n : 'Update installed; DSH Desktop is restarting to load it',\n }\n}\n\nexport function registerClaudeUpdateRoutes(ctx: Context, runtime: Pick<SubprocessRuntime, 'resolveExecutable' | 'spawn'>, deps: UpdateDependencies = {}): void {\n const shared: UpdateDependencies = { ...deps, resolveExecutable: runtime.resolveExecutable.bind(runtime), spawn: runtime.spawn.bind(runtime) }\n const routes: readonly { path: string; method: PluginMethod; run: (signal: AbortSignal) => Promise<PluginUpdateStatus> }[] = [\n { path: CLAUDE_UPDATE_CHECK_PATH, method: 'GET', run: signal => checkPluginUpdate(shared, signal) },\n { path: CLAUDE_UPDATE_PATH, method: 'POST', run: signal => updatePlugin(shared, signal) },\n ]\n for (const route of routes) {\n registerPluginRoute(ctx, {\n mode: 'unary',\n kind: 'exact',\n path: route.path,\n methods: [route.method],\n // The npm registry, then `dsh plugin add`, then a manifest re-read.\n budget: 'remote',\n handler: async io => {\n try {\n return { status: 200, value: await route.run(io.signal) }\n } catch (error) {\n return { status: 500, value: { error: safeMessage(error) } }\n }\n },\n })\n }\n}\n","import type { Context } from '@deepseek-ai/cordis'\nimport type {} from '@deepseek-ai/dsh-host-webserver'\nimport { CLAUDE_USAGE_PATH } from './constants.ts'\nimport { redactText } from './events.ts'\nimport { registerPluginRoute } from './http.ts'\nimport { latestPlanUsage, recordPlanUsage, type PlanUsageReport } from './plan-usage.ts'\n\nconst EMPTY: PlanUsageReport = { available: false, windows: [], fetchedAt: 0 }\n\nfunction safeMessage(error: unknown): string {\n return redactText(error instanceof Error ? error.message : String(error), 1_000)\n}\n\n/** Plan usage: GET serves the value the metadata bridge last cached (free —\n * it rides an already-running session), POST reads fresh numbers from a\n * throwaway probe process so a refresh never depends on, or disturbs, a live\n * Claude session. */\nexport function registerPlanUsageRoute(\n ctx: Context,\n probe: (fetchedAt: number) => Promise<PlanUsageReport>,\n now: () => number = Date.now,\n): void {\n registerPluginRoute(ctx, {\n mode: 'unary',\n kind: 'exact',\n path: CLAUDE_USAGE_PATH,\n methods: ['GET', 'POST'],\n // The probe spawns a throwaway CLI; the cached GET answers from memory.\n budget: 'git',\n handler: async io => {\n if (io.method === 'GET') return { status: 200, value: latestPlanUsage() ?? EMPTY }\n try {\n const report = await probe(now())\n recordPlanUsage(report)\n return { status: 200, value: report }\n } catch (error) {\n return { status: 500, value: { error: safeMessage(error) } }\n }\n },\n })\n}\n","import { randomUUID } from 'node:crypto'\nimport { homedir } from 'node:os'\nimport { chmod, mkdir, opendir, readFile, rename, rm, writeFile } from 'node:fs/promises'\nimport { dirname, extname, join } from 'node:path'\nimport type { Context } from '@deepseek-ai/cordis'\nimport type {} from '@deepseek-ai/dsh-host-webserver'\nimport { dshHomePath } from '@deepseek-ai/dsh-home-paths'\nimport {\n CLAUDE_GLOBAL_SETTINGS_PATH,\n CLAUDE_RENDER_MODES,\n CLAUDE_PROSE_MODES,\n DEFAULT_CLAUDE_PROSE_MODE,\n DEFAULT_CLAUDE_RENDER_MODE,\n isClaudeProseMode,\n isClaudeRenderMode,\n type ClaudeRenderMode,\n} from './constants.ts'\nimport { registerPluginRoute, type PluginRouteIo } from './http.ts'\n\nconst MAX_SETTINGS_BYTES = 256 * 1024\nconst MAX_REQUEST_BYTES = 8 * 1024\nconst MAX_STYLE_BYTES = 64 * 1024\nconst MAX_STYLE_FILES = 256\nconst BUILTIN_OUTPUT_STYLES = ['Default', 'Proactive', 'Concise', 'Explanatory', 'Learning'] as const\nconst STYLE_NAME = /^[\\p{L}\\p{N}][\\p{L}\\p{N} ._()\\[\\]-]{0,127}$/u\nconst DEFAULT_WORKTREE_BRANCH_PREFIX = 'claude'\nconst MAX_BRANCH_PREFIX_CHARS = 128\nconst MAX_PROCESSES_LIMIT = 16\nconst MAX_IDLE_TIMEOUT_MINUTES = 24 * 60\nconst DEFAULT_LIMITS: SupervisorLimits = { maxProcesses: 4, idleTimeoutMs: 30 * 60_000 }\n\ntype JsonObject = Record<string, unknown>\nexport type GlobalSettingEffect = 'immediate' | 'new-session' | 'next-turn' | 'next-worktree' | 'restart'\n\nexport interface GlobalSettingOption {\n value: string\n label: string\n source: 'built-in' | 'user' | 'configured'\n}\n\nexport type GlobalSettingView = {\n key: string\n kind: 'select'\n value: string\n options: readonly GlobalSettingOption[]\n effect: GlobalSettingEffect\n} | {\n key: string\n kind: 'text'\n value: string\n maxLength: number\n effect: GlobalSettingEffect\n}\n\nexport interface GlobalSettingsView {\n settings: readonly GlobalSettingView[]\n}\n\ninterface GlobalSettingsPaths {\n settingsFile: string\n outputStylesDir: string\n pluginSettingsFile: string\n}\n\n/** Effective supervisor limits: the plugin config values unless overridden in Settings. */\nexport interface SupervisorLimits {\n maxProcesses: number\n idleTimeoutMs: number\n}\n\nexport interface GlobalSettingsDependencies {\n paths?: Partial<GlobalSettingsPaths>\n /** Limits from the plugin config, shown when Settings holds no override. */\n defaultLimits?: SupervisorLimits\n /** Invoked after a successful update so live runtime state can follow. */\n onUpdated?: () => void | Promise<void>\n}\n\ninterface SelectSettingDescriptor {\n key: string\n kind: 'select'\n document: 'claude' | 'plugin'\n effect: GlobalSettingEffect\n options(paths: GlobalSettingsPaths): Promise<readonly GlobalSettingOption[]>\n read(document: JsonObject, options: readonly GlobalSettingOption[]): string\n apply(document: JsonObject, value: unknown, options: readonly GlobalSettingOption[]): void\n}\n\ninterface TextSettingDescriptor {\n key: string\n kind: 'text'\n document: 'claude' | 'plugin'\n effect: GlobalSettingEffect\n maxLength: number\n read(document: JsonObject, defaults?: SupervisorLimits): string\n apply(document: JsonObject, value: unknown): void\n}\n\ntype SettingDescriptor = SelectSettingDescriptor | TextSettingDescriptor\n\nfunction pathsFor(deps: GlobalSettingsDependencies): GlobalSettingsPaths {\n const root = join(homedir(), '.claude')\n return {\n settingsFile: deps.paths?.settingsFile ?? join(root, 'settings.json'),\n outputStylesDir: deps.paths?.outputStylesDir ?? join(root, 'output-styles'),\n pluginSettingsFile: deps.paths?.pluginSettingsFile ?? dshHomePath('plugins', 'dsh-claude', 'settings.json'),\n }\n}\n\nfunction object(value: unknown): JsonObject | undefined {\n return value !== null && typeof value === 'object' && !Array.isArray(value)\n ? value as JsonObject\n : undefined\n}\n\nasync function readDocument(path: string): Promise<JsonObject> {\n try {\n const text = await readFile(path, 'utf8')\n if (Buffer.byteLength(text) > MAX_SETTINGS_BYTES) throw new Error('Claude Code settings file is too large')\n const parsed = object(JSON.parse(text))\n if (parsed === undefined) throw new Error('Claude Code settings file must contain a JSON object')\n return parsed\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') return {}\n throw error\n }\n}\n\nfunction frontmatterName(text: string): string | undefined {\n if (!text.startsWith('---\\n') && !text.startsWith('---\\r\\n')) return undefined\n const normalized = text.replaceAll('\\r\\n', '\\n')\n const end = normalized.indexOf('\\n---\\n', 4)\n if (end < 0) return undefined\n for (const line of normalized.slice(4, end).split('\\n')) {\n const match = /^name:\\s*(.+?)\\s*$/.exec(line)\n if (match?.[1] === undefined) continue\n const raw = match[1]\n const value = (raw.startsWith('\"') && raw.endsWith('\"')) || (raw.startsWith(\"'\") && raw.endsWith(\"'\"))\n ? raw.slice(1, -1)\n : raw\n return STYLE_NAME.test(value) ? value : undefined\n }\n return undefined\n}\n\nasync function userOutputStyleOptions(directory: string): Promise<GlobalSettingOption[]> {\n const options: GlobalSettingOption[] = []\n let entries\n try {\n entries = await opendir(directory)\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') return options\n throw error\n }\n for await (const entry of entries) {\n if (options.length >= MAX_STYLE_FILES) break\n if (!entry.isFile() || extname(entry.name).toLowerCase() !== '.md') continue\n try {\n const text = await readFile(join(directory, entry.name), 'utf8')\n if (Buffer.byteLength(text) > MAX_STYLE_BYTES) continue\n const name = frontmatterName(text) ?? entry.name.slice(0, -3)\n if (STYLE_NAME.test(name)) options.push({ value: name, label: name, source: 'user' })\n } catch {\n // Ignore unreadable or malformed optional style files.\n }\n }\n return options\n}\n\nconst OUTPUT_STYLE: SettingDescriptor = {\n key: 'outputStyle',\n kind: 'select',\n document: 'claude',\n effect: 'new-session',\n async options(paths) {\n const builtIn = BUILTIN_OUTPUT_STYLES.map(value => ({ value, label: value, source: 'built-in' as const }))\n const user = await userOutputStyleOptions(paths.outputStylesDir)\n const seen = new Set<string>(builtIn.map(option => option.value))\n return [...builtIn, ...user.filter(option => !seen.has(option.value)).sort((a, b) => a.label.localeCompare(b.label))]\n },\n read(document, options) {\n const value = document.outputStyle\n return typeof value === 'string' && STYLE_NAME.test(value) ? value : 'Default'\n },\n apply(document, value, options) {\n if (typeof value !== 'string' || !options.some(option => option.value === value)) {\n throw new Error('Invalid value for global setting outputStyle')\n }\n if (value === 'Default') delete document.outputStyle\n else document.outputStyle = value\n },\n}\n\nexport function isValidWorktreeBranchPrefix(value: string): boolean {\n return value.length > 0\n && value.length <= MAX_BRANCH_PREFIX_CHARS\n && value.trim() === value\n && !value.startsWith('/')\n && !value.endsWith('/')\n && !value.includes('//')\n && !value.includes('..')\n && !value.includes('@{')\n && !/[\\0-\\x20\\x7f~^:?*[\\\\]/u.test(value)\n && value.split('/').every(segment => segment.length > 0 && !segment.startsWith('.') && !segment.endsWith('.lock'))\n}\n\nconst WORKTREE_BRANCH_PREFIX: TextSettingDescriptor = {\n key: 'worktreeBranchPrefix',\n kind: 'text',\n document: 'plugin',\n effect: 'next-worktree',\n maxLength: MAX_BRANCH_PREFIX_CHARS,\n read(document) {\n const value = document.worktreeBranchPrefix\n return typeof value === 'string' && isValidWorktreeBranchPrefix(value) ? value : DEFAULT_WORKTREE_BRANCH_PREFIX\n },\n apply(document, value) {\n if (typeof value !== 'string' || !isValidWorktreeBranchPrefix(value)) {\n throw new Error('Invalid value for global setting worktreeBranchPrefix')\n }\n if (value === DEFAULT_WORKTREE_BRANCH_PREFIX) delete document.worktreeBranchPrefix\n else document.worktreeBranchPrefix = value\n },\n}\n\n/** Which renderer draws Claude's visible output. Plugin settings, not Claude's:\n * the CLI has no opinion about how DSH paints a turn. The option labels stay\n * machine-readable ids; the Client translates the two known values. */\nconst RENDERER: SelectSettingDescriptor = {\n key: 'renderer',\n kind: 'select',\n document: 'plugin',\n // The Host reads this per message and stamps every record it writes with the\n // renderer that produced it, so the switch lands on the next turn and a turn\n // already recorded keeps the renderer it was recorded with.\n effect: 'next-turn',\n async options() {\n return CLAUDE_RENDER_MODES.map(value => ({ value, label: value, source: 'built-in' as const }))\n },\n read(document) {\n const value = document.renderer\n return isClaudeRenderMode(value) ? value : DEFAULT_CLAUDE_RENDER_MODE\n },\n apply(document, value) {\n if (!isClaudeRenderMode(value)) throw new Error('Invalid value for global setting renderer')\n if (value === DEFAULT_CLAUDE_RENDER_MODE) delete document.renderer\n else document.renderer = value\n },\n}\n\n/** Whether Claude's prose gets the highlight palette. Presentation only: no\n * record carries it and nothing on the server reads it back, so unlike\n * {@link RENDERER} the switch lands the moment the Client rewrites its own\n * stylesheet — hence 'immediate' rather than 'next-turn'. */\nconst PROSE: SelectSettingDescriptor = {\n key: 'prose',\n kind: 'select',\n document: 'plugin',\n effect: 'immediate',\n async options() {\n return CLAUDE_PROSE_MODES.map(value => ({ value, label: value, source: 'built-in' as const }))\n },\n read(document) {\n const value = document.prose\n return isClaudeProseMode(value) ? value : DEFAULT_CLAUDE_PROSE_MODE\n },\n apply(document, value) {\n if (!isClaudeProseMode(value)) throw new Error('Invalid value for global setting prose')\n if (value === DEFAULT_CLAUDE_PROSE_MODE) delete document.prose\n else document.prose = value\n },\n}\n\nfunction isBoundedInteger(value: unknown, min: number, max: number): value is number {\n return typeof value === 'number' && Number.isInteger(value) && value >= min && value <= max\n}\n\nfunction integerSetting(\n key: 'maxProcesses' | 'idleTimeoutMinutes',\n min: number,\n max: number,\n defaultFor: (limits: SupervisorLimits) => number,\n): TextSettingDescriptor {\n return {\n key,\n kind: 'text',\n document: 'plugin',\n effect: 'new-session',\n maxLength: String(max).length,\n read(document, defaults = DEFAULT_LIMITS) {\n const value = document[key]\n return String(isBoundedInteger(value, min, max) ? value : defaultFor(defaults))\n },\n apply(document, value) {\n const parsed = typeof value === 'string' && /^\\d{1,6}$/u.test(value.trim()) ? Number(value.trim()) : value\n if (!isBoundedInteger(parsed, min, max)) throw new Error(`Invalid value for global setting ${key}`)\n document[key] = parsed\n },\n }\n}\n\nconst MAX_PROCESSES = integerSetting('maxProcesses', 1, MAX_PROCESSES_LIMIT, limits => limits.maxProcesses)\nconst IDLE_TIMEOUT_MINUTES = integerSetting('idleTimeoutMinutes', 1, MAX_IDLE_TIMEOUT_MINUTES, limits => Math.max(1, Math.round(limits.idleTimeoutMs / 60_000)))\n\nconst DESCRIPTORS: readonly SettingDescriptor[] = [OUTPUT_STYLE, RENDERER, PROSE, WORKTREE_BRANCH_PREFIX, MAX_PROCESSES, IDLE_TIMEOUT_MINUTES]\nconst DESCRIPTOR_BY_KEY = new Map(DESCRIPTORS.map(descriptor => [descriptor.key, descriptor]))\nlet pendingWrite: Promise<unknown> = Promise.resolve()\n\nfunction documentFor(descriptor: SettingDescriptor, documents: { claude: JsonObject; plugin: JsonObject }): JsonObject {\n return documents[descriptor.document]\n}\n\nasync function views(documents: { claude: JsonObject; plugin: JsonObject }, paths: GlobalSettingsPaths, defaults: SupervisorLimits): Promise<GlobalSettingsView> {\n return {\n settings: await Promise.all(DESCRIPTORS.map(async descriptor => {\n const document = documentFor(descriptor, documents)\n if (descriptor.kind === 'text') {\n return {\n key: descriptor.key,\n kind: descriptor.kind,\n value: descriptor.read(document, defaults),\n maxLength: descriptor.maxLength,\n effect: descriptor.effect,\n }\n }\n const discovered = await descriptor.options(paths)\n const value = descriptor.read(document, discovered)\n const options = discovered.some(option => option.value === value)\n ? discovered\n : [...discovered, { value, label: value, source: 'configured' as const }]\n return {\n key: descriptor.key,\n kind: descriptor.kind,\n value,\n options,\n effect: descriptor.effect,\n }\n })),\n }\n}\n\nasync function readDocuments(paths: GlobalSettingsPaths): Promise<{ claude: JsonObject; plugin: JsonObject }> {\n const [claude, plugin] = await Promise.all([readDocument(paths.settingsFile), readDocument(paths.pluginSettingsFile)])\n return { claude, plugin }\n}\n\nexport async function readGlobalSettings(deps: GlobalSettingsDependencies = {}): Promise<GlobalSettingsView> {\n const paths = pathsFor(deps)\n return views(await readDocuments(paths), paths, deps.defaultLimits ?? DEFAULT_LIMITS)\n}\n\n/** Supervisor limits the user overrode in Settings; absent keys fall back to the plugin config. */\nexport async function readSupervisorLimitOverrides(deps: GlobalSettingsDependencies = {}): Promise<Partial<SupervisorLimits>> {\n let document: JsonObject\n try {\n document = await readDocument(pathsFor(deps).pluginSettingsFile)\n } catch {\n return {}\n }\n const maxProcesses = document.maxProcesses\n const idleTimeoutMinutes = document.idleTimeoutMinutes\n return {\n ...(isBoundedInteger(maxProcesses, 1, MAX_PROCESSES_LIMIT) ? { maxProcesses } : {}),\n ...(isBoundedInteger(idleTimeoutMinutes, 1, MAX_IDLE_TIMEOUT_MINUTES) ? { idleTimeoutMs: idleTimeoutMinutes * 60_000 } : {}),\n }\n}\n\n/** The renderer the Host should produce output for. A missing, unreadable, or\n * malformed plugin settings file keeps today's plugin-owned transcript. */\nexport async function readRenderMode(deps: GlobalSettingsDependencies = {}): Promise<ClaudeRenderMode> {\n let document: JsonObject\n try {\n document = await readDocument(pathsFor(deps).pluginSettingsFile)\n } catch {\n return DEFAULT_CLAUDE_RENDER_MODE\n }\n return isClaudeRenderMode(document.renderer) ? document.renderer : DEFAULT_CLAUDE_RENDER_MODE\n}\n\nexport async function readWorktreeBranchPrefix(deps: GlobalSettingsDependencies = {}): Promise<string> {\n const paths = pathsFor(deps)\n return WORKTREE_BRANCH_PREFIX.read(await readDocument(paths.pluginSettingsFile))\n}\n\nasync function atomicWrite(path: string, document: JsonObject): Promise<void> {\n await mkdir(dirname(path), { recursive: true, mode: 0o700 })\n const temporary = `${path}.${process.pid}.${randomUUID()}.tmp`\n try {\n await writeFile(temporary, `${JSON.stringify(document, null, 2)}\\n`, { encoding: 'utf8', mode: 0o600, flag: 'wx' })\n await chmod(temporary, 0o600)\n await rename(temporary, path)\n await chmod(path, 0o600)\n } finally {\n await rm(temporary, { force: true }).catch(() => undefined)\n }\n}\n\nexport function updateGlobalSettings(changes: unknown, deps: GlobalSettingsDependencies = {}): Promise<GlobalSettingsView> {\n const changeObject = object(changes)\n if (changeObject === undefined || Object.keys(changeObject).length === 0) {\n return Promise.reject(new Error('Global settings changes must be a non-empty object'))\n }\n for (const key of Object.keys(changeObject)) {\n if (!DESCRIPTOR_BY_KEY.has(key)) return Promise.reject(new Error(`Unsupported global setting: ${key}`))\n }\n const paths = pathsFor(deps)\n const operation = pendingWrite.catch(() => undefined).then(async () => {\n const documents = await readDocuments(paths)\n const changedDocuments = new Set<'claude' | 'plugin'>()\n for (const [key, value] of Object.entries(changeObject)) {\n const descriptor = DESCRIPTOR_BY_KEY.get(key)!\n const document = documentFor(descriptor, documents)\n if (descriptor.kind === 'select') descriptor.apply(document, value, await descriptor.options(paths))\n else descriptor.apply(document, value)\n changedDocuments.add(descriptor.document)\n }\n if (changedDocuments.has('claude')) await atomicWrite(paths.settingsFile, documents.claude)\n if (changedDocuments.has('plugin')) await atomicWrite(paths.pluginSettingsFile, documents.plugin)\n return views(documents, paths, deps.defaultLimits ?? DEFAULT_LIMITS)\n })\n pendingWrite = operation\n return operation\n}\n\nasync function requestJson(io: PluginRouteIo): Promise<unknown> {\n const body = object(await io.body(MAX_REQUEST_BYTES))\n if (body === undefined || Object.keys(body).some(key => key !== 'changes')) throw new Error('Invalid global settings request')\n return body.changes\n}\n\nexport function registerClaudeGlobalSettingsRoute(ctx: Context, deps: GlobalSettingsDependencies = {}): void {\n registerPluginRoute(ctx, {\n mode: 'unary',\n kind: 'exact',\n path: CLAUDE_GLOBAL_SETTINGS_PATH,\n methods: ['GET', 'PATCH'],\n // Reads and writes two small JSON files under the home directory.\n budget: 'fast',\n handler: async io => {\n try {\n const result = io.method === 'GET'\n ? await readGlobalSettings(deps)\n : await updateGlobalSettings(await requestJson(io), deps)\n if (io.method === 'PATCH') await deps.onUpdated?.()\n return { status: 200, value: result }\n } catch (error) {\n return { status: 400, value: { error: error instanceof Error ? error.message : 'Invalid global settings request' } }\n }\n },\n })\n}\n","import type { Context } from '@deepseek-ai/cordis'\nimport type {} from '@deepseek-ai/dsh-attachment'\nimport z from '@deepseek-ai/schemastery'\nimport type { Agent } from '@deepseek-ai/dsh-agent'\nimport type {} from '@deepseek-ai/dsh-commands'\nimport type {} from '@deepseek-ai/dsh-agent-presets'\nimport type {} from '@deepseek-ai/dsh-host-webserver'\nimport type {} from '@deepseek-ai/dsh-subprocess'\nimport type {} from '@deepseek-ai/dsh-user-approval'\nimport type {} from '@deepseek-ai/dsh-user-questions'\nimport { CLAUDE_CODE_PRESET_ID, CLAUDE_CODE_PROVIDER_IDS, DEFAULT_CLAUDE_RENDER_MODE } from './constants.ts'\nimport { CLAUDE_COMMANDS_SERVICE, projectClaudeCommands, type ClaudeAgentCommandService, type ClaudeCommandView } from './command-bridge.ts'\nimport { ClaudeSidecarRepository } from './sidecar.ts'\nimport { resolveClaudeExecutable } from './executable.ts'\nimport { ClaudeSupervisor } from './supervisor.ts'\nimport { createClaudeCodeAdapter } from './adapter.ts'\nimport { ensureManagedPreset, ManagedPresetConflictError } from './preset-installer.ts'\nimport { claudeBridgeDiagnostics, registerClaudeDoctorRoutes, type ClaudeBridgeDiagnostic } from './doctor-routes.ts'\nimport { registerClaudeProjectionRoute } from './projection-routes.ts'\nimport { RepositoryStatusService } from './repository-status.ts'\nimport { comparablePath, RepositorySetupService } from './repository-setup.ts'\nimport { summarizeBranchSlug } from './branch-name.ts'\nimport { RepositoryActionService } from './repository-actions.ts'\nimport { registerRepositorySetupRoute } from './repository-setup-routes.ts'\nimport { registerRepositoryActionRoute } from './repository-action-routes.ts'\nimport { registerEditorOpenRoute } from './editor-open-routes.ts'\nimport { EditorOpenService } from './editor-open.ts'\nimport { PullRequestFeedbackService } from './pr-feedback.ts'\nimport { registerPullRequestFeedbackRoute } from './pr-feedback-routes.ts'\nimport { registerRepositoryStatusRoute } from './repository-status-routes.ts'\nimport { registerRepositoryFileRoute } from './repository-file-routes.ts'\nimport { JiraService } from './jira.ts'\nimport { registerJiraRoute } from './jira-routes.ts'\nimport { AskService } from './ask.ts'\nimport { registerAskRoute } from './ask-routes.ts'\nimport { registerReviewCommentRoute } from './review-comment-routes.ts'\nimport { registerClaudeClientDiagnosticsRoute } from './client-diagnostics-routes.ts'\nimport { registerClaudeRewindRoute } from './rewind-routes.ts'\nimport { ReviewCommentStore } from './review-comments.ts'\nimport { registerClaudeUpdateRoutes } from './update-routes.ts'\nimport { normalizePlanUsage, probePlanUsage, recordPlanUsage } from './plan-usage.ts'\nimport { registerPlanUsageRoute } from './plan-usage-routes.ts'\nimport { readRenderMode, readSupervisorLimitOverrides, readWorktreeBranchPrefix, registerClaudeGlobalSettingsRoute } from './global-settings.ts'\n\nexport const name = 'llm-claude'\nexport const inject = ['llm', 'agents', 'agentPresets', 'commands', 'subprocess', 'approval', 'userQuestions', 'attachments']\n\nexport interface Config {\n executablePath?: string\n model?: string\n idleTimeoutMs?: number\n maxProcesses?: number\n}\n\nexport const Config: z<Config> = z.object({\n executablePath: z.string().default(''),\n model: z.string().default('default'),\n idleTimeoutMs: z.number().min(1_000).max(2_147_483_647).default(30 * 60 * 1_000),\n maxProcesses: z.number().step(1).min(1).default(4),\n})\n\nconst CLAUDE_SCOPE_UNAVAILABLE_MESSAGE = 'agent command scope unavailable (preset route not mounted?)'\nconst CATALOG_RETRY_MS = 5_000\nconst SCOPE_RETRY_MS = 500\nconst MAX_CATALOG_RETRIES = 3\nconst MAX_SCOPE_RETRIES = 24\n\nexport function mountClaudeMetadata(\n ctx: Context,\n supervisor: ClaudeSupervisor,\n agent: Agent,\n model: string,\n sidecar: ClaudeSidecarRepository,\n publishCommands: (commands: readonly ClaudeCommandView[]) => void = () => {},\n // IMPORTANT: call through the injected agentPresets SERVICE, never an\n // imported serviceForAgent() — a linked plugin resolves peer packages from\n // its own node_modules, which creates a second module instance with empty\n // module-level mount state. The service method runs on the app's instance.\n resolveCommands: () => ClaudeAgentCommandService | undefined =\n () => ctx.agentPresets.serviceFor(agent, CLAUDE_COMMANDS_SERVICE),\n): (() => Promise<void>) | undefined {\n if (ctx.agentPresets.composedPreset(agent.ctx) !== CLAUDE_CODE_PRESET_ID) return undefined\n\n let stopped = false\n let pending = Promise.resolve()\n let commandScope: ClaudeAgentCommandService | undefined\n\n // The commands service is unreachable from this host view of agent.ctx;\n // the preset route plugin provides it as an isolated per-session service.\n const scopedCommands = () => {\n const scoped = commandScope ?? resolveCommands()\n if (scoped === undefined) throw new Error(CLAUDE_SCOPE_UNAVAILABLE_MESSAGE)\n commandScope = scoped\n return scoped\n }\n\n const commandTarget = {\n list: () => scopedCommands().list(agent),\n }\n\n const warn = (area: string, error: unknown) => {\n ctx.logger.warn(`dsh-claude: ${area} refresh failed for ${String(agent.id)}: ${error instanceof Error ? error.message : String(error)}`)\n }\n\n const isScopeUnavailable = (error: unknown): boolean => {\n if (error instanceof Error) return error.message === CLAUDE_SCOPE_UNAVAILABLE_MESSAGE\n return String(error) === CLAUDE_SCOPE_UNAVAILABLE_MESSAGE\n }\n\n const diagnostic: ClaudeBridgeDiagnostic = claudeBridgeDiagnostics.get(agent) ?? { attempts: 0 }\n claudeBridgeDiagnostics.set(agent, diagnostic)\n\n // A fresh session's first catalog fetch races CLI startup (skills/plugins\n // can make init slow); retry with backoff so the command palette still\n // populates without waiting for the first completed turn.\n let catalogRetries = 0\n let scopeRetries = 0\n let retryTimer: ReturnType<typeof setTimeout> | undefined\n\n const scheduleRetry = (area: 'command catalog' | 'command scope', attempt: number) => {\n if (retryTimer !== undefined) clearTimeout(retryTimer)\n const delay = area === 'command catalog' ? CATALOG_RETRY_MS * attempt : Math.min(SCOPE_RETRY_MS * 2 ** attempt, 5_000)\n retryTimer = setTimeout(() => {\n if (!stopped) refresh()\n }, delay)\n retryTimer.unref?.()\n }\n\n const refresh = () => {\n pending = pending.then(async () => {\n if (stopped) return\n diagnostic.attempts += 1\n\n let catalog: Awaited<ReturnType<ClaudeSupervisor['supportedCommands']>> | undefined\n\n try {\n const result = await supervisor.supportedCommands(agent, model)\n catalog = result\n catalogRetries = 0\n scopeRetries = 0\n diagnostic.lastCatalog = catalog.length\n delete diagnostic.lastError\n } catch (error) {\n diagnostic.lastError = error instanceof Error ? error.message : String(error)\n warn('command catalog', error)\n if (!stopped && catalogRetries < MAX_CATALOG_RETRIES) {\n catalogRetries += 1\n scheduleRetry('command catalog', catalogRetries)\n }\n }\n\n if (stopped || catalog === undefined) return\n\n try {\n const commands = projectClaudeCommands(catalog, commandTarget)\n publishCommands(commands)\n diagnostic.registered = commands.map(view => view.publicName)\n if (!stopped) scopeRetries = 0\n } catch (error) {\n diagnostic.lastError = error instanceof Error ? error.message : String(error)\n warn('command catalog', error)\n if (!stopped && isScopeUnavailable(error) && scopeRetries < MAX_SCOPE_RETRIES) {\n scopeRetries += 1\n scheduleRetry('command scope', scopeRetries)\n }\n }\n\n if (stopped) return\n try {\n const usage = await supervisor.contextUsage(agent, model)\n if (!stopped) await sidecar.writeContextUsage(agent.id as string, usage)\n } catch (error) {\n warn('context usage', error)\n }\n\n if (stopped) return\n // Plan limits belong to the account, not the session, so any idle Claude\n // agent can refresh the cache the (session-less) settings page reads.\n try {\n const plan = await supervisor.planUsage(agent, model)\n if (!stopped) recordPlanUsage(normalizePlanUsage(plan, Date.now()))\n } catch (error) {\n warn('plan usage', error)\n }\n })\n }\n\n return agent.ctx.effect(() => {\n const stopStatus = agent.ctx.on('agent/status', ({ status }) => {\n if (status === 'idle') refresh()\n })\n\n refresh()\n\n return async () => {\n stopped = true\n publishCommands([])\n if (retryTimer !== undefined) clearTimeout(retryTimer)\n stopStatus()\n await pending\n }\n }, 'dsh-claude: agent metadata bridge')\n}\n\nexport async function installManagedPresetCompatibility(\n logger: Pick<Context['logger'], 'warn'>,\n install: typeof ensureManagedPreset = ensureManagedPreset,\n): Promise<'installed' | 'unchanged' | 'conflict'> {\n try {\n return await install()\n } catch (error) {\n if (!(error instanceof ManagedPresetConflictError)) throw error\n logger.warn(`dsh-claude: preserving user-modified preset at ${error.path}`)\n return 'conflict'\n }\n}\n\nexport async function apply(ctx: Context, config: Config): Promise<void> {\n // DSH Desktop 2.0.4 does not retain third-party preset roots from bundle\n // patches, so keep a guarded user-root copy. Its bare route specifier resolves\n // through the profile package factory and does not create a second Loader source.\n await installManagedPresetCompatibility(ctx.logger)\n const defaultLimits = {\n idleTimeoutMs: config.idleTimeoutMs ?? 30 * 60 * 1_000,\n maxProcesses: config.maxProcesses ?? 4,\n }\n const supervisorConfig = {\n executablePath: '',\n defaultModel: config.model ?? 'default',\n renderMode: DEFAULT_CLAUDE_RENDER_MODE,\n ...defaultLimits,\n }\n // Settings overrides win over the plugin config; the supervisor reads the\n // shared config object on every admission, idle schedule, and rendered\n // message, so updates take effect without a restart. The Client still\n // decides its own conversation nodes at boot, which is why the renderer\n // setting is declared as restart-scoped.\n const applySettingsOverrides = async (): Promise<void> => {\n const overrides = await readSupervisorLimitOverrides()\n supervisorConfig.idleTimeoutMs = overrides.idleTimeoutMs ?? defaultLimits.idleTimeoutMs\n supervisorConfig.maxProcesses = overrides.maxProcesses ?? defaultLimits.maxProcesses\n supervisorConfig.renderMode = await readRenderMode()\n }\n await applySettingsOverrides()\n const sidecar = new ClaudeSidecarRepository()\n const repositoryStatus = new RepositoryStatusService(ctx.subprocess)\n const repositorySetup = new RepositorySetupService(ctx.subprocess, {\n branchPrefix: () => readWorktreeBranchPrefix(),\n // Read at call time: the executable is resolved after this service exists.\n summarizeBranch: intent => summarizeBranchSlug(supervisorConfig.executablePath, intent),\n })\n const reviewComments = new ReviewCommentStore()\n const commandCatalogs = new Map<string, readonly ClaudeCommandView[]>()\n const supervisor = new ClaudeSupervisor({\n runtime: ctx.subprocess,\n approval: ctx.approval,\n userQuestions: ctx.userQuestions,\n config: supervisorConfig,\n runDetached: operation => ctx.agents.withoutInitiator(operation),\n sidecar,\n })\n let resolutionError: unknown\n try {\n const resolution = await resolveClaudeExecutable(\n ctx.subprocess,\n config.executablePath === undefined || config.executablePath.length === 0\n ? undefined\n : config.executablePath,\n )\n supervisorConfig.executablePath = resolution.path\n ctx.llm.registerAdapter(\n [...CLAUDE_CODE_PROVIDER_IDS],\n createClaudeCodeAdapter(supervisor, ctx.agents, ctx.attachments, agent => ctx.agentPresets.composedPreset(agent.ctx), sessionId => reviewComments.drain(sessionId), () => supervisorConfig.renderMode),\n )\n ctx.effect(() => {\n const mounted = new Map<Agent, () => Promise<void>>()\n const pending = new Set<Agent>()\n const MOUNT_RETRY_MS = 200\n const MOUNT_RETRY_LIMIT = 50\n const mount = (agent: Agent) => {\n if (mounted.has(agent)) return\n const sessionId = agent.id as string\n const dispose = mountClaudeMetadata(\n ctx,\n supervisor,\n agent,\n supervisorConfig.defaultModel,\n sidecar,\n commands => {\n if (commands.length === 0) commandCatalogs.delete(sessionId)\n else commandCatalogs.set(sessionId, commands)\n },\n )\n if (dispose !== undefined) mounted.set(agent, dispose)\n pending.delete(agent)\n }\n // The standing preset mount lands AFTER agent/created (the PresetTree is\n // applied asynchronously), so composedPreset is still undefined at that\n // point. Poll briefly until the join settles, then decide.\n const mountWhenPresetSettles = (agent: Agent) => {\n if (mounted.has(agent) || pending.has(agent)) return\n if (ctx.agentPresets.composedPreset(agent.ctx) !== undefined) {\n mount(agent)\n return\n }\n pending.add(agent)\n let attempts = 0\n const retry = () => {\n if (mounted.has(agent) || !pending.has(agent)) return\n if (ctx.agentPresets.composedPreset(agent.ctx) !== undefined) {\n mount(agent)\n return\n }\n attempts += 1\n if (attempts >= MOUNT_RETRY_LIMIT) {\n pending.delete(agent)\n return\n }\n const timer = setTimeout(retry, MOUNT_RETRY_MS)\n timer.unref?.()\n }\n const timer = setTimeout(retry, MOUNT_RETRY_MS)\n timer.unref?.()\n }\n const stopCreated = ctx.on('agent/created', ({ agent }) => { mountWhenPresetSettles(agent) })\n // Belt and suspenders: the session records its preset selection as a\n // durable event, which agent-presets republishes as agent-preset/selected.\n // agent-preset/selected is emitted by dsh-agent-presets but is not part\n // of the typed host event map yet; subscribe through a typed escape hatch.\n const onPresetSelected = ctx.on as (event: 'agent-preset/selected', handler: (sessionId: string, preset: string) => void) => () => void\n const stopSelected = onPresetSelected('agent-preset/selected', (sessionId, preset) => {\n if (preset !== CLAUDE_CODE_PRESET_ID) return\n const agent = ctx.agents.get(sessionId as never)\n if (agent !== undefined) mountWhenPresetSettles(agent)\n })\n for (const agent of ctx.agents.list()) mountWhenPresetSettles(agent)\n return async () => {\n stopCreated()\n stopSelected()\n pending.clear()\n await Promise.allSettled([...mounted.values()].map(dispose => dispose()))\n mounted.clear()\n }\n }, 'dsh-claude: metadata bridges')\n } catch (error) {\n resolutionError = error\n }\n ctx.on('agent/disposed', async ({ agent }) => {\n reviewComments.disposeSession(agent.id as string)\n await supervisor.disposeSession(agent.id as string)\n })\n // Set once the reconciliation below is wired; the Client's sweep route kicks\n // it so a deleted workspace does not wait out the interval.\n let sweepWorktrees: (() => void) | undefined\n // Deleting a workspace from the sidebar is a durable-registry mutation with\n // no agent lifecycle edge, so worktree cleanup reconciles leases against\n // the workspace registry instead: unreferenced clean worktrees are removed\n // on boot, on the Client's deletion kick, and on a slow interval.\n // workspaceRegistry is not part of this plugin's typed host surface yet;\n // inject through an untyped escape hatch so older Hosts without the service\n // simply never start the sweep.\n const injectWorkspaceRegistry = ctx.inject as unknown as (\n deps: readonly string[],\n callback: (sweepCtx: Context & {\n workspaceRegistry: {\n list(): readonly { readonly path: string }[]\n archiveSession(sessionId: string): Promise<void>\n }\n }) => void,\n ) => void\n injectWorkspaceRegistry(['workspaceRegistry'], sweepCtx => {\n // Deleting a workspace only drops its registration: the Host keeps every\n // session log, and rebuilds the workspace from those headers on the next\n // boot. Archiving the sessions that lived in the worktree is what makes\n // the deletion stick. Resolved per sweep rather than injected so a Host\n // without the service still gets worktree cleanup.\n const archiveSessions = async (worktreePath: string): Promise<void> => {\n const persistence = sweepCtx.get('sessionPersistence') as {\n list(): Promise<readonly { readonly id?: unknown; readonly cwd?: unknown }[]>\n } | undefined\n if (persistence === undefined) return\n const target = comparablePath(worktreePath)\n for (const header of await persistence.list()) {\n if (typeof header.id !== 'string' || typeof header.cwd !== 'string') continue\n if (comparablePath(header.cwd) !== target) continue\n await sweepCtx.workspaceRegistry.archiveSession(header.id).catch(() => undefined)\n }\n }\n const sweep = (): void => {\n try {\n const paths = sweepCtx.workspaceRegistry.list().map(workspace => workspace.path)\n void repositorySetup.cleanupOrphans(paths, archiveSessions).catch(() => undefined)\n } catch {\n // The registry can be mid-teardown; skip this pass.\n }\n }\n sweepCtx.effect(() => {\n sweep()\n sweepWorktrees = sweep\n // The kick covers the deletion the user is watching; this poll is the\n // backstop for a Client that never sent one. A pass with nothing to\n // reconcile is one small file read.\n const timer = setInterval(sweep, 60_000)\n timer.unref?.()\n return () => {\n sweepWorktrees = undefined\n clearInterval(timer)\n }\n }, 'dsh-claude: worktree reconciliation')\n })\n ctx.effect(() => () => reviewComments.dispose(), 'dsh-claude: review comments store')\n ctx.effect(() => () => supervisor.dispose(), 'dsh-claude: process supervisor')\n ctx.effect(() => () => repositoryStatus.dispose(), 'dsh-claude: repository status cache')\n ctx.inject(['webServer'], webCtx => {\n registerClaudeClientDiagnosticsRoute(webCtx)\n registerClaudeDoctorRoutes(webCtx, webCtx.subprocess, supervisor, supervisorConfig, resolutionError)\n const desktopActions = webCtx.get('desktopActions') as { requestRestart?: () => void } | undefined\n registerClaudeUpdateRoutes(webCtx, webCtx.subprocess, {\n ...(typeof desktopActions?.requestRestart === 'function'\n ? { requestRestart: desktopActions.requestRestart.bind(desktopActions) }\n : {}),\n })\n registerClaudeGlobalSettingsRoute(webCtx, { defaultLimits, onUpdated: applySettingsOverrides })\n registerRepositorySetupRoute(webCtx, repositorySetup, () => sweepWorktrees?.())\n registerRepositoryStatusRoute(webCtx, repositoryStatus)\n registerRepositoryFileRoute(webCtx, repositoryStatus)\n registerJiraRoute(webCtx, new JiraService())\n const repositoryActions = new RepositoryActionService(webCtx.subprocess, supervisorConfig.executablePath, cwd => repositoryStatus.invalidate(cwd))\n const cwdForClaudeSession = (sessionId: string): string | undefined => {\n const agent = webCtx.agents.get(sessionId as never)\n if (agent === undefined || webCtx.agentPresets.composedPreset(agent.ctx) !== CLAUDE_CODE_PRESET_ID) return undefined\n return agent.session.header.cwd\n }\n registerRepositoryActionRoute(webCtx, repositoryActions, cwdForClaudeSession)\n registerEditorOpenRoute(webCtx, new EditorOpenService(webCtx.subprocess), cwdForClaudeSession)\n registerPullRequestFeedbackRoute(webCtx, new PullRequestFeedbackService(webCtx.subprocess), cwdForClaudeSession)\n registerAskRoute(webCtx, new AskService(webCtx.subprocess, supervisorConfig.executablePath), cwdForClaudeSession, sessionId => {\n const snapshot = supervisor.snapshots().find(item => item.sessionId === sessionId)\n return snapshot === undefined ? undefined : { model: snapshot.model, ...(snapshot.thinkingMode === undefined ? {} : { thinkingMode: snapshot.thinkingMode }) }\n })\n const ownsClaudeSession = (sessionId: string): boolean => {\n const agent = webCtx.agents.get(sessionId as never)\n return agent !== undefined && webCtx.agentPresets.composedPreset(agent.ctx) === CLAUDE_CODE_PRESET_ID\n }\n registerReviewCommentRoute(webCtx, reviewComments, ownsClaudeSession)\n registerClaudeRewindRoute(webCtx, sidecar, {\n eventsFor: sessionId => {\n const agent = webCtx.agents.get(sessionId as never)\n return agent === undefined || webCtx.agentPresets.composedPreset(agent.ctx) !== CLAUDE_CODE_PRESET_ID\n ? undefined\n : agent.session.events\n },\n busy: sessionId => supervisor.snapshots().some(item => (\n item.sessionId === sessionId && (item.state === 'running' || item.state === 'interrupting')\n )),\n reset: sessionId => supervisor.disposeSession(sessionId),\n })\n registerPlanUsageRoute(webCtx, fetchedAt => probePlanUsage(supervisorConfig.executablePath, fetchedAt))\n registerClaudeProjectionRoute(webCtx, sidecar, ownsClaudeSession, sessionId => commandCatalogs.get(sessionId) ?? [], async sessionId => {\n const agent = webCtx.agents.get(sessionId as never)\n if (agent === undefined || webCtx.agentPresets.composedPreset(agent.ctx) !== CLAUDE_CODE_PRESET_ID) return undefined\n const cwd = agent.session.header.cwd\n return cwd === undefined ? undefined : repositoryStatus.inspect(cwd)\n }, sessionId => reviewComments.list(sessionId))\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAwCA,MAAa,qBAAwC;CAAE,QAAQ,CAAC;CAAG,SAAS,CAAC;A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