bareloop 0.54.1 → 0.56.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/CHANGELOG.md +122 -0
- package/bareloop.context.md +67 -6
- package/package.json +3 -3
- package/src/authorflow.js +217 -238
- package/src/authoring.js +22 -6
- package/src/authorjob.js +138 -30
- package/src/authorreadout.js +15 -4
- package/src/authorrun.js +13 -4
- package/src/authorscout.js +9 -6
- package/src/behaviour.js +14 -0
- package/src/blockasks.js +43 -0
- package/src/cardschedule.js +42 -0
- package/src/checkblock.js +772 -0
- package/src/checklist.js +128 -0
- package/src/checkpick.js +294 -0
- package/src/checksuggest.js +28 -0
- package/src/checkwords.js +27 -0
- package/src/cli.js +1 -1
- package/src/config.js +24 -1
- package/src/declaredclose.js +30 -1
- package/src/destpoint.js +151 -0
- package/src/draftspend.js +85 -0
- package/src/facts.js +8 -1
- package/src/factwords.js +14 -1
- package/src/fitcheck.js +5 -3
- package/src/job.js +81 -1
- package/src/jobblock.js +9 -0
- package/src/labelscan.js +11 -0
- package/src/launcher.js +3 -2
- package/src/mcpchecks.js +52 -0
- package/src/mcppick.js +36 -0
- package/src/mcpsources.js +77 -0
- package/src/mcpuse.js +97 -0
- package/src/natural.js +23 -0
- package/src/pagemap.js +20 -5
- package/src/panel/authorroutes.js +105 -18
- package/src/panel/authorsession.js +293 -44
- package/src/panel/index.html +873 -41
- package/src/panel/jobgrid.js +117 -0
- package/src/panel/jobplan.js +103 -35
- package/src/panel/scheduler.js +80 -13
- package/src/panel/schedules.js +189 -28
- package/src/panel/schedulestart.js +44 -13
- package/src/panel/server.js +471 -39
- package/src/panel/settingsroutes.js +133 -3
- package/src/panel/status.js +19 -1
- package/src/panel/tickets.js +44 -0
- package/src/pickrecord.js +163 -0
- package/src/placerule.js +355 -0
- package/src/plan.js +31 -2
- package/src/planrun.js +71 -15
- package/src/prcheckout.js +259 -0
- package/src/promptregisters.js +11 -0
- package/src/questionbox.js +112 -0
- package/src/readshim.js +3 -2
- package/src/revises.js +56 -0
- package/src/rowedit.js +115 -0
- package/src/rubricstep.js +265 -132
- package/src/run.js +19 -2
- package/src/runexport.js +2 -0
- package/src/runlist.js +3 -2
- package/src/schedulewords.js +46 -4
- package/src/source.js +81 -7
- package/src/stepmcp.js +86 -0
- package/src/ticket.js +113 -0
- package/src/ticketfilter.js +76 -0
- package/src/ticketlabels.js +79 -0
- package/src/ticketmcp.js +111 -0
- package/src/ticketnext.js +35 -0
- package/src/ticketrepo.js +98 -0
- package/src/ticketschedule.js +32 -0
- package/src/ticketshape.js +45 -0
- package/src/tools.js +9 -0
- package/src/trigger.js +14 -2
- package/src/triggerclock.js +7 -3
- package/src/triggerfiles.js +19 -11
- package/src/triggertickets.js +244 -0
- package/src/userrun.js +191 -10
- package/src/validate.js +3 -1
- package/src/worktree.js +43 -1
- package/types/authorflow.d.ts +86 -93
- package/types/authorjob.d.ts +35 -4
- package/types/authorreadout.d.ts +4 -3
- package/types/authorscout.d.ts +4 -2
- package/types/behaviour.d.ts +12 -0
- package/types/blockasks.d.ts +37 -0
- package/types/cardschedule.d.ts +24 -0
- package/types/checkblock.d.ts +361 -0
- package/types/checklist.d.ts +134 -0
- package/types/checkpick.d.ts +160 -0
- package/types/checksuggest.d.ts +30 -0
- package/types/checkwords.d.ts +14 -0
- package/types/config.d.ts +7 -0
- package/types/declaredclose.d.ts +4 -0
- package/types/destpoint.d.ts +89 -0
- package/types/draftspend.d.ts +37 -0
- package/types/factwords.d.ts +7 -0
- package/types/fitcheck.d.ts +7 -1
- package/types/job.d.ts +13 -0
- package/types/jobblock.d.ts +9 -0
- package/types/labelscan.d.ts +7 -0
- package/types/launcher.d.ts +2 -2
- package/types/mcpchecks.d.ts +8 -0
- package/types/mcppick.d.ts +33 -0
- package/types/mcpsources.d.ts +51 -0
- package/types/mcpuse.d.ts +15 -0
- package/types/natural.d.ts +2 -0
- package/types/pagemap.d.ts +6 -1
- package/types/panel/authorroutes.d.ts +11 -2
- package/types/panel/authorsession.d.ts +69 -3
- package/types/panel/jobgrid.d.ts +405 -0
- package/types/panel/jobplan.d.ts +55 -11
- package/types/panel/scheduler.d.ts +7 -2
- package/types/panel/schedules.d.ts +124 -4
- package/types/panel/schedulestart.d.ts +21 -3
- package/types/panel/server.d.ts +432 -10
- package/types/panel/settingsroutes.d.ts +4 -2
- package/types/panel/status.d.ts +16 -2
- package/types/panel/tickets.d.ts +61 -0
- package/types/pickrecord.d.ts +100 -0
- package/types/placerule.d.ts +194 -0
- package/types/plan.d.ts +1 -0
- package/types/prcheckout.d.ts +151 -0
- package/types/questionbox.d.ts +87 -0
- package/types/readshim.d.ts +4 -3
- package/types/revises.d.ts +23 -0
- package/types/rowedit.d.ts +32 -0
- package/types/rubricstep.d.ts +100 -48
- package/types/run.d.ts +27 -1
- package/types/runlist.d.ts +6 -3
- package/types/schedulewords.d.ts +29 -2
- package/types/source.d.ts +40 -4
- package/types/stepmcp.d.ts +40 -0
- package/types/ticket.d.ts +114 -0
- package/types/ticketfilter.d.ts +34 -0
- package/types/ticketlabels.d.ts +44 -0
- package/types/ticketmcp.d.ts +84 -0
- package/types/ticketnext.d.ts +33 -0
- package/types/ticketrepo.d.ts +118 -0
- package/types/ticketschedule.d.ts +21 -0
- package/types/ticketshape.d.ts +37 -0
- package/types/tools.d.ts +1 -0
- package/types/trigger.d.ts +9 -1
- package/types/triggerclock.d.ts +6 -2
- package/types/triggerfiles.d.ts +13 -5
- package/types/triggertickets.d.ts +110 -0
- package/types/userrun.d.ts +50 -0
- package/types/validate.d.ts +1 -0
- package/types/worktree.d.ts +19 -0
package/src/checklist.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// THE ROW VOCABULARY of a rubric job's one check list, and the call that suggests extra `!` checks. The list itself is the CheckBlock (src/checkblock.js): every check the job can have is a row there.
|
|
2
|
+
// `~` rows the person's own rules (by: you; a settled pick builds the rule's check)
|
|
3
|
+
// `!` rows checks the agent suggests once, only from what it sees in the inputs (by: agent): the look's kept facts that carry no `~` rule, plus the call's own
|
|
4
|
+
// proposals (count, phrase). Code proves a word-bearing `!` row against the input text, else drops it with a reason. A `~` always wins over a `!` on the same thing.
|
|
5
|
+
// `$` rows default checks code adds itself (by: default): every claim quotes the input (a text line with one input), the numbers tie (a text line after a fact line);
|
|
6
|
+
// the mechanical floor (file exists, text not empty) is shown as a `$` row but is never counted as a check.
|
|
7
|
+
// Nothing here decides a verdict; the list says what the drafter may build, and code builds the rest.
|
|
8
|
+
import { askStructured, makeCostBook } from './authorflow.js';
|
|
9
|
+
import { lineRules } from './rubricstep.js';
|
|
10
|
+
|
|
11
|
+
/** at most this many `!` checks come from the call */
|
|
12
|
+
export const MAX_BANG = 3;
|
|
13
|
+
/** the reason a check on a version or a date goes under Not checked: it is true only for the input as it is today */
|
|
14
|
+
export const WEEK_ONLY_WORDS = 'It names a version or a date from the input, true only for the input as it is today, so you judge it at Accept.';
|
|
15
|
+
/** the label of the list call, as the drafting book and the draft log see it */
|
|
16
|
+
export const LEDGER_LABEL = 'ledger-suggest';
|
|
17
|
+
export const LEDGER_TOOL = 'suggest_extra_checks';
|
|
18
|
+
/** how much of each input the call is shown */
|
|
19
|
+
const SHOWN_CHARS = 8000;
|
|
20
|
+
/** the reason the empty list is logged with */
|
|
21
|
+
export const EMPTY_LIST_WORDS = 'empty list: nothing to check';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* A check that needs exact words from the input is true only while the input stays as it is when those words hold a VERSION-like token (1.2 or 1.2.3, not after a currency sign or before
|
|
25
|
+
* a percent) or a DATE-like token (2026-11-04, 04/11/2026, "Nov 4, 2026", "4 November 2026", "November 2026"). Code refuses it; a `~` rule is the person's own and is never refused by this.
|
|
26
|
+
* @param {unknown} t @returns {boolean}
|
|
27
|
+
*/
|
|
28
|
+
export function weekOnly(t) {
|
|
29
|
+
return weekTokens(t).length > 0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The version-like and date-like tokens a text holds (the very tokens {@link weekOnly} reads), each once. Pure.
|
|
34
|
+
* @param {unknown} t @returns {string[]}
|
|
35
|
+
*/
|
|
36
|
+
export function weekTokens(t) {
|
|
37
|
+
const s = String(t ?? '');
|
|
38
|
+
const M = '(?:jan(?:uary)?|feb(?:ruary)?|mar(?:ch)?|apr(?:il)?|may|jun(?:e)?|jul(?:y)?|aug(?:ust)?|sep(?:t(?:ember)?)?|oct(?:ober)?|nov(?:ember)?|dec(?:ember)?)';
|
|
39
|
+
const res = [/(?<![\d.$€£])\d+\.\d+(?:\.\d+)*(?![\d.]*%)/g, /\b\d{4}-\d{2}-\d{2}\b/g, /\b\d{1,2}[/.]\d{1,2}[/.]\d{2,4}\b/g,
|
|
40
|
+
new RegExp(`\\b${M}\\.? \\d{1,2}(?:st|nd|rd|th)?(?:,? \\d{4})?\\b`, 'gi'), new RegExp(`\\b\\d{1,2}(?:st|nd|rd|th)? ${M}\\.?(?: \\d{4})?\\b`, 'gi'), new RegExp(`\\b${M}\\.? \\d{4}\\b`, 'gi')];
|
|
41
|
+
return [...new Set(res.flatMap((re) => [...s.matchAll(re)].map((m) => m[0])))];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @typedef {{key: string, line: number, kind: 'rule'|'fact'|'cited'|'count'|'phrase'|'numbers'|'floor', from: 'rule'|'pick'|'look'|'agent'|'default', by: 'you'|'agent'|'default',
|
|
46
|
+
* words: string[], text?: string, rule?: number, part?: {line: number, part: number}, source?: string, name?: string, min?: number, max?: number, pick?: string, after?: number[],
|
|
47
|
+
* state: 'listed'|'built'|'not-checked'|'dropped', reason: string|null, forRule?: number, reading?: import('./pagerules.js').Reading}} Row
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
/** an empty list (no row that stands but the floor) is said so, never left as no record at all @param {Row[]} rows @returns {boolean} */
|
|
51
|
+
export const isEmptyList = (rows) => !rows.some((r) => r.kind !== 'floor' && r.state !== 'dropped');
|
|
52
|
+
|
|
53
|
+
/** the record the draft log keeps, one object per row (key, line, rowKind, from, by, words, state, reason), plus ONE explicit record when nothing stands @param {Row[]} rows */
|
|
54
|
+
export const ledgerRecord = (rows) => [
|
|
55
|
+
...rows.map((r) => ({ key: r.key, line: r.line, rowKind: r.kind, from: r.from, by: r.by, words: r.kind === 'rule' ? [r.text ?? ''] : r.words, state: r.state, reason: r.reason })),
|
|
56
|
+
...(isEmptyList(rows) ? [{ key: 'empty', line: 0, rowKind: 'empty', from: 'default', by: 'default', words: [], state: 'empty', reason: EMPTY_LIST_WORDS }] : []),
|
|
57
|
+
];
|
|
58
|
+
|
|
59
|
+
// ---- the one paid call ---------------------------------------------------------------------------------------------------------------------
|
|
60
|
+
/** the list call's own system text (model-facing; used only by the list call of a rubric job with input text) */
|
|
61
|
+
export const LEDGER_SYSTEM = `You look at the inputs of a job and name checks the inputs themselves support, beyond the guardrails the person wrote.
|
|
62
|
+
Call ${LEDGER_TOOL} once with up to ${MAX_BANG} entries, or with an empty list.
|
|
63
|
+
- kind "count": how many results the input shows or the job asks for (min and/or max, whole numbers).
|
|
64
|
+
- kind "phrase": fixed words copied verbatim from an input (phrase, and source = that input's label).
|
|
65
|
+
Use only what you can see in the inputs. Do not repeat a guardrail the person wrote. If the inputs support none, send an empty list.`;
|
|
66
|
+
|
|
67
|
+
export const LEDGER_SCHEMA = Object.freeze({
|
|
68
|
+
type: 'object',
|
|
69
|
+
properties: {
|
|
70
|
+
extra: {
|
|
71
|
+
type: 'array', maxItems: MAX_BANG,
|
|
72
|
+
items: {
|
|
73
|
+
type: 'object',
|
|
74
|
+
properties: {
|
|
75
|
+
line: { type: 'integer', minimum: 1, description: 'the job line number' },
|
|
76
|
+
kind: { enum: ['count', 'phrase'] },
|
|
77
|
+
source: { type: 'string', description: 'the label of the input' },
|
|
78
|
+
phrase: { type: 'string', description: 'phrase only: words copied verbatim from the input' },
|
|
79
|
+
min: { type: 'integer', minimum: 1 },
|
|
80
|
+
max: { type: 'integer', minimum: 1 },
|
|
81
|
+
},
|
|
82
|
+
required: ['line', 'kind'],
|
|
83
|
+
additionalProperties: false,
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
required: ['extra'],
|
|
88
|
+
additionalProperties: false,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const ledgerChannel = () => ({
|
|
92
|
+
name: LEDGER_TOOL,
|
|
93
|
+
instruction: `Your reply did not deliver exactly one ${LEDGER_TOOL} call. Call ${LEDGER_TOOL} exactly once. Do not write the answer as text.`,
|
|
94
|
+
textPath: 'extra',
|
|
95
|
+
tool: (/** @type {{calls: any[]}} */ box) => ({
|
|
96
|
+
name: LEDGER_TOOL,
|
|
97
|
+
description: 'Deliver the extra checks the inputs support (or an empty list). Call this exactly once.',
|
|
98
|
+
parameters: LEDGER_SCHEMA,
|
|
99
|
+
execute: async (/** @type {any} */ args) => { box.calls.push(args); return 'received'; },
|
|
100
|
+
}),
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
/** @param {{n: number, text: string, rules?: string[], rule?: string}[]} jobLines @param {Record<string, string>} texts @returns {string} */
|
|
104
|
+
export function ledgerUserText(jobLines, texts) {
|
|
105
|
+
const out = ['The job:'];
|
|
106
|
+
for (const l of jobLines) {
|
|
107
|
+
out.push(`${l.n}. ${l.text}`);
|
|
108
|
+
lineRules(l).forEach((r, i) => out.push(` g${i + 1}: ${r}`));
|
|
109
|
+
}
|
|
110
|
+
for (const [label, t] of Object.entries(texts)) out.push('', `Input "${label}":`, String(t).slice(0, SHOWN_CHARS));
|
|
111
|
+
return out.join('\n');
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* The one paid call; its spend is booked like the look's. An unusable answer is NOT a guessed list: it yields no `!` proposals and says why.
|
|
116
|
+
* @param {{jobLines: any[], texts: Record<string, string>, generate: Function, ceilingUsd?: number|null, onCall?: (c: any) => void, priorCalls?: any[], priorRaws?: any[]}} o
|
|
117
|
+
* @returns {Promise<{extra: any[], reason: string|null, calls: any[], raws: any[]}>}
|
|
118
|
+
*/
|
|
119
|
+
export async function runLedgerSuggest({ jobLines, texts, generate, ceilingUsd = null, onCall = () => {}, priorCalls = [], priorRaws = [] }) {
|
|
120
|
+
const book = makeCostBook({ ceilingUsd, onCall });
|
|
121
|
+
book.absorb(priorCalls, priorRaws);
|
|
122
|
+
const before = book.report().calls.length;
|
|
123
|
+
const beforeRaws = book.raws().length;
|
|
124
|
+
const r = await askStructured({ messages: [{ role: 'user', content: ledgerUserText(jobLines, texts) }], generate, mode: 'tool', retries: 1, label: LEDGER_LABEL, book, channel: ledgerChannel() });
|
|
125
|
+
const extra = r.artifact && Array.isArray(r.artifact.extra) ? r.artifact.extra : [];
|
|
126
|
+
const reason = r.artifact ? null : (r.budget ? 'the spend ceiling was reached' : (r.providerError ?? r.red?.detail ?? 'the answer could not be read'));
|
|
127
|
+
return { extra, reason, calls: book.report().calls.slice(before), raws: book.raws().slice(beforeRaws) };
|
|
128
|
+
}
|
package/src/checkpick.js
ADDED
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
// borrowed-from: fwdloop src/checkpick.js@v0.29.0 (scope, keepOrDrop, SUGGEST_SYSTEM/SUGGEST_SCHEMA, checkAsks, settleRules) and src/declaration.js@v0.29.0 (the guardrail* readers)
|
|
2
|
+
// R10 = fwdloop M10 amendment 16 ("shape guardrails are settled the way item 3-4 settle a source's words"). ONE AI call suggests, per `~` rule of a rubric job, ONE check
|
|
3
|
+
// from bareguard's own list (`rubricVocabulary`) or none; CODE keeps a suggestion only if its rule is on the list, it carries only that rule's own fields, every number
|
|
4
|
+
// is one the rule names and every word is a word of the rule; the person picks (agree / own words / drop it); the plan carries only the checks picked. The drafter writes
|
|
5
|
+
// no check of its own. The prompt, the per-rule answer form and the keep-or-drop are the ones fwd's F144c proved.
|
|
6
|
+
// Throws away: a suggestion's `id`, `field`, `strict`, `text` (code sets them, or they never decide); every rule that code scopes out; what the model says in words.
|
|
7
|
+
// bareloop differences from fwd (ruled 2026-11-09): rubric jobs only; the call runs over bareloop's own `askStructured` ladder (cost booked and the answer logged like every
|
|
8
|
+
// drafting call); a pick lands as a `countable` part of the line's rubric-step stage (src/rubricstep.js), carrying the `~` rule numbers it settles.
|
|
9
|
+
import { rubricVocabulary } from 'bareguard';
|
|
10
|
+
import { plainWords, OFFERED } from './checkwords.js';
|
|
11
|
+
import { KEPT_WORDS } from './pickrecord.js';
|
|
12
|
+
import { lineRules } from './rubricstep.js';
|
|
13
|
+
|
|
14
|
+
export { plainWords, OFFERED };
|
|
15
|
+
|
|
16
|
+
/** the one tool the suggestion call uses */
|
|
17
|
+
export const SUGGEST_TOOL = 'suggest_checks';
|
|
18
|
+
const VOCAB = /** @type {Record<string, {description: string, fields: Record<string, {type: string, required?: boolean}>}>} */ (rubricVocabulary.rules);
|
|
19
|
+
/** fields code sets, or that never decide: never offered, never kept */
|
|
20
|
+
const IGNORED = new Set(['id', 'field', 'text', 'strict']);
|
|
21
|
+
const NUM_FIELDS = ['value', 'size', 'wordsPerSection'];
|
|
22
|
+
const WORD_FIELDS = ['names', 'phrases'];
|
|
23
|
+
|
|
24
|
+
// ---- the guardrail readers (fwd src/declaration.js@v0.29.0) ------------------------------------------------------------------------------
|
|
25
|
+
const readNumber = (/** @type {string} */ t) => Number(t.replace(/,/g, ''));
|
|
26
|
+
/** every whole-output word number in a guardrail ("under 600 words" -> [600]); a "<n> words each" / "per section" size is never listed here @param {unknown} g @returns {number[]} */
|
|
27
|
+
export function guardrailWordNumbers(g) {
|
|
28
|
+
if (typeof g !== 'string') return [];
|
|
29
|
+
return [...g.matchAll(/(?<![\d,])(\d{1,3}(?:,\d{3})+|\d+)\s*words?\b(?!\s*(?:each|per\s+section)\b)/gi)].map((m) => readNumber(m[1]));
|
|
30
|
+
}
|
|
31
|
+
/** every standalone number in a guardrail's own text (digits not joined to letters) @param {unknown} g @returns {number[]} */
|
|
32
|
+
export function guardrailStandaloneNumbers(g) {
|
|
33
|
+
if (typeof g !== 'string') return [];
|
|
34
|
+
return [...g.matchAll(/(?<![A-Za-z0-9_.,])(\d{1,3}(?:,\d{3})+|\d+(?:\.\d+)?)(?![A-Za-z0-9_])/g)].map((m) => Number(m[1].replace(/,/g, '')));
|
|
35
|
+
}
|
|
36
|
+
/** the "<n> words each" / "<n> words per section" size, or null @param {unknown} g @returns {number|null} */
|
|
37
|
+
export function guardrailWordsPerSection(g) {
|
|
38
|
+
const m = typeof g === 'string' ? /(?<![\d,])(\d{1,3}(?:,\d{3})+|\d+)(?:\s*words?|ish(?:\s+words?)?)\s+(?:each|per\s+section)\b/i.exec(g) : null;
|
|
39
|
+
return m ? readNumber(m[1]) : null;
|
|
40
|
+
}
|
|
41
|
+
const NUMBER_WORDS = /** @type {Record<string, number>} */ ({ one: 1, two: 2, three: 3, four: 4, five: 5, six: 6, seven: 7, eight: 8, nine: 9, ten: 10 });
|
|
42
|
+
/** the first "<N> sections" in a guardrail (digits, or one..ten), or null @param {unknown} g @returns {number|null} */
|
|
43
|
+
export function guardrailSectionCount(g) {
|
|
44
|
+
const m = typeof g === 'string' ? /\b(\d+|one|two|three|four|five|six|seven|eight|nine|ten)\s+(?:\w+\s+)?sections?\b/i.exec(g) : null;
|
|
45
|
+
if (!m) return null;
|
|
46
|
+
return /^\d+$/.test(m[1]) ? Number(m[1]) : NUMBER_WORDS[m[1].toLowerCase()];
|
|
47
|
+
}
|
|
48
|
+
/** the first "<N> bullets / list items / items / lines / points" in a guardrail (digits, or one..ten), or null @param {unknown} g @returns {number|null} */
|
|
49
|
+
export function guardrailItemCount(g) {
|
|
50
|
+
const m = typeof g === 'string' ? /\b(\d+|one|two|three|four|five|six|seven|eight|nine|ten)\s+(?:\w+\s+)?(?:bullets?|bullet\s+points?|list\s+items?|items?|lines?|points?)\b/i.exec(g) : null;
|
|
51
|
+
if (!m) return null;
|
|
52
|
+
return /^\d+$/.test(m[1]) ? Number(m[1]) : NUMBER_WORDS[m[1].toLowerCase()];
|
|
53
|
+
}
|
|
54
|
+
/** a list-bound word the guardrail uses: the count it names, or the one it stands for ("more than 3" = at least 4, "fewer than 3" = at most 2) */
|
|
55
|
+
const MORE_THAN = /(?<!\b(?:no|not)\s)\bmore\s+than\s+(\d+)\b/i;
|
|
56
|
+
const FEWER_THAN = /(?<!\b(?:no|not)\s)\b(?:(?:fewer|less)\s+than|under|below)\s+(\d+)\b/i;
|
|
57
|
+
/** the direction of a list-items rule's wording: 'max', 'min' or null (exact / not said) @param {string} t @returns {'max'|'min'|null} */
|
|
58
|
+
function listDirection(t) {
|
|
59
|
+
if (/\b(at\s+most|up\s+to|no\s+more\s+than|not\s+more\s+than|max(?:imum)?(?:\s+of)?)\b/i.test(t) || FEWER_THAN.test(t)) return 'max';
|
|
60
|
+
if (/\b(at\s+least|min(?:imum)?(?:\s+of)?|no\s+fewer\s+than|not\s+fewer\s+than)\b/i.test(t) || MORE_THAN.test(t)) return 'min';
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
/** the numbers a rule may carry: the standalone numbers of the guardrail, plus N+1 for "more than N" (min) and N-1 for "fewer than N" (max) @param {string} rule @param {string} g @returns {number[]} */
|
|
64
|
+
function listBoundNumbers(rule, g) {
|
|
65
|
+
const named = guardrailStandaloneNumbers(g);
|
|
66
|
+
if (rule === 'minListItems') { const m = MORE_THAN.exec(g); if (m) named.push(Number(m[1]) + 1); }
|
|
67
|
+
if (rule === 'maxListItems') { const m = FEWER_THAN.exec(g); if (m) named.push(Number(m[1]) - 1); }
|
|
68
|
+
return named;
|
|
69
|
+
}
|
|
70
|
+
/** @param {unknown} g @returns {boolean} the rule is a COUNT bareguard checks (words, list items or lines, sections): code reads it, whatever the page look said about it */
|
|
71
|
+
export const isCountable = (g) => guardrailWordNumbers(g).length > 0 || guardrailItemCount(g) !== null || guardrailSectionCount(g) !== null;
|
|
72
|
+
|
|
73
|
+
// ---- scope, decided by CODE before the call ----------------------------------------------------------------------------------------------
|
|
74
|
+
/** @param {unknown} v @returns {boolean} the input is a web page (a URL), which routes its rules to the page words (facts) */
|
|
75
|
+
export const isUrlInput = (v) => /^https?:\/\//i.test(String(v ?? '').trim());
|
|
76
|
+
/** @param {{value?: string}[]|null|undefined} inputs @returns {boolean} the job signs an input that routes its rules to another signed part */
|
|
77
|
+
export const hasRoutingInput = (inputs) => (inputs ?? []).some((i) => isUrlInput(i?.value));
|
|
78
|
+
/**
|
|
79
|
+
* A rule goes to this call unless the job signs an input that routes its rules elsewhere (a web page) AND the rule names no whole-output word number (the one thing the
|
|
80
|
+
* shape reader still takes in such a job). fwd's F144b `codeScope`.
|
|
81
|
+
* @param {{value?: string}[]|null|undefined} inputs @param {string} g @returns {'in'|'out'}
|
|
82
|
+
*/
|
|
83
|
+
export const codeScope = (inputs, g) => (hasRoutingInput(inputs) && guardrailWordNumbers(g).length === 0 ? 'out' : 'in');
|
|
84
|
+
|
|
85
|
+
/** @typedef {{line: number, rule: number, text: string}} Rule */
|
|
86
|
+
/**
|
|
87
|
+
* Every `~` rule of a rubric job that this call settles, in line order. `rule` is the rule's number on its line (the number a part's `rules` and the answers use). A rule a
|
|
88
|
+
* kept page word already carries (the look tied it by line and rule number) or that the look already put under Not checked is left to that, EXCEPT a countable rule (`isCountable`: a word, list-item/line or section count), which always comes here: the look's fact stays beside the pick (keep-both). A repeated text on a line is
|
|
89
|
+
* one rule here, asked once.
|
|
90
|
+
* @param {{n: number, rule?: string, rules?: string[]}[]} jobLines @param {{inputs?: {value?: string}[]|null, look?: any}} [o]
|
|
91
|
+
* @returns {Rule[]}
|
|
92
|
+
*/
|
|
93
|
+
export function scopedRules(jobLines, { inputs = null, look = null } = {}) {
|
|
94
|
+
const facts = Array.isArray(look?.facts) ? look.facts : [];
|
|
95
|
+
const dropped = Array.isArray(look?.dropped) ? look.dropped : [];
|
|
96
|
+
/** @type {Rule[]} */
|
|
97
|
+
const out = [];
|
|
98
|
+
for (const l of Array.isArray(jobLines) ? jobLines : []) {
|
|
99
|
+
const seen = new Set();
|
|
100
|
+
lineRules(l).forEach((text, i) => {
|
|
101
|
+
const key = text.trim().toLowerCase();
|
|
102
|
+
const n = i + 1;
|
|
103
|
+
if (seen.has(key) || codeScope(inputs, text) !== 'in') return;
|
|
104
|
+
// a countable rule always reaches the pick offer: what the look tied or dropped on it stays (keep-both), but never hides the count from the person
|
|
105
|
+
if (!isCountable(text)) {
|
|
106
|
+
if (facts.some((/** @type {any} */ f) => f?.line === l.n && f?.forRule === n)) return;
|
|
107
|
+
if (dropped.some((/** @type {any} */ d) => d?.line === l.n && d?.rule === n)) return;
|
|
108
|
+
}
|
|
109
|
+
seen.add(key);
|
|
110
|
+
out.push({ line: l.n, rule: n, text });
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
return out;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// ---- code's keep-or-drop (am16 (2)) ------------------------------------------------------------------------------------------------------
|
|
117
|
+
const norm = (/** @type {unknown} */ t) => String(t).toLowerCase().replace(/\s+/g, ' ').trim();
|
|
118
|
+
/** a ~ rule's words compared case, spacing and trailing punctuation blind: the one spelling "is this the same rule?" is asked by */
|
|
119
|
+
export const sameRuleWords = (/** @type {unknown} */ a, /** @type {unknown} */ b) => norm(a).replace(/[.,;:!?\s]+$/, '') === norm(b).replace(/[.,;:!?\s]+$/, '');
|
|
120
|
+
const tokens = (/** @type {unknown} */ t) => new Set(norm(t).match(/[\p{L}\p{N}]+/gu) ?? []);
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* 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 every word in it
|
|
124
|
+
* is a word of the guardrail. Anything else is dropped, with the reason. `none` is a drop with the reason `none`.
|
|
125
|
+
* @param {string} guardrail @param {any} sug the model's entry for this guardrail
|
|
126
|
+
* @returns {{kept: true, check: Record<string, any>}|{kept: false, why: string}}
|
|
127
|
+
*/
|
|
128
|
+
export function keepOrDrop(guardrail, sug) {
|
|
129
|
+
if (sug == null || typeof sug !== 'object') return { kept: false, why: 'unreadable suggestion' };
|
|
130
|
+
const { rule } = sug;
|
|
131
|
+
if (rule === 'none' || rule === undefined || rule === null) return { kept: false, why: 'none' };
|
|
132
|
+
if (typeof rule !== 'string' || !Object.hasOwn(VOCAB, rule)) return { kept: false, why: `rule "${rule}" is not on bareguard's list` };
|
|
133
|
+
if (!OFFERED.includes(rule)) return { kept: false, why: `rule "${rule}" is on bareguard's list but is not offered here` };
|
|
134
|
+
const own = Object.keys(VOCAB[rule].fields).filter((k) => !IGNORED.has(k));
|
|
135
|
+
for (const k of own) if (VOCAB[rule].fields[k].required && sug[k] == null) return { kept: false, why: `${rule} needs ${k}` };
|
|
136
|
+
const allowed = new Set([...own, 'rule', 'line', 'guardrail']);
|
|
137
|
+
for (const k of Object.keys(sug)) if (sug[k] != null && !allowed.has(k)) return { kept: false, why: `${rule} does not take ${k}` };
|
|
138
|
+
/** @type {Record<string, any>} */
|
|
139
|
+
const check = { rule };
|
|
140
|
+
for (const k of own) {
|
|
141
|
+
const v = sug[k];
|
|
142
|
+
if (v == null) continue;
|
|
143
|
+
if (NUM_FIELDS.includes(k)) {
|
|
144
|
+
const floor = rule === 'maxListItems' ? 0 : 1; // maxListItems 0 = no bullets (bareguard 0.35); every other count starts at 1
|
|
145
|
+
if (!Number.isInteger(v) || v < floor) return { kept: false, why: `${k} ${JSON.stringify(v)} is not a whole number >= ${floor}` };
|
|
146
|
+
const named = rule === 'maxWords' || rule === 'minWords' ? guardrailWordNumbers(guardrail)
|
|
147
|
+
: k === 'wordsPerSection' ? [guardrailWordsPerSection(guardrail)].filter((x) => x !== null)
|
|
148
|
+
: listBoundNumbers(rule, guardrail);
|
|
149
|
+
if (!named.includes(v)) return { kept: false, why: `${k} ${v} is not a number the guardrail names (${named.join(', ') || 'it names none'})` };
|
|
150
|
+
check[k] = v;
|
|
151
|
+
} else if (WORD_FIELDS.includes(k)) {
|
|
152
|
+
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` };
|
|
153
|
+
const gTok = tokens(guardrail);
|
|
154
|
+
const gNorm = norm(guardrail);
|
|
155
|
+
for (const s of v) {
|
|
156
|
+
if (!gNorm.includes(norm(s))) return { kept: false, why: `${k} "${s}" is not in the guardrail's words` };
|
|
157
|
+
for (const t of tokens(s)) if (!gTok.has(t)) return { kept: false, why: `${k} word "${t}" is not a word of the guardrail` };
|
|
158
|
+
}
|
|
159
|
+
check[k] = v;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (rule === 'sections' || rule === 'sectionOrder' || rule === 'sectionWords') {
|
|
163
|
+
const want = guardrailSectionCount(guardrail);
|
|
164
|
+
if (want !== null && check.names.length !== want) return { kept: false, why: `the guardrail says ${want} sections; the check has ${check.names.length}` };
|
|
165
|
+
}
|
|
166
|
+
return { kept: true, check };
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// ---- the call: prompt, answer form (fwd F144c, per-rule anyOf) ---------------------------------------------------------------------------
|
|
170
|
+
const vocabBlock = OFFERED.map((r) => `- ${VOCAB[r].description}`).join('\n');
|
|
171
|
+
export const SUGGEST_SYSTEM = `You help a person turn the guardrails written under the lines of a job into mechanical checks.
|
|
172
|
+
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.
|
|
173
|
+
|
|
174
|
+
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".
|
|
175
|
+
|
|
176
|
+
Rules:
|
|
177
|
+
- 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.
|
|
178
|
+
- 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.
|
|
179
|
+
- Suggest \`sections\` or \`sectionWords\` only when the guardrail itself names the sections.
|
|
180
|
+
- A guardrail like 'all under N words' or 'under N words' is about the whole answer: use maxWords N.
|
|
181
|
+
- 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".
|
|
182
|
+
- Answer for every guardrail once, using the line number and the guardrail number shown.
|
|
183
|
+
|
|
184
|
+
Checks the checker can run (rule({ fields })):
|
|
185
|
+
${vocabBlock}`;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* 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.
|
|
189
|
+
* @param {{n: number, text: string}[]} lines @param {Rule[]} scoped @returns {string}
|
|
190
|
+
*/
|
|
191
|
+
export function suggestUserText(lines, scoped) {
|
|
192
|
+
const out = ['The job:'];
|
|
193
|
+
for (const l of lines) {
|
|
194
|
+
out.push(`${l.n}. ${l.text}`);
|
|
195
|
+
for (const s of scoped) if (s.line === l.n) out.push(` g${s.rule}: ${s.text}`);
|
|
196
|
+
}
|
|
197
|
+
return out.join('\n');
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const JSON_TYPE = /** @type {Record<string, any>} */ ({ integer: { type: 'integer', minimum: 1 }, 'string-list': { type: 'array', minItems: 1, items: { type: 'string' } } });
|
|
201
|
+
/** @param {string} rule @returns {object} one variant of the answer form: exactly that rule's own fields, nothing else */
|
|
202
|
+
function variant(rule) {
|
|
203
|
+
/** @type {Record<string, any>} */
|
|
204
|
+
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 } };
|
|
205
|
+
const required = ['line', 'guardrail', 'rule'];
|
|
206
|
+
if (rule !== 'none') {
|
|
207
|
+
for (const [k, f] of Object.entries(VOCAB[rule].fields)) {
|
|
208
|
+
if (IGNORED.has(k)) continue;
|
|
209
|
+
properties[k] = JSON_TYPE[f.type];
|
|
210
|
+
if (f.required) required.push(k);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return { type: 'object', properties, required, additionalProperties: false };
|
|
214
|
+
}
|
|
215
|
+
/** the tool's parameter schema: one `anyOf` variant per offered rule, plus `none` */
|
|
216
|
+
export const SUGGEST_SCHEMA = Object.freeze({
|
|
217
|
+
type: 'object',
|
|
218
|
+
properties: { checks: { type: 'array', description: 'One entry per guardrail.', items: { anyOf: [...OFFERED, 'none'].map(variant) } } },
|
|
219
|
+
required: ['checks'],
|
|
220
|
+
additionalProperties: false,
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
/** the instruction a retry carries (the structured ladder's own words, naming this tool) */
|
|
224
|
+
export const SUGGEST_INSTRUCTION = `Your reply did not deliver exactly one ${SUGGEST_TOOL} call. Call ${SUGGEST_TOOL} exactly once, with one entry per guardrail as its arguments. Do not write the answer as text.`;
|
|
225
|
+
|
|
226
|
+
/** @param {{calls: any[]}} box the tool the suggestion call is made through; it records and acknowledges, and takes no action */
|
|
227
|
+
export const suggestTool = (box) => ({
|
|
228
|
+
name: SUGGEST_TOOL,
|
|
229
|
+
description: 'Deliver your suggestion for every guardrail. Call this exactly once, with one entry per guardrail.',
|
|
230
|
+
parameters: SUGGEST_SCHEMA,
|
|
231
|
+
execute: async (/** @type {any} */ args) => { box.calls.push(args); return 'suggestions received'; },
|
|
232
|
+
});
|
|
233
|
+
/** the channel `askStructured` (src/authorflow.js) runs the call over */
|
|
234
|
+
export const suggestChannel = () => ({
|
|
235
|
+
name: SUGGEST_TOOL,
|
|
236
|
+
instruction: SUGGEST_INSTRUCTION,
|
|
237
|
+
textPath: 'checks',
|
|
238
|
+
tool: (/** @type {{calls: any[]}} */ box) => suggestTool(box),
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* The check CODE proposes for a count rule when the call yields none (R10, ours; fwd has no such fallback): a bullets / list-items / points count -> listItems N (exact; "at most / up to / no more than / fewer than / under / below" -> maxListItems, "at least / minimum / no fewer than / more than" -> minListItems, F315), a lines count ->
|
|
243
|
+
* maxLines N, ONE word number -> minWords N when the rule says "at least / minimum / more than", else maxWords N. A section count names no sections, so none is built; a rule naming two different counts ("3 bullets under 80 words") is not built either; a rule with
|
|
244
|
+
* several word numbers or a range ("between 100 and 200 words") is not guessed. The result passes `keepOrDrop`, so every number is one the rule names.
|
|
245
|
+
* @param {string} text @returns {Record<string, any>|null}
|
|
246
|
+
*/
|
|
247
|
+
export function countCheck(text) {
|
|
248
|
+
const items = guardrailItemCount(text);
|
|
249
|
+
const words = guardrailWordNumbers(text);
|
|
250
|
+
/** @type {Record<string, any>|null} */
|
|
251
|
+
let built = null;
|
|
252
|
+
if (items !== null && (words.length > 0 || guardrailSectionCount(text) !== null)) return null; // two different counts in one rule: first-match readers would guess, so nothing is built
|
|
253
|
+
if (items !== null && /\blines?\b/i.test(text) && !/\b(bullets?|items?|points?)\b/i.test(text)) built = { rule: 'maxLines', value: items };
|
|
254
|
+
else if (items !== null) {
|
|
255
|
+
const dir = listDirection(text);
|
|
256
|
+
if (dir === 'min') built = { rule: 'minListItems', value: MORE_THAN.test(text) ? items + 1 : items };
|
|
257
|
+
else if (dir === 'max') built = { rule: 'maxListItems', value: FEWER_THAN.test(text) ? items - 1 : items };
|
|
258
|
+
else built = { rule: 'listItems', value: items };
|
|
259
|
+
}
|
|
260
|
+
else if (words.length === 1 && !/\bbetween\b|\d\s*(?:-|–|to)\s*\d/i.test(text)) built = { rule: /\b(at least|min(?:imum)?|more than|over|no fewer than)\b/i.test(text) ? 'minWords' : 'maxWords', value: words[0] };
|
|
261
|
+
if (built === null) return null;
|
|
262
|
+
const res = keepOrDrop(text, built);
|
|
263
|
+
return res.kept ? res.check : null;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* What the call's answer comes to, one row per scoped rule: the check kept (or null) and why it was dropped. A rule the answer never mentions is dropped as `no entry`; an
|
|
268
|
+
* entry for a rule that was not sent is ignored.
|
|
269
|
+
* @param {Rule[]} scoped @param {any} args the tool call's arguments
|
|
270
|
+
* @returns {(Rule & {check: Record<string, any>|null, why: string|null})[]}
|
|
271
|
+
*/
|
|
272
|
+
export function rowsFromAnswer(scoped, args) {
|
|
273
|
+
const entries = Array.isArray(args?.checks) ? args.checks : [];
|
|
274
|
+
return scoped.map((s) => {
|
|
275
|
+
const e = entries.find((/** @type {any} */ x) => x?.line === s.line && x?.guardrail === s.rule);
|
|
276
|
+
const res = e === undefined ? /** @type {ReturnType<typeof keepOrDrop>} */ ({ kept: false, why: 'no entry' }) : keepOrDrop(s.text, e);
|
|
277
|
+
if (res.kept) return { ...s, check: res.check, why: null };
|
|
278
|
+
// R10 (hamr 2026-11-09): a count rule is never "I can't check this"; with no kept pick from the call, CODE proposes the check its own readers name
|
|
279
|
+
const own = countCheck(s.text);
|
|
280
|
+
return { ...s, check: own, why: own ? null : res.why };
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// ---- the asks (words are item 4's) -------------------------------------------------------------------------------------------------------
|
|
285
|
+
/** the can't-check ask, as the signed words say it */
|
|
286
|
+
export const CANT_CHECK_WORDS = "I can't check this. Your own words, or Not checked?";
|
|
287
|
+
/** how every answer is told, once (fwd am2 item 2's words) */
|
|
288
|
+
export 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.`;
|
|
289
|
+
|
|
290
|
+
/** a part of a rubric-step stage, from a pick: the check's own fields, the rule's words, and the `~` rule numbers it carries out @param {Record<string, any>} check @param {string} text @param {number[]} rules */
|
|
291
|
+
export function partOfPick(check, text, rules) {
|
|
292
|
+
const { rule, ...fields } = check;
|
|
293
|
+
return { text, class: 'countable', check: rule, ...fields, rules };
|
|
294
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// R10 (fwdloop M10 am16 (1)): the ONE paid call that suggests, per `~` rule, a check from bareguard's list. It runs over bareloop's own structured ladder (`askStructured`: the ceiling
|
|
2
|
+
// is read before the call, one retry on an unusable reply, cut-off and malformed arguments are named reds, the answer is logged scrubbed), thinking as the drafter's (off).
|
|
3
|
+
// An unusable answer is NOT a guessed check: every rule then reads "I can't check this" (fwd: "one retry on an unusable answer, then every guardrail reads I can't check this").
|
|
4
|
+
import { askStructured, makeCostBook } from './authorflow.js';
|
|
5
|
+
import { suggestChannel, suggestUserText, rowsFromAnswer } from './checkpick.js';
|
|
6
|
+
|
|
7
|
+
/** the label of the call, as the drafting book and the draft log see it */
|
|
8
|
+
export const SUGGEST_LABEL = 'check-suggest';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param {{jobLines: {n: number, text: string}[], scoped: {line: number, rule: number, text: string}[], generate: Function, ceilingUsd?: number|null,
|
|
12
|
+
* onCall?: (call: any) => void, priorCalls?: any[], priorRaws?: any[]}} o
|
|
13
|
+
* @returns {Promise<{state: 'ok'|'absent', reason: string|null, rows: ReturnType<typeof rowsFromAnswer>, calls: any[], raws: any[]}>}
|
|
14
|
+
*/
|
|
15
|
+
export async function runCheckSuggest({ jobLines, scoped, generate, ceilingUsd = null, onCall = () => {}, priorCalls = [], priorRaws = [] }) {
|
|
16
|
+
const book = makeCostBook({ ceilingUsd, onCall });
|
|
17
|
+
book.absorb(priorCalls, priorRaws);
|
|
18
|
+
const before = book.report().calls.length;
|
|
19
|
+
const beforeRaws = book.raws().length;
|
|
20
|
+
const r = await askStructured({
|
|
21
|
+
messages: [{ role: 'user', content: suggestUserText(jobLines, scoped) }], generate, mode: 'tool', retries: 1, label: SUGGEST_LABEL, book, channel: suggestChannel(),
|
|
22
|
+
});
|
|
23
|
+
const calls = book.report().calls.slice(before);
|
|
24
|
+
const raws = book.raws().slice(beforeRaws);
|
|
25
|
+
if (r.artifact) return { state: 'ok', reason: null, rows: rowsFromAnswer(scoped, r.artifact), calls, raws };
|
|
26
|
+
const reason = r.budget ? 'the spend ceiling was reached' : (r.providerError ?? r.red?.detail ?? 'the answer could not be read');
|
|
27
|
+
return { state: 'absent', reason, rows: rowsFromAnswer(scoped, { checks: [] }), calls, raws };
|
|
28
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// borrowed-from: fwdloop src/checkwords.js@v0.29.0
|
|
2
|
+
// R10 (fwdloop 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,
|
|
3
|
+
// the plan card, the draft log and the Audit all read it; nothing else writes these words. Identical to fwdloop v0.29.0 by ruling (match fwd first).
|
|
4
|
+
/** the rules of bareguard's list a person may pick here (text rules only: the ones a plain answer can be judged by) */
|
|
5
|
+
export const OFFERED = Object.freeze(['nonEmpty', 'maxWords', 'minWords', 'maxLines', 'listItems', 'maxListItems', 'minListItems', 'sections', 'sectionOrder', 'sectionWords', 'mustCarry', 'blockLines']);
|
|
6
|
+
const listOf = (/** @type {string[]} */ xs) => xs.join(', ');
|
|
7
|
+
/**
|
|
8
|
+
* 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.
|
|
9
|
+
* @param {{rule: string, value?: number, size?: number, wordsPerSection?: number, names?: string[], phrases?: string[]}} c @returns {string}
|
|
10
|
+
*/
|
|
11
|
+
export function plainWords(c) {
|
|
12
|
+
switch (c.rule) {
|
|
13
|
+
case 'nonEmpty': return 'the answer is not empty';
|
|
14
|
+
case 'maxWords': return `at most ${c.value} words`;
|
|
15
|
+
case 'minWords': return `at least ${c.value} words`;
|
|
16
|
+
case 'maxLines': return `at most ${c.value} lines`;
|
|
17
|
+
case 'listItems': return `exactly ${c.value} list items`;
|
|
18
|
+
case 'maxListItems': return `at most ${c.value} list items`;
|
|
19
|
+
case 'minListItems': return `at least ${c.value} list items`;
|
|
20
|
+
case 'sections': return `sections named ${listOf(c.names ?? [])}`;
|
|
21
|
+
case 'sectionOrder': return `sections named ${listOf(c.names ?? [])}, in that order`;
|
|
22
|
+
case 'sectionWords': return `sections named ${listOf(c.names ?? [])}, each about ${c.wordsPerSection} words`;
|
|
23
|
+
case 'mustCarry': return `the answer carries ${listOf(c.phrases ?? [])}`;
|
|
24
|
+
case 'blockLines': return `blocks of ${c.size} lines, each carrying ${listOf(c.phrases ?? [])}`;
|
|
25
|
+
default: return `a ${c.rule} check`;
|
|
26
|
+
}
|
|
27
|
+
}
|
package/src/cli.js
CHANGED
|
@@ -352,7 +352,7 @@ async function mainInner(argv, deps, holder) {
|
|
|
352
352
|
// deps)`, unparsed: that function is this flag grammar's one owner
|
|
353
353
|
// (`--job`/`--spec`/`--resume`/`--door`/`--decide`/`--text`/
|
|
354
354
|
// `--review-door`/`--approve`/`--registry`/`--workflow`/`--model`/
|
|
355
|
-
// `--read-shim`/`--scout`). `deps` is spread first so an injected test
|
|
355
|
+
// `--read-shim`/`--scout`/`--ticket`/`--anyway`). `deps` is spread first so an injected test
|
|
356
356
|
// seam (`deps.provider`/`providerFor`/`judgeProvider`) still reaches it,
|
|
357
357
|
// then `env`/`out`/`err` are overridden to the SAME resolved values every
|
|
358
358
|
// other command here prints through, so `run-u`'s output lands on the
|
package/src/config.js
CHANGED
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
// { "monthlyLimitUsd": <number > 0>, // absent = no limit, no check
|
|
12
12
|
// "learningHints": true|false, // absent = true (ON by default; only false turns it off): the planner is handed cross-run learnings (src/learn.js); the tally is kept either way
|
|
13
13
|
// "keys": { "<ENV NAME>": { "shape": "<shape id>", "baseUrl": "http(s)://…", "legacyMaxTokens": true|false } },
|
|
14
|
-
// "models": { "<ENV NAME>": [ { "model": "<id>", "use": true|false, "inPerM": n, "outPerM": n } ] }
|
|
14
|
+
// "models": { "<ENV NAME>": [ { "model": "<id>", "use": true|false, "inPerM": n, "outPerM": n } ] },
|
|
15
|
+
// "mcpPaths": [ "<absolute path of an extra MCP config file>" ] } // judged by `mcpPathProblem`; read by src/mcpsources.js
|
|
15
16
|
// An older file's `keys.<ENV>.{name,priceInPerM,priceOutPerM}` is tolerated and read as ONE model
|
|
16
17
|
// line (`effectiveModels`, src/providerrows.js); the first write of that row's `models` list removes them.
|
|
17
18
|
// `modelsProblem` is the ONE rule for a row's model lines: a price is a PAIR or neither, a ticked
|
|
@@ -122,6 +123,24 @@ export function modelsProblem(list) {
|
|
|
122
123
|
return null;
|
|
123
124
|
}
|
|
124
125
|
|
|
126
|
+
/**
|
|
127
|
+
* The rule for `mcpPaths` (extra MCP config files the person added): a list of absolute, NUL-free paths, no duplicates. Plain words, or null.
|
|
128
|
+
* (The Settings > MCP tab, R3, is the writer; `~` is expanded there, so what is stored is always absolute. One line, at most 500 characters: fwd's rule.)
|
|
129
|
+
* @param {unknown} list
|
|
130
|
+
* @returns {string|null}
|
|
131
|
+
*/
|
|
132
|
+
export function mcpPathProblem(list) {
|
|
133
|
+
if (!Array.isArray(list)) return 'The MCP paths must be a list of file paths.';
|
|
134
|
+
const seen = new Set();
|
|
135
|
+
for (const p of list) {
|
|
136
|
+
if (typeof p !== 'string' || p.trim() === '' || p.length > 500 || /[\0\r\n]/.test(p)) return 'Each MCP path must be one line of at most 500 characters.';
|
|
137
|
+
if (!p.startsWith('/')) return `The MCP path "${p}" must be a full path (it starts with /).`;
|
|
138
|
+
if (seen.has(p)) return `The MCP path "${p}" is listed twice.`;
|
|
139
|
+
seen.add(p);
|
|
140
|
+
}
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
|
|
125
144
|
/**
|
|
126
145
|
* The first problem in a document's known fields, in plain words, or null.
|
|
127
146
|
* @param {Record<string, any>} doc
|
|
@@ -130,6 +149,10 @@ export function modelsProblem(list) {
|
|
|
130
149
|
function docProblem(doc) {
|
|
131
150
|
// monthlyLimitUsd is NOT judged here: `monthlyLimitOf` (src/monthly.js) owns its read-time sentence
|
|
132
151
|
if (doc.learningHints !== undefined && typeof doc.learningHints !== 'boolean') return 'learningHints must be true or false';
|
|
152
|
+
if (doc.mcpPaths !== undefined) {
|
|
153
|
+
const bad = mcpPathProblem(doc.mcpPaths);
|
|
154
|
+
if (bad) return `mcpPaths: ${bad}`;
|
|
155
|
+
}
|
|
133
156
|
if (doc.keys !== undefined) {
|
|
134
157
|
if (doc.keys === null || typeof doc.keys !== 'object' || Array.isArray(doc.keys)) return 'keys must be an object of key variable names';
|
|
135
158
|
for (const [env, row] of Object.entries(doc.keys)) {
|
package/src/declaredclose.js
CHANGED
|
@@ -102,7 +102,15 @@ export const DECLARED_GENRES = Object.freeze([TYPES_GENRE.name, TEXT_GENRE]);
|
|
|
102
102
|
* constrained to the names the genre OWNS, so it can never become an environment
|
|
103
103
|
* channel of its own.
|
|
104
104
|
*/
|
|
105
|
-
export const CLOSE_DECL_FIELDS = Object.freeze(['genre', 'lang', 'stages', 'notes', 'refused', 'guardLines', 'genreEnv', 'calibration']);
|
|
105
|
+
export const CLOSE_DECL_FIELDS = Object.freeze(['genre', 'lang', 'stages', 'notes', 'refused', 'guardLines', 'picks', 'list', 'genreEnv', 'calibration']);
|
|
106
|
+
|
|
107
|
+
/** the fields of a row of the one check list that the signed close carries (`closeDecl.list`); the row's own words are never signed */
|
|
108
|
+
export const SIGNED_ROW_FIELDS = Object.freeze(['line', 'key', 'from', 'by', 'kind', 'state', 'rule', 'part', 'reason', 'facts']);
|
|
109
|
+
/** the states a signed row may end in */
|
|
110
|
+
export const SIGNED_STATES = Object.freeze(['built', 'not-checked', 'dropped']);
|
|
111
|
+
const SIGNED_FROM = Object.freeze(['rule', 'pick', 'look', 'agent', 'default']);
|
|
112
|
+
const SIGNED_BY = Object.freeze(['you', 'agent', 'default']);
|
|
113
|
+
const SIGNED_KINDS = Object.freeze(['rule', 'fact', 'cited', 'count', 'phrase', 'numbers', 'floor']);
|
|
106
114
|
|
|
107
115
|
/** what a stored calibration set carries, ENUMERATED: the frozen cases and the judge
|
|
108
116
|
* tier that graded them. Both are inside the spec, so `jobSpecHash` covers both — which
|
|
@@ -321,6 +329,27 @@ export function validateCloseDecl(closeDecl, opts = {}) {
|
|
|
321
329
|
+ `land here); fields: ${CLOSE_DECL_FIELDS.join(', ')}`);
|
|
322
330
|
}
|
|
323
331
|
}
|
|
332
|
+
// the signed copy of the one check list: an array of rows with exactly the signed fields (no words), each in its closed menu
|
|
333
|
+
if (closeDecl.list !== undefined) {
|
|
334
|
+
if (!Array.isArray(closeDecl.list)) red('invalid-value', `${at}.list`, 'the one check list as an array of rows: { line, key, from, by, kind, state, rule?, part?, reason? }');
|
|
335
|
+
else {
|
|
336
|
+
closeDecl.list.forEach((/** @type {any} */ row, /** @type {number} */ i) => {
|
|
337
|
+
const w = `${at}.list[${i}]`;
|
|
338
|
+
if (!isObj(row)) { red('invalid-value', w, 'a row: { line, key, from, by, kind, state, rule?, part?, reason? }'); return; }
|
|
339
|
+
for (const k of Object.keys(row)) if (!SIGNED_ROW_FIELDS.includes(k)) red('unknown-field', `${w}.${k}`, `not a signed row field (the row's own words are never signed); fields: ${SIGNED_ROW_FIELDS.join(', ')}`);
|
|
340
|
+
if (!Number.isInteger(row.line) || row.line < 1) red('invalid-value', `${w}.line`, 'the job line number');
|
|
341
|
+
if (!isNonEmptyString(row.key)) red('invalid-value', `${w}.key`, 'the row key, a non-empty string');
|
|
342
|
+
if (!SIGNED_FROM.includes(row.from)) red('invalid-value', `${w}.from`, `menu: ${SIGNED_FROM.join('|')}`);
|
|
343
|
+
if (!SIGNED_BY.includes(row.by)) red('invalid-value', `${w}.by`, `menu: ${SIGNED_BY.join('|')}`);
|
|
344
|
+
if (!SIGNED_KINDS.includes(row.kind)) red('invalid-value', `${w}.kind`, `menu: ${SIGNED_KINDS.join('|')}`);
|
|
345
|
+
if (!SIGNED_STATES.includes(row.state)) red('invalid-value', `${w}.state`, `menu: ${SIGNED_STATES.join('|')}`);
|
|
346
|
+
if (row.rule !== undefined && !Number.isInteger(row.rule)) red('invalid-value', `${w}.rule`, 'the ~ rule number');
|
|
347
|
+
if (row.part !== undefined && !(isObj(row.part) && Number.isInteger(row.part.line) && Number.isInteger(row.part.part))) red('invalid-value', `${w}.part`, '{ line, part }: the job line and the index of the part that carries the row');
|
|
348
|
+
if (row.reason !== undefined && typeof row.reason !== 'string') red('invalid-value', `${w}.reason`, 'plain words');
|
|
349
|
+
if (row.facts !== undefined && !(Array.isArray(row.facts) && row.facts.every((/** @type {unknown} */ x) => typeof x === 'string'))) red('invalid-value', `${w}.facts`, 'the names of the facts the row built, an array of strings');
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
}
|
|
324
353
|
// PART 1a: a genre is bound to its language — code languages are TYPES, the rubric-files language is TEXT, and neither may
|
|
325
354
|
// wear the other's label (`lang` is checked just below; an unknown lang reds there)
|
|
326
355
|
if (!DECLARED_GENRES.includes(closeDecl.genre) || closeDecl.genre !== genreForLang(closeDecl.lang)) {
|