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
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
} from 'node:fs';
|
|
28
28
|
import { join, resolve, dirname } from 'node:path';
|
|
29
29
|
import {
|
|
30
|
-
prepareSource, proveDestination, proveRubricInputs, looksLikeRubricInput, missingDependencies, looksLikeRepoSource, nearestGitAncestor, nonRepoSourceMessage,
|
|
30
|
+
prepareSource, proveDestination, proveRubricInputs, looksLikeRubricInput, missingDependencies, looksLikeRepoSource, nearestGitAncestor, nonRepoSourceMessage, destinationMissingInRepo, repoTrackedFiles,
|
|
31
31
|
} from '../source.js';
|
|
32
32
|
import {
|
|
33
33
|
worktreePath, uncommittedCount, shortHead, removeWorktree,
|
|
@@ -42,27 +42,39 @@ import {
|
|
|
42
42
|
import { prepareSigning } from '../authorjob.js';
|
|
43
43
|
import { checkCloseByteSignature } from '../close-integrity.js';
|
|
44
44
|
import {
|
|
45
|
-
questionsFor, requiredAnswersFor, makeLoopGenerate,
|
|
45
|
+
questionsFor, requiredAnswersFor, makeLoopGenerate, confirmSystemFor, SOFTGREEN_JUDGE_EXAMPLES_KEY,
|
|
46
46
|
} from '../authorflow.js';
|
|
47
47
|
import {
|
|
48
48
|
resolveProvider, buildRunnerProviders, apiKeyProblem,
|
|
49
49
|
} from '../providers.js';
|
|
50
50
|
import { resolveJobJudge, defaultJudgeLoop } from '../judged.js';
|
|
51
|
-
import { assertThinkingMode, thinkingPlanFor, thinkingRowText } from '../thinking.js';
|
|
51
|
+
import { assertThinkingMode, thinkingPlanFor, thinkingRowText, thinkingCallOptions } from '../thinking.js';
|
|
52
52
|
import { closeJudges } from '../kinds.js';
|
|
53
53
|
import { RUBRIC_LANG } from '../authoring.js';
|
|
54
|
-
import { rubricGoal,
|
|
54
|
+
import { rubricGoal, cardOfClose, signedFactNames } from '../rubricstep.js';
|
|
55
55
|
import { redactSecrets } from '../validate.js';
|
|
56
|
+
import { FLOW_TYPES } from '../job.js';
|
|
57
|
+
import { mcpPickFor, signFlow } from '../mcppick.js';
|
|
58
|
+
import { parseTicketList, ticketNumberOf, TICKET_NUMBER_WORDS } from '../ticketshape.js';
|
|
56
59
|
import { isDropIt, isAgree, stripAgreeLead } from '../pagemap.js';
|
|
60
|
+
import { plainWords, SUGGEST_SYSTEM, sameRuleWords } from '../checkpick.js';
|
|
61
|
+
import { LEDGER_SYSTEM } from '../checklist.js';
|
|
62
|
+
import { ROW_EDIT_SYSTEM } from '../rowedit.js';
|
|
63
|
+
import { readRecordFile, readRowChoices, writeRecordPart, RECORD_FILE, KEPT_WORDS } from '../pickrecord.js';
|
|
64
|
+
import { MAX_REVISES, draftLabelOf, nextRevisesUsed, sessionsRootOf, writeRevisesUsed } from '../revises.js';
|
|
57
65
|
import { FIT_ABSENT_NOTE } from '../fitcheck.js';
|
|
66
|
+
import { runDestPoint, destQuestionText, yesNoOf } from '../destpoint.js';
|
|
58
67
|
import { tallyCalls } from '../text.js';
|
|
59
|
-
import { appendDraftLog } from '../draftspend.js';
|
|
68
|
+
import { appendDraftLog, readDraftLedger } from '../draftspend.js';
|
|
60
69
|
import { PLAIN_PROPOSAL_STOPS, proposalStopText, signingStopText, draftStopText, redsRecord, declarationRecord, calibrationSummary, tryRefusedText } from '../authorreadout.js';
|
|
61
70
|
import { runNpmCi, NPM_CI_LOCKS } from '../npminstall.js';
|
|
62
71
|
import {
|
|
63
|
-
parseJobBlock, parseInputs, jobBlockFitsCheck, renderJobLines, renderExamples, signedJobLines,
|
|
72
|
+
parseJobBlock, parseInputs, jobBlockFitsCheck, renderJobLines, renderExamples, signedJobLines, jobBoxText,
|
|
64
73
|
} from '../jobblock.js';
|
|
65
74
|
import { planFromConfirm } from './jobplan.js';
|
|
75
|
+
import { boxFor, offersOf, panelQuestionText, refuseChoice, resolveChoice } from '../questionbox.js';
|
|
76
|
+
import { isTicketTrigger } from '../trigger.js';
|
|
77
|
+
import { ticketLookOf } from '../ticketschedule.js';
|
|
66
78
|
|
|
67
79
|
/**
|
|
68
80
|
* THE PROGRESS LIST's one table (hamr 2026-10-04, "one place showing all"): every pipeline step the left Chat panel
|
|
@@ -170,7 +182,7 @@ export const PLAN_FOOTER = 'Sign & run to confirm this plan, or Revise to edit t
|
|
|
170
182
|
* The confirm turn's plan as a chat message (P7): a STRUCTURED `{role:'bot', kind:'plan', plan}` the page draws with the
|
|
171
183
|
* same renderer the Job tab uses — each numbered job line, its `~` rule, its drafted checks folded; the AI's own "not
|
|
172
184
|
* checked"; the always-on guards. `questions` (what the plan still asks) ride inside the plan. One owner of the shape.
|
|
173
|
-
* @param {{goal?: string, checks?: string[], checkItems?: {text: string, fromLine: number[]|null}[], notChecked?: string[], questions?: string[], protections?: string[], signedFacts?: string[]}} p the confirm turn's plan
|
|
185
|
+
* @param {{goal?: string, checks?: string[], checkItems?: {text: string, fromLine: number[]|null, by?: 'agent'|'you'|'default'|null, key?: string}[], notChecked?: string[], notCheckedBy?: Record<string, 'you'|'agent'|'default'>, suggested?: {key: string, line: number, text: string}[], editable?: boolean, questions?: string[], protections?: string[], signedFacts?: string[], ticketFilter?: any, picked?: {line: number, text: string}[]}} p the confirm turn's plan
|
|
174
186
|
* @param {{n: number, text: string, rule: string}[]|null} jobLines
|
|
175
187
|
* @returns {{role: 'bot', kind: 'plan', text: string, plan: ReturnType<typeof planFromConfirm> & {goal: string, questions: string[]}}}
|
|
176
188
|
*/
|
|
@@ -224,7 +236,7 @@ export function nextFreeJobName(origin, runJobs, opts = {}) {
|
|
|
224
236
|
}
|
|
225
237
|
|
|
226
238
|
/** the form's fields, in card order — what `card.json` stores, verbatim (P5 item 3) */
|
|
227
|
-
export const CARD_FIELDS = Object.freeze(['jobName', 'checkType', 'provider', 'model', 'thinking', 'jobText', 'inputs', 'destination', 'capUsd', 'maxWallMs']);
|
|
239
|
+
export const CARD_FIELDS = Object.freeze(['jobName', 'checkType', 'provider', 'model', 'thinking', 'jobText', 'inputs', 'destination', 'capUsd', 'maxWallMs', 'flowType', 'mcp', 'ticket', 'schedule']);
|
|
228
240
|
|
|
229
241
|
/**
|
|
230
242
|
* The repo a card names: Inputs line 1 (P7 — the Source box is gone; the first input IS the repo). `''` when the Inputs
|
|
@@ -255,7 +267,53 @@ export function cardFields(card) {
|
|
|
255
267
|
* `~` rules, `~ PASS`/`~ FAIL`), the check type and the thinking tick. The RUN boxes (Inputs, Destination, Model, $ cap, Time cap)
|
|
256
268
|
* never decide it. A green origin with no job box changed reuses the signed plan verbatim (no drafting); anything else drafts.
|
|
257
269
|
*/
|
|
258
|
-
export const JOB_BOXES = Object.freeze(['jobText', 'checkType', 'thinking']);
|
|
270
|
+
export const JOB_BOXES = Object.freeze(['jobText', 'checkType', 'thinking', 'flowType', 'mcp']);
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* The card's flow type and MCP, normalised: a card with no `flowType` (or `plain`) is plain with no MCP; any other pick keeps its server name.
|
|
274
|
+
* @param {any} card @returns {{flowType: 'plain'|'mcp'|'tickets', mcp: string}}
|
|
275
|
+
*/
|
|
276
|
+
export function flowOfCard(card) {
|
|
277
|
+
const t = card?.flowType;
|
|
278
|
+
if (t !== 'mcp' && t !== 'tickets') return { flowType: 'plain', mcp: '' };
|
|
279
|
+
return { flowType: t, mcp: typeof card?.mcp === 'string' ? card.mcp.trim() : '' };
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* ITEM33-BUILD piece 8: what the card's Flow type and MCP become, decided at $0 before any session (nothing is started, no server runs). A plain card is `{flowType:'plain', pick:null}`.
|
|
284
|
+
* An MCP or Tickets card needs a server named in Settings > MCP and that server's newest successful `check tools` (`mcpPickFor`: ALL its tools, set by code); an unknown flow type, no pick, a
|
|
285
|
+
* never-checked MCP and a Tickets card with no ticket-list Inputs line are refused in plain words.
|
|
286
|
+
* @param {any} card @param {{ home?: string, mcpHome?: string }} [o]
|
|
287
|
+
* @returns {{ok: true, flowType: 'plain'|'mcp'|'tickets', pick: {server: string, tools: string[]}|null} | {ok: false, error: string}}
|
|
288
|
+
*/
|
|
289
|
+
export function resolveFlowCard(card, o = {}) {
|
|
290
|
+
if (card?.flowType !== undefined && !FLOW_TYPES.includes(card.flowType)) return { ok: false, error: `Flow type must be one of ${FLOW_TYPES.join(', ')}.` };
|
|
291
|
+
const { flowType, mcp } = flowOfCard(card);
|
|
292
|
+
if (flowType === 'plain') return { ok: true, flowType, pick: null };
|
|
293
|
+
if (mcp === '') return { ok: false, error: 'Pick an MCP.' };
|
|
294
|
+
const pick = mcpPickFor(mcp, o);
|
|
295
|
+
if (!pick.ok) return { ok: false, error: pick.say };
|
|
296
|
+
if (flowType === 'tickets') {
|
|
297
|
+
const ip = parseInputs(card.inputs);
|
|
298
|
+
if (ip.ok && !ip.inputs.some((i) => parseTicketList(i.value).ok)) {
|
|
299
|
+
return { ok: false, error: 'Tickets MCP needs the ticket list address (the issues or pulls page of one repository) as an Inputs line.' };
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
return { ok: true, flowType, pick: { server: pick.server, tools: pick.tools } };
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* The by-hand ticket of a Tickets MCP run (ITEM33-BUILD piece 8): the number typed on the card, the same number `--ticket` takes, or BLANK = the newest ticket this job has not run
|
|
307
|
+
* (R6: `run-u` finds it with the schedule's own look, src/ticketnext.js, and a list that cannot be looked at says so and asks for a number). Any other job takes none.
|
|
308
|
+
* @param {any} card @param {'plain'|'mcp'|'tickets'} flowType the FINAL flow type of the job (the card's, or the reused spec's)
|
|
309
|
+
* @returns {string|null} the refusal in plain words, or null when the card is fine
|
|
310
|
+
*/
|
|
311
|
+
export function ticketBoxProblem(card, flowType) {
|
|
312
|
+
const typed = typeof card?.ticket === 'string' ? card.ticket.trim() : (typeof card?.ticket === 'number' ? String(card.ticket) : '');
|
|
313
|
+
if (flowType !== 'tickets') return typed === '' ? null : 'A ticket number is only for a Tickets MCP job. Clear the Ticket box.';
|
|
314
|
+
if (typed === '') return null;
|
|
315
|
+
return ticketNumberOf(typed) === undefined ? `The ticket must be ${TICKET_NUMBER_WORDS}, not "${typed}".` : null;
|
|
316
|
+
}
|
|
259
317
|
|
|
260
318
|
/**
|
|
261
319
|
* Did any JOB box on `card` change from what the origin run prefilled (`origin`)? Whitespace is not compared (a one-line input drops
|
|
@@ -267,6 +325,8 @@ export const JOB_BOXES = Object.freeze(['jobText', 'checkType', 'thinking']);
|
|
|
267
325
|
export function jobBoxesChanged(card, origin) {
|
|
268
326
|
const text = (/** @type {any} */ v) => (typeof v === 'string' ? v.replace(/\s+/g, '') : '');
|
|
269
327
|
return text(card?.jobText) !== text(origin?.jobText)
|
|
328
|
+
|| flowOfCard(card).flowType !== flowOfCard(origin).flowType
|
|
329
|
+
|| flowOfCard(card).mcp !== flowOfCard(origin).mcp
|
|
270
330
|
|| (card?.checkType === 'rubric') !== (origin?.checkType === 'rubric')
|
|
271
331
|
|| (card?.thinking === true) !== (origin?.thinking === true);
|
|
272
332
|
}
|
|
@@ -335,6 +395,9 @@ export { nonRepoSourceMessage };
|
|
|
335
395
|
/** the refusal for a plain-files rubric job whose Destination is not an absolute folder (ends with the words the session start shows) */
|
|
336
396
|
export const FILES_DESTINATION_WORDS = 'Destination must be the full path of a folder, like /home/me/out — the finished files are delivered there. Nothing spent.';
|
|
337
397
|
|
|
398
|
+
/** the fixed example of a Destination refusal (code-owned; it never guesses a folder from the job's words) */
|
|
399
|
+
export const DESTINATION_HINT = 'Type the folder that holds the files the job should change, like src/.';
|
|
400
|
+
|
|
338
401
|
/**
|
|
339
402
|
* THE ONE Destination check of a session start, at $0, before any session, copy or model call. The session's own pipeline, the HTTP
|
|
340
403
|
* start (`startSession`), the schedule's two clicks and a scheduled fire's `wouldAccept` all call THIS (never a copy of it), so a start
|
|
@@ -349,6 +412,12 @@ export function startDestinationProblem(card) {
|
|
|
349
412
|
const isRepoLike = looksLikeRepoSource(source);
|
|
350
413
|
const repo = repoDestinationProblem(destination, isRepoLike);
|
|
351
414
|
if (repo !== null) return repo;
|
|
415
|
+
// R7b (F287): a repo's Destination is the write fence, so every piece of it must name something the repo really has (its committed tree: what the job's copy holds)
|
|
416
|
+
if (isRepoLike) {
|
|
417
|
+
const root = nearestGitAncestor(resolve(source))?.dir;
|
|
418
|
+
const missing = root === undefined ? null : destinationMissingInRepo(root, destination);
|
|
419
|
+
if (missing !== null) return `Destination \`${missing}\` is not a folder or file in this repo. ${DESTINATION_HINT}`;
|
|
420
|
+
}
|
|
352
421
|
if (card?.checkType === 'rubric' && !isRepoLike && !isAbsoluteDestination(destination)) return FILES_DESTINATION_WORDS;
|
|
353
422
|
return null;
|
|
354
423
|
}
|
|
@@ -407,8 +476,8 @@ export function validateJobCard(card, opts = {}) {
|
|
|
407
476
|
* `signPrepare()` are the only ways in.
|
|
408
477
|
* @param {any} card the validated job card (see {@link validateJobCard})
|
|
409
478
|
* @param {{env?: Record<string,string|undefined>, sessionsRoot?: string, home?: string, timeoutMs?: number,
|
|
410
|
-
* scout?: any, generate?: Function, confirmGenerate?: Function, authorFn?: Function,
|
|
411
|
-
* prepareSigningFn?: Function, npmCiFn?: Function, lookFn?: Function|null, fitFn?: Function|null, fetchUrl?: (url: string) => Promise<{ok: true, text: string, url: string}|{ok: false, error: string}>, draftThinking?: "on"|"off", reuse?: {spec: any, workflowKey: string}}} [deps] `scout`..`prepareSigningFn` are
|
|
479
|
+
* scout?: any, generate?: Function, pickGenerate?: Function|null, ledgerGenerate?: Function|null, editGenerate?: Function|null, carryFrom?: string, carryKind?: string, confirmGenerate?: Function, authorFn?: Function,
|
|
480
|
+
* prepareSigningFn?: Function, npmCiFn?: Function, lookFn?: Function|null, fitFn?: Function|null, destFn?: Function|null, fetchUrl?: (url: string) => Promise<{ok: true, text: string, url: string}|{ok: false, error: string}>, draftThinking?: "on"|"off", reuse?: {spec: any, workflowKey: string}, schedule?: import('../trigger.js').Trigger|null, flow?: {flowType: 'plain'|'mcp'|'tickets', pick: {server: string, tools: string[]}|null}}} [deps] `scout`..`prepareSigningFn` are
|
|
412
481
|
* TEST SEAMS ONLY — see the note just above where each is read, below. `reuse` (Reuse workflow) is NOT a seam: the
|
|
413
482
|
* caller (`/api/author/start`) sets it only when the server's own same-job rule held.
|
|
414
483
|
* @returns {any} the session object
|
|
@@ -426,7 +495,7 @@ export function createSession(card, deps = {}) {
|
|
|
426
495
|
const INPUTS = inputsParsed.ok ? inputsParsed.inputs : [];
|
|
427
496
|
/** the repo — Inputs line 1 */
|
|
428
497
|
const SOURCE = INPUTS[0]?.value ?? '';
|
|
429
|
-
const sessionsRoot = deps.sessionsRoot
|
|
498
|
+
const sessionsRoot = sessionsRootOf(deps.sessionsRoot);
|
|
430
499
|
// config.json lives beside the sessions dir (~/.config/bareloop) unless a home is injected
|
|
431
500
|
const configHome = deps.home ?? dirname(sessionsRoot);
|
|
432
501
|
const timeoutMs = deps.timeoutMs ?? 300_000;
|
|
@@ -442,13 +511,31 @@ export function createSession(card, deps = {}) {
|
|
|
442
511
|
const id = `s${Date.now().toString(36)}${Math.random().toString(36).slice(2, 6)}`;
|
|
443
512
|
const outDir = join(sessionsRoot, id);
|
|
444
513
|
mkdirSync(outDir, { recursive: true });
|
|
514
|
+
// R10 (fwd am17/am18/am20): the picks record of the earlier session this draft follows (a Revise, or a Start over), read from that session's own folder. The id is a session id
|
|
515
|
+
// (never a path); no record, or an unreadable one, is no record: every rule is asked.
|
|
516
|
+
const carriedPicks = typeof deps.carryFrom === 'string' && /^s[a-z0-9]+$/.test(deps.carryFrom) ? readRecordFile(join(sessionsRoot, deps.carryFrom, RECORD_FILE)) : null;
|
|
517
|
+
// hamr 2026-11-13 (N-2): the Drop/Add choices of that same earlier draft ride in the same record file
|
|
518
|
+
const carriedChoices = typeof deps.carryFrom === 'string' && /^s[a-z0-9]+$/.test(deps.carryFrom) ? readRowChoices(join(sessionsRoot, deps.carryFrom, RECORD_FILE)) : null;
|
|
519
|
+
/** the confirm card's Drop/Add door for the plan now waiting (set by `ask`, cleared when it is answered): a row edit through the live check block, $0, no model call @type {((op: 'drop'|'add', key: string) => any)|null} */
|
|
520
|
+
let planEdit = null;
|
|
521
|
+
|
|
522
|
+
// fwd M4e am14 item 3: the revises this draft has used (src/revises.js); the page reads `revisesLeft` to word its button
|
|
523
|
+
const revisesUsed = nextRevisesUsed(sessionsRoot, deps.carryFrom, deps.carryKind);
|
|
524
|
+
writeRevisesUsed(outDir, revisesUsed);
|
|
525
|
+
// fwd am14 item 6: the draft record says which kind of draft this is (a first draft says nothing); the Audit's Draft group reads it back
|
|
526
|
+
const draftLabel = draftLabelOf(deps.carryFrom, deps.carryKind, revisesUsed);
|
|
527
|
+
if (draftLabel !== null) appendDraftLog(outDir, { kind: 'draft-label', no: 0, label: draftLabel, at: new Date().toISOString() });
|
|
445
528
|
|
|
446
529
|
/** @type {any} */
|
|
447
530
|
const state = {
|
|
448
531
|
id,
|
|
532
|
+
revisesUsed,
|
|
533
|
+
revisesLeft: Math.max(0, MAX_REVISES - revisesUsed),
|
|
449
534
|
// the form as submitted + whether it is a reuse session: a refreshed page re-attaches to a live session from these
|
|
450
535
|
card: cardFields(card),
|
|
451
536
|
reuse: deps.reuse !== undefined,
|
|
537
|
+
// R7: the schedule the card asked for (the typed trigger the job is signed with); `signRun` writes it OFF beside the run it starts
|
|
538
|
+
...(deps.schedule ? { schedule: deps.schedule } : {}),
|
|
452
539
|
messages: /** @type {{role: string, text: string}[]} */ ([]),
|
|
453
540
|
pendingAsk: /** @type {any} */ (null),
|
|
454
541
|
cost: /** @type {any} */ (null),
|
|
@@ -523,8 +610,17 @@ export function createSession(card, deps = {}) {
|
|
|
523
610
|
|
|
524
611
|
/** @param {'bot'|'you'|'system'} role @param {string} text */
|
|
525
612
|
const say = (role, text) => { state.messages.push({ role, text }); };
|
|
613
|
+
/** the bot message of the question now open: the panel's question box shows it, so the thread holds it back (`askOpen`) until the question is answered @type {{role: string, text: string, askOpen?: boolean}|null} */
|
|
614
|
+
let openMsg = null;
|
|
615
|
+
const sayOpen = (/** @type {string} */ text) => { openMsg = { role: 'bot', text, askOpen: true }; state.messages.push(openMsg); };
|
|
616
|
+
const closeOpenMsg = () => { if (openMsg) { delete openMsg.askOpen; openMsg = null; } };
|
|
617
|
+
/** the button the person used to answer the question just resolved (`agree`, `drop`, `rule`, ...), or null when they typed words (the CLI, an old page); read once, right after the `await ask(...)` @type {string|null} */
|
|
618
|
+
let answeredChoice = null;
|
|
619
|
+
const takeChoice = () => { const c = answeredChoice; answeredChoice = null; return c; };
|
|
526
620
|
/** a structured message (the plan bubble): the page draws it, the thread keeps it as data */
|
|
527
|
-
|
|
621
|
+
/** the checks the person has agreed so far (their plain words, `kept from last draft` on a carried one): the plan bubble draws each once, as a `[you picked]` row @type {{line: number, text: string}[]} */
|
|
622
|
+
const pickedSoFar = [];
|
|
623
|
+
const sayPlan = (/** @type {any} */ plan) => { state.messages.push(planMessage({ ...plan, ...(pickedSoFar.length ? { picked: [...pickedSoFar] } : {}) }, jobLines)); };
|
|
528
624
|
|
|
529
625
|
/** @type {((value: string|null) => void)|null} */
|
|
530
626
|
let resolvePending = null;
|
|
@@ -554,27 +650,34 @@ export function createSession(card, deps = {}) {
|
|
|
554
650
|
const running = state.steps.findLastIndex((/** @type {any} */ x) => x.status === 'running');
|
|
555
651
|
appendDraftLog(outDir, {
|
|
556
652
|
kind: 'human', no: running === -1 ? Math.max(0, state.steps.length - 1) : running, source: typeof step.source === 'string' ? step.source : 'confirm',
|
|
557
|
-
question: redactSecrets(step.question), answer: said, ...(Number.isInteger(step.line) ? { line: step.line } : {}), at: new Date().toISOString(),
|
|
653
|
+
question: redactSecrets(step.question), answer: said, ...(answeredChoice === null ? {} : { choice: answeredChoice }), ...(Number.isInteger(step.line) ? { line: step.line } : {}), at: new Date().toISOString(),
|
|
558
654
|
});
|
|
559
655
|
}
|
|
560
656
|
resolveFn0(value);
|
|
561
657
|
};
|
|
562
|
-
|
|
658
|
+
const box = boxFor(step);
|
|
659
|
+
// the plan's Drop/Add door is a function: it never rides in `state` (that is JSON)
|
|
660
|
+
const { edit: stepEdit, ...stepPure } = step;
|
|
661
|
+
planEdit = typeof stepEdit === 'function' ? stepEdit : null;
|
|
662
|
+
state.pendingAsk = box === null ? stepPure : { ...stepPure, box };
|
|
563
663
|
resolvePending = resolveFn;
|
|
564
664
|
if (step.kind === 'language') say('bot', `${step.field?.prompt ?? 'Which language is this job about?'} (${(step.candidates ?? []).join(', ')})`);
|
|
565
665
|
else if (step.kind === 'menu') {
|
|
566
666
|
sayPlan(step.plan ?? {});
|
|
567
|
-
} else if (step.kind === 'answer' && step.source === 'fit-check'
|
|
568
|
-
else if (step.kind === 'answer')
|
|
667
|
+
} else if (step.kind === 'answer' && (step.source === 'fit-check' || step.source === 'dest-point')) sayOpen(panelQuestionText(/** @type {any} */ (step)));
|
|
668
|
+
else if (step.kind === 'answer') sayOpen(`A question the plan raised (${step.index} of ${step.total})${Number.isInteger(step.line) ? `, about job line ${step.line}` : ''}: ${panelQuestionText(/** @type {any} */ (step))}`);
|
|
569
669
|
else if (step.kind === 'goal') say('bot', 'Type the goal sentence yourself.');
|
|
570
670
|
});
|
|
571
671
|
|
|
572
|
-
/** @param {string|null} value @returns {boolean} */
|
|
573
|
-
const answer = (value) => {
|
|
672
|
+
/** @param {string|null} value @param {string|null} [choice] the button used, when the answer came from the question box @returns {boolean} */
|
|
673
|
+
const answer = (value, choice = null) => {
|
|
574
674
|
if (!resolvePending) return false;
|
|
575
675
|
const r = resolvePending;
|
|
576
676
|
resolvePending = null;
|
|
577
677
|
state.pendingAsk = null;
|
|
678
|
+
planEdit = null;
|
|
679
|
+
closeOpenMsg();
|
|
680
|
+
answeredChoice = choice;
|
|
578
681
|
r(value);
|
|
579
682
|
return true;
|
|
580
683
|
};
|
|
@@ -605,6 +708,12 @@ export function createSession(card, deps = {}) {
|
|
|
605
708
|
if (PHASE_STEP[name]) stepStart(PHASE_STEP[name], PHASE_STEP[name] === 'draft' ? `${card.model}, $${card.capUsd.toFixed(2)} cap` : undefined);
|
|
606
709
|
// WHY a try was refused: the drafting log keeps it beside the call that made it (it used to say only "retry 3 of 3"), and the
|
|
607
710
|
// progress line shows it briefly, in code's words
|
|
711
|
+
// PRD v1.131 tick 7: the retention counts of a rubric draft, one line when it ends (counts only, no words)
|
|
712
|
+
// the one check list of a rubric job: each row once when it is built and once at the end, and each try's refusals (kind `ledger` / `ledger-try`)
|
|
713
|
+
if (name === 'ledger-built' && Array.isArray(data.rows)) for (const r of data.rows) appendDraftLog(outDir, { phase: 'built', ...r, kind: 'ledger', no: Math.max(0, state.steps.length - 1), at: new Date().toISOString() });
|
|
714
|
+
if (name === 'draft-ledger-try') appendDraftLog(outDir, { kind: 'ledger-try', no: Math.max(0, state.steps.length - 1), label: data.label, kept: data.kept, refused: data.refused, at: new Date().toISOString() });
|
|
715
|
+
if (name === 'draft-ledger' && Array.isArray(data.rows)) for (const r of data.rows) appendDraftLog(outDir, { phase: 'final', ...r, kind: 'ledger', no: Math.max(0, state.steps.length - 1), at: new Date().toISOString() });
|
|
716
|
+
if (name === 'draft-retention' && Array.isArray(data.lines)) appendDraftLog(outDir, { kind: 'retention', no: Math.max(0, state.steps.length - 1), lines: data.lines, at: new Date().toISOString() });
|
|
608
717
|
if (name === 'author-try-failed') {
|
|
609
718
|
lastTryRefused = true;
|
|
610
719
|
const no = state.steps.findLastIndex((/** @type {any} */ x) => x.id === 'draft');
|
|
@@ -865,8 +974,16 @@ export function createSession(card, deps = {}) {
|
|
|
865
974
|
* the seed themselves.
|
|
866
975
|
* @param {any} spec @param {string|null} seedRef
|
|
867
976
|
*/
|
|
868
|
-
const finish = async (spec, seedRef) => {
|
|
977
|
+
const finish = async (spec, seedRef, hasBuiltCheck = /** @type {boolean|null} */ (null)) => {
|
|
869
978
|
if (abandoned) return;
|
|
979
|
+
// R7 (piece 9): a schedule picked on the card is part of the job the person signs, so the FIRST run's hash already covers it. By hand adds nothing (the key stays absent).
|
|
980
|
+
if (deps.schedule) {
|
|
981
|
+
spec.trigger = deps.schedule;
|
|
982
|
+
if (isTicketTrigger(deps.schedule)) {
|
|
983
|
+
const look = ticketLookOf(spec, deps.schedule);
|
|
984
|
+
if (!look.ok) { refuse(look.say); return; }
|
|
985
|
+
}
|
|
986
|
+
}
|
|
870
987
|
const specFile = join(outDir, 'resolved-spec.json');
|
|
871
988
|
writeFileSync(specFile, `${JSON.stringify(spec, null, 2)}\n`);
|
|
872
989
|
state.resolvedSpecPath = specFile;
|
|
@@ -899,6 +1016,13 @@ export function createSession(card, deps = {}) {
|
|
|
899
1016
|
return;
|
|
900
1017
|
}
|
|
901
1018
|
|
|
1019
|
+
// the end check: a rubric close with no real check never reaches the signing gates (R10, hamr 2026-11-10)
|
|
1020
|
+
// the check block says it (block.hasBuiltCheck(), carried out of drafting): a rubric run needs at least one built check
|
|
1021
|
+
const noCheck = hasBuiltCheck === false ? signingStopText({ reds: [], noCheck: true, spend: { knownUsd: state.draftSpentUsd, spendComplete: state.draftSpendComplete } }) : null;
|
|
1022
|
+
if (noCheck) {
|
|
1023
|
+
refuse(noCheck);
|
|
1024
|
+
return;
|
|
1025
|
+
}
|
|
902
1026
|
state.phase = 'signing-gates';
|
|
903
1027
|
stepStart('gates', 'gates 1–3 cost $0; gate 4 only for a rubric');
|
|
904
1028
|
const judges = closeJudges(spec.closeDecl);
|
|
@@ -956,7 +1080,7 @@ export function createSession(card, deps = {}) {
|
|
|
956
1080
|
reds: redsRecord(signing.reds ?? [], { signing: true }), at: new Date().toISOString(),
|
|
957
1081
|
});
|
|
958
1082
|
refuse(signingStopText({
|
|
959
|
-
reds: signing.reds ?? [], refusal: signing.refusal,
|
|
1083
|
+
reds: signing.reds ?? [], refusal: signing.refusal, noCheck: hasBuiltCheck === false,
|
|
960
1084
|
spend: { knownUsd: state.draftSpentUsd, spendComplete: state.draftSpendComplete },
|
|
961
1085
|
}));
|
|
962
1086
|
return;
|
|
@@ -989,7 +1113,7 @@ export function createSession(card, deps = {}) {
|
|
|
989
1113
|
|
|
990
1114
|
// a rubric job on files writes only inside the hidden tree's own `output/`; its Destination is a drop-off folder
|
|
991
1115
|
// (proven above, per run), never a fence
|
|
992
|
-
|
|
1116
|
+
let writeScope = RUBRIC_FILES ? ['output/'] : card.destination.split(/[,\n]/).map((s) => s.trim()).filter(Boolean);
|
|
993
1117
|
/** @type {any} the confirm turn (below) fills `goal` in once accepted —
|
|
994
1118
|
* declared loosely rather than typed field-by-field, since this object's
|
|
995
1119
|
* own shape is a `job-v1` draft `validateJob` itself is the real
|
|
@@ -1044,23 +1168,74 @@ export function createSession(card, deps = {}) {
|
|
|
1044
1168
|
// no NEW model call starts after an abandon; a call already in flight books its usage via onCall and is discarded
|
|
1045
1169
|
const noCallAfterAbandon = (fn) => (...a) => { if (abandoned) throw new Error('abandoned — no new model call'); return fn(...a); };
|
|
1046
1170
|
const generate = noCallAfterAbandon(deps.generate ?? makeLoopGenerate(provider, { rates: draftPrice?.rates ?? null, draftThinking }));
|
|
1047
|
-
const confirmGenerate = noCallAfterAbandon(deps.confirmGenerate ?? makeLoopGenerate(provider, { system:
|
|
1171
|
+
const confirmGenerate = noCallAfterAbandon(deps.confirmGenerate ?? makeLoopGenerate(provider, { system: confirmSystemFor(RUBRIC_FILES ? RUBRIC_LANG : ''), rates: draftPrice?.rates ?? null, draftThinking }));
|
|
1172
|
+
// R10 (fwd am16): the check-suggestion call's own model boundary (SUGGEST_SYSTEM, the drafter's thinking); a test that replaces the model boundary never reaches it unless it brings `deps.pickGenerate`
|
|
1173
|
+
const pickGenerate = deps.pickGenerate !== undefined ? deps.pickGenerate : (deps.generate ? null : noCallAfterAbandon(makeLoopGenerate(provider, { system: SUGGEST_SYSTEM, rates: draftPrice?.rates ?? null, draftThinking })));
|
|
1174
|
+
// the one check list's call has its own model boundary (LEDGER_SYSTEM, the drafter's thinking); like the others, a test that replaces the model boundary never reaches it unless it brings `deps.ledgerGenerate`
|
|
1175
|
+
const ledgerGenerate = deps.ledgerGenerate !== undefined ? deps.ledgerGenerate : (deps.generate ? null : noCallAfterAbandon(makeLoopGenerate(provider, { system: LEDGER_SYSTEM, rates: draftPrice?.rates ?? null, draftThinking })));
|
|
1176
|
+
// the row-edit turn (the drafter's reply of a rubric job, src/rowedit.js) has its own model boundary; a test that replaces `generate` need not bring one
|
|
1177
|
+
const editGenerate = deps.editGenerate !== undefined ? deps.editGenerate : (deps.generate ? null : noCallAfterAbandon(makeLoopGenerate(provider, { system: ROW_EDIT_SYSTEM, rates: draftPrice?.rates ?? null, draftThinking })));
|
|
1178
|
+
|
|
1179
|
+
// R7b (3), hamr's option A: the drafting AI POINTS when a job line's file to change lies outside Destination; code checks the claim (src/destpoint.js) and asks ONE typed
|
|
1180
|
+
// yes/no question through the same `ask` as the fit check's "go on". "yes" sets the fence (below) AND this session's card Destination (the page re-fills its box from it);
|
|
1181
|
+
// "no" goes on unchanged. The fence and the draft are updated before the composer sees them, so the signed spec carries the answer. The caller's own card object is never mutated. A repo job only; failure is OPEN.
|
|
1182
|
+
if (!RUBRIC_FILES && isRepoLike) {
|
|
1183
|
+
const destFn = deps.destFn !== undefined ? deps.destFn : (deps.generate ? null : runDestPoint);
|
|
1184
|
+
const tracked = destFn ? repoTrackedFiles(prep.tree) : null;
|
|
1185
|
+
if (destFn && tracked !== null) {
|
|
1186
|
+
const pointed = await destFn({
|
|
1187
|
+
jobLines, files: tracked, destination: card.destination, provider, ceilingUsd: card.capUsd, onCall, ...(draftPrice?.rates ? { rates: draftPrice.rates } : {}),
|
|
1188
|
+
...(Object.keys(thinkingCallOptions(provider, draftThinking)).length ? { callOptions: thinkingCallOptions(provider, draftThinking) } : {}),
|
|
1189
|
+
});
|
|
1190
|
+
if (abandoned) return;
|
|
1191
|
+
appendDraftLog(outDir, { kind: 'dest-point', no: Math.max(0, state.steps.length - 1), state: pointed.state, ...(pointed.point ? { line: pointed.point.line, file: redactSecrets(pointed.point.file), folder: redactSecrets(pointed.point.folder) } : {}), ...(pointed.reason ? { reason: redactSecrets(pointed.reason) } : {}), at: new Date().toISOString() });
|
|
1192
|
+
if (pointed.state === 'point' && pointed.point) {
|
|
1193
|
+
const question = destQuestionText(pointed.point, card.destination);
|
|
1194
|
+
let said = null;
|
|
1195
|
+
let typedDest = '';
|
|
1196
|
+
while (said === null) {
|
|
1197
|
+
const a = await ask({ kind: 'answer', source: 'dest-point', index: 1, total: 1, question, line: pointed.point.line, folder: pointed.point.folder, current: card.destination });
|
|
1198
|
+
if (a === null) return;
|
|
1199
|
+
// a typed Destination (the question box's own words, already checked at $0 by `send`) is taken as typed; buttons and old words say yes or no
|
|
1200
|
+
if (takeChoice() === 'path') { said = 'typed'; typedDest = String(a).trim(); break; }
|
|
1201
|
+
said = yesNoOf(a);
|
|
1202
|
+
if (said === null) say('bot', 'Type yes or no.');
|
|
1203
|
+
}
|
|
1204
|
+
const newDest = said === 'typed' ? typedDest : pointed.point.folder;
|
|
1205
|
+
appendDraftLog(outDir, { kind: 'dest-answer', no: Math.max(0, state.steps.length - 1), answer: said, from: redactSecrets(card.destination), to: redactSecrets(newDest), at: new Date().toISOString() });
|
|
1206
|
+
if (said === 'yes' || said === 'typed') {
|
|
1207
|
+
card = { ...card, destination: newDest };
|
|
1208
|
+
writeScope = said === 'typed' ? newDest.split(/[,\n]/).map((x) => x.trim()).filter(Boolean) : [newDest];
|
|
1209
|
+
draft.writeScope = writeScope;
|
|
1210
|
+
state.card = { ...state.card, destination: newDest };
|
|
1211
|
+
say('bot', `Destination is now ${newDest}. Drafting.`);
|
|
1212
|
+
} else say('bot', 'Destination stays as it is. Drafting.');
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1048
1216
|
|
|
1049
1217
|
// P7 item 5 (fwdloop am24/25): the last drafting try, after two failed ones, may ask. Each question comes through the same
|
|
1050
1218
|
// ask path as every other (the chat box + Send); the answer is REQUIRED (a blank one asks again, there is no skip) and is
|
|
1051
1219
|
// added WORD FOR WORD as a `~` rule on the job line it names — never rewritten. The lines are mutated in place, so the
|
|
1052
1220
|
// signed `jobLines`, the answers text and the plan card all read the same words.
|
|
1053
|
-
const answerQuestions = async (/** @type {{questions: {line: number, question: string, rule?: number, source?: string, ask?: string, reading?: string}[], dropped: {reason: string, raw: any}[], confirmed: any}} */ o) => {
|
|
1221
|
+
const answerQuestions = async (/** @type {{questions: {line: number, question: string, rule?: number, source?: string, ask?: string, reading?: string, ruleText?: string, check?: Record<string, any>}[], dropped: {reason: string, raw: any}[], confirmed: any}} */ o) => {
|
|
1054
1222
|
if (o.dropped.length) appendDraftLog(outDir, { kind: 'questions-dropped', no: Math.max(0, state.steps.length - 1), dropped: o.dropped, at: new Date().toISOString() });
|
|
1055
1223
|
const total = o.questions.length;
|
|
1056
1224
|
/** @type {{line: number, rule: number}[]} */
|
|
1057
1225
|
const left = [];
|
|
1226
|
+
/** R10: the picks the person made (fwd am16): the check agreed to, or their own words with no check @type {{line: number, rule: number, check: Record<string, any>|null, added?: string, own?: boolean}[]} */
|
|
1227
|
+
const picks = [];
|
|
1228
|
+
/** the choices the check block applies (src/blockasks.js) @type {{key: string, choice: string, text: string}[]} */
|
|
1229
|
+
const choices = [];
|
|
1058
1230
|
for (let k = 0; k < total; k += 1) {
|
|
1059
1231
|
const q = o.questions[k];
|
|
1060
1232
|
let text = '';
|
|
1233
|
+
/** the button the person used for this question (src/questionbox.js), or null when they typed words (the CLI, an old page): a typed choice decides, never the words */
|
|
1234
|
+
let via = null;
|
|
1061
1235
|
for (;;) {
|
|
1062
|
-
const a = await ask({ kind: 'answer', source: typeof q.source === 'string' ? q.source : 'try-3', index: k + 1, total, question: q.question, line: q.line });
|
|
1236
|
+
const a = await ask({ kind: 'answer', source: typeof q.source === 'string' ? q.source : 'try-3', index: k + 1, total, question: q.question, line: q.line, ...(q.source === 'look' ? { ask: q.ask, rule: q.rule, offers: offersOf(q) } : {}) });
|
|
1063
1237
|
if (a === null) return null;
|
|
1238
|
+
via = takeChoice();
|
|
1064
1239
|
// one `~` line is one line: the person's own words, newlines folded to spaces, nothing else touched
|
|
1065
1240
|
text = String(a).replace(/\s*\n\s*/g, ' ').trim();
|
|
1066
1241
|
if (text) break;
|
|
@@ -1070,16 +1245,42 @@ export function createSession(card, deps = {}) {
|
|
|
1070
1245
|
// rule on the look's Not checked list. A reading ask answered "agree" adds the code's reading, in plain words, as the `~` rule (so the
|
|
1071
1246
|
// bound is now the person's own words); anything else typed is the person's own rule, word for word.
|
|
1072
1247
|
// F240: "yes, check it as ..." is the person's own words minus the leading "yes,"
|
|
1073
|
-
|
|
1074
|
-
if (q.source === 'look' &&
|
|
1075
|
-
|
|
1248
|
+
// a choice from the question box decides what the answer does; the box's own words (`rule`) are kept whole, even when they read "agree" or "drop it"
|
|
1249
|
+
if (q.source === 'look' && via === null) text = stripAgreeLead(text);
|
|
1250
|
+
const agrees = via === 'agree' || (via === null && isAgree(text));
|
|
1251
|
+
const dropsIt = via === 'drop' || (via === null && isDropIt(text));
|
|
1252
|
+
if (q.source === 'look' && q.ask === 'reading' && typeof q.reading === 'string' && agrees) text = q.reading;
|
|
1253
|
+
// the person's CHOICE, for the check block (the choice decides, never the words): agree only where agree is offered, drop only where drop is
|
|
1254
|
+
const canAgree = q.source === 'look' && ((q.ask === 'reading' && typeof q.reading === 'string') || (q.ask === 'check' && q.check !== undefined && q.check !== null));
|
|
1255
|
+
const canDrop = q.source === 'look' && (q.ask === 'cant-check' || q.ask === 'no-check' || q.ask === 'check') && Number.isInteger(q.rule);
|
|
1256
|
+
if (typeof (/** @type {any} */ (q)).key === 'string') choices.push({ key: /** @type {any} */ (q).key, choice: canDrop && dropsIt ? 'drop' : canAgree && agrees ? 'agree' : 'rule', text });
|
|
1257
|
+
if (q.source === 'look' && q.ask === 'cant-check' && Number.isInteger(q.rule) && dropsIt) { left.push({ line: q.line, rule: /** @type {number} */ (q.rule) }); continue; }
|
|
1258
|
+
// R10 (fwd am16): a check-pick ask. `agree` writes the proposal's plain words as a new `~` rule and picks the check; "drop it" leaves the rule Not checked; anything else
|
|
1259
|
+
// is the person's own words, a `~` rule word for word with no check (Not checked: they judge it at Accept)
|
|
1260
|
+
let agreedPick = false;
|
|
1261
|
+
const isPick = q.source === 'look' && (q.ask === 'check' || q.ask === 'no-check') && Number.isInteger(q.rule);
|
|
1262
|
+
// am21: the ask is about the person's EDITED added `~` line (`pairRule` = the rule it was agreed from): the answer REPLACES that line and the pick is kept under the source's number
|
|
1263
|
+
const pair = isPick && Number.isInteger(/** @type {any} */ (q).pairRule) ? /** @type {number} */ (/** @type {any} */ (q).pairRule) : null;
|
|
1264
|
+
if (isPick && dropsIt) { left.push({ line: q.line, rule: /** @type {number} */ (q.rule) }); if (pair !== null) left.push({ line: q.line, rule: pair }); appendDraftLog(outDir, { kind: 'check-pick', no: Math.max(0, state.steps.length - 1), line: q.line, rule: q.rule, ruleText: redactSecrets(String(q.ruleText ?? '')), proposed: q.reading ?? null, how: 'drop it', at: new Date().toISOString() }); continue; }
|
|
1265
|
+
if (isPick) {
|
|
1266
|
+
const agreed = q.ask === 'check' && q.check && agrees;
|
|
1267
|
+
if (agreed) text = plainWords(/** @type {any} */ (q.check));
|
|
1268
|
+
agreedPick = agreed === true;
|
|
1269
|
+
if (agreed) pickedSoFar.push({ line: q.line, text: plainWords(/** @type {any} */ (q.check)) });
|
|
1270
|
+
picks.push({ line: q.line, rule: pair ?? /** @type {number} */ (q.rule), check: agreed ? /** @type {any} */ (q.check) : null, added: text, ...(agreed ? {} : { own: true }) });
|
|
1271
|
+
appendDraftLog(outDir, { kind: 'check-pick', no: Math.max(0, state.steps.length - 1), line: q.line, rule: q.rule, ruleText: redactSecrets(String(q.ruleText ?? '')), proposed: q.reading ?? null, how: agreed ? 'agree' : 'own words', ...(agreed ? { picked: q.check } : {}), added: redactSecrets(text), at: new Date().toISOString() });
|
|
1272
|
+
}
|
|
1076
1273
|
const line = jobLines.find((l) => l.n === q.line);
|
|
1077
|
-
if (line) { line.
|
|
1274
|
+
if (line && pair !== null) { line.rules[/** @type {number} */ (q.rule) - 1] = text; line.rule = line.rules.join('; '); }
|
|
1275
|
+
// F318: agreeing to words the line already holds as a ~ rule adds no second line (the pick cites the rule that is there); different words still add one
|
|
1276
|
+
else if (line && !(agreedPick && line.rules.some((/** @type {string} */ t) => sameRuleWords(t, text)))) { line.rule = line.rule ? `${line.rule}; ${text}` : text; line.rules.push(text); }
|
|
1078
1277
|
}
|
|
1079
1278
|
draft.jobLines = signedJobLines(jobLines);
|
|
1279
|
+
// R10 (fwd am21): the answers are `~` rules on the lines, so the card's job box says so too: a Revise reopens the boxes WITH them, and an edit of an agreed line is seen as an edit
|
|
1280
|
+
state.card = { ...state.card, jobText: jobBoxText(jobLines) };
|
|
1080
1281
|
answers[1] = renderJobLines(jobLines);
|
|
1081
|
-
state.messages.push({ ...planMessage(o.confirmed ?? {}, jobLines), text: left.length === total ? 'Noted: those stay Not checked. Drafting.' : 'Your answers are in as ~ rules on those job lines. Drafting again.' });
|
|
1082
|
-
return { jobLines, answers, left };
|
|
1282
|
+
state.messages.push({ ...planMessage({ ...(o.confirmed ?? {}), ...(pickedSoFar.length ? { picked: [...pickedSoFar] } : {}) }, jobLines), text: left.length === total ? 'Noted: those stay Not checked. Drafting.' : 'Your answers are in as ~ rules on those job lines. Drafting again.' });
|
|
1283
|
+
return { jobLines, answers, left, picks, choices };
|
|
1083
1284
|
};
|
|
1084
1285
|
|
|
1085
1286
|
// F243: the fit check's one question, through the same `ask` (the chat box + Send; a blank answer asks again, there is no skip)
|
|
@@ -1107,7 +1308,16 @@ export function createSession(card, deps = {}) {
|
|
|
1107
1308
|
rates: draftPrice?.rates ?? null,
|
|
1108
1309
|
draftThinking,
|
|
1109
1310
|
onPhase, onCall,
|
|
1110
|
-
ask, answerQuestions, confirmGenerate, isRepo: !RUBRIC_FILES, langResult,
|
|
1311
|
+
ask, answerQuestions, confirmGenerate, isRepo: !RUBRIC_FILES, langResult, pickGenerate, ledgerGenerate, editGenerate, carriedPicks, carriedChoices,
|
|
1312
|
+
onChoices: (/** @type {any[]} */ rec) => { try { writeRecordPart(join(outDir, RECORD_FILE), { rowChoices: rec }); } catch { /* a convenience: a disk fault only means the next draft starts without them */ } },
|
|
1313
|
+
// R10: this draft's record (the picks it kept and the ones just answered) goes to its own folder for the next draft to carry; each kept pick is logged as such
|
|
1314
|
+
onPicks: (/** @type {{entries: any[], kept: {line: number, rule: number, entry: any}[]}} */ o) => {
|
|
1315
|
+
try { writeRecordPart(join(outDir, RECORD_FILE), { picks: o.entries }); } catch { /* the record is a convenience: a disk fault only means the next draft asks again */ }
|
|
1316
|
+
for (const k of o.kept) {
|
|
1317
|
+
if (k.entry.check) pickedSoFar.push({ line: k.line, text: `${plainWords(/** @type {any} */ (k.entry.check))} \u00B7 ${KEPT_WORDS}` });
|
|
1318
|
+
appendDraftLog(outDir, { kind: 'check-pick', no: Math.max(0, state.steps.length - 1), line: k.line, rule: k.rule, ruleText: redactSecrets(String(k.entry.ruleText ?? '')), how: KEPT_WORDS, ...(k.entry.check ? { picked: k.entry.check } : {}), ...(k.entry.left ? { left: true } : {}), ...(k.entry.own ? { own: true } : {}), at: new Date().toISOString() });
|
|
1319
|
+
}
|
|
1320
|
+
},
|
|
1111
1321
|
...(deps.scout ? { scout: deps.scout } : {}),
|
|
1112
1322
|
// PART 1c: a test that replaces the model boundary (`generate`) must not reach the real paid look; `deps.lookFn` brings its own
|
|
1113
1323
|
...(deps.lookFn !== undefined ? { lookFn: deps.lookFn } : (deps.generate ? { lookFn: null } : {})),
|
|
@@ -1115,6 +1325,8 @@ export function createSession(card, deps = {}) {
|
|
|
1115
1325
|
fitAsk, onFit,
|
|
1116
1326
|
...(deps.fitFn !== undefined ? { fitFn: deps.fitFn } : (deps.generate ? { fitFn: null } : {})),
|
|
1117
1327
|
...(authorFnOverride ? { authorFn: authorFnOverride } : {}),
|
|
1328
|
+
// R5 (piece 2): a Tickets job's drafter is told about the ticket filter and may propose one (the person signs it)
|
|
1329
|
+
...(deps.flow?.flowType === 'tickets' ? { authorOpts: { ticket: true } } : {}),
|
|
1118
1330
|
});
|
|
1119
1331
|
|
|
1120
1332
|
if (!authored.ok && PLAIN_PROPOSAL_STOPS.includes(String(authored.stop))) {
|
|
@@ -1152,24 +1364,27 @@ export function createSession(card, deps = {}) {
|
|
|
1152
1364
|
|
|
1153
1365
|
if (RUBRIC_FILES) draft.goal = redactSecrets(rubricGoal({ jobLines, files: prep.manifest.inputs, confirmedGoal: authored.confirmed?.goal ?? null, closeDecl: authored.closeDecl }));
|
|
1154
1366
|
else if (authored.confirmed?.goal) draft.goal = redactSecrets(String(authored.confirmed.goal));
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
//
|
|
1158
|
-
// from the close itself, and every confirmed check no part carries out is moved to Not checked, in code, before signing.
|
|
1367
|
+
// piece 8: the card's Flow type and MCP pick are signed by CODE, after the draft (the agent cannot carry them: `assembleSpec` refuses a draft that does). A plain card adds nothing.
|
|
1368
|
+
const spec = signFlow(assembleSpec(draft, { ...authored, verdictType: /** @type {string} */ (authored.verdictType) }), deps.flow?.flowType ?? 'plain', deps.flow?.pick ?? null, authored.authoring?.ticketFilter);
|
|
1369
|
+
// PART 1a (run mv5bk400): the card AFTER drafting is built from the signed close itself (cardOfClose), never from what the confirm turn planned.
|
|
1159
1370
|
if (RUBRIC_FILES) {
|
|
1160
|
-
const rec =
|
|
1161
|
-
|
|
1162
|
-
});
|
|
1163
|
-
|
|
1371
|
+
const rec = cardOfClose({ closeDecl: spec.closeDecl, jobLines, ledger: readDraftLedger(outDir) });
|
|
1372
|
+
// the checks this draft ended with, each marked who added it (`agent` or `you`): the Audit's Draft group shows them (a log line, not a second record of the plan)
|
|
1373
|
+
appendDraftLog(outDir, { kind: 'draft-checks', no: Math.max(0, state.steps.length - 1), checks: rec.checkItems.filter((/** @type {any} */ c) => c.by === 'agent' || c.by === 'you').map((/** @type {any} */ c) => ({ line: c.fromLine[0], text: redactSecrets(String(c.text)), by: c.by })), at: new Date().toISOString() });
|
|
1374
|
+
// F-b (hamr 2026-11-13): a suggestion code could not build is not on the card; it is one plain sentence in the Audit's draft lines
|
|
1375
|
+
appendDraftLog(outDir, { kind: 'draft-notbuilt', no: Math.max(0, state.steps.length - 1), rows: (Array.isArray(authored.notBuilt) ? authored.notBuilt : []).map((/** @type {any} */ x) => ({ line: x.line, text: redactSecrets(String(x.text)) })), at: new Date().toISOString() });
|
|
1376
|
+
// R10: the checks the person picked, for the plan card's "You picked" rows (the check rows and the Not checked rows come from the signed close itself)
|
|
1377
|
+
const picked = Array.isArray(authored.picked) ? authored.picked : [];
|
|
1378
|
+
state.finalPlan = { goal: String(draft.goal ?? ''), checkItems: rec.checkItems, picked, notChecked: rec.notChecked, notCheckedBy: rec.notCheckedBy, protections: authored.confirmed?.protections ?? [], signedFacts: signedFactNames(spec.closeDecl), ...(spec.ticketFilter ? { ticketFilter: spec.ticketFilter } : {}) };
|
|
1164
1379
|
}
|
|
1165
|
-
await finish(spec, authored.seedRef);
|
|
1380
|
+
await finish(spec, authored.seedRef, authored.hasBuiltCheck ?? null);
|
|
1166
1381
|
if (state.finalPlan && state.phase === 'prepared') {
|
|
1167
1382
|
// The confirm turn's plan bubble (and a try-3 "answers are in" one) is the DRAFTER's wording of the checks, written before
|
|
1168
1383
|
// any close existed. Once the close is signed-ready its card is the only plan the person sees: the earlier ones are
|
|
1169
1384
|
// dropped, so drafter prose can never sit above (and be read instead of) the code's sentences (run mv5e1ktb).
|
|
1170
1385
|
state.messages = state.messages.filter((/** @type {any} */ m) => m.kind !== 'plan');
|
|
1171
1386
|
state.messages.push({
|
|
1172
|
-
...planMessage({ checkItems: state.finalPlan.checkItems, checks: state.finalPlan.checkItems.map((/** @type {any} */ c) => c.text), notChecked: state.finalPlan.notChecked, protections: state.finalPlan.protections, signedFacts: state.finalPlan.signedFacts, questions: [] }, jobLines),
|
|
1387
|
+
...planMessage({ checkItems: state.finalPlan.checkItems, checks: state.finalPlan.checkItems.map((/** @type {any} */ c) => c.text), notChecked: state.finalPlan.notChecked, notCheckedBy: state.finalPlan.notCheckedBy, protections: state.finalPlan.protections, signedFacts: state.finalPlan.signedFacts, picked: state.finalPlan.picked, ticketFilter: state.finalPlan.ticketFilter, questions: [] }, jobLines),
|
|
1173
1388
|
text: 'These are the checks the signed close will run, and what it will not check. Sign & run to accept them, or Revise to edit the boxes and draft again.',
|
|
1174
1389
|
});
|
|
1175
1390
|
}
|
|
@@ -1185,11 +1400,26 @@ export function createSession(card, deps = {}) {
|
|
|
1185
1400
|
return {
|
|
1186
1401
|
id,
|
|
1187
1402
|
state,
|
|
1188
|
-
/** @param {string} text */
|
|
1189
|
-
send: (text) => {
|
|
1403
|
+
/** @param {string} text @param {unknown} [choice] the button used in the question box (`agree`, `drop`, `rule`); absent = the words reading (the CLI's way, old pages) */
|
|
1404
|
+
send: (text, choice) => {
|
|
1190
1405
|
if (!state.pendingAsk) return { ok: false, error: 'nothing is being asked right now' };
|
|
1191
1406
|
if (state.pendingAsk.kind === 'menu') return { ok: false, error: 'use Sign & run for a plan, never Send — the chat can never sign or pick a plan action' };
|
|
1192
1407
|
if (state.pendingAsk.kind === 'install-needed') return { ok: false, error: 'install the packages, then click Check again — nothing to send here' };
|
|
1408
|
+
if (choice !== undefined) {
|
|
1409
|
+
// hamr 2026-11-12 (fwd am29/am31): the question box posts a typed choice. A refusal leaves the question open: nothing said, nothing logged, nothing resolved.
|
|
1410
|
+
const no = refuseChoice(state.pendingAsk, choice);
|
|
1411
|
+
if (no !== null) return { ok: false, refused: 'bad-choice', error: no };
|
|
1412
|
+
const r = resolveChoice(choice, text);
|
|
1413
|
+
if ('error' in r) return { ok: false, refused: 'blank-answer', error: r.error };
|
|
1414
|
+
// a typed Destination goes through the SAME $0 check the card's Destination does, before it is taken; a refusal keeps the question open with that check's own words
|
|
1415
|
+
if (choice === 'path') {
|
|
1416
|
+
const problem = startDestinationProblem({ inputs: card.inputs, destination: r.value, checkType: card.checkType });
|
|
1417
|
+
if (problem !== null) return { ok: false, refused: 'bad-destination', error: problem };
|
|
1418
|
+
}
|
|
1419
|
+
say('you', r.shown);
|
|
1420
|
+
answer(r.value, /** @type {string} */ (choice));
|
|
1421
|
+
return { ok: true };
|
|
1422
|
+
}
|
|
1193
1423
|
say('you', text);
|
|
1194
1424
|
answer(text);
|
|
1195
1425
|
return { ok: true };
|
|
@@ -1204,6 +1434,7 @@ export function createSession(card, deps = {}) {
|
|
|
1204
1434
|
dropWorktree();
|
|
1205
1435
|
state.error = 'Abandoned by you — money already spent stays booked.';
|
|
1206
1436
|
state.pendingAsk = null;
|
|
1437
|
+
closeOpenMsg();
|
|
1207
1438
|
if (resolvePending) { const r = resolvePending; resolvePending = null; r(null); }
|
|
1208
1439
|
if (resolveDepsCheck) { const r = resolveDepsCheck; resolveDepsCheck = null; r(); }
|
|
1209
1440
|
return { ok: true };
|
|
@@ -1217,6 +1448,24 @@ export function createSession(card, deps = {}) {
|
|
|
1217
1448
|
r();
|
|
1218
1449
|
return { ok: true };
|
|
1219
1450
|
},
|
|
1451
|
+
/**
|
|
1452
|
+
* Drop or Add on the confirm card (hamr 2026-11-13, N-2): an instant row edit through the live check block. $0: no model call, no new draft. The block reconciles the whole list; a refusal is plain
|
|
1453
|
+
* words and changes nothing. On success the plan bubble is drawn again from the rows and the person's choices are kept for a Revise.
|
|
1454
|
+
* @param {unknown} op @param {unknown} key @returns {{ok: true}|{ok: false, error: string, refused?: string}}
|
|
1455
|
+
*/
|
|
1456
|
+
rowEdit: (op, key) => {
|
|
1457
|
+
if (!state.pendingAsk || state.pendingAsk.kind !== 'menu' || planEdit === null) return { ok: false, refused: 'no-plan', error: 'no plan is waiting where checks can be dropped or added right now' };
|
|
1458
|
+
if (op !== 'drop' && op !== 'add') return { ok: false, refused: 'bad-choice', error: 'not one of the choices' };
|
|
1459
|
+
const r = planEdit(op, String(key ?? ''));
|
|
1460
|
+
if (!r.ok) return { ok: false, refused: 'bad-row', error: String(r.why) };
|
|
1461
|
+
const at = state.messages.findLastIndex((/** @type {any} */ m) => m.kind === 'plan');
|
|
1462
|
+
const msg = planMessage({ ...r.plan, ...(pickedSoFar.length ? { picked: [...pickedSoFar] } : {}) }, jobLines);
|
|
1463
|
+
if (at === -1) state.messages.push(msg); else state.messages[at] = msg;
|
|
1464
|
+
state.pendingAsk = { ...state.pendingAsk, plan: r.plan };
|
|
1465
|
+
if (Array.isArray(r.choices)) { try { writeRecordPart(join(outDir, RECORD_FILE), { rowChoices: r.choices }); } catch { /* a convenience */ } }
|
|
1466
|
+
appendDraftLog(outDir, { kind: 'row-edit', no: Math.max(0, state.steps.length - 1), op, key: redactSecrets(String(key)), at: new Date().toISOString() });
|
|
1467
|
+
return { ok: true };
|
|
1468
|
+
},
|
|
1220
1469
|
/** click 1 — the confirm pick. Never signs on its own. */
|
|
1221
1470
|
signPrepare: () => {
|
|
1222
1471
|
if (!state.pendingAsk || state.pendingAsk.kind !== 'menu') return { ok: false, error: 'no plan is waiting for a decision right now' };
|