fwdloop 0.35.2 → 0.36.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/package.json +1 -1
- package/src/authoring.js +4 -4
- package/src/drafter.js +1 -1
- package/src/pageask.js +6 -1
- package/src/panel/author.js +11 -5
- package/src/panel/authorcard.js +3 -3
- package/src/panel/index.html +33 -8
- package/src/panel/result.js +6 -2
- package/src/report.js +205 -0
- package/src/runner.js +24 -5
- package/src/send.js +19 -82
- package/src/sheetclaims.js +48 -0
- package/src/sheetfind.js +8 -0
- package/src/sheetlook.js +11 -1
- package/src/whole-job.js +90 -14
- package/types/authoring.d.ts +4 -2
- package/types/pageask.d.ts +5 -2
- package/types/panel/result.d.ts +3 -1
- package/types/report.d.ts +45 -0
- package/types/send.d.ts +13 -12
- package/types/sheetclaims.d.ts +15 -0
- package/types/sheetfind.d.ts +1 -0
- package/types/whole-job.d.ts +53 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fwdloop",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.36.0",
|
|
4
4
|
"description": "Describe a job as steps and guardrails; an agent builds the workflow, pauses for humans where you said, checks every step happened, and reruns it under budgets it cannot touch.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
package/src/authoring.js
CHANGED
|
@@ -93,7 +93,7 @@ export function specHash({
|
|
|
93
93
|
* answer file counts as no answer. No questions file = `{ questions: [], open: [] }`.
|
|
94
94
|
* @param {string} planDir
|
|
95
95
|
* 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`.
|
|
96
|
-
* @returns {{ questions: {k:number, line:number, question:string, answer:string|null, at?:string, rule?:string|null, choice?:'agree'|'drop'|'rule', source?:string, ask?:string, ruleNo?:number, ruleText?:string, proposal?:string|null, check?:Record<string, any>, pairRule?:number}[], open: {k:number, line:number, question:string, answer:null}[] }}
|
|
96
|
+
* @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}[] }}
|
|
97
97
|
*/
|
|
98
98
|
export function readQuestions(planDir) {
|
|
99
99
|
const none = { questions: [], open: [] };
|
|
@@ -109,18 +109,18 @@ export function readQuestions(planDir) {
|
|
|
109
109
|
let at;
|
|
110
110
|
/** @type {string|null|undefined} the `~` rule the answer added (null = it left the rule Not checked), as the answer file recorded it */
|
|
111
111
|
let rule;
|
|
112
|
-
/** @type {'agree'|'drop'|'rule'|undefined} M10 am29: which one the answer used (`agree`, `drop` or `rule`), when the file records it */
|
|
112
|
+
/** @type {'agree'|'drop'|'rule'|'column'|undefined} M10 am29: which one the answer used (`agree`, `drop` or `rule`), when the file records it */
|
|
113
113
|
let choice;
|
|
114
114
|
if (a.ok) {
|
|
115
115
|
try {
|
|
116
116
|
const j = JSON.parse(a.text);
|
|
117
117
|
const t = j?.answer;
|
|
118
|
-
if (typeof t === 'string' && t.trim() !== '') { answer = t; if (typeof j.at === 'string') at = j.at; if (j.rule === null || typeof j.rule === 'string') rule = j.rule; if (j.choice === 'agree' || j.choice === 'drop' || j.choice === 'rule') choice = j.choice; }
|
|
118
|
+
if (typeof t === 'string' && t.trim() !== '') { answer = t; if (typeof j.at === 'string') at = j.at; if (j.rule === null || typeof j.rule === 'string') rule = j.rule; if (j.choice === 'agree' || j.choice === 'drop' || j.choice === 'rule' || j.choice === 'column') choice = j.choice; }
|
|
119
119
|
} catch { /* unreadable = unanswered */ }
|
|
120
120
|
}
|
|
121
121
|
return {
|
|
122
122
|
k, line: q.line, question: String(q.question), answer, ...(at === undefined ? {} : { at }), ...(rule === undefined ? {} : { rule }), ...(choice === undefined ? {} : { choice }),
|
|
123
|
-
...(q.source === 'look' ? { source: 'look', ask: q.ask, ruleNo: q.ruleNo, ruleText: q.ruleText, proposal: typeof q.proposal === 'string' ? q.proposal : null, ...(q.check && typeof q.check === 'object' ? { check: q.check } : {}), ...(Number.isInteger(q.pairRule) ? { pairRule: q.pairRule } : {}) } : {}),
|
|
123
|
+
...(q.source === 'look' ? { source: 'look', ask: q.ask, ruleNo: q.ruleNo, ruleText: q.ruleText, proposal: typeof q.proposal === 'string' ? q.proposal : null, ...(q.check && typeof q.check === 'object' ? { check: q.check } : {}), ...(Number.isInteger(q.pairRule) ? { pairRule: q.pairRule } : {}), ...(Array.isArray(q.columns) && q.columns.length > 0 && q.readings && typeof q.readings === 'object' ? { columns: q.columns.map(String), readings: q.readings } : {}) } : {}),
|
|
124
124
|
};
|
|
125
125
|
});
|
|
126
126
|
return { questions, open: /** @type {any} */ (questions.filter((q) => q.answer === null)) };
|
package/src/drafter.js
CHANGED
|
@@ -786,7 +786,7 @@ export async function draft({
|
|
|
786
786
|
return withAction({
|
|
787
787
|
ok: false, declaration: null, reds: tooMany ? [`${tooManyAsksText(counted)} Spent so far: ${spent}.`] : [], rounds: m.rounds, calls, spendComplete: unmetered === 0 && m.costUsd !== null, costUsd: m.costUsd, modelReturned: m.model, modelId, price: priceRecord(prices, rates), tokens: m.tokens, structureRetries: 0, revisions: 0, stop: tooMany ? 'look-asks-too-many' : 'look-asks', log, thinking: thinkingOf(), inputs: facts.list,
|
|
788
788
|
questions: tooMany ? [] : asks.map((a) => ({
|
|
789
|
-
line: a.line, question: a.question, source: a.source, ask: a.ask, ruleNo: 'rule' in a ? a.rule : undefined, ruleText: a.ruleText, proposal: a.reading ?? null, ...('check' in a && a.check ? { check: a.check } : {}),
|
|
789
|
+
line: a.line, question: a.question, source: a.source, ask: a.ask, ruleNo: 'rule' in a ? a.rule : undefined, ruleText: a.ruleText, proposal: a.reading ?? null, ...('check' in a && a.check ? { check: a.check } : {}), ...('columns' in a && Array.isArray(a.columns) ? { columns: a.columns, readings: /** @type {any} */ (a).readings } : {}),
|
|
790
790
|
})),
|
|
791
791
|
droppedQuestions: [], notChecked: pageNotChecked, ...pageExtras,
|
|
792
792
|
});
|
package/src/pageask.js
CHANGED
|
@@ -10,6 +10,9 @@ import { columnTail } from './sheetfind.js';
|
|
|
10
10
|
export const MAX_LOOK_ASKS = 3;
|
|
11
11
|
/** the answer that drops a `~` rule the page cannot check: the person types it (any case, a closing full stop allowed) */
|
|
12
12
|
export const DROP_IT = 'drop it';
|
|
13
|
+
// borrowed-from: bareloop src/questionbox.js@v0.60.0 (CHOICE_SAYS.pickColumn)
|
|
14
|
+
/** M17 am9 item 3: the door's refusal of a wrong answer to a column tie (signed words) */
|
|
15
|
+
export const TIE_PICK_SAY = 'This question has a list to choose from: pick one of the columns, or Drop it. Nothing was saved.';
|
|
13
16
|
/** @param {unknown} text @returns {boolean} */
|
|
14
17
|
export const isDropIt = (text) => String(text ?? '').trim().replace(/\.$/, '').toLowerCase() === DROP_IT;
|
|
15
18
|
/** the answers that accept the code's reading of a rule; anything else the person types is their own reading */
|
|
@@ -119,7 +122,7 @@ export function decidedWords(h) {
|
|
|
119
122
|
* person's own words, taken word for word with newlines folded to spaces. A question that is not a look ask is never changed: its answer is its rule.
|
|
120
123
|
* 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
|
|
121
124
|
* 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).
|
|
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)
|
|
125
|
+
* @param {{source?: string, ask?: string, proposal?: string|null, check?: Record<string, any>, readings?: Record<string, string>}} q @param {unknown} typed @param {'agree'|'drop'|'rule'|'column'} [choice] M10 am29: the button used; absent = today's words reading (CLI, old files)
|
|
123
126
|
* @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)
|
|
124
127
|
*/
|
|
125
128
|
export function ruleOfAnswer(q, typed, choice) {
|
|
@@ -130,6 +133,8 @@ export function ruleOfAnswer(q, typed, choice) {
|
|
|
130
133
|
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
134
|
return { rule: null, left: false, action: 'known', actionLine: choice === 'agree' && typeof q.proposal === 'string' ? q.proposal : typedText };
|
|
132
135
|
}
|
|
136
|
+
// M17 am9 item 4: a column picked from a tie is the reading the tie carried for that column (the rule's words are rewritten in place by applyAnswers); anything not on the list never reaches here (the door refuses it)
|
|
137
|
+
if (choice === 'column') return { rule: q.readings?.[typedText] ?? null, left: q.readings?.[typedText] === undefined };
|
|
133
138
|
if (choice !== undefined) { // M10 am29: a typed choice decides, never the words; the box (`rule`) keeps its words whole
|
|
134
139
|
const shapeC = q.ask === 'check' || q.ask === 'no-check';
|
|
135
140
|
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/panel/author.js
CHANGED
|
@@ -41,7 +41,7 @@ import {
|
|
|
41
41
|
import { rowEditPlan } from '../planrebuild.js';
|
|
42
42
|
import { cardLinesOf } from '../checklistsign.js';
|
|
43
43
|
import { appendSpendRow } from '../provider.js';
|
|
44
|
-
import { ruleOfAnswer, panelQuestionText, DROP_IT } from '../pageask.js';
|
|
44
|
+
import { ruleOfAnswer, panelQuestionText, DROP_IT, TIE_PICK_SAY } from '../pageask.js';
|
|
45
45
|
import { checkFlowName, nextRunId, readFileInside, readdirInside } from '../flow.js';
|
|
46
46
|
import { readModelRecord } from '../flowmodel.js';
|
|
47
47
|
import { isFwdloopAlive } from '../liveness.js';
|
|
@@ -291,7 +291,7 @@ export function createAuthor(opts) {
|
|
|
291
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)
|
|
292
292
|
if (childRunning(dir)) return { ...shared, phase: newest > 0 ? (cur.kind === 'answers' ? 'redrafting' : 'revising') : 'drafting' };
|
|
293
293
|
const lineText = (line) => parseJobBox(typeof card?.job === 'string' ? card.job : '').steps[line - 1]?.text ?? null;
|
|
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
|
+
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), ...(Array.isArray(x.columns) && x.columns.length > 0 ? { columns: x.columns.map((c) => scrub(c, keys)) } : {}) } : {}) }));
|
|
295
295
|
return { ...shared, stepList: stepListOf(dir, rel, keys, true), phase: 'questions-open', plan: rel, questions, openK: q.open[0].k, total: q.questions.length };
|
|
296
296
|
}
|
|
297
297
|
if (q.questions.length > 0) return { ...shared, phase: 'stopped', say: ANSWERS_NOT_DRAFTED_SAY };
|
|
@@ -814,10 +814,14 @@ export function createAuthor(opts) {
|
|
|
814
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.' } };
|
|
815
815
|
{
|
|
816
816
|
const proposes = look && typeof q.proposal === 'string' && (q.ask === 'reading' || q.ask === 'check' || q.ask === 'action');
|
|
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.' } };
|
|
817
|
+
if (choice !== 'agree' && choice !== 'drop' && choice !== 'rule' && choice !== 'column') return { status: 400, body: { ok: false, refused: 'bad-choice', say: 'That answer is not one of the choices. Nothing was saved.' } };
|
|
818
|
+
// M17 am9 item 3: a column tie is a closed question. `column` is taken only as the name of one of ITS OWN tied columns; `rule` and `agree` are refused on it; `column` on any other question is not offered
|
|
819
|
+
if (Array.isArray(q.columns) && q.columns.length > 0) {
|
|
820
|
+
if (choice === 'rule' || choice === 'agree' || (choice === 'column' && !(typeof b.answer === 'string' && q.columns.includes(b.answer)))) return { status: 400, body: { ok: false, refused: 'bad-choice', say: TIE_PICK_SAY } };
|
|
821
|
+
} else if (choice === 'column') return { status: 400, body: { ok: false, refused: 'bad-choice', say: 'That choice is not offered for this question. Nothing was saved.' } };
|
|
818
822
|
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.' } };
|
|
819
823
|
}
|
|
820
|
-
const answer = choice === 'agree' ? 'agree' : choice === 'drop' ? DROP_IT : typeof b.answer === 'string' ? (look ? b.answer.replace(/\s*\n\s*/g, ' ') : b.answer).trim().replace(/^(?:~\s*)+/, '') : '';
|
|
824
|
+
const answer = choice === 'column' ? /** @type {string} */ (b.answer) : choice === 'agree' ? 'agree' : choice === 'drop' ? DROP_IT : typeof b.answer === 'string' ? (look ? b.answer.replace(/\s*\n\s*/g, ' ') : b.answer).trim().replace(/^(?:~\s*)+/, '') : '';
|
|
821
825
|
if (answer === '') return { status: 400, body: { ok: false, refused: 'blank-answer', say: look ? LOOK_BLANK_ANSWER_SAY : BLANK_ANSWER_SAY } };
|
|
822
826
|
if (!look && /[\r\n]/.test(answer)) return { status: 400, body: { ok: false, refused: 'one-line', say: ONE_LINE_ANSWER_SAY } };
|
|
823
827
|
if (keys.some((k) => k.length >= 8 && answer.includes(k))) return { status: 400, body: { ok: false, refused: 'key', say: 'This answer contains an API key. Keys go in Settings only. Nothing was saved.' } };
|
|
@@ -836,7 +840,9 @@ export function createAuthor(opts) {
|
|
|
836
840
|
const all = full.map((x) => {
|
|
837
841
|
const typed = x.k === v.openK ? answer : x.answer;
|
|
838
842
|
const ch = x.k === v.openK ? choice : x.choice;
|
|
839
|
-
|
|
843
|
+
const eff = ruleOfAnswer(x, typed, ch);
|
|
844
|
+
// M17 am9a: a picked column is the agreed column rule, the same shape an Agree to one offered column has, so applyAnswers rewrites the `~` rule in place
|
|
845
|
+
return { line: x.line, question: x.question, answer: typed, ...eff, ruleNo: x.ruleNo, ruleText: x.ruleText, ask: x.ask, proposal: ch === 'column' ? eff.rule : x.proposal };
|
|
840
846
|
});
|
|
841
847
|
const adds = all.filter((x) => x.rule !== null);
|
|
842
848
|
// 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
|
package/src/panel/authorcard.js
CHANGED
|
@@ -184,10 +184,10 @@ export function applyAnswers(job, all) {
|
|
|
184
184
|
const parts = isColumnChoiceRule(x.proposal) && Number.isInteger(x.ruleNo) ? columnChoiceParts(x.rule) : null;
|
|
185
185
|
const swapped = parts ? swapColumnWord(String(x.ruleText ?? ''), parts.word, parts.column) : null;
|
|
186
186
|
// M17 ruling 2: an agreed column for a word that is no `~` rule (the job's prose) adds NO `~` line; it is told to the AI, whose check (if it suggests one) is a `!` `[agent]` row built by code
|
|
187
|
-
//
|
|
188
|
-
const proseCol = isColumnChoiceRule(x.proposal) && isColumnChoiceRule(x.rule) &&
|
|
187
|
+
// M17 am9a: an agreed column answer about a `~` rule always rewrites that rule in place: the word swapped for the column, else `use the column '<c>' for '<w>'`; never only told to the AI
|
|
188
|
+
const proseCol = isColumnChoiceRule(x.proposal) && isColumnChoiceRule(x.rule) && !Number.isInteger(x.ruleNo) ? columnChoiceParts(x.rule) : null;
|
|
189
189
|
if (proseCol) { columns.push({ line: x.line, word: proseCol.word, column: proseCol.column }); continue; }
|
|
190
|
-
if (x.ask !== undefined && Number.isInteger(x.ruleNo)
|
|
190
|
+
if (x.ask !== undefined && Number.isInteger(x.ruleNo)) {
|
|
191
191
|
const r = replaceRuleOnJob(out, x.line, String(x.ruleText ?? ''), swapped ?? x.rule);
|
|
192
192
|
if (r.replaced) { out = r.job; done += 1; }
|
|
193
193
|
} else appends.push({ line: x.line, answer: x.rule });
|
package/src/panel/index.html
CHANGED
|
@@ -744,6 +744,7 @@
|
|
|
744
744
|
.chat-question .q-line{font-size:12px;color:var(--text-faint);margin-top:4px;overflow-wrap:anywhere;}
|
|
745
745
|
.chat-question .q-text{font-size:13px;margin-top:4px;overflow-wrap:anywhere;white-space:pre-wrap;}
|
|
746
746
|
.chat-question textarea{display:block;width:100%;max-width:100%;box-sizing:border-box;margin-top:8px;min-height:3.4em;font:inherit;padding:6px 8px;border:1px solid var(--border-strong);border-radius:0;background:var(--bg);color:var(--text);resize:vertical;}
|
|
747
|
+
.chat-question select{display:block;width:100%;max-width:100%;min-width:0;box-sizing:border-box;margin-top:8px;}
|
|
747
748
|
.chat-question .q-choices{display:flex;flex-wrap:wrap;gap:8px;margin-top:8px;}
|
|
748
749
|
.chat-question .q-choices .btn{flex:1 1 auto;min-width:0;}
|
|
749
750
|
.chat-question .q-or{display:block;font-size:12px;color:var(--text-faint);margin-top:8px;text-transform:none;letter-spacing:normal;font-weight:normal;}
|
|
@@ -1432,6 +1433,7 @@
|
|
|
1432
1433
|
<button class="btn small" type="button" id="chat-q-agree" data-testid="chat-q-agree" hidden>Agree</button>
|
|
1433
1434
|
<button class="btn small" type="button" id="chat-q-drop" data-testid="chat-q-drop" hidden>Drop it</button>
|
|
1434
1435
|
</div>
|
|
1436
|
+
<select id="chat-q-column" data-testid="chat-q-column" aria-label="Choose a column" hidden></select>
|
|
1435
1437
|
<label class="q-or" id="chat-q-or" data-testid="chat-q-or" for="chat-q-answer">Or type a new rule:</label>
|
|
1436
1438
|
<textarea id="chat-q-answer" data-testid="chat-q-answer" rows="2" autocomplete="off" spellcheck="false" aria-label="Your answer" placeholder="Your answer, on one line"></textarea>
|
|
1437
1439
|
<div class="hint q-err" id="chat-q-error" data-testid="chat-q-error" role="alert"></div>
|
|
@@ -2833,9 +2835,11 @@
|
|
|
2833
2835
|
// M15 item 5: the sent file(s), at the top: a link that opens the file, or the server's words (gone / changed) in its place. A run that sent nothing draws nothing.
|
|
2834
2836
|
function resultFileLinks(data){
|
|
2835
2837
|
return (data.delivered || []).map(function(d){
|
|
2836
|
-
|
|
2838
|
+
// M15 am3 item 1: a report saved under a new name says why, in the server's own words (`d.note`)
|
|
2839
|
+
var renamed = d.note ? '<div class="hint" data-testid="result-file-top-note">' + escapeXml(d.note) + '</div>' : "";
|
|
2840
|
+
return resultField("Saved", d.words ? '<div class="rs-warn" data-testid="result-file-top-gone">' + escapeXml(d.name) + ' \u2014 ' + escapeXml(d.words) + '</div>' + renamed
|
|
2837
2841
|
: '<div class="ro-value" data-testid="result-file-top" style="overflow-wrap:anywhere"><a href="/api/runs/' + encodeURIComponent(data.flow) + '/' + encodeURIComponent(data.runId) +
|
|
2838
|
-
'/download?i=' + d.i + '&view=1" target="_blank" rel="noopener noreferrer">' + escapeXml(d.name) + '</a
|
|
2842
|
+
'/download?i=' + d.i + '&view=1" target="_blank" rel="noopener noreferrer">' + escapeXml(d.name) + '</a>' + renamed + '</div>');
|
|
2839
2843
|
}).join("");
|
|
2840
2844
|
}
|
|
2841
2845
|
// `own` = the Result tab read 2+ pages, so this line's box shows its own page
|
|
@@ -2995,6 +2999,7 @@
|
|
|
2995
2999
|
if((data.delivered || []).length){
|
|
2996
3000
|
h += '<div class="job-card" data-testid="result-saved"><h4>Saved</h4>' + data.delivered.map(function(d){
|
|
2997
3001
|
return resultField(d.name, '<div class="ro-value" data-testid="result-path" style="overflow-wrap:anywhere">' + escapeXml(d.path) + '</div>' +
|
|
3002
|
+
(d.note ? '<div class="hint" data-testid="result-file-note">' + escapeXml(d.note) + '</div>' : "") +
|
|
2998
3003
|
(d.words ? '<div class="rs-warn" data-testid="result-file-gone">' + escapeXml(d.words) + '</div>'
|
|
2999
3004
|
: '<div class="run-actions" style="margin:6px 0 0;"><a class="btn" style="text-decoration:none;" data-testid="result-download" download href="/api/runs/' + encodeURIComponent(data.flow) + '/' + encodeURIComponent(data.runId) + '/download?i=' + d.i + '">Download ' + escapeXml(d.name) + '</a></div>'));
|
|
3000
3005
|
}).join("") + '</div>';
|
|
@@ -5716,6 +5721,8 @@
|
|
|
5716
5721
|
var qChoices = document.getElementById("chat-q-choices");
|
|
5717
5722
|
var qAgree = document.getElementById("chat-q-agree");
|
|
5718
5723
|
var qDrop = document.getElementById("chat-q-drop");
|
|
5724
|
+
var qColumn = document.getElementById("chat-q-column");
|
|
5725
|
+
var qOr = document.getElementById("chat-q-or");
|
|
5719
5726
|
var extrasEl = document.getElementById("chat-extras");
|
|
5720
5727
|
var newBox = document.getElementById("jf-new");
|
|
5721
5728
|
var runBox = document.getElementById("jf-run");
|
|
@@ -5964,13 +5971,13 @@
|
|
|
5964
5971
|
if(!q) return null;
|
|
5965
5972
|
// M10 am2 item 1 / am5 item 1: a question the page look raised is ONE plain chat message (bareloop's words); the head and line rows stay empty
|
|
5966
5973
|
if(q.source === "look"){
|
|
5967
|
-
return { key: String(state.draftId) + ":" + q.k, k: q.k, head: "", line: "", question: "A question the plan raised (" + q.k + " of " + state.total + "), about job line " + q.line + ": " + (typeof q.shown === "string" ? q.shown : q.question), agree: q.proposes === true, drop: q.drops === true };
|
|
5974
|
+
return { key: String(state.draftId) + ":" + q.k, k: q.k, head: "", line: "", question: "A question the plan raised (" + q.k + " of " + state.total + "), about job line " + q.line + ": " + (typeof q.shown === "string" ? q.shown : q.question), agree: q.proposes === true, drop: q.drops === true, columns: Array.isArray(q.columns) ? q.columns : [] };
|
|
5968
5975
|
}
|
|
5969
5976
|
return {
|
|
5970
5977
|
key: String(state.draftId) + ":" + q.k, k: q.k,
|
|
5971
5978
|
head: "A question the plan raised (" + q.k + " of " + state.total + ")",
|
|
5972
5979
|
line: q.lineText ? "About job line " + q.line + ": " + q.lineText : "About job line " + q.line,
|
|
5973
|
-
question: q.question, agree: false, drop: false
|
|
5980
|
+
question: q.question, agree: false, drop: false, columns: []
|
|
5974
5981
|
};
|
|
5975
5982
|
}
|
|
5976
5983
|
// pure: the plan view's model for a plan with a list: each job line with its `~` rules, its lead sentence (src/checked.js), the built rows of the list, a sheet line's block; then the suggestions and the three folds
|
|
@@ -6847,6 +6854,15 @@
|
|
|
6847
6854
|
qHead.hidden = v.head === ""; qLine.hidden = v.line === ""; // a look question is one plain message: no empty rows
|
|
6848
6855
|
// M10 am29: every question has the labelled box; a look question also has Agree (only when it proposes something) and Drop it
|
|
6849
6856
|
qAgree.hidden = !v.agree; qDrop.hidden = !v.drop; qChoices.hidden = !(v.agree || v.drop);
|
|
6857
|
+
// M17 am9 item 2: a column tie is a closed question: ONE choose-one picker (a native select) listing every tied column, the answer button, and Drop it; no box to type your own words, no Agree
|
|
6858
|
+
qColumn.textContent = "";
|
|
6859
|
+
qColumn.hidden = v.columns.length === 0;
|
|
6860
|
+
qOr.hidden = v.columns.length > 0; qAnswer.hidden = v.columns.length > 0;
|
|
6861
|
+
if(v.columns.length){
|
|
6862
|
+
var first = document.createElement("option"); first.value = ""; first.textContent = "Choose a column"; qColumn.appendChild(first);
|
|
6863
|
+
v.columns.forEach(function(c){ var o = document.createElement("option"); o.value = c; o.textContent = c; qColumn.appendChild(o); });
|
|
6864
|
+
}
|
|
6865
|
+
qColumn.value = "";
|
|
6850
6866
|
qAnswer.value = ""; qError.textContent = "";
|
|
6851
6867
|
}
|
|
6852
6868
|
}
|
|
@@ -6920,6 +6936,14 @@
|
|
|
6920
6936
|
startOverBtn.disabled = !!st.busy;
|
|
6921
6937
|
fitCardBoxes();
|
|
6922
6938
|
}
|
|
6939
|
+
// M17 am9a item 2: while a session is live the job box follows the server's newest card (`card.job`, the job as `applyAnswers` wrote it after an answer: the rule as answered). The page reads it, never
|
|
6940
|
+
// recomputes it, and never touches the box while Revise has it open for typing.
|
|
6941
|
+
function syncJobBoxFromSession(state){
|
|
6942
|
+
var jt = state && state.card && state.card.job;
|
|
6943
|
+
var box = document.getElementById("jf-job");
|
|
6944
|
+
if(!sessionLive || reviseOpen || typeof jt !== "string" || jt === box.value) return;
|
|
6945
|
+
setVal("jf-job", jt); fitCardBoxes();
|
|
6946
|
+
}
|
|
6923
6947
|
function renderActions(state){
|
|
6924
6948
|
lastState = state;
|
|
6925
6949
|
renderQuestion(state);
|
|
@@ -6932,6 +6956,7 @@
|
|
|
6932
6956
|
var progressChanged = renderProgress(stepsFor(state, {model: drafterModel, starting: startId !== null, signClicked: signClickedOnce}));
|
|
6933
6957
|
sessionLive = CLIENT_TERMINAL_PHASES.indexOf(state.phase) === -1;
|
|
6934
6958
|
refreshStartEnabled();
|
|
6959
|
+
syncJobBoxFromSession(state);
|
|
6935
6960
|
// while the draft is live and the list changed, bring the newest progress line into view.
|
|
6936
6961
|
// Never moves keyboard focus, and an unchanged poll tick never scrolls.
|
|
6937
6962
|
if(progressChanged && sessionLive && progressRow.lastElementChild){
|
|
@@ -7083,16 +7108,16 @@
|
|
|
7083
7108
|
});
|
|
7084
7109
|
function doAnswer(choice){
|
|
7085
7110
|
if(qBusy || !sessionId || !lastState || lastState.phase !== "questions-open") return;
|
|
7086
|
-
qBusy = true; qSend.disabled = true; qAgree.disabled = true; qDrop.disabled = true; qError.textContent = "";
|
|
7111
|
+
qBusy = true; qSend.disabled = true; qAgree.disabled = true; qDrop.disabled = true; qColumn.disabled = true; qError.textContent = "";
|
|
7087
7112
|
var id = sessionId;
|
|
7088
|
-
var body = choice === "agree" || choice === "drop" ? {k: lastState.openK, choice: choice} : {k: lastState.openK, answer: qAnswer.value, choice: "rule"};
|
|
7113
|
+
var body = choice === "agree" || choice === "drop" ? {k: lastState.openK, choice: choice} : !qColumn.hidden ? {k: lastState.openK, answer: qColumn.value, choice: "column"} : {k: lastState.openK, answer: qAnswer.value, choice: "rule"};
|
|
7089
7114
|
authorPost("/api/author/" + id + "/answer", body).then(function(r){
|
|
7090
|
-
qBusy = false; qSend.disabled = false; qAgree.disabled = false; qDrop.disabled = false;
|
|
7115
|
+
qBusy = false; qSend.disabled = false; qAgree.disabled = false; qDrop.disabled = false; qColumn.disabled = false;
|
|
7091
7116
|
if(id !== sessionId) return;
|
|
7092
7117
|
if(!(r.status >= 200 && r.status < 300 && r.body && r.body.ok === true)){ qError.textContent = refusalText(r); return; }
|
|
7093
7118
|
qAnswer.value = "";
|
|
7094
7119
|
poll();
|
|
7095
|
-
}).catch(function(){ qBusy = false; qSend.disabled = false; qAgree.disabled = false; qDrop.disabled = false; qError.textContent = NETWORK_SAY; });
|
|
7120
|
+
}).catch(function(){ qBusy = false; qSend.disabled = false; qAgree.disabled = false; qDrop.disabled = false; qColumn.disabled = false; qError.textContent = NETWORK_SAY; });
|
|
7096
7121
|
}
|
|
7097
7122
|
function doDraft(startedOverFrom){
|
|
7098
7123
|
clearFieldErrors();
|
package/src/panel/result.js
CHANGED
|
@@ -15,6 +15,7 @@ import { readFileInside } from '../flow.js';
|
|
|
15
15
|
import { isCellsPath } from '../closers.js';
|
|
16
16
|
import { readAcceptedHashesByEmits } from '../ask.js';
|
|
17
17
|
import { notCheckedLabelOf } from '../checked.js';
|
|
18
|
+
import { REPORT_RENAMED } from '../report.js';
|
|
18
19
|
import { checkSendDestination, readArtifactResult } from '../runner.js';
|
|
19
20
|
import { flowTypeOf } from '../declaration.js';
|
|
20
21
|
import { isAgree, readingOfQuestion } from '../pageask.js';
|
|
@@ -181,7 +182,7 @@ export function readDelivered(rec) {
|
|
|
181
182
|
* The files this run's signed sends wrote: for each signed send whose send step ended green in the audit, the file `<flow>-<runId>-<emits>.md`
|
|
182
183
|
* in the signed folder with the sha256 the send recorded for it (M15), or, for a send older than M15, `.json` with the sha256 the human's accept recorded for the ask that
|
|
183
184
|
* send reads (`readAcceptedHashesByEmits`, the same record the send itself checked). No accepted hash = recorded as null, which reads as "changed", never as ok.
|
|
184
|
-
* @returns {{path: string, dir: string|null, name: string, sha256: string|null}[]}
|
|
185
|
+
* @returns {{path: string, dir: string|null, name: string, note: string|null, sha256: string|null}[]}
|
|
185
186
|
*/
|
|
186
187
|
export function deliveredOf({
|
|
187
188
|
arbiter, declaration, runDir, root, flow, runId, auditRows,
|
|
@@ -197,11 +198,13 @@ export function deliveredOf({
|
|
|
197
198
|
if (!step || !sentRow) continue; // eslint-disable-line no-continue
|
|
198
199
|
// M15 item 4: a send since M15 wrote `<emits>.md` and recorded that file's own sha256 on its green audit row; an older send wrote the JSON, bound to the accept's hash
|
|
199
200
|
const plain = isStr(sentRow.sentSha256) && sentRow.sentSha256 !== '';
|
|
200
|
-
|
|
201
|
+
// M15 am3: a send since am3 recorded the name it wrote (`sentName`, `<job>-YYYY-MM-DD[-n].md`); an older .md send is `<flow>-<runId>-<emits>.md`, an older still the .json. Old files are not renamed.
|
|
202
|
+
const name = plain && isStr(sentRow.sentName) && sentRow.sentName !== '' ? sentRow.sentName : `${flow}-${runId}-${step.emits}.${plain ? 'md' : 'json'}`;
|
|
201
203
|
const dest = checkSendDestination(`${send.target.kind}:${send.target.path}`, { root, runDir });
|
|
202
204
|
const [askId] = (step.reads ?? []).filter((id) => askEmits.has(id));
|
|
203
205
|
out.push({
|
|
204
206
|
path: join(dest.ok ? dest.dir : send.target.path, name), dir: dest.ok ? dest.dir : null, name,
|
|
207
|
+
note: plain && isStr(sentRow.sentTaken) && sentRow.sentTaken !== '' ? REPORT_RENAMED(sentRow.sentTaken) : null,
|
|
205
208
|
sha256: plain ? sentRow.sentSha256 : (hashes.ok && askId !== undefined ? (hashes.byEmits.get(askId) ?? null) : null),
|
|
206
209
|
});
|
|
207
210
|
}
|
|
@@ -283,6 +286,7 @@ export function buildResult({
|
|
|
283
286
|
return {
|
|
284
287
|
i, path: d.path, name: d.name, bytes: got.buf ? got.buf.length : null, state: got.state,
|
|
285
288
|
words: got.state === 'gone' ? RESULT_FILE_GONE : (got.state === 'changed' ? RESULT_FILE_CHANGED : null),
|
|
289
|
+
note: d.note,
|
|
286
290
|
};
|
|
287
291
|
});
|
|
288
292
|
// a run that failed delivered nothing: say its own first gap, never rows. A stop, a cap halt, a rerun and an expired ask are not a failure (the same
|
package/src/report.js
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
// M15 am3 (docs/wiki/the-module-ladder.md, "M15 am3 - one markdown report per run"): the ONE writer of the report's words. The body (every line's section, in job order) is built by code at the last
|
|
2
|
+
// Ask (`wholeJobText`, src/whole-job.js) and is what the person accepts; the send step adds the title and the `Passed` line after the accept (`reportFileText`) and picks the file's name (`nextFreeName`).
|
|
3
|
+
// borrowed-from: bareloop src/resultmd.js@v0.60.0 (leaves, words, friendlyName, blockLines, isResultList, claimLines, reportBullet, plainDate, stepSection, the section writer of renderRunMd) and src/source.js@v0.60.0 (pickDelivery, the name clean-up).
|
|
4
|
+
// Adapted to fwd's run data: one JSON artifact per step, a sheet step's claim boxes at the top of its artifact, the close from the signed declaration.
|
|
5
|
+
// What this throws away: a result's keys other than `quote` and `values`; a claim box no check of the line carries; an artifact key that is neither text, results nor a claim; the AI's own count and total (code's are written).
|
|
6
|
+
// Third outcomes: a line whose artifact holds neither text, results nor a written claim has no section (as bareloop: nothing to write is not a heading alone); an artifact that is not an object has no section.
|
|
7
|
+
import { lstatSync } from 'node:fs';
|
|
8
|
+
import { join } from 'node:path';
|
|
9
|
+
import { sheetCheckSentence } from './sheetchecks.js';
|
|
10
|
+
import { sheetTotalLines, ROW_MATH_OPS } from './sheetclaims.js';
|
|
11
|
+
import { lineRules } from './pagebits.js';
|
|
12
|
+
|
|
13
|
+
const SCALAR = ['string', 'number', 'boolean'];
|
|
14
|
+
const isRec = (/** @type {unknown} */ v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
15
|
+
|
|
16
|
+
/** the words under a not-checked answer and a checked one (M15 am3 item 2) */
|
|
17
|
+
export const NOT_CHECKED_HEADING = '### The AI\'s answer (not checked — you judge it at Accept)';
|
|
18
|
+
export const CHECKED_HEADING = '### The answer';
|
|
19
|
+
/** an Ask line, in M13 am9's words */
|
|
20
|
+
export const askLineWords = (/** @type {number} */ n) => `Line ${n}: you accepted this at the Ask.`;
|
|
21
|
+
/** the Result tab's note for a report saved under a new name (code-owned; the page types no words) @param {string} taken */
|
|
22
|
+
export const REPORT_RENAMED = (taken) => `saved under a new name because ${taken} was already taken`;
|
|
23
|
+
|
|
24
|
+
/** one value as leaf lines `{parts, text}`: parts are the names on the way in; a string as it is, a number or boolean written out; a list of plain values joined by ", "; null as empty */
|
|
25
|
+
/** @param {string[]} parts @param {any} v @returns {{parts: string[], text: string}[]} */
|
|
26
|
+
function leaves(parts, v) {
|
|
27
|
+
if (v === null || v === undefined) return [{ parts, text: '' }];
|
|
28
|
+
if (SCALAR.includes(typeof v)) return [{ parts, text: `${v}` }];
|
|
29
|
+
if (Array.isArray(v) && v.every((x) => x === null || SCALAR.includes(typeof x))) return [{ parts, text: v.join(', ') }];
|
|
30
|
+
if (Array.isArray(v)) return v.flatMap((x, i) => leaves([...parts, `${i + 1}`], x));
|
|
31
|
+
return Object.entries(v).flatMap(([k, x]) => leaves([...parts, k], x));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** @param {string} name split only at a lowercase-to-capital boundary, `_`, `-` and spaces, so `ID` stays one word */
|
|
35
|
+
const words = (name) => name.replace(/([a-z0-9])([A-Z])/g, '$1 $2').split(/[_\-\s]+/).filter(Boolean);
|
|
36
|
+
|
|
37
|
+
/** the names as plain words (M15 am2 (1)); a last name of `value` or `rows` is left out; the first letter capital, the later words lowercase @param {string[]} parts */
|
|
38
|
+
function friendlyName(parts) {
|
|
39
|
+
const p = parts.length > 1 && (parts[parts.length - 1] === 'value' || parts[parts.length - 1] === 'rows') ? parts.slice(0, -1) : parts;
|
|
40
|
+
const w = p.flatMap(words).map((x) => x.toLowerCase());
|
|
41
|
+
if (!w.length) return parts.join('.');
|
|
42
|
+
return w[0][0].toUpperCase() + w[0].slice(1) + (w.length > 1 ? ` ${w.slice(1).join(' ')}` : '');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** the lines of one block, each a bullet; two lines with the same words both keep the `a.b` form @param {{parts: string[], text: string}[]} ls */
|
|
46
|
+
function blockLines(ls) {
|
|
47
|
+
const f = ls.map((l) => friendlyName(l.parts));
|
|
48
|
+
/** @type {Record<string, number>} */
|
|
49
|
+
const n = {};
|
|
50
|
+
for (const x of f) n[x] = (n[x] || 0) + 1;
|
|
51
|
+
return ls.map((l, i) => `- ${n[f[i]] > 1 ? l.parts.join('.') : f[i]}: ${l.text}`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** a list of results: every item an object holding a `values` object @param {any} v */
|
|
55
|
+
const isResultList = (v) => Array.isArray(v) && v.length > 0 && v.every((r) => isRec(r) && isRec(r.values));
|
|
56
|
+
|
|
57
|
+
/** the box keys that only say what the box holds: left out of a line's name */
|
|
58
|
+
const BOX_KEYS = ['value', 'rows', 'keys', 'values', 'totals'];
|
|
59
|
+
/** a box that maps a row number to its value */
|
|
60
|
+
const ROW_MAPS = ['days', 'bands'];
|
|
61
|
+
const cap = (/** @type {string} */ s) => (s ? s[0].toUpperCase() + s.slice(1) : s);
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The claim bullets of a sheet step. A claim id is named with the plain sentence of the first passed check that carries it and is not a sumIf / countIf; a claim only sumIf / countIf carry is null (code computes it, the AI's
|
|
65
|
+
* number is never written); a box no check carries is left out. A map of rows (`days`, `bands`) writes one bullet per row.
|
|
66
|
+
* @param {Record<string, any>} claims @param {Record<string, string|null>} claimWords @returns {string[]}
|
|
67
|
+
*/
|
|
68
|
+
function claimLines(claims, claimWords) {
|
|
69
|
+
/** @type {string[]} */
|
|
70
|
+
const out = [];
|
|
71
|
+
for (const [id, box] of Object.entries(claims)) {
|
|
72
|
+
if (!Object.hasOwn(claimWords, id) || claimWords[id] === null) continue;
|
|
73
|
+
const label = cap(/** @type {string} */ (claimWords[id]));
|
|
74
|
+
for (const l of leaves([], box)) {
|
|
75
|
+
let p = l.parts;
|
|
76
|
+
if (p.length === 2 && ROW_MAPS.includes(p[0])) { out.push(`- ${label}, row ${p[1]}: ${l.text}`); continue; }
|
|
77
|
+
if (p.length > 0 && BOX_KEYS.includes(p[p.length - 1])) p = p.slice(0, -1);
|
|
78
|
+
out.push(`- ${p.length ? `${label}, ${p.flatMap(words).map((x) => x.toLowerCase()).join(' ')}` : label}: ${l.text}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const COMPUTED = ' (computed by code from the rows named)';
|
|
85
|
+
|
|
86
|
+
/** code's own line (`Count of rows 3, 5: 2 (computed by code from the rows named)`) as a bullet `- Count: 2` / `- Total: 1,234.50` @param {string} line */
|
|
87
|
+
function reportBullet(line) {
|
|
88
|
+
const m = /^(Count|Total) of [^:]*: (.*)$/.exec(line);
|
|
89
|
+
const rest = (m ? m[2] : line).endsWith(COMPUTED) ? (m ? m[2] : line).slice(0, -COMPUTED.length) : (m ? m[2] : line);
|
|
90
|
+
return m ? `- ${m[1]}: ${rest}` : `- ${rest}`;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* claim id -> the sentence of the first passed non-sumIf/countIf check carrying it; a claim only sumIf/countIf carry is null. `okIds` = the ids of the checks that passed, or null = no record (all count).
|
|
95
|
+
* @param {any[]} checks @param {Set<string>|null} okIds @returns {Record<string, string|null>}
|
|
96
|
+
*/
|
|
97
|
+
export function claimWordsOf(checks, okIds) {
|
|
98
|
+
/** @type {Record<string, string|null>} */
|
|
99
|
+
const out = {};
|
|
100
|
+
/** @type {Set<string>} */
|
|
101
|
+
const seen = new Set();
|
|
102
|
+
for (const c of checks) {
|
|
103
|
+
if (!isRec(c) || typeof c.claim !== 'string') continue;
|
|
104
|
+
seen.add(c.claim);
|
|
105
|
+
if (c.rule === 'cells' && ROW_MATH_OPS.includes(c.op)) continue;
|
|
106
|
+
if (okIds && !okIds.has(c.id)) continue;
|
|
107
|
+
if (typeof out[c.claim] !== 'string') out[c.claim] = sheetCheckSentence(c);
|
|
108
|
+
}
|
|
109
|
+
for (const id of seen) if (!Object.hasOwn(out, id)) out[id] = null;
|
|
110
|
+
return out;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** the date as plain words, `18 Nov 2026`, in the machine's local day (the day the dated file names use) @param {Date} d */
|
|
114
|
+
export function plainDate(d) {
|
|
115
|
+
return `${d.getDate()} ${['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][d.getMonth()]} ${d.getFullYear()}`;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** the run number when the run id reads `run-N`, else null (a rerun id `run-1-rerun-1` has none) @param {string} runId @returns {number|null} */
|
|
119
|
+
export function runNumberOf(runId) {
|
|
120
|
+
const m = /^run-(\d+)$/.exec(String(runId));
|
|
121
|
+
return m ? Number(m[1]) : null;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** the title and the `Passed` line, written by the send step (M15 am3 item 2) @param {string} job @param {number|null} runNo @param {Date} now */
|
|
125
|
+
export const reportHead = (job, runNo, now) => `# ${job}${runNo === null ? '' : ` — run-${runNo}`}\nPassed · ${plainDate(now)}`;
|
|
126
|
+
|
|
127
|
+
/** the whole file: the title and the Passed line, then the accepted body @param {string} job @param {number|null} runNo @param {Date} now @param {string} body */
|
|
128
|
+
export const reportFileText = (job, runNo, now, body) => `${reportHead(job, runNo, now)}\n\n${body}\n`;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* One line's section parts: `checked` blocks (`#### Result k` blocks and the bullets) and `answer`, the AI's own text, or null.
|
|
132
|
+
* @param {{artifact: unknown, checks: any[], okIds: Set<string>|null, tables: Record<string, any>}} o
|
|
133
|
+
* @returns {{checked: string[], answer: string|null}|null}
|
|
134
|
+
*/
|
|
135
|
+
function stepSection({ artifact, checks, okIds, tables }) {
|
|
136
|
+
if (!isRec(artifact)) return null;
|
|
137
|
+
const a = /** @type {Record<string, any>} */ (artifact);
|
|
138
|
+
const hasText = typeof a.text === 'string';
|
|
139
|
+
/** @type {string[]} */
|
|
140
|
+
const checked = [];
|
|
141
|
+
if (isResultList(a.results)) {
|
|
142
|
+
a.results.forEach((/** @type {any} */ r, /** @type {number} */ i) => {
|
|
143
|
+
const lines = blockLines(Object.entries(r.values).flatMap(([n, x]) => leaves([n], x)));
|
|
144
|
+
checked.push([`#### Result ${i + 1}`, ...lines, ...(typeof r.quote === 'string' ? ['', `from the page: "${r.quote}"`] : [])].join('\n'));
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
const sheet = checks.filter((c) => isRec(c) && c.rule === 'cells');
|
|
148
|
+
// a sheet step's boxes are its artifact's keys named by a check's claim; nothing else of the artifact is a claim
|
|
149
|
+
const claimIds = new Set(sheet.map((c) => c.claim).filter((x) => typeof x === 'string'));
|
|
150
|
+
const claims = Object.fromEntries(Object.entries(a).filter(([k]) => claimIds.has(k)));
|
|
151
|
+
// Count then Total, whatever the order of the signed checks
|
|
152
|
+
const counted = sheetTotalLines(sheet, claims, tables).sort((x, y) => Number(y.startsWith('Count of')) - Number(x.startsWith('Count of')));
|
|
153
|
+
const bullets = [...claimLines(claims, claimWordsOf(sheet, okIds)), ...counted.map(reportBullet)];
|
|
154
|
+
if (bullets.length) checked.push(bullets.join('\n'));
|
|
155
|
+
const answer = hasText && /** @type {string} */ (a.text).trim() !== '' ? /** @type {string} */ (a.text) : null;
|
|
156
|
+
return checked.length === 0 && answer === null ? null : { checked, answer };
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* The body: every line before the send, in job order. A work line is `## <n>. <text>`, a `Rule:` per ~ rule, `### Checked by code` (bullets) and the AI's text under its heading; an Ask line is one line
|
|
161
|
+
* in its place; a work line with nothing to write has no section. Pure.
|
|
162
|
+
* @param {{n: number, kind: 'ask'|'work', text?: string, rules?: string[], artifact?: unknown, checks?: any[], okIds?: Set<string>|null, proseChecked?: boolean}[]} lines
|
|
163
|
+
* @param {Record<string, any>} tables the frozen sheets by input name
|
|
164
|
+
* @returns {string}
|
|
165
|
+
*/
|
|
166
|
+
export function renderReportBody(lines, tables) {
|
|
167
|
+
/** @type {string[]} */
|
|
168
|
+
const sections = [];
|
|
169
|
+
for (const l of lines) {
|
|
170
|
+
if (l.kind === 'ask') { sections.push(askLineWords(l.n)); continue; }
|
|
171
|
+
const sec = stepSection({ artifact: l.artifact, checks: l.checks ?? [], okIds: l.okIds ?? null, tables });
|
|
172
|
+
if (sec === null) continue;
|
|
173
|
+
const parts = [[`## ${l.n}. ${l.text}`, ...lineRules({ rules: l.rules }).map((r) => `Rule: ${r}`)].join('\n')];
|
|
174
|
+
if (sec.checked.length) parts.push(['### Checked by code', sec.checked.join('\n\n')].join('\n'));
|
|
175
|
+
if (sec.answer !== null) parts.push([l.proseChecked ? CHECKED_HEADING : NOT_CHECKED_HEADING, sec.answer].join('\n'));
|
|
176
|
+
sections.push(parts.join('\n\n'));
|
|
177
|
+
}
|
|
178
|
+
return sections.join('\n\n');
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** is anything at this path (lstat: a dangling symlink counts as present) @param {string} p */
|
|
182
|
+
function present(p) {
|
|
183
|
+
try { lstatSync(p); return true; } catch (err) { return /** @type {any} */ (err).code !== 'ENOENT'; }
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** the most same-day names tried before the send stops (bareloop's MAX_SAME_DAY) */
|
|
187
|
+
export const MAX_SAME_DAY = 99;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* The file name for a report: `<job>-YYYY-MM-DD.md`, then `<job>-YYYY-MM-DD-2.md`, `-3`, ... the first one that is free in `dir` (the machine's local day). Never a taken name. `taken` = the first choice
|
|
191
|
+
* when it was not free (the Result tab's note names it), else null. `name` = null when every name up to -99 is taken.
|
|
192
|
+
* @param {string} dir the Destination folder @param {string} job @param {Date} now
|
|
193
|
+
* @returns {{name: string|null, taken: string|null}}
|
|
194
|
+
*/
|
|
195
|
+
export function nextFreeName(dir, job, now) {
|
|
196
|
+
const clean = String(job).replace(/[/\\\0]/g, '-').replace(/^\.+/, '') || 'report';
|
|
197
|
+
const pad = (/** @type {number} */ n) => String(n).padStart(2, '0');
|
|
198
|
+
const base = `${clean}-${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`;
|
|
199
|
+
const first = `${base}.md`;
|
|
200
|
+
for (let n = 1; n <= MAX_SAME_DAY; n += 1) {
|
|
201
|
+
const name = n === 1 ? first : `${base}-${n}.md`;
|
|
202
|
+
if (!present(join(dir, name))) return { name, taken: n === 1 ? null : first };
|
|
203
|
+
}
|
|
204
|
+
return { name: null, taken: first };
|
|
205
|
+
}
|