@christang/keel 5.210.0 → 5.211.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.210.0",
3
+ "version": "5.211.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,4 +1,4 @@
1
- <!-- keel:start version=5.210.0 -->
1
+ <!-- keel:start version=5.211.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.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@christang/keel",
3
- "version": "5.210.0",
3
+ "version": "5.211.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@christang/keel",
9
- "version": "5.210.0",
9
+ "version": "5.211.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.210.0",
5
+ "version": "5.211.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.210.0",
3
+ "version": "5.211.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.210.0",
3
+ "version": "5.211.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",
@@ -180,6 +180,9 @@ function repoRelative(repo, target) {
180
180
  // check standing: a broken declaration fails toward more checking (D3).
181
181
 
182
182
  const EXPLICIT_FORM = "`git push origin <branch>`";
183
+ // A push after `cd` may run in another repository than the one whose config
184
+ // is read, so the form to use names the directory instead (#486).
185
+ const DIRECTORY_FORM = "`git -C <directory> push <remote> <branch>`";
183
186
 
184
187
  function gitOut(cwd, args) {
185
188
  const result = spawnSync("git", ["-C", cwd, ...args], { encoding: "utf8", timeout: 3000 });
@@ -460,9 +463,13 @@ function pushDestination(dir) {
460
463
  return remote ? rest.slice(remote.length + 1) : null;
461
464
  }
462
465
 
463
- // Target branches of one push, or { undetermined: reason }.
466
+ // Target branches of one push, or { undetermined: reason[, form] }.
464
467
  function pushTargets(push) {
465
468
  if (push.undetermined) return push;
469
+ // Whatever the refspec, the repository it pushes is unknown here (#486 D1).
470
+ if (push.cdBefore) {
471
+ return { undetermined: "a `cd` or `pushd` runs before this `git push`, so the repository it pushes is unknown here", form: DIRECTORY_FORM };
472
+ }
466
473
  const positionals = [];
467
474
  let deleting = false;
468
475
  let followTags = null;
@@ -506,13 +513,7 @@ function pushTargets(push) {
506
513
  tags = "`push.followTags`";
507
514
  }
508
515
  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
516
  if (!refspecs.length) {
514
- const unknown = needsCurrent();
515
- if (unknown) return unknown;
516
517
  const branch = pushDestination(push.dir);
517
518
  return branch ? { targets: [branch], tags } : { undetermined: "the branch has no configured push destination" };
518
519
  }
@@ -524,8 +525,6 @@ function pushTargets(push) {
524
525
  else if (spec.startsWith(":")) dst = spec.slice(1);
525
526
  if (!dst) return { undetermined: `\`${raw}\` names no destination` };
526
527
  if (dst === "HEAD" || dst === "@") {
527
- const unknown = needsCurrent();
528
- if (unknown) return unknown;
529
528
  dst = currentBranch(push.dir);
530
529
  if (!dst) return { undetermined: "HEAD is detached" };
531
530
  }
@@ -553,6 +552,14 @@ function checkPushes(event) {
553
552
  ...protectedEntries.map((e) => `\`push-protected:${e.glob}${e.role ? `@${e.role}` : ""}\``),
554
553
  ].join(", ");
555
554
  const result = pushTargets(push);
555
+ if (result.form) {
556
+ // Which repository it pushes is the unknown, not its branch (#486 D2).
557
+ deny(
558
+ `Keel push guard: ${result.undetermined}, so this repository's push rules in keel/config.yaml `
559
+ + `cannot be applied to it. Push without changing directory, as ${result.form}.`
560
+ );
561
+ return 0;
562
+ }
556
563
  if (result.undetermined) {
557
564
  deny(
558
565
  `Keel push guard: keel/config.yaml limits push to ${declared}, and the `
@@ -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.210.0"
38
+ PACKAGE_VERSION = "5.211.0"
39
39
 
40
40
 
41
- PROTOCOL_VERSION = "5.210.0"
41
+ PROTOCOL_VERSION = "5.211.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
 
@@ -504,6 +504,7 @@ SCENARIOS: tuple = (
504
504
  ("native-plugin-install-matrix", hosts.validate_native_plugin_install_matrix_scenario),
505
505
  ("touch-write-guard", guard.validate_touch_write_guard_scenario),
506
506
  ("push-branch-guard", guard.validate_push_branch_guard_scenario),
507
+ ("push-guard-cd-before-push", guard.validate_push_guard_cd_before_push_scenario),
507
508
  ("push-guard-redirects", guard.validate_push_guard_redirects_scenario),
508
509
  ("push-guard-follow-tags", guard.validate_push_guard_follow_tags_scenario),
509
510
  ("push-protected-guard", guard.validate_push_protected_guard_scenario),