bareloop 0.54.1 → 0.55.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 +75 -0
- package/bareloop.context.md +65 -6
- package/package.json +3 -3
- package/src/authorflow.js +148 -46
- package/src/authoring.js +21 -4
- package/src/authorjob.js +82 -3
- package/src/authorreadout.js +20 -3
- package/src/authorrun.js +1 -1
- package/src/authorscout.js +9 -6
- package/src/cardschedule.js +42 -0
- package/src/checkpick.js +576 -0
- package/src/checksuggest.js +28 -0
- package/src/checkwords.js +25 -0
- package/src/cli.js +1 -1
- package/src/config.js +24 -1
- package/src/declaredclose.js +1 -1
- package/src/destpoint.js +149 -0
- package/src/draftspend.js +39 -0
- package/src/factwords.js +14 -1
- 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 +5 -2
- package/src/panel/authorroutes.js +90 -15
- package/src/panel/authorsession.js +183 -21
- package/src/panel/index.html +686 -26
- package/src/panel/jobgrid.js +117 -0
- package/src/panel/jobplan.js +31 -15
- 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 +419 -32
- 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 +145 -0
- package/src/plan.js +31 -2
- package/src/planrun.js +71 -15
- package/src/prcheckout.js +259 -0
- package/src/readshim.js +3 -2
- package/src/revises.js +56 -0
- package/src/rubricstep.js +62 -16
- package/src/run.js +10 -1
- 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 +145 -9
- package/src/validate.js +3 -1
- package/src/worktree.js +43 -1
- package/types/authorflow.d.ts +128 -28
- package/types/authorjob.d.ts +16 -3
- package/types/authorreadout.d.ts +9 -2
- package/types/authorscout.d.ts +4 -2
- package/types/cardschedule.d.ts +24 -0
- package/types/checkpick.d.ts +297 -0
- package/types/checksuggest.d.ts +30 -0
- package/types/checkwords.d.ts +14 -0
- package/types/config.d.ts +7 -0
- package/types/destpoint.d.ts +87 -0
- package/types/draftspend.d.ts +16 -0
- package/types/factwords.d.ts +7 -0
- 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 +2 -1
- package/types/panel/authorroutes.d.ts +11 -2
- package/types/panel/authorsession.d.ts +58 -3
- package/types/panel/jobgrid.d.ts +405 -0
- package/types/panel/jobplan.d.ts +10 -4
- 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 +427 -6
- 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 +88 -0
- package/types/plan.d.ts +1 -0
- package/types/prcheckout.d.ts +151 -0
- package/types/readshim.d.ts +4 -3
- package/types/revises.d.ts +23 -0
- package/types/rubricstep.d.ts +14 -5
- package/types/run.d.ts +18 -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
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// borrowed-from: fwdloop src/checkwords.js@v0.29.0
|
|
2
|
+
// R10 (fwdloop M10 amendment 16): the ONE place a picked check is put in plain words (one fixed phrase per bareguard rule, written by code). The ask, the `~` line an agree writes,
|
|
3
|
+
// the plan card, the draft log and the Audit all read it; nothing else writes these words. Identical to fwdloop v0.29.0 by ruling (match fwd first).
|
|
4
|
+
/** the rules of bareguard's list a person may pick here (text rules only: the ones a plain answer can be judged by) */
|
|
5
|
+
export const OFFERED = Object.freeze(['nonEmpty', 'maxWords', 'minWords', 'maxLines', 'listItems', 'sections', 'sectionOrder', 'sectionWords', 'mustCarry', 'blockLines']);
|
|
6
|
+
const listOf = (/** @type {string[]} */ xs) => xs.join(', ');
|
|
7
|
+
/**
|
|
8
|
+
* The check in plain words, one fixed phrase per rule: the ask, the `~` line an agree writes, the plan card and the Audit all read this one function.
|
|
9
|
+
* @param {{rule: string, value?: number, size?: number, wordsPerSection?: number, names?: string[], phrases?: string[]}} c @returns {string}
|
|
10
|
+
*/
|
|
11
|
+
export function plainWords(c) {
|
|
12
|
+
switch (c.rule) {
|
|
13
|
+
case 'nonEmpty': return 'the answer is not empty';
|
|
14
|
+
case 'maxWords': return `at most ${c.value} words`;
|
|
15
|
+
case 'minWords': return `at least ${c.value} words`;
|
|
16
|
+
case 'maxLines': return `at most ${c.value} lines`;
|
|
17
|
+
case 'listItems': return `exactly ${c.value} list items`;
|
|
18
|
+
case 'sections': return `sections named ${listOf(c.names ?? [])}`;
|
|
19
|
+
case 'sectionOrder': return `sections named ${listOf(c.names ?? [])}, in that order`;
|
|
20
|
+
case 'sectionWords': return `sections named ${listOf(c.names ?? [])}, each about ${c.wordsPerSection} words`;
|
|
21
|
+
case 'mustCarry': return `the answer carries ${listOf(c.phrases ?? [])}`;
|
|
22
|
+
case 'blockLines': return `blocks of ${c.size} lines, each carrying ${listOf(c.phrases ?? [])}`;
|
|
23
|
+
default: return `a ${c.rule} check`;
|
|
24
|
+
}
|
|
25
|
+
}
|
package/src/cli.js
CHANGED
|
@@ -352,7 +352,7 @@ async function mainInner(argv, deps, holder) {
|
|
|
352
352
|
// deps)`, unparsed: that function is this flag grammar's one owner
|
|
353
353
|
// (`--job`/`--spec`/`--resume`/`--door`/`--decide`/`--text`/
|
|
354
354
|
// `--review-door`/`--approve`/`--registry`/`--workflow`/`--model`/
|
|
355
|
-
// `--read-shim`/`--scout`). `deps` is spread first so an injected test
|
|
355
|
+
// `--read-shim`/`--scout`/`--ticket`/`--anyway`). `deps` is spread first so an injected test
|
|
356
356
|
// seam (`deps.provider`/`providerFor`/`judgeProvider`) still reaches it,
|
|
357
357
|
// then `env`/`out`/`err` are overridden to the SAME resolved values every
|
|
358
358
|
// other command here prints through, so `run-u`'s output lands on the
|
package/src/config.js
CHANGED
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
// { "monthlyLimitUsd": <number > 0>, // absent = no limit, no check
|
|
12
12
|
// "learningHints": true|false, // absent = true (ON by default; only false turns it off): the planner is handed cross-run learnings (src/learn.js); the tally is kept either way
|
|
13
13
|
// "keys": { "<ENV NAME>": { "shape": "<shape id>", "baseUrl": "http(s)://…", "legacyMaxTokens": true|false } },
|
|
14
|
-
// "models": { "<ENV NAME>": [ { "model": "<id>", "use": true|false, "inPerM": n, "outPerM": n } ] }
|
|
14
|
+
// "models": { "<ENV NAME>": [ { "model": "<id>", "use": true|false, "inPerM": n, "outPerM": n } ] },
|
|
15
|
+
// "mcpPaths": [ "<absolute path of an extra MCP config file>" ] } // judged by `mcpPathProblem`; read by src/mcpsources.js
|
|
15
16
|
// An older file's `keys.<ENV>.{name,priceInPerM,priceOutPerM}` is tolerated and read as ONE model
|
|
16
17
|
// line (`effectiveModels`, src/providerrows.js); the first write of that row's `models` list removes them.
|
|
17
18
|
// `modelsProblem` is the ONE rule for a row's model lines: a price is a PAIR or neither, a ticked
|
|
@@ -122,6 +123,24 @@ export function modelsProblem(list) {
|
|
|
122
123
|
return null;
|
|
123
124
|
}
|
|
124
125
|
|
|
126
|
+
/**
|
|
127
|
+
* The rule for `mcpPaths` (extra MCP config files the person added): a list of absolute, NUL-free paths, no duplicates. Plain words, or null.
|
|
128
|
+
* (The Settings > MCP tab, R3, is the writer; `~` is expanded there, so what is stored is always absolute. One line, at most 500 characters: fwd's rule.)
|
|
129
|
+
* @param {unknown} list
|
|
130
|
+
* @returns {string|null}
|
|
131
|
+
*/
|
|
132
|
+
export function mcpPathProblem(list) {
|
|
133
|
+
if (!Array.isArray(list)) return 'The MCP paths must be a list of file paths.';
|
|
134
|
+
const seen = new Set();
|
|
135
|
+
for (const p of list) {
|
|
136
|
+
if (typeof p !== 'string' || p.trim() === '' || p.length > 500 || /[\0\r\n]/.test(p)) return 'Each MCP path must be one line of at most 500 characters.';
|
|
137
|
+
if (!p.startsWith('/')) return `The MCP path "${p}" must be a full path (it starts with /).`;
|
|
138
|
+
if (seen.has(p)) return `The MCP path "${p}" is listed twice.`;
|
|
139
|
+
seen.add(p);
|
|
140
|
+
}
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
|
|
125
144
|
/**
|
|
126
145
|
* The first problem in a document's known fields, in plain words, or null.
|
|
127
146
|
* @param {Record<string, any>} doc
|
|
@@ -130,6 +149,10 @@ export function modelsProblem(list) {
|
|
|
130
149
|
function docProblem(doc) {
|
|
131
150
|
// monthlyLimitUsd is NOT judged here: `monthlyLimitOf` (src/monthly.js) owns its read-time sentence
|
|
132
151
|
if (doc.learningHints !== undefined && typeof doc.learningHints !== 'boolean') return 'learningHints must be true or false';
|
|
152
|
+
if (doc.mcpPaths !== undefined) {
|
|
153
|
+
const bad = mcpPathProblem(doc.mcpPaths);
|
|
154
|
+
if (bad) return `mcpPaths: ${bad}`;
|
|
155
|
+
}
|
|
133
156
|
if (doc.keys !== undefined) {
|
|
134
157
|
if (doc.keys === null || typeof doc.keys !== 'object' || Array.isArray(doc.keys)) return 'keys must be an object of key variable names';
|
|
135
158
|
for (const [env, row] of Object.entries(doc.keys)) {
|
package/src/declaredclose.js
CHANGED
|
@@ -102,7 +102,7 @@ export const DECLARED_GENRES = Object.freeze([TYPES_GENRE.name, TEXT_GENRE]);
|
|
|
102
102
|
* constrained to the names the genre OWNS, so it can never become an environment
|
|
103
103
|
* channel of its own.
|
|
104
104
|
*/
|
|
105
|
-
export const CLOSE_DECL_FIELDS = Object.freeze(['genre', 'lang', 'stages', 'notes', 'refused', 'guardLines', 'genreEnv', 'calibration']);
|
|
105
|
+
export const CLOSE_DECL_FIELDS = Object.freeze(['genre', 'lang', 'stages', 'notes', 'refused', 'guardLines', 'picks', 'genreEnv', 'calibration']);
|
|
106
106
|
|
|
107
107
|
/** what a stored calibration set carries, ENUMERATED: the frozen cases and the judge
|
|
108
108
|
* tier that graded them. Both are inside the spec, so `jobSpecHash` covers both — which
|
package/src/destpoint.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
// R7b (3), hamr 2026-11-07 (option A): "the AI points, the person decides". Before a repo job is drafted, ONE small paid call reads the job lines and names, for a line that
|
|
2
|
+
// names a file to change, the line, the file (copied from that line) and the folder that holds it. Plain code then checks every claim (the line is a job line, the path
|
|
3
|
+
// stands in that line's own words, the file is in the repo's committed tree, the folder is a real parent of it) and that the file lies OUTSIDE the Destination. Only then is
|
|
4
|
+
// there ONE question, worded by code, answered yes or no like the fit check's "go on". A made-up file, a path the line does not hold or a malformed reply is no question.
|
|
5
|
+
// Failure is OPEN (a wrong question is the costly mistake): a call that does not finish asks nothing and drafting goes on. The call/book/retry pattern is src/fitcheck.js's.
|
|
6
|
+
|
|
7
|
+
import { createRequire } from 'node:module';
|
|
8
|
+
import { priceOf, scrubRaw, tallyCalls, capStop, callCasualty } from './text.js';
|
|
9
|
+
import { redactSecrets } from './validate.js';
|
|
10
|
+
import { isTransportFailure } from './transport.js';
|
|
11
|
+
import { isRateLimited, rateLimitWaitMs } from './ratelimit.js';
|
|
12
|
+
import { isOutputCutOff } from './authorflow.js';
|
|
13
|
+
import { AUTHOR_CALL_TIMEOUT_MS, AUTHOR_SCOUT_MAX_TOKENS } from './authorscout.js';
|
|
14
|
+
|
|
15
|
+
const require = createRequire(import.meta.url);
|
|
16
|
+
const { Loop } = require('bare-agent');
|
|
17
|
+
|
|
18
|
+
/** the label of the one paid call, as the drafting book sees it */
|
|
19
|
+
export const DEST_CALL_LABEL = 'dest-point';
|
|
20
|
+
|
|
21
|
+
export const DEST_SYSTEM = 'You read the numbered lines of a code job. You never invent words: every file path you name must be copied, character for character, from the job line that holds it.';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* What the AI is told (the numbered job text only, no `~` rules) and the one rule, with a legal example.
|
|
25
|
+
* @param {{jobLines: {n: number, text: string}[], destination: string}} o @returns {string}
|
|
26
|
+
*/
|
|
27
|
+
export function destPrompt({ jobLines, destination }) {
|
|
28
|
+
const job = jobLines.map((l) => `LINE ${l.n}: ${l.text}`).join('\n');
|
|
29
|
+
return `THE JOB:\n${job}\n\nDestination (the only place the job may change files): ${destination}\n\n`
|
|
30
|
+
+ 'Name ONLY a file the line asks to CHANGE (to fix, edit, write, add or remove). A file the line only says must pass, be read, be run or be checked (for example the tests it must make pass) is NOT a change: never name it. '
|
|
31
|
+
+ 'For EACH job line, for each file it asks to change, give the line number, the file path copied exactly from that line, and the folder that holds that file (the folder part of the path, ending with /). '
|
|
32
|
+
+ 'A line that names no file path to change is left out; never guess a path the line does not contain. '
|
|
33
|
+
+ 'Reply with JSON only, no prose, no code fence: {"points":[{"line":<line number>,"file":"<path copied from the line>","folder":"<its folder>"}]}. '
|
|
34
|
+
+ 'Example: for the line "LINE 1: Fix the bug in src/sum.js so the tests in test/sum.test.js pass" the reply is {"points":[{"line":1,"file":"src/sum.js","folder":"src/"}]}, and test/sum.test.js is not named because the line only needs those tests to pass; for "LINE 2: make npm test pass" it is {"points":[]}.';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** @typedef {{line: number, file: string, folder: string}} DestPoint */
|
|
38
|
+
|
|
39
|
+
/** does `file` lie under the Destination (a folder, a file, a glob, or `.`)? @param {string} file @param {string} destination @returns {boolean} */
|
|
40
|
+
export function destinationCovers(file, destination) {
|
|
41
|
+
for (const raw of destination.split(/[,\n]/)) {
|
|
42
|
+
const t = raw.trim().replace(/^(\.\/)+/, '').replace(/\/+$/, '');
|
|
43
|
+
if (raw.trim() === '') continue;
|
|
44
|
+
if (t === '' || t === '.') return true;
|
|
45
|
+
if (/[*?]/.test(t)) {
|
|
46
|
+
const re = new RegExp(`^${t.replace(/[.+^${}()|[\]\\]/g, '\\$&').replace(/\*\*/g, '\u0000').replace(/\*/g, '[^/]*').replace(/\?/g, '[^/]').replace(/\u0000/g, '.*')}$`);
|
|
47
|
+
if (re.test(file)) return true;
|
|
48
|
+
} else if (file === t || file.startsWith(`${t}/`)) return true;
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Read the AI's reply and decide, all in code. Malformed (no repair): not JSON, not `{points:[...]}`, a point that is not an object with a whole line, a string file and a string folder.
|
|
55
|
+
* A point survives only when its line is a job line, the file path is written in that line's own text, the file is in the repo's committed tree, the folder is a real parent folder
|
|
56
|
+
* of that file, and the file is NOT under the Destination. The survivors are ordered by line.
|
|
57
|
+
* @param {unknown} text @param {{jobLines: {n: number, text: string}[], files: readonly string[], destination: string}} o
|
|
58
|
+
* @returns {{status: 'malformed'}|{status: 'ok', points: DestPoint[], dropped: number}}
|
|
59
|
+
*/
|
|
60
|
+
export function decideDestPoint(text, { jobLines, files, destination }) {
|
|
61
|
+
/** @type {any} */
|
|
62
|
+
let j;
|
|
63
|
+
try { j = JSON.parse(String(text ?? '').trim()); } catch { return { status: 'malformed' }; }
|
|
64
|
+
if (j === null || typeof j !== 'object' || Array.isArray(j) || !Array.isArray(j.points)) return { status: 'malformed' };
|
|
65
|
+
const lines = new Map(jobLines.map((l) => [l.n, l.text]));
|
|
66
|
+
const tree = new Set(files);
|
|
67
|
+
/** @type {DestPoint[]} */
|
|
68
|
+
const points = [];
|
|
69
|
+
let dropped = 0;
|
|
70
|
+
for (const p of j.points) {
|
|
71
|
+
if (p === null || typeof p !== 'object' || Array.isArray(p) || !Number.isInteger(p.line) || typeof p.file !== 'string' || typeof p.folder !== 'string') return { status: 'malformed' };
|
|
72
|
+
const file = p.file.replace(/^(\.\/)+/, '');
|
|
73
|
+
const folder = p.folder.replace(/^(\.\/)+/, '').replace(/\/+$/, '');
|
|
74
|
+
const lineText = lines.get(p.line);
|
|
75
|
+
const ok = lineText !== undefined && file !== '' && lineText.includes(p.file) && tree.has(file) && folder !== '' && file.startsWith(`${folder}/`) && !destinationCovers(file, destination);
|
|
76
|
+
if (ok) points.push({ line: p.line, file, folder: `${folder}/` }); else dropped += 1;
|
|
77
|
+
}
|
|
78
|
+
points.sort((a, b) => a.line - b.line);
|
|
79
|
+
return { status: 'ok', points, dropped };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** the one question, worded by code @param {DestPoint} p @param {string} destination @returns {string} */
|
|
83
|
+
export const destQuestionText = (p, destination) => redactSecrets(
|
|
84
|
+
`Line ${p.line} needs ${p.file} changed, but Destination is ${destination.trim().replace(/\s*\n\s*/g, ', ')}, so the job could not change it. Set Destination to ${p.folder}? Type yes to set it, or no to keep it as it is.`,
|
|
85
|
+
);
|
|
86
|
+
/** the answers (any case, a closing full stop allowed) @param {unknown} text @returns {'yes'|'no'|null} */
|
|
87
|
+
export const yesNoOf = (text) => {
|
|
88
|
+
const t = String(text ?? '').trim().replace(/\.$/, '').toLowerCase();
|
|
89
|
+
return t === 'yes' || t === 'y' ? 'yes' : (t === 'no' || t === 'n' ? 'no' : null);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const defaultLoop = (/** @type {any} */ { system, onLlmResult, provider, rates }) =>
|
|
93
|
+
new Loop({ provider, system, onLlmResult, ...(rates ? { rates } : {}) });
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Run the pointing call: one call (one retry on a malformed reply, a transport failure or a 429). Never throws on a call casualty; every failure is `absent` (no question).
|
|
97
|
+
* @param {{jobLines: {n: number, text: string}[], files: readonly string[], destination: string, provider?: any, maxTokens?: number, ceilingUsd?: number|null,
|
|
98
|
+
* callTimeoutMs?: number, onCall?: (call: {label: string, costUsd: number|null, unpricedRounds: number, thinkingStatus?: string, raw?: string}) => void,
|
|
99
|
+
* createLoop?: Function, rates?: {in: number, out: number}|null, callOptions?: Record<string, any>, sleep?: (ms: number) => Promise<void>}} o
|
|
100
|
+
* @returns {Promise<{state: 'point'|'none'|'absent', point: DestPoint|null, reason: string|null, calls: {label: string, costUsd: number|null, unpricedRounds: number}[]}>}
|
|
101
|
+
*/
|
|
102
|
+
export async function runDestPoint({
|
|
103
|
+
jobLines, files, destination, provider = null, maxTokens = AUTHOR_SCOUT_MAX_TOKENS, ceilingUsd = null, callTimeoutMs = AUTHOR_CALL_TIMEOUT_MS,
|
|
104
|
+
onCall = () => {}, createLoop = defaultLoop, rates = null, callOptions = {}, sleep = (ms) => new Promise((r) => setTimeout(r, ms)),
|
|
105
|
+
}) {
|
|
106
|
+
const callTimeout = Number.isFinite(Number(callTimeoutMs)) && Number(callTimeoutMs) > 0 ? Math.min(Math.trunc(Number(callTimeoutMs)), AUTHOR_CALL_TIMEOUT_MS) : AUTHOR_CALL_TIMEOUT_MS;
|
|
107
|
+
const priced = rates ? { rates } : {};
|
|
108
|
+
/** @type {{label: string, costUsd: number|null, unpricedRounds: number}[]} */
|
|
109
|
+
const calls = [];
|
|
110
|
+
let attempts = 0;
|
|
111
|
+
const record = (/** @type {any} */ r) => {
|
|
112
|
+
const call = { label: DEST_CALL_LABEL, ...priceOf(r) };
|
|
113
|
+
calls.push(call);
|
|
114
|
+
const raw = scrubRaw({ label: DEST_CALL_LABEL, attempt: attempts, text: r?.text });
|
|
115
|
+
onCall({ ...call, raw: raw.text, ...(r?.thinkingStatus === undefined ? {} : { thinkingStatus: r.thinkingStatus }) });
|
|
116
|
+
};
|
|
117
|
+
const absent = (/** @type {string} */ reason) => ({ state: /** @type {'absent'} */ ('absent'), point: null, reason, calls });
|
|
118
|
+
const content = destPrompt({ jobLines, destination });
|
|
119
|
+
let malformed = 0;
|
|
120
|
+
let transportRetried = false;
|
|
121
|
+
let rateRetried = false;
|
|
122
|
+
for (;;) {
|
|
123
|
+
if (capStop({ ceilingUsd, ...tallyCalls(calls) })) return absent('the folder check was not made: the spend ceiling was reached');
|
|
124
|
+
attempts += 1;
|
|
125
|
+
const loop = createLoop({ system: DEST_SYSTEM, onLlmResult: undefined, provider, ...priced });
|
|
126
|
+
/** @type {any} */
|
|
127
|
+
let r;
|
|
128
|
+
try {
|
|
129
|
+
r = await loop.run([{ role: 'user', content }], [], { cacheMessages: true, maxTokens, timeoutMs: callTimeout, ...callOptions });
|
|
130
|
+
} catch (e) {
|
|
131
|
+
if (isRateLimited(e) && !rateRetried) {
|
|
132
|
+
const wait = rateLimitWaitMs(e);
|
|
133
|
+
if (wait !== null) { rateRetried = true; await sleep(wait); continue; }
|
|
134
|
+
}
|
|
135
|
+
const casualty = callCasualty(e) ?? (isTransportFailure(e) ? String(/** @type {any} */ (e)?.message ?? e) : null);
|
|
136
|
+
if (casualty === null) throw e;
|
|
137
|
+
record({ error: casualty });
|
|
138
|
+
if (!transportRetried) { transportRetried = true; continue; }
|
|
139
|
+
return absent(`the folder check call failed: ${redactSecrets(casualty)}`);
|
|
140
|
+
}
|
|
141
|
+
record(r);
|
|
142
|
+
if (isOutputCutOff(r)) return absent('the folder check answer was cut off');
|
|
143
|
+
if (r?.error) return absent(`the folder check call failed: ${redactSecrets(String(r.error))}`);
|
|
144
|
+
const d = decideDestPoint(r?.text, { jobLines, files, destination });
|
|
145
|
+
if (d.status === 'ok') return { state: d.points.length > 0 ? 'point' : 'none', point: d.points[0] ?? null, reason: null, calls };
|
|
146
|
+
malformed += 1;
|
|
147
|
+
if (malformed >= 2) return absent('the folder check answer was not readable twice');
|
|
148
|
+
}
|
|
149
|
+
}
|
package/src/draftspend.js
CHANGED
|
@@ -243,6 +243,43 @@ export function readDraftSteps(dir) {
|
|
|
243
243
|
return steps;
|
|
244
244
|
}
|
|
245
245
|
|
|
246
|
+
/**
|
|
247
|
+
* fwd am14 item 6: the label this draft's record carries (`revise 1`, `revise 2`, `start over`; src/revises.js `draftLabelOf` owns the words), or null for a first draft.
|
|
248
|
+
* @param {string} dir
|
|
249
|
+
* @returns {string|null}
|
|
250
|
+
*/
|
|
251
|
+
export function readDraftLabel(dir) {
|
|
252
|
+
/** @type {string} */
|
|
253
|
+
let text;
|
|
254
|
+
try { text = readFileSync(join(dir, DRAFT_LOG_FILE), 'utf8'); } catch { return null; }
|
|
255
|
+
for (const line of text.split('\n')) {
|
|
256
|
+
if (!line.includes('"draft-label"')) continue;
|
|
257
|
+
try { const ev = JSON.parse(line); if (ev?.kind === 'draft-label' && typeof ev.label === 'string') return ev.label; } catch { /* a torn line */ }
|
|
258
|
+
}
|
|
259
|
+
return null;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* The checks the draft ended with, each marked who added it (`agent` = the drafter, `you` = the person's own pick): the last `draft-checks` line of the log, or `[]` (a draft from before it, or a job that has none).
|
|
264
|
+
* @param {string} dir
|
|
265
|
+
* @returns {{line: number, text: string, by: 'agent'|'you'}[]}
|
|
266
|
+
*/
|
|
267
|
+
export function readDraftChecks(dir) {
|
|
268
|
+
/** @type {string} */
|
|
269
|
+
let text;
|
|
270
|
+
try { text = readFileSync(join(dir, DRAFT_LOG_FILE), 'utf8'); } catch { return []; }
|
|
271
|
+
/** @type {{line: number, text: string, by: 'agent'|'you'}[]} */
|
|
272
|
+
let out = [];
|
|
273
|
+
for (const line of text.split('\n')) {
|
|
274
|
+
if (!line.includes('"draft-checks"')) continue;
|
|
275
|
+
try {
|
|
276
|
+
const ev = JSON.parse(line);
|
|
277
|
+
if (ev?.kind === 'draft-checks' && Array.isArray(ev.checks)) out = ev.checks.filter((/** @type {any} */ c) => c && Number.isInteger(c.line) && typeof c.text === 'string' && (c.by === 'agent' || c.by === 'you'));
|
|
278
|
+
} catch { /* a torn line */ }
|
|
279
|
+
}
|
|
280
|
+
return out;
|
|
281
|
+
}
|
|
282
|
+
|
|
246
283
|
/**
|
|
247
284
|
* The DRAFTING PART of a run (hamr 2026-10-06, option A): the first part of the run's views, built from the session's
|
|
248
285
|
* drafting log. `null` when the run did not come out of a panel session, or the log carries no metered call (a Reuse
|
|
@@ -268,5 +305,7 @@ export function draftingPartFor(row, spine, opts = {}) {
|
|
|
268
305
|
wallMs: starts.length && ends.length ? Math.max(0, Math.max(...ends) - Math.min(...starts)) : null,
|
|
269
306
|
spentUsd: spine.draftSpentUsd, spendComplete: spine.draftSpendComplete !== false, unpricedRounds: 0,
|
|
270
307
|
draftSteps: steps,
|
|
308
|
+
draftLabel: readDraftLabel(dir),
|
|
309
|
+
draftChecks: readDraftChecks(dir),
|
|
271
310
|
};
|
|
272
311
|
}
|
package/src/factwords.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// Compared WHITE-SPACE BLIND: any run of white space (U+202F and U+00A0 included - Google writes U+202F before AM/PM, 259 times in one
|
|
7
7
|
// page) is one space on both sides.
|
|
8
8
|
|
|
9
|
-
import { labelOnList, normLabel, scanLabels } from './labelscan.js';
|
|
9
|
+
import { labelOnList, normLabel, scanLabels, renderLabelList, renderKeptLabelList } from './labelscan.js';
|
|
10
10
|
import { asList } from './facts.js';
|
|
11
11
|
import { dropSentence } from './pagedropwords.js';
|
|
12
12
|
|
|
@@ -73,6 +73,19 @@ export function keptSetOf(look, source) {
|
|
|
73
73
|
};
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
/**
|
|
77
|
+
* The label lists the drafter is told, one per input: ONE owner with the proof above. An input the page-word map read (a look with a
|
|
78
|
+
* `dropped` list) is offered the labels `keptSetOf` accepts, nothing else; any other input keeps the code-made list the proof reads.
|
|
79
|
+
* @param {Record<string, string>} texts @param {Parameters<typeof keptSetOf>[0]} look
|
|
80
|
+
* @returns {string[]}
|
|
81
|
+
*/
|
|
82
|
+
export function labelListsFor(texts, look) {
|
|
83
|
+
return Object.entries(texts).map(([label, text]) => {
|
|
84
|
+
const kept = keptSetOf(look, label);
|
|
85
|
+
return kept ? renderKeptLabelList(label, [...kept.labels]) : renderLabelList(label, scanLabels(text));
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
76
89
|
/**
|
|
77
90
|
* The reds for ONE fact part against its frozen source text.
|
|
78
91
|
* @param {{part: any, text: string, line: number|string, scan?: import('./labelscan.js').LabelScan, kept?: ReturnType<typeof keptSetOf>}} o
|
package/src/job.js
CHANGED
|
@@ -19,7 +19,9 @@ import { validateCloseDecl, DECLARED_CLOSE_CLASSES } from './declaredclose.js';
|
|
|
19
19
|
import { inputLabelsOf } from './rubricstep.js';
|
|
20
20
|
import { CLOSE_TIMEOUT_FLOOR_MS } from './closetimeout.js';
|
|
21
21
|
import { validateTrigger } from './trigger.js';
|
|
22
|
+
import { WATCHABLE } from './ticketshape.js';
|
|
22
23
|
import { resolveJobJudge } from './judged.js';
|
|
24
|
+
import { ticketFilterReds } from './ticketfilter.js';
|
|
23
25
|
|
|
24
26
|
// The menus below ARE the close-authoring hierarchy (PRD §7) and ship frozen:
|
|
25
27
|
// they are read at call time, so a mutable export would let adopter code
|
|
@@ -170,7 +172,7 @@ export const CONDITION_KEYS = Object.freeze(['providerPath', 'closeVerbosity', '
|
|
|
170
172
|
// `steps` stays in the field list ONLY so a retired spec reds by name
|
|
171
173
|
// (`shape-retired`) instead of falling through to a generic unknown-field —
|
|
172
174
|
// the operator gets told what happened, not just that something is wrong.
|
|
173
|
-
const JOB_FIELDS = ['schema', 'job', 'description', 'provider', 'baseUrl', 'conditions', 'cadence', 'trigger', 'budgetUsd', 'maxWallMs', 'closeTimeoutMs', 'model', 'thinking', 'handoffNote', 'seedNote', 'readMap', 'judge', 'writeScope', 'steps', 'escalation', 'goal', 'verdictType', 'close', 'closeDecl', 'checks', 'tools', 'jobLines', 'inputs'];
|
|
175
|
+
const JOB_FIELDS = ['schema', 'job', 'description', 'provider', 'baseUrl', 'conditions', 'cadence', 'trigger', 'budgetUsd', 'maxWallMs', 'closeTimeoutMs', 'model', 'thinking', 'handoffNote', 'seedNote', 'mcp', 'flowType', 'ticketFilter', 'ticketWatch', 'readMap', 'judge', 'writeScope', 'steps', 'escalation', 'goal', 'verdictType', 'close', 'closeDecl', 'checks', 'tools', 'jobLines', 'inputs'];
|
|
174
176
|
/** the exact fields of a signed `judge` override — nested objects red unknown
|
|
175
177
|
* keys too, because no smuggling level exists in a signed spec */
|
|
176
178
|
const JUDGE_FIELDS = ['provider', 'model'];
|
|
@@ -231,6 +233,79 @@ export function validateBaseUrl(value) {
|
|
|
231
233
|
return 'https:// required (http:// admitted only to 127.0.0.1/localhost/::1)';
|
|
232
234
|
}
|
|
233
235
|
|
|
236
|
+
/** the job's flow types; `flowType` is set by code from the job card and signed with the job (fwdloop M13 piece 4) */
|
|
237
|
+
export const FLOW_TYPES = Object.freeze(['plain', 'mcp', 'tickets']);
|
|
238
|
+
|
|
239
|
+
/** the words the card's Flow type menu and the Job tab use for each flow type (fwd's am2 names) */
|
|
240
|
+
export const FLOW_TYPE_LABELS = Object.freeze({ plain: 'plain', mcp: 'MCP', tickets: 'Tickets MCP' });
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* The ONE reader of a job's flow type: the field when present; an `mcp` block with no `flowType` is a Tickets job; no `mcp` block is plain.
|
|
244
|
+
* @param {Record<string, any>} spec @returns {'plain'|'mcp'|'tickets'}
|
|
245
|
+
*/
|
|
246
|
+
export function flowTypeOf(spec) {
|
|
247
|
+
if (typeof spec?.flowType === 'string' && FLOW_TYPES.includes(spec.flowType)) return /** @type {any} */ (spec.flowType);
|
|
248
|
+
return spec?.mcp ? 'tickets' : 'plain';
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** the shape of an MCP server or tool name in a job (the bridge names a tool `<server>_<tool>`) */
|
|
252
|
+
const MCP_NAME = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Validate `mcp`, `flowType`, `ticketFilter`, `ticketWatch` (all optional; a spec without them is unchanged). Reds name the field and the legal shape.
|
|
256
|
+
* @param {Record<string, any>} spec @param {(code: string, path: string, detail?: string) => void} red
|
|
257
|
+
*/
|
|
258
|
+
function checkMcpFields(spec, red) {
|
|
259
|
+
const has = (/** @type {string} */ k) => spec[k] !== undefined;
|
|
260
|
+
const hasMcp = has('mcp');
|
|
261
|
+
if (hasMcp) {
|
|
262
|
+
const m = spec.mcp;
|
|
263
|
+
if (!isObj(m)) red('invalid-value', 'mcp', 'an object {server, tools}');
|
|
264
|
+
else {
|
|
265
|
+
for (const key of Object.keys(m)) if (key !== 'server' && key !== 'tools') red('unknown-field', `mcp.${key}`, 'declared keys only: server|tools');
|
|
266
|
+
if (typeof m.server !== 'string' || !MCP_NAME.test(m.server)) red('invalid-value', 'mcp.server', 'a plain server name (letters, digits, _ or -)');
|
|
267
|
+
if (!Array.isArray(m.tools) || m.tools.length === 0) red('invalid-value', 'mcp.tools', 'a non-empty list of tool names');
|
|
268
|
+
else {
|
|
269
|
+
const seen = new Set();
|
|
270
|
+
for (const t of m.tools) {
|
|
271
|
+
if (typeof t !== 'string' || !MCP_NAME.test(t)) red('invalid-value', 'mcp.tools', `names ${JSON.stringify(t)}, which is not a plain tool name`);
|
|
272
|
+
else if (seen.has(t)) red('invalid-value', 'mcp.tools', `names "${t}" twice`);
|
|
273
|
+
else seen.add(t);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
if (has('flowType')) {
|
|
279
|
+
const t = spec.flowType;
|
|
280
|
+
if (typeof t !== 'string' || !FLOW_TYPES.includes(t)) red('invalid-value', 'flowType', `one of ${FLOW_TYPES.join(', ')}`);
|
|
281
|
+
else {
|
|
282
|
+
if (t === 'plain' && hasMcp) red('invalid-value', 'flowType', 'a "plain" job takes no "mcp" server');
|
|
283
|
+
if (t !== 'plain' && !hasMcp) red('invalid-value', 'flowType', `a "${t}" job needs an "mcp" server`);
|
|
284
|
+
if (t !== 'tickets') {
|
|
285
|
+
if (has('ticketFilter')) red('invalid-value', 'ticketFilter', 'belongs to a Tickets MCP job');
|
|
286
|
+
if (has('ticketWatch')) red('invalid-value', 'ticketWatch', 'belongs to a Tickets MCP job');
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
if (has('ticketFilter')) {
|
|
291
|
+
// ONE reader of a legal filter (src/ticketfilter.js), shared with the drafter's proposal
|
|
292
|
+
for (const r of ticketFilterReds(spec.ticketFilter, { hasMcp })) red(r.code, r.path, r.detail);
|
|
293
|
+
}
|
|
294
|
+
if (has('ticketWatch')) {
|
|
295
|
+
const w = spec.ticketWatch;
|
|
296
|
+
if (!Array.isArray(w) || w.length === 0) red('invalid-value', 'ticketWatch', `a non-empty list of fields (${WATCHABLE.join(' and ')})`);
|
|
297
|
+
else {
|
|
298
|
+
if (!hasMcp) red('invalid-value', 'ticketWatch', 'watches tickets read through the job\'s "mcp" tools, but the job lists no "mcp" server');
|
|
299
|
+
const seen = new Set();
|
|
300
|
+
for (const f of w) {
|
|
301
|
+
if (typeof f !== 'string' || !WATCHABLE.includes(f)) red('invalid-value', 'ticketWatch', `names ${JSON.stringify(f)}, which is not a field that can be watched (${WATCHABLE.join(' and ')})`);
|
|
302
|
+
else if (seen.has(f)) red('invalid-value', 'ticketWatch', `names "${f}" twice`);
|
|
303
|
+
else seen.add(f);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
234
309
|
/**
|
|
235
310
|
* Validate an operator-owned job spec (`schema: "job-v1"`). Never throws on
|
|
236
311
|
* JSON text or plain parsed data — the ingest contract; a live object with a
|
|
@@ -361,6 +436,11 @@ export function validateJob(input, { shellCapUsd = 2 } = {}) {
|
|
|
361
436
|
red('invalid-value', 'seedNote', 'true or false (absent = on): whether the planner and the first worker are told what the job\'s own count check said on the untouched tree');
|
|
362
437
|
}
|
|
363
438
|
|
|
439
|
+
// THE MCP SOURCE AND TICKET FIELDS (ITEM33-BUILD, MCP+tickets piece 1): `mcp {server, tools}`, `flowType`, `ticketFilter`, `ticketWatch`.
|
|
440
|
+
// Signed like `seedNote`: ABSENT keeps every old spec's bytes, so its hash. Set by CODE from the person's card pick, never by the drafter
|
|
441
|
+
// (assembleSpec refuses a draft carrying them). Validated here; the run-start reader is src/ticketmcp.js.
|
|
442
|
+
checkMcpFields(spec, red);
|
|
443
|
+
|
|
364
444
|
// THE FIRST-READ MAP (src/readshim.js, EXPERIMENTAL): a declared job condition, signed like `thinking`. A boolean; ABSENT = off (an old spec keeps
|
|
365
445
|
// its bytes, so its hash), `true` makes the first shell_read of a big non-test file in an ask return a map of its parts. The switch is hashed.
|
|
366
446
|
if (spec.readMap !== undefined && typeof spec.readMap !== 'boolean') {
|
package/src/jobblock.js
CHANGED
|
@@ -90,6 +90,15 @@ export function renderJobLines(lines) {
|
|
|
90
90
|
return lines.map((l) => `${l.n}. ${l.text}${l.rule ? `\n rule: ${l.rule}` : ''}`).join('\n');
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
+
/**
|
|
94
|
+
* The job lines as the job BOX reads them (R10): each line's text, then one `~` line per rule. The inverse of {@link parseJobBlock}, so a card reopened by a Revise holds
|
|
95
|
+
* the `~` lines the person's answers added.
|
|
96
|
+
* @param {{text: string, rules: string[]}[]} lines @returns {string}
|
|
97
|
+
*/
|
|
98
|
+
export function jobBoxText(lines) {
|
|
99
|
+
return lines.map((l) => [l.text, ...l.rules.map((r) => `~ ${r}`)].join('\n')).join('\n');
|
|
100
|
+
}
|
|
101
|
+
|
|
93
102
|
/**
|
|
94
103
|
* The PASS:/FAIL: examples the person wrote, each kept with its line number (answer 2 of a rubric interview — what the
|
|
95
104
|
* calibration compile reads). Empty string when there are none.
|
package/src/labelscan.js
CHANGED
|
@@ -177,3 +177,14 @@ export function renderLabelList(inputLabel, scan) {
|
|
|
177
177
|
});
|
|
178
178
|
return `LABELS IN THE INPUT "${inputLabel}" - pick a label ONLY from this list (by its id or its exact words); a label that is not here is refused:\n\n${blocks.length ? blocks.join('\n\n') : '(no repeated label was found before a value)'}`;
|
|
179
179
|
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* The list a page-word map input is shown: ONLY the labels the map kept (what the draft gate's `keptSetOf` accepts), so the prompt and the
|
|
183
|
+
* proof read the same words. Empty = no label was kept, so the drafter leaves the label out.
|
|
184
|
+
* @param {string} inputLabel @param {string[]} labels
|
|
185
|
+
* @returns {string}
|
|
186
|
+
*/
|
|
187
|
+
export function renderKeptLabelList(inputLabel, labels) {
|
|
188
|
+
return `LABELS IN THE INPUT "${inputLabel}" - pick a label ONLY from this list (its exact words); a label that is not here is refused:\n\n`
|
|
189
|
+
+ (labels.length ? labels.map((l) => ` ${JSON.stringify(l)}`).join('\n') : '(the page words kept no label for this input - leave the label out of every fact)');
|
|
190
|
+
}
|
package/src/launcher.js
CHANGED
|
@@ -13,6 +13,7 @@ import { createServer } from 'node:net';
|
|
|
13
13
|
import { spawn as realSpawn } from 'node:child_process';
|
|
14
14
|
import { dirname, join } from 'node:path';
|
|
15
15
|
import { fileURLToPath } from 'node:url';
|
|
16
|
+
import { npmEnv } from './npminstall.js';
|
|
16
17
|
import { readConfig, updateConfig, ConfigError } from './config.js';
|
|
17
18
|
import { keysHome, keysFilePath, ensureKeysFile } from './keysfile.js';
|
|
18
19
|
import { openInOs } from './opener.js';
|
|
@@ -67,7 +68,7 @@ const RULE_WIDTH = 56;
|
|
|
67
68
|
* @property {import('./tty-colour.js').Paint} [paintErr] colour for stderr lines (default: `paint`)
|
|
68
69
|
* @property {number} [now] ms clock for the run list's age rules (default: real time); tests pass their own
|
|
69
70
|
* @property {string} [platform]
|
|
70
|
-
* @property {Record<string, string|undefined>} [env] raw env handed to the panel child (default process.env)
|
|
71
|
+
* @property {Record<string, string|undefined>} [env] raw env: handed whole to the panel child, stripped by npmEnv for the update npm child (default process.env)
|
|
71
72
|
*/
|
|
72
73
|
|
|
73
74
|
/**
|
|
@@ -349,7 +350,7 @@ export async function updateCmd(io, d, shown) {
|
|
|
349
350
|
let timer;
|
|
350
351
|
const end = (/** @type {boolean} */ v) => { clearTimeout(timer); resolve(v); };
|
|
351
352
|
try {
|
|
352
|
-
const child = (d.npmSpawn ?? realSpawn)('npm', ['install', '-g', 'bareloop@latest'], { stdio: 'inherit' });
|
|
353
|
+
const child = (d.npmSpawn ?? realSpawn)('npm', ['install', '-g', 'bareloop@latest'], { stdio: 'inherit', env: npmEnv(d.env ?? process.env) });
|
|
353
354
|
// not in the signed text: npm may run this long, then its own child is ended (aligned with fwdloop)
|
|
354
355
|
timer = setTimeout(() => { try { child.kill('SIGTERM'); } catch { /* already gone */ } end(false); }, d.npmDeadlineMs ?? NPM_DEADLINE_MS);
|
|
355
356
|
child.once('error', () => end(false));
|
package/src/mcpchecks.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// borrowed-from: fwdloop src/mcp-checks.js@6f9bd72 (the config home is bareloop's `keysHome`; the "newest OK tools" reader is kept for the New job card, R4)
|
|
2
|
+
// The log of `check tools` presses: `mcp-checks.jsonl` beside config.json in the config home. APPEND-ONLY: each press appends one line, nothing is ever rewritten or
|
|
3
|
+
// removed. A line is `{server, path, at, ok, tools:[{name, hint}]}` or `{server, path, at, ok:false, error}`. A tool row is a NAME and a hint (`read-only` or null),
|
|
4
|
+
// an error is a fixed plain sentence: no env value, no command line and no key is ever written here. The page shows the newest line per path and server.
|
|
5
|
+
// A torn or foreign line is skipped when reading, so a half-written last line never hides the earlier ones.
|
|
6
|
+
import { appendFileSync, mkdirSync, readFileSync } from 'node:fs';
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
import { keysHome } from './keysfile.js';
|
|
9
|
+
|
|
10
|
+
export const MCP_CHECKS_FILE = 'mcp-checks.jsonl';
|
|
11
|
+
|
|
12
|
+
/** @param {string|undefined} home the config home (undefined = `~/.config/bareloop`) */
|
|
13
|
+
export const mcpChecksFile = (home) => join(keysHome(home), MCP_CHECKS_FILE);
|
|
14
|
+
|
|
15
|
+
/** append ONE line; throws when it cannot be written @param {string|undefined} home @param {Record<string, any>} entry */
|
|
16
|
+
export function appendMcpCheck(home, entry) {
|
|
17
|
+
mkdirSync(keysHome(home), { recursive: true, mode: 0o700 });
|
|
18
|
+
appendFileSync(mcpChecksFile(home), `${JSON.stringify(entry)}\n`, { mode: 0o600 });
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** every well-formed line, oldest first; none when the file is missing @param {string|undefined} home @returns {any[]} */
|
|
22
|
+
function checkLines(home) {
|
|
23
|
+
let text = '';
|
|
24
|
+
try { text = readFileSync(mcpChecksFile(home), 'utf8'); } catch { return []; }
|
|
25
|
+
const out = [];
|
|
26
|
+
for (const line of text.split('\n')) {
|
|
27
|
+
let r;
|
|
28
|
+
try { r = JSON.parse(line); } catch { continue; }
|
|
29
|
+
if (typeof r?.server !== 'string' || typeof r?.path !== 'string' || typeof r?.at !== 'string') continue;
|
|
30
|
+
out.push(r);
|
|
31
|
+
}
|
|
32
|
+
return out;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** the newest line per `path\tserver` @param {string|undefined} home @returns {Map<string, any>} */
|
|
36
|
+
export function newestMcpChecks(home) {
|
|
37
|
+
const out = new Map();
|
|
38
|
+
for (const r of checkLines(home)) out.set(`${r.path}\t${r.server}`, r);
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** the tool names of the newest OK line (with at least one tool) for this server at this path, or null @param {string|undefined} home @param {string} server @param {string} path @returns {string[]|null} */
|
|
43
|
+
export function newestOkMcpTools(home, server, path) {
|
|
44
|
+
/** @type {string[]|null} */
|
|
45
|
+
let tools = null;
|
|
46
|
+
for (const r of checkLines(home)) {
|
|
47
|
+
if (r.server !== server || r.path !== path || r.ok !== true || !Array.isArray(r.tools)) continue;
|
|
48
|
+
const names = r.tools.map((/** @type {any} */ x) => x?.name).filter((/** @type {unknown} */ n) => typeof n === 'string' && n !== '');
|
|
49
|
+
if (names.length > 0) tools = [...new Set(names)];
|
|
50
|
+
}
|
|
51
|
+
return tools;
|
|
52
|
+
}
|
package/src/mcppick.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// borrowed-from: fwdloop src/mcp-pick.js@d18d65b (imports are bareloop's: the config home is `keysHome`, the person's home folder is `mcpHome`)
|
|
2
|
+
// The ONE place that decides the tools a job gets from its MCP. A job with an MCP gets ALL the tools of that MCP's newest OK line in `mcp-checks.jsonl` (src/mcpchecks.js),
|
|
3
|
+
// set by code: never chosen by the drafter, never reviewed by the person, and no server is ever started here (a server starts only on a press of `check tools`).
|
|
4
|
+
// A tool the server gains later is not in the job. Read-only; writes nothing.
|
|
5
|
+
import { newestOkMcpTools } from './mcpchecks.js';
|
|
6
|
+
import { mcpSources, mcpConfigFor } from './mcpsources.js';
|
|
7
|
+
import { remoteRefusal } from './ticketmcp.js';
|
|
8
|
+
|
|
9
|
+
/** the one refusal for an MCP nobody has checked (or whose check never succeeded) */
|
|
10
|
+
export const NEVER_CHECKED_SAY = 'press check tools in Settings > MCP first';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param {string} server
|
|
14
|
+
* @param {{ home?: string, mcpHome?: string }} [o] `home` the config home (undefined = `~/.config/bareloop`); `mcpHome` the person's home folder the MCP config places live under (tests inject one)
|
|
15
|
+
* @returns {{ ok: true, server: string, tools: string[] } | { ok: false, say: string }}
|
|
16
|
+
*/
|
|
17
|
+
export function mcpPickFor(server, o = {}) {
|
|
18
|
+
const place = mcpSources(o).places.find((p) => p.servers.some((s) => s.name === server));
|
|
19
|
+
if (!place) return { ok: false, say: `${server} is not in any MCP config (Settings > MCP lists the ones found)` };
|
|
20
|
+
if (mcpConfigFor(server, o)?.remote) return { ok: false, say: remoteRefusal(server) };
|
|
21
|
+
const tools = newestOkMcpTools(o.home, server, place.path);
|
|
22
|
+
return tools === null ? { ok: false, say: NEVER_CHECKED_SAY } : { ok: true, server, tools };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The spec with the card's flow type and MCP pick signed into it. A `plain` pick writes NOTHING (no `flowType` key, no `mcp`), so every plain job keeps the hash it had before
|
|
27
|
+
* the card had these controls. The `mcp` block is the pick's server and EVERY tool of its newest check; the agent never sets it (`assembleSpec` refuses a draft that carries it).
|
|
28
|
+
* @template {Record<string, any>} T
|
|
29
|
+
* R5: a Tickets job also signs the drafter's PROPOSED `ticketFilter` (already read by `ticketFilterReds`), if it made one: the person signs the whole hash. Never on an `mcp` job.
|
|
30
|
+
* @param {T} spec @param {'plain'|'mcp'|'tickets'} flowType @param {{ server: string, tools: string[] }|null} pick @param {{priority?: string[], labels?: string[]}|undefined} [ticketFilter]
|
|
31
|
+
* @returns {T}
|
|
32
|
+
*/
|
|
33
|
+
export function signFlow(spec, flowType, pick, ticketFilter = undefined) {
|
|
34
|
+
if (flowType === 'plain' || pick === null) return spec;
|
|
35
|
+
return { ...spec, flowType, mcp: { server: pick.server, tools: [...pick.tools] }, ...(flowType === 'tickets' && ticketFilter !== undefined ? { ticketFilter } : {}) };
|
|
36
|
+
}
|