fwdloop 0.38.0 → 0.40.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/README.md +6 -9
- package/bin/fwdloop +21 -19
- package/package.json +1 -1
- package/src/ask.js +70 -148
- package/src/audit-fold.js +6 -5
- package/src/auditchecks.js +6 -4
- package/src/authoring.js +32 -60
- package/src/blockasks.js +2 -1
- package/src/blockassemble.js +15 -3
- package/src/blockdraft.js +2 -2
- package/src/blockpick.js +42 -16
- package/src/books.js +237 -12
- package/src/checkblock.js +24 -44
- package/src/checklistsign.js +25 -3
- package/src/checklook.js +3 -1
- package/src/checkpick.js +6 -77
- 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 +18 -12
- 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 +106 -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 +186 -188
- package/src/panel/index.html +139 -115
- 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/plain-checks.js +1 -1
- 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 +380 -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 +71 -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 +50 -16
- 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/types/drafter.d.ts
CHANGED
|
@@ -364,7 +364,7 @@ export function draft({ proseText, slot, model, provider: injected, rates: injec
|
|
|
364
364
|
ids: string[];
|
|
365
365
|
} | null | undefined;
|
|
366
366
|
mcpServers?: string[] | undefined;
|
|
367
|
-
flowType?: "
|
|
367
|
+
flowType?: "mcp" | "plain" | "tickets" | undefined;
|
|
368
368
|
mcp?: any;
|
|
369
369
|
actionMode?: "check" | "known" | null | undefined;
|
|
370
370
|
}): Promise<{
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* M20 am3 item 12: the ONE reader of one plan folder's verdict, from its files (`spec.hash`, `scrub-leak.red`, `log.json`). Green = a
|
|
3
|
+
* non-empty spec.hash; red = a leak marker or a log that says not ok (`reds` = the log's own reds, then the marker's text); none otherwise.
|
|
4
|
+
* `hashFile` and `leak` are the raw reads, so sign can name a missing or refused file in its own words. Callers scrub `reds` themselves.
|
|
5
|
+
* @param {string} dir the folder that holds the plan folder @param {string} [rel] `draft`, `draft-<n>` or `.` (the plan folder itself)
|
|
6
|
+
* @returns {{verdict: 'green'|'red'|'none', hash: string|null, hashFile: ReturnType<typeof readFileInside>, leak: ReturnType<typeof readFileInside>, log: any, reds: string[]}}
|
|
7
|
+
*/
|
|
8
|
+
export function draftVerdict(dir: string, rel?: string): {
|
|
9
|
+
verdict: "green" | "red" | "none";
|
|
10
|
+
hash: string | null;
|
|
11
|
+
hashFile: ReturnType<typeof readFileInside>;
|
|
12
|
+
leak: ReturnType<typeof readFileInside>;
|
|
13
|
+
log: any;
|
|
14
|
+
reds: string[];
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* The questions a plan folder raised and the answers on disk, READ from its files — the ONE reader (the panel's phase reader, the sign
|
|
18
|
+
* checks and the page all use it). `questions` = [{ k, line, question, answer|null }], `open` = those with no answer. A blank or unreadable
|
|
19
|
+
* answer file counts as no answer. No questions file = `{ questions: [], open: [] }`.
|
|
20
|
+
* @param {string} planDir
|
|
21
|
+
* A question the page look raised (M10 piece 3) also carries `source: 'look'`, `ask` ('reading' | 'cant-check'), `ruleNo`, `ruleText` and `proposal`; an answer file carries `at`.
|
|
22
|
+
* @returns {{ questions: {k:number, line:number, question:string, answer:string|null, at?:string, rule?:string|null, choice?:'agree'|'drop'|'rule'|'column', source?:string, ask?:string, ruleNo?:number, ruleText?:string, proposal?:string|null, check?:Record<string, any>, pairRule?:number, columns?:string[], readings?:Record<string,string>}[], open: {k:number, line:number, question:string, answer:null}[] }}
|
|
23
|
+
*/
|
|
24
|
+
export function readQuestions(planDir: string): {
|
|
25
|
+
questions: {
|
|
26
|
+
k: number;
|
|
27
|
+
line: number;
|
|
28
|
+
question: string;
|
|
29
|
+
answer: string | null;
|
|
30
|
+
at?: string;
|
|
31
|
+
rule?: string | null;
|
|
32
|
+
choice?: "agree" | "drop" | "rule" | "column";
|
|
33
|
+
source?: string;
|
|
34
|
+
ask?: string;
|
|
35
|
+
ruleNo?: number;
|
|
36
|
+
ruleText?: string;
|
|
37
|
+
proposal?: string | null;
|
|
38
|
+
check?: Record<string, any>;
|
|
39
|
+
pairRule?: number;
|
|
40
|
+
columns?: string[];
|
|
41
|
+
readings?: Record<string, string>;
|
|
42
|
+
}[];
|
|
43
|
+
open: {
|
|
44
|
+
k: number;
|
|
45
|
+
line: number;
|
|
46
|
+
question: string;
|
|
47
|
+
answer: null;
|
|
48
|
+
}[];
|
|
49
|
+
};
|
|
50
|
+
/** Literal (never RegExp) key scrub; a secret under 8 chars is skipped so it can't blank ordinary text. */
|
|
51
|
+
export function scrub(text: any, secrets: any): any;
|
|
52
|
+
/**
|
|
53
|
+
* M20 am3 item 10: the ONE reader of a plan folder's `not-checked.json`. `notChecked` is the file's own list as it is (any type; the callers keep what they
|
|
54
|
+
* accept of it: `notCheckedBlock`/`notCheckedView` filter strings, the rebuild keeps strings), `by` the tag of each line when the file holds an object, else null.
|
|
55
|
+
* A missing, refused, unparseable or non-object file reads as `{notChecked: undefined, by: null}` (a plan from before amendment 25 has none).
|
|
56
|
+
* @param {string} dir the folder that holds the plan folder @param {string} [rel] `draft`, `draft-<n>` or `.` (the plan folder itself)
|
|
57
|
+
* @returns {{notChecked: any, by: Record<string, any>|null}}
|
|
58
|
+
*/
|
|
59
|
+
export function readNotCheckedFile(dir: string, rel?: string): {
|
|
60
|
+
notChecked: any;
|
|
61
|
+
by: Record<string, any> | null;
|
|
62
|
+
};
|
|
63
|
+
/** @param {string} dir the session folder @param {number} n @returns {Record<string, any>|null} */
|
|
64
|
+
export function readRedraftMarker(dir: string, n: number): Record<string, any> | null;
|
|
65
|
+
/**
|
|
66
|
+
* M20 am3e item 20: a draft plan folder's job text and steps, the ONE reader. `proseText` is prose.txt as it is (null when missing or refused), `parsed` the signed-text
|
|
67
|
+
* parse of it (`parseSignedText`'s result, ok or not; null when there is no prose), `declaration` declaration.json as an object (null when missing, refused, not JSON or not
|
|
68
|
+
* an object). Each caller keeps its own sentence for what it does when one is null. (A flow folder with a signature is `readFlow`'s; a plan that falls back to
|
|
69
|
+
* declaration.rejected.json is src/panel/author.js `stepListOf`'s own question.)
|
|
70
|
+
* @param {string} dir the folder that holds the plan folder @param {string} [rel] `draft`, `draft-<n>` or `.` (the plan folder itself)
|
|
71
|
+
* @returns {{proseText: string|null, parsed: ReturnType<typeof parseSignedText>|null, declaration: any}}
|
|
72
|
+
*/
|
|
73
|
+
export function readPlanTexts(dir: string, rel?: string): {
|
|
74
|
+
proseText: string | null;
|
|
75
|
+
parsed: ReturnType<typeof parseSignedText> | null;
|
|
76
|
+
declaration: any;
|
|
77
|
+
};
|
|
78
|
+
export const SPEC_HASH_FILE: "spec.hash";
|
|
79
|
+
/** Written when the end sweep finds a key in the draft dir; sign refuses a dir that has it. */
|
|
80
|
+
export const LEAK_MARKER_FILE: "scrub-leak.red";
|
|
81
|
+
export const QUESTIONS_FILE: "questions.json";
|
|
82
|
+
export function ANSWER_FILE(k: any): string;
|
|
83
|
+
/** the drafter's own "Not checked" reading, kept in a plan folder (information only; never in the readout, so never in the hash) */
|
|
84
|
+
export const NOT_CHECKED_FILE: "not-checked.json";
|
|
85
|
+
export function cardFileName(n?: number): string;
|
|
86
|
+
export function readCard(dir: string, n?: number): Record<string, any> | null;
|
|
87
|
+
export function redraftFileName(n: number): string;
|
|
88
|
+
import { readFileInside } from './inside.js';
|
|
89
|
+
import { parseSignedText } from './signed-text.js';
|
package/types/draftspend.d.ts
CHANGED
|
@@ -18,6 +18,12 @@ export function readDraftSpend(dir: string): Record<string, any> | null;
|
|
|
18
18
|
* @returns {Record<string, any>[]}
|
|
19
19
|
*/
|
|
20
20
|
export function readDirSpendRows(dir: string): Record<string, any>[];
|
|
21
|
+
/**
|
|
22
|
+
* M20 am3 item 12: the ONE reader of a session folder's `started-over-from.json`: the `startedOverFrom` value it holds, or null when
|
|
23
|
+
* there is no file, it is unreadable, or it holds none. (A value that is not a session id is the caller's to judge.)
|
|
24
|
+
* @param {string} sessionDir @returns {unknown}
|
|
25
|
+
*/
|
|
26
|
+
export function readStartedOverFrom(sessionDir: string): unknown;
|
|
21
27
|
/**
|
|
22
28
|
* M4d amendment 16 item 1: what ALL of a job's drafting spent — the one writer of that total. A panel draft's session folder holds one plan
|
|
23
29
|
* folder per draft (`draft/`, `draft-<n>/` for each revise and the redraft after answers); each is read by `readDirSpendRows` and priced by
|
|
@@ -69,9 +75,77 @@ export function draftHoldUsd(proseText: string, outDir: string, ceilingUsd: numb
|
|
|
69
75
|
* @param {'drafting'|'run'} kind @param {number} capUsd @param {number} minUsd @param {string} modelId
|
|
70
76
|
*/
|
|
71
77
|
export function capTooSmallText(kind: "drafting" | "run", capUsd: number, minUsd: number, modelId: string): string;
|
|
78
|
+
/**
|
|
79
|
+
* The ONE writer of the step lines. `emit(kind, record)` prints one line (the CLI passes stderr). Each call is given the result so far
|
|
80
|
+
* (`log`, as log.json will hold it) and writes a start for every step not yet started, and an end for every step but the last (the running one);
|
|
81
|
+
* `final` ends them all. A step is keyed by its `id`: written once.
|
|
82
|
+
* @param {(kind: 'step-start'|'step-end', rec: Record<string, any>) => void} emit
|
|
83
|
+
*/
|
|
84
|
+
export function makeStepWriter(emit: (kind: "step-start" | "step-end", rec: Record<string, any>) => void): (/** @type {any} */ log: any, /** @type {any} */ declaration: any, final: any) => void;
|
|
85
|
+
/**
|
|
86
|
+
* Fold the step lines of `<dir>/child.log` into one record per step, oldest first. A line that cannot be parsed is skipped.
|
|
87
|
+
* @param {string} dir the draft folder @param {string} [file] the child's log: `child.log` (the first draft), `revise-<n>.log` or `redraft-<n>.log`
|
|
88
|
+
* @returns {{no: number, id: string, label: string, status: 'running'|'done'|'failed', startedAt: string, endedAt: string|null, wallMs: number|null}[]}
|
|
89
|
+
*/
|
|
90
|
+
export function readDraftSteps(dir: string, file?: string): {
|
|
91
|
+
no: number;
|
|
92
|
+
id: string;
|
|
93
|
+
label: string;
|
|
94
|
+
status: "running" | "done" | "failed";
|
|
95
|
+
startedAt: string;
|
|
96
|
+
endedAt: string | null;
|
|
97
|
+
wallMs: number | null;
|
|
98
|
+
}[];
|
|
99
|
+
/** M:SS, the ONE spelling of a drafting time ("took 0:42", "Drafting so far: 2:00"). @param {number} ms @returns {string} */
|
|
100
|
+
export function mmss(ms: number): string;
|
|
101
|
+
/**
|
|
102
|
+
* The drafting's whole time: the first step's start to the last step's end; `null` when no step has both times.
|
|
103
|
+
* @param {{startedAt: string, endedAt: string|null}[]} steps `readDraftSteps`' records
|
|
104
|
+
* @returns {number|null}
|
|
105
|
+
*/
|
|
106
|
+
export function draftWallMs(steps: {
|
|
107
|
+
startedAt: string;
|
|
108
|
+
endedAt: string | null;
|
|
109
|
+
}[]): number | null;
|
|
110
|
+
/**
|
|
111
|
+
* The ONE owner of the times on the chat's drafting list. While the draft runs the list is the started steps (`no` order, latest label), each `time` "M:SS so far"
|
|
112
|
+
* (a finished one "took M:SS") and `draftSoFar` is "Drafting so far: M:SS". After it ends `list` is `draftStepList`'s list unchanged, each line taking the times of the
|
|
113
|
+
* step line with the same `id` (the first unused, in order); a line no step line matches (thinking, a Fix note) has no time. No lines = no times, `draftSoFar` null.
|
|
114
|
+
* A revise or answer redraft is read from its own log (`file`); its one `plan` line (`reviseStepList`) takes the draft's whole time (`wholeId`).
|
|
115
|
+
* @param {{dir: string, running: boolean, list: any[]|null, nowMs?: number, file?: string, wholeId?: string}} p `dir` = the draft folder, `file` = the child's log in it, `list` = draftStepList's (or reviseStepList's) list or null
|
|
116
|
+
* @returns {{list: any[]|null, draftSoFar: string|null}}
|
|
117
|
+
*/
|
|
118
|
+
export function withDraftTimes({ dir, running, list, nowMs, file, wholeId }: {
|
|
119
|
+
dir: string;
|
|
120
|
+
running: boolean;
|
|
121
|
+
list: any[] | null;
|
|
122
|
+
nowMs?: number;
|
|
123
|
+
file?: string;
|
|
124
|
+
wholeId?: string;
|
|
125
|
+
}): {
|
|
126
|
+
list: any[] | null;
|
|
127
|
+
draftSoFar: string | null;
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* The plan card's one line: "Drafted in M:SS · $X". The time is the session's first step start to its last step end across ALL its drafts (the first, each revise,
|
|
131
|
+
* each answer redraft); the money is the session's drafting spend (`draftingSpent`, handed in as `spentUsd`; "at least" when `complete` is false). `null` when no
|
|
132
|
+
* step line has a time or the spend is not a number (a Reuse, an old draft, a session that never knew its cost): nothing is made up.
|
|
133
|
+
* @param {{dir: string, spentUsd: number|null, complete: boolean}} p `dir` = the session's draft folder
|
|
134
|
+
* @returns {string|null}
|
|
135
|
+
*/
|
|
136
|
+
export function draftedLine({ dir, spentUsd, complete }: {
|
|
137
|
+
dir: string;
|
|
138
|
+
spentUsd: number | null;
|
|
139
|
+
complete: boolean;
|
|
140
|
+
}): string | null;
|
|
72
141
|
export const DRAFT_SPEND_FILE: "draft-spend.json";
|
|
73
142
|
/** M4d am21 item 2: the one sentence for a Start over (or revise, or sign) whose chain names an earlier draft that is gone. */
|
|
74
143
|
export const EARLIER_MISSING_SAY: "An earlier draft of this job is missing, so its spend can't be counted.";
|
|
75
144
|
/** The file a Start over's session folder carries to name the session it started over from (written once by src/panel/author.js). */
|
|
76
145
|
export const STARTED_OVER_FILE: "started-over-from.json";
|
|
77
146
|
export function usdText(n: number): string;
|
|
147
|
+
export const STEP_LINE_RE: RegExp;
|
|
148
|
+
export const STEP_LINE_PREFIXES: string[];
|
|
149
|
+
/** a running time moves in 30 s steps, never a ticking clock (the page polls often; the words change every 30 s) */
|
|
150
|
+
export const TIME_STEP_MS: 30000;
|
|
151
|
+
export function stepped(ms: number): number;
|
package/types/flow.d.ts
CHANGED
|
@@ -126,63 +126,18 @@ export function claimRunId(flowDir: string): {
|
|
|
126
126
|
red: string;
|
|
127
127
|
};
|
|
128
128
|
/**
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
* to somewhere inside `realpath(baseDir)` — the second check alone also
|
|
135
|
-
* catches a symlinked ANCESTOR directory partway down `relPath` (e.g.
|
|
136
|
-
* `asks/` itself replaced by a symlink to an outside directory), the same
|
|
137
|
-
* shape `readFlow`'s own `runs/` check and `resolveRunDir` already apply one
|
|
138
|
-
* level up. A path that does not exist yet is reported as `missing: true`
|
|
139
|
-
* (never a red) so every existing caller keeps its own "not written yet"
|
|
140
|
-
* behaviour unchanged.
|
|
141
|
-
*
|
|
142
|
-
* @param {string} baseDir
|
|
143
|
-
* @param {string} relPath
|
|
144
|
-
* @returns {{ok:true, full:string}|{ok:false, missing:true}|{ok:false, missing:false, red:string}}
|
|
129
|
+
* M20 am1 item 4: the ONE reader of a DRAFT's `log.json` (`<dir>/<rel>/log.json`, or `<dir>/log.json` with no `rel`): what the drafter kept of its rounds,
|
|
130
|
+
* its `checkCard` and its `action`. The run's `log.json` is another file, read only by `readLog` (src/books.js). `null` when missing, refused by the
|
|
131
|
+
* gateway, unparseable or not an object (a torn write), never a thrown error.
|
|
132
|
+
* @param {string} dir @param {string} [rel] a plan folder under `dir` (`draft`, `draft-<n>`)
|
|
133
|
+
* @returns {any|null}
|
|
145
134
|
*/
|
|
146
|
-
export function
|
|
147
|
-
ok: true;
|
|
148
|
-
full: string;
|
|
149
|
-
} | {
|
|
150
|
-
ok: false;
|
|
151
|
-
missing: true;
|
|
152
|
-
} | {
|
|
153
|
-
ok: false;
|
|
154
|
-
missing: false;
|
|
155
|
-
red: string;
|
|
156
|
-
};
|
|
135
|
+
export function readDraftLog(dir: string, rel?: string): any | null;
|
|
157
136
|
/**
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
* @param {string} baseDir
|
|
161
|
-
* @param {string} relPath
|
|
162
|
-
* @returns {{ok:true, text:string}|{ok:false, missing:true}|{ok:false, missing:false, red:string}}
|
|
137
|
+
* M20 am3 item 12: the ONE tolerant JSON read of a file in a folder, through the gateway: the parsed object, or null when the file is missing, refused,
|
|
138
|
+
* unparseable (a torn write) or not an object. Never throws. @param {string} dir @param {string} rel @returns {any|null}
|
|
163
139
|
*/
|
|
164
|
-
export function
|
|
165
|
-
ok: true;
|
|
166
|
-
text: string;
|
|
167
|
-
} | {
|
|
168
|
-
ok: false;
|
|
169
|
-
missing: true;
|
|
170
|
-
} | {
|
|
171
|
-
ok: false;
|
|
172
|
-
missing: false;
|
|
173
|
-
red: string;
|
|
174
|
-
};
|
|
175
|
-
/**
|
|
176
|
-
* `readdirSync` guarded the same way: refuses (returns `[]`) when `relDir`
|
|
177
|
-
* itself is a symlink or resolves outside `baseDir`, and skips (never
|
|
178
|
-
* follows) any individual entry that is itself a symlink — a directory
|
|
179
|
-
* listing must never hand a caller a name that, joined back onto `relDir`,
|
|
180
|
-
* would escape `baseDir`. `[]` when `relDir` doesn't exist.
|
|
181
|
-
* @param {string} baseDir
|
|
182
|
-
* @param {string} relDir
|
|
183
|
-
* @returns {string[]}
|
|
184
|
-
*/
|
|
185
|
-
export function readdirInside(baseDir: string, relDir: string): string[];
|
|
140
|
+
export function readJsonFile(dir: string, rel: string): any | null;
|
|
186
141
|
/**
|
|
187
142
|
* Write a signed flow to `<root>/<name>/`. Refuses (writing nothing) if the
|
|
188
143
|
* flow name is invalid, if `proseText`/`declaration` don't parse/validate,
|
|
@@ -241,6 +196,29 @@ export function planForReuse({ root, name, runDir, catalogue, }: {
|
|
|
241
196
|
ok: false;
|
|
242
197
|
red: string;
|
|
243
198
|
};
|
|
199
|
+
/**
|
|
200
|
+
* M20 am3 item 1 (as am3a): the ONE rule for "this run ran the job the flow holds now": the run's verified job copy (`readRunJobCopy`), the exact
|
|
201
|
+
* declaration, the prose without its trigger line. `{present:false}` = the run kept no copy (before M6); `{present:true, ok:false, reds}` = a copy that
|
|
202
|
+
* fails its signature; `{present:true, ok:true, same, ...copy}` otherwise.
|
|
203
|
+
* @param {{flowDir: string, runDir: string, catalogue: unknown}} a
|
|
204
|
+
* @returns {{present: false} | {present: true, ok: false, reds: string[]} | ({present: true, same: boolean} & ReadFlowResult & {ok: true})}
|
|
205
|
+
*/
|
|
206
|
+
export function sameJob({ flowDir, runDir, catalogue }: {
|
|
207
|
+
flowDir: string;
|
|
208
|
+
runDir: string;
|
|
209
|
+
catalogue: unknown;
|
|
210
|
+
}): {
|
|
211
|
+
present: false;
|
|
212
|
+
} | {
|
|
213
|
+
present: true;
|
|
214
|
+
ok: false;
|
|
215
|
+
reds: string[];
|
|
216
|
+
} | ({
|
|
217
|
+
present: true;
|
|
218
|
+
same: boolean;
|
|
219
|
+
} & ReadFlowResult & {
|
|
220
|
+
ok: true;
|
|
221
|
+
});
|
|
244
222
|
/**
|
|
245
223
|
* M6 am9: give the run folder `runDir` a verified copy of the plan run `fromRunDir` kept (`job/` write-once, then `plan.json {planOf}`), so the run executes
|
|
246
224
|
* it. Nothing is signed: the bytes already carry a signature, proved here. A failure removes what this call wrote.
|
package/types/index.d.ts
CHANGED
|
@@ -5,6 +5,6 @@ export { signFlow, verifyFlow, canonicalBytes, SIGNATURE_FIELDS } from "./signat
|
|
|
5
5
|
export { validateDeclaration, DECLARATION_FIELDS } from "./declaration.js";
|
|
6
6
|
export { parseCatalogue, loadCatalogue, menu, primitiveFor, resolveEntry, CATALOGUE_FIELDS } from "./catalogue.js";
|
|
7
7
|
export { checkFlowName, checkRunId, resolveRunDir, writeFlow, readFlow, listFlowNames, listRunIds, FLOW_FILES } from "./flow.js";
|
|
8
|
-
export { runFlow, resumeRun, makeParkingAskStep, STRIKE_LIMIT, MAX_ATTEMPTS, readAsk
|
|
9
|
-
export {
|
|
10
|
-
export {
|
|
8
|
+
export { runFlow, resumeRun, makeParkingAskStep, STRIKE_LIMIT, MAX_ATTEMPTS, readAsk } from "./runner.js";
|
|
9
|
+
export { readRunState, readLog, appendAudit, appendHistory, readAudit, readHistory, auditRowTokens, auditRowTools } from "./books.js";
|
|
10
|
+
export { answerAsk, readAskEvidence, writeAskArchive, listArchivedAsks } from "./ask.js";
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* F48 round 3 (docs/logs/FINDINGS.md): the ONE mechanism every book reader
|
|
3
|
+
* in src/ and bin/ routes through to read a file that lives inside a run
|
|
4
|
+
* dir or flow dir — closing the symlink-escape class at the source instead
|
|
5
|
+
* of patching each reader a second time. `resolveInside(baseDir, relPath)`
|
|
6
|
+
* requires the target to both (a) not itself be a symlink and (b) realpath
|
|
7
|
+
* to somewhere inside `realpath(baseDir)` — the second check alone also
|
|
8
|
+
* catches a symlinked ANCESTOR directory partway down `relPath` (e.g.
|
|
9
|
+
* `asks/` itself replaced by a symlink to an outside directory), the same
|
|
10
|
+
* shape `readFlow`'s own `runs/` check and `resolveRunDir` already apply one
|
|
11
|
+
* level up. A path that does not exist yet is reported as `missing: true`
|
|
12
|
+
* (never a red) so every existing caller keeps its own "not written yet"
|
|
13
|
+
* behaviour unchanged.
|
|
14
|
+
*
|
|
15
|
+
* `fast` (M20 am9f, change stamps only): skip the realpath checks, keep the symlink refusal. The caller only lists or stamps (never opens) what comes back.
|
|
16
|
+
* @param {string} baseDir
|
|
17
|
+
* @param {string} relPath
|
|
18
|
+
* @param {boolean} [fast]
|
|
19
|
+
* @returns {{ok:true, full:string, stat:{size:number, mtimeMs:number}}|{ok:false, missing:true}|{ok:false, missing:false, red:string}}
|
|
20
|
+
*/
|
|
21
|
+
export function resolveInside(baseDir: string, relPath: string, fast?: boolean): {
|
|
22
|
+
ok: true;
|
|
23
|
+
full: string;
|
|
24
|
+
stat: {
|
|
25
|
+
size: number;
|
|
26
|
+
mtimeMs: number;
|
|
27
|
+
};
|
|
28
|
+
} | {
|
|
29
|
+
ok: false;
|
|
30
|
+
missing: true;
|
|
31
|
+
} | {
|
|
32
|
+
ok: false;
|
|
33
|
+
missing: false;
|
|
34
|
+
red: string;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* `resolveInside` plus the actual read — every raw-text book reader's one
|
|
38
|
+
* gateway. Same result shape as `resolveInside`, plus `{ok:true, text}`.
|
|
39
|
+
* @param {string} baseDir
|
|
40
|
+
* @param {string} relPath
|
|
41
|
+
* @returns {{ok:true, text:string}|{ok:false, missing:true}|{ok:false, missing:false, red:string}}
|
|
42
|
+
*/
|
|
43
|
+
export function readFileInside(baseDir: string, relPath: string): {
|
|
44
|
+
ok: true;
|
|
45
|
+
text: string;
|
|
46
|
+
} | {
|
|
47
|
+
ok: false;
|
|
48
|
+
missing: true;
|
|
49
|
+
} | {
|
|
50
|
+
ok: false;
|
|
51
|
+
missing: false;
|
|
52
|
+
red: string;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* `readdirSync` guarded the same way: refuses (returns `[]`) when `relDir`
|
|
56
|
+
* itself is a symlink or resolves outside `baseDir`, and skips (never
|
|
57
|
+
* follows) any individual entry that is itself a symlink — a directory
|
|
58
|
+
* listing must never hand a caller a name that, joined back onto `relDir`,
|
|
59
|
+
* would escape `baseDir`. `[]` when `relDir` doesn't exist.
|
|
60
|
+
* @param {string} baseDir
|
|
61
|
+
* @param {string} relDir
|
|
62
|
+
* @param {boolean} [fast] see `resolveInside`
|
|
63
|
+
* @returns {string[]}
|
|
64
|
+
*/
|
|
65
|
+
export function readdirInside(baseDir: string, relDir: string, fast?: boolean): string[];
|
|
66
|
+
/**
|
|
67
|
+
* M20 am9f: one string that changes when any file in `dirs` (folders of `baseDir`, `.` for itself) is written, replaced, renamed or removed: every entry's name, size and mtime.
|
|
68
|
+
* It only lists and stats through `resolveInside`'s `fast` form (a symlink reads `-`, nothing is opened); a missing folder adds nothing.
|
|
69
|
+
* @param {string} baseDir @param {string[]} dirs @returns {string}
|
|
70
|
+
*/
|
|
71
|
+
export function stampsInside(baseDir: string, dirs: string[]): string;
|
package/types/jsonl-append.d.ts
CHANGED
|
@@ -4,3 +4,23 @@ export function ledgerText(file: string): string;
|
|
|
4
4
|
export function appendRow(file: string, row: unknown, options?: {
|
|
5
5
|
mode?: number;
|
|
6
6
|
}): void;
|
|
7
|
+
/** M20 am3 item 12: the ONE tolerant JSONL parse: every line of the text that parses, in order; a blank, torn or unparseable line is skipped. @param {string} text @returns {any[]} */
|
|
8
|
+
export function parseJsonl(text: string): any[];
|
|
9
|
+
/**
|
|
10
|
+
* The ONE reader of a trigger ledger (the files ledger and the schedule ledger): every row on disk that parses, oldest first; a missing file is no rows;
|
|
11
|
+
* a line a crash tore mid-append is skipped (it counts as not written; `appendTriggerLedger` starts each append on a fresh line, so it never glues onto the next row).
|
|
12
|
+
* @param {string} file @param {string} [sig] M9 am20: only the rows of that schedule signing (the one schedule ledger carries every signing's rows); absent = every row
|
|
13
|
+
* @returns {any[]}
|
|
14
|
+
*/
|
|
15
|
+
export function readTriggerLedger(file: string, sig?: string): any[];
|
|
16
|
+
/**
|
|
17
|
+
* The ONE appender of a trigger ledger: write-once by id within a signing (a second row with the same id is not written). `sig` is stamped on the row.
|
|
18
|
+
* @param {string} file @param {{id: string, [k: string]: any}} row @param {string} [sig] @param {{throwIfWritten?: boolean}} [o] `throwIfWritten`: a row already on disk is an error, not `false`
|
|
19
|
+
* @returns {boolean} written
|
|
20
|
+
*/
|
|
21
|
+
export function appendTriggerLedger(file: string, row: {
|
|
22
|
+
id: string;
|
|
23
|
+
[k: string]: any;
|
|
24
|
+
}, sig?: string, { throwIfWritten }?: {
|
|
25
|
+
throwIfWritten?: boolean;
|
|
26
|
+
}): boolean;
|
package/types/learnstore.d.ts
CHANGED
|
@@ -163,5 +163,3 @@ export function hintsForRun({ home, spec, specHash, now }: {
|
|
|
163
163
|
text: string;
|
|
164
164
|
ids: string[];
|
|
165
165
|
} | null;
|
|
166
|
-
/** M8 am4 item 2: a run waiting at an ask has not ended ('paused', or a Stop whose set-aside failed). ONE decider: the runner's run-end tally and the seed both read it. */
|
|
167
|
-
export const NOT_A_RUN_END: Set<string>;
|
package/types/liveness.d.ts
CHANGED
|
@@ -69,6 +69,7 @@ export function readResumeLock(runDir: string): {
|
|
|
69
69
|
export function booksFresh(runDir: string, nowMs?: number): boolean;
|
|
70
70
|
/** The words the runner's refusal uses for a lock it cannot clear; the panel reads the same constant (M4c amendment 3 (e)). */
|
|
71
71
|
export const LOCK_NO_HOLDER: "with no recorded holder";
|
|
72
|
+
export function lockMayBeHeld(state: unknown): boolean;
|
|
72
73
|
declare namespace REAL_PROC {
|
|
73
74
|
function cmdline(pid: number): string;
|
|
74
75
|
function stat(pid: number): string;
|
package/types/pageask.d.ts
CHANGED
|
@@ -71,3 +71,5 @@ export const AGREE_WORDS: string[];
|
|
|
71
71
|
export function isAgree(text: unknown): boolean;
|
|
72
72
|
export function stripAgreeLead(text: string): string;
|
|
73
73
|
export function readingQuestion(n: number, rule: string, reading: string): string;
|
|
74
|
+
export function isShapeAsk(ask: unknown): boolean;
|
|
75
|
+
export function HOW_TO_ANSWER(line: number, agree: boolean): string;
|
package/types/pagebits.d.ts
CHANGED
|
@@ -26,6 +26,9 @@ export const MAX_CURRENCIES: 3;
|
|
|
26
26
|
export const MAX_UNITS: 10;
|
|
27
27
|
export const MAX_UNIT_CHARS: 100;
|
|
28
28
|
export function asList(v: unknown): string[];
|
|
29
|
+
export function isPhraseShape(shape: unknown): boolean;
|
|
30
|
+
export function isLegalCount(c: any): boolean;
|
|
31
|
+
export function isAmountShape(shape: unknown): boolean;
|
|
29
32
|
export function boundOk(shape: string, v: unknown): boolean;
|
|
30
33
|
export function squash(t: string): string;
|
|
31
34
|
export function boundInWords(b: unknown, said: string): boolean;
|
package/types/pagerules.d.ts
CHANGED
|
@@ -48,6 +48,7 @@ export function applyPageRules(text: string, mapping: PageMap, jobLines: {
|
|
|
48
48
|
facts: KeptFact[];
|
|
49
49
|
dropped: Dropped[];
|
|
50
50
|
};
|
|
51
|
+
export function canReadLimit(shape: unknown): shape is "money" | "time";
|
|
51
52
|
export function linesOf(text: string): string[];
|
|
52
53
|
/**
|
|
53
54
|
* what a `~` rule means as a limit (PRD v1.107 Part 5b): the same shape as a signed fact rule
|
package/types/panel/author.d.ts
CHANGED
|
@@ -201,7 +201,7 @@ export function createAuthor(opts: {
|
|
|
201
201
|
flowHash: string;
|
|
202
202
|
sig: string | null;
|
|
203
203
|
armed: boolean;
|
|
204
|
-
armedAt:
|
|
204
|
+
armedAt: any;
|
|
205
205
|
nextSlotMs: number | null;
|
|
206
206
|
lastOutcome: any;
|
|
207
207
|
hasGreenRun: boolean;
|
|
@@ -223,7 +223,7 @@ export function createAuthor(opts: {
|
|
|
223
223
|
flowHash: string;
|
|
224
224
|
sig: string | null;
|
|
225
225
|
armed: boolean;
|
|
226
|
-
armedAt:
|
|
226
|
+
armedAt: any;
|
|
227
227
|
nextSlotMs: number | null;
|
|
228
228
|
lastOutcome: any;
|
|
229
229
|
hasGreenRun: boolean;
|
|
@@ -450,7 +450,7 @@ export function createAuthor(opts: {
|
|
|
450
450
|
body: any;
|
|
451
451
|
};
|
|
452
452
|
/**
|
|
453
|
-
* `POST /api/author/:id/abandon`: stop the child (by its recorded pid, only after `
|
|
453
|
+
* `POST /api/author/:id/abandon`: stop the child (by its recorded pid, only after `childState` says it is ours),
|
|
454
454
|
* confirm it is gone, then write `abandoned.json`. No further model call; the spend already booked stays booked.
|
|
455
455
|
* @param {string} id
|
|
456
456
|
*/
|
|
@@ -485,4 +485,8 @@ export function createAuthor(opts: {
|
|
|
485
485
|
};
|
|
486
486
|
/** 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). */
|
|
487
487
|
export const MAX_REVISES: 2;
|
|
488
|
+
/** 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. */
|
|
489
|
+
export const REVISE_PHASES: readonly string[];
|
|
490
|
+
/** 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. */
|
|
491
|
+
export const NOT_GREEN_PHASES: readonly string[];
|
|
488
492
|
import { thinkingSupport as bareagentThinkingSupport } from '../thinking.js';
|
|
@@ -110,13 +110,7 @@ export function parseInputLines(text: string): {
|
|
|
110
110
|
*/
|
|
111
111
|
export function cardFields(body: any): {
|
|
112
112
|
schedule?: {
|
|
113
|
-
kind: string;
|
|
114
|
-
hour?: undefined;
|
|
115
|
-
minute?: undefined;
|
|
116
|
-
} | {
|
|
117
113
|
kind: any;
|
|
118
|
-
hour: any;
|
|
119
|
-
minute: any;
|
|
120
114
|
} | undefined;
|
|
121
115
|
flowType?: string | undefined;
|
|
122
116
|
mcp?: string | undefined;
|
|
@@ -95,7 +95,7 @@ export function createFlowsDoor(opts: {
|
|
|
95
95
|
} | {
|
|
96
96
|
ok: boolean;
|
|
97
97
|
card: {
|
|
98
|
-
flowType?: "
|
|
98
|
+
flowType?: "mcp" | "plain" | "tickets" | undefined;
|
|
99
99
|
mcp?: any;
|
|
100
100
|
job: string;
|
|
101
101
|
inputs: string;
|
|
@@ -123,7 +123,7 @@ export function createFlowsDoor(opts: {
|
|
|
123
123
|
roles: any;
|
|
124
124
|
pages: Record<string, string>;
|
|
125
125
|
tickets: string[];
|
|
126
|
-
flowType: "
|
|
126
|
+
flowType: "mcp" | "plain" | "tickets";
|
|
127
127
|
mcp: any;
|
|
128
128
|
nextRunId: string;
|
|
129
129
|
lastRunId: string | null;
|
|
@@ -188,7 +188,7 @@ export function createFlowsDoor(opts: {
|
|
|
188
188
|
} | {
|
|
189
189
|
ok: boolean;
|
|
190
190
|
card: {
|
|
191
|
-
flowType?: "
|
|
191
|
+
flowType?: "mcp" | "plain" | "tickets" | undefined;
|
|
192
192
|
mcp?: any;
|
|
193
193
|
job: string;
|
|
194
194
|
inputs: string;
|
|
@@ -216,7 +216,7 @@ export function createFlowsDoor(opts: {
|
|
|
216
216
|
roles: any;
|
|
217
217
|
pages: Record<string, string>;
|
|
218
218
|
tickets: string[];
|
|
219
|
-
flowType: "
|
|
219
|
+
flowType: "mcp" | "plain" | "tickets";
|
|
220
220
|
mcp: any;
|
|
221
221
|
nextRunId: string;
|
|
222
222
|
lastRunId: string | null;
|
|
@@ -2,6 +2,17 @@
|
|
|
2
2
|
export function readOutcomes(flowDir: string): any[];
|
|
3
3
|
/** The ONE writer of `triggers.jsonl`: append-only, one line per fire outcome. @param {string} flowDir @param {Record<string, any>} row */
|
|
4
4
|
export function appendOutcome(flowDir: string, row: Record<string, any>): void;
|
|
5
|
+
/**
|
|
6
|
+
* M9 item 1 and 2: the runs that count as "one green run" for this job, in run-name order. THE decider: a passed run counts when the job it ran (its own
|
|
7
|
+
* `job/` copy) is the job as it is now (prose and declaration, byte for byte: a schedule is its own file, so setting one never changes the job).
|
|
8
|
+
* A run from before runs kept a job copy has none to compare, so it counts only when its history row's signature is the job's current one.
|
|
9
|
+
* @param {string} flowDir @returns {Generator<{runId: string, runDir: string, at: string}>}
|
|
10
|
+
*/
|
|
11
|
+
export function greenRuns(flowDir: string): Generator<{
|
|
12
|
+
runId: string;
|
|
13
|
+
runDir: string;
|
|
14
|
+
at: string;
|
|
15
|
+
}>;
|
|
5
16
|
/** M9 item 1 and 2: does this job have "one green run"? @param {string} flowDir */
|
|
6
17
|
export function hasGreenRunForJob(flowDir: string): boolean;
|
|
7
18
|
/**
|
|
@@ -239,7 +250,7 @@ export function createTriggerDoor(opts: {
|
|
|
239
250
|
flowHash: string;
|
|
240
251
|
sig: string | null;
|
|
241
252
|
armed: boolean;
|
|
242
|
-
armedAt:
|
|
253
|
+
armedAt: any;
|
|
243
254
|
nextSlotMs: number | null;
|
|
244
255
|
lastOutcome: any;
|
|
245
256
|
hasGreenRun: boolean;
|
|
@@ -267,7 +278,7 @@ export function createTriggerDoor(opts: {
|
|
|
267
278
|
flowHash: string;
|
|
268
279
|
sig: string | null;
|
|
269
280
|
armed: boolean;
|
|
270
|
-
armedAt:
|
|
281
|
+
armedAt: any;
|
|
271
282
|
nextSlotMs: number | null;
|
|
272
283
|
lastOutcome: any;
|
|
273
284
|
hasGreenRun: boolean;
|
|
@@ -296,3 +307,6 @@ export const TICKET_LOOK_TOOL: "list_issues";
|
|
|
296
307
|
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.";
|
|
297
308
|
export type Trigger = import("../trigger-line.js").Trigger;
|
|
298
309
|
export type Schedule = import("../schedule.js").Schedule;
|
|
310
|
+
export type FileTrigger = Extract<Trigger, {
|
|
311
|
+
kind: "file-updated" | "new-file";
|
|
312
|
+
}>;
|