@bastani/atomic 0.9.2 → 0.9.3-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +66 -0
- package/README.md +2 -2
- package/dist/builtin/cursor/CHANGELOG.md +15 -0
- package/dist/builtin/cursor/README.md +2 -1
- package/dist/builtin/cursor/package.json +2 -2
- package/dist/builtin/cursor/src/cursor-models-raw.json +2 -9
- package/dist/builtin/cursor/src/model-mapper.ts +14 -3
- package/dist/builtin/cursor/src/proto/protobuf-codec-base64.ts +22 -0
- package/dist/builtin/cursor/src/proto/protobuf-codec-request.ts +53 -13
- package/dist/builtin/cursor/src/proto/protobuf-codec-wire.ts +24 -7
- package/dist/builtin/cursor/src/proto/protobuf-codec.ts +3 -2
- package/dist/builtin/cursor/src/stream.ts +5 -11
- package/dist/builtin/cursor/src/transport-types.ts +3 -0
- package/dist/builtin/cursor/src/transport.ts +1 -0
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/CHANGELOG.md +6 -0
- package/dist/builtin/mcp/direct-tools.ts +4 -2
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/mcp/proxy-call.ts +3 -1
- package/dist/builtin/mcp/utils.ts +18 -7
- package/dist/builtin/subagents/CHANGELOG.md +20 -0
- package/dist/builtin/subagents/README.md +6 -6
- package/dist/builtin/subagents/agents/code-simplifier.md +7 -6
- package/dist/builtin/subagents/agents/codebase-analyzer.md +5 -4
- package/dist/builtin/subagents/agents/codebase-locator.md +3 -3
- package/dist/builtin/subagents/agents/codebase-online-researcher.md +10 -10
- package/dist/builtin/subagents/agents/codebase-pattern-finder.md +4 -4
- package/dist/builtin/subagents/agents/codebase-research-analyzer.md +3 -3
- package/dist/builtin/subagents/agents/codebase-research-locator.md +4 -4
- package/dist/builtin/subagents/agents/debugger.md +5 -5
- package/dist/builtin/subagents/agents/worker.md +56 -0
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/skills/subagent/SKILL.md +11 -11
- package/dist/builtin/subagents/src/agents/agent-loaders.ts +3 -5
- package/dist/builtin/subagents/src/agents/agent-management-helpers.ts +3 -3
- package/dist/builtin/subagents/src/extension/fanout-child.ts +1 -0
- package/dist/builtin/subagents/src/extension/index.ts +6 -3
- package/dist/builtin/subagents/src/extension/schemas.ts +2 -7
- package/dist/builtin/subagents/src/intercom/result-intercom.ts +4 -3
- package/dist/builtin/subagents/src/runs/background/async-job-tracker.ts +1 -4
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-single.ts +15 -1
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor.ts +35 -1
- package/dist/builtin/subagents/src/runs/shared/mcp-direct-tool-allowlist.ts +1 -1
- package/dist/builtin/subagents/src/runs/shared/nested-render.ts +2 -2
- package/dist/builtin/subagents/src/runs/shared/pi-args.ts +2 -1
- package/dist/builtin/subagents/src/runs/shared/subagent-prompt-runtime.ts +4 -2
- package/dist/builtin/subagents/src/shared/types-async.ts +1 -0
- package/dist/builtin/subagents/src/shared/types-depth.ts +5 -5
- package/dist/builtin/subagents/src/shared/types-runtime.ts +2 -1
- package/dist/builtin/subagents/src/slash/prompt-template-bridge.ts +27 -5
- package/dist/builtin/subagents/src/tui/render-event-formatting.ts +2 -2
- package/dist/builtin/subagents/src/tui/render-layout.ts +27 -4
- package/dist/builtin/subagents/src/tui/render-result-animation.ts +22 -31
- package/dist/builtin/subagents/src/tui/render-result-compact.ts +6 -6
- package/dist/builtin/subagents/src/tui/render-result.ts +20 -19
- package/dist/builtin/subagents/src/tui/render-status-progress.ts +3 -3
- package/dist/builtin/subagents/src/tui/render-widget.ts +46 -7
- package/dist/builtin/subagents/src/tui/render.ts +2 -2
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/builtin/workflows/CHANGELOG.md +56 -0
- package/dist/builtin/workflows/README.md +3 -3
- package/dist/builtin/workflows/builtin/goal-artifacts.ts +11 -6
- package/dist/builtin/workflows/builtin/goal-ledger.ts +33 -1
- package/dist/builtin/workflows/builtin/goal-prompts.ts +23 -28
- package/dist/builtin/workflows/builtin/goal-reducer.ts +2 -2
- package/dist/builtin/workflows/builtin/goal-reports.ts +2 -5
- package/dist/builtin/workflows/builtin/goal-review.ts +1 -1
- package/dist/builtin/workflows/builtin/goal-runner.ts +10 -17
- package/dist/builtin/workflows/builtin/open-claude-design-feedback.ts +3 -3
- package/dist/builtin/workflows/builtin/open-claude-design-phases.ts +1 -3
- package/dist/builtin/workflows/builtin/open-claude-design-setup.ts +1 -1
- package/dist/builtin/workflows/builtin/ralph-core.ts +7 -17
- package/dist/builtin/workflows/builtin/ralph-runner.ts +11 -18
- package/dist/builtin/workflows/builtin/shared-prompts.ts +1 -1
- package/dist/builtin/workflows/package.json +1 -1
- package/dist/builtin/workflows/src/authoring.d.ts +1 -1
- package/dist/builtin/workflows/src/durable/backend.ts +343 -0
- package/dist/builtin/workflows/src/durable/child-primitive.ts +79 -0
- package/dist/builtin/workflows/src/durable/dbos-backend.ts +421 -0
- package/dist/builtin/workflows/src/durable/dbos-envelope.ts +171 -0
- package/dist/builtin/workflows/src/durable/factory.ts +96 -0
- package/dist/builtin/workflows/src/durable/file-backend.ts +433 -0
- package/dist/builtin/workflows/src/durable/index.ts +73 -0
- package/dist/builtin/workflows/src/durable/resume-catalog.ts +217 -0
- package/dist/builtin/workflows/src/durable/resume-runtime.ts +299 -0
- package/dist/builtin/workflows/src/durable/scoped-backend.ts +171 -0
- package/dist/builtin/workflows/src/durable/stage-primitive.ts +284 -0
- package/dist/builtin/workflows/src/durable/tool-primitive.ts +180 -0
- package/dist/builtin/workflows/src/durable/types.ts +168 -0
- package/dist/builtin/workflows/src/durable/ui-primitive.ts +96 -0
- package/dist/builtin/workflows/src/engine/options.ts +3 -0
- package/dist/builtin/workflows/src/engine/primitives/parallel.ts +2 -2
- package/dist/builtin/workflows/src/engine/primitives/task.ts +4 -4
- package/dist/builtin/workflows/src/engine/primitives/ui.ts +22 -8
- package/dist/builtin/workflows/src/engine/primitives/workflow.ts +8 -0
- package/dist/builtin/workflows/src/engine/run-durable-finalize.ts +69 -0
- package/dist/builtin/workflows/src/engine/run-durable-stage-session.ts +31 -0
- package/dist/builtin/workflows/src/engine/run.ts +148 -6
- package/dist/builtin/workflows/src/engine/runtime.ts +8 -2
- package/dist/builtin/workflows/src/extension/config-loader.ts +35 -15
- package/dist/builtin/workflows/src/extension/discovery.ts +20 -8
- package/dist/builtin/workflows/src/extension/extension-factory.ts +6 -12
- package/dist/builtin/workflows/src/extension/extension-lifecycle.ts +5 -1
- package/dist/builtin/workflows/src/extension/extension-runtime-state.ts +4 -2
- package/dist/builtin/workflows/src/extension/runtime.ts +48 -9
- package/dist/builtin/workflows/src/extension/wiring.ts +1 -1
- package/dist/builtin/workflows/src/extension/workflow-run-control-command.ts +143 -4
- package/dist/builtin/workflows/src/runs/background/quit.ts +61 -0
- package/dist/builtin/workflows/src/runs/background/status.ts +1 -0
- package/dist/builtin/workflows/src/runs/foreground/executor-direct-helpers.ts +5 -5
- package/dist/builtin/workflows/src/runs/foreground/executor-stage-call.ts +74 -33
- package/dist/builtin/workflows/src/runs/foreground/executor-stage-context.ts +20 -1
- package/dist/builtin/workflows/src/runs/foreground/executor-stage-factory.ts +8 -7
- package/dist/builtin/workflows/src/runs/foreground/executor-stage-replay.ts +1 -0
- package/dist/builtin/workflows/src/runs/foreground/executor-stage-types.ts +1 -1
- package/dist/builtin/workflows/src/runs/foreground/executor-types.ts +19 -2
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-context.ts +4 -0
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-controller.ts +10 -10
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-options.ts +5 -1
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-send-user-message.ts +25 -0
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-types.ts +3 -0
- package/dist/builtin/workflows/src/shared/authoring-contract-stage.d.ts +16 -0
- package/dist/builtin/workflows/src/shared/authoring-contract-stage.ts +20 -0
- package/dist/builtin/workflows/src/shared/authoring-contract-ui.d.ts +23 -1
- package/dist/builtin/workflows/src/shared/authoring-contract-ui.ts +30 -1
- package/dist/builtin/workflows/src/shared/store-public-types.ts +6 -2
- package/dist/builtin/workflows/src/shared/store-run-methods.ts +12 -6
- package/dist/builtin/workflows/src/shared/types.ts +55 -0
- package/dist/builtin/workflows/src/tui/dispatch-confirm.ts +11 -10
- package/dist/builtin/workflows/src/tui/graph-view-constants.ts +1 -1
- package/dist/builtin/workflows/src/tui/graph-view-graph-render.ts +41 -0
- package/dist/builtin/workflows/src/tui/graph-view-input.ts +82 -24
- package/dist/builtin/workflows/src/tui/graph-view-render.ts +7 -0
- package/dist/builtin/workflows/src/tui/graph-view-state.ts +22 -2
- package/dist/builtin/workflows/src/tui/graph-view-types.ts +4 -5
- package/dist/builtin/workflows/src/tui/overlay-adapter.ts +9 -11
- package/dist/builtin/workflows/src/tui/stage-chat-view-footer-status.ts +9 -3
- package/dist/builtin/workflows/src/tui/stage-chat-view-input.ts +11 -2
- package/dist/builtin/workflows/src/tui/stage-chat-view-live-events.ts +35 -0
- package/dist/builtin/workflows/src/tui/stage-chat-view-state.ts +51 -17
- package/dist/builtin/workflows/src/tui/stage-chat-view-status.ts +36 -0
- package/dist/builtin/workflows/src/tui/stage-chat-view-types.ts +5 -1
- package/dist/builtin/workflows/src/tui/stage-chat-view.ts +3 -1
- package/dist/builtin/workflows/src/tui/status-list.ts +14 -2
- package/dist/builtin/workflows/src/tui/widget.ts +23 -8
- package/dist/builtin/workflows/src/tui/workflow-attach-pane-types.ts +5 -4
- package/dist/builtin/workflows/src/tui/workflow-attach-pane.ts +8 -8
- package/dist/builtin/workflows/src/tui/workflow-resume-selector.ts +151 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +9 -9
- package/dist/cli/args.js.map +1 -1
- package/dist/config-self-update.d.ts.map +1 -1
- package/dist/config-self-update.js +3 -4
- package/dist/config-self-update.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +4 -5
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session-bash.d.ts +1 -0
- package/dist/core/agent-session-bash.d.ts.map +1 -1
- package/dist/core/agent-session-bash.js +1 -0
- package/dist/core/agent-session-bash.js.map +1 -1
- package/dist/core/agent-session-tool-registry.d.ts.map +1 -1
- package/dist/core/agent-session-tool-registry.js +23 -0
- package/dist/core/agent-session-tool-registry.js.map +1 -1
- package/dist/core/bash-executor.d.ts +2 -0
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js +1 -0
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +29 -0
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +36 -1
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/compaction/context-compaction-metrics.d.ts +14 -2
- package/dist/core/compaction/context-compaction-metrics.d.ts.map +1 -1
- package/dist/core/compaction/context-compaction-metrics.js +50 -1
- package/dist/core/compaction/context-compaction-metrics.js.map +1 -1
- package/dist/core/compaction/context-compaction-prompt.d.ts.map +1 -1
- package/dist/core/compaction/context-compaction-prompt.js +2 -0
- package/dist/core/compaction/context-compaction-prompt.js.map +1 -1
- package/dist/core/compaction/context-compaction-runner.d.ts.map +1 -1
- package/dist/core/compaction/context-compaction-runner.js +1 -1
- package/dist/core/compaction/context-compaction-runner.js.map +1 -1
- package/dist/core/compaction/context-deletion-application.d.ts.map +1 -1
- package/dist/core/compaction/context-deletion-application.js +5 -5
- package/dist/core/compaction/context-deletion-application.js.map +1 -1
- package/dist/core/compaction/context-deletion-targets.d.ts +2 -0
- package/dist/core/compaction/context-deletion-targets.d.ts.map +1 -1
- package/dist/core/compaction/context-deletion-targets.js +23 -3
- package/dist/core/compaction/context-deletion-targets.js.map +1 -1
- package/dist/core/compaction/context-deletion-tool-definitions.d.ts +6 -0
- package/dist/core/compaction/context-deletion-tool-definitions.d.ts.map +1 -1
- package/dist/core/compaction/context-deletion-tool-definitions.js.map +1 -1
- package/dist/core/compaction/context-deletion-tools.d.ts.map +1 -1
- package/dist/core/compaction/context-deletion-tools.js +18 -10
- package/dist/core/compaction/context-deletion-tools.js.map +1 -1
- package/dist/core/compaction/context-transcript-analysis.d.ts.map +1 -1
- package/dist/core/compaction/context-transcript-analysis.js +2 -4
- package/dist/core/compaction/context-transcript-analysis.js.map +1 -1
- package/dist/core/copilot-gemini-tool-arguments.d.ts.map +1 -1
- package/dist/core/copilot-gemini-tool-arguments.js +2 -60
- package/dist/core/copilot-gemini-tool-arguments.js.map +1 -1
- package/dist/core/extensions/context-types.d.ts +2 -0
- package/dist/core/extensions/context-types.d.ts.map +1 -1
- package/dist/core/extensions/context-types.js.map +1 -1
- package/dist/core/extensions/index.d.ts +2 -2
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader-virtual-modules.d.ts.map +1 -1
- package/dist/core/extensions/loader-virtual-modules.js +57 -32
- package/dist/core/extensions/loader-virtual-modules.js.map +1 -1
- package/dist/core/extensions/runner-context.d.ts.map +1 -1
- package/dist/core/extensions/runner-context.js +11 -0
- package/dist/core/extensions/runner-context.js.map +1 -1
- package/dist/core/extensions/tool-events.d.ts +13 -13
- package/dist/core/extensions/tool-events.d.ts.map +1 -1
- package/dist/core/extensions/tool-events.js +3 -3
- package/dist/core/extensions/tool-events.js.map +1 -1
- package/dist/core/extensions/types.d.ts +1 -1
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/flattened-tool-arguments.d.ts +18 -0
- package/dist/core/flattened-tool-arguments.d.ts.map +1 -1
- package/dist/core/flattened-tool-arguments.js +104 -0
- package/dist/core/flattened-tool-arguments.js.map +1 -1
- package/dist/core/messages.d.ts +1 -0
- package/dist/core/messages.d.ts.map +1 -1
- package/dist/core/messages.js +46 -1
- package/dist/core/messages.js.map +1 -1
- package/dist/core/sdk-exports.d.ts +1 -1
- package/dist/core/sdk-exports.d.ts.map +1 -1
- package/dist/core/sdk-exports.js +1 -1
- package/dist/core/sdk-exports.js.map +1 -1
- package/dist/core/sdk-types.d.ts +2 -2
- package/dist/core/sdk-types.d.ts.map +1 -1
- package/dist/core/sdk-types.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +12 -0
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager-core.d.ts +15 -7
- package/dist/core/session-manager-core.d.ts.map +1 -1
- package/dist/core/session-manager-core.js +20 -9
- package/dist/core/session-manager-core.js.map +1 -1
- package/dist/core/session-manager-entries.d.ts +2 -2
- package/dist/core/session-manager-entries.d.ts.map +1 -1
- package/dist/core/session-manager-entries.js +9 -3
- package/dist/core/session-manager-entries.js.map +1 -1
- package/dist/core/session-manager-history.d.ts.map +1 -1
- package/dist/core/session-manager-history.js +2 -1
- package/dist/core/session-manager-history.js.map +1 -1
- package/dist/core/session-manager-list.d.ts +3 -3
- package/dist/core/session-manager-list.d.ts.map +1 -1
- package/dist/core/session-manager-list.js +27 -8
- package/dist/core/session-manager-list.js.map +1 -1
- package/dist/core/session-manager-storage.d.ts +3 -1
- package/dist/core/session-manager-storage.d.ts.map +1 -1
- package/dist/core/session-manager-storage.js +55 -12
- package/dist/core/session-manager-storage.js.map +1 -1
- package/dist/core/session-manager-tool-dependencies.d.ts +10 -0
- package/dist/core/session-manager-tool-dependencies.d.ts.map +1 -0
- package/dist/core/session-manager-tool-dependencies.js +133 -0
- package/dist/core/session-manager-tool-dependencies.js.map +1 -0
- package/dist/core/session-manager-types.d.ts +22 -0
- package/dist/core/session-manager-types.d.ts.map +1 -1
- package/dist/core/session-manager-types.js.map +1 -1
- package/dist/core/session-manager.d.ts +2 -2
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +1 -1
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager-basic-accessors.d.ts +4 -0
- package/dist/core/settings-manager-basic-accessors.d.ts.map +1 -1
- package/dist/core/settings-manager-basic-accessors.js +18 -0
- package/dist/core/settings-manager-basic-accessors.js.map +1 -1
- package/dist/core/settings-manager-resource-accessors.d.ts +4 -0
- package/dist/core/settings-manager-resource-accessors.d.ts.map +1 -1
- package/dist/core/settings-manager-resource-accessors.js +15 -0
- package/dist/core/settings-manager-resource-accessors.js.map +1 -1
- package/dist/core/settings-types.d.ts +11 -0
- package/dist/core/settings-types.d.ts.map +1 -1
- package/dist/core/settings-types.js.map +1 -1
- package/dist/core/system-prompt.d.ts +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +3 -2
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/artifact-protocol.d.ts +11 -0
- package/dist/core/tools/artifact-protocol.d.ts.map +1 -0
- package/dist/core/tools/artifact-protocol.js +76 -0
- package/dist/core/tools/artifact-protocol.js.map +1 -0
- package/dist/core/tools/artifacts.d.ts +18 -0
- package/dist/core/tools/artifacts.d.ts.map +1 -0
- package/dist/core/tools/artifacts.js +90 -0
- package/dist/core/tools/artifacts.js.map +1 -0
- package/dist/core/tools/bash-async-jobs.d.ts +20 -0
- package/dist/core/tools/bash-async-jobs.d.ts.map +1 -0
- package/dist/core/tools/bash-async-jobs.js +59 -0
- package/dist/core/tools/bash-async-jobs.js.map +1 -0
- package/dist/core/tools/bash-async-output.d.ts +10 -0
- package/dist/core/tools/bash-async-output.d.ts.map +1 -0
- package/dist/core/tools/bash-async-output.js +80 -0
- package/dist/core/tools/bash-async-output.js.map +1 -0
- package/dist/core/tools/bash-interceptor.d.ts +10 -0
- package/dist/core/tools/bash-interceptor.d.ts.map +1 -0
- package/dist/core/tools/bash-interceptor.js +39 -0
- package/dist/core/tools/bash-interceptor.js.map +1 -0
- package/dist/core/tools/bash-leading-cd.d.ts +7 -0
- package/dist/core/tools/bash-leading-cd.d.ts.map +1 -0
- package/dist/core/tools/bash-leading-cd.js +59 -0
- package/dist/core/tools/bash-leading-cd.js.map +1 -0
- package/dist/core/tools/bash-pty-native.d.ts +14 -0
- package/dist/core/tools/bash-pty-native.d.ts.map +1 -0
- package/dist/core/tools/bash-pty-native.js +71 -0
- package/dist/core/tools/bash-pty-native.js.map +1 -0
- package/dist/core/tools/bash.d.ts +28 -17
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +152 -35
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/block-resolver.d.ts +16 -0
- package/dist/core/tools/block-resolver.d.ts.map +1 -0
- package/dist/core/tools/block-resolver.js +74 -0
- package/dist/core/tools/block-resolver.js.map +1 -0
- package/dist/core/tools/conflict-registry.d.ts +16 -0
- package/dist/core/tools/conflict-registry.d.ts.map +1 -0
- package/dist/core/tools/conflict-registry.js +44 -0
- package/dist/core/tools/conflict-registry.js.map +1 -0
- package/dist/core/tools/directory-tree.d.ts +13 -0
- package/dist/core/tools/directory-tree.d.ts.map +1 -0
- package/dist/core/tools/directory-tree.js +81 -0
- package/dist/core/tools/directory-tree.js.map +1 -0
- package/dist/core/tools/edit.d.ts +4 -29
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +136 -228
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/fetch-url.d.ts +74 -0
- package/dist/core/tools/fetch-url.d.ts.map +1 -0
- package/dist/core/tools/fetch-url.js +518 -0
- package/dist/core/tools/fetch-url.js.map +1 -0
- package/dist/core/tools/find.d.ts +27 -9
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +400 -176
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/glob-path-utils.d.ts +8 -0
- package/dist/core/tools/glob-path-utils.d.ts.map +1 -0
- package/dist/core/tools/glob-path-utils.js +26 -0
- package/dist/core/tools/glob-path-utils.js.map +1 -0
- package/dist/core/tools/grep.d.ts +12 -0
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +141 -17
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/hashline-engine/apply.d.ts +11 -0
- package/dist/core/tools/hashline-engine/apply.d.ts.map +1 -0
- package/dist/core/tools/hashline-engine/apply.js +752 -0
- package/dist/core/tools/hashline-engine/apply.js.map +1 -0
- package/dist/core/tools/hashline-engine/block.d.ts +40 -0
- package/dist/core/tools/hashline-engine/block.d.ts.map +1 -0
- package/dist/core/tools/hashline-engine/block.js +117 -0
- package/dist/core/tools/hashline-engine/block.js.map +1 -0
- package/dist/core/tools/hashline-engine/diff-preview.d.ts +15 -0
- package/dist/core/tools/hashline-engine/diff-preview.d.ts.map +1 -0
- package/dist/core/tools/hashline-engine/diff-preview.js +98 -0
- package/dist/core/tools/hashline-engine/diff-preview.js.map +1 -0
- package/dist/core/tools/hashline-engine/format.d.ts +71 -0
- package/dist/core/tools/hashline-engine/format.d.ts.map +1 -0
- package/dist/core/tools/hashline-engine/format.js +178 -0
- package/dist/core/tools/hashline-engine/format.js.map +1 -0
- package/dist/core/tools/hashline-engine/fs.d.ts +81 -0
- package/dist/core/tools/hashline-engine/fs.d.ts.map +1 -0
- package/dist/core/tools/hashline-engine/fs.js +143 -0
- package/dist/core/tools/hashline-engine/fs.js.map +1 -0
- package/dist/core/tools/hashline-engine/index.d.ts +18 -0
- package/dist/core/tools/hashline-engine/index.d.ts.map +1 -0
- package/dist/core/tools/hashline-engine/index.js +20 -0
- package/dist/core/tools/hashline-engine/index.js.map +1 -0
- package/dist/core/tools/hashline-engine/input.d.ts +101 -0
- package/dist/core/tools/hashline-engine/input.d.ts.map +1 -0
- package/dist/core/tools/hashline-engine/input.js +398 -0
- package/dist/core/tools/hashline-engine/input.js.map +1 -0
- package/dist/core/tools/hashline-engine/messages.d.ts +99 -0
- package/dist/core/tools/hashline-engine/messages.d.ts.map +1 -0
- package/dist/core/tools/hashline-engine/messages.js +144 -0
- package/dist/core/tools/hashline-engine/messages.js.map +1 -0
- package/dist/core/tools/hashline-engine/mismatch.d.ts +45 -0
- package/dist/core/tools/hashline-engine/mismatch.d.ts.map +1 -0
- package/dist/core/tools/hashline-engine/mismatch.js +90 -0
- package/dist/core/tools/hashline-engine/mismatch.js.map +1 -0
- package/dist/core/tools/hashline-engine/normalize.d.ts +21 -0
- package/dist/core/tools/hashline-engine/normalize.d.ts.map +1 -0
- package/dist/core/tools/hashline-engine/normalize.js +33 -0
- package/dist/core/tools/hashline-engine/normalize.js.map +1 -0
- package/dist/core/tools/hashline-engine/parser.d.ts +24 -0
- package/dist/core/tools/hashline-engine/parser.d.ts.map +1 -0
- package/dist/core/tools/hashline-engine/parser.js +381 -0
- package/dist/core/tools/hashline-engine/parser.js.map +1 -0
- package/dist/core/tools/hashline-engine/patcher.d.ts +118 -0
- package/dist/core/tools/hashline-engine/patcher.d.ts.map +1 -0
- package/dist/core/tools/hashline-engine/patcher.js +341 -0
- package/dist/core/tools/hashline-engine/patcher.js.map +1 -0
- package/dist/core/tools/hashline-engine/prefixes.d.ts +43 -0
- package/dist/core/tools/hashline-engine/prefixes.d.ts.map +1 -0
- package/dist/core/tools/hashline-engine/prefixes.js +135 -0
- package/dist/core/tools/hashline-engine/prefixes.js.map +1 -0
- package/dist/core/tools/hashline-engine/recovery.d.ts +41 -0
- package/dist/core/tools/hashline-engine/recovery.d.ts.map +1 -0
- package/dist/core/tools/hashline-engine/recovery.js +168 -0
- package/dist/core/tools/hashline-engine/recovery.js.map +1 -0
- package/dist/core/tools/hashline-engine/snapshots.d.ts +65 -0
- package/dist/core/tools/hashline-engine/snapshots.d.ts.map +1 -0
- package/dist/core/tools/hashline-engine/snapshots.js +108 -0
- package/dist/core/tools/hashline-engine/snapshots.js.map +1 -0
- package/dist/core/tools/hashline-engine/stream.d.ts +3 -0
- package/dist/core/tools/hashline-engine/stream.d.ts.map +1 -0
- package/dist/core/tools/hashline-engine/stream.js +111 -0
- package/dist/core/tools/hashline-engine/stream.js.map +1 -0
- package/dist/core/tools/hashline-engine/tokenizer.d.ts +69 -0
- package/dist/core/tools/hashline-engine/tokenizer.d.ts.map +1 -0
- package/dist/core/tools/hashline-engine/tokenizer.js +430 -0
- package/dist/core/tools/hashline-engine/tokenizer.js.map +1 -0
- package/dist/core/tools/hashline-engine/types.d.ts +166 -0
- package/dist/core/tools/hashline-engine/types.d.ts.map +1 -0
- package/dist/core/tools/hashline-engine/types.js +9 -0
- package/dist/core/tools/hashline-engine/types.js.map +1 -0
- package/dist/core/tools/hashline.d.ts +29 -0
- package/dist/core/tools/hashline.d.ts.map +1 -0
- package/dist/core/tools/hashline.js +110 -0
- package/dist/core/tools/hashline.js.map +1 -0
- package/dist/core/tools/index.d.ts +6 -4
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +52 -35
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/notebook.d.ts +38 -0
- package/dist/core/tools/notebook.d.ts.map +1 -0
- package/dist/core/tools/notebook.js +125 -0
- package/dist/core/tools/notebook.js.map +1 -0
- package/dist/core/tools/read-document-extract.d.ts +9 -0
- package/dist/core/tools/read-document-extract.d.ts.map +1 -0
- package/dist/core/tools/read-document-extract.js +212 -0
- package/dist/core/tools/read-document-extract.js.map +1 -0
- package/dist/core/tools/read-selectors.d.ts +24 -0
- package/dist/core/tools/read-selectors.d.ts.map +1 -0
- package/dist/core/tools/read-selectors.js +277 -0
- package/dist/core/tools/read-selectors.js.map +1 -0
- package/dist/core/tools/read-url.d.ts +37 -0
- package/dist/core/tools/read-url.d.ts.map +1 -0
- package/dist/core/tools/read-url.js +39 -0
- package/dist/core/tools/read-url.js.map +1 -0
- package/dist/core/tools/read.d.ts +11 -11
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +224 -94
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/resource-selectors.d.ts +44 -0
- package/dist/core/tools/resource-selectors.d.ts.map +1 -0
- package/dist/core/tools/resource-selectors.js +808 -0
- package/dist/core/tools/resource-selectors.js.map +1 -0
- package/dist/core/tools/search-details.d.ts +26 -0
- package/dist/core/tools/search-details.d.ts.map +1 -0
- package/dist/core/tools/search-details.js +24 -0
- package/dist/core/tools/search-details.js.map +1 -0
- package/dist/core/tools/search-line-ranges.d.ts +11 -0
- package/dist/core/tools/search-line-ranges.d.ts.map +1 -0
- package/dist/core/tools/search-line-ranges.js +65 -0
- package/dist/core/tools/search-line-ranges.js.map +1 -0
- package/dist/core/tools/search-native.d.ts +97 -0
- package/dist/core/tools/search-native.d.ts.map +1 -0
- package/dist/core/tools/search-native.js +27 -0
- package/dist/core/tools/search-native.js.map +1 -0
- package/dist/core/tools/search.d.ts +24 -0
- package/dist/core/tools/search.d.ts.map +1 -0
- package/dist/core/tools/search.js +573 -0
- package/dist/core/tools/search.js.map +1 -0
- package/dist/core/tools/truncate.d.ts +4 -4
- package/dist/core/tools/truncate.d.ts.map +1 -1
- package/dist/core/tools/truncate.js +3 -3
- package/dist/core/tools/truncate.js.map +1 -1
- package/dist/core/tools/url-ip-guards.d.ts +4 -0
- package/dist/core/tools/url-ip-guards.d.ts.map +1 -0
- package/dist/core/tools/url-ip-guards.js +126 -0
- package/dist/core/tools/url-ip-guards.js.map +1 -0
- package/dist/core/tools/write.d.ts +12 -2
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +166 -14
- package/dist/core/tools/write.js.map +1 -1
- package/dist/core/trust-manager.d.ts.map +1 -1
- package/dist/core/trust-manager.js +2 -3
- package/dist/core/trust-manager.js.map +1 -1
- package/dist/index-extensions.d.ts +2 -2
- package/dist/index-extensions.d.ts.map +1 -1
- package/dist/index-extensions.js +1 -1
- package/dist/index-extensions.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-runtime.d.ts +1 -0
- package/dist/modes/interactive/components/chat-session-host-runtime.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-runtime.js +12 -0
- package/dist/modes/interactive/components/chat-session-host-runtime.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-terminal-cleanup.d.ts +4 -0
- package/dist/modes/interactive/components/chat-session-host-terminal-cleanup.d.ts.map +1 -0
- package/dist/modes/interactive/components/chat-session-host-terminal-cleanup.js +131 -0
- package/dist/modes/interactive/components/chat-session-host-terminal-cleanup.js.map +1 -0
- package/dist/modes/interactive/components/chat-session-host.d.ts +2 -0
- package/dist/modes/interactive/components/chat-session-host.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host.js +7 -1
- package/dist/modes/interactive/components/chat-session-host.js.map +1 -1
- package/dist/modes/interactive/components/chat-transcript.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-transcript.js +15 -4
- package/dist/modes/interactive/components/chat-transcript.js.map +1 -1
- package/dist/modes/interactive/components/custom-editor.d.ts +1 -0
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-editor.js +9 -2
- package/dist/modes/interactive/components/custom-editor.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector-handlers.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector-handlers.js +3 -0
- package/dist/modes/interactive/components/settings-selector-handlers.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector-items.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector-items.js +7 -0
- package/dist/modes/interactive/components/settings-selector-items.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector-types.d.ts +2 -0
- package/dist/modes/interactive/components/settings-selector-types.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector-types.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +3 -0
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +26 -0
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector-content.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector-content.js +0 -5
- package/dist/modes/interactive/components/tree-selector-content.js.map +1 -1
- package/dist/modes/interactive/interactive-auth-login.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-auth-login.js +1 -0
- package/dist/modes/interactive/interactive-auth-login.js.map +1 -1
- package/dist/modes/interactive/interactive-autocomplete.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-autocomplete.js +80 -2
- package/dist/modes/interactive/interactive-autocomplete.js.map +1 -1
- package/dist/modes/interactive/interactive-hotkeys-debug.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-hotkeys-debug.js +3 -0
- package/dist/modes/interactive/interactive-hotkeys-debug.js.map +1 -1
- package/dist/modes/interactive/interactive-input-handling.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-input-handling.js +51 -0
- package/dist/modes/interactive/interactive-input-handling.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-base.d.ts +5 -0
- package/dist/modes/interactive/interactive-mode-base.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-base.js +5 -0
- package/dist/modes/interactive/interactive-mode-base.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-deps.d.ts +1 -1
- package/dist/modes/interactive/interactive-mode-deps.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-deps.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-surface.d.ts +12 -0
- package/dist/modes/interactive/interactive-mode-surface.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-surface.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +1 -0
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/interactive-model-routing.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-model-routing.js +4 -1
- package/dist/modes/interactive/interactive-model-routing.js.map +1 -1
- package/dist/modes/interactive/interactive-onboarding.d.ts +11 -0
- package/dist/modes/interactive/interactive-onboarding.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-onboarding.js +220 -0
- package/dist/modes/interactive/interactive-onboarding.js.map +1 -0
- package/dist/modes/interactive/interactive-selectors.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-selectors.js +4 -0
- package/dist/modes/interactive/interactive-selectors.js.map +1 -1
- package/dist/modes/interactive/interactive-session-routing.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-session-routing.js +6 -0
- package/dist/modes/interactive/interactive-session-routing.js.map +1 -1
- package/dist/modes/interactive/interactive-slash-commands.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-slash-commands.js +9 -4
- package/dist/modes/interactive/interactive-slash-commands.js.map +1 -1
- package/dist/modes/interactive/interactive-startup.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-startup.js +28 -0
- package/dist/modes/interactive/interactive-startup.js.map +1 -1
- package/dist/utils/child-process.d.ts.map +1 -1
- package/dist/utils/child-process.js +21 -1
- package/dist/utils/child-process.js.map +1 -1
- package/dist/utils/markit.d.ts +8 -0
- package/dist/utils/markit.d.ts.map +1 -0
- package/dist/utils/markit.js +53 -0
- package/dist/utils/markit.js.map +1 -0
- package/dist/utils/paths.d.ts +2 -1
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +14 -1
- package/dist/utils/paths.js.map +1 -1
- package/docs/compaction.md +18 -1
- package/docs/containerization.md +1 -1
- package/docs/docs.json +1 -0
- package/docs/extensions.md +25 -36
- package/docs/models.md +1 -1
- package/docs/providers.md +2 -1
- package/docs/quickstart.md +11 -6
- package/docs/sdk.md +5 -5
- package/docs/session-format.md +6 -0
- package/docs/sessions.md +6 -0
- package/docs/settings.md +7 -0
- package/docs/subagents.md +3 -2
- package/docs/tools.md +49 -0
- package/docs/usage.md +3 -3
- package/docs/workflows.md +112 -8
- package/examples/extensions/subagent/README.md +5 -5
- package/examples/extensions/subagent/agents/planner.md +1 -1
- package/examples/extensions/subagent/agents/reviewer.md +1 -1
- package/examples/extensions/subagent/agents/scout.md +2 -2
- package/examples/extensions/subagent/display.ts +3 -3
- package/examples/sdk/05-tools.ts +3 -3
- package/examples/sdk/README.md +1 -1
- package/package.json +5 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner-context.js","sourceRoot":"","sources":["../../../src/core/extensions/runner-context.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"runner-context.js","sourceRoot":"","sources":["../../../src/core/extensions/runner-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAKjC,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAiD1F;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CAAC,MAA8B;IACpE,OAAO;QACN,IAAI,EAAE;YACL,MAAM,CAAC,YAAY,EAAE,CAAC;YACtB,OAAO,MAAM,CAAC,YAAY,EAAE,CAAC;QAC9B,CAAC;QACD,IAAI,IAAI;YACP,MAAM,CAAC,YAAY,EAAE,CAAC;YACtB,OAAO,MAAM,CAAC,OAAO,EAAE,CAAC;QACzB,CAAC;QACD,IAAI,KAAK;YACR,MAAM,CAAC,YAAY,EAAE,CAAC;YACtB,OAAO,MAAM,CAAC,KAAK,EAAE,CAAC;QACvB,CAAC;QACD,IAAI,GAAG;YACN,MAAM,CAAC,YAAY,EAAE,CAAC;YACtB,OAAO,MAAM,CAAC,MAAM,EAAE,CAAC;QACxB,CAAC;QACD,IAAI,cAAc;YACjB,MAAM,CAAC,YAAY,EAAE,CAAC;YACtB,OAAO,MAAM,CAAC,iBAAiB,EAAE,CAAC;QACnC,CAAC;QACD,IAAI,aAAa;YAChB,MAAM,CAAC,YAAY,EAAE,CAAC;YACtB,OAAO,MAAM,CAAC,gBAAgB,EAAE,CAAC;QAClC,CAAC;QACD,IAAI,KAAK;YACR,MAAM,CAAC,YAAY,EAAE,CAAC;YAC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ACtC,CAAC,CAAC;IACF,OAAO,CAAC,YAAY,GAAG,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE;QAC5C,MAAM,CAAC,YAAY,EAAE,CAAC;QACtB,OAAO,MAAM,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC/C,CAAC,CAAC;IACF,OAAO,CAAC,aAAa,GAAG,CAAC,WAAW,EAAE,OAAO,EAAE,EAAE;QAChD,MAAM,CAAC,YAAY,EAAE,CAAC;QACtB,OAAO,MAAM,CAAC,aAAa,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IACnD,CAAC,CAAC;IACF,OAAO,CAAC,MAAM,GAAG,GAAG,EAAE;QACrB,MAAM,CAAC,YAAY,EAAE,CAAC;QACtB,OAAO,MAAM,CAAC,MAAM,EAAE,CAAC;IACxB,CAAC,CAAC;IACF,OAAO,OAAO,CAAC;AAChB,CAAC","sourcesContent":["import { join } from \"node:path\";\nimport type { Api, Model } from \"@earendil-works/pi-ai\";\nimport type { ModelRegistry } from \"../model-registry.ts\";\nimport type { SessionManager } from \"../session-manager.ts\";\nimport type { BuildSystemPromptOptions } from \"../system-prompt.ts\";\nimport { createArtifactRouter, registerArtifactDir } from \"../tools/artifact-protocol.ts\";\nimport type {\n\tCompactOptions,\n\tContextUsage,\n\tExtensionCommandContext,\n\tExtensionContext,\n\tExtensionMode,\n\tExtensionUIContext,\n\tOrchestrationContext,\n} from \"./types.ts\";\nimport type {\n\tForkHandler,\n\tNavigateTreeHandler,\n\tNewSessionHandler,\n\tReloadHandler,\n\tSwitchSessionHandler,\n} from \"./runner-handlers.ts\";\n\nexport interface ExtensionContextSource {\n\tassertActive(): void;\n\tgetUIContext(): ExtensionUIContext;\n\tgetMode(): ExtensionMode;\n\thasUI(): boolean;\n\tgetCwd(): string;\n\tgetSessionManager(): SessionManager;\n\tgetModelRegistry(): ModelRegistry;\n\tgetModel(): Model<Api> | undefined;\n\tgetOrchestrationContext(): OrchestrationContext | undefined;\n\tisIdle(): boolean;\n\tisProjectTrusted(): boolean;\n\tgetSignal(): AbortSignal | undefined;\n\tabort(): void;\n\thasPendingMessages(): boolean;\n\tshutdown(): void;\n\tgetContextUsage(): ContextUsage | undefined;\n\tcompact(options?: CompactOptions): void;\n\tgetSystemPrompt(): string;\n}\n\nexport interface ExtensionCommandContextSource extends ExtensionContextSource {\n\tgetSystemPromptOptions(): BuildSystemPromptOptions;\n\twaitForIdle(): Promise<void>;\n\tnewSession: NewSessionHandler;\n\tfork: ForkHandler;\n\tnavigateTree: NavigateTreeHandler;\n\tswitchSession: SwitchSessionHandler;\n\treload: ReloadHandler;\n}\n\n/**\n * Create an ExtensionContext for use in event handlers and tool execution.\n * Context values are resolved at call time, so host changes are reflected.\n */\nexport function createExtensionContext(source: ExtensionContextSource): ExtensionContext {\n\treturn {\n\t\tget ui() {\n\t\t\tsource.assertActive();\n\t\t\treturn source.getUIContext();\n\t\t},\n\t\tget mode() {\n\t\t\tsource.assertActive();\n\t\t\treturn source.getMode();\n\t\t},\n\t\tget hasUI() {\n\t\t\tsource.assertActive();\n\t\t\treturn source.hasUI();\n\t\t},\n\t\tget cwd() {\n\t\t\tsource.assertActive();\n\t\t\treturn source.getCwd();\n\t\t},\n\t\tget sessionManager() {\n\t\t\tsource.assertActive();\n\t\t\treturn source.getSessionManager();\n\t\t},\n\t\tget modelRegistry() {\n\t\t\tsource.assertActive();\n\t\t\treturn source.getModelRegistry();\n\t\t},\n\t\tget model() {\n\t\t\tsource.assertActive();\n\t\t\treturn source.getModel();\n\t\t},\n\t\tget internalResourceRouter() {\n\t\t\tsource.assertActive();\n\t\t\tconst sessionDir = source.getSessionManager().getSessionDir();\n\t\t\tif (!sessionDir) return undefined;\n\t\t\tconst artifactsDir = join(sessionDir, \"artifacts\");\n\t\t\tregisterArtifactDir(artifactsDir);\n\t\t\treturn createArtifactRouter(() => [artifactsDir]);\n\t\t},\n\t\tget orchestrationContext() {\n\t\t\tsource.assertActive();\n\t\t\treturn source.getOrchestrationContext();\n\t\t},\n\t\tisIdle: () => {\n\t\t\tsource.assertActive();\n\t\t\treturn source.isIdle();\n\t\t},\n\t\tisProjectTrusted: () => {\n\t\t\tsource.assertActive();\n\t\t\treturn source.isProjectTrusted();\n\t\t},\n\t\tget signal() {\n\t\t\tsource.assertActive();\n\t\t\treturn source.getSignal();\n\t\t},\n\t\tabort: () => {\n\t\t\tsource.assertActive();\n\t\t\tsource.abort();\n\t\t},\n\t\thasPendingMessages: () => {\n\t\t\tsource.assertActive();\n\t\t\treturn source.hasPendingMessages();\n\t\t},\n\t\tshutdown: () => {\n\t\t\tsource.assertActive();\n\t\t\tsource.shutdown();\n\t\t},\n\t\tgetContextUsage: () => {\n\t\t\tsource.assertActive();\n\t\t\treturn source.getContextUsage();\n\t\t},\n\t\tcompact: (options) => {\n\t\t\tsource.assertActive();\n\t\t\tsource.compact(options);\n\t\t},\n\t\tgetSystemPrompt: () => {\n\t\t\tsource.assertActive();\n\t\t\treturn source.getSystemPrompt();\n\t\t},\n\t};\n}\n\nexport function createExtensionCommandContext(source: ExtensionCommandContextSource): ExtensionCommandContext {\n\t// Use property descriptors instead of object spread so the guarded getters from\n\t// createExtensionContext() stay lazy. A spread would eagerly read them once and\n\t// freeze old values into the returned object, bypassing stale-instance checks.\n\tconst context = Object.defineProperties(\n\t\t{},\n\t\tObject.getOwnPropertyDescriptors(createExtensionContext(source)),\n\t) as ExtensionCommandContext;\n\tcontext.getSystemPromptOptions = () => {\n\t\tsource.assertActive();\n\t\treturn source.getSystemPromptOptions();\n\t};\n\tcontext.waitForIdle = () => {\n\t\tsource.assertActive();\n\t\treturn source.waitForIdle();\n\t};\n\tcontext.newSession = (options) => {\n\t\tsource.assertActive();\n\t\treturn source.newSession(options);\n\t};\n\tcontext.fork = (entryId, options) => {\n\t\tsource.assertActive();\n\t\treturn source.fork(entryId, options);\n\t};\n\tcontext.navigateTree = (targetId, options) => {\n\t\tsource.assertActive();\n\t\treturn source.navigateTree(targetId, options);\n\t};\n\tcontext.switchSession = (sessionPath, options) => {\n\t\tsource.assertActive();\n\t\treturn source.switchSession(sessionPath, options);\n\t};\n\tcontext.reload = () => {\n\t\tsource.assertActive();\n\t\treturn source.reload();\n\t};\n\treturn context;\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ImageContent, TextContent } from "@earendil-works/pi-ai";
|
|
2
2
|
import type { EditToolDetails } from "../tools/edit.ts";
|
|
3
|
-
import type { BashToolDetails, BashToolInput, EditToolInput, FindToolDetails, FindToolInput,
|
|
3
|
+
import type { BashToolDetails, BashToolInput, EditToolInput, FindToolDetails, FindToolInput, LsToolDetails, LsToolInput, ReadToolDetails, ReadToolInput, SearchToolDetails, SearchToolInput, WriteToolInput } from "../tools/index.ts";
|
|
4
4
|
interface ToolCallEventBase {
|
|
5
5
|
type: "tool_call";
|
|
6
6
|
toolCallId: string;
|
|
@@ -21,14 +21,14 @@ export interface WriteToolCallEvent extends ToolCallEventBase {
|
|
|
21
21
|
toolName: "write";
|
|
22
22
|
input: WriteToolInput;
|
|
23
23
|
}
|
|
24
|
-
export interface GrepToolCallEvent extends ToolCallEventBase {
|
|
25
|
-
toolName: "grep";
|
|
26
|
-
input: GrepToolInput;
|
|
27
|
-
}
|
|
28
24
|
export interface FindToolCallEvent extends ToolCallEventBase {
|
|
29
25
|
toolName: "find";
|
|
30
26
|
input: FindToolInput;
|
|
31
27
|
}
|
|
28
|
+
export interface SearchToolCallEvent extends ToolCallEventBase {
|
|
29
|
+
toolName: "search";
|
|
30
|
+
input: SearchToolInput;
|
|
31
|
+
}
|
|
32
32
|
export interface LsToolCallEvent extends ToolCallEventBase {
|
|
33
33
|
toolName: "ls";
|
|
34
34
|
input: LsToolInput;
|
|
@@ -43,7 +43,7 @@ export interface CustomToolCallEvent extends ToolCallEventBase {
|
|
|
43
43
|
* `event.input` is mutable. Mutate it in place to patch tool arguments before execution.
|
|
44
44
|
* Later `tool_call` handlers see earlier mutations. No re-validation is performed after mutation.
|
|
45
45
|
*/
|
|
46
|
-
export type ToolCallEvent = BashToolCallEvent | ReadToolCallEvent | EditToolCallEvent | WriteToolCallEvent |
|
|
46
|
+
export type ToolCallEvent = BashToolCallEvent | ReadToolCallEvent | EditToolCallEvent | WriteToolCallEvent | FindToolCallEvent | SearchToolCallEvent | LsToolCallEvent | CustomToolCallEvent;
|
|
47
47
|
interface ToolResultEventBase {
|
|
48
48
|
type: "tool_result";
|
|
49
49
|
toolCallId: string;
|
|
@@ -67,14 +67,14 @@ export interface WriteToolResultEvent extends ToolResultEventBase {
|
|
|
67
67
|
toolName: "write";
|
|
68
68
|
details: undefined;
|
|
69
69
|
}
|
|
70
|
-
export interface GrepToolResultEvent extends ToolResultEventBase {
|
|
71
|
-
toolName: "grep";
|
|
72
|
-
details: GrepToolDetails | undefined;
|
|
73
|
-
}
|
|
74
70
|
export interface FindToolResultEvent extends ToolResultEventBase {
|
|
75
71
|
toolName: "find";
|
|
76
72
|
details: FindToolDetails | undefined;
|
|
77
73
|
}
|
|
74
|
+
export interface SearchToolResultEvent extends ToolResultEventBase {
|
|
75
|
+
toolName: "search";
|
|
76
|
+
details: SearchToolDetails | undefined;
|
|
77
|
+
}
|
|
78
78
|
export interface LsToolResultEvent extends ToolResultEventBase {
|
|
79
79
|
toolName: "ls";
|
|
80
80
|
details: LsToolDetails | undefined;
|
|
@@ -84,13 +84,13 @@ export interface CustomToolResultEvent extends ToolResultEventBase {
|
|
|
84
84
|
details: unknown;
|
|
85
85
|
}
|
|
86
86
|
/** Fired after a tool executes. Can modify result. */
|
|
87
|
-
export type ToolResultEvent = BashToolResultEvent | ReadToolResultEvent | EditToolResultEvent | WriteToolResultEvent |
|
|
87
|
+
export type ToolResultEvent = BashToolResultEvent | ReadToolResultEvent | EditToolResultEvent | WriteToolResultEvent | FindToolResultEvent | SearchToolResultEvent | LsToolResultEvent | CustomToolResultEvent;
|
|
88
88
|
export declare function isBashToolResult(e: ToolResultEvent): e is BashToolResultEvent;
|
|
89
89
|
export declare function isReadToolResult(e: ToolResultEvent): e is ReadToolResultEvent;
|
|
90
90
|
export declare function isEditToolResult(e: ToolResultEvent): e is EditToolResultEvent;
|
|
91
91
|
export declare function isWriteToolResult(e: ToolResultEvent): e is WriteToolResultEvent;
|
|
92
|
-
export declare function isGrepToolResult(e: ToolResultEvent): e is GrepToolResultEvent;
|
|
93
92
|
export declare function isFindToolResult(e: ToolResultEvent): e is FindToolResultEvent;
|
|
93
|
+
export declare function isSearchToolResult(e: ToolResultEvent): e is SearchToolResultEvent;
|
|
94
94
|
export declare function isLsToolResult(e: ToolResultEvent): e is LsToolResultEvent;
|
|
95
95
|
/**
|
|
96
96
|
* Type guard for narrowing ToolCallEvent by tool name.
|
|
@@ -116,8 +116,8 @@ export declare function isToolCallEventType(toolName: "bash", event: ToolCallEve
|
|
|
116
116
|
export declare function isToolCallEventType(toolName: "read", event: ToolCallEvent): event is ReadToolCallEvent;
|
|
117
117
|
export declare function isToolCallEventType(toolName: "edit", event: ToolCallEvent): event is EditToolCallEvent;
|
|
118
118
|
export declare function isToolCallEventType(toolName: "write", event: ToolCallEvent): event is WriteToolCallEvent;
|
|
119
|
-
export declare function isToolCallEventType(toolName: "grep", event: ToolCallEvent): event is GrepToolCallEvent;
|
|
120
119
|
export declare function isToolCallEventType(toolName: "find", event: ToolCallEvent): event is FindToolCallEvent;
|
|
120
|
+
export declare function isToolCallEventType(toolName: "search", event: ToolCallEvent): event is SearchToolCallEvent;
|
|
121
121
|
export declare function isToolCallEventType(toolName: "ls", event: ToolCallEvent): event is LsToolCallEvent;
|
|
122
122
|
export declare function isToolCallEventType<TName extends string, TInput extends Record<string, unknown>>(toolName: TName, event: ToolCallEvent): event is ToolCallEvent & {
|
|
123
123
|
toolName: TName;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-events.d.ts","sourceRoot":"","sources":["../../../src/core/extensions/tool-events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW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AAO,EAAE,KAAK,EAAE,aAAa,GAAG,KAAK,IAAI,kBAAkB,CAAC;AAC1G,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,GAAG,KAAK,IAAI,iBAAiB,CAAC;AACxG,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,GAAG,KAAK,IAAI,iBAAiB,CAAC;AACxG,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,aAAa,GAAG,KAAK,IAAI,eAAe,CAAC;AACpG,wBAAgB,mBAAmB,CAAC,KAAK,SAAS,MAAM,EAAE,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/F,QAAQ,EAAE,KAAK,EACf,KAAK,EAAE,aAAa,GAClB,KAAK,IAAI,aAAa,GAAG;IAAE,QAAQ,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC","sourcesContent":["import type { ImageContent, TextContent } from \"@earendil-works/pi-ai\";\nimport type { EditToolDetails } from \"../tools/edit.ts\";\nimport type {\n\tBashToolDetails,\n\tBashToolInput,\n\tEditToolInput,\n\tFindToolDetails,\n\tFindToolInput,\n\tGrepToolDetails,\n\tGrepToolInput,\n\tLsToolDetails,\n\tLsToolInput,\n\tReadToolDetails,\n\tReadToolInput,\n\tWriteToolInput,\n} from \"../tools/index.ts\";\n\n// ============================================================================\n// Tool Events\n// ============================================================================\n\ninterface ToolCallEventBase {\n\ttype: \"tool_call\";\n\ttoolCallId: string;\n}\n\nexport interface BashToolCallEvent extends ToolCallEventBase {\n\ttoolName: \"bash\";\n\tinput: BashToolInput;\n}\n\nexport interface ReadToolCallEvent extends ToolCallEventBase {\n\ttoolName: \"read\";\n\tinput: ReadToolInput;\n}\n\nexport interface EditToolCallEvent extends ToolCallEventBase {\n\ttoolName: \"edit\";\n\tinput: EditToolInput;\n}\n\nexport interface WriteToolCallEvent extends ToolCallEventBase {\n\ttoolName: \"write\";\n\tinput: WriteToolInput;\n}\n\nexport interface GrepToolCallEvent extends ToolCallEventBase {\n\ttoolName: \"grep\";\n\tinput: GrepToolInput;\n}\n\nexport interface FindToolCallEvent extends ToolCallEventBase {\n\ttoolName: \"find\";\n\tinput: FindToolInput;\n}\n\nexport interface LsToolCallEvent extends ToolCallEventBase {\n\ttoolName: \"ls\";\n\tinput: LsToolInput;\n}\n\nexport interface CustomToolCallEvent extends ToolCallEventBase {\n\ttoolName: string;\n\tinput: Record<string, unknown>;\n}\n\n/**\n * Fired before a tool executes. Can block.\n *\n * `event.input` is mutable. Mutate it in place to patch tool arguments before execution.\n * Later `tool_call` handlers see earlier mutations. No re-validation is performed after mutation.\n */\nexport type ToolCallEvent =\n\t| BashToolCallEvent\n\t| ReadToolCallEvent\n\t| EditToolCallEvent\n\t| WriteToolCallEvent\n\t| GrepToolCallEvent\n\t| FindToolCallEvent\n\t| LsToolCallEvent\n\t| CustomToolCallEvent;\n\ninterface ToolResultEventBase {\n\ttype: \"tool_result\";\n\ttoolCallId: string;\n\tinput: Record<string, unknown>;\n\tcontent: (TextContent | ImageContent)[];\n\tisError: boolean;\n}\n\nexport interface BashToolResultEvent extends ToolResultEventBase {\n\ttoolName: \"bash\";\n\tdetails: BashToolDetails | undefined;\n}\n\nexport interface ReadToolResultEvent extends ToolResultEventBase {\n\ttoolName: \"read\";\n\tdetails: ReadToolDetails | undefined;\n}\n\nexport interface EditToolResultEvent extends ToolResultEventBase {\n\ttoolName: \"edit\";\n\tdetails: EditToolDetails | undefined;\n}\n\nexport interface WriteToolResultEvent extends ToolResultEventBase {\n\ttoolName: \"write\";\n\tdetails: undefined;\n}\n\nexport interface GrepToolResultEvent extends ToolResultEventBase {\n\ttoolName: \"grep\";\n\tdetails: GrepToolDetails | undefined;\n}\n\nexport interface FindToolResultEvent extends ToolResultEventBase {\n\ttoolName: \"find\";\n\tdetails: FindToolDetails | undefined;\n}\n\nexport interface LsToolResultEvent extends ToolResultEventBase {\n\ttoolName: \"ls\";\n\tdetails: LsToolDetails | undefined;\n}\n\nexport interface CustomToolResultEvent extends ToolResultEventBase {\n\ttoolName: string;\n\tdetails: unknown;\n}\n\n/** Fired after a tool executes. Can modify result. */\nexport type ToolResultEvent =\n\t| BashToolResultEvent\n\t| ReadToolResultEvent\n\t| EditToolResultEvent\n\t| WriteToolResultEvent\n\t| GrepToolResultEvent\n\t| FindToolResultEvent\n\t| LsToolResultEvent\n\t| CustomToolResultEvent;\n\n// Type guards for ToolResultEvent\nexport function isBashToolResult(e: ToolResultEvent): e is BashToolResultEvent {\n\treturn e.toolName === \"bash\";\n}\nexport function isReadToolResult(e: ToolResultEvent): e is ReadToolResultEvent {\n\treturn e.toolName === \"read\";\n}\nexport function isEditToolResult(e: ToolResultEvent): e is EditToolResultEvent {\n\treturn e.toolName === \"edit\";\n}\nexport function isWriteToolResult(e: ToolResultEvent): e is WriteToolResultEvent {\n\treturn e.toolName === \"write\";\n}\nexport function isGrepToolResult(e: ToolResultEvent): e is GrepToolResultEvent {\n\treturn e.toolName === \"grep\";\n}\nexport function isFindToolResult(e: ToolResultEvent): e is FindToolResultEvent {\n\treturn e.toolName === \"find\";\n}\nexport function isLsToolResult(e: ToolResultEvent): e is LsToolResultEvent {\n\treturn e.toolName === \"ls\";\n}\n\n/**\n * Type guard for narrowing ToolCallEvent by tool name.\n *\n * Built-in tools narrow automatically (no type params needed):\n * ```ts\n * if (isToolCallEventType(\"bash\", event)) {\n * event.input.command; // string\n * }\n * ```\n *\n * Custom tools require explicit type parameters:\n * ```ts\n * if (isToolCallEventType<\"my_tool\", MyToolInput>(\"my_tool\", event)) {\n * event.input.action; // typed\n * }\n * ```\n *\n * Note: Direct narrowing via `event.toolName === \"bash\"` doesn't work because\n * CustomToolCallEvent.toolName is `string` which overlaps with all literals.\n */\nexport function isToolCallEventType(toolName: \"bash\", event: ToolCallEvent): event is BashToolCallEvent;\nexport function isToolCallEventType(toolName: \"read\", event: ToolCallEvent): event is ReadToolCallEvent;\nexport function isToolCallEventType(toolName: \"edit\", event: ToolCallEvent): event is EditToolCallEvent;\nexport function isToolCallEventType(toolName: \"write\", event: ToolCallEvent): event is WriteToolCallEvent;\nexport function isToolCallEventType(toolName: \"grep\", event: ToolCallEvent): event is GrepToolCallEvent;\nexport function isToolCallEventType(toolName: \"find\", event: ToolCallEvent): event is FindToolCallEvent;\nexport function isToolCallEventType(toolName: \"ls\", event: ToolCallEvent): event is LsToolCallEvent;\nexport function isToolCallEventType<TName extends string, TInput extends Record<string, unknown>>(\n\ttoolName: TName,\n\tevent: ToolCallEvent,\n): event is ToolCallEvent & { toolName: TName; input: TInput };\nexport function isToolCallEventType(toolName: string, event: ToolCallEvent): boolean {\n\treturn event.toolName === toolName;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tool-events.d.ts","sourceRoot":"","sources":["../../../src/core/extensions/tool-events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,EACX,eAAe,EACf,aAAa,EACb,aAAa,EACb,eAAe,EACf,aAAa,EACb,aAAa,EACb,WAAW,EACX,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,MAAM,mBAAmB,CAAC;AAM3B,UAAU,iBAAiB;IAC1B,IAAI,EAAE,WAAW,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,iBAAkB,SAAQ,iBAAiB;IAC3D,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,aAAa,CAAC;CACrB;AAED,MAAM,WAAW,iBAAkB,SAAQ,iBAAiB;IAC3D,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,aAAa,CAAC;CACrB;AAED,MAAM,WAAW,iBAAkB,SAAQ,iBAA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,EAAE,MAAM,CAAA;CAAE,CAAC","sourcesContent":["import type { ImageContent, TextContent } from \"@earendil-works/pi-ai\";\nimport type { EditToolDetails } from \"../tools/edit.ts\";\nimport type {\n\tBashToolDetails,\n\tBashToolInput,\n\tEditToolInput,\n\tFindToolDetails,\n\tFindToolInput,\n\tLsToolDetails,\n\tLsToolInput,\n\tReadToolDetails,\n\tReadToolInput,\n\tSearchToolDetails,\n\tSearchToolInput,\n\tWriteToolInput,\n} from \"../tools/index.ts\";\n\n// ============================================================================\n// Tool Events\n// ============================================================================\n\ninterface ToolCallEventBase {\n\ttype: \"tool_call\";\n\ttoolCallId: string;\n}\n\nexport interface BashToolCallEvent extends ToolCallEventBase {\n\ttoolName: \"bash\";\n\tinput: BashToolInput;\n}\n\nexport interface ReadToolCallEvent extends ToolCallEventBase {\n\ttoolName: \"read\";\n\tinput: ReadToolInput;\n}\n\nexport interface EditToolCallEvent extends ToolCallEventBase {\n\ttoolName: \"edit\";\n\tinput: EditToolInput;\n}\n\nexport interface WriteToolCallEvent extends ToolCallEventBase {\n\ttoolName: \"write\";\n\tinput: WriteToolInput;\n}\n\nexport interface FindToolCallEvent extends ToolCallEventBase {\n\ttoolName: \"find\";\n\tinput: FindToolInput;\n}\n\nexport interface SearchToolCallEvent extends ToolCallEventBase {\n\ttoolName: \"search\";\n\tinput: SearchToolInput;\n}\n\nexport interface LsToolCallEvent extends ToolCallEventBase {\n\ttoolName: \"ls\";\n\tinput: LsToolInput;\n}\n\nexport interface CustomToolCallEvent extends ToolCallEventBase {\n\ttoolName: string;\n\tinput: Record<string, unknown>;\n}\n\n/**\n * Fired before a tool executes. Can block.\n *\n * `event.input` is mutable. Mutate it in place to patch tool arguments before execution.\n * Later `tool_call` handlers see earlier mutations. No re-validation is performed after mutation.\n */\nexport type ToolCallEvent =\n\t| BashToolCallEvent\n\t| ReadToolCallEvent\n\t| EditToolCallEvent\n\t| WriteToolCallEvent\n\t| FindToolCallEvent\n\t| SearchToolCallEvent\n\t| LsToolCallEvent\n\t| CustomToolCallEvent;\n\ninterface ToolResultEventBase {\n\ttype: \"tool_result\";\n\ttoolCallId: string;\n\tinput: Record<string, unknown>;\n\tcontent: (TextContent | ImageContent)[];\n\tisError: boolean;\n}\n\nexport interface BashToolResultEvent extends ToolResultEventBase {\n\ttoolName: \"bash\";\n\tdetails: BashToolDetails | undefined;\n}\n\nexport interface ReadToolResultEvent extends ToolResultEventBase {\n\ttoolName: \"read\";\n\tdetails: ReadToolDetails | undefined;\n}\n\nexport interface EditToolResultEvent extends ToolResultEventBase {\n\ttoolName: \"edit\";\n\tdetails: EditToolDetails | undefined;\n}\n\nexport interface WriteToolResultEvent extends ToolResultEventBase {\n\ttoolName: \"write\";\n\tdetails: undefined;\n}\n\nexport interface FindToolResultEvent extends ToolResultEventBase {\n\ttoolName: \"find\";\n\tdetails: FindToolDetails | undefined;\n}\n\nexport interface SearchToolResultEvent extends ToolResultEventBase {\n\ttoolName: \"search\";\n\tdetails: SearchToolDetails | undefined;\n}\n\nexport interface LsToolResultEvent extends ToolResultEventBase {\n\ttoolName: \"ls\";\n\tdetails: LsToolDetails | undefined;\n}\n\nexport interface CustomToolResultEvent extends ToolResultEventBase {\n\ttoolName: string;\n\tdetails: unknown;\n}\n\n/** Fired after a tool executes. Can modify result. */\nexport type ToolResultEvent =\n\t| BashToolResultEvent\n\t| ReadToolResultEvent\n\t| EditToolResultEvent\n\t| WriteToolResultEvent\n\t| FindToolResultEvent\n\t| SearchToolResultEvent\n\t| LsToolResultEvent\n\t| CustomToolResultEvent;\n\n// Type guards for ToolResultEvent\nexport function isBashToolResult(e: ToolResultEvent): e is BashToolResultEvent {\n\treturn e.toolName === \"bash\";\n}\nexport function isReadToolResult(e: ToolResultEvent): e is ReadToolResultEvent {\n\treturn e.toolName === \"read\";\n}\nexport function isEditToolResult(e: ToolResultEvent): e is EditToolResultEvent {\n\treturn e.toolName === \"edit\";\n}\nexport function isWriteToolResult(e: ToolResultEvent): e is WriteToolResultEvent {\n\treturn e.toolName === \"write\";\n}\nexport function isFindToolResult(e: ToolResultEvent): e is FindToolResultEvent {\n\treturn e.toolName === \"find\";\n}\nexport function isSearchToolResult(e: ToolResultEvent): e is SearchToolResultEvent {\n\treturn e.toolName === \"search\";\n}\nexport function isLsToolResult(e: ToolResultEvent): e is LsToolResultEvent {\n\treturn e.toolName === \"ls\";\n}\n\n/**\n * Type guard for narrowing ToolCallEvent by tool name.\n *\n * Built-in tools narrow automatically (no type params needed):\n * ```ts\n * if (isToolCallEventType(\"bash\", event)) {\n * event.input.command; // string\n * }\n * ```\n *\n * Custom tools require explicit type parameters:\n * ```ts\n * if (isToolCallEventType<\"my_tool\", MyToolInput>(\"my_tool\", event)) {\n * event.input.action; // typed\n * }\n * ```\n *\n * Note: Direct narrowing via `event.toolName === \"bash\"` doesn't work because\n * CustomToolCallEvent.toolName is `string` which overlaps with all literals.\n */\nexport function isToolCallEventType(toolName: \"bash\", event: ToolCallEvent): event is BashToolCallEvent;\nexport function isToolCallEventType(toolName: \"read\", event: ToolCallEvent): event is ReadToolCallEvent;\nexport function isToolCallEventType(toolName: \"edit\", event: ToolCallEvent): event is EditToolCallEvent;\nexport function isToolCallEventType(toolName: \"write\", event: ToolCallEvent): event is WriteToolCallEvent;\nexport function isToolCallEventType(toolName: \"find\", event: ToolCallEvent): event is FindToolCallEvent;\nexport function isToolCallEventType(toolName: \"search\", event: ToolCallEvent): event is SearchToolCallEvent;\nexport function isToolCallEventType(toolName: \"ls\", event: ToolCallEvent): event is LsToolCallEvent;\nexport function isToolCallEventType<TName extends string, TInput extends Record<string, unknown>>(\n\ttoolName: TName,\n\tevent: ToolCallEvent,\n): event is ToolCallEvent & { toolName: TName; input: TInput };\nexport function isToolCallEventType(toolName: string, event: ToolCallEvent): boolean {\n\treturn event.toolName === toolName;\n}\n"]}
|
|
@@ -11,12 +11,12 @@ export function isEditToolResult(e) {
|
|
|
11
11
|
export function isWriteToolResult(e) {
|
|
12
12
|
return e.toolName === "write";
|
|
13
13
|
}
|
|
14
|
-
export function isGrepToolResult(e) {
|
|
15
|
-
return e.toolName === "grep";
|
|
16
|
-
}
|
|
17
14
|
export function isFindToolResult(e) {
|
|
18
15
|
return e.toolName === "find";
|
|
19
16
|
}
|
|
17
|
+
export function isSearchToolResult(e) {
|
|
18
|
+
return e.toolName === "search";
|
|
19
|
+
}
|
|
20
20
|
export function isLsToolResult(e) {
|
|
21
21
|
return e.toolName === "ls";
|
|
22
22
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-events.js","sourceRoot":"","sources":["../../../src/core/extensions/tool-events.ts"],"names":[],"mappings":"AA6IA,kCAAkC;AAClC,MAAM,UAAU,gBAAgB,CAAC,CAAkB;IAClD,OAAO,CAAC,CAAC,QAAQ,KAAK,MAAM,CAAC;AAC9B,CAAC;AACD,MAAM,UAAU,gBAAgB,CAAC,CAAkB;IAClD,OAAO,CAAC,CAAC,QAAQ,KAAK,MAAM,CAAC;AAC9B,CAAC;AACD,MAAM,UAAU,gBAAgB,CAAC,CAAkB;IAClD,OAAO,CAAC,CAAC,QAAQ,KAAK,MAAM,CAAC;AAC9B,CAAC;AACD,MAAM,UAAU,iBAAiB,CAAC,CAAkB;IACnD,OAAO,CAAC,CAAC,QAAQ,KAAK,OAAO,CAAC;AAC/B,CAAC;AACD,MAAM,UAAU,gBAAgB,CAAC,CAAkB;IAClD,OAAO,CAAC,CAAC,QAAQ,KAAK,MAAM,CAAC;AAC9B,CAAC;AACD,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"tool-events.js","sourceRoot":"","sources":["../../../src/core/extensions/tool-events.ts"],"names":[],"mappings":"AA6IA,kCAAkC;AAClC,MAAM,UAAU,gBAAgB,CAAC,CAAkB;IAClD,OAAO,CAAC,CAAC,QAAQ,KAAK,MAAM,CAAC;AAC9B,CAAC;AACD,MAAM,UAAU,gBAAgB,CAAC,CAAkB;IAClD,OAAO,CAAC,CAAC,QAAQ,KAAK,MAAM,CAAC;AAC9B,CAAC;AACD,MAAM,UAAU,gBAAgB,CAAC,CAAkB;IAClD,OAAO,CAAC,CAAC,QAAQ,KAAK,MAAM,CAAC;AAC9B,CAAC;AACD,MAAM,UAAU,iBAAiB,CAAC,CAAkB;IACnD,OAAO,CAAC,CAAC,QAAQ,KAAK,OAAO,CAAC;AAC/B,CAAC;AACD,MAAM,UAAU,gBAAgB,CAAC,CAAkB;IAClD,OAAO,CAAC,CAAC,QAAQ,KAAK,MAAM,CAAC;AAC9B,CAAC;AACD,MAAM,UAAU,kBAAkB,CAAC,CAAkB;IACpD,OAAO,CAAC,CAAC,QAAQ,KAAK,QAAQ,CAAC;AAChC,CAAC;AACD,MAAM,UAAU,cAAc,CAAC,CAAkB;IAChD,OAAO,CAAC,CAAC,QAAQ,KAAK,IAAI,CAAC;AAC5B,CAAC;AAiCD,MAAM,UAAU,mBAAmB,CAAC,QAAgB,EAAE,KAAoB;IACzE,OAAO,KAAK,CAAC,QAAQ,KAAK,QAAQ,CAAC;AACpC,CAAC","sourcesContent":["import type { ImageContent, TextContent } from \"@earendil-works/pi-ai\";\nimport type { EditToolDetails } from \"../tools/edit.ts\";\nimport type {\n\tBashToolDetails,\n\tBashToolInput,\n\tEditToolInput,\n\tFindToolDetails,\n\tFindToolInput,\n\tLsToolDetails,\n\tLsToolInput,\n\tReadToolDetails,\n\tReadToolInput,\n\tSearchToolDetails,\n\tSearchToolInput,\n\tWriteToolInput,\n} from \"../tools/index.ts\";\n\n// ============================================================================\n// Tool Events\n// ============================================================================\n\ninterface ToolCallEventBase {\n\ttype: \"tool_call\";\n\ttoolCallId: string;\n}\n\nexport interface BashToolCallEvent extends ToolCallEventBase {\n\ttoolName: \"bash\";\n\tinput: BashToolInput;\n}\n\nexport interface ReadToolCallEvent extends ToolCallEventBase {\n\ttoolName: \"read\";\n\tinput: ReadToolInput;\n}\n\nexport interface EditToolCallEvent extends ToolCallEventBase {\n\ttoolName: \"edit\";\n\tinput: EditToolInput;\n}\n\nexport interface WriteToolCallEvent extends ToolCallEventBase {\n\ttoolName: \"write\";\n\tinput: WriteToolInput;\n}\n\nexport interface FindToolCallEvent extends ToolCallEventBase {\n\ttoolName: \"find\";\n\tinput: FindToolInput;\n}\n\nexport interface SearchToolCallEvent extends ToolCallEventBase {\n\ttoolName: \"search\";\n\tinput: SearchToolInput;\n}\n\nexport interface LsToolCallEvent extends ToolCallEventBase {\n\ttoolName: \"ls\";\n\tinput: LsToolInput;\n}\n\nexport interface CustomToolCallEvent extends ToolCallEventBase {\n\ttoolName: string;\n\tinput: Record<string, unknown>;\n}\n\n/**\n * Fired before a tool executes. Can block.\n *\n * `event.input` is mutable. Mutate it in place to patch tool arguments before execution.\n * Later `tool_call` handlers see earlier mutations. No re-validation is performed after mutation.\n */\nexport type ToolCallEvent =\n\t| BashToolCallEvent\n\t| ReadToolCallEvent\n\t| EditToolCallEvent\n\t| WriteToolCallEvent\n\t| FindToolCallEvent\n\t| SearchToolCallEvent\n\t| LsToolCallEvent\n\t| CustomToolCallEvent;\n\ninterface ToolResultEventBase {\n\ttype: \"tool_result\";\n\ttoolCallId: string;\n\tinput: Record<string, unknown>;\n\tcontent: (TextContent | ImageContent)[];\n\tisError: boolean;\n}\n\nexport interface BashToolResultEvent extends ToolResultEventBase {\n\ttoolName: \"bash\";\n\tdetails: BashToolDetails | undefined;\n}\n\nexport interface ReadToolResultEvent extends ToolResultEventBase {\n\ttoolName: \"read\";\n\tdetails: ReadToolDetails | undefined;\n}\n\nexport interface EditToolResultEvent extends ToolResultEventBase {\n\ttoolName: \"edit\";\n\tdetails: EditToolDetails | undefined;\n}\n\nexport interface WriteToolResultEvent extends ToolResultEventBase {\n\ttoolName: \"write\";\n\tdetails: undefined;\n}\n\nexport interface FindToolResultEvent extends ToolResultEventBase {\n\ttoolName: \"find\";\n\tdetails: FindToolDetails | undefined;\n}\n\nexport interface SearchToolResultEvent extends ToolResultEventBase {\n\ttoolName: \"search\";\n\tdetails: SearchToolDetails | undefined;\n}\n\nexport interface LsToolResultEvent extends ToolResultEventBase {\n\ttoolName: \"ls\";\n\tdetails: LsToolDetails | undefined;\n}\n\nexport interface CustomToolResultEvent extends ToolResultEventBase {\n\ttoolName: string;\n\tdetails: unknown;\n}\n\n/** Fired after a tool executes. Can modify result. */\nexport type ToolResultEvent =\n\t| BashToolResultEvent\n\t| ReadToolResultEvent\n\t| EditToolResultEvent\n\t| WriteToolResultEvent\n\t| FindToolResultEvent\n\t| SearchToolResultEvent\n\t| LsToolResultEvent\n\t| CustomToolResultEvent;\n\n// Type guards for ToolResultEvent\nexport function isBashToolResult(e: ToolResultEvent): e is BashToolResultEvent {\n\treturn e.toolName === \"bash\";\n}\nexport function isReadToolResult(e: ToolResultEvent): e is ReadToolResultEvent {\n\treturn e.toolName === \"read\";\n}\nexport function isEditToolResult(e: ToolResultEvent): e is EditToolResultEvent {\n\treturn e.toolName === \"edit\";\n}\nexport function isWriteToolResult(e: ToolResultEvent): e is WriteToolResultEvent {\n\treturn e.toolName === \"write\";\n}\nexport function isFindToolResult(e: ToolResultEvent): e is FindToolResultEvent {\n\treturn e.toolName === \"find\";\n}\nexport function isSearchToolResult(e: ToolResultEvent): e is SearchToolResultEvent {\n\treturn e.toolName === \"search\";\n}\nexport function isLsToolResult(e: ToolResultEvent): e is LsToolResultEvent {\n\treturn e.toolName === \"ls\";\n}\n\n/**\n * Type guard for narrowing ToolCallEvent by tool name.\n *\n * Built-in tools narrow automatically (no type params needed):\n * ```ts\n * if (isToolCallEventType(\"bash\", event)) {\n * event.input.command; // string\n * }\n * ```\n *\n * Custom tools require explicit type parameters:\n * ```ts\n * if (isToolCallEventType<\"my_tool\", MyToolInput>(\"my_tool\", event)) {\n * event.input.action; // typed\n * }\n * ```\n *\n * Note: Direct narrowing via `event.toolName === \"bash\"` doesn't work because\n * CustomToolCallEvent.toolName is `string` which overlaps with all literals.\n */\nexport function isToolCallEventType(toolName: \"bash\", event: ToolCallEvent): event is BashToolCallEvent;\nexport function isToolCallEventType(toolName: \"read\", event: ToolCallEvent): event is ReadToolCallEvent;\nexport function isToolCallEventType(toolName: \"edit\", event: ToolCallEvent): event is EditToolCallEvent;\nexport function isToolCallEventType(toolName: \"write\", event: ToolCallEvent): event is WriteToolCallEvent;\nexport function isToolCallEventType(toolName: \"find\", event: ToolCallEvent): event is FindToolCallEvent;\nexport function isToolCallEventType(toolName: \"search\", event: ToolCallEvent): event is SearchToolCallEvent;\nexport function isToolCallEventType(toolName: \"ls\", event: ToolCallEvent): event is LsToolCallEvent;\nexport function isToolCallEventType<TName extends string, TInput extends Record<string, unknown>>(\n\ttoolName: TName,\n\tevent: ToolCallEvent,\n): event is ToolCallEvent & { toolName: TName; input: TInput };\nexport function isToolCallEventType(toolName: string, event: ToolCallEvent): boolean {\n\treturn event.toolName === toolName;\n}\n"]}
|
|
@@ -28,5 +28,5 @@ export type * from "./tool-events.ts";
|
|
|
28
28
|
export type * from "./tool-types.ts";
|
|
29
29
|
export type * from "./ui-types.ts";
|
|
30
30
|
export { defineTool } from "./tool-types.ts";
|
|
31
|
-
export { isBashToolResult, isEditToolResult, isFindToolResult,
|
|
31
|
+
export { isBashToolResult, isEditToolResult, isFindToolResult, isLsToolResult, isSearchToolResult, isReadToolResult, isToolCallEventType, isWriteToolResult, } from "./tool-events.ts";
|
|
32
32
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/extensions/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,YAAY,EAAE,eAAe,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AACjH,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC1D,YAAY,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC3E,YAAY,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AACpE,mBAAmB,mBAAmB,CA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MAAM,iBAAiB,CAAC;AAC7C,OAAO,EACN,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,GACjB,MAAM,kBAAkB,CAAC","sourcesContent":["/**\n * Extension system types.\n *\n * Extensions are TypeScript modules that can:\n * - Subscribe to agent lifecycle events\n * - Register LLM-callable tools\n * - Register commands, keyboard shortcuts, and CLI flags\n * - Interact with the user via UI primitives\n *\n * This file preserves the public import path for extension authors while the\n * declarations live in responsibility-focused sibling modules.\n */\n\nexport type { AgentToolResult, AgentToolUpdateCallback, ToolExecutionMode } from \"@earendil-works/pi-agent-core\";\nexport type { ExecOptions, ExecResult } from \"../exec.ts\";\nexport type { AppKeybinding, KeybindingsManager } from \"../keybindings.ts\";\nexport type { BuildSystemPromptOptions } from \"../system-prompt.ts\";\nexport type * from \"./agent-events.ts\";\nexport type * from \"./api-types.ts\";\nexport type * from \"./command-types.ts\";\nexport type * from \"./context-types.ts\";\nexport type * from \"./event-results.ts\";\nexport type * from \"./event-types.ts\";\nexport type * from \"./message-types.ts\";\nexport type * from \"./provider-types.ts\";\nexport type * from \"./runtime-types.ts\";\nexport type * from \"./session-events.ts\";\nexport type * from \"./tool-events.ts\";\nexport type * from \"./tool-types.ts\";\nexport type * from \"./ui-types.ts\";\n\nexport { defineTool } from \"./tool-types.ts\";\nexport {\n\tisBashToolResult,\n\tisEditToolResult,\n\tisFindToolResult,\n\tisLsToolResult,\n\tisSearchToolResult,\n\tisReadToolResult,\n\tisToolCallEventType,\n\tisWriteToolResult,\n} from \"./tool-events.ts\";\n"]}
|
|
@@ -11,5 +11,5 @@
|
|
|
11
11
|
* declarations live in responsibility-focused sibling modules.
|
|
12
12
|
*/
|
|
13
13
|
export { defineTool } from "./tool-types.js";
|
|
14
|
-
export { isBashToolResult, isEditToolResult, isFindToolResult,
|
|
14
|
+
export { isBashToolResult, isEditToolResult, isFindToolResult, isLsToolResult, isSearchToolResult, isReadToolResult, isToolCallEventType, isWriteToolResult, } from "./tool-events.js";
|
|
15
15
|
//# sourceMappingURL=types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/extensions/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAoBH,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EACN,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/extensions/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAoBH,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EACN,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,GACjB,MAAM,kBAAkB,CAAC","sourcesContent":["/**\n * Extension system types.\n *\n * Extensions are TypeScript modules that can:\n * - Subscribe to agent lifecycle events\n * - Register LLM-callable tools\n * - Register commands, keyboard shortcuts, and CLI flags\n * - Interact with the user via UI primitives\n *\n * This file preserves the public import path for extension authors while the\n * declarations live in responsibility-focused sibling modules.\n */\n\nexport type { AgentToolResult, AgentToolUpdateCallback, ToolExecutionMode } from \"@earendil-works/pi-agent-core\";\nexport type { ExecOptions, ExecResult } from \"../exec.ts\";\nexport type { AppKeybinding, KeybindingsManager } from \"../keybindings.ts\";\nexport type { BuildSystemPromptOptions } from \"../system-prompt.ts\";\nexport type * from \"./agent-events.ts\";\nexport type * from \"./api-types.ts\";\nexport type * from \"./command-types.ts\";\nexport type * from \"./context-types.ts\";\nexport type * from \"./event-results.ts\";\nexport type * from \"./event-types.ts\";\nexport type * from \"./message-types.ts\";\nexport type * from \"./provider-types.ts\";\nexport type * from \"./runtime-types.ts\";\nexport type * from \"./session-events.ts\";\nexport type * from \"./tool-events.ts\";\nexport type * from \"./tool-types.ts\";\nexport type * from \"./ui-types.ts\";\n\nexport { defineTool } from \"./tool-types.ts\";\nexport {\n\tisBashToolResult,\n\tisEditToolResult,\n\tisFindToolResult,\n\tisLsToolResult,\n\tisSearchToolResult,\n\tisReadToolResult,\n\tisToolCallEventType,\n\tisWriteToolResult,\n} from \"./tool-events.ts\";\n"]}
|
|
@@ -38,4 +38,22 @@ export declare function parseFlattenedKeyPath(key: string): Array<string | numbe
|
|
|
38
38
|
* plain key equal to one of those names.
|
|
39
39
|
*/
|
|
40
40
|
export declare function reconstructFlattenedKeys(args: Record<string, unknown>, shouldSplit: (key: string) => boolean): Record<string, unknown>;
|
|
41
|
+
/**
|
|
42
|
+
* Reconstruct flattened tool-call arguments into nested arrays/objects using
|
|
43
|
+
* schema-aware disambiguation for dotted keys.
|
|
44
|
+
*
|
|
45
|
+
* - Bracket-indexed keys (`ids[0]`, `files[0].path`) are always reconstructed.
|
|
46
|
+
* - Purely dotted keys (`parent.child`) are reconstructed only when the optional
|
|
47
|
+
* `schema` marks their head segment as an object/array container property.
|
|
48
|
+
* The presence of a bracket-indexed sibling does NOT force a pure dotted key
|
|
49
|
+
* to split, so a literal property name such as `filter.name` survives intact
|
|
50
|
+
* even when a sibling like `ids[0]` is present (issue #1496).
|
|
51
|
+
* - Otherwise dotted keys are preserved verbatim — fixing the regression where a
|
|
52
|
+
* literal property name like `filter.name` was silently corrupted.
|
|
53
|
+
*
|
|
54
|
+
* Returns the original reference unchanged when there is nothing to
|
|
55
|
+
* reconstruct. Prototype-pollution safety is delegated to
|
|
56
|
+
* {@link reconstructFlattenedKeys}.
|
|
57
|
+
*/
|
|
58
|
+
export declare function unflattenArgumentsWithSchema(args: Record<string, unknown>, schema?: unknown): Record<string, unknown>;
|
|
41
59
|
//# sourceMappingURL=flattened-tool-arguments.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flattened-tool-arguments.d.ts","sourceRoot":"","sources":["../../src/core/flattened-tool-arguments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AASH;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,SAAS,CAmCrF;AA0CD;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,WAAW,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,GACpC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAazB","sourcesContent":["/**\n * Canonical reconstruction of flattened tool-call arguments.\n *\n * Some upstream providers — notably GitHub Copilot Gemini models proxied through\n * Google's GenAI API — serialize array/object function-call arguments as\n * flattened, indexed keys on the wire. For example a tool called with\n * `{ keywords: [\"a\", \"b\"] }` arrives as `{ \"keywords[0]\": \"a\", \"keywords[1]\": \"b\" }`,\n * and `{ files: [{ path }] }` as `{ \"files[0].path\": \"...\" }`.\n *\n * This module is the single source of truth for turning those flattened keys\n * back into nested arrays/objects. Both the host runtime's per-tool\n * normalization (gated to Copilot Gemini, schema-aware) and the MCP `callTool`\n * boundary (provider-agnostic, bracket self-gating) delegate here so the two\n * paths cannot drift — in particular so the prototype-pollution guard lives in\n * exactly one place.\n *\n * Security: argument keys cross a trust boundary (model/provider wire → tool /\n * MCP server validation). A key path that walks through `__proto__`,\n * `constructor`, or `prototype` could otherwise reach `Object.prototype` and\n * mutate it process-wide. Any key whose path contains such a segment — at any\n * position, including the final segment and a literal plain key — is dropped.\n */\n\n/** Key segments that must never be written or traversed (prototype pollution). */\nconst UNSAFE_KEY_SEGMENTS: ReadonlySet<string> = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\nfunction isUnsafeSegment(segment: string | number): boolean {\n return typeof segment === \"string\" && UNSAFE_KEY_SEGMENTS.has(segment);\n}\n\n/**\n * Parse a flattened key such as `a.b[0].c` into path segments\n * `[\"a\", \"b\", 0, \"c\"]`. Returns `undefined` for a plain key with no `.`/`[`, or\n * for a malformed bracket expression (left untouched by the caller).\n */\nexport function parseFlattenedKeyPath(key: string): Array<string | number> | undefined {\n if (!/[.[]/.test(key)) return undefined;\n const segments: Array<string | number> = [];\n let current = \"\";\n let index = 0;\n const flush = () => {\n if (current !== \"\") {\n segments.push(current);\n current = \"\";\n }\n };\n while (index < key.length) {\n const char = key[index];\n if (char === \".\") {\n flush();\n index += 1;\n } else if (char === \"[\") {\n flush();\n const end = key.indexOf(\"]\", index);\n if (end === -1) return undefined; // malformed — leave key untouched\n const inner = key.slice(index + 1, end);\n const numeric = Number(inner);\n if (inner.trim() !== \"\" && Number.isInteger(numeric) && numeric >= 0) {\n segments.push(numeric);\n } else {\n segments.push(inner.replace(/^[\"']|[\"']$/g, \"\"));\n }\n index = end + 1;\n } else {\n current += char;\n index += 1;\n }\n }\n flush();\n return segments.length > 0 ? segments : undefined;\n}\n\n/** Assign `value` at the given path inside `root`, creating arrays/objects as needed. */\nfunction assignFlattenedKeyPath(\n root: Record<string | number, unknown>,\n segments: Array<string | number>,\n value: unknown,\n): void {\n let node: Record<string | number, unknown> = root;\n for (let i = 0; i < segments.length - 1; i += 1) {\n const segment = segments[i];\n const nextIsIndex = typeof segments[i + 1] === \"number\";\n const existing = node[segment];\n if (existing === null || existing === undefined || typeof existing !== \"object\") {\n node[segment] = nextIsIndex ? [] : {};\n }\n node = node[segment] as Record<string | number, unknown>;\n }\n node[segments[segments.length - 1]] = value;\n}\n\n/**\n * Remove empty holes from sparse arrays produced by out-of-order indices.\n *\n * Note: this collapses holes rather than preserving them — `name[0]` + `name[2]`\n * (no index 1) becomes a dense 2-element array `[a, c]`, not `[a, <hole>, c]`.\n * That is the intended healing for Gemini's flattened output (which emits\n * contiguous indices in practice); it would, however, silently misalign two\n * arrays that were meant to be index-paired.\n */\nfunction compactSparseArrays(value: unknown): unknown {\n if (Array.isArray(value)) {\n return value.filter((entry) => entry !== undefined).map((entry) => compactSparseArrays(entry));\n }\n if (value !== null && typeof value === \"object\") {\n const out: Record<string, unknown> = {};\n for (const [key, entry] of Object.entries(value)) out[key] = compactSparseArrays(entry);\n return out;\n }\n return value;\n}\n\n/**\n * Reconstruct (unflatten) flattened keys into nested arrays/objects — for\n * example `\"items[0]\"` -> `{ items: [...] }` and `\"parent.child\"` ->\n * `{ parent: { child: ... } }`. `shouldSplit` decides, per key, whether it is a\n * flattened path (true) or an opaque literal key to be preserved (false);\n * callers apply their own gating/schema logic there.\n *\n * Prototype-pollution safe: a key whose parsed path contains `__proto__`,\n * `constructor`, or `prototype` (at any position) is dropped, as is a literal\n * plain key equal to one of those names.\n */\nexport function reconstructFlattenedKeys(\n args: Record<string, unknown>,\n shouldSplit: (key: string) => boolean,\n): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(args)) {\n const segments = shouldSplit(key) ? parseFlattenedKeyPath(key) : undefined;\n if (!segments) {\n // Plain passthrough — but never assign a literal prototype-polluting key.\n if (!UNSAFE_KEY_SEGMENTS.has(key)) result[key] = value;\n continue;\n }\n if (segments.some(isUnsafeSegment)) continue; // drop a polluting path entirely\n assignFlattenedKeyPath(result, segments, value);\n }\n return compactSparseArrays(result) as Record<string, unknown>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"flattened-tool-arguments.d.ts","sourceRoot":"","sources":["../../src/core/flattened-tool-arguments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AASH;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,SAAS,CAmCrF;AA0CD;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,WAAW,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,GACpC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAazB;AAyFD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,4BAA4B,CAC1C,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,MAAM,CAAC,EAAE,OAAO,GACf,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAYzB","sourcesContent":["/**\n * Canonical reconstruction of flattened tool-call arguments.\n *\n * Some upstream providers — notably GitHub Copilot Gemini models proxied through\n * Google's GenAI API — serialize array/object function-call arguments as\n * flattened, indexed keys on the wire. For example a tool called with\n * `{ keywords: [\"a\", \"b\"] }` arrives as `{ \"keywords[0]\": \"a\", \"keywords[1]\": \"b\" }`,\n * and `{ files: [{ path }] }` as `{ \"files[0].path\": \"...\" }`.\n *\n * This module is the single source of truth for turning those flattened keys\n * back into nested arrays/objects. Both the host runtime's per-tool\n * normalization (gated to Copilot Gemini, schema-aware) and the MCP `callTool`\n * boundary (provider-agnostic, bracket self-gating) delegate here so the two\n * paths cannot drift — in particular so the prototype-pollution guard lives in\n * exactly one place.\n *\n * Security: argument keys cross a trust boundary (model/provider wire → tool /\n * MCP server validation). A key path that walks through `__proto__`,\n * `constructor`, or `prototype` could otherwise reach `Object.prototype` and\n * mutate it process-wide. Any key whose path contains such a segment — at any\n * position, including the final segment and a literal plain key — is dropped.\n */\n\n/** Key segments that must never be written or traversed (prototype pollution). */\nconst UNSAFE_KEY_SEGMENTS: ReadonlySet<string> = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\nfunction isUnsafeSegment(segment: string | number): boolean {\n return typeof segment === \"string\" && UNSAFE_KEY_SEGMENTS.has(segment);\n}\n\n/**\n * Parse a flattened key such as `a.b[0].c` into path segments\n * `[\"a\", \"b\", 0, \"c\"]`. Returns `undefined` for a plain key with no `.`/`[`, or\n * for a malformed bracket expression (left untouched by the caller).\n */\nexport function parseFlattenedKeyPath(key: string): Array<string | number> | undefined {\n if (!/[.[]/.test(key)) return undefined;\n const segments: Array<string | number> = [];\n let current = \"\";\n let index = 0;\n const flush = () => {\n if (current !== \"\") {\n segments.push(current);\n current = \"\";\n }\n };\n while (index < key.length) {\n const char = key[index];\n if (char === \".\") {\n flush();\n index += 1;\n } else if (char === \"[\") {\n flush();\n const end = key.indexOf(\"]\", index);\n if (end === -1) return undefined; // malformed — leave key untouched\n const inner = key.slice(index + 1, end);\n const numeric = Number(inner);\n if (inner.trim() !== \"\" && Number.isInteger(numeric) && numeric >= 0) {\n segments.push(numeric);\n } else {\n segments.push(inner.replace(/^[\"']|[\"']$/g, \"\"));\n }\n index = end + 1;\n } else {\n current += char;\n index += 1;\n }\n }\n flush();\n return segments.length > 0 ? segments : undefined;\n}\n\n/** Assign `value` at the given path inside `root`, creating arrays/objects as needed. */\nfunction assignFlattenedKeyPath(\n root: Record<string | number, unknown>,\n segments: Array<string | number>,\n value: unknown,\n): void {\n let node: Record<string | number, unknown> = root;\n for (let i = 0; i < segments.length - 1; i += 1) {\n const segment = segments[i];\n const nextIsIndex = typeof segments[i + 1] === \"number\";\n const existing = node[segment];\n if (existing === null || existing === undefined || typeof existing !== \"object\") {\n node[segment] = nextIsIndex ? [] : {};\n }\n node = node[segment] as Record<string | number, unknown>;\n }\n node[segments[segments.length - 1]] = value;\n}\n\n/**\n * Remove empty holes from sparse arrays produced by out-of-order indices.\n *\n * Note: this collapses holes rather than preserving them — `name[0]` + `name[2]`\n * (no index 1) becomes a dense 2-element array `[a, c]`, not `[a, <hole>, c]`.\n * That is the intended healing for Gemini's flattened output (which emits\n * contiguous indices in practice); it would, however, silently misalign two\n * arrays that were meant to be index-paired.\n */\nfunction compactSparseArrays(value: unknown): unknown {\n if (Array.isArray(value)) {\n return value.filter((entry) => entry !== undefined).map((entry) => compactSparseArrays(entry));\n }\n if (value !== null && typeof value === \"object\") {\n const out: Record<string, unknown> = {};\n for (const [key, entry] of Object.entries(value)) out[key] = compactSparseArrays(entry);\n return out;\n }\n return value;\n}\n\n/**\n * Reconstruct (unflatten) flattened keys into nested arrays/objects — for\n * example `\"items[0]\"` -> `{ items: [...] }` and `\"parent.child\"` ->\n * `{ parent: { child: ... } }`. `shouldSplit` decides, per key, whether it is a\n * flattened path (true) or an opaque literal key to be preserved (false);\n * callers apply their own gating/schema logic there.\n *\n * Prototype-pollution safe: a key whose parsed path contains `__proto__`,\n * `constructor`, or `prototype` (at any position) is dropped, as is a literal\n * plain key equal to one of those names.\n */\nexport function reconstructFlattenedKeys(\n args: Record<string, unknown>,\n shouldSplit: (key: string) => boolean,\n): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(args)) {\n const segments = shouldSplit(key) ? parseFlattenedKeyPath(key) : undefined;\n if (!segments) {\n // Plain passthrough — but never assign a literal prototype-polluting key.\n if (!UNSAFE_KEY_SEGMENTS.has(key)) result[key] = value;\n continue;\n }\n if (segments.some(isUnsafeSegment)) continue; // drop a polluting path entirely\n assignFlattenedKeyPath(result, segments, value);\n }\n return compactSparseArrays(result) as Record<string, unknown>;\n}\n\n// ---------------------------------------------------------------------------\n// Schema-aware unflattening\n// ---------------------------------------------------------------------------\n//\n// A flattened key with a bracket index (`foo[0]`) is unambiguous and is always\n// reconstructed. A purely dotted key (`parent.child`) is ambiguous: it could be\n// a real nested path *or* a legitimate argument whose name literally contains\n// a dot (for example an MCP tool whose JSON Schema declares a property named\n// `filter.name`). To avoid corrupting such literal dotted keys, a dotted key is\n// only split when the tool's `inputSchema` proves its head segment is an\n// object/array container property. The presence of a bracket-indexed sibling\n// does NOT force a pure dotted key to split — the two are decided per key, so\n// a literal property such as `filter.name` survives intact even when a bracket\n// sibling like `ids[0]` is present (issue #1496). Callers that only want the\n// unambiguous bracket case can omit the schema.\n\ntype JsonRecord = Record<string, unknown>;\n\nfunction isPlainObject(value: unknown): value is JsonRecord {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/** A flattened key contains a bracket index like `foo[0]`. */\nfunction hasBracketIndex(key: string): boolean {\n return /\\[\\d+\\]/.test(key);\n}\n\n/** A schema node that holds a nested object/array (so dotted keys are real paths). */\nfunction isContainerSchema(schema: unknown): boolean {\n if (!isPlainObject(schema)) return false;\n if (schema.type === \"object\" || schema.type === \"array\") return true;\n if (\"properties\" in schema || \"items\" in schema) return true;\n const union = schema.anyOf ?? schema.oneOf;\n if (Array.isArray(union)) return union.some((branch) => isContainerSchema(branch));\n return false;\n}\n\n/** Exact top-level `schema.properties` names (literal property keys). */\nfunction literalPropertyNames(schema: unknown): Set<string> {\n const names = new Set<string>();\n if (!isPlainObject(schema)) return names;\n const properties = schema.properties;\n if (!isPlainObject(properties)) return names;\n for (const name of Object.keys(properties)) names.add(name);\n return names;\n}\n\n/** Top-level property names whose schema is an object/array container. */\nfunction containerPropertyNames(schema: unknown): Set<string> {\n const names = new Set<string>();\n if (!isPlainObject(schema)) return names;\n const properties = schema.properties;\n if (!isPlainObject(properties)) return names;\n for (const [name, sub] of Object.entries(properties)) {\n if (isContainerSchema(sub)) names.add(name);\n }\n return names;\n}\n\n/** Whether `key` is a pure dotted path (`parent.child`) headed by a container prop. */\nfunction isDottedContainerKey(key: string, containers: Set<string>): boolean {\n const dot = key.indexOf(\".\");\n if (dot <= 0) return false;\n return containers.has(key.slice(0, dot));\n}\n\n/**\n * Decide whether a flattened key should be split into nested path segments.\n *\n * - Bracket-indexed keys (`foo[0]`, `foo[0].bar`) always split: they are\n * unambiguous evidence of provider flattening.\n * - Purely dotted keys (`parent.child`) split only when the schema marks their\n * head segment as an object/array container property AND the schema does not\n * declare the full key as a literal top-level property. The latter guard\n * protects a schema that intentionally defines both a literal dotted property\n * (e.g. `filter.name`) and a same-head container (e.g. `filter`): the literal\n * property wins and is preserved verbatim (reviewer-b P2, issue #1496). The\n * presence of a bracket-indexed sibling does NOT force a pure dotted key to\n * split, so a literal property name such as `filter.name` is preserved\n * verbatim even when a sibling like `ids[0]` is reconstructed.\n */\nfunction shouldSplitKey(key: string, containers: Set<string>, literals: Set<string>): boolean {\n if (hasBracketIndex(key)) return true;\n if (literals.has(key)) return false; // explicit literal property wins\n return isDottedContainerKey(key, containers);\n}\n\n/**\n * Reconstruct flattened tool-call arguments into nested arrays/objects using\n * schema-aware disambiguation for dotted keys.\n *\n * - Bracket-indexed keys (`ids[0]`, `files[0].path`) are always reconstructed.\n * - Purely dotted keys (`parent.child`) are reconstructed only when the optional\n * `schema` marks their head segment as an object/array container property.\n * The presence of a bracket-indexed sibling does NOT force a pure dotted key\n * to split, so a literal property name such as `filter.name` survives intact\n * even when a sibling like `ids[0]` is present (issue #1496).\n * - Otherwise dotted keys are preserved verbatim — fixing the regression where a\n * literal property name like `filter.name` was silently corrupted.\n *\n * Returns the original reference unchanged when there is nothing to\n * reconstruct. Prototype-pollution safety is delegated to\n * {@link reconstructFlattenedKeys}.\n */\nexport function unflattenArgumentsWithSchema(\n args: Record<string, unknown>,\n schema?: unknown,\n): Record<string, unknown> {\n const keys = Object.keys(args);\n const literals = literalPropertyNames(schema);\n const containers = containerPropertyNames(schema);\n const hasBracket = keys.some((key) => hasBracketIndex(key));\n // A dotted key needs splitting only if it is not a literal property AND its\n // head is a schema container. Literal dotted properties are always preserved.\n const hasSplittableDotted = keys.some(\n (key) => !literals.has(key) && isDottedContainerKey(key, containers),\n );\n if (!hasBracket && !hasSplittableDotted) return args;\n return reconstructFlattenedKeys(args, (key) => shouldSplitKey(key, containers, literals));\n}\n"]}
|
|
@@ -133,4 +133,108 @@ export function reconstructFlattenedKeys(args, shouldSplit) {
|
|
|
133
133
|
}
|
|
134
134
|
return compactSparseArrays(result);
|
|
135
135
|
}
|
|
136
|
+
function isPlainObject(value) {
|
|
137
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
138
|
+
}
|
|
139
|
+
/** A flattened key contains a bracket index like `foo[0]`. */
|
|
140
|
+
function hasBracketIndex(key) {
|
|
141
|
+
return /\[\d+\]/.test(key);
|
|
142
|
+
}
|
|
143
|
+
/** A schema node that holds a nested object/array (so dotted keys are real paths). */
|
|
144
|
+
function isContainerSchema(schema) {
|
|
145
|
+
if (!isPlainObject(schema))
|
|
146
|
+
return false;
|
|
147
|
+
if (schema.type === "object" || schema.type === "array")
|
|
148
|
+
return true;
|
|
149
|
+
if ("properties" in schema || "items" in schema)
|
|
150
|
+
return true;
|
|
151
|
+
const union = schema.anyOf ?? schema.oneOf;
|
|
152
|
+
if (Array.isArray(union))
|
|
153
|
+
return union.some((branch) => isContainerSchema(branch));
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
/** Exact top-level `schema.properties` names (literal property keys). */
|
|
157
|
+
function literalPropertyNames(schema) {
|
|
158
|
+
const names = new Set();
|
|
159
|
+
if (!isPlainObject(schema))
|
|
160
|
+
return names;
|
|
161
|
+
const properties = schema.properties;
|
|
162
|
+
if (!isPlainObject(properties))
|
|
163
|
+
return names;
|
|
164
|
+
for (const name of Object.keys(properties))
|
|
165
|
+
names.add(name);
|
|
166
|
+
return names;
|
|
167
|
+
}
|
|
168
|
+
/** Top-level property names whose schema is an object/array container. */
|
|
169
|
+
function containerPropertyNames(schema) {
|
|
170
|
+
const names = new Set();
|
|
171
|
+
if (!isPlainObject(schema))
|
|
172
|
+
return names;
|
|
173
|
+
const properties = schema.properties;
|
|
174
|
+
if (!isPlainObject(properties))
|
|
175
|
+
return names;
|
|
176
|
+
for (const [name, sub] of Object.entries(properties)) {
|
|
177
|
+
if (isContainerSchema(sub))
|
|
178
|
+
names.add(name);
|
|
179
|
+
}
|
|
180
|
+
return names;
|
|
181
|
+
}
|
|
182
|
+
/** Whether `key` is a pure dotted path (`parent.child`) headed by a container prop. */
|
|
183
|
+
function isDottedContainerKey(key, containers) {
|
|
184
|
+
const dot = key.indexOf(".");
|
|
185
|
+
if (dot <= 0)
|
|
186
|
+
return false;
|
|
187
|
+
return containers.has(key.slice(0, dot));
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Decide whether a flattened key should be split into nested path segments.
|
|
191
|
+
*
|
|
192
|
+
* - Bracket-indexed keys (`foo[0]`, `foo[0].bar`) always split: they are
|
|
193
|
+
* unambiguous evidence of provider flattening.
|
|
194
|
+
* - Purely dotted keys (`parent.child`) split only when the schema marks their
|
|
195
|
+
* head segment as an object/array container property AND the schema does not
|
|
196
|
+
* declare the full key as a literal top-level property. The latter guard
|
|
197
|
+
* protects a schema that intentionally defines both a literal dotted property
|
|
198
|
+
* (e.g. `filter.name`) and a same-head container (e.g. `filter`): the literal
|
|
199
|
+
* property wins and is preserved verbatim (reviewer-b P2, issue #1496). The
|
|
200
|
+
* presence of a bracket-indexed sibling does NOT force a pure dotted key to
|
|
201
|
+
* split, so a literal property name such as `filter.name` is preserved
|
|
202
|
+
* verbatim even when a sibling like `ids[0]` is reconstructed.
|
|
203
|
+
*/
|
|
204
|
+
function shouldSplitKey(key, containers, literals) {
|
|
205
|
+
if (hasBracketIndex(key))
|
|
206
|
+
return true;
|
|
207
|
+
if (literals.has(key))
|
|
208
|
+
return false; // explicit literal property wins
|
|
209
|
+
return isDottedContainerKey(key, containers);
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Reconstruct flattened tool-call arguments into nested arrays/objects using
|
|
213
|
+
* schema-aware disambiguation for dotted keys.
|
|
214
|
+
*
|
|
215
|
+
* - Bracket-indexed keys (`ids[0]`, `files[0].path`) are always reconstructed.
|
|
216
|
+
* - Purely dotted keys (`parent.child`) are reconstructed only when the optional
|
|
217
|
+
* `schema` marks their head segment as an object/array container property.
|
|
218
|
+
* The presence of a bracket-indexed sibling does NOT force a pure dotted key
|
|
219
|
+
* to split, so a literal property name such as `filter.name` survives intact
|
|
220
|
+
* even when a sibling like `ids[0]` is present (issue #1496).
|
|
221
|
+
* - Otherwise dotted keys are preserved verbatim — fixing the regression where a
|
|
222
|
+
* literal property name like `filter.name` was silently corrupted.
|
|
223
|
+
*
|
|
224
|
+
* Returns the original reference unchanged when there is nothing to
|
|
225
|
+
* reconstruct. Prototype-pollution safety is delegated to
|
|
226
|
+
* {@link reconstructFlattenedKeys}.
|
|
227
|
+
*/
|
|
228
|
+
export function unflattenArgumentsWithSchema(args, schema) {
|
|
229
|
+
const keys = Object.keys(args);
|
|
230
|
+
const literals = literalPropertyNames(schema);
|
|
231
|
+
const containers = containerPropertyNames(schema);
|
|
232
|
+
const hasBracket = keys.some((key) => hasBracketIndex(key));
|
|
233
|
+
// A dotted key needs splitting only if it is not a literal property AND its
|
|
234
|
+
// head is a schema container. Literal dotted properties are always preserved.
|
|
235
|
+
const hasSplittableDotted = keys.some((key) => !literals.has(key) && isDottedContainerKey(key, containers));
|
|
236
|
+
if (!hasBracket && !hasSplittableDotted)
|
|
237
|
+
return args;
|
|
238
|
+
return reconstructFlattenedKeys(args, (key) => shouldSplitKey(key, containers, literals));
|
|
239
|
+
}
|
|
136
240
|
//# sourceMappingURL=flattened-tool-arguments.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flattened-tool-arguments.js","sourceRoot":"","sources":["../../src/core/flattened-tool-arguments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,kFAAkF;AAClF,MAAM,mBAAmB,GAAwB,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,aAAa,EAAE,WAAW,CAAC,CAAC,CAAC;AAEpG,SAAS,eAAe,CAAC,OAAwB;IAC/C,OAAO,OAAO,OAAO,KAAK,QAAQ,IAAI,mBAAmB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AACzE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,GAAW;IAC/C,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,SAAS,CAAC;IACxC,MAAM,QAAQ,GAA2B,EAAE,CAAC;IAC5C,IAAI,OAAO,GAAG,EAAE,CAAC;IACjB,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,MAAM,KAAK,GAAG,GAAG,EAAE;QACjB,IAAI,OA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EAAE,CAAC;QAChD,MAAM,GAAG,GAA4B,EAAE,CAAC;QACxC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;YAAE,GAAG,CAAC,GAAG,CAAC,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC;QACxF,OAAO,GAAG,CAAC;IACb,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,wBAAwB,CACtC,IAA6B,EAC7B,WAAqC;IAErC,MAAM,MAAM,GAA4B,EAAE,CAAC;IAC3C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QAChD,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,qBAAqB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAC3E,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,0EAA0E;YAC1E,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,GAAG,CAAC;gBAAE,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;YACvD,SAAS;QACX,CAAC;QACD,IAAI,QAAQ,CAAC,IAAI,CAAC,eAAe,CAAC;YAAE,SAAS,CAAC,iCAAiC;QAC/E,sBAAsB,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;IAClD,CAAC;IACD,OAAO,mBAAmB,CAAC,MAAM,CAA4B,CAAC;AAChE,CAAC","sourcesContent":["/**\n * Canonical reconstruction of flattened tool-call arguments.\n *\n * Some upstream providers — notably GitHub Copilot Gemini models proxied through\n * Google's GenAI API — serialize array/object function-call arguments as\n * flattened, indexed keys on the wire. For example a tool called with\n * `{ keywords: [\"a\", \"b\"] }` arrives as `{ \"keywords[0]\": \"a\", \"keywords[1]\": \"b\" }`,\n * and `{ files: [{ path }] }` as `{ \"files[0].path\": \"...\" }`.\n *\n * This module is the single source of truth for turning those flattened keys\n * back into nested arrays/objects. Both the host runtime's per-tool\n * normalization (gated to Copilot Gemini, schema-aware) and the MCP `callTool`\n * boundary (provider-agnostic, bracket self-gating) delegate here so the two\n * paths cannot drift — in particular so the prototype-pollution guard lives in\n * exactly one place.\n *\n * Security: argument keys cross a trust boundary (model/provider wire → tool /\n * MCP server validation). A key path that walks through `__proto__`,\n * `constructor`, or `prototype` could otherwise reach `Object.prototype` and\n * mutate it process-wide. Any key whose path contains such a segment — at any\n * position, including the final segment and a literal plain key — is dropped.\n */\n\n/** Key segments that must never be written or traversed (prototype pollution). */\nconst UNSAFE_KEY_SEGMENTS: ReadonlySet<string> = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\nfunction isUnsafeSegment(segment: string | number): boolean {\n return typeof segment === \"string\" && UNSAFE_KEY_SEGMENTS.has(segment);\n}\n\n/**\n * Parse a flattened key such as `a.b[0].c` into path segments\n * `[\"a\", \"b\", 0, \"c\"]`. Returns `undefined` for a plain key with no `.`/`[`, or\n * for a malformed bracket expression (left untouched by the caller).\n */\nexport function parseFlattenedKeyPath(key: string): Array<string | number> | undefined {\n if (!/[.[]/.test(key)) return undefined;\n const segments: Array<string | number> = [];\n let current = \"\";\n let index = 0;\n const flush = () => {\n if (current !== \"\") {\n segments.push(current);\n current = \"\";\n }\n };\n while (index < key.length) {\n const char = key[index];\n if (char === \".\") {\n flush();\n index += 1;\n } else if (char === \"[\") {\n flush();\n const end = key.indexOf(\"]\", index);\n if (end === -1) return undefined; // malformed — leave key untouched\n const inner = key.slice(index + 1, end);\n const numeric = Number(inner);\n if (inner.trim() !== \"\" && Number.isInteger(numeric) && numeric >= 0) {\n segments.push(numeric);\n } else {\n segments.push(inner.replace(/^[\"']|[\"']$/g, \"\"));\n }\n index = end + 1;\n } else {\n current += char;\n index += 1;\n }\n }\n flush();\n return segments.length > 0 ? segments : undefined;\n}\n\n/** Assign `value` at the given path inside `root`, creating arrays/objects as needed. */\nfunction assignFlattenedKeyPath(\n root: Record<string | number, unknown>,\n segments: Array<string | number>,\n value: unknown,\n): void {\n let node: Record<string | number, unknown> = root;\n for (let i = 0; i < segments.length - 1; i += 1) {\n const segment = segments[i];\n const nextIsIndex = typeof segments[i + 1] === \"number\";\n const existing = node[segment];\n if (existing === null || existing === undefined || typeof existing !== \"object\") {\n node[segment] = nextIsIndex ? [] : {};\n }\n node = node[segment] as Record<string | number, unknown>;\n }\n node[segments[segments.length - 1]] = value;\n}\n\n/**\n * Remove empty holes from sparse arrays produced by out-of-order indices.\n *\n * Note: this collapses holes rather than preserving them — `name[0]` + `name[2]`\n * (no index 1) becomes a dense 2-element array `[a, c]`, not `[a, <hole>, c]`.\n * That is the intended healing for Gemini's flattened output (which emits\n * contiguous indices in practice); it would, however, silently misalign two\n * arrays that were meant to be index-paired.\n */\nfunction compactSparseArrays(value: unknown): unknown {\n if (Array.isArray(value)) {\n return value.filter((entry) => entry !== undefined).map((entry) => compactSparseArrays(entry));\n }\n if (value !== null && typeof value === \"object\") {\n const out: Record<string, unknown> = {};\n for (const [key, entry] of Object.entries(value)) out[key] = compactSparseArrays(entry);\n return out;\n }\n return value;\n}\n\n/**\n * Reconstruct (unflatten) flattened keys into nested arrays/objects — for\n * example `\"items[0]\"` -> `{ items: [...] }` and `\"parent.child\"` ->\n * `{ parent: { child: ... } }`. `shouldSplit` decides, per key, whether it is a\n * flattened path (true) or an opaque literal key to be preserved (false);\n * callers apply their own gating/schema logic there.\n *\n * Prototype-pollution safe: a key whose parsed path contains `__proto__`,\n * `constructor`, or `prototype` (at any position) is dropped, as is a literal\n * plain key equal to one of those names.\n */\nexport function reconstructFlattenedKeys(\n args: Record<string, unknown>,\n shouldSplit: (key: string) => boolean,\n): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(args)) {\n const segments = shouldSplit(key) ? parseFlattenedKeyPath(key) : undefined;\n if (!segments) {\n // Plain passthrough — but never assign a literal prototype-polluting key.\n if (!UNSAFE_KEY_SEGMENTS.has(key)) result[key] = value;\n continue;\n }\n if (segments.some(isUnsafeSegment)) continue; // drop a polluting path entirely\n assignFlattenedKeyPath(result, segments, value);\n }\n return compactSparseArrays(result) as Record<string, unknown>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"flattened-tool-arguments.js","sourceRoot":"","sources":["../../src/core/flattened-tool-arguments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,kFAAkF;AAClF,MAAM,mBAAmB,GAAwB,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,aAAa,EAAE,WAAW,CAAC,CAAC,CAAC;AAEpG,SAAS,eAAe,CAAC,OAAwB;IAC/C,OAAO,OAAO,OAAO,KAAK,QAAQ,IAAI,mBAAmB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AACzE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,GAAW;IAC/C,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,SAAS,CAAC;IACxC,MAAM,QAAQ,GAA2B,EAAE,CAAC;IAC5C,IAAI,OAAO,GAAG,EAAE,CAAC;IACjB,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,MAAM,KAAK,GAAG,GAAG,EAAE;QACjB,IAAI,OAAO,KAAK,EAAE,EAAE,CAAC;YACnB,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACvB,OAAO,GAAG,EAAE,CAAC;QACf,CAAC;IACH,CAAC,CAAC;IACF,OAAO,KAAK,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC;QAC1B,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC;QACxB,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;YACjB,KAAK,EAAE,CAAC;YACR,KAAK,IAAI,CAAC,CAAC;QACb,CAAC;aAAM,IAAI,IAAI,KAAK,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AC,GAAG,EAAE,EAAE,CAAC,cAAc,CAAC,GAAG,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC;AAC5F,CAAC","sourcesContent":["/**\n * Canonical reconstruction of flattened tool-call arguments.\n *\n * Some upstream providers — notably GitHub Copilot Gemini models proxied through\n * Google's GenAI API — serialize array/object function-call arguments as\n * flattened, indexed keys on the wire. For example a tool called with\n * `{ keywords: [\"a\", \"b\"] }` arrives as `{ \"keywords[0]\": \"a\", \"keywords[1]\": \"b\" }`,\n * and `{ files: [{ path }] }` as `{ \"files[0].path\": \"...\" }`.\n *\n * This module is the single source of truth for turning those flattened keys\n * back into nested arrays/objects. Both the host runtime's per-tool\n * normalization (gated to Copilot Gemini, schema-aware) and the MCP `callTool`\n * boundary (provider-agnostic, bracket self-gating) delegate here so the two\n * paths cannot drift — in particular so the prototype-pollution guard lives in\n * exactly one place.\n *\n * Security: argument keys cross a trust boundary (model/provider wire → tool /\n * MCP server validation). A key path that walks through `__proto__`,\n * `constructor`, or `prototype` could otherwise reach `Object.prototype` and\n * mutate it process-wide. Any key whose path contains such a segment — at any\n * position, including the final segment and a literal plain key — is dropped.\n */\n\n/** Key segments that must never be written or traversed (prototype pollution). */\nconst UNSAFE_KEY_SEGMENTS: ReadonlySet<string> = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\nfunction isUnsafeSegment(segment: string | number): boolean {\n return typeof segment === \"string\" && UNSAFE_KEY_SEGMENTS.has(segment);\n}\n\n/**\n * Parse a flattened key such as `a.b[0].c` into path segments\n * `[\"a\", \"b\", 0, \"c\"]`. Returns `undefined` for a plain key with no `.`/`[`, or\n * for a malformed bracket expression (left untouched by the caller).\n */\nexport function parseFlattenedKeyPath(key: string): Array<string | number> | undefined {\n if (!/[.[]/.test(key)) return undefined;\n const segments: Array<string | number> = [];\n let current = \"\";\n let index = 0;\n const flush = () => {\n if (current !== \"\") {\n segments.push(current);\n current = \"\";\n }\n };\n while (index < key.length) {\n const char = key[index];\n if (char === \".\") {\n flush();\n index += 1;\n } else if (char === \"[\") {\n flush();\n const end = key.indexOf(\"]\", index);\n if (end === -1) return undefined; // malformed — leave key untouched\n const inner = key.slice(index + 1, end);\n const numeric = Number(inner);\n if (inner.trim() !== \"\" && Number.isInteger(numeric) && numeric >= 0) {\n segments.push(numeric);\n } else {\n segments.push(inner.replace(/^[\"']|[\"']$/g, \"\"));\n }\n index = end + 1;\n } else {\n current += char;\n index += 1;\n }\n }\n flush();\n return segments.length > 0 ? segments : undefined;\n}\n\n/** Assign `value` at the given path inside `root`, creating arrays/objects as needed. */\nfunction assignFlattenedKeyPath(\n root: Record<string | number, unknown>,\n segments: Array<string | number>,\n value: unknown,\n): void {\n let node: Record<string | number, unknown> = root;\n for (let i = 0; i < segments.length - 1; i += 1) {\n const segment = segments[i];\n const nextIsIndex = typeof segments[i + 1] === \"number\";\n const existing = node[segment];\n if (existing === null || existing === undefined || typeof existing !== \"object\") {\n node[segment] = nextIsIndex ? [] : {};\n }\n node = node[segment] as Record<string | number, unknown>;\n }\n node[segments[segments.length - 1]] = value;\n}\n\n/**\n * Remove empty holes from sparse arrays produced by out-of-order indices.\n *\n * Note: this collapses holes rather than preserving them — `name[0]` + `name[2]`\n * (no index 1) becomes a dense 2-element array `[a, c]`, not `[a, <hole>, c]`.\n * That is the intended healing for Gemini's flattened output (which emits\n * contiguous indices in practice); it would, however, silently misalign two\n * arrays that were meant to be index-paired.\n */\nfunction compactSparseArrays(value: unknown): unknown {\n if (Array.isArray(value)) {\n return value.filter((entry) => entry !== undefined).map((entry) => compactSparseArrays(entry));\n }\n if (value !== null && typeof value === \"object\") {\n const out: Record<string, unknown> = {};\n for (const [key, entry] of Object.entries(value)) out[key] = compactSparseArrays(entry);\n return out;\n }\n return value;\n}\n\n/**\n * Reconstruct (unflatten) flattened keys into nested arrays/objects — for\n * example `\"items[0]\"` -> `{ items: [...] }` and `\"parent.child\"` ->\n * `{ parent: { child: ... } }`. `shouldSplit` decides, per key, whether it is a\n * flattened path (true) or an opaque literal key to be preserved (false);\n * callers apply their own gating/schema logic there.\n *\n * Prototype-pollution safe: a key whose parsed path contains `__proto__`,\n * `constructor`, or `prototype` (at any position) is dropped, as is a literal\n * plain key equal to one of those names.\n */\nexport function reconstructFlattenedKeys(\n args: Record<string, unknown>,\n shouldSplit: (key: string) => boolean,\n): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(args)) {\n const segments = shouldSplit(key) ? parseFlattenedKeyPath(key) : undefined;\n if (!segments) {\n // Plain passthrough — but never assign a literal prototype-polluting key.\n if (!UNSAFE_KEY_SEGMENTS.has(key)) result[key] = value;\n continue;\n }\n if (segments.some(isUnsafeSegment)) continue; // drop a polluting path entirely\n assignFlattenedKeyPath(result, segments, value);\n }\n return compactSparseArrays(result) as Record<string, unknown>;\n}\n\n// ---------------------------------------------------------------------------\n// Schema-aware unflattening\n// ---------------------------------------------------------------------------\n//\n// A flattened key with a bracket index (`foo[0]`) is unambiguous and is always\n// reconstructed. A purely dotted key (`parent.child`) is ambiguous: it could be\n// a real nested path *or* a legitimate argument whose name literally contains\n// a dot (for example an MCP tool whose JSON Schema declares a property named\n// `filter.name`). To avoid corrupting such literal dotted keys, a dotted key is\n// only split when the tool's `inputSchema` proves its head segment is an\n// object/array container property. The presence of a bracket-indexed sibling\n// does NOT force a pure dotted key to split — the two are decided per key, so\n// a literal property such as `filter.name` survives intact even when a bracket\n// sibling like `ids[0]` is present (issue #1496). Callers that only want the\n// unambiguous bracket case can omit the schema.\n\ntype JsonRecord = Record<string, unknown>;\n\nfunction isPlainObject(value: unknown): value is JsonRecord {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/** A flattened key contains a bracket index like `foo[0]`. */\nfunction hasBracketIndex(key: string): boolean {\n return /\\[\\d+\\]/.test(key);\n}\n\n/** A schema node that holds a nested object/array (so dotted keys are real paths). */\nfunction isContainerSchema(schema: unknown): boolean {\n if (!isPlainObject(schema)) return false;\n if (schema.type === \"object\" || schema.type === \"array\") return true;\n if (\"properties\" in schema || \"items\" in schema) return true;\n const union = schema.anyOf ?? schema.oneOf;\n if (Array.isArray(union)) return union.some((branch) => isContainerSchema(branch));\n return false;\n}\n\n/** Exact top-level `schema.properties` names (literal property keys). */\nfunction literalPropertyNames(schema: unknown): Set<string> {\n const names = new Set<string>();\n if (!isPlainObject(schema)) return names;\n const properties = schema.properties;\n if (!isPlainObject(properties)) return names;\n for (const name of Object.keys(properties)) names.add(name);\n return names;\n}\n\n/** Top-level property names whose schema is an object/array container. */\nfunction containerPropertyNames(schema: unknown): Set<string> {\n const names = new Set<string>();\n if (!isPlainObject(schema)) return names;\n const properties = schema.properties;\n if (!isPlainObject(properties)) return names;\n for (const [name, sub] of Object.entries(properties)) {\n if (isContainerSchema(sub)) names.add(name);\n }\n return names;\n}\n\n/** Whether `key` is a pure dotted path (`parent.child`) headed by a container prop. */\nfunction isDottedContainerKey(key: string, containers: Set<string>): boolean {\n const dot = key.indexOf(\".\");\n if (dot <= 0) return false;\n return containers.has(key.slice(0, dot));\n}\n\n/**\n * Decide whether a flattened key should be split into nested path segments.\n *\n * - Bracket-indexed keys (`foo[0]`, `foo[0].bar`) always split: they are\n * unambiguous evidence of provider flattening.\n * - Purely dotted keys (`parent.child`) split only when the schema marks their\n * head segment as an object/array container property AND the schema does not\n * declare the full key as a literal top-level property. The latter guard\n * protects a schema that intentionally defines both a literal dotted property\n * (e.g. `filter.name`) and a same-head container (e.g. `filter`): the literal\n * property wins and is preserved verbatim (reviewer-b P2, issue #1496). The\n * presence of a bracket-indexed sibling does NOT force a pure dotted key to\n * split, so a literal property name such as `filter.name` is preserved\n * verbatim even when a sibling like `ids[0]` is reconstructed.\n */\nfunction shouldSplitKey(key: string, containers: Set<string>, literals: Set<string>): boolean {\n if (hasBracketIndex(key)) return true;\n if (literals.has(key)) return false; // explicit literal property wins\n return isDottedContainerKey(key, containers);\n}\n\n/**\n * Reconstruct flattened tool-call arguments into nested arrays/objects using\n * schema-aware disambiguation for dotted keys.\n *\n * - Bracket-indexed keys (`ids[0]`, `files[0].path`) are always reconstructed.\n * - Purely dotted keys (`parent.child`) are reconstructed only when the optional\n * `schema` marks their head segment as an object/array container property.\n * The presence of a bracket-indexed sibling does NOT force a pure dotted key\n * to split, so a literal property name such as `filter.name` survives intact\n * even when a sibling like `ids[0]` is present (issue #1496).\n * - Otherwise dotted keys are preserved verbatim — fixing the regression where a\n * literal property name like `filter.name` was silently corrupted.\n *\n * Returns the original reference unchanged when there is nothing to\n * reconstruct. Prototype-pollution safety is delegated to\n * {@link reconstructFlattenedKeys}.\n */\nexport function unflattenArgumentsWithSchema(\n args: Record<string, unknown>,\n schema?: unknown,\n): Record<string, unknown> {\n const keys = Object.keys(args);\n const literals = literalPropertyNames(schema);\n const containers = containerPropertyNames(schema);\n const hasBracket = keys.some((key) => hasBracketIndex(key));\n // A dotted key needs splitting only if it is not a literal property AND its\n // head is a schema container. Literal dotted properties are always preserved.\n const hasSplittableDotted = keys.some(\n (key) => !literals.has(key) && isDottedContainerKey(key, containers),\n );\n if (!hasBracket && !hasSplittableDotted) return args;\n return reconstructFlattenedKeys(args, (key) => shouldSplitKey(key, containers, literals));\n}\n"]}
|
package/dist/core/messages.d.ts
CHANGED
|
@@ -55,6 +55,7 @@ export declare function bashExecutionToText(msg: BashExecutionMessage): string;
|
|
|
55
55
|
export declare function createBranchSummaryMessage(summary: string, fromId: string, timestamp: string): BranchSummaryMessage;
|
|
56
56
|
/** Convert CustomMessageEntry to AgentMessage format */
|
|
57
57
|
export declare function createCustomMessage(customType: string, content: string | (TextContent | ImageContent)[], display: boolean, details: unknown | undefined, timestamp: string, excludeFromContext?: boolean): CustomMessage;
|
|
58
|
+
export declare function repairOrphanToolResults(messages: Message[]): Message[];
|
|
58
59
|
/**
|
|
59
60
|
* Transform AgentMessages (including custom types) to LLM-compatible Messages.
|
|
60
61
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.d.ts","sourceRoot":"","s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AE,CAiDhE","sourcesContent":["/**\n * Custom message types and transformers for the coding agent.\n *\n * Extends the base AgentMessage type with coding-agent specific message types,\n * and provides a transformer to convert them to LLM-compatible messages.\n */\n\nimport type { AgentMessage } from \"@earendil-works/pi-agent-core\";\nimport type { ImageContent, Message, TextContent } from \"@earendil-works/pi-ai\";\n\nexport const BRANCH_SUMMARY_PREFIX = `The following is a summary of a branch that this conversation came back from:\n\n<summary>\n`;\n\nexport const BRANCH_SUMMARY_SUFFIX = `</summary>`;\n\n/**\n * Message type for bash executions via the ! command.\n */\nexport interface BashExecutionMessage {\n\trole: \"bashExecution\";\n\tcommand: string;\n\toutput: string;\n\texitCode: number | undefined;\n\tcancelled: boolean;\n\ttruncated: boolean;\n\tfullOutputPath?: string;\n\ttimestamp: number;\n\t/** If true, this message is excluded from LLM context (!! prefix) */\n\texcludeFromContext?: boolean;\n}\n\n/**\n * Message type for extension-injected messages via sendMessage().\n * These are custom messages that extensions can inject into the conversation.\n */\nexport interface CustomMessage<T = unknown> {\n\trole: \"custom\";\n\tcustomType: string;\n\tcontent: string | (TextContent | ImageContent)[];\n\tdisplay: boolean;\n\tdetails?: T;\n\ttimestamp: number;\n}\n\nexport interface BranchSummaryMessage {\n\trole: \"branchSummary\";\n\tsummary: string;\n\tfromId: string;\n\ttimestamp: number;\n}\n\n// Extend CustomAgentMessages via declaration merging\ndeclare module \"@earendil-works/pi-agent-core\" {\n\tinterface CustomAgentMessages {\n\t\tbashExecution: BashExecutionMessage;\n\t\tcustom: CustomMessage;\n\t\tbranchSummary: BranchSummaryMessage;\n\t}\n}\n\n/**\n * Convert a BashExecutionMessage to user message text for LLM context.\n */\nexport function bashExecutionToText(msg: BashExecutionMessage): string {\n\tlet text = `Ran \\`${msg.command}\\`\\n`;\n\tif (msg.output) {\n\t\ttext += `\\`\\`\\`\\n${msg.output}\\n\\`\\`\\``;\n\t} else {\n\t\ttext += \"(no output)\";\n\t}\n\tif (msg.cancelled) {\n\t\ttext += \"\\n\\n(command cancelled)\";\n\t} else if (msg.exitCode !== null && msg.exitCode !== undefined && msg.exitCode !== 0) {\n\t\ttext += `\\n\\nCommand exited with code ${msg.exitCode}`;\n\t}\n\tif (msg.truncated && msg.fullOutputPath) {\n\t\ttext += `\\n\\n[Output truncated. Full output: ${msg.fullOutputPath}]`;\n\t}\n\treturn text;\n}\n\nexport function createBranchSummaryMessage(summary: string, fromId: string, timestamp: string): BranchSummaryMessage {\n\treturn {\n\t\trole: \"branchSummary\",\n\t\tsummary,\n\t\tfromId,\n\t\ttimestamp: new Date(timestamp).getTime(),\n\t};\n}\n\n/** Convert CustomMessageEntry to AgentMessage format */\nexport function createCustomMessage(\n\tcustomType: string,\n\tcontent: string | (TextContent | ImageContent)[],\n\tdisplay: boolean,\n\tdetails: unknown | undefined,\n\ttimestamp: string,\n\texcludeFromContext?: boolean,\n): CustomMessage {\n\tconst message: CustomMessage & { excludeFromContext?: boolean } = {\n\t\trole: \"custom\",\n\t\tcustomType,\n\t\tcontent,\n\t\tdisplay,\n\t\tdetails,\n\t\ttimestamp: new Date(timestamp).getTime(),\n\t};\n\tif (excludeFromContext === true) message.excludeFromContext = true;\n\treturn message;\n}\n\nfunction collectAssistantToolCallIds(message: Message): Set<string> {\n\tconst content = (message as { content?: unknown }).content;\n\tconst ids = new Set<string>();\n\tif (!Array.isArray(content)) return ids;\n\tfor (const block of content) {\n\t\tif (!block || typeof block !== \"object\") continue;\n\t\tconst candidate = block as { type?: unknown; id?: unknown };\n\t\tif (candidate.type === \"toolCall\" && typeof candidate.id === \"string\") ids.add(candidate.id);\n\t}\n\treturn ids;\n}\n\nfunction getToolResultCallId(message: Message): string | undefined {\n\tif (message.role !== \"toolResult\") return undefined;\n\tconst toolCallId = (message as { toolCallId?: unknown }).toolCallId;\n\treturn typeof toolCallId === \"string\" ? toolCallId : undefined;\n}\n\nexport function repairOrphanToolResults(messages: Message[]): Message[] {\n\tlet allowedToolCallIds: Set<string> | undefined;\n\tlet changed = false;\n\tconst repaired: Message[] = [];\n\tfor (const message of messages) {\n\t\tif (message.role === \"assistant\") {\n\t\t\tallowedToolCallIds = collectAssistantToolCallIds(message);\n\t\t\trepaired.push(message);\n\t\t\tcontinue;\n\t\t}\n\t\tif (message.role === \"toolResult\") {\n\t\t\tconst toolCallId = getToolResultCallId(message);\n\t\t\tif (toolCallId && allowedToolCallIds?.has(toolCallId)) {\n\t\t\t\trepaired.push(message);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tchanged = true;\n\t\t\tcontinue;\n\t\t}\n\t\tallowedToolCallIds = undefined;\n\t\trepaired.push(message);\n\t}\n\treturn changed ? repaired : messages;\n}\n\n/**\n * Transform AgentMessages (including custom types) to LLM-compatible Messages.\n *\n * This is used by:\n * - Agent's transormToLlm option (for prompt calls and queued messages)\n * - Branch summarization (for summarizing abandoned branches)\n * - Custom extensions and tools\n */\nexport function convertToLlm(messages: AgentMessage[]): Message[] {\n\tconst converted = messages\n\t\t.map((m): Message | undefined => {\n\t\t\tswitch (m.role) {\n\t\t\t\tcase \"bashExecution\":\n\t\t\t\t\t// Skip messages excluded from context (!! prefix)\n\t\t\t\t\tif (m.excludeFromContext) {\n\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t}\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: [{ type: \"text\", text: bashExecutionToText(m) }],\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\tcase \"custom\": {\n\t\t\t\t\tif ((m as CustomMessage & { excludeFromContext?: boolean }).excludeFromContext === true) return undefined;\n\t\t\t\t\tconst content = typeof m.content === \"string\" ? [{ type: \"text\" as const, text: m.content }] : m.content;\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent,\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tcase \"branchSummary\":\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: BRANCH_SUMMARY_PREFIX + m.summary + BRANCH_SUMMARY_SUFFIX }],\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\tcase \"user\":\n\t\t\t\tcase \"assistant\":\n\t\t\t\tcase \"toolResult\":\n\t\t\t\t\treturn m;\n\t\t\t\tcase \"compactionSummary\":\n\t\t\t\t\t// Legacy summary-compaction message type retained in the upstream AgentMessage\n\t\t\t\t\t// union. Summary compaction was removed; these archival entries are inert and are\n\t\t\t\t\t// never injected into active LLM context.\n\t\t\t\t\treturn undefined;\n\t\t\t\tdefault: {\n\t\t\t\t\t// Exhaustiveness guard: adding a new AgentMessage role must fail the build here\n\t\t\t\t\t// instead of silently mapping to undefined and dropping the message from context.\n\t\t\t\t\tconst _exhaustiveCheck: never = m;\n\t\t\t\t\tvoid _exhaustiveCheck;\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t\t.filter((m) => m !== undefined);\n\treturn repairOrphanToolResults(converted);\n}\n"]}
|