fwdloop 0.33.0 → 0.35.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 +14 -0
- package/bin/fwdloop +18 -2
- package/package.json +1 -1
- package/src/action-line.js +100 -0
- package/src/action-stop.js +44 -0
- package/src/ask.js +9 -2
- package/src/auditchecks.js +6 -4
- package/src/authoring.js +28 -14
- package/src/blockasks.js +3 -2
- package/src/blockassemble.js +40 -21
- package/src/blockdraft.js +8 -13
- package/src/blockpick.js +11 -1
- package/src/checkblock.js +102 -58
- package/src/checked.js +7 -2
- package/src/checklist.js +1 -3
- package/src/checklistsign.js +1 -1
- package/src/checkpick.js +7 -73
- package/src/declaration.js +20 -35
- package/src/drafter.js +281 -208
- package/src/jobkey.js +2 -3
- package/src/noteask.js +62 -0
- package/src/pageask.js +24 -69
- package/src/pagedry.js +27 -4
- package/src/pagemap.js +8 -2
- package/src/pagerules.js +19 -3
- package/src/panel/author.js +63 -36
- package/src/panel/authorcard.js +36 -20
- package/src/panel/data.js +5 -1
- package/src/panel/index.html +66 -37
- package/src/pickrecord.js +42 -54
- package/src/planrebuild.js +16 -6
- package/src/rowedit.js +35 -5
- package/src/rubricstep.js +9 -1
- package/src/runner.js +87 -41
- package/src/runvalues.js +9 -1
- package/src/setup.js +3 -1
- package/src/sheetblock.js +17 -7
- package/src/sheetbuild.js +148 -0
- package/src/sheetchecks.js +3 -2
- package/src/sheetfind.js +4 -4
- package/src/sheetlook.js +15 -4
- package/src/sheetoffer.js +50 -5
- package/src/sheetrows.js +18 -2
- package/src/signed-text.js +1 -5
- package/src/ticket-draft.js +4 -21
- package/src/ticketrows.js +100 -0
- package/src/whole-job.js +27 -11
- package/types/action-line.d.ts +71 -0
- package/types/action-stop.d.ts +36 -0
- package/types/ask.d.ts +3 -2
- package/types/auditchecks.d.ts +2 -1
- package/types/authoring.d.ts +8 -3
- package/types/blockasks.d.ts +1 -2
- package/types/blockassemble.d.ts +20 -3
- package/types/blockdraft.d.ts +4 -12
- package/types/blockpick.d.ts +5 -0
- package/types/checkblock.d.ts +33 -17
- package/types/checked.d.ts +2 -0
- package/types/checklist.d.ts +3 -5
- package/types/checkpick.d.ts +4 -34
- package/types/declaration.d.ts +7 -0
- package/types/drafter.d.ts +23 -356
- package/types/noteask.d.ts +52 -0
- package/types/pageask.d.ts +12 -36
- package/types/pagedry.d.ts +13 -0
- package/types/pagerules.d.ts +7 -0
- package/types/panel/author.d.ts +1 -1
- package/types/panel/authorcard.d.ts +13 -8
- package/types/panel/authorflows.d.ts +4 -4
- package/types/panel/data.d.ts +2 -2
- package/types/panel/jobgrid.d.ts +1 -1
- package/types/pickrecord.d.ts +47 -13
- package/types/rowedit.d.ts +16 -1
- package/types/rubricstep.d.ts +3 -0
- package/types/sheetblock.d.ts +11 -4
- package/types/sheetbuild.d.ts +82 -0
- package/types/sheetchecks.d.ts +2 -1
- package/types/sheetfind.d.ts +2 -2
- package/types/sheetoffer.d.ts +26 -1
- package/types/sheetrows.d.ts +8 -0
- package/types/ticket-draft.d.ts +3 -49
- package/types/ticketrows.d.ts +61 -0
- package/types/whole-job.d.ts +3 -3
- package/src/added-end.js +0 -60
- package/src/repairs.js +0 -38
- package/types/added-end.d.ts +0 -62
- package/types/repairs.d.ts +0 -13
package/src/jobkey.js
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
// TWO producers, ONE canonical form: the signed flow (parseSignedText's lines + arbiter) and the card's job box (parseJobBox).
|
|
6
6
|
import { createHash } from 'node:crypto';
|
|
7
7
|
|
|
8
|
-
import { typedLinesOf } from './added-end.js';
|
|
9
8
|
import { joinGuardrails, parseJobBox } from './panel/authorcard.js';
|
|
10
9
|
|
|
11
10
|
/** @param {{ask: boolean, text: string, guardrail: string}[]} steps */
|
|
@@ -22,6 +21,6 @@ export function jobKeyOfCard(job) {
|
|
|
22
21
|
/** The key of a signed job. @param {{ lines: {n: number, text: string, guardrail: string}[], arbiter: any }} signed `parseSignedText`'s ok result */
|
|
23
22
|
export function jobKeyOfSigned({ lines, arbiter }) {
|
|
24
23
|
const asks = new Set((arbiter.asks ?? []).map((a) => a.line));
|
|
25
|
-
// M13
|
|
26
|
-
return keyOf(
|
|
24
|
+
// M13 am11: every line of a signed job is a line the person typed (code adds none)
|
|
25
|
+
return keyOf(lines.map((l) => ({ ask: asks.has(l.n), text: String(l.text).trim(), guardrail: String(l.guardrail ?? '').trim() })));
|
|
27
26
|
}
|
package/src/noteask.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// borrowed-from: bareloop src/noteask.js@v0.57.0 (c18df406) (NOTE_SYSTEM, the question's wording, decideNote's reading of the typed answer; the call itself is fwd's forced tool turn, src/drafter.js forcedTurn, not bareloop's text reply)
|
|
2
|
+
// The note question (M17 am1 1(e)). A facts-only line ("find these on the page") may also ask for written words ("and write a one-sentence note"). Code cannot read that from the line, so the AI is
|
|
3
|
+
// asked ONCE per draft, only when a line is facts-only: yes or no per line, typed. CODE decides what it means (src/checkblock.js buildNote: a `$` note row and a countable nonEmpty part, so the step
|
|
4
|
+
// is told to write `text`). The AI sees the numbered line text only, never a `~` rule. A call with no usable answer leaves each asked line facts-only with a Not checked row, never a guess.
|
|
5
|
+
// What this throws away: everything but yes/no per asked line (a line it was not asked about, any other field).
|
|
6
|
+
|
|
7
|
+
/** the label of the forced turn, as the draft's log and the replay in src/planrebuild.js see it */
|
|
8
|
+
export const NOTE_KIND = 'note-ask';
|
|
9
|
+
export const NOTE_TOOL = 'answer_note_question';
|
|
10
|
+
|
|
11
|
+
export const NOTE_SYSTEM = 'You read the numbered lines of a job. You answer only about what each line says; you never invent words.';
|
|
12
|
+
|
|
13
|
+
export const NOTE_SCHEMA = Object.freeze({
|
|
14
|
+
type: 'object',
|
|
15
|
+
properties: {
|
|
16
|
+
lines: {
|
|
17
|
+
type: 'array',
|
|
18
|
+
items: {
|
|
19
|
+
type: 'object',
|
|
20
|
+
properties: { line: { type: 'integer', minimum: 1, description: 'the job line number' }, writtenWords: { enum: ['yes', 'no'] } },
|
|
21
|
+
required: ['line', 'writtenWords'],
|
|
22
|
+
additionalProperties: false,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
required: ['lines'],
|
|
27
|
+
additionalProperties: false,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
/** What the AI is told: the numbered job lines (text only) and the one question. @param {{n: number, text: string}[]} lines @returns {string} */
|
|
31
|
+
export function notePrompt(lines) {
|
|
32
|
+
return `THE JOB:\n${lines.map((l) => `LINE ${l.n}: ${l.text}`).join('\n')}\n\n`
|
|
33
|
+
+ 'For EACH line answer ONE question: does the line also ask for written words (a note, a sentence, a paragraph, a summary) beyond the facts found on the page (items, numbers, dates, quoted words)? '
|
|
34
|
+
+ 'A line that only asks to list, find or give items with their fields is "no". '
|
|
35
|
+
+ `Call ${NOTE_TOOL} once with one entry per line: {"line": <line number>, "writtenWords": "yes" or "no"}. `
|
|
36
|
+
+ 'Example: for "LINE 1: List the 3 newest posts with title and date" and "LINE 2: Write a two-sentence recap of the newest post" the entries are line 1 "no" and line 2 "yes".';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Code reads the typed answer: every asked line answered exactly yes or no, else null (no repair). An answer for a line not asked is unreadable too.
|
|
41
|
+
* @param {any} args the tool's arguments @param {{n: number}[]} lines @returns {Map<number, 'yes'|'no'>|null}
|
|
42
|
+
*/
|
|
43
|
+
export function decideNote(args, lines) {
|
|
44
|
+
if (args === null || typeof args !== 'object' || !Array.isArray(args.lines)) return null;
|
|
45
|
+
/** @type {Map<number, 'yes'|'no'>} */
|
|
46
|
+
const out = new Map();
|
|
47
|
+
for (const e of args.lines) {
|
|
48
|
+
if (e === null || typeof e !== 'object' || !Number.isInteger(e.line) || (e.writtenWords !== 'yes' && e.writtenWords !== 'no') || !lines.some((l) => l.n === e.line)) return null;
|
|
49
|
+
out.set(e.line, e.writtenWords);
|
|
50
|
+
}
|
|
51
|
+
return lines.every((l) => out.has(l.n)) ? out : null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The answers per asked line as the block reads them: the typed answer, or `failed` for every asked line when there is none. ONE function, shared by the draft and the replay.
|
|
56
|
+
* @param {number[]} asked the facts-only lines asked @param {any} args the tool's arguments, or null @param {{n: number}[]} lines
|
|
57
|
+
* @returns {{line: number, answer: 'yes'|'no'|'failed'}[]}
|
|
58
|
+
*/
|
|
59
|
+
export function noteAnswers(asked, args, lines) {
|
|
60
|
+
const d = args === null ? null : decideNote(args, lines.filter((l) => asked.includes(l.n)));
|
|
61
|
+
return asked.map((n) => ({ line: n, answer: d?.get(n) ?? 'failed' }));
|
|
62
|
+
}
|
package/src/pageask.js
CHANGED
|
@@ -1,21 +1,8 @@
|
|
|
1
|
-
// borrowed-from: bareloop src/pagemap.js@0a34846 (DROP_IT, isDropIt, isAgree, readingQuestion, readingOfQuestion,
|
|
1
|
+
// borrowed-from: bareloop src/pagemap.js@0a34846 (DROP_IT, isDropIt, isAgree, readingQuestion, readingOfQuestion, tooManyAsksText)
|
|
2
2
|
// borrowed-from: bareloop src/facts.js@0a34846 (ruleWords, sayBound, moneyAs)
|
|
3
3
|
// borrowed-from: bareloop src/pagemap.js@v0.49.0 (d51a367) (stripAgreeLead, F240; adapted: literal regex, src/ bans new RegExp)
|
|
4
|
-
//
|
|
5
|
-
// result. The model never decides whether to ask: this file reads a kept fact's own keys (line, forRule, name, shape, unit, currency, reading) and the job
|
|
6
|
-
// lines, and nothing else (test/m10-pageask.test.js greps for it). The question words are bareloop's, verbatim (am5 item 1); the answer words are
|
|
7
|
-
// agree / yes (code's reading), your own words, and, for a can't-check ask only, "drop it" (am2 item 2).
|
|
8
|
-
// Every rule is one of three kinds:
|
|
9
|
-
// PAGE: a kept page word carries it: no ask.
|
|
10
|
-
// READING: a kept fact carries it with a `reading` (a limit the page cannot hold in words, e.g. "not a red-eye"). Asked only when a bound of the
|
|
11
|
-
// reading is NOT in the words the person wrote; a bound they wrote themselves is theirs and nothing is asked.
|
|
12
|
-
// CAN'T CHECK: no kept fact carries it.
|
|
13
|
-
// A COUNT guardrail (declaration.js isCountGuardrail) is none of these: it is asked once, as a pick (M10 am24).
|
|
14
|
-
// Throws away: a fact's name, words and source (only its reading and the rule it serves are used).
|
|
4
|
+
// The words of the asks and of the answers to them. M17 am4 (A1): the asks themselves come from the list (src/blockasks.js); the page-look ask path that sat here is gone.
|
|
15
5
|
import { redactSecrets } from './redact.js';
|
|
16
|
-
import { lineRules, boundInWords, wordsSaidOn } from './pagebits.js';
|
|
17
|
-
import { validReading } from './pagerules.js';
|
|
18
|
-
import { isCountGuardrail } from './declaration.js';
|
|
19
6
|
import { HOW_TO_ANSWER } from './checkpick.js';
|
|
20
7
|
import { columnTail } from './sheetfind.js';
|
|
21
8
|
|
|
@@ -44,9 +31,6 @@ export const stripAgreeLead = (text) => {
|
|
|
44
31
|
return m ? m[1].trim() : String(text ?? '');
|
|
45
32
|
};
|
|
46
33
|
|
|
47
|
-
/** @typedef {{line: number, rule: number, source: 'look', question: string, ask: 'reading'|'cant-check', ruleText: string, reading?: string}} LookAsk
|
|
48
|
-
* `reading` = the plain words an `agree` writes as a `~` rule (a reading ask only) */
|
|
49
|
-
|
|
50
34
|
/** @param {unknown} n @param {string} shape @param {any} f @returns {string} one bound, as the person would say it */
|
|
51
35
|
function sayBound(n, shape, f) {
|
|
52
36
|
if (shape === 'money') return moneyAs(f, /** @type {string|number} */ (n), false);
|
|
@@ -77,9 +61,9 @@ const READING_ASKED = '. Agree?';
|
|
|
77
61
|
const READING_ANSWER = ' Answer "agree"';
|
|
78
62
|
const READING_TAIL = `${READING_ASKED}${READING_ANSWER}`;
|
|
79
63
|
/** @param {number} n @returns {string} the rest of a reading ask after its answer words */
|
|
80
|
-
const readingRest = (n) => `, or type your own reading (your answer
|
|
64
|
+
const readingRest = (n) => `, or type your own reading (your answer replaces that ~ rule on line ${n}).`;
|
|
81
65
|
/** @param {number} n @returns {string} the answer words a can't-check ask ends with (said once, here, and cut in the panel) */
|
|
82
|
-
const cantCheckTail = (n) => ` Answer "${DROP_IT}", or type how to check it (your answer
|
|
66
|
+
const cantCheckTail = (n) => ` Answer "${DROP_IT}", or type how to check it (your answer replaces that ~ rule on line ${n}).`;
|
|
83
67
|
/** @param {number} n @param {string} rule @param {string} reading @returns {string} */
|
|
84
68
|
export const readingQuestion = (n, rule, reading) => `Your line ${n} says "${rule}".${READING_HEAD}${reading}${READING_TAIL}${readingRest(n)}`;
|
|
85
69
|
// borrowed-from: bareloop src/pagemap.js@v0.56.0 (3383cce) (cantCheckQuestion; readingQuestion above is exported for the block's asks)
|
|
@@ -101,58 +85,11 @@ export function readingOfQuestion(q) {
|
|
|
101
85
|
export function panelQuestionText(q) {
|
|
102
86
|
const text = String(q.question);
|
|
103
87
|
if (q.source !== 'look') return text;
|
|
104
|
-
const tails = [`${READING_ANSWER}${readingRest(q.line)}`, cantCheckTail(q.line), columnTail(q.line), ` ${HOW_TO_ANSWER(q.line, true)}`, ` ${HOW_TO_ANSWER(q.line, false)}`];
|
|
88
|
+
const tails = [`${READING_ANSWER}${readingRest(q.line)}`, cantCheckTail(q.line), columnTail(q.line), columnTail(q.line, true), ` ${HOW_TO_ANSWER(q.line, true)}`, ` ${HOW_TO_ANSWER(q.line, false)}`];
|
|
105
89
|
const hit = tails.find((t) => text.endsWith(t));
|
|
106
90
|
return hit === undefined ? text : text.slice(0, text.length - hit.length);
|
|
107
91
|
}
|
|
108
92
|
|
|
109
|
-
/**
|
|
110
|
-
* The early asks CODE forces before any paid drafting, from the look's own result. One ask per rule text on a line; readings first, then can't-check
|
|
111
|
-
* asks, each in line order. The caller applies the cap and the answer gate.
|
|
112
|
-
* @param {{facts?: {line: number, forRule?: number, name?: string, shape?: string, unit?: string[], currency?: string[], reading?: import('./pagerules.js').Reading}[]}|null|undefined} look
|
|
113
|
-
* @param {{n: number, text?: string, rule?: string, rules?: string[]}[]|null|undefined} jobLines
|
|
114
|
-
* @returns {LookAsk[]}
|
|
115
|
-
*/
|
|
116
|
-
export function askableFromLook(look, jobLines) {
|
|
117
|
-
const facts = Array.isArray(look?.facts) ? look.facts : [];
|
|
118
|
-
/** @type {LookAsk[]} */
|
|
119
|
-
const readings = [];
|
|
120
|
-
/** @type {LookAsk[]} */
|
|
121
|
-
const cants = [];
|
|
122
|
-
/** @type {Set<string>} */
|
|
123
|
-
const seen = new Set();
|
|
124
|
-
for (const l of Array.isArray(jobLines) ? jobLines : []) {
|
|
125
|
-
lineRules(l).forEach((rule, k) => {
|
|
126
|
-
const n = k + 1;
|
|
127
|
-
if (isCountGuardrail(rule)) return; // M10 am24: a count guardrail is asked only as a pick (src/checkpick.js), never as a page question; its look facts stay
|
|
128
|
-
const key = `${l.n}\u0000${rule.trim().toLowerCase()}`;
|
|
129
|
-
const tied = facts.filter((f) => f.line === l.n && f.forRule === n);
|
|
130
|
-
if (tied.length > 0) {
|
|
131
|
-
const said = wordsSaidOn(l);
|
|
132
|
-
const f = tied.find((x) => x.reading && validReading(x.shape, x.reading) && ruleBounds(x.reading).some((b) => !boundInWords(b, said)));
|
|
133
|
-
if (f === undefined || seen.has(key)) return;
|
|
134
|
-
seen.add(key);
|
|
135
|
-
const reading = `${f.name} ${ruleWords({ shape: f.shape, unit: f.unit, currency: f.currency, rule: f.reading })}`;
|
|
136
|
-
readings.push({
|
|
137
|
-
line: l.n, rule: n, source: 'look', ask: 'reading', ruleText: rule, reading,
|
|
138
|
-
question: readingQuestion(l.n, rule, reading),
|
|
139
|
-
});
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
if (seen.has(key)) return;
|
|
143
|
-
seen.add(key);
|
|
144
|
-
cants.push({
|
|
145
|
-
line: l.n, rule: n, source: 'look', ask: 'cant-check', ruleText: rule,
|
|
146
|
-
question: `Your line ${l.n} says "${rule}". I can't check this on the page. Drop it?${cantCheckTail(l.n)}`,
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
return [...readings, ...cants];
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/** @param {import('./pagerules.js').Reading} r @returns {unknown[]} the bounds a reading holds */
|
|
154
|
-
const ruleBounds = (r) => (r.op === 'between' ? [r.lo, r.hi] : [r.value]);
|
|
155
|
-
|
|
156
93
|
/**
|
|
157
94
|
* More asks than the cap means the job needs a rewrite, not a questionnaire. The code-owned stop words list EVERY ask and its reading as the
|
|
158
95
|
* suggestion (no extra paid call). A secret in a rule is masked.
|
|
@@ -163,6 +100,19 @@ export function tooManyAsksText(asks) {
|
|
|
163
100
|
return redactSecrets(`Your job has ${asks.length} rules I can't check or had to guess. Please rewrite it so each one says what to look for. My readings: ${list}.`);
|
|
164
101
|
}
|
|
165
102
|
|
|
103
|
+
// borrowed-from: bareloop src/draftspend.js@v0.58.0 (decidedWords)
|
|
104
|
+
/**
|
|
105
|
+
* M17 am8: what a button-picked answer decided, as the one Audit line; null when the row has no pick (a box-answered drafter question, an older record).
|
|
106
|
+
* @param {{choice?: string, words?: string}} h
|
|
107
|
+
* @returns {string|null}
|
|
108
|
+
*/
|
|
109
|
+
export function decidedWords(h) {
|
|
110
|
+
if (h.choice === 'agree' && typeof h.words === 'string') return `agreed \u2014 ${h.words}`;
|
|
111
|
+
if (h.choice === 'rule' && typeof h.words === 'string') return `you wrote \u2014 ${h.words}`;
|
|
112
|
+
if (h.choice === 'drop') return 'dropped \u2014 Not checked';
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
|
|
166
116
|
/**
|
|
167
117
|
* What a typed answer to a look ask does, the ONE place that decides (the panel's answer route, the setup record and the Result tab all read it).
|
|
168
118
|
* `agree` / `yes` to a reading ask takes the code's reading; `drop it` to a can't-check ask leaves the rule Not checked (no `~` line); anything else is the
|
|
@@ -170,11 +120,16 @@ export function tooManyAsksText(asks) {
|
|
|
170
120
|
* M10 am16: a shape guardrail's ask (`ask: 'check'` proposes a check, `'no-check'` found none) takes the same words: `agree` takes the proposal (and the check it
|
|
171
121
|
* carries, `check`), `drop it` leaves the rule Not checked (either kind), anything else is the person's own words (`own`: a `~` rule on the line, no check).
|
|
172
122
|
* @param {{source?: string, ask?: string, proposal?: string|null, check?: Record<string, any>}} q @param {unknown} typed @param {'agree'|'drop'|'rule'} [choice] M10 am29: the button used; absent = today's words reading (CLI, old files)
|
|
173
|
-
* @returns {{rule: string|null, left: boolean, check?: Record<string, any>, own?: boolean}} `rule` = the words written as a new `~` rule (null when the rule is left Not checked)
|
|
123
|
+
* @returns {{rule: string|null, left: boolean, check?: Record<string, any>, own?: boolean, action?: 'known', actionLine?: string}} `rule` = the words written as a new `~` rule (null when the rule is left Not checked)
|
|
174
124
|
*/
|
|
175
125
|
export function ruleOfAnswer(q, typed, choice) {
|
|
176
126
|
const typedText = String(typed ?? '').replace(/\s*\n\s*/g, ' ').trim();
|
|
177
127
|
if (q.source !== 'look') return { rule: typedText, left: false };
|
|
128
|
+
// M13 am11 rule 2: the question about the job's last action adds no `~` rule. Agree adds the suggested line, the box adds the typed words; there is no Drop it (am11c).
|
|
129
|
+
if (q.source === 'look' && q.ask === 'action') {
|
|
130
|
+
if (choice === 'drop') return { rule: null, left: true }; // M13 am11c: there is no Drop it here; the answer door refuses it (the question is about the job line, not a ~ rule)
|
|
131
|
+
return { rule: null, left: false, action: 'known', actionLine: choice === 'agree' && typeof q.proposal === 'string' ? q.proposal : typedText };
|
|
132
|
+
}
|
|
178
133
|
if (choice !== undefined) { // M10 am29: a typed choice decides, never the words; the box (`rule`) keeps its words whole
|
|
179
134
|
const shapeC = q.ask === 'check' || q.ask === 'no-check';
|
|
180
135
|
if (choice === 'agree' && typeof q.proposal === 'string' && (q.ask === 'reading' || q.ask === 'check')) return { rule: q.proposal, left: false, ...(q.ask === 'check' && q.check ? { check: q.check } : {}) };
|
package/src/pagedry.js
CHANGED
|
@@ -83,6 +83,31 @@ export async function dryReadMoney(text, facts) {
|
|
|
83
83
|
return { facts: kept, dropped, reads, results };
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
// borrowed-from: bareloop src/pagedry.js@v0.57.0 (c18df406) (resultQuotes, phraseInNoResult: 637e76ad)
|
|
87
|
+
/**
|
|
88
|
+
* The page's RESULT LINES: the lines the given money facts read (`moneyResultLines`), each quote once. Empty when no money fact reads a line (the result lines are then unknown).
|
|
89
|
+
* The one owner of "what is a result row" for phrase facts, shared by the dry read below and by the check list's `!` rows (`phraseInNoResult`).
|
|
90
|
+
* @param {string} text @param {KeptFact[]} facts @returns {string[]}
|
|
91
|
+
*/
|
|
92
|
+
export function resultQuotes(text, facts) {
|
|
93
|
+
/** @type {Set<string>} */
|
|
94
|
+
const quotes = new Set();
|
|
95
|
+
for (const k of facts) if (k.shape === 'money') for (const r of moneyResultLines(text, k)) quotes.add(r.quote);
|
|
96
|
+
return [...quotes];
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Is this phrase in the page but in NONE of its result lines (the `phrase-no-result` case)? Sync, for a `!` row the check list is about to build.
|
|
101
|
+
* True only when result lines exist and no line holds the words (case and spacing aside, a plain substring: it never refuses a phrase the run's presence check could pass).
|
|
102
|
+
* With no result line known nothing is guessed (false).
|
|
103
|
+
* @param {string} text @param {KeptFact[]} moneyFacts the line's money facts @param {string} words @returns {boolean}
|
|
104
|
+
*/
|
|
105
|
+
export function phraseInNoResult(text, moneyFacts, words) {
|
|
106
|
+
const rows = resultQuotes(text, moneyFacts);
|
|
107
|
+
const w = words.replace(/\s+/g, ' ').trim().toLowerCase();
|
|
108
|
+
return rows.length > 0 && w !== '' && !rows.some((q) => q.replace(/\s+/g, ' ').toLowerCase().includes(w));
|
|
109
|
+
}
|
|
110
|
+
|
|
86
111
|
/**
|
|
87
112
|
* The same "can it read" for PHRASE facts (bareloop c550dc8; our failure: m10-walk-flights-3, "Rome" was on the page only in "Track prices from Madrid to
|
|
88
113
|
* Rome" switches, in none of the 18 result lines, so no result could ever say it). A kept phrase fact is read against the page's RESULT LINES = the lines
|
|
@@ -94,9 +119,7 @@ export async function dryReadMoney(text, facts) {
|
|
|
94
119
|
* @returns {Promise<{facts: KeptFact[], dropped: Dropped[], reads: Record<string, number>}>} `reads` = result lines that said the phrase, per fact name
|
|
95
120
|
*/
|
|
96
121
|
export async function dryReadPhrases(text, facts) {
|
|
97
|
-
|
|
98
|
-
const quotes = new Set();
|
|
99
|
-
for (const k of facts) if (k.shape === 'money') for (const r of moneyResultLines(text, k)) quotes.add(r.quote);
|
|
122
|
+
const quotes = resultQuotes(text, facts);
|
|
100
123
|
/** @type {KeptFact[]} */
|
|
101
124
|
const kept = [];
|
|
102
125
|
/** @type {Dropped[]} */
|
|
@@ -104,7 +127,7 @@ export async function dryReadPhrases(text, facts) {
|
|
|
104
127
|
/** @type {Record<string, number>} */
|
|
105
128
|
const reads = {};
|
|
106
129
|
for (const k of facts) {
|
|
107
|
-
if (k.shape !== 'phrase' || quotes.
|
|
130
|
+
if (k.shape !== 'phrase' || quotes.length === 0 || !k.words.length) { kept.push(k); continue; }
|
|
108
131
|
const part = { source: SOURCE, facts: factsOfLook({ name: CLAIM, shape: 'phrase', words: [k.words[0]] }) };
|
|
109
132
|
let n = 0;
|
|
110
133
|
for (const quote of quotes) {
|
package/src/pagemap.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// borrowed-from: bareloop src/pagemap.js@54fa5ca (MAP_SHAPES, MAP_SYSTEM, mapPrompt, parseMapAnswer, MAP_UNREADABLE)
|
|
2
|
+
// fwd change 2026-11-16 (F201, hamr): the prompt states the goal, asks for meaning + a why per fact, and gives a "cannot" list for a rule the page cannot show
|
|
2
3
|
// Not copied: runPageMap (bareloop's spend and transport plumbing; fwdloop meters through the drafter's own provider call, see src/pagelook.js),
|
|
3
4
|
// and the ask half (DROP_IT, askableFromLook, ...), which is the next piece.
|
|
4
5
|
import { lineRules } from './pagebits.js';
|
|
@@ -16,9 +17,14 @@ export const MAP_SYSTEM = 'You map a person\'s job to the exact words of ONE sav
|
|
|
16
17
|
export function mapPrompt({ jobLines, label, text }) {
|
|
17
18
|
const job = jobLines.map((l) => `LINE ${l.n}: ${l.text}${lineRules(l).map((r, i) => `\n~ rule ${i + 1}: ${r}`).join('')}`).join('\n');
|
|
18
19
|
return `THE JOB (each ~ rule applies to the line above it):\n${job}\n\n`
|
|
19
|
-
+ '
|
|
20
|
+
+ 'Your goal: the ~ rules are the person\'s intent. For each rule, say which words on the page would let code check that every result keeps it. Code will look for the words you give, and the person will see them and can drop them.\n\n'
|
|
21
|
+
+ 'A "result" is one item the page lists (one flight, one stay, one row).\n\n'
|
|
22
|
+
+ 'For each job line and for each ~ rule, do ONE of two things:\n'
|
|
23
|
+
+ '1. The page can show the rule. Give a fact: the PAGE\'S OWN WORDS that a result carries when it keeps the rule. The words do not have to be the rule\'s words, but they must carry the rule\'s MEANING. Add a one-line "why" that says what those words on a result mean for the rule.\n'
|
|
24
|
+
+ '2. The page cannot show the rule: how the answer is written, its tone or style, or anything the page does not hold. Give NO fact for it. Put it in "cannot" with its line and rule number and a one-line "why".\n'
|
|
25
|
+
+ 'Never tie a rule to page words that do not carry its meaning. A rule with no fact is a correct answer when the page cannot show it.\n\n'
|
|
20
26
|
+ 'Return ONLY a JSON object, no prose, no code fence:\n'
|
|
21
|
-
+ '{"facts":[{"name":"<letters and spaces only>","from":"<line N | line N rule M>","shape":"place|money|time|phrase","words":["<page words>", ...],"currency":["<symbol>"],"unit":["<words after the amount>"],"reading":<optional, see below>}]}\n\n'
|
|
27
|
+
+ '{"facts":[{"name":"<letters and spaces only>","from":"<line N | line N rule M>","shape":"place|money|time|phrase","words":["<page words>", ...],"why":"<one line>","currency":["<symbol>"],"unit":["<words after the amount>"],"reading":<optional, see below>}],"cannot":[{"from":"line N rule M","why":"<one line>"}]}\n\n'
|
|
22
28
|
+ 'shape meanings:\n'
|
|
23
29
|
+ '- place: words = ways the page writes the place (a city, an airport name), copied from the page.\n'
|
|
24
30
|
+ '- money: words = the label(s) written right BEFORE the amount, copied from the page. currency / unit = how the page writes the currency ("$") and/or the words after the amount ("US dollars"); give every spelling the page uses, as lists.\n'
|
package/src/pagerules.js
CHANGED
|
@@ -162,6 +162,19 @@ const CURRENCY_SYMBOLS = ['$', '€', '£'];
|
|
|
162
162
|
/** the shapes that read a value after a label */
|
|
163
163
|
const VALUE_SHAPES = ['money', 'time', 'number'];
|
|
164
164
|
|
|
165
|
+
// borrowed-from: bareloop src/pagerules.js@v0.57.0 (c18df406) (withColon, 1583d563)
|
|
166
|
+
/**
|
|
167
|
+
* The ONE owner of a label's separator: the label as the page writes it. The run's checker reads a value right after the signed label, so a page that
|
|
168
|
+
* writes "Departure time: 10:24 AM." can only be read by the label "Departure time:". When EVERY place the page holds the label has a colon right after
|
|
169
|
+
* it, the label is signed with that colon; one bare place leaves it as the look gave it. A plain count of the page's own text, no pattern.
|
|
170
|
+
* @param {string} text the frozen page text @param {string} label a label as normLabel leaves it @returns {string}
|
|
171
|
+
*/
|
|
172
|
+
export function withColon(text, label) {
|
|
173
|
+
if (label.endsWith(':')) return label;
|
|
174
|
+
const n = countExact(text, label);
|
|
175
|
+
return n >= 1 && countExact(text, `${label}:`) === n ? `${label}:` : label;
|
|
176
|
+
}
|
|
177
|
+
|
|
165
178
|
/**
|
|
166
179
|
* Apply the rules to the AI's map over one saved page. Returns the kept facts and, for everything a rule removed, one `dropped` entry.
|
|
167
180
|
* The order of the rules is the POC's (apply-v3.mjs): found-on-page, then the rules that read the page. A place is read as a phrase.
|
|
@@ -208,9 +221,12 @@ export function applyPageRules(text, mapping, jobLines) {
|
|
|
208
221
|
const asListed = [];
|
|
209
222
|
/** U1: labels the page writes after the number */
|
|
210
223
|
const moved = [];
|
|
211
|
-
for (const
|
|
212
|
-
const
|
|
213
|
-
if (!
|
|
224
|
+
for (const w00 of words) {
|
|
225
|
+
const base = normLabel(w00);
|
|
226
|
+
if (!base) continue;
|
|
227
|
+
// a label the page always writes with a colon right after it ("Departure time: 10:24 AM.") is signed as the page writes it (run mwgsl7zx)
|
|
228
|
+
const w = withColon(text, base);
|
|
229
|
+
const w0 = w === base ? w00 : w;
|
|
214
230
|
if (countExact(text, w) < 1) { asListed.push(w0); drop(f, w0, 'not-on-page'); continue; }
|
|
215
231
|
if (amount) {
|
|
216
232
|
const { B, A } = beforeAfter(lines, w);
|
package/src/panel/author.js
CHANGED
|
@@ -65,7 +65,8 @@ import {
|
|
|
65
65
|
capTooSmallText, draftingSpent, EARLIER_MISSING_SAY, potSplit, STARTED_OVER_FILE, usdText,
|
|
66
66
|
} from '../draftspend.js';
|
|
67
67
|
import { jobKeyOfCard } from '../jobkey.js';
|
|
68
|
-
import { flowValues, valuesHash } from '../runvalues.js';
|
|
68
|
+
import { flowValues, valuesHash, parseWaitMs } from '../runvalues.js';
|
|
69
|
+
import { DEFAULT_ACTION_WAIT_MS } from '../action-stop.js';
|
|
69
70
|
import { capAboveSpentText, capNotAboveSpent } from './authorvalues.js';
|
|
70
71
|
import { createFlowsDoor } from './authorflows.js';
|
|
71
72
|
import { createTriggerDoor } from './authortrigger.js';
|
|
@@ -290,7 +291,7 @@ export function createAuthor(opts) {
|
|
|
290
291
|
// A child never comes back to life, so a stale "alive" only delays the offer; asked AFTER the files were read, the questions are already on disk (C9's order is for a missing result)
|
|
291
292
|
if (childRunning(dir)) return { ...shared, phase: newest > 0 ? (cur.kind === 'answers' ? 'redrafting' : 'revising') : 'drafting' };
|
|
292
293
|
const lineText = (line) => parseJobBox(typeof card?.job === 'string' ? card.job : '').steps[line - 1]?.text ?? null;
|
|
293
|
-
const questions = q.questions.map((x) => ({ k: x.k, line: x.line, lineText: lineText(x.line), question: scrub(x.question, keys), answered: x.answer !== null, ...(x.source === 'look' ? { source: 'look', ask: x.ask, proposes: typeof x.proposal === 'string' && (x.ask === 'reading' || x.ask === 'check'), drops: Number.isInteger(x.ruleNo), shown: scrub(panelQuestionText(x), keys) } : {}) }));
|
|
294
|
+
const questions = q.questions.map((x) => ({ k: x.k, line: x.line, lineText: lineText(x.line), question: scrub(x.question, keys), answered: x.answer !== null, ...(x.source === 'look' ? { source: 'look', ask: x.ask, proposes: typeof x.proposal === 'string' && (x.ask === 'reading' || x.ask === 'check' || x.ask === 'action'), drops: Number.isInteger(x.ruleNo), shown: scrub(panelQuestionText(x), keys) } : {}) }));
|
|
294
295
|
return { ...shared, stepList: stepListOf(dir, rel, keys, true), phase: 'questions-open', plan: rel, questions, openK: q.open[0].k, total: q.questions.length };
|
|
295
296
|
}
|
|
296
297
|
if (q.questions.length > 0) return { ...shared, phase: 'stopped', say: ANSWERS_NOT_DRAFTED_SAY };
|
|
@@ -307,6 +308,32 @@ export function createAuthor(opts) {
|
|
|
307
308
|
* @param {string} dir @param {number[]} ns the plans' numbers @param {string} [only] the one plan folder (relative)
|
|
308
309
|
* @returns {string[]}
|
|
309
310
|
*/
|
|
311
|
+
/**
|
|
312
|
+
* The ONE writer of an answer-style redraft (M4e am24): `card-<n>.json`, `prose-<n>.txt` and the marker `redraft-<n>.json` written once ('wx'), then
|
|
313
|
+
* `fwdloop draft` as a detached child. A failure removes what it wrote (and `undoToo`) and says so; the redraft uses none of the revises.
|
|
314
|
+
* @param {{id: string, dir: string, v: any, vet: any, env: any, marker: any, argvOf: (n: number, proseFile: string, realRoot: string) => string[], failSay: (code: string) => string, undoToo?: string[]}} o
|
|
315
|
+
*/
|
|
316
|
+
function startRedraft({
|
|
317
|
+
id, dir, v, vet, env, marker, argvOf, failSay, undoToo = [],
|
|
318
|
+
}) {
|
|
319
|
+
const n = Math.max(0, ...v.revises.map((x) => x.n)) + 1;
|
|
320
|
+
const files = [`card-${n}.json`, `prose-${n}.txt`, `redraft-${n}.json`].map((f) => join(dir, f));
|
|
321
|
+
const undo = () => { for (const f of [...files, ...undoToo]) rmSync(f, { force: true }); };
|
|
322
|
+
let child;
|
|
323
|
+
try {
|
|
324
|
+
writeFileSync(files[0], `${JSON.stringify(vet.card, null, 2)}\n`, { mode: 0o600, flag: 'wx' });
|
|
325
|
+
writeFileSync(files[1], vet.prose, { mode: 0o600, flag: 'wx' });
|
|
326
|
+
writeFileSync(files[2], `${JSON.stringify(marker)}\n`, { mode: 0o600, flag: 'wx' });
|
|
327
|
+
child = spawnDetached({ bin, argv: argvOf(n, files[1], realpathSync(root)), env, logPath: join(dir, `redraft-${n}.log`) });
|
|
328
|
+
} catch (e) {
|
|
329
|
+
undo();
|
|
330
|
+
return { status: 500, body: { ok: false, refused: 'spawn', say: failSay(String(/** @type {any} */ (e)?.code ?? 'error')), draftId: id } };
|
|
331
|
+
}
|
|
332
|
+
child.on('error', () => {});
|
|
333
|
+
writePidFile(dir, child);
|
|
334
|
+
return { status: 202, body: { ok: true, draftId: id, n, redrafting: true } };
|
|
335
|
+
}
|
|
336
|
+
|
|
310
337
|
function carryArgv(dir, ns, only) {
|
|
311
338
|
const rels = only === undefined ? [...ns].sort((a, b) => b - a).map((x) => `draft-${x}`).concat('draft') : [only];
|
|
312
339
|
const rel = rels.find((r) => readFileInside(join(dir, r), RECORD_FILE).ok);
|
|
@@ -333,8 +360,11 @@ export function createAuthor(opts) {
|
|
|
333
360
|
const list = card && Array.isArray(card.rows) && Array.isArray(card.suggested) ? { lines: [...cardLinesOf(decl)].sort((a, b) => a - b), rows: card.rows, suggested: card.suggested } : null;
|
|
334
361
|
// 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
|
|
335
362
|
const planLines = parsed?.ok === true ? parsed.lines.map((/** @type {any} */ l) => ({ n: l.n, text: l.text, rules: l.guardrail ? l.guardrail.split('; ') : [] })) : [];
|
|
363
|
+
// 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)
|
|
364
|
+
const act = readJson(dir, `${rel}/log.json`)?.action;
|
|
365
|
+
const action = isObj(act) && Number.isInteger(act.line) && act.dropped !== true ? { line: act.line, ...(act.by === 'agent' || act.by === 'you' ? { by: act.by } : {}) } : null;
|
|
336
366
|
return {
|
|
337
|
-
checked: checkedLines(decl, opts), notChecked: { ...view, ...(isObj(ncFile?.by) ? { by: ncFile.by } : {}) }, ...(list ? { list, planLines, always: [...EVERY_STEP_TEXTS] } : {}),
|
|
367
|
+
...(action ? { action } : {}), checked: checkedLines(decl, opts), notChecked: { ...view, ...(isObj(ncFile?.by) ? { by: ncFile.by } : {}) }, ...(list ? { list, planLines, always: [...EVERY_STEP_TEXTS] } : {}),
|
|
338
368
|
};
|
|
339
369
|
}
|
|
340
370
|
|
|
@@ -405,6 +435,9 @@ export function createAuthor(opts) {
|
|
|
405
435
|
return u.ok ? [] : no(`${u.say} Nothing was spent.`);
|
|
406
436
|
}
|
|
407
437
|
|
|
438
|
+
/** M13 am11: with a Destination on the card the prose carries a tentative send on the last line; the draft child asks the AI whether it is the action. @param {any} card */
|
|
439
|
+
const actionArgv = (card) => (typeof card.destination === 'string' && card.destination !== '' ? ['--action', 'check'] : []);
|
|
440
|
+
|
|
408
441
|
/** The flags that make a draft child use the card's model and thinking choice. @param {any} card */
|
|
409
442
|
const modelArgv = (card) => ['--model', card.model, '--provider', card.provider, ...(card.thinking === true ? ['--thinking'] : []),
|
|
410
443
|
// M13 piece 4: the card's Flow type and MCP ride every draft of the job (first, revised, redrafted)
|
|
@@ -579,7 +612,7 @@ export function createAuthor(opts) {
|
|
|
579
612
|
let child;
|
|
580
613
|
try {
|
|
581
614
|
child = spawnDetached({
|
|
582
|
-
bin, argv: ['draft', proseFile, '--out', join(dir, 'draft'), '--root', realpathSync(root), '--name', card.flowName, ...carryFrom, ...modelArgv(card)], env: loaded.env, logPath: join(dir, 'child.log'),
|
|
615
|
+
bin, argv: ['draft', proseFile, '--out', join(dir, 'draft'), '--root', realpathSync(root), '--name', card.flowName, ...carryFrom, ...modelArgv(card), ...actionArgv(card)], env: loaded.env, logPath: join(dir, 'child.log'),
|
|
583
616
|
});
|
|
584
617
|
} catch (e) {
|
|
585
618
|
return { status: 500, body: { ok: false, refused: 'spawn', say: `The draft could not be started (${/** @type {any} */ (e)?.code ?? 'error'}). Nothing was spent.`, draftId: id } };
|
|
@@ -671,11 +704,16 @@ export function createAuthor(opts) {
|
|
|
671
704
|
// M4d am16 item 1: the first run gets what is LEFT of the card's cap after drafting, as its own signed values (the flow stays signed at the card's cap, and
|
|
672
705
|
// every later run that does not draft gets the whole of it). Nothing spent on drafting = no values file = the whole cap.
|
|
673
706
|
let values = null;
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
707
|
+
// 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
|
|
708
|
+
const cardWait = typeof v.card?.askWait === 'string' ? v.card.askWait.trim().toLowerCase() : '';
|
|
709
|
+
const proseNow = readFileInside(join(dir, v.plan), 'prose.txt');
|
|
710
|
+
const parsedNow = proseNow.ok ? parseSignedText(proseNow.text) : null;
|
|
711
|
+
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;
|
|
712
|
+
if (pot.split.spentUsd > 0 || (actionWait !== null && parseWaitMs(actionWait.wait) !== DEFAULT_ACTION_WAIT_MS)) {
|
|
713
|
+
const parsed = parsedNow;
|
|
677
714
|
if (parsed && parsed.ok) {
|
|
678
|
-
const
|
|
715
|
+
const own = flowValues(parsed.arbiter);
|
|
716
|
+
const vals = { ...own, capUsd: pot.split.spentUsd > 0 ? pot.split.leftUsd : own.capUsd, ...(actionWait === null ? {} : { askWaits: { ...own.askWaits, [actionWait.line]: actionWait.wait } }) };
|
|
679
717
|
values = { flow: name, flowSignatureHash: result.signature.flow, version: 0, values: vals, hash: valuesHash({ flow: name, flowSignatureHash: result.signature.flow, runId: null, version: 0, values: vals }), signedBy, at: new Date().toISOString() };
|
|
680
718
|
}
|
|
681
719
|
}
|
|
@@ -731,7 +769,7 @@ export function createAuthor(opts) {
|
|
|
731
769
|
try {
|
|
732
770
|
child = spawnDetached({
|
|
733
771
|
bin,
|
|
734
|
-
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)],
|
|
772
|
+
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)],
|
|
735
773
|
env: loaded.env,
|
|
736
774
|
logPath: join(dir, `revise-${n}.log`),
|
|
737
775
|
});
|
|
@@ -770,12 +808,12 @@ export function createAuthor(opts) {
|
|
|
770
808
|
// space (one `~` line is one line) instead of refused. Every other question keeps its own gate (blank, one line).
|
|
771
809
|
const look = q.source === 'look';
|
|
772
810
|
// hamr 2026-11-07 (ruling 2A): a leading `~` the person typed is dropped quietly (the job line adds its own); the ONE place, so a tilde-only answer is a blank answer
|
|
773
|
-
// M10 am29: the button used rides as a typed `choice
|
|
811
|
+
// M10 am29: the button used rides as a typed `choice`. agree needs a proposal, drop/agree are look asks only.
|
|
774
812
|
const choice = b.choice;
|
|
775
813
|
// M10 am32 A: every new answer carries its button's choice; an answer with none is refused before anything is written (old answer files are still read by the readers)
|
|
776
814
|
if (choice === undefined) return { status: 400, body: { ok: false, refused: 'bad-choice', say: 'This page is out of date. Reload it and answer again. Nothing was saved.' } };
|
|
777
815
|
{
|
|
778
|
-
const proposes = look && typeof q.proposal === 'string' && (q.ask === 'reading' || q.ask === 'check');
|
|
816
|
+
const proposes = look && typeof q.proposal === 'string' && (q.ask === 'reading' || q.ask === 'check' || q.ask === 'action');
|
|
779
817
|
if (choice !== 'agree' && choice !== 'drop' && choice !== 'rule') return { status: 400, body: { ok: false, refused: 'bad-choice', say: 'That answer is not one of the choices. Nothing was saved.' } };
|
|
780
818
|
if ((choice === 'agree' && !proposes) || (choice === 'drop' && !look)) return { status: 400, body: { ok: false, refused: 'bad-choice', say: 'That choice is not offered for this question. Nothing was saved.' } };
|
|
781
819
|
}
|
|
@@ -798,10 +836,14 @@ export function createAuthor(opts) {
|
|
|
798
836
|
const all = full.map((x) => {
|
|
799
837
|
const typed = x.k === v.openK ? answer : x.answer;
|
|
800
838
|
const ch = x.k === v.openK ? choice : x.choice;
|
|
801
|
-
return { line: x.line, question: x.question, answer: typed, ...ruleOfAnswer(x, typed, ch), ruleNo: x.ruleNo, ruleText: x.ruleText, ask: x.ask,
|
|
839
|
+
return { line: x.line, question: x.question, answer: typed, ...ruleOfAnswer(x, typed, ch), ruleNo: x.ruleNo, ruleText: x.ruleText, ask: x.ask, proposal: x.proposal };
|
|
802
840
|
});
|
|
803
841
|
const adds = all.filter((x) => x.rule !== null);
|
|
804
|
-
|
|
842
|
+
// M13 am11 rule 2: the answer to the action question adds the agreed or typed line as the job's LAST line (numbered by the card), (there is no Drop it: the answer door refuses it); the redraft is told
|
|
843
|
+
const act = all.find((x) => x.ask === 'action');
|
|
844
|
+
const baseJob = typeof v.card.job === 'string' ? v.card.job : '';
|
|
845
|
+
const jobWithAction = act !== undefined && act.action === 'known' && typeof act.actionLine === 'string' && act.actionLine !== '' ? `${baseJob.replace(/\s+$/, '')}\n${act.actionLine}` : baseJob;
|
|
846
|
+
const grown = applyAnswers(jobWithAction, all);
|
|
805
847
|
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.' } };
|
|
806
848
|
const vet = vetCard({ ...v.card, job: grown.job }, loaded, draftedSoFar(dir, v.card), readJson(dir, RUN_OF_FILE)?.flow);
|
|
807
849
|
if (!vet.ok) return vet.reply;
|
|
@@ -811,39 +853,24 @@ export function createAuthor(opts) {
|
|
|
811
853
|
if (ov && LIVE_PHASES.has(ov.phase)) return { status: 409, body: { ok: false, refused: 'draft-live', draftId: other, say: 'A draft is already running. Wait for it, or abandon it, before answering.' } };
|
|
812
854
|
}
|
|
813
855
|
// M10 am16 (4): what a shape guardrail's answers picked, for the redraft: the check an agree took, or the person's own words (a `~` rule, no check). A rule left Not checked rides `left`.
|
|
814
|
-
redraft = { vet, all, picks: grown.picks, left: grown.left };
|
|
856
|
+
redraft = { vet, all, picks: grown.picks, left: grown.left, columns: grown.columns, action: act === undefined ? (vet.card.destination === '' ? null : 'check') : act.action };
|
|
815
857
|
}
|
|
816
858
|
try {
|
|
817
859
|
// the human row of the draft log (am2 item 4): the question, the answer, the line, the time; a look ask also carries what code proposed and the rule the answer added, as their own fields
|
|
818
860
|
writeFileSync(answerFile, `${JSON.stringify({
|
|
819
861
|
k: v.openK, line: q.line, question: q.question, answer, ...(choice === undefined ? {} : { choice }), at,
|
|
820
|
-
...(look ? { source: 'look', ask: q.ask, ruleNo: q.ruleNo, ruleText: q.ruleText, proposal: q.proposal ?? null, rule: effect.rule } : {}),
|
|
862
|
+
...(look ? { source: 'look', ask: q.ask, ruleNo: q.ruleNo, ruleText: q.ruleText, proposal: q.proposal ?? null, rule: effect.rule ?? (effect.action === 'known' ? effect.actionLine : null) } : {}),
|
|
821
863
|
})}\n`, { mode: 0o600, flag: 'wx' });
|
|
822
864
|
} catch (e) {
|
|
823
865
|
return { status: 409, body: { ok: false, refused: 'already-answered', say: /** @type {any} */ (e)?.code === 'EEXIST' ? 'That question already has an answer.' : 'The answer could not be saved. Nothing was sent.' } };
|
|
824
866
|
}
|
|
825
867
|
if (!last) return { status: 200, body: { ok: true, draftId: id, next: v.openK + 1 } };
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
writeFileSync(files[1], redraft.vet.prose, { mode: 0o600, flag: 'wx' });
|
|
833
|
-
writeFileSync(files[2], `${JSON.stringify({ fromPlan: v.plan, answers: redraft.all.map((x) => ({ line: x.line, question: x.question, answer: x.answer })), ...(redraft.left.length ? { left: redraft.left } : {}) })}\n`, { mode: 0o600, flag: 'wx' });
|
|
834
|
-
child = spawnDetached({
|
|
835
|
-
bin,
|
|
836
|
-
argv: ['draft', files[1], '--out', join(dir, `draft-${n}`), '--root', realpathSync(root), '--name', redraft.vet.card.flowName, '--no-questions', ...carryArgv(dir, [], v.plan), ...(redraft.picks.length ? ['--picks', JSON.stringify(redraft.picks)] : []), ...(redraft.left.length ? ['--left', redraft.left.map((x) => `${x.line}.${x.rule}`).join(',')] : []), ...modelArgv(redraft.vet.card)],
|
|
837
|
-
env: loaded.env,
|
|
838
|
-
logPath: join(dir, `redraft-${n}.log`),
|
|
839
|
-
});
|
|
840
|
-
} catch (e) {
|
|
841
|
-
undo();
|
|
842
|
-
return { status: 500, body: { ok: false, refused: 'spawn', say: `The plan could not be drafted again (${/** @type {any} */ (e)?.code ?? 'error'}). Your answer was not kept; answer again. Nothing was spent.`, draftId: id } };
|
|
843
|
-
}
|
|
844
|
-
child.on('error', () => {});
|
|
845
|
-
writePidFile(dir, child);
|
|
846
|
-
return { status: 202, body: { ok: true, draftId: id, n, redrafting: true } };
|
|
868
|
+
return startRedraft({
|
|
869
|
+
id, dir, v, vet: redraft.vet, env: loaded.env, undoToo: [answerFile],
|
|
870
|
+
marker: { fromPlan: v.plan, answers: redraft.all.map((x) => ({ line: x.line, question: x.question, answer: x.answer })), ...(redraft.left.length ? { left: redraft.left } : {}) },
|
|
871
|
+
argvOf: (n, proseFile, realRoot) => ['draft', proseFile, '--out', join(dir, `draft-${n}`), '--root', realRoot, '--name', redraft.vet.card.flowName, '--no-questions', ...(redraft.action === null ? [] : ['--action', redraft.action]), ...carryArgv(dir, [], v.plan), ...(redraft.picks.length ? ['--picks', JSON.stringify(redraft.picks)] : []), ...(redraft.left.length ? ['--left', redraft.left.map((x) => `${x.line}.${x.rule}`).join(',')] : []), ...(redraft.columns.length ? ['--columns', JSON.stringify(redraft.columns)] : []), ...modelArgv(redraft.vet.card)],
|
|
872
|
+
failSay: (code) => `The plan could not be drafted again (${code}). Your answer was not kept; answer again. Nothing was spent.`,
|
|
873
|
+
});
|
|
847
874
|
},
|
|
848
875
|
|
|
849
876
|
/**
|