@christang/keel 5.147.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.147.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.147.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"]
@@ -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.148.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.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.147.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.147.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.147.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.147.0"
53
- PROTOCOL_VERSION = "5.147.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
@@ -39230,6 +39230,83 @@ def validate_a_claim_names_what_would_falsify_it_scenario() -> int:
39230
39230
  return 0
39231
39231
 
39232
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
+
39233
39310
  def validate_a_listed_marker_opens_its_clause_scenario() -> int:
39234
39311
  """Issue #362: a disposition written as a sub-list item was read as prose.
39235
39312
 
@@ -41869,6 +41946,7 @@ SCENARIOS: tuple = (
41869
41946
  "a-listed-marker-opens-its-clause",
41870
41947
  validate_a_listed_marker_opens_its_clause_scenario,
41871
41948
  ),
41949
+ ("archive-keeps-tracked-evidence", validate_archive_keeps_tracked_evidence_scenario),
41872
41950
  (
41873
41951
  "an-equivalence-claim-names-its-base",
41874
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(