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/src/panel/data.js CHANGED
@@ -24,6 +24,7 @@ import {
24
24
  } from 'node:fs';
25
25
  import { createHash } from 'node:crypto';
26
26
  import { plainPlanCheck } from '../plain-checks.js';
27
+ import { compareNatural } from '../natural.js';
27
28
  import { join, sep } from 'node:path';
28
29
 
29
30
  import {
@@ -46,8 +47,14 @@ import {
46
47
  NO_COPY_SAY, catchUpWords, endedLineWords, endedWords, needsLeftWords, nextInWords, nextTimeWords, scheduleAuditWords, scheduleBlockWords, scheduleFieldWords, scheduledNextFor, scheduledWords, startedWords,
47
48
  } from '../summary-words.js';
48
49
  import { MAX_STRUCTURE_RETRIES } from '../drafter.js';
49
- import { isResultRun, checkTypeOf, buildResult, downloadOf, readCitedChecks } from './result.js';
50
- import { ticketListOf } from './tickets.js';
50
+ import { hasResultCards, checkTypeOf, buildResult, downloadOf, readCitedChecks } from './result.js';
51
+ import { ticketListOf, ticketScheduleOf } from './tickets.js';
52
+ import { buildJobGrid } from './jobgrid.js';
53
+ import { readChecks } from '../diary.js';
54
+ import { readRunInputs, readRunRecord } from '../runfile.js';
55
+ import { filterUnsure } from '../ticket-labels.js';
56
+ import { readSchedule } from '../schedule.js';
57
+ import { flowTypeOf } from '../declaration.js';
51
58
  import { thinkingRuleWords, thinkingTryWords } from '../thinking.js';
52
59
  import { readLearningsRecord } from '../flowmodel.js';
53
60
  import { readRunThinking } from '../runfile.js';
@@ -1471,7 +1478,7 @@ function waitingLineOf(ctx) {
1471
1478
  * through the same `runControls` the Stop door uses (`atAsk`), so "waiting" is one decision.
1472
1479
  */
1473
1480
  function jobWaitingLine(root, flowDir, flow, catalogue) {
1474
- const ids = listRunIds(flowDir).sort((a, b) => (Number(b.replace(/\D/g, '')) || 0) - (Number(a.replace(/\D/g, '')) || 0));
1481
+ const ids = listRunIds(flowDir).sort((a, b) => compareNatural(b, a));
1475
1482
  const history = readHistory(flowDir); // `atAsk` needs no end row (`runControls`), so an ended run is skipped by the same `endRow` rule before a context is built for it
1476
1483
  for (const id of ids) {
1477
1484
  const run = resolveRunDir(flowDir, id);
@@ -1497,7 +1504,7 @@ function scheduleBlockOf({ root, flowDir, flow, catalogue, t, home, now }) {
1497
1504
  return scheduleBlockWords({
1498
1505
  trigger: t && t.trigger ? t.trigger : null, home,
1499
1506
  last: lastStart ? { at: lastStart.at, runId: lastStart.runId, outcome: lastGlyph ? (SIGN_WORDS[lastGlyph.glyph] ?? 'ended') : 'ended', catchUp: !!(lastRec && lastRec.catchUp === true) } : null,
1500
- nextSlotMs: t ? t.nextSlotMs : null, armed: !!(t && t.armed), nowMs: now(),
1507
+ nextSlotMs: t ? t.nextSlotMs : null, armed: !!(t && t.armed), waiting: !!(t && t.waiting), lookProblem: t ? t.lookProblem ?? null : null, nowMs: now(),
1501
1508
  problem: latest && latest.outcome !== 'started' && ['busy', 'monthly-exhausted', 'refused'].includes(latest.outcome) ? latest : null,
1502
1509
  });
1503
1510
  }
@@ -1544,7 +1551,7 @@ function runSummary(ctx, glyph, { root, catalogue, triggerRead, now, home }) {
1544
1551
  const t = typeof triggerRead === 'function' ? triggerRead(ctx.flowName) : null;
1545
1552
  if (t && t.trigger) {
1546
1553
  const nx = scheduledNextFor({
1547
- trigger: t.trigger, armed: t.armed, nextSlotMs: t.nextSlotMs, lastOutcome: t.lastOutcome, waitingLine: jobWaitingLine(root, ctx.flowDir, ctx.flowName, catalogue), now: now(),
1554
+ trigger: t.trigger, armed: t.armed, waiting: t.waiting === true, lookProblem: t.lookProblem ?? null, nextSlotMs: t.nextSlotMs, lastOutcome: t.lastOutcome, waitingLine: jobWaitingLine(root, ctx.flowDir, ctx.flowName, catalogue), now: now(),
1548
1555
  });
1549
1556
  scheduled = { text: String(scheduledWords(t.trigger, home)), next: nx.text, nextRed: nx.red };
1550
1557
  }
@@ -1789,6 +1796,7 @@ export function getRunDetail({
1789
1796
  const model = deriveRunModel(ctx.auditRows);
1790
1797
  const modelWhy = model === null ? 'no audit.jsonl row in this run has ever named a model (no model step has run yet)' : null;
1791
1798
  const spendSummary = summarizeSpendRows(ctx.spendRows);
1799
+ const hasGrid = ctx.flowRead.ok && flowTypeOf(ctx.flowRead.declaration) === 'tickets';
1792
1800
 
1793
1801
  return {
1794
1802
  flow,
@@ -1805,8 +1813,11 @@ export function getRunDetail({
1805
1813
  needsYou: (({ tag, removable }) => ({ tag, removable }))(needsYouOf({
1806
1814
  runDir: run.runDir, ctx, glyph, controls: runControls(ctx, glyph, label), nowMs: now(), reopenAt: reopenableAt(run.runDir, ctx),
1807
1815
  })),
1808
- // M10 am4: the Result tab shows for a job that reads a page, a CSV or a .docx; `checkType` is its distinct close classes (the tab's top card)
1809
- hasResult: isResultRun(ctx.arbiter),
1816
+ // M10 am4 / M15 item 1: the Result tab shows for every job but a Tickets MCP one (that keeps the grid, and M10's cards when it reads a page); `checkType` is its distinct close classes (the tab's top card)
1817
+ hasResult: ctx.flowRead.ok && hasResultCards(ctx.arbiter, ctx.flowRead.declaration),
1818
+ // M13 am2 item 2: the ONE decider of the Result tab. The tab shows for a job that has M10's Result page (`hasResult`) or for a Tickets MCP job (the grid, `hasGrid`); a plain or MCP job keeps what it had before M13
1819
+ hasGrid,
1820
+ resultTab: (ctx.flowRead.ok && hasResultCards(ctx.arbiter, ctx.flowRead.declaration)) || hasGrid,
1810
1821
  checkType: ctx.flowRead.ok ? checkTypeOf(ctx.flowRead.declaration) : '\u2014',
1811
1822
  // M9 piece 6: the block at the top of the run page (ENDED / NEXT, SCHEDULED / NEXT), words set by code
1812
1823
  summary: runSummary(ctx, glyph, { root, catalogue, triggerRead, now, home }),
@@ -1984,11 +1995,16 @@ function attachFolds(groups, runDir, flowDir, { root, flow, catalogue }) {
1984
1995
  const job = readRunJob({ root, name: flow, catalogue, runDir }).read;
1985
1996
  if (job.ok) steps = job.declaration.steps ?? [];
1986
1997
  }
1998
+ // M14 am1 item 1: a rerun's own run.json holds the reason it started with; the Audit shows it on the first step, where that reason was handed
1999
+ const rec = readRunRecord(runDir);
2000
+ const rr = rec.ok ? rec.rec.rerun : null;
2001
+ let rerun = rr && typeof rr === 'object' && rr.decision === 'rerun' && typeof rr.words === 'string' ? { words: rr.words } : null;
1987
2002
  for (const g of groups) {
1988
2003
  if (g.run) continue;
1989
2004
  const decl = steps?.find((x) => x.emits === g.step);
1990
2005
  const read = Array.isArray(decl?.reads) ? decl.reads[0] : null;
1991
- const fold = deriveFold(g, d, { about: typeof read === 'string' ? `artifacts/${read}.json` : null });
2006
+ const fold = deriveFold(g, d, { about: typeof read === 'string' ? `artifacts/${read}.json` : null, rerun });
2007
+ rerun = null;
1992
2008
  if (fold) g.fold = fold;
1993
2009
  }
1994
2010
  }
@@ -2092,6 +2108,32 @@ function buildJobPlan(declaration, asks, flowDir, flowHash = null, jobLines = /*
2092
2108
  return { steps, notChecked: { label: NOT_CHECKED_LABEL, items: view.items, readNotes: view.readNotes, recorded } };
2093
2109
  }
2094
2110
 
2111
+ /**
2112
+ * M13 am4 item 2: the Job tab's MCP keys, read off the run's own declaration; `{}` for a plain job. The hint of a tool is the newest OK check of this server that names it
2113
+ * (`read-only` or null); no check, or a tool it does not name, is null (the page shows the name alone).
2114
+ * @param {any} declaration @param {(() => Map<string, any>)|undefined} mcpChecks
2115
+ */
2116
+ function mcpJobFields(declaration, mcpChecks) {
2117
+ const flowType = flowTypeOf(declaration);
2118
+ if (flowType === 'plain') return {};
2119
+ const server = declaration.mcp?.server ?? null;
2120
+ /** @type {any|null} */
2121
+ let newest = null;
2122
+ for (const r of (mcpChecks ? mcpChecks().values() : [])) {
2123
+ if (r.server === server && r.ok === true && Array.isArray(r.tools) && (newest === null || String(r.at) > String(newest.at))) newest = r;
2124
+ }
2125
+ const names = Array.isArray(declaration.mcp?.tools) ? declaration.mcp.tools : [];
2126
+ const tools = names.map((/** @type {any} */ t) => {
2127
+ const name = typeof t === 'string' ? t : String(t?.name);
2128
+ const hit = newest?.tools.find((/** @type {any} */ x) => x?.name === name);
2129
+ return { name, hint: hit?.hint === 'read-only' ? 'read-only' : null };
2130
+ });
2131
+ return {
2132
+ flowType, mcp: server, tools,
2133
+ ...(flowType === 'tickets' ? { ticketFilter: declaration.ticketFilter ?? null, ticketWatch: declaration.ticketWatch ?? null } : {}),
2134
+ };
2135
+ }
2136
+
2095
2137
  /**
2096
2138
  * `GET /api/runs/:flow/:runId/job` — the Job tab (hamr's 2026-09-27
2097
2139
  * exit-check review #5: bareloop-style one-field-per-piece layout,
@@ -2101,11 +2143,13 @@ function buildJobPlan(declaration, asks, flowDir, flowHash = null, jobLines = /*
2101
2143
  * name carries its own why, never a blank or a guess. Field order (server
2102
2144
  * order matches the page's own render order): prose, asks, model, cap
2103
2145
  * (+redo cap), sources, sends, guardrails, plan (one row per step, amendment 34), signature.
2104
- * @param {{root: string, flow: string, runId: string, catalogue: any, scheduleRead?: (flow: string) => any, home?: string}} opts
2146
+ * M13 am4 item 2: an MCP or Tickets MCP job also carries `flowType`, `mcp` (the server) and `tools` (`{name, hint}`; the hint is the newest OK check's, else null);
2147
+ * a Tickets job adds `ticketFilter` and `ticketWatch`. A plain job's payload has none of these keys. `mcpChecks` reads the newest-check map (unsigned, config home).
2148
+ * @param {{root: string, flow: string, runId: string, catalogue: any, scheduleRead?: (flow: string) => any, home?: string, mcpChecks?: () => Map<string, any>}} opts
2105
2149
  * @returns {any|null}
2106
2150
  */
2107
2151
  export function getRunJob({
2108
- root, flow, runId, catalogue, scheduleRead, home,
2152
+ root, flow, runId, catalogue, scheduleRead, home, mcpChecks,
2109
2153
  }) {
2110
2154
  const run = resolveRunPath(root, flow, runId);
2111
2155
  if (!run.ok) return null;
@@ -2144,6 +2188,7 @@ export function getRunJob({
2144
2188
  flow,
2145
2189
  runId,
2146
2190
  resolved: true,
2191
+ ...mcpJobFields(flowRead.declaration, mcpChecks),
2147
2192
  // M9 am6 items 1-2 / am7 item 5: how this run began and the workflow's schedule now; words from src/summary-words.js, the same owner as the Run tab's SCHEDULE block
2148
2193
  started: startedWords(readTriggerRecord(run.runDir), (() => { const at = firstPidStartedAt(run.runDir); return at === null ? null : Date.parse(at); })(), home),
2149
2194
  schedule: (() => {
@@ -2205,7 +2250,7 @@ function resultContext({
2205
2250
  const run = resolveRunPath(root, flow, runId);
2206
2251
  if (!run.ok || !readdirInside(run.flowDir, 'runs').includes(runId)) return null; // the gateway lists real, non-symlink run folders only
2207
2252
  const ctx = loadRunContext(root, run.flowDir, run.runDir, flow, runId, catalogue);
2208
- if (!ctx.flowRead.ok || !isResultRun(ctx.arbiter)) return null;
2253
+ if (!ctx.flowRead.ok || !hasResultCards(ctx.arbiter, ctx.flowRead.declaration)) return null;
2209
2254
  return { run, ctx };
2210
2255
  }
2211
2256
 
@@ -2266,6 +2311,45 @@ export function getTicketList({
2266
2311
  });
2267
2312
  }
2268
2313
 
2314
+ /**
2315
+ * M13 piece 6 (item 8): the Result tab's ONE grid of a job, all its runs (`buildJobGrid`, src/panel/jobgrid.js). Each run is read once through `loadRunContext`
2316
+ * (the glyph is `computeGlyph`'s, the money the history row's), a ticket run is named by the ticket number its `run.json` recorded. `Run it anyway` is offered
2317
+ * only for a ticket the ticket list (M12) puts in Skipped. `null` = the flow does not resolve.
2318
+ * @param {{root: string, flow: string, catalogue: any, now?: () => number}} a
2319
+ */
2320
+ export function getJobGrid({
2321
+ root, flow, catalogue, now = Date.now,
2322
+ }) {
2323
+ const fd = resolveFlowDir(root, flow);
2324
+ if (!fd.ok || !existsSync(fd.flowDir)) return null;
2325
+ const { flowDir } = fd;
2326
+ const runs = [];
2327
+ let flowType = null;
2328
+ for (const runId of listRunIds(flowDir)) {
2329
+ const run = resolveRunPath(root, flow, runId);
2330
+ if (!run.ok || !existsSync(run.runDir)) continue; // eslint-disable-line no-continue
2331
+ const ctx = loadRunContext(root, run.flowDir, run.runDir, flow, runId, catalogue, null);
2332
+ if (flowType === null && ctx.flowRead.ok) flowType = flowTypeOf(ctx.flowRead.declaration);
2333
+ const g = computeGlyph(ctx);
2334
+ const inputs = readRunInputs(run.runDir);
2335
+ const entry = inputs.ok ? inputs.entries.find((e) => e && e.ticket && Number.isInteger(e.ticket.number)) : null;
2336
+ const at = typeof ctx.historyRow?.at === 'string' ? Date.parse(ctx.historyRow.at) : NaN;
2337
+ runs.push({
2338
+ runId, glyph: g.glyph, ticket: entry ? entry.ticket.number : null, title: entry && typeof entry.ticket.title === 'string' ? entry.ticket.title : null, unsure: filterUnsure(entry), at: Number.isFinite(at) ? at : null,
2339
+ history: ctx.historyRow ?? null, spendRows: ctx.spendRows, diary: readChecks(run.runDir),
2340
+ steps: ctx.flowRead.ok ? (ctx.flowRead.declaration?.steps ?? []) : [],
2341
+ reason: g.glyph === '[–]' ? g.label.replace(/^skipped — ?/, '') || null : null,
2342
+ });
2343
+ }
2344
+ const sched = readSchedule(flowDir);
2345
+ const from = sched && sched.trigger?.kind === 'new-ticket' && typeof sched.from === 'string' ? sched.from : null;
2346
+ const list = from !== null && ticketScheduleOf(flowDir, from) !== null ? getTicketList({
2347
+ root, flow, runId: from, catalogue,
2348
+ }) : null;
2349
+ const numbers = new Set((list?.groups.find((x) => x.key === 'skip')?.rows ?? []).map((r) => r.number));
2350
+ return { flowType, ...buildJobGrid({ runs, anyway: from !== null ? { runId: from, numbers } : null, now: now() }) };
2351
+ }
2352
+
2269
2353
  /**
2270
2354
  * `GET /api/runs/:flow/:runId/download?i=<n>` (M10 am4): one saved file, or why not.
2271
2355
  * @param {{root: string, flow: string, runId: string, catalogue: any, index: unknown}} a
@@ -2785,6 +2869,9 @@ export function getRunAsks({
2785
2869
  if (!results) return ask;
2786
2870
  return { ...ask, evidence: { ...ev, cited: citedLineOfResults(results, cited) } };
2787
2871
  };
2872
+ // M13 piece 7 (9.4): the same reader as the grid's mark (filterUnsure), so the ask page and the grid never disagree
2873
+ const runInputs = readRunInputs(run.runDir);
2874
+ const filterUnsureRun = runInputs.ok && runInputs.entries.some(filterUnsure);
2788
2875
  const asks = ordered.map(withSheet).map(withCited).map((ask, i) => ({
2789
2876
  ...ask,
2790
2877
  ...deriveAskOpenFields(ask, hasHistoryRow, resume),
@@ -2795,6 +2882,7 @@ export function getRunAsks({
2795
2882
  stepName: stepInfo[i].step,
2796
2883
  stepLine: stepInfo[i].line,
2797
2884
  stepWhy: stepInfo[i].why,
2885
+ ...(filterUnsureRun ? { filterUnsure: true } : {}),
2798
2886
  }));
2799
2887
  // M11 am11 item 3: the Ask tab of an expired-ask run offers Remove from Needs you when the card is in Needs you now
2800
2888
  const needs = getRunNeeds({