@di-code/coding-agent 0.1.2 → 0.1.4
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 +499 -143
- package/dist/cli.d.ts +1 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +15 -0
- package/dist/cli.js.map +1 -1
- package/dist/core/clipboard-image.d.ts +13 -0
- package/dist/core/clipboard-image.d.ts.map +1 -0
- package/dist/core/clipboard-image.js +99 -0
- package/dist/core/clipboard-image.js.map +1 -0
- package/dist/core/context-builder.d.ts.map +1 -1
- package/dist/core/context-builder.js +6 -2
- package/dist/core/context-builder.js.map +1 -1
- package/dist/core/image-input.d.ts +13 -0
- package/dist/core/image-input.d.ts.map +1 -0
- package/dist/core/image-input.js +147 -0
- package/dist/core/image-input.js.map +1 -0
- package/dist/core/session/session-storage.d.ts.map +1 -1
- package/dist/core/session/session-storage.js +1 -0
- package/dist/core/session/session-storage.js.map +1 -1
- package/dist/core/session.d.ts +19 -2
- package/dist/core/session.d.ts.map +1 -1
- package/dist/core/session.js +101 -4
- package/dist/core/session.js.map +1 -1
- package/dist/core/tools/bash.d.ts +2 -2
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit-diff.d.ts +25 -0
- package/dist/core/tools/edit-diff.d.ts.map +1 -0
- package/dist/core/tools/edit-diff.js +136 -0
- package/dist/core/tools/edit-diff.js.map +1 -0
- package/dist/core/tools/edit.d.ts +13 -4
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +64 -30
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/read.d.ts +2 -2
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/write.d.ts +2 -2
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js.map +1 -1
- package/dist/entry.js +9 -2
- package/dist/entry.js.map +1 -1
- package/dist/main.d.ts +3 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +42 -8
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive-components.d.ts +3 -0
- package/dist/modes/interactive-components.d.ts.map +1 -1
- package/dist/modes/interactive-components.js +76 -25
- package/dist/modes/interactive-components.js.map +1 -1
- package/dist/modes/interactive-diff.d.ts +8 -0
- package/dist/modes/interactive-diff.d.ts.map +1 -0
- package/dist/modes/interactive-diff.js +78 -0
- package/dist/modes/interactive-diff.js.map +1 -0
- package/dist/modes/interactive-layout.d.ts +6 -1
- package/dist/modes/interactive-layout.d.ts.map +1 -1
- package/dist/modes/interactive-layout.js +21 -1
- package/dist/modes/interactive-layout.js.map +1 -1
- package/dist/modes/interactive-state.d.ts +17 -2
- package/dist/modes/interactive-state.d.ts.map +1 -1
- package/dist/modes/interactive-state.js +103 -3
- package/dist/modes/interactive-state.js.map +1 -1
- package/dist/modes/interactive.d.ts +18 -0
- package/dist/modes/interactive.d.ts.map +1 -1
- package/dist/modes/interactive.js +289 -24
- package/dist/modes/interactive.js.map +1 -1
- package/dist/provider-onboarding.d.ts +8 -1
- package/dist/provider-onboarding.d.ts.map +1 -1
- package/dist/provider-onboarding.js +53 -23
- package/dist/provider-onboarding.js.map +1 -1
- package/dist/rpc-entry.js +1 -1
- package/dist/rpc-entry.js.map +1 -1
- package/dist/startup.d.ts +11 -3
- package/dist/startup.d.ts.map +1 -1
- package/dist/startup.js +240 -84
- package/dist/startup.js.map +1 -1
- package/dist/utils/syntax-highlight.d.ts +2 -0
- package/dist/utils/syntax-highlight.d.ts.map +1 -0
- package/dist/utils/syntax-highlight.js +55 -0
- package/dist/utils/syntax-highlight.js.map +1 -0
- package/package.json +9 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interactive-components.js","sourceRoot":"","sources":["../../src/modes/interactive-components.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,eAAe,EAAE,Y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tB,CAAC;AAOD,MAAM,OAAO,gBAAgB;IACX,SAAS,CAA8B;IAExD,YAAY,SAAsC;QACjD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC5B,CAAC;IAED,UAAU,KAAU,CAAC;IAErB,MAAM,CAAC,KAAa;QACnB,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;QAC/B,OAAO,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;YACtD,MAAM,MAAM,GAAG,KAAK,KAAK,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;YACnD,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACrE,OAAO,IAAI,IAAI,CAAC,GAAG,MAAM,GAAG,IAAI,CAAC,KAAK,GAAG,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvE,CAAC,CAAC,CAAC;IACJ,CAAC;CACD","sourcesContent":["import type { AutocompleteItem, Component } from \"@di-code/tui\";\nimport { Markdown, Text, truncateToWidth, visibleWidth } from \"@di-code/tui\";\nimport type { InteractiveState } from \"./interactive-state.ts\";\n\nexport interface InteractiveViewState extends InteractiveState {\n\treadonly model: string;\n\treadonly theme: \"dark\" | \"light\";\n}\n\ninterface Palette {\n\treadonly accent: string;\n\treadonly assistant: string;\n\treadonly dim: string;\n\treadonly error: string;\n\treadonly success: string;\n\treadonly warning: string;\n}\n\nconst RESET = \"\\x1b[0m\";\nconst BOLD = \"\\x1b[1m\";\nconst MAX_VISIBLE_TOOL_ITEMS = 6;\nconst SPINNER_FRAMES = [\"|\", \"/\", \"-\", \"\\\\\"] as const;\n\nfunction paletteFor(theme: InteractiveViewState[\"theme\"]): Palette {\n\treturn theme === \"light\"\n\t\t? {\n\t\t\t\taccent: \"\\x1b[38;5;25m\",\n\t\t\t\tassistant: \"\\x1b[38;5;30m\",\n\t\t\t\tdim: \"\\x1b[38;5;242m\",\n\t\t\t\terror: \"\\x1b[38;5;160m\",\n\t\t\t\tsuccess: \"\\x1b[38;5;28m\",\n\t\t\t\twarning: \"\\x1b[38;5;130m\",\n\t\t\t}\n\t\t: {\n\t\t\t\taccent: \"\\x1b[38;5;45m\",\n\t\t\t\tassistant: \"\\x1b[38;5;80m\",\n\t\t\t\tdim: \"\\x1b[38;5;245m\",\n\t\t\t\terror: \"\\x1b[38;5;210m\",\n\t\t\t\tsuccess: \"\\x1b[38;5;114m\",\n\t\t\t\twarning: \"\\x1b[38;5;222m\",\n\t\t\t};\n}\n\nfunction paint(color: string, text: string, bold = false): string {\n\treturn `${color}${bold ? BOLD : \"\"}${text}${RESET}`;\n}\n\nfunction renderLine(text: string, width: number): string[] {\n\treturn new Text(truncateToWidth(text, width, \"\")).render(width);\n}\n\nfunction alignEnds(left: string, right: string, width: number): string {\n\tconst gap = 3;\n\tif (visibleWidth(left) + visibleWidth(right) + gap > width) return truncateToWidth(left, width, \"\");\n\treturn `${left}${\" \".repeat(width - visibleWidth(left) - visibleWidth(right))}${right}`;\n}\n\nfunction activityLabel(state: InteractiveViewState): { readonly text: string; readonly color: string } {\n\tconst colors = paletteFor(state.theme);\n\tif (state.error) return { text: \"ERROR\", color: colors.error };\n\tif (state.compacting) return { text: \"COMPACTING\", color: colors.warning };\n\tif (state.retrying) return { text: \"RETRYING\", color: colors.warning };\n\tif (state.busy) return { text: \"WORKING\", color: colors.accent };\n\treturn { text: \"READY\", color: colors.success };\n}\n\nexport class InteractiveHeader implements Component {\n\tprivate readonly readState: () => InteractiveViewState;\n\n\tconstructor(readState: () => InteractiveViewState) {\n\t\tthis.readState = readState;\n\t}\n\n\tinvalidate(): void {}\n\n\trender(width: number): string[] {\n\t\tconst state = this.readState();\n\t\tconst colors = paletteFor(state.theme);\n\t\tconst brand = paint(colors.accent, \"DI-CODE / INTERACTIVE\", true);\n\t\tconst model = paint(colors.dim, `MODEL ${state.model}`);\n\t\tconst title =\n\t\t\twidth >= 56\n\t\t\t\t? alignEnds(brand, model, width)\n\t\t\t\t: `${paint(colors.accent, \"DI-CODE\", true)} ${paint(colors.dim, state.model)}`;\n\t\treturn [...renderLine(title, width), ...renderLine(paint(colors.dim, \"-\".repeat(Math.max(0, width))), width)];\n\t}\n}\n\nexport class InteractiveChat implements Component {\n\tprivate readonly readState: () => InteractiveViewState;\n\n\tconstructor(readState: () => InteractiveViewState) {\n\t\tthis.readState = readState;\n\t}\n\n\tinvalidate(): void {}\n\n\trender(width: number): string[] {\n\t\tconst state = this.readState();\n\t\tconst lines: string[] = [];\n\t\tconst colors = paletteFor(state.theme);\n\t\tfor (const [index, message] of state.messageItems.entries()) {\n\t\t\tif (index > 0) lines.push(\" \");\n\t\t\tif (message.role === \"user\") {\n\t\t\t\tlines.push(...renderLine(` ${paint(colors.accent, \"You\", true)}`, width));\n\t\t\t\tlines.push(...new Text(` ${message.text}`).render(width));\n\t\t\t} else {\n\t\t\t\tlines.push(...renderLine(` ${paint(colors.assistant, \"Assistant\", true)}`, width));\n\t\t\t\tlines.push(...new Markdown(message.text, { paddingX: 4 }).render(width));\n\t\t\t}\n\t\t}\n\t\tconst toolCount = state.processItems.filter((item) => item.type === \"tool\").length;\n\t\tconst hiddenToolItems = Math.max(0, toolCount - MAX_VISIBLE_TOOL_ITEMS);\n\t\tlet skippedToolItems = 0;\n\t\tfor (const item of state.processItems) {\n\t\t\tif (item.type === \"tool\" && skippedToolItems < hiddenToolItems) {\n\t\t\t\tskippedToolItems += 1;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (item.type === \"tool\" && skippedToolItems === hiddenToolItems && hiddenToolItems > 0) {\n\t\t\t\tlines.push(...renderLine(` ${paint(colors.dim, `${hiddenToolItems} earlier tool updates`)}`, width));\n\t\t\t\tskippedToolItems += 1;\n\t\t\t}\n\t\t\tif (item.type === \"thinking\") {\n\t\t\t\tconst frame = SPINNER_FRAMES[state.spinnerFrame % SPINNER_FRAMES.length] ?? SPINNER_FRAMES[0];\n\t\t\t\tlines.push(...renderLine(` ${paint(colors.accent, `${frame} Thinking`)}`, width));\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst marker = item.status === \"running\" ? \">\" : item.status === \"error\" ? \"!\" : \"+\";\n\t\t\tconst command = truncateToWidth(item.command, Math.max(1, width - 6), \"...\");\n\t\t\tconst color = item.status === \"error\" ? colors.error : item.status === \"done\" ? colors.success : colors.warning;\n\t\t\tlines.push(...renderLine(` ${paint(color, marker)} ${paint(colors.dim, command)}`, width));\n\t\t}\n\t\tif (state.busy && !state.processItems.some((item) => item.type === \"thinking\")) {\n\t\t\tconst frame = SPINNER_FRAMES[state.spinnerFrame % SPINNER_FRAMES.length] ?? SPINNER_FRAMES[0];\n\t\t\tlines.push(...renderLine(` ${paint(colors.accent, `${frame} Thinking`)}`, width));\n\t\t}\n\t\tif (state.streamingText) {\n\t\t\tif (lines.length > 0) lines.push(\" \");\n\t\t\tlines.push(...renderLine(` ${paint(colors.assistant, \"Assistant\", true)}`, width));\n\t\t\tlines.push(...new Markdown(state.streamingText, { paddingX: 4 }).render(width));\n\t\t}\n\t\tconst hasActivity = state.status || state.queue.length > 0 || state.error;\n\t\tif (hasActivity) {\n\t\t\tif (lines.length > 0) lines.push(\" \");\n\t\t\tlines.push(...renderLine(` ${paint(colors.dim, \"ACTIVITY\", true)}`, width));\n\t\t\tif (state.status) lines.push(...renderLine(` ${paint(colors.dim, state.status)}`, width));\n\t\t\tif (state.queue.length > 0) {\n\t\t\t\tlines.push(...renderLine(` ${paint(colors.dim, `Queue (${state.queue.length})`)}`, width));\n\t\t\t\tfor (const prompt of state.queue) lines.push(...new Text(` ${prompt}`).render(width));\n\t\t\t}\n\t\t\tif (state.error)\n\t\t\t\tlines.push(...new Text(` ${paint(colors.error, `Error: ${state.error}`, true)}`).render(width));\n\t\t}\n\t\tconst rendered = lines.flatMap((line) => new Text(line).render(width));\n\t\treturn rendered.length > 0 ? rendered : [\"\"];\n\t}\n}\n\nexport class InteractiveComposer implements Component {\n\tprivate readonly readState: () => InteractiveViewState;\n\n\tconstructor(readState: () => InteractiveViewState) {\n\t\tthis.readState = readState;\n\t}\n\n\tinvalidate(): void {}\n\n\trender(width: number): string[] {\n\t\tconst state = this.readState();\n\t\tconst colors = paletteFor(state.theme);\n\t\tconst copy = width >= 56 ? \"COMPOSE / commands Tab complete\" : \"COMPOSE / commands\";\n\t\treturn [\n\t\t\t...renderLine(paint(colors.dim, \"-\".repeat(Math.max(0, width))), width),\n\t\t\t...renderLine(paint(colors.dim, copy), width),\n\t\t];\n\t}\n}\n\nexport class InteractiveFooter implements Component {\n\tprivate readonly readState: () => InteractiveViewState;\n\n\tconstructor(readState: () => InteractiveViewState) {\n\t\tthis.readState = readState;\n\t}\n\n\tinvalidate(): void {}\n\n\trender(width: number): string[] {\n\t\tconst state = this.readState();\n\t\tconst colors = paletteFor(state.theme);\n\t\tconst activity = activityLabel(state);\n\t\tconst left = paint(activity.color, `* ${activity.text}`, true);\n\t\tconst context = paint(\n\t\t\tcolors.dim,\n\t\t\t`${state.messageItems.length} messages ctx ${formatTokenCount(state.usage.estimatedContextTokens)}/${formatTokenCount(state.usage.contextWindow)} total ${formatTokenCount(state.usage.totalTokens)} tok`,\n\t\t);\n\t\tconst right = paint(colors.dim, `${state.model} ${state.theme}`);\n\t\tconst status = width >= 60 ? alignEnds(`${left} ${context}`, right, width) : `${left} ${right}`;\n\t\tconst hints = width >= 60 ? \"Enter send Esc cancel Ctrl+O model Ctrl+L session\" : \"Enter send Ctrl+O model\";\n\t\treturn [\n\t\t\t...renderLine(paint(colors.dim, \"-\".repeat(Math.max(0, width))), width),\n\t\t\t...renderLine(status, width),\n\t\t\t...renderLine(paint(colors.dim, hints), width),\n\t\t];\n\t}\n}\n\nfunction formatTokenCount(value: number): string {\n\tif (value >= 1_000_000) return `${(value / 1_000_000).toFixed(1)}m`;\n\tif (value >= 1_000) return `${(value / 1_000).toFixed(1)}k`;\n\treturn String(value);\n}\n\nexport interface AutocompleteMenuState {\n\treadonly items: readonly AutocompleteItem[];\n\treadonly index: number;\n}\n\nexport class AutocompleteMenu implements Component {\n\tprivate readonly readState: () => AutocompleteMenuState;\n\n\tconstructor(readState: () => AutocompleteMenuState) {\n\t\tthis.readState = readState;\n\t}\n\n\tinvalidate(): void {}\n\n\trender(width: number): string[] {\n\t\tconst state = this.readState();\n\t\treturn state.items.slice(0, 6).flatMap((item, index) => {\n\t\t\tconst prefix = index === state.index ? \"> \" : \" \";\n\t\t\tconst description = item.description ? ` - ${item.description}` : \"\";\n\t\t\treturn new Text(`${prefix}${item.label}${description}`).render(width);\n\t\t});\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"interactive-components.js","sourceRoot":"","sources":["../../src/modes/interactive-components.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAClF,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAmBnD,MAAM,KAAK,GAAG,SAAS,CAAC;AACxB,MAAM,IAAI,GAAG,SAAS,CAAC;AACvB,MAAM,sBAAsB,GAAG,CAAC,CAAC;AACjC,MAAM,cAAc,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,CAAU,CAAC;AAEtD,SAAS,UAAU,CAAC,KAAoC;IACvD,OAAO,KAAK,KAAK,OAAO;QACvB,CAAC,CAAC;YACA,MAAM,EAAE,eAAe;YACvB,SAAS,EAAE,eAAe;YAC1B,GAAG,EAAE,gBAAgB;YACrB,KAAK,EAAE,gBAAgB;YACvB,OAAO,EAAE,eAAe;YACxB,cAAc,EAAE,wBAA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AAI,IAAI,CAAC,GAAG,MAAM,GAAG,IAAI,CAAC,KAAK,GAAG,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvE,CAAC,CAAC,CAAC;IACJ,CAAC;CACD","sourcesContent":["import type { AutocompleteItem, Component, MarkdownTheme } from \"@di-code/tui\";\nimport { Box, Markdown, Text, truncateToWidth, visibleWidth } from \"@di-code/tui\";\nimport { highlightCode } from \"../utils/syntax-highlight.ts\";\nimport { renderDiff } from \"./interactive-diff.ts\";\nimport type { InteractiveState } from \"./interactive-state.ts\";\n\nexport interface InteractiveViewState extends InteractiveState {\n\treadonly model: string;\n\treadonly theme: \"dark\" | \"light\";\n\treadonly pasteImageShortcut?: string;\n}\n\ninterface Palette {\n\treadonly accent: string;\n\treadonly assistant: string;\n\treadonly dim: string;\n\treadonly error: string;\n\treadonly success: string;\n\treadonly userBackground: string;\n\treadonly warning: string;\n}\n\nconst RESET = \"\\x1b[0m\";\nconst BOLD = \"\\x1b[1m\";\nconst MAX_VISIBLE_TOOL_ITEMS = 6;\nconst SPINNER_FRAMES = [\"|\", \"/\", \"-\", \"\\\\\"] as const;\n\nfunction paletteFor(theme: InteractiveViewState[\"theme\"]): Palette {\n\treturn theme === \"light\"\n\t\t? {\n\t\t\t\taccent: \"\\x1b[38;5;25m\",\n\t\t\t\tassistant: \"\\x1b[38;5;30m\",\n\t\t\t\tdim: \"\\x1b[38;5;242m\",\n\t\t\t\terror: \"\\x1b[38;5;160m\",\n\t\t\t\tsuccess: \"\\x1b[38;5;28m\",\n\t\t\t\tuserBackground: \"\\x1b[48;2;239;246;255m\",\n\t\t\t\twarning: \"\\x1b[38;5;130m\",\n\t\t\t}\n\t\t: {\n\t\t\t\taccent: \"\\x1b[38;5;45m\",\n\t\t\t\tassistant: \"\\x1b[38;5;80m\",\n\t\t\t\tdim: \"\\x1b[38;5;245m\",\n\t\t\t\terror: \"\\x1b[38;5;210m\",\n\t\t\t\tsuccess: \"\\x1b[38;5;114m\",\n\t\t\t\tuserBackground: \"\\x1b[48;2;31;39;50m\",\n\t\t\t\twarning: \"\\x1b[38;5;222m\",\n\t\t\t};\n}\n\nfunction paint(color: string, text: string, bold = false): string {\n\treturn `${color}${bold ? BOLD : \"\"}${text}${RESET}`;\n}\n\nfunction paintBackground(background: string, text: string): string {\n\treturn `${background}${text}${RESET}`;\n}\n\nfunction markdownThemeFor(colors: Palette): MarkdownTheme {\n\treturn {\n\t\theading: (text) => paint(colors.assistant, text, true),\n\t\tlink: (text) => paint(colors.accent, text),\n\t\tlinkUrl: (text) => paint(colors.dim, text),\n\t\tcode: (text) => paint(colors.warning, text),\n\t\tcodeBlock: (text) => paint(colors.assistant, text),\n\t\tcodeBlockBorder: (text) => paint(colors.dim, text),\n\t\tquote: (text) => paint(colors.dim, text),\n\t\tquoteBorder: (text) => paint(colors.dim, text),\n\t\thr: (text) => paint(colors.dim, text),\n\t\tlistBullet: (text) => paint(colors.accent, text),\n\t\tbold: (text) => paint(colors.assistant, text, true),\n\t\titalic: (text) => `\\x1b[3m${text}${RESET}`,\n\t\tstrikethrough: (text) => `\\x1b[9m${text}${RESET}`,\n\t\tunderline: (text) => `\\x1b[4m${text}${RESET}`,\n\t\thighlightCode: (code, language) =>\n\t\t\t(language ? highlightCode(code, language) : undefined) ??\n\t\t\tcode.split(\"\\n\").map((line) => paint(colors.assistant, line)),\n\t};\n}\n\nfunction renderLine(text: string, width: number): string[] {\n\treturn new Text(truncateToWidth(text, width, \"\")).render(width);\n}\n\nfunction alignEnds(left: string, right: string, width: number): string {\n\tconst gap = 3;\n\tif (visibleWidth(left) + visibleWidth(right) + gap > width) return truncateToWidth(left, width, \"\");\n\treturn `${left}${\" \".repeat(width - visibleWidth(left) - visibleWidth(right))}${right}`;\n}\n\nfunction activityLabel(state: InteractiveViewState): { readonly text: string; readonly color: string } {\n\tconst colors = paletteFor(state.theme);\n\tif (state.error) return { text: \"ERROR\", color: colors.error };\n\tif (state.compacting) return { text: \"COMPACTING\", color: colors.warning };\n\tif (state.retrying) return { text: \"RETRYING\", color: colors.warning };\n\tif (state.busy) return { text: \"WORKING\", color: colors.accent };\n\treturn { text: \"READY\", color: colors.success };\n}\n\nexport class InteractiveHeader implements Component {\n\tprivate readonly readState: () => InteractiveViewState;\n\n\tconstructor(readState: () => InteractiveViewState) {\n\t\tthis.readState = readState;\n\t}\n\n\tinvalidate(): void {}\n\n\trender(width: number): string[] {\n\t\tconst state = this.readState();\n\t\tconst colors = paletteFor(state.theme);\n\t\tconst brand = paint(colors.accent, \"DI-CODE / INTERACTIVE\", true);\n\t\tconst model = paint(colors.dim, `MODEL ${state.model}`);\n\t\tconst title =\n\t\t\twidth >= 56\n\t\t\t\t? alignEnds(brand, model, width)\n\t\t\t\t: `${paint(colors.accent, \"DI-CODE\", true)} ${paint(colors.dim, state.model)}`;\n\t\treturn [...renderLine(title, width), ...renderLine(paint(colors.dim, \"-\".repeat(Math.max(0, width))), width)];\n\t}\n}\n\nexport class InteractiveChat implements Component {\n\tprivate readonly readState: () => InteractiveViewState;\n\n\tconstructor(readState: () => InteractiveViewState) {\n\t\tthis.readState = readState;\n\t}\n\n\tinvalidate(): void {}\n\n\trender(width: number): string[] {\n\t\tconst state = this.readState();\n\t\tconst lines: string[] = [];\n\t\tconst colors = paletteFor(state.theme);\n\t\tconst markdownTheme = markdownThemeFor(colors);\n\t\tfor (const [index, message] of state.messageItems.entries()) {\n\t\t\tif (index > 0) lines.push(\" \");\n\t\t\tif (message.role === \"file_change\") {\n\t\t\t\tlines.push(\n\t\t\t\t\t...renderLine(\n\t\t\t\t\t\tpaint(colors.dim, `${message.kind === \"edit\" ? \"Edited\" : \"Wrote\"} ${message.path}`, true),\n\t\t\t\t\t\twidth,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\tif (message.diff) {\n\t\t\t\t\tfor (const line of renderDiff(message.diff, colors)) lines.push(...renderLine(line, width));\n\t\t\t\t} else {\n\t\t\t\t\tfor (const line of message.removed) lines.push(...renderLine(paint(colors.error, `- ${line}`), width));\n\t\t\t\t\tfor (const line of message.added) lines.push(...renderLine(paint(colors.success, `+ ${line}`), width));\n\t\t\t\t}\n\t\t\t} else if (message.role === \"user\") {\n\t\t\t\tlines.push(\n\t\t\t\t\t...new Text(message.text, 2, 1).render(width).map((line) => paintBackground(colors.userBackground, line)),\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tlines.push(...new Markdown(message.text, { paddingX: 2, theme: markdownTheme }).render(width));\n\t\t\t}\n\t\t}\n\t\tconst hasProcess = state.processItems.length > 0 || (state.busy && !state.streamingText);\n\t\tif (hasProcess && lines.length > 0) lines.push(\" \");\n\t\tconst toolCount = state.processItems.filter((item) => item.type === \"tool\").length;\n\t\tconst hiddenToolItems = Math.max(0, toolCount - MAX_VISIBLE_TOOL_ITEMS);\n\t\tlet skippedToolItems = 0;\n\t\tfor (const item of state.processItems) {\n\t\t\tif (item.type === \"tool\" && skippedToolItems < hiddenToolItems) {\n\t\t\t\tskippedToolItems += 1;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (item.type === \"tool\" && skippedToolItems === hiddenToolItems && hiddenToolItems > 0) {\n\t\t\t\tlines.push(...renderLine(` ${paint(colors.dim, `${hiddenToolItems} earlier tool updates`)}`, width));\n\t\t\t\tskippedToolItems += 1;\n\t\t\t}\n\t\t\tif (item.type === \"thinking\") {\n\t\t\t\tconst frame = SPINNER_FRAMES[state.spinnerFrame % SPINNER_FRAMES.length] ?? SPINNER_FRAMES[0];\n\t\t\t\tlines.push(...renderLine(` ${paint(colors.accent, `${frame} Thinking`)}`, width));\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst marker = item.status === \"running\" ? \">\" : item.status === \"error\" ? \"!\" : \"+\";\n\t\t\tconst command = truncateToWidth(item.command, Math.max(1, width - 6), \"...\");\n\t\t\tconst color = item.status === \"error\" ? colors.error : item.status === \"done\" ? colors.success : colors.warning;\n\t\t\tlines.push(...renderLine(` ${paint(color, marker)} ${paint(colors.dim, command)}`, width));\n\t\t}\n\t\tif (state.busy && !state.streamingText && !state.processItems.some((item) => item.type === \"thinking\")) {\n\t\t\tconst frame = SPINNER_FRAMES[state.spinnerFrame % SPINNER_FRAMES.length] ?? SPINNER_FRAMES[0];\n\t\t\tlines.push(...renderLine(` ${paint(colors.accent, `${frame} Thinking`)}`, width));\n\t\t}\n\t\tif (hasProcess) lines.push(\" \");\n\t\tif (state.streamingText) {\n\t\t\tif (lines.length > 0 && lines.at(-1) !== \" \") lines.push(\" \");\n\t\t\tlines.push(...new Markdown(state.streamingText, { paddingX: 2, theme: markdownTheme }).render(width));\n\t\t}\n\t\tconst hasActivity = state.status || state.queue.length > 0 || state.error;\n\t\tif (hasActivity) {\n\t\t\tif (lines.length > 0) lines.push(\" \");\n\t\t\tlines.push(...renderLine(paint(colors.dim, \"Activity\", true), width));\n\t\t\tif (state.status) lines.push(...renderLine(` ${paint(colors.dim, state.status)}`, width));\n\t\t\tif (state.queue.length > 0) {\n\t\t\t\tlines.push(...renderLine(` ${paint(colors.dim, `Queue (${state.queue.length})`)}`, width));\n\t\t\t\tfor (const prompt of state.queue) lines.push(...new Text(` ${prompt}`).render(width));\n\t\t\t}\n\t\t\tif (state.error)\n\t\t\t\tlines.push(...new Text(` ${paint(colors.error, `Error: ${state.error}`, true)}`).render(width));\n\t\t}\n\t\tconst rendered = lines.flatMap((line) => new Text(line).render(width));\n\t\treturn rendered.length > 0 ? rendered : [\"\"];\n\t}\n}\n\nexport class InteractiveComposer implements Component {\n\tprivate readonly readState: () => InteractiveViewState;\n\n\tconstructor(readState: () => InteractiveViewState) {\n\t\tthis.readState = readState;\n\t}\n\n\tinvalidate(): void {}\n\n\trender(width: number): string[] {\n\t\tconst state = this.readState();\n\t\tconst colors = paletteFor(state.theme);\n\t\tconst copy = width >= 56 ? \"/ commands Tab complete\" : \"/ commands\";\n\t\treturn renderLine(paint(colors.dim, copy), width);\n\t}\n}\n\nexport class InteractiveFooter implements Component {\n\tprivate readonly readState: () => InteractiveViewState;\n\n\tconstructor(readState: () => InteractiveViewState) {\n\t\tthis.readState = readState;\n\t}\n\n\tinvalidate(): void {}\n\n\trender(width: number): string[] {\n\t\tconst state = this.readState();\n\t\tconst colors = paletteFor(state.theme);\n\t\tconst activity = activityLabel(state);\n\t\tconst left = paint(activity.color, `* ${activity.text}`, true);\n\t\tconst context = paint(\n\t\t\tcolors.dim,\n\t\t\t`${state.messageItems.length} messages ctx ${formatTokenCount(state.usage.estimatedContextTokens)}/${formatTokenCount(state.usage.contextWindow)} total ${formatTokenCount(state.usage.totalTokens)} tok`,\n\t\t);\n\t\tconst right = paint(colors.dim, `${state.model} ${state.theme}`);\n\t\tconst status = width >= 60 ? alignEnds(`${left} ${context}`, right, width) : `${left} ${right}`;\n\t\tconst pasteImageShortcut = state.pasteImageShortcut ?? (process.platform === \"win32\" ? \"Alt+V\" : \"Ctrl+V\");\n\t\tconst hints =\n\t\t\twidth >= 60\n\t\t\t\t? `Enter send ${pasteImageShortcut} paste image Shift+Tab thinking Esc cancel Ctrl+O model`\n\t\t\t\t: `Enter send ${pasteImageShortcut} image`;\n\t\treturn [...renderLine(status, width), ...renderLine(paint(colors.dim, hints), width)];\n\t}\n}\n\nfunction formatTokenCount(value: number): string {\n\tif (value >= 1_000_000) return `${(value / 1_000_000).toFixed(1)}m`;\n\tif (value >= 1_000) return `${(value / 1_000).toFixed(1)}k`;\n\treturn String(value);\n}\n\nexport interface AutocompleteMenuState {\n\treadonly items: readonly AutocompleteItem[];\n\treadonly index: number;\n}\n\nexport class AutocompleteMenu implements Component {\n\tprivate readonly readState: () => AutocompleteMenuState;\n\tprivate readonly box: Box;\n\n\tconstructor(readState: () => AutocompleteMenuState) {\n\t\tthis.readState = readState;\n\t\tthis.box = new Box(\n\t\t\t{\n\t\t\t\tinvalidate: () => {},\n\t\t\t\trender: (width) => this.renderItems(width),\n\t\t\t},\n\t\t\t{ border: \"rounded\", padding: 1, title: \"Suggestions\" },\n\t\t);\n\t}\n\n\tinvalidate(): void {\n\t\tthis.box.invalidate();\n\t}\n\n\trender(width: number): string[] {\n\t\treturn this.box.render(width);\n\t}\n\n\tprivate renderItems(width: number): string[] {\n\t\tconst state = this.readState();\n\t\tconst maxVisible = 6;\n\t\tconst start = Math.min(\n\t\t\tMath.max(0, state.index - Math.floor(maxVisible / 2)),\n\t\t\tMath.max(0, state.items.length - maxVisible),\n\t\t);\n\t\treturn state.items.slice(start, start + maxVisible).flatMap((item, offset) => {\n\t\t\tconst prefix = start + offset === state.index ? \"> \" : \" \";\n\t\t\tconst description = item.description ? ` - ${item.description}` : \"\";\n\t\t\treturn new Text(`${prefix}${item.label}${description}`).render(width);\n\t\t});\n\t}\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface DiffColors {
|
|
2
|
+
readonly dim: string;
|
|
3
|
+
readonly error: string;
|
|
4
|
+
readonly success: string;
|
|
5
|
+
}
|
|
6
|
+
/** 将 edit-diff 的行号格式转换成 Pi 风格的 ANSI 着色行。 */
|
|
7
|
+
export declare function renderDiff(diffText: string, colors: DiffColors): string[];
|
|
8
|
+
//# sourceMappingURL=interactive-diff.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interactive-diff.d.ts","sourceRoot":"","sources":["../../src/modes/interactive-diff.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,UAAU;IAC1B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CACzB;AAiCD,4CAA4C;AAC5C,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAG,MAAM,EAAE,CA0CzE"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import * as Diff from "diff";
|
|
2
|
+
const RESET = "\x1b[0m";
|
|
3
|
+
const INVERSE = "\x1b[7m";
|
|
4
|
+
function paint(color, text, inverse = false) {
|
|
5
|
+
return `${color}${inverse ? INVERSE : ""}${text}${RESET}`;
|
|
6
|
+
}
|
|
7
|
+
function parseLine(line) {
|
|
8
|
+
const match = line.match(/^([+-\s])(\s*\d*)\s(.*)$/);
|
|
9
|
+
return match ? { prefix: match[1], lineNumber: match[2], content: match[3] } : undefined;
|
|
10
|
+
}
|
|
11
|
+
function renderWordChange(oldContent, newContent) {
|
|
12
|
+
const parts = Diff.diffWords(oldContent, newContent);
|
|
13
|
+
let oldLine = "";
|
|
14
|
+
let newLine = "";
|
|
15
|
+
for (const part of parts) {
|
|
16
|
+
if (part.removed)
|
|
17
|
+
oldLine += paint("", part.value, true);
|
|
18
|
+
else if (part.added)
|
|
19
|
+
newLine += paint("", part.value, true);
|
|
20
|
+
else {
|
|
21
|
+
oldLine += part.value;
|
|
22
|
+
newLine += part.value;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return { oldLine, newLine };
|
|
26
|
+
}
|
|
27
|
+
function replaceTabs(text) {
|
|
28
|
+
return text.replaceAll("\t", " ");
|
|
29
|
+
}
|
|
30
|
+
/** 将 edit-diff 的行号格式转换成 Pi 风格的 ANSI 着色行。 */
|
|
31
|
+
export function renderDiff(diffText, colors) {
|
|
32
|
+
const source = diffText.split("\n");
|
|
33
|
+
const result = [];
|
|
34
|
+
let index = 0;
|
|
35
|
+
while (index < source.length) {
|
|
36
|
+
const current = parseLine(source[index]);
|
|
37
|
+
if (!current) {
|
|
38
|
+
result.push(paint(colors.dim, source[index]));
|
|
39
|
+
index += 1;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (current.prefix !== "-") {
|
|
43
|
+
const color = current.prefix === "+" ? colors.success : colors.dim;
|
|
44
|
+
result.push(paint(color, `${current.prefix}${current.lineNumber} ${replaceTabs(current.content)}`));
|
|
45
|
+
index += 1;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const removed = [];
|
|
49
|
+
while (index < source.length) {
|
|
50
|
+
const line = parseLine(source[index]);
|
|
51
|
+
if (!line || line.prefix !== "-")
|
|
52
|
+
break;
|
|
53
|
+
removed.push({ lineNumber: line.lineNumber, content: line.content });
|
|
54
|
+
index += 1;
|
|
55
|
+
}
|
|
56
|
+
const added = [];
|
|
57
|
+
while (index < source.length) {
|
|
58
|
+
const line = parseLine(source[index]);
|
|
59
|
+
if (!line || line.prefix !== "+")
|
|
60
|
+
break;
|
|
61
|
+
added.push({ lineNumber: line.lineNumber, content: line.content });
|
|
62
|
+
index += 1;
|
|
63
|
+
}
|
|
64
|
+
if (removed.length === 1 && added.length === 1) {
|
|
65
|
+
const changed = renderWordChange(replaceTabs(removed[0].content), replaceTabs(added[0].content));
|
|
66
|
+
result.push(paint(colors.error, `-${removed[0].lineNumber} ${changed.oldLine}`));
|
|
67
|
+
result.push(paint(colors.success, `+${added[0].lineNumber} ${changed.newLine}`));
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
for (const line of removed)
|
|
71
|
+
result.push(paint(colors.error, `-${line.lineNumber} ${replaceTabs(line.content)}`));
|
|
72
|
+
for (const line of added)
|
|
73
|
+
result.push(paint(colors.success, `+${line.lineNumber} ${replaceTabs(line.content)}`));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=interactive-diff.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interactive-diff.js","sourceRoot":"","sources":["../../src/modes/interactive-diff.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAQ7B,MAAM,KAAK,GAAG,SAAS,CAAC;AACxB,MAAM,OAAO,GAAG,SAAS,CAAC;AAE1B,SAAS,KAAK,CAAC,KAAa,EAAE,IAAY,EAAE,OAAO,GAAG,KAAK;IAC1D,OAAO,GAAG,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,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AI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,IAAI,CAAC,UAAU,IAAI,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;QAClH,CAAC;IACF,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["import * as Diff from \"diff\";\n\nexport interface DiffColors {\n\treadonly dim: string;\n\treadonly error: string;\n\treadonly success: string;\n}\n\nconst RESET = \"\\x1b[0m\";\nconst INVERSE = \"\\x1b[7m\";\n\nfunction paint(color: string, text: string, inverse = false): string {\n\treturn `${color}${inverse ? INVERSE : \"\"}${text}${RESET}`;\n}\n\nfunction parseLine(line: string): { prefix: string; lineNumber: string; content: string } | undefined {\n\tconst match = line.match(/^([+-\\s])(\\s*\\d*)\\s(.*)$/);\n\treturn match ? { prefix: match[1], lineNumber: match[2], content: match[3] } : undefined;\n}\n\nfunction renderWordChange(oldContent: string, newContent: string): { oldLine: string; newLine: string } {\n\tconst parts = Diff.diffWords(oldContent, newContent);\n\tlet oldLine = \"\";\n\tlet newLine = \"\";\n\tfor (const part of parts) {\n\t\tif (part.removed) oldLine += paint(\"\", part.value, true);\n\t\telse if (part.added) newLine += paint(\"\", part.value, true);\n\t\telse {\n\t\t\toldLine += part.value;\n\t\t\tnewLine += part.value;\n\t\t}\n\t}\n\treturn { oldLine, newLine };\n}\n\nfunction replaceTabs(text: string): string {\n\treturn text.replaceAll(\"\\t\", \" \");\n}\n\n/** 将 edit-diff 的行号格式转换成 Pi 风格的 ANSI 着色行。 */\nexport function renderDiff(diffText: string, colors: DiffColors): string[] {\n\tconst source = diffText.split(\"\\n\");\n\tconst result: string[] = [];\n\tlet index = 0;\n\twhile (index < source.length) {\n\t\tconst current = parseLine(source[index]);\n\t\tif (!current) {\n\t\t\tresult.push(paint(colors.dim, source[index]));\n\t\t\tindex += 1;\n\t\t\tcontinue;\n\t\t}\n\t\tif (current.prefix !== \"-\") {\n\t\t\tconst color = current.prefix === \"+\" ? colors.success : colors.dim;\n\t\t\tresult.push(paint(color, `${current.prefix}${current.lineNumber} ${replaceTabs(current.content)}`));\n\t\t\tindex += 1;\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst removed: Array<{ lineNumber: string; content: string }> = [];\n\t\twhile (index < source.length) {\n\t\t\tconst line = parseLine(source[index]);\n\t\t\tif (!line || line.prefix !== \"-\") break;\n\t\t\tremoved.push({ lineNumber: line.lineNumber, content: line.content });\n\t\t\tindex += 1;\n\t\t}\n\t\tconst added: Array<{ lineNumber: string; content: string }> = [];\n\t\twhile (index < source.length) {\n\t\t\tconst line = parseLine(source[index]);\n\t\t\tif (!line || line.prefix !== \"+\") break;\n\t\t\tadded.push({ lineNumber: line.lineNumber, content: line.content });\n\t\t\tindex += 1;\n\t\t}\n\t\tif (removed.length === 1 && added.length === 1) {\n\t\t\tconst changed = renderWordChange(replaceTabs(removed[0].content), replaceTabs(added[0].content));\n\t\t\tresult.push(paint(colors.error, `-${removed[0].lineNumber} ${changed.oldLine}`));\n\t\t\tresult.push(paint(colors.success, `+${added[0].lineNumber} ${changed.newLine}`));\n\t\t} else {\n\t\t\tfor (const line of removed) result.push(paint(colors.error, `-${line.lineNumber} ${replaceTabs(line.content)}`));\n\t\t\tfor (const line of added) result.push(paint(colors.success, `+${line.lineNumber} ${replaceTabs(line.content)}`));\n\t\t}\n\t}\n\treturn result;\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Component } from "@di-code/tui";
|
|
2
2
|
export interface InteractiveLayoutOptions {
|
|
3
3
|
readonly header: Component;
|
|
4
4
|
readonly chat: Component;
|
|
@@ -15,6 +15,11 @@ export declare class InteractiveLayout implements Component {
|
|
|
15
15
|
constructor(options: InteractiveLayoutOptions);
|
|
16
16
|
invalidate(): void;
|
|
17
17
|
renderTranscript(width: number): string[];
|
|
18
|
+
getEditorBounds(width: number): {
|
|
19
|
+
readonly start: number;
|
|
20
|
+
readonly end: number;
|
|
21
|
+
};
|
|
18
22
|
render(width: number): string[];
|
|
23
|
+
private renderEditor;
|
|
19
24
|
}
|
|
20
25
|
//# sourceMappingURL=interactive-layout.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interactive-layout.d.ts","sourceRoot":"","sources":["../../src/modes/interactive-layout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"interactive-layout.d.ts","sourceRoot":"","sources":["../../src/modes/interactive-layout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAiC,MAAM,cAAc,CAAC;AAE7E,MAAM,WAAW,wBAAwB;IACxC,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;CAC3B;AAED,qBAAa,iBAAkB,YAAW,SAAS;IAClD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAY;IACnC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAY;IACjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAY;IACrC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAY;IACnC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAY;gBACvB,OAAO,EAAE,wBAAwB;IAQ7C,UAAU,IAAI,IAAI;IAQlB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE;IAIzC,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG;QAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;KAAE;IAMhF,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE;IAU/B,OAAO,CAAC,YAAY;CAapB"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { truncateToWidth, visibleWidth } from "@di-code/tui";
|
|
1
2
|
export class InteractiveLayout {
|
|
2
3
|
header;
|
|
3
4
|
chat;
|
|
@@ -21,14 +22,33 @@ export class InteractiveLayout {
|
|
|
21
22
|
renderTranscript(width) {
|
|
22
23
|
return [...this.header.render(width), ...this.chat.render(width), ...this.footer.render(width)];
|
|
23
24
|
}
|
|
25
|
+
getEditorBounds(width) {
|
|
26
|
+
const start = this.header.render(width).length + this.chat.render(width).length + this.composer.render(width).length;
|
|
27
|
+
return { start, end: start + this.renderEditor(width).length };
|
|
28
|
+
}
|
|
24
29
|
render(width) {
|
|
25
30
|
return [
|
|
26
31
|
...this.header.render(width),
|
|
27
32
|
...this.chat.render(width),
|
|
28
33
|
...this.composer.render(width),
|
|
29
|
-
...this.
|
|
34
|
+
...this.renderEditor(width),
|
|
30
35
|
...this.footer.render(width),
|
|
31
36
|
];
|
|
32
37
|
}
|
|
38
|
+
renderEditor(width) {
|
|
39
|
+
if (width <= 0)
|
|
40
|
+
return [];
|
|
41
|
+
if (width < 3)
|
|
42
|
+
return this.editor.render(width).map((line) => truncateToWidth(line, width, ""));
|
|
43
|
+
const innerWidth = width - 2;
|
|
44
|
+
const title = " Compose ";
|
|
45
|
+
const top = `┌${title}${"─".repeat(Math.max(0, innerWidth - visibleWidth(title)))}┐`;
|
|
46
|
+
const content = this.editor.render(innerWidth).map((line) => {
|
|
47
|
+
const clipped = truncateToWidth(line, innerWidth, "", true);
|
|
48
|
+
return `│${clipped}${" ".repeat(Math.max(0, innerWidth - visibleWidth(clipped)))}│`;
|
|
49
|
+
});
|
|
50
|
+
const bottom = `└${"─".repeat(innerWidth)}┘`;
|
|
51
|
+
return [top, ...content, bottom];
|
|
52
|
+
}
|
|
33
53
|
}
|
|
34
54
|
//# sourceMappingURL=interactive-layout.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interactive-layout.js","sourceRoot":"","sources":["../../src/modes/interactive-layout.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"interactive-layout.js","sourceRoot":"","sources":["../../src/modes/interactive-layout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,eAAe,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAU7E,MAAM,OAAO,iBAAiB;IACZ,MAAM,CAAY;IAClB,IAAI,CAAY;IAChB,QAAQ,CAAY;IACpB,MAAM,CAAY;IAClB,MAAM,CAAY;IACnC,YAAY,OAAiC;QAC5C,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QACzB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAC9B,CAAC;IAED,UAAU;QACT,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;QACzB,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;QACvB,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;QAC3B,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;QACzB,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;IAC1B,CAAC;IAED,gBAAgB,CAAC,KAAa;QAC7B,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACjG,CAAC;IAED,eAAe,CAAC,KAAa;QAC5B,MAAM,KAAK,GACV,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAA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CAAC,CAAC,IAAI,EAAE,EAAE;YAC3D,MAAM,OAAO,GAAG,eAAe,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC;YAC5D,OAAO,IAAI,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,UAAU,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC;QACrF,CAAC,CAAC,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC;QAC7C,OAAO,CAAC,GAAG,EAAE,GAAG,OAAO,EAAE,MAAM,CAAC,CAAC;IAClC,CAAC;CACD","sourcesContent":["import { type Component, truncateToWidth, visibleWidth } from \"@di-code/tui\";\n\nexport interface InteractiveLayoutOptions {\n\treadonly header: Component;\n\treadonly chat: Component;\n\treadonly composer: Component;\n\treadonly editor: Component;\n\treadonly footer: Component;\n}\n\nexport class InteractiveLayout implements Component {\n\tprivate readonly header: Component;\n\tprivate readonly chat: Component;\n\tprivate readonly composer: Component;\n\tprivate readonly editor: Component;\n\tprivate readonly footer: Component;\n\tconstructor(options: InteractiveLayoutOptions) {\n\t\tthis.header = options.header;\n\t\tthis.chat = options.chat;\n\t\tthis.composer = options.composer;\n\t\tthis.editor = options.editor;\n\t\tthis.footer = options.footer;\n\t}\n\n\tinvalidate(): void {\n\t\tthis.header.invalidate();\n\t\tthis.chat.invalidate();\n\t\tthis.composer.invalidate();\n\t\tthis.editor.invalidate();\n\t\tthis.footer.invalidate();\n\t}\n\n\trenderTranscript(width: number): string[] {\n\t\treturn [...this.header.render(width), ...this.chat.render(width), ...this.footer.render(width)];\n\t}\n\n\tgetEditorBounds(width: number): { readonly start: number; readonly end: number } {\n\t\tconst start =\n\t\t\tthis.header.render(width).length + this.chat.render(width).length + this.composer.render(width).length;\n\t\treturn { start, end: start + this.renderEditor(width).length };\n\t}\n\n\trender(width: number): string[] {\n\t\treturn [\n\t\t\t...this.header.render(width),\n\t\t\t...this.chat.render(width),\n\t\t\t...this.composer.render(width),\n\t\t\t...this.renderEditor(width),\n\t\t\t...this.footer.render(width),\n\t\t];\n\t}\n\n\tprivate renderEditor(width: number): string[] {\n\t\tif (width <= 0) return [];\n\t\tif (width < 3) return this.editor.render(width).map((line) => truncateToWidth(line, width, \"\"));\n\t\tconst innerWidth = width - 2;\n\t\tconst title = \" Compose \";\n\t\tconst top = `┌${title}${\"─\".repeat(Math.max(0, innerWidth - visibleWidth(title)))}┐`;\n\t\tconst content = this.editor.render(innerWidth).map((line) => {\n\t\t\tconst clipped = truncateToWidth(line, innerWidth, \"\", true);\n\t\t\treturn `│${clipped}${\" \".repeat(Math.max(0, innerWidth - visibleWidth(clipped)))}│`;\n\t\t});\n\t\tconst bottom = `└${\"─\".repeat(innerWidth)}┘`;\n\t\treturn [top, ...content, bottom];\n\t}\n}\n"]}
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import type { Message } from "@di-code/ai";
|
|
2
2
|
import type { AgentSessionEvent, SessionUsage } from "../core/session.ts";
|
|
3
|
-
export
|
|
3
|
+
export type InteractiveMessage = {
|
|
4
4
|
readonly role: "user" | "assistant";
|
|
5
5
|
readonly text: string;
|
|
6
|
-
}
|
|
6
|
+
} | {
|
|
7
|
+
readonly role: "file_change";
|
|
8
|
+
readonly id: string;
|
|
9
|
+
readonly path: string;
|
|
10
|
+
readonly kind: "edit" | "write";
|
|
11
|
+
readonly removed: readonly string[];
|
|
12
|
+
readonly added: readonly string[];
|
|
13
|
+
readonly diff?: string;
|
|
14
|
+
readonly firstChangedLine?: number;
|
|
15
|
+
};
|
|
7
16
|
export type InteractiveProcessItem = {
|
|
8
17
|
readonly type: "thinking";
|
|
9
18
|
readonly id: "thinking";
|
|
@@ -31,6 +40,7 @@ export interface InteractiveState {
|
|
|
31
40
|
export declare class InteractiveProjection {
|
|
32
41
|
private readonly messages;
|
|
33
42
|
private readonly messageItems;
|
|
43
|
+
private readonly pendingFileChanges;
|
|
34
44
|
private readonly processItems;
|
|
35
45
|
private readonly toolStatus;
|
|
36
46
|
private spinnerFrame;
|
|
@@ -41,6 +51,8 @@ export declare class InteractiveProjection {
|
|
|
41
51
|
private status;
|
|
42
52
|
private compacting;
|
|
43
53
|
private retrying;
|
|
54
|
+
private previewRoot;
|
|
55
|
+
private previewChange;
|
|
44
56
|
private usage;
|
|
45
57
|
get state(): InteractiveState;
|
|
46
58
|
setError(message: string | undefined): void;
|
|
@@ -50,6 +62,7 @@ export declare class InteractiveProjection {
|
|
|
50
62
|
setCompacting(value: boolean): void;
|
|
51
63
|
setRetrying(value: boolean): void;
|
|
52
64
|
setUsage(usage: SessionUsage): void;
|
|
65
|
+
configureFilePreview(root: string, onChange: () => void): void;
|
|
53
66
|
advanceSpinner(): boolean;
|
|
54
67
|
clearTransientProcess(): void;
|
|
55
68
|
replaceTranscript(messages: readonly Message[]): void;
|
|
@@ -57,5 +70,7 @@ export declare class InteractiveProjection {
|
|
|
57
70
|
private removeThinking;
|
|
58
71
|
private updateToolStatus;
|
|
59
72
|
private appendCompletedMessage;
|
|
73
|
+
private storeFileChange;
|
|
74
|
+
private commitFileChange;
|
|
60
75
|
}
|
|
61
76
|
//# sourceMappingURL=interactive-state.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interactive-state.d.ts","sourceRoot":"","sources":["../../src/modes/interactive-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"interactive-state.d.ts","sourceRoot":"","sources":["../../src/modes/interactive-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,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AAK,EAAE,OAAO,GAAG,IAAI;IAInC,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI;IAIjC,QAAQ,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI;IAInC,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI;IAK9D,cAAc,IAAI,OAAO;IAMzB,qBAAqB,IAAI,IAAI;IAM7B,iBAAiB,CAAC,QAAQ,EAAE,SAAS,OAAO,EAAE,GAAG,IAAI;IAarD,KAAK,CAAC,KAAK,EAAE,iBAAiB,GAAG,IAAI;IAsErC,OAAO,CAAC,cAAc;IAKtB,OAAO,CAAC,gBAAgB;IAOxB,OAAO,CAAC,sBAAsB;IAwB9B,OAAO,CAAC,eAAe;IA2CvB,OAAO,CAAC,gBAAgB;CASxB"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { computeEditsDiff } from "../core/tools/edit-diff.js";
|
|
1
2
|
function textOf(message) {
|
|
2
3
|
return message.content
|
|
3
4
|
.filter((content) => content.type === "text")
|
|
@@ -7,6 +8,7 @@ function textOf(message) {
|
|
|
7
8
|
export class InteractiveProjection {
|
|
8
9
|
messages = [];
|
|
9
10
|
messageItems = [];
|
|
11
|
+
pendingFileChanges = new Map();
|
|
10
12
|
processItems = [];
|
|
11
13
|
toolStatus = new Map();
|
|
12
14
|
spinnerFrame = 0;
|
|
@@ -17,6 +19,8 @@ export class InteractiveProjection {
|
|
|
17
19
|
status;
|
|
18
20
|
compacting = false;
|
|
19
21
|
retrying = false;
|
|
22
|
+
previewRoot;
|
|
23
|
+
previewChange;
|
|
20
24
|
usage = {
|
|
21
25
|
requestCount: 0,
|
|
22
26
|
inputTokens: 0,
|
|
@@ -31,9 +35,12 @@ export class InteractiveProjection {
|
|
|
31
35
|
triggerTokens: 0,
|
|
32
36
|
};
|
|
33
37
|
get state() {
|
|
38
|
+
const visibleMessageItems = [...this.messageItems, ...this.pendingFileChanges.values()];
|
|
34
39
|
return {
|
|
35
40
|
messages: [...this.messages],
|
|
36
|
-
messageItems:
|
|
41
|
+
messageItems: visibleMessageItems.map((message) => message.role === "file_change"
|
|
42
|
+
? { ...message, removed: [...message.removed], added: [...message.added] }
|
|
43
|
+
: { ...message }),
|
|
37
44
|
processItems: this.processItems.map((item) => ({ ...item })),
|
|
38
45
|
spinnerFrame: this.spinnerFrame,
|
|
39
46
|
streamingText: this.streamingText,
|
|
@@ -53,6 +60,7 @@ export class InteractiveProjection {
|
|
|
53
60
|
clearVisibleMessages() {
|
|
54
61
|
this.messages.length = 0;
|
|
55
62
|
this.messageItems.length = 0;
|
|
63
|
+
this.pendingFileChanges.clear();
|
|
56
64
|
this.streamingText = "";
|
|
57
65
|
this.processItems.length = 0;
|
|
58
66
|
this.toolStatus.clear();
|
|
@@ -73,6 +81,10 @@ export class InteractiveProjection {
|
|
|
73
81
|
setUsage(usage) {
|
|
74
82
|
this.usage = structuredClone(usage);
|
|
75
83
|
}
|
|
84
|
+
configureFilePreview(root, onChange) {
|
|
85
|
+
this.previewRoot = root;
|
|
86
|
+
this.previewChange = onChange;
|
|
87
|
+
}
|
|
76
88
|
advanceSpinner() {
|
|
77
89
|
if (!this.busy)
|
|
78
90
|
return false;
|
|
@@ -87,6 +99,7 @@ export class InteractiveProjection {
|
|
|
87
99
|
replaceTranscript(messages) {
|
|
88
100
|
this.messages.length = 0;
|
|
89
101
|
this.messageItems.length = 0;
|
|
102
|
+
this.pendingFileChanges.clear();
|
|
90
103
|
this.processItems.length = 0;
|
|
91
104
|
this.toolStatus.clear();
|
|
92
105
|
this.spinnerFrame = 0;
|
|
@@ -118,13 +131,16 @@ export class InteractiveProjection {
|
|
|
118
131
|
case "usage_update":
|
|
119
132
|
this.setUsage(event.usage);
|
|
120
133
|
return;
|
|
134
|
+
case "queue_update":
|
|
135
|
+
return;
|
|
121
136
|
case "message_start":
|
|
122
137
|
if (event.message.role === "assistant")
|
|
123
138
|
this.streamingText = "";
|
|
124
139
|
return;
|
|
125
140
|
case "message_update":
|
|
126
141
|
if (event.event.type === "text_delta") {
|
|
127
|
-
|
|
142
|
+
if (event.event.delta.length > 0)
|
|
143
|
+
this.removeThinking();
|
|
128
144
|
this.streamingText += event.event.delta;
|
|
129
145
|
}
|
|
130
146
|
return;
|
|
@@ -137,10 +153,12 @@ export class InteractiveProjection {
|
|
|
137
153
|
status: "running",
|
|
138
154
|
});
|
|
139
155
|
this.toolStatus.set(event.toolCallId, `${event.toolName}: running`);
|
|
156
|
+
this.storeFileChange(event.toolCallId, event.toolName, event.arguments);
|
|
140
157
|
return;
|
|
141
158
|
case "tool_execution_end":
|
|
142
159
|
this.updateToolStatus(event.toolCallId, event.result.isError ? "error" : "done");
|
|
143
160
|
this.toolStatus.set(event.toolCallId, `${event.toolName}: ${event.result.isError ? "error" : "done"}`);
|
|
161
|
+
this.commitFileChange(event.toolCallId, event.result.isError, event.result.details);
|
|
144
162
|
return;
|
|
145
163
|
case "message_end":
|
|
146
164
|
this.appendCompletedMessage(event.message);
|
|
@@ -148,6 +166,7 @@ export class InteractiveProjection {
|
|
|
148
166
|
case "agent_end":
|
|
149
167
|
this.busy = false;
|
|
150
168
|
this.retrying = false;
|
|
169
|
+
this.pendingFileChanges.clear();
|
|
151
170
|
this.processItems.length = 0;
|
|
152
171
|
this.toolStatus.clear();
|
|
153
172
|
this.spinnerFrame = 0;
|
|
@@ -175,8 +194,10 @@ export class InteractiveProjection {
|
|
|
175
194
|
this.processItems[index] = { ...item, status };
|
|
176
195
|
}
|
|
177
196
|
appendCompletedMessage(message) {
|
|
178
|
-
if (message.role === "tool_result")
|
|
197
|
+
if (message.role === "tool_result") {
|
|
198
|
+
this.commitFileChange(message.toolCallId, message.isError, message.details);
|
|
179
199
|
return;
|
|
200
|
+
}
|
|
180
201
|
const text = textOf(message);
|
|
181
202
|
if (message.role === "user") {
|
|
182
203
|
if (text.length > 0) {
|
|
@@ -189,10 +210,89 @@ export class InteractiveProjection {
|
|
|
189
210
|
this.messages.push(text);
|
|
190
211
|
this.messageItems.push({ role: "assistant", text });
|
|
191
212
|
}
|
|
213
|
+
for (const content of message.content) {
|
|
214
|
+
if (content.type === "tool_call")
|
|
215
|
+
this.storeFileChange(content.id, content.name, content.arguments);
|
|
216
|
+
}
|
|
192
217
|
if (message.stopReason === "error" || message.stopReason === "aborted")
|
|
193
218
|
this.error = message.errorMessage;
|
|
194
219
|
this.streamingText = "";
|
|
195
220
|
}
|
|
221
|
+
storeFileChange(id, toolName, argumentsValue) {
|
|
222
|
+
const path = argumentsValue.path;
|
|
223
|
+
if (typeof path !== "string")
|
|
224
|
+
return;
|
|
225
|
+
if (toolName === "edit") {
|
|
226
|
+
const edits = parseEditArguments(argumentsValue);
|
|
227
|
+
if (!edits)
|
|
228
|
+
return;
|
|
229
|
+
const fallback = edits.flatMap((edit) => ({
|
|
230
|
+
removed: edit.oldText.replaceAll("\r\n", "\n").split("\n"),
|
|
231
|
+
added: edit.newText.replaceAll("\r\n", "\n").split("\n"),
|
|
232
|
+
}));
|
|
233
|
+
this.pendingFileChanges.set(id, {
|
|
234
|
+
role: "file_change",
|
|
235
|
+
id,
|
|
236
|
+
path,
|
|
237
|
+
kind: "edit",
|
|
238
|
+
removed: fallback.flatMap((edit) => edit.removed),
|
|
239
|
+
added: fallback.flatMap((edit) => edit.added),
|
|
240
|
+
});
|
|
241
|
+
if (this.previewRoot) {
|
|
242
|
+
void computeEditsDiff(path, edits, this.previewRoot).then((preview) => {
|
|
243
|
+
const current = this.pendingFileChanges.get(id);
|
|
244
|
+
if (!current || "error" in preview)
|
|
245
|
+
return;
|
|
246
|
+
this.pendingFileChanges.set(id, {
|
|
247
|
+
...current,
|
|
248
|
+
diff: preview.diff,
|
|
249
|
+
firstChangedLine: preview.firstChangedLine,
|
|
250
|
+
});
|
|
251
|
+
this.previewChange?.();
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
if (toolName === "write" && typeof argumentsValue.content === "string") {
|
|
256
|
+
this.pendingFileChanges.set(id, {
|
|
257
|
+
role: "file_change",
|
|
258
|
+
id,
|
|
259
|
+
path,
|
|
260
|
+
kind: "write",
|
|
261
|
+
removed: [],
|
|
262
|
+
added: argumentsValue.content.replaceAll("\r\n", "\n").split("\n"),
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
commitFileChange(id, isError, details = undefined) {
|
|
267
|
+
const change = this.pendingFileChanges.get(id);
|
|
268
|
+
this.pendingFileChanges.delete(id);
|
|
269
|
+
if (!change || isError)
|
|
270
|
+
return;
|
|
271
|
+
const metadata = isEditDetails(details) ? details : undefined;
|
|
272
|
+
this.messageItems.push(metadata ? { ...change, diff: metadata.diff, firstChangedLine: metadata.firstChangedLine } : change);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
function parseEditArguments(argumentsValue) {
|
|
276
|
+
if (Array.isArray(argumentsValue.edits)) {
|
|
277
|
+
const edits = [];
|
|
278
|
+
for (const value of argumentsValue.edits) {
|
|
279
|
+
if (!isRecord(value) || typeof value.oldText !== "string" || typeof value.newText !== "string")
|
|
280
|
+
return undefined;
|
|
281
|
+
edits.push({ oldText: value.oldText, newText: value.newText });
|
|
282
|
+
}
|
|
283
|
+
return edits.length > 0 ? edits : undefined;
|
|
284
|
+
}
|
|
285
|
+
return typeof argumentsValue.oldText === "string" && typeof argumentsValue.newText === "string"
|
|
286
|
+
? [{ oldText: argumentsValue.oldText, newText: argumentsValue.newText }]
|
|
287
|
+
: undefined;
|
|
288
|
+
}
|
|
289
|
+
function isRecord(value) {
|
|
290
|
+
return typeof value === "object" && value !== null;
|
|
291
|
+
}
|
|
292
|
+
function isEditDetails(value) {
|
|
293
|
+
return (isRecord(value) &&
|
|
294
|
+
typeof value.diff === "string" &&
|
|
295
|
+
(value.firstChangedLine === undefined || typeof value.firstChangedLine === "number"));
|
|
196
296
|
}
|
|
197
297
|
function formatToolCommand(toolName, argumentsValue) {
|
|
198
298
|
const serialized = JSON.stringify(argumentsValue);
|