@xzzpig/pi-subagents 0.14.0 → 0.15.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.
- package/CHANGELOG.md +239 -0
- package/README.md +7 -6
- package/agents/evidence-auditor.md +34 -0
- package/agents/researcher.md +23 -13
- package/agents/reviewer.md +3 -2
- package/docs/agents.md +55 -136
- package/docs/configuration.md +92 -14
- package/docs/extension-api.md +132 -74
- package/docs/fork-extensions.md +184 -0
- package/docs/missions.md +10 -2
- package/docs/models.md +11 -22
- package/docs/observability.md +63 -11
- package/docs/standalone-background.md +59 -0
- package/docs/tool-reference.md +42 -23
- package/docs/watchdog.md +39 -10
- package/docs/workflows.md +58 -19
- package/index.ts +5 -2
- package/inspector-runner.mjs +2 -2
- package/node_modules/@xzzpig/pi-components/dist/src/transcript.d.ts +13 -3
- package/node_modules/@xzzpig/pi-components/dist/src/transcript.js +18 -6
- package/node_modules/@xzzpig/pi-components/src/transcript.ts +26 -6
- package/package.json +9 -4
- package/prompts/parallel-review.md +1 -1
- package/runner-peer-loader.mjs +24 -0
- package/runner-peer-preload.mjs +36 -0
- package/skills/pi-subagents/SKILL.md +34 -22
- package/skills/pi-subagents/references/constraints-and-recipes.md +3 -2
- package/skills/pi-subagents/references/execution-controls.md +27 -8
- package/skills/pi-subagents/references/management-authoring-rpc.md +2 -2
- package/skills/pi-subagents/references/multi-lane-orchestration.md +3 -1
- package/skills/pi-subagents/references/prompting-and-roles.md +17 -13
- package/skills/pi-subagents/references/review-and-validation.md +3 -3
- package/src/agents/advertised-agent-prompt.ts +94 -0
- package/src/agents/agent-eject.ts +339 -0
- package/src/agents/agent-management.ts +79 -387
- package/src/agents/agent-serializer.ts +6 -3
- package/src/agents/agents.ts +198 -72
- package/src/agents/builtin-names.ts +1 -0
- package/src/agents/chain-serializer.ts +5 -0
- package/src/agents/runtime-agent-registry.ts +7 -6
- package/src/api/agent-management.ts +2 -2
- package/src/api/delegation.ts +4 -0
- package/src/api/preflight.ts +131 -86
- package/src/api/required-child-extensions.ts +6 -0
- package/src/api/shared-types.ts +3 -1
- package/src/api/workflow-resources.ts +6 -0
- package/src/extension/config.ts +14 -37
- package/src/extension/fanout-child.ts +68 -5
- package/src/extension/herdr-pi-bridge.ts +164 -0
- package/src/extension/index.ts +141 -51
- package/src/extension/public-execution.ts +7 -6
- package/src/extension/rpc.ts +8 -21
- package/src/extension/schemas.ts +86 -84
- package/src/extension/tool-description.ts +32 -79
- 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 +4 -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/integrations/pi-web-session-liveness.ts +73 -0
- package/src/intercom/intercom-bridge.ts +50 -8
- package/src/intercom/native-supervisor-channel.ts +142 -115
- package/src/intercom/supervisor-ui.ts +3 -2
- package/src/missions/workflow-state.ts +37 -16
- package/src/policy/authority.ts +4 -0
- package/src/profiles/profiles.ts +12 -6
- package/src/runs/background/active-async-capacity.ts +22 -18
- package/src/runs/background/active-run-index.ts +17 -1
- package/src/runs/background/async-execution.ts +359 -176
- package/src/runs/background/async-job-tracker.ts +41 -7
- package/src/runs/background/async-resume.ts +19 -12
- package/src/runs/background/async-retention.ts +20 -0
- package/src/runs/background/async-status-snapshot.ts +10 -12
- package/src/runs/background/async-status.ts +38 -35
- package/src/runs/background/auto-drain.ts +59 -35
- package/src/runs/background/binary-bootstrap.ts +38 -0
- package/src/runs/background/chain-append.ts +1 -1
- package/src/runs/background/chain-root-attachment.ts +22 -33
- package/src/runs/background/control-channel.ts +78 -44
- package/src/runs/background/fleet-view.ts +30 -2
- package/src/runs/background/notify.ts +193 -19
- package/src/runs/background/owned-process-tree.ts +35 -8
- package/src/runs/background/process-terminal.ts +23 -23
- package/src/runs/background/result-files.ts +8 -4
- package/src/runs/background/result-watcher.ts +19 -2
- package/src/runs/background/retained-nested-route-tracker.ts +96 -0
- package/src/runs/background/run-child-session.ts +118 -41
- package/src/runs/background/run-status.ts +78 -5
- package/src/runs/background/runner-aliases.ts +22 -5
- package/src/runs/background/runner-child-launch.ts +93 -0
- package/src/runs/background/runner-child-sessions.ts +5 -4
- package/src/runs/background/runner-http-dispatcher.ts +119 -0
- package/src/runs/background/scheduled-runs.ts +51 -18
- package/src/runs/background/stale-run-reconciler.ts +38 -12
- package/src/runs/background/steering.ts +20 -2
- package/src/runs/background/subagent-runner.ts +770 -444
- package/src/runs/background/subagent-wait.ts +179 -28
- package/src/runs/background/wait-completions.ts +79 -27
- package/src/runs/background/wait-subscriptions.ts +9 -3
- package/src/runs/background/wait-tool.ts +5 -3
- package/src/runs/foreground/async-steering-action.ts +37 -7
- package/src/runs/foreground/async-stop-action.ts +93 -3
- package/src/runs/foreground/execution.ts +174 -194
- package/src/runs/foreground/foreground-history.ts +5 -2
- package/src/runs/foreground/prompt-audit.ts +12 -6
- package/src/runs/foreground/subagent-executor.ts +915 -411
- 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 +54 -14
- package/src/runs/shared/agent-contract.ts +1 -1
- package/src/runs/shared/async-status-projection.ts +172 -78
- package/src/runs/shared/capability-ceiling.ts +2 -0
- package/src/runs/shared/child-hooks.ts +167 -3
- package/src/runs/shared/child-launch-plan.ts +15 -3
- package/src/runs/shared/child-launch.ts +49 -85
- package/src/runs/shared/child-lifecycle.ts +6 -3
- package/src/runs/shared/child-runtime-config.ts +8 -1
- package/src/runs/shared/child-session.ts +130 -24
- package/src/runs/shared/child-tool-plan.ts +149 -112
- package/src/runs/shared/completion-evidence.ts +2 -2
- package/src/runs/shared/completion-guard.ts +6 -3
- package/src/runs/shared/dynamic-fanout.ts +2 -2
- package/src/runs/shared/effective-system-prompt.ts +33 -0
- package/src/runs/shared/external-cli-contract.ts +11 -1
- package/src/runs/shared/external-cli-preflight.ts +6 -2
- package/src/runs/shared/external-cli-runner.ts +9 -7
- package/src/runs/shared/herdr-connection.ts +134 -0
- package/src/runs/shared/herdr-external-adapters.ts +169 -0
- package/src/runs/shared/herdr-machine.ts +279 -0
- package/src/runs/shared/herdr-pi-protocol.ts +59 -0
- package/src/runs/shared/herdr-placed-run.ts +263 -0
- package/src/runs/shared/host-step-status.ts +11 -11
- package/src/runs/shared/llm-intent-arbiter.ts +40 -21
- package/src/runs/shared/model-resolution-diagnostic.ts +76 -0
- package/src/runs/shared/{model-fallback.ts → model-resolution.ts} +34 -218
- package/src/runs/shared/model-scope.ts +1 -1
- package/src/runs/shared/nested-events.ts +27 -34
- 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 +10 -4
- package/src/runs/shared/pi-spawn.ts +10 -0
- package/src/runs/shared/profile-extensions.ts +134 -0
- package/src/runs/shared/profile-launch-env.ts +113 -0
- package/src/runs/shared/readonly-drain-observation.ts +42 -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/sandbox-profile-guard.ts +34 -0
- package/src/runs/shared/subagent-prompt-runtime.ts +23 -5
- 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-cleanup-plan.ts +6 -3
- package/src/runs/shared/worktree-setup-command.ts +213 -0
- package/src/runs/shared/worktree.ts +437 -214
- package/src/shared/child-cache-retention.ts +43 -0
- package/src/shared/fork-context.ts +15 -72
- package/src/shared/launch-contract.ts +70 -8
- package/src/shared/model-response-aliases.ts +13 -0
- package/src/shared/opencode-session-headers.ts +30 -0
- package/src/shared/permission-profile.ts +14 -0
- package/src/shared/pruned-fork.ts +1 -1
- package/src/shared/required-child-extensions.ts +81 -0
- package/src/shared/sandbox-profile.ts +14 -0
- package/src/shared/settings.ts +5 -2
- package/src/shared/shortcuts.ts +0 -4
- package/src/shared/types.ts +163 -90
- package/src/shared/utils.ts +10 -2
- package/src/shared/watch-strategy.ts +2 -0
- 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 -7
- package/src/slash/subagents-admin.ts +31 -14
- package/src/tui/fleet-status.ts +165 -20
- package/src/tui/fleet.ts +30 -19
- package/src/tui/render.ts +210 -50
- package/src/watchdog/child-status.ts +28 -28
- package/src/watchdog/lsp-diagnostics.ts +1 -1
- package/src/watchdog/model-selection.ts +21 -1
- package/src/watchdog/permission-arbiter.ts +5 -2
- package/src/watchdog/register-child.ts +10 -2
- package/src/watchdog/register-main.ts +39 -35
- package/src/watchdog/render.ts +1 -1
- package/src/watchdog/review.ts +122 -74
- package/src/watchdog/rules.ts +1 -1
- package/src/watchdog/runtime.ts +100 -27
- package/src/watchdog/scope.ts +1 -1
- package/src/watchdog/settings.ts +3 -0
- package/src/watchdog/tool-actions.ts +13 -12
- package/src/watchdog/turn-delta.ts +23 -0
- package/src/watchdog/types.ts +5 -3
- package/src/watchdog/warning-format.ts +1 -1
- package/src/workflows/chat-progress.ts +3 -3
- package/src/workflows/scripted-workflow.ts +349 -26
- package/src/workflows/workflow-checklist.ts +17 -20
- package/src/workflows/workflow-child-summary.ts +57 -8
- package/src/workflows/workflow-preflight.ts +19 -19
- package/src/workflows/workflow-receipt.ts +24 -6
- package/src/workflows/workflow-resources.ts +108 -22
- package/src/workflows/workflow-settlement.ts +3 -0
- package/src/runs/shared/model-exclusions.ts +0 -373
- /package/src/inspectors/{herdr/shell-command.ts → shell-command.ts} +0 -0
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* - `classifyTaskMutationIntent` / `expectsImplementationMutation`: does the
|
|
8
8
|
* task REQUIRE file changes? Consumed by the completion mutation guard,
|
|
9
9
|
* which blocks completion, so its vocabulary is deliberately narrow.
|
|
10
|
+
* Verbs inside filenames and path-like tokens do not count.
|
|
10
11
|
* - `taskMayMutate`: COULD the task plausibly change files? Consumed by
|
|
11
12
|
* acceptance level inference, which only raises evidence gates, so its
|
|
12
13
|
* vocabulary is deliberately broad (any bare write verb).
|
|
@@ -18,16 +19,20 @@
|
|
|
18
19
|
*/
|
|
19
20
|
|
|
20
21
|
const REVIEW_ONLY_PATTERNS = [
|
|
21
|
-
/\
|
|
22
|
+
/\b(?:review|read)[- ]only\b/i,
|
|
23
|
+
/\bno\s+(?:source\s+)?edits?\b/i,
|
|
24
|
+
/\bwithout\s+edits?\b/i,
|
|
22
25
|
/\bsuggest fixes only\b/i,
|
|
23
26
|
/\bonly return findings\b/i,
|
|
24
27
|
/\breturn findings only\b/i,
|
|
25
28
|
];
|
|
26
29
|
|
|
30
|
+
const NO_EDIT_BOUNDARY_ASSERTION_PATTERN = /\bno\s+(?:source\s+)?edits?\s*,\s*(?:commits?|pushes?|merges?|installs?|changes?|writes?)\b/i;
|
|
31
|
+
|
|
27
32
|
const REVIEWER_REQUIRED_EDIT_PATTERNS = [
|
|
28
33
|
/\bmust\s+(?:edit|modify|change|fix|patch|apply|implement)\b/i,
|
|
29
34
|
/\brequired\s+to\s+(?:edit|modify|change|fix|patch|apply|implement)\b/i,
|
|
30
|
-
/(?:^|[
|
|
35
|
+
/(?:^|[.!?:;,\n]\s*)implement\s+(?:the\s+)?(?:approved|requested|specified|file|code|source|fix(?:es)?|changes?)\b/i,
|
|
31
36
|
/\bregardless\s+of\s+findings\b/i,
|
|
32
37
|
/\balways\s+(?:edit|modify|change|fix|patch|apply|implement)\b/i,
|
|
33
38
|
/\bapply\s+(?:the\s+)?fix(?:es)?\s+directly\b/i,
|
|
@@ -40,7 +45,7 @@ const REVIEWER_REQUIRED_EDIT_PATTERNS = [
|
|
|
40
45
|
// being swallowed as the object.
|
|
41
46
|
// Accept serialized line separators too: workflow prompts can carry literal
|
|
42
47
|
// `\\n`/`\\r\\n` between clauses instead of decoded newlines.
|
|
43
|
-
const NO_EDIT_PROHIBITION_PATTERN = /(?:\b|\\(?:r\\n|n))(?:do not|don't|must not)\s+(?:edit|modify|write(?:\s+to)?|touch|change)\b((?:(?!\b(?:but|and|then)\b|\\(?:r\\n|n))[^.;,:!?\n–—-])*)/gi;
|
|
48
|
+
const NO_EDIT_PROHIBITION_PATTERN = /(?:\b|\\(?:r\\n|n))(?:do not|don't|must not)\s+(?:edit|modify|write(?:\s+to)?|touch|change|implement)\b((?:(?!\b(?:but|and|then)\b|\\(?:r\\n|n))[^.;,:!?\n–—-])*)/gi;
|
|
44
49
|
const COORDINATED_NO_EDIT_PROHIBITION_PATTERN = /(?:\b|\\(?:r\\n|n))(?:do not|don't|must not)\s+((?=(?:(?!\\(?:r\\n|n))[^.;:!?\n–—-])*\b(?:and|or)\s+(?:edit|modify|write(?:\s+to)?|touch|change)\b)(?:(?!\\(?:r\\n|n))[^.;:!?\n–—-])*?\b(?:and|or)\s+(?:edit|modify|write(?:\s+to)?|touch|change)\b(?:(?!\b(?:but|and|then)\b|\\(?:r\\n|n))[^.;,:!?\n–—-])*)/gi;
|
|
45
50
|
|
|
46
51
|
/** Objects of a no-edit prohibition that mean "the codebase in general" rather than a named scope. */
|
|
@@ -85,13 +90,25 @@ const RESEARCH_AGENT_PATTERNS = [
|
|
|
85
90
|
// CLI flags like "--fix" and genuine clause-level dashes like "branch—fix it"),
|
|
86
91
|
// strip the known severity compounds (must|should|needs + dash + verb) from the
|
|
87
92
|
// task text before matching. Dash coverage: ASCII hyphen + U+2010..U+2015.
|
|
88
|
-
const SEVERITY_COMPOUND_PATTERN = /\b(?:must|should|needs)[
|
|
93
|
+
const SEVERITY_COMPOUND_PATTERN = /\b(?:must|should|needs)[-\u2010-\u2015](?:fix|edit|update|add|remove|replace|create|apply|make|do|implement|modify|delete|patch)\b/gi;
|
|
89
94
|
|
|
90
95
|
function stripSeverityCompounds(task: string): string {
|
|
91
96
|
return task.replace(SEVERITY_COMPOUND_PATTERN, " ");
|
|
92
97
|
}
|
|
93
98
|
export { stripSeverityCompounds };
|
|
94
99
|
|
|
100
|
+
// Quoted categories in a finding-classification request describe fixes, not
|
|
101
|
+
// instructions to perform them. Strip only that request, leaving sibling
|
|
102
|
+
// imperatives (including another "must fix") subject to the normal guards.
|
|
103
|
+
const FINDING_CLASSIFICATION_PATTERN = /\b(?:classify|categorize|weigh)\s+(?:(?:the|remaining)\s+)*(?:findings?|items?|issues?)\s+as\s+["“]must\s+fix\s+before\s+[^"”\n]+["”]\s+(?:vs\.?|versus)\s+["“]must\s+fix\s+before\s+[^"”\n]+["”]/gi;
|
|
104
|
+
|
|
105
|
+
const PATH_LIKE_TOKEN_PATTERN = /[^\s]+[/\\][^\s]+|[^\s/\\]+\.[A-Za-z][A-Za-z0-9]{0,9}\b/g;
|
|
106
|
+
const PATH_INTERNAL_IMPLEMENTATION_VERB = /\b(?:implement|edit|modify|refactor|delete|update|add|remove|replace|create)\b/i;
|
|
107
|
+
|
|
108
|
+
function stripPathLikeTokens(task: string): string {
|
|
109
|
+
return task.replace(PATH_LIKE_TOKEN_PATTERN, (token) => (PATH_INTERNAL_IMPLEMENTATION_VERB.test(token) ? " " : token));
|
|
110
|
+
}
|
|
111
|
+
|
|
95
112
|
const FIX_OR_PATCH_IMPLEMENTATION_PATTERN = /\b(?:fix|patch)\s+(?:(?:it|this|that|them|each|any|all|these|those)\b|(?:(?:a|an|the|any|all)\s+)?(?:(?:failing|failed|broken|flaky|red|cold|start|current|existing|reported|approved|known|regression|unit|integration|e2e|source|typescript|type-?script|ts|type-?check|compiler)\s+)*(?:bug|defect|issues?|problems?|failures?|regressions?|tests?|errors?|items?|typos?|code|source|implementation|component|function|module|class|method|logic|file|files|readme|docs?|changelog|package\.json|config|manifest|extension|prompt|command|lint(?:ing)?|build|ci|type-?check|type\s+checking)\b)/i;
|
|
96
113
|
|
|
97
114
|
const WORKER_IMPLEMENTATION_PATTERNS = [
|
|
@@ -103,12 +120,18 @@ const WORKER_IMPLEMENTATION_PATTERNS = [
|
|
|
103
120
|
/\bdo those fixes\b/i,
|
|
104
121
|
];
|
|
105
122
|
|
|
106
|
-
const
|
|
123
|
+
const FOLLOW_ON_IMPLEMENTATION_PATTERN = /(?:^|[.!?:;,\n])\s*(?:fix|patch|update|add|remove|replace|create|delete)\s+(?:(?:the|a|an|this|that|these|those|requested|specified|current|existing|approved|your|our)\s+)(?!(?:report|summary|findings?|analysis|recommendations?|answer|response|proposal|plan|issue|bug report)\b)[a-z][\w./-]*/i;
|
|
124
|
+
const ADVISORY_INFINITIVE_PATTERN = /\b(?:explain|recommend|describe)\s+how\s+to\s+(?:fix|patch|update|add|remove|replace|create|delete|implement|edit|modify|refactor)\b/i;
|
|
125
|
+
const EXPLICIT_IMPLEMENTATION_PATTERNS = [
|
|
107
126
|
/\b(?:implement|edit|modify|refactor)\b/i,
|
|
108
|
-
FIX_OR_PATCH_IMPLEMENTATION_PATTERN,
|
|
109
127
|
/\bapply\s+(?:the\s+)?(?:(?:suggested|proposed|recommended)\s+)?(?:changes?|fix(?:es)?|patch)\b/i,
|
|
110
128
|
/\bmake\s+(?:the\s+)?changes\b/i,
|
|
111
129
|
/\bdo those fixes\b/i,
|
|
130
|
+
];
|
|
131
|
+
|
|
132
|
+
const GENERAL_IMPLEMENTATION_PATTERNS = [
|
|
133
|
+
...EXPLICIT_IMPLEMENTATION_PATTERNS,
|
|
134
|
+
FIX_OR_PATCH_IMPLEMENTATION_PATTERN,
|
|
112
135
|
/\b(?:update|add|remove|replace|delete|create)\s+(?:the\s+)?(?:file|files|code|source|implementation|test|tests|component|function|module|class|method|logic|import|imports|readme|docs?|changelog|package\.json|config|manifest|extension|prompt|command)\b/i,
|
|
113
136
|
];
|
|
114
137
|
|
|
@@ -141,10 +164,13 @@ interface NoEditProhibitionAnalysis {
|
|
|
141
164
|
}
|
|
142
165
|
|
|
143
166
|
function analyzeNoEditProhibitions(taskText: string): NoEditProhibitionAnalysis {
|
|
167
|
+
const readOnlyBoundary = NO_EDIT_BOUNDARY_ASSERTION_PATTERN.test(taskText);
|
|
144
168
|
let present = REVIEW_ONLY_PATTERNS.some((pattern) => pattern.test(taskText))
|
|
145
|
-
|| NO_TOOL_INTENT_PATTERNS.some((pattern) => pattern.test(taskText))
|
|
146
|
-
|
|
147
|
-
let
|
|
169
|
+
|| NO_TOOL_INTENT_PATTERNS.some((pattern) => pattern.test(taskText))
|
|
170
|
+
|| readOnlyBoundary;
|
|
171
|
+
let blanket = false;
|
|
172
|
+
let strippedText = stripPatterns(taskText, [...REVIEW_ONLY_PATTERNS, ...NO_TOOL_INTENT_PATTERNS, ADVISORY_INFINITIVE_PATTERN]);
|
|
173
|
+
if (readOnlyBoundary) strippedText = stripPatterns(strippedText, [NO_EDIT_BOUNDARY_ASSERTION_PATTERN]);
|
|
148
174
|
const stripNoEditProhibition = (match: string, object: string, offset: number, source: string): string => {
|
|
149
175
|
present = true;
|
|
150
176
|
if (GENERIC_PROHIBITION_OBJECT.test(object) && !hasScopedProhibitionContinuation(source.slice(offset + match.length))) blanket = true;
|
|
@@ -172,16 +198,23 @@ function hasImplementationIntent(agent: string, taskText: string): boolean {
|
|
|
172
198
|
}
|
|
173
199
|
|
|
174
200
|
export function classifyTaskMutationIntent(agent: string, task: string): TaskMutationIntent {
|
|
175
|
-
const taskText = stripSeverityCompounds(stripFrameworkInstructions(task));
|
|
201
|
+
const taskText = stripPatterns(stripSeverityCompounds(stripFrameworkInstructions(task)), [FINDING_CLASSIFICATION_PATTERN]);
|
|
176
202
|
const taskTextWithoutScopedConstraints = stripPatterns(taskText, SCOPED_NO_EDIT_CONSTRAINT_PATTERNS);
|
|
177
203
|
const prohibitions = analyzeNoEditProhibitions(taskTextWithoutScopedConstraints);
|
|
178
204
|
if (prohibitions.present) {
|
|
179
205
|
if (prohibitions.blanket) return { kind: "read-only" };
|
|
180
|
-
|
|
206
|
+
const remaining = stripPathLikeTokens(prohibitions.strippedText);
|
|
207
|
+
if (isReviewerStyleAgent(agent)) {
|
|
208
|
+
return hasImplementationIntent(agent, remaining) ? { kind: "implementation" } : { kind: "read-only" };
|
|
209
|
+
}
|
|
210
|
+
return EXPLICIT_IMPLEMENTATION_PATTERNS.some((pattern) => pattern.test(remaining))
|
|
211
|
+
|| FOLLOW_ON_IMPLEMENTATION_PATTERN.test(remaining)
|
|
212
|
+
? { kind: "implementation" }
|
|
213
|
+
: { kind: "read-only" };
|
|
181
214
|
}
|
|
182
215
|
|
|
183
216
|
if (RESEARCH_AGENT_PATTERNS.some((pattern) => pattern.test(agent))) return { kind: "read-only" };
|
|
184
|
-
if (hasImplementationIntent(agent, taskText)) return { kind: "implementation" };
|
|
217
|
+
if (hasImplementationIntent(agent, stripPathLikeTokens(taskText))) return { kind: "implementation" };
|
|
185
218
|
if (isReviewerStyleAgent(agent)) return { kind: "read-only" };
|
|
186
219
|
return taskHasReadOnlyDeliverable(taskTextWithoutScopedConstraints) ? { kind: "read-only" } : { kind: "unknown" };
|
|
187
220
|
}
|
|
@@ -204,7 +237,7 @@ const MAY_MUTATE_VERB_PATTERN = /\b(?:fix|implement|update|write|edit|modify|mig
|
|
|
204
237
|
* does.
|
|
205
238
|
*/
|
|
206
239
|
export function taskMayMutate(task: string): boolean {
|
|
207
|
-
const taskText = stripPatterns(stripSeverityCompounds(stripFrameworkInstructions(task)), SCOPED_NO_EDIT_CONSTRAINT_PATTERNS);
|
|
240
|
+
const taskText = stripPatterns(stripSeverityCompounds(stripFrameworkInstructions(task)), [FINDING_CLASSIFICATION_PATTERN, ...SCOPED_NO_EDIT_CONSTRAINT_PATTERNS]);
|
|
208
241
|
const prohibitions = analyzeNoEditProhibitions(taskText);
|
|
209
242
|
if (prohibitions.blanket) return false;
|
|
210
243
|
return MAY_MUTATE_VERB_PATTERN.test(stripPatterns(prohibitions.strippedText, READ_ONLY_DELIVERABLE_PATTERNS));
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { AsyncStatus, SubagentState } from "../../shared/types.ts";
|
|
2
|
+
|
|
3
|
+
/** Projection-only guidance, not a control route or proof of current child liveness. */
|
|
4
|
+
export function workflowAsyncChildSteeringGuidance(status: AsyncStatus, state?: SubagentState): string[] {
|
|
5
|
+
if (status.mode !== "workflow" || (status.state !== "running" && status.state !== "queued")
|
|
6
|
+
|| !state?.currentSessionId || status.sessionId !== state.currentSessionId
|
|
7
|
+
|| !state.workflowControllers?.has(status.runId)) return [];
|
|
8
|
+
const ids = new Set((status.steps ?? []).flatMap((step) =>
|
|
9
|
+
step.async === true && step.status === "running"
|
|
10
|
+
&& step.runner?.type !== "external-cli" && step.runner?.type !== "external-job"
|
|
11
|
+
&& typeof step.runId === "string" && /^[A-Za-z0-9_-]+$/.test(step.runId) && step.runId !== status.runId
|
|
12
|
+
? [step.runId] : []));
|
|
13
|
+
if (ids.size === 0) return [];
|
|
14
|
+
return [
|
|
15
|
+
"Async children recorded as running; direct steering rechecks controls. Choose an exact child ID (queued does not mean consumed):",
|
|
16
|
+
...[...ids].map((id) => ` subagent({ action: "steer", id: "${id}", mode: "follow_up", message: "..." })`),
|
|
17
|
+
];
|
|
18
|
+
}
|
|
@@ -15,6 +15,7 @@ import type {
|
|
|
15
15
|
} from "../../shared/types.ts";
|
|
16
16
|
import { getAgentDir } from "../../shared/utils.ts";
|
|
17
17
|
import { isTerminalParallelHandoffChildStatus } from "./parallel-handoff.ts";
|
|
18
|
+
import { MACHINE_DIFF_OPTIONS, validateWorktreePatchRepresentsCurrentWorktree } from "./worktree.ts";
|
|
18
19
|
|
|
19
20
|
export const WORKTREE_CLEANUP_PLAN_VERSION = 1 as const;
|
|
20
21
|
export const WORKTREE_CLEANUP_PLAN_TTL_MS = 30 * 60 * 1000;
|
|
@@ -572,7 +573,7 @@ function resolveBranchTip(repoRoot: string, branch: string): { value?: string; e
|
|
|
572
573
|
return { value: result.stdout.trim() };
|
|
573
574
|
}
|
|
574
575
|
|
|
575
|
-
function isPatchCaptured(record: ManifestMetadataRecord, worktreePath: string): { path?: string; error?: string } {
|
|
576
|
+
function isPatchCaptured(record: ManifestMetadataRecord, worktreePath: string, baseCommit: string): { path?: string; error?: string } {
|
|
576
577
|
const patchPath = metadataPatchPath(record);
|
|
577
578
|
if (!patchPath || record.child.patch?.error !== undefined || record.child.patch?.changed !== true) return {};
|
|
578
579
|
const inspection = inspectPath(patchPath);
|
|
@@ -587,6 +588,8 @@ function isPatchCaptured(record: ManifestMetadataRecord, worktreePath: string):
|
|
|
587
588
|
if (!patchStat.isFile()) return { error: "captured handoff patch is not a file" };
|
|
588
589
|
if (pathInside(worktreePath, inspection.realpath)) return { error: "durable handoff patch lives inside the worktree" };
|
|
589
590
|
if (patchStat.size <= 0) return { error: "captured handoff patch is empty" };
|
|
591
|
+
const validationError = validateWorktreePatchRepresentsCurrentWorktree(worktreePath, baseCommit, patchPath);
|
|
592
|
+
if (validationError) return { error: `captured handoff patch failed validation: ${validationError}` };
|
|
590
593
|
return { path: patchPath };
|
|
591
594
|
}
|
|
592
595
|
|
|
@@ -665,14 +668,14 @@ function buildManagedEntry(input: {
|
|
|
665
668
|
entry.preconditions.statusDigest = status.digest;
|
|
666
669
|
if (status.output && status.output.trim()) return blockedEntry(entry, "dirty", "keep", "worktree has uncommitted or untracked changes");
|
|
667
670
|
|
|
668
|
-
const diff = runGit(worktreePath, ["diff", "--quiet", resolvedBase.value, "--"]);
|
|
671
|
+
const diff = runGit(worktreePath, ["diff", "--quiet", ...MACHINE_DIFF_OPTIONS, resolvedBase.value, "--"]);
|
|
669
672
|
if (diff.status !== 0 && diff.status !== 1) return blockedEntry(entry, "unknown", "unknown", `git diff safety check failed: ${gitFailure(diff, "git diff")}`);
|
|
670
673
|
const ancestor = runGit(repoRoot, ["merge-base", "--is-ancestor", git.head, targetHead]);
|
|
671
674
|
if (ancestor.status !== 0 && ancestor.status !== 1) return blockedEntry(entry, "unknown", "unknown", `local merge safety check failed: ${gitFailure(ancestor, "git merge-base --is-ancestor")}`);
|
|
672
675
|
const branchTipIsAncestor = ancestor.status === 0;
|
|
673
676
|
let divergenceSafe = diff.status === 0;
|
|
674
677
|
if (!divergenceSafe) {
|
|
675
|
-
const captured = isPatchCaptured(record, worktreePath);
|
|
678
|
+
const captured = isPatchCaptured(record, worktreePath, resolvedBase.value);
|
|
676
679
|
if (captured.error) return blockedEntry(entry, "ineligible", "keep", captured.error);
|
|
677
680
|
if (captured.path) {
|
|
678
681
|
entry.patchPath = captured.path;
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { createOwnedProcessTreeController } from "../background/owned-process-tree.ts";
|
|
3
|
+
import type { ProcessTreeTerminal } from "../../shared/types.ts";
|
|
4
|
+
|
|
5
|
+
function terminateCommandTree(pid: number, controller: ReturnType<typeof createOwnedProcessTreeController>): Promise<ProcessTreeTerminal> {
|
|
6
|
+
if (process.platform !== "win32") return controller.terminate();
|
|
7
|
+
return new Promise((resolve) => {
|
|
8
|
+
let settled = false;
|
|
9
|
+
const fallback = () => {
|
|
10
|
+
if (settled) return;
|
|
11
|
+
settled = true;
|
|
12
|
+
void controller.terminate().then(resolve);
|
|
13
|
+
};
|
|
14
|
+
const cleanup = spawn("taskkill", ["/PID", String(pid), "/T", "/F"], { stdio: "ignore", windowsHide: true });
|
|
15
|
+
cleanup.once("error", fallback);
|
|
16
|
+
cleanup.once("close", (status) => {
|
|
17
|
+
if (settled) return;
|
|
18
|
+
if (status !== 0) return fallback();
|
|
19
|
+
settled = true;
|
|
20
|
+
resolve({ state: "observed", mechanism: "windows-taskkill", pid, verifiedAt: Date.now() });
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface SetupCommandOptions {
|
|
26
|
+
cwd?: string;
|
|
27
|
+
env?: NodeJS.ProcessEnv;
|
|
28
|
+
input?: string;
|
|
29
|
+
/** Worktrunk uses 128 KiB; Git and hooks use spawnSync's 1 MiB default. */
|
|
30
|
+
maxBuffer?: number;
|
|
31
|
+
signal?: AbortSignal;
|
|
32
|
+
deadlineAt?: number;
|
|
33
|
+
/** Only the existing configured setup-hook timeout, not a new Git budget. */
|
|
34
|
+
hookTimeoutMs?: number;
|
|
35
|
+
/** Read-only probes may define negative answers as completed commands. */
|
|
36
|
+
acceptedExitCodes?: readonly number[];
|
|
37
|
+
onSpawn?: (process: { pid: number; processGroupId?: number }) => void;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface SetupCommandResult {
|
|
41
|
+
stdout: string;
|
|
42
|
+
stdoutBuffer: Buffer;
|
|
43
|
+
stderr: string;
|
|
44
|
+
status: number | null;
|
|
45
|
+
signal: NodeJS.Signals | null;
|
|
46
|
+
error?: Error;
|
|
47
|
+
pid?: number;
|
|
48
|
+
processGroupId?: number;
|
|
49
|
+
/** Absent on normal completion: trusted command completion is NOT tree proof. */
|
|
50
|
+
processTree?: ProcessTreeTerminal;
|
|
51
|
+
outputIncomplete: boolean;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function commandError(message: string, code: string): NodeJS.ErrnoException {
|
|
55
|
+
return Object.assign(new Error(message), { code });
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Setup I/O only. Commands must await their descendants before reporting success.
|
|
60
|
+
* Exit 0 + natural close + complete output still requires caller JSON/path validation.
|
|
61
|
+
* Invalid output is NOT accepted completion: retain unknown ownership, never signal
|
|
62
|
+
* this completed command's PID later. Callers own compensation and admission.
|
|
63
|
+
*/
|
|
64
|
+
export async function runSetupCommand(
|
|
65
|
+
command: string,
|
|
66
|
+
args: string[],
|
|
67
|
+
options: SetupCommandOptions,
|
|
68
|
+
): Promise<SetupCommandResult> {
|
|
69
|
+
const result: SetupCommandResult = {
|
|
70
|
+
stdout: "", stdoutBuffer: Buffer.alloc(0), stderr: "", status: null, signal: null, outputIncomplete: false,
|
|
71
|
+
};
|
|
72
|
+
const maxBuffer = options.maxBuffer ?? 1024 * 1024;
|
|
73
|
+
if (!Number.isSafeInteger(maxBuffer) || maxBuffer <= 0) throw new Error("Invalid setup command maxBuffer");
|
|
74
|
+
if (options.deadlineAt !== undefined && !Number.isFinite(options.deadlineAt)) throw new Error("Invalid setup deadline");
|
|
75
|
+
if (options.hookTimeoutMs !== undefined && (!Number.isSafeInteger(options.hookTimeoutMs) || options.hookTimeoutMs <= 0)) {
|
|
76
|
+
throw new Error("Invalid setup hook timeout");
|
|
77
|
+
}
|
|
78
|
+
const cancellation = (): Error | undefined => {
|
|
79
|
+
if (options.signal?.aborted) return commandError("Worktree setup aborted", "ABORT_ERR");
|
|
80
|
+
if (options.deadlineAt !== undefined && Date.now() >= options.deadlineAt) {
|
|
81
|
+
return commandError("Worktree setup deadline exceeded", "ETIMEDOUT");
|
|
82
|
+
}
|
|
83
|
+
return undefined;
|
|
84
|
+
};
|
|
85
|
+
result.error = cancellation();
|
|
86
|
+
if (result.error) return result;
|
|
87
|
+
|
|
88
|
+
let child;
|
|
89
|
+
try {
|
|
90
|
+
child = spawn(command, args, {
|
|
91
|
+
cwd: options.cwd,
|
|
92
|
+
env: options.env ? { ...process.env, ...options.env } : process.env,
|
|
93
|
+
stdio: "pipe", shell: false, windowsHide: true,
|
|
94
|
+
// Isolated owned POSIX group, never unref'd or fire-and-forget.
|
|
95
|
+
detached: process.platform !== "win32",
|
|
96
|
+
});
|
|
97
|
+
} catch (error) {
|
|
98
|
+
result.error = error instanceof Error ? error : new Error(String(error));
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
result.pid = child.pid;
|
|
102
|
+
if (child.pid !== undefined && process.platform !== "win32") result.processGroupId = child.pid;
|
|
103
|
+
const tree = child.pid === undefined ? undefined : createOwnedProcessTreeController(child.pid);
|
|
104
|
+
let termination: Promise<ProcessTreeTerminal> | undefined;
|
|
105
|
+
let directSettled = false;
|
|
106
|
+
const releaseUnknownIO = () => {
|
|
107
|
+
if (!directSettled || result.processTree?.state !== "unknown") return;
|
|
108
|
+
const detail = result.processTree.diagnostic ? `: ${result.processTree.diagnostic}` : "";
|
|
109
|
+
result.error = commandError(`Worktree setup process tree settlement is unverified${detail}`, "PROCESS_TREE_UNVERIFIED");
|
|
110
|
+
result.outputIncomplete = true;
|
|
111
|
+
// Only local I/O is released; unknown descendant ownership remains retained.
|
|
112
|
+
child.stdin.destroy();
|
|
113
|
+
child.stdout.destroy();
|
|
114
|
+
child.stderr.destroy();
|
|
115
|
+
};
|
|
116
|
+
const terminate = () => {
|
|
117
|
+
if (termination || !tree) return;
|
|
118
|
+
if (directSettled) {
|
|
119
|
+
result.processTree = {
|
|
120
|
+
state: "unknown", reason: "verification-failed",
|
|
121
|
+
diagnostic: "Command exited before termination began; no longer safe to signal its recorded PID.",
|
|
122
|
+
};
|
|
123
|
+
releaseUnknownIO();
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
termination = terminateCommandTree(result.pid!, tree).then((proof) => {
|
|
127
|
+
result.processTree = proof;
|
|
128
|
+
releaseUnknownIO();
|
|
129
|
+
return proof;
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
const fail = (error: Error) => {
|
|
133
|
+
result.error ??= error;
|
|
134
|
+
terminate();
|
|
135
|
+
};
|
|
136
|
+
const onAbort = () => fail(commandError("Worktree setup aborted", "ABORT_ERR"));
|
|
137
|
+
const stdout: Buffer[] = [];
|
|
138
|
+
const stderr: Buffer[] = [];
|
|
139
|
+
let capturedBytes = 0;
|
|
140
|
+
const capture = (chunks: Buffer[], chunk: Buffer) => {
|
|
141
|
+
const remaining = maxBuffer - capturedBytes;
|
|
142
|
+
if (remaining > 0) {
|
|
143
|
+
const saved = Buffer.from(chunk.subarray(0, remaining));
|
|
144
|
+
chunks.push(saved);
|
|
145
|
+
capturedBytes += saved.length;
|
|
146
|
+
}
|
|
147
|
+
if (chunk.length > remaining) {
|
|
148
|
+
result.outputIncomplete = true;
|
|
149
|
+
fail(commandError("Worktree setup command output exceeds maxBuffer", "ENOBUFS"));
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
const onStdout = (chunk: Buffer) => capture(stdout, chunk);
|
|
153
|
+
const onStderr = (chunk: Buffer) => capture(stderr, chunk);
|
|
154
|
+
child.stdout.on("data", onStdout);
|
|
155
|
+
child.stderr.on("data", onStderr);
|
|
156
|
+
child.stdin.on("error", fail);
|
|
157
|
+
const close = new Promise<void>((resolve) => child.once("close", () => resolve()));
|
|
158
|
+
const directExit = new Promise<void>((resolve) => {
|
|
159
|
+
child.once("exit", (status, signal) => {
|
|
160
|
+
directSettled = true;
|
|
161
|
+
result.status = status;
|
|
162
|
+
result.signal = signal;
|
|
163
|
+
if (status === null || !(options.acceptedExitCodes ?? [0]).includes(status)) terminate();
|
|
164
|
+
releaseUnknownIO();
|
|
165
|
+
resolve();
|
|
166
|
+
});
|
|
167
|
+
child.once("error", (error) => {
|
|
168
|
+
fail(error);
|
|
169
|
+
// A failed spawn has no direct process to await. Other errors do not prove exit.
|
|
170
|
+
if (child.pid === undefined) {
|
|
171
|
+
directSettled = true;
|
|
172
|
+
resolve();
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
177
|
+
const deadlineAt = Math.min(options.deadlineAt ?? Infinity,
|
|
178
|
+
options.hookTimeoutMs === undefined ? Infinity : Date.now() + options.hookTimeoutMs);
|
|
179
|
+
const armDeadline = () => {
|
|
180
|
+
if (deadlineAt === Infinity) return;
|
|
181
|
+
const remaining = deadlineAt - Date.now();
|
|
182
|
+
if (remaining <= 0) fail(commandError("Worktree setup command timed out", "ETIMEDOUT"));
|
|
183
|
+
else timer = setTimeout(armDeadline, Math.min(remaining, 2 ** 31 - 1));
|
|
184
|
+
};
|
|
185
|
+
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
186
|
+
try {
|
|
187
|
+
armDeadline();
|
|
188
|
+
if (options.signal?.aborted) onAbort();
|
|
189
|
+
if (child.pid !== undefined) {
|
|
190
|
+
try { options.onSpawn?.({ pid: child.pid, processGroupId: result.processGroupId }); }
|
|
191
|
+
catch (error) { fail(error instanceof Error ? error : new Error(String(error))); }
|
|
192
|
+
}
|
|
193
|
+
child.stdin.end(options.input);
|
|
194
|
+
await directExit;
|
|
195
|
+
if (termination) result.processTree = await termination;
|
|
196
|
+
releaseUnknownIO();
|
|
197
|
+
await close;
|
|
198
|
+
// Abort/overflow may arrive while draining stdio after direct exit.
|
|
199
|
+
if (termination) result.processTree = await termination;
|
|
200
|
+
const cancelled = cancellation();
|
|
201
|
+
if (cancelled) fail(cancelled);
|
|
202
|
+
result.stdoutBuffer = Buffer.concat(stdout);
|
|
203
|
+
result.stdout = result.stdoutBuffer.toString("utf8");
|
|
204
|
+
result.stderr = Buffer.concat(stderr).toString("utf8");
|
|
205
|
+
return result;
|
|
206
|
+
} finally {
|
|
207
|
+
if (timer) clearTimeout(timer);
|
|
208
|
+
options.signal?.removeEventListener("abort", onAbort);
|
|
209
|
+
child.stdout.removeListener("data", onStdout);
|
|
210
|
+
child.stderr.removeListener("data", onStderr);
|
|
211
|
+
child.stdin.removeListener("error", fail);
|
|
212
|
+
}
|
|
213
|
+
}
|