@christang/keel 5.210.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.
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +2 -1
- package/README.zh-CN.md +2 -1
- package/assets/bootstrap/AGENTS.md +1 -1
- package/bin/keel.js +1 -1
- 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/scripts/pretooluse-guard.js +39 -13
- package/scripts/validation/common.py +2 -2
- package/scripts/validation/guard.py +114 -0
- package/scripts/validation/registry.py +2 -0
- package/src/core/guard.js +40 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keel",
|
|
3
|
-
"version": "5.
|
|
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
|
|
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
|
### 常设授权
|
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
|
}
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@christang/keel",
|
|
3
|
-
"version": "5.
|
|
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.
|
|
9
|
+
"version": "5.212.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.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.
|
|
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
|
|
@@ -180,6 +195,9 @@ function repoRelative(repo, target) {
|
|
|
180
195
|
// check standing: a broken declaration fails toward more checking (D3).
|
|
181
196
|
|
|
182
197
|
const EXPLICIT_FORM = "`git push origin <branch>`";
|
|
198
|
+
// A push after `cd` may run in another repository than the one whose config
|
|
199
|
+
// is read, so the form to use names the directory instead (#486).
|
|
200
|
+
const DIRECTORY_FORM = "`git -C <directory> push <remote> <branch>`";
|
|
183
201
|
|
|
184
202
|
function gitOut(cwd, args) {
|
|
185
203
|
const result = spawnSync("git", ["-C", cwd, ...args], { encoding: "utf8", timeout: 3000 });
|
|
@@ -460,9 +478,13 @@ function pushDestination(dir) {
|
|
|
460
478
|
return remote ? rest.slice(remote.length + 1) : null;
|
|
461
479
|
}
|
|
462
480
|
|
|
463
|
-
// Target branches of one push, or { undetermined: reason }.
|
|
481
|
+
// Target branches of one push, or { undetermined: reason[, form] }.
|
|
464
482
|
function pushTargets(push) {
|
|
465
483
|
if (push.undetermined) return push;
|
|
484
|
+
// Whatever the refspec, the repository it pushes is unknown here (#486 D1).
|
|
485
|
+
if (push.cdBefore) {
|
|
486
|
+
return { undetermined: "a `cd` or `pushd` runs before this `git push`, so the repository it pushes is unknown here", form: DIRECTORY_FORM };
|
|
487
|
+
}
|
|
466
488
|
const positionals = [];
|
|
467
489
|
let deleting = false;
|
|
468
490
|
let followTags = null;
|
|
@@ -506,13 +528,7 @@ function pushTargets(push) {
|
|
|
506
528
|
tags = "`push.followTags`";
|
|
507
529
|
}
|
|
508
530
|
const refspecs = positionals.slice(1);
|
|
509
|
-
const needsCurrent = () => {
|
|
510
|
-
if (push.cdBefore) return { undetermined: "the directory changes before it, so its branch is unknown here" };
|
|
511
|
-
return null;
|
|
512
|
-
};
|
|
513
531
|
if (!refspecs.length) {
|
|
514
|
-
const unknown = needsCurrent();
|
|
515
|
-
if (unknown) return unknown;
|
|
516
532
|
const branch = pushDestination(push.dir);
|
|
517
533
|
return branch ? { targets: [branch], tags } : { undetermined: "the branch has no configured push destination" };
|
|
518
534
|
}
|
|
@@ -524,8 +540,6 @@ function pushTargets(push) {
|
|
|
524
540
|
else if (spec.startsWith(":")) dst = spec.slice(1);
|
|
525
541
|
if (!dst) return { undetermined: `\`${raw}\` names no destination` };
|
|
526
542
|
if (dst === "HEAD" || dst === "@") {
|
|
527
|
-
const unknown = needsCurrent();
|
|
528
|
-
if (unknown) return unknown;
|
|
529
543
|
dst = currentBranch(push.dir);
|
|
530
544
|
if (!dst) return { undetermined: "HEAD is detached" };
|
|
531
545
|
}
|
|
@@ -553,6 +567,14 @@ function checkPushes(event) {
|
|
|
553
567
|
...protectedEntries.map((e) => `\`push-protected:${e.glob}${e.role ? `@${e.role}` : ""}\``),
|
|
554
568
|
].join(", ");
|
|
555
569
|
const result = pushTargets(push);
|
|
570
|
+
if (result.form) {
|
|
571
|
+
// Which repository it pushes is the unknown, not its branch (#486 D2).
|
|
572
|
+
deny(
|
|
573
|
+
`Keel push guard: ${result.undetermined}, so this repository's push rules in keel/config.yaml `
|
|
574
|
+
+ `cannot be applied to it. Push without changing directory, as ${result.form}.`
|
|
575
|
+
);
|
|
576
|
+
return 0;
|
|
577
|
+
}
|
|
556
578
|
if (result.undetermined) {
|
|
557
579
|
deny(
|
|
558
580
|
`Keel push guard: keel/config.yaml limits push to ${declared}, and the `
|
|
@@ -706,10 +728,14 @@ function main() {
|
|
|
706
728
|
// the stale Touch was denied by a message naming a task in an archived change
|
|
707
729
|
// and telling the reader to reauthorize it, which cannot be done; a write
|
|
708
730
|
// *inside* it passed silently, so an archived task went on granting write
|
|
709
|
-
// authority. Denying here fixes both, and denying
|
|
710
|
-
// what stops `openspec archive` from quietly disabling the
|
|
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).
|
|
711
735
|
const changeDir = path.join(repo, "openspec", "changes", manifest.change);
|
|
712
736
|
if (!fs.existsSync(changeDir)) {
|
|
737
|
+
const archived = archivedChangeDir(repo, manifest.change);
|
|
738
|
+
if (archived && taskIsChecked(repo, manifest, archived)) return 0;
|
|
713
739
|
deny(
|
|
714
740
|
`Keel write guard: this manifest is stale — it guards ${pointer}, but `
|
|
715
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.
|
|
38
|
+
PACKAGE_VERSION = "5.212.0"
|
|
39
39
|
|
|
40
40
|
|
|
41
|
-
PROTOCOL_VERSION = "5.
|
|
41
|
+
PROTOCOL_VERSION = "5.212.0"
|
|
42
42
|
|
|
43
43
|
|
|
44
44
|
LEGACY_MANAGED_START = "<!-- keel:start version=2.1 -->"
|
|
@@ -3903,6 +3903,61 @@ def validate_push_branch_guard_scenario() -> int:
|
|
|
3903
3903
|
return 0
|
|
3904
3904
|
|
|
3905
3905
|
|
|
3906
|
+
def validate_push_guard_cd_before_push_scenario() -> int:
|
|
3907
|
+
"""Issue #486: a `cd` before a push leaves its repository unknown, whatever the refspec.
|
|
3908
|
+
|
|
3909
|
+
The guard reads the push scope of the session's repository. kaiwu-layout's
|
|
3910
|
+
`cd <export dir> && git push <url> main:main` was judged by kaiwu-ip's
|
|
3911
|
+
`push-protected:main@kaiwu-chief`, though it pushed another repository.
|
|
3912
|
+
The refusal now names `git -C <directory> push`, which is judged by the
|
|
3913
|
+
repository it names.
|
|
3914
|
+
"""
|
|
3915
|
+
label = "push-guard-cd-before-push:"
|
|
3916
|
+
with tempfile.TemporaryDirectory(prefix="keel-push-cd-486-") as raw:
|
|
3917
|
+
base = Path(raw)
|
|
3918
|
+
repo = base / "repo"
|
|
3919
|
+
other = base / "export"
|
|
3920
|
+
|
|
3921
|
+
def git(*args: str, cwd: Path) -> None:
|
|
3922
|
+
subprocess.run(["git", *args], cwd=cwd, check=True, capture_output=True, text=True)
|
|
3923
|
+
|
|
3924
|
+
for tree in (repo, other):
|
|
3925
|
+
git("init", "-q", "-b", "main", str(tree), cwd=base)
|
|
3926
|
+
git("-c", "user.name=t", "-c", "user.email=t@t", "commit", "-q", "--allow-empty", "-m", "init", cwd=tree)
|
|
3927
|
+
(repo / "sub").mkdir()
|
|
3928
|
+
write_authorize_config(repo, "authorize:\n - push:claude/*\n - push-protected:main@chief\n")
|
|
3929
|
+
|
|
3930
|
+
def decide(command: str) -> dict | None:
|
|
3931
|
+
event = {"tool_name": "Bash", "tool_input": {"command": command}, "cwd": str(repo)}
|
|
3932
|
+
return pretooluse_decision(run_pretooluse_guard_hook(repo, event))
|
|
3933
|
+
|
|
3934
|
+
url = "https://example.invalid/acme/export.git"
|
|
3935
|
+
for what, command in (
|
|
3936
|
+
("a push in another repository after cd", f"cd {other} && git push {url} main:main"),
|
|
3937
|
+
("a push to a declared branch after cd", "cd sub && git push origin claude/fix"),
|
|
3938
|
+
):
|
|
3939
|
+
decision = decide(command)
|
|
3940
|
+
if not decision or decision.get("permissionDecision") != "deny":
|
|
3941
|
+
report(f"{label} {what} ({command!r}) was not denied: {decision!r}")
|
|
3942
|
+
return 1
|
|
3943
|
+
reason = decision.get("permissionDecisionReason", "")
|
|
3944
|
+
if "git -C <directory> push" not in reason:
|
|
3945
|
+
report(f"{label} {what} was denied without naming `git -C <directory> push`: {reason!r}")
|
|
3946
|
+
return 1
|
|
3947
|
+
if "chief" in reason:
|
|
3948
|
+
report(f"{label} {what} was judged by the session repository's protected branch: {reason!r}")
|
|
3949
|
+
return 1
|
|
3950
|
+
decision = decide(f"git -C {other} push {url} main:main")
|
|
3951
|
+
if decision is not None:
|
|
3952
|
+
report(f"{label} `git -C` into a repository that declares nothing got a decision: {decision!r}")
|
|
3953
|
+
return 1
|
|
3954
|
+
if label.rstrip(":") not in {name for name, _ in registry.SCENARIOS}:
|
|
3955
|
+
report(f"{label} the scenario registry does not include it.")
|
|
3956
|
+
return 1
|
|
3957
|
+
report(f"{label.rstrip(':')} scenario passed.")
|
|
3958
|
+
return 0
|
|
3959
|
+
|
|
3960
|
+
|
|
3906
3961
|
def validate_authorize_role_scoped_scenario() -> int:
|
|
3907
3962
|
"""Issue #378: a scoped grant may name the roles it applies to.
|
|
3908
3963
|
|
|
@@ -4836,6 +4891,65 @@ def guard_status_payload(repo: Path, cell: str) -> tuple[dict, str]:
|
|
|
4836
4891
|
return payload, (problems[0].get("message", "") if problems else "")
|
|
4837
4892
|
|
|
4838
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
|
+
|
|
4839
4953
|
def validate_guard_status_stale_manifest_scenario() -> int:
|
|
4840
4954
|
"""`keel guard status` says which of two states the manifest is in.
|
|
4841
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,
|
|
@@ -504,6 +505,7 @@ SCENARIOS: tuple = (
|
|
|
504
505
|
("native-plugin-install-matrix", hosts.validate_native_plugin_install_matrix_scenario),
|
|
505
506
|
("touch-write-guard", guard.validate_touch_write_guard_scenario),
|
|
506
507
|
("push-branch-guard", guard.validate_push_branch_guard_scenario),
|
|
508
|
+
("push-guard-cd-before-push", guard.validate_push_guard_cd_before_push_scenario),
|
|
507
509
|
("push-guard-redirects", guard.validate_push_guard_redirects_scenario),
|
|
508
510
|
("push-guard-follow-tags", guard.validate_push_guard_follow_tags_scenario),
|
|
509
511
|
("push-protected-guard", guard.validate_push_protected_guard_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
|
? {
|