fwdloop 0.27.0 → 0.29.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 (105) hide show
  1. package/README.md +1 -1
  2. package/bin/fwdloop +54 -13
  3. package/package.json +3 -3
  4. package/src/ask.js +1 -1
  5. package/src/audit-fold.js +9 -1
  6. package/src/authoring.js +22 -5
  7. package/src/canrun.js +19 -16
  8. package/src/checked.js +5 -2
  9. package/src/checkpick.js +257 -0
  10. package/src/checkwords.js +24 -0
  11. package/src/closers.js +8 -1
  12. package/src/config.js +18 -0
  13. package/src/declaration.js +85 -5
  14. package/src/drafter.js +143 -47
  15. package/src/flow.js +2 -1
  16. package/src/launcher.js +4 -2
  17. package/src/learn.js +1 -1
  18. package/src/learnstore.js +8 -7
  19. package/src/mcp-checks.js +50 -0
  20. package/src/mcp-pick.js +33 -0
  21. package/src/mcp-sources.js +84 -0
  22. package/src/mcp-use.js +54 -0
  23. package/src/memo.js +120 -0
  24. package/src/model-step.js +89 -17
  25. package/src/natural.js +23 -0
  26. package/src/pageask.js +9 -6
  27. package/src/pagedropwords.js +9 -0
  28. package/src/panel/author.js +50 -28
  29. package/src/panel/authorcard.js +86 -2
  30. package/src/panel/authorflows.js +18 -14
  31. package/src/panel/authortrigger.js +241 -84
  32. package/src/panel/data.js +99 -11
  33. package/src/panel/index.html +683 -210
  34. package/src/panel/jobgrid.js +127 -0
  35. package/src/panel/result.js +28 -7
  36. package/src/panel/scheduler.js +8 -2
  37. package/src/panel/server.js +17 -7
  38. package/src/panel/settings.js +119 -4
  39. package/src/panel/tickets.js +12 -7
  40. package/src/pickrecord.js +146 -0
  41. package/src/plain-checks.js +1 -0
  42. package/src/primitives.js +34 -5
  43. package/src/provider.js +4 -1
  44. package/src/runfile.js +4 -2
  45. package/src/runner.js +170 -45
  46. package/src/send.js +71 -4
  47. package/src/setup.js +13 -1
  48. package/src/summary-words.js +15 -3
  49. package/src/ticket-draft.js +40 -42
  50. package/src/ticket-labels.js +10 -0
  51. package/src/ticket-mcp.js +33 -10
  52. package/src/ticket-next.js +33 -0
  53. package/src/ticket-shape.js +9 -0
  54. package/src/trigger-clock.js +4 -4
  55. package/src/trigger-files.js +3 -3
  56. package/src/trigger-tickets.js +41 -12
  57. package/types/ask.d.ts +2 -1
  58. package/types/audit-fold.d.ts +13 -2
  59. package/types/authoring.d.ts +10 -2
  60. package/types/canrun.d.ts +5 -12
  61. package/types/checked.d.ts +7 -2
  62. package/types/checkpick.d.ts +149 -0
  63. package/types/checkwords.d.ts +14 -0
  64. package/types/closers.d.ts +2 -1
  65. package/types/config.d.ts +6 -0
  66. package/types/declaration.d.ts +17 -0
  67. package/types/drafter.d.ts +446 -50
  68. package/types/learn.d.ts +1 -0
  69. package/types/learnstore.d.ts +2 -3
  70. package/types/mcp-checks.d.ts +8 -0
  71. package/types/mcp-pick.d.ts +23 -0
  72. package/types/mcp-sources.d.ts +51 -0
  73. package/types/mcp-use.d.ts +12 -0
  74. package/types/memo.d.ts +15 -0
  75. package/types/model-step.d.ts +5 -0
  76. package/types/natural.d.ts +2 -0
  77. package/types/pageask.d.ts +9 -2
  78. package/types/pagedropwords.d.ts +1 -0
  79. package/types/panel/author.d.ts +37 -1
  80. package/types/panel/authorcard.d.ts +52 -0
  81. package/types/panel/authorflows.d.ts +9 -1
  82. package/types/panel/authortrigger.d.ts +73 -7
  83. package/types/panel/data.d.ts +56 -2
  84. package/types/panel/jobgrid.d.ts +109 -0
  85. package/types/panel/result.d.ts +9 -3
  86. package/types/panel/server.d.ts +5 -1
  87. package/types/panel/settings.d.ts +3 -2
  88. package/types/panel/tickets.d.ts +26 -4
  89. package/types/pickrecord.d.ts +88 -0
  90. package/types/primitives.d.ts +15 -2
  91. package/types/runfile.d.ts +7 -2
  92. package/types/runner.d.ts +128 -77
  93. package/types/send.d.ts +10 -2
  94. package/types/setup.d.ts +1 -56
  95. package/types/summary-words.d.ts +22 -3
  96. package/types/ticket-draft.d.ts +40 -32
  97. package/types/ticket-labels.d.ts +6 -0
  98. package/types/ticket-mcp.d.ts +18 -1
  99. package/types/ticket-next.d.ts +23 -0
  100. package/types/ticket-shape.d.ts +5 -0
  101. package/types/trigger-clock.d.ts +4 -3
  102. package/types/trigger-files.d.ts +1 -1
  103. package/types/trigger-tickets.d.ts +18 -4
  104. package/src/attemptdiff.js +0 -118
  105. 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.
@@ -20,12 +20,18 @@ export function nextInWords(ms: number, now: number): string;
20
20
  * 3. a clock kind with a next slot; 4. a file kind that is armed; 5. not armed yet.
21
21
  * A last outcome of `refused` goes in front of 3-5, so a trigger that cannot start is never silent.
22
22
  * `red` is the typed flag for "the human must act": monthly-exhausted and the refused lead. The page paints it; it never guesses from the text.
23
- * @param {{trigger: Trigger, armed: boolean, nextSlotMs: number|null, lastOutcome: any, waitingLine: number|null, now: number}} f
23
+ * M13 piece 5: `waiting` (signed with the job, off until the first green run) says SCHEDULE_WAITING_SAY, before every other row but the ask.
24
+ * @param {{trigger: Trigger, armed: boolean, waiting?: boolean, lookProblem?: {at: number, why: string}|null, nextSlotMs: number|null, lastOutcome: any, waitingLine: number|null, now: number}} f
24
25
  * @returns {{text: string, red: boolean}}
25
26
  */
26
27
  export function scheduledNextFor(f: {
27
28
  trigger: Trigger;
28
29
  armed: boolean;
30
+ waiting?: boolean;
31
+ lookProblem?: {
32
+ at: number;
33
+ why: string;
34
+ } | null;
29
35
  nextSlotMs: number | null;
30
36
  lastOutcome: any;
31
37
  waitingLine: number | null;
@@ -90,9 +96,10 @@ export function startedWords(rec: any, startMs: number | null, home?: string): s
90
96
  * - month used up: `month used up: $0.01 left, needs $0.50 · next: raise the limit in Settings, or it starts on the 1st`, red only while `nowMs` is still that month;
91
97
  * - refused: `refused: <why> · next: fix it in Cancel / modify schedule`, red until a later good start.
92
98
  * `next` otherwise: `next <day stamp>`, `next: waiting for a new file` (file schedule) or `next: not armed yet`.
93
- * @param {{trigger: Trigger|null, home?: string, last: {at: string, runId: string, outcome: string, catchUp: boolean}|null, nextSlotMs: number|null, armed: boolean, problem: any, nowMs?: number}} f
99
+ * M13 piece 5: a schedule signed with the job and still off (`waiting`) has line 2 `Schedule waiting for a green run`, `grey: true` (a red run is normal shaping, never red).
100
+ * @param {{trigger: Trigger|null, home?: string, last: {at: string, runId: string, outcome: string, catchUp: boolean}|null, nextSlotMs: number|null, armed: boolean, waiting?: boolean, lookProblem?: {at: number, why: string}|null, problem: any, nowMs?: number}} f
94
101
  * `problem`: the newest fire when it started nothing (busy, monthly-exhausted, refused), else null.
95
- * @returns {{line1: string, line2: string|null, red: boolean}}
102
+ * @returns {{line1: string, line2: string|null, red: boolean, grey?: boolean}}
96
103
  */
97
104
  export function scheduleBlockWords(f: {
98
105
  trigger: Trigger | null;
@@ -105,12 +112,18 @@ export function scheduleBlockWords(f: {
105
112
  } | null;
106
113
  nextSlotMs: number | null;
107
114
  armed: boolean;
115
+ waiting?: boolean;
116
+ lookProblem?: {
117
+ at: number;
118
+ why: string;
119
+ } | null;
108
120
  problem: any;
109
121
  nowMs?: number;
110
122
  }): {
111
123
  line1: string;
112
124
  line2: string | null;
113
125
  red: boolean;
126
+ grey?: boolean;
114
127
  };
115
128
  /**
116
129
  * M9 am9 / am11: a run's Audit `schedule` section (one for every run of a job that has a schedule NOW; `null` when it has none). Folded head
@@ -153,6 +166,12 @@ export function needsLeftWords(left: {
153
166
  } | null): string | null;
154
167
  /** ENDED (am7 item 1): `10/14 08:16 · passed · Goal met.`. The stamp is the run's local end time; the word is the run's outcome word (none for a run ended on purpose). @param {string|null} at ISO @param {string|null} word @param {string} reason */
155
168
  export function endedLineWords(at: string | null, word: string | null, reason: string): string;
169
+ /** M13 piece 5 (signed item 7): a schedule that was signed with the job and is off until the first green run. The Run card's grey line; one owner. */
170
+ export const SCHEDULE_WAITING_SAY: "Schedule waiting for a green run";
171
+ export function lookProblemWords(p: {
172
+ at: number;
173
+ why: string;
174
+ }): string;
156
175
  /** M9 am8 item 3: the busy sentence, in the busy row of `triggers.jsonl` and in the SCHEDULE block. One owner; the scheduler writes it, the words read it. */
157
176
  export const SCHEDULE_BUSY_SAY: "a run of this job was still working";
158
177
  export function startedNothing(row: any): any;
@@ -1,37 +1,38 @@
1
- /** the refusals of a by-hand start's ticket box: a ticket job needs a number; any other job takes none. @param {string|null} ticketRole @param {any} body @returns {{field: string, say: string}[]} */
2
- export function ticketRefusals(ticketRole: string | null, body: any): {
3
- field: string;
4
- say: string;
5
- }[];
6
- /** the server names in the user's own `~/.mcp.json` (what the drafter may name); none when the file is missing or unreadable @param {string} [configPath] @returns {string[]} */
1
+ /** the startable server names across the MCP sources (src/mcp-sources.js), or in one explicit file (what the drafter may name); none when the file is missing or unreadable @param {string} [configPath] @returns {string[]} */
7
2
  export function userMcpServers(configPath?: string): string[];
8
3
  /**
9
- * The lines under "Inputs" for one ticket role. The first is F90c's, word for word; the rest tell the drafter the two optional fields it may suggest.
10
- * @param {string} role @param {string[]} servers @returns {string[]}
4
+ * The lines under "Inputs" for one ticket role (M13 piece 4: flow type Tickets). The first is F90c's, word for word. The ticket is already frozen under its role and the job's own
5
+ * tools (`issue_read` to read it, `list_issues` to look for new ones) belong to the job, so no step needs them; a step lists a tool only if it calls it live.
6
+ * @param {string} role @returns {string[]}
7
+ */
8
+ export function ticketFactsLines(role: string): string[];
9
+ /** the lines for a generic MCP job: the server, its tool names (so the drafter can grant them to steps), and the rule that a step lists a tool only if it calls it live @param {string} server @param {string[]} tools @returns {string[]} */
10
+ export function mcpFactsLines(server: string, tools: string[]): string[];
11
+ /**
12
+ * The schema parts a job with an MCP adds (M13 piece 4): per-step `mcpTools` (an enum of the job's tool names) for MCP (generic) and Tickets, and for Tickets the top-level
13
+ * `ticketFilter` and `ticketWatch`. The job's own `mcp` block and `flowType` are NOT offered: code sets them.
14
+ * @param {{flowType: 'mcp'|'tickets', tools: string[]}} o
11
15
  */
12
- export function ticketFactsLines(role: string, servers: string[]): string[];
13
- /** the schema parts a job with a ticket role adds: top-level `mcp` and `ticketFilter`, per-step `mcpTools` @param {string[]} servers */
14
- export function ticketSchemaParts(servers: string[]): {
16
+ export function ticketSchemaParts({ flowType, tools }: {
17
+ flowType: "mcp" | "tickets";
18
+ tools: string[];
19
+ }): {
15
20
  top: {
16
- mcp: {
21
+ ticketFilter?: undefined;
22
+ ticketWatch?: undefined;
23
+ };
24
+ step: {
25
+ mcpTools: {
17
26
  type: string;
18
- properties: {
19
- server: {
20
- type: string;
21
- enum: string[];
22
- };
23
- tools: {
24
- type: string;
25
- items: {
26
- type: string;
27
- enum: string[];
28
- };
29
- };
27
+ items: {
28
+ type: string;
29
+ enum: string[];
30
30
  };
31
- required: string[];
32
- additionalProperties: boolean;
33
31
  description: string;
34
32
  };
33
+ };
34
+ } | {
35
+ top: {
35
36
  ticketFilter: {
36
37
  type: string;
37
38
  properties: {
@@ -75,12 +76,18 @@ export function ticketSchemaParts(servers: string[]): {
75
76
  };
76
77
  };
77
78
  /**
78
- * Reds a draft with a ticket role must not pass with: no `mcp`, a server the person's config does not have, or no step that reads the ticket and holds the tool.
79
- * @param {Record<string, any>} declaration @param {Array<{role: string}>} ticketSources @param {string[]} servers @returns {string[]}
79
+ * M13 piece 4: the $0 refusals before any provider call. Tickets needs a ticket-list Inputs line; MCP (generic) and Tickets need a server that is startable and a tool list from a
80
+ * check (`pick`, src/mcp-pick.js: `{ok, server, tools}` or `{ok:false, say}`).
81
+ * @param {{flowType: string, ticketSources: Array<{role: string}>, pick: any, servers: string[]}} o @returns {string[]}
80
82
  */
81
- export function ticketReds(declaration: Record<string, any>, ticketSources: Array<{
82
- role: string;
83
- }>, servers: string[]): string[];
83
+ export function ticketReds({ flowType, ticketSources, pick, servers }: {
84
+ flowType: string;
85
+ ticketSources: Array<{
86
+ role: string;
87
+ }>;
88
+ pick: any;
89
+ servers: string[];
90
+ }): string[];
84
91
  /** the one tool the first slice reads a ticket with */
85
92
  export const TICKET_TOOL: "issue_read";
86
93
  export function isTicketListUrl(url: unknown): boolean;
@@ -93,4 +100,5 @@ export function ticketSourcesOf(sources: Array<{
93
100
  role: string;
94
101
  path: string;
95
102
  }[];
96
- export function ticketNumberOf(v: unknown): number | null;
103
+ /** the one tool a Tickets job looks for new tickets with (src/panel/authortrigger.js) */
104
+ export const LOOK_TOOL: "list_issues";
@@ -17,6 +17,12 @@ export function readTicketFields(text: string): {
17
17
  } | {
18
18
  ok: false;
19
19
  };
20
+ /**
21
+ * M13 piece 7 (9.4): the ONE reader of "the filter was unsure about this ticket", from a run.json input entry: true when its stored verdict ran with an `unsure`
22
+ * reason (also when the ticket was sent with Run it anyway and the filter's own verdict was unsure). Anything else, a torn entry too, is false.
23
+ * @param {any} entry @returns {boolean}
24
+ */
25
+ export function filterUnsure(entry: any): boolean;
20
26
  /**
21
27
  * @param {{text: string, filter?: {priority?: string[], labels?: string[]}}} a `filter` = the job's signed `ticketFilter` (or absent)
22
28
  * @returns {{outcome: 'run', unsure?: string}|{outcome: 'skip', reason: string}}
@@ -1,10 +1,19 @@
1
+ /**
2
+ * M13 piece 3: the config file a server starts from. An explicit path (a test seam) wins; otherwise the file of the WINNING place for `server` (src/mcp-sources.js,
3
+ * the one decider), or `~/.mcp.json` when no place has it. `remote` true = the winner has no start command (listed, not usable).
4
+ * @param {string} server @param {string} [explicit] @returns {{ file: string, remote: boolean }}
5
+ */
6
+ export function configForServer(server: string, explicit?: string): {
7
+ file: string;
8
+ remote: boolean;
9
+ };
1
10
  /**
2
11
  * Read ticket `number` of the list at `listUrl` with the job's `issue_read`.
3
12
  * @param {{listUrl: string, number: number, mcp: {server: string, tools: string[]}, configPath?: string, timeoutMs?: number}} o
4
13
  * @returns {Promise<{ok: true, text: string, url: string, record: {server: string, exposed: string[], missing: Array<{server: string, tool: string}>, calls: Array<{tool: string, owner: string, repo: string, issue_number: number}>}} | {ok: false, error: string}>}
5
14
  * `record` is what the run keeps (in its `run.json` input entry): what the server exposed and lacked, and each call made.
6
15
  */
7
- export function readTicketMcp({ listUrl, number, mcp, configPath, timeoutMs }: {
16
+ export function readTicketMcp({ listUrl, number, mcp, configPath: explicitConfig, timeoutMs }: {
8
17
  listUrl: string;
9
18
  number: number;
10
19
  mcp: {
@@ -35,6 +44,14 @@ export function readTicketMcp({ listUrl, number, mcp, configPath, timeoutMs }: {
35
44
  ok: false;
36
45
  error: string;
37
46
  }>;
47
+ /** M13 item 9.5: the only parent env names an MCP gets (plus its own settings); the one list for every place fwdloop starts an MCP, so no provider key reaches it */
48
+ export const MCP_PASS_ENV: string[];
49
+ export function mcpStartOpts(): {
50
+ passEnv: string[];
51
+ cwd: string;
52
+ };
53
+ export function startRefusal(server: string, e: any): string;
38
54
  export function USER_MCP_CONFIG(): string;
55
+ export function remoteRefusal(server: string): string;
39
56
  export function firstLine(e: any): string;
40
57
  export function isDeviceLogin(text: any): any;
@@ -0,0 +1,23 @@
1
+ /** the ticket numbers this job's runs have read @param {string} flowDir @returns {Set<number>} */
2
+ export function ranTicketNumbers(flowDir: string): Set<number>;
3
+ /**
4
+ * @param {{flowDir: string, listUrl: string, mcp: {server: string, tool: string}, configPath?: string, look?: typeof lookTickets}} o `look` is a test seam
5
+ * @returns {Promise<{ok: true, number: number} | {ok: false, say: string}>}
6
+ */
7
+ export function newestUnrunTicket({ flowDir, listUrl, mcp, configPath, look }: {
8
+ flowDir: string;
9
+ listUrl: string;
10
+ mcp: {
11
+ server: string;
12
+ tool: string;
13
+ };
14
+ configPath?: string;
15
+ look?: typeof lookTickets;
16
+ }): Promise<{
17
+ ok: true;
18
+ number: number;
19
+ } | {
20
+ ok: false;
21
+ say: string;
22
+ }>;
23
+ import { lookTickets } from './trigger-tickets.js';
@@ -23,3 +23,8 @@ export function ticketListsOf(arbiter: {
23
23
  export const WATCHABLE: readonly string[];
24
24
  /** the shape of a ticket list address: owner and repo are the two groups */
25
25
  export const LIST_URL: RegExp;
26
+ /** M13 piece 7 (9.7): the one cap on a ticket number, 10 digits. Every door that takes or reads a ticket number uses `isTicketNumber`. Under 2^53, so a safe JS number. */
27
+ export const TICKET_MAX: 9999999999;
28
+ export function isTicketNumber(n: unknown): n is number;
29
+ /** The words every refusal of a ticket number uses. */
30
+ export const TICKET_NUMBER_WORDS: string;
@@ -22,15 +22,15 @@ export function due(schedule: Schedule, rows: ClockRow[], now: number): Due;
22
22
  export function nextSlot(schedule: Schedule, afterMs: number): number;
23
23
  /** @param {string} file @param {string} [sig] M9 am20: only the rows of that schedule signing (the one schedule ledger carries every signing's rows); absent = every row @returns {ClockRow[]} every row on disk that parses, oldest first; a missing file is no rows; a line a crash tore mid-append is skipped (`appendOnce` starts each append on a fresh line, so it never glues onto the next row). */
24
24
  export function readRows(file: string, sig?: string): ClockRow[];
25
- /** The trigger was set at `now`: no slot before this ever fires. @param {string} file @param {number} now @param {string} [sig] */
26
- export function armTrigger(file: string, now: number, sig?: string): void;
25
+ /** The trigger was set at `now`: no slot before this ever fires. M13 piece 5: `ticketN` = the highest ticket number the first green run read; a ticket schedule's first look baselines only tickets up to it. @param {string} file @param {number} now @param {string} [sig] @param {number} [ticketN] */
26
+ export function armTrigger(file: string, now: number, sig?: string, ticketN?: number): void;
27
27
  /**
28
28
  * Record that the run for this due slot is starting. Call BEFORE starting the run: a crash loses a run, never doubles one.
29
29
  * @param {string} file @param {Due} d the result of `due` with fire true @param {number} now @param {string} [sig]
30
30
  */
31
31
  export function recordFire(file: string, d: Due, now: number, sig?: string): void;
32
32
  /** @typedef {{kind:'daily'|'weekdays', hour:number, minute:number} | {kind:'weekly', day:string, hour:number, minute:number}} Schedule */
33
- /** @typedef {{id:string, kind:'armed'|'fire', at:number, slot?:number, catchUp?:boolean, missed?:number, sig?:string}} ClockRow */
33
+ /** @typedef {{id:string, kind:'armed'|'fire', at:number, slot?:number, catchUp?:boolean, missed?:number, sig?:string, ticketN?:number}} ClockRow */
34
34
  /** @typedef {{fire:boolean, catchUp:boolean, missed:number, slot?:number}} Due */
35
35
  /** A slot seen MORE than this after its set time is a catch-up (M9 am2 item 1). Exactly this late is on time. */
36
36
  export const GRACE_MS: 120000;
@@ -52,6 +52,7 @@ export type ClockRow = {
52
52
  catchUp?: boolean;
53
53
  missed?: number;
54
54
  sig?: string;
55
+ ticketN?: number;
55
56
  };
56
57
  export type Due = {
57
58
  fire: boolean;
@@ -14,7 +14,7 @@ export function recordDropped(ledger: string, item: {
14
14
  id?: string;
15
15
  }, why: "deleted" | "changed" | "schedule-changed" | "carried", at: number, sig?: string): boolean;
16
16
  /**
17
- * The queue: arrived and neither ran nor dropped, oldest arrival first. Identical arrival times: by name, then by sha (deterministic).
17
+ * The queue: arrived and neither ran nor dropped, oldest arrival first. Identical arrival times: by name, then by sha (deterministic); numbers inside a name compare as numbers (`#8` before `#10`).
18
18
  * @param {SeenRow[]} rows @returns {(SeenRow & {path:string})[]}
19
19
  */
20
20
  export function queueOf(rows: SeenRow[]): (SeenRow & {
@@ -12,10 +12,12 @@ export function reasonFor(prev: {
12
12
  * One look. `seen` null = the first look after signing (the first page is the starting point, nothing runs). Otherwise newest first with the cursor, stopping at a seen
13
13
  * number; with watched fields the walk goes on past it only as far as the oldest tracked ticket, comparing each tracked ticket's watched values with `last`.
14
14
  * Every failure is `{ok:false, error}` naming its cause, at $0; none reads as "0 new".
15
- * @param {{listUrl: string, mcp: {server: string, tool: string}, configPath?: string, seen: Set<number>|null, last: Map<number, {state: string, labels: string[]}>, watch: string[], perPage?: number, timeoutMs?: number}} o
16
- * @returns {Promise<{ok: true, first: boolean, found: Array<{number: number, state: string, labels: string[], createdAt: string|null}>, changed: Array<{number: number, reason: string, state: string, labels: string[]}>, pages: number} | {ok: false, error: string}>}
15
+ * M13 piece 5 (F114f): `cut` (first look only) = the highest ticket number the job's first green run read. The first look goes on past a page whose tickets are all above it, so
16
+ * every ticket that came in after that run started is seen; `recordLook` then baselines the ones up to `cut` and lets the rest arrive.
17
+ * @param {{listUrl: string, mcp: {server: string, tool: string}, configPath?: string, seen: Set<number>|null, last: Map<number, {state: string, labels: string[]}>, watch: string[], cut?: number, perPage?: number, timeoutMs?: number}} o
18
+ * @returns {Promise<{ok: true, first: boolean, cut?: number, ignored?: number[], found: Array<{number: number, state: string, labels: string[], createdAt: string|null}>, changed: Array<{number: number, reason: string, state: string, labels: string[]}>, pages: number} | {ok: false, error: string}>}
17
19
  */
18
- export function lookTickets({ listUrl, mcp, configPath, seen, last, watch, perPage, timeoutMs, }: {
20
+ export function lookTickets({ listUrl, mcp, configPath: explicitConfig, seen, last, watch, cut, perPage, timeoutMs, }: {
19
21
  listUrl: string;
20
22
  mcp: {
21
23
  server: string;
@@ -28,11 +30,14 @@ export function lookTickets({ listUrl, mcp, configPath, seen, last, watch, perPa
28
30
  labels: string[];
29
31
  }>;
30
32
  watch: string[];
33
+ cut?: number;
31
34
  perPage?: number;
32
35
  timeoutMs?: number;
33
36
  }): Promise<{
34
37
  ok: true;
35
38
  first: boolean;
39
+ cut?: number;
40
+ ignored?: number[];
36
41
  found: Array<{
37
42
  number: number;
38
43
  state: string;
@@ -57,6 +62,15 @@ export function lastSeen(ledger: string, sig: string): Map<number, {
57
62
  state: string;
58
63
  labels: string[];
59
64
  }>;
65
+ /** Has this signing had its first look (its baseline written)? @param {string} ledger @param {string} sig */
66
+ /**
67
+ * M13 item 9b.3: the cause of the newest look when it could not read, else null. The newest look row decides: an `unreadable` row is the problem until a later look reads
68
+ * (its `looked`, `baseline` or `arrived` row). @param {import('./trigger-files.js').SeenRow[]} rows @returns {{at: number, why: string}|null}
69
+ */
70
+ export function lookProblemOf(rows: import("./trigger-files.js").SeenRow[]): {
71
+ at: number;
72
+ why: string;
73
+ } | null;
60
74
  /**
61
75
  * Write what a look found, once. First look: a `baseline` row per ticket on the page (never runs). Later: an `arrived` row per new ticket, oldest first (its arrival
62
76
  * time is this clock), and one `arrived` row per watched change with its `reason`. A look that could not read writes one `unreadable` row with its cause.
@@ -88,4 +102,4 @@ export function watchedOf(i: any): {
88
102
  state: string;
89
103
  labels: any;
90
104
  };
91
- export function hasBaseline(ledger: string, sig: string): boolean;
105
+ export function hasBaseline(ledger: any, sig: any): boolean;
@@ -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;