@christang/keel 5.196.1 → 5.197.1
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/README.md +12 -0
- package/README.zh-CN.md +10 -0
- package/assets/bootstrap/AGENTS.md +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/plugins/keel/.claude-plugin/plugin.json +1 -1
- package/plugins/keel/.codex-plugin/plugin.json +1 -1
- package/scripts/validate_plugin.py +24 -5
- package/scripts/validation/common.py +2 -2
- package/scripts/validation/hosts.py +20 -11
- package/scripts/validation/registry.py +3 -0
- package/scripts/validation/selfcheck.py +34 -0
- package/scripts/validation/shift.py +95 -0
- package/src/core/config.js +10 -1
- package/src/core/tick.js +56 -5
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.197.1",
|
|
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/README.md
CHANGED
|
@@ -963,6 +963,18 @@ minutes, which runs the patrol once its recommended next run has passed. Declare
|
|
|
963
963
|
`cadence: adaptive` to let the patrol choose that next run by what it saw; `keel tick task` prints the
|
|
964
964
|
launchd job. See [docs/cli-team.md](docs/cli-team.md).
|
|
965
965
|
|
|
966
|
+
The tick also passes the patrol what a host task used to (#456). It measures free disk on each patrol
|
|
967
|
+
worktree's filesystem, against `disk_min_gb:` (default 20). It reads the weekly quota percent from the
|
|
968
|
+
file `quota_file:` names, if that file was written in the last 6 hours. Keel runs no command to get
|
|
969
|
+
quota; a status line can write it, since only status lines receive `rate_limits`. When the file is
|
|
970
|
+
stale, or none is declared, the tick says so once. Declare both on any `patrol:` item; the coordinator
|
|
971
|
+
that owns repository-wide risks reports them.
|
|
972
|
+
|
|
973
|
+
```bash
|
|
974
|
+
# in ~/.claude/statusline-command.sh, after reading the JSON into $input
|
|
975
|
+
echo "$input" | jq -r '.rate_limits.seven_day.used_percentage // empty' > ~/.claude/keel-quota.txt
|
|
976
|
+
```
|
|
977
|
+
|
|
966
978
|
## The owner's language
|
|
967
979
|
|
|
968
980
|
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.
|
package/README.zh-CN.md
CHANGED
|
@@ -802,6 +802,16 @@ patrol:
|
|
|
802
802
|
下一次运行时间,就运行巡查。声明 `runner: tick`,再加上 `cadence: adaptive` 让巡查根据所见来选择下一次运行时间;
|
|
803
803
|
`keel tick task` 会打印 launchd 任务。见 [docs/cli-team.zh-CN.md](docs/cli-team.zh-CN.md)。
|
|
804
804
|
|
|
805
|
+
tick 还会把以前由宿主任务传的数字交给巡查(#456)。它测量每个巡查 worktree 所在文件系统的剩余磁盘空间,对照
|
|
806
|
+
`disk_min_gb:`(默认 20)。它从 `quota_file:` 指定的文件里读取周配额百分比,前提是这个文件在 6 小时内写过。Keel
|
|
807
|
+
不会为了配额去执行任何命令;可以由 status line 来写这个文件,因为只有 status line 能拿到 `rate_limits`。文件过期,
|
|
808
|
+
或者根本没有声明时,tick 只说一次。两项都可以声明在任意一个 `patrol:` 项上,由负责全仓库风险的协调者报告。
|
|
809
|
+
|
|
810
|
+
```bash
|
|
811
|
+
# 在 ~/.claude/statusline-command.sh 里,把 JSON 读进 $input 之后
|
|
812
|
+
echo "$input" | jq -r '.rate_limits.seven_day.used_percentage // empty' > ~/.claude/keel-quota.txt
|
|
813
|
+
```
|
|
814
|
+
|
|
805
815
|
## 负责人的语言
|
|
806
816
|
|
|
807
817
|
agent 读到的大多是英文——工具输出、issue、spec、Keel 自己的输出——回答你时也会滑向英文。声明你希望被使用的语言,这条规则就会在写回复的地方被重申:在 `keel context`、会话启动提示,以及每个 worktree 里每次提示时的 chat hook 中(#305)——在 Claude 上,还会在每 15 次工具调用或连续 10 分钟的工具调用之后重申,因为回合中途写的状态更新并不跟在某次提示之后(#311)。agent 仍可以用任何语言工作;标识符、命令、路径和引用的输出保持原样。
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@christang/keel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.197.1",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@christang/keel",
|
|
9
|
-
"version": "5.
|
|
9
|
+
"version": "5.197.1",
|
|
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.197.1",
|
|
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.197.1",
|
|
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",
|
|
@@ -145,13 +145,27 @@ def run_group(group: str, jobs: int) -> int:
|
|
|
145
145
|
|
|
146
146
|
|
|
147
147
|
def main() -> int:
|
|
148
|
-
|
|
148
|
+
# One or more `--scenario NAME` pairs (#444): each named scenario runs, and
|
|
149
|
+
# the result fails when any of them does.
|
|
150
|
+
if sys.argv[1:2] == ["--scenario"]:
|
|
151
|
+
rest = sys.argv[1:]
|
|
152
|
+
if len(rest) % 2 or any(flag != "--scenario" for flag in rest[0::2]):
|
|
153
|
+
report(f"usage: validate_plugin.py --scenario NAME [--scenario NAME ...], got: {' '.join(rest)}")
|
|
154
|
+
return 2
|
|
149
155
|
registry = dict(SCENARIOS)
|
|
150
|
-
|
|
151
|
-
if
|
|
152
|
-
|
|
156
|
+
names = rest[1::2]
|
|
157
|
+
unknown = [name for name in names if name not in registry]
|
|
158
|
+
if unknown:
|
|
159
|
+
report(f"unknown validation scenario: {', '.join(unknown)}")
|
|
153
160
|
return 2
|
|
154
|
-
|
|
161
|
+
if len(names) == 1:
|
|
162
|
+
return registry[names[0]]()
|
|
163
|
+
failures = [name for name in names if registry[name]() != 0]
|
|
164
|
+
if failures:
|
|
165
|
+
report(f"validation --scenario failed for: {', '.join(failures)}")
|
|
166
|
+
return 1
|
|
167
|
+
report(f"validation --scenario passed: {len(names)} scenarios.")
|
|
168
|
+
return 0
|
|
155
169
|
|
|
156
170
|
if len(sys.argv) >= 2 and sys.argv[1] == "--all":
|
|
157
171
|
jobs = os.cpu_count() or 2
|
|
@@ -182,6 +196,11 @@ def main() -> int:
|
|
|
182
196
|
print(evidence.render_markdown(classes) if rest else evidence.render(classes))
|
|
183
197
|
return 0
|
|
184
198
|
|
|
199
|
+
# Only no arguments at all means the baseline: an argument it does not
|
|
200
|
+
# recognize used to fall through here and exit 0 having run nothing asked (#444).
|
|
201
|
+
if sys.argv[1:]:
|
|
202
|
+
report(f"usage: validate_plugin.py [--all [--jobs N] | --group NAME [--jobs N] | --scenario NAME ... | --evidence [--markdown]], got: {' '.join(sys.argv[1:])}")
|
|
203
|
+
return 2
|
|
185
204
|
return run_baseline()
|
|
186
205
|
|
|
187
206
|
|
|
@@ -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.197.1"
|
|
39
39
|
|
|
40
40
|
|
|
41
|
-
PROTOCOL_VERSION = "5.
|
|
41
|
+
PROTOCOL_VERSION = "5.197.1"
|
|
42
42
|
|
|
43
43
|
|
|
44
44
|
LEGACY_MANAGED_START = "<!-- keel:start version=2.1 -->"
|
|
@@ -3015,6 +3015,15 @@ OVERLAY_BLOCK_RE = re.compile(
|
|
|
3015
3015
|
)
|
|
3016
3016
|
|
|
3017
3017
|
|
|
3018
|
+
# The host-query limit the `keel --update` scenarios set (#452). Every stand-in
|
|
3019
|
+
# host, the ones meant to answer as well as the one meant to hang, is a node
|
|
3020
|
+
# program that must start and answer inside it. Under the full suite's own
|
|
3021
|
+
# parallel load, starting one took longer than 2–4 s, so the limit is set well
|
|
3022
|
+
# above that, and the hung stand-in sleeps well past two of them.
|
|
3023
|
+
QUERY_LIMIT_S = 12
|
|
3024
|
+
QUERY_LIMIT_MS = str(QUERY_LIMIT_S * 1000)
|
|
3025
|
+
|
|
3026
|
+
|
|
3018
3027
|
def validate_update_host_query_timeout_scenario() -> int:
|
|
3019
3028
|
"""Issue #354: a hung or failed host query is `failed`, never `absent`.
|
|
3020
3029
|
|
|
@@ -3073,12 +3082,12 @@ def validate_update_host_query_timeout_scenario() -> int:
|
|
|
3073
3082
|
return 1
|
|
3074
3083
|
|
|
3075
3084
|
# Only the hung case needs a short limit; the others keep 30 s, so load cannot trip them.
|
|
3076
|
-
result, calls, took = update(env_extra={"FAKE_LIST_SLEEP_CODEX": "
|
|
3085
|
+
result, calls, took = update(env_extra={"FAKE_LIST_SLEEP_CODEX": "40", "KEEL_UPDATE_QUERY_TIMEOUT_MS": QUERY_LIMIT_MS})
|
|
3077
3086
|
codex = line(result.stdout, "codex plugin")
|
|
3078
3087
|
if "absent" in codex:
|
|
3079
3088
|
report(f"{label} a hung codex plugin list --json was reported absent: {codex!r}")
|
|
3080
3089
|
return 1
|
|
3081
|
-
for needle in ("failed", "codex plugin list --json", "
|
|
3090
|
+
for needle in ("failed", "codex plugin list --json", f"{QUERY_LIMIT_S} s"):
|
|
3082
3091
|
if needle not in codex:
|
|
3083
3092
|
report(f"{label} the hung-query line does not name {needle!r}: {codex!r}")
|
|
3084
3093
|
return 1
|
|
@@ -3091,8 +3100,8 @@ def validate_update_host_query_timeout_scenario() -> int:
|
|
|
3091
3100
|
if result.returncode == 0:
|
|
3092
3101
|
report(f"{label} a failed query left keel --update exiting 0.")
|
|
3093
3102
|
return 1
|
|
3094
|
-
if took >
|
|
3095
|
-
report(f"{label} the hung query held keel --update for {took:.1f} s, past two
|
|
3103
|
+
if took > 2 * QUERY_LIMIT_S + 15:
|
|
3104
|
+
report(f"{label} the hung query held keel --update for {took:.1f} s, past two {QUERY_LIMIT_S} s attempts.")
|
|
3096
3105
|
return 1
|
|
3097
3106
|
|
|
3098
3107
|
result, _, _ = update(env_extra={"KEEL_UPDATE_CODEX": str(tmp / "no-such-codex")})
|
|
@@ -3100,7 +3109,7 @@ def validate_update_host_query_timeout_scenario() -> int:
|
|
|
3100
3109
|
report(f"{label} a missing codex executable no longer reads absent: {result.stdout!r}")
|
|
3101
3110
|
return 1
|
|
3102
3111
|
|
|
3103
|
-
result, _, _ = update("--dry-run", env_extra={"FAKE_LIST_SLEEP_CODEX": "
|
|
3112
|
+
result, _, _ = update("--dry-run", env_extra={"FAKE_LIST_SLEEP_CODEX": "40", "KEEL_UPDATE_QUERY_TIMEOUT_MS": QUERY_LIMIT_MS})
|
|
3104
3113
|
if result.returncode != 0:
|
|
3105
3114
|
report(f"{label} --dry-run with a hung query exited {result.returncode}: {result.stdout!r}")
|
|
3106
3115
|
return 1
|
|
@@ -3150,7 +3159,7 @@ def validate_update_codex_from_disk_scenario() -> int:
|
|
|
3150
3159
|
env.update({
|
|
3151
3160
|
"KEEL_UPDATE_NPM": str(launchers["npm"]), "KEEL_UPDATE_CLAUDE": str(launchers["claude"]),
|
|
3152
3161
|
"KEEL_UPDATE_CODEX": str(launchers["codex"]), "CODEX_HOME": str(codex_home),
|
|
3153
|
-
"KEEL_UPDATE_QUERY_TIMEOUT_MS":
|
|
3162
|
+
"KEEL_UPDATE_QUERY_TIMEOUT_MS": QUERY_LIMIT_MS, "FAKE_LIST_SLEEP_CODEX": "40",
|
|
3154
3163
|
"FAKE_LOG": str(log), "FAKE_STATE": str(state), "FAKE_CODEX_SOURCE": str(tmp / "codex-source"),
|
|
3155
3164
|
"FAKE_CODEX_CACHE": str(cache),
|
|
3156
3165
|
})
|
|
@@ -3319,10 +3328,10 @@ def validate_update_host_query_retry_scenario() -> int:
|
|
|
3319
3328
|
env = dict(os.environ)
|
|
3320
3329
|
env.update({
|
|
3321
3330
|
"KEEL_UPDATE_NPM": str(launchers["npm"]), "KEEL_UPDATE_CLAUDE": str(launchers["claude"]),
|
|
3322
|
-
"KEEL_UPDATE_CODEX": str(launchers["codex"]), "KEEL_UPDATE_QUERY_TIMEOUT_MS":
|
|
3331
|
+
"KEEL_UPDATE_CODEX": str(launchers["codex"]), "KEEL_UPDATE_QUERY_TIMEOUT_MS": QUERY_LIMIT_MS,
|
|
3323
3332
|
"CODEX_HOME": str(tmp / "codex-home"), "FAKE_LOG": str(log), "FAKE_STATE": str(state),
|
|
3324
3333
|
"FAKE_CODEX_SOURCE": str(source),
|
|
3325
|
-
"FAKE_LIST_SLEEP_CODEX": "
|
|
3334
|
+
"FAKE_LIST_SLEEP_CODEX": "40", "FAKE_LIST_SLEEP_TIMES_CODEX": times,
|
|
3326
3335
|
})
|
|
3327
3336
|
env.pop("KEEL_UPDATE_SOURCE", None)
|
|
3328
3337
|
started = time.monotonic()
|
|
@@ -3341,7 +3350,7 @@ def validate_update_host_query_retry_scenario() -> int:
|
|
|
3341
3350
|
return 1
|
|
3342
3351
|
|
|
3343
3352
|
result, calls, line, took = update("9")
|
|
3344
|
-
for needle in ("failed", "codex plugin list --json", "timed out twice", "
|
|
3353
|
+
for needle in ("failed", "codex plugin list --json", "timed out twice", f"{QUERY_LIMIT_S} s"):
|
|
3345
3354
|
if needle not in line:
|
|
3346
3355
|
report(f"{label} a lasting hang's line does not name {needle!r}: {line!r}")
|
|
3347
3356
|
return 1
|
|
@@ -3349,8 +3358,8 @@ def validate_update_host_query_retry_scenario() -> int:
|
|
|
3349
3358
|
if runs != 2:
|
|
3350
3359
|
report(f"{label} a lasting hang ran the query {runs} time(s), not 2: {calls!r}")
|
|
3351
3360
|
return 1
|
|
3352
|
-
if took >
|
|
3353
|
-
report(f"{label} two
|
|
3361
|
+
if took > 2 * QUERY_LIMIT_S + 15:
|
|
3362
|
+
report(f"{label} two {QUERY_LIMIT_S} s attempts held keel --update for {took:.1f} s.")
|
|
3354
3363
|
return 1
|
|
3355
3364
|
if "update-host-query-retry" not in {name for name, _ in registry.SCENARIOS}:
|
|
3356
3365
|
report(f"{label} scenario is not registered.")
|
|
@@ -459,6 +459,8 @@ SCENARIOS: tuple = (
|
|
|
459
459
|
("patrol-next", shift.validate_patrol_next_scenario),
|
|
460
460
|
("tick-runs-due-patrol", shift.validate_tick_runs_due_patrol_scenario),
|
|
461
461
|
("tick-runs-each-patrol", shift.validate_tick_runs_each_patrol_scenario),
|
|
462
|
+
("tick-passes-free-disk", shift.validate_tick_passes_free_disk_scenario),
|
|
463
|
+
("tick-reads-quota-file", shift.validate_tick_reads_quota_file_scenario),
|
|
462
464
|
("launchd-stable-node", shift.validate_launchd_stable_node_scenario),
|
|
463
465
|
("shift-slash-command", shift.validate_shift_slash_command_scenario),
|
|
464
466
|
("shift-check-skips-host-keep-awake", shift.validate_shift_check_skips_host_keep_awake_scenario),
|
|
@@ -582,6 +584,7 @@ SCENARIOS: tuple = (
|
|
|
582
584
|
("external-agents-are-documented", docs.validate_external_agents_are_documented_scenario),
|
|
583
585
|
("external-agent-exit-status", guard.validate_external_agent_exit_status_scenario),
|
|
584
586
|
("validation-runner", selfcheck.validate_validation_runner_scenario),
|
|
587
|
+
("runner-refuses-what-it-would-not-run", selfcheck.validate_runner_refuses_what_it_would_not_run_scenario),
|
|
585
588
|
("section-boundary", contract.validate_section_boundary_scenario),
|
|
586
589
|
("review-entry-extent", contract.validate_review_entry_extent_scenario),
|
|
587
590
|
("reauthorizations-shape", contract.validate_reauthorizations_shape_scenario),
|
|
@@ -785,6 +785,40 @@ def validation_modules() -> list:
|
|
|
785
785
|
]
|
|
786
786
|
|
|
787
787
|
|
|
788
|
+
def validate_runner_refuses_what_it_would_not_run_scenario() -> int:
|
|
789
|
+
"""Issue #444: the runner never reports a pass for scenarios it did not run.
|
|
790
|
+
|
|
791
|
+
Several `--scenario NAME` pairs run each named scenario; anything it does
|
|
792
|
+
not recognize exits 2 with a usage line instead of falling through to the
|
|
793
|
+
baseline, which used to exit 0 having run nothing that was asked for.
|
|
794
|
+
"""
|
|
795
|
+
label = "runner-refuses-what-it-would-not-run:"
|
|
796
|
+
|
|
797
|
+
def run(*args: str) -> subprocess.CompletedProcess[str]:
|
|
798
|
+
return subprocess.run([sys.executable, str(ROOT / "scripts" / "validate_plugin.py"), *args],
|
|
799
|
+
cwd=ROOT, text=True, capture_output=True, check=False, timeout=300)
|
|
800
|
+
|
|
801
|
+
both = run("--scenario", "version-alignment", "--scenario", "readme-zh-matches-english")
|
|
802
|
+
if both.returncode != 0:
|
|
803
|
+
report(f"{label} two passing scenarios exited {both.returncode}: {both.stdout!r} {both.stderr!r}")
|
|
804
|
+
return 1
|
|
805
|
+
for name in ("version-alignment", "readme-zh-matches-english"):
|
|
806
|
+
if f"{name} scenario passed" not in both.stdout:
|
|
807
|
+
report(f"{label} two --scenario pairs did not run {name}: {both.stdout!r}")
|
|
808
|
+
return 1
|
|
809
|
+
for args in (("--scenarios", "version-alignment"), ("--scenario", "version-alignment", "--jobs", "2"),
|
|
810
|
+
("--scenario", "version-alignment", "--scenario", "no-such-scenario")):
|
|
811
|
+
refused = run(*args)
|
|
812
|
+
if refused.returncode != 2:
|
|
813
|
+
report(f"{label} {' '.join(args)} exited {refused.returncode}, not 2: {refused.stdout!r}")
|
|
814
|
+
return 1
|
|
815
|
+
if "baseline validation passed" in refused.stdout:
|
|
816
|
+
report(f"{label} {' '.join(args)} fell through to the baseline: {refused.stdout!r}")
|
|
817
|
+
return 1
|
|
818
|
+
report("runner-refuses-what-it-would-not-run scenario passed.")
|
|
819
|
+
return 0
|
|
820
|
+
|
|
821
|
+
|
|
788
822
|
def validate_validation_runner_scenario() -> int:
|
|
789
823
|
if not getattr(registry, "SCENARIOS", None):
|
|
790
824
|
report("validation-runner: the scenario registry is missing.")
|
|
@@ -974,6 +974,101 @@ def validate_tick_runs_each_patrol_scenario() -> int:
|
|
|
974
974
|
return 0
|
|
975
975
|
|
|
976
976
|
|
|
977
|
+
def tick_scopes_scratch(base: Path, extra_a: str = "", extra_b: str = "", tail: str = "") -> tuple[Path, dict, dict[str, Path], Path]:
|
|
978
|
+
"""Two scoped coordinators run by `keel tick` (#434), for what the tick passes them (#456)."""
|
|
979
|
+
config = ("patrol:\n"
|
|
980
|
+
f" - role: pm-a\n every: 30m\n runner: tick\n scope: group:team-a\n{extra_a}"
|
|
981
|
+
f" - role: pm-b\n every: 45m\n runner: tick\n scope: group:team-b\n{extra_b}" + tail)
|
|
982
|
+
repo, env, wt = patrol_scopes_scratch(base, config)
|
|
983
|
+
return repo, env, wt, mailbox_common_dir(repo) / "keel-chat" / "tick" / "state.json"
|
|
984
|
+
|
|
985
|
+
|
|
986
|
+
def due_tick(repo: Path, env: dict, wt: dict[str, Path], state: Path) -> subprocess.CompletedProcess[str]:
|
|
987
|
+
"""Run `keel tick` with every recorded patrol made due first."""
|
|
988
|
+
if state.exists():
|
|
989
|
+
saved = json.loads(state.read_text(encoding="utf-8"))
|
|
990
|
+
for entry in (saved.get("patrols") or {}).values():
|
|
991
|
+
entry["next_at"] = "2000-01-01T00:00:00+00:00"
|
|
992
|
+
state.write_text(json.dumps(saved), encoding="utf-8")
|
|
993
|
+
return run_keel(wt["dev-a"], "tick", "--repo", str(repo), env=env)
|
|
994
|
+
|
|
995
|
+
|
|
996
|
+
def patrol_told(repo: Path, role: str, needle: str) -> int:
|
|
997
|
+
return len(chat_records_with(repo, "dm-" + "--".join(sorted(("keel-patrol", role))), needle))
|
|
998
|
+
|
|
999
|
+
|
|
1000
|
+
def validate_tick_passes_free_disk_scenario() -> int:
|
|
1001
|
+
"""Issue #456 D1, D2: `keel tick` measures free disk and passes it to the patrol.
|
|
1002
|
+
|
|
1003
|
+
Raising the floor far above the machine's free space turns the disk low
|
|
1004
|
+
without faking the measurement; the risk reaches the coordinator that owns
|
|
1005
|
+
repository-wide risks once, and nobody else.
|
|
1006
|
+
"""
|
|
1007
|
+
label = "tick-passes-free-disk:"
|
|
1008
|
+
with tempfile.TemporaryDirectory(prefix="keel-tick-disk-") as raw:
|
|
1009
|
+
# The patrol reports disk turning low, so the floor starts below the
|
|
1010
|
+
# machine's free space and is then raised far above it.
|
|
1011
|
+
repo, env, wt, state = tick_scopes_scratch(Path(raw), extra_a=" disk_min_gb: 1\n")
|
|
1012
|
+
config = repo / "keel" / "config.yaml"
|
|
1013
|
+
for floor in ("1", "1000000", "1000000"):
|
|
1014
|
+
config.write_text(config.read_text(encoding="utf-8").replace("disk_min_gb: 1\n", f"disk_min_gb: {floor}\n")
|
|
1015
|
+
.replace("disk_min_gb: 1000000\n", f"disk_min_gb: {floor}\n"), encoding="utf-8")
|
|
1016
|
+
ran = due_tick(repo, env, wt, state)
|
|
1017
|
+
if ran.returncode != 0:
|
|
1018
|
+
report(f"{label} keel tick exited {ran.returncode}: {ran.stdout!r} {ran.stderr!r}")
|
|
1019
|
+
return 1
|
|
1020
|
+
told = {role: patrol_told(repo, role, "free disk is") for role in ("pm-a", "pm-b")}
|
|
1021
|
+
if told != {"pm-a": 1, "pm-b": 0}:
|
|
1022
|
+
report(f"{label} the disk risk reached {told}, not pm-a once: {ran.stdout!r}")
|
|
1023
|
+
return 1
|
|
1024
|
+
if not patrol_told(repo, "pm-a", "below 1000000 GB"):
|
|
1025
|
+
report(f"{label} the disk risk does not name the declared floor of 1000000 GB.")
|
|
1026
|
+
return 1
|
|
1027
|
+
report("tick-passes-free-disk scenario passed.")
|
|
1028
|
+
return 0
|
|
1029
|
+
|
|
1030
|
+
|
|
1031
|
+
def validate_tick_reads_quota_file_scenario() -> int:
|
|
1032
|
+
"""Issue #456 D2, D3: `keel tick` passes the quota a declared file holds.
|
|
1033
|
+
|
|
1034
|
+
A status line writes the weekly percent; the tick reads it while fresh,
|
|
1035
|
+
says once when it is stale, and says once when no file is declared. Keel
|
|
1036
|
+
runs no command for it.
|
|
1037
|
+
"""
|
|
1038
|
+
label = "tick-reads-quota-file:"
|
|
1039
|
+
with tempfile.TemporaryDirectory(prefix="keel-tick-quota-") as raw:
|
|
1040
|
+
base = Path(raw)
|
|
1041
|
+
quota = base / "quota.txt"
|
|
1042
|
+
quota.write_text("91\n", encoding="utf-8")
|
|
1043
|
+
repo, env, wt, state = tick_scopes_scratch(base / "declared", extra_a=f" quota_file: {quota}\n")
|
|
1044
|
+
due_tick(repo, env, wt, state)
|
|
1045
|
+
quota.write_text("96.4\n", encoding="utf-8")
|
|
1046
|
+
due_tick(repo, env, wt, state)
|
|
1047
|
+
for needle in ("past 90%", "past 95%"):
|
|
1048
|
+
told = {role: patrol_told(repo, role, needle) for role in ("pm-a", "pm-b")}
|
|
1049
|
+
if told != {"pm-a": 1, "pm-b": 0}:
|
|
1050
|
+
report(f"{label} the {needle!r} quota risk reached {told}, not pm-a once.")
|
|
1051
|
+
return 1
|
|
1052
|
+
old = time.time() - 7 * 3600
|
|
1053
|
+
os.utime(quota, (old, old))
|
|
1054
|
+
stale = due_tick(repo, env, wt, state)
|
|
1055
|
+
if not any("quota" in line and "stale" in line for line in stale.stdout.splitlines()):
|
|
1056
|
+
report(f"{label} a quota file 7 hours old is not reported stale: {stale.stdout!r}")
|
|
1057
|
+
return 1
|
|
1058
|
+
|
|
1059
|
+
repo, env, wt, state = tick_scopes_scratch(base / "undeclared")
|
|
1060
|
+
first = due_tick(repo, env, wt, state)
|
|
1061
|
+
if "quota is not checked" not in first.stdout:
|
|
1062
|
+
report(f"{label} with no quota_file the tick does not say quota is not checked: {first.stdout!r}")
|
|
1063
|
+
return 1
|
|
1064
|
+
second = due_tick(repo, env, wt, state)
|
|
1065
|
+
if any("quota" in line for line in second.stdout.splitlines()):
|
|
1066
|
+
report(f"{label} the tick repeats an unchanged quota state: {second.stdout!r}")
|
|
1067
|
+
return 1
|
|
1068
|
+
report("tick-reads-quota-file scenario passed.")
|
|
1069
|
+
return 0
|
|
1070
|
+
|
|
1071
|
+
|
|
977
1072
|
def validate_patrol_nudge_scenario() -> int:
|
|
978
1073
|
"""Issues #307 part 1 and #313: the patrol nudges idle roles directly.
|
|
979
1074
|
|
package/src/core/config.js
CHANGED
|
@@ -1000,13 +1000,22 @@ function patrolItem(block) {
|
|
|
1000
1000
|
if (window) cadence.quiet = { start: Number(window[1]) * 60 + Number(window[2]), end: Number(window[3]) * 60 + Number(window[4]) };
|
|
1001
1001
|
else ignored.push(`quiet \`${block.quiet}\` is not a window such as 23:00-08:30`);
|
|
1002
1002
|
}
|
|
1003
|
+
// What `keel tick` passes the patrol (#456 D2): the free-disk floor, and the
|
|
1004
|
+
// file a status line writes the weekly quota percent to. Keel runs nothing to
|
|
1005
|
+
// read quota.
|
|
1006
|
+
let diskMinGb = null;
|
|
1007
|
+
if (block.disk_min_gb !== undefined) {
|
|
1008
|
+
if (Number(block.disk_min_gb) > 0) diskMinGb = Number(block.disk_min_gb);
|
|
1009
|
+
else ignored.push(`disk_min_gb \`${block.disk_min_gb}\` is not a positive number of gigabytes`);
|
|
1010
|
+
}
|
|
1011
|
+
const quotaFile = block.quota_file !== undefined ? String(block.quota_file).replace(/^["']|["']$/g, "") : null;
|
|
1003
1012
|
// `runner: tick` says `keel tick` runs the patrol from the host scheduler.
|
|
1004
1013
|
let runner = null;
|
|
1005
1014
|
if (block.runner !== undefined) {
|
|
1006
1015
|
if (block.runner === "tick") runner = "tick";
|
|
1007
1016
|
else ignored.push(`runner \`${block.runner}\` is not tick`);
|
|
1008
1017
|
}
|
|
1009
|
-
return { declaration: { declared: true, role: block.role, every: block.every, hostTask, model, cadence, runner, scope }, ignored };
|
|
1018
|
+
return { declaration: { declared: true, role: block.role, every: block.every, hostTask, model, cadence, runner, scope, diskMinGb, quotaFile }, ignored };
|
|
1010
1019
|
}
|
|
1011
1020
|
|
|
1012
1021
|
function readPatrolDeclarations(repo) {
|
package/src/core/tick.js
CHANGED
|
@@ -45,6 +45,38 @@ function patrolWorktrees(where) {
|
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
// Free space on a worktree's filesystem in GiB, as `df -g` reports it (#456 D1).
|
|
49
|
+
function freeDiskGb(dir) {
|
|
50
|
+
try {
|
|
51
|
+
const stats = fs.statfsSync(dir);
|
|
52
|
+
return { gb: Math.floor((Number(stats.bavail) * Number(stats.bsize)) / 2 ** 30), error: null };
|
|
53
|
+
} catch (error) {
|
|
54
|
+
return { gb: null, error: error.message };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const QUOTA_MAX_AGE_MS = 6 * 3600 * 1000;
|
|
59
|
+
|
|
60
|
+
function readQuota(where, declared, now) {
|
|
61
|
+
if (!declared) return { state: "unchecked", percent: null, text: "quota is not checked: no `patrol:` item declares quota_file" };
|
|
62
|
+
const file = path.resolve(where.worktree, declared.replace(/^~(?=\/|$)/, os.homedir()));
|
|
63
|
+
let stat;
|
|
64
|
+
let body;
|
|
65
|
+
try {
|
|
66
|
+
stat = fs.statSync(file);
|
|
67
|
+
body = fs.readFileSync(file, "utf8");
|
|
68
|
+
} catch (error) {
|
|
69
|
+
return { state: "unreadable", percent: null, text: `quota file ${file} cannot be read (${error.code || error.message}), so quota is not checked` };
|
|
70
|
+
}
|
|
71
|
+
if (now.getTime() - stat.mtimeMs > QUOTA_MAX_AGE_MS) {
|
|
72
|
+
return { state: "stale", percent: null, text: `quota file ${file} is stale, last written ${store.isoLocal(stat.mtime)}, so quota is not checked` };
|
|
73
|
+
}
|
|
74
|
+
const number = body.match(/\d+(?:\.\d+)?/);
|
|
75
|
+
if (!number) return { state: "unreadable", percent: null, text: `quota file ${file} holds no number, so quota is not checked` };
|
|
76
|
+
const percent = Math.round(Number(number[0]));
|
|
77
|
+
return { state: "read", percent, text: `quota is read from ${file} (${percent}%)` };
|
|
78
|
+
}
|
|
79
|
+
|
|
48
80
|
function patrolWorktree(where) {
|
|
49
81
|
const all = patrolWorktrees(where);
|
|
50
82
|
return all.find((found) => found.worktree) || all[0];
|
|
@@ -89,6 +121,20 @@ function tick(where, now = new Date()) {
|
|
|
89
121
|
const all = patrolWorktrees(where);
|
|
90
122
|
const listed = all.length > 1;
|
|
91
123
|
const state = readState(where);
|
|
124
|
+
// Repository-wide settings come from the first item declaring each (#456 D2);
|
|
125
|
+
// every run gets them, and the patrol decides who reports (#434 D4).
|
|
126
|
+
const declared = all.map((found) => found.declaration).filter(Boolean);
|
|
127
|
+
const diskMinGb = (declared.find((d) => d.diskMinGb) || {}).diskMinGb || null;
|
|
128
|
+
// Quota comes from a file the repository names, never from a command Keel
|
|
129
|
+
// runs (#456 D3, D4); its state is said when it changes, not every tick.
|
|
130
|
+
const quota = declared.length
|
|
131
|
+
? readQuota(where, (declared.find((d) => d.quotaFile) || {}).quotaFile || null, now)
|
|
132
|
+
: { state: null, percent: null };
|
|
133
|
+
if (quota.state && quota.state !== state.quota_state) {
|
|
134
|
+
result.quota = quota;
|
|
135
|
+
state.quota_state = quota.state;
|
|
136
|
+
store.writeJsonAtomic(where, stateFile(where), state);
|
|
137
|
+
}
|
|
92
138
|
result.patrols = all.map((found) => {
|
|
93
139
|
if (!found.worktree) return { role: found.declaration ? found.declaration.role : null, ran: false, why: found.why };
|
|
94
140
|
const role = found.declaration.role;
|
|
@@ -101,9 +147,12 @@ function tick(where, now = new Date()) {
|
|
|
101
147
|
// and the patrol still runs on the refs it has.
|
|
102
148
|
const fetched = spawnSync("git", ["-C", found.worktree, "fetch", "-q", "origin"], { encoding: "utf8" });
|
|
103
149
|
const fetchError = fetched.status === 0 ? null : String(fetched.stderr || fetched.error || "fetch failed").trim();
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
150
|
+
const args = [KEEL, "patrol", "--repo", found.worktree, "--since-last", "--notify", "--json"];
|
|
151
|
+
const disk = freeDiskGb(found.worktree);
|
|
152
|
+
if (disk.gb !== null) args.push("--disk-free-gb", String(disk.gb));
|
|
153
|
+
if (diskMinGb) args.push("--disk-min-gb", String(diskMinGb));
|
|
154
|
+
if (quota.percent !== null) args.push("--quota", String(quota.percent));
|
|
155
|
+
const ran = spawnSync(process.execPath, args, { cwd: found.worktree, encoding: "utf8" });
|
|
107
156
|
let payload = {};
|
|
108
157
|
try {
|
|
109
158
|
payload = JSON.parse(ran.stdout);
|
|
@@ -117,7 +166,7 @@ function tick(where, now = new Date()) {
|
|
|
117
166
|
store.writeJsonAtomic(where, stateFile(where), state);
|
|
118
167
|
return {
|
|
119
168
|
role, listed, ran: true, exit: ran.status, next_at: next, rule: payload.next_rule || null,
|
|
120
|
-
fetchError, error: ran.status === 1 ? String(ran.stderr || "").trim() : null,
|
|
169
|
+
fetchError, diskError: disk.error, error: ran.status === 1 ? String(ran.stderr || "").trim() : null,
|
|
121
170
|
};
|
|
122
171
|
});
|
|
123
172
|
result.patrol = result.patrols[0];
|
|
@@ -127,13 +176,15 @@ function tick(where, now = new Date()) {
|
|
|
127
176
|
function render(result) {
|
|
128
177
|
const woke = (result.woken || []).map((w) => `keel tick: ${w.ok ? "resumed" : "could not resume"} ${w.role}'s CLI session ${w.session} for ${w.record}`);
|
|
129
178
|
const handed = (result.handedOver || []).map((h) => `keel tick: ${h.role}'s hand-off ${h.state}${h.new_session ? ` as session ${h.new_session}` : ""}${h.error ? `: ${h.error}` : ""}`);
|
|
130
|
-
|
|
179
|
+
const quota = result.quota ? [`keel tick: ${result.quota.text}`] : [];
|
|
180
|
+
return [...handed, ...woke, ...quota, ...(result.patrols || [result.patrol]).map(renderPatrol)].join("\n");
|
|
131
181
|
}
|
|
132
182
|
|
|
133
183
|
function renderPatrol(p) {
|
|
134
184
|
if (!p.ran) return `keel tick: ${p.why}`;
|
|
135
185
|
const lines = [`keel tick: ran ${p.listed ? `${p.role}'s` : "the"} patrol (exit ${p.exit})${p.next_at ? `; next ${p.next_at} (${p.rule})` : ""}`];
|
|
136
186
|
if (p.fetchError) lines.push(`fetch failed: ${p.fetchError}`);
|
|
187
|
+
if (p.diskError) lines.push(`free disk not measured: ${p.diskError}`);
|
|
137
188
|
if (p.error) lines.push(`patrol failed: ${p.error}`);
|
|
138
189
|
return lines.join("\n");
|
|
139
190
|
}
|