@christang/keel 5.99.2 → 5.99.4

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.
@@ -1,4 +1,4 @@
1
- <!-- keel:start version=5.99.2 -->
1
+ <!-- keel:start version=5.99.4 -->
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.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@christang/keel",
3
- "version": "5.99.2",
3
+ "version": "5.99.4",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@christang/keel",
9
- "version": "5.99.2",
9
+ "version": "5.99.4",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@fission-ai/openspec": "^1.4.1"
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.99.2",
5
+ "version": "5.99.4",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keel",
3
- "version": "5.99.2",
3
+ "version": "5.99.4",
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.99.2",
3
+ "version": "5.99.4",
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",
@@ -47,8 +47,8 @@ REQUIRED_SCRIPTS = [
47
47
  "scripts/validate_plugin.py",
48
48
  ]
49
49
 
50
- PACKAGE_VERSION = "5.99.2"
51
- PROTOCOL_VERSION = "5.99.2"
50
+ PACKAGE_VERSION = "5.99.4"
51
+ PROTOCOL_VERSION = "5.99.4"
52
52
  LEGACY_MANAGED_START = "<!-- keel:start version=2.1 -->"
53
53
  OPENSPEC_SCHEMA_NAME = "keel-spec-driven"
54
54
  # Mirrors KEEL_PACKAGE_NAME in scripts/install_to_repo.py, one of the two
@@ -5469,6 +5469,47 @@ def validate_record_derives_skeleton_scenario() -> int:
5469
5469
  report(f"{label} --record did not add the missing M1.red slot beside the kept M1.")
5470
5470
  return 1
5471
5471
 
5472
+ # Issue #236: added slots land in template order, not at the block's end.
5473
+ def evidence_lines(text: str) -> list[str]:
5474
+ lines = text.splitlines()
5475
+ start = lines.index(" - Evidence:") + 1
5476
+ end = next((i for i in range(start, len(lines)) if not lines[i].startswith(" ")), len(lines))
5477
+ return lines[start:end]
5478
+
5479
+ logs_first = red_green.replace(
5480
+ " - Stop if:\n",
5481
+ " - Evidence:\n - Contract: pending\n - Blocker: none\n - Reauthorizations: none\n - Stop if:\n",
5482
+ )
5483
+ write_text(tasks, logs_first)
5484
+ code, payload = record("--record", "--no-guard")
5485
+ if code != 0:
5486
+ report(f"{label} --record refused a block holding Contract, Blocker and Reauthorizations: "
5487
+ f"{payload.get('problems')!r}")
5488
+ return 1
5489
+ fingerprint = payload["contract"]["fingerprint"]["value"]
5490
+ got = evidence_lines(tasks.read_text(encoding="utf-8"))
5491
+ want = [f" - Contract: keel-task-capsule/v1 sha256:{fingerprint}", *expected_slots]
5492
+ if got != want:
5493
+ report(f"{label} --record over Contract, Blocker and Reauthorizations left the block out of "
5494
+ f"template order: {got!r}, expected {want!r}.")
5495
+ return 1
5496
+ before_review = red_green.replace(
5497
+ " - Stop if:\n",
5498
+ " - Evidence:\n - M1: pass. node test.js printed ok.\n - Review:\n - Status: pending\n"
5499
+ " - Acceptance check: pending\n - Scope check: pending\n - Findings: pending\n"
5500
+ " - Stop if:\n",
5501
+ )
5502
+ write_text(tasks, before_review)
5503
+ code, payload = record("--record", "--no-guard")
5504
+ if code != 0:
5505
+ report(f"{label} --record refused a block holding M1 and Review: {payload.get('problems')!r}")
5506
+ return 1
5507
+ got = evidence_lines(tasks.read_text(encoding="utf-8"))
5508
+ at = got.index(" - M1: pass. node test.js printed ok.")
5509
+ if got[at + 1:at + 3] != [" - M1.red: pending", " - M1.green: pending"]:
5510
+ report(f"{label} --record did not place M1.red and M1.green directly after the kept M1: {got!r}")
5511
+ return 1
5512
+
5472
5513
  write_text(tasks, no_evidence)
5473
5514
  code, payload = record("--record", "--no-guard")
5474
5515
  text = tasks.read_text(encoding="utf-8")
@@ -36710,6 +36751,37 @@ def validate_external_agent_brief_scenario() -> int:
36710
36751
  if needle not in command:
36711
36752
  report(f"{label} the implementation command does not name {needle!r}: {command}")
36712
36753
  return 1
36754
+ # Issue #262: a helper worktree beside the session's, under .claude/worktrees/.
36755
+ session_tree = repo / ".claude" / "worktrees" / "review"
36756
+ helper_tree = repo / ".claude" / "worktrees" / "dsh_review"
36757
+ # A real project commits its external_agents: declaration, so worktrees carry it.
36758
+ for command in (["add", "-A"], ["-c", "user.email=k@example.com", "-c", "user.name=k",
36759
+ "commit", "-q", "-m", "declare external agents"]):
36760
+ subprocess.run(["git", *command], cwd=repo, check=True, capture_output=True)
36761
+ for tree in (session_tree, helper_tree):
36762
+ subprocess.run(["git", "worktree", "add", "-q", "--detach", str(tree)],
36763
+ cwd=repo, check=True, capture_output=True)
36764
+
36765
+ def helper_brief(cwd: Path) -> tuple[dict, str]:
36766
+ if prompt.exists():
36767
+ prompt.unlink()
36768
+ result = run_keel(cwd, "agents", "brief", "dsh", "--mode", "helper",
36769
+ "--dir", str(helper_tree), "--out", str(prompt),
36770
+ "--change", "demo", "--task", "1.1", "--json", env=env)
36771
+ try:
36772
+ return json.loads(result.stdout), result.stdout + result.stderr
36773
+ except json.JSONDecodeError:
36774
+ return {}, result.stdout + result.stderr
36775
+
36776
+ payload, out = helper_brief(session_tree)
36777
+ if payload.get("status") != "ready":
36778
+ report(f"{label} a helper worktree under .claude/worktrees/ was refused from a sibling worktree: "
36779
+ f"{out.strip()[:600]}")
36780
+ return 1
36781
+ payload, out = helper_brief(helper_tree)
36782
+ if not refused(payload, out, str(helper_tree.resolve()), "current directory", "--repo",
36783
+ what="a helper brief run from inside its own --dir"):
36784
+ return 1
36713
36785
  if calls.exists():
36714
36786
  report(f"{label} an agent was launched: {calls.read_text(encoding='utf-8').strip()}")
36715
36787
  return 1
@@ -341,7 +341,7 @@ function realpath(file) {
341
341
  // git common directory. The host's write guard is a hook on the host's own tool
342
342
  // calls, so a process the session launches writes past it; the checkout it runs
343
343
  // in is then the only write boundary there is.
344
- function worktreeRefusal(repo, dir) {
344
+ function worktreeRefusal(repo, dir, repoGiven) {
345
345
  const top = git(dir, "rev-parse", "--show-toplevel");
346
346
  const common = git(dir, "rev-parse", "--path-format=absolute", "--git-common-dir");
347
347
  const ownTop = git(repo, "rev-parse", "--show-toplevel");
@@ -353,10 +353,14 @@ function worktreeRefusal(repo, dir) {
353
353
  if (realpath(common) !== realpath(ownCommon)) {
354
354
  return `--dir ${dir} belongs to a different repository. ${how}`;
355
355
  }
356
+ // Keel cannot see the session's checkout, only the one it was pointed at
357
+ // (#262): name that one and how it was chosen, rather than claim the session's.
356
358
  if (realpath(top) === realpath(ownTop)) {
359
+ const from = repoGiven ? "named by --repo" : "the one containing the current directory";
357
360
  return (
358
- `--dir ${dir} is this session's own checkout. The write guard does not reach an external `
359
- + `process, so it needs a separate worktree of this repository. ${how}`
361
+ `--dir ${dir} is the checkout this command runs in, ${realpath(ownTop)} (${from}). `
362
+ + "The write guard does not reach an external process, so it needs a separate worktree "
363
+ + `of this repository. Run this from the session's own checkout, or pass --repo <it>. ${how}`
360
364
  );
361
365
  }
362
366
  return null;
@@ -485,7 +489,7 @@ function compileBrief(repo, options) {
485
489
  const dir = path.resolve(options.dir);
486
490
  const needsWorktree = options.mode === "implementation" || !entry.sandbox.helper;
487
491
  if (needsWorktree) {
488
- const refusal = worktreeRefusal(repo, dir);
492
+ const refusal = worktreeRefusal(repo, dir, options.repoGiven);
489
493
  if (refusal) {
490
494
  const why = options.mode === "implementation" ? ""
491
495
  : `${entry.name} offers no read-only sandbox, so even a helper run needs a separate worktree. `;
@@ -538,8 +542,10 @@ function runBrief(argv) {
538
542
  for (let index = 0; index < argv.length; index += 1) {
539
543
  const arg = argv[index];
540
544
  if (arg === "--json") json = true;
541
- else if (arg === "--repo") repo = argv[++index] || "";
542
- else if (flags[arg]) options[flags[arg]] = argv[++index] || "";
545
+ else if (arg === "--repo") {
546
+ repo = argv[++index] || "";
547
+ options.repoGiven = true;
548
+ } else if (flags[arg]) options[flags[arg]] = argv[++index] || "";
543
549
  else if (options.name === null && !arg.startsWith("-")) options.name = arg;
544
550
  else {
545
551
  process.stderr.write(`keel agents brief: unexpected argument ${arg}\n${BRIEF_USAGE}\n`);
package/src/core/gates.js CHANGED
@@ -414,10 +414,12 @@ function equivalenceEscapeProblems(repo, selection, task, compiled) {
414
414
  const EVIDENCE_FIELD = /^ {2}- Evidence:\s*$/;
415
415
  const TASK_FIELD = /^ {2}- [A-Za-z][A-Za-z /-]+:/;
416
416
 
417
+ const EVIDENCE_SLOT = /^ {4}- ([A-Za-z][\w.]*(?: [a-z]+)*):/;
418
+
417
419
  function evidenceSlotKeys(lines) {
418
420
  return new Set(
419
421
  lines
420
- .map((line) => line.match(/^ {4}- ([A-Za-z][\w.]*(?: [a-z]+)*):/))
422
+ .map((line) => line.match(EVIDENCE_SLOT))
421
423
  .filter(Boolean)
422
424
  .map((match) => match[1])
423
425
  );
@@ -445,17 +447,35 @@ function withEvidenceSlots(content, task, slots) {
445
447
  }
446
448
  const scanFrom = header >= 0 ? header + 1 : end;
447
449
  const present = evidenceSlotKeys(lines.slice(scanFrom, blockEnd));
450
+ if (slots.every((slot) => present.has(slot.key))) return { content, added: [] };
451
+ if (header < 0) {
452
+ let insertAt = end;
453
+ while (insertAt > task.line + 1 && !lines[insertAt - 1].trim()) insertAt -= 1;
454
+ const insertion = [" - Evidence:", ...slots.flatMap((slot) => slot.lines)];
455
+ lines.splice(insertAt, 0, ...insertion);
456
+ return { content: lines.join(eol), added: insertion };
457
+ }
458
+ // Template order (#236): a missing slot goes directly after the last slot
459
+ // already placed, present or just added, or first in the block; present
460
+ // slots never move.
448
461
  const added = [];
462
+ let cursor = scanFrom;
449
463
  for (const slot of slots) {
450
- if (present.has(slot.key)) continue;
464
+ const at = lines.slice(scanFrom, blockEnd).findIndex((line) => {
465
+ const match = line.match(EVIDENCE_SLOT);
466
+ return match && match[1] === slot.key;
467
+ });
468
+ if (at >= 0) {
469
+ cursor = scanFrom + at + 1;
470
+ while (cursor < blockEnd && !EVIDENCE_SLOT.test(lines[cursor]) && /^ {5,}\S/.test(lines[cursor])) cursor += 1;
471
+ continue;
472
+ }
473
+ lines.splice(cursor, 0, ...slot.lines);
451
474
  added.push(...slot.lines);
475
+ cursor += slot.lines.length;
476
+ blockEnd += slot.lines.length;
452
477
  }
453
- if (added.length === 0) return { content, added };
454
- let insertAt = header >= 0 ? blockEnd : end;
455
- while (insertAt > task.line + 1 && !lines[insertAt - 1].trim()) insertAt -= 1;
456
- const insertion = header >= 0 ? added : [" - Evidence:", ...added];
457
- lines.splice(insertAt, 0, ...insertion);
458
- return { content: lines.join(eol), added: insertion };
478
+ return { content: lines.join(eol), added };
459
479
  }
460
480
 
461
481
  function basicSlots(task) {