@christang/keel 5.218.0 → 5.219.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 +4 -0
- package/scripts/validation/shift.py +205 -0
- package/src/core/context.js +9 -0
- package/src/core/tick.js +25 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.219.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.219.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.219.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.219.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.219.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.219.0"
|
|
39
39
|
|
|
40
40
|
|
|
41
|
-
PROTOCOL_VERSION = "5.
|
|
41
|
+
PROTOCOL_VERSION = "5.219.0"
|
|
42
42
|
|
|
43
43
|
|
|
44
44
|
LEGACY_MANAGED_START = "<!-- keel:start version=2.1 -->"
|
|
@@ -489,6 +489,10 @@ 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),
|
|
494
498
|
("tick-skips-missing-bound-worktree", shift.validate_tick_skips_missing_bound_worktree_scenario),
|
|
@@ -1565,6 +1565,211 @@ def validate_tick_reports_issue_checks_scenario() -> int:
|
|
|
1565
1565
|
return 0
|
|
1566
1566
|
|
|
1567
1567
|
|
|
1568
|
+
def tick_heartbeat_scratch(base: Path) -> tuple[Path, dict, dict[str, Path], Path]:
|
|
1569
|
+
"""The two-coordinator scratch after one real `keel tick`, so the state file has the shape a tick writes (#510)."""
|
|
1570
|
+
repo, env, wt, state = tick_scopes_scratch(base / "repo")
|
|
1571
|
+
ran = run_keel(wt["dev-a"], "tick", "--repo", str(repo), env=env)
|
|
1572
|
+
if ran.returncode != 0:
|
|
1573
|
+
raise RuntimeError(f"keel tick failed: {ran.stderr!r}")
|
|
1574
|
+
return repo, env, wt, state
|
|
1575
|
+
|
|
1576
|
+
|
|
1577
|
+
def doctor_tick_lines(wt: dict[str, Path], env: dict) -> list[str]:
|
|
1578
|
+
doctor = run_keel(wt["dev-a"], "--doctor", str(wt["dev-a"]), env=env)
|
|
1579
|
+
return [line for line in doctor.stdout.splitlines() if line.startswith("tick:")]
|
|
1580
|
+
|
|
1581
|
+
|
|
1582
|
+
def set_last_tick(state: Path, value: str | None) -> None:
|
|
1583
|
+
saved = json.loads(state.read_text(encoding="utf-8"))
|
|
1584
|
+
if value is None:
|
|
1585
|
+
saved.pop("last_tick", None)
|
|
1586
|
+
else:
|
|
1587
|
+
saved["last_tick"] = value
|
|
1588
|
+
state.write_text(json.dumps(saved), encoding="utf-8")
|
|
1589
|
+
|
|
1590
|
+
|
|
1591
|
+
def ago(**delta: float) -> str:
|
|
1592
|
+
return (datetime.now().astimezone() - timedelta(**delta)).isoformat(timespec="seconds")
|
|
1593
|
+
|
|
1594
|
+
|
|
1595
|
+
def validate_tick_writes_heartbeat_scenario() -> int:
|
|
1596
|
+
"""Issue #510 D1: every `keel tick` records `last_tick`, a run whose patrol is not due included.
|
|
1597
|
+
|
|
1598
|
+
The patrol's own `last_run` moves once per patrol, so nothing else in the
|
|
1599
|
+
state file says that a tick ran five minutes ago.
|
|
1600
|
+
"""
|
|
1601
|
+
label = "tick-writes-heartbeat:"
|
|
1602
|
+
with tempfile.TemporaryDirectory(prefix="keel-tick-heartbeat-") as raw:
|
|
1603
|
+
try:
|
|
1604
|
+
repo, env, wt, state = tick_heartbeat_scratch(Path(raw))
|
|
1605
|
+
except RuntimeError as error:
|
|
1606
|
+
report(f"{label} {error}")
|
|
1607
|
+
return 1
|
|
1608
|
+
first = json.loads(state.read_text(encoding="utf-8"))
|
|
1609
|
+
if "last_tick" not in first:
|
|
1610
|
+
report(f"{label} a tick left no last_tick in {sorted(first)!r}")
|
|
1611
|
+
return 1
|
|
1612
|
+
time.sleep(1.1)
|
|
1613
|
+
second_run = run_keel(wt["dev-a"], "tick", "--repo", str(repo), env=env)
|
|
1614
|
+
second = json.loads(state.read_text(encoding="utf-8"))
|
|
1615
|
+
if "not due" not in second_run.stdout:
|
|
1616
|
+
report(f"{label} the second tick did not find its patrols not due, so the fixture proves nothing: {second_run.stdout!r}")
|
|
1617
|
+
return 1
|
|
1618
|
+
if not second.get("last_tick", "") > first["last_tick"]:
|
|
1619
|
+
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}")
|
|
1620
|
+
return 1
|
|
1621
|
+
for key in ("patrols", "patrol"):
|
|
1622
|
+
if first.get(key) != second.get(key):
|
|
1623
|
+
report(f"{label} the heartbeat changed the patrol's own record {key!r}: {first.get(key)!r} then {second.get(key)!r}")
|
|
1624
|
+
return 1
|
|
1625
|
+
if label.rstrip(":") not in {name for name, _ in registry.SCENARIOS}:
|
|
1626
|
+
report(f"{label} the scenario registry does not include it.")
|
|
1627
|
+
return 1
|
|
1628
|
+
report(f"{label.rstrip(':')} scenario passed.")
|
|
1629
|
+
return 0
|
|
1630
|
+
|
|
1631
|
+
|
|
1632
|
+
def validate_doctor_reports_silent_tick_scenario() -> int:
|
|
1633
|
+
"""Issue #510 D2-D4, D6: `keel --doctor` reads the heartbeat and names a tick that stopped.
|
|
1634
|
+
|
|
1635
|
+
The 2026-11-08 outage left the jobs' plists in place and unloaded; doctor
|
|
1636
|
+
said ok for 23 hours because it never asked whether the tick ran.
|
|
1637
|
+
"""
|
|
1638
|
+
label = "doctor-reports-silent-tick:"
|
|
1639
|
+
with tempfile.TemporaryDirectory(prefix="keel-tick-doctor-") as raw:
|
|
1640
|
+
try:
|
|
1641
|
+
_repo, env, wt, state = tick_heartbeat_scratch(Path(raw))
|
|
1642
|
+
except RuntimeError as error:
|
|
1643
|
+
report(f"{label} {error}")
|
|
1644
|
+
return 1
|
|
1645
|
+
stale = ago(hours=2)
|
|
1646
|
+
set_last_tick(state, stale)
|
|
1647
|
+
lines = doctor_tick_lines(wt, env)
|
|
1648
|
+
if len(lines) != 1:
|
|
1649
|
+
report(f"{label} a two-hour-old last_tick gives {len(lines)} tick lines, not one: {lines!r}")
|
|
1650
|
+
return 1
|
|
1651
|
+
for needle in ("tick: problem", stale, "keel tick task"):
|
|
1652
|
+
if needle not in lines[0]:
|
|
1653
|
+
report(f"{label} the stale line does not say {needle!r}: {lines[0]!r}")
|
|
1654
|
+
return 1
|
|
1655
|
+
fresh = ago(minutes=1)
|
|
1656
|
+
set_last_tick(state, fresh)
|
|
1657
|
+
lines = doctor_tick_lines(wt, env)
|
|
1658
|
+
if len(lines) != 1:
|
|
1659
|
+
report(f"{label} a one-minute-old last_tick gives {len(lines)} tick lines, not one: {lines!r}")
|
|
1660
|
+
return 1
|
|
1661
|
+
if not lines[0].startswith("tick: ok"):
|
|
1662
|
+
report(f"{label} a fresh heartbeat is not reported ok: {lines[0]!r}")
|
|
1663
|
+
return 1
|
|
1664
|
+
if fresh not in lines[0]:
|
|
1665
|
+
report(f"{label} a fresh heartbeat is ok without saying when the tick last ran: {lines[0]!r}")
|
|
1666
|
+
return 1
|
|
1667
|
+
set_last_tick(state, None)
|
|
1668
|
+
lines = doctor_tick_lines(wt, env)
|
|
1669
|
+
if len(lines) != 1:
|
|
1670
|
+
report(f"{label} a declared tick with no last_tick gives {len(lines)} tick lines, not one: {lines!r}")
|
|
1671
|
+
return 1
|
|
1672
|
+
if not lines[0].startswith("tick: problem"):
|
|
1673
|
+
report(f"{label} a declared tick that never ran is not a problem: {lines[0]!r}")
|
|
1674
|
+
return 1
|
|
1675
|
+
if "never" not in lines[0]:
|
|
1676
|
+
report(f"{label} a declared tick that never ran does not say it never ran: {lines[0]!r}")
|
|
1677
|
+
return 1
|
|
1678
|
+
set_last_tick(state, "last tuesday")
|
|
1679
|
+
lines = doctor_tick_lines(wt, env)
|
|
1680
|
+
if len(lines) != 1:
|
|
1681
|
+
report(f"{label} an unreadable last_tick gives {len(lines)} tick lines, not one: {lines!r}")
|
|
1682
|
+
return 1
|
|
1683
|
+
if not lines[0].startswith("tick: problem"):
|
|
1684
|
+
report(f"{label} an unreadable last_tick is not a problem: {lines[0]!r}")
|
|
1685
|
+
return 1
|
|
1686
|
+
if "last tuesday" not in lines[0]:
|
|
1687
|
+
report(f"{label} an unreadable last_tick is a problem that does not name the value: {lines[0]!r}")
|
|
1688
|
+
return 1
|
|
1689
|
+
config = wt["dev-a"] / "keel" / "config.yaml"
|
|
1690
|
+
config.write_text(config.read_text(encoding="utf-8").replace(" runner: tick\n", ""), encoding="utf-8")
|
|
1691
|
+
set_last_tick(state, ago(minutes=1))
|
|
1692
|
+
lines = doctor_tick_lines(wt, env)
|
|
1693
|
+
if len(lines) != 1:
|
|
1694
|
+
report(f"{label} a recorded heartbeat with no tick declared gives {len(lines)} tick lines, not one: {lines!r}")
|
|
1695
|
+
return 1
|
|
1696
|
+
if not lines[0].startswith("tick: ok"):
|
|
1697
|
+
report(f"{label} a recorded heartbeat is not read when nothing declares a tick: {lines[0]!r}")
|
|
1698
|
+
return 1
|
|
1699
|
+
if label.rstrip(":") not in {name for name, _ in registry.SCENARIOS}:
|
|
1700
|
+
report(f"{label} the scenario registry does not include it.")
|
|
1701
|
+
return 1
|
|
1702
|
+
report(f"{label.rstrip(':')} scenario passed.")
|
|
1703
|
+
return 0
|
|
1704
|
+
|
|
1705
|
+
|
|
1706
|
+
def validate_doctor_ignores_repo_without_tick_scenario() -> int:
|
|
1707
|
+
"""Issue #510 D3: a repository that declares no tick and never ran one gets no `tick` line."""
|
|
1708
|
+
label = "doctor-ignores-repo-without-tick:"
|
|
1709
|
+
with tempfile.TemporaryDirectory(prefix="keel-tick-doctor-none-") as raw:
|
|
1710
|
+
try:
|
|
1711
|
+
_repo, env, wt, state = tick_heartbeat_scratch(Path(raw))
|
|
1712
|
+
except RuntimeError as error:
|
|
1713
|
+
report(f"{label} {error}")
|
|
1714
|
+
return 1
|
|
1715
|
+
config = wt["dev-a"] / "keel" / "config.yaml"
|
|
1716
|
+
config.write_text(config.read_text(encoding="utf-8").replace(" runner: tick\n", ""), encoding="utf-8")
|
|
1717
|
+
set_last_tick(state, None)
|
|
1718
|
+
lines = doctor_tick_lines(wt, env)
|
|
1719
|
+
if lines:
|
|
1720
|
+
report(f"{label} doctor checks a tick nobody declared: {lines!r}")
|
|
1721
|
+
return 1
|
|
1722
|
+
if label.rstrip(":") not in {name for name, _ in registry.SCENARIOS}:
|
|
1723
|
+
report(f"{label} the scenario registry does not include it.")
|
|
1724
|
+
return 1
|
|
1725
|
+
report(f"{label.rstrip(':')} scenario passed.")
|
|
1726
|
+
return 0
|
|
1727
|
+
|
|
1728
|
+
|
|
1729
|
+
def validate_session_start_says_silent_tick_scenario() -> int:
|
|
1730
|
+
"""Issue #510 D5: the patrolling role starts knowing its tick is silent, and hears nothing when it is not."""
|
|
1731
|
+
label = "session-start-says-silent-tick:"
|
|
1732
|
+
with tempfile.TemporaryDirectory(prefix="keel-tick-session-start-") as raw:
|
|
1733
|
+
try:
|
|
1734
|
+
_repo, env, wt, state = tick_heartbeat_scratch(Path(raw))
|
|
1735
|
+
except RuntimeError as error:
|
|
1736
|
+
report(f"{label} {error}")
|
|
1737
|
+
return 1
|
|
1738
|
+
event = {"cwd": str(wt["pm-a"]), "source": "startup", "hook_event_name": "SessionStart"}
|
|
1739
|
+
|
|
1740
|
+
def started() -> str:
|
|
1741
|
+
hook = run_session_start_hook(wt["pm-a"], event, keel_cli=f'node "{ROOT / "bin" / "keel.js"}"')
|
|
1742
|
+
return session_start_context(hook) or ""
|
|
1743
|
+
|
|
1744
|
+
stale = ago(hours=2)
|
|
1745
|
+
set_last_tick(state, stale)
|
|
1746
|
+
context = started()
|
|
1747
|
+
for needle in (f"has not run since {stale}", "keel tick task"):
|
|
1748
|
+
if needle not in context:
|
|
1749
|
+
report(f"{label} the session-start context does not say {needle!r}: {context!r}")
|
|
1750
|
+
return 1
|
|
1751
|
+
as_json = run_keel(wt["pm-a"], "context", "--json", env=env)
|
|
1752
|
+
try:
|
|
1753
|
+
tick = json.loads(as_json.stdout)["patrol"]["tick"]
|
|
1754
|
+
except (ValueError, KeyError, TypeError) as error:
|
|
1755
|
+
report(f"{label} keel context --json has no patrol.tick ({error!r}): {as_json.stdout[:300]!r}")
|
|
1756
|
+
return 1
|
|
1757
|
+
if tick.get("state") != "stale":
|
|
1758
|
+
report(f"{label} patrol.tick.state is {tick.get('state')!r}, not 'stale': {tick!r}")
|
|
1759
|
+
return 1
|
|
1760
|
+
set_last_tick(state, ago(minutes=1))
|
|
1761
|
+
context = started()
|
|
1762
|
+
for needle in ("has not run since", "has never run"):
|
|
1763
|
+
if needle in context:
|
|
1764
|
+
report(f"{label} a fresh heartbeat still reaches the session as {needle!r}: {context!r}")
|
|
1765
|
+
return 1
|
|
1766
|
+
if label.rstrip(":") not in {name for name, _ in registry.SCENARIOS}:
|
|
1767
|
+
report(f"{label} the scenario registry does not include it.")
|
|
1768
|
+
return 1
|
|
1769
|
+
report(f"{label.rstrip(':')} scenario passed.")
|
|
1770
|
+
return 0
|
|
1771
|
+
|
|
1772
|
+
|
|
1568
1773
|
def validate_patrol_nudge_scenario() -> int:
|
|
1569
1774
|
"""Issues #307 part 1 and #313: the patrol nudges idle roles directly.
|
|
1570
1775
|
|
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 {}
|
|
@@ -184,8 +186,30 @@ function wakeEnded(where, state) {
|
|
|
184
186
|
return woken;
|
|
185
187
|
}
|
|
186
188
|
|
|
189
|
+
// What `tick/state.json` says about whether the tick runs (#510). Only that
|
|
190
|
+
// file is read: a tick that does not run cannot report it, so the report comes
|
|
191
|
+
// from the trace it left, and Keel asks the host nothing (D6). `state` is
|
|
192
|
+
// `ok`, `stale`, `never` (a declared tick with no run recorded), or null when
|
|
193
|
+
// nothing here uses a tick.
|
|
194
|
+
function heartbeat(where, now = new Date()) {
|
|
195
|
+
const at = readState(where).last_tick;
|
|
196
|
+
if (at === undefined || at === null) {
|
|
197
|
+
const declared = require("./config").readPatrolDeclarations(where.worktree).declarations.some((item) => item.runner === "tick");
|
|
198
|
+
return declared
|
|
199
|
+
? { state: "never", at: null, text: "has never run here although keel/config.yaml declares `runner: tick`; run the install commands `keel tick task` prints" }
|
|
200
|
+
: { state: null, at: null, text: "" };
|
|
201
|
+
}
|
|
202
|
+
const age = now.getTime() - Date.parse(at);
|
|
203
|
+
const repair = "run the install commands `keel tick task` prints again, or the machine was asleep";
|
|
204
|
+
if (Number.isNaN(age)) return { state: "stale", at, text: `has a last_tick that is not a date (${JSON.stringify(at)}); ${repair}` };
|
|
205
|
+
if (age > STALE_MS) return { state: "stale", at, text: `has not run since ${at} (${Math.round(age / 60000)} min ago); ${repair}` };
|
|
206
|
+
return { state: "ok", at, text: `last ran ${at}` };
|
|
207
|
+
}
|
|
208
|
+
|
|
187
209
|
function tick(where, now = new Date()) {
|
|
188
210
|
const result = { patrol: null, woken: [] };
|
|
211
|
+
// First, so a run that fails later still counts as a run (#510 D1).
|
|
212
|
+
store.writeJsonAtomic(where, stateFile(where), { ...readState(where), last_tick: store.isoLocal(now) });
|
|
189
213
|
const wakeState = readState(where);
|
|
190
214
|
result.woken = wakeEnded(where, wakeState);
|
|
191
215
|
result.handedOver = require("./shift").handOver(where);
|
|
@@ -366,4 +390,4 @@ function runTick(argv) {
|
|
|
366
390
|
}
|
|
367
391
|
}
|
|
368
392
|
|
|
369
|
-
module.exports = { runTick, tick, TickError };
|
|
393
|
+
module.exports = { runTick, tick, heartbeat, TickError };
|