@otium-team/negotium 0.0.0-stage → 0.23.13
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/LICENSE +202 -0
- package/README.md +329 -2
- package/bin/codex-sdk-window-hide.mjs +40 -0
- package/bin/negotium.mjs +22 -0
- package/dist/agent-helpers.js +23090 -0
- package/dist/agent-helpers.js.map +171 -0
- package/dist/background-bash.js +535 -0
- package/dist/background-bash.js.map +16 -0
- package/dist/browser-runtime.js +2334 -0
- package/dist/browser-runtime.js.map +35 -0
- package/dist/canonical-mcp-bridge.js +13 -0
- package/dist/canonical-mcp-bridge.js.map +9 -0
- package/dist/chunk-22kg3fsw.js +79 -0
- package/dist/chunk-22kg3fsw.js.map +9 -0
- package/dist/chunk-d4j77adx.js +336 -0
- package/dist/chunk-d4j77adx.js.map +13 -0
- package/dist/chunk-mk9x18jn.js +172 -0
- package/dist/chunk-mk9x18jn.js.map +12 -0
- package/dist/chunk-qd0vtfm2.js +3923 -0
- package/dist/chunk-qd0vtfm2.js.map +47 -0
- package/dist/chunk-wf7ny8eq.js +206 -0
- package/dist/chunk-wf7ny8eq.js.map +10 -0
- package/dist/chunk-ww8a4ej4.js +54 -0
- package/dist/chunk-ww8a4ej4.js.map +10 -0
- package/dist/cron.js +1 -0
- package/dist/hosted-agent.js +5982 -0
- package/dist/hosted-agent.js.map +62 -0
- package/dist/main.js +60229 -0
- package/dist/main.js.map +340 -0
- package/dist/mcp-catalog.js +39 -0
- package/dist/mcp-catalog.js.map +10 -0
- package/dist/mcp-factories.js +25767 -0
- package/dist/mcp-factories.js.map +181 -0
- package/dist/mcp-servers.js +50 -0
- package/dist/mcp-servers.js.map +10 -0
- package/dist/media.js +570 -0
- package/dist/media.js.map +15 -0
- package/dist/outbox.js +354 -0
- package/dist/outbox.js.map +15 -0
- package/dist/platform-runtime.js +73 -0
- package/dist/platform-runtime.js.map +12 -0
- package/dist/prompts.js +892 -0
- package/dist/prompts.js.map +15 -0
- package/dist/query-runtime.js +1071 -0
- package/dist/query-runtime.js.map +26 -0
- package/dist/registry.js +335 -0
- package/dist/registry.js.map +14 -0
- package/dist/rollout.js +57 -0
- package/dist/rollout.js.map +10 -0
- package/dist/runtime/cron/background-sessions.ts +119 -0
- package/dist/runtime/cron/context.ts +123 -0
- package/dist/runtime/cron/host.ts +67 -0
- package/dist/runtime/cron/index.ts +95 -0
- package/dist/runtime/cron/mcp-server.ts +556 -0
- package/dist/runtime/cron/module.ts +174 -0
- package/dist/runtime/cron/package.json +6 -0
- package/dist/runtime/cron/schedule.ts +211 -0
- package/dist/runtime/cron/scheduler.ts +444 -0
- package/dist/runtime/cron/scripts.ts +203 -0
- package/dist/runtime/cron/store.ts +1163 -0
- package/dist/runtime/cron/summarize.ts +115 -0
- package/dist/runtime/package.json +6 -0
- package/dist/runtime/scripts/faster-whisper-wrapper.py +87 -0
- package/dist/runtime/src/agents/api-topic-agent-switch.ts +179 -0
- package/dist/runtime/src/agents/archiver.ts +677 -0
- package/dist/runtime/src/agents/auth-check.ts +156 -0
- package/dist/runtime/src/agents/claude-notices.ts +130 -0
- package/dist/runtime/src/agents/claude-provider.ts +941 -0
- package/dist/runtime/src/agents/claude-registry.ts +117 -0
- package/dist/runtime/src/agents/claude-runtime-inspection.ts +43 -0
- package/dist/runtime/src/agents/codex-app-server.ts +138 -0
- package/dist/runtime/src/agents/codex-native-multi-agent.ts +360 -0
- package/dist/runtime/src/agents/codex-provider.ts +1193 -0
- package/dist/runtime/src/agents/codex-registry.ts +116 -0
- package/dist/runtime/src/agents/codex-tier-resolver.ts +74 -0
- package/dist/runtime/src/agents/codex-tree-kill.ts +54 -0
- package/dist/runtime/src/agents/codex-tree-manager.ts +230 -0
- package/dist/runtime/src/agents/codex-vault-hook-bridge.ts +240 -0
- package/dist/runtime/src/agents/codex-vault-hook.mjs +50 -0
- package/dist/runtime/src/agents/codex-windows-wrapper.ts +174 -0
- package/dist/runtime/src/agents/compaction-support.ts +75 -0
- package/dist/runtime/src/agents/compaction-tool-projection.ts +125 -0
- package/dist/runtime/src/agents/contracts.ts +75 -0
- package/dist/runtime/src/agents/deep-map.ts +13 -0
- package/dist/runtime/src/agents/execution-host.ts +118 -0
- package/dist/runtime/src/agents/explicit-agent-switch.ts +106 -0
- package/dist/runtime/src/agents/fixtures/claude-attachments.jsonl +2 -0
- package/dist/runtime/src/agents/fixtures/codex-shell.jsonl +5 -0
- package/dist/runtime/src/agents/fork.ts +100 -0
- package/dist/runtime/src/agents/hosted-agent.ts +78 -0
- package/dist/runtime/src/agents/idle-archiver.ts +225 -0
- package/dist/runtime/src/agents/idle-compact.ts +225 -0
- package/dist/runtime/src/agents/index.ts +225 -0
- package/dist/runtime/src/agents/maestro-provider.ts +246 -0
- package/dist/runtime/src/agents/maestro-registry.ts +189 -0
- package/dist/runtime/src/agents/mcp-tools/ask-user.ts +653 -0
- package/dist/runtime/src/agents/mcp-tools/common.ts +23 -0
- package/dist/runtime/src/agents/mcp-tools/inline-assets.ts +203 -0
- package/dist/runtime/src/agents/mcp-tools/publish-html.ts +183 -0
- package/dist/runtime/src/agents/mcp-tools/request-vault.ts +684 -0
- package/dist/runtime/src/agents/mcp-tools/self-config.ts +353 -0
- package/dist/runtime/src/agents/mcp-tools/spawn-subagent.ts +1349 -0
- package/dist/runtime/src/agents/mcp-tools/visual-compat.ts +18 -0
- package/dist/runtime/src/agents/mcp-tools/visuals.ts +60 -0
- package/dist/runtime/src/agents/memory-archive-policy.ts +54 -0
- package/dist/runtime/src/agents/model-catalog.ts +439 -0
- package/dist/runtime/src/agents/public-helpers.ts +149 -0
- package/dist/runtime/src/agents/registry.ts +35 -0
- package/dist/runtime/src/agents/rollout/claude.ts +336 -0
- package/dist/runtime/src/agents/rollout/codex.ts +910 -0
- package/dist/runtime/src/agents/rollout/index.ts +26 -0
- package/dist/runtime/src/agents/rollout/shared.ts +293 -0
- package/dist/runtime/src/agents/self-config-core.ts +704 -0
- package/dist/runtime/src/agents/task-events.ts +59 -0
- package/dist/runtime/src/agents/tool-format.ts +613 -0
- package/dist/runtime/src/agents/topic-agent-switch.ts +189 -0
- package/dist/runtime/src/agents/topic-cleanup.ts +285 -0
- package/dist/runtime/src/agents/vault-tool-policy.ts +36 -0
- package/dist/runtime/src/application/execute-external-user-turn.ts +23 -0
- package/dist/runtime/src/application/submit-runtime-gateway-turn.ts +484 -0
- package/dist/runtime/src/application/submit-user-message.ts +60 -0
- package/dist/runtime/src/application/switch-topic-effort.ts +48 -0
- package/dist/runtime/src/application/switch-topic-model.ts +79 -0
- package/dist/runtime/src/application/topic-service.ts +190 -0
- package/dist/runtime/src/application/turn-follow-ups.ts +291 -0
- package/dist/runtime/src/application/vault-command.ts +170 -0
- package/dist/runtime/src/bus.ts +409 -0
- package/dist/runtime/src/config-public.ts +2 -0
- package/dist/runtime/src/cron-host.ts +33 -0
- package/dist/runtime/src/cron-mcp-host.ts +5 -0
- package/dist/runtime/src/identifiers.ts +49 -0
- package/dist/runtime/src/index.ts +573 -0
- package/dist/runtime/src/mcp/agent-health-server.ts +8 -0
- package/dist/runtime/src/mcp/canonical-bridge-config.ts +84 -0
- package/dist/runtime/src/mcp/canonical-proxy-server.ts +308 -0
- package/dist/runtime/src/mcp/compaction-log-server.ts +25 -0
- package/dist/runtime/src/mcp/decision-server.ts +21 -0
- package/dist/runtime/src/mcp/dm-ipc.ts +60 -0
- package/dist/runtime/src/mcp/factories/agent-health.ts +394 -0
- package/dist/runtime/src/mcp/factories/compaction-log.ts +135 -0
- package/dist/runtime/src/mcp/factories/decision.ts +186 -0
- package/dist/runtime/src/mcp/factories/index.ts +73 -0
- package/dist/runtime/src/mcp/factories/session-comm.ts +184 -0
- package/dist/runtime/src/mcp/factories/session-history.ts +103 -0
- package/dist/runtime/src/mcp/factories/stdio-protection.ts +24 -0
- package/dist/runtime/src/mcp/factories/system-health.ts +259 -0
- package/dist/runtime/src/mcp/factories/task.ts +185 -0
- package/dist/runtime/src/mcp/factories/token-stats.ts +145 -0
- package/dist/runtime/src/mcp/factories/vault.ts +32 -0
- package/dist/runtime/src/mcp/mcp-helpers.ts +40 -0
- package/dist/runtime/src/mcp/peer-bridge.ts +119 -0
- package/dist/runtime/src/mcp/runtime-spec.ts +473 -0
- package/dist/runtime/src/mcp/session-comm/actor-policy.ts +160 -0
- package/dist/runtime/src/mcp/session-comm/bridge-ipc-config.ts +27 -0
- package/dist/runtime/src/mcp/session-comm/context.ts +113 -0
- package/dist/runtime/src/mcp/session-comm/default-host.ts +723 -0
- package/dist/runtime/src/mcp/session-comm/history-target.ts +89 -0
- package/dist/runtime/src/mcp/session-comm/history-tools.ts +113 -0
- package/dist/runtime/src/mcp/session-comm/hub-remote-session.ts +553 -0
- package/dist/runtime/src/mcp/session-comm/limits.ts +8 -0
- package/dist/runtime/src/mcp/session-comm/peer-forward.ts +251 -0
- package/dist/runtime/src/mcp/session-comm/runtime.ts +128 -0
- package/dist/runtime/src/mcp/session-comm/server.ts +1036 -0
- package/dist/runtime/src/mcp/session-comm/tell-permissions.ts +79 -0
- package/dist/runtime/src/mcp/session-comm/topic-catalog.ts +155 -0
- package/dist/runtime/src/mcp/session-comm/topic-config.ts +137 -0
- package/dist/runtime/src/mcp/session-comm/topics.ts +313 -0
- package/dist/runtime/src/mcp/session-history-limits.ts +36 -0
- package/dist/runtime/src/mcp/session-history-reader.ts +359 -0
- package/dist/runtime/src/mcp/session-history-server.ts +19 -0
- package/dist/runtime/src/mcp/stdio-protect.ts +7 -0
- package/dist/runtime/src/mcp/system-health-server.ts +5 -0
- package/dist/runtime/src/mcp/task-server.ts +17 -0
- package/dist/runtime/src/mcp/token-stats-server.ts +10 -0
- package/dist/runtime/src/mcp/vault-server.ts +12 -0
- package/dist/runtime/src/mcp/wiki-search-index.ts +359 -0
- package/dist/runtime/src/mcp/wiki-server.ts +2386 -0
- package/dist/runtime/src/mcp-runtime-host.ts +81 -0
- package/dist/runtime/src/media/file-events.ts +33 -0
- package/dist/runtime/src/media/text-extractor.ts +334 -0
- package/dist/runtime/src/media/video.ts +92 -0
- package/dist/runtime/src/node-host.ts +211 -0
- package/dist/runtime/src/outbox/coalescing-runner.ts +157 -0
- package/dist/runtime/src/outbox/file-ops.ts +267 -0
- package/dist/runtime/src/outbox/index.ts +26 -0
- package/dist/runtime/src/outbox/utils.ts +74 -0
- package/dist/runtime/src/platform/background-bash/context.ts +9 -0
- package/dist/runtime/src/platform/background-bash/manager.ts +292 -0
- package/dist/runtime/src/platform/background-bash/output-buffer.ts +323 -0
- package/dist/runtime/src/platform/config-helpers.ts +47 -0
- package/dist/runtime/src/platform/config.ts +618 -0
- package/dist/runtime/src/platform/constants.ts +30 -0
- package/dist/runtime/src/platform/debug-users.ts +14 -0
- package/dist/runtime/src/platform/delay.ts +1 -0
- package/dist/runtime/src/platform/error.ts +9 -0
- package/dist/runtime/src/platform/file-utils.ts +35 -0
- package/dist/runtime/src/platform/ipc.ts +55 -0
- package/dist/runtime/src/platform/jsonl.ts +277 -0
- package/dist/runtime/src/platform/lifecycle.ts +176 -0
- package/dist/runtime/src/platform/log-rotation.ts +45 -0
- package/dist/runtime/src/platform/logger.ts +42 -0
- package/dist/runtime/src/platform/maestro-bootstrap-env.ts +3 -0
- package/dist/runtime/src/platform/mcp-catalog-policy.ts +63 -0
- package/dist/runtime/src/platform/mcp-config.ts +1329 -0
- package/dist/runtime/src/platform/memoize-import.ts +26 -0
- package/dist/runtime/src/platform/modules.ts +145 -0
- package/dist/runtime/src/platform/node-plugins.ts +46 -0
- package/dist/runtime/src/platform/paths.ts +62 -0
- package/dist/runtime/src/platform/playwright/browser-processes.ts +300 -0
- package/dist/runtime/src/platform/playwright/capability.ts +5 -0
- package/dist/runtime/src/platform/playwright/headed-launch.ts +61 -0
- package/dist/runtime/src/platform/playwright/manager-utils.ts +128 -0
- package/dist/runtime/src/platform/playwright/manager.ts +1502 -0
- package/dist/runtime/src/platform/playwright/mcp-transport.ts +35 -0
- package/dist/runtime/src/platform/playwright/profile-management.ts +33 -0
- package/dist/runtime/src/platform/playwright/public-runtime.ts +52 -0
- package/dist/runtime/src/platform/playwright/transport-probe.ts +89 -0
- package/dist/runtime/src/platform/playwright/vault-broker.ts +261 -0
- package/dist/runtime/src/platform/public-runtime.ts +18 -0
- package/dist/runtime/src/prompts/agents/wiki-archiver.md +194 -0
- package/dist/runtime/src/prompts/builders.ts +696 -0
- package/dist/runtime/src/prompts/sessions/_shared-tools.md +38 -0
- package/dist/runtime/src/prompts/sessions/channel-system.md +13 -0
- package/dist/runtime/src/prompts/sessions/manager-system.md +34 -0
- package/dist/runtime/src/prompts/sessions/surfaces/cli.md +6 -0
- package/dist/runtime/src/prompts/sessions/surfaces/otium-manager.md +18 -0
- package/dist/runtime/src/prompts/sessions/surfaces/otium.md +6 -0
- package/dist/runtime/src/prompts/sessions/surfaces/telegram.md +5 -0
- package/dist/runtime/src/prompts/sessions/surfaces/terminal.md +6 -0
- package/dist/runtime/src/prompts/sessions/topic-system.md +9 -0
- package/dist/runtime/src/prompts/sessions/visual-design.md +38 -0
- package/dist/runtime/src/query/active-rooms.ts +514 -0
- package/dist/runtime/src/query/index.ts +23 -0
- package/dist/runtime/src/query/public-runtime.ts +28 -0
- package/dist/runtime/src/query/room-query-registry.ts +217 -0
- package/dist/runtime/src/query/session-inbox-cleanup.ts +45 -0
- package/dist/runtime/src/query/session-inbox-path.ts +42 -0
- package/dist/runtime/src/query/state.ts +116 -0
- package/dist/runtime/src/query/types.ts +8 -0
- package/dist/runtime/src/runtime/actor-topic-reach.ts +123 -0
- package/dist/runtime/src/runtime/actor-topic-scope.ts +255 -0
- package/dist/runtime/src/runtime/ask-callbacks.ts +217 -0
- package/dist/runtime/src/runtime/attachments.ts +149 -0
- package/dist/runtime/src/runtime/background-session-policy.ts +1 -0
- package/dist/runtime/src/runtime/background-sessions.ts +288 -0
- package/dist/runtime/src/runtime/bashrs-completions.ts +350 -0
- package/dist/runtime/src/runtime/channel-context.ts +115 -0
- package/dist/runtime/src/runtime/context-warning.ts +131 -0
- package/dist/runtime/src/runtime/cron-sessions.ts +35 -0
- package/dist/runtime/src/runtime/delivery-ack.ts +112 -0
- package/dist/runtime/src/runtime/errors.ts +70 -0
- package/dist/runtime/src/runtime/event-heartbeat.ts +77 -0
- package/dist/runtime/src/runtime/file-hooks.ts +81 -0
- package/dist/runtime/src/runtime/footer.ts +23 -0
- package/dist/runtime/src/runtime/gateway-capabilities.ts +22 -0
- package/dist/runtime/src/runtime/inbox.ts +1307 -0
- package/dist/runtime/src/runtime/playwright-turn-abort.ts +59 -0
- package/dist/runtime/src/runtime/public-helpers.ts +78 -0
- package/dist/runtime/src/runtime/remote-session-grant.ts +221 -0
- package/dist/runtime/src/runtime/remote-session-inbox.ts +943 -0
- package/dist/runtime/src/runtime/remote-session-reply-outbox.ts +168 -0
- package/dist/runtime/src/runtime/task-format.ts +18 -0
- package/dist/runtime/src/runtime/tasks.ts +53 -0
- package/dist/runtime/src/runtime/thread-context.ts +123 -0
- package/dist/runtime/src/runtime/thread-read.ts +67 -0
- package/dist/runtime/src/runtime/topic-config.ts +29 -0
- package/dist/runtime/src/runtime/turn-event-stream.ts +1051 -0
- package/dist/runtime/src/runtime/turn-runner.ts +2311 -0
- package/dist/runtime/src/runtime/turn-session.ts +116 -0
- package/dist/runtime/src/runtime/usage-alert.ts +51 -0
- package/dist/runtime/src/runtime/user-turn-envelope.ts +94 -0
- package/dist/runtime/src/runtime/visual-html.ts +175 -0
- package/dist/runtime/src/runtime/visual-store.ts +480 -0
- package/dist/runtime/src/runtime/visuals.ts +209 -0
- package/dist/runtime/src/runtime-gateway.ts +1045 -0
- package/dist/runtime/src/security/sanitize.ts +27 -0
- package/dist/runtime/src/security/sensitive-path.ts +41 -0
- package/dist/runtime/src/storage/activity-log.ts +167 -0
- package/dist/runtime/src/storage/api-messages.ts +766 -0
- package/dist/runtime/src/storage/api-topic-brief.ts +134 -0
- package/dist/runtime/src/storage/api-topic-config.ts +197 -0
- package/dist/runtime/src/storage/api-topics.ts +1647 -0
- package/dist/runtime/src/storage/app-settings.ts +50 -0
- package/dist/runtime/src/storage/ask-user-gates.ts +359 -0
- package/dist/runtime/src/storage/browser-profiles.ts +186 -0
- package/dist/runtime/src/storage/conversation-migration.ts +180 -0
- package/dist/runtime/src/storage/conversations.ts +377 -0
- package/dist/runtime/src/storage/decisions.ts +231 -0
- package/dist/runtime/src/storage/forum/agent-settings.ts +20 -0
- package/dist/runtime/src/storage/forum/index.ts +4 -0
- package/dist/runtime/src/storage/forum/repository.ts +283 -0
- package/dist/runtime/src/storage/forum/schema.ts +314 -0
- package/dist/runtime/src/storage/forum-db.ts +4 -0
- package/dist/runtime/src/storage/remote-session.ts +1028 -0
- package/dist/runtime/src/storage/runtime-events.ts +209 -0
- package/dist/runtime/src/storage/runtime-follow-ups.ts +212 -0
- package/dist/runtime/src/storage/runtime-gateway-submissions.ts +132 -0
- package/dist/runtime/src/storage/runtime-leases.ts +190 -0
- package/dist/runtime/src/storage/runtime-process-leases.ts +288 -0
- package/dist/runtime/src/storage/runtime-topic-state.ts +181 -0
- package/dist/runtime/src/storage/runtime-turn-requests.ts +846 -0
- package/dist/runtime/src/storage/self-schedules.ts +306 -0
- package/dist/runtime/src/storage/session-asks.ts +468 -0
- package/dist/runtime/src/storage/session-inbox-signal.ts +76 -0
- package/dist/runtime/src/storage/session-inbox.ts +161 -0
- package/dist/runtime/src/storage/sqlite.ts +154 -0
- package/dist/runtime/src/storage/storage-contract.ts +54 -0
- package/dist/runtime/src/storage/storage-host.ts +336 -0
- package/dist/runtime/src/storage/storage-public-host.ts +16 -0
- package/dist/runtime/src/storage/storage-public.ts +66 -0
- package/dist/runtime/src/storage/tasks.ts +172 -0
- package/dist/runtime/src/storage/token-stats.ts +432 -0
- package/dist/runtime/src/storage/topic-archive-state.ts +226 -0
- package/dist/runtime/src/storage/topic-archive.ts +169 -0
- package/dist/runtime/src/storage/topic-host-mcp-grants.ts +54 -0
- package/dist/runtime/src/storage/topic-link-records.ts +1085 -0
- package/dist/runtime/src/storage/topic-settings.ts +67 -0
- package/dist/runtime/src/storage/topic-tool-capabilities.ts +89 -0
- package/dist/runtime/src/storage/topic-transcript.ts +98 -0
- package/dist/runtime/src/storage/vault-crypto-core.ts +65 -0
- package/dist/runtime/src/storage/vault-crypto.ts +31 -0
- package/dist/runtime/src/storage/vault-public.ts +27 -0
- package/dist/runtime/src/storage/vault-request-gates.ts +359 -0
- package/dist/runtime/src/storage/vault.ts +388 -0
- package/dist/runtime/src/storage/wiki-summary-names.ts +52 -0
- package/dist/runtime/src/storage/wiki.ts +90 -0
- package/dist/runtime/src/topics/claim-abort.ts +190 -0
- package/dist/runtime/src/topics/create.ts +192 -0
- package/dist/runtime/src/topics/derive.ts +600 -0
- package/dist/runtime/src/topics/lifecycle.ts +425 -0
- package/dist/runtime/src/topics/links.ts +7 -0
- package/dist/runtime/src/topics/personal-general.ts +91 -0
- package/dist/runtime/src/topics/session.ts +1041 -0
- package/dist/runtime/src/topics/update.ts +287 -0
- package/dist/runtime/src/types/api.ts +591 -0
- package/dist/runtime/src/types.ts +418 -0
- package/dist/runtime/src/version.ts +1 -0
- package/dist/runtime/tsconfig.json +13 -0
- package/dist/runtime-gateway.js +514 -0
- package/dist/runtime-gateway.js.map +10 -0
- package/dist/runtime-helpers.js +1792 -0
- package/dist/runtime-helpers.js.map +40 -0
- package/dist/sqlite.js +66 -0
- package/dist/sqlite.js.map +10 -0
- package/dist/storage.js +5223 -0
- package/dist/storage.js.map +47 -0
- package/dist/types/apps/negotium/src/mcp-servers.d.ts +20 -0
- package/dist/types/packages/core/src/agents/api-topic-agent-switch.d.ts +38 -0
- package/dist/types/packages/core/src/agents/archiver.d.ts +87 -0
- package/dist/types/packages/core/src/agents/auth-check.d.ts +19 -0
- package/dist/types/packages/core/src/agents/claude-notices.d.ts +15 -0
- package/dist/types/packages/core/src/agents/claude-provider.d.ts +25 -0
- package/dist/types/packages/core/src/agents/claude-registry.d.ts +3 -0
- package/dist/types/packages/core/src/agents/claude-runtime-inspection.d.ts +9 -0
- package/dist/types/packages/core/src/agents/codex-app-server.d.ts +13 -0
- package/dist/types/packages/core/src/agents/codex-native-multi-agent.d.ts +20 -0
- package/dist/types/packages/core/src/agents/codex-provider.d.ts +64 -0
- package/dist/types/packages/core/src/agents/codex-registry.d.ts +3 -0
- package/dist/types/packages/core/src/agents/codex-tier-resolver.d.ts +10 -0
- package/dist/types/packages/core/src/agents/codex-tree-kill.d.ts +13 -0
- package/dist/types/packages/core/src/agents/codex-tree-manager.d.ts +28 -0
- package/dist/types/packages/core/src/agents/codex-vault-hook-bridge.d.ts +28 -0
- package/dist/types/packages/core/src/agents/codex-windows-wrapper.d.ts +30 -0
- package/dist/types/packages/core/src/agents/compaction-support.d.ts +5 -0
- package/dist/types/packages/core/src/agents/compaction-tool-projection.d.ts +9 -0
- package/dist/types/packages/core/src/agents/contracts.d.ts +68 -0
- package/dist/types/packages/core/src/agents/deep-map.d.ts +2 -0
- package/dist/types/packages/core/src/agents/execution-host.d.ts +33 -0
- package/dist/types/packages/core/src/agents/explicit-agent-switch.d.ts +26 -0
- package/dist/types/packages/core/src/agents/fork.d.ts +50 -0
- package/dist/types/packages/core/src/agents/hosted-agent.d.ts +15 -0
- package/dist/types/packages/core/src/agents/idle-archiver.d.ts +35 -0
- package/dist/types/packages/core/src/agents/idle-compact.d.ts +37 -0
- package/dist/types/packages/core/src/agents/index.d.ts +8 -0
- package/dist/types/packages/core/src/agents/maestro-provider.d.ts +75 -0
- package/dist/types/packages/core/src/agents/maestro-registry.d.ts +3 -0
- package/dist/types/packages/core/src/agents/mcp-tools/ask-user.d.ts +147 -0
- package/dist/types/packages/core/src/agents/mcp-tools/common.d.ts +14 -0
- package/dist/types/packages/core/src/agents/mcp-tools/inline-assets.d.ts +24 -0
- package/dist/types/packages/core/src/agents/mcp-tools/publish-html.d.ts +18 -0
- package/dist/types/packages/core/src/agents/mcp-tools/request-vault.d.ts +124 -0
- package/dist/types/packages/core/src/agents/mcp-tools/self-config.d.ts +45 -0
- package/dist/types/packages/core/src/agents/mcp-tools/spawn-subagent.d.ts +148 -0
- package/dist/types/packages/core/src/agents/mcp-tools/visual-compat.d.ts +55 -0
- package/dist/types/packages/core/src/agents/mcp-tools/visuals.d.ts +70 -0
- package/dist/types/packages/core/src/agents/memory-archive-policy.d.ts +24 -0
- package/dist/types/packages/core/src/agents/model-catalog.d.ts +132 -0
- package/dist/types/packages/core/src/agents/public-helpers.d.ts +17 -0
- package/dist/types/packages/core/src/agents/registry.d.ts +5 -0
- package/dist/types/packages/core/src/agents/rollout/claude.d.ts +77 -0
- package/dist/types/packages/core/src/agents/rollout/codex.d.ts +119 -0
- package/dist/types/packages/core/src/agents/rollout/index.d.ts +6 -0
- package/dist/types/packages/core/src/agents/rollout/shared.d.ts +56 -0
- package/dist/types/packages/core/src/agents/self-config-core.d.ts +199 -0
- package/dist/types/packages/core/src/agents/task-events.d.ts +19 -0
- package/dist/types/packages/core/src/agents/tool-format.d.ts +25 -0
- package/dist/types/packages/core/src/agents/topic-cleanup.d.ts +83 -0
- package/dist/types/packages/core/src/agents/vault-tool-policy.d.ts +2 -0
- package/dist/types/packages/core/src/bus.d.ts +141 -0
- package/dist/types/packages/core/src/identifiers.d.ts +27 -0
- package/dist/types/packages/core/src/mcp/canonical-bridge-config.d.ts +21 -0
- package/dist/types/packages/core/src/mcp/factories/agent-health.d.ts +5 -0
- package/dist/types/packages/core/src/mcp/factories/compaction-log.d.ts +8 -0
- package/dist/types/packages/core/src/mcp/factories/decision.d.ts +18 -0
- package/dist/types/packages/core/src/mcp/factories/index.d.ts +13 -0
- package/dist/types/packages/core/src/mcp/factories/session-comm.d.ts +38 -0
- package/dist/types/packages/core/src/mcp/factories/session-history.d.ts +11 -0
- package/dist/types/packages/core/src/mcp/factories/stdio-protection.d.ts +10 -0
- package/dist/types/packages/core/src/mcp/factories/system-health.d.ts +37 -0
- package/dist/types/packages/core/src/mcp/factories/task.d.ts +13 -0
- package/dist/types/packages/core/src/mcp/factories/token-stats.d.ts +20 -0
- package/dist/types/packages/core/src/mcp/factories/vault.d.ts +9 -0
- package/dist/types/packages/core/src/mcp/mcp-helpers.d.ts +26 -0
- package/dist/types/packages/core/src/mcp/peer-bridge.d.ts +92 -0
- package/dist/types/packages/core/src/mcp/runtime-spec.d.ts +147 -0
- package/dist/types/packages/core/src/mcp/session-comm/actor-policy.d.ts +120 -0
- package/dist/types/packages/core/src/mcp/session-comm/bridge-ipc-config.d.ts +6 -0
- package/dist/types/packages/core/src/mcp/session-comm/context.d.ts +44 -0
- package/dist/types/packages/core/src/mcp/session-comm/history-tools.d.ts +31 -0
- package/dist/types/packages/core/src/mcp/session-comm/hub-remote-session.d.ts +149 -0
- package/dist/types/packages/core/src/mcp/session-comm/limits.d.ts +8 -0
- package/dist/types/packages/core/src/mcp/session-comm/peer-forward.d.ts +85 -0
- package/dist/types/packages/core/src/mcp/session-comm/tell-permissions.d.ts +29 -0
- package/dist/types/packages/core/src/mcp/session-comm/topic-catalog.d.ts +59 -0
- package/dist/types/packages/core/src/mcp/session-history-limits.d.ts +20 -0
- package/dist/types/packages/core/src/mcp/session-history-reader.d.ts +35 -0
- package/dist/types/packages/core/src/mcp/wiki-search-index.d.ts +59 -0
- package/dist/types/packages/core/src/mcp/wiki-server.d.ts +53 -0
- package/dist/types/packages/core/src/media/file-events.d.ts +14 -0
- package/dist/types/packages/core/src/media/text-extractor.d.ts +34 -0
- package/dist/types/packages/core/src/outbox/coalescing-runner.d.ts +68 -0
- package/dist/types/packages/core/src/outbox/file-ops.d.ts +79 -0
- package/dist/types/packages/core/src/outbox/index.d.ts +3 -0
- package/dist/types/packages/core/src/outbox/utils.d.ts +16 -0
- package/dist/types/packages/core/src/platform/background-bash/context.d.ts +1 -0
- package/dist/types/packages/core/src/platform/background-bash/manager.d.ts +34 -0
- package/dist/types/packages/core/src/platform/config-helpers.d.ts +20 -0
- package/dist/types/packages/core/src/platform/config.d.ts +178 -0
- package/dist/types/packages/core/src/platform/constants.d.ts +20 -0
- package/dist/types/packages/core/src/platform/delay.d.ts +1 -0
- package/dist/types/packages/core/src/platform/error.d.ts +6 -0
- package/dist/types/packages/core/src/platform/file-utils.d.ts +16 -0
- package/dist/types/packages/core/src/platform/ipc.d.ts +32 -0
- package/dist/types/packages/core/src/platform/jsonl.d.ts +46 -0
- package/dist/types/packages/core/src/platform/lifecycle.d.ts +40 -0
- package/dist/types/packages/core/src/platform/logger.d.ts +20 -0
- package/dist/types/packages/core/src/platform/maestro-bootstrap-env.d.ts +0 -0
- package/dist/types/packages/core/src/platform/mcp-catalog-policy.d.ts +73 -0
- package/dist/types/packages/core/src/platform/mcp-config.d.ts +286 -0
- package/dist/types/packages/core/src/platform/memoize-import.d.ts +15 -0
- package/dist/types/packages/core/src/platform/paths.d.ts +18 -0
- package/dist/types/packages/core/src/platform/playwright/browser-processes.d.ts +60 -0
- package/dist/types/packages/core/src/platform/playwright/capability.d.ts +1 -0
- package/dist/types/packages/core/src/platform/playwright/headed-launch.d.ts +13 -0
- package/dist/types/packages/core/src/platform/playwright/manager-utils.d.ts +34 -0
- package/dist/types/packages/core/src/platform/playwright/manager.d.ts +194 -0
- package/dist/types/packages/core/src/platform/playwright/mcp-transport.d.ts +4 -0
- package/dist/types/packages/core/src/platform/playwright/profile-management.d.ts +8 -0
- package/dist/types/packages/core/src/platform/playwright/public-runtime.d.ts +6 -0
- package/dist/types/packages/core/src/platform/playwright/transport-probe.d.ts +13 -0
- package/dist/types/packages/core/src/platform/playwright/vault-broker.d.ts +6 -0
- package/dist/types/packages/core/src/platform/public-runtime.d.ts +3 -0
- package/dist/types/packages/core/src/prompts/builders.d.ts +78 -0
- package/dist/types/packages/core/src/query/active-rooms.d.ts +240 -0
- package/dist/types/packages/core/src/query/public-runtime.d.ts +4 -0
- package/dist/types/packages/core/src/query/room-query-registry.d.ts +71 -0
- package/dist/types/packages/core/src/query/session-inbox-cleanup.d.ts +5 -0
- package/dist/types/packages/core/src/query/session-inbox-path.d.ts +8 -0
- package/dist/types/packages/core/src/query/state.d.ts +25 -0
- package/dist/types/packages/core/src/query/types.d.ts +6 -0
- package/dist/types/packages/core/src/runtime/actor-topic-reach.d.ts +63 -0
- package/dist/types/packages/core/src/runtime/actor-topic-scope.d.ts +127 -0
- package/dist/types/packages/core/src/runtime/ask-callbacks.d.ts +53 -0
- package/dist/types/packages/core/src/runtime/attachments.d.ts +36 -0
- package/dist/types/packages/core/src/runtime/background-session-policy.d.ts +1 -0
- package/dist/types/packages/core/src/runtime/background-sessions.d.ts +27 -0
- package/dist/types/packages/core/src/runtime/bashrs-completions.d.ts +50 -0
- package/dist/types/packages/core/src/runtime/channel-context.d.ts +13 -0
- package/dist/types/packages/core/src/runtime/context-warning.d.ts +46 -0
- package/dist/types/packages/core/src/runtime/cron-sessions.d.ts +9 -0
- package/dist/types/packages/core/src/runtime/errors.d.ts +6 -0
- package/dist/types/packages/core/src/runtime/event-heartbeat.d.ts +17 -0
- package/dist/types/packages/core/src/runtime/file-hooks.d.ts +38 -0
- package/dist/types/packages/core/src/runtime/playwright-turn-abort.d.ts +12 -0
- package/dist/types/packages/core/src/runtime/public-helpers.d.ts +17 -0
- package/dist/types/packages/core/src/runtime/remote-session-grant.d.ts +91 -0
- package/dist/types/packages/core/src/runtime/remote-session-inbox.d.ts +206 -0
- package/dist/types/packages/core/src/runtime/remote-session-reply-outbox.d.ts +37 -0
- package/dist/types/packages/core/src/runtime/task-format.d.ts +4 -0
- package/dist/types/packages/core/src/runtime/tasks.d.ts +3 -0
- package/dist/types/packages/core/src/runtime/thread-context.d.ts +62 -0
- package/dist/types/packages/core/src/runtime/topic-config.d.ts +24 -0
- package/dist/types/packages/core/src/runtime/turn-event-stream.d.ts +47 -0
- package/dist/types/packages/core/src/runtime/turn-runner.d.ts +284 -0
- package/dist/types/packages/core/src/runtime/turn-session.d.ts +49 -0
- package/dist/types/packages/core/src/runtime/usage-alert.d.ts +11 -0
- package/dist/types/packages/core/src/runtime/user-turn-envelope.d.ts +37 -0
- package/dist/types/packages/core/src/runtime/visual-html.d.ts +13 -0
- package/dist/types/packages/core/src/runtime/visual-store.d.ts +71 -0
- package/dist/types/packages/core/src/runtime/visuals.d.ts +33 -0
- package/dist/types/packages/core/src/runtime-gateway.d.ts +282 -0
- package/dist/types/packages/core/src/security/sanitize.d.ts +16 -0
- package/dist/types/packages/core/src/security/sensitive-path.d.ts +1 -0
- package/dist/types/packages/core/src/storage/activity-log.d.ts +25 -0
- package/dist/types/packages/core/src/storage/api-messages.d.ts +156 -0
- package/dist/types/packages/core/src/storage/api-topic-brief.d.ts +39 -0
- package/dist/types/packages/core/src/storage/api-topic-config.d.ts +23 -0
- package/dist/types/packages/core/src/storage/api-topics.d.ts +274 -0
- package/dist/types/packages/core/src/storage/app-settings.d.ts +4 -0
- package/dist/types/packages/core/src/storage/ask-user-gates.d.ts +65 -0
- package/dist/types/packages/core/src/storage/browser-profiles.d.ts +31 -0
- package/dist/types/packages/core/src/storage/conversations.d.ts +149 -0
- package/dist/types/packages/core/src/storage/decisions.d.ts +45 -0
- package/dist/types/packages/core/src/storage/forum/agent-settings.d.ts +3 -0
- package/dist/types/packages/core/src/storage/forum/index.d.ts +4 -0
- package/dist/types/packages/core/src/storage/forum/repository.d.ts +42 -0
- package/dist/types/packages/core/src/storage/forum/schema.d.ts +38 -0
- package/dist/types/packages/core/src/storage/forum-db.d.ts +2 -0
- package/dist/types/packages/core/src/storage/remote-session.d.ts +318 -0
- package/dist/types/packages/core/src/storage/runtime-events.d.ts +33 -0
- package/dist/types/packages/core/src/storage/runtime-leases.d.ts +27 -0
- package/dist/types/packages/core/src/storage/runtime-process-leases.d.ts +47 -0
- package/dist/types/packages/core/src/storage/runtime-topic-state.d.ts +39 -0
- package/dist/types/packages/core/src/storage/runtime-turn-requests.d.ts +163 -0
- package/dist/types/packages/core/src/storage/self-schedules.d.ts +54 -0
- package/dist/types/packages/core/src/storage/session-asks.d.ts +78 -0
- package/dist/types/packages/core/src/storage/session-inbox-signal.d.ts +35 -0
- package/dist/types/packages/core/src/storage/session-inbox.d.ts +36 -0
- package/dist/types/packages/core/src/storage/sqlite.d.ts +20 -0
- package/dist/types/packages/core/src/storage/storage-contract.d.ts +46 -0
- package/dist/types/packages/core/src/storage/storage-host.d.ts +41 -0
- package/dist/types/packages/core/src/storage/storage-public-host.d.ts +7 -0
- package/dist/types/packages/core/src/storage/storage-public.d.ts +45 -0
- package/dist/types/packages/core/src/storage/tasks.d.ts +49 -0
- package/dist/types/packages/core/src/storage/token-stats.d.ts +69 -0
- package/dist/types/packages/core/src/storage/topic-archive-state.d.ts +33 -0
- package/dist/types/packages/core/src/storage/topic-archive.d.ts +42 -0
- package/dist/types/packages/core/src/storage/topic-host-mcp-grants.d.ts +5 -0
- package/dist/types/packages/core/src/storage/topic-link-records.d.ts +281 -0
- package/dist/types/packages/core/src/storage/topic-settings.d.ts +19 -0
- package/dist/types/packages/core/src/storage/topic-tool-capabilities.d.ts +37 -0
- package/dist/types/packages/core/src/storage/topic-transcript.d.ts +38 -0
- package/dist/types/packages/core/src/storage/vault-crypto-core.d.ts +6 -0
- package/dist/types/packages/core/src/storage/vault-crypto.d.ts +12 -0
- package/dist/types/packages/core/src/storage/vault-public.d.ts +3 -0
- package/dist/types/packages/core/src/storage/vault-request-gates.d.ts +69 -0
- package/dist/types/packages/core/src/storage/vault.d.ts +49 -0
- package/dist/types/packages/core/src/storage/wiki-summary-names.d.ts +13 -0
- package/dist/types/packages/core/src/storage/wiki.d.ts +15 -0
- package/dist/types/packages/core/src/topics/derive.d.ts +83 -0
- package/dist/types/packages/core/src/topics/lifecycle.d.ts +75 -0
- package/dist/types/packages/core/src/topics/links.d.ts +2 -0
- package/dist/types/packages/core/src/topics/personal-general.d.ts +15 -0
- package/dist/types/packages/core/src/topics/session.d.ts +70 -0
- package/dist/types/packages/core/src/types/api.d.ts +551 -0
- package/dist/types/packages/core/src/types.d.ts +405 -0
- package/dist/types/packages/core/src/version.d.ts +1 -0
- package/dist/types/packages/module-cron/src/background-sessions.d.ts +2 -0
- package/dist/types/packages/module-cron/src/context.d.ts +15 -0
- package/dist/types/packages/module-cron/src/host.d.ts +23 -0
- package/dist/types/packages/module-cron/src/index.d.ts +14 -0
- package/dist/types/packages/module-cron/src/module.d.ts +13 -0
- package/dist/types/packages/module-cron/src/schedule.d.ts +23 -0
- package/dist/types/packages/module-cron/src/scheduler.d.ts +46 -0
- package/dist/types/packages/module-cron/src/scripts.d.ts +29 -0
- package/dist/types/packages/module-cron/src/store.d.ts +152 -0
- package/dist/types/packages/module-cron/src/summarize.d.ts +4 -0
- package/dist/vault.js +848 -0
- package/dist/vault.js.map +18 -0
- package/install-bash-rs.mjs +90 -0
- package/install-browser-rs.mjs +83 -0
- package/package.json +171 -4
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { readTasks, taskFileMtimeNs, taskScopeKey } from "#storage/tasks";
|
|
2
|
+
import type { AgentQueryOptions, UnifiedEvent } from "#types";
|
|
3
|
+
|
|
4
|
+
export interface TaskEventScope {
|
|
5
|
+
userId: string;
|
|
6
|
+
scopeKey: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface TaskEventHost {
|
|
10
|
+
readTasks: typeof readTasks;
|
|
11
|
+
taskFileMtimeNs: typeof taskFileMtimeNs;
|
|
12
|
+
taskScopeKey: typeof taskScopeKey;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const defaultTaskEventHost: TaskEventHost = { readTasks, taskFileMtimeNs, taskScopeKey };
|
|
16
|
+
|
|
17
|
+
export function resolveTaskEventScope(
|
|
18
|
+
opts: AgentQueryOptions,
|
|
19
|
+
host: TaskEventHost = defaultTaskEventHost,
|
|
20
|
+
): TaskEventScope | null {
|
|
21
|
+
if (opts.silent) return null;
|
|
22
|
+
if (!opts.userId) return null;
|
|
23
|
+
if (opts.sessionType === "dm" || opts.sessionType === "ephemeral") {
|
|
24
|
+
return { userId: opts.userId, scopeKey: "dm" };
|
|
25
|
+
}
|
|
26
|
+
if (opts.sessionType === "manager") {
|
|
27
|
+
return { userId: opts.userId, scopeKey: opts.topicId ?? "general" };
|
|
28
|
+
}
|
|
29
|
+
if (!opts.session) return null;
|
|
30
|
+
return {
|
|
31
|
+
userId: opts.userId,
|
|
32
|
+
scopeKey: host.taskScopeKey({ topicId: opts.topicId, session: opts.session }),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The task MCP server runs as a child process of the agent SDK. Its writes do
|
|
38
|
+
* not appear in the provider stream, so after tool results and terminal
|
|
39
|
+
* results we stat the shared store and inject the full task snapshot when it
|
|
40
|
+
* changed.
|
|
41
|
+
*/
|
|
42
|
+
export async function* withTaskSnapshots(
|
|
43
|
+
inner: AsyncGenerator<UnifiedEvent>,
|
|
44
|
+
scope: TaskEventScope,
|
|
45
|
+
host: TaskEventHost = defaultTaskEventHost,
|
|
46
|
+
): AsyncGenerator<UnifiedEvent> {
|
|
47
|
+
let lastMtime = host.taskFileMtimeNs(scope.userId, scope.scopeKey);
|
|
48
|
+
if (host.readTasks(scope.userId, scope.scopeKey).length === 0) {
|
|
49
|
+
yield { type: "tasks", tasks: [] };
|
|
50
|
+
}
|
|
51
|
+
for await (const event of inner) {
|
|
52
|
+
yield event;
|
|
53
|
+
if (event.type !== "tool_result" && event.type !== "result") continue;
|
|
54
|
+
const mtime = host.taskFileMtimeNs(scope.userId, scope.scopeKey);
|
|
55
|
+
if (mtime === lastMtime) continue;
|
|
56
|
+
lastMtime = mtime;
|
|
57
|
+
yield { type: "tasks", tasks: host.readTasks(scope.userId, scope.scopeKey) };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,613 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Format a tool_use event into a human-readable label.
|
|
3
|
+
*
|
|
4
|
+
* Agent-agnostic: the SDKs share the same convention of `(name, input record)`
|
|
5
|
+
* for tool calls, so this lives next to the providers rather than inside any
|
|
6
|
+
* one of them. Used by progress messages, fork relays, and the conversation
|
|
7
|
+
* event processor.
|
|
8
|
+
*/
|
|
9
|
+
import { readFileSync, statSync } from "node:fs";
|
|
10
|
+
import { isAbsolute, resolve } from "node:path";
|
|
11
|
+
import { diffLines as computeLineDiff } from "diff";
|
|
12
|
+
|
|
13
|
+
export type ToolCallSummaryValue =
|
|
14
|
+
| string
|
|
15
|
+
| number
|
|
16
|
+
| boolean
|
|
17
|
+
| Array<{ label: string; description?: string }>;
|
|
18
|
+
|
|
19
|
+
export type ToolCallSummaryInput = Record<string, ToolCallSummaryValue>;
|
|
20
|
+
|
|
21
|
+
const TOOL_SUMMARY_MAX_CHARS = 90;
|
|
22
|
+
const TOOL_SUMMARY_HEAD_CHARS = 52;
|
|
23
|
+
const TOOL_SUMMARY_TAIL_CHARS = 28;
|
|
24
|
+
const TOOL_DIFF_MAX_CHARS = 4_000;
|
|
25
|
+
const TOOL_DIFF_SOURCE_MAX_BYTES = 2_000_000;
|
|
26
|
+
const SHELL_SUMMARY_MAX_PARTS = 3;
|
|
27
|
+
const SSH_OPTIONS_WITH_VALUE = new Set([
|
|
28
|
+
"-B",
|
|
29
|
+
"-b",
|
|
30
|
+
"-c",
|
|
31
|
+
"-D",
|
|
32
|
+
"-E",
|
|
33
|
+
"-e",
|
|
34
|
+
"-F",
|
|
35
|
+
"-I",
|
|
36
|
+
"-i",
|
|
37
|
+
"-J",
|
|
38
|
+
"-L",
|
|
39
|
+
"-l",
|
|
40
|
+
"-m",
|
|
41
|
+
"-O",
|
|
42
|
+
"-o",
|
|
43
|
+
"-p",
|
|
44
|
+
"-Q",
|
|
45
|
+
"-R",
|
|
46
|
+
"-S",
|
|
47
|
+
"-W",
|
|
48
|
+
"-w",
|
|
49
|
+
]);
|
|
50
|
+
|
|
51
|
+
const SUMMARY_KEYS = [
|
|
52
|
+
"command",
|
|
53
|
+
"cmd",
|
|
54
|
+
"file_path",
|
|
55
|
+
"file_id",
|
|
56
|
+
"path",
|
|
57
|
+
"image_path",
|
|
58
|
+
"url",
|
|
59
|
+
"query",
|
|
60
|
+
"pattern",
|
|
61
|
+
"question",
|
|
62
|
+
"task",
|
|
63
|
+
"description",
|
|
64
|
+
"title",
|
|
65
|
+
"change_kind",
|
|
66
|
+
"theme",
|
|
67
|
+
"alt",
|
|
68
|
+
"to",
|
|
69
|
+
] as const;
|
|
70
|
+
|
|
71
|
+
export function summarizeDisplayText(value: string): string {
|
|
72
|
+
const normalized = value.replace(/\s+/g, " ").trim();
|
|
73
|
+
if (!normalized) return "";
|
|
74
|
+
if (normalized.length <= TOOL_SUMMARY_MAX_CHARS) return normalized;
|
|
75
|
+
return `${normalized.slice(0, TOOL_SUMMARY_HEAD_CHARS).trimEnd()}...${normalized
|
|
76
|
+
.slice(-TOOL_SUMMARY_TAIL_CHARS)
|
|
77
|
+
.trimStart()}`;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function unwrapShellCommand(value: string): string {
|
|
81
|
+
const normalized = value.replace(/\s+/g, " ").trim();
|
|
82
|
+
const match = normalized.match(/^(?:\/[^\s]+\/)?(?:zsh|bash|sh)\s+-[a-z]*c\s+(.+)$/i);
|
|
83
|
+
if (!match?.[1]) return normalized;
|
|
84
|
+
const payload = match[1].trim();
|
|
85
|
+
const quote = payload[0];
|
|
86
|
+
return (quote === '"' || quote === "'") && payload.at(-1) === quote
|
|
87
|
+
? payload.slice(1, -1).trim()
|
|
88
|
+
: payload;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function splitShellCommands(value: string): string[] {
|
|
92
|
+
const commands: string[] = [];
|
|
93
|
+
let current = "";
|
|
94
|
+
let quote = "";
|
|
95
|
+
let escaped = false;
|
|
96
|
+
const flush = () => {
|
|
97
|
+
const command = current.trim();
|
|
98
|
+
if (command) commands.push(command);
|
|
99
|
+
current = "";
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
for (let i = 0; i < value.length; i++) {
|
|
103
|
+
const char = value[i] ?? "";
|
|
104
|
+
if (escaped) {
|
|
105
|
+
current += char;
|
|
106
|
+
escaped = false;
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (char === "\\" && quote !== "'") {
|
|
110
|
+
current += char;
|
|
111
|
+
escaped = true;
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
if (quote) {
|
|
115
|
+
current += char;
|
|
116
|
+
if (char === quote) quote = "";
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (char === '"' || char === "'") {
|
|
120
|
+
quote = char;
|
|
121
|
+
current += char;
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
const pair = value.slice(i, i + 2);
|
|
125
|
+
if (pair === "&&" || pair === "||") {
|
|
126
|
+
flush();
|
|
127
|
+
i += 1;
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
if (char === ";") {
|
|
131
|
+
flush();
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
current += char;
|
|
135
|
+
}
|
|
136
|
+
flush();
|
|
137
|
+
return commands;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function shellWords(value: string): string[] {
|
|
141
|
+
const words: string[] = [];
|
|
142
|
+
let current = "";
|
|
143
|
+
let quote = "";
|
|
144
|
+
let escaped = false;
|
|
145
|
+
const flush = () => {
|
|
146
|
+
if (current) words.push(current);
|
|
147
|
+
current = "";
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
for (const char of value) {
|
|
151
|
+
if (escaped) {
|
|
152
|
+
current += char;
|
|
153
|
+
escaped = false;
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
if (char === "\\" && quote !== "'") {
|
|
157
|
+
escaped = true;
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
if (quote) {
|
|
161
|
+
if (char === quote) quote = "";
|
|
162
|
+
else current += char;
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
if (char === '"' || char === "'") {
|
|
166
|
+
quote = char;
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
if (/\s/.test(char)) {
|
|
170
|
+
flush();
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
current += char;
|
|
174
|
+
}
|
|
175
|
+
flush();
|
|
176
|
+
return words;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function commandName(value: string): string {
|
|
180
|
+
return value.replace(/\\/g, "/").split("/").at(-1) || value;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function compactPath(value: string): string {
|
|
184
|
+
const normalized = value.replace(/\\/g, "/").replace(/\/$/, "");
|
|
185
|
+
return normalized.split("/").at(-1) || normalized;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function looksLikePath(value: string): boolean {
|
|
189
|
+
return (
|
|
190
|
+
value.includes("/") ||
|
|
191
|
+
/^\.?[A-Za-z0-9_-]+\.(?:[A-Za-z0-9_-]+)$/.test(value) ||
|
|
192
|
+
/^(?:CLAUDE|AGENTS|README|STYLE)(?:\.[A-Za-z0-9_-]+)?$/i.test(value)
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function summarizeTargets(values: string[]): string {
|
|
197
|
+
const targets = values.filter((value) => value && !value.startsWith("-")).map(compactPath);
|
|
198
|
+
if (targets.length === 0) return "";
|
|
199
|
+
if (targets.length === 1) return targets[0] ?? "";
|
|
200
|
+
return `${targets[0]} +${targets.length - 1}`;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function summarizeSsh(words: string[]): string {
|
|
204
|
+
let destination = "";
|
|
205
|
+
let index = 0;
|
|
206
|
+
while (index < words.length) {
|
|
207
|
+
const word = words[index] ?? "";
|
|
208
|
+
if (word === "--") {
|
|
209
|
+
destination = words[index + 1] ?? "";
|
|
210
|
+
index += 2;
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
if (!word.startsWith("-")) {
|
|
214
|
+
destination = word;
|
|
215
|
+
index += 1;
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
index += SSH_OPTIONS_WITH_VALUE.has(word) ? 2 : 1;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (!destination) return "ssh";
|
|
222
|
+
const remoteCommand = words.slice(index).join(" ");
|
|
223
|
+
const remoteSummary = remoteCommand ? summarizeShellCommand(remoteCommand) : "";
|
|
224
|
+
return ["ssh", destination, remoteSummary].filter(Boolean).join(" · ");
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function summarizeShellPart(value: string): string {
|
|
228
|
+
const words = shellWords(value).filter((word) => !/^\d*>/.test(word));
|
|
229
|
+
while (words[0] === "sudo") words.shift();
|
|
230
|
+
if (words[0] === "env") {
|
|
231
|
+
words.shift();
|
|
232
|
+
while (words[0] && (/^[A-Za-z_][A-Za-z0-9_]*=/.test(words[0]) || words[0].startsWith("-"))) {
|
|
233
|
+
words.shift();
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
const executable = commandName(words.shift() ?? "");
|
|
237
|
+
if (!executable || executable === "true" || executable === "printf" || executable === "echo") {
|
|
238
|
+
return "";
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (executable === "pwd") return "pwd";
|
|
242
|
+
if (executable === "command" && words[0] === "-v") {
|
|
243
|
+
return words[1] ? `find ${commandName(words[1])}` : "find command";
|
|
244
|
+
}
|
|
245
|
+
if (executable === "ssh") return summarizeSsh(words);
|
|
246
|
+
if (executable === "git") {
|
|
247
|
+
while (words[0]?.startsWith("-")) {
|
|
248
|
+
const option = words.shift();
|
|
249
|
+
if (
|
|
250
|
+
option === "-C" ||
|
|
251
|
+
option === "-c" ||
|
|
252
|
+
option === "--git-dir" ||
|
|
253
|
+
option === "--work-tree"
|
|
254
|
+
) {
|
|
255
|
+
words.shift();
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
const operation = words.shift();
|
|
259
|
+
const targets = words.filter((word) => looksLikePath(word));
|
|
260
|
+
const target = summarizeTargets(targets);
|
|
261
|
+
return ["git", operation, target].filter(Boolean).join(" ");
|
|
262
|
+
}
|
|
263
|
+
if (executable === "sed") {
|
|
264
|
+
const target = summarizeTargets(words.filter(looksLikePath));
|
|
265
|
+
return target ? `sed ${target}` : "sed";
|
|
266
|
+
}
|
|
267
|
+
if (executable === "rg") {
|
|
268
|
+
const filesOnly = words.includes("--files");
|
|
269
|
+
const values = words.filter((word) => !word.startsWith("-"));
|
|
270
|
+
const target = summarizeTargets(values);
|
|
271
|
+
return filesOnly ? ["rg files", target].filter(Boolean).join(" ") : `rg ${target || "search"}`;
|
|
272
|
+
}
|
|
273
|
+
if (
|
|
274
|
+
executable === "bun" ||
|
|
275
|
+
executable === "npm" ||
|
|
276
|
+
executable === "pnpm" ||
|
|
277
|
+
executable === "yarn"
|
|
278
|
+
) {
|
|
279
|
+
const operation = words[0];
|
|
280
|
+
if (operation === "test") {
|
|
281
|
+
const targets = words.slice(1).filter((word) => !word.startsWith("-"));
|
|
282
|
+
return targets.length > 0
|
|
283
|
+
? `${executable} test ${targets.length} files`
|
|
284
|
+
: `${executable} test`;
|
|
285
|
+
}
|
|
286
|
+
return [executable, operation].filter(Boolean).join(" ");
|
|
287
|
+
}
|
|
288
|
+
if (executable === "ls" || executable === "cat" || executable === "node") {
|
|
289
|
+
const target = summarizeTargets(words.filter(looksLikePath));
|
|
290
|
+
return [executable, target].filter(Boolean).join(" ");
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const detail = words.find((word) => !word.startsWith("-"));
|
|
294
|
+
return [executable, detail ? compactPath(detail) : ""].filter(Boolean).join(" ");
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/** Convert a raw Codex/Claude shell invocation into a bounded display label. */
|
|
298
|
+
export function summarizeShellCommand(value: string): string {
|
|
299
|
+
const payload = unwrapShellCommand(value);
|
|
300
|
+
const parts = splitShellCommands(payload).map(summarizeShellPart).filter(Boolean);
|
|
301
|
+
if (parts.length === 0) return summarizeDisplayText(payload);
|
|
302
|
+
const visible = parts.slice(0, SHELL_SUMMARY_MAX_PARTS);
|
|
303
|
+
const remainder = parts.length - visible.length;
|
|
304
|
+
return summarizeDisplayText(`${visible.join(" · ")}${remainder > 0 ? ` · +${remainder}` : ""}`);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Give simple, demonstrably read-only shell commands a more meaningful
|
|
309
|
+
* timeline name. This is shared display metadata only; every provider still
|
|
310
|
+
* executes the original shell tool unchanged.
|
|
311
|
+
*/
|
|
312
|
+
export function classifyShellToolName(value: string): "Bash" | "Read" | "Search" {
|
|
313
|
+
// unwrapShellCommand() normalizes whitespace for display, so reject scripts
|
|
314
|
+
// with physical line breaks before that normalization can hide composition.
|
|
315
|
+
if (/[\r\n]/.test(value)) return "Bash";
|
|
316
|
+
const payload = unwrapShellCommand(value);
|
|
317
|
+
// Composition, redirection, substitution, and multi-line scripts can turn
|
|
318
|
+
// a read-only executable into a mutating command, so keep those as Bash.
|
|
319
|
+
if (/[|;&><`]/.test(payload) || payload.includes("$(")) return "Bash";
|
|
320
|
+
|
|
321
|
+
const words = shellWords(payload);
|
|
322
|
+
while (words[0] === "sudo") words.shift();
|
|
323
|
+
if (words[0] === "env") {
|
|
324
|
+
words.shift();
|
|
325
|
+
while (words[0] && (/^[A-Za-z_][A-Za-z0-9_]*=/.test(words[0]) || words[0].startsWith("-"))) {
|
|
326
|
+
words.shift();
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
const executable = commandName(words.shift() ?? "");
|
|
330
|
+
if (
|
|
331
|
+
executable === "cat" ||
|
|
332
|
+
executable === "head" ||
|
|
333
|
+
executable === "tail" ||
|
|
334
|
+
executable === "wc"
|
|
335
|
+
) {
|
|
336
|
+
return "Read";
|
|
337
|
+
}
|
|
338
|
+
if (executable === "sed") {
|
|
339
|
+
const mutatingOption = words.some(
|
|
340
|
+
(word) =>
|
|
341
|
+
word === "-i" ||
|
|
342
|
+
word.startsWith("-i") ||
|
|
343
|
+
word === "--in-place" ||
|
|
344
|
+
word.startsWith("--in-place="),
|
|
345
|
+
);
|
|
346
|
+
const scriptWrites = words.some(
|
|
347
|
+
(word) =>
|
|
348
|
+
/(?:^|[;}\n])\s*(?:w|W|e)\b/.test(word) ||
|
|
349
|
+
/s(.)(?:\\.|(?!\1).)*\1(?:\\.|(?!\1).)*\1[gpimsxyM]*w\b/.test(word),
|
|
350
|
+
);
|
|
351
|
+
if (!mutatingOption && !scriptWrites) return "Read";
|
|
352
|
+
}
|
|
353
|
+
if (executable === "rg" || executable === "grep" || executable === "ls") return "Search";
|
|
354
|
+
if (
|
|
355
|
+
executable === "find" &&
|
|
356
|
+
!words.some((word) =>
|
|
357
|
+
[
|
|
358
|
+
"-delete",
|
|
359
|
+
"-exec",
|
|
360
|
+
"-execdir",
|
|
361
|
+
"-ok",
|
|
362
|
+
"-okdir",
|
|
363
|
+
"-fprint",
|
|
364
|
+
"-fprint0",
|
|
365
|
+
"-fprintf",
|
|
366
|
+
"-fls",
|
|
367
|
+
].includes(word),
|
|
368
|
+
)
|
|
369
|
+
) {
|
|
370
|
+
return "Search";
|
|
371
|
+
}
|
|
372
|
+
return "Bash";
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function summarizePrimitive(value: unknown): string | number | boolean | undefined {
|
|
376
|
+
if (typeof value === "number" || typeof value === "boolean") return value;
|
|
377
|
+
if (typeof value !== "string") return undefined;
|
|
378
|
+
return summarizeDisplayText(value) || undefined;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
function summarizeDiffText(value: unknown): string | undefined {
|
|
382
|
+
if (typeof value !== "string") return undefined;
|
|
383
|
+
const normalized = value.replace(/\r\n?/g, "\n");
|
|
384
|
+
if (!normalized.trim()) return undefined;
|
|
385
|
+
if (normalized.length <= TOOL_DIFF_MAX_CHARS) return normalized;
|
|
386
|
+
return `${normalized.slice(0, TOOL_DIFF_MAX_CHARS - 2)}\n…`;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
function changedDiffLines(value: string): string[] {
|
|
390
|
+
const lines = value.split("\n");
|
|
391
|
+
if (lines.at(-1) === "") lines.pop();
|
|
392
|
+
return lines;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
export interface NumberedDiffSummary {
|
|
396
|
+
before?: string;
|
|
397
|
+
after?: string;
|
|
398
|
+
diffPreview?: string;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/** Build one Git-style numbered diff used by every provider and adapter. */
|
|
402
|
+
export function buildNumberedDiffSummary(
|
|
403
|
+
before: string,
|
|
404
|
+
after: string,
|
|
405
|
+
startLine = 1,
|
|
406
|
+
): NumberedDiffSummary {
|
|
407
|
+
const removed: string[] = [];
|
|
408
|
+
const added: string[] = [];
|
|
409
|
+
const preview: string[] = [];
|
|
410
|
+
let oldLine = startLine;
|
|
411
|
+
let newLine = startLine;
|
|
412
|
+
for (const part of computeLineDiff(before, after)) {
|
|
413
|
+
const lines = changedDiffLines(part.value);
|
|
414
|
+
if (part.removed) {
|
|
415
|
+
for (const line of lines) {
|
|
416
|
+
removed.push(line);
|
|
417
|
+
preview.push(`${oldLine} -${line}`);
|
|
418
|
+
oldLine += 1;
|
|
419
|
+
}
|
|
420
|
+
continue;
|
|
421
|
+
}
|
|
422
|
+
if (part.added) {
|
|
423
|
+
for (const line of lines) {
|
|
424
|
+
added.push(line);
|
|
425
|
+
preview.push(`${newLine} +${line}`);
|
|
426
|
+
newLine += 1;
|
|
427
|
+
}
|
|
428
|
+
continue;
|
|
429
|
+
}
|
|
430
|
+
oldLine += lines.length;
|
|
431
|
+
newLine += lines.length;
|
|
432
|
+
}
|
|
433
|
+
return {
|
|
434
|
+
...(removed.length > 0 ? { before: removed.join("\n") } : {}),
|
|
435
|
+
...(added.length > 0 ? { after: added.join("\n") } : {}),
|
|
436
|
+
...(preview.length > 0 ? { diffPreview: preview.join("\n") } : {}),
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
function sourceStartLine(
|
|
441
|
+
input: Record<string, unknown>,
|
|
442
|
+
before: string,
|
|
443
|
+
after: string,
|
|
444
|
+
cwd: string | undefined,
|
|
445
|
+
): number {
|
|
446
|
+
const rawPath = input.file_path ?? input.path;
|
|
447
|
+
if (typeof rawPath !== "string" || !rawPath.trim()) return 1;
|
|
448
|
+
const path = isAbsolute(rawPath) ? rawPath : resolve(cwd ?? process.cwd(), rawPath);
|
|
449
|
+
try {
|
|
450
|
+
if (statSync(path).size > TOOL_DIFF_SOURCE_MAX_BYTES) return 1;
|
|
451
|
+
const source = readFileSync(path, "utf8").replace(/\r\n?/g, "\n");
|
|
452
|
+
for (const candidate of [before, after].filter(Boolean)) {
|
|
453
|
+
const index = source.indexOf(candidate);
|
|
454
|
+
if (index >= 0) return source.slice(0, index).split("\n").length;
|
|
455
|
+
}
|
|
456
|
+
} catch {
|
|
457
|
+
// Deleted and remote-only files fall back to snippet-relative numbering.
|
|
458
|
+
}
|
|
459
|
+
return 1;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
function logicalLineCount(value: string): number {
|
|
463
|
+
const normalized = value.replace(/\r\n?/g, "\n");
|
|
464
|
+
if (!normalized) return 0;
|
|
465
|
+
const withoutFinalTerminator = normalized.endsWith("\n") ? normalized.slice(0, -1) : normalized;
|
|
466
|
+
return withoutFinalTerminator.split("\n").length;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
function summarizeAskChoices(
|
|
470
|
+
value: unknown,
|
|
471
|
+
): Array<{ label: string; description?: string }> | undefined {
|
|
472
|
+
if (!Array.isArray(value)) return undefined;
|
|
473
|
+
const choices = value
|
|
474
|
+
.map((choice) => {
|
|
475
|
+
if (!choice || typeof choice !== "object") return null;
|
|
476
|
+
const record = choice as Record<string, unknown>;
|
|
477
|
+
const label = summarizePrimitive(record.label);
|
|
478
|
+
if (typeof label !== "string") return null;
|
|
479
|
+
const description = summarizePrimitive(record.description);
|
|
480
|
+
return {
|
|
481
|
+
label,
|
|
482
|
+
...(typeof description === "string" ? { description } : {}),
|
|
483
|
+
};
|
|
484
|
+
})
|
|
485
|
+
.filter((choice): choice is { label: string; description?: string } => choice !== null)
|
|
486
|
+
.slice(0, 6);
|
|
487
|
+
return choices.length > 0 ? choices : undefined;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
export function summarizeToolInput(
|
|
491
|
+
name: string,
|
|
492
|
+
input: Record<string, unknown>,
|
|
493
|
+
options: { cwd?: string } = {},
|
|
494
|
+
): ToolCallSummaryInput | undefined {
|
|
495
|
+
const summary: ToolCallSummaryInput = {};
|
|
496
|
+
const shortName = name.split("__").at(-1)?.toLowerCase() ?? name.toLowerCase();
|
|
497
|
+
|
|
498
|
+
if (name === "AskUserQuestion") {
|
|
499
|
+
const question = summarizePrimitive(input.question);
|
|
500
|
+
if (typeof question === "string") summary.question = question;
|
|
501
|
+
const choices = summarizeAskChoices(input.choices);
|
|
502
|
+
if (choices) summary.choices = choices;
|
|
503
|
+
return Object.keys(summary).length > 0 ? summary : undefined;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
for (const key of SUMMARY_KEYS) {
|
|
507
|
+
const raw = input[key];
|
|
508
|
+
const value =
|
|
509
|
+
(key === "command" || key === "cmd") && typeof raw === "string"
|
|
510
|
+
? summarizeShellCommand(raw)
|
|
511
|
+
: summarizePrimitive(raw);
|
|
512
|
+
if (value !== undefined) summary[key] = value;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
if (shortName === "ask_session" || shortName === "tell_session") {
|
|
516
|
+
const message = summarizePrimitive(input.message);
|
|
517
|
+
if (typeof message === "string") summary.message = message;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
if (shortName === "edit" || shortName === "delete") {
|
|
521
|
+
const rawBefore = input.before ?? input.old_string;
|
|
522
|
+
const rawAfter = input.after ?? input.new_string;
|
|
523
|
+
const before = summarizeDiffText(rawBefore);
|
|
524
|
+
if (before !== undefined) summary.before = before;
|
|
525
|
+
if (shortName === "edit") {
|
|
526
|
+
const after = summarizeDiffText(rawAfter);
|
|
527
|
+
if (after !== undefined) summary.after = after;
|
|
528
|
+
}
|
|
529
|
+
const normalizedBefore =
|
|
530
|
+
typeof rawBefore === "string" ? rawBefore.replace(/\r\n?/g, "\n") : undefined;
|
|
531
|
+
const normalizedAfter =
|
|
532
|
+
typeof rawAfter === "string" ? rawAfter.replace(/\r\n?/g, "\n") : undefined;
|
|
533
|
+
const generatedPreview =
|
|
534
|
+
options.cwd &&
|
|
535
|
+
normalizedBefore !== undefined &&
|
|
536
|
+
(shortName === "delete" || normalizedAfter !== undefined)
|
|
537
|
+
? buildNumberedDiffSummary(
|
|
538
|
+
normalizedBefore,
|
|
539
|
+
shortName === "edit" ? (normalizedAfter ?? "") : "",
|
|
540
|
+
sourceStartLine(
|
|
541
|
+
input,
|
|
542
|
+
normalizedBefore,
|
|
543
|
+
shortName === "edit" ? (normalizedAfter ?? "") : "",
|
|
544
|
+
options.cwd,
|
|
545
|
+
),
|
|
546
|
+
).diffPreview
|
|
547
|
+
: undefined;
|
|
548
|
+
const diffPreview = summarizeDiffText(input.diff_preview ?? generatedPreview);
|
|
549
|
+
if (diffPreview !== undefined) summary.diff_preview = diffPreview;
|
|
550
|
+
}
|
|
551
|
+
if (shortName === "write") {
|
|
552
|
+
const content =
|
|
553
|
+
typeof input.content === "string"
|
|
554
|
+
? input.content
|
|
555
|
+
: typeof input.after === "string"
|
|
556
|
+
? input.after
|
|
557
|
+
: undefined;
|
|
558
|
+
const preview = summarizeDiffText(content);
|
|
559
|
+
if (preview !== undefined) summary.preview = preview;
|
|
560
|
+
if (content !== undefined) summary.lines = logicalLineCount(content);
|
|
561
|
+
const normalizedContent = content?.replace(/\r\n?/g, "\n");
|
|
562
|
+
const generatedPreview =
|
|
563
|
+
options.cwd && normalizedContent !== undefined
|
|
564
|
+
? buildNumberedDiffSummary(
|
|
565
|
+
"",
|
|
566
|
+
normalizedContent,
|
|
567
|
+
sourceStartLine(input, "", normalizedContent, options.cwd),
|
|
568
|
+
).diffPreview
|
|
569
|
+
: undefined;
|
|
570
|
+
const diffPreview = summarizeDiffText(input.diff_preview ?? generatedPreview);
|
|
571
|
+
if (diffPreview !== undefined) summary.diff_preview = diffPreview;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
return Object.keys(summary).length > 0 ? summary : undefined;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
export function formatToolUse(name: string, input: Record<string, unknown>): string {
|
|
578
|
+
const rawCommand = input.command || input.cmd;
|
|
579
|
+
const shortName = name.split("__").at(-1)?.toLowerCase() ?? name.toLowerCase();
|
|
580
|
+
const displayName =
|
|
581
|
+
shortName === "bash" && rawCommand ? classifyShellToolName(String(rawCommand)) : name;
|
|
582
|
+
let detail = "";
|
|
583
|
+
if (displayName === "View" && input.question) {
|
|
584
|
+
const file = input.image_path || input.file_path || input.path;
|
|
585
|
+
const fileName = typeof file === "string" ? file.split("/").pop() : "";
|
|
586
|
+
const suffix = fileName ? ` [${fileName}]` : "";
|
|
587
|
+
detail = `${String(input.question)}${suffix}`;
|
|
588
|
+
} else if ((displayName === "Agent" || displayName === "Task") && input.subagent_type) {
|
|
589
|
+
const type = String(input.subagent_type);
|
|
590
|
+
const desc = input.description ? ` ${String(input.description).slice(0, 60)}` : "";
|
|
591
|
+
detail = `[${type}]${desc}`;
|
|
592
|
+
} else if (rawCommand) {
|
|
593
|
+
const command = summarizeShellCommand(String(rawCommand));
|
|
594
|
+
detail =
|
|
595
|
+
(displayName === "Read" || displayName === "Search") && command.includes(" ")
|
|
596
|
+
? command.slice(command.indexOf(" ") + 1)
|
|
597
|
+
: command;
|
|
598
|
+
} else if (input.file_path || input.path) detail = String(input.file_path || input.path);
|
|
599
|
+
else if (input.file_id) detail = String(input.file_id);
|
|
600
|
+
else if (input.url) detail = String(input.url);
|
|
601
|
+
else if (input.pattern) detail = String(input.pattern);
|
|
602
|
+
else if (input.query || input.text) detail = String(input.query || input.text);
|
|
603
|
+
else if (input.task) detail = String(input.task);
|
|
604
|
+
else if (input.title) detail = String(input.title);
|
|
605
|
+
else if (input.to) detail = String(input.to);
|
|
606
|
+
else if (input.message) detail = String(input.message).slice(0, 80);
|
|
607
|
+
else if (input.content) detail = String(input.content).slice(0, 80);
|
|
608
|
+
|
|
609
|
+
if (detail) {
|
|
610
|
+
return `${displayName}(${detail.length > 100 ? `${detail.slice(0, 100)}...` : detail})`;
|
|
611
|
+
}
|
|
612
|
+
return displayName;
|
|
613
|
+
}
|