@christang/keel 5.217.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 +7 -0
- package/scripts/validation/shift.py +310 -1
- package/src/core/context.js +9 -0
- package/src/core/shift.js +25 -13
- 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 -->"
|
|
@@ -428,6 +428,9 @@ SCENARIOS: tuple = (
|
|
|
428
428
|
("shift-cli-removes-after-exit", shift.validate_shift_cli_removes_after_exit_scenario),
|
|
429
429
|
("shift-cli-keeps-worktree-in-use", shift.validate_shift_cli_keeps_worktree_in_use_scenario),
|
|
430
430
|
("shift-cli-names-failed-removal", shift.validate_shift_cli_names_failed_removal_scenario),
|
|
431
|
+
("shift-ready-says-session-stays", shift.validate_shift_ready_says_session_stays_scenario),
|
|
432
|
+
("shift-ready-promises-removal-when-removable", shift.validate_shift_ready_promises_removal_when_removable_scenario),
|
|
433
|
+
("shift-ready-kept-session-names-shared-worktree", shift.validate_shift_ready_kept_session_names_shared_worktree_scenario),
|
|
431
434
|
("shift-cli-names-host-failure", shift.validate_shift_cli_names_host_failure_scenario),
|
|
432
435
|
("tick-retries-failed-wake", shift.validate_tick_retries_failed_wake_scenario),
|
|
433
436
|
("shift-cli-handover-claims-once", shift.validate_shift_cli_handover_claims_once_scenario),
|
|
@@ -486,6 +489,10 @@ SCENARIOS: tuple = (
|
|
|
486
489
|
("tick-reads-quota-file", shift.validate_tick_reads_quota_file_scenario),
|
|
487
490
|
("tick-checks-issues", shift.validate_tick_checks_issues_scenario),
|
|
488
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),
|
|
489
496
|
("launchd-stable-node", shift.validate_launchd_stable_node_scenario),
|
|
490
497
|
("tick-task-names-main-checkout", shift.validate_tick_task_names_main_checkout_scenario),
|
|
491
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
|
|
|
@@ -3726,14 +3931,20 @@ def validate_shift_cli_removes_after_exit_scenario() -> int:
|
|
|
3726
3931
|
return 0
|
|
3727
3932
|
|
|
3728
3933
|
|
|
3729
|
-
def handover_old_session(base: Path, row_cwd: Path, worktree_path: Path | None,
|
|
3934
|
+
def handover_old_session(base: Path, row_cwd: Path, worktree_path: Path | None, ready_out: list | None = None,
|
|
3935
|
+
config_text: str | None = None, **fake_env: str):
|
|
3730
3936
|
"""A delivered hand-over of `5b14fbae` from verify's worktree under the contract fake (#492).
|
|
3731
3937
|
|
|
3732
3938
|
Returns the `rm` calls the fake logged and `keel shift status` from rtl.
|
|
3733
3939
|
The row's `cwd` and the host's recorded `worktreePath` are the inputs.
|
|
3940
|
+
`ready_out`, when given, receives what `shift ready --wake` printed as text and then as `--json` (#506).
|
|
3734
3941
|
"""
|
|
3735
3942
|
OLD = "5b14fbae-b6aa-40b6-a72a-b3f89d2c6eea"
|
|
3736
3943
|
rtl, verify, env, _ = shift_scratch(base)
|
|
3944
|
+
if config_text is not None:
|
|
3945
|
+
write_text(verify / "keel" / "config.yaml", config_text)
|
|
3946
|
+
for git in (["add", "keel/config.yaml"], ["commit", "-q", "-m", "declare shift"], ["push", "-q", "origin", "HEAD"]):
|
|
3947
|
+
subprocess.run(["git", *git], cwd=verify, check=True, capture_output=True)
|
|
3737
3948
|
row_cwd = {"rtl": rtl, "verify": verify}[str(row_cwd)]
|
|
3738
3949
|
agents, calls, fake, config = base / "agents.json", base / "calls.jsonl", base / "fake-claude", base / "claude"
|
|
3739
3950
|
write_text(fake, HANDOVER_CONTRACT_FAKE)
|
|
@@ -3755,6 +3966,9 @@ def handover_old_session(base: Path, row_cwd: Path, worktree_path: Path | None,
|
|
|
3755
3966
|
readied = run_keel(verify, "shift", "ready", "--wake", "next: rerun R032", env=cli_env)
|
|
3756
3967
|
if readied.returncode != 0:
|
|
3757
3968
|
raise RuntimeError(f"ready --wake failed: {readied.stderr!r}")
|
|
3969
|
+
if ready_out is not None:
|
|
3970
|
+
as_json = run_keel(verify, "shift", "ready", "--wake", "--json", "next: rerun R032", env=cli_env)
|
|
3971
|
+
ready_out.extend([readied.stdout, as_json.stdout])
|
|
3758
3972
|
run_keel(verify, "tick", "--repo", str(rtl), env=env)
|
|
3759
3973
|
removals = [json.loads(line) for line in calls.read_text().splitlines() if json.loads(line)["argv"][:1] == ["rm"]]
|
|
3760
3974
|
return removals, run_keel(rtl, "shift", "status", env=env).stdout, verify
|
|
@@ -3818,6 +4032,101 @@ def validate_shift_cli_names_failed_removal_scenario() -> int:
|
|
|
3818
4032
|
return 0
|
|
3819
4033
|
|
|
3820
4034
|
|
|
4035
|
+
def validate_shift_ready_says_session_stays_scenario() -> int:
|
|
4036
|
+
"""Issue #506: `shift ready` does not promise a removal the hand-over will not carry out.
|
|
4037
|
+
|
|
4038
|
+
The session had made its worktree with `EnterWorktree` and the new shift
|
|
4039
|
+
starts in it, so `claude rm` would delete the worktree and the hand-over
|
|
4040
|
+
leaves the session listed (#492). `ready` printed that it is removed.
|
|
4041
|
+
"""
|
|
4042
|
+
label = "shift-ready-says-session-stays:"
|
|
4043
|
+
with tempfile.TemporaryDirectory(prefix="keel-shift-506a-") as raw:
|
|
4044
|
+
shown: list[str] = []
|
|
4045
|
+
try:
|
|
4046
|
+
removals, _status, verify = handover_old_session(Path(raw), Path("rtl"), Path("verify"), ready_out=shown)
|
|
4047
|
+
except RuntimeError as error:
|
|
4048
|
+
report(f"{label} {error}")
|
|
4049
|
+
return 1
|
|
4050
|
+
if len(shown) != 2:
|
|
4051
|
+
report(f"{label} the fixture did not return what ready printed: {shown!r}")
|
|
4052
|
+
return 1
|
|
4053
|
+
try:
|
|
4054
|
+
clear = json.loads(shown[1])["clear"]
|
|
4055
|
+
except (ValueError, KeyError) as error:
|
|
4056
|
+
report(f"{label} ready --json has no readable `clear` field ({error!r}): {shown[1]!r}")
|
|
4057
|
+
return 1
|
|
4058
|
+
for name, text in (("text", shown[0]), ("clear", clear)):
|
|
4059
|
+
if "removes it from the session list" in text:
|
|
4060
|
+
report(f"{label} the {name} hint promises a removal the hand-over does not carry out: {text!r}")
|
|
4061
|
+
return 1
|
|
4062
|
+
for needle in ("stays in `claude agents`", str(verify), "claude rm", "claude attach 5b14fbae"):
|
|
4063
|
+
if needle not in text:
|
|
4064
|
+
report(f"{label} the {name} hint does not say {needle!r}: {text!r}")
|
|
4065
|
+
return 1
|
|
4066
|
+
if any(r["argv"][1:2] == ["5b14fbae"] for r in removals):
|
|
4067
|
+
report(f"{label} the hand-over removed the session the hint said stays: {removals!r}")
|
|
4068
|
+
return 1
|
|
4069
|
+
if label.rstrip(":") not in {name for name, _ in registry.SCENARIOS}:
|
|
4070
|
+
report(f"{label} the scenario registry does not include it.")
|
|
4071
|
+
return 1
|
|
4072
|
+
report(f"{label.rstrip(':')} scenario passed.")
|
|
4073
|
+
return 0
|
|
4074
|
+
|
|
4075
|
+
|
|
4076
|
+
def validate_shift_ready_promises_removal_when_removable_scenario() -> int:
|
|
4077
|
+
"""Issue #506: a session nothing keeps is still told it is removed, and is."""
|
|
4078
|
+
label = "shift-ready-promises-removal-when-removable:"
|
|
4079
|
+
with tempfile.TemporaryDirectory(prefix="keel-shift-506b-") as raw:
|
|
4080
|
+
shown: list[str] = []
|
|
4081
|
+
try:
|
|
4082
|
+
removals, _status, _verify = handover_old_session(Path(raw), Path("verify"), None, ready_out=shown)
|
|
4083
|
+
except RuntimeError as error:
|
|
4084
|
+
report(f"{label} {error}")
|
|
4085
|
+
return 1
|
|
4086
|
+
if len(shown) != 2:
|
|
4087
|
+
report(f"{label} the fixture did not return what ready printed: {shown!r}")
|
|
4088
|
+
return 1
|
|
4089
|
+
if "removes it from the session list" not in shown[0]:
|
|
4090
|
+
report(f"{label} the hint no longer promises the removal that follows: {shown[0]!r}")
|
|
4091
|
+
return 1
|
|
4092
|
+
if "stays in `claude agents`" in shown[0]:
|
|
4093
|
+
report(f"{label} the hint says a removable session stays: {shown[0]!r}")
|
|
4094
|
+
return 1
|
|
4095
|
+
if not any(r["argv"][1:2] == ["5b14fbae"] for r in removals):
|
|
4096
|
+
report(f"{label} the hand-over did not call claude rm for the session the hint said is removed: {removals!r}")
|
|
4097
|
+
return 1
|
|
4098
|
+
if label.rstrip(":") not in {name for name, _ in registry.SCENARIOS}:
|
|
4099
|
+
report(f"{label} the scenario registry does not include it.")
|
|
4100
|
+
return 1
|
|
4101
|
+
report(f"{label.rstrip(':')} scenario passed.")
|
|
4102
|
+
return 0
|
|
4103
|
+
|
|
4104
|
+
|
|
4105
|
+
def validate_shift_ready_kept_session_names_shared_worktree_scenario() -> int:
|
|
4106
|
+
"""Issue #506: a kept session whose worktree is the new shift's says so."""
|
|
4107
|
+
label = "shift-ready-kept-session-names-shared-worktree:"
|
|
4108
|
+
with tempfile.TemporaryDirectory(prefix="keel-shift-506c-") as raw:
|
|
4109
|
+
shown: list[str] = []
|
|
4110
|
+
try:
|
|
4111
|
+
_removals, _status, verify = handover_old_session(Path(raw), Path("rtl"), Path("verify"), ready_out=shown,
|
|
4112
|
+
config_text="shift:\n keep_old_sessions: 1\n")
|
|
4113
|
+
except RuntimeError as error:
|
|
4114
|
+
report(f"{label} {error}")
|
|
4115
|
+
return 1
|
|
4116
|
+
if len(shown) != 2:
|
|
4117
|
+
report(f"{label} the fixture did not return what ready printed: {shown!r}")
|
|
4118
|
+
return 1
|
|
4119
|
+
for needle in ("its conversation is kept", "claude attach 5b14fbae", str(verify), "the new shift's"):
|
|
4120
|
+
if needle not in shown[0]:
|
|
4121
|
+
report(f"{label} the hint does not say {needle!r}: {shown[0]!r}")
|
|
4122
|
+
return 1
|
|
4123
|
+
if label.rstrip(":") not in {name for name, _ in registry.SCENARIOS}:
|
|
4124
|
+
report(f"{label} the scenario registry does not include it.")
|
|
4125
|
+
return 1
|
|
4126
|
+
report(f"{label.rstrip(':')} scenario passed.")
|
|
4127
|
+
return 0
|
|
4128
|
+
|
|
4129
|
+
|
|
3821
4130
|
def validate_shift_cli_names_host_failure_scenario() -> int:
|
|
3822
4131
|
"""Issue #408: a hand-off the host cannot be asked about says why it waits."""
|
|
3823
4132
|
label = "shift-cli-names-host-failure:"
|
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/shift.js
CHANGED
|
@@ -636,6 +636,20 @@ function keptCopyOf(where, role, transcript) {
|
|
|
636
636
|
}
|
|
637
637
|
}
|
|
638
638
|
|
|
639
|
+
// Worktrees in use: the hand-off's, every bound one, and each other listed
|
|
640
|
+
// session's (#492 D2). `claude rm` deletes the worktree a session created, so a
|
|
641
|
+
// session whose worktree is in use stays listed. `ready` asks the same question
|
|
642
|
+
// to say so up front (#506 D1), without a listing, so the last reason is
|
|
643
|
+
// evaluated only when `listed` is given.
|
|
644
|
+
function worktreeInUse(roles, handOffWorktree, worktree, row, listed) {
|
|
645
|
+
const real = realpath(worktree);
|
|
646
|
+
if (handOffWorktree && realpath(handOffWorktree) === real) return "the new shift's worktree";
|
|
647
|
+
const binding = Object.entries(roles).find(([tree]) => realpath(tree) === real);
|
|
648
|
+
if (binding) return `bound to role ${binding[1]}`;
|
|
649
|
+
const other = (listed || []).find((r) => r && r !== row && r.cwd && realpath(r.cwd) === real);
|
|
650
|
+
return other ? `session ${other.id || other.sessionId.slice(0, 8)} runs there` : null;
|
|
651
|
+
}
|
|
652
|
+
|
|
639
653
|
// After a delivered hand-over or a resume, the newest `keep` stopped background
|
|
640
654
|
// sessions of the role stay listed; each older one is removed with `claude rm`
|
|
641
655
|
// once Keel's store holds its transcript (#397 D2). `claude rm` leaves the
|
|
@@ -669,15 +683,7 @@ function removeOldSessions(claude, where, entry, keep) {
|
|
|
669
683
|
})
|
|
670
684
|
.filter(({ transcript, kept }) => transcript || fs.existsSync(kept))
|
|
671
685
|
.sort((a, b) => (Number(b.row.startedAt) || 0) - (Number(a.row.startedAt) || 0));
|
|
672
|
-
|
|
673
|
-
const inUse = (worktree, row) => {
|
|
674
|
-
const real = realpath(worktree);
|
|
675
|
-
if (entry.worktree && realpath(entry.worktree) === real) return "the new shift's worktree";
|
|
676
|
-
const binding = Object.entries(roles).find(([tree]) => realpath(tree) === real);
|
|
677
|
-
if (binding) return `bound to role ${binding[1]}`;
|
|
678
|
-
const other = listed.find((r) => r && r !== row && r.cwd && realpath(r.cwd) === real);
|
|
679
|
-
return other ? `session ${idOf(other)} runs there` : null;
|
|
680
|
-
};
|
|
686
|
+
const inUse = (worktree, row) => worktreeInUse(roles, entry.worktree, worktree, row, listed);
|
|
681
687
|
const removed = [];
|
|
682
688
|
const notRemoved = old.slice(0, keep).map(({ row }) => ({ id: idOf(row), reason: "kept by `shift: keep_old_sessions`" }));
|
|
683
689
|
for (const { row, worktree, transcript } of old.slice(keep)) {
|
|
@@ -1518,13 +1524,19 @@ const CLEAR_HINT = [
|
|
|
1518
1524
|
|
|
1519
1525
|
// Who starts the new session (#293 D3): the coordinator that asked, nobody,
|
|
1520
1526
|
// or — without a chat role — the person who opens it.
|
|
1521
|
-
function clearHint(result) {
|
|
1527
|
+
function clearHint(result, where) {
|
|
1522
1528
|
if (result.queued) {
|
|
1523
1529
|
const own = result.cli.session.slice(0, 8);
|
|
1530
|
+
// The hand-over leaves this session listed when its worktree is in use (#492), and says so here (#506 D2).
|
|
1531
|
+
const host = hostWorktree({ id: own, sessionId: result.cli.session });
|
|
1532
|
+
const using = host && fs.existsSync(host)
|
|
1533
|
+
? worktreeInUse(store.readJsonFile(path.join(where.root, "roles.json")), result.worktree, host, null, null) : null;
|
|
1524
1534
|
// Nothing kept by default (#418): the old shift is removed once Keel holds its transcript.
|
|
1525
1535
|
const kept = require("./config").readShiftDeclaration(result.worktree).keepOldSessions > 0
|
|
1526
|
-
? `its conversation is kept, \`claude attach ${own}\` reopens it`
|
|
1527
|
-
:
|
|
1536
|
+
? `its conversation is kept, \`claude attach ${own}\` reopens it${using ? `, beside the new shift, because its worktree ${host} is in use (${using})` : ""}`
|
|
1537
|
+
: using
|
|
1538
|
+
? `it stays in \`claude agents\`, because its worktree ${host} is in use (${using}) and \`claude rm\` would delete it, and \`claude attach ${own}\` brings it back beside the new shift`
|
|
1539
|
+
: `then removes it from the session list once Keel's store holds its transcript, which \`keel shift history ${result.role} --show ${own}\` prints`;
|
|
1528
1540
|
return "This is a Claude Code CLI session, which cannot clear itself (#357). End your turn now: once this session has finished, "
|
|
1529
1541
|
+ `a waiter stops it — ${kept} — and starts a new session `
|
|
1530
1542
|
+ `named for its start, \`${result.role} · <MM-DD HH:MM>\`, in ${result.worktree} that runs \`keel shift resume\`; \`keel tick\` does the same if the waiter is gone. \`keel shift status\` shows the hand-off.`;
|
|
@@ -1620,7 +1632,7 @@ function runShift(argv) {
|
|
|
1620
1632
|
case "ready": {
|
|
1621
1633
|
const result = ready(where, { ...options, text: rest.join(" ") });
|
|
1622
1634
|
const whose = result.role || "this worktree (no chat role, so no request to close)";
|
|
1623
|
-
const hint = clearHint(result);
|
|
1635
|
+
const hint = clearHint(result, where);
|
|
1624
1636
|
out({ ...result, clear: hint }, `Stored the shift note for ${whose} at ${result.note}${result.closed.length ? ` and closed ${result.closed.join(", ")}` : ""}.\n${hint}`);
|
|
1625
1637
|
return 0;
|
|
1626
1638
|
}
|
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 };
|