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
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
// MCP + tickets piece 12 (ITEM33-BUILD addendum, "Piece 12 - check out the PR's code (head) into the run's worktree"): at RUN START, before the work branch and the seed
|
|
2
|
+
// read, the run's own worktree is moved to the head commit of a GitHub pull request. Plain git against the remote of the person's repo that names the PR's
|
|
3
|
+
// `owner/repo`; never the MCP, never a URL built from ticket text, never a push. The head sha comes from the frozen PR record through ONE accessor (`prHeadSha`).
|
|
4
|
+
//
|
|
5
|
+
// What this file is NOT: a PR reader. The frozen PR record is made by a reader that does not exist yet (its MCP tool name and toolset are an OPEN item for hamr).
|
|
6
|
+
// This file consumes a record that carries `head.sha` and refuses, in the spec's words, when it does not.
|
|
7
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
8
|
+
import { join, resolve } from 'node:path';
|
|
9
|
+
import { spawnClose } from './ralph.js';
|
|
10
|
+
import { npmEnv as credentialStrippedEnv } from './npminstall.js';
|
|
11
|
+
import { redactSecrets } from './validate.js';
|
|
12
|
+
import { prRefName, removePrRef } from './worktree.js';
|
|
13
|
+
|
|
14
|
+
export { prRefName };
|
|
15
|
+
|
|
16
|
+
/** the ONLY git subcommands this piece may run (spec item 10a): anything else throws before a process is made. Nothing that writes to a remote, to the person's config or to their index is on the list. */
|
|
17
|
+
export const PR_GIT_SUBCOMMANDS = Object.freeze(['fetch', 'rev-parse', 'checkout', 'merge-base', 'update-ref', 'worktree']);
|
|
18
|
+
|
|
19
|
+
/** the hard deadline of the fetch, in ms (spec item 3: 120 s; tighten-only, like the other clamps) */
|
|
20
|
+
export const PR_FETCH_DEADLINE_MS = 120_000;
|
|
21
|
+
|
|
22
|
+
/** none of the person's git hooks run for anything this piece does (the same spelling as src/worktree.js) */
|
|
23
|
+
const NO_HOOKS = Object.freeze(['-c', 'core.hooksPath=/dev/null/bareloop-no-hooks']);
|
|
24
|
+
|
|
25
|
+
/** the belt of spec item 10c: even if something tried a push through the fetching remote, its push address is a dead word */
|
|
26
|
+
const NO_PUSH = 'no-push-by-bareloop';
|
|
27
|
+
|
|
28
|
+
const PR_URL = /^https:\/\/github\.com\/([^/\s]+)\/([^/\s]+)\/pull\/(\d{1,10})\/?$/;
|
|
29
|
+
const SHA = /^[0-9a-f]{40}$/;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The PR address a ticket list gives: `https://github.com/<owner>/<repo>/pull/<n>`.
|
|
33
|
+
* @param {unknown} url
|
|
34
|
+
* @returns {{ok: true, owner: string, repo: string, number: number}|{ok: false, error: string}}
|
|
35
|
+
*/
|
|
36
|
+
export function parsePrAddress(url) {
|
|
37
|
+
const m = typeof url === 'string' ? PR_URL.exec(url.trim()) : null;
|
|
38
|
+
if (!m) return { ok: false, error: 'This is not a GitHub pull request address.' };
|
|
39
|
+
const number = Number(m[3]);
|
|
40
|
+
if (!Number.isSafeInteger(number) || number < 1) return { ok: false, error: 'This is not a GitHub pull request address.' };
|
|
41
|
+
return { ok: true, owner: m[1], repo: m[2], number };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* THE one accessor of the frozen PR record's head commit: GitHub's own `head.sha`. Everything in this file reads the head through here, so the day the reader's record
|
|
46
|
+
* names it differently there is one line to change. A record without a full 40-hex sha has no head (null).
|
|
47
|
+
* @param {any} record @returns {string|null}
|
|
48
|
+
*/
|
|
49
|
+
export function prHeadSha(record) {
|
|
50
|
+
const sha = record?.head?.sha;
|
|
51
|
+
return typeof sha === 'string' && SHA.test(sha) ? sha : null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** the PR's base as the record gives it (`base.ref`, `base.sha`), or null when it names none @param {any} record @returns {{ref: string|null, sha: string}|null} */
|
|
55
|
+
export function prBaseOf(record) {
|
|
56
|
+
const sha = record?.base?.sha;
|
|
57
|
+
if (typeof sha !== 'string' || !SHA.test(sha)) return null;
|
|
58
|
+
return { ref: typeof record.base.ref === 'string' ? record.base.ref : null, sha };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The remotes a git config text declares, with their addresses AS WRITTEN (before any `insteadOf` rewrite): `[remote "name"]` sections, `url = ...` lines.
|
|
63
|
+
* Read from the config file instead of `git remote`, which would need a subcommand this piece is not allowed and prints the rewritten address.
|
|
64
|
+
* @param {string} text @returns {{name: string, url: string}[]}
|
|
65
|
+
*/
|
|
66
|
+
export function remotesOfConfig(text) {
|
|
67
|
+
/** @type {{name: string, url: string}[]} */
|
|
68
|
+
const out = [];
|
|
69
|
+
let name = null;
|
|
70
|
+
for (const raw of text.split('\n')) {
|
|
71
|
+
const line = raw.trim();
|
|
72
|
+
const head = /^\[\s*([A-Za-z0-9.-]+)(?:\s+"((?:[^"\\]|\\.)*)")?\s*\]/.exec(line);
|
|
73
|
+
if (head) { name = head[1].toLowerCase() === 'remote' && head[2] !== undefined ? head[2].replace(/\\(.)/g, '$1') : null; continue; }
|
|
74
|
+
if (name === null) continue;
|
|
75
|
+
const kv = /^url\s*=\s*(.*)$/i.exec(line);
|
|
76
|
+
if (kv) out.push({ name, url: kv[1].trim().replace(/^"(.*)"$/, '$1') });
|
|
77
|
+
}
|
|
78
|
+
return out;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Does a remote address name `github.com/<owner>/<repo>`? https, ssh:// and the scp-like `git@github.com:owner/repo.git` forms; case-blind, `.git` optional.
|
|
83
|
+
* @param {string} url @param {string} owner @param {string} repo
|
|
84
|
+
*/
|
|
85
|
+
export function remoteNames(url, owner, repo) {
|
|
86
|
+
const m = /^(?:[a-z][a-z0-9+.-]*:\/\/)?(?:[^/@\s]*@)?github\.com[:/]([^/\s]+)\/([^/\s]+?)(?:\.git)?\/?$/i.exec(url.trim());
|
|
87
|
+
return m !== null && m[1].toLowerCase() === owner.toLowerCase() && m[2].toLowerCase() === repo.toLowerCase();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** the remote to fetch from: `origin` when it names the repo, else the first that does; null = none @param {{name: string, url: string}[]} remotes @returns {{name: string, url: string}|null} */
|
|
91
|
+
export function matchRemote(remotes, owner, repo) {
|
|
92
|
+
const hits = remotes.filter((r) => remoteNames(r.url, owner, repo));
|
|
93
|
+
return hits.find((r) => r.name === 'origin') ?? hits[0] ?? null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** an address that carries a login: `https://user:pass@host`, `https://token@host`, or `ssh://user:pass@host` (a bare ssh user such as `git@` is not a secret) @param {string} url */
|
|
97
|
+
export function urlCarriesLogin(url) {
|
|
98
|
+
const m = /^([a-z][a-z0-9+.-]*):\/\/([^/@\s]*)@/i.exec(url.trim());
|
|
99
|
+
if (m === null) return false;
|
|
100
|
+
return /^https?$/i.test(m[1]) || m[2].includes(':');
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** the address with any login masked, for the words a person reads @param {string} url */
|
|
104
|
+
export function maskUrl(url) {
|
|
105
|
+
return url.trim().replace(/^([a-z][a-z0-9+.-]*:\/\/)[^/@\s]*@/i, '$1***@');
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The environment of every git child of this piece: the panel's env MINUS what `CLOSE_ENV_DENY` names (the one deny list, never re-spelled), KEEPING `HOME` and
|
|
110
|
+
* `SSH_AUTH_SOCK` (the documented exception: stripping it breaks git over ssh), with prompts off - no human is mid-run, so a credential question is a refusal, never a wait.
|
|
111
|
+
* @param {NodeJS.ProcessEnv} base @returns {NodeJS.ProcessEnv}
|
|
112
|
+
*/
|
|
113
|
+
export function prGitEnv(base) {
|
|
114
|
+
const env = credentialStrippedEnv(base);
|
|
115
|
+
// the repo is named by the cwd; an inherited GIT_DIR would aim a child at some other repo
|
|
116
|
+
delete env.GIT_DIR; delete env.GIT_WORK_TREE; delete env.GIT_INDEX_FILE;
|
|
117
|
+
env.GIT_TERMINAL_PROMPT = '0';
|
|
118
|
+
env.SSH_ASKPASS_REQUIRE = 'never';
|
|
119
|
+
return env;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* The argv of one git call. The subcommand is checked against `PR_GIT_SUBCOMMANDS` HERE, before any process exists.
|
|
124
|
+
* @param {string} sub @param {string[]} rest @param {string[]} [cfg] extra `-c key=value` words
|
|
125
|
+
* @returns {string[]}
|
|
126
|
+
*/
|
|
127
|
+
export function prGitArgs(sub, rest, cfg = []) {
|
|
128
|
+
if (!PR_GIT_SUBCOMMANDS.includes(sub)) throw new Error(`git ${sub} is not one of the git calls the pull request checkout may make`);
|
|
129
|
+
return [...NO_HOOKS, ...cfg.flatMap((c) => ['-c', c]), sub, ...rest];
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* The fetch (spec item 3): the PR's head ref from the base repo into bareloop's private ref, so the object survives gc during the run and no branch, tag or FETCH_HEAD is touched.
|
|
134
|
+
* The `+` lets a Rerun move the ref when the PR was force-pushed since the last run.
|
|
135
|
+
* @param {string} remote @param {number} n @param {{writeFetchHead?: boolean}} [o] `false` (default) = `--no-write-fetch-head`
|
|
136
|
+
* @returns {string[]} the subcommand's own args (after `fetch`)
|
|
137
|
+
*/
|
|
138
|
+
export function fetchRest(remote, n, { writeFetchHead = false } = {}) {
|
|
139
|
+
return ['--no-tags', '--no-recurse-submodules', ...(writeFetchHead ? [] : ['--no-write-fetch-head']), remote, `+refs/pull/${n}/head:${prRefName(n)}`];
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** git's reason, one line, with logins in addresses and secret shapes masked @param {string} stderr @param {string} [fallback] */
|
|
143
|
+
export function firstReason(stderr, fallback = 'no reason given') {
|
|
144
|
+
const line = redactSecrets(stderr).split('\n').map((l) => l.trim()).find((l) => l !== '') ?? fallback;
|
|
145
|
+
return line.replace(/([a-z][a-z0-9+.-]*:\/\/)[^/@\s]*@/gi, '$1***@').slice(0, 300);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* @typedef {object} PrCheckout
|
|
150
|
+
* @property {string} sha the PR's head commit, now the worktree's detached HEAD @property {number} number @property {string} ownerRepo `owner/repo`
|
|
151
|
+
* @property {string} remote the remote the fetch used @property {string} ref the private ref @property {{ref: string|null, sha: string}|null} base @property {string|null} mergeBase
|
|
152
|
+
*/
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* RUN START for a PR job: fetch the PR's head, verify it is the sha the frozen record names, and move the run's worktree there (detached). Every refusal is plain words
|
|
156
|
+
* that end in "Nothing spent." and leaves no private ref behind. Never pushes; the person's own tree is never touched (the worktree is the run's).
|
|
157
|
+
* @param {object} o
|
|
158
|
+
* @param {string} o.repo the person's repo root (the worktree's `repo` in source.json) @param {string} o.worktree the run's worktree
|
|
159
|
+
* @param {{url: string, record: any, reread?: () => Promise<any>}} o.pr `url` = the PR address; `record` = the frozen PR record; `reread` = optional: read the record again (one try, spec item 5)
|
|
160
|
+
* @param {NodeJS.ProcessEnv} [o.env] @param {number} [o.timeoutMs] @param {typeof spawnClose} [o.run] test seam for the child process
|
|
161
|
+
* @returns {Promise<{ok: true, checkout: PrCheckout}|{ok: false, error: string}>}
|
|
162
|
+
*/
|
|
163
|
+
export async function checkoutPrHead({ repo, worktree, pr, env = process.env, timeoutMs = PR_FETCH_DEADLINE_MS, run = spawnClose }) {
|
|
164
|
+
const tail = 'Nothing spent.';
|
|
165
|
+
const addr = parsePrAddress(pr.url);
|
|
166
|
+
if (!addr.ok) return addr;
|
|
167
|
+
const { owner, repo: name, number: n } = addr;
|
|
168
|
+
const ref = prRefName(n);
|
|
169
|
+
const noCode = { ok: /** @type {const} */ (false), error: `Pull request #${n} has no code to fetch (GitHub did not offer its head). ${tail}` };
|
|
170
|
+
const want = prHeadSha(pr.record);
|
|
171
|
+
if (want === null) return noCode;
|
|
172
|
+
|
|
173
|
+
const childEnv = prGitEnv(env);
|
|
174
|
+
const git = (/** @type {string} */ cwd, /** @type {string} */ sub, /** @type {string[]} */ rest, /** @type {string[]} */ cfg = []) => run('git', prGitArgs(sub, rest, cfg), { env: childEnv, cwd, timeoutMs });
|
|
175
|
+
const out = (/** @type {{stdout: string}} */ r) => r.stdout.trim();
|
|
176
|
+
|
|
177
|
+
// which remote: the person's own repo config, matched by owner/repo; no address is ever built from the ticket
|
|
178
|
+
const common = await git(repo, 'rev-parse', ['--git-common-dir']);
|
|
179
|
+
if (common.error || common.status !== 0) return { ok: false, error: `Git could not fetch pull request #${n} (${firstReason(common.stderr, 'this folder is not a git repository')}). Check your git login for this repo. ${tail}` };
|
|
180
|
+
let configText = '';
|
|
181
|
+
try { configText = readFileSync(join(resolve(repo, out(common)), 'config'), 'utf8'); } catch { configText = ''; }
|
|
182
|
+
const remote = matchRemote(remotesOfConfig(configText), owner, name);
|
|
183
|
+
if (remote === null) return { ok: false, error: `No remote in this repo points at ${owner}/${name}, so the pull request's code cannot be fetched. ${tail}` };
|
|
184
|
+
if (urlCarriesLogin(remote.url)) return { ok: false, error: `The remote ${remote.name} (${maskUrl(remote.url)}) has a login in its address, which bareloop will not use; use an ssh address or a git credential helper. ${tail}` };
|
|
185
|
+
|
|
186
|
+
/** @param {string} message @returns {{ok: false, error: string}} */
|
|
187
|
+
const failed = (message) => { removePrRef(repo, n); return { ok: false, error: message }; };
|
|
188
|
+
const cfg = [`remote.${remote.name}.pushurl=${NO_PUSH}`];
|
|
189
|
+
/** one fetch + rev-parse; a git that does not know --no-write-fetch-head (before 2.29) is run again without it @param {boolean} writeFetchHead */
|
|
190
|
+
const fetchOnce = async (writeFetchHead = false) => {
|
|
191
|
+
const r = await git(repo, 'fetch', fetchRest(remote.name, n, { writeFetchHead }), cfg);
|
|
192
|
+
if (!writeFetchHead && r.status !== 0 && /no-write-fetch-head/.test(r.stderr) && /unknown|unrecognized/i.test(r.stderr)) return fetchOnce(true);
|
|
193
|
+
return r;
|
|
194
|
+
};
|
|
195
|
+
/** @returns {Promise<{ok: true, sha: string}|{ok: false, error: string}>} */
|
|
196
|
+
const fetchAndRead = async () => {
|
|
197
|
+
const f = await fetchOnce();
|
|
198
|
+
if (f.error) {
|
|
199
|
+
if (/** @type {any} */ (f.error).code === 'ETIMEDOUT') return { ok: false, error: `Fetching pull request #${n} took longer than ${Math.round(timeoutMs / 1000)} seconds. ${tail}` };
|
|
200
|
+
return { ok: false, error: `Git could not fetch pull request #${n} (${firstReason(String(f.error.message ?? f.error))}). Check your git login for this repo. ${tail}` };
|
|
201
|
+
}
|
|
202
|
+
if (f.status !== 0) return { ok: false, error: `Git could not fetch pull request #${n} (${firstReason(f.stderr)}). Check your git login for this repo. ${tail}` };
|
|
203
|
+
const rp = await git(repo, 'rev-parse', ['--verify', '--quiet', `${ref}^{commit}`]);
|
|
204
|
+
if (rp.error || rp.status !== 0 || !SHA.test(out(rp))) return { ok: false, error: `Git could not fetch pull request #${n} (the fetched ref could not be read). Check your git login for this repo. ${tail}` };
|
|
205
|
+
return { ok: true, sha: out(rp) };
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
let got = await fetchAndRead();
|
|
209
|
+
if (!got.ok) return failed(got.error);
|
|
210
|
+
let sha = want;
|
|
211
|
+
if (got.sha !== want) {
|
|
212
|
+
// the PR moved after it was read: ONE re-read of the record and ONE re-fetch; the frozen text and the checked-out code must describe the same commit
|
|
213
|
+
const moved = { ok: /** @type {const} */ (false), error: `The pull request changed while the run was starting. Run it again. ${tail}` };
|
|
214
|
+
const again = typeof pr.reread === 'function' ? await pr.reread() : null;
|
|
215
|
+
const wantAgain = again === null ? null : prHeadSha(again);
|
|
216
|
+
if (wantAgain === null) return failed(moved.error);
|
|
217
|
+
got = await fetchAndRead();
|
|
218
|
+
if (!got.ok) return failed(got.error);
|
|
219
|
+
if (got.sha !== wantAgain) return failed(moved.error);
|
|
220
|
+
sha = wantAgain;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// the checkout: the run's OWN worktree, detached at the head; nothing is committed
|
|
224
|
+
const co = await git(worktree, 'checkout', ['--detach', sha]);
|
|
225
|
+
if (co.error || co.status !== 0) return failed(`Git could not fetch pull request #${n} (it could not be checked out: ${firstReason(co.stderr || String(co.error?.message ?? ''))}). Check your git login for this repo. ${tail}`);
|
|
226
|
+
|
|
227
|
+
const base = prBaseOf(pr.record);
|
|
228
|
+
let mergeBase = null;
|
|
229
|
+
if (base !== null) {
|
|
230
|
+
const mb = await git(repo, 'merge-base', [base.sha, sha]);
|
|
231
|
+
mergeBase = !mb.error && mb.status === 0 && SHA.test(out(mb)) ? out(mb) : null; // a base this repo has not got is unrecorded, not a refusal
|
|
232
|
+
}
|
|
233
|
+
return { ok: true, checkout: { sha, number: n, ownerRepo: `${owner}/${name}`, remote: remote.name, ref, base, mergeBase } };
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* A RESUME's check (spec item 12): the recorded PR head is an ancestor of the worktree's HEAD, so the work branch still holds the PR's code. No fetch.
|
|
238
|
+
* @param {string} worktree @param {string} prHead @param {{run?: typeof spawnClose, env?: NodeJS.ProcessEnv}} [o]
|
|
239
|
+
* @returns {Promise<boolean>}
|
|
240
|
+
*/
|
|
241
|
+
export async function prHeadIsAncestor(worktree, prHead, { run = spawnClose, env = process.env } = {}) {
|
|
242
|
+
if (!SHA.test(prHead)) return false;
|
|
243
|
+
const r = await run('git', prGitArgs('merge-base', ['--is-ancestor', prHead, 'HEAD']), { env: prGitEnv(env), cwd: worktree, timeoutMs: PR_FETCH_DEADLINE_MS });
|
|
244
|
+
return !r.error && r.status === 0;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Write the checkout into the run's `source.json` (spec item 6): `seed:<sha>`, `prHead`, `prNumber`, `prBase:{ref,sha}`. Only these fields change.
|
|
249
|
+
* @param {string} into the prepared copy's folder (holds source.json) @param {PrCheckout} c
|
|
250
|
+
*/
|
|
251
|
+
export function recordPrOnManifest(into, c) {
|
|
252
|
+
const file = join(resolve(into), 'source.json');
|
|
253
|
+
const manifest = JSON.parse(readFileSync(file, 'utf8'));
|
|
254
|
+
manifest.seed = c.sha;
|
|
255
|
+
manifest.prHead = c.sha;
|
|
256
|
+
manifest.prNumber = c.number;
|
|
257
|
+
manifest.prBase = c.base;
|
|
258
|
+
writeFileSync(file, `${JSON.stringify(manifest, null, 2)}\n`);
|
|
259
|
+
}
|
package/src/promptregisters.js
CHANGED
|
@@ -88,6 +88,17 @@ export const PROMPT_REGISTERS = Object.freeze([
|
|
|
88
88
|
// (F198 item 2), built inline inside `middle` and appended to `w.ask([...])`
|
|
89
89
|
Object.freeze({ file: 'src/planrun.js', name: 'middle()\'s facts-only "The close\'s own numbers so far" block (inline template, not a const)' }),
|
|
90
90
|
|
|
91
|
+
// src/checklist.js — the one check list of a rubric job: the list call's system text and schema descriptions, the drafter's list block, the code-written refusal words
|
|
92
|
+
Object.freeze({ file: 'src/checklist.js', name: 'LEDGER_SYSTEM' }),
|
|
93
|
+
Object.freeze({ file: 'src/checklist.js', name: 'LEDGER_SCHEMA (property descriptions)' }),
|
|
94
|
+
Object.freeze({ file: 'src/checklist.js', name: 'ledgerUserText() (inline template, not a const)' }),
|
|
95
|
+
Object.freeze({ file: 'src/checklist.js', name: 'WEEK_ONLY_WORDS, EMPTY_LIST_WORDS' }),
|
|
96
|
+
|
|
97
|
+
// src/rowedit.js — the drafter's row-edit turn of a rubric job (the check block): system text, the one user message, the revise line, the tool's description
|
|
98
|
+
Object.freeze({ file: 'src/rowedit.js', name: 'ROW_EDIT_SYSTEM' }),
|
|
99
|
+
Object.freeze({ file: 'src/rowedit.js', name: 'ROW_EDIT_REVISE, rowEditUserText() (inline template, not a const)' }),
|
|
100
|
+
Object.freeze({ file: 'src/rowedit.js', name: 'rowEditChannel() (tool description and instruction)' }),
|
|
101
|
+
|
|
91
102
|
// src/authoring.js — the types-genre close template, interpolated verbatim
|
|
92
103
|
// into the authoring prompt (src/authorflow.js's assembled system message,
|
|
93
104
|
// "THE GENRE TEMPLATE" block) — model-facing law for a types-genre
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// The question box of the drafting chat (hamr 2026-11-12, as fwdloop M10 am29/am30/am31): a question asked while drafting gets its own box in the panel, with the question,
|
|
2
|
+
// its own buttons where the question offers choices (the person's intent is a typed choice, never words read), and one line to type in. This file is the ONE owner of what the
|
|
3
|
+
// panel shows for a pending question and of which choices a question offers (the page draws it, never works it out). The CLI (src/authorrun.js) is a sibling caller of the same
|
|
4
|
+
// questions and keeps typing words; the stored question text never changes, only the panel's copy of it is cut.
|
|
5
|
+
import { readingTail, cantCheckTail, DROP_IT } from './pagemap.js';
|
|
6
|
+
import { HOW_TO_ANSWER } from './checkpick.js';
|
|
7
|
+
import { FIT_ANSWER, FIT_GO_ON } from './fitcheck.js';
|
|
8
|
+
import { DEST_ANSWER } from './destpoint.js';
|
|
9
|
+
|
|
10
|
+
/** the door's refusals, word for word (fwd am31); a refusal leaves the question open and writes nothing */
|
|
11
|
+
export const CHOICE_SAYS = Object.freeze({
|
|
12
|
+
bad: 'That answer is not one of the choices. Nothing was saved.',
|
|
13
|
+
notOffered: 'That choice is not offered for this question. Nothing was saved.',
|
|
14
|
+
outOfDate: 'This page is out of date. Reload it and answer again. Nothing was saved.',
|
|
15
|
+
noRule:'That question is about the job line, not one of your ~ rules, so there is nothing to drop. Agree, or type your own words. Nothing was saved.',
|
|
16
|
+
blank: 'An answer is needed here — there is no skip. Type it in the box and press Send.',
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Which buttons a look question offers. Agree only when it carries a proposal (a reading ask with its reading, a check-pick ask with its check); Drop it only where "drop it" leaves
|
|
21
|
+
* one of the person's own `~` rules Not checked (a can't-check ask or a check-pick ask about a rule number).
|
|
22
|
+
* @param {{source?: string, ask?: string, reading?: unknown, check?: unknown, rule?: unknown}} q @returns {{agree: boolean, drop: boolean}}
|
|
23
|
+
*/
|
|
24
|
+
export function offersOf(q) {
|
|
25
|
+
const look = q.source === 'look';
|
|
26
|
+
const agree = look && ((q.ask === 'reading' && typeof q.reading === 'string') || (q.ask === 'check' && q.check !== null && typeof q.check === 'object'));
|
|
27
|
+
const drop = look && Number.isInteger(q.rule) && (q.ask === 'cant-check' || q.ask === 'check' || q.ask === 'no-check');
|
|
28
|
+
return { agree, drop };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A look question as the PANEL shows it: the code's own answer words (`Answer "agree"...` / `Answer "drop it"...`) cut off the end, because the buttons and the box say it.
|
|
33
|
+
* Only the known tails are cut, matched exactly as a suffix (never a pattern over the prose); a question that ends in none of them is returned whole.
|
|
34
|
+
* @param {{question: string, line?: number, source?: string}} q @returns {string}
|
|
35
|
+
*/
|
|
36
|
+
export function panelQuestionText(q) {
|
|
37
|
+
const text = String(q.question);
|
|
38
|
+
if (q.source === 'fit-check') return text.endsWith(FIT_ANSWER) ? text.slice(0, text.length - FIT_ANSWER.length) : text;
|
|
39
|
+
if (q.source === 'dest-point') return text.endsWith(DEST_ANSWER) ? text.slice(0, text.length - DEST_ANSWER.length) : text;
|
|
40
|
+
if (q.source !== 'look' || !Number.isInteger(q.line)) return text;
|
|
41
|
+
const n = /** @type {number} */ (q.line);
|
|
42
|
+
const hit = [readingTail(n), cantCheckTail(n), ` ${HOW_TO_ANSWER(n, true)}`, ` ${HOW_TO_ANSWER(n, false)}`].find((t) => text.endsWith(t));
|
|
43
|
+
return hit === undefined ? text : text.slice(0, text.length - hit.length);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* What the panel's question box shows for one pending ask. Only a question the person answers (`kind: 'answer'`) has a box; every other ask (language, menu, install)
|
|
48
|
+
* keeps the chat input. `sendChoice` = the choice the box's own Send posts.
|
|
49
|
+
* @param {{kind: string, source?: string, index?: number, total?: number, question?: string, line?: number, offers?: {agree: boolean, drop: boolean}, folder?: string, current?: string}} step
|
|
50
|
+
* @returns {{head: string, line: string, text: string, choices: {choice: string, label: string}[], orLabel: string|null, sendChoice: string}|null}
|
|
51
|
+
*/
|
|
52
|
+
export function boxFor(step) {
|
|
53
|
+
if (step.kind !== 'answer' || typeof step.question !== 'string') return null;
|
|
54
|
+
const before = step.source === 'fit-check' || step.source === 'dest-point';
|
|
55
|
+
// the fit check: two buttons, no box (go on = keep drafting; stop = anything else, as typed words did)
|
|
56
|
+
if (step.source === 'fit-check') {
|
|
57
|
+
return { head: 'A question before drafting', line: '', text: panelQuestionText(/** @type {any} */ (step)), choices: [{ choice: 'go-on', label: 'Go on' }, { choice: 'stop', label: 'Stop' }], orLabel: null, sendChoice: 'stop' };
|
|
58
|
+
}
|
|
59
|
+
// the Destination point: yes / no buttons and a box for a different Destination (checked at $0 before it is taken)
|
|
60
|
+
if (step.source === 'dest-point') {
|
|
61
|
+
return {
|
|
62
|
+
head: 'A question before drafting', line: Number.isInteger(step.line) ? `About job line ${step.line}` : '', text: panelQuestionText(/** @type {any} */ (step)),
|
|
63
|
+
choices: [{ choice: 'yes', label: `Yes, set it to ${step.folder ?? ''}` }, { choice: 'no', label: `No, keep ${String(step.current ?? '').trim().replace(/\s*\n\s*/g, ', ')}` }],
|
|
64
|
+
orLabel: 'Or type a different Destination:', sendChoice: 'path',
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/** @type {{choice: string, label: string}[]} */
|
|
68
|
+
const choices = [];
|
|
69
|
+
if (step.offers?.agree) choices.push({ choice: 'agree', label: 'Agree' });
|
|
70
|
+
if (step.offers?.drop) choices.push({ choice: 'drop', label: 'Drop it' });
|
|
71
|
+
return {
|
|
72
|
+
head: before ? 'A question before drafting' : `A question the plan raised (${step.index ?? 1} of ${step.total ?? 1})`,
|
|
73
|
+
line: Number.isInteger(step.line) ? `About job line ${step.line}` : '',
|
|
74
|
+
text: panelQuestionText({ question: step.question, source: step.source, ...(Number.isInteger(step.line) ? { line: step.line } : {}) }),
|
|
75
|
+
choices,
|
|
76
|
+
orLabel: choices.length > 0 ? 'Or type a new rule:' : 'Type your answer:',
|
|
77
|
+
sendChoice: 'rule',
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** the choices each kind of question's typed answer may name */
|
|
82
|
+
const CHOICES = { look: ['agree', 'drop', 'rule'], 'fit-check': ['go-on', 'stop'], 'dest-point': ['yes', 'no', 'path'] };
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The door's check of a choice sent for the pending ask. Null = accepted; else the refusal words.
|
|
86
|
+
* @param {{kind: string, source?: string, rule?: unknown, offers?: {agree: boolean, drop: boolean}}} step @param {unknown} choice @returns {string|null}
|
|
87
|
+
*/
|
|
88
|
+
export function refuseChoice(step, choice) {
|
|
89
|
+
if (step.kind !== 'answer') return CHOICE_SAYS.notOffered;
|
|
90
|
+
const own = /** @type {string[]|undefined} */ (/** @type {Record<string, string[]>} */ (CHOICES)[step.source === 'fit-check' || step.source === 'dest-point' ? step.source : 'look']);
|
|
91
|
+
if (typeof choice !== 'string' || !(own ?? CHOICES.look).includes(choice)) return CHOICE_SAYS.bad;
|
|
92
|
+
if (step.source === 'fit-check' || step.source === 'dest-point') return null;
|
|
93
|
+
if (choice === 'agree' && step.offers?.agree !== true) return CHOICE_SAYS.notOffered;
|
|
94
|
+
if (choice === 'drop' && step.offers?.drop !== true) return step.source === 'look' && !Number.isInteger(step.rule) ? CHOICE_SAYS.noRule : CHOICE_SAYS.notOffered;
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* What a choice resolves the question with: the words the asker reads (today's own words for the effect, so the drafting log and the CLI path see the same), and the chat line the person
|
|
100
|
+
* sees as their own. `rule` = the box's words kept whole.
|
|
101
|
+
* @param {unknown} choice @param {unknown} text @returns {{value: string, shown: string}|{error: string}}
|
|
102
|
+
*/
|
|
103
|
+
export function resolveChoice(choice, text) {
|
|
104
|
+
if (choice === 'agree') return { value: 'agree', shown: 'Agree' };
|
|
105
|
+
if (choice === 'drop') return { value: DROP_IT, shown: 'Drop it' };
|
|
106
|
+
if (choice === 'go-on') return { value: FIT_GO_ON, shown: 'Go on' };
|
|
107
|
+
if (choice === 'stop') return { value: 'stop', shown: 'Stop' };
|
|
108
|
+
if (choice === 'yes') return { value: 'yes', shown: 'Yes' };
|
|
109
|
+
if (choice === 'no') return { value: 'no', shown: 'No' };
|
|
110
|
+
const said = String(text ?? '').replace(/\s*\n\s*/g, ' ').trim();
|
|
111
|
+
return said === '' ? { error: CHOICE_SAYS.blank } : { value: said, shown: said };
|
|
112
|
+
}
|
package/src/readshim.js
CHANGED
|
@@ -371,9 +371,9 @@ export function buildReadMap({ rel, lines, chunks }) {
|
|
|
371
371
|
}
|
|
372
372
|
|
|
373
373
|
/**
|
|
374
|
-
* @typedef {{root: string, hasGet: boolean, getNode: (rel: string) => any, refresh?: (() => Promise<unknown>)|null, emit: (type: string, data: object) => void}} ReadMapOpts
|
|
374
|
+
* @typedef {{root: string, hasGet: boolean, getNode: (rel: string) => any, indexed?: (() => boolean)|null, refresh?: (() => Promise<unknown>)|null, emit: (type: string, data: object) => void}} ReadMapOpts
|
|
375
375
|
* `root`: the job root (paths are made relative to it); `hasGet`: this worker holds `ctx_get` (a map hands out handles only that tool opens);
|
|
376
|
-
* `getNode`: the LiteCtx index's node for a path (its `chunks`); `refresh`: re-index first so the ranges are true to the file as it now is;
|
|
376
|
+
* `getNode`: the LiteCtx index's node for a path (its `chunks`); `indexed`: whether the job has an index at all (`lc.indexed`; false skips with `no-index`); `refresh`: re-index first so the ranges are true to the file as it now is;
|
|
377
377
|
* `emit`: the spine channel, for the report-only `read-map` / `read-map-skip` records (counts and a reason, never text).
|
|
378
378
|
*/
|
|
379
379
|
|
|
@@ -532,6 +532,7 @@ export function createReadShim({ cap = READ_SHIM_CAP, arm = ARM_ALL, onCount = n
|
|
|
532
532
|
let chunks;
|
|
533
533
|
try {
|
|
534
534
|
if (o.refresh) await o.refresh();
|
|
535
|
+
if (o.indexed && !o.indexed()) return skip('no-index');
|
|
535
536
|
chunks = o.getNode(rel)?.chunks;
|
|
536
537
|
} catch { return skip('no-index'); }
|
|
537
538
|
if (!Array.isArray(chunks)) return skip('no-index');
|
package/src/revises.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// M4e amendment 14 item 3 (fwdloop v0.29.0), the bareloop mapping: a draft has 2 revises, then the button reads Start over (a fresh draft with its own 2).
|
|
2
|
+
// A revise or Start over is a NEW authoring session here (the old draft is ended, the boxes reopen), so the count rides the carry link: a session folder holds
|
|
3
|
+
// `revises.json` ({used}); a draft that follows another by Revise has that draft's used + 1, one that follows by Start over (or follows nothing) has 0. The server is
|
|
4
|
+
// the only reader that decides: a refresh brings the count back from the session's own state, and a third revise is refused at $0 before anything is ended or sent.
|
|
5
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
|
|
8
|
+
export const MAX_REVISES = 2;
|
|
9
|
+
/** the count's file, inside a drafting session folder only */
|
|
10
|
+
export const REVISES_FILE = 'revises.json';
|
|
11
|
+
const SESSION_ID = /^s[a-z0-9]+$/;
|
|
12
|
+
|
|
13
|
+
/** The one spelling of the drafting sessions folder (the session and the routes both read it).
|
|
14
|
+
* @param {string|undefined} root */
|
|
15
|
+
export function sessionsRootOf(root) {
|
|
16
|
+
return root ?? join(process.env.HOME ?? '/tmp', '.config', 'bareloop', 'panel-sessions');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** @param {string} root @param {string} id revises used by that draft; no file, or an unreadable one, is 0 (a draft from before the count existed)
|
|
20
|
+
* @returns {number} */
|
|
21
|
+
export function revisesUsedOf(root, id) {
|
|
22
|
+
if (!SESSION_ID.test(id)) return 0;
|
|
23
|
+
try {
|
|
24
|
+
const n = Number(JSON.parse(readFileSync(join(root, id, REVISES_FILE), 'utf8')).used);
|
|
25
|
+
return Number.isInteger(n) && n >= 0 ? n : 0;
|
|
26
|
+
} catch { return 0; }
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The revises a draft will have used, given what it follows: a Revise adds one to the draft it follows; Start over, or following nothing, starts at 0.
|
|
30
|
+
* @param {string} root @param {unknown} carryFrom @param {unknown} carryKind
|
|
31
|
+
* @returns {number} */
|
|
32
|
+
export function nextRevisesUsed(root, carryFrom, carryKind) {
|
|
33
|
+
return carryKind === 'revise' && typeof carryFrom === 'string' ? revisesUsedOf(root, carryFrom) + 1 : 0;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Plain words when that revise would be a third; null when it is allowed. $0: called before anything is ended or started.
|
|
37
|
+
* @param {string} root @param {unknown} carryFrom @param {unknown} carryKind
|
|
38
|
+
* @returns {string|null} */
|
|
39
|
+
export function reviseRefusal(root, carryFrom, carryKind) {
|
|
40
|
+
if (nextRevisesUsed(root, carryFrom, carryKind) <= MAX_REVISES) return null;
|
|
41
|
+
return `This draft has used its ${MAX_REVISES} revises. Start over: it keeps the boxes and gives ${MAX_REVISES} new revises. Nothing was sent.`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The words the draft record and the Audit use for a draft that follows another (fwdloop am14 item 6): `revise 1`, `revise 2`, `start over`; a first draft has none.
|
|
45
|
+
* @param {unknown} carryFrom @param {unknown} carryKind @param {number} used this draft's revises used
|
|
46
|
+
* @returns {string|null} */
|
|
47
|
+
export function draftLabelOf(carryFrom, carryKind, used) {
|
|
48
|
+
if (typeof carryFrom !== 'string') return null;
|
|
49
|
+
if (carryKind === 'revise') return `revise ${used}`;
|
|
50
|
+
return carryKind === 'startover' ? 'start over' : null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** @param {string} dir the session's folder @param {number} used */
|
|
54
|
+
export function writeRevisesUsed(dir, used) {
|
|
55
|
+
try { writeFileSync(join(dir, REVISES_FILE), `${JSON.stringify({ used })}\n`, { mode: 0o600 }); } catch { /* the count is a convenience: a disk fault only means a later Revise reads 0 */ }
|
|
56
|
+
}
|
package/src/rowedit.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// THE DRAFTER'S ROW-EDIT TURN of a rubric job (the check block, docs/product/ITEM33-BUILD.md "CHECK BLOCK BUILD SPEC" section 4 and hamr's rulings of 2026-11-12).
|
|
2
|
+
// The AI never writes a part, a check or a declaration: it sends EDITS to the list of checks code keeps in the CheckBlock (src/checkblock.js). Code reads the inputs, proves every
|
|
3
|
+
// word, builds every check and decides what can be checked; every edit is judged on its own. The confirm turn owns the goal (ruling 5), so the reply has none. A Tickets job's reply
|
|
4
|
+
// may also carry the optional `ticketFilter` (ruling 2, R5), checked by its own reader. No text here restates the list of checks (the block's invariant 5): the only list-shaped input is
|
|
5
|
+
// the look's report, an input the drafter already had, and the person's own job lines.
|
|
6
|
+
import { lineRules } from './rubricstep.js';
|
|
7
|
+
import { renderLookReport } from './inputlook.js';
|
|
8
|
+
import { OFFERED } from './checkwords.js';
|
|
9
|
+
import { rubricVocabulary } from 'bareguard';
|
|
10
|
+
import { TICKET_FILTER_SCHEMA_WORDS } from './ticketfilter.js';
|
|
11
|
+
|
|
12
|
+
/** the tool a row-edit reply is delivered through */
|
|
13
|
+
export const ROW_EDIT_TOOL = 'submit_edits';
|
|
14
|
+
/** what an acknowledged reply returns (the loop ends the call the moment the tool fires) */
|
|
15
|
+
export const ROW_EDIT_ACK = 'edits received';
|
|
16
|
+
|
|
17
|
+
const IGNORED_FIELDS = new Set(['id', 'field', 'text', 'strict']);
|
|
18
|
+
const GLOSS = /** @type {Record<string, string>} */ ({ nonEmpty: 'the output is not empty', maxWords: 'at most value words in all', minWords: 'at least value words in all', maxLines: 'at most value lines', listItems: 'exactly value list items (bullets)', maxListItems: 'at most value list items', minListItems: 'at least value list items', sections: 'the output has sections with these names', sectionOrder: 'the sections come in this order', sectionWords: 'each named section has at most wordsPerSection words', mustCarry: 'the output carries these phrases', blockLines: 'blocks of size lines carry these phrases' });
|
|
19
|
+
/** the checks a `pick` edit may name: the checker's own list (the same bareguard vocabulary src/checkpick.js reads) */
|
|
20
|
+
const pickMenu = () => OFFERED.map((r) => {
|
|
21
|
+
const fields = Object.entries(/** @type {any} */ (rubricVocabulary).rules[r].fields).filter(([k]) => !IGNORED_FIELDS.has(k)).map(([k, v]) => `${k}${/** @type {any} */ (v).required ? '' : '?'}`);
|
|
22
|
+
return `- ${r}${fields.length ? ` { ${fields.join(', ')} }` : ''}: ${GLOSS[r] ?? ''}`;
|
|
23
|
+
}).join('\n');
|
|
24
|
+
|
|
25
|
+
/** the drafter's system text for the row-edit turn (a prompt register: src/promptregisters.js) */
|
|
26
|
+
export const ROW_EDIT_SYSTEM = `You help turn the lines of a job into checks, by sending EDITS to a list of checks that code keeps. You never write a check, a stage, a part or a declaration: code reads the inputs, proves every word, builds every check and decides what can be checked. Each edit you send is judged on its own: a refused edit is dropped and says why, and it never costs your other edits.
|
|
27
|
+
|
|
28
|
+
HOW TO ANSWER
|
|
29
|
+
Deliver ONE reply with an "edits" list (the ${ROW_EDIT_TOOL} tool, or one JSON object {"edits": [ ... ]} and nothing else when no tool is offered). An empty "edits" list is a good answer when you have nothing sure to send.
|
|
30
|
+
|
|
31
|
+
THE FOUR EDITS (each has "op"; the op is exactly one of: add, reading, pick, not-checkable. A count is an add with "kind":"count"; "count" is never an op)
|
|
32
|
+
1. add - a check the inputs support that the person did not write and the look did not give:
|
|
33
|
+
{"op":"add","kind":"fact","line":N,"name":"price label","shape":"money","words":["words copied exactly from the input"],"unit":["US dollars"],"currency":["$"],"source":"<input label>"}
|
|
34
|
+
{"op":"add","kind":"phrase","line":N,"name":"letters and spaces only","words":["fixed words copied exactly from the input"],"source":"<input label>"}
|
|
35
|
+
{"op":"add","kind":"count","line":N,"min":3,"max":3} (how many results the job line itself asks for; whole numbers of 1 or more; only when the line states it)
|
|
36
|
+
"shape" is one of phrase, money, number, date, time. A name uses letters, spaces, "-" or "_" only (no digits). "words" are copied exactly from the input, never typed from memory; words the input does not hold are refused. At most 3 adds in one reply: the later ones are refused.
|
|
37
|
+
2. reading - the limit a ~ rule means, for a ~ rule the look tied to a fact ("carries ~ rule N") without giving the limit:
|
|
38
|
+
{"op":"reading","line":N,"rules":[n],"fact":"<that look fact's name>","reading":{"op":"lt","value":450}} (reading op is lt, lte, gt or gte)
|
|
39
|
+
{"op":"reading","line":N,"rules":[n],"fact":"<that look fact's name>","reading":{"op":"between","lo":"05:00","hi":"21:00"}}
|
|
40
|
+
A money limit is a number. A time limit is a 24-hour "HH:MM" string. A limit the person WROTE ("under $450") is a rule that can be checked: give its reading with its number. A number YOU make out of their words ("not a red-eye" becomes a departure time between 06:00 and 21:00) is your proposal for the person to check, and a time limit that you propose is a RANGE (between), never one-sided. A rule that holds more than one amount or range gets no reading.
|
|
41
|
+
3. pick - for a ~ rule that counts words, bullets, lines or sections: the one check that says exactly what that rule says:
|
|
42
|
+
{"op":"pick","line":N,"rules":[n],"check":{"rule":"<one of the checks below>", ...that check's own fields}}
|
|
43
|
+
Use only numbers the ~ rule itself states and only words it contains. The checks (field? = optional):
|
|
44
|
+
${pickMenu()}
|
|
45
|
+
4. not-checkable - a ~ rule no check on the inputs can carry ("the cheapest", "the best", "the newest one"):
|
|
46
|
+
{"op":"not-checkable","line":N,"rule":n,"reason":"plain words, the person's own"}
|
|
47
|
+
|
|
48
|
+
RULES
|
|
49
|
+
- Names, labels and units are the input's own words, copied exactly as the input writes them. When the input does not use the person's word, use the words the input uses; never invent a word the input holds nowhere, and never add a code (like SFO) that the person did not write and the input does not hold.
|
|
50
|
+
- The look (below) is what a read of the inputs already found and code already checks: do not send it again as an add. Use it to name the fact a reading belongs to.
|
|
51
|
+
- Send only what you are sure of. A fact or ~ rule you cannot name from the look and the input is not guessed at.
|
|
52
|
+
- "line" is the job line's number; "rule" and "rules" are the ~ rule numbers shown under that line (1 = the first).`;
|
|
53
|
+
|
|
54
|
+
/** the fixed sentence that follows the refusals in a revise turn (the turn carries each refusal's own reason and nothing else) */
|
|
55
|
+
export const ROW_EDIT_REVISE = 'Send corrected edits only (an empty "edits" list is a good answer).';
|
|
56
|
+
|
|
57
|
+
/** how much of each input the turn is shown (the bound src/checklist.js used) */
|
|
58
|
+
const SHOWN_CHARS = 8000;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The ONE user message: the person's job lines (their `~` rules numbered), the look, the inputs (bounded).
|
|
62
|
+
* @param {{jobLines: any[], look: any, texts: Record<string, string>}} o
|
|
63
|
+
* @returns {string}
|
|
64
|
+
*/
|
|
65
|
+
export function rowEditUserText({ jobLines, look, texts }) {
|
|
66
|
+
const out = ["THE JOB (the person's own words)"];
|
|
67
|
+
for (const l of jobLines) {
|
|
68
|
+
out.push(`${l.n}. ${l.text}`);
|
|
69
|
+
lineRules(l).forEach((r, i) => out.push(` ~ rule ${i + 1}: ${r}`));
|
|
70
|
+
}
|
|
71
|
+
const report = look && typeof look === 'object' ? renderLookReport(look).replace(/^WHAT THE LOOK AT THE INPUTS FOUND[^\n]*/, 'WHAT THE LOOK AT THE INPUTS FOUND - code checks each of these itself; you do not write them') : '';
|
|
72
|
+
if (report) out.push('', report);
|
|
73
|
+
for (const [label, t] of Object.entries(texts)) out.push('', `INPUT "${label}" (first ${SHOWN_CHARS} characters):`, String(t).slice(0, SHOWN_CHARS));
|
|
74
|
+
return out.join('\n');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** @param {boolean} ticket @returns {Record<string, any>} the tool's schema: the edits list (each edit judged by code, so an item is any object), and for a Tickets job the optional ticketFilter */
|
|
78
|
+
const rowEditSchema = (ticket) => ({
|
|
79
|
+
type: 'object',
|
|
80
|
+
properties: {
|
|
81
|
+
edits: { type: 'array', items: { type: 'object', properties: { op: { enum: ['add', 'reading', 'pick', 'not-checkable'] } }, required: ['op'] }, description: 'row edits; each is judged on its own' },
|
|
82
|
+
...(ticket ? {
|
|
83
|
+
ticketFilter: {
|
|
84
|
+
type: 'object',
|
|
85
|
+
properties: {
|
|
86
|
+
priority: { type: 'array', items: { type: 'string', enum: ['P0', 'P1', 'P2', 'P3'] }, description: 'priorities a ticket must have; only when a job line names them' },
|
|
87
|
+
labels: { type: 'array', items: { type: 'string' }, description: 'label names, one of which a ticket must carry; only when a job line names them' },
|
|
88
|
+
},
|
|
89
|
+
additionalProperties: false,
|
|
90
|
+
description: TICKET_FILTER_SCHEMA_WORDS,
|
|
91
|
+
},
|
|
92
|
+
} : {}),
|
|
93
|
+
},
|
|
94
|
+
required: ['edits'],
|
|
95
|
+
additionalProperties: false,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
/** @param {boolean} ticket the channel `askStructured` reads (src/authorflow.js) */
|
|
99
|
+
export const rowEditChannel = (ticket = false) => ({
|
|
100
|
+
name: ROW_EDIT_TOOL,
|
|
101
|
+
instruction: `Your reply did not deliver exactly one ${ROW_EDIT_TOOL} call. Call ${ROW_EDIT_TOOL} exactly once, with the edits list as its arguments. Do not write the answer as text.`,
|
|
102
|
+
textPath: 'edits',
|
|
103
|
+
tool: (/** @type {{calls: any[]}} */ box) => ({
|
|
104
|
+
name: ROW_EDIT_TOOL,
|
|
105
|
+
description: 'Deliver your row edits (or an empty list). Call this exactly once.',
|
|
106
|
+
parameters: rowEditSchema(ticket),
|
|
107
|
+
execute: async (/** @type {any} */ args) => { box.calls.push(args); return ROW_EDIT_ACK; },
|
|
108
|
+
}),
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* The edits a reply holds, as a list (a reply whose `edits` is not a list holds none; each edit is still judged by the block).
|
|
113
|
+
* @param {any} artifact @returns {any[]}
|
|
114
|
+
*/
|
|
115
|
+
export const editsOf = (artifact) => (artifact && typeof artifact === 'object' && Array.isArray(artifact.edits) ? artifact.edits : []);
|