@norman-else/dsh-claude 0.1.34 → 0.1.36
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/README.md +196 -191
- package/lib/bin.mjs +1 -1
- package/lib/client.d.ts +13 -0
- package/lib/client.js +1991 -1174
- package/lib/client.js.map +1 -1
- package/lib/{events-DeSV0S1-.mjs → events-OhBoFNKO.mjs} +13 -2
- package/lib/events-OhBoFNKO.mjs.map +1 -0
- package/lib/index.d.mts +59 -2
- package/lib/index.mjs +1261 -483
- package/lib/index.mjs.map +1 -1
- package/lib/presenters-BBoM1Ju1.mjs +300 -0
- package/lib/presenters-BBoM1Ju1.mjs.map +1 -0
- package/lib/{preset-installer-BY4846KK.mjs → preset-installer-loenwnLS.mjs} +2 -2
- package/lib/{preset-installer-BY4846KK.mjs.map → preset-installer-loenwnLS.mjs.map} +1 -1
- package/lib/preset-route.mjs +2 -172
- package/lib/preset-route.mjs.map +1 -1
- package/package.json +189 -188
- package/lib/command-bridge-DXI6nWhB.mjs +0 -71
- package/lib/command-bridge-DXI6nWhB.mjs.map +0 -1
- package/lib/events-DeSV0S1-.mjs.map +0 -1
|
@@ -24,6 +24,16 @@ const CLAUDE_JIRA_PATH = "/plugins/dsh-claude/jira";
|
|
|
24
24
|
const CLAUDE_ASK_PATH = "/plugins/dsh-claude/ask";
|
|
25
25
|
const CLAUDE_EDITOR_OPEN_PATH = "/plugins/dsh-claude/editor/open";
|
|
26
26
|
const CLAUDE_REWIND_PATH = "/plugins/dsh-claude/rewind";
|
|
27
|
+
const CLAUDE_RENDER_MODES = ["plugin", "native"];
|
|
28
|
+
const DEFAULT_CLAUDE_RENDER_MODE = "plugin";
|
|
29
|
+
function isClaudeRenderMode(value) {
|
|
30
|
+
return value === "plugin" || value === "native";
|
|
31
|
+
}
|
|
32
|
+
const CLAUDE_PROSE_MODES = ["plain", "enhanced"];
|
|
33
|
+
const DEFAULT_CLAUDE_PROSE_MODE = "plain";
|
|
34
|
+
function isClaudeProseMode(value) {
|
|
35
|
+
return value === "plain" || value === "enhanced";
|
|
36
|
+
}
|
|
27
37
|
//#endregion
|
|
28
38
|
//#region src/events.ts
|
|
29
39
|
const SECRET_KEY = /(?:^|[_-])(password|passwd|secret|token|api[_-]?key|authorization|credential|private[_-]?key|session[_-]?key|env|environ|environment)(?:$|[_-])/i;
|
|
@@ -101,6 +111,7 @@ function normalizeActivity(activity) {
|
|
|
101
111
|
if (activity.text !== void 0) normalized.text = redactText(activity.text, MAX_TRANSCRIPT_TEXT_CHARS);
|
|
102
112
|
if (activity.isError !== void 0) normalized.isError = activity.isError;
|
|
103
113
|
if (activity.usage !== void 0) normalized.usage = { ...activity.usage };
|
|
114
|
+
if (isClaudeRenderMode(activity.renderer)) normalized.renderer = activity.renderer;
|
|
104
115
|
return normalized;
|
|
105
116
|
}
|
|
106
117
|
const MAX_CONTEXT_CATEGORIES = 24;
|
|
@@ -193,6 +204,6 @@ function latestClaudeSessionBinding(events) {
|
|
|
193
204
|
}
|
|
194
205
|
}
|
|
195
206
|
//#endregion
|
|
196
|
-
export {
|
|
207
|
+
export { CLAUDE_REWIND_PATH as A, CLAUDE_RENDER_MODES as C, CLAUDE_REPOSITORY_SETUP_PATH as D, CLAUDE_REPOSITORY_FILE_PATH as E, DEFAULT_CLAUDE_RENDER_MODE as F, SDK_VERSION as I, TASK_TOOL_NAMES as L, CLAUDE_UPDATE_PATH as M, CLAUDE_USAGE_PATH as N, CLAUDE_REPOSITORY_STATUS_PATH as O, DEFAULT_CLAUDE_PROSE_MODE as P, isClaudeProseMode as R, CLAUDE_PROSE_MODES as S, CLAUDE_REPOSITORY_FEEDBACK_PATH as T, CLAUDE_DOCTOR_PATH as _, latestClaudeTasks as a, CLAUDE_JIRA_PATH as b, normalizeTasksEvent as c, CLAUDE_ACTIVITY_EVENT as d, CLAUDE_ASK_PATH as f, CLAUDE_CODE_PROVIDER_IDS as g, CLAUDE_CODE_PROVIDER as h, latestClaudeSessionBinding as i, CLAUDE_UPDATE_CHECK_PATH as j, CLAUDE_REVIEW_COMMENT_PATH as k, redactText as l, CLAUDE_CODE_PRESET_ID as m, currentClaudeActivityCursor as n, normalizeActivity as o, CLAUDE_CLIENT_DIAGNOSTICS_PATH as p, latestClaudeContextUsage as r, normalizeContextUsage as s, boundText as t, safeDetail as u, CLAUDE_EDITOR_OPEN_PATH as v, CLAUDE_REPOSITORY_ACTION_PATH as w, CLAUDE_PROJECTION_PATH as x, CLAUDE_GLOBAL_SETTINGS_PATH as y, isClaudeRenderMode as z };
|
|
197
208
|
|
|
198
|
-
//# sourceMappingURL=events-
|
|
209
|
+
//# sourceMappingURL=events-OhBoFNKO.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events-OhBoFNKO.mjs","names":[],"sources":["../src/constants.ts","../src/events.ts"],"sourcesContent":["export const CLAUDE_CODE_PROVIDER = 'claude'\nexport const CLAUDE_CODE_PRESET_ID = 'claude'\nexport const CLAUDE_CODE_PROVIDER_IDS = [CLAUDE_CODE_PROVIDER] as const\nexport const CLAUDE_SESSION_BOUND_EVENT = 'claude-code/session-bound'\nexport const CLAUDE_ACTIVITY_EVENT = 'claude-code/activity'\nexport const CLAUDE_CONTEXT_USAGE_EVENT = 'claude-code/context-usage'\nexport const CLAUDE_TASKS_EVENT = 'claude-code/tasks'\n/** Claude's subagent dispatch tools; rendered as plugin-owned group cards\n * gathering subagent activity instead of native tool cards. */\nexport const TASK_TOOL_NAMES: ReadonlySet<string> = new Set(['Task', 'Agent'])\nexport const SDK_VERSION = '0.3.247'\nexport const CLAUDE_DOCTOR_PATH = '/plugins/dsh-claude/doctor'\nexport const CLAUDE_CLIENT_DIAGNOSTICS_PATH = '/plugins/dsh-claude/client-diagnostics'\nexport const CLAUDE_UPDATE_CHECK_PATH = '/plugins/dsh-claude/update/check'\nexport const CLAUDE_USAGE_PATH = '/plugins/dsh-claude/usage'\nexport const CLAUDE_UPDATE_PATH = '/plugins/dsh-claude/update'\nexport const CLAUDE_PROJECTION_PATH = '/plugins/dsh-claude/projection'\nexport const CLAUDE_GLOBAL_SETTINGS_PATH = '/plugins/dsh-claude/settings/global'\nexport const CLAUDE_REPOSITORY_SETUP_PATH = '/plugins/dsh-claude/repository/setup'\nexport const CLAUDE_REPOSITORY_ACTION_PATH = '/plugins/dsh-claude/repository/action'\nexport const CLAUDE_REVIEW_COMMENT_PATH = '/plugins/dsh-claude/review-comments'\nexport const CLAUDE_REPOSITORY_FEEDBACK_PATH = '/plugins/dsh-claude/repository/feedback'\nexport const CLAUDE_REPOSITORY_STATUS_PATH = '/plugins/dsh-claude/repository/status'\nexport const CLAUDE_REPOSITORY_FILE_PATH = '/plugins/dsh-claude/repository/file'\nexport const CLAUDE_JIRA_PATH = '/plugins/dsh-claude/jira'\nexport const CLAUDE_ASK_PATH = '/plugins/dsh-claude/ask'\nexport const CLAUDE_EDITOR_OPEN_PATH = '/plugins/dsh-claude/editor/open'\nexport const CLAUDE_REWIND_PATH = '/plugins/dsh-claude/rewind'\n\n/** Which renderer draws Claude's visible output.\n *\n * 'plugin' keeps the sidecar-backed transcript this package owns (interleaved\n * prose, grouped tool cards, activity rows). 'native' hands the same turn to\n * DSH's own conversation renderer: prose streams as ordinary assistant text\n * blocks, thinking as reasoning blocks, and root Claude tools are mirrored\n * into the durable `tool/call`/`tool/result` channel so the Host's tool\n * presentation pipeline draws them exactly like DSH-executed calls. */\nexport type ClaudeRenderMode = 'plugin' | 'native'\nexport const CLAUDE_RENDER_MODES = ['plugin', 'native'] as const\nexport const DEFAULT_CLAUDE_RENDER_MODE: ClaudeRenderMode = 'plugin'\n\nexport function isClaudeRenderMode(value: unknown): value is ClaudeRenderMode {\n return value === 'plugin' || value === 'native'\n}\n\n/** How this package paints the PROSE of a Claude answer.\n *\n * 'plain' is Claude's own presentation: body text in the Host's text colour,\n * colour reserved for code. 'enhanced' gives headings, emphasis, list markers,\n * quotes and links their own hues and darkens the code surface — the way a\n * Markdown-highlighting editor shows a document rather than the way Claude\n * desktop shows an answer. It is opt-in because it deliberately breaks the\n * parity the rest of `markdown-theme.ts` exists to hold.\n *\n * Only meaningful under {@link ClaudeRenderMode} 'plugin': the stylesheet is\n * scoped to markup this package renders, and 'native' turns are drawn by the\n * Host, where it has no reach. */\nexport type ClaudeProseMode = 'plain' | 'enhanced'\nexport const CLAUDE_PROSE_MODES = ['plain', 'enhanced'] as const\nexport const DEFAULT_CLAUDE_PROSE_MODE: ClaudeProseMode = 'plain'\n\nexport function isClaudeProseMode(value: unknown): value is ClaudeProseMode {\n return value === 'plain' || value === 'enhanced'\n}\n","import type { SessionEvent } from '@deepseek-ai/dsh-session'\nimport {\n CLAUDE_ACTIVITY_EVENT,\n CLAUDE_CONTEXT_USAGE_EVENT,\n CLAUDE_SESSION_BOUND_EVENT,\n CLAUDE_TASKS_EVENT,\n isClaudeRenderMode,\n type ClaudeRenderMode,\n} from './constants.ts'\n\nexport type ClaudeActivityKind =\n | 'text'\n | 'status'\n /** Context compaction boundary; the transcript draws it as a divider. */\n | 'compaction'\n | 'thinking'\n | 'tool-call'\n | 'tool-result'\n | 'permission'\n | 'question'\n | 'subagent'\n | 'usage'\n | 'warning'\n | 'error'\n\nexport type ClaudeActivityPhase =\n | 'started'\n | 'updated'\n | 'completed'\n | 'denied'\n | 'failed'\n\nexport interface ClaudeUsage {\n inputTokens?: number\n outputTokens?: number\n cacheReadTokens?: number\n cacheCreationTokens?: number\n cumulativeCostUsd?: number\n /** Wall time from the turn being admitted to it settling. Measured here\n * rather than derived on the client: activities carry no timestamps. */\n durationMs?: number\n /** Wall time to the first visible token of the turn. */\n ttftMs?: number\n}\n\nexport interface ClaudeSessionBoundEvent {\n claudeSessionId: string\n cliVersion?: string\n sdkVersion: string\n cwd: string\n}\n\nexport interface ClaudeActivityEvent {\n turn: number\n step: number\n ordinal: number\n kind: ClaudeActivityKind\n phase?: ClaudeActivityPhase\n /** Claude task-board identity for lifecycle activity; never a transcript path. */\n taskId?: string\n toolUseId?: string\n /** Enclosing Claude tool call for subagent-nested activity. */\n parentToolUseId?: string\n toolName?: string\n title?: string\n summary?: string\n detail?: string\n /** Redacted visible Claude prose used by the plugin-owned interleaved transcript. */\n text?: string\n isError?: boolean\n usage?: ClaudeUsage\n /** Which renderer this record was produced for. Stamped only when the Host\n * drew the step natively, so a record written before the setting existed —\n * and every record written under the plugin renderer — reads as 'plugin'.\n * It travels with the data so a step always renders the way it was\n * recorded, whatever the setting says now. */\n renderer?: ClaudeRenderMode\n}\n\nexport interface ClaudeContextUsageCategory {\n name: string\n tokens: number\n color: string\n isDeferred?: boolean\n}\n\nexport interface ClaudeContextUsageEvent {\n model: string\n totalTokens: number\n maxTokens: number\n percentage: number\n categories: readonly ClaudeContextUsageCategory[]\n}\n\nexport interface ClaudeContextUsageInput {\n model: unknown\n totalTokens: unknown\n maxTokens: unknown\n percentage: unknown\n categories: readonly {\n name?: unknown\n tokens?: unknown\n color?: unknown\n isDeferred?: unknown\n }[]\n}\n\ndeclare module '@deepseek-ai/dsh-session/types' {\n interface SessionEventMap {\n 'claude-code/session-bound': ClaudeSessionBoundEvent\n 'claude-code/activity': ClaudeActivityEvent\n 'claude-code/context-usage': ClaudeContextUsageEvent\n 'claude-code/tasks': ClaudeTasksEvent\n }\n}\n\nconst SECRET_KEY = /(?:^|[_-])(password|passwd|secret|token|api[_-]?key|authorization|credential|private[_-]?key|session[_-]?key|env|environ|environment)(?:$|[_-])/i\nconst MAX_SUMMARY_CHARS = 1_000\nconst MAX_DETAIL_CHARS = 4_000\nconst MAX_TRANSCRIPT_TEXT_CHARS = 64_000\nconst MAX_DEPTH = 6\nconst MAX_ARRAY_ITEMS = 40\nconst MAX_OBJECT_KEYS = 60\nconst REDACTED = '[REDACTED]'\nconst TRUNCATED = '…[truncated]'\nconst SECRET_ASSIGNMENT = /((?:password|passwd|secret|token|api[_-]?key|authorization|credential|private[_-]?key|session[_-]?key)\\s*(?:=|:)\\s*)(?:\"[^\"]*\"|'[^']*'|[^\\s,;&]+)/giu\nconst BEARER_TOKEN = /(\\bbearer\\s+)[A-Za-z0-9._~+/=-]+/giu\nconst PREFIXED_TOKEN = /\\b(?:sk-(?:ant-|proj-)?|xox[baprs]-|ghp_|github_pat_)[A-Za-z0-9_-]{8,}/giu\nconst JWT_TOKEN = /\\beyJ[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]+\\b/gu\nconst URL_USERINFO = /([a-z][a-z0-9+.-]*:\\/\\/[^:\\s/@]+:)[^@\\s/]+@/giu\nconst URL_SECRET_PARAM = /([?&](?:password|secret|token|api[_-]?key|access[_-]?token|refresh[_-]?token)=)[^&#\\s]+/giu\n\nexport function boundText(value: string, maxChars: number): string {\n if (value.length <= maxChars) return value\n return `${value.slice(0, Math.max(0, maxChars - TRUNCATED.length))}${TRUNCATED}`\n}\n\nexport function redactText(value: string, maxChars = MAX_DETAIL_CHARS): string {\n return boundText(\n value\n .replace(JWT_TOKEN, REDACTED)\n .replace(PREFIXED_TOKEN, REDACTED)\n .replace(BEARER_TOKEN, `$1${REDACTED}`)\n .replace(URL_USERINFO, `$1${REDACTED}@`)\n .replace(URL_SECRET_PARAM, `$1${REDACTED}`)\n .replace(SECRET_ASSIGNMENT, `$1${REDACTED}`),\n maxChars,\n )\n}\n\nexport function redactValue(value: unknown, depth = 0, seen = new WeakSet<object>()): unknown {\n if (depth > MAX_DEPTH) return '[max-depth]'\n if (value === null || typeof value === 'boolean' || typeof value === 'number') return value\n if (typeof value === 'string') return redactText(value)\n if (typeof value === 'bigint') return value.toString()\n if (typeof value === 'undefined') return null\n if (typeof value === 'function' || typeof value === 'symbol') return `[${typeof value}]`\n if (value instanceof Error) {\n return { name: value.name, message: redactText(value.message, MAX_SUMMARY_CHARS) }\n }\n if (typeof value !== 'object') return String(value)\n if (seen.has(value)) return '[circular]'\n seen.add(value)\n try {\n if (Array.isArray(value)) {\n const items = value.slice(0, MAX_ARRAY_ITEMS).map(item => redactValue(item, depth + 1, seen))\n if (value.length > MAX_ARRAY_ITEMS) items.push(`[${value.length - MAX_ARRAY_ITEMS} more items]`)\n return items\n }\n const result: Record<string, unknown> = {}\n const entries = Object.entries(value as Record<string, unknown>)\n for (const [key, item] of entries.slice(0, MAX_OBJECT_KEYS)) {\n result[key] = SECRET_KEY.test(key) ? REDACTED : redactValue(item, depth + 1, seen)\n }\n if (entries.length > MAX_OBJECT_KEYS) result.__truncatedKeys = entries.length - MAX_OBJECT_KEYS\n return result\n } finally {\n seen.delete(value)\n }\n}\n\nexport function safeDetail(value: unknown): string | undefined {\n if (value === undefined) return undefined\n const redacted = redactValue(value)\n const text = typeof redacted === 'string' ? redacted : JSON.stringify(redacted)\n return boundText(text, MAX_DETAIL_CHARS)\n}\n\nexport function normalizeActivity(\n activity: Omit<ClaudeActivityEvent, 'summary' | 'detail'> & {\n summary?: unknown\n detail?: unknown\n },\n): ClaudeActivityEvent {\n const normalized: ClaudeActivityEvent = {\n turn: activity.turn,\n step: activity.step,\n ordinal: activity.ordinal,\n kind: activity.kind,\n }\n if (activity.phase !== undefined) normalized.phase = activity.phase\n if (activity.taskId !== undefined) normalized.taskId = redactText(activity.taskId, 128)\n if (activity.toolUseId !== undefined) normalized.toolUseId = redactText(activity.toolUseId, 256)\n if (activity.parentToolUseId !== undefined) normalized.parentToolUseId = redactText(activity.parentToolUseId, 256)\n if (activity.toolName !== undefined) normalized.toolName = redactText(activity.toolName, 256)\n if (activity.title !== undefined) normalized.title = redactText(activity.title, MAX_SUMMARY_CHARS)\n if (activity.summary !== undefined) {\n normalized.summary = redactText(\n typeof activity.summary === 'string' ? activity.summary : safeDetail(activity.summary) ?? '',\n MAX_SUMMARY_CHARS,\n )\n }\n const detail = safeDetail(activity.detail)\n if (detail !== undefined) normalized.detail = detail\n if (activity.text !== undefined) normalized.text = redactText(activity.text, MAX_TRANSCRIPT_TEXT_CHARS)\n if (activity.isError !== undefined) normalized.isError = activity.isError\n if (activity.usage !== undefined) normalized.usage = { ...activity.usage }\n if (isClaudeRenderMode(activity.renderer)) normalized.renderer = activity.renderer\n return normalized\n}\n\nconst MAX_CONTEXT_CATEGORIES = 24\nconst FALLBACK_CONTEXT_COLOR = '#8b95a5'\nconst SAFE_CONTEXT_COLOR = /^#[0-9a-f]{3,8}$/iu\n\nfunction nonNegativeInteger(value: unknown): number {\n return typeof value === 'number' && Number.isFinite(value)\n ? Math.max(0, Math.floor(value))\n : 0\n}\n\nexport function normalizeContextUsage(input: ClaudeContextUsageInput): ClaudeContextUsageEvent {\n return {\n model: redactText(typeof input.model === 'string' ? input.model : 'unknown', 128),\n totalTokens: nonNegativeInteger(input.totalTokens),\n maxTokens: nonNegativeInteger(input.maxTokens),\n percentage: Math.min(100, nonNegativeInteger(input.percentage)),\n categories: input.categories.slice(0, MAX_CONTEXT_CATEGORIES).map(category => ({\n name: redactText(typeof category.name === 'string' ? category.name : 'Unknown', 128),\n tokens: nonNegativeInteger(category.tokens),\n color: typeof category.color === 'string' && SAFE_CONTEXT_COLOR.test(category.color)\n ? category.color\n : FALLBACK_CONTEXT_COLOR,\n ...(category.isDeferred === true ? { isDeferred: true } : {}),\n })),\n }\n}\n\nexport function latestClaudeContextUsage(\n events: readonly SessionEvent[],\n): ClaudeContextUsageEvent | undefined {\n for (let index = events.length - 1; index >= 0; index -= 1) {\n const event = events[index]\n if (event?.type === CLAUDE_CONTEXT_USAGE_EVENT) return event.data as ClaudeContextUsageEvent\n }\n return undefined\n}\n\nexport type ClaudeTaskStatus = 'running' | 'completed' | 'failed' | 'stopped' | 'killed'\n\nexport interface ClaudeTaskUsage {\n totalTokens?: number\n toolUses?: number\n durationMs?: number\n}\n\nexport interface ClaudeTaskInfo {\n taskId: string\n description: string\n status: ClaudeTaskStatus\n /** DSH turn during which this task was first observed, when known. */\n originTurn?: number\n subagentType?: string\n taskType?: string\n lastToolName?: string\n summary?: string\n usage?: ClaudeTaskUsage\n /** True while the task runs detached (background command/subagent). */\n backgrounded?: boolean\n}\n\n/** Level snapshot of one session's Claude task board, REPLACE semantics. */\nexport interface ClaudeTasksEvent {\n tasks: readonly ClaudeTaskInfo[]\n}\n\nconst MAX_TASKS_PER_SNAPSHOT = 50\nconst MAX_TASK_TEXT_CHARS = 300\n\nconst TASK_STATUSES: ReadonlySet<string> = new Set(['running', 'completed', 'failed', 'stopped', 'killed'])\n\nfunction normalizeTaskUsage(input: ClaudeTaskUsage | undefined): ClaudeTaskUsage | undefined {\n if (input === undefined) return undefined\n const usage: ClaudeTaskUsage = {}\n if (input.totalTokens !== undefined) usage.totalTokens = nonNegativeInteger(input.totalTokens)\n if (input.toolUses !== undefined) usage.toolUses = nonNegativeInteger(input.toolUses)\n if (input.durationMs !== undefined) usage.durationMs = nonNegativeInteger(input.durationMs)\n return Object.keys(usage).length === 0 ? undefined : usage\n}\n\nexport function normalizeTasksEvent(tasks: readonly ClaudeTaskInfo[]): ClaudeTasksEvent {\n return {\n tasks: tasks.slice(0, MAX_TASKS_PER_SNAPSHOT).map(task => {\n const usage = normalizeTaskUsage(task.usage)\n return {\n taskId: redactText(String(task.taskId), 128),\n description: redactText(String(task.description), MAX_TASK_TEXT_CHARS),\n status: TASK_STATUSES.has(task.status) ? task.status : 'running',\n ...(task.originTurn === undefined ? {} : { originTurn: nonNegativeInteger(task.originTurn) }),\n ...(task.subagentType === undefined ? {} : { subagentType: redactText(task.subagentType, 64) }),\n ...(task.taskType === undefined ? {} : { taskType: redactText(task.taskType, 64) }),\n ...(task.lastToolName === undefined ? {} : { lastToolName: redactText(task.lastToolName, 64) }),\n ...(task.summary === undefined ? {} : { summary: redactText(task.summary, MAX_TASK_TEXT_CHARS) }),\n ...(usage === undefined ? {} : { usage }),\n ...(task.backgrounded === true ? { backgrounded: true } : {}),\n }\n }),\n }\n}\n\nexport function latestClaudeTasks(\n events: readonly SessionEvent[],\n): ClaudeTasksEvent | undefined {\n for (let index = events.length - 1; index >= 0; index -= 1) {\n const event = events[index]\n if (event?.type === CLAUDE_TASKS_EVENT) return event.data as ClaudeTasksEvent\n }\n return undefined\n}\n\nexport type ClaudeActivityInput = Omit<\n ClaudeActivityEvent,\n 'turn' | 'step' | 'ordinal' | 'summary' | 'detail'\n> & {\n summary?: unknown\n detail?: unknown\n}\n\nexport interface ClaudeActivityCursor {\n turn: number\n step: number\n nextOrdinal: number\n}\n\n/** Derive the current DSH turn/step; activity ordinals are completed from the sidecar. */\nexport function currentClaudeActivityCursor(events: readonly SessionEvent[]): ClaudeActivityCursor {\n let turn = 0\n let step = 0\n for (const event of events) {\n if (event.type !== 'step/start') continue\n const data = event.data as { turn: number; step: number }\n turn = data.turn\n step = data.step\n }\n if (turn < 1 || step < 1) {\n throw new Error('dsh-claude: Claude activity requires an open DSH step')\n }\n return { turn, step, nextOrdinal: 0 }\n}\n\nexport function latestClaudeSessionBinding(\n events: readonly SessionEvent[],\n): ClaudeSessionBoundEvent | undefined {\n for (let index = events.length - 1; index >= 0; index -= 1) {\n const event = events[index]\n if (event?.type === CLAUDE_SESSION_BOUND_EVENT) {\n return event.data as ClaudeSessionBoundEvent\n }\n }\n return undefined\n}\n"],"mappings":";AAAA,MAAa,uBAAuB;AACpC,MAAa,wBAAwB;AACrC,MAAa,2BAA2B,CAAC,oBAAoB;AAE7D,MAAa,wBAAwB;;;AAKrC,MAAa,kCAAuC,IAAI,IAAI,CAAC,QAAQ,OAAO,CAAC;AAC7E,MAAa,cAAc;AAC3B,MAAa,qBAAqB;AAClC,MAAa,iCAAiC;AAC9C,MAAa,2BAA2B;AACxC,MAAa,oBAAoB;AACjC,MAAa,qBAAqB;AAClC,MAAa,yBAAyB;AACtC,MAAa,8BAA8B;AAC3C,MAAa,+BAA+B;AAC5C,MAAa,gCAAgC;AAC7C,MAAa,6BAA6B;AAC1C,MAAa,kCAAkC;AAC/C,MAAa,gCAAgC;AAC7C,MAAa,8BAA8B;AAC3C,MAAa,mBAAmB;AAChC,MAAa,kBAAkB;AAC/B,MAAa,0BAA0B;AACvC,MAAa,qBAAqB;AAWlC,MAAa,sBAAsB,CAAC,U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E;EAAM;EAAM,aAAa;CAAE;AACtC;AAEA,SAAgB,2BACd,QACqC;CACrC,KAAK,IAAI,QAAQ,OAAO,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG;EAC1D,MAAM,QAAQ,OAAO;EACrB,IAAI,OAAO,SAAA,6BACT,OAAO,MAAM;CAEjB;AAEF"}
|
package/lib/index.d.mts
CHANGED
|
@@ -31,6 +31,17 @@ interface ClaudeCommandView {
|
|
|
31
31
|
prefixed: boolean;
|
|
32
32
|
}
|
|
33
33
|
//#endregion
|
|
34
|
+
//#region src/constants.d.ts
|
|
35
|
+
/** Which renderer draws Claude's visible output.
|
|
36
|
+
*
|
|
37
|
+
* 'plugin' keeps the sidecar-backed transcript this package owns (interleaved
|
|
38
|
+
* prose, grouped tool cards, activity rows). 'native' hands the same turn to
|
|
39
|
+
* DSH's own conversation renderer: prose streams as ordinary assistant text
|
|
40
|
+
* blocks, thinking as reasoning blocks, and root Claude tools are mirrored
|
|
41
|
+
* into the durable `tool/call`/`tool/result` channel so the Host's tool
|
|
42
|
+
* presentation pipeline draws them exactly like DSH-executed calls. */
|
|
43
|
+
type ClaudeRenderMode = 'plugin' | 'native';
|
|
44
|
+
//#endregion
|
|
34
45
|
//#region src/events.d.ts
|
|
35
46
|
type ClaudeActivityKind = 'text' | 'status' |
|
|
36
47
|
/** Context compaction boundary; the transcript draws it as a divider. */
|
|
@@ -42,6 +53,11 @@ interface ClaudeUsage {
|
|
|
42
53
|
cacheReadTokens?: number;
|
|
43
54
|
cacheCreationTokens?: number;
|
|
44
55
|
cumulativeCostUsd?: number;
|
|
56
|
+
/** Wall time from the turn being admitted to it settling. Measured here
|
|
57
|
+
* rather than derived on the client: activities carry no timestamps. */
|
|
58
|
+
durationMs?: number;
|
|
59
|
+
/** Wall time to the first visible token of the turn. */
|
|
60
|
+
ttftMs?: number;
|
|
45
61
|
}
|
|
46
62
|
interface ClaudeSessionBoundEvent {
|
|
47
63
|
claudeSessionId: string;
|
|
@@ -68,6 +84,12 @@ interface ClaudeActivityEvent {
|
|
|
68
84
|
text?: string;
|
|
69
85
|
isError?: boolean;
|
|
70
86
|
usage?: ClaudeUsage;
|
|
87
|
+
/** Which renderer this record was produced for. Stamped only when the Host
|
|
88
|
+
* drew the step natively, so a record written before the setting existed —
|
|
89
|
+
* and every record written under the plugin renderer — reads as 'plugin'.
|
|
90
|
+
* It travels with the data so a step always renders the way it was
|
|
91
|
+
* recorded, whatever the setting says now. */
|
|
92
|
+
renderer?: ClaudeRenderMode;
|
|
71
93
|
}
|
|
72
94
|
interface ClaudeContextUsageCategory {
|
|
73
95
|
name: string;
|
|
@@ -168,7 +190,10 @@ interface ClaudeSidecarProjection {
|
|
|
168
190
|
readonly tasks?: ClaudeTasksEvent;
|
|
169
191
|
readonly rewind?: ClaudeRewindState;
|
|
170
192
|
}
|
|
171
|
-
/** Change notification published to live subscribers after each accepted write.
|
|
193
|
+
/** Change notification published to live subscribers after each accepted write.
|
|
194
|
+
*
|
|
195
|
+
* `checkpoint` is the one kind that carries no change: it restates where the
|
|
196
|
+
* stream stands so a reader can notice it is behind. See {@link ClaudeSidecarRepository.checkpoint}. */
|
|
172
197
|
type ClaudeSidecarDelta = {
|
|
173
198
|
kind: 'text';
|
|
174
199
|
turn: number;
|
|
@@ -176,6 +201,7 @@ type ClaudeSidecarDelta = {
|
|
|
176
201
|
ordinal: number;
|
|
177
202
|
append?: string;
|
|
178
203
|
text?: string;
|
|
204
|
+
renderer?: ClaudeRenderMode;
|
|
179
205
|
} | {
|
|
180
206
|
kind: 'activity';
|
|
181
207
|
activity: ClaudeActivityEvent;
|
|
@@ -187,6 +213,18 @@ type ClaudeSidecarDelta = {
|
|
|
187
213
|
value: ClaudeTasksEvent;
|
|
188
214
|
} | {
|
|
189
215
|
kind: 'sync';
|
|
216
|
+
} | {
|
|
217
|
+
kind: 'checkpoint';
|
|
218
|
+
};
|
|
219
|
+
/** One delta as subscribers see it: numbered, so a reader that applies them in
|
|
220
|
+
* order can tell a missing one from a slow one.
|
|
221
|
+
*
|
|
222
|
+
* The projection's own `revision` cannot do this job. Streaming prose notifies
|
|
223
|
+
* subscribers without touching disk (see {@link ClaudeSidecarRepository.appendTranscriptText}),
|
|
224
|
+
* so revisions and notifications advance on different clocks; this counter
|
|
225
|
+
* advances once per notification and nothing else reads it. */
|
|
226
|
+
type ClaudeSidecarNotification = ClaudeSidecarDelta & {
|
|
227
|
+
readonly seq: number;
|
|
190
228
|
};
|
|
191
229
|
interface ClaudeSidecarRepositoryOptions {
|
|
192
230
|
readonly root?: string;
|
|
@@ -199,7 +237,7 @@ declare class ClaudeSidecarRepository {
|
|
|
199
237
|
constructor(options?: ClaudeSidecarRepositoryOptions);
|
|
200
238
|
read(sessionId: string): Promise<ClaudeSidecarProjection>;
|
|
201
239
|
/** Observe accepted changes for one session; returns the unsubscriber. */
|
|
202
|
-
subscribe(sessionId: string, listener: (delta:
|
|
240
|
+
subscribe(sessionId: string, listener: (delta: ClaudeSidecarNotification) => void): () => void;
|
|
203
241
|
/** Record streaming assistant prose without touching the disk on the hot
|
|
204
242
|
* path: subscribers are notified synchronously (as an append when the
|
|
205
243
|
* redacted text grows in place) and persistence is coalesced. */
|
|
@@ -208,9 +246,19 @@ declare class ClaudeSidecarRepository {
|
|
|
208
246
|
step: number;
|
|
209
247
|
ordinal: number;
|
|
210
248
|
text: string;
|
|
249
|
+
renderer?: ClaudeRenderMode;
|
|
211
250
|
}): void;
|
|
212
251
|
/** Persist any pending streaming transcript now (segment close, turn end). */
|
|
213
252
|
flushTranscriptText(sessionId: string): Promise<void>;
|
|
253
|
+
/** How many notifications this session has published. */
|
|
254
|
+
sequence(sessionId: string): number;
|
|
255
|
+
/** Restate where the stream stands without changing anything.
|
|
256
|
+
*
|
|
257
|
+
* A reader detects a lost delta from the hole the NEXT one leaves, which
|
|
258
|
+
* never comes when the lost delta was the last of a turn -- exactly the
|
|
259
|
+
* case that leaves a finished tool group pulsing forever. Called at turn
|
|
260
|
+
* settlement, this gives that reader the one line it needs to disagree. */
|
|
261
|
+
checkpoint(sessionId: string): void;
|
|
214
262
|
writeBinding(sessionId: string, value: Omit<ClaudeSessionBoundEvent, 'sdkVersion'> & {
|
|
215
263
|
sdkVersion?: string;
|
|
216
264
|
}): Promise<ClaudeSidecarProjection>;
|
|
@@ -239,10 +287,19 @@ interface ClaudeSupervisorConfig {
|
|
|
239
287
|
idleTimeoutMs: number;
|
|
240
288
|
maxProcesses: number;
|
|
241
289
|
defaultModel: string;
|
|
290
|
+
/** Which renderer the visible turn is produced for; read per message so a
|
|
291
|
+
* Settings change lands on the next turn without a Host restart. */
|
|
292
|
+
renderMode?: ClaudeRenderMode;
|
|
242
293
|
}
|
|
243
294
|
type ClaudeTurnStreamEvent = {
|
|
244
295
|
type: 'text-delta';
|
|
245
296
|
text: string;
|
|
297
|
+
} |
|
|
298
|
+
/** One settled Claude thinking block, forwarded only for the native
|
|
299
|
+
* renderer, which draws it as a DSH reasoning block. */
|
|
300
|
+
{
|
|
301
|
+
type: 'thinking';
|
|
302
|
+
text: string;
|
|
246
303
|
} | {
|
|
247
304
|
type: 'usage';
|
|
248
305
|
usage: ClaudeUsage;
|