fwdloop 0.38.0 → 0.39.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 +21 -19
- package/package.json +1 -1
- package/src/ask.js +70 -148
- package/src/audit-fold.js +5 -4
- package/src/auditchecks.js +6 -4
- package/src/authoring.js +32 -60
- package/src/blockasks.js +2 -1
- package/src/blockassemble.js +3 -2
- package/src/blockdraft.js +2 -2
- package/src/blockpick.js +5 -5
- package/src/books.js +217 -12
- package/src/checkblock.js +20 -41
- package/src/checklistsign.js +25 -3
- package/src/checklook.js +3 -1
- package/src/checkpick.js +5 -76
- package/src/cited-source.js +4 -4
- package/src/citedcheck.js +6 -11
- package/src/citedwords.js +9 -8
- package/src/closers.js +9 -6
- package/src/declaration.js +14 -49
- package/src/diary.js +23 -1
- package/src/draft-steps.js +11 -1
- package/src/drafter.js +13 -9
- package/src/draftfiles.js +127 -0
- package/src/draftspend.js +165 -17
- package/src/flow.js +42 -87
- package/src/flowmodel.js +1 -1
- package/src/index.js +3 -2
- package/src/inside.js +86 -0
- package/src/jsonl-append.js +33 -1
- package/src/learn.js +1 -1
- package/src/learnstore.js +20 -22
- package/src/line-checks.js +1 -1
- package/src/liveness.js +3 -0
- package/src/mcp-use.js +8 -9
- package/src/memo.js +13 -16
- package/src/model-step.js +2 -2
- package/src/page-words.js +8 -0
- package/src/pageask.js +8 -3
- package/src/pagebits.js +8 -1
- package/src/pagedropwords.js +1 -1
- package/src/pagerules.js +6 -3
- package/src/panel/author.js +99 -75
- package/src/panel/authorcard.js +21 -8
- package/src/panel/authorflows.js +3 -3
- package/src/panel/authorresume.js +3 -3
- package/src/panel/authorstart.js +15 -16
- package/src/panel/authortrigger.js +43 -70
- package/src/panel/data.js +125 -168
- package/src/panel/index.html +122 -61
- package/src/panel/jobgrid.js +3 -7
- package/src/panel/result.js +7 -10
- package/src/panel/resume.js +4 -3
- package/src/panel/scheduler.js +9 -9
- package/src/panel/server.js +8 -4
- package/src/panel/spawn.js +22 -11
- package/src/panel/tickets.js +2 -2
- package/src/pickrecord.js +51 -31
- package/src/placerule.js +3 -4
- package/src/planrebuild.js +19 -19
- package/src/primitives.js +1 -1
- package/src/provider.js +1 -1
- package/src/reasons.js +25 -0
- package/src/runfile.js +26 -2
- package/src/runner.js +57 -105
- package/src/runvalues.js +47 -24
- package/src/schedule-choices.js +41 -0
- package/src/schedule-shape.js +39 -0
- package/src/schedule.js +9 -8
- package/src/setup.js +20 -36
- package/src/shaperows.js +2 -2
- package/src/sheetblock.js +2 -2
- package/src/sheetbuild.js +5 -5
- package/src/sheetrun.js +4 -5
- package/src/summary-words.js +2 -1
- package/src/thinking.js +5 -2
- package/src/ticketrows.js +7 -28
- package/src/trigger-clock.js +9 -23
- package/src/trigger-files.js +30 -22
- package/src/trigger-tickets.js +15 -14
- package/src/try-checks.js +2 -1
- package/src/types.js +2 -0
- package/types/ask.d.ts +25 -20
- package/types/authoring.d.ts +7 -42
- package/types/blockpick.d.ts +1 -1
- package/types/books.d.ts +256 -4
- package/types/checkblock.d.ts +1 -23
- package/types/checklist.d.ts +3 -3
- package/types/checklistsign.d.ts +7 -0
- package/types/checkpick.d.ts +0 -21
- package/types/citedwords.d.ts +7 -4
- package/types/closers.d.ts +1 -0
- package/types/declaration.d.ts +4 -14
- package/types/diary.d.ts +14 -1
- package/types/draft-steps.d.ts +7 -0
- package/types/drafter.d.ts +1 -1
- package/types/draftfiles.d.ts +89 -0
- package/types/draftspend.d.ts +74 -0
- package/types/flow.d.ts +32 -54
- package/types/index.d.ts +3 -3
- package/types/inside.d.ts +58 -0
- package/types/jsonl-append.d.ts +20 -0
- package/types/learnstore.d.ts +0 -2
- package/types/liveness.d.ts +1 -0
- package/types/page-words.d.ts +6 -0
- package/types/pageask.d.ts +2 -0
- package/types/pagebits.d.ts +3 -0
- package/types/pagerules.d.ts +1 -0
- package/types/panel/author.d.ts +7 -3
- package/types/panel/authorcard.d.ts +0 -6
- package/types/panel/authorflows.d.ts +4 -4
- package/types/panel/authortrigger.d.ts +16 -2
- package/types/panel/data.d.ts +36 -11
- package/types/panel/spawn.d.ts +18 -2
- package/types/pickrecord.d.ts +29 -0
- package/types/reasons.d.ts +23 -0
- package/types/runfile.d.ts +14 -0
- package/types/runner.d.ts +6 -38
- package/types/runvalues.d.ts +17 -2
- package/types/schedule-choices.d.ts +9 -0
- package/types/schedule-shape.d.ts +15 -0
- package/types/sheetbuild.d.ts +1 -1
- package/types/thinking.d.ts +1 -0
- package/types/ticketrows.d.ts +0 -9
- package/types/trigger-clock.d.ts +3 -2
- package/types/trigger-files.d.ts +15 -4
- package/types/types.d.ts +8 -0
package/src/panel/author.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// card.json the typed card fields (what the human typed; never a key — checkCard refuses one)
|
|
12
12
|
// prose.txt the prose file `fwdloop draft` reads, built from the card by `cardToProse` (src/panel/authorcard.js)
|
|
13
13
|
// child.log the child's stdout+stderr, mode 0600 (quoted to the page only after `scrub`)
|
|
14
|
-
// pid.json { pid, procStart } written right after the spawn; the ONE liveness fact (`
|
|
14
|
+
// pid.json { pid, procStart } written right after the spawn; the ONE liveness fact (`childState` in spawn.js, M4c / M20 am3 item 8)
|
|
15
15
|
// draft/ the CLI's own output (spec.hash, readout.txt, log.json, spend.jsonl, draft-spend.json ...)
|
|
16
16
|
// card-<n>.json the card as the human submitted it for revise <n> (M4e amendment 14 item 2), written by `revise`, write-once ('wx'), never a key
|
|
17
17
|
// prose-<n>.txt the prose file built from card-<n>.json (the ONE `cardToProse`); the model gets this card only, never the old plan
|
|
@@ -37,16 +37,15 @@ import { userInfo } from 'node:os';
|
|
|
37
37
|
import { dirname, join } from 'node:path';
|
|
38
38
|
import { fileURLToPath } from 'node:url';
|
|
39
39
|
|
|
40
|
-
import {
|
|
41
|
-
|
|
42
|
-
} from '../authoring.js';
|
|
40
|
+
import { OPEN_QUESTION_SAY, PANEL_DRAFTS_DIR, claimPlanDir, readTargetName, readoutHeadIndexes, signDraft, writePlanFiles } from '../authoring.js';
|
|
41
|
+
import { ANSWER_FILE, draftVerdict, readQuestions, readNotCheckedFile, readCard, cardFileName, readRedraftMarker, redraftFileName, readPlanTexts, scrub } from '../draftfiles.js';
|
|
43
42
|
import { rowEditPlan } from '../planrebuild.js';
|
|
44
43
|
import { cardLinesOf } from '../checklistsign.js';
|
|
45
44
|
import { appendSpendRow } from '../provider.js';
|
|
46
45
|
import { ruleOfAnswer, panelQuestionText, DROP_IT, TIE_PICK_SAY } from '../pageask.js';
|
|
47
|
-
import { checkFlowName, nextRunId,
|
|
46
|
+
import { checkFlowName, nextRunId, readJsonFile, readDraftLog } from '../flow.js';
|
|
47
|
+
import { readFileInside, readdirInside } from '../inside.js';
|
|
48
48
|
import { readModelRecord } from '../flowmodel.js';
|
|
49
|
-
import { isFwdloopAlive } from '../liveness.js';
|
|
50
49
|
import {
|
|
51
50
|
checkMonthlyRoom, ConfigError, monthlyNote, monthlyRefusalText,
|
|
52
51
|
} from '../monthly.js';
|
|
@@ -55,16 +54,16 @@ import {
|
|
|
55
54
|
} from './authorcard.js';
|
|
56
55
|
import { checkedLines, notCheckedView } from '../checked.js';
|
|
57
56
|
import { EVERY_STEP_TEXTS } from '../try-checks.js';
|
|
58
|
-
import { recordPath, RECORD_FILE, KEPT_WORDS } from '../pickrecord.js';
|
|
57
|
+
import { recordPath, RECORD_FILE, KEPT_WORDS, readKept, isRowChoice } from '../pickrecord.js';
|
|
59
58
|
import { csvRolesOf } from '../sheetblock.js';
|
|
60
59
|
import {
|
|
61
60
|
readPriceConfig, resolveSlot, resolveUsableModel, tickedLines,
|
|
62
61
|
} from '../provider.js';
|
|
63
62
|
import { thinkingSupport as bareagentThinkingSupport, THINKING_FIXED_SAY, THINKING_UNVERIFIED_SAY } from '../thinking.js';
|
|
64
63
|
import { parseSignedText } from '../signed-text.js';
|
|
65
|
-
import { draftStepList, reviseStepList } from '../draft-steps.js';
|
|
64
|
+
import { draftStepList, reviseStepList, CARD_RE, LOG_TAIL_CHARS, draftLogName } from '../draft-steps.js';
|
|
66
65
|
import {
|
|
67
|
-
capTooSmallText, draftingSpent, EARLIER_MISSING_SAY, potSplit, STARTED_OVER_FILE, usdText,
|
|
66
|
+
capTooSmallText, draftedLine, draftingSpent, EARLIER_MISSING_SAY, potSplit, STARTED_OVER_FILE, STEP_LINE_PREFIXES, usdText, withDraftTimes,
|
|
68
67
|
} from '../draftspend.js';
|
|
69
68
|
import { jobKeyOfCard } from '../jobkey.js';
|
|
70
69
|
import { flowValues, valuesHash, parseWaitMs } from '../runvalues.js';
|
|
@@ -75,7 +74,7 @@ import { createTriggerDoor } from './authortrigger.js';
|
|
|
75
74
|
import { createResumeDoor } from './authorresume.js';
|
|
76
75
|
import { createStarter } from './authorstart.js';
|
|
77
76
|
import {
|
|
78
|
-
childRunning as childRunningNow,
|
|
77
|
+
childAlive, childRunning as childRunningNow, childState, providerKeys, spawnDetached, writePidFile,
|
|
79
78
|
} from './spawn.js';
|
|
80
79
|
|
|
81
80
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
@@ -88,16 +87,18 @@ const ID_RE = /^d-[0-9a-z]{10}-[0-9a-f]{4}$/;
|
|
|
88
87
|
const newId = () => `d-${Date.now().toString(36).padStart(10, '0')}-${randomBytes(2).toString('hex')}`;
|
|
89
88
|
/** The phases that end a card's life: Abandon or a sign. Everything else is still on the card (to read, to sign, to retry). */
|
|
90
89
|
const FINISHED = new Set(['abandoned', 'signed']);
|
|
91
|
-
const LOG_TAIL_CHARS = 1500;
|
|
92
90
|
const STOPPED_SAY = 'The draft process ended before it finished (it was stopped from outside). Nothing was signed and nothing was sent. Draft again.';
|
|
93
91
|
/** M6 am9: written once into a draft folder when the draft is a red run's redraft of an UNCHANGED job: `{flow, fromRun}`. Sign reads it; nothing else decides. */
|
|
94
92
|
const RUN_OF_FILE = 'run-of.json';
|
|
95
93
|
const RED_SAY = 'The drafter\'s plan did not pass the checks. Nothing was signed and nothing was sent. Fix the job and draft again; this draft is kept on disk and is never reused.';
|
|
96
94
|
/** Up to 2 revises per draft (amendment 14 item 3); a revise is used once its `draft-<n>/` exists (a refusal at $0 makes none). */
|
|
97
95
|
export const MAX_REVISES = 2;
|
|
98
|
-
|
|
96
|
+
/** M20 am8a: the phases in which a revise or the redraft after the human's answers is running over an existing plan (a first draft is `drafting`: another refusal). The panel hands the list to the page. */
|
|
97
|
+
export const REVISE_PHASES = Object.freeze(['revising', 'redrafting']);
|
|
98
|
+
/** M20 am8a: the phases where the draft ended not green, red or stopped (the card is open to fix and draft again). The panel hands the list to the page. */
|
|
99
|
+
export const NOT_GREEN_PHASES = Object.freeze(['red', 'stopped']);
|
|
99
100
|
/** The phases in which a draft child is running (a first draft, a revise, or the redraft after the human's answers). */
|
|
100
|
-
const LIVE_PHASES = new Set(['drafting',
|
|
101
|
+
const LIVE_PHASES = new Set(['drafting', ...REVISE_PHASES]);
|
|
101
102
|
const ANSWERS_NOT_DRAFTED_SAY = 'Your answers are saved, but the plan was not drafted again with them (the process did not start). Nothing was signed. Draft again from the card.';
|
|
102
103
|
const REDRAFT_RED_SAY = 'The plan drafted with your answers did not pass the checks. Nothing can be signed until a plan is green. Your answers are kept in the card: change it and draft again.';
|
|
103
104
|
const BLANK_ANSWER_SAY = 'Write an answer. A question can\'t be skipped; the plan waits for it.';
|
|
@@ -140,7 +141,6 @@ export function createAuthor(opts) {
|
|
|
140
141
|
try { return join(realpathSync(root), PANEL_DRAFTS_DIR); } catch { return null; }
|
|
141
142
|
};
|
|
142
143
|
|
|
143
|
-
const readJson = readJsonFile;
|
|
144
144
|
/** every file text scrubbed of the keys, as the draft child writes them @param {Record<string, string>} files @param {string[]} keys */
|
|
145
145
|
const scrubbed = (files, keys) => Object.fromEntries(Object.entries(files).map(([f, t]) => [f, scrub(t, keys)]));
|
|
146
146
|
const isObj = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
@@ -163,10 +163,44 @@ export function createAuthor(opts) {
|
|
|
163
163
|
* @param {string} dir the draft folder @param {string} id @param {string[]} keys
|
|
164
164
|
*/
|
|
165
165
|
function readDraft(dir, id, keys) {
|
|
166
|
-
const
|
|
166
|
+
const v = readDraftState(dir, id, keys);
|
|
167
|
+
// M20 am1 items 5-6: the times of every draft's list (the first, each revise and answer redraft: each reads its own child log) and the session's "Drafted in" line,
|
|
168
|
+
// from the step lines (src/draftspend.js, the one owner); an old draft has none
|
|
169
|
+
const sc = (x) => scrub(String(x), keys);
|
|
170
|
+
const out = { ...v };
|
|
171
|
+
if ((v.phase === 'drafting' || Array.isArray(v.stepList)) && !(v.phase === 'questions-open' && v.plan !== 'draft')) {
|
|
172
|
+
// `stepList` is the FIRST draft's list in every phase but an open question on a later plan (that one is its own plan's list, which child.log does not hold)
|
|
173
|
+
const timed = withDraftTimes({ dir, running: v.phase === 'drafting', list: Array.isArray(v.stepList) ? v.stepList : null });
|
|
174
|
+
if (timed.list !== null) out.stepList = timed.list.map((l) => ({ ...l, label: sc(l.label) }));
|
|
175
|
+
if (timed.draftSoFar !== null) out.draftSoFar = timed.draftSoFar;
|
|
176
|
+
}
|
|
177
|
+
if (Array.isArray(v.revises)) {
|
|
178
|
+
out.revises = v.revises.map((rv) => {
|
|
179
|
+
const file = draftLogName(rv.kind, rv.n);
|
|
180
|
+
if (rv.phase === 'running') {
|
|
181
|
+
const t = withDraftTimes({ dir, file, running: true, list: null });
|
|
182
|
+
if (t.draftSoFar !== null) out.draftSoFar = t.draftSoFar;
|
|
183
|
+
return t.list === null ? rv : { ...rv, lines: t.list.map((l) => ({ ...l, label: sc(l.label) })) };
|
|
184
|
+
}
|
|
185
|
+
if (!Array.isArray(rv.lines)) return rv;
|
|
186
|
+
return { ...rv, lines: withDraftTimes({ dir, file, running: false, list: rv.lines, wholeId: 'plan' }).list };
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
if (v.phase === 'green') {
|
|
190
|
+
// the money is the session's drafting spend from the one session reader; a session none of whose plans knew its cost shows no line (never a number made of ceilings)
|
|
191
|
+
const known = readdirInside(dir, '.').some((n) => (n === 'draft' || PLAN_DIR_RE.test(n)) && typeof readDraftLog(dir, n)?.costUsd === 'number');
|
|
192
|
+
const spent = draftingSpent(dir, { ceilingUsd: capFloorFor(true, home, v.card) });
|
|
193
|
+
const line = draftedLine({ dir, spentUsd: known ? spent.usd : null, complete: spent.complete });
|
|
194
|
+
if (line !== null) out.draftedLine = line;
|
|
195
|
+
}
|
|
196
|
+
return out;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function readDraftState(dir, id, keys) {
|
|
200
|
+
const card = readCard(dir);
|
|
167
201
|
const base = { draftId: id, card };
|
|
168
|
-
if (
|
|
169
|
-
const signed =
|
|
202
|
+
if (readJsonFile(dir, 'abandoned.json')) return { ...base, phase: 'abandoned' };
|
|
203
|
+
const signed = readJsonFile(dir, 'signed.json');
|
|
170
204
|
if (signed) return { ...base, phase: 'signed' };
|
|
171
205
|
|
|
172
206
|
// C9: ask "is it still running" FIRST, then read the result. A child that finishes between the two reads is then seen as finished
|
|
@@ -186,7 +220,7 @@ export function createAuthor(opts) {
|
|
|
186
220
|
function logTail(dir, rel, keys) {
|
|
187
221
|
const logText = readFileInside(dir, rel);
|
|
188
222
|
// the typed refusal record (`refusalOf` reads it) is machine text, never part of what the person is told
|
|
189
|
-
return logText.ok ? scrub(logText.text, keys).split('\n').filter((l) => !l.startsWith(REFUSAL_RECORD)).join('\n').trim().slice(-LOG_TAIL_CHARS).replace(/^fwdloop: /, '') : '';
|
|
223
|
+
return logText.ok ? scrub(logText.text, keys).split('\n').filter((l) => !l.startsWith(REFUSAL_RECORD) && !STEP_LINE_PREFIXES.some((p) => l.startsWith(p))).join('\n').trim().slice(-LOG_TAIL_CHARS).replace(/^fwdloop: /, '') : '';
|
|
190
224
|
}
|
|
191
225
|
|
|
192
226
|
/**
|
|
@@ -211,8 +245,8 @@ export function createAuthor(opts) {
|
|
|
211
245
|
* @param {string} dir @param {string} rel @param {string[]} keys @param {boolean} [questionOpen]
|
|
212
246
|
*/
|
|
213
247
|
function stepListOf(dir, rel, keys, questionOpen = false) {
|
|
214
|
-
const declaration =
|
|
215
|
-
const list = draftStepList({ log:
|
|
248
|
+
const declaration = readJsonFile(dir, `${rel}/declaration.json`) ?? readJsonFile(dir, `${rel}/declaration.rejected.json`);
|
|
249
|
+
const list = draftStepList({ log: readDraftLog(dir, rel), declaration, questionOpen });
|
|
216
250
|
if (list === null) return null;
|
|
217
251
|
const sc = (x) => scrub(String(x), keys);
|
|
218
252
|
return list.map((st) => ({ ...st, label: sc(st.label), details: st.details.map(sc) }));
|
|
@@ -245,18 +279,14 @@ export function createAuthor(opts) {
|
|
|
245
279
|
* @returns {any}
|
|
246
280
|
*/
|
|
247
281
|
function resultOf(dir, rel, keys) {
|
|
248
|
-
const
|
|
249
|
-
if (
|
|
282
|
+
const v = draftVerdict(dir, rel);
|
|
283
|
+
if (v.verdict === 'green') {
|
|
250
284
|
const readout = readFileInside(dir, `${rel}/readout.txt`);
|
|
251
285
|
const text = readout.ok ? scrub(readout.text, keys) : '';
|
|
252
|
-
return { phase: 'green', hash:
|
|
286
|
+
return { phase: 'green', hash: v.hash, readout: text, readoutHeads: readoutHeadIndexes(text), stepList: stepListOf(dir, rel, keys) };
|
|
253
287
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
if (leak.ok || (log && log.ok === false)) {
|
|
257
|
-
const reds = Array.isArray(log?.reds) ? log.reds.map((r) => scrub(String(r), keys)) : [];
|
|
258
|
-
if (leak.ok) reds.push(scrub(leak.text.trim(), keys));
|
|
259
|
-
return { phase: 'red', reds, say: RED_SAY, stepList: stepListOf(dir, rel, keys) };
|
|
288
|
+
if (v.verdict === 'red') {
|
|
289
|
+
return { phase: 'red', reds: v.reds.map((r) => scrub(r, keys)), say: RED_SAY, stepList: stepListOf(dir, rel, keys) };
|
|
260
290
|
}
|
|
261
291
|
return null;
|
|
262
292
|
}
|
|
@@ -273,27 +303,27 @@ export function createAuthor(opts) {
|
|
|
273
303
|
function withRevises(base, dir, first, keys, firstQsRead) {
|
|
274
304
|
const names = readdirInside(dir, '.');
|
|
275
305
|
const ns = names.map((n) => CARD_RE.exec(n)?.[1]).filter((x) => x !== undefined).map(Number).sort((a, b) => a - b);
|
|
276
|
-
const redrafts = new Set(ns.filter((n) =>
|
|
306
|
+
const redrafts = new Set(ns.filter((n) => readRedraftMarker(dir, n) !== null));
|
|
277
307
|
const used = names.filter((n) => PLAN_DIR_RE.test(n) && !redrafts.has(Number(PLAN_DIR_RE.exec(n)?.[1]))).length;
|
|
278
308
|
const revisesLeft = Math.max(0, MAX_REVISES - used);
|
|
279
309
|
const newest = ns.length > 0 ? ns[ns.length - 1] : 0;
|
|
280
|
-
const card = newest > 0 ? (
|
|
310
|
+
const card = newest > 0 ? (readCard(dir, newest) ?? base.card) : base.card;
|
|
281
311
|
let reviseNo = 0;
|
|
282
312
|
const revises = ns.map((n) => {
|
|
283
313
|
const kind = redrafts.has(n) ? 'answers' : 'revise';
|
|
284
314
|
if (kind === 'revise') reviseNo += 1;
|
|
285
315
|
// M4d am15 (every line of the list): this plan's own line, from its own log, built by `reviseStepList`; the try history is in the Audit Draft group
|
|
286
|
-
const rowEdit = kind === 'answers' ?
|
|
316
|
+
const rowEdit = kind === 'answers' ? readRedraftMarker(dir, n)?.rowEdit : undefined;
|
|
287
317
|
const name = rowEdit ? (rowEdit.op === 'drop' ? 'a check dropped' : 'a check added') : kind === 'answers' ? 'drafted again with your answers' : `revise ${reviseNo}`;
|
|
288
318
|
const running = n === newest && childRunning(dir); // C9: running first, then the result
|
|
289
319
|
// the result BEFORE the log: the child writes log.json first and the result (spec.hash, or the red log itself) after, so a result we see has its log already on disk
|
|
290
320
|
const res = resultOf(dir, `draft-${n}`, keys);
|
|
291
|
-
const lines = reviseStepList({ log:
|
|
321
|
+
const lines = reviseStepList({ log: readDraftLog(dir, `draft-${n}`), name });
|
|
292
322
|
const scrubbed = lines === null ? null : lines.map((l) => ({ ...l, label: scrub(l.label, keys) }));
|
|
293
323
|
if (res && res.phase === 'green') return { n, kind, phase: 'green', hash: res.hash, name, lines: scrubbed };
|
|
294
324
|
if (res) return { n, kind, phase: 'red', reds: res.reds, say: kind === 'answers' ? REDRAFT_RED_SAY : REVISE_RED_SAY, name, lines: scrubbed };
|
|
295
325
|
if (running) return { n, kind, phase: 'running', name };
|
|
296
|
-
const logRel =
|
|
326
|
+
const logRel = draftLogName(kind, n);
|
|
297
327
|
return { n, kind, name, phase: 'stopped', say: logTail(dir, logRel, keys) || STOPPED_SAY, refusal: refusalOf(dir, logRel, keys) };
|
|
298
328
|
});
|
|
299
329
|
const cur = /** @type {{ phase: string, kind: string, say?: string, refusal?: {box: string|null, words: string} | null }} */ (newest > 0 ? revises[revises.length - 1] : { phase: first.phase, kind: 'first' });
|
|
@@ -338,14 +368,14 @@ export function createAuthor(opts) {
|
|
|
338
368
|
id, dir, v, vet, env, marker, argvOf, failSay, undoToo = [],
|
|
339
369
|
}) {
|
|
340
370
|
const n = Math.max(0, ...v.revises.map((x) => x.n)) + 1;
|
|
341
|
-
const files = [
|
|
371
|
+
const files = [cardFileName(n), `prose-${n}.txt`, redraftFileName(n)].map((f) => join(dir, f));
|
|
342
372
|
const undo = () => { for (const f of [...files, ...undoToo]) rmSync(f, { force: true }); };
|
|
343
373
|
let child;
|
|
344
374
|
try {
|
|
345
375
|
writeFileSync(files[0], `${JSON.stringify(vet.card, null, 2)}\n`, { mode: 0o600, flag: 'wx' });
|
|
346
376
|
writeFileSync(files[1], vet.prose, { mode: 0o600, flag: 'wx' });
|
|
347
377
|
writeFileSync(files[2], `${JSON.stringify(marker)}\n`, { mode: 0o600, flag: 'wx' });
|
|
348
|
-
child = spawnDetached({ bin, argv: argvOf(n, files[1], realpathSync(root)), env, logPath: join(dir,
|
|
378
|
+
child = spawnDetached({ bin, argv: argvOf(n, files[1], realpathSync(root)), env, logPath: join(dir, draftLogName('answers', n)) });
|
|
349
379
|
} catch (e) {
|
|
350
380
|
undo();
|
|
351
381
|
return { status: 500, body: { ok: false, refused: 'spawn', say: failSay(String(/** @type {any} */ (e)?.code ?? 'error')), draftId: id } };
|
|
@@ -366,19 +396,17 @@ export function createAuthor(opts) {
|
|
|
366
396
|
* "Not checked" (the drafter's own list, always with its label). Read-only; neither is signed or in the hash. @param {string} dir @param {string} rel
|
|
367
397
|
*/
|
|
368
398
|
function planChecks(dir, rel) {
|
|
369
|
-
const decl =
|
|
370
|
-
const
|
|
371
|
-
const parsed = prose.ok ? parseSignedText(prose.text) : null;
|
|
372
|
-
const kept = readJson(dir, `${rel}/${RECORD_FILE}`)?.kept;
|
|
399
|
+
const { declaration: decl, parsed } = readPlanTexts(dir, rel);
|
|
400
|
+
const kept = readKept(dir, rel).kept;
|
|
373
401
|
const opts = {
|
|
374
402
|
...(parsed?.ok === true ? { askLines: parsed.arbiter.asks.map((x) => x.line), lines: parsed.lines, csvRoles: csvRolesOf(parsed.arbiter) } : { hasAsk: true }),
|
|
375
403
|
...(Array.isArray(kept) ? { keptChecks: kept.filter((k) => k && k.check).map((k) => ({ line: k.line, check: k.check })), keptWords: KEPT_WORDS } : {}),
|
|
376
404
|
};
|
|
377
|
-
const ncFile =
|
|
378
|
-
const view = notCheckedView(ncFile
|
|
405
|
+
const ncFile = readNotCheckedFile(dir, rel);
|
|
406
|
+
const view = notCheckedView(ncFile.notChecked, decl);
|
|
379
407
|
// M16 item 5: the plan card's list - the rows with their tags and Drop, the suggestions with Add - read from the card the draft saved (src/cardlist.js); a plan without a list has none
|
|
380
408
|
// M19 am6: a saved draft with a signed list draws its card rows read from the plan (a card saved with the old words is rebuilt); the suggestions, the restorable rows and the Drop flags are the saved card's
|
|
381
|
-
const savedLog = cardLinesOf(decl).size > 0 ?
|
|
409
|
+
const savedLog = cardLinesOf(decl).size > 0 ? readDraftLog(dir, rel) : undefined;
|
|
382
410
|
const card = savedLog?.checkCard && parsed?.ok === true && Array.isArray(savedLog.checkCard.rows)
|
|
383
411
|
? planCard(savedLog.checkCard, { declaration: decl, lines: parsed.lines, csvRoles: csvRolesOf(parsed.arbiter), kept: Array.isArray(kept) ? kept.filter((/** @type {any} */ k) => k && Number.isInteger(k.line)) : [], log: savedLog.log })
|
|
384
412
|
: savedLog?.checkCard;
|
|
@@ -386,17 +414,17 @@ export function createAuthor(opts) {
|
|
|
386
414
|
// M16 P4c (bareloop's plan view): the job's lines with their `~` rules (the signed text's own, split at its "; " joins) and the two checks every step has; a plan with a list draws them
|
|
387
415
|
const planLines = parsed?.ok === true ? parsed.lines.map((/** @type {any} */ l) => ({ n: l.n, text: l.text, rules: l.guardrail ? l.guardrail.split('; ') : [] })) : [];
|
|
388
416
|
// M13 am11: the job's action (its last line, when the AI named it or the person agreed or typed it), drawn as `› line <n> writes everything before it [agent]` (no Drop, am11c)
|
|
389
|
-
const act =
|
|
417
|
+
const act = readDraftLog(dir, rel)?.action;
|
|
390
418
|
const action = isObj(act) && Number.isInteger(act.line) && act.dropped !== true ? { line: act.line, ...(act.by === 'agent' || act.by === 'you' ? { by: act.by } : {}) } : null;
|
|
391
419
|
return {
|
|
392
|
-
...(action ? { action } : {}), checked: checkedLines(decl, opts), notChecked: { ...view, ...(
|
|
420
|
+
...(action ? { action } : {}), checked: checkedLines(decl, opts), notChecked: { ...view, ...(ncFile.by ? { by: ncFile.by } : {}), rows: ncRowsOf(view.items, ncFile.by ?? {}) }, ...(list ? { list, planLines, always: [...EVERY_STEP_TEXTS] } : {}),
|
|
393
421
|
};
|
|
394
422
|
}
|
|
395
423
|
|
|
396
424
|
/** The answers an answer-redraft was drafted with, as the marker recorded them: `[{ line, lineText, question, answer }]` (scrubbed). @param {string} dir @param {number} n @param {string[]} keys */
|
|
397
425
|
function answersOf(dir, n, keys) {
|
|
398
|
-
const rec =
|
|
399
|
-
const card =
|
|
426
|
+
const rec = readRedraftMarker(dir, n);
|
|
427
|
+
const card = readCard(dir, n);
|
|
400
428
|
const steps = parseJobBox(typeof card?.job === 'string' ? card.job : '').steps;
|
|
401
429
|
return (Array.isArray(rec?.answers) ? rec.answers : []).map((a) => ({
|
|
402
430
|
line: a.line, lineText: steps[a.line - 1]?.text ?? null, question: scrub(String(a.question), keys), answer: scrub(String(a.answer), keys),
|
|
@@ -435,8 +463,8 @@ export function createAuthor(opts) {
|
|
|
435
463
|
// amendments 24/25: a plan with a question open is never signed from here; signDraft refuses it again from the plan folder (the same check)
|
|
436
464
|
if (v.phase === 'questions-open') return no(409, 'question-open', OPEN_QUESTION_SAY);
|
|
437
465
|
if (v.phase !== 'green') return no(409, 'not-green', `This draft is ${v.phase}, not a finished plan, so it cannot be signed.`);
|
|
438
|
-
const name =
|
|
439
|
-
if (
|
|
466
|
+
const name = readTargetName(join(dir, v.plan));
|
|
467
|
+
if (name === null) return no(409, 'no-name', 'The draft has no readable flow name. Nothing was signed.');
|
|
440
468
|
return {
|
|
441
469
|
ok: true, v: /** @type {any} */ (v), name, dir,
|
|
442
470
|
};
|
|
@@ -626,7 +654,7 @@ export function createAuthor(opts) {
|
|
|
626
654
|
mkdirSync(dd, { recursive: true, mode: 0o700 });
|
|
627
655
|
mkdirSync(dir, { mode: 0o700 });
|
|
628
656
|
const proseFile = join(dir, 'prose.txt');
|
|
629
|
-
writeFileSync(join(dir,
|
|
657
|
+
writeFileSync(join(dir, cardFileName()), `${JSON.stringify(card, null, 2)}\n`, { mode: 0o600 });
|
|
630
658
|
// amendment 14 item 6: a Start over names the draft it started over from; write-once, here only. An id that is not one of this panel's drafts is ignored.
|
|
631
659
|
const from = body?.startedOverFrom;
|
|
632
660
|
if (typeof from === 'string' && ID_RE.test(from) && listIds().includes(from)) {
|
|
@@ -700,16 +728,14 @@ export function createAuthor(opts) {
|
|
|
700
728
|
}
|
|
701
729
|
const signedBy = userInfo().username;
|
|
702
730
|
// M6 am9: a red run's redraft of an unchanged job is signed as the plan of a NEW run of the same workflow (the workflow's files are not written)
|
|
703
|
-
const runOfRec =
|
|
731
|
+
const runOfRec = readJsonFile(dir, RUN_OF_FILE);
|
|
704
732
|
const asRunOf = typeof runOfRec?.flow === 'string' ? { flow: runOfRec.flow } : undefined;
|
|
705
733
|
if (asRunOf !== undefined && runId !== '') return { status: 400, body: { ok: false, refused: 'run-id', say: 'This plan becomes the next run of its workflow by itself; a run name cannot be typed. Nothing was signed.' } };
|
|
706
734
|
// M13 piece 5 (signed item 7): the card's Schedule row is checked now, on the plan about to be signed, so a refusal never leaves a signed job without its schedule. A plan that becomes the next
|
|
707
735
|
// run of its workflow signs no job, so it signs no schedule: the workflow keeps the one it has.
|
|
708
736
|
let cardSchedule = null;
|
|
709
737
|
if (asRunOf === undefined && v.card.schedule) {
|
|
710
|
-
const
|
|
711
|
-
const planDecl = readJson(join(dir, v.plan), 'declaration.json');
|
|
712
|
-
const parsedPlan = planProse.ok ? parseSignedText(planProse.text) : null;
|
|
738
|
+
const { declaration: planDecl, parsed: parsedPlan } = readPlanTexts(join(dir, v.plan));
|
|
713
739
|
if (!parsedPlan || !parsedPlan.ok || !planDecl) return { status: 409, body: { ok: false, refused: 'schedule', say: 'The plan could not be read to check its schedule. Nothing was signed.' } };
|
|
714
740
|
const planned = triggerDoor.cardSchedule(v.card.schedule, { arbiter: parsedPlan.arbiter, declaration: planDecl });
|
|
715
741
|
if (!planned.ok) return { status: 400, body: { ok: false, refused: 'schedule', say: planned.say } };
|
|
@@ -731,8 +757,7 @@ export function createAuthor(opts) {
|
|
|
731
757
|
let values = null;
|
|
732
758
|
// M13 am11a 2: a job with an action and no Ask line keeps the card's Ask wait (the stop before the action waits that long) in the same signed values as the Destination and the Cap
|
|
733
759
|
const cardWait = typeof v.card?.askWait === 'string' ? v.card.askWait.trim().toLowerCase() : '';
|
|
734
|
-
const
|
|
735
|
-
const parsedNow = proseNow.ok ? parseSignedText(proseNow.text) : null;
|
|
760
|
+
const parsedNow = readPlanTexts(join(dir, v.plan)).parsed;
|
|
736
761
|
const actionWait = parsedNow && parsedNow.ok && parsedNow.arbiter.asks.length === 0 && parsedNow.arbiter.sends.length === 1 && parseWaitMs(cardWait) !== null ? { line: String(parsedNow.arbiter.sends[0].line), wait: cardWait } : null;
|
|
737
762
|
if (pot.split.spentUsd > 0 || (actionWait !== null && parseWaitMs(actionWait.wait) !== DEFAULT_ACTION_WAIT_MS)) {
|
|
738
763
|
const parsed = parsedNow;
|
|
@@ -770,14 +795,14 @@ export function createAuthor(opts) {
|
|
|
770
795
|
const dir = dd === null ? null : join(dd, id);
|
|
771
796
|
const v = dir === null ? null : /** @type {any} */ (readDraft(dir, id, keys));
|
|
772
797
|
if (dir === null || v === null || v.card === null) return { status: 404, body: { ok: false, refused: 'no-such-draft' } };
|
|
773
|
-
if (
|
|
798
|
+
if (REVISE_PHASES.includes(v.phase)) return { status: 409, body: { ok: false, refused: 'draft-live', say: 'A plan is already being drafted. Wait for it.' } };
|
|
774
799
|
if (v.phase === 'questions-open') return { status: 409, body: { ok: false, refused: 'question-open', say: 'A question the plan raised is still open. Answer it first; it is not a revise.' } };
|
|
775
800
|
// only a draft whose first plan was green has revises (`withRevises` is the one reader that sets them)
|
|
776
801
|
if (!Array.isArray(v.revises)) return { status: 409, body: { ok: false, refused: 'not-revisable', say: `This draft is ${v.phase}, so it cannot be revised. Draft again from the card.` } };
|
|
777
802
|
if (v.revisesLeft <= 0) return { status: 409, body: { ok: false, refused: 'no-revises-left', say: `This draft has used its ${MAX_REVISES} revises. Start over: it keeps the fields and gives ${MAX_REVISES} new revises.` } };
|
|
778
803
|
if (childRunning(dir)) return { status: 409, body: { ok: false, refused: 'draft-live', say: 'The draft process is still finishing. Try again in a moment.' } };
|
|
779
804
|
if (draftingSpent(dir).missingEarlier) return { status: 400, body: { ok: false, refused: 'earlier-missing', say: EARLIER_MISSING_SAY } };
|
|
780
|
-
const vet = vetCard(body, loaded, draftedSoFar(dir, v.card),
|
|
805
|
+
const vet = vetCard(body, loaded, draftedSoFar(dir, v.card), readJsonFile(dir, RUN_OF_FILE)?.flow);
|
|
781
806
|
if (!vet.ok) return vet.reply;
|
|
782
807
|
for (const other of listIds()) {
|
|
783
808
|
if (other === id) continue;
|
|
@@ -788,7 +813,7 @@ export function createAuthor(opts) {
|
|
|
788
813
|
}
|
|
789
814
|
const n = Math.max(0, ...v.revises.map((x) => x.n)) + 1;
|
|
790
815
|
const proseFile = join(dir, `prose-${n}.txt`);
|
|
791
|
-
writeFileSync(join(dir,
|
|
816
|
+
writeFileSync(join(dir, cardFileName(n)), `${JSON.stringify(vet.card, null, 2)}\n`, { mode: 0o600, flag: 'wx' });
|
|
792
817
|
writeFileSync(proseFile, vet.prose, { mode: 0o600, flag: 'wx' });
|
|
793
818
|
let child;
|
|
794
819
|
try {
|
|
@@ -796,7 +821,7 @@ export function createAuthor(opts) {
|
|
|
796
821
|
bin,
|
|
797
822
|
argv: ['draft', proseFile, '--out', join(dir, `draft-${n}`), '--root', realpathSync(root), '--name', vet.card.flowName, ...carryArgv(dir, v.revises.map((x) => x.n)), ...modelArgv(vet.card), ...actionArgv(vet.card)],
|
|
798
823
|
env: loaded.env,
|
|
799
|
-
logPath: join(dir,
|
|
824
|
+
logPath: join(dir, draftLogName('revise', n)),
|
|
800
825
|
});
|
|
801
826
|
} catch (e) {
|
|
802
827
|
return { status: 500, body: { ok: false, refused: 'spawn', say: `The revise could not be started (${/** @type {any} */ (e)?.code ?? 'error'}). Nothing was spent.`, draftId: id } };
|
|
@@ -876,7 +901,7 @@ export function createAuthor(opts) {
|
|
|
876
901
|
const jobWithAction = act !== undefined && act.action === 'known' && typeof act.actionLine === 'string' && act.actionLine !== '' ? `${baseJob.replace(/\s+$/, '')}\n${act.actionLine}` : baseJob;
|
|
877
902
|
const grown = applyAnswers(jobWithAction, all);
|
|
878
903
|
if (grown.added !== adds.length) return { status: 409, body: { ok: false, refused: 'no-such-line', say: 'An answer is about a job line the card no longer has. Draft again from the card. Nothing was signed.' } };
|
|
879
|
-
const vet = vetCard({ ...v.card, job: grown.job }, loaded, draftedSoFar(dir, v.card),
|
|
904
|
+
const vet = vetCard({ ...v.card, job: grown.job }, loaded, draftedSoFar(dir, v.card), readJsonFile(dir, RUN_OF_FILE)?.flow);
|
|
880
905
|
if (!vet.ok) return vet.reply;
|
|
881
906
|
for (const other of listIds()) {
|
|
882
907
|
if (other === id) continue;
|
|
@@ -920,12 +945,12 @@ export function createAuthor(opts) {
|
|
|
920
945
|
if (dir === null || v === null || v.card === null) return { status: 404, body: { ok: false, refused: 'no-such-draft' } };
|
|
921
946
|
if (v.phase !== 'green' || typeof v.plan !== 'string' || !Array.isArray(v.revises)) return { status: 409, body: { ok: false, refused: 'not-green', say: `This draft is ${v.phase}, not a finished plan, so its checks cannot be changed.` } };
|
|
922
947
|
const b = body && typeof body === 'object' ? body : {};
|
|
923
|
-
if (b.op
|
|
948
|
+
if (!isRowChoice(b.op)) return { status: 400, body: { ok: false, refused: 'bad-choice', say: 'That is not one of the choices. Nothing was changed.' } };
|
|
924
949
|
if (typeof b.key !== 'string' || b.key === '' || b.key.length > 200) return { status: 400, body: { ok: false, refused: 'bad-row', say: 'That check is not on the list. Nothing was changed.' } };
|
|
925
950
|
if (childRunning(dir)) return { status: 409, body: { ok: false, refused: 'draft-live', say: 'The draft process is still finishing. Try again in a moment.' } };
|
|
926
951
|
// the plan was drafted with questions on, unless it is the redraft after answers (it never asks); a plan made by a Drop or an Add keeps the one it came from
|
|
927
952
|
const cur = PLAN_DIR_RE.exec(v.plan)?.[1];
|
|
928
|
-
const marker = cur === undefined ? null :
|
|
953
|
+
const marker = cur === undefined ? null : readRedraftMarker(dir, Number(cur));
|
|
929
954
|
const asks = marker === null ? true : (marker.rowEdit ? marker.rowEdit.asks !== false : false);
|
|
930
955
|
const planDir = join(dir, v.plan);
|
|
931
956
|
const made = rowEditPlan({ planDir, op: b.op, key: b.key, asks });
|
|
@@ -933,7 +958,7 @@ export function createAuthor(opts) {
|
|
|
933
958
|
const n = Math.max(0, ...v.revises.map((x) => x.n)) + 1;
|
|
934
959
|
const at = new Date().toISOString();
|
|
935
960
|
const newDir = join(dir, `draft-${n}`);
|
|
936
|
-
const
|
|
961
|
+
const proseText = readPlanTexts(planDir).proseText;
|
|
937
962
|
try {
|
|
938
963
|
claimPlanDir(newDir);
|
|
939
964
|
if (Object.keys(made.pages).length > 0) claimPlanDir(join(newDir, 'pages'));
|
|
@@ -944,8 +969,8 @@ export function createAuthor(opts) {
|
|
|
944
969
|
kind: 'draft', provider: null, price: null, model: readModelRecord(planDir)?.model ?? null, modelReturned: null, tokens: null, costUsd: 0, rounds: 0, calls: 0, spendComplete: true, stop: null, budgetUsd: null, startedAt: at, wallMs: 0,
|
|
945
970
|
});
|
|
946
971
|
writePlanFiles(dir, {
|
|
947
|
-
[
|
|
948
|
-
[
|
|
972
|
+
[cardFileName(n)]: `${JSON.stringify(v.card, null, 2)}\n`, [`prose-${n}.txt`]: proseText ?? '',
|
|
973
|
+
[redraftFileName(n)]: `${JSON.stringify({ fromPlan: v.plan, answers: [], rowEdit: { op: b.op, key: b.key, at, asks } })}\n`,
|
|
949
974
|
}, { flag: 'wx', mode: 0o600 });
|
|
950
975
|
} catch (e) {
|
|
951
976
|
return { status: 500, body: { ok: false, refused: 'write', say: `The changed plan could not be saved (${/** @type {any} */ (e)?.code ?? 'error'}). Nothing was changed.` } };
|
|
@@ -979,7 +1004,7 @@ export function createAuthor(opts) {
|
|
|
979
1004
|
},
|
|
980
1005
|
|
|
981
1006
|
/**
|
|
982
|
-
* `POST /api/author/:id/abandon`: stop the child (by its recorded pid, only after `
|
|
1007
|
+
* `POST /api/author/:id/abandon`: stop the child (by its recorded pid, only after `childState` says it is ours),
|
|
983
1008
|
* confirm it is gone, then write `abandoned.json`. No further model call; the spend already booked stays booked.
|
|
984
1009
|
* @param {string} id
|
|
985
1010
|
*/
|
|
@@ -991,22 +1016,21 @@ export function createAuthor(opts) {
|
|
|
991
1016
|
const v = dir === null ? null : readDraft(dir, id, keys);
|
|
992
1017
|
if (dir === null || v === null || v.card === null) return { status: 404, body: { ok: false, refused: 'no-such-draft' } };
|
|
993
1018
|
if (FINISHED.has(v.phase)) return { status: 409, body: { ok: false, refused: 'not-abandonable', say: `This draft is already ${v.phase}.` } };
|
|
994
|
-
const
|
|
1019
|
+
const child = childState(dir);
|
|
995
1020
|
let killed = false;
|
|
996
|
-
if (
|
|
997
|
-
const
|
|
998
|
-
const alive = isFwdloopAlive(pid.pid, procStart);
|
|
1021
|
+
if (child) {
|
|
1022
|
+
const { alive } = child;
|
|
999
1023
|
if (alive === null) return { status: 409, body: { ok: false, refused: 'cannot-tell', say: 'The panel cannot tell whether the draft process is still running, so it did not stop anything.' } };
|
|
1000
1024
|
if (alive === true) {
|
|
1001
1025
|
// the child leads its own process group (detached), so one signal to the group reaches it and nothing else
|
|
1002
1026
|
for (const { sig, wait } of [{ sig: 'SIGTERM', wait: KILL_WAIT_MS }, { sig: 'SIGKILL', wait: KILL_HARD_WAIT_MS }]) {
|
|
1003
|
-
try { process.kill(-
|
|
1027
|
+
try { process.kill(-child.pid, /** @type {NodeJS.Signals} */ (sig)); } catch { /* already gone */ }
|
|
1004
1028
|
const t0 = Date.now();
|
|
1005
1029
|
// eslint-disable-next-line no-await-in-loop
|
|
1006
|
-
while (
|
|
1007
|
-
if (
|
|
1030
|
+
while (childAlive(child) === true && Date.now() - t0 < wait) await sleep(25);
|
|
1031
|
+
if (childAlive(child) !== true) break;
|
|
1008
1032
|
}
|
|
1009
|
-
if (
|
|
1033
|
+
if (childAlive(child) === true) {
|
|
1010
1034
|
return { status: 500, body: { ok: false, refused: 'still-running', say: 'The draft process did not stop. Nothing was marked abandoned.' } };
|
|
1011
1035
|
}
|
|
1012
1036
|
killed = true;
|
package/src/panel/authorcard.js
CHANGED
|
@@ -15,7 +15,9 @@ import {
|
|
|
15
15
|
import { isAbsolute, join } from 'node:path';
|
|
16
16
|
|
|
17
17
|
import { checkFlowName } from '../flow.js';
|
|
18
|
+
import { isFlowType } from '../declaration.js';
|
|
18
19
|
import { sameRuleWords } from '../blockpick.js';
|
|
20
|
+
import { isShapeAsk } from '../pageask.js';
|
|
19
21
|
import { isColumnChoiceRule, columnChoiceParts, swapColumnWord } from '../sheetoffer.js';
|
|
20
22
|
import { isWebUrl } from '../pagefetch.js';
|
|
21
23
|
import { checkSendDestination } from '../runner.js';
|
|
@@ -24,7 +26,10 @@ import { capTooSmallText } from '../draftspend.js';
|
|
|
24
26
|
import { startableMcpServers, mcpConfigFor } from '../mcp-sources.js';
|
|
25
27
|
import { mcpPickFor } from '../mcp-pick.js';
|
|
26
28
|
import { isTicketListUrl } from '../ticket-draft.js';
|
|
27
|
-
import { validateSchedule } from '../trigger-clock.js';
|
|
29
|
+
import { isClockKind, validateSchedule } from '../trigger-clock.js';
|
|
30
|
+
import { scheduleKindsOf } from '../schedule-choices.js';
|
|
31
|
+
import { shapeOf } from '../schedule-shape.js';
|
|
32
|
+
import { fileTriggerWhy, isFileKind } from '../trigger-files.js';
|
|
28
33
|
import { remoteRefusal } from '../ticket-mcp.js';
|
|
29
34
|
import { readPriceConfig, resolveUsableModel, ceilingCostUsd } from '../provider.js';
|
|
30
35
|
|
|
@@ -193,7 +198,7 @@ export function applyAnswers(job, all) {
|
|
|
193
198
|
} else appends.push({ line: x.line, answer: x.rule });
|
|
194
199
|
}
|
|
195
200
|
const grown = appendAnswersToJob(out, appends);
|
|
196
|
-
const picks = all.filter((x) => (x.ask
|
|
201
|
+
const picks = all.filter((x) => isShapeAsk(x.ask) && !x.left)
|
|
197
202
|
.map((x) => ({ line: x.line, rule: x.ruleNo, check: x.check ?? null, ...(x.own ? { own: true } : {}) }));
|
|
198
203
|
const left = all.filter((x) => x.left).map((x) => ({ line: x.line, rule: x.ruleNo }));
|
|
199
204
|
return { job: grown.job, added: grown.added + done + columns.length, picks, left, columns };
|
|
@@ -261,7 +266,10 @@ export function cardFields(body) {
|
|
|
261
266
|
...(str(b.flowType).trim() !== '' && str(b.flowType).trim() !== 'plain' ? { flowType: str(b.flowType).trim(), mcp: str(b.mcp).trim() } : {}),
|
|
262
267
|
// M13 piece 5 (item 7): the Schedule row, signed with the job. Absent = By hand (no schedule.json). Only the typed fields are kept.
|
|
263
268
|
...(b.schedule && typeof b.schedule === 'object' && !Array.isArray(b.schedule)
|
|
264
|
-
? { schedule: b.schedule.kind === 'new-ticket' ? { kind: 'new-ticket' } : {
|
|
269
|
+
? { schedule: b.schedule.kind === 'new-ticket' ? { kind: 'new-ticket' } : {
|
|
270
|
+
// only the typed fields the page sent, so a file choice carries no time and a clock choice no file (`shapeOf` refuses a field the kind does not take)
|
|
271
|
+
kind: b.schedule.kind, ...Object.fromEntries(['hour', 'minute', 'day', 'role', 'path', 'folder'].filter((k) => b.schedule[k] !== undefined).map((k) => [k, b.schedule[k]])),
|
|
272
|
+
} } : {}),
|
|
265
273
|
};
|
|
266
274
|
}
|
|
267
275
|
|
|
@@ -475,7 +483,7 @@ export function checkCard(card, { root, keys = [], home, runOf }) {
|
|
|
475
483
|
// M13 piece 4: the Flow type and its MCP. MCP and Tickets name an MCP fwdloop can start whose tools have been checked (R1: the job gets every tool of the newest OK check;
|
|
476
484
|
// never a started server here). Tickets needs the ticket list address as an Inputs line; MCP may have none.
|
|
477
485
|
const flow = /** @type {{flowType?: string, mcp?: string}} */ (card).flowType ?? 'plain';
|
|
478
|
-
if (!
|
|
486
|
+
if (!isFlowType(flow)) no('flowType', 'Flow type must be plain, MCP or Tickets MCP.');
|
|
479
487
|
else if (flow !== 'plain') {
|
|
480
488
|
const server = String(/** @type {any} */ (card).mcp ?? '');
|
|
481
489
|
if (server === '') no('mcp', 'Pick an MCP.');
|
|
@@ -490,11 +498,16 @@ export function checkCard(card, { root, keys = [], home, runOf }) {
|
|
|
490
498
|
// M13 piece 5 (item 7): the Schedule row. Every day at HH:MM for any flow type; When a new ticket arrives only for Tickets. The trigger itself (list, server, tool) is filled from the signed job at sign.
|
|
491
499
|
const sched = /** @type {any} */ (card).schedule;
|
|
492
500
|
if (sched !== undefined) {
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
501
|
+
// M20 am5 item 1: the kinds a flow type offers are the one list (src/schedule-choices.js); a file or folder choice is checked as the Run card checks it (src/schedule-shape.js)
|
|
502
|
+
if (sched.kind === 'new-ticket' && flow !== 'tickets') no('schedule', 'Only a Tickets MCP job can start on a new ticket.');
|
|
503
|
+
else if (sched.kind === 'hand' || !scheduleKindsOf(flow).includes(sched.kind)) no('schedule', 'Pick when it runs from the choices.');
|
|
504
|
+
else if (isClockKind(sched.kind)) {
|
|
496
505
|
try { validateSchedule(sched); } catch { no('schedule', 'The time must be an hour 0-23 and a minute 0-59, like 09:00.'); }
|
|
497
|
-
} else
|
|
506
|
+
} else if (isFileKind(sched.kind)) {
|
|
507
|
+
const shaped = shapeOf(sched, parseInputLines(card.inputs).filter((i) => !isWebUrl(i.path)).map((i) => i.role));
|
|
508
|
+
if (!shaped.ok) no('schedule', shaped.say.replace(/ Nothing was changed\.$/, ''));
|
|
509
|
+
else if (shaped.trigger !== null) { const why = fileTriggerWhy(/** @type {any} */ (shaped.trigger)); if (why !== null) no('schedule', why); }
|
|
510
|
+
}
|
|
498
511
|
}
|
|
499
512
|
|
|
500
513
|
// inputs: one `name: path` per line; a role and a path on every line, no repeated role; each path a readable regular file (realpath)
|
package/src/panel/authorflows.js
CHANGED
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
import { lstatSync, realpathSync } from 'node:fs';
|
|
14
14
|
import { join } from 'node:path';
|
|
15
15
|
|
|
16
|
-
import { scrub } from '../
|
|
16
|
+
import { scrub } from '../draftfiles.js';
|
|
17
17
|
import { ticketSourcesOf } from '../ticket-draft.js';
|
|
18
18
|
import { flowTypeOf } from '../declaration.js';
|
|
19
|
-
import { endRow, readHistory } from '../books.js';
|
|
19
|
+
import { endRow, readHistory, isGoodEnding } from '../books.js';
|
|
20
20
|
import { canFlowRun, willNotRunSay } from '../canrun.js';
|
|
21
21
|
import { loadCatalogue } from '../catalogue.js';
|
|
22
22
|
import { ConfigError, readConfig } from '../config.js';
|
|
@@ -141,7 +141,7 @@ export function createFlowsDoor(opts) {
|
|
|
141
141
|
if (!r.ok) continue;
|
|
142
142
|
const end = endRow(history, r.runDir, id);
|
|
143
143
|
if (end === null) continue; // not ended (running, parked, died): neither green nor not green
|
|
144
|
-
if (end.outcome
|
|
144
|
+
if (isGoodEnding(end.outcome)) {
|
|
145
145
|
green += 1;
|
|
146
146
|
passed.push({ runId: id, ...runValuesOf(read, name, r.runDir), sources: sourcesOf(r.runDir, roles, pageAddressesOf(read.arbiter)) });
|
|
147
147
|
} else notGreen += 1;
|
|
@@ -14,10 +14,10 @@ import { realpathSync } from 'node:fs';
|
|
|
14
14
|
import { dirname, join } from 'node:path';
|
|
15
15
|
import { userInfo } from 'node:os';
|
|
16
16
|
|
|
17
|
-
import { scrub } from '../
|
|
17
|
+
import { scrub } from '../draftfiles.js';
|
|
18
18
|
import { loadCatalogue } from '../catalogue.js';
|
|
19
19
|
import { changeSentence, checkFlowName, readPlan, readRunPlan, resolveRunDir } from '../flow.js';
|
|
20
|
-
import { readResumeLock } from '../liveness.js';
|
|
20
|
+
import { lockMayBeHeld, readResumeLock } from '../liveness.js';
|
|
21
21
|
import { auditSpend } from '../runner.js';
|
|
22
22
|
import {
|
|
23
23
|
flowValues, pickRunValues, valuesHash, writeRunValues,
|
|
@@ -68,7 +68,7 @@ export function createResumeDoor(opts) {
|
|
|
68
68
|
if (controls.canStop && !controls.atAsk) return no(409, { refused: 'running', say: 'This run is still running. Stop it first, or wait for it to end; a Resume is for a run that stopped.' });
|
|
69
69
|
if (!controls.canResume) return no(409, { refused: 'not-resumable', say: 'This run did not stop at its cap or by Stop, so there is nothing to resume. Start a new run instead.' });
|
|
70
70
|
const lock = readResumeLock(rd.runDir);
|
|
71
|
-
if (lock.state
|
|
71
|
+
if (lockMayBeHeld(lock.state)) return no(409, { refused: 'already-resuming', say: 'This run is already carrying on. Wait a moment, then look again.' });
|
|
72
72
|
const picked = pickRunValues(rd.runDir);
|
|
73
73
|
if (!picked.ok) return no(409, { refused: 'values', say: `${picked.red}. Nothing was signed.` });
|
|
74
74
|
const base = picked.none ? flowValues(read.arbiter) : picked.record.values;
|