pi-crew 0.9.68 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. package/CHANGELOG.md +124 -0
  2. package/agents/analyst.md +1 -1
  3. package/agents/cold-verifier.md +3 -1
  4. package/agents/critic.md +1 -1
  5. package/agents/executor.md +1 -1
  6. package/agents/explorer.md +1 -1
  7. package/agents/planner.md +1 -1
  8. package/agents/reviewer.md +1 -1
  9. package/agents/security-reviewer.md +1 -1
  10. package/agents/test-engineer.md +1 -1
  11. package/agents/verifier.md +1 -1
  12. package/agents/writer.md +1 -1
  13. package/dist/index.mjs +65838 -60331
  14. package/docs/README.md +2 -0
  15. package/docs/actions-reference.md +31 -0
  16. package/docs/commands-reference.md +17 -6
  17. package/docs/resource-formats.md +13 -0
  18. package/package.json +4 -2
  19. package/schema.json +15 -1
  20. package/scripts/resource-sampler.mjs +36 -2
  21. package/skills/requirements-to-task-packet/SKILL.md +26 -0
  22. package/skills/widget-rendering/SKILL.md +7 -7
  23. package/src/agents/agent-config.ts +2 -1
  24. package/src/agents/discover-agents.ts +23 -14
  25. package/src/config/config-merge.ts +183 -0
  26. package/src/config/config-validation.ts +681 -0
  27. package/src/config/config.ts +22 -864
  28. package/src/config/defaults.ts +35 -1
  29. package/src/config/drift-detector.ts +1 -1
  30. package/src/config/env-vars.ts +691 -0
  31. package/src/config/role-tools.ts +8 -8
  32. package/src/config/sanitize-project-config.ts +172 -0
  33. package/src/config/types.ts +30 -0
  34. package/src/extension/async-notifier.ts +25 -2
  35. package/src/extension/crew-vibes/config.ts +2 -1
  36. package/src/extension/plan-orchestrate.ts +132 -0
  37. package/src/extension/registration/commands/dashboard.ts +158 -0
  38. package/src/extension/registration/commands/index.ts +35 -0
  39. package/src/extension/registration/commands/manage.ts +303 -0
  40. package/src/extension/registration/commands/run.ts +214 -0
  41. package/src/extension/registration/commands/shared.ts +631 -0
  42. package/src/extension/registration/commands/status.ts +60 -0
  43. package/src/extension/registration/commands.ts +13 -1224
  44. package/src/extension/registration/lifecycle-handlers.ts +126 -15
  45. package/src/extension/registration/subagent-tools.ts +218 -9
  46. package/src/extension/rpc-hmac.ts +5 -3
  47. package/src/extension/team-tool/api/heartbeat.ts +47 -10
  48. package/src/extension/team-tool/api/plan-approval.ts +9 -0
  49. package/src/extension/team-tool/api/task-claims.ts +109 -40
  50. package/src/extension/team-tool/cancel.ts +84 -50
  51. package/src/extension/team-tool/dispatch/index.ts +1 -0
  52. package/src/extension/team-tool/dispatch/run.ts +4 -1
  53. package/src/extension/team-tool/doctor.ts +103 -1
  54. package/src/extension/team-tool/orchestrate.ts +66 -1
  55. package/src/extension/team-tool/plans.ts +192 -0
  56. package/src/extension/team-tool/respond.ts +197 -65
  57. package/src/extension/team-tool/run-deadline.ts +16 -1
  58. package/src/extension/team-tool/run-intent.ts +63 -0
  59. package/src/extension/team-tool/run.ts +48 -18
  60. package/src/extension/team-tool/status.ts +84 -26
  61. package/src/extension/team-tool.ts +11 -2
  62. package/src/hooks/registry.ts +1 -6
  63. package/src/i18n.ts +9 -0
  64. package/src/prompt/prompt-runtime.ts +521 -2
  65. package/src/prompt/worker-events-channel.ts +173 -0
  66. package/src/runtime/README.md +8 -8
  67. package/src/runtime/async-runner.ts +7 -3
  68. package/src/runtime/background-runner.ts +42 -14
  69. package/src/runtime/broker/broker-issuer.ts +9 -2
  70. package/src/runtime/broker/crew-broker-tokens.ts +43 -6
  71. package/src/runtime/broker/crew-broker.ts +838 -10
  72. package/src/runtime/broker/wait-status-cache.ts +157 -0
  73. package/src/runtime/budget-enforcement.ts +281 -0
  74. package/src/runtime/child-pi/child-pi-spawn.ts +60 -14
  75. package/src/runtime/child-pi/child-pi-timers.ts +324 -0
  76. package/src/runtime/child-pi/child-pi.ts +97 -201
  77. package/src/runtime/child-pi/mock-fixtures.ts +16 -2
  78. package/src/runtime/crew-agent-records.ts +259 -14
  79. package/src/runtime/delegate-spawn.ts +148 -0
  80. package/src/runtime/deterministic-ast.ts +2 -1
  81. package/src/runtime/dispatch-batch.ts +945 -0
  82. package/src/runtime/finalize-run.ts +557 -0
  83. package/src/runtime/goal-workflow/adaptive-plan.ts +87 -13
  84. package/src/runtime/goal-workflow/dynamic-workflow-runner.ts +3 -2
  85. package/src/runtime/goal-workflow/goal-state-store.ts +1 -1
  86. package/src/runtime/group-join.ts +11 -125
  87. package/src/runtime/live-session/live-session-runtime.ts +26 -1
  88. package/src/runtime/merge-gate.ts +7 -1
  89. package/src/runtime/merge-loop.ts +130 -0
  90. package/src/runtime/model/model-budget-summary.ts +53 -0
  91. package/src/runtime/model/model-fallback.ts +32 -2
  92. package/src/runtime/model/pi-args.ts +10 -0
  93. package/src/runtime/model/provider-extensions.ts +10 -0
  94. package/src/runtime/orphan-worker-registry.ts +1 -1
  95. package/src/runtime/output/output-validator.ts +45 -0
  96. package/src/runtime/parent-guard.ts +3 -1
  97. package/src/runtime/peer-dep.ts +2 -1
  98. package/src/runtime/per-write-validator.ts +0 -5
  99. package/src/runtime/pi-spawn.ts +61 -15
  100. package/src/runtime/plan-approval.ts +125 -0
  101. package/src/runtime/plan-replan.ts +151 -0
  102. package/src/runtime/recovery/checkpoint.ts +0 -18
  103. package/src/runtime/recovery/crash-recovery.ts +95 -46
  104. package/src/runtime/scheduler-context.ts +98 -0
  105. package/src/runtime/scheduling/coalesce-tasks.ts +5 -0
  106. package/src/runtime/scheduling/global-worker-cap.ts +2 -1
  107. package/src/runtime/scheduling/nested-slots.ts +70 -0
  108. package/src/runtime/scheduling/run-coalesced-task-group.ts +64 -13
  109. package/src/runtime/scheduling/task-graph-scheduler.ts +0 -10
  110. package/src/runtime/settings-store.ts +219 -0
  111. package/src/runtime/spawn-policy.ts +217 -0
  112. package/src/runtime/stale-reconciler.ts +87 -6
  113. package/src/runtime/subagent-manager.ts +25 -1
  114. package/src/runtime/task-output-context.ts +230 -9
  115. package/src/runtime/task-packet.ts +23 -1
  116. package/src/runtime/task-runner/child-executor.ts +106 -7
  117. package/src/runtime/task-runner/post-execution.ts +125 -1
  118. package/src/runtime/task-runner/pre-execution.ts +39 -1
  119. package/src/runtime/task-runner/prompt-builder.ts +51 -1
  120. package/src/runtime/task-runner/retrieval-orchestrator.ts +72 -18
  121. package/src/runtime/task-runner/spec-evidence.ts +403 -0
  122. package/src/runtime/task-runner/state-helpers.ts +26 -24
  123. package/src/runtime/task-runner.ts +11 -0
  124. package/src/runtime/team-runner.ts +129 -1671
  125. package/src/runtime/verification/spec-sandbox.ts +255 -0
  126. package/src/runtime/verification/verification-gates.ts +3 -2
  127. package/src/runtime/verification/verification-worktree.ts +2 -1
  128. package/src/runtime/workflow-phase-advance.ts +100 -0
  129. package/src/runtime/workspace-tree.ts +9 -0
  130. package/src/schema/config-schema.ts +65 -25
  131. package/src/schema/sensitive-config-paths.ts +64 -0
  132. package/src/schema/team-tool-schema.ts +13 -3
  133. package/src/state/README.md +4 -10
  134. package/src/state/atomic-write.ts +20 -3
  135. package/src/state/contracts.ts +38 -0
  136. package/src/state/coordination/mailbox.ts +12 -2
  137. package/src/state/event-log/cursor.ts +223 -0
  138. package/src/state/event-log/event-log-rotation.ts +12 -4
  139. package/src/state/event-log/event-log.ts +152 -369
  140. package/src/state/event-log/sequence-cache.ts +373 -0
  141. package/src/state/event-log/worker-atomic-writer.ts +2 -1
  142. package/src/state/stores/active-run-registry.ts +3 -2
  143. package/src/state/stores/manifest-io.ts +237 -0
  144. package/src/state/stores/ownership-map.ts +162 -0
  145. package/src/state/stores/plan-store.ts +241 -0
  146. package/src/state/stores/run-cache.ts +0 -90
  147. package/src/state/stores/spec-store.ts +189 -0
  148. package/src/state/stores/state-store.ts +66 -229
  149. package/src/state/types.ts +197 -0
  150. package/src/ui/dashboard-panes/plan-pane.ts +136 -0
  151. package/src/ui/dashboard-panes/progress-pane.ts +6 -0
  152. package/src/ui/dashboard-panes/transcript-pane.ts +31 -0
  153. package/src/ui/heartbeat-aggregator.ts +9 -1
  154. package/src/ui/keybinding-map.ts +54 -13
  155. package/src/ui/powerbar-publisher.ts +52 -1
  156. package/src/ui/run-dashboard.ts +31 -5
  157. package/src/ui/run-snapshot-cache.ts +57 -30
  158. package/src/ui/snapshot-types.ts +6 -1
  159. package/src/ui/widget/widget-renderer.ts +9 -1
  160. package/src/utils/file-coalescer.ts +0 -4
  161. package/src/utils/fs-errno.ts +66 -0
  162. package/src/utils/fs-watch.ts +1 -1
  163. package/src/utils/internal-error.ts +3 -1
  164. package/src/utils/paths.ts +11 -3
  165. package/src/utils/task-name-generator.ts +1 -8
  166. package/src/workflows/discover-workflows.ts +19 -2
  167. package/src/workflows/validate-workflow.ts +7 -1
  168. package/src/workflows/workflow-config.ts +10 -0
  169. package/src/workflows/workflow-serializer.ts +3 -0
  170. package/src/worktree/worktree-manager.ts +22 -0
  171. package/src/agents/agent-search.ts +0 -98
  172. package/src/benchmark/benchmark-runner.ts +0 -313
  173. package/src/benchmark/feedback-loop.ts +0 -73
  174. package/src/config/resilient-parser.ts +0 -117
  175. package/src/extension/crew-vibes/cat-frames.ts +0 -18
  176. package/src/extension/result-watcher.ts +0 -139
  177. package/src/observability/exporters/prometheus-exporter.ts +0 -54
  178. package/src/observability/metric-retention.ts +0 -64
  179. package/src/runtime/compaction/compaction-summary.ts +0 -278
  180. package/src/runtime/errors/crew-errors.ts +0 -162
  181. package/src/runtime/live-session/intercom-bridge.ts +0 -187
  182. package/src/runtime/loop-gates.ts +0 -128
  183. package/src/runtime/metric-parser.ts +0 -36
  184. package/src/runtime/output/stream-preview.ts +0 -184
  185. package/src/runtime/output/tool-progress.ts +0 -278
  186. package/src/runtime/phase-tracker.ts +0 -385
  187. package/src/runtime/pipeline-runner.ts +0 -523
  188. package/src/runtime/process/process-lifecycle.ts +0 -491
  189. package/src/runtime/recovery/retry-runner.ts +0 -330
  190. package/src/runtime/run-drift.ts +0 -219
  191. package/src/runtime/task-quality.ts +0 -199
  192. package/src/runtime/task-runner/run-projection.ts +0 -128
  193. package/src/runtime/verification/post-checks.ts +0 -142
  194. package/src/state/coordination/schedule.ts +0 -166
  195. package/src/state/event-log/jsonl-writer.ts +0 -115
  196. package/src/state/hook-instinct-bridge.ts +0 -94
  197. package/src/state/hook-integrations.ts +0 -51
  198. package/src/state/session-state-map.ts +0 -51
  199. package/src/state/stores/blob-store.ts +0 -308
  200. package/src/state/stores/instinct-store.ts +0 -275
  201. package/src/state/stores/observation-store.ts +0 -176
  202. package/src/state/tiered-eval.ts +0 -480
  203. package/src/state/types-eval.ts +0 -58
  204. package/src/tools/safe-bash-extension.ts +0 -54
  205. package/src/tools/safe-bash.ts +0 -505
  206. package/src/ui/agent-management-overlay.ts +0 -160
  207. package/src/ui/crew-footer.ts +0 -102
  208. package/src/ui/crew-select-list.ts +0 -114
  209. package/src/ui/dashboard-panes/capability-pane.ts +0 -77
  210. package/src/ui/transcript-entries.ts +0 -256
  211. package/src/utils/conflict-detect.ts +0 -721
  212. package/src/utils/fingerprint.ts +0 -180
  213. package/src/utils/gh-protocol.ts +0 -556
  214. package/src/utils/project-detector.ts +0 -160
  215. package/src/utils/sse-parser.ts +0 -131
  216. package/src/workflows/cost-estimator.ts +0 -34
  217. package/src/workflows/intermediate-store.ts +0 -166
@@ -0,0 +1,35 @@
1
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
+ import { printTimings, time } from "../../../utils/timings.ts";
3
+ import { registerDashboardCommands } from "./dashboard.ts";
4
+ import { registerManageCommands } from "./manage.ts";
5
+ import { registerRunCommands } from "./run.ts";
6
+ import type { RegisterTeamCommandsDeps } from "./shared.ts";
7
+ import { setTeamCommandsDeps } from "./shared.ts";
8
+ import { registerStatusCommands } from "./status.ts";
9
+
10
+ /**
11
+ * Register every pi-crew slash command on the ExtensionAPI.
12
+ *
13
+ * Phase 2.1 split: the former monolith `src/extension/registration/commands.ts`
14
+ * is now a re-export shim over this directory. Registration wiring lives here;
15
+ * the command handlers live in run.ts / status.ts / manage.ts / dashboard.ts,
16
+ * and cross-category module state + helpers (handleTeamTool, the UI cache,
17
+ * the overlays) live in shared.ts.
18
+ */
19
+ export function registerTeamCommands(pi: ExtensionAPI, deps: RegisterTeamCommandsDeps): void {
20
+ setTeamCommandsDeps(deps);
21
+ registerStatusCommands(pi, deps);
22
+ registerRunCommands(pi, deps);
23
+ registerManageCommands(pi, deps);
24
+ registerDashboardCommands(pi, deps);
25
+ time("register.commands");
26
+ printTimings();
27
+ }
28
+
29
+ export type { RegisterTeamCommandsDeps } from "./shared.ts";
30
+ // Re-export the shared seam + overlay entry points (and the deps type) so the
31
+ // original `./commands.ts` path keeps resolving every named export consumers
32
+ // rely on: __test__setHandleTeamTool (commands-handler.test.ts),
33
+ // openTeamSettingsOverlay + openTeamDashboard (crew-shortcuts.ts LAZY dynamic
34
+ // imports), RegisterTeamCommandsDeps (type).
35
+ export { __test__setHandleTeamTool, openTeamDashboard, openTeamSettingsOverlay } from "./shared.ts";
@@ -0,0 +1,303 @@
1
+ import * as fs from "node:fs";
2
+ import * as path from "node:path";
3
+ import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
4
+ import { getBuiltinTemplates, instantiateTemplate, listTemplates } from "../../../skills/skill-templates.ts";
5
+ import { atomicWriteFile } from "../../../state/atomic-write.ts";
6
+ import { suggestRunIds } from "../../command-completions.ts";
7
+ import { handleTeamManagerCommand } from "../../team-manager-command.ts";
8
+ import { commandText, notifyCommandResult, parseScalar, pushUnset, setNestedConfig } from "../command-utils.ts";
9
+ import type { RegisterTeamCommandsDeps } from "./shared.ts";
10
+ import { handleTeamTool, openTeamSettingsOverlay, teamCommandContext } from "./shared.ts";
11
+
12
+ export function registerManageCommands(pi: ExtensionAPI, deps: RegisterTeamCommandsDeps): void {
13
+ pi.registerCommand("team-prune", {
14
+ description: "Prune old finished pi-crew runs, keeping the newest N",
15
+ handler: async (args: string, ctx: ExtensionCommandContext) => {
16
+ const tokens = args.trim().split(/\s+/).filter(Boolean);
17
+ const keepToken = tokens.find((token) => token.startsWith("--keep="));
18
+ const keep = keepToken ? Number.parseInt(keepToken.slice("--keep=".length), 10) : undefined;
19
+ const result = await handleTeamTool(
20
+ {
21
+ action: "prune",
22
+ keep,
23
+ confirm: tokens.includes("--confirm"),
24
+ },
25
+ teamCommandContext(ctx),
26
+ );
27
+ await notifyCommandResult(ctx, commandText(result));
28
+ },
29
+ });
30
+
31
+ pi.registerCommand("team-forget", {
32
+ description: "Forget a pi-crew run by deleting its state and artifacts",
33
+ getArgumentCompletions: (argumentPrefix: string) => suggestRunIds(argumentPrefix),
34
+ handler: async (args: string, ctx: ExtensionCommandContext) => {
35
+ const tokens = args.trim().split(/\s+/).filter(Boolean);
36
+ const runId = tokens.find((token) => !token.startsWith("--"));
37
+ const result = await handleTeamTool(
38
+ {
39
+ action: "forget",
40
+ runId,
41
+ force: tokens.includes("--force"),
42
+ confirm: tokens.includes("--confirm"),
43
+ },
44
+ teamCommandContext(ctx),
45
+ );
46
+ await notifyCommandResult(ctx, commandText(result));
47
+ },
48
+ });
49
+
50
+ pi.registerCommand("team-settings", {
51
+ description: "View or update pi-crew settings: interactive UI or [list|get <key>|set <key> <value>|unset <key>|path|scope]",
52
+ handler: async (args: string, ctx: ExtensionCommandContext) => {
53
+ if (ctx.hasUI && !args.trim()) {
54
+ await openTeamSettingsOverlay(ctx);
55
+ return;
56
+ }
57
+ const result = await handleTeamTool({ action: "settings", config: { args: args.trim() } }, teamCommandContext(ctx));
58
+ await notifyCommandResult(ctx, commandText(result));
59
+ // Live-switch hook: when the text subcommand 'theme <name>' succeeds,
60
+ // also apply the theme live via ctx.ui.setTheme() (no restart). The
61
+ // handler above only writes to settings.json.
62
+ const trimmed = args.trim();
63
+ if (trimmed.startsWith("theme ")) {
64
+ const themeName = trimmed.slice(6).trim();
65
+ if (themeName && typeof ctx.ui.setTheme === "function") {
66
+ const res = ctx.ui.setTheme(themeName);
67
+ if (res.success) ctx.ui.notify(`Theme: ${themeName} (applied live)`, "info");
68
+ else ctx.ui.notify(`Saved but live-switch failed: ${res.error ?? "unknown"}. Restart Pi.`, "warning");
69
+ }
70
+ }
71
+ },
72
+ });
73
+
74
+ pi.registerCommand("team-manager", {
75
+ description: "Open the pi-crew interactive menu (list/run/status/cleanup/manage resources/doctor)",
76
+ handler: handleTeamManagerCommand,
77
+ });
78
+ // Backward-compat alias: this command was originally registered as "team-cleanup"
79
+ // (the interactive menu predates the runId-targeted cleanup action). Keep both so
80
+
81
+ pi.registerCommand("team-cleanup-menu", {
82
+ description: "Alias for /team-manager (pi-crew interactive menu)",
83
+ handler: handleTeamManagerCommand,
84
+ });
85
+
86
+ pi.registerCommand("team-init", {
87
+ description: "Initialize pi-crew layout and global config. Use --project-config to write .pi/pi-crew.json.",
88
+ handler: async (args: string, ctx: ExtensionCommandContext) => {
89
+ const tokens = args.trim().split(/\s+/).filter(Boolean);
90
+ const configScope =
91
+ tokens.includes("--project-config") || tokens.includes("--project")
92
+ ? "project"
93
+ : tokens.includes("--no-config")
94
+ ? "none"
95
+ : "global";
96
+ const result = await handleTeamTool(
97
+ {
98
+ action: "init",
99
+ config: {
100
+ copyBuiltins: tokens.includes("--copy-builtins"),
101
+ overwrite: tokens.includes("--overwrite"),
102
+ configScope,
103
+ },
104
+ },
105
+ teamCommandContext(ctx),
106
+ );
107
+ await notifyCommandResult(ctx, commandText(result));
108
+ },
109
+ });
110
+
111
+ pi.registerCommand("team-autonomy", {
112
+ description: "Show or toggle pi-crew autonomous delegation policy: status|on|off",
113
+ handler: async (args: string, ctx: ExtensionCommandContext) => {
114
+ const tokens = args.trim().split(/\s+/).filter(Boolean);
115
+ const mode = tokens[0]?.toLowerCase();
116
+ const config =
117
+ mode === "on"
118
+ ? {
119
+ profile: "suggested",
120
+ enabled: true,
121
+ injectPolicy: true,
122
+ }
123
+ : mode === "off"
124
+ ? { profile: "manual", enabled: false }
125
+ : mode === "manual" || mode === "suggested" || mode === "assisted" || mode === "aggressive"
126
+ ? {
127
+ profile: mode,
128
+ enabled: mode !== "manual",
129
+ injectPolicy: mode !== "manual",
130
+ }
131
+ : {
132
+ preferAsyncForLongTasks: tokens.includes("--prefer-async") ? true : undefined,
133
+ allowWorktreeSuggestion: tokens.includes("--no-worktree-suggest") ? false : undefined,
134
+ };
135
+ const result = await handleTeamTool({ action: "autonomy", config }, teamCommandContext(ctx));
136
+ await notifyCommandResult(ctx, commandText(result));
137
+ },
138
+ });
139
+
140
+ pi.registerCommand("team-config", {
141
+ description: "Show or update pi-crew config. Use key=value [--project] to update.",
142
+ handler: async (args: string, ctx: ExtensionCommandContext) => {
143
+ const tokens = args.trim().split(/\s+/).filter(Boolean);
144
+ if (tokens.length === 0) {
145
+ const result = await handleTeamTool({ action: "config" }, teamCommandContext(ctx));
146
+ await notifyCommandResult(ctx, commandText(result));
147
+ return;
148
+ }
149
+ const config: Record<string, unknown> = {
150
+ scope: tokens.includes("--project") ? "project" : "user",
151
+ };
152
+ for (const token of tokens) {
153
+ if (token.startsWith("--unset=")) {
154
+ pushUnset(config, token.slice("--unset=".length));
155
+ continue;
156
+ }
157
+ if (!token.includes("=")) continue;
158
+ const [key, ...rest] = token.split("=");
159
+ if (!key) continue;
160
+ const raw = rest.join("=");
161
+ if (raw === "unset" || raw === "null") pushUnset(config, key);
162
+ else setNestedConfig(config, key, parseScalar(raw));
163
+ }
164
+ const result = await handleTeamTool({ action: "config", config }, teamCommandContext(ctx));
165
+ await notifyCommandResult(ctx, commandText(result));
166
+ },
167
+ });
168
+
169
+ pi.registerCommand("skill-list", {
170
+ description: "List available builtin skill templates. Use --json for machine-readable output.",
171
+ handler: async (args: string, ctx: ExtensionCommandContext) => {
172
+ const asJson = args.trim().split(/\s+/).includes("--json");
173
+ const templates = listTemplates();
174
+ if (asJson) {
175
+ await notifyCommandResult(ctx, JSON.stringify(templates, null, 2));
176
+ } else {
177
+ const lines = ["Available builtin skill templates:", ""];
178
+ for (const t of templates) {
179
+ lines.push(` ${t.id.padEnd(20)} ${t.description}`);
180
+ lines.push(
181
+ ` Variables: ${t.variables.map((v) => (v.required ? "[required] " : "[optional] ") + v.name).join(", ")}`,
182
+ );
183
+ }
184
+ lines.push("");
185
+ lines.push("Create a skill: /skill-create <template-id> --var key=value [--var ...]");
186
+ await notifyCommandResult(ctx, lines.join("\n"));
187
+ }
188
+ },
189
+ });
190
+
191
+ pi.registerCommand("skill-create", {
192
+ description: "Create a skill from a builtin template: <template-id> [--var key=value...] [--project]",
193
+ handler: async (args: string, ctx: ExtensionCommandContext) => {
194
+ // LAZY: load withSessionId only when needed for skill-create command
195
+ const { withSessionId } = await import("../../team-tool/context.ts");
196
+ const sessionId = withSessionId(ctx);
197
+ const cwd =
198
+ (
199
+ ctx as unknown as {
200
+ workspaceFolder?: { uri: { fsPath: string } };
201
+ }
202
+ ).workspaceFolder?.uri?.fsPath ?? process.cwd();
203
+ const tokens = args.trim().split(/\s+/).filter(Boolean);
204
+ const useProject = tokens.includes("--project");
205
+ const varEntries = tokens
206
+ .filter((t) => t.startsWith("--var=") || t.startsWith("--var "))
207
+ .map((t): [string, string] => {
208
+ const s = t.replace(/^--var(?:\s+|=)/, "");
209
+ const idx = s.indexOf("=");
210
+ return idx === -1 ? [s, ""] : [s.slice(0, idx), s.slice(idx + 1)];
211
+ });
212
+ const templateId = tokens.find((t) => !t.startsWith("--") && !t.includes("="));
213
+ if (!templateId) {
214
+ await notifyCommandResult(
215
+ ctx,
216
+ "Usage: /skill-create <template-id> [--var key=value...] [--project]\nRun /skill-list to see available templates.",
217
+ );
218
+ return;
219
+ }
220
+ const template = getBuiltinTemplates().find((t) => t.id === templateId);
221
+ if (!template) {
222
+ await notifyCommandResult(ctx, `Unknown template '${templateId}'. Run /skill-list to see available templates.`);
223
+ return;
224
+ }
225
+ const variables: Record<string, string> = {};
226
+ const errors: string[] = [];
227
+ for (const v of template.variables) {
228
+ const entry = varEntries.find(([k]) => k === v.name);
229
+ if (!entry) {
230
+ if (v.required) errors.push(`Missing required variable: ${v.name} (${v.description})`);
231
+ else if (v.defaultValue !== undefined) variables[v.name] = v.defaultValue;
232
+ continue;
233
+ }
234
+ const [, value] = entry;
235
+ if (v.options && !v.options.includes(value)) {
236
+ errors.push(`Invalid value '${value}' for '${v.name}'. Allowed: ${v.options.join(", ")}`);
237
+ continue;
238
+ }
239
+ variables[v.name] = value;
240
+ }
241
+ if (errors.length > 0) {
242
+ await notifyCommandResult(ctx, errors.join("\n"));
243
+ return;
244
+ }
245
+ let instantiated: { filename: string; content: string };
246
+ try {
247
+ instantiated = instantiateTemplate(template, variables);
248
+ } catch (error) {
249
+ await notifyCommandResult(ctx, error instanceof Error ? error.message : String(error));
250
+ return;
251
+ }
252
+ const skillsDir = path.resolve(
253
+ cwd,
254
+ useProject
255
+ ? "skills"
256
+ : path.join(
257
+ path.dirname(
258
+ require.resolve("../../../../package.json", {
259
+ paths: [__dirname],
260
+ }),
261
+ ),
262
+ "skills",
263
+ ),
264
+ );
265
+ const skillDir = path.join(skillsDir, template.id);
266
+ const skillPath = path.join(skillDir, "SKILL.md");
267
+ try {
268
+ fs.mkdirSync(skillDir, { recursive: true });
269
+ atomicWriteFile(skillPath, instantiated.content);
270
+ await notifyCommandResult(
271
+ ctx,
272
+ `Created skill '${template.id}' at:\n${skillPath}\n\n${instantiated.content.slice(0, 200)}...`,
273
+ );
274
+ } catch (error) {
275
+ await notifyCommandResult(ctx, `Failed to write skill: ${error instanceof Error ? error.message : String(error)}`);
276
+ }
277
+ },
278
+ });
279
+
280
+ pi.registerCommand("crew-brief", {
281
+ description: "Toggle brief tool output mode: on | off | status",
282
+ handler: async (args: string, ctx: ExtensionCommandContext) => {
283
+ // LAZY: defer dynamic import of ../../ui/tool-renderers/brief-mode.ts to its call site. Multi-line form breaks scripts/check-lazy-imports.mjs (which does `lines[lineNum - 2]`), so keep destructuring + await import on one line and place this LAZY marker directly above.
284
+ const { isBrief, setBrief, BRIEF_ENTRY_TYPE, makeBriefEntry } = await import("../../../ui/tool-renderers/brief-mode.ts");
285
+ const trimmed = args.trim();
286
+
287
+ if (trimmed === "on") {
288
+ setBrief(true);
289
+ pi.appendEntry(BRIEF_ENTRY_TYPE, { enabled: true });
290
+ ctx.ui.notify("Brief mode: on — tool output will show compact summaries", "info");
291
+ return;
292
+ }
293
+ if (trimmed === "off") {
294
+ setBrief(false);
295
+ pi.appendEntry(BRIEF_ENTRY_TYPE, { enabled: false });
296
+ ctx.ui.notify("Brief mode: off — full tool output restored", "info");
297
+ return;
298
+ }
299
+ // status (default)
300
+ ctx.ui.notify(`Brief mode: ${isBrief() ? "on" : "off"}`, "info");
301
+ },
302
+ });
303
+ }
@@ -0,0 +1,214 @@
1
+ import type { ExtensionAPI, ExtensionCommandContext, ExtensionContext } from "@earendil-works/pi-coding-agent";
2
+ import { suggestRunIds, suggestTeams } from "../../command-completions.ts";
3
+ import { commandText, notifyCommandResult, parseRunArgs, parseScalar } from "../command-utils.ts";
4
+ import type { RegisterTeamCommandsDeps } from "./shared.ts";
5
+ import { handleTeamTool, teamCommandContext } from "./shared.ts";
6
+
7
+ export function registerRunCommands(pi: ExtensionAPI, deps: RegisterTeamCommandsDeps): void {
8
+ pi.registerCommand("team-run", {
9
+ description: "Manually start a pi-crew run (agent may also use the team tool autonomously)",
10
+ // Round 13 UX: suggest team names for Tab-completion of the first positional arg.
11
+ getArgumentCompletions: (argumentPrefix: string) => suggestTeams(argumentPrefix),
12
+ handler: async (args: string, ctx: ExtensionCommandContext) => {
13
+ const result = await handleTeamTool(parseRunArgs(args), {
14
+ ...teamCommandContext(ctx),
15
+ metricRegistry: deps.getMetricRegistry?.(),
16
+ startForegroundRun: (runner, runId) => deps.startForegroundRun(ctx as ExtensionContext, runner, runId),
17
+ abortForegroundRun: deps.abortForegroundRun,
18
+ onRunStarted: undefined,
19
+ });
20
+ await notifyCommandResult(ctx, commandText(result));
21
+ },
22
+ });
23
+
24
+ for (const [name, action, description] of [
25
+ ["team-resume", "resume", "Resume a pi-crew run by re-queueing failed/cancelled/skipped/running tasks"],
26
+ ["team-export", "export", "Export a pi-crew run bundle to artifacts/export"],
27
+ ["team-cancel", "cancel", "Cancel a pi-crew run"],
28
+ ] as const) {
29
+ pi.registerCommand(name, {
30
+ description,
31
+ // Round 13 UX: suggest recent run IDs for Tab-completion.
32
+ getArgumentCompletions: (argumentPrefix: string) => suggestRunIds(argumentPrefix),
33
+ handler: async (args: string, ctx: ExtensionCommandContext) => {
34
+ const runId = args.trim() || undefined;
35
+ const result = await handleTeamTool(
36
+ { action, runId },
37
+ {
38
+ ...teamCommandContext(ctx),
39
+ getRunSnapshotCache: deps.getRunSnapshotCache,
40
+ },
41
+ );
42
+ await notifyCommandResult(ctx, commandText(result));
43
+ },
44
+ });
45
+ }
46
+
47
+ pi.registerCommand("team-invalidate", {
48
+ description: "Invalidate the snapshot cache for a run so the UI refreshes immediately: <runId>",
49
+ getArgumentCompletions: (argumentPrefix: string) => suggestRunIds(argumentPrefix),
50
+ handler: async (args: string, ctx: ExtensionCommandContext) => {
51
+ const runId = args.trim() || undefined;
52
+ if (!runId) {
53
+ await notifyCommandResult(ctx, "Usage: /team-invalidate <runId>");
54
+ return;
55
+ }
56
+ const result = await handleTeamTool(
57
+ { action: "invalidate", runId },
58
+ {
59
+ ...teamCommandContext(ctx),
60
+ getRunSnapshotCache: deps.getRunSnapshotCache,
61
+ },
62
+ );
63
+ await notifyCommandResult(ctx, commandText(result));
64
+ },
65
+ });
66
+
67
+ pi.registerCommand("team-retry", {
68
+ description: "Retry failed/cancelled pi-crew tasks: <runId> [taskId]",
69
+ getArgumentCompletions: (argumentPrefix: string) => suggestRunIds(argumentPrefix),
70
+ handler: async (args: string, ctx: ExtensionCommandContext) => {
71
+ const tokens = args.trim().split(/\s+/).filter(Boolean);
72
+ const runId = tokens.shift();
73
+ const taskId = tokens.shift();
74
+ if (!runId) {
75
+ await notifyCommandResult(ctx, "Usage: /team-retry <runId> [taskId]");
76
+ return;
77
+ }
78
+ const retryResult = await handleTeamTool(
79
+ { action: "retry", runId, taskId },
80
+ {
81
+ ...teamCommandContext(ctx),
82
+ getRunSnapshotCache: deps.getRunSnapshotCache,
83
+ },
84
+ );
85
+ await notifyCommandResult(ctx, commandText(retryResult));
86
+ },
87
+ });
88
+
89
+ pi.registerCommand("team-respond", {
90
+ description: "Respond to a waiting pi-crew task: <runId> <taskId|--all> <message>",
91
+ getArgumentCompletions: (argumentPrefix: string) => suggestRunIds(argumentPrefix),
92
+ handler: async (args: string, ctx: ExtensionCommandContext) => {
93
+ const tokens = args.trim().split(/\s+/).filter(Boolean);
94
+ const runId = tokens.shift();
95
+ const taskToken = tokens[0] === "--all" ? tokens.shift() : tokens.shift();
96
+ const taskId = taskToken === "--all" ? undefined : taskToken;
97
+ const message = tokens.join(" ") || undefined;
98
+ const result = await handleTeamTool({ action: "respond", runId, taskId, message }, teamCommandContext(ctx));
99
+ await notifyCommandResult(ctx, commandText(result));
100
+ },
101
+ });
102
+
103
+ pi.registerCommand("team-follow-up", {
104
+ description: "Send a follow-up prompt to a pi-crew task: <runId> <taskId> <prompt>",
105
+ getArgumentCompletions: (argumentPrefix: string) => suggestRunIds(argumentPrefix),
106
+ handler: async (args: string, ctx: ExtensionCommandContext) => {
107
+ const tokens = args.trim().split(/\s+/).filter(Boolean);
108
+ const runId = tokens.shift();
109
+ const taskId = tokens.shift();
110
+ const prompt = tokens.join(" ") || undefined;
111
+ if (!runId || !taskId || !prompt) {
112
+ await notifyCommandResult(
113
+ ctx,
114
+ "Usage: /team-follow-up <runId> <taskId> <prompt>. Use /team-respond for waiting-task replies.",
115
+ );
116
+ return;
117
+ }
118
+ const result = await handleTeamTool(
119
+ {
120
+ action: "api",
121
+ runId,
122
+ config: { operation: "follow-up-agent", taskId, prompt },
123
+ },
124
+ teamCommandContext(ctx),
125
+ );
126
+ await notifyCommandResult(ctx, commandText(result));
127
+ },
128
+ });
129
+
130
+ pi.registerCommand("team-api", {
131
+ description: "Run safe pi-crew API interop operations: <runId> <operation> [key=value]",
132
+ getArgumentCompletions: (argumentPrefix: string) => suggestRunIds(argumentPrefix),
133
+ handler: async (args: string, ctx: ExtensionCommandContext) => {
134
+ const tokens = args.trim().split(/\s+/).filter(Boolean);
135
+ const positional = tokens.filter((token) => !token.includes("=") && !token.startsWith("--"));
136
+ const runIdLessOperations = new Set(["metrics-snapshot"]);
137
+ const first = positional[0];
138
+ const runId = first && runIdLessOperations.has(first) ? undefined : first;
139
+ const operation = runId ? (positional[1] ?? "read-manifest") : (first ?? "read-manifest");
140
+ const config: Record<string, unknown> = { operation };
141
+ for (const token of tokens.filter((item) => item.includes("="))) {
142
+ const [key, ...rest] = token.split("=");
143
+ if (key) config[key] = parseScalar(rest.join("="));
144
+ }
145
+ const result = await handleTeamTool({ action: "api", runId, config }, teamCommandContext(ctx));
146
+ await notifyCommandResult(ctx, commandText(result));
147
+ },
148
+ });
149
+
150
+ pi.registerCommand("team-goal", {
151
+ description:
152
+ "Autonomous goal loop control: [start|status|pause|resume|stop|step|clear] [goalId] [--objective=...] [--evaluatorModel=...] [--maxTurns=N]",
153
+ handler: async (args: string, ctx: ExtensionCommandContext) => {
154
+ const tokens = args.trim().split(/\s+/).filter(Boolean);
155
+ const knownSubs = new Set(["start", "status", "pause", "resume", "stop", "step", "clear", "cancel", "reset"]);
156
+ const subAction = tokens[0] && knownSubs.has(tokens[0]) ? tokens[0] : "status";
157
+ const positional = tokens.filter((token) => !token.includes("=") && !token.startsWith("--") && token !== subAction);
158
+ const goalId = positional[0];
159
+ const config: Record<string, unknown> = { subAction };
160
+ if (goalId) config.goalId = goalId;
161
+ for (const token of tokens.filter((item) => item.includes("="))) {
162
+ const [key, ...rest] = token.split("=");
163
+ if (key) config[key.replace(/^--/, "")] = parseScalar(rest.join("="));
164
+ }
165
+ const result = await handleTeamTool({ action: "goal", config }, teamCommandContext(ctx));
166
+ await notifyCommandResult(ctx, commandText(result));
167
+ },
168
+ });
169
+
170
+ pi.registerCommand("workflows", {
171
+ description: "List all workflows (static + dynamic .dwf.ts)",
172
+ handler: async (_args: string, ctx: ExtensionCommandContext) => {
173
+ const result = await handleTeamTool({ action: "workflow-list" }, teamCommandContext(ctx));
174
+ await notifyCommandResult(ctx, commandText(result));
175
+ },
176
+ });
177
+
178
+ pi.registerCommand("team-metrics", {
179
+ description: "Show pi-crew metrics snapshot: [filter]",
180
+ handler: async (args: string, ctx: ExtensionCommandContext) => {
181
+ const filter = args.trim() || undefined;
182
+ const result = await handleTeamTool(
183
+ {
184
+ action: "api",
185
+ config: { operation: "metrics-snapshot", filter },
186
+ },
187
+ {
188
+ ...teamCommandContext(ctx),
189
+ metricRegistry: deps.getMetricRegistry?.(),
190
+ },
191
+ );
192
+ await notifyCommandResult(ctx, commandText(result));
193
+ },
194
+ });
195
+
196
+ pi.registerCommand("team-imports", {
197
+ description: "List imported pi-crew run bundles",
198
+ handler: async (_args: string, ctx: ExtensionCommandContext) => {
199
+ const result = await handleTeamTool({ action: "imports" }, teamCommandContext(ctx));
200
+ await notifyCommandResult(ctx, commandText(result));
201
+ },
202
+ });
203
+
204
+ pi.registerCommand("team-import", {
205
+ description: "Import a pi-crew run-export.json bundle into local imports",
206
+ handler: async (args: string, ctx: ExtensionCommandContext) => {
207
+ const tokens = args.trim().split(/\s+/).filter(Boolean);
208
+ const pathArg = tokens.find((token) => !token.startsWith("--"));
209
+ const scope = tokens.includes("--user") ? "user" : "project";
210
+ const result = await handleTeamTool({ action: "import", config: { path: pathArg, scope } }, teamCommandContext(ctx));
211
+ await notifyCommandResult(ctx, commandText(result));
212
+ },
213
+ });
214
+ }