@christang/keel 5.215.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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keel",
3
- "version": "5.215.0",
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,4 +1,4 @@
1
- <!-- keel:start version=5.215.0 -->
1
+ <!-- keel:start version=5.216.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.215.0",
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.215.0",
9
+ "version": "5.216.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.215.0",
5
+ "version": "5.216.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.215.0",
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.215.0",
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.215.0"
38
+ PACKAGE_VERSION = "5.216.0"
39
39
 
40
40
 
41
- PROTOCOL_VERSION = "5.215.0"
41
+ PROTOCOL_VERSION = "5.216.0"
42
42
 
43
43
 
44
44
  LEGACY_MANAGED_START = "<!-- keel:start version=2.1 -->"
@@ -490,6 +490,9 @@ SCENARIOS: tuple = (
490
490
  ("shift-slash-command", shift.validate_shift_slash_command_scenario),
491
491
  ("shift-check-skips-host-keep-awake", shift.validate_shift_check_skips_host_keep_awake_scenario),
492
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),
493
496
  ("patrol-exit-says-who-acts", shift.validate_patrol_exit_says_who_acts_scenario),
494
497
  ("patrol-nudge", shift.validate_patrol_nudge_scenario),
495
498
  ("patrol-escalate", shift.validate_patrol_escalate_scenario),
@@ -3754,6 +3754,154 @@ def validate_shift_cli_handover_claims_once_scenario() -> int:
3754
3754
  return 0
3755
3755
 
3756
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
+
3757
3905
  def validate_shift_cli_retries_failed_handover_scenario() -> int:
3758
3906
  """Issue #408, second loop: a failed hand-off is retried within a bound (D4, D5).
3759
3907
 
@@ -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
- return { permissionMode, keepOldSessions, message: messages.length ? messages.join(" ") : null };
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/shift.js CHANGED
@@ -822,6 +822,36 @@ function claim(where, queued, sessions) {
822
822
  });
823
823
  }
824
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
+
825
855
  // One step of the waker (#357 D2): a busy or unfinished old session waits; a
826
856
  // finished or gone one is retired (stopped) and a new session starts. A claim
827
857
  // left by a runner that died is settled, and a failed start is tried again
@@ -856,14 +886,17 @@ function handOver(where, only = null) {
856
886
  // `stop`, `attach` and `logs` take the 8-character job id, not the full
857
887
  // session id (`No job matching`, measured 2026-10-19).
858
888
  if (row) retire(claude, entry, row);
859
- const mode = readShiftDeclaration(entry.worktree).permissionMode;
889
+ const declaration = readShiftDeclaration(entry.worktree);
860
890
  const name = sessionName(entry.role);
861
- const started = spawnSync(claude, ["--bg", "-n", name, "--permission-mode", mode, SHIFT_START_TEXT(entry.role)], {
862
- cwd: entry.worktree, encoding: "utf8", timeout: hostTimeout(),
863
- });
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() });
864
896
  const output = `${started.stdout || ""}`;
865
897
  if (!started.error && started.status === 0) {
866
898
  const id = (output.match(/backgrounded\s*·\s*(\S+)/) || [])[1] || null;
899
+ if (chosen) Object.assign(entry, { model: chosen.model, model_source: chosen.source });
867
900
  done.push(deliver(claude, where, entry, id, name, false));
868
901
  } else {
869
902
  const reason = started.error ? hostTrouble(started, "claude --bg") : String(started.stderr || output).trim().split(/\r?\n/).pop();
@@ -903,7 +936,7 @@ function waitForHandOver(where, role) {
903
936
 
904
937
  function describeHandOff(entry) {
905
938
  const tail = entry.state === "delivered"
906
- ? `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})` : ""}`
907
940
  : entry.state === "failed" ? `failed ${entry.failed_at}: ${entry.error}; ${retryNote(entry)}`
908
941
  : entry.state === "starting" ? `starting since ${entry.starting_at} (attempt ${entry.attempts} of ${HANDOVER_ATTEMPTS})`
909
942
  : entry.waiting_on ? `pending: cannot ask the host — ${entry.waiting_on}` : "pending: waits for the session to go idle";