Skip to content

Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.

refactor(help): derive names and split imports [C7]

Corey Olsonf34b7c5a84cc
diff --git a/src/agent-session.js b/src/agent-session.js
index c32f010d..7d9a3823 100644
--- a/src/agent-session.js
+++ b/src/agent-session.js
@@ -1,6 +1,11 @@
/** A checkout belongs to one local agent session; bindings never enter the shared board [B3,B7]. */
import { createHash } from 'node:crypto';
-import { existsSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
+import {
+ existsSync,
+ readFileSync,
+ renameSync,
+ writeFileSync,
+} from 'node:fs';
import { join } from 'node:path';
import { takeResource } from './resources.js';
import { Refused } from './refused.js';
diff --git a/src/api.js b/src/api.js
index 71711c05..17bcaa5e 100644
--- a/src/api.js
+++ b/src/api.js
@@ -1,23 +1,59 @@
/** The local API v1: the CLI's moves, persistent board identities and live events (A2). */
-import { createHash, randomBytes, timingSafeEqual } from 'node:crypto';
+import {
+ createHash,
+ randomBytes,
+ timingSafeEqual,
+} from 'node:crypto';
import { createServer } from 'node:http';
-import { basename, join, resolve } from 'node:path';
-import { existsSync, readFileSync, statSync } from 'node:fs';
+import {
+ basename,
+ join,
+ resolve,
+} from 'node:path';
+import {
+ existsSync,
+ readFileSync,
+ statSync,
+} from 'node:fs';
import { displayAgentName } from './agent-names.js';
import * as store from './board.js';
-import { CONFIG_FILE, COORDINATOR, loadConfig } from './config.js';
-import { codeIsFromMain, repoInfo, resolveCommit, withGitReadFacts } from './git.js';
+import {
+ CONFIG_FILE,
+ COORDINATOR,
+ loadConfig,
+} from './config.js';
+import {
+ codeIsFromMain,
+ repoInfo,
+ resolveCommit,
+ withGitReadFacts,
+} from './git.js';
import { refusalDocument } from './json.js';
-import { relayLinked, relayOperation, relayRevoke, relayTokens } from './relay.js';
+import {
+ relayLinked,
+ relayOperation,
+ relayRevoke,
+ relayTokens,
+} from './relay.js';
import { laneNames } from './lanes.js';
import { MACHINE } from './machine.js';
-import { listApiProjects, registryFile } from './projects.js';
+import {
+ listApiProjects,
+ registryFile,
+} from './projects.js';
import { milestoneRoadmap } from './roadmap.js';
import { proofStats } from './stats.js';
-import { prepareFlowHistory, projectFlowStats } from './stats-flow.js';
+import {
+ prepareFlowHistory,
+ projectFlowStats,
+} from './stats-flow.js';
import { projectRowDecisions } from './row-decisions.js';
import { Refused } from './refused.js';
-import { codeAt, projectItemState, projectState } from './serve.js';
+import {
+ codeAt,
+ projectItemState,
+ projectState,
+} from './serve.js';
import { relayPresentationShout } from './relay-presentation.js';
import { createApiHandler } from './api-http.js';
import { moveArgs } from './api-moves.js';
diff --git a/src/approved-rows.js b/src/approved-rows.js
index 3d468fb6..e80fa663 100644
--- a/src/approved-rows.js
+++ b/src/approved-rows.js
@@ -1,13 +1,32 @@
/** Person approval guards staged approved-row rewrites and exposes stale frozen items [S19,V3]. */
-import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
+import {
+ existsSync,
+ mkdirSync,
+ mkdtempSync,
+ rmSync,
+ writeFileSync,
+} from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { spawnSync } from 'node:child_process';
-import { parseSpec, SIGNOFFS_FILE } from './spec.js';
-import { boardBusyError, openBoardReadOnly, rowDecisions } from './board.js';
-import { hasSignerFile, verifySignedRecords } from './signature.js';
+import {
+ parseSpec,
+ SIGNOFFS_FILE,
+} from './spec.js';
+import {
+ boardBusyError,
+ openBoardReadOnly,
+ rowDecisions,
+} from './board.js';
+import {
+ hasSignerFile,
+ verifySignedRecords,
+} from './signature.js';
import { Refused } from './refused.js';
-import { CONFIG_FILE, configFromSource } from './config.js';
+import {
+ CONFIG_FILE,
+ configFromSource,
+} from './config.js';
const TRUST_FILES = ['.pullboard/signers', '.pullboard/first-commit', '.pullboard/signers.initial', SIGNOFFS_FILE];
diff --git a/src/board.js b/src/board.js
index 0cefd895..9afd5387 100644
--- a/src/board.js
+++ b/src/board.js
@@ -6,13 +6,31 @@
* every move lands in an append-only event log (R2). The caller supplies what only git and the
* spec know: the commit, the verifier's checkout, the frozen criterion.
*/
-import { randomBytes, randomUUID } from 'node:crypto';
-import { existsSync, mkdirSync } from 'node:fs';
+import {
+ randomBytes,
+ randomUUID,
+} from 'node:crypto';
+import {
+ existsSync,
+ mkdirSync,
+} from 'node:fs';
import { dirname } from 'node:path';
import { DatabaseSync } from 'node:sqlite';
-import { briefFiles, briefSections } from './brief.js';
+import {
+ briefFiles,
+ briefSections,
+} from './brief.js';
import { COORDINATOR } from './config.js';
-import { ENGINE_VERSION, GUARDS, IN_STATE, MOVES, STATES, UNKNOWN_MOVE, effectiveGuards, storeTriggers } from './machine.js';
+import {
+ ENGINE_VERSION,
+ GUARDS,
+ IN_STATE,
+ MOVES,
+ STATES,
+ UNKNOWN_MOVE,
+ effectiveGuards,
+ storeTriggers,
+} from './machine.js';
import { Refused } from './refused.js';
import { parseSpec } from './spec.js';
diff --git a/src/browser-admission.js b/src/browser-admission.js
index 03d15ee9..233bf6ad 100644
--- a/src/browser-admission.js
+++ b/src/browser-admission.js
@@ -1,9 +1,28 @@
/** Classify whether selected tests may launch Chrome; uncertainty keeps browser coverage enabled. */
-import { accessSync, constants } from 'node:fs';
-import { lstat, readFile, realpath, stat } from 'node:fs/promises';
-import { posix, relative, resolve, sep } from 'node:path';
-import { commonJsIn, importsIn } from './module-imports.js';
-import { cleanGitEnvironment, git } from './git.js';
+import {
+ accessSync,
+ constants,
+} from 'node:fs';
+import {
+ lstat,
+ readFile,
+ realpath,
+ stat,
+} from 'node:fs/promises';
+import {
+ posix,
+ relative,
+ resolve,
+ sep,
+} from 'node:path';
+import {
+ commonJsIn,
+ importsIn,
+} from './module-imports.js';
+import {
+ cleanGitEnvironment,
+ git,
+} from './git.js';
const MODULE_SUFFIXES = ['.js', '.mjs', '.cjs', '.cts', '.json'];
const CHROME_FIXTURE = 'test/chrome-fixture.js';
diff --git a/src/check-baseline-worker.js b/src/check-baseline-worker.js
index 5cd5bf1c..72b7f3f3 100644
--- a/src/check-baseline-worker.js
+++ b/src/check-baseline-worker.js
@@ -1,11 +1,29 @@
/** Detached baseline measurements and durable completion receipts use the ordered board engine [V2,H16]. */
import { spawn } from 'node:child_process';
-import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from 'node:fs';
-import { join, resolve } from 'node:path';
+import {
+ existsSync,
+ mkdirSync,
+ readFileSync,
+ readdirSync,
+ renameSync,
+ rmSync,
+ writeFileSync,
+} from 'node:fs';
+import {
+ join,
+ resolve,
+} from 'node:path';
import * as store from './board.js';
import { checkBaseline } from './check-baseline.js';
-import { codeIsFromMain, gitChildEnv, repoInfo } from './git.js';
-import { relayLinked, relayOperation } from './relay.js';
+import {
+ codeIsFromMain,
+ gitChildEnv,
+ repoInfo,
+} from './git.js';
+import {
+ relayLinked,
+ relayOperation,
+} from './relay.js';
import { Refused } from './refused.js';
const WORKER = resolve(import.meta.dirname, '../bin/check-baseline.js');
diff --git a/src/check-baseline.js b/src/check-baseline.js
index a7c83070..ccd80b85 100644
--- a/src/check-baseline.js
+++ b/src/check-baseline.js
@@ -1,10 +1,17 @@
/** Observe a proposed check on an isolated copy of main before recording its move [V2,H16]. */
import { spawnSync } from 'node:child_process';
import { randomUUID } from 'node:crypto';
-import { mkdtempSync, rmSync } from 'node:fs';
+import {
+ mkdtempSync,
+ rmSync,
+} from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
-import { gitChildEnv, mainCheckout, tryGit } from './git.js';
+import {
+ gitChildEnv,
+ mainCheckout,
+ tryGit,
+} from './git.js';
import { runShell } from './gate.js';
import { CONFIG_FILE } from './config.js';
diff --git a/src/cli.js b/src/cli.js
index 9ccc8f9c..b2b1a725 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -2,24 +2,96 @@
* The pullboard command line: every command, bound to who is asking (B3, R3). The main checkout is the
* coordinator; every other worktree is the agent that joined from it.
*/
-import { createHash, randomUUID } from 'node:crypto';
-import { spawn, spawnSync } from 'node:child_process';
-import { appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
+import {
+ createHash,
+ randomUUID,
+} from 'node:crypto';
+import {
+ spawn,
+ spawnSync,
+} from 'node:child_process';
+import {
+ appendFileSync,
+ existsSync,
+ mkdirSync,
+ readdirSync,
+ readFileSync,
+ renameSync,
+ writeFileSync,
+} from 'node:fs';
import { loadavg } from 'node:os';
-import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path';
+import {
+ basename,
+ dirname,
+ isAbsolute,
+ join,
+ relative,
+ resolve,
+} from 'node:path';
import { performance } from 'node:perf_hooks';
-import { fileURLToPath, pathToFileURL } from 'node:url';
+import {
+ fileURLToPath,
+ pathToFileURL,
+} from 'node:url';
import { parseArgs } from 'node:util';
import * as store from './board.js';
-import { CONFIG_FILE, COORDINATOR, DOCTRINE_FILE, LEGACY_DOCTRINE_FILE, loadConfig } from './config.js';
+import {
+ CONFIG_FILE,
+ COORDINATOR,
+ DOCTRINE_FILE,
+ LEGACY_DOCTRINE_FILE,
+ loadConfig,
+} from './config.js';
import { displayAgentName } from './agent-names.js';
-import { doctrineHistory, loadDoctrine } from './doctrine.js';
-import { agentSessionDigest, requirePersonChannel } from './person.js';
-import { bindLocalSession, localSessionMatches } from './agent-session.js';
-import { decisionProjection, planRowApply, prepareRowDecisions, restoreRowApply, writeRowApply } from './row-decisions.js';
-import { digestOf, gateReport, runGate, runProfiledShell, runSubmitGate, submitGateReport, timingDigest, withGateSlot } from './gate.js';
+import {
+ doctrineHistory,
+ loadDoctrine,
+} from './doctrine.js';
+import {
+ agentSessionDigest,
+ requirePersonChannel,
+} from './person.js';
+import {
+ bindLocalSession,
+ localSessionMatches,
+} from './agent-session.js';
+import {
+ decisionProjection,
+ planRowApply,
+ prepareRowDecisions,
+ restoreRowApply,
+ writeRowApply,
+} from './row-decisions.js';
+import {
+ digestOf,
+ gateReport,
+ runGate,
+ runProfiledShell,
+ runSubmitGate,
+ submitGateReport,
+ timingDigest,
+ withGateSlot,
+} from './gate.js';
import { checkNeedsBrowser } from './browser-admission.js';
-import { bareWorktreeFinding, codeIsFromMain, contains, differFromHead, git, gitChildEnv, headCommit, headTree, invalidateGitFacts, isClean, mainCheckout, patchId, repoInfo, resolveCommit, tryGit, untracked, withGitFacts } from './git.js';
+import {
+ bareWorktreeFinding,
+ codeIsFromMain,
+ contains,
+ differFromHead,
+ git,
+ gitChildEnv,
+ headCommit,
+ headTree,
+ invalidateGitFacts,
+ isClean,
+ mainCheckout,
+ patchId,
+ repoInfo,
+ resolveCommit,
+ tryGit,
+ untracked,
+ withGitFacts,
+} from './git.js';
import {
FIX_NOTE,
applyFixers,
@@ -31,16 +103,38 @@ import {
pushesTrunk,
unwiredHookProblems,
} from './hooks.js';
-import { detectGate, initRepo } from './init.js';
+import {
+ detectGate,
+ initRepo,
+} from './init.js';
import { lifecycleMarkdown } from './machine.js';
-import { HELP, VERSION } from './help.js';
+import {
+ buildHelp,
+ VERSION,
+} from './help.js';
import { defaultViewPort } from './view-port.js';
-export { HELP, VERSION };
-import { productLine, productProblems, productSummaries } from './products.js';
-import { isLane, laneNames, laneOf, outOfLane } from './lanes.js';
+export { VERSION };
+import {
+ productLine,
+ productProblems,
+ productSummaries,
+} from './products.js';
+import {
+ isLane,
+ laneNames,
+ laneOf,
+ outOfLane,
+} from './lanes.js';
import { Refused } from './refused.js';
-import { commitCitations, committedIds } from './history.js';
-import { promptFor, skillProblems, updateSkills } from './skills.js';
+import {
+ commitCitations,
+ committedIds,
+} from './history.js';
+import {
+ promptFor,
+ skillProblems,
+ updateSkills,
+} from './skills.js';
import {
frozenCriterion,
idProblems,
@@ -55,34 +149,122 @@ import {
unmetRows,
} from './spec.js';
import { briefFiles } from './brief.js';
-import { checkBaseline, prepareCheckBaseline, sayCheckBaseline } from './check-baseline.js';
-import { retryCheckBaselines, startCheckBaseline } from './check-baseline-worker.js';
-import { compareMainFailures, mainRedMessage, mainRedReworkItems } from './main-red.js';
+import {
+ checkBaseline,
+ prepareCheckBaseline,
+ sayCheckBaseline,
+} from './check-baseline.js';
+import {
+ retryCheckBaselines,
+ startCheckBaseline,
+} from './check-baseline-worker.js';
+import {
+ compareMainFailures,
+ mainRedMessage,
+ mainRedReworkItems,
+} from './main-red.js';
import { runItems } from './run.js';
-import { parseProblems, sweepItems } from './sweep.js';
+import {
+ parseProblems,
+ sweepItems,
+} from './sweep.js';
import { renderSpecView } from './view.js';
import { tour } from './tour.js';
-import { commandOutput, refusalDocument } from './json.js';
-import { forgetProject, listApiProjects, registerProjectAndLink } from './projects.js';
+import {
+ commandOutput,
+ refusalDocument,
+} from './json.js';
+import {
+ forgetProject,
+ listApiProjects,
+ registerProjectAndLink,
+} from './projects.js';
import { milestoneRoadmap } from './roadmap.js';
import { listResources } from './resources.js';
-import { citedTestFiles, rowEvidence, rowStage } from './evidence.js';
-import { exportView, serveView } from './serve.js';
-import { forgetView, rememberView, runningView } from './view-session.js';
+import {
+ citedTestFiles,
+ rowEvidence,
+ rowStage,
+} from './evidence.js';
+import {
+ exportView,
+ serveView,
+} from './serve.js';
+import {
+ forgetView,
+ rememberView,
+ runningView,
+} from './view-session.js';
import { serveApi } from './api.js';
-import { doctorProblems, doctrineProblems } from './doctor.js';
-import { staleFrozenItems, staleItemFinding } from './approved-rows.js';
-import { mainPolicy, policyAt, itemPolicy, submissionPaths, frozenCheck, checkAtCommit, dependencySnapshots, requireTrunkMerge, trunkRef } from './trusted-policy.js';
+import {
+ doctorProblems,
+ doctrineProblems,
+} from './doctor.js';
+import {
+ staleFrozenItems,
+ staleItemFinding,
+} from './approved-rows.js';
+import {
+ mainPolicy,
+ policyAt,
+ itemPolicy,
+ submissionPaths,
+ frozenCheck,
+ checkAtCommit,
+ dependencySnapshots,
+ requireTrunkMerge,
+ trunkRef,
+} from './trusted-policy.js';
import { proofStats } from './stats.js';
-import { flowLines, flowAlertLine } from './stats-flow.js';
+import {
+ flowLines,
+ flowAlertLine,
+} from './stats-flow.js';
import { releaseHeadlinesBetween } from './changelog.js';
-import { exportBoard, importBoard } from './exchange.js';
-import { addSigner, assertRequiredSigners, defaultPrincipal, hasSignerFile } from './signature.js';
-import { browserFreeChecksEnabled, loadMachineSettings, setBrowserSlots, setGateSlots } from './settings.js';
-import { formatSnapshotLimit, pendingSnapshotSize, pendingCheckpointProblem, relayCommandReceipt, relayCommandReceiptReported, relayLinked, relayOff, relayOn, relayOperation, relayRecover, relayRecovered, relayRevoke, relayStatus, relayTokens, syncRelay } from './relay.js';
-import { autoLinkProject, relayOnAll, revokeRelayDevice, unlinkedRelayProjects } from './relay-setup.js';
+import {
+ exportBoard,
+ importBoard,
+} from './exchange.js';
+import {
+ addSigner,
+ assertRequiredSigners,
+ defaultPrincipal,
+ hasSignerFile,
+} from './signature.js';
+import {
+ browserFreeChecksEnabled,
+ loadMachineSettings,
+ setBrowserSlots,
+ setGateSlots,
+} from './settings.js';
+import {
+ formatSnapshotLimit,
+ pendingSnapshotSize,
+ pendingCheckpointProblem,
+ relayCommandReceipt,
+ relayCommandReceiptReported,
+ relayLinked,
+ relayOff,
+ relayOn,
+ relayOperation,
+ relayRecover,
+ relayRecovered,
+ relayRevoke,
+ relayStatus,
+ relayTokens,
+ syncRelay,
+} from './relay.js';
+import {
+ autoLinkProject,
+ relayOnAll,
+ revokeRelayDevice,
+ unlinkedRelayProjects,
+} from './relay-setup.js';
import { readRelayMachine } from './relay-machine.js';
-import { relayJoin, relayPair } from './relay-pairing-client.js';
+import {
+ relayJoin,
+ relayPair,
+} from './relay-pairing-client.js';
import { executePersonRequests } from './relay-request-execution.js';
import { engineReceipt } from './engine.js';
import { land } from './land.js';
@@ -3533,6 +3715,9 @@ export function resultCommands() {
])].sort();
}
+/** The actual command maps supply help names, so adding a handler needs no parallel help-name edit. */
+export const HELP = buildHelp(resultCommands());
+
// This marker is emitted once when the actual CLI entrypoint finishes evaluating.
if (process.env.PULLBOARD_STARTUP_TRACE_ENTRY
&& resolve(process.argv[1] ?? '') === resolve(process.env.PULLBOARD_STARTUP_TRACE_ENTRY)) {
diff --git a/src/config.js b/src/config.js
index f06fe763..e1774499 100644
--- a/src/config.js
+++ b/src/config.js
@@ -2,7 +2,10 @@
* `pullboard.json`: the gate, the spec file, the lanes and the commit rules. Read once per command,
* merged over defaults, and checked, so a typo refuses with its field name instead of misbehaving.
*/
-import { existsSync, readFileSync } from 'node:fs';
+import {
+ existsSync,
+ readFileSync,
+} from 'node:fs';
import { join } from 'node:path';
import { Refused } from './refused.js';
diff --git a/src/doctor.js b/src/doctor.js
index bb643db7..a08d377f 100644
--- a/src/doctor.js
+++ b/src/doctor.js
@@ -1,16 +1,39 @@
/** Read-only integrity checks for a pullboard board file (A6). */
import { existsSync } from 'node:fs';
import { join } from 'node:path';
-import { DOCTRINE_FILE, LEGACY_DOCTRINE_FILE } from './config.js';
+import {
+ DOCTRINE_FILE,
+ LEGACY_DOCTRINE_FILE,
+} from './config.js';
import { tryGit } from './git.js';
-import { checkAtCommit, submissionPaths, dependencySnapshots } from './trusted-policy.js';
-import { BLANKS, STATES, storeTriggers } from './machine.js';
+import {
+ checkAtCommit,
+ submissionPaths,
+ dependencySnapshots,
+} from './trusted-policy.js';
+import {
+ BLANKS,
+ STATES,
+ storeTriggers,
+} from './machine.js';
-import { boardBusyError, EVENT_LOG_VERSION, openBoardReadOnly, readEventLogVersion, SCHEMA_VERSION } from './board.js';
-import { staleFrozenItems, staleItemFinding } from './approved-rows.js';
+import {
+ boardBusyError,
+ EVENT_LOG_VERSION,
+ openBoardReadOnly,
+ readEventLogVersion,
+ SCHEMA_VERSION,
+} from './board.js';
+import {
+ staleFrozenItems,
+ staleItemFinding,
+} from './approved-rows.js';
import { loadSpec } from './spec.js';
import { loadDoctrine } from './doctrine.js';
-import { preMergeHookProblems, unwiredHookProblems } from './hooks.js';
+import {
+ preMergeHookProblems,
+ unwiredHookProblems,
+} from './hooks.js';
const blankCharacters = new Set(BLANKS.map((point) => String.fromCodePoint(point)));
/** Offer a working tracked or untracked rename without rewriting the repo's doctrine [D1,D2]. */
diff --git a/src/doctrine.js b/src/doctrine.js
index 4e093a66..9e23d40a 100644
--- a/src/doctrine.js
+++ b/src/doctrine.js
@@ -1,8 +1,15 @@
/** The shared house rules (D1–D4): one packaged standard and a repo's explicit changes to it. */
import { readFileSync } from 'node:fs';
-import { DOCTRINE_FILE, LEGACY_DOCTRINE_FILE, doctrineFile } from './config.js';
+import {
+ DOCTRINE_FILE,
+ LEGACY_DOCTRINE_FILE,
+ doctrineFile,
+} from './config.js';
import { committedIds } from './history.js';
-import { loadSpec, parseSpec } from './spec.js';
+import {
+ loadSpec,
+ parseSpec,
+} from './spec.js';
export const STANDARD_VERSION = 1;
diff --git a/src/engine.js b/src/engine.js
index 3b5c167c..8d41d491 100644
--- a/src/engine.js
+++ b/src/engine.js
@@ -1,11 +1,21 @@
/** Versioned, deterministic replay through the CLI's existing board engine [H3,H16]. */
-import { createHash, randomUUID } from 'node:crypto';
+import {
+ createHash,
+ randomUUID,
+} from 'node:crypto';
import * as store from './board.js';
import { refusalDocument } from './json.js';
import { ENGINE_VERSION } from './machine.js';
import { Refused } from './refused.js';
-import { requestMoveProblem, recordRequestMove } from './relay-requests.js';
-import { relayMoveActor, relaySenderProblem, validRelaySender } from './relay-sender.js';
+import {
+ requestMoveProblem,
+ recordRequestMove,
+} from './relay-requests.js';
+import {
+ relayMoveActor,
+ relaySenderProblem,
+ validRelaySender,
+} from './relay-sender.js';
const ITEM_ID_FIRST_ARGUMENT = new Set(['editItem', 'escalate', 'recordAttempt', 'claim', 'release', 'submit', 'reserveReview', 'verify', 'merged', 'withdraw', 'refreeze', 'reopen', 'appendFact']);
diff --git a/src/exchange.js b/src/exchange.js
index 8cef32e9..13c36017 100644
--- a/src/exchange.js
+++ b/src/exchange.js
@@ -4,7 +4,10 @@
*/
import { createHash } from 'node:crypto';
import { Refused } from './refused.js';
-import { ENGINE_VERSION, storeTriggers } from './machine.js';
+import {
+ ENGINE_VERSION,
+ storeTriggers,
+} from './machine.js';
import { EVENT_LOG_VERSION } from './board.js';
const VERSION = 1;
diff --git a/src/gate.js b/src/gate.js
index f2154b49..b88a48a3 100644
--- a/src/gate.js
+++ b/src/gate.js
@@ -4,19 +4,51 @@
* tree's id in the git dir, so the same tree is never checked twice. An agent sees a digest of the
* run, not the run (V10): a passing suite's output costs tokens and says nothing.
*/
-import { spawn, spawnSync } from 'node:child_process';
+import {
+ spawn,
+ spawnSync,
+} from 'node:child_process';
import { randomUUID } from 'node:crypto';
-import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
-import { dirname, join } from 'node:path';
+import {
+ existsSync,
+ mkdirSync,
+ readFileSync,
+ writeFileSync,
+} from 'node:fs';
+import {
+ dirname,
+ join,
+} from 'node:path';
import { availableParallelism } from 'node:os';
-import { gitChildEnv, gitPath, headTree, invalidateGitFacts, isClean, untracked } from './git.js';
+import {
+ gitChildEnv,
+ gitPath,
+ headTree,
+ invalidateGitFacts,
+ isClean,
+ untracked,
+} from './git.js';
import { secretsIn } from './hooks.js';
import { Refused } from './refused.js';
-import { GATE_SLOT_HELD_ENV, gateSlotEnvironment, inheritedGateSlot, takeResource } from './resources.js';
-import { browserFreeChecksEnabled, loadMachineSettings } from './settings.js';
+import {
+ GATE_SLOT_HELD_ENV,
+ gateSlotEnvironment,
+ inheritedGateSlot,
+ takeResource,
+} from './resources.js';
+import {
+ browserFreeChecksEnabled,
+ loadMachineSettings,
+} from './settings.js';
import { selectAffectedTests } from './affected-tests.js';
-import { checkNeedsBrowser, testsNeedBrowser } from './browser-admission.js';
-import { timingFromOutput, timingRunner } from './timing.js';
+import {
+ checkNeedsBrowser,
+ testsNeedBrowser,
+} from './browser-admission.js';
+import {
+ timingFromOutput,
+ timingRunner,
+} from './timing.js';
const STAMP = 'pullboard-gate-green';
const LOG = 'pullboard-gate.log';
diff --git a/src/git.js b/src/git.js
index 30034311..b09c3d83 100644
--- a/src/git.js
+++ b/src/git.js
@@ -1,10 +1,25 @@
/**
* The few Git facts pullboard needs: repository/worktree identity, selected refs and tree cleanliness.
*/
-import { execFileSync, spawnSync } from 'node:child_process';
+import {
+ execFileSync,
+ spawnSync,
+} from 'node:child_process';
import { AsyncLocalStorage } from 'node:async_hooks';
-import { existsSync, lstatSync, readFileSync, readdirSync, realpathSync, statSync } from 'node:fs';
-import { basename, dirname, join, resolve } from 'node:path';
+import {
+ existsSync,
+ lstatSync,
+ readFileSync,
+ readdirSync,
+ realpathSync,
+ statSync,
+} from 'node:fs';
+import {
+ basename,
+ dirname,
+ join,
+ resolve,
+} from 'node:path';
import { fileURLToPath } from 'node:url';
import { Refused } from './refused.js';
diff --git a/src/help.js b/src/help.js
index d2485849..c12235fc 100644
--- a/src/help.js
+++ b/src/help.js
@@ -168,16 +168,6 @@ ${lifecycleHelp()}
Reject reasons: TEST_FAILURE, BEHAVIOR_MISMATCH, INSUFFICIENT_EVIDENCE, STALE_HEAD, OTHER.
--json prints one versioned document for every command; refusals include their code and next step.`;
-const HELP_NAMES = [
- 'tour', 'init', 'worktree', 'join', 'takeover', 'whoami', 'lanes', 'status', 'resources', 'settings', 'view', 'view export',
- 'serve', 'relay', 'relay recover', 'resume', 'hooks', 'add', 'edit', 'escalate', 'run', 'list', 'doctor', 'skills', 'show', 'next', 'land',
- 'check', 'claim', 'release', 'submit', 'done', 'verify', 'fact', 'shout', 'answer', 'pass', 'decisions', 'inbox', 'export', 'import',
- 'sweep', 'merged', 'withdraw', 'refreeze', 'reopen', 'hold', 'stats', 'ledger', 'log', 'spec', 'spec check', 'spec view',
- 'spec show', 'spec unmet', 'spec signoff', 'spec draft', 'spec signers', 'spec signers add', 'forget', 'prompt', 'gate', 'hook',
- 'hook pre-commit', 'hook pre-merge-commit', 'hook commit-msg', 'hook pre-push', 'view export', 'version', 'lifecycle', 'help',
- 'roadmap', 'milestone',
-];
-
const HELP_GROUPS = [
['Start', ['tour', 'init', 'worktree']],
['Work', ['add', 'list', 'claim']],
@@ -244,7 +234,7 @@ const HELP_FLAG_EXPLANATIONS = {
};
/** Build command-specific help rows from the preserved full list so its syntax stays authoritative. */
-function commandHelpRows(fullHelp) {
+function commandHelpRows(fullHelp, commandNames) {
const lines = fullHelp.split('\n');
const rows = [];
for (let index = 0; index < lines.length; index += 1) {
@@ -253,7 +243,10 @@ function commandHelpRows(fullHelp) {
for (let next = index + 1; next < lines.length && lines[next].startsWith(' ') && lines[next].trim() && !lines[next].startsWith(' pullboard '); next += 1) details.push(lines[next].trim());
rows.push({ usage: lines[index].trim().slice('pullboard '.length).split(/\s{2,}/, 1)[0].trim(), details });
}
- return Object.fromEntries(HELP_NAMES.map((name) => {
+ const phrases = rows.flatMap((row) => usagePhrases(row.usage));
+ const names = [...new Set([...commandNames, ...Object.keys(HELP_ALIASES),
+ ...phrases.flatMap((name) => [name.split(' ')[0], name])])];
+ return Object.fromEntries(names.map((name) => {
const parts = name.split(' ');
const alias = HELP_ALIASES[name];
const matches = alias?.source ? rows.filter((row) => row.usage === alias.source || row.usage.startsWith(`${alias.source} `)) : alias ? [] : rows.filter((row) => {
@@ -292,14 +285,19 @@ function overviewHelp(groups, firstRun = false) {
return lines.join('\n');
}
-/** The one help declaration feeds the overview, command detail, JSON result and unchanged full list. */
-export const HELP = Object.freeze({
- overview: overviewHelp(HELP_GROUPS),
- firstRun: overviewHelp(HELP_GROUPS, true),
- all: ALL_HELP,
- groups: HELP_GROUPS,
- commands: Object.freeze(commandHelpRows(ALL_HELP)),
-});
+/** Derive help names from live command declarations and the existing usage and alias declarations. */
+export function buildHelp(commandNames = []) {
+ return Object.freeze({
+ overview: overviewHelp(HELP_GROUPS),
+ firstRun: overviewHelp(HELP_GROUPS, true),
+ all: ALL_HELP,
+ groups: HELP_GROUPS,
+ commands: Object.freeze(commandHelpRows(ALL_HELP, commandNames)),
+ });
+}
+
+/** Browser command phrases use the same pure declarations without initializing the CLI or server. */
+export const HELP = buildHelp();
/** Replace help placeholders with ordinary values so every command receives a usable example. */
function exampleFor(name, usage) {
diff --git a/src/history.js b/src/history.js
index 72e0762b..828a0c94 100644
--- a/src/history.js
+++ b/src/history.js
@@ -4,7 +4,11 @@
* row keeps its meaning however the spec changes.
*/
import { spawnSync } from 'node:child_process';
-import { ID_RE, citedIds, parseSpec } from './spec.js';
+import {
+ ID_RE,
+ citedIds,
+ parseSpec,
+} from './spec.js';
/**
* Run git for output that can be large, or null when it fails.
diff --git a/src/hooks.js b/src/hooks.js
index f00aa81a..e2903e81 100644
--- a/src/hooks.js
+++ b/src/hooks.js
@@ -4,13 +4,42 @@
* Each check returns its problems; an empty list lets git go on.
*/
import { spawnSync } from 'node:child_process';
-import { chmodSync, existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
-import { join, relative, resolve } from 'node:path';
-import { git, gitChildEnv, gitPath, gitConfig, invalidateGitFacts, mainCheckout, refuseGrafts, tryGit } from './git.js';
-import { CONFIG_FILE, configFromSource, DOCTRINE_FILE, LEGACY_DOCTRINE_FILE } from './config.js';
+import {
+ chmodSync,
+ existsSync,
+ mkdirSync,
+ readFileSync,
+ statSync,
+ writeFileSync,
+} from 'node:fs';
+import {
+ join,
+ relative,
+ resolve,
+} from 'node:path';
+import {
+ git,
+ gitChildEnv,
+ gitPath,
+ gitConfig,
+ invalidateGitFacts,
+ mainCheckout,
+ refuseGrafts,
+ tryGit,
+} from './git.js';
+import {
+ CONFIG_FILE,
+ configFromSource,
+ DOCTRINE_FILE,
+ LEGACY_DOCTRINE_FILE,
+} from './config.js';
import { Refused } from './refused.js';
import { outOfLane } from './lanes.js';
-import { citedIds, deletedIds, idProblems } from './spec.js';
+import {
+ citedIds,
+ deletedIds,
+ idProblems,
+} from './spec.js';
import { approvedRowProblems } from './approved-rows.js';
export const HOOKS = ['pre-commit', 'pre-merge-commit', 'commit-msg', 'pre-push'];
diff --git a/src/init.js b/src/init.js
index 8a5b1567..5e6542ab 100644
--- a/src/init.js
+++ b/src/init.js
@@ -4,14 +4,35 @@
* the main checkout as the coordinator. It runs again safely and never overwrites a file it did not
* write.
*/
-import { appendFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
-import { basename, join } from 'node:path';
-import { CONFIG_FILE, COORDINATOR, doctrineFile, loadConfig } from './config.js';
+import {
+ appendFileSync,
+ existsSync,
+ mkdirSync,
+ readFileSync,
+ writeFileSync,
+} from 'node:fs';
+import {
+ basename,
+ join,
+} from 'node:path';
+import {
+ CONFIG_FILE,
+ COORDINATOR,
+ doctrineFile,
+ loadConfig,
+} from './config.js';
import { loadDoctrine } from './doctrine.js';
import { installHooks } from './hooks.js';
import { Refused } from './refused.js';
import { installSkills } from './skills.js';
-import { AGENTS_END, AGENTS_START, agentsBlock, configTemplate, practiceTemplate, specTemplate } from './templates.js';
+import {
+ AGENTS_END,
+ AGENTS_START,
+ agentsBlock,
+ configTemplate,
+ practiceTemplate,
+ specTemplate,
+} from './templates.js';
const NPM_DEFAULT_TEST = 'echo "Error: no test specified" && exit 1';
diff --git a/src/land.js b/src/land.js
index 03816629..a92066bb 100644
--- a/src/land.js
+++ b/src/land.js
@@ -1,10 +1,36 @@
/** Coordinator landing batches retain exact Git and gate receipts across interruptions [B3,R3]. */
-import { createHash, randomUUID } from 'node:crypto';
-import { copyFileSync, existsSync, mkdirSync, readFileSync } from 'node:fs';
-import { dirname, isAbsolute, join, relative } from 'node:path';
+import {
+ createHash,
+ randomUUID,
+} from 'node:crypto';
+import {
+ copyFileSync,
+ existsSync,
+ mkdirSync,
+ readFileSync,
+} from 'node:fs';
+import {
+ dirname,
+ isAbsolute,
+ join,
+ relative,
+} from 'node:path';
import * as store from './board.js';
-import { git, headCommit, headTree, isClean, mainCheckout, repoInfo, tryGit, untracked } from './git.js';
-import { runGate, runProfiledShell, withGateSlot } from './gate.js';
+import {
+ git,
+ headCommit,
+ headTree,
+ isClean,
+ mainCheckout,
+ repoInfo,
+ tryGit,
+ untracked,
+} from './git.js';
+import {
+ runGate,
+ runProfiledShell,
+ withGateSlot,
+} from './gate.js';
import { laneOf } from './lanes.js';
import { Refused } from './refused.js';
diff --git a/src/machine-home.js b/src/machine-home.js
index ff5efdba..24b9a0a3 100644
--- a/src/machine-home.js
+++ b/src/machine-home.js
@@ -1,6 +1,9 @@
/** Resolve the per-account directory for machine-wide Pullboard state. */
import { userInfo } from 'node:os';
-import { join, resolve } from 'node:path';
+import {
+ join,
+ resolve,
+} from 'node:path';
/** Use the OS account home unless a caller explicitly selects a private machine pool. */
export function machineHome() {
diff --git a/src/main-red.js b/src/main-red.js
index c6004099..5d3f7ebd 100644
--- a/src/main-red.js
+++ b/src/main-red.js
@@ -1,14 +1,35 @@
/** Fresh per-file main comparisons for inherited submit reds [V1]. */
import { spawnSync } from 'node:child_process';
import { randomUUID } from 'node:crypto';
-import { lstatSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
-import { join, relative, resolve, sep } from 'node:path';
+import {
+ lstatSync,
+ mkdirSync,
+ readFileSync,
+ renameSync,
+ rmSync,
+ writeFileSync,
+} from 'node:fs';
+import {
+ join,
+ relative,
+ resolve,
+ sep,
+} from 'node:path';
import { tmpdir } from 'node:os';
import { stripVTControlCharacters } from 'node:util';
import { fileURLToPath } from 'node:url';
-import { runProfiledShellAsync, withGateSlot } from './gate.js';
-import { cleanGitEnvironment, mainCheckout } from './git.js';
-import { mainPolicy, policyAt } from './trusted-policy.js';
+import {
+ runProfiledShellAsync,
+ withGateSlot,
+} from './gate.js';
+import {
+ cleanGitEnvironment,
+ mainCheckout,
+} from './git.js';
+import {
+ mainPolicy,
+ policyAt,
+} from './trusted-policy.js';
import { parseSpec } from './spec.js';
import { listItems } from './board.js';
import { takeResource } from './resources.js';
diff --git a/src/module-imports.js b/src/module-imports.js
index ce501137..2d6f24db 100644
--- a/src/module-imports.js
+++ b/src/module-imports.js
@@ -1,6 +1,10 @@
/** Parse import edges without evaluating repository code, using V8 rather than a JavaScript grammar guess [V4,C7]. */
import { spawnSync } from 'node:child_process';
-import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
+import {
+ mkdtempSync,
+ rmSync,
+ writeFileSync,
+} from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
diff --git a/src/pairing.js b/src/pairing.js
index ccb57d3c..3554276b 100644
--- a/src/pairing.js
+++ b/src/pairing.js
@@ -1,5 +1,8 @@
/** Client-side one-time pairing envelope; the relay sees only locator-bound ciphertext [H15,H17]. */
-import { randomBytes, webcrypto } from 'node:crypto';
+import {
+ randomBytes,
+ webcrypto,
+} from 'node:crypto';
import { ENGINE_VERSION } from './machine.js';
import { Refused } from './refused.js';
diff --git a/src/private-check-worker.js b/src/private-check-worker.js
index 1cd8e241..bddbb006 100644
--- a/src/private-check-worker.js
+++ b/src/private-check-worker.js
@@ -1,6 +1,10 @@
/** Collect private command output through pipes; dependency files are never size-limited [V18,V2]. */
import { spawn } from 'node:child_process';
-import { createWriteStream, readFileSync, writeFileSync } from 'node:fs';
+import {
+ createWriteStream,
+ readFileSync,
+ writeFileSync,
+} from 'node:fs';
const { command, timeout, pidFile, logPath } = JSON.parse(readFileSync(0, 'utf8'));
const LIMIT = 8 * 1024 * 1024;
diff --git a/src/projects.js b/src/projects.js
index efbade79..90ae6cc2 100644
--- a/src/projects.js
+++ b/src/projects.js
@@ -2,9 +2,23 @@
* The projects on this machine: every initialized repo, with optional project and display names.
* The registry lives in the user's home (or PULLBOARD_HOME for isolated runs).
*/
-import { closeSync, existsSync, fsyncSync, mkdirSync, openSync, readFileSync, renameSync, statSync, writeFileSync } from 'node:fs';
+import {
+ closeSync,
+ existsSync,
+ fsyncSync,
+ mkdirSync,
+ openSync,
+ readFileSync,
+ renameSync,
+ statSync,
+ writeFileSync,
+} from 'node:fs';
import { homedir } from 'node:os';
-import { basename, join, resolve } from 'node:path';
+import {
+ basename,
+ join,
+ resolve,
+} from 'node:path';
import { randomUUID } from 'node:crypto';
import { DatabaseSync } from 'node:sqlite';
import { loadConfig } from './config.js';
diff --git a/src/relay-key.js b/src/relay-key.js
index f45b657f..f4b30014 100644
--- a/src/relay-key.js
+++ b/src/relay-key.js
@@ -1,10 +1,22 @@
/** Device-only board keys, kept outside repositories and relay requests [H1,H15,H17]. */
import { spawnSync } from 'node:child_process';
import { randomUUID } from 'node:crypto';
-import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from 'node:fs';
+import {
+ existsSync,
+ lstatSync,
+ mkdirSync,
+ readFileSync,
+ readdirSync,
+ renameSync,
+ rmSync,
+ writeFileSync,
+} from 'node:fs';
import { homedir } from 'node:os';
import { join } from 'node:path';
-import { decodeBoardKey, encodeBoardKey } from './seal.js';
+import {
+ decodeBoardKey,
+ encodeBoardKey,
+} from './seal.js';
import { Refused } from './refused.js';
/** Validate a persistent board identity before using it as a file or credential name. */
diff --git a/src/relay-machine.js b/src/relay-machine.js
index 29d22ac7..d5582659 100644
--- a/src/relay-machine.js
+++ b/src/relay-machine.js
@@ -1,10 +1,26 @@
/** Owner-only machine metadata, authenticated device roster and one-use enrollment [H5,H15,H17]. */
import { randomUUID } from 'node:crypto';
-import { closeSync, existsSync, fsyncSync, lstatSync, mkdirSync, openSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from 'node:fs';
+import {
+ closeSync,
+ existsSync,
+ fsyncSync,
+ lstatSync,
+ mkdirSync,
+ openSync,
+ readFileSync,
+ readdirSync,
+ renameSync,
+ rmSync,
+ writeFileSync,
+} from 'node:fs';
import { homedir } from 'node:os';
import { join } from 'node:path';
import { DatabaseSync } from 'node:sqlite';
-import { authenticateDeviceEnrollment, devicePublicKey, wrapDeviceBoardKey } from './relay-device-keys.js';
+import {
+ authenticateDeviceEnrollment,
+ devicePublicKey,
+ wrapDeviceBoardKey,
+} from './relay-device-keys.js';
import { scrubLegacyPersonSessions } from './relay-key.js';
import { approvalContext } from './relay-approval.js';
import { createPairingCode } from './pairing.js';
diff --git a/src/relay-pairing-client.js b/src/relay-pairing-client.js
index a90d5395..fcc46c1e 100644
--- a/src/relay-pairing-client.js
+++ b/src/relay-pairing-client.js
@@ -1,15 +1,46 @@
/** CLI pairing flow: the relay stores only a one-use client-encrypted package [H15,H17]. */
import { randomUUID } from 'node:crypto';
-import { existsSync, lstatSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
-import { dirname, join } from 'node:path';
+import {
+ existsSync,
+ lstatSync,
+ mkdirSync,
+ readFileSync,
+ renameSync,
+ rmSync,
+ writeFileSync,
+} from 'node:fs';
+import {
+ dirname,
+ join,
+} from 'node:path';
import * as store from './board.js';
-import { exportBoard, importBoard } from './exchange.js';
-import { codeIsFromMain, repoInfo } from './git.js';
-import { forgetBoardKey, readBoardKey, storeBoardKey } from './relay-key.js';
+import {
+ exportBoard,
+ importBoard,
+} from './exchange.js';
+import {
+ codeIsFromMain,
+ repoInfo,
+} from './git.js';
+import {
+ forgetBoardKey,
+ readBoardKey,
+ storeBoardKey,
+} from './relay-key.js';
import { encodeBoardKey } from './seal.js';
-import { createPairingCode, openPairingBundle, parsePairingCode, sealPairingBundle } from './pairing.js';
+import {
+ createPairingCode,
+ openPairingBundle,
+ parsePairingCode,
+ sealPairingBundle,
+} from './pairing.js';
import { terminalQr } from './qr.js';
-import { DEFAULT_RELAY, originRepository, relayStatus, syncRelay } from './relay.js';
+import {
+ DEFAULT_RELAY,
+ originRepository,
+ relayStatus,
+ syncRelay,
+} from './relay.js';
import { ENGINE_VERSION } from './machine.js';
import { Refused } from './refused.js';
import { requirePersonChannel } from './person.js';
diff --git a/src/relay-phone.js b/src/relay-phone.js
index 79d42250..cddc5537 100644
--- a/src/relay-phone.js
+++ b/src/relay-phone.js
@@ -1,6 +1,12 @@
/** Native approval requests never retain a person grant or its reply key [H5,H16,H17,B26]. */
import { randomUUID } from 'node:crypto';
-import { approvalContext, createApprovalReply, openApproval, sealApproval, signApprovalIntent } from './relay-approval.js';
+import {
+ approvalContext,
+ createApprovalReply,
+ openApproval,
+ sealApproval,
+ signApprovalIntent,
+} from './relay-approval.js';
import { readBoardKey } from './relay-key.js';
import { readRelayMachine } from './relay-machine.js';
import { requirePersonChannel } from './person.js';
diff --git a/src/relay-presentation.js b/src/relay-presentation.js
index b89ed310..154aee83 100644
--- a/src/relay-presentation.js
+++ b/src/relay-presentation.js
@@ -3,7 +3,10 @@ import { createHash } from 'node:crypto';
import { join } from 'node:path';
import * as store from './board.js';
import { exportBoard } from './exchange.js';
-import { codeIsFromMain, repoInfo } from './git.js';
+import {
+ codeIsFromMain,
+ repoInfo,
+} from './git.js';
import { Refused } from './refused.js';
import { loadConfig } from './config.js';
import { projectState } from './serve.js';
diff --git a/src/relay-request-execution.js b/src/relay-request-execution.js
index 4d1a3271..e46aa404 100644
--- a/src/relay-request-execution.js
+++ b/src/relay-request-execution.js
@@ -1,15 +1,30 @@
/** Native person requests run the actual CLI outside the relay lock [H12,H16]. */
-import { createHash, randomUUID } from 'node:crypto';
+import {
+ createHash,
+ randomUUID,
+} from 'node:crypto';
import { join } from 'node:path';
import * as store from './board.js';
import { executeMove } from './api.js';
import { loadConfig } from './config.js';
-import { codeIsFromMain, git, repoInfo } from './git.js';
+import {
+ codeIsFromMain,
+ git,
+ repoInfo,
+} from './git.js';
import { laneNames } from './lanes.js';
import { refusalDocument } from './json.js';
import { Refused } from './refused.js';
-import { relayLinked, relayOperation, relayRequestDevice } from './relay.js';
-import { personRequestRecords, requestIntentDigest, requestStageText } from './relay-requests.js';
+import {
+ relayLinked,
+ relayOperation,
+ relayRequestDevice,
+} from './relay.js';
+import {
+ personRequestRecords,
+ requestIntentDigest,
+ requestStageText,
+} from './relay-requests.js';
/** Read durable intake without retaining a SQLite connection while the CLI runs. */
function requests(root) {
diff --git a/src/relay-setup.js b/src/relay-setup.js
index ef931dbf..1db43bb5 100644
--- a/src/relay-setup.js
+++ b/src/relay-setup.js
@@ -2,13 +2,39 @@
import { join } from 'node:path';
import { randomUUID } from 'node:crypto';
import * as store from './board.js';
-import { phoneProposal, publishPhoneApproval, warnPhoneApproval } from './relay-phone.js';
-import { openApproval, restoreLinkReply } from './relay-approval.js';
+import {
+ phoneProposal,
+ publishPhoneApproval,
+ warnPhoneApproval,
+} from './relay-phone.js';
+import {
+ openApproval,
+ restoreLinkReply,
+} from './relay-approval.js';
import { requirePersonChannel } from './person.js';
-import { codeIsFromMain, repoInfo } from './git.js';
+import {
+ codeIsFromMain,
+ repoInfo,
+} from './git.js';
import { listApiProjects } from './projects.js';
-import { acceptDeviceEnrollment, beginDeviceEnrollment, readRelayMachine, relayMachineOwner, updateRelayMachine } from './relay-machine.js';
-import { deliverDeviceWraps, relayDeviceRequest, relayMachineSignIn, relayMachineContext, relayRevokeDevice, relayOn, relayStatus, originRepository, revokeRelayPersonSession } from './relay.js';
+import {
+ acceptDeviceEnrollment,
+ beginDeviceEnrollment,
+ readRelayMachine,
+ relayMachineOwner,
+ updateRelayMachine,
+} from './relay-machine.js';
+import {
+ deliverDeviceWraps,
+ relayDeviceRequest,
+ relayMachineSignIn,
+ relayMachineContext,
+ relayRevokeDevice,
+ relayOn,
+ relayStatus,
+ originRepository,
+ revokeRelayPersonSession,
+} from './relay.js';
import { terminalQr } from './qr.js';
import { Refused } from './refused.js';
diff --git a/src/relay.js b/src/relay.js
index bbb42d66..d4c04d46 100644
--- a/src/relay.js
+++ b/src/relay.js
@@ -1,25 +1,91 @@
/** Opt-in, sealed relay ordering, with crash-safe migration from the older mirror [H1,H3,H5,H16,H17,P5]. */
-import { createHash, randomUUID } from 'node:crypto';
-import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from 'node:fs';
+import {
+ createHash,
+ randomUUID,
+} from 'node:crypto';
+import {
+ existsSync,
+ lstatSync,
+ mkdirSync,
+ readFileSync,
+ readdirSync,
+ renameSync,
+ rmSync,
+ writeFileSync,
+} from 'node:fs';
import { hostname } from 'node:os';
-import { basename, dirname, join } from 'node:path';
-import { gunzipSync, gzipSync } from 'node:zlib';
+import {
+ basename,
+ dirname,
+ join,
+} from 'node:path';
+import {
+ gunzipSync,
+ gzipSync,
+} from 'node:zlib';
import * as store from './board.js';
-import { exportBoard, importBoard, restoreRelaySnapshot, semanticBoardDigest } from './exchange.js';
-import { appliedSequence, applyRelayMove, checkpointSequence, engineReceipt, prepareEngineMove, refuseRelayMove, requireSupportedEngine, startRelayEpoch } from './engine.js';
+import {
+ exportBoard,
+ importBoard,
+ restoreRelaySnapshot,
+ semanticBoardDigest,
+} from './exchange.js';
+import {
+ appliedSequence,
+ applyRelayMove,
+ checkpointSequence,
+ engineReceipt,
+ prepareEngineMove,
+ refuseRelayMove,
+ requireSupportedEngine,
+ startRelayEpoch,
+} from './engine.js';
import { relayMoveActor } from './relay-sender.js';
import { ENGINE_VERSION } from './machine.js';
-import { presentationDigest, relayPresentation, relaySnapshot } from './relay-presentation.js';
-import { codeIsFromMain, repoInfo, tryGit } from './git.js';
-import { forgetBoardKey, readBoardKey, storeBoardKey } from './relay-key.js';
-import { encodeBoardKey, generateBoardKey, seal, unseal } from './seal.js';
+import {
+ presentationDigest,
+ relayPresentation,
+ relaySnapshot,
+} from './relay-presentation.js';
+import {
+ codeIsFromMain,
+ repoInfo,
+ tryGit,
+} from './git.js';
+import {
+ forgetBoardKey,
+ readBoardKey,
+ storeBoardKey,
+} from './relay-key.js';
+import {
+ encodeBoardKey,
+ generateBoardKey,
+ seal,
+ unseal,
+} from './seal.js';
import { terminalQr } from './qr.js';
import { Refused } from './refused.js';
import { relaySenderProblem } from './relay-sender.js';
-import { readRelayMachine, removeRecordedDevice, updateRelayMachine, wrapForRecordedDevice } from './relay-machine.js';
-import { receivePersonRequest, requestMoveProblem } from './relay-requests.js';
-import { nativePhoneAction, phoneProposal, publishPhoneApproval, warnPhoneApproval } from './relay-phone.js';
-import { requirePersonChannel, requireRelayOnChannel } from './person.js';
+import {
+ readRelayMachine,
+ removeRecordedDevice,
+ updateRelayMachine,
+ wrapForRecordedDevice,
+} from './relay-machine.js';
+import {
+ receivePersonRequest,
+ requestMoveProblem,
+} from './relay-requests.js';
+import {
+ nativePhoneAction,
+ phoneProposal,
+ publishPhoneApproval,
+ warnPhoneApproval,
+} from './relay-phone.js';
+import {
+ requirePersonChannel,
+ requireRelayOnChannel,
+} from './person.js';
import { listApiProjects } from './projects.js';
export const DEFAULT_RELAY = 'https://app.pullboard.dev';
diff --git a/src/resources.js b/src/resources.js
index 7f505336..9ad937b0 100644
--- a/src/resources.js
+++ b/src/resources.js
@@ -1,7 +1,15 @@
/** Machine and repository queues persist leases; landings go first, then eligible waiters in arrival order [Q1,Q2,Q3]. */
-import { mkdirSync, realpathSync } from 'node:fs';
+import {
+ mkdirSync,
+ realpathSync,
+} from 'node:fs';
import { execFileSync } from 'node:child_process';
-import { basename, dirname, join, resolve } from 'node:path';
+import {
+ basename,
+ dirname,
+ join,
+ resolve,
+} from 'node:path';
import { randomUUID } from 'node:crypto';
import { DatabaseSync } from 'node:sqlite';
import { repoInfo } from './git.js';
diff --git a/src/roadmap.js b/src/roadmap.js
index 514fa8f9..b315a4be 100644
--- a/src/roadmap.js
+++ b/src/roadmap.js
@@ -1,7 +1,19 @@
/** Read milestone references across the boards registered on this machine. */
-import { basename, resolve, join } from 'node:path';
-import { closeBoard, getItem, openBoard, roadmap } from './board.js';
-import { codeIsFromMain, repoInfo } from './git.js';
+import {
+ basename,
+ resolve,
+ join,
+} from 'node:path';
+import {
+ closeBoard,
+ getItem,
+ openBoard,
+ roadmap,
+} from './board.js';
+import {
+ codeIsFromMain,
+ repoInfo,
+} from './git.js';
import { listApiProjects } from './projects.js';
/** Resolve a repo-qualified milestone item against registered boards, optionally within an API scope.
diff --git a/src/row-decisions.js b/src/row-decisions.js
index f45638c0..69911523 100644
--- a/src/row-decisions.js
+++ b/src/row-decisions.js
@@ -1,9 +1,27 @@
/** Exact person row decisions and coordinator file application [B26,S18,S19]. */
-import { appendFileSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
-import { dirname, join } from 'node:path';
+import {
+ appendFileSync,
+ existsSync,
+ mkdirSync,
+ readFileSync,
+ rmSync,
+ writeFileSync,
+} from 'node:fs';
+import {
+ dirname,
+ join,
+} from 'node:path';
import { loadDoctrine } from './doctrine.js';
-import { loadSpec, SIGNOFFS_FILE } from './spec.js';
-import { defaultPrincipal, hasSignerFile, signRowDecision, verifyRowDecision } from './signature.js';
+import {
+ loadSpec,
+ SIGNOFFS_FILE,
+} from './spec.js';
+import {
+ defaultPrincipal,
+ hasSignerFile,
+ signRowDecision,
+ verifyRowDecision,
+} from './signature.js';
import { Refused } from './refused.js';
/** Resolve qualified doctrine ids while bare ids continue to name the spec. */
diff --git a/src/run.js b/src/run.js
index e8b87370..4031fcfe 100644
--- a/src/run.js
+++ b/src/run.js
@@ -9,16 +9,48 @@
* Pullboard never calls a model itself (E4): the agent command is whatever the person runs, such as
* OpenCode on a local model or Claude Code headless on a smaller one.
*/
-import { spawn, spawnSync } from 'node:child_process';
-import { appendFileSync, existsSync, mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';
+import {
+ spawn,
+ spawnSync,
+} from 'node:child_process';
+import {
+ appendFileSync,
+ existsSync,
+ mkdirSync,
+ readFileSync,
+ rmSync,
+ statSync,
+ writeFileSync,
+} from 'node:fs';
import { join } from 'node:path';
import * as store from './board.js';
import { briefFiles } from './brief.js';
-import { CONFIG_FILE, COORDINATOR, loadConfig } from './config.js';
-import { doctrineText, loadDoctrine } from './doctrine.js';
-import { digestOf, runGate } from './gate.js';
-import { contains, git, headCommit, invalidateGitFacts, isClean, tryGit, untracked } from './git.js';
-import { laneNames, outOfLane } from './lanes.js';
+import {
+ CONFIG_FILE,
+ COORDINATOR,
+ loadConfig,
+} from './config.js';
+import {
+ doctrineText,
+ loadDoctrine,
+} from './doctrine.js';
+import {
+ digestOf,
+ runGate,
+} from './gate.js';
+import {
+ contains,
+ git,
+ headCommit,
+ invalidateGitFacts,
+ isClean,
+ tryGit,
+ untracked,
+} from './git.js';
+import {
+ laneNames,
+ outOfLane,
+} from './lanes.js';
import { Refused } from './refused.js';
/** Report changing machine queue state while an unattended item waits for a gate slot. */
diff --git a/src/settings.js b/src/settings.js
index 5c3f3542..1094e275 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -1,6 +1,16 @@
/** Machine-wide settings shared by every Pullboard checkout on this machine. */
-import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
-import { dirname, join } from 'node:path';
+import {
+ existsSync,
+ mkdirSync,
+ readFileSync,
+ renameSync,
+ rmSync,
+ writeFileSync,
+} from 'node:fs';
+import {
+ dirname,
+ join,
+} from 'node:path';
import { randomUUID } from 'node:crypto';
import { machineHome } from './machine-home.js';
import { setResourceCapacity } from './resources.js';
diff --git a/src/signature.js b/src/signature.js
index 4226e841..b10fb49c 100644
--- a/src/signature.js
+++ b/src/signature.js
@@ -1,8 +1,25 @@
/** Offline SSH signature handling for spec sign-offs and signer-list transitions [S17,S18,S19,S20,S21]. */
-import { createHash, randomUUID } from 'node:crypto';
-import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
-import { homedir, tmpdir } from 'node:os';
-import { dirname, join, resolve } from 'node:path';
+import {
+ createHash,
+ randomUUID,
+} from 'node:crypto';
+import {
+ existsSync,
+ mkdirSync,
+ readFileSync,
+ renameSync,
+ rmSync,
+ writeFileSync,
+} from 'node:fs';
+import {
+ homedir,
+ tmpdir,
+} from 'node:os';
+import {
+ dirname,
+ join,
+ resolve,
+} from 'node:path';
import { spawnSync } from 'node:child_process';
import { gitConfig } from './git.js';
import { Refused } from './refused.js';
diff --git a/src/skills.js b/src/skills.js
index 57d029f4..e2c2bc01 100644
--- a/src/skills.js
+++ b/src/skills.js
@@ -5,7 +5,12 @@
* agent, and a repo's own override in `.pullboard/prompts/<role>.md`.
*/
import { createHash } from 'node:crypto';
-import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
+import {
+ existsSync,
+ mkdirSync,
+ readFileSync,
+ writeFileSync,
+} from 'node:fs';
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { Refused } from './refused.js';
diff --git a/src/spec.js b/src/spec.js
index 00ac4d4b..9e4fa28a 100644
--- a/src/spec.js
+++ b/src/spec.js
@@ -9,12 +9,28 @@
*/
import { createHash } from 'node:crypto';
import { spawnSync } from 'node:child_process';
-import { appendFileSync, existsSync, mkdirSync, readFileSync } from 'node:fs';
-import { dirname, join } from 'node:path';
-import { DOCTRINE_FILE, LEGACY_DOCTRINE_FILE } from './config.js';
+import {
+ appendFileSync,
+ existsSync,
+ mkdirSync,
+ readFileSync,
+} from 'node:fs';
+import {
+ dirname,
+ join,
+} from 'node:path';
+import {
+ DOCTRINE_FILE,
+ LEGACY_DOCTRINE_FILE,
+} from './config.js';
import { cleanGitEnvironment } from './git.js';
import { Refused } from './refused.js';
-import { hasSignerFile, isVerifiedSignoff, signRows, verifySignedRecords } from './signature.js';
+import {
+ hasSignerFile,
+ isVerifiedSignoff,
+ signRows,
+ verifySignedRecords,
+} from './signature.js';
export const STATUSES = ['approved', 'draft', 'pending', 'fact', 'wont', 'retired'];
export const TIERS = ['must', 'aim'];
diff --git a/src/sweep.js b/src/sweep.js
index 291945d5..b4a0ce48 100644
--- a/src/sweep.js
+++ b/src/sweep.js
@@ -4,7 +4,10 @@
* item per file, in the lane that owns it, with the exact problems in its brief and the same tool,
* run on that file, as its check. Much of a codebase's rigor is just running that loop.
*/
-import { relative, isAbsolute } from 'node:path';
+import {
+ relative,
+ isAbsolute,
+} from 'node:path';
const TSC_RE = /^(.+?)\((\d+),(\d+)\): (?:error|warning) (TS\d+): (.+)$/;
const LINE_RE = /^([^\s:][^:]*?):(\d+)(?::(\d+))?:?\s+(.+)$/;
diff --git a/src/templates.js b/src/templates.js
index 4ca3e3fe..e5776780 100644
--- a/src/templates.js
+++ b/src/templates.js
@@ -2,7 +2,10 @@
* What `pullboard init` writes into a repo: the config, a starter spec, and the agent instructions
* every coding agent reads (AGENTS.md, which CLAUDE.md points at).
*/
-import { doctrineText, standardDoctrine } from './doctrine.js';
+import {
+ doctrineText,
+ standardDoctrine,
+} from './doctrine.js';
import { DOCTRINE_FILE } from './config.js';
export const AGENTS_START = '<!-- pullboard:start -->';
diff --git a/src/timing.js b/src/timing.js
index 28639104..cf5ec658 100644
--- a/src/timing.js
+++ b/src/timing.js
@@ -1,5 +1,9 @@
/** Read durations already printed by a caller's test runner, without changing its command [C7,V10]. */
-import { closeSync, openSync, readSync } from 'node:fs';
+import {
+ closeSync,
+ openSync,
+ readSync,
+} from 'node:fs';
import { StringDecoder } from 'node:string_decoder';
const MAX_LINE = 64 * 1024;
diff --git a/src/tour.js b/src/tour.js
index 61984255..03110731 100644
--- a/src/tour.js
+++ b/src/tour.js
@@ -5,7 +5,13 @@
* the machine; the repo stays behind to look around in.
*/
import { spawnSync } from 'node:child_process';
-import { chmodSync, mkdirSync, mkdtempSync, realpathSync, writeFileSync } from 'node:fs';
+import {
+ chmodSync,
+ mkdirSync,
+ mkdtempSync,
+ realpathSync,
+ writeFileSync,
+} from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
diff --git a/src/trusted-policy.js b/src/trusted-policy.js
index 76f2c7b4..b7d82e1f 100644
--- a/src/trusted-policy.js
+++ b/src/trusted-policy.js
@@ -1,16 +1,42 @@
/** Coordinator policy and immutable submission checks cannot come from a builder's candidate [V4,V16,L3,M3]. */
import { randomUUID } from 'node:crypto';
import { spawnSync } from 'node:child_process';
-import { digestOf, writeTimingProfile } from './gate.js';
-import { timingFromOutput, timingFromLog, timingRunner } from './timing.js';
-import { closeSync, existsSync, mkdtempSync, mkdirSync, openSync, readFileSync, readSync, rmSync, writeSync } from 'node:fs';
+import {
+ digestOf,
+ writeTimingProfile,
+} from './gate.js';
+import {
+ timingFromOutput,
+ timingFromLog,
+ timingRunner,
+} from './timing.js';
+import {
+ closeSync,
+ existsSync,
+ mkdtempSync,
+ mkdirSync,
+ openSync,
+ readFileSync,
+ readSync,
+ rmSync,
+ writeSync,
+} from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { StringDecoder } from 'node:string_decoder';
import { fileURLToPath } from 'node:url';
-import { GATE_SLOT_HELD_ENV, gateSlotEnvironment } from './resources.js';
+import {
+ GATE_SLOT_HELD_ENV,
+ gateSlotEnvironment,
+} from './resources.js';
import { configFromSource } from './config.js';
-import { cleanGitEnvironment, gitConfig, invalidateGitFacts, mainCheckout, refuseGrafts } from './git.js';
+import {
+ cleanGitEnvironment,
+ gitConfig,
+ invalidateGitFacts,
+ mainCheckout,
+ refuseGrafts,
+} from './git.js';
import { secretsIn } from './hooks.js';
import { outOfLane } from './lanes.js';
import { Refused } from './refused.js';
diff --git a/src/view-session.js b/src/view-session.js
index 547b31e5..2f09dc01 100644
--- a/src/view-session.js
+++ b/src/view-session.js
@@ -1,7 +1,20 @@
/** Private runtime records that let an unattended CLI hand off its live view link. */
-import { chmodSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
-import { dirname, join } from 'node:path';
-import { LOOPBACK, lastPort } from './serve.js';
+import {
+ chmodSync,
+ mkdirSync,
+ readFileSync,
+ renameSync,
+ rmSync,
+ writeFileSync,
+} from 'node:fs';
+import {
+ dirname,
+ join,
+} from 'node:path';
+import {
+ LOOPBACK,
+ lastPort,
+} from './serve.js';
import { registryFile } from './projects.js';
import { fetchLocal } from './local-fetch.js';
diff --git a/test/cli-help.test.js b/test/cli-help.test.js
index 7dc3c3a1..03783d15 100644
--- a/test/cli-help.test.js
+++ b/test/cli-help.test.js
@@ -1,11 +1,16 @@
/** The layered CLI help stays short, command-specific, and in parity with its declaration [N37,I1]. */
import assert from 'node:assert/strict';
-import { mkdtempSync, rmSync } from 'node:fs';
+import { mkdtempSync, readdirSync, readFileSync, rmSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join, resolve } from 'node:path';
import { runFixtureChild } from './fixture-child.js';
import { after, test } from 'node:test';
import { HELP, resultCommands } from '../src/cli.js';
+import * as helpDeclaration from '../src/help.js';
+import { importStyleViolations } from './import-style-helpers.js';
+import { pathToFileURL } from 'node:url';
+import { loadConfig } from '../src/config.js';
+import { laneOf } from '../src/lanes.js';
const BIN = resolve(import.meta.dirname, '../bin/pullboard.js');
const sandboxes = [];
@@ -123,3 +128,57 @@ test('next help exposes explicit build intent alongside review reservations [Q1,
assert.match(all.stdout, /pullboard next \[--wait <minutes>\]\s+offer an eligible review when reviews pile up, otherwise claim work/u);
assert.match(all.stdout, /pullboard next --build\s+claim a build explicitly, recording a skipped review offer/u);
});
+
+test('help names come from the command declarations [C7,N37]', async (t) => {
+ const overview = run('help');
+ const all = run('help', '--all');
+ assert.equal(overview.status, 0, overview.failure);
+ assert.equal(all.status, 0, all.failure);
+ assert.equal(overview.stdout, HELP.overview + '\n');
+ assert.equal(all.stdout, HELP.all + '\n');
+ t.diagnostic('help overview bytes ' + JSON.stringify(overview.stdout));
+
+ const directory = resolve(import.meta.dirname, '../src');
+ const config = loadConfig(resolve(directory, '..'));
+ const sources = readdirSync(directory, { recursive: true })
+ .filter((file) => file.endsWith('.js') && laneOf(config, `src/${file}`) === 'core')
+ .map((file) => ({ file, source: readFileSync(join(directory, file), 'utf8') }));
+ assert.ok(sources.length > 0, 'the core lane owns source files');
+ assert.deepEqual(importStyleViolations(sources), [], 'each actual static import has one binding per line');
+ const styles = [
+ { file: 'same-line', source: "import { first, second as renamed } from 'module';" },
+ { file: 'mixed', source: "import initial, { first } from 'module';" },
+ { file: 'namespace', source: "import initial, * as space from 'module';" },
+ { file: 'formatted', source: "import {\n first,\n second as renamed,\n} from 'module';" },
+ { file: 'comments', source: "import /* before */ { first, /* middle */ second } from 'module';" },
+ { file: 'attributes', source: "import { first, second } from 'module' with { type: 'json' };" },
+ { file: 'text', source: "const text = 'import { first, second }'; const raw = `import { first, second }`; const expression = /import { first, second }/; /* import { first, second } */" },
+ { file: 'quoted', source: "import { 'a,b' as first } from 'module';" },
+ { file: 'line-separator', source: "import { // comment\u2028 first, second } from 'module';" },
+ { file: 'paragraph-separator', source: "import // comment\u2029 { first, second } from 'module';" },
+ ];
+ assert.deepEqual(importStyleViolations(styles), ['same-line', 'mixed', 'namespace', 'comments', 'attributes']
+ .map((file) => ({ file, line: 1, count: 2 })).concat([
+ { file: 'line-separator', line: 2, count: 2 },
+ { file: 'paragraph-separator', line: 2, count: 2 },
+ ]));
+
+ assert.equal(typeof helpDeclaration.buildHelp, 'function', 'help is built from declarations');
+ const generated = helpDeclaration.buildHelp([...resultCommands(), 'future-command']);
+ for (const name of resultCommands()) assert.ok(generated.commands[name], `${name} is derived`);
+ assert.deepEqual(generated.commands['future-command'].usages, ['pullboard future-command']);
+ assert.equal(generated.overview, HELP.overview, 'a new declaration preserves the overview bytes');
+ assert.equal(generated.all, HELP.all, 'a new declaration preserves the full-help bytes');
+
+ const original = readFileSync(join(directory, 'cli.js'), 'utf8');
+ const declaration = /function readCommands\(io, \{ first, second, rest, values \}\) \{\s*return \{/u;
+ assert.match(original, declaration);
+ const extended = original.replace(declaration, (text) => text + "\n/** A private new command proves help follows actual dispatch declarations. */\n'future-command': () => 0,")
+ .replace(/\bfrom (['"])(\.[^'"]+)\1/gu, (_match, _quote, path) => 'from ' + JSON.stringify(pathToFileURL(resolve(directory, path)).href));
+ const privateCli = await import('data:text/javascript;base64,' + Buffer.from(extended).toString('base64'));
+ assert.ok(privateCli.resultCommands().includes('future-command'));
+ assert.deepEqual(privateCli.HELP.commands['future-command']?.usages, ['pullboard future-command'],
+ 'adding an actual command requires no edit to help.js');
+ assert.equal(privateCli.HELP.overview, HELP.overview);
+ assert.equal(privateCli.HELP.all, HELP.all);
+});
diff --git a/test/import-style-helpers.js b/test/import-style-helpers.js
new file mode 100644
index 00000000..01e45043
--- /dev/null
+++ b/test/import-style-helpers.js
@@ -0,0 +1,79 @@
+/** Check actual static import binding lines without mistaking embedded source text for code [C7]. */
+import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { runFixtureChild } from './fixture-child.js';
+
+const GAP = String.raw`(?:\s|/\*[\s\S]*?\*/|//[^\r\n\u2028\u2029]*(?:\r\n|[\r\n\u2028\u2029]|$))*`;
+const IDENTIFIER = String.raw`[\p{ID_Start}_$][\p{ID_Continue}$\u200c\u200d]*`;
+const NAMED = new RegExp(String.raw`\bimport${GAP}(?:(?<default>${IDENTIFIER})${GAP},${GAP})?\{(?<bindings>[^{}]*)\}`, 'dgu');
+const NAMESPACE = new RegExp(String.raw`\bimport${GAP}(?<default>${IDENTIFIER})${GAP},${GAP}\*${GAP}as${GAP}(?<namespace>${IDENTIFIER})`, 'dgu');
+
+/** Keep line positions while removing comments inside an import's binding list. */
+function withoutComments(text) {
+ return text.replace(/(['"])(?:\\[\s\S]|(?!\1)[^\\])*\1|\/\/[^\r\n\u2028\u2029]*|\/\*[\s\S]*?\*\//gu,
+ (part) => part.startsWith('/') ? part.replace(/[^\r\n\u2028\u2029]/gu, ' ') : part);
+}
+
+/** Read binding starts, treating quoted exported names and aliases as one binding each. */
+function bindingOffsets(text) {
+ const clean = withoutComments(text);
+ const starts = [];
+ let start = 0;
+ let quote = null;
+ for (let index = 0; index <= clean.length; index++) {
+ const character = clean[index];
+ if (quote) {
+ if (character === '\\') index++;
+ else if (character === quote) quote = null;
+ } else if (character === '"' || character === "'") quote = character;
+ else if (character === ',' || index === clean.length) {
+ const first = /\S/u.exec(clean.slice(start, index));
+ if (first) starts.push(start + first.index);
+ start = index + 1;
+ }
+ }
+ return starts;
+}
+
+/** Let V8 distinguish code imports from the same words inside comments, strings, templates or regexes. */
+export function importStyleViolations(sources) {
+ const candidates = sources.map(({ source }) => [
+ ...[...source.matchAll(NAMED)].map((match) => ({ at: match.index, offsets: [
+ ...(match.groups.default ? [match.indices.groups.default[0]] : []),
+ ...bindingOffsets(match.groups.bindings).map((offset) => match.indices.groups.bindings[0] + offset),
+ ] })),
+ ...[...source.matchAll(NAMESPACE)].map((match) => ({ at: match.index,
+ offsets: [match.indices.groups.default[0], match.indices.groups.namespace[0]] })),
+ ]);
+ const variants = sources.flatMap(({ source }, index) => candidates[index]
+ .map(({ at }) => source.slice(0, at) + '\u0000' + source.slice(at)));
+ const directory = mkdtempSync(join(tmpdir(), 'pullboard-import-style-'));
+ const input = join(directory, 'sources.json');
+ try {
+ writeFileSync(input, JSON.stringify([...sources.map(({ source }) => source), ...variants]));
+ const program = `import vm from 'node:vm';
+import { readFileSync } from 'node:fs';
+/** Compile syntax without linking or running repository source. */
+function compiles(source) { try { new vm.SourceTextModule(source); return true; } catch { return false; } }
+process.stdout.write(JSON.stringify(JSON.parse(readFileSync(process.argv[1], 'utf8')).map(compiles)));`;
+ const child = runFixtureChild(process.execPath,
+ ['--experimental-vm-modules', '--disable-warning=ExperimentalWarning', '--input-type=module', '-e', program, input],
+ { encoding: 'utf8', timeout: 10_000, killSignal: 'SIGKILL', maxBuffer: 2 ** 24 });
+ if (child.status !== 0) throw new Error(child.failure ?? child.stderr);
+ const compiles = JSON.parse(child.stdout);
+ let next = sources.length;
+ return sources.flatMap(({ file, source }, index) => {
+ if (!compiles[index]) throw new Error(`${file}: source does not compile`);
+ return candidates[index].flatMap(({ offsets }) => {
+ if (compiles[next++]) return [];
+ const lines = new Map();
+ for (const offset of offsets) {
+ const line = source.slice(0, offset).split(/\r\n|[\n\r\u2028\u2029]/u).length;
+ lines.set(line, (lines.get(line) ?? 0) + 1);
+ }
+ return [...lines].filter(([, count]) => count > 1).map(([line, count]) => ({ file, line, count }));
+ });
+ });
+ } finally { rmSync(directory, { recursive: true, force: true }); }
+}