@christang/keel 5.211.0 → 5.212.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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keel",
3
- "version": "5.211.0",
3
+ "version": "5.212.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",
package/README.md CHANGED
@@ -209,7 +209,8 @@ The write guard is a disposable manifest, `keel/guard.json`. On Claude a passing
209
209
  it (`--no-guard` opts out); `keel guard start` writes it explicitly and `keel guard clear` removes it.
210
210
  It records the change and task, the capsule fingerprint, the normalized `Touch`, and hashes of the
211
211
  authority files, and it fails closed: a manifest Keel cannot read refuses edits rather than allowing
212
- them. The guard checks the file-editing tools. A write made by a `Bash` command is not checked,
212
+ them, and so does one whose change is gone, unless the change was archived with the guarded task
213
+ checked — that task has finished, and the manifest then enforces nothing (#491). The guard checks the file-editing tools. A write made by a `Bash` command is not checked,
213
214
  except `git push` where a `push:` scope is declared.
214
215
 
215
216
  ### Standing authorization
package/README.zh-CN.md CHANGED
@@ -178,7 +178,8 @@ Keel: add-user-auth#2.1 — next: task-start. Disposable projection; OpenSpec an
178
178
 
179
179
  写入守卫是一份一次性 manifest:`keel/guard.json`。在 Claude 上,通过的 `task-start` 会写入它(`--no-guard` 退出);
180
180
  `keel guard start` 显式写入,`keel guard clear` 删除。它记录 change 与 task、capsule 指纹、规范化后的 `Touch`
181
- 和权威文件的哈希,并且失败即关闭:Keel 读不了的 manifest 会拒绝编辑,而不是放行。守卫检查文件编辑工具;
181
+ 和权威文件的哈希,并且失败即关闭:Keel 读不了的 manifest 会拒绝编辑,而不是放行;它守的 change 不见了也一样拒绝,
182
+ 除非那个 change 是在所守任务已勾选完成后归档的——那个任务已经结束,manifest 就不再拦任何写入(#491)。守卫检查文件编辑工具;
182
183
  `Bash` 命令造成的写入不检查,只有声明了 `push:` 范围时会检查 `git push`。
183
184
 
184
185
  ### 常设授权
@@ -1,4 +1,4 @@
1
- <!-- keel:start version=5.211.0 -->
1
+ <!-- keel:start version=5.212.0 -->
2
2
  ## Keel Bootstrap
3
3
 
4
4
  - Start every session with `keel context`; OpenSpec artifacts and Git are the durable authority, and memory or transcripts may only inform.
package/bin/keel.js CHANGED
@@ -3111,7 +3111,7 @@ function runAction(options) {
3111
3111
  process.stdout.write(
3112
3112
  options.json ? `${JSON.stringify(result, null, 2)}\n` : renderGuard(result)
3113
3113
  );
3114
- return ["started", "active", "absent", "cleared"].includes(result.status)
3114
+ return ["started", "active", "absent", "cleared", "archived"].includes(result.status)
3115
3115
  ? 0
3116
3116
  : 3;
3117
3117
  }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@christang/keel",
3
- "version": "5.211.0",
3
+ "version": "5.212.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@christang/keel",
9
- "version": "5.211.0",
9
+ "version": "5.212.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@fission-ai/openspec": "^1.4.1"
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@christang/keel",
3
3
  "displayName": "Keel",
4
4
  "description": "Keel OpenSpec execution discipline CLI for Claude Code, Codex, and OpenCode.",
5
- "version": "5.211.0",
5
+ "version": "5.212.0",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keel",
3
- "version": "5.211.0",
3
+ "version": "5.212.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.211.0",
3
+ "version": "5.212.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",
@@ -120,9 +120,9 @@ function pathAllowed(candidate, touch) {
120
120
  // tasks.md; now it is stated. An unreadable or unmatched tasks.md is not read as
121
121
  // checked — every gate that compiles the capsule catches that, and denying
122
122
  // product writes on a parse miss would trade a real capability for a guess.
123
- function taskIsChecked(repo, manifest) {
123
+ function taskIsChecked(repo, manifest, changeDir = null) {
124
124
  const file = path.join(
125
- repo, "openspec", "changes", manifest.change, "tasks.md"
125
+ changeDir || path.join(repo, "openspec", "changes", manifest.change), "tasks.md"
126
126
  );
127
127
  let content = "";
128
128
  try {
@@ -137,6 +137,21 @@ function taskIsChecked(repo, manifest) {
137
137
  return Boolean(match && match[1].toLowerCase() === "x");
138
138
  }
139
139
 
140
+ // The archived copy `openspec archive` moved the change to, the lexically last
141
+ // `<YYYY-MM-DD>-<change>` under openspec/changes/archive/, or null (#491 D1).
142
+ // `src/core/guard.js` makes the same test for `keel guard status`.
143
+ function archivedChangeDir(repo, change) {
144
+ const root = path.join(repo, "openspec", "changes", "archive");
145
+ let names = [];
146
+ try {
147
+ names = fs.readdirSync(root);
148
+ } catch {
149
+ return null;
150
+ }
151
+ const own = names.filter((name) => /^\d{4}-\d{2}-\d{2}-/.test(name) && name.slice(11) === change).sort();
152
+ return own.length ? path.join(root, own[own.length - 1]) : null;
153
+ }
154
+
140
155
  // A path is not the file it names. `path.resolve` never follows a symbolic
141
156
  // link, while the `cwd` the operating system reports usually already has, so
142
157
  // one file could be spelled two ways and get two containment answers: measured
@@ -713,10 +728,14 @@ function main() {
713
728
  // the stale Touch was denied by a message naming a task in an archived change
714
729
  // and telling the reader to reauthorize it, which cannot be done; a write
715
730
  // *inside* it passed silently, so an archived task went on granting write
716
- // authority. Denying here fixes both, and denying rather than allowing is
717
- // what stops `openspec archive` from quietly disabling the guard.
731
+ // authority. Denying here fixes both, and denying an archived task that was
732
+ // never checked is what stops `openspec archive` from quietly disabling the
733
+ // guard. A task archived checked has finished: the manifest then guards
734
+ // nothing, as if it were absent (#491).
718
735
  const changeDir = path.join(repo, "openspec", "changes", manifest.change);
719
736
  if (!fs.existsSync(changeDir)) {
737
+ const archived = archivedChangeDir(repo, manifest.change);
738
+ if (archived && taskIsChecked(repo, manifest, archived)) return 0;
720
739
  deny(
721
740
  `Keel write guard: this manifest is stale — it guards ${pointer}, but `
722
741
  + `openspec/changes/${manifest.change} no longer exists, so the task it `
@@ -35,10 +35,10 @@ os.environ["KEEL_UPDATE_CLAUDE"] = str(Path(tempfile.gettempdir()) / "keel-suite
35
35
  os.environ["KEEL_UPDATE_CODEX"] = str(Path(tempfile.gettempdir()) / "keel-suite-has-no-codex")
36
36
 
37
37
 
38
- PACKAGE_VERSION = "5.211.0"
38
+ PACKAGE_VERSION = "5.212.0"
39
39
 
40
40
 
41
- PROTOCOL_VERSION = "5.211.0"
41
+ PROTOCOL_VERSION = "5.212.0"
42
42
 
43
43
 
44
44
  LEGACY_MANAGED_START = "<!-- keel:start version=2.1 -->"
@@ -4891,6 +4891,65 @@ def guard_status_payload(repo: Path, cell: str) -> tuple[dict, str]:
4891
4891
  return payload, (problems[0].get("message", "") if problems else "")
4892
4892
 
4893
4893
 
4894
+ def validate_guard_archived_complete_task_scenario() -> int:
4895
+ """Issue #491: a manifest over a task checked and then archived enforces nothing.
4896
+
4897
+ In ChipSTRIDE under auto mode, the write after an authorized archive — the
4898
+ next change's proposal — was refused as a stale manifest, and the
4899
+ permission classifier refused `keel guard clear`, so every change after the
4900
+ first needed a person. A task archived checked has finished; the guard
4901
+ stands down, while an archived unchecked task still fails closed.
4902
+ """
4903
+ label = "guard-archived-complete-task:"
4904
+ with tempfile.TemporaryDirectory(prefix="keel-guard-491-", ignore_cleanup_errors=True) as raw_tmp:
4905
+ repo = Path(raw_tmp) / "repo"
4906
+ repo.mkdir()
4907
+ change_dir = repo / "openspec/changes/demo"
4908
+ write_text(change_dir / "tasks.md", guard_task_fixture())
4909
+ write_text(repo / "src/feature.js", "// fixture\n")
4910
+ started = run_keel(repo, "guard", "start", "--change", "demo", "--task", "1.1", "--json")
4911
+ if started.returncode != 0:
4912
+ report(f"{label} guard start failed: {(started.stderr or started.stdout).strip()}")
4913
+ return 1
4914
+ write_text(change_dir / "tasks.md", guard_task_fixture(checked=True))
4915
+ archived_dir = repo / "openspec/changes/archive/2026-10-27-demo"
4916
+ archived_dir.parent.mkdir(parents=True, exist_ok=True)
4917
+ shutil.move(str(change_dir), str(archived_dir))
4918
+ for what, target, tool in (
4919
+ ("an edit of a product file", repo / "src/feature.js", "Edit"),
4920
+ ("the next change's proposal", repo / "openspec/changes/next/proposal.md", "Write"),
4921
+ ):
4922
+ decision = pretooluse_decision(run_pretooluse_guard_hook(repo, edit_event(repo, target, tool)))
4923
+ if decision is not None:
4924
+ report(f"{label} {what} got a decision from a manifest over an archived, checked task: {decision!r}")
4925
+ return 1
4926
+ status = run_keel(repo, "guard", "status", "--json")
4927
+ if status.returncode != 0:
4928
+ report(f"{label} keel guard status exited {status.returncode}: {status.stdout!r} {status.stderr!r}")
4929
+ return 1
4930
+ try:
4931
+ result = json.loads(status.stdout)
4932
+ except json.JSONDecodeError:
4933
+ report(f"{label} keel guard status --json printed no JSON: {status.stdout!r}")
4934
+ return 1
4935
+ if result.get("status") != "archived":
4936
+ report(f"{label} keel guard status reports {result.get('status')!r}, not 'archived'.")
4937
+ return 1
4938
+ problem = next((p for p in result.get("problems", []) if p.get("code") == "task-archived"), None)
4939
+ if problem is None:
4940
+ report(f"{label} keel guard status carries no task-archived problem: {result.get('problems')!r}")
4941
+ return 1
4942
+ for needle in ("openspec/changes/archive/2026-10-27-demo", "keel guard clear"):
4943
+ if needle not in problem.get("message", ""):
4944
+ report(f"{label} the task-archived message does not name {needle!r}: {problem!r}")
4945
+ return 1
4946
+ if label.rstrip(":") not in {name for name, _ in registry.SCENARIOS}:
4947
+ report(f"{label} the scenario registry does not include it.")
4948
+ return 1
4949
+ report(f"{label.rstrip(':')} scenario passed.")
4950
+ return 0
4951
+
4952
+
4894
4953
  def validate_guard_status_stale_manifest_scenario() -> int:
4895
4954
  """`keel guard status` says which of two states the manifest is in.
4896
4955
 
@@ -363,6 +363,7 @@ SCENARIOS: tuple = (
363
363
  ("tracker-durable-owner", contract.validate_tracker_durable_owner_scenario),
364
364
  ("findings-resolved-here", contract.validate_findings_resolved_here_scenario),
365
365
  ("guard-stale-manifest", guard.validate_guard_stale_manifest_scenario),
366
+ ("guard-archived-complete-task", guard.validate_guard_archived_complete_task_scenario),
366
367
  (
367
368
  "guard-status-stale-manifest",
368
369
  guard.validate_guard_status_stale_manifest_scenario,
package/src/core/guard.js CHANGED
@@ -283,6 +283,31 @@ function startGuard(repo, options) {
283
283
  return guardResult("start", "started", { manifest });
284
284
  }
285
285
 
286
+ // The archived copy of a change, the lexically last `<YYYY-MM-DD>-<change>`
287
+ // under openspec/changes/archive/, when its tasks.md shows the task checked;
288
+ // otherwise null. The write guard hook makes the same test (#491 D1).
289
+ function archivedCheckedChange(repo, change, task) {
290
+ const root = path.join(repo, "openspec", "changes", "archive");
291
+ let names = [];
292
+ try {
293
+ names = fs.readdirSync(root);
294
+ } catch {
295
+ return null;
296
+ }
297
+ const own = names.filter((name) => /^\d{4}-\d{2}-\d{2}-/.test(name) && name.slice(11) === change).sort();
298
+ if (!own.length) return null;
299
+ const dir = path.join(root, own[own.length - 1]);
300
+ let content = "";
301
+ try {
302
+ content = fs.readFileSync(path.join(dir, "tasks.md"), "utf8");
303
+ } catch {
304
+ return null;
305
+ }
306
+ const id = task.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
307
+ const match = content.match(new RegExp(`^\\s*-\\s*\\[([ xX])\\]\\s*${id}(?![0-9.])`, "m"));
308
+ return match && match[1].toLowerCase() === "x" ? path.relative(repo, dir).split(path.sep).join("/") : null;
309
+ }
310
+
286
311
  function guardStatus(repo) {
287
312
  const existing = readManifest(repo);
288
313
  if (existing.state === "absent") {
@@ -312,6 +337,21 @@ function guardStatus(repo) {
312
337
  // also leaves a live change whose tasks.md is absent — mid-authoring — on
313
338
  // the reauthorize path, where reauthorizing genuinely is the way out.
314
339
  const changeDir = path.join(repo, "openspec", "changes", manifest.change);
340
+ const archived = fs.existsSync(changeDir) ? null : archivedCheckedChange(repo, manifest.change, manifest.task);
341
+ if (archived) {
342
+ const finished = guardResult("status", "archived", { manifest });
343
+ finished.problems = [
344
+ {
345
+ code: "task-archived",
346
+ message:
347
+ `Guarded task ${manifest.change}#${manifest.task} is checked complete `
348
+ + `and its change is archived at ${archived}, so this manifest `
349
+ + "enforces nothing. `keel guard clear` removes it, and the next "
350
+ + "`keel gate task-start` replaces it.",
351
+ },
352
+ ];
353
+ return finished;
354
+ }
315
355
  problems.push(
316
356
  fs.existsSync(changeDir)
317
357
  ? {