fwdloop 0.16.0 → 0.17.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 +2 -0
- package/bin/fwdloop +8 -6
- package/package.json +1 -1
- package/src/authoring.js +6 -6
- package/src/catalogue.json +9 -3
- package/src/ctx-tools.js +245 -0
- package/src/draft-steps.js +89 -30
- package/src/drafter.js +28 -4
- package/src/draftspend.js +109 -3
- package/src/liveness.js +34 -10
- package/src/panel/author.js +101 -33
- package/src/panel/authorcard.js +13 -9
- package/src/panel/authorflows.js +3 -3
- package/src/panel/authorresume.js +5 -4
- package/src/panel/authorvalues.js +5 -3
- package/src/panel/data.js +17 -5
- package/src/panel/index.html +74 -42
- package/src/panel/server.js +10 -5
- package/src/panel/settings.js +2 -2
- package/src/plain-checks.js +51 -0
- package/src/primitives.js +34 -3
- package/src/provider.js +17 -8
- package/src/run-store.js +47 -0
- package/src/runner.js +2 -0
- package/src/setup.js +3 -0
- package/src/version.js +13 -0
- package/types/authoring.d.ts +1 -3
- package/types/ctx-tools.d.ts +18 -0
- package/types/draft-steps.d.ts +38 -5
- package/types/drafter.d.ts +3 -3
- package/types/draftspend.d.ts +56 -0
- package/types/liveness.d.ts +7 -1
- package/types/panel/author.d.ts +5 -5
- package/types/panel/authorcard.d.ts +12 -2
- package/types/panel/authorflows.d.ts +3 -3
- package/types/panel/authorvalues.d.ts +3 -1
- package/types/panel/server.d.ts +4 -2
- package/types/plain-checks.d.ts +22 -0
- package/types/primitives.d.ts +0 -6
- package/types/provider.d.ts +7 -1
- package/types/run-store.d.ts +11 -0
- package/types/setup.d.ts +8 -0
- package/types/version.d.ts +2 -0
|
@@ -22,7 +22,7 @@ import { auditSpend } from '../runner.js';
|
|
|
22
22
|
import {
|
|
23
23
|
flowValues, pickRunValues, valuesHash, writeRunValues,
|
|
24
24
|
} from '../runvalues.js';
|
|
25
|
-
import { capFloorFor,
|
|
25
|
+
import { capFloorFor, capFloorOf } from './authorcard.js';
|
|
26
26
|
import { formFacts } from './authorflows.js';
|
|
27
27
|
import { checkValues } from './authorvalues.js';
|
|
28
28
|
import { getRunControls } from './data.js';
|
|
@@ -75,7 +75,7 @@ export function createResumeDoor(opts) {
|
|
|
75
75
|
const hasRound = read.declaration.steps.some((st) => !(read.arbiter.asks ?? []).some((a) => a.line === st.fromLine));
|
|
76
76
|
if (formOnly) return { ok: /** @type {true} */ (true), flow, runId, runDir: rd.runDir, version, base, spentUsd: spent.total, read, hasRound };
|
|
77
77
|
const checked = checkValues({
|
|
78
|
-
allowedKeys: KEYS, body: b, base, realRoot, capOnly: true, floorUsd: capFloorFor(hasRound, home, readModelRecord(join(realRoot, flow))), spentUsd: spent.total, monthlyClaim, always: true,
|
|
78
|
+
allowedKeys: KEYS, body: b, base, realRoot, capOnly: true, floorUsd: capFloorFor(hasRound, home, readModelRecord(join(realRoot, flow))), floorModel: capFloorOf(hasRound, home, readModelRecord(join(realRoot, flow))).model, spentUsd: spent.total, monthlyClaim, always: true,
|
|
79
79
|
});
|
|
80
80
|
if (!checked.ok) {
|
|
81
81
|
return no(checked.status, checked.refused ? { refused: checked.refused, say: checked.say, refusals: checked.refusals } : { refused: 'resume', refusals: checked.refusals, say: checked.refusals[0]?.say ?? 'Not resumed. Fix the marked box.' });
|
|
@@ -101,11 +101,12 @@ export function createResumeDoor(opts) {
|
|
|
101
101
|
const inputsRead = readFileInside(s.runDir, 'inputs.json');
|
|
102
102
|
let inputs = [];
|
|
103
103
|
try { inputs = inputsRead.ok ? JSON.parse(inputsRead.text).map((m) => ({ role: String(m.id), path: String(m.source) })) : []; } catch { inputs = []; }
|
|
104
|
-
const
|
|
104
|
+
const floor = capFloorOf(s.hasRound, home, readModelRecord(dirname(dirname(s.runDir))));
|
|
105
|
+
const floorUsd = floor.usd;
|
|
105
106
|
return {
|
|
106
107
|
status: 200,
|
|
107
108
|
body: {
|
|
108
|
-
ok: true, flow: s.flow, runId: s.runId, version: s.version, values: s.base, spentUsd: s.spentUsd, inputs, floorUsd,
|
|
109
|
+
ok: true, flow: s.flow, runId: s.runId, version: s.version, values: s.base, spentUsd: s.spentUsd, inputs, floorUsd, floorModel: floor.model, jobLines: formFacts(s.read, home, dirname(dirname(s.runDir))).jobLines, model: formFacts(s.read, home, dirname(dirname(s.runDir))).model,
|
|
109
110
|
},
|
|
110
111
|
};
|
|
111
112
|
},
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
//
|
|
6
6
|
// What a run can change without a new flow is exactly these values; a job line, an ask's words or position, or the steps are not a run
|
|
7
7
|
// (the body may not even carry them: an unknown key is refused by name with the new-flow sentence).
|
|
8
|
-
import {
|
|
8
|
+
import { destinationRefusal } from './authorcard.js';
|
|
9
|
+
import { capTooSmallText } from '../draftspend.js';
|
|
9
10
|
import { monthlyRefusalText } from '../monthly.js';
|
|
10
11
|
import { parseWaitMs, valuesHash, sameValues } from '../runvalues.js';
|
|
11
12
|
|
|
@@ -33,6 +34,7 @@ const typed = (v) => (typeof v === 'string' ? v.trim() : v);
|
|
|
33
34
|
* @param {{capUsd: number, destination: string|null, askWaits: Record<string,string>}} a.base the values in force now (the flow's own, or the run's newest signed version)
|
|
34
35
|
* @param {string} a.realRoot the flows root (real path)
|
|
35
36
|
* @param {boolean} a.capOnly Resume: destination and waits are never read from the body
|
|
37
|
+
* @param {string|null} [a.floorModel] the model id the floor was computed for (named in the refusal, M4d am20)
|
|
36
38
|
* @param {number} a.floorUsd the smallest cap that funds one round of a step (amendment 4 item 2); 0 = none
|
|
37
39
|
* @param {number} [a.spentUsd] what the run has already spent (Resume): the cap must be above it
|
|
38
40
|
* @param {boolean} [a.always] Resume: the floor and the monthly check always apply. A Run applies them only when its cap differs from the
|
|
@@ -41,7 +43,7 @@ const typed = (v) => (typeof v === 'string' ? v.trim() : v);
|
|
|
41
43
|
* @returns {{ ok: true, values: {capUsd: number, destination: string|null, askWaits: Record<string,string>}, differs: boolean, remainingUsd: number } | { ok: false, status: number, refusals: {field: string, say: string}[], refused?: string, say?: string }}
|
|
42
44
|
*/
|
|
43
45
|
export function checkValues({
|
|
44
|
-
allowedKeys, body, base, realRoot, capOnly, floorUsd, spentUsd = 0, monthlyClaim, always = false,
|
|
46
|
+
allowedKeys, body, base, realRoot, capOnly, floorUsd, floorModel = null, spentUsd = 0, monthlyClaim, always = false,
|
|
45
47
|
}) {
|
|
46
48
|
/** @type {{field: string, say: string}[]} */
|
|
47
49
|
const refusals = [];
|
|
@@ -64,7 +66,7 @@ export function checkValues({
|
|
|
64
66
|
if (refusals.length === 0) {
|
|
65
67
|
if (spentUsd > 0 && capUsd <= spentUsd + 1e-9) {
|
|
66
68
|
no('capUsd', `The cap must be above what is already spent (at least $${leastResumeCapUsd(spentUsd, floorUsd).toFixed(2)}).`);
|
|
67
|
-
} else if (capUsd < floorUsd && (always || capUsd !== base.capUsd)) no('capUsd',
|
|
69
|
+
} else if (capUsd < floorUsd && (always || capUsd !== base.capUsd)) no('capUsd', capTooSmallText('run', capUsd, floorUsd, String(floorModel)));
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
let destination = base.destination;
|
package/src/panel/data.js
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
import {
|
|
23
23
|
existsSync, realpathSync,
|
|
24
24
|
} from 'node:fs';
|
|
25
|
+
import { plainPlanCheck } from '../plain-checks.js';
|
|
25
26
|
import { join, basename, sep } from 'node:path';
|
|
26
27
|
|
|
27
28
|
import {
|
|
@@ -1521,6 +1522,17 @@ export function getDraftBlock(flowDir, runDir) {
|
|
|
1521
1522
|
usd: typeof r.costUsd === 'number' ? r.costUsd : undefined, spendComplete: r.spendComplete === true, tokensDisplay: { kind: 'no-model' },
|
|
1522
1523
|
...(typeof r.wallMs === 'number' ? { wallMs: r.wallMs } : {}),
|
|
1523
1524
|
});
|
|
1525
|
+
// M4d am15 item 4: one row per try under the draft's plan row: `try N ✗|✓`, its plain reason (the first refusal, "and k more"), the raw checker text under it.
|
|
1526
|
+
// The free retry after a broken reply reads `try N again`. A flow signed before am15 recorded no tries: nothing is added.
|
|
1527
|
+
const tryRows = (r, n) => (Array.isArray(r.tries) ? r.tries : []).map((t, k) => {
|
|
1528
|
+
const reds = Array.isArray(t.reds) ? t.reds.map(String) : [];
|
|
1529
|
+
const gap = t.passed ? '' : (reds.length > 0 ? `${plainPlanCheck(reds[0]).reason}${reds.length > 1 ? ` (and ${reds.length - 1} more)` : ''}` : String(t.outcome ?? ''));
|
|
1530
|
+
return {
|
|
1531
|
+
attempt: `${n}.${k + 1}`, step: 'drafting', class: null, verdict: t.passed ? 'green' : 'red', gap, at: r.at ?? null, setup: true, blocked: false,
|
|
1532
|
+
action: `${t.label} ${t.passed ? '✓' : '✗'}`, tryRow: true, tokensDisplay: { kind: 'no-model' },
|
|
1533
|
+
...(t.passed ? {} : { raw: reds.length > 0 ? reds : [String(t.rawOutcome ?? t.outcome ?? '')] }),
|
|
1534
|
+
};
|
|
1535
|
+
});
|
|
1524
1536
|
// M4e amendment 8 item 1, line 4: one short phrase per Draft row, in order (the drafting card joins them with ` · `)
|
|
1525
1537
|
const happened = [];
|
|
1526
1538
|
const retry = (r) => (Number.isInteger(r.structureRetries) && r.structureRetries >= 1 ? ` (retry ${r.structureRetries} of ${MAX_STRUCTURE_RETRIES})` : '');
|
|
@@ -1541,11 +1553,11 @@ export function getDraftBlock(flowDir, runDir) {
|
|
|
1541
1553
|
typeof c.inputs === 'string' && c.inputs.trim() ? `inputs: ${c.inputs.trim().replace(/\n+/g, ' / ')}` : null, `job: ${String(c.job ?? '').trim().replace(/\n+/g, ' / ')}`].filter(Boolean).join(' · ');
|
|
1542
1554
|
rows.push(human(r, n, { action: 'card (you)', gap }));
|
|
1543
1555
|
} else if (r.kind === 'note') rows.push(human(r, n, { action: 'note (you)', gap: String(r.text ?? '') }));
|
|
1544
|
-
else if (r.kind === 'draft') rows.push(model(r, n, 'draft'));
|
|
1545
|
-
else if (r.kind === 'change') rows.push(model(r, n, `change ${r.n}`));
|
|
1546
|
-
else if (r.kind === 'startover') rows.push(model(r, n, 'start over'));
|
|
1547
|
-
else if (r.kind === 'revise') rows.push(model(r, n, `revise ${r.n}`));
|
|
1548
|
-
else if (r.kind === 'redraft') rows.push(model(r, n, `answers redraft ${r.n}`));
|
|
1556
|
+
else if (r.kind === 'draft') { rows.push(model(r, n, 'draft')); rows.push(...tryRows(r, n)); }
|
|
1557
|
+
else if (r.kind === 'change') { rows.push(model(r, n, `change ${r.n}`)); rows.push(...tryRows(r, n)); }
|
|
1558
|
+
else if (r.kind === 'startover') { rows.push(model(r, n, 'start over')); rows.push(...tryRows(r, n)); }
|
|
1559
|
+
else if (r.kind === 'revise') { rows.push(model(r, n, `revise ${r.n}`)); rows.push(...tryRows(r, n)); }
|
|
1560
|
+
else if (r.kind === 'redraft') { rows.push(model(r, n, `answers redraft ${r.n}`)); rows.push(...tryRows(r, n)); }
|
|
1549
1561
|
else if (r.kind === 'sign') rows.push(human(r, n, { action: `sign (${r.signedBy ?? 'you'})`, gap: `plan ${String(r.hash ?? '').slice(0, 12)}` }));
|
|
1550
1562
|
});
|
|
1551
1563
|
}
|
package/src/panel/index.html
CHANGED
|
@@ -119,6 +119,11 @@
|
|
|
119
119
|
.topbar > div:first-child{display:flex;align-items:baseline;gap:0;white-space:nowrap;overflow:hidden;}
|
|
120
120
|
.topbar .brand{font-weight:700;font-size:17px;letter-spacing:0.06em;flex:none;}
|
|
121
121
|
.topbar .brand::before{content:"■ ";}
|
|
122
|
+
.update-bar{display:flex;flex-wrap:wrap;align-items:center;gap:6px 12px;padding:6px 16px;background:var(--amber);color:#000;font-size:13px;}
|
|
123
|
+
.update-bar[hidden]{display:none;}
|
|
124
|
+
.update-bar .btn{color:#000;border-color:#000;}
|
|
125
|
+
.topbar .version{font-size:12px;color:var(--text-dim);margin-left:8px;flex:none;white-space:nowrap;}
|
|
126
|
+
.topbar .version::before{content:"· ";color:var(--text-faint);}
|
|
122
127
|
.topbar .tagline{font-size:12px;color:var(--text-dim);margin-left:8px;overflow:hidden;text-overflow:ellipsis;}
|
|
123
128
|
.topbar .tagline::before{content:"· ";color:var(--text-faint);}
|
|
124
129
|
@media (max-width: 600px){ .topbar .tagline{display:none;} }
|
|
@@ -499,7 +504,9 @@
|
|
|
499
504
|
.chat-steps .step.wait .step-label{color:var(--amber);}
|
|
500
505
|
.chat-steps .step-detail{display:block;flex-basis:100%;min-width:0;padding-left:1.2em;color:var(--text-faint);word-break:break-word;white-space:pre-wrap;}
|
|
501
506
|
.chat-steps .step.bad .step-detail{color:var(--red);}
|
|
507
|
+
.chat-steps .step.note .step-label{color:var(--text);padding-left:1.2em;}
|
|
502
508
|
.chat-steps .step[data-step="thinking"].bad .step-label{color:var(--red);font-weight:600;}
|
|
509
|
+
.audit-raw{color:var(--text-faint);font-size:11px;word-break:break-word;white-space:pre-wrap;margin-top:2px;}
|
|
503
510
|
.chat-steps .step-raw{margin-top:2px;color:var(--text-faint);}
|
|
504
511
|
.chat-steps .step-raw summary{cursor:pointer;}
|
|
505
512
|
.chat-steps .step.run .step-sign::after{content:"\2026";}
|
|
@@ -762,9 +769,15 @@
|
|
|
762
769
|
|
|
763
770
|
<div id="FwdloopPanel">
|
|
764
771
|
|
|
772
|
+
<div id="update-bar" class="update-bar" data-testid="update-bar" role="status" hidden>
|
|
773
|
+
<span id="update-text"></span>
|
|
774
|
+
<button class="btn" type="button" id="update-reload" data-testid="update-reload">Reload</button>
|
|
775
|
+
</div>
|
|
776
|
+
|
|
765
777
|
<header class="topbar">
|
|
766
778
|
<div>
|
|
767
779
|
<span class="brand">fwdloop</span>
|
|
780
|
+
<span class="version" data-version="__FWDLOOP_VERSION__">v__FWDLOOP_VERSION__</span>
|
|
768
781
|
<span class="tagline">automate a job — it has humans in it</span>
|
|
769
782
|
</div>
|
|
770
783
|
<div class="topbar-right">
|
|
@@ -903,6 +916,7 @@
|
|
|
903
916
|
<label for="jf-cap-money">Cap $</label>
|
|
904
917
|
<input id="jf-cap-money" type="text" inputmode="decimal" placeholder="per run" data-testid="jf-cap-money">
|
|
905
918
|
<div class="hint" id="jf-cap-note" data-testid="cap-note"></div>
|
|
919
|
+
<div class="hint" id="jf-cap-job-note" data-testid="jf-cap-job-note"></div>
|
|
906
920
|
<div class="jf-err" id="jf-err-capUsd" data-testid="jf-err-capUsd"></div>
|
|
907
921
|
</div>
|
|
908
922
|
<div class="cap-field">
|
|
@@ -1192,6 +1206,7 @@
|
|
|
1192
1206
|
"use strict";
|
|
1193
1207
|
|
|
1194
1208
|
var PORT = "__FWDLOOP_PANEL_PORT__";
|
|
1209
|
+
var PLAN_CHECK_RULES = __FWDLOOP_PLAN_CHECK_RULES__;
|
|
1195
1210
|
// No token, no cookie (M4e amendment 4 item 8): the panel is local and trusted; the server checks Host and, on a POST, Origin.
|
|
1196
1211
|
document.getElementById("host-line").textContent = "127.0.0.1:" + PORT;
|
|
1197
1212
|
|
|
@@ -1285,7 +1300,7 @@
|
|
|
1285
1300
|
return (r.gapHead || []).concat(["ask waits " + waits]).join(" · ");
|
|
1286
1301
|
}
|
|
1287
1302
|
function auditCostCellText(r){
|
|
1288
|
-
if(r.setup && typeof r.usd !== "number" && r.verdict === "hitl") return "—"; // a setup row you wrote (card, note, sign) has no cost
|
|
1303
|
+
if(r.setup && typeof r.usd !== "number" && (r.verdict === "hitl" || r.tryRow === true)) return "—"; // a try row (its plan row has the cost) or a setup row you wrote (card, note, sign) has no cost of its own
|
|
1289
1304
|
if(r.setup) return money(r.usd, r.spendComplete) + (typeof r.wallMs === "number" ? " \u00b7 " + duration(r.wallMs) : ""); // a draft/change row: its own booked cost ("unknown" when nobody booked it) and time (left out when not recorded)
|
|
1290
1305
|
var bits = [money(r.usd, r.spendComplete)];
|
|
1291
1306
|
var td = r.tokensDisplay;
|
|
@@ -2467,6 +2482,7 @@
|
|
|
2467
2482
|
function auditDetailHtml(r, word, actionText, isRejectRow){
|
|
2468
2483
|
var lines = (typeof r.step === "string" && r.step.length > 0 ? [["step", r.step]] : []).concat([["result", word], ["action", actionText]]);
|
|
2469
2484
|
if(!isRejectRow && r.gap) lines.push(["gap", auditGapText(r)]);
|
|
2485
|
+
if(Array.isArray(r.raw) && r.raw.length > 0) lines.push(["raw", r.raw.join(" | ")]);
|
|
2470
2486
|
if(Array.isArray(r.refused) && r.refused.length > 0){
|
|
2471
2487
|
lines.push(["refused", r.refused.map(function(x){ return x.verb + " " + x.path + " (" + x.rule + ")"; }).join("; ")]);
|
|
2472
2488
|
}
|
|
@@ -2487,6 +2503,11 @@
|
|
|
2487
2503
|
// number and no close class — it shows nothing / "—", never "null", "unknown" or "#null".
|
|
2488
2504
|
function auditAttemptText(r){ return (typeof r.attempt === "number" || (typeof r.attempt === "string" && r.attempt.length > 0)) ? String(r.attempt) : ""; }
|
|
2489
2505
|
function auditCloseText(r){ return (r.setup || r.class === null || r.class === undefined) ? "—" : closeClassLabel(r.class); }
|
|
2506
|
+
// M4d am15 item 4: a try row's raw checker text, under its plain reason (the Gap cell). Server data, always escaped.
|
|
2507
|
+
function auditRawHtml(r){
|
|
2508
|
+
if(!Array.isArray(r.raw) || r.raw.length === 0) return "";
|
|
2509
|
+
return r.raw.map(function(t){ return "<div class=\"audit-raw\">" + escapeXml(String(t)) + "</div>"; }).join("");
|
|
2510
|
+
}
|
|
2490
2511
|
function buildAuditRowEl(r, includeStep){
|
|
2491
2512
|
var tr = document.createElement("tr");
|
|
2492
2513
|
var glyph = verdictGlyph(r.verdict, r.class);
|
|
@@ -2503,7 +2524,7 @@
|
|
|
2503
2524
|
"<td data-label=\"Attempt\">" + escapeXml(auditAttemptText(r)) + "</td>" +
|
|
2504
2525
|
(includeStep ? "<td data-label=\"Step\">" + escapeXml(r.stepName || r.step) + "</td>" : "") +
|
|
2505
2526
|
"<td data-label=\"Action\">" + escapeXml(actionText) + "</td>" +
|
|
2506
|
-
"<td data-label=\"Gap\">" + escapeXml(isRejectRow ? "" : auditGapText(r)) + "</td>" +
|
|
2527
|
+
"<td data-label=\"Gap\">" + escapeXml(isRejectRow ? "" : auditGapText(r)) + auditRawHtml(r) + "</td>" +
|
|
2507
2528
|
"<td data-label=\"Cost\">" + escapeXml(auditCostCellText(r)) + "</td>" +
|
|
2508
2529
|
"<td data-label=\"Verdict\"><span class=\"badge " + badgeClass + "\">" + escapeXml(word) + "</span></td>" +
|
|
2509
2530
|
"<td data-label=\"Close\">" + escapeXml(auditCloseText(r)) + "</td>" +
|
|
@@ -2980,6 +3001,19 @@
|
|
|
2980
3001
|
el._say = say;
|
|
2981
3002
|
say(timeLeftMs);
|
|
2982
3003
|
}
|
|
3004
|
+
// M4d am18: the page keeps the version it was served with (the header's data-version, am17); the Inbox poll reports the server's. A different one = the panel
|
|
3005
|
+
// restarted on newer code under this open tab: say so. Pure text rule (null = no bar), one painter.
|
|
3006
|
+
function updateBarText(pageVersion, serverVersion){
|
|
3007
|
+
if(typeof pageVersion !== "string" || pageVersion === "" || typeof serverVersion !== "string" || serverVersion === "") return null;
|
|
3008
|
+
return pageVersion === serverVersion ? null : "fwdloop was updated to v" + serverVersion + ". Reload this page.";
|
|
3009
|
+
}
|
|
3010
|
+
function paintUpdateBar(serverVersion){
|
|
3011
|
+
var vEl = document.querySelector(".topbar .version");
|
|
3012
|
+
var text = updateBarText(vEl ? vEl.getAttribute("data-version") : "", serverVersion);
|
|
3013
|
+
document.getElementById("update-bar").hidden = text === null;
|
|
3014
|
+
if(text !== null) document.getElementById("update-text").textContent = text;
|
|
3015
|
+
}
|
|
3016
|
+
document.getElementById("update-reload").addEventListener("click", function(){ location.reload(); });
|
|
2983
3017
|
function tickLeft(){
|
|
2984
3018
|
document.querySelectorAll(".live-left").forEach(function(el){ el._say(Math.max(0, el._endsAt - Date.now())); });
|
|
2985
3019
|
}
|
|
@@ -3075,7 +3109,7 @@
|
|
|
3075
3109
|
// Immediate (every user action that re-reads calls this); the tick uses `listsDue` to throttle.
|
|
3076
3110
|
function reloadLists(){
|
|
3077
3111
|
lastListsAt = Date.now();
|
|
3078
|
-
getJSON("/api/inbox").then(function(r){ renderInbox(r.rows || [], r.openCount); }).catch(function(){});
|
|
3112
|
+
getJSON("/api/inbox").then(function(r){ renderInbox(r.rows || [], r.openCount); paintUpdateBar(r.version); }).catch(function(){});
|
|
3079
3113
|
getJSON("/api/runs").then(function(r){
|
|
3080
3114
|
var rows = r.rows || [];
|
|
3081
3115
|
var next = sig(rows);
|
|
@@ -3938,7 +3972,7 @@
|
|
|
3938
3972
|
var sessionId = null; // the draft's id (GET /api/author/<id>)
|
|
3939
3973
|
var sessionLive = false; // a draft exists that is not abandoned or signed
|
|
3940
3974
|
var lastState = null; // the draft as the server last described it
|
|
3941
|
-
var signInfo = null; // the first Sign click's reply: { hash, flowName, capUsd, runId }
|
|
3975
|
+
var signInfo = null; // the first Sign click's reply: { hash, flowName, capUsd, runId, split }
|
|
3942
3976
|
var signClickedOnce = false;
|
|
3943
3977
|
var reviseOpen = false; // amendment 14 item 2: Revise was pressed on a green plan, so every card field is open (ONE writer: setReviseOpen)
|
|
3944
3978
|
var qKey = ""; // which question the box is showing (draft id + k): the answer box is rewritten only when this changes
|
|
@@ -4059,33 +4093,11 @@
|
|
|
4059
4093
|
// am41 item 7: ONE function turns a checker's red (the text src/declaration.js writes) into one plain sentence for the card. The raw text rides
|
|
4060
4094
|
// along unchanged and is folded under "details"; a red no rule below knows gets the generic sentence and still shows its raw text. This reads
|
|
4061
4095
|
// the checker's own fixed wording, never the model's prose.
|
|
4096
|
+
// M4d am15: the plain words are src/plain-checks.js, handed to the page by the server (PLAN_CHECK_RULES, top of this script): one copy.
|
|
4062
4097
|
function plainPlanCheck(raw){
|
|
4063
|
-
var PLAN_CHECK_RULES = [
|
|
4064
|
-
[/which is not in the job line's words/, "A section name in the plan's check is not in your job line. Change the job line to use the section words you want."],
|
|
4065
|
-
[/the job line says .*; the check says/, "The sections in the plan's check come in a different order than your job line. Change the job line to change the order."],
|
|
4066
|
-
[/the guardrail says \d+ sections; the check has/, "The number of sections in your guardrail is not the number in the plan's check."],
|
|
4067
|
-
[/section name is a short phrase|which is the job line or most of it/, "A section name in the plan's check is too long; it must be a short phrase from your job line."],
|
|
4068
|
-
[/one section name may not contain another/, "One section name in the plan's check contains another, which cannot be checked."],
|
|
4069
|
-
[/wordsPerSection/, "The words for each section in your guardrail and in the plan's check do not match."],
|
|
4070
|
-
[/work as a pair/, "The plan's check has one part of a pair without the other, so it cannot be checked."],
|
|
4071
|
-
[/is blank|characters; the most one entry|ends in ":"/, "A name in the plan's check is empty, too long or ends in a colon, so it cannot be matched."],
|
|
4072
|
-
[/cannot be built into a check/, "The plan's check cannot be built from what the AI wrote."],
|
|
4073
|
-
[/is not its signed line/, "A step does not use your job line word for word as its goal."],
|
|
4074
|
-
[/not in the catalogue|not wired|which is not signed|checkpoint/, "A step uses a tool that is not available for this job."],
|
|
4075
|
-
[/reads artifact|is a duplicate|\.reads must|\.emits must/, "The steps do not pass their results to each other in a workable order."],
|
|
4076
|
-
[/ask at line \d+|signed ask at line|ask slot/, "The ask on one of your lines is not set up as a plain stop where you decide."],
|
|
4077
|
-
[/send at line \d+|signed send at line|send slot/, "The send step is not set up to follow your accept and write only to your destination."],
|
|
4078
|
-
[/hitl after the last signed ask/, "A step after your last ask would leave without your seeing it, so it is refused."],
|
|
4079
|
-
[/is a pause .* unsigned line/, "A step pauses at a line you did not sign as an ask."],
|
|
4080
|
-
[/neither served by any step/, "A line of your job is not covered by any step."],
|
|
4081
|
-
[/picks|inputFacts|invented name/, "The plan names a field that is not in your input."],
|
|
4082
|
-
[/guardrailClasses|unjudgeable|refused/, "The AI's notes on which lines it can check are not in a form the checker accepts."],
|
|
4083
|
-
[/^line \d+'s (guardrail|check)|can't write files/, null],
|
|
4084
|
-
[/must be an? |is required|must name|does not name/, "The plan the AI wrote is not in the shape the checker needs."]
|
|
4085
|
-
];
|
|
4086
4098
|
var text = typeof raw === "string" ? raw : "";
|
|
4087
4099
|
for(var i = 0; i < PLAN_CHECK_RULES.length; i++){
|
|
4088
|
-
if(PLAN_CHECK_RULES[i]
|
|
4100
|
+
if(new RegExp(PLAN_CHECK_RULES[i].re).test(text)) return {say: PLAN_CHECK_RULES[i].say === null ? text.replace(/^declaration: /, "") : PLAN_CHECK_RULES[i].say, raw: text};
|
|
4089
4101
|
}
|
|
4090
4102
|
return {say: "One of the checks on the plan failed.", raw: text};
|
|
4091
4103
|
}
|
|
@@ -4104,8 +4116,8 @@
|
|
|
4104
4116
|
function draftLines(fallback){
|
|
4105
4117
|
if(!state || !Array.isArray(state.stepList) || state.stepList.length === 0) return fallback();
|
|
4106
4118
|
state.stepList.forEach(function(st){
|
|
4107
|
-
var row = {id: st.id, label: st.label, status: st.status === "failed" ? "failed" : "done", details: st.details || []};
|
|
4108
|
-
if(
|
|
4119
|
+
var row = {id: st.id, label: st.label, status: st.status === "failed" ? "failed" : (st.status === "waiting" ? "waiting" : "done"), details: st.details || []};
|
|
4120
|
+
if(st.note === true) row.note = true;
|
|
4109
4121
|
out.push(row);
|
|
4110
4122
|
});
|
|
4111
4123
|
}
|
|
@@ -4119,11 +4131,18 @@
|
|
|
4119
4131
|
draftLines(function(){ out.push({id: "drafted", label: "drafted with " + who, status: "done", details: []}); });
|
|
4120
4132
|
var reviseNo = 0;
|
|
4121
4133
|
state.revises.forEach(function(rv){
|
|
4122
|
-
// an answer redraft (amendment 24 item 4) is not a revise and is not counted as one
|
|
4123
|
-
|
|
4134
|
+
// an answer redraft (amendment 24 item 4) is not a revise and is not counted as one; the server names each one (`rv.name`) and, from the plan's own log,
|
|
4135
|
+
// writes its line (`rv.lines`, src/draft-steps.js `reviseStepList`): one line, facts joined by " · ", a red one with one plain reason and a Fix line (am15)
|
|
4136
|
+
var label = rv.name || (rv.kind === "answers" ? "drafted again with your answers" : "revise " + (reviseNo += 1));
|
|
4124
4137
|
if(rv.phase === "running") out.push({id: "revise-" + rv.n, label: label, status: "running", details: []});
|
|
4125
|
-
else if(rv.
|
|
4126
|
-
|
|
4138
|
+
else if(Array.isArray(rv.lines) && rv.lines.length){
|
|
4139
|
+
rv.lines.forEach(function(l){
|
|
4140
|
+
var row = {id: "revise-" + rv.n + "-" + l.id, label: l.label, status: l.status === "failed" ? "failed" : "done", details: []};
|
|
4141
|
+
if(l.note === true) row.note = true;
|
|
4142
|
+
out.push(row);
|
|
4143
|
+
});
|
|
4144
|
+
}
|
|
4145
|
+
else out.push({id: "revise-" + rv.n, label: label, status: rv.phase === "green" ? "done" : "failed", details: []});
|
|
4127
4146
|
});
|
|
4128
4147
|
if(state.phase === "green"){
|
|
4129
4148
|
if(ctx.starting) out.push({id: "signed", label: "signed", status: "done", details: []});
|
|
@@ -4133,8 +4152,7 @@
|
|
|
4133
4152
|
} else if(state.phase === "red"){
|
|
4134
4153
|
draftLines(function(){
|
|
4135
4154
|
out.push({id: "drafted", label: "drafted with " + who, status: "done", details: []});
|
|
4136
|
-
|
|
4137
|
-
out.push({id: "checks", label: "plan checks", status: "failed", details: cf.details, raw: cf.raw});
|
|
4155
|
+
out.push({id: "checks", label: "plan checks", status: "failed", details: []}); // no log to read a reason from: the card's own sentence says it
|
|
4138
4156
|
});
|
|
4139
4157
|
} else if(state.phase === "stopped"){
|
|
4140
4158
|
out.push({id: "drafting", label: "drafting with " + who + capPart, status: "failed", details: []});
|
|
@@ -4358,23 +4376,33 @@
|
|
|
4358
4376
|
function jobHasModelStep(){
|
|
4359
4377
|
return byId("jf-job").value.split("\n").some(function(l){ var t = l.trim(); return t !== "" && t.charAt(0) !== "~" && !/^ask\b/i.test(t); });
|
|
4360
4378
|
}
|
|
4379
|
+
// M4d am21 item 3: with no step that needs a model the cap cannot be checked against one yet: a grey line says so (the New job card only)
|
|
4380
|
+
function paintCapJobNote(m){
|
|
4381
|
+
byId("jf-cap-job-note").textContent = (m === "new" && !jobHasModelStep()) ? "The cap is checked against the model once the job has a step." : "";
|
|
4382
|
+
}
|
|
4361
4383
|
function refreshCapNote(){
|
|
4384
|
+
paintCapJobNote(mode);
|
|
4362
4385
|
var cap = mode === "run" ? runCapEl.value.trim() : (mode === "resume" ? resumeCapEl.value.trim() : byId("jf-cap-money").value.trim());
|
|
4363
4386
|
var seq = ++capNoteSeq;
|
|
4364
4387
|
if(cap === ""){ setMoneyNote("", false); return; }
|
|
4365
4388
|
// a Resume holds only what the run has still to spend (amendment 4 item 1): the server is told what is already spent
|
|
4366
|
-
var spent = (mode === "resume" && resumeCtx) ? "&spent=" + encodeURIComponent(String(resumeCtx.form.spentUsd)) + "&flow=" + encodeURIComponent(resumeCtx.flow) : "";
|
|
4389
|
+
var spent = (mode === "resume" && resumeCtx) ? "&spent=" + encodeURIComponent(String(resumeCtx.form.spentUsd)) + "&flow=" + encodeURIComponent(resumeCtx.flow) + "&kind=run" : "";
|
|
4367
4390
|
var pk = modelPick();
|
|
4368
4391
|
var picked = (mode === "new" && pk.provider !== "") ? "&provider=" + encodeURIComponent(pk.provider) + "&model=" + encodeURIComponent(pk.model) : "";
|
|
4369
|
-
|
|
4392
|
+
// M4d am20: Run a signed flow does not draft: the server writes the same cap-too-small sentence with "run" (the flow's recorded model, else the one picked in Chat)
|
|
4393
|
+
var sfNow = selectedFlow();
|
|
4394
|
+
if(mode === "run" && sfNow) picked = "&kind=run&flow=" + encodeURIComponent(sfNow.flow) + (pk.provider !== "" ? "&provider=" + encodeURIComponent(pk.provider) + "&model=" + encodeURIComponent(pk.model) : "");
|
|
4395
|
+
// M4d am21 item 1: a card that belongs to a live draft (a revise, or the Start over about to be made) is checked for the pot left, as the doors do
|
|
4396
|
+
var ofDraft = (mode === "new" && sessionLive && sessionId) ? "&draft=" + encodeURIComponent(sessionId) : "";
|
|
4397
|
+
authorGet("/api/author/monthly-check?cap=" + encodeURIComponent(cap) + spent + picked + ofDraft).then(function(j){
|
|
4370
4398
|
if(seq !== capNoteSeq) return;
|
|
4371
4399
|
if(!j || j.ok !== true){ setMoneyNote("", false); return; }
|
|
4372
4400
|
var v = Number(cap);
|
|
4373
4401
|
if(mode === "new" && j.floorText && isFinite(v) && v > 0 && v < j.floorUsd && jobHasModelStep()){ setMoneyNote(j.floorText, true); return; }
|
|
4374
4402
|
// a Run's own cap is never judged against the floor (an old flow signed lower still runs plain); a changed cap below it is red
|
|
4375
4403
|
var sf = selectedFlow();
|
|
4376
|
-
if(mode === "run" && sf && j.floorText && isFinite(v) && v > 0 && v !== sf.capUsd && v < sf.capFloorUsd){ setMoneyNote(
|
|
4377
|
-
if(mode === "resume" && resumeCtx && j.floorText && isFinite(v) && v > resumeCtx.form.spentUsd && v < resumeCtx.form.floorUsd){ setMoneyNote(
|
|
4404
|
+
if(mode === "run" && sf && j.floorText && isFinite(v) && v > 0 && v !== sf.capUsd && v < sf.capFloorUsd){ setMoneyNote(j.floorText, true); return; }
|
|
4405
|
+
if(mode === "resume" && resumeCtx && j.floorText && isFinite(v) && v > resumeCtx.form.spentUsd && v < resumeCtx.form.floorUsd){ setMoneyNote(j.floorText, true); return; }
|
|
4378
4406
|
setMoneyNote(typeof j.text === "string" ? j.text : "", j.red === true);
|
|
4379
4407
|
}).catch(function(){ if(seq === capNoteSeq) setMoneyNote("", false); });
|
|
4380
4408
|
}
|
|
@@ -4682,7 +4710,9 @@
|
|
|
4682
4710
|
progressRow.hidden = steps.length === 0;
|
|
4683
4711
|
var html = steps.map(function(st){
|
|
4684
4712
|
var cls = st.status === "waiting" ? "wait" : (st.status === "running" ? "run" : (st.status === "failed" ? "bad" : "ok"));
|
|
4685
|
-
var sign = cls === "ok" ? "✓" : (cls === "bad" ? "✗" : "");
|
|
4713
|
+
var sign = st.note ? "" : (cls === "ok" ? "✓" : (cls === "bad" ? "✗" : ""));
|
|
4714
|
+
// M4d am15: a line with no ✓/✗ (the Fix line under a red plan check)
|
|
4715
|
+
if(st.note) cls += " note";
|
|
4686
4716
|
return '<li class="step ' + cls + '" data-step="' + escapeXml(st.id) + '"><div class="step-line"><span class="step-label">' + escapeXml(st.label) + '</span>' +
|
|
4687
4717
|
'<span class="step-sign">' + sign + '</span></div>' +
|
|
4688
4718
|
(st.details || []).map(function(d, k){
|
|
@@ -4770,6 +4800,8 @@
|
|
|
4770
4800
|
mainAction = b.action; mainStartOver = !!b.startOver;
|
|
4771
4801
|
// amendment 14 item 3: the count shows while a draft has revises to count; at 0 the way on is Start over
|
|
4772
4802
|
mainHint.textContent = (mode === "new" && sessionLive && st.revisable && st.phase !== "signed" && st.phase !== "questions-open") ? (st.left > 0 ? revisesLeftText(st.left) : "No revises left: Start over keeps the fields and gives 2 new ones.") : "";
|
|
4803
|
+
// M4d am16 item 3: the first Sign click shows how the card's Cap $ is split between drafting and this run, before the second click starts it
|
|
4804
|
+
if(mode === "new" && sessionLive && signInfo && signInfo.split && signClickedOnce) mainHint.textContent = signInfo.split.line;
|
|
4773
4805
|
reviseBtn.hidden = !reviseShownFor(st);
|
|
4774
4806
|
reviseBtn.disabled = !!st.busy;
|
|
4775
4807
|
startOverBtn.hidden = !startOverShownFor(st);
|
|
@@ -5063,7 +5095,7 @@
|
|
|
5063
5095
|
var o = chatPostOutcome(r);
|
|
5064
5096
|
if(!o.ok){ failFrom(r); refreshStartEnabled(); return; }
|
|
5065
5097
|
chatActionOk();
|
|
5066
|
-
signInfo = {hash: r.body.hash, flowName: r.body.flowName, capUsd: r.body.capUsd, runId: r.body.runId};
|
|
5098
|
+
signInfo = {hash: r.body.hash, flowName: r.body.flowName, capUsd: r.body.capUsd, runId: r.body.runId, split: r.body.split || null};
|
|
5067
5099
|
signClickedOnce = true;
|
|
5068
5100
|
if(lastState) renderActions(lastState); else refreshStartEnabled();
|
|
5069
5101
|
}).catch(function(){ busy = false; chatActionFailed(NETWORK_SAY); refreshStartEnabled(); });
|
package/src/panel/server.js
CHANGED
|
@@ -48,6 +48,8 @@
|
|
|
48
48
|
|
|
49
49
|
import { createServer } from 'node:http';
|
|
50
50
|
import { readFileSync, realpathSync } from 'node:fs';
|
|
51
|
+
import { pageRules } from '../plain-checks.js';
|
|
52
|
+
import { readOwnVersion } from '../version.js';
|
|
51
53
|
import path, { dirname, join } from 'node:path';
|
|
52
54
|
import { fileURLToPath } from 'node:url';
|
|
53
55
|
|
|
@@ -351,7 +353,7 @@ function authorPost(res, url, body, author) {
|
|
|
351
353
|
* real listening socket where that is simpler.
|
|
352
354
|
* @param {import('node:http').IncomingMessage} req
|
|
353
355
|
* @param {import('node:http').ServerResponse} res
|
|
354
|
-
* @param {{ root: string, port: number, resumer: ReturnType<typeof createResumer>, settings: ReturnType<typeof createSettings>, author: ReturnType<typeof createAuthor> }} opts
|
|
356
|
+
* @param {{ root: string, port: number, packagePath?: string, resumer: ReturnType<typeof createResumer>, settings: ReturnType<typeof createSettings>, author: ReturnType<typeof createAuthor> }} opts
|
|
355
357
|
*/
|
|
356
358
|
export function handleRequest(req, res, opts) {
|
|
357
359
|
const method = req.method ?? 'GET';
|
|
@@ -456,7 +458,7 @@ export function handleRequest(req, res, opts) {
|
|
|
456
458
|
if (pathname === '/api/author/live') r = opts.author.live();
|
|
457
459
|
else if (pathname === '/api/author/flows') r = opts.author.flows();
|
|
458
460
|
else if (pathname === '/api/author/run-again') r = opts.author.runAgain(url.searchParams.get('flow'), url.searchParams.get('runId'));
|
|
459
|
-
else if (pathname === '/api/author/monthly-check') r = opts.author.monthlyCheck(url.searchParams.get('cap'), url.searchParams.get('spent'), { provider: url.searchParams.get('provider') ?? undefined, model: url.searchParams.get('model') ?? undefined, flow: url.searchParams.get('flow') ?? undefined });
|
|
461
|
+
else if (pathname === '/api/author/monthly-check') r = opts.author.monthlyCheck(url.searchParams.get('cap'), url.searchParams.get('spent'), { provider: url.searchParams.get('provider') ?? undefined, model: url.searchParams.get('model') ?? undefined, flow: url.searchParams.get('flow') ?? undefined }, url.searchParams.get('kind') ?? 'drafting', url.searchParams.get('draft'));
|
|
460
462
|
else if (pathname === '/api/author/models') r = opts.author.models();
|
|
461
463
|
else if (pathname === '/api/author/resume-form') r = opts.author.resumeForm(url.searchParams.get('flow'), url.searchParams.get('runId'));
|
|
462
464
|
else if (sm) r = opts.author.startGet(sm[1]);
|
|
@@ -483,6 +485,9 @@ export function handleRequest(req, res, opts) {
|
|
|
483
485
|
return;
|
|
484
486
|
}
|
|
485
487
|
html = html.replace(/__FWDLOOP_PANEL_PORT__/g, String(opts.port));
|
|
488
|
+
const version = readOwnVersion(opts.packagePath); // M4d am17: the header's number, read from fwdloop's own package.json at serve time
|
|
489
|
+
html = version === null ? html.replace(/v__FWDLOOP_VERSION__/g, 'version unknown').replace(/__FWDLOOP_VERSION__/g, '') : html.replace(/__FWDLOOP_VERSION__/g, version);
|
|
490
|
+
html = html.replace(/__FWDLOOP_PLAN_CHECK_RULES__/g, () => JSON.stringify(pageRules())); // M4d am15: the one copy of the plain words
|
|
486
491
|
if (method === 'HEAD') {
|
|
487
492
|
res.writeHead(200, { 'content-type': 'text/html; charset=utf-8', 'content-length': Buffer.byteLength(html) });
|
|
488
493
|
res.end();
|
|
@@ -508,7 +513,7 @@ export function handleRequest(req, res, opts) {
|
|
|
508
513
|
|
|
509
514
|
if (pathname === '/api/inbox') {
|
|
510
515
|
const rows = listStops({ root: opts.root, resumeAttempt, catalogue });
|
|
511
|
-
send(200, { rows, openCount: inboxOpenCount(rows) });
|
|
516
|
+
send(200, { rows, openCount: inboxOpenCount(rows), version: readOwnVersion(opts.packagePath) }); // M4d am18: the page compares it with the version it was served with
|
|
512
517
|
return;
|
|
513
518
|
}
|
|
514
519
|
|
|
@@ -570,7 +575,7 @@ export function handleRequest(req, res, opts) {
|
|
|
570
575
|
* header). Resolves once actually listening; rejects on a bind error
|
|
571
576
|
* (including `EADDRINUSE`) with a `.port` field on the error for the
|
|
572
577
|
* caller's message.
|
|
573
|
-
* @param {{ port?: number, root: string, settings?: { home?: string, env?: Record<string,string|undefined>, fetch?: typeof fetch, now?: () => number, openFolderSpawn?: Function, platform?: string }, resume?: { env?: Record<string,string|undefined>, bin?: string, logDir?: string, maxTries?: number, windowMs?: number, slotMs?: number }, author?: { env?: Record<string,string|undefined>, loadEnv?: () => any, bin?: string } }} opts
|
|
578
|
+
* @param {{ port?: number, root: string, packagePath?: string, settings?: { home?: string, env?: Record<string,string|undefined>, fetch?: typeof fetch, now?: () => number, openFolderSpawn?: Function, platform?: string }, resume?: { env?: Record<string,string|undefined>, bin?: string, logDir?: string, maxTries?: number, windowMs?: number, slotMs?: number }, author?: { env?: Record<string,string|undefined>, loadEnv?: () => any, bin?: string } }} opts
|
|
574
579
|
* `resume` and `author` are for tests only (a fake env/bin, a short retry window); the CLI passes none.
|
|
575
580
|
* @returns {Promise<{ server: import('node:http').Server, port: number, close: () => Promise<void> }>}
|
|
576
581
|
*/
|
|
@@ -604,7 +609,7 @@ export function createPanelServer(opts) {
|
|
|
604
609
|
const server = createServer((req, res) => {
|
|
605
610
|
try {
|
|
606
611
|
handleRequest(req, res, {
|
|
607
|
-
root, port: boundPort, resumer, settings, author,
|
|
612
|
+
root, port: boundPort, resumer, settings, author, packagePath: opts.packagePath,
|
|
608
613
|
});
|
|
609
614
|
} catch (e) {
|
|
610
615
|
sendText(res, 500, 'internal error');
|
package/src/panel/settings.js
CHANGED
|
@@ -53,8 +53,8 @@ export function createSettings(cfg) {
|
|
|
53
53
|
const notKeyName = (slot) => (typeof slot === 'string' && slot !== '' && !isKeyName(slot)
|
|
54
54
|
? refuse('not-a-key-name', `${slot} is not a key name. A key name ends in _KEY, like MY_API_KEY. Nothing was saved.`) : null);
|
|
55
55
|
|
|
56
|
-
/** The row named by a request, or null: only a key that is in the keys file (or the shell) is a row. @param {
|
|
57
|
-
const slotOf = (slot) => (
|
|
56
|
+
/** The row named by a request, or null: only a key that is in the keys file (or the shell) is a row. @param {any} slot */
|
|
57
|
+
const slotOf = (slot) => (rowNames(keys()).includes(slot) ? slot : null);
|
|
58
58
|
|
|
59
59
|
/** config.json, or `{problem}` in plain words when it is broken (never read as "nothing set"). */
|
|
60
60
|
function config() {
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// M4d amendment 15: the plain words for a plan-check refusal. ONE copy of them: the Chat list (src/draft-steps.js), the Audit Draft rows
|
|
2
|
+
// (src/panel/data.js) and the page (the server hands it the same rules in index.html, see src/panel/server.js) all read this file.
|
|
3
|
+
// Moved here from the page's `plainPlanCheck` (M4e am41 item 7), sentences unchanged.
|
|
4
|
+
//
|
|
5
|
+
// `say` is the plain sentence(s) the page's revise lines show. `reason` is `say` without its fix. `fix` is the one short sentence that tells the human what to
|
|
6
|
+
// change (the job line, the guardrail, the inputs, the destination) or to Draft again when it is the AI's own form error; every rule has one (am15 item 3).
|
|
7
|
+
// The first two rules' `say` already ends with their fix, as the page has always shown them.
|
|
8
|
+
|
|
9
|
+
/** @type {ReadonlyArray<{re: RegExp, say: string|null, fix: string}>} `say` null = the checker's own sentence, as it is without its "declaration: " prefix */
|
|
10
|
+
export const PLAN_CHECK_RULES = Object.freeze([
|
|
11
|
+
{ re: /which is not in the job line's words/, say: "A section name in the plan's check is not in your job line. Change the job line to use the section words you want.", fix: 'Change the job line to use the section words you want.' },
|
|
12
|
+
{ re: /the job line says .*; the check says/, say: "The sections in the plan's check come in a different order than your job line. Change the job line to change the order.", fix: 'Change the job line to change the order.' },
|
|
13
|
+
{ re: /the guardrail says \d+ sections; the check has/, say: "The number of sections in your guardrail is not the number in the plan's check.", fix: 'Make the guardrail and the job line say the same number of sections, then Draft again.' },
|
|
14
|
+
{ re: /section name is a short phrase|which is the job line or most of it/, say: "A section name in the plan's check is too long; it must be a short phrase from your job line.", fix: 'Use a short phrase from your job line for each section, then Draft again.' },
|
|
15
|
+
{ re: /one section name may not contain another/, say: 'One section name in the plan\'s check contains another, which cannot be checked.', fix: 'Rename the sections in your job line so none contains another, then Draft again.' },
|
|
16
|
+
{ re: /wordsPerSection/, say: "The words for each section in your guardrail and in the plan's check do not match.", fix: 'Give each section one clear number of words in your guardrail, then Draft again.' },
|
|
17
|
+
{ re: /work as a pair/, say: "The plan's check has one part of a pair without the other, so it cannot be checked.", fix: 'Draft again; if it repeats, simplify the guardrail on that line.' },
|
|
18
|
+
{ re: /is blank|characters; the most one entry|ends in ":"/, say: "A name in the plan's check is empty, too long or ends in a colon, so it cannot be matched.", fix: 'Shorten the section names in your job line, then Draft again.' },
|
|
19
|
+
{ re: /cannot be built into a check/, say: "The plan's check cannot be built from what the AI wrote.", fix: 'Draft again; if it repeats, simplify the guardrail on that line.' },
|
|
20
|
+
{ re: /is not its signed line/, say: 'A step does not use your job line word for word as its goal.', fix: 'Draft again.' },
|
|
21
|
+
{ re: /not in the catalogue|not wired|which is not signed|checkpoint/, say: 'A step uses a tool that is not available for this job.', fix: 'Draft again; if it repeats, say in the job line what that step should do.' },
|
|
22
|
+
{ re: /reads artifact|is a duplicate|\.reads must|\.emits must/, say: 'The steps do not pass their results to each other in a workable order.', fix: 'Draft again.' },
|
|
23
|
+
{ re: /ask at line \d+|signed ask at line|ask slot/, say: 'The ask on one of your lines is not set up as a plain stop where you decide.', fix: 'Check the line that starts with Ask in your job, then Draft again.' },
|
|
24
|
+
{ re: /send at line \d+|signed send at line|send slot/, say: 'The send step is not set up to follow your accept and write only to your destination.', fix: 'Check the Destination on the card, then Draft again.' },
|
|
25
|
+
{ re: /hitl after the last signed ask/, say: 'A step after your last ask would leave without your seeing it, so it is refused.', fix: 'Move the lines you want to check before your last Ask line, then Draft again.' },
|
|
26
|
+
{ re: /is a pause .* unsigned line/, say: 'A step pauses at a line you did not sign as an ask.', fix: 'Mark the line you want to stop at with Ask, then Draft again.' },
|
|
27
|
+
{ re: /neither served by any step/, say: 'A line of your job is not covered by any step.', fix: 'Make every line of your job say one thing to do, then Draft again.' },
|
|
28
|
+
{ re: /picks|inputFacts|invented name/, say: 'The plan names a field that is not in your input.', fix: 'Check the names in your Inputs and job line, then Draft again.' },
|
|
29
|
+
{ re: /guardrailClasses|unjudgeable|refused/, say: "The AI's notes on which lines it can check are not in a form the checker accepts.", fix: 'Draft again.' },
|
|
30
|
+
{ re: /^line \d+'s (guardrail|check)|can't write files/, say: null, fix: 'Change the guardrail on that line the way the sentence says, then Draft again.' },
|
|
31
|
+
{ re: /must be an? |is required|must name|does not name/, say: 'The plan the AI wrote is not in the shape the checker needs.', fix: 'Draft again.' },
|
|
32
|
+
]);
|
|
33
|
+
|
|
34
|
+
export const GENERIC_SAY = 'One of the checks on the plan failed.';
|
|
35
|
+
export const GENERIC_FIX = 'Draft again.';
|
|
36
|
+
|
|
37
|
+
/** The rules as the page takes them: JSON, the regex as its source text. */
|
|
38
|
+
export const pageRules = () => PLAN_CHECK_RULES.map((r) => ({ re: r.re.source, say: r.say }));
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @param {unknown} raw one raw refusal text
|
|
42
|
+
* @returns {{ say: string, reason: string, fix: string, raw: string }}
|
|
43
|
+
*/
|
|
44
|
+
export function plainPlanCheck(raw) {
|
|
45
|
+
const text = typeof raw === 'string' ? raw : '';
|
|
46
|
+
const rule = PLAN_CHECK_RULES.find((r) => r.re.test(text));
|
|
47
|
+
const say = rule === undefined ? GENERIC_SAY : (rule.say === null ? text.replace(/^declaration: /, '') : rule.say);
|
|
48
|
+
const fix = rule === undefined ? GENERIC_FIX : rule.fix;
|
|
49
|
+
const reason = (say.endsWith(fix) ? say.slice(0, -fix.length) : say).trim().replace(/\.$/, '');
|
|
50
|
+
return { say, reason, fix, raw: text };
|
|
51
|
+
}
|
package/src/primitives.js
CHANGED
|
@@ -31,6 +31,7 @@ import { Gate } from 'bareguard';
|
|
|
31
31
|
import { primitiveFor, loadCatalogue } from './catalogue.js';
|
|
32
32
|
import { readDocxText } from './docx.js';
|
|
33
33
|
import { parseCsv } from './csv.js';
|
|
34
|
+
import { makeCtxTools } from './ctx-tools.js';
|
|
34
35
|
|
|
35
36
|
// bare-agent >=0.47.0: `noFollowSymlinks: true` makes shell_read/write/edit/
|
|
36
37
|
// grep throw `err.code === 'ELOOP'` when the path's FINAL component is a
|
|
@@ -80,7 +81,8 @@ async function resolveAndGate(gate, verb, tool, runDir, rawPath) {
|
|
|
80
81
|
}
|
|
81
82
|
const joined = (rawPath.startsWith('~') || path.isAbsolute(rawPath)) ? rawPath : path.join(runDir, rawPath);
|
|
82
83
|
const resolved = resolveToolPath(joined);
|
|
83
|
-
|
|
84
|
+
// `edit` is judged as bareguard's own 'edit' action type: the SAME fs.writeScope fence as `write` (M7 item 3)
|
|
85
|
+
const type = verb === 'write' || verb === 'edit' ? verb : 'read';
|
|
84
86
|
const decision = await gate.check({ type, tool, path: resolved });
|
|
85
87
|
if (decision.outcome !== 'allow') {
|
|
86
88
|
throw new GateRefusal(verb, resolved, decision.rule);
|
|
@@ -214,6 +216,20 @@ function sandboxedWriteTool(gate, runDir, outDir) {
|
|
|
214
216
|
};
|
|
215
217
|
}
|
|
216
218
|
|
|
219
|
+
function sandboxedEditTool(gate, runDir) {
|
|
220
|
+
const real = shellTool('shell_edit');
|
|
221
|
+
return {
|
|
222
|
+
name: 'edit',
|
|
223
|
+
description: `${real.description} Sandboxed exactly like write: only files under <runDir>/out can be edited; `
|
|
224
|
+
+ 'the run records and the frozen inputs are never editable.',
|
|
225
|
+
parameters: real.parameters,
|
|
226
|
+
execute: async (args) => {
|
|
227
|
+
const resolvedPath = await resolveAndGate(gate, 'edit', 'edit', runDir, args?.path);
|
|
228
|
+
return real.execute({ ...args, path: resolvedPath });
|
|
229
|
+
},
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
217
233
|
/** `readDocx`/`addressCells` take a `role` naming one of the run's frozen
|
|
218
234
|
* inputs (never a raw path — the model is never handed a filesystem path
|
|
219
235
|
* to type back, so there is nothing to sandbox-check on the way in). */
|
|
@@ -259,7 +275,11 @@ function addressCellsPrimitiveTool(inputsByRole) {
|
|
|
259
275
|
* catalogue-present-but-unwired verb, e.g. litectx's `compress`, must
|
|
260
276
|
* refuse before any model call or spend) imports this SAME set rather than
|
|
261
277
|
* keeping a second copy of the list. */
|
|
262
|
-
|
|
278
|
+
/** M7: the in-run tools over this run's own store (src/ctx-tools.js). `remember`/`forget` are
|
|
279
|
+
* deliberately absent: memory lasts one run (PRD: no learning between flows). */
|
|
280
|
+
const CTX_VERBS = Object.freeze(['recall', 'get', 'recent', 'related', 'impact', 'compress', 'peek', 'stash']);
|
|
281
|
+
|
|
282
|
+
export const WIRED_VERBS = new Set(['read', 'grep', 'write', 'edit', 'readDocx', 'addressCells', ...CTX_VERBS]);
|
|
263
283
|
|
|
264
284
|
/** The wired menu, one place: the catalogue entries whose verb is in
|
|
265
285
|
* WIRED_VERBS (and, when `skills` is given, in a signed skill). Absence,
|
|
@@ -308,6 +328,13 @@ export function resolvePrimitives(catalogue, grantedVerbs, ctx) {
|
|
|
308
328
|
|
|
309
329
|
const tools = {};
|
|
310
330
|
const reds = [];
|
|
331
|
+
// Built on demand, once: nothing is opened or created here (the store is opened per call, inside a tool).
|
|
332
|
+
// A path a tool names goes through the SAME read gate as `read` before litectx sees it.
|
|
333
|
+
let ctxTools;
|
|
334
|
+
const ctxTool = (verb) => {
|
|
335
|
+
ctxTools ??= makeCtxTools({ runDir, gatePath: (v, rawPath) => resolveAndGate(gate, v, v, runDir, rawPath) });
|
|
336
|
+
return ctxTools[verb];
|
|
337
|
+
};
|
|
311
338
|
|
|
312
339
|
for (const verb of grantedVerbs ?? []) {
|
|
313
340
|
const entry = primitiveFor(catalogue, verb);
|
|
@@ -338,6 +365,9 @@ export function resolvePrimitives(catalogue, grantedVerbs, ctx) {
|
|
|
338
365
|
// even for a run `runFlow` goes on to refuse.
|
|
339
366
|
tools.write = sandboxedWriteTool(gate, runDir, outDir);
|
|
340
367
|
break;
|
|
368
|
+
case 'edit':
|
|
369
|
+
tools.edit = sandboxedEditTool(gate, runDir);
|
|
370
|
+
break;
|
|
341
371
|
case 'readDocx':
|
|
342
372
|
tools.readDocx = readDocxPrimitiveTool(inputsByRole);
|
|
343
373
|
break;
|
|
@@ -345,7 +375,8 @@ export function resolvePrimitives(catalogue, grantedVerbs, ctx) {
|
|
|
345
375
|
tools.addressCells = addressCellsPrimitiveTool(inputsByRole);
|
|
346
376
|
break;
|
|
347
377
|
default:
|
|
348
|
-
|
|
378
|
+
if (CTX_VERBS.includes(verb)) tools[verb] = ctxTool(verb);
|
|
379
|
+
else reds.push(`primitives: verb "${verb}" is in the catalogue but has no M2 implementation yet`);
|
|
349
380
|
}
|
|
350
381
|
}
|
|
351
382
|
|