fwdloop 0.28.0 → 0.30.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 +1 -1
- package/bin/fwdloop +27 -5
- package/package.json +3 -3
- package/src/added-end.js +60 -0
- package/src/ask.js +1 -1
- package/src/audit-fold.js +9 -1
- package/src/authoring.js +18 -7
- package/src/checked.js +14 -9
- package/src/checkpick.js +318 -0
- package/src/checkwords.js +29 -0
- package/src/citedcheck.js +14 -0
- package/src/closers.js +40 -3
- package/src/declaration.js +102 -5
- package/src/draft-steps.js +3 -3
- package/src/drafter.js +151 -38
- package/src/jobkey.js +3 -1
- package/src/learn.js +1 -1
- package/src/learnstore.js +6 -6
- package/src/memo.js +120 -0
- package/src/model-step.js +103 -25
- package/src/pageask.js +12 -6
- package/src/pagedropwords.js +9 -0
- package/src/panel/author.js +33 -10
- package/src/panel/authorcard.js +59 -6
- package/src/panel/data.js +16 -10
- package/src/panel/index.html +151 -59
- package/src/panel/result.js +28 -7
- package/src/panel/server.js +2 -1
- package/src/pickrecord.js +146 -0
- package/src/plain-checks.js +16 -3
- package/src/provider.js +4 -1
- package/src/repairs.js +38 -0
- package/src/runfile.js +4 -2
- package/src/runner.js +129 -40
- package/src/send.js +71 -4
- package/src/setup.js +13 -1
- package/src/sheetblock.js +2 -1
- package/src/ticket-draft.js +2 -2
- package/src/ticket-labels.js +2 -2
- package/src/try-checks.js +13 -3
- package/src/whole-job.js +71 -0
- package/types/added-end.d.ts +62 -0
- package/types/ask.d.ts +2 -1
- package/types/audit-fold.d.ts +13 -2
- package/types/authoring.d.ts +6 -2
- package/types/checked.d.ts +7 -2
- package/types/checkpick.d.ts +183 -0
- package/types/checkwords.d.ts +18 -0
- package/types/citedcheck.d.ts +6 -0
- package/types/closers.d.ts +6 -3
- package/types/declaration.d.ts +12 -0
- package/types/drafter.d.ts +28 -25
- package/types/learn.d.ts +1 -0
- package/types/learnstore.d.ts +2 -3
- package/types/memo.d.ts +15 -0
- package/types/model-step.d.ts +23 -3
- package/types/pageask.d.ts +9 -2
- package/types/pagedropwords.d.ts +1 -0
- package/types/panel/author.d.ts +1 -1
- package/types/panel/authorcard.d.ts +41 -0
- package/types/panel/data.d.ts +1 -1
- package/types/panel/jobgrid.d.ts +1 -1
- package/types/panel/result.d.ts +9 -3
- package/types/pickrecord.d.ts +88 -0
- package/types/plain-checks.d.ts +9 -1
- package/types/repairs.d.ts +13 -0
- package/types/runfile.d.ts +7 -2
- package/types/runner.d.ts +16 -5
- package/types/send.d.ts +10 -2
- package/types/setup.d.ts +1 -56
- package/types/try-checks.d.ts +1 -7
- package/types/whole-job.d.ts +70 -0
- package/src/attemptdiff.js +0 -118
- package/types/attemptdiff.d.ts +0 -38
package/src/runner.js
CHANGED
|
@@ -76,6 +76,8 @@ import {
|
|
|
76
76
|
} from './try-checks.js';
|
|
77
77
|
import { readJobThinking, readModelRecord, takeLearningsRecord } from './flowmodel.js';
|
|
78
78
|
import { readRunInputs, writeRunStart } from './runfile.js';
|
|
79
|
+
import { buildMemo } from './memo.js';
|
|
80
|
+
import { wholeJobAskIndex, wholeJobText } from './whole-job.js';
|
|
79
81
|
import { fetchPageText, isWebUrl } from './pagefetch.js';
|
|
80
82
|
import { readTicketMcp, configForServer, remoteRefusal, mcpStartOpts, startRefusal, firstLine } from './ticket-mcp.js';
|
|
81
83
|
import { createMCPBridge, discoverServers } from 'bare-agent/mcp';
|
|
@@ -226,9 +228,9 @@ const holdOf = (ceilingUsd) => (Number.isFinite(ceilingUsd) && /** @type {number
|
|
|
226
228
|
// WITHOUT the cap (M2 scope item 3, the load-bearing invariant).
|
|
227
229
|
// ---------------------------------------------------------------------------
|
|
228
230
|
|
|
229
|
-
const EXECUTOR_FIELDS = Object.freeze(['goal', 'primitives', 'reads', 'gap', 'hints']);
|
|
231
|
+
const EXECUTOR_FIELDS = Object.freeze(['goal', 'primitives', 'reads', 'gap', 'hints', 'memo']);
|
|
230
232
|
|
|
231
|
-
/** @param {{goal:string, primitives?:string[], reads?:Record<string,any>, gap?:string|null, hints?:string|null}} opts `hints` (M8 am7): the earlier runs' block, text only, for a retry / redo / rerun try */
|
|
233
|
+
/** @param {{goal:string, primitives?:string[], reads?:Record<string,any>, gap?:string|null, hints?:string|null, memo?:string|null}} opts `hints` (M8 am7): the earlier runs' block, text only, for a retry / redo / rerun try; `memo` (M14): what happened so far in this run, text only, every try */
|
|
232
234
|
export function buildExecutorContext(opts) {
|
|
233
235
|
for (const key of Object.keys(opts ?? {})) {
|
|
234
236
|
if (!EXECUTOR_FIELDS.includes(key)) {
|
|
@@ -236,7 +238,7 @@ export function buildExecutorContext(opts) {
|
|
|
236
238
|
}
|
|
237
239
|
}
|
|
238
240
|
const {
|
|
239
|
-
goal, primitives = [], reads = {}, gap = null, hints = null,
|
|
241
|
+
goal, primitives = [], reads = {}, gap = null, hints = null, memo = null,
|
|
240
242
|
} = opts ?? {};
|
|
241
243
|
return Object.freeze({
|
|
242
244
|
goal,
|
|
@@ -244,6 +246,7 @@ export function buildExecutorContext(opts) {
|
|
|
244
246
|
reads: Object.freeze({ ...reads }),
|
|
245
247
|
gap: gap ?? null,
|
|
246
248
|
hints: hints ?? null,
|
|
249
|
+
memo: memo ?? null,
|
|
247
250
|
});
|
|
248
251
|
}
|
|
249
252
|
|
|
@@ -251,7 +254,7 @@ export function buildExecutorContext(opts) {
|
|
|
251
254
|
* construction test, negative vi). Walks any depth, any key, any array
|
|
252
255
|
* entry; also catches a bare function value anywhere in the tree. */
|
|
253
256
|
const FORBIDDEN_CONTEXT_KEYS = Object.freeze([
|
|
254
|
-
'close', 'shape', 'cap', 'strike', 'maxWords', 'sections', 'linesPerInvoice', 'mustCarry',
|
|
257
|
+
'close', 'shape', 'cap', 'strike', 'maxWords', 'sections', 'linesPerInvoice', 'mustCarry', 'picked',
|
|
255
258
|
]);
|
|
256
259
|
|
|
257
260
|
/**
|
|
@@ -738,17 +741,17 @@ function recordLateAnswerIfAny(runDir, now = () => new Date().toISOString()) {
|
|
|
738
741
|
export const LEARN_ERROR_FILE = 'learn-error.jsonl';
|
|
739
742
|
|
|
740
743
|
/**
|
|
741
|
-
* @param {{flowName: string, runId: string, runDir: string, outcome: string,
|
|
744
|
+
* @param {{flowName: string, runId: string, runDir: string, outcome: string, now: () => string}} o
|
|
742
745
|
*/
|
|
743
746
|
function recordRunNotes({
|
|
744
|
-
flowName, runId, runDir, outcome,
|
|
747
|
+
flowName, runId, runDir, outcome, now,
|
|
745
748
|
}) {
|
|
746
749
|
if (NOT_A_RUN_END.has(outcome)) return;
|
|
747
750
|
const door = configDoorHome();
|
|
748
751
|
if (door.skip) return;
|
|
749
752
|
try {
|
|
750
753
|
const r = learnAtRunEnd({
|
|
751
|
-
home: door.home, workflow: flowName, runId, runDir,
|
|
754
|
+
home: door.home, workflow: flowName, runId, runDir, now: new Date(now()),
|
|
752
755
|
});
|
|
753
756
|
if (r.problem) throw new Error(r.problem);
|
|
754
757
|
} catch (/** @type {any} */ e) {
|
|
@@ -819,6 +822,11 @@ function makeAuditRow({
|
|
|
819
822
|
hintsText = /** @type {string|undefined} */ (undefined),
|
|
820
823
|
hintIds = /** @type {string[]|undefined} */ (undefined),
|
|
821
824
|
hintsError = /** @type {string|undefined} */ (undefined),
|
|
825
|
+
memoText = /** @type {string|undefined} */ (undefined),
|
|
826
|
+
badCalls = /** @type {any[]|undefined} */ (undefined),
|
|
827
|
+
sentSha256 = /** @type {string|undefined} */ (undefined),
|
|
828
|
+
savedBy = /** @type {string|undefined} */ (undefined),
|
|
829
|
+
forcedRefused = /** @type {string|undefined} */ (undefined),
|
|
822
830
|
}) {
|
|
823
831
|
const row = {
|
|
824
832
|
step: step?.emits ?? step?.goal ?? null,
|
|
@@ -844,6 +852,16 @@ function makeAuditRow({
|
|
|
844
852
|
// (this row, written after the call from what the try held in memory); a failed ask for the block is `hintsError`, the first line, secrets redacted.
|
|
845
853
|
if (hints !== undefined) { row.hints = hints; row.hintsText = hintsText; row.hintIds = hintIds; }
|
|
846
854
|
if (hintsError !== undefined) row.hintsError = hintsError;
|
|
855
|
+
// M14 item 7: the exact memo text this try was handed (what happened so far in the run); the key is absent when the try got none. The ONE place the text is kept.
|
|
856
|
+
if (memoText !== undefined) row.memoText = memoText;
|
|
857
|
+
// M14 item 10: bare-agent's facts about this try's calls that went wrong (`badCalls`), as the model step returned them; the key is absent when there were none. The ONE writer.
|
|
858
|
+
if (Array.isArray(badCalls) && badCalls.length > 0) row.badCalls = badCalls;
|
|
859
|
+
// M15 item 4: the sha256 of the plain-text file a send wrote; the key is only on a green send row. The ONE writer; the Result tab reads it to tell the file changed.
|
|
860
|
+
if (typeof sentSha256 === 'string') row.sentSha256 = sentSha256;
|
|
861
|
+
// M4d am37 item 5: which way the model step saved its artifact - `first` (round 1), `forced` (the forced call after the fixed line), `fallback` (the unforced call); absent when it did not save. The ONE writer.
|
|
862
|
+
if (savedBy === 'first' || savedBy === 'forced' || savedBy === 'fallback') row.savedBy = savedBy;
|
|
863
|
+
// M4d am37, ruling A: the fixed say of a try whose forced call the provider refused with no usage returned (it booked $0); absent otherwise. The ONE writer.
|
|
864
|
+
if (typeof forcedRefused === 'string') row.forcedRefused = forcedRefused;
|
|
847
865
|
return row;
|
|
848
866
|
}
|
|
849
867
|
|
|
@@ -956,13 +974,26 @@ async function runStepTries({
|
|
|
956
974
|
}
|
|
957
975
|
}
|
|
958
976
|
// every row this try writes from here on carries how many hints it was handed, which, and what (none handed = no field)
|
|
959
|
-
|
|
977
|
+
// M14 items 2 and 7: the memo is built fresh from the run's files before EVERY try (src/memo.js), handed whole, and kept on every row this try writes
|
|
978
|
+
const memo = buildMemo(runDir, { step: step?.emits ?? step?.goal ?? null });
|
|
979
|
+
// M14 item 10: this try's `badCalls` come back with the model step's result; every row the try writes carries them
|
|
980
|
+
/** @type {any[]|undefined} */
|
|
981
|
+
let badCalls;
|
|
982
|
+
// M4d am37: how this try's model step saved, as it returned it
|
|
983
|
+
let savedBy;
|
|
984
|
+
let forcedRefused;
|
|
985
|
+
let firstText;
|
|
986
|
+
const rowOf = (/** @type {any} */ a) => withFirstText(makeAuditRow({
|
|
960
987
|
...a,
|
|
988
|
+
...(memo !== '' ? { memoText: memo } : {}),
|
|
989
|
+
...(badCalls !== undefined ? { badCalls } : {}),
|
|
990
|
+
...(savedBy !== undefined ? { savedBy } : {}),
|
|
991
|
+
...(forcedRefused !== undefined ? { forcedRefused } : {}),
|
|
961
992
|
...(handed !== null ? { hints: handed.ids.length, hintsText: handed.text, hintIds: handed.ids } : {}),
|
|
962
993
|
...(handedError !== undefined ? { hintsError: handedError } : {}),
|
|
963
|
-
});
|
|
994
|
+
}), firstText);
|
|
964
995
|
const executorContext = buildExecutorContext({
|
|
965
|
-
goal: step.goal, primitives: step.primitives ?? [], reads: readsMap, gap, hints: handed === null ? null : handed.text,
|
|
996
|
+
goal: step.goal, primitives: step.primitives ?? [], reads: readsMap, gap, hints: handed === null ? null : handed.text, memo: memo === '' ? null : memo,
|
|
966
997
|
});
|
|
967
998
|
|
|
968
999
|
// `stepMeta` is a SEPARATE argument from `executorContext` — never a
|
|
@@ -974,7 +1005,7 @@ async function runStepTries({
|
|
|
974
1005
|
// M4d am25: `thinkingMode` is the ONE decision of what this try asks of thinking (`stepThinkingMode`); the model step only passes it on.
|
|
975
1006
|
// M10 am7 item 3: `cited` is the fact part of a green step that quotes a saved page - the form of its ANSWER ({results: [{quote, values}]}) and the facts it must hold,
|
|
976
1007
|
// told to the step in plain words by the model step. It is not the check: the quotes are checked by `closeCited` against the run's own copy.
|
|
977
|
-
const stepMeta = Object.freeze({ class: step.close?.class ?? null, cited: step.close?.class === 'green' && step.close.cited ? step.close.cited : null, sheet: step.close?.class === 'green' && Array.isArray(step.close.sheet) ? step.close.sheet : null, attempt, step: step?.emits ?? step?.goal ?? null, thinkingMode: stepThinkingMode({ boxOn: thinkingBox, attempt }) });
|
|
1008
|
+
const stepMeta = Object.freeze({ class: step.close?.class ?? null, cited: step.close?.class === 'green' && step.close.cited ? step.close.cited : null, sheet: step.close?.class === 'green' && Array.isArray(step.close.sheet) ? step.close.sheet : null, withText: step.close?.class === 'green' && Array.isArray(step.close.picked) && step.close.picked.length > 0, picked: step.close?.class === 'green' && Array.isArray(step.close.picked) ? step.close.picked : null, attempt, step: step?.emits ?? step?.goal ?? null, thinkingMode: stepThinkingMode({ boxOn: thinkingBox, attempt }) });
|
|
978
1009
|
|
|
979
1010
|
const stopSeam = readStop ? Object.freeze({ stopRequested: readStop }) : undefined;
|
|
980
1011
|
|
|
@@ -1005,10 +1036,15 @@ async function runStepTries({
|
|
|
1005
1036
|
const tools = first.tools || result.tools ? { ...(first.tools ?? {}) } : null;
|
|
1006
1037
|
if (tools) for (const [k, v] of Object.entries(result.tools ?? {})) tools[k] = (tools[k] ?? 0) + v;
|
|
1007
1038
|
const ungranted = [...new Set([...(first.ungranted ?? []), ...(result.ungranted ?? [])])].sort();
|
|
1008
|
-
|
|
1039
|
+
const bad = [...(first.badCalls ?? []), ...(result.badCalls ?? [])];
|
|
1040
|
+
result = { ...result, refused, tools, ...(ungranted.length > 0 ? { ungranted } : {}), ...(bad.length > 0 ? { badCalls: bad } : {}) };
|
|
1009
1041
|
}
|
|
1010
1042
|
}
|
|
1011
1043
|
const wallMs = Date.now() - startedAt;
|
|
1044
|
+
badCalls = Array.isArray(result?.badCalls) ? result.badCalls : undefined;
|
|
1045
|
+
savedBy = typeof result?.savedBy === 'string' ? result.savedBy : undefined;
|
|
1046
|
+
forcedRefused = typeof result?.forcedRefused === 'string' ? result.forcedRefused : undefined;
|
|
1047
|
+
firstText = typeof result?.firstText === 'string' ? result.firstText : undefined;
|
|
1012
1048
|
|
|
1013
1049
|
// A Stop landed during this try: the call in flight finished and is booked here (its cost into the run's spend and onto the one
|
|
1014
1050
|
// `stopped` row), no new call started. Unknown cost stays unknown (usd null, spend incomplete), never 0.
|
|
@@ -1226,13 +1262,14 @@ export async function runStepRalph({ mcpServer = null, ...opts }) {
|
|
|
1226
1262
|
* @param {unknown} opts.catalogue - passed straight through to `readFlow`.
|
|
1227
1263
|
* @param {(executorContext:object, grantedTools:Record<string,any>, stepMeta?:{class:string|null}) => Promise<{ok:boolean, artifact?:unknown, costUsd:number|null, red?:string, transport?:boolean, model?:string, modelMatch?:boolean}>} opts.modelStep
|
|
1228
1264
|
* @param {(opts:{question:string, evidence:unknown, runDir:string}) => Promise<{decision:'accept'|'redo'|'rerun'|'timeout'|'park', reason?:string, artifactSha256?:string}>} opts.askStep
|
|
1229
|
-
* @param {(target:string, filename:string, content:unknown, acceptedSha256?:string|null) => Promise<{ok:boolean, red?:string, bytes?:number}>} opts.sendStep
|
|
1265
|
+
* @param {(target:string, filename:string, content:unknown, acceptedSha256?:string|null) => Promise<{ok:boolean, red?:string, bytes?:number, sha256?:string}>} opts.sendStep
|
|
1230
1266
|
* @param {Record<string, any>} [opts.primitives] - injected primitive implementations, keyed by catalogue verb.
|
|
1231
1267
|
* @param {string[]} [opts.primitiveReds] - `resolvePrimitives`'s own `reds` (e.g. bareguard refusing a symlinked file scope); any entry refuses the run at $0 like an unwired verb, before the run dir exists.
|
|
1232
1268
|
* @param {() => string} [opts.clock] - returns the current ISO timestamp; defaults to the wall clock.
|
|
1233
1269
|
* @param {string} opts.businessDate - the run's explicit "as of today", never the wall clock.
|
|
1234
1270
|
* @param {number} [opts.ceilingUsd] - per-attempt ceiling override; the model's hold from Settings prices (`ceilingCostUsd`); absent = no hold.
|
|
1235
1271
|
* @param {{slot: string, model: string}} [opts.runModel] - M4d am33: the model this run started on; recorded once in the run folder (run.json) and kept by every resume/continue.
|
|
1272
|
+
* @param {{decision: 'rerun', words: string, afterStep: string|null}} [opts.rerunOf] - M14 am1 item 1: only `resumeRun`'s rerun path passes it; kept in the new run's run.json
|
|
1236
1273
|
* @param {string|null} [opts.initialGap] - M3 scope item 7 (rerun as a fresh
|
|
1237
1274
|
* run): a human's rerun reason, carried as the FIRST ordinary step's
|
|
1238
1275
|
* starting gap. Never used by a plain `runFlow` call outside `resumeRun`'s
|
|
@@ -1244,6 +1281,8 @@ export async function runStepRalph({ mcpServer = null, ...opts }) {
|
|
|
1244
1281
|
*/
|
|
1245
1282
|
export async function runFlow({
|
|
1246
1283
|
root, name, runId, sources, catalogue, modelStep, askStep, sendStep, primitives, primitiveReds, clock, businessDate, ceilingUsd, initialGap, fetchPage,
|
|
1284
|
+
// M14 am1 item 1: set only by `resumeRun`'s rerun path ({decision, words, afterStep}); written once into run.json by `writeRunStart`
|
|
1285
|
+
rerunOf,
|
|
1247
1286
|
// M4d am33: the model this run STARTED on ({ slot, model }); recorded once beside the run, kept by every resume/continue. Absent = nothing recorded.
|
|
1248
1287
|
runModel,
|
|
1249
1288
|
// F45 finding 3's test needs to advance wall time across a park/resume
|
|
@@ -1360,21 +1399,21 @@ export async function runFlow({
|
|
|
1360
1399
|
|
|
1361
1400
|
// M4d am25: the run keeps the job's "Thinking on" box as it is now (read by `readJobThinking` on every try and every resume); taken here, recorded in `run.json` once the inputs are frozen
|
|
1362
1401
|
const thinkingBox = readModelRecord(flowDir)?.thinking === true;
|
|
1363
|
-
// M8 item 6: the first run from a freshly signed flow takes the learnings its draft was handed (the Audit box); a run that kept its own plan already has its record; a failure never stops the run
|
|
1364
|
-
if (!runOwnsPlan(runDir)) {
|
|
1365
|
-
try { takeLearningsRecord(flowDir, runDir); } catch (/** @type {any} */ e) {
|
|
1366
|
-
try { appendRow(join(runDir, LEARN_ERROR_FILE), { at: now(), error: redactSecrets(`learnings record: ${e?.message ?? e}`).split('\n')[0] }); } catch { /* best-effort */ }
|
|
1367
|
-
}
|
|
1368
|
-
}
|
|
1369
|
-
|
|
1370
1402
|
const frozen = await freezeInputs(runDir, sources ?? [], { fetchPage, tableRoles: sheetRolesOf(declaration.steps), mcp: declaration.mcp, ticketFilter: declaration.ticketFilter });
|
|
1371
1403
|
if (!frozen.ok) {
|
|
1372
1404
|
return haltRun({
|
|
1373
1405
|
flowDir, runDir, runId, capUsd, startedAt, now, nowMs: getNowMs, signatureHash: signature.flow, outcome: 'preflight-red', red: frozen.red, spent: { value: 0 },
|
|
1374
1406
|
});
|
|
1375
1407
|
}
|
|
1408
|
+
// M8 item 6: the first run from a freshly signed flow takes the learnings its draft was handed (the Audit box); a run that kept its own plan already has its record; taken only once the inputs froze, so a run refused at its inputs leaves it; a failure never stops the run
|
|
1409
|
+
if (!runOwnsPlan(runDir)) {
|
|
1410
|
+
try { takeLearningsRecord(flowDir, runDir); } catch (/** @type {any} */ e) {
|
|
1411
|
+
try { appendRow(join(runDir, LEARN_ERROR_FILE), { at: now(), error: redactSecrets(`learnings record: ${e?.message ?? e}`).split('\n')[0] }); } catch { /* best-effort */ }
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1376
1415
|
// M8b item 1: the run's start record, written once: the model it started on (M4d am33), the "Thinking on" box (M4d am25) and the frozen inputs
|
|
1377
|
-
writeRunStart(runDir, { model: runModel ?? null, thinking: thinkingBox, inputs: /** @type {any[]} */ (frozen.manifest) });
|
|
1416
|
+
writeRunStart(runDir, { model: runModel ?? null, thinking: thinkingBox, inputs: /** @type {any[]} */ (frozen.manifest), rerun: rerunOf ?? null });
|
|
1378
1417
|
// M12 piece 3 (item 9): a ticket the signed labels do not match, or a closed one, ends here: skipped, $0, nothing else runs
|
|
1379
1418
|
if (frozen.skip) {
|
|
1380
1419
|
return haltRun({
|
|
@@ -1408,9 +1447,7 @@ export async function runFlow({
|
|
|
1408
1447
|
appendAudit(runDir, fullRow);
|
|
1409
1448
|
if (row.spendComplete === false) spendComplete.value = false;
|
|
1410
1449
|
if (modelOutput !== undefined) {
|
|
1411
|
-
attemptsLog.push(
|
|
1412
|
-
step: row.step, attempt: row.attempt, class: row.class, verdict: row.verdict, gap: row.gap, ...(row.refused ? { refused: row.refused } : {}), modelOutput,
|
|
1413
|
-
});
|
|
1450
|
+
attemptsLog.push(attemptEntry(row, modelOutput));
|
|
1414
1451
|
}
|
|
1415
1452
|
};
|
|
1416
1453
|
const spent = { value: 0 };
|
|
@@ -1478,7 +1515,7 @@ export async function runFlow({
|
|
|
1478
1515
|
firstStepGap: initialGap ?? null,
|
|
1479
1516
|
});
|
|
1480
1517
|
recordRunNotes({
|
|
1481
|
-
flowName: name, runId, runDir, outcome: result.outcome,
|
|
1518
|
+
flowName: name, runId, runDir, outcome: result.outcome, now,
|
|
1482
1519
|
});
|
|
1483
1520
|
|
|
1484
1521
|
if (result.outcome === 'complete') return { ...result, auditRows };
|
|
@@ -1569,6 +1606,8 @@ async function runAskSlot({
|
|
|
1569
1606
|
runStartedAt,
|
|
1570
1607
|
// M13 item 5: the job's signed `mcp.server`; a redo of the step before the ask runs it again with its signed MCP tools
|
|
1571
1608
|
mcpServer = /** @type {string|null} */ (null),
|
|
1609
|
+
// M13 am9: set only for the Ask that shows the whole job; rebuilds `{text}` from the saved outputs after a redo changed one
|
|
1610
|
+
rebuildPrior = /** @type {null | (() => ({ok:true,value:any}|{ok:false,red:string}))} */ (null),
|
|
1572
1611
|
}) {
|
|
1573
1612
|
let redone = initialRedone;
|
|
1574
1613
|
let currentPrior = priorArtifact;
|
|
@@ -1758,6 +1797,11 @@ async function runAskSlot({
|
|
|
1758
1797
|
// case `writeArtifact` allows to overwrite on purpose.
|
|
1759
1798
|
writeArtifact(runDir, priorId, currentPrior, { overwrite: true });
|
|
1760
1799
|
artifacts[priorId] = currentPrior;
|
|
1800
|
+
if (rebuildPrior) {
|
|
1801
|
+
const whole = rebuildPrior();
|
|
1802
|
+
if (!whole.ok) return { type: 'halted', outcome: 'red', red: whole.red };
|
|
1803
|
+
currentPrior = whole.value;
|
|
1804
|
+
}
|
|
1761
1805
|
// eslint-disable-next-line no-continue
|
|
1762
1806
|
continue;
|
|
1763
1807
|
}
|
|
@@ -1808,6 +1852,9 @@ async function foldFromStep({
|
|
|
1808
1852
|
}) {
|
|
1809
1853
|
let runAcceptedThisRun = acceptedThisRun;
|
|
1810
1854
|
let runUnjudged = unjudgedSinceLastAsk;
|
|
1855
|
+
// M13 am9: the Ask that shows the whole job (-1 = none: a job signed before am8 is unchanged)
|
|
1856
|
+
const wholeIdx = wholeJobAskIndex({ steps, askLines, sendLines });
|
|
1857
|
+
const rebuildWhole = () => wholeJobText({ steps, askLines, lastAskIndex: wholeIdx, readResult: (id) => readArtifactResult(runDir, id) });
|
|
1811
1858
|
|
|
1812
1859
|
for (let i = i0; i < steps.length; i += 1) {
|
|
1813
1860
|
const step = steps[i];
|
|
@@ -1880,11 +1927,12 @@ async function foldFromStep({
|
|
|
1880
1927
|
});
|
|
1881
1928
|
}
|
|
1882
1929
|
const content = contentResult.value;
|
|
1883
|
-
const filename = `${flowName}-${runId}-${step.emits}.
|
|
1930
|
+
const filename = `${flowName}-${runId}-${step.emits}.md`;
|
|
1884
1931
|
// eslint-disable-next-line no-await-in-loop
|
|
1885
1932
|
const sendResult = await sendStep(target, filename, content, acceptedAskEmitsThisRun.get(askArtifactId), { root: flowRoot, runDir });
|
|
1886
1933
|
const sendRow = makeAuditRow({
|
|
1887
1934
|
step, attempt: 1, verdict: sendResult.ok ? 'green' : 'red', gap: sendResult.ok ? null : sendResult.red, usd: 0, spendComplete: true, wallMs: 0, strike: false, at: now(),
|
|
1935
|
+
...(sendResult.ok && typeof sendResult.sha256 === 'string' ? { sentSha256: sendResult.sha256 } : {}),
|
|
1888
1936
|
});
|
|
1889
1937
|
recordAudit(sendRow);
|
|
1890
1938
|
if (!sendResult.ok) {
|
|
@@ -1918,7 +1966,17 @@ async function foldFromStep({
|
|
|
1918
1966
|
: `ask: prior artifact "${priorId}" for step "${step.goal}" — ${priorArtifactResult.red}`,
|
|
1919
1967
|
});
|
|
1920
1968
|
}
|
|
1921
|
-
|
|
1969
|
+
let priorArtifact = priorArtifactResult.value;
|
|
1970
|
+
if (i === wholeIdx) {
|
|
1971
|
+
const whole = rebuildWhole();
|
|
1972
|
+
if (!whole.ok) {
|
|
1973
|
+
return haltRun({
|
|
1974
|
+
flowDir, runDir, runId, capUsd, startedAt: runStartedAt, now, nowMs, signatureHash, spent, priorSpendComplete: spendComplete.value, attempts: attemptsLog, artifacts,
|
|
1975
|
+
outcome: 'red', red: whole.red,
|
|
1976
|
+
});
|
|
1977
|
+
}
|
|
1978
|
+
priorArtifact = whole.value;
|
|
1979
|
+
}
|
|
1922
1980
|
|
|
1923
1981
|
// M2 amendment 1 item 2: every hitl artifact carried since the
|
|
1924
1982
|
// previous ask goes to THIS ask as evidence, alongside the ask step's
|
|
@@ -1939,6 +1997,7 @@ async function foldFromStep({
|
|
|
1939
1997
|
priorStepNo: priorStepIndex + 1,
|
|
1940
1998
|
priorPrevStepId: priorStepIndex > 0 ? (steps[priorStepIndex - 1].emits ?? null) : null,
|
|
1941
1999
|
priorArtifact,
|
|
2000
|
+
rebuildPrior: i === wholeIdx ? rebuildWhole : null,
|
|
1942
2001
|
redoCap,
|
|
1943
2002
|
effectiveCeilingUsd,
|
|
1944
2003
|
capUsd,
|
|
@@ -2173,7 +2232,7 @@ function sameRoot(recorded, requested) {
|
|
|
2173
2232
|
* @param {string} opts.runId
|
|
2174
2233
|
* @param {unknown} opts.catalogue
|
|
2175
2234
|
* @param {(executorContext:object, grantedTools:Record<string,any>, stepMeta?:{class:string|null}) => Promise<any>} opts.modelStep
|
|
2176
|
-
* @param {(target:string, filename:string, content:unknown) => Promise<{ok:boolean, red?:string, bytes?:number}>} opts.sendStep
|
|
2235
|
+
* @param {(target:string, filename:string, content:unknown) => Promise<{ok:boolean, red?:string, bytes?:number, sha256?:string}>} opts.sendStep
|
|
2177
2236
|
* @param {Record<string, any>} [opts.primitives]
|
|
2178
2237
|
* @param {string[]} [opts.primitiveReds] - see `runFlow`'s own.
|
|
2179
2238
|
* @param {() => string} [opts.clock]
|
|
@@ -2463,7 +2522,7 @@ export async function resumeRun({
|
|
|
2463
2522
|
runId, at: now(), outcome: 'ask-expired', spentUsd: spent.value, spendComplete: spendComplete.value, capUsd: arbiter.capUsd ?? null, wallMs: getNowMs() - runStartedAt, signatureHash: state.signatureHash,
|
|
2464
2523
|
});
|
|
2465
2524
|
recordRunNotes({
|
|
2466
|
-
flowName: name, runId, runDir, outcome: 'ask-expired',
|
|
2525
|
+
flowName: name, runId, runDir, outcome: 'ask-expired', now,
|
|
2467
2526
|
});
|
|
2468
2527
|
return { outcome: 'ask-expired', runDir, spentUsd: spent.value };
|
|
2469
2528
|
}
|
|
@@ -2500,7 +2559,7 @@ export async function resumeRun({
|
|
|
2500
2559
|
}
|
|
2501
2560
|
// M8 am4: a rerun ends THIS run, so its notes count now (the new run, started below, makes its own).
|
|
2502
2561
|
recordRunNotes({
|
|
2503
|
-
flowName: name, runId, runDir, outcome: 'rerun',
|
|
2562
|
+
flowName: name, runId, runDir, outcome: 'rerun', now,
|
|
2504
2563
|
});
|
|
2505
2564
|
|
|
2506
2565
|
// Deterministic derived id (M3 scope item 7) — refused by name, never
|
|
@@ -2540,6 +2599,8 @@ export async function resumeRun({
|
|
|
2540
2599
|
runModel,
|
|
2541
2600
|
// Item 7: the reason becomes the new run's FIRST step's starting gap.
|
|
2542
2601
|
initialGap: reason,
|
|
2602
|
+
// M14 am1 item 1: the new run keeps the reason in its own run.json (decision, words, the step the old run's ask followed; null = the ask was first)
|
|
2603
|
+
rerunOf: { decision: 'rerun', words: reason, afterStep: steps[state.stepIndex - 1]?.emits ?? null },
|
|
2543
2604
|
});
|
|
2544
2605
|
|
|
2545
2606
|
return {
|
|
@@ -2582,9 +2643,7 @@ export async function resumeRun({
|
|
|
2582
2643
|
appendAudit(runDir, fullRow);
|
|
2583
2644
|
if (row.spendComplete === false) spendComplete.value = false;
|
|
2584
2645
|
if (modelOutput !== undefined) {
|
|
2585
|
-
attemptsLog.push(
|
|
2586
|
-
step: row.step, attempt: row.attempt, class: row.class, verdict: row.verdict, gap: row.gap, ...(row.refused ? { refused: row.refused } : {}), modelOutput,
|
|
2587
|
-
});
|
|
2646
|
+
attemptsLog.push(attemptEntry(row, modelOutput));
|
|
2588
2647
|
}
|
|
2589
2648
|
};
|
|
2590
2649
|
|
|
@@ -2599,7 +2658,21 @@ export async function resumeRun({
|
|
|
2599
2658
|
// `priorId` names a step strictly earlier than the parked ask
|
|
2600
2659
|
// (state.stepIndex), so i < state.stepIndex — already proven `ok` by the
|
|
2601
2660
|
// "was this step already done" gate above; safe to collapse here.
|
|
2602
|
-
|
|
2661
|
+
let priorArtifact = readArtifact(runDir, priorId);
|
|
2662
|
+
// M13 am9: the Ask that shows the whole job rebuilds `{text}` from the saved outputs, as the first pass did
|
|
2663
|
+
const wholeIdx = wholeJobAskIndex({ steps, askLines, sendLines });
|
|
2664
|
+
const rebuildWhole = () => wholeJobText({ steps, askLines, lastAskIndex: wholeIdx, readResult: (id) => readArtifactResult(runDir, id) });
|
|
2665
|
+
if (state.stepIndex === wholeIdx) {
|
|
2666
|
+
const whole = rebuildWhole();
|
|
2667
|
+
if (!whole.ok) {
|
|
2668
|
+
return haltRun({
|
|
2669
|
+
flowDir, runDir, runId, capUsd, startedAt: runStartedAt, now, nowMs: getNowMs, signatureHash: state.signatureHash, spent, priorSpendComplete: spendComplete.value, attempts: attemptsLog, artifacts,
|
|
2670
|
+
outcome: 'red', red: whole.red,
|
|
2671
|
+
resumeAt: { stepIndex: state.stepIndex, flowRoot: root, flowName: name, inputsManifest: state.inputsManifest, unjudged: state.evidenceUnjudged ?? [], redone: typeof state.redone === 'number' ? state.redone : 0 },
|
|
2672
|
+
});
|
|
2673
|
+
}
|
|
2674
|
+
priorArtifact = whole.value;
|
|
2675
|
+
}
|
|
2603
2676
|
|
|
2604
2677
|
const oneShotAskStep = makeOneShotThenParkAskStep({ decision: answer.decision, reason: answer.reason, artifactSha256: answer.artifactSha256 });
|
|
2605
2678
|
|
|
@@ -2613,6 +2686,7 @@ export async function resumeRun({
|
|
|
2613
2686
|
priorStepNo: priorStepIndex + 1,
|
|
2614
2687
|
priorPrevStepId: priorStepIndex > 0 ? (steps[priorStepIndex - 1].emits ?? null) : null,
|
|
2615
2688
|
priorArtifact,
|
|
2689
|
+
rebuildPrior: state.stepIndex === wholeIdx ? rebuildWhole : null,
|
|
2616
2690
|
redoCap,
|
|
2617
2691
|
effectiveCeilingUsd,
|
|
2618
2692
|
capUsd,
|
|
@@ -2696,7 +2770,7 @@ export async function resumeRun({
|
|
|
2696
2770
|
attemptsLog,
|
|
2697
2771
|
});
|
|
2698
2772
|
recordRunNotes({
|
|
2699
|
-
flowName: name, runId, runDir, outcome: result.outcome,
|
|
2773
|
+
flowName: name, runId, runDir, outcome: result.outcome, now,
|
|
2700
2774
|
});
|
|
2701
2775
|
|
|
2702
2776
|
if (result.outcome === 'complete') return { ...result, auditRows };
|
|
@@ -2732,7 +2806,7 @@ export function auditSpend(runDir) {
|
|
|
2732
2806
|
* @param {string} opts.runId
|
|
2733
2807
|
* @param {unknown} opts.catalogue
|
|
2734
2808
|
* @param {(executorContext:object, grantedTools:Record<string,any>, stepMeta?:{class:string|null}) => Promise<any>} opts.modelStep
|
|
2735
|
-
* @param {(target:string, filename:string, content:unknown) => Promise<{ok:boolean, red?:string, bytes?:number}>} opts.sendStep
|
|
2809
|
+
* @param {(target:string, filename:string, content:unknown) => Promise<{ok:boolean, red?:string, bytes?:number, sha256?:string}>} opts.sendStep
|
|
2736
2810
|
* @param {Record<string, any>} [opts.primitives]
|
|
2737
2811
|
* @param {string[]} [opts.primitiveReds]
|
|
2738
2812
|
* @param {() => string} [opts.clock]
|
|
@@ -2849,9 +2923,7 @@ export async function continueRun({
|
|
|
2849
2923
|
appendAudit(runDir, fullRow);
|
|
2850
2924
|
if (row.spendComplete === false) spendComplete.value = false;
|
|
2851
2925
|
if (modelOutput !== undefined) {
|
|
2852
|
-
attemptsLog.push(
|
|
2853
|
-
step: row.step, attempt: row.attempt, class: row.class, verdict: row.verdict, gap: row.gap, ...(row.refused ? { refused: row.refused } : {}), modelOutput,
|
|
2854
|
-
});
|
|
2926
|
+
attemptsLog.push(attemptEntry(row, modelOutput));
|
|
2855
2927
|
}
|
|
2856
2928
|
};
|
|
2857
2929
|
const runStartedAt = typeof halt.startedAt === 'number' ? halt.startedAt : startedAt;
|
|
@@ -2905,7 +2977,7 @@ export async function continueRun({
|
|
|
2905
2977
|
attemptsLog,
|
|
2906
2978
|
});
|
|
2907
2979
|
recordRunNotes({
|
|
2908
|
-
flowName: name, runId, runDir, outcome: result.outcome,
|
|
2980
|
+
flowName: name, runId, runDir, outcome: result.outcome, now,
|
|
2909
2981
|
});
|
|
2910
2982
|
if (result.outcome === 'complete') return { ...result, auditRows };
|
|
2911
2983
|
return result;
|
|
@@ -3009,6 +3081,23 @@ export async function stopParkedRun({
|
|
|
3009
3081
|
}
|
|
3010
3082
|
}
|
|
3011
3083
|
|
|
3084
|
+
/** hamr's ask 2026-11-03: the round-1 text of a try a later round saved. Held beside the audit row (rows stay small), read by `attemptEntry` only. */
|
|
3085
|
+
const FIRST_TEXT = new WeakMap();
|
|
3086
|
+
|
|
3087
|
+
/** Registers a try's round-1 text against its audit row (the row itself is unchanged). */
|
|
3088
|
+
function withFirstText(row, firstText) {
|
|
3089
|
+
if (firstText !== undefined) FIRST_TEXT.set(row, firstText);
|
|
3090
|
+
return row;
|
|
3091
|
+
}
|
|
3092
|
+
|
|
3093
|
+
/** The ONE builder of a try's log.json entry (what the model said, per try), for the three `recordAudit`s; `firstText` is there only when a later round saved. */
|
|
3094
|
+
function attemptEntry(row, modelOutput) {
|
|
3095
|
+
const firstText = FIRST_TEXT.get(row);
|
|
3096
|
+
return {
|
|
3097
|
+
step: row.step, attempt: row.attempt, class: row.class, verdict: row.verdict, gap: row.gap, ...(row.refused ? { refused: row.refused } : {}), modelOutput, ...(firstText !== undefined ? { firstText } : {}),
|
|
3098
|
+
};
|
|
3099
|
+
}
|
|
3100
|
+
|
|
3012
3101
|
/** log.json's one writer, called from every exit path (complete + every
|
|
3013
3102
|
* halt) — M2 scope item 9 / the M0 ruling: what the model wrote, every
|
|
3014
3103
|
* attempt, red runs included, never just the final artifacts. */
|
package/src/send.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
// in-memory content handed in — so a write that silently truncates to 0
|
|
12
12
|
// bytes reds here, not upstream).
|
|
13
13
|
|
|
14
|
+
import { createHash } from 'node:crypto';
|
|
14
15
|
import { lstatSync, readFileSync } from 'node:fs';
|
|
15
16
|
import { join } from 'node:path';
|
|
16
17
|
import { createShellTools } from 'bare-agent/tools';
|
|
@@ -23,15 +24,81 @@ const FOUND_WRITE_TOOL = SHELL_TOOLS.find((t) => t.name === 'shell_write');
|
|
|
23
24
|
if (!FOUND_WRITE_TOOL) throw new Error('send: bare-agent/tools does not export a "shell_write" tool');
|
|
24
25
|
const WRITE_TOOL = FOUND_WRITE_TOOL;
|
|
25
26
|
|
|
27
|
+
const SCALAR = ['string', 'number', 'boolean'];
|
|
28
|
+
|
|
29
|
+
/** one value as leaf lines `{parts, text}`: parts are the names on the way in; text is a string as it is, a number or boolean written out; a list of plain values joined by ", "; null as empty */
|
|
30
|
+
/** @param {string[]} parts @param {any} v @returns {{parts: string[], text: string}[]} */
|
|
31
|
+
function leaves(parts, v) {
|
|
32
|
+
if (v === null || v === undefined) return [{ parts, text: '' }];
|
|
33
|
+
if (SCALAR.includes(typeof v)) return [{ parts, text: `${v}` }];
|
|
34
|
+
if (Array.isArray(v) && v.every((x) => x === null || SCALAR.includes(typeof x))) return [{ parts, text: v.join(', ') }];
|
|
35
|
+
if (Array.isArray(v)) return v.flatMap((x, i) => leaves([...parts, `${i + 1}`], x));
|
|
36
|
+
return Object.entries(v).flatMap(([k, x]) => leaves([...parts, k], x));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** @param {string} name split only at a lowercase-to-capital boundary, `_` and `-`, so `ID` stays one word */
|
|
40
|
+
const words = (name) => name.replace(/([a-z0-9])([A-Z])/g, '$1 $2').split(/[_\-\s]+/).filter(Boolean);
|
|
41
|
+
|
|
42
|
+
/** M15 am2 (1): the names as plain words; a last name of `value` or `rows` is left out; the first letter capital, the later words lowercase */
|
|
43
|
+
/** @param {string[]} parts */
|
|
44
|
+
function friendlyName(parts) {
|
|
45
|
+
const p = parts.length > 1 && (parts[parts.length - 1] === 'value' || parts[parts.length - 1] === 'rows') ? parts.slice(0, -1) : parts;
|
|
46
|
+
const w = p.flatMap(words).map((x) => x.toLowerCase());
|
|
47
|
+
if (!w.length) return parts.join('.');
|
|
48
|
+
return w[0][0].toUpperCase() + w[0].slice(1) + (w.length > 1 ? ` ${w.slice(1).join(' ')}` : '');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** the lines of one block (the flat part, or one result); two lines with the same words both keep today's `a.b` form */
|
|
52
|
+
/** @param {{parts: string[], text: string}[]} ls */
|
|
53
|
+
function blockLines(ls) {
|
|
54
|
+
const f = ls.map((l) => friendlyName(l.parts));
|
|
55
|
+
/** @type {Record<string, number>} */
|
|
56
|
+
const n = {};
|
|
57
|
+
for (const x of f) n[x] = (n[x] || 0) + 1;
|
|
58
|
+
return ls.map((l, i) => `${n[f[i]] > 1 ? l.parts.join('.') : f[i]}: ${l.text}`);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** a list of results: every item an object holding a `values` object (flights' `results`, with a `quote` written as its last line) */
|
|
62
|
+
/** @param {any} v */
|
|
63
|
+
const isResultList = (v) => Array.isArray(v) && v.length > 0 && v.every((r) => r && typeof r === 'object' && !Array.isArray(r) && r.values && typeof r.values === 'object' && !Array.isArray(r.values));
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* M15 items 3 and am1, am2: the accepted answer as the plain-text file the send writes. `{text}` alone is the text exactly; any other flat object is one
|
|
67
|
+
* `Name words: value` line per field; a list of results is one `## Result k` block per result with one line per value, in the order the answer holds
|
|
68
|
+
* them, then `from the page: "<quote>"`. Never JSON braces, never check marks. What it throws away: a result's keys other than `quote` and `values`.
|
|
69
|
+
* @param {Record<string, any>} content @returns {string}
|
|
70
|
+
*/
|
|
71
|
+
export function renderSentMd(content) {
|
|
72
|
+
const keys = Object.keys(content);
|
|
73
|
+
if (keys.length === 1 && keys[0] === 'text' && typeof content.text === 'string') return content.text;
|
|
74
|
+
/** @type {string[]} */
|
|
75
|
+
const parts = [];
|
|
76
|
+
/** @type {{parts: string[], text: string}[]} */
|
|
77
|
+
let flat = [];
|
|
78
|
+
const flush = () => { if (flat.length) parts.push(blockLines(flat).join('\n')); flat = []; };
|
|
79
|
+
for (const [k, v] of Object.entries(content)) {
|
|
80
|
+
if (isResultList(v)) {
|
|
81
|
+
flush();
|
|
82
|
+
v.forEach((r, i) => {
|
|
83
|
+
const lines = blockLines(Object.entries(r.values).flatMap(([n, x]) => leaves([n], x)));
|
|
84
|
+
if (typeof r.quote === 'string') lines.push(`from the page: "${r.quote}"`);
|
|
85
|
+
parts.push([`## Result ${i + 1}`, ...lines].join('\n'));
|
|
86
|
+
});
|
|
87
|
+
} else flat.push(...leaves([k], v));
|
|
88
|
+
}
|
|
89
|
+
flush();
|
|
90
|
+
return parts.join('\n\n');
|
|
91
|
+
}
|
|
92
|
+
|
|
26
93
|
/**
|
|
27
94
|
* @param {string} target - a signed arbiter target, e.g. `file:poc/m0/out`.
|
|
28
95
|
* @param {string} filename
|
|
29
|
-
* @param {unknown} content -
|
|
96
|
+
* @param {unknown} content - the accepted artifact; hash-checked as its JSON, written as plain text (`renderSentMd`).
|
|
30
97
|
* @param {string|null} [acceptedSha256] - the sha256 the human's accept recorded
|
|
31
98
|
* (`answerAsk`, M4b piece 3). Required: none recorded (an answer written by an
|
|
32
99
|
* older version, or no accept in this process) refuses by name.
|
|
33
100
|
* @param {{root?: string, runDir?: string}} [ctx] the flow root and this run's folder, for the destination refusals
|
|
34
|
-
* @returns {Promise<{ok:true, path:string, bytes:number} | {ok:false, red:string}>}
|
|
101
|
+
* @returns {Promise<{ok:true, path:string, bytes:number, sha256:string} | {ok:false, red:string}>}
|
|
35
102
|
*/
|
|
36
103
|
export async function sendViaPrimitive(target, filename, content, acceptedSha256, ctx = {}) {
|
|
37
104
|
const destination = checkSendDestination(target, ctx);
|
|
@@ -77,11 +144,11 @@ export async function sendViaPrimitive(target, filename, content, acceptedSha256
|
|
|
77
144
|
let present = true;
|
|
78
145
|
try { lstatSync(path); } catch (err) { if (err.code === 'ENOENT') present = false; }
|
|
79
146
|
if (present) return { ok: false, red: `send: "${path}" already exists — never overwritten (nothing shipped)` };
|
|
80
|
-
await WRITE_TOOL.execute({ path, content:
|
|
147
|
+
await WRITE_TOOL.execute({ path, content: renderSentMd(/** @type {Record<string, unknown>} */ (content)) });
|
|
81
148
|
|
|
82
149
|
const bytes = readFileSync(path);
|
|
83
150
|
if (bytes.byteLength === 0) {
|
|
84
151
|
return { ok: false, red: `send: "${path}" wrote 0 bytes` };
|
|
85
152
|
}
|
|
86
|
-
return { ok: true, path, bytes: bytes.byteLength };
|
|
153
|
+
return { ok: true, path, bytes: bytes.byteLength, sha256: createHash('sha256').update(bytes).digest('hex') };
|
|
87
154
|
}
|
package/src/setup.js
CHANGED
|
@@ -16,6 +16,8 @@ import { notCheckedBlock } from './checked.js';
|
|
|
16
16
|
import { readDraftSpend } from './draftspend.js';
|
|
17
17
|
import { readFileInside, readdirInside } from './flow.js';
|
|
18
18
|
import { readSpendRows } from './provider.js';
|
|
19
|
+
import { checkAsks } from './checkpick.js';
|
|
20
|
+
import { RECORD_FILE, KEPT_WORDS } from './pickrecord.js';
|
|
19
21
|
|
|
20
22
|
export const SETUP_FILE = 'setup.jsonl';
|
|
21
23
|
const CARD_RE = /^card-(\d+)\.json$/;
|
|
@@ -65,10 +67,20 @@ function planRow(sessionDir, rel, kind, n) {
|
|
|
65
67
|
* @param {string} sessionDir @param {string} rel
|
|
66
68
|
*/
|
|
67
69
|
function humanRows(sessionDir, rel) {
|
|
68
|
-
|
|
70
|
+
const answered = readQuestions(join(sessionDir, rel)).questions.filter((q) => q.source === 'look' && q.answer !== null).map((q) => ({
|
|
69
71
|
kind: 'human', n: q.k, at: q.at ?? null, source: 'look', ask: q.ask, question: q.question, answer: q.answer, line: q.line,
|
|
70
72
|
ruleNo: q.ruleNo, ruleText: q.ruleText, proposal: q.proposal ?? null, rule: q.rule ?? null,
|
|
71
73
|
}));
|
|
74
|
+
// M10 am17 (6): a pick kept from the last draft is the same row, from this plan's picks record (not an answer file), its answer being the words `kept from last draft`
|
|
75
|
+
const kept = Array.isArray(readJson(join(sessionDir, rel), RECORD_FILE)?.kept) ? readJson(join(sessionDir, rel), RECORD_FILE).kept : [];
|
|
76
|
+
const keptRows = kept.map((k, i) => {
|
|
77
|
+
const [ask] = checkAsks([{ line: k.line, rule: k.rule, text: k.ruleText, check: k.check ?? null, why: null }]);
|
|
78
|
+
return {
|
|
79
|
+
kind: 'human', n: answered.length + i + 1, at: null, source: 'look', ask: ask.ask, question: ask.question, answer: KEPT_WORDS, line: k.line,
|
|
80
|
+
ruleNo: k.rule, ruleText: k.ruleText, proposal: ask.reading ?? null, rule: k.added ?? null,
|
|
81
|
+
};
|
|
82
|
+
});
|
|
83
|
+
return [...answered, ...keptRows];
|
|
72
84
|
}
|
|
73
85
|
|
|
74
86
|
/**
|
package/src/sheetblock.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
// A green "found" is the step's OWN claimed value in plain words (a number, or a count of rows / days / bands / groups); a string claim (a looked-up cell) is never
|
|
8
8
|
// repeated, because it is cell text. A red "found" is bareguard's gap words (row numbers and counts), never a cell's text.
|
|
9
9
|
// Third outcomes, named: a line the run never reached (no record) carries no verdict; a check the record lacks carries none (the page shows no mark).
|
|
10
|
+
import { labelled } from './checkwords.js';
|
|
10
11
|
import { isDeepStrictEqual } from 'node:util';
|
|
11
12
|
import { rubricVocabulary } from 'bareguard';
|
|
12
13
|
import { lineRules } from './pagebits.js';
|
|
@@ -90,7 +91,7 @@ export function sheetLineBlocks({ declaration, lines, csvRoles = [], record }) {
|
|
|
90
91
|
const words = sheetCheckSentence(c);
|
|
91
92
|
const cw = coversWords(rules);
|
|
92
93
|
/** @type {any} */
|
|
93
|
-
const e = { id: typeof c.id === 'string' ? c.id : '', name, words, covers: rules, coversWords: cw, text: [name, ...(words === name ? [] : [words]), ...(cw ? [cw] : [])].join(' — ') };
|
|
94
|
+
const e = { id: typeof c.id === 'string' ? c.id : '', name, words, covers: rules, coversWords: cw, text: labelled([name, ...(words === name ? [] : [words]), ...(cw ? [cw] : [])].join(' — '), 'agent') }; // M10 am22 (4): the AI wrote every sheet check
|
|
94
95
|
const res = newest && Array.isArray(newest.results) ? newest.results.find((/** @type {any} */ r) => isRec(r) && r.id === c.id) : undefined;
|
|
95
96
|
if (isRec(res) && typeof res.ok === 'boolean') {
|
|
96
97
|
e.ok = res.ok;
|
package/src/ticket-draft.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// M12 piece 3 (docs/wiki/the-module-ladder.md, "M12 scope (restart)" item 4): what the DRAFTER is told about a ticket role, and what it may suggest.
|
|
2
2
|
// A ticket role is a signed page input (`source <role> = page:<address>`) whose address is a GitHub issues list: it is never fetched at draft (one ticket is read
|
|
3
|
-
// per run through the job's MCP tools). The drafter may SUGGEST the job's `mcp`/`mcpTools` (issue_read) and a `ticketFilter` (priority / label names); a human
|
|
3
|
+
// per run through the job's MCP tools). The drafter may SUGGEST the job's `mcp`/`mcpTools` (issue_read), and MUST add a `ticketFilter` (priority / label names) when a guardrail names a priority or a label; a human
|
|
4
4
|
// signs it and code decides at run. The first facts line is F90c's, the line that made the drafter read a ticket role at all (FINDINGS F90c, F92).
|
|
5
5
|
import { discoverServers } from 'bare-agent/mcp';
|
|
6
6
|
import { startableMcpServers } from './mcp-sources.js';
|
|
@@ -63,7 +63,7 @@ export function ticketSchemaParts({ flowType, tools }) {
|
|
|
63
63
|
labels: { type: 'array', items: { type: 'string' }, description: 'label names, one of which a ticket must carry; only when a guardrail names them' },
|
|
64
64
|
},
|
|
65
65
|
additionalProperties: false,
|
|
66
|
-
description: '
|
|
66
|
+
description: 'required when a guardrail names a priority or a label: put those values here; leave it out only when no guardrail names one',
|
|
67
67
|
},
|
|
68
68
|
ticketWatch: { type: 'array', items: { type: 'string', enum: ['state', 'labels'] }, description: 'optional: suggest only for a guardrail that says to run a ticket again when its state or its labels change' },
|
|
69
69
|
},
|
package/src/ticket-labels.js
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
// Three outcomes are kept apart: skip (a definite miss, or closed), run (a match), run-with-`unsure` (an off-scale or unreadable label goes to a human at the
|
|
5
5
|
// ask, NEVER skipped). Normaliser borrowed in shape from fwdloop poc/mcp/f96/f96.mjs (the F96 rules, 12 of 12 on real tickets), re-shaped to a pure function.
|
|
6
6
|
|
|
7
|
-
/** `P0`..`P3`, optionally after `priority`, `priority:`, `priority /` or `priority -`;
|
|
8
|
-
const PRIORITY_LABEL = /^(?:priority\s*[:/-]?\s*)?p([0-3])(?![
|
|
7
|
+
/** `P0`..`P3`, optionally after `priority`, `priority:`, `priority /` or `priority -`; no letter or digit may follow the digit (`P12`, `p2p` are no priority; `P1-urgent` is P1) */
|
|
8
|
+
const PRIORITY_LABEL = /^(?:priority\s*[:/-]?\s*)?p([0-3])(?![a-z0-9])/;
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* One priority value from a ticket's labels: `P0`..`P3`; `unsure` when two different ones are present, or when a label names a priority on another scale
|