@christang/keel 5.146.0 → 5.148.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.146.0",
3
+ "version": "5.148.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.146.0 -->
1
+ <!-- keel:start version=5.148.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"]
@@ -1015,17 +1060,22 @@ function hostRun(executable, args) {
1015
1060
 
1016
1061
  // A read-only `plugin list --json` normally answers in 1–3 s, and once hung
1017
1062
  // for minutes through a proxy (#354). It gets its own short limit, and a query
1018
- // that fails is reported as one, never as a host with no Keel.
1063
+ // that fails is reported as one, never as a host with no Keel. A query that
1064
+ // times out is retried once: on the owner's link the same query took 58 s
1065
+ // once and about 1 s on the next runs (#365).
1019
1066
  function hostQuery(executable, args) {
1020
1067
  const limit = Number(process.env.KEEL_UPDATE_QUERY_TIMEOUT_MS) || 30 * 1000;
1021
- const result = spawnSync(executable, args, {
1068
+ const run = () => spawnSync(executable, args, {
1022
1069
  encoding: "utf8",
1023
1070
  shell: process.platform === "win32",
1024
1071
  timeout: limit,
1025
1072
  });
1073
+ const timedOut = (attempt) => attempt.error && attempt.error.code === "ETIMEDOUT";
1074
+ let result = run();
1075
+ if (timedOut(result)) result = run();
1026
1076
  if (result.error && result.error.code === "ENOENT") return { absent: true };
1027
- if (result.error && result.error.code === "ETIMEDOUT") {
1028
- return { failed: `timed out after ${limit / 1000} s` };
1077
+ if (timedOut(result)) {
1078
+ return { failed: `timed out twice, after ${limit / 1000} s each` };
1029
1079
  }
1030
1080
  if (result.error) return { failed: result.error.message };
1031
1081
  // On Windows the call goes through cmd.exe, which reports a missing command
@@ -2690,7 +2740,9 @@ function runAction(options) {
2690
2740
  );
2691
2741
  return 1;
2692
2742
  }
2743
+ const archiving = options.openspecArgs[0] === "archive" ? archiveTracking(process.cwd(), options.openspecArgs) : null;
2693
2744
  const status = runCommand(openspec, options.openspecArgs, { stdio: "inherit" });
2745
+ if (status === 0 && archiving) keepArchivedTracked(process.cwd(), archiving);
2694
2746
  if (status !== 0 || options.openspecArgs[0] !== "update") return status;
2695
2747
  const repo = process.cwd();
2696
2748
  for (const target of installedOpenSpecTargets(repo)) {
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@christang/keel",
3
- "version": "5.146.0",
3
+ "version": "5.148.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@christang/keel",
9
- "version": "5.146.0",
9
+ "version": "5.148.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.146.0",
5
+ "version": "5.148.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.146.0",
3
+ "version": "5.148.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.146.0",
3
+ "version": "5.148.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.146.0"
53
- PROTOCOL_VERSION = "5.146.0"
52
+ PACKAGE_VERSION = "5.148.0"
53
+ PROTOCOL_VERSION = "5.148.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
@@ -23838,8 +23838,15 @@ const args = process.argv.slice(2);
23838
23838
  fs.appendFileSync(process.env.FAKE_LOG, JSON.stringify([host, ...args]) + "\n");
23839
23839
  // FAKE_LIST_SLEEP_<HOST> holds `plugin list --json` for N seconds, and
23840
23840
  // FAKE_LIST_EXIT_<HOST> makes it exit with that status (#354).
23841
+ // FAKE_LIST_SLEEP_TIMES_<HOST> holds only the first N such calls (#365); the
23842
+ // count is written before the hold, since a held call is killed.
23841
23843
  if (args.join(" ") === "plugin list --json") {
23842
- const hold = Number(process.env[`FAKE_LIST_SLEEP_${host.toUpperCase()}`] || "0");
23844
+ let hold = Number(process.env[`FAKE_LIST_SLEEP_${host.toUpperCase()}`] || "0");
23845
+ const times = Number(process.env[`FAKE_LIST_SLEEP_TIMES_${host.toUpperCase()}`] || "Infinity");
23846
+ const counter = `${process.env.FAKE_STATE}.held-${host}`;
23847
+ const held = fs.existsSync(counter) ? Number(fs.readFileSync(counter, "utf8")) : 0;
23848
+ if (held >= times) hold = 0;
23849
+ else if (hold > 0) fs.writeFileSync(counter, String(held + 1));
23843
23850
  if (hold > 0) Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, hold * 1000);
23844
23851
  const code = process.env[`FAKE_LIST_EXIT_${host.toUpperCase()}`];
23845
23852
  if (code) process.exit(Number(code));
@@ -24103,7 +24110,7 @@ def validate_update_host_query_timeout_scenario() -> int:
24103
24110
  if "absent" in codex:
24104
24111
  report(f"{label} a hung codex plugin list --json was reported absent: {codex!r}")
24105
24112
  return 1
24106
- for needle in ("failed", "codex plugin list --json", "timed out after 1.5 s"):
24113
+ for needle in ("failed", "codex plugin list --json", "1.5 s"):
24107
24114
  if needle not in codex:
24108
24115
  report(f"{label} the hung-query line does not name {needle!r}: {codex!r}")
24109
24116
  return 1
@@ -24224,6 +24231,77 @@ def validate_update_claude_refresh_retry_scenario() -> int:
24224
24231
  return 0
24225
24232
 
24226
24233
 
24234
+ def validate_update_host_query_retry_scenario() -> int:
24235
+ """Issue #365: `codex plugin list --json` usually answers in about 1 s and
24236
+ sometimes took 58 s through the owner's proxy.
24237
+
24238
+ A query that times out is retried once before the component reads
24239
+ `failed`, so one slow spell no longer leaves the plugin a release behind.
24240
+ """
24241
+ label = "update-host-query-retry:"
24242
+ listing = ["codex", "plugin", "list", "--json"]
24243
+ with tempfile.TemporaryDirectory(prefix="keel-update-365-", ignore_cleanup_errors=True) as raw:
24244
+ tmp = Path(raw)
24245
+ fake = tmp / "fake.js"
24246
+ write_text(fake, UPDATE_FAKE)
24247
+ launchers = {}
24248
+ for host in ("npm", "claude", "codex"):
24249
+ launcher = tmp / f"fake-{host}"
24250
+ write_text(launcher, f'#!/bin/sh\nFAKE_HOST={host} exec node "{fake}" "$@"\n')
24251
+ launcher.chmod(0o755)
24252
+ launchers[host] = launcher
24253
+ source = tmp / "codex-source"
24254
+ write_text(source / "hooks/codex.json", "{}\n")
24255
+
24256
+ def update(times: str):
24257
+ log, state = tmp / "log.jsonl", tmp / "state.json"
24258
+ for stale in (log, state, tmp / "state.json.held-codex"):
24259
+ if stale.exists():
24260
+ stale.unlink()
24261
+ log.write_text("")
24262
+ env = dict(os.environ)
24263
+ env.update({
24264
+ "KEEL_UPDATE_NPM": str(launchers["npm"]), "KEEL_UPDATE_CLAUDE": str(launchers["claude"]),
24265
+ "KEEL_UPDATE_CODEX": str(launchers["codex"]), "KEEL_UPDATE_QUERY_TIMEOUT_MS": "4000",
24266
+ "CODEX_HOME": str(tmp / "codex-home"), "FAKE_LOG": str(log), "FAKE_STATE": str(state),
24267
+ "FAKE_CODEX_SOURCE": str(source),
24268
+ "FAKE_LIST_SLEEP_CODEX": "15", "FAKE_LIST_SLEEP_TIMES_CODEX": times,
24269
+ })
24270
+ env.pop("KEEL_UPDATE_SOURCE", None)
24271
+ started = time.monotonic()
24272
+ result = subprocess.run(["node", str(ROOT / "bin/keel.js"), "--update"], cwd=tmp, env=env,
24273
+ text=True, capture_output=True, check=False, timeout=120)
24274
+ calls = [json.loads(line) for line in log.read_text().splitlines() if line.strip()]
24275
+ line = next((l for l in result.stdout.splitlines() if l.startswith("keel update: codex plugin:")), "")
24276
+ return result, calls, line, time.monotonic() - started
24277
+
24278
+ result, calls, line, _ = update("1")
24279
+ if "5.0.0 -> 5.1.0" not in line:
24280
+ report(f"{label} a query that timed out once did not go on to update the Codex plugin: {line!r}")
24281
+ return 1
24282
+ if result.returncode != 0:
24283
+ report(f"{label} a query that answered on retry left keel --update exiting {result.returncode}: {result.stdout!r}")
24284
+ return 1
24285
+
24286
+ result, calls, line, took = update("9")
24287
+ for needle in ("failed", "codex plugin list --json", "timed out twice", "4 s"):
24288
+ if needle not in line:
24289
+ report(f"{label} a lasting hang's line does not name {needle!r}: {line!r}")
24290
+ return 1
24291
+ runs = sum(1 for c in calls if c[:4] == listing)
24292
+ if runs != 2:
24293
+ report(f"{label} a lasting hang ran the query {runs} time(s), not 2: {calls!r}")
24294
+ return 1
24295
+ if took > 25:
24296
+ report(f"{label} two 4 s attempts held keel --update for {took:.1f} s.")
24297
+ return 1
24298
+ if "update-host-query-retry" not in {name for name, _ in SCENARIOS}:
24299
+ report(f"{label} scenario is not registered.")
24300
+ return 1
24301
+ report("update-host-query-retry scenario passed.")
24302
+ return 0
24303
+
24304
+
24227
24305
  def validate_update_codex_refresh_retry_scenario() -> int:
24228
24306
  """Issue #329: a slow link can cut Codex's whole-repository marketplace clone.
24229
24307
 
@@ -39152,6 +39230,83 @@ def validate_a_claim_names_what_would_falsify_it_scenario() -> int:
39152
39230
  return 0
39153
39231
 
39154
39232
 
39233
+ def validate_archive_keeps_tracked_evidence_scenario() -> int:
39234
+ """Issue #352: archiving a change whose own .gitignore ignores tracked
39235
+ evidence dropped that evidence from version control.
39236
+
39237
+ The archive is a filesystem move; tracked files survive an ignore rule
39238
+ only at the path they were added at, so at the archived path they read as
39239
+ deleted-and-ignored and the archive commit removed them.
39240
+ `keel openspec archive` re-adds them, and `change-close --action archive`
39241
+ warns about them before any move.
39242
+ """
39243
+ label = "archive-keeps-tracked-evidence:"
39244
+ with tempfile.TemporaryDirectory(prefix="keel-archive-352-") as raw:
39245
+ tmp = Path(raw)
39246
+ repo = tmp / "repo"
39247
+ repo.mkdir()
39248
+
39249
+ def git(*args: str) -> subprocess.CompletedProcess[str]:
39250
+ return subprocess.run(["git", *args], cwd=repo, text=True, capture_output=True, check=False)
39251
+
39252
+ git("init", "-q")
39253
+ git("config", "user.email", "t@example.com")
39254
+ git("config", "user.name", "t")
39255
+ env = dict(os.environ)
39256
+ env["CODEX_HOME"] = str(tmp / "codex-home")
39257
+ init = run_keel(repo, "--init", "--target", "claude", env=env)
39258
+ if init.returncode:
39259
+ report(f"{label} init failed: {init.stderr or init.stdout}")
39260
+ return 1
39261
+ change = repo / "openspec/changes/demo"
39262
+ write_text(change / "proposal.md", "## Why\n\nfixture\n\n## What Changes\n\n- fixture\n")
39263
+ write_text(change / "tasks.md", "# Tasks\n\n- [x] 1.1 done\n")
39264
+ write_text(change / ".gitignore", "evidence/**\n")
39265
+ write_text(change / "evidence/run.log", "measured\n")
39266
+ git("add", "-A")
39267
+ git("add", "-f", "openspec/changes/demo/evidence/run.log")
39268
+ git("commit", "-q", "-m", "fixture")
39269
+ if "openspec/changes/demo/evidence/run.log" not in git("ls-files").stdout:
39270
+ report(f"{label} the fixture's evidence is not tracked.")
39271
+ return 1
39272
+
39273
+ # The gate sees it before any move.
39274
+ closing = run_keel(repo, "gate", "change-close", "--change", "demo", "--action", "archive", "--json", env=env)
39275
+ try:
39276
+ warnings = json.loads(closing.stdout).get("warnings", [])
39277
+ except json.JSONDecodeError:
39278
+ report(f"{label} change-close printed no JSON: {closing.stdout!r} {closing.stderr!r}")
39279
+ return 1
39280
+ warned = next((w for w in warnings if "evidence/run.log" in w), "")
39281
+ if not warned:
39282
+ report(f"{label} change-close --action archive does not warn about tracked evidence the change ignores: {warnings!r}")
39283
+ return 1
39284
+ if "keel openspec archive" not in warned:
39285
+ report(f"{label} the warning does not name the archive that keeps it: {warned!r}")
39286
+ return 1
39287
+
39288
+ archived = run_keel(repo, "openspec", "archive", "demo", "--yes", "--skip-specs", env=env)
39289
+ if archived.returncode:
39290
+ report(f"{label} keel openspec archive failed: {archived.stdout!r} {archived.stderr!r}")
39291
+ return 1
39292
+ moved = sorted((repo / "openspec/changes/archive").glob("*demo/evidence/run.log"))
39293
+ if len(moved) != 1:
39294
+ report(f"{label} the archive did not move the evidence: {sorted((repo / 'openspec/changes/archive').rglob('*'))!r}")
39295
+ return 1
39296
+ relative = moved[0].relative_to(repo).as_posix()
39297
+ if relative not in git("ls-files").stdout:
39298
+ report(f"{label} the archived evidence {relative} dropped out of version control: {archived.stdout!r}")
39299
+ return 1
39300
+ if "re-added 1" not in archived.stdout:
39301
+ report(f"{label} the archive does not say it re-added the tracked evidence: {archived.stdout!r}")
39302
+ return 1
39303
+ if "archive-keeps-tracked-evidence" not in {name for name, _ in SCENARIOS}:
39304
+ report(f"{label} scenario is not registered.")
39305
+ return 1
39306
+ report("archive-keeps-tracked-evidence scenario passed.")
39307
+ return 0
39308
+
39309
+
39155
39310
  def validate_a_listed_marker_opens_its_clause_scenario() -> int:
39156
39311
  """Issue #362: a disposition written as a sub-list item was read as prose.
39157
39312
 
@@ -41602,6 +41757,7 @@ SCENARIOS: tuple = (
41602
41757
  ("adopted-update-is-silent-unless-reload", validate_adopted_update_is_silent_unless_reload_scenario),
41603
41758
  ("update-covers-installed-hosts", validate_update_covers_installed_hosts_scenario),
41604
41759
  ("update-codex-refresh-retry", validate_update_codex_refresh_retry_scenario),
41760
+ ("update-host-query-retry", validate_update_host_query_retry_scenario),
41605
41761
  ("update-claude-refresh-retry", validate_update_claude_refresh_retry_scenario),
41606
41762
  ("update-host-query-timeout", validate_update_host_query_timeout_scenario),
41607
41763
  ("refresh-covers-every-target", validate_refresh_covers_every_target_scenario),
@@ -41790,6 +41946,7 @@ SCENARIOS: tuple = (
41790
41946
  "a-listed-marker-opens-its-clause",
41791
41947
  validate_a_listed_marker_opens_its_clause_scenario,
41792
41948
  ),
41949
+ ("archive-keeps-tracked-evidence", validate_archive_keeps_tracked_evidence_scenario),
41793
41950
  (
41794
41951
  "an-equivalence-claim-names-its-base",
41795
41952
  validate_an_equivalence_claim_names_its_base_scenario,
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(