@humain/humain-code 0.6.1 → 0.6.2
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/CHANGELOG.md +42 -0
- package/dist/bundle/agent-monitor.js +1 -1
- package/dist/bundle/chunks/{anthropic-messages-FGFIMZUF.js → anthropic-messages-MNISFDZA.js} +2 -2
- package/dist/bundle/chunks/{azure-openai-responses-6JNTC7KO.js → azure-openai-responses-IV74M5OR.js} +3 -3
- package/dist/bundle/chunks/bedrock-converse-stream.js +4 -5
- package/dist/bundle/chunks/{chunk-CVC2GV26.js → chunk-2HZ2V3HS.js} +610 -611
- package/dist/bundle/chunks/{chunk-IJYVMOB4.js → chunk-2PZ46FSM.js} +3 -3
- package/dist/bundle/chunks/{chunk-I6AQOITY.js → chunk-3LP543EX.js} +6 -6
- package/dist/bundle/chunks/{chunk-FDGW5ZTG.js → chunk-4J6BGNX2.js} +6 -6
- package/dist/bundle/chunks/{chunk-EDONIPUJ.js → chunk-4SQUP6IR.js} +7 -7
- package/dist/bundle/chunks/{chunk-P4P7OZ7R.js → chunk-5L4JG6PO.js} +1 -1
- package/dist/bundle/chunks/{chunk-GICL5V54.js → chunk-6PD3T2EF.js} +1 -1
- package/dist/bundle/chunks/{chunk-CFHOPLW5.js → chunk-75CQYZ63.js} +56 -54
- package/dist/bundle/chunks/{chunk-DHW3REC5.js → chunk-A2VPLMF2.js} +1 -1
- package/dist/bundle/chunks/{chunk-AOH2O5CP.js → chunk-DCPACGLH.js} +575 -538
- package/dist/bundle/chunks/{chunk-M4CHQBAI.js → chunk-DLCBSLHW.js} +1 -1
- package/dist/bundle/chunks/chunk-F77J5EQZ.js +3 -0
- package/dist/bundle/chunks/{chunk-T3KDZFM4.js → chunk-FHLLDO7U.js} +7 -6
- package/dist/bundle/chunks/{chunk-AHSNQWZU.js → chunk-FLVBQ6GS.js} +1 -1
- package/dist/bundle/chunks/{chunk-ONR6Q3II.js → chunk-JCTQQ3DX.js} +1 -1
- package/dist/bundle/chunks/{chunk-YRUIJ5AH.js → chunk-JEAM6N22.js} +6 -5
- package/dist/bundle/chunks/{chunk-LDGCU6PD.js → chunk-K7SDY3VJ.js} +1 -1
- package/dist/bundle/chunks/{chunk-IADQJFNH.js → chunk-KM4GQ2BU.js} +5 -4
- package/dist/bundle/chunks/{chunk-JFE52VSN.js → chunk-NCC2FAJN.js} +23 -22
- package/dist/bundle/chunks/{chunk-RO5YPAJH.js → chunk-PS2FJ7M4.js} +1 -1
- package/dist/bundle/chunks/{chunk-HW6HMUXS.js → chunk-SFMDIVZ4.js} +1 -1
- package/dist/bundle/chunks/{chunk-B7NJMF7B.js → chunk-WEFEQEIQ.js} +4 -4
- package/dist/bundle/chunks/{chunk-6DE7LJKV.js → chunk-WW4SILXG.js} +24 -19
- package/dist/bundle/chunks/{cli-BNCWK54K.js → cli-N7KOVPLB.js} +1 -1
- package/dist/bundle/chunks/{cloudflare-workers-ai-system-one-KI6W3USX.js → cloudflare-workers-ai-system-one-KRMHG2L3.js} +1 -1
- package/dist/bundle/chunks/codemode-worker.js +10 -4
- package/dist/bundle/chunks/{compat-I5VPOXFT.js → compat-MXAZPYDN.js} +9 -9
- package/dist/bundle/chunks/{dist-SKBR3C7C.js → dist-3V7ZSLER.js} +29 -26
- package/dist/bundle/chunks/dist-66CW64M2.js +8 -0
- package/dist/bundle/chunks/{easter-egg-3d-673VRP6Y.js → easter-egg-3d-O2GG2XIG.js} +1 -1
- package/dist/bundle/chunks/{execute-PIUR5MUV.js → execute-LMBACTKA.js} +28 -23
- package/dist/bundle/chunks/{extract-4O5Z5725.js → extract-CXXLVFC5.js} +7 -7
- package/dist/bundle/chunks/{google-generative-ai-635YZEHN.js → google-generative-ai-SBL77OXO.js} +4 -4
- package/dist/bundle/chunks/{google-vertex-I3ZJ3SB2.js → google-vertex-NZBNNXMK.js} +6 -6
- package/dist/bundle/chunks/{host-OQOEIWHK.js → host-SCZ4IKWR.js} +1 -1
- package/dist/bundle/chunks/{mistral-conversations-OKG5GKXR.js → mistral-conversations-DX4YKJSO.js} +14 -13
- package/dist/bundle/chunks/{openai-codex-responses-6JYZIFT4.js → openai-codex-responses-LZWBQYVP.js} +38 -37
- package/dist/bundle/chunks/{openai-completions-YBNI6CAP.js → openai-completions-7NWH423P.js} +2 -2
- package/dist/bundle/chunks/{openai-decisions-5G5YBFRQ.js → openai-decisions-ALJROWBE.js} +1 -1
- package/dist/bundle/chunks/{openai-responses-C3APJ6MK.js → openai-responses-5YOLHMCF.js} +3 -3
- package/dist/bundle/chunks/{pi-messages-UHYZYEOC.js → pi-messages-NHTQQOPW.js} +1 -1
- package/dist/bundle/chunks/{runtime-KE3HDSRT.js → runtime-UVPDE4CX.js} +1 -1
- package/dist/bundle/chunks/{typesafe-system-one-VYVAMWQV.js → typesafe-system-one-BHJYAZ6E.js} +1 -1
- package/dist/bundle/chunks/virtual-modules-YQPK57CW.js +23 -0
- package/dist/bundle/cli-runtime.js +3 -3
- package/dist/bundle/index.js +6 -6
- package/dist/bundle/rpc-entry.js +2 -2
- package/dist/coordination/adapter/commands-integration.d.ts +2 -2
- package/dist/coordination/adapter/commands-integration.d.ts.map +1 -1
- package/dist/coordination/adapter/commands-integration.js +14 -10
- package/dist/coordination/adapter/commands-integration.js.map +1 -1
- package/dist/coordination/adapter/delivery.d.ts +3 -0
- package/dist/coordination/adapter/delivery.d.ts.map +1 -1
- package/dist/coordination/adapter/delivery.js +4 -1
- package/dist/coordination/adapter/delivery.js.map +1 -1
- package/dist/coordination/adapter/index.d.ts.map +1 -1
- package/dist/coordination/adapter/index.js +26 -2
- package/dist/coordination/adapter/index.js.map +1 -1
- package/dist/coordination/adapter/integration-notices.d.ts +2 -2
- package/dist/coordination/adapter/integration-notices.d.ts.map +1 -1
- package/dist/coordination/adapter/integration-notices.js +5 -3
- package/dist/coordination/adapter/integration-notices.js.map +1 -1
- package/dist/coordination/adapter/integration-tool.d.ts +2 -1
- package/dist/coordination/adapter/integration-tool.d.ts.map +1 -1
- package/dist/coordination/adapter/integration-tool.js +11 -10
- package/dist/coordination/adapter/integration-tool.js.map +1 -1
- package/dist/coordination/adapter/peer-label.d.ts +5 -0
- package/dist/coordination/adapter/peer-label.d.ts.map +1 -0
- package/dist/coordination/adapter/peer-label.js +38 -0
- package/dist/coordination/adapter/peer-label.js.map +1 -0
- package/dist/coordination/adapter/render.d.ts +19 -0
- package/dist/coordination/adapter/render.d.ts.map +1 -0
- package/dist/coordination/adapter/render.js +107 -0
- package/dist/coordination/adapter/render.js.map +1 -0
- package/dist/coordination/adapter/tool.d.ts +12 -3
- package/dist/coordination/adapter/tool.d.ts.map +1 -1
- package/dist/coordination/adapter/tool.js +69 -32
- package/dist/coordination/adapter/tool.js.map +1 -1
- package/dist/coordination/broker/broker.d.ts +4 -1
- package/dist/coordination/broker/broker.d.ts.map +1 -1
- package/dist/coordination/broker/broker.js +146 -60
- package/dist/coordination/broker/broker.js.map +1 -1
- package/dist/coordination/client/client.d.ts.map +1 -1
- package/dist/coordination/client/client.js +10 -2
- package/dist/coordination/client/client.js.map +1 -1
- package/dist/coordination/transport/discovery.d.ts +4 -0
- package/dist/coordination/transport/discovery.d.ts.map +1 -1
- package/dist/coordination/transport/discovery.js +14 -0
- package/dist/coordination/transport/discovery.js.map +1 -1
- package/dist/coordination/transport/protocol.d.ts.map +1 -1
- package/dist/coordination/transport/protocol.js +3 -0
- package/dist/coordination/transport/protocol.js.map +1 -1
- package/dist/coordination/transport/types.d.ts +5 -1
- package/dist/coordination/transport/types.d.ts.map +1 -1
- package/dist/coordination/transport/types.js.map +1 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +6 -2
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js +13 -36
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/bedrock-account-reporting.d.ts.map +1 -1
- package/dist/core/bedrock-account-reporting.js +2 -1
- package/dist/core/bedrock-account-reporting.js.map +1 -1
- package/dist/core/cache-warmer.d.ts.map +1 -1
- package/dist/core/cache-warmer.js +2 -2
- package/dist/core/cache-warmer.js.map +1 -1
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js +3 -2
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +2 -2
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +2 -0
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/model-runtime.d.ts +2 -0
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +7 -7
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +8 -0
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager.d.ts +6 -0
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +27 -6
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/tools/bash.d.ts +2 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +39 -3
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/index.d.ts +1 -1
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/output-accumulator.d.ts +5 -1
- package/dist/core/tools/output-accumulator.d.ts.map +1 -1
- package/dist/core/tools/output-accumulator.js +45 -16
- package/dist/core/tools/output-accumulator.js.map +1 -1
- package/dist/core/tools/render-utils.d.ts.map +1 -1
- package/dist/core/tools/render-utils.js +2 -2
- package/dist/core/tools/render-utils.js.map +1 -1
- package/dist/core/tools/renderers/write.js +2 -2
- package/dist/core/tools/renderers/write.js.map +1 -1
- package/dist/core/tools/subagent.d.ts +22 -0
- package/dist/core/tools/subagent.d.ts.map +1 -1
- package/dist/core/tools/subagent.js +46 -7
- package/dist/core/tools/subagent.js.map +1 -1
- package/dist/core/trace-client/credential-store.d.ts.map +1 -1
- package/dist/core/trace-client/credential-store.js +2 -0
- package/dist/core/trace-client/credential-store.js.map +1 -1
- package/dist/extensions/codemode/execute.d.ts.map +1 -1
- package/dist/extensions/codemode/execute.js +3 -12
- package/dist/extensions/codemode/execute.js.map +1 -1
- package/dist/humain/bedrock-provider/vendor/index.bundle.mjs +10 -6
- package/dist/humain/gateway/secret-store.d.ts.map +1 -1
- package/dist/humain/gateway/secret-store.js +26 -12
- package/dist/humain/gateway/secret-store.js.map +1 -1
- package/dist/humain/gateway/session-store.d.ts +2 -2
- package/dist/humain/gateway/session-store.d.ts.map +1 -1
- package/dist/humain/gateway/session-store.js +13 -3
- package/dist/humain/gateway/session-store.js.map +1 -1
- package/dist/humain/web-access/vendor/extract.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/extract.js +4 -2
- package/dist/humain/web-access/vendor/extract.js.map +1 -1
- package/dist/humain/web-access/vendor/page-query.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/page-query.js +2 -1
- package/dist/humain/web-access/vendor/page-query.js.map +1 -1
- package/dist/humain/web-access/vendor/query-rewrite.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/query-rewrite.js +2 -1
- package/dist/humain/web-access/vendor/query-rewrite.js.map +1 -1
- package/dist/humain/web-access/vendor/storage.d.ts +2 -0
- package/dist/humain/web-access/vendor/storage.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/storage.js +71 -9
- package/dist/humain/web-access/vendor/storage.js.map +1 -1
- package/dist/humain/web-access/vendor/summary-review.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/summary-review.js +2 -1
- package/dist/humain/web-access/vendor/summary-review.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +3 -3
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/mermaid.d.ts.map +1 -1
- package/dist/modes/interactive/components/mermaid.js +71 -34
- package/dist/modes/interactive/components/mermaid.js.map +1 -1
- package/dist/utils/child-process.d.ts.map +1 -1
- package/dist/utils/child-process.js +16 -0
- package/dist/utils/child-process.js.map +1 -1
- package/docs/coordination.md +6 -2
- package/docs/development.md +4 -0
- package/docs/extensions.md +2 -0
- package/docs/providers.md +12 -2
- package/examples/extensions/gondolin/index.ts +1 -1
- package/examples/extensions/ssh.ts +34 -5
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/src/coordination/UPSTREAM.md +17 -0
- package/src/humain/web-access/UPSTREAM.md +11 -0
- package/dist/bundle/chunks/chunk-L6Z6JKKC.js +0 -3
- package/dist/bundle/chunks/dist-TVRQXUY6.js +0 -8
- package/dist/bundle/chunks/virtual-modules-KDUZIB3W.js +0 -23
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { pathToFileURL } from "node:url";
|
|
2
|
-
import { getCapabilities, getImageDimensions, hyperlink, imageFallback, sanitizeTerminalText, sanitizeTerminalTextFrom, } from "@earendil-works/pi-tui";
|
|
2
|
+
import { getCapabilities, getImageDimensions, hyperlink, imageFallback, sanitizeTerminalText, sanitizeTerminalTextFrom, startsWithText, } from "@earendil-works/pi-tui";
|
|
3
3
|
import { stripAnsi } from "../../utils/ansi.js";
|
|
4
4
|
import { resolvePath, shortenHomePath } from "../../utils/paths.js";
|
|
5
5
|
import { sanitizeBinaryOutput } from "../../utils/shell.js";
|
|
@@ -40,7 +40,7 @@ function sanitizeArgument(text) {
|
|
|
40
40
|
let previous;
|
|
41
41
|
for (let i = sanitizedArguments.length - 1; i >= 0; i--) {
|
|
42
42
|
const entry = sanitizedArguments[i];
|
|
43
|
-
if (text
|
|
43
|
+
if (startsWithText(text, entry.raw)) {
|
|
44
44
|
previous = entry;
|
|
45
45
|
sanitizedArguments.splice(i, 1);
|
|
46
46
|
break;
|
|
@@ -1 +1 @@
|
|
|
1
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E,eAAe,CAAC,CAAC;AAC3C,CAAC;AAED,MAAM,UAAU,cAAc,CAC7B,OAAsB,EACtB,KAAY,EACZ,GAAW,EACX,OAAoC;IAEpC,IAAI,OAAO,KAAK,IAAI;QAAE,OAAO,cAAc,CAAC,KAAK,CAAC,CAAC;IACnD,MAAM,KAAK,GAAG,OAAO,IAAI,OAAO,EAAE,aAAa,CAAC;IAChD,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAC,EAAE,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;IACjD,OAAO,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;AACrE,CAAC","sourcesContent":["import { pathToFileURL } from \"node:url\";\nimport type { ImageContent, TextContent } from \"@earendil-works/pi-ai\";\nimport {\n\tgetCapabilities,\n\tgetImageDimensions,\n\thyperlink,\n\timageFallback,\n\ttype SanitizedTerminalText,\n\tsanitizeTerminalText,\n\tsanitizeTerminalTextFrom,\n} from \"@earendil-works/pi-tui\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { stripAnsi } from \"../../utils/ansi.ts\";\nimport { resolvePath, shortenHomePath } from \"../../utils/paths.ts\";\nimport { sanitizeBinaryOutput } from \"../../utils/shell.ts\";\nimport type { ToolRenderContext } from \"../extensions/types.ts\";\n\nexport function shortenPath(path: unknown): string {\n\tif (typeof path !== \"string\") return \"\";\n\treturn shortenHomePath(path);\n}\n\nexport function linkPath(styledText: string, rawPath: string, cwd: string): string {\n\tif (!getCapabilities().hyperlinks) return styledText;\n\tconst absolutePath = resolvePath(rawPath, cwd);\n\treturn hyperlink(styledText, pathToFileURL(absolutePath).href);\n}\n\n/**\n * A tool call argument as text to show, or null when it is not a string. The model wrote it: escape sequences in it are\n * removed (sanitizeTerminalText()), so it cannot draw over the call's header or its command line.\n */\nexport function str(value: unknown): string | null {\n\tif (typeof value === \"string\") return sanitizeArgument(value);\n\tif (value == null) return \"\";\n\treturn null;\n}\n\n/**\n * Long arguments str() sanitised last, most recent last. An argument streaming in (a file's content) is shown again for\n * each chunk: what was sanitised of it the time before is kept, and only the text added since is gone through.\n */\nconst sanitizedArguments: SanitizedTerminalText[] = [];\nconst SANITIZED_ARGUMENTS_KEPT = 4;\n/** Shorter arguments (a path, a pattern) are sanitised whole: that costs less than looking for them. */\nconst SANITIZED_ARGUMENT_MIN_LENGTH = 1024;\n\n/** sanitizeTerminalText(text), from what a shorter text it begins with was sanitised to when there is one. */\nfunction sanitizeArgument(text: string): string {\n\tif (text.length < SANITIZED_ARGUMENT_MIN_LENGTH) return sanitizeTerminalText(text);\n\tlet previous: SanitizedTerminalText | undefined;\n\tfor (let i = sanitizedArguments.length - 1; i >= 0; i--) {\n\t\tconst entry = sanitizedArguments[i];\n\t\tif (text.length >= entry.raw.length && text.startsWith(entry.raw)) {\n\t\t\tprevious = entry;\n\t\t\tsanitizedArguments.splice(i, 1);\n\t\t\tbreak;\n\t\t}\n\t}\n\tconst sanitized = sanitizeTerminalTextFrom(text, previous);\n\tsanitizedArguments.push(sanitized);\n\tif (sanitizedArguments.length > SANITIZED_ARGUMENTS_KEPT) {\n\t\tsanitizedArguments.shift();\n\t}\n\treturn sanitized.text;\n}\n\nfunction parseLineNumber(value: unknown): number | undefined {\n\tif (typeof value === \"string\" && value.trim() !== \"\") value = Number(value);\n\treturn typeof value === \"number\" && Number.isFinite(value) ? value : undefined;\n}\n\n/** Format finite numbers or numeric strings as a read line range, omitting malformed ranges. */\nexport function formatReadLineRange(offset: unknown, limit: unknown): string {\n\t// Strict schemas represent omitted optional arguments as null.\n\tif (offset == null && limit == null) return \"\";\n\tconst start = offset == null ? 1 : parseLineNumber(offset);\n\tif (start === undefined) return \"\";\n\tif (limit == null) return `:${start}`;\n\tconst count = parseLineNumber(limit);\n\tif (count === undefined) return \"\";\n\tconst end = start + count - 1;\n\treturn `:${start}${end ? `-${end}` : \"\"}`;\n}\n\nexport function replaceTabs(text: string): string {\n\treturn text.replace(/\\t/g, \" \");\n}\n\nexport function normalizeDisplayText(text: string): string {\n\treturn text.replace(/\\r/g, \"\");\n}\n\nexport function getTextOutput(\n\tresult: { content: Array<{ type: string; text?: string; data?: string; mimeType?: string }> } | undefined,\n\tshowImages: boolean,\n): string {\n\tif (!result) return \"\";\n\n\tconst textBlocks = result.content.filter((c) => c.type === \"text\");\n\tconst imageBlocks = result.content.filter((c) => c.type === \"image\");\n\n\tlet output = textBlocks.map((c) => sanitizeBinaryOutput(stripAnsi(c.text || \"\")).replace(/\\r/g, \"\")).join(\"\\n\");\n\n\tconst caps = getCapabilities();\n\tif (imageBlocks.length > 0 && (!caps.images || !showImages)) {\n\t\tconst imageIndicators = imageBlocks\n\t\t\t.map((img) => {\n\t\t\t\tconst mimeType = img.mimeType ?? \"image/unknown\";\n\t\t\t\tconst dims =\n\t\t\t\t\timg.data && img.mimeType ? (getImageDimensions(img.data, img.mimeType) ?? undefined) : undefined;\n\t\t\t\treturn imageFallback(mimeType, dims);\n\t\t\t})\n\t\t\t.join(\"\\n\");\n\t\toutput = output ? `${output}\\n${imageIndicators}` : imageIndicators;\n\t}\n\n\treturn output;\n}\n\nexport type ToolRenderResultLike<TDetails> = {\n\tcontent: (TextContent | ImageContent)[];\n\tdetails: TDetails;\n};\n\nconst COLLAPSED_ARGS_CHARS = 100;\n\n/**\n * Generic tool call header: the title followed by the arguments. Collapsed, they are `key=value`\n * pairs on the title line, cut to {@link COLLAPSED_ARGS_CHARS}. Expanded, each is a `key: value`\n * line below the title, with strings shown raw and continuation lines indented.\n */\nexport function formatToolCallWithArgs(title: string, args: unknown, theme: Theme, expanded: boolean): string {\n\t// (The title can come from an MCP server, the arguments from the model: sanitizeTerminalText() keeps escape sequences in\n\t// either from acting on the terminal. JSON.stringify() escapes C0 controls, but not DEL and C1 controls.)\n\tconst header = theme.fg(\"toolTitle\", theme.bold(sanitizeTerminalText(title)));\n\tif (args == null) return header;\n\tconst entries =\n\t\ttypeof args === \"object\" && !Array.isArray(args)\n\t\t\t? Object.entries(args)\n\t\t\t: ([[\"args\", args]] as [string, unknown][]);\n\tif (entries.length === 0) return header;\n\tif (expanded) {\n\t\tconst lines = entries.map(([key, value]) => {\n\t\t\tconst text = typeof value === \"string\" ? value : (JSON.stringify(value, null, 2) ?? String(value));\n\t\t\tconst shown = replaceTabs(sanitizeTerminalText(text)).replace(/\\r/g, \"\");\n\t\t\treturn ` ${sanitizeTerminalText(key)}: ${shown.split(\"\\n\").join(\"\\n \")}`;\n\t\t});\n\t\treturn `${header}\\n${theme.fg(\"muted\", lines.join(\"\\n\"))}`;\n\t}\n\tconst pairs = entries.map(([key, value]) => `${key}=${JSON.stringify(value) ?? String(value)}`).join(\" \");\n\tconst preview = pairs.length > COLLAPSED_ARGS_CHARS ? `${pairs.slice(0, COLLAPSED_ARGS_CHARS - 3)}...` : pairs;\n\treturn `${header} ${theme.fg(\"muted\", sanitizeTerminalText(preview))}`;\n}\n\n/** Duration as `4.2s` below a minute, then `1m 30s` and `2h 3m 4s`. */\nexport function formatToolDuration(ms: number): string {\n\tconst seconds = ms / 1000;\n\tif (seconds < 60) return `${seconds.toFixed(1)}s`;\n\n\tconst totalSeconds = Math.floor(seconds);\n\tconst minutes = Math.floor(totalSeconds / 60);\n\tconst remainder = totalSeconds % 60;\n\tif (minutes < 60) return `${minutes}m ${remainder}s`;\n\n\treturn `${Math.floor(minutes / 60)}h ${minutes % 60}m ${remainder}s`;\n}\n\n/** Renderer state of {@link startToolTimer} and {@link toolTimerText}, kept in `ToolRenderContext.state`. */\ninterface ToolTimerState {\n\tstartedAt?: number;\n\tendedAt?: number;\n\tinterval?: ReturnType<typeof setInterval>;\n}\n\n/** Start the row's clock once execution starts. Call from `renderCall`. */\nexport function startToolTimer(context: ToolRenderContext<ToolTimerState>): void {\n\tconst state = context.state;\n\tif (context.executionStarted && state.startedAt === undefined) {\n\t\tstate.startedAt = Date.now();\n\t\tstate.endedAt = undefined;\n\t}\n}\n\n/**\n * The row's timing line, from `renderResult`: `Elapsed 4.2s` while the result is partial, redrawn\n * every second, and `Took 4.2s` once it is final. Undefined when the row has no start time and no\n * recorded duration.\n */\nexport function toolTimerText(context: ToolRenderContext<ToolTimerState>, isPartial: boolean): string | undefined {\n\tconst state = context.state;\n\tif (state.startedAt !== undefined && isPartial && !state.interval) {\n\t\tstate.interval = setInterval(() => context.invalidate(), 1000);\n\t}\n\tif (!isPartial || context.isError) {\n\t\tstate.endedAt ??= Date.now();\n\t\tif (state.interval) {\n\t\t\tclearInterval(state.interval);\n\t\t\tstate.interval = undefined;\n\t\t}\n\t}\n\t// A final result's recorded duration wins: it is monotonic and survives reloads. The renderer's own clock is the\n\t// fallback for live progress and for results stored without one.\n\tif (!isPartial && context.durationMs !== undefined) return `Took ${formatToolDuration(context.durationMs)}`;\n\tif (state.startedAt === undefined) return undefined;\n\tconst endTime = state.endedAt ?? Date.now();\n\treturn `${isPartial ? \"Elapsed\" : \"Took\"} ${formatToolDuration(endTime - state.startedAt)}`;\n}\n\nexport function invalidArgText(theme: Theme): string {\n\treturn theme.fg(\"error\", \"[invalid arg]\");\n}\n\nexport function renderToolPath(\n\trawPath: string | null,\n\ttheme: Theme,\n\tcwd: string,\n\toptions?: { emptyFallback?: string },\n): string {\n\tif (rawPath === null) return invalidArgText(theme);\n\tconst value = rawPath || options?.emptyFallback;\n\tif (!value) return theme.fg(\"toolOutput\", \"...\");\n\treturn linkPath(theme.fg(\"accent\", shortenPath(value)), value, cwd);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"render-utils.js","sourceRoot":"","sources":["../../../src/core/tools/render-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EACN,eAAe,EACf,kBAAkB,EAClB,SAAS,EACT,aAAa,EAEb,oBAAoB,EACpB,wBAAwB,EACxB,cAAc,GACd,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,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AAC,CAAC;IACjD,OAAO,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;AACrE,CAAC","sourcesContent":["import { pathToFileURL } from \"node:url\";\nimport type { ImageContent, TextContent } from \"@earendil-works/pi-ai\";\nimport {\n\tgetCapabilities,\n\tgetImageDimensions,\n\thyperlink,\n\timageFallback,\n\ttype SanitizedTerminalText,\n\tsanitizeTerminalText,\n\tsanitizeTerminalTextFrom,\n\tstartsWithText,\n} from \"@earendil-works/pi-tui\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { stripAnsi } from \"../../utils/ansi.ts\";\nimport { resolvePath, shortenHomePath } from \"../../utils/paths.ts\";\nimport { sanitizeBinaryOutput } from \"../../utils/shell.ts\";\nimport type { ToolRenderContext } from \"../extensions/types.ts\";\n\nexport function shortenPath(path: unknown): string {\n\tif (typeof path !== \"string\") return \"\";\n\treturn shortenHomePath(path);\n}\n\nexport function linkPath(styledText: string, rawPath: string, cwd: string): string {\n\tif (!getCapabilities().hyperlinks) return styledText;\n\tconst absolutePath = resolvePath(rawPath, cwd);\n\treturn hyperlink(styledText, pathToFileURL(absolutePath).href);\n}\n\n/**\n * A tool call argument as text to show, or null when it is not a string. The model wrote it: escape sequences in it are\n * removed (sanitizeTerminalText()), so it cannot draw over the call's header or its command line.\n */\nexport function str(value: unknown): string | null {\n\tif (typeof value === \"string\") return sanitizeArgument(value);\n\tif (value == null) return \"\";\n\treturn null;\n}\n\n/**\n * Long arguments str() sanitised last, most recent last. An argument streaming in (a file's content) is shown again for\n * each chunk: what was sanitised of it the time before is kept, and only the text added since is gone through.\n */\nconst sanitizedArguments: SanitizedTerminalText[] = [];\nconst SANITIZED_ARGUMENTS_KEPT = 4;\n/** Shorter arguments (a path, a pattern) are sanitised whole: that costs less than looking for them. */\nconst SANITIZED_ARGUMENT_MIN_LENGTH = 1024;\n\n/** sanitizeTerminalText(text), from what a shorter text it begins with was sanitised to when there is one. */\nfunction sanitizeArgument(text: string): string {\n\tif (text.length < SANITIZED_ARGUMENT_MIN_LENGTH) return sanitizeTerminalText(text);\n\tlet previous: SanitizedTerminalText | undefined;\n\tfor (let i = sanitizedArguments.length - 1; i >= 0; i--) {\n\t\tconst entry = sanitizedArguments[i];\n\t\tif (startsWithText(text, entry.raw)) {\n\t\t\tprevious = entry;\n\t\t\tsanitizedArguments.splice(i, 1);\n\t\t\tbreak;\n\t\t}\n\t}\n\tconst sanitized = sanitizeTerminalTextFrom(text, previous);\n\tsanitizedArguments.push(sanitized);\n\tif (sanitizedArguments.length > SANITIZED_ARGUMENTS_KEPT) {\n\t\tsanitizedArguments.shift();\n\t}\n\treturn sanitized.text;\n}\n\nfunction parseLineNumber(value: unknown): number | undefined {\n\tif (typeof value === \"string\" && value.trim() !== \"\") value = Number(value);\n\treturn typeof value === \"number\" && Number.isFinite(value) ? value : undefined;\n}\n\n/** Format finite numbers or numeric strings as a read line range, omitting malformed ranges. */\nexport function formatReadLineRange(offset: unknown, limit: unknown): string {\n\t// Strict schemas represent omitted optional arguments as null.\n\tif (offset == null && limit == null) return \"\";\n\tconst start = offset == null ? 1 : parseLineNumber(offset);\n\tif (start === undefined) return \"\";\n\tif (limit == null) return `:${start}`;\n\tconst count = parseLineNumber(limit);\n\tif (count === undefined) return \"\";\n\tconst end = start + count - 1;\n\treturn `:${start}${end ? `-${end}` : \"\"}`;\n}\n\nexport function replaceTabs(text: string): string {\n\treturn text.replace(/\\t/g, \" \");\n}\n\nexport function normalizeDisplayText(text: string): string {\n\treturn text.replace(/\\r/g, \"\");\n}\n\nexport function getTextOutput(\n\tresult: { content: Array<{ type: string; text?: string; data?: string; mimeType?: string }> } | undefined,\n\tshowImages: boolean,\n): string {\n\tif (!result) return \"\";\n\n\tconst textBlocks = result.content.filter((c) => c.type === \"text\");\n\tconst imageBlocks = result.content.filter((c) => c.type === \"image\");\n\n\tlet output = textBlocks.map((c) => sanitizeBinaryOutput(stripAnsi(c.text || \"\")).replace(/\\r/g, \"\")).join(\"\\n\");\n\n\tconst caps = getCapabilities();\n\tif (imageBlocks.length > 0 && (!caps.images || !showImages)) {\n\t\tconst imageIndicators = imageBlocks\n\t\t\t.map((img) => {\n\t\t\t\tconst mimeType = img.mimeType ?? \"image/unknown\";\n\t\t\t\tconst dims =\n\t\t\t\t\timg.data && img.mimeType ? (getImageDimensions(img.data, img.mimeType) ?? undefined) : undefined;\n\t\t\t\treturn imageFallback(mimeType, dims);\n\t\t\t})\n\t\t\t.join(\"\\n\");\n\t\toutput = output ? `${output}\\n${imageIndicators}` : imageIndicators;\n\t}\n\n\treturn output;\n}\n\nexport type ToolRenderResultLike<TDetails> = {\n\tcontent: (TextContent | ImageContent)[];\n\tdetails: TDetails;\n};\n\nconst COLLAPSED_ARGS_CHARS = 100;\n\n/**\n * Generic tool call header: the title followed by the arguments. Collapsed, they are `key=value`\n * pairs on the title line, cut to {@link COLLAPSED_ARGS_CHARS}. Expanded, each is a `key: value`\n * line below the title, with strings shown raw and continuation lines indented.\n */\nexport function formatToolCallWithArgs(title: string, args: unknown, theme: Theme, expanded: boolean): string {\n\t// (The title can come from an MCP server, the arguments from the model: sanitizeTerminalText() keeps escape sequences in\n\t// either from acting on the terminal. JSON.stringify() escapes C0 controls, but not DEL and C1 controls.)\n\tconst header = theme.fg(\"toolTitle\", theme.bold(sanitizeTerminalText(title)));\n\tif (args == null) return header;\n\tconst entries =\n\t\ttypeof args === \"object\" && !Array.isArray(args)\n\t\t\t? Object.entries(args)\n\t\t\t: ([[\"args\", args]] as [string, unknown][]);\n\tif (entries.length === 0) return header;\n\tif (expanded) {\n\t\tconst lines = entries.map(([key, value]) => {\n\t\t\tconst text = typeof value === \"string\" ? value : (JSON.stringify(value, null, 2) ?? String(value));\n\t\t\tconst shown = replaceTabs(sanitizeTerminalText(text)).replace(/\\r/g, \"\");\n\t\t\treturn ` ${sanitizeTerminalText(key)}: ${shown.split(\"\\n\").join(\"\\n \")}`;\n\t\t});\n\t\treturn `${header}\\n${theme.fg(\"muted\", lines.join(\"\\n\"))}`;\n\t}\n\tconst pairs = entries.map(([key, value]) => `${key}=${JSON.stringify(value) ?? String(value)}`).join(\" \");\n\tconst preview = pairs.length > COLLAPSED_ARGS_CHARS ? `${pairs.slice(0, COLLAPSED_ARGS_CHARS - 3)}...` : pairs;\n\treturn `${header} ${theme.fg(\"muted\", sanitizeTerminalText(preview))}`;\n}\n\n/** Duration as `4.2s` below a minute, then `1m 30s` and `2h 3m 4s`. */\nexport function formatToolDuration(ms: number): string {\n\tconst seconds = ms / 1000;\n\tif (seconds < 60) return `${seconds.toFixed(1)}s`;\n\n\tconst totalSeconds = Math.floor(seconds);\n\tconst minutes = Math.floor(totalSeconds / 60);\n\tconst remainder = totalSeconds % 60;\n\tif (minutes < 60) return `${minutes}m ${remainder}s`;\n\n\treturn `${Math.floor(minutes / 60)}h ${minutes % 60}m ${remainder}s`;\n}\n\n/** Renderer state of {@link startToolTimer} and {@link toolTimerText}, kept in `ToolRenderContext.state`. */\ninterface ToolTimerState {\n\tstartedAt?: number;\n\tendedAt?: number;\n\tinterval?: ReturnType<typeof setInterval>;\n}\n\n/** Start the row's clock once execution starts. Call from `renderCall`. */\nexport function startToolTimer(context: ToolRenderContext<ToolTimerState>): void {\n\tconst state = context.state;\n\tif (context.executionStarted && state.startedAt === undefined) {\n\t\tstate.startedAt = Date.now();\n\t\tstate.endedAt = undefined;\n\t}\n}\n\n/**\n * The row's timing line, from `renderResult`: `Elapsed 4.2s` while the result is partial, redrawn\n * every second, and `Took 4.2s` once it is final. Undefined when the row has no start time and no\n * recorded duration.\n */\nexport function toolTimerText(context: ToolRenderContext<ToolTimerState>, isPartial: boolean): string | undefined {\n\tconst state = context.state;\n\tif (state.startedAt !== undefined && isPartial && !state.interval) {\n\t\tstate.interval = setInterval(() => context.invalidate(), 1000);\n\t}\n\tif (!isPartial || context.isError) {\n\t\tstate.endedAt ??= Date.now();\n\t\tif (state.interval) {\n\t\t\tclearInterval(state.interval);\n\t\t\tstate.interval = undefined;\n\t\t}\n\t}\n\t// A final result's recorded duration wins: it is monotonic and survives reloads. The renderer's own clock is the\n\t// fallback for live progress and for results stored without one.\n\tif (!isPartial && context.durationMs !== undefined) return `Took ${formatToolDuration(context.durationMs)}`;\n\tif (state.startedAt === undefined) return undefined;\n\tconst endTime = state.endedAt ?? Date.now();\n\treturn `${isPartial ? \"Elapsed\" : \"Took\"} ${formatToolDuration(endTime - state.startedAt)}`;\n}\n\nexport function invalidArgText(theme: Theme): string {\n\treturn theme.fg(\"error\", \"[invalid arg]\");\n}\n\nexport function renderToolPath(\n\trawPath: string | null,\n\ttheme: Theme,\n\tcwd: string,\n\toptions?: { emptyFallback?: string },\n): string {\n\tif (rawPath === null) return invalidArgText(theme);\n\tconst value = rawPath || options?.emptyFallback;\n\tif (!value) return theme.fg(\"toolOutput\", \"...\");\n\treturn linkPath(theme.fg(\"accent\", shortenPath(value)), value, cwd);\n}\n"]}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* load the execution path or its typebox parameter schema. `write.ts` spreads these into its
|
|
7
7
|
* definition, so the tool's public shape is unchanged.
|
|
8
8
|
*/
|
|
9
|
-
import { Container, sanitizeTerminalText, Text } from "@earendil-works/pi-tui";
|
|
9
|
+
import { Container, sanitizeTerminalText, startsWithText, Text } from "@earendil-works/pi-tui";
|
|
10
10
|
import { keyHint } from "../../../modes/interactive/components/keybinding-hints.js";
|
|
11
11
|
import { CodeHighlighter, getLanguageFromPath, highlightCode, } from "../../../modes/interactive/theme/theme.js";
|
|
12
12
|
import { normalizeDisplayText, renderToolPath, replaceTabs, str } from "../render-utils.js";
|
|
@@ -97,7 +97,7 @@ function updateWriteHighlightCacheIncremental(cache, rawPath, fileContent, expan
|
|
|
97
97
|
if (!cache ||
|
|
98
98
|
cache.lang !== lang ||
|
|
99
99
|
cache.rawPath !== rawPath ||
|
|
100
|
-
!fileContent
|
|
100
|
+
!startsWithText(fileContent, cache.rawContent) ||
|
|
101
101
|
(cache.lineCount !== undefined && (expanded || fileContent.length !== cache.rawContent.length))) {
|
|
102
102
|
return expanded
|
|
103
103
|
? rebuildWriteHighlightCacheFull(rawPath, fileContent, highlighter)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write.js","sourceRoot":"","sources":["../../../../src/core/tools/renderers/write.ts"],"names":[],"mappings":"AAAA,mHAAmH;AACnH;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAC/E,OAAO,EAAE,OAAO,EAAE,MAAM,2DAA2D,CAAC;AACpF,OAAO,EACN,eAAe,EACf,mBAAmB,EACnB,aAAa,GAEb,MAAM,2CAA2C,CAAC;AAEnD,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAC5F,OAAO,EAAE,gCAAgC,EAAE,MAAM,mBAAmB,CAAC;AAwBrE,MAAM,wBAAyB,SAAQ,IAAI;IAC1C,wEAAwE;IACxE,KAAK,CAAuB;IAC5B,gHAAgH;IAChH,gHAAgH;IAChH,mFAAmF;IAC1E,WAAW,GAAG,IAAI,eAAe,EAAE,CAAC;IAE7C;QACC,KAAK,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACjB,CAAC;IAEQ,UAAU;QAClB,KAAK,CAAC,UAAU,EAAE,CAAC;QACnB,gFAAgF;QAChF,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;IACxB,CAAC;CACD;AACD,MAAM,kCAAkC,GAAG,EAAE,CAAC;AAC9C,oDAAoD;AACpD,MAAM,qBAAqB,GAAG,EAAE,CAAC;AACjC,SAAS,mBAAmB,CAAC,IAAY,EAAE,IAAY;IACtD,MAAM,WAAW,GAAG,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC9C,OAAO,WAAW,CAAC,C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,CAAC,KAAK,CAAC,CAAC;YAC7C,KAAK,CAAC,eAAe,GAAG,KAAK,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,EAAE,kCAAkC,CAAC,CAAC;QAC5F,CAAC;QACD,SAAS,CAAC,OAAO,CAChB,eAAe,CACd,UAAU,EACV,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,EAC5D,KAAK,EACL,SAAS,CAAC,KAAK,EACf,SAAS,CAAC,WAAW,EACrB,OAAO,CAAC,GAAG,CACX,CACD,CAAC;QACF,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,YAAY,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO;QAC5C,MAAM,MAAM,GAAG,iBAAiB,CAAC,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,CAAC;QACjF,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,MAAM,SAAS,GAAI,OAAO,CAAC,aAAuC,IAAI,IAAI,SAAS,EAAE,CAAC;YACtF,SAAS,CAAC,KAAK,EAAE,CAAC;YAClB,OAAO,SAAS,CAAC;QAClB,CAAC;QACD,MAAM,IAAI,GAAI,OAAO,CAAC,aAAkC,IAAI,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAC/E,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACrB,OAAO,IAAI,CAAC;IACb,CAAC;CACD,CAAC;AAEF,gCAAgC,CAAC,cAAc,CAAC,CAAC","sourcesContent":["// Derived from Pi-Bolt (MIT, Copyright (c) 2026 OpenSec (Pi-Bolt)), commit b93895d2; modified for HUMAIN Code CLI.\n/**\n * Presentation for the write tool.\n *\n * Renderers live apart from the implementation so a process that only displays tool output does not\n * load the execution path or its typebox parameter schema. `write.ts` spreads these into its\n * definition, so the tool's public shape is unchanged.\n */\n\nimport { Container, sanitizeTerminalText, Text } from \"@earendil-works/pi-tui\";\nimport { keyHint } from \"../../../modes/interactive/components/keybinding-hints.ts\";\nimport {\n\tCodeHighlighter,\n\tgetLanguageFromPath,\n\thighlightCode,\n\ttype Theme,\n} from \"../../../modes/interactive/theme/theme.ts\";\nimport type { ToolRenderers, ToolRenderResultOptions } from \"../../extensions/types.ts\";\nimport { normalizeDisplayText, renderToolPath, replaceTabs, str } from \"../render-utils.ts\";\nimport { declarePathHighlightingRenderers } from \"./highlighting.ts\";\n\ntype WriteHighlightCache = {\n\trawPath: string | null;\n\tlang: string;\n\trawContent: string;\n\tnormalizedLines: string[];\n\t/**\n\t * The lines highlighted. When the call is shown collapsed, only the first lines are: the lines after the ones that can\n\t * be shown are highlighted when the call is expanded (`all`), not as each one arrives and again when the file is\n\t * complete, which for a large file stops everything for as long as highlighting all of it takes.\n\t */\n\thighlightedLines: string[];\n\tall: boolean;\n\t/** Made from the complete file, not from the pieces it arrived in. */\n\tcomplete?: boolean;\n\t/**\n\t * Set once the call has its result and is shown collapsed: the count of lines shown when expanded, with\n\t * normalizedLines cut to the first lines. A collapsed call needs no more of them, and every write of a session stays in\n\t * the chat: keeping each file split into lines again holds more memory than the files themselves.\n\t */\n\tlineCount?: number;\n\tprefixSource?: string;\n};\nclass WriteCallRenderComponent extends Text {\n\t// Line by line highlighting of a call whose content is still streaming.\n\tcache?: WriteHighlightCache;\n\t// A streamed call highlights its first lines on every delta, which stop changing once the file is longer, and a\n\t// complete call highlights the whole file on every update and expand toggle. Either way the row reuses the last\n\t// highlighting; it also holds the only copy of a complete call's displayed source.\n\treadonly highlighter = new CodeHighlighter();\n\n\tconstructor() {\n\t\tsuper(\"\", 0, 0);\n\t}\n\n\toverride invalidate(): void {\n\t\tsuper.invalidate();\n\t\t// Theme changes invalidate the highlighted prefix as well as the rendered text.\n\t\tthis.cache = undefined;\n\t}\n}\nconst WRITE_PARTIAL_FULL_HIGHLIGHT_LINES = 50;\n/** The lines of a collapsed call that are shown. */\nconst WRITE_COLLAPSED_LINES = 10;\nfunction highlightSingleLine(line: string, lang: string): string {\n\tconst highlighted = highlightCode(line, lang);\n\treturn highlighted[0] ?? \"\";\n}\nfunction refreshWriteHighlightPrefix(cache: WriteHighlightCache, highlighter: CodeHighlighter): void {\n\tconst prefixCount = Math.min(WRITE_PARTIAL_FULL_HIGHLIGHT_LINES, cache.normalizedLines.length);\n\tif (prefixCount === 0) return;\n\tconst prefixSource = cache.normalizedLines.slice(0, prefixCount).join(\"\\n\");\n\tif (cache.prefixSource === prefixSource) return;\n\tcache.prefixSource = prefixSource;\n\tconst prefixHighlighted = highlighter.highlight(prefixSource, cache.lang);\n\tfor (let i = 0; i < prefixCount; i++) {\n\t\tcache.highlightedLines[i] =\n\t\t\tprefixHighlighted[i] ?? highlightSingleLine(cache.normalizedLines[i] ?? \"\", cache.lang);\n\t}\n}\nfunction rebuildWriteHighlightCacheFull(\n\trawPath: string | null,\n\tfileContent: string,\n\thighlighter: CodeHighlighter,\n): WriteHighlightCache | undefined {\n\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\tif (!lang) return undefined;\n\tconst displayContent = normalizeDisplayText(fileContent);\n\tconst normalized = replaceTabs(displayContent);\n\treturn {\n\t\trawPath,\n\t\tlang,\n\t\trawContent: fileContent,\n\t\tnormalizedLines: normalized.split(\"\\n\"),\n\t\thighlightedLines: [...highlighter.highlight(normalized, lang)],\n\t\tall: true,\n\t\tcomplete: true,\n\t};\n}\n/** The cache for a call shown collapsed: the first lines highlighted, as they are while the file streams in. */\nfunction rebuildWriteHighlightCacheCollapsed(\n\trawPath: string | null,\n\tfileContent: string,\n\thighlighter: CodeHighlighter,\n): WriteHighlightCache | undefined {\n\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\tif (!lang) return undefined;\n\tconst cache: WriteHighlightCache = {\n\t\trawPath,\n\t\tlang,\n\t\trawContent: fileContent,\n\t\tnormalizedLines: replaceTabs(normalizeDisplayText(fileContent)).split(\"\\n\"),\n\t\thighlightedLines: [],\n\t\tall: false,\n\t};\n\trefreshWriteHighlightPrefix(cache, highlighter);\n\tcache.all = cache.normalizedLines.length <= WRITE_PARTIAL_FULL_HIGHLIGHT_LINES;\n\treturn cache;\n}\n/** Highlights, each on its own, the lines after the first ones that a collapsed call left unhighlighted. */\nfunction highlightRemainingLines(cache: WriteHighlightCache): void {\n\tif (cache.all) return;\n\tfor (\n\t\tlet i = Math.min(WRITE_PARTIAL_FULL_HIGHLIGHT_LINES, cache.normalizedLines.length);\n\t\ti < cache.normalizedLines.length;\n\t\ti++\n\t) {\n\t\tcache.highlightedLines[i] = highlightSingleLine(cache.normalizedLines[i], cache.lang);\n\t}\n\tcache.all = true;\n}\nfunction updateWriteHighlightCacheIncremental(\n\tcache: WriteHighlightCache | undefined,\n\trawPath: string | null,\n\tfileContent: string,\n\texpanded: boolean,\n\thighlighter: CodeHighlighter,\n): WriteHighlightCache | undefined {\n\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\tif (!lang) return undefined;\n\tif (\n\t\t!cache ||\n\t\tcache.lang !== lang ||\n\t\tcache.rawPath !== rawPath ||\n\t\t!fileContent.startsWith(cache.rawContent) ||\n\t\t(cache.lineCount !== undefined && (expanded || fileContent.length !== cache.rawContent.length))\n\t) {\n\t\treturn expanded\n\t\t\t? rebuildWriteHighlightCacheFull(rawPath, fileContent, highlighter)\n\t\t\t: rebuildWriteHighlightCacheCollapsed(rawPath, fileContent, highlighter);\n\t}\n\tif (expanded) highlightRemainingLines(cache);\n\tif (fileContent.length === cache.rawContent.length) return cache;\n\tcache.complete = false;\n\tif (!expanded) {\n\t\t// Collapsed: the lines are kept, and the first of them highlighted.\n\t\tconst added = replaceTabs(normalizeDisplayText(fileContent.slice(cache.rawContent.length))).split(\"\\n\");\n\t\tcache.rawContent = fileContent;\n\t\tcache.all = false;\n\t\tif (cache.normalizedLines.length === 0) cache.normalizedLines.push(\"\");\n\t\tconst lastLine = cache.normalizedLines.length - 1;\n\t\tcache.normalizedLines[lastLine] += added[0];\n\t\tfor (let i = 1; i < added.length; i++) cache.normalizedLines.push(added[i]);\n\t\trefreshWriteHighlightPrefix(cache, highlighter);\n\t\t// (While the first lines are all the lines, every line is highlighted.)\n\t\tcache.all = cache.normalizedLines.length <= WRITE_PARTIAL_FULL_HIGHLIGHT_LINES;\n\t\treturn cache;\n\t}\n\n\tconst deltaRaw = fileContent.slice(cache.rawContent.length);\n\tconst deltaDisplay = normalizeDisplayText(deltaRaw);\n\tconst deltaNormalized = replaceTabs(deltaDisplay);\n\tcache.rawContent = fileContent;\n\tif (cache.normalizedLines.length === 0) {\n\t\tcache.normalizedLines.push(\"\");\n\t\tcache.highlightedLines.push(\"\");\n\t}\n\n\tconst segments = deltaNormalized.split(\"\\n\");\n\tconst lastIndex = cache.normalizedLines.length - 1;\n\tcache.normalizedLines[lastIndex] += segments[0];\n\tcache.highlightedLines[lastIndex] = highlightSingleLine(cache.normalizedLines[lastIndex], cache.lang);\n\tfor (let i = 1; i < segments.length; i++) {\n\t\tcache.normalizedLines.push(segments[i]);\n\t\tcache.highlightedLines.push(highlightSingleLine(segments[i], cache.lang));\n\t}\n\trefreshWriteHighlightPrefix(cache, highlighter);\n\treturn cache;\n}\n/** The lines of a collapsed cache that are counted: without the empty lines at the end, as formatWriteCall() counts them. */\nfunction countCollapsedLines(cache: WriteHighlightCache): number {\n\tif (cache.lineCount !== undefined) return cache.lineCount;\n\tlet totalLines = cache.normalizedLines.length;\n\t// Without the empty lines at the end, unless an empty line is not empty once highlighted (in a language without a\n\t// highlighter, every line is colored).\n\tif (highlightSingleLine(\"\", cache.lang) === \"\") {\n\t\twhile (totalLines > 0 && cache.normalizedLines[totalLines - 1] === \"\") totalLines--;\n\t}\n\treturn totalLines;\n}\nfunction trimTrailingEmptyLines(lines: readonly string[]): string[] {\n\tlet end = lines.length;\n\twhile (end > 0 && lines[end - 1] === \"\") {\n\t\tend--;\n\t}\n\treturn lines.slice(0, end);\n}\nfunction formatWriteCall(\n\targs: { path?: string; file_path?: string; content?: string } | undefined,\n\toptions: ToolRenderResultOptions,\n\ttheme: Theme,\n\tcache: WriteHighlightCache | undefined,\n\thighlighter: CodeHighlighter,\n\tcwd: string,\n): string {\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tconst fileContent = str(args?.content);\n\tconst pathDisplay = renderToolPath(rawPath, theme, cwd);\n\tlet text = `${theme.fg(\"toolTitle\", theme.bold(\"write\"))} ${pathDisplay}`;\n\n\tif (fileContent === null) {\n\t\ttext += `\\n\\n${theme.fg(\"error\", \"[invalid content arg - expected string]\")}`;\n\t} else if (fileContent) {\n\t\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\t\tlet totalLines: number;\n\t\tlet displayLines: string[];\n\t\tif (lang && cache && !cache.all && !options.expanded) {\n\t\t\t// Collapsed, with only the first lines highlighted. The lines are counted as they are when all are\n\t\t\t// highlighted.\n\t\t\ttotalLines = countCollapsedLines(cache);\n\t\t\tdisplayLines = cache.highlightedLines.slice(0, Math.min(WRITE_COLLAPSED_LINES, totalLines));\n\t\t} else {\n\t\t\tconst renderedLines = lang\n\t\t\t\t? (cache?.highlightedLines ?? highlighter.highlight(replaceTabs(normalizeDisplayText(fileContent)), lang))\n\t\t\t\t: normalizeDisplayText(fileContent).split(\"\\n\");\n\t\t\tconst lines = trimTrailingEmptyLines(renderedLines);\n\t\t\ttotalLines = lines.length;\n\t\t\tdisplayLines = lines.slice(0, options.expanded ? lines.length : WRITE_COLLAPSED_LINES);\n\t\t}\n\t\tconst maxLines = options.expanded ? totalLines : WRITE_COLLAPSED_LINES;\n\t\tconst remaining = totalLines - maxLines;\n\t\ttext += `\\n\\n${displayLines.map((line) => (lang ? line : theme.fg(\"toolOutput\", replaceTabs(line)))).join(\"\\n\")}`;\n\t\tif (remaining > 0) {\n\t\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines, ${totalLines} total,`)} ${keyHint(\"app.tools.expand\", \"to expand\")}${theme.fg(\"muted\", \")\")}`;\n\t\t}\n\t}\n\n\treturn text;\n}\nfunction formatWriteResult(\n\tresult: { content: Array<{ type: string; text?: string; data?: string; mimeType?: string }>; isError?: boolean },\n\ttheme: Theme,\n): string | undefined {\n\tif (!result.isError) {\n\t\treturn undefined;\n\t}\n\tconst output = result.content\n\t\t.filter((c) => c.type === \"text\")\n\t\t.map((c) => c.text || \"\")\n\t\t.join(\"\\n\");\n\tif (!output) {\n\t\treturn undefined;\n\t}\n\treturn `\\n${theme.fg(\"error\", sanitizeTerminalText(output))}`;\n}\n\nexport const writeRenderers: Pick<ToolRenderers, \"renderCall\" | \"renderResult\"> = {\n\trenderCall(args, theme, context) {\n\t\tconst renderArgs = args as { path?: string; file_path?: string; content?: string } | undefined;\n\t\tconst rawPath = str(renderArgs?.file_path ?? renderArgs?.path);\n\t\tconst fileContent = str(renderArgs?.content);\n\t\tconst component =\n\t\t\t(context.lastComponent as WriteCallRenderComponent | undefined) ?? new WriteCallRenderComponent();\n\t\tif (fileContent !== null) {\n\t\t\t// Expanded, the whole file is highlighted once it is complete. Collapsed, the first lines are, as they were\n\t\t\t// while it streamed in.\n\t\t\tif (!context.argsComplete) {\n\t\t\t\tcomponent.cache = updateWriteHighlightCacheIncremental(\n\t\t\t\t\tcomponent.cache,\n\t\t\t\t\trawPath,\n\t\t\t\t\tfileContent,\n\t\t\t\t\tcontext.expanded,\n\t\t\t\t\tcomponent.highlighter,\n\t\t\t\t);\n\t\t\t} else if (context.expanded) {\n\t\t\t\tconst cache = component.cache;\n\t\t\t\tif (!cache?.complete || !cache.all || cache.rawPath !== rawPath || cache.rawContent !== fileContent) {\n\t\t\t\t\tcomponent.cache = rebuildWriteHighlightCacheFull(rawPath, fileContent, component.highlighter);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst cache = component.cache;\n\t\t\t\tif (cache?.complete && !cache.all && cache.rawPath === rawPath && cache.rawContent === fileContent) {\n\t\t\t\t\trefreshWriteHighlightPrefix(cache, component.highlighter);\n\t\t\t\t} else {\n\t\t\t\t\tcomponent.cache = rebuildWriteHighlightCacheCollapsed(rawPath, fileContent, component.highlighter);\n\t\t\t\t\tif (component.cache) component.cache.complete = true;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tcomponent.cache = undefined;\n\t\t}\n\t\tconst cache = component.cache;\n\t\tif (cache && !cache.all && !context.expanded && !context.isPartial && cache.lineCount === undefined) {\n\t\t\tcache.lineCount = countCollapsedLines(cache);\n\t\t\tcache.normalizedLines = cache.normalizedLines.slice(0, WRITE_PARTIAL_FULL_HIGHLIGHT_LINES);\n\t\t}\n\t\tcomponent.setText(\n\t\t\tformatWriteCall(\n\t\t\t\trenderArgs,\n\t\t\t\t{ expanded: context.expanded, isPartial: context.isPartial },\n\t\t\t\ttheme,\n\t\t\t\tcomponent.cache,\n\t\t\t\tcomponent.highlighter,\n\t\t\t\tcontext.cwd,\n\t\t\t),\n\t\t);\n\t\treturn component;\n\t},\n\trenderResult(result, _options, theme, context) {\n\t\tconst output = formatWriteResult({ ...result, isError: context.isError }, theme);\n\t\tif (!output) {\n\t\t\tconst component = (context.lastComponent as Container | undefined) ?? new Container();\n\t\t\tcomponent.clear();\n\t\t\treturn component;\n\t\t}\n\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\ttext.setText(output);\n\t\treturn text;\n\t},\n};\n\ndeclarePathHighlightingRenderers(writeRenderers);\n"]}
|
|
1
|
+
{"version":3,"file":"write.js","sourceRoot":"","sources":["../../../../src/core/tools/renderers/write.ts"],"names":[],"mappings":"AAAA,mHAAmH;AACnH;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAC/F,OAAO,EAAE,OAAO,EAAE,MAAM,2DAA2D,CAAC;AACpF,OAAO,EACN,eAAe,EACf,mBAAmB,EACnB,aAAa,GAEb,MAAM,2CAA2C,CAAC;AAEnD,OA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,GAAG,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,CAAC;QACjF,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,MAAM,SAAS,GAAI,OAAO,CAAC,aAAuC,IAAI,IAAI,SAAS,EAAE,CAAC;YACtF,SAAS,CAAC,KAAK,EAAE,CAAC;YAClB,OAAO,SAAS,CAAC;QAClB,CAAC;QACD,MAAM,IAAI,GAAI,OAAO,CAAC,aAAkC,IAAI,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAC/E,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACrB,OAAO,IAAI,CAAC;IACb,CAAC;CACD,CAAC;AAEF,gCAAgC,CAAC,cAAc,CAAC,CAAC","sourcesContent":["// Derived from Pi-Bolt (MIT, Copyright (c) 2026 OpenSec (Pi-Bolt)), commit b93895d2; modified for HUMAIN Code CLI.\n/**\n * Presentation for the write tool.\n *\n * Renderers live apart from the implementation so a process that only displays tool output does not\n * load the execution path or its typebox parameter schema. `write.ts` spreads these into its\n * definition, so the tool's public shape is unchanged.\n */\n\nimport { Container, sanitizeTerminalText, startsWithText, Text } from \"@earendil-works/pi-tui\";\nimport { keyHint } from \"../../../modes/interactive/components/keybinding-hints.ts\";\nimport {\n\tCodeHighlighter,\n\tgetLanguageFromPath,\n\thighlightCode,\n\ttype Theme,\n} from \"../../../modes/interactive/theme/theme.ts\";\nimport type { ToolRenderers, ToolRenderResultOptions } from \"../../extensions/types.ts\";\nimport { normalizeDisplayText, renderToolPath, replaceTabs, str } from \"../render-utils.ts\";\nimport { declarePathHighlightingRenderers } from \"./highlighting.ts\";\n\ntype WriteHighlightCache = {\n\trawPath: string | null;\n\tlang: string;\n\trawContent: string;\n\tnormalizedLines: string[];\n\t/**\n\t * The lines highlighted. When the call is shown collapsed, only the first lines are: the lines after the ones that can\n\t * be shown are highlighted when the call is expanded (`all`), not as each one arrives and again when the file is\n\t * complete, which for a large file stops everything for as long as highlighting all of it takes.\n\t */\n\thighlightedLines: string[];\n\tall: boolean;\n\t/** Made from the complete file, not from the pieces it arrived in. */\n\tcomplete?: boolean;\n\t/**\n\t * Set once the call has its result and is shown collapsed: the count of lines shown when expanded, with\n\t * normalizedLines cut to the first lines. A collapsed call needs no more of them, and every write of a session stays in\n\t * the chat: keeping each file split into lines again holds more memory than the files themselves.\n\t */\n\tlineCount?: number;\n\tprefixSource?: string;\n};\nclass WriteCallRenderComponent extends Text {\n\t// Line by line highlighting of a call whose content is still streaming.\n\tcache?: WriteHighlightCache;\n\t// A streamed call highlights its first lines on every delta, which stop changing once the file is longer, and a\n\t// complete call highlights the whole file on every update and expand toggle. Either way the row reuses the last\n\t// highlighting; it also holds the only copy of a complete call's displayed source.\n\treadonly highlighter = new CodeHighlighter();\n\n\tconstructor() {\n\t\tsuper(\"\", 0, 0);\n\t}\n\n\toverride invalidate(): void {\n\t\tsuper.invalidate();\n\t\t// Theme changes invalidate the highlighted prefix as well as the rendered text.\n\t\tthis.cache = undefined;\n\t}\n}\nconst WRITE_PARTIAL_FULL_HIGHLIGHT_LINES = 50;\n/** The lines of a collapsed call that are shown. */\nconst WRITE_COLLAPSED_LINES = 10;\nfunction highlightSingleLine(line: string, lang: string): string {\n\tconst highlighted = highlightCode(line, lang);\n\treturn highlighted[0] ?? \"\";\n}\nfunction refreshWriteHighlightPrefix(cache: WriteHighlightCache, highlighter: CodeHighlighter): void {\n\tconst prefixCount = Math.min(WRITE_PARTIAL_FULL_HIGHLIGHT_LINES, cache.normalizedLines.length);\n\tif (prefixCount === 0) return;\n\tconst prefixSource = cache.normalizedLines.slice(0, prefixCount).join(\"\\n\");\n\tif (cache.prefixSource === prefixSource) return;\n\tcache.prefixSource = prefixSource;\n\tconst prefixHighlighted = highlighter.highlight(prefixSource, cache.lang);\n\tfor (let i = 0; i < prefixCount; i++) {\n\t\tcache.highlightedLines[i] =\n\t\t\tprefixHighlighted[i] ?? highlightSingleLine(cache.normalizedLines[i] ?? \"\", cache.lang);\n\t}\n}\nfunction rebuildWriteHighlightCacheFull(\n\trawPath: string | null,\n\tfileContent: string,\n\thighlighter: CodeHighlighter,\n): WriteHighlightCache | undefined {\n\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\tif (!lang) return undefined;\n\tconst displayContent = normalizeDisplayText(fileContent);\n\tconst normalized = replaceTabs(displayContent);\n\treturn {\n\t\trawPath,\n\t\tlang,\n\t\trawContent: fileContent,\n\t\tnormalizedLines: normalized.split(\"\\n\"),\n\t\thighlightedLines: [...highlighter.highlight(normalized, lang)],\n\t\tall: true,\n\t\tcomplete: true,\n\t};\n}\n/** The cache for a call shown collapsed: the first lines highlighted, as they are while the file streams in. */\nfunction rebuildWriteHighlightCacheCollapsed(\n\trawPath: string | null,\n\tfileContent: string,\n\thighlighter: CodeHighlighter,\n): WriteHighlightCache | undefined {\n\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\tif (!lang) return undefined;\n\tconst cache: WriteHighlightCache = {\n\t\trawPath,\n\t\tlang,\n\t\trawContent: fileContent,\n\t\tnormalizedLines: replaceTabs(normalizeDisplayText(fileContent)).split(\"\\n\"),\n\t\thighlightedLines: [],\n\t\tall: false,\n\t};\n\trefreshWriteHighlightPrefix(cache, highlighter);\n\tcache.all = cache.normalizedLines.length <= WRITE_PARTIAL_FULL_HIGHLIGHT_LINES;\n\treturn cache;\n}\n/** Highlights, each on its own, the lines after the first ones that a collapsed call left unhighlighted. */\nfunction highlightRemainingLines(cache: WriteHighlightCache): void {\n\tif (cache.all) return;\n\tfor (\n\t\tlet i = Math.min(WRITE_PARTIAL_FULL_HIGHLIGHT_LINES, cache.normalizedLines.length);\n\t\ti < cache.normalizedLines.length;\n\t\ti++\n\t) {\n\t\tcache.highlightedLines[i] = highlightSingleLine(cache.normalizedLines[i], cache.lang);\n\t}\n\tcache.all = true;\n}\nfunction updateWriteHighlightCacheIncremental(\n\tcache: WriteHighlightCache | undefined,\n\trawPath: string | null,\n\tfileContent: string,\n\texpanded: boolean,\n\thighlighter: CodeHighlighter,\n): WriteHighlightCache | undefined {\n\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\tif (!lang) return undefined;\n\tif (\n\t\t!cache ||\n\t\tcache.lang !== lang ||\n\t\tcache.rawPath !== rawPath ||\n\t\t!startsWithText(fileContent, cache.rawContent) ||\n\t\t(cache.lineCount !== undefined && (expanded || fileContent.length !== cache.rawContent.length))\n\t) {\n\t\treturn expanded\n\t\t\t? rebuildWriteHighlightCacheFull(rawPath, fileContent, highlighter)\n\t\t\t: rebuildWriteHighlightCacheCollapsed(rawPath, fileContent, highlighter);\n\t}\n\tif (expanded) highlightRemainingLines(cache);\n\tif (fileContent.length === cache.rawContent.length) return cache;\n\tcache.complete = false;\n\tif (!expanded) {\n\t\t// Collapsed: the lines are kept, and the first of them highlighted.\n\t\tconst added = replaceTabs(normalizeDisplayText(fileContent.slice(cache.rawContent.length))).split(\"\\n\");\n\t\tcache.rawContent = fileContent;\n\t\tcache.all = false;\n\t\tif (cache.normalizedLines.length === 0) cache.normalizedLines.push(\"\");\n\t\tconst lastLine = cache.normalizedLines.length - 1;\n\t\tcache.normalizedLines[lastLine] += added[0];\n\t\tfor (let i = 1; i < added.length; i++) cache.normalizedLines.push(added[i]);\n\t\trefreshWriteHighlightPrefix(cache, highlighter);\n\t\t// (While the first lines are all the lines, every line is highlighted.)\n\t\tcache.all = cache.normalizedLines.length <= WRITE_PARTIAL_FULL_HIGHLIGHT_LINES;\n\t\treturn cache;\n\t}\n\n\tconst deltaRaw = fileContent.slice(cache.rawContent.length);\n\tconst deltaDisplay = normalizeDisplayText(deltaRaw);\n\tconst deltaNormalized = replaceTabs(deltaDisplay);\n\tcache.rawContent = fileContent;\n\tif (cache.normalizedLines.length === 0) {\n\t\tcache.normalizedLines.push(\"\");\n\t\tcache.highlightedLines.push(\"\");\n\t}\n\n\tconst segments = deltaNormalized.split(\"\\n\");\n\tconst lastIndex = cache.normalizedLines.length - 1;\n\tcache.normalizedLines[lastIndex] += segments[0];\n\tcache.highlightedLines[lastIndex] = highlightSingleLine(cache.normalizedLines[lastIndex], cache.lang);\n\tfor (let i = 1; i < segments.length; i++) {\n\t\tcache.normalizedLines.push(segments[i]);\n\t\tcache.highlightedLines.push(highlightSingleLine(segments[i], cache.lang));\n\t}\n\trefreshWriteHighlightPrefix(cache, highlighter);\n\treturn cache;\n}\n/** The lines of a collapsed cache that are counted: without the empty lines at the end, as formatWriteCall() counts them. */\nfunction countCollapsedLines(cache: WriteHighlightCache): number {\n\tif (cache.lineCount !== undefined) return cache.lineCount;\n\tlet totalLines = cache.normalizedLines.length;\n\t// Without the empty lines at the end, unless an empty line is not empty once highlighted (in a language without a\n\t// highlighter, every line is colored).\n\tif (highlightSingleLine(\"\", cache.lang) === \"\") {\n\t\twhile (totalLines > 0 && cache.normalizedLines[totalLines - 1] === \"\") totalLines--;\n\t}\n\treturn totalLines;\n}\nfunction trimTrailingEmptyLines(lines: readonly string[]): string[] {\n\tlet end = lines.length;\n\twhile (end > 0 && lines[end - 1] === \"\") {\n\t\tend--;\n\t}\n\treturn lines.slice(0, end);\n}\nfunction formatWriteCall(\n\targs: { path?: string; file_path?: string; content?: string } | undefined,\n\toptions: ToolRenderResultOptions,\n\ttheme: Theme,\n\tcache: WriteHighlightCache | undefined,\n\thighlighter: CodeHighlighter,\n\tcwd: string,\n): string {\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tconst fileContent = str(args?.content);\n\tconst pathDisplay = renderToolPath(rawPath, theme, cwd);\n\tlet text = `${theme.fg(\"toolTitle\", theme.bold(\"write\"))} ${pathDisplay}`;\n\n\tif (fileContent === null) {\n\t\ttext += `\\n\\n${theme.fg(\"error\", \"[invalid content arg - expected string]\")}`;\n\t} else if (fileContent) {\n\t\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\t\tlet totalLines: number;\n\t\tlet displayLines: string[];\n\t\tif (lang && cache && !cache.all && !options.expanded) {\n\t\t\t// Collapsed, with only the first lines highlighted. The lines are counted as they are when all are\n\t\t\t// highlighted.\n\t\t\ttotalLines = countCollapsedLines(cache);\n\t\t\tdisplayLines = cache.highlightedLines.slice(0, Math.min(WRITE_COLLAPSED_LINES, totalLines));\n\t\t} else {\n\t\t\tconst renderedLines = lang\n\t\t\t\t? (cache?.highlightedLines ?? highlighter.highlight(replaceTabs(normalizeDisplayText(fileContent)), lang))\n\t\t\t\t: normalizeDisplayText(fileContent).split(\"\\n\");\n\t\t\tconst lines = trimTrailingEmptyLines(renderedLines);\n\t\t\ttotalLines = lines.length;\n\t\t\tdisplayLines = lines.slice(0, options.expanded ? lines.length : WRITE_COLLAPSED_LINES);\n\t\t}\n\t\tconst maxLines = options.expanded ? totalLines : WRITE_COLLAPSED_LINES;\n\t\tconst remaining = totalLines - maxLines;\n\t\ttext += `\\n\\n${displayLines.map((line) => (lang ? line : theme.fg(\"toolOutput\", replaceTabs(line)))).join(\"\\n\")}`;\n\t\tif (remaining > 0) {\n\t\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines, ${totalLines} total,`)} ${keyHint(\"app.tools.expand\", \"to expand\")}${theme.fg(\"muted\", \")\")}`;\n\t\t}\n\t}\n\n\treturn text;\n}\nfunction formatWriteResult(\n\tresult: { content: Array<{ type: string; text?: string; data?: string; mimeType?: string }>; isError?: boolean },\n\ttheme: Theme,\n): string | undefined {\n\tif (!result.isError) {\n\t\treturn undefined;\n\t}\n\tconst output = result.content\n\t\t.filter((c) => c.type === \"text\")\n\t\t.map((c) => c.text || \"\")\n\t\t.join(\"\\n\");\n\tif (!output) {\n\t\treturn undefined;\n\t}\n\treturn `\\n${theme.fg(\"error\", sanitizeTerminalText(output))}`;\n}\n\nexport const writeRenderers: Pick<ToolRenderers, \"renderCall\" | \"renderResult\"> = {\n\trenderCall(args, theme, context) {\n\t\tconst renderArgs = args as { path?: string; file_path?: string; content?: string } | undefined;\n\t\tconst rawPath = str(renderArgs?.file_path ?? renderArgs?.path);\n\t\tconst fileContent = str(renderArgs?.content);\n\t\tconst component =\n\t\t\t(context.lastComponent as WriteCallRenderComponent | undefined) ?? new WriteCallRenderComponent();\n\t\tif (fileContent !== null) {\n\t\t\t// Expanded, the whole file is highlighted once it is complete. Collapsed, the first lines are, as they were\n\t\t\t// while it streamed in.\n\t\t\tif (!context.argsComplete) {\n\t\t\t\tcomponent.cache = updateWriteHighlightCacheIncremental(\n\t\t\t\t\tcomponent.cache,\n\t\t\t\t\trawPath,\n\t\t\t\t\tfileContent,\n\t\t\t\t\tcontext.expanded,\n\t\t\t\t\tcomponent.highlighter,\n\t\t\t\t);\n\t\t\t} else if (context.expanded) {\n\t\t\t\tconst cache = component.cache;\n\t\t\t\tif (!cache?.complete || !cache.all || cache.rawPath !== rawPath || cache.rawContent !== fileContent) {\n\t\t\t\t\tcomponent.cache = rebuildWriteHighlightCacheFull(rawPath, fileContent, component.highlighter);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst cache = component.cache;\n\t\t\t\tif (cache?.complete && !cache.all && cache.rawPath === rawPath && cache.rawContent === fileContent) {\n\t\t\t\t\trefreshWriteHighlightPrefix(cache, component.highlighter);\n\t\t\t\t} else {\n\t\t\t\t\tcomponent.cache = rebuildWriteHighlightCacheCollapsed(rawPath, fileContent, component.highlighter);\n\t\t\t\t\tif (component.cache) component.cache.complete = true;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tcomponent.cache = undefined;\n\t\t}\n\t\tconst cache = component.cache;\n\t\tif (cache && !cache.all && !context.expanded && !context.isPartial && cache.lineCount === undefined) {\n\t\t\tcache.lineCount = countCollapsedLines(cache);\n\t\t\tcache.normalizedLines = cache.normalizedLines.slice(0, WRITE_PARTIAL_FULL_HIGHLIGHT_LINES);\n\t\t}\n\t\tcomponent.setText(\n\t\t\tformatWriteCall(\n\t\t\t\trenderArgs,\n\t\t\t\t{ expanded: context.expanded, isPartial: context.isPartial },\n\t\t\t\ttheme,\n\t\t\t\tcomponent.cache,\n\t\t\t\tcomponent.highlighter,\n\t\t\t\tcontext.cwd,\n\t\t\t),\n\t\t);\n\t\treturn component;\n\t},\n\trenderResult(result, _options, theme, context) {\n\t\tconst output = formatWriteResult({ ...result, isError: context.isError }, theme);\n\t\tif (!output) {\n\t\t\tconst component = (context.lastComponent as Container | undefined) ?? new Container();\n\t\t\tcomponent.clear();\n\t\t\treturn component;\n\t\t}\n\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\ttext.setText(output);\n\t\treturn text;\n\t},\n};\n\ndeclarePathHighlightingRenderers(writeRenderers);\n"]}
|
|
@@ -49,6 +49,17 @@ export interface SubagentUsageStats {
|
|
|
49
49
|
contextTokens: number;
|
|
50
50
|
turns: number;
|
|
51
51
|
}
|
|
52
|
+
/** Settled attempt accounting without its task, transcript, stderr or error payload. */
|
|
53
|
+
export interface SubagentAttemptResult {
|
|
54
|
+
attempt: number;
|
|
55
|
+
model?: string;
|
|
56
|
+
thinking?: string;
|
|
57
|
+
exitCode: number;
|
|
58
|
+
stopReason?: string;
|
|
59
|
+
usage: SubagentUsageStats;
|
|
60
|
+
usageEntries?: UsageEntry[];
|
|
61
|
+
usageIncomplete?: boolean;
|
|
62
|
+
}
|
|
52
63
|
export interface SubagentSingleResult {
|
|
53
64
|
agent: string;
|
|
54
65
|
agentSource: "user" | "project" | "unknown";
|
|
@@ -68,7 +79,14 @@ export interface SubagentSingleResult {
|
|
|
68
79
|
stderrTruncated?: boolean;
|
|
69
80
|
/** True when at least one child stdout line exceeded the line bound and was dropped. */
|
|
70
81
|
stdoutTruncated?: boolean;
|
|
82
|
+
/** Usage of this result's attempt only; retry charges are never folded into it. */
|
|
71
83
|
usage: SubagentUsageStats;
|
|
84
|
+
/** Completed native attempts, including the final attempt; at most three records. */
|
|
85
|
+
attempts?: SubagentAttemptResult[];
|
|
86
|
+
/** All native attempts' additive usage; contextTokens remains the current attempt's context size. */
|
|
87
|
+
totalUsage?: SubagentUsageStats;
|
|
88
|
+
/** totalUsage is a lower bound because at least one attempt reported incomplete usage. */
|
|
89
|
+
totalUsageIncomplete?: boolean;
|
|
72
90
|
/** Per-attempt auxiliary usage, retained for exact pricing and rounding by consumers. */
|
|
73
91
|
usageEntries?: UsageEntry[];
|
|
74
92
|
/** At least one received request had missing or invalid token counters. */
|
|
@@ -150,6 +168,10 @@ export interface SubagentProgressResult {
|
|
|
150
168
|
attempt?: number;
|
|
151
169
|
exitCode: number;
|
|
152
170
|
usage: SubagentUsageStats;
|
|
171
|
+
/** Completed attempts; while running, the current attempt is represented only by usage. */
|
|
172
|
+
attempts?: SubagentAttemptResult[];
|
|
173
|
+
totalUsage?: SubagentUsageStats;
|
|
174
|
+
totalUsageIncomplete?: boolean;
|
|
153
175
|
usageEntries?: UsageEntry[];
|
|
154
176
|
usageIncomplete?: boolean;
|
|
155
177
|
model?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subagent.d.ts","sourceRoot":"","sources":["../../../src/core/tools/subagent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAOH,OAAO,KAAK,EAAO,OAAO,EAAgB,MAAM,uBAAuB,CAAC;AAOxE,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAM/B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AA4BxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAGvD,OAAO,EAGN,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EAEzB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,KAAK,gBAAgB,EAAsB,MAAM,8BAA8B,CAAC;AAQzF,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,CAAC;A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("(usage incomplete)");
|
|
205
207
|
return parts.join(" ");
|
|
206
208
|
}
|
|
207
209
|
function formatToolCall(toolName, args, themeFg) {
|
|
@@ -287,6 +289,9 @@ export function toProgressDetails(results) {
|
|
|
287
289
|
attempt: result.attempt,
|
|
288
290
|
exitCode: result.exitCode,
|
|
289
291
|
usage: result.usage,
|
|
292
|
+
...(result.attempts ? { attempts: result.attempts } : {}),
|
|
293
|
+
...(result.totalUsage ? { totalUsage: result.totalUsage } : {}),
|
|
294
|
+
...(result.totalUsageIncomplete ? { totalUsageIncomplete: true } : {}),
|
|
290
295
|
...(result.usageEntries ? { usageEntries: result.usageEntries } : {}),
|
|
291
296
|
...(result.usageIncomplete ? { usageIncomplete: true } : {}),
|
|
292
297
|
model: result.model,
|
|
@@ -355,6 +360,16 @@ function getDisplayItems(messages) {
|
|
|
355
360
|
}
|
|
356
361
|
return items;
|
|
357
362
|
}
|
|
363
|
+
function attachAttemptUsage(result, previous) {
|
|
364
|
+
result.attempts = [...previous];
|
|
365
|
+
result.totalUsage = { ...result.usage };
|
|
366
|
+
result.totalUsageIncomplete = result.usageIncomplete || previous.some((attempt) => attempt.usageIncomplete);
|
|
367
|
+
for (const attempt of previous) {
|
|
368
|
+
for (const key of ["input", "output", "cacheRead", "cacheWrite", "cost", "turns"]) {
|
|
369
|
+
result.totalUsage[key] += attempt.usage[key];
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
358
373
|
function isProgressResult(result) {
|
|
359
374
|
return "latestText" in result;
|
|
360
375
|
}
|
|
@@ -1673,6 +1688,7 @@ export function createSubagentToolDefinition(cwd) {
|
|
|
1673
1688
|
let model = g.model;
|
|
1674
1689
|
let thinking = g.thinking;
|
|
1675
1690
|
let result;
|
|
1691
|
+
const attempts = [];
|
|
1676
1692
|
const worker = observation.workerAt(index);
|
|
1677
1693
|
let evidence = newAttemptEvidence();
|
|
1678
1694
|
let everStarted = false;
|
|
@@ -1683,6 +1699,7 @@ export function createSubagentToolDefinition(cwd) {
|
|
|
1683
1699
|
result = await runSingleAgent(defaultCwd, agents, discovery.diagnostics, g.agent, g.task, g.cwd, g.isolation, undefined, model, parentModel, signal, (partial) => {
|
|
1684
1700
|
const currentResult = partial.details?.results[0];
|
|
1685
1701
|
if (currentResult) {
|
|
1702
|
+
attachAttemptUsage(currentResult, attempts);
|
|
1686
1703
|
const progressResults = toProgressDetails(allResults);
|
|
1687
1704
|
progressResults[index] = currentResult;
|
|
1688
1705
|
emitParallelUpdate(progressResults);
|
|
@@ -1697,6 +1714,18 @@ export function createSubagentToolDefinition(cwd) {
|
|
|
1697
1714
|
traceChild,
|
|
1698
1715
|
fileEvidenceSink: getFileEvidenceSink(ctx?.sessionManager),
|
|
1699
1716
|
});
|
|
1717
|
+
attachAttemptUsage(result, attempts);
|
|
1718
|
+
attempts.push({
|
|
1719
|
+
attempt,
|
|
1720
|
+
model: result.model,
|
|
1721
|
+
thinking: result.thinking,
|
|
1722
|
+
exitCode: result.exitCode,
|
|
1723
|
+
stopReason: result.stopReason,
|
|
1724
|
+
usage: result.usage,
|
|
1725
|
+
...(result.usageEntries ? { usageEntries: result.usageEntries } : {}),
|
|
1726
|
+
...(result.usageIncomplete ? { usageIncomplete: true } : {}),
|
|
1727
|
+
});
|
|
1728
|
+
result.attempts = [...attempts];
|
|
1700
1729
|
everStarted ||= evidence.started;
|
|
1701
1730
|
if (!isFailedResult(result)) {
|
|
1702
1731
|
emitTaskEvent({ type: "complete", taskId: g.id, attempt, at: now() });
|
|
@@ -1942,14 +1971,24 @@ export function createSubagentToolDefinition(cwd) {
|
|
|
1942
1971
|
return new Text(text, 0, 0);
|
|
1943
1972
|
}
|
|
1944
1973
|
const aggregateUsage = (results) => {
|
|
1945
|
-
const total = {
|
|
1974
|
+
const total = {
|
|
1975
|
+
input: 0,
|
|
1976
|
+
output: 0,
|
|
1977
|
+
cacheRead: 0,
|
|
1978
|
+
cacheWrite: 0,
|
|
1979
|
+
cost: 0,
|
|
1980
|
+
turns: 0,
|
|
1981
|
+
usageIncomplete: false,
|
|
1982
|
+
};
|
|
1946
1983
|
for (const r of results) {
|
|
1947
|
-
|
|
1948
|
-
total.
|
|
1949
|
-
total.
|
|
1950
|
-
total.
|
|
1951
|
-
total.
|
|
1952
|
-
total.
|
|
1984
|
+
const usage = r.totalUsage ?? r.usage;
|
|
1985
|
+
total.input += usage.input;
|
|
1986
|
+
total.output += usage.output;
|
|
1987
|
+
total.cacheRead += usage.cacheRead;
|
|
1988
|
+
total.cacheWrite += usage.cacheWrite;
|
|
1989
|
+
total.cost += usage.cost;
|
|
1990
|
+
total.turns += usage.turns;
|
|
1991
|
+
total.usageIncomplete ||= r.totalUsageIncomplete === true || r.usageIncomplete === true;
|
|
1953
1992
|
}
|
|
1954
1993
|
return total;
|
|
1955
1994
|
};
|