fwdloop 0.27.0 → 0.28.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 (67) hide show
  1. package/bin/fwdloop +27 -8
  2. package/package.json +2 -2
  3. package/src/authoring.js +11 -1
  4. package/src/canrun.js +19 -16
  5. package/src/config.js +18 -0
  6. package/src/declaration.js +32 -2
  7. package/src/drafter.js +29 -14
  8. package/src/flow.js +2 -1
  9. package/src/launcher.js +4 -2
  10. package/src/learnstore.js +2 -1
  11. package/src/mcp-checks.js +50 -0
  12. package/src/mcp-pick.js +33 -0
  13. package/src/mcp-sources.js +84 -0
  14. package/src/mcp-use.js +54 -0
  15. package/src/natural.js +23 -0
  16. package/src/panel/author.js +19 -19
  17. package/src/panel/authorcard.js +35 -0
  18. package/src/panel/authorflows.js +18 -14
  19. package/src/panel/authortrigger.js +241 -84
  20. package/src/panel/data.js +89 -6
  21. package/src/panel/index.html +552 -157
  22. package/src/panel/jobgrid.js +127 -0
  23. package/src/panel/scheduler.js +8 -2
  24. package/src/panel/server.js +15 -6
  25. package/src/panel/settings.js +119 -4
  26. package/src/panel/tickets.js +12 -7
  27. package/src/primitives.js +34 -5
  28. package/src/runner.js +88 -15
  29. package/src/summary-words.js +15 -3
  30. package/src/ticket-draft.js +40 -42
  31. package/src/ticket-labels.js +10 -0
  32. package/src/ticket-mcp.js +33 -10
  33. package/src/ticket-next.js +33 -0
  34. package/src/ticket-shape.js +9 -0
  35. package/src/trigger-clock.js +4 -4
  36. package/src/trigger-files.js +3 -3
  37. package/src/trigger-tickets.js +41 -12
  38. package/types/authoring.d.ts +5 -1
  39. package/types/canrun.d.ts +5 -12
  40. package/types/config.d.ts +6 -0
  41. package/types/declaration.d.ts +8 -0
  42. package/types/drafter.d.ts +447 -38
  43. package/types/mcp-checks.d.ts +8 -0
  44. package/types/mcp-pick.d.ts +23 -0
  45. package/types/mcp-sources.d.ts +51 -0
  46. package/types/mcp-use.d.ts +12 -0
  47. package/types/natural.d.ts +2 -0
  48. package/types/panel/author.d.ts +36 -0
  49. package/types/panel/authorcard.d.ts +11 -0
  50. package/types/panel/authorflows.d.ts +9 -1
  51. package/types/panel/authortrigger.d.ts +73 -7
  52. package/types/panel/data.d.ts +56 -2
  53. package/types/panel/jobgrid.d.ts +109 -0
  54. package/types/panel/server.d.ts +5 -1
  55. package/types/panel/settings.d.ts +3 -2
  56. package/types/panel/tickets.d.ts +26 -4
  57. package/types/primitives.d.ts +15 -2
  58. package/types/runner.d.ts +112 -72
  59. package/types/summary-words.d.ts +22 -3
  60. package/types/ticket-draft.d.ts +40 -32
  61. package/types/ticket-labels.d.ts +6 -0
  62. package/types/ticket-mcp.d.ts +18 -1
  63. package/types/ticket-next.d.ts +23 -0
  64. package/types/ticket-shape.d.ts +5 -0
  65. package/types/trigger-clock.d.ts +4 -3
  66. package/types/trigger-files.d.ts +1 -1
  67. package/types/trigger-tickets.d.ts +18 -4
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 {
@@ -47,7 +48,13 @@ import {
47
48
  } from '../summary-words.js';
48
49
  import { MAX_STRUCTURE_RETRIES } from '../drafter.js';
49
50
  import { isResultRun, checkTypeOf, buildResult, downloadOf, readCitedChecks } from './result.js';
50
- import { ticketListOf } from './tickets.js';
51
+ import { ticketListOf, ticketScheduleOf } from './tickets.js';
52
+ import { buildJobGrid } from './jobgrid.js';
53
+ import { readChecks } from '../diary.js';
54
+ import { readRunInputs } 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,
@@ -1807,6 +1815,9 @@ export function getRunDetail({
1807
1815
  })),
1808
1816
  // 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
1817
  hasResult: isResultRun(ctx.arbiter),
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: isResultRun(ctx.arbiter) || 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 }),
@@ -2092,6 +2103,32 @@ function buildJobPlan(declaration, asks, flowDir, flowHash = null, jobLines = /*
2092
2103
  return { steps, notChecked: { label: NOT_CHECKED_LABEL, items: view.items, readNotes: view.readNotes, recorded } };
2093
2104
  }
2094
2105
 
2106
+ /**
2107
+ * 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
2108
+ * (`read-only` or null); no check, or a tool it does not name, is null (the page shows the name alone).
2109
+ * @param {any} declaration @param {(() => Map<string, any>)|undefined} mcpChecks
2110
+ */
2111
+ function mcpJobFields(declaration, mcpChecks) {
2112
+ const flowType = flowTypeOf(declaration);
2113
+ if (flowType === 'plain') return {};
2114
+ const server = declaration.mcp?.server ?? null;
2115
+ /** @type {any|null} */
2116
+ let newest = null;
2117
+ for (const r of (mcpChecks ? mcpChecks().values() : [])) {
2118
+ if (r.server === server && r.ok === true && Array.isArray(r.tools) && (newest === null || String(r.at) > String(newest.at))) newest = r;
2119
+ }
2120
+ const names = Array.isArray(declaration.mcp?.tools) ? declaration.mcp.tools : [];
2121
+ const tools = names.map((/** @type {any} */ t) => {
2122
+ const name = typeof t === 'string' ? t : String(t?.name);
2123
+ const hit = newest?.tools.find((/** @type {any} */ x) => x?.name === name);
2124
+ return { name, hint: hit?.hint === 'read-only' ? 'read-only' : null };
2125
+ });
2126
+ return {
2127
+ flowType, mcp: server, tools,
2128
+ ...(flowType === 'tickets' ? { ticketFilter: declaration.ticketFilter ?? null, ticketWatch: declaration.ticketWatch ?? null } : {}),
2129
+ };
2130
+ }
2131
+
2095
2132
  /**
2096
2133
  * `GET /api/runs/:flow/:runId/job` — the Job tab (hamr's 2026-09-27
2097
2134
  * exit-check review #5: bareloop-style one-field-per-piece layout,
@@ -2101,11 +2138,13 @@ function buildJobPlan(declaration, asks, flowDir, flowHash = null, jobLines = /*
2101
2138
  * name carries its own why, never a blank or a guess. Field order (server
2102
2139
  * order matches the page's own render order): prose, asks, model, cap
2103
2140
  * (+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
2141
+ * 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);
2142
+ * 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).
2143
+ * @param {{root: string, flow: string, runId: string, catalogue: any, scheduleRead?: (flow: string) => any, home?: string, mcpChecks?: () => Map<string, any>}} opts
2105
2144
  * @returns {any|null}
2106
2145
  */
2107
2146
  export function getRunJob({
2108
- root, flow, runId, catalogue, scheduleRead, home,
2147
+ root, flow, runId, catalogue, scheduleRead, home, mcpChecks,
2109
2148
  }) {
2110
2149
  const run = resolveRunPath(root, flow, runId);
2111
2150
  if (!run.ok) return null;
@@ -2144,6 +2183,7 @@ export function getRunJob({
2144
2183
  flow,
2145
2184
  runId,
2146
2185
  resolved: true,
2186
+ ...mcpJobFields(flowRead.declaration, mcpChecks),
2147
2187
  // 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
2188
  started: startedWords(readTriggerRecord(run.runDir), (() => { const at = firstPidStartedAt(run.runDir); return at === null ? null : Date.parse(at); })(), home),
2149
2189
  schedule: (() => {
@@ -2266,6 +2306,45 @@ export function getTicketList({
2266
2306
  });
2267
2307
  }
2268
2308
 
2309
+ /**
2310
+ * 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`
2311
+ * (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
2312
+ * only for a ticket the ticket list (M12) puts in Skipped. `null` = the flow does not resolve.
2313
+ * @param {{root: string, flow: string, catalogue: any, now?: () => number}} a
2314
+ */
2315
+ export function getJobGrid({
2316
+ root, flow, catalogue, now = Date.now,
2317
+ }) {
2318
+ const fd = resolveFlowDir(root, flow);
2319
+ if (!fd.ok || !existsSync(fd.flowDir)) return null;
2320
+ const { flowDir } = fd;
2321
+ const runs = [];
2322
+ let flowType = null;
2323
+ for (const runId of listRunIds(flowDir)) {
2324
+ const run = resolveRunPath(root, flow, runId);
2325
+ if (!run.ok || !existsSync(run.runDir)) continue; // eslint-disable-line no-continue
2326
+ const ctx = loadRunContext(root, run.flowDir, run.runDir, flow, runId, catalogue, null);
2327
+ if (flowType === null && ctx.flowRead.ok) flowType = flowTypeOf(ctx.flowRead.declaration);
2328
+ const g = computeGlyph(ctx);
2329
+ const inputs = readRunInputs(run.runDir);
2330
+ const entry = inputs.ok ? inputs.entries.find((e) => e && e.ticket && Number.isInteger(e.ticket.number)) : null;
2331
+ const at = typeof ctx.historyRow?.at === 'string' ? Date.parse(ctx.historyRow.at) : NaN;
2332
+ runs.push({
2333
+ 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,
2334
+ history: ctx.historyRow ?? null, spendRows: ctx.spendRows, diary: readChecks(run.runDir),
2335
+ steps: ctx.flowRead.ok ? (ctx.flowRead.declaration?.steps ?? []) : [],
2336
+ reason: g.glyph === '[–]' ? g.label.replace(/^skipped — ?/, '') || null : null,
2337
+ });
2338
+ }
2339
+ const sched = readSchedule(flowDir);
2340
+ const from = sched && sched.trigger?.kind === 'new-ticket' && typeof sched.from === 'string' ? sched.from : null;
2341
+ const list = from !== null && ticketScheduleOf(flowDir, from) !== null ? getTicketList({
2342
+ root, flow, runId: from, catalogue,
2343
+ }) : null;
2344
+ const numbers = new Set((list?.groups.find((x) => x.key === 'skip')?.rows ?? []).map((r) => r.number));
2345
+ return { flowType, ...buildJobGrid({ runs, anyway: from !== null ? { runId: from, numbers } : null, now: now() }) };
2346
+ }
2347
+
2269
2348
  /**
2270
2349
  * `GET /api/runs/:flow/:runId/download?i=<n>` (M10 am4): one saved file, or why not.
2271
2350
  * @param {{root: string, flow: string, runId: string, catalogue: any, index: unknown}} a
@@ -2785,6 +2864,9 @@ export function getRunAsks({
2785
2864
  if (!results) return ask;
2786
2865
  return { ...ask, evidence: { ...ev, cited: citedLineOfResults(results, cited) } };
2787
2866
  };
2867
+ // M13 piece 7 (9.4): the same reader as the grid's mark (filterUnsure), so the ask page and the grid never disagree
2868
+ const runInputs = readRunInputs(run.runDir);
2869
+ const filterUnsureRun = runInputs.ok && runInputs.entries.some(filterUnsure);
2788
2870
  const asks = ordered.map(withSheet).map(withCited).map((ask, i) => ({
2789
2871
  ...ask,
2790
2872
  ...deriveAskOpenFields(ask, hasHistoryRow, resume),
@@ -2795,6 +2877,7 @@ export function getRunAsks({
2795
2877
  stepName: stepInfo[i].step,
2796
2878
  stepLine: stepInfo[i].line,
2797
2879
  stepWhy: stepInfo[i].why,
2880
+ ...(filterUnsureRun ? { filterUnsure: true } : {}),
2798
2881
  }));
2799
2882
  // 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
2883
  const needs = getRunNeeds({