@armadra/agent 0.7.6 → 0.8.1
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 +51 -31
- package/CHANGELOG.zh-CN.md +68 -48
- package/README.md +162 -204
- package/README.zh-CN.md +150 -199
- package/dist/acp.d.ts +1 -1
- package/dist/acp.js +1 -1
- package/dist/agent/limits.d.ts +1 -1
- package/dist/agent/limits.js +1 -1
- package/dist/agent/loop-guard.d.ts +1 -1
- package/dist/agent/loop-guard.js +1 -1
- package/dist/agent/prompt-rules.d.ts +1 -1
- package/dist/agent/prompt-rules.js +1 -1
- package/dist/agent/reminders.d.ts +1 -1
- package/dist/agent/reminders.js +1 -1
- package/dist/agent/session-cache-key.d.ts +1 -1
- package/dist/agent/session-cache-key.js +1 -1
- package/dist/agent/session-extensions.d.ts +1 -1
- package/dist/agent/session-extensions.js +1 -1
- package/dist/agent/session-images.d.ts +1 -1
- package/dist/agent/session-images.js +1 -1
- package/dist/agent/session-plan.d.ts +1 -1
- package/dist/agent/session-plan.js +1 -1
- package/dist/agent/session-rewind.d.ts +1 -1
- package/dist/agent/session-rewind.js +1 -1
- package/dist/agent/session-settings.d.ts +1 -1
- package/dist/agent/session-settings.js +1 -1
- package/dist/agent/session-subagent.d.ts +1 -1
- package/dist/agent/session-subagent.js +1 -1
- package/dist/agent/session-telemetry.d.ts +1 -1
- package/dist/agent/session-telemetry.js +1 -1
- package/dist/agent/session-trace-writer.d.ts +1 -1
- package/dist/agent/session-trace-writer.js +1 -1
- package/dist/agent/session.js +1 -1
- package/dist/agent/subagent-background.d.ts +1 -1
- package/dist/agent/subagent-background.js +1 -1
- package/dist/agent/subagent-direct.d.ts +1 -1
- package/dist/agent/subagent-direct.js +1 -1
- package/dist/agent/subagent-fork.d.ts +1 -1
- package/dist/agent/subagent-fork.js +1 -1
- package/dist/agent/subagent-registry.d.ts +1 -1
- package/dist/agent/subagent-registry.js +1 -1
- package/dist/agent/system-prompt.js +1 -1
- package/dist/agent/tool-availability.d.ts +1 -1
- package/dist/agent/tool-availability.js +1 -1
- package/dist/agent/types-w5.d.ts +2 -2
- package/dist/agent/types-w5.js +1 -1
- package/dist/agent/types-w6.d.ts +1 -1
- package/dist/agent/types-w6.js +1 -1
- package/dist/agent/types.d.ts +1 -1
- package/dist/agent/worktree.d.ts +1 -1
- package/dist/agent/worktree.js +1 -1
- package/dist/agents/builtin.d.ts +1 -1
- package/dist/agents/builtin.js +1 -1
- package/dist/agents/catalog.d.ts +1 -1
- package/dist/agents/catalog.js +1 -1
- package/dist/agents/discover.d.ts +1 -1
- package/dist/agents/discover.js +1 -1
- package/dist/agents/external.d.ts +1 -1
- package/dist/agents/external.js +1 -1
- package/dist/agents/parse.d.ts +1 -1
- package/dist/agents/parse.js +1 -1
- package/dist/agents/result.d.ts +1 -1
- package/dist/agents/result.js +2 -2
- package/dist/agents/task-record.d.ts +3 -3
- package/dist/agents/task-record.js +2 -2
- package/dist/agents/types.d.ts +1 -1
- package/dist/agents/types.js +1 -1
- package/dist/ai/apis/anthropic-compat.d.ts +2 -2
- package/dist/ai/apis/anthropic-compat.js +2 -2
- package/dist/ai/apis/cache-params.d.ts +1 -1
- package/dist/ai/apis/cache-params.js +1 -1
- package/dist/ai/apis/chatgpt-backend.d.ts +4 -2
- package/dist/ai/apis/chatgpt-backend.js +11 -2
- package/dist/ai/apis/chatgpt-rate-limits.d.ts +1 -1
- package/dist/ai/apis/chatgpt-rate-limits.js +1 -1
- package/dist/ai/apis/max-tokens.d.ts +1 -1
- package/dist/ai/apis/max-tokens.js +1 -1
- package/dist/ai/apis/shared.d.ts +1 -1
- package/dist/ai/apis/shared.js +1 -1
- package/dist/ai/image-intern.d.ts +2 -2
- package/dist/ai/image-intern.js +1 -1
- package/dist/ai/image-limits.d.ts +1 -1
- package/dist/ai/image-limits.js +1 -1
- package/dist/ai/json-body.d.ts +1 -1
- package/dist/ai/json-body.js +1 -1
- package/dist/ai/providers/builtin.d.ts +2 -2
- package/dist/ai/providers/builtin.js +4 -4
- package/dist/ai/providers/catalog.d.ts +2 -2
- package/dist/ai/providers/catalog.js +1 -1
- package/dist/ai/providers/channels.d.ts +1 -1
- package/dist/ai/providers/channels.js +1 -1
- package/dist/ai/providers/enrich.d.ts +1 -1
- package/dist/ai/providers/enrich.js +1 -1
- package/dist/ai/providers/models-dev-cache.d.ts +1 -1
- package/dist/ai/providers/models-dev-cache.js +1 -1
- package/dist/ai/providers/models-dev-data.d.ts +1 -1
- package/dist/ai/providers/models-dev-data.js +1 -1
- package/dist/ai/providers/models-dev-snapshot.d.ts +1 -1
- package/dist/ai/providers/models-dev-snapshot.js +1 -1
- package/dist/ai/providers/models-dev.d.ts +4 -4
- package/dist/ai/providers/models-dev.js +3 -3
- package/dist/ai/types.d.ts +2 -2
- package/dist/ai/types.js +1 -1
- package/dist/auth/chatgpt/cli.d.ts +1 -1
- package/dist/auth/chatgpt/cli.js +1 -1
- package/dist/auth/chatgpt/host-id.d.ts +1 -1
- package/dist/auth/chatgpt/host-id.js +1 -1
- package/dist/auth/chatgpt/login.d.ts +1 -1
- package/dist/auth/chatgpt/login.js +1 -1
- package/dist/auth/chatgpt/presets.d.ts +1 -1
- package/dist/auth/chatgpt/presets.js +1 -1
- package/dist/auth/oauth/callback-server.d.ts +1 -1
- package/dist/auth/oauth/callback-server.js +1 -1
- package/dist/auth/oauth/flows.d.ts +1 -1
- package/dist/auth/oauth/flows.js +1 -1
- package/dist/auth/oauth/oidc.d.ts +1 -1
- package/dist/auth/oauth/oidc.js +1 -1
- package/dist/auth/oauth/pkce.d.ts +1 -1
- package/dist/auth/oauth/pkce.js +1 -1
- package/dist/auth/oauth/refresh.d.ts +1 -1
- package/dist/auth/oauth/refresh.js +1 -1
- package/dist/auth/oauth/token-client.d.ts +1 -1
- package/dist/auth/oauth/token-client.js +1 -1
- package/dist/auth/oauth/token-store.d.ts +1 -1
- package/dist/auth/oauth/token-store.js +1 -1
- package/dist/auth/testing/fake-oauth.d.ts +1 -1
- package/dist/auth/testing/fake-oauth.js +1 -1
- package/dist/bundle/ama.cjs +1041 -359
- package/dist/checkpoints/blobs.d.ts +1 -1
- package/dist/checkpoints/blobs.js +1 -1
- package/dist/checkpoints/gc.d.ts +1 -1
- package/dist/checkpoints/gc.js +1 -1
- package/dist/checkpoints/git-head.d.ts +1 -1
- package/dist/checkpoints/git-head.js +1 -1
- package/dist/checkpoints/index.d.ts +1 -1
- package/dist/checkpoints/index.js +1 -1
- package/dist/checkpoints/replay.d.ts +1 -1
- package/dist/checkpoints/replay.js +1 -1
- package/dist/checkpoints/restore.d.ts +1 -1
- package/dist/checkpoints/restore.js +1 -1
- package/dist/checkpoints/settings.d.ts +1 -1
- package/dist/checkpoints/settings.js +1 -1
- package/dist/checkpoints/shadow-git.d.ts +1 -1
- package/dist/checkpoints/shadow-git.js +1 -1
- package/dist/checkpoints/shadow-restore.d.ts +1 -1
- package/dist/checkpoints/shadow-restore.js +1 -1
- package/dist/checkpoints/tracker.d.ts +1 -1
- package/dist/checkpoints/tracker.js +1 -1
- package/dist/checkpoints/types.d.ts +1 -1
- package/dist/checkpoints/types.js +1 -1
- package/dist/cli/args.d.ts +2 -2
- package/dist/cli/args.js +1 -1
- package/dist/cli/bootstrap.js +1 -1
- package/dist/cli/choice-prompt.d.ts +1 -1
- package/dist/cli/choice-prompt.js +1 -1
- package/dist/cli/codemode-notice.d.ts +1 -1
- package/dist/cli/codemode-notice.js +1 -1
- package/dist/cli/compose-agents.d.ts +1 -1
- package/dist/cli/compose-agents.js +1 -1
- package/dist/cli/compose-extensions.d.ts +1 -1
- package/dist/cli/compose-extensions.js +1 -1
- package/dist/cli/compose-memory.d.ts +1 -1
- package/dist/cli/compose-memory.js +1 -1
- package/dist/cli/compose-providers.d.ts +1 -1
- package/dist/cli/compose-providers.js +1 -1
- package/dist/cli/compose-request.d.ts +1 -1
- package/dist/cli/compose-request.js +1 -1
- package/dist/cli/from-prompt.d.ts +1 -1
- package/dist/cli/from-prompt.js +1 -1
- package/dist/cli/main.d.ts +1 -1
- package/dist/cli/main.js +1 -1
- package/dist/cli/subcommands/auth.d.ts +1 -1
- package/dist/cli/subcommands/auth.js +1 -1
- package/dist/cli/subcommands/config-set.d.ts +1 -1
- package/dist/cli/subcommands/config-set.js +1 -1
- package/dist/cli/subcommands/doctor.js +1 -1
- package/dist/cli/subcommands/init.d.ts +1 -1
- package/dist/cli/subcommands/init.js +1 -1
- package/dist/cli/subcommands/memory.d.ts +1 -1
- package/dist/cli/subcommands/memory.js +1 -1
- package/dist/cli/subcommands/models.js +1 -1
- package/dist/cli/subcommands/providers-list.d.ts +1 -1
- package/dist/cli/subcommands/providers-list.js +1 -1
- package/dist/cli/subcommands/providers-plan.d.ts +1 -1
- package/dist/cli/subcommands/providers-plan.js +1 -1
- package/dist/cli/subcommands/providers.d.ts +1 -1
- package/dist/cli/subcommands/providers.js +1 -1
- package/dist/cli/subcommands/sessions-export.d.ts +1 -1
- package/dist/cli/subcommands/sessions-export.js +1 -1
- package/dist/cli/subcommands/sessions-trace.d.ts +1 -1
- package/dist/cli/subcommands/sessions-trace.js +1 -1
- package/dist/cli/subcommands/sessions.d.ts +1 -1
- package/dist/cli/subcommands/sessions.js +1 -1
- package/dist/cli/subcommands/stats.d.ts +1 -1
- package/dist/cli/subcommands/stats.js +1 -1
- package/dist/codemode/capability.d.ts +1 -1
- package/dist/codemode/capability.js +1 -1
- package/dist/codemode/host-side.d.ts +2 -2
- package/dist/codemode/host-side.js +2 -2
- package/dist/compaction/image-budget.d.ts +1 -1
- package/dist/compaction/image-budget.js +1 -1
- package/dist/config/edit.d.ts +1 -1
- package/dist/config/edit.js +1 -1
- package/dist/config/init.d.ts +1 -1
- package/dist/config/init.js +1 -1
- package/dist/config/json-schema.d.ts +2 -2
- package/dist/config/json-schema.js +2 -2
- package/dist/config/schema-w5.d.ts +1 -1
- package/dist/config/schema-w5.js +1 -1
- package/dist/config/schema-w6.d.ts +1 -1
- package/dist/config/schema-w6.js +1 -1
- package/dist/config/settings-registry.d.ts +1 -1
- package/dist/config/settings-registry.js +1 -1
- package/dist/config/types-w5.d.ts +2 -2
- package/dist/config/types-w5.js +2 -2
- package/dist/config/types-w6.d.ts +5 -5
- package/dist/config/types-w6.js +1 -1
- package/dist/config/types.d.ts +6 -6
- package/dist/config/types.js +1 -1
- package/dist/drivers/acp/client.d.ts +1 -1
- package/dist/drivers/acp/client.js +1 -1
- package/dist/drivers/acp/driver.d.ts +23 -2
- package/dist/drivers/acp/driver.js +60 -6
- package/dist/drivers/acp/testing/fake-agent.d.ts +1 -1
- package/dist/drivers/acp/testing/fake-agent.js +1 -1
- package/dist/drivers/acp/types.d.ts +1 -1
- package/dist/drivers/acp/types.js +1 -1
- package/dist/drivers/agents.d.ts +1 -1
- package/dist/drivers/agents.js +4 -1
- package/dist/drivers/base.d.ts +1 -1
- package/dist/drivers/base.js +1 -1
- package/dist/drivers/catalog.d.ts +3 -1
- package/dist/drivers/catalog.js +95 -5
- package/dist/drivers/env.d.ts +1 -1
- package/dist/drivers/env.js +1 -1
- package/dist/drivers/host-runners.d.ts +1 -1
- package/dist/drivers/host-runners.js +1 -1
- package/dist/drivers/jsonrpc.d.ts +1 -1
- package/dist/drivers/jsonrpc.js +1 -1
- package/dist/drivers/native/claude-normalize.d.ts +9 -1
- package/dist/drivers/native/claude-normalize.js +28 -1
- package/dist/drivers/native/claude-stream.d.ts +1 -1
- package/dist/drivers/native/claude-stream.js +17 -2
- package/dist/drivers/native/codex-app-server.d.ts +1 -1
- package/dist/drivers/native/codex-app-server.js +5 -3
- package/dist/drivers/native/codex-normalize.d.ts +1 -1
- package/dist/drivers/native/codex-normalize.js +1 -1
- package/dist/drivers/native/oneshot.d.ts +1 -1
- package/dist/drivers/native/oneshot.js +13 -3
- package/dist/drivers/native/pi-gate.d.ts +19 -0
- package/dist/drivers/native/pi-gate.js +39 -0
- package/dist/drivers/native/pi-rpc.d.ts +29 -0
- package/dist/drivers/native/pi-rpc.js +483 -0
- package/dist/drivers/permissions.d.ts +1 -1
- package/dist/drivers/permissions.js +1 -1
- package/dist/drivers/pids.d.ts +1 -1
- package/dist/drivers/pids.js +1 -1
- package/dist/drivers/pool.d.ts +1 -1
- package/dist/drivers/pool.js +1 -1
- package/dist/drivers/probe.d.ts +1 -1
- package/dist/drivers/probe.js +1 -1
- package/dist/drivers/process.d.ts +1 -1
- package/dist/drivers/process.js +1 -1
- package/dist/drivers/runner.d.ts +1 -1
- package/dist/drivers/runner.js +2 -1
- package/dist/drivers/store.d.ts +1 -1
- package/dist/drivers/store.js +1 -1
- package/dist/drivers/types.d.ts +2 -2
- package/dist/drivers/types.js +1 -1
- package/dist/git/info.d.ts +1 -1
- package/dist/git/info.js +1 -1
- package/dist/host/api-impl.d.ts +1 -1
- package/dist/host/api-impl.js +1 -1
- package/dist/host/types.d.ts +2 -2
- package/dist/i18n/catalog.d.ts +5 -2
- package/dist/i18n/catalog.js +2 -2
- package/dist/i18n/format.d.ts +1 -1
- package/dist/i18n/format.js +1 -1
- package/dist/i18n/index.d.ts +1 -1
- package/dist/i18n/index.js +1 -1
- package/dist/i18n/messages/acp.d.ts +1 -1
- package/dist/i18n/messages/acp.js +1 -1
- package/dist/i18n/messages/agents.d.ts +1 -1
- package/dist/i18n/messages/agents.js +1 -1
- package/dist/i18n/messages/approval.d.ts +1 -1
- package/dist/i18n/messages/approval.js +1 -1
- package/dist/i18n/messages/auth.d.ts +3 -1
- package/dist/i18n/messages/auth.js +3 -1
- package/dist/i18n/messages/cli.d.ts +1 -1
- package/dist/i18n/messages/cli.js +1 -1
- package/dist/i18n/messages/config-keys.js +12 -12
- package/dist/i18n/messages/config.d.ts +1 -1
- package/dist/i18n/messages/config.js +3 -3
- package/dist/i18n/messages/drivers.d.ts +5 -1
- package/dist/i18n/messages/drivers.js +5 -1
- package/dist/i18n/messages/errors.d.ts +1 -1
- package/dist/i18n/messages/errors.js +1 -1
- package/dist/i18n/messages/interactive-line.d.ts +1 -1
- package/dist/i18n/messages/interactive-line.js +1 -1
- package/dist/i18n/messages/interactive-startup.d.ts +1 -1
- package/dist/i18n/messages/interactive-startup.js +1 -1
- package/dist/i18n/messages/interactive-view.d.ts +1 -1
- package/dist/i18n/messages/interactive-view.js +1 -1
- package/dist/i18n/messages/interactive.d.ts +1 -1
- package/dist/i18n/messages/interactive.js +1 -1
- package/dist/i18n/messages/memory.d.ts +1 -1
- package/dist/i18n/messages/memory.js +1 -1
- package/dist/i18n/messages/panels.d.ts +1 -1
- package/dist/i18n/messages/panels.js +1 -1
- package/dist/i18n/messages/permissions.d.ts +1 -1
- package/dist/i18n/messages/permissions.js +1 -1
- package/dist/i18n/messages/plan.d.ts +1 -1
- package/dist/i18n/messages/plan.js +1 -1
- package/dist/i18n/messages/print.d.ts +2 -2
- package/dist/i18n/messages/print.js +2 -2
- package/dist/i18n/messages/report-context.d.ts +1 -1
- package/dist/i18n/messages/report-context.js +1 -1
- package/dist/i18n/messages/report.d.ts +1 -1
- package/dist/i18n/messages/report.js +1 -1
- package/dist/i18n/messages/rewind.d.ts +1 -1
- package/dist/i18n/messages/rewind.js +1 -1
- package/dist/i18n/messages/session.d.ts +1 -1
- package/dist/i18n/messages/session.js +1 -1
- package/dist/i18n/messages/settings.d.ts +1 -1
- package/dist/i18n/messages/settings.js +1 -1
- package/dist/i18n/messages/subcommands.d.ts +1 -1
- package/dist/i18n/messages/subcommands.js +1 -1
- package/dist/i18n/messages/trace.d.ts +1 -1
- package/dist/i18n/messages/trace.js +1 -1
- package/dist/i18n/types.d.ts +1 -1
- package/dist/i18n/types.js +1 -1
- package/dist/memory/frontmatter.d.ts +1 -1
- package/dist/memory/frontmatter.js +1 -1
- package/dist/memory/index.d.ts +1 -1
- package/dist/memory/index.js +1 -1
- package/dist/memory/lock.d.ts +1 -1
- package/dist/memory/lock.js +1 -1
- package/dist/memory/paths.d.ts +1 -1
- package/dist/memory/paths.js +1 -1
- package/dist/memory/runtime.d.ts +1 -1
- package/dist/memory/runtime.js +1 -1
- package/dist/memory/secrets.d.ts +1 -1
- package/dist/memory/secrets.js +1 -1
- package/dist/memory/section.d.ts +1 -1
- package/dist/memory/section.js +1 -1
- package/dist/memory/store.d.ts +1 -1
- package/dist/memory/store.js +1 -1
- package/dist/memory/tool.d.ts +1 -1
- package/dist/memory/tool.js +1 -1
- package/dist/modes/acp/acp-auth-gate.d.ts +1 -1
- package/dist/modes/acp/acp-auth-gate.js +1 -1
- package/dist/modes/acp/acp-config.d.ts +1 -1
- package/dist/modes/acp/acp-config.js +1 -1
- package/dist/modes/acp/acp-connection.d.ts +1 -1
- package/dist/modes/acp/acp-connection.js +1 -1
- package/dist/modes/acp/acp-events.d.ts +1 -1
- package/dist/modes/acp/acp-events.js +1 -1
- package/dist/modes/acp/acp-mode.d.ts +1 -1
- package/dist/modes/acp/acp-mode.js +1 -1
- package/dist/modes/acp/acp-server.d.ts +2 -2
- package/dist/modes/acp/acp-server.js +2 -2
- package/dist/modes/acp/acp-sessions.d.ts +2 -2
- package/dist/modes/acp/acp-sessions.js +2 -2
- package/dist/modes/acp/acp-tool-text.d.ts +1 -1
- package/dist/modes/acp/acp-tool-text.js +1 -1
- package/dist/modes/commands-core.js +1 -1
- package/dist/modes/image-input.d.ts +1 -1
- package/dist/modes/image-input.js +1 -1
- package/dist/modes/interactive/agent-bar.d.ts +1 -1
- package/dist/modes/interactive/agent-bar.js +1 -1
- package/dist/modes/interactive/agent-transcript.d.ts +1 -1
- package/dist/modes/interactive/agent-transcript.js +1 -1
- package/dist/modes/interactive/agent-view.d.ts +1 -1
- package/dist/modes/interactive/agent-view.js +1 -1
- package/dist/modes/interactive/approval-dock.d.ts +1 -1
- package/dist/modes/interactive/approval-dock.js +1 -1
- package/dist/modes/interactive/config-panel.d.ts +1 -1
- package/dist/modes/interactive/config-panel.js +1 -1
- package/dist/modes/interactive/config-ui.d.ts +1 -1
- package/dist/modes/interactive/config-ui.js +1 -1
- package/dist/modes/interactive/memory-panel.d.ts +1 -1
- package/dist/modes/interactive/memory-panel.js +1 -1
- package/dist/modes/interactive/plan-command.d.ts +1 -1
- package/dist/modes/interactive/plan-command.js +1 -1
- package/dist/modes/interactive/plan-dialog.d.ts +1 -1
- package/dist/modes/interactive/plan-dialog.js +1 -1
- package/dist/modes/interactive/plan-flow.d.ts +1 -1
- package/dist/modes/interactive/plan-flow.js +1 -1
- package/dist/modes/interactive/subagent-view.d.ts +1 -1
- package/dist/modes/interactive/subagent-view.js +1 -1
- package/dist/modes/interactive/task-background.d.ts +1 -1
- package/dist/modes/interactive/task-background.js +1 -1
- package/dist/modes/interactive/trace-view.d.ts +1 -1
- package/dist/modes/interactive/trace-view.js +1 -1
- package/dist/modes/print/json-event.d.ts +1 -1
- package/dist/modes/print/json-event.js +2 -2
- package/dist/modes/print/print-mode.d.ts +1 -1
- package/dist/modes/print/print-mode.js +1 -1
- package/dist/modes/print/search-hint.d.ts +1 -1
- package/dist/modes/print/search-hint.js +1 -1
- package/dist/modes/rpc/commands.js +2 -2
- package/dist/permissions/auto-safe.d.ts +1 -1
- package/dist/permissions/auto-safe.js +1 -1
- package/dist/permissions/bypass.d.ts +1 -1
- package/dist/permissions/bypass.js +1 -1
- package/dist/permissions/classifier.d.ts +1 -1
- package/dist/permissions/classifier.js +1 -1
- package/dist/permissions/memory-class.d.ts +1 -1
- package/dist/permissions/memory-class.js +1 -1
- package/dist/permissions/pipeline.d.ts +2 -2
- package/dist/permissions/pipeline.js +2 -2
- package/dist/permissions/protected.d.ts +1 -1
- package/dist/permissions/protected.js +1 -1
- package/dist/permissions/readonly-bash.d.ts +1 -1
- package/dist/permissions/readonly-bash.js +1 -1
- package/dist/permissions/types.d.ts +2 -2
- package/dist/plan/done-markers.d.ts +1 -1
- package/dist/plan/done-markers.js +1 -1
- package/dist/plan/extract.d.ts +1 -1
- package/dist/plan/extract.js +1 -1
- package/dist/plan/prompts.d.ts +1 -1
- package/dist/plan/prompts.js +1 -1
- package/dist/plan/store.d.ts +1 -1
- package/dist/plan/store.js +1 -1
- package/dist/rpc.d.ts +3 -3
- package/dist/rpc.js +3 -3
- package/dist/sandbox/bash.d.ts +1 -1
- package/dist/sandbox/bash.js +1 -1
- package/dist/sandbox/detect.d.ts +1 -1
- package/dist/sandbox/detect.js +1 -1
- package/dist/sandbox/index.d.ts +1 -1
- package/dist/sandbox/index.js +1 -1
- package/dist/sandbox/profile.d.ts +1 -1
- package/dist/sandbox/profile.js +1 -1
- package/dist/sandbox/wrap.d.ts +1 -1
- package/dist/sandbox/wrap.js +1 -1
- package/dist/sdk.d.ts +3 -3
- package/dist/sdk.js +2 -2
- package/dist/session/line-reader.d.ts +1 -1
- package/dist/session/line-reader.js +1 -1
- package/dist/session/list.d.ts +1 -1
- package/dist/session/list.js +1 -1
- package/dist/session/migrate.d.ts +1 -1
- package/dist/session/migrate.js +1 -1
- package/dist/session/store.d.ts +1 -1
- package/dist/session/store.js +1 -1
- package/dist/skills/builtin.js +2 -2
- package/dist/tools/background-jobs.d.ts +1 -1
- package/dist/tools/background-jobs.js +1 -1
- package/dist/tools/clipboard-image.d.ts +1 -1
- package/dist/tools/clipboard-image.js +1 -1
- package/dist/tools/edit.d.ts +1 -1
- package/dist/tools/edit.js +1 -1
- package/dist/tools/grep.d.ts +1 -1
- package/dist/tools/grep.js +1 -1
- package/dist/tools/image-resize.d.ts +1 -1
- package/dist/tools/image-resize.js +1 -1
- package/dist/tools/read-lines.d.ts +1 -1
- package/dist/tools/read-lines.js +1 -1
- package/dist/tools/read.d.ts +1 -1
- package/dist/tools/read.js +1 -1
- package/dist/tools/task-ctl.d.ts +1 -1
- package/dist/tools/task-ctl.js +1 -1
- package/dist/tools/task.d.ts +2 -2
- package/dist/tools/task.js +2 -2
- package/dist/tools/types.d.ts +3 -3
- package/dist/tools/types.js +1 -1
- package/dist/trace/build.d.ts +1 -1
- package/dist/trace/build.js +1 -1
- package/dist/trace/detail.d.ts +1 -1
- package/dist/trace/detail.js +1 -1
- package/dist/trace/flatten.d.ts +1 -1
- package/dist/trace/flatten.js +1 -1
- package/dist/trace/format.d.ts +1 -1
- package/dist/trace/format.js +1 -1
- package/dist/trace/html-template.d.ts +1 -1
- package/dist/trace/html-template.js +1 -1
- package/dist/trace/html.d.ts +1 -1
- package/dist/trace/html.js +1 -1
- package/dist/trace/query-session.d.ts +1 -1
- package/dist/trace/query-session.js +1 -1
- package/dist/trace/query.d.ts +1 -1
- package/dist/trace/query.js +1 -1
- package/dist/trace/types.d.ts +1 -1
- package/dist/trace/types.js +1 -1
- package/dist/tui/components/settings-list.d.ts +1 -1
- package/dist/tui/components/settings-list.js +1 -1
- package/docs/README.md +85 -0
- package/docs/assets/ama-wordmark-dark.svg +37 -0
- package/docs/assets/ama-wordmark-light.svg +37 -0
- package/docs/en/README.md +39 -0
- package/docs/en/{permissions.md → guides/permissions.md} +14 -14
- package/docs/en/{providers.md → guides/providers.md} +13 -12
- package/docs/en/{sessions.md → guides/sessions.md} +6 -6
- package/docs/en/{tui.md → guides/tui.md} +15 -15
- package/docs/en/{acp.md → reference/acp.md} +6 -6
- package/docs/en/{host-api.md → reference/host-api.md} +7 -7
- package/docs/en/{rpc.md → reference/rpc.md} +13 -13
- package/docs/{agents.md → guides/agents.md} +68 -23
- package/docs/{codemode.md → guides/codemode.md} +3 -3
- package/docs/{hooks.md → guides/hooks.md} +2 -2
- package/docs/guides/i18n.md +93 -0
- package/docs/{memory.md → guides/memory.md} +1 -1
- package/docs/{permissions.md → guides/permissions.md} +2 -2
- package/docs/{plan.md → guides/plan.md} +4 -4
- package/docs/{providers.md → guides/providers.md} +11 -10
- package/docs/{sessions.md → guides/sessions.md} +5 -5
- package/docs/{tui.md → guides/tui.md} +8 -8
- package/docs/{acp.md → reference/acp.md} +5 -5
- package/docs/{host-api.md → reference/host-api.md} +4 -4
- package/docs/{rpc.md → reference/rpc.md} +11 -11
- package/docs/{session-format.md → reference/session-format.md} +7 -7
- package/package.json +12 -23
- package/docs/rewind-plan.md +0 -181
- package/docs/tui-design.md +0 -764
- /package/docs/{sandbox.md → guides/sandbox.md} +0 -0
|
@@ -0,0 +1,483 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pi 原生驱动:`pi --mode rpc` 长驻进程(stdin 命令 / stdout 响应与事件,严格按 LF 分帧)。[#198]
|
|
3
|
+
*
|
|
4
|
+
* `pi --mode rpc --session-id <uuid> [--model <m>] -e <审批闸> [--tools read,grep,find,ls]`
|
|
5
|
+
* (新会话与续聊都用 `--session-id`:pi 找到同 id 的项目会话就续上,否则新建)。
|
|
6
|
+
*
|
|
7
|
+
* - 回合:`prompt` → 响应 `disposition`(`handled` 时没有运行,直接结束)→ 事件流 → `agent_settled`
|
|
8
|
+
* 结束(`aborted` 为真即中断);运行中追加用 `steer`;中断 `abort`(15 s 看门狗)。
|
|
9
|
+
* - 审批:pi 自己不问人,ama 以 `-e` 加载审批闸({@link PI_GATE_SOURCE}),只读内置工具以外的调用
|
|
10
|
+
* 经 `extension_ui_request{confirm, title: "ama-approval"}` 到这里:plan / allowlist 直接拒绝(并以
|
|
11
|
+
* `--tools` 只开只读工具),auto-edit / auto / full-auto 放行 `edit` / `write`,其余交给人(只交给人,
|
|
12
|
+
* 不代答)。其它扩展的对话框(select / input / editor / 别的 confirm)一律取消并提示。
|
|
13
|
+
* - 用量:assistant `message_end` 的 usage 累加(input 不含缓存命中,cost.total 是 pi 按价目表的估算);
|
|
14
|
+
* 回合结束后 `get_session_stats` 的 `contextUsage` 记上下文占用与窗口。
|
|
15
|
+
*/
|
|
16
|
+
import { randomUUID } from "node:crypto";
|
|
17
|
+
import { resolve as resolvePath } from "node:path";
|
|
18
|
+
import { AmaError } from "../../errors.js";
|
|
19
|
+
import { createLineReader } from "../../modes/rpc/jsonl.js";
|
|
20
|
+
import { armCancelWatchdog, isReadOnlyMode, probeCandidate, spawnOf, } from "../base.js";
|
|
21
|
+
import { stderrHint } from "../process.js";
|
|
22
|
+
import { TurnCollector, oneLine } from "../turn.js";
|
|
23
|
+
import { PI_GATE_TITLE, PI_READ_ONLY_TOOLS, writePiGate } from "./pi-gate.js";
|
|
24
|
+
import { msg } from "../../i18n/index.js";
|
|
25
|
+
const DIALOG_METHODS = new Set(["select", "confirm", "input", "editor"]);
|
|
26
|
+
/** auto-edit 及更宽的模式下不问人的文件编辑工具。 */
|
|
27
|
+
const EDIT_TOOLS = new Set(["edit", "write"]);
|
|
28
|
+
export function piArgs(options, sessionId, gatePath) {
|
|
29
|
+
const args = ["--session-id", sessionId];
|
|
30
|
+
if (options.model !== undefined)
|
|
31
|
+
args.push("--model", options.model);
|
|
32
|
+
args.push("-e", gatePath);
|
|
33
|
+
if (isReadOnlyMode(options.mode))
|
|
34
|
+
args.push("--tools", PI_READ_ONLY_TOOLS.join(","));
|
|
35
|
+
return args;
|
|
36
|
+
}
|
|
37
|
+
export function piToolKind(tool) {
|
|
38
|
+
switch (tool) {
|
|
39
|
+
case "bash":
|
|
40
|
+
case "powershell":
|
|
41
|
+
return "execute";
|
|
42
|
+
case "edit":
|
|
43
|
+
case "write":
|
|
44
|
+
return "edit";
|
|
45
|
+
case "read":
|
|
46
|
+
return "read";
|
|
47
|
+
case "grep":
|
|
48
|
+
case "find":
|
|
49
|
+
case "ls":
|
|
50
|
+
return "search";
|
|
51
|
+
default:
|
|
52
|
+
return "other";
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function piToolTitle(tool, input) {
|
|
56
|
+
if (typeof input["command"] === "string")
|
|
57
|
+
return `$ ${oneLine(input["command"], 100)}`;
|
|
58
|
+
if (typeof input["path"] === "string")
|
|
59
|
+
return `${tool} ${input["path"]}`;
|
|
60
|
+
if (typeof input["pattern"] === "string")
|
|
61
|
+
return `${tool} ${oneLine(input["pattern"], 80)}`;
|
|
62
|
+
return tool;
|
|
63
|
+
}
|
|
64
|
+
function textOf(message) {
|
|
65
|
+
const content = message["content"];
|
|
66
|
+
if (typeof content === "string")
|
|
67
|
+
return content;
|
|
68
|
+
if (!Array.isArray(content))
|
|
69
|
+
return "";
|
|
70
|
+
return content
|
|
71
|
+
.map((b) => (b["type"] === "text" && typeof b["text"] === "string" ? b["text"] : ""))
|
|
72
|
+
.join("");
|
|
73
|
+
}
|
|
74
|
+
export class PiRpcDriver {
|
|
75
|
+
agentId;
|
|
76
|
+
candidate;
|
|
77
|
+
deps;
|
|
78
|
+
kind = "pi-rpc";
|
|
79
|
+
constructor(agentId, candidate, deps = {}) {
|
|
80
|
+
this.agentId = agentId;
|
|
81
|
+
this.candidate = candidate;
|
|
82
|
+
this.deps = deps;
|
|
83
|
+
}
|
|
84
|
+
probe() {
|
|
85
|
+
return probeCandidate(this.candidate, this.deps);
|
|
86
|
+
}
|
|
87
|
+
async open(options) {
|
|
88
|
+
const probed = await probeCandidate(this.candidate, this.deps);
|
|
89
|
+
const sessionId = options.resume ?? randomUUID();
|
|
90
|
+
const gate = writePiGate();
|
|
91
|
+
const transport = spawnOf(this.deps)({
|
|
92
|
+
program: probed.path ?? this.candidate.program,
|
|
93
|
+
args: [...this.candidate.args, ...piArgs(options, sessionId, gate.path)],
|
|
94
|
+
cwd: options.cwd,
|
|
95
|
+
env: options.env,
|
|
96
|
+
});
|
|
97
|
+
const session = new PiSession(this.agentId, sessionId, transport, options, this.deps, () => gate.dispose());
|
|
98
|
+
if (probed.warning !== undefined)
|
|
99
|
+
session.notices.push(probed.warning);
|
|
100
|
+
try {
|
|
101
|
+
await session.start(options.signal);
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
await session.close();
|
|
105
|
+
throw new AmaError("agent_start_failed", `${this.agentId}: failed to start (${error.message})${stderrHint(transport) !== "" ? `: ${stderrHint(transport)}` : ""}`, { cause: error });
|
|
106
|
+
}
|
|
107
|
+
return session;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
class PiSession {
|
|
111
|
+
agentId;
|
|
112
|
+
id;
|
|
113
|
+
transport;
|
|
114
|
+
options;
|
|
115
|
+
deps;
|
|
116
|
+
dispose;
|
|
117
|
+
notices = [];
|
|
118
|
+
nextId = 1;
|
|
119
|
+
pending = new Map();
|
|
120
|
+
permissions = new Set();
|
|
121
|
+
turn;
|
|
122
|
+
hooks;
|
|
123
|
+
settle;
|
|
124
|
+
running;
|
|
125
|
+
usage = { input: 0, output: 0, cacheRead: 0, costUsd: 0, seen: false };
|
|
126
|
+
lastAssistant;
|
|
127
|
+
interrupted = false;
|
|
128
|
+
closed = false;
|
|
129
|
+
exited = false;
|
|
130
|
+
exitWaiters = new Set();
|
|
131
|
+
constructor(agentId, id, transport, options, deps, dispose) {
|
|
132
|
+
this.agentId = agentId;
|
|
133
|
+
this.id = id;
|
|
134
|
+
this.transport = transport;
|
|
135
|
+
this.options = options;
|
|
136
|
+
this.deps = deps;
|
|
137
|
+
this.dispose = dispose;
|
|
138
|
+
createLineReader(transport.stdout, (line) => this.onLine(line), () => this.onExit());
|
|
139
|
+
transport.stdin.on?.("error", () => undefined);
|
|
140
|
+
}
|
|
141
|
+
get sessionId() {
|
|
142
|
+
return this.id;
|
|
143
|
+
}
|
|
144
|
+
/** 握手:`get_state` 确认进程起来了,并取 pi 实际使用的会话 id。 */
|
|
145
|
+
async start(signal) {
|
|
146
|
+
const aborted = new Promise((_, reject) => {
|
|
147
|
+
if (signal.aborted)
|
|
148
|
+
reject(new Error("aborted"));
|
|
149
|
+
signal.addEventListener("abort", () => reject(new Error("aborted")), { once: true });
|
|
150
|
+
});
|
|
151
|
+
void aborted.catch(() => undefined);
|
|
152
|
+
const state = await Promise.race([this.request({ type: "get_state" }), aborted]);
|
|
153
|
+
const data = (state["data"] ?? {});
|
|
154
|
+
if (typeof data["sessionId"] === "string" && data["sessionId"] !== "")
|
|
155
|
+
this.id = data["sessionId"];
|
|
156
|
+
}
|
|
157
|
+
async prompt(content, hooks) {
|
|
158
|
+
if (this.closed || this.exited)
|
|
159
|
+
throw new AmaError("agent_closed", `${this.agentId} session is closed`);
|
|
160
|
+
if (this.running !== undefined)
|
|
161
|
+
throw new AmaError("busy", `${this.agentId} is already running`);
|
|
162
|
+
const turn = new TurnCollector((e) => hooks.onEvent(e));
|
|
163
|
+
for (const text of this.notices.splice(0))
|
|
164
|
+
turn.push({ type: "notice", level: "warn", text });
|
|
165
|
+
this.turn = turn;
|
|
166
|
+
this.hooks = hooks;
|
|
167
|
+
this.interrupted = false;
|
|
168
|
+
this.usage = { input: 0, output: 0, cacheRead: 0, costUsd: 0, seen: false };
|
|
169
|
+
this.lastAssistant = undefined;
|
|
170
|
+
this.running = this.run(content, turn);
|
|
171
|
+
try {
|
|
172
|
+
return await this.running;
|
|
173
|
+
}
|
|
174
|
+
finally {
|
|
175
|
+
this.running = undefined;
|
|
176
|
+
this.turn = undefined;
|
|
177
|
+
this.hooks = undefined;
|
|
178
|
+
this.settle = undefined;
|
|
179
|
+
this.exitWaiters.clear();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
async run(content, turn) {
|
|
183
|
+
// 先让出一拍:`this.running` 赋值之后再写命令(同步回显的对端里事件可能立刻到达并触发 cancel)
|
|
184
|
+
await Promise.resolve();
|
|
185
|
+
const settled = new Promise((resolve) => (this.settle = resolve));
|
|
186
|
+
const response = await this.request({ type: "prompt", ...this.message(content) });
|
|
187
|
+
if (response["success"] !== true)
|
|
188
|
+
throw new AmaError("agent_failed", `${this.agentId} rejected the prompt: ${oneLine(String(response["error"] ?? "unknown"), 300)}`);
|
|
189
|
+
const disposition = (response["data"] ?? {})["disposition"];
|
|
190
|
+
if (disposition === "handled")
|
|
191
|
+
return turn.result("end_turn");
|
|
192
|
+
const aborted = await Promise.race([settled, this.exitPromise()]);
|
|
193
|
+
await this.reportContext(turn);
|
|
194
|
+
return this.complete(turn, aborted);
|
|
195
|
+
}
|
|
196
|
+
async steer(content) {
|
|
197
|
+
if (this.closed || this.exited)
|
|
198
|
+
throw new AmaError("agent_closed", `${this.agentId} session is closed`);
|
|
199
|
+
await this.request({ type: "steer", ...this.message(content) });
|
|
200
|
+
}
|
|
201
|
+
async cancel() {
|
|
202
|
+
const running = this.running;
|
|
203
|
+
if (running === undefined || this.closed)
|
|
204
|
+
return;
|
|
205
|
+
this.interrupted = true;
|
|
206
|
+
for (const c of this.permissions)
|
|
207
|
+
c.abort();
|
|
208
|
+
void this.request({ type: "abort" }).catch(() => undefined);
|
|
209
|
+
armCancelWatchdog(this.transport, running.catch(() => undefined), this.deps);
|
|
210
|
+
}
|
|
211
|
+
async close() {
|
|
212
|
+
if (this.closed)
|
|
213
|
+
return;
|
|
214
|
+
this.closed = true;
|
|
215
|
+
for (const c of this.permissions)
|
|
216
|
+
c.abort();
|
|
217
|
+
if (this.running !== undefined) {
|
|
218
|
+
this.interrupted = true;
|
|
219
|
+
this.write({ type: "abort" });
|
|
220
|
+
}
|
|
221
|
+
try {
|
|
222
|
+
await this.transport.terminate();
|
|
223
|
+
}
|
|
224
|
+
finally {
|
|
225
|
+
this.dispose();
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
message(content) {
|
|
229
|
+
const text = content.map((b) => (b.type === "text" ? b.text : "")).join("\n");
|
|
230
|
+
const images = content.flatMap((b) => b.type === "image" ? [{ type: "image", data: b.data, mimeType: b.mimeType }] : []);
|
|
231
|
+
return { message: text, ...(images.length > 0 ? { images } : {}) };
|
|
232
|
+
}
|
|
233
|
+
complete(turn, aborted) {
|
|
234
|
+
const u = this.usage;
|
|
235
|
+
if (u.seen)
|
|
236
|
+
turn.push({
|
|
237
|
+
type: "usage",
|
|
238
|
+
input: u.input,
|
|
239
|
+
output: u.output,
|
|
240
|
+
cacheRead: u.cacheRead,
|
|
241
|
+
costUsd: u.costUsd,
|
|
242
|
+
});
|
|
243
|
+
const last = this.lastAssistant;
|
|
244
|
+
if (last !== undefined) {
|
|
245
|
+
const text = textOf(last);
|
|
246
|
+
if (text !== "")
|
|
247
|
+
turn.setFinalText(text);
|
|
248
|
+
}
|
|
249
|
+
if (aborted || this.interrupted)
|
|
250
|
+
return turn.result("cancelled");
|
|
251
|
+
switch (last?.["stopReason"]) {
|
|
252
|
+
case "error":
|
|
253
|
+
throw new AmaError("agent_failed", `${this.agentId} failed: ${oneLine(String(last["errorMessage"] ?? "unknown error"), 300)}`);
|
|
254
|
+
case "aborted":
|
|
255
|
+
return turn.result("cancelled");
|
|
256
|
+
case "length":
|
|
257
|
+
return turn.result("max_tokens");
|
|
258
|
+
default:
|
|
259
|
+
return turn.result("end_turn");
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
/** `get_session_stats.contextUsage` → 上下文占用与窗口(拿不到就算了)。 */
|
|
263
|
+
async reportContext(turn) {
|
|
264
|
+
if (this.exited)
|
|
265
|
+
return;
|
|
266
|
+
try {
|
|
267
|
+
const stats = await Promise.race([
|
|
268
|
+
this.request({ type: "get_session_stats" }),
|
|
269
|
+
new Promise((resolve) => setTimeout(() => resolve({}), 5_000).unref()),
|
|
270
|
+
]);
|
|
271
|
+
const usage = ((stats["data"] ?? {})["contextUsage"] ?? {});
|
|
272
|
+
const tokens = usage["tokens"];
|
|
273
|
+
const window = usage["contextWindow"];
|
|
274
|
+
if (typeof tokens === "number" || typeof window === "number")
|
|
275
|
+
turn.push({
|
|
276
|
+
type: "usage",
|
|
277
|
+
...(typeof tokens === "number" ? { contextTokens: tokens } : {}),
|
|
278
|
+
...(typeof window === "number" ? { contextWindow: window } : {}),
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
catch {
|
|
282
|
+
// 统计拿不到不影响回合
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
exitPromise() {
|
|
286
|
+
return new Promise((_, reject) => {
|
|
287
|
+
if (this.exited)
|
|
288
|
+
reject(this.exitError());
|
|
289
|
+
else
|
|
290
|
+
this.exitWaiters.add(reject);
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
exitError() {
|
|
294
|
+
const hint = stderrHint(this.transport);
|
|
295
|
+
return new AmaError("agent_exited", `${this.agentId} process exited${hint !== "" ? `: ${hint}` : ""}`);
|
|
296
|
+
}
|
|
297
|
+
request(command) {
|
|
298
|
+
if (this.exited)
|
|
299
|
+
return Promise.reject(this.exitError());
|
|
300
|
+
const id = `ama-${this.nextId++}`;
|
|
301
|
+
return new Promise((resolve, reject) => {
|
|
302
|
+
this.pending.set(id, { resolve, reject });
|
|
303
|
+
this.write({ id, ...command });
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
write(record) {
|
|
307
|
+
if (this.exited)
|
|
308
|
+
return;
|
|
309
|
+
this.transport.stdin.write(`${JSON.stringify(record)}\n`);
|
|
310
|
+
}
|
|
311
|
+
onExit() {
|
|
312
|
+
this.exited = true;
|
|
313
|
+
const error = this.exitError();
|
|
314
|
+
for (const p of this.pending.values())
|
|
315
|
+
p.reject(error);
|
|
316
|
+
this.pending.clear();
|
|
317
|
+
for (const reject of this.exitWaiters)
|
|
318
|
+
reject(error);
|
|
319
|
+
this.exitWaiters.clear();
|
|
320
|
+
for (const c of this.permissions)
|
|
321
|
+
c.abort();
|
|
322
|
+
}
|
|
323
|
+
onLine(line) {
|
|
324
|
+
let record;
|
|
325
|
+
try {
|
|
326
|
+
record = JSON.parse(line);
|
|
327
|
+
}
|
|
328
|
+
catch {
|
|
329
|
+
this.deps.log?.("debug", msg().drivers.agent.nonJson(this.agentId));
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
switch (record["type"]) {
|
|
333
|
+
case "response": {
|
|
334
|
+
const id = record["id"];
|
|
335
|
+
const pending = typeof id === "string" ? this.pending.get(id) : undefined;
|
|
336
|
+
if (pending === undefined || typeof id !== "string")
|
|
337
|
+
return;
|
|
338
|
+
this.pending.delete(id);
|
|
339
|
+
pending.resolve(record);
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
case "agent_settled":
|
|
343
|
+
this.settle?.(record["aborted"] === true);
|
|
344
|
+
return;
|
|
345
|
+
case "extension_ui_request":
|
|
346
|
+
void this.onDialog(record);
|
|
347
|
+
return;
|
|
348
|
+
default:
|
|
349
|
+
this.onEvent(record);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
onEvent(record) {
|
|
353
|
+
const turn = this.turn;
|
|
354
|
+
if (turn === undefined)
|
|
355
|
+
return;
|
|
356
|
+
switch (record["type"]) {
|
|
357
|
+
case "message_update": {
|
|
358
|
+
const event = (record["assistantMessageEvent"] ?? {});
|
|
359
|
+
const delta = event["delta"];
|
|
360
|
+
if (typeof delta !== "string")
|
|
361
|
+
return;
|
|
362
|
+
if (event["type"] === "text_delta")
|
|
363
|
+
turn.push({ type: "message_delta", text: delta });
|
|
364
|
+
else if (event["type"] === "thinking_delta")
|
|
365
|
+
turn.push({ type: "thought_delta", text: delta });
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
case "message_end": {
|
|
369
|
+
const message = (record["message"] ?? {});
|
|
370
|
+
if (message["role"] !== "assistant")
|
|
371
|
+
return;
|
|
372
|
+
this.lastAssistant = message;
|
|
373
|
+
const usage = (message["usage"] ?? {});
|
|
374
|
+
const num = (key) => typeof usage[key] === "number" ? usage[key] : 0;
|
|
375
|
+
const cost = (usage["cost"] ?? {})["total"];
|
|
376
|
+
this.usage = {
|
|
377
|
+
input: this.usage.input + num("input"),
|
|
378
|
+
output: this.usage.output + num("output"),
|
|
379
|
+
cacheRead: this.usage.cacheRead + num("cacheRead"),
|
|
380
|
+
costUsd: this.usage.costUsd + (typeof cost === "number" ? cost : 0),
|
|
381
|
+
seen: true,
|
|
382
|
+
};
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
case "tool_execution_start":
|
|
386
|
+
case "tool_execution_end": {
|
|
387
|
+
const tool = String(record["toolName"] ?? "tool");
|
|
388
|
+
const known = turn.tool(String(record["toolCallId"] ?? ""));
|
|
389
|
+
const input = (record["args"] ?? {});
|
|
390
|
+
const path = typeof input["path"] === "string" ? input["path"] : undefined;
|
|
391
|
+
const locations = path !== undefined ? [resolvePath(this.options.cwd, path)] : known?.locations;
|
|
392
|
+
turn.push({
|
|
393
|
+
type: "tool_call",
|
|
394
|
+
id: String(record["toolCallId"] ?? ""),
|
|
395
|
+
title: known?.title ?? piToolTitle(tool, input),
|
|
396
|
+
kind: piToolKind(tool),
|
|
397
|
+
status: record["type"] === "tool_execution_start"
|
|
398
|
+
? "in_progress"
|
|
399
|
+
: record["isError"] === true
|
|
400
|
+
? "failed"
|
|
401
|
+
: "completed",
|
|
402
|
+
...(locations !== undefined && locations.length > 0 ? { locations } : {}),
|
|
403
|
+
});
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
case "auto_retry_start":
|
|
407
|
+
turn.push({
|
|
408
|
+
type: "notice",
|
|
409
|
+
level: "warn",
|
|
410
|
+
text: msg().drivers.agent.error(this.agentId, oneLine(String(record["errorMessage"] ?? "error"), 200), true),
|
|
411
|
+
});
|
|
412
|
+
return;
|
|
413
|
+
default:
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
/** 扩展对话框:ama 的审批闸按模式决定或交给人;其它扩展的对话框取消(不代答)。 */
|
|
418
|
+
async onDialog(record) {
|
|
419
|
+
const id = String(record["id"] ?? "");
|
|
420
|
+
const method = String(record["method"] ?? "");
|
|
421
|
+
if (!DIALOG_METHODS.has(method)) {
|
|
422
|
+
if (record["method"] === "notify" && record["notifyType"] !== "info")
|
|
423
|
+
this.turn?.push({
|
|
424
|
+
type: "notice",
|
|
425
|
+
level: "warn",
|
|
426
|
+
text: `${this.agentId}: ${oneLine(String(record["message"] ?? ""), 200)}`,
|
|
427
|
+
});
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
if (method !== "confirm" || record["title"] !== PI_GATE_TITLE) {
|
|
431
|
+
this.turn?.push({
|
|
432
|
+
type: "notice",
|
|
433
|
+
level: "warn",
|
|
434
|
+
text: msg().drivers.agent.extensionDialog(this.agentId, oneLine(String(record["title"] ?? method), 80)),
|
|
435
|
+
});
|
|
436
|
+
this.write({ type: "extension_ui_response", id, cancelled: true });
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
const confirmed = await this.decide(record);
|
|
440
|
+
this.write({ type: "extension_ui_response", id, confirmed });
|
|
441
|
+
}
|
|
442
|
+
async decide(record) {
|
|
443
|
+
let call;
|
|
444
|
+
try {
|
|
445
|
+
call = JSON.parse(String(record["message"] ?? "{}"));
|
|
446
|
+
}
|
|
447
|
+
catch {
|
|
448
|
+
return false;
|
|
449
|
+
}
|
|
450
|
+
const tool = String(call["tool"] ?? "tool");
|
|
451
|
+
const input = (call["input"] ?? {});
|
|
452
|
+
const mode = this.options.mode;
|
|
453
|
+
if (isReadOnlyMode(mode))
|
|
454
|
+
return false;
|
|
455
|
+
if (mode !== "default" && EDIT_TOOLS.has(tool))
|
|
456
|
+
return true;
|
|
457
|
+
const hooks = this.hooks;
|
|
458
|
+
if (hooks === undefined || this.interrupted || this.closed)
|
|
459
|
+
return false;
|
|
460
|
+
const known = this.turn?.tool(String(call["id"] ?? ""));
|
|
461
|
+
const path = typeof input["path"] === "string" ? input["path"] : undefined;
|
|
462
|
+
const controller = new AbortController();
|
|
463
|
+
this.permissions.add(controller);
|
|
464
|
+
try {
|
|
465
|
+
const outcome = await hooks.onPermission({
|
|
466
|
+
toolCall: {
|
|
467
|
+
title: known?.title ?? piToolTitle(tool, input),
|
|
468
|
+
kind: piToolKind(tool),
|
|
469
|
+
...(path !== undefined ? { locations: [resolvePath(this.options.cwd, path)] } : {}),
|
|
470
|
+
inputSummary: oneLine(JSON.stringify(input), 300),
|
|
471
|
+
},
|
|
472
|
+
options: [
|
|
473
|
+
{ optionId: "allow", kind: "allow_once" },
|
|
474
|
+
{ optionId: "reject", kind: "reject_once" },
|
|
475
|
+
],
|
|
476
|
+
}, controller.signal);
|
|
477
|
+
return (!controller.signal.aborted && outcome.outcome === "selected" && outcome.optionId === "allow");
|
|
478
|
+
}
|
|
479
|
+
finally {
|
|
480
|
+
this.permissions.delete(controller);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}
|
package/dist/drivers/pids.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 外部 Agent 进程登记与孤儿清理(docs/wave5-plan.md §5.4 孤儿进程)。[W5-E]
|
|
2
|
+
* 外部 Agent 进程登记与孤儿清理(docs/history/wave5-plan.md §5.4 孤儿进程)。[W5-E]
|
|
3
3
|
*
|
|
4
4
|
* `<dataDir>/drivers/pids.json` 记 `{ pid, program, owner }`(owner = 起它的 ama 进程)。
|
|
5
5
|
* 正常退出时 `process-tree.ts` 已同步杀掉仍存活的组;这里处理 ama 被 SIGKILL / 崩溃留下的孤儿:
|
package/dist/drivers/pids.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 外部 Agent 进程登记与孤儿清理(docs/wave5-plan.md §5.4 孤儿进程)。[W5-E]
|
|
2
|
+
* 外部 Agent 进程登记与孤儿清理(docs/history/wave5-plan.md §5.4 孤儿进程)。[W5-E]
|
|
3
3
|
*
|
|
4
4
|
* `<dataDir>/drivers/pids.json` 记 `{ pid, program, owner }`(owner = 起它的 ama 进程)。
|
|
5
5
|
* 正常退出时 `process-tree.ts` 已同步杀掉仍存活的组;这里处理 ama 被 SIGKILL / 崩溃留下的孤儿:
|
package/dist/drivers/pool.d.ts
CHANGED
package/dist/drivers/pool.js
CHANGED
package/dist/drivers/probe.d.ts
CHANGED
package/dist/drivers/probe.js
CHANGED
package/dist/drivers/process.js
CHANGED
package/dist/drivers/runner.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* ProcessRunner:把 AgentDriver 适配成 SubagentRunner(docs/wave5-plan.md §7.6、§5.3–§5.4)。[W5-E]
|
|
2
|
+
* ProcessRunner:把 AgentDriver 适配成 SubagentRunner(docs/history/wave5-plan.md §7.6、§5.3–§5.4)。[W5-E]
|
|
3
3
|
*
|
|
4
4
|
* 外部 CLI Agent 由此与 ama 子 Agent 共用 `task(agent=…)` 入口(D13)。`start()`:
|
|
5
5
|
* 1. 只在已信任目录里起(§5.4 信任;`claude -p` 会跳过目录信任对话框并执行项目 hooks);
|
package/dist/drivers/runner.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* ProcessRunner:把 AgentDriver 适配成 SubagentRunner(docs/wave5-plan.md §7.6、§5.3–§5.4)。[W5-E]
|
|
2
|
+
* ProcessRunner:把 AgentDriver 适配成 SubagentRunner(docs/history/wave5-plan.md §7.6、§5.3–§5.4)。[W5-E]
|
|
3
3
|
*
|
|
4
4
|
* 外部 CLI Agent 由此与 ama 子 Agent 共用 `task(agent=…)` 入口(D13)。`start()`:
|
|
5
5
|
* 1. 只在已信任目录里起(§5.4 信任;`claude -p` 会跳过目录信任对话框并执行项目 hooks);
|
|
@@ -144,6 +144,7 @@ const TURN_INTERRUPT = new Set([
|
|
|
144
144
|
"acp-adapter",
|
|
145
145
|
"claude-stream",
|
|
146
146
|
"codex-app-server",
|
|
147
|
+
"pi-rpc",
|
|
147
148
|
]);
|
|
148
149
|
class ProcessHandle {
|
|
149
150
|
runner;
|
package/dist/drivers/store.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 外部 Agent 的会话引用与记账(docs/wave5-plan.md §5.4 记账 / 敏感数据,session-format 登记)。[W5-E]
|
|
2
|
+
* 外部 Agent 的会话引用与记账(docs/history/wave5-plan.md §5.4 记账 / 敏感数据,session-format 登记)。[W5-E]
|
|
3
3
|
*
|
|
4
4
|
* - `custom{ama.agent-session}`:`{ agent, runner, sessionId, cwd?, taskId? }`——外部 CLI 自己的
|
|
5
5
|
* 会话 id,续聊(`taskId` / resume)用;不含原始事件与转录。
|
package/dist/drivers/store.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 外部 Agent 的会话引用与记账(docs/wave5-plan.md §5.4 记账 / 敏感数据,session-format 登记)。[W5-E]
|
|
2
|
+
* 外部 Agent 的会话引用与记账(docs/history/wave5-plan.md §5.4 记账 / 敏感数据,session-format 登记)。[W5-E]
|
|
3
3
|
*
|
|
4
4
|
* - `custom{ama.agent-session}`:`{ agent, runner, sessionId, cwd?, taskId? }`——外部 CLI 自己的
|
|
5
5
|
* 会话 id,续聊(`taskId` / resume)用;不含原始事件与转录。
|
package/dist/drivers/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 外部 Agent 驱动契约(docs/wave5-plan.md §5.1–§5.3,D14)。[W5-C0] 契约文件,实现归 W5-E。
|
|
2
|
+
* 外部 Agent 驱动契约(docs/history/wave5-plan.md §5.1–§5.3,D14)。[W5-C0] 契约文件,实现归 W5-E。
|
|
3
3
|
*
|
|
4
4
|
* 内部词汇 = ACP v1 子集:各家原生协议(Claude stream-json、Codex app-server、一次性打印模式)
|
|
5
5
|
* 都映射成 `DriverEvent`;权限请求以 `DriverPermissionRequest` 交给 ama 的 broker 链——**只交给人,
|
|
@@ -20,7 +20,7 @@ export interface DriverCapabilities {
|
|
|
20
20
|
usage: "tokens" | "usd" | "requests" | "none";
|
|
21
21
|
images: boolean;
|
|
22
22
|
}
|
|
23
|
-
export type DriverKind = "acp" | "acp-adapter" | "claude-stream" | "codex-app-server" | "oneshot" | "host";
|
|
23
|
+
export type DriverKind = "acp" | "acp-adapter" | "claude-stream" | "codex-app-server" | "pi-rpc" | "oneshot" | "host";
|
|
24
24
|
export interface DriverProbe {
|
|
25
25
|
installed: boolean;
|
|
26
26
|
version?: string;
|
package/dist/drivers/types.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 外部 Agent 驱动契约(docs/wave5-plan.md §5.1–§5.3,D14)。[W5-C0] 契约文件,实现归 W5-E。
|
|
2
|
+
* 外部 Agent 驱动契约(docs/history/wave5-plan.md §5.1–§5.3,D14)。[W5-C0] 契约文件,实现归 W5-E。
|
|
3
3
|
*
|
|
4
4
|
* 内部词汇 = ACP v1 子集:各家原生协议(Claude stream-json、Codex app-server、一次性打印模式)
|
|
5
5
|
* 都映射成 `DriverEvent`;权限请求以 `DriverPermissionRequest` 交给 ama 的 broker 链——**只交给人,
|
package/dist/git/info.d.ts
CHANGED
package/dist/git/info.js
CHANGED
package/dist/host/api-impl.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* 事件总线 `AgentEventBus` 由 bootstrap 创建并交给 AgentSession 发事件;处理器只观察,
|
|
7
7
|
* 抛错记日志;`emit` 等待全部处理器(`session_shutdown` 需要被 await)。
|
|
8
8
|
*
|
|
9
|
-
* [W5-EG] `runners.provide`(docs/wave5-plan.md §5.5,D17):宿主注入的 runner 进本适配器的
|
|
9
|
+
* [W5-EG] `runners.provide`(docs/history/wave5-plan.md §5.5,D17):宿主注入的 runner 进本适配器的
|
|
10
10
|
* {@link HostRunnerRegistry}(跨会话共享),每个主会话的外部 Agent 入口(agents/external.ts)经
|
|
11
11
|
* {@link hostRunnersOf} 取到它;有宿主时 ama 不自 spawn 外部 CLI,只认这里注入的。
|
|
12
12
|
*/
|
package/dist/host/api-impl.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* 事件总线 `AgentEventBus` 由 bootstrap 创建并交给 AgentSession 发事件;处理器只观察,
|
|
7
7
|
* 抛错记日志;`emit` 等待全部处理器(`session_shutdown` 需要被 await)。
|
|
8
8
|
*
|
|
9
|
-
* [W5-EG] `runners.provide`(docs/wave5-plan.md §5.5,D17):宿主注入的 runner 进本适配器的
|
|
9
|
+
* [W5-EG] `runners.provide`(docs/history/wave5-plan.md §5.5,D17):宿主注入的 runner 进本适配器的
|
|
10
10
|
* {@link HostRunnerRegistry}(跨会话共享),每个主会话的外部 Agent 入口(agents/external.ts)经
|
|
11
11
|
* {@link hostRunnersOf} 取到它;有宿主时 ama 不自 spawn 外部 CLI,只认这里注入的。
|
|
12
12
|
*/
|