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.

perf(git): code origin asks git once; a recorded trunk needs none [C7]

Corey Olson1bf832405774
diff --git a/src/git.js b/src/git.js
index 65ac2a0e..5e70e29c 100644
--- a/src/git.js
+++ b/src/git.js
@@ -576,7 +576,8 @@ export function codeIsFromMain(root = CODE_ROOT) {
/** Determine whether the code is from its main checkout, retaining the non-repository fallback. */
function readCodeIsFromMain(root) {
- const env = gitChildEnv(root);
+ // The same variables `git rev-parse --local-env-vars` names, cleared without a Git process to ask.
+ const env = cleanGitEnvironment();
const info = tryGit(root, ['rev-parse', '--path-format=absolute', '--show-toplevel', '--git-dir', '--git-common-dir'], { env });
const fields = info.stdout.split('\n');
if (info.status === 0 && fields.length === 3 && fields.every(Boolean)) {
@@ -597,6 +598,37 @@ function readCodeIsFromMain(root) {
}
}
+/**
+ * Whether the config file `git config --local` reads holds exactly one plain `<section>.<key>`, and it is `value`.
+ * False whenever the file could mean anything less certain (an include, a continued line, a quoted or commented
+ * value, a repeated key, an inherited selector), so the caller asks Git as before.
+ *
+ * @param {string} root
+ * @param {string} section
+ * @param {string} key
+ * @param {string} value
+ * @returns {boolean}
+ */
+export function localConfigIs(root, section, key, value) {
+ if (!/^[\w./-]+$/u.test(value) || !plainRepositoryEnvironment()) return false;
+ let text;
+ try { text = readFileSync(join(repoInfo(root).commonDir, 'config'), 'utf8'); }
+ catch { return false; }
+ if (/^\s*\[\s*include/imu.test(text) || /\\\r?$/mu.test(text)) return false;
+ let inSection = false;
+ const values = [];
+ for (const line of text.split('\n')) {
+ const header = /^\s*\[([^\]]*)\]\s*$/u.exec(line);
+ if (header) inSection = header[1].trim().toLowerCase() === section;
+ else if (/^\s*\[/u.test(line)) return false;
+ else {
+ const entry = /^\s*([A-Za-z][A-Za-z0-9-]*)\s*(?:=\s*(.*?))?\s*$/u.exec(line);
+ if (inSection && entry?.[1].toLowerCase() === key) values.push(entry[2]);
+ }
+ }
+ return values.length === 1 && values[0] === value;
+}
+
/**
* The full id of a commit-ish, or null when it names no commit here.
*
diff --git a/src/trusted-policy.js b/src/trusted-policy.js
index e103fcb3..f9888d3b 100644
--- a/src/trusted-policy.js
+++ b/src/trusted-policy.js
@@ -36,6 +36,7 @@ import {
cleanGitEnvironment,
gitConfig,
invalidateGitFacts,
+ localConfigIs,
mainCheckout,
refuseGrafts,
} from './git.js';
@@ -60,6 +61,8 @@ export function mainPolicy(root) {
/** Retain the local primary branch outside replicated board data and read-only diagnostics [B34,V6]. */
export function trunkRef(root, branch) {
+ // A trunk already recorded as this branch needs no Git process to confirm and nothing written.
+ if (branch !== undefined && localConfigIs(root, 'pullboard', 'trunk', branch)) return branch;
const read = gitConfig(root, 'pullboard.trunk', { local: true, clean: true, flags: false, noReplace: true });
if (read.status !== 0 && read.status !== 1) throw new Refused('NO_POLICY', 'the retained trunk cannot be read; restore the local Git configuration and retry');
const current = read.status === 0 ? read.stdout.trim() : null;