@christang/keel 5.71.0 → 5.73.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -271,8 +271,11 @@ designed to — resist widening the policy until it stops happening.
271
271
  ### Who merges
272
272
 
273
273
  Keel never lets the agent merge — an unattended run opens a pull request and stops. A repository can
274
- still merge without a person, on a rule of its own: GitHub auto-merge behind a required status check.
275
- If yours does, say so:
274
+ still merge without a person, on a rule of its own: GitHub auto-merge behind a required status check,
275
+ or a workflow job that merges what passed. Keel's own repository does the second — the `land` job in
276
+ `.github/workflows/publish.yml` merges the owner's pull request once `full-gate` passed on its head
277
+ commit, then publishes and releases the version in the same run, with no stored secret. If your
278
+ repository merges on its own, say so:
276
279
 
277
280
  ```yaml
278
281
  merge: repository:full-gate
@@ -284,8 +287,8 @@ because the only thing the protocol says about merging is that the agent may not
284
287
 
285
288
  `merge: human` says the opposite. A bare `repository` is refused — "nobody reviews this" is only honest
286
289
  beside what replaced the reviewer. It is not a permission: `authorize:` has no `merge` entry and should
287
- not gain one. Keel reads the declaration and never GitHub, so it cannot check that auto-merge is really
288
- on; it reports what you declared.
290
+ not gain one. Keel reads the declaration and never GitHub, so it cannot check that your repository really
291
+ merges that way; it reports what you declared.
289
292
 
290
293
  ### Full vs Lite
291
294
 
@@ -1,4 +1,4 @@
1
- <!-- keel:start version=5.71.0 -->
1
+ <!-- keel:start version=5.73.0 -->
2
2
  ## Keel Bootstrap
3
3
 
4
4
  - Start every session with `keel context`; OpenSpec artifacts and Git are the only durable authority — never native memory, goals, or transcripts.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@christang/keel",
3
3
  "displayName": "Keel",
4
4
  "description": "Keel OpenSpec execution discipline CLI for Claude Code, Codex, and OpenCode.",
5
- "version": "5.71.0",
5
+ "version": "5.73.0",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keel",
3
- "version": "5.71.0",
3
+ "version": "5.73.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.71.0",
3
+ "version": "5.73.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",
@@ -38,8 +38,8 @@ REQUIRED_SCRIPTS = [
38
38
  "scripts/validate_plugin.py",
39
39
  ]
40
40
 
41
- PACKAGE_VERSION = "5.71.0"
42
- PROTOCOL_VERSION = "5.71.0"
41
+ PACKAGE_VERSION = "5.73.0"
42
+ PROTOCOL_VERSION = "5.73.0"
43
43
  LEGACY_MANAGED_START = "<!-- keel:start version=2.1 -->"
44
44
  OPENSPEC_SCHEMA_NAME = "keel-spec-driven"
45
45
  # Mirrors KEEL_PACKAGE_NAME in scripts/install_to_repo.py, one of the two
@@ -5031,6 +5031,71 @@ def validate_section_boundary_scenario() -> int:
5031
5031
  report(repr(problems_of(unstarted["tail"])))
5032
5032
  return 1
5033
5033
 
5034
+ # Cells 5 and 6: the heading half of the boundary, in the tail, where
5035
+ # it is the only half that applies. An indented `##` line inside the
5036
+ # section's own body is not a heading, and the entry after it must still
5037
+ # be judged. The tolerant spelling `parseTasks()` uses for task bodies
5038
+ # ends the section there and drops that entry without a word — issue
5039
+ # #160, measured on the abandoned first attempt at #71 as `7bd6448`.
5040
+ # Both readers are covered because each slices its own section.
5041
+ indented = " ## an indented line is not a heading\n"
5042
+ indented_invalidates = (
5043
+ "## Invalidates\n\n"
5044
+ '- I1: "the wording that is now wrong" — README.md. Updated by: 1.1\n'
5045
+ + indented
5046
+ + '- I2: "wording nothing updates" — README.md.\n'
5047
+ )
5048
+ payload = start(
5049
+ "invalidates-indented-tail",
5050
+ section_boundary_tasks_md(
5051
+ section=indented_invalidates, task=start_task, position="tail"
5052
+ ),
5053
+ )
5054
+ if not readable(payload, "invalidates-indented-tail", "task-start"):
5055
+ return 1
5056
+ if not [
5057
+ message
5058
+ for message in closure_problems(payload, "invalidation-closure")
5059
+ if "I2" in message
5060
+ ]:
5061
+ report(
5062
+ f"{label} accepted an invalidation that closes nothing because "
5063
+ "it follows an indented `##` line; the section ended at a line "
5064
+ "that is not a heading."
5065
+ )
5066
+ report(repr(payload.get("problems")))
5067
+ return 1
5068
+
5069
+ indented_coverage = (
5070
+ "## Invalidates\n\n- None.\n\n"
5071
+ "## Expectation Coverage\n\n"
5072
+ "- E1: The task owns its file. Covered by: 1.1\n"
5073
+ + indented
5074
+ + "- E3: Nothing closes this one.\n"
5075
+ )
5076
+ payload = close(
5077
+ "coverage-indented-tail",
5078
+ section_boundary_tasks_md(
5079
+ section=indented_coverage,
5080
+ task=section_boundary_task("1.1", checked=True),
5081
+ position="tail",
5082
+ ),
5083
+ )
5084
+ if not readable(payload, "coverage-indented-tail", "change-close"):
5085
+ return 1
5086
+ if not [
5087
+ message
5088
+ for message in closure_problems(payload, "expectation-closure")
5089
+ if "E3" in message
5090
+ ]:
5091
+ report(
5092
+ f"{label} accepted an expectation that closes nothing because "
5093
+ "it follows an indented `##` line; the section ended at a line "
5094
+ "that is not a heading."
5095
+ )
5096
+ report(repr(payload.get("problems")))
5097
+ return 1
5098
+
5034
5099
  report(f"{label} scenario passed.")
5035
5100
  return 0
5036
5101
 
@@ -10016,6 +10081,48 @@ def validate_task_body_ends_at_heading_scenario() -> int:
10016
10081
  "preceding task's fields."
10017
10082
  )
10018
10083
  return 1
10084
+ # An indented `##` line is not a heading — issue #160. The tolerant
10085
+ # test ended the task there, and a field declared after it with a
10086
+ # documented default was replaced by that default without a word: the
10087
+ # stop rule below vanished and task-start still passed. The fields are
10088
+ # ordered so the dropped one is exactly such a field.
10089
+ write_text(
10090
+ repo / "openspec/changes/indented/tasks.md",
10091
+ header
10092
+ + "- [ ] 1.1 Exercise task contract\n"
10093
+ " - Covers:\n"
10094
+ " - E1: Public behavior passes.\n"
10095
+ " - Touch:\n"
10096
+ " - src/feature.js\n"
10097
+ " - Verify:\n"
10098
+ " - Strategy: evidence-first\n"
10099
+ " - Reason: this is a gate fixture; it exercises contract structure and has no executable behavior that can fail first\n"
10100
+ " - M1: node test.js asserts the recorded feed status\n"
10101
+ " - Evidence:\n"
10102
+ " - Contract: pending\n"
10103
+ " - M1: pending\n"
10104
+ " - Acceptance:\n"
10105
+ " - Public behavior passes.\n"
10106
+ " ## an indented line is not a heading\n"
10107
+ " - Stop Rules:\n"
10108
+ " - Stop on the rule declared after the indented line.\n"
10109
+ "\n## Invalidates\n\n- None.\n",
10110
+ )
10111
+ indented = json.loads(
10112
+ run_keel(
10113
+ repo, "gate", "task-start", "--change", "indented", "--task",
10114
+ "1.1", "--no-guard", "--json",
10115
+ ).stdout
10116
+ )
10117
+ if "Stop on the rule declared after the indented line." not in json.dumps(
10118
+ indented
10119
+ ):
10120
+ report(
10121
+ "task-body-ends-at-heading: task-start dropped the fields "
10122
+ "declared after an indented `##` line; the task ended at a line "
10123
+ f"that is not a heading (status {indented.get('status')!r})."
10124
+ )
10125
+ return 1
10019
10126
  # --record must anchor the last task's own Contract line, not the stray
10020
10127
  # one planted in the trailing section.
10021
10128
  recorded = run_keel(
@@ -29777,6 +29884,13 @@ def publish_serialization_problem(workflow: str) -> str | None:
29777
29884
  "release would cancel a publish still waiting to run, losing that "
29778
29885
  "version outright rather than appearing to."
29779
29886
  )
29887
+ if not re.search(r"^[ \t]+queue:\s*max\s*$", body, re.M):
29888
+ return (
29889
+ "a pending publish would be cancelled by the next one — the group "
29890
+ "declares no `queue: max`, and the default `queue: single` keeps one "
29891
+ "pending run and cancels it when a newer one arrives, so a burst of "
29892
+ "three releases drops the middle version (#157)."
29893
+ )
29780
29894
  group = re.search(r"^[ \t]+group:\s*(\S.*?)\s*$", body, re.M)
29781
29895
  if not group:
29782
29896
  return (
@@ -29835,6 +29949,25 @@ def validate_a_publish_waits_for_the_one_before_it_scenario() -> int:
29835
29949
  )
29836
29950
  return 1
29837
29951
 
29952
+ # The pending half (#157). `cancel-in-progress: false` protects the running
29953
+ # publish; the default `queue: single` still cancels a pending one when a
29954
+ # newer run arrives, so a burst of three releases drops the middle version.
29955
+ # A copy without `queue: max` is exactly what 5.70.0 shipped.
29956
+ unqueued = workflow.replace(" queue: max\n", "")
29957
+ if unqueued == workflow:
29958
+ report(
29959
+ f"{label}: a pending publish would be cancelled by the next one — "
29960
+ "`queue: max` could not be located to remove, so the real file keeps "
29961
+ "at most one pending run and cancels the rest."
29962
+ )
29963
+ return 1
29964
+ if not publish_serialization_problem(unqueued):
29965
+ report(
29966
+ f"{label}: a pending publish would be cancelled by the next one — a "
29967
+ "group without `queue: max` was accepted."
29968
+ )
29969
+ return 1
29970
+
29838
29971
  # M2 — the option whose default is wrong for this job. A check satisfied by
29839
29972
  # the block alone would pass on the configuration that loses a version
29840
29973
  # outright, which is worse than the one being fixed here.
@@ -30002,6 +30135,172 @@ def validate_a_merge_names_who_makes_it_scenario() -> int:
30002
30135
  return 0
30003
30136
 
30004
30137
 
30138
+ def workflow_job_block(workflow: str, job: str) -> str:
30139
+ """The text of one job under `jobs:`, up to the next job at the same indent."""
30140
+ match = re.search(
30141
+ r"^ " + re.escape(job) + r":\n((?:(?: [^\n]*|[ \t]*)\n)*)",
30142
+ workflow,
30143
+ re.M,
30144
+ )
30145
+ return match.group(1) if match else ""
30146
+
30147
+
30148
+ def landing_problem(workflow: str) -> str | None:
30149
+ """Return the problem the landing path in `publish.yml` has, or None.
30150
+
30151
+ Takes text so each broken shape can be planted. The workflow runs only on
30152
+ GitHub from the default branch; the repository's copy is the one input
30153
+ guaranteed to be correct, so a rule that only read it would never be seen to
30154
+ fire.
30155
+ """
30156
+ land = workflow_job_block(workflow, "land")
30157
+ if not land:
30158
+ return (
30159
+ f"merges without confirming full-gate — {PUBLISH_WORKFLOW} has no "
30160
+ "`land` job."
30161
+ )
30162
+ if "check_name=full-gate" not in land:
30163
+ return (
30164
+ "merges without confirming full-gate — the `land` job never reads "
30165
+ "the `full-gate` check-run on the head commit before merging."
30166
+ )
30167
+ if "--match-head-commit" not in land:
30168
+ return (
30169
+ "merges without confirming full-gate — the merge is not pinned to the "
30170
+ "tested head commit, so a push after the check could land untested."
30171
+ )
30172
+ if "actions/checkout" in land:
30173
+ return (
30174
+ "pull request code could run with a write token — the `land` job "
30175
+ "checks out code, and it runs in the base repository's context with "
30176
+ "write permission."
30177
+ )
30178
+ if '.user.login == \\"$OWNER\\"' not in land:
30179
+ return (
30180
+ "pull request code could run with a write token — the `land` job "
30181
+ "does not restrict itself to the repository owner's pull requests."
30182
+ )
30183
+ if '.head.repo.full_name == \\"$REPO\\"' not in land:
30184
+ return (
30185
+ "pull request code could run with a write token — the `land` job "
30186
+ "does not refuse pull requests from forks."
30187
+ )
30188
+ publish = workflow_job_block(workflow, "publish")
30189
+ published_at = publish.find("npm publish")
30190
+ released_at = publish.find("gh release create")
30191
+ if published_at < 0 or released_at < 0:
30192
+ return (
30193
+ "a failed publish would be left tagged and never retried — the "
30194
+ "`publish` job lacks `npm publish` or `gh release create`."
30195
+ )
30196
+ if released_at < published_at:
30197
+ return (
30198
+ "a failed publish would be left tagged and never retried — the "
30199
+ "`publish` job creates the tag and release before `npm publish`, and "
30200
+ "a tag is what tells the next run the version is already released."
30201
+ )
30202
+ return None
30203
+
30204
+
30205
+ def validate_the_repository_lands_what_passed_scenario() -> int:
30206
+ """#155 follow-up: the repository merges, not the agent, with no stored secret.
30207
+
30208
+ Events made with `GITHUB_TOKEN` start no new workflow runs, so a chain of
30209
+ workflows (merge, then release, then publish) needs a personal token at every
30210
+ hand-off. One run that merges, publishes and releases has no hand-off. The
30211
+ price is that the landing job runs with write permission in the base
30212
+ repository's context — so it must run no pull-request code, land only the
30213
+ owner's own pull requests, and merge only the commit `full-gate` passed.
30214
+ """
30215
+ label = "the-repository-lands-what-passed"
30216
+ workflow = (ROOT / PUBLISH_WORKFLOW).read_text(encoding="utf-8")
30217
+
30218
+ problem = landing_problem(workflow)
30219
+ if problem:
30220
+ report(f"{label}: {problem}")
30221
+ return 1
30222
+ land = workflow_job_block(workflow, "land")
30223
+ if not land:
30224
+ report(
30225
+ f"{label}: merges without confirming full-gate — {PUBLISH_WORKFLOW} "
30226
+ "has no `land` job, so nothing lands a pull request that passed."
30227
+ )
30228
+ return 1
30229
+
30230
+ # M1 — the check is read and the tested commit is what merges.
30231
+ for needle, why in (
30232
+ ("check_name=full-gate", "without reading the `full-gate` check-run"),
30233
+ ("--match-head-commit", "without pinning the merge to the tested head commit"),
30234
+ ):
30235
+ planted = workflow.replace(needle, "")
30236
+ if planted == workflow:
30237
+ report(f"{label}: merges without confirming full-gate — `{needle}` is absent.")
30238
+ return 1
30239
+ if not landing_problem(planted):
30240
+ report(
30241
+ f"{label}: merges without confirming full-gate — a landing job "
30242
+ f"that merges {why} was accepted."
30243
+ )
30244
+ return 1
30245
+
30246
+ # M2 — no pull-request code under a write token, and only the owner's own
30247
+ # pull requests from this repository. `workflow_run` and
30248
+ # `pull_request_target` run in the base repository's context with the
30249
+ # permissions the job asks for, so a checkout there hands the token to
30250
+ # whatever the pull request contains.
30251
+ checkout = workflow.replace(
30252
+ " - name: Land an owner's pull request whose head passed full-gate\n",
30253
+ " - uses: actions/checkout@v4\n"
30254
+ " - name: Land an owner's pull request whose head passed full-gate\n",
30255
+ )
30256
+ if checkout == workflow:
30257
+ report(f"{label}: pull request code could run with a write token — the land step could not be located.")
30258
+ return 1
30259
+ if not landing_problem(checkout):
30260
+ report(
30261
+ f"{label}: pull request code could run with a write token — a "
30262
+ "`land` job with a checkout step was accepted."
30263
+ )
30264
+ return 1
30265
+ for needle, why in (
30266
+ ('.user.login == \\"$OWNER\\"', "any author's pull request"),
30267
+ ('.head.repo.full_name == \\"$REPO\\"', "a pull request from a fork"),
30268
+ ):
30269
+ planted = workflow.replace(" and " + needle, "")
30270
+ if planted == workflow:
30271
+ report(f"{label}: pull request code could run with a write token — `{needle}` is absent.")
30272
+ return 1
30273
+ if not landing_problem(planted):
30274
+ report(
30275
+ f"{label}: pull request code could run with a write token — a "
30276
+ f"`land` job that would land {why} was accepted."
30277
+ )
30278
+ return 1
30279
+
30280
+ # M3 — publish before tagging. A tag is what tells the next run "already
30281
+ # released", so a tag created before a publish that then fails marks a version
30282
+ # released that never reached npm, and nothing would ever retry it.
30283
+ publish_step = workflow[workflow.index(" - name: Publish\n"):workflow.index(" - name: Tag and release the landed version\n")]
30284
+ tag_step = workflow[workflow.index(" - name: Tag and release the landed version\n"):]
30285
+ swapped = workflow.replace(publish_step + tag_step, tag_step.rstrip("\n") + "\n\n" + publish_step.rstrip("\n") + "\n")
30286
+ if swapped == workflow:
30287
+ report(f"{label}: a failed publish would be left tagged and never retried — the two steps could not be swapped.")
30288
+ return 1
30289
+ if not landing_problem(swapped):
30290
+ report(
30291
+ f"{label}: a failed publish would be left tagged and never retried — "
30292
+ "a `publish` job that creates the release before `npm publish` was "
30293
+ "accepted."
30294
+ )
30295
+ return 1
30296
+
30297
+ if label not in {name for name, _ in SCENARIOS}:
30298
+ report(f"{label}: the scenario registry does not include it.")
30299
+ return 1
30300
+ report(f"{label} scenario passed.")
30301
+ return 0
30302
+
30303
+
30005
30304
  SCENARIOS: tuple = (
30006
30305
  ("stateless-continuity", validate_stateless_continuity_scenario),
30007
30306
  ("core-gates", validate_core_gates_scenario),
@@ -30368,6 +30667,10 @@ SCENARIOS: tuple = (
30368
30667
  "an-equivalence-claim-names-its-base",
30369
30668
  validate_an_equivalence_claim_names_its_base_scenario,
30370
30669
  ),
30670
+ (
30671
+ "the-repository-lands-what-passed",
30672
+ validate_the_repository_lands_what_passed_scenario,
30673
+ ),
30371
30674
  (
30372
30675
  "a-merge-names-who-makes-it",
30373
30676
  validate_a_merge_names_who_makes_it_scenario,
package/src/core/gates.js CHANGED
@@ -13,6 +13,7 @@ const {
13
13
  declaredCommandLabels,
14
14
  field,
15
15
  isConcrete,
16
+ isHeadingLine,
16
17
  isPassingReviewStatus,
17
18
  parseTasks,
18
19
  unfilledToken,
@@ -1597,10 +1598,11 @@ function taskComplete(repo, options) {
1597
1598
  //
1598
1599
  // The task half is the task list already parsed for this file rather than a
1599
1600
  // second checkbox pattern, so it cannot drift from the boundary `parseTasks()`
1600
- // applies to a task's own body. The heading half stays as it was: the two
1601
- // spellings are not interchangeable, and unifying them truncates a tail-position
1602
- // section at an indented `##` line inside its own body, which is this same
1603
- // defect pointed the other way.
1601
+ // applies to a task's own body. The heading half is `isHeadingLine()`, the same
1602
+ // test `parseTasks()` uses. It must stay the column-zero one: the tolerant
1603
+ // spelling truncates a tail-position section at an indented `##` line inside
1604
+ // its own body and drops every entry after it, which is this same defect
1605
+ // pointed the other way (#160).
1604
1606
  function sectionBody(content, headingOffset, tasks) {
1605
1607
  const lines = content.split(/\r?\n/);
1606
1608
  const headingLine = content.slice(0, headingOffset).split(/\r?\n/).length - 1;
@@ -1609,7 +1611,7 @@ function sectionBody(content, headingOffset, tasks) {
1609
1611
  if (task.line > headingLine && task.line < end) end = task.line;
1610
1612
  }
1611
1613
  for (let cursor = headingLine + 1; cursor < end; cursor += 1) {
1612
- if (/^##\s+/.test(lines[cursor])) {
1614
+ if (isHeadingLine(lines[cursor])) {
1613
1615
  end = cursor;
1614
1616
  break;
1615
1617
  }
@@ -59,6 +59,17 @@ function unfilledToken(value) {
59
59
  return match ? match[0] : null;
60
60
  }
61
61
 
62
+ // A heading is a `##` line at column zero. An indented one is text: inside a
63
+ // task it belongs to the field that is open, inside a change-level section it
64
+ // is not an entry. Both readers decide through this one test — issue #160.
65
+ // The tolerant spelling `/^\s*##\s/` ended a task at an indented line and
66
+ // dropped every field after it, and a field with a documented default was
67
+ // replaced by that default without a word; in a section it dropped the entries
68
+ // after the line with no refusal at all.
69
+ function isHeadingLine(line) {
70
+ return /^##\s/.test(line);
71
+ }
72
+
62
73
  function parseTasks(content) {
63
74
  const lines = content.split(/\r?\n/);
64
75
  const tasks = [];
@@ -75,16 +86,17 @@ function parseTasks(content) {
75
86
  });
76
87
  }
77
88
  for (let index = 0; index < tasks.length; index += 1) {
78
- // A task body ends at the next task or the next `##` heading, whichever
79
- // comes first. Without the heading bound a change-level section such as
80
- // `## Invalidates` was appended to whichever field was open last — the
81
- // Evidence, in every shipped template — so a token quoted there made the
82
- // Evidence non-concrete and the gate blamed a task that was fine.
89
+ // A task body ends at the next task or the next `##` heading (see
90
+ // `isHeadingLine`), whichever comes first. Without the heading bound a
91
+ // change-level section such as `## Invalidates` was appended to whichever
92
+ // field was open last — the Evidence, in every shipped template — so a
93
+ // token quoted there made the Evidence non-concrete and the gate blamed a
94
+ // task that was fine.
83
95
  const nextTask =
84
96
  index + 1 < tasks.length ? tasks[index + 1].line : lines.length;
85
97
  let end = nextTask;
86
98
  for (let cursor = tasks[index].line + 1; cursor < nextTask; cursor += 1) {
87
- if (/^\s*##\s/.test(lines[cursor])) {
99
+ if (isHeadingLine(lines[cursor])) {
88
100
  end = cursor;
89
101
  break;
90
102
  }
@@ -1538,6 +1550,7 @@ module.exports = {
1538
1550
  isConcrete,
1539
1551
  isPassingReviewStatus,
1540
1552
  loadTaskContract,
1553
+ isHeadingLine,
1541
1554
  parseTasks,
1542
1555
  taskStartContractProblems,
1543
1556
  unfilledToken,