fwdloop 0.31.0 → 0.32.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/drafter.js +39 -12
- package/src/jsonbrace.js +21 -0
- package/src/panel/author.js +3 -1
- package/src/sheetlook.js +2 -2
- package/src/sheetoffer.js +1 -1
- package/src/sheetrun.js +27 -0
- package/types/jsonbrace.d.ts +8 -0
- package/types/sheetrun.d.ts +12 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fwdloop",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.32.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/drafter.js
CHANGED
|
@@ -22,6 +22,7 @@ import { validateDeclaration, checkGuardrailSums, checkSendLineGuardrail } from
|
|
|
22
22
|
import { readEveryStep } from './whole-job.js';
|
|
23
23
|
import { loadCatalogue } from './catalogue.js';
|
|
24
24
|
import { findMcpPlanRed } from './canrun.js';
|
|
25
|
+
import { tableChecksFailingOnInput } from './sheetrun.js';
|
|
25
26
|
import { WIRED_VERBS, wiredMenu } from './primitives.js';
|
|
26
27
|
import { ticketSourcesOf, ticketFactsLines, mcpFactsLines, ticketSchemaParts, ticketReds, userMcpServers } from './ticket-draft.js';
|
|
27
28
|
import { readInputFacts } from './input-facts.js';
|
|
@@ -50,6 +51,7 @@ import {
|
|
|
50
51
|
import { LIVE_PROVIDER_OPTIONS } from './model-step.js';
|
|
51
52
|
import { ConfigError } from './config.js';
|
|
52
53
|
import { thinkingSay, worstThinkingStatus } from './thinking.js';
|
|
54
|
+
import { repairTrailingBraces } from './jsonbrace.js';
|
|
53
55
|
|
|
54
56
|
export const MAX_STRUCTURE_RETRIES = 2;
|
|
55
57
|
export const MAX_REVISIONS = 2;
|
|
@@ -851,15 +853,9 @@ export async function draft({
|
|
|
851
853
|
break;
|
|
852
854
|
}
|
|
853
855
|
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
const why = result?.stopReason === 'max_tokens' ? 'truncated: the round hit the output cap with no completed tool call'
|
|
857
|
-
: malformed ? `the tool call's arguments were not valid JSON (${malformed.error})`
|
|
858
|
-
: 'no usable tool call (text instead of the tool)';
|
|
856
|
+
// M4d am39: a structure failure is handled by one function, so a brace repair that the validator then refuses takes the very same path.
|
|
857
|
+
const structureFailure = (/** @type {string} */ why) => {
|
|
859
858
|
entry.outcome = `structure: ${why}`;
|
|
860
|
-
// the raw answer is kept (log.json): the unparseable arguments as sent, else the model's text
|
|
861
|
-
if (typeof malformed?.rawArguments === 'string') entry.rawArguments = malformed.rawArguments;
|
|
862
|
-
else if (typeof result?.text === 'string' && result.text !== '') entry.rawText = result.text;
|
|
863
859
|
log.push(entry);
|
|
864
860
|
lastReds = [why];
|
|
865
861
|
// M4d am3 A3: a round cut off at the output cap before tries 1 and 2 are spent is a FAILED TRY, advancing the same counter a
|
|
@@ -873,15 +869,36 @@ export async function draft({
|
|
|
873
869
|
failedLines = lineNums;
|
|
874
870
|
userText += `\n\n${QUESTIONS_PROMPT}`;
|
|
875
871
|
}
|
|
876
|
-
continue;
|
|
872
|
+
return 'continue';
|
|
877
873
|
}
|
|
878
|
-
if (structureRetries >= MAX_STRUCTURE_RETRIES) { stop = 'structure'; break; }
|
|
874
|
+
if (structureRetries >= MAX_STRUCTURE_RETRIES) { stop = 'structure'; return 'break'; }
|
|
879
875
|
structureRetries += 1;
|
|
880
876
|
nextKind = 'structure-retry';
|
|
881
877
|
userText = `Your last reply was not a usable tool call (${why}). Call ${TOOL} now with a complete, valid JSON declaration.`;
|
|
882
878
|
if (validatorReds.length) userText += `\n\nThe last declaration you emitted was still refused by the validator; keep fixing these too:\n${validatorReds.map((r) => `- ${r}`).join('\n')}`;
|
|
883
879
|
if (askOpen) userText += `\n\n${QUESTIONS_PROMPT}`;
|
|
884
|
-
continue;
|
|
880
|
+
return 'continue';
|
|
881
|
+
};
|
|
882
|
+
/** @type {string | null} the structure reason, kept while a brace-repaired answer waits for the validator */
|
|
883
|
+
let braceWhy = null;
|
|
884
|
+
if (!isPlainObject(captured)) {
|
|
885
|
+
const malformed = provider?.lastMalformedToolCall ?? null;
|
|
886
|
+
const why = result?.stopReason === 'max_tokens' ? 'truncated: the round hit the output cap with no completed tool call'
|
|
887
|
+
: malformed ? `the tool call's arguments were not valid JSON (${malformed.error})`
|
|
888
|
+
: 'no usable tool call (text instead of the tool)';
|
|
889
|
+
// the raw answer is kept (log.json): the unparseable arguments as sent, else the model's text
|
|
890
|
+
if (typeof malformed?.rawArguments === 'string') entry.rawArguments = malformed.rawArguments;
|
|
891
|
+
else if (typeof result?.text === 'string' && result.text !== '') entry.rawText = result.text;
|
|
892
|
+
// M4d am39: only a malformed-JSON round (never a cut-off, never text) whose answer is a complete object plus trailing `}` is repaired
|
|
893
|
+
const fixed = malformed && result?.stopReason !== 'max_tokens' ? repairTrailingBraces(malformed.rawArguments) : null;
|
|
894
|
+
if (!fixed) {
|
|
895
|
+
const next = structureFailure(why);
|
|
896
|
+
if (next === 'break') break;
|
|
897
|
+
continue;
|
|
898
|
+
}
|
|
899
|
+
captured = fixed.value;
|
|
900
|
+
braceWhy = why;
|
|
901
|
+
entry.braceRepair = { dropped: fixed.dropped, used: true };
|
|
885
902
|
}
|
|
886
903
|
|
|
887
904
|
// `notChecked` was offered on every try, so it is information and never reaches the validator. `questions` is stripped only where it was
|
|
@@ -923,8 +940,18 @@ export async function draft({
|
|
|
923
940
|
pageWords: { texts: { ...(facts.docs ?? {}), ...Object.fromEntries(Object.entries(pages).map(([role, pg]) => [role, pg.text])) }, look: pageSources.length ? { facts: look.facts, dropped: look.dropped } : null, docs: docRolesOf(arbiter.sources) },
|
|
924
941
|
});
|
|
925
942
|
// M13 piece 4 (F105 rewritten): a generic MCP job whose steps call none of its tools is fed back like any validator red (the run would refuse it at $0, by the same sentence)
|
|
943
|
+
// M4d am39: a brace-repaired answer the validator finds an unknown key in is not used; the round is a structure failure, as today
|
|
944
|
+
if (braceWhy !== null && !verdict1.ok && verdict1.reds.some((r) => /unknown key/.test(r))) {
|
|
945
|
+
entry.braceRepair = { ...entry.braceRepair, used: false };
|
|
946
|
+
delete entry.retention;
|
|
947
|
+
const next = structureFailure(braceWhy);
|
|
948
|
+
if (next === 'break') break;
|
|
949
|
+
continue;
|
|
950
|
+
}
|
|
926
951
|
const planRed = verdict1.ok ? findMcpPlanRed(declaration) : null;
|
|
927
|
-
|
|
952
|
+
// M10b am5: a `table` check that already fails on the sheet this draft was made with is a red ($0: bareguard's checkStep on the draft-time table, no model call)
|
|
953
|
+
const tableReds = verdict1.ok && sheetTables ? await tableChecksFailingOnInput(declaration, sheetTables) : [];
|
|
954
|
+
const verdict = planRed ? { ok: false, reds: [planRed] } : tableReds.length ? { ok: false, reds: tableReds } : verdict1;
|
|
928
955
|
lastDecl = declaration;
|
|
929
956
|
const asked = askOpen ? normalizeQuestions(rawQuestions, failedLines) : { kept: [], dropped: [] };
|
|
930
957
|
extras = { questions: asked.kept, droppedQuestions: asked.dropped, notChecked: [...new Set([...pageNotChecked, ...cleanNotChecked(rawNotChecked), ...uncoveredRules(declaration, jobLines, Object.keys(facts.sheets ?? {}))])] };
|
package/src/jsonbrace.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// borrowed-from: poc/f183-brace/repair.mjs (the repair rule, M4d am39)
|
|
2
|
+
// A drafting answer that is a complete JSON object followed ONLY by `}` characters and whitespace: drop exactly those
|
|
3
|
+
// trailing characters and parse the rest. Anything else (trailing `]`, text, `}x`, a truncated object, two objects,
|
|
4
|
+
// an array root) returns null. The caller calls this only for a round whose reason is malformed JSON.
|
|
5
|
+
/**
|
|
6
|
+
* @param {unknown} raw
|
|
7
|
+
* @returns {{ value: Record<string, any>, dropped: string } | null}
|
|
8
|
+
*/
|
|
9
|
+
export function repairTrailingBraces(raw) {
|
|
10
|
+
if (typeof raw !== 'string') return null;
|
|
11
|
+
let cut = raw.trimEnd();
|
|
12
|
+
if (!cut.endsWith('}')) return null;
|
|
13
|
+
for (;;) {
|
|
14
|
+
cut = cut.slice(0, -1).trimEnd();
|
|
15
|
+
if (!cut.endsWith('}')) return null;
|
|
16
|
+
let value;
|
|
17
|
+
try { value = JSON.parse(cut); } catch { continue; }
|
|
18
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value)) return null;
|
|
19
|
+
return { value, dropped: raw.slice(cut.length) };
|
|
20
|
+
}
|
|
21
|
+
}
|
package/src/panel/author.js
CHANGED
|
@@ -752,7 +752,9 @@ export function createAuthor(opts) {
|
|
|
752
752
|
// 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
|
|
753
753
|
// M10 am29: the button used rides as a typed `choice`; absent = the words reading (CLI and old pages). agree needs a proposal, drop/agree are look asks only.
|
|
754
754
|
const choice = b.choice;
|
|
755
|
-
|
|
755
|
+
// 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)
|
|
756
|
+
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.' } };
|
|
757
|
+
{
|
|
756
758
|
const proposes = look && typeof q.proposal === 'string' && (q.ask === 'reading' || q.ask === 'check');
|
|
757
759
|
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.' } };
|
|
758
760
|
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.' } };
|
package/src/sheetlook.js
CHANGED
|
@@ -104,8 +104,8 @@ export function applySheetWords(text, words, jobLines, label) {
|
|
|
104
104
|
if (w.kind !== 'number') { dropped.push({ ...rec, reason: 'no-column' }); continue; }
|
|
105
105
|
if (found.kind === 'tie') { dropped.push({ ...rec, reason: 'column-tie', other: found.columns.map((c) => `"${c}"`).join(', ') }); continue; }
|
|
106
106
|
if (found.kind === 'none') { dropped.push({ ...rec, reason: 'no-fit', other: String(found.rows) }); continue; }
|
|
107
|
-
// the person already named this column in
|
|
108
|
-
if (rules.some((r, i) =>
|
|
107
|
+
// the person already named this column in a rule of the line (an answer they gave, or their own words): the word is that column, asked no more
|
|
108
|
+
if (rules.some((r, i) => countPhrase(r, found.column) > 0)) { facts.push(fact(found.column)); continue; }
|
|
109
109
|
asks.push({
|
|
110
110
|
line: at.line, rule: at.rule ?? null, source: 'look', ask: 'reading', ruleText, question: columnQuestion(w.word, found, at.line), reading: columnRuleWords(w.word, found.column), word: w.word, column: found.column,
|
|
111
111
|
});
|
package/src/sheetoffer.js
CHANGED
|
@@ -111,7 +111,7 @@ export function sheetOfferRules(roles) {
|
|
|
111
111
|
`- A green step whose line has a guardrail about values in a CSV input (${roles.join(', ')}) lists that input's role in its reads and carries close.sheet = a list of 1 to ${MAX_SHEET_CHECKS} checks, each a bareguard check object from the ops below, with "table" = the CSV input's role. Write the checks the line's guardrail needs and nothing else; the person signs them. close.sheet is for a green step only.`,
|
|
112
112
|
'- A column name in a check is picked from the sheet\'s header, spelled exactly; the tool only lets you pick a header name. A check that bareguard refuses (a wrong field for the op, overlapping bands, a missing dateFormats entry) is refused at $0 naming the job line.',
|
|
113
113
|
'- A number in a where condition (gt, gte, lt, lte, eq, between) must be a number the person wrote on that job line or its guardrail; a date (asOf, and the values of before, after, dateOn, dateBetween) must be a date they wrote there as YYYY-MM-DD. Never make a number or a date up: if the person gave none, leave that condition out.',
|
|
114
|
-
'- A "cells" check names "claim", a short name for the answer the step gives; the step is told only the shape of the answer, never the check. A "table" check has no claim and judges the sheet itself. If every check of a step is a table check the step has nothing to answer and the line is refused: pair a table check with at least one cells check.',
|
|
114
|
+
'- A "cells" check names "claim", a short name for the answer the step gives; the step is told only the shape of the answer, never the check. A "table" check has no claim and judges the input sheet itself, so it must already hold on that sheet (one that fails on it is refused); to check what a step gives, use a cells check. If every check of a step is a table check the step has nothing to answer and the line is refused: pair a table check with at least one cells check.',
|
|
115
115
|
'- "covers" on each check lists the numbers of the line\'s guardrail rules (the ~ parts, counted from 1 in the order shown) that this check really verifies; [] if none. A guardrail rule that no check covers is shown to the person as Not checked, so cover every rule you can with a real check, and never claim a rule a check does not verify. A rule shaped like "use the column \'X\' for \'Y\'" is a column choice, not a rule to cover.',
|
|
116
116
|
...sheetOpsBrief(),
|
|
117
117
|
];
|
package/src/sheetrun.js
CHANGED
|
@@ -103,3 +103,30 @@ export async function closeSheet(checks, artifact, sheet) {
|
|
|
103
103
|
return /** @type {any} */ ({ verdict: 'crash', red: `sheet close crashed: ${/** @type {any} */ (err).message}` });
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* M10b am5: the `table` checks of a draft that already fail on the sheet the draft was made with. A table check judges the sheet itself, so bareguard's `checkStep` (the
|
|
109
|
+
* run's own judge, `closeSheet`) can run it before anything is spent: $0, no model call. Only `table` checks run; a cells check judges the step's answer and never runs here.
|
|
110
|
+
* Each check is read by its id, so bareguard's own `happened` check never counts; the answer handed over is non-empty, because an EMPTY one stops bareguard at `happened` before any
|
|
111
|
+
* table check runs (the check would then read as passing).
|
|
112
|
+
* @param {any} declaration the draft @param {Record<string, {header: string[], rows: any[]}>} tables the draft-time table of each CSV input, by role
|
|
113
|
+
* @returns {Promise<string[]>} one red per failing check, in plan order
|
|
114
|
+
*/
|
|
115
|
+
export async function tableChecksFailingOnInput(declaration, tables) {
|
|
116
|
+
const reds = [];
|
|
117
|
+
for (const s of Array.isArray(declaration?.steps) ? declaration.steps : []) {
|
|
118
|
+
const list = s?.close?.class === 'green' && Array.isArray(s.close.sheet) ? s.close.sheet : [];
|
|
119
|
+
for (const c of list) {
|
|
120
|
+
if (!isRec(c) || c.rule !== 'table' || typeof c.table !== 'string' || !isRec(tables[c.table])) continue;
|
|
121
|
+
const sha = tableSha(tables[c.table]);
|
|
122
|
+
if (sha === null) continue; // bareguard cannot read the sheet as a table: the draft's own sheet look has said so
|
|
123
|
+
const sheet = { ok: /** @type {const} */ (true), tables: { [c.table]: tables[c.table] }, inputs: [{ name: c.table, sha256: sha }] };
|
|
124
|
+
const v = /** @type {any} */ (await closeSheet([c], { done: true }, sheet));
|
|
125
|
+
const row = Array.isArray(v.checks) ? v.checks.find((/** @type {any} */ r) => r.id === c.id) : undefined;
|
|
126
|
+
if (!row || row.ok) continue;
|
|
127
|
+
const what = String(row.result).startsWith(`${c.id}: `) ? String(row.result).slice(c.id.length + 2) : String(row.result);
|
|
128
|
+
reds.push(`line ${s.fromLine}: the table check "${sheetCheckName(c)}" already fails on the input "${c.table}" (${what}), so this step could never pass. A table check judges the input sheet itself; to check what the step gives, use a cells check.`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return reds;
|
|
132
|
+
}
|
package/types/sheetrun.d.ts
CHANGED
|
@@ -33,3 +33,15 @@ export function readRunSheets(runDir: string, checks: any[]): {
|
|
|
33
33
|
* @returns {Promise<import('./types.js').CloseVerdict>}
|
|
34
34
|
*/
|
|
35
35
|
export function closeSheet(checks: any[], artifact: unknown, sheet: ReturnType<typeof readRunSheets> | null | undefined): Promise<import("./types.js").CloseVerdict>;
|
|
36
|
+
/**
|
|
37
|
+
* M10b am5: the `table` checks of a draft that already fail on the sheet the draft was made with. A table check judges the sheet itself, so bareguard's `checkStep` (the
|
|
38
|
+
* run's own judge, `closeSheet`) can run it before anything is spent: $0, no model call. Only `table` checks run; a cells check judges the step's answer and never runs here.
|
|
39
|
+
* Each check is read by its id, so bareguard's own `happened` check never counts; the answer handed over is non-empty, because an EMPTY one stops bareguard at `happened` before any
|
|
40
|
+
* table check runs (the check would then read as passing).
|
|
41
|
+
* @param {any} declaration the draft @param {Record<string, {header: string[], rows: any[]}>} tables the draft-time table of each CSV input, by role
|
|
42
|
+
* @returns {Promise<string[]>} one red per failing check, in plan order
|
|
43
|
+
*/
|
|
44
|
+
export function tableChecksFailingOnInput(declaration: any, tables: Record<string, {
|
|
45
|
+
header: string[];
|
|
46
|
+
rows: any[];
|
|
47
|
+
}>): Promise<string[]>;
|