@armadra/agent 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +257 -0
- package/README.md +263 -95
- package/THIRD_PARTY_NOTICES.md +34 -0
- package/dist/acp.d.ts +18 -0
- package/dist/acp.js +19 -0
- package/dist/agent/limits.d.ts +38 -0
- package/dist/agent/limits.js +127 -0
- package/dist/agent/loop-guard.d.ts +38 -0
- package/dist/agent/loop-guard.js +95 -0
- package/dist/agent/loop.d.ts +4 -0
- package/dist/agent/loop.js +7 -0
- package/dist/agent/prompt-rules.d.ts +12 -0
- package/dist/agent/prompt-rules.js +18 -0
- package/dist/agent/reminders.d.ts +59 -0
- package/dist/agent/reminders.js +327 -0
- package/dist/agent/retry.d.ts +1 -1
- package/dist/agent/retry.js +2 -1
- package/dist/agent/session-cache.d.ts +5 -0
- package/dist/agent/session-cache.js +18 -2
- package/dist/agent/session-classifier.d.ts +18 -0
- package/dist/agent/session-classifier.js +105 -0
- package/dist/agent/session-compaction.d.ts +35 -6
- package/dist/agent/session-compaction.js +157 -31
- package/dist/agent/session-core.d.ts +40 -1
- package/dist/agent/session-extensions.d.ts +61 -0
- package/dist/agent/session-extensions.js +129 -0
- package/dist/agent/session-images.d.ts +23 -0
- package/dist/agent/session-images.js +97 -0
- package/dist/agent/session-plan.d.ts +21 -0
- package/dist/agent/session-plan.js +524 -0
- package/dist/agent/session-rewind.d.ts +81 -0
- package/dist/agent/session-rewind.js +354 -0
- package/dist/agent/session-run.d.ts +28 -1
- package/dist/agent/session-run.js +157 -6
- package/dist/agent/session-settings.d.ts +49 -0
- package/dist/agent/session-settings.js +95 -0
- package/dist/agent/session-subagent.d.ts +36 -24
- package/dist/agent/session-subagent.js +259 -129
- package/dist/agent/session-sync.d.ts +10 -3
- package/dist/agent/session-sync.js +37 -8
- package/dist/agent/session-telemetry.d.ts +39 -0
- package/dist/agent/session-telemetry.js +231 -0
- package/dist/agent/session-tools.js +63 -3
- package/dist/agent/session.d.ts +33 -29
- package/dist/agent/session.js +91 -126
- package/dist/agent/subagent-registry.d.ts +91 -0
- package/dist/agent/subagent-registry.js +494 -0
- package/dist/agent/system-prompt.d.ts +6 -3
- package/dist/agent/system-prompt.js +7 -2
- package/dist/agent/tool-runner.d.ts +8 -1
- package/dist/agent/tool-runner.js +72 -6
- package/dist/agent/types-w5.d.ts +192 -0
- package/dist/agent/types-w5.js +10 -0
- package/dist/agent/types.d.ts +55 -4
- package/dist/agent/types.js +2 -0
- package/dist/agent/worktree.d.ts +36 -0
- package/dist/agent/worktree.js +86 -0
- package/dist/agents/builtin.d.ts +14 -0
- package/dist/agents/builtin.js +39 -0
- package/dist/agents/catalog.d.ts +43 -0
- package/dist/agents/catalog.js +82 -0
- package/dist/agents/discover.d.ts +35 -0
- package/dist/agents/discover.js +83 -0
- package/dist/agents/external.d.ts +82 -0
- package/dist/agents/external.js +326 -0
- package/dist/agents/parse.d.ts +18 -0
- package/dist/agents/parse.js +116 -0
- package/dist/agents/result.d.ts +32 -0
- package/dist/agents/result.js +67 -0
- package/dist/agents/task-control.d.ts +17 -0
- package/dist/agents/task-control.js +17 -0
- package/dist/agents/task-record.d.ts +78 -0
- package/dist/agents/task-record.js +141 -0
- package/dist/agents/types.d.ts +46 -0
- package/dist/agents/types.js +8 -0
- package/dist/ai/apis/anthropic-compat.d.ts +36 -0
- package/dist/ai/apis/anthropic-compat.js +92 -0
- package/dist/ai/apis/anthropic-messages.js +3 -2
- package/dist/ai/apis/anthropic-request.d.ts +7 -6
- package/dist/ai/apis/anthropic-request.js +10 -28
- package/dist/ai/apis/cache-params.d.ts +11 -2
- package/dist/ai/apis/cache-params.js +25 -6
- package/dist/ai/apis/google-generative-ai.js +3 -2
- package/dist/ai/apis/openai-compat.d.ts +4 -1
- package/dist/ai/apis/openai-compat.js +8 -1
- package/dist/ai/apis/openai-completions.js +3 -2
- package/dist/ai/apis/openai-responses.js +3 -2
- package/dist/ai/http.d.ts +28 -6
- package/dist/ai/http.js +41 -8
- package/dist/ai/image-limits.d.ts +45 -0
- package/dist/ai/image-limits.js +68 -0
- package/dist/ai/providers/builtin.d.ts +18 -6
- package/dist/ai/providers/builtin.js +135 -6
- package/dist/ai/providers/catalog-data.js +17 -13
- package/dist/ai/providers/catalog.d.ts +60 -7
- package/dist/ai/providers/catalog.js +197 -38
- package/dist/ai/providers/channels.d.ts +33 -3
- package/dist/ai/providers/channels.js +108 -7
- package/dist/ai/providers/enrich.d.ts +6 -3
- package/dist/ai/providers/enrich.js +19 -4
- package/dist/ai/providers/models-dev-cache.d.ts +28 -24
- package/dist/ai/providers/models-dev-cache.js +92 -78
- package/dist/ai/providers/models-dev-data.d.ts +7 -0
- package/dist/ai/providers/models-dev-data.js +32 -0
- package/dist/ai/providers/models-dev-snapshot.d.ts +50 -0
- package/dist/ai/providers/models-dev-snapshot.js +137 -0
- package/dist/ai/providers/models-dev.d.ts +51 -10
- package/dist/ai/providers/models-dev.js +132 -39
- package/dist/ai/providers/registry.d.ts +28 -11
- package/dist/ai/providers/registry.js +112 -65
- package/dist/ai/providers/suggest.d.ts +18 -0
- package/dist/ai/providers/suggest.js +72 -0
- package/dist/ai/sse.d.ts +6 -2
- package/dist/ai/sse.js +22 -2
- package/dist/ai/types.d.ts +37 -4
- package/dist/ai/types.js +5 -0
- package/dist/bundle/ama.cjs +41979 -21147
- package/dist/checkpoints/backend.d.ts +61 -0
- package/dist/checkpoints/backend.js +135 -0
- package/dist/checkpoints/blobs.d.ts +60 -0
- package/dist/checkpoints/blobs.js +203 -0
- package/dist/checkpoints/gc.d.ts +47 -0
- package/dist/checkpoints/gc.js +144 -0
- package/dist/checkpoints/git-head.d.ts +15 -0
- package/dist/checkpoints/git-head.js +89 -0
- package/dist/checkpoints/index.d.ts +17 -0
- package/dist/checkpoints/index.js +17 -0
- package/dist/checkpoints/replay.d.ts +48 -0
- package/dist/checkpoints/replay.js +154 -0
- package/dist/checkpoints/restore.d.ts +86 -0
- package/dist/checkpoints/restore.js +263 -0
- package/dist/checkpoints/settings.d.ts +14 -0
- package/dist/checkpoints/settings.js +23 -0
- package/dist/checkpoints/shadow-git.d.ts +108 -0
- package/dist/checkpoints/shadow-git.js +491 -0
- package/dist/checkpoints/shadow-restore.d.ts +25 -0
- package/dist/checkpoints/shadow-restore.js +128 -0
- package/dist/checkpoints/tracker.d.ts +64 -0
- package/dist/checkpoints/tracker.js +192 -0
- package/dist/checkpoints/types.d.ts +99 -0
- package/dist/checkpoints/types.js +12 -0
- package/dist/cli/args.d.ts +26 -7
- package/dist/cli/args.js +75 -82
- package/dist/cli/bootstrap.js +40 -4
- package/dist/cli/codemode-notice.d.ts +21 -0
- package/dist/cli/codemode-notice.js +56 -0
- package/dist/cli/compose-agents.d.ts +27 -0
- package/dist/cli/compose-agents.js +111 -0
- package/dist/cli/compose-extensions.d.ts +29 -0
- package/dist/cli/compose-extensions.js +44 -0
- package/dist/cli/compose-session.d.ts +8 -0
- package/dist/cli/compose-session.js +76 -2
- package/dist/cli/compose-store.d.ts +1 -1
- package/dist/cli/compose-store.js +3 -1
- package/dist/cli/compose.d.ts +17 -4
- package/dist/cli/compose.js +60 -14
- package/dist/cli/default-model.d.ts +38 -1
- package/dist/cli/default-model.js +96 -9
- package/dist/cli/deps.d.ts +42 -0
- package/dist/cli/exit-codes.d.ts +12 -0
- package/dist/cli/exit-codes.js +15 -0
- package/dist/cli/fake-visibility.d.ts +13 -0
- package/dist/cli/fake-visibility.js +26 -0
- package/dist/cli/from-prompt.d.ts +18 -0
- package/dist/cli/from-prompt.js +49 -0
- package/dist/cli/help-text.d.ts +4 -0
- package/dist/cli/help-text.js +102 -0
- package/dist/cli/main.d.ts +9 -2
- package/dist/cli/main.js +77 -3
- package/dist/cli/proxy.d.ts +51 -0
- package/dist/cli/proxy.js +135 -0
- package/dist/cli/startup-screen.d.ts +29 -0
- package/dist/cli/startup-screen.js +51 -2
- package/dist/cli/startup-steps.d.ts +1 -1
- package/dist/cli/startup-steps.js +21 -13
- package/dist/cli/subcommands/config.d.ts +22 -3
- package/dist/cli/subcommands/config.js +119 -21
- package/dist/cli/subcommands/context.js +4 -1
- package/dist/cli/subcommands/doctor.js +33 -1
- package/dist/cli/subcommands/init.js +2 -1
- package/dist/cli/subcommands/models-discover.d.ts +15 -9
- package/dist/cli/subcommands/models-discover.js +58 -52
- package/dist/cli/subcommands/models.d.ts +2 -0
- package/dist/cli/subcommands/models.js +33 -14
- package/dist/cli/subcommands/probe-runner.d.ts +96 -0
- package/dist/cli/subcommands/probe-runner.js +264 -0
- package/dist/cli/subcommands/providers-probe.d.ts +34 -0
- package/dist/cli/subcommands/providers-probe.js +87 -0
- package/dist/cli/subcommands/providers.d.ts +3 -2
- package/dist/cli/subcommands/providers.js +53 -51
- package/dist/cli/subcommands/sessions-export.d.ts +10 -0
- package/dist/cli/subcommands/sessions-export.js +59 -0
- package/dist/cli/subcommands/sessions-search.d.ts +13 -0
- package/dist/cli/subcommands/sessions-search.js +103 -0
- package/dist/cli/subcommands/sessions.d.ts +6 -3
- package/dist/cli/subcommands/sessions.js +58 -3
- package/dist/cli/subcommands/stats.d.ts +17 -0
- package/dist/cli/subcommands/stats.js +198 -0
- package/dist/cli/system-prompt-arg.d.ts +11 -0
- package/dist/cli/system-prompt-arg.js +34 -0
- package/dist/codemode/capability.d.ts +24 -7
- package/dist/codemode/capability.js +38 -10
- package/dist/codemode/host-side.d.ts +14 -0
- package/dist/codemode/host-side.js +24 -1
- package/dist/codemode/modes.d.ts +4 -11
- package/dist/codemode/modes.js +5 -27
- package/dist/codemode/tool.d.ts +18 -14
- package/dist/codemode/tool.js +76 -31
- package/dist/compaction/breaker.d.ts +25 -9
- package/dist/compaction/breaker.js +47 -17
- package/dist/compaction/estimate.d.ts +11 -3
- package/dist/compaction/estimate.js +64 -22
- package/dist/compaction/image-budget.d.ts +45 -0
- package/dist/compaction/image-budget.js +115 -0
- package/dist/compaction/post-compact.d.ts +38 -0
- package/dist/compaction/post-compact.js +152 -0
- package/dist/compaction/protect.d.ts +27 -0
- package/dist/compaction/protect.js +56 -0
- package/dist/compaction/prune-tier.d.ts +58 -12
- package/dist/compaction/prune-tier.js +120 -54
- package/dist/compaction/summarize-tier.d.ts +23 -4
- package/dist/compaction/summarize-tier.js +100 -29
- package/dist/config/checker.d.ts +28 -0
- package/dist/config/checker.js +97 -0
- package/dist/config/init.d.ts +6 -2
- package/dist/config/init.js +12 -5
- package/dist/config/json-schema.d.ts +1 -0
- package/dist/config/json-schema.js +98 -4
- package/dist/config/key-docs.d.ts +22 -0
- package/dist/config/key-docs.js +174 -0
- package/dist/config/merge.d.ts +12 -9
- package/dist/config/merge.js +102 -13
- package/dist/config/profile.d.ts +2 -0
- package/dist/config/profile.js +2 -0
- package/dist/config/schema-w5.d.ts +18 -0
- package/dist/config/schema-w5.js +109 -0
- package/dist/config/schema.d.ts +5 -9
- package/dist/config/schema.js +91 -118
- package/dist/config/types-w5.d.ts +118 -0
- package/dist/config/types-w5.js +20 -0
- package/dist/config/types.d.ts +84 -7
- package/dist/config/types.js +29 -1
- package/dist/drivers/acp/client.d.ts +57 -0
- package/dist/drivers/acp/client.js +160 -0
- package/dist/drivers/acp/driver.d.ts +31 -0
- package/dist/drivers/acp/driver.js +274 -0
- package/dist/drivers/acp/testing/fake-agent-main.d.ts +5 -0
- package/dist/drivers/acp/testing/fake-agent-main.js +7 -0
- package/dist/drivers/acp/testing/fake-agent.d.ts +27 -0
- package/dist/drivers/acp/testing/fake-agent.js +211 -0
- package/dist/drivers/acp/types.d.ts +285 -0
- package/dist/drivers/acp/types.js +36 -0
- package/dist/drivers/agents.d.ts +58 -0
- package/dist/drivers/agents.js +142 -0
- package/dist/drivers/base.d.ts +35 -0
- package/dist/drivers/base.js +59 -0
- package/dist/drivers/catalog.d.ts +46 -0
- package/dist/drivers/catalog.js +167 -0
- package/dist/drivers/env.d.ts +20 -0
- package/dist/drivers/env.js +46 -0
- package/dist/drivers/host-runners.d.ts +18 -0
- package/dist/drivers/host-runners.js +45 -0
- package/dist/drivers/jsonrpc.d.ts +58 -0
- package/dist/drivers/jsonrpc.js +180 -0
- package/dist/drivers/native/claude-normalize.d.ts +46 -0
- package/dist/drivers/native/claude-normalize.js +106 -0
- package/dist/drivers/native/claude-stream.d.ts +29 -0
- package/dist/drivers/native/claude-stream.js +456 -0
- package/dist/drivers/native/codex-app-server.d.ts +26 -0
- package/dist/drivers/native/codex-app-server.js +407 -0
- package/dist/drivers/native/codex-normalize.d.ts +38 -0
- package/dist/drivers/native/codex-normalize.js +124 -0
- package/dist/drivers/native/oneshot.d.ts +28 -0
- package/dist/drivers/native/oneshot.js +312 -0
- package/dist/drivers/permissions.d.ts +40 -0
- package/dist/drivers/permissions.js +92 -0
- package/dist/drivers/pids.d.ts +32 -0
- package/dist/drivers/pids.js +93 -0
- package/dist/drivers/pool.d.ts +28 -0
- package/dist/drivers/pool.js +96 -0
- package/dist/drivers/probe.d.ts +47 -0
- package/dist/drivers/probe.js +172 -0
- package/dist/drivers/process.d.ts +48 -0
- package/dist/drivers/process.js +100 -0
- package/dist/drivers/runner.d.ts +61 -0
- package/dist/drivers/runner.js +388 -0
- package/dist/drivers/store.d.ts +49 -0
- package/dist/drivers/store.js +91 -0
- package/dist/drivers/turn.d.ts +41 -0
- package/dist/drivers/turn.js +99 -0
- package/dist/drivers/types.d.ts +122 -0
- package/dist/drivers/types.js +11 -0
- package/dist/git/info.d.ts +75 -0
- package/dist/git/info.js +191 -0
- package/dist/hooks/protocol.js +6 -1
- package/dist/hooks/types.d.ts +10 -1
- package/dist/hooks/types.js +2 -0
- package/dist/host/api-impl.d.ts +7 -0
- package/dist/host/api-impl.js +15 -0
- package/dist/host/types.d.ts +24 -2
- package/dist/host/types.js +4 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1 -0
- package/dist/modes/acp/acp-events.d.ts +46 -0
- package/dist/modes/acp/acp-events.js +233 -0
- package/dist/modes/acp/acp-mode.d.ts +17 -0
- package/dist/modes/acp/acp-mode.js +47 -0
- package/dist/modes/acp/acp-server.d.ts +79 -0
- package/dist/modes/acp/acp-server.js +315 -0
- package/dist/modes/commands-core.d.ts +7 -1
- package/dist/modes/commands-core.js +61 -5
- package/dist/modes/image-input.d.ts +12 -4
- package/dist/modes/image-input.js +22 -5
- package/dist/modes/interactive/agent-panels.d.ts +14 -0
- package/dist/modes/interactive/agent-panels.js +103 -0
- package/dist/modes/interactive/agent-ui.d.ts +73 -0
- package/dist/modes/interactive/agent-ui.js +234 -0
- package/dist/modes/interactive/approval-dialog.d.ts +40 -7
- package/dist/modes/interactive/approval-dialog.js +192 -35
- package/dist/modes/interactive/approval-merge.d.ts +41 -0
- package/dist/modes/interactive/approval-merge.js +89 -0
- package/dist/modes/interactive/clipboard-paste.d.ts +18 -0
- package/dist/modes/interactive/clipboard-paste.js +28 -0
- package/dist/modes/interactive/commands.d.ts +20 -3
- package/dist/modes/interactive/commands.js +75 -16
- package/dist/modes/interactive/double-esc.d.ts +20 -0
- package/dist/modes/interactive/double-esc.js +34 -0
- package/dist/modes/interactive/event-notices.d.ts +32 -0
- package/dist/modes/interactive/event-notices.js +79 -0
- package/dist/modes/interactive/external-editor.d.ts +16 -0
- package/dist/modes/interactive/external-editor.js +39 -0
- package/dist/modes/interactive/interactive-mode.d.ts +16 -2
- package/dist/modes/interactive/interactive-mode.js +184 -202
- package/dist/modes/interactive/key-dispatch.d.ts +18 -2
- package/dist/modes/interactive/key-dispatch.js +53 -6
- package/dist/modes/interactive/line/line-mode.d.ts +3 -1
- package/dist/modes/interactive/line/line-mode.js +28 -9
- package/dist/modes/interactive/line/line-render.d.ts +6 -1
- package/dist/modes/interactive/line/line-render.js +66 -8
- package/dist/modes/interactive/message-view.d.ts +49 -10
- package/dist/modes/interactive/message-view.js +262 -46
- package/dist/modes/interactive/panels.d.ts +35 -0
- package/dist/modes/interactive/panels.js +157 -0
- package/dist/modes/interactive/pickers.d.ts +23 -2
- package/dist/modes/interactive/pickers.js +48 -15
- package/dist/modes/interactive/plan-command.d.ts +40 -0
- package/dist/modes/interactive/plan-command.js +129 -0
- package/dist/modes/interactive/plan-dialog.d.ts +98 -0
- package/dist/modes/interactive/plan-dialog.js +290 -0
- package/dist/modes/interactive/plan-flow.d.ts +34 -0
- package/dist/modes/interactive/plan-flow.js +98 -0
- package/dist/modes/interactive/rewind-command.d.ts +31 -0
- package/dist/modes/interactive/rewind-command.js +106 -0
- package/dist/modes/interactive/rewind-flow.d.ts +37 -0
- package/dist/modes/interactive/rewind-flow.js +151 -0
- package/dist/modes/interactive/rewind-list.d.ts +36 -0
- package/dist/modes/interactive/rewind-list.js +123 -0
- package/dist/modes/interactive/rewind-panel.d.ts +77 -0
- package/dist/modes/interactive/rewind-panel.js +309 -0
- package/dist/modes/interactive/rewind-text.d.ts +40 -0
- package/dist/modes/interactive/rewind-text.js +139 -0
- package/dist/modes/interactive/run-indicator.d.ts +51 -0
- package/dist/modes/interactive/run-indicator.js +189 -0
- package/dist/modes/interactive/session-events.d.ts +24 -0
- package/dist/modes/interactive/session-events.js +96 -0
- package/dist/modes/interactive/startup-header.d.ts +40 -0
- package/dist/modes/interactive/startup-header.js +169 -0
- package/dist/modes/interactive/status-area.d.ts +73 -0
- package/dist/modes/interactive/status-area.js +190 -0
- package/dist/modes/interactive/status-bar.d.ts +107 -16
- package/dist/modes/interactive/status-bar.js +306 -81
- package/dist/modes/interactive/status-line.d.ts +33 -0
- package/dist/modes/interactive/status-line.js +113 -0
- package/dist/modes/interactive/subagent-view.d.ts +56 -0
- package/dist/modes/interactive/subagent-view.js +154 -0
- package/dist/modes/interactive/tasks-report.d.ts +27 -0
- package/dist/modes/interactive/tasks-report.js +114 -0
- package/dist/modes/interactive/tool-summary.d.ts +46 -0
- package/dist/modes/interactive/tool-summary.js +218 -0
- package/dist/modes/interactive/tool-view.d.ts +58 -15
- package/dist/modes/interactive/tool-view.js +233 -145
- package/dist/modes/print/print-mode.d.ts +40 -4
- package/dist/modes/print/print-mode.js +161 -8
- package/dist/modes/rpc/commands.d.ts +9 -0
- package/dist/modes/rpc/commands.js +49 -0
- package/dist/modes/rpc/rpc-mode.js +7 -1
- package/dist/modes/session-report.d.ts +11 -0
- package/dist/modes/session-report.js +48 -1
- package/dist/permissions/auto-safe.d.ts +65 -0
- package/dist/permissions/auto-safe.js +547 -0
- package/dist/permissions/classifier.d.ts +68 -0
- package/dist/permissions/classifier.js +186 -0
- package/dist/permissions/dangerous.d.ts +5 -0
- package/dist/permissions/dangerous.js +1 -1
- package/dist/permissions/modes.d.ts +30 -0
- package/dist/permissions/modes.js +78 -0
- package/dist/permissions/pipeline.d.ts +72 -6
- package/dist/permissions/pipeline.js +306 -11
- package/dist/permissions/protected.d.ts +19 -0
- package/dist/permissions/protected.js +74 -0
- package/dist/permissions/readonly-bash.d.ts +30 -0
- package/dist/permissions/readonly-bash.js +118 -0
- package/dist/permissions/rules.js +3 -0
- package/dist/permissions/types.d.ts +92 -3
- package/dist/permissions/types.js +3 -0
- package/dist/plan/compose.d.ts +9 -0
- package/dist/plan/compose.js +19 -0
- package/dist/plan/controller.d.ts +71 -0
- package/dist/plan/controller.js +27 -0
- package/dist/plan/done-markers.d.ts +17 -0
- package/dist/plan/done-markers.js +51 -0
- package/dist/plan/extract.d.ts +29 -0
- package/dist/plan/extract.js +160 -0
- package/dist/plan/prompts.d.ts +36 -0
- package/dist/plan/prompts.js +89 -0
- package/dist/plan/store.d.ts +37 -0
- package/dist/plan/store.js +90 -0
- package/dist/rpc.d.ts +58 -2
- package/dist/rpc.js +7 -0
- package/dist/sandbox/bash.d.ts +74 -0
- package/dist/sandbox/bash.js +126 -0
- package/dist/sandbox/detect.d.ts +48 -0
- package/dist/sandbox/detect.js +149 -0
- package/dist/sandbox/index.d.ts +5 -0
- package/dist/sandbox/index.js +5 -0
- package/dist/sandbox/profile.d.ts +33 -0
- package/dist/sandbox/profile.js +76 -0
- package/dist/sandbox/wrap.d.ts +29 -0
- package/dist/sandbox/wrap.js +117 -0
- package/dist/sdk.d.ts +42 -5
- package/dist/sdk.js +34 -4
- package/dist/session/export.d.ts +32 -0
- package/dist/session/export.js +187 -0
- package/dist/session/redact.d.ts +15 -0
- package/dist/session/redact.js +55 -0
- package/dist/session/reuse.d.ts +33 -0
- package/dist/session/reuse.js +86 -0
- package/dist/session/scan.d.ts +34 -0
- package/dist/session/scan.js +140 -0
- package/dist/session/search.d.ts +52 -0
- package/dist/session/search.js +211 -0
- package/dist/session/stats-aggregate.d.ts +63 -0
- package/dist/session/stats-aggregate.js +163 -0
- package/dist/session/stats-index.d.ts +26 -0
- package/dist/session/stats-index.js +91 -0
- package/dist/session/stats-scan.d.ts +54 -0
- package/dist/session/stats-scan.js +236 -0
- package/dist/session/types.d.ts +3 -1
- package/dist/session/types.js +1 -0
- package/dist/skills/builtin.d.ts +31 -0
- package/dist/skills/builtin.js +109 -0
- package/dist/skills/discover.d.ts +2 -1
- package/dist/skills/index-prompt.js +5 -8
- package/dist/tools/background-jobs.d.ts +71 -0
- package/dist/tools/background-jobs.js +198 -0
- package/dist/tools/bash.d.ts +53 -1
- package/dist/tools/bash.js +158 -7
- package/dist/tools/clipboard-image.d.ts +44 -0
- package/dist/tools/clipboard-image.js +148 -0
- package/dist/tools/edit.d.ts +2 -0
- package/dist/tools/edit.js +18 -3
- package/dist/tools/image-file.d.ts +38 -3
- package/dist/tools/image-file.js +81 -10
- package/dist/tools/image-resize.d.ts +58 -0
- package/dist/tools/image-resize.js +97 -0
- package/dist/tools/presets.d.ts +40 -8
- package/dist/tools/presets.js +65 -19
- package/dist/tools/read.d.ts +5 -2
- package/dist/tools/read.js +13 -10
- package/dist/tools/registry.d.ts +7 -1
- package/dist/tools/registry.js +27 -4
- package/dist/tools/task-ctl.d.ts +22 -0
- package/dist/tools/task-ctl.js +116 -0
- package/dist/tools/task.d.ts +22 -10
- package/dist/tools/task.js +66 -26
- package/dist/tools/todo.d.ts +22 -2
- package/dist/tools/todo.js +58 -14
- package/dist/tools/truncate.d.ts +15 -0
- package/dist/tools/truncate.js +25 -0
- package/dist/tools/types.d.ts +113 -0
- package/dist/tools/types.js +5 -0
- package/dist/tools/write.js +3 -0
- package/dist/tui/component.d.ts +8 -2
- package/dist/tui/component.js +3 -1
- package/dist/tui/components/box.d.ts +6 -1
- package/dist/tui/components/box.js +16 -6
- package/dist/tui/components/card.d.ts +23 -0
- package/dist/tui/components/card.js +37 -0
- package/dist/tui/components/editor-history.d.ts +6 -0
- package/dist/tui/components/editor-history.js +45 -0
- package/dist/tui/components/editor-paste.d.ts +1 -1
- package/dist/tui/components/editor-paste.js +4 -4
- package/dist/tui/components/editor.d.ts +11 -5
- package/dist/tui/components/editor.js +52 -58
- package/dist/tui/components/key-value.d.ts +3 -0
- package/dist/tui/components/key-value.js +16 -6
- package/dist/tui/components/loader.d.ts +37 -7
- package/dist/tui/components/loader.js +84 -21
- package/dist/tui/components/markdown.d.ts +5 -1
- package/dist/tui/components/markdown.js +45 -21
- package/dist/tui/components/meter.d.ts +3 -3
- package/dist/tui/components/meter.js +13 -11
- package/dist/tui/components/select-list.d.ts +23 -1
- package/dist/tui/components/select-list.js +76 -13
- package/dist/tui/glyphs.d.ts +72 -0
- package/dist/tui/glyphs.js +118 -0
- package/dist/tui/keybindings.d.ts +5 -0
- package/dist/tui/keybindings.js +5 -0
- package/dist/tui/theme.d.ts +30 -6
- package/dist/tui/theme.js +103 -17
- package/dist/tui.d.ts +4 -2
- package/dist/tui.js +3 -1
- package/docs/acp.md +78 -0
- package/docs/agents.md +250 -0
- package/docs/codemode.md +28 -10
- package/docs/hooks.md +36 -32
- package/docs/permissions.md +212 -0
- package/docs/plan.md +107 -0
- package/docs/providers.md +261 -62
- package/docs/rewind-plan.md +181 -0
- package/docs/rpc.md +127 -40
- package/docs/sandbox.md +215 -0
- package/docs/session-format.md +43 -22
- package/docs/sessions.md +174 -0
- package/docs/tui-design.md +751 -0
- package/docs/tui.md +260 -64
- package/package.json +15 -2
|
@@ -2,15 +2,19 @@
|
|
|
2
2
|
* 边框 / 内边距容器(设计 §12.1)。[B4]
|
|
3
3
|
*
|
|
4
4
|
* 子组件按内宽渲染后加圆角边框(可选标题,嵌在上边框)与内边距;宽度不足 4 列时退化为只加内边距。
|
|
5
|
+
* 边框字形取 `theme.glyphs.box`(ASCII 下为 `+ - |`),颜色缺省 `border`,可用 `borderColor` 改
|
|
6
|
+
* (审批对话框按严重度用 error / warning)。
|
|
5
7
|
* 焦点与键输入透传给子组件,所以可以直接把 `Box(SelectList)` 交给 `showOverlay`。
|
|
6
8
|
*/
|
|
7
|
-
import { type Component, type Theme } from "../component.js";
|
|
9
|
+
import { type Component, type SemanticColor, type Theme } from "../component.js";
|
|
8
10
|
export interface BoxOptions {
|
|
9
11
|
border?: boolean;
|
|
10
12
|
paddingX?: number;
|
|
11
13
|
paddingY?: number;
|
|
12
14
|
title?: string;
|
|
13
15
|
theme?: Theme;
|
|
16
|
+
/** 边框颜色,缺省 `border`。 */
|
|
17
|
+
borderColor?: SemanticColor;
|
|
14
18
|
}
|
|
15
19
|
export declare class Box implements Component {
|
|
16
20
|
readonly child: Component;
|
|
@@ -21,6 +25,7 @@ export declare class Box implements Component {
|
|
|
21
25
|
set focused(value: boolean);
|
|
22
26
|
handleInput(data: string): void;
|
|
23
27
|
render(width: number): string[];
|
|
28
|
+
private get glyphs();
|
|
24
29
|
private topBorder;
|
|
25
30
|
invalidate(): void;
|
|
26
31
|
}
|
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
* 边框 / 内边距容器(设计 §12.1)。[B4]
|
|
3
3
|
*
|
|
4
4
|
* 子组件按内宽渲染后加圆角边框(可选标题,嵌在上边框)与内边距;宽度不足 4 列时退化为只加内边距。
|
|
5
|
+
* 边框字形取 `theme.glyphs.box`(ASCII 下为 `+ - |`),颜色缺省 `border`,可用 `borderColor` 改
|
|
6
|
+
* (审批对话框按严重度用 error / warning)。
|
|
5
7
|
* 焦点与键输入透传给子组件,所以可以直接把 `Box(SelectList)` 交给 `showOverlay`。
|
|
6
8
|
*/
|
|
7
9
|
import { isFocusable } from "../component.js";
|
|
8
10
|
import { padToWidth, truncateToWidth, visibleWidth } from "../ansi.js";
|
|
11
|
+
import { UNICODE_GLYPHS } from "../glyphs.js";
|
|
9
12
|
export class Box {
|
|
10
13
|
child;
|
|
11
14
|
options;
|
|
@@ -31,7 +34,9 @@ export class Box {
|
|
|
31
34
|
const frame = border ? 2 : 0;
|
|
32
35
|
const inner = Math.max(1, width - frame - padX * 2);
|
|
33
36
|
const body = this.child.render(inner);
|
|
34
|
-
const
|
|
37
|
+
const borderColor = this.options.borderColor ?? "border";
|
|
38
|
+
const color = (s) => this.options.theme ? this.options.theme.fg(borderColor, s) : s;
|
|
39
|
+
const g = this.glyphs;
|
|
35
40
|
const pad = " ".repeat(padX);
|
|
36
41
|
const contentWidth = Math.max(0, width - frame);
|
|
37
42
|
const rows = [];
|
|
@@ -47,17 +52,22 @@ export class Box {
|
|
|
47
52
|
return rows;
|
|
48
53
|
const lines = [this.topBorder(width, color)];
|
|
49
54
|
for (const row of rows)
|
|
50
|
-
lines.push(color(
|
|
51
|
-
lines.push(color(
|
|
55
|
+
lines.push(color(g.vertical) + row + color(g.vertical));
|
|
56
|
+
lines.push(color(g.bottomLeft + g.horizontal.repeat(width - 2) + g.bottomRight));
|
|
52
57
|
return lines;
|
|
53
58
|
}
|
|
59
|
+
get glyphs() {
|
|
60
|
+
return (this.options.theme?.glyphs ?? UNICODE_GLYPHS).box;
|
|
61
|
+
}
|
|
54
62
|
topBorder(width, color) {
|
|
63
|
+
const g = this.glyphs;
|
|
55
64
|
const title = this.options.title;
|
|
56
|
-
if (title === undefined || title === "")
|
|
57
|
-
return color(
|
|
65
|
+
if (title === undefined || title === "") {
|
|
66
|
+
return color(g.topLeft + g.horizontal.repeat(width - 2) + g.topRight);
|
|
67
|
+
}
|
|
58
68
|
const label = truncateToWidth(` ${title} `, width - 4);
|
|
59
69
|
const rest = Math.max(0, width - 3 - visibleWidth(label));
|
|
60
|
-
return color(
|
|
70
|
+
return color(g.topLeft + g.horizontal) + label + color(g.horizontal.repeat(rest) + g.topRight);
|
|
61
71
|
}
|
|
62
72
|
invalidate() {
|
|
63
73
|
this.child.invalidate();
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 左竖条卡片(终端界面视觉设计 v1 §3.6、§3.13):压缩摘要、`/session` 等面板。
|
|
3
|
+
*
|
|
4
|
+
* 每行前加 `theme.glyphs.card`(`▎`,ASCII `|`)与一个空格,竖条用 `border` 色;可选标题行(正文色粗体)
|
|
5
|
+
* 与跟在标题后的副标题(`muted`,两个空格隔开)。不加上下边框——Box 只留给代码块、启动头与覆盖层。
|
|
6
|
+
* 子组件按 `width - 2` 渲染;空行只画竖条。
|
|
7
|
+
*/
|
|
8
|
+
import type { Component, SemanticColor, Theme } from "../component.js";
|
|
9
|
+
export interface CardOptions {
|
|
10
|
+
theme?: Theme;
|
|
11
|
+
title?: string;
|
|
12
|
+
/** 标题后的次要说明(muted)。 */
|
|
13
|
+
subtitle?: string;
|
|
14
|
+
/** 竖条颜色,缺省 `border`。 */
|
|
15
|
+
barColor?: SemanticColor;
|
|
16
|
+
}
|
|
17
|
+
export declare class Card implements Component {
|
|
18
|
+
readonly child: Component | undefined;
|
|
19
|
+
private readonly options;
|
|
20
|
+
constructor(child: Component | undefined, options?: CardOptions);
|
|
21
|
+
render(width: number): string[];
|
|
22
|
+
invalidate(): void;
|
|
23
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 左竖条卡片(终端界面视觉设计 v1 §3.6、§3.13):压缩摘要、`/session` 等面板。
|
|
3
|
+
*
|
|
4
|
+
* 每行前加 `theme.glyphs.card`(`▎`,ASCII `|`)与一个空格,竖条用 `border` 色;可选标题行(正文色粗体)
|
|
5
|
+
* 与跟在标题后的副标题(`muted`,两个空格隔开)。不加上下边框——Box 只留给代码块、启动头与覆盖层。
|
|
6
|
+
* 子组件按 `width - 2` 渲染;空行只画竖条。
|
|
7
|
+
*/
|
|
8
|
+
import { truncateToWidth } from "../ansi.js";
|
|
9
|
+
import { UNICODE_GLYPHS } from "../glyphs.js";
|
|
10
|
+
export class Card {
|
|
11
|
+
child;
|
|
12
|
+
options;
|
|
13
|
+
constructor(child, options = {}) {
|
|
14
|
+
this.child = child;
|
|
15
|
+
this.options = options;
|
|
16
|
+
}
|
|
17
|
+
render(width) {
|
|
18
|
+
const { theme, title, subtitle } = this.options;
|
|
19
|
+
const glyph = (theme?.glyphs ?? UNICODE_GLYPHS).card;
|
|
20
|
+
const bar = theme ? theme.fg(this.options.barColor ?? "border", glyph) : glyph;
|
|
21
|
+
const inner = Math.max(1, width - 2);
|
|
22
|
+
const lines = [];
|
|
23
|
+
if (title !== undefined && title !== "") {
|
|
24
|
+
let head = theme ? theme.bold(title) : title;
|
|
25
|
+
if (subtitle !== undefined && subtitle !== "") {
|
|
26
|
+
head += " " + (theme ? theme.fg("muted", subtitle) : subtitle);
|
|
27
|
+
}
|
|
28
|
+
lines.push(head);
|
|
29
|
+
}
|
|
30
|
+
if (this.child)
|
|
31
|
+
lines.push(...this.child.render(inner));
|
|
32
|
+
return lines.map((line) => line === "" ? bar : truncateToWidth(`${bar} ${truncateToWidth(line, inner)}`, width));
|
|
33
|
+
}
|
|
34
|
+
invalidate() {
|
|
35
|
+
this.child?.invalidate();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 编辑器的历史文件(设计 §12.4):JSONL,每行一个 JSON 字符串,保留最近 `limit` 条。[B4]
|
|
3
|
+
* 读写失败都不影响编辑(损坏的行跳过;写失败静默)。
|
|
4
|
+
*/
|
|
5
|
+
export declare function loadHistoryFile(path: string, limit?: number): string[];
|
|
6
|
+
export declare function appendHistoryFile(path: string, entry: string, limit: number): void;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 编辑器的历史文件(设计 §12.4):JSONL,每行一个 JSON 字符串,保留最近 `limit` 条。[B4]
|
|
3
|
+
* 读写失败都不影响编辑(损坏的行跳过;写失败静默)。
|
|
4
|
+
*/
|
|
5
|
+
import { appendFileSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { dirname } from "node:path";
|
|
7
|
+
export function loadHistoryFile(path, limit = 500) {
|
|
8
|
+
let text;
|
|
9
|
+
try {
|
|
10
|
+
text = readFileSync(path, "utf8");
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
const entries = [];
|
|
16
|
+
for (const line of text.split("\n")) {
|
|
17
|
+
if (line.trim() === "")
|
|
18
|
+
continue;
|
|
19
|
+
try {
|
|
20
|
+
const value = JSON.parse(line);
|
|
21
|
+
if (typeof value === "string" && value !== "")
|
|
22
|
+
entries.push(value);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
// 损坏的行跳过
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return entries.slice(-limit);
|
|
29
|
+
}
|
|
30
|
+
export function appendHistoryFile(path, entry, limit) {
|
|
31
|
+
try {
|
|
32
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
33
|
+
appendFileSync(path, JSON.stringify(entry) + "\n", { mode: 0o600 });
|
|
34
|
+
const all = loadHistoryFile(path, Number.MAX_SAFE_INTEGER);
|
|
35
|
+
if (all.length > limit * 2) {
|
|
36
|
+
writeFileSync(path, all
|
|
37
|
+
.slice(-limit)
|
|
38
|
+
.map((e) => JSON.stringify(e) + "\n")
|
|
39
|
+
.join(""));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
// 历史写失败不影响编辑
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 大粘贴折叠(设计 §12.4):超过 10 行或超过 1 000 字符的粘贴折叠为 `[
|
|
2
|
+
* 大粘贴折叠(设计 §12.4):超过 10 行或超过 1 000 字符的粘贴折叠为 `[粘贴 #N · M 行]`,
|
|
3
3
|
* 在编辑器里是不可分割段;提交时展开为原文。[B4]
|
|
4
4
|
*
|
|
5
5
|
* - 换行规范化:`\r\n` / 单独的 `\r` → `\n`(括号粘贴里终端常把换行发成 `\r`)。
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
export const PASTE_LINE_THRESHOLD = 10;
|
|
10
10
|
export const PASTE_CHAR_THRESHOLD = 1000;
|
|
11
|
-
const MARKER_RE = /\[
|
|
11
|
+
const MARKER_RE = /\[粘贴 #(\d+) · (\d+) 行\]/g;
|
|
12
12
|
export function normalizePastedText(text) {
|
|
13
13
|
return text.replace(/\r\n?/g, "\n");
|
|
14
14
|
}
|
|
@@ -20,7 +20,7 @@ export function shouldCollapse(text) {
|
|
|
20
20
|
return countLines(text) > PASTE_LINE_THRESHOLD || text.length > PASTE_CHAR_THRESHOLD;
|
|
21
21
|
}
|
|
22
22
|
export function formatMarker(id, lines) {
|
|
23
|
-
return `[
|
|
23
|
+
return `[粘贴 #${id} · ${lines} 行]`;
|
|
24
24
|
}
|
|
25
25
|
export class PasteStore {
|
|
26
26
|
next = 1;
|
|
@@ -48,7 +48,7 @@ export class PasteStore {
|
|
|
48
48
|
}
|
|
49
49
|
/** 一行内已登记标记的区间(编辑器的不可分割段)。 */
|
|
50
50
|
ranges(line) {
|
|
51
|
-
if (this.entries.size === 0 || !line.includes("[
|
|
51
|
+
if (this.entries.size === 0 || !line.includes("[粘贴 #"))
|
|
52
52
|
return [];
|
|
53
53
|
const out = [];
|
|
54
54
|
for (const m of line.matchAll(MARKER_RE)) {
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 多行编辑器组件(设计 §12.3、§12.4)。[B4]
|
|
3
3
|
*
|
|
4
|
-
* -
|
|
5
|
-
*
|
|
4
|
+
* - 渲染:上下规则线之间按列宽折行(不切开字素与折叠标记);首行前是提示符 `› `(`user` 粗体,
|
|
5
|
+
* `disableSubmit` 时 dim),续行缩进 2 列对齐;超过 `maxVisibleLines` 时视窗跟随光标,规则线上提示
|
|
6
|
+
* 上 / 下方隐藏的行数(dim);获焦时在光标处输出 CURSOR_MARKER 并反显光标格。空文本显示占位
|
|
7
|
+
* (获焦时也显示,光标反显占位首字)。
|
|
6
8
|
* - 键位:`tui.editor.*`(见 keybindings.ts)。Enter 提交(`disableSubmit` 时忽略);Shift+Enter / Ctrl+J 换行;
|
|
7
9
|
* Up/Down 在首 / 末视觉行时浏览历史(单行文本或空文本或已在浏览中),否则按视觉行移动。
|
|
8
10
|
* - 括号粘贴(`ESC[200~…ESC[201~`,由 StdinBuffer 合成一次输入):> 10 行或 > 1 000 字符折叠为
|
|
9
|
-
* `[
|
|
10
|
-
* - 补全:提供者由外部注入(`/` 命令、`@` 文件等由 B7
|
|
11
|
+
* `[粘贴 #N · M 行]`,提交时展开;粘贴期间不触发补全;粘贴后紧随的 `\r` 是普通 Enter(提交)。
|
|
12
|
+
* - 补全:提供者由外部注入(`/` 命令、`@` 文件等由 B7 实现);同步或异步返回候选与替换起点;
|
|
13
|
+
* 弹层缩进 2 列,尾行 `(i/n) Tab 接受 · Esc 关闭`。
|
|
11
14
|
* - 历史:会话内 + 可选历史文件(JSONL,每行一个 JSON 字符串,保留最近 500 条)。
|
|
12
15
|
*/
|
|
13
16
|
import { type Component, type Focusable, type Theme } from "../component.js";
|
|
14
17
|
import { type Keybindings } from "../keybindings.js";
|
|
18
|
+
export { loadHistoryFile } from "./editor-history.js";
|
|
15
19
|
export interface AutocompleteItem {
|
|
16
20
|
/** 接受后替换进编辑器的文本。 */
|
|
17
21
|
value: string;
|
|
@@ -52,7 +56,6 @@ export interface EditorOptions {
|
|
|
52
56
|
onSubmit?(text: string): void;
|
|
53
57
|
onChange?(text: string): void;
|
|
54
58
|
}
|
|
55
|
-
export declare function loadHistoryFile(path: string, limit?: number): string[];
|
|
56
59
|
export declare class Editor implements Component, Focusable {
|
|
57
60
|
private readonly options;
|
|
58
61
|
focused: boolean;
|
|
@@ -103,7 +106,10 @@ export declare class Editor implements Component, Focusable {
|
|
|
103
106
|
private applyCompletion;
|
|
104
107
|
private acceptCompletion;
|
|
105
108
|
private closeCompletion;
|
|
109
|
+
/** 文本列宽:去掉提示符与行尾光标格。 */
|
|
106
110
|
private contentWidth;
|
|
111
|
+
private prompt;
|
|
112
|
+
private placeholderLine;
|
|
107
113
|
/** 逻辑行 → 视觉行(按列宽折行,不切开字素与折叠标记)。 */
|
|
108
114
|
private layout;
|
|
109
115
|
private cursorRowIndex;
|
|
@@ -1,65 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 多行编辑器组件(设计 §12.3、§12.4)。[B4]
|
|
3
3
|
*
|
|
4
|
-
* -
|
|
5
|
-
*
|
|
4
|
+
* - 渲染:上下规则线之间按列宽折行(不切开字素与折叠标记);首行前是提示符 `› `(`user` 粗体,
|
|
5
|
+
* `disableSubmit` 时 dim),续行缩进 2 列对齐;超过 `maxVisibleLines` 时视窗跟随光标,规则线上提示
|
|
6
|
+
* 上 / 下方隐藏的行数(dim);获焦时在光标处输出 CURSOR_MARKER 并反显光标格。空文本显示占位
|
|
7
|
+
* (获焦时也显示,光标反显占位首字)。
|
|
6
8
|
* - 键位:`tui.editor.*`(见 keybindings.ts)。Enter 提交(`disableSubmit` 时忽略);Shift+Enter / Ctrl+J 换行;
|
|
7
9
|
* Up/Down 在首 / 末视觉行时浏览历史(单行文本或空文本或已在浏览中),否则按视觉行移动。
|
|
8
10
|
* - 括号粘贴(`ESC[200~…ESC[201~`,由 StdinBuffer 合成一次输入):> 10 行或 > 1 000 字符折叠为
|
|
9
|
-
* `[
|
|
10
|
-
* - 补全:提供者由外部注入(`/` 命令、`@` 文件等由 B7
|
|
11
|
+
* `[粘贴 #N · M 行]`,提交时展开;粘贴期间不触发补全;粘贴后紧随的 `\r` 是普通 Enter(提交)。
|
|
12
|
+
* - 补全:提供者由外部注入(`/` 命令、`@` 文件等由 B7 实现);同步或异步返回候选与替换起点;
|
|
13
|
+
* 弹层缩进 2 列,尾行 `(i/n) Tab 接受 · Esc 关闭`。
|
|
11
14
|
* - 历史:会话内 + 可选历史文件(JSONL,每行一个 JSON 字符串,保留最近 500 条)。
|
|
12
15
|
*/
|
|
13
|
-
import { appendFileSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
14
|
-
import { dirname } from "node:path";
|
|
15
16
|
import { CURSOR_MARKER } from "../component.js";
|
|
16
17
|
import { truncateToWidth, visibleWidth } from "../ansi.js";
|
|
17
18
|
import { defaultKeybindings } from "../keybindings.js";
|
|
18
19
|
import { isPasteData, isPrintableText, unwrapPaste } from "../keys.js";
|
|
19
20
|
import { plainTheme } from "../theme.js";
|
|
20
21
|
import { EditorBuffer } from "./editor-buffer.js";
|
|
22
|
+
import { appendHistoryFile, loadHistoryFile } from "./editor-history.js";
|
|
21
23
|
import { PasteStore } from "./editor-paste.js";
|
|
22
24
|
import { SelectList } from "./select-list.js";
|
|
25
|
+
export { loadHistoryFile } from "./editor-history.js";
|
|
23
26
|
const segmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" });
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
text = readFileSync(path, "utf8");
|
|
28
|
-
}
|
|
29
|
-
catch {
|
|
30
|
-
return [];
|
|
31
|
-
}
|
|
32
|
-
const entries = [];
|
|
33
|
-
for (const line of text.split("\n")) {
|
|
34
|
-
if (line.trim() === "")
|
|
35
|
-
continue;
|
|
36
|
-
try {
|
|
37
|
-
const value = JSON.parse(line);
|
|
38
|
-
if (typeof value === "string" && value !== "")
|
|
39
|
-
entries.push(value);
|
|
40
|
-
}
|
|
41
|
-
catch {
|
|
42
|
-
// 损坏的行跳过
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return entries.slice(-limit);
|
|
46
|
-
}
|
|
47
|
-
function appendHistoryFile(path, entry, limit) {
|
|
48
|
-
try {
|
|
49
|
-
mkdirSync(dirname(path), { recursive: true });
|
|
50
|
-
appendFileSync(path, JSON.stringify(entry) + "\n", { mode: 0o600 });
|
|
51
|
-
const all = loadHistoryFile(path, Number.MAX_SAFE_INTEGER);
|
|
52
|
-
if (all.length > limit * 2) {
|
|
53
|
-
writeFileSync(path, all
|
|
54
|
-
.slice(-limit)
|
|
55
|
-
.map((e) => JSON.stringify(e) + "\n")
|
|
56
|
-
.join(""));
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
catch {
|
|
60
|
-
// 历史写失败不影响编辑
|
|
61
|
-
}
|
|
62
|
-
}
|
|
27
|
+
/** 提示符 `› ` / 续行缩进的宽度。 */
|
|
28
|
+
const PROMPT_WIDTH = 2;
|
|
29
|
+
const COMPLETION_FOOTER = "Tab 接受 · Esc 关闭";
|
|
63
30
|
export class Editor {
|
|
64
31
|
options;
|
|
65
32
|
focused = false;
|
|
@@ -380,7 +347,13 @@ export class Editor {
|
|
|
380
347
|
? { value: item.value, label: item.label }
|
|
381
348
|
: { value: item.value, label: item.label, description: item.description });
|
|
382
349
|
this.completion = {
|
|
383
|
-
list: new SelectList(items, {
|
|
350
|
+
list: new SelectList(items, {
|
|
351
|
+
maxVisible: 8,
|
|
352
|
+
theme: this.theme,
|
|
353
|
+
keybindings: this.keys,
|
|
354
|
+
footer: COMPLETION_FOOTER,
|
|
355
|
+
showCount: true,
|
|
356
|
+
}),
|
|
384
357
|
from: result.from,
|
|
385
358
|
};
|
|
386
359
|
}
|
|
@@ -401,8 +374,22 @@ export class Editor {
|
|
|
401
374
|
this.completionToken++;
|
|
402
375
|
}
|
|
403
376
|
// ---- 渲染 -----------------------------------------------------------------
|
|
377
|
+
/** 文本列宽:去掉提示符与行尾光标格。 */
|
|
404
378
|
contentWidth(width) {
|
|
405
|
-
return Math.max(1, width - 1);
|
|
379
|
+
return Math.max(1, width - PROMPT_WIDTH - 1);
|
|
380
|
+
}
|
|
381
|
+
prompt() {
|
|
382
|
+
const glyph = this.theme.glyphs.prompt;
|
|
383
|
+
return this.theme.fg(this.disableSubmit ? "dim" : "user", this.theme.bold(glyph)) + " ";
|
|
384
|
+
}
|
|
385
|
+
placeholderLine(width) {
|
|
386
|
+
const text = this.options.placeholder ?? "";
|
|
387
|
+
if (!this.focused)
|
|
388
|
+
return truncateToWidth(this.prompt() + this.theme.fg("dim", text), width);
|
|
389
|
+
const first = nextGrapheme(text, 0);
|
|
390
|
+
const rest = text.slice(first.length);
|
|
391
|
+
const cursor = CURSOR_MARKER + `\x1b[7m${this.theme.fg("dim", first)}\x1b[27m`;
|
|
392
|
+
return truncateToWidth(this.prompt() + cursor + this.theme.fg("dim", rest), width);
|
|
406
393
|
}
|
|
407
394
|
/** 逻辑行 → 视觉行(按列宽折行,不切开字素与折叠标记)。 */
|
|
408
395
|
layout(width) {
|
|
@@ -494,27 +481,34 @@ export class Editor {
|
|
|
494
481
|
this.scrollTop = cursorRow - maxVisible + 1;
|
|
495
482
|
this.scrollTop = Math.max(0, Math.min(this.scrollTop, rows.length - maxVisible));
|
|
496
483
|
const end = Math.min(rows.length, this.scrollTop + maxVisible);
|
|
497
|
-
const
|
|
498
|
-
|
|
499
|
-
|
|
484
|
+
const g = theme.glyphs;
|
|
485
|
+
const lines = [this.border(width, this.scrollTop > 0 ? `${g.arrowUp} ${this.scrollTop}` : "")];
|
|
486
|
+
if (this.buffer.isEmpty() && this.options.placeholder) {
|
|
487
|
+
lines.push(this.placeholderLine(width));
|
|
500
488
|
}
|
|
501
489
|
else {
|
|
490
|
+
const indent = " ".repeat(PROMPT_WIDTH);
|
|
502
491
|
for (let i = this.scrollTop; i < end; i++) {
|
|
503
|
-
|
|
492
|
+
const prefix = i === 0 ? this.prompt() : indent;
|
|
493
|
+
lines.push(prefix + this.renderRow(rows[i], this.focused && i === cursorRow));
|
|
504
494
|
}
|
|
505
495
|
}
|
|
506
|
-
|
|
496
|
+
const below = rows.length - end;
|
|
497
|
+
lines.push(this.border(width, below > 0 ? `${g.arrowDown} ${below}` : ""));
|
|
507
498
|
if (this.completion) {
|
|
508
|
-
for (const line of this.completion.list.render(width))
|
|
509
|
-
lines.push(line);
|
|
499
|
+
for (const line of this.completion.list.render(Math.max(1, width - 2))) {
|
|
500
|
+
lines.push(" " + line);
|
|
501
|
+
}
|
|
510
502
|
}
|
|
511
503
|
return lines;
|
|
512
504
|
}
|
|
513
505
|
border(width, label) {
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
506
|
+
const rule = this.theme.glyphs.rule;
|
|
507
|
+
const labelWidth = visibleWidth(label);
|
|
508
|
+
if (label === "" || width < labelWidth + 6)
|
|
509
|
+
return this.theme.fg("border", rule.repeat(width));
|
|
510
|
+
const tail = rule.repeat(width - labelWidth - 5);
|
|
511
|
+
return (this.theme.fg("border", rule.repeat(3) + " ") +
|
|
518
512
|
this.theme.fg("dim", label) +
|
|
519
513
|
this.theme.fg("border", " " + tail));
|
|
520
514
|
}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* - 键列宽 = 最长键的可见宽度,但不超过总宽的 `maxKeyRatio`(缺省 0.4,至少 4 列),超出的键截断;
|
|
5
5
|
* - 值在剩余宽度内截断(不换行,保留 ANSI 样式);值里的换行折成 ` ⏎ `;
|
|
6
6
|
* - 宽度连键列都放不下时退化为只显示截断后的键;空行(`key` 为空串)原样输出空行,可作分组间隔。
|
|
7
|
+
* - `wrap: true`:值按剩余宽度折行(值里的换行也换行),续行对齐值列。
|
|
7
8
|
*/
|
|
8
9
|
import type { Component, SemanticColor, Theme } from "../component.js";
|
|
9
10
|
export interface KeyValueRow {
|
|
@@ -17,6 +18,8 @@ export interface KeyValueOptions {
|
|
|
17
18
|
/** 两列之间的空白,缺省 2。 */
|
|
18
19
|
gap?: number;
|
|
19
20
|
maxKeyRatio?: number;
|
|
21
|
+
/** 值折行(续行对齐值列),缺省 false(截断)。 */
|
|
22
|
+
wrap?: boolean;
|
|
20
23
|
}
|
|
21
24
|
export declare class KeyValue implements Component {
|
|
22
25
|
private rows;
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
* - 键列宽 = 最长键的可见宽度,但不超过总宽的 `maxKeyRatio`(缺省 0.4,至少 4 列),超出的键截断;
|
|
5
5
|
* - 值在剩余宽度内截断(不换行,保留 ANSI 样式);值里的换行折成 ` ⏎ `;
|
|
6
6
|
* - 宽度连键列都放不下时退化为只显示截断后的键;空行(`key` 为空串)原样输出空行,可作分组间隔。
|
|
7
|
+
* - `wrap: true`:值按剩余宽度折行(值里的换行也换行),续行对齐值列。
|
|
7
8
|
*/
|
|
8
|
-
import { padToWidth, truncateToWidth, visibleWidth } from "../ansi.js";
|
|
9
|
+
import { padToWidth, truncateToWidth, visibleWidth, wrapTextWithAnsi } from "../ansi.js";
|
|
9
10
|
/** 键列至少保留的宽度(键更短时取键宽);再窄就只显示键。 */
|
|
10
11
|
const MIN_KEY_WIDTH = 4;
|
|
11
12
|
export class KeyValue {
|
|
@@ -29,15 +30,24 @@ export class KeyValue {
|
|
|
29
30
|
const keyWidth = Math.min(longest, Math.max(share, MIN_KEY_WIDTH));
|
|
30
31
|
const valueWidth = width - keyWidth - gap;
|
|
31
32
|
const { theme, keyColor = "dim" } = this.options;
|
|
32
|
-
const
|
|
33
|
+
const wrap = this.options.wrap === true;
|
|
34
|
+
const lines = this.rows.flatMap(({ key, value }) => {
|
|
33
35
|
if (key === "" && value === "")
|
|
34
|
-
return "";
|
|
36
|
+
return [""];
|
|
35
37
|
const shownKey = truncateToWidth(key, Math.max(keyWidth, 1));
|
|
36
38
|
const styledKey = theme ? theme.fg(keyColor, shownKey) : shownKey;
|
|
37
39
|
if (valueWidth < 1)
|
|
38
|
-
return truncateToWidth(styledKey, width);
|
|
39
|
-
const
|
|
40
|
-
|
|
40
|
+
return [truncateToWidth(styledKey, width)];
|
|
41
|
+
const head = padToWidth(styledKey, keyWidth) + " ".repeat(gap);
|
|
42
|
+
if (!wrap) {
|
|
43
|
+
const flat = value.replace(/\r?\n/g, " ⏎ ");
|
|
44
|
+
return [head + truncateToWidth(flat, valueWidth)];
|
|
45
|
+
}
|
|
46
|
+
const pieces = value
|
|
47
|
+
.split(/\r?\n/)
|
|
48
|
+
.flatMap((line) => (line === "" ? [""] : wrapTextWithAnsi(line, valueWidth)));
|
|
49
|
+
const indent = " ".repeat(keyWidth + gap);
|
|
50
|
+
return pieces.map((piece, i) => (i === 0 ? head : indent) + piece);
|
|
41
51
|
});
|
|
42
52
|
this.cache = { width, lines };
|
|
43
53
|
return lines;
|
|
@@ -1,35 +1,65 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* 运行指示(设计 §12.1、§12.6;终端界面视觉设计 v1 §3.7)。[B4]
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* 一行 `⠋ 动词 · 已用时 · 附加项…`:spinner `accent`、动词正文色、其余 `dim`,以 ` · ` 连接。
|
|
5
|
+
* - `setVerb(verb, extras, { elapsed })` 换动词(思考中 / 回复中 / 运行 bash / 等待确认……);
|
|
6
|
+
* `setMessage(text)` 是只换动词的旧接口。
|
|
7
|
+
* - 帧取 `theme.glyphs.spinner`(Unicode 10 帧 80 ms、ASCII 4 帧 250 ms);`frame` 暴露当前帧字形,
|
|
8
|
+
* `onFrame` 让别的组件(运行中的工具摘要行)与 Loader 同帧换字,保证一帧只多改一行。
|
|
9
|
+
* - `animation: false`:spinner 固定为 `glyphs.spinnerStatic`,定时器每秒一次,已用时变了才请求重绘。
|
|
10
|
+
* - `stop()` 后不再触发渲染。时钟可注入便于测试。
|
|
5
11
|
*/
|
|
6
12
|
import type { Component, Theme } from "../component.js";
|
|
7
|
-
|
|
13
|
+
/** Unicode 帧表(兼容旧导出;实际帧取 `theme.glyphs.spinner`)。 */
|
|
14
|
+
export declare const LOADER_FRAMES: readonly string[];
|
|
8
15
|
export interface LoaderOptions {
|
|
16
|
+
/** 初始动词(旧名 message)。 */
|
|
9
17
|
message?: string;
|
|
10
18
|
theme?: Theme;
|
|
11
|
-
/** 帧间隔(ms),缺省 80。 */
|
|
19
|
+
/** 帧间隔(ms),缺省 Unicode 80、ASCII 250;`animation: false` 时为 1000。 */
|
|
12
20
|
intervalMs?: number;
|
|
13
21
|
/** 显示已用时(`12s`、`1m05s`),缺省 true。 */
|
|
14
22
|
showElapsed?: boolean;
|
|
23
|
+
/** false:spinner 静止,缺省 true。 */
|
|
24
|
+
animation?: boolean;
|
|
15
25
|
now?: () => number;
|
|
16
26
|
}
|
|
27
|
+
export interface LoaderVerbOptions {
|
|
28
|
+
/** 本动词是否显示已用时(缺省跟随 `showElapsed`)。 */
|
|
29
|
+
elapsed?: boolean;
|
|
30
|
+
}
|
|
17
31
|
export declare function formatElapsed(ms: number): string;
|
|
18
32
|
export declare class Loader implements Component {
|
|
19
33
|
private readonly requestRender;
|
|
20
34
|
private readonly options;
|
|
21
|
-
private
|
|
35
|
+
private frameIndex;
|
|
22
36
|
private timer;
|
|
23
37
|
private startedAt;
|
|
24
|
-
private
|
|
38
|
+
private verb;
|
|
39
|
+
private extras;
|
|
40
|
+
private verbElapsed;
|
|
41
|
+
private lastElapsed;
|
|
42
|
+
private readonly listeners;
|
|
25
43
|
private readonly now;
|
|
26
44
|
constructor(requestRender: () => void, options?: LoaderOptions);
|
|
27
45
|
get running(): boolean;
|
|
46
|
+
private get frames();
|
|
47
|
+
private get animated();
|
|
48
|
+
/** 当前帧字形(静止时为 `spinnerStatic`)。 */
|
|
49
|
+
get frame(): string;
|
|
50
|
+
/** 订阅换帧(返回取消函数)。 */
|
|
51
|
+
onFrame(listener: (frame: string) => void): () => void;
|
|
52
|
+
/** 换动词与附加项(附加项 dim,排在已用时之后)。 */
|
|
53
|
+
setVerb(verb: string, extras?: readonly string[], options?: LoaderVerbOptions): void;
|
|
54
|
+
/** 旧接口:只换动词。 */
|
|
28
55
|
setMessage(message: string): void;
|
|
56
|
+
/** 已用时从现在重新算(换到另一段工作时)。 */
|
|
57
|
+
resetElapsed(): void;
|
|
29
58
|
start(): void;
|
|
30
59
|
stop(): void;
|
|
31
|
-
/**
|
|
60
|
+
/** 推进一帧(定时器调用;测试可直接调用)。静止时只在已用时变化时重绘。 */
|
|
32
61
|
tick(): void;
|
|
62
|
+
private elapsedText;
|
|
33
63
|
render(width: number): string[];
|
|
34
64
|
invalidate(): void;
|
|
35
65
|
}
|