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.
JavaScript agentic-codingai-agentsai-governanceautonomous-agentsclaude-codeclicode-reviewcodexcoding-agentsdeveloper-toolsgit-hooksllmlocal-firstmulti-agentsoftware-factoryspec-driven-developmentverificationvibe-coding
refactor(core): landing messages live in their own module [C7]
Corey Olsoncb7cd42016e4
diff --git a/src/cli.js b/src/cli.jsindex b84d57d9..99515234 100644--- a/src/cli.js+++ b/src/cli.js@@ -387,11 +387,10 @@ import { unlinkedRelayProjects } from './relay-setup.js';import {accountedFailures,landingRemote,- itemCommitType,- landingMessage,waivedFailures,waiverLine,} from './land.js';+import { handMergeCommand } from './landing-message.js';import { installStep } from './worktree.js';import * as infraNotes from './infra-note.js';export { gateWaitReporter };@@ -1454,12 +1453,8 @@ export function landNext(info, item, commit = item.item_commit, { spec = null, rconst trunk = mainCheckout(info.root);const branch = trunk?.branch ?? '';const remote = landingRemote(info.root, branch);- // The hand merge writes the same generated message as pullboard land: the trailers are one paragraph.- const message = landingMessage(item, { spec, type: itemCommitType(info.root, trunk?.commit, commit), ...(requireIds ? { requireIds } : {}) });- const trailers = `"$(printf '%s\\n' ${message.trailers.split('\n').map(shellWord).join(' ')})"`;- const command = remote- ? 'pullboard land'- : `git merge --no-ff ${commit} -m ${shellWord(message.header)} -m ${trailers} && pullboard merged ${item.item_id} HEAD`;+ const command = remote ? 'pullboard land'+ : handMergeCommand(item, commit, { root: info.root, base: trunk?.commit, spec, requireIds, quote: shellWord });if (!mainRoot) return `next: could not safely locate the primary checkout; run from the main checkout: ${command}`;if (remote) return `next: the coordinator lands it: ${cdTo(mainRoot)} ${command}`;return `next: this repo has no remote for pullboard land to push to, so the coordinator merges it on ${branch.replace(/^refs\/heads\//u, '') || 'the trunk'}: ${cdTo(mainRoot)} ${command}`;diff --git a/src/land.js b/src/land.jsindex a9cab279..59c45725 100644--- a/src/land.js+++ b/src/land.js@@ -66,12 +66,9 @@ import { runLandingCandidateWorker } from './landing-candidates.js';import { inheritedGateSlot } from './resources.js';import { Refused } from './refused.js';import {- buildCommitMessage,- commitMessageProblems,- parseCommitMessage,- specOrder,-} from './commit-message.js';-import { loadSpec } from './spec.js';+ checkLandingMessages,+ landingContext,+} from './landing-message.js';import { requireLandingHost } from './landing-host.js';import {environmentLabel,@@ -160,109 +157,14 @@ export function landingFailures(output, root, { excludeCancelled = false } = {})return [...unique.values()];}-/** The merge header type an item with no typed commit takes from its lane; any other lane lands as chore. */-const LANE_MERGE_TYPES = Object.freeze({ docs: 'docs', test: 'test' });--/** Which commit type names an item when its commits mix types: the first in this list wins. */-const TYPE_RANK = Object.freeze(['feat', 'fix', 'perf', 'refactor', 'revert', 'docs', 'test', 'build', 'ci', 'style', 'chore']);--/**- * The item's type, read from the typed headers of its own commits (those in `commit` and not in- * `base`): feat over fix over the rest (RFC 0005 takes the type from the item, and an item has no- * type field). Null when none of its commits is typed, so the lane rule applies.- *- * @param {string} root- * @param {string | null | undefined} base- * @param {string | null | undefined} commit- * @returns {string | null}- */-export function itemCommitType(root, base, commit) {- if (!root || !commit) return null;- const listed = tryGit(root, ['log', '--no-merges', '--format=%s', base ? `${base}..${commit}` : commit]);- if (listed.status !== 0) return null;- const types = new Set(listed.stdout.split('\n').map((subject) => parseCommitMessage(subject).type).filter(Boolean));- return TYPE_RANK.find((type) => types.has(type)) ?? null;-}--/**- * The rows a landing names: the item's final frozen set when it has one, since a refreeze after the- * claim is what the verdict checked, else its cited ids; in spec order when the spec is at hand.- *- * @param {any} item- * @param {{ rows: { id: string }[] } | null} [spec]- * @returns {string[]}- */-export function landingRows(item, spec = null) {- let frozen = null;- try { frozen = item.item_frozen ? JSON.parse(item.item_frozen) : null; } catch { frozen = null; }- const ids = Array.isArray(frozen?.rows)- ? frozen.rows.map((row) => row.id)- : String(item.item_spec_ids ?? '').split(/[\s,]+/u);- return specOrder(ids.filter(Boolean), spec);-}--/**- * The whole landing message from board state through the shared builder [B3,R3]: header- * `<type>(merge): <title> [<rows that fit>,+N]`, then `Pullboard-Item` and `Pullboard-Rows` as the- * last paragraph. It never refuses for how many rows an item cites. The type is the item's own- * (from its commits); with none, or with one the commit hook would refuse without rows, the lane's.- *- * @param {any} item- * @param {{ spec?: { rows: { id: string }[] } | null, type?: string | null, requireIds?: string[] }} [options]- * @returns {{ header: string, body: string, trailers: string, message: string, rows: string[], type: string }}- */-export function landingMessage(item, { spec = null, type = null, requireIds = ['feat', 'fix'] } = {}) {- const rows = landingRows(item, spec);- const own = type && !(requireIds.includes(type) && !rows.length) ? type : null;- const chosen = own ?? (rows.length ? 'chore' : (LANE_MERGE_TYPES[item.item_lane] ?? 'chore'));- return { ...buildCommitMessage({ type: chosen, scope: 'merge', title: item.item_title, item: item.item_id, rows }), rows, type: chosen };-}--/** Produce a hook-valid lower-case merge header at a word boundary [R3]. */-export function landingSubject(item, options = {}) {- return landingMessage(item, options).header;-}--/**- * Check every item's landing message before the first merge of a batch [B3,R3]. The builder- * writes them, so a problem here is a Pullboard defect, never something an item's citations fix.- *- * @param {any[]} items- * @param {{ spec: { rows: { id: string }[] } | null, typeOf?: (item: any) => string | null, requireIds?: string[] }} context- * @returns {Map<number, ReturnType<typeof landingMessage>>}- */-export function checkLandingMessages(items, { spec, typeOf = () => null, requireIds = ['feat', 'fix'] }) {- const messages = new Map();- for (const item of items) {- const built = landingMessage(item, { spec, type: typeOf(item), requireIds });- const problems = commitMessageProblems(built.message, { item: item.item_id, rows: built.rows });- if (problems.length) {- throw new Refused('LAND_HEADER', `the landing message for #${item.item_id} fails its own check (${problems.join('; ')}); nothing merged; shout the coordinator: pullboard shout coordinator "#${item.item_id} landing message fails its check"`);- }- messages.set(item.item_id, built);- }- return messages;-}--/** The trunk spec a landing orders rows by, or none when the repo has no spec file. */-function landingSpec(root, config) {- return config?.spec ? loadSpec(root, config) : null;-}--/**- * Everything a landing message needs from the trunk at `base`: its spec, each item's own type and- * the types the commit hook requires ids for.- *- * @param {string} root- * @param {string} base- * @param {any} config- * @param {(item: any) => string} commitOf - The item's checked landing commit.- * @returns {{ spec: any, typeOf: (item: any) => string | null, requireIds: string[] }}- */-export function landingContext(root, base, config, commitOf) {- return { spec: landingSpec(root, config), typeOf: (item) => itemCommitType(root, base, commitOf(item)),- requireIds: config?.commits?.requireIds ?? ['feat', 'fix'] };-}+export {+ checkLandingMessages,+ itemCommitType,+ landingContext,+ landingMessage,+ landingRows,+ landingSubject,+} from './landing-message.js';/** Keep the submitted identity and, when different, its sealed checked composition. */function landingEntry(item) {diff --git a/src/landing-message.js b/src/landing-message.jsnew file mode 100644index 00000000..5c819123--- /dev/null+++ b/src/landing-message.js@@ -0,0 +1,129 @@+/** Landing messages from board state through the shared commit-message builder (RFC 0005) [B3,R3,C7]. */+import {+ buildCommitMessage,+ commitMessageProblems,+ parseCommitMessage,+ specOrder,+} from './commit-message.js';+import { tryGit } from './git.js';+import { Refused } from './refused.js';+import { loadSpec } from './spec.js';++/** The merge header type an item with no typed commit takes from its lane; any other lane lands as chore. */+const LANE_MERGE_TYPES = Object.freeze({ docs: 'docs', test: 'test' });++/** Which commit type names an item when its commits mix types: the first in this list wins. */+const TYPE_RANK = Object.freeze(['feat', 'fix', 'perf', 'refactor', 'revert', 'docs', 'test', 'build', 'ci', 'style', 'chore']);++/**+ * The item's type, read from the typed headers of its own commits (those in `commit` and not in+ * `base`): feat over fix over the rest (RFC 0005 takes the type from the item, and an item has no+ * type field). Null when none of its commits is typed, so the lane rule applies.+ *+ * @param {string} root+ * @param {string | null | undefined} base+ * @param {string | null | undefined} commit+ * @returns {string | null}+ */+export function itemCommitType(root, base, commit) {+ if (!root || !commit) return null;+ const listed = tryGit(root, ['log', '--no-merges', '--format=%s', base ? `${base}..${commit}` : commit]);+ if (listed.status !== 0) return null;+ const types = new Set(listed.stdout.split('\n').map((subject) => parseCommitMessage(subject).type).filter(Boolean));+ return TYPE_RANK.find((type) => types.has(type)) ?? null;+}++/**+ * The rows a landing names: the item's final frozen set when it has one, since a refreeze after the+ * claim is what the verdict checked, else its cited ids; in spec order when the spec is at hand.+ *+ * @param {any} item+ * @param {{ rows: { id: string }[] } | null} [spec]+ * @returns {string[]}+ */+export function landingRows(item, spec = null) {+ let frozen = null;+ try { frozen = item.item_frozen ? JSON.parse(item.item_frozen) : null; } catch { frozen = null; }+ const ids = Array.isArray(frozen?.rows)+ ? frozen.rows.map((row) => row.id)+ : String(item.item_spec_ids ?? '').split(/[\s,]+/u);+ return specOrder(ids.filter(Boolean), spec);+}++/**+ * The whole landing message from board state through the shared builder [B3,R3]: header+ * `<type>(merge): <title> [<rows that fit>,+N]`, then `Pullboard-Item` and `Pullboard-Rows` as the+ * last paragraph. It never refuses for how many rows an item cites. The type is the item's own+ * (from its commits); with none, or with one the commit hook would refuse without rows, the lane's.+ *+ * @param {any} item+ * @param {{ spec?: { rows: { id: string }[] } | null, type?: string | null, requireIds?: string[] }} [options]+ * @returns {{ header: string, body: string, trailers: string, message: string, rows: string[], type: string }}+ */+export function landingMessage(item, { spec = null, type = null, requireIds = ['feat', 'fix'] } = {}) {+ const rows = landingRows(item, spec);+ const own = type && !(requireIds.includes(type) && !rows.length) ? type : null;+ const chosen = own ?? (rows.length ? 'chore' : (LANE_MERGE_TYPES[item.item_lane] ?? 'chore'));+ return { ...buildCommitMessage({ type: chosen, scope: 'merge', title: item.item_title, item: item.item_id, rows }), rows, type: chosen };+}++/** Produce a hook-valid lower-case merge header at a word boundary [R3]. */+export function landingSubject(item, options = {}) {+ return landingMessage(item, options).header;+}++/**+ * Check every item's landing message before the first merge of a batch [B3,R3]. The builder+ * writes them, so a problem here is a Pullboard defect, never something an item's citations fix.+ *+ * @param {any[]} items+ * @param {{ spec: { rows: { id: string }[] } | null, typeOf?: (item: any) => string | null, requireIds?: string[] }} context+ * @returns {Map<number, ReturnType<typeof landingMessage>>}+ */+export function checkLandingMessages(items, { spec, typeOf = () => null, requireIds = ['feat', 'fix'] }) {+ const messages = new Map();+ for (const item of items) {+ const built = landingMessage(item, { spec, type: typeOf(item), requireIds });+ const problems = commitMessageProblems(built.message, { item: item.item_id, rows: built.rows });+ if (problems.length) {+ throw new Refused('LAND_HEADER', `the landing message for #${item.item_id} fails its own check (${problems.join('; ')}); nothing merged; shout the coordinator: pullboard shout coordinator "#${item.item_id} landing message fails its check"`);+ }+ messages.set(item.item_id, built);+ }+ return messages;+}++/** The trunk spec a landing orders rows by, or none when the repo has no spec file. */+function landingSpec(root, config) {+ return config?.spec ? loadSpec(root, config) : null;+}++/**+ * Everything a landing message needs from the trunk at `base`: its spec, each item's own type and+ * the types the commit hook requires ids for.+ *+ * @param {string} root+ * @param {string} base+ * @param {any} config+ * @param {(item: any) => string} commitOf - The item's checked landing commit.+ * @returns {{ spec: any, typeOf: (item: any) => string | null, requireIds: string[] }}+ */+export function landingContext(root, base, config, commitOf) {+ return { spec: landingSpec(root, config), typeOf: (item) => itemCommitType(root, base, commitOf(item)),+ requireIds: config?.commits?.requireIds ?? ['feat', 'fix'] };+}++/**+ * The exact hand merge that lands an item in a repo with no remote: the same generated header and+ * one trailer paragraph `pullboard land` writes, then the merged receipt [B3,R3].+ *+ * @param {any} item+ * @param {string} commit - The checked composition to merge.+ * @param {{ root: string, base?: string | null, spec?: any, requireIds?: string[], quote: (word: string) => string }} context+ * @returns {string}+ */+export function handMergeCommand(item, commit, { root, base = null, spec = null, requireIds, quote }) {+ const message = landingMessage(item, { spec, type: itemCommitType(root, base, commit), ...(requireIds ? { requireIds } : {}) });+ const trailers = `"$(printf '%s\\n' ${message.trailers.split('\n').map(quote).join(' ')})"`;+ return `git merge --no-ff ${commit} -m ${quote(message.header)} -m ${trailers} && pullboard merged ${item.item_id} HEAD`;+}