pi-crew 0.9.68 → 0.10.2
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 +222 -0
- package/NOTICE.md +21 -0
- package/README.md +44 -2
- package/agents/analyst.md +1 -1
- package/agents/cold-verifier.md +3 -1
- package/agents/critic.md +1 -1
- package/agents/executor.md +1 -1
- package/agents/explorer.md +1 -1
- package/agents/planner.md +1 -1
- package/agents/reviewer.md +1 -1
- package/agents/security-reviewer.md +1 -1
- package/agents/test-engineer.md +1 -1
- package/agents/verifier.md +1 -1
- package/agents/writer.md +1 -1
- package/dist/index.mjs +68113 -60774
- package/docs/README.md +2 -0
- package/docs/actions-reference.md +31 -0
- package/docs/commands-reference.md +17 -6
- package/docs/resource-formats.md +13 -0
- package/package.json +4 -2
- package/schema.json +503 -91
- package/scripts/resource-sampler.mjs +36 -2
- package/skills/requirements-to-task-packet/SKILL.md +26 -0
- package/skills/widget-rendering/SKILL.md +7 -7
- package/src/agents/agent-config.ts +2 -1
- package/src/agents/discover-agents.ts +23 -14
- package/src/config/config-merge.ts +183 -0
- package/src/config/config-validation.ts +687 -0
- package/src/config/config.ts +22 -864
- package/src/config/defaults.ts +43 -2
- package/src/config/drift-detector.ts +1 -1
- package/src/config/env-vars.ts +691 -0
- package/src/config/role-tools.ts +11 -9
- package/src/config/sanitize-project-config.ts +172 -0
- package/src/config/types.ts +49 -1
- package/src/extension/async-notifier.ts +25 -2
- package/src/extension/crew-cleanup.ts +13 -0
- package/src/extension/crew-vibes/config.ts +2 -1
- package/src/extension/crew-vibes/footer.ts +19 -0
- package/src/extension/crew-vibes/index.ts +11 -1
- package/src/extension/plan-orchestrate.ts +132 -0
- package/src/extension/register.ts +8 -0
- package/src/extension/registration/command-registration.ts +1 -0
- package/src/extension/registration/commands/dashboard.ts +158 -0
- package/src/extension/registration/commands/index.ts +35 -0
- package/src/extension/registration/commands/manage.ts +303 -0
- package/src/extension/registration/commands/run.ts +228 -0
- package/src/extension/registration/commands/shared.ts +639 -0
- package/src/extension/registration/commands/status.ts +60 -0
- package/src/extension/registration/commands.ts +13 -1224
- package/src/extension/registration/foreground-run-controller.ts +10 -2
- package/src/extension/registration/lifecycle-handlers.ts +178 -17
- package/src/extension/registration/runtime-cleanup.ts +23 -5
- package/src/extension/registration/subagent-tools.ts +218 -9
- package/src/extension/registration/team-tool.ts +5 -1
- package/src/extension/registration/ui.ts +5 -4
- package/src/extension/rpc-hmac.ts +5 -3
- package/src/extension/team-tool/api/heartbeat.ts +47 -10
- package/src/extension/team-tool/api/plan-approval.ts +9 -0
- package/src/extension/team-tool/api/task-claims.ts +109 -40
- package/src/extension/team-tool/cancel.ts +84 -50
- package/src/extension/team-tool/dispatch/index.ts +1 -0
- package/src/extension/team-tool/dispatch/run.ts +4 -1
- package/src/extension/team-tool/doctor.ts +103 -1
- package/src/extension/team-tool/orchestrate.ts +66 -1
- package/src/extension/team-tool/plans.ts +192 -0
- package/src/extension/team-tool/respond.ts +197 -65
- package/src/extension/team-tool/run-deadline.ts +35 -3
- package/src/extension/team-tool/run-intent.ts +63 -0
- package/src/extension/team-tool/run.ts +74 -20
- package/src/extension/team-tool/status.ts +84 -26
- package/src/extension/team-tool.ts +11 -2
- package/src/hooks/registry.ts +1 -6
- package/src/i18n.ts +9 -0
- package/src/prompt/prompt-runtime.ts +521 -2
- package/src/prompt/worker-events-channel.ts +173 -0
- package/src/runtime/README.md +8 -8
- package/src/runtime/async-runner.ts +7 -3
- package/src/runtime/background-runner.ts +42 -14
- package/src/runtime/broker/broker-issuer.ts +9 -2
- package/src/runtime/broker/crew-broker-tokens.ts +43 -6
- package/src/runtime/broker/crew-broker.ts +838 -10
- package/src/runtime/broker/wait-status-cache.ts +157 -0
- package/src/runtime/budget-enforcement.ts +281 -0
- package/src/runtime/child-pi/child-pi-constants.ts +8 -0
- package/src/runtime/child-pi/child-pi-spawn.ts +60 -14
- package/src/runtime/child-pi/child-pi-streams.ts +21 -1
- package/src/runtime/child-pi/child-pi-timers.ts +324 -0
- package/src/runtime/child-pi/child-pi.ts +97 -201
- package/src/runtime/child-pi/mock-fixtures.ts +16 -2
- package/src/runtime/crew-agent-records.ts +259 -14
- package/src/runtime/delegate-spawn.ts +148 -0
- package/src/runtime/detached-run-results.ts +90 -0
- package/src/runtime/deterministic-ast.ts +2 -1
- package/src/runtime/dispatch-batch.ts +945 -0
- package/src/runtime/finalize-run.ts +557 -0
- package/src/runtime/goal-workflow/adaptive-plan.ts +116 -15
- package/src/runtime/goal-workflow/dynamic-workflow-runner.ts +8 -3
- package/src/runtime/goal-workflow/goal-state-store.ts +1 -1
- package/src/runtime/group-join.ts +11 -125
- package/src/runtime/live-session/live-session-runtime.ts +26 -1
- package/src/runtime/merge-gate.ts +32 -10
- package/src/runtime/merge-loop.ts +130 -0
- package/src/runtime/model/model-budget-summary.ts +53 -0
- package/src/runtime/model/model-fallback.ts +36 -2
- package/src/runtime/model/pi-args.ts +10 -0
- package/src/runtime/model/provider-extensions.ts +10 -0
- package/src/runtime/orphan-worker-registry.ts +1 -1
- package/src/runtime/output/output-validator.ts +45 -0
- package/src/runtime/parent-guard.ts +3 -1
- package/src/runtime/peer-dep.ts +2 -1
- package/src/runtime/per-write-validator.ts +0 -5
- package/src/runtime/pi-spawn.ts +61 -15
- package/src/runtime/plan-approval.ts +125 -0
- package/src/runtime/plan-replan.ts +151 -0
- package/src/runtime/process-status.ts +16 -1
- package/src/runtime/recovery/checkpoint.ts +0 -18
- package/src/runtime/recovery/crash-recovery.ts +111 -46
- package/src/runtime/run-tracker.ts +77 -10
- package/src/runtime/scheduler-context.ts +98 -0
- package/src/runtime/scheduling/coalesce-tasks.ts +5 -0
- package/src/runtime/scheduling/global-worker-cap.ts +2 -1
- package/src/runtime/scheduling/nested-slots.ts +70 -0
- package/src/runtime/scheduling/run-coalesced-task-group.ts +64 -13
- package/src/runtime/scheduling/task-graph-scheduler.ts +0 -10
- package/src/runtime/settings-store.ts +219 -0
- package/src/runtime/spawn-policy.ts +217 -0
- package/src/runtime/stale-reconciler.ts +87 -6
- package/src/runtime/subagent-manager.ts +25 -1
- package/src/runtime/task-output-context.ts +230 -9
- package/src/runtime/task-packet.ts +23 -1
- package/src/runtime/task-runner/child-executor.ts +106 -7
- package/src/runtime/task-runner/post-execution.ts +125 -1
- package/src/runtime/task-runner/pre-execution.ts +39 -1
- package/src/runtime/task-runner/prompt-builder.ts +51 -1
- package/src/runtime/task-runner/retrieval-orchestrator.ts +72 -18
- package/src/runtime/task-runner/spec-evidence.ts +403 -0
- package/src/runtime/task-runner/state-helpers.ts +26 -24
- package/src/runtime/task-runner.ts +11 -0
- package/src/runtime/team-runner.ts +132 -1673
- package/src/runtime/verification/spec-sandbox.ts +255 -0
- package/src/runtime/verification/verification-gates.ts +3 -2
- package/src/runtime/verification/verification-worktree.ts +2 -1
- package/src/runtime/workflow-phase-advance.ts +100 -0
- package/src/runtime/workspace-tree.ts +9 -0
- package/src/schema/config-schema.ts +66 -26
- package/src/schema/sensitive-config-paths.ts +64 -0
- package/src/schema/team-tool-schema.ts +13 -3
- package/src/state/README.md +4 -10
- package/src/state/atomic-write.ts +20 -3
- package/src/state/contracts.ts +38 -0
- package/src/state/coordination/mailbox.ts +12 -2
- package/src/state/event-log/cursor.ts +223 -0
- package/src/state/event-log/event-log-rotation.ts +12 -4
- package/src/state/event-log/event-log.ts +152 -369
- package/src/state/event-log/sequence-cache.ts +373 -0
- package/src/state/event-log/worker-atomic-writer.ts +2 -1
- package/src/state/stores/active-run-registry.ts +3 -2
- package/src/state/stores/manifest-io.ts +237 -0
- package/src/state/stores/ownership-map.ts +162 -0
- package/src/state/stores/plan-store.ts +241 -0
- package/src/state/stores/run-cache.ts +0 -90
- package/src/state/stores/spec-store.ts +189 -0
- package/src/state/stores/state-store.ts +139 -232
- package/src/state/types.ts +199 -0
- package/src/ui/dashboard-panes/plan-pane.ts +136 -0
- package/src/ui/dashboard-panes/progress-pane.ts +6 -0
- package/src/ui/dashboard-panes/transcript-pane.ts +31 -0
- package/src/ui/dock-footer.ts +49 -0
- package/src/ui/heartbeat-aggregator.ts +9 -1
- package/src/ui/inline-panel/agent-pane.ts +375 -0
- package/src/ui/inline-panel/agent-transcript.ts +338 -0
- package/src/ui/inline-panel/agent-view-overlay.ts +225 -0
- package/src/ui/inline-panel/crew-editor.ts +192 -0
- package/src/ui/inline-panel/index.ts +290 -0
- package/src/ui/inline-panel/panel-rows.ts +37 -0
- package/src/ui/inline-panel/panel-selection.ts +157 -0
- package/src/ui/inline-panel/panel-store.ts +111 -0
- package/src/ui/inline-panel/view-session-store.ts +36 -0
- package/src/ui/keybinding-map.ts +54 -13
- package/src/ui/pi-ui-compat.ts +9 -0
- package/src/ui/powerbar-publisher.ts +52 -1
- package/src/ui/run-dashboard.ts +31 -5
- package/src/ui/run-snapshot-cache.ts +57 -30
- package/src/ui/snapshot-types.ts +6 -1
- package/src/ui/widget/index.ts +176 -22
- package/src/ui/widget/task-list.ts +198 -0
- package/src/ui/widget/widget-formatters.ts +240 -4
- package/src/ui/widget/widget-renderer.ts +243 -38
- package/src/ui/widget/widget-types.ts +11 -0
- package/src/utils/child-process-shield.ts +106 -0
- package/src/utils/file-coalescer.ts +0 -4
- package/src/utils/fs-errno.ts +66 -0
- package/src/utils/fs-watch.ts +1 -1
- package/src/utils/internal-error.ts +3 -1
- package/src/utils/paths.ts +11 -3
- package/src/utils/redaction.ts +7 -0
- package/src/utils/safe-abort.ts +45 -0
- package/src/utils/task-name-generator.ts +1 -8
- package/src/workflows/discover-workflows.ts +20 -2
- package/src/workflows/validate-workflow.ts +7 -1
- package/src/workflows/workflow-config.ts +17 -0
- package/src/workflows/workflow-serializer.ts +3 -0
- package/src/worktree/worktree-manager.ts +22 -0
- package/workflows/default.workflow.md +36 -26
- package/workflows/strict-fast-fix.workflow.md +26 -0
- package/src/agents/agent-search.ts +0 -98
- package/src/benchmark/benchmark-runner.ts +0 -313
- package/src/benchmark/feedback-loop.ts +0 -73
- package/src/config/resilient-parser.ts +0 -117
- package/src/extension/crew-vibes/cat-frames.ts +0 -18
- package/src/extension/result-watcher.ts +0 -139
- package/src/observability/exporters/prometheus-exporter.ts +0 -54
- package/src/observability/metric-retention.ts +0 -64
- package/src/runtime/compaction/compaction-summary.ts +0 -278
- package/src/runtime/errors/crew-errors.ts +0 -162
- package/src/runtime/live-session/intercom-bridge.ts +0 -187
- package/src/runtime/loop-gates.ts +0 -128
- package/src/runtime/metric-parser.ts +0 -36
- package/src/runtime/output/stream-preview.ts +0 -184
- package/src/runtime/output/tool-progress.ts +0 -278
- package/src/runtime/phase-tracker.ts +0 -385
- package/src/runtime/pipeline-runner.ts +0 -523
- package/src/runtime/process/process-lifecycle.ts +0 -491
- package/src/runtime/recovery/retry-runner.ts +0 -330
- package/src/runtime/run-drift.ts +0 -219
- package/src/runtime/task-quality.ts +0 -199
- package/src/runtime/task-runner/run-projection.ts +0 -128
- package/src/runtime/verification/post-checks.ts +0 -142
- package/src/state/coordination/schedule.ts +0 -166
- package/src/state/event-log/jsonl-writer.ts +0 -115
- package/src/state/hook-instinct-bridge.ts +0 -94
- package/src/state/hook-integrations.ts +0 -51
- package/src/state/session-state-map.ts +0 -51
- package/src/state/stores/blob-store.ts +0 -308
- package/src/state/stores/instinct-store.ts +0 -275
- package/src/state/stores/observation-store.ts +0 -176
- package/src/state/tiered-eval.ts +0 -480
- package/src/state/types-eval.ts +0 -58
- package/src/tools/safe-bash-extension.ts +0 -54
- package/src/tools/safe-bash.ts +0 -505
- package/src/ui/agent-management-overlay.ts +0 -160
- package/src/ui/crew-footer.ts +0 -102
- package/src/ui/crew-select-list.ts +0 -114
- package/src/ui/dashboard-panes/capability-pane.ts +0 -77
- package/src/ui/transcript-entries.ts +0 -256
- package/src/utils/conflict-detect.ts +0 -721
- package/src/utils/fingerprint.ts +0 -180
- package/src/utils/gh-protocol.ts +0 -556
- package/src/utils/project-detector.ts +0 -160
- package/src/utils/sse-parser.ts +0 -131
- package/src/workflows/cost-estimator.ts +0 -34
- package/src/workflows/intermediate-store.ts +0 -166
|
@@ -0,0 +1,639 @@
|
|
|
1
|
+
import * as path from "node:path";
|
|
2
|
+
import type { ExtensionCommandContext, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
import { loadConfig } from "../../../config/config.ts";
|
|
4
|
+
import { DEFAULT_UI } from "../../../config/defaults.ts";
|
|
5
|
+
import type { MetricRegistry } from "../../../observability/metric-registry.ts";
|
|
6
|
+
import { listRecentDiagnostic } from "../../../runtime/diagnostic-export.ts";
|
|
7
|
+
import { isPlanApprovalPendingEffective } from "../../../runtime/plan-approval.ts";
|
|
8
|
+
import type { TeamAction } from "../../../schema/team-tool-schema.ts";
|
|
9
|
+
import { loadRunManifestById } from "../../../state/stores/state-store.ts";
|
|
10
|
+
import type { TeamRunManifest } from "../../../state/types.ts";
|
|
11
|
+
import { getKeybindingOverrideWarnings } from "../../../ui/keybinding-map.ts";
|
|
12
|
+
import type { AnimatedMascot as AnimatedMascotType } from "../../../ui/mascot.ts";
|
|
13
|
+
import type { AgentPickerOverlay as AgentPickerOverlayType } from "../../../ui/overlays/agent-picker-overlay.ts";
|
|
14
|
+
import type { ConfirmOptions, ConfirmOverlay as ConfirmOverlayType } from "../../../ui/overlays/confirm-overlay.ts";
|
|
15
|
+
import type {
|
|
16
|
+
MailboxComposeOverlay as MailboxComposeOverlayType,
|
|
17
|
+
MailboxComposeResult,
|
|
18
|
+
} from "../../../ui/overlays/mailbox-compose-overlay.ts";
|
|
19
|
+
import type { MailboxAction, MailboxDetailOverlay as MailboxDetailOverlayType } from "../../../ui/overlays/mailbox-detail-overlay.ts";
|
|
20
|
+
import { requestRenderTarget } from "../../../ui/pi-ui-compat.ts";
|
|
21
|
+
import {
|
|
22
|
+
dispatchDiagnosticExport,
|
|
23
|
+
dispatchHealthRecovery,
|
|
24
|
+
dispatchKillStaleWorkers,
|
|
25
|
+
dispatchMailboxAck,
|
|
26
|
+
dispatchMailboxAckAll,
|
|
27
|
+
dispatchMailboxCompose,
|
|
28
|
+
dispatchMailboxNudge,
|
|
29
|
+
} from "../../../ui/run-action-dispatcher.ts";
|
|
30
|
+
import type { RunDashboardSelection, RunDashboard as RunDashboardType } from "../../../ui/run-dashboard.ts";
|
|
31
|
+
import type { createRunSnapshotCache } from "../../../ui/run-snapshot-cache.ts";
|
|
32
|
+
import type { DurableTextViewer as DurableTextViewerType } from "../../../ui/transcript-viewer.ts";
|
|
33
|
+
import { withSessionId } from "../../team-tool/context.ts";
|
|
34
|
+
// Lazy-loaded: team-tool.ts pulls in entire runtime chain (1.4s+).
|
|
35
|
+
import type { handleTeamTool as HandleTeamToolFn } from "../../team-tool.ts";
|
|
36
|
+
import { commandText, notifyCommandResult } from "../command-utils.ts";
|
|
37
|
+
import type { UiState } from "../ui.ts";
|
|
38
|
+
import { openLiveConversation, openTranscriptViewer } from "../viewers.ts";
|
|
39
|
+
|
|
40
|
+
let _cachedHandleTeamTool: typeof HandleTeamToolFn | undefined;
|
|
41
|
+
let _handleTeamToolPromise: Promise<typeof HandleTeamToolFn> | undefined;
|
|
42
|
+
export async function handleTeamTool(
|
|
43
|
+
params: Parameters<typeof HandleTeamToolFn>[0],
|
|
44
|
+
ctx: Parameters<typeof HandleTeamToolFn>[1],
|
|
45
|
+
): Promise<Awaited<ReturnType<typeof HandleTeamToolFn>>> {
|
|
46
|
+
if (!_cachedHandleTeamTool) {
|
|
47
|
+
if (!_handleTeamToolPromise) {
|
|
48
|
+
_handleTeamToolPromise = import("../../team-tool.ts").then((mod) => {
|
|
49
|
+
_cachedHandleTeamTool = mod.handleTeamTool;
|
|
50
|
+
return mod.handleTeamTool;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
const fn = await _handleTeamToolPromise;
|
|
54
|
+
return fn(params, ctx);
|
|
55
|
+
}
|
|
56
|
+
return _cachedHandleTeamTool(params, ctx);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* TEST SEAM (STEP 1.9a) — substitute the lazy-loaded team-tool facade.
|
|
61
|
+
* Production `handleTeamTool` populates `_cachedHandleTeamTool` on first use
|
|
62
|
+
* via `import("../../team-tool.ts")` (1.4s+ runtime chain). This lets unit tests
|
|
63
|
+
* inject a recording stub and exercise command handlers without importing the
|
|
64
|
+
* chain. No production behavior change: the lazy-import path is untouched when
|
|
65
|
+
* this is never called, and handlers always resolve through the same cache.
|
|
66
|
+
*/
|
|
67
|
+
export function __test__setHandleTeamTool(fn: typeof HandleTeamToolFn | undefined): void {
|
|
68
|
+
_cachedHandleTeamTool = fn;
|
|
69
|
+
_handleTeamToolPromise = undefined;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface RegisterTeamCommandsDeps {
|
|
73
|
+
startForegroundRun: (ctx: ExtensionContext, runner: (signal?: AbortSignal) => Promise<void>, runId?: string) => void;
|
|
74
|
+
abortForegroundRun: (runId: string) => boolean;
|
|
75
|
+
openLiveSidebar: (ctx: ExtensionContext, runId: string) => void;
|
|
76
|
+
getManifestCache: (cwd: string) => {
|
|
77
|
+
list(max?: number): TeamRunManifest[];
|
|
78
|
+
};
|
|
79
|
+
getRunSnapshotCache?: (cwd: string) => ReturnType<typeof createRunSnapshotCache>;
|
|
80
|
+
getMetricRegistry?: () => MetricRegistry | undefined;
|
|
81
|
+
uiState?: UiState;
|
|
82
|
+
dismissNotifications?: () => void;
|
|
83
|
+
/**
|
|
84
|
+
* The session file of the CURRENT session (RegistrationContext.currentCtx).
|
|
85
|
+
* Commands whose handler can span a session switch — team-run awaits the
|
|
86
|
+
* whole foreground run — use this after the await to detect that the
|
|
87
|
+
* captured ctx is stale and skip notifications that pi would drop with a
|
|
88
|
+
* "ctx is stale" error.
|
|
89
|
+
*/
|
|
90
|
+
getCurrentSessionFile?: () => string | undefined;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Lazy-loaded UI module cache — avoids importing 900ms+ of UI at Pi startup.
|
|
94
|
+
// These modules are only needed when user invokes /crew commands.
|
|
95
|
+
let _uiCache:
|
|
96
|
+
| {
|
|
97
|
+
RunDashboard: typeof RunDashboardType;
|
|
98
|
+
DurableTextViewer: typeof DurableTextViewerType;
|
|
99
|
+
ConfirmOverlay: typeof ConfirmOverlayType;
|
|
100
|
+
MailboxDetailOverlay: typeof MailboxDetailOverlayType;
|
|
101
|
+
MailboxComposeOverlay: typeof MailboxComposeOverlayType;
|
|
102
|
+
AgentPickerOverlay: typeof AgentPickerOverlayType;
|
|
103
|
+
AnimatedMascot: typeof AnimatedMascotType;
|
|
104
|
+
}
|
|
105
|
+
| undefined;
|
|
106
|
+
let _uiCachePromise: Promise<NonNullable<typeof _uiCache>> | undefined;
|
|
107
|
+
export async function ui(): Promise<NonNullable<typeof _uiCache>> {
|
|
108
|
+
if (!_uiCache) {
|
|
109
|
+
if (!_uiCachePromise) {
|
|
110
|
+
_uiCachePromise = (async () => {
|
|
111
|
+
const [rd, tv, co, md, mc, ap, ma] = await Promise.all([
|
|
112
|
+
import("../../../ui/run-dashboard.ts"),
|
|
113
|
+
import("../../../ui/transcript-viewer.ts"),
|
|
114
|
+
import("../../../ui/overlays/confirm-overlay.ts"),
|
|
115
|
+
import("../../../ui/overlays/mailbox-detail-overlay.ts"),
|
|
116
|
+
import("../../../ui/overlays/mailbox-compose-overlay.ts"),
|
|
117
|
+
import("../../../ui/overlays/agent-picker-overlay.ts"),
|
|
118
|
+
import("../../../ui/mascot.ts"),
|
|
119
|
+
]);
|
|
120
|
+
const cache = {
|
|
121
|
+
RunDashboard: rd.RunDashboard,
|
|
122
|
+
DurableTextViewer: tv.DurableTextViewer,
|
|
123
|
+
ConfirmOverlay: co.ConfirmOverlay,
|
|
124
|
+
MailboxDetailOverlay: md.MailboxDetailOverlay,
|
|
125
|
+
MailboxComposeOverlay: mc.MailboxComposeOverlay,
|
|
126
|
+
AgentPickerOverlay: ap.AgentPickerOverlay,
|
|
127
|
+
AnimatedMascot: ma.AnimatedMascot,
|
|
128
|
+
};
|
|
129
|
+
_uiCache = cache;
|
|
130
|
+
return cache;
|
|
131
|
+
})();
|
|
132
|
+
}
|
|
133
|
+
return _uiCachePromise;
|
|
134
|
+
}
|
|
135
|
+
return _uiCache;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
async function openConfirm(ctx: ExtensionCommandContext, options: ConfirmOptions): Promise<boolean> {
|
|
139
|
+
if (!ctx.hasUI) return false;
|
|
140
|
+
const { ConfirmOverlay } = await ui();
|
|
141
|
+
return await ctx.ui.custom<boolean>((_tui, theme, _keybindings, done) => new ConfirmOverlay(options, done, theme), {
|
|
142
|
+
overlay: true,
|
|
143
|
+
overlayOptions: { width: 64, maxHeight: "70%", anchor: "center" },
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async function handleMailboxDashboardAction(ctx: ExtensionCommandContext, runId: string): Promise<void> {
|
|
148
|
+
if (!ctx.hasUI) return;
|
|
149
|
+
const { MailboxDetailOverlay } = await ui();
|
|
150
|
+
const action = await ctx.ui.custom<MailboxAction | undefined>(
|
|
151
|
+
(_tui, theme, _keybindings, done) => new MailboxDetailOverlay({ runId, cwd: ctx.cwd, done, theme }),
|
|
152
|
+
{
|
|
153
|
+
overlay: true,
|
|
154
|
+
overlayOptions: {
|
|
155
|
+
width: "90%",
|
|
156
|
+
maxHeight: "85%",
|
|
157
|
+
anchor: "center",
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
);
|
|
161
|
+
if (!action || action.type === "close") return;
|
|
162
|
+
let resultMessage: string | undefined;
|
|
163
|
+
let ok = true;
|
|
164
|
+
if (action.type === "ack") {
|
|
165
|
+
const result = await dispatchMailboxAck(ctx as ExtensionContext, runId, action.messageId);
|
|
166
|
+
ok = result.ok;
|
|
167
|
+
resultMessage = result.message;
|
|
168
|
+
} else if (action.type === "ackAll") {
|
|
169
|
+
const confirmed = await openConfirm(ctx, {
|
|
170
|
+
title: "Acknowledge all unread messages?",
|
|
171
|
+
body: "This cannot be undone. Y=ack all, N=cancel.",
|
|
172
|
+
dangerLevel: "medium",
|
|
173
|
+
defaultAction: "cancel",
|
|
174
|
+
});
|
|
175
|
+
if (!confirmed) return;
|
|
176
|
+
const result = await dispatchMailboxAckAll(ctx as ExtensionContext, runId);
|
|
177
|
+
ok = result.ok;
|
|
178
|
+
resultMessage = result.message;
|
|
179
|
+
} else if (action.type === "compose") {
|
|
180
|
+
const { MailboxComposeOverlay } = await ui();
|
|
181
|
+
const compose = await ctx.ui.custom<MailboxComposeResult>(
|
|
182
|
+
(_tui, theme, _keybindings, done) => new MailboxComposeOverlay({ done, theme }),
|
|
183
|
+
{
|
|
184
|
+
overlay: true,
|
|
185
|
+
overlayOptions: {
|
|
186
|
+
width: "90%",
|
|
187
|
+
maxHeight: "85%",
|
|
188
|
+
anchor: "center",
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
);
|
|
192
|
+
if (compose.type === "cancel") return;
|
|
193
|
+
const result = await dispatchMailboxCompose(ctx as ExtensionContext, runId, compose.payload);
|
|
194
|
+
ok = result.ok;
|
|
195
|
+
resultMessage = result.message;
|
|
196
|
+
} else if (action.type === "nudge") {
|
|
197
|
+
let agentId = action.agentId;
|
|
198
|
+
if (!agentId) {
|
|
199
|
+
const { AgentPickerOverlay } = await ui();
|
|
200
|
+
const picked = await ctx.ui.custom<{ agentId: string } | undefined>(
|
|
201
|
+
(_tui, theme, _keybindings, done) =>
|
|
202
|
+
new AgentPickerOverlay({
|
|
203
|
+
cwd: ctx.cwd,
|
|
204
|
+
runId,
|
|
205
|
+
done,
|
|
206
|
+
theme,
|
|
207
|
+
}),
|
|
208
|
+
{
|
|
209
|
+
overlay: true,
|
|
210
|
+
overlayOptions: {
|
|
211
|
+
width: 72,
|
|
212
|
+
maxHeight: "75%",
|
|
213
|
+
anchor: "center",
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
);
|
|
217
|
+
agentId = picked?.agentId;
|
|
218
|
+
}
|
|
219
|
+
if (!agentId) return;
|
|
220
|
+
const result = await dispatchMailboxNudge(
|
|
221
|
+
ctx as ExtensionContext,
|
|
222
|
+
runId,
|
|
223
|
+
agentId,
|
|
224
|
+
"Please report your current status, blocker, or smallest next step.",
|
|
225
|
+
);
|
|
226
|
+
ok = result.ok;
|
|
227
|
+
resultMessage = result.message;
|
|
228
|
+
}
|
|
229
|
+
depsNotify(ctx, resultMessage ?? "Mailbox action complete.", ok ? "info" : "error");
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function depsNotify(ctx: ExtensionCommandContext, message: string, level: "info" | "warning" | "error"): void {
|
|
233
|
+
if (!ctx.hasUI) return;
|
|
234
|
+
ctx.ui.notify(message, level);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export function teamCommandContext(ctx: ExtensionCommandContext): ExtensionCommandContext & { sessionId?: string } {
|
|
238
|
+
return withSessionId(ctx);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Open the pi-crew settings overlay (config editor + theme picker).
|
|
243
|
+
*
|
|
244
|
+
* Extracted from the `team-settings` command so it is reusable from a
|
|
245
|
+
* keyboard shortcut. Takes the base `ExtensionContext` (the shortcut
|
|
246
|
+
* handler's context) — uses only `hasUI`, `cwd`, and `ui` fields, so both
|
|
247
|
+
* `ExtensionContext` and `ExtensionCommandContext` satisfy it.
|
|
248
|
+
*/
|
|
249
|
+
export async function openTeamSettingsOverlay(ctx: ExtensionContext): Promise<void> {
|
|
250
|
+
if (!ctx.hasUI) return;
|
|
251
|
+
const [{ updateConfig, parseConfig }, { asCrewTheme }, { createSettingsOverlay }] = await Promise.all([
|
|
252
|
+
import("../../../config/config.ts"),
|
|
253
|
+
import("../../../ui/theme-adapter.ts"),
|
|
254
|
+
import("../../../ui/settings-overlay.ts"),
|
|
255
|
+
]);
|
|
256
|
+
const loaded = loadConfig(ctx.cwd);
|
|
257
|
+
const config = loaded.config as Record<string, unknown>;
|
|
258
|
+
await ctx.ui.custom<undefined>(
|
|
259
|
+
(_tui, _theme, _keybindings, done) => {
|
|
260
|
+
const theme = asCrewTheme(_theme);
|
|
261
|
+
const { overlay } = createSettingsOverlay(
|
|
262
|
+
config,
|
|
263
|
+
theme,
|
|
264
|
+
(id: string, value: unknown) => {
|
|
265
|
+
try {
|
|
266
|
+
const patch: Record<string, unknown> = {};
|
|
267
|
+
const keys = id.split(".");
|
|
268
|
+
let target: Record<string, unknown> = patch;
|
|
269
|
+
for (let i = 0; i < keys.length - 1; i++) {
|
|
270
|
+
if (!target[keys[i]!] || typeof target[keys[i]!] !== "object") target[keys[i]!] = {};
|
|
271
|
+
target = target[keys[i]!] as Record<string, unknown>;
|
|
272
|
+
}
|
|
273
|
+
target[keys[keys.length - 1]!] = value;
|
|
274
|
+
if (value === undefined) {
|
|
275
|
+
updateConfig({}, { unsetPaths: [id] });
|
|
276
|
+
} else {
|
|
277
|
+
updateConfig(parseConfig(patch));
|
|
278
|
+
}
|
|
279
|
+
} catch (error) {
|
|
280
|
+
ctx.ui.notify(`Failed to save: ${error instanceof Error ? error.message : String(error)}`, "error");
|
|
281
|
+
}
|
|
282
|
+
},
|
|
283
|
+
() => done(undefined),
|
|
284
|
+
async (action: string, value: unknown) => {
|
|
285
|
+
// Action callbacks (Pi theme switch) write to a different store
|
|
286
|
+
// than pi-crew config (e.g. ~/.pi/agent/settings.json).
|
|
287
|
+
try {
|
|
288
|
+
if (action === "piTheme" && typeof value === "string") {
|
|
289
|
+
// Live theme switch: ctx.ui.setTheme() swaps the global theme,
|
|
290
|
+
// persists it to settings.json, and triggers a UI redraw — no
|
|
291
|
+
// restart needed. Falls back to file-write + restart hint if
|
|
292
|
+
// the live API is unavailable (e.g. non-TUI mode).
|
|
293
|
+
if (typeof ctx.ui.setTheme === "function") {
|
|
294
|
+
const res = ctx.ui.setTheme(value);
|
|
295
|
+
if (res.success) {
|
|
296
|
+
ctx.ui.notify(`Theme: ${value} (applied live)`, "info");
|
|
297
|
+
} else {
|
|
298
|
+
// LAZY: defer dynamic import of ../../ui/theme-discovery.ts to its call site.
|
|
299
|
+
const { setPiTheme } = await import("../../../ui/theme-discovery.ts");
|
|
300
|
+
setPiTheme(value);
|
|
301
|
+
ctx.ui.notify(
|
|
302
|
+
`Theme saved as '${value}' but failed to apply: ${res.error ?? "unknown"}. Restart Pi.`,
|
|
303
|
+
"warning",
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
} else {
|
|
307
|
+
// LAZY: defer dynamic import of ../../ui/theme-discovery.ts to its call site.
|
|
308
|
+
const { setPiTheme } = await import("../../../ui/theme-discovery.ts");
|
|
309
|
+
setPiTheme(value);
|
|
310
|
+
ctx.ui.notify(`Pi theme set to '${value}'. Restart Pi to apply.`, "info");
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
} catch (error) {
|
|
314
|
+
ctx.ui.notify(`Failed: ${error instanceof Error ? error.message : String(error)}`, "error");
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
);
|
|
318
|
+
return overlay;
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
overlay: true,
|
|
322
|
+
overlayOptions: {
|
|
323
|
+
width: "90%",
|
|
324
|
+
maxHeight: "85%",
|
|
325
|
+
anchor: "center",
|
|
326
|
+
},
|
|
327
|
+
},
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
async function handleHealthDashboardAction(ctx: ExtensionCommandContext, selection: RunDashboardSelection): Promise<void> {
|
|
332
|
+
const loaded = loadRunManifestById(ctx.cwd, selection.runId); // NOTE: no withRunLock - best-effort only; concurrent writes may cause inconsistency
|
|
333
|
+
if (!loaded) {
|
|
334
|
+
depsNotify(ctx, `Run '${selection.runId}' not found.`, "error");
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
if (selection.action === "health-recovery") {
|
|
338
|
+
if (loaded.manifest.async) {
|
|
339
|
+
depsNotify(ctx, "Recovery is only available for foreground runs.", "warning");
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
const confirmed = await openConfirm(ctx, {
|
|
343
|
+
title: "Interrupt foreground run?",
|
|
344
|
+
body: "Tasks may be marked failed. Y=interrupt, N=cancel.",
|
|
345
|
+
dangerLevel: "high",
|
|
346
|
+
defaultAction: "cancel",
|
|
347
|
+
});
|
|
348
|
+
if (!confirmed) return;
|
|
349
|
+
const result = await dispatchHealthRecovery(ctx as ExtensionContext, selection.runId);
|
|
350
|
+
depsNotify(ctx, result.message, result.ok ? "info" : "error");
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
if (selection.action === "health-kill-stale") {
|
|
354
|
+
const confirmed = await openConfirm(ctx, {
|
|
355
|
+
title: "Mark stale workers dead?",
|
|
356
|
+
body: "This updates worker heartbeat state. Y=mark dead, N=cancel.",
|
|
357
|
+
dangerLevel: "medium",
|
|
358
|
+
defaultAction: "cancel",
|
|
359
|
+
});
|
|
360
|
+
if (!confirmed) return;
|
|
361
|
+
const result = await dispatchKillStaleWorkers(ctx as ExtensionContext, selection.runId);
|
|
362
|
+
depsNotify(ctx, result.message, result.ok ? "info" : "error");
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
if (selection.action === "health-diagnostic-export") {
|
|
366
|
+
const diagDir = path.join(loaded.manifest.artifactsRoot, "diagnostic");
|
|
367
|
+
const recent = listRecentDiagnostic(diagDir, 60_000);
|
|
368
|
+
if (recent) {
|
|
369
|
+
const confirmed = await openConfirm(ctx, {
|
|
370
|
+
title: "Recent diagnostic exists",
|
|
371
|
+
body: `File ${recent} was created <1min ago. Export another diagnostic?`,
|
|
372
|
+
defaultAction: "cancel",
|
|
373
|
+
});
|
|
374
|
+
if (!confirmed) return;
|
|
375
|
+
}
|
|
376
|
+
const result = await dispatchDiagnosticExport(ctx as ExtensionContext, selection.runId, {
|
|
377
|
+
registry: depsRef?.getMetricRegistry?.(),
|
|
378
|
+
});
|
|
379
|
+
depsNotify(ctx, result.message, result.ok ? "info" : "error");
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* WP-3 (H4-subset): dashboard plan-approval actions (A approve / n deny in
|
|
385
|
+
* the progress pane). Modeled on handleHealthDashboardAction above: reload the
|
|
386
|
+
* manifest, pre-check pending (the backend api op re-validates under
|
|
387
|
+
* withRunLock — this pre-check is UX-only), dispatch the EXISTING team api op,
|
|
388
|
+
* then notify. The caller invalidates the snapshot cache afterwards.
|
|
389
|
+
*/
|
|
390
|
+
async function handlePlanDashboardAction(ctx: ExtensionCommandContext, selection: RunDashboardSelection): Promise<void> {
|
|
391
|
+
// F3 decision (WP-3 review round 1, documented): NO manifest.async gate —
|
|
392
|
+
// unlike health-recovery (which interrupts the foreground loop and is
|
|
393
|
+
// foreground-only by necessity). Async/background runs park on plan approval
|
|
394
|
+
// exactly like foreground runs (background-runner executeTeamRun → plan
|
|
395
|
+
// gate), so their approvals MUST be decidable from the dashboard. Deny on
|
|
396
|
+
// an async run terminates tasks via the SAME backend path as chat `team api
|
|
397
|
+
// cancel-plan` (parity), guarded by the medium-danger confirm below + the
|
|
398
|
+
// backend's withRunLock re-validation.
|
|
399
|
+
const loaded = loadRunManifestById(ctx.cwd, selection.runId); // NOTE: no withRunLock - best-effort only; concurrent writes may cause inconsistency
|
|
400
|
+
if (!loaded) {
|
|
401
|
+
depsNotify(ctx, `Run '${selection.runId}' not found.`, "error");
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
if (!isPlanApprovalPendingEffective(loaded.manifest)) {
|
|
405
|
+
depsNotify(ctx, "no pending plan approval", "warning");
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
if (selection.action === "plan-deny") {
|
|
409
|
+
// cancel-plan KILLS tasks, so deny gets a medium-danger confirm.
|
|
410
|
+
// Keystroke math (plan AC ≤ 2 per action): approve = "A" → 1 keystroke
|
|
411
|
+
// (dispatched directly below, no confirm); deny = "n" + confirm = 2.
|
|
412
|
+
// ConfirmOverlay.handleInput treats n/N as CANCEL in its own overlay,
|
|
413
|
+
// so the copy must instruct Y-to-confirm — pressing "n" twice would
|
|
414
|
+
// abort instead of confirming.
|
|
415
|
+
const confirmed = await openConfirm(ctx, {
|
|
416
|
+
title: "Cancel plan and kill tasks?",
|
|
417
|
+
body: "Y=cancel plan and kill tasks, N=abort.",
|
|
418
|
+
dangerLevel: "medium",
|
|
419
|
+
defaultAction: "cancel",
|
|
420
|
+
});
|
|
421
|
+
if (!confirmed) return;
|
|
422
|
+
}
|
|
423
|
+
const operation = selection.action === "plan-approve" ? "approve-plan" : "cancel-plan";
|
|
424
|
+
const result = await handleTeamTool(
|
|
425
|
+
{
|
|
426
|
+
action: "api",
|
|
427
|
+
runId: selection.runId,
|
|
428
|
+
config: { operation },
|
|
429
|
+
},
|
|
430
|
+
teamCommandContext(ctx),
|
|
431
|
+
);
|
|
432
|
+
// F4 (WP-3 review round 1): notifyCommandResult hardcodes level "info",
|
|
433
|
+
// which downgraded backend rejections (e.g. the deny TOCTOU tail — approval
|
|
434
|
+
// answered between keypress and dispatch, refused under withRunLock) to
|
|
435
|
+
// info toasts. Surface isError results at their true level.
|
|
436
|
+
const text = commandText(result);
|
|
437
|
+
depsNotify(ctx, text.length > 800 ? `${text.slice(0, 797)}...` : text, result.isError ? "error" : "info");
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
let depsRef: RegisterTeamCommandsDeps | undefined;
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Internal setter for `depsRef` (Phase 2.1 split). ESM import bindings are
|
|
444
|
+
* read-only, so `registerTeamCommands` in index.ts cannot assign to the
|
|
445
|
+
* shared binding directly; this setter preserves the original single-module
|
|
446
|
+
* behavior (module-level state set once at registration).
|
|
447
|
+
*/
|
|
448
|
+
export function setTeamCommandsDeps(deps: RegisterTeamCommandsDeps): void {
|
|
449
|
+
depsRef = deps;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* Open the pi-crew run dashboard overlay and run its action loop.
|
|
454
|
+
*
|
|
455
|
+
* Extracted verbatim from the `team-dashboard` command so it is reusable from
|
|
456
|
+
* a keyboard shortcut (alt+c, see crew-shortcuts.ts). Takes the base
|
|
457
|
+
* `ExtensionContext` (the shortcut handler's context) — uses only `hasUI`,
|
|
458
|
+
* `cwd`, `ui`, and `sessionManager` fields, so both `ExtensionContext` and
|
|
459
|
+
* `ExtensionCommandContext` satisfy it. Reads run caches via the module-level
|
|
460
|
+
* `depsRef` (set by `registerTeamCommands`), so it is a no-op if commands
|
|
461
|
+
* have not been registered yet. `deps` is captured into a local const so the
|
|
462
|
+
* non-undefined narrowing survives the awaited overlay call.
|
|
463
|
+
*
|
|
464
|
+
* The dashboard action helpers (handleMailboxDashboardAction, the viewers,
|
|
465
|
+
* notifyCommandResult, teamCommandContext/handleTeamTool) are declared for
|
|
466
|
+
* `ExtensionCommandContext` but only ever read base `ExtensionContext` fields
|
|
467
|
+
* (verified). The keyboard-shortcut path supplies an `ExtensionContext`, so we
|
|
468
|
+
* bridge those over-typed helpers with a single cast rather than relaxing
|
|
469
|
+
* signatures across several modules (some outside this file's scope).
|
|
470
|
+
*/
|
|
471
|
+
export async function openTeamDashboard(ctx: ExtensionContext): Promise<void> {
|
|
472
|
+
if (!ctx.hasUI) return;
|
|
473
|
+
const deps = depsRef;
|
|
474
|
+
if (!deps) return;
|
|
475
|
+
if (deps.uiState) deps.uiState.dashboardOpen = true;
|
|
476
|
+
const cmdCtx = ctx as ExtensionCommandContext;
|
|
477
|
+
// F1 (WP-3 review round 1): keybinding-override collisions are reverted to
|
|
478
|
+
// defaults by computeEffectiveBindings to keep dispatch unambiguous — but
|
|
479
|
+
// the warning API (getKeybindingOverrideWarnings) previously had NO src
|
|
480
|
+
// consumer, so users whose overrides claimed the new progress-pane keys
|
|
481
|
+
// ("A"/"n") got a silent, persistent keybinding break. Surface the revert
|
|
482
|
+
// once per dashboard open instead.
|
|
483
|
+
const keyWarnings = getKeybindingOverrideWarnings();
|
|
484
|
+
if (keyWarnings.length > 0) {
|
|
485
|
+
depsNotify(cmdCtx, `keybindings reverted to defaults: ${keyWarnings.join("; ")}`, "warning");
|
|
486
|
+
}
|
|
487
|
+
for (;;) {
|
|
488
|
+
// Extract sessionId for workspace-scoped filtering
|
|
489
|
+
const sessionId = cmdCtx.sessionManager?.getSessionId?.();
|
|
490
|
+
const runs = deps.getManifestCache(cmdCtx.cwd).list(50);
|
|
491
|
+
const uiConfig = loadConfig(cmdCtx.cwd).config.ui;
|
|
492
|
+
const rightPanel = (uiConfig?.dashboardPlacement ?? DEFAULT_UI.dashboardPlacement) === "right";
|
|
493
|
+
const width = rightPanel ? Math.min(90, Math.max(40, uiConfig?.dashboardWidth ?? DEFAULT_UI.dashboardWidth)) : "90%";
|
|
494
|
+
const { RunDashboard } = await ui();
|
|
495
|
+
const selection = await cmdCtx.ui.custom<RunDashboardSelection | undefined>(
|
|
496
|
+
(tui, theme, _keybindings, done) =>
|
|
497
|
+
new RunDashboard(runs, done, theme, {
|
|
498
|
+
placement: rightPanel ? "right" : "center",
|
|
499
|
+
showModel: uiConfig?.showModel,
|
|
500
|
+
showTokens: uiConfig?.showTokens,
|
|
501
|
+
showTools: uiConfig?.showTools,
|
|
502
|
+
snapshotCache: deps.getRunSnapshotCache?.(cmdCtx.cwd),
|
|
503
|
+
runProvider: () => deps.getManifestCache(cmdCtx.cwd).list(50),
|
|
504
|
+
registry: deps.getMetricRegistry?.(),
|
|
505
|
+
workspaceId: sessionId,
|
|
506
|
+
requestRender: () => requestRenderTarget(tui),
|
|
507
|
+
}),
|
|
508
|
+
{
|
|
509
|
+
overlay: true,
|
|
510
|
+
overlayOptions: rightPanel
|
|
511
|
+
? {
|
|
512
|
+
width,
|
|
513
|
+
minWidth: 40,
|
|
514
|
+
maxHeight: "100%",
|
|
515
|
+
anchor: "top-right",
|
|
516
|
+
offsetX: 0,
|
|
517
|
+
offsetY: 0,
|
|
518
|
+
margin: { top: 0, right: 0, bottom: 0, left: 0 },
|
|
519
|
+
}
|
|
520
|
+
: { width, maxHeight: "90%", anchor: "center", margin: 2 },
|
|
521
|
+
},
|
|
522
|
+
);
|
|
523
|
+
if (!selection) break;
|
|
524
|
+
if (selection.action === "reload") continue;
|
|
525
|
+
if (selection.action === "notifications-dismiss") {
|
|
526
|
+
deps.dismissNotifications?.();
|
|
527
|
+
cmdCtx.ui.notify("pi-crew notifications dismissed.", "info");
|
|
528
|
+
continue;
|
|
529
|
+
}
|
|
530
|
+
if (selection.action === "mailbox-detail") {
|
|
531
|
+
await handleMailboxDashboardAction(cmdCtx, selection.runId);
|
|
532
|
+
deps.getRunSnapshotCache?.(cmdCtx.cwd).invalidate(selection.runId);
|
|
533
|
+
continue;
|
|
534
|
+
}
|
|
535
|
+
if (
|
|
536
|
+
selection.action === "health-recovery" ||
|
|
537
|
+
selection.action === "health-kill-stale" ||
|
|
538
|
+
selection.action === "health-diagnostic-export"
|
|
539
|
+
) {
|
|
540
|
+
await handleHealthDashboardAction(cmdCtx, selection);
|
|
541
|
+
deps.getRunSnapshotCache?.(cmdCtx.cwd).invalidate(selection.runId);
|
|
542
|
+
continue;
|
|
543
|
+
}
|
|
544
|
+
if (selection.action === "plan-approve" || selection.action === "plan-deny") {
|
|
545
|
+
await handlePlanDashboardAction(cmdCtx, selection);
|
|
546
|
+
deps.getRunSnapshotCache?.(cmdCtx.cwd).invalidate(selection.runId);
|
|
547
|
+
continue;
|
|
548
|
+
}
|
|
549
|
+
if (selection.action === "agent-transcript" && (await openTranscriptViewer(cmdCtx, selection.runId))) continue;
|
|
550
|
+
if (selection.action === "agent-live" && (await openLiveConversation(cmdCtx, selection.runId))) continue;
|
|
551
|
+
if (selection.action === "agent-live") {
|
|
552
|
+
await notifyCommandResult(
|
|
553
|
+
cmdCtx,
|
|
554
|
+
commandText({
|
|
555
|
+
content: [
|
|
556
|
+
{
|
|
557
|
+
type: "text",
|
|
558
|
+
text: "No live agent found for this run.",
|
|
559
|
+
},
|
|
560
|
+
],
|
|
561
|
+
}),
|
|
562
|
+
);
|
|
563
|
+
continue;
|
|
564
|
+
}
|
|
565
|
+
const result =
|
|
566
|
+
selection.action === "api"
|
|
567
|
+
? await handleTeamTool(
|
|
568
|
+
{
|
|
569
|
+
action: "api",
|
|
570
|
+
runId: selection.runId,
|
|
571
|
+
config: { operation: "read-manifest" },
|
|
572
|
+
},
|
|
573
|
+
teamCommandContext(cmdCtx),
|
|
574
|
+
)
|
|
575
|
+
: selection.action === "agents"
|
|
576
|
+
? await handleTeamTool(
|
|
577
|
+
{
|
|
578
|
+
action: "api",
|
|
579
|
+
runId: selection.runId,
|
|
580
|
+
config: { operation: "agent-dashboard" },
|
|
581
|
+
},
|
|
582
|
+
teamCommandContext(cmdCtx),
|
|
583
|
+
)
|
|
584
|
+
: selection.action === "mailbox"
|
|
585
|
+
? await handleTeamTool(
|
|
586
|
+
{
|
|
587
|
+
action: "api",
|
|
588
|
+
runId: selection.runId,
|
|
589
|
+
config: { operation: "read-mailbox" },
|
|
590
|
+
},
|
|
591
|
+
teamCommandContext(cmdCtx),
|
|
592
|
+
)
|
|
593
|
+
: selection.action === "agent-events"
|
|
594
|
+
? await handleTeamTool(
|
|
595
|
+
{
|
|
596
|
+
action: "api",
|
|
597
|
+
runId: selection.runId,
|
|
598
|
+
config: {
|
|
599
|
+
operation: "read-agent-events",
|
|
600
|
+
limit: 50,
|
|
601
|
+
},
|
|
602
|
+
},
|
|
603
|
+
teamCommandContext(cmdCtx),
|
|
604
|
+
)
|
|
605
|
+
: selection.action === "agent-output"
|
|
606
|
+
? await handleTeamTool(
|
|
607
|
+
{
|
|
608
|
+
action: "api",
|
|
609
|
+
runId: selection.runId,
|
|
610
|
+
config: {
|
|
611
|
+
operation: "read-agent-output",
|
|
612
|
+
maxBytes: 32_000,
|
|
613
|
+
},
|
|
614
|
+
},
|
|
615
|
+
teamCommandContext(cmdCtx),
|
|
616
|
+
)
|
|
617
|
+
: selection.action === "agent-transcript"
|
|
618
|
+
? await handleTeamTool(
|
|
619
|
+
{
|
|
620
|
+
action: "api",
|
|
621
|
+
runId: selection.runId,
|
|
622
|
+
config: {
|
|
623
|
+
operation: "read-agent-transcript",
|
|
624
|
+
},
|
|
625
|
+
},
|
|
626
|
+
teamCommandContext(cmdCtx),
|
|
627
|
+
)
|
|
628
|
+
: await handleTeamTool(
|
|
629
|
+
{
|
|
630
|
+
action: selection.action as TeamAction,
|
|
631
|
+
runId: selection.runId,
|
|
632
|
+
},
|
|
633
|
+
teamCommandContext(cmdCtx),
|
|
634
|
+
);
|
|
635
|
+
await notifyCommandResult(cmdCtx, commandText(result));
|
|
636
|
+
break;
|
|
637
|
+
}
|
|
638
|
+
if (deps.uiState) deps.uiState.dashboardOpen = false;
|
|
639
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { suggestRunIds } from "../../command-completions.ts";
|
|
3
|
+
import { piTeamsHelp } from "../../help.ts";
|
|
4
|
+
import { commandText, notifyCommandResult } from "../command-utils.ts";
|
|
5
|
+
import type { RegisterTeamCommandsDeps } from "./shared.ts";
|
|
6
|
+
import { handleTeamTool, teamCommandContext } from "./shared.ts";
|
|
7
|
+
|
|
8
|
+
export function registerStatusCommands(pi: ExtensionAPI, deps: RegisterTeamCommandsDeps): void {
|
|
9
|
+
pi.registerCommand("teams", {
|
|
10
|
+
description: "List pi-crew teams, workflows, and agents",
|
|
11
|
+
handler: async (_args: string, ctx: ExtensionCommandContext) => {
|
|
12
|
+
const result = await handleTeamTool({ action: "list" }, teamCommandContext(ctx));
|
|
13
|
+
await notifyCommandResult(ctx, commandText(result));
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
for (const [name, action, description] of [
|
|
18
|
+
["team-status", "status", "Show pi-crew run status"],
|
|
19
|
+
["team-summary", "summary", "Show pi-crew run summary"],
|
|
20
|
+
["team-events", "events", "Show full pi-crew event log for a run"],
|
|
21
|
+
["team-artifacts", "artifacts", "List pi-crew artifacts for a run"],
|
|
22
|
+
["team-worktrees", "worktrees", "List pi-crew worktrees for a run"],
|
|
23
|
+
] as const) {
|
|
24
|
+
pi.registerCommand(name, {
|
|
25
|
+
description,
|
|
26
|
+
// Round 13 UX: suggest recent run IDs for Tab-completion.
|
|
27
|
+
getArgumentCompletions: (argumentPrefix: string) => suggestRunIds(argumentPrefix),
|
|
28
|
+
handler: async (args: string, ctx: ExtensionCommandContext) => {
|
|
29
|
+
const runId = args.trim() || undefined;
|
|
30
|
+
const result = await handleTeamTool(
|
|
31
|
+
{ action, runId },
|
|
32
|
+
{
|
|
33
|
+
...teamCommandContext(ctx),
|
|
34
|
+
getRunSnapshotCache: deps.getRunSnapshotCache,
|
|
35
|
+
},
|
|
36
|
+
);
|
|
37
|
+
await notifyCommandResult(ctx, commandText(result));
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
for (const [name, action, description] of [
|
|
43
|
+
["team-validate", "validate", "Validate pi-crew agents, teams, and workflows"],
|
|
44
|
+
["team-doctor", "doctor", "Check pi-crew installation and discovery readiness"],
|
|
45
|
+
] as const)
|
|
46
|
+
pi.registerCommand(name, {
|
|
47
|
+
description,
|
|
48
|
+
handler: async (_args: string, ctx: ExtensionCommandContext) => {
|
|
49
|
+
const result = await handleTeamTool({ action }, teamCommandContext(ctx));
|
|
50
|
+
await notifyCommandResult(ctx, commandText(result));
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
pi.registerCommand("team-help", {
|
|
55
|
+
description: "Show pi-crew command help",
|
|
56
|
+
handler: async (_args: string, ctx: ExtensionCommandContext) => {
|
|
57
|
+
await notifyCommandResult(ctx, piTeamsHelp());
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
}
|