@christang/keel 5.226.0 → 5.227.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/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/chatwake.py +189 -0
- package/scripts/validation/common.py +2 -2
- package/scripts/validation/registry.py +4 -0
- package/src/core/chat/notice.js +54 -7
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.227.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/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@christang/keel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.227.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.227.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.227.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.227.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",
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"""Keel validation: chatwake (#516). A record wakes a session once, and the wake lists what is new."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
import subprocess
|
|
6
|
+
import tempfile
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
from validation.common import (
|
|
10
|
+
PLUGIN_ROOT,
|
|
11
|
+
ROOT,
|
|
12
|
+
chat_json,
|
|
13
|
+
chat_scratch_group,
|
|
14
|
+
report,
|
|
15
|
+
run_keel,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
SCRIPT = ROOT / PLUGIN_ROOT / "scripts/mail-hook.js"
|
|
19
|
+
HOST_EVENTS = {
|
|
20
|
+
"session-start": "SessionStart",
|
|
21
|
+
"user-prompt-submit": "UserPromptSubmit",
|
|
22
|
+
"file-changed": "FileChanged",
|
|
23
|
+
"session-end": "SessionEnd",
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def hook_payload(cwd: Path, event: str, session: str | None) -> str:
|
|
28
|
+
payload = {"hook_event_name": HOST_EVENTS[event], "cwd": str(cwd)}
|
|
29
|
+
if session is not None:
|
|
30
|
+
payload["session_id"] = session
|
|
31
|
+
return json.dumps(payload)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def run_hook(cwd: Path, env: dict, event: str, session: str | None) -> subprocess.CompletedProcess[str]:
|
|
35
|
+
return subprocess.run(
|
|
36
|
+
["node", str(SCRIPT), event], cwd=cwd, env=env, text=True, capture_output=True, check=False,
|
|
37
|
+
input=hook_payload(cwd, event, session),
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def start_hooks(cwd: Path, env: dict, event: str, session: str, count: int) -> list[subprocess.Popen]:
|
|
42
|
+
return [
|
|
43
|
+
subprocess.Popen(
|
|
44
|
+
["node", str(SCRIPT), event], cwd=cwd, env=env, text=True, stdin=subprocess.PIPE,
|
|
45
|
+
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
|
46
|
+
)
|
|
47
|
+
for _ in range(count)
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def world(prefix: str):
|
|
52
|
+
raw = tempfile.TemporaryDirectory(prefix=prefix)
|
|
53
|
+
base = Path(raw.name).resolve()
|
|
54
|
+
rtl, verify, env = chat_scratch_group(base)
|
|
55
|
+
env["KEEL_CLI"] = f'node "{ROOT / "bin" / "keel.js"}"'
|
|
56
|
+
return raw, rtl, verify, env
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def mention(rtl: Path, env: dict, text: str) -> str:
|
|
60
|
+
return chat_json(run_keel(rtl, "chat", "post", "soc", f"@verify {text}", "--json", env=env)).get("id", "")
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def validate_chat_wake_once_scenario() -> int:
|
|
64
|
+
label = "chat-wake-once:"
|
|
65
|
+
raw, rtl, verify, env = world("keel-wake-once-")
|
|
66
|
+
with raw:
|
|
67
|
+
first = mention(rtl, env, "first")
|
|
68
|
+
woke = run_hook(verify, env, "file-changed", "s1")
|
|
69
|
+
if woke.returncode != 2:
|
|
70
|
+
report(f"{label} the first FileChanged exited {woke.returncode}, not 2: {woke.stderr.strip()}")
|
|
71
|
+
return 1
|
|
72
|
+
if first not in woke.stderr:
|
|
73
|
+
report(f"{label} the first wake does not name the record {first}: {woke.stderr.strip()}")
|
|
74
|
+
return 1
|
|
75
|
+
again = run_hook(verify, env, "file-changed", "s1")
|
|
76
|
+
if again.returncode != 0:
|
|
77
|
+
report(f"{label} the second FileChanged for the same record exited {again.returncode}, not 0: {again.stderr.strip()}")
|
|
78
|
+
return 1
|
|
79
|
+
if again.stderr.strip():
|
|
80
|
+
report(f"{label} the second FileChanged wrote {again.stderr.strip()!r} for a record already announced")
|
|
81
|
+
return 1
|
|
82
|
+
|
|
83
|
+
second = mention(rtl, env, "second")
|
|
84
|
+
later = run_hook(verify, env, "file-changed", "s1")
|
|
85
|
+
if later.returncode != 2:
|
|
86
|
+
report(f"{label} a later mention exited {later.returncode}, not 2: {later.stderr.strip()}")
|
|
87
|
+
return 1
|
|
88
|
+
if second not in later.stderr:
|
|
89
|
+
report(f"{label} the later wake does not name {second}: {later.stderr.strip()}")
|
|
90
|
+
return 1
|
|
91
|
+
if first in later.stderr:
|
|
92
|
+
report(f"{label} the later wake repeats the record already announced ({first}): {later.stderr.strip()}")
|
|
93
|
+
return 1
|
|
94
|
+
if "2 unread" not in later.stderr:
|
|
95
|
+
report(f"{label} the later wake does not state the total unread (2): {later.stderr.strip()}")
|
|
96
|
+
return 1
|
|
97
|
+
|
|
98
|
+
other = run_hook(verify, env, "file-changed", "s2")
|
|
99
|
+
if other.returncode != 2:
|
|
100
|
+
report(f"{label} another session's first FileChanged exited {other.returncode}, not 2")
|
|
101
|
+
return 1
|
|
102
|
+
for record in (first, second):
|
|
103
|
+
if record not in other.stderr:
|
|
104
|
+
report(f"{label} another session was not told {record}: {other.stderr.strip()}")
|
|
105
|
+
return 1
|
|
106
|
+
|
|
107
|
+
for _ in range(2):
|
|
108
|
+
anonymous = run_hook(verify, env, "file-changed", None)
|
|
109
|
+
if anonymous.returncode != 2:
|
|
110
|
+
report(f"{label} a payload without a session id exited {anonymous.returncode}, not 2")
|
|
111
|
+
return 1
|
|
112
|
+
report("chat-wake-once scenario passed.")
|
|
113
|
+
return 0
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def validate_chat_wake_race_scenario() -> int:
|
|
117
|
+
label = "chat-wake-race:"
|
|
118
|
+
raw, rtl, verify, env = world("keel-wake-race-")
|
|
119
|
+
with raw:
|
|
120
|
+
mention(rtl, env, "once")
|
|
121
|
+
procs = start_hooks(verify, env, "file-changed", "s1", 8)
|
|
122
|
+
payload = hook_payload(verify, "file-changed", "s1")
|
|
123
|
+
codes = []
|
|
124
|
+
for proc in procs:
|
|
125
|
+
proc.communicate(payload)
|
|
126
|
+
codes.append(proc.returncode)
|
|
127
|
+
winners = [c for c in codes if c == 2]
|
|
128
|
+
if len(winners) != 1:
|
|
129
|
+
report(f"{label} {len(winners)} of 8 simultaneous hooks announced the record, not 1: {codes}")
|
|
130
|
+
return 1
|
|
131
|
+
quiet = [c for c in codes if c == 0]
|
|
132
|
+
if len(quiet) != 7:
|
|
133
|
+
report(f"{label} the other hooks did not all exit 0: {codes}")
|
|
134
|
+
return 1
|
|
135
|
+
report("chat-wake-race scenario passed.")
|
|
136
|
+
return 0
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def validate_chat_wake_after_notice_scenario() -> int:
|
|
140
|
+
label = "chat-wake-after-notice:"
|
|
141
|
+
raw, rtl, verify, env = world("keel-wake-notice-")
|
|
142
|
+
with raw:
|
|
143
|
+
first = mention(rtl, env, "first")
|
|
144
|
+
start = run_hook(verify, env, "session-start", "s1")
|
|
145
|
+
if first not in chat_json(start).get("hookSpecificOutput", {}).get("additionalContext", ""):
|
|
146
|
+
report(f"{label} SessionStart did not list the mention it is meant to have shown: {start.stdout.strip()}")
|
|
147
|
+
return 1
|
|
148
|
+
after_start = run_hook(verify, env, "file-changed", "s1")
|
|
149
|
+
if after_start.returncode != 0:
|
|
150
|
+
report(f"{label} FileChanged exited {after_start.returncode} for a record SessionStart already listed: {after_start.stderr.strip()}")
|
|
151
|
+
return 1
|
|
152
|
+
|
|
153
|
+
second = mention(rtl, env, "second")
|
|
154
|
+
prompt = run_hook(verify, env, "user-prompt-submit", "s1")
|
|
155
|
+
if second not in chat_json(prompt).get("hookSpecificOutput", {}).get("additionalContext", ""):
|
|
156
|
+
report(f"{label} UserPromptSubmit did not list the later mention: {prompt.stdout.strip()}")
|
|
157
|
+
return 1
|
|
158
|
+
after_prompt = run_hook(verify, env, "file-changed", "s1")
|
|
159
|
+
if after_prompt.returncode != 0:
|
|
160
|
+
report(f"{label} FileChanged exited {after_prompt.returncode} for a record a prompt notice already listed: {after_prompt.stderr.strip()}")
|
|
161
|
+
return 1
|
|
162
|
+
|
|
163
|
+
run_keel(verify, "chat", "notice", env=env)
|
|
164
|
+
run_keel(verify, "chat", "check", env=env)
|
|
165
|
+
third = mention(rtl, env, "third")
|
|
166
|
+
run_keel(verify, "chat", "notice", env=env)
|
|
167
|
+
run_keel(verify, "chat", "check", env=env)
|
|
168
|
+
unannounced = run_hook(verify, env, "file-changed", "s1")
|
|
169
|
+
if unannounced.returncode != 2:
|
|
170
|
+
report(f"{label} `keel chat notice` and `check` marked a record announced; FileChanged exited {unannounced.returncode}, not 2")
|
|
171
|
+
return 1
|
|
172
|
+
if third not in unannounced.stderr:
|
|
173
|
+
report(f"{label} the wake after notice and check does not name {third}: {unannounced.stderr.strip()}")
|
|
174
|
+
return 1
|
|
175
|
+
|
|
176
|
+
run_hook(verify, env, "session-start", "s1")
|
|
177
|
+
resumed = run_hook(verify, env, "file-changed", "s1")
|
|
178
|
+
if resumed.returncode != 0:
|
|
179
|
+
report(f"{label} FileChanged exited {resumed.returncode} after a second SessionStart listed everything unread")
|
|
180
|
+
return 1
|
|
181
|
+
|
|
182
|
+
mention(rtl, env, "fourth")
|
|
183
|
+
run_hook(verify, env, "session-end", "s1")
|
|
184
|
+
restarted = run_hook(verify, env, "file-changed", "s1")
|
|
185
|
+
if restarted.returncode != 2:
|
|
186
|
+
report(f"{label} FileChanged exited {restarted.returncode} for a session id that ended, not 2")
|
|
187
|
+
return 1
|
|
188
|
+
report("chat-wake-after-notice scenario passed.")
|
|
189
|
+
return 0
|
|
@@ -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.227.0"
|
|
39
39
|
|
|
40
40
|
|
|
41
|
-
PROTOCOL_VERSION = "5.
|
|
41
|
+
PROTOCOL_VERSION = "5.227.0"
|
|
42
42
|
|
|
43
43
|
|
|
44
44
|
LEGACY_MANAGED_START = "<!-- keel:start version=2.1 -->"
|
|
@@ -8,6 +8,7 @@ from validation import shift
|
|
|
8
8
|
from validation import docs
|
|
9
9
|
from validation import selfcheck
|
|
10
10
|
from validation import export
|
|
11
|
+
from validation import chatwake
|
|
11
12
|
from validation import dsh
|
|
12
13
|
from validation import skipspecs
|
|
13
14
|
from validation import feedback
|
|
@@ -554,6 +555,9 @@ SCENARIOS: tuple = (
|
|
|
554
555
|
("dsh-uninstall-shared", dsh.validate_dsh_uninstall_shared_scenario),
|
|
555
556
|
("dsh-docs", dsh.validate_dsh_docs_scenario),
|
|
556
557
|
("change-close-skip-specs", skipspecs.validate_change_close_skip_specs_scenario),
|
|
558
|
+
("chat-wake-once", chatwake.validate_chat_wake_once_scenario),
|
|
559
|
+
("chat-wake-race", chatwake.validate_chat_wake_race_scenario),
|
|
560
|
+
("chat-wake-after-notice", chatwake.validate_chat_wake_after_notice_scenario),
|
|
557
561
|
("push-protected-guard", guard.validate_push_protected_guard_scenario),
|
|
558
562
|
("authorize-role-scoped", guard.validate_authorize_role_scoped_scenario),
|
|
559
563
|
("touch-guard-record-layer", guard.validate_touch_guard_record_layer_scenario),
|
package/src/core/chat/notice.js
CHANGED
|
@@ -26,18 +26,22 @@ function firstLine(text) {
|
|
|
26
26
|
return line.length > 120 ? `${line.slice(0, 117)}...` : line;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
// `only`, when given, is the waking records a FileChanged wake announces for
|
|
30
|
+
// the first time (#516 D2): they are the ones listed, and the header says so;
|
|
31
|
+
// the other unread are still counted.
|
|
32
|
+
function noticeText(where, role, now = Date.now(), only = null) {
|
|
30
33
|
// Newest first (#252 D3).
|
|
31
34
|
const records = store.unread(where, role).reverse();
|
|
32
35
|
if (!records.length) return "";
|
|
33
|
-
const
|
|
36
|
+
const allWaking = records.filter((record) => store.wakes(record, role));
|
|
37
|
+
const waking = only ? allWaking.filter((record) => only.some((item) => item.id === record.id)) : allWaking;
|
|
34
38
|
const others = new Map();
|
|
35
39
|
for (const record of records) {
|
|
36
|
-
if (
|
|
40
|
+
if (allWaking.includes(record)) continue;
|
|
37
41
|
others.set(record.group, (others.get(record.group) || 0) + 1);
|
|
38
42
|
}
|
|
39
43
|
const lines = [
|
|
40
|
-
`keel chat: ${records.length} unread for role \`${role}\`, ${waking.length} addressed to you.`,
|
|
44
|
+
`keel chat: ${records.length} unread for role \`${role}\`, ${waking.length} ${only ? "new " : ""}addressed to you.`,
|
|
41
45
|
];
|
|
42
46
|
for (const record of waking.slice(0, NOTICE_LIMIT)) {
|
|
43
47
|
const asks = record.ack === "requested" ? " (ack requested)" : "";
|
|
@@ -341,6 +345,40 @@ function signalPath(where, role) {
|
|
|
341
345
|
return path.join(where.root, "signal", role);
|
|
342
346
|
}
|
|
343
347
|
|
|
348
|
+
// What a session has been told (#516 D1): one empty file per waking record id,
|
|
349
|
+
// named under the session's own directory. A record is announced to a session
|
|
350
|
+
// only by the process that creates its file, so two hooks started together
|
|
351
|
+
// cannot both announce it. Without a valid session id nothing is remembered.
|
|
352
|
+
function wokenDir(where, payload) {
|
|
353
|
+
const id = typeof payload.session_id === "string" ? payload.session_id : "";
|
|
354
|
+
return /^[A-Za-z0-9._-]{1,128}$/.test(id) ? path.join(where.root, "woken", id) : null;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
function claimWoken(where, payload, records) {
|
|
358
|
+
const dir = wokenDir(where, payload);
|
|
359
|
+
if (!dir) return records;
|
|
360
|
+
try {
|
|
361
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
362
|
+
} catch {
|
|
363
|
+
return records;
|
|
364
|
+
}
|
|
365
|
+
const won = [];
|
|
366
|
+
for (const record of records) {
|
|
367
|
+
try {
|
|
368
|
+
fs.writeFileSync(path.join(dir, record.id), "", { flag: "wx" });
|
|
369
|
+
won.push(record);
|
|
370
|
+
} catch (error) {
|
|
371
|
+
if (!error || error.code !== "EEXIST") won.push(record);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
return won;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
function forgetWoken(where, payload) {
|
|
378
|
+
const dir = wokenDir(where, payload);
|
|
379
|
+
if (dir) fs.rmSync(dir, { recursive: true, force: true });
|
|
380
|
+
}
|
|
381
|
+
|
|
344
382
|
function ensureSignal(where, role) {
|
|
345
383
|
const signal = signalPath(where, role);
|
|
346
384
|
fs.mkdirSync(path.dirname(signal), { recursive: true });
|
|
@@ -746,13 +784,20 @@ function hook(event, input, { mail = false } = {}) {
|
|
|
746
784
|
}
|
|
747
785
|
if (event === "session-end") {
|
|
748
786
|
touchPresence(where, role, "offline");
|
|
787
|
+
forgetWoken(where, payload);
|
|
749
788
|
return { code: 0 };
|
|
750
789
|
}
|
|
751
790
|
if (event === "session-start") rememberSession(where, role, file);
|
|
752
791
|
const started = event === "session-start" ? { source: typeof payload.source === "string" ? payload.source : null } : null;
|
|
753
792
|
touchPresence(where, role, "online", mail ? null : "claude-code", started);
|
|
754
793
|
if (event === "session-start" || event === "user-prompt-submit") recordSegment(where, role, existingTranscript(payload));
|
|
794
|
+
// What SessionStart and a prompt show counts as announced (#516 D3); a
|
|
795
|
+
// SessionStart first forgets what an earlier run of the same session id was told.
|
|
796
|
+
if (event === "session-start") forgetWoken(where, payload);
|
|
755
797
|
const chatText = noticeText(where, role);
|
|
798
|
+
if (event === "session-start" || event === "user-prompt-submit") {
|
|
799
|
+
claimWoken(where, payload, store.unread(where, role).filter((record) => store.wakes(record, role)));
|
|
800
|
+
}
|
|
756
801
|
const text = chatText && mail ? `${chatText}\n${MAIL_POINTER}` : chatText;
|
|
757
802
|
if (event === "session-start") {
|
|
758
803
|
const output = {
|
|
@@ -766,9 +811,11 @@ function hook(event, input, { mail = false } = {}) {
|
|
|
766
811
|
const context = [replacedLine, languageLine, text].filter(Boolean).join("\n");
|
|
767
812
|
return context ? promptOutput(context) : { code: 0 };
|
|
768
813
|
}
|
|
769
|
-
// file-changed
|
|
770
|
-
const
|
|
771
|
-
|
|
814
|
+
// file-changed: one wake per record and session, listing what is new (#516)
|
|
815
|
+
const fresh = claimWoken(where, payload, store.unread(where, role).filter((record) => store.wakes(record, role)));
|
|
816
|
+
if (!fresh.length) return { code: 0 };
|
|
817
|
+
const news = noticeText(where, role, Date.now(), fresh);
|
|
818
|
+
return { code: 2, stderr: `${mail ? `${news}\n${MAIL_POINTER}` : news}\n` };
|
|
772
819
|
}
|
|
773
820
|
|
|
774
821
|
// The model-free question a scheduler asks before starting a turn (#194):
|