@armadra/agent 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +177 -294
- package/CHANGELOG.zh-CN.md +442 -0
- package/README.md +408 -364
- package/README.zh-CN.md +705 -0
- package/dist/agent/session-plan.js +2 -2
- package/dist/agent/session-state.d.ts +3 -0
- package/dist/agent/session-state.js +20 -0
- package/dist/agent/session-subagent.d.ts +15 -1
- package/dist/agent/session-subagent.js +26 -3
- package/dist/agent/session-telemetry.d.ts +16 -2
- package/dist/agent/session-telemetry.js +29 -7
- package/dist/agent/session-tools.js +5 -2
- package/dist/agent/session-trace-writer.d.ts +27 -0
- package/dist/agent/session-trace-writer.js +253 -0
- package/dist/agent/session.d.ts +2 -0
- package/dist/agent/session.js +12 -0
- package/dist/agent/subagent-direct.d.ts +20 -0
- package/dist/agent/subagent-direct.js +76 -0
- package/dist/agent/subagent-registry.d.ts +8 -1
- package/dist/agent/subagent-registry.js +28 -1
- package/dist/agent/system-prompt.d.ts +3 -1
- package/dist/agent/system-prompt.js +3 -0
- package/dist/agent/tool-runner.d.ts +2 -1
- package/dist/agent/tool-runner.js +5 -4
- package/dist/agent/types-w6.d.ts +39 -0
- package/dist/agent/types-w6.js +4 -0
- package/dist/agent/types.d.ts +5 -2
- package/dist/agents/external.js +1 -1
- package/dist/agents/task-record.d.ts +74 -1
- package/dist/agents/task-record.js +100 -0
- package/dist/ai/apis/cache-params.js +2 -1
- package/dist/ai/apis/chatgpt-backend.d.ts +52 -0
- package/dist/ai/apis/chatgpt-backend.js +224 -0
- package/dist/ai/apis/chatgpt-rate-limits.d.ts +26 -0
- package/dist/ai/apis/chatgpt-rate-limits.js +91 -0
- package/dist/ai/apis/openai-responses-request.d.ts +2 -1
- package/dist/ai/apis/openai-responses-request.js +8 -2
- package/dist/ai/apis/openai-responses.d.ts +2 -0
- package/dist/ai/apis/openai-responses.js +51 -16
- package/dist/ai/overflow.d.ts +1 -1
- package/dist/ai/overflow.js +10 -7
- package/dist/ai/providers/auth.d.ts +15 -2
- package/dist/ai/providers/auth.js +69 -2
- package/dist/ai/providers/builtin.js +27 -0
- package/dist/ai/providers/catalog-data.js +1 -0
- package/dist/ai/providers/enrich.js +2 -7
- package/dist/ai/providers/models-dev-cache.js +15 -19
- package/dist/ai/providers/models-dev-snapshot.js +8 -7
- package/dist/ai/providers/models-dev.js +5 -15
- package/dist/ai/providers/suggest.js +2 -16
- package/dist/ai/types.d.ts +27 -1
- package/dist/auth/chatgpt/backend-client.d.ts +26 -0
- package/dist/auth/chatgpt/backend-client.js +74 -0
- package/dist/auth/chatgpt/claims.d.ts +17 -0
- package/dist/auth/chatgpt/claims.js +46 -0
- package/dist/auth/chatgpt/cli.d.ts +33 -0
- package/dist/auth/chatgpt/cli.js +252 -0
- package/dist/auth/chatgpt/doctor.d.ts +17 -0
- package/dist/auth/chatgpt/doctor.js +36 -0
- package/dist/auth/chatgpt/host-id.d.ts +7 -0
- package/dist/auth/chatgpt/host-id.js +26 -0
- package/dist/auth/chatgpt/login.d.ts +30 -0
- package/dist/auth/chatgpt/login.js +130 -0
- package/dist/auth/chatgpt/presets.d.ts +66 -0
- package/dist/auth/chatgpt/presets.js +120 -0
- package/dist/auth/chatgpt/quota-text.d.ts +13 -0
- package/dist/auth/chatgpt/quota-text.js +36 -0
- package/dist/auth/oauth/browser.d.ts +12 -0
- package/dist/auth/oauth/browser.js +27 -0
- package/dist/auth/oauth/callback-server.d.ts +47 -0
- package/dist/auth/oauth/callback-server.js +147 -0
- package/dist/auth/oauth/flows.d.ts +62 -0
- package/dist/auth/oauth/flows.js +113 -0
- package/dist/auth/oauth/jwt.d.ts +24 -0
- package/dist/auth/oauth/jwt.js +81 -0
- package/dist/auth/oauth/live.d.ts +21 -0
- package/dist/auth/oauth/live.js +25 -0
- package/dist/auth/oauth/oidc.d.ts +26 -0
- package/dist/auth/oauth/oidc.js +72 -0
- package/dist/auth/oauth/pkce.d.ts +15 -0
- package/dist/auth/oauth/pkce.js +20 -0
- package/dist/auth/oauth/refresh.d.ts +35 -0
- package/dist/auth/oauth/refresh.js +129 -0
- package/dist/auth/oauth/token-client.d.ts +33 -0
- package/dist/auth/oauth/token-client.js +121 -0
- package/dist/auth/oauth/token-store.d.ts +23 -0
- package/dist/auth/oauth/token-store.js +125 -0
- package/dist/auth/testing/fake-oauth.d.ts +73 -0
- package/dist/auth/testing/fake-oauth.js +271 -0
- package/dist/auth/testing/refresh-child.d.ts +5 -0
- package/dist/auth/testing/refresh-child.js +16 -0
- package/dist/bundle/ama.cjs +28307 -13241
- package/dist/checkpoints/backend.js +6 -5
- package/dist/checkpoints/restore.js +3 -2
- package/dist/checkpoints/settings.js +2 -1
- package/dist/checkpoints/shadow-git.js +7 -6
- package/dist/checkpoints/shadow-restore.js +3 -2
- package/dist/checkpoints/tracker.js +4 -3
- package/dist/cli/args.d.ts +9 -2
- package/dist/cli/args.js +74 -27
- package/dist/cli/bootstrap.js +53 -31
- package/dist/cli/choice-prompt.d.ts +58 -0
- package/dist/cli/choice-prompt.js +142 -0
- package/dist/cli/codemode-notice.js +2 -2
- package/dist/cli/compose-agents.js +2 -1
- package/dist/cli/compose-extensions.js +2 -0
- package/dist/cli/compose-memory.d.ts +53 -0
- package/dist/cli/compose-memory.js +127 -0
- package/dist/cli/compose-providers.d.ts +5 -0
- package/dist/cli/compose-providers.js +32 -2
- package/dist/cli/compose-session.d.ts +5 -0
- package/dist/cli/compose-session.js +27 -13
- package/dist/cli/compose-store.d.ts +2 -0
- package/dist/cli/compose-store.js +9 -5
- package/dist/cli/compose.d.ts +2 -0
- package/dist/cli/compose.js +13 -5
- package/dist/cli/default-model.d.ts +0 -2
- package/dist/cli/default-model.js +5 -8
- package/dist/cli/deps.d.ts +5 -1
- package/dist/cli/exit-codes.d.ts +1 -1
- package/dist/cli/exit-codes.js +7 -16
- package/dist/cli/from-prompt.js +3 -2
- package/dist/cli/help-text.d.ts +2 -1
- package/dist/cli/help-text.js +5 -99
- package/dist/cli/main.d.ts +5 -0
- package/dist/cli/main.js +21 -2
- package/dist/cli/proxy.js +14 -9
- package/dist/cli/runtime.d.ts +5 -0
- package/dist/cli/startup-screen.js +20 -27
- package/dist/cli/startup-steps.js +6 -8
- package/dist/cli/subcommands/auth.d.ts +6 -3
- package/dist/cli/subcommands/auth.js +52 -22
- package/dist/cli/subcommands/config-set.d.ts +21 -0
- package/dist/cli/subcommands/config-set.js +137 -0
- package/dist/cli/subcommands/config.d.ts +2 -1
- package/dist/cli/subcommands/config.js +51 -37
- package/dist/cli/subcommands/doctor.d.ts +2 -1
- package/dist/cli/subcommands/doctor.js +97 -58
- package/dist/cli/subcommands/init.d.ts +1 -1
- package/dist/cli/subcommands/init.js +8 -7
- package/dist/cli/subcommands/memory.d.ts +18 -0
- package/dist/cli/subcommands/memory.js +189 -0
- package/dist/cli/subcommands/model-meta.js +11 -9
- package/dist/cli/subcommands/models-cache-probe.d.ts +1 -1
- package/dist/cli/subcommands/models-cache-probe.js +26 -32
- package/dist/cli/subcommands/models-discover.d.ts +3 -0
- package/dist/cli/subcommands/models-discover.js +44 -21
- package/dist/cli/subcommands/models.d.ts +1 -1
- package/dist/cli/subcommands/models.js +29 -22
- package/dist/cli/subcommands/probe-runner.js +8 -7
- package/dist/cli/subcommands/providers-list.js +32 -21
- package/dist/cli/subcommands/providers-plan.js +24 -25
- package/dist/cli/subcommands/providers-probe.js +5 -6
- package/dist/cli/subcommands/providers.d.ts +2 -2
- package/dist/cli/subcommands/providers.js +48 -59
- package/dist/cli/subcommands/sessions-export.d.ts +1 -1
- package/dist/cli/subcommands/sessions-export.js +10 -9
- package/dist/cli/subcommands/sessions-search.d.ts +1 -1
- package/dist/cli/subcommands/sessions-search.js +11 -10
- package/dist/cli/subcommands/sessions-trace.d.ts +30 -0
- package/dist/cli/subcommands/sessions-trace.js +156 -0
- package/dist/cli/subcommands/sessions.d.ts +4 -3
- package/dist/cli/subcommands/sessions.js +40 -37
- package/dist/cli/subcommands/stats.d.ts +1 -1
- package/dist/cli/subcommands/stats.js +49 -30
- package/dist/cli/system-prompt-arg.js +3 -2
- package/dist/codemode/capability.js +3 -2
- package/dist/compaction/post-compact.d.ts +1 -0
- package/dist/compaction/post-compact.js +15 -1
- package/dist/compaction/prune-tier.d.ts +1 -1
- package/dist/compaction/prune-tier.js +3 -3
- package/dist/compaction/serialize.js +2 -1
- package/dist/config/auth-file.d.ts +12 -2
- package/dist/config/auth-file.js +32 -10
- package/dist/config/checker.js +12 -11
- package/dist/config/context-files.js +3 -2
- package/dist/config/edit.d.ts +106 -0
- package/dist/config/edit.js +350 -0
- package/dist/config/init.d.ts +4 -3
- package/dist/config/init.js +10 -18
- package/dist/config/json-schema.d.ts +2 -1
- package/dist/config/json-schema.js +101 -68
- package/dist/config/key-docs.d.ts +18 -7
- package/dist/config/key-docs.js +43 -128
- package/dist/config/load.js +7 -6
- package/dist/config/merge.d.ts +4 -1
- package/dist/config/merge.js +42 -22
- package/dist/config/paths.js +6 -5
- package/dist/config/profile.d.ts +5 -1
- package/dist/config/profile.js +7 -2
- package/dist/config/schema-w5.js +3 -2
- package/dist/config/schema-w6.d.ts +19 -0
- package/dist/config/schema-w6.js +115 -0
- package/dist/config/schema.js +34 -20
- package/dist/config/settings-registry.d.ts +78 -0
- package/dist/config/settings-registry.js +184 -0
- package/dist/config/types-w6.d.ts +109 -0
- package/dist/config/types-w6.js +19 -0
- package/dist/config/types.d.ts +11 -8
- package/dist/config/types.js +1 -0
- package/dist/drivers/acp/client.js +1 -1
- package/dist/drivers/acp/driver.js +13 -8
- package/dist/drivers/agents.js +4 -3
- package/dist/drivers/base.js +3 -2
- package/dist/drivers/host-runners.js +2 -1
- package/dist/drivers/native/claude-stream.js +12 -11
- package/dist/drivers/native/codex-app-server.js +17 -12
- package/dist/drivers/native/oneshot.js +8 -7
- package/dist/drivers/pool.js +1 -1
- package/dist/drivers/runner.d.ts +3 -1
- package/dist/drivers/runner.js +68 -20
- package/dist/drivers/turn.js +1 -1
- package/dist/hooks/config.js +3 -2
- package/dist/hooks/protocol.js +18 -12
- package/dist/host/api-impl.js +11 -10
- package/dist/host/loader.js +9 -8
- package/dist/host/types.d.ts +3 -0
- package/dist/i18n/catalog.d.ts +2169 -0
- package/dist/i18n/catalog.js +72 -0
- package/dist/i18n/format.d.ts +21 -0
- package/dist/i18n/format.js +58 -0
- package/dist/i18n/index.d.ts +58 -0
- package/dist/i18n/index.js +72 -0
- package/dist/i18n/messages/agents.d.ts +84 -0
- package/dist/i18n/messages/agents.js +85 -0
- package/dist/i18n/messages/approval.d.ts +99 -0
- package/dist/i18n/messages/approval.js +100 -0
- package/dist/i18n/messages/auth.d.ts +187 -0
- package/dist/i18n/messages/auth.js +189 -0
- package/dist/i18n/messages/cli-args.d.ts +46 -0
- package/dist/i18n/messages/cli-args.js +46 -0
- package/dist/i18n/messages/cli-help.d.ts +12 -0
- package/dist/i18n/messages/cli-help.js +244 -0
- package/dist/i18n/messages/cli.d.ts +336 -0
- package/dist/i18n/messages/cli.js +311 -0
- package/dist/i18n/messages/config-keys.d.ts +289 -0
- package/dist/i18n/messages/config-keys.js +292 -0
- package/dist/i18n/messages/config.d.ts +502 -0
- package/dist/i18n/messages/config.js +239 -0
- package/dist/i18n/messages/drivers.d.ts +123 -0
- package/dist/i18n/messages/drivers.js +124 -0
- package/dist/i18n/messages/errors.d.ts +83 -0
- package/dist/i18n/messages/errors.js +171 -0
- package/dist/i18n/messages/interactive-line.d.ts +61 -0
- package/dist/i18n/messages/interactive-line.js +69 -0
- package/dist/i18n/messages/interactive-startup.d.ts +103 -0
- package/dist/i18n/messages/interactive-startup.js +104 -0
- package/dist/i18n/messages/interactive-view.d.ts +140 -0
- package/dist/i18n/messages/interactive-view.js +141 -0
- package/dist/i18n/messages/interactive.d.ts +493 -0
- package/dist/i18n/messages/interactive.js +248 -0
- package/dist/i18n/messages/memory.d.ts +123 -0
- package/dist/i18n/messages/memory.js +128 -0
- package/dist/i18n/messages/panels.d.ts +190 -0
- package/dist/i18n/messages/panels.js +189 -0
- package/dist/i18n/messages/permissions.d.ts +126 -0
- package/dist/i18n/messages/permissions.js +151 -0
- package/dist/i18n/messages/plan.d.ts +123 -0
- package/dist/i18n/messages/plan.js +124 -0
- package/dist/i18n/messages/print.d.ts +86 -0
- package/dist/i18n/messages/print.js +91 -0
- package/dist/i18n/messages/report.d.ts +391 -0
- package/dist/i18n/messages/report.js +490 -0
- package/dist/i18n/messages/rewind.d.ts +198 -0
- package/dist/i18n/messages/rewind.js +217 -0
- package/dist/i18n/messages/session.d.ts +230 -0
- package/dist/i18n/messages/session.js +258 -0
- package/dist/i18n/messages/settings.d.ts +348 -0
- package/dist/i18n/messages/settings.js +336 -0
- package/dist/i18n/messages/subcommands-config.d.ts +111 -0
- package/dist/i18n/messages/subcommands-config.js +127 -0
- package/dist/i18n/messages/subcommands.d.ts +548 -0
- package/dist/i18n/messages/subcommands.js +474 -0
- package/dist/i18n/messages/trace.d.ts +243 -0
- package/dist/i18n/messages/trace.js +238 -0
- package/dist/i18n/types.d.ts +15 -0
- package/dist/i18n/types.js +7 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +2 -0
- package/dist/memory/edit.d.ts +24 -0
- package/dist/memory/edit.js +63 -0
- package/dist/memory/frontmatter.d.ts +37 -0
- package/dist/memory/frontmatter.js +79 -0
- package/dist/memory/index.d.ts +28 -0
- package/dist/memory/index.js +126 -0
- package/dist/memory/lock.d.ts +17 -0
- package/dist/memory/lock.js +62 -0
- package/dist/memory/paths.d.ts +57 -0
- package/dist/memory/paths.js +175 -0
- package/dist/memory/report.d.ts +36 -0
- package/dist/memory/report.js +86 -0
- package/dist/memory/runtime.d.ts +42 -0
- package/dist/memory/runtime.js +36 -0
- package/dist/memory/secrets.d.ts +8 -0
- package/dist/memory/secrets.js +27 -0
- package/dist/memory/section.d.ts +28 -0
- package/dist/memory/section.js +59 -0
- package/dist/memory/store.d.ts +70 -0
- package/dist/memory/store.js +284 -0
- package/dist/memory/tool.d.ts +31 -0
- package/dist/memory/tool.js +94 -0
- package/dist/modes/acp/acp-events.js +2 -1
- package/dist/modes/acp/acp-server.js +13 -12
- package/dist/modes/commands-core.d.ts +17 -0
- package/dist/modes/commands-core.js +101 -61
- package/dist/modes/image-input.js +20 -6
- package/dist/modes/interactive/agent-bar.d.ts +95 -0
- package/dist/modes/interactive/agent-bar.js +248 -0
- package/dist/modes/interactive/agent-panels.js +27 -26
- package/dist/modes/interactive/agent-transcript.d.ts +47 -0
- package/dist/modes/interactive/agent-transcript.js +191 -0
- package/dist/modes/interactive/agent-ui.d.ts +36 -1
- package/dist/modes/interactive/agent-ui.js +180 -14
- package/dist/modes/interactive/agent-view.d.ts +72 -0
- package/dist/modes/interactive/agent-view.js +281 -0
- package/dist/modes/interactive/approval-dialog.js +46 -34
- package/dist/modes/interactive/clipboard-paste.d.ts +2 -2
- package/dist/modes/interactive/clipboard-paste.js +9 -4
- package/dist/modes/interactive/commands.d.ts +22 -1
- package/dist/modes/interactive/commands.js +93 -38
- package/dist/modes/interactive/completion.js +2 -1
- package/dist/modes/interactive/config-panel.d.ts +70 -0
- package/dist/modes/interactive/config-panel.js +319 -0
- package/dist/modes/interactive/config-ui.d.ts +96 -0
- package/dist/modes/interactive/config-ui.js +397 -0
- package/dist/modes/interactive/confirm-dialog.d.ts +49 -0
- package/dist/modes/interactive/confirm-dialog.js +120 -0
- package/dist/modes/interactive/event-notices.js +11 -9
- package/dist/modes/interactive/interactive-mode.d.ts +1 -1
- package/dist/modes/interactive/interactive-mode.js +25 -22
- package/dist/modes/interactive/key-dispatch.d.ts +18 -0
- package/dist/modes/interactive/key-dispatch.js +39 -13
- package/dist/modes/interactive/line/line-editor.js +2 -1
- package/dist/modes/interactive/line/line-mode.d.ts +2 -0
- package/dist/modes/interactive/line/line-mode.js +24 -4
- package/dist/modes/interactive/line/line-render.js +25 -24
- package/dist/modes/interactive/memory-panel.d.ts +64 -0
- package/dist/modes/interactive/memory-panel.js +221 -0
- package/dist/modes/interactive/message-view.d.ts +4 -2
- package/dist/modes/interactive/message-view.js +42 -33
- package/dist/modes/interactive/panels.js +39 -31
- package/dist/modes/interactive/pickers.d.ts +2 -1
- package/dist/modes/interactive/pickers.js +10 -6
- package/dist/modes/interactive/plan-command.d.ts +1 -1
- package/dist/modes/interactive/plan-command.js +24 -27
- package/dist/modes/interactive/plan-dialog.js +18 -17
- package/dist/modes/interactive/plan-flow.js +6 -5
- package/dist/modes/interactive/rewind-command.d.ts +1 -1
- package/dist/modes/interactive/rewind-command.js +18 -16
- package/dist/modes/interactive/rewind-flow.d.ts +0 -1
- package/dist/modes/interactive/rewind-flow.js +13 -14
- package/dist/modes/interactive/rewind-list.js +7 -6
- package/dist/modes/interactive/rewind-panel.js +40 -40
- package/dist/modes/interactive/rewind-text.d.ts +5 -3
- package/dist/modes/interactive/rewind-text.js +48 -38
- package/dist/modes/interactive/run-indicator.js +15 -12
- package/dist/modes/interactive/session-events.js +3 -2
- package/dist/modes/interactive/startup-header.js +22 -23
- package/dist/modes/interactive/startup-ui.js +41 -29
- package/dist/modes/interactive/status-area.d.ts +2 -0
- package/dist/modes/interactive/status-area.js +8 -2
- package/dist/modes/interactive/status-bar.js +4 -3
- package/dist/modes/interactive/subagent-view.js +9 -7
- package/dist/modes/interactive/tasks-report.d.ts +6 -0
- package/dist/modes/interactive/tasks-report.js +28 -31
- package/dist/modes/interactive/terminal-setup.d.ts +9 -0
- package/dist/modes/interactive/terminal-setup.js +23 -0
- package/dist/modes/interactive/tool-summary.js +19 -17
- package/dist/modes/interactive/tool-view.js +7 -4
- package/dist/modes/interactive/trace-view.d.ts +89 -0
- package/dist/modes/interactive/trace-view.js +332 -0
- package/dist/modes/print/print-mode.js +14 -15
- package/dist/modes/rpc/commands.js +7 -3
- package/dist/modes/rpc/rpc-mode.js +9 -3
- package/dist/modes/session-report.d.ts +2 -0
- package/dist/modes/session-report.js +101 -105
- package/dist/modes/startup-ui-text.js +11 -6
- package/dist/permissions/bypass.d.ts +30 -0
- package/dist/permissions/bypass.js +45 -0
- package/dist/permissions/memory-class.d.ts +23 -0
- package/dist/permissions/memory-class.js +54 -0
- package/dist/permissions/modes.d.ts +3 -3
- package/dist/permissions/modes.js +21 -16
- package/dist/permissions/pipeline.d.ts +1 -1
- package/dist/permissions/pipeline.js +9 -2
- package/dist/permissions/preview.js +49 -42
- package/dist/permissions/rules.js +5 -2
- package/dist/permissions/types.d.ts +4 -0
- package/dist/plan/store.js +2 -1
- package/dist/rpc.d.ts +39 -1
- package/dist/rpc.js +3 -0
- package/dist/sandbox/bash.js +11 -8
- package/dist/sandbox/detect.js +14 -11
- package/dist/sdk.d.ts +17 -1
- package/dist/sdk.js +29 -7
- package/dist/session/export.js +31 -30
- package/dist/session/manager.d.ts +1 -1
- package/dist/session/manager.js +5 -3
- package/dist/session/reuse.js +5 -4
- package/dist/session/scan.js +3 -2
- package/dist/session/stats-aggregate.d.ts +3 -1
- package/dist/session/stats-aggregate.js +5 -1
- package/dist/session/stats-index.js +2 -1
- package/dist/session/stats-scan.d.ts +4 -1
- package/dist/session/stats-scan.js +6 -2
- package/dist/session/store.d.ts +11 -0
- package/dist/session/store.js +48 -1
- package/dist/session/types.d.ts +2 -0
- package/dist/skills/builtin.js +2 -1
- package/dist/tools/image-file.d.ts +26 -1
- package/dist/tools/image-file.js +55 -13
- package/dist/tools/presets.d.ts +14 -1
- package/dist/tools/presets.js +3 -3
- package/dist/tools/registry.js +1 -1
- package/dist/tools/truncate.d.ts +1 -1
- package/dist/tools/truncate.js +2 -2
- package/dist/tools/types.d.ts +17 -1
- package/dist/trace/build-index.d.ts +91 -0
- package/dist/trace/build-index.js +127 -0
- package/dist/trace/build-nodes.d.ts +24 -0
- package/dist/trace/build-nodes.js +279 -0
- package/dist/trace/build-util.d.ts +43 -0
- package/dist/trace/build-util.js +120 -0
- package/dist/trace/build.d.ts +82 -0
- package/dist/trace/build.js +382 -0
- package/dist/trace/detail.d.ts +35 -0
- package/dist/trace/detail.js +205 -0
- package/dist/trace/flatten.d.ts +69 -0
- package/dist/trace/flatten.js +173 -0
- package/dist/trace/format.d.ts +47 -0
- package/dist/trace/format.js +329 -0
- package/dist/trace/html-template.d.ts +19 -0
- package/dist/trace/html-template.js +150 -0
- package/dist/trace/html.d.ts +104 -0
- package/dist/trace/html.js +292 -0
- package/dist/trace/preview.d.ts +29 -0
- package/dist/trace/preview.js +59 -0
- package/dist/trace/query-session.d.ts +14 -0
- package/dist/trace/query-session.js +38 -0
- package/dist/trace/query.d.ts +55 -0
- package/dist/trace/query.js +188 -0
- package/dist/trace/session.d.ts +40 -0
- package/dist/trace/session.js +168 -0
- package/dist/trace/types.d.ts +243 -0
- package/dist/trace/types.js +13 -0
- package/dist/tui/components/editor-paste.d.ts +2 -0
- package/dist/tui/components/editor-paste.js +6 -3
- package/dist/tui/components/editor.js +2 -2
- package/dist/tui/components/loader.d.ts +3 -0
- package/dist/tui/components/loader.js +14 -0
- package/dist/tui/components/settings-list.d.ts +61 -0
- package/dist/tui/components/settings-list.js +135 -0
- package/dist/tui/keybindings.d.ts +6 -1
- package/dist/tui/keybindings.js +18 -6
- package/dist/tui.d.ts +1 -0
- package/dist/tui.js +2 -0
- package/docs/en/host-api.md +167 -0
- package/docs/en/permissions.md +214 -0
- package/docs/en/providers.md +625 -0
- package/docs/en/rpc.md +361 -0
- package/docs/en/sessions.md +219 -0
- package/docs/en/tui.md +527 -0
- package/docs/host-api.md +18 -17
- package/docs/memory.md +172 -0
- package/docs/permissions.md +3 -2
- package/docs/providers.md +67 -1
- package/docs/rpc.md +31 -3
- package/docs/session-format.md +8 -2
- package/docs/sessions.md +29 -1
- package/docs/tui.md +189 -21
- package/package.json +8 -3
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 记忆的组装(docs/wave6-plan.md §3、D8、D9、D11、D12)。[W6-M]
|
|
3
|
+
*
|
|
4
|
+
* - 开关:独立终端看合并后的 `memory.enabled`(用户级 / profile.config;项目级只能设 false;`--memory` /
|
|
5
|
+
* `--no-memory`;`AMA_MEMORY=0|1` 经 bootstrap 并入命令行覆盖,命令行优先)。缺省关闭:不建运行期、不读盘、
|
|
6
|
+
* 不注册工具、不渲染节。
|
|
7
|
+
* - 嵌入宿主(有 profile;SDK `createAgentSession`):只看 `profile.memory = { enabled, dir }`,作用域只有
|
|
8
|
+
* `workspace`(= dir),不读用户级;合并配置里显式 `memory.enabled: false`(项目级、`--no-memory`、
|
|
9
|
+
* `AMA_MEMORY=0`)仍可关掉。
|
|
10
|
+
* - 项目作用域要求项目已受信任,否则跳过(`/memory` 提示)。
|
|
11
|
+
* - 系统节:会话开始(新会话)渲染一次;resume / fork 沿用会话里已有的 `memory` 节;压缩结束后重渲染
|
|
12
|
+
* (`compaction_end` 时 `updateSystem`,压缩本就是前缀重置点);`/memory reload` 显式重渲染。
|
|
13
|
+
*/
|
|
14
|
+
import { AmaError } from "../errors.js";
|
|
15
|
+
import { projectRootOf, standaloneRoots } from "../memory/paths.js";
|
|
16
|
+
import { MemoryRuntime } from "../memory/runtime.js";
|
|
17
|
+
import { DEFAULT_MEMORY_LIMITS, MemoryStore } from "../memory/store.js";
|
|
18
|
+
import { replaySystem } from "../session/projection.js";
|
|
19
|
+
/** `AMA_MEMORY=0|1`(也认 true / false / on / off);其它值或未设 → undefined。 */
|
|
20
|
+
export function memoryEnvOverride(env) {
|
|
21
|
+
const raw = env["AMA_MEMORY"]?.trim().toLowerCase();
|
|
22
|
+
if (raw === "1" || raw === "true" || raw === "on")
|
|
23
|
+
return true;
|
|
24
|
+
if (raw === "0" || raw === "false" || raw === "off")
|
|
25
|
+
return false;
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
/** 按配置建运行期;关闭时返回 undefined(什么都不做)。 */
|
|
29
|
+
export function resolveMemory(input) {
|
|
30
|
+
const config = input.config.memory ?? {};
|
|
31
|
+
const limits = {
|
|
32
|
+
indexMaxBytes: config.indexMaxBytes ?? DEFAULT_MEMORY_LIMITS.indexMaxBytes,
|
|
33
|
+
fileMaxBytes: config.fileMaxBytes ?? DEFAULT_MEMORY_LIMITS.fileMaxBytes,
|
|
34
|
+
maxFiles: config.maxFiles ?? DEFAULT_MEMORY_LIMITS.maxFiles,
|
|
35
|
+
};
|
|
36
|
+
const subagents = config.subagents ?? "read";
|
|
37
|
+
const storeOptions = input.today === undefined ? {} : { today: input.today };
|
|
38
|
+
if (input.embedded !== undefined) {
|
|
39
|
+
const profile = input.embedded.memory;
|
|
40
|
+
if (profile?.enabled !== true || config.enabled === false)
|
|
41
|
+
return undefined;
|
|
42
|
+
if (profile.dir === undefined || profile.dir === "")
|
|
43
|
+
throw new AmaError("invalid_arguments", "memory.enabled is true but memory.dir is missing (embedded hosts must give a per-workspace directory)");
|
|
44
|
+
const roots = { workspace: profile.dir };
|
|
45
|
+
return new MemoryRuntime(new MemoryStore(roots, limits, storeOptions), {
|
|
46
|
+
subagents,
|
|
47
|
+
embedded: true,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
if (config.enabled !== true)
|
|
51
|
+
return undefined;
|
|
52
|
+
const scopes = config.scopes ?? ["user", "project"];
|
|
53
|
+
const skipped = [];
|
|
54
|
+
let projectRoot;
|
|
55
|
+
if (scopes.includes("project")) {
|
|
56
|
+
if (input.trusted)
|
|
57
|
+
projectRoot = projectRootOf(input.cwd);
|
|
58
|
+
else
|
|
59
|
+
skipped.push({ scope: "project", reason: "untrusted" });
|
|
60
|
+
}
|
|
61
|
+
const roots = standaloneRoots({
|
|
62
|
+
dataDir: input.dataDir,
|
|
63
|
+
projectRoot,
|
|
64
|
+
user: scopes.includes("user"),
|
|
65
|
+
});
|
|
66
|
+
const store = new MemoryStore(roots, limits, {
|
|
67
|
+
...storeOptions,
|
|
68
|
+
...(projectRoot === undefined ? {} : { projectRoot }),
|
|
69
|
+
});
|
|
70
|
+
return new MemoryRuntime(store, {
|
|
71
|
+
subagents,
|
|
72
|
+
embedded: false,
|
|
73
|
+
skipped,
|
|
74
|
+
...(projectRoot === undefined ? {} : { projectRoot }),
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
const attached = new WeakMap();
|
|
78
|
+
/** 会话的记忆运行期(未开启 → undefined)。 */
|
|
79
|
+
export function memoryOf(session) {
|
|
80
|
+
return attached.get(session);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* 新会话渲染当前索引;会话里已有 system 状态(resume / fork)时沿用其中的 `memory` 节(可能没有)。
|
|
84
|
+
* 未开启 → undefined。
|
|
85
|
+
*/
|
|
86
|
+
export function initialMemorySection(runtime, manager) {
|
|
87
|
+
if (runtime === undefined)
|
|
88
|
+
return undefined;
|
|
89
|
+
const messages = manager
|
|
90
|
+
.branch()
|
|
91
|
+
.flatMap((entry) => (entry.type === "message" ? [entry.message] : []));
|
|
92
|
+
const existing = replaySystem(messages);
|
|
93
|
+
if (existing !== undefined)
|
|
94
|
+
return existing.sections["memory"];
|
|
95
|
+
return runtime.renderSection();
|
|
96
|
+
}
|
|
97
|
+
/** 把 `memory` 节并进静态系统输入(未开启时原样返回同一对象,字节不变)。 */
|
|
98
|
+
export function withMemorySection(system, runtime, manager) {
|
|
99
|
+
const section = initialMemorySection(runtime, manager);
|
|
100
|
+
return section === undefined ? system : { ...system, memory: section };
|
|
101
|
+
}
|
|
102
|
+
/** 会话建好后:登记运行期,压缩结束后重渲染 `memory` 节。 */
|
|
103
|
+
export function attachMemory(session, runtime) {
|
|
104
|
+
if (runtime === undefined)
|
|
105
|
+
return;
|
|
106
|
+
attached.set(session, runtime);
|
|
107
|
+
session.subscribe((event) => {
|
|
108
|
+
if (event.type === "compaction_end" && event.result !== undefined)
|
|
109
|
+
session.updateSystem({ memory: runtime.renderSection() ?? "" });
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* `/memory reload`:按磁盘重渲染 `memory` 节。返回 undefined = 会话未开启记忆;`changed` = 节有变化
|
|
114
|
+
* (下次请求产生一条 system 补丁,缓存前缀断一次)。
|
|
115
|
+
*/
|
|
116
|
+
export function reloadMemorySection(session) {
|
|
117
|
+
const runtime = memoryOf(session);
|
|
118
|
+
if (runtime === undefined)
|
|
119
|
+
return undefined;
|
|
120
|
+
const impl = session;
|
|
121
|
+
const before = impl.childBase().system?.memory;
|
|
122
|
+
const next = runtime.renderSection() ?? "";
|
|
123
|
+
if ((before ?? "") === next)
|
|
124
|
+
return { changed: false };
|
|
125
|
+
impl.updateSystem({ memory: next });
|
|
126
|
+
return { changed: true };
|
|
127
|
+
}
|
|
@@ -9,6 +9,9 @@
|
|
|
9
9
|
* - SDK 追加的供应商(`ProviderData[]`)折成 `config.providers` 条目,走同一条合并路径。
|
|
10
10
|
* - 零配置(设计 §10.0):没有 `defaultModel`、也没有任何需要 key 的供应商配了 key 时,探测本地
|
|
11
11
|
* ollama / lmstudio(短超时),把枚举到的模型加进注册表,供 `pickDefaultModel` 选用。
|
|
12
|
+
* - [W6-O] ChatGPT 登录(docs/wave6-plan.md D14):`chatgpt` 的缺省渠道按 auth.json 条目的 flavor 定(用户写了
|
|
13
|
+
* `defaultChannel` 时不动);`AMA_CHATGPT_BASE_URL` 改该渠道地址;`auth.chatgpt.originator` 改 codex 渠道的
|
|
14
|
+
* `originator` 头;OAuth 刷新拿到 `auth.chatgpt` 配置与同一份 env。
|
|
12
15
|
*/
|
|
13
16
|
import type { ApiRegistry } from "../ai/apis/api.js";
|
|
14
17
|
import { ProviderRegistry } from "../ai/providers/registry.js";
|
|
@@ -32,6 +35,8 @@ export interface ProviderComposeOptions {
|
|
|
32
35
|
}
|
|
33
36
|
export declare function providerConfigOf(provider: ProviderData): ProviderConfig;
|
|
34
37
|
export declare function withExtraProviders(config: AmaConfig, providers: readonly ProviderData[] | undefined): AmaConfig;
|
|
38
|
+
/** [W6-O] 按 auth.json 的 ChatGPT 条目与 `AMA_CHATGPT_BASE_URL` / `auth.chatgpt.originator` 补 chatgpt 的渠道配置。 */
|
|
39
|
+
export declare function withChatGptChannels(config: AmaConfig, authFile: string, env: Readonly<Record<string, string | undefined>>): AmaConfig;
|
|
35
40
|
export declare function buildProviderRegistry(input: ProviderBuildInput, options?: ProviderComposeOptions): Promise<ProviderRegistry>;
|
|
36
41
|
/** 本地服务(无需 key、模型表为空)的模型枚举;连不上静默跳过。 */
|
|
37
42
|
export declare function probeLocalProviders(registry: ProviderRegistry, timeoutMs?: number): Promise<string[]>;
|
|
@@ -9,9 +9,14 @@
|
|
|
9
9
|
* - SDK 追加的供应商(`ProviderData[]`)折成 `config.providers` 条目,走同一条合并路径。
|
|
10
10
|
* - 零配置(设计 §10.0):没有 `defaultModel`、也没有任何需要 key 的供应商配了 key 时,探测本地
|
|
11
11
|
* ollama / lmstudio(短超时),把枚举到的模型加进注册表,供 `pickDefaultModel` 选用。
|
|
12
|
+
* - [W6-O] ChatGPT 登录(docs/wave6-plan.md D14):`chatgpt` 的缺省渠道按 auth.json 条目的 flavor 定(用户写了
|
|
13
|
+
* `defaultChannel` 时不动);`AMA_CHATGPT_BASE_URL` 改该渠道地址;`auth.chatgpt.originator` 改 codex 渠道的
|
|
14
|
+
* `originator` 头;OAuth 刷新拿到 `auth.chatgpt` 配置与同一份 env。
|
|
12
15
|
*/
|
|
13
16
|
import { loadModelsDevIndex } from "../ai/providers/models-dev-cache.js";
|
|
14
17
|
import { ProviderRegistry, discoverLocalModels } from "../ai/providers/registry.js";
|
|
18
|
+
import { readOAuthEntry } from "../auth/oauth/token-store.js";
|
|
19
|
+
import { CHATGPT_BASE_URLS, CHATGPT_PROVIDER_ID } from "../auth/chatgpt/presets.js";
|
|
15
20
|
export const LOCAL_PROBE_TIMEOUT_MS = 300;
|
|
16
21
|
export const NO_LOCAL_PROBE_ENV = "AMA_NO_LOCAL_PROBE";
|
|
17
22
|
/** 模型协议与供应商不同时保留模型级 `api`(同一中转下的模型可走不同协议)。 */
|
|
@@ -44,8 +49,33 @@ export function withExtraProviders(config, providers) {
|
|
|
44
49
|
merged[provider.id] = providerConfigOf(provider);
|
|
45
50
|
return { ...config, providers: merged };
|
|
46
51
|
}
|
|
52
|
+
/** [W6-O] 按 auth.json 的 ChatGPT 条目与 `AMA_CHATGPT_BASE_URL` / `auth.chatgpt.originator` 补 chatgpt 的渠道配置。 */
|
|
53
|
+
export function withChatGptChannels(config, authFile, env) {
|
|
54
|
+
const entry = readOAuthEntry(authFile, CHATGPT_PROVIDER_ID);
|
|
55
|
+
const baseUrl = env["AMA_CHATGPT_BASE_URL"]?.trim();
|
|
56
|
+
const originator = config.auth?.chatgpt?.originator?.trim();
|
|
57
|
+
if (entry === undefined && !baseUrl && !originator)
|
|
58
|
+
return config;
|
|
59
|
+
const current = { ...(config.providers?.[CHATGPT_PROVIDER_ID] ?? {}) };
|
|
60
|
+
if (current.defaultChannel === undefined && entry !== undefined)
|
|
61
|
+
current.defaultChannel = entry.flavor;
|
|
62
|
+
const channels = { ...(current.channels ?? {}) };
|
|
63
|
+
const channel = (name) => (channels[name] ??= { api: "openai-responses", baseUrl: CHATGPT_BASE_URLS[name] });
|
|
64
|
+
if (baseUrl) {
|
|
65
|
+
const name = current.defaultChannel === "codex" ? "codex" : "siwc";
|
|
66
|
+
channels[name] = { ...channel(name), baseUrl };
|
|
67
|
+
}
|
|
68
|
+
if (originator) {
|
|
69
|
+
const codex = channel("codex");
|
|
70
|
+
channels.codex = { ...codex, headers: { ...codex.headers, originator } };
|
|
71
|
+
}
|
|
72
|
+
if (Object.keys(channels).length > 0)
|
|
73
|
+
current.channels = channels;
|
|
74
|
+
return { ...config, providers: { ...(config.providers ?? {}), [CHATGPT_PROVIDER_ID]: current } };
|
|
75
|
+
}
|
|
47
76
|
export async function buildProviderRegistry(input, options = {}) {
|
|
48
|
-
const
|
|
77
|
+
const env = options.env ?? process.env;
|
|
78
|
+
const config = withChatGptChannels(withExtraProviders(input.config, options.providers), input.authFile, input.authEnv ? env : {});
|
|
49
79
|
const dataDir = input.dataDir;
|
|
50
80
|
const make = (cliApiKey) => new ProviderRegistry({
|
|
51
81
|
config,
|
|
@@ -57,6 +87,7 @@ export async function buildProviderRegistry(input, options = {}) {
|
|
|
57
87
|
userAuthFile: null,
|
|
58
88
|
useEnv: input.authEnv,
|
|
59
89
|
env: options.env,
|
|
90
|
+
oauth: { env: input.authEnv ? env : {}, config: config.auth?.chatgpt },
|
|
60
91
|
},
|
|
61
92
|
onWarning: options.warn,
|
|
62
93
|
...(dataDir !== undefined ? { modelsDev: () => loadModelsDevIndex(dataDir) } : {}),
|
|
@@ -73,7 +104,6 @@ export async function buildProviderRegistry(input, options = {}) {
|
|
|
73
104
|
if (provider !== undefined)
|
|
74
105
|
registry = make({ provider, apiKey: cli.apiKey });
|
|
75
106
|
}
|
|
76
|
-
const env = options.env ?? process.env;
|
|
77
107
|
const probe = options.probeLocal ?? env[NO_LOCAL_PROBE_ENV] !== "1";
|
|
78
108
|
if (probe && config.defaultModel === undefined && !anyKeyConfigured(registry)) {
|
|
79
109
|
await probeLocalProviders(registry, options.probeTimeoutMs ?? LOCAL_PROBE_TIMEOUT_MS);
|
|
@@ -23,6 +23,7 @@ import { type AmaConfig } from "../config/types.js";
|
|
|
23
23
|
import type { AgentEventBus } from "../host/api-impl.js";
|
|
24
24
|
import type { Skill } from "../skills/discover.js";
|
|
25
25
|
import { type PromptTemplate } from "../skills/templates.js";
|
|
26
|
+
import type { MemoryRuntime } from "../memory/runtime.js";
|
|
26
27
|
import type { SessionAssembly } from "./deps.js";
|
|
27
28
|
import type { Runtime } from "./runtime.js";
|
|
28
29
|
/** createRuntimeDeps 闭包里跨步骤共享的状态。 */
|
|
@@ -38,6 +39,8 @@ export interface ComposeState {
|
|
|
38
39
|
providers?: ProviderRegistryApi;
|
|
39
40
|
/** [S2] tools.create 算出的 bash 沙箱设定,permissions.create 用同一份。 */
|
|
40
41
|
bashSandbox?: BashSandbox;
|
|
42
|
+
/** [W6-M] tools.create 收到的记忆运行期(未开启为 undefined)。 */
|
|
43
|
+
memory?: MemoryRuntime | undefined;
|
|
41
44
|
}
|
|
42
45
|
export declare function emptyComposeState(): ComposeState;
|
|
43
46
|
export type LogFn = (level: "debug" | "info" | "warn" | "error", message: string) => void;
|
|
@@ -48,6 +51,8 @@ export interface SessionComposeOptions {
|
|
|
48
51
|
}
|
|
49
52
|
/** `AMA_LOG=debug|info|warn|error`(缺省 warn)过滤后写 stderr。 */
|
|
50
53
|
export declare function stderrLog(env?: NodeJS.ProcessEnv): LogFn;
|
|
54
|
+
/** [W6-S] D22:回复语言规则(发给模型,固定英文)。 */
|
|
55
|
+
export declare function replyLanguageRule(language: string): string;
|
|
51
56
|
/** config `cache` 段 + 环境变量 → 会话缓存设置;非法的环境变量值忽略并 warning。 */
|
|
52
57
|
export declare function cacheSettingsFrom(config: Pick<AmaConfig, "cache">, env?: NodeJS.ProcessEnv, warn?: (message: string) => void): Partial<CacheSettings>;
|
|
53
58
|
/**
|
|
@@ -34,7 +34,9 @@ import { expandPromptCommand } from "../skills/templates.js";
|
|
|
34
34
|
import { PresetToolRegistry } from "../tools/presets.js";
|
|
35
35
|
import { openSession } from "./compose-store.js";
|
|
36
36
|
import { composeExtensions } from "./compose-extensions.js";
|
|
37
|
+
import { attachMemory, withMemorySection } from "./compose-memory.js";
|
|
37
38
|
import { ExitCode } from "./exit-codes.js";
|
|
39
|
+
import { msg } from "../i18n/index.js";
|
|
38
40
|
export function emptyComposeState() {
|
|
39
41
|
return { skills: [], templates: [], warnings: [], session: undefined };
|
|
40
42
|
}
|
|
@@ -66,7 +68,7 @@ function sourceText(source, cache, log) {
|
|
|
66
68
|
text = readFileSync(source.path, "utf8");
|
|
67
69
|
}
|
|
68
70
|
catch (error) {
|
|
69
|
-
log("warn",
|
|
71
|
+
log("warn", msg().cli.composeSession.instructionsReadFailed(source.path, error.message));
|
|
70
72
|
}
|
|
71
73
|
cache.set(source.path, text);
|
|
72
74
|
return text;
|
|
@@ -85,6 +87,10 @@ function contextFiles(record) {
|
|
|
85
87
|
}));
|
|
86
88
|
return [...resources.contextFiles, ...extra.filter((f) => f.content.trim() !== "")];
|
|
87
89
|
}
|
|
90
|
+
/** [W6-S] D22:回复语言规则(发给模型,固定英文)。 */
|
|
91
|
+
export function replyLanguageRule(language) {
|
|
92
|
+
return `Reply to the user in ${language}.`;
|
|
93
|
+
}
|
|
88
94
|
function systemInput(record, active) {
|
|
89
95
|
const system = { contextFiles: contextFiles(record) };
|
|
90
96
|
const override = record.assembly.overrides?.systemPrompt;
|
|
@@ -92,6 +98,10 @@ function systemInput(record, active) {
|
|
|
92
98
|
system.preamble = override.text;
|
|
93
99
|
else if (override !== undefined)
|
|
94
100
|
system.extraRules = [override.text];
|
|
101
|
+
// [W6-S] D22 ui.replyLanguage:会话开始在 rules 节末尾追加一句英文规则;不设时零字节变化
|
|
102
|
+
const reply = record.assembly.config.ui?.replyLanguage?.trim();
|
|
103
|
+
if (reply)
|
|
104
|
+
system.extraRules = [...(system.extraRules ?? []), replyLanguageRule(reply)];
|
|
95
105
|
const index = formatSkillIndex(record.state.skills, {
|
|
96
106
|
hasSkillTool: false,
|
|
97
107
|
hasReadTool: active.includes("read"),
|
|
@@ -122,8 +132,7 @@ async function expandPrompt(record, session, text) {
|
|
|
122
132
|
refreshSystem(record, session);
|
|
123
133
|
const skill = await expandSkillCommand(text, record.state.skills);
|
|
124
134
|
if (skill?.kind === "unknown") {
|
|
125
|
-
|
|
126
|
-
throw new AmaError("skill_not_found", `未知 Skill:${skill.name}${hint}`);
|
|
135
|
+
throw new AmaError("skill_not_found", msg().cli.composeSession.unknownSkill(skill.name, skill.available));
|
|
127
136
|
}
|
|
128
137
|
if (skill?.kind === "expanded")
|
|
129
138
|
return { text: skill.text };
|
|
@@ -142,7 +151,7 @@ export function cacheSettingsFrom(config, env = process.env, warn = () => undefi
|
|
|
142
151
|
if (WARMING_MODES.includes(warming))
|
|
143
152
|
settings.warming = warming;
|
|
144
153
|
else
|
|
145
|
-
warn(
|
|
154
|
+
warn(msg().cli.composeSession.invalidCacheWarming(warming));
|
|
146
155
|
}
|
|
147
156
|
const retention = env["AMA_CACHE_RETENTION"];
|
|
148
157
|
if (retention !== undefined && retention !== "") {
|
|
@@ -150,7 +159,7 @@ export function cacheSettingsFrom(config, env = process.env, warn = () => undefi
|
|
|
150
159
|
if (CACHE_RETENTIONS.includes(value))
|
|
151
160
|
settings.retention = value;
|
|
152
161
|
else
|
|
153
|
-
warn(
|
|
162
|
+
warn(msg().cli.composeSession.invalidCacheRetention(retention));
|
|
154
163
|
}
|
|
155
164
|
return settings;
|
|
156
165
|
}
|
|
@@ -164,7 +173,7 @@ export function idleTimeoutFrom(config, env = process.env, warn = () => undefine
|
|
|
164
173
|
const value = Number(raw);
|
|
165
174
|
if (Number.isFinite(value) && value >= 0)
|
|
166
175
|
return value;
|
|
167
|
-
warn(
|
|
176
|
+
warn(msg().cli.composeSession.invalidIdleTimeout(raw));
|
|
168
177
|
}
|
|
169
178
|
return config.request?.idleTimeoutMs;
|
|
170
179
|
}
|
|
@@ -229,6 +238,11 @@ export function bridgeEvent(event, bus) {
|
|
|
229
238
|
void bus.emit("context_pressure", pressure);
|
|
230
239
|
return;
|
|
231
240
|
}
|
|
241
|
+
case "quota_update": {
|
|
242
|
+
const { type: _type, ...quota } = event;
|
|
243
|
+
void bus.emit("quota_update", quota);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
232
246
|
// [W5-C0] 子 Agent 与计划事件
|
|
233
247
|
case "subagent_start": {
|
|
234
248
|
const { type: _type, ...payload } = event;
|
|
@@ -276,7 +290,7 @@ function buildSession(record, manager, model, thinkingLevel) {
|
|
|
276
290
|
unattended: assembly.unattended,
|
|
277
291
|
approvalTimeoutMs: approvalTimeout(record.options),
|
|
278
292
|
hooks: assembly.hooks,
|
|
279
|
-
system: systemInput(record, active),
|
|
293
|
+
system: withMemorySection(systemInput(record, active), record.state.memory, manager),
|
|
280
294
|
compaction: { ...config.compaction },
|
|
281
295
|
retry: { ...config.retry },
|
|
282
296
|
expandPrompt: (text) => expandPrompt(record, session, text),
|
|
@@ -320,6 +334,7 @@ function buildSession(record, manager, model, thinkingLevel) {
|
|
|
320
334
|
sessionsRoot: assembly.paths.sessionDir,
|
|
321
335
|
});
|
|
322
336
|
session = new AgentSessionImpl(options);
|
|
337
|
+
attachMemory(session, record.state.memory);
|
|
323
338
|
session.subscribe((event) => bridgeEvent(event, assembly.events));
|
|
324
339
|
records.set(session, record);
|
|
325
340
|
record.state.session = session;
|
|
@@ -329,12 +344,11 @@ function buildSession(record, manager, model, thinkingLevel) {
|
|
|
329
344
|
export function composeSession(assembly, state = emptyComposeState(), options = {}) {
|
|
330
345
|
const manager = assembly.sessionManager;
|
|
331
346
|
if (!(manager instanceof SessionManager)) {
|
|
332
|
-
throw new AmaError("invalid_arguments",
|
|
347
|
+
throw new AmaError("invalid_arguments", msg().cli.composeSession.notSessionManager);
|
|
333
348
|
}
|
|
334
349
|
const { model } = assembly;
|
|
335
350
|
if (assembly.providers.getApi(model.api) === undefined) {
|
|
336
|
-
|
|
337
|
-
throw new StartupError("provider_not_found", `模型 ${model.provider}/${model.id} 的协议 ${model.api} 尚未实现${via}`, ExitCode.NoModel);
|
|
351
|
+
throw new StartupError("provider_not_found", msg().cli.composeSession.apiNotImplemented(`${model.provider}/${model.id}`, model.api, model.api === "google-generative-ai"), ExitCode.NoModel);
|
|
338
352
|
}
|
|
339
353
|
for (const warning of state.warnings.splice(0))
|
|
340
354
|
assembly.warn(warning);
|
|
@@ -366,7 +380,7 @@ export function composeSession(assembly, state = emptyComposeState(), options =
|
|
|
366
380
|
record.current.addTool(tool, active);
|
|
367
381
|
}
|
|
368
382
|
catch (error) {
|
|
369
|
-
record.log("warn",
|
|
383
|
+
record.log("warn", msg().cli.composeSession.appendToolFailed(tool.name, error.message));
|
|
370
384
|
}
|
|
371
385
|
});
|
|
372
386
|
}
|
|
@@ -390,10 +404,10 @@ export function currentSession(target) {
|
|
|
390
404
|
export async function switchSession(target, request) {
|
|
391
405
|
const record = recordOf(target);
|
|
392
406
|
if (record === undefined)
|
|
393
|
-
throw new AmaError("not_implemented",
|
|
407
|
+
throw new AmaError("not_implemented", msg().cli.composeSession.notComposed);
|
|
394
408
|
const old = record.current;
|
|
395
409
|
if (old.state.isStreaming)
|
|
396
|
-
throw new AmaError("busy",
|
|
410
|
+
throw new AmaError("busy", msg().cli.composeSession.switchWhileStreaming);
|
|
397
411
|
const { assembly } = record;
|
|
398
412
|
const sessionDir = assembly.paths.sessionDir;
|
|
399
413
|
let manager;
|
|
@@ -17,8 +17,10 @@ export declare function openSession(request: SessionRequest, context: {
|
|
|
17
17
|
sessionDir: string;
|
|
18
18
|
cwd: string;
|
|
19
19
|
}): SessionManager;
|
|
20
|
+
/** 列会话(最新在前);子 Agent 会话缺省跳过,`includeSubagents` 时保留(带 `subagent` 标记)。 */
|
|
20
21
|
export declare function listSessions(context: {
|
|
21
22
|
sessionDir: string;
|
|
22
23
|
cwd?: string;
|
|
24
|
+
includeSubagents?: boolean;
|
|
23
25
|
}): SessionListItem[];
|
|
24
26
|
export declare function createSessionStore(): RuntimeDeps["sessions"];
|
|
@@ -14,6 +14,7 @@ import { AmaError } from "../errors.js";
|
|
|
14
14
|
import { SessionManager } from "../session/manager.js";
|
|
15
15
|
import { migrateSessionLines } from "../session/migrate.js";
|
|
16
16
|
import { TRASH_DIR_NAME, listSessionFiles, purgeTrash, readSessionLines, sessionDirForCwd, sessionIdFromFileName, trashSession, } from "../session/store.js";
|
|
17
|
+
import { msg } from "../i18n/index.js";
|
|
17
18
|
/** 根目录下全部 cwd 子目录(不含 trash)。 */
|
|
18
19
|
function cwdDirs(root) {
|
|
19
20
|
if (!existsSync(root))
|
|
@@ -49,7 +50,7 @@ export function findSessionFile(root, id, cwd) {
|
|
|
49
50
|
}
|
|
50
51
|
if (prefix.length > 1) {
|
|
51
52
|
const ids = prefix.map((f) => sessionIdFromFileName(f) ?? f).slice(0, 10);
|
|
52
|
-
throw new AmaError("invalid_arguments",
|
|
53
|
+
throw new AmaError("invalid_arguments", msg().cli.composeStore.ambiguousId(id, ids), {
|
|
53
54
|
exitCode: 5,
|
|
54
55
|
});
|
|
55
56
|
}
|
|
@@ -58,7 +59,7 @@ export function findSessionFile(root, id, cwd) {
|
|
|
58
59
|
function requireFile(root, id, cwd) {
|
|
59
60
|
const file = findSessionFile(root, id, cwd);
|
|
60
61
|
if (file === undefined)
|
|
61
|
-
throw new AmaError("session_not_found",
|
|
62
|
+
throw new AmaError("session_not_found", msg().cli.composeStore.sessionNotFound(id));
|
|
62
63
|
return file;
|
|
63
64
|
}
|
|
64
65
|
export function openSession(request, context) {
|
|
@@ -84,7 +85,7 @@ export function openSession(request, context) {
|
|
|
84
85
|
try {
|
|
85
86
|
const leaf = source.leafId();
|
|
86
87
|
if (leaf === null)
|
|
87
|
-
throw new AmaError("session_corrupt",
|
|
88
|
+
throw new AmaError("session_corrupt", msg().cli.composeStore.noEntries(request.id));
|
|
88
89
|
return source.fork(leaf);
|
|
89
90
|
}
|
|
90
91
|
finally {
|
|
@@ -93,12 +94,14 @@ export function openSession(request, context) {
|
|
|
93
94
|
}
|
|
94
95
|
}
|
|
95
96
|
}
|
|
97
|
+
/** 列会话(最新在前);子 Agent 会话缺省跳过,`includeSubagents` 时保留(带 `subagent` 标记)。 */
|
|
96
98
|
export function listSessions(context) {
|
|
97
99
|
const dirs = context.cwd === undefined
|
|
98
100
|
? cwdDirs(context.sessionDir)
|
|
99
101
|
: [sessionDirForCwd(context.sessionDir, context.cwd)];
|
|
100
102
|
return dirs
|
|
101
103
|
.flatMap((dir) => SessionManager.list(dir))
|
|
104
|
+
.filter((item) => context.includeSubagents === true || item.subagent !== true)
|
|
102
105
|
.sort((a, b) => b.modifiedAt.localeCompare(a.modifiedAt));
|
|
103
106
|
}
|
|
104
107
|
export function createSessionStore() {
|
|
@@ -109,13 +112,14 @@ export function createSessionStore() {
|
|
|
109
112
|
const file = requireFile(context.sessionDir, id);
|
|
110
113
|
const item = SessionManager.list(join(file, "..")).find((i) => i.file === file);
|
|
111
114
|
if (item === undefined)
|
|
112
|
-
throw new AmaError("session_corrupt",
|
|
115
|
+
throw new AmaError("session_corrupt", msg().cli.composeStore.unreadable(file));
|
|
113
116
|
const { entries } = migrateSessionLines(readSessionLines(file).lines, file);
|
|
114
117
|
return { item, entries };
|
|
115
118
|
},
|
|
116
119
|
prune: async (context) => {
|
|
117
120
|
const cutoff = Date.now() - context.olderThanDays * 24 * 60 * 60 * 1000;
|
|
118
|
-
|
|
121
|
+
// 子 Agent 会话一样按时间清理
|
|
122
|
+
const old = listSessions({ ...context, includeSubagents: true }).filter((i) => Date.parse(i.modifiedAt) < cutoff);
|
|
119
123
|
if (context.dryRun)
|
|
120
124
|
return { moved: old.map((i) => i.file) };
|
|
121
125
|
for (const item of old)
|
package/dist/cli/compose.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ import type { Rule } from "../permissions/types.js";
|
|
|
30
30
|
import { type SandboxCapability } from "../codemode/capability.js";
|
|
31
31
|
import { type BashSandbox } from "../sandbox/bash.js";
|
|
32
32
|
import { PresetToolRegistry } from "../tools/presets.js";
|
|
33
|
+
import type { MemoryRuntime } from "../memory/runtime.js";
|
|
33
34
|
import type { ToolDefinition, ToolRegistryApi } from "../tools/types.js";
|
|
34
35
|
import { type ComposeState, type LogFn } from "./compose-session.js";
|
|
35
36
|
import type { CliIo, InteractiveUi, ModeRunner, RuntimeDeps } from "./deps.js";
|
|
@@ -94,6 +95,7 @@ export declare function createTools(input: {
|
|
|
94
95
|
configDir: string;
|
|
95
96
|
dataDir: string;
|
|
96
97
|
} | undefined;
|
|
98
|
+
memory?: MemoryRuntime | undefined;
|
|
97
99
|
}, options: ComposeOptions, state: ComposeState): PresetToolRegistry;
|
|
98
100
|
/** 当前模型是否收图片(read 工具用);查不到模型时按收(交给协议层过滤)。 */
|
|
99
101
|
export declare function modelAcceptsImages(state: ComposeState, model: ModelRef | undefined): boolean;
|
package/dist/cli/compose.js
CHANGED
|
@@ -37,12 +37,14 @@ import { join } from "node:path";
|
|
|
37
37
|
import { AUTH_FILE } from "../config/paths.js";
|
|
38
38
|
import { PresetToolRegistry, resolvePreset } from "../tools/presets.js";
|
|
39
39
|
import { builtinTools } from "../tools/registry.js";
|
|
40
|
+
import { MEMORY_TOOL, createMemoryTool } from "../memory/tool.js";
|
|
40
41
|
import { takeCodemodeNotice } from "./codemode-notice.js";
|
|
41
42
|
import { buildProviderRegistry } from "./compose-providers.js";
|
|
42
43
|
import { composeSession, emptyComposeState, } from "./compose-session.js";
|
|
43
44
|
import { createSessionStore } from "./compose-store.js";
|
|
44
45
|
import { defaultSendUser } from "./startup-steps.js";
|
|
45
46
|
import { imageFitOptionsFor } from "../modes/image-input.js";
|
|
47
|
+
import { msg } from "../i18n/index.js";
|
|
46
48
|
/** 缺省工具工厂:codemode(生效模式为 off 时不注册;缺省跟随预设,见 tools/presets.ts)。 */
|
|
47
49
|
export const DEFAULT_TOOL_FACTORIES = [codemodeToolFactory()];
|
|
48
50
|
export function lazyMode(load) {
|
|
@@ -105,9 +107,13 @@ export function createTools(input, options, state) {
|
|
|
105
107
|
produced.push(tool);
|
|
106
108
|
}
|
|
107
109
|
catch (error) {
|
|
108
|
-
state.warnings.push(
|
|
110
|
+
state.warnings.push(msg().cli.compose.toolFactoryFailed(error.message));
|
|
109
111
|
}
|
|
110
112
|
}
|
|
113
|
+
// [W6-M] 记忆开启时注册 memory 工具并放进活动集(关闭时什么都不加,工具表字节不变)
|
|
114
|
+
if (input.memory !== undefined)
|
|
115
|
+
produced.push(createMemoryTool(input.memory));
|
|
116
|
+
state.memory = input.memory;
|
|
111
117
|
const extra = options.extraTools ?? [];
|
|
112
118
|
const names = new Set([...builtins, ...produced, ...extra].map((tool) => tool.name));
|
|
113
119
|
const preset = resolvePreset({
|
|
@@ -120,13 +126,15 @@ export function createTools(input, options, state) {
|
|
|
120
126
|
registry.register(tool, "builtin");
|
|
121
127
|
}
|
|
122
128
|
catch (error) {
|
|
123
|
-
state.warnings.push(
|
|
129
|
+
state.warnings.push(msg().cli.compose.toolRegisterFailed(tool.name, error.message));
|
|
124
130
|
}
|
|
125
131
|
}
|
|
126
132
|
for (const tool of extra)
|
|
127
133
|
registry.register(tool, "sdk");
|
|
134
|
+
if (input.memory !== undefined && preset.codemode !== "only")
|
|
135
|
+
preset.builtin.push(MEMORY_TOOL);
|
|
128
136
|
applyCodemodeMode(registry, preset);
|
|
129
|
-
state.warnings.push(...preset.warnings);
|
|
137
|
+
state.warnings.push(...preset.warnings.map((w) => msg().session.codemode.presetWarning(w)));
|
|
130
138
|
// 一次性提示只给有人看的界面(交互 / 行式);-p 与 RPC 的 stderr 常被脚本解析,不打扰。
|
|
131
139
|
if (input.paths !== undefined && (input.mode === "interactive" || input.mode === "line")) {
|
|
132
140
|
const notice = takeCodemodeNotice({ config: input.config, capability, ...input.paths });
|
|
@@ -157,7 +165,7 @@ export function buildRules(specs, builtinDeny, warn) {
|
|
|
157
165
|
rules.push(parseRule(spec.raw, spec.effect, spec.source));
|
|
158
166
|
}
|
|
159
167
|
catch (error) {
|
|
160
|
-
warn(
|
|
168
|
+
warn(msg().cli.compose.permissionRuleIgnored(spec.source, error.message));
|
|
161
169
|
}
|
|
162
170
|
}
|
|
163
171
|
return rules;
|
|
@@ -238,7 +246,7 @@ export function createRuntimeDeps(options = {}) {
|
|
|
238
246
|
const skipped = [...new Set([...skills.skippedUntrusted, ...prompts.skippedUntrusted])];
|
|
239
247
|
const warnings = [...skills.warnings, ...prompts.warnings];
|
|
240
248
|
if (skipped.length > 0)
|
|
241
|
-
warnings.push(
|
|
249
|
+
warnings.push(msg().cli.compose.untrustedDirsSkipped(skipped.length));
|
|
242
250
|
return {
|
|
243
251
|
skills: skills.skills.map((s) => ({
|
|
244
252
|
name: s.name,
|
|
@@ -27,8 +27,6 @@ export interface PricePick {
|
|
|
27
27
|
/** 为什么选它(一句话)。 */
|
|
28
28
|
reason: string;
|
|
29
29
|
}
|
|
30
|
-
/** 规则说明(帮助与输出共用)。 */
|
|
31
|
-
export declare const PRICE_RULE = "\u652F\u6301\u5DE5\u5177\u8C03\u7528\u3001\u4E0A\u4E0B\u6587 \u2265 64k \u4E14\u6709\u4EF7\u683C\u7684\u6A21\u578B\u91CC\u8F93\u5165\u4EF7\u6700\u4F4E";
|
|
32
30
|
/** 按价格挑缺省模型;没有满足条件的返回 undefined(规则见文件头)。 */
|
|
33
31
|
export declare function pickByPrice(candidates: readonly PriceCandidate[]): PricePick | undefined;
|
|
34
32
|
export interface DefaultModelChoice {
|
|
@@ -12,10 +12,9 @@
|
|
|
12
12
|
* 无 key 时探测)。跳过 `fake`(测试供应商只能显式 `--model fake/…`)与协议尚未实现的供应商。
|
|
13
13
|
*/
|
|
14
14
|
import { compactTokens, metadataOf } from "./subcommands/model-meta.js";
|
|
15
|
+
import { msg } from "../i18n/index.js";
|
|
15
16
|
/** 缺省模型的最小上下文(token)。 */
|
|
16
17
|
export const MIN_DEFAULT_CONTEXT = 64_000;
|
|
17
|
-
/** 规则说明(帮助与输出共用)。 */
|
|
18
|
-
export const PRICE_RULE = "支持工具调用、上下文 ≥ 64k 且有价格的模型里输入价最低";
|
|
19
18
|
/** 按价格挑缺省模型;没有满足条件的返回 undefined(规则见文件头)。 */
|
|
20
19
|
export function pickByPrice(candidates) {
|
|
21
20
|
let best;
|
|
@@ -41,7 +40,7 @@ export function pickByPrice(candidates) {
|
|
|
41
40
|
const { c } = best;
|
|
42
41
|
return {
|
|
43
42
|
id: c.id,
|
|
44
|
-
reason:
|
|
43
|
+
reason: msg().cli.defaultModel.priceReason(c.inputCost, compactTokens(c.contextWindow)),
|
|
45
44
|
};
|
|
46
45
|
}
|
|
47
46
|
/** 供应商内挑模型:内置取目录首条;自定义按价格规则,挑不出再取首条。 */
|
|
@@ -51,7 +50,7 @@ export function pickProviderModel(registry, provider) {
|
|
|
51
50
|
if (first === undefined)
|
|
52
51
|
return undefined;
|
|
53
52
|
if (provider.builtin)
|
|
54
|
-
return { model: first, rule:
|
|
53
|
+
return { model: first, rule: msg().cli.defaultModel.builtinFirst };
|
|
55
54
|
const picked = pickByPrice(usable.map((m) => ({
|
|
56
55
|
id: m.id,
|
|
57
56
|
contextWindow: m.contextWindow,
|
|
@@ -63,7 +62,7 @@ export function pickProviderModel(registry, provider) {
|
|
|
63
62
|
return { model, rule: picked.reason };
|
|
64
63
|
return {
|
|
65
64
|
model: first,
|
|
66
|
-
rule:
|
|
65
|
+
rule: msg().cli.defaultModel.listFirst,
|
|
67
66
|
};
|
|
68
67
|
}
|
|
69
68
|
export async function pickDefaultModel(registry) {
|
|
@@ -105,7 +104,5 @@ export function noModelGuidance(registry) {
|
|
|
105
104
|
.map((p) => p.envKeys[0])
|
|
106
105
|
.filter((name) => name !== undefined);
|
|
107
106
|
const shown = envs.slice(0, 3).join(" / ");
|
|
108
|
-
|
|
109
|
-
return (`没有可用模型:设置 ${shown}${more}环境变量,或 \`ama auth set <provider>\` 保存 key,` +
|
|
110
|
-
"或 `ama providers add <id> --base-url <url>` 接入中转站(也可 --model 指定)");
|
|
107
|
+
return msg().cli.defaultModel.noModel(shown, envs.length > 3);
|
|
111
108
|
}
|
package/dist/cli/deps.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ import type { AmaConfig } from "../config/types.js";
|
|
|
15
15
|
import type { PermissionRuleSpec } from "../config/merge.js";
|
|
16
16
|
import type { TrustPromptAnswer } from "../config/trust.js";
|
|
17
17
|
import type { HookDispatcherApi } from "../hooks/types.js";
|
|
18
|
+
import type { MemoryRuntime } from "../memory/runtime.js";
|
|
18
19
|
import type { WarmingDecisionHandler } from "../ai/cache/types.js";
|
|
19
20
|
import type { AgentEventBus } from "../host/api-impl.js";
|
|
20
21
|
import type { ApprovalBroker, HostAdapterHandle, InstructionSource } from "../host/types.js";
|
|
@@ -162,10 +163,11 @@ export interface RuntimeDeps {
|
|
|
162
163
|
sessionDir: string;
|
|
163
164
|
cwd: string;
|
|
164
165
|
}): SessionManagerApi | Promise<SessionManagerApi>;
|
|
165
|
-
/** `--resume` 选择器与 `ama sessions`
|
|
166
|
+
/** `--resume` 选择器与 `ama sessions` 用;子 Agent 会话缺省不列,`includeSubagents` 时列出。 */
|
|
166
167
|
list?(context: {
|
|
167
168
|
sessionDir: string;
|
|
168
169
|
cwd?: string;
|
|
170
|
+
includeSubagents?: boolean;
|
|
169
171
|
}): Promise<SessionListItem[]>;
|
|
170
172
|
/** `ama sessions show`:id 可为前缀;找不到抛 AmaError{code:"session_not_found"}。 */
|
|
171
173
|
show?(id: string, context: {
|
|
@@ -195,6 +197,8 @@ export interface RuntimeDeps {
|
|
|
195
197
|
configDir: string;
|
|
196
198
|
dataDir: string;
|
|
197
199
|
};
|
|
200
|
+
/** [W6-M] 记忆运行期(开启时注册 memory 工具;组装会话时渲染 memory 节)。 */
|
|
201
|
+
memory?: MemoryRuntime | undefined;
|
|
198
202
|
}): ToolRegistryApi;
|
|
199
203
|
};
|
|
200
204
|
/** B3:权限管线。 */
|
package/dist/cli/exit-codes.d.ts
CHANGED
|
@@ -37,5 +37,5 @@ export declare const ExitCode: {
|
|
|
37
37
|
};
|
|
38
38
|
export type ExitCodeName = keyof typeof ExitCode;
|
|
39
39
|
export type ExitCode = (typeof ExitCode)[ExitCodeName];
|
|
40
|
-
|
|
40
|
+
/** [W6-I1] 退出码说明按界面语言取(`msg().cli.exitCodes`,键是 `ExitCode` 名字的 camelCase)。 */
|
|
41
41
|
export declare function describeExitCode(code: number): string;
|