apex-code 0.2.0 → 0.3.0

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.
Files changed (49) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +1 -1
  3. package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
  4. package/dist/core/export-html/tool-renderer.js +3 -0
  5. package/dist/core/export-html/tool-renderer.js.map +1 -1
  6. package/dist/core/extensions/types.d.ts +7 -0
  7. package/dist/core/extensions/types.d.ts.map +1 -1
  8. package/dist/core/extensions/types.js.map +1 -1
  9. package/dist/core/keybindings.d.ts +1 -1
  10. package/dist/core/keybindings.d.ts.map +1 -1
  11. package/dist/core/keybindings.js +1 -1
  12. package/dist/core/keybindings.js.map +1 -1
  13. package/dist/core/tools/bash.d.ts +6 -0
  14. package/dist/core/tools/bash.d.ts.map +1 -1
  15. package/dist/core/tools/bash.js +71 -24
  16. package/dist/core/tools/bash.js.map +1 -1
  17. package/dist/core/tools/edit.d.ts.map +1 -1
  18. package/dist/core/tools/edit.js +47 -7
  19. package/dist/core/tools/edit.js.map +1 -1
  20. package/dist/core/tools/shell-operation.d.ts +34 -0
  21. package/dist/core/tools/shell-operation.d.ts.map +1 -0
  22. package/dist/core/tools/shell-operation.js +69 -0
  23. package/dist/core/tools/shell-operation.js.map +1 -0
  24. package/dist/modes/interactive/components/keybinding-hints.d.ts +7 -1
  25. package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
  26. package/dist/modes/interactive/components/keybinding-hints.js +3 -2
  27. package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
  28. package/dist/modes/interactive/components/model-row.d.ts +84 -0
  29. package/dist/modes/interactive/components/model-row.d.ts.map +1 -0
  30. package/dist/modes/interactive/components/model-row.js +206 -0
  31. package/dist/modes/interactive/components/model-row.js.map +1 -0
  32. package/dist/modes/interactive/components/model-selector.d.ts +39 -4
  33. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  34. package/dist/modes/interactive/components/model-selector.js +158 -27
  35. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  36. package/dist/modes/interactive/components/tool-execution.d.ts +2 -0
  37. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  38. package/dist/modes/interactive/components/tool-execution.js +8 -0
  39. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  40. package/dist/modes/interactive/interactive-mode.d.ts +53 -1
  41. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  42. package/dist/modes/interactive/interactive-mode.js +99 -26
  43. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  44. package/dist/modes/interactive/theme/theme.d.ts +16 -0
  45. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  46. package/dist/modes/interactive/theme/theme.js +19 -1
  47. package/dist/modes/interactive/theme/theme.js.map +1 -1
  48. package/npm-shrinkwrap.json +5 -5
  49. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"edit.js","sourceRoot":"","sources":["../../../src/core/tools/edit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAEtE,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAC/B,OAAO,EAAE,MAAM,IAAI,QAAQ,EAAE,QAAQ,IAAI,UAAU,EAAE,SAAS,IAAI,WAAW,EAAE,MAAM,aAAa,CAAC;AACnG,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,4CAA4C,CAAC;AAExE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,wBAAwB,EAA8B,MAAM,8BAA8B,CAAC;AAIpG,OAAO,EAAE,yBAAy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AAQ,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YAC3C,OAAO,SAAS,CAAC;QAAA,CACjB;KACD,CAAC;AAAA,CACF;AAED,MAAM,UAAU,cAAc,CAAC,GAAW,EAAE,OAAyB,EAAgC;IACpG,OAAO,kBAAkB,CAAC,wBAAwB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AAAA,CAClE","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { Box, Container, Spacer, Text } from \"@earendil-works/pi-tui\";\nimport type { AgentTool } from \"apex-code-agent-core\";\nimport { constants } from \"fs\";\nimport { access as fsAccess, readFile as fsReadFile, writeFile as fsWriteFile } from \"fs/promises\";\nimport { type Static, Type } from \"typebox\";\nimport { renderDiff } from \"../../modes/interactive/components/diff.ts\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { splitBom } from \"../../utils/text.ts\";\nimport { getExperimentalToolSampling } from \"../experimental.ts\";\nimport { getPreparedPathOperation, type PreparedPathOperation } from \"../permissions/operations.ts\";\nimport type { PermissionPreview } from \"../permissions/responder.ts\";\nimport type { ApexToolDefinition, EvidenceRecord } from \"./contract.ts\";\nimport type { DiagnosticsOperations, DiagnosticsOutcome } from \"./diagnostics.ts\";\nimport { diagnosticEvidenceForPath, formatDiagnosticsOutcome } from \"./diagnostics.ts\";\nimport {\n\tapplyEditsToNormalizedContent,\n\tcomputeEditsDiff,\n\tcomputeEditsDiffFromContent,\n\tdetectLineEnding,\n\ttype Edit,\n\ttype EditDiffError,\n\ttype EditDiffResult,\n\tgenerateDiffString,\n\tgenerateUnifiedPatch,\n\tnormalizeToLF,\n\trestoreLineEndings,\n} from \"./edit-diff.ts\";\nimport { withFileMutationQueue } from \"./file-mutation-queue.ts\";\nimport { createPathPermissionSpec } from \"./path-permission.ts\";\nimport { readPreparedPath, resolveToCwd, writePreparedPath } from \"./path-utils.ts\";\nimport { renderToolPath, str } from \"./render-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\ntype EditPreview = EditDiffResult | EditDiffError;\n\ntype EditRenderState = {\n\tcallComponent?: EditCallRenderComponent;\n};\n\nconst replaceEditSchema = Type.Object(\n\t{\n\t\toldText: Type.String({\n\t\t\tdescription:\n\t\t\t\t\"Exact text for one targeted replacement. It must be unique in the original file and must not overlap with any other edits[].oldText in the same call.\",\n\t\t}),\n\t\tnewText: Type.String({ description: \"Replacement text for this targeted edit.\" }),\n\t},\n\t{},\n);\n\nconst editSchema = Type.Object(\n\t{\n\t\tpath: Type.String({ description: \"Path to the file to edit (relative or absolute)\" }),\n\t\tedits: Type.Array(replaceEditSchema, {\n\t\t\tdescription:\n\t\t\t\t\"One or more targeted replacements. Each edit is matched against the original file, not incrementally. Do not include overlapping or nested edits. If two changes touch the same block or nearby lines, merge them into one edit instead.\",\n\t\t}),\n\t},\n\t{},\n);\n\nexport const editToolSystemPromptContribution = {\n\tsnippet: \"Make precise file edits with exact text replacement, including multiple disjoint edits in one call\",\n\tguidelines: [\n\t\t\"Use edit for precise changes (edits[].oldText must match exactly)\",\n\t\t\"When changing multiple separate locations in one file, use one edit call with multiple entries in edits[] instead of multiple edit calls\",\n\t\t\"Each edits[].oldText is matched against the original file, not after earlier edits are applied. Do not emit overlapping or nested edits. Merge nearby changes into one edit.\",\n\t\t\"Keep edits[].oldText as small as possible while still being unique in the file. Do not pad with large unchanged regions.\",\n\t],\n} as const;\n\nexport type EditToolInput = Static<typeof editSchema>;\ntype LegacyEditToolInput = EditToolInput & {\n\toldText?: unknown;\n\tnewText?: unknown;\n};\n\nfunction sha256(value: string): string {\n\treturn createHash(\"sha256\").update(value).digest(\"hex\");\n}\n\ntype SingleEditInput = { oldText: string; newText: string };\n\nfunction isSingleEditInput(value: unknown): value is SingleEditInput {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) {\n\t\treturn false;\n\t}\n\n\tconst edit = value as Record<string, unknown>;\n\treturn typeof edit.oldText === \"string\" && typeof edit.newText === \"string\";\n}\n\nexport interface EditToolDetails {\n\t/** Display-oriented diff of the changes made */\n\tdiff: string;\n\t/** Standard unified patch of the changes made */\n\tpatch: string;\n\t/** Line number of the first change in the new file (for editor navigation) */\n\tfirstChangedLine?: number;\n\t/** Present only when `EditToolOptions.diagnosticsOperations` is configured (LSP.4). */\n\tdiagnostics?: DiagnosticsOutcome;\n}\n\n/**\n * Pluggable operations for the edit tool.\n * Override these to delegate file editing to remote systems (for example SSH).\n */\nexport interface EditOperations {\n\t/** Read file contents as a Buffer */\n\treadFile: (absolutePath: string) => Promise<Buffer>;\n\t/** Write content to a file */\n\twriteFile: (absolutePath: string, content: string) => Promise<void>;\n\t/** Check if file is readable and writable (throw if not) */\n\taccess: (absolutePath: string) => Promise<void>;\n\t/**\n\t * Execute a gate-prepared edit no-follow against the authorized target.\n\t * Required for gated calls: when a prepared operation exists, pathname reads\n\t * and writes are never used, so an unset implementation fails closed.\n\t */\n\treadPreparedFile?: (operation: PreparedPathOperation) => Buffer;\n\twritePreparedFile?: (operation: PreparedPathOperation, content: Buffer) => void;\n}\n\nconst defaultEditOperations: EditOperations = {\n\treadFile: (path) => fsReadFile(path),\n\twriteFile: (path, content) => fsWriteFile(path, content, \"utf-8\"),\n\taccess: (path) => fsAccess(path, constants.R_OK | constants.W_OK),\n\treadPreparedFile: (operation) => readPreparedPath(operation),\n\twritePreparedFile: (operation, content) => writePreparedPath(operation, content),\n};\n\nexport interface EditToolOptions {\n\t/** Custom operations for file editing. Default: local filesystem */\n\toperations?: EditOperations;\n\t/**\n\t * Optional post-mutation diagnostics (LSP.4). Absent by default -- byte-identical\n\t * existing behavior. When present, called inside `withFileMutationQueue` after the\n\t * write succeeds and before the queue releases, matching `TestOperations`/\n\t * `GrepOperations`' injection pattern (`test.ts:28`, `grep.ts:58`).\n\t */\n\tdiagnosticsOperations?: DiagnosticsOperations;\n}\n\n/** A preview is a courtesy, so it never costs more than a screen or two of reading. */\nconst PREVIEW_MAX_BYTES = 512 * 1024;\nconst PREVIEW_MAX_LINES = 40;\n\n/**\n * Describe the edit for the person deciding whether to allow it.\n *\n * Reads through the operation `prepareCall` stored rather than resolving the\n * pathname again, so a target swapped after authorization fails here exactly as\n * it fails the write. `readPreparedPath` throws in that case and the gate turns\n * the throw into a stated reason, which is the outcome a reader needs: better a\n * prompt that admits it cannot show the change than a diff of the wrong file.\n */\nfunction previewEdit(params: EditToolInput): PermissionPreview {\n\tconst prepared = getPreparedPathOperation(params);\n\tif (!prepared) return { kind: \"unavailable\", reason: \"No authorized target was prepared for this call\" };\n\tif (prepared.kind === \"path-new\") {\n\t\treturn { kind: \"summary\", lines: [`Create ${params.path}`] };\n\t}\n\n\tconst buffer = readPreparedPath(prepared, PREVIEW_MAX_BYTES + 1);\n\tif (buffer.byteLength > PREVIEW_MAX_BYTES) {\n\t\treturn { kind: \"unavailable\", reason: `File is larger than ${PREVIEW_MAX_BYTES / 1024}KB, so no diff is shown` };\n\t}\n\tif (buffer.includes(0)) {\n\t\treturn { kind: \"unavailable\", reason: \"File is binary, so there is no diff to show\" };\n\t}\n\n\tconst result = computeEditsDiffFromContent(params.path, buffer.toString(\"utf-8\"), params.edits as Edit[]);\n\tif (\"error\" in result) return { kind: \"unavailable\", reason: result.error };\n\n\tconst lines = result.diff.split(\"\\n\");\n\tconst shown = lines.slice(0, PREVIEW_MAX_LINES);\n\treturn { kind: \"diff\", path: params.path, lines: shown, omittedLines: lines.length - shown.length };\n}\n\nfunction prepareEditArguments(input: unknown): EditToolInput {\n\tif (!input || typeof input !== \"object\") {\n\t\treturn input as EditToolInput;\n\t}\n\n\tconst args = input as Record<string, unknown>;\n\n\t// Some models (Opus 4.6, GLM-5.1) send edits as a JSON string instead of an array.\n\t// Others send a single edit object instead of a one-element edits array.\n\tif (typeof args.edits === \"string\") {\n\t\ttry {\n\t\t\tconst parsed = JSON.parse(args.edits);\n\t\t\tif (Array.isArray(parsed)) {\n\t\t\t\targs.edits = parsed;\n\t\t\t} else if (isSingleEditInput(parsed)) {\n\t\t\t\targs.edits = [parsed];\n\t\t\t}\n\t\t} catch {}\n\t} else if (isSingleEditInput(args.edits)) {\n\t\targs.edits = [args.edits];\n\t}\n\n\tconst legacy = args as LegacyEditToolInput;\n\tif (typeof legacy.oldText !== \"string\" || typeof legacy.newText !== \"string\") {\n\t\treturn args as EditToolInput;\n\t}\n\n\tconst edits = Array.isArray(legacy.edits) ? [...legacy.edits] : [];\n\tedits.push({ oldText: legacy.oldText, newText: legacy.newText });\n\tconst { oldText: _oldText, newText: _newText, ...rest } = legacy;\n\treturn { ...rest, edits } as EditToolInput;\n}\n\nfunction validateEditInput(input: EditToolInput): { path: string; edits: Edit[] } {\n\tif (!Array.isArray(input.edits) || input.edits.length === 0) {\n\t\tthrow new Error(\"Edit tool input is invalid. edits must contain at least one replacement.\");\n\t}\n\treturn { path: input.path, edits: input.edits };\n}\n\ntype RenderableEditArgs = {\n\tpath?: string;\n\tfile_path?: string;\n\tedits?: Edit[];\n\toldText?: string;\n\tnewText?: string;\n};\n\ntype EditToolResultLike = {\n\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\tdetails?: EditToolDetails;\n};\n\ntype EditCallRenderComponent = Box & {\n\tpreview?: EditPreview;\n\tpreviewArgsKey?: string;\n\tpreviewPending?: boolean;\n\tsettledError?: boolean;\n};\n\nfunction createEditCallRenderComponent(): EditCallRenderComponent {\n\treturn Object.assign(new Box(1, 1, (text: string) => text), {\n\t\tpreview: undefined as EditPreview | undefined,\n\t\tpreviewArgsKey: undefined as string | undefined,\n\t\tpreviewPending: false,\n\t\tsettledError: false,\n\t});\n}\n\nfunction getEditCallRenderComponent(state: EditRenderState, lastComponent: unknown): EditCallRenderComponent {\n\tif (lastComponent instanceof Box) {\n\t\tconst component = lastComponent as EditCallRenderComponent;\n\t\tstate.callComponent = component;\n\t\treturn component;\n\t}\n\tif (state.callComponent) {\n\t\treturn state.callComponent;\n\t}\n\tconst component = createEditCallRenderComponent();\n\tstate.callComponent = component;\n\treturn component;\n}\n\nfunction getRenderablePreviewInput(args: RenderableEditArgs | undefined): { path: string; edits: Edit[] } | null {\n\tif (!args) {\n\t\treturn null;\n\t}\n\n\tconst path = typeof args.path === \"string\" ? args.path : typeof args.file_path === \"string\" ? args.file_path : null;\n\tif (!path) {\n\t\treturn null;\n\t}\n\n\tif (\n\t\tArray.isArray(args.edits) &&\n\t\targs.edits.length > 0 &&\n\t\targs.edits.every((edit) => typeof edit?.oldText === \"string\" && typeof edit?.newText === \"string\")\n\t) {\n\t\treturn { path, edits: args.edits };\n\t}\n\n\tif (typeof args.oldText === \"string\" && typeof args.newText === \"string\") {\n\t\treturn { path, edits: [{ oldText: args.oldText, newText: args.newText }] };\n\t}\n\n\treturn null;\n}\n\nfunction formatEditCall(args: RenderableEditArgs | undefined, theme: Theme, cwd: string): string {\n\tconst pathDisplay = renderToolPath(str(args?.file_path ?? args?.path), theme, cwd);\n\treturn `${theme.fg(\"toolTitle\", theme.bold(\"edit\"))} ${pathDisplay}`;\n}\n\nfunction formatEditResult(\n\targs: RenderableEditArgs | undefined,\n\tpreview: EditPreview | undefined,\n\tresult: EditToolResultLike,\n\ttheme: Theme,\n\tisError: boolean,\n): string | undefined {\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tconst previewDiff = preview && !(\"error\" in preview) ? preview.diff : undefined;\n\tconst previewError = preview && \"error\" in preview ? preview.error : undefined;\n\tif (isError) {\n\t\tconst errorText = result.content\n\t\t\t.filter((c) => c.type === \"text\")\n\t\t\t.map((c) => c.text || \"\")\n\t\t\t.join(\"\\n\");\n\t\tif (!errorText || errorText === previewError) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn theme.fg(\"error\", errorText);\n\t}\n\n\tconst resultDiff = result.details?.diff;\n\tif (resultDiff && resultDiff !== previewDiff) {\n\t\treturn renderDiff(resultDiff, { filePath: rawPath ?? undefined });\n\t}\n\n\treturn undefined;\n}\n\nfunction getEditHeaderBg(\n\tpreview: EditPreview | undefined,\n\tsettledError: boolean | undefined,\n\ttheme: Theme,\n): (text: string) => string {\n\tif (preview) {\n\t\tif (\"error\" in preview) {\n\t\t\treturn (text: string) => theme.bg(\"toolErrorBg\", text);\n\t\t}\n\t\treturn (text: string) => theme.bg(\"toolSuccessBg\", text);\n\t}\n\tif (settledError) {\n\t\treturn (text: string) => theme.bg(\"toolErrorBg\", text);\n\t}\n\treturn (text: string) => theme.bg(\"toolPendingBg\", text);\n}\n\nfunction buildEditCallComponent(\n\tcomponent: EditCallRenderComponent,\n\targs: RenderableEditArgs | undefined,\n\ttheme: Theme,\n\tcwd: string,\n): EditCallRenderComponent {\n\tcomponent.setBgFn(getEditHeaderBg(component.preview, component.settledError, theme));\n\tcomponent.clear();\n\tcomponent.addChild(new Text(formatEditCall(args, theme, cwd), 0, 0));\n\n\tif (!component.preview) {\n\t\treturn component;\n\t}\n\n\tconst body =\n\t\t\"error\" in component.preview ? theme.fg(\"error\", component.preview.error) : renderDiff(component.preview.diff);\n\tcomponent.addChild(new Spacer(1));\n\tcomponent.addChild(new Text(body, 0, 0));\n\treturn component;\n}\n\nfunction setEditPreview(\n\tcomponent: EditCallRenderComponent,\n\tpreview: EditPreview,\n\targsKey: string | undefined,\n): boolean {\n\tconst current = component.preview;\n\tconst changed =\n\t\tcurrent === undefined ||\n\t\t(\"error\" in current && \"error\" in preview\n\t\t\t? current.error !== preview.error\n\t\t\t: \"error\" in current !== \"error\" in preview) ||\n\t\t(!(\"error\" in current) &&\n\t\t\t!(\"error\" in preview) &&\n\t\t\t(current.diff !== preview.diff || current.firstChangedLine !== preview.firstChangedLine));\n\tcomponent.preview = preview;\n\tcomponent.previewArgsKey = argsKey;\n\tcomponent.previewPending = false;\n\treturn changed;\n}\n\nexport function createEditToolDefinition(\n\tcwd: string,\n\toptions?: EditToolOptions,\n): ApexToolDefinition<typeof editSchema, EditToolDetails | undefined, EditRenderState> {\n\tconst ops = options?.operations ?? defaultEditOperations;\n\tconst diagnosticsOperations = options?.diagnosticsOperations;\n\treturn {\n\t\tname: \"edit\",\n\t\tlabel: \"edit\",\n\t\tdescription:\n\t\t\t\"Edit a single file using exact text replacement. Every edits[].oldText must match a unique, non-overlapping region of the original file. If two changes affect the same block or nearby lines, merge them into one edit instead of emitting overlapping edits. Do not include large unchanged regions just to connect distant changes.\",\n\t\tpromptSnippet: editToolSystemPromptContribution.snippet,\n\t\tpromptGuidelines: [...editToolSystemPromptContribution.guidelines],\n\t\tparameters: editSchema,\n\t\tcontract: {\n\t\t\tcapabilities: new Set([\"fs.read\", \"fs.write\"]),\n\t\t\tpermission: createPathPermissionSpec({\n\t\t\t\tcwd,\n\t\t\t\tdefaultBehavior: \"ask\",\n\t\t\t\tverb: \"Edit\",\n\t\t\t\tgetPath: (params) => params.path,\n\t\t\t\tpreviewCall: (params) => previewEdit(params as EditToolInput),\n\t\t\t}),\n\t\t\tcontext: { resultRecoverable: true, deferSchema: false },\n\t\t\tevidence: {\n\t\t\t\temits: new Set(diagnosticsOperations ? [\"diff\", \"diagnostic\"] : [\"diff\"]),\n\t\t\t\tcapture: (params, result) => {\n\t\t\t\t\tconst patch = result.details?.patch;\n\t\t\t\t\tconst records: EvidenceRecord[] = patch\n\t\t\t\t\t\t? [{ kind: \"diff\", path: params.path, patchHash: sha256(patch) }]\n\t\t\t\t\t\t: [{ kind: \"diff\", path: params.path }];\n\t\t\t\t\tconst diagnostics = result.details?.diagnostics;\n\t\t\t\t\tif (diagnostics) records.push(diagnosticEvidenceForPath(params.path, diagnostics));\n\t\t\t\t\treturn records;\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tconstrainedSampling: getExperimentalToolSampling(),\n\t\trenderShell: \"self\",\n\t\tprepareArguments: prepareEditArguments,\n\t\tasync execute(_toolCallId, input: EditToolInput, signal?: AbortSignal, _onUpdate?, _ctx?) {\n\t\t\tconst { path, edits } = validateEditInput(input);\n\t\t\tconst prepared = getPreparedPathOperation(input);\n\t\t\tconst absolutePath = prepared?.path.value ?? resolveToCwd(path, cwd);\n\t\t\tif (prepared && (!ops.readPreparedFile || !ops.writePreparedFile)) {\n\t\t\t\tthrow new Error(\"No safe prepared edit operation is available for this gated edit\");\n\t\t\t}\n\n\t\t\treturn withFileMutationQueue(absolutePath, async () => {\n\t\t\t\t// Do not reject from an abort event listener here: that would release the\n\t\t\t\t// mutation queue while an in-flight filesystem operation may still finish.\n\t\t\t\t// Checking signal.aborted after each await observes the same aborts while\n\t\t\t\t// keeping the queue locked until the current operation has settled.\n\t\t\t\tconst throwIfAborted = (): void => {\n\t\t\t\t\tif (signal?.aborted) throw new Error(\"Operation aborted\");\n\t\t\t\t};\n\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Check if file exists (skipped for a gated call: the prepared operation\n\t\t\t\t// already proves existence, and the no-follow read enforces the identity).\n\t\t\t\ttry {\n\t\t\t\t\tif (!prepared) await ops.access(absolutePath);\n\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\tthrowIfAborted();\n\t\t\t\t\tconst errorMessage =\n\t\t\t\t\t\terror instanceof Error && \"code\" in error ? `Error code: ${error.code}` : String(error);\n\t\t\t\t\tthrow new Error(`Could not edit file: ${path}. ${errorMessage}.`);\n\t\t\t\t}\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Read the file.\n\t\t\t\tconst buffer = prepared ? ops.readPreparedFile!(prepared) : await ops.readFile(absolutePath);\n\t\t\t\tconst rawContent = buffer.toString(\"utf-8\");\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Strip BOM before matching. The model will not include an invisible BOM in oldText.\n\t\t\t\tconst { bom, text: content } = splitBom(rawContent);\n\t\t\t\tconst originalEnding = detectLineEnding(content);\n\t\t\t\tconst normalizedContent = normalizeToLF(content);\n\t\t\t\tconst { baseContent, newContent } = applyEditsToNormalizedContent(normalizedContent, edits, path);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\tconst finalContent = bom + restoreLineEndings(newContent, originalEnding);\n\t\t\t\tif (prepared) ops.writePreparedFile!(prepared, Buffer.from(finalContent, \"utf-8\"));\n\t\t\t\telse await ops.writeFile(absolutePath, finalContent);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\tconst diffResult = generateDiffString(baseContent, newContent);\n\t\t\t\tconst patch = generateUnifiedPatch(path, baseContent, newContent);\n\t\t\t\tconst successText = `Successfully replaced ${edits.length} block(s) in ${path}.`;\n\n\t\t\t\tif (diagnosticsOperations) {\n\t\t\t\t\tconst diagnostics = await diagnosticsOperations.afterMutation(absolutePath, signal);\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\", text: `${successText}\\n\\n${formatDiagnosticsOutcome(diagnostics)}` }],\n\t\t\t\t\t\tdetails: { diff: diffResult.diff, patch, firstChangedLine: diffResult.firstChangedLine, diagnostics },\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: successText }],\n\t\t\t\t\tdetails: { diff: diffResult.diff, patch, firstChangedLine: diffResult.firstChangedLine },\n\t\t\t\t};\n\t\t\t});\n\t\t},\n\t\trenderCall(args, theme, context) {\n\t\t\tconst component = getEditCallRenderComponent(context.state, context.lastComponent);\n\t\t\tconst previewInput = getRenderablePreviewInput(args as RenderableEditArgs | undefined);\n\t\t\tconst argsKey = previewInput\n\t\t\t\t? JSON.stringify({ path: previewInput.path, edits: previewInput.edits })\n\t\t\t\t: undefined;\n\n\t\t\tif (component.previewArgsKey !== argsKey) {\n\t\t\t\tcomponent.preview = undefined;\n\t\t\t\tcomponent.previewArgsKey = argsKey;\n\t\t\t\tcomponent.previewPending = false;\n\t\t\t\tcomponent.settledError = false;\n\t\t\t}\n\n\t\t\tif (context.argsComplete && previewInput && !component.preview && !component.previewPending) {\n\t\t\t\tcomponent.previewPending = true;\n\t\t\t\tconst requestKey = argsKey;\n\t\t\t\tvoid computeEditsDiff(previewInput.path, previewInput.edits, context.cwd).then((preview) => {\n\t\t\t\t\tif (component.previewArgsKey === requestKey) {\n\t\t\t\t\t\tsetEditPreview(component, preview, requestKey);\n\t\t\t\t\t\tcontext.invalidate();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn buildEditCallComponent(component, args, theme, context.cwd);\n\t\t},\n\t\trenderResult(result, _options, theme, context) {\n\t\t\tconst callComponent = context.state.callComponent;\n\t\t\tconst previewInput = getRenderablePreviewInput(context.args as RenderableEditArgs | undefined);\n\t\t\tconst argsKey = previewInput\n\t\t\t\t? JSON.stringify({ path: previewInput.path, edits: previewInput.edits })\n\t\t\t\t: undefined;\n\t\t\tconst typedResult = result as EditToolResultLike;\n\t\t\tconst resultDiff = !context.isError ? typedResult.details?.diff : undefined;\n\t\t\tlet changed = false;\n\t\t\tif (callComponent) {\n\t\t\t\tif (typeof resultDiff === \"string\") {\n\t\t\t\t\tchanged =\n\t\t\t\t\t\tsetEditPreview(\n\t\t\t\t\t\t\tcallComponent,\n\t\t\t\t\t\t\t{ diff: resultDiff, firstChangedLine: typedResult.details?.firstChangedLine },\n\t\t\t\t\t\t\targsKey,\n\t\t\t\t\t\t) || changed;\n\t\t\t\t}\n\t\t\t\tif (callComponent.settledError !== context.isError) {\n\t\t\t\t\tcallComponent.settledError = context.isError;\n\t\t\t\t\tchanged = true;\n\t\t\t\t}\n\t\t\t\tif (changed) {\n\t\t\t\t\tbuildEditCallComponent(\n\t\t\t\t\t\tcallComponent,\n\t\t\t\t\t\tcontext.args as RenderableEditArgs | undefined,\n\t\t\t\t\t\ttheme,\n\t\t\t\t\t\tcontext.cwd,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst output = formatEditResult(context.args, callComponent?.preview, typedResult, theme, context.isError);\n\t\t\tconst component = (context.lastComponent as Container | undefined) ?? new Container();\n\t\t\tcomponent.clear();\n\t\t\tif (!output) {\n\t\t\t\treturn component;\n\t\t\t}\n\t\t\tcomponent.addChild(new Spacer(1));\n\t\t\tcomponent.addChild(new Text(output, 1, 0));\n\t\t\treturn component;\n\t\t},\n\t};\n}\n\nexport function createEditTool(cwd: string, options?: EditToolOptions): AgentTool<typeof editSchema> {\n\treturn wrapToolDefinition(createEditToolDefinition(cwd, options));\n}\n"]}
1
+ {"version":3,"file":"edit.js","sourceRoot":"","sources":["../../../src/core/tools/edit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAEtE,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAC/B,OAAO,EAAE,MAAM,IAAI,QAAQ,EAAE,QAAQ,IAAI,UAAU,EAAE,SAAS,IAAI,WAAW,EAAE,MAAM,aAAa,CAAC;AACnG,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,4CAA4C,CAAC;AAExE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,wBAAwB,EAA8B,MAAM,8BAA8B,CAAC;AAIpG,OAAO,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AACvF,OAAO,EACN,6BAA6B,EAC7B,gBAAgB,EAChB,2BAA2B,EAC3B,gBAAgB,EAIhB,kBAAkB,EAClB,oBAAoB,EACpB,aAAa,EACb,kBAAkB,GAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpF,OAAO,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAA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AE,OAAyB,EAAgC;IACpG,OAAO,kBAAkB,CAAC,wBAAwB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AAAA,CAClE","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { Box, Container, Spacer, Text } from \"@earendil-works/pi-tui\";\nimport type { AgentTool } from \"apex-code-agent-core\";\nimport { constants } from \"fs\";\nimport { access as fsAccess, readFile as fsReadFile, writeFile as fsWriteFile } from \"fs/promises\";\nimport { type Static, Type } from \"typebox\";\nimport { renderDiff } from \"../../modes/interactive/components/diff.ts\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { splitBom } from \"../../utils/text.ts\";\nimport { getExperimentalToolSampling } from \"../experimental.ts\";\nimport { getPreparedPathOperation, type PreparedPathOperation } from \"../permissions/operations.ts\";\nimport type { PermissionPreview } from \"../permissions/responder.ts\";\nimport type { ApexToolDefinition, EvidenceRecord } from \"./contract.ts\";\nimport type { DiagnosticsOperations, DiagnosticsOutcome } from \"./diagnostics.ts\";\nimport { diagnosticEvidenceForPath, formatDiagnosticsOutcome } from \"./diagnostics.ts\";\nimport {\n\tapplyEditsToNormalizedContent,\n\tcomputeEditsDiff,\n\tcomputeEditsDiffFromContent,\n\tdetectLineEnding,\n\ttype Edit,\n\ttype EditDiffError,\n\ttype EditDiffResult,\n\tgenerateDiffString,\n\tgenerateUnifiedPatch,\n\tnormalizeToLF,\n\trestoreLineEndings,\n} from \"./edit-diff.ts\";\nimport { withFileMutationQueue } from \"./file-mutation-queue.ts\";\nimport { createPathPermissionSpec } from \"./path-permission.ts\";\nimport { readPreparedPath, resolveToCwd, writePreparedPath } from \"./path-utils.ts\";\nimport { renderToolPath, str } from \"./render-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\ntype EditPreview = EditDiffResult | EditDiffError;\n\ntype EditRenderState = {\n\tcallComponent?: EditCallRenderComponent;\n};\n\nconst replaceEditSchema = Type.Object(\n\t{\n\t\toldText: Type.String({\n\t\t\tdescription:\n\t\t\t\t\"Exact text for one targeted replacement. It must be unique in the original file and must not overlap with any other edits[].oldText in the same call.\",\n\t\t}),\n\t\tnewText: Type.String({ description: \"Replacement text for this targeted edit.\" }),\n\t},\n\t{},\n);\n\nconst editSchema = Type.Object(\n\t{\n\t\tpath: Type.String({ description: \"Path to the file to edit (relative or absolute)\" }),\n\t\tedits: Type.Array(replaceEditSchema, {\n\t\t\tdescription:\n\t\t\t\t\"One or more targeted replacements. Each edit is matched against the original file, not incrementally. Do not include overlapping or nested edits. If two changes touch the same block or nearby lines, merge them into one edit instead.\",\n\t\t}),\n\t},\n\t{},\n);\n\nexport const editToolSystemPromptContribution = {\n\tsnippet: \"Make precise file edits with exact text replacement, including multiple disjoint edits in one call\",\n\tguidelines: [\n\t\t\"Use edit for precise changes (edits[].oldText must match exactly)\",\n\t\t\"When changing multiple separate locations in one file, use one edit call with multiple entries in edits[] instead of multiple edit calls\",\n\t\t\"Each edits[].oldText is matched against the original file, not after earlier edits are applied. Do not emit overlapping or nested edits. Merge nearby changes into one edit.\",\n\t\t\"Keep edits[].oldText as small as possible while still being unique in the file. Do not pad with large unchanged regions.\",\n\t],\n} as const;\n\nexport type EditToolInput = Static<typeof editSchema>;\ntype LegacyEditToolInput = EditToolInput & {\n\toldText?: unknown;\n\tnewText?: unknown;\n};\n\nfunction sha256(value: string): string {\n\treturn createHash(\"sha256\").update(value).digest(\"hex\");\n}\n\ntype SingleEditInput = { oldText: string; newText: string };\n\nfunction isSingleEditInput(value: unknown): value is SingleEditInput {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) {\n\t\treturn false;\n\t}\n\n\tconst edit = value as Record<string, unknown>;\n\treturn typeof edit.oldText === \"string\" && typeof edit.newText === \"string\";\n}\n\nexport interface EditToolDetails {\n\t/** Display-oriented diff of the changes made */\n\tdiff: string;\n\t/** Standard unified patch of the changes made */\n\tpatch: string;\n\t/** Line number of the first change in the new file (for editor navigation) */\n\tfirstChangedLine?: number;\n\t/** Present only when `EditToolOptions.diagnosticsOperations` is configured (LSP.4). */\n\tdiagnostics?: DiagnosticsOutcome;\n}\n\n/**\n * Pluggable operations for the edit tool.\n * Override these to delegate file editing to remote systems (for example SSH).\n */\nexport interface EditOperations {\n\t/** Read file contents as a Buffer */\n\treadFile: (absolutePath: string) => Promise<Buffer>;\n\t/** Write content to a file */\n\twriteFile: (absolutePath: string, content: string) => Promise<void>;\n\t/** Check if file is readable and writable (throw if not) */\n\taccess: (absolutePath: string) => Promise<void>;\n\t/**\n\t * Execute a gate-prepared edit no-follow against the authorized target.\n\t * Required for gated calls: when a prepared operation exists, pathname reads\n\t * and writes are never used, so an unset implementation fails closed.\n\t */\n\treadPreparedFile?: (operation: PreparedPathOperation) => Buffer;\n\twritePreparedFile?: (operation: PreparedPathOperation, content: Buffer) => void;\n}\n\nconst defaultEditOperations: EditOperations = {\n\treadFile: (path) => fsReadFile(path),\n\twriteFile: (path, content) => fsWriteFile(path, content, \"utf-8\"),\n\taccess: (path) => fsAccess(path, constants.R_OK | constants.W_OK),\n\treadPreparedFile: (operation) => readPreparedPath(operation),\n\twritePreparedFile: (operation, content) => writePreparedPath(operation, content),\n};\n\nexport interface EditToolOptions {\n\t/** Custom operations for file editing. Default: local filesystem */\n\toperations?: EditOperations;\n\t/**\n\t * Optional post-mutation diagnostics (LSP.4). Absent by default -- byte-identical\n\t * existing behavior. When present, called inside `withFileMutationQueue` after the\n\t * write succeeds and before the queue releases, matching `TestOperations`/\n\t * `GrepOperations`' injection pattern (`test.ts:28`, `grep.ts:58`).\n\t */\n\tdiagnosticsOperations?: DiagnosticsOperations;\n}\n\n/** A preview is a courtesy, so it never costs more than a screen or two of reading. */\nconst PREVIEW_MAX_BYTES = 512 * 1024;\nconst PREVIEW_MAX_LINES = 40;\n\n/**\n * Describe the edit for the person deciding whether to allow it.\n *\n * Reads through the operation `prepareCall` stored rather than resolving the\n * pathname again, so a target swapped after authorization fails here exactly as\n * it fails the write. `readPreparedPath` throws in that case and the gate turns\n * the throw into a stated reason, which is the outcome a reader needs: better a\n * prompt that admits it cannot show the change than a diff of the wrong file.\n */\nfunction previewEdit(params: EditToolInput): PermissionPreview {\n\tconst prepared = getPreparedPathOperation(params);\n\tif (!prepared) return { kind: \"unavailable\", reason: \"No authorized target was prepared for this call\" };\n\tif (prepared.kind === \"path-new\") {\n\t\treturn { kind: \"summary\", lines: [`Create ${params.path}`] };\n\t}\n\n\tconst buffer = readPreparedPath(prepared, PREVIEW_MAX_BYTES + 1);\n\tif (buffer.byteLength > PREVIEW_MAX_BYTES) {\n\t\treturn { kind: \"unavailable\", reason: `File is larger than ${PREVIEW_MAX_BYTES / 1024}KB, so no diff is shown` };\n\t}\n\tif (buffer.includes(0)) {\n\t\treturn { kind: \"unavailable\", reason: \"File is binary, so there is no diff to show\" };\n\t}\n\n\tconst result = computeEditsDiffFromContent(params.path, buffer.toString(\"utf-8\"), params.edits as Edit[]);\n\tif (\"error\" in result) return { kind: \"unavailable\", reason: result.error };\n\n\tconst lines = result.diff.split(\"\\n\");\n\tconst shown = lines.slice(0, PREVIEW_MAX_LINES);\n\treturn { kind: \"diff\", path: params.path, lines: shown, omittedLines: lines.length - shown.length };\n}\n\nfunction prepareEditArguments(input: unknown): EditToolInput {\n\tif (!input || typeof input !== \"object\") {\n\t\treturn input as EditToolInput;\n\t}\n\n\tconst args = input as Record<string, unknown>;\n\n\t// Some models (Opus 4.6, GLM-5.1) send edits as a JSON string instead of an array.\n\t// Others send a single edit object instead of a one-element edits array.\n\tif (typeof args.edits === \"string\") {\n\t\ttry {\n\t\t\tconst parsed = JSON.parse(args.edits);\n\t\t\tif (Array.isArray(parsed)) {\n\t\t\t\targs.edits = parsed;\n\t\t\t} else if (isSingleEditInput(parsed)) {\n\t\t\t\targs.edits = [parsed];\n\t\t\t}\n\t\t} catch {}\n\t} else if (isSingleEditInput(args.edits)) {\n\t\targs.edits = [args.edits];\n\t}\n\n\tconst legacy = args as LegacyEditToolInput;\n\tif (typeof legacy.oldText !== \"string\" || typeof legacy.newText !== \"string\") {\n\t\treturn args as EditToolInput;\n\t}\n\n\tconst edits = Array.isArray(legacy.edits) ? [...legacy.edits] : [];\n\tedits.push({ oldText: legacy.oldText, newText: legacy.newText });\n\tconst { oldText: _oldText, newText: _newText, ...rest } = legacy;\n\treturn { ...rest, edits } as EditToolInput;\n}\n\nfunction validateEditInput(input: EditToolInput): { path: string; edits: Edit[] } {\n\tif (!Array.isArray(input.edits) || input.edits.length === 0) {\n\t\tthrow new Error(\"Edit tool input is invalid. edits must contain at least one replacement.\");\n\t}\n\treturn { path: input.path, edits: input.edits };\n}\n\ntype RenderableEditArgs = {\n\tpath?: string;\n\tfile_path?: string;\n\tedits?: Edit[];\n\toldText?: string;\n\tnewText?: string;\n};\n\ntype EditToolResultLike = {\n\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\tdetails?: EditToolDetails;\n};\n\ntype EditCallRenderComponent = Box & {\n\tpreview?: EditPreview;\n\tpreviewArgsKey?: string;\n\tpreviewPending?: boolean;\n\tsettledError?: boolean;\n};\n\nfunction createEditCallRenderComponent(): EditCallRenderComponent {\n\treturn Object.assign(new Box(1, 1, (text: string) => text), {\n\t\tpreview: undefined as EditPreview | undefined,\n\t\tpreviewArgsKey: undefined as string | undefined,\n\t\tpreviewPending: false,\n\t\tsettledError: false,\n\t});\n}\n\nfunction getEditCallRenderComponent(state: EditRenderState, lastComponent: unknown): EditCallRenderComponent {\n\tif (lastComponent instanceof Box) {\n\t\tconst component = lastComponent as EditCallRenderComponent;\n\t\tstate.callComponent = component;\n\t\treturn component;\n\t}\n\tif (state.callComponent) {\n\t\treturn state.callComponent;\n\t}\n\tconst component = createEditCallRenderComponent();\n\tstate.callComponent = component;\n\treturn component;\n}\n\nfunction getRenderablePreviewInput(args: RenderableEditArgs | undefined): { path: string; edits: Edit[] } | null {\n\tif (!args) {\n\t\treturn null;\n\t}\n\n\tconst path = typeof args.path === \"string\" ? args.path : typeof args.file_path === \"string\" ? args.file_path : null;\n\tif (!path) {\n\t\treturn null;\n\t}\n\n\tif (\n\t\tArray.isArray(args.edits) &&\n\t\targs.edits.length > 0 &&\n\t\targs.edits.every((edit) => typeof edit?.oldText === \"string\" && typeof edit?.newText === \"string\")\n\t) {\n\t\treturn { path, edits: args.edits };\n\t}\n\n\tif (typeof args.oldText === \"string\" && typeof args.newText === \"string\") {\n\t\treturn { path, edits: [{ oldText: args.oldText, newText: args.newText }] };\n\t}\n\n\treturn null;\n}\n\n/**\n * Added and removed line counts read off a unified diff.\n *\n * `+++`/`---` file headers open with the same characters as content lines, so\n * they are skipped explicitly rather than by counting the first two lines,\n * which a diff without headers would not have.\n */\nfunction countChangedLines(diff: string): { added: number; removed: number } {\n\tlet added = 0;\n\tlet removed = 0;\n\tfor (const line of diff.split(\"\\n\")) {\n\t\tif (line.startsWith(\"+++\") || line.startsWith(\"---\")) continue;\n\t\tif (line.startsWith(\"+\")) added++;\n\t\telse if (line.startsWith(\"-\")) removed++;\n\t}\n\treturn { added, removed };\n}\n\n/** The one line a collapsed diff leaves behind, so the edit is still legible as an edit. */\nfunction formatChangeSummary(diff: string, theme: Theme): string {\n\tconst { added, removed } = countChangedLines(diff);\n\tconst parts: string[] = [];\n\tif (added > 0) parts.push(theme.fg(\"toolDiffAdded\", `+${added}`));\n\tif (removed > 0) parts.push(theme.fg(\"toolDiffRemoved\", `-${removed}`));\n\tif (parts.length === 0) return theme.fg(\"dim\", \"no line changes\");\n\treturn parts.join(theme.fg(\"dim\", \" \"));\n}\n\nfunction formatEditCall(args: RenderableEditArgs | undefined, theme: Theme, cwd: string): string {\n\tconst pathDisplay = renderToolPath(str(args?.file_path ?? args?.path), theme, cwd);\n\treturn `${theme.fg(\"toolTitle\", theme.bold(\"edit\"))} ${pathDisplay}`;\n}\n\nfunction formatEditResult(\n\targs: RenderableEditArgs | undefined,\n\tpreview: EditPreview | undefined,\n\tresult: EditToolResultLike,\n\ttheme: Theme,\n\tisError: boolean,\n\tdiffsExpanded: boolean,\n): string | undefined {\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tconst previewDiff = preview && !(\"error\" in preview) ? preview.diff : undefined;\n\tconst previewError = preview && \"error\" in preview ? preview.error : undefined;\n\tif (isError) {\n\t\tconst errorText = result.content\n\t\t\t.filter((c) => c.type === \"text\")\n\t\t\t.map((c) => c.text || \"\")\n\t\t\t.join(\"\\n\");\n\t\tif (!errorText || errorText === previewError) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn theme.fg(\"error\", errorText);\n\t}\n\n\tconst resultDiff = result.details?.diff;\n\tif (resultDiff && resultDiff !== previewDiff) {\n\t\treturn diffsExpanded\n\t\t\t? renderDiff(resultDiff, { filePath: rawPath ?? undefined })\n\t\t\t: formatChangeSummary(resultDiff, theme);\n\t}\n\n\treturn undefined;\n}\n\nfunction getEditHeaderBg(\n\tpreview: EditPreview | undefined,\n\tsettledError: boolean | undefined,\n\ttheme: Theme,\n): (text: string) => string {\n\tif (preview) {\n\t\tif (\"error\" in preview) {\n\t\t\treturn (text: string) => theme.bg(\"toolErrorBg\", text);\n\t\t}\n\t\treturn (text: string) => theme.bg(\"toolSuccessBg\", text);\n\t}\n\tif (settledError) {\n\t\treturn (text: string) => theme.bg(\"toolErrorBg\", text);\n\t}\n\treturn (text: string) => theme.bg(\"toolPendingBg\", text);\n}\n\nfunction buildEditCallComponent(\n\tcomponent: EditCallRenderComponent,\n\targs: RenderableEditArgs | undefined,\n\ttheme: Theme,\n\tcwd: string,\n\tdiffsExpanded: boolean,\n): EditCallRenderComponent {\n\tcomponent.setBgFn(getEditHeaderBg(component.preview, component.settledError, theme));\n\tcomponent.clear();\n\tcomponent.addChild(new Text(formatEditCall(args, theme, cwd), 0, 0));\n\n\tif (!component.preview) {\n\t\treturn component;\n\t}\n\n\t// An error always shows, whatever the detail level. A collapsed diff still\n\t// leaves its counts behind, so the row never becomes a bare filename.\n\tconst body =\n\t\t\"error\" in component.preview\n\t\t\t? theme.fg(\"error\", component.preview.error)\n\t\t\t: diffsExpanded\n\t\t\t\t? renderDiff(component.preview.diff)\n\t\t\t\t: formatChangeSummary(component.preview.diff, theme);\n\tcomponent.addChild(new Spacer(1));\n\tcomponent.addChild(new Text(body, 0, 0));\n\treturn component;\n}\n\nfunction setEditPreview(\n\tcomponent: EditCallRenderComponent,\n\tpreview: EditPreview,\n\targsKey: string | undefined,\n): boolean {\n\tconst current = component.preview;\n\tconst changed =\n\t\tcurrent === undefined ||\n\t\t(\"error\" in current && \"error\" in preview\n\t\t\t? current.error !== preview.error\n\t\t\t: \"error\" in current !== \"error\" in preview) ||\n\t\t(!(\"error\" in current) &&\n\t\t\t!(\"error\" in preview) &&\n\t\t\t(current.diff !== preview.diff || current.firstChangedLine !== preview.firstChangedLine));\n\tcomponent.preview = preview;\n\tcomponent.previewArgsKey = argsKey;\n\tcomponent.previewPending = false;\n\treturn changed;\n}\n\nexport function createEditToolDefinition(\n\tcwd: string,\n\toptions?: EditToolOptions,\n): ApexToolDefinition<typeof editSchema, EditToolDetails | undefined, EditRenderState> {\n\tconst ops = options?.operations ?? defaultEditOperations;\n\tconst diagnosticsOperations = options?.diagnosticsOperations;\n\treturn {\n\t\tname: \"edit\",\n\t\tlabel: \"edit\",\n\t\tdescription:\n\t\t\t\"Edit a single file using exact text replacement. Every edits[].oldText must match a unique, non-overlapping region of the original file. If two changes affect the same block or nearby lines, merge them into one edit instead of emitting overlapping edits. Do not include large unchanged regions just to connect distant changes.\",\n\t\tpromptSnippet: editToolSystemPromptContribution.snippet,\n\t\tpromptGuidelines: [...editToolSystemPromptContribution.guidelines],\n\t\tparameters: editSchema,\n\t\tcontract: {\n\t\t\tcapabilities: new Set([\"fs.read\", \"fs.write\"]),\n\t\t\tpermission: createPathPermissionSpec({\n\t\t\t\tcwd,\n\t\t\t\tdefaultBehavior: \"ask\",\n\t\t\t\tverb: \"Edit\",\n\t\t\t\tgetPath: (params) => params.path,\n\t\t\t\tpreviewCall: (params) => previewEdit(params as EditToolInput),\n\t\t\t}),\n\t\t\tcontext: { resultRecoverable: true, deferSchema: false },\n\t\t\tevidence: {\n\t\t\t\temits: new Set(diagnosticsOperations ? [\"diff\", \"diagnostic\"] : [\"diff\"]),\n\t\t\t\tcapture: (params, result) => {\n\t\t\t\t\tconst patch = result.details?.patch;\n\t\t\t\t\tconst records: EvidenceRecord[] = patch\n\t\t\t\t\t\t? [{ kind: \"diff\", path: params.path, patchHash: sha256(patch) }]\n\t\t\t\t\t\t: [{ kind: \"diff\", path: params.path }];\n\t\t\t\t\tconst diagnostics = result.details?.diagnostics;\n\t\t\t\t\tif (diagnostics) records.push(diagnosticEvidenceForPath(params.path, diagnostics));\n\t\t\t\t\treturn records;\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tconstrainedSampling: getExperimentalToolSampling(),\n\t\trenderShell: \"self\",\n\t\tprepareArguments: prepareEditArguments,\n\t\tasync execute(_toolCallId, input: EditToolInput, signal?: AbortSignal, _onUpdate?, _ctx?) {\n\t\t\tconst { path, edits } = validateEditInput(input);\n\t\t\tconst prepared = getPreparedPathOperation(input);\n\t\t\tconst absolutePath = prepared?.path.value ?? resolveToCwd(path, cwd);\n\t\t\tif (prepared && (!ops.readPreparedFile || !ops.writePreparedFile)) {\n\t\t\t\tthrow new Error(\"No safe prepared edit operation is available for this gated edit\");\n\t\t\t}\n\n\t\t\treturn withFileMutationQueue(absolutePath, async () => {\n\t\t\t\t// Do not reject from an abort event listener here: that would release the\n\t\t\t\t// mutation queue while an in-flight filesystem operation may still finish.\n\t\t\t\t// Checking signal.aborted after each await observes the same aborts while\n\t\t\t\t// keeping the queue locked until the current operation has settled.\n\t\t\t\tconst throwIfAborted = (): void => {\n\t\t\t\t\tif (signal?.aborted) throw new Error(\"Operation aborted\");\n\t\t\t\t};\n\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Check if file exists (skipped for a gated call: the prepared operation\n\t\t\t\t// already proves existence, and the no-follow read enforces the identity).\n\t\t\t\ttry {\n\t\t\t\t\tif (!prepared) await ops.access(absolutePath);\n\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\tthrowIfAborted();\n\t\t\t\t\tconst errorMessage =\n\t\t\t\t\t\terror instanceof Error && \"code\" in error ? `Error code: ${error.code}` : String(error);\n\t\t\t\t\tthrow new Error(`Could not edit file: ${path}. ${errorMessage}.`);\n\t\t\t\t}\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Read the file.\n\t\t\t\tconst buffer = prepared ? ops.readPreparedFile!(prepared) : await ops.readFile(absolutePath);\n\t\t\t\tconst rawContent = buffer.toString(\"utf-8\");\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Strip BOM before matching. The model will not include an invisible BOM in oldText.\n\t\t\t\tconst { bom, text: content } = splitBom(rawContent);\n\t\t\t\tconst originalEnding = detectLineEnding(content);\n\t\t\t\tconst normalizedContent = normalizeToLF(content);\n\t\t\t\tconst { baseContent, newContent } = applyEditsToNormalizedContent(normalizedContent, edits, path);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\tconst finalContent = bom + restoreLineEndings(newContent, originalEnding);\n\t\t\t\tif (prepared) ops.writePreparedFile!(prepared, Buffer.from(finalContent, \"utf-8\"));\n\t\t\t\telse await ops.writeFile(absolutePath, finalContent);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\tconst diffResult = generateDiffString(baseContent, newContent);\n\t\t\t\tconst patch = generateUnifiedPatch(path, baseContent, newContent);\n\t\t\t\tconst successText = `Successfully replaced ${edits.length} block(s) in ${path}.`;\n\n\t\t\t\tif (diagnosticsOperations) {\n\t\t\t\t\tconst diagnostics = await diagnosticsOperations.afterMutation(absolutePath, signal);\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [{ type: \"text\", text: `${successText}\\n\\n${formatDiagnosticsOutcome(diagnostics)}` }],\n\t\t\t\t\t\tdetails: { diff: diffResult.diff, patch, firstChangedLine: diffResult.firstChangedLine, diagnostics },\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: successText }],\n\t\t\t\t\tdetails: { diff: diffResult.diff, patch, firstChangedLine: diffResult.firstChangedLine },\n\t\t\t\t};\n\t\t\t});\n\t\t},\n\t\trenderCall(args, theme, context) {\n\t\t\tconst component = getEditCallRenderComponent(context.state, context.lastComponent);\n\t\t\tconst previewInput = getRenderablePreviewInput(args as RenderableEditArgs | undefined);\n\t\t\tconst argsKey = previewInput\n\t\t\t\t? JSON.stringify({ path: previewInput.path, edits: previewInput.edits })\n\t\t\t\t: undefined;\n\n\t\t\tif (component.previewArgsKey !== argsKey) {\n\t\t\t\tcomponent.preview = undefined;\n\t\t\t\tcomponent.previewArgsKey = argsKey;\n\t\t\t\tcomponent.previewPending = false;\n\t\t\t\tcomponent.settledError = false;\n\t\t\t}\n\n\t\t\tif (context.argsComplete && previewInput && !component.preview && !component.previewPending) {\n\t\t\t\tcomponent.previewPending = true;\n\t\t\t\tconst requestKey = argsKey;\n\t\t\t\tvoid computeEditsDiff(previewInput.path, previewInput.edits, context.cwd).then((preview) => {\n\t\t\t\t\tif (component.previewArgsKey === requestKey) {\n\t\t\t\t\t\tsetEditPreview(component, preview, requestKey);\n\t\t\t\t\t\tcontext.invalidate();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn buildEditCallComponent(component, args, theme, context.cwd, context.editDiffsExpanded);\n\t\t},\n\t\trenderResult(result, _options, theme, context) {\n\t\t\tconst callComponent = context.state.callComponent;\n\t\t\tconst previewInput = getRenderablePreviewInput(context.args as RenderableEditArgs | undefined);\n\t\t\tconst argsKey = previewInput\n\t\t\t\t? JSON.stringify({ path: previewInput.path, edits: previewInput.edits })\n\t\t\t\t: undefined;\n\t\t\tconst typedResult = result as EditToolResultLike;\n\t\t\tconst resultDiff = !context.isError ? typedResult.details?.diff : undefined;\n\t\t\tlet changed = false;\n\t\t\tif (callComponent) {\n\t\t\t\tif (typeof resultDiff === \"string\") {\n\t\t\t\t\tchanged =\n\t\t\t\t\t\tsetEditPreview(\n\t\t\t\t\t\t\tcallComponent,\n\t\t\t\t\t\t\t{ diff: resultDiff, firstChangedLine: typedResult.details?.firstChangedLine },\n\t\t\t\t\t\t\targsKey,\n\t\t\t\t\t\t) || changed;\n\t\t\t\t}\n\t\t\t\tif (callComponent.settledError !== context.isError) {\n\t\t\t\t\tcallComponent.settledError = context.isError;\n\t\t\t\t\tchanged = true;\n\t\t\t\t}\n\t\t\t\tif (changed) {\n\t\t\t\t\tbuildEditCallComponent(\n\t\t\t\t\t\tcallComponent,\n\t\t\t\t\t\tcontext.args as RenderableEditArgs | undefined,\n\t\t\t\t\t\ttheme,\n\t\t\t\t\t\tcontext.cwd,\n\t\t\t\t\t\tcontext.editDiffsExpanded,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst output = formatEditResult(\n\t\t\t\tcontext.args,\n\t\t\t\tcallComponent?.preview,\n\t\t\t\ttypedResult,\n\t\t\t\ttheme,\n\t\t\t\tcontext.isError,\n\t\t\t\tcontext.editDiffsExpanded,\n\t\t\t);\n\t\t\tconst component = (context.lastComponent as Container | undefined) ?? new Container();\n\t\t\tcomponent.clear();\n\t\t\tif (!output) {\n\t\t\t\treturn component;\n\t\t\t}\n\t\t\tcomponent.addChild(new Spacer(1));\n\t\t\tcomponent.addChild(new Text(output, 1, 0));\n\t\t\treturn component;\n\t\t},\n\t};\n}\n\nexport function createEditTool(cwd: string, options?: EditToolOptions): AgentTool<typeof editSchema> {\n\treturn wrapToolDefinition(createEditToolDefinition(cwd, options));\n}\n"]}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * The one shell operation a set of tool arguments requests.
3
+ *
4
+ * The shell schema advertises a flat bag of fields because providers ignore
5
+ * `anyOf` (see `toolUnion` in `contract.ts`). That advertisement cannot enforce
6
+ * anything: a model may send any combination of fields, and it does. Consumers
7
+ * that each re-read the raw bag disagreed about which operation a mixed call
8
+ * requested — permissions keyed on `command`, execution keyed on `handle` — so
9
+ * an allowed command could carry a denied background kill past the gate.
10
+ *
11
+ * Parse once, here, and let permissions, execution, display, and evidence all
12
+ * read the same answer.
13
+ */
14
+ export type ShellOperation = {
15
+ kind: "run";
16
+ command: string;
17
+ timeout: number | undefined;
18
+ background: boolean;
19
+ } | {
20
+ kind: "retrieve";
21
+ handle: string;
22
+ } | {
23
+ kind: "kill";
24
+ handle: string;
25
+ };
26
+ export type ShellOperationParse = {
27
+ ok: true;
28
+ operation: ShellOperation;
29
+ } | {
30
+ ok: false;
31
+ reason: string;
32
+ };
33
+ export declare function parseShellOperation(params: unknown): ShellOperationParse;
34
+ //# sourceMappingURL=shell-operation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shell-operation.d.ts","sourceRoot":"","sources":["../../../src/core/tools/shell-operation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,cAAc,GACvB;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,UAAU,EAAE,OAAO,CAAA;CAAE,GAClF;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACpC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEpC,MAAM,MAAM,mBAAmB,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,SAAS,EAAE,cAAc,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAqB1G,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,OAAO,GAAG,mBAAmB,CAuDxE","sourcesContent":["/**\n * The one shell operation a set of tool arguments requests.\n *\n * The shell schema advertises a flat bag of fields because providers ignore\n * `anyOf` (see `toolUnion` in `contract.ts`). That advertisement cannot enforce\n * anything: a model may send any combination of fields, and it does. Consumers\n * that each re-read the raw bag disagreed about which operation a mixed call\n * requested — permissions keyed on `command`, execution keyed on `handle` — so\n * an allowed command could carry a denied background kill past the gate.\n *\n * Parse once, here, and let permissions, execution, display, and evidence all\n * read the same answer.\n */\nexport type ShellOperation =\n\t| { kind: \"run\"; command: string; timeout: number | undefined; background: boolean }\n\t| { kind: \"retrieve\"; handle: string }\n\t| { kind: \"kill\"; handle: string };\n\nexport type ShellOperationParse = { ok: true; operation: ShellOperation } | { ok: false; reason: string };\n\n/**\n * Placeholder policy, stated once and applied everywhere.\n *\n * Models routinely populate every advertised field, sending `handle: \"\"` or\n * `timeout: null` beside a real command. A value that is absent, null, or an\n * empty string carries no request and is dropped. A value that would change\n * behaviour if honoured is never dropped: it either selects the operation or,\n * when it belongs to a different operation, makes the call ambiguous.\n */\nfunction meaningful(value: unknown): boolean {\n\treturn value !== undefined && value !== null && value !== \"\";\n}\n\nfunction presentString(value: unknown): string | undefined {\n\treturn typeof value === \"string\" && value.length > 0 ? value : undefined;\n}\n\nconst RUN_HINT = \"Supply `command` to run a command, or `handle` to retrieve or kill a background command.\";\n\nexport function parseShellOperation(params: unknown): ShellOperationParse {\n\tif (typeof params !== \"object\" || params === null) {\n\t\treturn { ok: false, reason: `Shell arguments must be an object. ${RUN_HINT}` };\n\t}\n\tconst raw = params as Record<string, unknown>;\n\tconst command = presentString(raw.command);\n\tconst handle = presentString(raw.handle);\n\tconst wantsKill = raw.kill === true;\n\n\tif (command !== undefined && handle !== undefined) {\n\t\treturn {\n\t\t\tok: false,\n\t\t\treason: `Ambiguous shell call: \\`command\\` and \\`handle\\` request different operations. ${RUN_HINT} Send one, not both.`,\n\t\t};\n\t}\n\n\tif (handle !== undefined) {\n\t\tconst stray: string[] = [];\n\t\tif (typeof raw.timeout === \"number\") stray.push(\"timeout\");\n\t\tif (raw.background === true) stray.push(\"background\");\n\t\tif (stray.length > 0) {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\treason: `A background handle call takes only \\`handle\\` and optional \\`kill\\`. Remove: ${stray.join(\", \")}.`,\n\t\t\t};\n\t\t}\n\t\treturn { ok: true, operation: wantsKill ? { kind: \"kill\", handle } : { kind: \"retrieve\", handle } };\n\t}\n\n\tif (command !== undefined) {\n\t\tif (wantsKill) {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\treason:\n\t\t\t\t\t\"`kill: true` terminates a background command and requires its `handle`. It cannot be combined with `command`.\",\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\tok: true,\n\t\t\toperation: {\n\t\t\t\tkind: \"run\",\n\t\t\t\tcommand,\n\t\t\t\ttimeout: typeof raw.timeout === \"number\" ? raw.timeout : undefined,\n\t\t\t\tbackground: raw.background === true,\n\t\t\t},\n\t\t};\n\t}\n\n\treturn {\n\t\tok: false,\n\t\treason:\n\t\t\t\"handle\" in raw && !meaningful(raw.handle)\n\t\t\t\t? `\\`handle\\` is empty, which is not a background handle. ${RUN_HINT}`\n\t\t\t\t: `Shell call names no operation. ${RUN_HINT}`,\n\t};\n}\n"]}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Placeholder policy, stated once and applied everywhere.
3
+ *
4
+ * Models routinely populate every advertised field, sending `handle: ""` or
5
+ * `timeout: null` beside a real command. A value that is absent, null, or an
6
+ * empty string carries no request and is dropped. A value that would change
7
+ * behaviour if honoured is never dropped: it either selects the operation or,
8
+ * when it belongs to a different operation, makes the call ambiguous.
9
+ */
10
+ function meaningful(value) {
11
+ return value !== undefined && value !== null && value !== "";
12
+ }
13
+ function presentString(value) {
14
+ return typeof value === "string" && value.length > 0 ? value : undefined;
15
+ }
16
+ const RUN_HINT = "Supply `command` to run a command, or `handle` to retrieve or kill a background command.";
17
+ export function parseShellOperation(params) {
18
+ if (typeof params !== "object" || params === null) {
19
+ return { ok: false, reason: `Shell arguments must be an object. ${RUN_HINT}` };
20
+ }
21
+ const raw = params;
22
+ const command = presentString(raw.command);
23
+ const handle = presentString(raw.handle);
24
+ const wantsKill = raw.kill === true;
25
+ if (command !== undefined && handle !== undefined) {
26
+ return {
27
+ ok: false,
28
+ reason: `Ambiguous shell call: \`command\` and \`handle\` request different operations. ${RUN_HINT} Send one, not both.`,
29
+ };
30
+ }
31
+ if (handle !== undefined) {
32
+ const stray = [];
33
+ if (typeof raw.timeout === "number")
34
+ stray.push("timeout");
35
+ if (raw.background === true)
36
+ stray.push("background");
37
+ if (stray.length > 0) {
38
+ return {
39
+ ok: false,
40
+ reason: `A background handle call takes only \`handle\` and optional \`kill\`. Remove: ${stray.join(", ")}.`,
41
+ };
42
+ }
43
+ return { ok: true, operation: wantsKill ? { kind: "kill", handle } : { kind: "retrieve", handle } };
44
+ }
45
+ if (command !== undefined) {
46
+ if (wantsKill) {
47
+ return {
48
+ ok: false,
49
+ reason: "`kill: true` terminates a background command and requires its `handle`. It cannot be combined with `command`.",
50
+ };
51
+ }
52
+ return {
53
+ ok: true,
54
+ operation: {
55
+ kind: "run",
56
+ command,
57
+ timeout: typeof raw.timeout === "number" ? raw.timeout : undefined,
58
+ background: raw.background === true,
59
+ },
60
+ };
61
+ }
62
+ return {
63
+ ok: false,
64
+ reason: "handle" in raw && !meaningful(raw.handle)
65
+ ? `\`handle\` is empty, which is not a background handle. ${RUN_HINT}`
66
+ : `Shell call names no operation. ${RUN_HINT}`,
67
+ };
68
+ }
69
+ //# sourceMappingURL=shell-operation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shell-operation.js","sourceRoot":"","sources":["../../../src/core/tools/shell-operation.ts"],"names":[],"mappings":"AAoBA;;;;;;;;GAQG;AACH,SAAS,UAAU,CAAC,KAAc,EAAW;IAC5C,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC;AAAA,CAC7D;AAED,SAAS,aAAa,CAAC,KAAc,EAAsB;IAC1D,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC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,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,CAAC;IACrG,CAAC;IAED,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC3B,IAAI,SAAS,EAAE,CAAC;YACf,OAAO;gBACN,EAAE,EAAE,KAAK;gBACT,MAAM,EACL,+GAA+G;aAChH,CAAC;QACH,CAAC;QACD,OAAO;YACN,EAAE,EAAE,IAAI;YACR,SAAS,EAAE;gBACV,IAAI,EAAE,KAAK;gBACX,OAAO;gBACP,OAAO,EAAE,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS;gBAClE,UAAU,EAAE,GAAG,CAAC,UAAU,KAAK,IAAI;aACnC;SACD,CAAC;IACH,CAAC;IAED,OAAO;QACN,EAAE,EAAE,KAAK;QACT,MAAM,EACL,QAAQ,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC;YACzC,CAAC,CAAC,0DAA0D,QAAQ,EAAE;YACtE,CAAC,CAAC,kCAAkC,QAAQ,EAAE;KAChD,CAAC;AAAA,CACF","sourcesContent":["/**\n * The one shell operation a set of tool arguments requests.\n *\n * The shell schema advertises a flat bag of fields because providers ignore\n * `anyOf` (see `toolUnion` in `contract.ts`). That advertisement cannot enforce\n * anything: a model may send any combination of fields, and it does. Consumers\n * that each re-read the raw bag disagreed about which operation a mixed call\n * requested — permissions keyed on `command`, execution keyed on `handle` — so\n * an allowed command could carry a denied background kill past the gate.\n *\n * Parse once, here, and let permissions, execution, display, and evidence all\n * read the same answer.\n */\nexport type ShellOperation =\n\t| { kind: \"run\"; command: string; timeout: number | undefined; background: boolean }\n\t| { kind: \"retrieve\"; handle: string }\n\t| { kind: \"kill\"; handle: string };\n\nexport type ShellOperationParse = { ok: true; operation: ShellOperation } | { ok: false; reason: string };\n\n/**\n * Placeholder policy, stated once and applied everywhere.\n *\n * Models routinely populate every advertised field, sending `handle: \"\"` or\n * `timeout: null` beside a real command. A value that is absent, null, or an\n * empty string carries no request and is dropped. A value that would change\n * behaviour if honoured is never dropped: it either selects the operation or,\n * when it belongs to a different operation, makes the call ambiguous.\n */\nfunction meaningful(value: unknown): boolean {\n\treturn value !== undefined && value !== null && value !== \"\";\n}\n\nfunction presentString(value: unknown): string | undefined {\n\treturn typeof value === \"string\" && value.length > 0 ? value : undefined;\n}\n\nconst RUN_HINT = \"Supply `command` to run a command, or `handle` to retrieve or kill a background command.\";\n\nexport function parseShellOperation(params: unknown): ShellOperationParse {\n\tif (typeof params !== \"object\" || params === null) {\n\t\treturn { ok: false, reason: `Shell arguments must be an object. ${RUN_HINT}` };\n\t}\n\tconst raw = params as Record<string, unknown>;\n\tconst command = presentString(raw.command);\n\tconst handle = presentString(raw.handle);\n\tconst wantsKill = raw.kill === true;\n\n\tif (command !== undefined && handle !== undefined) {\n\t\treturn {\n\t\t\tok: false,\n\t\t\treason: `Ambiguous shell call: \\`command\\` and \\`handle\\` request different operations. ${RUN_HINT} Send one, not both.`,\n\t\t};\n\t}\n\n\tif (handle !== undefined) {\n\t\tconst stray: string[] = [];\n\t\tif (typeof raw.timeout === \"number\") stray.push(\"timeout\");\n\t\tif (raw.background === true) stray.push(\"background\");\n\t\tif (stray.length > 0) {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\treason: `A background handle call takes only \\`handle\\` and optional \\`kill\\`. Remove: ${stray.join(\", \")}.`,\n\t\t\t};\n\t\t}\n\t\treturn { ok: true, operation: wantsKill ? { kind: \"kill\", handle } : { kind: \"retrieve\", handle } };\n\t}\n\n\tif (command !== undefined) {\n\t\tif (wantsKill) {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\treason:\n\t\t\t\t\t\"`kill: true` terminates a background command and requires its `handle`. It cannot be combined with `command`.\",\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\tok: true,\n\t\t\toperation: {\n\t\t\t\tkind: \"run\",\n\t\t\t\tcommand,\n\t\t\t\ttimeout: typeof raw.timeout === \"number\" ? raw.timeout : undefined,\n\t\t\t\tbackground: raw.background === true,\n\t\t\t},\n\t\t};\n\t}\n\n\treturn {\n\t\tok: false,\n\t\treason:\n\t\t\t\"handle\" in raw && !meaningful(raw.handle)\n\t\t\t\t? `\\`handle\\` is empty, which is not a background handle. ${RUN_HINT}`\n\t\t\t\t: `Shell call names no operation. ${RUN_HINT}`,\n\t};\n}\n"]}
@@ -4,9 +4,15 @@
4
4
  import { type Keybinding } from "@earendil-works/pi-tui";
5
5
  export interface KeyTextFormatOptions {
6
6
  capitalize?: boolean;
7
+ /**
8
+ * Name only the first binding. A hint sitting alongside several others has
9
+ * no room to list every alias, and "left/ctrl+b/right/ctrl+f effort" is
10
+ * longer than the thing it explains.
11
+ */
12
+ primaryOnly?: boolean;
7
13
  }
8
14
  export declare function formatKeyText(key: string, options?: KeyTextFormatOptions): string;
9
- export declare function keyText(keybinding: Keybinding): string;
15
+ export declare function keyText(keybinding: Keybinding, options?: KeyTextFormatOptions): string;
10
16
  export declare function keyDisplayText(keybinding: Keybinding): string;
11
17
  export declare function keyHint(keybinding: Keybinding, description: string): string;
12
18
  export declare function rawKeyHint(key: string, description: string): string;
@@ -1 +1 @@
1
- {"version":3,"file":"keybinding-hints.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/keybinding-hints.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAkB,KAAK,UAAU,EAAc,MAAM,wBAAwB,CAAC;AAGrF,MAAM,WAAW,oBAAoB;IACpC,UAAU,CAAC,EAAE,OAAO,CAAC;CACrB;AAOD,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,oBAAyB,GAAG,MAAM,CAUrF;AAOD,wBAAgB,OAAO,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAEtD;AAED,wBAAgB,cAAc,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAE7D;AAED,wBAAgB,OAAO,CAAC,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAE3E;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAEnE","sourcesContent":["/**\n * Utilities for formatting keybinding hints in the UI.\n */\n\nimport { getKeybindings, type Keybinding, type KeyId } from \"@earendil-works/pi-tui\";\nimport { theme } from \"../theme/theme.ts\";\n\nexport interface KeyTextFormatOptions {\n\tcapitalize?: boolean;\n}\n\nfunction formatKeyPart(part: string, options: KeyTextFormatOptions): string {\n\tconst displayPart = process.platform === \"darwin\" && part.toLowerCase() === \"alt\" ? \"option\" : part;\n\treturn options.capitalize ? displayPart.charAt(0).toUpperCase() + displayPart.slice(1) : displayPart;\n}\n\nexport function formatKeyText(key: string, options: KeyTextFormatOptions = {}): string {\n\treturn key\n\t\t.split(\"/\")\n\t\t.map((k) =>\n\t\t\tk\n\t\t\t\t.split(\"+\")\n\t\t\t\t.map((part) => formatKeyPart(part, options))\n\t\t\t\t.join(\"+\"),\n\t\t)\n\t\t.join(\"/\");\n}\n\nfunction formatKeys(keys: KeyId[], options: KeyTextFormatOptions = {}): string {\n\tif (keys.length === 0) return \"\";\n\treturn formatKeyText(keys.join(\"/\"), options);\n}\n\nexport function keyText(keybinding: Keybinding): string {\n\treturn formatKeys(getKeybindings().getKeys(keybinding));\n}\n\nexport function keyDisplayText(keybinding: Keybinding): string {\n\treturn formatKeys(getKeybindings().getKeys(keybinding), { capitalize: true });\n}\n\nexport function keyHint(keybinding: Keybinding, description: string): string {\n\treturn theme.fg(\"dim\", keyText(keybinding)) + theme.fg(\"muted\", ` ${description}`);\n}\n\nexport function rawKeyHint(key: string, description: string): string {\n\treturn theme.fg(\"dim\", formatKeyText(key)) + theme.fg(\"muted\", ` ${description}`);\n}\n"]}
1
+ {"version":3,"file":"keybinding-hints.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/keybinding-hints.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAkB,KAAK,UAAU,EAAc,MAAM,wBAAwB,CAAC;AAGrF,MAAM,WAAW,oBAAoB;IACpC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;;OAIG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACtB;AAOD,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,oBAAyB,GAAG,MAAM,CAUrF;AAOD,wBAAgB,OAAO,CAAC,UAAU,EAAE,UAAU,EAAE,OAAO,GAAE,oBAAyB,GAAG,MAAM,CAG1F;AAED,wBAAgB,cAAc,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAE7D;AAED,wBAAgB,OAAO,CAAC,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAE3E;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAEnE","sourcesContent":["/**\n * Utilities for formatting keybinding hints in the UI.\n */\n\nimport { getKeybindings, type Keybinding, type KeyId } from \"@earendil-works/pi-tui\";\nimport { theme } from \"../theme/theme.ts\";\n\nexport interface KeyTextFormatOptions {\n\tcapitalize?: boolean;\n\t/**\n\t * Name only the first binding. A hint sitting alongside several others has\n\t * no room to list every alias, and \"left/ctrl+b/right/ctrl+f effort\" is\n\t * longer than the thing it explains.\n\t */\n\tprimaryOnly?: boolean;\n}\n\nfunction formatKeyPart(part: string, options: KeyTextFormatOptions): string {\n\tconst displayPart = process.platform === \"darwin\" && part.toLowerCase() === \"alt\" ? \"option\" : part;\n\treturn options.capitalize ? displayPart.charAt(0).toUpperCase() + displayPart.slice(1) : displayPart;\n}\n\nexport function formatKeyText(key: string, options: KeyTextFormatOptions = {}): string {\n\treturn key\n\t\t.split(\"/\")\n\t\t.map((k) =>\n\t\t\tk\n\t\t\t\t.split(\"+\")\n\t\t\t\t.map((part) => formatKeyPart(part, options))\n\t\t\t\t.join(\"+\"),\n\t\t)\n\t\t.join(\"/\");\n}\n\nfunction formatKeys(keys: KeyId[], options: KeyTextFormatOptions = {}): string {\n\tif (keys.length === 0) return \"\";\n\treturn formatKeyText(keys.join(\"/\"), options);\n}\n\nexport function keyText(keybinding: Keybinding, options: KeyTextFormatOptions = {}): string {\n\tconst keys = getKeybindings().getKeys(keybinding);\n\treturn formatKeys(options.primaryOnly ? keys.slice(0, 1) : keys, options);\n}\n\nexport function keyDisplayText(keybinding: Keybinding): string {\n\treturn formatKeys(getKeybindings().getKeys(keybinding), { capitalize: true });\n}\n\nexport function keyHint(keybinding: Keybinding, description: string): string {\n\treturn theme.fg(\"dim\", keyText(keybinding)) + theme.fg(\"muted\", ` ${description}`);\n}\n\nexport function rawKeyHint(key: string, description: string): string {\n\treturn theme.fg(\"dim\", formatKeyText(key)) + theme.fg(\"muted\", ` ${description}`);\n}\n"]}
@@ -21,8 +21,9 @@ function formatKeys(keys, options = {}) {
21
21
  return "";
22
22
  return formatKeyText(keys.join("/"), options);
23
23
  }
24
- export function keyText(keybinding) {
25
- return formatKeys(getKeybindings().getKeys(keybinding));
24
+ export function keyText(keybinding, options = {}) {
25
+ const keys = getKeybindings().getKeys(keybinding);
26
+ return formatKeys(options.primaryOnly ? keys.slice(0, 1) : keys, options);
26
27
  }
27
28
  export function keyDisplayText(keybinding) {
28
29
  return formatKeys(getKeybindings().getKeys(keybinding), { capitalize: true });
@@ -1 +1 @@
1
- {"version":3,"file":"keybinding-hints.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/keybinding-hints.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,cAAc,EAA+B,MAAM,wBAAwB,CAAC;AACrF,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAM1C,SAAS,aAAa,CAAC,IAAY,EAAE,OAA6B,EAAU;IAC3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AED,MAAM,UAAU,OAAO,CAAC,UAAsB,EAAE,WAAmB,EAAU;IAC5E,OAAO,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC,GAAG,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,IAAI,WAAW,EAAE,CAAC,CAAC;AAAA,CACnF;AAED,MAAM,UAAU,UAAU,CAAC,GAAW,EAAE,WAAmB,EAAU;IACpE,OAAO,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,IAAI,WAAW,EAAE,CAAC,CAAC;AAAA,CAClF","sourcesContent":["/**\n * Utilities for formatting keybinding hints in the UI.\n */\n\nimport { getKeybindings, type Keybinding, type KeyId } from \"@earendil-works/pi-tui\";\nimport { theme } from \"../theme/theme.ts\";\n\nexport interface KeyTextFormatOptions {\n\tcapitalize?: boolean;\n}\n\nfunction formatKeyPart(part: string, options: KeyTextFormatOptions): string {\n\tconst displayPart = process.platform === \"darwin\" && part.toLowerCase() === \"alt\" ? \"option\" : part;\n\treturn options.capitalize ? displayPart.charAt(0).toUpperCase() + displayPart.slice(1) : displayPart;\n}\n\nexport function formatKeyText(key: string, options: KeyTextFormatOptions = {}): string {\n\treturn key\n\t\t.split(\"/\")\n\t\t.map((k) =>\n\t\t\tk\n\t\t\t\t.split(\"+\")\n\t\t\t\t.map((part) => formatKeyPart(part, options))\n\t\t\t\t.join(\"+\"),\n\t\t)\n\t\t.join(\"/\");\n}\n\nfunction formatKeys(keys: KeyId[], options: KeyTextFormatOptions = {}): string {\n\tif (keys.length === 0) return \"\";\n\treturn formatKeyText(keys.join(\"/\"), options);\n}\n\nexport function keyText(keybinding: Keybinding): string {\n\treturn formatKeys(getKeybindings().getKeys(keybinding));\n}\n\nexport function keyDisplayText(keybinding: Keybinding): string {\n\treturn formatKeys(getKeybindings().getKeys(keybinding), { capitalize: true });\n}\n\nexport function keyHint(keybinding: Keybinding, description: string): string {\n\treturn theme.fg(\"dim\", keyText(keybinding)) + theme.fg(\"muted\", ` ${description}`);\n}\n\nexport function rawKeyHint(key: string, description: string): string {\n\treturn theme.fg(\"dim\", formatKeyText(key)) + theme.fg(\"muted\", ` ${description}`);\n}\n"]}
1
+ {"version":3,"file":"keybinding-hints.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/keybinding-hints.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,cAAc,EAA+B,MAAM,wBAAwB,CAAC;AACrF,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAY1C,SAAS,aAAa,CAAC,IAAY,EAAE,OAA6B,EAAU;IAC3E,MAAM,WAAW,GAAG,OAAO,CAAC,QAAQ,KAAK,QAAQ,IAAI,IAAI,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;IACpG,OAAO,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;AAAA,CACrG;AAED,MAAM,UAAU,aAAa,CAAC,GAAW,EAAE,OAAO,GAAyB,EAAE,EAAU;IACtF,OAAO,GAAG;SACR,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CACV,CAAC;SACC,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;SAC3C,IAAI,CAAC,GAAG,CAAC,CACX;SACA,IAAI,CAAC,GAAG,CAAC,CAAC;AAAA,CACZ;AAED,SAAS,UAAU,CAAC,IAAa,EAAE,OAAO,GAAyB,EAAE,EAAU;IAC9E,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IACjC,OAAO,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC;AAAA,CAC9C;AAED,MAAM,UAAU,OAAO,CAAC,UAAsB,EAAE,OAAO,GAAyB,EAAE,EAAU;IAC3F,MAAM,IAAI,GAAG,cAAc,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAClD,OAAO,UAAU,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAAA,CAC1E;AAED,MAAM,UAAU,cAAc,CAAC,UAAsB,EAAU;IAC9D,OAAO,UAAU,CAAC,cAAc,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;AAAA,CAC9E;AAED,MAAM,UAAU,OAAO,CAAC,UAAsB,EAAE,WAAmB,EAAU;IAC5E,OAAO,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC,GAAG,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,IAAI,WAAW,EAAE,CAAC,CAAC;AAAA,CACnF;AAED,MAAM,UAAU,UAAU,CAAC,GAAW,EAAE,WAAmB,EAAU;IACpE,OAAO,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,IAAI,WAAW,EAAE,CAAC,CAAC;AAAA,CAClF","sourcesContent":["/**\n * Utilities for formatting keybinding hints in the UI.\n */\n\nimport { getKeybindings, type Keybinding, type KeyId } from \"@earendil-works/pi-tui\";\nimport { theme } from \"../theme/theme.ts\";\n\nexport interface KeyTextFormatOptions {\n\tcapitalize?: boolean;\n\t/**\n\t * Name only the first binding. A hint sitting alongside several others has\n\t * no room to list every alias, and \"left/ctrl+b/right/ctrl+f effort\" is\n\t * longer than the thing it explains.\n\t */\n\tprimaryOnly?: boolean;\n}\n\nfunction formatKeyPart(part: string, options: KeyTextFormatOptions): string {\n\tconst displayPart = process.platform === \"darwin\" && part.toLowerCase() === \"alt\" ? \"option\" : part;\n\treturn options.capitalize ? displayPart.charAt(0).toUpperCase() + displayPart.slice(1) : displayPart;\n}\n\nexport function formatKeyText(key: string, options: KeyTextFormatOptions = {}): string {\n\treturn key\n\t\t.split(\"/\")\n\t\t.map((k) =>\n\t\t\tk\n\t\t\t\t.split(\"+\")\n\t\t\t\t.map((part) => formatKeyPart(part, options))\n\t\t\t\t.join(\"+\"),\n\t\t)\n\t\t.join(\"/\");\n}\n\nfunction formatKeys(keys: KeyId[], options: KeyTextFormatOptions = {}): string {\n\tif (keys.length === 0) return \"\";\n\treturn formatKeyText(keys.join(\"/\"), options);\n}\n\nexport function keyText(keybinding: Keybinding, options: KeyTextFormatOptions = {}): string {\n\tconst keys = getKeybindings().getKeys(keybinding);\n\treturn formatKeys(options.primaryOnly ? keys.slice(0, 1) : keys, options);\n}\n\nexport function keyDisplayText(keybinding: Keybinding): string {\n\treturn formatKeys(getKeybindings().getKeys(keybinding), { capitalize: true });\n}\n\nexport function keyHint(keybinding: Keybinding, description: string): string {\n\treturn theme.fg(\"dim\", keyText(keybinding)) + theme.fg(\"muted\", ` ${description}`);\n}\n\nexport function rawKeyHint(key: string, description: string): string {\n\treturn theme.fg(\"dim\", formatKeyText(key)) + theme.fg(\"muted\", ` ${description}`);\n}\n"]}
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Row rendering for the model step of the model picker.
3
+ *
4
+ * The effort-cluster placement and the price panel are adapted from Prime Agent
5
+ * (https://github.com/PrimeIntellect-ai/prime-agent), a separate Pi-derived fork
6
+ * under the MIT License. ADR 0002 permits that for MIT prior art; NOTICE records
7
+ * the attribution. Apex Code's own panel chrome, cursor, and theme tokens are
8
+ * kept, so this is the row and nothing above it.
9
+ */
10
+ import type { ModelCost, ModelThinkingLevel } from "@earendil-works/pi-ai";
11
+ /**
12
+ * Column budget the effort cluster gets on every row of one rendered page.
13
+ *
14
+ * It is computed once per page rather than per row so the squares sit in the
15
+ * same column all the way down. A per-row measurement would shift the cluster
16
+ * whenever a neighbouring name or level label changed length, which reads as
17
+ * the list wobbling while you arrow through it.
18
+ */
19
+ export interface EffortLayout {
20
+ nameColumn: number;
21
+ squareSlots: number;
22
+ gap: number;
23
+ labelWidth: number;
24
+ showLabel: boolean;
25
+ showCluster: boolean;
26
+ }
27
+ export declare const NO_EFFORT_CLUSTER: EffortLayout;
28
+ /** One visible row's inputs to the page-wide layout measurement. */
29
+ export interface EffortLayoutRow {
30
+ name: string;
31
+ /** Selectable thinking levels, empty when the model has no reasoning to dial. */
32
+ levels: ReadonlyArray<ModelThinkingLevel>;
33
+ trailingSegments: ReadonlyArray<TrailingSegment>;
34
+ }
35
+ /**
36
+ * One piece of a row's trailing context, with what it costs to lose.
37
+ *
38
+ * Reading order and dropping order are not the same thing. `id · current` reads
39
+ * correctly in that order, but under a squeeze `current` is the segment worth
40
+ * keeping, because the row already carries the model's name and the id is
41
+ * recoverable from it, while which model is active is not shown anywhere else.
42
+ * Dropping purely from the front would have kept the wrong one.
43
+ */
44
+ export interface TrailingSegment {
45
+ text: string;
46
+ /** Lower drops first. */
47
+ priority: number;
48
+ }
49
+ /** Rendered width of a trailing cluster, degraded and truncated exactly as {@link renderTrailing} will. */
50
+ export declare function getTrailingWidth(segments: ReadonlyArray<TrailingSegment>, width: number): number;
51
+ /**
52
+ * Where the effort cluster sits on this page, or {@link NO_EFFORT_CLUSTER} when it does not fit.
53
+ *
54
+ * The cluster is placed near the row's horizontal centre and then given up one
55
+ * piece at a time as the terminal narrows: first the centring gap, then the
56
+ * name column, then the level label, then the cluster itself. Rows stay aligned
57
+ * at every width because each step is taken for the whole page at once.
58
+ */
59
+ export declare function getEffortLayout(rows: ReadonlyArray<EffortLayoutRow>, width: number): EffortLayout;
60
+ export interface ModelRowOptions {
61
+ name: string;
62
+ levels: ReadonlyArray<ModelThinkingLevel>;
63
+ effort: ModelThinkingLevel | undefined;
64
+ trailingSegments: ReadonlyArray<TrailingSegment>;
65
+ selected: boolean;
66
+ layout: EffortLayout;
67
+ width: number;
68
+ }
69
+ /**
70
+ * One model row: cursor, name, optional effort cluster, right-aligned trailing context.
71
+ *
72
+ * The line is padded out to `width` so the caller's selection fill covers the
73
+ * whole row rather than stopping at the last glyph.
74
+ */
75
+ export declare function composeModelRow(options: ModelRowOptions): string;
76
+ /**
77
+ * Per-million-token prices for the highlighted model.
78
+ *
79
+ * This is the detail the old list carried as a second "Model Name" line, which
80
+ * became redundant once the name became the row itself. Price is what you
81
+ * actually weigh when two models are otherwise interchangeable.
82
+ */
83
+ export declare function renderPricePanel(cost: ModelCost | undefined, width: number): string[];
84
+ //# sourceMappingURL=model-row.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-row.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/model-row.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AA+B3E;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,WAAW,EAAE,OAAO,CAAC;CACrB;AAED,eAAO,MAAM,iBAAiB,EAAE,YAO/B,CAAC;AAEF,oEAAoE;AACpE,MAAM,WAAW,eAAe;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,iFAAiF;IACjF,MAAM,EAAE,aAAa,CAAC,kBAAkB,CAAC,CAAC;IAC1C,gBAAgB,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;CACjD;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,eAAe;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,yBAAyB;IACzB,QAAQ,EAAE,MAAM,CAAC;CACjB;AAuBD,2GAA2G;AAC3G,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,aAAa,CAAC,eAAe,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAKhG;AASD;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,aAAa,CAAC,eAAe,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,YAAY,CAmCjG;AAmBD,MAAM,WAAW,eAAe;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,aAAa,CAAC,kBAAkB,CAAC,CAAC;IAC1C,MAAM,EAAE,kBAAkB,GAAG,SAAS,CAAC;IACvC,gBAAgB,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;IACjD,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,YAAY,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;CACd;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM,CA+BhE;AASD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,SAAS,GAAG,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CA8BrF","sourcesContent":["/**\n * Row rendering for the model step of the model picker.\n *\n * The effort-cluster placement and the price panel are adapted from Prime Agent\n * (https://github.com/PrimeIntellect-ai/prime-agent), a separate Pi-derived fork\n * under the MIT License. ADR 0002 permits that for MIT prior art; NOTICE records\n * the attribution. Apex Code's own panel chrome, cursor, and theme tokens are\n * kept, so this is the row and nothing above it.\n */\n\nimport type { ModelCost, ModelThinkingLevel } from \"@earendil-works/pi-ai\";\nimport { truncateToWidth, visibleWidth } from \"@earendil-works/pi-tui\";\nimport { type ThemeColor, theme } from \"../theme/theme.ts\";\n\n/** Columns the cursor cell occupies at the head of every row. */\nconst CURSOR_WIDTH = 2;\nconst NAME_COLUMN_MAX = 30;\nconst NAME_COLUMN_MIN = 12;\n/** `← ` + squares + ` → ` around the cluster, plus at least one column of gap before it. */\nconst CLUSTER_CHROME = 5;\nconst CLUSTER_CHROME_AND_GAP = CLUSTER_CHROME + 1;\nconst PRICE_UNIT_TEXT = \"$ / 1M tokens\";\n/** A wide price column must still fit the longest label, \"Cached input\". */\nconst PRICE_COLUMN_MIN_WIDTH = 13;\n/**\n * Past this the three prices stop reading as one group and become three lonely\n * numbers spread across the terminal, so the block stays put and the row ends early.\n */\nconst PRICE_COLUMN_MAX_WIDTH = 18;\nconst PRICE_WIDE_LAYOUT_MIN_WIDTH = 58;\n\nconst THINKING_COLORS: Record<ModelThinkingLevel, ThemeColor> = {\n\toff: \"thinkingOff\",\n\tminimal: \"thinkingMinimal\",\n\tlow: \"thinkingLow\",\n\tmedium: \"thinkingMedium\",\n\thigh: \"thinkingHigh\",\n\txhigh: \"thinkingXhigh\",\n\tmax: \"thinkingMax\",\n};\n\n/**\n * Column budget the effort cluster gets on every row of one rendered page.\n *\n * It is computed once per page rather than per row so the squares sit in the\n * same column all the way down. A per-row measurement would shift the cluster\n * whenever a neighbouring name or level label changed length, which reads as\n * the list wobbling while you arrow through it.\n */\nexport interface EffortLayout {\n\tnameColumn: number;\n\tsquareSlots: number;\n\tgap: number;\n\tlabelWidth: number;\n\tshowLabel: boolean;\n\tshowCluster: boolean;\n}\n\nexport const NO_EFFORT_CLUSTER: EffortLayout = {\n\tnameColumn: 0,\n\tsquareSlots: 0,\n\tgap: 0,\n\tlabelWidth: 0,\n\tshowLabel: false,\n\tshowCluster: false,\n};\n\n/** One visible row's inputs to the page-wide layout measurement. */\nexport interface EffortLayoutRow {\n\tname: string;\n\t/** Selectable thinking levels, empty when the model has no reasoning to dial. */\n\tlevels: ReadonlyArray<ModelThinkingLevel>;\n\ttrailingSegments: ReadonlyArray<TrailingSegment>;\n}\n\n/**\n * One piece of a row's trailing context, with what it costs to lose.\n *\n * Reading order and dropping order are not the same thing. `id · current` reads\n * correctly in that order, but under a squeeze `current` is the segment worth\n * keeping, because the row already carries the model's name and the id is\n * recoverable from it, while which model is active is not shown anywhere else.\n * Dropping purely from the front would have kept the wrong one.\n */\nexport interface TrailingSegment {\n\ttext: string;\n\t/** Lower drops first. */\n\tpriority: number;\n}\n\n/** Drop the least valuable segments until the cluster fits, preserving reading order. */\nfunction reduceTrailingSegments(segments: ReadonlyArray<TrailingSegment>, budget: number): TrailingSegment[] {\n\tlet current = segments.filter((segment) => visibleWidth(segment.text) > 0);\n\twhile (current.length > 1 && visibleWidth(joinSegments(current)) > budget) {\n\t\tlet weakest = 0;\n\t\tfor (let i = 1; i < current.length; i++) {\n\t\t\tif ((current[i]?.priority ?? 0) < (current[weakest]?.priority ?? 0)) weakest = i;\n\t\t}\n\t\tcurrent = current.filter((_, i) => i !== weakest);\n\t}\n\treturn current;\n}\n\nfunction joinSegments(segments: ReadonlyArray<TrailingSegment>): string {\n\treturn segments.map((segment) => segment.text).join(theme.fg(\"borderMuted\", \" · \"));\n}\n\nfunction trailingBudget(width: number): number {\n\treturn Math.max(1, width - CURSOR_WIDTH - 5);\n}\n\n/** Rendered width of a trailing cluster, degraded and truncated exactly as {@link renderTrailing} will. */\nexport function getTrailingWidth(segments: ReadonlyArray<TrailingSegment>, width: number): number {\n\tconst budget = trailingBudget(width);\n\tconst reduced = reduceTrailingSegments(segments, budget);\n\tif (reduced.length === 0) return 0;\n\treturn Math.min(visibleWidth(joinSegments(reduced)), budget);\n}\n\nfunction renderTrailing(segments: ReadonlyArray<TrailingSegment>, width: number): string {\n\tconst budget = trailingBudget(width);\n\tconst reduced = reduceTrailingSegments(segments, budget);\n\tif (reduced.length === 0) return \"\";\n\treturn truncateToWidth(joinSegments(reduced), budget, \"…\");\n}\n\n/**\n * Where the effort cluster sits on this page, or {@link NO_EFFORT_CLUSTER} when it does not fit.\n *\n * The cluster is placed near the row's horizontal centre and then given up one\n * piece at a time as the terminal narrows: first the centring gap, then the\n * name column, then the level label, then the cluster itself. Rows stay aligned\n * at every width because each step is taken for the whole page at once.\n */\nexport function getEffortLayout(rows: ReadonlyArray<EffortLayoutRow>, width: number): EffortLayout {\n\tconst reasoningRows = rows.filter((row) => row.levels.length > 0);\n\tif (reasoningRows.length === 0) return NO_EFFORT_CLUSTER;\n\n\tconst maxTrailingWidth = Math.max(0, ...rows.map((row) => getTrailingWidth(row.trailingSegments, width)));\n\tconst available = Math.max(1, width - CURSOR_WIDTH - maxTrailingWidth - 2);\n\n\tconst maxNameColumn = Math.min(Math.max(...reasoningRows.map((row) => visibleWidth(row.name))), NAME_COLUMN_MAX);\n\tconst squareSlots = Math.max(...reasoningRows.map((row) => row.levels.filter((level) => level !== \"off\").length));\n\t// A fixed label cell sized to the longest level name, so dialling effort up\n\t// and down never changes the cluster's span or its centred gap.\n\tconst labelWidth = Math.max(...reasoningRows.flatMap((row) => row.levels.map((level) => visibleWidth(level))));\n\n\tconst place = (nameColumn: number, showLabel: boolean): EffortLayout => {\n\t\tconst span = squareSlots + (showLabel ? labelWidth + CLUSTER_CHROME : CLUSTER_CHROME - 1);\n\t\tconst desired = Math.floor(width / 2 - span / 2) - CURSOR_WIDTH - nameColumn;\n\t\tconst gap = Math.max(1, Math.min(desired, available - nameColumn - span));\n\t\treturn { nameColumn, squareSlots, gap, labelWidth, showLabel, showCluster: true };\n\t};\n\n\tif (maxNameColumn + squareSlots + labelWidth + CLUSTER_CHROME_AND_GAP <= available) {\n\t\treturn place(maxNameColumn, true);\n\t}\n\tconst labelNameColumn = available - squareSlots - labelWidth - CLUSTER_CHROME_AND_GAP;\n\tif (labelNameColumn >= NAME_COLUMN_MIN) {\n\t\treturn place(Math.min(maxNameColumn, labelNameColumn), true);\n\t}\n\tif (maxNameColumn + squareSlots + CLUSTER_CHROME_AND_GAP <= available) {\n\t\treturn place(maxNameColumn, false);\n\t}\n\tconst clusterNameColumn = available - squareSlots - CLUSTER_CHROME_AND_GAP;\n\tif (clusterNameColumn >= NAME_COLUMN_MIN) {\n\t\treturn place(Math.min(maxNameColumn, clusterNameColumn), false);\n\t}\n\treturn NO_EFFORT_CLUSTER;\n}\n\nfunction renderEffortSquares(\n\tlevels: ReadonlyArray<ModelThinkingLevel>,\n\teffort: ModelThinkingLevel,\n\tsquareSlots: number,\n\tselected: boolean,\n): string {\n\tconst onLevels = levels.filter((level) => level !== \"off\");\n\tif (onLevels.length === 0) return \"\";\n\tconst filledCount = effort === \"off\" ? 0 : onLevels.indexOf(effort) + 1;\n\t// Only the highlighted row's squares carry the level's colour. Colouring\n\t// every row turned the list into a stripe of unrelated hues.\n\tconst paintFilled = (glyph: string) =>\n\t\tselected ? theme.fg(THINKING_COLORS[effort], glyph) : theme.fg(\"muted\", glyph);\n\tconst marks = onLevels.map((_, index) => (index < filledCount ? paintFilled(\"■\") : theme.fg(\"dim\", \"□\"))).join(\"\");\n\treturn marks + \" \".repeat(Math.max(0, squareSlots - visibleWidth(marks)));\n}\n\nexport interface ModelRowOptions {\n\tname: string;\n\tlevels: ReadonlyArray<ModelThinkingLevel>;\n\teffort: ModelThinkingLevel | undefined;\n\ttrailingSegments: ReadonlyArray<TrailingSegment>;\n\tselected: boolean;\n\tlayout: EffortLayout;\n\twidth: number;\n}\n\n/**\n * One model row: cursor, name, optional effort cluster, right-aligned trailing context.\n *\n * The line is padded out to `width` so the caller's selection fill covers the\n * whole row rather than stopping at the last glyph.\n */\nexport function composeModelRow(options: ModelRowOptions): string {\n\tconst { name, levels, effort, trailingSegments, selected, layout, width } = options;\n\t// Selection is carried by the background step alone, so the cursor stays\n\t// uncoloured: the accent means \"Apex owns this\" everywhere else on screen.\n\tconst cursor = selected ? \"→ \" : \" \";\n\tconst inner = Math.max(1, width - CURSOR_WIDTH);\n\tconst trailing = renderTrailing(trailingSegments, width);\n\tconst trailingWidth = visibleWidth(trailing);\n\n\tlet primary: string;\n\tif (layout.showCluster && levels.length > 0 && effort !== undefined) {\n\t\tconst nameCell = truncateToWidth(name, layout.nameColumn, \"…\", true);\n\t\tconst gap = \" \".repeat(layout.gap);\n\t\t// The arrows are the affordance for left/right, so they appear only on the\n\t\t// row they would act on. Their columns are reserved on every row regardless.\n\t\tconst leftArrow = selected ? theme.fg(\"dim\", \"←\") : \" \";\n\t\tconst rightArrow = selected ? theme.fg(\"dim\", \"→\") : \" \";\n\t\tconst squares = renderEffortSquares(levels, effort, layout.squareSlots, selected);\n\t\tconst label = layout.showLabel ? ` ${theme.fg(\"muted\", effort.padEnd(layout.labelWidth))}` : \"\";\n\t\tprimary = `${nameCell}${gap}${leftArrow} ${squares} ${rightArrow}${label}`;\n\t} else {\n\t\tprimary = name;\n\t}\n\n\t// Truncate before painting, never after: a cut inside the bold wrapper would\n\t// drop its closing code and bleed the weight across the rest of the line.\n\tconst gapBeforeTrailing = trailingWidth > 0 ? 2 : 0;\n\tconst capped = truncateToWidth(primary, Math.max(1, inner - trailingWidth - gapBeforeTrailing), \"…\");\n\tconst painted = selected ? theme.bold(theme.fg(\"text\", capped)) : theme.fg(\"text\", capped);\n\tconst filler = \" \".repeat(Math.max(0, inner - visibleWidth(capped) - trailingWidth));\n\treturn `${cursor}${painted}${filler}${trailing}`;\n}\n\nfunction formatPrice(value: number | undefined): string {\n\tif (value === undefined || !Number.isFinite(value) || value < 0) return \"—\";\n\tif (value === 0) return \"$0\";\n\tconst rounded = Math.round(value * 1000) / 1000;\n\treturn rounded === 0 ? \"<$0.001\" : `$${rounded}`;\n}\n\n/**\n * Per-million-token prices for the highlighted model.\n *\n * This is the detail the old list carried as a second \"Model Name\" line, which\n * became redundant once the name became the row itself. Price is what you\n * actually weigh when two models are otherwise interchangeable.\n */\nexport function renderPricePanel(cost: ModelCost | undefined, width: number): string[] {\n\tconst entries: [string, string][] = [\n\t\t[\"Input\", formatPrice(cost?.input)],\n\t\t[\"Cached input\", formatPrice(cost?.cacheRead)],\n\t\t[\"Output\", formatPrice(cost?.output)],\n\t];\n\tconst unit = theme.fg(\"muted\", PRICE_UNIT_TEXT);\n\tconst lines: string[] = [\"\"];\n\tif (width >= PRICE_WIDE_LAYOUT_MIN_WIDTH) {\n\t\tconst columnWidth = Math.min(\n\t\t\tPRICE_COLUMN_MAX_WIDTH,\n\t\t\tMath.max(\n\t\t\t\tPRICE_COLUMN_MIN_WIDTH,\n\t\t\t\tMath.floor((width - CURSOR_WIDTH - (visibleWidth(PRICE_UNIT_TEXT) + 1)) / entries.length),\n\t\t\t),\n\t\t);\n\t\tconst row = (index: 0 | 1) =>\n\t\t\tentries\n\t\t\t\t.map((entry) => entry[index] + \" \".repeat(Math.max(0, columnWidth - visibleWidth(entry[index]))))\n\t\t\t\t.join(\"\");\n\t\tlines.push(`${theme.fg(\"muted\", row(0))} ${unit}`, theme.fg(\"text\", row(1)));\n\t} else {\n\t\tlines.push(\n\t\t\t...entries.map(([label, value], index) => {\n\t\t\t\tconst suffix = index === entries.length - 1 ? ` ${unit}` : \"\";\n\t\t\t\treturn `${theme.fg(\"muted\", `${label}:`)} ${theme.fg(\"text\", value)}${suffix}`;\n\t\t\t}),\n\t\t);\n\t}\n\treturn lines.map((line) => truncateToWidth(` ${line}`, width, \"…\"));\n}\n"]}