@christang/keel 5.147.0 → 5.149.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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keel",
3
- "version": "5.147.0",
3
+ "version": "5.149.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,4 +1,4 @@
1
- <!-- keel:start version=5.147.0 -->
1
+ <!-- keel:start version=5.149.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/bin/keel.js CHANGED
@@ -701,6 +701,51 @@ function npmCommand() {
701
701
  // further up. The `.bin` entry is the published contract between npm and a
702
702
  // consumer; resolving through the dependency's internal bin path instead would
703
703
  // bind Keel to a path that belongs to the dependency.
704
+ // An archive moves the change directory on the filesystem. A file Git tracked
705
+ // there stays tracked only at the path it was added at, so one that an ignore
706
+ // rule matches — evidence a change's own .gitignore excludes and was
707
+ // force-added — is dropped by the archive commit (#352). The files tracked
708
+ // before the move are recorded, and those the archived path leaves ignored are
709
+ // re-added afterwards.
710
+ function archiveTracking(repo, args) {
711
+ const name = args.slice(1).find((arg) => !arg.startsWith("-"));
712
+ if (!name || !/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(name)) return null;
713
+ const listed = spawnSync("git", ["ls-files", "-z", "--", `openspec/changes/${name}/`], { cwd: repo, encoding: "utf8" });
714
+ if (listed.error || listed.status !== 0) return null;
715
+ const prefix = `openspec/changes/${name}/`;
716
+ const files = listed.stdout.split("\0").filter((file) => file.startsWith(prefix)).map((file) => file.slice(prefix.length));
717
+ return files.length > 0 ? { name, files } : null;
718
+ }
719
+
720
+ function keepArchivedTracked(repo, tracking) {
721
+ const archive = path.join(repo, "openspec", "changes", "archive");
722
+ let entries = [];
723
+ try {
724
+ entries = fs.readdirSync(archive);
725
+ } catch {
726
+ return;
727
+ }
728
+ const dirs = entries.filter((entry) => entry === tracking.name || entry.endsWith(`-${tracking.name}`))
729
+ .map((entry) => path.join(archive, entry))
730
+ .filter((dir) => tracking.files.some((file) => fs.existsSync(path.join(dir, file))))
731
+ .sort((a, b) => fs.statSync(b).mtimeMs - fs.statSync(a).mtimeMs);
732
+ if (dirs.length === 0) return;
733
+ const moved = tracking.files.map((file) => path.relative(repo, path.join(dirs[0], file)).split(path.sep).join("/"))
734
+ .filter((file) => fs.existsSync(path.join(repo, file)));
735
+ if (moved.length === 0) return;
736
+ const ignored = spawnSync("git", ["check-ignore", "--no-index", "-z", "--stdin"], {
737
+ cwd: repo, encoding: "utf8", input: `${moved.join("\0")}\0`,
738
+ });
739
+ const dropped = ignored.status === 0 ? ignored.stdout.split("\0").filter(Boolean) : [];
740
+ if (dropped.length === 0) return;
741
+ const added = spawnSync("git", ["add", "-f", "--", ...dropped], { cwd: repo, encoding: "utf8" });
742
+ if (added.error || added.status !== 0) {
743
+ process.stderr.write(`keel: ${dropped.length} tracked file(s) the archive move left ignored could not be re-added; run git add -f on them (#352)\n`);
744
+ return;
745
+ }
746
+ process.stdout.write(`keel: re-added ${dropped.length} tracked file(s) the archive move left ignored (#352)\n`);
747
+ }
748
+
704
749
  function openspecBinNames() {
705
750
  return process.platform === "win32"
706
751
  ? ["openspec.cmd", "openspec.exe", "openspec"]
@@ -2695,7 +2740,9 @@ function runAction(options) {
2695
2740
  );
2696
2741
  return 1;
2697
2742
  }
2743
+ const archiving = options.openspecArgs[0] === "archive" ? archiveTracking(process.cwd(), options.openspecArgs) : null;
2698
2744
  const status = runCommand(openspec, options.openspecArgs, { stdio: "inherit" });
2745
+ if (status === 0 && archiving) keepArchivedTracked(process.cwd(), archiving);
2699
2746
  if (status !== 0 || options.openspecArgs[0] !== "update") return status;
2700
2747
  const repo = process.cwd();
2701
2748
  for (const target of installedOpenSpecTargets(repo)) {
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@christang/keel",
3
- "version": "5.147.0",
3
+ "version": "5.149.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@christang/keel",
9
- "version": "5.147.0",
9
+ "version": "5.149.0",
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.147.0",
5
+ "version": "5.149.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.147.0",
3
+ "version": "5.149.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.147.0",
3
+ "version": "5.149.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",
@@ -49,8 +49,8 @@ REQUIRED_SCRIPTS = [
49
49
  "scripts/validate_plugin.py",
50
50
  ]
51
51
 
52
- PACKAGE_VERSION = "5.147.0"
53
- PROTOCOL_VERSION = "5.147.0"
52
+ PACKAGE_VERSION = "5.149.0"
53
+ PROTOCOL_VERSION = "5.149.0"
54
54
  LEGACY_MANAGED_START = "<!-- keel:start version=2.1 -->"
55
55
  OPENSPEC_SCHEMA_NAME = "keel-spec-driven"
56
56
  # Mirrors KEEL_PACKAGE_NAME in scripts/install_to_repo.py, one of the two
@@ -2450,6 +2450,57 @@ def chat_scratch_group(base: Path) -> tuple[Path, Path, dict[str, str]]:
2450
2450
  return rtl, verify, env
2451
2451
 
2452
2452
 
2453
+ def validate_chat_mention_skips_code_scenario() -> int:
2454
+ """Issue #345: `keel chat post` refused a whole message over `@<commit-id>`
2455
+ or an `@word` inside backticks.
2456
+
2457
+ The refusal exists so a typo cannot post a message that reaches nobody;
2458
+ a commit id (`branch @ 638059e4`) and quoted text are not mentions.
2459
+ """
2460
+ label = "chat-mention-skips-code:"
2461
+ with tempfile.TemporaryDirectory(prefix="keel-chat-345-") as raw:
2462
+ base = Path(raw)
2463
+ rtl, _verify, env = chat_scratch_group(base)
2464
+
2465
+ def post(text: str) -> subprocess.CompletedProcess[str]:
2466
+ return run_keel(rtl, "chat", "post", "soc", text, "--json", env=env)
2467
+
2468
+ for name, text in (
2469
+ ("commit-id", "main moved: claude/x @638059e4 waiting for the push window"),
2470
+ ("long-commit-id", "landed @638059e4c0ffee1234567890abcdef12345678"),
2471
+ ("inline-code", "write it as `@verifyy` in the note"),
2472
+ ("fenced", "example:\n```\nkeel chat post soc @nobody hi\n```\nthat is all"),
2473
+ ):
2474
+ result = post(text)
2475
+ if result.returncode != 0:
2476
+ report(f"{label} a post with {name} was refused: {result.stdout!r} {result.stderr!r}")
2477
+ return 1
2478
+ mentions = chat_json(result).get("mentions", [])
2479
+ if mentions:
2480
+ report(f"{label} a post with {name} recorded mentions {mentions!r}.")
2481
+ return 1
2482
+
2483
+ typo = post("@verifyy please check")
2484
+ if typo.returncode == 0:
2485
+ report(f"{label} a bare typo is no longer refused: {typo.stdout!r}")
2486
+ return 1
2487
+ if "@verifyy is not a member" not in typo.stderr:
2488
+ report(f"{label} a bare typo's refusal does not name it: {typo.stderr!r}")
2489
+ return 1
2490
+ real = post("`@nobody` is quoted, @verify is asked")
2491
+ if real.returncode != 0:
2492
+ report(f"{label} a real mention beside quoted text was refused: {real.stderr!r}")
2493
+ return 1
2494
+ if chat_json(real).get("mentions") != ["verify"]:
2495
+ report(f"{label} a real mention beside quoted text was not recorded alone: {real.stdout!r}")
2496
+ return 1
2497
+ if "chat-mention-skips-code" not in {name for name, _ in SCENARIOS}:
2498
+ report(f"{label} scenario is not registered.")
2499
+ return 1
2500
+ report("chat-mention-skips-code scenario passed.")
2501
+ return 0
2502
+
2503
+
2453
2504
  def validate_chat_supersedes_scenario() -> int:
2454
2505
  """Issue #252: a record supersedes its author's earlier one.
2455
2506
 
@@ -39230,6 +39281,83 @@ def validate_a_claim_names_what_would_falsify_it_scenario() -> int:
39230
39281
  return 0
39231
39282
 
39232
39283
 
39284
+ def validate_archive_keeps_tracked_evidence_scenario() -> int:
39285
+ """Issue #352: archiving a change whose own .gitignore ignores tracked
39286
+ evidence dropped that evidence from version control.
39287
+
39288
+ The archive is a filesystem move; tracked files survive an ignore rule
39289
+ only at the path they were added at, so at the archived path they read as
39290
+ deleted-and-ignored and the archive commit removed them.
39291
+ `keel openspec archive` re-adds them, and `change-close --action archive`
39292
+ warns about them before any move.
39293
+ """
39294
+ label = "archive-keeps-tracked-evidence:"
39295
+ with tempfile.TemporaryDirectory(prefix="keel-archive-352-") as raw:
39296
+ tmp = Path(raw)
39297
+ repo = tmp / "repo"
39298
+ repo.mkdir()
39299
+
39300
+ def git(*args: str) -> subprocess.CompletedProcess[str]:
39301
+ return subprocess.run(["git", *args], cwd=repo, text=True, capture_output=True, check=False)
39302
+
39303
+ git("init", "-q")
39304
+ git("config", "user.email", "t@example.com")
39305
+ git("config", "user.name", "t")
39306
+ env = dict(os.environ)
39307
+ env["CODEX_HOME"] = str(tmp / "codex-home")
39308
+ init = run_keel(repo, "--init", "--target", "claude", env=env)
39309
+ if init.returncode:
39310
+ report(f"{label} init failed: {init.stderr or init.stdout}")
39311
+ return 1
39312
+ change = repo / "openspec/changes/demo"
39313
+ write_text(change / "proposal.md", "## Why\n\nfixture\n\n## What Changes\n\n- fixture\n")
39314
+ write_text(change / "tasks.md", "# Tasks\n\n- [x] 1.1 done\n")
39315
+ write_text(change / ".gitignore", "evidence/**\n")
39316
+ write_text(change / "evidence/run.log", "measured\n")
39317
+ git("add", "-A")
39318
+ git("add", "-f", "openspec/changes/demo/evidence/run.log")
39319
+ git("commit", "-q", "-m", "fixture")
39320
+ if "openspec/changes/demo/evidence/run.log" not in git("ls-files").stdout:
39321
+ report(f"{label} the fixture's evidence is not tracked.")
39322
+ return 1
39323
+
39324
+ # The gate sees it before any move.
39325
+ closing = run_keel(repo, "gate", "change-close", "--change", "demo", "--action", "archive", "--json", env=env)
39326
+ try:
39327
+ warnings = json.loads(closing.stdout).get("warnings", [])
39328
+ except json.JSONDecodeError:
39329
+ report(f"{label} change-close printed no JSON: {closing.stdout!r} {closing.stderr!r}")
39330
+ return 1
39331
+ warned = next((w for w in warnings if "evidence/run.log" in w), "")
39332
+ if not warned:
39333
+ report(f"{label} change-close --action archive does not warn about tracked evidence the change ignores: {warnings!r}")
39334
+ return 1
39335
+ if "keel openspec archive" not in warned:
39336
+ report(f"{label} the warning does not name the archive that keeps it: {warned!r}")
39337
+ return 1
39338
+
39339
+ archived = run_keel(repo, "openspec", "archive", "demo", "--yes", "--skip-specs", env=env)
39340
+ if archived.returncode:
39341
+ report(f"{label} keel openspec archive failed: {archived.stdout!r} {archived.stderr!r}")
39342
+ return 1
39343
+ moved = sorted((repo / "openspec/changes/archive").glob("*demo/evidence/run.log"))
39344
+ if len(moved) != 1:
39345
+ report(f"{label} the archive did not move the evidence: {sorted((repo / 'openspec/changes/archive').rglob('*'))!r}")
39346
+ return 1
39347
+ relative = moved[0].relative_to(repo).as_posix()
39348
+ if relative not in git("ls-files").stdout:
39349
+ report(f"{label} the archived evidence {relative} dropped out of version control: {archived.stdout!r}")
39350
+ return 1
39351
+ if "re-added 1" not in archived.stdout:
39352
+ report(f"{label} the archive does not say it re-added the tracked evidence: {archived.stdout!r}")
39353
+ return 1
39354
+ if "archive-keeps-tracked-evidence" not in {name for name, _ in SCENARIOS}:
39355
+ report(f"{label} scenario is not registered.")
39356
+ return 1
39357
+ report("archive-keeps-tracked-evidence scenario passed.")
39358
+ return 0
39359
+
39360
+
39233
39361
  def validate_a_listed_marker_opens_its_clause_scenario() -> int:
39234
39362
  """Issue #362: a disposition written as a sub-list item was read as prose.
39235
39363
 
@@ -41713,6 +41841,7 @@ SCENARIOS: tuple = (
41713
41841
  ("self-shift-authorization", validate_self_shift_authorization_scenario),
41714
41842
  ("resource-lock", validate_resource_lock_scenario),
41715
41843
  ("chat-supersedes", validate_chat_supersedes_scenario),
41844
+ ("chat-mention-skips-code", validate_chat_mention_skips_code_scenario),
41716
41845
  ("chat-ack", validate_chat_ack_scenario),
41717
41846
  ("coordinator-patrol", validate_coordinator_patrol_scenario),
41718
41847
  ("patrol-since-last", validate_patrol_since_last_scenario),
@@ -41869,6 +41998,7 @@ SCENARIOS: tuple = (
41869
41998
  "a-listed-marker-opens-its-clause",
41870
41999
  validate_a_listed_marker_opens_its_clause_scenario,
41871
42000
  ),
42001
+ ("archive-keeps-tracked-evidence", validate_archive_keeps_tracked_evidence_scenario),
41872
42002
  (
41873
42003
  "an-equivalence-claim-names-its-base",
41874
42004
  validate_an_equivalence_claim_names_its_base_scenario,
@@ -476,7 +476,8 @@ function lenientMentions(project, group, text) {
476
476
  const state = store.groupState(store.readLog(project.where, group));
477
477
  const aliases = store.aliasMap(project.where.root);
478
478
  const mentions = [];
479
- for (const match of String(text).matchAll(MENTION)) {
479
+ // Quoted text is not a mention here either (#345).
480
+ for (const match of store.mentionText(text).matchAll(MENTION)) {
480
481
  const token = match[2].replace(/[-/]+$/, "").toLowerCase();
481
482
  let role = null;
482
483
  if (token === store.ALL || token === store.OWNER || token.includes("/") || state.members.has(token)) role = token;
@@ -527,10 +527,23 @@ const MENTION = /(^|[^\w@/])@([A-Za-z0-9][A-Za-z0-9/-]*)/g;
527
527
  // `@role`, `@alias` (case-insensitive), `@all`, `@owner`, and the cross-project
528
528
  // `@project/role`. Anything else is refused by name, so a typo cannot post a
529
529
  // message that silently reaches nobody (design D3, D4).
530
+ // Quoted text is not a mention: a fenced block or an inline code span is
531
+ // blanked with spaces of its own length before the scan, so `@verify` written
532
+ // as an example neither refuses the post nor wakes anyone (#345).
533
+ function mentionText(text) {
534
+ return String(text)
535
+ .replace(/```[\s\S]*?(?:```|$)/g, (block) => block.replace(/[^\n]/g, " "))
536
+ .replace(/`[^`\n]*`/g, (span) => " ".repeat(span.length));
537
+ }
538
+
539
+ // `<branch> @ <sha>` is the commonest `@` in some projects; a hex token that
540
+ // names nobody is that commit id, not a typo of a role (#345).
541
+ const COMMIT_ID = /^[0-9a-f]{7,40}$/;
542
+
530
543
  function resolveMentions(where, group, state, text) {
531
544
  const aliases = aliasMap(where.root);
532
545
  const mentions = [];
533
- for (const match of String(text).matchAll(MENTION)) {
546
+ for (const match of mentionText(text).matchAll(MENTION)) {
534
547
  const token = match[2].replace(/[-/]+$/, "").toLowerCase();
535
548
  let role = null;
536
549
  if (token === ALL || token === OWNER) role = token;
@@ -540,6 +553,7 @@ function resolveMentions(where, group, state, text) {
540
553
  if (role && role !== ALL && role !== OWNER && !role.includes("/") && !state.members.has(role)) {
541
554
  throw new ChatError(`@${match[2]} names role ${role}, which is not a member of group ${group}.`);
542
555
  }
556
+ if (!role && COMMIT_ID.test(token)) continue;
543
557
  if (!role) {
544
558
  throw new ChatError(`@${match[2]} is not a member or alias in group ${group}.`);
545
559
  }
@@ -984,6 +998,7 @@ function readGroups(where, role, group) {
984
998
 
985
999
  module.exports = {
986
1000
  wait,
1001
+ mentionText,
987
1002
  openWaits,
988
1003
  markMet,
989
1004
  canAct,
package/src/core/gates.js CHANGED
@@ -2211,6 +2211,20 @@ function hasDeltaSpec(changePath) {
2211
2211
  return false;
2212
2212
  }
2213
2213
 
2214
+ // Tracked files under a change that an ignore rule matches. Git keeps them
2215
+ // tracked where they were added, and an archive moves them to a new path,
2216
+ // where the same rule leaves them untracked: the archive commit then deletes
2217
+ // them while they sit on disk (#352).
2218
+ function trackedButIgnored(repo, changePath) {
2219
+ const result = spawnSync(
2220
+ "git",
2221
+ ["ls-files", "-z", "-c", "-i", "--exclude-standard", "--", path.relative(repo, changePath) || "."],
2222
+ { cwd: repo, encoding: "utf8" }
2223
+ );
2224
+ if (result.error || result.status !== 0) return [];
2225
+ return result.stdout.split("\0").filter(Boolean);
2226
+ }
2227
+
2214
2228
  function changeClose(repo, options) {
2215
2229
  if (!["sync", "archive"].includes(options.closeAction)) {
2216
2230
  throw new GateInputError(
@@ -2312,6 +2326,16 @@ function changeClose(repo, options) {
2312
2326
  );
2313
2327
  }
2314
2328
  if (options.closeAction === "archive") {
2329
+ const dropped = trackedButIgnored(repo, changePath);
2330
+ if (dropped.length > 0) {
2331
+ const named = dropped.slice(0, 5).map((file) => `\`${file}\``).join(", ");
2332
+ warnings.push(
2333
+ `${dropped.length} tracked file(s) under this change match an ignore rule (${named}`
2334
+ + `${dropped.length > 5 ? ", …" : ""}). Git keeps them tracked only at the path they were `
2335
+ + "added at, so an archive that moves the directory drops them from version control. "
2336
+ + "`keel openspec archive` re-adds them; after any other move, `git add -f` their archived paths."
2337
+ );
2338
+ }
2315
2339
  for (const artifact of ["proposal.md", "design.md"]) {
2316
2340
  if (!fs.existsSync(path.join(changePath, artifact))) {
2317
2341
  problems.push(