@llm4ts/flow 2.53.0 → 2.54.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 (70) hide show
  1. package/dist/Approval.d.ts +1 -1
  2. package/dist/Approval.d.ts.map +1 -1
  3. package/dist/Artifacts.d.ts +2 -2
  4. package/dist/Artifacts.d.ts.map +1 -1
  5. package/dist/BenchReport.d.ts +2 -2
  6. package/dist/BenchReport.d.ts.map +1 -1
  7. package/dist/CostLedger.d.ts +2 -2
  8. package/dist/CostLedger.d.ts.map +1 -1
  9. package/dist/Equiv.d.ts +3 -3
  10. package/dist/Equiv.d.ts.map +1 -1
  11. package/dist/Flow.d.ts +1 -1
  12. package/dist/Flow.d.ts.map +1 -1
  13. package/dist/FlowError.d.ts +25 -1
  14. package/dist/FlowError.d.ts.map +1 -1
  15. package/dist/FlowError.js +33 -1
  16. package/dist/FlowError.js.map +1 -1
  17. package/dist/FlowEvents.d.ts +21 -1
  18. package/dist/FlowEvents.d.ts.map +1 -1
  19. package/dist/FlowEvents.js +19 -0
  20. package/dist/FlowEvents.js.map +1 -1
  21. package/dist/Gates.d.ts +1 -1
  22. package/dist/Gates.d.ts.map +1 -1
  23. package/dist/GraphCache.d.ts +1 -1
  24. package/dist/GraphCache.d.ts.map +1 -1
  25. package/dist/Judgment.d.ts +2 -2
  26. package/dist/Judgment.d.ts.map +1 -1
  27. package/dist/Landing.d.ts +1 -1
  28. package/dist/Landing.d.ts.map +1 -1
  29. package/dist/Memory.d.ts +35 -0
  30. package/dist/Memory.d.ts.map +1 -0
  31. package/dist/Memory.js +139 -0
  32. package/dist/Memory.js.map +1 -0
  33. package/dist/NodePreflight.d.ts +1 -1
  34. package/dist/NodePreflight.d.ts.map +1 -1
  35. package/dist/Persistence.d.ts +2 -2
  36. package/dist/Persistence.d.ts.map +1 -1
  37. package/dist/PlanExecution.d.ts +2 -2
  38. package/dist/PlanExecution.d.ts.map +1 -1
  39. package/dist/ProgramJudge.d.ts +1 -1
  40. package/dist/ProgramJudge.d.ts.map +1 -1
  41. package/dist/Replay.d.ts +2 -2
  42. package/dist/Replay.d.ts.map +1 -1
  43. package/dist/Retro.d.ts +3 -3
  44. package/dist/Retro.d.ts.map +1 -1
  45. package/dist/Review.d.ts +5 -5
  46. package/dist/Review.d.ts.map +1 -1
  47. package/dist/ReviewCache.d.ts +1 -1
  48. package/dist/ReviewCache.d.ts.map +1 -1
  49. package/dist/Roster.d.ts +1 -1
  50. package/dist/Roster.d.ts.map +1 -1
  51. package/dist/RosterSeats.d.ts +1 -1
  52. package/dist/RosterSeats.d.ts.map +1 -1
  53. package/dist/Roundtable.d.ts +17 -4
  54. package/dist/Roundtable.d.ts.map +1 -1
  55. package/dist/Roundtable.js +45 -6
  56. package/dist/Roundtable.js.map +1 -1
  57. package/dist/Stories.d.ts +1 -1
  58. package/dist/Stories.d.ts.map +1 -1
  59. package/dist/Taskforce.d.ts +293 -0
  60. package/dist/Taskforce.d.ts.map +1 -0
  61. package/dist/Taskforce.js +1063 -0
  62. package/dist/Taskforce.js.map +1 -0
  63. package/dist/WorkQueue.d.ts +1 -1
  64. package/dist/WorkQueue.d.ts.map +1 -1
  65. package/package.json +4 -2
  66. package/src/FlowError.ts +36 -1
  67. package/src/FlowEvents.ts +21 -0
  68. package/src/Memory.ts +151 -0
  69. package/src/Roundtable.ts +49 -6
  70. package/src/Taskforce.ts +1248 -0
@@ -0,0 +1,1063 @@
1
+ /**
2
+ * taskforce (ADR 0047): the pure half of the delegation loop. The plan file
3
+ * and the reports are the state; this module parses and renders them,
4
+ * derives what is ready, blocked, checked and done, and tells the flow what
5
+ * to do next (`nextAction`). Nothing here talks to a model, a file or a
6
+ * process; the flow does.
7
+ */
8
+ import * as Effect from "effect/Effect";
9
+ import * as Schema from "effect/Schema";
10
+ import { makeOpenPointsCollector, OpenPoint } from "./Decisions.js";
11
+ import { PlanInvalid, ReportInvalid } from "./FlowError.js";
12
+ export { ToolGrade } from "./Roundtable.js";
13
+ const dash = " — ";
14
+ const headerLine = /^([A-Za-z][A-Za-z ]*):\s*(.*)$/;
15
+ const oneLine = (text) => text.replace(/\s+/g, " ").trim();
16
+ const prose = (text) => text.trim().length === 0 ? [] : text.trim().split(/\r?\n/);
17
+ const bulletLines = (text) => prose(text)
18
+ .map((line) => line.trim().replace(/^-\s*/, "").trim())
19
+ .filter((line) => line.length > 0);
20
+ // ---- The plan file --------------------------------------------------------------
21
+ export const PlanStatus = Schema.Literals([
22
+ "planned",
23
+ "working",
24
+ "drafting",
25
+ "reviewing",
26
+ "fixing",
27
+ "distilling",
28
+ "done"
29
+ ]);
30
+ const isPlanStatus = (value) => PlanStatus.literals.some((status) => status === value);
31
+ /** The eight fields of a brief, in the order the file shows them (pstack's template). */
32
+ export const briefFields = [
33
+ "GOAL",
34
+ "SCOPE",
35
+ "CONTEXT",
36
+ "ACCEPTANCE",
37
+ "VERIFY",
38
+ "TIMEBOX",
39
+ "FORBIDDEN",
40
+ "REPORT"
41
+ ];
42
+ const fieldKeys = {
43
+ GOAL: "goal",
44
+ SCOPE: "scope",
45
+ CONTEXT: "context",
46
+ ACCEPTANCE: "acceptance",
47
+ VERIFY: "verify",
48
+ TIMEBOX: "timebox",
49
+ FORBIDDEN: "forbidden",
50
+ REPORT: "report"
51
+ };
52
+ const isBriefField = (value) => briefFields.some((field) => field === value);
53
+ /** One unit of delegated work: an owner, dependencies, a wave, the eight fields. */
54
+ export class Brief extends Schema.Class("Brief")({
55
+ /** `B1`, `B2`, … in the order they were added to the plan. */
56
+ id: Schema.String,
57
+ title: Schema.String,
58
+ /** A specialist's name from the cast. */
59
+ owner: Schema.String,
60
+ dependsOn: Schema.Array(Schema.String),
61
+ /** The wave it was planned in: 1 the plan, 2 a re-plan or rework, the fix wave after a review. */
62
+ wave: Schema.Int,
63
+ goal: Schema.String,
64
+ scope: Schema.String,
65
+ context: Schema.String,
66
+ /** One line per criterion, as written (bullets kept). */
67
+ acceptance: Schema.String,
68
+ /** One command per line; only a `commands` card ever runs them. */
69
+ verify: Schema.String,
70
+ timebox: Schema.String,
71
+ forbidden: Schema.String,
72
+ /** What the report must hold, and which deliverable it feeds. */
73
+ report: Schema.String
74
+ }) {
75
+ }
76
+ /** The Chief of Staff's verdict after a wave. */
77
+ export class GoalCheck extends Schema.Class("GoalCheck")({
78
+ wave: Schema.Int,
79
+ reached: Schema.Boolean,
80
+ note: Schema.String
81
+ }) {
82
+ }
83
+ export class Plan extends Schema.Class("TaskforcePlan")({
84
+ id: Schema.String,
85
+ status: PlanStatus,
86
+ goal: Schema.String,
87
+ /** File names the Doc Writer writes; `result.md` is always among them. */
88
+ deliverables: Schema.Array(Schema.String),
89
+ /** Every specialist present, the Chief of Staff and the Doc Writer included. */
90
+ cast: Schema.Array(Schema.String),
91
+ briefs: Schema.Array(Brief),
92
+ checks: Schema.Array(GoalCheck),
93
+ /** Questions for the owner, with the assumption the run took; an answer here reopens work. */
94
+ answers: Schema.Array(OpenPoint),
95
+ feedback: Schema.String,
96
+ /** Drafts the Doc Writer wrote: 0 none, 1 reviewed, 2 redrafted after the fix wave. */
97
+ drafts: Schema.Int,
98
+ /** Answer numbers already folded into a brief, so a rerun does not fold them twice. */
99
+ folded: Schema.Array(Schema.Int)
100
+ }) {
101
+ }
102
+ /** The turn cap a TIMEBOX names (`20 turns`, `20`), when it names one. */
103
+ export const timeboxTurns = (brief) => {
104
+ const match = /(\d+)/.exec(brief.timebox);
105
+ const turns = match === null ? undefined : Number.parseInt(match[1] ?? "", 10);
106
+ return turns === undefined || Number.isNaN(turns) || turns <= 0 ? undefined : turns;
107
+ };
108
+ /** The VERIFY lines as commands: bullets stripped, blanks dropped. */
109
+ export const verifyCommands = (brief) => bulletLines(brief.verify);
110
+ /** The ACCEPTANCE lines as criteria. */
111
+ export const acceptanceLines = (brief) => bulletLines(brief.acceptance);
112
+ export const renderBrief = (brief) => [
113
+ `### ${brief.id}. ${brief.title}`,
114
+ `Owner: ${brief.owner}`,
115
+ `Depends on: ${brief.dependsOn.length === 0 ? "-" : brief.dependsOn.join(", ")}`,
116
+ `Wave: ${brief.wave}`,
117
+ "",
118
+ ...briefFields.flatMap((field) => {
119
+ const body = brief[fieldKeys[field]];
120
+ const lines = prose(body);
121
+ return lines.length <= 1 ? [`${field}: ${lines[0] ?? ""}`.trimEnd()] : [`${field}:`, ...lines];
122
+ }),
123
+ ""
124
+ ];
125
+ const renderCheck = (check) => `- wave ${check.wave}: ${check.reached ? "reached" : "not reached"}${dash}${oneLine(check.note)}`;
126
+ export const renderPlan = (plan) => [
127
+ `# Taskforce: ${plan.id}`,
128
+ "",
129
+ `Status: ${plan.status}`,
130
+ `Goal: ${plan.goal}`,
131
+ `Deliverables: ${plan.deliverables.join(", ")}`,
132
+ `Cast: ${plan.cast.join(", ")}`,
133
+ `Drafts: ${plan.drafts}`,
134
+ `Folded: ${plan.folded.length === 0 ? "-" : plan.folded.join(", ")}`,
135
+ "",
136
+ "## Briefs",
137
+ "",
138
+ ...plan.briefs.flatMap(renderBrief),
139
+ "## Goal checks",
140
+ "",
141
+ ...(plan.checks.length === 0 ? ["- none"] : plan.checks.map(renderCheck)),
142
+ "",
143
+ "## Answers",
144
+ "",
145
+ ...plan.answers.flatMap((point) => [
146
+ `${point.number}. ${point.question}`,
147
+ ` answer:${(point.answer ?? "").trim().length === 0 ? "" : ` ${(point.answer ?? "").trim()}`}`
148
+ ]),
149
+ "",
150
+ "## Feedback",
151
+ "",
152
+ ...prose(plan.feedback),
153
+ ""
154
+ ].join("\n");
155
+ const settledPoint = (point) => (point.answer ?? "").trim().length === 0
156
+ ? OpenPoint.make({ number: point.number, question: point.question })
157
+ : OpenPoint.make({
158
+ number: point.number,
159
+ question: point.question,
160
+ answer: (point.answer ?? "").trim()
161
+ });
162
+ const planSections = {
163
+ briefs: "briefs",
164
+ "goal checks": "checks",
165
+ answers: "answers",
166
+ feedback: "feedback"
167
+ };
168
+ const splitList = (value) => value === "-"
169
+ ? []
170
+ : value
171
+ .split(",")
172
+ .map((entry) => entry.trim())
173
+ .filter((entry) => entry.length > 0);
174
+ const emptyFields = () => ({
175
+ GOAL: [],
176
+ SCOPE: [],
177
+ CONTEXT: [],
178
+ ACCEPTANCE: [],
179
+ VERIFY: [],
180
+ TIMEBOX: [],
181
+ FORBIDDEN: [],
182
+ REPORT: []
183
+ });
184
+ export const parsePlan = Effect.fn("@llm4ts/flow/Taskforce.parsePlan")(function* (markdown, path) {
185
+ const violations = [];
186
+ let id;
187
+ let status;
188
+ let drafts = 0;
189
+ let folded = [];
190
+ const header = {};
191
+ const briefs = [];
192
+ const checks = [];
193
+ const points = makeOpenPointsCollector();
194
+ const feedback = [];
195
+ let current = "header";
196
+ let fenced = false;
197
+ const lines = markdown.split(/\r?\n/);
198
+ for (let index = 0; index < lines.length; index += 1) {
199
+ const number = index + 1;
200
+ const raw = lines[index] ?? "";
201
+ const trimmed = raw.trim();
202
+ if (trimmed.startsWith("```")) {
203
+ fenced = !fenced;
204
+ if (current === "feedback")
205
+ feedback.push(raw);
206
+ else if (current === "briefs") {
207
+ const brief = briefs.at(-1);
208
+ if (brief?.field !== undefined)
209
+ brief.fields[brief.field].push(raw);
210
+ }
211
+ continue;
212
+ }
213
+ if (!fenced && trimmed.startsWith("## ")) {
214
+ const title = trimmed.slice(3).trim();
215
+ const key = planSections[title.toLowerCase()];
216
+ if (key === undefined) {
217
+ violations.push(`line ${number}: unknown section "${title}"`);
218
+ current = "unknown";
219
+ }
220
+ else {
221
+ current = key;
222
+ }
223
+ continue;
224
+ }
225
+ if (current === "feedback") {
226
+ feedback.push(raw);
227
+ continue;
228
+ }
229
+ if (current === "briefs") {
230
+ const opened = /^###\s+(B\d+)\.\s+(.*)$/.exec(trimmed);
231
+ if (!fenced && opened !== null) {
232
+ briefs.push({
233
+ id: opened[1] ?? "",
234
+ title: (opened[2] ?? "").trim(),
235
+ owner: undefined,
236
+ dependsOn: [],
237
+ wave: undefined,
238
+ fields: emptyFields(),
239
+ field: undefined,
240
+ line: number
241
+ });
242
+ continue;
243
+ }
244
+ const brief = briefs.at(-1);
245
+ if (brief === undefined) {
246
+ if (trimmed.length > 0) {
247
+ violations.push(`line ${number}: a brief starts with \`### B1. <title>\`, got: ${trimmed}`);
248
+ }
249
+ continue;
250
+ }
251
+ const field = /^([A-Z]+):\s?(.*)$/.exec(fenced ? "" : raw);
252
+ if (field !== null && isBriefField(field[1] ?? "")) {
253
+ const name = field[1] ?? "GOAL";
254
+ if (isBriefField(name)) {
255
+ brief.field = name;
256
+ const rest = (field[2] ?? "").trimEnd();
257
+ if (rest.trim().length > 0)
258
+ brief.fields[name].push(rest);
259
+ }
260
+ continue;
261
+ }
262
+ if (brief.field === undefined) {
263
+ const meta = headerLine.exec(trimmed);
264
+ if (meta?.[1] === undefined) {
265
+ if (trimmed.length > 0) {
266
+ violations.push(`line ${number}: a brief's header is Owner:, Depends on:, Wave:, got: ${trimmed}`);
267
+ }
268
+ continue;
269
+ }
270
+ const name = meta[1].toLowerCase();
271
+ const value = (meta[2] ?? "").trim();
272
+ if (name === "owner")
273
+ brief.owner = value;
274
+ else if (name === "depends on")
275
+ brief.dependsOn = splitList(value);
276
+ else if (name === "wave") {
277
+ if (/^\d+$/.test(value))
278
+ brief.wave = Number.parseInt(value, 10);
279
+ else
280
+ violations.push(`line ${number}: Wave is a whole number, got: ${value}`);
281
+ }
282
+ else {
283
+ violations.push(`line ${number}: unknown brief header ${meta[1]}`);
284
+ }
285
+ continue;
286
+ }
287
+ brief.fields[brief.field].push(raw);
288
+ continue;
289
+ }
290
+ if (fenced || trimmed.length === 0 || current === "unknown")
291
+ continue;
292
+ if (current === "header") {
293
+ const title = /^#\s+Taskforce:\s*(.+)$/i.exec(trimmed);
294
+ if (title?.[1] !== undefined) {
295
+ id = title[1].trim();
296
+ continue;
297
+ }
298
+ const field = headerLine.exec(trimmed);
299
+ if (field?.[1] === undefined)
300
+ continue;
301
+ const name = field[1].toLowerCase();
302
+ const value = (field[2] ?? "").trim();
303
+ if (name === "status") {
304
+ if (isPlanStatus(value))
305
+ status = value;
306
+ else {
307
+ violations.push(`line ${number}: Status is one of ${PlanStatus.literals.join(", ")}, got: ${value}`);
308
+ status = "working";
309
+ }
310
+ }
311
+ else if (name === "drafts") {
312
+ if (/^\d+$/.test(value))
313
+ drafts = Number.parseInt(value, 10);
314
+ else
315
+ violations.push(`line ${number}: Drafts is a whole number, got: ${value}`);
316
+ }
317
+ else if (name === "folded") {
318
+ folded = splitList(value).flatMap((entry) => /^\d+$/.test(entry) ? [Number.parseInt(entry, 10)] : []);
319
+ }
320
+ else {
321
+ header[name] = value;
322
+ }
323
+ continue;
324
+ }
325
+ if (current === "answers") {
326
+ const problem = points.add(number, trimmed);
327
+ if (problem !== undefined)
328
+ violations.push(problem);
329
+ continue;
330
+ }
331
+ if (current === "checks") {
332
+ if (trimmed === "- none")
333
+ continue;
334
+ const check = /^-\s*wave\s+(\d+):\s*(reached|not reached)(?:\s*—\s*(.*))?$/.exec(trimmed);
335
+ if (check === null) {
336
+ violations.push(`line ${number}: a goal check is \`- wave <n>: reached|not reached${dash}<note>\`, got: ${trimmed}`);
337
+ }
338
+ else {
339
+ checks.push(GoalCheck.make({
340
+ wave: Number.parseInt(check[1] ?? "0", 10),
341
+ reached: check[2] === "reached",
342
+ note: (check[3] ?? "").trim()
343
+ }));
344
+ }
345
+ }
346
+ }
347
+ if (id === undefined)
348
+ violations.push("missing the `# Taskforce: <id>` title");
349
+ if (status === undefined)
350
+ violations.push("missing the `Status:` line");
351
+ if (header.goal === undefined)
352
+ violations.push("missing the `Goal:` line");
353
+ if (header.cast === undefined)
354
+ violations.push("missing the `Cast:` line");
355
+ if (fenced)
356
+ violations.push("a code fence is never closed");
357
+ for (const brief of briefs) {
358
+ if (brief.owner === undefined)
359
+ violations.push(`line ${brief.line}: ${brief.id} has no Owner:`);
360
+ if (brief.wave === undefined)
361
+ violations.push(`line ${brief.line}: ${brief.id} has no Wave:`);
362
+ }
363
+ if (violations.length > 0 || id === undefined || status === undefined) {
364
+ return yield* PlanInvalid.make({ ...(path === undefined ? {} : { path }), violations });
365
+ }
366
+ const text = (lines) => lines.join("\n").trim();
367
+ return Plan.make({
368
+ id,
369
+ status,
370
+ goal: header.goal ?? "",
371
+ deliverables: splitList(header.deliverables ?? ""),
372
+ cast: splitList(header.cast ?? ""),
373
+ briefs: briefs.map((brief) => Brief.make({
374
+ id: brief.id,
375
+ title: brief.title,
376
+ owner: brief.owner ?? "",
377
+ dependsOn: brief.dependsOn,
378
+ wave: brief.wave ?? 1,
379
+ goal: text(brief.fields.GOAL),
380
+ scope: text(brief.fields.SCOPE),
381
+ context: text(brief.fields.CONTEXT),
382
+ acceptance: text(brief.fields.ACCEPTANCE),
383
+ verify: text(brief.fields.VERIFY),
384
+ timebox: text(brief.fields.TIMEBOX),
385
+ forbidden: text(brief.fields.FORBIDDEN),
386
+ report: text(brief.fields.REPORT)
387
+ })),
388
+ checks,
389
+ answers: points.points.map(settledPoint),
390
+ feedback: feedback.join("\n").trim(),
391
+ drafts,
392
+ folded
393
+ });
394
+ });
395
+ export const defaultCaps = { waves: 3, briefs: 12 };
396
+ export const minBriefs = 2;
397
+ const hasCycle = (briefs) => {
398
+ const edges = new Map(briefs.map((brief) => [brief.id, brief.dependsOn]));
399
+ const state = new Map();
400
+ const visit = (id) => {
401
+ const seen = state.get(id);
402
+ if (seen === "open")
403
+ return true;
404
+ if (seen === "done")
405
+ return false;
406
+ state.set(id, "open");
407
+ for (const next of edges.get(id) ?? [])
408
+ if (edges.has(next) && visit(next))
409
+ return true;
410
+ state.set(id, "done");
411
+ return false;
412
+ };
413
+ return briefs.some((brief) => visit(brief.id));
414
+ };
415
+ /** Everything that stops a plan from running; empty when it may. */
416
+ export const planViolations = (plan, caps) => {
417
+ const violations = [];
418
+ if (plan.briefs.length < minBriefs || plan.briefs.length > caps.briefs) {
419
+ violations.push(`${minBriefs} to ${caps.briefs} briefs, got ${plan.briefs.length}`);
420
+ }
421
+ const ids = new Set();
422
+ for (const brief of plan.briefs) {
423
+ if (ids.has(brief.id))
424
+ violations.push(`${brief.id}: listed twice`);
425
+ ids.add(brief.id);
426
+ }
427
+ for (const brief of plan.briefs) {
428
+ if (brief.title.trim().length === 0)
429
+ violations.push(`${brief.id}: has no title`);
430
+ if (!plan.cast.includes(brief.owner)) {
431
+ violations.push(`${brief.id}: owner ${brief.owner} is not in the cast`);
432
+ }
433
+ for (const dependency of brief.dependsOn) {
434
+ if (!ids.has(dependency)) {
435
+ violations.push(`${brief.id}: depends on ${dependency}, which is not a brief`);
436
+ }
437
+ }
438
+ if (brief.goal.trim().length === 0)
439
+ violations.push(`${brief.id}: GOAL is empty`);
440
+ if (acceptanceLines(brief).length === 0)
441
+ violations.push(`${brief.id}: ACCEPTANCE is empty`);
442
+ }
443
+ if (hasCycle(plan.briefs))
444
+ violations.push("briefs depend on each other in a cycle");
445
+ for (const deliverable of plan.deliverables) {
446
+ const named = plan.briefs.some((brief) => brief.report.toLowerCase().includes(deliverable.toLowerCase()) ||
447
+ brief.goal.toLowerCase().includes(deliverable.toLowerCase()));
448
+ if (!named)
449
+ violations.push(`deliverable ${deliverable} is named by no brief`);
450
+ }
451
+ return violations;
452
+ };
453
+ // ---- Proposals (what the models reply) ---------------------------------------------
454
+ export class BriefProposal extends Schema.Class("BriefProposal")({
455
+ title: Schema.String,
456
+ owner: Schema.String,
457
+ /** Brief ids (`B3`), the proposal's own numbered from the `from` the prompt names. */
458
+ dependsOn: Schema.Array(Schema.String),
459
+ goal: Schema.String,
460
+ scope: Schema.String,
461
+ context: Schema.String,
462
+ acceptance: Schema.Array(Schema.String),
463
+ verify: Schema.Array(Schema.String),
464
+ timebox: Schema.String,
465
+ forbidden: Schema.String,
466
+ report: Schema.String
467
+ }) {
468
+ }
469
+ const briefProposalJsonSchema = {
470
+ type: "object",
471
+ properties: {
472
+ title: { type: "string" },
473
+ owner: { type: "string" },
474
+ dependsOn: { type: "array", items: { type: "string" } },
475
+ goal: { type: "string" },
476
+ scope: { type: "string" },
477
+ context: { type: "string" },
478
+ acceptance: { type: "array", items: { type: "string" } },
479
+ verify: { type: "array", items: { type: "string" } },
480
+ timebox: { type: "string" },
481
+ forbidden: { type: "string" },
482
+ report: { type: "string" }
483
+ },
484
+ required: [
485
+ "title",
486
+ "owner",
487
+ "dependsOn",
488
+ "goal",
489
+ "scope",
490
+ "context",
491
+ "acceptance",
492
+ "verify",
493
+ "timebox",
494
+ "forbidden",
495
+ "report"
496
+ ]
497
+ };
498
+ export class PlanProposal extends Schema.Class("PlanProposal")({
499
+ deliverables: Schema.Array(Schema.String),
500
+ briefs: Schema.Array(BriefProposal)
501
+ }) {
502
+ }
503
+ export const planProposalJsonSchema = {
504
+ type: "object",
505
+ properties: {
506
+ deliverables: { type: "array", items: { type: "string" } },
507
+ briefs: { type: "array", items: briefProposalJsonSchema }
508
+ },
509
+ required: ["deliverables", "briefs"]
510
+ };
511
+ export class CheckProposal extends Schema.Class("CheckProposal")({
512
+ reached: Schema.Boolean,
513
+ note: Schema.String,
514
+ /** The second wave, when the goal is not reached and a re-plan is allowed; else empty. */
515
+ briefs: Schema.Array(BriefProposal)
516
+ }) {
517
+ }
518
+ export const checkProposalJsonSchema = {
519
+ type: "object",
520
+ properties: {
521
+ reached: { type: "boolean" },
522
+ note: { type: "string" },
523
+ briefs: { type: "array", items: briefProposalJsonSchema }
524
+ },
525
+ required: ["reached", "note", "briefs"]
526
+ };
527
+ export const ReportStatus = Schema.Literals(["PASS", "ISSUES", "BLOCKED"]);
528
+ const isReportStatus = (value) => ReportStatus.literals.some((status) => status === value);
529
+ export class OwnerQuestion extends Schema.Class("OwnerQuestion")({
530
+ question: Schema.String,
531
+ /** What the specialist proceeded on, since nobody answers inside the run. */
532
+ assumption: Schema.String
533
+ }) {
534
+ }
535
+ export class ReportProposal extends Schema.Class("ReportProposal")({
536
+ status: ReportStatus,
537
+ evidence: Schema.Array(Schema.String),
538
+ summary: Schema.String,
539
+ questions: Schema.Array(OwnerQuestion),
540
+ body: Schema.String
541
+ }) {
542
+ }
543
+ export const reportProposalJsonSchema = {
544
+ type: "object",
545
+ properties: {
546
+ status: { type: "string", enum: ["PASS", "ISSUES", "BLOCKED"] },
547
+ evidence: { type: "array", items: { type: "string" } },
548
+ summary: { type: "string" },
549
+ questions: {
550
+ type: "array",
551
+ items: {
552
+ type: "object",
553
+ properties: { question: { type: "string" }, assumption: { type: "string" } },
554
+ required: ["question", "assumption"]
555
+ }
556
+ },
557
+ body: { type: "string" }
558
+ },
559
+ required: ["status", "evidence", "summary", "questions", "body"]
560
+ };
561
+ const joinLines = (lines) => lines
562
+ .map((line) => oneLine(line))
563
+ .filter((line) => line.length > 0)
564
+ .map((line) => `- ${line}`)
565
+ .join("\n");
566
+ /**
567
+ * Proposed briefs as plan briefs: ids from `from`, titles one line,
568
+ * dependencies kept only when they name a brief that exists or is proposed,
569
+ * and VERIFY moved off every card that may not run commands onto a
570
+ * verifying brief owned by the first `commands` card, after the brief it
571
+ * checks (decision 5).
572
+ */
573
+ export const assembleBriefs = (proposals, options, existing = []) => {
574
+ const notes = [];
575
+ const operator = options.cast.find((persona) => persona.tools === "commands");
576
+ const gradeOf = (owner) => options.cast.find((persona) => persona.name === owner)?.tools;
577
+ let next = options.from;
578
+ const proposed = proposals.map(() => `B${next++}`);
579
+ const known = new Set([...existing, ...proposed]);
580
+ const briefs = [];
581
+ const verifiers = [];
582
+ proposals.forEach((proposal, index) => {
583
+ const id = proposed[index] ?? `B${options.from + index}`;
584
+ const dependsOn = [...new Set(proposal.dependsOn.map((entry) => entry.trim()))]
585
+ .filter((entry) => known.has(entry) && entry !== id)
586
+ .sort((left, right) => Number.parseInt(left.slice(1), 10) - Number.parseInt(right.slice(1), 10));
587
+ const verify = joinLines(proposal.verify);
588
+ const runsCommands = gradeOf(proposal.owner) === "commands";
589
+ briefs.push(Brief.make({
590
+ id,
591
+ title: oneLine(proposal.title),
592
+ owner: proposal.owner.trim(),
593
+ dependsOn,
594
+ wave: options.wave,
595
+ goal: proposal.goal.trim(),
596
+ scope: proposal.scope.trim(),
597
+ context: proposal.context.trim(),
598
+ acceptance: joinLines(proposal.acceptance),
599
+ verify: runsCommands ? verify : "",
600
+ timebox: oneLine(proposal.timebox),
601
+ forbidden: proposal.forbidden.trim(),
602
+ report: proposal.report.trim()
603
+ }));
604
+ if (runsCommands || verify.length === 0)
605
+ return;
606
+ if (operator === undefined) {
607
+ notes.push(`${id}: VERIFY dropped — no card in the cast runs commands (add the Operator with --agents)`);
608
+ return;
609
+ }
610
+ const verifier = `B${next++}`;
611
+ verifiers.push(Brief.make({
612
+ id: verifier,
613
+ title: `Verify ${id}`,
614
+ owner: operator.name,
615
+ dependsOn: [id],
616
+ wave: options.wave,
617
+ goal: `Run the checks for ${id} and report what each said.`,
618
+ scope: `The repository as ${id} left it; write nothing.`,
619
+ context: `${id}'s report is in reports/${id}.md.`,
620
+ acceptance: "- Every command's exit code and output are in the report, unparaphrased.",
621
+ verify,
622
+ timebox: "1 run of each command",
623
+ forbidden: "Fixing anything; running a command the VERIFY list does not name.",
624
+ report: `reports/${verifier}.md with the commands, exit codes and output.`
625
+ }));
626
+ });
627
+ return { briefs: [...briefs, ...verifiers], notes };
628
+ };
629
+ // ---- Reports -------------------------------------------------------------------------
630
+ export class Report extends Schema.Class("BriefReport")({
631
+ brief: Schema.String,
632
+ status: ReportStatus,
633
+ /** 1 the first dispatch, 2 the retry after BLOCKED. */
634
+ attempt: Schema.Int,
635
+ evidence: Schema.Array(Schema.String),
636
+ summary: Schema.String,
637
+ questions: Schema.Array(OwnerQuestion),
638
+ body: Schema.String
639
+ }) {
640
+ }
641
+ export const renderReport = (report, title) => [
642
+ `# ${report.brief}: ${oneLine(title)}`,
643
+ `Status: ${report.status}`,
644
+ `Attempt: ${report.attempt}`,
645
+ `Evidence: ${report.evidence.length === 0 ? "-" : report.evidence.map(oneLine).join(", ")}`,
646
+ `Summary: ${oneLine(report.summary)}`,
647
+ ...report.questions.map((question) => `Question: ${oneLine(question.question)} (assuming: ${oneLine(question.assumption)})`),
648
+ "",
649
+ report.body.trim(),
650
+ ""
651
+ ].join("\n");
652
+ export const parseReport = Effect.fn("@llm4ts/flow/Taskforce.parseReport")(function* (markdown, path) {
653
+ const violations = [];
654
+ const lines = markdown.split(/\r?\n/);
655
+ let brief;
656
+ let status;
657
+ let attempt = 1;
658
+ let evidence = [];
659
+ let summary = "";
660
+ const questions = [];
661
+ let index = 0;
662
+ for (; index < lines.length; index += 1) {
663
+ const trimmed = (lines[index] ?? "").trim();
664
+ if (trimmed.length === 0)
665
+ break;
666
+ const title = /^#\s+(B\d+):\s*(.*)$/.exec(trimmed);
667
+ if (title !== null) {
668
+ brief = title[1];
669
+ continue;
670
+ }
671
+ const field = headerLine.exec(trimmed);
672
+ if (field?.[1] === undefined) {
673
+ violations.push(`line ${index + 1}: not a report header line: ${trimmed}`);
674
+ continue;
675
+ }
676
+ const name = field[1].toLowerCase();
677
+ const value = (field[2] ?? "").trim();
678
+ if (name === "status") {
679
+ if (isReportStatus(value))
680
+ status = value;
681
+ else
682
+ violations.push(`line ${index + 1}: Status is PASS, ISSUES or BLOCKED, got: ${value}`);
683
+ }
684
+ else if (name === "attempt") {
685
+ if (/^\d+$/.test(value))
686
+ attempt = Number.parseInt(value, 10);
687
+ else
688
+ violations.push(`line ${index + 1}: Attempt is a whole number, got: ${value}`);
689
+ }
690
+ else if (name === "evidence")
691
+ evidence = splitList(value);
692
+ else if (name === "summary")
693
+ summary = value;
694
+ else if (name === "question") {
695
+ const parts = /^(.*?)\s*\(assuming:\s*(.*)\)$/.exec(value);
696
+ questions.push(OwnerQuestion.make(parts === null
697
+ ? { question: value, assumption: "" }
698
+ : { question: (parts[1] ?? "").trim(), assumption: (parts[2] ?? "").trim() }));
699
+ }
700
+ else
701
+ violations.push(`line ${index + 1}: unknown report header ${field[1]}`);
702
+ }
703
+ if (brief === undefined)
704
+ violations.push("missing the `# B<n>: <title>` title");
705
+ if (status === undefined)
706
+ violations.push("missing the `Status:` line");
707
+ if (violations.length > 0 || brief === undefined || status === undefined) {
708
+ return yield* ReportInvalid.make({ ...(path === undefined ? {} : { path }), violations });
709
+ }
710
+ return Report.make({
711
+ brief,
712
+ status,
713
+ attempt,
714
+ evidence,
715
+ summary,
716
+ questions,
717
+ body: lines.slice(index).join("\n").trim()
718
+ });
719
+ });
720
+ // ---- Derived state (decision 6) -----------------------------------------------------
721
+ export const reportOf = (reports, id) => reports.find((report) => report.brief === id);
722
+ /** PASS and ISSUES end a brief; BLOCKED ends it on the second attempt. */
723
+ export const isFinal = (report) => report.status !== "BLOCKED" || report.attempt >= 2;
724
+ const finallyBlocked = (report) => report !== undefined && report.status === "BLOCKED" && isFinal(report);
725
+ export const currentWave = (plan) => plan.briefs.reduce((wave, brief) => Math.max(wave, brief.wave), 0);
726
+ const openBriefs = (plan, reports) => plan.briefs.filter((brief) => {
727
+ const report = reportOf(reports, brief.id);
728
+ return report === undefined || !isFinal(report);
729
+ });
730
+ /** The reason a brief cannot run: a dependency finally blocked. */
731
+ const deadReason = (brief, reports) => {
732
+ const dead = brief.dependsOn.filter((id) => finallyBlocked(reportOf(reports, id)));
733
+ return dead.length === 0 ? undefined : `depends on ${dead.join(", ")}, blocked twice`;
734
+ };
735
+ /** Open briefs whose dependencies all ended well: what the next dispatch runs together. */
736
+ export const readyBriefs = (plan, reports) => openBriefs(plan, reports).filter((brief) => deadReason(brief, reports) === undefined &&
737
+ brief.dependsOn.every((id) => {
738
+ const report = reportOf(reports, id);
739
+ return report !== undefined && isFinal(report);
740
+ }));
741
+ const pendingOwner = (plan) => ({
742
+ answers: plan.answers.flatMap((point) => {
743
+ const answer = (point.answer ?? "").trim();
744
+ return answer.length === 0 || plan.folded.includes(point.number)
745
+ ? []
746
+ : [{ number: point.number, question: point.question, answer }];
747
+ }),
748
+ feedback: plan.feedback.trim()
749
+ });
750
+ /** What the loop does next, from the plan and the reports alone. */
751
+ export const nextAction = (plan, reports, caps) => {
752
+ if (plan.status === "planned") {
753
+ return plan.briefs.length === 0 ? { _tag: "ProposePlan" } : { _tag: "Open" };
754
+ }
755
+ const owner = pendingOwner(plan);
756
+ if (owner.answers.length > 0 || owner.feedback.length > 0) {
757
+ return { _tag: "RecordOwner", answers: owner.answers, feedback: owner.feedback };
758
+ }
759
+ switch (plan.status) {
760
+ case "working":
761
+ case "fixing": {
762
+ const open = openBriefs(plan, reports);
763
+ if (open.length === 0) {
764
+ if (plan.status === "fixing")
765
+ return { _tag: "Draft", redraft: true };
766
+ const wave = currentWave(plan);
767
+ const checked = plan.checks.some((check) => check.wave === wave);
768
+ if (!checked) {
769
+ return {
770
+ _tag: "Check",
771
+ wave,
772
+ mayReplan: plan.checks.length === 0 && wave < caps.waves
773
+ };
774
+ }
775
+ return { _tag: "Draft", redraft: plan.drafts > 0 };
776
+ }
777
+ for (const brief of open) {
778
+ const reason = deadReason(brief, reports);
779
+ if (reason !== undefined)
780
+ return { _tag: "Skip", brief, reason };
781
+ }
782
+ const ready = readyBriefs(plan, reports);
783
+ if (ready.length === 0) {
784
+ return { _tag: "Refused", reason: "the open briefs wait on each other" };
785
+ }
786
+ // A brief back from BLOCKED runs alone, on its second attempt.
787
+ const retry = ready.find((brief) => reportOf(reports, brief.id) !== undefined);
788
+ return retry === undefined
789
+ ? { _tag: "Dispatch", briefs: ready, attempt: 1 }
790
+ : { _tag: "Dispatch", briefs: [retry], attempt: 2 };
791
+ }
792
+ case "drafting":
793
+ return { _tag: "Draft", redraft: plan.drafts > 0 };
794
+ case "reviewing":
795
+ return { _tag: "Review" };
796
+ case "distilling":
797
+ return { _tag: "Distill" };
798
+ case "done":
799
+ return { _tag: "Done" };
800
+ }
801
+ };
802
+ const nextId = (plan, added) => `B${plan.briefs.length + added + 1}`;
803
+ /** The brief an answer's question came from: `(B3, assuming: …)` in the question text. */
804
+ const askingBrief = (plan, question) => {
805
+ const match = /\((B\d+)(?:,|\))/.exec(question);
806
+ return match === null ? undefined : plan.briefs.find((brief) => brief.id === match[1]);
807
+ };
808
+ /**
809
+ * Folds the owner's words in: an answer reopens the brief that asked, with
810
+ * the answer in its CONTEXT, one wave on; feedback becomes a fix brief for
811
+ * the Doc Writer. At the wave cap the answer is folded and nothing is added.
812
+ */
813
+ export const recordOwner = (plan, action, caps, docWriter = "Doc Writer") => {
814
+ const notes = [];
815
+ const briefs = [];
816
+ const wave = currentWave(plan) + 1;
817
+ const capped = wave > caps.waves;
818
+ for (const answer of action.answers) {
819
+ const asked = askingBrief(plan, answer.question);
820
+ if (capped) {
821
+ notes.push(`answer ${answer.number} folded without rework: wave ${wave} is past the cap of ${caps.waves}`);
822
+ continue;
823
+ }
824
+ const id = nextId(plan, briefs.length);
825
+ briefs.push(Brief.make({
826
+ id,
827
+ title: asked === undefined
828
+ ? `Rework after answer ${answer.number}`
829
+ : `Rework ${asked.id}: ${asked.title}`,
830
+ owner: asked?.owner ?? docWriter,
831
+ dependsOn: [],
832
+ wave,
833
+ goal: asked?.goal ?? `Fold the owner's answer into the deliverables.`,
834
+ scope: asked?.scope ?? "",
835
+ context: [
836
+ asked?.context ?? "",
837
+ `The owner answered question ${answer.number} (${oneLine(answer.question)}): ${oneLine(answer.answer)}. Redo the work on that answer, not the assumption.`
838
+ ]
839
+ .filter((line) => line.length > 0)
840
+ .join("\n"),
841
+ acceptance: asked?.acceptance ?? "- The answer is reflected.",
842
+ verify: "",
843
+ timebox: asked?.timebox ?? "",
844
+ forbidden: asked?.forbidden ?? "",
845
+ report: `reports/${id}.md${asked === undefined ? "" : `, replacing reports/${asked.id}.md`}`
846
+ }));
847
+ }
848
+ if (action.feedback.length > 0) {
849
+ if (capped) {
850
+ notes.push(`feedback recorded without a fix wave: wave ${wave} is past the cap of ${caps.waves}`);
851
+ }
852
+ else {
853
+ const id = nextId(plan, briefs.length);
854
+ briefs.push(Brief.make({
855
+ id,
856
+ title: "Fix: the owner's feedback",
857
+ owner: docWriter,
858
+ dependsOn: [],
859
+ wave,
860
+ goal: "Address the owner's feedback in the deliverables.",
861
+ scope: plan.deliverables.join(", "),
862
+ context: `The owner wrote: ${action.feedback}`,
863
+ acceptance: "- The feedback is addressed and nothing else changed.",
864
+ verify: "",
865
+ timebox: "",
866
+ forbidden: "Rewriting what the feedback does not touch.",
867
+ report: `reports/${id}.md with what changed and why.`
868
+ }));
869
+ }
870
+ }
871
+ const status = briefs.length === 0
872
+ ? plan.status
873
+ : action.feedback.length > 0 && action.answers.length === 0
874
+ ? "fixing"
875
+ : "working";
876
+ return {
877
+ plan: Plan.make({
878
+ ...plan,
879
+ status,
880
+ feedback: "",
881
+ folded: [...new Set([...plan.folded, ...action.answers.map((answer) => answer.number)])].sort((left, right) => left - right)
882
+ }),
883
+ briefs,
884
+ notes
885
+ };
886
+ };
887
+ /** Questions the reports raised, added under `## Answers` once each, with the assumption. */
888
+ export const syncAnswers = (plan, reports) => {
889
+ const known = new Set(plan.answers.map((point) => point.question));
890
+ const added = [];
891
+ let number = plan.answers.reduce((max, point) => Math.max(max, point.number), 0);
892
+ for (const report of reports) {
893
+ for (const question of report.questions) {
894
+ const text = `${oneLine(question.question)} (${report.brief}, assuming: ${oneLine(question.assumption)})`;
895
+ if (known.has(text))
896
+ continue;
897
+ known.add(text);
898
+ number += 1;
899
+ added.push(OpenPoint.make({ number, question: text }));
900
+ }
901
+ }
902
+ return added.length === 0 ? plan : Plan.make({ ...plan, answers: [...plan.answers, ...added] });
903
+ };
904
+ // ---- The review (decision 7) ----------------------------------------------------------
905
+ export const Bucket = Schema.Literals(["act-on", "consider", "noted", "dismissed"]);
906
+ export class Finding extends Schema.Class("Finding")({
907
+ id: Schema.Int,
908
+ lens: Schema.String,
909
+ title: Schema.String,
910
+ /** A path, a section, a line. */
911
+ where: Schema.String,
912
+ /** The brief whose work it is about, or empty when it is about a deliverable. */
913
+ brief: Schema.String,
914
+ detail: Schema.String,
915
+ bucket: Bucket,
916
+ reason: Schema.String
917
+ }) {
918
+ }
919
+ export class LensFindings extends Schema.Class("LensFindings")({
920
+ findings: Schema.Array(Schema.Struct({
921
+ title: Schema.String,
922
+ where: Schema.String,
923
+ brief: Schema.String,
924
+ detail: Schema.String
925
+ }))
926
+ }) {
927
+ }
928
+ export const lensFindingsJsonSchema = {
929
+ type: "object",
930
+ properties: {
931
+ findings: {
932
+ type: "array",
933
+ items: {
934
+ type: "object",
935
+ properties: {
936
+ title: { type: "string" },
937
+ where: { type: "string" },
938
+ brief: { type: "string" },
939
+ detail: { type: "string" }
940
+ },
941
+ required: ["title", "where", "brief", "detail"]
942
+ }
943
+ }
944
+ },
945
+ required: ["findings"]
946
+ };
947
+ export class LeadProposal extends Schema.Class("LeadProposal")({
948
+ verdicts: Schema.Array(Schema.Struct({
949
+ id: Schema.Int,
950
+ bucket: Schema.Literals(["consider", "noted", "dismissed"]),
951
+ reason: Schema.String
952
+ }))
953
+ }) {
954
+ }
955
+ export const leadProposalJsonSchema = {
956
+ type: "object",
957
+ properties: {
958
+ verdicts: {
959
+ type: "array",
960
+ items: {
961
+ type: "object",
962
+ properties: {
963
+ id: { type: "integer" },
964
+ bucket: { type: "string", enum: ["consider", "noted", "dismissed"] },
965
+ reason: { type: "string" }
966
+ },
967
+ required: ["id", "bucket", "reason"]
968
+ }
969
+ }
970
+ },
971
+ required: ["verdicts"]
972
+ };
973
+ const bucketTitles = {
974
+ "act-on": "Act on",
975
+ consider: "Consider",
976
+ noted: "Noted",
977
+ dismissed: "Dismissed"
978
+ };
979
+ export const renderReview = (findings) => [
980
+ "# Review",
981
+ "",
982
+ ...Bucket.literals.flatMap((bucket) => {
983
+ const these = findings.filter((finding) => finding.bucket === bucket);
984
+ return [
985
+ `## ${bucketTitles[bucket]}`,
986
+ "",
987
+ ...(these.length === 0
988
+ ? ["- none"]
989
+ : these.flatMap((finding) => [
990
+ `- ${finding.id}. ${oneLine(finding.title)} (${finding.lens}${finding.brief.length === 0 ? "" : `, ${finding.brief}`}; ${oneLine(finding.where)})`,
991
+ ` ${oneLine(finding.detail)}${finding.reason.length === 0 ? "" : ` — ${oneLine(finding.reason)}`}`
992
+ ])),
993
+ ""
994
+ ];
995
+ })
996
+ ].join("\n");
997
+ /** One fix brief per act-on finding, for the owner of the work it is about, the Doc Writer otherwise. */
998
+ export const fixBriefs = (plan, findings, caps, docWriter) => {
999
+ const wave = currentWave(plan) + 1;
1000
+ const briefs = [];
1001
+ const dropped = [];
1002
+ for (const finding of findings) {
1003
+ if (finding.bucket !== "act-on")
1004
+ continue;
1005
+ if (plan.briefs.length + briefs.length >= caps.briefs) {
1006
+ dropped.push(finding);
1007
+ continue;
1008
+ }
1009
+ const about = plan.briefs.find((brief) => brief.id === finding.brief);
1010
+ const id = nextId(plan, briefs.length);
1011
+ briefs.push(Brief.make({
1012
+ id,
1013
+ title: `Fix: ${oneLine(finding.title)}`,
1014
+ owner: about?.owner ?? docWriter,
1015
+ dependsOn: [],
1016
+ wave,
1017
+ goal: `Address the review finding: ${oneLine(finding.title)}.`,
1018
+ scope: about?.scope ?? plan.deliverables.join(", "),
1019
+ context: `The ${finding.lens} lens found, at ${oneLine(finding.where)}: ${oneLine(finding.detail)}${about === undefined ? "" : ` (about ${about.id}: ${about.title})`}`,
1020
+ acceptance: "- The finding no longer holds.\n- Nothing the finding does not touch changed.",
1021
+ verify: "",
1022
+ timebox: about?.timebox ?? "",
1023
+ forbidden: about?.forbidden ?? "Changing what the finding does not touch.",
1024
+ report: `reports/${id}.md with what changed and the evidence.`
1025
+ }));
1026
+ }
1027
+ return { briefs, dropped };
1028
+ };
1029
+ // ---- Views ---------------------------------------------------------------------------------
1030
+ /** What nobody in the run could settle: finally blocked briefs with the assumption taken, and unanswered questions. */
1031
+ export const renderOpenQuestions = (plan, reports) => {
1032
+ const blocked = plan.briefs.flatMap((brief) => {
1033
+ const report = reportOf(reports, brief.id);
1034
+ return finallyBlocked(report) && report !== undefined ? [{ brief, report }] : [];
1035
+ });
1036
+ const unanswered = plan.answers.filter((point) => (point.answer ?? "").trim().length === 0);
1037
+ return [
1038
+ `# Open questions: ${plan.id}`,
1039
+ "",
1040
+ "## Blocked briefs",
1041
+ "",
1042
+ ...(blocked.length === 0
1043
+ ? ["- none"]
1044
+ : blocked.map(({ brief, report }) => `- ${brief.id} ${oneLine(brief.title)} (${brief.owner}): ${oneLine(report.summary)}`)),
1045
+ "",
1046
+ "## For the owner",
1047
+ "",
1048
+ ...(unanswered.length === 0
1049
+ ? ["- none"]
1050
+ : unanswered.map((point) => `- ${point.number}. ${point.question}`)),
1051
+ "",
1052
+ `Answer under '## Answers' in plan.md and rerun.`,
1053
+ ""
1054
+ ].join("\n");
1055
+ };
1056
+ export const trailHeader = "ts\tphase\tdecision\twhy\tevidence\tresult";
1057
+ /** A cell on one line, with a leading `=`, `+`, `-` or `@` quoted so a spreadsheet reads it as text. */
1058
+ const cell = (text) => {
1059
+ const flat = oneLine(text);
1060
+ return /^[=+\-@]/.test(flat) ? `'${flat}` : flat;
1061
+ };
1062
+ export const renderTrailRow = (row) => [row.ts, row.phase, row.decision, row.why, row.evidence, row.result].map(cell).join("\t");
1063
+ //# sourceMappingURL=Taskforce.js.map