fwdloop 0.26.2 → 0.27.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/bin/fwdloop +23 -3
- package/package.json +1 -1
- package/src/authoring.js +10 -0
- package/src/canrun.js +20 -0
- package/src/declaration.js +98 -2
- package/src/drafter.js +23 -10
- package/src/learnstore.js +1 -1
- package/src/panel/author.js +18 -2
- package/src/panel/authorflows.js +9 -4
- package/src/panel/authorstart.js +10 -6
- package/src/panel/authortrigger.js +34 -10
- package/src/panel/data.js +39 -4
- package/src/panel/index.html +516 -60
- package/src/panel/scheduler.js +42 -6
- package/src/panel/server.js +21 -5
- package/src/panel/tickets.js +113 -0
- package/src/runner.js +51 -10
- package/src/schedule.js +5 -0
- package/src/summary-words.js +12 -4
- package/src/ticket-draft.js +87 -0
- package/src/ticket-labels.js +65 -0
- package/src/ticket-mcp.js +66 -0
- package/src/ticket-shape.js +24 -0
- package/src/trigger-files.js +1 -1
- package/src/trigger-line.js +2 -1
- package/src/trigger-tickets.js +209 -0
- package/types/canrun.d.ts +14 -0
- package/types/drafter.d.ts +186 -64
- package/types/panel/author.d.ts +8 -0
- package/types/panel/authorflows.d.ts +2 -0
- package/types/panel/authorstart.d.ts +3 -1
- package/types/panel/authortrigger.d.ts +11 -1
- package/types/panel/data.d.ts +22 -3
- package/types/panel/scheduler.d.ts +7 -2
- package/types/panel/server.d.ts +9 -2
- package/types/panel/tickets.d.ts +81 -0
- package/types/runner.d.ts +21 -3
- package/types/summary-words.d.ts +2 -1
- package/types/ticket-draft.d.ts +96 -0
- package/types/ticket-labels.d.ts +36 -0
- package/types/ticket-mcp.d.ts +40 -0
- package/types/ticket-shape.d.ts +25 -0
- package/types/trigger-files.d.ts +2 -0
- package/types/trigger-line.d.ts +7 -0
- package/types/trigger-tickets.d.ts +91 -0
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
import { scheduleHead, scheduledWords } from '../summary-words.js';
|
|
33
33
|
import { armTrigger, nextSlot, readRows, validateSchedule } from '../trigger-clock.js';
|
|
34
34
|
import { checkTarget, createFileTrigger } from '../trigger-files.js';
|
|
35
|
+
import { WATCHABLE, ticketListsOf } from '../ticket-shape.js';
|
|
35
36
|
import { readModelRecord } from '../flowmodel.js';
|
|
36
37
|
import { pageAddressesOf, pageAddressRefusal } from '../pagefetch.js';
|
|
37
38
|
import {
|
|
@@ -45,6 +46,8 @@ import { triggerHash, triggerLine } from '../trigger-line.js';
|
|
|
45
46
|
/** A trigger in the words a row and a run reason use: `daily 09:00`, `new-file jd = file:/home/you/inbox`. @param {Trigger} t */
|
|
46
47
|
const describe = (t) => triggerLine(t).replace('guardrail: trigger ', '');
|
|
47
48
|
|
|
49
|
+
/** M12: the one tool a ticket schedule's look uses, signed with the schedule's two clicks. */
|
|
50
|
+
export const TICKET_LOOK_TOOL = 'list_issues';
|
|
48
51
|
export const NO_GREEN_SAY = 'This job has not had a good run yet. Run it once by hand and get it right first; then you can set when it runs. Nothing was changed.';
|
|
49
52
|
const HISTORY_FILE = 'triggers.jsonl';
|
|
50
53
|
|
|
@@ -129,6 +132,14 @@ function shapeOf(t, roles) {
|
|
|
129
132
|
if (typeof p !== 'string' || p === '' || !isAbsolute(p) || /[\x00-\x1f\x7f]/.test(p)) return { ok: false, say: `The ${where} must be a full path on one line, like /home/you/inbox. Nothing was changed.` };
|
|
130
133
|
return { ok: true, trigger: /** @type {Trigger} */ (o.kind === 'new-file' ? { kind: 'new-file', role: o.role, folder: p } : { kind: 'file-updated', role: o.role, path: p }) };
|
|
131
134
|
}
|
|
135
|
+
if (o.kind === 'new-ticket') {
|
|
136
|
+
// M12 piece 2: the person picks the input; the list address, the job's server and the look's tool are filled from the signed job (inspect), never typed here
|
|
137
|
+
const extra = Object.keys(o).filter((k) => !['kind', 'role', 'watch'].includes(k));
|
|
138
|
+
if (extra.length > 0) return { ok: false, say: `A "new-ticket" trigger takes a kind and a role, not "${extra[0]}". Nothing was changed.` };
|
|
139
|
+
if (typeof o.role !== 'string' || !roles.includes(o.role)) return { ok: false, say: `This job has no input named "${String(o.role)}" (it takes: ${roles.join(', ') || 'none'}). Pick one of those. Nothing was changed.` };
|
|
140
|
+
if (o.watch !== undefined && !(Array.isArray(o.watch) && o.watch.every((w) => WATCHABLE.includes(w)))) return { ok: false, say: `A ticket schedule can watch only ${WATCHABLE.join(' and ')}. Nothing was changed.` };
|
|
141
|
+
return { ok: true, trigger: /** @type {Trigger} */ ({ kind: 'new-ticket', role: o.role, list: '', server: '', tool: '', ...(o.watch ? { watch: o.watch } : {}) }) };
|
|
142
|
+
}
|
|
132
143
|
try { return { ok: true, trigger: validateSchedule(t) }; } catch (e) { return { ok: false, say: `${/** @type {Error} */ (e).message}. Nothing was changed.` }; }
|
|
133
144
|
}
|
|
134
145
|
|
|
@@ -165,23 +176,35 @@ export function createTriggerDoor(opts) {
|
|
|
165
176
|
const roles = (read.arbiter.sources ?? []).map((s) => s.role);
|
|
166
177
|
const shaped = shapeOf(body?.trigger === undefined ? 'missing' : body.trigger, roles);
|
|
167
178
|
if (!shaped.ok) return reply(400, { refused: 'bad-trigger', say: shaped.say });
|
|
168
|
-
|
|
179
|
+
let { trigger } = shaped;
|
|
180
|
+
if (trigger !== null && trigger.kind === 'new-ticket') {
|
|
181
|
+
// M12 piece 2 (items 8; PRD ruling "a tool counts as used if a step or the signed schedule uses it"): the look's tool is `list_issues` on the server the job names
|
|
182
|
+
const list = ticketListsOf(read.arbiter)[trigger.role];
|
|
183
|
+
if (list === undefined) return reply(400, { refused: 'bad-trigger', say: `The input "${trigger.role}" is not a ticket list (a GitHub issues list address), so no new ticket can start a run from it. Nothing was changed.` });
|
|
184
|
+
const server = read.declaration?.mcp?.server;
|
|
185
|
+
if (typeof server !== 'string') return reply(400, { refused: 'bad-trigger', say: 'This job names no MCP server, so the ticket list cannot be looked at. Nothing was changed.' });
|
|
186
|
+
// signed M12 item 7: the fields to watch come from the signed job (`ticketWatch`) unless the click itself names them; a job that names none watches nothing
|
|
187
|
+
const jobWatch = read.declaration?.ticketWatch;
|
|
188
|
+
const watch = trigger.watch ?? (Array.isArray(jobWatch) && jobWatch.length > 0 ? jobWatch : undefined);
|
|
189
|
+
trigger = { kind: trigger.kind, role: trigger.role, list, server, tool: TICKET_LOOK_TOOL, ...(watch ? { watch } : {}) };
|
|
190
|
+
}
|
|
169
191
|
const flowDir = join(realRoot, flow);
|
|
170
192
|
if (trigger !== null && !hasGreenRunForJob(flowDir)) return reply(409, { refused: 'no-green-run', say: NO_GREEN_SAY });
|
|
171
193
|
// M9 am20 item 3: neither Cancel nor a new schedule is refused because a run is starting, working or waiting: a run carries on from its own copy and
|
|
172
194
|
// keeps its own signed values; the next fire uses the new schedule. (A schedule never touches the job, so there is nothing for a run to collide with.)
|
|
173
|
-
|
|
174
|
-
|
|
195
|
+
const fileTrigger = trigger !== null && (trigger.kind === 'file-updated' || trigger.kind === 'new-file') ? trigger : null;
|
|
196
|
+
if (fileTrigger !== null && Object.hasOwn(pageAddressesOf(read.arbiter), fileTrigger.role)) {
|
|
197
|
+
return reply(400, { refused: 'bad-trigger', say: `The input "${fileTrigger.role}" is a web page, not a file, so no file arrival can start a run from it. Nothing was changed.` }); // M10 am3
|
|
175
198
|
}
|
|
176
|
-
if (
|
|
199
|
+
if (fileTrigger !== null) {
|
|
177
200
|
try {
|
|
178
|
-
checkTarget(
|
|
201
|
+
checkTarget(fileTrigger.kind === 'new-file' ? 'new' : 'updated', fileTrigger.kind === 'new-file' ? fileTrigger.folder : fileTrigger.path);
|
|
179
202
|
} catch (e) {
|
|
180
203
|
return reply(400, { refused: 'bad-trigger', say: `${/** @type {Error} */ (e).message}. Nothing was changed.` });
|
|
181
204
|
}
|
|
182
205
|
// a file that does not exist yet may arrive (checkTarget allows it), but its folder must be there: a typo is caught now, not never
|
|
183
|
-
if (
|
|
184
|
-
try { realpathSync(dirname(
|
|
206
|
+
if (fileTrigger.kind === 'file-updated') {
|
|
207
|
+
try { realpathSync(dirname(fileTrigger.path)); } catch { return reply(400, { refused: 'bad-trigger', say: `The folder of ${fileTrigger.path} does not exist. Nothing was changed.` }); }
|
|
185
208
|
}
|
|
186
209
|
}
|
|
187
210
|
// M6 am5 item 3: a schedule may carry the model of the run it was made from (a run field). Checked now by the Run door's own model check; the same as
|
|
@@ -367,7 +390,7 @@ export function createTriggerDoor(opts) {
|
|
|
367
390
|
* are missing) -> started through the ONE start path (kind `trigger`; the reason and the catch-up mark go into the run's own folder first).
|
|
368
391
|
* The fire / ran ledger row was written by the caller BEFORE this, so a crash loses a run and never doubles one.
|
|
369
392
|
* @param {{flow: string, flowDir: string, read: any, trigger: Trigger, schedule: Schedule}} job
|
|
370
|
-
* @param {{kind: 'clock', slot: number, catchUp: boolean, missed: number} | {kind: 'file', path: string, sha: string}} cause
|
|
393
|
+
* @param {{kind: 'clock', slot: number, catchUp: boolean, missed: number} | {kind: 'file', path: string, sha: string} | {kind: 'ticket', number: number, sha: string, role: string, list: string, why?: string, anyway?: boolean}} cause
|
|
371
394
|
* @param {{ told?: (row: Record<string, any>) => boolean, beforeStart?: () => void, holdIfCannotStart?: boolean }} [hooks] M9 am3 (a queued file): `told(row)` true = this file
|
|
372
395
|
* already has a row for that outcome and reason (`why`), so none is written again (the outcome is still returned); `beforeStart` runs right before the ONE
|
|
373
396
|
* start, once every check has passed: the scheduler writes the file's `ran` row there. `holdIfCannotStart` (a queued file, M9 am17): the starter's `canStart` is asked first, and a no writes nothing
|
|
@@ -381,7 +404,7 @@ export function createTriggerDoor(opts) {
|
|
|
381
404
|
const desc = describe(trigger);
|
|
382
405
|
const base = {
|
|
383
406
|
at: new Date(now()).toISOString(), flow, trigger: desc, sig: schedule.sig,
|
|
384
|
-
...(cause.kind === 'clock' ? { slot: new Date(cause.slot).toISOString(), catchUp: cause.catchUp, missed: cause.missed } : { file: cause.path, sha: cause.sha, catchUp: false }),
|
|
407
|
+
...(cause.kind === 'clock' ? { slot: new Date(cause.slot).toISOString(), catchUp: cause.catchUp, missed: cause.missed } : cause.kind === 'ticket' ? { ticket: cause.number, sha: cause.sha, catchUp: false } : { file: cause.path, sha: cause.sha, catchUp: false }),
|
|
385
408
|
};
|
|
386
409
|
const done = (/** @type {Record<string, any>} */ r) => { const row = /** @type {Record<string, any>} */ ({ ...base, ...r }); if (!(row.outcome !== 'started' && hooks.told?.(row))) appendOutcome(flowDir, row); return row; };
|
|
387
410
|
const busy = flowsDoor.scheduleBusy(flow); // M9 am8: one WORKING run at a time per job; a run waiting at its ask does not block
|
|
@@ -412,6 +435,7 @@ export function createTriggerDoor(opts) {
|
|
|
412
435
|
const sources = [];
|
|
413
436
|
const pages = pageAddressesOf(read.arbiter);
|
|
414
437
|
for (const role of roles) {
|
|
438
|
+
if (cause.kind === 'ticket' && cause.role === role) { sources.push({ role, path: pages[role], ticket: cause.number, ...(cause.anyway === true ? { anyway: true } : {}) }); continue; } // M12: this run's input is ONE ticket of the signed list
|
|
415
439
|
if (Object.hasOwn(pages, role)) { sources.push({ role, path: pages[role] }); continue; } // M10 am3: a page input is its signed address, never an earlier run's or an arriving file
|
|
416
440
|
const p = 'role' in trigger && trigger.role === role && cause.kind === 'file' ? cause.path : last[role];
|
|
417
441
|
if (!p) return done({ outcome: 'refused', why: `There is no earlier run of this job to take the input "${role}" from. Run it by hand once with that input. Nothing started.` });
|
|
@@ -439,7 +463,7 @@ export function createTriggerDoor(opts) {
|
|
|
439
463
|
if (modelSays.length > 0) return done({ outcome: 'refused', why: modelSays[0].say.replace(/ Nothing was spent\.$/, '. Nothing started.') });
|
|
440
464
|
const catchUp = base.catchUp === true;
|
|
441
465
|
const record = {
|
|
442
|
-
kind: cause.kind, trigger: desc, reason: `Started by the trigger: ${desc}${catchUp ? ' (catch-up)' : ''}`, catchUp, ...(cause.kind === 'clock' ? { slot: new Date(cause.slot).toISOString(), missed: cause.missed } : { file: cause.path, sha: cause.sha }),
|
|
466
|
+
kind: cause.kind, trigger: desc, reason: `Started by the trigger: ${desc}${catchUp ? ' (catch-up)' : ''}`, catchUp, ...(cause.kind === 'clock' ? { slot: new Date(cause.slot).toISOString(), missed: cause.missed } : cause.kind === 'ticket' ? { ticket: cause.number, sha: cause.sha, ...(cause.why ? { why: cause.why } : {}) } : { file: cause.path, sha: cause.sha }),
|
|
443
467
|
// M9 am6: typed facts for the run's Job tab and Audit (their words are built from these, in src/summary-words.js, never here)
|
|
444
468
|
triggerKind: trigger.kind, words: scheduleHead(trigger), at: base.at, ...(cause.kind === 'clock' ? { lateMin: Math.max(0, Math.round((now() - cause.slot) / 60_000)) } : {}),
|
|
445
469
|
sig: schedule.sig, ...(schedule.from ? { fromRun: schedule.from } : {}),
|
package/src/panel/data.js
CHANGED
|
@@ -47,6 +47,7 @@ import {
|
|
|
47
47
|
} from '../summary-words.js';
|
|
48
48
|
import { MAX_STRUCTURE_RETRIES } from '../drafter.js';
|
|
49
49
|
import { isResultRun, checkTypeOf, buildResult, downloadOf, readCitedChecks } from './result.js';
|
|
50
|
+
import { ticketListOf } from './tickets.js';
|
|
50
51
|
import { thinkingRuleWords, thinkingTryWords } from '../thinking.js';
|
|
51
52
|
import { readLearningsRecord } from '../flowmodel.js';
|
|
52
53
|
import { readRunThinking } from '../runfile.js';
|
|
@@ -243,7 +244,7 @@ export const CRASHED_LABEL = 'crashed after taking your answer — start a fresh
|
|
|
243
244
|
* @type {Record<string, string>}
|
|
244
245
|
*/
|
|
245
246
|
export const SIGN_WORDS = {
|
|
246
|
-
'[▶]': 'running', '[·]': 'waiting', '[II]': 'stuck', '[!]': 'expired', '[?]': 'crashed', '[✓]': 'passed', '[✗]': 'failed', '[■]': 'stopped',
|
|
247
|
+
'[▶]': 'running', '[·]': 'waiting', '[II]': 'stuck', '[!]': 'expired', '[?]': 'crashed', '[✓]': 'passed', '[✗]': 'failed', '[■]': 'stopped', '[–]': 'skipped',
|
|
247
248
|
};
|
|
248
249
|
|
|
249
250
|
/**
|
|
@@ -378,13 +379,15 @@ export function glyphPulses(g) {
|
|
|
378
379
|
* - `[?]` crashed after taking your answer (amendment 2 (f)) — the answer was
|
|
379
380
|
* consumed, the process is gone, no end row: cannot be carried on.
|
|
380
381
|
* @param {{historyRow: any, askJson: any, consumedAnswerExists: boolean, hasStateJson: boolean, resume?: any, liveness?: 'running'|'gone'|'unknown', booksFresh?: boolean, lock?: string, resumable?: boolean, stoppedAtAsk?: string|null, jobEdited?: boolean, starting?: boolean}} ctx
|
|
381
|
-
* @returns {{glyph: '[✓]'|'[✗]'|'[·]'|'[!]'|'[▶]'|'[?]'|'[II]'|'[■]', label: string}}
|
|
382
|
+
* @returns {{glyph: '[✓]'|'[✗]'|'[·]'|'[!]'|'[▶]'|'[?]'|'[II]'|'[■]'|'[–]', label: string}}
|
|
382
383
|
*/
|
|
383
384
|
export function computeGlyph({
|
|
384
385
|
historyRow, askJson, consumedAnswerExists, hasStateJson, resume, liveness, booksFresh, lock, resumable, stoppedAtAsk, jobEdited, starting,
|
|
385
386
|
}) {
|
|
386
387
|
if (historyRow) {
|
|
387
388
|
if (historyRow.outcome === 'complete') return { glyph: '[✓]', label: 'passed' };
|
|
389
|
+
// M12 piece 3 (item 9): a ticket the signed labels do not match, or a closed one: grey, never failed
|
|
390
|
+
if (historyRow.outcome === 'skipped') return { glyph: '[–]', label: typeof historyRow.skipReason === 'string' && historyRow.skipReason !== '' ? `skipped — ${historyRow.skipReason}` : 'skipped' };
|
|
388
391
|
// M6 amendment 4: a stopped (or cap-halted) run whose job was edited and signed since cannot be resumed; the words say so.
|
|
389
392
|
if (jobEdited === true && (historyRow.outcome === 'stopped' || historyRow.outcome === 'cap-halt')) return { glyph: '[■]', label: JOB_EDITED_LINE };
|
|
390
393
|
// M4e amendment 4 item 4: a run the human stopped, or one that hit its money cap and can be continued, is `[■]` stopped — never "failed".
|
|
@@ -1090,6 +1093,19 @@ export function getRunGlyph({
|
|
|
1090
1093
|
return computeGlyph(loadRunContext(root, run.flowDir, run.runDir, flow, runId, catalogue, null));
|
|
1091
1094
|
}
|
|
1092
1095
|
|
|
1096
|
+
/**
|
|
1097
|
+
* The time (ms) the run's history row was written, or null when it has none. @param {{root: string, flow: string, runId: string, catalogue: any}} opts
|
|
1098
|
+
*/
|
|
1099
|
+
function getRunEndedAt({
|
|
1100
|
+
root, flow, runId, catalogue,
|
|
1101
|
+
}) {
|
|
1102
|
+
const run = resolveRunPath(root, flow, runId);
|
|
1103
|
+
if (!run.ok) return null;
|
|
1104
|
+
const at = loadRunContext(root, run.flowDir, run.runDir, flow, runId, catalogue, null).historyRow?.at;
|
|
1105
|
+
const ms = typeof at === 'string' ? Date.parse(at) : NaN;
|
|
1106
|
+
return Number.isFinite(ms) ? ms : null;
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1093
1109
|
/**
|
|
1094
1110
|
* `GET /api/runs` — every flow under `root`, every run under each flow
|
|
1095
1111
|
* (M4a scope item 2). A flow with zero runs still gets one row (`runId:
|
|
@@ -1518,7 +1534,7 @@ function runSummary(ctx, glyph, { root, catalogue, triggerRead, now, home }) {
|
|
|
1518
1534
|
}
|
|
1519
1535
|
const send = ctx.arbiter && Array.isArray(ctx.arbiter.sends) ? ctx.arbiter.sends.find((x) => x.target && typeof x.target.path === 'string') : undefined;
|
|
1520
1536
|
const endedPlain = endedWords({
|
|
1521
|
-
outcome, died, line, destination: send ? send.target.path : null, canResume: ctx.resumable === true && ctx.sameJob === true, home,
|
|
1537
|
+
outcome, died, line, destination: send ? send.target.path : null, canResume: ctx.resumable === true && ctx.sameJob === true, home, skipReason: ctx.historyRow?.skipReason,
|
|
1522
1538
|
});
|
|
1523
1539
|
// M9 am7 item 1: ENDED opens with the run's local end date and time, then its outcome word, then today's reason (NEXT stays as it was)
|
|
1524
1540
|
const ended = endedPlain === null ? null : {
|
|
@@ -2222,13 +2238,32 @@ export function getRunResult({
|
|
|
2222
2238
|
const { run, ctx } = got;
|
|
2223
2239
|
const sig = ctx.flowRead.signature;
|
|
2224
2240
|
const plan = buildJobPlan(ctx.flowRead.declaration, ctx.arbiter.asks ?? [], run.flowDir, typeof sig?.flow === 'string' ? sig.flow : null, ctx.flowRead.lines, csvRolesOf(ctx.arbiter));
|
|
2225
|
-
|
|
2241
|
+
const result = buildResult({
|
|
2226
2242
|
flow, runId, runDir: run.runDir, root, flowRead: ctx.flowRead, arbiter: ctx.arbiter, historyRow: ctx.historyRow, auditRows: ctx.auditRows, logJson: ctx.logJson, notChecked: plan.notChecked.items, readNotes: plan.notChecked.readNotes,
|
|
2227
2243
|
setupRows: (() => { const st = readSetup(run.flowDir); return st.present ? st.rows : []; })(),
|
|
2228
2244
|
door: resultDoorOf(getRunAsks({
|
|
2229
2245
|
root, flow, runId, catalogue, resumeAttempt, now,
|
|
2230
2246
|
})),
|
|
2231
2247
|
});
|
|
2248
|
+
// M12 piece 3 (item 9): the run a ticket schedule was set from also carries the ticket list (null for every other run)
|
|
2249
|
+
const tickets = getTicketList({
|
|
2250
|
+
root, flow, runId, catalogue,
|
|
2251
|
+
});
|
|
2252
|
+
return tickets === null ? result : { ...result, tickets };
|
|
2253
|
+
}
|
|
2254
|
+
|
|
2255
|
+
/**
|
|
2256
|
+
* M12 piece 3: the ticket list of the run a ticket schedule was set from (the Result tab's, and `Run it anyway`'s check), or null.
|
|
2257
|
+
* @param {{root: string, flow: string, runId: string, catalogue: any}} a
|
|
2258
|
+
*/
|
|
2259
|
+
export function getTicketList({
|
|
2260
|
+
root, flow, runId, catalogue,
|
|
2261
|
+
}) {
|
|
2262
|
+
const run = resolveRunPath(root, flow, runId);
|
|
2263
|
+
if (!run.ok) return null;
|
|
2264
|
+
return ticketListOf({
|
|
2265
|
+
flowDir: run.flowDir, runId, runIdsOf: listRunIds, glyphOf: (id) => getRunGlyph({ root, flow, runId: id, catalogue }), atOf: (id) => getRunEndedAt({ root, flow, runId: id, catalogue }),
|
|
2266
|
+
});
|
|
2232
2267
|
}
|
|
2233
2268
|
|
|
2234
2269
|
/**
|