@christang/keel 5.231.4 → 5.231.6

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.231.4",
3
+ "version": "5.231.6",
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.231.4 -->
1
+ <!-- keel:start version=5.231.6 -->
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.231.4",
3
+ "version": "5.231.6",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@christang/keel",
9
- "version": "5.231.4",
9
+ "version": "5.231.6",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@fission-ai/openspec": "1.14.0"
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.231.4",
5
+ "version": "5.231.6",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keel",
3
- "version": "5.231.4",
3
+ "version": "5.231.6",
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.231.4",
3
+ "version": "5.231.6",
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",
@@ -7,12 +7,14 @@
7
7
  {
8
8
  "type": "command",
9
9
  "command": "node \"${PLUGIN_ROOT}/scripts/session-start.js\"",
10
- "timeout": 15
10
+ "timeout": 15,
11
+ "statusMessage": "Keel: Session context"
11
12
  },
12
13
  {
13
14
  "type": "command",
14
15
  "command": "node \"${PLUGIN_ROOT}/scripts/codex-mail-hook.js\" session-start",
15
- "timeout": 10
16
+ "timeout": 10,
17
+ "statusMessage": "Keel: Mail at session start"
16
18
  }
17
19
  ]
18
20
  }
@@ -24,7 +26,8 @@
24
26
  {
25
27
  "type": "command",
26
28
  "command": "node \"${PLUGIN_ROOT}/scripts/pretooluse-guard.js\"",
27
- "timeout": 10
29
+ "timeout": 10,
30
+ "statusMessage": "Keel: Write guard"
28
31
  }
29
32
  ]
30
33
  }
@@ -35,7 +38,8 @@
35
38
  {
36
39
  "type": "command",
37
40
  "command": "node \"${PLUGIN_ROOT}/scripts/codex-mail-hook.js\" user-prompt-submit",
38
- "timeout": 10
41
+ "timeout": 10,
42
+ "statusMessage": "Keel: Mail before prompt"
39
43
  }
40
44
  ]
41
45
  }
@@ -927,4 +927,4 @@ function main(suppliedEvent = null) {
927
927
  return 0;
928
928
  }
929
929
 
930
- process.exit(main());
930
+ process.exitCode = main();
@@ -771,4 +771,4 @@ function recordedContract(repo, selection) {
771
771
  return null;
772
772
  }
773
773
 
774
- process.exit(main());
774
+ process.exitCode = main();
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env python3
2
2
  """Public-interface checks for Codex hooks; native tests are opt-in."""
3
3
  import argparse
4
+ import hashlib
4
5
  import json
5
6
  import os
6
7
  from pathlib import Path
@@ -17,6 +18,25 @@ ROOT = Path(__file__).resolve().parents[1]
17
18
  PLUGIN = ROOT / "plugins/keel"
18
19
  CLI = ROOT / "bin/keel.js"
19
20
  RECEIVER = PLUGIN / "scripts/codex-mail-hook.js"
21
+ HOOK_LABELS = {
22
+ ("SessionStart", "session-start.js"): "Keel: Session context",
23
+ ("SessionStart", "codex-mail-hook.js"): "Keel: Mail at session start",
24
+ ("UserPromptSubmit", "codex-mail-hook.js"): "Keel: Mail before prompt",
25
+ ("PreToolUse", "pretooluse-guard.js"): "Keel: Write guard",
26
+ }
27
+
28
+
29
+ def check_hook_labels(hooks):
30
+ event_names = {name[0].lower(): name[0] for name in HOOK_LABELS}
31
+ found = {
32
+ key: hook.get("statusMessage")
33
+ for hook in hooks
34
+ for key in HOOK_LABELS
35
+ if event_names.get(hook.get("eventName", "").lower()) == key[0]
36
+ and key[1] in hook["command"]
37
+ }
38
+ assert found == HOOK_LABELS, f"Keel hook labels missing or ambiguous: {found}"
39
+
20
40
 
21
41
 
22
42
  def run(args, cwd=ROOT, env=None, input=None, check=True, timeout=30):
@@ -48,13 +68,79 @@ def invoke(repo, event, provider=None, timeout_ms=None):
48
68
  return json.loads(result.stdout) if result.stdout.strip() else None
49
69
 
50
70
 
71
+ def read_hook_response(script, repo, event, env=None):
72
+ proc = subprocess.Popen(
73
+ ["node", str(PLUGIN / "scripts" / script)],
74
+ cwd=repo, env=env, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
75
+ stderr=subprocess.PIPE, text=True,
76
+ )
77
+ try:
78
+ proc.stdin.write(json.dumps({"cwd": str(repo), **event}))
79
+ proc.stdin.close()
80
+ proc.stdin = None
81
+ # Exercise the real pipe. A reader that has not been scheduled must
82
+ # still receive the whole JSON response when it starts draining.
83
+ time.sleep(0.3)
84
+ out, err = proc.communicate(timeout=12)
85
+ assert proc.returncode == 0 and not err, (proc.returncode, err)
86
+ try:
87
+ return json.loads(out)["hookSpecificOutput"]
88
+ except (ValueError, KeyError) as error:
89
+ raise AssertionError(f"{script}: hook response truncated ({len(out)} characters)") from error
90
+ finally:
91
+ if proc.poll() is None:
92
+ proc.kill()
93
+ proc.wait(timeout=5)
94
+
95
+
96
+ def buffered_output():
97
+ with tempfile.TemporaryDirectory(prefix="keel-codex-hook-output-") as raw:
98
+ repo = Path(raw)
99
+ change = repo / "openspec/changes/probe"
100
+ change.mkdir(parents=True)
101
+ context = {
102
+ "status": "ready",
103
+ "selection": {"change": "probe", "task": "1.1", "source": "fixture"},
104
+ "read": ["fixture/" + "a" * 180000 + "/projection-tail"],
105
+ }
106
+ provider = repo / "cli.js"
107
+ provider.write_text(
108
+ "process.stdout.write(process.argv[2] === '--version' ? '5.231.5' : "
109
+ + json.dumps(json.dumps(context)) + ")",
110
+ encoding="utf-8",
111
+ )
112
+ env = dict(os.environ, KEEL_CLI=shlex.join(["node", str(provider)]))
113
+ projection = read_hook_response("session-start.js", repo, {"hook_event_name": "SessionStart"}, env)
114
+ assert "/projection-tail" in projection["additionalContext"]
115
+ tasks = change / "tasks.md"
116
+ tasks.write_text("- [ ] 1.1 Write in Touch only\n", encoding="utf-8")
117
+ touch = [f"src/fixture-{index:05d}.js" for index in range(12000)]
118
+ manifest = {
119
+ "schema": "keel-write-guard/v1", "change": "probe", "task": "1.1",
120
+ "authority": [{"path": str(tasks.relative_to(repo)), "sha256": hashlib.sha256(tasks.read_bytes()).hexdigest()}],
121
+ "touch": touch,
122
+ }
123
+ (repo / "keel").mkdir()
124
+ (repo / "keel/guard.json").write_text(json.dumps(manifest), encoding="utf-8")
125
+ decision = read_hook_response("pretooluse-guard.js", repo, {
126
+ "hook_event_name": "PreToolUse", "tool_name": "Edit",
127
+ "tool_input": {"file_path": str(repo / "src/outside.js")},
128
+ })
129
+ assert decision["permissionDecision"] == "deny"
130
+ assert touch[-1] in decision["permissionDecisionReason"]
131
+ print("codex hook output: complete SessionStart projection and PreToolUse verdict")
132
+
133
+
51
134
  def behavior():
52
135
  manifest = json.loads((PLUGIN / ".codex-plugin/plugin.json").read_text())
53
136
  assert manifest.get("hooks") == "./hooks/codex.json", "Codex still uses the args-only shared hooks"
54
137
  hooks = json.loads((PLUGIN / "hooks/codex.json").read_text())["hooks"]
55
138
  assert set(hooks) == {"SessionStart", "PreToolUse", "UserPromptSubmit"}
56
139
  assert not any(field in json.dumps(hooks) for field in ["asyncRewake", "watchPaths", "FileChanged"])
57
- commands = [h["command"] for groups in hooks.values() for g in groups for h in g["hooks"]]
140
+ declared = [dict(h, eventName=event) for event, groups in hooks.items() for g in groups for h in g["hooks"]]
141
+ check_hook_labels(declared)
142
+ buffered_output()
143
+ commands = [h["command"] for h in declared]
58
144
  for script in ["session-start.js", "pretooluse-guard.js", "codex-mail-hook.js"]:
59
145
  assert any(script in command for command in commands), script
60
146
  with tempfile.TemporaryDirectory(prefix="keel-codex-mail-") as raw:
@@ -177,6 +263,7 @@ trust_level = "trusted"
177
263
  assert not found["errors"], found
178
264
  hooks = found["hooks"]
179
265
  assert len(hooks) == 4, hooks
266
+ check_hook_labels(hooks)
180
267
  assert all(h["trustStatus"] == "untrusted" for h in hooks), hooks
181
268
  assert all(".js" in h["command"] for h in hooks), hooks
182
269
  assert {h["eventName"] for h in hooks} == {"preToolUse", "sessionStart", "userPromptSubmit"}
@@ -1605,6 +1605,30 @@ def validate_chat_records_scenario() -> int:
1605
1605
  if not todo_id:
1606
1606
  report(f"{label} keel chat todo did not report an id: {todo.stdout.strip()} {todo.stderr.strip()}")
1607
1607
  return 1
1608
+ chat(verify, "read", "soc")
1609
+ store = mailbox_common_dir(rtl) / "keel-chat"
1610
+
1611
+ def snapshot():
1612
+ return {
1613
+ file.relative_to(store): file.read_bytes()
1614
+ for directory in (store / "groups", store / "cursors")
1615
+ for file in directory.rglob("*") if file.is_file()
1616
+ }
1617
+
1618
+ def show(record_id):
1619
+ result = chat(verify, "show", record_id, "--json")
1620
+ assert result.returncode == 0, result.stderr
1621
+ return chat_json(result)
1622
+
1623
+ before = snapshot()
1624
+ active = show(todo_id)
1625
+ assert active.get("task") == {
1626
+ "id": todo_id,
1627
+ "state": "open",
1628
+ "closureRecordId": None,
1629
+ }, "task view missing for open todo"
1630
+ assert active["record"]["id"] == todo_id and "readers" in active
1631
+ assert snapshot() == before, "open task query wrote to chat"
1608
1632
  mine = chat_json(chat(verify, "todos", "--mine", "--json")).get("todos", [])
1609
1633
  listed = [t for t in mine if t.get("id") == todo_id]
1610
1634
  if not listed:
@@ -1621,8 +1645,20 @@ def validate_chat_records_scenario() -> int:
1621
1645
  if todo_id in open_ids:
1622
1646
  report(f"{label} a todo answered with ✅ is still listed: {open_ids!r}")
1623
1647
  return 1
1648
+ before = snapshot()
1649
+ completed = show(todo_id)["task"]
1650
+ assert completed == {
1651
+ "id": todo_id,
1652
+ "state": "closed",
1653
+ "closureRecordId": completed["closureRecordId"],
1654
+ }
1655
+ receipt = show(completed["closureRecordId"])
1656
+ assert receipt["record"]["kind"] == "done" and receipt["record"]["target"] == todo_id
1657
+ assert "task" not in receipt
1658
+ assert show(todo_id)["task"] == completed
1659
+ assert snapshot() == before, "closed task query wrote to chat"
1624
1660
  second_id = chat_json(chat(rtl, "todo", "soc", "--assignee", "verify", "Update the spec", "--json")).get("id", "")
1625
- done = chat(verify, "done", second_id)
1661
+ done = chat(verify, "done", second_id, "--json")
1626
1662
  if done.returncode != 0:
1627
1663
  report(f"{label} keel chat done failed: {done.stderr.strip()}")
1628
1664
  return 1
@@ -1630,9 +1666,12 @@ def validate_chat_records_scenario() -> int:
1630
1666
  if second_id in open_ids:
1631
1667
  report(f"{label} a todo closed with keel chat done is still listed: {open_ids!r}")
1632
1668
  return 1
1669
+ explicit = {"id": second_id, "state": "closed", "closureRecordId": chat_json(done)["id"]}
1670
+ assert show(second_id)["task"] == explicit
1633
1671
 
1634
1672
  message_id = chat_json(chat(rtl, "post", "soc", "Clock is 100MHz", "--json")).get("id", "")
1635
1673
  message_file = chat_log(rtl, "soc") / f"{message_id}.md"
1674
+ assert "task" not in show(message_id)
1636
1675
  original = message_file.read_bytes()
1637
1676
  foreign = chat(verify, "edit", message_id, "Clock is 50MHz")
1638
1677
  if foreign.returncode == 0:
@@ -1683,6 +1722,12 @@ def validate_chat_records_scenario() -> int:
1683
1722
  if "06:00:00+00:00" in local.stdout:
1684
1723
  report(f"{label} the view prints the raw stored stamp.")
1685
1724
  return 1
1725
+ archived = chat(rtl, "group", "archive", "soc")
1726
+ assert archived.returncode == 0, archived.stderr
1727
+ before = snapshot()
1728
+ assert show(second_id)["task"] == explicit
1729
+ assert show(todo_id)["task"] == completed
1730
+ assert snapshot() == before, "archived task query wrote to chat"
1686
1731
 
1687
1732
  if "chat-records" not in {name for name, _ in registry.SCENARIOS}:
1688
1733
  report(f"{label} scenario is not registered.")
@@ -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.231.4"
38
+ PACKAGE_VERSION = "5.231.6"
39
39
 
40
40
 
41
- PROTOCOL_VERSION = "5.231.4"
41
+ PROTOCOL_VERSION = "5.231.6"
42
42
 
43
43
 
44
44
  LEGACY_MANAGED_START = "<!-- keel:start version=2.1 -->"
@@ -493,8 +493,14 @@ function dispatch(where, options) {
493
493
  if (!record) throw new ChatError(`No record ${id}.`);
494
494
  const readers = store.readersOf(where, record);
495
495
  const acks = record.ack === "requested" ? store.ackStatus(where, record) : null;
496
- if (options.json) out(JSON.stringify({ record: publicRecord(record), readers, ...(acks ? { acks } : {}) }));
497
- else out([`${record.group} ${formatLine(record)}`, `read by: ${readers.join(", ") || "nobody yet"}`, ...(acks ? ackLines(acks) : [])].join("\n"));
496
+ if (options.json) {
497
+ const result = { record: publicRecord(record), readers, ...(acks ? { acks } : {}) };
498
+ if (record.kind === "todo") {
499
+ const closure = store.todoClosure(where, record);
500
+ result.task = { id: record.id, state: closure ? "closed" : "open", closureRecordId: closure ? closure.id : null };
501
+ }
502
+ out(JSON.stringify(result));
503
+ } else out([`${record.group} ${formatLine(record)}`, `read by: ${readers.join(", ") || "nobody yet"}`, ...(acks ? ackLines(acks) : [])].join("\n"));
498
504
  return 0;
499
505
  }
500
506
  case "todo": {
@@ -689,7 +689,7 @@ function post(where, options) {
689
689
  text: text.replace(/\s+$/, ""),
690
690
  });
691
691
  // A reply that opens with `done` or ✅ closes the todo it answers (D6).
692
- if (parent && parent.kind === "todo" && DONE_REPLY.test(text) && !isDone(where, parent)) {
692
+ if (parent && parent.kind === "todo" && DONE_REPLY.test(text) && !todoClosure(where, parent)) {
693
693
  writeRecord(where, { group, kind: "done", from, target: parent.id });
694
694
  }
695
695
  // Answering a record marks it read for the one who answered (#201): a woken
@@ -795,8 +795,9 @@ function supersededIds(records) {
795
795
  return ids;
796
796
  }
797
797
 
798
- function isDone(where, todo) {
799
- return readLog(where, todo.group).some((record) => record.kind === "done" && record.target === todo.id);
798
+ function todoClosure(where, todo) {
799
+ checkGroup(todo.group);
800
+ return readLog(where, todo.group).find((record) => record.kind === "done" && record.target === todo.id);
800
801
  }
801
802
 
802
803
  function normalizeIssue(issue) {
@@ -831,7 +832,7 @@ function targetFor(where, id, actor, kinds) {
831
832
  function done(where, id) {
832
833
  const from = requireRole(where);
833
834
  const target = targetFor(where, id, from, ["todo"]);
834
- if (isDone(where, target)) throw new ChatError(`Todo ${id} is already done.`);
835
+ if (todoClosure(where, target)) throw new ChatError(`Todo ${id} is already done.`);
835
836
  const record = writeRecord(where, { group: target.group, kind: "done", from, target: id });
836
837
  advanceCursor(where, from, target.group, id);
837
838
  return record;
@@ -1137,6 +1138,7 @@ module.exports = {
1137
1138
  amend,
1138
1139
  done,
1139
1140
  openTodos,
1141
+ todoClosure,
1140
1142
  search,
1141
1143
  todo,
1142
1144
  archiveGroup,