@bastani/atomic 0.9.25-alpha.1 → 0.9.25-alpha.3

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 (133) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/dist/builtin/intercom/package.json +2 -2
  3. package/dist/builtin/mcp/CHANGELOG.md +13 -0
  4. package/dist/builtin/mcp/index.bundle.mjs +489 -208
  5. package/dist/builtin/mcp/package.json +2 -2
  6. package/dist/builtin/subagents/package.json +3 -3
  7. package/dist/builtin/web-access/package.json +2 -2
  8. package/dist/builtin/workflows/CHANGELOG.md +12 -0
  9. package/dist/builtin/workflows/builtin/{chunk-e1254zvd.js → chunk-kfsnh3w7.js} +40 -12
  10. package/dist/builtin/workflows/builtin/{chunk-cpw5gtzg.js → chunk-rqmasd3d.js} +1 -1
  11. package/dist/builtin/workflows/builtin/{chunk-qy6g0baf.js → chunk-wz783pvd.js} +1 -1
  12. package/dist/builtin/workflows/builtin/goal.js +2 -2
  13. package/dist/builtin/workflows/builtin/index.js +3 -3
  14. package/dist/builtin/workflows/builtin/ralph.js +2 -2
  15. package/dist/builtin/workflows/package.json +2 -2
  16. package/dist/builtin/workflows/src/extension/index.bundle.mjs +472 -88
  17. package/dist/builtin/workflows/src/index.js +65 -28
  18. package/dist/core/agent-session-accessors.d.ts.map +1 -1
  19. package/dist/core/agent-session-accessors.js +7 -0
  20. package/dist/core/agent-session-accessors.js.map +1 -1
  21. package/dist/core/agent-session-extension-bindings.d.ts.map +1 -1
  22. package/dist/core/agent-session-extension-bindings.js +16 -2
  23. package/dist/core/agent-session-extension-bindings.js.map +1 -1
  24. package/dist/core/agent-session-methods.d.ts +7 -1
  25. package/dist/core/agent-session-methods.d.ts.map +1 -1
  26. package/dist/core/agent-session-methods.js.map +1 -1
  27. package/dist/core/agent-session-state.d.ts.map +1 -1
  28. package/dist/core/agent-session-state.js +3 -2
  29. package/dist/core/agent-session-state.js.map +1 -1
  30. package/dist/core/agent-session-types.d.ts +1 -0
  31. package/dist/core/agent-session-types.d.ts.map +1 -1
  32. package/dist/core/agent-session-types.js.map +1 -1
  33. package/dist/core/agent-session.d.ts +3 -0
  34. package/dist/core/agent-session.d.ts.map +1 -1
  35. package/dist/core/agent-session.js +6 -0
  36. package/dist/core/agent-session.js.map +1 -1
  37. package/dist/core/builtin-resource-loader.d.ts.map +1 -1
  38. package/dist/core/builtin-resource-loader.js +13 -1
  39. package/dist/core/builtin-resource-loader.js.map +1 -1
  40. package/dist/core/extensions/api-types.d.ts +3 -0
  41. package/dist/core/extensions/api-types.d.ts.map +1 -1
  42. package/dist/core/extensions/api-types.js.map +1 -1
  43. package/dist/core/extensions/index.d.ts +2 -0
  44. package/dist/core/extensions/index.d.ts.map +1 -1
  45. package/dist/core/extensions/index.js +1 -0
  46. package/dist/core/extensions/index.js.map +1 -1
  47. package/dist/core/extensions/loader-api.d.ts.map +1 -1
  48. package/dist/core/extensions/loader-api.js +11 -0
  49. package/dist/core/extensions/loader-api.js.map +1 -1
  50. package/dist/core/extensions/loader-runtime.d.ts.map +1 -1
  51. package/dist/core/extensions/loader-runtime.js +3 -0
  52. package/dist/core/extensions/loader-runtime.js.map +1 -1
  53. package/dist/core/extensions/mcp-server-registry.d.ts.map +1 -1
  54. package/dist/core/extensions/mcp-server-registry.js +4 -0
  55. package/dist/core/extensions/mcp-server-registry.js.map +1 -1
  56. package/dist/core/extensions/runner.d.ts +3 -0
  57. package/dist/core/extensions/runner.d.ts.map +1 -1
  58. package/dist/core/extensions/runner.js +4 -0
  59. package/dist/core/extensions/runner.js.map +1 -1
  60. package/dist/core/extensions/runtime-types.d.ts +3 -0
  61. package/dist/core/extensions/runtime-types.d.ts.map +1 -1
  62. package/dist/core/extensions/runtime-types.js.map +1 -1
  63. package/dist/core/extensions/tool-types.d.ts +1 -0
  64. package/dist/core/extensions/tool-types.d.ts.map +1 -1
  65. package/dist/core/extensions/tool-types.js.map +1 -1
  66. package/dist/core/extensions/workflow-run-control-hub.d.ts +23 -0
  67. package/dist/core/extensions/workflow-run-control-hub.d.ts.map +1 -0
  68. package/dist/core/extensions/workflow-run-control-hub.js +57 -0
  69. package/dist/core/extensions/workflow-run-control-hub.js.map +1 -0
  70. package/dist/core/extensions/workflow-run-control.d.ts +163 -0
  71. package/dist/core/extensions/workflow-run-control.d.ts.map +1 -0
  72. package/dist/core/extensions/workflow-run-control.js +73 -0
  73. package/dist/core/extensions/workflow-run-control.js.map +1 -0
  74. package/dist/core/mandatory-resource-loader.d.ts.map +1 -1
  75. package/dist/core/mandatory-resource-loader.js +9 -0
  76. package/dist/core/mandatory-resource-loader.js.map +1 -1
  77. package/dist/core/mcp-servers.d.ts +4 -1
  78. package/dist/core/mcp-servers.d.ts.map +1 -1
  79. package/dist/core/mcp-servers.js.map +1 -1
  80. package/dist/core/oauth-provider-metadata.js +1 -1
  81. package/dist/core/oauth-provider-metadata.js.map +1 -1
  82. package/dist/core/remote-catalog-provider.d.ts.map +1 -1
  83. package/dist/core/remote-catalog-provider.js +4 -9
  84. package/dist/core/remote-catalog-provider.js.map +1 -1
  85. package/dist/core/resource-loader-types.d.ts +4 -0
  86. package/dist/core/resource-loader-types.d.ts.map +1 -1
  87. package/dist/core/resource-loader-types.js.map +1 -1
  88. package/dist/core/sdk.js +1 -0
  89. package/dist/core/sdk.js.map +1 -1
  90. package/dist/core/structured-output/index.d.ts.map +1 -1
  91. package/dist/core/structured-output/index.js +3 -1
  92. package/dist/core/structured-output/index.js.map +1 -1
  93. package/dist/core/tool-loadout.d.ts +1 -0
  94. package/dist/core/tool-loadout.d.ts.map +1 -1
  95. package/dist/core/tool-loadout.js +3 -0
  96. package/dist/core/tool-loadout.js.map +1 -1
  97. package/dist/core/tools/bash.d.ts.map +1 -1
  98. package/dist/core/tools/bash.js +11 -30
  99. package/dist/core/tools/bash.js.map +1 -1
  100. package/dist/extensions/codemode/execute.d.ts.map +1 -1
  101. package/dist/extensions/codemode/execute.js +26 -0
  102. package/dist/extensions/codemode/execute.js.map +1 -1
  103. package/dist/extensions/codemode/renderer.d.ts.map +1 -1
  104. package/dist/extensions/codemode/renderer.js +38 -23
  105. package/dist/extensions/codemode/renderer.js.map +1 -1
  106. package/dist/extensions/codemode/tool.d.ts.map +1 -1
  107. package/dist/extensions/codemode/tool.js +22 -10
  108. package/dist/extensions/codemode/tool.js.map +1 -1
  109. package/dist/extensions/tool-search/tool.d.ts +1 -1
  110. package/dist/extensions/tool-search/tool.d.ts.map +1 -1
  111. package/dist/extensions/tool-search/tool.js +3 -13
  112. package/dist/extensions/tool-search/tool.js.map +1 -1
  113. package/dist/index-extensions.d.ts +2 -1
  114. package/dist/index-extensions.d.ts.map +1 -1
  115. package/dist/index-extensions.js +1 -1
  116. package/dist/index-extensions.js.map +1 -1
  117. package/dist/modes/interactive/components/visual-truncate.d.ts +27 -3
  118. package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -1
  119. package/dist/modes/interactive/components/visual-truncate.js +39 -6
  120. package/dist/modes/interactive/components/visual-truncate.js.map +1 -1
  121. package/docs/extensions/events.md +2 -0
  122. package/docs/mcp-servers.md +47 -0
  123. package/docs/providers.md +9 -1
  124. package/docs/sdk/reference.md +22 -0
  125. package/docs/sdk/structured-decisions.md +2 -0
  126. package/docs/sdk.md +67 -1
  127. package/docs/settings.md +2 -0
  128. package/docs/tools.md +6 -0
  129. package/docs/workflows/operations.md +3 -1
  130. package/examples/extensions/built-in-tool-renderer.ts +16 -40
  131. package/examples/extensions/minimal-mode.ts +28 -108
  132. package/npm-shrinkwrap.json +69 -69
  133. package/package.json +8 -8
@@ -1 +1 @@
1
- {"version":3,"file":"renderer.js","sourceRoot":"","sources":["../../../src/extensions/codemode/renderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAE9C,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,kCAAkC,CAAC;AACnF,OAAO,EAAE,OAAO,EAAE,MAAM,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E,OAAO,SAAS,CAAC;IAClB,CAAC;CACD,CAAC","sourcesContent":["import { Text } from \"@earendil-works/pi-tui\";\nimport type { ToolDefinition } from \"../../core/extensions/types.ts\";\nimport { getTextOutput, replaceTabs, str } from \"../../core/tools/render-utils.ts\";\nimport { keyHint } from \"../../modes/interactive/components/keybinding-hints.js\";\nimport { highlightCode, type Theme } from \"../../modes/interactive/theme/theme.js\";\nimport type { CodemodeNestedCall, CodemodeToolDetails, codemodeSchema } from \"./tool.js\";\n\nconst SCRIPT_HEADER = /^Script (completed|failed)\\nWall time [\\d.]+ seconds\\nOutput:\\n$/;\nfunction hint(theme: Theme, count: number, noun: string): string {\n\treturn `${theme.fg(\"muted\", `... (${count} more ${noun},`)} ${keyHint(\"app.tools.expand\", \"to expand\")}${theme.fg(\"muted\", \")\")}`;\n}\nfunction cost(value: number): string {\n\treturn `$${value >= 0.01 ? value.toFixed(2) : value.toPrecision(2)}`;\n}\nfunction formatCall(call: CodemodeNestedCall, theme: Theme, expanded: boolean): string {\n\tconst icon =\n\t\tcall.status === \"running\"\n\t\t\t? theme.fg(\"warning\", \"…\")\n\t\t\t: call.status === \"ok\"\n\t\t\t\t? theme.fg(\"success\", \"✓\")\n\t\t\t\t: call.status === \"error\"\n\t\t\t\t\t? theme.fg(\"error\", \"✗\")\n\t\t\t\t\t: theme.fg(\"muted\", \"⊘\");\n\tconst args = !expanded && call.args.length > 80 ? `${call.args.slice(0, 77)}...` : call.args;\n\tlet text = `${icon} ${theme.fg(\"toolTitle\", call.name)}${args ? ` ${theme.fg(\"muted\", args)}` : \"\"}`;\n\tif (call.durationMs !== undefined)\n\t\ttext += ` ${theme.fg(\"dim\", call.durationMs < 1000 ? `${Math.round(call.durationMs)}ms` : `${(call.durationMs / 1000).toFixed(1)}s`)}`;\n\tif (call.cost) text += ` ${theme.fg(\"dim\", cost(call.cost))}`;\n\tif (expanded && call.error) text += `\\n ${theme.fg(\"error\", call.error.split(\"\\n\").join(\"\\n \"))}`;\n\treturn text;\n}\nexport const codemodeRenderers: Pick<\n\tToolDefinition<typeof codemodeSchema, CodemodeToolDetails>,\n\t\"renderCall\" | \"renderResult\"\n> = {\n\trenderCall(args, theme, context) {\n\t\tconst code = str(args?.code);\n\t\tlet text = theme.fg(\"toolTitle\", theme.bold(\"codemode\"));\n\t\tif (code === null) text += ` ${theme.fg(\"error\", \"[invalid arg]\")}`;\n\t\telse if (code) {\n\t\t\tconst lines = highlightCode(replaceTabs(code.replace(/\\r/g, \"\").trimEnd()), \"javascript\");\n\t\t\tconst shown = context.expanded ? lines : lines.slice(0, 10);\n\t\t\ttext += `\\n${shown.join(\"\\n\")}`;\n\t\t\tif (shown.length < lines.length) text += `\\n${hint(theme, lines.length - shown.length, \"lines\")}`;\n\t\t}\n\t\tconst component = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\tcomponent.setText(text);\n\t\treturn component;\n\t},\n\trenderResult(result, options, theme, context) {\n\t\tconst sections: string[] = [];\n\t\tconst calls = result.details?.calls ?? [];\n\t\tif (calls.length) {\n\t\t\tconst shown = options.expanded ? calls : calls.slice(-8);\n\t\t\tconst lines = shown.map((call) => formatCall(call, theme, options.expanded));\n\t\t\tif (shown.length < calls.length) lines.unshift(hint(theme, calls.length - shown.length, \"earlier calls\"));\n\t\t\tconst priced = calls.filter((call) => call.cost);\n\t\t\tif (priced.length > 1)\n\t\t\t\tlines.push(\n\t\t\t\t\ttheme.fg(\"muted\", `Model calls: ${cost(priced.reduce((sum, call) => sum + (call.cost ?? 0), 0))}`),\n\t\t\t\t);\n\t\t\tsections.push(lines.join(\"\\n\"));\n\t\t}\n\t\tconst [first, ...rest] = result.content;\n\t\tconst content = first?.type === \"text\" && SCRIPT_HEADER.test(first.text) ? rest : result.content;\n\t\tconst output = options.isPartial ? \"\" : getTextOutput({ ...result, content }, context.showImages).trim();\n\t\tif (output) {\n\t\t\tconst lines = replaceTabs(output).split(\"\\n\");\n\t\t\tconst shown = options.expanded ? lines : lines.slice(0, 5);\n\t\t\tlet text = shown.map((line) => theme.fg(context.isError ? \"error\" : \"toolOutput\", line)).join(\"\\n\");\n\t\t\tif (shown.length < lines.length) text += `\\n${hint(theme, lines.length - shown.length, \"lines\")}`;\n\t\t\tif (result.details?.fullOutputPath && !options.expanded)\n\t\t\t\ttext += `\\n${theme.fg(\"muted\", `Full output: ${result.details.fullOutputPath}`)}`;\n\t\t\tsections.push(text);\n\t\t}\n\t\tconst component = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\tcomponent.setText(sections.length ? `\\n${sections.join(\"\\n\\n\")}` : \"\");\n\t\treturn component;\n\t},\n};\n"]}
1
+ {"version":3,"file":"renderer.js","sourceRoot":"","sources":["../../../src/extensions/codemode/renderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAEjE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,kCAAkC,CAAC;AACnF,OAAO,EAAE,OAAO,EAAE,MAAM,wDAAwD,CAAC;AACjF,OAAO,EAAE,iBAAiB,EAAE,MAAM,uDAAuD,CAAC;AAC1F,OAAO,EAAE,aAAa,EAAc,MAAM,wCAAwC,CAAC;AAGnF,MAAM,aAAa,GAAG,kEAAkE,CAAC;AACzF,SAAS,IAAI,CAAC,KAAY,EAAE,KAAa,EAAE,IAAY;IACtD,OAAO,GAAG,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,QAAQ,KAAK,SAAS,IAAI,GAAG,CAAC,IAAI,OAAO,CAAC,kBAAkB,EAAE,WAAW,CAAC,GAAG,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC,EAAE,CAAC;AACnI,CAAC;AACD,SAAS,IAAI,CAAC,KAAa;IAC1B,OAAO,IAAI,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KA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C,IAAI,CAAC;iBACX,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;iBACvE,IAAI,CAAC,IAAI,CAAC,CAAC;YACb,SAAS,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;YAClC,SAAS,CAAC,QAAQ,CACjB,OAAO,CAAC,QAAQ;gBACf,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC;gBACxB,CAAC,CAAC,IAAI,iBAAiB,CAAC;oBACtB,IAAI,EAAE,MAAM;oBACZ,cAAc,EAAE,CAAC;oBACjB,IAAI,EAAE,OAAO;oBACb,UAAU,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC;iBACpD,CAAC,CACJ,CAAC;YACF,IAAI,MAAM,CAAC,OAAO,EAAE,cAAc,IAAI,CAAC,OAAO,CAAC,QAAQ;gBACtD,SAAS,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,gBAAgB,MAAM,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QACzG,CAAC;QACD,OAAO,SAAS,CAAC;IAClB,CAAC;CACD,CAAC","sourcesContent":["import { Container, Spacer, Text } from \"@earendil-works/pi-tui\";\nimport type { ToolDefinition } from \"../../core/extensions/types.ts\";\nimport { getTextOutput, replaceTabs, str } from \"../../core/tools/render-utils.ts\";\nimport { keyHint } from \"../../modes/interactive/components/keybinding-hints.js\";\nimport { VisualLinePreview } from \"../../modes/interactive/components/visual-truncate.ts\";\nimport { highlightCode, type Theme } from \"../../modes/interactive/theme/theme.js\";\nimport type { CodemodeNestedCall, CodemodeToolDetails, codemodeSchema } from \"./tool.js\";\n\nconst SCRIPT_HEADER = /^Script (completed|failed)\\nWall time [\\d.]+ seconds\\nOutput:\\n$/;\nfunction hint(theme: Theme, count: number, noun: string): string {\n\treturn `${theme.fg(\"muted\", `... (${count} more ${noun},`)} ${keyHint(\"app.tools.expand\", \"to expand\")}${theme.fg(\"muted\", \")\")}`;\n}\nfunction cost(value: number): string {\n\treturn `$${value >= 0.01 ? value.toFixed(2) : value.toPrecision(2)}`;\n}\nfunction formatCall(call: CodemodeNestedCall, theme: Theme, expanded: boolean): string {\n\tconst icon =\n\t\tcall.status === \"running\"\n\t\t\t? theme.fg(\"warning\", \"…\")\n\t\t\t: call.status === \"ok\"\n\t\t\t\t? theme.fg(\"success\", \"✓\")\n\t\t\t\t: call.status === \"error\"\n\t\t\t\t\t? theme.fg(\"error\", \"✗\")\n\t\t\t\t\t: theme.fg(\"muted\", \"⊘\");\n\tconst args = !expanded && call.args.length > 80 ? `${call.args.slice(0, 77)}...` : call.args;\n\tlet text = `${icon} ${theme.fg(\"toolTitle\", call.name)}${args ? ` ${theme.fg(\"muted\", args)}` : \"\"}`;\n\tif (call.durationMs !== undefined)\n\t\ttext += ` ${theme.fg(\"dim\", call.durationMs < 1000 ? `${Math.round(call.durationMs)}ms` : `${(call.durationMs / 1000).toFixed(1)}s`)}`;\n\tif (call.cost) text += ` ${theme.fg(\"dim\", cost(call.cost))}`;\n\tif (expanded && call.error) text += `\\n ${theme.fg(\"error\", call.error.split(\"\\n\").join(\"\\n \"))}`;\n\treturn text;\n}\nexport const codemodeRenderers: Pick<\n\tToolDefinition<typeof codemodeSchema, CodemodeToolDetails>,\n\t\"renderCall\" | \"renderResult\"\n> = {\n\trenderCall(args, theme, context) {\n\t\tconst code = str(args?.code);\n\t\tconst title = theme.fg(\"toolTitle\", theme.bold(\"codemode\"));\n\t\tconst component = (context.lastComponent as Container | undefined) ?? new Container();\n\t\tcomponent.clear();\n\t\tif (code === null) {\n\t\t\tcomponent.addChild(new Text(`${title} ${theme.fg(\"error\", \"[invalid arg]\")}`, 0, 0));\n\t\t\treturn component;\n\t\t}\n\t\tcomponent.addChild(new Text(title, 0, 0));\n\t\tif (code) {\n\t\t\tconst highlighted = highlightCode(replaceTabs(code.replace(/\\r/g, \"\").trimEnd()), \"javascript\").join(\"\\n\");\n\t\t\tcomponent.addChild(\n\t\t\t\tcontext.expanded\n\t\t\t\t\t? new Text(highlighted, 0, 0)\n\t\t\t\t\t: new VisualLinePreview({\n\t\t\t\t\t\t\ttext: highlighted,\n\t\t\t\t\t\t\tmaxVisualLines: 10,\n\t\t\t\t\t\t\tkeep: \"start\",\n\t\t\t\t\t\t\tformatHint: (hidden) => hint(theme, hidden, \"lines\"),\n\t\t\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t\treturn component;\n\t},\n\trenderResult(result, options, theme, context) {\n\t\tconst component = (context.lastComponent as Container | undefined) ?? new Container();\n\t\tcomponent.clear();\n\t\tconst calls = result.details?.calls ?? [];\n\t\tif (calls.length) {\n\t\t\tconst shown = options.expanded ? calls : calls.slice(-8);\n\t\t\tconst lines = shown.map((call) => formatCall(call, theme, options.expanded));\n\t\t\tif (shown.length < calls.length) lines.unshift(hint(theme, calls.length - shown.length, \"earlier calls\"));\n\t\t\tconst priced = calls.filter((call) => call.cost);\n\t\t\tif (priced.length > 1)\n\t\t\t\tlines.push(\n\t\t\t\t\ttheme.fg(\"muted\", `Model calls: ${cost(priced.reduce((sum, call) => sum + (call.cost ?? 0), 0))}`),\n\t\t\t\t);\n\t\t\tcomponent.addChild(new Spacer(1));\n\t\t\tcomponent.addChild(new Text(lines.join(\"\\n\"), 0, 0));\n\t\t}\n\t\tconst [first, ...rest] = result.content;\n\t\tconst content = first?.type === \"text\" && SCRIPT_HEADER.test(first.text) ? rest : result.content;\n\t\tconst output = options.isPartial ? \"\" : getTextOutput({ ...result, content }, context.showImages).trim();\n\t\tif (output) {\n\t\t\tconst styled = replaceTabs(output)\n\t\t\t\t.split(\"\\n\")\n\t\t\t\t.map((line) => theme.fg(context.isError ? \"error\" : \"toolOutput\", line))\n\t\t\t\t.join(\"\\n\");\n\t\t\tcomponent.addChild(new Spacer(1));\n\t\t\tcomponent.addChild(\n\t\t\t\toptions.expanded\n\t\t\t\t\t? new Text(styled, 0, 0)\n\t\t\t\t\t: new VisualLinePreview({\n\t\t\t\t\t\t\ttext: styled,\n\t\t\t\t\t\t\tmaxVisualLines: 5,\n\t\t\t\t\t\t\tkeep: \"start\",\n\t\t\t\t\t\t\tformatHint: (hidden) => hint(theme, hidden, \"lines\"),\n\t\t\t\t\t\t}),\n\t\t\t);\n\t\t\tif (result.details?.fullOutputPath && !options.expanded)\n\t\t\t\tcomponent.addChild(new Text(theme.fg(\"muted\", `Full output: ${result.details.fullOutputPath}`), 0, 0));\n\t\t}\n\t\treturn component;\n\t},\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../../src/extensions/codemode/tool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,KAAK,EAAsB,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAGpF,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAe,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC3G,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAInE,eAAO,MAAM,kBAAkB,aAAa,CAAC;AAC7C,eAAO,MAAM,yBAAyB,mBAAmB,CAAC;AAC1D,eAAO,MAAM,8BAA8B,OAAO,CAAC;AACnD,MAAM,WAAW,sBAAsB;IACtC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7B,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AAY,EAAE,SAAS,CAAC,CAOpF;AACD,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,SAAS,SAAS,EAAE,GAAG,SAAS,EAAE,CAEjF;AACD,MAAM,WAAW,0BAA0B;IAC1C,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAChD,QAAQ,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC/B,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB;AAUD,wBAAgB,yBAAyB,CACxC,KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,OAAO,GAAE,0BAA+B,GACtC,MAAM,CAgER;AA+BD,wBAAgB,4BAA4B,CAC3C,OAAO,GAAE,mBAAwB,GAC/B,cAAc,CAAC,OAAO,cAAc,EAAE,mBAAmB,CAAC,CAgB5D;AACD,wBAAgB,kBAAkB,CACjC,KAAK,GAAE,SAAS,SAAS,EAAO,EAChC,OAAO,GAAE,mBAAwB,GAC/B,SAAS,CAAC,OAAO,cAAc,CAAC,CAKlC"}
@@ -29,12 +29,15 @@ const INTRO = `Run JavaScript that composes tool calls in a fresh QuickJS worker
29
29
  Top-level await and return work. Use tools.name(args), or tools["raw-name"](args). Tool names normalize to JavaScript identifiers.
30
30
  No Node, filesystem, network, timers, modules or credentials are available directly. Calls go through session validation and permission hooks. They have real side effects and are not undone after script failure.
31
31
  Tools with output schemas resolve to structuredContent; others resolve to text. Failed or blocked calls throw. Scripts have a 256 MB memory limit.
32
- Globals: ALL_TOOLS, text(value), image(base64DataUrlOrImageContent), exit(), console.log(...), store(key, value), load(key), searchTools(query, {limit?, namespace?}), describeTool(name).
32
+ Globals: ALL_TOOLS, text(value), image(base64DataUrlOrImageContent), exit(), console.log(...), store(key, value), load(key), searchTools(query, {limit?, namespace?}), describeTool(name), describeNamespace(name).
33
+ describeNamespace(name) returns { name, description?, instructions?, tools } for a callable tool namespace, or undefined. Namespace instructions are available on request, not in tool listings.
33
34
  Successful scripts persist store writes on the current session branch; failed scripts discard writes. Unawaited calls are cancelled when the script ends.
34
35
  Optional first line: // @options: {"max_output_tokens": 1000, "timeout_ms": 60000}. Output defaults to 10000 tokens; there is no default deadline.`;
35
36
  export function createCodemodeDescription(tools, options = {}) {
36
37
  const groups = new Map();
37
38
  for (const tool of getCodemodeCallableTools(tools)) {
39
+ if (options.deferred?.has(tool.name))
40
+ continue;
38
41
  const namespace = options.namespaces?.get(tool.name);
39
42
  const key = namespace?.name ?? "";
40
43
  let group = groups.get(key);
@@ -48,14 +51,13 @@ export function createCodemodeDescription(tools, options = {}) {
48
51
  name: tool.name,
49
52
  section,
50
53
  cost: Math.ceil(section.length / 4),
51
- deferred: options.deferred?.has(tool.name) === true,
52
54
  });
53
55
  }
54
56
  const ordered = [...groups.values()].sort((a, b) => a.namespace === undefined ? -1 : b.namespace === undefined ? 1 : a.namespace.name.localeCompare(b.namespace.name));
55
57
  const shown = new Set();
56
58
  let remaining = options.inlineBudget ?? Number.POSITIVE_INFINITY;
57
59
  let queues = ordered
58
- .map((group) => group.entries.filter((entry) => !entry.deferred).sort((a, b) => a.cost - b.cost))
60
+ .map((group) => [...group.entries].sort((a, b) => a.cost - b.cost))
59
61
  .filter((queue) => queue.length);
60
62
  while (queues.length)
61
63
  queues = queues.filter((queue) => {
@@ -67,16 +69,26 @@ export function createCodemodeDescription(tools, options = {}) {
67
69
  queue.shift();
68
70
  return queue.length > 0;
69
71
  });
70
- const sections = [INTRO];
72
+ const sections = [
73
+ INTRO,
74
+ "Some nested tools may be omitted, including deferred tools. They remain available through tools and ALL_TOOLS. Use await searchTools(query), describeTool(name), or describeNamespace(name) to discover them.",
75
+ ];
71
76
  if (options.models)
72
77
  sections.push("Model API: models.getModelsOfType(type, provider?), models.getAvailableOfType(type, provider?), models.getModelOfType(type, provider, id), models.classify(model, context). Types are chat, image, classifier. Catalog entries exclude headers; classifier calls resolve credentials on the host.");
73
- const count = getCodemodeCallableTools(tools).length;
74
- sections.push(shown.size === count
75
- ? `Nested tools: COMPLETE list (${count} tools).`
76
- : `Nested tools: PARTIAL - ${shown.size} of ${count} shown. Use searchTools(), describeTool(), or ALL_TOOLS for omitted/deferred tools.`);
78
+ if (ordered.length === 0)
79
+ return sections.join("\n\n");
80
+ sections.push("Nested tools:");
77
81
  for (const group of ordered) {
78
- if (group.namespace)
79
- sections.push(`## ${group.namespace.name} (${group.entries.length} tools)\n${group.namespace.description ?? ""}`);
82
+ if (group.namespace) {
83
+ const visible = group.entries.filter((entry) => shown.has(entry.name));
84
+ const listing = visible.length === group.entries.length
85
+ ? ""
86
+ : visible.length === 0
87
+ ? " (tools not listed)"
88
+ : " (some tools not listed)";
89
+ const description = group.namespace.description?.trim();
90
+ sections.push(`## ${group.namespace.name}${listing}${description ? `\n${description}` : ""}`);
91
+ }
80
92
  for (const entry of group.entries)
81
93
  if (shown.has(entry.name))
82
94
  sections.push(entry.section);
@@ -1 +1 @@
1
- {"version":3,"file":"tool.js","sourceRoot":"","sources":["../../../src/extensions/codemode/tool.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,0CAA0C,CAAC;AAClG,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAC7E,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAI5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,6CAA6C,CAAC;AACjF,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAElD,MAAM,CAAC,MAAM,kBAAkB,GAAG,UAAU,CAAC;AAC7C,MAAM,CAAC,MAAM,yBAAyB,GAAG,gBAAgB,CAAC;AAC1D,MAAM,CAAC,MAAM,8BAA8B,GAAG,IAAI,CAAC;AAgBnD,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAC,MAAM,CAAC;IACzC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC;QACjB,WAAW,EACV,0I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AS,EAAE,QAAQ,EAAE,EAAE,WAAW,EAAE,uBAAuB,EAAE,EAAE;QAC5F,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,CACjD,CAAC,MAAM,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,eAAe,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,CAAC;QACxF,GAAG,iBAAiB;KACpB,CAAC;AACH,CAAC;AACD,MAAM,UAAU,kBAAkB,CACjC,KAAK,GAAyB,EAAE,EAChC,OAAO,GAAwB,EAAE;IAEjC,OAAO;QACN,GAAG,kBAAkB,CAAC,4BAA4B,CAAC,OAAO,CAAC,CAAC;QAC5D,WAAW,EAAE,yBAAyB,CAAC,KAAK,EAAE,OAAO,CAAC;KACtD,CAAC;AACH,CAAC","sourcesContent":["import type { AgentTool } from \"@earendil-works/pi-agent-core\";\nimport type { CodemodeJsonSchema, CodemodeTool } from \"@earendil-works/pi-codemode\";\nimport { renderToolSample, toCodemodeIdentifier } from \"@earendil-works/pi-codemode/declarations\";\nimport { CODEMODE_SOURCE_GRAMMAR } from \"@earendil-works/pi-codemode/source\";\nimport { type Static, Type } from \"typebox\";\nimport type { ToolDefinition, ToolInfo, ToolLoadout, ToolNamespace } from \"../../core/extensions/types.ts\";\nimport type { ModelRegistry } from \"../../core/model-registry.ts\";\nimport type { CodemodeMode } from \"../../core/settings-manager.ts\";\nimport { wrapToolDefinition } from \"../../core/tools/tool-definition-wrapper.ts\";\nimport { codemodeRenderers } from \"./renderer.js\";\n\nexport const CODEMODE_TOOL_NAME = \"codemode\";\nexport const CODEMODE_STORE_ENTRY_TYPE = \"codemode-store\";\nexport const DEFAULT_CODEMODE_INLINE_BUDGET = 3000;\nexport interface CodemodeStoreEntryData {\n\tset: Record<string, unknown>;\n\tdelete: string[];\n}\nexport type CodemodeModelRuntime = Pick<\n\tModelRegistry,\n\t\"getModelsOfType\" | \"getAvailableOfType\" | \"getModelOfType\" | \"classify\"\n>;\nexport interface CodemodeToolOptions {\n\tgetToolNamespace?: (name: string) => ToolNamespace | undefined;\n\tmodels?: boolean;\n\tappendEntry?: (type: string, data: CodemodeStoreEntryData) => void;\n\tgetMode?: () => CodemodeMode;\n\tgetInlineBudget?: () => number | undefined;\n}\nexport const codemodeSchema = Type.Object({\n\tcode: Type.String({\n\t\tdescription:\n\t\t\t'Raw JavaScript source with top-level await and return. Optional first line // @options: {\"max_output_tokens\": 1000, \"timeout_ms\": 60000}',\n\t}),\n});\nexport type CodemodeToolInput = Static<typeof codemodeSchema>;\nexport function isCodemodeTool(tool: Pick<ToolInfo, \"name\" | \"parameters\">): boolean {\n\treturn tool.name === CODEMODE_TOOL_NAME && tool.parameters === codemodeSchema;\n}\nexport interface CodemodeNestedCall {\n\tid: string;\n\tname: string;\n\targs: string;\n\tstatus: \"running\" | \"ok\" | \"error\" | \"cancelled\";\n\tdurationMs?: number;\n\terror?: string;\n\tcost?: number;\n}\nexport interface CodemodeToolDetails {\n\tcalls: CodemodeNestedCall[];\n\tfullOutputPath?: string;\n}\nexport function toCodemodeDeclaration(tool: AgentTool): Omit<CodemodeTool, \"execute\"> {\n\treturn {\n\t\tname: tool.name,\n\t\tdescription: tool.description,\n\t\tinputSchema: tool.parameters as CodemodeJsonSchema,\n\t\toutputSchema: (tool.outputSchema as CodemodeJsonSchema | undefined) ?? { type: \"string\" },\n\t};\n}\nexport function getCodemodeCallableTools(tools: readonly AgentTool[]): AgentTool[] {\n\treturn tools.filter((tool) => tool.name !== CODEMODE_TOOL_NAME);\n}\nexport interface CodemodeDescriptionOptions {\n\tmodels?: boolean;\n\tnamespaces?: ReadonlyMap<string, ToolNamespace>;\n\tdeferred?: ReadonlySet<string>;\n\tinlineBudget?: number;\n}\nconst INTRO = `Run JavaScript that composes tool calls in a fresh QuickJS worker sandbox.\nTop-level await and return work. Use tools.name(args), or tools[\"raw-name\"](args). Tool names normalize to JavaScript identifiers.\nNo Node, filesystem, network, timers, modules or credentials are available directly. Calls go through session validation and permission hooks. They have real side effects and are not undone after script failure.\nTools with output schemas resolve to structuredContent; others resolve to text. Failed or blocked calls throw. Scripts have a 256 MB memory limit.\nGlobals: ALL_TOOLS, text(value), image(base64DataUrlOrImageContent), exit(), console.log(...), store(key, value), load(key), searchTools(query, {limit?, namespace?}), describeTool(name).\nSuccessful scripts persist store writes on the current session branch; failed scripts discard writes. Unawaited calls are cancelled when the script ends.\nOptional first line: // @options: {\"max_output_tokens\": 1000, \"timeout_ms\": 60000}. Output defaults to 10000 tokens; there is no default deadline.`;\n\nexport function createCodemodeDescription(\n\ttools: readonly AgentTool[],\n\toptions: CodemodeDescriptionOptions = {},\n): string {\n\tconst groups = new Map<\n\t\tstring,\n\t\t{ namespace?: ToolNamespace; entries: { name: string; section: string; cost: number; deferred: boolean }[] }\n\t>();\n\tfor (const tool of getCodemodeCallableTools(tools)) {\n\t\tconst namespace = options.namespaces?.get(tool.name);\n\t\tconst key = namespace?.name ?? \"\";\n\t\tlet group = groups.get(key);\n\t\tif (!group) {\n\t\t\tgroup = { namespace, entries: [] };\n\t\t\tgroups.set(key, group);\n\t\t}\n\t\tconst id = toCodemodeIdentifier(tool.name);\n\t\tconst section = `### \\`${id}\\`${id === tool.name ? \"\" : ` (\\`${tool.name}\\`)`}\\n${renderToolSample(toCodemodeDeclaration(tool)).trim()}`;\n\t\tgroup.entries.push({\n\t\t\tname: tool.name,\n\t\t\tsection,\n\t\t\tcost: Math.ceil(section.length / 4),\n\t\t\tdeferred: options.deferred?.has(tool.name) === true,\n\t\t});\n\t}\n\tconst ordered = [...groups.values()].sort((a, b) =>\n\t\ta.namespace === undefined ? -1 : b.namespace === undefined ? 1 : a.namespace.name.localeCompare(b.namespace.name),\n\t);\n\tconst shown = new Set<string>();\n\tlet remaining = options.inlineBudget ?? Number.POSITIVE_INFINITY;\n\tlet queues = ordered\n\t\t.map((group) => group.entries.filter((entry) => !entry.deferred).sort((a, b) => a.cost - b.cost))\n\t\t.filter((queue) => queue.length);\n\twhile (queues.length)\n\t\tqueues = queues.filter((queue) => {\n\t\t\tconst next = queue[0];\n\t\t\tif (next.cost > remaining) return false;\n\t\t\tremaining -= next.cost;\n\t\t\tshown.add(next.name);\n\t\t\tqueue.shift();\n\t\t\treturn queue.length > 0;\n\t\t});\n\tconst sections = [INTRO];\n\tif (options.models)\n\t\tsections.push(\n\t\t\t\"Model API: models.getModelsOfType(type, provider?), models.getAvailableOfType(type, provider?), models.getModelOfType(type, provider, id), models.classify(model, context). Types are chat, image, classifier. Catalog entries exclude headers; classifier calls resolve credentials on the host.\",\n\t\t);\n\tconst count = getCodemodeCallableTools(tools).length;\n\tsections.push(\n\t\tshown.size === count\n\t\t\t? `Nested tools: COMPLETE list (${count} tools).`\n\t\t\t: `Nested tools: PARTIAL - ${shown.size} of ${count} shown. Use searchTools(), describeTool(), or ALL_TOOLS for omitted/deferred tools.`,\n\t);\n\tfor (const group of ordered) {\n\t\tif (group.namespace)\n\t\t\tsections.push(\n\t\t\t\t`## ${group.namespace.name} (${group.entries.length} tools)\\n${group.namespace.description ?? \"\"}`,\n\t\t\t);\n\t\tfor (const entry of group.entries) if (shown.has(entry.name)) sections.push(entry.section);\n\t}\n\treturn sections.join(\"\\n\\n\");\n}\nfunction prepareLoadout(loadout: ToolLoadout, options: CodemodeToolOptions) {\n\tconst only = options.getMode?.() === \"only\";\n\tconst callable = getCodemodeCallableTools(loadout.callable);\n\tconst descriptions: Record<string, string> = {};\n\tif (!only)\n\t\tfor (const tool of loadout.declared)\n\t\t\tif (callable.some((candidate) => candidate.name === tool.name))\n\t\t\t\tdescriptions[tool.name] = renderToolSample(toCodemodeDeclaration(tool));\n\tconst listed = only ? callable : callable.filter((tool) => loadout.getExposure(tool.name) !== \"direct\");\n\tconst namespaces = new Map(\n\t\tlisted.flatMap((tool) => {\n\t\t\tconst namespace = loadout.getNamespace(tool.name);\n\t\t\treturn namespace ? [[tool.name, namespace] as const] : [];\n\t\t}),\n\t);\n\tdescriptions[CODEMODE_TOOL_NAME] = createCodemodeDescription(listed, {\n\t\tmodels: options.models,\n\t\tnamespaces,\n\t\tdeferred: new Set(\n\t\t\tlisted.filter((tool) => loadout.getExposure(tool.name) === \"deferred\").map((tool) => tool.name),\n\t\t),\n\t\tinlineBudget: options.getInlineBudget?.() ?? DEFAULT_CODEMODE_INLINE_BUDGET,\n\t});\n\treturn {\n\t\tdescriptions,\n\t\thiddenDeclarations: only\n\t\t\t? callable.filter((tool) => loadout.getExposure(tool.name) === \"direct\").map((tool) => tool.name)\n\t\t\t: [],\n\t};\n}\nexport function createCodemodeToolDefinition(\n\toptions: CodemodeToolOptions = {},\n): ToolDefinition<typeof codemodeSchema, CodemodeToolDetails> {\n\treturn {\n\t\tname: CODEMODE_TOOL_NAME,\n\t\tlabel: CODEMODE_TOOL_NAME,\n\t\tdescription: createCodemodeDescription([], options),\n\t\tparameters: codemodeSchema,\n\t\texposure: \"model-only\",\n\t\tconcurrency: \"exclusive\",\n\t\tdefaultActive: false,\n\t\tpromptSnippet: \"Run JavaScript that calls other tools, filters results, or batches independent calls\",\n\t\tprepareLoadout: (loadout) => prepareLoadout(loadout, options),\n\t\tconstrainedSampling: { type: \"grammar\", variants: { openai_lark: CODEMODE_SOURCE_GRAMMAR } },\n\t\texecute: async (id, input, signal, update, ctx) =>\n\t\t\t(await import(\"./execute.js\")).executeCodemode(id, input, signal, update, ctx, options),\n\t\t...codemodeRenderers,\n\t};\n}\nexport function createCodemodeTool(\n\ttools: readonly AgentTool[] = [],\n\toptions: CodemodeToolOptions = {},\n): AgentTool<typeof codemodeSchema> {\n\treturn {\n\t\t...wrapToolDefinition(createCodemodeToolDefinition(options)),\n\t\tdescription: createCodemodeDescription(tools, options),\n\t};\n}\n"]}
1
+ {"version":3,"file":"tool.js","sourceRoot":"","sources":["../../../src/extensions/codemode/tool.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,o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AChC,OAAO,GAAwB,EAAE;IAEjC,OAAO;QACN,GAAG,kBAAkB,CAAC,4BAA4B,CAAC,OAAO,CAAC,CAAC;QAC5D,WAAW,EAAE,yBAAyB,CAAC,KAAK,EAAE,OAAO,CAAC;KACtD,CAAC;AACH,CAAC","sourcesContent":["import type { AgentTool } from \"@earendil-works/pi-agent-core\";\nimport type { CodemodeJsonSchema, CodemodeTool } from \"@earendil-works/pi-codemode\";\nimport { renderToolSample, toCodemodeIdentifier } from \"@earendil-works/pi-codemode/declarations\";\nimport { CODEMODE_SOURCE_GRAMMAR } from \"@earendil-works/pi-codemode/source\";\nimport { type Static, Type } from \"typebox\";\nimport type { ToolDefinition, ToolInfo, ToolLoadout, ToolNamespace } from \"../../core/extensions/types.ts\";\nimport type { ModelRegistry } from \"../../core/model-registry.ts\";\nimport type { CodemodeMode } from \"../../core/settings-manager.ts\";\nimport { wrapToolDefinition } from \"../../core/tools/tool-definition-wrapper.ts\";\nimport { codemodeRenderers } from \"./renderer.js\";\n\nexport const CODEMODE_TOOL_NAME = \"codemode\";\nexport const CODEMODE_STORE_ENTRY_TYPE = \"codemode-store\";\nexport const DEFAULT_CODEMODE_INLINE_BUDGET = 3000;\nexport interface CodemodeStoreEntryData {\n\tset: Record<string, unknown>;\n\tdelete: string[];\n}\nexport type CodemodeModelRuntime = Pick<\n\tModelRegistry,\n\t\"getModelsOfType\" | \"getAvailableOfType\" | \"getModelOfType\" | \"classify\"\n>;\nexport interface CodemodeToolOptions {\n\tgetToolNamespace?: (name: string) => ToolNamespace | undefined;\n\tmodels?: boolean;\n\tappendEntry?: (type: string, data: CodemodeStoreEntryData) => void;\n\tgetMode?: () => CodemodeMode;\n\tgetInlineBudget?: () => number | undefined;\n}\nexport const codemodeSchema = Type.Object({\n\tcode: Type.String({\n\t\tdescription:\n\t\t\t'Raw JavaScript source with top-level await and return. Optional first line // @options: {\"max_output_tokens\": 1000, \"timeout_ms\": 60000}',\n\t}),\n});\nexport type CodemodeToolInput = Static<typeof codemodeSchema>;\nexport function isCodemodeTool(tool: Pick<ToolInfo, \"name\" | \"parameters\">): boolean {\n\treturn tool.name === CODEMODE_TOOL_NAME && tool.parameters === codemodeSchema;\n}\nexport interface CodemodeNestedCall {\n\tid: string;\n\tname: string;\n\targs: string;\n\tstatus: \"running\" | \"ok\" | \"error\" | \"cancelled\";\n\tdurationMs?: number;\n\terror?: string;\n\tcost?: number;\n}\nexport interface CodemodeToolDetails {\n\tcalls: CodemodeNestedCall[];\n\tfullOutputPath?: string;\n}\nexport function toCodemodeDeclaration(tool: AgentTool): Omit<CodemodeTool, \"execute\"> {\n\treturn {\n\t\tname: tool.name,\n\t\tdescription: tool.description,\n\t\tinputSchema: tool.parameters as CodemodeJsonSchema,\n\t\toutputSchema: (tool.outputSchema as CodemodeJsonSchema | undefined) ?? { type: \"string\" },\n\t};\n}\nexport function getCodemodeCallableTools(tools: readonly AgentTool[]): AgentTool[] {\n\treturn tools.filter((tool) => tool.name !== CODEMODE_TOOL_NAME);\n}\nexport interface CodemodeDescriptionOptions {\n\tmodels?: boolean;\n\tnamespaces?: ReadonlyMap<string, ToolNamespace>;\n\tdeferred?: ReadonlySet<string>;\n\tinlineBudget?: number;\n}\nconst INTRO = `Run JavaScript that composes tool calls in a fresh QuickJS worker sandbox.\nTop-level await and return work. Use tools.name(args), or tools[\"raw-name\"](args). Tool names normalize to JavaScript identifiers.\nNo Node, filesystem, network, timers, modules or credentials are available directly. Calls go through session validation and permission hooks. They have real side effects and are not undone after script failure.\nTools with output schemas resolve to structuredContent; others resolve to text. Failed or blocked calls throw. Scripts have a 256 MB memory limit.\nGlobals: ALL_TOOLS, text(value), image(base64DataUrlOrImageContent), exit(), console.log(...), store(key, value), load(key), searchTools(query, {limit?, namespace?}), describeTool(name), describeNamespace(name).\ndescribeNamespace(name) returns { name, description?, instructions?, tools } for a callable tool namespace, or undefined. Namespace instructions are available on request, not in tool listings.\nSuccessful scripts persist store writes on the current session branch; failed scripts discard writes. Unawaited calls are cancelled when the script ends.\nOptional first line: // @options: {\"max_output_tokens\": 1000, \"timeout_ms\": 60000}. Output defaults to 10000 tokens; there is no default deadline.`;\n\nexport function createCodemodeDescription(\n\ttools: readonly AgentTool[],\n\toptions: CodemodeDescriptionOptions = {},\n): string {\n\tconst groups = new Map<\n\t\tstring,\n\t\t{ namespace?: ToolNamespace; entries: { name: string; section: string; cost: number }[] }\n\t>();\n\tfor (const tool of getCodemodeCallableTools(tools)) {\n\t\tif (options.deferred?.has(tool.name)) continue;\n\t\tconst namespace = options.namespaces?.get(tool.name);\n\t\tconst key = namespace?.name ?? \"\";\n\t\tlet group = groups.get(key);\n\t\tif (!group) {\n\t\t\tgroup = { namespace, entries: [] };\n\t\t\tgroups.set(key, group);\n\t\t}\n\t\tconst id = toCodemodeIdentifier(tool.name);\n\t\tconst section = `### \\`${id}\\`${id === tool.name ? \"\" : ` (\\`${tool.name}\\`)`}\\n${renderToolSample(toCodemodeDeclaration(tool)).trim()}`;\n\t\tgroup.entries.push({\n\t\t\tname: tool.name,\n\t\t\tsection,\n\t\t\tcost: Math.ceil(section.length / 4),\n\t\t});\n\t}\n\tconst ordered = [...groups.values()].sort((a, b) =>\n\t\ta.namespace === undefined ? -1 : b.namespace === undefined ? 1 : a.namespace.name.localeCompare(b.namespace.name),\n\t);\n\tconst shown = new Set<string>();\n\tlet remaining = options.inlineBudget ?? Number.POSITIVE_INFINITY;\n\tlet queues = ordered\n\t\t.map((group) => [...group.entries].sort((a, b) => a.cost - b.cost))\n\t\t.filter((queue) => queue.length);\n\twhile (queues.length)\n\t\tqueues = queues.filter((queue) => {\n\t\t\tconst next = queue[0];\n\t\t\tif (next.cost > remaining) return false;\n\t\t\tremaining -= next.cost;\n\t\t\tshown.add(next.name);\n\t\t\tqueue.shift();\n\t\t\treturn queue.length > 0;\n\t\t});\n\tconst sections = [\n\t\tINTRO,\n\t\t\"Some nested tools may be omitted, including deferred tools. They remain available through tools and ALL_TOOLS. Use await searchTools(query), describeTool(name), or describeNamespace(name) to discover them.\",\n\t];\n\tif (options.models)\n\t\tsections.push(\n\t\t\t\"Model API: models.getModelsOfType(type, provider?), models.getAvailableOfType(type, provider?), models.getModelOfType(type, provider, id), models.classify(model, context). Types are chat, image, classifier. Catalog entries exclude headers; classifier calls resolve credentials on the host.\",\n\t\t);\n\tif (ordered.length === 0) return sections.join(\"\\n\\n\");\n\tsections.push(\"Nested tools:\");\n\tfor (const group of ordered) {\n\t\tif (group.namespace) {\n\t\t\tconst visible = group.entries.filter((entry) => shown.has(entry.name));\n\t\t\tconst listing =\n\t\t\t\tvisible.length === group.entries.length\n\t\t\t\t\t? \"\"\n\t\t\t\t\t: visible.length === 0\n\t\t\t\t\t\t? \" (tools not listed)\"\n\t\t\t\t\t\t: \" (some tools not listed)\";\n\t\t\tconst description = group.namespace.description?.trim();\n\t\t\tsections.push(`## ${group.namespace.name}${listing}${description ? `\\n${description}` : \"\"}`);\n\t\t}\n\t\tfor (const entry of group.entries) if (shown.has(entry.name)) sections.push(entry.section);\n\t}\n\treturn sections.join(\"\\n\\n\");\n}\nfunction prepareLoadout(loadout: ToolLoadout, options: CodemodeToolOptions) {\n\tconst only = options.getMode?.() === \"only\";\n\tconst callable = getCodemodeCallableTools(loadout.callable);\n\tconst descriptions: Record<string, string> = {};\n\tif (!only)\n\t\tfor (const tool of loadout.declared)\n\t\t\tif (callable.some((candidate) => candidate.name === tool.name))\n\t\t\t\tdescriptions[tool.name] = renderToolSample(toCodemodeDeclaration(tool));\n\tconst listed = only ? callable : callable.filter((tool) => loadout.getExposure(tool.name) !== \"direct\");\n\tconst namespaces = new Map(\n\t\tlisted.flatMap((tool) => {\n\t\t\tconst namespace = loadout.getNamespace(tool.name);\n\t\t\treturn namespace ? [[tool.name, namespace] as const] : [];\n\t\t}),\n\t);\n\tdescriptions[CODEMODE_TOOL_NAME] = createCodemodeDescription(listed, {\n\t\tmodels: options.models,\n\t\tnamespaces,\n\t\tdeferred: new Set(\n\t\t\tlisted.filter((tool) => loadout.getExposure(tool.name) === \"deferred\").map((tool) => tool.name),\n\t\t),\n\t\tinlineBudget: options.getInlineBudget?.() ?? DEFAULT_CODEMODE_INLINE_BUDGET,\n\t});\n\treturn {\n\t\tdescriptions,\n\t\thiddenDeclarations: only\n\t\t\t? callable.filter((tool) => loadout.getExposure(tool.name) === \"direct\").map((tool) => tool.name)\n\t\t\t: [],\n\t};\n}\nexport function createCodemodeToolDefinition(\n\toptions: CodemodeToolOptions = {},\n): ToolDefinition<typeof codemodeSchema, CodemodeToolDetails> {\n\treturn {\n\t\tname: CODEMODE_TOOL_NAME,\n\t\tlabel: CODEMODE_TOOL_NAME,\n\t\tdescription: createCodemodeDescription([], options),\n\t\tparameters: codemodeSchema,\n\t\texposure: \"model-only\",\n\t\tconcurrency: \"exclusive\",\n\t\tdefaultActive: false,\n\t\tpromptSnippet: \"Run JavaScript that calls other tools, filters results, or batches independent calls\",\n\t\tprepareLoadout: (loadout) => prepareLoadout(loadout, options),\n\t\tconstrainedSampling: { type: \"grammar\", variants: { openai_lark: CODEMODE_SOURCE_GRAMMAR } },\n\t\texecute: async (id, input, signal, update, ctx) =>\n\t\t\t(await import(\"./execute.js\")).executeCodemode(id, input, signal, update, ctx, options),\n\t\t...codemodeRenderers,\n\t};\n}\nexport function createCodemodeTool(\n\ttools: readonly AgentTool[] = [],\n\toptions: CodemodeToolOptions = {},\n): AgentTool<typeof codemodeSchema> {\n\treturn {\n\t\t...wrapToolDefinition(createCodemodeToolDefinition(options)),\n\t\tdescription: createCodemodeDescription(tools, options),\n\t};\n}\n"]}
@@ -36,6 +36,6 @@ export interface ToolSearchToolOptions {
36
36
  tools?: Pick<ExtensionAPI, "getAllTools" | "getActiveTools" | "setActiveTools">;
37
37
  }
38
38
  export declare function isToolSearchTool(tool: Pick<ToolInfo, "name" | "parameters">): boolean;
39
- export declare function createToolSearchDescription(sources?: readonly ToolNamespace[]): string;
39
+ export declare function createToolSearchDescription(_sources?: readonly ToolNamespace[]): string;
40
40
  export declare function createToolSearchToolDefinition(options?: ToolSearchToolOptions): ToolDefinition<typeof toolSearchSchema, ToolSearchToolDetails>;
41
41
  //# sourceMappingURL=tool.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../../src/extensions/tool-search/tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAE5G,eAAO,MAAM,qBAAqB,gBAAgB,CAAC;AACnD,eAAO,MAAM,yBAAyB,IAAI,CAAC;AAC3C,MAAM,WAAW,kBAAkB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACb;AACD,MAAM,WAAW,eAAe;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACd;AACD,MAAM,WAAW,UAAU;IAC1B,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,kBAAkB,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,eAAe,EAAE,CAAC;CAChG;AA8BD,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAQ/C;AAgBD,wBAAgB,wBAAwB,CACvC,IAAI,EAAE,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,aAAa,GAAG,YAAY,CAAC,EAC3D,SAAS,CAAC,EAAE,aAAa,GACvB,kBAAkB,CAKpB;AACD,qBAAa,UAAW,YAAW,UAAU;IAC5C,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAS;IAC5B,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAS;IAC3B,YAAY,OAAO,GAAE;QAAE,EAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,CAAC,EAAE,MAAM,CAAA;KAAO,EAGpD;IAC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;AACD,wBAAgB,8BAA8B,CAC7C,OAAO,GAAE,qBAA0B,GACjC,cAAc,CAAC,OAAO,gBAAgB,EAAE,qBAAqB,CAAC,CAsChE"}
@@ -65,7 +65,7 @@ export function createToolSearchDocument(tool, namespace) {
65
65
  const parts = [tool.name, tool.name.replaceAll("_", " "), tool.description];
66
66
  schemaText(tool.parameters, parts);
67
67
  if (namespace)
68
- parts.push(namespace.name, namespace.description ?? "");
68
+ parts.push(namespace.name, namespace.description ?? "", namespace.instructions ?? "");
69
69
  return { name: tool.name, text: parts.filter((part) => part.trim()).join(" ") };
70
70
  }
71
71
  export class Bm25Ranker {
@@ -111,8 +111,8 @@ export const toolSearchSchema = Type.Object({ query: Type.String(), limit: Type.
111
111
  export function isToolSearchTool(tool) {
112
112
  return tool.name === TOOL_SEARCH_TOOL_NAME && tool.parameters === toolSearchSchema;
113
113
  }
114
- export function createToolSearchDescription(sources = []) {
115
- return `Search deferred tool metadata with BM25 and load matching tools for the next model call.\nSources:\n${sources.length ? sources.map((source) => `- ${source.name}: ${source.description ?? ""}`).join("\n") : "None currently enabled."}`;
114
+ export function createToolSearchDescription(_sources = []) {
115
+ return "Search deferred tool metadata with BM25 and load matching tools for the next model call. Some tools may not have been provided upfront; use tool_search to discover currently registered tools.";
116
116
  }
117
117
  export function createToolSearchToolDefinition(options = {}) {
118
118
  return {
@@ -122,16 +122,6 @@ export function createToolSearchToolDefinition(options = {}) {
122
122
  parameters: toolSearchSchema,
123
123
  exposure: "model-only",
124
124
  defaultActive: false,
125
- prepareLoadout: (loadout) => {
126
- const sources = new Map();
127
- for (const tool of loadout.registered) {
128
- const exposure = loadout.getExposure(tool.name);
129
- const namespace = loadout.getNamespace(tool.name);
130
- if ((exposure === "codemode" || exposure === "deferred") && namespace)
131
- sources.set(namespace.name, namespace);
132
- }
133
- return { descriptions: { [TOOL_SEARCH_TOOL_NAME]: createToolSearchDescription([...sources.values()]) } };
134
- },
135
125
  execute: async (_id, { query, limit = DEFAULT_TOOL_SEARCH_LIMIT }) => {
136
126
  if (!query.trim())
137
127
  throw new Error("query must not be empty");
@@ -1 +1 @@
1
- {"version":3,"file":"tool.js","sourceRoot":"","sources":["../../../src/extensions/tool-search/tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAG5C,MAAM,CAAC,MAAM,qBAAqB,GAAG,aAAa,CAAC;AACnD,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC;AAY3C,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC;IAC1B,GAAG;IACH,IAAI;IACJ,KAAK;IACL,KAAK;IACL,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,KAAK;IACL,MAAM;IACN,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,MAAM;IACN,KAAK;IACL,MAAM;IACN,IAAI;IACJ,MAAM;CACN,CAAC,CAAC;AACH,SAAS,IAAI,CAAC,IAAY;IACzB,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;IAC5E,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,2BAA2B,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACxF,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC5F,OAAO,IAAI,CAAC;AACb,CAAC;AACD,MAAM,UAAU,QAAQ,CA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U,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,CAAC,EAAE,WAAW,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;4BACxK,CAAC,CAAC,0BAA0B;qBAC7B;iBACD;gBACD,OAAO,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;aACvD,CAAC;QACH,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import { type Static, Type } from \"typebox\";\nimport type { ExtensionAPI, ToolDefinition, ToolInfo, ToolNamespace } from \"../../core/extensions/types.ts\";\n\nexport const TOOL_SEARCH_TOOL_NAME = \"tool_search\";\nexport const DEFAULT_TOOL_SEARCH_LIMIT = 8;\nexport interface ToolSearchDocument {\n\tname: string;\n\ttext: string;\n}\nexport interface ToolSearchMatch {\n\tname: string;\n\tscore: number;\n}\nexport interface ToolRanker {\n\trank(query: string, documents: readonly ToolSearchDocument[], limit: number): ToolSearchMatch[];\n}\nconst STOP_WORDS = new Set([\n\t\"a\",\n\t\"an\",\n\t\"and\",\n\t\"are\",\n\t\"as\",\n\t\"at\",\n\t\"be\",\n\t\"by\",\n\t\"for\",\n\t\"from\",\n\t\"in\",\n\t\"is\",\n\t\"it\",\n\t\"of\",\n\t\"on\",\n\t\"or\",\n\t\"that\",\n\t\"the\",\n\t\"this\",\n\t\"to\",\n\t\"with\",\n]);\nfunction stem(term: string): string {\n\tif (term.length > 4 && term.endsWith(\"ies\")) return `${term.slice(0, -3)}y`;\n\tif (term.length > 4 && /(ches|shes|sses|xes|zes)$/.test(term)) return term.slice(0, -2);\n\tif (term.length > 3 && term.endsWith(\"s\") && !term.endsWith(\"ss\")) return term.slice(0, -1);\n\treturn term;\n}\nexport function tokenize(text: string): string[] {\n\treturn text\n\t\t.replace(/([a-z0-9])([A-Z])/g, \"$1 $2\")\n\t\t.replace(/([A-Z]+)([A-Z][a-z])/g, \"$1 $2\")\n\t\t.toLowerCase()\n\t\t.split(/[^a-z0-9]+/)\n\t\t.filter((term) => term.length > 0 && !STOP_WORDS.has(term))\n\t\t.map(stem);\n}\nfunction isObject(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\nfunction schemaText(schema: unknown, parts: string[]): void {\n\tif (!isObject(schema)) return;\n\tif (typeof schema.description === \"string\") parts.push(schema.description);\n\tif (isObject(schema.properties))\n\t\tfor (const [name, property] of Object.entries(schema.properties)) {\n\t\t\tparts.push(name);\n\t\t\tschemaText(property, parts);\n\t\t}\n\tschemaText(schema.items, parts);\n\tfor (const key of [\"anyOf\", \"oneOf\", \"allOf\"])\n\t\tif (Array.isArray(schema[key])) for (const variant of schema[key]) schemaText(variant, parts);\n}\nexport function createToolSearchDocument(\n\ttool: Pick<ToolInfo, \"name\" | \"description\" | \"parameters\">,\n\tnamespace?: ToolNamespace,\n): ToolSearchDocument {\n\tconst parts = [tool.name, tool.name.replaceAll(\"_\", \" \"), tool.description];\n\tschemaText(tool.parameters, parts);\n\tif (namespace) parts.push(namespace.name, namespace.description ?? \"\");\n\treturn { name: tool.name, text: parts.filter((part) => part.trim()).join(\" \") };\n}\nexport class Bm25Ranker implements ToolRanker {\n\tprivate readonly k1: number;\n\tprivate readonly b: number;\n\tconstructor(options: { k1?: number; b?: number } = {}) {\n\t\tthis.k1 = options.k1 ?? 1.2;\n\t\tthis.b = options.b ?? 0.75;\n\t}\n\trank(query: string, documents: readonly ToolSearchDocument[], limit: number): ToolSearchMatch[] {\n\t\tconst terms = [...new Set(tokenize(query))];\n\t\tif (!terms.length || !documents.length || limit <= 0) return [];\n\t\tconst counts = documents.map((document) => {\n\t\t\tconst result = new Map<string, number>();\n\t\t\tfor (const term of tokenize(document.text)) result.set(term, (result.get(term) ?? 0) + 1);\n\t\t\treturn result;\n\t\t});\n\t\tconst lengths = counts.map((count) => [...count.values()].reduce((sum, value) => sum + value, 0));\n\t\tconst average = lengths.reduce((sum, value) => sum + value, 0) / documents.length || 1;\n\t\tconst idf = new Map(\n\t\t\tterms.map((term) => {\n\t\t\t\tconst frequency = counts.filter((count) => count.has(term)).length;\n\t\t\t\treturn [term, Math.log(1 + (documents.length - frequency + 0.5) / (frequency + 0.5))];\n\t\t\t}),\n\t\t);\n\t\treturn documents\n\t\t\t.flatMap((document, index) => {\n\t\t\t\tlet score = 0;\n\t\t\t\tfor (const term of terms) {\n\t\t\t\t\tconst count = counts[index].get(term);\n\t\t\t\t\tif (!count) continue;\n\t\t\t\t\tconst norm = this.k1 * (1 - this.b + (this.b * lengths[index]) / average);\n\t\t\t\t\tscore += ((idf.get(term) ?? 0) * count * (this.k1 + 1)) / (count + norm);\n\t\t\t\t}\n\t\t\t\treturn score > 0 ? [{ name: document.name, score }] : [];\n\t\t\t})\n\t\t\t.sort((a, b) => b.score - a.score)\n\t\t\t.slice(0, limit);\n\t}\n}\nexport const toolSearchSchema = Type.Object({ query: Type.String(), limit: Type.Optional(Type.Number()) });\nexport type ToolSearchInput = Static<typeof toolSearchSchema>;\nexport interface ToolSearchToolDetails {\n\tloaded: string[];\n}\nexport interface ToolSearchToolOptions {\n\ttools?: Pick<ExtensionAPI, \"getAllTools\" | \"getActiveTools\" | \"setActiveTools\">;\n}\nexport function isToolSearchTool(tool: Pick<ToolInfo, \"name\" | \"parameters\">): boolean {\n\treturn tool.name === TOOL_SEARCH_TOOL_NAME && tool.parameters === toolSearchSchema;\n}\nexport function createToolSearchDescription(sources: readonly ToolNamespace[] = []): string {\n\treturn `Search deferred tool metadata with BM25 and load matching tools for the next model call.\\nSources:\\n${sources.length ? sources.map((source) => `- ${source.name}: ${source.description ?? \"\"}`).join(\"\\n\") : \"None currently enabled.\"}`;\n}\nexport function createToolSearchToolDefinition(\n\toptions: ToolSearchToolOptions = {},\n): ToolDefinition<typeof toolSearchSchema, ToolSearchToolDetails> {\n\treturn {\n\t\tname: TOOL_SEARCH_TOOL_NAME,\n\t\tlabel: TOOL_SEARCH_TOOL_NAME,\n\t\tdescription: createToolSearchDescription(),\n\t\tparameters: toolSearchSchema,\n\t\texposure: \"model-only\",\n\t\tdefaultActive: false,\n\t\tprepareLoadout: (loadout) => {\n\t\t\tconst sources = new Map<string, ToolNamespace>();\n\t\t\tfor (const tool of loadout.registered) {\n\t\t\t\tconst exposure = loadout.getExposure(tool.name);\n\t\t\t\tconst namespace = loadout.getNamespace(tool.name);\n\t\t\t\tif ((exposure === \"codemode\" || exposure === \"deferred\") && namespace)\n\t\t\t\t\tsources.set(namespace.name, namespace);\n\t\t\t}\n\t\t\treturn { descriptions: { [TOOL_SEARCH_TOOL_NAME]: createToolSearchDescription([...sources.values()]) } };\n\t\t},\n\t\texecute: async (_id, { query, limit = DEFAULT_TOOL_SEARCH_LIMIT }) => {\n\t\t\tif (!query.trim()) throw new Error(\"query must not be empty\");\n\t\t\tif (!Number.isInteger(limit) || limit <= 0) throw new Error(\"limit must be a positive integer\");\n\t\t\tconst active = options.tools?.getActiveTools() ?? [];\n\t\t\tconst candidates =\n\t\t\t\toptions.tools\n\t\t\t\t\t?.getAllTools()\n\t\t\t\t\t.filter(\n\t\t\t\t\t\t(tool) =>\n\t\t\t\t\t\t\t(tool.exposure === \"codemode\" || tool.exposure === \"deferred\") && !active.includes(tool.name),\n\t\t\t\t\t) ?? [];\n\t\t\tconst matches = new Bm25Ranker().rank(\n\t\t\t\tquery,\n\t\t\t\tcandidates.map((tool) => createToolSearchDocument(tool, tool.namespace)),\n\t\t\t\tlimit,\n\t\t\t);\n\t\t\tif (matches.length) options.tools?.setActiveTools([...active, ...matches.map((match) => match.name)]);\n\t\t\treturn {\n\t\t\t\tcontent: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\ttext: matches.length\n\t\t\t\t\t\t\t? `Loaded tools for your next call:\\n${matches.map((match) => `- ${match.name}: ${candidates.find((tool) => tool.name === match.name)?.description ?? \"\"}`).join(\"\\n\")}`\n\t\t\t\t\t\t\t: \"No matching tools found.\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdetails: { loaded: matches.map((match) => match.name) },\n\t\t\t};\n\t\t},\n\t};\n}\n"]}
1
+ {"version":3,"file":"tool.js","sourceRoot":"","sources":["../../../src/extensions/tool-search/tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAG5C,MAAM,CAAC,MAAM,qBAAqB,GAAG,aAAa,CAAC;AACnD,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC;AAY3C,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC;IAC1B,GAAG;IACH,IAAI;IACJ,KAAK;IACL,KAAK;IACL,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,KAAK;IACL,MAAM;IACN,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,MAAM;IACN,KAAK;IACL,MAAM;IACN,IAAI;IACJ,MAAM;CACN,CAAC,CAAC;AACH,SAAS,IAAI,CAAC,IAAY;IACzB,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;IAC5E,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,2BAA2B,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACxF,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC,KAAK,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,IAAI,EAAE,EAAE,CAAC,wBAAwB,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,EACxE,KAAK,CACL,CAAC;YACF,IAAI,OAAO,CAAC,MAAM;gBAAE,OAAO,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YACtG,OAAO;gBACN,OAAO,EAAE;oBACR;wBACC,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,OAAO,CAAC,MAAM;4BACnB,CAAC,CAAC,qCAAqC,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,CAAC,IAAI,KAAK,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,CAAC,EAAE,WAAW,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;4BACxK,CAAC,CAAC,0BAA0B;qBAC7B;iBACD;gBACD,OAAO,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;aACvD,CAAC;QACH,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import { type Static, Type } from \"typebox\";\nimport type { ExtensionAPI, ToolDefinition, ToolInfo, ToolNamespace } from \"../../core/extensions/types.ts\";\n\nexport const TOOL_SEARCH_TOOL_NAME = \"tool_search\";\nexport const DEFAULT_TOOL_SEARCH_LIMIT = 8;\nexport interface ToolSearchDocument {\n\tname: string;\n\ttext: string;\n}\nexport interface ToolSearchMatch {\n\tname: string;\n\tscore: number;\n}\nexport interface ToolRanker {\n\trank(query: string, documents: readonly ToolSearchDocument[], limit: number): ToolSearchMatch[];\n}\nconst STOP_WORDS = new Set([\n\t\"a\",\n\t\"an\",\n\t\"and\",\n\t\"are\",\n\t\"as\",\n\t\"at\",\n\t\"be\",\n\t\"by\",\n\t\"for\",\n\t\"from\",\n\t\"in\",\n\t\"is\",\n\t\"it\",\n\t\"of\",\n\t\"on\",\n\t\"or\",\n\t\"that\",\n\t\"the\",\n\t\"this\",\n\t\"to\",\n\t\"with\",\n]);\nfunction stem(term: string): string {\n\tif (term.length > 4 && term.endsWith(\"ies\")) return `${term.slice(0, -3)}y`;\n\tif (term.length > 4 && /(ches|shes|sses|xes|zes)$/.test(term)) return term.slice(0, -2);\n\tif (term.length > 3 && term.endsWith(\"s\") && !term.endsWith(\"ss\")) return term.slice(0, -1);\n\treturn term;\n}\nexport function tokenize(text: string): string[] {\n\treturn text\n\t\t.replace(/([a-z0-9])([A-Z])/g, \"$1 $2\")\n\t\t.replace(/([A-Z]+)([A-Z][a-z])/g, \"$1 $2\")\n\t\t.toLowerCase()\n\t\t.split(/[^a-z0-9]+/)\n\t\t.filter((term) => term.length > 0 && !STOP_WORDS.has(term))\n\t\t.map(stem);\n}\nfunction isObject(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\nfunction schemaText(schema: unknown, parts: string[]): void {\n\tif (!isObject(schema)) return;\n\tif (typeof schema.description === \"string\") parts.push(schema.description);\n\tif (isObject(schema.properties))\n\t\tfor (const [name, property] of Object.entries(schema.properties)) {\n\t\t\tparts.push(name);\n\t\t\tschemaText(property, parts);\n\t\t}\n\tschemaText(schema.items, parts);\n\tfor (const key of [\"anyOf\", \"oneOf\", \"allOf\"])\n\t\tif (Array.isArray(schema[key])) for (const variant of schema[key]) schemaText(variant, parts);\n}\nexport function createToolSearchDocument(\n\ttool: Pick<ToolInfo, \"name\" | \"description\" | \"parameters\">,\n\tnamespace?: ToolNamespace,\n): ToolSearchDocument {\n\tconst parts = [tool.name, tool.name.replaceAll(\"_\", \" \"), tool.description];\n\tschemaText(tool.parameters, parts);\n\tif (namespace) parts.push(namespace.name, namespace.description ?? \"\", namespace.instructions ?? \"\");\n\treturn { name: tool.name, text: parts.filter((part) => part.trim()).join(\" \") };\n}\nexport class Bm25Ranker implements ToolRanker {\n\tprivate readonly k1: number;\n\tprivate readonly b: number;\n\tconstructor(options: { k1?: number; b?: number } = {}) {\n\t\tthis.k1 = options.k1 ?? 1.2;\n\t\tthis.b = options.b ?? 0.75;\n\t}\n\trank(query: string, documents: readonly ToolSearchDocument[], limit: number): ToolSearchMatch[] {\n\t\tconst terms = [...new Set(tokenize(query))];\n\t\tif (!terms.length || !documents.length || limit <= 0) return [];\n\t\tconst counts = documents.map((document) => {\n\t\t\tconst result = new Map<string, number>();\n\t\t\tfor (const term of tokenize(document.text)) result.set(term, (result.get(term) ?? 0) + 1);\n\t\t\treturn result;\n\t\t});\n\t\tconst lengths = counts.map((count) => [...count.values()].reduce((sum, value) => sum + value, 0));\n\t\tconst average = lengths.reduce((sum, value) => sum + value, 0) / documents.length || 1;\n\t\tconst idf = new Map(\n\t\t\tterms.map((term) => {\n\t\t\t\tconst frequency = counts.filter((count) => count.has(term)).length;\n\t\t\t\treturn [term, Math.log(1 + (documents.length - frequency + 0.5) / (frequency + 0.5))];\n\t\t\t}),\n\t\t);\n\t\treturn documents\n\t\t\t.flatMap((document, index) => {\n\t\t\t\tlet score = 0;\n\t\t\t\tfor (const term of terms) {\n\t\t\t\t\tconst count = counts[index].get(term);\n\t\t\t\t\tif (!count) continue;\n\t\t\t\t\tconst norm = this.k1 * (1 - this.b + (this.b * lengths[index]) / average);\n\t\t\t\t\tscore += ((idf.get(term) ?? 0) * count * (this.k1 + 1)) / (count + norm);\n\t\t\t\t}\n\t\t\t\treturn score > 0 ? [{ name: document.name, score }] : [];\n\t\t\t})\n\t\t\t.sort((a, b) => b.score - a.score)\n\t\t\t.slice(0, limit);\n\t}\n}\nexport const toolSearchSchema = Type.Object({ query: Type.String(), limit: Type.Optional(Type.Number()) });\nexport type ToolSearchInput = Static<typeof toolSearchSchema>;\nexport interface ToolSearchToolDetails {\n\tloaded: string[];\n}\nexport interface ToolSearchToolOptions {\n\ttools?: Pick<ExtensionAPI, \"getAllTools\" | \"getActiveTools\" | \"setActiveTools\">;\n}\nexport function isToolSearchTool(tool: Pick<ToolInfo, \"name\" | \"parameters\">): boolean {\n\treturn tool.name === TOOL_SEARCH_TOOL_NAME && tool.parameters === toolSearchSchema;\n}\nexport function createToolSearchDescription(_sources: readonly ToolNamespace[] = []): string {\n\treturn \"Search deferred tool metadata with BM25 and load matching tools for the next model call. Some tools may not have been provided upfront; use tool_search to discover currently registered tools.\";\n}\nexport function createToolSearchToolDefinition(\n\toptions: ToolSearchToolOptions = {},\n): ToolDefinition<typeof toolSearchSchema, ToolSearchToolDetails> {\n\treturn {\n\t\tname: TOOL_SEARCH_TOOL_NAME,\n\t\tlabel: TOOL_SEARCH_TOOL_NAME,\n\t\tdescription: createToolSearchDescription(),\n\t\tparameters: toolSearchSchema,\n\t\texposure: \"model-only\",\n\t\tdefaultActive: false,\n\t\texecute: async (_id, { query, limit = DEFAULT_TOOL_SEARCH_LIMIT }) => {\n\t\t\tif (!query.trim()) throw new Error(\"query must not be empty\");\n\t\t\tif (!Number.isInteger(limit) || limit <= 0) throw new Error(\"limit must be a positive integer\");\n\t\t\tconst active = options.tools?.getActiveTools() ?? [];\n\t\t\tconst candidates =\n\t\t\t\toptions.tools\n\t\t\t\t\t?.getAllTools()\n\t\t\t\t\t.filter(\n\t\t\t\t\t\t(tool) =>\n\t\t\t\t\t\t\t(tool.exposure === \"codemode\" || tool.exposure === \"deferred\") && !active.includes(tool.name),\n\t\t\t\t\t) ?? [];\n\t\t\tconst matches = new Bm25Ranker().rank(\n\t\t\t\tquery,\n\t\t\t\tcandidates.map((tool) => createToolSearchDocument(tool, tool.namespace)),\n\t\t\t\tlimit,\n\t\t\t);\n\t\t\tif (matches.length) options.tools?.setActiveTools([...active, ...matches.map((match) => match.name)]);\n\t\t\treturn {\n\t\t\t\tcontent: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\ttext: matches.length\n\t\t\t\t\t\t\t? `Loaded tools for your next call:\\n${matches.map((match) => `- ${match.name}: ${candidates.find((tool) => tool.name === match.name)?.description ?? \"\"}`).join(\"\\n\")}`\n\t\t\t\t\t\t\t: \"No matching tools found.\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdetails: { loaded: matches.map((match) => match.name) },\n\t\t\t};\n\t\t},\n\t};\n}\n"]}
@@ -1,4 +1,5 @@
1
1
  export type { AfterProviderResponseEvent, AgentActivityOutcome, AgentBeforeSettleEvent, AgentBeforeSettleEventResult, AgentEndEvent, AgentSettledEvent, AgentStartEvent, AgentToolResult, AgentToolUpdateCallback, AppKeybinding, AtomicProviderCompat, AutocompleteProviderFactory, BashToolCallEvent, BeforeAgentStartEvent, BeforeAgentStartEventResult, BeforeProviderHeadersEvent, BeforeProviderRequestEvent, BeforeProviderRequestEventResult, BoundaryContextPreview, BoundaryResult, BoundaryState, BuildSystemPromptOptions, CompactionEntryDraft, CompactOptions, ConstrainedSamplingConfig, ContextEditEntryDraft, ContextEvent, ContextEventResult, ContextUsage, ContextWithSystemEvent, CustomEntryDraft, CustomMessageEntryDraft, CustomToolCallEvent, EditToolCallEvent, EntryRenderer, EntryRenderOptions, ExecOptions, ExecResult, Extension, ExtensionActions, ExtensionAPI, ExtensionCommandContext, ExtensionCommandContextActions, ExtensionContext, ExtensionContextActions, ExtensionCustomComponent, ExtensionError, ExtensionEvent, ExtensionFactory, ExtensionFlag, ExtensionHandler, ExtensionRuntime, ExtensionScopedModels, ExtensionShortcut, ExtensionUIContext, ExtensionUIDialogOptions, ExtensionWidgetOptions, FindToolCallEvent, HostInputFormField, HostInputFormFieldType, HostInputFormRequest, HostSessionPickerHandle, HostSessionPickerRequest, HostSessionPickerRow, InlineExtension, InputEvent, InputEventResult, InputSource, InstallReactiveWidgetOptions, KeybindingsManager, LoadExtensionsResult, LsToolCallEvent, MarkdownTransformContext, MarkdownTransformer, MessageEndEventResult, MessageRenderer, MessageRenderOptions, ModelSelectEvent, ModelSelectSource, OrchestrationContext, PowerShellToolCallEvent, ProjectTrustContext, ProjectTrustEvent, ProjectTrustEventDecision, ProjectTrustEventResult, ProjectTrustHandler, ProviderConfig, ProviderModelConfig, ProviderStreamEvent, ReactiveWidgetAction, ReactiveWidgetComponent, ReactiveWidgetController, ReactiveWidgetFactory, ReactiveWidgetRefreshReason, ReactiveWidgetRenderContext, ReactiveWidgetRenderState, ReactiveWidgetScheduler, ReactiveWidgetTimerApi, ReactiveWidgetTimerHandle, ReactiveWidgetUi, ReadToolCallEvent, RegisteredCommand, RegisteredTool, ResolvedCommand, ResourcesDiscoverEvent, ResourcesDiscoverResult, ScopedModel, ScrollableWidgetComponent, SessionBeforeCompactEvent, SessionBeforeCompactResult, SessionBeforeForkEvent, SessionBeforeForkResult, SessionBeforeSwitchEvent, SessionBeforeSwitchResult, SessionBeforeTreeEvent, SessionBeforeTreeResult, SessionBoundaryDraft, SessionCompactEvent, SessionCompactFailedEvent, SessionInfoChangedEvent, SessionShutdownEvent, SessionStartEvent, SessionTreeEvent, SlashCommandInfo, SlashCommandSource, SourceInfo, SubagentChildPolicy, SubagentIntercomIdentity, TerminalInputHandler, ThinkingLevelSelectEvent, ToolCallEvent, ToolCallEventResult, ToolDefinition, ToolExecutionEndEvent, ToolExecutionMode, ToolExecutionStartEvent, ToolInfo, ToolRenderResultOptions, ToolResultEvent, ToolResultEventResult, TurnEndEvent, TurnEndEventResult, TurnStartEvent, UIPromptEndEvent, UIPromptKind, UIPromptStartEvent, UserBashEvent, UserBashEventResult, WidgetPlacement, WidgetScrollRequest, WidgetScrollState, WorkflowPendingStageDelivery, WorkflowStageOrchestrationContext, WorkingIndicatorOptions, WriteToolCallEvent, } from "./core/extensions/index.js";
2
- export { createExtensionRuntime, decideReactiveWidgetAction, defineTool, discoverAndLoadExtensions, ExtensionRunner, installReactiveWidget, isBashToolResult, isEditToolResult, isFindToolResult, isLsToolResult, isPowerShellToolResult, isReadToolResult, isStaleExtensionContextError, isToolCallEventType, isWriteToolResult, OVERLAY_ACTIVE_ROW_MARKER, STALE_EXTENSION_CONTEXT_MARKER, wrapRegisteredTool, wrapRegisteredTools, } from "./core/extensions/index.js";
2
+ export { createExtensionRuntime, decideReactiveWidgetAction, defineTool, discoverAndLoadExtensions, ExtensionRunner, installReactiveWidget, isBashToolResult, isEditToolResult, isFindToolResult, isLsToolResult, isPowerShellToolResult, isReadToolResult, isStaleExtensionContextError, isToolCallEventType, isWriteToolResult, OVERLAY_ACTIVE_ROW_MARKER, STALE_EXTENSION_CONTEXT_MARKER, WorkflowRunControlError, WorkflowRunControlUnavailableError, WorkflowRunDatabaseError, WorkflowRunNotFoundError, WorkflowRunNotResumableError, WorkflowRunOwnershipError, WorkflowStageAmbiguousError, WorkflowStageNotFoundError, WorkflowStageResumeUnsupportedError, wrapRegisteredTool, wrapRegisteredTools, } from "./core/extensions/index.js";
3
3
  export type * from "./core/extensions/workflow-events.js";
4
+ export type * from "./core/extensions/workflow-run-control.js";
4
5
  //# sourceMappingURL=index-extensions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index-extensions.d.ts","sourceRoot":"","sources":["../src/index-extensions.ts"],"names":[],"mappings":"AACA,YAAY,EACX,0BAA0B,EAC1B,oBAAoB,EACpB,sBAAsB,EACtB,4BAA4B,EAC5B,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,uBAAuB,EACvB,aAAa,EACb,oBAAoB,EACpB,2BAA2B,EAC3B,iBAAiB,EACjB,qBAAqB,EACrB,2BAA2B,EAC3B,0BAA0B,EAC1B,0BAA0B,EAC1B,gCAAgC,EAChC,sBAAsB,EACtB,cAAc,EACd,aAAa,EACb,wBAAwB,EACxB,oBAAoB,EACpB,cAAc,EACd,yBAAyB,EACzB,qBAAqB,EACrB,YAAY,EACZ,kBAAkB,EAClB,YAAY,EACZ,sBAAs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,EACzB,uBAAuB,EACvB,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,UAAU,EACV,mBAAmB,EACnB,wBAAwB,EACxB,oBAAoB,EACpB,wBAAwB,EACxB,aAAa,EACb,mBAAmB,EACnB,cAAc,EACd,qBAAqB,EACrB,iBAAiB,EACjB,uBAAuB,EACvB,QAAQ,EACR,uBAAuB,EACvB,eAAe,EACf,qBAAqB,EACrB,YAAY,EACZ,kBAAkB,EAClB,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,kBAAkB,EAClB,aAAa,EACb,mBAAmB,EACnB,eAAe,EACf,mBAAmB,EACnB,iBAAiB,EACjB,4BAA4B,EAC5B,iCAAiC,EACjC,uBAAuB,EACvB,kBAAkB,GAClB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACN,sBAAsB,EACtB,0BAA0B,EAC1B,UAAU,EACV,yBAAyB,EACzB,eAAe,EACf,qBAAqB,EACrB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,sBAAsB,EACtB,gBAAgB,EAChB,4BAA4B,EAC5B,mBAAmB,EACnB,iBAAiB,EACjB,yBAAyB,EACzB,8BAA8B,EAC9B,kBAAkB,EAClB,mBAAmB,GACnB,MAAM,4BAA4B,CAAC;AACpC,mBAAmB,sCAAsC,CAAC"}
1
+ {"version":3,"file":"index-extensions.d.ts","sourceRoot":"","sources":["../src/index-extensions.ts"],"names":[],"mappings":"AACA,YAAY,EACX,0BAA0B,EAC1B,oBAAoB,EACpB,sBAAsB,EACtB,4BAA4B,EAC5B,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,uBAAuB,EACvB,aAAa,EACb,oBAAoB,EACpB,2BAA2B,EAC3B,iBAAiB,EACjB,qBAAqB,EACrB,2BAA2B,EAC3B,0BAA0B,EAC1B,0BAA0B,EAC1B,gCAAgC,EAChC,sBAAsB,EACtB,cAAc,EACd,aAAa,EACb,w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tB,uBAAuB,EACvB,wBAAwB,EACxB,yBAAyB,EACzB,sBAAsB,EACtB,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,yBAAyB,EACzB,uBAAuB,EACvB,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,UAAU,EACV,mBAAmB,EACnB,wBAAwB,EACxB,oBAAoB,EACpB,wBAAwB,EACxB,aAAa,EACb,mBAAmB,EACnB,cAAc,EACd,qBAAqB,EACrB,iBAAiB,EACjB,uBAAuB,EACvB,QAAQ,EACR,uBAAuB,EACvB,eAAe,EACf,qBAAqB,EACrB,YAAY,EACZ,kBAAkB,EAClB,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,kBAAkB,EAClB,aAAa,EACb,mBAAmB,EACnB,eAAe,EACf,mBAAmB,EACnB,iBAAiB,EACjB,4BAA4B,EAC5B,iCAAiC,EACjC,uBAAuB,EACvB,kBAAkB,GAClB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACN,sBAAsB,EACtB,0BAA0B,EAC1B,UAAU,EACV,yBAAyB,EACzB,eAAe,EACf,qBAAqB,EACrB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,sBAAsB,EACtB,gBAAgB,EAChB,4BAA4B,EAC5B,mBAAmB,EACnB,iBAAiB,EACjB,yBAAyB,EACzB,8BAA8B,EAC9B,uBAAuB,EACvB,kCAAkC,EAClC,wBAAwB,EACxB,wBAAwB,EACxB,4BAA4B,EAC5B,yBAAyB,EACzB,2BAA2B,EAC3B,0BAA0B,EAC1B,mCAAmC,EACnC,kBAAkB,EAClB,mBAAmB,GACnB,MAAM,4BAA4B,CAAC;AACpC,mBAAmB,sCAAsC,CAAC;AAC1D,mBAAmB,2CAA2C,CAAC"}
@@ -1,2 +1,2 @@
1
- export { createExtensionRuntime, decideReactiveWidgetAction, defineTool, discoverAndLoadExtensions, ExtensionRunner, installReactiveWidget, isBashToolResult, isEditToolResult, isFindToolResult, isLsToolResult, isPowerShellToolResult, isReadToolResult, isStaleExtensionContextError, isToolCallEventType, isWriteToolResult, OVERLAY_ACTIVE_ROW_MARKER, STALE_EXTENSION_CONTEXT_MARKER, wrapRegisteredTool, wrapRegisteredTools, } from "./core/extensions/index.js";
1
+ export { createExtensionRuntime, decideReactiveWidgetAction, defineTool, discoverAndLoadExtensions, ExtensionRunner, installReactiveWidget, isBashToolResult, isEditToolResult, isFindToolResult, isLsToolResult, isPowerShellToolResult, isReadToolResult, isStaleExtensionContextError, isToolCallEventType, isWriteToolResult, OVERLAY_ACTIVE_ROW_MARKER, STALE_EXTENSION_CONTEXT_MARKER, WorkflowRunControlError, WorkflowRunControlUnavailableError, WorkflowRunDatabaseError, WorkflowRunNotFoundError, WorkflowRunNotResumableError, WorkflowRunOwnershipError, WorkflowStageAmbiguousError, WorkflowStageNotFoundError, WorkflowStageResumeUnsupportedError, wrapRegisteredTool, wrapRegisteredTools, } from "./core/extensions/index.js";
2
2
  //# sourceMappingURL=index-extensions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index-extensions.js","sourceRoot":"","sources":["../src/index-extensions.ts"],"names":[],"mappings":"AA8JA,OAAO,EACN,sBAAsB,EACtB,0BAA0B,EAC1B,UAAU,EACV,yBAAyB,EACzB,eAAe,EACf,qBAAqB,EACrB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,sBAAsB,EACtB,gBAAgB,EAChB,4BAA4B,EAC5B,mBAAmB,EACnB,iBAAiB,EACjB,yBAAyB,EACzB,8BAA8B,EAC9B,kBAAkB,EAClB,mBAAmB,GACnB,MAAM,4BAA4B,CAAC","sourcesContent":["// Extension system\nexport type {\n\tAfterProviderResponseEvent,\n\tAgentActivityOutcome,\n\tAgentBeforeSettleEvent,\n\tAgentBeforeSettleEventResult,\n\tAgentEndEvent,\n\tAgentSettledEvent,\n\tAgentStartEvent,\n\tAgentToolResult,\n\tAgentToolUpdateCallback,\n\tAppKeybinding,\n\tAtomicProviderCompat,\n\tAutocompleteProviderFactory,\n\tBashToolCallEvent,\n\tBeforeAgentStartEvent,\n\tBeforeAgentStartEventResult,\n\tBeforeProviderHeadersEvent,\n\tBeforeProviderRequestEvent,\n\tBeforeProviderRequestEventResult,\n\tBoundaryContextPreview,\n\tBoundaryResult,\n\tBoundaryState,\n\tBuildSystemPromptOptions,\n\tCompactionEntryDraft,\n\tCompactOptions,\n\tConstrainedSamplingConfig,\n\tContextEditEntryDraft,\n\tContextEvent,\n\tContextEventResult,\n\tContextUsage,\n\tContextWithSystemEvent,\n\tCustomEntryDraft,\n\tCustomMessageEntryDraft,\n\tCustomToolCallEvent,\n\tEditToolCallEvent,\n\tEntryRenderer,\n\tEntryRenderOptions,\n\tExecOptions,\n\tExecResult,\n\tExtension,\n\tExtensionActions,\n\tExtensionAPI,\n\tExtensionCommandContext,\n\tExtensionCommandContextActions,\n\tExtensionContext,\n\tExtensionContextActions,\n\tExtensionCustomComponent,\n\tExtensionError,\n\tExtensionEvent,\n\tExtensionFactory,\n\tExtensionFlag,\n\tExtensionHandler,\n\tExtensionRuntime,\n\tExtensionScopedModels,\n\tExtensionShortcut,\n\tExtensionUIContext,\n\tExtensionUIDialogOptions,\n\tExtensionWidgetOptions,\n\tFindToolCallEvent,\n\tHostInputFormField,\n\tHostInputFormFieldType,\n\tHostInputFormRequest,\n\tHostSessionPickerHandle,\n\tHostSessionPickerRequest,\n\tHostSessionPickerRow,\n\tInlineExtension,\n\tInputEvent,\n\tInputEventResult,\n\tInputSource,\n\tInstallReactiveWidgetOptions,\n\tKeybindingsManager,\n\tLoadExtensionsResult,\n\tLsToolCallEvent,\n\tMarkdownTransformContext,\n\tMarkdownTransformer,\n\tMessageEndEventResult,\n\tMessageRenderer,\n\tMessageRenderOptions,\n\tModelSelectEvent,\n\tModelSelectSource,\n\tOrchestrationContext,\n\tPowerShellToolCallEvent,\n\tProjectTrustContext,\n\tProjectTrustEvent,\n\tProjectTrustEventDecision,\n\tProjectTrustEventResult,\n\tProjectTrustHandler,\n\tProviderConfig,\n\tProviderModelConfig,\n\tProviderStreamEvent,\n\tReactiveWidgetAction,\n\tReactiveWidgetComponent,\n\tReactiveWidgetController,\n\tReactiveWidgetFactory,\n\tReactiveWidgetRefreshReason,\n\tReactiveWidgetRenderContext,\n\tReactiveWidgetRenderState,\n\tReactiveWidgetScheduler,\n\tReactiveWidgetTimerApi,\n\tReactiveWidgetTimerHandle,\n\tReactiveWidgetUi,\n\tReadToolCallEvent,\n\tRegisteredCommand,\n\tRegisteredTool,\n\tResolvedCommand,\n\tResourcesDiscoverEvent,\n\tResourcesDiscoverResult,\n\tScopedModel,\n\tScrollableWidgetComponent,\n\tSessionBeforeCompactEvent,\n\tSessionBeforeCompactResult,\n\tSessionBeforeForkEvent,\n\tSessionBeforeForkResult,\n\tSessionBeforeSwitchEvent,\n\tSessionBeforeSwitchResult,\n\tSessionBeforeTreeEvent,\n\tSessionBeforeTreeResult,\n\tSessionBoundaryDraft,\n\tSessionCompactEvent,\n\tSessionCompactFailedEvent,\n\tSessionInfoChangedEvent,\n\tSessionShutdownEvent,\n\tSessionStartEvent,\n\tSessionTreeEvent,\n\tSlashCommandInfo,\n\tSlashCommandSource,\n\tSourceInfo,\n\tSubagentChildPolicy,\n\tSubagentIntercomIdentity,\n\tTerminalInputHandler,\n\tThinkingLevelSelectEvent,\n\tToolCallEvent,\n\tToolCallEventResult,\n\tToolDefinition,\n\tToolExecutionEndEvent,\n\tToolExecutionMode,\n\tToolExecutionStartEvent,\n\tToolInfo,\n\tToolRenderResultOptions,\n\tToolResultEvent,\n\tToolResultEventResult,\n\tTurnEndEvent,\n\tTurnEndEventResult,\n\tTurnStartEvent,\n\tUIPromptEndEvent,\n\tUIPromptKind,\n\tUIPromptStartEvent,\n\tUserBashEvent,\n\tUserBashEventResult,\n\tWidgetPlacement,\n\tWidgetScrollRequest,\n\tWidgetScrollState,\n\tWorkflowPendingStageDelivery,\n\tWorkflowStageOrchestrationContext,\n\tWorkingIndicatorOptions,\n\tWriteToolCallEvent,\n} from \"./core/extensions/index.js\";\nexport {\n\tcreateExtensionRuntime,\n\tdecideReactiveWidgetAction,\n\tdefineTool,\n\tdiscoverAndLoadExtensions,\n\tExtensionRunner,\n\tinstallReactiveWidget,\n\tisBashToolResult,\n\tisEditToolResult,\n\tisFindToolResult,\n\tisLsToolResult,\n\tisPowerShellToolResult,\n\tisReadToolResult,\n\tisStaleExtensionContextError,\n\tisToolCallEventType,\n\tisWriteToolResult,\n\tOVERLAY_ACTIVE_ROW_MARKER,\n\tSTALE_EXTENSION_CONTEXT_MARKER,\n\twrapRegisteredTool,\n\twrapRegisteredTools,\n} from \"./core/extensions/index.js\";\nexport type * from \"./core/extensions/workflow-events.js\";\n"]}
1
+ {"version":3,"file":"index-extensions.js","sourceRoot":"","sources":["../src/index-extensions.ts"],"names":[],"mappings":"AA8JA,OAAO,EACN,sBAAsB,EACtB,0BAA0B,EAC1B,UAAU,EACV,yBAAyB,EACzB,eAAe,EACf,qBAAqB,EACrB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,sBAAsB,EACtB,gBAAgB,EAChB,4BAA4B,EAC5B,mBAAmB,EACnB,iBAAiB,EACjB,yBAAyB,EACzB,8BAA8B,EAC9B,uBAAuB,EACvB,kCAAkC,EAClC,wBAAwB,EACxB,wBAAwB,EACxB,4BAA4B,EAC5B,yBAAyB,EACzB,2BAA2B,EAC3B,0BAA0B,EAC1B,mCAAmC,EACnC,kBAAkB,EAClB,mBAAmB,GACnB,MAAM,4BAA4B,CAAC","sourcesContent":["// Extension system\nexport type {\n\tAfterProviderResponseEvent,\n\tAgentActivityOutcome,\n\tAgentBeforeSettleEvent,\n\tAgentBeforeSettleEventResult,\n\tAgentEndEvent,\n\tAgentSettledEvent,\n\tAgentStartEvent,\n\tAgentToolResult,\n\tAgentToolUpdateCallback,\n\tAppKeybinding,\n\tAtomicProviderCompat,\n\tAutocompleteProviderFactory,\n\tBashToolCallEvent,\n\tBeforeAgentStartEvent,\n\tBeforeAgentStartEventResult,\n\tBeforeProviderHeadersEvent,\n\tBeforeProviderRequestEvent,\n\tBeforeProviderRequestEventResult,\n\tBoundaryContextPreview,\n\tBoundaryResult,\n\tBoundaryState,\n\tBuildSystemPromptOptions,\n\tCompactionEntryDraft,\n\tCompactOptions,\n\tConstrainedSamplingConfig,\n\tContextEditEntryDraft,\n\tContextEvent,\n\tContextEventResult,\n\tContextUsage,\n\tContextWithSystemEvent,\n\tCustomEntryDraft,\n\tCustomMessageEntryDraft,\n\tCustomToolCallEvent,\n\tEditToolCallEvent,\n\tEntryRenderer,\n\tEntryRenderOptions,\n\tExecOptions,\n\tExecResult,\n\tExtension,\n\tExtensionActions,\n\tExtensionAPI,\n\tExtensionCommandContext,\n\tExtensionCommandContextActions,\n\tExtensionContext,\n\tExtensionContextActions,\n\tExtensionCustomComponent,\n\tExtensionError,\n\tExtensionEvent,\n\tExtensionFactory,\n\tExtensionFlag,\n\tExtensionHandler,\n\tExtensionRuntime,\n\tExtensionScopedModels,\n\tExtensionShortcut,\n\tExtensionUIContext,\n\tExtensionUIDialogOptions,\n\tExtensionWidgetOptions,\n\tFindToolCallEvent,\n\tHostInputFormField,\n\tHostInputFormFieldType,\n\tHostInputFormRequest,\n\tHostSessionPickerHandle,\n\tHostSessionPickerRequest,\n\tHostSessionPickerRow,\n\tInlineExtension,\n\tInputEvent,\n\tInputEventResult,\n\tInputSource,\n\tInstallReactiveWidgetOptions,\n\tKeybindingsManager,\n\tLoadExtensionsResult,\n\tLsToolCallEvent,\n\tMarkdownTransformContext,\n\tMarkdownTransformer,\n\tMessageEndEventResult,\n\tMessageRenderer,\n\tMessageRenderOptions,\n\tModelSelectEvent,\n\tModelSelectSource,\n\tOrchestrationContext,\n\tPowerShellToolCallEvent,\n\tProjectTrustContext,\n\tProjectTrustEvent,\n\tProjectTrustEventDecision,\n\tProjectTrustEventResult,\n\tProjectTrustHandler,\n\tProviderConfig,\n\tProviderModelConfig,\n\tProviderStreamEvent,\n\tReactiveWidgetAction,\n\tReactiveWidgetComponent,\n\tReactiveWidgetController,\n\tReactiveWidgetFactory,\n\tReactiveWidgetRefreshReason,\n\tReactiveWidgetRenderContext,\n\tReactiveWidgetRenderState,\n\tReactiveWidgetScheduler,\n\tReactiveWidgetTimerApi,\n\tReactiveWidgetTimerHandle,\n\tReactiveWidgetUi,\n\tReadToolCallEvent,\n\tRegisteredCommand,\n\tRegisteredTool,\n\tResolvedCommand,\n\tResourcesDiscoverEvent,\n\tResourcesDiscoverResult,\n\tScopedModel,\n\tScrollableWidgetComponent,\n\tSessionBeforeCompactEvent,\n\tSessionBeforeCompactResult,\n\tSessionBeforeForkEvent,\n\tSessionBeforeForkResult,\n\tSessionBeforeSwitchEvent,\n\tSessionBeforeSwitchResult,\n\tSessionBeforeTreeEvent,\n\tSessionBeforeTreeResult,\n\tSessionBoundaryDraft,\n\tSessionCompactEvent,\n\tSessionCompactFailedEvent,\n\tSessionInfoChangedEvent,\n\tSessionShutdownEvent,\n\tSessionStartEvent,\n\tSessionTreeEvent,\n\tSlashCommandInfo,\n\tSlashCommandSource,\n\tSourceInfo,\n\tSubagentChildPolicy,\n\tSubagentIntercomIdentity,\n\tTerminalInputHandler,\n\tThinkingLevelSelectEvent,\n\tToolCallEvent,\n\tToolCallEventResult,\n\tToolDefinition,\n\tToolExecutionEndEvent,\n\tToolExecutionMode,\n\tToolExecutionStartEvent,\n\tToolInfo,\n\tToolRenderResultOptions,\n\tToolResultEvent,\n\tToolResultEventResult,\n\tTurnEndEvent,\n\tTurnEndEventResult,\n\tTurnStartEvent,\n\tUIPromptEndEvent,\n\tUIPromptKind,\n\tUIPromptStartEvent,\n\tUserBashEvent,\n\tUserBashEventResult,\n\tWidgetPlacement,\n\tWidgetScrollRequest,\n\tWidgetScrollState,\n\tWorkflowPendingStageDelivery,\n\tWorkflowStageOrchestrationContext,\n\tWorkingIndicatorOptions,\n\tWriteToolCallEvent,\n} from \"./core/extensions/index.js\";\nexport {\n\tcreateExtensionRuntime,\n\tdecideReactiveWidgetAction,\n\tdefineTool,\n\tdiscoverAndLoadExtensions,\n\tExtensionRunner,\n\tinstallReactiveWidget,\n\tisBashToolResult,\n\tisEditToolResult,\n\tisFindToolResult,\n\tisLsToolResult,\n\tisPowerShellToolResult,\n\tisReadToolResult,\n\tisStaleExtensionContextError,\n\tisToolCallEventType,\n\tisWriteToolResult,\n\tOVERLAY_ACTIVE_ROW_MARKER,\n\tSTALE_EXTENSION_CONTEXT_MARKER,\n\tWorkflowRunControlError,\n\tWorkflowRunControlUnavailableError,\n\tWorkflowRunDatabaseError,\n\tWorkflowRunNotFoundError,\n\tWorkflowRunNotResumableError,\n\tWorkflowRunOwnershipError,\n\tWorkflowStageAmbiguousError,\n\tWorkflowStageNotFoundError,\n\tWorkflowStageResumeUnsupportedError,\n\twrapRegisteredTool,\n\twrapRegisteredTools,\n} from \"./core/extensions/index.js\";\nexport type * from \"./core/extensions/workflow-events.js\";\nexport type * from \"./core/extensions/workflow-run-control.js\";\n"]}
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * Shared utility for truncating text to visual lines (accounting for line wrapping).
3
- * Used by both tool-execution.ts and bash-execution.ts for consistent behavior.
3
+ * Used by tool renderers and bash-execution.ts for consistent behavior.
4
4
  */
5
+ import { type Component } from "@earendil-works/pi-tui";
5
6
  export interface VisualTruncateResult {
6
7
  /** The visual lines to display */
7
8
  visualLines: string[];
@@ -9,7 +10,7 @@ export interface VisualTruncateResult {
9
10
  skippedCount: number;
10
11
  }
11
12
  /**
12
- * Truncate text to a maximum number of visual lines (from the end).
13
+ * Truncate text to a maximum number of visual lines.
13
14
  * This accounts for line wrapping based on terminal width.
14
15
  *
15
16
  * @param text - The text content (may contain newlines)
@@ -18,7 +19,30 @@ export interface VisualTruncateResult {
18
19
  * @param paddingX - Horizontal padding for Text component (default 0).
19
20
  * Use 0 when result will be placed in a Box (Box adds its own padding).
20
21
  * Use 1 when result will be placed in a plain Container.
22
+ * @param keep - Which visual lines to keep: the last ones (default) or the first ones.
21
23
  * @returns The truncated visual lines and count of skipped lines
22
24
  */
23
- export declare function truncateToVisualLines(text: string, maxVisualLines: number, width: number, paddingX?: number): VisualTruncateResult;
25
+ export declare function truncateToVisualLines(text: string, maxVisualLines: number, width: number, paddingX?: number, keep?: "start" | "end"): VisualTruncateResult;
26
+ export interface VisualLinePreviewOptions {
27
+ /** Styled text; may contain newlines. */
28
+ text: string;
29
+ maxVisualLines: number;
30
+ /** Which visual lines to keep. The hint goes before kept end lines and after kept start lines. */
31
+ keep: "start" | "end";
32
+ /** Styled hint line for the given number of hidden visual lines. */
33
+ formatHint: (hidden: number) => string;
34
+ }
35
+ /**
36
+ * Collapsed tool output limited to a number of visual lines, like bash output. Limiting logical
37
+ * lines instead lets a single long line (such as minified JSON) wrap across the whole screen.
38
+ * Caches its lines per width, since it renders on every frame for every result in the transcript.
39
+ */
40
+ export declare class VisualLinePreview implements Component {
41
+ private options;
42
+ private cachedWidth;
43
+ private cachedLines;
44
+ constructor(options: VisualLinePreviewOptions);
45
+ render(width: number): string[];
46
+ invalidate(): void;
47
+ }
24
48
  //# sourceMappingURL=visual-truncate.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"visual-truncate.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/visual-truncate.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,MAAM,WAAW,oBAAoB;IACpC,kCAAkC;IAClC,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,wDAAwD;IACxD,YAAY,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CACpC,IAAI,EAAE,MAAM,EACZ,cAAc,EAAE,MAAM,EACtB,KAAK,EAAE,MAAM,EACb,QAAQ,GAAE,MAAU,GAClB,oBAAoB,CAkBtB"}
1
+ {"version":3,"file":"visual-truncate.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/visual-truncate.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,SAAS,EAAyB,MAAM,wBAAwB,CAAC;AAE/E,MAAM,WAAW,oBAAoB;IACpC,kCAAkC;IAClC,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,wDAAwD;IACxD,YAAY,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CACpC,IAAI,EAAE,MAAM,EACZ,cAAc,EAAE,MAAM,EACtB,KAAK,EAAE,MAAM,EACb,QAAQ,GAAE,MAAU,EACpB,IAAI,GAAE,OAAO,GAAG,KAAa,GAC3B,oBAAoB,CAkBtB;AAED,MAAM,WAAW,wBAAwB;IACxC,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,CAAC;IACvB,kGAAkG;IAClG,IAAI,EAAE,OAAO,GAAG,KAAK,CAAC;IACtB,oEAAoE;IACpE,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC;CACvC;AAED;;;;GAIG;AACH,qBAAa,iBAAkB,YAAW,SAAS;IAClD,OAAO,CAAC,OAAO,CAA2B;IAC1C,OAAO,CAAC,WAAW,CAAqB;IACxC,OAAO,CAAC,WAAW,CAAuB;IAE1C,YAAY,OAAO,EAAE,wBAAwB,EAE5C;IAED,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAc9B;IAED,UAAU,IAAI,IAAI,CAGjB;CACD"}
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * Shared utility for truncating text to visual lines (accounting for line wrapping).
3
- * Used by both tool-execution.ts and bash-execution.ts for consistent behavior.
3
+ * Used by tool renderers and bash-execution.ts for consistent behavior.
4
4
  */
5
- import { Text } from "@earendil-works/pi-tui";
5
+ import { Text, truncateToWidth } from "@earendil-works/pi-tui";
6
6
  /**
7
- * Truncate text to a maximum number of visual lines (from the end).
7
+ * Truncate text to a maximum number of visual lines.
8
8
  * This accounts for line wrapping based on terminal width.
9
9
  *
10
10
  * @param text - The text content (may contain newlines)
@@ -13,9 +13,10 @@ import { Text } from "@earendil-works/pi-tui";
13
13
  * @param paddingX - Horizontal padding for Text component (default 0).
14
14
  * Use 0 when result will be placed in a Box (Box adds its own padding).
15
15
  * Use 1 when result will be placed in a plain Container.
16
+ * @param keep - Which visual lines to keep: the last ones (default) or the first ones.
16
17
  * @returns The truncated visual lines and count of skipped lines
17
18
  */
18
- export function truncateToVisualLines(text, maxVisualLines, width, paddingX = 0) {
19
+ export function truncateToVisualLines(text, maxVisualLines, width, paddingX = 0, keep = "end") {
19
20
  if (!text) {
20
21
  return { visualLines: [], skippedCount: 0 };
21
22
  }
@@ -25,9 +26,41 @@ export function truncateToVisualLines(text, maxVisualLines, width, paddingX = 0)
25
26
  if (allVisualLines.length <= maxVisualLines) {
26
27
  return { visualLines: allVisualLines, skippedCount: 0 };
27
28
  }
28
- // Take the last N visual lines
29
- const truncatedLines = allVisualLines.slice(-maxVisualLines);
29
+ const truncatedLines = keep === "start" ? allVisualLines.slice(0, maxVisualLines) : allVisualLines.slice(-maxVisualLines);
30
30
  const skippedCount = allVisualLines.length - maxVisualLines;
31
31
  return { visualLines: truncatedLines, skippedCount };
32
32
  }
33
+ /**
34
+ * Collapsed tool output limited to a number of visual lines, like bash output. Limiting logical
35
+ * lines instead lets a single long line (such as minified JSON) wrap across the whole screen.
36
+ * Caches its lines per width, since it renders on every frame for every result in the transcript.
37
+ */
38
+ export class VisualLinePreview {
39
+ options;
40
+ cachedWidth;
41
+ cachedLines;
42
+ constructor(options) {
43
+ this.options = options;
44
+ }
45
+ render(width) {
46
+ if (this.cachedLines === undefined || this.cachedWidth !== width) {
47
+ const { text, maxVisualLines, keep, formatHint } = this.options;
48
+ const preview = truncateToVisualLines(text, maxVisualLines, width, 0, keep);
49
+ const lines = preview.visualLines;
50
+ if (preview.skippedCount > 0) {
51
+ const hint = truncateToWidth(formatHint(preview.skippedCount), width, "...");
52
+ this.cachedLines = keep === "start" ? [...lines, hint] : [hint, ...lines];
53
+ }
54
+ else {
55
+ this.cachedLines = lines;
56
+ }
57
+ this.cachedWidth = width;
58
+ }
59
+ return this.cachedLines;
60
+ }
61
+ invalidate() {
62
+ this.cachedWidth = undefined;
63
+ this.cachedLines = undefined;
64
+ }
65
+ }
33
66
  //# sourceMappingURL=visual-truncate.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"visual-truncate.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/visual-truncate.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAS9C;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,qBAAqB,CACpC,IAAY,EACZ,cAAsB,EACtB,KAAa,EACb,QAAQ,GAAW,CAAC;IAEpB,IAAI,CAAC,IAAI,EAAE,CAAC;QACX,OAAO,EAAE,WAAW,EAAE,EAAE,EAAE,YAAY,EAAE,CAAC,EAAE,CAAC;IAC7C,CAAC;IAED,mEAAmE;IACnE,MAAM,QAAQ,GAAG,IAAI,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC;IAC7C,MAAM,cAAc,GAAG,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAE9C,IAAI,cAAc,CAAC,MAAM,IAAI,cAAc,EAAE,CAAC;QAC7C,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,YAAY,EAAE,CAAC,EAAE,CAAC;IACzD,CAAC;IAED,+BAA+B;IAC/B,MAAM,cAAc,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC,cAAc,CAAC,CAAC;IAC7D,MAAM,YAAY,GAAG,cAAc,CAAC,MAAM,GAAG,cAAc,CAAC;IAE5D,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,YAAY,EAAE,CAAC;AACtD,CAAC","sourcesContent":["/**\n * Shared utility for truncating text to visual lines (accounting for line wrapping).\n * Used by both tool-execution.ts and bash-execution.ts for consistent behavior.\n */\n\nimport { Text } from \"@earendil-works/pi-tui\";\n\nexport interface VisualTruncateResult {\n\t/** The visual lines to display */\n\tvisualLines: string[];\n\t/** Number of visual lines that were skipped (hidden) */\n\tskippedCount: number;\n}\n\n/**\n * Truncate text to a maximum number of visual lines (from the end).\n * This accounts for line wrapping based on terminal width.\n *\n * @param text - The text content (may contain newlines)\n * @param maxVisualLines - Maximum number of visual lines to show\n * @param width - Terminal/render width\n * @param paddingX - Horizontal padding for Text component (default 0).\n * Use 0 when result will be placed in a Box (Box adds its own padding).\n * Use 1 when result will be placed in a plain Container.\n * @returns The truncated visual lines and count of skipped lines\n */\nexport function truncateToVisualLines(\n\ttext: string,\n\tmaxVisualLines: number,\n\twidth: number,\n\tpaddingX: number = 0,\n): VisualTruncateResult {\n\tif (!text) {\n\t\treturn { visualLines: [], skippedCount: 0 };\n\t}\n\n\t// Create a temporary Text component to render and get visual lines\n\tconst tempText = new Text(text, paddingX, 0);\n\tconst allVisualLines = tempText.render(width);\n\n\tif (allVisualLines.length <= maxVisualLines) {\n\t\treturn { visualLines: allVisualLines, skippedCount: 0 };\n\t}\n\n\t// Take the last N visual lines\n\tconst truncatedLines = allVisualLines.slice(-maxVisualLines);\n\tconst skippedCount = allVisualLines.length - maxVisualLines;\n\n\treturn { visualLines: truncatedLines, skippedCount };\n}\n"]}
1
+ {"version":3,"file":"visual-truncate.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/visual-truncate.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAkB,IAAI,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAS/E;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,qBAAqB,CACpC,IAAY,EACZ,cAAsB,EACtB,KAAa,EACb,QAAQ,GAAW,CAAC,EACpB,IAAI,GAAoB,KAAK;IAE7B,IAAI,CAAC,IAAI,EAAE,CAAC;QACX,OAAO,EAAE,WAAW,EAAE,EAAE,E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GAAG,CAAC,EAAE,CAAC;gBAC9B,MAAM,IAAI,GAAG,eAAe,CAAC,UAAU,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;gBAC7E,IAAI,CAAC,WAAW,GAAG,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,GAAG,KAAK,CAAC,CAAC;YAC3E,CAAC;iBAAM,CAAC;gBACP,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;YAC1B,CAAC;YACD,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;QAC1B,CAAC;QACD,OAAO,IAAI,CAAC,WAAW,CAAC;IACzB,CAAC;IAED,UAAU;QACT,IAAI,CAAC,WAAW,GAAG,SAAS,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,SAAS,CAAC;IAC9B,CAAC;CACD","sourcesContent":["/**\n * Shared utility for truncating text to visual lines (accounting for line wrapping).\n * Used by tool renderers and bash-execution.ts for consistent behavior.\n */\n\nimport { type Component, Text, truncateToWidth } from \"@earendil-works/pi-tui\";\n\nexport interface VisualTruncateResult {\n\t/** The visual lines to display */\n\tvisualLines: string[];\n\t/** Number of visual lines that were skipped (hidden) */\n\tskippedCount: number;\n}\n\n/**\n * Truncate text to a maximum number of visual lines.\n * This accounts for line wrapping based on terminal width.\n *\n * @param text - The text content (may contain newlines)\n * @param maxVisualLines - Maximum number of visual lines to show\n * @param width - Terminal/render width\n * @param paddingX - Horizontal padding for Text component (default 0).\n * Use 0 when result will be placed in a Box (Box adds its own padding).\n * Use 1 when result will be placed in a plain Container.\n * @param keep - Which visual lines to keep: the last ones (default) or the first ones.\n * @returns The truncated visual lines and count of skipped lines\n */\nexport function truncateToVisualLines(\n\ttext: string,\n\tmaxVisualLines: number,\n\twidth: number,\n\tpaddingX: number = 0,\n\tkeep: \"start\" | \"end\" = \"end\",\n): VisualTruncateResult {\n\tif (!text) {\n\t\treturn { visualLines: [], skippedCount: 0 };\n\t}\n\n\t// Create a temporary Text component to render and get visual lines\n\tconst tempText = new Text(text, paddingX, 0);\n\tconst allVisualLines = tempText.render(width);\n\n\tif (allVisualLines.length <= maxVisualLines) {\n\t\treturn { visualLines: allVisualLines, skippedCount: 0 };\n\t}\n\n\tconst truncatedLines =\n\t\tkeep === \"start\" ? allVisualLines.slice(0, maxVisualLines) : allVisualLines.slice(-maxVisualLines);\n\tconst skippedCount = allVisualLines.length - maxVisualLines;\n\n\treturn { visualLines: truncatedLines, skippedCount };\n}\n\nexport interface VisualLinePreviewOptions {\n\t/** Styled text; may contain newlines. */\n\ttext: string;\n\tmaxVisualLines: number;\n\t/** Which visual lines to keep. The hint goes before kept end lines and after kept start lines. */\n\tkeep: \"start\" | \"end\";\n\t/** Styled hint line for the given number of hidden visual lines. */\n\tformatHint: (hidden: number) => string;\n}\n\n/**\n * Collapsed tool output limited to a number of visual lines, like bash output. Limiting logical\n * lines instead lets a single long line (such as minified JSON) wrap across the whole screen.\n * Caches its lines per width, since it renders on every frame for every result in the transcript.\n */\nexport class VisualLinePreview implements Component {\n\tprivate options: VisualLinePreviewOptions;\n\tprivate cachedWidth: number | undefined;\n\tprivate cachedLines: string[] | undefined;\n\n\tconstructor(options: VisualLinePreviewOptions) {\n\t\tthis.options = options;\n\t}\n\n\trender(width: number): string[] {\n\t\tif (this.cachedLines === undefined || this.cachedWidth !== width) {\n\t\t\tconst { text, maxVisualLines, keep, formatHint } = this.options;\n\t\t\tconst preview = truncateToVisualLines(text, maxVisualLines, width, 0, keep);\n\t\t\tconst lines = preview.visualLines;\n\t\t\tif (preview.skippedCount > 0) {\n\t\t\t\tconst hint = truncateToWidth(formatHint(preview.skippedCount), width, \"...\");\n\t\t\t\tthis.cachedLines = keep === \"start\" ? [...lines, hint] : [hint, ...lines];\n\t\t\t} else {\n\t\t\t\tthis.cachedLines = lines;\n\t\t\t}\n\t\t\tthis.cachedWidth = width;\n\t\t}\n\t\treturn this.cachedLines;\n\t}\n\n\tinvalidate(): void {\n\t\tthis.cachedWidth = undefined;\n\t\tthis.cachedLines = undefined;\n\t}\n}\n"]}
@@ -851,6 +851,8 @@ export default function (pi: ExtensionAPI) {
851
851
 
852
852
  Frames are ordinary objects with a `{ epoch: string, revision: number }` cursor. Revisions increase within an epoch; lifecycle publication may leave gaps between activity revisions. A new publisher starts a new epoch and an `unavailable` snapshot. Never compare revision numbers across epochs. A `ready` snapshot has a `roots` array, including an empty array when known empty. `recovering` and `unavailable` snapshots omit `roots`. Subsequent snapshots replace all prior knowledge. Changes replace a complete root, not increment counters. Removals contain `rootRunId`. Root summaries include `state`, `reason`, execution/wait counts, and `needsAttention`.
853
853
 
854
+ The workflows extension also calls `pi.registerWorkflowRunControl(control)` to back `session.workflows`, the typed pause, quit, and resume API for SDK hosts (see [Workflow run control](/sdk#workflow-run-control)). The registration is released with the extension generation, and only the most recent registration is active.
855
+
854
856
  Providers call `pi.registerWorkflowActivityPublisher()` and retain its returned `WorkflowActivityPublisher`. Its methods are `publishSnapshot({ availability: "ready", roots })`, `publishSnapshot({ availability: "recovering" | "unavailable" })`, `publishChanged(root)`, `publishRemoved(rootRunId)`, `publishLifecycle(event)`, `publishHeartbeat(event)`, and `dispose()`. Lifecycle input includes `type: "workflow_lifecycle"` and the envelope except `cursor`, which the host supplies. Heartbeat input includes `type: "workflow_heartbeat"`. IDs, names, timestamps, zero counts and optional attribution are preserved. Roots are keyed by `rootRunId`; duplicate snapshot IDs use the last value at the first insertion position. Removing an absent ID is permitted. Changes do not turn an unknown source into `ready`; publish a snapshot to establish readiness.
855
857
 
856
858
  Workflow hooks published during extension factory initialization are retained until the runner binds dispatch, then delivered asynchronously in publication order before later live publications. Buffered events keep their original payloads and cursors; publisher retirement and runner disposal fence them just like live events.