fwdloop 0.21.0 → 0.22.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 +85 -34
- package/package.json +4 -3
- package/src/audit-fold.js +5 -1
- package/src/authoring.js +32 -6
- package/src/checked.js +18 -1
- package/src/cited-record.js +138 -0
- package/src/cited-source.js +49 -0
- package/src/citedcheck.js +306 -0
- package/src/citedwords.js +197 -0
- package/src/closers.js +56 -7
- package/src/ctx-tools.js +2 -14
- package/src/declaration.js +85 -5
- package/src/diary.js +2 -2
- package/src/docx.js +16 -2
- package/src/draft-steps.js +1 -1
- package/src/drafter.js +292 -25
- package/src/flow.js +33 -7
- package/src/flowmodel.js +21 -0
- package/src/input-facts.js +20 -3
- package/src/model-step.js +30 -5
- package/src/pageask.js +136 -0
- package/src/pagebits.js +107 -0
- package/src/pagedropwords.js +171 -0
- package/src/pagedry.js +120 -0
- package/src/pagefetch.js +164 -0
- package/src/pagelook.js +155 -0
- package/src/pagemap.js +55 -0
- package/src/pageplace.js +103 -0
- package/src/pagerules.js +318 -0
- package/src/panel/author.js +41 -20
- package/src/panel/authorcard.js +11 -1
- package/src/panel/authorflows.js +21 -15
- package/src/panel/authorstart.js +2 -4
- package/src/panel/authortrigger.js +14 -4
- package/src/panel/data.js +83 -2
- package/src/panel/index.html +279 -12
- package/src/panel/result.js +295 -0
- package/src/panel/server.js +27 -3
- package/src/primitives.js +2 -3
- package/src/provider.js +5 -2
- package/src/redact.js +17 -0
- package/src/runner.js +83 -12
- package/src/schedule.js +3 -3
- package/src/setup.js +16 -1
- package/src/sheetfind.js +50 -0
- package/src/sheetlook.js +157 -0
- package/src/signed-text.js +11 -1
- package/src/thinking.js +1 -1
- package/src/try-checks.js +6 -0
- package/src/types.js +3 -2
- package/types/authoring.d.ts +19 -2
- package/types/checked.d.ts +10 -0
- package/types/cited-record.d.ts +21 -0
- package/types/cited-source.d.ts +18 -0
- package/types/citedcheck.d.ts +95 -0
- package/types/citedwords.d.ts +97 -0
- package/types/closers.d.ts +55 -3
- package/types/ctx-tools.d.ts +0 -1
- package/types/declaration.d.ts +15 -1
- package/types/docx.d.ts +14 -0
- package/types/drafter.d.ts +244 -2
- package/types/flow.d.ts +21 -0
- package/types/flowmodel.d.ts +15 -0
- package/types/input-facts.d.ts +12 -2
- package/types/model-step.d.ts +35 -3
- package/types/pageask.d.ts +75 -0
- package/types/pagebits.d.ts +32 -0
- package/types/pagedropwords.d.ts +40 -0
- package/types/pagedry.d.ts +38 -0
- package/types/pagefetch.d.ts +86 -0
- package/types/pagelook.d.ts +75 -0
- package/types/pagemap.d.ts +31 -0
- package/types/pageplace.d.ts +22 -0
- package/types/pagerules.d.ts +86 -0
- package/types/panel/authorcard.d.ts +2 -0
- package/types/panel/authorflows.d.ts +2 -0
- package/types/panel/data.d.ts +26 -0
- package/types/panel/result.d.ts +156 -0
- package/types/provider.d.ts +3 -1
- package/types/redact.d.ts +1 -0
- package/types/runner.d.ts +156 -7
- package/types/schedule.d.ts +0 -11
- package/types/setup.d.ts +13 -0
- package/types/sheetfind.d.ts +46 -0
- package/types/sheetlook.d.ts +120 -0
- package/types/thinking.d.ts +1 -1
- package/types/types.d.ts +11 -3
package/src/panel/authorstart.js
CHANGED
|
@@ -31,7 +31,7 @@ import { loadCatalogue } from '../catalogue.js';
|
|
|
31
31
|
import { scrub } from '../authoring.js';
|
|
32
32
|
import { readPidRows } from '../books.js';
|
|
33
33
|
import {
|
|
34
|
-
PANEL_STARTS_DIR, checkRunId, claimRunId,
|
|
34
|
+
PANEL_STARTS_DIR, checkRunId, claimRunId, freeRunId, readFileInside, readdirInside, resolveRunDir, runOwnsPlan, copyRunPlan, RUN_PLAN_MARKER,
|
|
35
35
|
} from '../flow.js';
|
|
36
36
|
import { booksFresh, runLiveness } from '../liveness.js';
|
|
37
37
|
import { dropUnstartedValues, writeRunValues } from '../runvalues.js';
|
|
@@ -146,10 +146,8 @@ export function createStarter(opts) {
|
|
|
146
146
|
if (!planRun) {
|
|
147
147
|
const flowDir = join(realpathSync(root), flow);
|
|
148
148
|
if (runId === '') {
|
|
149
|
-
const
|
|
150
|
-
const r = resolveRunDir(flowDir, next);
|
|
149
|
+
const r = freeRunId(flowDir); // the decider claimRunId uses: a stray file under a run name is skipped, not refused
|
|
151
150
|
if (!r.ok) return { status: 400, body: { ok: false, refused: 'run-id', say: `${r.red.replace(/^run: /, '')}.` } };
|
|
152
|
-
if (existsSync(r.runDir)) return { status: 400, body: { ok: false, refused: 'run-id', say: `There is already a run "${next}" of this flow. Use a new run id.` } };
|
|
153
151
|
} else {
|
|
154
152
|
const run = checkRun(flow, runId);
|
|
155
153
|
if (!run.ok) return { status: 400, body: { ok: false, refused: 'run-id', say: run.say } };
|
|
@@ -32,6 +32,7 @@ import { scheduleHead, scheduledWords } from '../summary-words.js';
|
|
|
32
32
|
import { armTrigger, nextSlot, readRows, validateSchedule } from '../trigger-clock.js';
|
|
33
33
|
import { checkTarget, createFileTrigger } from '../trigger-files.js';
|
|
34
34
|
import { readModelRecord } from '../flowmodel.js';
|
|
35
|
+
import { pageAddressesOf, pageAddressRefusal } from '../pagefetch.js';
|
|
35
36
|
import {
|
|
36
37
|
carryQueue, dropQueue, finishCarry, isArmed, ledgerOf, readSchedule, recordCancelled, removeSchedule, sameTarget, sigOf, writeSchedule,
|
|
37
38
|
} from '../schedule.js';
|
|
@@ -168,6 +169,9 @@ export function createTriggerDoor(opts) {
|
|
|
168
169
|
if (trigger !== null && !hasGreenRunForJob(flowDir)) return reply(409, { refused: 'no-green-run', say: NO_GREEN_SAY });
|
|
169
170
|
// 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
|
|
170
171
|
// 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.)
|
|
172
|
+
if (trigger !== null && 'role' in trigger && Object.hasOwn(pageAddressesOf(read.arbiter), trigger.role)) {
|
|
173
|
+
return reply(400, { refused: 'bad-trigger', say: `The input "${trigger.role}" is a web page, not a file, so no file arrival can start a run from it. Nothing was changed.` }); // M10 am3
|
|
174
|
+
}
|
|
171
175
|
if (trigger !== null && 'role' in trigger) {
|
|
172
176
|
try {
|
|
173
177
|
checkTarget(trigger.kind === 'new-file' ? 'new' : 'updated', trigger.kind === 'new-file' ? trigger.folder : trigger.path);
|
|
@@ -203,13 +207,16 @@ export function createTriggerDoor(opts) {
|
|
|
203
207
|
scheduledDestination = body.destination.trim();
|
|
204
208
|
}
|
|
205
209
|
if (Array.isArray(body?.inputs)) {
|
|
206
|
-
|
|
210
|
+
// M10 am3: a page input's address is the job's, signed: a blank row is the signed one, any other address is refused naming the input
|
|
211
|
+
const pages = pageAddressesOf(read.arbiter);
|
|
212
|
+
const rows = runInputRows(body.inputs).map((r) => (Object.hasOwn(pages, r.role) && r.path === '' ? { ...r, path: pages[r.role] } : r));
|
|
207
213
|
const declared = roles;
|
|
208
214
|
const bad = [...checkInputRows(rows)];
|
|
209
|
-
|
|
215
|
+
rows.forEach((r, n) => { if (Object.hasOwn(pages, r.role) && r.path !== pages[r.role]) bad.push({ field: `inputs.${n}`, say: pageAddressRefusal(r.role, pages[r.role]) }); });
|
|
216
|
+
for (const role of declared) if (!Object.hasOwn(pages, role) && !rows.some((r) => r.role === role)) bad.push({ field: 'inputs', say: `This flow needs an input named "${role}". Add it.` });
|
|
210
217
|
for (const r of rows) if (!declared.includes(r.role)) bad.push({ field: 'inputs', say: `This flow has no input named "${r.role}" (it takes: ${declared.join(', ') || 'none'}).` });
|
|
211
218
|
if (bad.length > 0) return reply(400, { refused: 'bad-inputs', say: `${bad[0].say} Nothing was changed.`, refusals: bad });
|
|
212
|
-
scheduledInputs = declared.map((role) => ({ role, path: /** @type {{path: string}} */ (rows.find((r) => r.role === role)).path }));
|
|
219
|
+
scheduledInputs = declared.map((role) => ({ role, path: Object.hasOwn(pages, role) ? pages[role] : /** @type {{path: string}} */ (rows.find((r) => r.role === role)).path }));
|
|
213
220
|
}
|
|
214
221
|
}
|
|
215
222
|
// M6 am9: the schedule uses the plan of the run it was set from. The workflow's own plan = nothing to bind; a different kept plan is verified now and
|
|
@@ -399,7 +406,9 @@ export function createTriggerDoor(opts) {
|
|
|
399
406
|
let last = flowsDoor.lastSourcesOf(flow, roles).sources;
|
|
400
407
|
if (schedule.inputs !== null) last = { ...last, ...Object.fromEntries(schedule.inputs.map((r) => [r.role, r.path])) };
|
|
401
408
|
const sources = [];
|
|
409
|
+
const pages = pageAddressesOf(read.arbiter);
|
|
402
410
|
for (const role of roles) {
|
|
411
|
+
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
|
|
403
412
|
const p = 'role' in trigger && trigger.role === role && cause.kind === 'file' ? cause.path : last[role];
|
|
404
413
|
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.` });
|
|
405
414
|
try { sources.push({ role, path: realpathSync(p) }); } catch { return done({ outcome: 'refused', why: `The input "${role}" is not there (${p}). Nothing started.` }); }
|
|
@@ -485,7 +494,8 @@ export function createTriggerDoor(opts) {
|
|
|
485
494
|
from: sc ? sc.from : null,
|
|
486
495
|
model: sc && sc.model ? sc.model.model : (rec ? rec.model : null),
|
|
487
496
|
destination: sc && sc.destination ? sc.destination : (read.ok ? flowValues(read.arbiter).destination : null),
|
|
488
|
-
|
|
497
|
+
// M10: a page input shows its FULL signed address (the page cuts it with an ellipsis, the whole on hover); a file shows its name
|
|
498
|
+
inputs: sources.map((p) => (Object.values(read.ok ? pageAddressesOf(read.arbiter) : {}).includes(String(p)) ? String(p) : basename(String(p)))),
|
|
489
499
|
fires: base.sig === null ? [] : readOutcomes(flowDir).filter((o) => o.sig === base.sig),
|
|
490
500
|
allFires: readOutcomes(flowDir), // M9 am9 item 4: the Audit's `tries` span every signing
|
|
491
501
|
};
|
package/src/panel/data.js
CHANGED
|
@@ -38,11 +38,12 @@ import {
|
|
|
38
38
|
import { readSpendRows } from '../provider.js';
|
|
39
39
|
import { applyRunValues, parseWaitMs, pickRunValues, VALUES_FILE_RE } from '../runvalues.js';
|
|
40
40
|
import { readSetup } from '../setup.js';
|
|
41
|
-
import { checkedLines,
|
|
41
|
+
import { checkedLines, notCheckedView, NOT_CHECKED_LABEL } from '../checked.js';
|
|
42
42
|
import {
|
|
43
43
|
NO_COPY_SAY, catchUpWords, endedLineWords, endedWords, needsLeftWords, nextInWords, nextTimeWords, scheduleAuditWords, scheduleBlockWords, scheduleFieldWords, scheduledNextFor, scheduledWords, startedWords,
|
|
44
44
|
} from '../summary-words.js';
|
|
45
45
|
import { MAX_STRUCTURE_RETRIES } from '../drafter.js';
|
|
46
|
+
import { isResultRun, checkTypeOf, buildResult, downloadOf } from './result.js';
|
|
46
47
|
import { thinkingRuleWords, thinkingTryWords } from '../thinking.js';
|
|
47
48
|
import { readRunThinking } from '../flowmodel.js';
|
|
48
49
|
import {
|
|
@@ -1769,6 +1770,9 @@ export function getRunDetail({
|
|
|
1769
1770
|
needsYou: (({ tag, removable }) => ({ tag, removable }))(needsYouOf({
|
|
1770
1771
|
runDir: run.runDir, ctx, glyph, controls: runControls(ctx, glyph, label), nowMs: now(), reopenAt: reopenableAt(run.runDir, ctx),
|
|
1771
1772
|
})),
|
|
1773
|
+
// M10 am4: the Result tab shows for a job that reads a page, a CSV or a .docx; `checkType` is its distinct close classes (the tab's top card)
|
|
1774
|
+
hasResult: isResultRun(ctx.arbiter),
|
|
1775
|
+
checkType: ctx.flowRead.ok ? checkTypeOf(ctx.flowRead.declaration) : '\u2014',
|
|
1772
1776
|
// M9 piece 6: the block at the top of the run page (ENDED / NEXT, SCHEDULED / NEXT), words set by code
|
|
1773
1777
|
summary: runSummary(ctx, glyph, { root, catalogue, triggerRead, now, home }),
|
|
1774
1778
|
resume: ctx.resume,
|
|
@@ -1881,6 +1885,7 @@ export function getDraftBlock(flowDir, runDir) {
|
|
|
1881
1885
|
else if (r.kind === 'startover') happened.push(r.verdict === 'green' ? `starting over${retry(r)}` : 'start over red');
|
|
1882
1886
|
else if (r.kind === 'revise') happened.push(r.verdict === 'red' ? 'revise red' : `revising${retry(r)}`);
|
|
1883
1887
|
else if (r.kind === 'redraft') happened.push(r.verdict === 'red' ? 'redraft red' : `redrafting with your answers${retry(r)}`);
|
|
1888
|
+
else if (r.kind === 'human') happened.push('your answer');
|
|
1884
1889
|
else if (r.kind === 'sign') happened.push(`signed (${r.signedBy ?? 'you'})`);
|
|
1885
1890
|
if (r.kind === 'card') {
|
|
1886
1891
|
const c = r.card && typeof r.card === 'object' ? r.card : {};
|
|
@@ -1888,6 +1893,8 @@ export function getDraftBlock(flowDir, runDir) {
|
|
|
1888
1893
|
typeof c.inputs === 'string' && c.inputs.trim() ? `inputs: ${c.inputs.trim().replace(/\n+/g, ' / ')}` : null, `job: ${String(c.job ?? '').trim().replace(/\n+/g, ' / ')}`].filter(Boolean).join(' · ');
|
|
1889
1894
|
rows.push(human(r, n, { action: 'card (you)', gap }));
|
|
1890
1895
|
} else if (r.kind === 'note') rows.push(human(r, n, { action: 'note (you)', gap: String(r.text ?? '') }));
|
|
1896
|
+
// M10 am2 item 4: a question the page look raised and your answer, under the drafting step, in bareloop's words (`you were asked:` / `you said:`)
|
|
1897
|
+
else if (r.kind === 'human') rows.push(human(r, n, { action: `you were asked: ${r.question}`, gap: `you said: ${r.answer}` }));
|
|
1891
1898
|
else if (r.kind === 'draft') { rows.push(model(r, n, 'draft')); rows.push(...tryRows(r, n)); }
|
|
1892
1899
|
else if (r.kind === 'change') { rows.push(model(r, n, `change ${r.n}`)); rows.push(...tryRows(r, n)); }
|
|
1893
1900
|
else if (r.kind === 'startover') { rows.push(model(r, n, 'start over')); rows.push(...tryRows(r, n)); }
|
|
@@ -2042,7 +2049,8 @@ function buildJobPlan(declaration, asks, flowDir, flowHash = null) {
|
|
|
2042
2049
|
const ofThisJob = !!signRow && (typeof signRow.flowHash !== 'string' || flowHash === null || signRow.flowHash === flowHash);
|
|
2043
2050
|
const nc = ofThisJob ? signRow?.notChecked : undefined;
|
|
2044
2051
|
const recorded = !!nc && Array.isArray(nc.items);
|
|
2045
|
-
|
|
2052
|
+
const view = recorded ? notCheckedView(nc.items, declaration) : { items: [], readNotes: [] };
|
|
2053
|
+
return { steps, notChecked: { label: NOT_CHECKED_LABEL, items: view.items, readNotes: view.readNotes, recorded } };
|
|
2046
2054
|
}
|
|
2047
2055
|
|
|
2048
2056
|
/**
|
|
@@ -2148,6 +2156,79 @@ export function getRunJob({
|
|
|
2148
2156
|
};
|
|
2149
2157
|
}
|
|
2150
2158
|
|
|
2159
|
+
/**
|
|
2160
|
+
* M10 am4: what `getRunResult` and `getRunDownload` both need of one run: its books and the signed job it ran. `null` = no such run, the job is
|
|
2161
|
+
* unreadable, or it is not an M10 job (the route answers 404 "no such run, or it has no result tab").
|
|
2162
|
+
* @param {{root: string, flow: string, runId: string, catalogue: any}} a
|
|
2163
|
+
*/
|
|
2164
|
+
function resultContext({
|
|
2165
|
+
root, flow, runId, catalogue,
|
|
2166
|
+
}) {
|
|
2167
|
+
const run = resolveRunPath(root, flow, runId);
|
|
2168
|
+
if (!run.ok || !readdirInside(run.flowDir, 'runs').includes(runId)) return null; // the gateway lists real, non-symlink run folders only
|
|
2169
|
+
const ctx = loadRunContext(root, run.flowDir, run.runDir, flow, runId, catalogue);
|
|
2170
|
+
if (!ctx.flowRead.ok || !isResultRun(ctx.arbiter)) return null;
|
|
2171
|
+
return { run, ctx };
|
|
2172
|
+
}
|
|
2173
|
+
|
|
2174
|
+
/**
|
|
2175
|
+
* M10 am5 item 2: does this run wait for the person's accept? The Ask tab's own rule (`answerControls` kind "doors"): the newest ask is open and either has no saved
|
|
2176
|
+
* answer or its saved answer could not be read. Read from `getRunAsks`, the Ask tab's one reader, so the two tabs can never disagree.
|
|
2177
|
+
* @param {ReturnType<typeof getRunAsks>} asks @returns {{askId: string, draftNo: number}|null}
|
|
2178
|
+
*/
|
|
2179
|
+
function resultDoorOf(asks) {
|
|
2180
|
+
if (asks === null) return null;
|
|
2181
|
+
const block = asks.blocks.at(-1);
|
|
2182
|
+
const ask = block?.current;
|
|
2183
|
+
if (!ask || ask.open !== true) return null;
|
|
2184
|
+
if (asks.resume && asks.resume.askId === ask.askId && asks.resume.state !== 'broken') return null;
|
|
2185
|
+
return { askId: ask.askId, draftNo: block.draftNo };
|
|
2186
|
+
}
|
|
2187
|
+
|
|
2188
|
+
/**
|
|
2189
|
+
* `GET /api/runs/:flow/:runId/result` — the Result tab (M10 am4). The Not checked list is the Job tab's own (`buildJobPlan`), never a second spelling.
|
|
2190
|
+
* @param {{root: string, flow: string, runId: string, catalogue: any, resumeAttempt?: (flow: string, runId: string) => any, now?: () => number}} a
|
|
2191
|
+
* @returns {any|null}
|
|
2192
|
+
*/
|
|
2193
|
+
export function getRunResult({
|
|
2194
|
+
root, flow, runId, catalogue, resumeAttempt, now,
|
|
2195
|
+
}) {
|
|
2196
|
+
const got = resultContext({
|
|
2197
|
+
root, flow, runId, catalogue,
|
|
2198
|
+
});
|
|
2199
|
+
if (!got) return null;
|
|
2200
|
+
const { run, ctx } = got;
|
|
2201
|
+
const sig = ctx.flowRead.signature;
|
|
2202
|
+
const plan = buildJobPlan(ctx.flowRead.declaration, ctx.arbiter.asks ?? [], run.flowDir, typeof sig?.flow === 'string' ? sig.flow : null);
|
|
2203
|
+
return buildResult({
|
|
2204
|
+
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,
|
|
2205
|
+
setupRows: (() => { const st = readSetup(run.flowDir); return st.present ? st.rows : []; })(),
|
|
2206
|
+
door: resultDoorOf(getRunAsks({
|
|
2207
|
+
root, flow, runId, catalogue, resumeAttempt, now,
|
|
2208
|
+
})),
|
|
2209
|
+
});
|
|
2210
|
+
}
|
|
2211
|
+
|
|
2212
|
+
/**
|
|
2213
|
+
* `GET /api/runs/:flow/:runId/download?i=<n>` (M10 am4): one saved file, or why not.
|
|
2214
|
+
* @param {{root: string, flow: string, runId: string, catalogue: any, index: unknown}} a
|
|
2215
|
+
* @returns {ReturnType<typeof downloadOf>}
|
|
2216
|
+
*/
|
|
2217
|
+
export function getRunDownload({
|
|
2218
|
+
root, flow, runId, catalogue, index,
|
|
2219
|
+
}) {
|
|
2220
|
+
const got = resultContext({
|
|
2221
|
+
root, flow, runId, catalogue,
|
|
2222
|
+
});
|
|
2223
|
+
if (!got) return { ok: false, code: 404, error: 'no such run, or it has no result tab' };
|
|
2224
|
+
return downloadOf({
|
|
2225
|
+
index,
|
|
2226
|
+
ctx: {
|
|
2227
|
+
arbiter: got.ctx.arbiter, declaration: got.ctx.flowRead.declaration, runDir: got.run.runDir, root, flow, runId, auditRows: got.ctx.auditRows,
|
|
2228
|
+
},
|
|
2229
|
+
});
|
|
2230
|
+
}
|
|
2231
|
+
|
|
2151
2232
|
// ---------------------------------------------------------------------------
|
|
2152
2233
|
// M4a Amendment M4a-1 — the panel's Inbox/Ask surface (docs/wiki/the-module-
|
|
2153
2234
|
// ladder.md, "M4a" section, signed 2026-09-27). Every stop (parked ask) this
|