@christang/keel 5.104.0 → 5.105.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/README.md +24 -7
- package/assets/bootstrap/AGENTS.md +1 -1
- package/bin/keel.js +16 -4
- 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 -1
- package/plugins/keel/hooks/hooks.json +20 -3
- package/plugins/keel/scripts/pretooluse-guard.js +299 -0
- package/scripts/validate_plugin.py +158 -6
- package/src/core/capabilities.js +4 -3
- package/src/core/config.js +67 -7
package/README.md
CHANGED
|
@@ -30,7 +30,8 @@ What Keel adds:
|
|
|
30
30
|
check that the task contract and evidence are present; they do not judge whether the design
|
|
31
31
|
is correct.
|
|
32
32
|
- **A write guard (Claude).** After `task-start`, a `PreToolUse` hook rejects any edit
|
|
33
|
-
outside the files the task declared it would touch.
|
|
33
|
+
outside the files the task declared it would touch. Where `push:<branch glob>` is declared, it
|
|
34
|
+
also refuses a `git push` to any other branch, with or without a task.
|
|
34
35
|
- **Expectation alignment.** Before specs and tasks are finalized, Keel surfaces hidden
|
|
35
36
|
assumptions and asks about the ones that actually change behavior.
|
|
36
37
|
|
|
@@ -181,7 +182,7 @@ because a permission granted in conversation does not survive a context reset. D
|
|
|
181
182
|
`keel/config.yaml` instead:
|
|
182
183
|
|
|
183
184
|
```yaml
|
|
184
|
-
authorize: # accepted names: commit, push, release, archive, continuation, issue:<owner>/<repo>, protocol-refresh, chat-reply:<group
|
|
185
|
+
authorize: # accepted names: commit, push, push:<branch glob>, release, archive, continuation, issue:<owner>/<repo>, protocol-refresh, chat-reply:<group>, issue-close:<owner>/<repo>, cleanup:scratch
|
|
185
186
|
- commit
|
|
186
187
|
- push
|
|
187
188
|
```
|
|
@@ -201,14 +202,30 @@ whose vocabulary predates the word, the entry is unrecognized and the whole decl
|
|
|
201
202
|
nothing until corrected — fail-closed, never a silent grant.
|
|
202
203
|
|
|
203
204
|
`issue:<owner>/<repo>`, the sixth name, names the resource it reaches, and it is refused without
|
|
204
|
-
one; `chat-reply:<group>`, the eighth,
|
|
205
|
-
checkout the declaration sits in, so each is already bounded by the repository you declared it in. The credentials that open an issue are not:
|
|
205
|
+
one; `chat-reply:<group>`, the eighth, and `issue-close:<owner>/<repo>` and `cleanup:scratch`, the ninth
|
|
206
|
+
and tenth, are the others that do. The other names act on the checkout the declaration sits in, so each is already bounded by the repository you declared it in. The credentials that open an issue are not:
|
|
206
207
|
`gh` is account-wide, so a bare `issue` would reach every repository your account can touch —
|
|
207
208
|
silently the widest entry in the file, and wider than `push`. Naming the repository keeps the
|
|
208
209
|
grant the size of what it says. Keel carries that scope to `keel --doctor` and to the compiled
|
|
209
210
|
capsule and **does not enforce it**: it invokes no tracker client and cannot observe one, exactly
|
|
210
|
-
as it never commits on your behalf either. Closing an issue is
|
|
211
|
-
|
|
211
|
+
as it never commits on your behalf either. Closing an issue is a separate name,
|
|
212
|
+
`issue-close:<owner>/<repo>` (#257): a merge made by an automation token does not fire
|
|
213
|
+
`Closes #<n>`, so a session that finished the work closes the issue itself, with a comment naming
|
|
214
|
+
the pull request that resolved it. Keel carries that scope the same way and does not enforce it.
|
|
215
|
+
|
|
216
|
+
`push:<branch glob>` narrows `push` to the branches a session may push (#257) — for example
|
|
217
|
+
`push:claude/*` and `push:worktree-*` in a repository where only the coordinator pushes `main`.
|
|
218
|
+
Declare one entry per glob; `*` matches within one `/` segment and `**` across them. Unlike every
|
|
219
|
+
other scope, this one is enforced: while any `push:` glob is declared, the Claude write guard checks
|
|
220
|
+
every `git push` a `Bash` call runs, with or without a task, and refuses one to any other branch, or
|
|
221
|
+
one whose target it cannot tell — `--all`, `--mirror`, `--tags`, a shell variable, no configured
|
|
222
|
+
push destination — naming `git push origin <branch>` instead. A bare `push` keeps its old meaning,
|
|
223
|
+
and declaring it beside a `push:` glob is refused, because it would silently widen the glob. Codex
|
|
224
|
+
has no such hook, so there the scope is carried, not enforced.
|
|
225
|
+
|
|
226
|
+
`cleanup:scratch` covers removing temporary worktrees and run output under the session's own
|
|
227
|
+
scratchpad, after checking that they are merged and that no process is using them. It never covers
|
|
228
|
+
a branch or another session's files, and like the tracker scopes it is carried, not enforced.
|
|
212
229
|
|
|
213
230
|
`protocol-refresh`, the seventh name, covers the one piece of a release that a plugin update cannot
|
|
214
231
|
carry: the managed protocol block in this repository's `AGENTS.md`, which moves only when
|
|
@@ -234,7 +251,7 @@ Three things the declaration is not:
|
|
|
234
251
|
anything.
|
|
235
252
|
- **Not a trigger.** It removes a confirmation, not the step that reaches the action. Nothing
|
|
236
253
|
schedules itself, and no next task is selected for you.
|
|
237
|
-
- **Not open-ended.** The
|
|
254
|
+
- **Not open-ended.** The ten names above are the whole vocabulary. An unrecognized entry is
|
|
238
255
|
reported with the accepted names and the declaration authorizes nothing until you fix it — a
|
|
239
256
|
typo never becomes a silent grant.
|
|
240
257
|
|
package/bin/keel.js
CHANGED
|
@@ -2254,13 +2254,25 @@ function printStandingAuthorizationSurface(repo) {
|
|
|
2254
2254
|
// observes none that an agent runs, so the scope is a declaration carried to
|
|
2255
2255
|
// the people who read it rather than a boundary anything holds. A reader who
|
|
2256
2256
|
// took it for a sandbox would be relying on nothing.
|
|
2257
|
-
if ([...scopes.
|
|
2257
|
+
if ([...scopes.entries()].some(([action, scope]) => scope !== null && action !== "push")) {
|
|
2258
2258
|
printDoctorLine(
|
|
2259
2259
|
"scope",
|
|
2260
2260
|
"carried",
|
|
2261
|
-
"Keel records a scope and does not enforce
|
|
2262
|
-
+ "client and cannot observe one, so the
|
|
2263
|
-
+ "acts, not by this check"
|
|
2261
|
+
"Keel records a tracker, chat, or scratchpad scope and does not enforce "
|
|
2262
|
+
+ "it — it invokes no tracker client and cannot observe one, so the "
|
|
2263
|
+
+ "boundary is kept by whoever acts, not by this check"
|
|
2264
|
+
);
|
|
2265
|
+
}
|
|
2266
|
+
// The one scope something holds (#257): the Claude write guard reads the
|
|
2267
|
+
// `push:` globs and refuses a `git push` to any other branch, with or
|
|
2268
|
+
// without a task. Codex has no such hook, so there it is a declaration too.
|
|
2269
|
+
if (scopes.get("push")) {
|
|
2270
|
+
printDoctorLine(
|
|
2271
|
+
"push scope",
|
|
2272
|
+
"enforced",
|
|
2273
|
+
"the Claude write guard enforces these globs: it refuses a `git push` "
|
|
2274
|
+
+ "to any other branch, or one whose target it cannot determine, with "
|
|
2275
|
+
+ "or without a task; on Codex the scope is carried, not enforced"
|
|
2264
2276
|
);
|
|
2265
2277
|
}
|
|
2266
2278
|
return true;
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@christang/keel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.105.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@christang/keel",
|
|
9
|
-
"version": "5.
|
|
9
|
+
"version": "5.105.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@fission-ai/openspec": "^1.4.1"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.105.0",
|
|
4
4
|
"description": "Keel OpenSpec execution discipline: stateless continuity, task capsules, deterministic gates, and expectation alignment for Codex and Claude Code.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "TanglmChris",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.105.0",
|
|
4
4
|
"description": "Keel OpenSpec execution discipline: stateless continuity, task capsules, deterministic gates, and expectation alignment for Codex and Claude Code.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "TanglmChris",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"description": "Keel plugin hooks: non-blocking SessionStart projection
|
|
2
|
+
"description": "Keel plugin hooks: non-blocking SessionStart projection, the manifest-gated PreToolUse write guard, and its push-branch check on Bash, all backed by the shared keel CLI contract.",
|
|
3
3
|
"hooks": {
|
|
4
4
|
"SessionStart": [
|
|
5
5
|
{
|
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
{
|
|
8
8
|
"type": "command",
|
|
9
9
|
"command": "node",
|
|
10
|
-
"args": [
|
|
10
|
+
"args": [
|
|
11
|
+
"${CLAUDE_PLUGIN_ROOT}/scripts/session-start.js"
|
|
12
|
+
],
|
|
11
13
|
"timeout": 15
|
|
12
14
|
}
|
|
13
15
|
]
|
|
@@ -20,7 +22,22 @@
|
|
|
20
22
|
{
|
|
21
23
|
"type": "command",
|
|
22
24
|
"command": "node",
|
|
23
|
-
"args": [
|
|
25
|
+
"args": [
|
|
26
|
+
"${CLAUDE_PLUGIN_ROOT}/scripts/pretooluse-guard.js"
|
|
27
|
+
],
|
|
28
|
+
"timeout": 10
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"matcher": "Bash",
|
|
34
|
+
"hooks": [
|
|
35
|
+
{
|
|
36
|
+
"type": "command",
|
|
37
|
+
"command": "node",
|
|
38
|
+
"args": [
|
|
39
|
+
"${CLAUDE_PLUGIN_ROOT}/scripts/pretooluse-guard.js"
|
|
40
|
+
],
|
|
24
41
|
"timeout": 10
|
|
25
42
|
}
|
|
26
43
|
]
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
const crypto = require("crypto");
|
|
17
17
|
const fs = require("fs");
|
|
18
18
|
const path = require("path");
|
|
19
|
+
const { spawnSync } = require("child_process");
|
|
19
20
|
|
|
20
21
|
// A newer installed copy of this script runs in its place when the host has
|
|
21
22
|
// installed one (forward.js, #204). A copy of this script without forward.js
|
|
@@ -157,6 +158,302 @@ function repoRelative(repo, target) {
|
|
|
157
158
|
);
|
|
158
159
|
}
|
|
159
160
|
|
|
161
|
+
// --- push-branch check (#257) -------------------------------------------------
|
|
162
|
+
//
|
|
163
|
+
// While keel/config.yaml declares `push:<branch glob>`, every `git push` a Bash
|
|
164
|
+
// call runs must target a matching branch, with or without a task manifest.
|
|
165
|
+
// The globs are read here rather than through the declaration's validator, so
|
|
166
|
+
// a typo elsewhere in `authorize:` — which voids the declaration — leaves the
|
|
167
|
+
// check standing: a broken declaration fails toward more checking (D3).
|
|
168
|
+
|
|
169
|
+
const EXPLICIT_FORM = "`git push origin <branch>`";
|
|
170
|
+
|
|
171
|
+
function gitOut(cwd, args) {
|
|
172
|
+
const result = spawnSync("git", ["-C", cwd, ...args], { encoding: "utf8", timeout: 3000 });
|
|
173
|
+
return result.status === 0 ? String(result.stdout || "").trim() : null;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function readPushGlobs(top) {
|
|
177
|
+
let text = "";
|
|
178
|
+
try {
|
|
179
|
+
text = fs.readFileSync(path.join(top, "keel", "config.yaml"), "utf8");
|
|
180
|
+
} catch {
|
|
181
|
+
return [];
|
|
182
|
+
}
|
|
183
|
+
const globs = [];
|
|
184
|
+
let inBlock = false;
|
|
185
|
+
for (const line of text.split(/\r?\n/)) {
|
|
186
|
+
if (/^\s*#/.test(line) || line.trim() === "") continue;
|
|
187
|
+
if (/^authorize\s*:\s*$/.test(line)) {
|
|
188
|
+
inBlock = true;
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
if (!inBlock) continue;
|
|
192
|
+
if (!/^\s/.test(line)) break;
|
|
193
|
+
const entry = line.match(/^\s+-\s*push:(\S+)\s*$/);
|
|
194
|
+
if (entry) globs.push(entry[1]);
|
|
195
|
+
}
|
|
196
|
+
return globs;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Shell words and the separators between commands. Quotes are honoured, and a
|
|
200
|
+
// word that the shell would expand (`$`, a backtick) is marked, because its
|
|
201
|
+
// value is not knowable here.
|
|
202
|
+
function shellSegments(command) {
|
|
203
|
+
const segments = [];
|
|
204
|
+
let words = [];
|
|
205
|
+
let word = null;
|
|
206
|
+
let expands = false;
|
|
207
|
+
const finishWord = () => {
|
|
208
|
+
if (word !== null) words.push({ text: word, expands });
|
|
209
|
+
word = null;
|
|
210
|
+
expands = false;
|
|
211
|
+
};
|
|
212
|
+
const finishSegment = () => {
|
|
213
|
+
finishWord();
|
|
214
|
+
if (words.length) segments.push(words);
|
|
215
|
+
words = [];
|
|
216
|
+
};
|
|
217
|
+
// Heredoc bodies are data, not commands: `<<'EOF'` … `EOF` is skipped from
|
|
218
|
+
// the end of its line to the terminator, so a body line reading like a push
|
|
219
|
+
// is not taken for one.
|
|
220
|
+
const pendingHeredocs = [];
|
|
221
|
+
for (let i = 0; i < command.length; i += 1) {
|
|
222
|
+
const c = command[i];
|
|
223
|
+
if (c === "<" && command[i + 1] === "<" && command[i + 2] !== "<") {
|
|
224
|
+
const marker = command.slice(i + 2).match(/^-?\s*(['"]?)([A-Za-z_][A-Za-z0-9_]*)\1/);
|
|
225
|
+
if (marker) {
|
|
226
|
+
pendingHeredocs.push(marker[2]);
|
|
227
|
+
finishWord();
|
|
228
|
+
i += 1 + marker[0].length;
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (c === "\n" && pendingHeredocs.length) {
|
|
233
|
+
finishSegment();
|
|
234
|
+
let rest = i + 1;
|
|
235
|
+
while (pendingHeredocs.length) {
|
|
236
|
+
const terminator = pendingHeredocs.shift();
|
|
237
|
+
const lines = command.slice(rest).split("\n");
|
|
238
|
+
let consumed = 0;
|
|
239
|
+
for (const line of lines) {
|
|
240
|
+
consumed += line.length + 1;
|
|
241
|
+
if (line.replace(/^\t+/, "") === terminator) break;
|
|
242
|
+
}
|
|
243
|
+
rest += consumed;
|
|
244
|
+
}
|
|
245
|
+
i = rest - 1;
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
if (c === "'") {
|
|
249
|
+
const end = command.indexOf("'", i + 1);
|
|
250
|
+
word = (word || "") + command.slice(i + 1, end === -1 ? command.length : end);
|
|
251
|
+
i = end === -1 ? command.length : end;
|
|
252
|
+
} else if (c === '"') {
|
|
253
|
+
let j = i + 1;
|
|
254
|
+
let text = "";
|
|
255
|
+
while (j < command.length && command[j] !== '"') {
|
|
256
|
+
if (command[j] === "\\" && j + 1 < command.length) {
|
|
257
|
+
text += command[j + 1];
|
|
258
|
+
j += 2;
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
if (command[j] === "$" || command[j] === "`") expands = true;
|
|
262
|
+
text += command[j];
|
|
263
|
+
j += 1;
|
|
264
|
+
}
|
|
265
|
+
word = (word || "") + text;
|
|
266
|
+
i = j;
|
|
267
|
+
} else if (c === "\\" && i + 1 < command.length) {
|
|
268
|
+
word = (word || "") + command[i + 1];
|
|
269
|
+
i += 1;
|
|
270
|
+
} else if (c === "$" || c === "`") {
|
|
271
|
+
expands = true;
|
|
272
|
+
word = (word || "") + c;
|
|
273
|
+
} else if (c === ";" || c === "\n" || c === "&" || c === "|" || c === "(" || c === ")") {
|
|
274
|
+
finishSegment();
|
|
275
|
+
} else if (/\s/.test(c)) {
|
|
276
|
+
finishWord();
|
|
277
|
+
} else {
|
|
278
|
+
word = (word || "") + c;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
finishSegment();
|
|
282
|
+
return segments;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
const PREFIX_COMMANDS = new Set(["env", "command", "exec", "nohup", "time", "sudo"]);
|
|
286
|
+
const SHELLS = new Set(["bash", "sh", "zsh", "eval"]);
|
|
287
|
+
const PUSH_FLAGS = new Set([
|
|
288
|
+
"-u", "--set-upstream", "-f", "--force", "--force-if-includes", "--no-force-if-includes",
|
|
289
|
+
"-n", "--dry-run", "--no-verify", "--verify", "-q", "--quiet", "-v", "--verbose",
|
|
290
|
+
"--porcelain", "--progress", "--no-progress", "--atomic", "--no-atomic", "--no-signed",
|
|
291
|
+
"--thin", "--no-thin", "--follow-tags", "--no-follow-tags", "-4", "--ipv4", "-6", "--ipv6",
|
|
292
|
+
"--prune", "--no-recurse-submodules", "--force-with-lease", "--signed", "-d", "--delete",
|
|
293
|
+
]);
|
|
294
|
+
const PUSH_VALUED = new Set(["-o", "--push-option", "--repo", "--receive-pack", "--exec"]);
|
|
295
|
+
const PUSH_UNDETERMINED = new Set(["--all", "--branches", "--mirror", "--tags"]);
|
|
296
|
+
|
|
297
|
+
// The pushes a command runs, each as { dir, cdBefore, args } or { undetermined }.
|
|
298
|
+
function findPushes(command, cwd) {
|
|
299
|
+
const pushes = [];
|
|
300
|
+
let cdBefore = false;
|
|
301
|
+
for (const words of shellSegments(command)) {
|
|
302
|
+
let i = 0;
|
|
303
|
+
while (i < words.length && /^[A-Za-z_][A-Za-z0-9_]*=/.test(words[i].text)) i += 1;
|
|
304
|
+
while (i < words.length && PREFIX_COMMANDS.has(words[i].text)) i += 1;
|
|
305
|
+
const head = words[i] ? words[i].text : "";
|
|
306
|
+
if (head === "cd" || head === "pushd") {
|
|
307
|
+
cdBefore = true;
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
if (SHELLS.has(head)) {
|
|
311
|
+
if (/\bgit\b[\s\S]*\bpush\b/.test(words.slice(i + 1).map((w) => w.text).join(" "))) {
|
|
312
|
+
pushes.push({ undetermined: `it runs \`git push\` inside \`${head}\`` });
|
|
313
|
+
}
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
if (head !== "git") continue;
|
|
317
|
+
let dir = cwd;
|
|
318
|
+
i += 1;
|
|
319
|
+
let unknownGlobal = null;
|
|
320
|
+
while (i < words.length && words[i].text.startsWith("-")) {
|
|
321
|
+
const option = words[i].text;
|
|
322
|
+
if (option === "-C" && words[i + 1]) {
|
|
323
|
+
dir = path.resolve(dir, words[i + 1].text);
|
|
324
|
+
i += 2;
|
|
325
|
+
} else if (option === "-c" && words[i + 1]) {
|
|
326
|
+
i += 2;
|
|
327
|
+
} else if (option === "--no-pager" || option === "-P") {
|
|
328
|
+
i += 1;
|
|
329
|
+
} else {
|
|
330
|
+
unknownGlobal = option;
|
|
331
|
+
i += 1;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
if (!words[i] || words[i].text !== "push") continue;
|
|
335
|
+
if (unknownGlobal) {
|
|
336
|
+
pushes.push({ undetermined: `the git option \`${unknownGlobal}\` is not one the guard reads` });
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
pushes.push({ dir, cdBefore, args: words.slice(i + 1) });
|
|
340
|
+
}
|
|
341
|
+
return pushes;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
function currentBranch(dir) {
|
|
345
|
+
return gitOut(dir, ["symbolic-ref", "--short", "-q", "HEAD"]);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// The branch a push with no refspec goes to: its configured push destination.
|
|
349
|
+
function pushDestination(dir) {
|
|
350
|
+
const ref = gitOut(dir, ["rev-parse", "--symbolic-full-name", "@{push}"]);
|
|
351
|
+
if (!ref || !ref.startsWith("refs/remotes/")) return null;
|
|
352
|
+
const rest = ref.slice("refs/remotes/".length);
|
|
353
|
+
const remotes = (gitOut(dir, ["remote"]) || "").split(/\s+/).filter(Boolean)
|
|
354
|
+
.sort((a, b) => b.length - a.length);
|
|
355
|
+
const remote = remotes.find((name) => rest.startsWith(`${name}/`));
|
|
356
|
+
return remote ? rest.slice(remote.length + 1) : null;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// Target branches of one push, or { undetermined: reason }.
|
|
360
|
+
function pushTargets(push) {
|
|
361
|
+
if (push.undetermined) return push;
|
|
362
|
+
const positionals = [];
|
|
363
|
+
let deleting = false;
|
|
364
|
+
for (let i = 0; i < push.args.length; i += 1) {
|
|
365
|
+
const word = push.args[i];
|
|
366
|
+
if (word.expands) return { undetermined: `\`${word.text}\` is expanded by the shell` };
|
|
367
|
+
const text = word.text;
|
|
368
|
+
if (text === "--") {
|
|
369
|
+
positionals.push(...push.args.slice(i + 1).map((w) => w.text));
|
|
370
|
+
break;
|
|
371
|
+
}
|
|
372
|
+
if (!text.startsWith("-") || text === "-") {
|
|
373
|
+
positionals.push(text);
|
|
374
|
+
continue;
|
|
375
|
+
}
|
|
376
|
+
const name = text.includes("=") ? text.slice(0, text.indexOf("=")) : text;
|
|
377
|
+
if (PUSH_UNDETERMINED.has(name)) return { undetermined: `\`${name}\` pushes refs the guard cannot list` };
|
|
378
|
+
if (name === "-d" || name === "--delete") deleting = true;
|
|
379
|
+
if (PUSH_VALUED.has(name)) {
|
|
380
|
+
if (!text.includes("=")) i += 1;
|
|
381
|
+
continue;
|
|
382
|
+
}
|
|
383
|
+
if (PUSH_FLAGS.has(name) || name.startsWith("--force-with-lease") || name.startsWith("--signed")
|
|
384
|
+
|| name.startsWith("--recurse-submodules")) {
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
387
|
+
if (/^-[a-zA-Z0-9]{2,}$/.test(text) && [...text.slice(1)].every((c) => PUSH_FLAGS.has(`-${c}`))) {
|
|
388
|
+
if (text.includes("d")) deleting = true;
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
return { undetermined: `the push option \`${text}\` is not one the guard reads` };
|
|
392
|
+
}
|
|
393
|
+
const refspecs = positionals.slice(1);
|
|
394
|
+
const needsCurrent = () => {
|
|
395
|
+
if (push.cdBefore) return { undetermined: "the directory changes before it, so its branch is unknown here" };
|
|
396
|
+
return null;
|
|
397
|
+
};
|
|
398
|
+
if (!refspecs.length) {
|
|
399
|
+
const unknown = needsCurrent();
|
|
400
|
+
if (unknown) return unknown;
|
|
401
|
+
const branch = pushDestination(push.dir);
|
|
402
|
+
return branch ? { targets: [branch] } : { undetermined: "the branch has no configured push destination" };
|
|
403
|
+
}
|
|
404
|
+
const targets = [];
|
|
405
|
+
for (const raw of refspecs) {
|
|
406
|
+
const spec = raw.replace(/^\+/, "");
|
|
407
|
+
let dst = spec;
|
|
408
|
+
if (!deleting && spec.includes(":")) dst = spec.slice(spec.indexOf(":") + 1);
|
|
409
|
+
else if (spec.startsWith(":")) dst = spec.slice(1);
|
|
410
|
+
if (!dst) return { undetermined: `\`${raw}\` names no destination` };
|
|
411
|
+
if (dst === "HEAD" || dst === "@") {
|
|
412
|
+
const unknown = needsCurrent();
|
|
413
|
+
if (unknown) return unknown;
|
|
414
|
+
dst = currentBranch(push.dir);
|
|
415
|
+
if (!dst) return { undetermined: "HEAD is detached" };
|
|
416
|
+
}
|
|
417
|
+
if (dst.startsWith("refs/heads/")) dst = dst.slice("refs/heads/".length);
|
|
418
|
+
else if (dst.startsWith("refs/")) return { undetermined: `\`${raw}\` is not a branch` };
|
|
419
|
+
targets.push(dst);
|
|
420
|
+
}
|
|
421
|
+
return { targets };
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
function checkPushes(event) {
|
|
425
|
+
const command = event.tool_input && typeof event.tool_input.command === "string"
|
|
426
|
+
? event.tool_input.command : "";
|
|
427
|
+
if (!/\bgit\b/.test(command) || !/\bpush\b/.test(command)) return 0;
|
|
428
|
+
const cwd = typeof event.cwd === "string" && event.cwd ? event.cwd : process.cwd();
|
|
429
|
+
for (const push of findPushes(command, cwd)) {
|
|
430
|
+
const top = gitOut(push.dir || cwd, ["rev-parse", "--show-toplevel"]);
|
|
431
|
+
if (!top) continue;
|
|
432
|
+
const globs = readPushGlobs(top);
|
|
433
|
+
if (!globs.length) continue;
|
|
434
|
+
const declared = globs.map((glob) => `\`push:${glob}\``).join(", ");
|
|
435
|
+
const result = pushTargets(push);
|
|
436
|
+
if (result.undetermined) {
|
|
437
|
+
deny(
|
|
438
|
+
`Keel push guard: keel/config.yaml limits push to ${declared}, and the `
|
|
439
|
+
+ `guard cannot tell which branch this push targets: ${result.undetermined}. `
|
|
440
|
+
+ `Name the branch, as ${EXPLICIT_FORM}.`
|
|
441
|
+
);
|
|
442
|
+
return 0;
|
|
443
|
+
}
|
|
444
|
+
const outside = result.targets.filter((branch) => !globs.some((glob) => globPattern(glob).test(branch)));
|
|
445
|
+
if (outside.length) {
|
|
446
|
+
deny(
|
|
447
|
+
`Keel push guard: this command pushes to ${outside.map((b) => `\`${b}\``).join(", ")}, `
|
|
448
|
+
+ `and keel/config.yaml limits push to ${declared}. Push a matching branch, `
|
|
449
|
+
+ "or ask the owner; the declaration is theirs to widen."
|
|
450
|
+
);
|
|
451
|
+
return 0;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
return 0;
|
|
455
|
+
}
|
|
456
|
+
|
|
160
457
|
function main() {
|
|
161
458
|
const input = readStdin();
|
|
162
459
|
let event = {};
|
|
@@ -176,6 +473,8 @@ function main() {
|
|
|
176
473
|
if (handed !== null) return handed;
|
|
177
474
|
}
|
|
178
475
|
|
|
476
|
+
if (event.tool_name === "Bash") return checkPushes(event);
|
|
477
|
+
|
|
179
478
|
const pathField = FILE_EDIT_TOOLS.get(event.tool_name);
|
|
180
479
|
if (!pathField) return 0;
|
|
181
480
|
|
|
@@ -47,8 +47,8 @@ REQUIRED_SCRIPTS = [
|
|
|
47
47
|
"scripts/validate_plugin.py",
|
|
48
48
|
]
|
|
49
49
|
|
|
50
|
-
PACKAGE_VERSION = "5.
|
|
51
|
-
PROTOCOL_VERSION = "5.
|
|
50
|
+
PACKAGE_VERSION = "5.105.0"
|
|
51
|
+
PROTOCOL_VERSION = "5.105.0"
|
|
52
52
|
LEGACY_MANAGED_START = "<!-- keel:start version=2.1 -->"
|
|
53
53
|
OPENSPEC_SCHEMA_NAME = "keel-spec-driven"
|
|
54
54
|
# Mirrors KEEL_PACKAGE_NAME in scripts/install_to_repo.py, one of the two
|
|
@@ -24084,6 +24084,72 @@ def write_authorize_config(repo: Path, body: str) -> None:
|
|
|
24084
24084
|
(repo / "keel" / "config.yaml").write_text(body, encoding="utf-8")
|
|
24085
24085
|
|
|
24086
24086
|
|
|
24087
|
+
def validate_authorize_push_close_cleanup_scenario() -> int:
|
|
24088
|
+
"""Issue #257: `push:<glob>`, `issue-close:<owner>/<repo>`, `cleanup:scratch`.
|
|
24089
|
+
|
|
24090
|
+
Each is reported with its scope, a task with no boundary inherits all of
|
|
24091
|
+
them, and each wrong form is refused naming the form it needs.
|
|
24092
|
+
"""
|
|
24093
|
+
label = "authorize-push-close-cleanup:"
|
|
24094
|
+
with tempfile.TemporaryDirectory(prefix="keel-authorize-257-") as raw_tmp:
|
|
24095
|
+
root = Path(raw_tmp)
|
|
24096
|
+
|
|
24097
|
+
def fixture(name: str, entries: list[str]) -> Path:
|
|
24098
|
+
repo = root / name
|
|
24099
|
+
repo.mkdir()
|
|
24100
|
+
write_authorize_config(repo, "authorize:\n" + "".join(f" - {e}\n" for e in entries))
|
|
24101
|
+
return repo
|
|
24102
|
+
|
|
24103
|
+
good = fixture("good", ["push:claude/*", "push:worktree-*", "issue-close:acme/widgets", "cleanup:scratch"])
|
|
24104
|
+
doctor = run_keel(good, "--doctor")
|
|
24105
|
+
lines = doctor.stdout.splitlines()
|
|
24106
|
+
|
|
24107
|
+
def line_for(action: str) -> str:
|
|
24108
|
+
return next((l for l in lines if l.strip().startswith(f"{action}:")), "")
|
|
24109
|
+
|
|
24110
|
+
for action, needles in (
|
|
24111
|
+
("push", ("authorized", "claude/*", "worktree-*")),
|
|
24112
|
+
("issue-close", ("authorized", "acme/widgets")),
|
|
24113
|
+
("cleanup", ("authorized", "scratch")),
|
|
24114
|
+
):
|
|
24115
|
+
line = line_for(action)
|
|
24116
|
+
missing = [n for n in needles if n not in line]
|
|
24117
|
+
if missing:
|
|
24118
|
+
report(f"{label} doctor's {action} line lacks {missing!r}: {line!r}")
|
|
24119
|
+
report(doctor.stdout)
|
|
24120
|
+
return 1
|
|
24121
|
+
if "write guard enforces" not in doctor.stdout:
|
|
24122
|
+
report(f"{label} doctor does not say the write guard enforces the push globs.")
|
|
24123
|
+
report(doctor.stdout)
|
|
24124
|
+
return 1
|
|
24125
|
+
|
|
24126
|
+
write_text(good / "openspec/changes/inherit/tasks.md", task_capsule_compact_fixture().replace(
|
|
24127
|
+
" - Autonomy boundary:\n - Default: hard-stop\n - Pre-authorized fallback: none\n", ""))
|
|
24128
|
+
started = run_keel(good, "gate", "task-start", "--change", "inherit", "--task", "1.1", "--json")
|
|
24129
|
+
text = started.stdout
|
|
24130
|
+
inherited = "push:claude/*, push:worktree-*, issue-close:acme/widgets, cleanup:scratch"
|
|
24131
|
+
if inherited not in text:
|
|
24132
|
+
report(f"{label} the inherited autonomy entry does not name all four: {text[:1500]}")
|
|
24133
|
+
return 1
|
|
24134
|
+
|
|
24135
|
+
for name, entries, needles in (
|
|
24136
|
+
("mixed", ["push", "push:claude/*"], ("push", "push:claude/*")),
|
|
24137
|
+
("bare-close", ["issue-close"], ("issue-close:<owner>/<repo>",)),
|
|
24138
|
+
("cleanup-runs", ["cleanup:runs"], ("cleanup:scratch",)),
|
|
24139
|
+
("bad-glob", ["push:main?"], ("push:main?", "push:<branch glob>")),
|
|
24140
|
+
):
|
|
24141
|
+
refused = run_keel(fixture(name, entries), "--doctor")
|
|
24142
|
+
if refused.returncode == 0:
|
|
24143
|
+
report(f"{label} {entries!r} was accepted.")
|
|
24144
|
+
return 1
|
|
24145
|
+
missing = [n for n in needles if n not in refused.stdout + refused.stderr]
|
|
24146
|
+
if missing:
|
|
24147
|
+
report(f"{label} {entries!r} was refused without naming {missing!r}: {refused.stdout}")
|
|
24148
|
+
return 1
|
|
24149
|
+
report("authorize-push-close-cleanup scenario passed.")
|
|
24150
|
+
return 0
|
|
24151
|
+
|
|
24152
|
+
|
|
24087
24153
|
def validate_standing_authorization_declaration_scenario() -> int:
|
|
24088
24154
|
with tempfile.TemporaryDirectory(prefix="keel-authorize-") as raw_tmp:
|
|
24089
24155
|
root = Path(raw_tmp)
|
|
@@ -27009,6 +27075,13 @@ def validate_continuation_authorization_scenario() -> int:
|
|
|
27009
27075
|
return 0
|
|
27010
27076
|
|
|
27011
27077
|
|
|
27078
|
+
ACCEPTED_AUTHORIZE_NAMES = (
|
|
27079
|
+
"commit, push, push:<branch glob>, release, archive, continuation, "
|
|
27080
|
+
"issue:<owner>/<repo>, protocol-refresh, chat-reply:<group>, "
|
|
27081
|
+
"issue-close:<owner>/<repo>, cleanup:scratch"
|
|
27082
|
+
)
|
|
27083
|
+
|
|
27084
|
+
|
|
27012
27085
|
def validate_continuation_docs_scenario() -> int:
|
|
27013
27086
|
"""Every text an agent reads at the between-task boundary names the word (#94).
|
|
27014
27087
|
|
|
@@ -27058,9 +27131,8 @@ def validate_continuation_docs_scenario() -> int:
|
|
|
27058
27131
|
# The seventh name (#164). Each surface that spells the vocabulary out has
|
|
27059
27132
|
# to spell all of it: a reader copies from the list they are shown.
|
|
27060
27133
|
for needle in (
|
|
27061
|
-
"accepted names:
|
|
27062
|
-
"
|
|
27063
|
-
"The eight names above are the whole vocabulary.",
|
|
27134
|
+
f"accepted names: {ACCEPTED_AUTHORIZE_NAMES}",
|
|
27135
|
+
"The ten names above are the whole vocabulary.",
|
|
27064
27136
|
"`protocol-refresh`, the seventh name",
|
|
27065
27137
|
):
|
|
27066
27138
|
if needle not in readme:
|
|
@@ -27068,7 +27140,7 @@ def validate_continuation_docs_scenario() -> int:
|
|
|
27068
27140
|
return 1
|
|
27069
27141
|
|
|
27070
27142
|
config_text = (ROOT / "keel/config.yaml").read_text(encoding="utf-8")
|
|
27071
|
-
if "commit, push, release, archive
|
|
27143
|
+
if "commit, push, push:<branch glob>,\n# release, archive, continuation, issue:<owner>/<repo>, protocol-refresh,\n# chat-reply:<group>, issue-close:<owner>/<repo>, cleanup:scratch" not in config_text:
|
|
27072
27144
|
report(
|
|
27073
27145
|
f"{label}: keel/config.yaml's comment lacks: protocol-refresh in the "
|
|
27074
27146
|
"seven-name vocabulary."
|
|
@@ -29455,6 +29527,84 @@ def validate_touch_guard_record_layer_scenario() -> int:
|
|
|
29455
29527
|
return 0
|
|
29456
29528
|
|
|
29457
29529
|
|
|
29530
|
+
def validate_push_branch_guard_scenario() -> int:
|
|
29531
|
+
"""Issue #257: with `push:<glob>` declared, the hook refuses other pushes.
|
|
29532
|
+
|
|
29533
|
+
The real hook script receives `Bash` events with no task manifest. A push
|
|
29534
|
+
to a declared branch passes, one to `main` is refused by name, a bare
|
|
29535
|
+
`git push` resolves the branch's push destination, an undetermined target
|
|
29536
|
+
is refused naming the explicit form, a typo elsewhere does not lift the
|
|
29537
|
+
check, and a bare `push` declaration intercepts nothing.
|
|
29538
|
+
"""
|
|
29539
|
+
label = "push-branch-guard:"
|
|
29540
|
+
hooks = json.loads((ROOT / PLUGIN_ROOT / "hooks/hooks.json").read_text(encoding="utf-8"))
|
|
29541
|
+
matchers = [entry.get("matcher", "") for entry in hooks.get("hooks", {}).get("PreToolUse", [])]
|
|
29542
|
+
if not any("Bash" in matcher.split("|") for matcher in matchers):
|
|
29543
|
+
report(f"{label} hooks.json does not register the guard for Bash: {matchers!r}")
|
|
29544
|
+
return 1
|
|
29545
|
+
with tempfile.TemporaryDirectory(prefix="keel-push-guard-") as raw:
|
|
29546
|
+
base = Path(raw)
|
|
29547
|
+
remote = base / "remote.git"
|
|
29548
|
+
repo = base / "repo"
|
|
29549
|
+
|
|
29550
|
+
def git(*args: str, cwd: Path = repo) -> None:
|
|
29551
|
+
subprocess.run(["git", *args], cwd=cwd, check=True, capture_output=True, text=True)
|
|
29552
|
+
|
|
29553
|
+
git("init", "-q", "--bare", str(remote), cwd=base)
|
|
29554
|
+
git("init", "-q", "-b", "main", str(repo), cwd=base)
|
|
29555
|
+
git("-c", "user.name=t", "-c", "user.email=t@t", "commit", "-q", "--allow-empty", "-m", "init")
|
|
29556
|
+
git("remote", "add", "origin", str(remote))
|
|
29557
|
+
git("push", "-q", "-u", "origin", "main")
|
|
29558
|
+
git("switch", "-q", "-c", "claude/fix")
|
|
29559
|
+
git("push", "-q", "-u", "origin", "claude/fix")
|
|
29560
|
+
|
|
29561
|
+
def decide(command: str) -> dict | None:
|
|
29562
|
+
event = {"tool_name": "Bash", "tool_input": {"command": command}, "cwd": str(repo)}
|
|
29563
|
+
return pretooluse_decision(run_pretooluse_guard_hook(repo, event))
|
|
29564
|
+
|
|
29565
|
+
def denied(decision: dict | None) -> bool:
|
|
29566
|
+
return bool(decision) and decision.get("permissionDecision") == "deny"
|
|
29567
|
+
|
|
29568
|
+
write_authorize_config(repo, "authorize:\n - commit\n - push:claude/*\n")
|
|
29569
|
+
checks = [
|
|
29570
|
+
("a push to the declared branch", "git add -A && git push -u origin claude/fix", False, None),
|
|
29571
|
+
("a push to main", "git push origin HEAD:main", True, "main"),
|
|
29572
|
+
("a bare push on a branch pushing to claude/fix", "git push", False, None),
|
|
29573
|
+
("--all", "git push --all origin", True, "git push origin <branch>"),
|
|
29574
|
+
("a shell variable", 'git push origin "$BRANCH"', True, "git push origin <branch>"),
|
|
29575
|
+
]
|
|
29576
|
+
for what, command, want_deny, needle in checks:
|
|
29577
|
+
decision = decide(command)
|
|
29578
|
+
if decision and "error" in decision:
|
|
29579
|
+
report(f"{label} the hook failed on {what}: {decision['error']}")
|
|
29580
|
+
return 1
|
|
29581
|
+
if denied(decision) != want_deny:
|
|
29582
|
+
report(f"{label} {what} ({command!r}) was {'allowed' if want_deny else 'denied'}: {decision!r}")
|
|
29583
|
+
return 1
|
|
29584
|
+
if needle and needle not in decision.get("permissionDecisionReason", ""):
|
|
29585
|
+
report(f"{label} {what} was denied without naming {needle!r}: {decision!r}")
|
|
29586
|
+
return 1
|
|
29587
|
+
git("switch", "-q", "main")
|
|
29588
|
+
decision = decide("git push")
|
|
29589
|
+
if not denied(decision):
|
|
29590
|
+
report(f"{label} a bare push on a branch pushing to origin/main was allowed: {decision!r}")
|
|
29591
|
+
return 1
|
|
29592
|
+
if "main" not in decision.get("permissionDecisionReason", ""):
|
|
29593
|
+
report(f"{label} the bare push to main was denied without naming main: {decision!r}")
|
|
29594
|
+
return 1
|
|
29595
|
+
|
|
29596
|
+
write_authorize_config(repo, "authorize:\n - push:claude/*\n - deploy\n")
|
|
29597
|
+
if not denied(decide("git push origin HEAD:main")):
|
|
29598
|
+
report(f"{label} a typo elsewhere in authorize: lifted the push check.")
|
|
29599
|
+
return 1
|
|
29600
|
+
write_authorize_config(repo, "authorize:\n - push\n")
|
|
29601
|
+
if decide("git push origin HEAD:main") is not None:
|
|
29602
|
+
report(f"{label} a bare push declaration intercepted a push.")
|
|
29603
|
+
return 1
|
|
29604
|
+
report("push-branch-guard scenario passed.")
|
|
29605
|
+
return 0
|
|
29606
|
+
|
|
29607
|
+
|
|
29458
29608
|
def validate_touch_write_guard_scenario() -> int:
|
|
29459
29609
|
with tempfile.TemporaryDirectory(
|
|
29460
29610
|
prefix="keel-touch-guard-", ignore_cleanup_errors=True
|
|
@@ -37996,6 +38146,7 @@ SCENARIOS: tuple = (
|
|
|
37996
38146
|
"standing-authorization-declaration",
|
|
37997
38147
|
validate_standing_authorization_declaration_scenario,
|
|
37998
38148
|
),
|
|
38149
|
+
("authorize-push-close-cleanup", validate_authorize_push_close_cleanup_scenario),
|
|
37999
38150
|
(
|
|
38000
38151
|
"standing-authorization-sync-confusion",
|
|
38001
38152
|
validate_standing_authorization_sync_confusion_scenario,
|
|
@@ -38199,6 +38350,7 @@ SCENARIOS: tuple = (
|
|
|
38199
38350
|
("native-helper-targets", validate_native_helper_targets_scenario),
|
|
38200
38351
|
("native-single-task-matrix", validate_native_single_task_matrix_scenario),
|
|
38201
38352
|
("touch-write-guard", validate_touch_write_guard_scenario),
|
|
38353
|
+
("push-branch-guard", validate_push_branch_guard_scenario),
|
|
38202
38354
|
("touch-guard-record-layer", validate_touch_guard_record_layer_scenario),
|
|
38203
38355
|
("repo-action-mode", validate_repo_action_mode_scenario),
|
|
38204
38356
|
("runner-skip-accounting", validate_runner_skip_accounting_scenario),
|
package/src/core/capabilities.js
CHANGED
|
@@ -230,9 +230,10 @@ function guardDiagnostics(repo, target) {
|
|
|
230
230
|
boundary: {
|
|
231
231
|
level: "advisory",
|
|
232
232
|
evidence:
|
|
233
|
-
"The guard covers file-edit tools
|
|
234
|
-
+ "Bash
|
|
235
|
-
+ "
|
|
233
|
+
"The guard covers file-edit tools (Edit, Write, NotebookEdit), and on "
|
|
234
|
+
+ "Bash only `git push` while keel/config.yaml declares `push:<branch "
|
|
235
|
+
+ "glob>`; every other Bash command and indirect write stays "
|
|
236
|
+
+ "disciplinary, and paths outside the repository are not product writes.",
|
|
236
237
|
},
|
|
237
238
|
};
|
|
238
239
|
}
|
package/src/core/config.js
CHANGED
|
@@ -21,6 +21,13 @@ const STANDING_AUTHORIZATION_ACTIONS = [
|
|
|
21
21
|
// Answering, in the named chat group, a record addressed to the session's
|
|
22
22
|
// role (#195). Scoped: in a Slack-enabled group a reply leaves the machine.
|
|
23
23
|
"chat-reply",
|
|
24
|
+
// Closing an issue on the named repository with a comment naming the work
|
|
25
|
+
// that resolved it (#257). Scoped for the reason `issue` is.
|
|
26
|
+
"issue-close",
|
|
27
|
+
// Removing temporary worktrees and run output under the session's own
|
|
28
|
+
// scratchpad once merged and unused, never a branch or another session's
|
|
29
|
+
// files (#257). Its one scope, `scratch`, says which tree it reaches.
|
|
30
|
+
"cleanup",
|
|
24
31
|
];
|
|
25
32
|
|
|
26
33
|
// The actions whose credential reaches further than the checkout the
|
|
@@ -30,7 +37,12 @@ const STANDING_AUTHORIZATION_ACTIONS = [
|
|
|
30
37
|
// actions are declared with the resource they may reach and refused bare —
|
|
31
38
|
// accepting the bare form as a convenience would make the narrow form optional
|
|
32
39
|
// and the wide one the default, which is the decision inverted.
|
|
33
|
-
const SCOPED_AUTHORIZATION_ACTIONS = new Set(["issue", "chat-reply"]);
|
|
40
|
+
const SCOPED_AUTHORIZATION_ACTIONS = new Set(["issue", "chat-reply", "issue-close", "cleanup"]);
|
|
41
|
+
|
|
42
|
+
// Actions whose scope narrows them but is not required (#257). A bare `push`
|
|
43
|
+
// keeps the meaning it always had; `push:<branch glob>` limits it to matching
|
|
44
|
+
// branches, and the Claude write guard enforces that limit.
|
|
45
|
+
const OPTIONALLY_SCOPED_AUTHORIZATION_ACTIONS = new Set(["push"]);
|
|
34
46
|
|
|
35
47
|
// `<owner>/<repo>`: two non-empty segments and nothing else. The shape is
|
|
36
48
|
// checked and the existence is not, for the reason `triage` never fetches an
|
|
@@ -43,14 +55,24 @@ const AUTHORIZATION_SCOPE_PATTERN = /^[A-Za-z0-9._-]+\/[A-Za-z0-9._-]+$/;
|
|
|
43
55
|
const AUTHORIZATION_SCOPES = {
|
|
44
56
|
issue: { form: "<owner>/<repo>", pattern: AUTHORIZATION_SCOPE_PATTERN },
|
|
45
57
|
"chat-reply": { form: "<group>", pattern: /^[a-z0-9][a-z0-9-]{0,31}$/ },
|
|
58
|
+
"issue-close": { form: "<owner>/<repo>", pattern: AUTHORIZATION_SCOPE_PATTERN },
|
|
59
|
+
cleanup: { form: "scratch", pattern: /^scratch$/ },
|
|
60
|
+
// Branch-name characters and `*`; `*` matches within one `/` segment and
|
|
61
|
+
// `**` across them, as Touch globs do.
|
|
62
|
+
push: { form: "<branch glob>", pattern: /^[A-Za-z0-9._/*-]+$/ },
|
|
46
63
|
};
|
|
47
64
|
|
|
48
65
|
// How the accepted names are spelled back to an author: the scoped ones carry
|
|
49
66
|
// their form, so the list is copyable rather than a name the next message
|
|
50
67
|
// refuses.
|
|
51
|
-
const STANDING_AUTHORIZATION_ACCEPTED_FORMS = STANDING_AUTHORIZATION_ACTIONS.
|
|
52
|
-
(action) =>
|
|
53
|
-
SCOPED_AUTHORIZATION_ACTIONS.has(action)
|
|
68
|
+
const STANDING_AUTHORIZATION_ACCEPTED_FORMS = STANDING_AUTHORIZATION_ACTIONS.flatMap(
|
|
69
|
+
(action) => {
|
|
70
|
+
if (SCOPED_AUTHORIZATION_ACTIONS.has(action)) return [`${action}:${AUTHORIZATION_SCOPES[action].form}`];
|
|
71
|
+
if (OPTIONALLY_SCOPED_AUTHORIZATION_ACTIONS.has(action)) {
|
|
72
|
+
return [action, `${action}:${AUTHORIZATION_SCOPES[action].form}`];
|
|
73
|
+
}
|
|
74
|
+
return [action];
|
|
75
|
+
}
|
|
54
76
|
);
|
|
55
77
|
|
|
56
78
|
// One declared entry, split into the action and the resource it names. Returns
|
|
@@ -63,7 +85,10 @@ function classifyAuthorizationEntry(entry) {
|
|
|
63
85
|
if (!STANDING_AUTHORIZATION_ACTIONS.includes(action)) {
|
|
64
86
|
return { ok: false, entry, reason: "unknown-action" };
|
|
65
87
|
}
|
|
66
|
-
if (
|
|
88
|
+
if (OPTIONALLY_SCOPED_AUTHORIZATION_ACTIONS.has(action) && scope === null) {
|
|
89
|
+
return { ok: true, entry, action, scope: null };
|
|
90
|
+
}
|
|
91
|
+
if (!SCOPED_AUTHORIZATION_ACTIONS.has(action) && !OPTIONALLY_SCOPED_AUTHORIZATION_ACTIONS.has(action)) {
|
|
67
92
|
if (scope !== null) return { ok: false, entry, action, reason: "unexpected-scope" };
|
|
68
93
|
return { ok: true, entry, action, scope: null };
|
|
69
94
|
}
|
|
@@ -257,6 +282,28 @@ function standingAuthorizationUnknownMessage(unknown, problems = []) {
|
|
|
257
282
|
// names are ... issue" beside "unrecognized action: issue" would contradict
|
|
258
283
|
// itself. Name what is missing instead, and why this one name carries it.
|
|
259
284
|
for (const problem of problems) {
|
|
285
|
+
if (problem.reason === "mixed-push") {
|
|
286
|
+
notes.push(
|
|
287
|
+
`\`push\` and ${problem.scoped.map((entry) => `\`${entry}\``).join(", ")} are `
|
|
288
|
+
+ "declared together; the bare form would silently widen the scoped "
|
|
289
|
+
+ "one. Keep `push` alone, or only the `push:<branch glob>` entries."
|
|
290
|
+
);
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
if (problem.action === "push") {
|
|
294
|
+
notes.push(
|
|
295
|
+
`\`${problem.entry}\` does not name a branch glob as \`push:<branch glob>\` — `
|
|
296
|
+
+ "letters, digits, `.`, `_`, `-`, `/`, and `*`."
|
|
297
|
+
);
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
300
|
+
if (problem.action === "cleanup") {
|
|
301
|
+
notes.push(
|
|
302
|
+
`\`${problem.entry}\` is not \`cleanup:scratch\`, the one form this name `
|
|
303
|
+
+ "takes: it covers the session's own scratchpad and nothing else."
|
|
304
|
+
);
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
260
307
|
if (problem.reason === "missing-scope" && problem.action === "chat-reply") {
|
|
261
308
|
notes.push(
|
|
262
309
|
"`chat-reply` names no chat group; write it as `chat-reply:<group>`, "
|
|
@@ -271,7 +318,7 @@ function standingAuthorizationUnknownMessage(unknown, problems = []) {
|
|
|
271
318
|
} else if (problem.reason === "missing-scope") {
|
|
272
319
|
notes.push(
|
|
273
320
|
`\`${problem.action}\` names no repository; write it as `
|
|
274
|
-
+ `\`${problem.action}:<owner>/<repo>\`. The credentials that open an `
|
|
321
|
+
+ `\`${problem.action}:<owner>/<repo>\`. The credentials that open or close an `
|
|
275
322
|
+ "issue are account-wide, so an unscoped grant would reach every "
|
|
276
323
|
+ "repository the account can touch — wider than commit or push, "
|
|
277
324
|
+ "which this checkout bounds."
|
|
@@ -318,17 +365,30 @@ function readStandingAuthorization(repo) {
|
|
|
318
365
|
// Fail closed. A declaration Keel cannot fully read authorizes nothing,
|
|
319
366
|
// because the alternative is granting the entries beside a typo while the
|
|
320
367
|
// author believes they granted the typo too.
|
|
368
|
+
const pushGlobs = [];
|
|
369
|
+
for (const entry of declared) {
|
|
370
|
+
const classified = classifyAuthorizationEntry(entry);
|
|
371
|
+
if (classified.action === "push" && classified.scope !== null && !pushGlobs.includes(classified.scope)) {
|
|
372
|
+
pushGlobs.push(classified.scope);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
if (pushGlobs.length && declared.includes("push")) {
|
|
376
|
+
unknown.push("push");
|
|
377
|
+
problems.push({ reason: "mixed-push", entry: "push", action: "push", scoped: pushGlobs.map((glob) => `push:${glob}`) });
|
|
378
|
+
}
|
|
321
379
|
if (unknown.length > 0) {
|
|
322
380
|
return {
|
|
323
381
|
declared: [],
|
|
324
382
|
scopes: new Map(),
|
|
325
383
|
chatReplyGroups: [],
|
|
384
|
+
pushGlobs: [],
|
|
326
385
|
unknown,
|
|
327
386
|
message: standingAuthorizationUnknownMessage(unknown, problems),
|
|
328
387
|
};
|
|
329
388
|
}
|
|
330
389
|
if (chatReplyGroups.length) scopes.set("chat-reply", chatReplyGroups.join(", "));
|
|
331
|
-
|
|
390
|
+
if (pushGlobs.length) scopes.set("push", pushGlobs.join(", "));
|
|
391
|
+
return { declared, scopes, chatReplyGroups, pushGlobs, unknown, message: null };
|
|
332
392
|
}
|
|
333
393
|
|
|
334
394
|
// `full_mode_paths:` — the paths whose change always routes Full, whatever the
|