@christang/keel 5.99.3 → 5.99.5

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.3 -->
1
+ <!-- keel:start version=5.99.5 -->
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.3",
3
+ "version": "5.99.5",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@christang/keel",
9
- "version": "5.99.3",
9
+ "version": "5.99.5",
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.3",
5
+ "version": "5.99.5",
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.3",
3
+ "version": "5.99.5",
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.3",
3
+ "version": "5.99.5",
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.3"
51
- PROTOCOL_VERSION = "5.99.3"
50
+ PACKAGE_VERSION = "5.99.5"
51
+ PROTOCOL_VERSION = "5.99.5"
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")
@@ -36402,7 +36443,7 @@ def validate_codex_receiving_scenario() -> int:
36402
36443
 
36403
36444
  EXTERNAL_AGENT_FACT_FIELDS = {
36404
36445
  "name", "source", "executable", "resolved", "allowed",
36405
- "command", "sandbox", "sendsTo", "pitfalls",
36446
+ "command", "sandbox", "ownSandbox", "sendsTo", "pitfalls",
36406
36447
  }
36407
36448
 
36408
36449
 
@@ -36507,6 +36548,20 @@ def validate_external_agent_catalog_scenario() -> int:
36507
36548
  report(f"{label} `keel agents codex` does not print {needle!r}.")
36508
36549
  return 1
36509
36550
 
36551
+ # Issue #259: dsh's headless profile has a sandbox of its own, as measured.
36552
+ dsh_text = run_keel(repo, "agents", "dsh", env=env).stdout
36553
+ sandbox_line = next((line for line in dsh_text.splitlines() if line.startswith("Sandbox:")), "")
36554
+ if "workspace-write" not in sandbox_line:
36555
+ report(f"{label} `keel agents dsh` does not describe its own sandbox: {sandbox_line!r}")
36556
+ return 1
36557
+ for needle in ("/dev/stdout", "PYTHONPYCACHEPREFIX"):
36558
+ if needle not in dsh_text:
36559
+ report(f"{label} `keel agents dsh` has no pitfall naming {needle!r}.")
36560
+ return 1
36561
+ if "reads and writes wherever it is started" in dsh_text:
36562
+ report(f"{label} `keel agents dsh` still says it reads and writes wherever it is started.")
36563
+ return 1
36564
+
36510
36565
  # A machine entry declaring one field overrides that field only.
36511
36566
  custom = base / "bin" / "dsh"
36512
36567
  (base / "home" / "agents.json").write_text(
@@ -36737,6 +36792,19 @@ def validate_external_agent_brief_scenario() -> int:
36737
36792
  report(f"{label} a helper worktree under .claude/worktrees/ was refused from a sibling worktree: "
36738
36793
  f"{out.strip()[:600]}")
36739
36794
  return 1
36795
+ # Issue #259: a dsh brief keeps temporary files in tmp/ beside the brief.
36796
+ tmp = prompt.parent / "tmp"
36797
+ if not tmp.is_dir():
36798
+ report(f"{label} the dsh brief did not create {tmp} beside --out.")
36799
+ return 1
36800
+ if str(tmp) not in prompt.read_text(encoding="utf-8"):
36801
+ report(f"{label} the dsh brief does not name its temporary directory {tmp}.")
36802
+ return 1
36803
+ command = payload.get("run") or ""
36804
+ for needle in (f"TMPDIR={tmp}", f"PYTHONPYCACHEPREFIX={tmp}/pycache"):
36805
+ if needle not in command:
36806
+ report(f"{label} the dsh command does not set {needle!r}: {command}")
36807
+ return 1
36740
36808
  payload, out = helper_brief(helper_tree)
36741
36809
  if not refused(payload, out, str(helper_tree.resolve()), "current directory", "--repo",
36742
36810
  what="a helper brief run from inside its own --dir"):
@@ -20,7 +20,7 @@ const path = require("path");
20
20
 
21
21
  const { readExternalAgents } = require("./config");
22
22
 
23
- const FIELDS = ["executable", "command", "sandbox", "sendsTo", "pitfalls"];
23
+ const FIELDS = ["executable", "command", "sandbox", "ownSandbox", "sendsTo", "pitfalls"];
24
24
  const MODES = ["helper", "implementation"];
25
25
 
26
26
  const RTL_TOOLCHAIN = "rtl_ppa_prj docs/toolchain.md (main 632ad85)";
@@ -71,8 +71,9 @@ const BUNDLED = {
71
71
  },
72
72
  dsh: {
73
73
  executable: "/Applications/DeepSeek Harness.app/Contents/Resources/runtime/cli/bin/dsh",
74
- command: "cd {dir} && {executable} --profile headless - < {prompt} > {out}",
74
+ command: "cd {dir} && TMPDIR={tmp} PYTHONPYCACHEPREFIX={tmp}/pycache {executable} --profile headless - < {prompt} > {out}",
75
75
  sandbox: { helper: null, implementation: null },
76
+ ownSandbox: "the headless profile applies its own workspace-write file policy: outside the directory it starts in, writes are refused (including /dev/stdout and ~/Library/Caches) while /tmp stays writable; inside it, it writes freely, so it still needs a separate worktree (dsh 0.2.0-rc.2, #259)",
76
77
  sendsTo: "DeepSeek, through the provider the profile configures (by default deepseek-official, model deepseek-flash)",
77
78
  pitfalls: [
78
79
  {
@@ -86,9 +87,19 @@ const BUNDLED = {
86
87
  text: "First use needs a DeepSeek API key, stored once through the app's Models page or exported as DEEPSEEK_API_KEY where it is launched; until then the headless profile fails with MISSING_CREDENTIAL. With the key stored it runs from any directory.",
87
88
  },
88
89
  {
89
- date: "2026-10-04",
90
- source: "dsh headless --help, 0.2.0-rc.2",
91
- text: "It offers no sandbox flag and no working-directory flag. It reads and writes wherever it is started, so start it in a separate worktree.",
90
+ date: "2026-10-05",
91
+ source: "https://github.com/TanglmChris/keel/issues/259",
92
+ text: "It offers no sandbox flag and no working-directory flag, and its headless profile has no read-only mode: it writes freely inside the directory it starts in, so start it in a separate worktree.",
93
+ },
94
+ {
95
+ date: "2026-10-05",
96
+ source: "https://github.com/TanglmChris/keel/issues/259",
97
+ text: "Writing /dev/stdout is refused (`Operation not permitted`), so a tool that writes through it, such as yosys `tee -o /dev/stdout`, fails in its shell. One run spent about an hour working around it.",
98
+ },
99
+ {
100
+ date: "2026-10-05",
101
+ source: "https://github.com/TanglmChris/keel/issues/259",
102
+ text: "macOS Python's cache directory under ~/Library/Caches is not writable, so `python -m compileall` fails unless PYTHONPYCACHEPREFIX points inside a writable directory. The brief's command sets it, and TMPDIR, to `tmp/` beside the brief.",
92
103
  },
93
104
  {
94
105
  date: "2026-10-04",
@@ -230,6 +241,7 @@ function describeAgents(repo) {
230
241
  allowed: declaration.allow.includes(entry.name),
231
242
  command: entry.command,
232
243
  sandbox: entry.sandbox,
244
+ ownSandbox: entry.ownSandbox || null,
233
245
  sendsTo: entry.sendsTo || null,
234
246
  pitfalls: entry.pitfalls,
235
247
  }));
@@ -248,8 +260,9 @@ function describeAgents(repo) {
248
260
  };
249
261
  }
250
262
 
251
- function sandboxLine(sandbox) {
252
- return MODES.map((mode) => `${mode} ${sandbox[mode] || "none (needs a separate worktree)"}`).join("; ");
263
+ function sandboxLine(sandbox, ownSandbox) {
264
+ const modes = MODES.map((mode) => `${mode} ${sandbox[mode] || "none (needs a separate worktree)"}`).join("; ");
265
+ return ownSandbox ? `${modes}. Its own: ${ownSandbox}` : modes;
253
266
  }
254
267
 
255
268
  function pitfallLines(pitfalls) {
@@ -278,7 +291,7 @@ function renderAgent(payload, agent) {
278
291
  `${agent.name} [${agent.source}]`,
279
292
  `Executable: ${agent.executable} → ${agent.resolved || "not found"}`,
280
293
  `Command: ${agent.command}`,
281
- `Sandbox: ${sandboxLine(agent.sandbox)}`,
294
+ `Sandbox: ${sandboxLine(agent.sandbox, agent.ownSandbox)}`,
282
295
  `Sends to: ${agent.sendsTo || "not recorded"}`,
283
296
  `Allowed here: ${agent.allowed ? "yes" : "no"}`,
284
297
  "",
@@ -372,7 +385,7 @@ function shellQuote(value) {
372
385
  }
373
386
 
374
387
  function fillCommand(template, values) {
375
- return template.replace(/\{(executable|sandbox|dir|prompt|out)\}/g, (_, key) => shellQuote(values[key]));
388
+ return template.replace(/\{(executable|sandbox|dir|prompt|out|tmp)\}/g, (_, key) => shellQuote(values[key]));
376
389
  }
377
390
 
378
391
  const BRIEF_PROHIBITIONS = [
@@ -382,7 +395,7 @@ const BRIEF_PROHIBITIONS = [
382
395
  "Do not update a task's checkbox, Contract, Evidence, or Review.",
383
396
  ];
384
397
 
385
- function renderBrief({ agent, mode, dir, projection, source, result }) {
398
+ function renderBrief({ agent, mode, dir, projection, source, result, tmp }) {
386
399
  const list = (items) => (items.length ? items.map((item) => `- ${item}`) : ["- none"]);
387
400
  const lines = [
388
401
  `# Brief for ${agent.name}: ${source.change}#${source.task}`,
@@ -390,6 +403,7 @@ function renderBrief({ agent, mode, dir, projection, source, result }) {
390
403
  `Mode: ${mode}${agent.sandbox[mode] ? ` (sandbox ${agent.sandbox[mode]})` : ""}`,
391
404
  `Working directory: ${dir}`,
392
405
  `Write your final report to: ${result}`,
406
+ ...(tmp ? [`Temporary files: ${tmp} (TMPDIR points there); put none anywhere else.`] : []),
393
407
  "",
394
408
  "## Task",
395
409
  "",
@@ -499,8 +513,12 @@ function compileBrief(repo, options) {
499
513
  const out = path.resolve(options.out);
500
514
  const result = out.replace(/(\.md)?$/, ".result.md");
501
515
  fs.mkdirSync(path.dirname(out), { recursive: true });
516
+ // A template's {tmp} is a directory beside the brief, inside whatever the
517
+ // agent's own sandbox lets it write when --out is in its worktree (#259).
518
+ const tmp = entry.command.includes("{tmp}") ? path.join(path.dirname(out), "tmp") : null;
519
+ if (tmp) fs.mkdirSync(tmp, { recursive: true });
502
520
  fs.writeFileSync(out, renderBrief({
503
- agent: entry, mode: options.mode, dir, projection, source: projected.source, result,
521
+ agent: entry, mode: options.mode, dir, projection, source: projected.source, result, tmp,
504
522
  }));
505
523
  // A subshell, so a `cd` in a template does not move the caller, and the exit
506
524
  // status beside the result, because it is the one account of how the run
@@ -512,6 +530,7 @@ function compileBrief(repo, options) {
512
530
  dir,
513
531
  prompt: out,
514
532
  out: result,
533
+ tmp: tmp || "",
515
534
  });
516
535
  const run = `( ${filled} ); echo $? > ${shellQuote(exit)}`;
517
536
  return {
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) {