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
package/src/panel/schedules.js
CHANGED
|
@@ -21,12 +21,14 @@ import { checkMonthlyRoom, monthlyRefusalText } from '../monthly.js';
|
|
|
21
21
|
import { ConfigError } from '../config.js';
|
|
22
22
|
import { doorAccepted } from '../reviewdoor.js';
|
|
23
23
|
import { findRow } from '../providerrows.js';
|
|
24
|
-
import { validateTrigger, isClockTrigger, isFileTrigger } from '../trigger.js';
|
|
24
|
+
import { validateTrigger, isClockTrigger, isFileTrigger, isTicketTrigger } from '../trigger.js';
|
|
25
25
|
import { armTrigger, nextSlot, recordFire } from '../triggerclock.js';
|
|
26
26
|
import { appendRow, readLedger, withoutReleased } from '../triggerledger.js';
|
|
27
27
|
import { checkTarget, createFileTrigger, queueOf, readSeen, recordDropped, recordRan } from '../triggerfiles.js';
|
|
28
|
+
import { lookProblemOf, recordAnyway, recordTicketRan } from '../triggertickets.js';
|
|
29
|
+
import { ticketInputLabels, ticketLookOf } from '../ticketschedule.js';
|
|
28
30
|
import {
|
|
29
|
-
SCHEDULE_WORDS, dateTimeWords, gaveUpDateWords, lateRefusalWords, nextInWords, nextSlotShort, nextTimeWords, retryNextWords, sameMonthAs, scheduledNextFor, scheduledWords, skippedWords,
|
|
31
|
+
SCHEDULE_WORDS, dateTimeWords, gaveUpDateWords, lateRefusalWords, nextInWords, nextSlotShort, nextTimeWords, retryNextWords, sameMonthAs, scheduledNextFor, scheduledWords, lookProblemWords, skippedWords,
|
|
30
32
|
} from '../schedulewords.js';
|
|
31
33
|
import { buildReuseSpec, startDestinationProblem, validateReuseCard } from './authorsession.js';
|
|
32
34
|
|
|
@@ -83,7 +85,7 @@ export function runnerAlive(row, nowMs) {
|
|
|
83
85
|
}
|
|
84
86
|
|
|
85
87
|
/**
|
|
86
|
-
* @typedef {{runid: string, outcome: string|null, spec: any, records: any[]}} JobRun
|
|
88
|
+
* @typedef {{runid: string, outcome: string|null, spec: any, records: any[], ticket?: number}} JobRun
|
|
87
89
|
* @typedef {{job: string, trigger: import('../trigger.js').Trigger, spec: any, specHash: string, workflowKey: string,
|
|
88
90
|
* originRunid: string, inputsText: string, destination?: string, signedBy: string, signedAt: string}} Schedule
|
|
89
91
|
*/
|
|
@@ -146,36 +148,79 @@ export function createScheduleDoor(deps) {
|
|
|
146
148
|
* THE gate (T3). The job's CURRENT workflow key is the key of its newest listed run whose signed spec is on disk.
|
|
147
149
|
* It passes when a run with THAT key has a real `green` outcome (`already-green` does not count) and, for a rubric
|
|
148
150
|
* job, that run's spine holds an honoured accept. An edited job has a new key, so an older green does not count (T5).
|
|
149
|
-
* @param {string} job
|
|
151
|
+
* @param {string} job @param {Set<string>} [skip] runs that do not count (R7: the runs that existed when a schedule was signed WITH its job, so only a later run turns it on)
|
|
150
152
|
* @returns {{ok: true, run: JobRun, key: string} | {ok: false, say: string}}
|
|
151
153
|
*/
|
|
152
|
-
function greenFor(job) {
|
|
154
|
+
function greenFor(job, skip) {
|
|
153
155
|
const runs = deps.jobRuns(job);
|
|
154
156
|
const head = runs.find((r) => r.spec);
|
|
155
157
|
if (!head) return { ok: false, say: SCHEDULE_WORDS.notGreen };
|
|
156
158
|
const key = workflowKey(head.spec);
|
|
157
|
-
const hit = runs.find((r) => r.spec && workflowKey(r.spec) === key && r.outcome === 'green'
|
|
159
|
+
const hit = runs.find((r) => !(skip && skip.has(r.runid)) && r.spec && workflowKey(r.spec) === key && r.outcome === 'green'
|
|
158
160
|
&& (r.spec.verdictType !== 'soft-green' || doorAccepted(r.records)));
|
|
159
161
|
return hit ? { ok: true, run: hit, key } : { ok: false, say: SCHEDULE_WORDS.notGreen };
|
|
160
162
|
}
|
|
161
163
|
|
|
164
|
+
/**
|
|
165
|
+
* The ledger rows of the CURRENT signing (live ones), oldest first. @param {string} job @param {string} sig
|
|
166
|
+
*/
|
|
167
|
+
function rowsOf(job, sig) {
|
|
168
|
+
return withoutReleased(readLedger(ledgerOf(job)).rows).filter((r) => r.sig === sig);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* R7 (piece 9): the `armed` row of a signing, or undefined. A `waiting` row (a schedule signed WITH its job on the New job card) starts the signing over: an `armed` row older than the
|
|
173
|
+
* newest `waiting` row belongs to an earlier life of the same signature and does not count.
|
|
174
|
+
* @param {import('../triggerledger.js').LedgerRow[]} rows the live rows of one signing
|
|
175
|
+
*/
|
|
176
|
+
function armedRowOf(rows) {
|
|
177
|
+
const w = rows.map((r) => r.kind).lastIndexOf('waiting');
|
|
178
|
+
return rows.slice(w + 1).find((r) => r.kind === 'armed');
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* R7 (piece 9): the `waiting` row when the signing is signed with its job and still OFF - no `armed` row after it, and no later `signed` row (the two-click door's click 2 supersedes the wait).
|
|
183
|
+
* @param {import('../triggerledger.js').LedgerRow[]} rows the live rows of one signing @returns {import('../triggerledger.js').LedgerRow|null}
|
|
184
|
+
*/
|
|
185
|
+
function waitingRowOf(rows) {
|
|
186
|
+
if (armedRowOf(rows)) return null;
|
|
187
|
+
const marks = rows.filter((r) => r.kind === 'waiting' || r.kind === 'signed');
|
|
188
|
+
const last = marks.length > 0 ? marks[marks.length - 1] : null;
|
|
189
|
+
return last !== null && last.kind === 'waiting' ? last : null;
|
|
190
|
+
}
|
|
191
|
+
|
|
162
192
|
/**
|
|
163
193
|
* The ONE writer of "this schedule was armed". A file kind records what is already there first (it never runs),
|
|
164
194
|
* then the armed row, so a failure between the two leaves it unarmed and the next call finishes it. Idempotent for
|
|
165
195
|
* a signing: a second call with the same sig writes nothing. Throws, naming why, when the target is not usable.
|
|
196
|
+
* R7: a schedule signed WITH its job waits (`waitingRowOf`): it arms only when a run that began after the signing has a real green (`greenFor`, so a rubric job needs its honoured Accept);
|
|
197
|
+
* until then this returns `{armed: false, waiting: true}` and writes nothing. A ticket schedule keeps the ticket number that run read (`ticketN`).
|
|
166
198
|
* @param {string} job @param {Schedule} schedule @param {{baseline?: boolean}} [o] `baseline: false` = a re-sign that kept the same folder/file: its queue and baseline stand
|
|
199
|
+
* @returns {{armed: boolean, already?: boolean, waiting?: boolean}}
|
|
167
200
|
*/
|
|
168
201
|
function armFor(job, schedule, o = {}) {
|
|
169
202
|
const sig = schedule.specHash;
|
|
170
203
|
const ledger = ledgerOf(job);
|
|
171
|
-
|
|
204
|
+
const rows = rowsOf(job, sig);
|
|
205
|
+
if (armedRowOf(rows)) return { armed: true, already: true };
|
|
206
|
+
const wait = waitingRowOf(rows);
|
|
207
|
+
/** @type {number|undefined} */
|
|
208
|
+
let ticketN;
|
|
209
|
+
if (wait) {
|
|
210
|
+
const green = cachedGreen(job, new Set(Array.isArray(wait.before) ? wait.before.map(String) : []));
|
|
211
|
+
// the run that turns it on must be of THIS workflow (an edited job is a new workflow and its schedule never arms)
|
|
212
|
+
if (!green.ok || green.key !== schedule.workflowKey) return { armed: false, waiting: true };
|
|
213
|
+
if (isTicketTrigger(schedule.trigger) && Number.isInteger(green.run.ticket)) ticketN = green.run.ticket;
|
|
214
|
+
// the schedule now names the run it was turned on by (the card opens from it); written before the armed row, so a crash between the two is finished by the next call
|
|
215
|
+
if (green.run.runid !== schedule.originRunid) writeSchedule(job, { ...schedule, originRunid: green.run.runid });
|
|
216
|
+
}
|
|
172
217
|
if (isFileTrigger(schedule.trigger) && o.baseline !== false) {
|
|
173
218
|
const t = schedule.trigger;
|
|
174
219
|
createFileTrigger({
|
|
175
220
|
mode: t.kind === 'new-file' ? 'new' : 'updated', target: t.kind === 'new-file' ? t.folder : t.path, ledger, sig, now,
|
|
176
221
|
}).arm();
|
|
177
222
|
}
|
|
178
|
-
armTrigger(ledger, now(), sig);
|
|
223
|
+
armTrigger(ledger, now(), sig, ticketN);
|
|
179
224
|
return { armed: true, already: false };
|
|
180
225
|
}
|
|
181
226
|
|
|
@@ -255,6 +300,12 @@ export function createScheduleDoor(deps) {
|
|
|
255
300
|
}
|
|
256
301
|
const spec = buildReuseSpec(pre.spec, card, rows);
|
|
257
302
|
spec.trigger = trigger;
|
|
303
|
+
if (isTicketTrigger(trigger)) {
|
|
304
|
+
// MCP + tickets piece 3: the look reads with the SIGNED tools. The job to be signed (the card's Inputs included) must be a Tickets MCP job whose tools include `list_issues`, and the
|
|
305
|
+
// named Inputs line must be an issues list; the refusal is plain words at sign time, never a schedule that can never look
|
|
306
|
+
const look = ticketLookOf(spec, trigger);
|
|
307
|
+
if (!look.ok) return reply(400, { refused: 'bad-trigger', say: look.say });
|
|
308
|
+
}
|
|
258
309
|
const jv = validateJob(spec, { shellCapUsd: spec.budgetUsd });
|
|
259
310
|
if (!jv.ok) return reply(400, { refused: 'bad-spec', say: `The job this would sign is not valid (${jv.reds.map((r) => `${r.code} at ${r.path}`).join('; ')}). Nothing was changed.` });
|
|
260
311
|
if (workflowKey(spec) !== green.key) return reply(400, { refused: 'bad-spec', say: 'The job this would sign is not the one that had the good run. Nothing was changed.' });
|
|
@@ -312,16 +363,18 @@ export function createScheduleDoor(deps) {
|
|
|
312
363
|
*/
|
|
313
364
|
function stateOf(job) {
|
|
314
365
|
const schedule = readSchedule(job);
|
|
315
|
-
if (!schedule) return { schedule: null, trigger: null, armed: false, armedAt: null, nextSlotMs: null, lastOutcome: null, retryInMs: null, gaveUp: null };
|
|
366
|
+
if (!schedule) return { schedule: null, trigger: null, armed: false, armedAt: null, waiting: false, nextSlotMs: null, lastOutcome: null, retryInMs: null, gaveUp: null, lookProblem: null };
|
|
316
367
|
const rows = withoutReleased(readLedger(ledgerOf(job)).rows).filter((r) => r.sig === schedule.specHash);
|
|
317
|
-
const armed = rows
|
|
368
|
+
const armed = armedRowOf(rows);
|
|
318
369
|
const outcomes = rows.filter((r) => OUTCOME_KINDS.includes(r.kind));
|
|
319
370
|
return {
|
|
320
|
-
schedule, trigger: schedule.trigger, armed: armed !== undefined, armedAt: armed ? armed.at : null,
|
|
371
|
+
schedule, trigger: schedule.trigger, armed: armed !== undefined, armedAt: armed ? armed.at : null, waiting: waitingRowOf(rows) !== null,
|
|
321
372
|
nextSlotMs: isClockTrigger(schedule.trigger) && armed ? nextSlot(/** @type {any} */ (schedule.trigger), now()) : null,
|
|
322
373
|
lastOutcome: outcomes.length > 0 ? outcomes[outcomes.length - 1] : null,
|
|
323
374
|
retryInMs: (() => { const w = installWait.get(job); return w && w.until > now() ? w.until - now() : null; })(),
|
|
324
375
|
gaveUp: pausedRow(rows),
|
|
376
|
+
// R9 (fwd 9b.3): the cause when the newest look of a ticket schedule could not read (pass locked, a server error), else null; a later look that reads clears it
|
|
377
|
+
lookProblem: schedule.trigger.kind === 'new-ticket' ? lookProblemOf(readSeen(ledgerOf(job), schedule.specHash)) : null,
|
|
325
378
|
};
|
|
326
379
|
}
|
|
327
380
|
|
|
@@ -357,16 +410,16 @@ export function createScheduleDoor(deps) {
|
|
|
357
410
|
/**
|
|
358
411
|
* `greenFor`, memoised on the job's run-list state (each of its spines' size and mtime), so the Run tab's poll does not
|
|
359
412
|
* re-parse every run of the job each time. A finished run changes its spine, so the key moves and the gate is asked again.
|
|
360
|
-
* @param {string} job
|
|
413
|
+
* @param {string} job @param {Set<string>} [skip] see {@link greenFor}; part of the memo key
|
|
361
414
|
*/
|
|
362
|
-
function cachedGreen(job) {
|
|
415
|
+
function cachedGreen(job, skip) {
|
|
363
416
|
const rows = (deps.runRows ? deps.runRows() : readRunList({ home: deps.home }).rows).filter((r) => r && r.job === job);
|
|
364
|
-
const key = rows.map((r) => {
|
|
417
|
+
const key = `${rows.map((r) => {
|
|
365
418
|
try { const st = statSync(r.spine); return `${r.runid}:${st.size}:${st.mtimeMs}`; } catch { return `${r.runid}:gone`; }
|
|
366
|
-
}).join('|')
|
|
419
|
+
}).join('|')}#${skip ? [...skip].sort().join(',') : ''}`;
|
|
367
420
|
const hit = greenMemo.get(job);
|
|
368
421
|
if (hit && hit.key === key) return hit.green;
|
|
369
|
-
const green = greenFor(job);
|
|
422
|
+
const green = greenFor(job, skip);
|
|
370
423
|
greenMemo.set(job, { key, green });
|
|
371
424
|
return green;
|
|
372
425
|
}
|
|
@@ -399,7 +452,7 @@ export function createScheduleDoor(deps) {
|
|
|
399
452
|
* `key|outcome|why` (read back from disk, so a restart does not repeat it). RULED 2026-10-14: a busy, monthly or refused
|
|
400
453
|
* fire consumes NOTHING, so the next tick tries again; a spawn error after `beforeSpawn` writes a `released` row (bounded).
|
|
401
454
|
* @param {string} job
|
|
402
|
-
* @param {{kind: 'clock', slot: number, catchUp: boolean, missed: number} | {kind: 'file', path: string, sha: string, size?: number}} cause
|
|
455
|
+
* @param {{kind: 'clock', slot: number, catchUp: boolean, missed: number} | {kind: 'file', path: string, sha: string, size?: number} | {kind: 'ticket', number: number, sha: string, why?: string, anyway?: boolean}} cause
|
|
403
456
|
* @param {{beforeSpawn?: () => void, busy?: boolean}} [hooks] `busy` = the scheduler's one read of the run list this tick
|
|
404
457
|
* @returns {Promise<{outcome: 'busy'|'monthly-exhausted'|'refused'|'started', why?: string, told: boolean, sessionId?: string}>}
|
|
405
458
|
*/
|
|
@@ -408,9 +461,10 @@ export function createScheduleDoor(deps) {
|
|
|
408
461
|
if (!schedule || !starter) return { outcome: 'refused', why: 'This job has no schedule any more. Nothing started.', told: false };
|
|
409
462
|
const sig = schedule.specHash;
|
|
410
463
|
const ledger = ledgerOf(job);
|
|
411
|
-
const key = cause.kind === '
|
|
412
|
-
const consumeId = cause.kind === '
|
|
413
|
-
const base = cause.kind === 'file' ? { file: cause.path, sha: cause.sha }
|
|
464
|
+
const key = cause.kind === 'clock' ? String(cause.slot) : cause.sha;
|
|
465
|
+
const consumeId = cause.kind === 'clock' ? `fire:${cause.slot}` : `ran:${cause.sha}`;
|
|
466
|
+
const base = cause.kind === 'file' ? { file: cause.path, sha: cause.sha }
|
|
467
|
+
: cause.kind === 'ticket' ? { ticket: cause.number, sha: cause.sha } : { slot: cause.slot, catchUp: cause.catchUp, missed: cause.missed };
|
|
414
468
|
/** @param {'busy'|'monthly-exhausted'|'refused'} outcome @param {string} why @param {Record<string, unknown>} [extra] */
|
|
415
469
|
const told = (outcome, why, extra = {}) => {
|
|
416
470
|
const tag = `${key}|${outcome}|${why}`;
|
|
@@ -430,7 +484,7 @@ export function createScheduleDoor(deps) {
|
|
|
430
484
|
return told('refused', `${e.message} — refusing rather than guess the monthly limit. Nothing started.`);
|
|
431
485
|
}
|
|
432
486
|
// already consumed (a live `fire`/`ran` row, e.g. given up on after releases): never start it a second time
|
|
433
|
-
if (readLedger(ledger).rows.length > 0 && withoutReleased(readLedger(ledger).rows).some((r) => r.id === consumeId)) {
|
|
487
|
+
if (readLedger(ledger).rows.length > 0 && withoutReleased(readLedger(ledger).rows).some((r) => r.id === consumeId && (cause.kind !== 'ticket' || r.sig === sig))) {
|
|
434
488
|
return { outcome: 'refused', why: 'This one was already started or given up on.', told: false };
|
|
435
489
|
}
|
|
436
490
|
// RULED 2026-10-15: inside an install-needed wait nothing is written, no session made, no copy or install run
|
|
@@ -440,6 +494,7 @@ export function createScheduleDoor(deps) {
|
|
|
440
494
|
if (!accept.ok) return told('refused', accept.why);
|
|
441
495
|
const beforeSpawn = hooks.beforeSpawn ?? (() => {
|
|
442
496
|
if (cause.kind === 'file') recordRan(ledger, { sha: cause.sha, path: cause.path, size: cause.size ?? 0 }, now(), sig);
|
|
497
|
+
else if (cause.kind === 'ticket') recordTicketRan(ledger, sig, { sha: cause.sha, name: `#${cause.number}` }, now());
|
|
443
498
|
else recordFire(ledger, { fire: true, slot: cause.slot, catchUp: cause.catchUp, missed: cause.missed }, now(), sig);
|
|
444
499
|
});
|
|
445
500
|
starting.set(job, now());
|
|
@@ -475,6 +530,72 @@ export function createScheduleDoor(deps) {
|
|
|
475
530
|
return out;
|
|
476
531
|
},
|
|
477
532
|
|
|
533
|
+
/**
|
|
534
|
+
* R7, am3 (fwd M13 am3): "Run it anyway" on a ticket while the job's ticket schedule is still OFF (signed with the job, waiting for its first green run): start that ticket's run at
|
|
535
|
+
* once, by hand, with the job's normal cap, after the same busy / monthly / would-accept checks a fire makes. `null` = not this door's case (no ticket schedule, or it is on: the queue
|
|
536
|
+
* takes it, R8). Else `{ok, say}`; a refusal starts nothing and spends $0. It writes NO ledger row: a skipped run never arms the schedule, a green one does (`armFor`).
|
|
537
|
+
* `fromRun` (am3, no ticket schedule at all): the skipped run whose saved signed job is started instead of a schedule's.
|
|
538
|
+
* @param {{job: string, number: number, fromRun?: string}} a
|
|
539
|
+
* @returns {Promise<{ok: boolean, say: string}|null>}
|
|
540
|
+
*/
|
|
541
|
+
async startAnyway({ job, number, fromRun }) {
|
|
542
|
+
if (!SLUG_RE.test(job)) return null;
|
|
543
|
+
/** @type {any} */
|
|
544
|
+
let spec;
|
|
545
|
+
if (fromRun === undefined) {
|
|
546
|
+
const schedule = readSchedule(job);
|
|
547
|
+
if (!schedule || !isTicketTrigger(schedule.trigger) || !stateOf(job).waiting || !starter) return null;
|
|
548
|
+
spec = schedule.spec;
|
|
549
|
+
} else {
|
|
550
|
+
// am3 with NO ticket schedule: the signed job is the skipped run's own (its session's saved copy, read through the one `startFrom`)
|
|
551
|
+
if (!starter) return null;
|
|
552
|
+
const pre = deps.startFrom(fromRun);
|
|
553
|
+
if (!pre || !pre.ok) return { ok: false, say: `This skipped ticket's signed job cannot be read (${String(pre?.error ?? 'its run is gone from the list').replace(/\.$/, '')}), so it cannot be run from here. Nothing started.` };
|
|
554
|
+
spec = pre.spec;
|
|
555
|
+
}
|
|
556
|
+
if (!Number.isSafeInteger(number) || number < 1) return { ok: false, say: 'The ticket number must be a whole number from 1 up. Nothing started.' };
|
|
557
|
+
if (busy(job)) return { ok: false, say: 'A run of this job is still going. Nothing started.' };
|
|
558
|
+
try {
|
|
559
|
+
const room = checkMonthlyRoom({ capUsd: spec.budgetUsd, home: deps.home, sessionsRoot: deps.sessionsRoot, now });
|
|
560
|
+
if (!room.ok) return { ok: false, say: "This month's limit has no room for this job's cap. Nothing started." };
|
|
561
|
+
} catch (e) {
|
|
562
|
+
if (!(e instanceof ConfigError)) throw e;
|
|
563
|
+
return { ok: false, say: `${e.message} — refusing rather than guess the monthly limit. Nothing started.` };
|
|
564
|
+
}
|
|
565
|
+
const cause = { kind: /** @type {const} */ ('ticket'), number, sha: `ticket:${number}`, byHand: true, ...(fromRun === undefined ? {} : { fromRun }) };
|
|
566
|
+
const accept = starter.wouldAccept(job, cause);
|
|
567
|
+
if (!accept.ok) return { ok: false, say: accept.why };
|
|
568
|
+
starting.set(job, now());
|
|
569
|
+
const r = await starter.start(job, cause);
|
|
570
|
+
if (!r.ok) { starting.delete(job); return { ok: false, say: r.why }; }
|
|
571
|
+
return { ok: true, say: fromRun === undefined ? `Ticket #${number} started now; the schedule is still off until a green run.` : `Ticket #${number} started now.` };
|
|
572
|
+
},
|
|
573
|
+
|
|
574
|
+
/**
|
|
575
|
+
* R8 (piece 4, `POST /api/author/ticket-anyway`): the ONE door of "Run it anyway" once the person has given a reason (the route checks it). A ticket schedule that is still OFF starts that
|
|
576
|
+
* ticket's run at once ({@link startAnyway}, by hand, no row); one that is ON takes ONE `arrived` row with the reason and `anyway: true` ({@link recordAnyway}), and the queue starts it
|
|
577
|
+
* with `--anyway` under the job's normal cap. A job with NO ticket schedule (am3: for a first ticket this is the only way to run it) starts at once from the skipped run's own saved signed job
|
|
578
|
+
* (`runid`, the grid's skipped row, through the one `startFrom` and the one starter); with no readable job there, or no `runid`, it is refused in words and nothing is written.
|
|
579
|
+
* @param {{job: string, number: number, reason: string, runid?: string}} a
|
|
580
|
+
* @returns {Promise<{ok: boolean, say: string, started?: boolean}>}
|
|
581
|
+
*/
|
|
582
|
+
async arriveAnyway({ job, number, reason, runid }) {
|
|
583
|
+
const schedule = SLUG_RE.test(job) ? readSchedule(job) : null;
|
|
584
|
+
if ((!schedule || !isTicketTrigger(schedule.trigger)) && SLUG_RE.test(job) && typeof runid === 'string' && runid !== '') {
|
|
585
|
+
const r = await this.startAnyway({ job, number, fromRun: runid });
|
|
586
|
+
if (r === null) return { ok: false, say: 'The job could not start this ticket now. Nothing started.' };
|
|
587
|
+
return { ok: r.ok, say: r.say, ...(r.ok ? { started: true } : {}) };
|
|
588
|
+
}
|
|
589
|
+
if (!schedule || !isTicketTrigger(schedule.trigger)) return { ok: false, say: `Job "${job}" has no ticket schedule, so Run it anyway has nothing to start it from. Nothing started.` };
|
|
590
|
+
if (stateOf(job).waiting) {
|
|
591
|
+
const r = await this.startAnyway({ job, number });
|
|
592
|
+
if (r === null) return { ok: false, say: 'The job could not start this ticket now. Nothing started.' };
|
|
593
|
+
return { ok: r.ok, say: r.say, ...(r.ok ? { started: true } : {}) };
|
|
594
|
+
}
|
|
595
|
+
const r = recordAnyway(ledgerOf(job), schedule.specHash, { number, reason }, now());
|
|
596
|
+
return r.ok ? { ok: true, say: `Ticket #${number} is queued; it runs when its turn comes.` } : { ok: false, say: r.say };
|
|
597
|
+
},
|
|
598
|
+
|
|
478
599
|
greenFor,
|
|
479
600
|
armFor,
|
|
480
601
|
readSchedule,
|
|
@@ -511,7 +632,7 @@ export function createScheduleDoor(deps) {
|
|
|
511
632
|
}
|
|
512
633
|
const cur = s.cur;
|
|
513
634
|
const keep = sameTarget(cur, s.trigger);
|
|
514
|
-
if (cur && !keep && isFileTrigger(cur.trigger)) dropQueue(s.job, jobSpecHash(s.spec), 'schedule-changed');
|
|
635
|
+
if (cur && !keep && (isFileTrigger(cur.trigger) || isTicketTrigger(cur.trigger))) dropQueue(s.job, jobSpecHash(s.spec), 'schedule-changed');
|
|
515
636
|
/** @type {Schedule} */
|
|
516
637
|
const schedule = {
|
|
517
638
|
job: s.job, trigger: s.trigger, spec: s.spec, specHash: s.hash, workflowKey: s.key, originRunid: s.originRunid,
|
|
@@ -527,6 +648,39 @@ export function createScheduleDoor(deps) {
|
|
|
527
648
|
return { status: 200, body: { ok: true, job: s.job, words: s.words, hash: s.hash, armed, ...(say ? { say } : {}) } };
|
|
528
649
|
},
|
|
529
650
|
|
|
651
|
+
/**
|
|
652
|
+
* R7 (piece 9, hamr: schedule exactly like fwd): the New job card's Sign & run signs the schedule WITH the job, written OFF. It writes `schedule.json`, a `signed` row and a `waiting`
|
|
653
|
+
* row that remembers the runs the job already had (`before`): only a run that began after this turns the schedule on (`armFor`, the one turn-on), and a skipped run never does.
|
|
654
|
+
* Nothing looks or fires while it waits. $0. A refusal names why and writes nothing. The job is the one just signed, so a job that already has a schedule is refused (the two-click door edits it).
|
|
655
|
+
* @param {{spec: any, specHash: string, trigger: unknown, inputsText: string, destination?: string|null}} o `spec` = the signed spec WITH its `trigger`; `specHash` = the hash the person signed (it must be the spec's own)
|
|
656
|
+
* @returns {{ok: true, hash: string}|{ok: false, say: string}}
|
|
657
|
+
*/
|
|
658
|
+
signWithJob(o) {
|
|
659
|
+
const job = o.spec?.job;
|
|
660
|
+
if (typeof job !== 'string' || !SLUG_RE.test(job)) return { ok: false, say: 'This job has no name a schedule can be kept under. Nothing was signed.' };
|
|
661
|
+
const tv = validateTrigger(o.trigger);
|
|
662
|
+
if (!tv.ok) return { ok: false, say: `${tv.say}. Nothing was signed.` };
|
|
663
|
+
if (!isClockTrigger(tv.trigger) && !isTicketTrigger(tv.trigger)) return { ok: false, say: 'The New job card can start a job every day or on a new ticket. A file trigger is set after the first good run. Nothing was signed.' };
|
|
664
|
+
if (readSchedule(job)) return { ok: false, say: 'This job already has a schedule. Change it with Cancel / modify schedule on one of its runs. Nothing was signed.' };
|
|
665
|
+
if (isTicketTrigger(tv.trigger)) {
|
|
666
|
+
const look = ticketLookOf(o.spec, tv.trigger);
|
|
667
|
+
if (!look.ok) return { ok: false, say: look.say };
|
|
668
|
+
}
|
|
669
|
+
const hash = jobSpecHash(o.spec);
|
|
670
|
+
if (hash !== o.specHash) return { ok: false, say: 'The saved copy of this job no longer matches what was signed. Nothing was signed.' };
|
|
671
|
+
const before = (deps.runRows ? deps.runRows() : readRunList({ home: deps.home }).rows).filter((r) => r && r.job === job).map((r) => String(r.runid));
|
|
672
|
+
/** @type {Schedule} */
|
|
673
|
+
const schedule = {
|
|
674
|
+
job, trigger: tv.trigger, spec: o.spec, specHash: hash, workflowKey: workflowKey(o.spec), originRunid: '',
|
|
675
|
+
inputsText: o.inputsText, ...(typeof o.destination === 'string' && o.destination !== '' ? { destination: o.destination } : {}), signedBy: userInfo().username, signedAt: new Date(now()).toISOString(),
|
|
676
|
+
};
|
|
677
|
+
writeSchedule(job, schedule);
|
|
678
|
+
appendRow(ledgerOf(job), { kind: 'signed', sig: hash, at: now() });
|
|
679
|
+
appendRow(ledgerOf(job), { kind: 'waiting', sig: hash, at: now(), before });
|
|
680
|
+
installWait.delete(job);
|
|
681
|
+
return { ok: true, hash };
|
|
682
|
+
},
|
|
683
|
+
|
|
530
684
|
/** Cancel a job's schedule, never refused. @param {string} job @returns {boolean} there was one */
|
|
531
685
|
cancel(job) {
|
|
532
686
|
const cur = SLUG_RE.test(job) ? readSchedule(job) : null;
|
|
@@ -563,6 +717,8 @@ export function createScheduleDoor(deps) {
|
|
|
563
717
|
},
|
|
564
718
|
|
|
565
719
|
stateOf,
|
|
720
|
+
/** is this job's schedule signed with its job and still off? (the Audit and Job tab read it) @param {string} job */
|
|
721
|
+
isWaiting(job) { return SLUG_RE.test(job) && stateOf(job).waiting; },
|
|
566
722
|
userHome,
|
|
567
723
|
|
|
568
724
|
/**
|
|
@@ -579,25 +735,27 @@ export function createScheduleDoor(deps) {
|
|
|
579
735
|
const g = cachedGreen(job);
|
|
580
736
|
return { scheduled: false, canSchedule: g.ok, words: SCHEDULE_WORDS, ...(g.ok ? { fromRunid: g.run.runid } : {}) };
|
|
581
737
|
}
|
|
582
|
-
|
|
583
|
-
|
|
738
|
+
// R7: signed with the job and still off - the grey line says so, whatever else is true of a schedule that has not started
|
|
739
|
+
const next = st.waiting ? { text: SCHEDULE_WORDS.waiting, red: false } : scheduledNextFor({
|
|
740
|
+
trigger: st.schedule.trigger, armed: st.armed, nextSlotMs: st.nextSlotMs, lastOutcome: st.lastOutcome, waitingRunNo: o.waitingRunNo ?? null, now: now(), retryInMs: st.retryInMs, gaveUp: st.gaveUp, lookProblem: st.lookProblem,
|
|
584
741
|
});
|
|
585
742
|
const last = lastFireRow(job, st.schedule);
|
|
586
|
-
const nextWords = !st.armed ? 'next: not armed yet' : isClockTrigger(st.schedule.trigger)
|
|
743
|
+
const nextWords = st.waiting ? SCHEDULE_WORDS.waiting : !st.armed ? 'next: not armed yet' : isClockTrigger(st.schedule.trigger)
|
|
587
744
|
? (st.nextSlotMs === null ? 'next: not armed yet' : `next ${nextSlotShort(st.nextSlotMs)}`)
|
|
588
|
-
: (st.schedule.trigger.kind === 'new-file' ? 'next: waiting for a new file' : 'next: waiting for the file to change');
|
|
745
|
+
: (st.schedule.trigger.kind === 'new-ticket' ? 'next: waiting for a new ticket' : st.schedule.trigger.kind === 'new-file' ? 'next: waiting for a new file' : 'next: waiting for the file to change');
|
|
589
746
|
// hamr 2026-10-15: only a refusal that is not retrying, the give-up and a used-up month are problems (red); busy and an install back-off are not
|
|
590
747
|
let problem = false;
|
|
591
748
|
let ended = nextWords;
|
|
592
749
|
if (st.gaveUp !== null) { problem = true; ended = SCHEDULE_WORDS.problemNext; }
|
|
593
750
|
else if (last !== null && last.kind === 'monthly-exhausted' && sameMonthAs(last.at, now())) { problem = true; ended = SCHEDULE_WORDS.monthNext; }
|
|
751
|
+
else if (st.lookProblem !== null && !st.waiting) { problem = true; ended = `last look ${dateTimeWords(st.lookProblem.at)} · ${lookProblemWords(st.lookProblem)}`; }
|
|
594
752
|
else if (last !== null && last.kind === 'refused') {
|
|
595
753
|
if (typeof st.retryInMs === 'number') ended = retryNextWords(st.retryInMs);
|
|
596
754
|
else { problem = true; ended = SCHEDULE_WORDS.problemNext; }
|
|
597
755
|
}
|
|
598
756
|
return {
|
|
599
757
|
scheduled: true, canSchedule: false, words: SCHEDULE_WORDS, fromRunid: st.schedule.originRunid,
|
|
600
|
-
text: scheduledWords(st.schedule.trigger, userHome), next: next.text, nextRed: next.red,
|
|
758
|
+
text: scheduledWords(st.schedule.trigger, userHome), next: next.text, nextRed: next.red, waiting: st.waiting,
|
|
601
759
|
// aligned with fwdloop M9 am7: the SCHEDULE row's second line is put together by the server from these
|
|
602
760
|
lastRow: last, problem, nextWords: ended, accept: o.waitingRunNo !== undefined && o.waitingRunNo !== null,
|
|
603
761
|
};
|
|
@@ -613,9 +771,12 @@ export function createScheduleDoor(deps) {
|
|
|
613
771
|
const st = stateOf(job);
|
|
614
772
|
const green = st.schedule ? null : cachedGreen(job);
|
|
615
773
|
const t = st.schedule ? st.schedule.trigger : null;
|
|
774
|
+
// the Inputs lines a new-ticket schedule could watch (a Tickets MCP job with list_issues signed); [] = the card does not offer the choice
|
|
775
|
+
const specNow = st.schedule ? st.schedule.spec : (green && green.ok ? green.run.spec : null);
|
|
616
776
|
return {
|
|
617
|
-
scheduled: st.schedule !== null, trigger: t, now: t ? scheduledWords(t, userHome) : null,
|
|
777
|
+
scheduled: st.schedule !== null, trigger: t, now: t ? [scheduledWords(t, userHome), st.waiting ? SCHEDULE_WORDS.waiting : null].filter(Boolean).join(' · ') : null,
|
|
618
778
|
refusal: green && !green.ok ? green.say : null,
|
|
779
|
+
ticketInputs: ticketInputLabels(specNow),
|
|
619
780
|
words: SCHEDULE_WORDS,
|
|
620
781
|
};
|
|
621
782
|
},
|
|
@@ -19,6 +19,7 @@ import { recheck } from '../triggerfiles.js';
|
|
|
19
19
|
import { scheduledWords } from '../schedulewords.js';
|
|
20
20
|
import { signRun } from './authorroutes.js';
|
|
21
21
|
import { startDestinationProblem } from './authorsession.js';
|
|
22
|
+
import { removePrRef } from '../worktree.js';
|
|
22
23
|
|
|
23
24
|
/** how long a headless session may take to reach `prepared` (copy, install, signing gates) */
|
|
24
25
|
export const PREPARE_TIMEOUT_MS = 20 * 60_000;
|
|
@@ -39,7 +40,8 @@ function destinationOf(schedule, spec, fallback) {
|
|
|
39
40
|
* field must be deep-equal and the workflow key unchanged (F.4): the person signed the SCHEDULE, each fire's hash is
|
|
40
41
|
* derived by code. A clock fire's spec equals the signed spec byte for byte (same hash).
|
|
41
42
|
* @param {{spec: any, specHash: string, workflowKey: string}} schedule
|
|
42
|
-
*
|
|
43
|
+
* A TICKET fire leaves the spec UNCHANGED (hash equal, like a clock fire): the ticket number is per run, never signed, and rides on argv (`--ticket N`).
|
|
44
|
+
* @param {{kind: 'clock'}|{kind: 'file', path: string}|{kind: 'ticket'}} cause
|
|
43
45
|
* @returns {{ok: true, spec: any, hash: string}|{ok: false, why: string}}
|
|
44
46
|
*/
|
|
45
47
|
export function perFireSpec(schedule, cause) {
|
|
@@ -81,6 +83,11 @@ export function createStarter(deps) {
|
|
|
81
83
|
/** Remove what a start that did not go through made: the session leaves the headless map and its folder is deleted. @param {any} session */
|
|
82
84
|
function discard(session) {
|
|
83
85
|
try { deps.forgetSession?.(session.state.id); } catch { /* the map entry is gone or never was */ }
|
|
86
|
+
// a refused PR job's private ref (piece 12 item 13) goes with it: the child that checked the PR out recorded it in this folder's source.json
|
|
87
|
+
try {
|
|
88
|
+
const m = JSON.parse(readFileSync(join(session.state.outDir, 'source.json'), 'utf8'));
|
|
89
|
+
if (typeof m.repo === 'string' && Number.isSafeInteger(m.prNumber)) removePrRef(m.repo, m.prNumber);
|
|
90
|
+
} catch { /* no source.json, or no PR job: nothing to clean */ }
|
|
84
91
|
try { if (typeof session.state.outDir === 'string' && session.state.outDir !== '') rmSync(session.state.outDir, { recursive: true, force: true }); } catch { /* already gone */ }
|
|
85
92
|
}
|
|
86
93
|
|
|
@@ -103,23 +110,40 @@ export function createStarter(deps) {
|
|
|
103
110
|
|
|
104
111
|
/** @param {any} schedule @param {any} cause @returns {{ok: true, spec: any, hash: string}|{ok: false, why: string}} */
|
|
105
112
|
function resolveFire(schedule, cause) {
|
|
106
|
-
return perFireSpec(schedule, cause.kind === 'file' ? { kind: 'file', path: cause.path } : { kind: 'clock' });
|
|
113
|
+
return perFireSpec(schedule, cause.kind === 'file' ? { kind: 'file', path: cause.path } : cause.kind === 'ticket' ? { kind: 'ticket' } : { kind: 'clock' });
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* The schedule a start runs from: the job's signed schedule, or - for a by-hand "Run it anyway" with no ticket schedule at all (`cause.fromRun`, am3) - a stand-in built from the
|
|
118
|
+
* skipped run's own saved signed job through the one `startFrom`. `null` = nothing to run from.
|
|
119
|
+
* @param {string} job @param {any} cause @returns {any}
|
|
120
|
+
*/
|
|
121
|
+
function scheduleOf(job, cause) {
|
|
122
|
+
if (cause.kind !== 'ticket' || typeof cause.fromRun !== 'string') return deps.door.readSchedule(job);
|
|
123
|
+
const pre = deps.startFrom(cause.fromRun);
|
|
124
|
+
if (!pre || !pre.ok) return null;
|
|
125
|
+
const spec = pre.spec;
|
|
126
|
+
return {
|
|
127
|
+
spec, specHash: jobSpecHash(spec), workflowKey: workflowKey(spec), originRunid: cause.fromRun, trigger: { kind: 'new-ticket', input: '' }, destination: pre.card.destination,
|
|
128
|
+
inputsText: typeof pre.card.inputs === 'string' && pre.card.inputs !== '' ? pre.card.inputs : (spec.inputs ?? []).map((/** @type {any} */ i) => `${i.label}: ${i.value}`).join('\n'),
|
|
129
|
+
};
|
|
107
130
|
}
|
|
108
131
|
|
|
109
132
|
return {
|
|
110
133
|
/**
|
|
111
134
|
* Cheap, $0, no copy, no session. `{ok: true}` or `{ok: false, why}` (words).
|
|
112
135
|
* @param {string} job
|
|
113
|
-
* @param {{kind: 'clock'} | {kind: 'file', path: string, sha: string}} cause
|
|
136
|
+
* @param {{kind: 'clock'} | {kind: 'file', path: string, sha: string} | {kind: 'ticket', number: number, sha: string, byHand?: boolean, anyway?: boolean, fromRun?: string}} cause `byHand` (R7, am3) = "Run it anyway" while the schedule is still off: no good run exists yet to read the saved job from
|
|
114
137
|
* @returns {{ok: true}|{ok: false, why: string}}
|
|
115
138
|
*/
|
|
116
139
|
wouldAccept(job, cause) {
|
|
117
|
-
const schedule =
|
|
140
|
+
const schedule = scheduleOf(job, cause);
|
|
118
141
|
if (!schedule) return { ok: false, why: 'This job has no schedule any more. Nothing started.' };
|
|
119
142
|
const fire = resolveFire(schedule, cause);
|
|
120
143
|
if (!fire.ok) return fire;
|
|
121
|
-
// the origin run's saved job is still readable (the start reads it)
|
|
122
|
-
const
|
|
144
|
+
// the origin run's saved job is still readable (the start reads it). A by-hand start (R7, am3) runs the signed schedule's own spec: there is no good run yet
|
|
145
|
+
const byHand = cause.kind === 'ticket' && cause.byHand === true;
|
|
146
|
+
const pre = byHand ? { ok: true, card: { destination: '' } } : deps.startFrom(schedule.originRunid);
|
|
123
147
|
if (!pre || !pre.ok) return { ok: false, why: "The good run this schedule was made from is gone from the list, so its saved job cannot be read. Nothing started." };
|
|
124
148
|
// THE session start's Destination check (authorsession.js), on the card the start would build: before any session exists
|
|
125
149
|
const inputsText = cause.kind === 'file'
|
|
@@ -134,7 +158,7 @@ export function createStarter(deps) {
|
|
|
134
158
|
const r = recheck({ path: cause.path, sha: cause.sha });
|
|
135
159
|
if (r.state === 'deleted') return { ok: false, why: `The file ${cause.path} is not there (${r.say}). Nothing started.` };
|
|
136
160
|
if (r.state === 'changed') return { ok: false, why: `The file ${cause.path} changed before its turn. Nothing started.` };
|
|
137
|
-
} else {
|
|
161
|
+
} else if (cause.kind === 'clock') {
|
|
138
162
|
for (const inp of fire.spec.inputs ?? []) {
|
|
139
163
|
const v = String(inp.value);
|
|
140
164
|
if (/^https?:\/\//i.test(v)) continue;
|
|
@@ -155,18 +179,21 @@ export function createStarter(deps) {
|
|
|
155
179
|
/**
|
|
156
180
|
* Start the run. Never throws. `consumed` says whether `beforeSpawn` ran, so the caller knows whether a `released` row is owed.
|
|
157
181
|
* @param {string} job
|
|
158
|
-
* @param {{kind: 'clock', slot: number, catchUp: boolean, missed: number} | {kind: 'file', path: string, sha: string}} cause
|
|
182
|
+
* @param {{kind: 'clock', slot: number, catchUp: boolean, missed: number} | {kind: 'file', path: string, sha: string} | {kind: 'ticket', number: number, sha: string, byHand?: boolean, anyway?: boolean, fromRun?: string}} cause
|
|
183
|
+
* `byHand` (R7, am3): the person's own "Run it anyway" while the schedule is still off - the same path as Sign & run (no review door, no `trigger.json`, `--anyway`), the job's normal cap, no ledger row
|
|
159
184
|
* @param {{beforeSpawn?: () => void}} [hooks]
|
|
160
185
|
* @returns {Promise<{ok: true, sessionId: string, specHash: string, consumed: true}|{ok: false, why: string, consumed: boolean, installNeeded?: true}>}
|
|
161
186
|
*/
|
|
162
187
|
async start(job, cause, hooks = {}) {
|
|
163
188
|
let consumed = false;
|
|
164
189
|
try {
|
|
165
|
-
const schedule =
|
|
190
|
+
const schedule = scheduleOf(job, cause);
|
|
166
191
|
if (!schedule) return { ok: false, why: 'This job has no schedule any more. Nothing started.', consumed };
|
|
167
192
|
const fire = resolveFire(schedule, cause);
|
|
168
193
|
if (!fire.ok) return { ok: false, why: fire.why, consumed };
|
|
169
|
-
const
|
|
194
|
+
const byHand = cause.kind === 'ticket' && cause.byHand === true;
|
|
195
|
+
// a by-hand start (R7, am3) has no good run to read the saved job from yet: the card is made from the signed spec itself
|
|
196
|
+
const pre = byHand ? { ok: true, card: { jobName: String(fire.spec.job), checkType: fire.spec.verdictType === 'soft-green' ? 'rubric' : 'deterministic', thinking: fire.spec.thinking === true, jobText: '', destination: '' } } : deps.startFrom(schedule.originRunid);
|
|
170
197
|
if (!pre || !pre.ok) return { ok: false, why: "The good run this schedule was made from is gone from the list, so its saved job cannot be read. Nothing started.", consumed };
|
|
171
198
|
const spec = fire.spec;
|
|
172
199
|
const rows = deps.rowsFor();
|
|
@@ -179,6 +206,8 @@ export function createStarter(deps) {
|
|
|
179
206
|
inputs: inputsText,
|
|
180
207
|
destination: destinationOf(schedule, spec, pre.card.destination),
|
|
181
208
|
capUsd: spec.budgetUsd,
|
|
209
|
+
// a ticket fire: the number rides on the card exactly as the person's typed Ticket box does, and `signRun` turns it into `--ticket N`; a queued Run it anyway (an `arrived` row with `anyway: true`, R8) adds `--anyway` below
|
|
210
|
+
...(cause.kind === 'ticket' ? { ticket: String(cause.number) } : {}),
|
|
182
211
|
...(typeof spec.maxWallMs === 'number' ? { maxWallMs: spec.maxWallMs } : { maxWallMs: undefined }),
|
|
183
212
|
model: spec.model,
|
|
184
213
|
...(row ? { provider: row.envName } : {}),
|
|
@@ -211,9 +240,11 @@ export function createStarter(deps) {
|
|
|
211
240
|
const outDir = session.state.outDir;
|
|
212
241
|
const words = scheduledWords(schedule.trigger, deps.door.userHome) ?? '';
|
|
213
242
|
const catchUp = cause.kind === 'clock' && cause.catchUp === true;
|
|
214
|
-
|
|
243
|
+
// a by-hand start is not the schedule's: it writes no `trigger.json` (so the run reads "By hand"), opens no review door and says `--anyway` like the person's own Run it anyway
|
|
244
|
+
if (!byHand) writeFileSync(join(outDir, 'trigger.json'), `${JSON.stringify({
|
|
215
245
|
kind: cause.kind, trigger: words, reason: `Started by the schedule: ${words}${catchUp ? ' (catch-up)' : ''}`, catchUp,
|
|
216
|
-
...(cause.kind === 'clock' ? { slot: cause.slot, missed: cause.missed, lateMs: Math.max(0, now() - cause.slot) }
|
|
246
|
+
...(cause.kind === 'clock' ? { slot: cause.slot, missed: cause.missed, lateMs: Math.max(0, now() - cause.slot) }
|
|
247
|
+
: cause.kind === 'ticket' ? { ticket: cause.number, sha: cause.sha } : { file: cause.path, sha: cause.sha }),
|
|
217
248
|
// RULED 2026-10-15: what the Job tab and Audit say about a scheduled start (older records lack these; the words fall back)
|
|
218
249
|
triggerKind: schedule.trigger.kind, sessionId: session.state.id, originRunid: schedule.originRunid, sig: schedule.specHash, startedAt: now(),
|
|
219
250
|
}, null, 2)}\n`, { flag: 'wx', mode: 0o600 });
|
|
@@ -224,7 +255,7 @@ export function createStarter(deps) {
|
|
|
224
255
|
const spawnedAt = Date.now();
|
|
225
256
|
const signed = signRun(session, session.state.specHash, {
|
|
226
257
|
env: deps.envNow(), spawnFn: /** @type {any} */ (deps.spawnFn), bareloopBin: deps.bareloopBin, sessionsRoot: deps.sessionsRoot, home: deps.home,
|
|
227
|
-
reviewDoor: true, onSpawnError: (e) => { spawnError = e; }, onExit: (code) => { exitCode = typeof code === 'number' ? code : 1; },
|
|
258
|
+
reviewDoor: !byHand, ...(byHand || (cause.kind === 'ticket' && cause.anyway === true) ? { anyway: true } : {}), onSpawnError: (e) => { spawnError = e; }, onExit: (code) => { exitCode = typeof code === 'number' ? code : 1; },
|
|
228
259
|
});
|
|
229
260
|
// a spawn failure is reported on the next turn of the event loop; give it that turn before calling this started
|
|
230
261
|
await new Promise((r) => { setImmediate(r); });
|