bareloop 0.54.1 → 0.56.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.
- package/CHANGELOG.md +122 -0
- package/bareloop.context.md +67 -6
- package/package.json +3 -3
- package/src/authorflow.js +217 -238
- package/src/authoring.js +22 -6
- package/src/authorjob.js +138 -30
- package/src/authorreadout.js +15 -4
- package/src/authorrun.js +13 -4
- package/src/authorscout.js +9 -6
- package/src/behaviour.js +14 -0
- package/src/blockasks.js +43 -0
- package/src/cardschedule.js +42 -0
- package/src/checkblock.js +772 -0
- package/src/checklist.js +128 -0
- package/src/checkpick.js +294 -0
- package/src/checksuggest.js +28 -0
- package/src/checkwords.js +27 -0
- package/src/cli.js +1 -1
- package/src/config.js +24 -1
- package/src/declaredclose.js +30 -1
- package/src/destpoint.js +151 -0
- package/src/draftspend.js +85 -0
- package/src/facts.js +8 -1
- package/src/factwords.js +14 -1
- package/src/fitcheck.js +5 -3
- package/src/job.js +81 -1
- package/src/jobblock.js +9 -0
- package/src/labelscan.js +11 -0
- package/src/launcher.js +3 -2
- package/src/mcpchecks.js +52 -0
- package/src/mcppick.js +36 -0
- package/src/mcpsources.js +77 -0
- package/src/mcpuse.js +97 -0
- package/src/natural.js +23 -0
- package/src/pagemap.js +20 -5
- package/src/panel/authorroutes.js +105 -18
- package/src/panel/authorsession.js +293 -44
- package/src/panel/index.html +873 -41
- package/src/panel/jobgrid.js +117 -0
- package/src/panel/jobplan.js +103 -35
- package/src/panel/scheduler.js +80 -13
- package/src/panel/schedules.js +189 -28
- package/src/panel/schedulestart.js +44 -13
- package/src/panel/server.js +471 -39
- package/src/panel/settingsroutes.js +133 -3
- package/src/panel/status.js +19 -1
- package/src/panel/tickets.js +44 -0
- package/src/pickrecord.js +163 -0
- package/src/placerule.js +355 -0
- package/src/plan.js +31 -2
- package/src/planrun.js +71 -15
- package/src/prcheckout.js +259 -0
- package/src/promptregisters.js +11 -0
- package/src/questionbox.js +112 -0
- package/src/readshim.js +3 -2
- package/src/revises.js +56 -0
- package/src/rowedit.js +115 -0
- package/src/rubricstep.js +265 -132
- package/src/run.js +19 -2
- package/src/runexport.js +2 -0
- package/src/runlist.js +3 -2
- package/src/schedulewords.js +46 -4
- package/src/source.js +81 -7
- package/src/stepmcp.js +86 -0
- package/src/ticket.js +113 -0
- package/src/ticketfilter.js +76 -0
- package/src/ticketlabels.js +79 -0
- package/src/ticketmcp.js +111 -0
- package/src/ticketnext.js +35 -0
- package/src/ticketrepo.js +98 -0
- package/src/ticketschedule.js +32 -0
- package/src/ticketshape.js +45 -0
- package/src/tools.js +9 -0
- package/src/trigger.js +14 -2
- package/src/triggerclock.js +7 -3
- package/src/triggerfiles.js +19 -11
- package/src/triggertickets.js +244 -0
- package/src/userrun.js +191 -10
- package/src/validate.js +3 -1
- package/src/worktree.js +43 -1
- package/types/authorflow.d.ts +86 -93
- package/types/authorjob.d.ts +35 -4
- package/types/authorreadout.d.ts +4 -3
- package/types/authorscout.d.ts +4 -2
- package/types/behaviour.d.ts +12 -0
- package/types/blockasks.d.ts +37 -0
- package/types/cardschedule.d.ts +24 -0
- package/types/checkblock.d.ts +361 -0
- package/types/checklist.d.ts +134 -0
- package/types/checkpick.d.ts +160 -0
- package/types/checksuggest.d.ts +30 -0
- package/types/checkwords.d.ts +14 -0
- package/types/config.d.ts +7 -0
- package/types/declaredclose.d.ts +4 -0
- package/types/destpoint.d.ts +89 -0
- package/types/draftspend.d.ts +37 -0
- package/types/factwords.d.ts +7 -0
- package/types/fitcheck.d.ts +7 -1
- package/types/job.d.ts +13 -0
- package/types/jobblock.d.ts +9 -0
- package/types/labelscan.d.ts +7 -0
- package/types/launcher.d.ts +2 -2
- package/types/mcpchecks.d.ts +8 -0
- package/types/mcppick.d.ts +33 -0
- package/types/mcpsources.d.ts +51 -0
- package/types/mcpuse.d.ts +15 -0
- package/types/natural.d.ts +2 -0
- package/types/pagemap.d.ts +6 -1
- package/types/panel/authorroutes.d.ts +11 -2
- package/types/panel/authorsession.d.ts +69 -3
- package/types/panel/jobgrid.d.ts +405 -0
- package/types/panel/jobplan.d.ts +55 -11
- package/types/panel/scheduler.d.ts +7 -2
- package/types/panel/schedules.d.ts +124 -4
- package/types/panel/schedulestart.d.ts +21 -3
- package/types/panel/server.d.ts +432 -10
- package/types/panel/settingsroutes.d.ts +4 -2
- package/types/panel/status.d.ts +16 -2
- package/types/panel/tickets.d.ts +61 -0
- package/types/pickrecord.d.ts +100 -0
- package/types/placerule.d.ts +194 -0
- package/types/plan.d.ts +1 -0
- package/types/prcheckout.d.ts +151 -0
- package/types/questionbox.d.ts +87 -0
- package/types/readshim.d.ts +4 -3
- package/types/revises.d.ts +23 -0
- package/types/rowedit.d.ts +32 -0
- package/types/rubricstep.d.ts +100 -48
- package/types/run.d.ts +27 -1
- package/types/runlist.d.ts +6 -3
- package/types/schedulewords.d.ts +29 -2
- package/types/source.d.ts +40 -4
- package/types/stepmcp.d.ts +40 -0
- package/types/ticket.d.ts +114 -0
- package/types/ticketfilter.d.ts +34 -0
- package/types/ticketlabels.d.ts +44 -0
- package/types/ticketmcp.d.ts +84 -0
- package/types/ticketnext.d.ts +33 -0
- package/types/ticketrepo.d.ts +118 -0
- package/types/ticketschedule.d.ts +21 -0
- package/types/ticketshape.d.ts +37 -0
- package/types/tools.d.ts +1 -0
- package/types/trigger.d.ts +9 -1
- package/types/triggerclock.d.ts +6 -2
- package/types/triggerfiles.d.ts +13 -5
- package/types/triggertickets.d.ts +110 -0
- package/types/userrun.d.ts +50 -0
- package/types/validate.d.ts +1 -0
- 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
|
+
}
|
package/src/panel/jobplan.js
CHANGED
|
@@ -4,19 +4,31 @@
|
|
|
4
4
|
//
|
|
5
5
|
// { lines: [{n, text, rule, rules: [string...], checks: [{name, cls}], refused: [reason...]}],
|
|
6
6
|
// loose: [{name, cls}], checks that name no job line (an older caller, or a model slip)
|
|
7
|
-
// notChecked: [text...], "
|
|
7
|
+
// notChecked: [text...], "Not checked" — what nothing checks
|
|
8
|
+
// notCheckedBy: {text: 'you'|'agent'|'default'}, the tag of a Not checked row, by its row's kind (a refused line under a job line is keyed by its text too)
|
|
8
9
|
// alwaysOn: [text...], the mandatory guards / protections, which serve no job line
|
|
9
10
|
// older: boolean } an older job: the numbered lines were not saved
|
|
10
11
|
//
|
|
11
12
|
// `cls` is 'machine check' | 'judge' | null (null = not known yet: the confirm card's checks are the model's plan, the
|
|
12
13
|
// stage kinds exist only after drafting). Pure; no file IO.
|
|
14
|
+
import { ticketFilterWords } from '../ticketfilter.js';
|
|
13
15
|
import { KIND_CATALOGUE } from '../authoring.js';
|
|
16
|
+
import { WEEK_ONLY_WORDS } from '../checklist.js';
|
|
14
17
|
import { splitReadNotes } from '../pagedropwords.js';
|
|
15
|
-
import { checksOfClose, signedFactNames, proseNotChecked, lineRules, confirmedGoalOf } from '../rubricstep.js';
|
|
18
|
+
import { checksOfClose, signedFactNames, proseNotChecked, lineRules, confirmedGoalOf, refusedOf, listRowName, ruleNotCheckedItems } from '../rubricstep.js';
|
|
16
19
|
|
|
17
|
-
/**
|
|
18
|
-
/**
|
|
19
|
-
/** @typedef {{
|
|
20
|
+
/** `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 */
|
|
21
|
+
/** `stage` = the signed close stage the row belongs to (its recorded verdict is the row's result in the Audit) */
|
|
22
|
+
/** @typedef {{text: string, by: 'agent'|'you'|'default'|null, result: 'passed'|'failed'|'none'|'not-checked'|'held'|'record-missing', word?: string}} AuditRow */
|
|
23
|
+
/** @typedef {{name: string, cls: 'machine check'|'judge'|null, by?: 'agent'|'you'|'default'|null, key?: string, stage?: string}} PlanCheck */
|
|
24
|
+
/** @typedef {{n: number, text: string, rule: string, rules: string[], checks: PlanCheck[], refused: string[], always?: string[], picked?: string[]}} PlanLine */
|
|
25
|
+
/** @typedef {{lines: PlanLine[], loose: PlanCheck[], notChecked: string[], readNotes: string[], alwaysOn: string[], older: boolean, goal?: string, ticketFilter?: string, notCheckedBy?: Record<string, 'you'|'agent'|'default'>, suggested?: {key: string, line: number, text: string}[], editable?: boolean}} JobPlan */
|
|
26
|
+
|
|
27
|
+
/** the ticket filter's code-owned words as a plan part, or nothing (R5) @param {any} f @returns {{ticketFilter?: string}} */
|
|
28
|
+
function filterPart(f) {
|
|
29
|
+
const w = ticketFilterWords(f);
|
|
30
|
+
return w === null ? {} : { ticketFilter: w };
|
|
31
|
+
}
|
|
20
32
|
|
|
21
33
|
/**
|
|
22
34
|
* `machine check` for a kind a command decides, `judge` for one that needs judgement; `null` for a stage whose kind is
|
|
@@ -31,26 +43,18 @@ export function checkClassOfKind(kind) {
|
|
|
31
43
|
return spec.verdictClass === 'green' ? 'machine check' : 'judge';
|
|
32
44
|
}
|
|
33
45
|
|
|
34
|
-
/**
|
|
35
|
-
* The `~` rules of one job line, each on its own (the page draws one `~` row per rule): the line's own `rules` array when it
|
|
36
|
-
* has one (a rule may itself contain "; "), else the joined `rule` split on "; " (an older line that saved only the join).
|
|
37
|
-
* @param {any} l @returns {string[]}
|
|
38
|
-
*/
|
|
39
|
-
export function rulesOfLine(l) {
|
|
40
|
-
if (Array.isArray(l?.rules)) return l.rules.filter((/** @type {unknown} */ r) => typeof r === 'string' && r);
|
|
41
|
-
return typeof l?.rule === 'string' && l.rule ? l.rule.split('; ').filter(Boolean) : [];
|
|
42
|
-
}
|
|
43
|
-
|
|
44
46
|
/**
|
|
45
47
|
* The plan of a SIGNED spec. With `jobLines`, each stage lands under EACH line its `fromLine` array names (a stage with none is
|
|
46
48
|
* a mandatory guard: "Always checked"), `closeDecl.refused` reasons land under their line, and `closeDecl.notes` are the
|
|
47
49
|
* drafter's own "not checked" words. Without `jobLines` (a spec that predates the job block) the signed goal sentence is
|
|
48
50
|
* line 1 and every stage name is a check under it — `older: true`.
|
|
51
|
+
* `ledger` = the draft log's final check-list rows (`readDraftLedger`), the words a Not checked row is named by; absent (no draft log) a row is named from its key.
|
|
49
52
|
* @param {any} spec
|
|
53
|
+
* @param {{key: string, words: string[]}[]|null} [ledger]
|
|
50
54
|
* @returns {JobPlan}
|
|
51
55
|
*/
|
|
52
|
-
export function planFromSpec(spec) {
|
|
53
|
-
/** @type {{name: string, cls: 'machine check'|'judge'|null, fromLine: number[]|null}[]} */
|
|
56
|
+
export function planFromSpec(spec, ledger = null) {
|
|
57
|
+
/** @type {{name: string, cls: 'machine check'|'judge'|null, fromLine: number[]|null, by?: 'agent'|'you'|'default'|null, stage?: string}[]} */
|
|
54
58
|
let stages = [];
|
|
55
59
|
if (spec && Array.isArray(spec.closeDecl?.stages)) {
|
|
56
60
|
stages = spec.closeDecl.stages.filter((/** @type {any} */ s) => s && typeof s.name === 'string' && s.name)
|
|
@@ -58,8 +62,8 @@ export function planFromSpec(spec) {
|
|
|
58
62
|
const fromLine = Array.isArray(s.fromLine) && s.fromLine.length ? s.fromLine.filter(Number.isInteger) : null;
|
|
59
63
|
// 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
64
|
// 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 }];
|
|
65
|
+
const rows = s.kind === 'rubric-step' ? checksOfClose({ stages: [s], picks: spec.closeDecl.picks, list: spec.closeDecl.list }) : [];
|
|
66
|
+
return rows.length > 0 ? rows.map((r) => ({ name: r.text, cls: /** @type {'machine check'} */ ('machine check'), fromLine, by: r.by, stage: s.name })) : [{ name: s.name, cls: checkClassOfKind(s.kind), fromLine, by: /** @type {'agent'} */ ('agent'), stage: s.name }];
|
|
63
67
|
});
|
|
64
68
|
} else if (spec && Array.isArray(spec.close)) {
|
|
65
69
|
stages = spec.close.filter((/** @type {any} */ s) => s && typeof s.name === 'string' && s.name)
|
|
@@ -79,45 +83,57 @@ export function planFromSpec(spec) {
|
|
|
79
83
|
n: 1, text: typeof spec?.goal === 'string' && spec.goal ? spec.goal : '(no goal recorded)', rule: '', rules: [],
|
|
80
84
|
checks: stages.map((s) => ({ name: s.name, cls: s.cls })), refused: [],
|
|
81
85
|
}],
|
|
82
|
-
loose: [], notChecked: notes, readNotes, alwaysOn: [], older: true,
|
|
86
|
+
loose: [], notChecked: notes, readNotes, alwaysOn: [], older: true, ...filterPart(spec?.ticketFilter),
|
|
83
87
|
};
|
|
84
88
|
}
|
|
85
89
|
/** @type {PlanLine[]} */
|
|
86
|
-
const lines = jl.map((/** @type {any} */ l) => ({ n: l.n, text: l.text, rule: typeof l.rule === 'string' ? l.rule : '', rules:
|
|
90
|
+
const lines = jl.map((/** @type {any} */ l) => ({ n: l.n, text: l.text, rule: typeof l.rule === 'string' ? l.rule : '', rules: lineRules(l), checks: [], refused: [] }));
|
|
87
91
|
/** @type {PlanCheck[]} */
|
|
88
92
|
const loose = [];
|
|
89
93
|
/** @type {string[]} */
|
|
90
94
|
const alwaysOn = [];
|
|
95
|
+
/** Not checked rows tagged by their row's kind (F-c): `[you]` a rule the person wrote, `[agent]` the agent's, `[default]` code's @type {Record<string, 'you'|'agent'|'default'>} */
|
|
96
|
+
const refusedBy = {};
|
|
91
97
|
for (const s of stages) {
|
|
92
98
|
if (s.fromLine === null) { alwaysOn.push(s.name); continue; }
|
|
93
99
|
// a check that serves several job lines is shown under EACH line it serves (no new element: the same check line, repeated)
|
|
94
100
|
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 });
|
|
101
|
+
for (const line of served) line.checks.push({ name: s.name, cls: s.cls, ...(s.by ? { by: s.by } : {}), ...(s.stage ? { stage: s.stage } : {}) });
|
|
102
|
+
if (served.length === 0) loose.push({ name: s.name, cls: s.cls, ...(s.by ? { by: s.by } : {}), ...(s.stage ? { stage: s.stage } : {}) });
|
|
97
103
|
}
|
|
98
104
|
// an always-on guard that the drafter said covers a job line is shown under that line too ("› check · always-on: <guard>")
|
|
99
105
|
for (const g of Array.isArray(spec?.closeDecl?.guardLines) ? spec.closeDecl.guardLines : []) {
|
|
100
106
|
if (!g || typeof g.guard !== 'string' || !Array.isArray(g.lines)) continue;
|
|
101
107
|
for (const line of lines.filter((l) => g.lines.includes(l.n))) (line.always ??= []).push(g.guard);
|
|
102
108
|
}
|
|
103
|
-
const
|
|
104
|
-
for (const r of refused) {
|
|
109
|
+
for (const r of refusedOf(spec?.closeDecl)) {
|
|
105
110
|
const line = lines.find((l) => l.n === r?.line);
|
|
106
|
-
// a refusal of ONE ~ rule (PART 1b, RF16) names the rule in the person's words, so the row reads as that rule's Not checked
|
|
107
|
-
const ruleText = line && Number.isInteger(r.rule) ? lineRules(spec.jobLines.find((/** @type {any} */ l) => l?.n === r.line))[r.rule - 1] : null;
|
|
108
|
-
|
|
111
|
+
// a refusal of ONE ~ rule (PART 1b, RF16) names the rule in the person's words, so the row reads as that rule's Not checked; a list row of another kind names its fact when it has one
|
|
112
|
+
const ruleText = line && Number.isInteger(r.rule) ? lineRules(spec.jobLines.find((/** @type {any} */ l) => l?.n === r.line))[Number(r.rule) - 1] : (r.label ?? null);
|
|
113
|
+
// a list row that is not a fact or a rule (a phrase, a count) is named by its words: the draft log's, else the text after the key's kind prefix
|
|
114
|
+
const named = line && !ruleText && r.fromList && r.key ? listRowName(r.kind, r.key, ledger?.find((x) => x.key === r.key)?.words) : null;
|
|
115
|
+
const text = ruleText ? `"${ruleText}" — ${r.reason}` : (named ? `${named} — ${r.reason}` : r.reason);
|
|
116
|
+
if (line) { line.refused.push(text); if (r.by) refusedBy[text] = r.by; }
|
|
117
|
+
}
|
|
118
|
+
// a row the list dropped because it names a version or a date from the input is told, with its reason (the signed card preview, A11); other dropped rows are not drawn
|
|
119
|
+
for (const r of Array.isArray(spec?.closeDecl?.list) ? spec.closeDecl.list : []) {
|
|
120
|
+
if (!r || r.state !== 'dropped' || r.reason !== WEEK_ONLY_WORDS || typeof r.key !== 'string' || r.kind === 'rule') continue;
|
|
121
|
+
const line = lines.find((l) => l.n === r.line);
|
|
122
|
+
if (line) line.refused.push(`${listRowName(r.kind, r.key, ledger?.find((x) => x.key === r.key)?.words)} — ${r.reason}`);
|
|
109
123
|
}
|
|
124
|
+
const notCheckedBy = { ...refusedBy };
|
|
125
|
+
for (const i of ruleNotCheckedItems(spec?.closeDecl, spec?.jobLines, ledger)) if (i.by) notCheckedBy[i.text] = i.by;
|
|
110
126
|
// 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
127
|
// (a rubric job's signed goal is the whole worker brief: only the sentence the person confirmed is the summary)
|
|
112
128
|
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 } : {}) };
|
|
129
|
+
return { lines, loose, notChecked: notes, readNotes, alwaysOn, older: false, ...(Object.keys(notCheckedBy).length ? { notCheckedBy } : {}), ...(summary ? { goal: summary } : {}), ...filterPart(spec?.ticketFilter) };
|
|
114
130
|
}
|
|
115
131
|
|
|
116
132
|
/**
|
|
117
133
|
* The plan of the confirm turn, before anything is drafted: the person's own job lines, the model's checks under the
|
|
118
134
|
* line each names, its own "not checked" words, and the real protections (code-owned) as "Always checked".
|
|
119
135
|
* @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
|
|
136
|
+
* @param {{checkItems?: {text: string, fromLine: number[]|null, by?: 'agent'|'you'|'default'|null, key?: string}[], checks?: string[], notChecked?: string[], protections?: string[], signedFacts?: string[], ticketFilter?: any, picked?: {line: number, text: string}[], notCheckedBy?: Record<string, 'you'|'agent'|'default'>, suggested?: {key: string, line: number, text: string}[], editable?: boolean}} plan
|
|
121
137
|
* `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
138
|
* @returns {JobPlan}
|
|
123
139
|
*/
|
|
@@ -127,16 +143,68 @@ export function planFromConfirm(jobLines, plan) {
|
|
|
127
143
|
: (Array.isArray(plan?.checks) ? plan.checks.map((c) => ({ text: String(c), fromLine: null })) : []);
|
|
128
144
|
const jl = Array.isArray(jobLines) ? jobLines : [];
|
|
129
145
|
/** @type {PlanLine[]} */
|
|
130
|
-
const lines = jl.map((l) => ({ n: l.n, text: l.text, rule: l.rule, rules:
|
|
146
|
+
const lines = jl.map((l) => ({ n: l.n, text: l.text, rule: l.rule, rules: lineRules(l), checks: [], refused: [] }));
|
|
131
147
|
/** @type {PlanCheck[]} */
|
|
132
148
|
const loose = [];
|
|
133
|
-
|
|
149
|
+
// 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
|
|
150
|
+
const hasPicked = Array.isArray(plan?.picked) && plan.picked.length > 0;
|
|
151
|
+
for (const c of items.filter((x) => !(hasPicked && /** @type {any} */ (x).by === 'you' && !(/** @type {any} */ (x).key)))) {
|
|
152
|
+
const by = /** @type {any} */ (c).by === null ? {} : { by: /** @type {'agent'|'you'|'default'} */ (/** @type {any} */ (c).by ?? 'agent') };
|
|
134
153
|
const served = lines.filter((l) => Array.isArray(c.fromLine) && c.fromLine.includes(l.n));
|
|
135
|
-
|
|
136
|
-
|
|
154
|
+
const key = typeof (/** @type {any} */ (c).key) === 'string' ? { key: /** @type {any} */ (c).key } : {};
|
|
155
|
+
for (const line of served) line.checks.push({ name: c.text, cls: null, ...by, ...key });
|
|
156
|
+
if (served.length === 0) loose.push({ name: c.text, cls: null, ...by, ...key });
|
|
137
157
|
}
|
|
138
158
|
const { notChecked, readNotes } = splitReadNotes(plan?.notChecked, plan?.signedFacts);
|
|
159
|
+
// 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)
|
|
160
|
+
for (const x of Array.isArray(plan?.picked) ? plan.picked : []) {
|
|
161
|
+
const line = lines.find((l) => l.n === x?.line);
|
|
162
|
+
if (line && typeof x.text === 'string') (line.picked ??= []).push(x.text);
|
|
163
|
+
}
|
|
139
164
|
return {
|
|
140
|
-
lines, loose, notChecked, readNotes, alwaysOn: [...(plan?.protections ?? [])], older: false,
|
|
165
|
+
lines, loose, notChecked, readNotes, alwaysOn: [...(plan?.protections ?? [])], older: false, ...filterPart(plan?.ticketFilter),
|
|
166
|
+
...(plan?.notCheckedBy && typeof plan.notCheckedBy === 'object' && Object.keys(plan.notCheckedBy).length ? { notCheckedBy: plan.notCheckedBy } : {}),
|
|
167
|
+
...(Array.isArray(plan?.suggested) && plan.suggested.length ? { suggested: plan.suggested } : {}),
|
|
168
|
+
...(plan?.editable === true ? { editable: true } : {}),
|
|
141
169
|
};
|
|
142
170
|
}
|
|
171
|
+
|
|
172
|
+
/** the words of a row the run recorded no verdict for: never "passed" */
|
|
173
|
+
export const AUDIT_NO_RESULT = 'no result recorded';
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* The Audit's check list (hamr ruling A, 2026-11-13): the SAME sections as the card, read from the SAME model (`plan` = {@link planFromSpec}'s, plus `guards` = the
|
|
177
|
+
* code-owned protections the confirm card shows), each row with its tag and, after the run, its result. A check's result is the recorded verdict of its own signed stage
|
|
178
|
+
* (`results`: stage name to passed), never re-derived; a row no verdict was recorded for says so. A Not checked row's result is "not checked" (its reason is in its words).
|
|
179
|
+
* The write fence is enforced per write by the gate, so its row reads the gate's own record of THIS run (hamr ruling A, 2026-11-13): `blocked` = the write/edit attempts the gate denied
|
|
180
|
+
* (`held · N writes blocked`), or `null` when the run's gate record is missing (said in plain words, never "held").
|
|
181
|
+
* @param {JobPlan} plan @param {string[]} guards @param {Map<string, boolean>|null} results @param {number|null} [blocked]
|
|
182
|
+
* @returns {{checks: AuditRow[], notChecked: AuditRow[], always: AuditRow[]}}
|
|
183
|
+
*/
|
|
184
|
+
export function auditChecksOf(plan, guards, results, blocked = null) {
|
|
185
|
+
/** @param {string|undefined|null} stage @returns {'passed'|'failed'|'none'} */
|
|
186
|
+
const verdict = (stage) => (!stage || !results || !results.has(stage) ? 'none' : (results.get(stage) ? 'passed' : 'failed'));
|
|
187
|
+
/** @type {AuditRow[]} */
|
|
188
|
+
const checks = [];
|
|
189
|
+
for (const l of plan.lines) for (const c of l.checks) checks.push({ text: `line ${l.n} · ${c.name}`, by: c.by ?? null, result: verdict(c.stage) });
|
|
190
|
+
for (const c of plan.loose) checks.push({ text: `other · ${c.name}`, by: c.by ?? null, result: verdict(c.stage) });
|
|
191
|
+
/** @type {AuditRow[]} */
|
|
192
|
+
const notChecked = [];
|
|
193
|
+
const by = plan.notCheckedBy ?? {};
|
|
194
|
+
for (const l of plan.lines) for (const r of l.refused) notChecked.push({ text: `line ${l.n} · ${r}`, by: by[r] ?? null, result: 'not-checked' });
|
|
195
|
+
for (const r of plan.notChecked) notChecked.push({ text: r, by: by[r] ?? null, result: 'not-checked' });
|
|
196
|
+
const names = guards.length > 0 ? guards : plan.alwaysOn;
|
|
197
|
+
const always = names.map((g) => {
|
|
198
|
+
const head = g.split(' — ')[0];
|
|
199
|
+
const file = /^line (\d+) file$/.exec(head);
|
|
200
|
+
// the write fence is held by the gate (the row reads the gate's own record, above), never another stage's verdict
|
|
201
|
+
const stage = file ? `line-${file[1]}` : (head === 'write fence' ? null : head);
|
|
202
|
+
if (head === 'write fence') {
|
|
203
|
+
return blocked === null
|
|
204
|
+
? { text: g, by: /** @type {'default'} */ ('default'), result: /** @type {'record-missing'} */ ('record-missing'), word: "the gate's record for this run is missing" }
|
|
205
|
+
: { text: g, by: /** @type {'default'} */ ('default'), result: /** @type {'held'} */ ('held'), word: `held · ${blocked} ${blocked === 1 ? 'write' : 'writes'} blocked` };
|
|
206
|
+
}
|
|
207
|
+
return { text: g, by: /** @type {'default'} */ ('default'), result: verdict(stage) };
|
|
208
|
+
});
|
|
209
|
+
return { checks, notChecked, always };
|
|
210
|
+
}
|
package/src/panel/scheduler.js
CHANGED
|
@@ -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,
|
|
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(
|
|
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 (
|
|
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;
|