@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
package/dist/bundle/ama.cjs
CHANGED
|
@@ -41,7 +41,7 @@ var AMA_VERSION;
|
|
|
41
41
|
var init_version = __esm({
|
|
42
42
|
"src/version.ts"() {
|
|
43
43
|
"use strict";
|
|
44
|
-
AMA_VERSION = true ? "0.
|
|
44
|
+
AMA_VERSION = true ? "0.8.1" : readPackageVersion();
|
|
45
45
|
}
|
|
46
46
|
});
|
|
47
47
|
|
|
@@ -3712,8 +3712,8 @@ var init_config_keys = __esm({
|
|
|
3712
3712
|
version: "Config file format version; always 1",
|
|
3713
3713
|
defaultModel: "Default model provider/model or provider/model@channel; when unset it is picked automatically (ama config show shows which one and why)",
|
|
3714
3714
|
thinkingLevel: "Thinking level",
|
|
3715
|
-
providers: "Custom providers and overrides of built-in providers (docs/providers.md)",
|
|
3716
|
-
permission: "Permissions (docs/permissions.md)",
|
|
3715
|
+
providers: "Custom providers and overrides of built-in providers (docs/guides/providers.md)",
|
|
3716
|
+
permission: "Permissions (docs/guides/permissions.md)",
|
|
3717
3717
|
"permission.mode": "Permission mode; project level can only make it stricter",
|
|
3718
3718
|
"permission.allow": "Allow rules, e.g. bash(npm test); cannot be added at project level",
|
|
3719
3719
|
"permission.deny": "Deny rules, e.g. write(**/.env); accumulated across levels",
|
|
@@ -3740,7 +3740,7 @@ var init_config_keys = __esm({
|
|
|
3740
3740
|
"tools.maxToolResultChars": "Character limit for one tool result in the context; beyond it head and tail are kept",
|
|
3741
3741
|
"tools.bashTimeoutMs": "Default bash timeout (ms; overridable per call, max 600000)",
|
|
3742
3742
|
"tools.disabled": "Disabled tool names; accumulated across levels",
|
|
3743
|
-
codemode: "codemode: the model writes scripts that call tools in batches (docs/codemode.md)",
|
|
3743
|
+
codemode: "codemode: the model writes scripts that call tools in batches (docs/guides/codemode.md)",
|
|
3744
3744
|
"codemode.mode": "off | on | only; when unset it follows the preset: default → on (Node ≥ 25; Node 22 / 24 → off), codemode-only → only, minimal / coordinator → off; project level only accepts off",
|
|
3745
3745
|
"codemode.inlineBudget": "Budget (estimated tokens) for inlining tool declarations in the description in only mode; beyond it only names are listed",
|
|
3746
3746
|
"codemode.requireStrict": "true: disable codemode when the runtime Node does not isolate the network (Node 22 / 24)",
|
|
@@ -3764,7 +3764,7 @@ var init_config_keys = __esm({
|
|
|
3764
3764
|
"ui.language": "Interface language: auto decides from LC_ALL / LC_MESSAGES / LANG (zh* is Chinese, anything else English), zh, en; AMA_LANG and --lang override; affects the interface only, text sent to the model is always English",
|
|
3765
3765
|
"ui.replyLanguage": "Reply language for the model (e.g. Chinese): one English rule is appended to the end of the rules section at session start; zero-byte change when unset; user level only (effective from wave 6)",
|
|
3766
3766
|
"ui.agentBar": "Agent bar (sub-agent list above the status line): auto shows it while tasks exist, off hides it; press ↓ on an empty input to enter it",
|
|
3767
|
-
memory: "Cross-session memory (docs/memory.md): off by default, requests are byte-identical while off; project level can only set enabled: false (effective from wave 6 W6-M)",
|
|
3767
|
+
memory: "Cross-session memory (docs/guides/memory.md): off by default, requests are byte-identical while off; project level can only set enabled: false (effective from wave 6 W6-M)",
|
|
3768
3768
|
"memory.enabled": "Master switch; --memory / --no-memory and AMA_MEMORY=0|1 override",
|
|
3769
3769
|
"memory.scopes": "Enabled scopes: user (data directory, across projects), project (keyed by a hash of the repository path)",
|
|
3770
3770
|
"memory.indexMaxBytes": "Per-scope limit for the index in the system prompt (bytes); truncated by update time beyond it",
|
|
@@ -3790,11 +3790,11 @@ var init_config_keys = __esm({
|
|
|
3790
3790
|
"cache.minSavingsUsd": "Minimum expected savings (USD) for warming",
|
|
3791
3791
|
"cache.missNotices": "Show cache misses and remaining context in the message area",
|
|
3792
3792
|
"cache.warmSubagents": "Also warm sub-sessions (task)",
|
|
3793
|
-
checkpoints: 'Checkpoints: file backups used to roll back code (docs/sessions.md "Checkpoints and file backups")',
|
|
3793
|
+
checkpoints: 'Checkpoints: file backups used to roll back code (docs/guides/sessions.md "Checkpoints and file backups")',
|
|
3794
3794
|
"checkpoints.mode": "tools: track files changed by edit / write; shadow-git: also snapshot the whole working directory with a shadow git so direct changes (bash etc.) can be rolled back too (needs git; large directories fall back to tools); off: disabled; AMA_CHECKPOINTS overrides; project level only accepts off",
|
|
3795
3795
|
"checkpoints.maxFileBytes": "Backup limit for a single file (bytes); larger files are not backed up and rollback reports them as unrecoverable; project level can only lower it",
|
|
3796
3796
|
"checkpoints.keep": "Number of recent checkpoints available for rollback; older ones are no longer listed; user level / profile only",
|
|
3797
|
-
sandbox: 'OS-level sandbox (docs/sandbox.md); user level / profile only, project level only accepts network: "deny"',
|
|
3797
|
+
sandbox: 'OS-level sandbox (docs/guides/sandbox.md); user level / profile only, project level only accepts network: "deny"',
|
|
3798
3798
|
"sandbox.enabled": "auto: use macOS sandbox-exec / Linux bwrap or unshare when available (codemode child processes are denied network and writes; this isolates codemode's network on Node 22 / 24); off: not used; AMA_SANDBOX=off overrides",
|
|
3799
3799
|
"sandbox.bash": "auto: run bash through sandbox-exec / bwrap (unshare does not count), writes limited to the workspace, temp dir, output dir and sandbox.writable, and sandboxed commands need no approval in default mode; off: not used; user level / profile only",
|
|
3800
3800
|
"sandbox.network": "Network inside the bash sandbox: deny blocks it (required for approval-free sandboxed commands); allow permits network but writes stay limited and approval works as usual; project level can only set deny",
|
|
@@ -3841,8 +3841,8 @@ var init_config_keys = __esm({
|
|
|
3841
3841
|
version: "配置文件格式版本,固定为 1",
|
|
3842
3842
|
defaultModel: "缺省模型 provider/model 或 provider/model@channel;不写时零配置自动选择(ama config show 显示选了谁、为什么)",
|
|
3843
3843
|
thinkingLevel: "思考强度",
|
|
3844
|
-
providers: "自定义供应商与对内置供应商的覆盖(docs/providers.md)",
|
|
3845
|
-
permission: "权限(docs/permissions.md)",
|
|
3844
|
+
providers: "自定义供应商与对内置供应商的覆盖(docs/guides/providers.md)",
|
|
3845
|
+
permission: "权限(docs/guides/permissions.md)",
|
|
3846
3846
|
"permission.mode": "权限模式;项目级只能更严",
|
|
3847
3847
|
"permission.allow": "放行规则,如 bash(npm test);项目级不能加",
|
|
3848
3848
|
"permission.deny": "拒绝规则,如 write(**/.env);各层累加",
|
|
@@ -3869,7 +3869,7 @@ var init_config_keys = __esm({
|
|
|
3869
3869
|
"tools.maxToolResultChars": "单条工具结果进上下文的字符上限,超出保留首尾",
|
|
3870
3870
|
"tools.bashTimeoutMs": "bash 缺省超时(毫秒,单次调用可覆盖,最大 600000)",
|
|
3871
3871
|
"tools.disabled": "禁用的工具名;各层累加",
|
|
3872
|
-
codemode: "codemode:模型写脚本批量调用工具(docs/codemode.md)",
|
|
3872
|
+
codemode: "codemode:模型写脚本批量调用工具(docs/guides/codemode.md)",
|
|
3873
3873
|
"codemode.mode": "off | on | only;不写时跟随预设:default → on(Node ≥ 25;Node 22 / 24 → off)、codemode-only → only、minimal / coordinator → off;项目级只接受 off",
|
|
3874
3874
|
"codemode.inlineBudget": "only 模式在描述里内联工具声明的预算(估算 token),超出只列名字",
|
|
3875
3875
|
"codemode.requireStrict": "true:运行时 Node 不隔离网络(Node 22 / 24)时直接禁用 codemode",
|
|
@@ -3893,7 +3893,7 @@ var init_config_keys = __esm({
|
|
|
3893
3893
|
"ui.language": "界面语言:auto 按 LC_ALL / LC_MESSAGES / LANG 判断(zh* 为中文,其余英文),zh,en;AMA_LANG、--lang 覆盖;只影响界面,发给模型的文本固定英文",
|
|
3894
3894
|
"ui.replyLanguage": "模型回复语言(如 Chinese):会话开始在 rules 节末尾追加一句英文规则;不设时零字节变化;只认用户级(第六波起生效)",
|
|
3895
3895
|
"ui.agentBar": "Agent 栏(状态行上方的子 Agent 列表):auto 有任务时显示,off 不显示;空输入时按 ↓ 进入",
|
|
3896
|
-
memory: "跨会话记忆(docs/memory.md):缺省关闭,关闭时请求逐字节不变;项目级只能设 enabled: false(第六波 W6-M 起生效)",
|
|
3896
|
+
memory: "跨会话记忆(docs/guides/memory.md):缺省关闭,关闭时请求逐字节不变;项目级只能设 enabled: false(第六波 W6-M 起生效)",
|
|
3897
3897
|
"memory.enabled": "总开关;--memory / --no-memory、AMA_MEMORY=0|1 覆盖",
|
|
3898
3898
|
"memory.scopes": "启用的作用域:user(数据目录,跨项目)、project(按仓库路径哈希)",
|
|
3899
3899
|
"memory.indexMaxBytes": "每作用域索引进系统提示的上限(字节),超出按更新时间截断",
|
|
@@ -3919,11 +3919,11 @@ var init_config_keys = __esm({
|
|
|
3919
3919
|
"cache.minSavingsUsd": "保温的最低期望节省(美元)",
|
|
3920
3920
|
"cache.missNotices": "在消息区提示缓存未命中与上下文余量",
|
|
3921
3921
|
"cache.warmSubagents": "子会话(task)也保温",
|
|
3922
|
-
checkpoints: "检查点:回滚代码用的文件备份(docs/sessions.md「检查点与文件备份」)",
|
|
3922
|
+
checkpoints: "检查点:回滚代码用的文件备份(docs/guides/sessions.md「检查点与文件备份」)",
|
|
3923
3923
|
"checkpoints.mode": "tools:跟踪 edit / write 改过的文件;shadow-git:另用影子 git 快照整个工作目录,bash 等直接改动也能回滚(需要 git,大目录自动降级为 tools);off:关闭;AMA_CHECKPOINTS 覆盖;项目级只接受 off",
|
|
3924
3924
|
"checkpoints.maxFileBytes": "单个文件的备份上限(字节),超出不备份、回滚时报告无法恢复;项目级只能调小",
|
|
3925
3925
|
"checkpoints.keep": "可回滚的最近检查点数,更早的不再列为回滚点;只认用户级 / profile",
|
|
3926
|
-
sandbox: '操作系统级沙箱(docs/sandbox.md);只认用户级 / profile,项目级只接受 network: "deny"',
|
|
3926
|
+
sandbox: '操作系统级沙箱(docs/guides/sandbox.md);只认用户级 / profile,项目级只接受 network: "deny"',
|
|
3927
3927
|
"sandbox.enabled": "auto:探测到可用的 macOS sandbox-exec / Linux bwrap、unshare 就用(codemode 子进程拒绝网络与写入;Node 22 / 24 上 codemode 因此网络隔离);off:不用;AMA_SANDBOX=off 覆盖",
|
|
3928
3928
|
"sandbox.bash": "auto:bash 经 sandbox-exec / bwrap 运行(unshare 不算),写入只限工作区、临时目录、输出目录与 sandbox.writable,default 模式下沙箱内命令免审批;off:不用;只认用户级 / profile",
|
|
3929
3929
|
"sandbox.network": "bash 沙箱里的网络:deny 拒绝(沙箱内免审批的前提);allow 允许联网但写入仍受限、照常审批;项目级只能设 deny",
|
|
@@ -4085,7 +4085,7 @@ var init_config = __esm({
|
|
|
4085
4085
|
/** config.schema.json 里供应商内部字段的说明(顶层与各段的键用 `keys`)。 */
|
|
4086
4086
|
jsonSchema: {
|
|
4087
4087
|
api: "Protocol",
|
|
4088
|
-
compat: 'Protocol compatibility switches (docs/providers.md "compat")',
|
|
4088
|
+
compat: 'Protocol compatibility switches (docs/guides/providers.md "compat")',
|
|
4089
4089
|
modelId: "Model id (the name sent upstream)",
|
|
4090
4090
|
modelBaseUrl: "Overrides the channel / provider address",
|
|
4091
4091
|
contextWindow: "Context tokens; filled from models.dev by default, not guessed when there is no match",
|
|
@@ -4201,7 +4201,7 @@ var init_config = __esm({
|
|
|
4201
4201
|
},
|
|
4202
4202
|
jsonSchema: {
|
|
4203
4203
|
api: "协议",
|
|
4204
|
-
compat: "协议兼容开关(docs/providers.md「compat」)",
|
|
4204
|
+
compat: "协议兼容开关(docs/guides/providers.md「compat」)",
|
|
4205
4205
|
modelId: "模型 id(发给上游的名字)",
|
|
4206
4206
|
modelBaseUrl: "覆盖渠道 / 供应商的地址",
|
|
4207
4207
|
contextWindow: "上下文 token;缺省从 models.dev 补,匹配不到不猜",
|
|
@@ -4241,6 +4241,7 @@ var init_drivers = __esm({
|
|
|
4241
4241
|
resumeUnsupported: (agent) => `${agent} cannot resume sessions; started a new one`,
|
|
4242
4242
|
resumeNotFound: (agent, id) => `${agent} cannot find session ${id}; started a new one`,
|
|
4243
4243
|
noMatchingMode: (agent, mode) => `${agent} has no "${mode}" mode; running in its own default mode (actions that need approval still come to you)`,
|
|
4244
|
+
noMatchingModel: (agent, model) => `${agent} does not offer model "${model}"; using its own default model`,
|
|
4244
4245
|
noImages: (agent) => `${agent} does not accept images; omitted`,
|
|
4245
4246
|
noImagesDriver: (agent) => `the ${agent} driver does not pass images yet; omitted`,
|
|
4246
4247
|
noImagesOneshot: (agent) => `${agent} one-shot mode does not pass images; omitted`,
|
|
@@ -4251,6 +4252,7 @@ var init_drivers = __esm({
|
|
|
4251
4252
|
error: (agent, message, retrying) => `${agent}: ${message}${retrying ? " (retrying)" : ""}`,
|
|
4252
4253
|
askedQuestion: (agent, tool) => `${agent} wants to ask you a question (${tool}); ama does not answer for you and asked it to put the question in its final reply`,
|
|
4253
4254
|
askedQuestionCodex: (agent) => `${agent} wants to ask you a question; ama does not answer for you — have it put the question in its final reply`,
|
|
4255
|
+
extensionDialog: (agent, title) => `${agent}: an extension asked for input (${title}); ama does not answer for you, cancelled`,
|
|
4254
4256
|
mcpElicitation: (agent) => `${agent}'s MCP server asked for input; ama does not answer for you, cancelled`
|
|
4255
4257
|
},
|
|
4256
4258
|
/** Hook 配置与输出的警告(给人看;回给模型的阻止理由固定英文)。 */
|
|
@@ -4300,6 +4302,7 @@ var init_drivers = __esm({
|
|
|
4300
4302
|
resumeUnsupported: (agent) => `${agent} 不支持续接会话,已新开`,
|
|
4301
4303
|
resumeNotFound: (agent, id) => `${agent} 找不到会话 ${id},已新开`,
|
|
4302
4304
|
noMatchingMode: (agent, mode) => `${agent} 没有「${mode}」模式,按它自己的缺省模式运行(需要授权的操作仍交给你)`,
|
|
4305
|
+
noMatchingModel: (agent, model) => `${agent} 没有模型「${model}」,按它自己的缺省模型运行`,
|
|
4303
4306
|
noImages: (agent) => `${agent} 不接受图片,已省略`,
|
|
4304
4307
|
noImagesDriver: (agent) => `${agent} 驱动暂不传图片,已省略`,
|
|
4305
4308
|
noImagesOneshot: (agent) => `${agent} 一次性模式不传图片,已省略`,
|
|
@@ -4310,6 +4313,7 @@ var init_drivers = __esm({
|
|
|
4310
4313
|
error: (agent, message, retrying) => `${agent}:${message}${retrying ? "(重试中)" : ""}`,
|
|
4311
4314
|
askedQuestion: (agent, tool) => `${agent} 想向你提问(${tool});ama 不代答,已请它把问题写进最终回复`,
|
|
4312
4315
|
askedQuestionCodex: (agent) => `${agent} 想向你提问;ama 不代答,请让它把问题写进最终回复`,
|
|
4316
|
+
extensionDialog: (agent, title) => `${agent}:扩展请求输入(${title});ama 不代答,已取消`,
|
|
4313
4317
|
mcpElicitation: (agent) => `${agent} 的 MCP 服务器请求输入;ama 不代答,已取消`
|
|
4314
4318
|
},
|
|
4315
4319
|
hooks: {
|
|
@@ -5359,6 +5363,7 @@ Then paste the full URL from the address bar (http://127.0.0.1:…/auth/callback
|
|
|
5359
5363
|
},
|
|
5360
5364
|
request: {
|
|
5361
5365
|
notEligible: "this ChatGPT account cannot share plan usage with ama (403 subscription_sharing_user_not_eligible). Possible causes:\n 1. Plan: plan usage is shared with Plus / Pro only\n 2. Workspace account: Team / Enterprise / Edu workspaces may not offer it\n 3. Region restriction, or not yet rolled out during the preview (most likely when a Pro account still gets this error)\nYou can sign in the other way instead: ama auth login chatgpt --flavor codex",
|
|
5366
|
+
modelUnavailable: (model) => `${model} is not available to this ChatGPT account (400 from the codex backend). The backend's model list changes over time: run ama models discover chatgpt to refresh it, then pick a listed model with /model or --model`,
|
|
5362
5367
|
flavorMismatch: (current3, ref, pinned) => `signed in with ${current3}, but ${ref} pins the @${pinned} channel. Drop @${pinned} so the channel follows the sign-in, or run ama auth login chatgpt --flavor ${pinned}`
|
|
5363
5368
|
},
|
|
5364
5369
|
errors: {
|
|
@@ -5467,6 +5472,7 @@ Then paste the full URL from the address bar (http://127.0.0.1:…/auth/callback
|
|
|
5467
5472
|
},
|
|
5468
5473
|
request: {
|
|
5469
5474
|
notEligible: "这个 ChatGPT 账户不能把套餐额度共享给 ama(403 subscription_sharing_user_not_eligible)。可能的原因:\n 1. 账户套餐:额度共享只对 Plus / Pro 开放\n 2. 工作空间账户:Team / Enterprise / Edu 工作空间可能未开放\n 3. 地区受限,或预览期尚未开放(Pro 账户仍报此错时最可能是这一条)\n可以改用另一种登录方式:ama auth login chatgpt --flavor codex",
|
|
5475
|
+
modelUnavailable: (model) => `${model} 在这个 ChatGPT 账户下不可用(codex 后端回 400)。后端的模型表会变化:运行 ama models discover chatgpt 刷新,再用 /model 或 --model 选表里的模型`,
|
|
5470
5476
|
flavorMismatch: (current3, ref, pinned) => `当前以 ${current3} 方式登录,但 ${ref} 显式指定了 @${pinned} 渠道。去掉 @${pinned} 让渠道跟随登录方式,或运行 ama auth login chatgpt --flavor ${pinned}`
|
|
5471
5477
|
},
|
|
5472
5478
|
errors: {
|
|
@@ -7129,7 +7135,7 @@ var init_builtin = __esm({
|
|
|
7129
7135
|
baseUrl: "https://openrouter.ai/api/v1",
|
|
7130
7136
|
envKeys: ["OPENROUTER_API_KEY", "AMA_API_KEY_OPENROUTER"],
|
|
7131
7137
|
headers: {
|
|
7132
|
-
"HTTP-Referer": "https://github.com/
|
|
7138
|
+
"HTTP-Referer": "https://github.com/AMA-Link/armadra-agent",
|
|
7133
7139
|
"X-Title": "ama"
|
|
7134
7140
|
},
|
|
7135
7141
|
requiresApiKey: true
|
|
@@ -7229,7 +7235,7 @@ var init_builtin = __esm({
|
|
|
7229
7235
|
requiresApiKey: true
|
|
7230
7236
|
},
|
|
7231
7237
|
{
|
|
7232
|
-
// [W6-O] ChatGPT 订阅(docs/wave6-plan.md §4、D14):`ama auth login chatgpt` 写 auth.json 的 OAuth 条目;
|
|
7238
|
+
// [W6-O] ChatGPT 订阅(docs/history/wave6-plan.md §4、D14):`ama auth login chatgpt` 写 auth.json 的 OAuth 条目;
|
|
7233
7239
|
// 缺省渠道在组装时按条目的 flavor 定(compose-providers.ts)。模型表为空:`chatgpt/<slug>` 任意接受,
|
|
7234
7240
|
// `ama models discover chatgpt` 列出账户可用的 slug。缓存只有 prompt_cache_key(无 24h / 30m 显式缓存)。
|
|
7235
7241
|
id: "chatgpt",
|
|
@@ -22667,7 +22673,7 @@ var init_system_prompt = __esm({
|
|
|
22667
22673
|
"rules",
|
|
22668
22674
|
"project_context",
|
|
22669
22675
|
"skills",
|
|
22670
|
-
// [W6-C0] 记忆索引(W6-M,docs/wave6-plan.md §3.4);未开启时为 undefined,字节不变
|
|
22676
|
+
// [W6-C0] 记忆索引(W6-M,docs/history/wave6-plan.md §3.4);未开启时为 undefined,字节不变
|
|
22671
22677
|
"memory",
|
|
22672
22678
|
"hooks",
|
|
22673
22679
|
"cwd",
|
|
@@ -29410,7 +29416,7 @@ var init_session2 = __esm({
|
|
|
29410
29416
|
return Promise.reject(new AmaError("busy", "cannot compact while running"));
|
|
29411
29417
|
return this.startCycle((signal) => this.compaction.compactManual(instructions, signal, cutAt));
|
|
29412
29418
|
}
|
|
29413
|
-
// [RW-B] 回滚(docs/rewind-plan.md §3;编排与校验在 session-rewind.ts)
|
|
29419
|
+
// [RW-B] 回滚(docs/history/rewind-plan.md §3;编排与校验在 session-rewind.ts)
|
|
29414
29420
|
rewindPoints = () => this.rewinder.points();
|
|
29415
29421
|
rewind = (request) => this.rewinder.rewind(request);
|
|
29416
29422
|
summarizeFrom = (entryId, instructions) => this.rewinder.summarizeFrom(entryId, instructions);
|
|
@@ -33224,6 +33230,16 @@ function candidateCapabilities(c) {
|
|
|
33224
33230
|
usage: "tokens",
|
|
33225
33231
|
images: false
|
|
33226
33232
|
};
|
|
33233
|
+
case "pi-rpc":
|
|
33234
|
+
return {
|
|
33235
|
+
resume: "resume",
|
|
33236
|
+
list: false,
|
|
33237
|
+
permissions: "interactive",
|
|
33238
|
+
steer: true,
|
|
33239
|
+
modes: ALL_MODES,
|
|
33240
|
+
usage: "usd",
|
|
33241
|
+
images: true
|
|
33242
|
+
};
|
|
33227
33243
|
case "oneshot":
|
|
33228
33244
|
return {
|
|
33229
33245
|
resume: c.oneshot === "gemini" ? "none" : "resume",
|
|
@@ -33247,7 +33263,7 @@ function candidateCapabilities(c) {
|
|
|
33247
33263
|
};
|
|
33248
33264
|
}
|
|
33249
33265
|
}
|
|
33250
|
-
var ALL_MODES, DRIVER_CATALOG;
|
|
33266
|
+
var ALL_MODES, CLAUDE_ACP_MODES, CODEX_ACP_MODES, COPILOT_MODE, COPILOT_MODES, CURSOR_MODES, DRIVER_CATALOG;
|
|
33251
33267
|
var init_catalog4 = __esm({
|
|
33252
33268
|
"src/drivers/catalog.ts"() {
|
|
33253
33269
|
"use strict";
|
|
@@ -33259,12 +33275,48 @@ var init_catalog4 = __esm({
|
|
|
33259
33275
|
"auto",
|
|
33260
33276
|
"full-auto"
|
|
33261
33277
|
];
|
|
33278
|
+
CLAUDE_ACP_MODES = {
|
|
33279
|
+
plan: "plan",
|
|
33280
|
+
default: "default",
|
|
33281
|
+
"auto-edit": "acceptEdits",
|
|
33282
|
+
auto: "auto",
|
|
33283
|
+
"full-auto": "auto"
|
|
33284
|
+
};
|
|
33285
|
+
CODEX_ACP_MODES = {
|
|
33286
|
+
plan: "read-only",
|
|
33287
|
+
default: "read-only",
|
|
33288
|
+
"auto-edit": "workspace-write",
|
|
33289
|
+
auto: "agent",
|
|
33290
|
+
"full-auto": "agent"
|
|
33291
|
+
};
|
|
33292
|
+
COPILOT_MODE = "https://agentclientprotocol.com/protocol/session-modes#";
|
|
33293
|
+
COPILOT_MODES = {
|
|
33294
|
+
plan: `${COPILOT_MODE}plan`,
|
|
33295
|
+
default: `${COPILOT_MODE}agent`,
|
|
33296
|
+
"auto-edit": `${COPILOT_MODE}agent`,
|
|
33297
|
+
auto: `${COPILOT_MODE}agent`,
|
|
33298
|
+
"full-auto": `${COPILOT_MODE}agent`
|
|
33299
|
+
};
|
|
33300
|
+
CURSOR_MODES = {
|
|
33301
|
+
plan: "plan",
|
|
33302
|
+
default: "agent",
|
|
33303
|
+
"auto-edit": "agent",
|
|
33304
|
+
auto: "agent",
|
|
33305
|
+
"full-auto": "agent"
|
|
33306
|
+
};
|
|
33262
33307
|
DRIVER_CATALOG = [
|
|
33263
33308
|
{
|
|
33264
33309
|
agentId: "claude",
|
|
33265
33310
|
label: "Claude Code",
|
|
33266
33311
|
candidates: [
|
|
33267
|
-
{
|
|
33312
|
+
{
|
|
33313
|
+
kind: "acp-adapter",
|
|
33314
|
+
program: "claude-agent-acp",
|
|
33315
|
+
args: [],
|
|
33316
|
+
verified: ">=0.89.0 <1.0.0",
|
|
33317
|
+
usage: "usd",
|
|
33318
|
+
modes: CLAUDE_ACP_MODES
|
|
33319
|
+
},
|
|
33268
33320
|
{
|
|
33269
33321
|
kind: "claude-stream",
|
|
33270
33322
|
program: "claude",
|
|
@@ -33279,7 +33331,14 @@ var init_catalog4 = __esm({
|
|
|
33279
33331
|
agentId: "codex",
|
|
33280
33332
|
label: "Codex",
|
|
33281
33333
|
candidates: [
|
|
33282
|
-
{
|
|
33334
|
+
{
|
|
33335
|
+
kind: "acp-adapter",
|
|
33336
|
+
program: "codex-acp",
|
|
33337
|
+
args: [],
|
|
33338
|
+
verified: ">=2.2.0 <3.0.0",
|
|
33339
|
+
usage: "tokens",
|
|
33340
|
+
modes: CODEX_ACP_MODES
|
|
33341
|
+
},
|
|
33283
33342
|
{
|
|
33284
33343
|
kind: "codex-app-server",
|
|
33285
33344
|
program: "codex",
|
|
@@ -33312,15 +33371,44 @@ var init_catalog4 = __esm({
|
|
|
33312
33371
|
{
|
|
33313
33372
|
agentId: "opencode",
|
|
33314
33373
|
label: "OpenCode",
|
|
33315
|
-
candidates: [{ kind: "acp", program: "opencode", args: ["acp"] }]
|
|
33374
|
+
candidates: [{ kind: "acp", program: "opencode", args: ["acp"], verified: ">=1.18.0 <2.0.0" }]
|
|
33316
33375
|
},
|
|
33317
33376
|
{
|
|
33318
33377
|
agentId: "copilot",
|
|
33319
33378
|
label: "GitHub Copilot CLI",
|
|
33320
33379
|
candidates: [
|
|
33321
|
-
{
|
|
33380
|
+
{
|
|
33381
|
+
kind: "acp",
|
|
33382
|
+
program: "copilot",
|
|
33383
|
+
args: ["--acp", "--stdio"],
|
|
33384
|
+
verified: ">=1.0.95 <2.0.0",
|
|
33385
|
+
usage: "requests",
|
|
33386
|
+
modes: COPILOT_MODES,
|
|
33387
|
+
acpUsage: "session"
|
|
33388
|
+
}
|
|
33389
|
+
]
|
|
33390
|
+
},
|
|
33391
|
+
{
|
|
33392
|
+
agentId: "pi",
|
|
33393
|
+
label: "Pi",
|
|
33394
|
+
// 社区 ACP 适配器 pi-acp 不发 request_permission(pi 没有审批通道),会让工具不经人直接执行,不收录
|
|
33395
|
+
candidates: [
|
|
33396
|
+
{
|
|
33397
|
+
kind: "pi-rpc",
|
|
33398
|
+
program: "pi",
|
|
33399
|
+
args: ["--mode", "rpc"],
|
|
33400
|
+
verified: ">=1.1.0 <2.0.0",
|
|
33401
|
+
usage: "usd"
|
|
33402
|
+
}
|
|
33322
33403
|
]
|
|
33323
33404
|
},
|
|
33405
|
+
{
|
|
33406
|
+
agentId: "cursor",
|
|
33407
|
+
label: "Cursor CLI",
|
|
33408
|
+
// 未实测(本机未装):按官方文档 `cursor-agent acp`,模式 agent / plan / ask;`cursor/ask_question`
|
|
33409
|
+
// 等阻塞式扩展方法 ama 不实现(回 method not found,不代答)
|
|
33410
|
+
candidates: [{ kind: "acp", program: "cursor-agent", args: ["acp"], modes: CURSOR_MODES }]
|
|
33411
|
+
},
|
|
33324
33412
|
{
|
|
33325
33413
|
agentId: "goose",
|
|
33326
33414
|
label: "Goose",
|
|
@@ -34042,6 +34130,24 @@ function pushAcpUpdate(update, turn) {
|
|
|
34042
34130
|
return;
|
|
34043
34131
|
}
|
|
34044
34132
|
}
|
|
34133
|
+
function acpTurnUsage(usage, previous) {
|
|
34134
|
+
const diff = (key) => {
|
|
34135
|
+
const now = usage[key];
|
|
34136
|
+
if (now === void 0) return void 0;
|
|
34137
|
+
return previous === void 0 ? now : Math.max(0, now - (previous[key] ?? 0));
|
|
34138
|
+
};
|
|
34139
|
+
const input2 = diff("inputTokens");
|
|
34140
|
+
const output = diff("outputTokens");
|
|
34141
|
+
const cacheRead = diff("cachedReadTokens");
|
|
34142
|
+
const { totalTokens: total, inputTokens: rawIn = 0, outputTokens: rawOut = 0 } = usage;
|
|
34143
|
+
const cached = usage.cachedReadTokens ?? 0;
|
|
34144
|
+
const includesCache = total !== void 0 && cached > 0 && Math.abs(total - (rawIn + rawOut)) < Math.abs(total - (rawIn + rawOut + cached));
|
|
34145
|
+
return {
|
|
34146
|
+
...input2 !== void 0 ? { input: includesCache ? Math.max(0, input2 - (cacheRead ?? 0)) : input2 } : {},
|
|
34147
|
+
...output !== void 0 ? { output } : {},
|
|
34148
|
+
...cacheRead !== void 0 ? { cacheRead } : {}
|
|
34149
|
+
};
|
|
34150
|
+
}
|
|
34045
34151
|
function wantedModeIds(mode, candidate) {
|
|
34046
34152
|
const wanted = [candidate.modes?.[mode] ?? mode];
|
|
34047
34153
|
if (mode === "allowlist") wanted.push(candidate.modes?.plan ?? "plan");
|
|
@@ -34062,6 +34168,14 @@ function pickConfigModeValue(mode, candidate, option2) {
|
|
|
34062
34168
|
);
|
|
34063
34169
|
return wantedModeIds(mode, candidate).find((id) => values.includes(id));
|
|
34064
34170
|
}
|
|
34171
|
+
function pickModelValue(model, options) {
|
|
34172
|
+
const option2 = options?.find((o) => o.category === "model" && o.type === "select");
|
|
34173
|
+
if (option2 === void 0) return void 0;
|
|
34174
|
+
const values = option2.options.flatMap((o) => "options" in o ? o.options : [o]);
|
|
34175
|
+
const lower = model.toLowerCase();
|
|
34176
|
+
const hit = values.find((v) => v.value === model) ?? values.find((v) => v.value.toLowerCase() === lower || v.name.toLowerCase() === lower) ?? values.find((v) => v.value.toLowerCase().split("/").at(-1) === lower);
|
|
34177
|
+
return hit === void 0 ? void 0 : { configId: option2.id, value: hit.value, current: option2.currentValue === hit.value };
|
|
34178
|
+
}
|
|
34065
34179
|
function authMethodText(method, command3) {
|
|
34066
34180
|
if (method.type !== "terminal") return method.name;
|
|
34067
34181
|
const words = [...command3, ...method.args ?? []].map(
|
|
@@ -34148,6 +34262,9 @@ var init_driver = __esm({
|
|
|
34148
34262
|
notices = [];
|
|
34149
34263
|
/** 本回合已发过 cancel。 */
|
|
34150
34264
|
cancelling = false;
|
|
34265
|
+
/** Agent 的 usage 是会话累计时,上一回合的原始值({@link acpTurnUsage})。 */
|
|
34266
|
+
usageTotals;
|
|
34267
|
+
cumulativeUsage = false;
|
|
34151
34268
|
get sessionId() {
|
|
34152
34269
|
return this.id;
|
|
34153
34270
|
}
|
|
@@ -34162,6 +34279,7 @@ var init_driver = __esm({
|
|
|
34162
34279
|
onProtocolError: (_line, reason) => this.deps.log?.("debug", `${this.agentId}: ${reason}`)
|
|
34163
34280
|
});
|
|
34164
34281
|
const signal = options.signal;
|
|
34282
|
+
this.cumulativeUsage = candidate.acpUsage === "session";
|
|
34165
34283
|
await this.client.initialize(signal);
|
|
34166
34284
|
let opened;
|
|
34167
34285
|
try {
|
|
@@ -34188,6 +34306,13 @@ var init_driver = __esm({
|
|
|
34188
34306
|
} else if (modes != null || modeOption !== void 0) {
|
|
34189
34307
|
this.notices.push(msg().drivers.agent.noMatchingMode(this.agentId, options.mode));
|
|
34190
34308
|
}
|
|
34309
|
+
if (options.model !== void 0) {
|
|
34310
|
+
const model = pickModelValue(options.model, opened.configOptions);
|
|
34311
|
+
if (model === void 0)
|
|
34312
|
+
this.notices.push(msg().drivers.agent.noMatchingModel(this.agentId, options.model));
|
|
34313
|
+
else if (!model.current)
|
|
34314
|
+
await this.client.setConfigOption(this.id, model.configId, model.value);
|
|
34315
|
+
}
|
|
34191
34316
|
}
|
|
34192
34317
|
/** 续聊优先 resume(不回放),其次 load(回放丢弃),都不行就新开;设好 `this.id`。 */
|
|
34193
34318
|
async openSession(options) {
|
|
@@ -34248,11 +34373,10 @@ var init_driver = __esm({
|
|
|
34248
34373
|
});
|
|
34249
34374
|
const usage = result.usage;
|
|
34250
34375
|
if (usage != null) {
|
|
34251
|
-
turn.mergeUsage(
|
|
34252
|
-
|
|
34253
|
-
|
|
34254
|
-
|
|
34255
|
-
});
|
|
34376
|
+
turn.mergeUsage(
|
|
34377
|
+
acpTurnUsage(usage, this.cumulativeUsage ? this.usageTotals ?? {} : void 0)
|
|
34378
|
+
);
|
|
34379
|
+
if (this.cumulativeUsage) this.usageTotals = usage;
|
|
34256
34380
|
}
|
|
34257
34381
|
return turn.result(result.stopReason);
|
|
34258
34382
|
} finally {
|
|
@@ -34361,6 +34485,26 @@ function claudePermissionMode(mode, manualName) {
|
|
|
34361
34485
|
return "auto";
|
|
34362
34486
|
}
|
|
34363
34487
|
}
|
|
34488
|
+
function claudeContextTokens(usage) {
|
|
34489
|
+
if (typeof usage !== "object" || usage === null) return void 0;
|
|
34490
|
+
const u = usage;
|
|
34491
|
+
let total = 0;
|
|
34492
|
+
for (const key of [
|
|
34493
|
+
"input_tokens",
|
|
34494
|
+
"cache_read_input_tokens",
|
|
34495
|
+
"cache_creation_input_tokens",
|
|
34496
|
+
"output_tokens"
|
|
34497
|
+
])
|
|
34498
|
+
if (typeof u[key] === "number") total += u[key];
|
|
34499
|
+
return total > 0 ? total : void 0;
|
|
34500
|
+
}
|
|
34501
|
+
function claudeContextWindow(result, model) {
|
|
34502
|
+
const entries = result.modelUsage ?? {};
|
|
34503
|
+
const hit = model !== void 0 ? entries[model]?.contextWindow : void 0;
|
|
34504
|
+
if (typeof hit === "number" && hit > 0) return hit;
|
|
34505
|
+
const windows = Object.values(entries).map((e) => e.contextWindow).filter((w) => typeof w === "number" && w > 0);
|
|
34506
|
+
return windows.length > 0 ? Math.max(...windows) : void 0;
|
|
34507
|
+
}
|
|
34364
34508
|
function claudeStopReason(result, interrupted) {
|
|
34365
34509
|
if (interrupted) return "cancelled";
|
|
34366
34510
|
switch (result.subtype) {
|
|
@@ -34521,6 +34665,8 @@ var init_claude_stream = __esm({
|
|
|
34521
34665
|
interrupted = false;
|
|
34522
34666
|
sawPartialText = false;
|
|
34523
34667
|
lastTotalCost = 0;
|
|
34668
|
+
/** 最近一条主线 assistant 消息的上下文占用与模型(result 里查窗口用)。 */
|
|
34669
|
+
context = {};
|
|
34524
34670
|
closed = false;
|
|
34525
34671
|
exited = false;
|
|
34526
34672
|
get sessionId() {
|
|
@@ -34612,6 +34758,13 @@ var init_claude_stream = __esm({
|
|
|
34612
34758
|
...u.cache_read_input_tokens !== void 0 ? { cacheRead: u.cache_read_input_tokens } : {},
|
|
34613
34759
|
...cost2 !== void 0 ? { costUsd: cost2 } : {}
|
|
34614
34760
|
});
|
|
34761
|
+
const window2 = claudeContextWindow(result, this.context.model);
|
|
34762
|
+
if (this.context.tokens !== void 0 || window2 !== void 0)
|
|
34763
|
+
turn.push({
|
|
34764
|
+
type: "usage",
|
|
34765
|
+
...this.context.tokens !== void 0 ? { contextTokens: this.context.tokens } : {},
|
|
34766
|
+
...window2 !== void 0 ? { contextWindow: window2 } : {}
|
|
34767
|
+
});
|
|
34615
34768
|
if (typeof result.result === "string" && result.result !== "") turn.setFinalText(result.result);
|
|
34616
34769
|
const denials = result.permission_denials?.length ?? 0;
|
|
34617
34770
|
if (denials > 0)
|
|
@@ -34729,6 +34882,12 @@ var init_claude_stream = __esm({
|
|
|
34729
34882
|
const turn = this.turn;
|
|
34730
34883
|
if (turn === void 0 || !Array.isArray(message["content"])) return;
|
|
34731
34884
|
const nested = typeof parent === "string" && parent !== "";
|
|
34885
|
+
const tokens = nested ? void 0 : claudeContextTokens(message["usage"]);
|
|
34886
|
+
if (tokens !== void 0)
|
|
34887
|
+
this.context = {
|
|
34888
|
+
tokens,
|
|
34889
|
+
...typeof message["model"] === "string" ? { model: message["model"] } : {}
|
|
34890
|
+
};
|
|
34732
34891
|
for (const block of message["content"]) {
|
|
34733
34892
|
if (block["type"] === "text" && !nested && !this.sawPartialText && typeof block["text"] === "string")
|
|
34734
34893
|
turn.push({ type: "message_delta", text: block["text"] });
|
|
@@ -35178,11 +35337,12 @@ var init_codex_app_server = __esm({
|
|
|
35178
35337
|
const start = this.tokensAtStart;
|
|
35179
35338
|
const end = this.tokensTotal;
|
|
35180
35339
|
if (end !== void 0) {
|
|
35340
|
+
const cacheRead = end.cachedInputTokens - (start?.cachedInputTokens ?? 0);
|
|
35181
35341
|
turn.push({
|
|
35182
35342
|
type: "usage",
|
|
35183
|
-
input: end.inputTokens - (start?.inputTokens ?? 0),
|
|
35343
|
+
input: end.inputTokens - (start?.inputTokens ?? 0) - cacheRead,
|
|
35184
35344
|
output: end.outputTokens - (start?.outputTokens ?? 0),
|
|
35185
|
-
cacheRead
|
|
35345
|
+
cacheRead,
|
|
35186
35346
|
...this.contextTokens !== void 0 ? { contextTokens: this.contextTokens } : {},
|
|
35187
35347
|
...this.contextWindow !== void 0 ? { contextWindow: this.contextWindow } : {}
|
|
35188
35348
|
});
|
|
@@ -35377,7 +35537,14 @@ function oneshotArgs(dialect, options, session, prompt) {
|
|
|
35377
35537
|
return args;
|
|
35378
35538
|
}
|
|
35379
35539
|
case "codex": {
|
|
35380
|
-
const common = [
|
|
35540
|
+
const common = [
|
|
35541
|
+
"--json",
|
|
35542
|
+
"--skip-git-repo-check",
|
|
35543
|
+
"-c",
|
|
35544
|
+
'sandbox_mode="read-only"',
|
|
35545
|
+
"-c",
|
|
35546
|
+
'approval_policy="never"'
|
|
35547
|
+
];
|
|
35381
35548
|
if (options.model !== void 0) common.push("-m", options.model);
|
|
35382
35549
|
return session.resume ? ["exec", "resume", session.id, ...common, "-"] : ["exec", ...common, "-"];
|
|
35383
35550
|
}
|
|
@@ -35597,9 +35764,10 @@ ${item["text"]}`
|
|
|
35597
35764
|
}
|
|
35598
35765
|
case "turn.completed": {
|
|
35599
35766
|
const u = msg2["usage"] ?? {};
|
|
35767
|
+
const input2 = u["input_tokens"];
|
|
35600
35768
|
turn.push({
|
|
35601
35769
|
type: "usage",
|
|
35602
|
-
...
|
|
35770
|
+
...input2 !== void 0 ? { input: input2 - (u["cached_input_tokens"] ?? 0) } : {},
|
|
35603
35771
|
...u["output_tokens"] !== void 0 ? { output: u["output_tokens"] } : {},
|
|
35604
35772
|
...u["cached_input_tokens"] !== void 0 ? { cacheRead: u["cached_input_tokens"] } : {}
|
|
35605
35773
|
});
|
|
@@ -35663,13 +35831,516 @@ ${item["text"]}`
|
|
|
35663
35831
|
}
|
|
35664
35832
|
});
|
|
35665
35833
|
|
|
35834
|
+
// src/drivers/native/pi-gate.ts
|
|
35835
|
+
function writePiGate() {
|
|
35836
|
+
const dir = (0, import_node_fs41.mkdtempSync)((0, import_node_path60.join)((0, import_node_os11.tmpdir)(), "ama-pi-"));
|
|
35837
|
+
const path = (0, import_node_path60.join)(dir, "ama-approval-gate.ts");
|
|
35838
|
+
(0, import_node_fs41.writeFileSync)(path, PI_GATE_SOURCE, { mode: 384 });
|
|
35839
|
+
return {
|
|
35840
|
+
path,
|
|
35841
|
+
dispose: () => (0, import_node_fs41.rmSync)(dir, { recursive: true, force: true })
|
|
35842
|
+
};
|
|
35843
|
+
}
|
|
35844
|
+
var import_node_fs41, import_node_os11, import_node_path60, PI_GATE_TITLE, PI_READ_ONLY_TOOLS, PI_GATE_SOURCE;
|
|
35845
|
+
var init_pi_gate = __esm({
|
|
35846
|
+
"src/drivers/native/pi-gate.ts"() {
|
|
35847
|
+
"use strict";
|
|
35848
|
+
import_node_fs41 = require("node:fs");
|
|
35849
|
+
import_node_os11 = require("node:os");
|
|
35850
|
+
import_node_path60 = require("node:path");
|
|
35851
|
+
PI_GATE_TITLE = "ama-approval";
|
|
35852
|
+
PI_READ_ONLY_TOOLS = ["read", "grep", "find", "ls"];
|
|
35853
|
+
PI_GATE_SOURCE = `// Generated by ama for one pi run: routes non-read-only tool calls to ama for approval.
|
|
35854
|
+
const READ_ONLY = new Set(${JSON.stringify(PI_READ_ONLY_TOOLS)});
|
|
35855
|
+
export default function (pi) {
|
|
35856
|
+
pi.on("tool_call", async (event, ctx) => {
|
|
35857
|
+
if (READ_ONLY.has(event.toolName)) return undefined;
|
|
35858
|
+
const ok = await ctx.ui.confirm(
|
|
35859
|
+
${JSON.stringify(PI_GATE_TITLE)},
|
|
35860
|
+
JSON.stringify({ id: event.toolCallId, tool: event.toolName, input: event.input }),
|
|
35861
|
+
);
|
|
35862
|
+
return ok ? undefined : { block: true, reason: event.toolName + " was not approved by the user" };
|
|
35863
|
+
});
|
|
35864
|
+
}
|
|
35865
|
+
`;
|
|
35866
|
+
}
|
|
35867
|
+
});
|
|
35868
|
+
|
|
35869
|
+
// src/drivers/native/pi-rpc.ts
|
|
35870
|
+
function piArgs(options, sessionId, gatePath) {
|
|
35871
|
+
const args = ["--session-id", sessionId];
|
|
35872
|
+
if (options.model !== void 0) args.push("--model", options.model);
|
|
35873
|
+
args.push("-e", gatePath);
|
|
35874
|
+
if (isReadOnlyMode(options.mode)) args.push("--tools", PI_READ_ONLY_TOOLS.join(","));
|
|
35875
|
+
return args;
|
|
35876
|
+
}
|
|
35877
|
+
function piToolKind(tool) {
|
|
35878
|
+
switch (tool) {
|
|
35879
|
+
case "bash":
|
|
35880
|
+
case "powershell":
|
|
35881
|
+
return "execute";
|
|
35882
|
+
case "edit":
|
|
35883
|
+
case "write":
|
|
35884
|
+
return "edit";
|
|
35885
|
+
case "read":
|
|
35886
|
+
return "read";
|
|
35887
|
+
case "grep":
|
|
35888
|
+
case "find":
|
|
35889
|
+
case "ls":
|
|
35890
|
+
return "search";
|
|
35891
|
+
default:
|
|
35892
|
+
return "other";
|
|
35893
|
+
}
|
|
35894
|
+
}
|
|
35895
|
+
function piToolTitle(tool, input2) {
|
|
35896
|
+
if (typeof input2["command"] === "string") return `$ ${oneLine2(input2["command"], 100)}`;
|
|
35897
|
+
if (typeof input2["path"] === "string") return `${tool} ${input2["path"]}`;
|
|
35898
|
+
if (typeof input2["pattern"] === "string") return `${tool} ${oneLine2(input2["pattern"], 80)}`;
|
|
35899
|
+
return tool;
|
|
35900
|
+
}
|
|
35901
|
+
function textOf4(message) {
|
|
35902
|
+
const content = message["content"];
|
|
35903
|
+
if (typeof content === "string") return content;
|
|
35904
|
+
if (!Array.isArray(content)) return "";
|
|
35905
|
+
return content.map((b) => b["type"] === "text" && typeof b["text"] === "string" ? b["text"] : "").join("");
|
|
35906
|
+
}
|
|
35907
|
+
var import_node_crypto14, import_node_path61, DIALOG_METHODS, EDIT_TOOLS, PiRpcDriver, PiSession;
|
|
35908
|
+
var init_pi_rpc = __esm({
|
|
35909
|
+
"src/drivers/native/pi-rpc.ts"() {
|
|
35910
|
+
"use strict";
|
|
35911
|
+
import_node_crypto14 = require("node:crypto");
|
|
35912
|
+
import_node_path61 = require("node:path");
|
|
35913
|
+
init_errors();
|
|
35914
|
+
init_jsonl();
|
|
35915
|
+
init_base();
|
|
35916
|
+
init_process();
|
|
35917
|
+
init_turn();
|
|
35918
|
+
init_pi_gate();
|
|
35919
|
+
init_i18n();
|
|
35920
|
+
DIALOG_METHODS = /* @__PURE__ */ new Set(["select", "confirm", "input", "editor"]);
|
|
35921
|
+
EDIT_TOOLS = /* @__PURE__ */ new Set(["edit", "write"]);
|
|
35922
|
+
PiRpcDriver = class {
|
|
35923
|
+
constructor(agentId, candidate, deps = {}) {
|
|
35924
|
+
this.agentId = agentId;
|
|
35925
|
+
this.candidate = candidate;
|
|
35926
|
+
this.deps = deps;
|
|
35927
|
+
}
|
|
35928
|
+
agentId;
|
|
35929
|
+
candidate;
|
|
35930
|
+
deps;
|
|
35931
|
+
kind = "pi-rpc";
|
|
35932
|
+
probe() {
|
|
35933
|
+
return probeCandidate(this.candidate, this.deps);
|
|
35934
|
+
}
|
|
35935
|
+
async open(options) {
|
|
35936
|
+
const probed = await probeCandidate(this.candidate, this.deps);
|
|
35937
|
+
const sessionId = options.resume ?? (0, import_node_crypto14.randomUUID)();
|
|
35938
|
+
const gate = writePiGate();
|
|
35939
|
+
const transport = spawnOf(this.deps)({
|
|
35940
|
+
program: probed.path ?? this.candidate.program,
|
|
35941
|
+
args: [...this.candidate.args, ...piArgs(options, sessionId, gate.path)],
|
|
35942
|
+
cwd: options.cwd,
|
|
35943
|
+
env: options.env
|
|
35944
|
+
});
|
|
35945
|
+
const session = new PiSession(
|
|
35946
|
+
this.agentId,
|
|
35947
|
+
sessionId,
|
|
35948
|
+
transport,
|
|
35949
|
+
options,
|
|
35950
|
+
this.deps,
|
|
35951
|
+
() => gate.dispose()
|
|
35952
|
+
);
|
|
35953
|
+
if (probed.warning !== void 0) session.notices.push(probed.warning);
|
|
35954
|
+
try {
|
|
35955
|
+
await session.start(options.signal);
|
|
35956
|
+
} catch (error2) {
|
|
35957
|
+
await session.close();
|
|
35958
|
+
throw new AmaError(
|
|
35959
|
+
"agent_start_failed",
|
|
35960
|
+
`${this.agentId}: failed to start (${error2.message})${stderrHint(transport) !== "" ? `: ${stderrHint(transport)}` : ""}`,
|
|
35961
|
+
{ cause: error2 }
|
|
35962
|
+
);
|
|
35963
|
+
}
|
|
35964
|
+
return session;
|
|
35965
|
+
}
|
|
35966
|
+
};
|
|
35967
|
+
PiSession = class {
|
|
35968
|
+
constructor(agentId, id, transport, options, deps, dispose) {
|
|
35969
|
+
this.agentId = agentId;
|
|
35970
|
+
this.id = id;
|
|
35971
|
+
this.transport = transport;
|
|
35972
|
+
this.options = options;
|
|
35973
|
+
this.deps = deps;
|
|
35974
|
+
this.dispose = dispose;
|
|
35975
|
+
createLineReader(
|
|
35976
|
+
transport.stdout,
|
|
35977
|
+
(line2) => this.onLine(line2),
|
|
35978
|
+
() => this.onExit()
|
|
35979
|
+
);
|
|
35980
|
+
transport.stdin.on?.("error", () => void 0);
|
|
35981
|
+
}
|
|
35982
|
+
agentId;
|
|
35983
|
+
id;
|
|
35984
|
+
transport;
|
|
35985
|
+
options;
|
|
35986
|
+
deps;
|
|
35987
|
+
dispose;
|
|
35988
|
+
notices = [];
|
|
35989
|
+
nextId = 1;
|
|
35990
|
+
pending = /* @__PURE__ */ new Map();
|
|
35991
|
+
permissions = /* @__PURE__ */ new Set();
|
|
35992
|
+
turn;
|
|
35993
|
+
hooks;
|
|
35994
|
+
settle;
|
|
35995
|
+
running;
|
|
35996
|
+
usage = { input: 0, output: 0, cacheRead: 0, costUsd: 0, seen: false };
|
|
35997
|
+
lastAssistant;
|
|
35998
|
+
interrupted = false;
|
|
35999
|
+
closed = false;
|
|
36000
|
+
exited = false;
|
|
36001
|
+
exitWaiters = /* @__PURE__ */ new Set();
|
|
36002
|
+
get sessionId() {
|
|
36003
|
+
return this.id;
|
|
36004
|
+
}
|
|
36005
|
+
/** 握手:`get_state` 确认进程起来了,并取 pi 实际使用的会话 id。 */
|
|
36006
|
+
async start(signal) {
|
|
36007
|
+
const aborted = new Promise((_, reject2) => {
|
|
36008
|
+
if (signal.aborted) reject2(new Error("aborted"));
|
|
36009
|
+
signal.addEventListener("abort", () => reject2(new Error("aborted")), { once: true });
|
|
36010
|
+
});
|
|
36011
|
+
void aborted.catch(() => void 0);
|
|
36012
|
+
const state = await Promise.race([this.request({ type: "get_state" }), aborted]);
|
|
36013
|
+
const data2 = state["data"] ?? {};
|
|
36014
|
+
if (typeof data2["sessionId"] === "string" && data2["sessionId"] !== "")
|
|
36015
|
+
this.id = data2["sessionId"];
|
|
36016
|
+
}
|
|
36017
|
+
async prompt(content, hooks) {
|
|
36018
|
+
if (this.closed || this.exited)
|
|
36019
|
+
throw new AmaError("agent_closed", `${this.agentId} session is closed`);
|
|
36020
|
+
if (this.running !== void 0)
|
|
36021
|
+
throw new AmaError("busy", `${this.agentId} is already running`);
|
|
36022
|
+
const turn = new TurnCollector((e) => hooks.onEvent(e));
|
|
36023
|
+
for (const text of this.notices.splice(0)) turn.push({ type: "notice", level: "warn", text });
|
|
36024
|
+
this.turn = turn;
|
|
36025
|
+
this.hooks = hooks;
|
|
36026
|
+
this.interrupted = false;
|
|
36027
|
+
this.usage = { input: 0, output: 0, cacheRead: 0, costUsd: 0, seen: false };
|
|
36028
|
+
this.lastAssistant = void 0;
|
|
36029
|
+
this.running = this.run(content, turn);
|
|
36030
|
+
try {
|
|
36031
|
+
return await this.running;
|
|
36032
|
+
} finally {
|
|
36033
|
+
this.running = void 0;
|
|
36034
|
+
this.turn = void 0;
|
|
36035
|
+
this.hooks = void 0;
|
|
36036
|
+
this.settle = void 0;
|
|
36037
|
+
this.exitWaiters.clear();
|
|
36038
|
+
}
|
|
36039
|
+
}
|
|
36040
|
+
async run(content, turn) {
|
|
36041
|
+
await Promise.resolve();
|
|
36042
|
+
const settled = new Promise((resolve41) => this.settle = resolve41);
|
|
36043
|
+
const response = await this.request({ type: "prompt", ...this.message(content) });
|
|
36044
|
+
if (response["success"] !== true)
|
|
36045
|
+
throw new AmaError(
|
|
36046
|
+
"agent_failed",
|
|
36047
|
+
`${this.agentId} rejected the prompt: ${oneLine2(String(response["error"] ?? "unknown"), 300)}`
|
|
36048
|
+
);
|
|
36049
|
+
const disposition = (response["data"] ?? {})["disposition"];
|
|
36050
|
+
if (disposition === "handled") return turn.result("end_turn");
|
|
36051
|
+
const aborted = await Promise.race([settled, this.exitPromise()]);
|
|
36052
|
+
await this.reportContext(turn);
|
|
36053
|
+
return this.complete(turn, aborted);
|
|
36054
|
+
}
|
|
36055
|
+
async steer(content) {
|
|
36056
|
+
if (this.closed || this.exited)
|
|
36057
|
+
throw new AmaError("agent_closed", `${this.agentId} session is closed`);
|
|
36058
|
+
await this.request({ type: "steer", ...this.message(content) });
|
|
36059
|
+
}
|
|
36060
|
+
async cancel() {
|
|
36061
|
+
const running = this.running;
|
|
36062
|
+
if (running === void 0 || this.closed) return;
|
|
36063
|
+
this.interrupted = true;
|
|
36064
|
+
for (const c of this.permissions) c.abort();
|
|
36065
|
+
void this.request({ type: "abort" }).catch(() => void 0);
|
|
36066
|
+
armCancelWatchdog(
|
|
36067
|
+
this.transport,
|
|
36068
|
+
running.catch(() => void 0),
|
|
36069
|
+
this.deps
|
|
36070
|
+
);
|
|
36071
|
+
}
|
|
36072
|
+
async close() {
|
|
36073
|
+
if (this.closed) return;
|
|
36074
|
+
this.closed = true;
|
|
36075
|
+
for (const c of this.permissions) c.abort();
|
|
36076
|
+
if (this.running !== void 0) {
|
|
36077
|
+
this.interrupted = true;
|
|
36078
|
+
this.write({ type: "abort" });
|
|
36079
|
+
}
|
|
36080
|
+
try {
|
|
36081
|
+
await this.transport.terminate();
|
|
36082
|
+
} finally {
|
|
36083
|
+
this.dispose();
|
|
36084
|
+
}
|
|
36085
|
+
}
|
|
36086
|
+
message(content) {
|
|
36087
|
+
const text = content.map((b) => b.type === "text" ? b.text : "").join("\n");
|
|
36088
|
+
const images = content.flatMap(
|
|
36089
|
+
(b) => b.type === "image" ? [{ type: "image", data: b.data, mimeType: b.mimeType }] : []
|
|
36090
|
+
);
|
|
36091
|
+
return { message: text, ...images.length > 0 ? { images } : {} };
|
|
36092
|
+
}
|
|
36093
|
+
complete(turn, aborted) {
|
|
36094
|
+
const u = this.usage;
|
|
36095
|
+
if (u.seen)
|
|
36096
|
+
turn.push({
|
|
36097
|
+
type: "usage",
|
|
36098
|
+
input: u.input,
|
|
36099
|
+
output: u.output,
|
|
36100
|
+
cacheRead: u.cacheRead,
|
|
36101
|
+
costUsd: u.costUsd
|
|
36102
|
+
});
|
|
36103
|
+
const last = this.lastAssistant;
|
|
36104
|
+
if (last !== void 0) {
|
|
36105
|
+
const text = textOf4(last);
|
|
36106
|
+
if (text !== "") turn.setFinalText(text);
|
|
36107
|
+
}
|
|
36108
|
+
if (aborted || this.interrupted) return turn.result("cancelled");
|
|
36109
|
+
switch (last?.["stopReason"]) {
|
|
36110
|
+
case "error":
|
|
36111
|
+
throw new AmaError(
|
|
36112
|
+
"agent_failed",
|
|
36113
|
+
`${this.agentId} failed: ${oneLine2(String(last["errorMessage"] ?? "unknown error"), 300)}`
|
|
36114
|
+
);
|
|
36115
|
+
case "aborted":
|
|
36116
|
+
return turn.result("cancelled");
|
|
36117
|
+
case "length":
|
|
36118
|
+
return turn.result("max_tokens");
|
|
36119
|
+
default:
|
|
36120
|
+
return turn.result("end_turn");
|
|
36121
|
+
}
|
|
36122
|
+
}
|
|
36123
|
+
/** `get_session_stats.contextUsage` → 上下文占用与窗口(拿不到就算了)。 */
|
|
36124
|
+
async reportContext(turn) {
|
|
36125
|
+
if (this.exited) return;
|
|
36126
|
+
try {
|
|
36127
|
+
const stats = await Promise.race([
|
|
36128
|
+
this.request({ type: "get_session_stats" }),
|
|
36129
|
+
new Promise((resolve41) => setTimeout(() => resolve41({}), 5e3).unref())
|
|
36130
|
+
]);
|
|
36131
|
+
const usage = (stats["data"] ?? {})["contextUsage"] ?? {};
|
|
36132
|
+
const tokens = usage["tokens"];
|
|
36133
|
+
const window2 = usage["contextWindow"];
|
|
36134
|
+
if (typeof tokens === "number" || typeof window2 === "number")
|
|
36135
|
+
turn.push({
|
|
36136
|
+
type: "usage",
|
|
36137
|
+
...typeof tokens === "number" ? { contextTokens: tokens } : {},
|
|
36138
|
+
...typeof window2 === "number" ? { contextWindow: window2 } : {}
|
|
36139
|
+
});
|
|
36140
|
+
} catch {
|
|
36141
|
+
}
|
|
36142
|
+
}
|
|
36143
|
+
exitPromise() {
|
|
36144
|
+
return new Promise((_, reject2) => {
|
|
36145
|
+
if (this.exited) reject2(this.exitError());
|
|
36146
|
+
else this.exitWaiters.add(reject2);
|
|
36147
|
+
});
|
|
36148
|
+
}
|
|
36149
|
+
exitError() {
|
|
36150
|
+
const hint = stderrHint(this.transport);
|
|
36151
|
+
return new AmaError(
|
|
36152
|
+
"agent_exited",
|
|
36153
|
+
`${this.agentId} process exited${hint !== "" ? `: ${hint}` : ""}`
|
|
36154
|
+
);
|
|
36155
|
+
}
|
|
36156
|
+
request(command3) {
|
|
36157
|
+
if (this.exited) return Promise.reject(this.exitError());
|
|
36158
|
+
const id = `ama-${this.nextId++}`;
|
|
36159
|
+
return new Promise((resolve41, reject2) => {
|
|
36160
|
+
this.pending.set(id, { resolve: resolve41, reject: reject2 });
|
|
36161
|
+
this.write({ id, ...command3 });
|
|
36162
|
+
});
|
|
36163
|
+
}
|
|
36164
|
+
write(record3) {
|
|
36165
|
+
if (this.exited) return;
|
|
36166
|
+
this.transport.stdin.write(`${JSON.stringify(record3)}
|
|
36167
|
+
`);
|
|
36168
|
+
}
|
|
36169
|
+
onExit() {
|
|
36170
|
+
this.exited = true;
|
|
36171
|
+
const error2 = this.exitError();
|
|
36172
|
+
for (const p of this.pending.values()) p.reject(error2);
|
|
36173
|
+
this.pending.clear();
|
|
36174
|
+
for (const reject2 of this.exitWaiters) reject2(error2);
|
|
36175
|
+
this.exitWaiters.clear();
|
|
36176
|
+
for (const c of this.permissions) c.abort();
|
|
36177
|
+
}
|
|
36178
|
+
onLine(line2) {
|
|
36179
|
+
let record3;
|
|
36180
|
+
try {
|
|
36181
|
+
record3 = JSON.parse(line2);
|
|
36182
|
+
} catch {
|
|
36183
|
+
this.deps.log?.("debug", msg().drivers.agent.nonJson(this.agentId));
|
|
36184
|
+
return;
|
|
36185
|
+
}
|
|
36186
|
+
switch (record3["type"]) {
|
|
36187
|
+
case "response": {
|
|
36188
|
+
const id = record3["id"];
|
|
36189
|
+
const pending = typeof id === "string" ? this.pending.get(id) : void 0;
|
|
36190
|
+
if (pending === void 0 || typeof id !== "string") return;
|
|
36191
|
+
this.pending.delete(id);
|
|
36192
|
+
pending.resolve(record3);
|
|
36193
|
+
return;
|
|
36194
|
+
}
|
|
36195
|
+
case "agent_settled":
|
|
36196
|
+
this.settle?.(record3["aborted"] === true);
|
|
36197
|
+
return;
|
|
36198
|
+
case "extension_ui_request":
|
|
36199
|
+
void this.onDialog(record3);
|
|
36200
|
+
return;
|
|
36201
|
+
default:
|
|
36202
|
+
this.onEvent(record3);
|
|
36203
|
+
}
|
|
36204
|
+
}
|
|
36205
|
+
onEvent(record3) {
|
|
36206
|
+
const turn = this.turn;
|
|
36207
|
+
if (turn === void 0) return;
|
|
36208
|
+
switch (record3["type"]) {
|
|
36209
|
+
case "message_update": {
|
|
36210
|
+
const event = record3["assistantMessageEvent"] ?? {};
|
|
36211
|
+
const delta = event["delta"];
|
|
36212
|
+
if (typeof delta !== "string") return;
|
|
36213
|
+
if (event["type"] === "text_delta") turn.push({ type: "message_delta", text: delta });
|
|
36214
|
+
else if (event["type"] === "thinking_delta")
|
|
36215
|
+
turn.push({ type: "thought_delta", text: delta });
|
|
36216
|
+
return;
|
|
36217
|
+
}
|
|
36218
|
+
case "message_end": {
|
|
36219
|
+
const message = record3["message"] ?? {};
|
|
36220
|
+
if (message["role"] !== "assistant") return;
|
|
36221
|
+
this.lastAssistant = message;
|
|
36222
|
+
const usage = message["usage"] ?? {};
|
|
36223
|
+
const num10 = (key) => typeof usage[key] === "number" ? usage[key] : 0;
|
|
36224
|
+
const cost2 = (usage["cost"] ?? {})["total"];
|
|
36225
|
+
this.usage = {
|
|
36226
|
+
input: this.usage.input + num10("input"),
|
|
36227
|
+
output: this.usage.output + num10("output"),
|
|
36228
|
+
cacheRead: this.usage.cacheRead + num10("cacheRead"),
|
|
36229
|
+
costUsd: this.usage.costUsd + (typeof cost2 === "number" ? cost2 : 0),
|
|
36230
|
+
seen: true
|
|
36231
|
+
};
|
|
36232
|
+
return;
|
|
36233
|
+
}
|
|
36234
|
+
case "tool_execution_start":
|
|
36235
|
+
case "tool_execution_end": {
|
|
36236
|
+
const tool = String(record3["toolName"] ?? "tool");
|
|
36237
|
+
const known = turn.tool(String(record3["toolCallId"] ?? ""));
|
|
36238
|
+
const input2 = record3["args"] ?? {};
|
|
36239
|
+
const path = typeof input2["path"] === "string" ? input2["path"] : void 0;
|
|
36240
|
+
const locations = path !== void 0 ? [(0, import_node_path61.resolve)(this.options.cwd, path)] : known?.locations;
|
|
36241
|
+
turn.push({
|
|
36242
|
+
type: "tool_call",
|
|
36243
|
+
id: String(record3["toolCallId"] ?? ""),
|
|
36244
|
+
title: known?.title ?? piToolTitle(tool, input2),
|
|
36245
|
+
kind: piToolKind(tool),
|
|
36246
|
+
status: record3["type"] === "tool_execution_start" ? "in_progress" : record3["isError"] === true ? "failed" : "completed",
|
|
36247
|
+
...locations !== void 0 && locations.length > 0 ? { locations } : {}
|
|
36248
|
+
});
|
|
36249
|
+
return;
|
|
36250
|
+
}
|
|
36251
|
+
case "auto_retry_start":
|
|
36252
|
+
turn.push({
|
|
36253
|
+
type: "notice",
|
|
36254
|
+
level: "warn",
|
|
36255
|
+
text: msg().drivers.agent.error(
|
|
36256
|
+
this.agentId,
|
|
36257
|
+
oneLine2(String(record3["errorMessage"] ?? "error"), 200),
|
|
36258
|
+
true
|
|
36259
|
+
)
|
|
36260
|
+
});
|
|
36261
|
+
return;
|
|
36262
|
+
default:
|
|
36263
|
+
return;
|
|
36264
|
+
}
|
|
36265
|
+
}
|
|
36266
|
+
/** 扩展对话框:ama 的审批闸按模式决定或交给人;其它扩展的对话框取消(不代答)。 */
|
|
36267
|
+
async onDialog(record3) {
|
|
36268
|
+
const id = String(record3["id"] ?? "");
|
|
36269
|
+
const method = String(record3["method"] ?? "");
|
|
36270
|
+
if (!DIALOG_METHODS.has(method)) {
|
|
36271
|
+
if (record3["method"] === "notify" && record3["notifyType"] !== "info")
|
|
36272
|
+
this.turn?.push({
|
|
36273
|
+
type: "notice",
|
|
36274
|
+
level: "warn",
|
|
36275
|
+
text: `${this.agentId}: ${oneLine2(String(record3["message"] ?? ""), 200)}`
|
|
36276
|
+
});
|
|
36277
|
+
return;
|
|
36278
|
+
}
|
|
36279
|
+
if (method !== "confirm" || record3["title"] !== PI_GATE_TITLE) {
|
|
36280
|
+
this.turn?.push({
|
|
36281
|
+
type: "notice",
|
|
36282
|
+
level: "warn",
|
|
36283
|
+
text: msg().drivers.agent.extensionDialog(
|
|
36284
|
+
this.agentId,
|
|
36285
|
+
oneLine2(String(record3["title"] ?? method), 80)
|
|
36286
|
+
)
|
|
36287
|
+
});
|
|
36288
|
+
this.write({ type: "extension_ui_response", id, cancelled: true });
|
|
36289
|
+
return;
|
|
36290
|
+
}
|
|
36291
|
+
const confirmed = await this.decide(record3);
|
|
36292
|
+
this.write({ type: "extension_ui_response", id, confirmed });
|
|
36293
|
+
}
|
|
36294
|
+
async decide(record3) {
|
|
36295
|
+
let call;
|
|
36296
|
+
try {
|
|
36297
|
+
call = JSON.parse(String(record3["message"] ?? "{}"));
|
|
36298
|
+
} catch {
|
|
36299
|
+
return false;
|
|
36300
|
+
}
|
|
36301
|
+
const tool = String(call["tool"] ?? "tool");
|
|
36302
|
+
const input2 = call["input"] ?? {};
|
|
36303
|
+
const mode = this.options.mode;
|
|
36304
|
+
if (isReadOnlyMode(mode)) return false;
|
|
36305
|
+
if (mode !== "default" && EDIT_TOOLS.has(tool)) return true;
|
|
36306
|
+
const hooks = this.hooks;
|
|
36307
|
+
if (hooks === void 0 || this.interrupted || this.closed) return false;
|
|
36308
|
+
const known = this.turn?.tool(String(call["id"] ?? ""));
|
|
36309
|
+
const path = typeof input2["path"] === "string" ? input2["path"] : void 0;
|
|
36310
|
+
const controller = new AbortController();
|
|
36311
|
+
this.permissions.add(controller);
|
|
36312
|
+
try {
|
|
36313
|
+
const outcome = await hooks.onPermission(
|
|
36314
|
+
{
|
|
36315
|
+
toolCall: {
|
|
36316
|
+
title: known?.title ?? piToolTitle(tool, input2),
|
|
36317
|
+
kind: piToolKind(tool),
|
|
36318
|
+
...path !== void 0 ? { locations: [(0, import_node_path61.resolve)(this.options.cwd, path)] } : {},
|
|
36319
|
+
inputSummary: oneLine2(JSON.stringify(input2), 300)
|
|
36320
|
+
},
|
|
36321
|
+
options: [
|
|
36322
|
+
{ optionId: "allow", kind: "allow_once" },
|
|
36323
|
+
{ optionId: "reject", kind: "reject_once" }
|
|
36324
|
+
]
|
|
36325
|
+
},
|
|
36326
|
+
controller.signal
|
|
36327
|
+
);
|
|
36328
|
+
return !controller.signal.aborted && outcome.outcome === "selected" && outcome.optionId === "allow";
|
|
36329
|
+
} finally {
|
|
36330
|
+
this.permissions.delete(controller);
|
|
36331
|
+
}
|
|
36332
|
+
}
|
|
36333
|
+
};
|
|
36334
|
+
}
|
|
36335
|
+
});
|
|
36336
|
+
|
|
35666
36337
|
// src/drivers/pids.ts
|
|
35667
36338
|
function pidsFile(dataDir) {
|
|
35668
|
-
return (0,
|
|
36339
|
+
return (0, import_node_path62.join)(dataDir, "drivers", "pids.json");
|
|
35669
36340
|
}
|
|
35670
36341
|
function read(file) {
|
|
35671
36342
|
try {
|
|
35672
|
-
const parsed = JSON.parse((0,
|
|
36343
|
+
const parsed = JSON.parse((0, import_node_fs42.readFileSync)(file, "utf8"));
|
|
35673
36344
|
return Array.isArray(parsed.entries) ? parsed.entries : [];
|
|
35674
36345
|
} catch {
|
|
35675
36346
|
return [];
|
|
@@ -35677,11 +36348,11 @@ function read(file) {
|
|
|
35677
36348
|
}
|
|
35678
36349
|
function write(file, entries) {
|
|
35679
36350
|
try {
|
|
35680
|
-
(0,
|
|
36351
|
+
(0, import_node_fs42.mkdirSync)((0, import_node_path62.dirname)(file), { recursive: true });
|
|
35681
36352
|
const tmp = `${file}.${process.pid}.tmp`;
|
|
35682
|
-
(0,
|
|
36353
|
+
(0, import_node_fs42.writeFileSync)(tmp, `${JSON.stringify({ version: 1, entries }, null, 2)}
|
|
35683
36354
|
`);
|
|
35684
|
-
(0,
|
|
36355
|
+
(0, import_node_fs42.renameSync)(tmp, file);
|
|
35685
36356
|
} catch {
|
|
35686
36357
|
}
|
|
35687
36358
|
}
|
|
@@ -35697,13 +36368,13 @@ function psCommand(pid) {
|
|
|
35697
36368
|
const out = (0, import_node_child_process11.spawnSync)("ps", ["-o", "command=", "-p", String(pid)], { encoding: "utf8" });
|
|
35698
36369
|
return out.status === 0 ? out.stdout.trim() : void 0;
|
|
35699
36370
|
}
|
|
35700
|
-
var import_node_child_process11,
|
|
36371
|
+
var import_node_child_process11, import_node_fs42, import_node_path62, PidRegistry;
|
|
35701
36372
|
var init_pids = __esm({
|
|
35702
36373
|
"src/drivers/pids.ts"() {
|
|
35703
36374
|
"use strict";
|
|
35704
36375
|
import_node_child_process11 = require("node:child_process");
|
|
35705
|
-
|
|
35706
|
-
|
|
36376
|
+
import_node_fs42 = require("node:fs");
|
|
36377
|
+
import_node_path62 = require("node:path");
|
|
35707
36378
|
init_process_tree();
|
|
35708
36379
|
PidRegistry = class {
|
|
35709
36380
|
constructor(file) {
|
|
@@ -35739,7 +36410,7 @@ var init_pids = __esm({
|
|
|
35739
36410
|
}
|
|
35740
36411
|
if (platform === "win32" || !groupAlive(entry.pid)) continue;
|
|
35741
36412
|
const command3 = commandOf(entry.pid);
|
|
35742
|
-
if (command3 !== void 0 && command3.includes((0,
|
|
36413
|
+
if (command3 !== void 0 && command3.includes((0, import_node_path62.basename)(entry.program))) {
|
|
35743
36414
|
await kill(entry.pid);
|
|
35744
36415
|
killed.push(entry.pid);
|
|
35745
36416
|
}
|
|
@@ -35899,7 +36570,7 @@ async function askHuman(request, ctx) {
|
|
|
35899
36570
|
if (ctx.signal.aborted) return CANCELLED;
|
|
35900
36571
|
if (ctx.unattended) return pick(request, "reject_once") ?? CANCELLED;
|
|
35901
36572
|
const approval = {
|
|
35902
|
-
requestId: (0,
|
|
36573
|
+
requestId: (0, import_node_crypto15.randomUUID)(),
|
|
35903
36574
|
toolName: externalToolName(ctx.agent),
|
|
35904
36575
|
input: request.toolCall,
|
|
35905
36576
|
reason: "mode",
|
|
@@ -35940,11 +36611,11 @@ function supportedMode(mode, supported) {
|
|
|
35940
36611
|
if (rank(m) <= rank(mode) && (best === void 0 || rank(m) > rank(best))) best = m;
|
|
35941
36612
|
return best;
|
|
35942
36613
|
}
|
|
35943
|
-
var
|
|
36614
|
+
var import_node_crypto15, CANCELLED;
|
|
35944
36615
|
var init_permissions2 = __esm({
|
|
35945
36616
|
"src/drivers/permissions.ts"() {
|
|
35946
36617
|
"use strict";
|
|
35947
|
-
|
|
36618
|
+
import_node_crypto15 = require("node:crypto");
|
|
35948
36619
|
init_types();
|
|
35949
36620
|
CANCELLED = { outcome: "cancelled" };
|
|
35950
36621
|
}
|
|
@@ -36091,7 +36762,8 @@ var init_runner2 = __esm({
|
|
|
36091
36762
|
"acp",
|
|
36092
36763
|
"acp-adapter",
|
|
36093
36764
|
"claude-stream",
|
|
36094
|
-
"codex-app-server"
|
|
36765
|
+
"codex-app-server",
|
|
36766
|
+
"pi-rpc"
|
|
36095
36767
|
]);
|
|
36096
36768
|
ProcessHandle = class {
|
|
36097
36769
|
constructor(runner, chosen, request, deps) {
|
|
@@ -36418,15 +37090,17 @@ function createDriver(agentId, candidate, deps) {
|
|
|
36418
37090
|
return new ClaudeStreamDriver(agentId, candidate, deps);
|
|
36419
37091
|
case "codex-app-server":
|
|
36420
37092
|
return new CodexAppServerDriver(agentId, candidate, deps);
|
|
37093
|
+
case "pi-rpc":
|
|
37094
|
+
return new PiRpcDriver(agentId, candidate, deps);
|
|
36421
37095
|
case "oneshot":
|
|
36422
37096
|
return new OneshotDriver(agentId, candidate, deps);
|
|
36423
37097
|
}
|
|
36424
37098
|
}
|
|
36425
|
-
var
|
|
37099
|
+
var import_node_path63, reaped, ExternalAgents;
|
|
36426
37100
|
var init_agents2 = __esm({
|
|
36427
37101
|
"src/drivers/agents.ts"() {
|
|
36428
37102
|
"use strict";
|
|
36429
|
-
|
|
37103
|
+
import_node_path63 = require("node:path");
|
|
36430
37104
|
init_errors();
|
|
36431
37105
|
init_driver();
|
|
36432
37106
|
init_catalog4();
|
|
@@ -36434,6 +37108,7 @@ var init_agents2 = __esm({
|
|
|
36434
37108
|
init_claude_stream();
|
|
36435
37109
|
init_codex_app_server();
|
|
36436
37110
|
init_oneshot();
|
|
37111
|
+
init_pi_rpc();
|
|
36437
37112
|
init_pids();
|
|
36438
37113
|
init_pool();
|
|
36439
37114
|
init_probe();
|
|
@@ -36459,7 +37134,7 @@ var init_agents2 = __esm({
|
|
|
36459
37134
|
probe: new ProgramProbe({
|
|
36460
37135
|
env: options.env,
|
|
36461
37136
|
cwd: options.cwd,
|
|
36462
|
-
...options.dataDir !== void 0 ? { cacheFile: (0,
|
|
37137
|
+
...options.dataDir !== void 0 ? { cacheFile: (0, import_node_path63.join)(options.dataDir, "drivers.json") } : {}
|
|
36463
37138
|
}),
|
|
36464
37139
|
spawn: (spec2) => spawnTransport(spec2, {
|
|
36465
37140
|
onSpawn: (pid) => registry3?.add(pid, spec2.program),
|
|
@@ -36706,11 +37381,11 @@ function mergeAgentInfos(base4, external) {
|
|
|
36706
37381
|
}
|
|
36707
37382
|
return out;
|
|
36708
37383
|
}
|
|
36709
|
-
var
|
|
37384
|
+
var import_node_crypto16, LISTED_EXTERNAL_AGENTS, NO_AGENT_PROBE_ENV, externalTesting, HOST_AMA_RUNNER, ExternalTaskHandle, infoCache, SessionExternalAgents;
|
|
36710
37385
|
var init_external = __esm({
|
|
36711
37386
|
"src/agents/external.ts"() {
|
|
36712
37387
|
"use strict";
|
|
36713
|
-
|
|
37388
|
+
import_node_crypto16 = require("node:crypto");
|
|
36714
37389
|
init_session_tools();
|
|
36715
37390
|
init_types_w5();
|
|
36716
37391
|
init_agents2();
|
|
@@ -36885,7 +37560,7 @@ var init_external = __esm({
|
|
|
36885
37560
|
agentEntry(this.wiring.config, spec2)?.maxMode
|
|
36886
37561
|
);
|
|
36887
37562
|
const approval = {
|
|
36888
|
-
requestId: (0,
|
|
37563
|
+
requestId: (0, import_node_crypto16.randomUUID)(),
|
|
36889
37564
|
toolName: "task",
|
|
36890
37565
|
input: {
|
|
36891
37566
|
agent: spec2,
|
|
@@ -37131,7 +37806,7 @@ function sourceText2(source, cache3, log) {
|
|
|
37131
37806
|
if (cached !== void 0) return cached;
|
|
37132
37807
|
let text = "";
|
|
37133
37808
|
try {
|
|
37134
|
-
text = (0,
|
|
37809
|
+
text = (0, import_node_fs43.readFileSync)(source.path, "utf8");
|
|
37135
37810
|
} catch (error2) {
|
|
37136
37811
|
log(
|
|
37137
37812
|
"warn",
|
|
@@ -37485,11 +38160,11 @@ async function disposeSessionAlongside(target, session, fallback) {
|
|
|
37485
38160
|
await session.dispose();
|
|
37486
38161
|
record3.live.delete(session);
|
|
37487
38162
|
}
|
|
37488
|
-
var
|
|
38163
|
+
var import_node_fs43, records, LOG_LEVELS;
|
|
37489
38164
|
var init_compose_session = __esm({
|
|
37490
38165
|
"src/cli/compose-session.ts"() {
|
|
37491
38166
|
"use strict";
|
|
37492
|
-
|
|
38167
|
+
import_node_fs43 = require("node:fs");
|
|
37493
38168
|
init_limits();
|
|
37494
38169
|
init_session2();
|
|
37495
38170
|
init_session_subagent();
|
|
@@ -37537,7 +38212,7 @@ function toolTitle(name, args, nested = false) {
|
|
|
37537
38212
|
function toolLocations(args, cwd) {
|
|
37538
38213
|
const path = argOf(args, "path", "file_path", "filePath");
|
|
37539
38214
|
if (path === void 0) return void 0;
|
|
37540
|
-
return [{ path: (0,
|
|
38215
|
+
return [{ path: (0, import_node_path64.isAbsolute)(path) ? path : (0, import_node_path64.resolve)(cwd, path) }];
|
|
37541
38216
|
}
|
|
37542
38217
|
function resultText2(content) {
|
|
37543
38218
|
const text = typeof content === "string" ? content : content.map((b) => b.type === "text" ? b.text : `[${b.type}]`).join("");
|
|
@@ -37564,11 +38239,11 @@ function resultContent(result) {
|
|
|
37564
38239
|
]
|
|
37565
38240
|
};
|
|
37566
38241
|
}
|
|
37567
|
-
var
|
|
38242
|
+
var import_node_path64, TOOL_OUTPUT_LIMIT, KINDS3;
|
|
37568
38243
|
var init_acp_tool_text = __esm({
|
|
37569
38244
|
"src/modes/acp/acp-tool-text.ts"() {
|
|
37570
38245
|
"use strict";
|
|
37571
|
-
|
|
38246
|
+
import_node_path64 = require("node:path");
|
|
37572
38247
|
init_turn();
|
|
37573
38248
|
init_i18n();
|
|
37574
38249
|
TOOL_OUTPUT_LIMIT = 4 * 1024;
|
|
@@ -38345,9 +39020,9 @@ var init_acp_sessions = __esm({
|
|
|
38345
39020
|
// src/modes/acp/acp-server.ts
|
|
38346
39021
|
function canonical(path) {
|
|
38347
39022
|
try {
|
|
38348
|
-
return
|
|
39023
|
+
return import_node_fs44.realpathSync.native((0, import_node_path65.resolve)(path));
|
|
38349
39024
|
} catch {
|
|
38350
|
-
return (0,
|
|
39025
|
+
return (0, import_node_path65.resolve)(path);
|
|
38351
39026
|
}
|
|
38352
39027
|
}
|
|
38353
39028
|
function str(params, key) {
|
|
@@ -38376,12 +39051,12 @@ ${block.resource.text}
|
|
|
38376
39051
|
function countOf(value) {
|
|
38377
39052
|
return Array.isArray(value) ? value.length : 0;
|
|
38378
39053
|
}
|
|
38379
|
-
var
|
|
39054
|
+
var import_node_fs44, import_node_path65, ACP_AGENT_CAPABILITIES, SESSION_ID_SHAPE, AcpServer;
|
|
38380
39055
|
var init_acp_server = __esm({
|
|
38381
39056
|
"src/modes/acp/acp-server.ts"() {
|
|
38382
39057
|
"use strict";
|
|
38383
|
-
|
|
38384
|
-
|
|
39058
|
+
import_node_fs44 = require("node:fs");
|
|
39059
|
+
import_node_path65 = require("node:path");
|
|
38385
39060
|
init_shared();
|
|
38386
39061
|
init_compose_session();
|
|
38387
39062
|
init_compose_store();
|
|
@@ -38895,7 +39570,7 @@ function terminalAuthMethods(authFile) {
|
|
|
38895
39570
|
];
|
|
38896
39571
|
}
|
|
38897
39572
|
function gateAuthFile(args, cwd) {
|
|
38898
|
-
if (args.authFile !== void 0) return (0,
|
|
39573
|
+
if (args.authFile !== void 0) return (0, import_node_path66.resolve)(cwd, args.authFile);
|
|
38899
39574
|
if (args.profile === void 0) return void 0;
|
|
38900
39575
|
try {
|
|
38901
39576
|
return loadProfile(args.profile, cwd).authFile;
|
|
@@ -39018,11 +39693,11 @@ async function runAcpAuthGate(args, deps, io, cause, options = {}) {
|
|
|
39018
39693
|
await runtime?.dispose("exit").catch(() => void 0);
|
|
39019
39694
|
return code;
|
|
39020
39695
|
}
|
|
39021
|
-
var
|
|
39696
|
+
var import_node_path66, AUTH_RETRY_INTERVAL_MS, SESSION_METHODS;
|
|
39022
39697
|
var init_acp_auth_gate = __esm({
|
|
39023
39698
|
"src/modes/acp/acp-auth-gate.ts"() {
|
|
39024
39699
|
"use strict";
|
|
39025
|
-
|
|
39700
|
+
import_node_path66 = require("node:path");
|
|
39026
39701
|
init_args();
|
|
39027
39702
|
init_bootstrap();
|
|
39028
39703
|
init_exit_codes();
|
|
@@ -39104,7 +39779,7 @@ async function bootstrap(argsIn, deps, io) {
|
|
|
39104
39779
|
() => deps.sessions.open(sessionRequest, { sessionDir: paths.sessionDir, cwd: paths.cwd })
|
|
39105
39780
|
);
|
|
39106
39781
|
let sessionCwd = sessionManager.cwd;
|
|
39107
|
-
if (!(0,
|
|
39782
|
+
if (!(0, import_node_fs45.existsSync)(sessionCwd)) {
|
|
39108
39783
|
const replacement = interactive ? await deps.ui?.askCwd?.(sessionCwd) : void 0;
|
|
39109
39784
|
if (replacement === void 0) {
|
|
39110
39785
|
throw new StartupError(
|
|
@@ -39113,7 +39788,7 @@ async function bootstrap(argsIn, deps, io) {
|
|
|
39113
39788
|
ExitCode.Session
|
|
39114
39789
|
);
|
|
39115
39790
|
}
|
|
39116
|
-
sessionCwd = (0,
|
|
39791
|
+
sessionCwd = (0, import_node_path67.resolve)(replacement);
|
|
39117
39792
|
}
|
|
39118
39793
|
const runtimePaths = { ...paths, cwd: sessionCwd };
|
|
39119
39794
|
const trust = await step(
|
|
@@ -39188,7 +39863,7 @@ async function bootstrap(argsIn, deps, io) {
|
|
|
39188
39863
|
() => deps.providers.create({
|
|
39189
39864
|
config,
|
|
39190
39865
|
cwd: sessionCwd,
|
|
39191
|
-
authFile: args.authFile !== void 0 ? (0,
|
|
39866
|
+
authFile: args.authFile !== void 0 ? (0, import_node_path67.resolve)(io.cwd, args.authFile) : defaultAuthFilePath(paths.configDir),
|
|
39192
39867
|
authEnv: profile?.authEnv ?? true,
|
|
39193
39868
|
dataDir: paths.dataDir,
|
|
39194
39869
|
...args.apiKey !== void 0 && args.model !== void 0 ? {
|
|
@@ -39498,12 +40173,12 @@ function reportError(error2, io, fallback = ExitCode.RuntimeError) {
|
|
|
39498
40173
|
if (isAmaError(error2) && error2.exitCode !== void 0) return error2.exitCode;
|
|
39499
40174
|
return fallback;
|
|
39500
40175
|
}
|
|
39501
|
-
var
|
|
40176
|
+
var import_node_fs45, import_node_path67;
|
|
39502
40177
|
var init_bootstrap = __esm({
|
|
39503
40178
|
"src/cli/bootstrap.ts"() {
|
|
39504
40179
|
"use strict";
|
|
39505
|
-
|
|
39506
|
-
|
|
40180
|
+
import_node_fs45 = require("node:fs");
|
|
40181
|
+
import_node_path67 = require("node:path");
|
|
39507
40182
|
init_auth_file();
|
|
39508
40183
|
init_context_files();
|
|
39509
40184
|
init_load();
|
|
@@ -39529,7 +40204,7 @@ var init_bootstrap = __esm({
|
|
|
39529
40204
|
// src/auth/oauth/token-store.ts
|
|
39530
40205
|
function readRaw(path) {
|
|
39531
40206
|
try {
|
|
39532
|
-
const value = JSON.parse(retryTransientFs(() => (0,
|
|
40207
|
+
const value = JSON.parse(retryTransientFs(() => (0, import_node_fs46.readFileSync)(path, "utf8")));
|
|
39533
40208
|
return typeof value === "object" && value !== null && typeof value.providers === "object" ? value : void 0;
|
|
39534
40209
|
} catch {
|
|
39535
40210
|
return void 0;
|
|
@@ -39561,12 +40236,12 @@ function isStaleLock(path, now = Date.now()) {
|
|
|
39561
40236
|
let age;
|
|
39562
40237
|
let pid;
|
|
39563
40238
|
try {
|
|
39564
|
-
age = now - (0,
|
|
39565
|
-
const value = JSON.parse((0,
|
|
40239
|
+
age = now - (0, import_node_fs46.statSync)(path).mtimeMs;
|
|
40240
|
+
const value = JSON.parse((0, import_node_fs46.readFileSync)(path, "utf8"));
|
|
39566
40241
|
pid = typeof value.pid === "number" ? value.pid : void 0;
|
|
39567
40242
|
} catch {
|
|
39568
40243
|
try {
|
|
39569
|
-
age = now - (0,
|
|
40244
|
+
age = now - (0, import_node_fs46.statSync)(path).mtimeMs;
|
|
39570
40245
|
} catch {
|
|
39571
40246
|
return false;
|
|
39572
40247
|
}
|
|
@@ -39575,11 +40250,11 @@ function isStaleLock(path, now = Date.now()) {
|
|
|
39575
40250
|
}
|
|
39576
40251
|
function tryAcquire(path) {
|
|
39577
40252
|
try {
|
|
39578
|
-
const fd = (0,
|
|
40253
|
+
const fd = (0, import_node_fs46.openSync)(path, "wx", 384);
|
|
39579
40254
|
try {
|
|
39580
|
-
(0,
|
|
40255
|
+
(0, import_node_fs46.writeSync)(fd, JSON.stringify({ pid: process.pid, at: (/* @__PURE__ */ new Date()).toISOString() }));
|
|
39581
40256
|
} finally {
|
|
39582
|
-
(0,
|
|
40257
|
+
(0, import_node_fs46.closeSync)(fd);
|
|
39583
40258
|
}
|
|
39584
40259
|
return true;
|
|
39585
40260
|
} catch (error2) {
|
|
@@ -39590,13 +40265,13 @@ function tryAcquire(path) {
|
|
|
39590
40265
|
}
|
|
39591
40266
|
async function withRefreshLock(authFile, fn, options = {}) {
|
|
39592
40267
|
const path = lockPath(authFile);
|
|
39593
|
-
(0,
|
|
40268
|
+
(0, import_node_fs46.mkdirSync)((0, import_node_path68.dirname)(path), { recursive: true, mode: 448 });
|
|
39594
40269
|
const deadline = Date.now() + (options.waitMs ?? LOCK_WAIT_MS);
|
|
39595
40270
|
for (; ; ) {
|
|
39596
40271
|
if (tryAcquire(path)) break;
|
|
39597
40272
|
if (isStaleLock(path)) {
|
|
39598
40273
|
try {
|
|
39599
|
-
(0,
|
|
40274
|
+
(0, import_node_fs46.unlinkSync)(path);
|
|
39600
40275
|
} catch {
|
|
39601
40276
|
}
|
|
39602
40277
|
continue;
|
|
@@ -39611,17 +40286,17 @@ async function withRefreshLock(authFile, fn, options = {}) {
|
|
|
39611
40286
|
return await fn();
|
|
39612
40287
|
} finally {
|
|
39613
40288
|
try {
|
|
39614
|
-
(0,
|
|
40289
|
+
(0, import_node_fs46.unlinkSync)(path);
|
|
39615
40290
|
} catch {
|
|
39616
40291
|
}
|
|
39617
40292
|
}
|
|
39618
40293
|
}
|
|
39619
|
-
var
|
|
40294
|
+
var import_node_fs46, import_node_path68, LOCK_WAIT_MS, LOCK_STALE_MS, LOCK_POLL_MS;
|
|
39620
40295
|
var init_token_store = __esm({
|
|
39621
40296
|
"src/auth/oauth/token-store.ts"() {
|
|
39622
40297
|
"use strict";
|
|
39623
|
-
|
|
39624
|
-
|
|
40298
|
+
import_node_fs46 = require("node:fs");
|
|
40299
|
+
import_node_path68 = require("node:path");
|
|
39625
40300
|
init_auth_file();
|
|
39626
40301
|
init_fs_retry();
|
|
39627
40302
|
init_types2();
|
|
@@ -39635,7 +40310,7 @@ var init_token_store = __esm({
|
|
|
39635
40310
|
|
|
39636
40311
|
// src/ai/providers/discovered-cache.ts
|
|
39637
40312
|
function discoveredCachePath(dataDir, provider) {
|
|
39638
|
-
return (0,
|
|
40313
|
+
return (0, import_node_path69.join)(dataDir, "models", "discovered", `${provider}.json`);
|
|
39639
40314
|
}
|
|
39640
40315
|
function toEntry(value) {
|
|
39641
40316
|
if (typeof value !== "object" || value === null) return void 0;
|
|
@@ -39655,7 +40330,7 @@ function toEntry(value) {
|
|
|
39655
40330
|
function readDiscoveredCache(dataDir, provider) {
|
|
39656
40331
|
let parsed;
|
|
39657
40332
|
try {
|
|
39658
|
-
parsed = JSON.parse((0,
|
|
40333
|
+
parsed = JSON.parse((0, import_node_fs47.readFileSync)(discoveredCachePath(dataDir, provider), "utf8"));
|
|
39659
40334
|
} catch {
|
|
39660
40335
|
return void 0;
|
|
39661
40336
|
}
|
|
@@ -39679,17 +40354,17 @@ function writeDiscoveredCache(dataDir, provider, input2, now = Date.now()) {
|
|
|
39679
40354
|
...input2.flavor !== void 0 ? { flavor: input2.flavor } : {},
|
|
39680
40355
|
models: input2.models.map(toEntry).filter((m) => m !== void 0)
|
|
39681
40356
|
};
|
|
39682
|
-
(0,
|
|
40357
|
+
(0, import_node_fs47.mkdirSync)((0, import_node_path69.dirname)(path), { recursive: true, mode: 448 });
|
|
39683
40358
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
39684
|
-
(0,
|
|
40359
|
+
(0, import_node_fs47.writeFileSync)(tmp, `${JSON.stringify(file, null, 2)}
|
|
39685
40360
|
`);
|
|
39686
|
-
(0,
|
|
40361
|
+
(0, import_node_fs47.renameSync)(tmp, path);
|
|
39687
40362
|
return path;
|
|
39688
40363
|
}
|
|
39689
40364
|
function clearDiscoveredCache(dataDir, provider) {
|
|
39690
40365
|
const path = discoveredCachePath(dataDir, provider);
|
|
39691
|
-
if (!(0,
|
|
39692
|
-
(0,
|
|
40366
|
+
if (!(0, import_node_fs47.existsSync)(path)) return false;
|
|
40367
|
+
(0, import_node_fs47.rmSync)(path, { force: true });
|
|
39693
40368
|
return true;
|
|
39694
40369
|
}
|
|
39695
40370
|
function thinkingMapOf(levels) {
|
|
@@ -39743,12 +40418,12 @@ function mergeDiscoveredModels(registry3, dataDir, modelsDev, loginFlavor = () =
|
|
|
39743
40418
|
}
|
|
39744
40419
|
return merged;
|
|
39745
40420
|
}
|
|
39746
|
-
var
|
|
40421
|
+
var import_node_fs47, import_node_path69, DISCOVERED_CACHE_VERSION, EFFORT_LEVELS, SUBSCRIPTION_FALLBACK_CONTEXT_WINDOW, SUBSCRIPTION_PROVIDERS;
|
|
39747
40422
|
var init_discovered_cache = __esm({
|
|
39748
40423
|
"src/ai/providers/discovered-cache.ts"() {
|
|
39749
40424
|
"use strict";
|
|
39750
|
-
|
|
39751
|
-
|
|
40425
|
+
import_node_fs47 = require("node:fs");
|
|
40426
|
+
import_node_path69 = require("node:path");
|
|
39752
40427
|
init_catalog2();
|
|
39753
40428
|
init_enrich();
|
|
39754
40429
|
DISCOVERED_CACHE_VERSION = 1;
|
|
@@ -41631,7 +42306,7 @@ function parseKeybindings(value) {
|
|
|
41631
42306
|
function loadKeybindingsFile(path) {
|
|
41632
42307
|
let text;
|
|
41633
42308
|
try {
|
|
41634
|
-
text = (0,
|
|
42309
|
+
text = (0, import_node_fs49.readFileSync)(path, "utf8");
|
|
41635
42310
|
} catch (error2) {
|
|
41636
42311
|
if (error2.code === "ENOENT") return { overrides: {}, warnings: [] };
|
|
41637
42312
|
return {
|
|
@@ -41648,12 +42323,12 @@ function loadKeybindingsFile(path) {
|
|
|
41648
42323
|
};
|
|
41649
42324
|
}
|
|
41650
42325
|
}
|
|
41651
|
-
var
|
|
42326
|
+
var import_node_fs49, DEFAULT_KEYBINDINGS, Keybindings, defaultKeybindings;
|
|
41652
42327
|
var init_keybindings = __esm({
|
|
41653
42328
|
"src/tui/keybindings.ts"() {
|
|
41654
42329
|
"use strict";
|
|
41655
42330
|
init_i18n();
|
|
41656
|
-
|
|
42331
|
+
import_node_fs49 = require("node:fs");
|
|
41657
42332
|
init_keys();
|
|
41658
42333
|
DEFAULT_KEYBINDINGS = {
|
|
41659
42334
|
"tui.editor.submit": ["enter"],
|
|
@@ -42489,7 +43164,7 @@ var init_editor_buffer = __esm({
|
|
|
42489
43164
|
function loadHistoryFile(path, limit = 500) {
|
|
42490
43165
|
let text;
|
|
42491
43166
|
try {
|
|
42492
|
-
text = (0,
|
|
43167
|
+
text = (0, import_node_fs50.readFileSync)(path, "utf8");
|
|
42493
43168
|
} catch {
|
|
42494
43169
|
return [];
|
|
42495
43170
|
}
|
|
@@ -42506,11 +43181,11 @@ function loadHistoryFile(path, limit = 500) {
|
|
|
42506
43181
|
}
|
|
42507
43182
|
function appendHistoryFile(path, entry, limit) {
|
|
42508
43183
|
try {
|
|
42509
|
-
(0,
|
|
42510
|
-
(0,
|
|
43184
|
+
(0, import_node_fs50.mkdirSync)((0, import_node_path71.dirname)(path), { recursive: true });
|
|
43185
|
+
(0, import_node_fs50.appendFileSync)(path, JSON.stringify(entry) + "\n", { mode: 384 });
|
|
42511
43186
|
const all = loadHistoryFile(path, Number.MAX_SAFE_INTEGER);
|
|
42512
43187
|
if (all.length > limit * 2) {
|
|
42513
|
-
(0,
|
|
43188
|
+
(0, import_node_fs50.writeFileSync)(
|
|
42514
43189
|
path,
|
|
42515
43190
|
all.slice(-limit).map((e) => JSON.stringify(e) + "\n").join("")
|
|
42516
43191
|
);
|
|
@@ -42518,12 +43193,12 @@ function appendHistoryFile(path, entry, limit) {
|
|
|
42518
43193
|
} catch {
|
|
42519
43194
|
}
|
|
42520
43195
|
}
|
|
42521
|
-
var
|
|
43196
|
+
var import_node_fs50, import_node_path71;
|
|
42522
43197
|
var init_editor_history = __esm({
|
|
42523
43198
|
"src/tui/components/editor-history.ts"() {
|
|
42524
43199
|
"use strict";
|
|
42525
|
-
|
|
42526
|
-
|
|
43200
|
+
import_node_fs50 = require("node:fs");
|
|
43201
|
+
import_node_path71 = require("node:path");
|
|
42527
43202
|
}
|
|
42528
43203
|
});
|
|
42529
43204
|
|
|
@@ -44097,7 +44772,7 @@ var init_key_docs = __esm({
|
|
|
44097
44772
|
|
|
44098
44773
|
// src/ai/providers/models-dev-cache.ts
|
|
44099
44774
|
function modelsDevCachePath(dataDir) {
|
|
44100
|
-
return (0,
|
|
44775
|
+
return (0, import_node_path73.join)(dataDir, MODELS_DEV_FILE);
|
|
44101
44776
|
}
|
|
44102
44777
|
function modelsDevUrl(env = process.env) {
|
|
44103
44778
|
const custom = env[MODELS_DEV_URL_ENV]?.trim();
|
|
@@ -44105,7 +44780,7 @@ function modelsDevUrl(env = process.env) {
|
|
|
44105
44780
|
}
|
|
44106
44781
|
function readModelsDevCache(dataDir) {
|
|
44107
44782
|
try {
|
|
44108
|
-
const value = JSON.parse((0,
|
|
44783
|
+
const value = JSON.parse((0, import_node_fs51.readFileSync)(modelsDevCachePath(dataDir), "utf8"));
|
|
44109
44784
|
if (typeof value !== "object" || value === null) return void 0;
|
|
44110
44785
|
const file = value;
|
|
44111
44786
|
if (file.version !== 2 || typeof file.fetchedAt !== "string") return void 0;
|
|
@@ -44118,10 +44793,10 @@ function readModelsDevCache(dataDir) {
|
|
|
44118
44793
|
}
|
|
44119
44794
|
function writeModelsDevCache(dataDir, file) {
|
|
44120
44795
|
const path = modelsDevCachePath(dataDir);
|
|
44121
|
-
(0,
|
|
44796
|
+
(0, import_node_fs51.mkdirSync)((0, import_node_path73.dirname)(path), { recursive: true, mode: 448 });
|
|
44122
44797
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
44123
|
-
(0,
|
|
44124
|
-
(0,
|
|
44798
|
+
(0, import_node_fs51.writeFileSync)(tmp, JSON.stringify(file));
|
|
44799
|
+
(0, import_node_fs51.renameSync)(tmp, path);
|
|
44125
44800
|
memo = void 0;
|
|
44126
44801
|
}
|
|
44127
44802
|
function overrideApplies(file) {
|
|
@@ -44131,7 +44806,7 @@ function loadModelsDevIndex(dataDir) {
|
|
|
44131
44806
|
const path = modelsDevCachePath(dataDir);
|
|
44132
44807
|
let key;
|
|
44133
44808
|
try {
|
|
44134
|
-
const stat16 = (0,
|
|
44809
|
+
const stat16 = (0, import_node_fs51.statSync)(path);
|
|
44135
44810
|
key = `${path}\0${stat16.mtimeMs}\0${stat16.size}`;
|
|
44136
44811
|
} catch {
|
|
44137
44812
|
return builtinSnapshotIndex();
|
|
@@ -44216,12 +44891,12 @@ function describeRefresh(result, limit = 20) {
|
|
|
44216
44891
|
}
|
|
44217
44892
|
return lines2.join("\n");
|
|
44218
44893
|
}
|
|
44219
|
-
var
|
|
44894
|
+
var import_node_fs51, import_node_path73, MODELS_DEV_URL, MODELS_DEV_URL_ENV, MODELS_DEV_FILE, MODELS_DEV_TIMEOUT_MS, memo;
|
|
44220
44895
|
var init_models_dev_cache = __esm({
|
|
44221
44896
|
"src/ai/providers/models-dev-cache.ts"() {
|
|
44222
44897
|
"use strict";
|
|
44223
|
-
|
|
44224
|
-
|
|
44898
|
+
import_node_fs51 = require("node:fs");
|
|
44899
|
+
import_node_path73 = require("node:path");
|
|
44225
44900
|
init_models_dev();
|
|
44226
44901
|
init_models_dev_snapshot();
|
|
44227
44902
|
init_i18n();
|
|
@@ -44519,7 +45194,7 @@ var init_json_schema = __esm({
|
|
|
44519
45194
|
init_schema_w5();
|
|
44520
45195
|
init_types_w5();
|
|
44521
45196
|
CONFIG_SCHEMA_FILE = "config.schema.json";
|
|
44522
|
-
CONFIG_SCHEMA_ID = "https://github.com/
|
|
45197
|
+
CONFIG_SCHEMA_ID = "https://github.com/AMA-Link/armadra-agent/config.schema.json";
|
|
44523
45198
|
KNOWN_APIS = [
|
|
44524
45199
|
"openai-completions",
|
|
44525
45200
|
"openai-responses",
|
|
@@ -44566,40 +45241,40 @@ function minimalConfig() {
|
|
|
44566
45241
|
}
|
|
44567
45242
|
function writeAtomic2(path, text, mode) {
|
|
44568
45243
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
44569
|
-
(0,
|
|
44570
|
-
(0,
|
|
45244
|
+
(0, import_node_fs52.writeFileSync)(tmp, text, { mode });
|
|
45245
|
+
(0, import_node_fs52.renameSync)(tmp, path);
|
|
44571
45246
|
}
|
|
44572
45247
|
function initConfigDir(dir, options = {}) {
|
|
44573
|
-
const dirCreated = !(0,
|
|
44574
|
-
(0,
|
|
44575
|
-
if (dirCreated && process.platform !== "win32") (0,
|
|
45248
|
+
const dirCreated = !(0, import_node_fs52.existsSync)(dir);
|
|
45249
|
+
(0, import_node_fs52.mkdirSync)(dir, { recursive: true, mode: 448 });
|
|
45250
|
+
if (dirCreated && process.platform !== "win32") (0, import_node_fs52.chmodSync)(dir, 448);
|
|
44576
45251
|
const files = [];
|
|
44577
|
-
const config = (0,
|
|
45252
|
+
const config = (0, import_node_path74.join)(dir, CONFIG_FILE);
|
|
44578
45253
|
const text = `${JSON.stringify(minimalConfig(), null, 2)}
|
|
44579
45254
|
`;
|
|
44580
|
-
if (!(0,
|
|
45255
|
+
if (!(0, import_node_fs52.existsSync)(config)) {
|
|
44581
45256
|
writeAtomic2(config, text, 420);
|
|
44582
45257
|
files.push({ path: config, status: "created" });
|
|
44583
45258
|
} else if (options.force) {
|
|
44584
|
-
(0,
|
|
45259
|
+
(0, import_node_fs52.copyFileSync)(config, `${config}.bak`);
|
|
44585
45260
|
writeAtomic2(config, text, 420);
|
|
44586
45261
|
files.push({ path: config, status: "overwritten" });
|
|
44587
45262
|
} else files.push({ path: config, status: "exists" });
|
|
44588
|
-
const schema = (0,
|
|
45263
|
+
const schema = (0, import_node_path74.join)(dir, CONFIG_SCHEMA_FILE);
|
|
44589
45264
|
const schemaText = configSchemaText();
|
|
44590
|
-
if (!(0,
|
|
45265
|
+
if (!(0, import_node_fs52.existsSync)(schema)) {
|
|
44591
45266
|
writeAtomic2(schema, schemaText, 420);
|
|
44592
45267
|
files.push({ path: schema, status: "created" });
|
|
44593
|
-
} else if ((0,
|
|
45268
|
+
} else if ((0, import_node_fs52.readFileSync)(schema, "utf8") !== schemaText) {
|
|
44594
45269
|
writeAtomic2(schema, schemaText, 420);
|
|
44595
45270
|
files.push({ path: schema, status: "updated" });
|
|
44596
45271
|
} else files.push({ path: schema, status: "unchanged" });
|
|
44597
|
-
const auth = (0,
|
|
44598
|
-
if ((0,
|
|
45272
|
+
const auth = (0, import_node_path74.join)(dir, AUTH_FILE);
|
|
45273
|
+
if ((0, import_node_fs52.existsSync)(auth)) files.push({ path: auth, status: "exists" });
|
|
44599
45274
|
return { dir, dirCreated, files };
|
|
44600
45275
|
}
|
|
44601
45276
|
function autoInitConfigDir(dir, env) {
|
|
44602
|
-
if (env[NO_INIT_ENV] === "1" || (0,
|
|
45277
|
+
if (env[NO_INIT_ENV] === "1" || (0, import_node_fs52.existsSync)(dir)) return false;
|
|
44603
45278
|
try {
|
|
44604
45279
|
initConfigDir(dir);
|
|
44605
45280
|
return true;
|
|
@@ -44617,12 +45292,12 @@ function describeInit(result) {
|
|
|
44617
45292
|
return `${lines2.join("\n")}
|
|
44618
45293
|
`;
|
|
44619
45294
|
}
|
|
44620
|
-
var
|
|
45295
|
+
var import_node_fs52, import_node_path74, NO_INIT_ENV;
|
|
44621
45296
|
var init_init = __esm({
|
|
44622
45297
|
"src/config/init.ts"() {
|
|
44623
45298
|
"use strict";
|
|
44624
|
-
|
|
44625
|
-
|
|
45299
|
+
import_node_fs52 = require("node:fs");
|
|
45300
|
+
import_node_path74 = require("node:path");
|
|
44626
45301
|
init_i18n();
|
|
44627
45302
|
init_json_schema();
|
|
44628
45303
|
init_paths();
|
|
@@ -45668,6 +46343,13 @@ function recoverChatGptError(error2, model, compat, options, apiKey, tried) {
|
|
|
45668
46343
|
return { kind: "retry" };
|
|
45669
46344
|
}
|
|
45670
46345
|
}
|
|
46346
|
+
if (backend === "codex" && error2.status === 400 && /not supported when using codex with a chatgpt account/i.test(error2.body))
|
|
46347
|
+
return {
|
|
46348
|
+
kind: "fail",
|
|
46349
|
+
error: new Error(
|
|
46350
|
+
`model_unavailable: ${msg().auth.request.modelUnavailable(`${provider}/${model.id}`)}`
|
|
46351
|
+
)
|
|
46352
|
+
};
|
|
45671
46353
|
if (backend === "codex" && error2.status === 400 && /instructions are not valid/i.test(error2.body) && !tried.has("instructions")) {
|
|
45672
46354
|
tried.add("instructions");
|
|
45673
46355
|
developerMode.add(sessionKeyOf(model, options));
|
|
@@ -47498,14 +48180,14 @@ var init_api = __esm({
|
|
|
47498
48180
|
// src/ai/providers/auth.ts
|
|
47499
48181
|
function defaultConfigDir(env = process.env) {
|
|
47500
48182
|
if (env["AMA_CONFIG_DIR"]) return env["AMA_CONFIG_DIR"];
|
|
47501
|
-
if (process.platform === "win32" && env["APPDATA"]) return (0,
|
|
47502
|
-
if (env["XDG_CONFIG_HOME"]) return (0,
|
|
47503
|
-
return (0,
|
|
48183
|
+
if (process.platform === "win32" && env["APPDATA"]) return (0, import_node_path75.join)(env["APPDATA"], "ama");
|
|
48184
|
+
if (env["XDG_CONFIG_HOME"]) return (0, import_node_path75.join)(env["XDG_CONFIG_HOME"], "ama");
|
|
48185
|
+
return (0, import_node_path75.join)(env["HOME"] ?? (0, import_node_os12.homedir)(), ".config", "ama");
|
|
47504
48186
|
}
|
|
47505
48187
|
function readAuthFile2(path, onWarning) {
|
|
47506
48188
|
let raw;
|
|
47507
48189
|
try {
|
|
47508
|
-
raw = (0,
|
|
48190
|
+
raw = (0, import_node_fs53.readFileSync)(path, "utf8");
|
|
47509
48191
|
} catch (error2) {
|
|
47510
48192
|
const code = error2.code;
|
|
47511
48193
|
if (code !== "ENOENT") onWarning?.(`cannot read auth file ${path}`);
|
|
@@ -47513,7 +48195,7 @@ function readAuthFile2(path, onWarning) {
|
|
|
47513
48195
|
}
|
|
47514
48196
|
if (process.platform !== "win32") {
|
|
47515
48197
|
try {
|
|
47516
|
-
const mode = (0,
|
|
48198
|
+
const mode = (0, import_node_fs53.statSync)(path).mode & 511;
|
|
47517
48199
|
if ((mode & 63) !== 0) {
|
|
47518
48200
|
onWarning?.(
|
|
47519
48201
|
`auth file ${path} has permissions ${mode.toString(8).padStart(4, "0")}; expected 0600`
|
|
@@ -47547,14 +48229,14 @@ function expandEnvRefs(value, env) {
|
|
|
47547
48229
|
);
|
|
47548
48230
|
return missing || out.length === 0 ? void 0 : out;
|
|
47549
48231
|
}
|
|
47550
|
-
var import_node_child_process13,
|
|
48232
|
+
var import_node_child_process13, import_node_fs53, import_node_os12, import_node_path75, ApiKeyResolver;
|
|
47551
48233
|
var init_auth2 = __esm({
|
|
47552
48234
|
"src/ai/providers/auth.ts"() {
|
|
47553
48235
|
"use strict";
|
|
47554
48236
|
import_node_child_process13 = require("node:child_process");
|
|
47555
|
-
|
|
47556
|
-
|
|
47557
|
-
|
|
48237
|
+
import_node_fs53 = require("node:fs");
|
|
48238
|
+
import_node_os12 = require("node:os");
|
|
48239
|
+
import_node_path75 = require("node:path");
|
|
47558
48240
|
init_live();
|
|
47559
48241
|
init_refresh();
|
|
47560
48242
|
init_token_store();
|
|
@@ -47574,7 +48256,7 @@ var init_auth2 = __esm({
|
|
|
47574
48256
|
authFiles() {
|
|
47575
48257
|
const files = [];
|
|
47576
48258
|
if (this.options.authFile) files.push(this.options.authFile);
|
|
47577
|
-
const user = this.options.userAuthFile === void 0 ? (0,
|
|
48259
|
+
const user = this.options.userAuthFile === void 0 ? (0, import_node_path75.join)(defaultConfigDir(this.env), "auth.json") : this.options.userAuthFile;
|
|
47578
48260
|
if (user && !files.includes(user)) files.push(user);
|
|
47579
48261
|
return files;
|
|
47580
48262
|
}
|
|
@@ -48340,26 +49022,26 @@ var init_settings_registry = __esm({
|
|
|
48340
49022
|
|
|
48341
49023
|
// src/config/write.ts
|
|
48342
49024
|
function writeConfigFile(path, config, options = {}) {
|
|
48343
|
-
(0,
|
|
49025
|
+
(0, import_node_fs54.mkdirSync)((0, import_node_path77.dirname)(path), { recursive: true });
|
|
48344
49026
|
let mode;
|
|
48345
49027
|
try {
|
|
48346
|
-
mode = (0,
|
|
49028
|
+
mode = (0, import_node_fs54.statSync)(path).mode & 511;
|
|
48347
49029
|
} catch {
|
|
48348
49030
|
mode = void 0;
|
|
48349
49031
|
}
|
|
48350
|
-
if (mode !== void 0 && options.backup !== false) (0,
|
|
49032
|
+
if (mode !== void 0 && options.backup !== false) (0, import_node_fs54.copyFileSync)(path, `${path}.bak`);
|
|
48351
49033
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
48352
|
-
(0,
|
|
49034
|
+
(0, import_node_fs54.writeFileSync)(tmp, `${JSON.stringify(config, null, 2)}
|
|
48353
49035
|
`, { mode: mode ?? 420 });
|
|
48354
|
-
if (mode !== void 0) (0,
|
|
48355
|
-
(0,
|
|
49036
|
+
if (mode !== void 0) (0, import_node_fs54.chmodSync)(tmp, mode);
|
|
49037
|
+
(0, import_node_fs54.renameSync)(tmp, path);
|
|
48356
49038
|
}
|
|
48357
|
-
var
|
|
49039
|
+
var import_node_fs54, import_node_path77;
|
|
48358
49040
|
var init_write2 = __esm({
|
|
48359
49041
|
"src/config/write.ts"() {
|
|
48360
49042
|
"use strict";
|
|
48361
|
-
|
|
48362
|
-
|
|
49043
|
+
import_node_fs54 = require("node:fs");
|
|
49044
|
+
import_node_path77 = require("node:path");
|
|
48363
49045
|
}
|
|
48364
49046
|
});
|
|
48365
49047
|
|
|
@@ -48557,7 +49239,7 @@ function parseEnum(key, text, options) {
|
|
|
48557
49239
|
function readTarget(path, scope) {
|
|
48558
49240
|
let text;
|
|
48559
49241
|
try {
|
|
48560
|
-
text = (0,
|
|
49242
|
+
text = (0, import_node_fs55.readFileSync)(path, "utf8");
|
|
48561
49243
|
} catch (error2) {
|
|
48562
49244
|
if (error2.code === "ENOENT")
|
|
48563
49245
|
return scope === "user" ? minimalConfig() : { version: CONFIG_FILE_VERSION };
|
|
@@ -48639,11 +49321,11 @@ function formatSettingValue(value) {
|
|
|
48639
49321
|
if (typeof value === "string") return value;
|
|
48640
49322
|
return JSON.stringify(value);
|
|
48641
49323
|
}
|
|
48642
|
-
var
|
|
49324
|
+
var import_node_fs55, ConfigEditError, same, ABOVE, TRUE, FALSE, UNSET;
|
|
48643
49325
|
var init_edit2 = __esm({
|
|
48644
49326
|
"src/config/edit.ts"() {
|
|
48645
49327
|
"use strict";
|
|
48646
|
-
|
|
49328
|
+
import_node_fs55 = require("node:fs");
|
|
48647
49329
|
init_errors();
|
|
48648
49330
|
init_i18n();
|
|
48649
49331
|
init_init();
|
|
@@ -48719,11 +49401,11 @@ async function readClipboardImage(dataDir, deps = {}) {
|
|
|
48719
49401
|
const platform = deps.platform ?? process.platform;
|
|
48720
49402
|
const env = deps.env ?? process.env;
|
|
48721
49403
|
const run7 = deps.run ?? runCommand;
|
|
48722
|
-
const dir = (0,
|
|
49404
|
+
const dir = (0, import_node_path80.join)(dataDir, CLIPBOARD_DIR);
|
|
48723
49405
|
await (0, import_promises22.mkdir)(dir, { recursive: true });
|
|
48724
49406
|
const stamp = new Date((deps.now ?? Date.now)()).toISOString().replace(/[:.]/g, "-");
|
|
48725
|
-
let file = (0,
|
|
48726
|
-
for (let n = 1; (0,
|
|
49407
|
+
let file = (0, import_node_path80.join)(dir, `${stamp}.png`);
|
|
49408
|
+
for (let n = 1; (0, import_node_fs61.existsSync)(file); n++) file = (0, import_node_path80.join)(dir, `${stamp}-${n}.png`);
|
|
48727
49409
|
let anyTool = false;
|
|
48728
49410
|
for (const attempt of attempts(platform, file, env)) {
|
|
48729
49411
|
const options = attempt.via === "file" && attempt.env !== void 0 ? { env: attempt.env } : {};
|
|
@@ -48742,7 +49424,7 @@ async function readClipboardImage(dataDir, deps = {}) {
|
|
|
48742
49424
|
return { ok: false, reason: anyTool ? "no_image" : "no_tool" };
|
|
48743
49425
|
}
|
|
48744
49426
|
async function gcClipboardImages(dataDir, options = {}) {
|
|
48745
|
-
const dir = (0,
|
|
49427
|
+
const dir = (0, import_node_path80.join)(dataDir, CLIPBOARD_DIR);
|
|
48746
49428
|
let names;
|
|
48747
49429
|
try {
|
|
48748
49430
|
names = await (0, import_promises22.readdir)(dir);
|
|
@@ -48752,7 +49434,7 @@ async function gcClipboardImages(dataDir, options = {}) {
|
|
|
48752
49434
|
const cutoff = (options.now ?? Date.now()) - (options.maxAgeDays ?? CLIPBOARD_MAX_AGE_DAYS) * 864e5;
|
|
48753
49435
|
const removed = [];
|
|
48754
49436
|
for (const name of names) {
|
|
48755
|
-
const file = (0,
|
|
49437
|
+
const file = (0, import_node_path80.join)(dir, name);
|
|
48756
49438
|
try {
|
|
48757
49439
|
const info2 = await (0, import_promises22.stat)(file);
|
|
48758
49440
|
if (!info2.isFile() || info2.mtimeMs >= cutoff) continue;
|
|
@@ -48763,13 +49445,13 @@ async function gcClipboardImages(dataDir, options = {}) {
|
|
|
48763
49445
|
}
|
|
48764
49446
|
return removed;
|
|
48765
49447
|
}
|
|
48766
|
-
var
|
|
49448
|
+
var import_node_fs61, import_promises22, import_node_path80, CLIPBOARD_DIR, CLIPBOARD_MAX_AGE_DAYS, OSASCRIPT, POWERSHELL;
|
|
48767
49449
|
var init_clipboard_image = __esm({
|
|
48768
49450
|
"src/tools/clipboard-image.ts"() {
|
|
48769
49451
|
"use strict";
|
|
48770
|
-
|
|
49452
|
+
import_node_fs61 = require("node:fs");
|
|
48771
49453
|
import_promises22 = require("node:fs/promises");
|
|
48772
|
-
|
|
49454
|
+
import_node_path80 = require("node:path");
|
|
48773
49455
|
init_image_file();
|
|
48774
49456
|
init_image_resize();
|
|
48775
49457
|
CLIPBOARD_DIR = "clipboard";
|
|
@@ -50156,7 +50838,7 @@ function statusCost(stats) {
|
|
|
50156
50838
|
function layoutRow(parts, width2, theme, style = {}) {
|
|
50157
50839
|
const sep5 = style.sep ?? " · ";
|
|
50158
50840
|
const dim = (text) => text === "" ? "" : theme.fg("dim", text);
|
|
50159
|
-
const
|
|
50841
|
+
const join68 = (list5) => {
|
|
50160
50842
|
let out = "";
|
|
50161
50843
|
let size = 0;
|
|
50162
50844
|
const add3 = (text, measured = visibleWidth(text)) => {
|
|
@@ -50188,7 +50870,7 @@ function layoutRow(parts, width2, theme, style = {}) {
|
|
|
50188
50870
|
const left = zone("left");
|
|
50189
50871
|
const right = zone("right");
|
|
50190
50872
|
const between = left.length === 0 || right.length === 0 ? 0 : sep5.length;
|
|
50191
|
-
return
|
|
50873
|
+
return join68(left)[1] + between + join68(right)[1] <= width2;
|
|
50192
50874
|
};
|
|
50193
50875
|
while (!fits()) {
|
|
50194
50876
|
const droppable = kept.filter((p) => p.priority !== void 0);
|
|
@@ -50196,8 +50878,8 @@ function layoutRow(parts, width2, theme, style = {}) {
|
|
|
50196
50878
|
const drop = droppable.reduce((worst, p) => p.priority > worst.priority ? p : worst);
|
|
50197
50879
|
kept = kept.filter((p) => p !== drop);
|
|
50198
50880
|
}
|
|
50199
|
-
const l =
|
|
50200
|
-
const r =
|
|
50881
|
+
const l = join68(zone("left"))[0];
|
|
50882
|
+
const r = join68(zone("right"))[0];
|
|
50201
50883
|
const gap = width2 - visibleWidth(l) - visibleWidth(r);
|
|
50202
50884
|
const line2 = r === "" ? l : l === "" ? " ".repeat(Math.max(0, gap)) + r : gap >= MIN_GAP ? l + " ".repeat(gap) + r : l + dim(sep5) + r;
|
|
50203
50885
|
return truncateToWidth(line2, width2);
|
|
@@ -50456,9 +51138,9 @@ function flat(text, max = 120) {
|
|
|
50456
51138
|
return one.length > max ? `${one.slice(0, max - 1)}…` : one;
|
|
50457
51139
|
}
|
|
50458
51140
|
function displayPath2(path, cwd) {
|
|
50459
|
-
if (cwd === void 0 || !(0,
|
|
50460
|
-
const rel = (0,
|
|
50461
|
-
return rel === "" ? "." : rel.startsWith("..") || (0,
|
|
51141
|
+
if (cwd === void 0 || !(0, import_node_path85.isAbsolute)(path)) return path;
|
|
51142
|
+
const rel = (0, import_node_path85.relative)(cwd, path);
|
|
51143
|
+
return rel === "" ? "." : rel.startsWith("..") || (0, import_node_path85.isAbsolute)(rel) ? path : rel;
|
|
50462
51144
|
}
|
|
50463
51145
|
function toolSummary(name, args, cwd) {
|
|
50464
51146
|
if (typeof args !== "object" || args === null) return "";
|
|
@@ -50613,12 +51295,12 @@ function resultSummary(input2, theme) {
|
|
|
50613
51295
|
return muted(count2 === 0 ? m.done : m.outputLines(count2));
|
|
50614
51296
|
}
|
|
50615
51297
|
}
|
|
50616
|
-
var
|
|
51298
|
+
var import_node_path85;
|
|
50617
51299
|
var init_tool_summary = __esm({
|
|
50618
51300
|
"src/modes/interactive/tool-summary.ts"() {
|
|
50619
51301
|
"use strict";
|
|
50620
51302
|
init_i18n();
|
|
50621
|
-
|
|
51303
|
+
import_node_path85 = require("node:path");
|
|
50622
51304
|
init_tui2();
|
|
50623
51305
|
init_status_bar();
|
|
50624
51306
|
}
|
|
@@ -51435,7 +52117,7 @@ function childLoader(read2 = readTraceInput) {
|
|
|
51435
52117
|
const load2 = ((file) => {
|
|
51436
52118
|
let stamp = "";
|
|
51437
52119
|
try {
|
|
51438
|
-
const st = (0,
|
|
52120
|
+
const st = (0, import_node_fs64.statSync)(file);
|
|
51439
52121
|
stamp = `${st.mtimeMs}:${st.size}`;
|
|
51440
52122
|
} catch {
|
|
51441
52123
|
stamp = "missing";
|
|
@@ -51479,11 +52161,11 @@ function traceText(session, taskId) {
|
|
|
51479
52161
|
`${msg().trace.taskTitle(node.taskId, node.agent)}${summary2}`
|
|
51480
52162
|
);
|
|
51481
52163
|
}
|
|
51482
|
-
var
|
|
52164
|
+
var import_node_fs64, LiveTracker, lineTraceCommand;
|
|
51483
52165
|
var init_session3 = __esm({
|
|
51484
52166
|
"src/trace/session.ts"() {
|
|
51485
52167
|
"use strict";
|
|
51486
|
-
|
|
52168
|
+
import_node_fs64 = require("node:fs");
|
|
51487
52169
|
init_session2();
|
|
51488
52170
|
init_i18n();
|
|
51489
52171
|
init_scan();
|
|
@@ -51557,10 +52239,10 @@ var init_session3 = __esm({
|
|
|
51557
52239
|
|
|
51558
52240
|
// src/skills/builtin.ts
|
|
51559
52241
|
function builtinSkillPath(dataDir, name) {
|
|
51560
|
-
return (0,
|
|
52242
|
+
return (0, import_node_path88.join)(dataDir, BUILTIN_SKILLS_DIR, `${name}.md`);
|
|
51561
52243
|
}
|
|
51562
52244
|
function isBuiltinSkill(skill) {
|
|
51563
|
-
return BUILTIN_SKILLS.some((b) => b.name === skill.name) && skill.location.endsWith((0,
|
|
52245
|
+
return BUILTIN_SKILLS.some((b) => b.name === skill.name) && skill.location.endsWith((0, import_node_path88.join)(BUILTIN_SKILLS_DIR, `${skill.name}.md`));
|
|
51564
52246
|
}
|
|
51565
52247
|
function builtinSkillText(skill) {
|
|
51566
52248
|
return `---
|
|
@@ -51575,7 +52257,7 @@ async function ensureFile(path, text) {
|
|
|
51575
52257
|
if (await (0, import_promises23.readFile)(path, "utf8") === text) return;
|
|
51576
52258
|
} catch {
|
|
51577
52259
|
}
|
|
51578
|
-
await (0, import_promises23.mkdir)((0,
|
|
52260
|
+
await (0, import_promises23.mkdir)((0, import_node_path88.dirname)(path), { recursive: true });
|
|
51579
52261
|
await (0, import_promises23.writeFile)(path, text, "utf8");
|
|
51580
52262
|
}
|
|
51581
52263
|
async function withBuiltinSkills(skills, dataDir, builtins = BUILTIN_SKILLS) {
|
|
@@ -51584,7 +52266,7 @@ async function withBuiltinSkills(skills, dataDir, builtins = BUILTIN_SKILLS) {
|
|
|
51584
52266
|
const taken = new Set(skills.map((skill) => skill.name));
|
|
51585
52267
|
for (const builtin2 of builtins) {
|
|
51586
52268
|
if (taken.has(builtin2.name)) continue;
|
|
51587
|
-
const baseDir = (0,
|
|
52269
|
+
const baseDir = (0, import_node_path88.join)(dataDir, BUILTIN_SKILLS_DIR);
|
|
51588
52270
|
const location = builtinSkillPath(dataDir, builtin2.name);
|
|
51589
52271
|
try {
|
|
51590
52272
|
await ensureFile(location, builtinSkillText(builtin2));
|
|
@@ -51605,16 +52287,16 @@ async function withBuiltinSkills(skills, dataDir, builtins = BUILTIN_SKILLS) {
|
|
|
51605
52287
|
}
|
|
51606
52288
|
return { skills: out, warnings };
|
|
51607
52289
|
}
|
|
51608
|
-
var import_promises23,
|
|
52290
|
+
var import_promises23, import_node_path88, BUILTIN_SKILLS_DIR, AMA_DOCS_BODY, BUILTIN_SKILLS;
|
|
51609
52291
|
var init_builtin3 = __esm({
|
|
51610
52292
|
"src/skills/builtin.ts"() {
|
|
51611
52293
|
"use strict";
|
|
51612
52294
|
import_promises23 = require("node:fs/promises");
|
|
51613
|
-
|
|
52295
|
+
import_node_path88 = require("node:path");
|
|
51614
52296
|
BUILTIN_SKILLS_DIR = "builtin";
|
|
51615
52297
|
AMA_DOCS_BODY = `# ama quick reference
|
|
51616
52298
|
|
|
51617
|
-
ama is the coding agent running this session. Docs: https://github.com/
|
|
52299
|
+
ama is the coding agent running this session. Docs: https://github.com/AMA-Link/armadra-agent (README.md, docs/).
|
|
51618
52300
|
|
|
51619
52301
|
## Files
|
|
51620
52302
|
- User config dir \`~/.config/ama/\` (\`AMA_CONFIG_DIR\`; Windows \`%APPDATA%\\ama\`): \`config.json\`, \`auth.json\` (keys, 0600), \`hooks.json\`, \`keybindings.json\`, \`trust.json\`, \`AGENTS.md\`, \`skills/\`, \`prompts/\`.
|
|
@@ -51663,33 +52345,33 @@ Skills: \`<dir>/<name>/SKILL.md\` with \`name\` and \`description\` frontmatter
|
|
|
51663
52345
|
// src/skills/discover.ts
|
|
51664
52346
|
function ancestorDirs(cwd) {
|
|
51665
52347
|
const out = [];
|
|
51666
|
-
let dir = (0,
|
|
52348
|
+
let dir = (0, import_node_path89.resolve)(cwd);
|
|
51667
52349
|
for (; ; ) {
|
|
51668
52350
|
out.push(dir);
|
|
51669
|
-
if ((0,
|
|
51670
|
-
const parent = (0,
|
|
52351
|
+
if ((0, import_node_fs66.existsSync)((0, import_node_path89.join)(dir, ".git"))) return out;
|
|
52352
|
+
const parent = (0, import_node_path89.dirname)(dir);
|
|
51671
52353
|
if (parent === dir) return out;
|
|
51672
52354
|
dir = parent;
|
|
51673
52355
|
}
|
|
51674
52356
|
}
|
|
51675
52357
|
function skillSources(options) {
|
|
51676
52358
|
const sources = [];
|
|
51677
|
-
const add3 = (dir, scope, requiresTrust) => sources.push({ dir: (0,
|
|
52359
|
+
const add3 = (dir, scope, requiresTrust) => sources.push({ dir: (0, import_node_path89.resolve)(options.cwd, dir), scope, requiresTrust });
|
|
51678
52360
|
for (const d of options.cliDirs ?? []) add3(d, "cli", false);
|
|
51679
52361
|
for (const d of options.profileDirs ?? []) add3(d, "profile", false);
|
|
51680
52362
|
for (const d of options.configDirs ?? []) add3(d, "config", false);
|
|
51681
|
-
add3((0,
|
|
51682
|
-
add3((0,
|
|
51683
|
-
for (const d of ancestorDirs(options.cwd)) add3((0,
|
|
52363
|
+
add3((0, import_node_path89.join)(options.configDir, "skills"), "user", false);
|
|
52364
|
+
add3((0, import_node_path89.join)(options.cwd, ".ama", "skills"), "project", true);
|
|
52365
|
+
for (const d of ancestorDirs(options.cwd)) add3((0, import_node_path89.join)(d, ".agents", "skills"), "ancestor", true);
|
|
51684
52366
|
return sources;
|
|
51685
52367
|
}
|
|
51686
52368
|
function parseSkill(text, location, scope) {
|
|
51687
52369
|
const warnings = [];
|
|
51688
52370
|
const fm = parseFrontmatter(text);
|
|
51689
52371
|
for (const e of fm.errors) warnings.push(`${location}: ${e}`);
|
|
51690
|
-
const baseDir = (0,
|
|
52372
|
+
const baseDir = (0, import_node_path89.dirname)(location);
|
|
51691
52373
|
const rawName = fm.data["name"];
|
|
51692
|
-
const name = typeof rawName === "string" && rawName !== "" ? rawName : (0,
|
|
52374
|
+
const name = typeof rawName === "string" && rawName !== "" ? rawName : (0, import_node_path89.basename)(baseDir);
|
|
51693
52375
|
if (name.length > MAX_SKILL_NAME || !SKILL_NAME_RE.test(name)) {
|
|
51694
52376
|
warnings.push(`${location}: invalid skill name "${name}" (lowercase letters, digits, -)`);
|
|
51695
52377
|
return { warnings };
|
|
@@ -51727,8 +52409,8 @@ async function isDir3(path) {
|
|
|
51727
52409
|
}
|
|
51728
52410
|
async function findSkillFiles(dir, depth = 0) {
|
|
51729
52411
|
if (depth > MAX_DEPTH3) return [];
|
|
51730
|
-
const own = (0,
|
|
51731
|
-
if ((0,
|
|
52412
|
+
const own = (0, import_node_path89.join)(dir, SKILL_FILE);
|
|
52413
|
+
if ((0, import_node_fs66.existsSync)(own)) return [own];
|
|
51732
52414
|
let names;
|
|
51733
52415
|
try {
|
|
51734
52416
|
names = await (0, import_promises24.readdir)(dir);
|
|
@@ -51739,7 +52421,7 @@ async function findSkillFiles(dir, depth = 0) {
|
|
|
51739
52421
|
const out = [];
|
|
51740
52422
|
for (const name of names) {
|
|
51741
52423
|
if (SKIP_DIRS.has(name)) continue;
|
|
51742
|
-
const child = (0,
|
|
52424
|
+
const child = (0, import_node_path89.join)(dir, name);
|
|
51743
52425
|
if (await isDir3(child)) out.push(...await findSkillFiles(child, depth + 1));
|
|
51744
52426
|
}
|
|
51745
52427
|
return out;
|
|
@@ -51780,13 +52462,13 @@ async function discoverSkills(sources, options) {
|
|
|
51780
52462
|
}
|
|
51781
52463
|
return result;
|
|
51782
52464
|
}
|
|
51783
|
-
var
|
|
52465
|
+
var import_node_fs66, import_promises24, import_node_path89, SKILL_FILE, SKILL_NAME_RE, MAX_SKILL_NAME, MAX_SKILL_DESCRIPTION, MAX_DEPTH3, SKIP_DIRS;
|
|
51784
52466
|
var init_discover2 = __esm({
|
|
51785
52467
|
"src/skills/discover.ts"() {
|
|
51786
52468
|
"use strict";
|
|
51787
|
-
|
|
52469
|
+
import_node_fs66 = require("node:fs");
|
|
51788
52470
|
import_promises24 = require("node:fs/promises");
|
|
51789
|
-
|
|
52471
|
+
import_node_path89 = require("node:path");
|
|
51790
52472
|
init_frontmatter2();
|
|
51791
52473
|
SKILL_FILE = "SKILL.md";
|
|
51792
52474
|
SKILL_NAME_RE = /^[a-z0-9-]+$/;
|
|
@@ -51901,14 +52583,14 @@ var init_protocol2 = __esm({
|
|
|
51901
52583
|
|
|
51902
52584
|
// src/codemode/host-side.ts
|
|
51903
52585
|
function resolveSandboxEntry(moduleUrl = __ama_import_meta_url) {
|
|
51904
|
-
const here = (0,
|
|
52586
|
+
const here = (0, import_node_path90.dirname)((0, import_node_url2.fileURLToPath)(moduleUrl));
|
|
51905
52587
|
const candidates2 = [];
|
|
51906
52588
|
if (true)
|
|
51907
|
-
candidates2.push((0,
|
|
51908
|
-
candidates2.push((0,
|
|
51909
|
-
candidates2.push((0,
|
|
52589
|
+
candidates2.push((0, import_node_path90.join)(here, "ama-sandbox.cjs"));
|
|
52590
|
+
candidates2.push((0, import_node_path90.join)(here, "sandbox-entry.js"));
|
|
52591
|
+
candidates2.push((0, import_node_path90.join)(here, "sandbox-entry.ts"));
|
|
51910
52592
|
for (const candidate of candidates2) {
|
|
51911
|
-
if ((0,
|
|
52593
|
+
if ((0, import_node_fs67.existsSync)(candidate)) return (0, import_node_fs67.realpathSync)(candidate);
|
|
51912
52594
|
}
|
|
51913
52595
|
return void 0;
|
|
51914
52596
|
}
|
|
@@ -52140,13 +52822,13 @@ async function runSandbox(request) {
|
|
|
52140
52822
|
child.stdin.end();
|
|
52141
52823
|
return result;
|
|
52142
52824
|
}
|
|
52143
|
-
var import_node_child_process16,
|
|
52825
|
+
var import_node_child_process16, import_node_fs67, import_node_path90, import_node_url2, MAX_COLLECTED_OUTPUT_CHARS, ABORT_GRACE_MS, DEFAULT_CODEMODE_HEAP_MB, CODEMODE_OS_POLICY;
|
|
52144
52826
|
var init_host_side = __esm({
|
|
52145
52827
|
"src/codemode/host-side.ts"() {
|
|
52146
52828
|
"use strict";
|
|
52147
52829
|
import_node_child_process16 = require("node:child_process");
|
|
52148
|
-
|
|
52149
|
-
|
|
52830
|
+
import_node_fs67 = require("node:fs");
|
|
52831
|
+
import_node_path90 = require("node:path");
|
|
52150
52832
|
import_node_url2 = require("node:url");
|
|
52151
52833
|
init_detect();
|
|
52152
52834
|
init_wrap();
|
|
@@ -52208,7 +52890,7 @@ var init_store5 = __esm({
|
|
|
52208
52890
|
});
|
|
52209
52891
|
|
|
52210
52892
|
// src/codemode/tool.ts
|
|
52211
|
-
function
|
|
52893
|
+
function textOf5(content) {
|
|
52212
52894
|
if (typeof content === "string") return content;
|
|
52213
52895
|
return content.map((block) => block.type === "text" ? block.text : "").join("");
|
|
52214
52896
|
}
|
|
@@ -52227,8 +52909,8 @@ function toScriptValue(name, result) {
|
|
|
52227
52909
|
if (s2.full_output_path !== void 0) value.fullOutputPath = s2.full_output_path;
|
|
52228
52910
|
return value;
|
|
52229
52911
|
}
|
|
52230
|
-
if (result.isError === true) throw new Error(
|
|
52231
|
-
return result.structured !== void 0 ? result.structured :
|
|
52912
|
+
if (result.isError === true) throw new Error(textOf5(result.content) || `Tool ${name} failed`);
|
|
52913
|
+
return result.structured !== void 0 ? result.structured : textOf5(result.content);
|
|
52232
52914
|
}
|
|
52233
52915
|
function scriptErrorHint(error2, toolNames2) {
|
|
52234
52916
|
if (/Cannot use import statement|dynamic import callback/.test(error2) || SCRIPT_ONLY_GLOBALS.test(error2)) {
|
|
@@ -52310,10 +52992,10 @@ ${output.slice(-half)}`;
|
|
|
52310
52992
|
}
|
|
52311
52993
|
function saveFullOutput(ctx, text) {
|
|
52312
52994
|
try {
|
|
52313
|
-
const dir = ctx.outputDir ?? (0,
|
|
52314
|
-
(0,
|
|
52315
|
-
const file = (0,
|
|
52316
|
-
(0,
|
|
52995
|
+
const dir = ctx.outputDir ?? (0, import_node_path91.join)((0, import_node_os14.tmpdir)(), "ama-codemode");
|
|
52996
|
+
(0, import_node_fs68.mkdirSync)(dir, { recursive: true });
|
|
52997
|
+
const file = (0, import_node_path91.join)(dir, `${ctx.toolCallId.replace(/[^A-Za-z0-9_-]/g, "_")}.txt`);
|
|
52998
|
+
(0, import_node_fs68.writeFileSync)(file, text, "utf8");
|
|
52317
52999
|
return file;
|
|
52318
53000
|
} catch {
|
|
52319
53001
|
return void 0;
|
|
@@ -52419,7 +53101,7 @@ function createCodemodeTool(options) {
|
|
|
52419
53101
|
return shown2;
|
|
52420
53102
|
},
|
|
52421
53103
|
renderResult(result, width2, expanded) {
|
|
52422
|
-
const lines2 =
|
|
53104
|
+
const lines2 = textOf5(result.content).split("\n");
|
|
52423
53105
|
const clip4 = (line2) => line2.slice(0, Math.max(10, width2));
|
|
52424
53106
|
if (expanded || lines2.length <= 8) return lines2.map(clip4);
|
|
52425
53107
|
return [clip4(lines2[0] ?? ""), `… ${lines2.length - 6} lines`, ...lines2.slice(-5).map(clip4)];
|
|
@@ -52465,13 +53147,13 @@ function codemodeToolFactory(overrides = {}) {
|
|
|
52465
53147
|
return createCodemodeTool(options);
|
|
52466
53148
|
};
|
|
52467
53149
|
}
|
|
52468
|
-
var
|
|
53150
|
+
var import_node_fs68, import_node_os14, import_node_path91, CODEMODE_TOOL_NAME2, DEFAULT_MAX_TOOL_RESULT_CHARS2, CODEMODE_EXAMPLE, SCRIPT_ONLY_GLOBALS, TAIL_CHARS, CODEMODE_ONLY_GUIDELINE;
|
|
52469
53151
|
var init_tool = __esm({
|
|
52470
53152
|
"src/codemode/tool.ts"() {
|
|
52471
53153
|
"use strict";
|
|
52472
|
-
|
|
52473
|
-
|
|
52474
|
-
|
|
53154
|
+
import_node_fs68 = require("node:fs");
|
|
53155
|
+
import_node_os14 = require("node:os");
|
|
53156
|
+
import_node_path91 = require("node:path");
|
|
52475
53157
|
init_presets2();
|
|
52476
53158
|
init_capability();
|
|
52477
53159
|
init_declarations();
|
|
@@ -52583,7 +53265,7 @@ var init_tool2 = __esm({
|
|
|
52583
53265
|
// src/cli/codemode-notice.ts
|
|
52584
53266
|
function readNotices(path) {
|
|
52585
53267
|
try {
|
|
52586
|
-
const value = JSON.parse((0,
|
|
53268
|
+
const value = JSON.parse((0, import_node_fs69.readFileSync)(path, "utf8"));
|
|
52587
53269
|
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
52588
53270
|
const shown2 = value[KEY];
|
|
52589
53271
|
return {
|
|
@@ -52602,26 +53284,26 @@ function takeCodemodeNotice(input2) {
|
|
|
52602
53284
|
const resolved = resolveCodemodeMode(input2.config, input2.capability.strict);
|
|
52603
53285
|
if (resolved.source !== "preset" || resolved.preset !== "default" || input2.capability.strict)
|
|
52604
53286
|
return void 0;
|
|
52605
|
-
const path = (0,
|
|
53287
|
+
const path = (0, import_node_path92.join)(input2.dataDir, NOTICES_FILE);
|
|
52606
53288
|
const notices = readNotices(path);
|
|
52607
53289
|
const shown2 = notices[KEY] ?? [];
|
|
52608
53290
|
if (shown2.includes(input2.configDir)) return void 0;
|
|
52609
53291
|
try {
|
|
52610
|
-
(0,
|
|
53292
|
+
(0, import_node_fs69.mkdirSync)(input2.dataDir, { recursive: true });
|
|
52611
53293
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
52612
|
-
(0,
|
|
53294
|
+
(0, import_node_fs69.writeFileSync)(tmp, `${JSON.stringify({ ...notices, [KEY]: [...shown2, input2.configDir] })}
|
|
52613
53295
|
`);
|
|
52614
|
-
(0,
|
|
53296
|
+
(0, import_node_fs69.renameSync)(tmp, path);
|
|
52615
53297
|
} catch {
|
|
52616
53298
|
}
|
|
52617
53299
|
return codemodeNoticeText(input2.capability);
|
|
52618
53300
|
}
|
|
52619
|
-
var
|
|
53301
|
+
var import_node_fs69, import_node_path92, NOTICES_FILE, KEY;
|
|
52620
53302
|
var init_codemode_notice = __esm({
|
|
52621
53303
|
"src/cli/codemode-notice.ts"() {
|
|
52622
53304
|
"use strict";
|
|
52623
|
-
|
|
52624
|
-
|
|
53305
|
+
import_node_fs69 = require("node:fs");
|
|
53306
|
+
import_node_path92 = require("node:path");
|
|
52625
53307
|
init_presets2();
|
|
52626
53308
|
init_i18n();
|
|
52627
53309
|
NOTICES_FILE = "notices.json";
|
|
@@ -52631,13 +53313,13 @@ var init_codemode_notice = __esm({
|
|
|
52631
53313
|
|
|
52632
53314
|
// src/ai/providers/max-tokens-cache.ts
|
|
52633
53315
|
function maxTokensCachePath(dataDir) {
|
|
52634
|
-
return (0,
|
|
53316
|
+
return (0, import_node_path93.join)(dataDir, "models", "max-tokens-caps.json");
|
|
52635
53317
|
}
|
|
52636
53318
|
function readEntries(dataDir, now) {
|
|
52637
53319
|
const out = /* @__PURE__ */ new Map();
|
|
52638
53320
|
let parsed;
|
|
52639
53321
|
try {
|
|
52640
|
-
parsed = JSON.parse((0,
|
|
53322
|
+
parsed = JSON.parse((0, import_node_fs70.readFileSync)(maxTokensCachePath(dataDir), "utf8"));
|
|
52641
53323
|
} catch {
|
|
52642
53324
|
return out;
|
|
52643
53325
|
}
|
|
@@ -52671,11 +53353,11 @@ function recordMaxTokensCap(dataDir, key, cap, now = Date.now) {
|
|
|
52671
53353
|
const path = maxTokensCachePath(dataDir);
|
|
52672
53354
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
52673
53355
|
try {
|
|
52674
|
-
(0,
|
|
53356
|
+
(0, import_node_fs70.mkdirSync)((0, import_node_path93.dirname)(path), { recursive: true, mode: 448 });
|
|
52675
53357
|
const caps = Object.fromEntries([...entries].sort(([a], [b]) => a < b ? -1 : 1));
|
|
52676
|
-
(0,
|
|
53358
|
+
(0, import_node_fs70.writeFileSync)(tmp, `${JSON.stringify({ version: MAX_TOKENS_CACHE_VERSION, caps }, null, 2)}
|
|
52677
53359
|
`);
|
|
52678
|
-
(0,
|
|
53360
|
+
(0, import_node_fs70.renameSync)(tmp, path);
|
|
52679
53361
|
} catch {
|
|
52680
53362
|
}
|
|
52681
53363
|
}
|
|
@@ -52691,12 +53373,12 @@ function attachMaxTokensCache(dataDir, now = Date.now) {
|
|
|
52691
53373
|
attached2.set(dataDir, detach);
|
|
52692
53374
|
return detach;
|
|
52693
53375
|
}
|
|
52694
|
-
var
|
|
53376
|
+
var import_node_fs70, import_node_path93, MAX_TOKENS_CACHE_VERSION, MAX_TOKENS_CACHE_TTL_MS, attached2;
|
|
52695
53377
|
var init_max_tokens_cache = __esm({
|
|
52696
53378
|
"src/ai/providers/max-tokens-cache.ts"() {
|
|
52697
53379
|
"use strict";
|
|
52698
|
-
|
|
52699
|
-
|
|
53380
|
+
import_node_fs70 = require("node:fs");
|
|
53381
|
+
import_node_path93 = require("node:path");
|
|
52700
53382
|
init_max_tokens();
|
|
52701
53383
|
MAX_TOKENS_CACHE_VERSION = 1;
|
|
52702
53384
|
MAX_TOKENS_CACHE_TTL_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
@@ -52836,8 +53518,8 @@ var init_compose_providers = __esm({
|
|
|
52836
53518
|
|
|
52837
53519
|
// src/modes/image-input.ts
|
|
52838
53520
|
function expand(path, cwd) {
|
|
52839
|
-
const home = path === "~" || path.startsWith("~/") ? (0,
|
|
52840
|
-
return (0,
|
|
53521
|
+
const home = path === "~" || path.startsWith("~/") ? (0, import_node_os15.homedir)() + path.slice(1) : path;
|
|
53522
|
+
return (0, import_node_path94.resolve)(cwd, home);
|
|
52841
53523
|
}
|
|
52842
53524
|
function findImageRefs(text, cwd) {
|
|
52843
53525
|
const out = [];
|
|
@@ -52849,7 +53531,7 @@ function findImageRefs(text, cwd) {
|
|
|
52849
53531
|
token = token.replace(/\\ /g, " ").replace(/[,\uFF0C\u3002;\uFF1B)\uFF09]+$/, "");
|
|
52850
53532
|
if (token === "" || imageMimeFromPath(token) === void 0) continue;
|
|
52851
53533
|
const path = expand(token, cwd);
|
|
52852
|
-
if (!explicit && !(0,
|
|
53534
|
+
if (!explicit && !(0, import_node_fs71.existsSync)(path)) continue;
|
|
52853
53535
|
if (seen.has(path)) continue;
|
|
52854
53536
|
seen.add(path);
|
|
52855
53537
|
out.push({ path, explicit });
|
|
@@ -52908,13 +53590,13 @@ async function loadLocalized(path, options) {
|
|
|
52908
53590
|
throw error2;
|
|
52909
53591
|
}
|
|
52910
53592
|
}
|
|
52911
|
-
var
|
|
53593
|
+
var import_node_fs71, import_node_os15, import_node_path94, TOKEN;
|
|
52912
53594
|
var init_image_input = __esm({
|
|
52913
53595
|
"src/modes/image-input.ts"() {
|
|
52914
53596
|
"use strict";
|
|
52915
|
-
|
|
52916
|
-
|
|
52917
|
-
|
|
53597
|
+
import_node_fs71 = require("node:fs");
|
|
53598
|
+
import_node_os15 = require("node:os");
|
|
53599
|
+
import_node_path94 = require("node:path");
|
|
52918
53600
|
init_channels();
|
|
52919
53601
|
init_errors();
|
|
52920
53602
|
init_image_limits();
|
|
@@ -52940,7 +53622,7 @@ function compactEvent(event) {
|
|
|
52940
53622
|
if (event.toolResults.length === 0) return event;
|
|
52941
53623
|
return {
|
|
52942
53624
|
...event,
|
|
52943
|
-
// 线上形状(docs/rpc.md)不是完整的 ToolResultMessage:正文与 details 都不带
|
|
53625
|
+
// 线上形状(docs/reference/rpc.md)不是完整的 ToolResultMessage:正文与 details 都不带
|
|
52944
53626
|
toolResults: event.toolResults.map(
|
|
52945
53627
|
({ toolCallId: toolCallId2, toolName, isError, timestamp }) => ({
|
|
52946
53628
|
toolCallId: toolCallId2,
|
|
@@ -53128,7 +53810,7 @@ async function runPrintMode(runtime, context) {
|
|
|
53128
53810
|
denied.push({
|
|
53129
53811
|
toolCallId: event.toolCallId,
|
|
53130
53812
|
toolName: event.toolName,
|
|
53131
|
-
reason:
|
|
53813
|
+
reason: textOf6(event)
|
|
53132
53814
|
});
|
|
53133
53815
|
const command3 = bashCommands.get(event.toolCallId);
|
|
53134
53816
|
if (event.toolName === "bash" && command3 !== void 0) deniedBash.push(command3);
|
|
@@ -53264,7 +53946,7 @@ function describeLimit(event) {
|
|
|
53264
53946
|
const m = msg().print.print;
|
|
53265
53947
|
return event.kind === "turns" ? m.limitTurns(event.limit) : m.limitCost(formatUsd(event.limit), formatUsd(event.value));
|
|
53266
53948
|
}
|
|
53267
|
-
function
|
|
53949
|
+
function textOf6(event) {
|
|
53268
53950
|
const content = event.result.content;
|
|
53269
53951
|
const text = typeof content === "string" ? content : content.map((b) => b.type === "text" ? b.text : "").join("");
|
|
53270
53952
|
return text.split("\n")[0]?.trim().slice(0, 200) ?? "";
|
|
@@ -53711,7 +54393,7 @@ function trustChoices() {
|
|
|
53711
54393
|
}
|
|
53712
54394
|
function isDirectory2(path) {
|
|
53713
54395
|
try {
|
|
53714
|
-
return (0,
|
|
54396
|
+
return (0, import_node_fs72.statSync)(path).isDirectory();
|
|
53715
54397
|
} catch {
|
|
53716
54398
|
return false;
|
|
53717
54399
|
}
|
|
@@ -53765,8 +54447,8 @@ function createStartupUi(options = {}) {
|
|
|
53765
54447
|
placeholder: m.cwdPlaceholder,
|
|
53766
54448
|
validate: (text) => {
|
|
53767
54449
|
if (text === "") return m.cwdEmpty;
|
|
53768
|
-
const abs = (0,
|
|
53769
|
-
if (!(0,
|
|
54450
|
+
const abs = (0, import_node_path95.resolve)(text);
|
|
54451
|
+
if (!(0, import_node_fs72.existsSync)(abs)) return m.cwdMissing(abs);
|
|
53770
54452
|
if (!isDirectory2(abs)) return m.cwdNotDir(abs);
|
|
53771
54453
|
return void 0;
|
|
53772
54454
|
}
|
|
@@ -53774,13 +54456,13 @@ function createStartupUi(options = {}) {
|
|
|
53774
54456
|
}
|
|
53775
54457
|
};
|
|
53776
54458
|
}
|
|
53777
|
-
var
|
|
54459
|
+
var import_node_fs72, import_node_path95;
|
|
53778
54460
|
var init_startup_ui = __esm({
|
|
53779
54461
|
"src/modes/interactive/startup-ui.ts"() {
|
|
53780
54462
|
"use strict";
|
|
53781
54463
|
init_i18n();
|
|
53782
|
-
|
|
53783
|
-
|
|
54464
|
+
import_node_fs72 = require("node:fs");
|
|
54465
|
+
import_node_path95 = require("node:path");
|
|
53784
54466
|
init_tui2();
|
|
53785
54467
|
init_model_items();
|
|
53786
54468
|
init_model_items();
|
|
@@ -54197,7 +54879,7 @@ function startupInfo(runtime, home) {
|
|
|
54197
54879
|
permissionMode: runtime.session.state.permissionMode,
|
|
54198
54880
|
preset: runtime.config.tools?.preset ?? "default",
|
|
54199
54881
|
codemode: effectiveCodemodeMode(runtime.config),
|
|
54200
|
-
contextFiles: resources.contextFiles.map((f) => (0,
|
|
54882
|
+
contextFiles: resources.contextFiles.map((f) => (0, import_node_path96.basename)(f.path)),
|
|
54201
54883
|
skills: resources.skills.filter((s2) => !isBuiltinSkill(s2)).length,
|
|
54202
54884
|
prompts: resources.prompts.length,
|
|
54203
54885
|
hooks: runtime.hooks.list().length,
|
|
@@ -54206,12 +54888,12 @@ function startupInfo(runtime, home) {
|
|
|
54206
54888
|
if (runtime.host !== void 0) info2.host = runtime.host.adapter.id;
|
|
54207
54889
|
return info2;
|
|
54208
54890
|
}
|
|
54209
|
-
var
|
|
54891
|
+
var import_node_path96;
|
|
54210
54892
|
var init_startup_screen = __esm({
|
|
54211
54893
|
"src/cli/startup-screen.ts"() {
|
|
54212
54894
|
"use strict";
|
|
54213
54895
|
init_builtin3();
|
|
54214
|
-
|
|
54896
|
+
import_node_path96 = require("node:path");
|
|
54215
54897
|
init_channels();
|
|
54216
54898
|
init_presets2();
|
|
54217
54899
|
init_i18n();
|
|
@@ -55126,7 +55808,7 @@ var init_commands = __esm({
|
|
|
55126
55808
|
},
|
|
55127
55809
|
get_commands: async (_p, ctx) => ({ commands: commands(ctx.runtime) }),
|
|
55128
55810
|
get_skills: async (_p, ctx) => ({ skills: ctx.runtime.resources.skills }),
|
|
55129
|
-
// [W5-F] 计划 / 任务命令(docs/wave5-plan.md §6.5、§7.5)
|
|
55811
|
+
// [W5-F] 计划 / 任务命令(docs/history/wave5-plan.md §6.5、§7.5)
|
|
55130
55812
|
plan_response: async (p, ctx) => {
|
|
55131
55813
|
const result = await plans(ctx).respond(p);
|
|
55132
55814
|
if (result.freshPrompt !== void 0) {
|
|
@@ -55141,7 +55823,7 @@ var init_commands = __esm({
|
|
|
55141
55823
|
get_todos: async (_p, ctx) => ({ items: currentTodos(impl(ctx.session()).manager.branch()) }),
|
|
55142
55824
|
get_tasks: async (_p, ctx) => ({ tasks: [...ctx.tasks?.()?.list() ?? []] }),
|
|
55143
55825
|
get_agents: async (_p, ctx) => ({ agents: [...ctx.agents?.() ?? []] }),
|
|
55144
|
-
// [W6-T2] 轨迹(docs/wave6-plan.md §2.6;分页 / 增量 / 脱敏见 trace/query.ts)
|
|
55826
|
+
// [W6-T2] 轨迹(docs/history/wave6-plan.md §2.6;分页 / 增量 / 脱敏见 trace/query.ts)
|
|
55145
55827
|
get_trace: async (p, ctx) => sessionTrace(ctx.session(), p ?? {}),
|
|
55146
55828
|
// [W7-B2] 前台任务转后台:工具调用立即返回、任务继续,完成后照常通知
|
|
55147
55829
|
background_task: async (p, ctx) => {
|
|
@@ -56954,29 +57636,29 @@ function runEditor(command3, file) {
|
|
|
56954
57636
|
return result.status;
|
|
56955
57637
|
}
|
|
56956
57638
|
async function editExternally(text, name, deps) {
|
|
56957
|
-
const dir = (0,
|
|
56958
|
-
const file = (0,
|
|
56959
|
-
(0,
|
|
57639
|
+
const dir = (0, import_node_fs73.mkdtempSync)((0, import_node_path97.join)((0, import_node_os16.tmpdir)(), "ama-edit-"));
|
|
57640
|
+
const file = (0, import_node_path97.join)(dir, name);
|
|
57641
|
+
(0, import_node_fs73.writeFileSync)(file, text);
|
|
56960
57642
|
deps.suspend();
|
|
56961
57643
|
try {
|
|
56962
57644
|
const code = (deps.run ?? runEditor)(editorCommand(deps.env, deps.platform), file);
|
|
56963
57645
|
if (code !== 0) return void 0;
|
|
56964
|
-
return (0,
|
|
57646
|
+
return (0, import_node_fs73.readFileSync)(file, "utf8");
|
|
56965
57647
|
} catch {
|
|
56966
57648
|
return void 0;
|
|
56967
57649
|
} finally {
|
|
56968
57650
|
deps.resume();
|
|
56969
|
-
(0,
|
|
57651
|
+
(0, import_node_fs73.rmSync)(dir, { recursive: true, force: true });
|
|
56970
57652
|
}
|
|
56971
57653
|
}
|
|
56972
|
-
var import_node_child_process17,
|
|
57654
|
+
var import_node_child_process17, import_node_fs73, import_node_os16, import_node_path97;
|
|
56973
57655
|
var init_external_editor = __esm({
|
|
56974
57656
|
"src/modes/interactive/external-editor.ts"() {
|
|
56975
57657
|
"use strict";
|
|
56976
57658
|
import_node_child_process17 = require("node:child_process");
|
|
56977
|
-
|
|
56978
|
-
|
|
56979
|
-
|
|
57659
|
+
import_node_fs73 = require("node:fs");
|
|
57660
|
+
import_node_os16 = require("node:os");
|
|
57661
|
+
import_node_path97 = require("node:path");
|
|
56980
57662
|
}
|
|
56981
57663
|
});
|
|
56982
57664
|
|
|
@@ -60996,9 +61678,9 @@ function parseLeftRight(text) {
|
|
|
60996
61678
|
async function hasUpstream(cwd, branch) {
|
|
60997
61679
|
const gitDir = await findGitDir(cwd);
|
|
60998
61680
|
if (gitDir === void 0) return false;
|
|
60999
|
-
const common = (await (0, import_promises25.readFile)((0,
|
|
61000
|
-
const dir = common === void 0 ? gitDir : (0,
|
|
61001
|
-
const text = await (0, import_promises25.readFile)((0,
|
|
61681
|
+
const common = (await (0, import_promises25.readFile)((0, import_node_path98.join)(gitDir, "commondir"), "utf8").catch(() => void 0))?.trim();
|
|
61682
|
+
const dir = common === void 0 ? gitDir : (0, import_node_path98.isAbsolute)(common) ? common : (0, import_node_path98.resolve)(gitDir, common);
|
|
61683
|
+
const text = await (0, import_promises25.readFile)((0, import_node_path98.join)(dir, "config"), "utf8").catch(() => "");
|
|
61002
61684
|
let inBranch = false;
|
|
61003
61685
|
for (const raw of text.split("\n")) {
|
|
61004
61686
|
const line2 = raw.trim();
|
|
@@ -61021,17 +61703,17 @@ async function readHead2(cwd) {
|
|
|
61021
61703
|
}
|
|
61022
61704
|
const gitDir = await findGitDir(cwd);
|
|
61023
61705
|
if (gitDir === void 0) return void 0;
|
|
61024
|
-
const text = await (0, import_promises25.readFile)((0,
|
|
61706
|
+
const text = await (0, import_promises25.readFile)((0, import_node_path98.join)(gitDir, "HEAD"), "utf8").catch(() => void 0);
|
|
61025
61707
|
const match = /^ref:\s*refs\/heads\/(\S+)\s*$/.exec(text ?? "");
|
|
61026
61708
|
return match?.[1] !== void 0 ? { branch: match[1] } : void 0;
|
|
61027
61709
|
}
|
|
61028
|
-
var import_node_child_process18, import_promises25,
|
|
61710
|
+
var import_node_child_process18, import_promises25, import_node_path98, GIT_NUMSTAT_INTERVAL_MS, GIT_NUMSTAT_TIMEOUT_MS, sameInfo, GitInfoWatcher;
|
|
61029
61711
|
var init_info = __esm({
|
|
61030
61712
|
"src/git/info.ts"() {
|
|
61031
61713
|
"use strict";
|
|
61032
61714
|
import_node_child_process18 = require("node:child_process");
|
|
61033
61715
|
import_promises25 = require("node:fs/promises");
|
|
61034
|
-
|
|
61716
|
+
import_node_path98 = require("node:path");
|
|
61035
61717
|
init_git_head();
|
|
61036
61718
|
GIT_NUMSTAT_INTERVAL_MS = 1e4;
|
|
61037
61719
|
GIT_NUMSTAT_TIMEOUT_MS = 2e3;
|
|
@@ -61327,12 +62009,12 @@ function statusLineText(mode) {
|
|
|
61327
62009
|
const m = msg().interactive.statusLine;
|
|
61328
62010
|
return mode === "full" ? m.full : m.compact;
|
|
61329
62011
|
}
|
|
61330
|
-
var
|
|
62012
|
+
var import_node_path99, WRITE_TOOLS3, QUOTA_TICK_MS, HintLine, StatusArea;
|
|
61331
62013
|
var init_status_area = __esm({
|
|
61332
62014
|
"src/modes/interactive/status-area.ts"() {
|
|
61333
62015
|
"use strict";
|
|
61334
62016
|
init_i18n();
|
|
61335
|
-
|
|
62017
|
+
import_node_path99 = require("node:path");
|
|
61336
62018
|
init_capability();
|
|
61337
62019
|
init_channels();
|
|
61338
62020
|
init_info();
|
|
@@ -61522,7 +62204,7 @@ var init_status_area = __esm({
|
|
|
61522
62204
|
gitView() {
|
|
61523
62205
|
const cwd = this.gitCwd;
|
|
61524
62206
|
if (cwd === void 0) return void 0;
|
|
61525
|
-
return { dir: (0,
|
|
62207
|
+
return { dir: (0, import_node_path99.basename)(cwd), info: this.git?.current() };
|
|
61526
62208
|
}
|
|
61527
62209
|
watchGit() {
|
|
61528
62210
|
const cwd = this.deps.session().state.cwd;
|
|
@@ -63849,15 +64531,15 @@ function processTerminal() {
|
|
|
63849
64531
|
return new ProcessTerminal();
|
|
63850
64532
|
}
|
|
63851
64533
|
function loadKeys(runtime, warn2) {
|
|
63852
|
-
const parsed = loadKeybindingsFile((0,
|
|
64534
|
+
const parsed = loadKeybindingsFile((0, import_node_path100.join)(runtime.paths.configDir, KEYBINDINGS_FILE));
|
|
63853
64535
|
for (const w of parsed.warnings) warn2(msg().interactive.app.keybindingsWarning(w));
|
|
63854
64536
|
return new Keybindings(parsed.overrides);
|
|
63855
64537
|
}
|
|
63856
|
-
var
|
|
64538
|
+
var import_node_path100;
|
|
63857
64539
|
var init_terminal_setup = __esm({
|
|
63858
64540
|
"src/modes/interactive/terminal-setup.ts"() {
|
|
63859
64541
|
"use strict";
|
|
63860
|
-
|
|
64542
|
+
import_node_path100 = require("node:path");
|
|
63861
64543
|
init_paths();
|
|
63862
64544
|
init_errors();
|
|
63863
64545
|
init_i18n();
|
|
@@ -63923,7 +64605,7 @@ function runInteractiveMode(runtime, context, options = {}) {
|
|
|
63923
64605
|
...options.statusLine !== void 0 ? { layout: options.statusLine } : {}
|
|
63924
64606
|
});
|
|
63925
64607
|
const { hint, bar: status } = area;
|
|
63926
|
-
const historyFile = options.historyFile === false ? void 0 : options.historyFile ?? (0,
|
|
64608
|
+
const historyFile = options.historyFile === false ? void 0 : options.historyFile ?? (0, import_node_path101.join)(runtime.paths.dataDir, "history");
|
|
63927
64609
|
const completion = new InteractiveCompletion({
|
|
63928
64610
|
commands: () => ALL_COMMANDS,
|
|
63929
64611
|
prompts: () => runtime.resources.prompts,
|
|
@@ -64287,12 +64969,12 @@ function runInteractiveMode(runtime, context, options = {}) {
|
|
|
64287
64969
|
}
|
|
64288
64970
|
});
|
|
64289
64971
|
}
|
|
64290
|
-
var
|
|
64972
|
+
var import_node_path101, HINT_MS;
|
|
64291
64973
|
var init_interactive_mode = __esm({
|
|
64292
64974
|
"src/modes/interactive/interactive-mode.ts"() {
|
|
64293
64975
|
"use strict";
|
|
64294
64976
|
init_image_input();
|
|
64295
|
-
|
|
64977
|
+
import_node_path101 = require("node:path");
|
|
64296
64978
|
init_session2();
|
|
64297
64979
|
init_compose_session();
|
|
64298
64980
|
init_startup_screen();
|
|
@@ -64368,7 +65050,7 @@ function choose(answer, values) {
|
|
|
64368
65050
|
}
|
|
64369
65051
|
function isDirectory3(path) {
|
|
64370
65052
|
try {
|
|
64371
|
-
return (0,
|
|
65053
|
+
return (0, import_node_fs74.statSync)(path).isDirectory();
|
|
64372
65054
|
} catch {
|
|
64373
65055
|
return false;
|
|
64374
65056
|
}
|
|
@@ -64412,8 +65094,8 @@ function createTextStartupUi(io) {
|
|
|
64412
65094
|
const m = msg().report.startup;
|
|
64413
65095
|
const answer = (await ask([m.cwdMissing(missing)], m.cwdAnswer))?.trim();
|
|
64414
65096
|
if (answer === void 0 || answer === "") return void 0;
|
|
64415
|
-
const abs = (0,
|
|
64416
|
-
if (!(0,
|
|
65097
|
+
const abs = (0, import_node_path102.resolve)(answer);
|
|
65098
|
+
if (!(0, import_node_fs74.existsSync)(abs) || !isDirectory3(abs)) {
|
|
64417
65099
|
io.write(m.notDirectory(abs));
|
|
64418
65100
|
return void 0;
|
|
64419
65101
|
}
|
|
@@ -64421,12 +65103,12 @@ function createTextStartupUi(io) {
|
|
|
64421
65103
|
}
|
|
64422
65104
|
};
|
|
64423
65105
|
}
|
|
64424
|
-
var
|
|
65106
|
+
var import_node_fs74, import_node_path102;
|
|
64425
65107
|
var init_startup_ui_text = __esm({
|
|
64426
65108
|
"src/modes/startup-ui-text.ts"() {
|
|
64427
65109
|
"use strict";
|
|
64428
|
-
|
|
64429
|
-
|
|
65110
|
+
import_node_fs74 = require("node:fs");
|
|
65111
|
+
import_node_path102 = require("node:path");
|
|
64430
65112
|
init_i18n();
|
|
64431
65113
|
}
|
|
64432
65114
|
});
|
|
@@ -64451,7 +65133,7 @@ function createTools(input2, options, state) {
|
|
|
64451
65133
|
const osStatus = configureOsSandbox(input2.config.sandbox?.enabled);
|
|
64452
65134
|
const bashSandbox = options.bashSandbox ?? resolveBashSandbox(input2.config.sandbox, {
|
|
64453
65135
|
status: osStatus,
|
|
64454
|
-
...input2.paths === void 0 ? {} : { hidden: [(0,
|
|
65136
|
+
...input2.paths === void 0 ? {} : { hidden: [(0, import_node_path103.join)(input2.paths.configDir, AUTH_FILE)] }
|
|
64455
65137
|
});
|
|
64456
65138
|
state.bashSandbox = bashSandbox;
|
|
64457
65139
|
const capability = options.sandboxCapability ?? sandboxCapabilityFor(input2.config);
|
|
@@ -64641,7 +65323,7 @@ function createRuntimeDeps(options = {}) {
|
|
|
64641
65323
|
if (ui !== void 0) deps.ui = ui;
|
|
64642
65324
|
return deps;
|
|
64643
65325
|
}
|
|
64644
|
-
var
|
|
65326
|
+
var import_node_path103, DEFAULT_TOOL_FACTORIES, DEFAULT_MODES;
|
|
64645
65327
|
var init_compose2 = __esm({
|
|
64646
65328
|
"src/cli/compose.ts"() {
|
|
64647
65329
|
"use strict";
|
|
@@ -64656,7 +65338,7 @@ var init_compose2 = __esm({
|
|
|
64656
65338
|
init_tool();
|
|
64657
65339
|
init_detect();
|
|
64658
65340
|
init_bash();
|
|
64659
|
-
|
|
65341
|
+
import_node_path103 = require("node:path");
|
|
64660
65342
|
init_paths();
|
|
64661
65343
|
init_presets2();
|
|
64662
65344
|
init_registry();
|
|
@@ -64871,8 +65553,8 @@ var init_memory3 = __esm({
|
|
|
64871
65553
|
});
|
|
64872
65554
|
|
|
64873
65555
|
// src/cli/main.ts
|
|
64874
|
-
var
|
|
64875
|
-
var
|
|
65556
|
+
var import_node_fs75 = require("node:fs");
|
|
65557
|
+
var import_node_path104 = require("node:path");
|
|
64876
65558
|
var import_node_url3 = require("node:url");
|
|
64877
65559
|
init_version();
|
|
64878
65560
|
init_args();
|
|
@@ -64880,7 +65562,7 @@ init_bootstrap();
|
|
|
64880
65562
|
init_exit_codes();
|
|
64881
65563
|
|
|
64882
65564
|
// src/cli/subcommands/auth.ts
|
|
64883
|
-
var
|
|
65565
|
+
var import_node_path72 = require("node:path");
|
|
64884
65566
|
init_builtin();
|
|
64885
65567
|
|
|
64886
65568
|
// src/auth/chatgpt/cli.ts
|
|
@@ -65160,15 +65842,15 @@ async function startCallbackServer(options) {
|
|
|
65160
65842
|
}
|
|
65161
65843
|
|
|
65162
65844
|
// src/auth/oauth/pkce.ts
|
|
65163
|
-
var
|
|
65845
|
+
var import_node_crypto17 = require("node:crypto");
|
|
65164
65846
|
function base64url(input2) {
|
|
65165
65847
|
return Buffer.from(input2).toString("base64url");
|
|
65166
65848
|
}
|
|
65167
65849
|
function randomToken(bytes = 32) {
|
|
65168
|
-
return base64url((0,
|
|
65850
|
+
return base64url((0, import_node_crypto17.randomBytes)(bytes));
|
|
65169
65851
|
}
|
|
65170
65852
|
function s256(verifier) {
|
|
65171
|
-
return base64url((0,
|
|
65853
|
+
return base64url((0, import_node_crypto17.createHash)("sha256").update(verifier, "ascii").digest());
|
|
65172
65854
|
}
|
|
65173
65855
|
function generatePkce() {
|
|
65174
65856
|
const verifier = randomToken(32);
|
|
@@ -65284,7 +65966,7 @@ async function loginDevice(preset, deps) {
|
|
|
65284
65966
|
}
|
|
65285
65967
|
|
|
65286
65968
|
// src/auth/oauth/jwt.ts
|
|
65287
|
-
var
|
|
65969
|
+
var import_node_crypto18 = require("node:crypto");
|
|
65288
65970
|
init_errors();
|
|
65289
65971
|
function invalid2(reason) {
|
|
65290
65972
|
return new AmaError("oauth_invalid_token", `invalid id_token: ${reason}`, { detail: { reason } });
|
|
@@ -65335,11 +66017,11 @@ function verifyJwtSignature(decoded, keys) {
|
|
|
65335
66017
|
if (candidates2.length === 0) throw invalid2("no matching key");
|
|
65336
66018
|
for (const jwk of candidates2) {
|
|
65337
66019
|
try {
|
|
65338
|
-
const key = (0,
|
|
65339
|
-
const ok = (0,
|
|
66020
|
+
const key = (0, import_node_crypto18.createPublicKey)({ key: jwk, format: "jwk" });
|
|
66021
|
+
const ok = (0, import_node_crypto18.verify)(
|
|
65340
66022
|
spec2.hash,
|
|
65341
66023
|
Buffer.from(decoded.signingInput),
|
|
65342
|
-
spec2.pss ? { key, padding:
|
|
66024
|
+
spec2.pss ? { key, padding: import_node_crypto18.constants.RSA_PKCS1_PSS_PADDING, saltLength: 32 } : spec2.ec ? { key, dsaEncoding: "ieee-p1363" } : key,
|
|
65343
66025
|
decoded.signature
|
|
65344
66026
|
);
|
|
65345
66027
|
if (ok) return;
|
|
@@ -65407,24 +66089,24 @@ async function validateIdToken(fetchFn, idToken, expect) {
|
|
|
65407
66089
|
init_token_client();
|
|
65408
66090
|
|
|
65409
66091
|
// src/auth/chatgpt/host-id.ts
|
|
65410
|
-
var
|
|
65411
|
-
var
|
|
65412
|
-
var
|
|
66092
|
+
var import_node_crypto19 = require("node:crypto");
|
|
66093
|
+
var import_node_fs48 = require("node:fs");
|
|
66094
|
+
var import_node_path70 = require("node:path");
|
|
65413
66095
|
var HOST_ID_FILE = "chatgpt-host.json";
|
|
65414
66096
|
function hostIdPath(dataDir) {
|
|
65415
|
-
return (0,
|
|
66097
|
+
return (0, import_node_path70.join)(dataDir, HOST_ID_FILE);
|
|
65416
66098
|
}
|
|
65417
66099
|
function readOrCreateHostId(dataDir) {
|
|
65418
66100
|
const path = hostIdPath(dataDir);
|
|
65419
66101
|
try {
|
|
65420
|
-
const value = JSON.parse((0,
|
|
66102
|
+
const value = JSON.parse((0, import_node_fs48.readFileSync)(path, "utf8"));
|
|
65421
66103
|
if (typeof value.hostId === "string" && /^urn:uuid:[0-9a-f-]{36}$/i.test(value.hostId))
|
|
65422
66104
|
return value.hostId;
|
|
65423
66105
|
} catch {
|
|
65424
66106
|
}
|
|
65425
|
-
const hostId = `urn:uuid:${(0,
|
|
65426
|
-
(0,
|
|
65427
|
-
(0,
|
|
66107
|
+
const hostId = `urn:uuid:${(0, import_node_crypto19.randomUUID)()}`;
|
|
66108
|
+
(0, import_node_fs48.mkdirSync)((0, import_node_path70.dirname)(path), { recursive: true, mode: 448 });
|
|
66109
|
+
(0, import_node_fs48.writeFileSync)(path, `${JSON.stringify({ version: 1, hostId }, null, 2)}
|
|
65428
66110
|
`, { mode: 384 });
|
|
65429
66111
|
return hostId;
|
|
65430
66112
|
}
|
|
@@ -65861,7 +66543,7 @@ async function runAuth(argv, io, deps = {}) {
|
|
|
65861
66543
|
return flags2.has("help") ? ExitCode.Ok : ExitCode.Usage;
|
|
65862
66544
|
}
|
|
65863
66545
|
const explicit = values.get("auth-file");
|
|
65864
|
-
const path = explicit !== void 0 ? (0,
|
|
66546
|
+
const path = explicit !== void 0 ? (0, import_node_path72.resolve)(io.cwd, explicit) : defaultAuthFilePath(resolveConfigDir({ env: io.env }));
|
|
65865
66547
|
const loginOnly = ["flavor", "port"].filter((name) => values.has(name));
|
|
65866
66548
|
const loginFlags = ["paste", "device", "no-browser", "yes"].filter((name) => flags2.has(name));
|
|
65867
66549
|
if (action !== "login" && [...loginOnly, ...loginFlags].length > 0)
|
|
@@ -65937,8 +66619,8 @@ init_merge();
|
|
|
65937
66619
|
init_key_docs();
|
|
65938
66620
|
init_paths();
|
|
65939
66621
|
var import_node_child_process14 = require("node:child_process");
|
|
65940
|
-
var
|
|
65941
|
-
var
|
|
66622
|
+
var import_node_fs57 = require("node:fs");
|
|
66623
|
+
var import_node_path79 = require("node:path");
|
|
65942
66624
|
init_models_dev_cache();
|
|
65943
66625
|
init_init();
|
|
65944
66626
|
init_json_schema();
|
|
@@ -65953,7 +66635,7 @@ init_default_model();
|
|
|
65953
66635
|
init_exit_codes();
|
|
65954
66636
|
|
|
65955
66637
|
// src/cli/subcommands/context.ts
|
|
65956
|
-
var
|
|
66638
|
+
var import_node_path76 = require("node:path");
|
|
65957
66639
|
init_auth_file();
|
|
65958
66640
|
init_load();
|
|
65959
66641
|
init_merge();
|
|
@@ -65974,7 +66656,7 @@ function loadUserLevel(io, options = {}) {
|
|
|
65974
66656
|
profile: profile?.config,
|
|
65975
66657
|
hasProfile: profile !== void 0
|
|
65976
66658
|
});
|
|
65977
|
-
const authFile = options.authFile !== void 0 ? (0,
|
|
66659
|
+
const authFile = options.authFile !== void 0 ? (0, import_node_path76.resolve)(io.cwd, options.authFile) : profile?.authFile ?? defaultAuthFilePath(configDir);
|
|
65978
66660
|
const result = { configDir, dataDir, merged, userConfigPath, authFile, warnings };
|
|
65979
66661
|
if (profile !== void 0) result.profile = profile;
|
|
65980
66662
|
return result;
|
|
@@ -65999,8 +66681,8 @@ init_ansi();
|
|
|
65999
66681
|
// src/cli/subcommands/config-set.ts
|
|
66000
66682
|
init_i18n();
|
|
66001
66683
|
init_edit2();
|
|
66002
|
-
var
|
|
66003
|
-
var
|
|
66684
|
+
var import_node_fs56 = require("node:fs");
|
|
66685
|
+
var import_node_path78 = require("node:path");
|
|
66004
66686
|
init_init();
|
|
66005
66687
|
init_paths();
|
|
66006
66688
|
init_profile();
|
|
@@ -66129,7 +66811,7 @@ async function runConfigEdit(action, argv, io, deps = {}) {
|
|
|
66129
66811
|
if (key === "permission.mode" && value === "full-auto" && scope === "user") {
|
|
66130
66812
|
if (!await confirmBypass(io, flags2.has("yes"), deps)) return ExitCode.Config;
|
|
66131
66813
|
}
|
|
66132
|
-
if (scope === "user" && !(0,
|
|
66814
|
+
if (scope === "user" && !(0, import_node_fs56.existsSync)((0, import_node_path78.join)(input2.configDir, CONFIG_FILE)))
|
|
66133
66815
|
initConfigDir(input2.configDir);
|
|
66134
66816
|
report(io, setConfigValue({ ...input2, scope, key, value }), value);
|
|
66135
66817
|
return ExitCode.Ok;
|
|
@@ -66142,17 +66824,17 @@ function showPaths(io) {
|
|
|
66142
66824
|
const configDir = resolveConfigDir({ env: io.env });
|
|
66143
66825
|
const dataDir = resolveDataDir({ env: io.env });
|
|
66144
66826
|
const m = msg().subcommands.configShow;
|
|
66145
|
-
const mark = (path) => `${path}${(0,
|
|
66827
|
+
const mark = (path) => `${path}${(0, import_node_fs57.existsSync)(path) ? "" : m.missing}`;
|
|
66146
66828
|
const width2 = Math.max(...[m.configDir, m.dataDir, m.projectLevel].map(visibleWidth)) + 2;
|
|
66147
66829
|
const label2 = (text) => padToWidth(text, width2);
|
|
66148
66830
|
const lines2 = [
|
|
66149
66831
|
`${label2(m.configDir)}${mark(configDir)}`,
|
|
66150
|
-
` config.json ${mark((0,
|
|
66151
|
-
` config.schema.json ${mark((0,
|
|
66152
|
-
` auth.json ${mark((0,
|
|
66153
|
-
` hooks.json ${mark((0,
|
|
66832
|
+
` config.json ${mark((0, import_node_path79.join)(configDir, CONFIG_FILE))}`,
|
|
66833
|
+
` config.schema.json ${mark((0, import_node_path79.join)(configDir, CONFIG_SCHEMA_FILE))}`,
|
|
66834
|
+
` auth.json ${mark((0, import_node_path79.join)(configDir, AUTH_FILE))}`,
|
|
66835
|
+
` hooks.json ${mark((0, import_node_path79.join)(configDir, HOOKS_FILE))}`,
|
|
66154
66836
|
`${label2(m.dataDir)}${mark(dataDir)}`,
|
|
66155
|
-
` sessions/ ${mark((0,
|
|
66837
|
+
` sessions/ ${mark((0, import_node_path79.join)(dataDir, "sessions"))}`,
|
|
66156
66838
|
` models-dev.json ${mark(modelsDevCachePath(dataDir))}`,
|
|
66157
66839
|
`${label2(m.projectLevel)}${mark(projectFile(io.cwd, CONFIG_FILE))}`
|
|
66158
66840
|
];
|
|
@@ -66162,8 +66844,8 @@ function showPaths(io) {
|
|
|
66162
66844
|
}
|
|
66163
66845
|
function editConfig(io) {
|
|
66164
66846
|
const configDir = resolveConfigDir({ env: io.env });
|
|
66165
|
-
const path = (0,
|
|
66166
|
-
if (!(0,
|
|
66847
|
+
const path = (0, import_node_path79.join)(configDir, CONFIG_FILE);
|
|
66848
|
+
if (!(0, import_node_fs57.existsSync)(path)) initConfigDir(configDir);
|
|
66167
66849
|
const editor = (io.env["VISUAL"] ?? io.env["EDITOR"] ?? "").trim();
|
|
66168
66850
|
if (editor === "") {
|
|
66169
66851
|
io.stdout(msg().subcommands.configShow.noEditor(path));
|
|
@@ -66455,7 +67137,7 @@ async function runConfig(argv, io, deps) {
|
|
|
66455
67137
|
}
|
|
66456
67138
|
|
|
66457
67139
|
// src/cli/subcommands/doctor.ts
|
|
66458
|
-
var
|
|
67140
|
+
var import_node_fs58 = require("node:fs");
|
|
66459
67141
|
init_blobs();
|
|
66460
67142
|
init_shadow_git();
|
|
66461
67143
|
init_gc();
|
|
@@ -66828,7 +67510,7 @@ async function runDoctor(argv, io, deps) {
|
|
|
66828
67510
|
const m = msg().report.doctor;
|
|
66829
67511
|
report2.section(m.dirsTitle);
|
|
66830
67512
|
report2.item(m.configDir(level.configDir));
|
|
66831
|
-
report2.item(m.dataDir(level.dataDir, (0,
|
|
67513
|
+
report2.item(m.dataDir(level.dataDir, (0, import_node_fs58.existsSync)(level.dataDir)));
|
|
66832
67514
|
await fileHistoryLine(report2, level.dataDir);
|
|
66833
67515
|
report2.section(m.layersTitle);
|
|
66834
67516
|
report2.item(m.builtinDefaults);
|
|
@@ -67056,7 +67738,7 @@ init_discovered_cache();
|
|
|
67056
67738
|
init_catalog2();
|
|
67057
67739
|
init_models_dev_cache();
|
|
67058
67740
|
init_models_dev();
|
|
67059
|
-
var
|
|
67741
|
+
var import_node_fs59 = require("node:fs");
|
|
67060
67742
|
init_load();
|
|
67061
67743
|
init_write2();
|
|
67062
67744
|
init_args();
|
|
@@ -67419,7 +68101,7 @@ function writeEntries(ctx, provider, entries, notes) {
|
|
|
67419
68101
|
return 0;
|
|
67420
68102
|
}
|
|
67421
68103
|
models.push(...added);
|
|
67422
|
-
const backup = (0,
|
|
68104
|
+
const backup = (0, import_node_fs59.existsSync)(path);
|
|
67423
68105
|
writeConfigFile(path, config, { backup: true });
|
|
67424
68106
|
io.stdout(m.written(path, provider.id, added.length, kept, backup));
|
|
67425
68107
|
if (notes.noTools.size > 0) io.stdout(m.skippedNoTools([...notes.noTools].join(", ")));
|
|
@@ -67844,7 +68526,7 @@ async function runModels(argv, io, deps) {
|
|
|
67844
68526
|
}
|
|
67845
68527
|
|
|
67846
68528
|
// src/cli/subcommands/providers.ts
|
|
67847
|
-
var
|
|
68529
|
+
var import_node_fs60 = require("node:fs");
|
|
67848
68530
|
init_models_dev_cache();
|
|
67849
68531
|
init_models_dev();
|
|
67850
68532
|
init_auth_file();
|
|
@@ -68501,7 +69183,7 @@ ${renderTable2(result.plans)}`);
|
|
|
68501
69183
|
const providers = config.providers ??= {};
|
|
68502
69184
|
providers[id] = merged.config;
|
|
68503
69185
|
if (defaultPick !== void 0) config.defaultModel = `${id}/${defaultPick.id}`;
|
|
68504
|
-
const backup = (0,
|
|
69186
|
+
const backup = (0, import_node_fs60.existsSync)(level.userConfigPath);
|
|
68505
69187
|
writeConfigFile(level.userConfigPath, config, { backup: true });
|
|
68506
69188
|
if (key.store !== void 0) setAuthKey(level.authFile, id, key.store);
|
|
68507
69189
|
io.stdout(m.written(level.userConfigPath, backup));
|
|
@@ -68617,7 +69299,7 @@ init_init();
|
|
|
68617
69299
|
init_paths();
|
|
68618
69300
|
|
|
68619
69301
|
// src/cli/subcommands/sessions.ts
|
|
68620
|
-
var
|
|
69302
|
+
var import_node_path87 = require("node:path");
|
|
68621
69303
|
init_gc();
|
|
68622
69304
|
init_paths();
|
|
68623
69305
|
init_args();
|
|
@@ -68626,8 +69308,8 @@ init_reuse();
|
|
|
68626
69308
|
init_clipboard_image();
|
|
68627
69309
|
|
|
68628
69310
|
// src/cli/subcommands/sessions-export.ts
|
|
68629
|
-
var
|
|
68630
|
-
var
|
|
69311
|
+
var import_node_fs62 = require("node:fs");
|
|
69312
|
+
var import_node_path81 = require("node:path");
|
|
68631
69313
|
init_paths();
|
|
68632
69314
|
|
|
68633
69315
|
// src/session/export.ts
|
|
@@ -68849,7 +69531,7 @@ async function runSessionsExport(argv, io) {
|
|
|
68849
69531
|
throw new UsageError(msg().subcommands.common.invalidChoice("--branch", BRANCHES, branch));
|
|
68850
69532
|
}
|
|
68851
69533
|
const dirFlag = values.get("session-dir");
|
|
68852
|
-
const root = dirFlag !== void 0 ? (0,
|
|
69534
|
+
const root = dirFlag !== void 0 ? (0, import_node_path81.resolve)(io.cwd, expandHome(dirFlag, { env: io.env })) : (0, import_node_path81.join)(resolveDataDir({ env: io.env }), "sessions");
|
|
68853
69535
|
const session = readSessionReadOnly(findSessionFileReadOnly(root, id, io.cwd));
|
|
68854
69536
|
const text = renderExport(session, format, branch);
|
|
68855
69537
|
const output = values.get("output");
|
|
@@ -68857,14 +69539,14 @@ async function runSessionsExport(argv, io) {
|
|
|
68857
69539
|
io.stdout(text);
|
|
68858
69540
|
return ExitCode.Ok;
|
|
68859
69541
|
}
|
|
68860
|
-
const target = (0,
|
|
68861
|
-
(0,
|
|
69542
|
+
const target = (0, import_node_path81.resolve)(io.cwd, expandHome(output, { env: io.env }));
|
|
69543
|
+
(0, import_node_fs62.writeFileSync)(target, text, { mode: 384 });
|
|
68862
69544
|
io.stderr(msg().subcommands.sessionsExport.exported(target));
|
|
68863
69545
|
return ExitCode.Ok;
|
|
68864
69546
|
}
|
|
68865
69547
|
|
|
68866
69548
|
// src/cli/subcommands/sessions-search.ts
|
|
68867
|
-
var
|
|
69549
|
+
var import_node_path84 = require("node:path");
|
|
68868
69550
|
init_paths();
|
|
68869
69551
|
init_scan();
|
|
68870
69552
|
|
|
@@ -69042,7 +69724,7 @@ init_args();
|
|
|
69042
69724
|
init_exit_codes();
|
|
69043
69725
|
|
|
69044
69726
|
// src/cli/subcommands/stats.ts
|
|
69045
|
-
var
|
|
69727
|
+
var import_node_path83 = require("node:path");
|
|
69046
69728
|
init_paths();
|
|
69047
69729
|
init_scan();
|
|
69048
69730
|
|
|
@@ -69190,8 +69872,8 @@ function aggregateStats(summaries, options = {}) {
|
|
|
69190
69872
|
}
|
|
69191
69873
|
|
|
69192
69874
|
// src/session/stats-index.ts
|
|
69193
|
-
var
|
|
69194
|
-
var
|
|
69875
|
+
var import_node_fs63 = require("node:fs");
|
|
69876
|
+
var import_node_path82 = require("node:path");
|
|
69195
69877
|
|
|
69196
69878
|
// src/session/stats-scan.ts
|
|
69197
69879
|
init_scan();
|
|
@@ -69404,7 +70086,7 @@ function collectSummaries(files, options = {}) {
|
|
|
69404
70086
|
let index2 = { version: INDEX_VERSION, zone, files: {} };
|
|
69405
70087
|
if (options.indexFile !== void 0) {
|
|
69406
70088
|
try {
|
|
69407
|
-
const loaded = JSON.parse((0,
|
|
70089
|
+
const loaded = JSON.parse((0, import_node_fs63.readFileSync)(options.indexFile, "utf8"));
|
|
69408
70090
|
if (loaded.version === INDEX_VERSION && loaded.zone === zone && typeof loaded.files === "object")
|
|
69409
70091
|
index2 = loaded;
|
|
69410
70092
|
} catch {
|
|
@@ -69415,7 +70097,7 @@ function collectSummaries(files, options = {}) {
|
|
|
69415
70097
|
for (const file of files) {
|
|
69416
70098
|
let stat16;
|
|
69417
70099
|
try {
|
|
69418
|
-
stat16 = (0,
|
|
70100
|
+
stat16 = (0, import_node_fs63.statSync)(file);
|
|
69419
70101
|
} catch {
|
|
69420
70102
|
result.invalid++;
|
|
69421
70103
|
continue;
|
|
@@ -69445,10 +70127,10 @@ function collectSummaries(files, options = {}) {
|
|
|
69445
70127
|
}
|
|
69446
70128
|
if (dirty && options.indexFile !== void 0) {
|
|
69447
70129
|
try {
|
|
69448
|
-
(0,
|
|
70130
|
+
(0, import_node_fs63.mkdirSync)((0, import_node_path82.dirname)(options.indexFile), { recursive: true, mode: 448 });
|
|
69449
70131
|
const tmp = `${options.indexFile}.${process.pid}.tmp`;
|
|
69450
|
-
(0,
|
|
69451
|
-
(0,
|
|
70132
|
+
(0, import_node_fs63.writeFileSync)(tmp, JSON.stringify(index2), { mode: 384 });
|
|
70133
|
+
(0, import_node_fs63.renameSync)(tmp, options.indexFile);
|
|
69452
70134
|
} catch {
|
|
69453
70135
|
}
|
|
69454
70136
|
}
|
|
@@ -69609,13 +70291,13 @@ async function runStats(argv, io) {
|
|
|
69609
70291
|
}
|
|
69610
70292
|
const dataDir = resolveDataDir({ env: io.env });
|
|
69611
70293
|
const dirFlag = values.get("session-dir");
|
|
69612
|
-
const root = dirFlag !== void 0 ? (0,
|
|
70294
|
+
const root = dirFlag !== void 0 ? (0, import_node_path83.resolve)(io.cwd, expandHome(dirFlag, { env: io.env })) : (0, import_node_path83.join)(dataDir, "sessions");
|
|
69613
70295
|
const projectFlag = values.get("project");
|
|
69614
|
-
const project = projectFlag !== void 0 ? (0,
|
|
70296
|
+
const project = projectFlag !== void 0 ? (0, import_node_path83.resolve)(io.cwd, expandHome(projectFlag, { env: io.env })) : flags2.has("all") || by === "project" ? void 0 : io.cwd;
|
|
69615
70297
|
const files = sessionFilesInScope(root, project);
|
|
69616
70298
|
const useCache = !flags2.has("no-cache");
|
|
69617
70299
|
const collected = collectSummaries(files, {
|
|
69618
|
-
...useCache ? { indexFile: (0,
|
|
70300
|
+
...useCache ? { indexFile: (0, import_node_path83.join)(dataDir, STATS_INDEX_FILE) } : {},
|
|
69619
70301
|
prune: project === void 0
|
|
69620
70302
|
});
|
|
69621
70303
|
const report2 = aggregateStats(collected.summaries, {
|
|
@@ -69710,7 +70392,7 @@ async function runSessionsSearch(argv, io) {
|
|
|
69710
70392
|
const sinceRaw = values.get("since");
|
|
69711
70393
|
const sinceIso = sinceRaw === void 0 ? void 0 : (/* @__PURE__ */ new Date(`${parseDaySpec("since", sinceRaw)}T00:00:00`)).toISOString();
|
|
69712
70394
|
const dirFlag = values.get("session-dir");
|
|
69713
|
-
const root = dirFlag !== void 0 ? (0,
|
|
70395
|
+
const root = dirFlag !== void 0 ? (0, import_node_path84.resolve)(io.cwd, expandHome(dirFlag, { env: io.env })) : (0, import_node_path84.join)(resolveDataDir({ env: io.env }), "sessions");
|
|
69714
70396
|
const files = sessionFilesInScope(root, flags2.has("all") ? void 0 : io.cwd);
|
|
69715
70397
|
const { hits, truncated } = searchSessions(files, query, {
|
|
69716
70398
|
limit,
|
|
@@ -69734,9 +70416,9 @@ async function runSessionsSearch(argv, io) {
|
|
|
69734
70416
|
|
|
69735
70417
|
// src/cli/subcommands/sessions-trace.ts
|
|
69736
70418
|
var import_node_child_process15 = require("node:child_process");
|
|
69737
|
-
var
|
|
69738
|
-
var
|
|
69739
|
-
var
|
|
70419
|
+
var import_node_fs65 = require("node:fs");
|
|
70420
|
+
var import_node_os13 = require("node:os");
|
|
70421
|
+
var import_node_path86 = require("node:path");
|
|
69740
70422
|
init_paths();
|
|
69741
70423
|
init_i18n();
|
|
69742
70424
|
init_scan();
|
|
@@ -70172,9 +70854,9 @@ function splitHtmlFlag(argv) {
|
|
|
70172
70854
|
return { rest, html, ...file !== void 0 ? { file } : {} };
|
|
70173
70855
|
}
|
|
70174
70856
|
function locate(io, target, dirFlag) {
|
|
70175
|
-
const asPath = (0,
|
|
70176
|
-
if (/[\\/]|\.jsonl$/.test(target) && (0,
|
|
70177
|
-
const root = dirFlag !== void 0 ? (0,
|
|
70857
|
+
const asPath = (0, import_node_path86.resolve)(io.cwd, expandHome(target, { env: io.env }));
|
|
70858
|
+
if (/[\\/]|\.jsonl$/.test(target) && (0, import_node_fs65.existsSync)(asPath)) return asPath;
|
|
70859
|
+
const root = dirFlag !== void 0 ? (0, import_node_path86.resolve)(io.cwd, expandHome(dirFlag, { env: io.env })) : (0, import_node_path86.join)(resolveDataDir({ env: io.env }), "sessions");
|
|
70178
70860
|
return findSessionFileReadOnly(root, target, io.cwd);
|
|
70179
70861
|
}
|
|
70180
70862
|
async function runSessionsTrace(argv, io, deps = {}) {
|
|
@@ -70239,14 +70921,14 @@ async function runSessionsTrace(argv, io, deps = {}) {
|
|
|
70239
70921
|
}
|
|
70240
70922
|
const outFlag = split.file ?? values.get("output");
|
|
70241
70923
|
const open3 = flags2.has("open");
|
|
70242
|
-
let outPath = outFlag === void 0 ? void 0 : (0,
|
|
70924
|
+
let outPath = outFlag === void 0 ? void 0 : (0, import_node_path86.resolve)(io.cwd, expandHome(outFlag, { env: io.env }));
|
|
70243
70925
|
if (outPath === void 0 && open3)
|
|
70244
|
-
outPath = (0,
|
|
70926
|
+
outPath = (0, import_node_path86.join)((0, import_node_os13.tmpdir)(), `ama-trace-${read2.header.id}.${wantsJson ? "json" : "html"}`);
|
|
70245
70927
|
if (outPath === void 0) {
|
|
70246
70928
|
io.stdout(text);
|
|
70247
70929
|
return ExitCode.Ok;
|
|
70248
70930
|
}
|
|
70249
|
-
(0,
|
|
70931
|
+
(0, import_node_fs65.writeFileSync)(outPath, text, { mode: 384 });
|
|
70250
70932
|
io.stderr(m.wrote(outPath));
|
|
70251
70933
|
if (open3) {
|
|
70252
70934
|
try {
|
|
@@ -70287,7 +70969,7 @@ async function runSessions(argv, io, deps) {
|
|
|
70287
70969
|
return flags2.has("help") ? ExitCode.Ok : ExitCode.Usage;
|
|
70288
70970
|
}
|
|
70289
70971
|
const dirFlag = values.get("session-dir");
|
|
70290
|
-
const sessionDir = dirFlag !== void 0 ? (0,
|
|
70972
|
+
const sessionDir = dirFlag !== void 0 ? (0, import_node_path87.resolve)(io.cwd, expandHome(dirFlag, { env: io.env })) : (0, import_node_path87.resolve)(resolveDataDir({ env: io.env }), "sessions");
|
|
70291
70973
|
const sessions = deps?.sessions;
|
|
70292
70974
|
const scope = flags2.has("all") ? {} : { cwd: io.cwd };
|
|
70293
70975
|
switch (action) {
|
|
@@ -70373,7 +71055,7 @@ async function pruneFileHistory(io, sessionDir, dryRun) {
|
|
|
70373
71055
|
try {
|
|
70374
71056
|
const result = await gcBlobs({
|
|
70375
71057
|
dataDir,
|
|
70376
|
-
sessionRoots: [sessionDir, (0,
|
|
71058
|
+
sessionRoots: [sessionDir, (0, import_node_path87.join)(dataDir, "sessions")],
|
|
70377
71059
|
dryRun
|
|
70378
71060
|
});
|
|
70379
71061
|
if (result.removed.length === 0) return;
|
|
@@ -70447,7 +71129,7 @@ function readStdinDefault() {
|
|
|
70447
71129
|
}
|
|
70448
71130
|
function stdinKindDefault() {
|
|
70449
71131
|
try {
|
|
70450
|
-
const stat16 = (0,
|
|
71132
|
+
const stat16 = (0, import_node_fs75.fstatSync)(0);
|
|
70451
71133
|
if (stat16.isFile()) return "file";
|
|
70452
71134
|
if (stat16.isFIFO()) return "fifo";
|
|
70453
71135
|
if (stat16.isSocket()) return "socket";
|
|
@@ -70507,7 +71189,7 @@ function defaultIo() {
|
|
|
70507
71189
|
}
|
|
70508
71190
|
function peekUserLanguage(env) {
|
|
70509
71191
|
try {
|
|
70510
|
-
const raw = (0,
|
|
71192
|
+
const raw = (0, import_node_fs75.readFileSync)((0, import_node_path104.join)(resolveConfigDir({ env }), "config.json"), "utf8");
|
|
70511
71193
|
const value = JSON.parse(raw).ui?.language;
|
|
70512
71194
|
return value === "auto" || value === "zh" || value === "en" ? value : void 0;
|
|
70513
71195
|
} catch {
|
|
@@ -70595,7 +71277,7 @@ function isDirectRun() {
|
|
|
70595
71277
|
const entry = process.argv[1];
|
|
70596
71278
|
if (entry === void 0) return false;
|
|
70597
71279
|
try {
|
|
70598
|
-
return (0,
|
|
71280
|
+
return (0, import_node_fs75.realpathSync)(entry) === (0, import_node_fs75.realpathSync)((0, import_node_url3.fileURLToPath)(__ama_import_meta_url));
|
|
70599
71281
|
} catch {
|
|
70600
71282
|
return false;
|
|
70601
71283
|
}
|