@christang/keel 5.218.0 → 5.220.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/bin/keel.js +15 -0
- 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/session-start.js +5 -0
- package/scripts/validation/common.py +2 -2
- package/scripts/validation/registry.py +6 -0
- package/scripts/validation/shift.py +274 -0
- package/src/core/context.js +9 -0
- package/src/core/tick.js +43 -11
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.220.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/bin/keel.js
CHANGED
|
@@ -2500,6 +2500,7 @@ function runDoctor(options) {
|
|
|
2500
2500
|
printSourceRepoCliResolution(repo);
|
|
2501
2501
|
printChatRoleDrift(repo);
|
|
2502
2502
|
printTickIssueChecks(repo);
|
|
2503
|
+
printTickHeartbeat(repo);
|
|
2503
2504
|
printMergedBranches(repo);
|
|
2504
2505
|
printLaunchdJobs();
|
|
2505
2506
|
|
|
@@ -2566,6 +2567,20 @@ function printTickIssueChecks(repo) {
|
|
|
2566
2567
|
else printDoctorLine("issue checks", "ok", "nothing needs them: no issue_roles route and no issue wait");
|
|
2567
2568
|
}
|
|
2568
2569
|
|
|
2570
|
+
// Whether `keel tick` has run lately, from the trace it leaves in its own state
|
|
2571
|
+
// (#510); the host is not asked. Nothing for a repository that uses no tick.
|
|
2572
|
+
function printTickHeartbeat(repo) {
|
|
2573
|
+
let where = null;
|
|
2574
|
+
try {
|
|
2575
|
+
where = require("../src/core/chat/store").locate(repo);
|
|
2576
|
+
} catch {
|
|
2577
|
+
where = null;
|
|
2578
|
+
}
|
|
2579
|
+
if (!where) return;
|
|
2580
|
+
const beat = require("../src/core/tick").heartbeat(where, new Date());
|
|
2581
|
+
if (beat.state) printDoctorLine("tick", beat.state === "ok" ? "ok" : "problem", beat.text);
|
|
2582
|
+
}
|
|
2583
|
+
|
|
2569
2584
|
function printMergedBranches(repo) {
|
|
2570
2585
|
let where = null;
|
|
2571
2586
|
try {
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@christang/keel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.220.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.220.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.220.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.220.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",
|
|
@@ -684,6 +684,11 @@ function main() {
|
|
|
684
684
|
`- patrol: role ${context.patrol.role}'s \`keel patrol\` is run by \`keel tick\` from the host scheduler (render it with \`keel tick task\`), `
|
|
685
685
|
+ "which outlives this session; no session schedule is needed."
|
|
686
686
|
);
|
|
687
|
+
// A tick that stopped is the one thing the session cannot see for itself (#510 D5).
|
|
688
|
+
const tick = context.patrol.tick;
|
|
689
|
+
if (tick && (tick.state === "stale" || tick.state === "never")) {
|
|
690
|
+
lines.push(`- patrol: the tick ${tick.text}.`);
|
|
691
|
+
}
|
|
687
692
|
} else if (context.patrol && context.patrol.role && context.patrol.hostTask) {
|
|
688
693
|
// A host scheduled task outlives the session (#295 D3).
|
|
689
694
|
lines.push(
|
|
@@ -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.220.0"
|
|
39
39
|
|
|
40
40
|
|
|
41
|
-
PROTOCOL_VERSION = "5.
|
|
41
|
+
PROTOCOL_VERSION = "5.220.0"
|
|
42
42
|
|
|
43
43
|
|
|
44
44
|
LEGACY_MANAGED_START = "<!-- keel:start version=2.1 -->"
|
|
@@ -489,8 +489,14 @@ SCENARIOS: tuple = (
|
|
|
489
489
|
("tick-reads-quota-file", shift.validate_tick_reads_quota_file_scenario),
|
|
490
490
|
("tick-checks-issues", shift.validate_tick_checks_issues_scenario),
|
|
491
491
|
("tick-reports-issue-checks", shift.validate_tick_reports_issue_checks_scenario),
|
|
492
|
+
("tick-writes-heartbeat", shift.validate_tick_writes_heartbeat_scenario),
|
|
493
|
+
("doctor-reports-silent-tick", shift.validate_doctor_reports_silent_tick_scenario),
|
|
494
|
+
("doctor-ignores-repo-without-tick", shift.validate_doctor_ignores_repo_without_tick_scenario),
|
|
495
|
+
("session-start-says-silent-tick", shift.validate_session_start_says_silent_tick_scenario),
|
|
492
496
|
("launchd-stable-node", shift.validate_launchd_stable_node_scenario),
|
|
493
497
|
("tick-task-names-main-checkout", shift.validate_tick_task_names_main_checkout_scenario),
|
|
498
|
+
("tick-task-without-patrol", shift.validate_tick_task_without_patrol_scenario),
|
|
499
|
+
("tick-task-refuses-unreadable-patrol", shift.validate_tick_task_refuses_unreadable_patrol_scenario),
|
|
494
500
|
("tick-skips-missing-bound-worktree", shift.validate_tick_skips_missing_bound_worktree_scenario),
|
|
495
501
|
("launchd-doctor-names-job-directories", shift.validate_launchd_doctor_names_job_directories_scenario),
|
|
496
502
|
("shift-slash-command", shift.validate_shift_slash_command_scenario),
|
|
@@ -880,6 +880,75 @@ def validate_tick_task_names_main_checkout_scenario() -> int:
|
|
|
880
880
|
return 0
|
|
881
881
|
|
|
882
882
|
|
|
883
|
+
def validate_tick_task_without_patrol_scenario() -> int:
|
|
884
|
+
"""Issue #509: a repository that declares no patrol still gets a tick job.
|
|
885
|
+
|
|
886
|
+
`keel tick task` failed for want of a `patrol:`, though the tick's resume
|
|
887
|
+
of ended sessions and its hand-over need none; Keel's own repository
|
|
888
|
+
declared a patrol only to get a job.
|
|
889
|
+
"""
|
|
890
|
+
label = "tick-task-without-patrol:"
|
|
891
|
+
with tempfile.TemporaryDirectory(prefix="keel-tick-509-") as raw:
|
|
892
|
+
base = Path(raw)
|
|
893
|
+
rtl, _verify, env, _ = shift_scratch(base)
|
|
894
|
+
main = os.path.realpath(rtl)
|
|
895
|
+
wa = chat_worktree(rtl, rtl / ".claude" / "worktrees" / "wa")
|
|
896
|
+
|
|
897
|
+
def named(text: str, pattern: str) -> str:
|
|
898
|
+
return (re.search(pattern, text, re.S) or [None, ""])[1]
|
|
899
|
+
|
|
900
|
+
for where, cwd in (("the main checkout", rtl), ("a linked worktree", wa)):
|
|
901
|
+
printed = run_keel(cwd, "tick", "task", env=env)
|
|
902
|
+
if printed.returncode != 0:
|
|
903
|
+
report(f"{label} keel tick task failed in {where} with no patrol declared: {printed.stderr!r}")
|
|
904
|
+
return 1
|
|
905
|
+
repo = named(printed.stdout, r"<string>--repo</string>\s*<string>(.*?)</string>")
|
|
906
|
+
directory = named(printed.stdout, r"<key>WorkingDirectory</key>\s*<string>(.*?)</string>")
|
|
907
|
+
if repo != main or directory != main:
|
|
908
|
+
report(f"{label} the job printed in {where} does not name the main checkout {main!r}: --repo {repo!r}, WorkingDirectory {directory!r}")
|
|
909
|
+
return 1
|
|
910
|
+
if os.path.realpath(wa) in printed.stdout:
|
|
911
|
+
report(f"{label} the job printed in {where} names the worktree {os.path.realpath(wa)!r}: {printed.stdout!r}")
|
|
912
|
+
return 1
|
|
913
|
+
for needle in ("declares no `patrol:`", "resumes ended sessions", "carries hand-overs out", "Keel creates nothing"):
|
|
914
|
+
if needle not in printed.stdout:
|
|
915
|
+
report(f"{label} the text printed in {where} does not say {needle!r}: {printed.stdout!r}")
|
|
916
|
+
return 1
|
|
917
|
+
ran = run_keel(rtl, "tick", "--repo", main, env=env)
|
|
918
|
+
if ran.returncode != 0:
|
|
919
|
+
report(f"{label} the printed command `keel tick --repo {main}` exits {ran.returncode}: {ran.stderr!r}")
|
|
920
|
+
return 1
|
|
921
|
+
if label.rstrip(":") not in {name for name, _ in registry.SCENARIOS}:
|
|
922
|
+
report(f"{label} the scenario registry does not include it.")
|
|
923
|
+
return 1
|
|
924
|
+
report(f"{label.rstrip(':')} scenario passed.")
|
|
925
|
+
return 0
|
|
926
|
+
|
|
927
|
+
|
|
928
|
+
def validate_tick_task_refuses_unreadable_patrol_scenario() -> int:
|
|
929
|
+
"""Issue #509 D4: a `patrol:` Keel cannot read is shown, not treated as none."""
|
|
930
|
+
label = "tick-task-refuses-unreadable-patrol:"
|
|
931
|
+
with tempfile.TemporaryDirectory(prefix="keel-tick-509b-") as raw:
|
|
932
|
+
base = Path(raw)
|
|
933
|
+
rtl, _verify, env, _ = shift_scratch(base)
|
|
934
|
+
write_authorize_config(rtl, "patrol:\n role: rtl\n")
|
|
935
|
+
refused = run_keel(rtl, "tick", "task", env=env)
|
|
936
|
+
if refused.returncode == 0:
|
|
937
|
+
report(f"{label} keel tick task printed a job for a patrol it cannot read: {refused.stdout!r}")
|
|
938
|
+
return 1
|
|
939
|
+
if "<plist" in refused.stdout:
|
|
940
|
+
report(f"{label} a plist was printed for a patrol it cannot read: {refused.stdout!r}")
|
|
941
|
+
return 1
|
|
942
|
+
if not refused.stderr.strip():
|
|
943
|
+
report(f"{label} the refusal says nothing on stderr: {refused.stdout!r}")
|
|
944
|
+
return 1
|
|
945
|
+
if label.rstrip(":") not in {name for name, _ in registry.SCENARIOS}:
|
|
946
|
+
report(f"{label} the scenario registry does not include it.")
|
|
947
|
+
return 1
|
|
948
|
+
report(f"{label.rstrip(':')} scenario passed.")
|
|
949
|
+
return 0
|
|
950
|
+
|
|
951
|
+
|
|
883
952
|
def validate_tick_skips_missing_bound_worktree_scenario() -> int:
|
|
884
953
|
"""Issue #503: a bound worktree that was removed does not stop the patrol.
|
|
885
954
|
|
|
@@ -1565,6 +1634,211 @@ def validate_tick_reports_issue_checks_scenario() -> int:
|
|
|
1565
1634
|
return 0
|
|
1566
1635
|
|
|
1567
1636
|
|
|
1637
|
+
def tick_heartbeat_scratch(base: Path) -> tuple[Path, dict, dict[str, Path], Path]:
|
|
1638
|
+
"""The two-coordinator scratch after one real `keel tick`, so the state file has the shape a tick writes (#510)."""
|
|
1639
|
+
repo, env, wt, state = tick_scopes_scratch(base / "repo")
|
|
1640
|
+
ran = run_keel(wt["dev-a"], "tick", "--repo", str(repo), env=env)
|
|
1641
|
+
if ran.returncode != 0:
|
|
1642
|
+
raise RuntimeError(f"keel tick failed: {ran.stderr!r}")
|
|
1643
|
+
return repo, env, wt, state
|
|
1644
|
+
|
|
1645
|
+
|
|
1646
|
+
def doctor_tick_lines(wt: dict[str, Path], env: dict) -> list[str]:
|
|
1647
|
+
doctor = run_keel(wt["dev-a"], "--doctor", str(wt["dev-a"]), env=env)
|
|
1648
|
+
return [line for line in doctor.stdout.splitlines() if line.startswith("tick:")]
|
|
1649
|
+
|
|
1650
|
+
|
|
1651
|
+
def set_last_tick(state: Path, value: str | None) -> None:
|
|
1652
|
+
saved = json.loads(state.read_text(encoding="utf-8"))
|
|
1653
|
+
if value is None:
|
|
1654
|
+
saved.pop("last_tick", None)
|
|
1655
|
+
else:
|
|
1656
|
+
saved["last_tick"] = value
|
|
1657
|
+
state.write_text(json.dumps(saved), encoding="utf-8")
|
|
1658
|
+
|
|
1659
|
+
|
|
1660
|
+
def ago(**delta: float) -> str:
|
|
1661
|
+
return (datetime.now().astimezone() - timedelta(**delta)).isoformat(timespec="seconds")
|
|
1662
|
+
|
|
1663
|
+
|
|
1664
|
+
def validate_tick_writes_heartbeat_scenario() -> int:
|
|
1665
|
+
"""Issue #510 D1: every `keel tick` records `last_tick`, a run whose patrol is not due included.
|
|
1666
|
+
|
|
1667
|
+
The patrol's own `last_run` moves once per patrol, so nothing else in the
|
|
1668
|
+
state file says that a tick ran five minutes ago.
|
|
1669
|
+
"""
|
|
1670
|
+
label = "tick-writes-heartbeat:"
|
|
1671
|
+
with tempfile.TemporaryDirectory(prefix="keel-tick-heartbeat-") as raw:
|
|
1672
|
+
try:
|
|
1673
|
+
repo, env, wt, state = tick_heartbeat_scratch(Path(raw))
|
|
1674
|
+
except RuntimeError as error:
|
|
1675
|
+
report(f"{label} {error}")
|
|
1676
|
+
return 1
|
|
1677
|
+
first = json.loads(state.read_text(encoding="utf-8"))
|
|
1678
|
+
if "last_tick" not in first:
|
|
1679
|
+
report(f"{label} a tick left no last_tick in {sorted(first)!r}")
|
|
1680
|
+
return 1
|
|
1681
|
+
time.sleep(1.1)
|
|
1682
|
+
second_run = run_keel(wt["dev-a"], "tick", "--repo", str(repo), env=env)
|
|
1683
|
+
second = json.loads(state.read_text(encoding="utf-8"))
|
|
1684
|
+
if "not due" not in second_run.stdout:
|
|
1685
|
+
report(f"{label} the second tick did not find its patrols not due, so the fixture proves nothing: {second_run.stdout!r}")
|
|
1686
|
+
return 1
|
|
1687
|
+
if not second.get("last_tick", "") > first["last_tick"]:
|
|
1688
|
+
report(f"{label} a tick whose patrol was not due did not move last_tick: {first['last_tick']!r} then {second.get('last_tick')!r}")
|
|
1689
|
+
return 1
|
|
1690
|
+
for key in ("patrols", "patrol"):
|
|
1691
|
+
if first.get(key) != second.get(key):
|
|
1692
|
+
report(f"{label} the heartbeat changed the patrol's own record {key!r}: {first.get(key)!r} then {second.get(key)!r}")
|
|
1693
|
+
return 1
|
|
1694
|
+
if label.rstrip(":") not in {name for name, _ in registry.SCENARIOS}:
|
|
1695
|
+
report(f"{label} the scenario registry does not include it.")
|
|
1696
|
+
return 1
|
|
1697
|
+
report(f"{label.rstrip(':')} scenario passed.")
|
|
1698
|
+
return 0
|
|
1699
|
+
|
|
1700
|
+
|
|
1701
|
+
def validate_doctor_reports_silent_tick_scenario() -> int:
|
|
1702
|
+
"""Issue #510 D2-D4, D6: `keel --doctor` reads the heartbeat and names a tick that stopped.
|
|
1703
|
+
|
|
1704
|
+
The 2026-11-08 outage left the jobs' plists in place and unloaded; doctor
|
|
1705
|
+
said ok for 23 hours because it never asked whether the tick ran.
|
|
1706
|
+
"""
|
|
1707
|
+
label = "doctor-reports-silent-tick:"
|
|
1708
|
+
with tempfile.TemporaryDirectory(prefix="keel-tick-doctor-") as raw:
|
|
1709
|
+
try:
|
|
1710
|
+
_repo, env, wt, state = tick_heartbeat_scratch(Path(raw))
|
|
1711
|
+
except RuntimeError as error:
|
|
1712
|
+
report(f"{label} {error}")
|
|
1713
|
+
return 1
|
|
1714
|
+
stale = ago(hours=2)
|
|
1715
|
+
set_last_tick(state, stale)
|
|
1716
|
+
lines = doctor_tick_lines(wt, env)
|
|
1717
|
+
if len(lines) != 1:
|
|
1718
|
+
report(f"{label} a two-hour-old last_tick gives {len(lines)} tick lines, not one: {lines!r}")
|
|
1719
|
+
return 1
|
|
1720
|
+
for needle in ("tick: problem", stale, "keel tick task"):
|
|
1721
|
+
if needle not in lines[0]:
|
|
1722
|
+
report(f"{label} the stale line does not say {needle!r}: {lines[0]!r}")
|
|
1723
|
+
return 1
|
|
1724
|
+
fresh = ago(minutes=1)
|
|
1725
|
+
set_last_tick(state, fresh)
|
|
1726
|
+
lines = doctor_tick_lines(wt, env)
|
|
1727
|
+
if len(lines) != 1:
|
|
1728
|
+
report(f"{label} a one-minute-old last_tick gives {len(lines)} tick lines, not one: {lines!r}")
|
|
1729
|
+
return 1
|
|
1730
|
+
if not lines[0].startswith("tick: ok"):
|
|
1731
|
+
report(f"{label} a fresh heartbeat is not reported ok: {lines[0]!r}")
|
|
1732
|
+
return 1
|
|
1733
|
+
if fresh not in lines[0]:
|
|
1734
|
+
report(f"{label} a fresh heartbeat is ok without saying when the tick last ran: {lines[0]!r}")
|
|
1735
|
+
return 1
|
|
1736
|
+
set_last_tick(state, None)
|
|
1737
|
+
lines = doctor_tick_lines(wt, env)
|
|
1738
|
+
if len(lines) != 1:
|
|
1739
|
+
report(f"{label} a declared tick with no last_tick gives {len(lines)} tick lines, not one: {lines!r}")
|
|
1740
|
+
return 1
|
|
1741
|
+
if not lines[0].startswith("tick: problem"):
|
|
1742
|
+
report(f"{label} a declared tick that never ran is not a problem: {lines[0]!r}")
|
|
1743
|
+
return 1
|
|
1744
|
+
if "never" not in lines[0]:
|
|
1745
|
+
report(f"{label} a declared tick that never ran does not say it never ran: {lines[0]!r}")
|
|
1746
|
+
return 1
|
|
1747
|
+
set_last_tick(state, "last tuesday")
|
|
1748
|
+
lines = doctor_tick_lines(wt, env)
|
|
1749
|
+
if len(lines) != 1:
|
|
1750
|
+
report(f"{label} an unreadable last_tick gives {len(lines)} tick lines, not one: {lines!r}")
|
|
1751
|
+
return 1
|
|
1752
|
+
if not lines[0].startswith("tick: problem"):
|
|
1753
|
+
report(f"{label} an unreadable last_tick is not a problem: {lines[0]!r}")
|
|
1754
|
+
return 1
|
|
1755
|
+
if "last tuesday" not in lines[0]:
|
|
1756
|
+
report(f"{label} an unreadable last_tick is a problem that does not name the value: {lines[0]!r}")
|
|
1757
|
+
return 1
|
|
1758
|
+
config = wt["dev-a"] / "keel" / "config.yaml"
|
|
1759
|
+
config.write_text(config.read_text(encoding="utf-8").replace(" runner: tick\n", ""), encoding="utf-8")
|
|
1760
|
+
set_last_tick(state, ago(minutes=1))
|
|
1761
|
+
lines = doctor_tick_lines(wt, env)
|
|
1762
|
+
if len(lines) != 1:
|
|
1763
|
+
report(f"{label} a recorded heartbeat with no tick declared gives {len(lines)} tick lines, not one: {lines!r}")
|
|
1764
|
+
return 1
|
|
1765
|
+
if not lines[0].startswith("tick: ok"):
|
|
1766
|
+
report(f"{label} a recorded heartbeat is not read when nothing declares a tick: {lines[0]!r}")
|
|
1767
|
+
return 1
|
|
1768
|
+
if label.rstrip(":") not in {name for name, _ in registry.SCENARIOS}:
|
|
1769
|
+
report(f"{label} the scenario registry does not include it.")
|
|
1770
|
+
return 1
|
|
1771
|
+
report(f"{label.rstrip(':')} scenario passed.")
|
|
1772
|
+
return 0
|
|
1773
|
+
|
|
1774
|
+
|
|
1775
|
+
def validate_doctor_ignores_repo_without_tick_scenario() -> int:
|
|
1776
|
+
"""Issue #510 D3: a repository that declares no tick and never ran one gets no `tick` line."""
|
|
1777
|
+
label = "doctor-ignores-repo-without-tick:"
|
|
1778
|
+
with tempfile.TemporaryDirectory(prefix="keel-tick-doctor-none-") as raw:
|
|
1779
|
+
try:
|
|
1780
|
+
_repo, env, wt, state = tick_heartbeat_scratch(Path(raw))
|
|
1781
|
+
except RuntimeError as error:
|
|
1782
|
+
report(f"{label} {error}")
|
|
1783
|
+
return 1
|
|
1784
|
+
config = wt["dev-a"] / "keel" / "config.yaml"
|
|
1785
|
+
config.write_text(config.read_text(encoding="utf-8").replace(" runner: tick\n", ""), encoding="utf-8")
|
|
1786
|
+
set_last_tick(state, None)
|
|
1787
|
+
lines = doctor_tick_lines(wt, env)
|
|
1788
|
+
if lines:
|
|
1789
|
+
report(f"{label} doctor checks a tick nobody declared: {lines!r}")
|
|
1790
|
+
return 1
|
|
1791
|
+
if label.rstrip(":") not in {name for name, _ in registry.SCENARIOS}:
|
|
1792
|
+
report(f"{label} the scenario registry does not include it.")
|
|
1793
|
+
return 1
|
|
1794
|
+
report(f"{label.rstrip(':')} scenario passed.")
|
|
1795
|
+
return 0
|
|
1796
|
+
|
|
1797
|
+
|
|
1798
|
+
def validate_session_start_says_silent_tick_scenario() -> int:
|
|
1799
|
+
"""Issue #510 D5: the patrolling role starts knowing its tick is silent, and hears nothing when it is not."""
|
|
1800
|
+
label = "session-start-says-silent-tick:"
|
|
1801
|
+
with tempfile.TemporaryDirectory(prefix="keel-tick-session-start-") as raw:
|
|
1802
|
+
try:
|
|
1803
|
+
_repo, env, wt, state = tick_heartbeat_scratch(Path(raw))
|
|
1804
|
+
except RuntimeError as error:
|
|
1805
|
+
report(f"{label} {error}")
|
|
1806
|
+
return 1
|
|
1807
|
+
event = {"cwd": str(wt["pm-a"]), "source": "startup", "hook_event_name": "SessionStart"}
|
|
1808
|
+
|
|
1809
|
+
def started() -> str:
|
|
1810
|
+
hook = run_session_start_hook(wt["pm-a"], event, keel_cli=f'node "{ROOT / "bin" / "keel.js"}"')
|
|
1811
|
+
return session_start_context(hook) or ""
|
|
1812
|
+
|
|
1813
|
+
stale = ago(hours=2)
|
|
1814
|
+
set_last_tick(state, stale)
|
|
1815
|
+
context = started()
|
|
1816
|
+
for needle in (f"has not run since {stale}", "keel tick task"):
|
|
1817
|
+
if needle not in context:
|
|
1818
|
+
report(f"{label} the session-start context does not say {needle!r}: {context!r}")
|
|
1819
|
+
return 1
|
|
1820
|
+
as_json = run_keel(wt["pm-a"], "context", "--json", env=env)
|
|
1821
|
+
try:
|
|
1822
|
+
tick = json.loads(as_json.stdout)["patrol"]["tick"]
|
|
1823
|
+
except (ValueError, KeyError, TypeError) as error:
|
|
1824
|
+
report(f"{label} keel context --json has no patrol.tick ({error!r}): {as_json.stdout[:300]!r}")
|
|
1825
|
+
return 1
|
|
1826
|
+
if tick.get("state") != "stale":
|
|
1827
|
+
report(f"{label} patrol.tick.state is {tick.get('state')!r}, not 'stale': {tick!r}")
|
|
1828
|
+
return 1
|
|
1829
|
+
set_last_tick(state, ago(minutes=1))
|
|
1830
|
+
context = started()
|
|
1831
|
+
for needle in ("has not run since", "has never run"):
|
|
1832
|
+
if needle in context:
|
|
1833
|
+
report(f"{label} a fresh heartbeat still reaches the session as {needle!r}: {context!r}")
|
|
1834
|
+
return 1
|
|
1835
|
+
if label.rstrip(":") not in {name for name, _ in registry.SCENARIOS}:
|
|
1836
|
+
report(f"{label} the scenario registry does not include it.")
|
|
1837
|
+
return 1
|
|
1838
|
+
report(f"{label.rstrip(':')} scenario passed.")
|
|
1839
|
+
return 0
|
|
1840
|
+
|
|
1841
|
+
|
|
1568
1842
|
def validate_patrol_nudge_scenario() -> int:
|
|
1569
1843
|
"""Issues #307 part 1 and #313: the patrol nudges idle roles directly.
|
|
1570
1844
|
|
package/src/core/context.js
CHANGED
|
@@ -886,6 +886,15 @@ function resolveContext(repo, options) {
|
|
|
886
886
|
context.patrol = { role: patrol.role, every: patrol.every };
|
|
887
887
|
if (patrol.hostTask) context.patrol.hostTask = patrol.hostTask;
|
|
888
888
|
if (patrol.runner) context.patrol.runner = patrol.runner;
|
|
889
|
+
// A tick that has gone silent is said at session start (#510 D5); only its own state is read.
|
|
890
|
+
if (patrol.runner === "tick") {
|
|
891
|
+
try {
|
|
892
|
+
const beat = require("./tick").heartbeat(require("./chat/store").locate(repo));
|
|
893
|
+
if (beat.state) context.patrol.tick = { state: beat.state, at: beat.at, text: beat.text };
|
|
894
|
+
} catch {
|
|
895
|
+
// no chat store here: nothing to report
|
|
896
|
+
}
|
|
897
|
+
}
|
|
889
898
|
}
|
|
890
899
|
context.warnings.push(...gitWarnings(repo));
|
|
891
900
|
// A broken `authorize:` declaration is otherwise reported only by
|
package/src/core/tick.js
CHANGED
|
@@ -14,6 +14,8 @@ const { stableNode, launchdPath } = require("./launchd");
|
|
|
14
14
|
const USAGE = "keel tick [--repo <path>] [--json] one model-free step: run the patrol when it is due\n"
|
|
15
15
|
+ " keel tick task [--json] [--repo <path>] print the launchd job that calls it";
|
|
16
16
|
const INTERVAL_SECONDS = 300;
|
|
17
|
+
// A tick silent for three of the job's intervals is reported (#510 D2).
|
|
18
|
+
const STALE_MS = 3 * INTERVAL_SECONDS * 1000;
|
|
17
19
|
const KEEL = path.resolve(__dirname, "..", "..", "bin", "keel.js");
|
|
18
20
|
|
|
19
21
|
class TickError extends Error {}
|
|
@@ -57,10 +59,11 @@ function patrolWorktrees(where) {
|
|
|
57
59
|
// bound worktree again. It stands in only when it exists and its
|
|
58
60
|
// keel/config.yaml declares a `patrol:`, since that is the file `keel tick
|
|
59
61
|
// --repo` reads; otherwise `dir` is null and `why` says which.
|
|
60
|
-
function stableRepo(where) {
|
|
62
|
+
function stableRepo(where, patrolless = false) {
|
|
61
63
|
if (path.basename(where.common) !== ".git") return { dir: null, why: "the repository has no main checkout" };
|
|
62
64
|
const dir = path.dirname(where.common);
|
|
63
|
-
|
|
65
|
+
// With no patrol anywhere nothing is read from it, so it stands in as it is (#509 D2).
|
|
66
|
+
if (!patrolless && !require("./config").readPatrolDeclarations(dir).declarations.length) return { dir: null, why: `the main checkout ${dir} declares no \`patrol:\`` };
|
|
64
67
|
return { dir, why: null };
|
|
65
68
|
}
|
|
66
69
|
|
|
@@ -184,8 +187,30 @@ function wakeEnded(where, state) {
|
|
|
184
187
|
return woken;
|
|
185
188
|
}
|
|
186
189
|
|
|
190
|
+
// What `tick/state.json` says about whether the tick runs (#510). Only that
|
|
191
|
+
// file is read: a tick that does not run cannot report it, so the report comes
|
|
192
|
+
// from the trace it left, and Keel asks the host nothing (D6). `state` is
|
|
193
|
+
// `ok`, `stale`, `never` (a declared tick with no run recorded), or null when
|
|
194
|
+
// nothing here uses a tick.
|
|
195
|
+
function heartbeat(where, now = new Date()) {
|
|
196
|
+
const at = readState(where).last_tick;
|
|
197
|
+
if (at === undefined || at === null) {
|
|
198
|
+
const declared = require("./config").readPatrolDeclarations(where.worktree).declarations.some((item) => item.runner === "tick");
|
|
199
|
+
return declared
|
|
200
|
+
? { state: "never", at: null, text: "has never run here although keel/config.yaml declares `runner: tick`; run the install commands `keel tick task` prints" }
|
|
201
|
+
: { state: null, at: null, text: "" };
|
|
202
|
+
}
|
|
203
|
+
const age = now.getTime() - Date.parse(at);
|
|
204
|
+
const repair = "run the install commands `keel tick task` prints again, or the machine was asleep";
|
|
205
|
+
if (Number.isNaN(age)) return { state: "stale", at, text: `has a last_tick that is not a date (${JSON.stringify(at)}); ${repair}` };
|
|
206
|
+
if (age > STALE_MS) return { state: "stale", at, text: `has not run since ${at} (${Math.round(age / 60000)} min ago); ${repair}` };
|
|
207
|
+
return { state: "ok", at, text: `last ran ${at}` };
|
|
208
|
+
}
|
|
209
|
+
|
|
187
210
|
function tick(where, now = new Date()) {
|
|
188
211
|
const result = { patrol: null, woken: [] };
|
|
212
|
+
// First, so a run that fails later still counts as a run (#510 D1).
|
|
213
|
+
store.writeJsonAtomic(where, stateFile(where), { ...readState(where), last_tick: store.isoLocal(now) });
|
|
189
214
|
const wakeState = readState(where);
|
|
190
215
|
result.woken = wakeEnded(where, wakeState);
|
|
191
216
|
result.handedOver = require("./shift").handOver(where);
|
|
@@ -282,14 +307,19 @@ function xml(text) {
|
|
|
282
307
|
}
|
|
283
308
|
|
|
284
309
|
function task(where) {
|
|
285
|
-
|
|
286
|
-
|
|
310
|
+
// A repository that declares no patrol still gets a job: the tick's resume of
|
|
311
|
+
// ended sessions and its hand-over need none (#509 D1). A declaration Keel
|
|
312
|
+
// cannot read carries a message and is refused as before (D4).
|
|
313
|
+
const declared = require("./config").readPatrolDeclarations(where.worktree);
|
|
314
|
+
const patrolless = !declared.declarations.length && !declared.messages.length;
|
|
315
|
+
const found = patrolless ? { worktree: null, why: null } : patrolWorktree(where);
|
|
316
|
+
if (!patrolless && !found.worktree) throw new TickError(found.why);
|
|
287
317
|
const label = `dev.keel.tick.${where.project.replace(/[^A-Za-z0-9.-]/g, "-")}`;
|
|
288
318
|
const logs = path.join(where.root, "tick");
|
|
289
319
|
// The job names the main checkout when it can stand in (#503 D1), so that
|
|
290
320
|
// binding the role elsewhere or pruning a worktree changes nothing it names.
|
|
291
|
-
const stable = stableRepo(where);
|
|
292
|
-
const repo = stable.dir || found.worktree;
|
|
321
|
+
const stable = stableRepo(where, patrolless);
|
|
322
|
+
const repo = stable.dir || found.worktree || where.worktree;
|
|
293
323
|
const args = [stableNode(), KEEL, "tick", "--repo", repo];
|
|
294
324
|
const plist = [
|
|
295
325
|
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
@@ -307,7 +337,7 @@ function task(where) {
|
|
|
307
337
|
"</plist>",
|
|
308
338
|
].join("\n");
|
|
309
339
|
const target = path.join(os.homedir(), "Library", "LaunchAgents", `${label}.plist`);
|
|
310
|
-
return { label, interval: INTERVAL_SECONDS, repo, stable: Boolean(stable.dir), why: stable.why, worktree: found.worktree, plist, target,
|
|
340
|
+
return { label, interval: INTERVAL_SECONDS, repo, stable: Boolean(stable.dir), why: stable.why, patrolless, worktree: found.worktree, plist, target,
|
|
311
341
|
install: [`mkdir -p ${path.dirname(target)} && cat > ${target} <<'PLIST'\n${plist}\nPLIST`, `launchctl bootstrap gui/${process.getuid ? process.getuid() : "<uid>"} ${target}`] };
|
|
312
342
|
}
|
|
313
343
|
|
|
@@ -315,9 +345,11 @@ function renderTask(job) {
|
|
|
315
345
|
// The main checkout is named when it can stand in, and the tick finds each
|
|
316
346
|
// role's bound worktree on every run; otherwise the worktree is named, and
|
|
317
347
|
// the job stops working if that worktree moves (#503).
|
|
318
|
-
const where = job.
|
|
319
|
-
? `in the main checkout ${job.repo}
|
|
320
|
-
:
|
|
348
|
+
const where = job.patrolless
|
|
349
|
+
? `in ${job.stable ? "the main checkout" : "the worktree"} ${job.repo}; keel/config.yaml declares no \`patrol:\`, so each run resumes ended sessions and carries hand-overs out and runs no patrol${job.stable ? "" : `, and the job stops working if that worktree is moved or pruned (${job.why})`}`
|
|
350
|
+
: job.stable
|
|
351
|
+
? `in the main checkout ${job.repo}, and the tick runs each declared patrol in the worktree its role is bound to when due, so binding a role elsewhere needs no new job`
|
|
352
|
+
: `in the worktree ${job.repo}, because ${job.why}; the job stops working if that worktree is moved or pruned, so declare the \`patrol:\` in the main checkout and print it again`;
|
|
321
353
|
return [
|
|
322
354
|
`launchd job for \`keel tick\` (label ${job.label}): it calls \`keel tick\` every ${job.interval} s ${where}. Keel creates nothing: install it with the two commands below.`,
|
|
323
355
|
"",
|
|
@@ -366,4 +398,4 @@ function runTick(argv) {
|
|
|
366
398
|
}
|
|
367
399
|
}
|
|
368
400
|
|
|
369
|
-
module.exports = { runTick, tick, TickError };
|
|
401
|
+
module.exports = { runTick, tick, heartbeat, TickError };
|