@christang/keel 5.172.0 → 5.173.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/.claude-plugin/plugin.json +1 -4
- package/README.md +5 -6
- package/README.zh-CN.md +3 -5
- package/assets/bootstrap/AGENTS.md +1 -1
- package/assets/openspec/schemas/keel-spec-driven/templates/tasks.md +5 -5
- package/bin/keel.js +9 -176
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/plugins/keel/.claude-plugin/plugin.json +1 -1
- package/plugins/keel/.codex-plugin/plugin.json +1 -2
- package/plugins/keel/scripts/pretooluse-guard.js +3 -4
- package/scripts/validate_plugin.py +90 -2446
- package/src/core/agents.js +57 -12
- package/src/core/capabilities.js +0 -53
- package/src/core/config.js +4 -37
- package/src/core/projection.js +42 -149
- package/src/core/task-contract.js +3 -30
- package/plugins/keel/agents/keel-single-task-goal-claude.md +0 -17
- package/plugins/keel/agents/keel-single-task-goal-codex.md +0 -16
- package/plugins/keel/skills/keel-run-single-task-goal/SKILL.md +0 -64
- package/plugins/keel/skills/keel-run-single-task-goal/guidance.md +0 -30
- package/src/core/goal.js +0 -242
- package/src/core/helper.js +0 -345
- package/src/core/tasksview.js +0 -123
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: keel-run-single-task-goal
|
|
3
|
-
description: Use when the user explicitly authorizes automatic execution or resume of exactly one OpenSpec task on Codex or Claude. Drives the single-task native goal lifecycle through Keel gates, keeps the current agent the sole holder of write authority, and stops at the task boundary. Never activate for ordinary apply, proposal work, ambiguous or multiple tasks, or OpenCode.
|
|
4
|
-
license: UNLICENSED
|
|
5
|
-
metadata:
|
|
6
|
-
keel-role: single-task-goal-activation
|
|
7
|
-
keel-targets: codex, claude
|
|
8
|
-
---
|
|
9
|
-
|
|
10
|
-
# keel-run-single-task-goal
|
|
11
|
-
|
|
12
|
-
## Purpose
|
|
13
|
-
|
|
14
|
-
Activate a native goal runtime to execute exactly one authorized OpenSpec task end to end, while OpenSpec, Git, the task-capsule fingerprint, and deterministic Keel gates stay the only durable authority. The current agent remains the sole holder of write authority and owns Review, gate invocation, the task checkbox, and completion. A model-chosen implementation delegate with a matching active guard may write inside the `Touch` boundary that authority already defined and acquires none of those decisions; the current agent re-runs each `M<n>` check itself before recording Evidence, because a delegate's reported result is a claim and the byte-identity check that validates a read-only helper cannot apply to a writer. A native evaluator declaring success never marks or reports the task complete.
|
|
15
|
-
|
|
16
|
-
## Guidance
|
|
17
|
-
|
|
18
|
-
Read `guidance.md` beside this file before proceeding, unless `keel/config.yaml` declares `executor_tier: high` — it holds the runtime references, the manual sequence, and the per-target detail. Every criterion is here, so an absent or unreadable declaration costs a read and nothing else.
|
|
19
|
-
|
|
20
|
-
## License
|
|
21
|
-
|
|
22
|
-
License note: the Keel package license (UNLICENSED, all rights reserved by the author). Linking the official runtime docs relicenses nothing; their provenance is recorded beside the links and their content is never pasted into Keel artifacts.
|
|
23
|
-
|
|
24
|
-
## When to activate
|
|
25
|
-
|
|
26
|
-
Activate only on an explicit, unambiguous request to automatically execute or resume **one** task:
|
|
27
|
-
|
|
28
|
-
- The user names one OpenSpec change and one executable task and asks to run or continue it automatically.
|
|
29
|
-
- A resume request points at the same durable task whose recorded authorization fingerprint still matches the recompiled capsule.
|
|
30
|
-
|
|
31
|
-
## When NOT to activate
|
|
32
|
-
|
|
33
|
-
- Ordinary `/opsx:apply` or manual step-by-step work the user is driving.
|
|
34
|
-
- Proposal, design, or spec authoring before tasks are final.
|
|
35
|
-
- Ambiguous selection, multiple tasks, or a whole task group or change backlog.
|
|
36
|
-
- An unrelated native `/goal` use that is not a Keel OpenSpec task.
|
|
37
|
-
- Ordinary helper use, which does not activate a native goal. Model-chosen implementation delegates still require task write authority and a matching active guard.
|
|
38
|
-
- OpenCode, which stays manual compatibility only with no v4 native activation.
|
|
39
|
-
|
|
40
|
-
If any of these hold, stop and use the normal manual Keel loop.
|
|
41
|
-
|
|
42
|
-
## Single-task goal lifecycle
|
|
43
|
-
|
|
44
|
-
1. `keel gate task-start --change C --task T` and record the returned fingerprint in the task Evidence `Contract` line as the durable authorization.
|
|
45
|
-
2. `keel project goal --target codex|claude --change C --task T --json` to compile the disposable `keel-native-goal/v1` projection (objective, Acceptance, command labels, verification strategy, Touch, stop boundary, ownership, terminal condition). The projection is a view, never authority, and never checks the box.
|
|
46
|
-
3. Implement within Touch and produce the strategy's evidence (for example red/green slices for vertical-tdd).
|
|
47
|
-
4. Surface every command result and gate outcome in the transcript before any success claim.
|
|
48
|
-
5. Pass the current agent's Review, then `keel gate task-complete`.
|
|
49
|
-
6. The current agent durably checks the task checkbox.
|
|
50
|
-
7. Stop. Continuing to another task requires a new explicit user instruction and a new start fingerprint; a standing `continuation` authorization in `keel/config.yaml` is the durable form of that instruction, covering only the next unchecked task of the same change in its approved `tasks.md` order. Each next task still passes `keel gate task-start` with its own recorded fingerprint, and there is still no hidden scheduler or automatic next-task selection — the declaration removes the confirmation, never the selection, the gates, or the evidence.
|
|
51
|
-
|
|
52
|
-
Resume reconstructs the goal from OpenSpec and Git only. Fingerprint drift, checkout divergence, a completed authorization, or missing authorization hard-stops before any product write; pass `--expected-fingerprint` and `--expected-owner` to assert the recorded authorization.
|
|
53
|
-
|
|
54
|
-
## Bounded read-only helpers
|
|
55
|
-
|
|
56
|
-
Helpers are optional, read-only evidence producers and never a second writer. Compile one with `keel project helper` for a single bounded question or one repository-byte-stable verification command; a helper never writes products, delegates, nests, or holds acceptance or completion authority. Accept a helper return only after `keel project helper --verify` proves before/after repository byte identity; a modified, added, removed, renamed, or permission-changed path rejects the evidence with exact paths and no cleanup. Helper absence never disables current-agent goal execution.
|
|
57
|
-
|
|
58
|
-
## Manual fallback
|
|
59
|
-
|
|
60
|
-
When native activation is unavailable, do not fake activation: run the identical lifecycle by hand. The manual loop preserves the same single-task boundary and the same stop boundary; its steps are in `guidance.md`.
|
|
61
|
-
|
|
62
|
-
## Target activation
|
|
63
|
-
|
|
64
|
-
Claude and Codex only. Activate exactly one bounded goal for the selected task; a native evaluator declaring success never marks or reports the task complete. The per-target detail is in `guidance.md`.
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
# keel-run-single-task-goal — guidance
|
|
2
|
-
|
|
3
|
-
How to carry out the lifecycle. Every criterion is in `SKILL.md`; nothing here decides whether a task
|
|
4
|
-
may start, pass, or complete.
|
|
5
|
-
|
|
6
|
-
## Authoritative runtime references
|
|
7
|
-
|
|
8
|
-
Provenance: linked, not copied. Their text and trademarks belong to their owners, and Keel paraphrases
|
|
9
|
-
only the activation semantics it needs. License note: see `SKILL.md`.
|
|
10
|
-
|
|
11
|
-
- Codex goal-following: https://learn.chatgpt.com/use-cases/follow-goals
|
|
12
|
-
- Codex subagents: https://developers.openai.com/codex/subagents
|
|
13
|
-
- Claude goal execution: https://code.claude.com/docs/en/goal
|
|
14
|
-
- Claude subagents: https://code.claude.com/docs/en/sub-agents
|
|
15
|
-
|
|
16
|
-
## Running the lifecycle by hand
|
|
17
|
-
|
|
18
|
-
Native activation can be unavailable — no plugin, disabled hooks, managed policy, missing trust, or an
|
|
19
|
-
unsupported surface. Type the same numbered steps `SKILL.md` lists, in the same order: `keel gate task-start`, record the
|
|
20
|
-
fingerprint, `keel project goal … --json` for the view, implement inside `Touch`, surface every result
|
|
21
|
-
in the transcript, `keel gate task-complete`, check the box. What changes is who types them.
|
|
22
|
-
|
|
23
|
-
## Per-target activation notes
|
|
24
|
-
|
|
25
|
-
- **Codex**: where a callable goal or subagent surface exists, activate one bounded goal for the
|
|
26
|
-
selected task; choose helpers or guarded implementation delegates under the task contract and host policy. Without a callable surface, paste
|
|
27
|
-
the exact `keel project goal` command and treat the capability as advisory.
|
|
28
|
-
- **Claude**: activate one `/goal` whose condition fits the 4,000-character budget. The evaluator sees
|
|
29
|
-
the transcript only, so command and gate evidence has to appear there explicitly. If hooks are
|
|
30
|
-
disabled, policy blocks activation, or trust is missing, the manual sequence above applies.
|
package/src/core/goal.js
DELETED
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
// Keel 4.1.0 single-task native goal projection contract.
|
|
4
|
-
//
|
|
5
|
-
// Compiles one passing `keel-task-capsule/v1` into an ephemeral
|
|
6
|
-
// `keel-native-goal/v1` projection for a supported native runtime. The
|
|
7
|
-
// projection is never written as Keel-owned state; OpenSpec, Git, the capsule
|
|
8
|
-
// fingerprint, and deterministic gates remain durable authority.
|
|
9
|
-
|
|
10
|
-
const { resolveContext } = require("./context");
|
|
11
|
-
const { loadTaskContract } = require("./task-contract");
|
|
12
|
-
const { probeCapabilities } = require("./capabilities");
|
|
13
|
-
|
|
14
|
-
const GOAL_VERSION = "keel-native-goal/v1";
|
|
15
|
-
const CLAUDE_CONDITION_LIMIT = 4000;
|
|
16
|
-
const SUPPORTED_GOAL_TARGETS = new Set(["codex", "claude"]);
|
|
17
|
-
const TERMINAL_STATES = ["complete", "blocked", "paused"];
|
|
18
|
-
const EVIDENCE_PRESENTATION = [
|
|
19
|
-
"Surface every Command result and gate outcome in the transcript before any success claim.",
|
|
20
|
-
"Native evaluator success alone never marks or reports the OpenSpec task complete.",
|
|
21
|
-
"Achievement requires matching change/task/fingerprint, Acceptance demonstrated by the named Commands, passing Review, passing task-complete, and the durably checked task checkbox.",
|
|
22
|
-
];
|
|
23
|
-
|
|
24
|
-
function blockedGoal(target, reason, warnings = [], extra = {}) {
|
|
25
|
-
return {
|
|
26
|
-
version: GOAL_VERSION,
|
|
27
|
-
status: "blocked",
|
|
28
|
-
target,
|
|
29
|
-
source: null,
|
|
30
|
-
capability: null,
|
|
31
|
-
goal: null,
|
|
32
|
-
reasons: [reason],
|
|
33
|
-
warnings,
|
|
34
|
-
...extra,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function renderCondition(goal) {
|
|
39
|
-
const lines = [
|
|
40
|
-
`Goal: complete exactly one OpenSpec task — ${goal.owner} (fingerprint ${goal.fingerprint.value}).`,
|
|
41
|
-
`Objective: ${goal.objective}`,
|
|
42
|
-
"Acceptance (all must be demonstrated by the named Commands):",
|
|
43
|
-
...goal.acceptance.map((item) => `- ${item}`),
|
|
44
|
-
"Commands:",
|
|
45
|
-
...goal.commands.map((item) => `- ${item}`),
|
|
46
|
-
`Verification strategy: ${goal.verificationStrategy}.`,
|
|
47
|
-
`Write boundary (Touch): ${goal.touch.join(", ")}.`,
|
|
48
|
-
"Stop/Autonomy boundary:",
|
|
49
|
-
...goal.stopBoundary.map((item) => `- ${item}`),
|
|
50
|
-
"Ownership: the current agent is the sole holder of write authority and owns Review, gate invocation, the task checkbox, and completion. A declared delegate writes only inside Touch and the current agent re-runs each check before recording Evidence.",
|
|
51
|
-
...(goal.delegation
|
|
52
|
-
? [
|
|
53
|
-
`Delegation: tier ${goal.delegation.tier}, declared by `
|
|
54
|
-
+ `${goal.delegation.source}. Keel carries the tier and does not `
|
|
55
|
-
+ "select or observe a model.",
|
|
56
|
-
]
|
|
57
|
-
: []),
|
|
58
|
-
"Done only when: task-complete passes and the current agent has durably checked the task; then stop and require a new explicit authorization before any next task.",
|
|
59
|
-
];
|
|
60
|
-
return lines.join("\n");
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function compileGoalProjection(repo, options) {
|
|
64
|
-
const target = options.target;
|
|
65
|
-
if (!SUPPORTED_GOAL_TARGETS.has(target)) {
|
|
66
|
-
return blockedGoal(
|
|
67
|
-
target,
|
|
68
|
-
`Native single-task goal execution supports codex and claude only; `
|
|
69
|
-
+ `${target || "<missing>"} remains manual/compatibility-only.`
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
if (!options.change || !options.task) {
|
|
73
|
-
return blockedGoal(
|
|
74
|
-
target,
|
|
75
|
-
"Native goal activation requires one explicit --change and --task "
|
|
76
|
-
+ "selection; ambiguous, multiple, or task-group activation is rejected."
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const context = resolveContext(repo, {
|
|
81
|
-
change: options.change,
|
|
82
|
-
task: options.task,
|
|
83
|
-
});
|
|
84
|
-
if (context.status !== "ready" || !context.selection) {
|
|
85
|
-
return blockedGoal(
|
|
86
|
-
target,
|
|
87
|
-
context.reasons.join(" ") || "Current OpenSpec context is not ready.",
|
|
88
|
-
context.warnings
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
const change = context.selection.change;
|
|
92
|
-
const taskId = context.selection.task;
|
|
93
|
-
if (!taskId) {
|
|
94
|
-
return blockedGoal(
|
|
95
|
-
target,
|
|
96
|
-
"Native goal activation requires one selected executable task, not a "
|
|
97
|
-
+ "change backlog or contiguous task group.",
|
|
98
|
-
context.warnings
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const loaded = loadTaskContract(repo, change, taskId);
|
|
103
|
-
if (!loaded) {
|
|
104
|
-
return blockedGoal(
|
|
105
|
-
target,
|
|
106
|
-
`Selected durable task owner openspec/changes/${change}/tasks.md#${taskId} `
|
|
107
|
-
+ "is missing.",
|
|
108
|
-
context.warnings
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
if (loaded.task.checked) {
|
|
112
|
-
return blockedGoal(
|
|
113
|
-
target,
|
|
114
|
-
"Selected task is already complete; a later task requires a new explicit "
|
|
115
|
-
+ "user authorization and a new start fingerprint.",
|
|
116
|
-
context.warnings
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
|
-
if (loaded.contract.diagnostics.length > 0) {
|
|
120
|
-
return blockedGoal(
|
|
121
|
-
target,
|
|
122
|
-
loaded.contract.diagnostics.map((item) => item.message).join(" "),
|
|
123
|
-
context.warnings
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const contract = loaded.contract;
|
|
128
|
-
const capsule = contract.capsule;
|
|
129
|
-
const owner = `openspec/changes/${change}/tasks.md#${taskId}`;
|
|
130
|
-
|
|
131
|
-
// Continuity is reconstructed from durable OpenSpec/Git authority, never a
|
|
132
|
-
// Keel cursor or cache: a resume passes the previously recorded owner and
|
|
133
|
-
// fingerprint, and any divergence hard-stops rather than silently rebinding.
|
|
134
|
-
if (options.expectedOwner && options.expectedOwner !== owner) {
|
|
135
|
-
return blockedGoal(
|
|
136
|
-
target,
|
|
137
|
-
`Recorded authorization owns ${options.expectedOwner}, but the current `
|
|
138
|
-
+ `OpenSpec selection is ${owner}; checkout divergence requires new `
|
|
139
|
-
+ "explicit authorization, not automatic rebinding.",
|
|
140
|
-
context.warnings
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
if (
|
|
144
|
-
options.expectedFingerprint
|
|
145
|
-
&& options.expectedFingerprint !== contract.fingerprint.value
|
|
146
|
-
) {
|
|
147
|
-
return blockedGoal(
|
|
148
|
-
target,
|
|
149
|
-
`Recompiled capsule fingerprint ${contract.fingerprint.value} does not `
|
|
150
|
-
+ `match the recorded authorization ${options.expectedFingerprint}; `
|
|
151
|
-
+ "fingerprint drift requires reauthorization before any product write.",
|
|
152
|
-
context.warnings
|
|
153
|
-
);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
const capabilities = probeCapabilities(repo, target);
|
|
157
|
-
const capability = capabilities.capabilities["execution.goal"];
|
|
158
|
-
|
|
159
|
-
const goal = {
|
|
160
|
-
version: GOAL_VERSION,
|
|
161
|
-
target,
|
|
162
|
-
change,
|
|
163
|
-
task: taskId,
|
|
164
|
-
fingerprint: contract.fingerprint,
|
|
165
|
-
objective: capsule.task.title,
|
|
166
|
-
acceptance: capsule.acceptance,
|
|
167
|
-
commands: capsule.verification.commands.map(
|
|
168
|
-
(item) => `${item.label}: ${item.check}`
|
|
169
|
-
),
|
|
170
|
-
verificationStrategy: capsule.verification.strategy,
|
|
171
|
-
touch: capsule.touch,
|
|
172
|
-
stopBoundary: [...capsule.boundaries.stop, ...capsule.boundaries.autonomy],
|
|
173
|
-
owner: capsule.owner,
|
|
174
|
-
ownership: "current-agent-sole-writer",
|
|
175
|
-
helperPolicy: capsule.helperAuthority,
|
|
176
|
-
// Carried inside the condition rather than beside it, so a declared
|
|
177
|
-
// delegation is subject to the same budget as everything else the
|
|
178
|
-
// activation must state. A field that never reaches the condition
|
|
179
|
-
// cannot overflow it, and would then be a boundary the goal omits.
|
|
180
|
-
delegation: capsule.delegation || null,
|
|
181
|
-
terminalStates: TERMINAL_STATES,
|
|
182
|
-
evidencePresentation: EVIDENCE_PRESENTATION,
|
|
183
|
-
authorizationEvidence: {
|
|
184
|
-
field: "Automation authorization: single-task",
|
|
185
|
-
target,
|
|
186
|
-
change,
|
|
187
|
-
task: taskId,
|
|
188
|
-
fingerprint: contract.fingerprint.value,
|
|
189
|
-
},
|
|
190
|
-
prohibitions: capsule.prohibitions,
|
|
191
|
-
};
|
|
192
|
-
goal.owner = owner;
|
|
193
|
-
const conditionText = renderCondition(goal);
|
|
194
|
-
goal.condition = conditionText;
|
|
195
|
-
goal.conditionLength = conditionText.length;
|
|
196
|
-
|
|
197
|
-
if (target === "claude" && conditionText.length > CLAUDE_CONDITION_LIMIT) {
|
|
198
|
-
return blockedGoal(
|
|
199
|
-
target,
|
|
200
|
-
`Compiled goal condition is ${conditionText.length} characters, above the `
|
|
201
|
-
+ `Claude ${CLAUDE_CONDITION_LIMIT}-character limit; refusing native `
|
|
202
|
-
+ "activation rather than omitting Acceptance, fingerprint, or stop "
|
|
203
|
-
+ "authority. Use the manual current-agent loop instead.",
|
|
204
|
-
context.warnings,
|
|
205
|
-
{ conditionLength: conditionText.length }
|
|
206
|
-
);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
return {
|
|
210
|
-
version: GOAL_VERSION,
|
|
211
|
-
status: "ready",
|
|
212
|
-
target,
|
|
213
|
-
source: { authority: "OpenSpec", owner, change, task: taskId },
|
|
214
|
-
capability,
|
|
215
|
-
goal,
|
|
216
|
-
reasons: [],
|
|
217
|
-
warnings: context.warnings,
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
function renderGoalProjection(result) {
|
|
222
|
-
const lines = [
|
|
223
|
-
`Keel native goal: ${result.status}`,
|
|
224
|
-
`Target: ${result.target}`,
|
|
225
|
-
];
|
|
226
|
-
if (result.source) lines.push(`Owner: ${result.source.owner}`);
|
|
227
|
-
if (result.goal) {
|
|
228
|
-
lines.push(`Fingerprint: ${result.goal.fingerprint.value}`);
|
|
229
|
-
lines.push(`Condition length: ${result.goal.conditionLength}`);
|
|
230
|
-
}
|
|
231
|
-
for (const reason of result.reasons || []) lines.push(`Reason: ${reason}`);
|
|
232
|
-
for (const warning of result.warnings || []) lines.push(`Warning: ${warning}`);
|
|
233
|
-
return `${lines.join("\n")}\n`;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
module.exports = {
|
|
237
|
-
GOAL_VERSION,
|
|
238
|
-
CLAUDE_CONDITION_LIMIT,
|
|
239
|
-
SUPPORTED_GOAL_TARGETS,
|
|
240
|
-
compileGoalProjection,
|
|
241
|
-
renderGoalProjection,
|
|
242
|
-
};
|
package/src/core/helper.js
DELETED
|
@@ -1,345 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
// Keel 4.1.0 bounded read-only helper contract.
|
|
4
|
-
//
|
|
5
|
-
// A helper is never a second writer. `keel project helper` compiles one
|
|
6
|
-
// bounded read-only question or one exact repository-byte-stable verification
|
|
7
|
-
// command into a `keel-helper-brief/v1` evidence contract, and verifies a
|
|
8
|
-
// helper's return only after proving the repository bytes are unchanged. The
|
|
9
|
-
// current agent stays the sole writer, owner of Acceptance, Review, gates, and
|
|
10
|
-
// completion; helper absence never disables current-agent goal execution.
|
|
11
|
-
|
|
12
|
-
const fs = require("fs");
|
|
13
|
-
const os = require("os");
|
|
14
|
-
const path = require("path");
|
|
15
|
-
const crypto = require("crypto");
|
|
16
|
-
|
|
17
|
-
const BRIEF_VERSION = "keel-helper-brief/v1";
|
|
18
|
-
const BASELINE_VERSION = "keel-helper-baseline/v1";
|
|
19
|
-
const VERIFY_VERSION = "keel-helper-verification/v1";
|
|
20
|
-
const SUPPORTED_HELPER_TARGETS = new Set(["codex", "claude"]);
|
|
21
|
-
|
|
22
|
-
// Any mutation, delegation, or ownership request disqualifies a read-only brief.
|
|
23
|
-
const FORBIDDEN_INTENT = new RegExp(
|
|
24
|
-
"\\b(implement|write|edit|modify|create|refactor|delete|remove|fix|apply|"
|
|
25
|
-
+ "generate|install|commit|push|sync|archive|mark|check off|rewrite|"
|
|
26
|
-
+ "update the task|change the acceptance|use the fallback|use a fallback)\\b",
|
|
27
|
-
"i"
|
|
28
|
-
);
|
|
29
|
-
const DELEGATION_INTENT = new RegExp(
|
|
30
|
-
"\\b(subagent|sub-agent|delegate|delegation|spawn|agent team|another agent|"
|
|
31
|
-
+ "helper)\\b",
|
|
32
|
-
"i"
|
|
33
|
-
);
|
|
34
|
-
// Shell tokens that would create or move repository artifacts.
|
|
35
|
-
const ARTIFACT_TOKENS = [
|
|
36
|
-
">", ">>", "|&", "tee ", "git commit", "git add", "git push", "git checkout",
|
|
37
|
-
"git reset", "git restore", "git rm", "git mv", "npm install", "npm i ",
|
|
38
|
-
"npm ci", "mkdir", "touch ", "rm ", "mv ", "cp ", "rmdir",
|
|
39
|
-
];
|
|
40
|
-
const REPORT_SCHEMA = [
|
|
41
|
-
"question-or-command",
|
|
42
|
-
"reads-performed",
|
|
43
|
-
"observed-evidence",
|
|
44
|
-
"byte-stability: verified|rejected|unverifiable",
|
|
45
|
-
"no-writes-no-delegation-no-completion-authority",
|
|
46
|
-
];
|
|
47
|
-
|
|
48
|
-
function blockedBrief(target, reason, extra = {}) {
|
|
49
|
-
return {
|
|
50
|
-
version: BRIEF_VERSION,
|
|
51
|
-
status: "blocked",
|
|
52
|
-
target,
|
|
53
|
-
brief: null,
|
|
54
|
-
reasons: [reason],
|
|
55
|
-
...extra,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Symbolic links are resolved on both sides, because `process.cwd()` comes
|
|
60
|
-
// back already resolved while `path.resolve` never follows a link — on macOS,
|
|
61
|
-
// where `/tmp` is a link to `/private/tmp`, that made a path inside the
|
|
62
|
-
// worktree look external and let the helper write its baseline into the
|
|
63
|
-
// repository it had just promised not to touch. The baseline usually does not
|
|
64
|
-
// exist yet, so the nearest existing ancestor is what resolves. The write
|
|
65
|
-
// guard hook answers the same question and keeps its own copy of this rule,
|
|
66
|
-
// because it is a standalone script that cannot import from here.
|
|
67
|
-
function realPathOrNearest(target) {
|
|
68
|
-
let current = path.resolve(target);
|
|
69
|
-
const trailing = [];
|
|
70
|
-
for (;;) {
|
|
71
|
-
try {
|
|
72
|
-
return path.join(fs.realpathSync(current), ...trailing);
|
|
73
|
-
} catch {
|
|
74
|
-
const parent = path.dirname(current);
|
|
75
|
-
if (parent === current) return path.resolve(target);
|
|
76
|
-
trailing.unshift(path.basename(current));
|
|
77
|
-
current = parent;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function isExternal(repo, candidate) {
|
|
83
|
-
const rel = path.relative(
|
|
84
|
-
realPathOrNearest(repo),
|
|
85
|
-
realPathOrNearest(candidate)
|
|
86
|
-
);
|
|
87
|
-
return (
|
|
88
|
-
rel === ".."
|
|
89
|
-
|| rel.startsWith(`..${path.sep}`)
|
|
90
|
-
|| path.isAbsolute(rel)
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function compileHelperBrief(repo, options) {
|
|
95
|
-
const target = options.target;
|
|
96
|
-
if (!SUPPORTED_HELPER_TARGETS.has(target)) {
|
|
97
|
-
return blockedBrief(
|
|
98
|
-
target,
|
|
99
|
-
`Bounded read-only helpers support codex and claude only; `
|
|
100
|
-
+ `${target || "missing"} remains manual/compatibility-only.`
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const question = (options.helperQuestion || "").trim();
|
|
105
|
-
const command = (options.helperCommand || "").trim();
|
|
106
|
-
if ((question && command) || (!question && !command)) {
|
|
107
|
-
return blockedBrief(
|
|
108
|
-
target,
|
|
109
|
-
"A helper brief needs exactly one bounded read-only question or one exact "
|
|
110
|
-
+ "repository-byte-stable verification command, not both and not neither."
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const external = options.helperExternal || [];
|
|
115
|
-
for (const declared of external) {
|
|
116
|
-
if (!isExternal(repo, declared)) {
|
|
117
|
-
return blockedBrief(
|
|
118
|
-
target,
|
|
119
|
-
`Declared helper output path is inside the repository: ${declared}; `
|
|
120
|
-
+ "helper temporaries must live outside the worktree."
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (question) {
|
|
126
|
-
if (/\?[\s\S]*\?/.test(question)) {
|
|
127
|
-
return blockedBrief(
|
|
128
|
-
target,
|
|
129
|
-
"A helper brief carries one bounded question; multiple unrelated "
|
|
130
|
-
+ "questions must be split into separate read-only briefs."
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
if (DELEGATION_INTENT.test(question)) {
|
|
134
|
-
return blockedBrief(
|
|
135
|
-
target,
|
|
136
|
-
"A helper cannot delegate or spawn nested helpers; the brief must be a "
|
|
137
|
-
+ "single read-only question the helper answers itself."
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
if (FORBIDDEN_INTENT.test(question)) {
|
|
141
|
-
return blockedBrief(
|
|
142
|
-
target,
|
|
143
|
-
"A helper is read-only and owns no completion authority; it cannot be "
|
|
144
|
-
+ "asked to implement, write, mark, sync, archive, commit, push, or "
|
|
145
|
-
+ "change Acceptance."
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
} else {
|
|
149
|
-
if (DELEGATION_INTENT.test(command)) {
|
|
150
|
-
return blockedBrief(
|
|
151
|
-
target,
|
|
152
|
-
"A helper verification command cannot delegate or nest further helpers."
|
|
153
|
-
);
|
|
154
|
-
}
|
|
155
|
-
const lowered = command.toLowerCase();
|
|
156
|
-
const artifact = ARTIFACT_TOKENS.find((token) => lowered.includes(token));
|
|
157
|
-
if (artifact) {
|
|
158
|
-
return blockedBrief(
|
|
159
|
-
target,
|
|
160
|
-
`Helper command would generate or move repository artifacts (${artifact.trim()}); `
|
|
161
|
-
+ "only repository-byte-stable verification commands are allowed."
|
|
162
|
-
);
|
|
163
|
-
}
|
|
164
|
-
if (FORBIDDEN_INTENT.test(command)) {
|
|
165
|
-
return blockedBrief(
|
|
166
|
-
target,
|
|
167
|
-
"A helper verification command cannot mark, sync, archive, commit, push, "
|
|
168
|
-
+ "or otherwise assume completion authority."
|
|
169
|
-
);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const brief = {
|
|
174
|
-
version: BRIEF_VERSION,
|
|
175
|
-
target,
|
|
176
|
-
mode: question ? "question" : "verification-command",
|
|
177
|
-
request: question || command,
|
|
178
|
-
reads: options.helperReads || [],
|
|
179
|
-
externalPaths: external,
|
|
180
|
-
authority: "read-only-evidence-only",
|
|
181
|
-
writesProducts: false,
|
|
182
|
-
delegates: false,
|
|
183
|
-
completionAuthority: false,
|
|
184
|
-
reportSchema: REPORT_SCHEMA,
|
|
185
|
-
};
|
|
186
|
-
return {
|
|
187
|
-
version: BRIEF_VERSION,
|
|
188
|
-
status: "ready",
|
|
189
|
-
target,
|
|
190
|
-
brief,
|
|
191
|
-
reasons: [],
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
function snapshotRepo(repo) {
|
|
196
|
-
const snapshot = {};
|
|
197
|
-
const walk = (dir) => {
|
|
198
|
-
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
199
|
-
if (entry.name === ".git") continue;
|
|
200
|
-
const full = path.join(dir, entry.name);
|
|
201
|
-
if (entry.isDirectory()) {
|
|
202
|
-
walk(full);
|
|
203
|
-
} else if (entry.isFile()) {
|
|
204
|
-
const rel = path.relative(repo, full).replace(/\\/g, "/");
|
|
205
|
-
const bytes = fs.readFileSync(full);
|
|
206
|
-
const hash = crypto.createHash("sha256").update(bytes).digest("hex");
|
|
207
|
-
const mode = fs.statSync(full).mode & 0o777;
|
|
208
|
-
snapshot[rel] = `${hash}:${mode.toString(8)}`;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
};
|
|
212
|
-
walk(repo);
|
|
213
|
-
return snapshot;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
function captureHelperBaseline(repo, options) {
|
|
217
|
-
const outPath = options.helperBaseline;
|
|
218
|
-
if (!outPath) {
|
|
219
|
-
throw new Error("helper baseline capture requires --baseline");
|
|
220
|
-
}
|
|
221
|
-
if (!isExternal(repo, outPath)) {
|
|
222
|
-
throw new Error(
|
|
223
|
-
"helper baseline must be written outside the repository worktree"
|
|
224
|
-
);
|
|
225
|
-
}
|
|
226
|
-
const snapshot = snapshotRepo(repo);
|
|
227
|
-
fs.mkdirSync(path.dirname(path.resolve(outPath)), { recursive: true });
|
|
228
|
-
fs.writeFileSync(
|
|
229
|
-
path.resolve(outPath),
|
|
230
|
-
`${JSON.stringify({ version: BASELINE_VERSION, snapshot }, null, 2)}\n`,
|
|
231
|
-
"utf8"
|
|
232
|
-
);
|
|
233
|
-
return {
|
|
234
|
-
version: BASELINE_VERSION,
|
|
235
|
-
status: "captured",
|
|
236
|
-
path: path.resolve(outPath),
|
|
237
|
-
count: Object.keys(snapshot).length,
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
function classifyChanges(before, after) {
|
|
242
|
-
const changes = [];
|
|
243
|
-
for (const [rel, value] of Object.entries(after)) {
|
|
244
|
-
if (!(rel in before)) {
|
|
245
|
-
changes.push({ path: rel, kind: "added" });
|
|
246
|
-
} else if (before[rel] !== after[rel]) {
|
|
247
|
-
const [beforeHash, beforeMode] = before[rel].split(":");
|
|
248
|
-
const [afterHash] = value.split(":");
|
|
249
|
-
changes.push({
|
|
250
|
-
path: rel,
|
|
251
|
-
kind: beforeHash === afterHash ? "permission-changed" : "modified",
|
|
252
|
-
});
|
|
253
|
-
void beforeMode;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
for (const rel of Object.keys(before)) {
|
|
257
|
-
if (!(rel in after)) {
|
|
258
|
-
changes.push({ path: rel, kind: "removed" });
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
return changes.sort((a, b) => a.path.localeCompare(b.path));
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
function verifyHelperEvidence(repo, options) {
|
|
265
|
-
const baselinePath = options.helperBaseline;
|
|
266
|
-
if (!baselinePath || !fs.existsSync(path.resolve(baselinePath))) {
|
|
267
|
-
return {
|
|
268
|
-
version: VERIFY_VERSION,
|
|
269
|
-
status: "unverifiable",
|
|
270
|
-
target: options.target,
|
|
271
|
-
changes: [],
|
|
272
|
-
cleanup: "none",
|
|
273
|
-
reasons: [
|
|
274
|
-
"Byte stability cannot be established without a recorded baseline; the "
|
|
275
|
-
+ "verification remains current-agent work.",
|
|
276
|
-
],
|
|
277
|
-
};
|
|
278
|
-
}
|
|
279
|
-
let baseline;
|
|
280
|
-
try {
|
|
281
|
-
baseline = JSON.parse(fs.readFileSync(path.resolve(baselinePath), "utf8"));
|
|
282
|
-
} catch {
|
|
283
|
-
return {
|
|
284
|
-
version: VERIFY_VERSION,
|
|
285
|
-
status: "unverifiable",
|
|
286
|
-
target: options.target,
|
|
287
|
-
changes: [],
|
|
288
|
-
cleanup: "none",
|
|
289
|
-
reasons: [
|
|
290
|
-
"Recorded helper baseline is unreadable; byte stability cannot be "
|
|
291
|
-
+ "established and the verification remains current-agent work.",
|
|
292
|
-
],
|
|
293
|
-
};
|
|
294
|
-
}
|
|
295
|
-
const before = baseline.snapshot || {};
|
|
296
|
-
const after = snapshotRepo(repo);
|
|
297
|
-
const changes = classifyChanges(before, after);
|
|
298
|
-
if (changes.length === 0) {
|
|
299
|
-
return {
|
|
300
|
-
version: VERIFY_VERSION,
|
|
301
|
-
status: "verified",
|
|
302
|
-
target: options.target,
|
|
303
|
-
changes: [],
|
|
304
|
-
cleanup: "none",
|
|
305
|
-
reasons: [],
|
|
306
|
-
};
|
|
307
|
-
}
|
|
308
|
-
return {
|
|
309
|
-
version: VERIFY_VERSION,
|
|
310
|
-
status: "rejected",
|
|
311
|
-
target: options.target,
|
|
312
|
-
changes,
|
|
313
|
-
// The helper never restores, deletes, or attributes; it reports exact paths.
|
|
314
|
-
cleanup: "none",
|
|
315
|
-
reasons: [
|
|
316
|
-
"Helper evidence rejected: repository bytes changed at "
|
|
317
|
-
+ changes.map((item) => `${item.path} (${item.kind})`).join(", ")
|
|
318
|
-
+ "; the current agent owns these paths and no cleanup is performed.",
|
|
319
|
-
],
|
|
320
|
-
};
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
function renderHelper(result) {
|
|
324
|
-
const lines = [
|
|
325
|
-
`Keel helper: ${result.status}`,
|
|
326
|
-
`Version: ${result.version}`,
|
|
327
|
-
];
|
|
328
|
-
if (result.target) lines.push(`Target: ${result.target}`);
|
|
329
|
-
for (const change of result.changes || []) {
|
|
330
|
-
lines.push(`Changed: ${change.path} (${change.kind})`);
|
|
331
|
-
}
|
|
332
|
-
for (const reason of result.reasons || []) lines.push(`Reason: ${reason}`);
|
|
333
|
-
return `${lines.join("\n")}\n`;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
module.exports = {
|
|
337
|
-
BRIEF_VERSION,
|
|
338
|
-
BASELINE_VERSION,
|
|
339
|
-
VERIFY_VERSION,
|
|
340
|
-
SUPPORTED_HELPER_TARGETS,
|
|
341
|
-
compileHelperBrief,
|
|
342
|
-
captureHelperBaseline,
|
|
343
|
-
verifyHelperEvidence,
|
|
344
|
-
renderHelper,
|
|
345
|
-
};
|