one-code-extension 0.4.1 → 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/README.md +16 -5
- package/agents/general-purpose.md +2 -2
- package/docs/guide/README.md +2 -1
- package/docs/guide/bring-your-claude-code-setup.md +60 -9
- package/docs/guide/configuration.md +48 -14
- package/docs/guide/differences-from-claude-code.md +32 -23
- package/docs/guide/doctor.md +20 -13
- package/docs/guide/hooks.md +18 -3
- package/docs/guide/installation.md +27 -4
- package/docs/guide/permissions-modes-and-auto-mode.md +225 -49
- package/docs/guide/providers-and-models.md +137 -54
- package/docs/guide/reference.md +27 -15
- package/docs/guide/sessions-and-context.md +69 -16
- package/docs/guide/skills-plugins-and-mcp.md +57 -20
- package/docs/guide/subagents-and-workflows.md +95 -29
- package/docs/guide/tasks-and-background-work.md +101 -26
- package/docs/guide/terminal-interface.md +24 -12
- package/docs/guide/tools.md +46 -5
- package/docs/guide/troubleshooting.md +13 -9
- package/docs/guide/windows.md +58 -31
- package/extensions/artifacts/gallery.ts +227 -0
- package/extensions/artifacts/index.ts +288 -0
- package/extensions/artifacts/store.ts +570 -0
- package/extensions/artifacts/viewer.ts +199 -0
- package/extensions/ask-user/description.ts +67 -0
- package/extensions/ask-user/dialogs.ts +80 -0
- package/extensions/ask-user/index.ts +37 -33
- package/extensions/ask-user/questions.ts +32 -7
- package/extensions/ask-user/widget.ts +45 -25
- package/extensions/auto-mode/actions.ts +6 -0
- package/extensions/auto-mode/cache.ts +88 -0
- package/extensions/auto-mode/classifier-prompt.ts +5 -4
- package/extensions/auto-mode/classifier.ts +290 -65
- package/extensions/auto-mode/config.ts +72 -20
- package/extensions/auto-mode/decision-log.ts +2 -0
- package/extensions/auto-mode/defaults.ts +1 -1
- package/extensions/auto-mode/denials.ts +123 -0
- package/extensions/auto-mode/git-checkout-programs.ts +187 -0
- package/extensions/auto-mode/git-status-meta.ts +159 -0
- package/extensions/auto-mode/history.ts +189 -0
- package/extensions/auto-mode/instructions.ts +58 -52
- package/extensions/auto-mode/model-select.ts +159 -134
- package/extensions/auto-mode/paths.ts +57 -5
- package/extensions/auto-mode/pause.ts +57 -2
- package/extensions/auto-mode/prompt.ts +37 -21
- package/extensions/auto-mode/read-only-options.ts +724 -0
- package/extensions/auto-mode/resolved-paths-meta.ts +133 -0
- package/extensions/auto-mode/rules.ts +18 -1
- package/extensions/auto-mode/safety-floor.ts +361 -18
- package/extensions/auto-mode/setup-run.ts +20 -14
- package/extensions/auto-mode/shell-analysis.ts +764 -490
- package/extensions/auto-mode/shell-parse.ts +885 -0
- package/extensions/auto-mode/system-note.ts +33 -0
- package/extensions/auto-mode/transcript.ts +80 -51
- package/extensions/background/cron.ts +515 -0
- package/extensions/background/index.ts +514 -236
- package/extensions/background/loop-fire.ts +136 -0
- package/extensions/background/loop-preamble.ts +59 -0
- package/extensions/background/loop-skill.ts +163 -0
- package/extensions/background/monitor-batch.ts +53 -0
- package/extensions/background/noop-fold.ts +128 -0
- package/extensions/background/switch-guard.ts +52 -0
- package/extensions/background/wakeup.ts +159 -55
- package/extensions/bash/background.ts +53 -17
- package/extensions/bash/child.ts +7 -0
- package/extensions/bash/description.ts +188 -0
- package/extensions/bash/guards.ts +15 -67
- package/extensions/bash/index.ts +88 -35
- package/extensions/branding/compaction-keep.ts +63 -0
- package/extensions/branding/declined.ts +22 -0
- package/extensions/branding/index.ts +133 -9
- package/extensions/branding/prompt-editor.ts +53 -6
- package/extensions/branding/queued-edit.ts +31 -0
- package/extensions/branding/replaced-builtins.ts +68 -0
- package/extensions/branding/startup.ts +33 -71
- package/extensions/btw/index.ts +229 -71
- package/extensions/btw/panel.ts +228 -100
- package/extensions/btw/prompt.ts +41 -4
- package/extensions/claude-compat/index.ts +7 -11
- package/extensions/claude-context/index.ts +446 -58
- package/extensions/compaction/cut.ts +157 -0
- package/extensions/compaction/index.ts +216 -75
- package/extensions/compaction/kept-thinking.ts +62 -0
- package/extensions/compaction/prompt.ts +15 -12
- package/extensions/context-budget/index.ts +24 -5
- package/extensions/context-management/index.ts +25 -0
- package/extensions/doctor/build.ts +59 -8
- package/extensions/doctor/builtins.ts +84 -0
- package/extensions/doctor/cli.ts +7 -1
- package/extensions/doctor/compat.ts +88 -23
- package/extensions/doctor/dependencies.ts +41 -5
- package/extensions/doctor/fix-prompt.ts +9 -2
- package/extensions/doctor/index.ts +102 -58
- package/extensions/doctor/models.ts +102 -63
- package/extensions/doctor/presets.ts +42 -27
- package/extensions/doctor/report.ts +19 -2
- package/extensions/doctor/viewer.ts +49 -27
- package/extensions/effort/index.ts +72 -19
- package/extensions/effort/settings.ts +21 -0
- package/extensions/effort/slider.ts +24 -20
- package/extensions/exit/index.ts +32 -1
- package/extensions/file-tracker/index.ts +337 -26
- package/extensions/file-tracker/replay.ts +96 -10
- package/extensions/file-tracker/restore.ts +63 -0
- package/extensions/file-tracker/results.ts +66 -0
- package/extensions/file-tracker/shell-reads.ts +211 -0
- package/extensions/file-tracker/tracker.ts +32 -15
- package/extensions/footer/footer-line.ts +45 -24
- package/extensions/footer/index.ts +47 -2
- package/extensions/footer/pr.ts +34 -5
- package/extensions/hooks/compaction.ts +7 -0
- package/extensions/hooks/executor.ts +32 -30
- package/extensions/hooks/index.ts +198 -31
- package/extensions/hooks/matcher.ts +3 -0
- package/extensions/hooks/protocol.ts +41 -3
- package/extensions/hooks/settings.ts +50 -19
- package/extensions/hooks/subagent-bridge.ts +2 -0
- package/extensions/hooks/trust.ts +13 -5
- package/extensions/idle-compact/index.ts +119 -0
- package/extensions/idle-compact/policy.ts +143 -0
- package/extensions/init/index.ts +11 -10
- package/extensions/init/prompt.ts +25 -32
- package/extensions/interrupted/index.ts +13 -1
- package/extensions/kept-thinking/index.ts +27 -0
- package/extensions/lib/agent-cron.ts +130 -0
- package/extensions/lib/agent-loader.ts +15 -1
- package/extensions/lib/agent-view.ts +85 -0
- package/extensions/lib/anthropic-payload.ts +82 -1
- package/extensions/lib/anthropic-server-call.ts +230 -0
- package/extensions/lib/anthropic-server-tools.ts +485 -0
- package/extensions/lib/app-launch.mjs +94 -0
- package/extensions/lib/argument-hints.ts +190 -0
- package/extensions/lib/atomic-write.ts +6 -2
- package/extensions/lib/auto-memory.ts +75 -0
- package/extensions/lib/bash-parser.ts +84 -0
- package/extensions/lib/btw-fork.ts +93 -0
- package/extensions/lib/child-extensions.ts +42 -0
- package/extensions/lib/child-writes.ts +45 -0
- package/extensions/lib/claude-context.ts +515 -100
- package/extensions/lib/claude-external-includes.ts +68 -0
- package/extensions/lib/claude-id.ts +22 -0
- package/extensions/lib/claude-rules.ts +323 -0
- package/extensions/lib/claude-settings.ts +76 -4
- package/extensions/lib/compaction-boundary.ts +36 -0
- package/extensions/lib/compaction-keep.mjs +83 -0
- package/extensions/lib/config-mode.ts +112 -0
- package/extensions/lib/consent-dialogs.ts +63 -0
- package/extensions/lib/consent-preview.ts +5 -1
- package/extensions/lib/consent-stores.ts +48 -0
- package/extensions/lib/context-facts.ts +78 -0
- package/extensions/lib/context-stack.ts +81 -0
- package/extensions/lib/deferred.ts +219 -25
- package/extensions/lib/dock-rows.ts +60 -0
- package/extensions/lib/empty-tool-result.ts +27 -0
- package/extensions/lib/environment-block.ts +76 -0
- package/extensions/lib/fetch-timeout.ts +24 -6
- package/extensions/{system-prompt → lib}/git-status.ts +51 -13
- package/extensions/lib/git.ts +75 -13
- package/extensions/lib/grammars/LICENSE-tree-sitter-bash +21 -0
- package/extensions/lib/grammars/README.md +2 -0
- package/extensions/lib/grammars/tree-sitter-bash.wasm +0 -0
- package/extensions/lib/guide-docs.ts +45 -0
- package/extensions/lib/headless-output.ts +46 -0
- package/extensions/lib/hook-gate.ts +7 -7
- package/extensions/lib/interrupt.ts +20 -4
- package/extensions/lib/key-input.ts +455 -0
- package/extensions/lib/keys.ts +14 -1
- package/extensions/lib/local-command.ts +47 -13
- package/extensions/lib/mcp-overrides.ts +1 -1
- package/extensions/lib/mcp-share.ts +46 -0
- package/extensions/lib/memory-content.ts +146 -0
- package/extensions/lib/memory-index.ts +18 -0
- package/extensions/lib/memory.ts +134 -123
- package/extensions/lib/model-catalog/huggingface.json +174 -0
- package/extensions/lib/model-catalog/models-dev.json +18297 -0
- package/extensions/lib/model-catalog/openrouter.json +5252 -0
- package/extensions/lib/model-catalog-data.ts +513 -0
- package/extensions/lib/model-catalog.ts +462 -0
- package/extensions/lib/model-choice-warnings.ts +137 -0
- package/extensions/lib/model-pairings.ts +152 -0
- package/extensions/{auto-mode → lib}/model-picker.ts +26 -43
- package/extensions/lib/model-policy.ts +112 -15
- package/extensions/lib/model-tier.ts +283 -355
- package/extensions/lib/model-unusable.ts +1 -1
- package/extensions/lib/newer-model.ts +100 -0
- package/extensions/lib/notices.ts +87 -0
- package/extensions/lib/notifications.ts +308 -64
- package/extensions/lib/one-code-settings.ts +74 -8
- package/extensions/lib/open-browser.ts +63 -0
- package/extensions/lib/openrouter-generation.ts +94 -0
- package/extensions/lib/operation-deadline.ts +30 -0
- package/extensions/lib/original-command.ts +4 -4
- package/extensions/lib/package-version.ts +1 -1
- package/extensions/lib/panel-focus.ts +134 -0
- package/extensions/lib/paths.ts +17 -2
- package/extensions/lib/permission-gate.ts +72 -6
- package/extensions/lib/persisted-output.ts +60 -8
- package/extensions/lib/pi-ai-estimate.ts +19 -3
- package/extensions/lib/pi-version.ts +21 -2
- package/extensions/lib/plan-mode-channels.ts +20 -5
- package/extensions/lib/plugins.ts +26 -17
- package/extensions/lib/powershell-parse-script.ts +208 -0
- package/extensions/lib/powershell-parser.ts +344 -0
- package/extensions/lib/process-tree.ts +131 -8
- package/extensions/lib/prompt-options.ts +82 -0
- package/extensions/lib/queued-delivery.ts +44 -0
- package/extensions/lib/reminders.ts +364 -58
- package/extensions/lib/replaced-builtins.mjs +199 -0
- package/extensions/lib/replay-call.ts +70 -0
- package/extensions/lib/request-replay.ts +439 -0
- package/extensions/lib/scratchpad.ts +81 -14
- package/extensions/lib/send-now-channel.ts +7 -0
- package/extensions/lib/session-model-tier.ts +51 -0
- package/extensions/lib/session-work.ts +64 -0
- package/extensions/lib/settings-channels.ts +4 -4
- package/extensions/lib/shell-exit-semantics.ts +170 -0
- package/extensions/lib/shell-quote.ts +11 -0
- package/extensions/lib/shell-result.ts +70 -0
- package/extensions/lib/shell-spawn.ts +70 -6
- package/extensions/lib/shell-tool.ts +75 -25
- package/extensions/lib/side-call-cache.ts +124 -0
- package/extensions/lib/side-call-run.ts +96 -0
- package/extensions/lib/side-call-usage.ts +38 -0
- package/extensions/lib/side-call.ts +13 -1
- package/extensions/lib/single-flight.ts +18 -0
- package/extensions/lib/skill-body.ts +42 -0
- package/extensions/lib/skill-scan.ts +63 -24
- package/extensions/lib/spill-file.ts +140 -0
- package/extensions/lib/subagent-handback.ts +113 -0
- package/extensions/lib/system-role.ts +156 -0
- package/extensions/lib/terminal-text.ts +114 -0
- package/extensions/lib/text-width.ts +47 -16
- package/extensions/lib/timer-ops.ts +20 -0
- package/extensions/lib/tool-additions.ts +149 -0
- package/extensions/lib/tool-call-corruption.ts +134 -0
- package/extensions/lib/tool-path.ts +66 -0
- package/extensions/lib/tool-variants.ts +69 -0
- package/extensions/lib/tui-render.ts +255 -27
- package/extensions/lib/turn-budget-layout.ts +143 -0
- package/extensions/lib/update-check.mjs +15 -2
- package/extensions/lib/usage-bus.ts +1 -1
- package/extensions/lib/user-denial.ts +38 -0
- package/extensions/lib/workspace-channel.ts +16 -0
- package/extensions/lib/worktree-channel.ts +31 -3
- package/extensions/lib/worktree-isolation.ts +40 -10
- package/extensions/lsp/client.ts +8 -9
- package/extensions/lsp/index.ts +70 -4
- package/extensions/lsp/keep-alive.ts +1 -1
- package/extensions/lsp/trust.ts +119 -0
- package/extensions/lsp/watcher.ts +1 -1
- package/extensions/mcp/announce.ts +87 -5
- package/extensions/mcp/client.ts +161 -48
- package/extensions/mcp/config.ts +132 -8
- package/extensions/mcp/discovery.ts +19 -0
- package/extensions/mcp/index.ts +209 -71
- package/extensions/mcp/oauth/browser.ts +38 -17
- package/extensions/mcp/oauth/flow.ts +25 -17
- package/extensions/mcp/oauth/provider.ts +14 -8
- package/extensions/mcp/oauth/store.ts +34 -16
- package/extensions/mcp/panel/keys.ts +12 -11
- package/extensions/mcp/panel/render.ts +9 -6
- package/extensions/mcp/schema.ts +104 -5
- package/extensions/mcp/trust.ts +151 -67
- package/extensions/memory/entries.ts +23 -14
- package/extensions/memory/index.ts +134 -28
- package/extensions/memory/open-external.ts +33 -18
- package/extensions/memory/panel.ts +135 -26
- package/extensions/newer-model/index.ts +31 -0
- package/extensions/notebook/description.ts +18 -0
- package/extensions/notebook/index.ts +6 -5
- package/extensions/notebook/notebook.ts +1 -1
- package/extensions/permissions/index.ts +1300 -381
- package/extensions/permissions/matcher.ts +425 -74
- package/extensions/permissions/modes.ts +6 -4
- package/extensions/permissions/panel/host.ts +130 -0
- package/extensions/permissions/panel/keys.ts +48 -0
- package/extensions/permissions/panel/render.ts +450 -0
- package/extensions/permissions/panel/state.ts +550 -0
- package/extensions/permissions/powershell-cmdlets.ts +198 -0
- package/extensions/permissions/powershell-paths.ts +197 -0
- package/extensions/permissions/powershell-rules.ts +207 -280
- package/extensions/permissions/powershell-tree.ts +557 -0
- package/extensions/permissions/project-trust.ts +27 -11
- package/extensions/permissions/protected-paths.ts +14 -2
- package/extensions/permissions/session-grant.ts +6 -0
- package/extensions/permissions/settings.ts +166 -31
- package/extensions/permissions/subagent-gate.ts +25 -0
- package/extensions/permissions/workspace.ts +78 -0
- package/extensions/plan-mode/index.ts +156 -69
- package/extensions/plan-mode/reminder.ts +89 -21
- package/extensions/plan-mode/texts.ts +177 -0
- package/extensions/plan-mode/viewer.ts +92 -27
- package/extensions/plugins/counts.ts +3 -3
- package/extensions/plugins/index.ts +61 -46
- package/extensions/plugins/install/install.ts +16 -0
- package/extensions/plugins/marketplace/sync.ts +9 -3
- package/extensions/plugins/marketplace/types.ts +3 -1
- package/extensions/plugins/panel/keys.ts +21 -24
- package/extensions/plugins/panel/render.ts +12 -6
- package/extensions/plugins/shell-expand.ts +107 -0
- package/extensions/plugins/template.ts +32 -15
- package/extensions/powershell/child.ts +7 -0
- package/extensions/powershell/description.ts +38 -6
- package/extensions/powershell/guards.ts +1 -1
- package/extensions/powershell/index.ts +12 -7
- package/extensions/recap/index.ts +65 -60
- package/extensions/recap/prompt.ts +2 -2
- package/extensions/recap/scheduler.ts +3 -5
- package/extensions/search-tools/grep-merge.ts +39 -0
- package/extensions/search-tools/index.ts +0 -0
- package/extensions/send-now/chord.ts +62 -0
- package/extensions/send-now/index.ts +133 -0
- package/extensions/session-title/index.ts +3 -0
- package/extensions/session-title/title.ts +4 -1
- package/extensions/skill/code-review.ts +97 -0
- package/extensions/skill/index.ts +421 -101
- package/extensions/skill/invoke.ts +128 -18
- package/extensions/skill/listing.ts +133 -9
- package/extensions/skill/panel/keys.ts +15 -16
- package/extensions/skill/panel/render.ts +5 -2
- package/extensions/skill/panel/state.ts +12 -1
- package/extensions/subagents/agent-args.ts +39 -0
- package/extensions/subagents/agent-description.ts +132 -0
- package/extensions/subagents/agents.ts +116 -23
- package/extensions/subagents/announce.ts +69 -0
- package/extensions/subagents/default-model.ts +2 -3
- package/extensions/subagents/delegation-steer.ts +4 -4
- package/extensions/subagents/fork-cache.ts +76 -0
- package/extensions/subagents/guide-agent.ts +189 -0
- package/extensions/subagents/hand-back-review.ts +3 -0
- package/extensions/subagents/index.ts +1493 -824
- package/extensions/subagents/live-runs.ts +26 -6
- package/extensions/subagents/model-select.ts +38 -25
- package/extensions/subagents/outcome.ts +2 -2
- package/extensions/subagents/panel-keys.ts +73 -31
- package/extensions/subagents/panel-render.ts +120 -96
- package/extensions/subagents/panel-widget.ts +60 -89
- package/extensions/subagents/runner.ts +108 -80
- package/extensions/subagents/runs.ts +39 -5
- package/extensions/subagents/send-to-main-tool.ts +1 -1
- package/extensions/subagents/session-turns.ts +32 -8
- package/extensions/subagents/shell-panel.ts +36 -178
- package/extensions/subagents/tasks-dialog.ts +170 -0
- package/extensions/subagents/viewport-mirror.ts +95 -0
- package/extensions/subagents/worktree.ts +57 -13
- package/extensions/system-prompt/environment.ts +19 -19
- package/extensions/system-prompt/idle-turn.ts +65 -0
- package/extensions/system-prompt/index.ts +131 -47
- package/extensions/system-prompt/template.ts +24 -50
- package/extensions/system-prompt/tiers/common.ts +23 -64
- package/extensions/system-prompt/tiers/frontier.ts +32 -11
- package/extensions/system-prompt/tiers/low.ts +67 -45
- package/extensions/system-prompt/tiers/mid.ts +96 -38
- package/extensions/system-reminder/index.ts +175 -13
- package/extensions/tasks/descriptions.ts +190 -0
- package/extensions/tasks/index.ts +120 -41
- package/extensions/tasks/store.ts +83 -16
- package/extensions/tool-call-corruption/child.ts +7 -0
- package/extensions/tool-call-corruption/index.ts +237 -0
- package/extensions/tool-search/announce.ts +16 -0
- package/extensions/tool-search/index.ts +189 -41
- package/extensions/tool-style/index.ts +68 -10
- package/extensions/tool-style/write-description.ts +40 -0
- package/extensions/tool-style/write-render.ts +237 -0
- package/extensions/turn-duration/index.ts +7 -3
- package/extensions/turn-duration/line.ts +47 -4
- package/extensions/web/backends.ts +6 -9
- package/extensions/web/description.ts +50 -0
- package/extensions/web/index.ts +118 -53
- package/extensions/web/native-call.ts +15 -0
- package/extensions/web/native-results.ts +41 -0
- package/extensions/web-fetch/description.ts +42 -0
- package/extensions/web-fetch/extract.ts +53 -6
- package/extensions/web-fetch/index.ts +125 -76
- package/extensions/web-fetch/page-content.ts +19 -0
- package/extensions/web-fetch/response.ts +49 -0
- package/extensions/web-fetch/summarize.ts +9 -10
- package/extensions/workflow/agent-session.ts +105 -18
- package/extensions/workflow/args.ts +24 -0
- package/extensions/workflow/description.ts +67 -0
- package/extensions/workflow/globals.ts +17 -3
- package/extensions/workflow/index.ts +145 -162
- package/extensions/workflow/records.ts +1 -0
- package/extensions/workflow/run-manager.ts +29 -6
- package/extensions/workflow/saved-workflows.ts +3 -2
- package/extensions/workflow/types.ts +22 -1
- package/extensions/workflow/viewer.ts +54 -24
- package/extensions/workflow/widget.ts +20 -0
- package/extensions/worktree/descriptions.ts +91 -0
- package/extensions/worktree/guards.ts +316 -54
- package/extensions/worktree/index.ts +121 -39
- package/extensions/worktree/powershell-guards.ts +167 -0
- package/extensions/worktree/rewrite.ts +14 -16
- package/package.json +18 -7
- package/skills/artifact-design/SKILL.md +85 -0
- package/skills/code-review/SKILL.md +20 -20
- package/skills/code-review/cells/arguments-and-flags.md +19 -0
- package/skills/code-review/cells/high-3x5-recall-verify.md +137 -0
- package/skills/code-review/cells/high-8-inline.md +122 -0
- package/skills/code-review/cells/low-1-pass-max4.md +27 -0
- package/skills/code-review/cells/low-1-pass-min-files-4.md +28 -0
- package/skills/code-review/cells/max-5x5-verify-sweep.md +162 -0
- package/skills/code-review/cells/medium-3x5-verify.md +132 -0
- package/skills/code-review/cells/minimal-prompt.md +32 -0
- package/skills/code-review/cells/xhigh-10-inline-sweep.md +149 -0
- package/skills/code-review/cells/xhigh-5x5-verify-sweep.md +162 -0
- package/skills/fewer-permission-prompts/SKILL.md +1 -1
- package/skills/loop/SKILL.md +11 -0
- package/skills/security-review/SKILL.md +2 -5
- package/skills/simplify/SKILL.md +7 -5
- package/skills/workflow-authoring/SKILL.md +143 -0
- package/themes/onecode-light.json +1 -1
- package/themes/onecode.json +1 -1
- package/types/app.d.ts +58 -0
- package/types/community-packages.d.ts +26 -1
- package/extensions/auto-mode/recoverability.ts +0 -229
- package/extensions/lib/capability-index.ts +0 -466
- package/extensions/lib/model-facts.generated.json +0 -2675
- package/extensions/lib/model-facts.ts +0 -162
|
@@ -15,6 +15,7 @@ import { randomBytes } from "node:crypto";
|
|
|
15
15
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
16
16
|
import os from "node:os";
|
|
17
17
|
import { join } from "node:path";
|
|
18
|
+
import type { ToolDefinition } from "@earendil-works/pi-coding-agent";
|
|
18
19
|
import type { PermissionBridge } from "../permissions/subagent-gate.ts";
|
|
19
20
|
import type { HookBridge } from "../hooks/subagent-bridge.ts";
|
|
20
21
|
import type { SubagentDefault } from "../subagents/default-model.ts";
|
|
@@ -25,7 +26,7 @@ import { AgentRecordStore, previewValue } from "./records.ts";
|
|
|
25
26
|
import { findSavedWorkflow } from "./saved-workflows.ts";
|
|
26
27
|
import { parseWorkflowScript } from "./script-source.ts";
|
|
27
28
|
import { runWorkflowScript } from "./vm-runtime.ts";
|
|
28
|
-
import type { RunProgressEvent, RunStatus, WorkflowMeta } from "./types.ts";
|
|
29
|
+
import type { AgentRecord, RunProgressEvent, RunStatus, WorkflowMeta } from "./types.ts";
|
|
29
30
|
import { WorkflowScriptError } from "./types.ts";
|
|
30
31
|
import type { ViewerRunSnapshot } from "./viewer.ts";
|
|
31
32
|
|
|
@@ -53,6 +54,10 @@ export interface StartRunOptions {
|
|
|
53
54
|
unusableModels?: () => ReadonlySet<string>;
|
|
54
55
|
/** An agent's provider refused its model: published so every picker skips it (lib/model-unusable.ts). */
|
|
55
56
|
onModelUnusable?: (model: string, reason: string) => void;
|
|
57
|
+
/** An agent's edit or write changed a file (lib/child-writes.ts). */
|
|
58
|
+
onChildWrite?: (path: string, agent: string | undefined) => void;
|
|
59
|
+
/** The parent's live MCP tools, shared into every workflow agent (see AgentRunnerOptions). */
|
|
60
|
+
getMcpTools?: () => ToolDefinition[] | Promise<ToolDefinition[]>;
|
|
56
61
|
}
|
|
57
62
|
|
|
58
63
|
export class RunHandle extends EventEmitter {
|
|
@@ -137,9 +142,11 @@ function formatEvent(event: RunProgressEvent): string | undefined {
|
|
|
137
142
|
return `— ${event.phase} —`;
|
|
138
143
|
case "agentStart":
|
|
139
144
|
return `⏳ ${event.label}${event.phase ? ` [${event.phase}]` : ""}`;
|
|
140
|
-
case "agentEnd":
|
|
141
|
-
|
|
142
|
-
return
|
|
145
|
+
case "agentEnd": {
|
|
146
|
+
const kept = event.worktree ? ` · worktree kept at ${event.worktree.path}` : "";
|
|
147
|
+
if (event.text) return `✗ ${event.label}: ${event.text}${kept}`;
|
|
148
|
+
return `✓ ${event.label}${event.replayed ? " (replayed)" : ""}${event.tokens ? ` · ${event.tokens.output} out` : ""}${kept}`;
|
|
149
|
+
}
|
|
143
150
|
default:
|
|
144
151
|
return undefined;
|
|
145
152
|
}
|
|
@@ -254,6 +261,9 @@ export class WorkflowRunManager {
|
|
|
254
261
|
onUsage: options.onUsage,
|
|
255
262
|
unusableModels: options.unusableModels,
|
|
256
263
|
onModelUnusable: options.onModelUnusable,
|
|
264
|
+
onChildWrite: options.onChildWrite,
|
|
265
|
+
getMcpTools: options.getMcpTools,
|
|
266
|
+
resultsDir: handle.runDir,
|
|
257
267
|
});
|
|
258
268
|
|
|
259
269
|
const { globals, state } = createScriptGlobals({
|
|
@@ -342,14 +352,27 @@ export function buildRunReport(handle: RunHandle): string {
|
|
|
342
352
|
? `${state.agentCount()} agent(s), ${state.outputTokens()} output tokens, $${state.cost().toFixed(4)}, ${duration}s`
|
|
343
353
|
: `${duration}s`;
|
|
344
354
|
|
|
355
|
+
const kept = keptWorktreesSection(handle.agents.list());
|
|
345
356
|
if (handle.status === "completed") {
|
|
346
357
|
const resultText =
|
|
347
358
|
handle.result === undefined
|
|
348
359
|
? "(script returned no value)"
|
|
349
360
|
: previewValue(handle.result, RESULT_CAP, "\n… (truncated)");
|
|
350
|
-
return `Workflow **${handle.meta.name}** (${handle.runId}) completed — ${statsLine}.\n\nResult:\n${resultText}`;
|
|
361
|
+
return `Workflow **${handle.meta.name}** (${handle.runId}) completed — ${statsLine}.\n\nResult:\n${resultText}${kept}`;
|
|
351
362
|
}
|
|
352
363
|
|
|
353
364
|
const tail = handle.recentEvents.slice(-5).join("\n");
|
|
354
|
-
return `Workflow **${handle.meta.name}** (${handle.runId}) ${handle.status} — ${statsLine}.\nReason: ${handle.errorMessage ?? "unknown"}${tail ? `\nRecent progress:\n${tail}` : ""}\nCompleted agent calls are journaled; re-invoke the workflow tool with resumeFromRunId: "${handle.runId}" to continue from where it stopped
|
|
365
|
+
return `Workflow **${handle.meta.name}** (${handle.runId}) ${handle.status} — ${statsLine}.\nReason: ${handle.errorMessage ?? "unknown"}${tail ? `\nRecent progress:\n${tail}` : ""}\nCompleted agent calls are journaled; re-invoke the workflow tool with resumeFromRunId: "${handle.runId}" to continue from where it stopped.${kept}`;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* The report's list of isolation worktrees the run's agents left work in:
|
|
370
|
+
* their edits and commits live only there, so the model must be told where
|
|
371
|
+
* to review and merge them. Empty when every worktree was removed.
|
|
372
|
+
*/
|
|
373
|
+
function keptWorktreesSection(agents: readonly AgentRecord[]): string {
|
|
374
|
+
const kept = agents.filter((agent) => agent.worktree);
|
|
375
|
+
if (kept.length === 0) return "";
|
|
376
|
+
const lines = kept.map((agent) => `- ${agent.label}: ${agent.worktree!.path}${agent.worktree!.branch ? ` (branch ${agent.worktree!.branch})` : ""}`);
|
|
377
|
+
return `\n\nWorktrees kept with agents' changes or commits (review or merge them):\n${lines.join("\n")}`;
|
|
355
378
|
}
|
|
@@ -10,7 +10,7 @@ import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
|
10
10
|
import { basename, join } from "node:path";
|
|
11
11
|
import { parseWorkflowScript } from "./script-source.ts";
|
|
12
12
|
import type { SavedWorkflow } from "./types.ts";
|
|
13
|
-
import {
|
|
13
|
+
import { projectConfigDir, userConfigDir } from "../lib/config-mode.ts";
|
|
14
14
|
|
|
15
15
|
function scanDir(dir: string, source: SavedWorkflow["source"]): SavedWorkflow[] {
|
|
16
16
|
if (!existsSync(dir)) return [];
|
|
@@ -29,8 +29,9 @@ function scanDir(dir: string, source: SavedWorkflow["source"]): SavedWorkflow[]
|
|
|
29
29
|
return found;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
/** `.claude/workflows` and `~/.claude/workflows`, or their `.onecode` twins in independent mode (lib/config-mode.ts). */
|
|
32
33
|
export function workflowDirs(cwd: string, home: string): { project: string; user: string } {
|
|
33
|
-
return { project: join(cwd, "
|
|
34
|
+
return { project: join(projectConfigDir(cwd), "workflows"), user: join(userConfigDir(home), "workflows") };
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
export function discoverSavedWorkflows(cwd: string, home: string): SavedWorkflow[] {
|
|
@@ -47,8 +47,25 @@ export interface AgentCallResult {
|
|
|
47
47
|
value: unknown;
|
|
48
48
|
tokens: AgentTokens;
|
|
49
49
|
cost: number;
|
|
50
|
-
/** Path of a kept worktree (uncommitted changes
|
|
50
|
+
/** Path of a kept worktree (the agent left uncommitted changes or commits there), if any. */
|
|
51
51
|
worktreePath?: string;
|
|
52
|
+
/** The kept worktree's branch, which holds the agent's commits. */
|
|
53
|
+
worktreeBranch?: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** An `isolation: 'worktree'` agent's worktree, kept because it holds the agent's work. */
|
|
57
|
+
export interface KeptWorktree {
|
|
58
|
+
path: string;
|
|
59
|
+
branch?: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The worktree a failed agent call kept, carried on the error it threw (the
|
|
64
|
+
* call returns no result to put it on), so the run still reports it.
|
|
65
|
+
*/
|
|
66
|
+
export function keptWorktreeOf(error: unknown): KeptWorktree | undefined {
|
|
67
|
+
const kept = (error as { keptWorktree?: KeptWorktree } | undefined)?.keptWorktree;
|
|
68
|
+
return kept && typeof kept.path === "string" ? kept : undefined;
|
|
52
69
|
}
|
|
53
70
|
|
|
54
71
|
/** One tool call an agent made, kept structured so the viewer owns the formatting. */
|
|
@@ -122,6 +139,8 @@ export type RunProgressEvent = (
|
|
|
122
139
|
preview?: string;
|
|
123
140
|
/** Failure message; presence means the agent failed. */
|
|
124
141
|
text?: string;
|
|
142
|
+
/** The agent's isolation worktree, kept because it holds changes or commits. */
|
|
143
|
+
worktree?: KeptWorktree;
|
|
125
144
|
} & AgentEventBase)
|
|
126
145
|
) & { source?: string };
|
|
127
146
|
|
|
@@ -147,6 +166,8 @@ export interface AgentRecord {
|
|
|
147
166
|
outcome?: string;
|
|
148
167
|
/** Failure message when status === "failed". */
|
|
149
168
|
error?: string;
|
|
169
|
+
/** The agent's kept isolation worktree, where its changes or commits wait to be merged. */
|
|
170
|
+
worktree?: KeptWorktree;
|
|
150
171
|
}
|
|
151
172
|
|
|
152
173
|
/** A saved workflow discovered in .claude/workflows/ or ~/.claude/workflows/. */
|
|
@@ -11,9 +11,11 @@
|
|
|
11
11
|
* before painting so ANSI escapes never enter the width accounting.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import { cutPlainText as cut, formatDuration, padPlainText, splitCell, splitRow, visibleWidth, wrapPlainText } from "../lib/tui-render.ts";
|
|
14
|
+
import { cutPlainText as cut, formatDuration, padPlainText, splitCell, splitRow, visibleWidth, wrapHints, wrapPlainText, wrapProse } from "../lib/tui-render.ts";
|
|
15
15
|
import { formatTokenCount } from "../subagents/usage.ts";
|
|
16
16
|
import type { AgentRecord, RunStatus } from "./types.ts";
|
|
17
|
+
import { keyId, keyText } from "../lib/key-input.ts";
|
|
18
|
+
import { projectConfigDirName } from "../lib/config-mode.ts";
|
|
17
19
|
|
|
18
20
|
/** Theme access the renderer needs: fg tokens ("accent", "dim", "error", …) and bold. */
|
|
19
21
|
export interface ViewerPaint {
|
|
@@ -76,24 +78,30 @@ export type ViewerKey =
|
|
|
76
78
|
| { kind: "close" };
|
|
77
79
|
|
|
78
80
|
export function decodeViewerKey(data: string): ViewerKey | undefined {
|
|
79
|
-
switch (data) {
|
|
80
|
-
case "
|
|
81
|
-
case "\x1bOA":
|
|
81
|
+
switch (keyId(data)) {
|
|
82
|
+
case "up":
|
|
82
83
|
return { kind: "up" };
|
|
83
|
-
case "
|
|
84
|
-
case "\x1bOB":
|
|
84
|
+
case "down":
|
|
85
85
|
return { kind: "down" };
|
|
86
|
-
case "
|
|
86
|
+
case "pageUp":
|
|
87
87
|
return { kind: "pageUp" };
|
|
88
|
-
case "
|
|
88
|
+
case "pageDown":
|
|
89
|
+
// pi's fullscreen mode keeps PageUp/PageDown for its own scrollback, so
|
|
90
|
+
// space and b page too (findings §10).
|
|
91
|
+
case "space":
|
|
89
92
|
return { kind: "pageDown" };
|
|
90
|
-
case "
|
|
93
|
+
case "tab":
|
|
91
94
|
return { kind: "nextRun" };
|
|
92
|
-
case "
|
|
93
|
-
case "\n":
|
|
95
|
+
case "enter":
|
|
94
96
|
return { kind: "enter" };
|
|
95
|
-
case "
|
|
97
|
+
case "escape":
|
|
96
98
|
return { kind: "back" };
|
|
99
|
+
case "ctrl+c": // close from anywhere, like q
|
|
100
|
+
return { kind: "close" };
|
|
101
|
+
default:
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
switch (keyText(data)) {
|
|
97
105
|
case "x":
|
|
98
106
|
case "X":
|
|
99
107
|
return { kind: "stop" };
|
|
@@ -101,8 +109,9 @@ export function decodeViewerKey(data: string): ViewerKey | undefined {
|
|
|
101
109
|
case "S":
|
|
102
110
|
return { kind: "save" };
|
|
103
111
|
case "q":
|
|
104
|
-
case "\x03": // ctrl+c — close from anywhere, like q
|
|
105
112
|
return { kind: "close" };
|
|
113
|
+
case "b":
|
|
114
|
+
return { kind: "pageUp" };
|
|
106
115
|
default:
|
|
107
116
|
return undefined;
|
|
108
117
|
}
|
|
@@ -137,7 +146,7 @@ export function planSave(input: {
|
|
|
137
146
|
sameContent: boolean;
|
|
138
147
|
confirmed: boolean;
|
|
139
148
|
}): { action: "write" | "confirm" | "noop"; notice: string } {
|
|
140
|
-
const target =
|
|
149
|
+
const target = `${projectConfigDirName()}/workflows/${input.name}.js`;
|
|
141
150
|
if (!input.exists || input.sameContent) return { action: "write", notice: `saved to ${target}` };
|
|
142
151
|
if (input.confirmed) return { action: "write", notice: `overwrote ${target}` };
|
|
143
152
|
return { action: "confirm", notice: `${target} exists and differs — press s again to overwrite` };
|
|
@@ -348,7 +357,11 @@ export function buildDetail(
|
|
|
348
357
|
if (record.status === "failed") {
|
|
349
358
|
section("Error", wrapPlainText(record.error ?? "unknown", width - 2), "error");
|
|
350
359
|
} else {
|
|
351
|
-
section("Outcome", record.outcome ?
|
|
360
|
+
section("Outcome", record.outcome ? wrapProse(record.outcome, width - 2) : ["Still running…"], record.outcome ? undefined : "dim");
|
|
361
|
+
}
|
|
362
|
+
if (record.worktree) {
|
|
363
|
+
const { path, branch } = record.worktree;
|
|
364
|
+
section("Worktree kept", wrapPlainText(`${path}${branch ? ` (branch ${branch})` : ""}`, width - 2));
|
|
352
365
|
}
|
|
353
366
|
return lines;
|
|
354
367
|
}
|
|
@@ -367,6 +380,20 @@ export interface ViewerInput {
|
|
|
367
380
|
|
|
368
381
|
const MIN_TWO_PANE_WIDTH = 70;
|
|
369
382
|
|
|
383
|
+
/**
|
|
384
|
+
* Rows the viewer may take. It replaces the editor, so pi's layout keeps the
|
|
385
|
+
* rest of the dock beside it: the status strip, the permission-mode line and
|
|
386
|
+
* the footer below, at least one transcript row above, and a status or
|
|
387
|
+
* widget line. pi cuts a component taller than its share from the bottom,
|
|
388
|
+
* which took the key-hint row, so the viewer leaves those rows free.
|
|
389
|
+
* `stripRows` is the status strip's current row count.
|
|
390
|
+
*/
|
|
391
|
+
export function viewerHeight(terminalRows: number, mode: "full" | "half", stripRows: number): number {
|
|
392
|
+
const reserved = 4 + Math.max(0, stripRows);
|
|
393
|
+
const available = Math.max(8, terminalRows - reserved);
|
|
394
|
+
return mode === "half" ? Math.min(available, Math.max(12, Math.min(Math.floor(terminalRows / 2), 30))) : available;
|
|
395
|
+
}
|
|
396
|
+
|
|
370
397
|
export function renderViewer(input: ViewerInput, paint: ViewerPaint): string[] {
|
|
371
398
|
const { runs, state } = input;
|
|
372
399
|
const width = Math.max(20, input.width);
|
|
@@ -406,10 +433,18 @@ export function renderViewer(input: ViewerInput, paint: ViewerPaint): string[] {
|
|
|
406
433
|
out.push(paint.fg("error", cut(`⚠ ${run.errorMessage}`, width)));
|
|
407
434
|
}
|
|
408
435
|
|
|
409
|
-
//
|
|
410
|
-
|
|
411
|
-
|
|
436
|
+
// Footer: per-level key hints, replaced by a transient notice when set. It
|
|
437
|
+
// wraps at the separators on a narrow terminal so no key is cut off, and
|
|
438
|
+
// the body gives up the rows the footer needs.
|
|
412
439
|
const atAgents = state.level === "agents" && phase && phase.agents.length > 0;
|
|
440
|
+
const stopHint = run.status === "running" ? "x stop workflow · " : "";
|
|
441
|
+
const hints = !atAgents
|
|
442
|
+
? `↑↓ select · ⏎ open · ${runs.length > 1 ? "tab run · " : ""}${stopHint}s save · esc close`
|
|
443
|
+
: `↑↓ agent · ⏎ prompt · space/b scroll · ${stopHint}s save · esc back`;
|
|
444
|
+
const footer = state.notice ? [cut(state.notice, width)] : wrapHints(hints, width);
|
|
445
|
+
|
|
446
|
+
// Body: two boxed panes, side by side (or stacked when narrow).
|
|
447
|
+
const bodyHeight = Math.max(6, input.height - out.length - footer.length);
|
|
413
448
|
|
|
414
449
|
const agentCountTitle = phase
|
|
415
450
|
? `${phase.title} · ${phase.agents.length} agent${phase.agents.length === 1 ? "" : "s"}`
|
|
@@ -458,12 +493,7 @@ export function renderViewer(input: ViewerInput, paint: ViewerPaint): string[] {
|
|
|
458
493
|
out.push(...boxPane(rightTitle, panes.right, width, rightHeight, paint));
|
|
459
494
|
}
|
|
460
495
|
|
|
461
|
-
|
|
462
|
-
const stopHint = run.status === "running" ? "x stop workflow · " : "";
|
|
463
|
-
const hints = !atAgents
|
|
464
|
-
? `↑↓ select · ⏎ open · ${runs.length > 1 ? "tab run · " : ""}${stopHint}s save · esc close`
|
|
465
|
-
: `↑↓ agent · ⏎ prompt · pgup/pgdn scroll · ${stopHint}s save · esc back`;
|
|
466
|
-
out.push(paint.fg("dim", cut(state.notice ?? hints, width)));
|
|
496
|
+
for (const line of footer) out.push(paint.fg("dim", line));
|
|
467
497
|
return out;
|
|
468
498
|
}
|
|
469
499
|
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
15
|
+
import { canShowCustomUi } from "../lib/headless-output.ts";
|
|
15
16
|
import { linesComponent, liveUiCtx, safeThemeBold, safeThemePaint } from "../lib/tui-render.ts";
|
|
16
17
|
import type { RunHandle, WorkflowRunManager } from "./run-manager.ts";
|
|
17
18
|
import { MAX_STATUS_ROWS, renderStatusRows, type ViewerRunSnapshot } from "./viewer.ts";
|
|
@@ -42,6 +43,8 @@ export class WorkflowWidget {
|
|
|
42
43
|
constructor(
|
|
43
44
|
private readonly manager: WorkflowRunManager,
|
|
44
45
|
private readonly getCtx: () => ExtensionContext | undefined,
|
|
46
|
+
/** Told the rows this strip paints below the editor (lib/dock-rows.ts). */
|
|
47
|
+
private readonly onRows: (rows: number) => void = () => {},
|
|
45
48
|
) {}
|
|
46
49
|
|
|
47
50
|
attach(handle: RunHandle): void {
|
|
@@ -64,6 +67,12 @@ export class WorkflowWidget {
|
|
|
64
67
|
return Math.min(this.manager.list().length, MAX_STATUS_ROWS);
|
|
65
68
|
}
|
|
66
69
|
|
|
70
|
+
/** Rows the strip paints: one per shown run plus the "+n more" line. */
|
|
71
|
+
paintedRowCount(): number {
|
|
72
|
+
const total = this.manager.list().length;
|
|
73
|
+
return Math.min(total, MAX_STATUS_ROWS) + (total > MAX_STATUS_ROWS ? 1 : 0);
|
|
74
|
+
}
|
|
75
|
+
|
|
67
76
|
selectedRun(): ViewerRunSnapshot | undefined {
|
|
68
77
|
if (this.focusIndex === undefined) return undefined;
|
|
69
78
|
return this.manager.snapshots(MAX_STATUS_ROWS)[this.focusIndex];
|
|
@@ -99,6 +108,7 @@ export class WorkflowWidget {
|
|
|
99
108
|
|
|
100
109
|
dispose(): void {
|
|
101
110
|
this.disposed = true;
|
|
111
|
+
this.onRows(0);
|
|
102
112
|
if (this.timer) clearTimeout(this.timer);
|
|
103
113
|
if (this.ticker) clearInterval(this.ticker);
|
|
104
114
|
this.timer = this.ticker = undefined;
|
|
@@ -124,6 +134,7 @@ export class WorkflowWidget {
|
|
|
124
134
|
this.syncTicker(runs);
|
|
125
135
|
if (!runs.length) {
|
|
126
136
|
ctx.ui.setWidget(WIDGET_KEY, undefined);
|
|
137
|
+
this.onRows(0);
|
|
127
138
|
return;
|
|
128
139
|
}
|
|
129
140
|
if (this.focusIndex !== undefined && this.focusIndex >= this.rowCount()) {
|
|
@@ -131,6 +142,14 @@ export class WorkflowWidget {
|
|
|
131
142
|
}
|
|
132
143
|
const selected = this.focusIndex;
|
|
133
144
|
const now = Date.now();
|
|
145
|
+
// RPC forwards string-array widgets but silently ignores factories.
|
|
146
|
+
if (!canShowCustomUi(ctx)) {
|
|
147
|
+
const lines = runs.map((run) => `${run.runId} ${run.name} — ${run.status} (${run.agents.length} agents)`);
|
|
148
|
+
if (totalRuns > runs.length) lines.push(`${totalRuns - runs.length} more workflows — /workflows to list all`);
|
|
149
|
+
ctx.ui.setWidget(WIDGET_KEY, lines, { placement: "belowEditor" });
|
|
150
|
+
this.onRows(0); // no TUI view sizes itself in RPC
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
134
153
|
ctx.ui.setWidget(
|
|
135
154
|
WIDGET_KEY,
|
|
136
155
|
(tui, theme) => {
|
|
@@ -148,6 +167,7 @@ export class WorkflowWidget {
|
|
|
148
167
|
},
|
|
149
168
|
{ placement: "belowEditor" },
|
|
150
169
|
);
|
|
170
|
+
this.onRows(this.paintedRowCount());
|
|
151
171
|
}
|
|
152
172
|
|
|
153
173
|
/** Keep elapsed time ticking while any run is live; stop when none is. */
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* enter_worktree and exit_worktree's model-facing texts: Claude Code's
|
|
3
|
+
* EnterWorktree and ExitWorktree descriptions, trimmed of what One Code does
|
|
4
|
+
* not have (pure).
|
|
5
|
+
*
|
|
6
|
+
* Removed: the WorktreeCreate/WorktreeRemove hooks, the `worktree.baseRef`
|
|
7
|
+
* setting (a new worktree always branches from the current HEAD), the
|
|
8
|
+
* prompt on session exit, nested repositories in a multi-repo workspace,
|
|
9
|
+
* switching from an agent pinned at launch, the tmux session and the cache
|
|
10
|
+
* clearing on exit. Tool names are One Code's.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** Claude Code's EnterWorktree description, naming the mode's config directory (`.onecode` in independent mode, lib/config-mode.ts). */
|
|
14
|
+
export function enterWorktreeDescription(configDir = ".claude"): string {
|
|
15
|
+
return `Use this tool ONLY when explicitly instructed to work in a worktree — either by the user directly, or by project instructions (CLAUDE.md / memory). This tool creates an isolated git worktree and switches the current session into it.
|
|
16
|
+
|
|
17
|
+
## When to Use
|
|
18
|
+
|
|
19
|
+
- The user explicitly says "worktree" (e.g., "start a worktree", "work in a worktree", "create a worktree", "use a worktree")
|
|
20
|
+
- CLAUDE.md or memory instructions direct you to work in a worktree for the current task
|
|
21
|
+
|
|
22
|
+
## When NOT to Use
|
|
23
|
+
|
|
24
|
+
- The user asks to create a branch, switch branches, or work on a different branch — use git commands instead
|
|
25
|
+
- The user asks to fix a bug or work on a feature — use normal git workflow unless worktrees are explicitly requested by the user or project instructions
|
|
26
|
+
- Never use this tool unless "worktree" is explicitly mentioned by the user or in CLAUDE.md / memory instructions
|
|
27
|
+
|
|
28
|
+
## Requirements
|
|
29
|
+
|
|
30
|
+
- Must be in a git repository
|
|
31
|
+
- Must not already be in a worktree session when creating a new worktree (\`name\`); switching into another existing worktree via \`path\` is allowed
|
|
32
|
+
|
|
33
|
+
## Behavior
|
|
34
|
+
|
|
35
|
+
- In a git repository: creates a new git worktree inside \`${configDir}/worktrees/\` on a new branch from your current local HEAD
|
|
36
|
+
- Switches the session's working directory to the new worktree
|
|
37
|
+
- Use exit_worktree to leave the worktree mid-session (keep or remove)
|
|
38
|
+
|
|
39
|
+
## Entering an existing worktree
|
|
40
|
+
|
|
41
|
+
Pass \`path\` instead of \`name\` to switch the session into a worktree that already exists (e.g., one you just created with \`git worktree add\`). The path must appear in \`git worktree list\` for the current repository; other paths are rejected. exit_worktree will not remove a worktree entered this way; use \`action: "keep"\` to return to the original directory.
|
|
42
|
+
|
|
43
|
+
Switching with \`path\` also works when the session is already in a worktree (the previous worktree is left on disk, untouched). Re-issue enter_worktree with \`path\` to return to one.
|
|
44
|
+
|
|
45
|
+
## Parameters
|
|
46
|
+
|
|
47
|
+
- \`name\` (optional): A name for a new worktree. If neither \`name\` nor \`path\` is provided, a random name is generated.
|
|
48
|
+
- \`path\` (optional): Path to an existing worktree of the current repository to enter instead of creating one. Mutually exclusive with \`name\`.
|
|
49
|
+
`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const ENTER_WORKTREE_DESCRIPTION = enterWorktreeDescription();
|
|
53
|
+
|
|
54
|
+
export const EXIT_WORKTREE_DESCRIPTION = `Exit a worktree session created by enter_worktree and return the session to the original working directory.
|
|
55
|
+
|
|
56
|
+
## Scope
|
|
57
|
+
|
|
58
|
+
This tool ONLY operates on the worktree session enter_worktree started in this session. It will NOT touch:
|
|
59
|
+
- Worktrees you created manually with \`git worktree add\` and never entered with enter_worktree (one entered by \`path\` can be left with \`action: "keep"\`, but never removed)
|
|
60
|
+
- Worktrees from a previous session (even if created by enter_worktree then)
|
|
61
|
+
- The directory you're in if enter_worktree was never called
|
|
62
|
+
|
|
63
|
+
If called outside an enter_worktree session, the tool is a **no-op**: it reports that no worktree session is active and takes no action. Filesystem state is unchanged.
|
|
64
|
+
|
|
65
|
+
## When to Use
|
|
66
|
+
|
|
67
|
+
- The user explicitly asks to "exit the worktree", "leave the worktree", "go back", or otherwise end the worktree session
|
|
68
|
+
- Do NOT call this proactively — only when the user asks
|
|
69
|
+
|
|
70
|
+
## Parameters
|
|
71
|
+
|
|
72
|
+
- \`action\` (required): \`"keep"\` or \`"remove"\`
|
|
73
|
+
- \`"keep"\` — leave the worktree directory and branch intact on disk. Use this if the user wants to come back to the work later, or if there are changes to preserve.
|
|
74
|
+
- \`"remove"\` — delete the worktree directory and its branch. Use this for a clean exit when the work is done or abandoned.
|
|
75
|
+
- \`discard_changes\` (optional, default false): only meaningful with \`action: "remove"\`. If the worktree has uncommitted files or commits not on the original branch, the tool will REFUSE to remove it unless this is set to \`true\`. If the tool returns an error listing changes, confirm with the user before re-invoking with \`discard_changes: true\`.
|
|
76
|
+
|
|
77
|
+
## Behavior
|
|
78
|
+
|
|
79
|
+
- Restores the session's working directory to where it was before enter_worktree
|
|
80
|
+
- Once exited, enter_worktree can be called again to create a fresh worktree
|
|
81
|
+
`;
|
|
82
|
+
|
|
83
|
+
export const ENTER_WORKTREE_PARAMS = {
|
|
84
|
+
name: `Optional name for a new worktree. Each "/"-separated segment may contain only letters, digits, dots, underscores, and dashes; max 64 chars total. A random name is generated if not provided. Mutually exclusive with \`path\`.`,
|
|
85
|
+
path: `Path to an existing worktree to switch into instead of creating a new one. Must appear in \`git worktree list\` for the current repo. Mutually exclusive with \`name\`.`,
|
|
86
|
+
} as const;
|
|
87
|
+
|
|
88
|
+
export const EXIT_WORKTREE_PARAMS = {
|
|
89
|
+
action: `"keep" leaves the worktree and branch on disk; "remove" deletes both.`,
|
|
90
|
+
discard_changes: `Required true when action is "remove" and the worktree has uncommitted files or unmerged commits. The tool will refuse and list them otherwise.`,
|
|
91
|
+
} as const;
|