@christang/keel 5.110.0 → 5.112.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/README.md CHANGED
@@ -688,6 +688,10 @@ or, with no owner named, when another worktree's branch has commits touching it
688
688
  branch and yours has none. Only committed history counts; uncommitted files never decide it. `keel
689
689
  context --change <name>` still selects any change by name.
690
690
 
691
+ When nothing is selected, `keel context` and the session note also point at what the branch was
692
+ last working on (#278): up to five issues its commits beyond the default branch reference, newest
693
+ first — `recently referenced: #162, #182`. It is read from Git, and it selects nothing.
694
+
691
695
  A session that never owns a change — review, verification, a coordinator — can be declared
692
696
  read-only by its chat role (#246):
693
697
 
@@ -793,6 +797,16 @@ issue_roles:
793
797
  role:verify: verify
794
798
  ```
795
799
 
800
+ A host schedule made inside a session ends with that session, so a shift change or restart drops
801
+ it. Declare which role patrols and how often, and that role's new sessions — and its `keel shift
802
+ resume` — are reminded to re-create it (#260); Keel itself still schedules nothing:
803
+
804
+ ```yaml
805
+ patrol:
806
+ role: iecc-pm
807
+ every: 30m
808
+ ```
809
+
796
810
  ## Commands
797
811
 
798
812
  ```bash
@@ -1,4 +1,4 @@
1
- <!-- keel:start version=5.110.0 -->
1
+ <!-- keel:start version=5.112.0 -->
2
2
  ## Keel Bootstrap
3
3
 
4
4
  - Start every session with `keel context`; OpenSpec artifacts and Git are the only durable authority — never native memory, goals, or transcripts.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@christang/keel",
3
- "version": "5.110.0",
3
+ "version": "5.112.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@christang/keel",
9
- "version": "5.110.0",
9
+ "version": "5.112.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.110.0",
5
+ "version": "5.112.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.110.0",
3
+ "version": "5.112.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.110.0",
3
+ "version": "5.112.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",
@@ -653,6 +653,21 @@ function main() {
653
653
  lines.push(`- ${drift}`);
654
654
  human.splice(human.length - 1, 0, drift[0].toUpperCase() + drift.slice(1));
655
655
  }
656
+ // What the branch was last working on, when idle (#278).
657
+ if (context.recent && Array.isArray(context.recent.issues) && context.recent.issues.length) {
658
+ lines.push(
659
+ `- recently referenced: ${context.recent.issues.map((n) => `#${n}`).join(", ")} `
660
+ + `(commits in ${context.recent.range}; a pointer, not a selection).`
661
+ );
662
+ }
663
+ // The patrolling role re-arms its schedule after a shift change (#260).
664
+ if (context.patrol && context.patrol.role) {
665
+ lines.push(
666
+ `- patrol: role ${context.patrol.role} runs \`keel patrol\` every ${context.patrol.every}; `
667
+ + "a session's schedule ends with the session, so re-create it with the host "
668
+ + "if this session has none, and wake the model only on exit 2."
669
+ );
670
+ }
656
671
  // The role other sessions address this one by (#245).
657
672
  if (context.role) {
658
673
  lines.push(`- chat role: ${context.role} (other sessions address this one by it).`);
@@ -47,8 +47,8 @@ REQUIRED_SCRIPTS = [
47
47
  "scripts/validate_plugin.py",
48
48
  ]
49
49
 
50
- PACKAGE_VERSION = "5.110.0"
51
- PROTOCOL_VERSION = "5.110.0"
50
+ PACKAGE_VERSION = "5.112.0"
51
+ PROTOCOL_VERSION = "5.112.0"
52
52
  LEGACY_MANAGED_START = "<!-- keel:start version=2.1 -->"
53
53
  OPENSPEC_SCHEMA_NAME = "keel-spec-driven"
54
54
  # Mirrors KEEL_PACKAGE_NAME in scripts/install_to_repo.py, one of the two
@@ -2583,6 +2583,72 @@ def chat_logs_snapshot(repo: Path) -> dict:
2583
2583
  return {str(p): p.read_bytes() for p in groups.rglob("*") if p.is_file()}
2584
2584
 
2585
2585
 
2586
+ def validate_patrol_rearm_scenario() -> int:
2587
+ """Issue #260: the patrolling role is reminded to re-arm its schedule.
2588
+
2589
+ `patrol:` names the role and interval; that role's `keel context`, session
2590
+ projection, and `keel shift resume` remind it; other roles and a broken
2591
+ declaration are quiet. Keel schedules nothing.
2592
+ """
2593
+ label = "patrol-rearm:"
2594
+ with tempfile.TemporaryDirectory(prefix="keel-patrol-rearm-") as raw:
2595
+ base = Path(raw)
2596
+ repo = mailbox_repository(base / "repo")
2597
+ write_text(repo / "openspec/specs/.keep", "")
2598
+ write_authorize_config(repo, "patrol:\n role: iecc-pm\n every: 30m\n")
2599
+ subprocess.run(["git", "add", "-A"], cwd=repo, check=True, capture_output=True)
2600
+ subprocess.run(["git", "commit", "-q", "-m", "patrol"], cwd=repo, check=True, capture_output=True)
2601
+ pm = chat_worktree(repo, base / "pm")
2602
+ rtl = chat_worktree(repo, base / "rtl")
2603
+ env = chat_environment()
2604
+ run_keel(pm, "chat", "role", "--set", "iecc-pm", env=env)
2605
+ run_keel(rtl, "chat", "role", "--set", "rtl", env=env)
2606
+
2607
+ def look(cwd: Path) -> tuple[dict, str]:
2608
+ context = json.loads(run_keel(cwd, "context", "--json", env=env).stdout)
2609
+ session = run_session_start_hook(
2610
+ cwd, {"hook_event_name": "SessionStart", "source": "startup", "cwd": str(cwd)},
2611
+ keel_cli=f'node "{ROOT / "bin" / "keel.js"}"',
2612
+ )
2613
+ return context, session_start_context(session) or ""
2614
+
2615
+ context, note = look(pm)
2616
+ if context.get("patrol") != {"role": "iecc-pm", "every": "30m"}:
2617
+ report(f"{label} the coordinator's context carries patrol {context.get('patrol')!r}.")
2618
+ return 1
2619
+ if "keel patrol" not in note or "30m" not in note:
2620
+ report(f"{label} the coordinator's projection does not remind it: {note!r}")
2621
+ return 1
2622
+ ready = run_keel(pm, "shift", "ready", "next: keep patrolling", env=env)
2623
+ if ready.returncode != 0:
2624
+ report(f"{label} keel shift ready failed: {ready.stdout} {ready.stderr}")
2625
+ return 1
2626
+ resumed = run_keel(pm, "shift", "resume", env=env)
2627
+ tail = resumed.stdout.strip().splitlines()[-1] if resumed.stdout.strip() else ""
2628
+ if "keel patrol" not in tail or "30m" not in tail:
2629
+ report(f"{label} keel shift resume does not end with the reminder: {resumed.stdout!r}")
2630
+ return 1
2631
+
2632
+ context, note = look(rtl)
2633
+ if "patrol" in context:
2634
+ report(f"{label} another role carries patrol: {context.get('patrol')!r}")
2635
+ return 1
2636
+ if "keel patrol" in note:
2637
+ report(f"{label} another role's projection reminds it: {note!r}")
2638
+ return 1
2639
+
2640
+ write_authorize_config(pm, "patrol:\n role: iecc-pm\n every: soon\n")
2641
+ broken = json.loads(run_keel(pm, "context", "--json", env=env).stdout)
2642
+ if "patrol" in broken:
2643
+ report(f"{label} a malformed declaration still reminds: {broken.get('patrol')!r}")
2644
+ return 1
2645
+ if not any("patrol" in w for w in broken.get("warnings", [])):
2646
+ report(f"{label} the malformed declaration is not reported: {broken.get('warnings')!r}")
2647
+ return 1
2648
+ report("patrol-rearm scenario passed.")
2649
+ return 0
2650
+
2651
+
2586
2652
  def validate_coordinator_patrol_scenario() -> int:
2587
2653
  """Issue #260: declared waits, and a patrol that notifies once.
2588
2654
 
@@ -8879,6 +8945,55 @@ def validate_session_role_identity_scenario() -> int:
8879
8945
  return 0
8880
8946
 
8881
8947
 
8948
+ def validate_idle_recent_issues_scenario() -> int:
8949
+ """Issue #278: an idle result points at the issues the branch referenced.
8950
+
8951
+ From Git alone, newest first and without repeats, in a separate field the
8952
+ session projection prints; nothing on the default branch.
8953
+ """
8954
+ label = "idle-recent-issues:"
8955
+ with tempfile.TemporaryDirectory(prefix="keel-idle-recent-") as raw:
8956
+ base = Path(raw)
8957
+ repo = mailbox_repository(base / "repo")
8958
+ write_text(repo / "openspec/specs/.keep", "")
8959
+ subprocess.run(["git", "add", "-A"], cwd=repo, check=True, capture_output=True)
8960
+ subprocess.run(["git", "commit", "-q", "-m", "openspec"], cwd=repo, check=True, capture_output=True)
8961
+ work = chat_worktree(repo, base / "work")
8962
+ for message in ("fix the lock lease (#162)", "context per worktree, #182", "follow-up for #162"):
8963
+ subprocess.run(["git", "commit", "-q", "--allow-empty", "-m", message], cwd=work, check=True, capture_output=True)
8964
+
8965
+ def look(cwd: Path) -> tuple[dict, str]:
8966
+ context = json.loads(run_keel(cwd, "context", "--json").stdout)
8967
+ session = run_session_start_hook(
8968
+ cwd, {"hook_event_name": "SessionStart", "source": "compact", "cwd": str(cwd)},
8969
+ keel_cli=f'node "{ROOT / "bin" / "keel.js"}"',
8970
+ )
8971
+ return context, session_start_context(session) or ""
8972
+
8973
+ on_main, main_note = look(repo)
8974
+ context, note = look(work)
8975
+ if context.get("status") != "idle":
8976
+ report(f"{label} the worktree is {context.get('status')!r}, not idle.")
8977
+ return 1
8978
+ if (context.get("recent") or {}).get("issues") != [162, 182]:
8979
+ report(f"{label} recent is {context.get('recent')!r}, not issues [162, 182].")
8980
+ return 1
8981
+ if context.get("reasons") != on_main.get("reasons"):
8982
+ report(f"{label} recent issues changed the reasons: {context.get('reasons')!r}")
8983
+ return 1
8984
+ if "recently referenced: #162, #182" not in note:
8985
+ report(f"{label} the projection does not print the recent issues: {note!r}")
8986
+ return 1
8987
+ if "recent" in on_main:
8988
+ report(f"{label} the default branch carries recent: {on_main.get('recent')!r}")
8989
+ return 1
8990
+ if "recently referenced" in main_note:
8991
+ report(f"{label} the default branch's projection prints recent issues: {main_note!r}")
8992
+ return 1
8993
+ report("idle-recent-issues scenario passed.")
8994
+ return 0
8995
+
8996
+
8882
8997
  def validate_read_only_role_scenario() -> int:
8883
8998
  """Issue #246: a role listed in `read_only_roles:` infers nothing.
8884
8999
 
@@ -38526,6 +38641,7 @@ SCENARIOS: tuple = (
38526
38641
  ("stateless-continuity", validate_stateless_continuity_scenario),
38527
38642
  ("context-per-worktree", validate_context_per_worktree_scenario),
38528
38643
  ("read-only-role", validate_read_only_role_scenario),
38644
+ ("idle-recent-issues", validate_idle_recent_issues_scenario),
38529
38645
  ("session-role-identity", validate_session_role_identity_scenario),
38530
38646
  ("core-gates", validate_core_gates_scenario),
38531
38647
  ("scope-rename-attribution", validate_scope_rename_attribution_scenario),
@@ -38912,6 +39028,7 @@ SCENARIOS: tuple = (
38912
39028
  ("chat-supersedes", validate_chat_supersedes_scenario),
38913
39029
  ("chat-ack", validate_chat_ack_scenario),
38914
39030
  ("coordinator-patrol", validate_coordinator_patrol_scenario),
39031
+ ("patrol-rearm", validate_patrol_rearm_scenario),
38915
39032
  ("patrol-issue-routing", validate_patrol_issue_routing_scenario),
38916
39033
  ("chat-listen-only", validate_chat_listen_only_scenario),
38917
39034
  ("chat-summary", validate_chat_summary_scenario),
@@ -129,6 +129,7 @@ const CONFIG_DECLARATIONS = [
129
129
  "external_agents",
130
130
  "read_only_roles",
131
131
  "issue_roles",
132
+ "patrol",
132
133
  ];
133
134
 
134
135
  const CONFIG_RELATIVE_PATH = path.join("keel", "config.yaml");
@@ -872,7 +873,32 @@ function readIssueRoles(repo) {
872
873
  return { routes, unreadable };
873
874
  }
874
875
 
876
+ // `patrol:` — which role runs `keel patrol`, and how often (#260). Keel only
877
+ // reminds that role to re-create its host schedule; it schedules nothing. A
878
+ // declaration missing a value, or with a malformed one, reminds nobody.
879
+ function readPatrolDeclaration(repo) {
880
+ const block = configMap(repo, "patrol");
881
+ if (!Object.keys(block).length) return { declared: false, role: null, every: null, message: null };
882
+ const problems = [];
883
+ if (!/^[a-z0-9][a-z0-9-]{0,31}$/.test(block.role || "")) problems.push(`role \`${block.role || ""}\` is not a chat role name`);
884
+ if (!/^\d+[smhd]$/.test(block.every || "")) problems.push(`every \`${block.every || ""}\` is not a duration such as 30m`);
885
+ if (problems.length) {
886
+ return {
887
+ declared: true, role: null, every: null,
888
+ message: `keel/config.yaml patrol: ${problems.join("; ")}, so no session is reminded to run \`keel patrol\`.`,
889
+ };
890
+ }
891
+ return { declared: true, role: block.role, every: block.every, message: null };
892
+ }
893
+
894
+ function patrolReminder(patrol) {
895
+ return `Patrol: role ${patrol.role} runs \`keel patrol\` every ${patrol.every}; a session's schedule ends with `
896
+ + "the session, so re-create it with the host if this session has none, and wake the model only on exit 2.";
897
+ }
898
+
875
899
  module.exports = {
900
+ readPatrolDeclaration,
901
+ patrolReminder,
876
902
  readIssueRoles,
877
903
  readReadOnlyRoles,
878
904
  readExternalAgents,
@@ -18,6 +18,7 @@ const {
18
18
  readExecutorTier,
19
19
  readMergeDeclaration,
20
20
  readReadOnlyRoles,
21
+ readPatrolDeclaration,
21
22
  } = require("./config");
22
23
  const { isKeelSourceRepo } = require("./capabilities");
23
24
 
@@ -812,6 +813,21 @@ function resolveContext(repo, options) {
812
813
  // by role, and Keel cannot see the host's session title. A worktree with no
813
814
  // role while others here have one is reminded; a repository that uses no
814
815
  // roles hears nothing.
816
+ // An idle session gets a pointer at what its branch was working on (#278):
817
+ // Git alone, a separate field, never a reason or a selection.
818
+ if (context.status === "idle") {
819
+ try {
820
+ const { branchIssues, defaultBranch } = require("./worktrees");
821
+ const base = defaultBranch(repo);
822
+ const branch = gitOutput(repo, ["symbolic-ref", "--short", "-q", "HEAD"]);
823
+ // `origin/main` and `main` are the same default branch here.
824
+ const onDefault = base && branch && base.replace(/^[^/]+\//, "") === branch;
825
+ const issues = base && branch && branch !== base && !onDefault ? branchIssues(repo, base, 5) : [];
826
+ if (issues.length) context.recent = { issues, range: `${base}..${branch}` };
827
+ } catch {
828
+ // A pointer that cannot be read is simply absent.
829
+ }
830
+ }
815
831
  context.role = null;
816
832
  try {
817
833
  const store = require("./chat/store");
@@ -832,6 +848,10 @@ function resolveContext(repo, options) {
832
848
  } catch {
833
849
  context.role = null;
834
850
  }
851
+ // The patrolling role is reminded to re-arm its schedule (#260).
852
+ const patrol = readPatrolDeclaration(repo);
853
+ if (patrol.message) context.warnings.push(patrol.message);
854
+ if (patrol.role && context.role === patrol.role) context.patrol = { role: patrol.role, every: patrol.every };
835
855
  context.warnings.push(...gitWarnings(repo));
836
856
  // A broken `authorize:` declaration is otherwise reported only by
837
857
  // `keel --doctor`, an explicitly-invoked diagnostic — surfaced here too so a
package/src/core/shift.js CHANGED
@@ -458,7 +458,12 @@ function runShift(argv) {
458
458
  out(result, `No shift note waits for ${result.role || "this worktree"}.`);
459
459
  return 0;
460
460
  }
461
- out(result, `${result.text.replace(/\s+$/, "")}\n\n(The note moved to ${result.note}.)`);
461
+ // A new shift of the patrolling role re-creates its schedule (#260).
462
+ const { readPatrolDeclaration, patrolReminder } = require("./config");
463
+ const patrol = readPatrolDeclaration(where.worktree);
464
+ const remind = patrol.role && result.role === patrol.role;
465
+ if (remind) result.patrol = { role: patrol.role, every: patrol.every };
466
+ out(result, `${result.text.replace(/\s+$/, "")}\n\n(The note moved to ${result.note}.)${remind ? `\n\n${patrolReminder(patrol)}` : ""}`);
462
467
  return 0;
463
468
  }
464
469
  case "status": {
@@ -53,6 +53,22 @@ function defaultBranch(repo) {
53
53
  return null;
54
54
  }
55
55
 
56
+ // The issues a branch's commits beyond `base` reference as `#<n>`, newest
57
+ // commit first and without repeats (#278 D1); `limit` caps the list.
58
+ function branchIssues(cwd, base, limit = Infinity) {
59
+ if (!base) return [];
60
+ const log = git(cwd, ["log", "--format=%s%n%b%x00", `${base}..HEAD`, "--"], true);
61
+ if (!log) return [];
62
+ const seen = [];
63
+ for (const message of log.split("\0")) {
64
+ for (const match of message.matchAll(/#(\d+)/g)) {
65
+ const number = Number(match[1]);
66
+ if (Number.isSafeInteger(number) && number > 0 && !seen.includes(number)) seen.push(number);
67
+ }
68
+ }
69
+ return seen.slice(0, limit);
70
+ }
71
+
56
72
  function readIssues(file) {
57
73
  if (file === null) return null;
58
74
  try {
@@ -94,9 +110,7 @@ function inspect(where, row, base, roles, times) {
94
110
  const dirty = git(row.path, ["status", "--porcelain"]).split("\n").filter(Boolean).length;
95
111
  const bound = roles[fs.realpathSync(row.path)];
96
112
  const role = typeof bound === "string" && new RegExp(store.NAME_PATTERN_TEXT).test(bound) ? bound : null;
97
- const subjects = head && base ? git(row.path, ["log", "--format=%s%n%b", `${base}..HEAD`, "--"]) : "";
98
- const issues = [...new Set([...subjects.matchAll(/#(\d+)/g)].map((match) => Number(match[1])))]
99
- .filter((number) => Number.isSafeInteger(number) && number > 0).sort((a, b) => a - b);
113
+ const issues = head ? branchIssues(row.path, base).sort((a, b) => a - b) : [];
100
114
  const result = {
101
115
  ...row, head, missing: false, upstream, ahead, behind, lastCommit, dirty,
102
116
  role, presence: role ? notice.presenceOf(where, role) : null, issues,
@@ -163,4 +177,4 @@ function runWorktrees(argv) {
163
177
  }
164
178
  }
165
179
 
166
- module.exports = { WorktreesError, runWorktrees };
180
+ module.exports = { WorktreesError, runWorktrees, branchIssues, defaultBranch };