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
feat(registry): track project and repo labels [N33,N35,N36]
Corey Olsonc0fee25d1b67
diff --git a/src/config.js b/src/config.jsindex c5057f04..b3fa89e9 100644--- a/src/config.js+++ b/src/config.js@@ -128,6 +128,15 @@ function laneProblems(name, lane) {*/export function configProblems(config) {const problems = [];+ for (const field of ['project', 'name']) {+ if (config[field] === undefined) continue;+ const value = config[field];+ if (typeof value !== 'string' || !value.trim() || value.trim() !== value || /[\u0000-\u001f\u007f-\u009f]/u.test(value)) {+ problems.push(`"${field}" is a trimmed, nonempty string without control characters`);+ } else if (field === 'name' && /[#,]/u.test(value)) {+ problems.push('"name" cannot contain "#" or ","');+ }+ }if (typeof config.spec !== 'string' || !config.spec) problems.push('"spec" names a file');if (typeof config.practice !== 'string' || !config.practice) problems.push('"practice" names a file');if (typeof config.gate !== 'string') problems.push('"gate" is a shell command, like "npm test"');diff --git a/src/projects.js b/src/projects.jsindex 3c4eb7ee..2dcdfb8f 100644--- a/src/projects.js+++ b/src/projects.js@@ -1,11 +1,11 @@/**- * The projects on this machine (I8): every repo `pullboard init` set up, so `pullboard view` can show- * them all on one page. A plain JSON file in the person's home, or wherever PULLBOARD_HOME points,- * which is how tests and the tour keep their throwaway repos out of it.+ * 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 { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';+import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';import { homedir } from 'node:os';-import { basename, join } from 'node:path';+import { basename, join, resolve } from 'node:path';+import { loadConfig } from './config.js';/*** The registry file.@@ -17,34 +17,160 @@ export function registryFile() {}/**- * Every registered project, oldest first. An unreadable registry reads as empty.+ * Read the registry, treating unreadable or malformed content as empty without authorizing a rewrite.*- * @returns {{ root: string, name: string, added: string }[]}+ * @returns {{ projects: any[], readable: boolean }}*/-export function listProjects() {+function readRegistry() {const file = registryFile();- if (!existsSync(file)) return [];+ if (!existsSync(file)) return { projects: [], readable: true };try {const projects = JSON.parse(readFileSync(file, 'utf8')).projects;- return Array.isArray(projects) ? projects.filter((project) => typeof project?.root === 'string') : [];+ return Array.isArray(projects)+ ? { projects: projects.filter((project) => typeof project?.root === 'string'), readable: true }+ : { projects: [], readable: false };} catch {- return [];+ return { projects: [], readable: false };}}/**- * Add a project's main checkout to the registry, once.+ * Whether a path currently names a directory.+ *+ * @param {string} path+ * @returns {boolean}+ */+function isDirectory(path) {+ try {+ return statSync(path).isDirectory();+ } catch {+ return false;+ }+}++/**+ * Metadata from a validated config, or null when the config cannot be trusted.** @param {string} root- * @param {Date} [now]- * @returns {boolean} Whether it was new.+ * @param {object} [provided]+ * @returns {{ name: string, project: string } | null}*/-export function registerProject(root, now = new Date()) {- const projects = listProjects();- if (projects.some((project) => project.root === root)) return false;+function configMetadata(root, provided = {}) {+ let current;+ try {+ current = loadConfig(root);+ } catch {+ current = null;+ }+ const hasProvidedMetadata = provided && typeof provided === 'object'+ && (provided.name !== undefined || provided.project !== undefined);+ if (!current && !hasProvidedMetadata) return null;+ const candidate = { ...(current ?? {}) };+ if (provided && typeof provided === 'object') {+ if (provided.name !== undefined) candidate.name = provided.name;+ if (provided.project !== undefined) candidate.project = provided.project;+ }+ /**+ * Whether optional metadata is trimmed, nonempty text with no control characters.+ *+ * @param {unknown} value+ * @returns {boolean}+ */+ const validText = (value) => typeof value === 'string' && value.length > 0 && value.trim() === value && !/[\u0000-\u001f\u007f-\u009f]/u.test(value);+ if (candidate.name !== undefined && (!validText(candidate.name) || /[#,]/u.test(candidate.name))) return null;+ if (candidate.project !== undefined && !validText(candidate.project)) return null;+ return { name: candidate.name ?? basename(root), project: candidate.project ?? '' };+}++/**+ * Persist a registry only after a caller has determined that its contents changed.+ *+ * @param {any[]} projects+ * @returns {void}+ */+function writeRegistry(projects) {const file = registryFile();mkdirSync(join(file, '..'), { recursive: true });- projects.push({ root, name: basename(root), added: now.toISOString() });writeFileSync(file, `${JSON.stringify({ projects }, null, 2)}\n`);+}++/**+ * Every registered project, oldest first. Refreshes valid live metadata and prunes missing roots.+ *+ * @returns {{ root: string, name: string, project: string, added: string }[]}+ */+export function listProjects() {+ const state = readRegistry();+ if (!state.readable) return [];+ let changed = false;+ const projects = [];+ for (const stored of state.projects) {+ const root = resolve(stored.root);+ if (!isDirectory(root)) {+ changed = true;+ continue;+ }+ const metadata = configMetadata(root);+ const project = {+ ...stored,+ root,+ name: stored.name ?? basename(root),+ project: stored.project ?? '',+ };+ if (metadata) {+ project.name = metadata.name;+ project.project = metadata.project;+ }+ if (project.root !== stored.root || project.name !== stored.name || project.project !== stored.project) changed = true;+ projects.push(project);+ }+ if (changed) writeRegistry(projects);+ return projects;+}++/**+ * Add a project's main checkout once, preserving its original added timestamp on later registrations.+ *+ * @param {string} root+ * @param {Date} [now]+ * @param {object} [config]+ * @returns {boolean} Whether it was new.+ */+export function registerProject(root, now = new Date(), config = {}) {+ const normalizedRoot = resolve(root);+ const state = readRegistry();+ if (!state.readable) return false;+ const projects = state.projects.map((entry) => ({ ...entry, root: resolve(entry.root) }));+ const metadata = configMetadata(normalizedRoot, config);+ const existing = projects.find((project) => project.root === normalizedRoot);+ if (existing) {+ if (metadata) {+ const changed = existing.name !== metadata.name || existing.project !== metadata.project;+ if (changed) {+ Object.assign(existing, metadata);+ writeRegistry(projects);+ }+ }+ return false;+ }+ const initialMetadata = metadata ?? { name: basename(normalizedRoot), project: '' };+ projects.push({ root: normalizedRoot, ...initialMetadata, added: now.toISOString() });+ writeRegistry(projects);+ return true;+}++/**+ * Remove exactly the registered project at a normalized absolute path.+ *+ * @param {string} path+ * @returns {boolean} Whether one registered project was removed.+ */+export function forgetProject(path) {+ const normalized = resolve(path);+ const state = readRegistry();+ if (!state.readable) return false;+ const projects = state.projects.filter((project) => resolve(project.root) !== normalized);+ if (projects.length === state.projects.length) return false;+ writeRegistry(projects);return true;}diff --git a/test/registry.test.js b/test/registry.test.jsnew file mode 100644index 00000000..f61134dd--- /dev/null+++ b/test/registry.test.js@@ -0,0 +1,72 @@+/** Registry metadata, refresh, pruning and forgetting (N33, N35, N36). */+import assert from 'node:assert/strict';+import { execFileSync } from 'node:child_process';+import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { basename, join, resolve } from 'node:path';+import { test } from 'node:test';+import { configProblems, defaults, loadConfig } from '../src/config.js';+import { forgetProject, listProjects, registerProject, registryFile } from '../src/projects.js';++/**+ * Create an initialized temporary Git repository with a private Pullboard home.+ *+ * @param {string} parent+ * @param {string} name+ * @returns {string}+ */+function makeRepo(parent, name) {+ const root = join(parent, name);+ mkdirSync(root, { recursive: true });+ execFileSync('git', ['init', '--quiet', root]);+ return root;+}++test('registry uses validated repo labels, refreshes metadata, prunes missing roots and forgets one path [N33, N35, N36]', () => {+ const sandbox = mkdtempSync(join(tmpdir(), 'pullboard-registry-'));+ const home = join(sandbox, 'private-home');+ const priorHome = process.env.PULLBOARD_HOME;+ process.env.PULLBOARD_HOME = home;+ try {+ const first = makeRepo(sandbox, 'first-repo');+ const second = makeRepo(sandbox, 'second-repo');+ writeFileSync(join(first, 'pullboard.json'), JSON.stringify({ name: 'Core API', project: 'Atlas', gate: '' }));+ assert.equal(loadConfig(first).name, 'Core API');+ assert.equal(registerProject(first, new Date('2026-01-02T03:04:05.000Z'), loadConfig(first)), true);+ assert.equal(registerProject(second, new Date('2026-01-03T03:04:05.000Z')), true);++ let projects = listProjects();+ assert.deepEqual(projects.map(({ name, project }) => ({ name, project })), [+ { name: 'Core API', project: 'Atlas' },+ { name: basename(second), project: '' },+ ]);+ const firstAdded = projects[0].added;++ writeFileSync(join(first, 'pullboard.json'), JSON.stringify({ name: 'Core API v2', project: 'Atlas One', gate: '' }));+ projects = listProjects();+ assert.equal(projects[0].name, 'Core API v2');+ assert.equal(projects[0].project, 'Atlas One');+ assert.equal(projects[0].added, firstAdded);+ const unchangedRegistry = readFileSync(registryFile(), 'utf8');+ assert.deepEqual(listProjects(), projects);+ assert.equal(readFileSync(registryFile(), 'utf8'), unchangedRegistry, 'unchanged metadata is not rewritten');++ writeFileSync(join(first, 'pullboard.json'), JSON.stringify({ name: ' invalid ', project: 'Atlas', gate: '' }));+ assert.throws(() => loadConfig(first), /"name"/);+ assert.equal(listProjects()[0].name, 'Core API v2', 'invalid current config cannot erase stored metadata');+ assert.equal(registerProject(first), false);+ assert.equal(listProjects()[0].name, 'Core API v2', 'registration with invalid config preserves stored metadata');+ assert.ok(configProblems({ ...defaults(), name: 'bad,name', project: '' }).some((problem) => problem.includes('"name"')));+ assert.ok(configProblems({ ...defaults(), name: 'valid', project: 'bad\u0001value' }).some((problem) => problem.includes('"project"')));++ rmSync(second, { recursive: true, force: true });+ assert.deepEqual(listProjects().map((project) => project.root), [first]);+ assert.equal(forgetProject(resolve(first, '..', basename(first))), true);+ assert.equal(forgetProject(first), false);+ assert.deepEqual(listProjects(), []);+ } finally {+ if (priorHome === undefined) delete process.env.PULLBOARD_HOME;+ else process.env.PULLBOARD_HOME = priorHome;+ rmSync(sandbox, { recursive: true, force: true });+ }+});