@inixiative/foundry-core 0.5.3 → 0.5.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inixiative/foundry-core",
3
- "version": "0.5.3",
3
+ "version": "0.5.5",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -3,7 +3,10 @@
3
3
  * Oracle's replay runner: a wide run (more than TINY_MOMENTS moments, or whatever else the caller
4
4
  * counts as wide) needs `--experiment <design.md>` whose pre-registration sections are filled and
5
5
  * whose `<design>.review.md` says `verdict: go` for this exact design (`design-sha256:` of its
6
- * bytes). A tiny test runs without one.
6
+ * bytes). A tiny test runs without one. When a `<design>.decisions.md` companion sits beside the
7
+ * design (run pins and answers that are filled after review, so the design's hash stays fixed), the
8
+ * run is refused while it still holds a TBD value outside its `## Log`, and its path and hash are
9
+ * recorded too.
7
10
  */
8
11
  import { createHash } from 'node:crypto';
9
12
  import { existsSync, readFileSync } from 'node:fs';
@@ -24,12 +27,32 @@ export const DESIGN_SECTIONS = [
24
27
  'What would make the result wrong',
25
28
  ] as const;
26
29
 
27
- export type ExperimentRecord = { design: string; designSha256: string; review: string };
30
+ export type ExperimentRecord = {
31
+ design: string;
32
+ designSha256: string;
33
+ review: string;
34
+ decisions?: string;
35
+ decisionsSha256?: string;
36
+ };
28
37
 
29
38
  export const reviewPathOf = (design: string) => design.replace(/\.md$/, '.review.md');
39
+ export const decisionsPathOf = (design: string) => design.replace(/\.md$/, '.decisions.md');
30
40
 
31
41
  const sha256 = (path: string) => createHash('sha256').update(readFileSync(path)).digest('hex');
32
42
 
43
+ /**
44
+ * Line numbers of a decisions companion that still hold a `TBD` value. The `## Log` section is
45
+ * history and is skipped, and the token quoted alone in backticks is a mention of it, not a value.
46
+ */
47
+ export const openDecisionLines = (text: string): number[] => {
48
+ let inLog = false;
49
+ return text.split('\n').flatMap((line, i) => {
50
+ const heading = /^(#{1,6})\s+(.+?)\s*$/.exec(line);
51
+ if (heading) inLog = heading[1] === '##' ? /^log$/i.test(heading[2] ?? '') : inLog;
52
+ return !inLog && /\bTBD\b/.test(line.replaceAll('`TBD`', '')) ? [i + 1] : [];
53
+ });
54
+ };
55
+
33
56
  /** Why the design may not run wide; empty when it may. */
34
57
  export const experimentProblems = (designPath: string): string[] => {
35
58
  const design = resolve(designPath);
@@ -54,6 +77,14 @@ export const experimentProblems = (designPath: string): string[] => {
54
77
  problems.push(`section "## ${name}" is empty`);
55
78
  }
56
79
  if (text.includes('<fill')) problems.push('unfilled <fill: …> placeholders remain');
80
+ const decisions = decisionsPathOf(design);
81
+ if (existsSync(decisions)) {
82
+ const open = openDecisionLines(readFileSync(decisions, 'utf8'));
83
+ if (open.length)
84
+ problems.push(
85
+ `${decisions} still says TBD (line${open.length > 1 ? 's' : ''} ${open.join(', ')})`,
86
+ );
87
+ }
57
88
  const review = reviewPathOf(design);
58
89
  if (!existsSync(review)) return [...problems, `no adversarial review at ${review}`];
59
90
  const reviewText = readFileSync(review, 'utf8');
@@ -85,5 +116,15 @@ export const requireExperiment = (
85
116
  'see .claude/skills/experiment/SKILL.md',
86
117
  );
87
118
  const design = resolve(experiment);
88
- return { design, designSha256: sha256(design), review: reviewPathOf(design) };
119
+ const record: ExperimentRecord = {
120
+ design,
121
+ designSha256: sha256(design),
122
+ review: reviewPathOf(design),
123
+ };
124
+ const decisions = decisionsPathOf(design);
125
+ if (existsSync(decisions)) {
126
+ record.decisions = decisions;
127
+ record.decisionsSha256 = sha256(decisions);
128
+ }
129
+ return record;
89
130
  };
package/src/index.ts CHANGED
@@ -192,8 +192,10 @@ export {
192
192
  } from './feedback/correction';
193
193
  export {
194
194
  DESIGN_SECTIONS,
195
+ decisionsPathOf,
195
196
  type ExperimentRecord,
196
197
  experimentProblems,
198
+ openDecisionLines,
197
199
  requireExperiment,
198
200
  reviewPathOf,
199
201
  TINY_MOMENTS,