fwdloop 0.28.0 → 0.30.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.
Files changed (74) hide show
  1. package/README.md +1 -1
  2. package/bin/fwdloop +27 -5
  3. package/package.json +3 -3
  4. package/src/added-end.js +60 -0
  5. package/src/ask.js +1 -1
  6. package/src/audit-fold.js +9 -1
  7. package/src/authoring.js +18 -7
  8. package/src/checked.js +14 -9
  9. package/src/checkpick.js +318 -0
  10. package/src/checkwords.js +29 -0
  11. package/src/citedcheck.js +14 -0
  12. package/src/closers.js +40 -3
  13. package/src/declaration.js +102 -5
  14. package/src/draft-steps.js +3 -3
  15. package/src/drafter.js +151 -38
  16. package/src/jobkey.js +3 -1
  17. package/src/learn.js +1 -1
  18. package/src/learnstore.js +6 -6
  19. package/src/memo.js +120 -0
  20. package/src/model-step.js +103 -25
  21. package/src/pageask.js +12 -6
  22. package/src/pagedropwords.js +9 -0
  23. package/src/panel/author.js +33 -10
  24. package/src/panel/authorcard.js +59 -6
  25. package/src/panel/data.js +16 -10
  26. package/src/panel/index.html +151 -59
  27. package/src/panel/result.js +28 -7
  28. package/src/panel/server.js +2 -1
  29. package/src/pickrecord.js +146 -0
  30. package/src/plain-checks.js +16 -3
  31. package/src/provider.js +4 -1
  32. package/src/repairs.js +38 -0
  33. package/src/runfile.js +4 -2
  34. package/src/runner.js +129 -40
  35. package/src/send.js +71 -4
  36. package/src/setup.js +13 -1
  37. package/src/sheetblock.js +2 -1
  38. package/src/ticket-draft.js +2 -2
  39. package/src/ticket-labels.js +2 -2
  40. package/src/try-checks.js +13 -3
  41. package/src/whole-job.js +71 -0
  42. package/types/added-end.d.ts +62 -0
  43. package/types/ask.d.ts +2 -1
  44. package/types/audit-fold.d.ts +13 -2
  45. package/types/authoring.d.ts +6 -2
  46. package/types/checked.d.ts +7 -2
  47. package/types/checkpick.d.ts +183 -0
  48. package/types/checkwords.d.ts +18 -0
  49. package/types/citedcheck.d.ts +6 -0
  50. package/types/closers.d.ts +6 -3
  51. package/types/declaration.d.ts +12 -0
  52. package/types/drafter.d.ts +28 -25
  53. package/types/learn.d.ts +1 -0
  54. package/types/learnstore.d.ts +2 -3
  55. package/types/memo.d.ts +15 -0
  56. package/types/model-step.d.ts +23 -3
  57. package/types/pageask.d.ts +9 -2
  58. package/types/pagedropwords.d.ts +1 -0
  59. package/types/panel/author.d.ts +1 -1
  60. package/types/panel/authorcard.d.ts +41 -0
  61. package/types/panel/data.d.ts +1 -1
  62. package/types/panel/jobgrid.d.ts +1 -1
  63. package/types/panel/result.d.ts +9 -3
  64. package/types/pickrecord.d.ts +88 -0
  65. package/types/plain-checks.d.ts +9 -1
  66. package/types/repairs.d.ts +13 -0
  67. package/types/runfile.d.ts +7 -2
  68. package/types/runner.d.ts +16 -5
  69. package/types/send.d.ts +10 -2
  70. package/types/setup.d.ts +1 -56
  71. package/types/try-checks.d.ts +1 -7
  72. package/types/whole-job.d.ts +70 -0
  73. package/src/attemptdiff.js +0 -118
  74. package/types/attemptdiff.d.ts +0 -38
package/types/setup.d.ts CHANGED
@@ -10,62 +10,7 @@ export function buildSetupRows({ sessionDir, planDir, hash, signedBy, signedAt,
10
10
  signedBy: string;
11
11
  signedAt: string;
12
12
  flowHash?: string;
13
- }): ({
14
- tries?: {
15
- label: string;
16
- passed: boolean;
17
- reds: string[];
18
- outcome: string;
19
- rawOutcome: string;
20
- again: boolean;
21
- }[] | undefined;
22
- kind: any;
23
- n: any;
24
- at: any;
25
- model: any;
26
- costUsd: any;
27
- spendComplete: boolean;
28
- calls: any;
29
- wallMs: any;
30
- structureRetries: any;
31
- verdict: string;
32
- hash: string | null;
33
- gap: string | null;
34
- } | {
35
- kind: string;
36
- n: number;
37
- at: string | null;
38
- source: string;
39
- ask: string | undefined;
40
- question: string;
41
- answer: string | null;
42
- line: number;
43
- ruleNo: number | undefined;
44
- ruleText: string | undefined;
45
- proposal: string | null;
46
- rule: string | null;
47
- } | {
48
- kind: string;
49
- n: number;
50
- at: string | null;
51
- card: any;
52
- signedBy?: undefined;
53
- hash?: undefined;
54
- flowHash?: undefined;
55
- notChecked?: undefined;
56
- } | {
57
- kind: string;
58
- n: number;
59
- at: string;
60
- signedBy: string;
61
- hash: string;
62
- flowHash: string | null;
63
- notChecked: {
64
- label: string;
65
- items: any[];
66
- };
67
- card?: undefined;
68
- })[];
13
+ }): any[];
69
14
  /**
70
15
  * Write `<flowDir>/setup.jsonl` ONCE ('wx': a second write is refused, never merged or replaced), mode 0600, every row scrubbed of the
71
16
  * given key values. Never throws.
@@ -42,13 +42,7 @@ export function closeRecords(step: any, artifact: any, closed: {
42
42
  ok: boolean;
43
43
  result: string | null;
44
44
  }>;
45
- }): {
46
- n: number;
47
- text: string;
48
- ok: boolean;
49
- result: string | null;
50
- source: string;
51
- }[];
45
+ }): any[];
52
46
  export const EVERY_STEP: "every step";
53
47
  export function lineSource(step: {
54
48
  fromLine?: unknown;
@@ -0,0 +1,70 @@
1
+ /**
2
+ * The index of the Ask that shows the whole job: the Ask the added send reads, only when the plan has the am8 added `write it out`. A job signed before am8
3
+ * (its send line is the person's own words) finds -1 and keeps today's behaviour exactly.
4
+ * @param {{ steps: { fromLine: number, goal: string, emits?: string, reads?: string[] }[], askLines: Map<number, any>, sendLines: Map<number, any> }} p
5
+ * @returns {number} -1 = none
6
+ */
7
+ export function wholeJobAskIndex({ steps, askLines, sendLines }: {
8
+ steps: {
9
+ fromLine: number;
10
+ goal: string;
11
+ emits?: string;
12
+ reads?: string[];
13
+ }[];
14
+ askLines: Map<number, any>;
15
+ sendLines: Map<number, any>;
16
+ }): number;
17
+ /**
18
+ * @param {{ steps: { fromLine: number, goal: string, emits?: string }[], askLines: Map<number, any>, lastAskIndex: number,
19
+ * readResult: (id: string) => ({ ok: true, value: any } | { ok: false, missing: true } | { ok: false, missing: false, red: string }) }} p
20
+ * @returns {{ ok: true, value: { text: string } } | { ok: false, red: string }}
21
+ */
22
+ export function wholeJobText({ steps, askLines, lastAskIndex, readResult }: {
23
+ steps: {
24
+ fromLine: number;
25
+ goal: string;
26
+ emits?: string;
27
+ }[];
28
+ askLines: Map<number, any>;
29
+ lastAskIndex: number;
30
+ readResult: (id: string) => ({
31
+ ok: true;
32
+ value: any;
33
+ } | {
34
+ ok: false;
35
+ missing: true;
36
+ } | {
37
+ ok: false;
38
+ missing: false;
39
+ red: string;
40
+ });
41
+ }): {
42
+ ok: true;
43
+ value: {
44
+ text: string;
45
+ };
46
+ } | {
47
+ ok: false;
48
+ red: string;
49
+ };
50
+ /**
51
+ * M13 am9 item 4: the plan shows the last Ask as reading every step. Code sets the Ask's `reads` to every work step's emits before it (the nearest one first, so a
52
+ * redo still re-runs the step just before the Ask; the rest in job order). Only a plan with the am8 added end; any other plan comes back as it was.
53
+ * @template {{ fromLine: number, goal: string, emits?: string, reads?: string[], primitives?: string[] }} S
54
+ * @param {S[]} steps @param {{ asks?: { line: number }[], sends?: { line: number }[] }} arbiter
55
+ * @returns {S[]}
56
+ */
57
+ export function readEveryStep<S extends {
58
+ fromLine: number;
59
+ goal: string;
60
+ emits?: string;
61
+ reads?: string[];
62
+ primitives?: string[];
63
+ }>(steps: S[], arbiter: {
64
+ asks?: {
65
+ line: number;
66
+ }[];
67
+ sends?: {
68
+ line: number;
69
+ }[];
70
+ }): S[];
@@ -1,118 +0,0 @@
1
- // borrowed-from: bareloop src/attemptdiff.js@v0.46.0 (8b3d815)
2
- // Adaptations: redactSecrets imported from ./redact.js (fwdloop's one secret inventory) in place of bareloop's ./validate.js; the temp index dir prefix is fwdloop-adiff-. Nothing else changed.
3
- // attempt-diff — what each worker TRY changed, as a spine record (ITEM33 addendum
4
- // 2026-10-22). The spine and the gate audit keep only file names and byte sizes of
5
- // edits; a learnings card could say WHICH files a passing try touched but never WHAT
6
- // changed. This module is the ONE owner of that capture. It is a record, never a
7
- // verdict: every failure is caught and returned as a field, nothing here throws.
8
- //
9
- // How: a git TREE snapshot at try start and at try end, each through a TEMPORARY
10
- // index (GIT_INDEX_FILE + `git add -A` + `git write-tree`), then `git diff <t0> <t1>`.
11
- // The work branch, HEAD, the real index and the stash list are never touched; the
12
- // temp index is removed. Only unreferenced loose objects are left in the object store.
13
-
14
- import { execFile } from 'node:child_process';
15
- import { promisify } from 'node:util';
16
- import { mkdtemp, rm } from 'node:fs/promises';
17
- import { tmpdir } from 'node:os';
18
- import { existsSync } from 'node:fs';
19
- import { join, relative, resolve } from 'node:path';
20
- import { redactSecrets } from './redact.js';
21
-
22
- const exec = promisify(execFile);
23
-
24
- /** per-file and per-event byte caps for the recorded diff text */
25
- export const ATTEMPT_DIFF_FILE_MAX = 4096;
26
- export const ATTEMPT_DIFF_EVENT_MAX = 16384;
27
-
28
- /**
29
- * Cut `text` to at most `max` bytes at a LINE boundary (never mid-line).
30
- * @param {string} text @param {number} max
31
- * @returns {{text: string, truncated: boolean, cutLines: number}}
32
- */
33
- export function cutAtLine(text, max) {
34
- if (Buffer.byteLength(text) <= max) return { text, truncated: false, cutLines: 0 };
35
- const lines = text.match(/[^\n]*\n|[^\n]+$/g) ?? [];
36
- let used = 0;
37
- let kept = 0;
38
- for (const l of lines) {
39
- const b = Buffer.byteLength(l);
40
- if (used + b > max) break;
41
- used += b;
42
- kept++;
43
- }
44
- return { text: lines.slice(0, kept).join(''), truncated: true, cutLines: lines.length - kept };
45
- }
46
-
47
- /** @param {string} abs @param {string[]} prefixes */
48
- const inFence = (abs, prefixes) => prefixes.some((p) => abs === p || abs.startsWith(p.endsWith('/') ? p : `${p}/`));
49
-
50
- // the arbiter's books and installed packages never enter a snapshot, even inside a wide fence
51
- const NOT_WORK = [':(exclude,glob)**/node_modules/**', ':(exclude,glob)**/.git/**', ':(exclude).smoke', ':(exclude).litectx', ':(exclude)gate-audit.jsonl'];
52
-
53
- /**
54
- * Snapshot the FENCE of the working tree to a git tree id via a throwaway index. Only the
55
- * fence's existing prefixes are added, and with `-f`: a rubric job's `output/` must be seen
56
- * even when the source folder's own .gitignore lists it (the hidden-git seed ignores that
57
- * file's meaning; so does this).
58
- * @param {string} workdir @param {string[]} fence @returns {Promise<string>}
59
- */
60
- async function snapshotTree(workdir, fence) {
61
- const tmp = await mkdtemp(join(tmpdir(), 'fwdloop-adiff-'));
62
- try {
63
- const env = { ...process.env, GIT_INDEX_FILE: join(tmp, 'index') };
64
- const specs = fence.filter((p) => existsSync(p)).map((p) => `:(literal)${relative(workdir, p) || '.'}`);
65
- if (specs.length > 0) await exec('git', ['add', '-A', '-f', '--', ...specs, ...NOT_WORK], { cwd: workdir, env, maxBuffer: 1 << 26 });
66
- const { stdout } = await exec('git', ['write-tree'], { cwd: workdir, env });
67
- return stdout.trim();
68
- } finally {
69
- await rm(tmp, { recursive: true, force: true });
70
- }
71
- }
72
-
73
- /**
74
- * Begin recording one worker try. Call BEFORE the worker's turn; call `finish()` after
75
- * (in a `finally`). Never throws.
76
- * @param {{workdir: string, fence: string[], redact?: (s: string) => string}} o
77
- * `fence` = the ABSOLUTE write-scope prefixes the gate enforces for this try.
78
- * @returns {Promise<{finish: () => Promise<null | {files: {path: string, diff: string, truncated: boolean, cutLines: number}[], binary: string[], truncated: boolean, gitError?: string}>}>}
79
- * `finish()` resolves null when the try changed nothing in scope.
80
- */
81
- export async function startAttemptDiff({ workdir, fence, redact = redactSecrets }) {
82
- /** @type {string|null} */
83
- let t0 = null;
84
- /** @type {string|null} */
85
- let startError = null;
86
- try { t0 = await snapshotTree(workdir, fence); } catch (e) { startError = String(/** @type {any} */ (e)?.message ?? e); }
87
- return {
88
- async finish() {
89
- try {
90
- if (t0 === null) throw new Error(`start snapshot failed: ${startError}`);
91
- const t1 = await snapshotTree(workdir, fence);
92
- if (t1 === t0) return null;
93
- const g = (/** @type {string[]} */ a) => exec('git', ['-c', 'core.quotepath=false', ...a], { cwd: workdir, maxBuffer: 1 << 26 });
94
- const { stdout: names } = await g(['diff', '--name-only', '-z', '--relative', /** @type {string} */ (t0), t1]);
95
- const paths = names.split('\0').filter(Boolean).filter((p) => inFence(resolve(workdir, p), fence));
96
- /** @type {{path: string, diff: string, truncated: boolean, cutLines: number}[]} */
97
- const files = [];
98
- /** @type {string[]} */
99
- const binary = [];
100
- let left = ATTEMPT_DIFF_EVENT_MAX;
101
- let anyCut = false;
102
- for (const p of paths) {
103
- const { stdout } = await g(['diff', '-U1', '--no-color', '--no-ext-diff', '--relative', /** @type {string} */ (t0), t1, '--', `:(literal)${p}`]);
104
- const path = redact(p);
105
- if (/^Binary files .* differ$/m.test(stdout) || /^GIT binary patch$/m.test(stdout)) { binary.push(path); continue; }
106
- const cut = cutAtLine(redact(stdout), Math.min(ATTEMPT_DIFF_FILE_MAX, left));
107
- left -= Buffer.byteLength(cut.text);
108
- if (cut.truncated) anyCut = true;
109
- files.push({ path, diff: cut.text, truncated: cut.truncated, cutLines: cut.cutLines });
110
- }
111
- if (files.length === 0 && binary.length === 0) return null;
112
- return { files, binary, truncated: anyCut };
113
- } catch (e) {
114
- return { files: [], binary: [], truncated: false, gitError: redact(String(/** @type {any} */ (e)?.message ?? e)).slice(0, 500) };
115
- }
116
- },
117
- };
118
- }
@@ -1,38 +0,0 @@
1
- /**
2
- * Cut `text` to at most `max` bytes at a LINE boundary (never mid-line).
3
- * @param {string} text @param {number} max
4
- * @returns {{text: string, truncated: boolean, cutLines: number}}
5
- */
6
- export function cutAtLine(text: string, max: number): {
7
- text: string;
8
- truncated: boolean;
9
- cutLines: number;
10
- };
11
- /**
12
- * Begin recording one worker try. Call BEFORE the worker's turn; call `finish()` after
13
- * (in a `finally`). Never throws.
14
- * @param {{workdir: string, fence: string[], redact?: (s: string) => string}} o
15
- * `fence` = the ABSOLUTE write-scope prefixes the gate enforces for this try.
16
- * @returns {Promise<{finish: () => Promise<null | {files: {path: string, diff: string, truncated: boolean, cutLines: number}[], binary: string[], truncated: boolean, gitError?: string}>}>}
17
- * `finish()` resolves null when the try changed nothing in scope.
18
- */
19
- export function startAttemptDiff({ workdir, fence, redact }: {
20
- workdir: string;
21
- fence: string[];
22
- redact?: (s: string) => string;
23
- }): Promise<{
24
- finish: () => Promise<null | {
25
- files: {
26
- path: string;
27
- diff: string;
28
- truncated: boolean;
29
- cutLines: number;
30
- }[];
31
- binary: string[];
32
- truncated: boolean;
33
- gitError?: string;
34
- }>;
35
- }>;
36
- /** per-file and per-event byte caps for the recorded diff text */
37
- export const ATTEMPT_DIFF_FILE_MAX: 4096;
38
- export const ATTEMPT_DIFF_EVENT_MAX: 16384;