pi-subagents 0.65.1 → 0.67.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +123 -0
- package/README.md +5 -4
- package/agents/evidence-auditor.md +34 -0
- package/agents/researcher.md +23 -13
- package/agents/reviewer.md +3 -2
- package/docs/agents.md +20 -3
- package/docs/configuration.md +25 -5
- package/docs/extension-api.md +124 -18
- package/docs/missions.md +8 -0
- package/docs/models.md +59 -2
- package/docs/observability.md +46 -6
- package/docs/standalone-background.md +49 -0
- package/docs/tool-reference.md +20 -10
- package/docs/watchdog.md +35 -4
- package/docs/workflows.md +40 -19
- package/inspector-runner.mjs +2 -2
- package/package.json +2 -1
- package/prompts/parallel-review.md +1 -1
- package/{runner-server-preload.mjs → runner-peer-preload.mjs} +8 -3
- package/skills/pi-subagents/SKILL.md +14 -0
- package/skills/pi-subagents/references/execution-controls.md +20 -5
- package/skills/pi-subagents/references/management-authoring-rpc.md +2 -1
- package/skills/pi-subagents/references/prompting-and-roles.md +2 -2
- package/src/agents/advertised-agent-prompt.ts +94 -0
- package/src/agents/agent-management.ts +14 -1
- package/src/agents/agent-serializer.ts +2 -0
- package/src/agents/agents.ts +14 -0
- package/src/agents/builtin-names.ts +1 -0
- package/src/api/delegation.ts +4 -0
- package/src/api/preflight.ts +76 -45
- package/src/api/shared-types.ts +3 -1
- package/src/api/workflow-resources.ts +6 -0
- package/src/extension/fanout-child.ts +63 -4
- package/src/extension/index.ts +58 -8
- package/src/extension/public-execution.ts +4 -3
- package/src/extension/rpc.ts +8 -21
- package/src/extension/schemas.ts +71 -80
- package/src/extension/tool-description.ts +29 -81
- package/src/inspectors/actions.ts +148 -0
- package/src/inspectors/ghostty/actions.ts +74 -0
- package/src/inspectors/ghostty/plugin.ts +17 -0
- package/src/inspectors/herdr/actions.ts +99 -179
- package/src/inspectors/herdr/plugin.ts +20 -0
- package/src/inspectors/herdr/project-panes.ts +1 -1
- package/src/inspectors/{herdr/inspector-runner.ts → inspector-runner.ts} +12 -12
- package/src/inspectors/plugins.ts +8 -0
- package/src/inspectors/{herdr/session-roots-codec.ts → session-roots-codec.ts} +3 -14
- package/src/inspectors/types.ts +51 -0
- package/src/intercom/intercom-bridge.ts +50 -8
- package/src/intercom/native-supervisor-channel.ts +104 -67
- package/src/runs/background/active-async-capacity.ts +22 -18
- package/src/runs/background/async-execution.ts +45 -56
- package/src/runs/background/async-job-tracker.ts +35 -3
- package/src/runs/background/async-resume.ts +5 -9
- package/src/runs/background/async-status-snapshot.ts +10 -12
- package/src/runs/background/async-status.ts +17 -9
- package/src/runs/background/auto-drain.ts +44 -30
- package/src/runs/background/binary-bootstrap.ts +33 -0
- package/src/runs/background/chain-root-attachment.ts +8 -0
- package/src/runs/background/control-channel.ts +78 -44
- package/src/runs/background/fleet-view.ts +30 -2
- package/src/runs/background/notify.ts +117 -13
- package/src/runs/background/owned-process-tree.ts +35 -8
- package/src/runs/background/process-terminal.ts +23 -23
- package/src/runs/background/run-child-session.ts +121 -36
- package/src/runs/background/run-status.ts +78 -5
- package/src/runs/background/runner-aliases.ts +28 -9
- package/src/runs/background/runner-child-launch.ts +88 -0
- package/src/runs/background/runner-child-sessions.ts +5 -4
- package/src/runs/background/scheduled-runs.ts +40 -13
- package/src/runs/background/stale-run-reconciler.ts +3 -1
- package/src/runs/background/steering.ts +20 -2
- package/src/runs/background/subagent-runner.ts +458 -239
- package/src/runs/background/subagent-wait.ts +54 -8
- package/src/runs/background/wait-completions.ts +4 -0
- package/src/runs/background/wait-tool.ts +1 -1
- package/src/runs/foreground/async-steering-action.ts +37 -7
- package/src/runs/foreground/execution.ts +145 -56
- package/src/runs/foreground/prompt-audit.ts +3 -1
- package/src/runs/foreground/subagent-executor.ts +584 -297
- package/src/runs/foreground/workflow-detach-reconcile.ts +10 -5
- package/src/runs/foreground/workflow-foreground-steering.ts +57 -2
- package/src/runs/shared/acceptance.ts +7 -4
- package/src/runs/shared/agent-contract.ts +1 -1
- package/src/runs/shared/async-status-projection.ts +51 -47
- package/src/runs/shared/capability-ceiling.ts +2 -0
- package/src/runs/shared/child-hooks.ts +167 -3
- package/src/runs/shared/child-launch.ts +28 -13
- package/src/runs/shared/child-lifecycle.ts +6 -3
- package/src/runs/shared/child-runtime-config.ts +3 -1
- package/src/runs/shared/child-session.ts +75 -8
- package/src/runs/shared/child-tool-plan.ts +124 -5
- package/src/runs/shared/completion-evidence.ts +2 -2
- package/src/runs/shared/completion-guard.ts +6 -3
- package/src/runs/shared/effective-system-prompt.ts +33 -0
- package/src/runs/shared/external-cli-runner.ts +9 -7
- package/src/runs/shared/host-step-status.ts +11 -11
- package/src/runs/shared/llm-intent-arbiter.ts +21 -11
- package/src/runs/shared/model-fallback.ts +12 -6
- package/src/runs/shared/nested-events.ts +5 -5
- package/src/runs/shared/orca-progress-tabs.ts +7 -1
- package/src/runs/shared/parallel-handoff.ts +57 -12
- package/src/runs/shared/parallel-utils.ts +2 -2
- package/src/runs/shared/pi-spawn.ts +10 -0
- package/src/runs/shared/readonly-drain-observation.ts +42 -0
- package/src/runs/shared/readonly-model-continuation.ts +69 -0
- package/src/runs/shared/readonly-session-evidence.ts +307 -0
- package/src/runs/shared/run-fanout-budget.ts +8 -8
- package/src/runs/shared/runtime-acknowledged-extensions.ts +3 -3
- package/src/runs/shared/subagent-prompt-runtime.ts +20 -4
- package/src/runs/shared/task-intent.ts +46 -13
- package/src/runs/shared/workflow-async-child-guidance.ts +18 -0
- package/src/runs/shared/worktree-setup-command.ts +190 -0
- package/src/runs/shared/worktree.ts +366 -208
- package/src/shared/fork-context.ts +15 -72
- package/src/shared/launch-contract.ts +65 -2
- package/src/shared/opencode-session-headers.ts +30 -0
- package/src/shared/types.ts +85 -61
- package/src/shared/utils.ts +7 -2
- package/src/shared/workflow-child-permit.ts +18 -13
- package/src/slash/delegation-adapters.ts +3 -1
- package/src/slash/delegation-request.ts +14 -0
- package/src/slash/slash-commands.ts +2 -1
- package/src/slash/subagents-admin.ts +11 -4
- package/src/tui/fleet-status.ts +164 -19
- package/src/tui/fleet.ts +27 -19
- package/src/tui/render.ts +172 -33
- package/src/watchdog/child-status.ts +8 -0
- package/src/watchdog/model-selection.ts +20 -0
- package/src/watchdog/permission-arbiter.ts +3 -1
- package/src/watchdog/register-child.ts +1 -0
- package/src/watchdog/register-main.ts +31 -27
- package/src/watchdog/review.ts +132 -67
- package/src/watchdog/runtime.ts +82 -20
- package/src/watchdog/scope.ts +1 -1
- package/src/watchdog/settings.ts +9 -3
- package/src/watchdog/tool-actions.ts +13 -12
- package/src/watchdog/turn-delta.ts +23 -0
- package/src/watchdog/types.ts +4 -0
- package/src/workflows/chat-progress.ts +3 -3
- package/src/workflows/scripted-workflow.ts +275 -17
- package/src/workflows/workflow-checklist.ts +13 -17
- package/src/workflows/workflow-child-summary.ts +57 -8
- package/src/workflows/workflow-preflight.ts +19 -19
- package/src/workflows/workflow-receipt.ts +3 -3
- package/src/workflows/workflow-resources.ts +96 -21
- package/src/workflows/workflow-settlement.ts +3 -0
- /package/src/inspectors/{herdr/shell-command.ts → shell-command.ts} +0 -0
package/src/watchdog/runtime.ts
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
import { ruleViolationWarning, type WatchdogRuleViolation } from "./rules.ts";
|
|
13
13
|
import { WatchdogScopeArtifact } from "./scope.ts";
|
|
14
14
|
import { resolveWatchdogConfig } from "./settings.ts";
|
|
15
|
-
import { formatWatchdogTurnDelta } from "./turn-delta.ts";
|
|
15
|
+
import { formatWatchdogOrchestrationActivity, formatWatchdogTurnDelta } from "./turn-delta.ts";
|
|
16
16
|
import {
|
|
17
17
|
type ResolvedWatchdogConfig,
|
|
18
18
|
type WatchdogEndpointConfig,
|
|
@@ -31,6 +31,7 @@ type ReviewStopReason = "stop" | "error" | "aborted" | "length";
|
|
|
31
31
|
export interface WatchdogReviewResult {
|
|
32
32
|
warnings?: WatchdogWarning[];
|
|
33
33
|
stopReason?: ReviewStopReason;
|
|
34
|
+
clarification?: { question: string; evidence: string };
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
export interface WatchdogReviewRequest {
|
|
@@ -40,6 +41,7 @@ export interface WatchdogReviewRequest {
|
|
|
40
41
|
reviewId: number;
|
|
41
42
|
config: ResolvedWatchdogConfig;
|
|
42
43
|
emitWarning(warning: WatchdogWarning): boolean;
|
|
44
|
+
allowClarification?: boolean;
|
|
43
45
|
signal?: AbortSignal;
|
|
44
46
|
}
|
|
45
47
|
|
|
@@ -81,6 +83,8 @@ interface MainWatchdogRuntimeOptions {
|
|
|
81
83
|
review?: WatchdogReviewFunction;
|
|
82
84
|
reviewDescription?: string;
|
|
83
85
|
displayWarning?: (warning: WatchdogWarningDetails, options?: WatchdogWarningSendOptions) => void;
|
|
86
|
+
/** Supplying this main-session delivery capability gates clarification (children omit it). */
|
|
87
|
+
displayClarification?: (content: string) => void;
|
|
84
88
|
reviewChangesOnly?: boolean;
|
|
85
89
|
lspDiagnostics?: WatchdogLspDiagnosticsFunction;
|
|
86
90
|
repoChangeSignature?: typeof computeWatchdogRepoChangeSignature;
|
|
@@ -88,8 +92,8 @@ interface MainWatchdogRuntimeOptions {
|
|
|
88
92
|
|
|
89
93
|
export type WatchdogWarningSendOptions = { deliverAs: "steer" } | { triggerTurn: false };
|
|
90
94
|
|
|
91
|
-
type ContextLike = Pick<ExtensionContext, "cwd"
|
|
92
|
-
type ReviewDeltaOutcome = "completed" | "timeout" | "stale"
|
|
95
|
+
type ContextLike = Pick<ExtensionContext, "cwd"> & { signal?: AbortSignal };
|
|
96
|
+
type ReviewDeltaOutcome = "completed" | "timeout" | "stale" | NonNullable<WatchdogReviewResult["clarification"]>;
|
|
93
97
|
|
|
94
98
|
const DEFAULT_REVIEW: WatchdogReviewFunction = () => ({ warnings: [] });
|
|
95
99
|
const MAX_REVIEW_INPUT_CHARS = 24_000;
|
|
@@ -170,6 +174,11 @@ export class MainWatchdogRuntime {
|
|
|
170
174
|
private activeReviewAbortController: AbortController | undefined;
|
|
171
175
|
private failedReviews = 0;
|
|
172
176
|
private staleReviews = 0;
|
|
177
|
+
private readonly displayClarification: MainWatchdogRuntimeOptions["displayClarification"];
|
|
178
|
+
private askedThisPrompt = false;
|
|
179
|
+
private activityTail = "";
|
|
180
|
+
private activityPending = false;
|
|
181
|
+
private activityReviewUsed = false;
|
|
173
182
|
|
|
174
183
|
constructor(options: MainWatchdogRuntimeOptions = {}) {
|
|
175
184
|
this.cwd = options.cwd ?? process.cwd();
|
|
@@ -178,6 +187,7 @@ export class MainWatchdogRuntime {
|
|
|
178
187
|
this.reviewConnected = Boolean(options.review);
|
|
179
188
|
this.reviewDescription = options.reviewDescription ?? (options.review ? "injected seam" : "not wired");
|
|
180
189
|
this.displayWarning = options.displayWarning;
|
|
190
|
+
this.displayClarification = options.displayClarification;
|
|
181
191
|
this.reviewChangesOnly = options.reviewChangesOnly === true;
|
|
182
192
|
this.lspDiagnostics = options.lspDiagnostics ?? collectWatchdogLspDiagnostics;
|
|
183
193
|
this.repoChangeSignature = options.repoChangeSignature ?? computeWatchdogRepoChangeSignature;
|
|
@@ -200,6 +210,8 @@ export class MainWatchdogRuntime {
|
|
|
200
210
|
refreshConfig(cwd = this.cwd): WatchdogSettingsResult {
|
|
201
211
|
this.cwd = cwd;
|
|
202
212
|
const wasEnabled = this.isEnabled();
|
|
213
|
+
const hadClarification = this.configResult.config.clarification;
|
|
214
|
+
const previousMain = this.configResult.config.main;
|
|
203
215
|
const session = this.sessionOverrideEnabled === undefined && this.sessionModelOverride === undefined
|
|
204
216
|
? undefined
|
|
205
217
|
: {
|
|
@@ -215,6 +227,10 @@ export class MainWatchdogRuntime {
|
|
|
215
227
|
this.guard = new WatchdogEmissionGuard({ maxWarnings: this.guardMaxWarnings });
|
|
216
228
|
}
|
|
217
229
|
if (wasEnabled && !this.isEnabled()) this.invalidateActiveReview("watchdog disabled");
|
|
230
|
+
if (!this.isEnabled() || !this.configResult.config.clarification) this.clearActivity();
|
|
231
|
+
if (this.displayClarification && (hadClarification || this.configResult.config.clarification) && (this.reviewing || this.waitingAtAgentEnd)) {
|
|
232
|
+
if (!this.configResult.config.clarification || previousMain.model !== this.configResult.config.main.model || previousMain.thinking !== this.configResult.config.main.thinking) this.invalidateActiveReview("clarification configuration changed");
|
|
233
|
+
}
|
|
218
234
|
return this.configResult;
|
|
219
235
|
}
|
|
220
236
|
|
|
@@ -253,6 +269,7 @@ export class MainWatchdogRuntime {
|
|
|
253
269
|
}
|
|
254
270
|
|
|
255
271
|
reset(_reason = "reset", options: { clearReviewInputSignature?: boolean; resetChangeSignature?: boolean; clearLspLedger?: boolean; clearScope?: boolean } = {}): void {
|
|
272
|
+
this.activeReviewAbortController?.abort();
|
|
256
273
|
this.abortActiveAgentEnd();
|
|
257
274
|
this.epoch++;
|
|
258
275
|
this.status = "idle";
|
|
@@ -273,7 +290,10 @@ export class MainWatchdogRuntime {
|
|
|
273
290
|
this.lspLedger.reset();
|
|
274
291
|
this.lastLspSnapshot = undefined;
|
|
275
292
|
}
|
|
276
|
-
if (options.clearScope)
|
|
293
|
+
if (options.clearScope) {
|
|
294
|
+
this.scope.reset();
|
|
295
|
+
this.clearActivity();
|
|
296
|
+
}
|
|
277
297
|
if (options.clearReviewInputSignature) this.lastReviewInputSignature = undefined;
|
|
278
298
|
if (options.resetChangeSignature) this.resetRepoChangeBaseline({ reviewed: true });
|
|
279
299
|
this.guard.reset();
|
|
@@ -281,6 +301,8 @@ export class MainWatchdogRuntime {
|
|
|
281
301
|
}
|
|
282
302
|
|
|
283
303
|
dispose(): void {
|
|
304
|
+
this.clearActivity();
|
|
305
|
+
this.activeReviewAbortController?.abort();
|
|
284
306
|
this.disposed = true;
|
|
285
307
|
this.abortActiveAgentEnd();
|
|
286
308
|
this.epoch++;
|
|
@@ -305,6 +327,8 @@ export class MainWatchdogRuntime {
|
|
|
305
327
|
if (this.disposed) return;
|
|
306
328
|
const incomingPrompt = promptFromBeforeAgentStart(event);
|
|
307
329
|
this.reset("before_agent_start");
|
|
330
|
+
this.askedThisPrompt = false;
|
|
331
|
+
this.activityReviewUsed = false;
|
|
308
332
|
this.resetBoundaryRepeats();
|
|
309
333
|
this.refreshConfig(ctx.cwd);
|
|
310
334
|
this.userPrompt = incomingPrompt;
|
|
@@ -322,6 +346,13 @@ export class MainWatchdogRuntime {
|
|
|
322
346
|
this.refreshConfig(ctx.cwd);
|
|
323
347
|
if (!this.isEnabled()) return;
|
|
324
348
|
try {
|
|
349
|
+
if (this.displayClarification && this.configResult.config.clarification && this.boundaryRepeats === 0) {
|
|
350
|
+
const activity = formatWatchdogOrchestrationActivity(event);
|
|
351
|
+
if (activity) {
|
|
352
|
+
this.activityTail = [this.activityTail, boundWatchdogReviewText(activity, 3_000)].filter(Boolean).join(REVIEW_DELTA_SEPARATOR).slice(-6_000);
|
|
353
|
+
this.activityPending = true;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
325
356
|
this.observedRepoEditThisTurn ||= eventIndicatesRepoEdit(event);
|
|
326
357
|
const delta = formatWatchdogTurnDelta({
|
|
327
358
|
includeUserPrompt: this.includeUserPromptInNextDelta,
|
|
@@ -359,20 +390,19 @@ export class MainWatchdogRuntime {
|
|
|
359
390
|
if (this.disposed) return;
|
|
360
391
|
this.refreshConfig(ctx.cwd);
|
|
361
392
|
if (!this.isEnabled()) return;
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
return;
|
|
368
|
-
}
|
|
369
|
-
if (changeSignature && changeSignature.key === this.lastReviewedChangeSignature) {
|
|
393
|
+
if (ctx.signal?.aborted) return;
|
|
394
|
+
const changeSignature = this.resolveReviewChangeSignature(this.currentRepoChangeSignature(ctx.cwd), ctx.cwd);
|
|
395
|
+
const activityReview = Boolean(this.displayClarification && this.configResult.config.clarification && !this.activityReviewUsed && this.boundaryRepeats === 0 && this.activityPending);
|
|
396
|
+
const knownEvidence = changeSignature && changeSignature.key === this.lastReviewedChangeSignature;
|
|
397
|
+
if (!activityReview && (knownEvidence || (this.reviewChangesOnly && !changeSignature))) {
|
|
370
398
|
this.clearPendingDeltas();
|
|
371
|
-
this.status = "idle";
|
|
399
|
+
if (knownEvidence || this.status === "queued") this.status = "idle";
|
|
372
400
|
this.resolveWaiters(true);
|
|
373
401
|
return;
|
|
374
402
|
}
|
|
375
403
|
this.cancelMidRunReview();
|
|
404
|
+
if (activityReview && (!changeSignature || knownEvidence)) this.activityReviewUsed = true;
|
|
405
|
+
this.activityPending = false;
|
|
376
406
|
this.waitingAtAgentEnd = true;
|
|
377
407
|
const agentEndEpoch = this.epoch;
|
|
378
408
|
const agentEndId = ++this.agentEndIdCounter;
|
|
@@ -403,7 +433,8 @@ export class MainWatchdogRuntime {
|
|
|
403
433
|
this.resolveWaiters(true);
|
|
404
434
|
return;
|
|
405
435
|
}
|
|
406
|
-
const outcome = await this.reviewDelta(delta, this.configResult.config.agentEndTimeoutMs);
|
|
436
|
+
const outcome = await this.reviewDelta(delta, this.configResult.config.agentEndTimeoutMs, { allowClarification: true });
|
|
437
|
+
if (!this.isAgentEndCurrent(agentEndEpoch, agentEndId)) return;
|
|
407
438
|
this.waitingAtAgentEnd = false;
|
|
408
439
|
if (outcome === "timeout") {
|
|
409
440
|
this.staleReviews++;
|
|
@@ -413,11 +444,16 @@ export class MainWatchdogRuntime {
|
|
|
413
444
|
this.resolveWaiters(true);
|
|
414
445
|
return;
|
|
415
446
|
}
|
|
416
|
-
if (outcome === "completed" && this.status !== "failed" && this.status !== "stale") {
|
|
447
|
+
if ((outcome === "completed" || typeof outcome === "object") && this.status !== "failed" && this.status !== "stale") {
|
|
448
|
+
// A question consumes this evidence just like a completed review, not a pending exchange.
|
|
417
449
|
this.lastReviewInputSignature = signature;
|
|
418
450
|
if (changeSignature) this.lastReviewedChangeSignature = changeSignature.key;
|
|
419
451
|
this.currentChangedPaths = changeSignature?.changedPaths;
|
|
420
452
|
this.status = "idle";
|
|
453
|
+
if (typeof outcome === "object" && !ctx.signal?.aborted) this.displayClarification?.([
|
|
454
|
+
"Main watchdog clarification:", outcome.question, `Evidence: ${outcome.evidence}`,
|
|
455
|
+
"Consider this missing context as you continue the task. This is not approval, permission, or a warning. The reviewer has yielded; no reply or follow-up review is required.",
|
|
456
|
+
].join("\n"));
|
|
421
457
|
}
|
|
422
458
|
this.resolveWaiters(true);
|
|
423
459
|
} finally {
|
|
@@ -468,6 +504,15 @@ export class MainWatchdogRuntime {
|
|
|
468
504
|
};
|
|
469
505
|
}
|
|
470
506
|
|
|
507
|
+
/** A real mid-stream user input can steer without emitting before_agent_start. */
|
|
508
|
+
handleUserInput(): void {
|
|
509
|
+
if (this.displayClarification && this.configResult.config.clarification && (this.reviewing || this.waitingAtAgentEnd)) this.reset("new user input");
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
handleModelChange(): void {
|
|
513
|
+
if (this.displayClarification && this.configResult.config.clarification && (this.reviewing || this.waitingAtAgentEnd)) this.reset("model changed");
|
|
514
|
+
}
|
|
515
|
+
|
|
471
516
|
async waitForIdle(timeoutMs = 1_000): Promise<boolean> {
|
|
472
517
|
return this.waitForSettled(timeoutMs);
|
|
473
518
|
}
|
|
@@ -523,6 +568,7 @@ export class MainWatchdogRuntime {
|
|
|
523
568
|
}
|
|
524
569
|
|
|
525
570
|
private invalidateActiveReview(_reason: string): void {
|
|
571
|
+
this.activeReviewAbortController?.abort();
|
|
526
572
|
this.abortActiveAgentEnd();
|
|
527
573
|
this.epoch++;
|
|
528
574
|
this.status = "idle";
|
|
@@ -567,7 +613,7 @@ export class MainWatchdogRuntime {
|
|
|
567
613
|
this.activeReviewWarning = undefined;
|
|
568
614
|
}
|
|
569
615
|
|
|
570
|
-
private async reviewDelta(delta: string, timeoutMs: number, options: { correction?: boolean } = {}): Promise<ReviewDeltaOutcome> {
|
|
616
|
+
private async reviewDelta(delta: string, timeoutMs: number, options: { correction?: boolean; allowClarification?: boolean } = {}): Promise<ReviewDeltaOutcome> {
|
|
571
617
|
if (this.reviewing || this.disposed) return "stale";
|
|
572
618
|
this.reviewing = true;
|
|
573
619
|
const reviewEpoch = this.epoch;
|
|
@@ -578,6 +624,7 @@ export class MainWatchdogRuntime {
|
|
|
578
624
|
let timeout: ReturnType<typeof setTimeout> | undefined;
|
|
579
625
|
const abortController = new AbortController();
|
|
580
626
|
this.activeReviewAbortController = abortController;
|
|
627
|
+
const allowClarification = Boolean(options.allowClarification && this.displayClarification && this.configResult.config.clarification && !this.askedThisPrompt && !this.stalemate);
|
|
581
628
|
const reviewPromise = Promise.resolve().then(() => this.review({
|
|
582
629
|
delta,
|
|
583
630
|
epoch: reviewEpoch,
|
|
@@ -586,6 +633,7 @@ export class MainWatchdogRuntime {
|
|
|
586
633
|
hasScope: this.scopeBlock().trim().length > 0,
|
|
587
634
|
signal: abortController.signal,
|
|
588
635
|
emitWarning: (warning) => this.acceptWarning(reviewEpoch, reviewId, warning),
|
|
636
|
+
...(allowClarification ? { allowClarification: true } : {}),
|
|
589
637
|
}));
|
|
590
638
|
try {
|
|
591
639
|
const result = await Promise.race([
|
|
@@ -600,6 +648,14 @@ export class MainWatchdogRuntime {
|
|
|
600
648
|
}
|
|
601
649
|
if (!this.isCurrent(reviewEpoch, reviewId)) return "stale";
|
|
602
650
|
if (!result) return "stale";
|
|
651
|
+
if (allowClarification && this.configResult.config.clarification && result.clarification && (!result.stopReason || result.stopReason === "stop") && !this.activeReviewWarning && !result.warnings?.length && !abortController.signal.aborted) {
|
|
652
|
+
const question = result.clarification.question.trim();
|
|
653
|
+
const evidence = result.clarification.evidence.trim();
|
|
654
|
+
if (question && evidence) {
|
|
655
|
+
this.askedThisPrompt = true;
|
|
656
|
+
return { question: boundWatchdogReviewText(question, 1_000), evidence: boundWatchdogReviewText(evidence, 2_000) };
|
|
657
|
+
}
|
|
658
|
+
}
|
|
603
659
|
for (const warning of result.warnings ?? []) this.acceptWarning(reviewEpoch, reviewId, warning);
|
|
604
660
|
if (result.stopReason && result.stopReason !== "stop") {
|
|
605
661
|
this.fail(`Watchdog review ended with stop reason '${result.stopReason}'.`);
|
|
@@ -681,9 +737,8 @@ export class MainWatchdogRuntime {
|
|
|
681
737
|
this.observedRepoEditThisTurn = false;
|
|
682
738
|
}
|
|
683
739
|
|
|
684
|
-
private resolveReviewChangeSignature(
|
|
740
|
+
private resolveReviewChangeSignature(current: WatchdogRepoChangeSignature | undefined, cwd: string): WatchdogRepoChangeSignature | undefined {
|
|
685
741
|
if (!this.reviewChangesOnly) return undefined;
|
|
686
|
-
const current = this.currentRepoChangeSignature(cwd);
|
|
687
742
|
if (current) {
|
|
688
743
|
this.currentChangedPaths = current.changedPaths;
|
|
689
744
|
if (current.key === this.turnStartChangeSignature?.key) return undefined;
|
|
@@ -785,13 +840,14 @@ export class MainWatchdogRuntime {
|
|
|
785
840
|
const changes = changeSignature?.changedPaths.length
|
|
786
841
|
? ["Changed repo paths:", ...changeSignature.changedPaths.slice(0, 200).map((file) => `- ${file}`)].join("\n")
|
|
787
842
|
: "";
|
|
788
|
-
const
|
|
843
|
+
const activity = this.activityTail ? `Recent delivered orchestration activity (oldest first; bounded observations, not a task board; waits/holds are not evidence of neglect):\n${this.activityTail}` : "";
|
|
844
|
+
const contextPieces = [scopeBlock, changes, lspBlock, activity].filter(Boolean);
|
|
789
845
|
if (!contextPieces.length) return boundWatchdogReviewText(input);
|
|
790
846
|
|
|
791
847
|
const maxContextLength = Math.floor(MAX_REVIEW_INPUT_CHARS / 2);
|
|
792
848
|
const maxPieceLength = Math.max(1_000, Math.floor(maxContextLength / contextPieces.length));
|
|
793
849
|
const boundedContext = contextPieces.map((piece) => piece.length > maxPieceLength
|
|
794
|
-
? `${piece.slice(0, maxPieceLength - 6)}\n- ...`
|
|
850
|
+
? piece === activity ? boundWatchdogReviewText(piece, maxPieceLength) : `${piece.slice(0, maxPieceLength - 6)}\n- ...`
|
|
795
851
|
: piece).join(REVIEW_DELTA_SEPARATOR);
|
|
796
852
|
const separatorLength = input ? REVIEW_DELTA_SEPARATOR.length : 0;
|
|
797
853
|
const inputBudget = MAX_REVIEW_INPUT_CHARS - boundedContext.length - separatorLength;
|
|
@@ -808,6 +864,12 @@ export class MainWatchdogRuntime {
|
|
|
808
864
|
this.pendingDeltaChars = 0;
|
|
809
865
|
}
|
|
810
866
|
|
|
867
|
+
private clearActivity(): void {
|
|
868
|
+
if (!this.activityTail) return;
|
|
869
|
+
this.activityTail = "";
|
|
870
|
+
this.activityPending = false;
|
|
871
|
+
}
|
|
872
|
+
|
|
811
873
|
private fail(message: string): void {
|
|
812
874
|
this.failedReviews++;
|
|
813
875
|
this.lastError = message;
|
package/src/watchdog/scope.ts
CHANGED
|
@@ -32,7 +32,7 @@ export class WatchdogScopeArtifact {
|
|
|
32
32
|
if (!this.entries.length) return "";
|
|
33
33
|
return [
|
|
34
34
|
"Current scope:",
|
|
35
|
-
"The following real user prompts are the current scope record, newest last.
|
|
35
|
+
"The following real user prompts are the current scope record, newest last. Side questions are additive, not scope drift or cancellation of older objectives; only explicit changes supersede requirements. Use watchdog_warn for evidence-backed reminders of forgotten authorized work, not dependencies still pending or explicit holds. The orchestrator owns task tracking. Flag unauthorized work as category 'scope-drift'.",
|
|
36
36
|
...this.entries.map((entry, index) => [
|
|
37
37
|
`Scope prompt ${index + 1} (${entry.createdAt}):`,
|
|
38
38
|
entry.prompt,
|
package/src/watchdog/settings.ts
CHANGED
|
@@ -61,6 +61,7 @@ interface ParseMeta {
|
|
|
61
61
|
|
|
62
62
|
export const DEFAULT_WATCHDOG_CONFIG: ResolvedWatchdogConfig = {
|
|
63
63
|
enabled: false,
|
|
64
|
+
clarification: false,
|
|
64
65
|
agentEndTimeoutMs: 30_000,
|
|
65
66
|
severityThreshold: "concern",
|
|
66
67
|
maxWarnings: null,
|
|
@@ -92,6 +93,7 @@ export const DEFAULT_WATCHDOG_CONFIG: ResolvedWatchdogConfig = {
|
|
|
92
93
|
|
|
93
94
|
const WATCHDOG_FIELDS = new Set([
|
|
94
95
|
"enabled",
|
|
96
|
+
"clarification",
|
|
95
97
|
"agentEndTimeoutMs",
|
|
96
98
|
"severityThreshold",
|
|
97
99
|
"maxWarnings",
|
|
@@ -109,9 +111,9 @@ const ROLE_MODEL_RULE_FIELDS = new Set(["allow", "deny", "note"]);
|
|
|
109
111
|
const GUIDANCE_FIELDS = new Set(["watchdogMd"]);
|
|
110
112
|
const SCOPE_FIELDS = new Set(["enabled"]);
|
|
111
113
|
const CADENCE_FIELDS = new Set(["everyNTools"]);
|
|
112
|
-
const ENDPOINT_FIELDS = new Set(["enabled", "model", "thinking"]);
|
|
113
|
-
const CHILDREN_FIELDS = new Set(["enabled", "model", "thinking", "watchdogTailTimeoutMs", "cadence", "overrides"]);
|
|
114
|
-
const CHILD_OVERRIDE_FIELDS = new Set(["enabled", "model", "thinking", "cadence"]);
|
|
114
|
+
const ENDPOINT_FIELDS = new Set(["enabled", "model", "fallbackModels", "thinking"]);
|
|
115
|
+
const CHILDREN_FIELDS = new Set(["enabled", "model", "fallbackModels", "thinking", "watchdogTailTimeoutMs", "cadence", "overrides"]);
|
|
116
|
+
const CHILD_OVERRIDE_FIELDS = new Set(["enabled", "model", "fallbackModels", "thinking", "cadence"]);
|
|
115
117
|
const LSP_FIELDS = new Set(["enabled", "timeoutMs", "maxFiles", "maxDiagnostics"]);
|
|
116
118
|
|
|
117
119
|
function cloneDefaultConfig(): ResolvedWatchdogConfig {
|
|
@@ -219,6 +221,7 @@ function parseEndpointPatch(value: unknown, field: string, meta: ParseMeta): Wat
|
|
|
219
221
|
const input = parseObject(value, field, meta);
|
|
220
222
|
assertKnownFields(input, ENDPOINT_FIELDS, field, meta);
|
|
221
223
|
const patch: WatchdogEndpointPatch = {};
|
|
224
|
+
if ("fallbackModels" in input) patch.fallbackModels = parseStringList(input.fallbackModels, `${field}.fallbackModels`, meta);
|
|
222
225
|
if ("enabled" in input) patch.enabled = parseBoolean(input.enabled, `${field}.enabled`, meta);
|
|
223
226
|
if ("model" in input) patch.model = parseNonEmptyString(input.model, `${field}.model`, meta);
|
|
224
227
|
if ("thinking" in input) patch.thinking = parseThinking(input.thinking, `${field}.thinking`, meta);
|
|
@@ -229,6 +232,7 @@ function parseChildOverridePatch(value: unknown, field: string, meta: ParseMeta)
|
|
|
229
232
|
const input = parseObject(value, field, meta);
|
|
230
233
|
assertKnownFields(input, CHILD_OVERRIDE_FIELDS, field, meta);
|
|
231
234
|
const patch: WatchdogChildOverridePatch = {};
|
|
235
|
+
if ("fallbackModels" in input) patch.fallbackModels = parseStringList(input.fallbackModels, `${field}.fallbackModels`, meta);
|
|
232
236
|
if ("enabled" in input) patch.enabled = parseBoolean(input.enabled, `${field}.enabled`, meta);
|
|
233
237
|
if ("model" in input) patch.model = parseNonEmptyString(input.model, `${field}.model`, meta);
|
|
234
238
|
if ("thinking" in input) patch.thinking = parseThinking(input.thinking, `${field}.thinking`, meta);
|
|
@@ -240,6 +244,7 @@ function parseChildrenPatch(value: unknown, field: string, meta: ParseMeta): Wat
|
|
|
240
244
|
const input = parseObject(value, field, meta);
|
|
241
245
|
assertKnownFields(input, CHILDREN_FIELDS, field, meta);
|
|
242
246
|
const patch: WatchdogChildrenPatch = {};
|
|
247
|
+
if ("fallbackModels" in input) patch.fallbackModels = parseStringList(input.fallbackModels, `${field}.fallbackModels`, meta);
|
|
243
248
|
if ("enabled" in input) patch.enabled = parseBoolean(input.enabled, `${field}.enabled`, meta);
|
|
244
249
|
if ("model" in input) patch.model = parseNonEmptyString(input.model, `${field}.model`, meta);
|
|
245
250
|
if ("thinking" in input) patch.thinking = parseThinking(input.thinking, `${field}.thinking`, meta);
|
|
@@ -303,6 +308,7 @@ function parseWatchdogPatch(value: unknown, field: string, meta: ParseMeta): Wat
|
|
|
303
308
|
assertKnownFields(input, WATCHDOG_FIELDS, field, meta);
|
|
304
309
|
const patch: WatchdogConfigPatch = {};
|
|
305
310
|
if ("enabled" in input) patch.enabled = parseBoolean(input.enabled, `${field}.enabled`, meta);
|
|
311
|
+
if ("clarification" in input) patch.clarification = parseBoolean(input.clarification, `${field}.clarification`, meta);
|
|
306
312
|
if ("agentEndTimeoutMs" in input) {
|
|
307
313
|
patch.agentEndTimeoutMs = parseInteger(input.agentEndTimeoutMs, `${field}.agentEndTimeoutMs`, meta, "a positive integer", (candidate) => candidate >= 1);
|
|
308
314
|
}
|
|
@@ -4,8 +4,8 @@ import { THINKING_LEVELS, type ThinkingLevel } from "../shared/model-info.ts";
|
|
|
4
4
|
import type { Details } from "../shared/types.ts";
|
|
5
5
|
import { buildWatchdogStatus } from "./register-main.ts";
|
|
6
6
|
import type { MainWatchdogRuntime } from "./runtime.ts";
|
|
7
|
-
import { parseWatchdogThinkingInput, recommendStrongWatchdogModel, resolveWatchdogModelInput } from "./model-selection.ts";
|
|
8
|
-
import { writeWatchdogModelSettings, type WatchdogModelSettingsTarget, type WatchdogSettingsWriteScope } from "./settings.ts";
|
|
7
|
+
import { formatWatchdogRecommendation, parseWatchdogThinkingInput, recommendStrongWatchdogModel, recommendWatchdogModel, resolveWatchdogModelInput } from "./model-selection.ts";
|
|
8
|
+
import { resolveWatchdogConfig, writeWatchdogModelSettings, type WatchdogModelSettingsTarget, type WatchdogSettingsWriteScope } from "./settings.ts";
|
|
9
9
|
|
|
10
10
|
interface WatchdogToolParams {
|
|
11
11
|
action?: string;
|
|
@@ -52,7 +52,7 @@ function parseThinking(raw: string | false | undefined): ThinkingLevel | false |
|
|
|
52
52
|
return parseWatchdogThinkingInput(raw, "watchdog.configure thinking") ?? undefined;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
function resolveConfiguredValue(ctx: ExtensionContext, params: WatchdogToolParams): { model?: string | null; thinking?: ThinkingLevel | false | null; description: string } {
|
|
55
|
+
function resolveConfiguredValue(ctx: ExtensionContext, params: WatchdogToolParams, runtime?: MainWatchdogRuntime): { model?: string | null; thinking?: ThinkingLevel | false | null; description: string } {
|
|
56
56
|
const thinking = parseThinking(params.thinking);
|
|
57
57
|
const rawModel = params.model?.trim();
|
|
58
58
|
if (!rawModel) {
|
|
@@ -61,7 +61,9 @@ function resolveConfiguredValue(ctx: ExtensionContext, params: WatchdogToolParam
|
|
|
61
61
|
}
|
|
62
62
|
if (rawModel === "inherit") return { model: null, thinking: thinking ?? null, description: "inherit" };
|
|
63
63
|
if (rawModel === "recommended") {
|
|
64
|
-
const recommendation =
|
|
64
|
+
const recommendation = (params.target ?? "main") === "main"
|
|
65
|
+
? recommendWatchdogModel(ctx, (runtime?.getSnapshot(ctx.cwd).config ?? resolveWatchdogConfig(ctx.cwd).config).main)
|
|
66
|
+
: recommendStrongWatchdogModel(ctx);
|
|
65
67
|
return {
|
|
66
68
|
model: recommendation.model,
|
|
67
69
|
thinking: recommendation.thinking,
|
|
@@ -76,11 +78,11 @@ function resolveConfiguredValue(ctx: ExtensionContext, params: WatchdogToolParam
|
|
|
76
78
|
};
|
|
77
79
|
}
|
|
78
80
|
|
|
79
|
-
function buildRecommendationText(ctx: ExtensionContext): string {
|
|
80
|
-
const recommendation =
|
|
81
|
+
function buildRecommendationText(ctx: ExtensionContext, runtime?: MainWatchdogRuntime): string {
|
|
82
|
+
const recommendation = recommendWatchdogModel(ctx, (runtime?.getSnapshot(ctx.cwd).config ?? resolveWatchdogConfig(ctx.cwd).config).main);
|
|
81
83
|
return [
|
|
82
84
|
"Subagent watchdog recommended model",
|
|
83
|
-
`Recommended: ${recommendation.model}:${recommendation.thinking}`,
|
|
85
|
+
recommendation.source === "configured" ? formatWatchdogRecommendation(recommendation) : `Recommended: ${recommendation.model}:${recommendation.thinking}`,
|
|
84
86
|
`Reason: ${recommendation.reason}`,
|
|
85
87
|
"Apply temporarily with subagent({ action: \"watchdog.configure\", scope: \"session\", model: \"recommended\" }).",
|
|
86
88
|
"Persist with scope: \"project\" or scope: \"user\" only when the user asks for that scope.",
|
|
@@ -100,10 +102,9 @@ function buildCheckText(runtime: MainWatchdogRuntime | undefined, ctx: Extension
|
|
|
100
102
|
}
|
|
101
103
|
lines.push(`LSP diagnostics: ${snapshot.lsp.enabled ? "on" : "off"} · ${snapshot.lsp.status}`);
|
|
102
104
|
try {
|
|
103
|
-
|
|
104
|
-
lines.push(`Recommended strong watchdog: ${recommendation.model}:${recommendation.thinking}`);
|
|
105
|
+
lines.push(formatWatchdogRecommendation(recommendWatchdogModel(ctx, snapshot.config.main)));
|
|
105
106
|
} catch (error) {
|
|
106
|
-
lines.push(`
|
|
107
|
+
lines.push(`Watchdog recommendation unavailable: ${messageFromError(error)}`);
|
|
107
108
|
}
|
|
108
109
|
return lines.join("\n");
|
|
109
110
|
}
|
|
@@ -114,13 +115,13 @@ export function handleWatchdogToolAction(action: string, params: WatchdogToolPar
|
|
|
114
115
|
if (!runtime) return result("Subagent watchdog runtime is unavailable.", true);
|
|
115
116
|
return result(buildWatchdogStatus(runtime.getSnapshot(ctx.cwd), ctx));
|
|
116
117
|
}
|
|
117
|
-
if (action === "watchdog.recommend-model") return result(buildRecommendationText(ctx));
|
|
118
|
+
if (action === "watchdog.recommend-model") return result(buildRecommendationText(ctx, runtime));
|
|
118
119
|
if (action === "watchdog.check") return result(buildCheckText(runtime, ctx));
|
|
119
120
|
if (action !== "watchdog.configure") return result(`Unknown watchdog action: ${action}`, true);
|
|
120
121
|
|
|
121
122
|
const scope = parseScope(params.scope);
|
|
122
123
|
const target = parseTarget(params);
|
|
123
|
-
const value = resolveConfiguredValue(ctx, params);
|
|
124
|
+
const value = resolveConfiguredValue(ctx, params, runtime);
|
|
124
125
|
if (scope === "session") {
|
|
125
126
|
if (!runtime) return result("Subagent watchdog runtime is unavailable.", true);
|
|
126
127
|
if (target.kind !== "main") return result("Session-scoped watchdog.configure currently supports target='main' only.", true);
|
|
@@ -159,3 +159,26 @@ export function formatWatchdogTurnDelta(input: WatchdogTurnDeltaInput): string {
|
|
|
159
159
|
if (input.finalAssistantStop) sections.push("Final assistant stop: stop without tool call");
|
|
160
160
|
return sections.join("\n\n---\n\n");
|
|
161
161
|
}
|
|
162
|
+
|
|
163
|
+
/** Only completed, exactly paired native orchestration calls are activity evidence. */
|
|
164
|
+
export function formatWatchdogOrchestrationActivity(event: unknown): string {
|
|
165
|
+
const turn = event as { type?: string; message?: { content?: unknown }; toolResults?: unknown[] } | undefined;
|
|
166
|
+
if (turn?.type !== "turn_end" || !Array.isArray(turn.message?.content) || !Array.isArray(turn.toolResults)) return "";
|
|
167
|
+
const sections: string[] = [];
|
|
168
|
+
for (const call of turn.message.content) {
|
|
169
|
+
if (call?.type !== "toolCall" || typeof call.id !== "string") continue;
|
|
170
|
+
const args = call.arguments;
|
|
171
|
+
if (!args || typeof args !== "object") continue;
|
|
172
|
+
const eligible = call.name === "bg_wait"
|
|
173
|
+
|| (call.name === "subagent_supervisor" && ["pending", "list", "reply"].includes(args.action))
|
|
174
|
+
|| (call.name === "subagent" && (["status", "resume", "interrupt", "steer", "stop"].includes(args.action)
|
|
175
|
+
|| (args.action === undefined && (typeof args.agent === "string" || typeof args.workflowScript === "string" || typeof args.workflowScriptPath === "string"))));
|
|
176
|
+
if (!eligible) continue;
|
|
177
|
+
const result = turn.toolResults.find((value) => {
|
|
178
|
+
const result = value as { role?: string; toolCallId?: string; toolName?: string };
|
|
179
|
+
return result?.role === "toolResult" && result.toolCallId === call.id && result.toolName === call.name;
|
|
180
|
+
});
|
|
181
|
+
if (result) sections.push(formatToolCall(call.name, args), formatWatchdogReviewMessage(result) ?? "");
|
|
182
|
+
}
|
|
183
|
+
return sections.join("\n\n");
|
|
184
|
+
}
|
package/src/watchdog/types.ts
CHANGED
|
@@ -87,12 +87,14 @@ export interface WatchdogCadenceConfig {
|
|
|
87
87
|
export interface WatchdogEndpointConfig {
|
|
88
88
|
enabled: boolean;
|
|
89
89
|
model?: string;
|
|
90
|
+
fallbackModels?: string[];
|
|
90
91
|
thinking?: string | false;
|
|
91
92
|
}
|
|
92
93
|
|
|
93
94
|
export interface WatchdogChildOverrideConfig {
|
|
94
95
|
enabled?: boolean;
|
|
95
96
|
model?: string;
|
|
97
|
+
fallbackModels?: string[];
|
|
96
98
|
thinking?: string | false;
|
|
97
99
|
cadence?: Partial<WatchdogCadenceConfig>;
|
|
98
100
|
}
|
|
@@ -150,6 +152,8 @@ export interface WatchdogRulesConfig {
|
|
|
150
152
|
|
|
151
153
|
export interface ResolvedWatchdogConfig {
|
|
152
154
|
enabled: boolean;
|
|
155
|
+
/** Main-only, bounded boundary clarification; never enabled for child reviews. */
|
|
156
|
+
clarification: boolean;
|
|
153
157
|
agentEndTimeoutMs: number;
|
|
154
158
|
severityThreshold: WatchdogSeverity;
|
|
155
159
|
maxWarnings: number | null;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { spawnSync } from "node:child_process";
|
|
2
2
|
import * as fs from "node:fs";
|
|
3
3
|
import * as path from "node:path";
|
|
4
|
-
import type { Details,
|
|
4
|
+
import type { Details, WorkflowPreflightLane, WorkflowPreflight } from "../shared/types.ts";
|
|
5
5
|
import { workflowPreflightLaneForRuntimeKey } from "./workflow-preflight.ts";
|
|
6
6
|
|
|
7
7
|
export const WORKFLOW_CHAT_PROGRESS_MODES = ["auto", "off", "live-card"] as const;
|
|
@@ -103,14 +103,14 @@ export interface WorkflowChatProgressRow {
|
|
|
103
103
|
runId?: string;
|
|
104
104
|
durationMs?: number;
|
|
105
105
|
error?: string;
|
|
106
|
-
preflight?:
|
|
106
|
+
preflight?: WorkflowPreflightLane;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
function cleanLabel(value: unknown): string | undefined {
|
|
110
110
|
return typeof value === "string" && value.trim() ? value.trim() : undefined;
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
export function buildWorkflowChatProgressRows(trace: NonNullable<Details["workflow"]>["trace"], preflight?:
|
|
113
|
+
export function buildWorkflowChatProgressRows(trace: NonNullable<Details["workflow"]>["trace"], preflight?: WorkflowPreflight): WorkflowChatProgressRow[] {
|
|
114
114
|
const rows = new Map<string, WorkflowChatProgressRow>();
|
|
115
115
|
for (const entry of trace) {
|
|
116
116
|
if (entry.operation !== "run") continue;
|