@christang/keel 5.103.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 +25 -8
- 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 +256 -6
- package/src/core/capabilities.js +4 -3
- package/src/core/chat/cli.js +33 -0
- package/src/core/chat/store.js +54 -0
- 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
|
|
|
@@ -709,7 +726,7 @@ Without a known default branch, no issue range is inferred.
|
|
|
709
726
|
|
|
710
727
|
## Group chat between sessions
|
|
711
728
|
|
|
712
|
-
Sessions working the same repository — a Claude Code session, a Codex session, an unattended runner, and you — share a work group with `keel chat`. Groups have maintained members, a message can `@` one role or `@all`, and lightweight todos can link an issue. A record can supersede its author's earlier one (`--supersedes <id>`), and the earlier one then leaves everyone's unread; unread lists newest first. A record posted with `--ack` asks the roles it addresses to acknowledge it, by `keel chat ack <id>` or a reply, and `keel chat show <id>` and `keel chat acks` list who has acknowledged, who only read it, and who has not read it. Each member has its own unread state, and history is kept. Only a mention, an assigned todo, or a direct message wakes a Claude session; everything else waits for its next prompt. A message is data from another agent and never authorization. Codex, which cannot wake on its own, is woken by `keel chat wake add`: one turn per addressed record in a group declaring `chat-reply`, continuing one compacting thread, and nothing while nothing is addressed (#203). Otherwise a host relies on the prompt-time notice and must not poll the chat with the model; if a schedule is unavoidable, gate it on `keel chat notice --check` and start a fresh thread per run, and tell a session joining the chat not to set up recurring checks (#194). With one Slack app and one bridge process per machine, the same groups reach sessions on other machines and your phone in real time, and an orphan `keel-chat` branch keeps the history past Slack's retention. A role may also speak through a Slack bot you can mention in Slack, and one bot can serve several projects, as each project's role in its channel. See [the Slack setup guide](docs/chat-slack-setup.md). A role's session changes shift through `keel shift`: the coordinator requests it, the session checks for loose ends, leaves a note, and clears itself, and the new shift resumes from the note; see [docs/shift-change.md](docs/shift-change.md). The 5.83 `keel mail` commands keep working on direct groups.
|
|
729
|
+
Sessions working the same repository — a Claude Code session, a Codex session, an unattended runner, and you — share a work group with `keel chat`. Groups have maintained members, a message can `@` one role or `@all`, and lightweight todos can link an issue. A record can supersede its author's earlier one (`--supersedes <id>`), and the earlier one then leaves everyone's unread; unread lists newest first. A record posted with `--ack` asks the roles it addresses to acknowledge it, by `keel chat ack <id>` or a reply, and `keel chat show <id>` and `keel chat acks` list who has acknowledged, who only read it, and who has not read it. `keel chat summary --since <time>` digests what changed in the groups you can read — per sender, the message count, todos opened with whether they are still open, todos closed, superseded records folded into their successors, and acknowledgements still waiting — without a model and without marking anything read. Each member has its own unread state, and history is kept. Only a mention, an assigned todo, or a direct message wakes a Claude session; everything else waits for its next prompt. A message is data from another agent and never authorization. Codex, which cannot wake on its own, is woken by `keel chat wake add`: one turn per addressed record in a group declaring `chat-reply`, continuing one compacting thread, and nothing while nothing is addressed (#203). Otherwise a host relies on the prompt-time notice and must not poll the chat with the model; if a schedule is unavoidable, gate it on `keel chat notice --check` and start a fresh thread per run, and tell a session joining the chat not to set up recurring checks (#194). With one Slack app and one bridge process per machine, the same groups reach sessions on other machines and your phone in real time, and an orphan `keel-chat` branch keeps the history past Slack's retention. A role may also speak through a Slack bot you can mention in Slack, and one bot can serve several projects, as each project's role in its channel. See [the Slack setup guide](docs/chat-slack-setup.md). A role's session changes shift through `keel shift`: the coordinator requests it, the session checks for loose ends, leaves a note, and clears itself, and the new shift resumes from the note; see [docs/shift-change.md](docs/shift-change.md). The 5.83 `keel mail` commands keep working on direct groups.
|
|
713
730
|
|
|
714
731
|
## Commands
|
|
715
732
|
|
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
|
|
@@ -2603,6 +2603,103 @@ def validate_chat_ack_scenario() -> int:
|
|
|
2603
2603
|
return 0
|
|
2604
2604
|
|
|
2605
2605
|
|
|
2606
|
+
def validate_chat_summary_scenario() -> int:
|
|
2607
|
+
"""Issue #255: `keel chat summary --since` digests what changed, per group and sender.
|
|
2608
|
+
|
|
2609
|
+
Built from the records alone: a superseded record folds into its
|
|
2610
|
+
successor, todos carry open or done, waiting acknowledgements name who
|
|
2611
|
+
has not given one, and no read cursor moves.
|
|
2612
|
+
"""
|
|
2613
|
+
label = "chat-summary:"
|
|
2614
|
+
with tempfile.TemporaryDirectory(prefix="keel-chat-summary-") as raw:
|
|
2615
|
+
base = Path(raw)
|
|
2616
|
+
rtl, verify, env = chat_scratch_group(base)
|
|
2617
|
+
loose = chat_worktree(rtl, base / "loose")
|
|
2618
|
+
|
|
2619
|
+
def chat(cwd: Path, *args: str) -> subprocess.CompletedProcess[str]:
|
|
2620
|
+
return run_keel(cwd, "chat", *args, env=env)
|
|
2621
|
+
|
|
2622
|
+
# A record's `created` is stamped to the second, so the time is too.
|
|
2623
|
+
before = datetime.now(timezone.utc).replace(microsecond=0).isoformat()
|
|
2624
|
+
rule = chat_json(chat(rtl, "post", "soc", "rule: rerun on every merge", "--json")).get("id", "")
|
|
2625
|
+
newer = chat_json(chat(rtl, "post", "soc", "rule: rerun nightly", "--supersedes", rule, "--json")).get("id", "")
|
|
2626
|
+
asked = chat_json(chat(rtl, "post", "soc", "@verify confirm R007", "--ack", "--json")).get("id", "")
|
|
2627
|
+
closed = chat_json(chat(rtl, "todo", "soc", "--assignee", "verify", "rerun R007", "--json")).get("id", "")
|
|
2628
|
+
chat(verify, "done", closed)
|
|
2629
|
+
chat(verify, "post", "soc", "R007 is green")
|
|
2630
|
+
still = chat_json(chat(verify, "todo", "soc", "--assignee", "rtl", "review the clock fix", "--json")).get("id", "")
|
|
2631
|
+
if not all((rule, newer, asked, closed, still)):
|
|
2632
|
+
report(f"{label} the fixture could not post every record: {[rule, newer, asked, closed, still]!r}")
|
|
2633
|
+
return 1
|
|
2634
|
+
|
|
2635
|
+
store = Path(chat_json(chat(rtl, "role", "--json")).get("store", ""))
|
|
2636
|
+
cursors = {path: path.read_bytes() for path in (store / "cursors").rglob("*") if path.is_file()}
|
|
2637
|
+
result = chat(rtl, "summary", "--since", before, "--json")
|
|
2638
|
+
if result.returncode != 0:
|
|
2639
|
+
report(f"{label} keel chat summary failed: {result.stdout} {result.stderr}")
|
|
2640
|
+
return 1
|
|
2641
|
+
payload = chat_json(result)
|
|
2642
|
+
after = {path: path.read_bytes() for path in (store / "cursors").rglob("*") if path.is_file()}
|
|
2643
|
+
if after != cursors:
|
|
2644
|
+
report(f"{label} the summary moved a read cursor.")
|
|
2645
|
+
return 1
|
|
2646
|
+
groups = {group.get("group"): group for group in payload.get("groups", [])}
|
|
2647
|
+
if list(groups) != ["soc"]:
|
|
2648
|
+
report(f"{label} the summary lists groups {list(groups)!r}, not ['soc'].")
|
|
2649
|
+
return 1
|
|
2650
|
+
senders = {sender.get("role"): sender for sender in groups["soc"].get("senders", [])}
|
|
2651
|
+
if list(senders) != ["rtl", "verify"]:
|
|
2652
|
+
report(f"{label} the senders are {list(senders)!r}, not ['rtl', 'verify'] in role order.")
|
|
2653
|
+
return 1
|
|
2654
|
+
r, v = senders["rtl"], senders["verify"]
|
|
2655
|
+
expected = [
|
|
2656
|
+
("rtl's message count, the superseded rule folded", r.get("messages"), 2),
|
|
2657
|
+
("rtl's todo, closed", [(t.get("id"), t.get("assignee"), t.get("state")) for t in r.get("todosOpened", [])], [(closed, "verify", "done")]),
|
|
2658
|
+
("rtl's superseding record", [(x.get("id"), x.get("supersedes")) for x in r.get("supersedes", [])], [(newer, rule)]),
|
|
2659
|
+
("verify's message count", v.get("messages"), 1),
|
|
2660
|
+
("verify's todo, open", [(t.get("id"), t.get("assignee"), t.get("state")) for t in v.get("todosOpened", [])], [(still, "rtl", "open")]),
|
|
2661
|
+
("verify's closed todo", [t.get("id") for t in v.get("todosClosed", [])], [closed]),
|
|
2662
|
+
("the waiting acknowledgement", [(a.get("id"), a.get("waiting")) for a in payload.get("waitingAcks", [])], [(asked, ["verify"])]),
|
|
2663
|
+
]
|
|
2664
|
+
for what, got, want in expected:
|
|
2665
|
+
if got != want:
|
|
2666
|
+
report(f"{label} {what} is {got!r}, not {want!r}.")
|
|
2667
|
+
return 1
|
|
2668
|
+
if rule in json.dumps(payload).replace(f'"supersedes": "{rule}"', ""):
|
|
2669
|
+
report(f"{label} the superseded rule {rule} is listed on its own.")
|
|
2670
|
+
return 1
|
|
2671
|
+
text = chat(rtl, "summary", "--since", before)
|
|
2672
|
+
if text.returncode != 0:
|
|
2673
|
+
report(f"{label} the text summary failed: {text.stderr!r}")
|
|
2674
|
+
return 1
|
|
2675
|
+
if f"{newer} superseded {rule}" not in text.stdout:
|
|
2676
|
+
report(f"{label} the text summary does not name the superseding record: {text.stdout!r}")
|
|
2677
|
+
return 1
|
|
2678
|
+
|
|
2679
|
+
quiet = chat(rtl, "summary", "--since", "2999-01-01")
|
|
2680
|
+
if quiet.returncode != 0:
|
|
2681
|
+
report(f"{label} a time after the last record exited {quiet.returncode}: {quiet.stderr!r}")
|
|
2682
|
+
return 1
|
|
2683
|
+
if "nothing changed" not in quiet.stdout:
|
|
2684
|
+
report(f"{label} a time after the last record did not say nothing changed: {quiet.stdout!r}")
|
|
2685
|
+
return 1
|
|
2686
|
+
refusals = [
|
|
2687
|
+
("a summary without --since", chat(rtl, "summary"), "--since"),
|
|
2688
|
+
("an unreadable --since", chat(rtl, "summary", "--since", "yesterdayish"), "--since"),
|
|
2689
|
+
("a worktree with no role", chat(loose, "summary", "--since", "1d"), "keel chat role --set"),
|
|
2690
|
+
]
|
|
2691
|
+
for what, refused, needle in refusals:
|
|
2692
|
+
if refused.returncode == 0:
|
|
2693
|
+
report(f"{label} {what} was accepted: {refused.stdout}")
|
|
2694
|
+
return 1
|
|
2695
|
+
if needle not in refused.stderr:
|
|
2696
|
+
report(f"{label} {what} was refused without naming {needle!r}: {refused.stderr}")
|
|
2697
|
+
return 1
|
|
2698
|
+
|
|
2699
|
+
report("chat-summary scenario passed.")
|
|
2700
|
+
return 0
|
|
2701
|
+
|
|
2702
|
+
|
|
2606
2703
|
def validate_chat_records_scenario() -> int:
|
|
2607
2704
|
"""Issue #187: todos, edits, retractions, search, and local-time display.
|
|
2608
2705
|
|
|
@@ -23987,6 +24084,72 @@ def write_authorize_config(repo: Path, body: str) -> None:
|
|
|
23987
24084
|
(repo / "keel" / "config.yaml").write_text(body, encoding="utf-8")
|
|
23988
24085
|
|
|
23989
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
|
+
|
|
23990
24153
|
def validate_standing_authorization_declaration_scenario() -> int:
|
|
23991
24154
|
with tempfile.TemporaryDirectory(prefix="keel-authorize-") as raw_tmp:
|
|
23992
24155
|
root = Path(raw_tmp)
|
|
@@ -26912,6 +27075,13 @@ def validate_continuation_authorization_scenario() -> int:
|
|
|
26912
27075
|
return 0
|
|
26913
27076
|
|
|
26914
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
|
+
|
|
26915
27085
|
def validate_continuation_docs_scenario() -> int:
|
|
26916
27086
|
"""Every text an agent reads at the between-task boundary names the word (#94).
|
|
26917
27087
|
|
|
@@ -26961,9 +27131,8 @@ def validate_continuation_docs_scenario() -> int:
|
|
|
26961
27131
|
# The seventh name (#164). Each surface that spells the vocabulary out has
|
|
26962
27132
|
# to spell all of it: a reader copies from the list they are shown.
|
|
26963
27133
|
for needle in (
|
|
26964
|
-
"accepted names:
|
|
26965
|
-
"
|
|
26966
|
-
"The eight names above are the whole vocabulary.",
|
|
27134
|
+
f"accepted names: {ACCEPTED_AUTHORIZE_NAMES}",
|
|
27135
|
+
"The ten names above are the whole vocabulary.",
|
|
26967
27136
|
"`protocol-refresh`, the seventh name",
|
|
26968
27137
|
):
|
|
26969
27138
|
if needle not in readme:
|
|
@@ -26971,7 +27140,7 @@ def validate_continuation_docs_scenario() -> int:
|
|
|
26971
27140
|
return 1
|
|
26972
27141
|
|
|
26973
27142
|
config_text = (ROOT / "keel/config.yaml").read_text(encoding="utf-8")
|
|
26974
|
-
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:
|
|
26975
27144
|
report(
|
|
26976
27145
|
f"{label}: keel/config.yaml's comment lacks: protocol-refresh in the "
|
|
26977
27146
|
"seven-name vocabulary."
|
|
@@ -29358,6 +29527,84 @@ def validate_touch_guard_record_layer_scenario() -> int:
|
|
|
29358
29527
|
return 0
|
|
29359
29528
|
|
|
29360
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
|
+
|
|
29361
29608
|
def validate_touch_write_guard_scenario() -> int:
|
|
29362
29609
|
with tempfile.TemporaryDirectory(
|
|
29363
29610
|
prefix="keel-touch-guard-", ignore_cleanup_errors=True
|
|
@@ -37899,6 +38146,7 @@ SCENARIOS: tuple = (
|
|
|
37899
38146
|
"standing-authorization-declaration",
|
|
37900
38147
|
validate_standing_authorization_declaration_scenario,
|
|
37901
38148
|
),
|
|
38149
|
+
("authorize-push-close-cleanup", validate_authorize_push_close_cleanup_scenario),
|
|
37902
38150
|
(
|
|
37903
38151
|
"standing-authorization-sync-confusion",
|
|
37904
38152
|
validate_standing_authorization_sync_confusion_scenario,
|
|
@@ -38084,6 +38332,7 @@ SCENARIOS: tuple = (
|
|
|
38084
38332
|
("resource-lock", validate_resource_lock_scenario),
|
|
38085
38333
|
("chat-supersedes", validate_chat_supersedes_scenario),
|
|
38086
38334
|
("chat-ack", validate_chat_ack_scenario),
|
|
38335
|
+
("chat-summary", validate_chat_summary_scenario),
|
|
38087
38336
|
("worktree-overview", validate_worktree_overview_scenario),
|
|
38088
38337
|
("init-never-downgrades-openspec", validate_init_never_downgrades_openspec_scenario),
|
|
38089
38338
|
("native-plugin-marketplaces", validate_native_plugin_marketplaces_scenario),
|
|
@@ -38101,6 +38350,7 @@ SCENARIOS: tuple = (
|
|
|
38101
38350
|
("native-helper-targets", validate_native_helper_targets_scenario),
|
|
38102
38351
|
("native-single-task-matrix", validate_native_single_task_matrix_scenario),
|
|
38103
38352
|
("touch-write-guard", validate_touch_write_guard_scenario),
|
|
38353
|
+
("push-branch-guard", validate_push_branch_guard_scenario),
|
|
38104
38354
|
("touch-guard-record-layer", validate_touch_guard_record_layer_scenario),
|
|
38105
38355
|
("repo-action-mode", validate_repo_action_mode_scenario),
|
|
38106
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/chat/cli.js
CHANGED
|
@@ -23,6 +23,7 @@ const USAGE = [
|
|
|
23
23
|
"keel chat post <group> <text...> [--reply-to <id>] [--supersedes <id>] [--ack] [--json] (also: keel chat <group> <text...>)",
|
|
24
24
|
"keel chat ack <id> acknowledge a record that asks (a reply also counts)",
|
|
25
25
|
"keel chat acks [--mine] [--json] records still waiting on an acknowledgement",
|
|
26
|
+
"keel chat summary --since <90s|15m|2h|3d|date> [--group <group>] [--json] (what changed, per group and sender; reads without marking read)",
|
|
26
27
|
"keel chat dm <role> <text...> [--json]",
|
|
27
28
|
"keel chat <group> [--since <90s|15m|2h|3d|date>] [--follow] [--peek] [--json] (view; advances your read position unless --peek)",
|
|
28
29
|
"keel chat unread [--json]",
|
|
@@ -131,6 +132,26 @@ function ackLines(acks) {
|
|
|
131
132
|
];
|
|
132
133
|
}
|
|
133
134
|
|
|
135
|
+
function summaryLines({ groups, waitingAcks }, sinceText) {
|
|
136
|
+
if (!groups.length && !waitingAcks.length) return [`keel chat: nothing changed since ${sinceText}.`];
|
|
137
|
+
const first = (text) => String(text || "").split("\n")[0];
|
|
138
|
+
const lines = [`Since ${sinceText}:`];
|
|
139
|
+
for (const { group, senders } of groups) {
|
|
140
|
+
lines.push(`${group}:`);
|
|
141
|
+
for (const sender of senders) {
|
|
142
|
+
lines.push(` ${sender.role}: ${sender.messages} message${sender.messages === 1 ? "" : "s"}`);
|
|
143
|
+
for (const t of sender.todosOpened) lines.push(` todo for ${t.assignee} (${t.state}) ${t.id}: ${first(t.text)}`);
|
|
144
|
+
for (const t of sender.todosClosed) lines.push(` closed todo from ${t.from} ${t.id}: ${first(t.text)}`);
|
|
145
|
+
for (const x of sender.supersedes) lines.push(` ${x.id} superseded ${x.supersedes}: ${first(x.text)}`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (waitingAcks.length) {
|
|
149
|
+
lines.push("Waiting on an acknowledgement:");
|
|
150
|
+
for (const a of waitingAcks) lines.push(` ${a.group} ${a.id} from ${a.from}, waiting on ${a.waiting.join(", ")}: ${first(a.text)}`);
|
|
151
|
+
}
|
|
152
|
+
return lines;
|
|
153
|
+
}
|
|
154
|
+
|
|
134
155
|
function publicRecord(record) {
|
|
135
156
|
const { refs, ...rest } = record;
|
|
136
157
|
return refs && refs.length ? record : rest;
|
|
@@ -289,6 +310,18 @@ function dispatch(where, options) {
|
|
|
289
310
|
else out(rows.map(({ record, acks }) => [`${record.group} ${formatLine(record)}`, ...ackLines(acks).map((line) => ` ${line}`)].join("\n")).join("\n"));
|
|
290
311
|
return 0;
|
|
291
312
|
}
|
|
313
|
+
case "summary": {
|
|
314
|
+
if (options.since === null) throw new ChatError("keel chat summary needs --since <90s|15m|2h|3d|date>.");
|
|
315
|
+
const threshold = parseSince(options.since);
|
|
316
|
+
if (threshold === null) throw new ChatError(`--since ${JSON.stringify(options.since)} is not a time; use 90s, 15m, 2h, 3d, or a date.`);
|
|
317
|
+
const role = store.requireRole(where);
|
|
318
|
+
if (options.group !== null) store.checkName(options.group, "Group");
|
|
319
|
+
const digest = store.summary(where, role, threshold, { group: options.group });
|
|
320
|
+
const sinceText = store.isoLocal(new Date(threshold));
|
|
321
|
+
if (options.json) out(JSON.stringify({ since: sinceText, ...digest }));
|
|
322
|
+
else out(summaryLines(digest, sinceText).join("\n"));
|
|
323
|
+
return 0;
|
|
324
|
+
}
|
|
292
325
|
case "dm": {
|
|
293
326
|
const [target, ...words] = rest;
|
|
294
327
|
if (!target) throw new ChatError("keel chat dm needs a role.");
|
package/src/core/chat/store.js
CHANGED
|
@@ -789,6 +789,59 @@ function directPost(where, target, text, extra = {}) {
|
|
|
789
789
|
|
|
790
790
|
// --- cursors and receipts -----------------------------------------------------
|
|
791
791
|
|
|
792
|
+
// What changed since a time, per group and sender (#255): built from the
|
|
793
|
+
// records alone, and read without moving any cursor (D4). A superseded record
|
|
794
|
+
// folds into its successor and is not listed on its own (D2).
|
|
795
|
+
function summary(where, role, threshold, { group = null } = {}) {
|
|
796
|
+
const after = (record) => {
|
|
797
|
+
const time = Date.parse(record.created);
|
|
798
|
+
return !Number.isNaN(time) && time >= threshold;
|
|
799
|
+
};
|
|
800
|
+
const groups = [];
|
|
801
|
+
const waitingAcks = [];
|
|
802
|
+
for (const name of group ? [group] : listGroupNames(where)) {
|
|
803
|
+
const records = readLog(where, name);
|
|
804
|
+
const state = groupState(records);
|
|
805
|
+
if (!state.exists || state.archived || !canAct(state, role)) continue;
|
|
806
|
+
const superseded = supersededIds(records);
|
|
807
|
+
const closedBy = new Map(records.filter((r) => r.kind === "done").map((r) => [r.target, r]));
|
|
808
|
+
const byId = new Map(records.map((r) => [r.id, r]));
|
|
809
|
+
const senders = new Map();
|
|
810
|
+
const entry = (from) => {
|
|
811
|
+
if (!senders.has(from)) senders.set(from, { role: from, messages: 0, todosOpened: [], todosClosed: [], supersedes: [] });
|
|
812
|
+
return senders.get(from);
|
|
813
|
+
};
|
|
814
|
+
for (const record of records) {
|
|
815
|
+
if (!after(record) || superseded.has(record.id)) continue;
|
|
816
|
+
if (record.kind === "message") entry(record.from).messages += 1;
|
|
817
|
+
if (record.kind === "todo") {
|
|
818
|
+
entry(record.from).todosOpened.push({
|
|
819
|
+
id: record.id,
|
|
820
|
+
assignee: record.assignee,
|
|
821
|
+
state: closedBy.has(record.id) ? "done" : "open",
|
|
822
|
+
text: record.text,
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
if (record.kind === "done" && byId.get(record.target)?.kind === "todo") {
|
|
826
|
+
const todo = byId.get(record.target);
|
|
827
|
+
entry(record.from).todosClosed.push({ id: todo.id, from: todo.from, text: todo.text });
|
|
828
|
+
}
|
|
829
|
+
if (record.supersedes && READABLE_KINDS.has(record.kind)) {
|
|
830
|
+
entry(record.from).supersedes.push({ id: record.id, supersedes: record.supersedes, text: record.text });
|
|
831
|
+
}
|
|
832
|
+
if (record.ack === ACK_REQUESTED) {
|
|
833
|
+
const status = ackStatus(where, record);
|
|
834
|
+
const waiting = [...status.readNotAcknowledged, ...status.unread].sort();
|
|
835
|
+
if (waiting.length) waitingAcks.push({ id: record.id, group: name, from: record.from, text: record.text, waiting });
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
if (senders.size) {
|
|
839
|
+
groups.push({ group: name, senders: [...senders.values()].sort((a, b) => (a.role < b.role ? -1 : a.role > b.role ? 1 : 0)) });
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
return { groups, waitingAcks };
|
|
843
|
+
}
|
|
844
|
+
|
|
792
845
|
function cursorFile(where, role, group) {
|
|
793
846
|
return path.join(where.root, "cursors", role, group);
|
|
794
847
|
}
|
|
@@ -859,6 +912,7 @@ function readGroups(where, role, group) {
|
|
|
859
912
|
|
|
860
913
|
module.exports = {
|
|
861
914
|
ack,
|
|
915
|
+
summary,
|
|
862
916
|
ackStatus,
|
|
863
917
|
openAcks,
|
|
864
918
|
checkName,
|
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
|