@christang/keel 5.123.0 → 5.125.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 +5 -5
- 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/plugins/keel/scripts/mail-hook.js +1 -1
- package/scripts/validate_plugin.py +112 -25
- package/src/core/chat/notice.js +54 -0
- package/src/core/patrol.js +41 -26
package/README.md
CHANGED
|
@@ -808,10 +808,10 @@ nudge wakes a large session.
|
|
|
808
808
|
|
|
809
809
|
`keel patrol --nudge` goes further and nudges each idle role itself, with one direct message from
|
|
810
810
|
`keel-patrol` that wakes its session (#307): when records addressed to it have waited longer than
|
|
811
|
-
`--idle` (at most every two hours); when
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
was never resumed. A note filed without `--wake` — a coordinator parking a role — is left alone, and
|
|
811
|
+
`--idle` (at most every two hours); when a todo assigned to it is closed, telling it to change shift
|
|
812
|
+
at that task boundary — with `keel shift ready --wake` if another todo is still open for it, or plain
|
|
813
|
+
`ready` to wait for the coordinator — since a shift follows a finished task and the host compacts
|
|
814
|
+
within one (#313); and when a note it filed with `ready --wake` was never resumed. A note filed without `--wake` — a coordinator parking a role — is left alone, and
|
|
815
815
|
Keel's own messages never count as waiting.
|
|
816
816
|
|
|
817
817
|
With `--issues`, patrol also routes issue updates (#242): `issue_roles:` in `keel/config.yaml`
|
|
@@ -847,7 +847,7 @@ session, so it neither marks the role offline nor fires a `keel shift ready --wa
|
|
|
847
847
|
|
|
848
848
|
## The owner's language
|
|
849
849
|
|
|
850
|
-
An agent reads mostly English — tool output, issues, specs, Keel's own output — and drifts into it when it answers you. Declare the language you want to be addressed in, and the rule is restated where replies are written: in `keel context`, the session-start note, and the chat hook on every prompt, in every worktree (#305). The agent may still work in any language; identifiers, commands, paths, and quoted output stay as they are.
|
|
850
|
+
An agent reads mostly English — tool output, issues, specs, Keel's own output — and drifts into it when it answers you. Declare the language you want to be addressed in, and the rule is restated where replies are written: in `keel context`, the session-start note, and the chat hook on every prompt, in every worktree (#305) — and, on Claude, after every 15 tool calls or 10 minutes of them, since a status update written mid-turn follows no prompt (#311). The agent may still work in any language; identifiers, commands, paths, and quoted output stay as they are.
|
|
851
851
|
|
|
852
852
|
```yaml
|
|
853
853
|
owner_language: zh
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@christang/keel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.125.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.125.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.125.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.125.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",
|
|
@@ -28,7 +28,7 @@ try {
|
|
|
28
28
|
// Copied on its own: no hand-off.
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
const EVENTS = new Set(["session-start", "user-prompt-submit", "file-changed", "session-end"]);
|
|
31
|
+
const EVENTS = new Set(["session-start", "user-prompt-submit", "post-tool-use", "file-changed", "session-end"]);
|
|
32
32
|
const TIMEOUT_MS = Number(process.env.KEEL_HOOK_TIMEOUT_MS || 8000) || 8000;
|
|
33
33
|
|
|
34
34
|
function readStdin() {
|
|
@@ -47,8 +47,8 @@ REQUIRED_SCRIPTS = [
|
|
|
47
47
|
"scripts/validate_plugin.py",
|
|
48
48
|
]
|
|
49
49
|
|
|
50
|
-
PACKAGE_VERSION = "5.
|
|
51
|
-
PROTOCOL_VERSION = "5.
|
|
50
|
+
PACKAGE_VERSION = "5.125.0"
|
|
51
|
+
PROTOCOL_VERSION = "5.125.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
|
|
@@ -2828,11 +2828,12 @@ def validate_patrol_since_last_scenario() -> int:
|
|
|
2828
2828
|
|
|
2829
2829
|
|
|
2830
2830
|
def validate_patrol_nudge_scenario() -> int:
|
|
2831
|
-
"""
|
|
2831
|
+
"""Issues #307 part 1 and #313: the patrol nudges idle roles directly.
|
|
2832
2832
|
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2833
|
+
Addressed unread records nudge once per window; a closed todo nudges a
|
|
2834
|
+
shift change at that task boundary, naming `--wake` only while another
|
|
2835
|
+
todo is open; a self-initiated note nudges a resume; a parked note and
|
|
2836
|
+
the patrol's own messages never do; context is no longer an input.
|
|
2836
2837
|
"""
|
|
2837
2838
|
label = "patrol-nudge:"
|
|
2838
2839
|
with tempfile.TemporaryDirectory(prefix="keel-patrol-nudge-") as raw:
|
|
@@ -2842,6 +2843,12 @@ def validate_patrol_nudge_scenario() -> int:
|
|
|
2842
2843
|
lint = chat_worktree(rtl, base / "lint")
|
|
2843
2844
|
subprocess.run(["git", "push", "-q", "-u", "origin", "HEAD"], cwd=lint, check=True, capture_output=True)
|
|
2844
2845
|
run_keel(lint, "chat", "role", "--set", "lint", env=env)
|
|
2846
|
+
run_keel(rtl, "chat", "group", "add", "soc", "lint", env=env)
|
|
2847
|
+
todo_ids = []
|
|
2848
|
+
for text in ("R009 timing fix", "R010 lint cleanup"):
|
|
2849
|
+
made = run_keel(rtl, "chat", "todo", "soc", "--assignee", "lint", text, "--json", env=env)
|
|
2850
|
+
todo_ids.append(json.loads(made.stdout)["id"])
|
|
2851
|
+
run_keel(lint, "chat", "read", env=env)
|
|
2845
2852
|
run_keel(rtl, "chat", "post", "soc", "@verify please rerun R007", env=env)
|
|
2846
2853
|
time.sleep(1.2)
|
|
2847
2854
|
|
|
@@ -2851,45 +2858,60 @@ def validate_patrol_nudge_scenario() -> int:
|
|
|
2851
2858
|
def nudged(result: subprocess.CompletedProcess[str]) -> list[str]:
|
|
2852
2859
|
return [line for line in result.stdout.splitlines() if line.startswith("nudged ")]
|
|
2853
2860
|
|
|
2861
|
+
def told_lint(needle: str) -> str:
|
|
2862
|
+
return "\n".join(chat_records_with(rtl, "dm-keel-patrol--lint", needle))
|
|
2863
|
+
|
|
2854
2864
|
seen: list[str] = []
|
|
2855
|
-
first = nudge(
|
|
2865
|
+
first = nudge()
|
|
2856
2866
|
seen += nudged(first)
|
|
2857
2867
|
if "nudged verify: unread" not in nudged(first):
|
|
2858
2868
|
report(f"{label} verify was not nudged for unread: {first.stdout!r} {first.stderr!r}")
|
|
2859
2869
|
return 1
|
|
2860
2870
|
if any(line.startswith("nudged lint") for line in nudged(first)):
|
|
2861
|
-
report(f"{label} lint was nudged
|
|
2871
|
+
report(f"{label} lint was nudged before any task closed: {nudged(first)!r}")
|
|
2862
2872
|
return 1
|
|
2863
2873
|
if first.returncode != 2:
|
|
2864
2874
|
report(f"{label} a run that nudged exited {first.returncode}.")
|
|
2865
2875
|
return 1
|
|
2866
|
-
if not chat_records_with(rtl, "dm-keel-patrol--verify", "keel chat unread"):
|
|
2867
|
-
report(f"{label} no keel-patrol record reached verify.")
|
|
2868
|
-
return 1
|
|
2869
2876
|
if run_keel(verify, "chat", "notice", "--check", env=env).returncode != 0:
|
|
2870
2877
|
report(f"{label} the nudge does not wake verify.")
|
|
2871
2878
|
return 1
|
|
2872
|
-
|
|
2879
|
+
run_keel(lint, "chat", "done", todo_ids[0], env=env)
|
|
2880
|
+
time.sleep(1.2)
|
|
2881
|
+
second = nudge()
|
|
2873
2882
|
seen += nudged(second)
|
|
2874
2883
|
if nudged(second) != ["nudged lint: shift"]:
|
|
2875
|
-
report(f"{label}
|
|
2884
|
+
report(f"{label} closing a todo should nudge only lint's shift: {second.stdout!r} {second.stderr!r}")
|
|
2876
2885
|
return 1
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
report(f"{label} the shift nudge does not name keel shift ready --wake: {shift_text!r}")
|
|
2886
|
+
if "keel shift ready --wake" not in told_lint("R009"):
|
|
2887
|
+
report(f"{label} with a todo still open, the shift nudge does not name ready --wake: {told_lint('R009')!r}")
|
|
2880
2888
|
return 1
|
|
2881
|
-
if "Remote Control" not in
|
|
2882
|
-
report(f"{label} the shift nudge does not name Remote Control
|
|
2889
|
+
if "Remote Control" not in told_lint("R009"):
|
|
2890
|
+
report(f"{label} the shift nudge does not name Remote Control.")
|
|
2883
2891
|
return 1
|
|
2884
2892
|
time.sleep(1.2)
|
|
2885
|
-
third = nudge(
|
|
2893
|
+
third = nudge()
|
|
2886
2894
|
seen += nudged(third)
|
|
2887
2895
|
if nudged(third):
|
|
2888
|
-
report(f"{label} a run
|
|
2896
|
+
report(f"{label} a run with nothing new nudged: {nudged(third)!r}")
|
|
2889
2897
|
return 1
|
|
2890
2898
|
if third.returncode != 0:
|
|
2891
2899
|
report(f"{label} a run that nudged nobody exited {third.returncode}.")
|
|
2892
2900
|
return 1
|
|
2901
|
+
run_keel(lint, "chat", "done", todo_ids[1], env=env)
|
|
2902
|
+
time.sleep(1.2)
|
|
2903
|
+
fourth = nudge()
|
|
2904
|
+
seen += nudged(fourth)
|
|
2905
|
+
if "nudged lint: shift" not in nudged(fourth):
|
|
2906
|
+
report(f"{label} closing the last todo did not nudge lint: {fourth.stdout!r}")
|
|
2907
|
+
return 1
|
|
2908
|
+
last = told_lint("R010")
|
|
2909
|
+
if "wait for the coordinator" not in last:
|
|
2910
|
+
report(f"{label} with no todo left, the shift nudge does not say to wait for the coordinator: {last!r}")
|
|
2911
|
+
return 1
|
|
2912
|
+
if "--wake" in last:
|
|
2913
|
+
report(f"{label} with no todo left, the shift nudge still names --wake: {last!r}")
|
|
2914
|
+
return 1
|
|
2893
2915
|
armed = run_keel(lint, "shift", "ready", "--wake", "lint note", env=env)
|
|
2894
2916
|
if armed.returncode != 0:
|
|
2895
2917
|
report(f"{label} lint's ready --wake failed: {armed.stderr}")
|
|
@@ -2898,17 +2920,24 @@ def validate_patrol_nudge_scenario() -> int:
|
|
|
2898
2920
|
report(f"{label} verify's ready failed.")
|
|
2899
2921
|
return 1
|
|
2900
2922
|
time.sleep(1.2)
|
|
2901
|
-
|
|
2902
|
-
seen += nudged(
|
|
2903
|
-
if "nudged lint: resume" not in nudged(
|
|
2904
|
-
report(f"{label} lint's self-initiated note was not nudged to resume: {
|
|
2923
|
+
fifth = nudge()
|
|
2924
|
+
seen += nudged(fifth)
|
|
2925
|
+
if "nudged lint: resume" not in nudged(fifth):
|
|
2926
|
+
report(f"{label} lint's self-initiated note was not nudged to resume: {fifth.stdout!r}")
|
|
2905
2927
|
return 1
|
|
2906
|
-
if "nudged verify: resume" in nudged(
|
|
2928
|
+
if "nudged verify: resume" in nudged(fifth):
|
|
2907
2929
|
report(f"{label} verify's parked note was nudged to resume.")
|
|
2908
2930
|
return 1
|
|
2909
2931
|
if "nudged lint: unread" in seen:
|
|
2910
2932
|
report(f"{label} lint was nudged over the patrol's own message.")
|
|
2911
2933
|
return 1
|
|
2934
|
+
retired = nudge("--context", "lint=62")
|
|
2935
|
+
if retired.returncode != 1:
|
|
2936
|
+
report(f"{label} --context exited {retired.returncode}.")
|
|
2937
|
+
return 1
|
|
2938
|
+
if "retired" not in retired.stderr:
|
|
2939
|
+
report(f"{label} the --context refusal does not say it was retired: {retired.stderr!r}")
|
|
2940
|
+
return 1
|
|
2912
2941
|
report("patrol-nudge scenario passed.")
|
|
2913
2942
|
return 0
|
|
2914
2943
|
|
|
@@ -6405,6 +6434,62 @@ def validate_owner_language_scenario() -> int:
|
|
|
6405
6434
|
return 0
|
|
6406
6435
|
|
|
6407
6436
|
|
|
6437
|
+
def validate_owner_language_after_tools_scenario() -> int:
|
|
6438
|
+
"""Issue #311: the owner's language is restated after runs of tool calls."""
|
|
6439
|
+
label = "owner-language-after-tools:"
|
|
6440
|
+
manifest = json.loads((ROOT / ".claude-plugin" / "plugin.json").read_text(encoding="utf-8"))
|
|
6441
|
+
post = json.dumps(manifest.get("hooks", {}).get("PostToolUse", []))
|
|
6442
|
+
if "mail-hook.js" not in post or "post-tool-use" not in post:
|
|
6443
|
+
report(f"{label} .claude-plugin/plugin.json does not register PostToolUse on mail-hook.js post-tool-use: {post}")
|
|
6444
|
+
return 1
|
|
6445
|
+
with tempfile.TemporaryDirectory(prefix="keel-language-tools-") as raw:
|
|
6446
|
+
base = Path(raw)
|
|
6447
|
+
rtl, _verify, env = chat_scratch_group(base)
|
|
6448
|
+
env = {**env, "KEEL_CLI": f'node "{ROOT / "bin" / "keel.js"}"'}
|
|
6449
|
+
write_authorize_config(rtl, "owner_language: zh\n")
|
|
6450
|
+
|
|
6451
|
+
def hook(event: str, payload: dict) -> str:
|
|
6452
|
+
result = subprocess.run(
|
|
6453
|
+
["node", str(ROOT / PLUGIN_ROOT / "scripts/mail-hook.js"), event],
|
|
6454
|
+
cwd=rtl, env=env, text=True, capture_output=True, check=False,
|
|
6455
|
+
input=json.dumps({"cwd": str(rtl), **payload}),
|
|
6456
|
+
)
|
|
6457
|
+
if not result.stdout.strip():
|
|
6458
|
+
return ""
|
|
6459
|
+
return json.loads(result.stdout).get("hookSpecificOutput", {}).get("additionalContext", "")
|
|
6460
|
+
|
|
6461
|
+
def tool(session: str) -> str:
|
|
6462
|
+
return hook("post-tool-use", {"hook_event_name": "PostToolUse", "session_id": session, "tool_name": "Bash"})
|
|
6463
|
+
|
|
6464
|
+
hook("user-prompt-submit", {"hook_event_name": "UserPromptSubmit", "session_id": "t1", "prompt": "go on"})
|
|
6465
|
+
outputs = [tool("t1") for _ in range(16)]
|
|
6466
|
+
early = [n + 1 for n, text in enumerate(outputs[:14]) if text]
|
|
6467
|
+
if early:
|
|
6468
|
+
report(f"{label} PostToolUse calls {early} restated the rule before the 15th.")
|
|
6469
|
+
return 1
|
|
6470
|
+
if "中文" not in outputs[14]:
|
|
6471
|
+
report(f"{label} the 15th PostToolUse did not restate the rule: {outputs[14]!r}")
|
|
6472
|
+
return 1
|
|
6473
|
+
if outputs[15]:
|
|
6474
|
+
report(f"{label} the 16th PostToolUse restated the rule again: {outputs[15]!r}")
|
|
6475
|
+
return 1
|
|
6476
|
+
hook("user-prompt-submit", {"hook_event_name": "UserPromptSubmit", "session_id": "t1", "prompt": "next"})
|
|
6477
|
+
if tool("t1"):
|
|
6478
|
+
report(f"{label} the first tool call after a prompt restated the rule.")
|
|
6479
|
+
return 1
|
|
6480
|
+
hook("session-start", {"hook_event_name": "SessionStart", "source": "startup", "session_id": "run1"})
|
|
6481
|
+
hook("user-prompt-submit", {"hook_event_name": "UserPromptSubmit", "session_id": "run1", "prompt": '<scheduled-task name="patrol">run'})
|
|
6482
|
+
if any(tool("run1") for _ in range(16)):
|
|
6483
|
+
report(f"{label} a host-run session was reminded.")
|
|
6484
|
+
return 1
|
|
6485
|
+
write_authorize_config(rtl, "")
|
|
6486
|
+
if any(tool("t2") for _ in range(16)):
|
|
6487
|
+
report(f"{label} a repository without owner_language was reminded.")
|
|
6488
|
+
return 1
|
|
6489
|
+
report("owner-language-after-tools scenario passed.")
|
|
6490
|
+
return 0
|
|
6491
|
+
|
|
6492
|
+
|
|
6408
6493
|
def validate_shift_coordinator_last_scenario() -> int:
|
|
6409
6494
|
"""Issue #289: the coordinator starts the others before its own shift ends.
|
|
6410
6495
|
|
|
@@ -21107,6 +21192,7 @@ def validate_native_plugin_manifests_scenario() -> int:
|
|
|
21107
21192
|
{"hooks": [mail_hook("session-start")]},
|
|
21108
21193
|
]
|
|
21109
21194
|
expected_hooks["UserPromptSubmit"] = [{"hooks": [mail_hook("user-prompt-submit")]}]
|
|
21195
|
+
expected_hooks["PostToolUse"] = [{"hooks": [mail_hook("post-tool-use")]}]
|
|
21110
21196
|
expected_hooks["FileChanged"] = [
|
|
21111
21197
|
{"hooks": [mail_hook("file-changed", asyncRewake=True)]}
|
|
21112
21198
|
]
|
|
@@ -40085,6 +40171,7 @@ SCENARIOS: tuple = (
|
|
|
40085
40171
|
("shift-self", validate_shift_self_scenario),
|
|
40086
40172
|
("shift-self-wake", validate_shift_self_wake_scenario),
|
|
40087
40173
|
("owner-language", validate_owner_language_scenario),
|
|
40174
|
+
("owner-language-after-tools", validate_owner_language_after_tools_scenario),
|
|
40088
40175
|
("shift-history", validate_shift_history_scenario),
|
|
40089
40176
|
("role-drift", validate_role_drift_scenario),
|
|
40090
40177
|
("host-run-session", validate_host_run_session_scenario),
|
package/src/core/chat/notice.js
CHANGED
|
@@ -161,6 +161,7 @@ const OWNER_RULE = "Slack notifies the owner only for messages that write `@owne
|
|
|
161
161
|
const HOST_EVENTS = {
|
|
162
162
|
"session-start": "SessionStart",
|
|
163
163
|
"user-prompt-submit": "UserPromptSubmit",
|
|
164
|
+
"post-tool-use": "PostToolUse",
|
|
164
165
|
"file-changed": "FileChanged",
|
|
165
166
|
"session-end": "SessionEnd",
|
|
166
167
|
};
|
|
@@ -237,6 +238,55 @@ function decideSession(where, file, session, prompt) {
|
|
|
237
238
|
return hostRun;
|
|
238
239
|
}
|
|
239
240
|
|
|
241
|
+
// --- the owner's language after tool calls (#311) ---------------------------------------
|
|
242
|
+
|
|
243
|
+
function languageFile(where, payload) {
|
|
244
|
+
const file = sessionFile(where, payload);
|
|
245
|
+
return file ? file.replace(/\.json$/, ".language.json") : null;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function resetLanguageCount(where, payload) {
|
|
249
|
+
const file = languageFile(where, payload);
|
|
250
|
+
if (!file) return;
|
|
251
|
+
try {
|
|
252
|
+
store.writeJsonAtomic(where, file, { count: 0, at: Date.now() });
|
|
253
|
+
} catch {
|
|
254
|
+
// A convenience: never fail the hook.
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// Once 15 tool calls or 10 minutes have passed since the rule was last stated
|
|
259
|
+
// in this session, it is stated again (D2); a host run gets nothing (D4).
|
|
260
|
+
function languageAfterTools(where, payload) {
|
|
261
|
+
const file = languageFile(where, payload);
|
|
262
|
+
if (!file) return { code: 0 };
|
|
263
|
+
try {
|
|
264
|
+
const session = sessionFile(where, payload);
|
|
265
|
+
if (fs.existsSync(session) && store.readJsonFile(session).host_run) return { code: 0 };
|
|
266
|
+
const { readOwnerLanguage, ownerLanguageRule } = require("../config");
|
|
267
|
+
const language = readOwnerLanguage(where.worktree);
|
|
268
|
+
if (!language.tag) return { code: 0 };
|
|
269
|
+
const everyTools = Number(process.env.KEEL_LANGUAGE_EVERY_TOOLS) > 0 ? Number(process.env.KEEL_LANGUAGE_EVERY_TOOLS) : 15;
|
|
270
|
+
const everyMs = Number(process.env.KEEL_LANGUAGE_EVERY_MS) > 0 ? Number(process.env.KEEL_LANGUAGE_EVERY_MS) : 10 * 60 * 1000;
|
|
271
|
+
const now = Date.now();
|
|
272
|
+
const record = fs.existsSync(file) ? store.readJsonFile(file) : null;
|
|
273
|
+
if (!record || typeof record.count !== "number") {
|
|
274
|
+
store.writeJsonAtomic(where, file, { count: 1, at: now });
|
|
275
|
+
return { code: 0 };
|
|
276
|
+
}
|
|
277
|
+
const count = record.count + 1;
|
|
278
|
+
if (count >= everyTools || now - Number(record.at || 0) >= everyMs) {
|
|
279
|
+
store.writeJsonAtomic(where, file, { count: 0, at: now });
|
|
280
|
+
const output = { hookSpecificOutput: { hookEventName: "PostToolUse", additionalContext: ownerLanguageRule(language.tag) } };
|
|
281
|
+
return { code: 0, stdout: `${JSON.stringify(output)}\n` };
|
|
282
|
+
}
|
|
283
|
+
store.writeJsonAtomic(where, file, { count, at: record.at });
|
|
284
|
+
} catch {
|
|
285
|
+
// Never fail a tool call over a reminder.
|
|
286
|
+
}
|
|
287
|
+
return { code: 0 };
|
|
288
|
+
}
|
|
289
|
+
|
|
240
290
|
function hook(event, input, { mail = false } = {}) {
|
|
241
291
|
if (!(event in HOST_EVENTS)) return { code: 0 };
|
|
242
292
|
let payload = {};
|
|
@@ -256,6 +306,8 @@ function hook(event, input, { mail = false } = {}) {
|
|
|
256
306
|
// A session's watch list is fixed at SessionStart, so a worktree with no role
|
|
257
307
|
// yet still watches its own signal, which a role bound later will touch
|
|
258
308
|
// (chat-wake-late-binding D1). Nothing else is said until there is a role.
|
|
309
|
+
// After a run of tool calls the owner's language is restated too (#311).
|
|
310
|
+
if (event === "post-tool-use") return where ? languageAfterTools(where, payload) : { code: 0 };
|
|
259
311
|
// The owner's language is restated on every prompt, role or not (#305 D4).
|
|
260
312
|
let languageLine = null;
|
|
261
313
|
if (where && event === "user-prompt-submit") {
|
|
@@ -266,6 +318,8 @@ function hook(event, input, { mail = false } = {}) {
|
|
|
266
318
|
} catch {
|
|
267
319
|
languageLine = null;
|
|
268
320
|
}
|
|
321
|
+
// A prompt that states the rule starts the tool count over (#311 D3).
|
|
322
|
+
if (languageLine) resetLanguageCount(where, payload);
|
|
269
323
|
}
|
|
270
324
|
const promptOutput = (text) => ({
|
|
271
325
|
code: 0,
|
package/src/core/patrol.js
CHANGED
|
@@ -12,7 +12,7 @@ const store = require("./chat/store");
|
|
|
12
12
|
const notice = require("./chat/notice");
|
|
13
13
|
const { parseSince } = require("./chat/view");
|
|
14
14
|
|
|
15
|
-
const USAGE = "keel patrol [--issues <file>] [--idle <90s|15m|2h|3d>] [--since-last [--notify]] [--nudge
|
|
15
|
+
const USAGE = "keel patrol [--issues <file>] [--idle <90s|15m|2h|3d>] [--since-last [--notify]] [--nudge] [--json] [--repo <path>]\n keel patrol task [--json] [--repo <path>] print the host scheduled task for `patrol:`";
|
|
16
16
|
const NOTIFY_SENDER = "keel-patrol";
|
|
17
17
|
const EXIT_QUIET = 0;
|
|
18
18
|
const EXIT_ERROR = 1;
|
|
@@ -204,19 +204,8 @@ function sinceLast(where, role, result, options) {
|
|
|
204
204
|
|
|
205
205
|
const KEEL_SENDERS = new Set([NOTIFY_SENDER, "keel-shift", "keel"]);
|
|
206
206
|
const UNREAD_EVERY_MS = Number(process.env.KEEL_PATROL_UNREAD_EVERY_MS) > 0 ? Number(process.env.KEEL_PATROL_UNREAD_EVERY_MS) : 2 * 60 * 60 * 1000;
|
|
207
|
-
const SHIFT_EVERY_MS = 6 * 60 * 60 * 1000;
|
|
208
207
|
const SELF_INITIATED = "Self-initiated: this shift armed `keel shift ready --wake`.";
|
|
209
208
|
|
|
210
|
-
function parseContexts(values) {
|
|
211
|
-
const contexts = new Map();
|
|
212
|
-
for (const value of values) {
|
|
213
|
-
const match = String(value).match(/^([a-z0-9][a-z0-9-]{0,31})=(\d{1,3}(?:\.\d+)?)%?$/);
|
|
214
|
-
if (!match) throw new PatrolError(`--context ${value} is not <role>=<percent>.`);
|
|
215
|
-
contexts.set(match[1], Number(match[2]));
|
|
216
|
-
}
|
|
217
|
-
return contexts;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
209
|
function sendNudge(where, role, kind, text) {
|
|
221
210
|
const group = store.directName(NOTIFY_SENDER, role);
|
|
222
211
|
if (!store.groupState(store.readLog(where, group)).exists) {
|
|
@@ -226,6 +215,24 @@ function sendNudge(where, role, kind, text) {
|
|
|
226
215
|
return { role, kind, text };
|
|
227
216
|
}
|
|
228
217
|
|
|
218
|
+
// Closed todos per assignee: each `done` record and the todo it closes.
|
|
219
|
+
function closedTodos(where) {
|
|
220
|
+
const byRole = new Map();
|
|
221
|
+
for (const name of store.listGroupNames(where)) {
|
|
222
|
+
const records = store.readLog(where, name);
|
|
223
|
+
const todos = new Map(records.filter((r) => r.kind === "todo").map((r) => [r.id, r]));
|
|
224
|
+
for (const record of records) {
|
|
225
|
+
if (record.kind !== "done" || !todos.has(record.target)) continue;
|
|
226
|
+
const todo = todos.get(record.target);
|
|
227
|
+
if (!todo.assignee) continue;
|
|
228
|
+
if (!byRole.has(todo.assignee)) byRole.set(todo.assignee, []);
|
|
229
|
+
byRole.get(todo.assignee).push({ done: record.id, todo: todo.id, title: String(todo.text || "").split("\n")[0].slice(0, 80) });
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
for (const list of byRole.values()) list.sort((a, b) => (a.done < b.done ? -1 : 1));
|
|
233
|
+
return byRole;
|
|
234
|
+
}
|
|
235
|
+
|
|
229
236
|
function nudgeRoles(where, patroller, options) {
|
|
230
237
|
const stateFile = path.join(where.root, "patrol", "nudges.json");
|
|
231
238
|
const state = store.readJsonFile(stateFile);
|
|
@@ -235,7 +242,12 @@ function nudgeRoles(where, patroller, options) {
|
|
|
235
242
|
const escalations = [];
|
|
236
243
|
const roles = [...new Set(Object.values(store.readJsonFile(path.join(where.root, "roles.json"))).filter(Boolean))]
|
|
237
244
|
.filter((role) => role !== patroller).sort();
|
|
245
|
+
const closures = closedTodos(where);
|
|
238
246
|
for (const role of roles) {
|
|
247
|
+
// The first look only records the tasks already closed (#313 D1).
|
|
248
|
+
if (!state[role] || !Array.isArray(state[role].closedSeen)) {
|
|
249
|
+
state[role] = { ...(state[role] || {}), closedSeen: (closures.get(role) || []).map((entry) => entry.done) };
|
|
250
|
+
}
|
|
239
251
|
const last = Date.parse(notice.presenceOf(where, role).last_active || "");
|
|
240
252
|
if (!Number.isNaN(last) && last >= idleBefore) continue;
|
|
241
253
|
const mine = state[role] || {};
|
|
@@ -260,15 +272,19 @@ function nudgeRoles(where, patroller, options) {
|
|
|
260
272
|
} else {
|
|
261
273
|
mine.unanswered = 0;
|
|
262
274
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
275
|
+
// A finished task is the shift boundary (#313 D2); within a task the host compacts.
|
|
276
|
+
const fresh = (closures.get(role) || []).filter((entry) => !mine.closedSeen.includes(entry.done));
|
|
277
|
+
if (fresh.length && !noteText) {
|
|
278
|
+
const task = fresh[fresh.length - 1];
|
|
279
|
+
const open = store.openTodos(where, { assignee: role }).length;
|
|
280
|
+
const next = open
|
|
281
|
+
? `\`keel shift ready --wake "<note>"\` — you still hold ${open} open todo(s)`
|
|
282
|
+
: "`keel shift ready \"<note>\"`, and wait for the coordinator to start you with new work";
|
|
283
|
+
sent.push(sendNudge(where, role, "shift",
|
|
284
|
+
`${role}: your task ${task.todo} ("${task.title}") was closed. Change shift at this task boundary: `
|
|
285
|
+
+ `\`keel shift check\`, then ${next}, then clear this session (a session serving Remote Control cannot be `
|
|
286
|
+
+ "cleared: turn it off, clear, then turn it back on)."));
|
|
287
|
+
mine.closedSeen = [...mine.closedSeen, ...fresh.map((entry) => entry.done)];
|
|
272
288
|
}
|
|
273
289
|
if (noteText && noteText.includes(SELF_INITIATED)) {
|
|
274
290
|
const written = fs.statSync(note).mtime;
|
|
@@ -422,7 +438,7 @@ function runPatrol(argv) {
|
|
|
422
438
|
throw error;
|
|
423
439
|
}
|
|
424
440
|
}
|
|
425
|
-
const options = { repo: process.cwd(), issues: null, idle: "30m", json: false, sinceLast: false, notify: false, nudge: false,
|
|
441
|
+
const options = { repo: process.cwd(), issues: null, idle: "30m", json: false, sinceLast: false, notify: false, nudge: false, diskFreeGb: null, diskMinGb: 20, quota: null, quotaAlerts: [90, 95, 99], quotaQuietAt: 90 };
|
|
426
442
|
try {
|
|
427
443
|
for (let index = 0; index < argv.length; index += 1) {
|
|
428
444
|
const arg = argv[index];
|
|
@@ -430,8 +446,9 @@ function runPatrol(argv) {
|
|
|
430
446
|
else if (arg === "--since-last") options.sinceLast = true;
|
|
431
447
|
else if (arg === "--notify") options.notify = true;
|
|
432
448
|
else if (arg === "--nudge") options.nudge = true;
|
|
433
|
-
else if (arg === "--context"
|
|
434
|
-
|
|
449
|
+
else if (arg === "--context" || arg === "--shift-at") {
|
|
450
|
+
throw new PatrolError(`${arg}: --context and --shift-at were retired in 5.125.0 (#313): a shift follows a task's close, and compaction within a task stays the host's.`);
|
|
451
|
+
}
|
|
435
452
|
else if (arg === "--disk-free-gb") options.diskFreeGb = Number(argv[++index]);
|
|
436
453
|
else if (arg === "--disk-min-gb") options.diskMinGb = Number(argv[++index]);
|
|
437
454
|
else if (arg === "--quota") options.quota = Number(argv[++index]);
|
|
@@ -447,8 +464,6 @@ function runPatrol(argv) {
|
|
|
447
464
|
} else throw new PatrolError(`Unknown argument ${arg}. ${USAGE}`);
|
|
448
465
|
}
|
|
449
466
|
if (options.notify && !options.sinceLast) throw new PatrolError("--notify sends the risks found since the last run, so it needs --since-last.");
|
|
450
|
-
if (!(options.shiftAt > 0 && options.shiftAt <= 100)) throw new PatrolError("--shift-at needs a percentage from 1 to 100.");
|
|
451
|
-
options.contexts = parseContexts(options.context);
|
|
452
467
|
if (options.diskFreeGb !== null && !(options.diskFreeGb >= 0)) throw new PatrolError("--disk-free-gb needs a number of gigabytes.");
|
|
453
468
|
if (!(options.diskMinGb > 0)) throw new PatrolError("--disk-min-gb needs a positive number of gigabytes.");
|
|
454
469
|
const percent = (value) => Number.isFinite(value) && value >= 0 && value <= 100;
|