@selesai/code 0.13.0 → 0.13.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 +22 -0
- package/dist/core/agent-session.d.ts +1 -1
- package/dist/core/agent-session.js +1 -1
- package/dist/core/sdk.d.ts +2 -2
- package/dist/core/sdk.js +1 -1
- package/dist/core/system-prompt.d.ts +1 -1
- package/dist/core/system-prompt.js +1 -1
- package/dist/extensions/package.json +1 -2
- package/dist/extensions/pi-hermes-memory/CHANGELOG.md +371 -0
- package/dist/extensions/pi-hermes-memory/LICENSE +21 -0
- package/dist/extensions/pi-hermes-memory/README.md +643 -0
- package/dist/extensions/pi-hermes-memory/docs/0.1/TASKS.md +197 -0
- package/dist/extensions/pi-hermes-memory/docs/0.2/PLAN.md +290 -0
- package/dist/extensions/pi-hermes-memory/docs/0.2/TASKS.md +134 -0
- package/dist/extensions/pi-hermes-memory/docs/0.2/TEST-PLAN.md +216 -0
- package/dist/extensions/pi-hermes-memory/docs/0.3/PLAN.md +330 -0
- package/dist/extensions/pi-hermes-memory/docs/0.3/TASKS.md +125 -0
- package/dist/extensions/pi-hermes-memory/docs/0.4/PLAN.md +160 -0
- package/dist/extensions/pi-hermes-memory/docs/0.4/TASKS.md +113 -0
- package/dist/extensions/pi-hermes-memory/docs/0.6/CHANGELOG.md +57 -0
- package/dist/extensions/pi-hermes-memory/docs/0.6/PLAN.md +202 -0
- package/dist/extensions/pi-hermes-memory/docs/0.6/TASKS.md +144 -0
- package/dist/extensions/pi-hermes-memory/docs/0.7/PLAN.md +349 -0
- package/dist/extensions/pi-hermes-memory/docs/0.7/TASKS.md +110 -0
- package/dist/extensions/pi-hermes-memory/docs/PUBLISHING.md +149 -0
- package/dist/extensions/pi-hermes-memory/docs/ROADMAP.md +468 -0
- package/dist/extensions/pi-hermes-memory/docs/images/memory-architecture.svg +1 -0
- package/dist/extensions/pi-hermes-memory/docs/images/pi-logo.svg +22 -0
- package/dist/extensions/pi-hermes-memory/docs/images/pi_memory.png +0 -0
- package/dist/extensions/pi-hermes-memory/docs/images/pi_memory.svg +19 -0
- package/dist/extensions/pi-hermes-memory/docs/images/security-flow.svg +1 -0
- package/dist/extensions/pi-hermes-memory/docs/images/session-lifecycle.svg +1 -0
- package/dist/extensions/pi-hermes-memory/docs/images/source-architecture.svg +1 -0
- package/dist/extensions/pi-hermes-memory/docs/mermaid/memory-architecture.mmd +49 -0
- package/dist/extensions/pi-hermes-memory/docs/mermaid/security-flow.mmd +40 -0
- package/dist/extensions/pi-hermes-memory/docs/mermaid/session-lifecycle.mmd +56 -0
- package/dist/extensions/pi-hermes-memory/docs/mermaid/source-architecture.mmd +54 -0
- package/dist/extensions/pi-hermes-memory/package-lock.json +3799 -0
- package/dist/extensions/pi-hermes-memory/package.json +66 -0
- package/dist/extensions/pi-hermes-memory/scripts/check-min-sdk.mjs +99 -0
- package/dist/extensions/pi-hermes-memory/scripts/ensure-dev.mjs +57 -0
- package/dist/extensions/pi-hermes-memory/src/auto-consolidation-warning.ts +6 -0
- package/dist/extensions/pi-hermes-memory/src/config.ts +178 -0
- package/dist/extensions/pi-hermes-memory/src/constants.ts +424 -0
- package/dist/extensions/pi-hermes-memory/src/extension-root-migration.ts +639 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/auto-consolidate.ts +401 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/background-review.ts +297 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/child-process-watchdog.mjs +90 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/correction-detector.ts +300 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/index-sessions.ts +86 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/insights.ts +78 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/interview.ts +37 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/learn-memory.ts +186 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/message-parts.ts +27 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/pi-child-process.ts +485 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/preview-context.ts +105 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/review-memory-ops.ts +506 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/session-backfill.ts +145 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/session-flush.ts +151 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/session-live-index.ts +94 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/skills-command.ts +1334 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/standing-pin.ts +111 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/switch-project.ts +75 -0
- package/dist/extensions/pi-hermes-memory/src/handlers/sync-markdown-memories.ts +266 -0
- package/dist/extensions/pi-hermes-memory/src/index.ts +378 -0
- package/dist/extensions/pi-hermes-memory/src/lifecycle-timing.ts +54 -0
- package/dist/extensions/pi-hermes-memory/src/paths.ts +61 -0
- package/dist/extensions/pi-hermes-memory/src/project-context.ts +13 -0
- package/dist/extensions/pi-hermes-memory/src/project-memory-migration.ts +93 -0
- package/dist/extensions/pi-hermes-memory/src/project.ts +157 -0
- package/dist/extensions/pi-hermes-memory/src/prompt-context.ts +55 -0
- package/dist/extensions/pi-hermes-memory/src/store/atomic-lock-coordinator.ts +375 -0
- package/dist/extensions/pi-hermes-memory/src/store/canonical-storage-path.ts +54 -0
- package/dist/extensions/pi-hermes-memory/src/store/content-scanner.ts +101 -0
- package/dist/extensions/pi-hermes-memory/src/store/db.ts +1180 -0
- package/dist/extensions/pi-hermes-memory/src/store/fts-query.ts +101 -0
- package/dist/extensions/pi-hermes-memory/src/store/markdown-mutation-lock.ts +38 -0
- package/dist/extensions/pi-hermes-memory/src/store/memory-lookup.ts +24 -0
- package/dist/extensions/pi-hermes-memory/src/store/memory-store.ts +1191 -0
- package/dist/extensions/pi-hermes-memory/src/store/recovery-maintenance.ts +66 -0
- package/dist/extensions/pi-hermes-memory/src/store/schema.ts +118 -0
- package/dist/extensions/pi-hermes-memory/src/store/session-anchor-search.ts +472 -0
- package/dist/extensions/pi-hermes-memory/src/store/session-indexer.ts +511 -0
- package/dist/extensions/pi-hermes-memory/src/store/session-parser.ts +213 -0
- package/dist/extensions/pi-hermes-memory/src/store/session-search.ts +234 -0
- package/dist/extensions/pi-hermes-memory/src/store/skill-store.ts +950 -0
- package/dist/extensions/pi-hermes-memory/src/store/skill-utils.ts +133 -0
- package/dist/extensions/pi-hermes-memory/src/store/sqlite-memory-store.ts +1002 -0
- package/dist/extensions/pi-hermes-memory/src/store/sqlite-native.ts +241 -0
- package/dist/extensions/pi-hermes-memory/src/store/standing-instructions.ts +247 -0
- package/dist/extensions/pi-hermes-memory/src/tools/memory-search-tool.ts +95 -0
- package/dist/extensions/pi-hermes-memory/src/tools/memory-tool.ts +469 -0
- package/dist/extensions/pi-hermes-memory/src/tools/session-search-tool.ts +246 -0
- package/dist/extensions/pi-hermes-memory/src/tools/shared-output-view.ts +170 -0
- package/dist/extensions/pi-hermes-memory/src/tools/skill-tool.ts +333 -0
- package/dist/extensions/pi-hermes-memory/src/tools/tool-result-views.ts +105 -0
- package/dist/extensions/pi-hermes-memory/src/types.ts +214 -0
- package/dist/extensions/pi-hermes-memory/tests/config.test.ts +434 -0
- package/dist/extensions/pi-hermes-memory/tests/extension-root-migration.test.ts +368 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/auto-consolidate.test.ts +984 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/background-review.test.ts +950 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/correction-detector.test.ts +671 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/insights.test.ts +157 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/interview.test.ts +127 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/pi-child-process.test.ts +905 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/preview-context.test.ts +152 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/prompt-context.test.ts +166 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/resources-discover.test.ts +71 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/review-memory-ops.test.ts +614 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/session-backfill.test.ts +192 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/session-flush.test.ts +677 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/session-live-index.test.ts +225 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/skills-command.test.ts +827 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/standing-pin.test.ts +134 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/sync-markdown-memories.test.ts +491 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/system-prompt.test.ts +199 -0
- package/dist/extensions/pi-hermes-memory/tests/handlers/thinking-max.test.ts +64 -0
- package/dist/extensions/pi-hermes-memory/tests/index.test.ts +30 -0
- package/dist/extensions/pi-hermes-memory/tests/integration/flow.test.ts +126 -0
- package/dist/extensions/pi-hermes-memory/tests/lifecycle-timing.test.ts +76 -0
- package/dist/extensions/pi-hermes-memory/tests/paths.test.ts +23 -0
- package/dist/extensions/pi-hermes-memory/tests/project-memory-migration.test.ts +80 -0
- package/dist/extensions/pi-hermes-memory/tests/project-rebinding.test.ts +115 -0
- package/dist/extensions/pi-hermes-memory/tests/project.test.ts +120 -0
- package/dist/extensions/pi-hermes-memory/tests/run-all-timeout.test.ts +107 -0
- package/dist/extensions/pi-hermes-memory/tests/run-all.sh +45 -0
- package/dist/extensions/pi-hermes-memory/tests/store/atomic-lock-coordinator.test.ts +381 -0
- package/dist/extensions/pi-hermes-memory/tests/store/content-scanner.test.ts +388 -0
- package/dist/extensions/pi-hermes-memory/tests/store/db.test.ts +1046 -0
- package/dist/extensions/pi-hermes-memory/tests/store/markdown-mutation-lock.test.ts +34 -0
- package/dist/extensions/pi-hermes-memory/tests/store/memory-store.test.ts +2150 -0
- package/dist/extensions/pi-hermes-memory/tests/store/recovery-maintenance.test.ts +170 -0
- package/dist/extensions/pi-hermes-memory/tests/store/session-anchor-search.test.ts +210 -0
- package/dist/extensions/pi-hermes-memory/tests/store/session-indexer.test.ts +643 -0
- package/dist/extensions/pi-hermes-memory/tests/store/session-parser.test.ts +282 -0
- package/dist/extensions/pi-hermes-memory/tests/store/session-search.test.ts +287 -0
- package/dist/extensions/pi-hermes-memory/tests/store/skill-store.test.ts +678 -0
- package/dist/extensions/pi-hermes-memory/tests/store/skill-utils.test.ts +21 -0
- package/dist/extensions/pi-hermes-memory/tests/store/sqlite-lazy-load.test.ts +78 -0
- package/dist/extensions/pi-hermes-memory/tests/store/sqlite-memory-store.test.ts +543 -0
- package/dist/extensions/pi-hermes-memory/tests/store/sqlite-native.test.ts +164 -0
- package/dist/extensions/pi-hermes-memory/tests/store/standing-instructions.test.ts +171 -0
- package/dist/extensions/pi-hermes-memory/tests/tools/memory-search-tool.test.ts +84 -0
- package/dist/extensions/pi-hermes-memory/tests/tools/memory-tool.test.ts +709 -0
- package/dist/extensions/pi-hermes-memory/tests/tools/session-search-tool.test.ts +345 -0
- package/dist/extensions/pi-hermes-memory/tests/tools/shared-output-view.test.ts +362 -0
- package/dist/extensions/pi-hermes-memory/tests/tools/skill-tool.test.ts +478 -0
- package/dist/extensions/pi-hermes-memory/tests/tools/tool-result-renderer-wiring.test.ts +40 -0
- package/dist/extensions/pi-hermes-memory/tsconfig.json +19 -0
- package/dist/extensions/pi-rewind-hook/README.md +4 -1
- package/dist/extensions/pi-rewind-hook/index.ts +151 -21
- package/dist/extensions/pi-rewind-hook/package.json +5 -3
- package/dist/extensions/pi-subagents/.oxlintrc.json +43 -0
- package/dist/extensions/pi-subagents/AGENTS.md +5 -0
- package/dist/extensions/pi-subagents/CHANGELOG.md +157 -0
- package/dist/extensions/pi-subagents/README.md +12 -6
- package/dist/extensions/pi-subagents/VISION.md +81 -0
- package/dist/extensions/pi-subagents/agents/claude-code-writer.md +15 -0
- package/dist/extensions/pi-subagents/agents/claude-code.md +15 -0
- package/dist/extensions/pi-subagents/agents/codex-exec-writer.md +15 -0
- package/dist/extensions/pi-subagents/agents/codex-exec.md +15 -0
- package/dist/extensions/pi-subagents/agents/cursor-agent-writer.md +14 -0
- package/dist/extensions/pi-subagents/agents/cursor-agent.md +14 -0
- package/dist/extensions/pi-subagents/agents/reviewer.md +1 -3
- package/dist/extensions/pi-subagents/docs/agents.md +488 -0
- package/dist/extensions/pi-subagents/docs/configuration.md +46 -9
- package/dist/extensions/pi-subagents/docs/extension-api.md +42 -3
- package/dist/extensions/pi-subagents/docs/models.md +27 -4
- package/dist/extensions/pi-subagents/docs/observability.md +10 -9
- package/dist/extensions/pi-subagents/docs/tool-reference.md +102 -6
- package/dist/extensions/pi-subagents/docs/workflows.md +135 -0
- package/dist/extensions/pi-subagents/package-lock.json +389 -2
- package/dist/extensions/pi-subagents/package.json +3 -1
- package/dist/extensions/pi-subagents/prompts/review-loop.md +2 -2
- package/dist/extensions/pi-subagents/skills/council-mode/SKILL.md +1 -1
- package/dist/extensions/pi-subagents/skills/pi-subagents/SKILL.md +3 -1
- package/dist/extensions/pi-subagents/skills/pi-subagents/references/execution-controls.md +7 -3
- package/dist/extensions/pi-subagents/skills/pi-subagents/references/management-authoring-rpc.md +2 -2
- package/dist/extensions/pi-subagents/skills/pi-subagents/references/prompting-and-roles.md +26 -5
- package/dist/extensions/pi-subagents/src/agents/agent-management.ts +41 -22
- package/dist/extensions/pi-subagents/src/agents/agent-refinements.ts +4 -4
- package/dist/extensions/pi-subagents/src/agents/agent-serializer.ts +9 -2
- package/dist/extensions/pi-subagents/src/agents/agents.ts +322 -75
- package/dist/extensions/pi-subagents/src/agents/builtin-names.ts +6 -0
- package/dist/extensions/pi-subagents/src/agents/runtime-agent-events.ts +70 -0
- package/dist/extensions/pi-subagents/src/agents/runtime-agent-registry.ts +27 -20
- package/dist/extensions/pi-subagents/src/api/agents.ts +10 -5
- package/dist/extensions/pi-subagents/src/api/background-work.ts +5 -1
- package/dist/extensions/pi-subagents/src/api/delegation.ts +0 -7
- package/dist/extensions/pi-subagents/src/api/preflight.ts +34 -12
- package/dist/extensions/pi-subagents/src/extension/config.ts +70 -0
- package/dist/extensions/pi-subagents/src/extension/doctor.ts +3 -3
- package/dist/extensions/pi-subagents/src/extension/fanout-child.ts +5 -3
- package/dist/extensions/pi-subagents/src/extension/index.ts +83 -30
- package/dist/extensions/pi-subagents/src/extension/public-execution.ts +44 -15
- package/dist/extensions/pi-subagents/src/extension/rpc.ts +55 -19
- package/dist/extensions/pi-subagents/src/extension/schemas.ts +41 -15
- package/dist/extensions/pi-subagents/src/extension/tool-description.ts +28 -31
- package/dist/extensions/pi-subagents/src/inspectors/herdr/actions.ts +2 -1
- package/dist/extensions/pi-subagents/src/inspectors/herdr/inspector-runner.ts +2 -10
- package/dist/extensions/pi-subagents/src/inspectors/herdr/session-roots-codec.ts +42 -0
- package/dist/extensions/pi-subagents/src/integrations/herdr-status.ts +51 -7
- package/dist/extensions/pi-subagents/src/intercom/result-intercom.ts +2 -0
- package/dist/extensions/pi-subagents/src/profiles/profiles.ts +5 -6
- package/dist/extensions/pi-subagents/src/runs/background/active-async-capacity.ts +77 -10
- package/dist/extensions/pi-subagents/src/runs/background/async-execution.ts +176 -53
- package/dist/extensions/pi-subagents/src/runs/background/async-job-tracker.ts +19 -12
- package/dist/extensions/pi-subagents/src/runs/background/async-resume.ts +29 -27
- package/dist/extensions/pi-subagents/src/runs/background/async-retention.ts +20 -3
- package/dist/extensions/pi-subagents/src/runs/background/async-status-snapshot.ts +23 -261
- package/dist/extensions/pi-subagents/src/runs/background/async-status.ts +73 -7
- package/dist/extensions/pi-subagents/src/runs/background/chain-append.ts +8 -3
- package/dist/extensions/pi-subagents/src/runs/background/chain-root-attachment.ts +74 -8
- package/dist/extensions/pi-subagents/src/runs/background/fleet-view.ts +37 -21
- package/dist/extensions/pi-subagents/src/runs/background/inspect-rpc.ts +8 -8
- package/dist/extensions/pi-subagents/src/runs/background/notify.ts +184 -9
- package/dist/extensions/pi-subagents/src/runs/background/result-delivery-ownership.ts +45 -0
- package/dist/extensions/pi-subagents/src/runs/background/result-files.ts +28 -14
- package/dist/extensions/pi-subagents/src/runs/background/result-watcher.ts +38 -15
- package/dist/extensions/pi-subagents/src/runs/background/resume-guidance.ts +1 -1
- package/dist/extensions/pi-subagents/src/runs/background/retained-children.ts +1 -1
- package/dist/extensions/pi-subagents/src/runs/background/run-status.ts +50 -13
- package/dist/extensions/pi-subagents/src/runs/background/scheduled-runs.ts +93 -8
- package/dist/extensions/pi-subagents/src/runs/background/stale-run-reconciler.ts +10 -4
- package/dist/extensions/pi-subagents/src/runs/background/steering.ts +4 -14
- package/dist/extensions/pi-subagents/src/runs/background/subagent-runner.ts +549 -377
- package/dist/extensions/pi-subagents/src/runs/background/subagent-wait.ts +58 -10
- package/dist/extensions/pi-subagents/src/runs/background/terminal-run-index.ts +1 -1
- package/dist/extensions/pi-subagents/src/runs/background/wait-completions.ts +26 -1
- package/dist/extensions/pi-subagents/src/runs/background/wait-config.ts +23 -9
- package/dist/extensions/pi-subagents/src/runs/background/wait-tool.ts +9 -2
- package/dist/extensions/pi-subagents/src/runs/foreground/async-steering-action.ts +2 -2
- package/dist/extensions/pi-subagents/src/runs/foreground/execution.ts +204 -129
- package/dist/extensions/pi-subagents/src/runs/foreground/foreground-control.ts +9 -0
- package/dist/extensions/pi-subagents/src/runs/foreground/foreground-history.ts +23 -1
- package/dist/extensions/pi-subagents/src/runs/foreground/subagent-executor.ts +773 -311
- package/dist/extensions/pi-subagents/src/runs/foreground/workflow-detach-reconcile.ts +140 -115
- package/dist/extensions/pi-subagents/src/runs/shared/abort-recovery.ts +119 -0
- package/dist/extensions/pi-subagents/src/runs/shared/async-status-projection.ts +463 -0
- package/dist/extensions/pi-subagents/src/runs/shared/child-identity.ts +19 -4
- package/dist/extensions/pi-subagents/src/runs/shared/child-launch-plan.ts +151 -0
- package/dist/extensions/pi-subagents/src/runs/shared/child-protocol.ts +21 -7
- package/dist/extensions/pi-subagents/src/runs/shared/claude-code-adapter.ts +129 -0
- package/dist/extensions/pi-subagents/src/runs/shared/codex-exec-adapter.ts +129 -0
- package/dist/extensions/pi-subagents/src/runs/shared/completion-evidence.ts +89 -0
- package/dist/extensions/pi-subagents/src/runs/shared/completion-guard.ts +5 -4
- package/dist/extensions/pi-subagents/src/runs/shared/cursor-agent-adapter.ts +114 -0
- package/dist/extensions/pi-subagents/src/runs/shared/dynamic-fanout.ts +3 -3
- package/dist/extensions/pi-subagents/src/runs/shared/external-cli-contract.ts +167 -0
- package/dist/extensions/pi-subagents/src/runs/shared/external-cli-preflight.ts +122 -0
- package/dist/extensions/pi-subagents/src/runs/shared/external-cli-runner.ts +348 -55
- package/dist/extensions/pi-subagents/src/runs/shared/fast-mode-extension.ts +5 -5
- package/dist/extensions/pi-subagents/src/runs/shared/host-step-status.ts +230 -0
- package/dist/extensions/pi-subagents/src/runs/shared/lane-metadata.ts +105 -0
- package/dist/extensions/pi-subagents/src/runs/shared/launch-cwd.ts +16 -0
- package/dist/extensions/pi-subagents/src/runs/shared/long-running-guard.ts +2 -1
- package/dist/extensions/pi-subagents/src/runs/shared/mcp-config-sources.ts +422 -0
- package/dist/extensions/pi-subagents/src/runs/shared/mcp-direct-tool-allowlist.ts +221 -158
- package/dist/extensions/pi-subagents/src/runs/shared/mcp-direct-tool-grant.ts +197 -0
- package/dist/extensions/pi-subagents/src/runs/shared/model-exclusions.ts +69 -7
- package/dist/extensions/pi-subagents/src/runs/shared/model-fallback.ts +47 -6
- package/dist/extensions/pi-subagents/src/runs/shared/mutation-evidence.ts +7 -2
- package/dist/extensions/pi-subagents/src/runs/shared/nested-events.ts +9 -3
- package/dist/extensions/pi-subagents/src/runs/shared/nested-render.ts +9 -5
- package/dist/extensions/pi-subagents/src/runs/shared/parallel-handoff.ts +419 -7
- package/dist/extensions/pi-subagents/src/runs/shared/parallel-utils.ts +15 -1
- package/dist/extensions/pi-subagents/src/runs/shared/pi-args.ts +81 -8
- package/dist/extensions/pi-subagents/src/runs/shared/process-signal.ts +13 -0
- package/dist/extensions/pi-subagents/src/runs/shared/run-history.ts +21 -1
- package/dist/extensions/pi-subagents/src/runs/shared/single-output.ts +44 -4
- package/dist/extensions/pi-subagents/src/runs/shared/subagent-prompt-runtime.ts +98 -13
- package/dist/extensions/pi-subagents/src/runs/shared/subagent-startup-retry.ts +1 -1
- package/dist/extensions/pi-subagents/src/runs/shared/worktree-cleanup-plan.ts +847 -0
- package/dist/extensions/pi-subagents/src/runs/shared/worktree.ts +18 -0
- package/dist/extensions/pi-subagents/src/shared/child-session-name.ts +46 -0
- package/dist/extensions/pi-subagents/src/shared/extension-context.ts +24 -0
- package/dist/extensions/pi-subagents/src/shared/fork-context.ts +21 -0
- package/dist/extensions/pi-subagents/src/shared/formatters.ts +18 -3
- package/dist/extensions/pi-subagents/src/shared/launch-contract.ts +5 -1
- package/dist/extensions/pi-subagents/src/shared/pruned-fork.ts +450 -0
- package/dist/extensions/pi-subagents/src/shared/session-file-trust.ts +19 -0
- package/dist/extensions/pi-subagents/src/shared/session-tokens.ts +14 -3
- package/dist/extensions/pi-subagents/src/shared/settings.ts +19 -105
- package/dist/extensions/pi-subagents/src/shared/shortcuts.ts +17 -0
- package/dist/extensions/pi-subagents/src/shared/types.ts +359 -40
- package/dist/extensions/pi-subagents/src/shared/utils.ts +41 -84
- package/dist/extensions/pi-subagents/src/shared/workflow-child-permit.ts +116 -0
- package/dist/extensions/pi-subagents/src/slash/delegation-adapters.ts +1 -9
- package/dist/extensions/pi-subagents/src/slash/delegation-request.ts +0 -4
- package/dist/extensions/pi-subagents/src/slash/slash-bridge.ts +1 -2
- package/dist/extensions/pi-subagents/src/slash/slash-commands.ts +378 -88
- package/dist/extensions/pi-subagents/src/slash/slash-live-state.ts +22 -11
- package/dist/extensions/pi-subagents/src/slash/subagents-admin.ts +3 -0
- package/dist/extensions/pi-subagents/src/tui/fleet-status.ts +147 -79
- package/dist/extensions/pi-subagents/src/tui/fleet-transcript.ts +11 -5
- package/dist/extensions/pi-subagents/src/tui/fleet.ts +39 -18
- package/dist/extensions/pi-subagents/src/tui/render.ts +369 -46
- package/dist/extensions/pi-subagents/src/watchdog/turn-delta.ts +1 -1
- package/dist/extensions/pi-subagents/src/workflows/chat-progress.ts +6 -3
- package/dist/extensions/pi-subagents/src/workflows/host-command.ts +230 -0
- package/dist/extensions/pi-subagents/src/workflows/scripted-workflow.ts +740 -58
- package/dist/extensions/pi-subagents/src/workflows/workflow-child-summary.ts +121 -0
- package/dist/extensions/pi-subagents/src/workflows/workflow-preflight.ts +270 -0
- package/dist/extensions/pi-subagents/src/workflows/workflow-receipt.ts +195 -6
- package/dist/extensions/pi-subagents/src/workflows/workflow-settlement.ts +246 -0
- package/dist/extensions/pi-subagents/test/e2e/real-session-subagent.test.ts +2 -2
- package/dist/extensions/pi-subagents/test/integration/async-execution.test.ts +1114 -260
- package/dist/extensions/pi-subagents/test/integration/async-job-tracker.test.ts +34 -0
- package/dist/extensions/pi-subagents/test/integration/async-status.test.ts +150 -3
- package/dist/extensions/pi-subagents/test/integration/claude-code-smoke.test.ts +52 -0
- package/dist/extensions/pi-subagents/test/integration/claude-code-writer-smoke.test.ts +55 -0
- package/dist/extensions/pi-subagents/test/integration/codex-exec-smoke.test.ts +53 -0
- package/dist/extensions/pi-subagents/test/integration/codex-exec-writer-smoke.test.ts +57 -0
- package/dist/extensions/pi-subagents/test/integration/cursor-agent-smoke.test.ts +59 -0
- package/dist/extensions/pi-subagents/test/integration/cursor-agent-writer-smoke.test.ts +62 -0
- package/dist/extensions/pi-subagents/test/integration/error-handling.test.ts +57 -1
- package/dist/extensions/pi-subagents/test/integration/external-cli-runner.test.ts +1 -0
- package/dist/extensions/pi-subagents/test/integration/fork-context-execution.test.ts +20 -0
- package/dist/extensions/pi-subagents/test/integration/intercom-result-delivery.test.ts +4 -3
- package/dist/extensions/pi-subagents/test/integration/orca-progress-tabs.test.ts +2 -2
- package/dist/extensions/pi-subagents/test/integration/render-fork-badge.test.ts +54 -4
- package/dist/extensions/pi-subagents/test/integration/render-widget.test.ts +482 -4
- package/dist/extensions/pi-subagents/test/integration/result-watcher.test.ts +157 -9
- package/dist/extensions/pi-subagents/test/integration/session-tokens.test.ts +5 -5
- package/dist/extensions/pi-subagents/test/integration/single-execution.test.ts +1508 -291
- package/dist/extensions/pi-subagents/test/integration/slash-commands.test.ts +423 -1
- package/dist/extensions/pi-subagents/test/integration/template-resolution.test.ts +8 -0
- package/dist/extensions/pi-subagents/test/support/cursor-smoke-inputs.ts +51 -0
- package/dist/extensions/pi-subagents/test/support/helpers.ts +2 -0
- package/dist/extensions/pi-subagents/test/support/mock-pi.ts +5 -5
- package/dist/extensions/pi-subagents/test/support/real-session-runner.ts +6 -6
- package/dist/extensions/pi-subagents/test/unit/abort-recovery.test.ts +152 -0
- package/dist/extensions/pi-subagents/test/unit/active-async-capacity.test.ts +48 -0
- package/dist/extensions/pi-subagents/test/unit/agent-frontmatter.test.ts +184 -6
- package/dist/extensions/pi-subagents/test/unit/agent-management.test.ts +66 -6
- package/dist/extensions/pi-subagents/test/unit/agent-overrides.test.ts +77 -0
- package/dist/extensions/pi-subagents/test/unit/agent-refinements.test.ts +18 -0
- package/dist/extensions/pi-subagents/test/unit/anti-slop-oxlint.test.ts +86 -0
- package/dist/extensions/pi-subagents/test/unit/artifacts.test.ts +1 -1
- package/dist/extensions/pi-subagents/test/unit/async-execution.test.ts +101 -1
- package/dist/extensions/pi-subagents/test/unit/async-interrupt-action.test.ts +121 -0
- package/dist/extensions/pi-subagents/test/unit/async-recovery-descriptor.test.ts +28 -0
- package/dist/extensions/pi-subagents/test/unit/async-resume.test.ts +14 -7
- package/dist/extensions/pi-subagents/test/unit/async-retention.test.ts +53 -0
- package/dist/extensions/pi-subagents/test/unit/async-status-projection.test.ts +190 -0
- package/dist/extensions/pi-subagents/test/unit/async-status-snapshot.test.ts +42 -0
- package/dist/extensions/pi-subagents/test/unit/auto-drain.test.ts +8 -4
- package/dist/extensions/pi-subagents/test/unit/background-work.test.ts +23 -0
- package/dist/extensions/pi-subagents/test/unit/chain-root-attachment.test.ts +78 -1
- package/dist/extensions/pi-subagents/test/unit/child-launch-plan.test.ts +94 -0
- package/dist/extensions/pi-subagents/test/unit/child-protocol.test.ts +21 -0
- package/dist/extensions/pi-subagents/test/unit/child-session-name.test.ts +50 -0
- package/dist/extensions/pi-subagents/test/unit/claude-code-adapter.test.ts +245 -0
- package/dist/extensions/pi-subagents/test/unit/codex-exec-adapter.test.ts +192 -0
- package/dist/extensions/pi-subagents/test/unit/compaction-resume.test.ts +27 -0
- package/dist/extensions/pi-subagents/test/unit/completion-evidence.test.ts +150 -0
- package/dist/extensions/pi-subagents/test/unit/completion-guard.test.ts +21 -0
- package/dist/extensions/pi-subagents/test/unit/cursor-agent-adapter.test.ts +259 -0
- package/dist/extensions/pi-subagents/test/unit/cursor-smoke-inputs.test.ts +77 -0
- package/dist/extensions/pi-subagents/test/unit/delegation-api.test.ts +1 -4
- package/dist/extensions/pi-subagents/test/unit/doctor.test.ts +1 -1
- package/dist/extensions/pi-subagents/test/unit/extension-context.test.ts +27 -0
- package/dist/extensions/pi-subagents/test/unit/external-cli-runner.test.ts +223 -0
- package/dist/extensions/pi-subagents/test/unit/fast-mode-extension.test.ts +27 -0
- package/dist/extensions/pi-subagents/test/unit/fleet-status.test.ts +208 -2
- package/dist/extensions/pi-subagents/test/unit/fleet-transcript.test.ts +29 -1
- package/dist/extensions/pi-subagents/test/unit/fleet.test.ts +110 -1
- package/dist/extensions/pi-subagents/test/unit/foreground-control.test.ts +10 -0
- package/dist/extensions/pi-subagents/test/unit/formatters.test.ts +14 -0
- package/dist/extensions/pi-subagents/test/unit/herdr-inspector.test.ts +18 -9
- package/dist/extensions/pi-subagents/test/unit/herdr-session-roots-codec.test.ts +63 -0
- package/dist/extensions/pi-subagents/test/unit/herdr-shell-command.test.ts +2 -2
- package/dist/extensions/pi-subagents/test/unit/herdr-status-bridge.test.ts +136 -6
- package/dist/extensions/pi-subagents/test/unit/host-command.test.ts +156 -0
- package/dist/extensions/pi-subagents/test/unit/host-step-status.test.ts +98 -0
- package/dist/extensions/pi-subagents/test/unit/index-child-registration.test.ts +178 -26
- package/dist/extensions/pi-subagents/test/unit/index-segment.test.ts +2 -1
- package/dist/extensions/pi-subagents/test/unit/inspect-rpc.test.ts +21 -0
- package/dist/extensions/pi-subagents/test/unit/mcp-direct-tool-grant.test.ts +138 -0
- package/dist/extensions/pi-subagents/test/unit/mission-lifecycle.test.ts +1 -1
- package/dist/extensions/pi-subagents/test/unit/model-exclusions.test.ts +91 -0
- package/dist/extensions/pi-subagents/test/unit/model-fallback.test.ts +72 -7
- package/dist/extensions/pi-subagents/test/unit/mutation-evidence.test.ts +21 -0
- package/dist/extensions/pi-subagents/test/unit/nested-control.test.ts +1 -0
- package/dist/extensions/pi-subagents/test/unit/nested-events.test.ts +20 -2
- package/dist/extensions/pi-subagents/test/unit/notify.test.ts +129 -1
- package/dist/extensions/pi-subagents/test/unit/orca-progress-tabs.test.ts +2 -2
- package/dist/extensions/pi-subagents/test/unit/package-manifest.test.ts +4 -0
- package/dist/extensions/pi-subagents/test/unit/parallel-handoff.test.ts +358 -0
- package/dist/extensions/pi-subagents/test/unit/pi-args.test.ts +574 -21
- package/dist/extensions/pi-subagents/test/unit/pi-coding-agent-dir.test.ts +109 -1
- package/dist/extensions/pi-subagents/test/unit/preflight.test.ts +71 -1
- package/dist/extensions/pi-subagents/test/unit/profiles.test.ts +7 -7
- package/dist/extensions/pi-subagents/test/unit/pruned-fork.test.ts +214 -0
- package/dist/extensions/pi-subagents/test/unit/public-execution.test.ts +29 -8
- package/dist/extensions/pi-subagents/test/unit/render-helpers.test.ts +53 -0
- package/dist/extensions/pi-subagents/test/unit/result-delivery-ownership.test.ts +34 -0
- package/dist/extensions/pi-subagents/test/unit/result-files.test.ts +101 -3
- package/dist/extensions/pi-subagents/test/unit/retained-children.test.ts +1 -0
- package/dist/extensions/pi-subagents/test/unit/rpc.test.ts +10 -8
- package/dist/extensions/pi-subagents/test/unit/run-fanout-budget.test.ts +71 -1
- package/dist/extensions/pi-subagents/test/unit/run-status.test.ts +41 -7
- package/dist/extensions/pi-subagents/test/unit/runtime-agent-registration.test.ts +136 -2
- package/dist/extensions/pi-subagents/test/unit/scheduled-runs.test.ts +137 -0
- package/dist/extensions/pi-subagents/test/unit/schemas.test.ts +33 -12
- package/dist/extensions/pi-subagents/test/unit/scripted-workflow.test.ts +504 -1
- package/dist/extensions/pi-subagents/test/unit/single-output.test.ts +8 -0
- package/dist/extensions/pi-subagents/test/unit/skills-fallback.test.ts +1 -1
- package/dist/extensions/pi-subagents/test/unit/stale-run-reconciler.test.ts +12 -1
- package/dist/extensions/pi-subagents/test/unit/steering-action.test.ts +3 -5
- package/dist/extensions/pi-subagents/test/unit/steering.test.ts +5 -6
- package/dist/extensions/pi-subagents/test/unit/subagent-action-recovery.test.ts +0 -8
- package/dist/extensions/pi-subagents/test/unit/subagent-guide.test.ts +5 -0
- package/dist/extensions/pi-subagents/test/unit/subagent-prompt-runtime.test.ts +157 -2
- package/dist/extensions/pi-subagents/test/unit/subagent-startup-retry.test.ts +1 -1
- package/dist/extensions/pi-subagents/test/unit/subagent-wait.test.ts +63 -4
- package/dist/extensions/pi-subagents/test/unit/tool-description.test.ts +27 -23
- package/dist/extensions/pi-subagents/test/unit/wait-completions.test.ts +44 -0
- package/dist/extensions/pi-subagents/test/unit/wait-subscriptions.test.ts +1 -0
- package/dist/extensions/pi-subagents/test/unit/widget-nested-render.test.ts +7 -5
- package/dist/extensions/pi-subagents/test/unit/workflow-chat-progress.test.ts +106 -0
- package/dist/extensions/pi-subagents/test/unit/workflow-detach-reconcile.test.ts +484 -9
- package/dist/extensions/pi-subagents/test/unit/workflow-launch-params.test.ts +38 -4
- package/dist/extensions/pi-subagents/test/unit/workflow-preflight.test.ts +155 -0
- package/dist/extensions/pi-subagents/test/unit/workflow-receipt.test.ts +318 -0
- package/dist/extensions/pi-subagents/test/unit/workflow-resume-hint.test.ts +365 -0
- package/dist/extensions/pi-subagents/test/unit/worktree-cleanup-plan.test.ts +349 -0
- package/dist/extensions/pi-subagents/test/unit/worktree.test.ts +21 -0
- package/dist/extensions/pi-subagents/test/unit/writer-budget-guidance.test.ts +2 -7
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/effect/index.ts +13 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/effect/rules/no-service-constructor-imports.ts +52 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/index.ts +41 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-chained-type-assertions.ts +77 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-conditional-empty-object-spread.ts +49 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-known-value-widening.ts +247 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-module-mocking.ts +91 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-object-parameters.ts +126 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-reflect-apply.ts +28 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-reflect-get.ts +28 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-runtime-typeof.ts +67 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-shape-in-symbol-names.ts +39 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-unknown-parameters.ts +83 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-unknown-returns.ts +115 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-unknown-type-aliases.ts +72 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-unsafe-dictionary-type.ts +134 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/no-widen-then-assert.ts +366 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/rules/require-safety-comment-for-type-assertion.ts +62 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/shared/dictionary-types.ts +502 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/shared/lexical-type-parameters.ts +60 -0
- package/dist/extensions/pi-subagents/tools/oxlint/anti-slop/shared/reflect-method.ts +35 -0
- package/dist/extensions/pi-tool-display/tests/capabilities.test.ts +1 -1
- package/dist/extensions/pi-tool-display/tests/settings-inspector.test.ts +2 -2
- package/dist/extensions/pi-tool-display/tests/tool-overrides-mcp.test.ts +1 -1
- package/dist/modes/interactive/interactive-mode.js +7 -7
- package/dist/skills/workflow/SKILL.md +65 -50
- package/package.json +112 -110
- package/dist/extensions/enable-readonly-tools.test.ts +0 -63
- package/dist/extensions/enable-readonly-tools.ts +0 -24
- package/dist/extensions/model-prompt-injector/config.json +0 -16
- package/dist/extensions/model-prompt-injector/index.test.ts +0 -102
- package/dist/extensions/model-prompt-injector/index.ts +0 -148
- package/dist/extensions/pi-subagents/src/runs/shared/turn-budget.ts +0 -98
- package/dist/extensions/pi-subagents/test/unit/turn-budget.test.ts +0 -250
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
import { describe, it, afterEach } from "node:test";
|
|
2
|
+
import * as assert from "node:assert/strict";
|
|
3
|
+
import * as fs from "node:fs";
|
|
4
|
+
import * as os from "node:os";
|
|
5
|
+
import * as path from "node:path";
|
|
6
|
+
import { registerSessionSearchTool } from "../../src/tools/session-search-tool.js";
|
|
7
|
+
import { DatabaseManager } from "../../src/store/db.js";
|
|
8
|
+
import { indexSession } from "../../src/store/session-indexer.js";
|
|
9
|
+
|
|
10
|
+
let ROOT_DIR = "";
|
|
11
|
+
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
if (ROOT_DIR) fs.rmSync(ROOT_DIR, { recursive: true, force: true });
|
|
14
|
+
ROOT_DIR = "";
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
function makeSessionsDir(): string {
|
|
18
|
+
ROOT_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "pi-session-search-tool-test-"));
|
|
19
|
+
return ROOT_DIR;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
describe("registerSessionSearchTool", () => {
|
|
23
|
+
it("registers the legacy query schema by default", () => {
|
|
24
|
+
let captured: any;
|
|
25
|
+
const mockPi = {
|
|
26
|
+
registerTool: (def: any) => { captured = def; },
|
|
27
|
+
} as any;
|
|
28
|
+
|
|
29
|
+
registerSessionSearchTool(mockPi, {} as any);
|
|
30
|
+
|
|
31
|
+
const schema = JSON.stringify(captured.parameters);
|
|
32
|
+
assert.strictEqual(captured.name, "session_search");
|
|
33
|
+
assert.match(schema, /query/);
|
|
34
|
+
assert.doesNotMatch(schema, /markdown/);
|
|
35
|
+
assert.match(schema, /"minimum":1/);
|
|
36
|
+
assert.match(schema, /"maximum":20/);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("clamps negative and fractional legacy limits before querying", async () => {
|
|
40
|
+
let captured: any;
|
|
41
|
+
const mockPi = {
|
|
42
|
+
registerTool: (def: any) => { captured = def; },
|
|
43
|
+
} as any;
|
|
44
|
+
const memoryDir = makeSessionsDir();
|
|
45
|
+
const dbManager = new DatabaseManager(memoryDir);
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
indexSession(dbManager, {
|
|
49
|
+
id: "bounded-limit-session",
|
|
50
|
+
project: "bounded-project",
|
|
51
|
+
cwd: "/work/bounded",
|
|
52
|
+
startedAt: "2026-07-11T00:00:00.000Z",
|
|
53
|
+
endedAt: null,
|
|
54
|
+
messages: Array.from({ length: 25 }, (_, index) => ({
|
|
55
|
+
id: `bounded-limit-message-${index}`,
|
|
56
|
+
role: "assistant",
|
|
57
|
+
content: `bounded-limit-needle ${index}`,
|
|
58
|
+
timestamp: `2026-07-11T00:${String(index).padStart(2, "0")}:00.000Z`,
|
|
59
|
+
})),
|
|
60
|
+
});
|
|
61
|
+
registerSessionSearchTool(mockPi, dbManager);
|
|
62
|
+
|
|
63
|
+
const negative = await captured.execute("tc-negative-limit", {
|
|
64
|
+
query: "bounded-limit-needle",
|
|
65
|
+
limit: -1,
|
|
66
|
+
});
|
|
67
|
+
const fractional = await captured.execute("tc-fractional-limit", {
|
|
68
|
+
query: "bounded-limit-needle",
|
|
69
|
+
limit: 2.9,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
assert.strictEqual(negative.details.count, 1);
|
|
73
|
+
assert.strictEqual(fractional.details.count, 2);
|
|
74
|
+
assert.ok(negative.content[0].text.length < 2_000);
|
|
75
|
+
assert.ok(fractional.content[0].text.length < 4_000);
|
|
76
|
+
} finally {
|
|
77
|
+
dbManager.close();
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("clamps non-finite snippetChars values instead of propagating NaN", async () => {
|
|
82
|
+
let captured: any;
|
|
83
|
+
const mockPi = {
|
|
84
|
+
registerTool: (def: any) => { captured = def; },
|
|
85
|
+
} as any;
|
|
86
|
+
const memoryDir = makeSessionsDir();
|
|
87
|
+
const dbManager = new DatabaseManager(memoryDir);
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
indexSession(dbManager, {
|
|
91
|
+
id: "nan-snippet-session",
|
|
92
|
+
project: "nan-snippet-project",
|
|
93
|
+
cwd: "/work/nan-snippet",
|
|
94
|
+
startedAt: "2026-07-11T00:00:00.000Z",
|
|
95
|
+
endedAt: null,
|
|
96
|
+
messages: [{
|
|
97
|
+
id: "nan-snippet-message",
|
|
98
|
+
role: "assistant",
|
|
99
|
+
content: `needle ${"a".repeat(500)}`,
|
|
100
|
+
timestamp: "2026-07-11T00:01:00.000Z",
|
|
101
|
+
}],
|
|
102
|
+
});
|
|
103
|
+
registerSessionSearchTool(mockPi, dbManager);
|
|
104
|
+
|
|
105
|
+
const nanResult = await captured.execute("tc-nan-snippet", {
|
|
106
|
+
query: "needle",
|
|
107
|
+
snippetChars: NaN,
|
|
108
|
+
});
|
|
109
|
+
const infinityResult = await captured.execute("tc-infinity-snippet", {
|
|
110
|
+
query: "needle",
|
|
111
|
+
snippetChars: Infinity,
|
|
112
|
+
});
|
|
113
|
+
const largeResult = await captured.execute("tc-large-snippet", {
|
|
114
|
+
query: "needle",
|
|
115
|
+
snippetChars: 999_999_999,
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
assert.strictEqual(nanResult.details.snippetChars, 1_200);
|
|
119
|
+
assert.strictEqual(infinityResult.details.snippetChars, 1_200);
|
|
120
|
+
assert.strictEqual(largeResult.details.snippetChars, 4_000);
|
|
121
|
+
assert.ok(Number.isFinite(nanResult.details.snippetChars));
|
|
122
|
+
assert.match(nanResult.content[0].text, /needle a+/);
|
|
123
|
+
} finally {
|
|
124
|
+
dbManager.close();
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it("bounds oversized legacy results and reports truncation without duplicating output in details", async () => {
|
|
129
|
+
let captured: any;
|
|
130
|
+
const mockPi = {
|
|
131
|
+
registerTool: (def: any) => { captured = def; },
|
|
132
|
+
} as any;
|
|
133
|
+
const memoryDir = makeSessionsDir();
|
|
134
|
+
const dbManager = new DatabaseManager(memoryDir);
|
|
135
|
+
const oversizedContent = `needle ${"x".repeat(6_000_000)}`;
|
|
136
|
+
|
|
137
|
+
try {
|
|
138
|
+
// Seed a pre-cap database row directly. New ingestion paths must cap
|
|
139
|
+
// message content, but search output still needs to stay bounded for
|
|
140
|
+
// oversized rows written by older extension versions.
|
|
141
|
+
const db = dbManager.getDb();
|
|
142
|
+
db.prepare(`
|
|
143
|
+
INSERT INTO sessions (id, project, cwd, started_at, ended_at, message_count)
|
|
144
|
+
VALUES (?, ?, ?, ?, ?, ?)
|
|
145
|
+
`).run(
|
|
146
|
+
"oversized-session",
|
|
147
|
+
"oversized-project",
|
|
148
|
+
"/work/oversized",
|
|
149
|
+
"2026-07-11T00:00:00.000Z",
|
|
150
|
+
null,
|
|
151
|
+
1,
|
|
152
|
+
);
|
|
153
|
+
db.prepare(`
|
|
154
|
+
INSERT INTO messages (id, session_id, role, content, timestamp)
|
|
155
|
+
VALUES (?, ?, ?, ?, ?)
|
|
156
|
+
`).run(
|
|
157
|
+
"oversized-message",
|
|
158
|
+
"oversized-session",
|
|
159
|
+
"assistant",
|
|
160
|
+
oversizedContent,
|
|
161
|
+
"2026-07-11T00:01:00.000Z",
|
|
162
|
+
);
|
|
163
|
+
registerSessionSearchTool(mockPi, dbManager);
|
|
164
|
+
|
|
165
|
+
const result = await captured.execute("tc-oversized", { query: "needle" });
|
|
166
|
+
const output = result.content[0].text as string;
|
|
167
|
+
|
|
168
|
+
assert.ok(output.length <= 50 * 1024, `expected <= 50 KiB, got ${output.length}`);
|
|
169
|
+
assert.match(output, /truncated/);
|
|
170
|
+
assert.match(output, /6000007 chars total/);
|
|
171
|
+
assert.strictEqual(result.details.truncatedCount, 1);
|
|
172
|
+
assert.strictEqual(result.details.outputChars, output.length);
|
|
173
|
+
assert.strictEqual(result.details.output, undefined);
|
|
174
|
+
assert.ok(JSON.stringify(result.details).length < 1_000);
|
|
175
|
+
} finally {
|
|
176
|
+
dbManager.close();
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it("offers a bounded snippetChars override for legacy searches", async () => {
|
|
181
|
+
let captured: any;
|
|
182
|
+
const mockPi = {
|
|
183
|
+
registerTool: (def: any) => { captured = def; },
|
|
184
|
+
} as any;
|
|
185
|
+
const memoryDir = makeSessionsDir();
|
|
186
|
+
const dbManager = new DatabaseManager(memoryDir);
|
|
187
|
+
|
|
188
|
+
try {
|
|
189
|
+
indexSession(dbManager, {
|
|
190
|
+
id: "bounded-override-session",
|
|
191
|
+
project: "bounded-project",
|
|
192
|
+
cwd: "/work/bounded",
|
|
193
|
+
startedAt: "2026-07-11T00:00:00.000Z",
|
|
194
|
+
endedAt: null,
|
|
195
|
+
messages: [{
|
|
196
|
+
id: "bounded-override-message",
|
|
197
|
+
role: "assistant",
|
|
198
|
+
content: `needle ${"y".repeat(10_000)}`,
|
|
199
|
+
timestamp: "2026-07-11T00:01:00.000Z",
|
|
200
|
+
}],
|
|
201
|
+
});
|
|
202
|
+
registerSessionSearchTool(mockPi, dbManager);
|
|
203
|
+
|
|
204
|
+
assert.match(JSON.stringify(captured.parameters), /snippetChars/);
|
|
205
|
+
const result = await captured.execute("tc-bounded-override", {
|
|
206
|
+
query: "needle",
|
|
207
|
+
snippetChars: 2_000,
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
assert.strictEqual(result.details.snippetChars, 2_000);
|
|
211
|
+
assert.strictEqual(result.details.truncatedCount, 1);
|
|
212
|
+
assert.match(result.content[0].text, /10007 chars total/);
|
|
213
|
+
assert.ok(result.content[0].text.length < 3_000);
|
|
214
|
+
} finally {
|
|
215
|
+
dbManager.close();
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it("enforces a hard 50 KiB ceiling across many large legacy results", async () => {
|
|
220
|
+
let captured: any;
|
|
221
|
+
const mockPi = {
|
|
222
|
+
registerTool: (def: any) => { captured = def; },
|
|
223
|
+
} as any;
|
|
224
|
+
const memoryDir = makeSessionsDir();
|
|
225
|
+
const dbManager = new DatabaseManager(memoryDir);
|
|
226
|
+
|
|
227
|
+
try {
|
|
228
|
+
indexSession(dbManager, {
|
|
229
|
+
id: "aggregate-ceiling-session",
|
|
230
|
+
project: "aggregate-project",
|
|
231
|
+
cwd: "/work/aggregate",
|
|
232
|
+
startedAt: "2026-07-11T00:00:00.000Z",
|
|
233
|
+
endedAt: null,
|
|
234
|
+
messages: Array.from({ length: 20 }, (_, index) => ({
|
|
235
|
+
id: `aggregate-message-${index}`,
|
|
236
|
+
role: "assistant",
|
|
237
|
+
content: `needle-${index} ${"z".repeat(10_000)}`,
|
|
238
|
+
timestamp: `2026-07-11T00:${String(index).padStart(2, "0")}:00.000Z`,
|
|
239
|
+
})),
|
|
240
|
+
});
|
|
241
|
+
registerSessionSearchTool(mockPi, dbManager);
|
|
242
|
+
|
|
243
|
+
const result = await captured.execute("tc-aggregate-ceiling", {
|
|
244
|
+
query: "needle",
|
|
245
|
+
limit: 20,
|
|
246
|
+
snippetChars: 4_000,
|
|
247
|
+
});
|
|
248
|
+
const output = result.content[0].text as string;
|
|
249
|
+
|
|
250
|
+
assert.ok(output.length <= 50 * 1024, `expected <= 50 KiB, got ${output.length}`);
|
|
251
|
+
assert.strictEqual(result.details.outputTruncated, true);
|
|
252
|
+
assert.match(output, /output truncated/);
|
|
253
|
+
assert.match(output, /refine the query or lower the result limit/);
|
|
254
|
+
} finally {
|
|
255
|
+
dbManager.close();
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it("bounds the zero-result response without echoing an oversized query", async () => {
|
|
260
|
+
let captured: any;
|
|
261
|
+
const mockPi = {
|
|
262
|
+
registerTool: (def: any) => { captured = def; },
|
|
263
|
+
} as any;
|
|
264
|
+
const memoryDir = makeSessionsDir();
|
|
265
|
+
const dbManager = new DatabaseManager(memoryDir);
|
|
266
|
+
|
|
267
|
+
try {
|
|
268
|
+
indexSession(dbManager, {
|
|
269
|
+
id: "zero-result-session",
|
|
270
|
+
project: "zero-result-project",
|
|
271
|
+
cwd: "/work/zero-result",
|
|
272
|
+
startedAt: "2026-07-11T00:00:00.000Z",
|
|
273
|
+
endedAt: null,
|
|
274
|
+
messages: [{
|
|
275
|
+
id: "zero-result-message",
|
|
276
|
+
role: "assistant",
|
|
277
|
+
content: "indexed haystack",
|
|
278
|
+
timestamp: "2026-07-11T00:01:00.000Z",
|
|
279
|
+
}],
|
|
280
|
+
});
|
|
281
|
+
registerSessionSearchTool(mockPi, dbManager);
|
|
282
|
+
const query = `${" ".repeat(60_000)}missing`;
|
|
283
|
+
|
|
284
|
+
const result = await captured.execute("tc-zero-result", { query });
|
|
285
|
+
const output = result.content[0].text as string;
|
|
286
|
+
|
|
287
|
+
assert.strictEqual(result.details.count, 0);
|
|
288
|
+
assert.ok(output.length <= 50 * 1024, `expected <= 50 KiB, got ${output.length}`);
|
|
289
|
+
assert.strictEqual(output.includes(query), false);
|
|
290
|
+
assert.ok(JSON.stringify(result.details).length < 1_000);
|
|
291
|
+
} finally {
|
|
292
|
+
dbManager.close();
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
it("registers and executes the anchor markdown-only schema when configured", async () => {
|
|
297
|
+
let captured: any;
|
|
298
|
+
const mockPi = {
|
|
299
|
+
registerTool: (def: any) => { captured = def; },
|
|
300
|
+
} as any;
|
|
301
|
+
const sessionsDir = makeSessionsDir();
|
|
302
|
+
const filePath = path.join(sessionsDir, "session.jsonl");
|
|
303
|
+
fs.writeFileSync(filePath, `${JSON.stringify({
|
|
304
|
+
type: "message",
|
|
305
|
+
timestamp: "2026-05-15T10:00:00.000Z",
|
|
306
|
+
sessionId: "session-1",
|
|
307
|
+
cwd: "/work/project",
|
|
308
|
+
message: { role: "user", content: "needle" },
|
|
309
|
+
})}\n`);
|
|
310
|
+
|
|
311
|
+
registerSessionSearchTool(mockPi, {} as any, { variant: "anchors" }, { sessionsDir });
|
|
312
|
+
|
|
313
|
+
const schema = JSON.stringify(captured.parameters);
|
|
314
|
+
assert.strictEqual(captured.name, "session_search");
|
|
315
|
+
assert.match(schema, /markdown/);
|
|
316
|
+
assert.doesNotMatch(schema, /query/);
|
|
317
|
+
assert.match(captured.description, /all terms must match/);
|
|
318
|
+
assert.match(captured.description, /any requires at least one listed term/);
|
|
319
|
+
assert.match(captured.description, /exclude removes matching ranges/);
|
|
320
|
+
assert.match(captured.description, /Output is plain text: count, optional message/);
|
|
321
|
+
assert.match(captured.description, /path:startLine-endLine with a short reason/);
|
|
322
|
+
assert.match(captured.description, /Example:\nfrom: 2026-05-14/);
|
|
323
|
+
assert.match(captured.promptGuidelines.join("\n"), /Use all for required terms/);
|
|
324
|
+
|
|
325
|
+
const empty = await captured.execute("tc-1", { markdown: "" });
|
|
326
|
+
assert.strictEqual(empty.details.success, false);
|
|
327
|
+
assert.strictEqual(empty.details.message, "markdown is required");
|
|
328
|
+
|
|
329
|
+
const result = await captured.execute("tc-2", { markdown: "any:\n- needle" });
|
|
330
|
+
assert.strictEqual(result.details.success, true);
|
|
331
|
+
assert.strictEqual(result.details.count, 1);
|
|
332
|
+
assert.deepStrictEqual(result.details.ranges.map((range: any) => ({
|
|
333
|
+
path: range.path,
|
|
334
|
+
startLine: range.startLine,
|
|
335
|
+
endLine: range.endLine,
|
|
336
|
+
reason: range.reason,
|
|
337
|
+
})), [{ path: filePath, startLine: 1, endLine: 1, reason: "matched any: needle" }]);
|
|
338
|
+
assert.strictEqual(result.details.output, result.content[0].text);
|
|
339
|
+
assert.match(result.content[0].text, /^count: 1\nanchors:\n-/);
|
|
340
|
+
assert.match(result.content[0].text, new RegExp(`${filePath.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}:1-1 — matched any: needle`));
|
|
341
|
+
assert.doesNotMatch(result.content[0].text, /"ranges"/);
|
|
342
|
+
assert.doesNotMatch(result.content[0].text, /"startLine"/);
|
|
343
|
+
assert.doesNotMatch(result.content[0].text, /"sessionId"/);
|
|
344
|
+
});
|
|
345
|
+
});
|
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
import { describe, it } from "node:test";
|
|
2
|
+
import * as assert from "node:assert/strict";
|
|
3
|
+
import { initTheme } from "@earendil-works/pi-coding-agent";
|
|
4
|
+
import { Box, visibleWidth, type Component } from "@earendil-works/pi-tui";
|
|
5
|
+
import {
|
|
6
|
+
createSharedToolResultRenderer,
|
|
7
|
+
type SharedOutputView,
|
|
8
|
+
} from "../../src/tools/shared-output-view.js";
|
|
9
|
+
import {
|
|
10
|
+
memoryResultView,
|
|
11
|
+
searchResultView,
|
|
12
|
+
skillResultView,
|
|
13
|
+
} from "../../src/tools/tool-result-views.js";
|
|
14
|
+
|
|
15
|
+
initTheme();
|
|
16
|
+
|
|
17
|
+
function fakeTheme() {
|
|
18
|
+
return {
|
|
19
|
+
fg: (_color: string, text: string): string => text,
|
|
20
|
+
getBgAnsi: (_color: string): string => "",
|
|
21
|
+
} as any;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function stripAnsi(text: string): string {
|
|
25
|
+
return text.replace(/\x1b\[[0-?]*[ -/]*m/g, "");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function renderPlain(component: Component, width = 120): string {
|
|
29
|
+
return component.render(width).map((row) => stripAnsi(row).trimEnd()).join("\n");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function result(text: string, details: Record<string, unknown> = { success: true }) {
|
|
33
|
+
return { content: [{ type: "text", text }], details };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function renderToolResult(
|
|
37
|
+
toolResult: ReturnType<typeof result>,
|
|
38
|
+
expanded: boolean,
|
|
39
|
+
width = 120,
|
|
40
|
+
): string {
|
|
41
|
+
return renderPlain(
|
|
42
|
+
createSharedToolResultRenderer()(
|
|
43
|
+
toolResult,
|
|
44
|
+
{ expanded, isPartial: false },
|
|
45
|
+
fakeTheme(),
|
|
46
|
+
{ isError: false },
|
|
47
|
+
),
|
|
48
|
+
width,
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function renderView(view: SharedOutputView, expanded: boolean, width = 120): string {
|
|
53
|
+
return renderPlain(
|
|
54
|
+
createSharedToolResultRenderer(() => view)(
|
|
55
|
+
result(view.expandedText),
|
|
56
|
+
{ expanded, isPartial: false },
|
|
57
|
+
fakeTheme(),
|
|
58
|
+
{ isError: false },
|
|
59
|
+
),
|
|
60
|
+
width,
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function assertRowKeepsBackground(row: string): void {
|
|
65
|
+
let backgroundActive = false;
|
|
66
|
+
for (let index = 0; index < row.length;) {
|
|
67
|
+
const sgr = row.slice(index).match(/^\x1b\[([0-9;]*)m/);
|
|
68
|
+
if (sgr) {
|
|
69
|
+
const parameters = sgr[1];
|
|
70
|
+
if (parameters === "" || parameters === "0" || parameters === "49") {
|
|
71
|
+
backgroundActive = false;
|
|
72
|
+
} else if (parameters.split(";")[0] === "48") {
|
|
73
|
+
backgroundActive = true;
|
|
74
|
+
}
|
|
75
|
+
index += sgr[0].length;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
assert.equal(backgroundActive, true, `background cleared before ${JSON.stringify(row.slice(index))}`);
|
|
79
|
+
index += 1;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
describe("shared tool-result view", () => {
|
|
84
|
+
it("collapses to one concise line and expands to the full bounded result", () => {
|
|
85
|
+
const toolResult = result("Found 2 memories matching auth:\n\nfirst\nsecond", {
|
|
86
|
+
success: true,
|
|
87
|
+
count: 2,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const collapsed = renderToolResult(toolResult, false);
|
|
91
|
+
assert.equal(collapsed.split("\n").length, 1);
|
|
92
|
+
assert.match(collapsed, /Found 2 memories matching auth/);
|
|
93
|
+
assert.doesNotMatch(collapsed, /second/);
|
|
94
|
+
assert.match(collapsed, /expand/);
|
|
95
|
+
|
|
96
|
+
const expanded = renderToolResult(toolResult, true);
|
|
97
|
+
assert.equal(expanded, toolResult.content[0].text);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("sanitizes only the rendered copy of hostile tool text and failure details", () => {
|
|
101
|
+
const hostileText = [
|
|
102
|
+
"safe 世界 \x1b]52;c;YXR0YWNr\x07 after OSC",
|
|
103
|
+
"styled \x1b[31mred\x1b[0m moved \x1b[2J after CSI",
|
|
104
|
+
"private \x1bPdanger\x1b\\ after DCS",
|
|
105
|
+
"linked \x1b]8;;https://evil.example\x1b\\label\x1b]8;;\x1b\\ after ST",
|
|
106
|
+
"carriage\rreturn binary\x00\x08\x7f end",
|
|
107
|
+
].join("\n");
|
|
108
|
+
const hostileReason = "query \x1b]52;c;YXR0YWNr\x07 is required\x00";
|
|
109
|
+
const toolResult = result(hostileText, {
|
|
110
|
+
success: false,
|
|
111
|
+
message: hostileReason,
|
|
112
|
+
nested: { keep: true },
|
|
113
|
+
});
|
|
114
|
+
const before = structuredClone(toolResult);
|
|
115
|
+
|
|
116
|
+
const collapsed = renderToolResult(toolResult, false);
|
|
117
|
+
const expanded = renderToolResult(toolResult, true);
|
|
118
|
+
|
|
119
|
+
for (const rendered of [collapsed, expanded]) {
|
|
120
|
+
assert.doesNotMatch(rendered, /\x1b|\x07|\x00|\x08|\x7f|\r/);
|
|
121
|
+
}
|
|
122
|
+
assert.match(collapsed, /query .* is required/);
|
|
123
|
+
assert.match(expanded, /safe 世界/);
|
|
124
|
+
assert.match(expanded, /styled red moved after CSI/);
|
|
125
|
+
assert.match(expanded, /private danger\\ after DCS/);
|
|
126
|
+
assert.match(expanded, /linked label after ST/);
|
|
127
|
+
assert.match(expanded, /carriagereturn binary end/);
|
|
128
|
+
assert.deepEqual(toolResult, before);
|
|
129
|
+
|
|
130
|
+
const adapterResult = result("safe", {
|
|
131
|
+
success: true,
|
|
132
|
+
message: "Entry added.",
|
|
133
|
+
target: "memory\x1b[2J",
|
|
134
|
+
usage: "1 entry\x00",
|
|
135
|
+
});
|
|
136
|
+
const adapterBefore = structuredClone(adapterResult);
|
|
137
|
+
const adapterRendered = renderPlain(createSharedToolResultRenderer(memoryResultView)(
|
|
138
|
+
adapterResult,
|
|
139
|
+
{ expanded: false, isPartial: false },
|
|
140
|
+
fakeTheme(),
|
|
141
|
+
{ isError: false },
|
|
142
|
+
));
|
|
143
|
+
assert.doesNotMatch(adapterRendered, /\x1b|\x00/);
|
|
144
|
+
assert.deepEqual(adapterResult, adapterBefore);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("does not mutate model-visible content or details", () => {
|
|
148
|
+
const toolResult = result("immutable\nfull output", {
|
|
149
|
+
success: true,
|
|
150
|
+
nested: { keep: true },
|
|
151
|
+
});
|
|
152
|
+
const before = structuredClone(toolResult);
|
|
153
|
+
|
|
154
|
+
renderToolResult(toolResult, false);
|
|
155
|
+
renderToolResult(toolResult, true);
|
|
156
|
+
|
|
157
|
+
assert.deepEqual(toolResult, before);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("keeps textual failure and warning reasons in collapsed output", () => {
|
|
161
|
+
const failure = renderToolResult(
|
|
162
|
+
result("query is required", { success: false, message: "query is required" }),
|
|
163
|
+
false,
|
|
164
|
+
);
|
|
165
|
+
assert.match(failure, /query is required/);
|
|
166
|
+
|
|
167
|
+
const warningView = memoryResultView(result(JSON.stringify({
|
|
168
|
+
success: true,
|
|
169
|
+
message: "Entry added. Warning: SQLite mirror unavailable",
|
|
170
|
+
warning: "SQLite mirror unavailable",
|
|
171
|
+
warnings: ["SQLite mirror unavailable"],
|
|
172
|
+
target: "memory",
|
|
173
|
+
entry_count: 1,
|
|
174
|
+
}), {
|
|
175
|
+
success: true,
|
|
176
|
+
message: "Entry added. Warning: SQLite mirror unavailable",
|
|
177
|
+
warning: "SQLite mirror unavailable",
|
|
178
|
+
warnings: ["SQLite mirror unavailable"],
|
|
179
|
+
target: "memory",
|
|
180
|
+
entry_count: 1,
|
|
181
|
+
}));
|
|
182
|
+
assert.match(renderView(warningView, false), /SQLite mirror unavailable/);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it("fits ANSI, CJK, and partial rows while preserving the outer tool-card background", () => {
|
|
186
|
+
const width = 34;
|
|
187
|
+
const backgroundOpen = "\x1b[48;2;40;50;40m";
|
|
188
|
+
const ansiTheme = {
|
|
189
|
+
fg: (_color: string, text: string): string => `\x1b[38;2;145;148;145m${text}\x1b[39m`,
|
|
190
|
+
getBgAnsi: (_color: string): string => backgroundOpen,
|
|
191
|
+
} as any;
|
|
192
|
+
const box = new Box(1, 1, (text: string) => `${backgroundOpen}${text}\x1b[49m`);
|
|
193
|
+
box.addChild(createSharedToolResultRenderer()(
|
|
194
|
+
result("处理中 世界世界世界世界 \x1b[1mvery long partial output\x1b[0m"),
|
|
195
|
+
{ expanded: false, isPartial: true },
|
|
196
|
+
ansiTheme,
|
|
197
|
+
{ isError: false },
|
|
198
|
+
));
|
|
199
|
+
|
|
200
|
+
const rows = box.render(width);
|
|
201
|
+
assert.equal(rows.length, 3);
|
|
202
|
+
assert.equal(visibleWidth(rows[1]), width);
|
|
203
|
+
assert.match(stripAnsi(rows[1]), /处理中|In progress/);
|
|
204
|
+
|
|
205
|
+
assertRowKeepsBackground(rows[1]);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it("keeps the tool-card background after sanitizing expanded ANSI and CJK text", () => {
|
|
209
|
+
const width = 18;
|
|
210
|
+
const backgroundOpen = "\x1b[48;2;40;50;40m";
|
|
211
|
+
const ansiTheme = {
|
|
212
|
+
fg: (_color: string, text: string): string => text,
|
|
213
|
+
getBgAnsi: (_color: string): string => backgroundOpen,
|
|
214
|
+
} as any;
|
|
215
|
+
const expandedText = "第一行 世界世界世界\x1b[0m继续\n第二行 \x1b[49m背景保留";
|
|
216
|
+
const box = new Box(1, 1, (text: string) => `${backgroundOpen}${text}\x1b[49m`);
|
|
217
|
+
box.addChild(createSharedToolResultRenderer()(
|
|
218
|
+
result(expandedText),
|
|
219
|
+
{ expanded: true, isPartial: false },
|
|
220
|
+
ansiTheme,
|
|
221
|
+
{ isError: false },
|
|
222
|
+
));
|
|
223
|
+
|
|
224
|
+
const rows = box.render(width);
|
|
225
|
+
assert.ok(rows.length > 4);
|
|
226
|
+
for (const row of rows) {
|
|
227
|
+
assert.equal(visibleWidth(row), width);
|
|
228
|
+
assertRowKeepsBackground(row);
|
|
229
|
+
}
|
|
230
|
+
const expandedRows = rows.slice(1, -1).map((row) => stripAnsi(row).trim());
|
|
231
|
+
assert.deepEqual(expandedRows, ["第一行 世界世界", "世界继续", "第二行 背景保留"]);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it("uses Pi shell state for the card background and logical status for foreground", () => {
|
|
235
|
+
const scenarios = [
|
|
236
|
+
{ partial: true, isError: false, success: false, background: "toolPendingBg", foreground: "warning" },
|
|
237
|
+
{ partial: false, isError: true, success: true, background: "toolErrorBg", foreground: "error" },
|
|
238
|
+
{ partial: false, isError: false, success: true, background: "toolSuccessBg", foreground: "toolOutput" },
|
|
239
|
+
{ partial: false, isError: false, success: false, background: "toolSuccessBg", foreground: "error" },
|
|
240
|
+
] as const;
|
|
241
|
+
|
|
242
|
+
for (const scenario of scenarios) {
|
|
243
|
+
const backgrounds: string[] = [];
|
|
244
|
+
const foregrounds: string[] = [];
|
|
245
|
+
const theme = {
|
|
246
|
+
fg: (color: string, text: string): string => {
|
|
247
|
+
foregrounds.push(color);
|
|
248
|
+
return text;
|
|
249
|
+
},
|
|
250
|
+
getBgAnsi: (color: string): string => {
|
|
251
|
+
backgrounds.push(color);
|
|
252
|
+
return "";
|
|
253
|
+
},
|
|
254
|
+
} as any;
|
|
255
|
+
const message = scenario.success ? "done" : "query is required";
|
|
256
|
+
const toolResult = result(message, { success: scenario.success, message });
|
|
257
|
+
|
|
258
|
+
const renderer = createSharedToolResultRenderer();
|
|
259
|
+
const rendered = renderPlain(renderer(
|
|
260
|
+
toolResult,
|
|
261
|
+
{ expanded: false, isPartial: scenario.partial },
|
|
262
|
+
theme,
|
|
263
|
+
{ isError: scenario.isError },
|
|
264
|
+
));
|
|
265
|
+
renderPlain(renderer(
|
|
266
|
+
toolResult,
|
|
267
|
+
{ expanded: true, isPartial: scenario.partial },
|
|
268
|
+
theme,
|
|
269
|
+
{ isError: scenario.isError },
|
|
270
|
+
));
|
|
271
|
+
|
|
272
|
+
assert.deepEqual(backgrounds, [scenario.background, scenario.background]);
|
|
273
|
+
assert.deepEqual(foregrounds, [scenario.foreground]);
|
|
274
|
+
if (!scenario.success) assert.match(rendered, /query is required/);
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
describe("tool-specific summaries", () => {
|
|
280
|
+
it("summarizes memory, search/session, and skill results without changing expanded text", () => {
|
|
281
|
+
const memoryText = JSON.stringify({
|
|
282
|
+
success: true,
|
|
283
|
+
message: "Entry added.",
|
|
284
|
+
target: "failure",
|
|
285
|
+
category: "tool-quirk",
|
|
286
|
+
entry_count: 2,
|
|
287
|
+
usage: "120 / 5,000 chars",
|
|
288
|
+
});
|
|
289
|
+
const memory = memoryResultView(result(memoryText, JSON.parse(memoryText)));
|
|
290
|
+
assert.match(memory.summary, /Saved/);
|
|
291
|
+
assert.match(memory.summary, /target: failure/);
|
|
292
|
+
assert.match(memory.summary, /category: tool-quirk/);
|
|
293
|
+
assert.equal(memory.expandedText, memoryText);
|
|
294
|
+
|
|
295
|
+
const searchText = "Found 3 memories matching auth:\n\nfirst\nsecond\nthird";
|
|
296
|
+
const search = searchResultView(result(searchText, { success: true, count: 3 }));
|
|
297
|
+
assert.match(search.summary, /3/);
|
|
298
|
+
assert.equal(search.expandedText, searchText);
|
|
299
|
+
|
|
300
|
+
const skillText = JSON.stringify({ success: true, skillId: "global:deploy", name: "deploy" });
|
|
301
|
+
const skill = skillResultView(result(skillText, JSON.parse(skillText)));
|
|
302
|
+
assert.match(skill.summary, /deploy/i);
|
|
303
|
+
assert.equal(skill.expandedText, skillText);
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
it("renders a real skill-tool JSON failure as an actionable failure", () => {
|
|
307
|
+
const error = "Skill 'global:missing' not found.";
|
|
308
|
+
const skillText = JSON.stringify({ success: false, error });
|
|
309
|
+
const toolResult = result(skillText, {});
|
|
310
|
+
const skill = skillResultView(toolResult);
|
|
311
|
+
|
|
312
|
+
assert.equal(skill.status, "failure");
|
|
313
|
+
assert.equal(skill.summary, `Error · ${error}`);
|
|
314
|
+
assert.equal(skill.expandedText, skillText);
|
|
315
|
+
assert.match(renderPlain(
|
|
316
|
+
createSharedToolResultRenderer(skillResultView)(
|
|
317
|
+
toolResult,
|
|
318
|
+
{ expanded: false, isPartial: false },
|
|
319
|
+
fakeTheme(),
|
|
320
|
+
{ isError: false },
|
|
321
|
+
),
|
|
322
|
+
), new RegExp(error.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")));
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
it("summarizes successful failure memory from the real producer result shape", () => {
|
|
326
|
+
// MemoryResult has no category field; producers encode it only in message.
|
|
327
|
+
const details = {
|
|
328
|
+
success: true,
|
|
329
|
+
target: "failure",
|
|
330
|
+
message: "Failure memory saved: tool-quirk",
|
|
331
|
+
entry_count: 16,
|
|
332
|
+
usage: "92% — 9271/10000 chars",
|
|
333
|
+
};
|
|
334
|
+
const fullText = JSON.stringify(details);
|
|
335
|
+
const toolResult = result(fullText, details);
|
|
336
|
+
const before = structuredClone(toolResult);
|
|
337
|
+
const view = memoryResultView(toolResult);
|
|
338
|
+
|
|
339
|
+
assert.equal(view.status, "success");
|
|
340
|
+
assert.equal(
|
|
341
|
+
view.summary,
|
|
342
|
+
"Saved · target: failure · category: tool-quirk · 16 entries · 92% — 9271/10000 chars",
|
|
343
|
+
);
|
|
344
|
+
assert.doesNotMatch(view.summary, /^failure:/);
|
|
345
|
+
assert.equal(view.expandedText, fullText);
|
|
346
|
+
assert.deepEqual(toolResult, before);
|
|
347
|
+
|
|
348
|
+
const collapsed = renderPlain(
|
|
349
|
+
createSharedToolResultRenderer(memoryResultView)(
|
|
350
|
+
toolResult,
|
|
351
|
+
{ expanded: false, isPartial: false },
|
|
352
|
+
fakeTheme(),
|
|
353
|
+
{ isError: false },
|
|
354
|
+
),
|
|
355
|
+
);
|
|
356
|
+
assert.match(
|
|
357
|
+
collapsed,
|
|
358
|
+
/Saved · target: failure · category: tool-quirk · 16 entries · 92% — 9271\/10000 chars/,
|
|
359
|
+
);
|
|
360
|
+
assert.doesNotMatch(collapsed, /^failure:/);
|
|
361
|
+
});
|
|
362
|
+
});
|