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/authorflow.js
CHANGED
|
@@ -87,11 +87,14 @@ import {
|
|
|
87
87
|
import { buildSeedListing, cleanEntry, SURVEY_CAUSES, AUTHOR_CALL_TIMEOUT_MS } from './authorscout.js';
|
|
88
88
|
import { extractArtifact, priceOf, scrubRaw, tallyCalls, capStop, callCasualty } from './text.js';
|
|
89
89
|
import { redactSecrets } from './validate.js';
|
|
90
|
-
import {
|
|
90
|
+
import { ledgerRecord } from './checklist.js';
|
|
91
|
+
import { ROW_EDIT_REVISE, rowEditUserText, rowEditChannel, editsOf } from './rowedit.js';
|
|
92
|
+
import { REASON, CheckBlock } from './checkblock.js';
|
|
93
|
+
import { stepFileContract, inputLabelsOf, stepFileRel, readFrozenInputs, lineRules } from './rubricstep.js';
|
|
91
94
|
import { dropRows, dropLine } from './pagedropwords.js';
|
|
92
|
-
import {
|
|
93
|
-
import {
|
|
94
|
-
import {
|
|
95
|
+
import { renderLookReport } from './inputlook.js';
|
|
96
|
+
import { checkDeclarationWords, labelListsFor } from './factwords.js';
|
|
97
|
+
import { ticketFilterReds, ticketFilterBlock, ticketPerRunFacts, TICKET_FILTER_SCHEMA_WORDS } from './ticketfilter.js';
|
|
95
98
|
|
|
96
99
|
const require = createRequire(import.meta.url);
|
|
97
100
|
const { Loop } = require('bare-agent');
|
|
@@ -830,13 +833,10 @@ export const PARAM_SCHEMAS = Object.freeze({
|
|
|
830
833
|
properties: {
|
|
831
834
|
text: { type: 'string', minLength: 1, description: 'the constraint, in the person\'s own words' },
|
|
832
835
|
class: { enum: ['countable', 'fact', 'judged', 'guard', 'none'] },
|
|
833
|
-
check: { enum: ['
|
|
834
|
-
value: { type: 'integer', minimum: 1, description: '
|
|
835
|
-
names: { type: 'array', minItems: 1, items: { type: 'string', minLength: 1 }, description: 'sections / sectionWords: the section names' },
|
|
836
|
-
wordsPerSection: { type: 'integer', minimum: 1 },
|
|
836
|
+
check: { enum: ['cited', 'minClaims', 'maxClaims'], description: 'countable only; minClaims / maxClaims count the claims listed under the input named in source' },
|
|
837
|
+
value: { type: 'integer', minimum: 1, description: 'minClaims / maxClaims: the number of claims asked for' },
|
|
837
838
|
source: { type: 'string', minLength: 1, description: 'cited: the label of the input a quote must come from' },
|
|
838
839
|
domains: { type: 'array', minItems: 1, items: { type: 'string', minLength: 1 }, description: 'guard only: the web domains the rule is about' },
|
|
839
|
-
covers: { type: 'array', minItems: 1, uniqueItems: true, items: { type: 'integer', minimum: 1 }, description: 'the number(s) of the CONFIRMED check(s) this part carries out' },
|
|
840
840
|
rules: { type: 'array', minItems: 1, uniqueItems: true, items: { type: 'integer', minimum: 1 }, description: 'the number(s) of the job line\'s ~ rules this part carries out (1 = the first ~ rule under the line)' },
|
|
841
841
|
facts: {
|
|
842
842
|
type: 'array',
|
|
@@ -940,9 +940,10 @@ export function schemaCoverage(catalogue = KIND_CATALOGUE) {
|
|
|
940
940
|
* `kinds` (Part 1a) narrows the branches to the kinds a language may use (`catalogueForLang`) WITHOUT narrowing the coverage check,
|
|
941
941
|
* which stays over the whole catalogue; null (the default) = no narrowing.
|
|
942
942
|
* @param {Record<string, any>} [catalogue]
|
|
943
|
-
*
|
|
943
|
+
* `ticket` (MCP + tickets piece 2) adds the optional top-level `ticketFilter` property for a job that reads tickets; absent, the schema is byte-identical.
|
|
944
|
+
* @param {{verdictType?: string|null, questions?: boolean, kinds?: string[]|null, ticket?: boolean}} [o]
|
|
944
945
|
*/
|
|
945
|
-
export function declarationSchema(catalogue = KIND_CATALOGUE, { verdictType = null, questions = false, kinds = null } = {}) {
|
|
946
|
+
export function declarationSchema(catalogue = KIND_CATALOGUE, { verdictType = null, questions = false, kinds = null, ticket = false } = {}) {
|
|
946
947
|
const cov = schemaCoverage(catalogue);
|
|
947
948
|
if (!cov.ok) {
|
|
948
949
|
throw new Error('[authorflow] the declaration schema does not cover the catalogue — '
|
|
@@ -1016,6 +1017,17 @@ export function declarationSchema(catalogue = KIND_CATALOGUE, { verdictType = nu
|
|
|
1016
1017
|
},
|
|
1017
1018
|
description: 'optional: which job lines the always-on guards already cover (a line whose every ask a mandatory guard checks needs no stage of its own)',
|
|
1018
1019
|
},
|
|
1020
|
+
...(ticket ? {
|
|
1021
|
+
ticketFilter: {
|
|
1022
|
+
type: 'object',
|
|
1023
|
+
properties: {
|
|
1024
|
+
priority: { type: 'array', items: { type: 'string', enum: ['P0', 'P1', 'P2', 'P3'] }, description: 'priorities a ticket must have; only when a job line names them' },
|
|
1025
|
+
labels: { type: 'array', items: { type: 'string' }, description: 'label names, one of which a ticket must carry; only when a job line names them' },
|
|
1026
|
+
},
|
|
1027
|
+
additionalProperties: false,
|
|
1028
|
+
description: TICKET_FILTER_SCHEMA_WORDS,
|
|
1029
|
+
},
|
|
1030
|
+
} : {}),
|
|
1019
1031
|
...(questions ? {
|
|
1020
1032
|
questions: {
|
|
1021
1033
|
type: 'array',
|
|
@@ -1037,13 +1049,13 @@ export function declarationSchema(catalogue = KIND_CATALOGUE, { verdictType = nu
|
|
|
1037
1049
|
* The output channel. It records and acknowledges; it takes no action, which is
|
|
1038
1050
|
* why handing it to a toolless authoring call does not reopen D3.
|
|
1039
1051
|
* @param {{calls: any[]}} box
|
|
1040
|
-
* @param {{catalogue?: Record<string, any>, verdictType?: string|null, questions?: boolean, kinds?: string[]|null}} [o]
|
|
1052
|
+
* @param {{catalogue?: Record<string, any>, verdictType?: string|null, questions?: boolean, kinds?: string[]|null, ticket?: boolean}} [o]
|
|
1041
1053
|
*/
|
|
1042
|
-
export function declarationTool(box, { catalogue = KIND_CATALOGUE, verdictType = null, questions = false, kinds = null } = {}) {
|
|
1054
|
+
export function declarationTool(box, { catalogue = KIND_CATALOGUE, verdictType = null, questions = false, kinds = null, ticket = false } = {}) {
|
|
1043
1055
|
return {
|
|
1044
1056
|
name: DECLARATION_TOOL_NAME,
|
|
1045
1057
|
description: 'Deliver the finished close. Call this exactly once, with the whole declaration as its arguments.',
|
|
1046
|
-
parameters: declarationSchema(catalogue, { verdictType, questions, kinds }),
|
|
1058
|
+
parameters: declarationSchema(catalogue, { verdictType, questions, kinds, ticket }),
|
|
1047
1059
|
execute: async (/** @type {any} */ args) => { box.calls.push(args); return DECLARATION_ACK; },
|
|
1048
1060
|
};
|
|
1049
1061
|
}
|
|
@@ -1228,21 +1240,28 @@ export function writeScopeBlock(writeScope) {
|
|
|
1228
1240
|
* meaning from `openQuestions` (which means "could not resolve"): the two
|
|
1229
1241
|
* never merge.
|
|
1230
1242
|
* @param {{checks: string[], checkItems?: {text: string, fromLine: number[]|null}[], protections: string[], openQuestions?: string[], notChecked?: string[],
|
|
1231
|
-
* answeredQuestions?: string[]}} confirmed
|
|
1232
|
-
* @param {{numbered?: boolean}} [o] `numbered` (a rubric job on files): each confirmed check carries its `#n`, which a part cites in `covers`
|
|
1243
|
+
* answeredQuestions?: string[], goalOnly?: boolean}} confirmed
|
|
1233
1244
|
*/
|
|
1234
|
-
export function confirmedBlock(confirmed
|
|
1245
|
+
export function confirmedBlock(confirmed) {
|
|
1235
1246
|
const checks = confirmed.checks ?? [];
|
|
1236
1247
|
const protections = confirmed.protections ?? [];
|
|
1237
1248
|
const openQuestions = confirmed.openQuestions ?? [];
|
|
1238
1249
|
const notChecked = confirmed.notChecked ?? [];
|
|
1239
1250
|
const answeredQuestions = confirmed.answeredQuestions ?? [];
|
|
1251
|
+
// a rubric job's confirm turn plans the goal only (its checks are the list's): no check list and no "the person confirmed" text
|
|
1252
|
+
if (confirmed.goalOnly === true) {
|
|
1253
|
+
return 'ALWAYS-ON PROTECTIONS \u2014 already enforced by this run and unchanged by the job; never compose one of these as a check:\n\n'
|
|
1254
|
+
+ `${protections.map((p) => ` - ${p}`).join('\n') || ' (none)'}\n`
|
|
1255
|
+
+ (notChecked.length ? `\nTHESE WERE ASKED FOR, BUT NOTHING CHECKS THEM (state these in your notes):\n\n${notChecked.map((n) => ` - ${n}`).join('\n')}\n` : '')
|
|
1256
|
+
+ (answeredQuestions.length ? `\nQUESTIONS THE PERSON ANSWERED \u2014 binding:\n\n${answeredQuestions.map((a) => ` - ${a}`).join('\n')}\n` : '')
|
|
1257
|
+
+ (openQuestions.length ? `\nOPEN QUESTIONS (state these in your notes, never decide them silently):\n\n${openQuestions.map((q) => ` - ${q}`).join('\n')}\n` : '');
|
|
1258
|
+
}
|
|
1240
1259
|
return 'THE CONFIRMED PLAN — the person already saw and confirmed this in the confirm turn\n\n'
|
|
1241
1260
|
+ 'Compose stages for these checks and no other — a genre never adds a check the goal did not ask for, and '
|
|
1242
1261
|
+ 'neither do you:\n\n'
|
|
1243
1262
|
+ `${(confirmed.checkItems?.length
|
|
1244
|
-
? confirmed.checkItems.map((c
|
|
1245
|
-
: checks.map((c
|
|
1263
|
+
? confirmed.checkItems.map((c) => ` - ${c.fromLine && c.fromLine.length ? `[line ${c.fromLine.join(', ')}] ` : ''}${c.text}`)
|
|
1264
|
+
: checks.map((c) => ` - ${c}`)).join('\n') || ' (none)'}\n\n`
|
|
1246
1265
|
+ 'These protections are already always-on and unchanged by this plan — never compose one of these as a check:\n\n'
|
|
1247
1266
|
+ `${protections.map((p) => ` - ${p}`).join('\n') || ' (none)'}\n\n`
|
|
1248
1267
|
+ (notChecked.length
|
|
@@ -1330,9 +1349,6 @@ export function authorPrompt({
|
|
|
1330
1349
|
// it gets its own brief (`rubricAuthorPrompt`), which still ends in the same declaration tool and the same guards
|
|
1331
1350
|
// an absent catalogue is the language's own menu (`catalogueForLang`), so a code job's prompt never lists a rubric-only kind
|
|
1332
1351
|
const catalogue = catalogueIn ?? catalogueForLang(lang);
|
|
1333
|
-
if (lang === RUBRIC_LANG) {
|
|
1334
|
-
return rubricAuthorPrompt({ answers, questions, facts, listingBlock, verdictType, guards, mode, catalogue, writeScope, jobLines, inputs, confirmed, labelLists });
|
|
1335
|
-
}
|
|
1336
1352
|
const statement = CLASS_STATEMENTS[String(verdictType)] ?? null;
|
|
1337
1353
|
if (statement === null) {
|
|
1338
1354
|
throw new Error(`[authorflow] the authoring prompt needs the verdict class the user picked, and "${verdictType}" `
|
|
@@ -1449,165 +1465,6 @@ export const RUBRIC_FILES_STATEMENT = 'The person declared this job SOFT-GREEN a
|
|
|
1449
1465
|
+ 'Compose ONE rubric-step stage per numbered job line, after the mandatory guard, and name only limits the person actually '
|
|
1450
1466
|
+ 'asked for. A part you cannot express that way is not approximated by a stage that means something else.';
|
|
1451
1467
|
|
|
1452
|
-
/**
|
|
1453
|
-
* THE RUBRIC RULES, in one place (live fix B1): what the confirm step and the drafter are both told about turning the person's words
|
|
1454
|
-
* into checks. The confirm note ({@link RUBRIC_CONFIRM_NOTE}) and the composer brief ({@link REQUIRED_FACTS_BRIEF}) interpolate THIS
|
|
1455
|
-
* constant, so the two cannot drift (in smv6k6l8dxkzs the confirm step planned a limit the drafter then could not carry, and the
|
|
1456
|
-
* drafter added an airport code the person never wrote). Field-neutral: neither turn needs the other's field names.
|
|
1457
|
-
*/
|
|
1458
|
-
export const RUBRIC_RULES = 'THE RULES FOR TURNING THE PERSON\'S WORDS INTO CHECKS (the same for every turn of this job):\n - A limit the person WROTE ("under $450") is a rule that can be checked: plan it as a limit with its number.\n'
|
|
1459
|
-
+ ' - 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, marked '
|
|
1460
|
-
+ 'as the AI\'s proposal for the person to check; a limit on a time that you propose is a RANGE (between), never one-sided. The input does '
|
|
1461
|
-
+ 'not have to hold the person\'s word (it holds no "red-eye"): the limit goes on the time the input DOES hold (e.g. the one after "Departure time:"), as a '
|
|
1462
|
-
+ 'range marked as the AI\'s proposal.\n'
|
|
1463
|
-
+ ' - Names, labels and units are the INPUT\'s own words, copied exactly as the input writes them. When the input does not use the '
|
|
1464
|
-
+ 'person\'s word (they wrote SFO, the input says San Francisco International Airport), use the words the input uses; never invent a '
|
|
1465
|
-
+ 'word the input does not hold, and never add a code (like SFO) that the person did not write and the input does not hold.\n'
|
|
1466
|
-
+ ' - A label for a line that asks for N results (a count of N) must sit in each result, so the label list must count it N or more times '
|
|
1467
|
-
+ '(the x-number beside it). A label counted fewer times is on the page once or twice (a sort tab, a switch) and is refused at $0 with its count.\n'
|
|
1468
|
-
+ ' - The same holds for the words a "must say" (phrase) fact makes each quote say: they must be in the input at least N times for N results. Words counted fewer times (page-header words like "from San Francisco" when each result says "Leaves San Francisco International Airport") are refused at $0 with their count; pick words every result says, or drop the check.';
|
|
1469
|
-
|
|
1470
|
-
/**
|
|
1471
|
-
* REQUIRED FACTS, as the composer is told them (PART 1b, PRD item 33 RF1–RF17). The shape of the fact part is in the catalogue and the
|
|
1472
|
-
* schema; this is the judgement the schema cannot carry: what becomes a fact, where its words come from, and what is Not checked.
|
|
1473
|
-
*/
|
|
1474
|
-
export const REQUIRED_FACTS_BRIEF = 'REQUIRED FACTS — what a line that finds, lists or looks something up leaves behind\n\n'
|
|
1475
|
-
+ 'For such a line write ONE part of class "fact". The worker\'s file for that line holds only results, each with ONE quote copied '
|
|
1476
|
-
+ 'from the input and the value of every fact as the quote writes it — no free text. Code checks every value against its quote.\n'
|
|
1477
|
-
+ ' - The facts come from the job line itself AND from its ~ rules: "SFO to LAX" is a from fact and a to fact even with no ~ line. '
|
|
1478
|
-
+ 'One fact per thing the person asked for. Give every fact a shape. A rule (op, value, or between lo and hi) only where the person '
|
|
1479
|
-
+ 'asked for a limit.\n'
|
|
1480
|
-
+ ' - THE LOOK above is what a read of the inputs found: write the facts from it. Copy every label (anchor), unit and phrase EXACTLY '
|
|
1481
|
-
+ 'as the look gives it (the look\'s phrase facts become phrase facts with the same words), and say in "notes" when you used the input\'s '
|
|
1482
|
-
+ 'words instead of the person\'s. A label (anchor) is PICKED from the labels the look found in the input, never typed; one that is not '
|
|
1483
|
-
+ 'among them is refused at $0. What the look could not find is not checked: list it under "refused" in the person\'s words.\n'
|
|
1484
|
-
+ ' - A money fact names at least one of "unit" (the words the input writes after the amount) or "currency" (a sign: $, € or £), and may name both. Each is one value or a list: '
|
|
1485
|
-
+ 'at most 3 currencies and 10 units, none repeated, a unit at most 100 characters. A code like EUR is a unit (it is read after the number), never a currency. '
|
|
1486
|
-
+ 'Copy the forms the look gives for the fact, in its order (the first is the main one); a form the look does not give is refused at $0.\n'
|
|
1487
|
-
+ ' - A word the look lists under NOT CHECKED or LEFT OUT is never used in a fact - not as a label, a closing label, a unit or a currency - and is refused at $0 with the reason if you do. '
|
|
1488
|
-
+ 'A fact or ~ rule listed under NOT CHECKED is not turned into a check: code lists it under Not checked for the person, so you do not write it into "refused" yourself.\n'
|
|
1489
|
-
+ ' - A date fact whose look line gives a "lang" is signed with that lang, and a number or money fact whose look line gives a "decimal" is signed with that decimal; copy it exactly (a fact that does not is refused at $0, nothing spent). "lang" goes on a date only and "decimal" on a number or money only. '
|
|
1490
|
-
+ 'For such a fact the worker writes the value in one canonical form (a date as YYYY-MM-DD, an amount with a point before the decimals), not as the quote writes it. A fact the look lists under NOT CHECKED for its month names or its decimal comma is not signed.\n'
|
|
1491
|
-
+ ' - When one result holds several values of one kind (leaves / arrives, subtotal / total) give the fact an anchor, the label that sits right before the value you mean.\n'
|
|
1492
|
-
+ ' - Set aiProposal true on a fact whose number you made out of their words.\n'
|
|
1493
|
-
+ RUBRIC_RULES + '\n'
|
|
1494
|
-
+ ' - How MANY results were asked for is a count ("3 releases": count {min: 3, max: 3}). WHICH ones ("the last", "the newest") and '
|
|
1495
|
-
+ 'anything else you cannot express as a shape and a rule ("the cheapest", "the best", "a good pick") is NOT CHECKED: list it in "refused" as {"line": N, "rule": the number of that ~ rule, "reason": the '
|
|
1496
|
-
+ 'person\'s own words}. EVERY ~ rule of a line must be carried out by a part (list its number in the part\'s "rules", 1 = the first ~ '
|
|
1497
|
-
+ 'rule under the line) or be listed in "refused"; a rule that is neither is refused at $0.\n'
|
|
1498
|
-
+ ' - A line that WRITES (a summary, a report) keeps word, section and line counts. Code ties its numbers to the facts of the lines '
|
|
1499
|
-
+ 'before it; you do not add that.\n'
|
|
1500
|
-
+ ' - A look fact that says "carries ~ rule N" is how the look carried that rule: put N in the fact part\'s "rules" and do not also list rule N in "refused".\n'
|
|
1501
|
-
+ ' - A ~ rule that you carry out as a fact (a limit on a time, a price, a date: "not a red-eye" is a time fact with a between rule) is carried by the '
|
|
1502
|
-
+ 'fact part: list its number in that part\'s "rules". It is NOT also a part of its own: on a line that lists facts, a part of class judged or none '
|
|
1503
|
-
+ 'is refused. A rule you cannot express as a shape and a rule goes in "refused", never into a part.\n'
|
|
1504
|
-
+ ' - "covers" and "rules" are fields of the PART, written once on it as a list of numbers. A fact never has a "covers" or a "rules" field.\n'
|
|
1505
|
-
+ ' - ONE stage per job line, holding ALL of that line\'s facts (and its other parts). Two stages for one line are refused: put a '
|
|
1506
|
-
+ '~ rule\'s fact (a "not a red-eye" time) on the same stage as the line\'s other facts.\n'
|
|
1507
|
-
+ ' - WHICH SHAPE TAKES WHICH FIELDS (a field a shape does not take is refused):\n'
|
|
1508
|
-
+ factShapeGuide();
|
|
1509
|
-
|
|
1510
|
-
/**
|
|
1511
|
-
* The composer prompt for a rubric job on local files (Part 1a, docs/product/ITEM33-BUILD.md). There is no repository
|
|
1512
|
-
* and no survey: the facts are the numbered inputs and the listing is the frozen tree (input/ files, output/). It states
|
|
1513
|
-
* the step-file contract the worker is also told ({@link stepFileContract}), so the stage and the file cannot drift.
|
|
1514
|
-
* @param {{answers: Record<string|number, string>, questions?: Record<string|number, string>, facts: any, listingBlock: string,
|
|
1515
|
-
* verdictType: string, guards: {name: string, kind: string, params: Record<string, any>, fill: string[]}[],
|
|
1516
|
-
* mode?: 'tool'|'text', catalogue?: Record<string, any>, writeScope?: string[]|null,
|
|
1517
|
-
* jobLines?: {n: number}[]|null, inputs?: {n: number, label: string, value: string}[]|null, confirmed?: any,
|
|
1518
|
-
* labelLists?: string[]|null,
|
|
1519
|
-
* }} o
|
|
1520
|
-
* @returns {string}
|
|
1521
|
-
*/
|
|
1522
|
-
export function rubricAuthorPrompt({
|
|
1523
|
-
answers, questions = GREEN_QUESTIONS, facts, listingBlock, verdictType, guards,
|
|
1524
|
-
mode = 'tool', catalogue = KIND_CATALOGUE, writeScope = null, jobLines = null, inputs = null, confirmed = null, labelLists = null,
|
|
1525
|
-
}) {
|
|
1526
|
-
const interview = Object.entries(questions)
|
|
1527
|
-
.map(([n, q]) => `Q${n}. ${q}\nA${n}. ${answers?.[n] ?? '(no answer given)'}`)
|
|
1528
|
-
.join('\n\n');
|
|
1529
|
-
const role = `You are composing the close for one job.
|
|
1530
|
-
|
|
1531
|
-
The close is what decides whether a run of this job came back DONE. It runs after the work is
|
|
1532
|
-
finished, it is the only truth, and nothing else can overrule it. It is a list of STAGES. Each
|
|
1533
|
-
stage names a kind from the catalogue below and fills that kind's parameters. Stages run in the
|
|
1534
|
-
order you declare them.
|
|
1535
|
-
|
|
1536
|
-
Two sources fed you this brief and neither of them is you:
|
|
1537
|
-
- the person who wants the job done answered an interview, below, in their own words. They are
|
|
1538
|
-
not a software engineer and did not name commands, thresholds or patterns;
|
|
1539
|
-
- the person's own text files, frozen into the job. There is no code repository: the files sit
|
|
1540
|
-
under input/ and the run writes only under output/.`;
|
|
1541
|
-
const guardJson = guards.map((g) => ({
|
|
1542
|
-
name: g.name,
|
|
1543
|
-
kind: g.kind,
|
|
1544
|
-
params: { ...g.params, ...Object.fromEntries(g.fill.map((f) => [f, FILL_MARKER])) },
|
|
1545
|
-
}));
|
|
1546
|
-
const output = mode === 'tool'
|
|
1547
|
-
? `HOW TO ANSWER
|
|
1548
|
-
|
|
1549
|
-
Call the ${DECLARATION_TOOL_NAME} tool exactly once. Its arguments ARE the declaration: an ordered
|
|
1550
|
-
"stages" array, plus "notes" for anything you could not express, and "refused" for a job line no stage can check.
|
|
1551
|
-
Do not write the declaration as text.
|
|
1552
|
-
|
|
1553
|
-
Stage names are unique. Every parameter name comes from the catalogue and no other. No parameter is
|
|
1554
|
-
left as a placeholder. You never write a number the person did not ask for.`
|
|
1555
|
-
: `HOW TO ANSWER
|
|
1556
|
-
|
|
1557
|
-
A single JSON object and nothing else: an ordered "stages" array, plus "notes" for anything you
|
|
1558
|
-
could not express, and "refused" for a job line no stage can check.
|
|
1559
|
-
|
|
1560
|
-
Stage names are unique. Every parameter name comes from the catalogue and no other. No parameter is
|
|
1561
|
-
left as a placeholder. You never write a number the person did not ask for.`;
|
|
1562
|
-
return [
|
|
1563
|
-
role,
|
|
1564
|
-
`WHAT THE PERSON DECLARED "DONE" TO MEAN — their answer, not yours\n\n${RUBRIC_FILES_STATEMENT}`,
|
|
1565
|
-
`THE INTERVIEW — the person's own words\n\n${interview}`
|
|
1566
|
-
+ (inputs && inputs.length ? `\n\n${renderInputs(inputs)}` : ''),
|
|
1567
|
-
...(jobLines && jobLines.length ? [jobLineTagBlock(jobLines.length)] : []),
|
|
1568
|
-
...(writeScope && writeScope.length ? [writeScopeBlock(writeScope)] : []),
|
|
1569
|
-
...(confirmed ? [confirmedBlock(confirmed, { numbered: true }),
|
|
1570
|
-
'EVERY CONFIRMED CHECK IS COMPOSED OR MOVED, NEVER DROPPED\n\nThe person saw the numbered checks above. On each countable or fact part that carries one of them out, list its number in the PART\'s "covers" (once on the part, never on a fact inside it). '
|
|
1571
|
-
+ 'A confirmed check that no part covers is not silently left out: it is moved to Not checked before signing, and the person is told. '
|
|
1572
|
-
+ 'To count "N things listed", use minClaims / maxClaims (it counts the claims listed under an input); anything else you cannot count is not composed.'] : []),
|
|
1573
|
-
REQUIRED_FACTS_BRIEF,
|
|
1574
|
-
`THE STEP FILES — what the worker leaves behind for each job line\n\n${stepFileContract()}\n\n`
|
|
1575
|
-
+ 'The rubric-step stage for job line N reads exactly that file, output/steps/N.json. It names the inputs (by label) the '
|
|
1576
|
-
+ 'step must cite from, and the limits on its "text".',
|
|
1577
|
-
`THE FILES — the inputs the person pointed at, frozen into the job\n\n${JSON.stringify(withoutLook(facts), null, 2)}`
|
|
1578
|
-
+ (listingBlock ? `\n\n${listingBlock}` : ''),
|
|
1579
|
-
...(Array.isArray(labelLists) && labelLists.length ? [labelLists.join('\n\n')] : []),
|
|
1580
|
-
...(facts && facts.look ? [renderLookReport(facts.look)] : []),
|
|
1581
|
-
rubricCatalogueBlock(catalogue, { verdictType }),
|
|
1582
|
-
'MANDATORY GUARDS — already placed and already parameterised\n\n'
|
|
1583
|
-
+ 'This kind of job carries a stage the person did not ask for. It is fixed and you may not change, drop, rename, or '
|
|
1584
|
-
+ `re-kind it. The ONLY thing you fill in is each "${FILL_MARKER}" slot, from the interview:\n\n${JSON.stringify(guardJson, null, 2)}\n\n`
|
|
1585
|
-
+ 'Place it first: it is cheap, and the first red ends the judgement.',
|
|
1586
|
-
output,
|
|
1587
|
-
].join('\n\n---\n\n');
|
|
1588
|
-
}
|
|
1589
|
-
|
|
1590
|
-
/** the facts object without the look's report (that is its own block, written by code) @param {any} facts */
|
|
1591
|
-
function withoutLook(facts) {
|
|
1592
|
-
if (!facts || typeof facts !== 'object' || !('look' in facts)) return facts;
|
|
1593
|
-
const { look: _look, ...rest } = facts;
|
|
1594
|
-
return rest;
|
|
1595
|
-
}
|
|
1596
|
-
|
|
1597
|
-
/**
|
|
1598
|
-
* The kind rows of the catalogue, without the command-output parser text a rubric job never needs.
|
|
1599
|
-
* @param {Record<string, any>} catalogue @param {{verdictType?: string|null}} [o]
|
|
1600
|
-
*/
|
|
1601
|
-
function rubricCatalogueBlock(catalogue, { verdictType = null } = {}) {
|
|
1602
|
-
const menu = classMenu(verdictType, catalogue);
|
|
1603
|
-
const rows = Object.entries(catalogue).filter(([name, spec]) => menu.includes(name) && !spec.locked).map(([name, spec]) => `- ${name}\n ${spec.shape}\n required: ${spec.required.join(', ')}`
|
|
1604
|
-
+ `${spec.optional.length ? ` optional: ${spec.optional.join(', ')}` : ''}\n asserts: ${spec.asserts}`);
|
|
1605
|
-
return `THE KIND CATALOGUE — these are the only kinds that exist.
|
|
1606
|
-
You parameterise kinds. You never write a script, a shell fragment, or a new kind.
|
|
1607
|
-
|
|
1608
|
-
${rows.join('\n\n')}`;
|
|
1609
|
-
}
|
|
1610
|
-
|
|
1611
1468
|
// ── 3. THE MEASURED BLOCKS ───────────────────────────────────────────────────
|
|
1612
1469
|
|
|
1613
1470
|
/** F6, at the rendering boundary: an absent number is unknown, never 0. */
|
|
@@ -1664,13 +1521,15 @@ export function renderSeedReadBlock(rows, { gapCap = REVISE_GAP_CAP } = {}) {
|
|
|
1664
1521
|
* a credential crossed unmasked before this line existed. Applied to the whole
|
|
1665
1522
|
* rendered block rather than one field, so a red added to the validator is
|
|
1666
1523
|
* scrubbed by construction rather than by remembering.
|
|
1667
|
-
* @param {{kind: 'validation'|'artifact', reds: (Red|string)[], cap?: number}} o
|
|
1524
|
+
* @param {{kind: 'validation'|'artifact'|'edits', reds: (Red|string)[], cap?: number}} o
|
|
1668
1525
|
*/
|
|
1669
1526
|
export function renderRejectBlock({ kind, reds, cap = REVISE_RED_CAP }) {
|
|
1670
1527
|
const head = kind === 'validation'
|
|
1671
1528
|
? 'MEASURED VALIDATION — your declaration was rejected by the validator before any stage could run:'
|
|
1672
|
-
:
|
|
1673
|
-
|
|
1529
|
+
: kind === 'edits'
|
|
1530
|
+
? 'MEASURED EDITS — some of your edits were refused; each refusal is its own and your other edits stand:'
|
|
1531
|
+
: 'MEASURED PARSE — your reply could not be read as one declaration:';
|
|
1532
|
+
const rendered = (reds ?? []).map((r) => (typeof r === 'string' ? r : `${r.code} at ${r.path || '(root)'}: ${r.detail}${typeof r.hint === 'string' ? ` ${r.hint}` : ''}`));
|
|
1674
1533
|
const shown = rendered.slice(0, cap);
|
|
1675
1534
|
const tail = rendered.length > shown.length
|
|
1676
1535
|
? [` [${rendered.length - shown.length} of ${rendered.length} reds withheld — the cap is ${cap}]`]
|
|
@@ -1841,7 +1700,7 @@ export function resolveSourcePrefixes({ workdir, sourcePaths, seedFiles }) {
|
|
|
1841
1700
|
*/
|
|
1842
1701
|
/**
|
|
1843
1702
|
* @param {{ceilingUsd?: number|null,
|
|
1844
|
-
* onCall?: (call: {label: string, costUsd: number|null, unpricedRounds: number, thinkingStatus?: string}) => void}} [o]
|
|
1703
|
+
* onCall?: (call: {label: string, costUsd: number|null, unpricedRounds: number, thinkingStatus?: string, raw?: string}) => void}} [o]
|
|
1845
1704
|
* `ceilingUsd` is the OPERATOR's ceiling; `null`/absent is UNBOUNDED.
|
|
1846
1705
|
* `onCall` is a REPORTING seam fired as each metered call lands — the shell's
|
|
1847
1706
|
* only chance to know what has been spent while the run is still alive. It is
|
|
@@ -1861,10 +1720,13 @@ export function makeCostBook({ ceilingUsd = null, onCall = () => {} } = {}) {
|
|
|
1861
1720
|
add(label, r, attempt = 1) {
|
|
1862
1721
|
const call = { label, ...priceOf(r) };
|
|
1863
1722
|
entries.push(call);
|
|
1864
|
-
|
|
1723
|
+
const kept = scrubRaw({ label, attempt, text: r?.text, reason: r?.error ? String(r.error) : null });
|
|
1724
|
+
raws.push(kept);
|
|
1865
1725
|
// bare-agent's per-run `thinkingStatus` ('applied' | 'unsupported' | 'ignored' | 'unknown') rides the REPORTING seam only —
|
|
1866
|
-
// never the stored entry, so the cost report and every persisted shape stay as they were; absent when thinkingMode was not sent
|
|
1867
|
-
|
|
1726
|
+
// never the stored entry, so the cost report and every persisted shape stay as they were; absent when thinkingMode was not sent.
|
|
1727
|
+
// R9 (Part B 4): the call's scrubbed answer rides the same seam (secret-masked and bounded by `scrubRaw`, the one mask owner), so the session's drafting log keeps what an
|
|
1728
|
+
// unusable draft try actually said; an empty answer (a tool-delivered reply) adds nothing
|
|
1729
|
+
onCall({ ...call, ...(kept.text === '' ? {} : { raw: kept.text }), ...(r?.thinkingStatus === undefined ? {} : { thinkingStatus: r.thinkingStatus }) });
|
|
1868
1730
|
return entries.at(-1);
|
|
1869
1731
|
},
|
|
1870
1732
|
/** @param {{label: string, costUsd: number|null, unpricedRounds: number}[]} calls
|
|
@@ -2089,12 +1951,12 @@ export async function askStructured({ messages, generate, mode, retries, label,
|
|
|
2089
1951
|
/** THE DECLARATION CHANNEL — the one this loop has always used. Its schema is
|
|
2090
1952
|
* CLASS-SCOPED, like the prompt's catalogue block: the two must offer one set of
|
|
2091
1953
|
* kinds, or the composer reads about a kind it cannot call.
|
|
2092
|
-
* @param {{catalogue: Record<string, any>, verdictType: string, questions?: boolean, kinds?: string[]|null}} o */
|
|
2093
|
-
const declarationChannel = ({ catalogue, verdictType, questions = false, kinds = null }) => ({
|
|
1954
|
+
* @param {{catalogue: Record<string, any>, verdictType: string, questions?: boolean, kinds?: string[]|null, ticket?: boolean}} o */
|
|
1955
|
+
const declarationChannel = ({ catalogue, verdictType, questions = false, kinds = null, ticket = false }) => ({
|
|
2094
1956
|
name: DECLARATION_TOOL_NAME,
|
|
2095
1957
|
instruction: STRUCTURE_INSTRUCTION_TOOL,
|
|
2096
1958
|
textPath: 'declaration',
|
|
2097
|
-
tool: (/** @type {{calls: any[]}} */ box) => declarationTool(box, { catalogue, verdictType, questions, kinds }),
|
|
1959
|
+
tool: (/** @type {{calls: any[]}} */ box) => declarationTool(box, { catalogue, verdictType, questions, kinds, ticket }),
|
|
2098
1960
|
});
|
|
2099
1961
|
|
|
2100
1962
|
/** The declaration ask, over the shared ladder. `declaration` is `artifact`
|
|
@@ -2102,11 +1964,11 @@ const declarationChannel = ({ catalogue, verdictType, questions = false, kinds =
|
|
|
2102
1964
|
* anonymous artifact, and one word for two things is how a reader loses which.
|
|
2103
1965
|
* @param {{messages: any[], generate: Function, mode: 'tool'|'text', retries: number,
|
|
2104
1966
|
* label: string, book: ReturnType<typeof makeCostBook>, catalogue: Record<string, any>,
|
|
2105
|
-
* verdictType: string, questions?: boolean, kinds?: string[]|null}} o
|
|
1967
|
+
* verdictType: string, questions?: boolean, kinds?: string[]|null, ticket?: boolean}} o
|
|
2106
1968
|
*/
|
|
2107
|
-
async function askDeclaration({ messages, generate, mode, retries, label, book, catalogue, verdictType, questions = false, kinds = null }) {
|
|
1969
|
+
async function askDeclaration({ messages, generate, mode, retries, label, book, catalogue, verdictType, questions = false, kinds = null, ticket = false }) {
|
|
2108
1970
|
const r = await askStructured({
|
|
2109
|
-
messages, generate, mode, retries, label, book, channel: declarationChannel({ catalogue, verdictType, questions, kinds }),
|
|
1971
|
+
messages, generate, mode, retries, label, book, channel: declarationChannel({ catalogue, verdictType, questions, kinds, ticket }),
|
|
2110
1972
|
});
|
|
2111
1973
|
return { ...r, declaration: r.artifact };
|
|
2112
1974
|
}
|
|
@@ -2229,21 +2091,12 @@ const confirmChannel = () => ({
|
|
|
2229
2091
|
* {@link CLASS_STATEMENTS} already use, rather than a code matcher over prose.
|
|
2230
2092
|
*/
|
|
2231
2093
|
/**
|
|
2232
|
-
* What the confirm turn tells the model about a rubric job on local text files (model-facing, registered).
|
|
2233
|
-
*
|
|
2234
|
-
* input must back. Everything else the person asked for is named in `notChecked`, in their words.
|
|
2094
|
+
* What the confirm turn tells the model about a rubric job on local text files (model-facing, registered). The turn plans the goal only: the checks of the job are the one list's
|
|
2095
|
+
* (`src/checklist.js`), made before the draft, never this turn's.
|
|
2235
2096
|
*/
|
|
2236
|
-
export const RUBRIC_CONFIRM_NOTE = 'THIS JOB HAS NO REPOSITORY. Its inputs are the person\'s own text files, and each numbered job line leaves ONE '
|
|
2237
|
-
+ '
|
|
2238
|
-
+ '
|
|
2239
|
-
+ 'limit on that text (words, lines, sections, words per section); a claim that must be backed by a quote copied from a named input; '
|
|
2240
|
-
+ 'and a REQUIRED FACT, something a line finds (a price, a date, a time, a name, a phrase) with a limit only if the person gave one '
|
|
2241
|
-
+ '— plan one fact check for each thing the line asks to find, including those named in the line itself ("SFO to LAX"). Plan a check '
|
|
2242
|
-
+ 'only for what the person asked for in those terms; '
|
|
2243
|
-
+ 'anything that needs reading the text to judge it (tone, quality, accuracy), any superlative ("the cheapest", "the best") and any '
|
|
2244
|
-
+ 'choice of WHICH ones ("the last", "the newest") goes in `notChecked`, in the person\'s own words; how MANY results were asked for is '
|
|
2245
|
-
+ 'a count and can be checked.\n'
|
|
2246
|
-
+ RUBRIC_RULES;
|
|
2097
|
+
export const RUBRIC_CONFIRM_NOTE = 'THIS JOB HAS NO REPOSITORY. Its inputs are the person\'s own text files, and each numbered job line leaves ONE file the run writes. '
|
|
2098
|
+
+ 'The checks of this job are made elsewhere: plan none. Send an empty checks list, an empty notChecked list and an empty questions list, '
|
|
2099
|
+
+ 'and write ONE sentence saying what the job does, from the numbered job lines.';
|
|
2247
2100
|
|
|
2248
2101
|
export const CONFIRM_SYSTEM = 'You read what a NON-ENGINEER answered, plus a read-only survey or listing of their '
|
|
2249
2102
|
+ 'own repository, and draft a PLAN for a job\'s definition of done: the checks you plan to compose and one '
|
|
@@ -2264,6 +2117,14 @@ export const CONFIRM_SYSTEM = 'You read what a NON-ENGINEER answered, plus a rea
|
|
|
2264
2117
|
+ 'where an answer is genuinely missing — never to double-check something already answered. You cannot read '
|
|
2265
2118
|
+ 'anything and you cannot run anything: everything you know is in the message you are given.';
|
|
2266
2119
|
|
|
2120
|
+
/** the confirm turn's system prompt for a rubric job (model-facing, registered): a one-sentence goal, no check of its own */
|
|
2121
|
+
export const CONFIRM_GOAL_SYSTEM = 'You read what a NON-ENGINEER answered, plus the numbered job lines and the inputs they pointed at, and write a one-sentence goal for the job. '
|
|
2122
|
+
+ 'You never propose a check, a gap or a question: the checks of this job are made elsewhere. '
|
|
2123
|
+
+ 'You cannot read anything and you cannot run anything: everything you know is in the message you are given.';
|
|
2124
|
+
|
|
2125
|
+
/** the confirm turn's system prompt for a job of this language: a rubric job's is the goal-only one @param {string} lang @returns {string} */
|
|
2126
|
+
export const confirmSystemFor = (lang) => (lang === RUBRIC_LANG ? CONFIRM_GOAL_SYSTEM : CONFIRM_SYSTEM);
|
|
2127
|
+
|
|
2267
2128
|
/**
|
|
2268
2129
|
* The confirm turn's per-round prompt (model-facing, registered). Shows the
|
|
2269
2130
|
* person's own answers with their labels (the signed table's Field/Holds
|
|
@@ -2282,9 +2143,9 @@ export const CONFIRM_SYSTEM = 'You read what a NON-ENGINEER answered, plus a rea
|
|
|
2282
2143
|
* @param {{answers: Record<string|number, string>, questions: Record<string|number, string>,
|
|
2283
2144
|
* labels?: Record<string|number, string>, facts?: any, listing?: string|null,
|
|
2284
2145
|
* writeScope?: string[]|null, isRepo: boolean, lang: string, worseThanBefore?: string,
|
|
2285
|
-
* fixText?: string|null, protections?: string[], inputs?: {n: number, label: string, value: string}[]|null}} o
|
|
2146
|
+
* fixText?: string|null, protections?: string[], inputs?: {n: number, label: string, value: string}[]|null, ticket?: boolean}} o
|
|
2286
2147
|
*/
|
|
2287
|
-
export function confirmPrompt({ answers, questions, labels = {}, facts = null, listing = null, writeScope = null, isRepo, lang, worseThanBefore = '', fixText = null, protections = [], inputs = null }) {
|
|
2148
|
+
export function confirmPrompt({ answers, questions, labels = {}, facts = null, listing = null, writeScope = null, isRepo, lang, worseThanBefore = '', fixText = null, protections = [], inputs = null, ticket = false }) {
|
|
2288
2149
|
const lines = ['THE PERSON\'S OWN ANSWERS (a non-engineer; read exactly what they wrote, invent nothing beyond it):'];
|
|
2289
2150
|
for (const k of Object.keys(questions)) {
|
|
2290
2151
|
const label = labels[k] ? ` (${labels[k]})` : '';
|
|
@@ -2299,6 +2160,9 @@ export function confirmPrompt({ answers, questions, labels = {}, facts = null, l
|
|
|
2299
2160
|
// PART 1a: a rubric job on the person's own text files. The model is told what a check CAN be here, so that anything
|
|
2300
2161
|
// needing judgement lands in `notChecked` instead of being promised as a check
|
|
2301
2162
|
if (lang === RUBRIC_LANG) lines.push('', RUBRIC_CONFIRM_NOTE);
|
|
2163
|
+
// R10: the `~` rules code settles from the person's own picks are not yours to plan: a check for them is code's, a gap is code's Not checked row
|
|
2164
|
+
// MCP + tickets R5 (F285): a Tickets job's confirm turn is told the ticket is picked per run and a priority/label line is code's, so it never asks the person which ticket
|
|
2165
|
+
if (ticket) lines.push('', ticketPerRunFacts());
|
|
2302
2166
|
if (writeScope) lines.push(`WRITE SCOPE (the fence — the run may write only here): ${writeScope.join(', ')}`);
|
|
2303
2167
|
if (protections.length > 0) {
|
|
2304
2168
|
lines.push(
|
|
@@ -2352,7 +2216,7 @@ async function askConfirmPlan({ convo, generate, mode, book, label }) {
|
|
|
2352
2216
|
* ask: (step: {kind: string, [k: string]: any}) => Promise<string|null>,
|
|
2353
2217
|
* onPhase?: (phase: string, data?: any) => void, mode?: 'tool'|'text',
|
|
2354
2218
|
* worseThanBefore?: string, inputs?: {n: number, label: string, value: string}[]|null,
|
|
2355
|
-
* jobLines?: {n: number}[]|null}} o retired field (hamr's ruling 2026-09-28):
|
|
2219
|
+
* jobLines?: {n: number}[]|null, ticket?: boolean, card?: {checkItems: {text: string, fromLine: number[], by: 'agent'|'you'|'default', key?: string}[], notChecked: string[], notCheckedBy?: Record<string, string>}|null, block?: CheckBlock|null, cardOf?: (() => any)|null}} o retired field (hamr's ruling 2026-09-28):
|
|
2356
2220
|
* `worseThanBefore` is never asked any more and defaults to `''` — a
|
|
2357
2221
|
* caller may still pass a string through (kept for a future, non-ask
|
|
2358
2222
|
* source of the same constraint), it just never comes from an ask() step.
|
|
@@ -2376,7 +2240,15 @@ export async function runConfirmTurn({
|
|
|
2376
2240
|
inputs = null,
|
|
2377
2241
|
// PART 1a: the numbered job lines, so a rubric job's per-line file protections are listed from code
|
|
2378
2242
|
jobLines = null,
|
|
2243
|
+
// MCP + tickets R5 (F285): the job reads tickets; absent = the confirm prompt is byte-identical
|
|
2244
|
+
ticket = false,
|
|
2245
|
+
// a rubric job's check rows as the card readers read them (`cardOfClose` over `block.closeView()`): the card draws them, nothing else. SHOWN only: the accepted plan below never carries them
|
|
2246
|
+
card = null,
|
|
2247
|
+
// the live check block of a rubric job and the reader that draws its rows (`() => cardOfClose(...)`): the confirm card's Drop and Add are instant row edits ($0, no AI) through the block, and the card is redrawn from its rows
|
|
2248
|
+
block = null, cardOf = null,
|
|
2379
2249
|
}) {
|
|
2250
|
+
/** a rubric job's confirm turn plans the goal only (its checks are the list's) */
|
|
2251
|
+
const goalOnly = lang === RUBRIC_LANG;
|
|
2380
2252
|
/** @typedef {null|'cap-halt'|'pricing-red'|'provider-red'|'artifact-red'|'confirm-abandoned'|'confirm-restart'} ConfirmStop */
|
|
2381
2253
|
/** @returns {{ok: boolean, stop: ConfirmStop, rounds: number, accepted: null, reds: Red[], cost: any}} */
|
|
2382
2254
|
const base = () => ({ ok: false, stop: null, rounds: 0, accepted: null, reds: [], cost: book.report() });
|
|
@@ -2446,14 +2318,14 @@ export async function runConfirmTurn({
|
|
|
2446
2318
|
let convo = [{
|
|
2447
2319
|
role: 'user',
|
|
2448
2320
|
content: confirmPrompt({
|
|
2449
|
-
answers, questions, labels, facts, listing, writeScope, isRepo, lang: resolvedLang, worseThanBefore, protections, inputs,
|
|
2321
|
+
answers, questions, labels, facts, listing, writeScope, isRepo, lang: resolvedLang, worseThanBefore, protections, inputs, ticket,
|
|
2450
2322
|
}),
|
|
2451
2323
|
}];
|
|
2452
2324
|
|
|
2453
2325
|
for (let round = 1; round <= 2; round += 1) {
|
|
2454
2326
|
if (fixText) {
|
|
2455
2327
|
convo = [...convo, { role: 'user', content: confirmPrompt({
|
|
2456
|
-
answers, questions, labels, facts, listing, writeScope, isRepo, lang: resolvedLang, worseThanBefore, fixText, protections, inputs,
|
|
2328
|
+
answers, questions, labels, facts, listing, writeScope, isRepo, lang: resolvedLang, worseThanBefore, fixText, protections, inputs, ticket,
|
|
2457
2329
|
}) }];
|
|
2458
2330
|
}
|
|
2459
2331
|
onPhase('confirm-round', { round });
|
|
@@ -2483,13 +2355,26 @@ export async function runConfirmTurn({
|
|
|
2483
2355
|
// model's own honest gap list, carried through unchanged.
|
|
2484
2356
|
// NO SILENT DROP (idea A core, spec 4.5): what the page rules removed is said HERE too, in the same words as the signed plan, before
|
|
2485
2357
|
// drafting is paid for. The words come from the one table (src/pagedropwords.js).
|
|
2358
|
+
// a rubric job's turn keeps nothing but the goal of the model's plan: its checks, gaps and questions are the list's to make, so code discards any it sent
|
|
2359
|
+
if (goalOnly) r.plan = { ...r.plan, checks: [], notChecked: [], questions: [] };
|
|
2486
2360
|
const notChecked = [...(r.plan.notChecked ?? [])];
|
|
2487
2361
|
for (const row of dropRows(facts?.look?.dropped)) { const text = dropLine(row, jobLines, lineRules); if (!notChecked.includes(text)) notChecked.push(text); }
|
|
2488
2362
|
const checkItems = normalizeChecks(r.plan.checks);
|
|
2489
2363
|
r.plan = { ...r.plan, checks: checkItems.map((c) => c.text), checkItems };
|
|
2490
|
-
|
|
2364
|
+
// the rows of the check block, drawn by the same readers as the signed card (hamr 2026-11-12: the confirm card showed no row the block had built); shown only, never accepted
|
|
2365
|
+
const planFor = (/** @type {any} */ c) => ({
|
|
2366
|
+
...r.plan, ...(c === null ? {} : { checkItems: c.checkItems, checks: c.checkItems.map((/** @type {any} */ x) => x.text) }), protections, notChecked: c === null ? notChecked : [...new Set([...notChecked, ...c.notChecked])], ...(c?.notCheckedBy ? { notCheckedBy: c.notCheckedBy } : {}),
|
|
2367
|
+
signedFacts: (Array.isArray(facts?.look?.facts) ? facts.look.facts : []).map((/** @type {any} */ f) => String(f?.name)),
|
|
2368
|
+
...(block !== null && cardOf !== null ? { suggested: block.suggestedView(), editable: true } : {}),
|
|
2369
|
+
});
|
|
2370
|
+
const plan = planFor(card);
|
|
2491
2371
|
onPhase('confirm-done', { round, plan });
|
|
2492
|
-
|
|
2372
|
+
// Drop and Add on the confirm card: a row edit through the block (the choice decides), reconciled, then the card is drawn again from the rows. $0: no model call is made here
|
|
2373
|
+
const edit = block !== null && cardOf !== null ? (/** @type {'drop'|'add'} */ op, /** @type {string} */ key) => {
|
|
2374
|
+
const res = block.rowChoice(key, op);
|
|
2375
|
+
return res.ok ? { ok: true, plan: planFor(cardOf()), choices: block.choicesRecord() } : res;
|
|
2376
|
+
} : null;
|
|
2377
|
+
const picked = await ask({ kind: 'menu', field: CONFIRM_MENU, plan, ...(edit ? { edit } : {}) });
|
|
2493
2378
|
if (picked === null) return abandon(round);
|
|
2494
2379
|
if (picked === 'start-over') return { ...base(), stop: /** @type {ConfirmStop} */ ('confirm-restart'), rounds: round, cost: book.report() };
|
|
2495
2380
|
|
|
@@ -2500,7 +2385,7 @@ export async function runConfirmTurn({
|
|
|
2500
2385
|
ok: true, stop: null, rounds: round,
|
|
2501
2386
|
accepted: {
|
|
2502
2387
|
goal: String(r.plan.goal ?? ''), checks: [...(r.plan.checks ?? [])], checkItems: [...(r.plan.checkItems ?? [])], protections: [...protections],
|
|
2503
|
-
lang: resolvedLang, worseThanBefore,
|
|
2388
|
+
lang: resolvedLang, worseThanBefore, ...(goalOnly ? { goalOnly: true } : {}),
|
|
2504
2389
|
// every question forced above was answered in order, so what's left
|
|
2505
2390
|
// unresolved is honestly empty — computed FROM questionsFromPlan
|
|
2506
2391
|
// rather than a hardcoded `[]`, so this stays true if the forcing
|
|
@@ -2521,7 +2406,7 @@ export async function runConfirmTurn({
|
|
|
2521
2406
|
ok: true, stop: null, rounds: round,
|
|
2522
2407
|
accepted: {
|
|
2523
2408
|
goal: redactSecrets(String(typed).trim()), checks: [...(r.plan.checks ?? [])], checkItems: [...(r.plan.checkItems ?? [])], protections: [...protections],
|
|
2524
|
-
lang: resolvedLang, worseThanBefore,
|
|
2409
|
+
lang: resolvedLang, worseThanBefore, ...(goalOnly ? { goalOnly: true } : {}),
|
|
2525
2410
|
openQuestions: questionsFromPlan(r.plan).slice(answeredQuestions.length),
|
|
2526
2411
|
notChecked: [...notChecked], answeredQuestions,
|
|
2527
2412
|
},
|
|
@@ -2543,7 +2428,7 @@ export async function runConfirmTurn({
|
|
|
2543
2428
|
ok: true, stop: null, rounds: round,
|
|
2544
2429
|
accepted: {
|
|
2545
2430
|
goal: String(r.plan.goal ?? ''), checks: [...(r.plan.checks ?? [])], checkItems: [...(r.plan.checkItems ?? [])], protections: [...protections],
|
|
2546
|
-
lang: resolvedLang, worseThanBefore, openQuestions: [...questionsFromPlan(r.plan), redactedFix], notChecked: [...notChecked],
|
|
2431
|
+
lang: resolvedLang, worseThanBefore, ...(goalOnly ? { goalOnly: true } : {}), openQuestions: [...questionsFromPlan(r.plan), redactedFix], notChecked: [...notChecked],
|
|
2547
2432
|
},
|
|
2548
2433
|
reds: [], cost: book.report(),
|
|
2549
2434
|
};
|
|
@@ -2602,7 +2487,7 @@ export async function runConfirmTurn({
|
|
|
2602
2487
|
* priorCalls?: {label: string, costUsd: number|null, unpricedRounds: number}[]|null,
|
|
2603
2488
|
* priorRaws?: any[]|null,
|
|
2604
2489
|
* jobLines?: {n: number, text: string}[]|null, inputs?: {n: number, label: string, value: string}[]|null,
|
|
2605
|
-
* offerQuestions?: boolean,
|
|
2490
|
+
* offerQuestions?: boolean, ticket?: boolean, block?: CheckBlock|null, editGenerate?: Function|null,
|
|
2606
2491
|
* confirmed?: {checks: string[], checkItems?: {text: string, fromLine: number[]|null}[], protections: string[], openQuestions?: string[], notChecked?: string[], answeredQuestions?: string[]}|null}} o
|
|
2607
2492
|
*/
|
|
2608
2493
|
export async function authorClose({
|
|
@@ -2644,6 +2529,13 @@ export async function authorClose({
|
|
|
2644
2529
|
// full drafting ladder (the author call plus both revisions), and only after the two before it both failed validation,
|
|
2645
2530
|
// is offered the optional `questions` property — see `askOpen` below. Absent = byte-identical to today.
|
|
2646
2531
|
offerQuestions = false,
|
|
2532
|
+
// MCP + tickets piece 2 (R5): the job reads tickets, so the drafter is told about the ticket filter, the schema offers the optional `ticketFilter` property and a proposal is
|
|
2533
|
+
// checked by the one reader (src/ticketfilter.js). ABSENT = every other job: prompt, schema and validation byte-identical.
|
|
2534
|
+
ticket = false,
|
|
2535
|
+
// the rubric job's CheckBlock (src/checkblock.js), built before the first try: the AI sends row edits, code builds every check and assembles the declaration from the rows. ABSENT = every other caller.
|
|
2536
|
+
block = null,
|
|
2537
|
+
// the row-edit turn's own model boundary (ROW_EDIT_SYSTEM); a test that replaces `generate` need not bring one
|
|
2538
|
+
editGenerate = null,
|
|
2647
2539
|
}) {
|
|
2648
2540
|
// PART 1a: the menu this close may draw from — a rubric job on local files sees its own two kinds, a code job never sees
|
|
2649
2541
|
// the rubric-only ones (`catalogueForLang`). Everything below (prompt, schema, validator, env) reads THIS one catalogue.
|
|
@@ -2815,15 +2707,51 @@ export async function authorClose({
|
|
|
2815
2707
|
let labelLists = null;
|
|
2816
2708
|
if (lang === RUBRIC_LANG && Array.isArray(inputs) && inputs.length > 0) {
|
|
2817
2709
|
const frozen = await readFrozenInputs(workdir, inputs.map((i) => i.label));
|
|
2818
|
-
if (frozen.ok) { inputTexts = frozen.texts; labelLists =
|
|
2710
|
+
if (frozen.ok) { inputTexts = frozen.texts; labelLists = labelListsFor(frozen.texts, facts?.look ?? null); }
|
|
2819
2711
|
}
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2712
|
+
// every rubric job drafts through the check block (src/authorjob.js builds it, with the person's answers applied); a caller that brings none (a direct authorClose call) gets the block of the look alone, nobody to ask
|
|
2713
|
+
if (block === null && lang === RUBRIC_LANG && inputTexts !== null && Array.isArray(jobLines)) {
|
|
2714
|
+
block = new CheckBlock({ texts: inputTexts, labels: (inputs ?? []).map((/** @type {any} */ i) => i.label), asks: false });
|
|
2715
|
+
block.fromJob(jobLines);
|
|
2716
|
+
block.addLook(Array.isArray(facts?.look?.facts) ? facts.look.facts : [], Array.isArray(facts?.look?.dropped) ? facts.look.dropped : []);
|
|
2717
|
+
block.reconcile();
|
|
2718
|
+
}
|
|
2719
|
+
/** the row-edit turn replaces the drafter's declaration for a rubric job: the model boundary and the declaration code assembles from the block's rows */
|
|
2720
|
+
const rowEdits = block !== null && lang === RUBRIC_LANG;
|
|
2721
|
+
const draftGenerate = rowEdits && editGenerate ? editGenerate : generate;
|
|
2722
|
+
/** the declaration of a rubric job, assembled by code from the rows: the mandatory guards, then the block's stages (hamr 2026-11-12, ruling 6), the rule rows no check carries as `refused`, the picks code recorded */
|
|
2723
|
+
const assemble = () => {
|
|
2724
|
+
const c = /** @type {CheckBlock} */ (block).reconcile();
|
|
2725
|
+
/** @type {{line: number, rule?: number, reason: string}[]} */
|
|
2726
|
+
const refused = /** @type {CheckBlock} */ (block).rows.filter((r) => r.kind === 'rule' && r.state !== 'built').map((r) => ({ line: r.line, rule: r.rule, reason: String(r.reason ?? 'not checked') }));
|
|
2727
|
+
// a job line no check could be built for (no stage) is refused as a line, in code's plain words, so the draft gate sees it covered and the end check (hasBuiltCheck) can say "no check" in its own words
|
|
2728
|
+
for (const l of jobLines ?? []) if (!c.stages.some((/** @type {any} */ st) => Array.isArray(st.fromLine) && st.fromLine.includes(l.n))) refused.push({ line: l.n, reason: REASON.noRule });
|
|
2729
|
+
const picks = /** @type {CheckBlock} */ (block).picksOf(c);
|
|
2730
|
+
// a guard's one fill slot (`allowPrefixes`) is the signed write fence, the very value the old drafter was told to copy: for a rubric job the run writes only under output/
|
|
2731
|
+
const fence = Array.isArray(writeScope) && writeScope.length ? [...writeScope] : ['output/'];
|
|
2732
|
+
return { stages: [...guards.map((/** @type {any} */ g) => ({ name: g.name, kind: g.kind, params: { ...g.params, ...Object.fromEntries((g.fill ?? []).map((/** @type {string} */ f) => [f, fence])) } })), ...c.stages], ...(refused.length ? { refused } : {}), ...(picks.length ? { picks } : {}) };
|
|
2733
|
+
};
|
|
2734
|
+
const prompt = rowEdits
|
|
2735
|
+
? rowEditUserText({ jobLines: jobLines ?? [], look: facts?.look ?? null, texts: inputTexts ?? {} }) + (ticket ? `\n\n${ticketFilterBlock()}` : '')
|
|
2736
|
+
: authorPrompt({
|
|
2737
|
+
answers, questions, facts, listingBlock: /** @type {string} */ (seeds.block),
|
|
2738
|
+
lang, verdictType, guards, ownedEnvNames, mode: structuredMode, catalogue, writeScope, confirmed, jobLines, inputs,
|
|
2739
|
+
labelLists,
|
|
2740
|
+
}) + (ticket ? `\n\n${ticketFilterBlock()}` : '');
|
|
2741
|
+
// the draft gate on one settled declaration: validation, then (PART 1c, rubric) code proves, at $0, that every label is PICKED from the input's own list and every word a fact depends
|
|
2742
|
+
// on is really in the source (white-space blind, once is enough). A word that is not found is a red naming the word and the input; the drafter revises like it does for any validation red.
|
|
2743
|
+
const checkDraft = (/** @type {any} */ d) => {
|
|
2744
|
+
let r = validateDeclaration(d, { catalogue, listing: seedFiles, guards, envOwned: ownedEnvNames, verdictType, writeScope, jobLines, inputLabels: inputLabelsOf(inputs) });
|
|
2745
|
+
if (r.ok && lang === RUBRIC_LANG) {
|
|
2746
|
+
const words = checkDeclarationWords(r.declaration, inputTexts, facts?.look ?? null);
|
|
2747
|
+
if (words.length > 0) r = { ...r, ok: false, reds: [...r.reds, ...words], declaration: null };
|
|
2748
|
+
}
|
|
2749
|
+
return r;
|
|
2750
|
+
};
|
|
2825
2751
|
/** @type {any[]} */
|
|
2826
2752
|
let messages = [{ role: 'user', content: prompt }];
|
|
2753
|
+
/** the drafter's PROPOSED ticket filter of the accepted iteration (a Tickets job only); the person signs it, the spec carries it, the close never does @type {any} */
|
|
2754
|
+
let acceptedTicketFilter;
|
|
2827
2755
|
/** @type {any[]} */
|
|
2828
2756
|
const iterations = [];
|
|
2829
2757
|
/** @type {any} */
|
|
@@ -2907,8 +2835,19 @@ export async function authorClose({
|
|
|
2907
2835
|
// P7 item 5: a mechanism, never a wish. Only the last try of the full ladder carries the property, and only when the
|
|
2908
2836
|
// two before it both failed (validation or the seed read; `questionLines` is set at the end of the second one, below).
|
|
2909
2837
|
const askOpen = questionLines !== null && i === revisionCap;
|
|
2910
|
-
const ask =
|
|
2838
|
+
const ask = rowEdits
|
|
2839
|
+
? { ...(await askStructured({ messages, generate: draftGenerate, mode: structuredMode, retries: retryCap, label, book, channel: rowEditChannel(ticket) })), declaration: null }
|
|
2840
|
+
: await askDeclaration({ messages, generate, mode: structuredMode, retries: retryCap, label, book, catalogue: catalogueIn, kinds: Object.keys(catalogue), verdictType, questions: askOpen, ticket });
|
|
2841
|
+
if (rowEdits) ask.declaration = ask.artifact;
|
|
2911
2842
|
messages = ask.convo;
|
|
2843
|
+
// `ticketFilter` is never part of the declaration (the close): taken out before validation, checked by its own reader below, and kept beside the declaration
|
|
2844
|
+
/** @type {any} */
|
|
2845
|
+
let proposedFilter;
|
|
2846
|
+
if (ticket && ask.declaration && typeof ask.declaration === 'object' && Object.hasOwn(ask.declaration, 'ticketFilter')) {
|
|
2847
|
+
const { ticketFilter: tf, ...restDecl } = ask.declaration;
|
|
2848
|
+
proposedFilter = tf;
|
|
2849
|
+
ask.declaration = restDecl;
|
|
2850
|
+
}
|
|
2912
2851
|
/** @type {{reason: string, raw: any}[]} */
|
|
2913
2852
|
let droppedQuestions = [];
|
|
2914
2853
|
if (askOpen && ask.declaration && typeof ask.declaration === 'object' && Object.hasOwn(ask.declaration, 'questions')) {
|
|
@@ -2990,22 +2929,38 @@ export async function authorClose({
|
|
|
2990
2929
|
// early stop: an unchanged declaration has the previous iteration's
|
|
2991
2930
|
// measurements by definition — re-executing it buys nothing and costs a
|
|
2992
2931
|
// full close
|
|
2993
|
-
if (previous && canonical(ask.declaration) === canonical(previous)) {
|
|
2932
|
+
if (previous && canonical({ d: ask.declaration, f: proposedFilter ?? null }) === canonical(previous)) {
|
|
2994
2933
|
iter.validation = '(identical declaration — see the previous iteration)';
|
|
2995
2934
|
iter.seedRead = '(identical declaration — see the previous iteration)';
|
|
2996
2935
|
stop = 'unchanged';
|
|
2997
2936
|
break;
|
|
2998
2937
|
}
|
|
2999
|
-
previous = ask.declaration;
|
|
3000
|
-
|
|
3001
|
-
//
|
|
3002
|
-
let
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
2938
|
+
previous = { d: ask.declaration, f: proposedFilter ?? null };
|
|
2939
|
+
|
|
2940
|
+
// a rubric job: ONE reply of row edits, each judged alone by the block; the declaration is assembled from the rows (a refused edit costs the others nothing)
|
|
2941
|
+
let pre = ask.declaration;
|
|
2942
|
+
/** @type {any[]} */
|
|
2943
|
+
let refusedEdits = [];
|
|
2944
|
+
if (rowEdits) {
|
|
2945
|
+
const rec = /** @type {CheckBlock} */ (block).applyDelta({ label, edits: editsOf(ask.declaration) });
|
|
2946
|
+
refusedEdits = rec.edits.filter((/** @type {any} */ e) => e.accepted !== true);
|
|
2947
|
+
pre = assemble();
|
|
2948
|
+
iter.edits = rec.edits.map((/** @type {any} */ e) => ({ op: e?.op, accepted: e.accepted === true, ...(e.accepted === true ? {} : { refusedBecause: e.refusedBecause }) }));
|
|
2949
|
+
onPhase('draft-ledger-try', { label, kept: rec.edits.length - refusedEdits.length, refused: refusedEdits.map((/** @type {any} */ e) => ({ op: String(e?.op), reason: String(e.refusedBecause) })) });
|
|
2950
|
+
}
|
|
2951
|
+
let v = checkDraft(pre);
|
|
2952
|
+
// a gate red on the code-built declaration is OUR bug (hamr 2026-11-12, ruling 3): the plan stops in plain words, the AI is never asked to fix it
|
|
2953
|
+
if (rowEdits && !v.ok) {
|
|
2954
|
+
fatal = [{ code: 'plan-red', path: 'closeDecl', detail: `The plan code built from your checks did not pass its own gate (${v.reds.slice(0, 2).map((/** @type {Red} */ r) => `${r.code} at ${r.path || '(root)'}: ${r.detail}`).join('; ')}). That is a fault in the build, not in your job: nothing was spent on a close.` }];
|
|
2955
|
+
stop = 'plan-red';
|
|
2956
|
+
iter.validation = { ok: false, reds: v.reds.map(scrubRed), scoped: v.scoped };
|
|
2957
|
+
lastValidation = { ok: false, reds: v.reds.map(scrubRed) };
|
|
2958
|
+
break;
|
|
2959
|
+
}
|
|
2960
|
+
// MCP + tickets piece 2: a proposed ticket filter is read by the ONE reader (src/ticketfilter.js); its reds carry a legal example and go back to the drafter like any red
|
|
2961
|
+
if (v.ok && ticket && proposedFilter !== undefined) {
|
|
2962
|
+
const fr = ticketFilterReds(proposedFilter);
|
|
2963
|
+
if (fr.length > 0) v = { ...v, ok: false, reds: [...v.reds, ...fr], declaration: null };
|
|
3009
2964
|
}
|
|
3010
2965
|
// SCRUBBED HERE, once, where the reds enter this module's records — the same
|
|
3011
2966
|
// boundary rule `renderRejectBlock` already states, applied to the OTHER
|
|
@@ -3022,6 +2977,7 @@ export async function authorClose({
|
|
|
3022
2977
|
|
|
3023
2978
|
/** @type {string} */
|
|
3024
2979
|
let measured;
|
|
2980
|
+
let seedFailed = false;
|
|
3025
2981
|
if (!v.ok) {
|
|
3026
2982
|
// a validation red IS a measurement of the declaration, so it rides the
|
|
3027
2983
|
// same channel and counts as a revision (addendum 5)
|
|
@@ -3053,12 +3009,14 @@ export async function authorClose({
|
|
|
3053
3009
|
onPhase('seed-read-done', { call: label, stages: stageCount });
|
|
3054
3010
|
iter.seedRead = rows;
|
|
3055
3011
|
accepted = injected.declaration;
|
|
3012
|
+
acceptedTicketFilter = proposedFilter;
|
|
3056
3013
|
acceptedSeedRead = rows;
|
|
3057
3014
|
finalFrom = label;
|
|
3058
3015
|
measured = renderSeedReadBlock(rows);
|
|
3059
3016
|
measuredIterations.push({ label, declaration: injected.declaration, seedRead: rows, droppedEnv: injected.dropped });
|
|
3060
3017
|
const sf = seedReadFailure(rows, injected.declaration, guards.map((/** @type {any} */ g) => g.name), (jobLines ?? []).map((l) => l.n));
|
|
3061
3018
|
tryFails[i] = sf.failed ? { lines: sf.lines } : null;
|
|
3019
|
+
seedFailed = sf.failed;
|
|
3062
3020
|
if (sf.failed) {
|
|
3063
3021
|
const guardNames = guards.map((/** @type {any} */ g) => g.name);
|
|
3064
3022
|
const stoppedNames = [...new Set(rows.filter((/** @type {any} */ r) => !guardNames.includes(r?.stage) && r?.verdict === 'instrument-stop').map((/** @type {any} */ r) => String(r.stage)))];
|
|
@@ -3071,6 +3029,8 @@ export async function authorClose({
|
|
|
3071
3029
|
}
|
|
3072
3030
|
}
|
|
3073
3031
|
|
|
3032
|
+
// hamr 2026-11-12 (ruling 3): a rubric job revises only when the last reply had refused edits OR the seed read failed; else the plan stands
|
|
3033
|
+
if (rowEdits && v.ok && refusedEdits.length === 0 && !seedFailed) { stop = 'settled'; break; }
|
|
3074
3034
|
if (i === revisionCap) { stop = 'max-revisions'; break; }
|
|
3075
3035
|
|
|
3076
3036
|
// P7 item 5: the NEXT try is the last of a full ladder, and this one AND the first both FAILED — either failed validation
|
|
@@ -3081,6 +3041,16 @@ export async function authorClose({
|
|
|
3081
3041
|
questionLines = second && second.lines.length ? second.lines : null;
|
|
3082
3042
|
}
|
|
3083
3043
|
|
|
3044
|
+
if (rowEdits) {
|
|
3045
|
+
// the revise turn carries each refused edit's own reason, and the seed read when it failed, and nothing else
|
|
3046
|
+
const blocks = [];
|
|
3047
|
+
if (refusedEdits.length) blocks.push(renderRejectBlock({ kind: 'edits', reds: refusedEdits.map((/** @type {any} */ e) => `edit ${String(e?.op)}: ${String(e.refusedBecause)}`) }));
|
|
3048
|
+
blocks.push(v.ok ? (seedFailed ? measured : '') : measured);
|
|
3049
|
+
const editTurn = `${blocks.filter(Boolean).join('\n\n')}\n\n${ROW_EDIT_REVISE}`;
|
|
3050
|
+
iter.reviseTurn = { bytes: Buffer.byteLength(editTurn) };
|
|
3051
|
+
messages = [...messages, { role: 'assistant', content: ask.raw.trim() || '(the reply carried no text)' }, { role: 'user', content: editTurn }];
|
|
3052
|
+
continue;
|
|
3053
|
+
}
|
|
3084
3054
|
const turn = buildReviseTurn(measured);
|
|
3085
3055
|
// A TRIPWIRE, not behaviour: it can only fire once something else is
|
|
3086
3056
|
// already broken, so it is the one guard in this module the mutation
|
|
@@ -3113,7 +3083,7 @@ export async function authorClose({
|
|
|
3113
3083
|
// it by reading only `declaration`/`seedRead`/`finalFrom`.
|
|
3114
3084
|
/** @type {{from: string, to: string, brokenStages: string[]}|null} */
|
|
3115
3085
|
let fellBack = null;
|
|
3116
|
-
if (measuredIterations.length) {
|
|
3086
|
+
if (measuredIterations.length && !rowEdits) {
|
|
3117
3087
|
const last = measuredIterations[measuredIterations.length - 1];
|
|
3118
3088
|
if (!isSoundMeasurement(last.seedRead)) {
|
|
3119
3089
|
for (let k = measuredIterations.length - 2; k >= 0; k -= 1) {
|
|
@@ -3134,6 +3104,12 @@ export async function authorClose({
|
|
|
3134
3104
|
}
|
|
3135
3105
|
}
|
|
3136
3106
|
|
|
3107
|
+
// PRD v1.131 tick 7: ONE retention record when a rubric draft ends (accepted or stopped), counts only; the panel writes it into the drafting log. Read from the block's rows.
|
|
3108
|
+
if (rowEdits) {
|
|
3109
|
+
onPhase('draft-retention', { lines: /** @type {CheckBlock} */ (block).retention() });
|
|
3110
|
+
onPhase('draft-ledger', { rows: ledgerRecord(/** @type {any} */ (block).rows) });
|
|
3111
|
+
}
|
|
3112
|
+
|
|
3137
3113
|
const reds = fatal.length ? fatal : (lastValidation && !lastValidation.ok ? lastValidation.reds : []);
|
|
3138
3114
|
return {
|
|
3139
3115
|
// `ok` means A SIGNABLE CLOSE EXISTS, and nothing more. A dead socket on a
|
|
@@ -3143,6 +3119,7 @@ export async function authorClose({
|
|
|
3143
3119
|
// Why the loop ended is never hidden: `stop` names it and `reds` carries it.
|
|
3144
3120
|
ok: accepted !== null,
|
|
3145
3121
|
declaration: accepted,
|
|
3122
|
+
...(ticket && acceptedTicketFilter !== undefined ? { ticketFilter: acceptedTicketFilter } : {}),
|
|
3146
3123
|
seedRead: acceptedSeedRead,
|
|
3147
3124
|
iterations,
|
|
3148
3125
|
reds,
|
|
@@ -3165,6 +3142,8 @@ export async function authorClose({
|
|
|
3165
3142
|
stop,
|
|
3166
3143
|
// P7 item 5: what the person is asked (empty on every other stop)
|
|
3167
3144
|
questions: stop === 'questions-open' ? askedQuestions : [],
|
|
3145
|
+
// the one check list's final rows against the declaration that stands (the signed close carries them as `closeDecl.list`); null = no list
|
|
3146
|
+
ledger: rowEdits && accepted !== null ? /** @type {CheckBlock} */ (block).signedRows() : null,
|
|
3168
3147
|
revisions: Math.max(0, iterations.length - 1),
|
|
3169
3148
|
};
|
|
3170
3149
|
}
|