@xzzpig/pi-subagents 0.15.1 → 0.18.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 +178 -1
- package/README.md +5 -3
- package/agents/claude-code-writer.md +1 -0
- package/agents/codex-exec-writer.md +1 -0
- package/agents/cursor-agent-writer.md +1 -0
- package/agents/reviewer.md +3 -2
- package/agents/worker.md +3 -2
- package/docs/agents.md +19 -12
- package/docs/configuration.md +21 -3
- package/docs/extension-api.md +70 -4
- package/docs/fork-extensions.md +23 -15
- package/docs/models.md +5 -3
- package/docs/observability.md +23 -13
- package/docs/standalone-background.md +4 -4
- package/docs/tool-reference.md +40 -19
- package/docs/watchdog.md +2 -0
- package/docs/workflows.md +57 -3
- package/inspector-runner.mjs +1 -1
- package/package.json +14 -8
- package/prompts/council.md +6 -3
- package/runner-peer-loader.mjs +4 -7
- package/runner-peer-preload.mjs +5 -7
- package/skills/pi-subagents/SKILL.md +1 -0
- package/skills/pi-subagents/references/constraints-and-recipes.md +5 -2
- package/skills/pi-subagents/references/execution-controls.md +6 -4
- package/skills/pi-subagents/references/management-authoring-rpc.md +3 -3
- package/skills/pi-subagents/references/multi-lane-orchestration.md +8 -0
- package/skills/pi-subagents/references/prompting-and-roles.md +16 -15
- package/src/agents/agent-eject.ts +3 -3
- package/src/agents/agent-management.ts +61 -52
- package/src/agents/agent-memory.ts +90 -3
- package/src/agents/agent-serializer.ts +4 -4
- package/src/agents/agents.ts +125 -51
- package/src/agents/global-npm-root.ts +58 -0
- package/src/agents/proactive-skills.ts +4 -1
- package/src/agents/runtime-agent-registry.ts +14 -11
- package/src/agents/skills.ts +42 -9
- package/src/api/delegation.ts +15 -0
- package/src/api/inspectors.ts +27 -0
- package/src/api/preflight.ts +60 -60
- package/src/extension/doctor.ts +9 -4
- package/src/extension/fanout-child.ts +8 -0
- package/src/extension/index.ts +101 -48
- package/src/extension/rpc.ts +10 -1
- package/src/extension/schemas.ts +12 -6
- package/src/extension/subagent-guide.ts +12 -4
- package/src/extension/tool-activation.ts +197 -0
- package/src/extension/tool-description.ts +1 -1
- package/src/inspectors/ghostty/plugin.ts +13 -1
- package/src/inspectors/plugins.ts +70 -3
- package/src/intercom/intercom-bridge.ts +2 -0
- package/src/intercom/native-supervisor-channel.ts +22 -15
- package/src/intercom/result-intercom.ts +4 -0
- package/src/runs/background/active-async-capacity.ts +3 -25
- package/src/runs/background/async-execution.ts +100 -140
- package/src/runs/background/async-job-tracker.ts +28 -34
- package/src/runs/background/async-resume.ts +16 -8
- package/src/runs/background/async-status.ts +2 -0
- package/src/runs/background/binary-bootstrap.ts +34 -6
- package/src/runs/background/fleet-view.ts +51 -7
- package/src/runs/background/notify.ts +93 -7
- package/src/runs/background/pid-namespace.ts +18 -0
- package/src/runs/background/process-terminal-candidate.ts +98 -0
- package/src/runs/background/process-terminal.ts +17 -96
- package/src/runs/background/result-watcher.ts +1 -1
- package/src/runs/background/retained-children.ts +3 -2
- package/src/runs/background/run-child-session.ts +16 -5
- package/src/runs/background/run-id-resolver.ts +10 -5
- package/src/runs/background/run-status.ts +10 -4
- package/src/runs/background/runner-aliases.ts +25 -15
- package/src/runs/background/runner-child-launch.ts +1 -2
- package/src/runs/background/runner-startup-failure.ts +56 -0
- package/src/runs/background/stale-run-reconciler.ts +19 -3
- package/src/runs/background/subagent-runner-bootstrap.ts +276 -0
- package/src/runs/background/subagent-runner.ts +96 -287
- package/src/runs/background/wait-tool.ts +2 -0
- package/src/runs/background/workflow-terminal-proof.ts +68 -0
- package/src/runs/foreground/execution.ts +217 -250
- package/src/runs/foreground/prompt-audit.ts +3 -9
- package/src/runs/foreground/subagent-executor.ts +377 -119
- package/src/runs/shared/acceptance.ts +167 -68
- package/src/runs/shared/capability-ceiling.ts +4 -1
- package/src/runs/shared/child-hooks.ts +1 -16
- package/src/runs/shared/child-launch.ts +22 -14
- package/src/runs/shared/child-runtime-config.ts +3 -0
- package/src/runs/shared/child-session.ts +52 -2
- package/src/runs/shared/child-tool-plan.ts +23 -113
- package/src/runs/shared/dynamic-fanout.ts +1 -1
- package/src/runs/shared/external-cli-runner.ts +3 -1
- package/src/runs/shared/external-job-bridge.ts +54 -0
- package/src/runs/shared/git-environment.ts +29 -0
- package/src/runs/shared/mcp-config-sources.ts +3 -0
- package/src/runs/shared/mcp-direct-tool-allowlist.ts +1 -1
- package/src/runs/shared/mcp-direct-tool-grant.ts +22 -6
- package/src/runs/shared/model-resolution.ts +6 -1
- package/src/runs/shared/nested-events.ts +67 -55
- package/src/runs/shared/orca-progress-tabs.ts +3 -2
- package/src/runs/shared/parallel-utils.ts +2 -1
- package/src/runs/shared/pi-spawn.ts +92 -6
- package/src/runs/shared/profile-launch-env.ts +10 -2
- package/src/runs/shared/single-output.ts +11 -2
- package/src/runs/shared/structured-output.ts +227 -7
- package/src/runs/shared/subagent-control.ts +2 -16
- package/src/runs/shared/subagent-prompt-runtime.ts +27 -5
- package/src/runs/shared/tool-availability.ts +2 -2
- package/src/runs/shared/tool-budget.ts +21 -0
- package/src/runs/shared/usage-reconciliation.ts +73 -0
- package/src/runs/shared/worktree.ts +35 -8
- package/src/shared/child-session-name.ts +4 -2
- package/src/shared/fork-context.ts +11 -4
- package/src/shared/launch-contract.ts +1 -1
- package/src/shared/pruned-fork.ts +69 -56
- package/src/shared/types.ts +52 -16
- package/src/slash/delegation-adapters.ts +25 -1
- package/src/slash/prompt-template-bridge.ts +16 -1
- package/src/slash/prompt-workflows.ts +12 -1
- package/src/slash/slash-commands.ts +7 -241
- package/src/slash/subagent-cost.ts +313 -0
- package/src/slash/subagents-admin.ts +28 -29
- package/src/tui/fleet-status.ts +24 -2
- package/src/tui/fleet.ts +7 -4
- package/src/tui/render.ts +53 -19
- package/src/watchdog/diff-tool.ts +24 -3
- package/src/watchdog/permission-arbiter.ts +13 -15
- package/src/watchdog/register-child.ts +10 -2
- package/src/watchdog/review.ts +14 -14
- package/src/watchdog/runtime.ts +2 -1
- package/src/watchdog/turn-delta.ts +11 -5
- package/src/workflows/scripted-workflow.ts +109 -23
- package/src/workflows/workflow-child-summary.ts +4 -2
- package/src/workflows/workflow-settlement.ts +4 -1
- package/src/runs/shared/completion-evidence.ts +0 -89
- package/src/runs/shared/completion-guard.ts +0 -255
- package/src/runs/shared/llm-intent-arbiter.ts +0 -321
- package/src/runs/shared/task-intent.ts +0 -244
|
@@ -1,321 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
import type { Agent, AgentTool, StreamFn } from "@earendil-works/pi-agent-core";
|
|
3
|
-
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
4
|
-
import type { ProviderHeaders } from "@earendil-works/pi-ai";
|
|
5
|
-
import { Type, type Static } from "typebox";
|
|
6
|
-
import { agentStreamOptions } from "../../shared/agent-stream-options.ts";
|
|
7
|
-
import { opencodeSessionHeaders } from "../../shared/opencode-session-headers.ts";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* LLM intent arbiter for the completion mutation guard.
|
|
11
|
-
*
|
|
12
|
-
* The regex classifier (task-intent.ts) is deliberately narrow, so exotic
|
|
13
|
-
* review wording can still look like an implementation task ("to fix this,
|
|
14
|
-
* compare the outputs", verbs inside URLs or quoted text). When the guard is
|
|
15
|
-
* about to hard-fail a run that made no edits, this arbiter asks a model
|
|
16
|
-
* whether the task actually instructed file changes. It can only downgrade a
|
|
17
|
-
* failure to a pass; every error, timeout, or non-read-only verdict keeps the
|
|
18
|
-
* guard's original behavior.
|
|
19
|
-
*
|
|
20
|
-
* Enabled by default; set PI_SUBAGENTS_LLM_INTENT_ARBITER=0 to disable.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
const COMPLETION_GUARD_ERROR_PREFIX =
|
|
24
|
-
"Subagent completed without making edits for an implementation task.";
|
|
25
|
-
|
|
26
|
-
export type TaskMutationVerdict = "read-only" | "implementation" | "unavailable";
|
|
27
|
-
|
|
28
|
-
export type TaskMutationArbiter = (task: string) => Promise<TaskMutationVerdict>;
|
|
29
|
-
|
|
30
|
-
const DecisionParams = Type.Object(
|
|
31
|
-
{
|
|
32
|
-
classification: Type.String({ enum: ["read_only", "implementation"] }),
|
|
33
|
-
confidence: Type.String({
|
|
34
|
-
enum: ["low", "medium", "high"],
|
|
35
|
-
description: "Confidence in the classification. Only read_only with high confidence rescues a failed run.",
|
|
36
|
-
}),
|
|
37
|
-
reason: Type.String({ description: "One concise reason for this classification." }),
|
|
38
|
-
},
|
|
39
|
-
{ additionalProperties: false },
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
type DecisionParams = Static<typeof DecisionParams>;
|
|
43
|
-
|
|
44
|
-
/** Map a model decision to a verdict. Only a high-confidence read_only rescues. */
|
|
45
|
-
export function mapArbiterDecision(
|
|
46
|
-
decision: { classification?: string; confidence?: string } | undefined,
|
|
47
|
-
): TaskMutationVerdict {
|
|
48
|
-
if (!decision) return "unavailable";
|
|
49
|
-
if (decision.classification === "read_only" && decision.confidence === "high") return "read-only";
|
|
50
|
-
return "implementation";
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
interface ArbiterRuntime {
|
|
54
|
-
model: NonNullable<RegistryModel>;
|
|
55
|
-
/** Explicit override; it always wins over a registered provider stream. */
|
|
56
|
-
explicitStreamFn?: StreamFn;
|
|
57
|
-
/** Registered provider stream, usable only when its api matches the model. */
|
|
58
|
-
registeredStreamFn?: StreamFn;
|
|
59
|
-
registeredApi?: string;
|
|
60
|
-
/** Session id for OpenCode session-routing headers, when the caller has one. */
|
|
61
|
-
sessionId?: string;
|
|
62
|
-
timeoutMs: number;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
interface ArbiterAuth {
|
|
66
|
-
apiKey?: string;
|
|
67
|
-
headers?: ProviderHeaders;
|
|
68
|
-
env?: Record<string, string>;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export interface TaskMutationArbiterOptions {
|
|
72
|
-
/** Explicit "provider/id" model override (tests, config). */
|
|
73
|
-
model?: string;
|
|
74
|
-
/** Injectable stream function (tests). */
|
|
75
|
-
streamFn?: StreamFn;
|
|
76
|
-
timeoutMs?: number;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const DEFAULT_ARBITER_TIMEOUT_MS = 10_000;
|
|
80
|
-
|
|
81
|
-
type RegistryModel = ReturnType<NonNullable<ExtensionContext["modelRegistry"]["find"]>>;
|
|
82
|
-
/** Model services the arbiter needs, plus the caller's session id for OpenCode session-routing headers. */
|
|
83
|
-
export type ArbiterModelContext = Pick<ExtensionContext, "model" | "modelRegistry"> & {
|
|
84
|
-
/** Session id the headers attach to (the child's, captured by detached runners; the parent's, passed by foreground callers). */
|
|
85
|
-
sessionId?: string;
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
function resolveArbiterModel(
|
|
89
|
-
ctx: ArbiterModelContext,
|
|
90
|
-
options?: TaskMutationArbiterOptions,
|
|
91
|
-
): NonNullable<RegistryModel> | null {
|
|
92
|
-
const registry = ctx.modelRegistry as {
|
|
93
|
-
find?: (provider: string, modelId: string) => RegistryModel | undefined;
|
|
94
|
-
getAvailable?: () => Array<{ provider?: string; id?: string }>;
|
|
95
|
-
};
|
|
96
|
-
const explicit = options?.model?.trim();
|
|
97
|
-
if (explicit) {
|
|
98
|
-
const [provider, id] = explicit.split("/");
|
|
99
|
-
if (provider && id) return registry.find?.(provider, id) ?? null;
|
|
100
|
-
return null;
|
|
101
|
-
}
|
|
102
|
-
if (ctx.model) return ctx.model as NonNullable<RegistryModel>;
|
|
103
|
-
const first = registry.getAvailable?.()[0];
|
|
104
|
-
if (first?.provider && first.id) return registry.find?.(first.provider, first.id) ?? null;
|
|
105
|
-
return null;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function resolveArbiterRuntime(
|
|
109
|
-
ctx: ArbiterModelContext,
|
|
110
|
-
options?: TaskMutationArbiterOptions,
|
|
111
|
-
): ArbiterRuntime | null {
|
|
112
|
-
const model = resolveArbiterModel(ctx, options);
|
|
113
|
-
if (!model?.provider || !model.id) return null;
|
|
114
|
-
const registry = ctx.modelRegistry as {
|
|
115
|
-
getRegisteredProviderConfig?: (provider: string) => { api?: string; streamSimple?: StreamFn } | undefined;
|
|
116
|
-
};
|
|
117
|
-
const registered = registry.getRegisteredProviderConfig?.(model.provider);
|
|
118
|
-
return {
|
|
119
|
-
model,
|
|
120
|
-
explicitStreamFn: options?.streamFn,
|
|
121
|
-
registeredStreamFn: registered?.streamSimple,
|
|
122
|
-
registeredApi: registered?.api,
|
|
123
|
-
sessionId: ctx.sessionId,
|
|
124
|
-
timeoutMs: options?.timeoutMs ?? DEFAULT_ARBITER_TIMEOUT_MS,
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
async function resolveArbiterAuth(
|
|
129
|
-
ctx: ArbiterModelContext,
|
|
130
|
-
model: RegistryModel,
|
|
131
|
-
): Promise<ArbiterAuth | undefined> {
|
|
132
|
-
const registry = ctx.modelRegistry as {
|
|
133
|
-
getApiKeyAndHeaders?: (m: RegistryModel) => Promise<{
|
|
134
|
-
ok: boolean;
|
|
135
|
-
apiKey?: string;
|
|
136
|
-
headers?: ProviderHeaders;
|
|
137
|
-
env?: Record<string, string>;
|
|
138
|
-
error?: string;
|
|
139
|
-
}>;
|
|
140
|
-
};
|
|
141
|
-
// Call as a METHOD on the registry: the host ModelRegistry implementation
|
|
142
|
-
// is a class whose method reads instance state (this.runtime), so a
|
|
143
|
-
// detached call silently fails auth. Same shape as the watchdog.
|
|
144
|
-
if (!registry.getApiKeyAndHeaders) return {};
|
|
145
|
-
try {
|
|
146
|
-
const auth = await registry.getApiKeyAndHeaders(model);
|
|
147
|
-
if (auth.ok === false) return undefined;
|
|
148
|
-
return {
|
|
149
|
-
...(auth.apiKey ? { apiKey: auth.apiKey } : {}),
|
|
150
|
-
...(auth.headers ? { headers: auth.headers } : {}),
|
|
151
|
-
...(auth.env ? { env: auth.env } : {}),
|
|
152
|
-
};
|
|
153
|
-
} catch {
|
|
154
|
-
return undefined;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/** Build the effective stream function with resolved credentials wrapped in (watchdog pattern). */
|
|
159
|
-
function authWrappedStreamFn(
|
|
160
|
-
base: StreamFn,
|
|
161
|
-
auth: ArbiterAuth,
|
|
162
|
-
sessionId: string | undefined,
|
|
163
|
-
): StreamFn {
|
|
164
|
-
return (model, context, streamOptions) => base(model, context, {
|
|
165
|
-
...(streamOptions ?? {}),
|
|
166
|
-
...(auth.apiKey ? { apiKey: auth.apiKey } : {}),
|
|
167
|
-
...(auth.env || streamOptions?.env ? { env: { ...(auth.env ?? {}), ...(streamOptions?.env ?? {}) } } : {}),
|
|
168
|
-
headers: { ...opencodeSessionHeaders(model, sessionId), ...(streamOptions?.headers ?? {}), ...(auth.headers ?? {}) },
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
async function runArbitration(
|
|
173
|
-
runtime: ArbiterRuntime,
|
|
174
|
-
auth: ArbiterAuth,
|
|
175
|
-
task: string,
|
|
176
|
-
): Promise<TaskMutationVerdict> {
|
|
177
|
-
// Keep optional Pi peers out of the detached runner's static import graph.
|
|
178
|
-
const [{ Agent }, { convertToLlm }, { streamSimple }] = await Promise.all([
|
|
179
|
-
import("@earendil-works/pi-agent-core"),
|
|
180
|
-
import("@earendil-works/pi-coding-agent"),
|
|
181
|
-
import("@earendil-works/pi-ai/compat"),
|
|
182
|
-
]);
|
|
183
|
-
const streamFn: StreamFn = runtime.explicitStreamFn
|
|
184
|
-
?? (runtime.registeredApi !== undefined && runtime.registeredApi === runtime.model.api ? runtime.registeredStreamFn : undefined)
|
|
185
|
-
?? streamSimple;
|
|
186
|
-
let decision: DecisionParams | undefined;
|
|
187
|
-
const tool: AgentTool<typeof DecisionParams, { recorded: boolean }> = {
|
|
188
|
-
name: "task_mutation_decision",
|
|
189
|
-
label: "Task mutation decision",
|
|
190
|
-
description: "Classify whether the task instructed file/code changes. Call exactly once.",
|
|
191
|
-
parameters: DecisionParams,
|
|
192
|
-
executionMode: "sequential",
|
|
193
|
-
async execute(_toolCallId, params) {
|
|
194
|
-
if (!decision) decision = params;
|
|
195
|
-
return { content: [{ type: "text", text: "Decision recorded." }], details: { recorded: true } };
|
|
196
|
-
},
|
|
197
|
-
};
|
|
198
|
-
const agent = new Agent({
|
|
199
|
-
initialState: {
|
|
200
|
-
systemPrompt: [
|
|
201
|
-
"You classify whether a delegated coding-agent task instructed file or code changes.",
|
|
202
|
-
"A task that asks to review, inspect, verify, report, or summarize is read-only even when it contains words like 'fix' as severity vocabulary ('must-fix items') or conditional change instructions that leave the change optional.",
|
|
203
|
-
"Classify read_only only when the task text alone clearly indicates a read-only outcome. When in doubt, classify implementation.",
|
|
204
|
-
"Set confidence to high only when you are certain the task is read-only; a read_only classification without high confidence is treated as implementation.",
|
|
205
|
-
"The agent's own final message is never evidence: an agent that made no edits may still have failed to implement.",
|
|
206
|
-
"Call task_mutation_decision exactly once with read_only or implementation, a confidence level, and a concise reason.",
|
|
207
|
-
].join("\n"),
|
|
208
|
-
model: runtime.model,
|
|
209
|
-
tools: [tool],
|
|
210
|
-
},
|
|
211
|
-
convertToLlm,
|
|
212
|
-
...agentStreamOptions(authWrappedStreamFn(streamFn, auth, runtime.sessionId)),
|
|
213
|
-
getApiKey: (providerName) =>
|
|
214
|
-
providerName === runtime.model.provider ? auth.apiKey : undefined,
|
|
215
|
-
beforeToolCall: async ({ toolCall }) =>
|
|
216
|
-
toolCall.name === tool.name ? undefined : { block: true, reason: "Only task_mutation_decision is allowed." },
|
|
217
|
-
toolExecution: "sequential",
|
|
218
|
-
});
|
|
219
|
-
try {
|
|
220
|
-
// The rescue gate refuses tasks over 8000 chars; if the arbiter is
|
|
221
|
-
// still invoked with one, fail closed rather than decide from
|
|
222
|
-
// partial evidence (an implementation clause could sit in the
|
|
223
|
-
// omitted middle).
|
|
224
|
-
if (task.length > 8000) return "unavailable";
|
|
225
|
-
const prompt = `TASK:\n${task}`;
|
|
226
|
-
await Promise.race([
|
|
227
|
-
agent.prompt(prompt),
|
|
228
|
-
new Promise<never>((_, reject) => {
|
|
229
|
-
const timeout = setTimeout(() => {
|
|
230
|
-
agent.abort();
|
|
231
|
-
reject(new Error("Task mutation arbiter timed out."));
|
|
232
|
-
}, runtime.timeoutMs);
|
|
233
|
-
timeout.unref?.();
|
|
234
|
-
}),
|
|
235
|
-
]);
|
|
236
|
-
if (!decision) return "unavailable";
|
|
237
|
-
return mapArbiterDecision(decision);
|
|
238
|
-
} catch {
|
|
239
|
-
return "unavailable";
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
/** Create a memoized arbiter bound to the supplied model services, or undefined when disabled/unavailable. */
|
|
244
|
-
export function createTaskMutationArbiter(
|
|
245
|
-
ctx: ArbiterModelContext,
|
|
246
|
-
options?: TaskMutationArbiterOptions,
|
|
247
|
-
): TaskMutationArbiter | undefined {
|
|
248
|
-
if (process.env.PI_SUBAGENTS_LLM_INTENT_ARBITER === "0") return undefined;
|
|
249
|
-
const runtime = resolveArbiterRuntime(ctx, options);
|
|
250
|
-
if (!runtime) return undefined;
|
|
251
|
-
const cache = new Map<string, TaskMutationVerdict>();
|
|
252
|
-
return async (task) => {
|
|
253
|
-
const key = createHash("sha256").update(task).digest("base64url");
|
|
254
|
-
const cached = cache.get(key);
|
|
255
|
-
if (cached) return cached;
|
|
256
|
-
const auth = await resolveArbiterAuth(ctx, runtime.model);
|
|
257
|
-
const verdict = auth ? await runArbitration(runtime, auth, task) : "unavailable";
|
|
258
|
-
if (cache.size > 200) cache.clear();
|
|
259
|
-
cache.set(key, verdict);
|
|
260
|
-
return verdict;
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
export function isCompletionGuardFailure(result: { error?: string }): boolean {
|
|
265
|
-
return result.error?.startsWith(COMPLETION_GUARD_ERROR_PREFIX) === true;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
export async function arbitrateCompletionGuardRescue(input: {
|
|
269
|
-
guardTriggered: boolean;
|
|
270
|
-
task: string;
|
|
271
|
-
arbiter?: TaskMutationArbiter;
|
|
272
|
-
}): Promise<{ triggered: boolean; rescued: boolean }> {
|
|
273
|
-
if (!input.guardTriggered || !input.arbiter) {
|
|
274
|
-
return { triggered: input.guardTriggered, rescued: false };
|
|
275
|
-
}
|
|
276
|
-
// Never decide from partial evidence: refuse tasks over 8000 chars before
|
|
277
|
-
// even consulting the model.
|
|
278
|
-
if (input.task.length > 8000) {
|
|
279
|
-
return { triggered: true, rescued: false };
|
|
280
|
-
}
|
|
281
|
-
try {
|
|
282
|
-
const verdict = await input.arbiter(input.task);
|
|
283
|
-
if (verdict === "read-only") return { triggered: false, rescued: true };
|
|
284
|
-
return { triggered: true, rescued: false };
|
|
285
|
-
} catch {
|
|
286
|
-
return { triggered: true, rescued: false };
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* When the completion guard hard-failed a run and the arbiter classifies the
|
|
292
|
-
* task as read-only, clear the failure. Returns true when rescued. All other
|
|
293
|
-
* verdicts and every failure mode keep the original guard behavior.
|
|
294
|
-
*
|
|
295
|
-
* Classification uses the task text only: the agent's own final message is
|
|
296
|
-
* never evidence, so a child that failed to implement cannot talk its way
|
|
297
|
-
* out of the guard by claiming the work was read-only.
|
|
298
|
-
*/
|
|
299
|
-
export async function maybeRescueCompletionGuardFailure(
|
|
300
|
-
result: { exitCode?: number; error?: string },
|
|
301
|
-
task: string,
|
|
302
|
-
arbiter: TaskMutationArbiter | undefined,
|
|
303
|
-
): Promise<boolean> {
|
|
304
|
-
if (!arbiter || !isCompletionGuardFailure(result)) return false;
|
|
305
|
-
const verdict = await arbitrateWithGuard(arbiter, task);
|
|
306
|
-
if (verdict !== "read-only") return false;
|
|
307
|
-
result.exitCode = 0;
|
|
308
|
-
delete result.error;
|
|
309
|
-
return true;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
async function arbitrateWithGuard(
|
|
313
|
-
arbiter: TaskMutationArbiter,
|
|
314
|
-
task: string,
|
|
315
|
-
): Promise<TaskMutationVerdict> {
|
|
316
|
-
try {
|
|
317
|
-
return await arbiter(task);
|
|
318
|
-
} catch {
|
|
319
|
-
return "unavailable";
|
|
320
|
-
}
|
|
321
|
-
}
|
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared task mutation-intent classifier.
|
|
3
|
-
*
|
|
4
|
-
* Single authority for reading a task's wording, answering two different
|
|
5
|
-
* questions from one prohibition analysis:
|
|
6
|
-
*
|
|
7
|
-
* - `classifyTaskMutationIntent` / `expectsImplementationMutation`: does the
|
|
8
|
-
* task REQUIRE file changes? Consumed by the completion mutation guard,
|
|
9
|
-
* which blocks completion, so its vocabulary is deliberately narrow.
|
|
10
|
-
* Verbs inside filenames and path-like tokens do not count.
|
|
11
|
-
* - `taskMayMutate`: COULD the task plausibly change files? Consumed by
|
|
12
|
-
* acceptance level inference, which only raises evidence gates, so its
|
|
13
|
-
* vocabulary is deliberately broad (any bare write verb).
|
|
14
|
-
*
|
|
15
|
-
* Explicit read-only wording ("do not modify", "review only") is a task-level
|
|
16
|
-
* intent only when no write imperative survives outside those phrases. A task
|
|
17
|
-
* like "Do not modify tests; implement the fix" is an implementation task with
|
|
18
|
-
* a scoped constraint, not a read-only task.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
const REVIEW_ONLY_PATTERNS = [
|
|
22
|
-
/\b(?:review|read)[- ]only\b/i,
|
|
23
|
-
/\bno\s+(?:source\s+)?edits?\b/i,
|
|
24
|
-
/\bwithout\s+edits?\b/i,
|
|
25
|
-
/\bsuggest fixes only\b/i,
|
|
26
|
-
/\bonly return findings\b/i,
|
|
27
|
-
/\breturn findings only\b/i,
|
|
28
|
-
];
|
|
29
|
-
|
|
30
|
-
const NO_EDIT_BOUNDARY_ASSERTION_PATTERN = /\bno\s+(?:source\s+)?edits?\s*,\s*(?:commits?|pushes?|merges?|installs?|changes?|writes?)\b/i;
|
|
31
|
-
|
|
32
|
-
const REVIEWER_REQUIRED_EDIT_PATTERNS = [
|
|
33
|
-
/\bmust\s+(?:edit|modify|change|fix|patch|apply|implement)\b/i,
|
|
34
|
-
/\brequired\s+to\s+(?:edit|modify|change|fix|patch|apply|implement)\b/i,
|
|
35
|
-
/(?:^|[.!?:;,\n]\s*)implement\s+(?:the\s+)?(?:approved|requested|specified|file|code|source|fix(?:es)?|changes?)\b/i,
|
|
36
|
-
/\bregardless\s+of\s+findings\b/i,
|
|
37
|
-
/\balways\s+(?:edit|modify|change|fix|patch|apply|implement)\b/i,
|
|
38
|
-
/\bapply\s+(?:the\s+)?fix(?:es)?\s+directly\b/i,
|
|
39
|
-
/\bmake\s+(?:the\s+)?code\s+changes\b/i,
|
|
40
|
-
];
|
|
41
|
-
|
|
42
|
-
// The prohibition's object ends at punctuation, a serialized line separator,
|
|
43
|
-
// or a coordinating word (but/and/then), so a follow-on clause like "but
|
|
44
|
-
// implement the fix" stays in the text for write-intent testing instead of
|
|
45
|
-
// being swallowed as the object.
|
|
46
|
-
// Accept serialized line separators too: workflow prompts can carry literal
|
|
47
|
-
// `\\n`/`\\r\\n` between clauses instead of decoded newlines.
|
|
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;
|
|
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;
|
|
50
|
-
|
|
51
|
-
/** Objects of a no-edit prohibition that mean "the codebase in general" rather than a named scope. */
|
|
52
|
-
const GENERIC_PROHIBITION_OBJECT = /^\s*(?:(?:any|all|the|these|those|your|our|existing|project|product|source|sources|config|configs|repo|repository)[\s/,-]*)*(?:files?|code|codebase|sources?|anything|repo(?:sitory)?)?\s*$/i;
|
|
53
|
-
const SCOPED_PROHIBITION_CONTINUATION = /^(?:\\(?:r\\n|n)|\r?\n)\s*(?:in|inside|under|within|outside|except|other\s+than|besides)\b/i;
|
|
54
|
-
const OUTPUT_INSTRUCTION_CONTINUATION = /^(?:\\(?:r\\n|n)|\r?\n)\s*(?:in|inside|within)\s+(?:(?:(?:your|the)\s+)(?:final\s+)?|final\s+)(?:output|response|report|answer|reply|message|summary|findings?|analysis|recommendations?)(?:\s*\/\s*(?:output|response|report|answer|reply|message|summary|findings?|analysis|recommendations?))*\b(?![\\/])/i;
|
|
55
|
-
|
|
56
|
-
function hasScopedProhibitionContinuation(text: string): boolean {
|
|
57
|
-
return SCOPED_PROHIBITION_CONTINUATION.test(text) && !OUTPUT_INSTRUCTION_CONTINUATION.test(text);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const SCOPED_NO_EDIT_CONSTRAINT_PATTERNS = [
|
|
61
|
-
/\bdo not edit files?\s+outside\b/i,
|
|
62
|
-
/\bdo not edit\s+outside\b/i,
|
|
63
|
-
/\bdo not edit\s+unrelated files?\b/i,
|
|
64
|
-
/\bdo not change\s+unrelated files?\b/i,
|
|
65
|
-
/\bdo not modify\s+unrelated files?\b/i,
|
|
66
|
-
];
|
|
67
|
-
|
|
68
|
-
const NO_TOOL_INTENT_PATTERNS = [
|
|
69
|
-
/\bno tools? needed\b/i,
|
|
70
|
-
/\bno tools? required\b/i,
|
|
71
|
-
/\bwithout using tools\b/i,
|
|
72
|
-
/\bdo not use tools\b/i,
|
|
73
|
-
/\bdon't use tools\b/i,
|
|
74
|
-
];
|
|
75
|
-
|
|
76
|
-
const READ_ONLY_DELIVERABLE_PATTERNS = [
|
|
77
|
-
/\b(?:draft|write|compose|prepare|produce)\s+(?:(?:a|an|the)\s+)?(?:github\s+)?(?:issue|bug report|issue draft|issue body|proposal|plan|report|summary|findings?|analysis|recommendations?)\b/i,
|
|
78
|
-
/\b(?:issue|bug report)\s+(?:draft|body|template)\b/i,
|
|
79
|
-
/\b(?:return|provide|produce)\s+(?:text|markdown|answer|findings?|recommendations?)\s+only\b/i,
|
|
80
|
-
];
|
|
81
|
-
|
|
82
|
-
const RESEARCH_AGENT_PATTERNS = [
|
|
83
|
-
/\binvestigate\b/i,
|
|
84
|
-
/\bscout\b/i,
|
|
85
|
-
/\bresearch(?:er)?\b/i,
|
|
86
|
-
];
|
|
87
|
-
|
|
88
|
-
// Review/severity vocabulary like "must-fix items" or "should-fix tests" is not
|
|
89
|
-
// the verb. Rather than dash-guarding every pattern (which would also suppress
|
|
90
|
-
// CLI flags like "--fix" and genuine clause-level dashes like "branch—fix it"),
|
|
91
|
-
// strip the known severity compounds (must|should|needs + dash + verb) from the
|
|
92
|
-
// task text before matching. Dash coverage: ASCII hyphen + U+2010..U+2015.
|
|
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;
|
|
94
|
-
|
|
95
|
-
function stripSeverityCompounds(task: string): string {
|
|
96
|
-
return task.replace(SEVERITY_COMPOUND_PATTERN, " ");
|
|
97
|
-
}
|
|
98
|
-
export { stripSeverityCompounds };
|
|
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
|
-
|
|
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;
|
|
113
|
-
|
|
114
|
-
const WORKER_IMPLEMENTATION_PATTERNS = [
|
|
115
|
-
/\b(?:implement|edit|modify|refactor|delete)\b/i,
|
|
116
|
-
FIX_OR_PATCH_IMPLEMENTATION_PATTERN,
|
|
117
|
-
/\b(?:update|add|remove|replace|create)\b(?!\s+(?:(?:a|an|the)\s+)?(?:report|summary|findings?)(?:\b|$))/i,
|
|
118
|
-
/\bapply\s+(?:the\s+)?(?:(?:suggested|proposed|recommended)\s+)?(?:changes?|fix(?:es)?|patch)\b/i,
|
|
119
|
-
/\bmake\s+(?:the\s+)?changes\b/i,
|
|
120
|
-
/\bdo those fixes\b/i,
|
|
121
|
-
];
|
|
122
|
-
|
|
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 = [
|
|
126
|
-
/\b(?:implement|edit|modify|refactor)\b/i,
|
|
127
|
-
/\bapply\s+(?:the\s+)?(?:(?:suggested|proposed|recommended)\s+)?(?:changes?|fix(?:es)?|patch)\b/i,
|
|
128
|
-
/\bmake\s+(?:the\s+)?changes\b/i,
|
|
129
|
-
/\bdo those fixes\b/i,
|
|
130
|
-
];
|
|
131
|
-
|
|
132
|
-
const GENERAL_IMPLEMENTATION_PATTERNS = [
|
|
133
|
-
...EXPLICIT_IMPLEMENTATION_PATTERNS,
|
|
134
|
-
FIX_OR_PATCH_IMPLEMENTATION_PATTERN,
|
|
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,
|
|
136
|
-
];
|
|
137
|
-
|
|
138
|
-
export type TaskMutationIntent = { kind: "implementation" } | { kind: "read-only" } | { kind: "unknown" };
|
|
139
|
-
|
|
140
|
-
function stripFrameworkInstructions(task: string): string {
|
|
141
|
-
return task
|
|
142
|
-
.split("\n")
|
|
143
|
-
.filter((line) => !/^\s*\[(?:Write to|Read from):/i.test(line))
|
|
144
|
-
.filter((line) => !/^\s*(?:Create and maintain progress at:|Update progress at:|\*\*Output:\*\*|Write your findings to(?: exactly this path)?:|Return the complete artifact in your final response\.|The runtime will persist it to exactly this path:|Do not call contact_supervisor merely because no write-capable tool is available\.|This path is authoritative for this run\.|Ignore any other output filename or output path mentioned elsewhere)/i.test(line))
|
|
145
|
-
.join("\n");
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function stripPatterns(task: string, patterns: RegExp[]): string {
|
|
149
|
-
let stripped = task;
|
|
150
|
-
for (const pattern of patterns) {
|
|
151
|
-
const flags = pattern.flags.includes("g") ? pattern.flags : `${pattern.flags}g`;
|
|
152
|
-
stripped = stripped.replace(new RegExp(pattern.source, flags), " ");
|
|
153
|
-
}
|
|
154
|
-
return stripped;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
interface NoEditProhibitionAnalysis {
|
|
158
|
-
/** True when any prohibition (or review-only/no-tool wording) is present. */
|
|
159
|
-
present: boolean;
|
|
160
|
-
/** True when a prohibition covers files/code in general; such wording wins over write verbs. */
|
|
161
|
-
blanket: boolean;
|
|
162
|
-
/** Task text with prohibition phrases and their objects removed, for write-intent testing. */
|
|
163
|
-
strippedText: string;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
function analyzeNoEditProhibitions(taskText: string): NoEditProhibitionAnalysis {
|
|
167
|
-
const readOnlyBoundary = NO_EDIT_BOUNDARY_ASSERTION_PATTERN.test(taskText);
|
|
168
|
-
let present = REVIEW_ONLY_PATTERNS.some((pattern) => pattern.test(taskText))
|
|
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]);
|
|
174
|
-
const stripNoEditProhibition = (match: string, object: string, offset: number, source: string): string => {
|
|
175
|
-
present = true;
|
|
176
|
-
if (GENERIC_PROHIBITION_OBJECT.test(object) && !hasScopedProhibitionContinuation(source.slice(offset + match.length))) blanket = true;
|
|
177
|
-
return " ";
|
|
178
|
-
};
|
|
179
|
-
strippedText = strippedText.replace(new RegExp(COORDINATED_NO_EDIT_PROHIBITION_PATTERN.source, COORDINATED_NO_EDIT_PROHIBITION_PATTERN.flags), stripNoEditProhibition);
|
|
180
|
-
strippedText = strippedText.replace(new RegExp(NO_EDIT_PROHIBITION_PATTERN.source, NO_EDIT_PROHIBITION_PATTERN.flags), stripNoEditProhibition);
|
|
181
|
-
// Restore boundaries after stripping a prohibition from serialized prompts.
|
|
182
|
-
strippedText = strippedText.replace(/\\(?:r\\n|n)/g, "\n");
|
|
183
|
-
return { present, blanket, strippedText };
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
function taskHasReadOnlyDeliverable(taskText: string): boolean {
|
|
187
|
-
return READ_ONLY_DELIVERABLE_PATTERNS.some((pattern) => pattern.test(taskText));
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
function isReviewerStyleAgent(agent: string): boolean {
|
|
191
|
-
return /\b(?:advisor|reviewer|oracle)\b/i.test(agent);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
function hasImplementationIntent(agent: string, taskText: string): boolean {
|
|
195
|
-
if (isReviewerStyleAgent(agent)) return REVIEWER_REQUIRED_EDIT_PATTERNS.some((pattern) => pattern.test(taskText));
|
|
196
|
-
if (agent === "worker") return WORKER_IMPLEMENTATION_PATTERNS.some((pattern) => pattern.test(taskText));
|
|
197
|
-
return GENERAL_IMPLEMENTATION_PATTERNS.some((pattern) => pattern.test(taskText));
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
export function classifyTaskMutationIntent(agent: string, task: string): TaskMutationIntent {
|
|
201
|
-
const taskText = stripPatterns(stripSeverityCompounds(stripFrameworkInstructions(task)), [FINDING_CLASSIFICATION_PATTERN]);
|
|
202
|
-
const taskTextWithoutScopedConstraints = stripPatterns(taskText, SCOPED_NO_EDIT_CONSTRAINT_PATTERNS);
|
|
203
|
-
const prohibitions = analyzeNoEditProhibitions(taskTextWithoutScopedConstraints);
|
|
204
|
-
if (prohibitions.present) {
|
|
205
|
-
if (prohibitions.blanket) return { kind: "read-only" };
|
|
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" };
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
if (RESEARCH_AGENT_PATTERNS.some((pattern) => pattern.test(agent))) return { kind: "read-only" };
|
|
217
|
-
if (hasImplementationIntent(agent, stripPathLikeTokens(taskText))) return { kind: "implementation" };
|
|
218
|
-
if (isReviewerStyleAgent(agent)) return { kind: "read-only" };
|
|
219
|
-
return taskHasReadOnlyDeliverable(taskTextWithoutScopedConstraints) ? { kind: "read-only" } : { kind: "unknown" };
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
export function expectsImplementationMutation(agent: string, task: string): boolean {
|
|
223
|
-
return classifyTaskMutationIntent(agent, task).kind === "implementation";
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
/** Bare write verbs that make a task write-capable for acceptance inference.
|
|
227
|
-
* Severity compounds ("must-fix items") are stripped before matching, so they
|
|
228
|
-
* are not write imperatives, while CLI flags ("--fix", "-w"), clause-level
|
|
229
|
-
* dashes ("branch—fix it"), and hyphenated imperatives ("hot-fix the bug")
|
|
230
|
-
* all stay write-capable. */
|
|
231
|
-
const MAY_MUTATE_VERB_PATTERN = /\b(?:fix|implement|update|write|edit|modify|migrate|delete|remove|refactor|commit)\b/i;
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* Whether the task could plausibly change files. Blanket prohibitions win;
|
|
235
|
-
* write verbs inside a scoped prohibition's object or a read-only deliverable
|
|
236
|
-
* phrase ("write a summary report") do not count; any other bare write verb
|
|
237
|
-
* does.
|
|
238
|
-
*/
|
|
239
|
-
export function taskMayMutate(task: string): boolean {
|
|
240
|
-
const taskText = stripPatterns(stripSeverityCompounds(stripFrameworkInstructions(task)), [FINDING_CLASSIFICATION_PATTERN, ...SCOPED_NO_EDIT_CONSTRAINT_PATTERNS]);
|
|
241
|
-
const prohibitions = analyzeNoEditProhibitions(taskText);
|
|
242
|
-
if (prohibitions.blanket) return false;
|
|
243
|
-
return MAY_MUTATE_VERB_PATTERN.test(stripPatterns(prohibitions.strippedText, READ_ONLY_DELIVERABLE_PATTERNS));
|
|
244
|
-
}
|