bareloop 0.55.0 → 0.57.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.
Files changed (92) hide show
  1. package/CHANGELOG.md +82 -0
  2. package/README.md +3 -3
  3. package/bareloop.context.md +69 -209
  4. package/package.json +2 -2
  5. package/src/authorflow.js +164 -340
  6. package/src/authoring.js +7 -127
  7. package/src/authorjob.js +139 -472
  8. package/src/authorreadout.js +24 -368
  9. package/src/authorrun.js +21 -215
  10. package/src/behaviour.js +14 -0
  11. package/src/blockasks.js +43 -0
  12. package/src/bundlerun.js +4 -1
  13. package/src/checkblock.js +798 -0
  14. package/src/checklist.js +128 -0
  15. package/src/checkpick.js +39 -312
  16. package/src/checkwords.js +3 -1
  17. package/src/cli.js +3 -3
  18. package/src/declaredclose.js +38 -108
  19. package/src/destpoint.js +4 -2
  20. package/src/draftspend.js +46 -0
  21. package/src/facts.js +8 -1
  22. package/src/index.js +3 -43
  23. package/src/interviewrun.js +13 -8
  24. package/src/job.js +20 -1
  25. package/src/jobblock.js +11 -46
  26. package/src/judged.js +13 -1229
  27. package/src/kinds.js +5 -347
  28. package/src/noteask.js +124 -0
  29. package/src/pagedry.js +27 -5
  30. package/src/pagemap.js +15 -3
  31. package/src/pagerules.js +18 -3
  32. package/src/panel/authorroutes.js +24 -6
  33. package/src/panel/authorsession.js +222 -177
  34. package/src/panel/importrun.js +0 -1
  35. package/src/panel/index.html +198 -26
  36. package/src/panel/jobplan.js +87 -33
  37. package/src/panel/server.js +74 -68
  38. package/src/panel/status.js +3 -0
  39. package/src/pickrecord.js +34 -55
  40. package/src/placerule.js +355 -0
  41. package/src/planrun.js +2 -48
  42. package/src/promptregisters.js +13 -17
  43. package/src/providerrows.js +0 -36
  44. package/src/providers.js +4 -25
  45. package/src/questionbox.js +104 -0
  46. package/src/rowedit.js +115 -0
  47. package/src/rubricstep.js +234 -127
  48. package/src/run.js +11 -16
  49. package/src/userrun.js +60 -112
  50. package/types/authorflow.d.ts +41 -197
  51. package/types/authoring.d.ts +1 -14
  52. package/types/authorjob.d.ts +35 -59
  53. package/types/authorreadout.d.ts +10 -88
  54. package/types/behaviour.d.ts +12 -0
  55. package/types/blockasks.d.ts +36 -0
  56. package/types/checkblock.d.ts +376 -0
  57. package/types/checklist.d.ts +134 -0
  58. package/types/checkpick.d.ts +8 -140
  59. package/types/cli.d.ts +1 -3
  60. package/types/declaredclose.d.ts +7 -33
  61. package/types/destpoint.d.ts +2 -0
  62. package/types/draftspend.d.ts +21 -0
  63. package/types/index.d.ts +2 -4
  64. package/types/job.d.ts +8 -0
  65. package/types/jobblock.d.ts +8 -38
  66. package/types/judged.d.ts +7 -357
  67. package/types/kinds.d.ts +3 -104
  68. package/types/noteask.d.ts +76 -0
  69. package/types/pagedry.d.ts +13 -0
  70. package/types/pagemap.d.ts +4 -0
  71. package/types/pagerules.d.ts +7 -0
  72. package/types/panel/authorsession.d.ts +47 -5
  73. package/types/panel/jobgrid.d.ts +8 -8
  74. package/types/panel/jobplan.d.ts +48 -10
  75. package/types/panel/server.d.ts +27 -18
  76. package/types/panel/status.d.ts +5 -0
  77. package/types/pickrecord.d.ts +20 -13
  78. package/types/placerule.d.ts +194 -0
  79. package/types/planrun.d.ts +1 -22
  80. package/types/providerrows.d.ts +0 -31
  81. package/types/providers.d.ts +3 -19
  82. package/types/questionbox.d.ts +87 -0
  83. package/types/rowedit.d.ts +32 -0
  84. package/types/rubricstep.d.ts +100 -48
  85. package/types/run.d.ts +9 -19
  86. package/types/userrun.d.ts +0 -1
  87. package/src/calibrate.js +0 -702
  88. package/src/cardauthor.js +0 -502
  89. package/src/fitcheck.js +0 -166
  90. package/types/calibrate.d.ts +0 -201
  91. package/types/cardauthor.d.ts +0 -358
  92. package/types/fitcheck.d.ts +0 -113
@@ -8,8 +8,7 @@
8
8
  // rule applies to, and this file's own doc-comment is where a human reads it.
9
9
  //
10
10
  // The inventory is FILE-scoped, not const-scoped. Several of the files below
11
- // hold more than one named prompt const, and at least two (authorscout.js,
12
- // cardauthor.js) also build a model-facing prompt INLINE inside a function
11
+ // hold more than one named prompt const, and at least one (authorscout.js) also build a model-facing prompt INLINE inside a function
13
12
  // (template literals, not a top-level const) rather than assembling one from a
14
13
  // named export. A const-scoped check would silently miss those; a file-scoped
15
14
  // one does not, because the whole file is in scope once it appears here. The
@@ -20,7 +19,7 @@
20
19
  // consts that read as model-facing instruction text, and separately for inline
21
20
  // template-literal prompts built inside a function). Files checked and found to
22
21
  // carry NO prompt content: src/plan.js, src/validate.js, src/kinds.js,
23
- // src/text.js, src/declaredclose.js, src/calibrate.js, src/index.js (the last
22
+ // src/text.js, src/declaredclose.js, src/index.js (the last
24
23
  // is the barrel export only).
25
24
 
26
25
  /**
@@ -51,24 +50,10 @@ export const PROMPT_REGISTERS = Object.freeze([
51
50
  Object.freeze({ file: 'src/authorflow.js', name: 'CONFIRM_STRUCTURE_INSTRUCTION' }),
52
51
  Object.freeze({ file: 'src/authorflow.js', name: 'confirmedBlock() (inline template, not a const — feeds authorPrompt)' }),
53
52
 
54
- // src/judged.js — the softgreen judge's locate prompt (spine + per-rule asks)
55
- Object.freeze({ file: 'src/judged.js', name: 'PROMPT_HEAD' }),
56
- Object.freeze({ file: 'src/judged.js', name: 'PROMPT_TAIL' }),
57
- Object.freeze({ file: 'src/judged.js', name: 'JUDGE_RULES[*].ask (per-rule fragments)' }),
58
- Object.freeze({ file: 'src/judged.js', name: 'locatePrompt() (inline template, not a const)' }),
59
-
60
- // src/cardauthor.js — compiles a person's own words into a judged rubric
61
- Object.freeze({ file: 'src/cardauthor.js', name: 'COMPILE_SYSTEM' }),
62
- Object.freeze({ file: 'src/cardauthor.js', name: 'cardCasesPrompt() (inline template, not a const)' }),
63
-
64
53
  // src/pagemap.js - the page-word map call (idea A core): the AI names the page's own words for the person's job
65
54
  Object.freeze({ file: 'src/pagemap.js', name: 'MAP_SYSTEM' }),
66
55
  Object.freeze({ file: 'src/pagemap.js', name: 'mapPrompt() (inline template, not a const)' }),
67
56
 
68
- // src/fitcheck.js - the fit check call (F243): the AI splits each job line into asks and quotes the page for each
69
- Object.freeze({ file: 'src/fitcheck.js', name: 'FIT_SYSTEM' }),
70
- Object.freeze({ file: 'src/fitcheck.js', name: 'fitPrompt() (inline template, not a const)' }),
71
-
72
57
  // src/readshim.js — the capped/deduplicating read shim's worker-facing strategy
73
58
  Object.freeze({ file: 'src/readshim.js', name: 'READ_SHIM_STRATEGY' }),
74
59
  Object.freeze({ file: 'src/readshim.js', name: 'READ_SHIM_DIFF_STRATEGY' }),
@@ -88,6 +73,17 @@ export const PROMPT_REGISTERS = Object.freeze([
88
73
  // (F198 item 2), built inline inside `middle` and appended to `w.ask([...])`
89
74
  Object.freeze({ file: 'src/planrun.js', name: 'middle()\'s facts-only "The close\'s own numbers so far" block (inline template, not a const)' }),
90
75
 
76
+ // src/checklist.js — the one check list of a rubric job: the list call's system text and schema descriptions, the drafter's list block, the code-written refusal words
77
+ Object.freeze({ file: 'src/checklist.js', name: 'LEDGER_SYSTEM' }),
78
+ Object.freeze({ file: 'src/checklist.js', name: 'LEDGER_SCHEMA (property descriptions)' }),
79
+ Object.freeze({ file: 'src/checklist.js', name: 'ledgerUserText() (inline template, not a const)' }),
80
+ Object.freeze({ file: 'src/checklist.js', name: 'WEEK_ONLY_WORDS, EMPTY_LIST_WORDS' }),
81
+
82
+ // src/rowedit.js — the drafter's row-edit turn of a rubric job (the check block): system text, the one user message, the revise line, the tool's description
83
+ Object.freeze({ file: 'src/rowedit.js', name: 'ROW_EDIT_SYSTEM' }),
84
+ Object.freeze({ file: 'src/rowedit.js', name: 'ROW_EDIT_REVISE, rowEditUserText() (inline template, not a const)' }),
85
+ Object.freeze({ file: 'src/rowedit.js', name: 'rowEditChannel() (tool description and instruction)' }),
86
+
91
87
  // src/authoring.js — the types-genre close template, interpolated verbatim
92
88
  // into the authoring prompt (src/authorflow.js's assembled system message,
93
89
  // "THE GENRE TEMPLATE" block) — model-facing law for a types-genre
@@ -367,39 +367,3 @@ export function ratesOfLine(line) {
367
367
  const outPerM = /** @type {number} */ (line.outPerM);
368
368
  return { rates: { in: inPerM / 1000, out: outPerM / 1000 }, inPerM, outPerM };
369
369
  }
370
-
371
- /**
372
- * The row a judge's key and endpoint come from: the worker's own row when the judge shares the worker's API shape, else the judge
373
- * shape's row that ticks the judge's model (else the first row of that shape). `null` when no row is on that shape.
374
- * @param {readonly KeyRow[]} rows
375
- * @param {{ provider: string, model?: string|null }} judge
376
- * @param {string|null|undefined} workerProvider
377
- * @param {KeyRow|null} workerRow
378
- * @returns {KeyRow|null}
379
- */
380
- export function judgeRowFor(rows, judge, workerProvider, workerRow) {
381
- if (judge.provider === workerProvider && workerRow) return workerRow;
382
- const onShape = rows.filter((r) => r.provider === judge.provider);
383
- return onShape.find((r) => r.models.some((l) => l.model === judge.model && isTickedLine(l))) ?? onShape[0] ?? null;
384
- }
385
-
386
- /**
387
- * The price a judge's rounds are booked at. A price belongs to the MODEL's line: when the judge is
388
- * the worker's own provider it calls the worker's endpoint, so a row on that endpoint with a line
389
- * NAMED for the judge's model prices it ({@link ratesFor}); a judge model that is absent or names
390
- * no line there keeps the worker's price (the worker's row, or none = the guess). A different
391
- * provider resolves with no endpoint. The judge's KEY is chosen elsewhere (`judgeRowFor`:
392
- * the worker's own row when the judge shares its provider), so the two can come from different rows.
393
- * @param {{ provider: string, model?: string|null }} judge
394
- * @param {string|null|undefined} workerProvider
395
- * @param {string|null|undefined} workerBaseUrl
396
- * @param {ReturnType<typeof ratesFor>} workerPrice what the worker's own rounds are booked at
397
- * @param {readonly KeyRow[]} rows
398
- * @returns {ReturnType<typeof ratesFor>}
399
- */
400
- export function judgeRatesFor(judge, workerProvider, workerBaseUrl, workerPrice, rows) {
401
- if (judge.provider !== workerProvider) return ratesFor(judge.provider, undefined, rows, judge.model);
402
- const want = endpointOf(judge.provider, workerBaseUrl);
403
- const named = judge.model ? rows.some((r) => r.provider === judge.provider && endpointOf(r.provider, r.baseUrl) === want && r.models.some((l) => l.model === judge.model)) : false;
404
- return named ? ratesFor(judge.provider, workerBaseUrl, rows, judge.model) : workerPrice;
405
- }
package/src/providers.js CHANGED
@@ -169,41 +169,20 @@ export function makeProvider(providerName, { apiKey, model, baseUrl, legacyMaxTo
169
169
  }
170
170
 
171
171
  /**
172
- * Build the `{provider, providerFor, judgeProvider}` triple both authoring runners need (`src/authorrun.js` and
173
- * `src/panel/authorsession.js` call it) — ONE seam instead of two copies of the same construction. `model` is the
174
- * already-RESOLVED worker model id (the caller picked the Settings line).
175
- *
176
- * THE JUDGE IS NOT PINNED (PRD item 32.2): it is constructed through this same factory from a `judgeProviderName`/`judgeModel`
177
- * pair the CALLER resolved. `judgeApiKey` stays a SEPARATE argument: the judge may be a different provider from the worker,
178
- * and each key is read by the caller from its own row.
172
+ * Build the `{provider, providerFor}` pair both authoring runners need (`src/authorrun.js` and `src/panel/authorsession.js` call it) — ONE seam
173
+ * instead of two copies of the same construction. `model` is the already-RESOLVED worker model id (the caller picked the Settings line).
179
174
  * @param {object} args
180
175
  * @param {string} args.providerName the worker's API shape id
181
176
  * @param {string|undefined} args.apiKey the WORKER's key, read from its row's env name
182
177
  * @param {string} args.model the already-resolved worker model id
183
178
  * @param {string|undefined} [args.baseUrl] the worker row's Base URL
184
179
  * @param {boolean} [args.legacyMaxTokens] the worker row's old max_tokens tick
185
- * @param {string|undefined} args.judgeApiKey the judge's own key
186
- * @param {string} args.judgeModel the resolved judge model id
187
- * @param {string} [args.judgeProviderName] the resolved judge shape; defaults to `providerName`
188
- * @param {string|undefined} [args.judgeBaseUrl] the judge row's endpoint
189
- * @param {boolean} [args.judgeLegacyMaxTokens] the judge row's old max_tokens tick (defaults to the worker's when the judge shares its provider)
190
180
  */
191
- export function buildRunnerProviders({
192
- providerName, apiKey, model, baseUrl, legacyMaxTokens = false, judgeApiKey, judgeModel,
193
- judgeProviderName = providerName, judgeBaseUrl = undefined, judgeLegacyMaxTokens = undefined,
194
- }) {
181
+ export function buildRunnerProviders({ providerName, apiKey, model, baseUrl, legacyMaxTokens = false }) {
195
182
  const provider = makeProvider(providerName, { apiKey, model, baseUrl, legacyMaxTokens });
196
183
  // a plan step's `model` is the one schema token `sonnet` (STEP_MODELS, src/plan.js): it means THE JOB'S worker model
197
184
  const providerFor = (/** @type {string} */ _tier) => provider;
198
- // the judge goes through the SAME table as the worker. Reusing the worker instance when the identity matches exactly is not an
199
- // optimisation for its own sake: a second instance against the same endpoint/model is a second prompt-cache prefix, and cache
200
- // writes are ~41% of the bill.
201
- const judgeLegacy = judgeLegacyMaxTokens ?? (judgeProviderName === providerName ? legacyMaxTokens : false);
202
- const judgeProvider = (judgeProviderName === providerName && judgeModel === model && judgeApiKey === apiKey
203
- && judgeBaseUrl === baseUrl && judgeLegacy === legacyMaxTokens)
204
- ? provider
205
- : makeProvider(judgeProviderName, { apiKey: judgeApiKey, model: judgeModel, baseUrl: judgeBaseUrl, legacyMaxTokens: judgeLegacy });
206
- return { provider, providerFor, judgeProvider };
185
+ return { provider, providerFor };
207
186
  }
208
187
 
209
188
  /**
@@ -0,0 +1,104 @@
1
+ // The question box of the drafting chat (hamr 2026-11-12, as fwdloop M10 am29/am30/am31): a question asked while drafting gets its own box in the panel, with the question,
2
+ // its own buttons where the question offers choices (the person's intent is a typed choice, never words read), and one line to type in. This file is the ONE owner of what the
3
+ // panel shows for a pending question and of which choices a question offers (the page draws it, never works it out). The CLI (src/authorrun.js) is a sibling caller of the same
4
+ // questions and keeps typing words; the stored question text never changes, only the panel's copy of it is cut.
5
+ import { readingTail, cantCheckTail, DROP_IT } from './pagemap.js';
6
+ import { HOW_TO_ANSWER } from './checkpick.js';
7
+ import { DEST_ANSWER } from './destpoint.js';
8
+
9
+ /** the door's refusals, word for word (fwd am31); a refusal leaves the question open and writes nothing */
10
+ export const CHOICE_SAYS = Object.freeze({
11
+ bad: 'That answer is not one of the choices. Nothing was saved.',
12
+ notOffered: 'That choice is not offered for this question. Nothing was saved.',
13
+ outOfDate: 'This page is out of date. Reload it and answer again. Nothing was saved.',
14
+ noRule:'That question is about the job line, not one of your ~ rules, so there is nothing to drop. Agree, or type your own words. Nothing was saved.',
15
+ blank: 'An answer is needed here — there is no skip. Type it in the box and press Send.',
16
+ });
17
+
18
+ /**
19
+ * Which buttons a look question offers. Agree only when it carries a proposal (a reading ask with its reading, a check-pick ask with its check); Drop it only where "drop it" leaves
20
+ * one of the person's own `~` rules Not checked (a can't-check ask or a check-pick ask about a rule number).
21
+ * @param {{source?: string, ask?: string, reading?: unknown, check?: unknown, rule?: unknown}} q @returns {{agree: boolean, drop: boolean}}
22
+ */
23
+ export function offersOf(q) {
24
+ const look = q.source === 'look';
25
+ const agree = look && ((q.ask === 'reading' && typeof q.reading === 'string') || (q.ask === 'check' && q.check !== null && typeof q.check === 'object'));
26
+ const drop = look && Number.isInteger(q.rule) && (q.ask === 'cant-check' || q.ask === 'check' || q.ask === 'no-check');
27
+ return { agree, drop };
28
+ }
29
+
30
+ /**
31
+ * A look question as the PANEL shows it: the code's own answer words (`Answer "agree"...` / `Answer "drop it"...`) cut off the end, because the buttons and the box say it.
32
+ * Only the known tails are cut, matched exactly as a suffix (never a pattern over the prose); a question that ends in none of them is returned whole.
33
+ * @param {{question: string, line?: number, source?: string}} q @returns {string}
34
+ */
35
+ export function panelQuestionText(q) {
36
+ const text = String(q.question);
37
+ if (q.source === 'dest-point') return text.endsWith(DEST_ANSWER) ? text.slice(0, text.length - DEST_ANSWER.length) : text;
38
+ if (q.source !== 'look' || !Number.isInteger(q.line)) return text;
39
+ const n = /** @type {number} */ (q.line);
40
+ const hit = [readingTail(n), cantCheckTail(n), ` ${HOW_TO_ANSWER(n, true)}`, ` ${HOW_TO_ANSWER(n, false)}`].find((t) => text.endsWith(t));
41
+ return hit === undefined ? text : text.slice(0, text.length - hit.length);
42
+ }
43
+
44
+ /**
45
+ * What the panel's question box shows for one pending ask. Only a question the person answers (`kind: 'answer'`) has a box; every other ask (language, menu, install)
46
+ * keeps the chat input. `sendChoice` = the choice the box's own Send posts.
47
+ * @param {{kind: string, source?: string, index?: number, total?: number, question?: string, line?: number, offers?: {agree: boolean, drop: boolean}, folder?: string, current?: string}} step
48
+ * @returns {{head: string, line: string, text: string, choices: {choice: string, label: string}[], orLabel: string|null, sendChoice: string}|null}
49
+ */
50
+ export function boxFor(step) {
51
+ if (step.kind !== 'answer' || typeof step.question !== 'string') return null;
52
+ const before = step.source === 'dest-point';
53
+ // the Destination point: yes / no buttons and a box for a different Destination (checked at $0 before it is taken)
54
+ if (step.source === 'dest-point') {
55
+ return {
56
+ head: 'A question before drafting', line: Number.isInteger(step.line) ? `About job line ${step.line}` : '', text: panelQuestionText(/** @type {any} */ (step)),
57
+ choices: [{ choice: 'yes', label: `Yes, set it to ${step.folder ?? ''}` }, { choice: 'no', label: `No, keep ${String(step.current ?? '').trim().replace(/\s*\n\s*/g, ', ')}` }],
58
+ orLabel: 'Or type a different Destination:', sendChoice: 'path',
59
+ };
60
+ }
61
+ /** @type {{choice: string, label: string}[]} */
62
+ const choices = [];
63
+ if (step.offers?.agree) choices.push({ choice: 'agree', label: 'Agree' });
64
+ if (step.offers?.drop) choices.push({ choice: 'drop', label: 'Drop it' });
65
+ return {
66
+ head: before ? 'A question before drafting' : `A question the plan raised (${step.index ?? 1} of ${step.total ?? 1})`,
67
+ line: Number.isInteger(step.line) ? `About job line ${step.line}` : '',
68
+ text: panelQuestionText({ question: step.question, source: step.source, ...(Number.isInteger(step.line) ? { line: step.line } : {}) }),
69
+ choices,
70
+ orLabel: choices.length > 0 ? 'Or type a new rule:' : 'Type your answer:',
71
+ sendChoice: 'rule',
72
+ };
73
+ }
74
+
75
+ /** the choices each kind of question's typed answer may name */
76
+ const CHOICES = { look: ['agree', 'drop', 'rule'], 'dest-point': ['yes', 'no', 'path'] };
77
+
78
+ /**
79
+ * The door's check of a choice sent for the pending ask. Null = accepted; else the refusal words.
80
+ * @param {{kind: string, source?: string, rule?: unknown, offers?: {agree: boolean, drop: boolean}}} step @param {unknown} choice @returns {string|null}
81
+ */
82
+ export function refuseChoice(step, choice) {
83
+ if (step.kind !== 'answer') return CHOICE_SAYS.notOffered;
84
+ const own = /** @type {string[]|undefined} */ (/** @type {Record<string, string[]>} */ (CHOICES)[step.source === 'dest-point' ? step.source : 'look']);
85
+ if (typeof choice !== 'string' || !(own ?? CHOICES.look).includes(choice)) return CHOICE_SAYS.bad;
86
+ if (step.source === 'dest-point') return null;
87
+ if (choice === 'agree' && step.offers?.agree !== true) return CHOICE_SAYS.notOffered;
88
+ if (choice === 'drop' && step.offers?.drop !== true) return step.source === 'look' && !Number.isInteger(step.rule) ? CHOICE_SAYS.noRule : CHOICE_SAYS.notOffered;
89
+ return null;
90
+ }
91
+
92
+ /**
93
+ * What a choice resolves the question with: the words the asker reads (today's own words for the effect, so the drafting log and the CLI path see the same), and the chat line the person
94
+ * sees as their own. `rule` = the box's words kept whole.
95
+ * @param {unknown} choice @param {unknown} text @returns {{value: string, shown: string}|{error: string}}
96
+ */
97
+ export function resolveChoice(choice, text) {
98
+ if (choice === 'agree') return { value: 'agree', shown: 'Agree' };
99
+ if (choice === 'drop') return { value: DROP_IT, shown: 'Drop it' };
100
+ if (choice === 'yes') return { value: 'yes', shown: 'Yes' };
101
+ if (choice === 'no') return { value: 'no', shown: 'No' };
102
+ const said = String(text ?? '').replace(/\s*\n\s*/g, ' ').trim();
103
+ return said === '' ? { error: CHOICE_SAYS.blank } : { value: said, shown: said };
104
+ }
package/src/rowedit.js ADDED
@@ -0,0 +1,115 @@
1
+ // THE DRAFTER'S ROW-EDIT TURN of a rubric job (the check block, docs/product/ITEM33-BUILD.md "CHECK BLOCK BUILD SPEC" section 4 and hamr's rulings of 2026-11-12).
2
+ // The AI never writes a part, a check or a declaration: it sends EDITS to the list of checks code keeps in the CheckBlock (src/checkblock.js). Code reads the inputs, proves every
3
+ // word, builds every check and decides what can be checked; every edit is judged on its own. The confirm turn owns the goal (ruling 5), so the reply has none. A Tickets job's reply
4
+ // may also carry the optional `ticketFilter` (ruling 2, R5), checked by its own reader. No text here restates the list of checks (the block's invariant 5): the only list-shaped input is
5
+ // the look's report, an input the drafter already had, and the person's own job lines.
6
+ import { lineRules } from './rubricstep.js';
7
+ import { renderLookReport } from './inputlook.js';
8
+ import { OFFERED } from './checkwords.js';
9
+ import { rubricVocabulary } from 'bareguard';
10
+ import { TICKET_FILTER_SCHEMA_WORDS } from './ticketfilter.js';
11
+
12
+ /** the tool a row-edit reply is delivered through */
13
+ export const ROW_EDIT_TOOL = 'submit_edits';
14
+ /** what an acknowledged reply returns (the loop ends the call the moment the tool fires) */
15
+ export const ROW_EDIT_ACK = 'edits received';
16
+
17
+ const IGNORED_FIELDS = new Set(['id', 'field', 'text', 'strict']);
18
+ const GLOSS = /** @type {Record<string, string>} */ ({ nonEmpty: 'the output is not empty', maxWords: 'at most value words in all', minWords: 'at least value words in all', maxLines: 'at most value lines', listItems: 'exactly value list items (bullets)', maxListItems: 'at most value list items', minListItems: 'at least value list items', sections: 'the output has sections with these names', sectionOrder: 'the sections come in this order', sectionWords: 'each named section has at most wordsPerSection words', mustCarry: 'the output carries these phrases', blockLines: 'blocks of size lines carry these phrases' });
19
+ /** the checks a `pick` edit may name: the checker's own list (the same bareguard vocabulary src/checkpick.js reads) */
20
+ const pickMenu = () => OFFERED.map((r) => {
21
+ const fields = Object.entries(/** @type {any} */ (rubricVocabulary).rules[r].fields).filter(([k]) => !IGNORED_FIELDS.has(k)).map(([k, v]) => `${k}${/** @type {any} */ (v).required ? '' : '?'}`);
22
+ return `- ${r}${fields.length ? ` { ${fields.join(', ')} }` : ''}: ${GLOSS[r] ?? ''}`;
23
+ }).join('\n');
24
+
25
+ /** the drafter's system text for the row-edit turn (a prompt register: src/promptregisters.js) */
26
+ export const ROW_EDIT_SYSTEM = `You help turn the lines of a job into checks, by sending EDITS to a list of checks that code keeps. You never write a check, a stage, a part or a declaration: code reads the inputs, proves every word, builds every check and decides what can be checked. Each edit you send is judged on its own: a refused edit is dropped and says why, and it never costs your other edits.
27
+
28
+ HOW TO ANSWER
29
+ Deliver ONE reply with an "edits" list (the ${ROW_EDIT_TOOL} tool, or one JSON object {"edits": [ ... ]} and nothing else when no tool is offered). An empty "edits" list is a good answer when you have nothing sure to send.
30
+
31
+ THE FOUR EDITS (each has "op"; the op is exactly one of: add, reading, pick, not-checkable. A count is an add with "kind":"count"; "count" is never an op)
32
+ 1. add - a check the inputs support that the person did not write and the look did not give:
33
+ {"op":"add","kind":"fact","line":N,"name":"price label","shape":"money","words":["words copied exactly from the input"],"unit":["US dollars"],"currency":["$"],"source":"<input label>"}
34
+ {"op":"add","kind":"phrase","line":N,"name":"letters and spaces only","words":["fixed words copied exactly from the input"],"source":"<input label>"}
35
+ {"op":"add","kind":"count","line":N,"min":3,"max":3} (how many results the job line itself asks for; whole numbers of 1 or more; only when the line states it)
36
+ "shape" is one of phrase, money, number, date, time. A name uses letters, spaces, "-" or "_" only (no digits). "words" are copied exactly from the input, never typed from memory; words the input does not hold are refused. At most 3 adds in one reply: the later ones are refused.
37
+ 2. reading - the limit a ~ rule means, for a ~ rule the look tied to a fact ("carries ~ rule N") without giving the limit:
38
+ {"op":"reading","line":N,"rules":[n],"fact":"<that look fact's name>","reading":{"op":"lt","value":450}} (reading op is lt, lte, gt or gte)
39
+ {"op":"reading","line":N,"rules":[n],"fact":"<that look fact's name>","reading":{"op":"between","lo":"05:00","hi":"21:00"}}
40
+ A money limit is a number. A time limit is a 24-hour "HH:MM" string. A limit the person WROTE ("under $450") is a rule that can be checked: give its reading with its number. A number YOU make out of their words ("not a red-eye" becomes a departure time between 06:00 and 21:00) is your proposal for the person to check, and a time limit that you propose is a RANGE (between), never one-sided. A rule that holds more than one amount or range gets no reading.
41
+ 3. pick - for a ~ rule that counts words, bullets, lines or sections: the one check that says exactly what that rule says:
42
+ {"op":"pick","line":N,"rules":[n],"check":{"rule":"<one of the checks below>", ...that check's own fields}}
43
+ Use only numbers the ~ rule itself states and only words it contains. The checks (field? = optional):
44
+ ${pickMenu()}
45
+ 4. not-checkable - a ~ rule no check on the inputs can carry ("the cheapest", "the best", "the newest one"):
46
+ {"op":"not-checkable","line":N,"rule":n,"reason":"plain words, the person's own"}
47
+
48
+ RULES
49
+ - Names, labels and units are the input's own words, copied exactly as the input writes them. When the input does not use the person's word, use the words the input uses; never invent a word the input holds nowhere, and never add a code (like SFO) that the person did not write and the input does not hold.
50
+ - The look (below) is what a read of the inputs already found and code already checks: do not send it again as an add. Use it to name the fact a reading belongs to.
51
+ - Send only what you are sure of. A fact or ~ rule you cannot name from the look and the input is not guessed at.
52
+ - "line" is the job line's number; "rule" and "rules" are the ~ rule numbers shown under that line (1 = the first).`;
53
+
54
+ /** the fixed sentence that follows the refusals in a revise turn (the turn carries each refusal's own reason and nothing else) */
55
+ export const ROW_EDIT_REVISE = 'Send corrected edits only (an empty "edits" list is a good answer).';
56
+
57
+ /** how much of each input the turn is shown (the bound src/checklist.js used) */
58
+ const SHOWN_CHARS = 8000;
59
+
60
+ /**
61
+ * The ONE user message: the person's job lines (their `~` rules numbered), the look, the inputs (bounded).
62
+ * @param {{jobLines: any[], look: any, texts: Record<string, string>}} o
63
+ * @returns {string}
64
+ */
65
+ export function rowEditUserText({ jobLines, look, texts }) {
66
+ const out = ["THE JOB (the person's own words)"];
67
+ for (const l of jobLines) {
68
+ out.push(`${l.n}. ${l.text}`);
69
+ lineRules(l).forEach((r, i) => out.push(` ~ rule ${i + 1}: ${r}`));
70
+ }
71
+ const report = look && typeof look === 'object' ? renderLookReport(look).replace(/^WHAT THE LOOK AT THE INPUTS FOUND[^\n]*/, 'WHAT THE LOOK AT THE INPUTS FOUND - code checks each of these itself; you do not write them') : '';
72
+ if (report) out.push('', report);
73
+ for (const [label, t] of Object.entries(texts)) out.push('', `INPUT "${label}" (first ${SHOWN_CHARS} characters):`, String(t).slice(0, SHOWN_CHARS));
74
+ return out.join('\n');
75
+ }
76
+
77
+ /** @param {boolean} ticket @returns {Record<string, any>} the tool's schema: the edits list (each edit judged by code, so an item is any object), and for a Tickets job the optional ticketFilter */
78
+ const rowEditSchema = (ticket) => ({
79
+ type: 'object',
80
+ properties: {
81
+ edits: { type: 'array', items: { type: 'object', properties: { op: { enum: ['add', 'reading', 'pick', 'not-checkable'] } }, required: ['op'] }, description: 'row edits; each is judged on its own' },
82
+ ...(ticket ? {
83
+ ticketFilter: {
84
+ type: 'object',
85
+ properties: {
86
+ priority: { type: 'array', items: { type: 'string', enum: ['P0', 'P1', 'P2', 'P3'] }, description: 'priorities a ticket must have; only when a job line names them' },
87
+ labels: { type: 'array', items: { type: 'string' }, description: 'label names, one of which a ticket must carry; only when a job line names them' },
88
+ },
89
+ additionalProperties: false,
90
+ description: TICKET_FILTER_SCHEMA_WORDS,
91
+ },
92
+ } : {}),
93
+ },
94
+ required: ['edits'],
95
+ additionalProperties: false,
96
+ });
97
+
98
+ /** @param {boolean} ticket the channel `askStructured` reads (src/authorflow.js) */
99
+ export const rowEditChannel = (ticket = false) => ({
100
+ name: ROW_EDIT_TOOL,
101
+ instruction: `Your reply did not deliver exactly one ${ROW_EDIT_TOOL} call. Call ${ROW_EDIT_TOOL} exactly once, with the edits list as its arguments. Do not write the answer as text.`,
102
+ textPath: 'edits',
103
+ tool: (/** @type {{calls: any[]}} */ box) => ({
104
+ name: ROW_EDIT_TOOL,
105
+ description: 'Deliver your row edits (or an empty list). Call this exactly once.',
106
+ parameters: rowEditSchema(ticket),
107
+ execute: async (/** @type {any} */ args) => { box.calls.push(args); return ROW_EDIT_ACK; },
108
+ }),
109
+ });
110
+
111
+ /**
112
+ * The edits a reply holds, as a list (a reply whose `edits` is not a list holds none; each edit is still judged by the block).
113
+ * @param {any} artifact @returns {any[]}
114
+ */
115
+ export const editsOf = (artifact) => (artifact && typeof artifact === 'object' && Array.isArray(artifact.edits) ? artifact.edits : []);