fwdloop 0.27.0 → 0.29.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 +54 -13
- package/package.json +3 -3
- package/src/ask.js +1 -1
- package/src/audit-fold.js +9 -1
- package/src/authoring.js +22 -5
- package/src/canrun.js +19 -16
- package/src/checked.js +5 -2
- package/src/checkpick.js +257 -0
- package/src/checkwords.js +24 -0
- package/src/closers.js +8 -1
- package/src/config.js +18 -0
- package/src/declaration.js +85 -5
- package/src/drafter.js +143 -47
- package/src/flow.js +2 -1
- package/src/launcher.js +4 -2
- package/src/learn.js +1 -1
- package/src/learnstore.js +8 -7
- package/src/mcp-checks.js +50 -0
- package/src/mcp-pick.js +33 -0
- package/src/mcp-sources.js +84 -0
- package/src/mcp-use.js +54 -0
- package/src/memo.js +120 -0
- package/src/model-step.js +89 -17
- package/src/natural.js +23 -0
- package/src/pageask.js +9 -6
- package/src/pagedropwords.js +9 -0
- package/src/panel/author.js +50 -28
- package/src/panel/authorcard.js +86 -2
- package/src/panel/authorflows.js +18 -14
- package/src/panel/authortrigger.js +241 -84
- package/src/panel/data.js +99 -11
- package/src/panel/index.html +683 -210
- package/src/panel/jobgrid.js +127 -0
- package/src/panel/result.js +28 -7
- package/src/panel/scheduler.js +8 -2
- package/src/panel/server.js +17 -7
- package/src/panel/settings.js +119 -4
- package/src/panel/tickets.js +12 -7
- package/src/pickrecord.js +146 -0
- package/src/plain-checks.js +1 -0
- package/src/primitives.js +34 -5
- package/src/provider.js +4 -1
- package/src/runfile.js +4 -2
- package/src/runner.js +170 -45
- package/src/send.js +71 -4
- package/src/setup.js +13 -1
- package/src/summary-words.js +15 -3
- package/src/ticket-draft.js +40 -42
- package/src/ticket-labels.js +10 -0
- package/src/ticket-mcp.js +33 -10
- package/src/ticket-next.js +33 -0
- package/src/ticket-shape.js +9 -0
- package/src/trigger-clock.js +4 -4
- package/src/trigger-files.js +3 -3
- package/src/trigger-tickets.js +41 -12
- package/types/ask.d.ts +2 -1
- package/types/audit-fold.d.ts +13 -2
- package/types/authoring.d.ts +10 -2
- package/types/canrun.d.ts +5 -12
- package/types/checked.d.ts +7 -2
- package/types/checkpick.d.ts +149 -0
- package/types/checkwords.d.ts +14 -0
- package/types/closers.d.ts +2 -1
- package/types/config.d.ts +6 -0
- package/types/declaration.d.ts +17 -0
- package/types/drafter.d.ts +446 -50
- package/types/learn.d.ts +1 -0
- package/types/learnstore.d.ts +2 -3
- package/types/mcp-checks.d.ts +8 -0
- package/types/mcp-pick.d.ts +23 -0
- package/types/mcp-sources.d.ts +51 -0
- package/types/mcp-use.d.ts +12 -0
- package/types/memo.d.ts +15 -0
- package/types/model-step.d.ts +5 -0
- package/types/natural.d.ts +2 -0
- package/types/pageask.d.ts +9 -2
- package/types/pagedropwords.d.ts +1 -0
- package/types/panel/author.d.ts +37 -1
- package/types/panel/authorcard.d.ts +52 -0
- package/types/panel/authorflows.d.ts +9 -1
- package/types/panel/authortrigger.d.ts +73 -7
- package/types/panel/data.d.ts +56 -2
- package/types/panel/jobgrid.d.ts +109 -0
- package/types/panel/result.d.ts +9 -3
- package/types/panel/server.d.ts +5 -1
- package/types/panel/settings.d.ts +3 -2
- package/types/panel/tickets.d.ts +26 -4
- package/types/pickrecord.d.ts +88 -0
- package/types/primitives.d.ts +15 -2
- package/types/runfile.d.ts +7 -2
- package/types/runner.d.ts +128 -77
- package/types/send.d.ts +10 -2
- package/types/setup.d.ts +1 -56
- package/types/summary-words.d.ts +22 -3
- package/types/ticket-draft.d.ts +40 -32
- package/types/ticket-labels.d.ts +6 -0
- package/types/ticket-mcp.d.ts +18 -1
- package/types/ticket-next.d.ts +23 -0
- package/types/ticket-shape.d.ts +5 -0
- package/types/trigger-clock.d.ts +4 -3
- package/types/trigger-files.d.ts +1 -1
- package/types/trigger-tickets.d.ts +18 -4
- package/src/attemptdiff.js +0 -118
- package/types/attemptdiff.d.ts +0 -38
package/src/checkpick.js
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
// M10 amendment 16 (docs/wiki/the-module-ladder.md "M10 amendment 16"): shape guardrails are settled the way item 3-4 settle a source's words.
|
|
2
|
+
// One AI call suggests, per guardrail, ONE check from bareguard's own list (`rubricVocabulary`) or none; CODE keeps a suggestion only if its rule is on
|
|
3
|
+
// the list, every number is one the guardrail names and every word is a word of the guardrail; the person picks (src/drafter.js asks, src/panel/author.js
|
|
4
|
+
// takes the answer); the plan carries only the checks picked. The drafter writes no check of its own.
|
|
5
|
+
// The prompt, the per-rule answer form and the keep-or-drop are the ones F144c proved (docs/logs/FINDINGS.md F144c).
|
|
6
|
+
// Throws away: a suggestion's `id`, `field`, `strict`, `text` (code sets them, or they never decide); every guardrail that code scopes out; what the model says in words.
|
|
7
|
+
import { rubricVocabulary } from 'bareguard';
|
|
8
|
+
import { lineRules } from './pagebits.js';
|
|
9
|
+
import { isCellsPath } from './closers.js';
|
|
10
|
+
import { plainWords, OFFERED } from './checkwords.js';
|
|
11
|
+
|
|
12
|
+
export { plainWords, OFFERED };
|
|
13
|
+
import { guardrailWordNumbers, guardrailStandaloneNumbers, guardrailWordsPerSection, guardrailSectionCount } from './declaration.js';
|
|
14
|
+
|
|
15
|
+
/** the one tool the suggestion call is forced to use */
|
|
16
|
+
export const SUGGEST_TOOL = 'suggest_checks';
|
|
17
|
+
const VOCAB = /** @type {Record<string, {description: string, fields: Record<string, {type: string, required?: boolean}>}>} */ (rubricVocabulary.rules);
|
|
18
|
+
/** fields code sets, or that never decide: never offered, never kept */
|
|
19
|
+
const IGNORED = new Set(['id', 'field', 'text', 'strict']);
|
|
20
|
+
const NUM_FIELDS = ['value', 'size', 'wordsPerSection'];
|
|
21
|
+
const WORD_FIELDS = ['names', 'phrases'];
|
|
22
|
+
|
|
23
|
+
// ---- scope, decided by CODE before the call ------------------------------------------------------------------------------------------------
|
|
24
|
+
/** @param {any[]|undefined} sources the job's signed inputs @returns {boolean} a CSV file or a web page routes its guardrails to another signed part (M10 items 1-3, M12) */
|
|
25
|
+
export const hasRoutingInput = (sources) => (sources ?? []).some((s) => (s.kind === 'file' && isCellsPath(s.path)) || s.kind === 'page');
|
|
26
|
+
/**
|
|
27
|
+
* A guardrail goes to this call unless the job signs an input that routes its guardrails elsewhere AND the guardrail names no whole-output word number
|
|
28
|
+
* (the one thing the shape reader still takes in such a job). A page job whose guardrail carries a word number therefore counts as in (F144b caveat).
|
|
29
|
+
* @param {any[]|undefined} sources @param {string} g @returns {'in'|'out'}
|
|
30
|
+
*/
|
|
31
|
+
export const codeScope = (sources, g) => (hasRoutingInput(sources) && guardrailWordNumbers(g).length === 0 ? 'out' : 'in');
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Every guardrail rule on a step line (not a signed ask or send line) that this call settles, in line order. `rule` is the rule's number on its line (the one
|
|
35
|
+
* number `leftRules`, `ruleNo` and the answers use); a repeated text on a line is one rule here, asked once.
|
|
36
|
+
* @param {{n: number, guardrail?: string}[]} lines `parseSignedText`'s lines @param {{asks?: {line: number}[], sends?: {line: number}[], sources?: any[]}} arbiter
|
|
37
|
+
* @returns {{line: number, rule: number, text: string}[]}
|
|
38
|
+
*/
|
|
39
|
+
export function scopedRules(lines, arbiter) {
|
|
40
|
+
const skip = new Set([...(arbiter?.asks ?? []), ...(arbiter?.sends ?? [])].map((x) => x.line));
|
|
41
|
+
/** @type {{line: number, rule: number, text: string}[]} */
|
|
42
|
+
const out = [];
|
|
43
|
+
for (const l of Array.isArray(lines) ? lines : []) {
|
|
44
|
+
if (skip.has(l.n)) continue;
|
|
45
|
+
const seen = new Set();
|
|
46
|
+
lineRules({ rule: l.guardrail }).forEach((text, i) => {
|
|
47
|
+
const key = text.trim().toLowerCase();
|
|
48
|
+
if (seen.has(key) || codeScope(arbiter?.sources, text) !== 'in') return;
|
|
49
|
+
seen.add(key);
|
|
50
|
+
out.push({ line: l.n, rule: i + 1, text });
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// ---- code's keep-or-drop (am16 (2)) --------------------------------------------------------------------------------------------------------
|
|
57
|
+
const norm = (/** @type {unknown} */ t) => String(t).toLowerCase().replace(/\s+/g, ' ').trim();
|
|
58
|
+
const tokens = (/** @type {unknown} */ t) => new Set(norm(t).match(/[\p{L}\p{N}]+/gu) ?? []);
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Keep a suggestion only if its rule is on bareguard's list, it carries only that rule's own fields, every number in it is a number the guardrail names and
|
|
62
|
+
* every word in it is a word of the guardrail. Anything else is dropped, with the reason. `none` is a drop with the reason `none`.
|
|
63
|
+
* @param {string} guardrail @param {any} sug the model's entry for this guardrail
|
|
64
|
+
* @returns {{kept: true, check: Record<string, any>}|{kept: false, why: string}}
|
|
65
|
+
*/
|
|
66
|
+
export function keepOrDrop(guardrail, sug) {
|
|
67
|
+
if (sug == null || typeof sug !== 'object') return { kept: false, why: 'unreadable suggestion' };
|
|
68
|
+
const { rule } = sug;
|
|
69
|
+
if (rule === 'none' || rule === undefined || rule === null) return { kept: false, why: 'none' };
|
|
70
|
+
if (typeof rule !== 'string' || !Object.hasOwn(VOCAB, rule)) return { kept: false, why: `rule "${rule}" is not on bareguard's list` };
|
|
71
|
+
if (!OFFERED.includes(rule)) return { kept: false, why: `rule "${rule}" is on bareguard's list but is not offered here` };
|
|
72
|
+
const own = Object.keys(VOCAB[rule].fields).filter((k) => !IGNORED.has(k));
|
|
73
|
+
for (const k of own) if (VOCAB[rule].fields[k].required && sug[k] == null) return { kept: false, why: `${rule} needs ${k}` };
|
|
74
|
+
const allowed = new Set([...own, 'rule', 'line', 'guardrail']);
|
|
75
|
+
for (const k of Object.keys(sug)) if (sug[k] != null && !allowed.has(k)) return { kept: false, why: `${rule} does not take ${k}` };
|
|
76
|
+
/** @type {Record<string, any>} */
|
|
77
|
+
const check = { rule };
|
|
78
|
+
for (const k of own) {
|
|
79
|
+
const v = sug[k];
|
|
80
|
+
if (v == null) continue;
|
|
81
|
+
if (NUM_FIELDS.includes(k)) {
|
|
82
|
+
if (!Number.isInteger(v) || v < 1) return { kept: false, why: `${k} ${JSON.stringify(v)} is not a whole number >= 1` };
|
|
83
|
+
const named = rule === 'maxWords' || rule === 'minWords' ? guardrailWordNumbers(guardrail)
|
|
84
|
+
: k === 'wordsPerSection' ? [guardrailWordsPerSection(guardrail)].filter((x) => x !== null)
|
|
85
|
+
: guardrailStandaloneNumbers(guardrail);
|
|
86
|
+
if (!named.includes(v)) return { kept: false, why: `${k} ${v} is not a number the guardrail names (${named.join(', ') || 'it names none'})` };
|
|
87
|
+
check[k] = v;
|
|
88
|
+
} else if (WORD_FIELDS.includes(k)) {
|
|
89
|
+
if (!Array.isArray(v) || v.length === 0 || v.some((s) => typeof s !== 'string' || s.trim() === '')) return { kept: false, why: `${k} is not a list of words` };
|
|
90
|
+
const gTok = tokens(guardrail);
|
|
91
|
+
const gNorm = norm(guardrail);
|
|
92
|
+
for (const s of v) {
|
|
93
|
+
if (!gNorm.includes(norm(s))) return { kept: false, why: `${k} "${s}" is not in the guardrail's words` };
|
|
94
|
+
for (const t of tokens(s)) if (!gTok.has(t)) return { kept: false, why: `${k} word "${t}" is not a word of the guardrail` };
|
|
95
|
+
}
|
|
96
|
+
check[k] = v;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (rule === 'sections' || rule === 'sectionOrder' || rule === 'sectionWords') {
|
|
100
|
+
const want = guardrailSectionCount(guardrail);
|
|
101
|
+
if (want !== null && check.names.length !== want) return { kept: false, why: `the guardrail says ${want} sections; the check has ${check.names.length}` };
|
|
102
|
+
}
|
|
103
|
+
return { kept: true, check };
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// ---- the call: prompt, answer form -------------------------------------------------------------------------------------------------------
|
|
107
|
+
const vocabBlock = OFFERED.map((r) => `- ${VOCAB[r].description}`).join('\n');
|
|
108
|
+
export const SUGGEST_SYSTEM = `You help a person turn the guardrails written under the lines of a job into mechanical checks.
|
|
109
|
+
You are given the job's lines. Under a line, its guardrails are numbered g1, g2, ... You are also given the checks the checker can run.
|
|
110
|
+
|
|
111
|
+
For EACH guardrail, call ${SUGGEST_TOOL} with one entry: the one check from the list that checks exactly what that guardrail says, or the rule "none".
|
|
112
|
+
|
|
113
|
+
Rules:
|
|
114
|
+
- Use only a rule from the list below, with only the fields that rule takes. Do not set id, field, strict or text: code sets them.
|
|
115
|
+
- Use only numbers the guardrail itself states, and only words the guardrail itself contains. Never add a section name, phrase or number the guardrail does not state.
|
|
116
|
+
- Suggest \`sections\` or \`sectionWords\` only when the guardrail itself names the sections.
|
|
117
|
+
- A guardrail like 'all under N words' or 'under N words' is about the whole answer: use maxWords N.
|
|
118
|
+
- If no check on the list checks exactly what the guardrail says (it is about content, sources, prices, columns, or a count the list cannot check exactly), answer "none". A check that is weaker than, or different from, the guardrail is worse than "none".
|
|
119
|
+
- Answer for every guardrail once, using the line number and the guardrail number shown.
|
|
120
|
+
|
|
121
|
+
Checks the checker can run (rule({ fields })):
|
|
122
|
+
${vocabBlock}`;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The user message: the job's lines, and under a line only the guardrails this call settles, numbered by their rule number on the line.
|
|
126
|
+
* @param {{n: number, text: string}[]} lines @param {{line: number, rule: number, text: string}[]} scoped @returns {string}
|
|
127
|
+
*/
|
|
128
|
+
export function suggestUserText(lines, scoped) {
|
|
129
|
+
const out = ['The job:'];
|
|
130
|
+
for (const l of lines) {
|
|
131
|
+
out.push(`${l.n}. ${l.text}`);
|
|
132
|
+
for (const s of scoped) if (s.line === l.n) out.push(` g${s.rule}: ${s.text}`);
|
|
133
|
+
}
|
|
134
|
+
return out.join('\n');
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const JSON_TYPE = { integer: { type: 'integer', minimum: 1 }, 'string-list': { type: 'array', minItems: 1, items: { type: 'string' } } };
|
|
138
|
+
/** @param {string} rule @returns {object} one variant of the answer form: exactly that rule's own fields, nothing else */
|
|
139
|
+
function variant(rule) {
|
|
140
|
+
/** @type {Record<string, any>} */
|
|
141
|
+
const properties = { line: { type: 'integer', description: 'the job line number' }, guardrail: { type: 'integer', description: 'the guardrail number under that line (g1 = 1)' }, rule: { const: rule } };
|
|
142
|
+
const required = ['line', 'guardrail', 'rule'];
|
|
143
|
+
if (rule !== 'none') {
|
|
144
|
+
for (const [k, f] of Object.entries(VOCAB[rule].fields)) {
|
|
145
|
+
if (IGNORED.has(k)) continue;
|
|
146
|
+
properties[k] = /** @type {Record<string, any>} */ (JSON_TYPE)[f.type];
|
|
147
|
+
if (f.required) required.push(k);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return { type: 'object', properties, required, additionalProperties: false };
|
|
151
|
+
}
|
|
152
|
+
/** the forced tool's parameter schema: one `anyOf` variant per offered rule, plus `none` */
|
|
153
|
+
export const SUGGEST_SCHEMA = Object.freeze({
|
|
154
|
+
type: 'object',
|
|
155
|
+
properties: { checks: { type: 'array', description: 'One entry per guardrail.', items: { anyOf: [...OFFERED, 'none'].map(variant) } } },
|
|
156
|
+
required: ['checks'],
|
|
157
|
+
additionalProperties: false,
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* What the call's answer comes to, one row per scoped guardrail: the check kept (or null) and why it was dropped. A guardrail the answer never mentions is
|
|
162
|
+
* dropped as `no entry`; an entry for a guardrail that was not sent is ignored.
|
|
163
|
+
* @param {{line: number, rule: number, text: string}[]} scoped @param {any} args the tool call's arguments
|
|
164
|
+
* @returns {{line: number, rule: number, text: string, check: Record<string, any>|null, why: string|null}[]}
|
|
165
|
+
*/
|
|
166
|
+
export function rowsFromAnswer(scoped, args) {
|
|
167
|
+
const entries = Array.isArray(args?.checks) ? args.checks : [];
|
|
168
|
+
return scoped.map((s) => {
|
|
169
|
+
const e = entries.find((/** @type {any} */ x) => x?.line === s.line && x?.guardrail === s.rule);
|
|
170
|
+
const res = e === undefined ? /** @type {ReturnType<typeof keepOrDrop>} */ ({ kept: false, why: 'no entry' }) : keepOrDrop(s.text, e);
|
|
171
|
+
return { ...s, check: res.kept ? res.check : null, why: res.kept ? null : res.why };
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// ---- the asks (words are item 4's) -----------------------------------------------------------------------------------------------------
|
|
176
|
+
/** the can't-check ask, as the signed words say it */
|
|
177
|
+
export const CANT_CHECK_WORDS = "I can't check this. Your own words, or Not checked?";
|
|
178
|
+
/** how every answer is told, once (am2 item 2's words) */
|
|
179
|
+
const HOW_TO_ANSWER = (/** @type {number} */ line, /** @type {boolean} */ agree) => `${agree ? 'Answer "agree" to use it, or type your own words' : 'Type your own words'} (your answer is added as a new ~ rule on line ${line}), or answer "drop it" to leave it Not checked.`;
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* The asks for the rows: `Line n, guardrail "<…>": I propose <check in plain words>.` for a kept check, `Line n, guardrail "<…>": I can't check this. Your own words, or
|
|
183
|
+
* Not checked?` when nothing was kept. A proposal is not counted toward am1's cap; a can't-check ask is (am16 (5)).
|
|
184
|
+
* @param {ReturnType<typeof rowsFromAnswer>} rows
|
|
185
|
+
* @returns {{pairRule?: number, line: number, rule: number, source: 'look', ask: 'check'|'no-check', ruleText: string, question: string, reading?: string, check?: Record<string, any>, counted: boolean}[]}
|
|
186
|
+
*/
|
|
187
|
+
export function checkAsks(rows) {
|
|
188
|
+
return rows.map((r) => {
|
|
189
|
+
const pair = typeof (/** @type {any} */ (r).pairRule) === 'number' ? { pairRule: /** @type {any} */ (r).pairRule } : {}; // M10 am21: the asked line is an edited added line
|
|
190
|
+
if (r.check === null) {
|
|
191
|
+
return { ...pair, line: r.line, rule: r.rule, source: 'look', ask: 'no-check', ruleText: r.text, counted: true, question: `Line ${r.line}, guardrail "${r.text}": ${CANT_CHECK_WORDS} ${HOW_TO_ANSWER(r.line, false)}` };
|
|
192
|
+
}
|
|
193
|
+
const words = plainWords(/** @type {any} */ (r.check));
|
|
194
|
+
return { ...pair, line: r.line, rule: r.rule, source: 'look', ask: 'check', ruleText: r.text, counted: false, reading: words, check: r.check, question: `Line ${r.line}, guardrail "${r.text}": I propose ${words}. ${HOW_TO_ANSWER(r.line, true)}` };
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// ---- the plan uses only the checks you picked (am16 (4)) -------------------------------------------------------------------------------------
|
|
199
|
+
/**
|
|
200
|
+
* @typedef {{line: number, rule: number, check: Record<string, any>|null, added?: string, own?: boolean}} Pick
|
|
201
|
+
* `check` = the check the person agreed to (null for their own words); `added` = the `~` rule the answer wrote on the line; `own` = their own words
|
|
202
|
+
*/
|
|
203
|
+
/**
|
|
204
|
+
* Settle every scoped rule against the person's answers: a rule with a picked check is checked; the `~` line an agree wrote is covered by that pick; every other
|
|
205
|
+
* rule is Not checked, with the reason (`person-left` = they chose it, `own-words` = they gave their own words, `no-pick` = nothing was picked).
|
|
206
|
+
* @param {ReturnType<typeof scopedRules>} rules @param {Pick[]} picks @param {{line: number, rule: number}[]} left
|
|
207
|
+
* @returns {{checks: Map<number, Record<string, any>[]>, notes: {line: number, rule: number, text: string, reason: 'person-left'|'own-words'|'no-pick'}[]}}
|
|
208
|
+
*/
|
|
209
|
+
export function settleRules(rules, picks, left) {
|
|
210
|
+
/** @type {Map<number, Record<string, any>[]>} */
|
|
211
|
+
const checks = new Map();
|
|
212
|
+
/** @type {{line: number, rule: number, text: string, reason: 'person-left'|'own-words'|'no-pick'}[]} */
|
|
213
|
+
const notes = [];
|
|
214
|
+
const sameText = (/** @type {string|undefined} */ a, /** @type {string} */ b) => typeof a === 'string' && norm(a) === norm(b);
|
|
215
|
+
for (const r of rules) {
|
|
216
|
+
const own = picks.find((p) => p.line === r.line && p.rule === r.rule);
|
|
217
|
+
if (own?.check) { checks.set(r.line, [...(checks.get(r.line) ?? []), own.check]); continue; }
|
|
218
|
+
if (picks.some((p) => p.check && p.line === r.line && sameText(p.added, r.text))) continue;
|
|
219
|
+
if (left.some((l) => l.line === r.line && l.rule === r.rule)) notes.push({ ...r, reason: 'person-left' });
|
|
220
|
+
else if (own?.own || picks.some((p) => !p.check && p.own && p.line === r.line && sameText(p.added, r.text))) notes.push({ ...r, reason: 'own-words' });
|
|
221
|
+
else notes.push({ ...r, reason: 'no-pick' });
|
|
222
|
+
}
|
|
223
|
+
return { checks, notes };
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Overwrite the drafter's check on every step of a line this call settles (a green step, which another signed part settles, is left alone): a line with picked checks
|
|
228
|
+
* is softgreen and carries exactly those checks; a line with none is hitl. Whatever `close.shape` the drafter wrote is gone. Pure: returns a new declaration.
|
|
229
|
+
* @param {any} declaration @param {ReturnType<typeof scopedRules>} rules @param {ReturnType<typeof settleRules>} settled
|
|
230
|
+
* @param {(note: {line: number, reason: 'person-left'|'own-words'|'no-pick'}) => string} sentence the one table's words for a reason
|
|
231
|
+
*/
|
|
232
|
+
export function applyPicks(declaration, rules, settled, sentence) {
|
|
233
|
+
if (!declaration || !Array.isArray(declaration.steps)) return declaration;
|
|
234
|
+
const lineSet = new Set(rules.map((r) => r.line));
|
|
235
|
+
const green = (/** @type {number} */ n) => declaration.steps.some((/** @type {any} */ st) => st?.fromLine === n && st?.close?.class === 'green');
|
|
236
|
+
const mine = (/** @type {number} */ n) => lineSet.has(n) && !green(n);
|
|
237
|
+
const steps = declaration.steps.map((/** @type {any} */ st) => {
|
|
238
|
+
if (!st || typeof st !== 'object' || !mine(st.fromLine)) return st;
|
|
239
|
+
const picked = settled.checks.get(st.fromLine) ?? [];
|
|
240
|
+
return { ...st, close: picked.length ? { class: 'softgreen', shape: { picked } } : { class: 'hitl' } };
|
|
241
|
+
});
|
|
242
|
+
const out = { ...declaration, steps };
|
|
243
|
+
const isRec = (/** @type {unknown} */ v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
244
|
+
if (isRec(declaration.guardrailClasses)) {
|
|
245
|
+
out.guardrailClasses = { ...declaration.guardrailClasses };
|
|
246
|
+
const un = isRec(declaration.unjudgeable) ? { ...declaration.unjudgeable } : {};
|
|
247
|
+
for (const n of lineSet) {
|
|
248
|
+
if (!mine(n) || !declaration.steps.some((/** @type {any} */ st) => st?.fromLine === n)) continue;
|
|
249
|
+
const has = (settled.checks.get(n) ?? []).length > 0;
|
|
250
|
+
out.guardrailClasses[String(n)] = has ? 'softgreen' : 'hitl';
|
|
251
|
+
if (has) delete un[String(n)];
|
|
252
|
+
else un[String(n)] = [...new Set(settled.notes.filter((x) => x.line === n).map(sentence))].join(' ') || 'No check was picked for it, so you judge it at the Ask.';
|
|
253
|
+
}
|
|
254
|
+
if (isRec(declaration.unjudgeable) || Object.keys(un).length) out.unjudgeable = un;
|
|
255
|
+
}
|
|
256
|
+
return out;
|
|
257
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// M10 amendment 16: the ONE place a picked check is put in plain words (one fixed phrase per bareguard rule, written by code). The ask, the `~` line an agree writes,
|
|
2
|
+
// the plan card (src/checked.js), the softgreen close's check list (src/closers.js) and the Audit all read it; nothing else writes these words.
|
|
3
|
+
/** the rules of bareguard's list a person may pick here (text rules only: the ones a plain answer can be judged by) */
|
|
4
|
+
export const OFFERED = Object.freeze(['nonEmpty', 'maxWords', 'minWords', 'maxLines', 'listItems', 'sections', 'sectionOrder', 'sectionWords', 'mustCarry', 'blockLines']);
|
|
5
|
+
const listOf = (/** @type {string[]} */ xs) => xs.join(', ');
|
|
6
|
+
/**
|
|
7
|
+
* The check in plain words, one fixed phrase per rule: the ask, the `~` line an agree writes, the plan card and the Audit all read this one function.
|
|
8
|
+
* @param {{rule: string, value?: number, size?: number, wordsPerSection?: number, names?: string[], phrases?: string[]}} c @returns {string}
|
|
9
|
+
*/
|
|
10
|
+
export function plainWords(c) {
|
|
11
|
+
switch (c.rule) {
|
|
12
|
+
case 'nonEmpty': return 'the answer is not empty';
|
|
13
|
+
case 'maxWords': return `at most ${c.value} words`;
|
|
14
|
+
case 'minWords': return `at least ${c.value} words`;
|
|
15
|
+
case 'maxLines': return `at most ${c.value} lines`;
|
|
16
|
+
case 'listItems': return `exactly ${c.value} list items`;
|
|
17
|
+
case 'sections': return `sections named ${listOf(c.names ?? [])}`;
|
|
18
|
+
case 'sectionOrder': return `sections named ${listOf(c.names ?? [])}, in that order`;
|
|
19
|
+
case 'sectionWords': return `sections named ${listOf(c.names ?? [])}, each about ${c.wordsPerSection} words`;
|
|
20
|
+
case 'mustCarry': return `the answer carries ${listOf(c.phrases ?? [])}`;
|
|
21
|
+
case 'blockLines': return `blocks of ${c.size} lines, each carrying ${listOf(c.phrases ?? [])}`;
|
|
22
|
+
default: return `a ${c.rule} check`;
|
|
23
|
+
}
|
|
24
|
+
}
|
package/src/closers.js
CHANGED
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
// signed text).
|
|
45
45
|
|
|
46
46
|
import { createRubric, checkStep } from 'bareguard';
|
|
47
|
+
import { plainWords } from './checkwords.js';
|
|
47
48
|
import { checkCited } from './citedcheck.js';
|
|
48
49
|
import { closeSheet } from './sheetrun.js';
|
|
49
50
|
|
|
@@ -105,6 +106,8 @@ export function softgreenSpec(shape) {
|
|
|
105
106
|
if (shape.linesPerInvoice !== undefined || shape.mustCarry !== undefined) {
|
|
106
107
|
checks.push({ id: 'lines', rule: 'blockLines', field: 'text', size: shape.linesPerInvoice, phrases: shape.mustCarry });
|
|
107
108
|
}
|
|
109
|
+
// M10 am16: each check the person picked is one more bareguard rule on the answer's text, id `pick<k>`; code set it from the person's pick, the drafter never writes one
|
|
110
|
+
if (Array.isArray(shape.picked)) shape.picked.forEach((c, k) => checks.push({ id: `pick${k + 1}`, field: 'text', ...c }));
|
|
108
111
|
return { schema: 1, goal: 'softgreen', checkpoints: { close: { gating: true, checks } } };
|
|
109
112
|
}
|
|
110
113
|
|
|
@@ -123,7 +126,7 @@ const partAfter = (item) => item.slice(item.indexOf(':') + 1);
|
|
|
123
126
|
* A gap it has no sentence for is still a red, worded generically, never dropped.
|
|
124
127
|
*
|
|
125
128
|
* @param {any[]} gaps
|
|
126
|
-
* @param {{ linesPerInvoice?: number, mustCarry?: string[] }} shape
|
|
129
|
+
* @param {{ linesPerInvoice?: number, mustCarry?: string[], picked?: any[] }} shape
|
|
127
130
|
* @returns {{ red: string, reds: string[] }}
|
|
128
131
|
*/
|
|
129
132
|
export function renderSoftgreenGaps(gaps, shape) {
|
|
@@ -165,6 +168,9 @@ export function renderSoftgreenGaps(gaps, shape) {
|
|
|
165
168
|
// bareguard lists (block, word) misses and bounds the list; the tail counts the missing words it left out (amendment 20)
|
|
166
169
|
const moreWords = (g.itemsTotal ?? 0) - (g.items?.length ?? 0);
|
|
167
170
|
if (moreWords > 0) reds.push(`${moreWords} more missing word(s)`);
|
|
171
|
+
} else if (/^pick\d+$/.test(String(g.id)) && shape.picked?.[Number(String(g.id).slice(4)) - 1]) {
|
|
172
|
+
// M10 am16: a check the person picked is told in the words it was picked in, with the count bareguard measured when it gives one
|
|
173
|
+
reds.push(`not met: ${plainWords(shape.picked[Number(String(g.id).slice(4)) - 1])}${typeof g.measured === 'number' ? ` (found ${g.measured})` : ''}`);
|
|
168
174
|
} else {
|
|
169
175
|
reds.push(`the ${g.check} check failed (${g.kind ?? 'no detail'})`);
|
|
170
176
|
}
|
|
@@ -179,6 +185,7 @@ function softgreenCheckText(c) {
|
|
|
179
185
|
if (c.id === 'words') return `at most ${c.value} words`;
|
|
180
186
|
if (c.id === 'sections') return `the sections are there, in order: ${c.names.join(', ')}`;
|
|
181
187
|
if (c.id === 'perSection') return `each section is about ${c.wordsPerSection} words`;
|
|
188
|
+
if (/^pick\d+$/.test(c.id)) return plainWords(/** @type {any} */ (c));
|
|
182
189
|
return `${c.size ?? 'its'} lines per block, each carrying: ${(c.phrases ?? []).join(', ')}`;
|
|
183
190
|
}
|
|
184
191
|
|
package/src/config.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
// "prices": { "<slot>": { "inPerM": n, "cachedInPerM": n, "outPerM": n } }, // USD per 1M tokens, each optional; a saved "cachedInPerM" is tolerated, never read (M4d amendment 2)
|
|
7
7
|
// "providers": { "<KEY_NAME>": { "shape": "<shape id>", "baseUrl": "http(s)://…", "legacyMaxTokens": true|false } }, // each optional; a row is a key name from the keys file (M4d amendment 6). An older file's "model" is tolerated and read by nothing.
|
|
8
8
|
// "models": { "<KEY_NAME>": [ { "model": "<id>", "use": true|false, "inPerM": n, "outPerM": n } ] }, // M4d amendment 3 C: a price per model
|
|
9
|
+
// "mcpPaths": ["<path to an MCP config file>", …], // M13 piece 3: the paths added on Settings > MCP, in order (absolute or ~/…); the page's only writer is POST /api/settings/mcp-path
|
|
9
10
|
// "learningHints": true|false } // M8 am1: absent = false; the drafter is handed earlier runs' notes only when true (src/learnstore.js learningHintsOn). No control on the Settings page.
|
|
10
11
|
// A models line's price is a PAIR or nothing (`modelsProblem` is the one rule): 0 / 0 typed is a chosen price, a
|
|
11
12
|
// ticked line needs both, a half pair is refused. A slot with no list is migrated on READ (`effectiveModels` in
|
|
@@ -129,6 +130,18 @@ export function providerFieldProblem(field, v) {
|
|
|
129
130
|
* // borrowed-from: bareloop src/config.js@v0.48.0 (ed3a110) */
|
|
130
131
|
export const cleanBaseUrl = (v) => v.replace(/(?<!\/)\/+$/, '');
|
|
131
132
|
|
|
133
|
+
/**
|
|
134
|
+
* M13 piece 3: why a typed MCP config path cannot be kept in `mcpPaths`, or null: one rule for the Settings route and for the config reader.
|
|
135
|
+
* Absolute or `~/…`, one line of at most 500 characters.
|
|
136
|
+
* @param {unknown} p
|
|
137
|
+
*/
|
|
138
|
+
export function mcpPathProblem(p) {
|
|
139
|
+
if (typeof p !== 'string' || p.trim() === '') return 'must be a path to an MCP config file';
|
|
140
|
+
if (p.length > 500 || /[\0\r\n]/.test(p)) return 'must be one line of at most 500 characters';
|
|
141
|
+
if (!(p.startsWith('/') || p.startsWith('~/'))) return 'must start with / or ~/';
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
|
|
132
145
|
const isPrice = (v) => typeof v === 'number' && Number.isFinite(v) && v > 0;
|
|
133
146
|
|
|
134
147
|
/**
|
|
@@ -198,6 +211,11 @@ function validateDoc(doc) {
|
|
|
198
211
|
if (doc.learningHints !== undefined && typeof doc.learningHints !== 'boolean') {
|
|
199
212
|
throw new ConfigError('learningHints must be true or false');
|
|
200
213
|
}
|
|
214
|
+
if (doc.mcpPaths !== undefined) {
|
|
215
|
+
if (!Array.isArray(doc.mcpPaths)) throw new ConfigError('mcpPaths must be a list of paths');
|
|
216
|
+
doc.mcpPaths.forEach((p, i) => { const why = mcpPathProblem(p); if (why) throw new ConfigError(`mcpPaths.${i} ${why}`); });
|
|
217
|
+
if (new Set(doc.mcpPaths).size !== doc.mcpPaths.length) throw new ConfigError('mcpPaths holds a path twice');
|
|
218
|
+
}
|
|
201
219
|
validateProviders(doc.providers);
|
|
202
220
|
validateModels(doc.models);
|
|
203
221
|
if (doc.prices === undefined) return;
|
package/src/declaration.js
CHANGED
|
@@ -42,6 +42,7 @@ import { factPartReds } from './citedcheck.js';
|
|
|
42
42
|
import { numberRuleReds, countReds, citedWordReds } from './citedwords.js';
|
|
43
43
|
import { SHEET_RULES, MAX_SHEET_CHECKS, sheetCheckColumns, sheetCheckReds, sheetCheckWordReds, sheetNoClaimReds, sheetCoversReds } from './sheetchecks.js';
|
|
44
44
|
import { lineRules } from './pagebits.js';
|
|
45
|
+
import { OFFERED as OFFERED_RULES } from './checkwords.js';
|
|
45
46
|
import { isColumnChoiceRule } from './sheetoffer.js';
|
|
46
47
|
|
|
47
48
|
/** @typedef {import('./types.js').Arbiter} Arbiter */
|
|
@@ -60,6 +61,7 @@ export const DECLARATION_FIELDS = Object.freeze([
|
|
|
60
61
|
'refused',
|
|
61
62
|
'inputFacts',
|
|
62
63
|
'mcp',
|
|
64
|
+
'flowType',
|
|
63
65
|
'ticketFilter',
|
|
64
66
|
'ticketWatch',
|
|
65
67
|
// step level
|
|
@@ -87,10 +89,38 @@ const VALID_CLASSES = Object.freeze(['green', 'softgreen', 'hitl']);
|
|
|
87
89
|
// an ask's position, an ask's TTL, the egress allow-list...").
|
|
88
90
|
const ARBITER_KEYS = Object.freeze(['cap', 'ask', 'ttl', 'send', 'source', 'trigger', 'skills']);
|
|
89
91
|
|
|
90
|
-
const TOP_LEVEL_ALLOWED = Object.freeze(['steps', 'guardrailClasses', 'unjudgeable', 'refused', 'inputFacts', 'mcp', 'ticketFilter', 'ticketWatch']);
|
|
92
|
+
const TOP_LEVEL_ALLOWED = Object.freeze(['steps', 'guardrailClasses', 'unjudgeable', 'refused', 'inputFacts', 'mcp', 'flowType', 'ticketFilter', 'ticketWatch']);
|
|
91
93
|
const STEP_ALLOWED = Object.freeze(['goal', 'primitives', 'reads', 'emits', 'fromLine', 'close', 'picks', 'mcpTools']);
|
|
92
94
|
const CLOSE_ALLOWED = Object.freeze(['class', 'shape', 'cited', 'columns', 'sheet']);
|
|
93
95
|
|
|
96
|
+
/** M13 piece 4 (signed item 4): the job's flow type, set by code from the job card, signed with the job. */
|
|
97
|
+
export const FLOW_TYPES = Object.freeze(['plain', 'mcp', 'tickets']);
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* M13 piece 4: the ONE reader of a job's flow type. The field when present; a job signed before it existed (M12 shape: an `mcp` block, no `flowType`) is a Tickets
|
|
101
|
+
* job, since M12 only had ticket jobs; no `mcp` block is plain.
|
|
102
|
+
* @param {Record<string, any>} declaration @returns {'plain'|'mcp'|'tickets'}
|
|
103
|
+
*/
|
|
104
|
+
export function flowTypeOf(declaration) {
|
|
105
|
+
if (typeof declaration?.flowType === 'string' && FLOW_TYPES.includes(declaration.flowType)) return /** @type {any} */ (declaration.flowType);
|
|
106
|
+
return declaration?.mcp ? 'tickets' : 'plain';
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** M13 piece 4: `flowType` (optional on a job signed before M13) must be one of the three, and agree with the `mcp` block.
|
|
110
|
+
* @param {Record<string, any>} declaration @param {string[]} reds */
|
|
111
|
+
function checkFlowType(declaration, reds) {
|
|
112
|
+
if (!Object.hasOwn(declaration, 'flowType')) return;
|
|
113
|
+
const t = declaration.flowType;
|
|
114
|
+
if (typeof t !== 'string' || !FLOW_TYPES.includes(t)) { reds.push('declaration: flowType must be plain, mcp or tickets'); return; }
|
|
115
|
+
const hasMcp = Object.hasOwn(declaration, 'mcp');
|
|
116
|
+
if (t === 'plain' && hasMcp) reds.push('declaration: flowType "plain" takes no "mcp" server');
|
|
117
|
+
if (t !== 'plain' && !hasMcp) reds.push(`declaration: flowType "${t}" needs an "mcp" server`);
|
|
118
|
+
if (t !== 'tickets') {
|
|
119
|
+
if (Object.hasOwn(declaration, 'ticketFilter')) reds.push('declaration: "ticketFilter" belongs to a Tickets MCP job');
|
|
120
|
+
if (Object.hasOwn(declaration, 'ticketWatch')) reds.push('declaration: "ticketWatch" belongs to a Tickets MCP job');
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
94
124
|
/** M12 piece 1a: the ONE shape of an MCP server or tool name in a job (the bridge names a tool `<server>_<tool>`). */
|
|
95
125
|
const MCP_NAME = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
|
|
96
126
|
|
|
@@ -188,9 +218,14 @@ function checkOwnKeys(obj, allowed, path, reds) {
|
|
|
188
218
|
export const SHAPE_KEYS = Object.freeze(['maxWords', 'sections', 'linesPerInvoice', 'mustCarry']);
|
|
189
219
|
|
|
190
220
|
/** Shape keys only the MACHINE sets (M4e amendment 15): read from the line's guardrail, never offered to the drafter's model. */
|
|
191
|
-
export const MACHINE_SHAPE_KEYS = Object.freeze(['wordsPerSection']);
|
|
221
|
+
export const MACHINE_SHAPE_KEYS = Object.freeze(['wordsPerSection', 'picked']);
|
|
192
222
|
|
|
193
223
|
const SHAPE_TYPE_CHECKS = Object.freeze({
|
|
224
|
+
// M10 am16: the checks the person picked, set by code (src/checkpick.js applyPicks), each one a bareguard rule with only that rule's own fields
|
|
225
|
+
picked: {
|
|
226
|
+
expected: 'a non-empty array of checks, each an object with a text rule of bareguard\'s list',
|
|
227
|
+
check: (v) => Array.isArray(v) && v.length > 0 && v.every((c) => isPlainObject(c) && typeof c.rule === 'string' && OFFERED_RULES.includes(c.rule)),
|
|
228
|
+
},
|
|
194
229
|
wordsPerSection: {
|
|
195
230
|
expected: 'a positive integer',
|
|
196
231
|
check: (v) => Number.isInteger(v) && v > 0,
|
|
@@ -348,6 +383,25 @@ export function guardrailWordNumbers(guardrail) {
|
|
|
348
383
|
return [...guardrail.matchAll(/(?<![\d,])(\d{1,3}(?:,\d{3})+|\d+)\s*words?\b(?!\s*(?:each|per\s+section)\b)/gi)].map((m) => readNumber(m[1]));
|
|
349
384
|
}
|
|
350
385
|
|
|
386
|
+
/** M10 amendment 14 item 2: every standalone number in a guardrail's own text (digits not joined to letters: "P1" and "250ish" are not one; "1,000" and "2.5" are one number each). */
|
|
387
|
+
export function guardrailStandaloneNumbers(guardrail) {
|
|
388
|
+
if (typeof guardrail !== 'string') return [];
|
|
389
|
+
return [...guardrail.matchAll(/(?<![A-Za-z0-9_.,])(\d{1,3}(?:,\d{3})+|\d+(?:\.\d+)?)(?![A-Za-z0-9_])/g)].map((m) => Number(m[1].replace(/,/g, '')));
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/** M10 amendment 14 item 1: the send line (a signed send) is where the accepted result is written out and no AI runs, so a guardrail under it is refused at $0, naming the line.
|
|
393
|
+
* Pure; the card (src/panel/authorcard.js checkCard) and the drafter's pre-flight both call it. @param {any[]} lines `parseSignedText`'s lines @param {{sends?: {line: number}[]}} arbiter */
|
|
394
|
+
export function checkSendLineGuardrail(lines, arbiter) {
|
|
395
|
+
const reds = [];
|
|
396
|
+
for (const s of Array.isArray(arbiter?.sends) ? arbiter.sends : []) {
|
|
397
|
+
const l = (Array.isArray(lines) ? lines : []).find((x) => x?.n === s.line);
|
|
398
|
+
if (l && typeof l.guardrail === 'string' && l.guardrail.trim() !== '') {
|
|
399
|
+
reds.push(`line ${s.line} is the send line (it writes out what you accepted at the Ask before it, and no AI runs there), so it cannot carry the guardrail "${l.guardrail.trim()}". Put the guardrail on the line that makes the result.`);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
return reds;
|
|
403
|
+
}
|
|
404
|
+
|
|
351
405
|
/** M4e amendment 15 item 1: the "<n> words each" / "<n> words per section" size in a guardrail ("about 250 words each", "250ish each" -> 250), or null. */
|
|
352
406
|
export function guardrailWordsPerSection(guardrail) {
|
|
353
407
|
const m = typeof guardrail === 'string' ? /(?<![\d,])(\d{1,3}(?:,\d{3})+|\d+)(?:\s*words?|ish(?:\s+words?)?)\s+(?:each|per\s+section)\b/i.exec(guardrail) : null;
|
|
@@ -435,7 +489,8 @@ export function checkShapeFitsJobLine(step, i, lines, reds) {
|
|
|
435
489
|
const wantPer = guardrailWordsPerSection(line?.guardrail);
|
|
436
490
|
if (shape.wordsPerSection !== undefined && shape.wordsPerSection !== wantPer) {
|
|
437
491
|
reds.push(`declaration: ${label} the check has wordsPerSection ${shape.wordsPerSection}; the guardrail says ${wantPer === null ? 'no size for each section' : `${wantPer} words each`} — change the guardrail on the card to change it`);
|
|
438
|
-
} else if (shape.wordsPerSection === undefined && wantPer !== null) {
|
|
492
|
+
} else if (shape.wordsPerSection === undefined && wantPer !== null && !Array.isArray(shape.picked)) {
|
|
493
|
+
// (a shape of picked checks, M10 am16, was kept by code and chosen by the person: the guardrail's size is a check only if it was picked)
|
|
439
494
|
reds.push(`declaration: ${label} the guardrail says ${wantPer} words each; the check has no wordsPerSection`);
|
|
440
495
|
}
|
|
441
496
|
// M4e amendment 16 C13: a size for each section needs the section names to be checked against.
|
|
@@ -596,6 +651,15 @@ function checkSheetKey(step, label, c, reds) {
|
|
|
596
651
|
for (const r of sheetCheckReds(list, step.fromLine, tables)) reds.push(r);
|
|
597
652
|
}
|
|
598
653
|
|
|
654
|
+
/** M10 am19: the tools that serve an input's kind (src/primitives.js rolePrimitiveFor): a page or ticket is frozen as text. */
|
|
655
|
+
function inputReachVerbs(source) {
|
|
656
|
+
if (source?.kind === 'page') return ['read', 'grep'];
|
|
657
|
+
const p = String(source?.path ?? '').toLowerCase();
|
|
658
|
+
if (p.endsWith('.docx')) return ['readDocx'];
|
|
659
|
+
if (isCellsPath(source?.path)) return ['addressCells'];
|
|
660
|
+
return ['read', 'grep'];
|
|
661
|
+
}
|
|
662
|
+
|
|
599
663
|
/**
|
|
600
664
|
* Validate a drafter declaration against the M1 closed schema. `arbiter`
|
|
601
665
|
* and `lines` are `parseSignedText`'s output; `catalogue` is a plain array
|
|
@@ -769,6 +833,7 @@ export function validateDeclaration(declaration, context = {}) {
|
|
|
769
833
|
}
|
|
770
834
|
|
|
771
835
|
// --- M12 piece 1a: the job's MCP tools (optional) -------------------------------
|
|
836
|
+
checkFlowType(declaration, reds);
|
|
772
837
|
const mcpTools = checkMcp(declaration, reds);
|
|
773
838
|
checkTicketFilter(declaration, reds);
|
|
774
839
|
checkTicketWatch(declaration, reds);
|
|
@@ -860,7 +925,9 @@ export function validateDeclaration(declaration, context = {}) {
|
|
|
860
925
|
if (cellsRoles.includes(readId) && !declaredEmits.has(readId)) continue; // an input with cells, frozen at run start (M4d amendment 8)
|
|
861
926
|
if (pageRoles.includes(readId) && !declaredEmits.has(readId)) continue; // a web page, frozen at run start (M10 am7 item 3)
|
|
862
927
|
if (docRoles.includes(readId) && !declaredEmits.has(readId) && step.close?.cited?.source === readId) continue; // a document the step quotes (M10 piece 5)
|
|
863
|
-
if (readId
|
|
928
|
+
if (docRoles.includes(readId) && !declaredEmits.has(readId)) {
|
|
929
|
+
reds.push(`declaration: ${label} reads document input "${readId}" — leave it out of reads and grant "read" ("readDocx" for .docx); only a step that quotes it lists it`);
|
|
930
|
+
} else if (readId === emits || !declaredEmits.has(readId)) {
|
|
864
931
|
reds.push(`declaration: ${label} reads artifact "${readId}" that no earlier step declared`);
|
|
865
932
|
}
|
|
866
933
|
}
|
|
@@ -1017,7 +1084,7 @@ export function validateDeclaration(declaration, context = {}) {
|
|
|
1017
1084
|
stepInfo.forEach((st, i) => {
|
|
1018
1085
|
const isSignedAskLine = st.fromLine !== null && signedAskLines.has(st.fromLine);
|
|
1019
1086
|
if (st.primitives.length === 0 && st.effectiveClass === 'hitl' && !isSignedAskLine) {
|
|
1020
|
-
reds.push(`declaration: steps[${i}] (line ${st.fromLine}) is a pause (no primitives, hitl) at an unsigned line`);
|
|
1087
|
+
reds.push(`declaration: steps[${i}] (line ${st.fromLine}) is a pause (no primitives, hitl) at an unsigned line: grant it "read" (or the verb it needs), or make the line an Ask`);
|
|
1021
1088
|
}
|
|
1022
1089
|
});
|
|
1023
1090
|
|
|
@@ -1132,6 +1199,19 @@ export function validateDeclaration(declaration, context = {}) {
|
|
|
1132
1199
|
}
|
|
1133
1200
|
}
|
|
1134
1201
|
|
|
1202
|
+
// --- check 7 (M10 am19): every input must be reachable by a model step (not an ask step, not the send step).
|
|
1203
|
+
// Ruling A, hamr 2026-11-04: md/txt/page/ticket -> read or grep; docx -> readDocx; a sheet -> addressCells; or the role in the step's `reads`.
|
|
1204
|
+
// `picks` / `inputFacts` name headings only and are not a grant. Plan-fit check: draft, revise and sign turn `fitJobLine` on; signed flows keep running.
|
|
1205
|
+
if (fitJobLine === true) {
|
|
1206
|
+
const modelSteps = stepInfo.filter((st) => st.fromLine === null || (!askLines.includes(st.fromLine) && !sendLines.includes(st.fromLine)));
|
|
1207
|
+
for (const s of Array.isArray(safeArbiter.sources) ? safeArbiter.sources : []) {
|
|
1208
|
+
const verbs = inputReachVerbs(s);
|
|
1209
|
+
if (!modelSteps.some((st) => st.reads.includes(s.role) || st.primitives.some((v) => verbs.includes(v)))) {
|
|
1210
|
+
reds.push(`Input "${s.role}" is read by no step.`);
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1135
1215
|
if (reds.length > 0) return deepFreeze({ ok: false, reds });
|
|
1136
1216
|
|
|
1137
1217
|
const classes = {};
|