@christang/keel 5.214.0 → 5.216.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/assets/bootstrap/AGENTS.md +1 -1
- package/bin/keel.js +2 -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/scripts/validation/common.py +18 -2
- package/scripts/validation/hosts.py +38 -4
- package/scripts/validation/registry.py +5 -0
- package/scripts/validation/shift.py +202 -0
- package/src/core/config.js +13 -1
- package/src/core/context.js +2 -1
- package/src/core/guard.js +10 -0
- package/src/core/shift.js +46 -6
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.216.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/bin/keel.js
CHANGED
|
@@ -26,6 +26,7 @@ const {
|
|
|
26
26
|
const {
|
|
27
27
|
GuardInputError,
|
|
28
28
|
clearGuard,
|
|
29
|
+
guardHolds,
|
|
29
30
|
guardStatus,
|
|
30
31
|
renderGuard,
|
|
31
32
|
startGuard,
|
|
@@ -1489,7 +1490,7 @@ function adoptClaudeSessions(options) {
|
|
|
1489
1490
|
left.push(`${named(row)}, ${row.status}`);
|
|
1490
1491
|
continue;
|
|
1491
1492
|
}
|
|
1492
|
-
if (row.cwd &&
|
|
1493
|
+
if (row.cwd && guardHolds(row.cwd)) {
|
|
1493
1494
|
left.push(`${named(row)}, under a task's write guard`);
|
|
1494
1495
|
continue;
|
|
1495
1496
|
}
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@christang/keel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.216.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.216.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.216.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.216.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",
|
|
@@ -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.216.0"
|
|
39
39
|
|
|
40
40
|
|
|
41
|
-
PROTOCOL_VERSION = "5.
|
|
41
|
+
PROTOCOL_VERSION = "5.216.0"
|
|
42
42
|
|
|
43
43
|
|
|
44
44
|
LEGACY_MANAGED_START = "<!-- keel:start version=2.1 -->"
|
|
@@ -868,6 +868,22 @@ def chat_records_with(repo: Path, group: str, needle: str) -> list[str]:
|
|
|
868
868
|
return [p.read_text(encoding="utf-8") for p in sorted(log.glob("*.md")) if needle in p.read_text(encoding="utf-8")]
|
|
869
869
|
|
|
870
870
|
|
|
871
|
+
def archived_guard(repo: Path, change: str = "demo", task: str = "1.1") -> None:
|
|
872
|
+
"""A shape-valid `keel/guard.json` over `change#task`, checked and archived (#496).
|
|
873
|
+
|
|
874
|
+
`keel guard status` reads it as `archived`: the change directory is gone and
|
|
875
|
+
its archived copy shows the task checked, so the manifest enforces nothing.
|
|
876
|
+
"""
|
|
877
|
+
tasks = f"openspec/changes/archive/2026-10-28-{change}/tasks.md"
|
|
878
|
+
write_text(repo / tasks, f"# Tasks\n\n- [x] {task} Done\n")
|
|
879
|
+
zero = "0" * 64
|
|
880
|
+
write_text(repo / "keel" / "guard.json", json.dumps({
|
|
881
|
+
"schema": "keel-write-guard/v1", "change": change, "task": task,
|
|
882
|
+
"fingerprint": {"algorithm": "sha256", "value": zero},
|
|
883
|
+
"touch": ["src/a.txt"], "authority": [{"path": tasks, "sha256": zero}],
|
|
884
|
+
}) + "\n")
|
|
885
|
+
|
|
886
|
+
|
|
871
887
|
def shift_scratch(base: Path) -> tuple[Path, Path, dict, Path]:
|
|
872
888
|
"""`rtl` and `verify` worktrees pushed to a bare remote, for shift scenarios."""
|
|
873
889
|
rtl, verify, env = chat_scratch_group(base)
|
|
@@ -22,6 +22,7 @@ from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
|
22
22
|
from pathlib import Path
|
|
23
23
|
|
|
24
24
|
from validation.common import (
|
|
25
|
+
archived_guard,
|
|
25
26
|
portable_projection_bytes,
|
|
26
27
|
HANDOFF_STUB,
|
|
27
28
|
OPENSPEC_CONFIG_PATH,
|
|
@@ -2798,6 +2799,9 @@ def validate_update_adopts_idle_sessions_scenario() -> int:
|
|
|
2798
2799
|
npm.chmod(0o755)
|
|
2799
2800
|
guarded = tmp / "guarded"
|
|
2800
2801
|
write_text(guarded / "keel" / "guard.json", "{}\n")
|
|
2802
|
+
# Only a checked, archived task's manifest, which enforces nothing (#496).
|
|
2803
|
+
finished = tmp / "finished"
|
|
2804
|
+
archived_guard(finished)
|
|
2801
2805
|
sleepers: list[int] = []
|
|
2802
2806
|
|
|
2803
2807
|
def row(name: str, sid: str, status: str, started: int, cwd: Path) -> dict:
|
|
@@ -2818,6 +2822,7 @@ def validate_update_adopts_idle_sessions_scenario() -> int:
|
|
|
2818
2822
|
row("rtl · old guarded", "cccccccc-0000-0000-0000-000000000003", "idle", t0 - 3600000, guarded),
|
|
2819
2823
|
row("pm · fresh idle", "dddddddd-0000-0000-0000-000000000004", "idle", t0 + 3600000, tmp),
|
|
2820
2824
|
row("maint · this session", "eeeeeeee-0000-0000-0000-000000000005", "busy", t0 - 3600000, tmp),
|
|
2825
|
+
row("ip · old finished", "ffffffff-0000-0000-0000-000000000006", "idle", t0 - 3600000, finished),
|
|
2821
2826
|
]
|
|
2822
2827
|
(tmp / "state.json").write_text(json.dumps({"version": "5.0.0", "lastUpdated": "2026-10-21T00:00:00.000Z", "rows": rows}))
|
|
2823
2828
|
env = dict(os.environ)
|
|
@@ -2840,11 +2845,15 @@ def validate_update_adopts_idle_sessions_scenario() -> int:
|
|
|
2840
2845
|
if adopted.returncode != 0:
|
|
2841
2846
|
report(f"{label} keel --update --adopt exited {adopted.returncode}: {adopted.stdout!r} {adopted.stderr!r}")
|
|
2842
2847
|
return 1
|
|
2843
|
-
if
|
|
2844
|
-
report(f"{label} --adopt
|
|
2848
|
+
if "ffffffff" not in stops:
|
|
2849
|
+
report(f"{label} --adopt left alone the session whose worktree holds only an archived manifest: {line!r}")
|
|
2845
2850
|
return 1
|
|
2846
|
-
if
|
|
2847
|
-
report(f"{label} --adopt
|
|
2851
|
+
if stops != ["aaaaaaaa", "ffffffff"]:
|
|
2852
|
+
report(f"{label} --adopt stopped {stops!r}, not only the idle sessions started before the update.")
|
|
2853
|
+
return 1
|
|
2854
|
+
if [r["args"] for r in resumes] != [["--bg", "--resume", "aaaaaaaa-0000-0000-0000-000000000001"],
|
|
2855
|
+
["--bg", "--resume", "ffffffff-0000-0000-0000-000000000006"]]:
|
|
2856
|
+
report(f"{label} --adopt did not resume the stopped sessions with exactly `--bg --resume <id>`: {resumes!r}")
|
|
2848
2857
|
return 1
|
|
2849
2858
|
if resumes[0]["cwd"] != os.path.realpath(tmp) and resumes[0]["cwd"] != str(tmp):
|
|
2850
2859
|
report(f"{label} the resume ran in {resumes[0]['cwd']!r}, not the session's worktree {str(tmp)!r}.")
|
|
@@ -4346,6 +4355,31 @@ def validate_context_names_the_protocol_refresh_scenario() -> int:
|
|
|
4346
4355
|
return 0
|
|
4347
4356
|
|
|
4348
4357
|
|
|
4358
|
+
def validate_context_archived_guard_does_not_defer_refresh_scenario() -> int:
|
|
4359
|
+
"""Issue #496: a manifest over a checked, archived task defers nothing."""
|
|
4360
|
+
label = "context-archived-guard-does-not-defer-refresh:"
|
|
4361
|
+
with tempfile.TemporaryDirectory(prefix="keel-protocol-496-") as raw:
|
|
4362
|
+
repo = _installed_repo(Path(raw), "archived", "claude", "5.0.0")
|
|
4363
|
+
write_text(repo / "keel/config.yaml", "authorize:\n - protocol-refresh\n")
|
|
4364
|
+
archived_guard(repo)
|
|
4365
|
+
status = run_keel(repo, "guard", "status")
|
|
4366
|
+
if "Status: archived" not in status.stdout:
|
|
4367
|
+
report(f"{label} the fixture manifest does not read as archived: {status.stdout.strip()!r}")
|
|
4368
|
+
return 1
|
|
4369
|
+
lines = _protocol_lines(repo)
|
|
4370
|
+
if len(lines) != 1:
|
|
4371
|
+
report(f"{label} context printed {len(lines)} Protocol lines, not one: {lines!r}")
|
|
4372
|
+
return 1
|
|
4373
|
+
if "deferred" in lines[0]:
|
|
4374
|
+
report(f"{label} an archived manifest deferred the refresh: {lines!r}")
|
|
4375
|
+
return 1
|
|
4376
|
+
if "standing-authorized" not in lines[0]:
|
|
4377
|
+
report(f"{label} the refresh is not read as standing-authorized: {lines!r}")
|
|
4378
|
+
return 1
|
|
4379
|
+
report(f"{label.rstrip(':')} scenario passed.")
|
|
4380
|
+
return 0
|
|
4381
|
+
|
|
4382
|
+
|
|
4349
4383
|
def validate_native_plugin_marketplaces_scenario() -> int:
|
|
4350
4384
|
codex = shutil.which("codex")
|
|
4351
4385
|
claude = claude_cli()
|
|
@@ -415,6 +415,7 @@ SCENARIOS: tuple = (
|
|
|
415
415
|
("directory-tree-is-the-package-renamed", hosts.validate_directory_tree_is_the_package_renamed_scenario),
|
|
416
416
|
("init-declares-plugin-auto-update", hosts.validate_init_declares_plugin_auto_update_scenario),
|
|
417
417
|
("context-names-the-protocol-refresh", hosts.validate_context_names_the_protocol_refresh_scenario),
|
|
418
|
+
("context-archived-guard-does-not-defer-refresh", hosts.validate_context_archived_guard_does_not_defer_refresh_scenario),
|
|
418
419
|
("collected-feedback-is-recorded", chat.validate_collected_feedback_is_recorded_scenario),
|
|
419
420
|
("shift-change", shift.validate_shift_change_scenario),
|
|
420
421
|
("shift-role-elsewhere", shift.validate_shift_role_elsewhere_scenario),
|
|
@@ -488,6 +489,10 @@ SCENARIOS: tuple = (
|
|
|
488
489
|
("launchd-stable-node", shift.validate_launchd_stable_node_scenario),
|
|
489
490
|
("shift-slash-command", shift.validate_shift_slash_command_scenario),
|
|
490
491
|
("shift-check-skips-host-keep-awake", shift.validate_shift_check_skips_host_keep_awake_scenario),
|
|
492
|
+
("shift-check-archived-guard-is-not-in-progress", shift.validate_shift_check_archived_guard_is_not_in_progress_scenario),
|
|
493
|
+
("shift-cli-handover-passes-default-model", shift.validate_shift_cli_handover_passes_default_model_scenario),
|
|
494
|
+
("shift-cli-declared-model-wins", shift.validate_shift_cli_declared_model_wins_scenario),
|
|
495
|
+
("shift-cli-handover-names-no-model-when-none", shift.validate_shift_cli_handover_names_no_model_when_none_scenario),
|
|
491
496
|
("patrol-exit-says-who-acts", shift.validate_patrol_exit_says_who_acts_scenario),
|
|
492
497
|
("patrol-nudge", shift.validate_patrol_nudge_scenario),
|
|
493
498
|
("patrol-escalate", shift.validate_patrol_escalate_scenario),
|
|
@@ -22,6 +22,7 @@ from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
|
22
22
|
from pathlib import Path
|
|
23
23
|
|
|
24
24
|
from validation.common import (
|
|
25
|
+
archived_guard,
|
|
25
26
|
BOOTSTRAP_BLOCK_BYTE_BUDGET,
|
|
26
27
|
ROOT,
|
|
27
28
|
extract_managed_block,
|
|
@@ -829,6 +830,59 @@ def validate_shift_check_skips_host_keep_awake_scenario() -> int:
|
|
|
829
830
|
return 0
|
|
830
831
|
|
|
831
832
|
|
|
833
|
+
def validate_shift_check_archived_guard_is_not_in_progress_scenario() -> int:
|
|
834
|
+
"""Issue #496: a manifest over a checked, archived task is not a loose end.
|
|
835
|
+
|
|
836
|
+
`keel guard status` reads it as `archived` and the hook enforces nothing
|
|
837
|
+
under it, so the check names it as a note with `keel guard clear`. The same
|
|
838
|
+
manifest over a live change still blocks.
|
|
839
|
+
"""
|
|
840
|
+
label = "shift-check-archived-guard-is-not-in-progress:"
|
|
841
|
+
with tempfile.TemporaryDirectory(prefix="keel-shift-496-") as raw:
|
|
842
|
+
base = Path(raw)
|
|
843
|
+
_rtl, verify, env, _ = shift_scratch(base)
|
|
844
|
+
# keel/.gitignore ignores the manifest, as a Keel repository's does.
|
|
845
|
+
write_text(verify / "keel" / ".gitignore", "guard.json\n")
|
|
846
|
+
subprocess.run(["git", "add", "keel/.gitignore"], cwd=verify, check=True, capture_output=True)
|
|
847
|
+
subprocess.run(["git", "commit", "-q", "-m", "ignore guard"], cwd=verify, check=True, capture_output=True)
|
|
848
|
+
subprocess.run(["git", "push", "-q"], cwd=verify, check=True, capture_output=True)
|
|
849
|
+
archived_guard(verify)
|
|
850
|
+
subprocess.run(["git", "add", "openspec"], cwd=verify, check=True, capture_output=True)
|
|
851
|
+
subprocess.run(["git", "commit", "-q", "-m", "archive demo"], cwd=verify, check=True, capture_output=True)
|
|
852
|
+
subprocess.run(["git", "push", "-q"], cwd=verify, check=True, capture_output=True)
|
|
853
|
+
status = run_keel(verify, "guard", "status", env=env)
|
|
854
|
+
if "Status: archived" not in status.stdout:
|
|
855
|
+
report(f"{label} the fixture manifest does not read as archived: {status.stdout.strip()!r}")
|
|
856
|
+
return 1
|
|
857
|
+
checked = run_keel(verify, "shift", "check", "--json", env=env)
|
|
858
|
+
found = chat_json(checked)
|
|
859
|
+
kinds = [item["kind"] for item in found.get("items", [])]
|
|
860
|
+
if "task-in-progress" in kinds:
|
|
861
|
+
report(f"{label} an archived manifest is reported as task-in-progress: {checked.stdout.strip()[:600]}")
|
|
862
|
+
return 1
|
|
863
|
+
if checked.returncode != 0:
|
|
864
|
+
report(f"{label} with only an archived manifest, keel shift check exited {checked.returncode}: {checked.stdout.strip()[:600]}")
|
|
865
|
+
return 1
|
|
866
|
+
if not any("keel guard clear" in note for note in found.get("notes", [])):
|
|
867
|
+
report(f"{label} no note names `keel guard clear` for the archived manifest: {found.get('notes')!r}")
|
|
868
|
+
return 1
|
|
869
|
+
# The same manifest over a live change of that name still holds.
|
|
870
|
+
live = verify / "openspec" / "changes" / "demo"
|
|
871
|
+
write_text(live / "tasks.md", "# Tasks\n\n- [ ] 1.1 Not yet\n")
|
|
872
|
+
subprocess.run(["git", "add", "openspec"], cwd=verify, check=True, capture_output=True)
|
|
873
|
+
subprocess.run(["git", "commit", "-q", "-m", "live demo"], cwd=verify, check=True, capture_output=True)
|
|
874
|
+
subprocess.run(["git", "push", "-q"], cwd=verify, check=True, capture_output=True)
|
|
875
|
+
held = run_keel(verify, "shift", "check", "--json", env=env)
|
|
876
|
+
if "task-in-progress" not in [item["kind"] for item in chat_json(held).get("items", [])]:
|
|
877
|
+
report(f"{label} a manifest over a live change is not reported as task-in-progress: {held.stdout.strip()[:600]}")
|
|
878
|
+
return 1
|
|
879
|
+
if held.returncode != 1:
|
|
880
|
+
report(f"{label} with a manifest over a live change, keel shift check exited {held.returncode}: {held.stdout.strip()[:600]}")
|
|
881
|
+
return 1
|
|
882
|
+
report("shift-check-archived-guard-is-not-in-progress scenario passed.")
|
|
883
|
+
return 0
|
|
884
|
+
|
|
885
|
+
|
|
832
886
|
def validate_shift_slash_command_scenario() -> int:
|
|
833
887
|
"""Issue #386: a session changes its own shift with one slash command.
|
|
834
888
|
|
|
@@ -3700,6 +3754,154 @@ def validate_shift_cli_handover_claims_once_scenario() -> int:
|
|
|
3700
3754
|
return 0
|
|
3701
3755
|
|
|
3702
3756
|
|
|
3757
|
+
def handover_model_case(*, user=None, project=None, local=None, shift_yaml="", anthropic_model=None, raw_user=None) -> dict:
|
|
3758
|
+
"""One CLI hand-over (#500) under the settings given; the call that started the new session, the entry and `shift status`.
|
|
3759
|
+
|
|
3760
|
+
`user`, `project` and `local` are the `model` values of the user's
|
|
3761
|
+
`settings.json` (in `CLAUDE_CONFIG_DIR`), the worktree's `.claude/settings.json`
|
|
3762
|
+
and its `.claude/settings.local.json`; `raw_user` is that user file's text as is.
|
|
3763
|
+
"""
|
|
3764
|
+
OLD = "5b14fbae-b6aa-40b6-a72a-b3f89d2c6eea"
|
|
3765
|
+
with tempfile.TemporaryDirectory(prefix="keel-shift-500-") as raw:
|
|
3766
|
+
base = Path(raw)
|
|
3767
|
+
s = handover_retry_scratch(base, OLD)
|
|
3768
|
+
try:
|
|
3769
|
+
config_dir = base / "claude-config"
|
|
3770
|
+
env = {k: v for k, v in s["env"].items() if k != "ANTHROPIC_MODEL"}
|
|
3771
|
+
env["CLAUDE_CONFIG_DIR"] = str(config_dir)
|
|
3772
|
+
if anthropic_model:
|
|
3773
|
+
env["ANTHROPIC_MODEL"] = anthropic_model
|
|
3774
|
+
if raw_user is not None:
|
|
3775
|
+
write_text(config_dir / "settings.json", raw_user)
|
|
3776
|
+
elif user is not None:
|
|
3777
|
+
write_text(config_dir / "settings.json", json.dumps({"model": user, "effortLevel": "xhigh"}))
|
|
3778
|
+
if project is not None:
|
|
3779
|
+
write_text(s["verify"] / ".claude" / "settings.json", json.dumps({"model": project}))
|
|
3780
|
+
if local is not None:
|
|
3781
|
+
write_text(s["verify"] / ".claude" / "settings.local.json", json.dumps({"model": local}))
|
|
3782
|
+
if shift_yaml:
|
|
3783
|
+
write_text(s["verify"] / "keel" / "config.yaml", shift_yaml)
|
|
3784
|
+
run_keel(s["verify"], "tick", "--repo", str(s["rtl"]), env=env)
|
|
3785
|
+
starts = [json.loads(line)["argv"] for line in s["calls"].read_text().splitlines()
|
|
3786
|
+
if json.loads(line)["argv"][:1] == ["--bg"] and "--resume" not in json.loads(line)["argv"]]
|
|
3787
|
+
entry = json.loads(s["queue"].read_text())
|
|
3788
|
+
status = run_keel(s["verify"], "shift", "status", env=env).stdout
|
|
3789
|
+
return {"argv": starts[0] if starts else None, "entry": entry, "status": status, "starts": len(starts)}
|
|
3790
|
+
finally:
|
|
3791
|
+
with contextlib.suppress(OSError):
|
|
3792
|
+
os.kill(s["process"], signal.SIGKILL)
|
|
3793
|
+
|
|
3794
|
+
|
|
3795
|
+
def model_args(argv) -> list:
|
|
3796
|
+
"""The `--model` and `--effort` arguments of a start call, in the order given, before the prompt."""
|
|
3797
|
+
found = []
|
|
3798
|
+
for flag in ("--model", "--effort"):
|
|
3799
|
+
if argv and flag in argv[:-1]:
|
|
3800
|
+
found += [flag, argv[argv.index(flag) + 1]]
|
|
3801
|
+
return found
|
|
3802
|
+
|
|
3803
|
+
|
|
3804
|
+
def validate_shift_cli_handover_passes_default_model_scenario() -> int:
|
|
3805
|
+
"""Issue #500: a hand-over names the model the owner would get, in the host's own order.
|
|
3806
|
+
|
|
3807
|
+
Measured 2026-11-03: the session a hand-over started ran sonnet although the
|
|
3808
|
+
owner's `settings.json` says opus, because the call named no model and the
|
|
3809
|
+
host chose one. The call now carries `--model` after `--permission-mode`.
|
|
3810
|
+
"""
|
|
3811
|
+
label = "shift-cli-handover-passes-default-model:"
|
|
3812
|
+
steps = [
|
|
3813
|
+
({"user": "opus"}, "opus", "user settings"),
|
|
3814
|
+
({"user": "opus", "project": "sonnet"}, "sonnet", "project settings"),
|
|
3815
|
+
({"user": "opus", "project": "sonnet", "local": "haiku"}, "haiku", "project-local settings"),
|
|
3816
|
+
({"user": "opus", "project": "sonnet", "local": "haiku", "anthropic_model": "fable"}, "fable", "ANTHROPIC_MODEL"),
|
|
3817
|
+
]
|
|
3818
|
+
for case, model, source in steps:
|
|
3819
|
+
got = handover_model_case(**case)
|
|
3820
|
+
argv = got["argv"]
|
|
3821
|
+
if got["entry"].get("state") != "delivered":
|
|
3822
|
+
report(f"{label} with {sorted(case)} the hand-off was not delivered: {got['entry']!r}")
|
|
3823
|
+
return 1
|
|
3824
|
+
if not argv:
|
|
3825
|
+
report(f"{label} with {sorted(case)} the hand-off was delivered but no `claude --bg` start call was recorded.")
|
|
3826
|
+
return 1
|
|
3827
|
+
if argv[3:7] != ["--permission-mode", "auto", "--model", model]:
|
|
3828
|
+
report(f"{label} with {sorted(case)} the start call is {argv!r}, not `--permission-mode auto --model {model}` before the prompt.")
|
|
3829
|
+
return 1
|
|
3830
|
+
if "keel shift resume" not in argv[-1]:
|
|
3831
|
+
report(f"{label} with {sorted(case)} the prompt is no longer last in the start call: {argv!r}")
|
|
3832
|
+
return 1
|
|
3833
|
+
if got["entry"].get("model") != model or got["entry"].get("model_source") != source:
|
|
3834
|
+
report(f"{label} with {sorted(case)} the entry records {got['entry'].get('model')!r} from {got['entry'].get('model_source')!r}, not {model!r} from {source!r}.")
|
|
3835
|
+
return 1
|
|
3836
|
+
if model not in got["status"] or source not in got["status"]:
|
|
3837
|
+
report(f"{label} with {sorted(case)} `keel shift status` does not show {model!r} and {source!r}: {got['status']!r}")
|
|
3838
|
+
return 1
|
|
3839
|
+
if label.rstrip(":") not in {name for name, _ in registry.SCENARIOS}:
|
|
3840
|
+
report(f"{label} the scenario registry does not include it.")
|
|
3841
|
+
return 1
|
|
3842
|
+
report(f"{label.rstrip(':')} scenario passed.")
|
|
3843
|
+
return 0
|
|
3844
|
+
|
|
3845
|
+
|
|
3846
|
+
def validate_shift_cli_declared_model_wins_scenario() -> int:
|
|
3847
|
+
"""Issue #500: `shift: model:` and `shift: effort:` start a role's shifts on something else, on purpose."""
|
|
3848
|
+
label = "shift-cli-declared-model-wins:"
|
|
3849
|
+
got = handover_model_case(user="opus", project="haiku", local="haiku", anthropic_model="fable",
|
|
3850
|
+
shift_yaml="shift:\n model: sonnet\n effort: high\n")
|
|
3851
|
+
if model_args(got["argv"]) != ["--model", "sonnet", "--effort", "high"] or got["argv"][3:5] != ["--permission-mode", "auto"]:
|
|
3852
|
+
report(f"{label} the declaration did not win: {got['argv']!r}")
|
|
3853
|
+
return 1
|
|
3854
|
+
if got["entry"].get("model") != "sonnet" or got["entry"].get("model_source") != "declared":
|
|
3855
|
+
report(f"{label} the entry does not record the declared model: {got['entry']!r}")
|
|
3856
|
+
return 1
|
|
3857
|
+
bad = handover_model_case(user="opus", shift_yaml="shift:\n effort: extreme\n")
|
|
3858
|
+
if "--effort" in (bad["argv"] or []):
|
|
3859
|
+
report(f"{label} an effort Keel cannot read was passed: {bad['argv']!r}")
|
|
3860
|
+
return 1
|
|
3861
|
+
if model_args(bad["argv"]) != ["--model", "opus"]:
|
|
3862
|
+
report(f"{label} an effort Keel cannot read took the model with it: {bad['argv']!r}")
|
|
3863
|
+
return 1
|
|
3864
|
+
for needle in ("extreme", "low, medium, high, xhigh, max"):
|
|
3865
|
+
if needle not in bad["status"]:
|
|
3866
|
+
report(f"{label} `keel shift status` does not name {needle!r}: {bad['status']!r}")
|
|
3867
|
+
return 1
|
|
3868
|
+
if label.rstrip(":") not in {name for name, _ in registry.SCENARIOS}:
|
|
3869
|
+
report(f"{label} the scenario registry does not include it.")
|
|
3870
|
+
return 1
|
|
3871
|
+
report(f"{label.rstrip(':')} scenario passed.")
|
|
3872
|
+
return 0
|
|
3873
|
+
|
|
3874
|
+
|
|
3875
|
+
def validate_shift_cli_handover_names_no_model_when_none_scenario() -> int:
|
|
3876
|
+
"""Issue #500: when nothing names a model the call names none, and the hand-over still happens."""
|
|
3877
|
+
label = "shift-cli-handover-names-no-model-when-none:"
|
|
3878
|
+
cases = {
|
|
3879
|
+
"no source": {},
|
|
3880
|
+
"invalid JSON": {"raw_user": "{not json"},
|
|
3881
|
+
"model not a string": {"raw_user": json.dumps({"model": {"name": "opus"}})},
|
|
3882
|
+
"empty model": {"raw_user": json.dumps({"model": ""})},
|
|
3883
|
+
}
|
|
3884
|
+
for name, case in cases.items():
|
|
3885
|
+
got = handover_model_case(**case)
|
|
3886
|
+
if got["entry"].get("state") != "delivered":
|
|
3887
|
+
report(f"{label} with {name} the hand-off was not delivered: {got['entry']!r}")
|
|
3888
|
+
return 1
|
|
3889
|
+
if not got["argv"]:
|
|
3890
|
+
report(f"{label} with {name} the hand-off was delivered but no `claude --bg` start call was recorded.")
|
|
3891
|
+
return 1
|
|
3892
|
+
if model_args(got["argv"]):
|
|
3893
|
+
report(f"{label} with {name} the call names a model: {got['argv']!r}")
|
|
3894
|
+
return 1
|
|
3895
|
+
if "model" in got["entry"] or "model_source" in got["entry"]:
|
|
3896
|
+
report(f"{label} with {name} the entry records a model: {got['entry']!r}")
|
|
3897
|
+
return 1
|
|
3898
|
+
if label.rstrip(":") not in {name for name, _ in registry.SCENARIOS}:
|
|
3899
|
+
report(f"{label} the scenario registry does not include it.")
|
|
3900
|
+
return 1
|
|
3901
|
+
report(f"{label.rstrip(':')} scenario passed.")
|
|
3902
|
+
return 0
|
|
3903
|
+
|
|
3904
|
+
|
|
3703
3905
|
def validate_shift_cli_retries_failed_handover_scenario() -> int:
|
|
3704
3906
|
"""Issue #408, second loop: a failed hand-off is retried within a bound (D4, D5).
|
|
3705
3907
|
|
package/src/core/config.js
CHANGED
|
@@ -1087,6 +1087,9 @@ function readPatrolDeclaration(repo, options = {}) {
|
|
|
1087
1087
|
|
|
1088
1088
|
// `shift: permission_mode:` for the session a CLI hand-off starts (#357 D5).
|
|
1089
1089
|
const PERMISSION_MODES = ["default", "acceptEdits", "auto", "plan", "bypassPermissions"];
|
|
1090
|
+
// `shift: model:` is a name or alias the host takes after `--model`; `shift: effort:` one of its `--effort` levels (#500).
|
|
1091
|
+
const SHIFT_MODEL = /^[A-Za-z0-9][A-Za-z0-9._:\[\]-]*$/;
|
|
1092
|
+
const SHIFT_EFFORTS = ["low", "medium", "high", "xhigh", "max"];
|
|
1090
1093
|
// `shift: keep_old_sessions:`, how many stopped old shift sessions a hand-over
|
|
1091
1094
|
// leaves listed per role (#397 D2): a whole number, 0 when absent or unreadable,
|
|
1092
1095
|
// so the old shift leaves the session list where the owner could mistake it for
|
|
@@ -1102,7 +1105,16 @@ function readShiftDeclaration(repo) {
|
|
|
1102
1105
|
let keepOldSessions = 0;
|
|
1103
1106
|
if (keep !== undefined && /^\d+$/.test(String(keep).trim())) keepOldSessions = Number(String(keep).trim());
|
|
1104
1107
|
else if (keep !== undefined) messages.push(`keel/config.yaml shift: keep_old_sessions \`${keep}\` is not a whole number, so 0 applies.`);
|
|
1105
|
-
|
|
1108
|
+
// `model:` and `effort:` start a role's shifts on something else on purpose (#500).
|
|
1109
|
+
let model = null;
|
|
1110
|
+
const declaredModel = block.model === undefined ? undefined : String(block.model).trim();
|
|
1111
|
+
if (declaredModel !== undefined && SHIFT_MODEL.test(declaredModel)) model = declaredModel;
|
|
1112
|
+
else if (declaredModel !== undefined) messages.push(`keel/config.yaml shift: model \`${declaredModel}\` is not a model name or alias, so it is ignored.`);
|
|
1113
|
+
let effort = null;
|
|
1114
|
+
const declaredEffort = block.effort === undefined ? undefined : String(block.effort).trim();
|
|
1115
|
+
if (SHIFT_EFFORTS.includes(declaredEffort)) effort = declaredEffort;
|
|
1116
|
+
else if (declaredEffort !== undefined) messages.push(`keel/config.yaml shift: effort \`${declaredEffort}\` is not one of ${SHIFT_EFFORTS.join(", ")}, so it is ignored.`);
|
|
1117
|
+
return { permissionMode, keepOldSessions, model, effort, message: messages.length ? messages.join(" ") : null };
|
|
1106
1118
|
}
|
|
1107
1119
|
|
|
1108
1120
|
// `branches:` (#469 D1, D7): `trunk:` names the branches beyond the remote
|
package/src/core/context.js
CHANGED
|
@@ -23,6 +23,7 @@ const {
|
|
|
23
23
|
ownerLanguageRule,
|
|
24
24
|
} = require("./config");
|
|
25
25
|
const { isKeelSourceRepo } = require("./capabilities");
|
|
26
|
+
const { guardHolds } = require("./guard");
|
|
26
27
|
const { diagnoseDrift, driftCause } = require("./drift");
|
|
27
28
|
|
|
28
29
|
const NEXT_ACTIONS = new Set([
|
|
@@ -1000,7 +1001,7 @@ function protocolRefresh(repo, running, authorization) {
|
|
|
1000
1001
|
file: stamped.file,
|
|
1001
1002
|
command: `keel --install --target ${installedTarget(repo)}`,
|
|
1002
1003
|
authorized: authorization.scopes.has("protocol-refresh"),
|
|
1003
|
-
deferred:
|
|
1004
|
+
deferred: guardHolds(repo),
|
|
1004
1005
|
};
|
|
1005
1006
|
}
|
|
1006
1007
|
|
package/src/core/guard.js
CHANGED
|
@@ -424,6 +424,15 @@ function guardStatus(repo) {
|
|
|
424
424
|
return guardResult("status", "active", { manifest });
|
|
425
425
|
}
|
|
426
426
|
|
|
427
|
+
// Whether a manifest is in force: every state but `absent` and `archived`
|
|
428
|
+
// still has the hook deny writes, so only those two hold nothing (#496 D1).
|
|
429
|
+
// The shift check, the protocol refresh, and `--update --adopt` ask this
|
|
430
|
+
// rather than whether the file exists.
|
|
431
|
+
function guardHolds(repo) {
|
|
432
|
+
const { status } = guardStatus(repo);
|
|
433
|
+
return status !== "absent" && status !== "archived";
|
|
434
|
+
}
|
|
435
|
+
|
|
427
436
|
function clearGuard(repo) {
|
|
428
437
|
const file = manifestFile(repo);
|
|
429
438
|
if (!fs.existsSync(file)) {
|
|
@@ -456,6 +465,7 @@ module.exports = {
|
|
|
456
465
|
clearGuard,
|
|
457
466
|
contentSignature,
|
|
458
467
|
gitPaths,
|
|
468
|
+
guardHolds,
|
|
459
469
|
guardStatus,
|
|
460
470
|
readManifest,
|
|
461
471
|
renderGuard,
|
package/src/core/shift.js
CHANGED
|
@@ -18,6 +18,7 @@ const path = require("path");
|
|
|
18
18
|
const { spawn, spawnSync } = require("child_process");
|
|
19
19
|
const store = require("./chat/store");
|
|
20
20
|
const locks = require("./lock");
|
|
21
|
+
const guard = require("./guard");
|
|
21
22
|
|
|
22
23
|
const REF = "keel-shift";
|
|
23
24
|
const USAGE = [
|
|
@@ -197,7 +198,13 @@ function check(where, role) {
|
|
|
197
198
|
}
|
|
198
199
|
|
|
199
200
|
if (fs.existsSync(path.join(where.worktree, "keel", "guard.json"))) {
|
|
200
|
-
|
|
201
|
+
if (guard.guardHolds(where.worktree)) {
|
|
202
|
+
items.push({ kind: "task-in-progress", detail: "keel/guard.json: a task's write guard is still active; complete the task or clear the guard" });
|
|
203
|
+
} else {
|
|
204
|
+
// Checked and archived: the hook lets every write through (#496 D2).
|
|
205
|
+
const { manifest } = guard.guardStatus(where.worktree);
|
|
206
|
+
notes.push(`keel/guard.json guards ${manifest.change}#${manifest.task}, which is checked and archived, so it enforces nothing; \`keel guard clear\` removes it`);
|
|
207
|
+
}
|
|
201
208
|
}
|
|
202
209
|
|
|
203
210
|
for (const row of liveProcesses(where.worktree)) {
|
|
@@ -815,6 +822,36 @@ function claim(where, queued, sessions) {
|
|
|
815
822
|
});
|
|
816
823
|
}
|
|
817
824
|
|
|
825
|
+
// The model a hand-over starts the new session on (#500). The host chose one
|
|
826
|
+
// itself when the call named none, and on 2026-11-01 it chose sonnet over the
|
|
827
|
+
// owner's `model: opus`, so the call names the owner's default: the declared
|
|
828
|
+
// `shift: model:`, else the first of the host's own sources that names one, in
|
|
829
|
+
// its order. A missing file, invalid JSON, or a value that is not a plain
|
|
830
|
+
// string names nothing and the next source is tried; managed policy settings
|
|
831
|
+
// are not read. Null when no source names a model: the call then names none.
|
|
832
|
+
function resolveShiftModel(worktree, declared) {
|
|
833
|
+
if (declared && declared.model) return { model: declared.model, source: "declared" };
|
|
834
|
+
const named = (value) => (typeof value === "string" && value.trim() && !value.trim().startsWith("-") ? value.trim() : null);
|
|
835
|
+
const fromEnv = named(process.env.ANTHROPIC_MODEL);
|
|
836
|
+
if (fromEnv) return { model: fromEnv, source: "ANTHROPIC_MODEL" };
|
|
837
|
+
const config = process.env.CLAUDE_CONFIG_DIR || path.join(os.homedir(), ".claude");
|
|
838
|
+
const files = [
|
|
839
|
+
[path.join(worktree, ".claude", "settings.local.json"), "project-local settings"],
|
|
840
|
+
[path.join(worktree, ".claude", "settings.json"), "project settings"],
|
|
841
|
+
[path.join(config, "settings.json"), "user settings"],
|
|
842
|
+
];
|
|
843
|
+
for (const [file, source] of files) {
|
|
844
|
+
let model = null;
|
|
845
|
+
try {
|
|
846
|
+
model = named(JSON.parse(fs.readFileSync(file, "utf8")).model);
|
|
847
|
+
} catch {
|
|
848
|
+
model = null;
|
|
849
|
+
}
|
|
850
|
+
if (model) return { model, source };
|
|
851
|
+
}
|
|
852
|
+
return null;
|
|
853
|
+
}
|
|
854
|
+
|
|
818
855
|
// One step of the waker (#357 D2): a busy or unfinished old session waits; a
|
|
819
856
|
// finished or gone one is retired (stopped) and a new session starts. A claim
|
|
820
857
|
// left by a runner that died is settled, and a failed start is tried again
|
|
@@ -849,14 +886,17 @@ function handOver(where, only = null) {
|
|
|
849
886
|
// `stop`, `attach` and `logs` take the 8-character job id, not the full
|
|
850
887
|
// session id (`No job matching`, measured 2026-10-19).
|
|
851
888
|
if (row) retire(claude, entry, row);
|
|
852
|
-
const
|
|
889
|
+
const declaration = readShiftDeclaration(entry.worktree);
|
|
853
890
|
const name = sessionName(entry.role);
|
|
854
|
-
const
|
|
855
|
-
|
|
856
|
-
|
|
891
|
+
const chosen = resolveShiftModel(entry.worktree, declaration);
|
|
892
|
+
const startArgs = ["--bg", "-n", name, "--permission-mode", declaration.permissionMode,
|
|
893
|
+
...(chosen ? ["--model", chosen.model] : []), ...(declaration.effort ? ["--effort", declaration.effort] : []),
|
|
894
|
+
SHIFT_START_TEXT(entry.role)];
|
|
895
|
+
const started = spawnSync(claude, startArgs, { cwd: entry.worktree, encoding: "utf8", timeout: hostTimeout() });
|
|
857
896
|
const output = `${started.stdout || ""}`;
|
|
858
897
|
if (!started.error && started.status === 0) {
|
|
859
898
|
const id = (output.match(/backgrounded\s*·\s*(\S+)/) || [])[1] || null;
|
|
899
|
+
if (chosen) Object.assign(entry, { model: chosen.model, model_source: chosen.source });
|
|
860
900
|
done.push(deliver(claude, where, entry, id, name, false));
|
|
861
901
|
} else {
|
|
862
902
|
const reason = started.error ? hostTrouble(started, "claude --bg") : String(started.stderr || output).trim().split(/\r?\n/).pop();
|
|
@@ -896,7 +936,7 @@ function waitForHandOver(where, role) {
|
|
|
896
936
|
|
|
897
937
|
function describeHandOff(entry) {
|
|
898
938
|
const tail = entry.state === "delivered"
|
|
899
|
-
? `delivered ${entry.delivered_at} as session ${entry.new_session || "(id not printed)"}${entry.new_name ? ` "${entry.new_name}"` : ""}`
|
|
939
|
+
? `delivered ${entry.delivered_at} as session ${entry.new_session || "(id not printed)"}${entry.new_name ? ` "${entry.new_name}"` : ""}${entry.model ? ` on model ${entry.model} (${entry.model_source})` : ""}`
|
|
900
940
|
: entry.state === "failed" ? `failed ${entry.failed_at}: ${entry.error}; ${retryNote(entry)}`
|
|
901
941
|
: entry.state === "starting" ? `starting since ${entry.starting_at} (attempt ${entry.attempts} of ${HANDOVER_ATTEMPTS})`
|
|
902
942
|
: entry.waiting_on ? `pending: cannot ask the host — ${entry.waiting_on}` : "pending: waits for the session to go idle";
|