bareloop 0.54.0 → 0.55.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 (139) hide show
  1. package/CHANGELOG.md +83 -0
  2. package/bareloop.context.md +73 -12
  3. package/package.json +3 -3
  4. package/src/authorflow.js +148 -46
  5. package/src/authoring.js +21 -4
  6. package/src/authorjob.js +82 -3
  7. package/src/authorreadout.js +20 -3
  8. package/src/authorrun.js +1 -1
  9. package/src/authorscout.js +9 -6
  10. package/src/bridges.js +4 -3
  11. package/src/cardschedule.js +42 -0
  12. package/src/carrystore.js +1 -1
  13. package/src/checkpick.js +576 -0
  14. package/src/checksuggest.js +28 -0
  15. package/src/checkwords.js +25 -0
  16. package/src/cli.js +1 -1
  17. package/src/config.js +24 -1
  18. package/src/declaredclose.js +1 -1
  19. package/src/destpoint.js +149 -0
  20. package/src/draftspend.js +39 -0
  21. package/src/factwords.js +14 -1
  22. package/src/job.js +81 -1
  23. package/src/jobblock.js +9 -0
  24. package/src/labelscan.js +11 -0
  25. package/src/launcher.js +10 -6
  26. package/src/learn.js +6 -4
  27. package/src/mcpchecks.js +52 -0
  28. package/src/mcppick.js +36 -0
  29. package/src/mcpsources.js +77 -0
  30. package/src/mcpuse.js +97 -0
  31. package/src/natural.js +23 -0
  32. package/src/pagemap.js +5 -2
  33. package/src/panel/authorroutes.js +90 -15
  34. package/src/panel/authorsession.js +183 -21
  35. package/src/panel/index.html +686 -26
  36. package/src/panel/jobgrid.js +117 -0
  37. package/src/panel/jobplan.js +31 -15
  38. package/src/panel/scheduler.js +80 -13
  39. package/src/panel/schedules.js +189 -28
  40. package/src/panel/schedulestart.js +44 -13
  41. package/src/panel/server.js +438 -33
  42. package/src/panel/settingsroutes.js +133 -3
  43. package/src/panel/status.js +22 -2
  44. package/src/panel/tickets.js +44 -0
  45. package/src/pickrecord.js +145 -0
  46. package/src/plan.js +31 -2
  47. package/src/planrun.js +71 -15
  48. package/src/prcheckout.js +259 -0
  49. package/src/readshim.js +3 -2
  50. package/src/replay.js +6 -0
  51. package/src/reuse.js +3 -3
  52. package/src/revises.js +56 -0
  53. package/src/rubricstep.js +62 -16
  54. package/src/run.js +10 -1
  55. package/src/runexport.js +2 -0
  56. package/src/runlist.js +3 -2
  57. package/src/schedulewords.js +46 -4
  58. package/src/source.js +81 -7
  59. package/src/stepmcp.js +86 -0
  60. package/src/ticket.js +113 -0
  61. package/src/ticketfilter.js +76 -0
  62. package/src/ticketlabels.js +79 -0
  63. package/src/ticketmcp.js +111 -0
  64. package/src/ticketnext.js +35 -0
  65. package/src/ticketrepo.js +98 -0
  66. package/src/ticketschedule.js +32 -0
  67. package/src/ticketshape.js +45 -0
  68. package/src/tools.js +9 -0
  69. package/src/trigger.js +14 -2
  70. package/src/triggerclock.js +7 -3
  71. package/src/triggerfiles.js +19 -11
  72. package/src/triggertickets.js +244 -0
  73. package/src/u-readout.js +2 -2
  74. package/src/userrun.js +146 -10
  75. package/src/validate.js +3 -1
  76. package/src/worktree.js +43 -1
  77. package/types/authorflow.d.ts +128 -28
  78. package/types/authorjob.d.ts +16 -3
  79. package/types/authorreadout.d.ts +9 -2
  80. package/types/authorscout.d.ts +4 -2
  81. package/types/bridges.d.ts +4 -3
  82. package/types/cardschedule.d.ts +24 -0
  83. package/types/checkpick.d.ts +297 -0
  84. package/types/checksuggest.d.ts +30 -0
  85. package/types/checkwords.d.ts +14 -0
  86. package/types/config.d.ts +7 -0
  87. package/types/destpoint.d.ts +87 -0
  88. package/types/draftspend.d.ts +16 -0
  89. package/types/factwords.d.ts +7 -0
  90. package/types/job.d.ts +13 -0
  91. package/types/jobblock.d.ts +9 -0
  92. package/types/labelscan.d.ts +7 -0
  93. package/types/launcher.d.ts +7 -2
  94. package/types/mcpchecks.d.ts +8 -0
  95. package/types/mcppick.d.ts +33 -0
  96. package/types/mcpsources.d.ts +51 -0
  97. package/types/mcpuse.d.ts +15 -0
  98. package/types/natural.d.ts +2 -0
  99. package/types/pagemap.d.ts +2 -1
  100. package/types/panel/authorroutes.d.ts +11 -2
  101. package/types/panel/authorsession.d.ts +58 -3
  102. package/types/panel/jobgrid.d.ts +405 -0
  103. package/types/panel/jobplan.d.ts +10 -4
  104. package/types/panel/scheduler.d.ts +7 -2
  105. package/types/panel/schedules.d.ts +124 -4
  106. package/types/panel/schedulestart.d.ts +21 -3
  107. package/types/panel/server.d.ts +427 -6
  108. package/types/panel/settingsroutes.d.ts +4 -2
  109. package/types/panel/status.d.ts +16 -2
  110. package/types/panel/tickets.d.ts +61 -0
  111. package/types/pickrecord.d.ts +88 -0
  112. package/types/plan.d.ts +1 -0
  113. package/types/prcheckout.d.ts +151 -0
  114. package/types/readshim.d.ts +4 -3
  115. package/types/replay.d.ts +3 -0
  116. package/types/reuse.d.ts +2 -2
  117. package/types/revises.d.ts +23 -0
  118. package/types/rubricstep.d.ts +14 -5
  119. package/types/run.d.ts +18 -1
  120. package/types/runlist.d.ts +6 -3
  121. package/types/schedulewords.d.ts +29 -2
  122. package/types/source.d.ts +40 -4
  123. package/types/stepmcp.d.ts +40 -0
  124. package/types/ticket.d.ts +114 -0
  125. package/types/ticketfilter.d.ts +34 -0
  126. package/types/ticketlabels.d.ts +44 -0
  127. package/types/ticketmcp.d.ts +84 -0
  128. package/types/ticketnext.d.ts +33 -0
  129. package/types/ticketrepo.d.ts +118 -0
  130. package/types/ticketschedule.d.ts +21 -0
  131. package/types/ticketshape.d.ts +37 -0
  132. package/types/tools.d.ts +1 -0
  133. package/types/trigger.d.ts +9 -1
  134. package/types/triggerclock.d.ts +6 -2
  135. package/types/triggerfiles.d.ts +13 -5
  136. package/types/triggertickets.d.ts +110 -0
  137. package/types/userrun.d.ts +50 -0
  138. package/types/validate.d.ts +1 -0
  139. package/types/worktree.d.ts +19 -0
@@ -0,0 +1,117 @@
1
+ // borrowed-from: fwdloop src/panel/jobgrid.js@v0.29.0 (adapted: bareloop's status table decides every bucket, `panelMoney2` is the one money spelling, the wall is the run list's own wording, and the
2
+ // cells are the mockup's: steps done, the close's checks, cost, time). ITEM33-BUILD piece 10 (R8): the Result tab's ONE grid for a ticket job.
3
+ // Pure of the panel: `getJobGrid` (src/panel/server.js) reads the run list and the spines and hands plain entries in. Nothing is written.
4
+ import { GROUP_OF, TICKET_GROUPS } from './tickets.js';
5
+ import { panelMoney2 } from '../panelmoney.js';
6
+ import { FILTER_UNSURE_SAY } from '../ticketlabels.js';
7
+
8
+ /** the buckets, in the mockup's order */
9
+ export const GRID_BUCKETS = TICKET_GROUPS;
10
+
11
+ const isNum = (x) => typeof x === 'number' && Number.isFinite(x);
12
+
13
+ /**
14
+ * ONE decider of a run's bucket: its status key through {@link GROUP_OF}; a run waiting at its review door (the run list's own `needs: 'Accept'`) needs the person, whatever its status.
15
+ * Anything the table does not know reads as Stopped.
16
+ * @param {string|null|undefined} statusKey @param {'Accept'|'Resume'|null|undefined} needs @returns {'wait'|'stop'|'done'|'skip'}
17
+ */
18
+ export function bucketOf(statusKey, needs) {
19
+ if (needs === 'Accept') return 'wait';
20
+ return /** @type {any} */ (GROUP_OF[/** @type {keyof typeof GROUP_OF} */ (statusKey ?? '')] ?? 'stop');
21
+ }
22
+
23
+ /**
24
+ * A money figure in the panel's one spelling: `at least $0.08` when only a floor is known, `unknown` when nothing is (never `$0.00` for unknown).
25
+ * @param {number|null} usd @param {boolean} complete
26
+ */
27
+ export function moneyWords(usd, complete) {
28
+ if (usd === null) return 'unknown';
29
+ return `${complete ? '' : 'at least '}${panelMoney2(usd)}`;
30
+ }
31
+
32
+ /**
33
+ * The stats line's money: the sum of the rows' money; a floor when any row's figure is a floor or unknown; `usd: null` = nothing is known.
34
+ * @param {Array<{usd: number|null, complete: boolean}>} moneys
35
+ */
36
+ export function sumMoney(moneys) {
37
+ const known = moneys.filter((m) => m.usd !== null);
38
+ return { usd: known.length === 0 ? null : known.reduce((a, m) => a + (m.usd ?? 0), 0), complete: moneys.every((m) => m.usd !== null && m.complete) };
39
+ }
40
+
41
+ /**
42
+ * One run's money: the run list's own figure (complete unless it says the figure is a floor), else the live/died floor, else unknown.
43
+ * @param {{spentUsd?: unknown, spendComplete?: unknown, spendFloorUsd?: unknown}} e
44
+ */
45
+ export function entryMoney(e) {
46
+ if (isNum(e.spentUsd)) return { usd: /** @type {number} */ (e.spentUsd), complete: e.spendComplete !== false };
47
+ if (isNum(e.spendFloorUsd)) return { usd: /** @type {number} */ (e.spendFloorUsd), complete: false };
48
+ return { usd: null, complete: false };
49
+ }
50
+
51
+ /**
52
+ * A row's short reference: its ticket (`#14`), else the run's panel name `run-N`, the run id only when the run list gave it no number (the run id never names a row otherwise).
53
+ * @param {{runId: string, runNo?: number|null, number: number|null}} e
54
+ */
55
+ function gridRefOf(e) {
56
+ return e.number !== null ? `#${e.number}` : (isNum(e.runNo) ? `run-${e.runNo}` : e.runId);
57
+ }
58
+
59
+ /**
60
+ * A row's name: the reference, and for a run that read no ticket the run list's OWN ending words after it (`run-3 · Nothing new: ...`), so the row says why it has no ticket.
61
+ * @param {{runId: string, runNo?: number|null, number: number|null, reason: string|null}} e
62
+ */
63
+ function gridNameOf(e) {
64
+ const ref = gridRefOf(e);
65
+ return e.number === null && typeof e.reason === 'string' && e.reason !== '' ? `${ref} · ${e.reason}` : ref;
66
+ }
67
+
68
+ /**
69
+ * The grid of one ticket job: every run a row in its bucket, newest first inside each bucket, and the stats line's numbers.
70
+ * @param {{entries: Array<{runId: string, runNo?: number|null, at: number|null, statusKey: string, sign: string, word: string, needs: 'Accept'|'Resume'|null, unsure?: boolean, number: number|null, title: string|null, url: string|null,
71
+ * steps: {done: number, total: number}|null, checks: {passed: number, total: number}|null, spentUsd: number|null, spendComplete: boolean, spendFloorUsd: number|null, wall: string|null, reason: string|null}>,
72
+ * scheduleLine?: string|null}} a
73
+ */
74
+ export function buildJobGrid({ entries, scheduleLine = null }) {
75
+ const rows = entries.map((e) => {
76
+ const bucket = bucketOf(e.statusKey, e.needs);
77
+ const ended = e.statusKey !== 'running' && e.statusKey !== 'waiting';
78
+ const money = entryMoney(e);
79
+ const skip = bucket === 'skip';
80
+ /** @type {{mark: 'g'|'r'|'q'|'n', text: string}} */
81
+ const steps = skip || e.steps === null ? { mark: 'n', text: '' }
82
+ : { mark: e.steps.done === e.steps.total ? 'g' : (ended ? 'r' : 'n'), text: `${e.steps.done} of ${e.steps.total}` };
83
+ /** @type {{mark: 'g'|'r'|'q'|'n', text: string}} */
84
+ const checks = skip || e.checks === null ? { mark: 'n', text: '' }
85
+ : (e.checks.passed === e.checks.total ? { mark: 'g', text: `${e.checks.passed} of ${e.checks.total}` } : { mark: 'r', text: `${e.checks.total - e.checks.passed} red` });
86
+ const walled = e.wall !== null && e.wall !== '' && e.wall !== 'unknown';
87
+ return {
88
+ runId: e.runId, runNo: e.runNo ?? null, number: e.number, title: e.title, url: e.url, ...(e.unsure === true ? { unsure: true, unsureSay: FILTER_UNSURE_SAY } : { unsure: false }),
89
+ name: gridNameOf(e), ref: gridRefOf(e), bucket, status: { key: e.statusKey, sign: e.sign, word: e.word }, needs: e.needs, at: e.at,
90
+ steps, checks,
91
+ // a cell with no data is the page's grey dash (mark `n`, no text), never `?` or `unknown`; a floor keeps its `?` and "at least"
92
+ cost: money.usd === null ? { mark: 'n', text: '' } : { mark: money.complete ? 'g' : 'q', text: moneyWords(money.usd, money.complete) },
93
+ time: skip || !walled ? { mark: 'n', text: '' } : { mark: 'g', text: /** @type {string} */ (e.wall) },
94
+ reason: e.reason,
95
+ money,
96
+ };
97
+ });
98
+ // "Run it anyway" is offered on a skipped row only while no later run read that ticket: a ticket that ran since is not skipped any more
99
+ const newestAt = new Map();
100
+ for (const r of rows) if (r.number !== null) newestAt.set(r.number, Math.max(newestAt.get(r.number) ?? -Infinity, r.at ?? -Infinity));
101
+ const order = (/** @type {any} */ a, /** @type {any} */ b) => ((b.at ?? -Infinity) - (a.at ?? -Infinity)) || (a.runId < b.runId ? 1 : a.runId > b.runId ? -1 : 0);
102
+ const groups = GRID_BUCKETS.map((g) => ({
103
+ ...g,
104
+ rows: rows.filter((r) => r.bucket === g.key).sort(order).map(({ money, ...row }) => ({
105
+ ...row, anyway: g.key === 'skip' && row.number !== null && (row.at ?? -Infinity) >= (newestAt.get(row.number) ?? -Infinity),
106
+ })),
107
+ }));
108
+ const total = sumMoney(rows.map((r) => r.money));
109
+ return {
110
+ groups,
111
+ scheduleLine,
112
+ stats: {
113
+ counts: Object.fromEntries(groups.map((g) => [g.key, g.rows.length])),
114
+ spent: moneyWords(total.usd, total.complete), spentUsd: total.usd, spentComplete: total.complete,
115
+ },
116
+ };
117
+ }
@@ -10,13 +10,21 @@
10
10
  //
11
11
  // `cls` is 'machine check' | 'judge' | null (null = not known yet: the confirm card's checks are the model's plan, the
12
12
  // stage kinds exist only after drafting). Pure; no file IO.
13
+ import { ticketFilterWords } from '../ticketfilter.js';
13
14
  import { KIND_CATALOGUE } from '../authoring.js';
14
15
  import { splitReadNotes } from '../pagedropwords.js';
15
16
  import { checksOfClose, signedFactNames, proseNotChecked, lineRules, confirmedGoalOf } from '../rubricstep.js';
16
17
 
17
- /** @typedef {{name: string, cls: 'machine check'|'judge'|null}} PlanCheck */
18
- /** @typedef {{n: number, text: string, rule: string, rules: string[], checks: PlanCheck[], refused: string[], always?: string[]}} PlanLine */
19
- /** @typedef {{lines: PlanLine[], loose: PlanCheck[], notChecked: string[], readNotes: string[], alwaysOn: string[], older: boolean, goal?: string}} JobPlan */
18
+ /** `by` = who added the check: the drafter (`agent`) or the person's own pick (`you`); absent = code's own (an always-on guard, a number tie) or not known */
19
+ /** @typedef {{name: string, cls: 'machine check'|'judge'|null, by?: 'agent'|'you'|null}} PlanCheck */
20
+ /** @typedef {{n: number, text: string, rule: string, rules: string[], checks: PlanCheck[], refused: string[], always?: string[], picked?: string[]}} PlanLine */
21
+ /** @typedef {{lines: PlanLine[], loose: PlanCheck[], notChecked: string[], readNotes: string[], alwaysOn: string[], older: boolean, goal?: string, ticketFilter?: string}} JobPlan */
22
+
23
+ /** the ticket filter's code-owned words as a plan part, or nothing (R5) @param {any} f @returns {{ticketFilter?: string}} */
24
+ function filterPart(f) {
25
+ const w = ticketFilterWords(f);
26
+ return w === null ? {} : { ticketFilter: w };
27
+ }
20
28
 
21
29
  /**
22
30
  * `machine check` for a kind a command decides, `judge` for one that needs judgement; `null` for a stage whose kind is
@@ -50,7 +58,7 @@ export function rulesOfLine(l) {
50
58
  * @returns {JobPlan}
51
59
  */
52
60
  export function planFromSpec(spec) {
53
- /** @type {{name: string, cls: 'machine check'|'judge'|null, fromLine: number[]|null}[]} */
61
+ /** @type {{name: string, cls: 'machine check'|'judge'|null, fromLine: number[]|null, by?: 'agent'|'you'|null}[]} */
54
62
  let stages = [];
55
63
  if (spec && Array.isArray(spec.closeDecl?.stages)) {
56
64
  stages = spec.closeDecl.stages.filter((/** @type {any} */ s) => s && typeof s.name === 'string' && s.name)
@@ -58,8 +66,8 @@ export function planFromSpec(spec) {
58
66
  const fromLine = Array.isArray(s.fromLine) && s.fromLine.length ? s.fromLine.filter(Number.isInteger) : null;
59
67
  // PART 1b: a rubric-step stage is shown as the checks it RUNS — one code-worded row per fact, per count, per limit — read by
60
68
  // the same reader (`checksOfClose`) the confirm card and the sign-time invariant use, so the Job tab cannot differ from them
61
- const rows = s.kind === 'rubric-step' ? checksOfClose({ stages: [s] }) : [];
62
- return rows.length > 0 ? rows.map((r) => ({ name: r.text, cls: /** @type {'machine check'} */ ('machine check'), fromLine })) : [{ name: s.name, cls: checkClassOfKind(s.kind), fromLine }];
69
+ const rows = s.kind === 'rubric-step' ? checksOfClose({ stages: [s], picks: spec.closeDecl.picks }) : [];
70
+ return rows.length > 0 ? rows.map((r) => ({ name: r.text, cls: /** @type {'machine check'} */ ('machine check'), fromLine, by: r.by })) : [{ name: s.name, cls: checkClassOfKind(s.kind), fromLine, by: /** @type {'agent'} */ ('agent') }];
63
71
  });
64
72
  } else if (spec && Array.isArray(spec.close)) {
65
73
  stages = spec.close.filter((/** @type {any} */ s) => s && typeof s.name === 'string' && s.name)
@@ -79,7 +87,7 @@ export function planFromSpec(spec) {
79
87
  n: 1, text: typeof spec?.goal === 'string' && spec.goal ? spec.goal : '(no goal recorded)', rule: '', rules: [],
80
88
  checks: stages.map((s) => ({ name: s.name, cls: s.cls })), refused: [],
81
89
  }],
82
- loose: [], notChecked: notes, readNotes, alwaysOn: [], older: true,
90
+ loose: [], notChecked: notes, readNotes, alwaysOn: [], older: true, ...filterPart(spec?.ticketFilter),
83
91
  };
84
92
  }
85
93
  /** @type {PlanLine[]} */
@@ -92,8 +100,8 @@ export function planFromSpec(spec) {
92
100
  if (s.fromLine === null) { alwaysOn.push(s.name); continue; }
93
101
  // a check that serves several job lines is shown under EACH line it serves (no new element: the same check line, repeated)
94
102
  const served = lines.filter((l) => /** @type {number[]} */ (s.fromLine).includes(l.n));
95
- for (const line of served) line.checks.push({ name: s.name, cls: s.cls });
96
- if (served.length === 0) loose.push({ name: s.name, cls: s.cls });
103
+ for (const line of served) line.checks.push({ name: s.name, cls: s.cls, ...(s.by ? { by: s.by } : {}) });
104
+ if (served.length === 0) loose.push({ name: s.name, cls: s.cls, ...(s.by ? { by: s.by } : {}) });
97
105
  }
98
106
  // an always-on guard that the drafter said covers a job line is shown under that line too ("› check · always-on: <guard>")
99
107
  for (const g of Array.isArray(spec?.closeDecl?.guardLines) ? spec.closeDecl.guardLines : []) {
@@ -110,14 +118,14 @@ export function planFromSpec(spec) {
110
118
  // the model's signed goal sentence rides along: the page draws it as the "AI's summary" row (an older job shows it as line 1 instead)
111
119
  // (a rubric job's signed goal is the whole worker brief: only the sentence the person confirmed is the summary)
112
120
  const summary = typeof spec?.goal === 'string' && spec.goal ? confirmedGoalOf(spec.goal) : null;
113
- return { lines, loose, notChecked: notes, readNotes, alwaysOn, older: false, ...(summary ? { goal: summary } : {}) };
121
+ return { lines, loose, notChecked: notes, readNotes, alwaysOn, older: false, ...(summary ? { goal: summary } : {}), ...filterPart(spec?.ticketFilter) };
114
122
  }
115
123
 
116
124
  /**
117
125
  * The plan of the confirm turn, before anything is drafted: the person's own job lines, the model's checks under the
118
126
  * line each names, its own "not checked" words, and the real protections (code-owned) as "Always checked".
119
127
  * @param {{n: number, text: string, rule: string, rules?: string[]}[]|null|undefined} jobLines
120
- * @param {{checkItems?: {text: string, fromLine: number[]|null}[], checks?: string[], notChecked?: string[], protections?: string[], signedFacts?: string[]}} plan
128
+ * @param {{checkItems?: {text: string, fromLine: number[]|null, by?: 'agent'|'you'|null}[], checks?: string[], notChecked?: string[], protections?: string[], signedFacts?: string[], ticketFilter?: any, picked?: {line: number, text: string}[]}} plan
121
129
  * `signedFacts` = the names of the facts the look signs (so an S1 copy of a signed fact reads as a note, not Not checked)
122
130
  * @returns {JobPlan}
123
131
  */
@@ -130,13 +138,21 @@ export function planFromConfirm(jobLines, plan) {
130
138
  const lines = jl.map((l) => ({ n: l.n, text: l.text, rule: l.rule, rules: rulesOfLine(l), checks: [], refused: [] }));
131
139
  /** @type {PlanCheck[]} */
132
140
  const loose = [];
133
- for (const c of items) {
141
+ // the person's picks are drawn once, from `plan.picked` (their words, with `kept from last draft`) as `[you picked]` check rows: a close row for the same pick is not a second row
142
+ const hasPicked = Array.isArray(plan?.picked) && plan.picked.length > 0;
143
+ for (const c of items.filter((x) => !(hasPicked && /** @type {any} */ (x).by === 'you'))) {
144
+ const by = /** @type {any} */ (c).by === null ? {} : { by: /** @type {'agent'|'you'} */ (/** @type {any} */ (c).by ?? 'agent') };
134
145
  const served = lines.filter((l) => Array.isArray(c.fromLine) && c.fromLine.includes(l.n));
135
- for (const line of served) line.checks.push({ name: c.text, cls: null });
136
- if (served.length === 0) loose.push({ name: c.text, cls: null });
146
+ for (const line of served) line.checks.push({ name: c.text, cls: null, ...by });
147
+ if (served.length === 0) loose.push({ name: c.text, cls: null, ...by });
137
148
  }
138
149
  const { notChecked, readNotes } = splitReadNotes(plan?.notChecked, plan?.signedFacts);
150
+ // R10 (fwd am16 (6)): the checks the person picked, each under its line, in the one table's plain words (`kept from last draft` rides in `text` when a Revise kept it)
151
+ for (const x of Array.isArray(plan?.picked) ? plan.picked : []) {
152
+ const line = lines.find((l) => l.n === x?.line);
153
+ if (line && typeof x.text === 'string') (line.picked ??= []).push(x.text);
154
+ }
139
155
  return {
140
- lines, loose, notChecked, readNotes, alwaysOn: [...(plan?.protections ?? [])], older: false,
156
+ lines, loose, notChecked, readNotes, alwaysOn: [...(plan?.protections ?? [])], older: false, ...filterPart(plan?.ticketFilter),
141
157
  };
142
158
  }
@@ -8,29 +8,40 @@
8
8
  // - the timer is unref'd, `start`/`stop` are idempotent, the server's close calls `stop`.
9
9
  // - with no schedule on disk a tick is one readdir and nothing else (no runs.jsonl read).
10
10
  // What a tick does for one job with a signed schedule:
11
- // 1. arm it if it is not armed under this signing (a crash between the sign and the arm);
11
+ // 1. arm it if it is not armed under this signing (a crash between the sign and the arm). A schedule signed WITH its job (R7) is asked again every tick and does nothing else until it arms: no look, no fire;
12
12
  // 2. clock kinds: `due`; a due slot goes to `door.fire` and is NOT consumed up front: the starter's `beforeSpawn` writes
13
13
  // the `fire` row only after busy, monthly, wouldAccept and the session all said yes, so a refused slot retries;
14
14
  // 3. file kinds: `poll`; each file taken is recorded `arrived` (THIS is the only writer of `arrived` rows), then the
15
15
  // queue runs: busy tells each queued file once and waits; free, the head is looked at again (deleted or changed is
16
16
  // dropped with a reason, the next head is tried) and goes through `door.fire`; `ran` is written by `beforeSpawn` only.
17
+ // 4. ticket kind (MCP + tickets piece 3): every `TICKET_LOOK_MS` (15 min, at $0, looks never overlap) the injected `look` reads the signed server's `list_issues` through
18
+ // the signed tools; the first look is the starting point (a `baseline` row per ticket, nothing runs), later ones queue each new ticket (`arrived`, oldest first) and
19
+ // each watched change once; an unreadable look is ONE `unreadable` row, never "no new tickets". The queue then runs like a file's: busy tells each ticket once and
20
+ // waits; free, the head goes through `door.fire` with `{kind:'ticket', number}` and `ran` is written by `beforeSpawn` only. The look is async and `tick` never waits for
21
+ // it (`settled()` does, for a test). The server, list address and watched fields are DERIVED from the signed spec, never stored in the trigger.
17
22
  // One job's exception is written once as a `refused` row and never stops the others (fwd scheduler.js:94-110).
18
23
  // BUSY IS CHEAP (T19): the run list is read at most ONCE per tick, and only when a fire or a queued head needs it.
19
24
  // Rewritten from fwdloop src/panel/scheduler.js.
20
25
  import { due } from '../triggerclock.js';
21
- import { isClockTrigger, isFileTrigger } from '../trigger.js';
26
+ import { isClockTrigger, isFileTrigger, isTicketTrigger } from '../trigger.js';
22
27
  import { appendRow, readLedger } from '../triggerledger.js';
23
28
  import {
24
29
  createFileTrigger, queueOf, readSeen, recheck, recordArrived, recordDropped, recordRan,
25
30
  } from '../triggerfiles.js';
26
31
  import { recordFire } from '../triggerclock.js';
32
+ import {
33
+ LOOK_TOOL, TICKET_LOOK_MS, hasBaseline, lastSeen, lookTickets, recordLook, recordTicketRan, seenNumbers,
34
+ } from '../triggertickets.js';
35
+ import { ticketLookOf } from '../ticketschedule.js';
27
36
 
28
37
  /**
29
- * @param {{ door: ReturnType<typeof import('./schedules.js').createScheduleDoor>, now?: () => number, intervalMs?: number }} opts
30
- * `intervalMs` 0 = no timer (a test drives `tick`).
38
+ * @param {{ door: ReturnType<typeof import('./schedules.js').createScheduleDoor>, now?: () => number, intervalMs?: number, look?: typeof lookTickets, mcpConfig?: string }} opts
39
+ * `intervalMs` 0 = no timer (a test drives `tick`). `look` / `mcpConfig` = the ticket look and the MCP config file it reads (tests inject them; default the real look over the person's own config).
31
40
  */
32
41
  export function createScheduler(opts) {
33
- const { door, now = Date.now, intervalMs = 500 } = opts;
42
+ const { door, now = Date.now, intervalMs = 500, look = lookTickets, mcpConfig } = opts;
43
+ /** per ticket schedule: when its last look STARTED, the look still out (a look is async; `tick` never waits), and a save failure not yet told (the ledger could not be written) @type {Map<string, {at: number|null, out: Promise<void>|null, untold?: string}>} */
44
+ const lookers = new Map();
34
45
  /** @type {Map<string, ReturnType<typeof createFileTrigger>>} */
35
46
  const watchers = new Map();
36
47
  /** `job|sig` keys already armed this process @type {Set<string>} */
@@ -42,15 +53,22 @@ export function createScheduler(opts) {
42
53
 
43
54
  /**
44
55
  * The queue of a file trigger (arrived minus ran minus dropped, oldest first).
45
- * @param {string} job @param {string} ledger @param {string} sig @param {number} nowMs @param {() => boolean} isBusy @param {Promise<unknown>[]} pending
56
+ * @param {string} job @param {string} ledger @param {string} sig @param {number} nowMs @param {() => boolean} isBusy @param {Promise<unknown>[]} pending @param {boolean} [ticket] a ticket schedule: the queue is this signing's tickets
46
57
  */
47
- function runQueue(job, ledger, sig, nowMs, isBusy, pending) {
48
- let queue = queueOf(readSeen(ledger));
58
+ function runQueue(job, ledger, sig, nowMs, isBusy, pending, ticket = false) {
59
+ let queue = queueOf(readSeen(ledger, ticket ? sig : undefined));
49
60
  if (queue.length === 0 || inflight.has(job)) return;
61
+ /** a ticket has no file to look at again: it is its number. @param {any} q */
62
+ const causeOf = (q) => (ticket ? { kind: /** @type {const} */ ('ticket'), number: q.number, sha: q.sha, ...(typeof q.reason === 'string' ? { why: q.reason } : {}), ...(q.anyway === true ? { anyway: true } : {}) } : { kind: /** @type {const} */ ('file'), path: q.path, sha: q.sha, size: q.size });
50
63
  const busy = isBusy();
51
64
  if (busy) {
52
- // every queued file is told ONCE (`busy`, once per sha) and waits
53
- for (const q of queue) pending.push(door.fire(job, { kind: 'file', path: q.path, sha: q.sha, size: q.size }, { busy: true }));
65
+ // every queued file (or ticket) is told ONCE (`busy`, once per sha) and waits
66
+ for (const q of queue) pending.push(door.fire(job, causeOf(q), { busy: true }));
67
+ return;
68
+ }
69
+ if (ticket) {
70
+ const q = queue[0];
71
+ pending.push(startFire(job, causeOf(q), { busy: false, beforeSpawn: () => { recordTicketRan(ledger, sig, { sha: q.sha, name: q.name }, nowMs); } }, sig));
54
72
  return;
55
73
  }
56
74
  while (queue.length > 0) {
@@ -84,10 +102,43 @@ export function createScheduler(opts) {
84
102
  .finally(() => { inflight.delete(job); });
85
103
  }
86
104
 
105
+ /**
106
+ * When a ticket schedule's look is due (never looked, or `TICKET_LOOK_MS` since the last START of one) and none is out, start it. THE writer of the ticket rows is
107
+ * `recordLook`, called once the look settles at THIS clock. Without a baseline the look is a first look again (an unreadable first look gave none). A save that throws is told
108
+ * once as a refusal and never leaves the look's promise rejected, so the panel stays up (fwd 9.3).
109
+ * @param {string} job @param {string} key @param {any} schedule @param {string} ledger @param {number} nowMs
110
+ */
111
+ function startLook(job, key, schedule, ledger, nowMs) {
112
+ let st = lookers.get(key);
113
+ if (!st) { st = { at: null, out: null }; lookers.set(key, st); }
114
+ if (st.out !== null || (st.at !== null && nowMs - st.at < TICKET_LOOK_MS)) return;
115
+ const sig = schedule.specHash;
116
+ if (st.untold !== undefined) { try { door.tellOnce(job, sig, `look-save|${st.untold}`, st.untold); st.untold = undefined; } catch { /* still unwritable: tried again next tick */ } }
117
+ const src = ticketLookOf(schedule.spec, schedule.trigger);
118
+ if (!src.ok) { door.tellOnce(job, sig, `look|${src.say}`, src.say); return; }
119
+ st.at = nowMs;
120
+ const first = !hasBaseline(ledger, sig);
121
+ // the turn-on may have written the ticket number the first green run read (`armed.ticketN`): the first look baselines only tickets up to it
122
+ const armed = first ? readLedger(ledger).rows.filter((r) => r.kind === 'armed' && r.sig === sig).at(-1) : undefined;
123
+ const cut = Number.isInteger(armed?.ticketN) ? /** @type {number} */ (armed?.ticketN) : undefined;
124
+ const state = st;
125
+ state.out = Promise.resolve(look({
126
+ listUrl: src.listUrl, mcp: { server: src.server, tool: LOOK_TOOL }, ...(mcpConfig ? { configPath: mcpConfig } : {}),
127
+ seen: first ? null : seenNumbers(ledger, sig), last: first ? new Map() : lastSeen(ledger, sig), watch: src.watch, ...(cut === undefined ? {} : { cut }),
128
+ })).catch((e) => ({ ok: /** @type {const} */ (false), error: String(e?.message ?? e) }))
129
+ .then((r) => {
130
+ try { recordLook(ledger, sig, r, now()); } catch (e) {
131
+ // the ledger itself cannot be written, so the failure cannot be told now: it is told on a later tick, once the ledger takes a row again
132
+ state.untold = `ticket look: its result could not be saved: ${String(/** @type {any} */ (e)?.message ?? e).split('\n')[0]}`;
133
+ }
134
+ })
135
+ .finally(() => { state.out = null; });
136
+ }
137
+
87
138
  /** @returns {Promise<void>} resolves when every fire this tick started has settled */
88
139
  function tick() {
89
140
  const jobs = door.scan();
90
- if (jobs.length === 0) { watchers.clear(); armedKeys.clear(); return Promise.resolve(); }
141
+ if (jobs.length === 0) { watchers.clear(); armedKeys.clear(); lookers.clear(); return Promise.resolve(); }
91
142
  const nowMs = now();
92
143
  /** @type {Promise<unknown>[]} */
93
144
  const pending = [];
@@ -97,16 +148,29 @@ export function createScheduler(opts) {
97
148
  for (const { job, schedule } of jobs) {
98
149
  const sig = schedule.specHash;
99
150
  const key = `${job}|${sig}`;
151
+ // a schedule signed again with the very same signature (cancelled, then signed with the job once more, between two ticks) is a NEW life of it: its arming is asked again (R7)
152
+ const armKey = `${key}|${schedule.signedAt ?? ''}`;
100
153
  live.add(key);
154
+ live.add(armKey);
101
155
  const isBusy = () => {
102
156
  if (!busyMemo.has(job)) busyMemo.set(job, door.busy(job));
103
157
  return /** @type {boolean} */ (busyMemo.get(job));
104
158
  };
105
159
  try {
106
- if (!armedKeys.has(key)) { door.armFor(job, schedule); armedKeys.add(key); }
160
+ if (!armedKeys.has(armKey)) {
161
+ // R7: a schedule signed with its job on the New job card is OFF until a run that began after the signing has a real green; it is asked again every tick and until then
162
+ // nothing looks, fires or queues for it (`armFor` answers `waiting`)
163
+ const turned = door.armFor(job, schedule);
164
+ if (turned && turned.armed === false) continue;
165
+ armedKeys.add(armKey);
166
+ }
107
167
  const ledger = door.ledgerOf(job);
108
168
  const { trigger } = schedule;
109
- if (isFileTrigger(trigger)) {
169
+ if (isTicketTrigger(trigger)) {
170
+ startLook(job, key, schedule, ledger, nowMs);
171
+ // a paused schedule still looks (tickets queue as `arrived`), but none runs
172
+ if (!door.paused(job)) runQueue(job, ledger, sig, nowMs, isBusy, pending, true);
173
+ } else if (isFileTrigger(trigger)) {
110
174
  let w = watchers.get(key);
111
175
  if (!w) {
112
176
  w = createFileTrigger({
@@ -135,11 +199,14 @@ export function createScheduler(opts) {
135
199
  }
136
200
  for (const k of [...watchers.keys()]) if (!live.has(k)) watchers.delete(k);
137
201
  for (const k of [...armedKeys]) if (!live.has(k)) armedKeys.delete(k);
202
+ for (const k of [...lookers.keys()]) if (!live.has(k)) lookers.delete(k);
138
203
  return Promise.all(pending).then(() => undefined);
139
204
  }
140
205
 
141
206
  return {
142
207
  tick,
208
+ /** resolves when every ticket look now out has been written to its ledger (a test awaits it; the timer never does) */
209
+ async settled() { await Promise.all([...lookers.values()].map((l) => l.out)); },
143
210
  /** Start the real timer (idempotent). */
144
211
  start() {
145
212
  if (intervalMs <= 0 || timer !== null) return;