@christang/keel 5.206.0 → 5.207.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.206.0",
3
+ "version": "5.207.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
@@ -883,6 +883,10 @@ fetches nothing, schedules nothing, calls no model, and writes nothing when noth
883
883
  0 then, 2 when the coordinator has something to act on — a risk, or its own wait met — 3 when it only
884
884
  recorded something or told other roles, and 1 on an error, so a cheap scheduler — cron, `/loop`, CI —
885
885
  can wake the model only on 2 (#350). `keel chat waits` lists what is still awaited.
886
+ A commit wait can name its branch, `--branch main`, and then holds only once that remote branch
887
+ contains the commit (#477). Without `--branch`, a repository whose `branches:` declares a `trunk:`
888
+ waits for the remote's default branch or any declared trunk. One that declares none waits for any
889
+ branch of the remote, and the echo and `keel chat waits` say `any branch of origin`.
886
890
 
887
891
  A patrol on an hourly schedule should report change, not state, or it wakes the coordinator every
888
892
  hour for a note deliberately left parked (#295). `keel patrol --since-last` keeps a snapshot per role
package/README.zh-CN.md CHANGED
@@ -735,6 +735,9 @@ keel patrol --issues /tmp/issues.json # 以协调者的角色运行
735
735
  角色。它不 fetch、不调度、不调用模型,没有新情况时什么都不写;这时它以 0 退出,当协调者有事要处理——一个风险,
736
736
  或它自己的等待已满足——时以 2 退出,只记录了东西或通知了其他角色时以 3 退出,出错时以 1 退出,所以一个廉价的
737
737
  调度器——cron、`/loop`、CI——可以只在 2 时唤醒模型(#350)。`keel chat waits` 列出仍在等待的事项。
738
+ 提交类等待可以用 `--branch main` 指定分支,这时只有那个远端分支包含该提交才算满足(#477)。不带 `--branch` 时,
739
+ `branches:` 声明了 `trunk:` 的仓库等的是远端默认分支或任一声明的主干;没有声明的仓库等的是远端的任一分支,
740
+ 登记回显和 `keel chat waits` 会写明 `any branch of origin`。
738
741
 
739
742
  按小时运行的巡查应该报告变化而不是状态,否则它每小时都会为一张故意搁置的便条唤醒协调者(#295)。
740
743
  `keel patrol --since-last` 为每个角色保存一份快照——换班状态、远端默认分支的末端、主 checkout 的未提交路径、
@@ -1,4 +1,4 @@
1
- <!-- keel:start version=5.206.0 -->
1
+ <!-- keel:start version=5.207.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.206.0",
3
+ "version": "5.207.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@christang/keel",
9
- "version": "5.206.0",
9
+ "version": "5.207.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.206.0",
5
+ "version": "5.207.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.206.0",
3
+ "version": "5.207.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.206.0",
3
+ "version": "5.207.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.206.0"
38
+ PACKAGE_VERSION = "5.207.0"
39
39
 
40
40
 
41
- PROTOCOL_VERSION = "5.206.0"
41
+ PROTOCOL_VERSION = "5.207.0"
42
42
 
43
43
 
44
44
  LEGACY_MANAGED_START = "<!-- keel:start version=2.1 -->"
@@ -469,6 +469,8 @@ SCENARIOS: tuple = (
469
469
  ("chat-ack", chat.validate_chat_ack_scenario),
470
470
  ("chat-reply-addresses-author", chat.validate_chat_reply_addresses_author_scenario),
471
471
  ("coordinator-patrol", shift.validate_coordinator_patrol_scenario),
472
+ ("chat-wait-commit-branch", shift.validate_chat_wait_commit_branch_scenario),
473
+ ("chat-wait-commit-trunks", shift.validate_chat_wait_commit_trunks_scenario),
472
474
  ("patrol-since-last", shift.validate_patrol_since_last_scenario),
473
475
  ("patrol-next", shift.validate_patrol_next_scenario),
474
476
  ("tick-runs-due-patrol", shift.validate_tick_runs_due_patrol_scenario),
@@ -1397,6 +1397,95 @@ def validate_patrol_quota_scenario() -> int:
1397
1397
  return 0
1398
1398
 
1399
1399
 
1400
+ def wait_branch_scratch(base: Path, config: str = "") -> tuple[Path, Path, dict, str]:
1401
+ """rtl and verify in group soc, a bare origin with `main`, and a commit pushed only to `origin/feature` (#477)."""
1402
+ rtl, verify, env = chat_scratch_group(base)
1403
+ if config:
1404
+ write_authorize_config(rtl, config)
1405
+ write_authorize_config(verify, config)
1406
+ subprocess.run(["git", "add", "-A"], cwd=rtl, check=True, capture_output=True)
1407
+ subprocess.run(["git", "commit", "-q", "-m", "config"], cwd=rtl, check=True, capture_output=True)
1408
+ origin = base / "origin.git"
1409
+ subprocess.run(["git", "init", "-q", "--bare", str(origin)], check=True, capture_output=True)
1410
+ for args in (["remote", "add", "origin", str(origin)], ["push", "-q", "origin", "main", "main:integ"],
1411
+ ["switch", "-q", "-c", "feature"], ["commit", "-q", "--allow-empty", "-m", "fix"],
1412
+ ["push", "-q", "origin", "feature"], ["fetch", "-q", "origin"]):
1413
+ subprocess.run(["git", *args], cwd=rtl, check=True, capture_output=True)
1414
+ sha = subprocess.run(["git", "rev-parse", "HEAD"], cwd=rtl, check=True, capture_output=True, text=True).stdout.strip()
1415
+ return rtl, verify, env, sha
1416
+
1417
+
1418
+ def push_to(rtl: Path, sha: str, branch: str) -> None:
1419
+ for args in (["push", "-q", "origin", f"{sha}:refs/heads/{branch}"], ["fetch", "-q", "origin"]):
1420
+ subprocess.run(["git", *args], cwd=rtl, check=True, capture_output=True)
1421
+
1422
+
1423
+ def validate_chat_wait_commit_branch_scenario() -> int:
1424
+ """Issue #477 D1: a commit wait with `--branch` holds only when that branch contains the commit."""
1425
+ label = "chat-wait-commit-branch:"
1426
+ with tempfile.TemporaryDirectory(prefix="keel-wait-branch-") as raw:
1427
+ rtl, verify, env, sha = wait_branch_scratch(Path(raw))
1428
+ waited = run_keel(verify, "chat", "wait", "soc", "--commit", sha, "--branch", "main", env=env)
1429
+ if waited.returncode != 0:
1430
+ report(f"{label} keel chat wait --branch main exited {waited.returncode}: {waited.stderr!r}")
1431
+ return 1
1432
+
1433
+ def told() -> int:
1434
+ return len(chat_records_with(rtl, "dm-rtl--verify", sha[:7]))
1435
+
1436
+ run_keel(rtl, "patrol", env=env)
1437
+ waits = chat_json(run_keel(rtl, "chat", "waits", "--json", env=env)).get("waits", [])
1438
+ if [w.get("condition") for w in waits] != [f"commit {sha} on origin/main"]:
1439
+ report(f"{label} with the commit only on origin/feature, waits lists {waits!r}, not the open wait on origin/main.")
1440
+ return 1
1441
+ if told():
1442
+ report(f"{label} verify was told of the commit while it was only on origin/feature.")
1443
+ return 1
1444
+ push_to(rtl, sha, "main")
1445
+ run_keel(rtl, "patrol", env=env)
1446
+ if len(chat_records_with(rtl, "dm-rtl--verify", "origin/main")) != 1:
1447
+ report(f"{label} after the push to main verify has {told()} messages naming the commit, not one naming origin/main.")
1448
+ return 1
1449
+ if chat_json(run_keel(rtl, "chat", "waits", "--json", env=env)).get("waits"):
1450
+ report(f"{label} the met wait is still listed.")
1451
+ return 1
1452
+ report("chat-wait-commit-branch scenario passed.")
1453
+ return 0
1454
+
1455
+
1456
+ def validate_chat_wait_commit_trunks_scenario() -> int:
1457
+ """Issue #477 D2, D3: declared trunks are a commit wait's default; an undeclared one says any branch."""
1458
+ label = "chat-wait-commit-trunks:"
1459
+ with tempfile.TemporaryDirectory(prefix="keel-wait-trunks-") as raw:
1460
+ base = Path(raw)
1461
+ rtl, verify, env, sha = wait_branch_scratch(base / "declared", "branches:\n trunk:\n - integ\n")
1462
+ waited = run_keel(verify, "chat", "wait", "soc", "--commit", sha, env=env)
1463
+ if "origin/main or origin/integ" not in waited.stdout:
1464
+ report(f"{label} with trunk integ declared the wait does not name origin/main or origin/integ: {waited.stdout!r} {waited.stderr!r}")
1465
+ return 1
1466
+ run_keel(rtl, "patrol", env=env)
1467
+ if not chat_json(run_keel(rtl, "chat", "waits", "--json", env=env)).get("waits"):
1468
+ report(f"{label} the trunk wait was met while the commit was only on origin/feature.")
1469
+ return 1
1470
+ push_to(rtl, sha, "integ")
1471
+ run_keel(rtl, "patrol", env=env)
1472
+ if chat_json(run_keel(rtl, "chat", "waits", "--json", env=env)).get("waits"):
1473
+ report(f"{label} the trunk wait is still open after the commit reached origin/integ.")
1474
+ return 1
1475
+
1476
+ _rtl, verify, env, sha = wait_branch_scratch(base / "undeclared")
1477
+ echo = run_keel(verify, "chat", "wait", "soc", "--commit", sha, env=env)
1478
+ if "any branch of origin" not in echo.stdout:
1479
+ report(f"{label} with no trunk declared the wait's echo does not say any branch of origin: {echo.stdout!r}")
1480
+ return 1
1481
+ listed = run_keel(verify, "chat", "waits", env=env)
1482
+ if "any branch of origin" not in listed.stdout:
1483
+ report(f"{label} keel chat waits does not say any branch of origin: {listed.stdout!r}")
1484
+ return 1
1485
+ report("chat-wait-commit-trunks scenario passed.")
1486
+ return 0
1487
+
1488
+
1400
1489
  def validate_coordinator_patrol_scenario() -> int:
1401
1490
  """Issue #260: declared waits, and a patrol that notifies once.
1402
1491
 
@@ -49,11 +49,11 @@ function globRegExp(glob) {
49
49
 
50
50
  const { readBranchesDeclaration } = require("./config");
51
51
 
52
- function remoteDefault(cwd) {
53
- const head = git(cwd, ["symbolic-ref", "--quiet", "--short", `refs/remotes/${REMOTE}/HEAD`]);
54
- if (head.ok && head.out) return head.out.slice(REMOTE.length + 1);
52
+ function remoteDefault(cwd, remote = REMOTE) {
53
+ const head = git(cwd, ["symbolic-ref", "--quiet", "--short", `refs/remotes/${remote}/HEAD`]);
54
+ if (head.ok && head.out) return head.out.slice(remote.length + 1);
55
55
  for (const name of ["main", "master"]) {
56
- if (git(cwd, ["rev-parse", "--verify", "--quiet", `refs/remotes/${REMOTE}/${name}`]).ok) return name;
56
+ if (git(cwd, ["rev-parse", "--verify", "--quiet", `refs/remotes/${remote}/${name}`]).ok) return name;
57
57
  }
58
58
  return null;
59
59
  }
@@ -255,4 +255,4 @@ function runBranches(argv) {
255
255
  }
256
256
  }
257
257
 
258
- module.exports = { BranchesError, readBranchesDeclaration, merged, describe, prune, runBranches, globRegExp, REMOTE, USAGE };
258
+ module.exports = { BranchesError, readBranchesDeclaration, remoteDefault, merged, describe, prune, runBranches, globRegExp, REMOTE, USAGE };
@@ -26,7 +26,7 @@ const USAGE = [
26
26
  "keel chat ack <id> acknowledge a record that asks (a reply also counts)",
27
27
  "keel chat acks [--mine] [--json] records still waiting on an acknowledgement",
28
28
  "keel chat summary --since <90s|15m|2h|3d|date> [--group <group>] [--json] (what changed, per group and sender; reads without marking read)",
29
- "keel chat wait <group> --commit <sha> [--remote <name>] [note...] (or --issue <n> --closed: what this role waits for; keel patrol tells it when it holds)",
29
+ "keel chat wait <group> --commit <sha> [--branch <name>] [--remote <name>] [note...] (or --issue <n> --closed: what this role waits for; keel patrol tells it when it holds)",
30
30
  "keel chat waits [--json] waits not yet met",
31
31
  "keel chat dm <role> <text...> [--no-stamp] [--not-a-loop <why>] [--json]",
32
32
  "keel chat <group> [--since <90s|15m|2h|3d|date>] [--follow] [--peek] [--json] (view; advances your read position unless --peek)",
@@ -74,6 +74,7 @@ const VALUED = {
74
74
  "--since": "since",
75
75
  "--commit": "commit",
76
76
  "--remote": "remote",
77
+ "--branch": "branch",
77
78
  "--worktree": "worktree",
78
79
  "--thread": "thread",
79
80
  "--host": "host",
@@ -442,16 +443,16 @@ function dispatch(where, options) {
442
443
  const [group, ...words] = rest;
443
444
  if (!group) throw new ChatError("keel chat wait needs a group.");
444
445
  const record = store.wait(where, {
445
- group, commit: options.commit, remote: options.remote, issue: options.issue,
446
+ group, commit: options.commit, branch: options.branch, remote: options.remote, issue: options.issue,
446
447
  closed: options.closed, text: words.join(" "),
447
448
  });
448
- out(options.json ? JSON.stringify({ id: record.id, condition: record.condition }) : `Waiting: ${record.condition} (${record.id}).`);
449
+ out(options.json ? JSON.stringify({ id: record.id, condition: record.condition }) : `Waiting: ${store.describeCondition(record.condition)} (${record.id}).`);
449
450
  return 0;
450
451
  }
451
452
  case "waits": {
452
453
  const waits = store.openWaits(where);
453
454
  if (options.json) out(JSON.stringify({ waits: waits.map((w) => ({ id: w.id, group: w.group, from: w.from, condition: w.condition, text: w.text, created: w.created })) }));
454
- else out(waits.length ? waits.map((w) => `${w.group} ${w.id} ${w.from} waits for ${w.condition}${w.text ? `: ${w.text}` : ""}`).join("\n") : "keel chat: nobody is waiting.");
455
+ else out(waits.length ? waits.map((w) => `${w.group} ${w.id} ${w.from} waits for ${store.describeCondition(w.condition)}${w.text ? `: ${w.text}` : ""}`).join("\n") : "keel chat: nobody is waiting.");
455
456
  return 0;
456
457
  }
457
458
  case "dm": {
@@ -893,7 +893,25 @@ function directPost(where, target, text, extra = {}) {
893
893
 
894
894
  // --- waits (#260) ---------------------------------------------------------------
895
895
 
896
- const WAIT_FORMS = "`--commit <sha> [--remote <name>]` or `--issue <n> --closed`";
896
+ const WAIT_FORMS = "`--commit <sha> [--branch <name>] [--remote <name>]` or `--issue <n> --closed`";
897
+
898
+ // `commit <sha> on <remote>` holds on any of the remote's branches; `on
899
+ // <remote>/<branch>`, joined by ` or `, only on those branches (#477 D1, D3).
900
+ function parseCommitCondition(condition) {
901
+ const match = String(condition).match(/^commit ([0-9a-f]+) on (.+)$/);
902
+ if (!match) return null;
903
+ const targets = match[2].split(" or ");
904
+ if (targets.length === 1 && !targets[0].includes("/")) return { sha: match[1], remote: targets[0], branches: null };
905
+ const refs = targets.map((target) => target.match(/^([^/\s]+)\/(\S+)$/));
906
+ if (refs.some((ref) => !ref)) return null;
907
+ return { sha: match[1], remote: refs[0][1], refs: refs.map((ref) => ({ remote: ref[1], branch: ref[2] })) };
908
+ }
909
+
910
+ // A condition as people read it: an any-branch commit wait says so (#477 D2).
911
+ function describeCondition(condition) {
912
+ const commit = parseCommitCondition(condition);
913
+ return commit && !commit.refs ? `commit ${commit.sha} on any branch of ${commit.remote}` : String(condition);
914
+ }
897
915
 
898
916
  // What a role is waiting for, as a record every session can read. A wait is
899
917
  // not readable (D1): it wakes nobody and is unread for nobody.
@@ -914,8 +932,24 @@ function wait(where, options) {
914
932
  const remote = options.remote || "origin";
915
933
  checkName(remote.toLowerCase(), "Remote");
916
934
  condition = `commit ${String(options.commit).toLowerCase()} on ${remote}`;
935
+ if (options.branch !== null && options.branch !== undefined) {
936
+ if (!/^[A-Za-z0-9._][A-Za-z0-9._/-]*$/.test(String(options.branch)) || String(options.branch).includes("..")) {
937
+ throw new ChatError(`--branch ${JSON.stringify(options.branch)} is not a branch name.`);
938
+ }
939
+ condition += `/${options.branch}`;
940
+ } else {
941
+ // Declared trunks are the default (#477 D3), resolved now so a later
942
+ // change to `branches:` does not move an open wait.
943
+ const branches = require("../branches");
944
+ const declared = branches.readBranchesDeclaration(where.worktree).trunk;
945
+ if (declared.length) {
946
+ const names = [...new Set([branches.remoteDefault(where.worktree, remote), ...declared].filter(Boolean))];
947
+ condition = `commit ${String(options.commit).toLowerCase()} on ${names.map((name) => `${remote}/${name}`).join(" or ")}`;
948
+ }
949
+ }
917
950
  } else {
918
951
  if (!options.closed) throw new ChatError(`keel chat wait --issue needs --closed; use ${WAIT_FORMS}.`);
952
+ if (options.branch !== null && options.branch !== undefined) throw new ChatError(`--branch goes with --commit; use ${WAIT_FORMS}.`);
919
953
  condition = `issue ${normalizeIssue(options.issue)} closed`;
920
954
  }
921
955
  const { state } = loadGroup(where, group);
@@ -1073,6 +1107,8 @@ module.exports = {
1073
1107
  wait,
1074
1108
  mentionText,
1075
1109
  openWaits,
1110
+ parseCommitCondition,
1111
+ describeCondition,
1076
1112
  markMet,
1077
1113
  canAct,
1078
1114
  ack,
@@ -48,10 +48,14 @@ function readIssues(file) {
48
48
 
49
49
  // D3: a commit condition holds when a `refs/remotes/<remote>/` ref contains it.
50
50
  function conditionHolds(where, condition, issues) {
51
- const commit = condition.match(/^commit ([0-9a-f]+) on (\S+)$/);
51
+ const commit = store.parseCommitCondition(condition);
52
52
  if (commit) {
53
- if (git(where.worktree, ["cat-file", "-e", `${commit[1]}^{commit}`]) === null) return { holds: false };
54
- const refs = git(where.worktree, ["for-each-ref", "--contains", commit[1], "--format=%(refname)", `refs/remotes/${commit[2]}/`]);
53
+ if (git(where.worktree, ["cat-file", "-e", `${commit.sha}^{commit}`]) === null) return { holds: false };
54
+ // A named branch holds only when it contains the commit (#477 D1, D3).
55
+ if (commit.refs) {
56
+ return { holds: commit.refs.some((ref) => git(where.worktree, ["merge-base", "--is-ancestor", commit.sha, `refs/remotes/${ref.remote}/${ref.branch}`]) !== null) };
57
+ }
58
+ const refs = git(where.worktree, ["for-each-ref", "--contains", commit.sha, "--format=%(refname)", `refs/remotes/${commit.remote}/`]);
55
59
  return { holds: Boolean(refs) };
56
60
  }
57
61
  const issue = condition.match(/^issue #(\d+) closed$/);
@@ -101,7 +105,7 @@ function patrol(where, role, options) {
101
105
  store.markMet(where, waitRecord, role);
102
106
  result.held.push({ id: waitRecord.id, from: waitRecord.from, condition: waitRecord.condition });
103
107
  if (waitRecord.from !== role) {
104
- const text = `Condition met: ${waitRecord.condition} (wait ${waitRecord.id}${waitRecord.text ? `: ${waitRecord.text}` : ""}).`;
108
+ const text = `Condition met: ${store.describeCondition(waitRecord.condition)} (wait ${waitRecord.id}${waitRecord.text ? `: ${waitRecord.text}` : ""}).`;
105
109
  const posted = store.directPost(where, waitRecord.from, text, { refs: [`wait:${waitRecord.id}`] });
106
110
  result.notices.push({ to: waitRecord.from, id: posted.id, text });
107
111
  }