@rness/cli 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/version.ts","../src/core/fs.ts","../src/core/workspace.ts","../src/core/manifest.ts","../src/core/scope.ts","../src/core/frontmatter.ts","../src/core/collect.ts","../src/core/context.ts","../src/report.ts","../src/commands/context.ts","../src/core/contract.ts","../src/core/block.ts","../src/core/merge.ts","../src/core/blocks.ts","../src/commands/validate.ts","../src/commands/sync.ts","../src/core/git.ts","../src/cli.ts"],"sourcesContent":["// Single source of the package version. test/version.test.ts keeps it equal\n// to package.json; bump both together.\nexport const VERSION = '0.3.0'\n","import { access, lstat, readFile, rename, rm, writeFile } from 'node:fs/promises'\nimport { basename, dirname, join } from 'node:path'\n\nexport async function exists(p: string): Promise<boolean> {\n try {\n await access(p)\n return true\n } catch {\n return false\n }\n}\n\n/**\n * True when `p` is itself a symbolic link (the link is not followed). False\n * when it does not exist. Callers use it to leave a `CLAUDE.md → AGENTS.md`\n * link alone: reading follows the link and the atomic rename would replace it.\n */\nexport async function isSymlink(p: string): Promise<boolean> {\n try {\n return (await lstat(p)).isSymbolicLink()\n } catch (e) {\n if ((e as NodeJS.ErrnoException).code === 'ENOENT') return false\n throw e\n }\n}\n\n/** File content, or null when the file does not exist; any other error propagates. */\nexport async function readOrNull(p: string): Promise<string | null> {\n try {\n return await readFile(p, 'utf8')\n } catch (e) {\n if ((e as NodeJS.ErrnoException).code === 'ENOENT') return null\n throw e\n }\n}\n\nlet sequence = 0\n\n/** Write to a temporary file in the same directory, then rename over the target. */\nexport async function writeFileAtomic(p: string, text: string): Promise<void> {\n sequence += 1\n const tmp = join(dirname(p), `.${basename(p)}.${process.pid}.${sequence}.tmp`)\n await writeFile(tmp, text, 'utf8')\n try {\n await rename(tmp, p)\n } catch (e) {\n await rm(tmp, { force: true }).catch(() => undefined)\n throw e\n }\n}\n","import { dirname, join, parse, resolve } from 'node:path'\nimport { exists } from './fs.ts'\nimport type { Workspace } from './types.ts'\n\n/** Walk up from `startDir`: a directory holding `.rness/rness.json` is the root. Only when none exists anywhere above does a directory that itself holds `rness.json` count — a standalone checkout of the context repository (CI): that directory is `.rness/`, its parent the root. */\nexport async function findWorkspace(startDir: string): Promise<Workspace> {\n const start = resolve(startDir)\n const { root: fsRoot } = parse(start)\n const ancestors: string[] = []\n for (let dir = start; ; dir = dirname(dir)) {\n ancestors.push(dir)\n if (dir === fsRoot) break\n }\n for (const dir of ancestors) {\n if (await exists(join(dir, '.rness', 'rness.json'))) return { root: dir, rnessDir: join(dir, '.rness') }\n }\n for (const dir of ancestors) {\n if (await exists(join(dir, 'rness.json'))) return { root: dirname(dir), rnessDir: dir }\n }\n throw new Error(`no rness workspace found above ${startDir}`)\n}\n","import { readFile } from 'node:fs/promises'\nimport { basename, join } from 'node:path'\nimport type { Manifest, RepoEntry, ScopeEntry } from './types.ts'\n\nexport const NAME = /^[a-z0-9][a-z0-9-]*$/\n\nfunction fail(message: string): never {\n throw new Error(`rness.json: ${message}`)\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === 'object' && !Array.isArray(value)\n}\n\nfunction checkPath(scope: string, path: unknown): string {\n if (typeof path !== 'string' || path === '') fail(`scope \"${scope}\" needs a string \"path\"`)\n if (path.startsWith('/')) fail(`scope \"${scope}\" path must be relative`)\n if (path.split('/').includes('..')) fail(`scope \"${scope}\" path must not contain \"..\"`)\n if (path.split('/').some((segment) => segment === '')) fail(`scope \"${scope}\" path must not contain empty segments`)\n return path\n}\n\nfunction readOrg(value: unknown): string | null {\n if (value === undefined || value === null) return null\n if (typeof value !== 'string' || !NAME.test(value)) {\n fail(`\"org\" must be a name matching [a-z0-9-] (got ${JSON.stringify(value)})`)\n }\n return value\n}\n\n/** The organisation name every block and `add` use: `org`, else the root directory's name. */\nexport function resolveOrg(manifest: Manifest, root: string): { org: string; warning: string | null } {\n if (manifest.org !== null) return { org: manifest.org, warning: null }\n const name = basename(root)\n return { org: name, warning: `rness.json: no \"org\"; using the directory name \"${name}\"` }\n}\n\nfunction readRepos(value: unknown): Record<string, RepoEntry> {\n const raw = value ?? {}\n if (!isRecord(raw)) fail('\"repos\" must be an object')\n const repos: Record<string, RepoEntry> = {}\n for (const [name, entry] of Object.entries(raw)) {\n if (!NAME.test(name)) fail(`repo name \"${name}\" is not [a-z0-9-]`)\n if (!isRecord(entry) || typeof entry.url !== 'string') fail(`repo \"${name}\" needs a string \"url\"`)\n repos[name] = { url: entry.url }\n }\n return repos\n}\n\nfunction readScopes(value: unknown): Record<string, ScopeEntry> {\n const raw = value ?? {}\n if (!isRecord(raw)) fail('\"scopes\" must be an object')\n const scopes: Record<string, ScopeEntry> = {}\n for (const [name, entry] of Object.entries(raw)) {\n if (!NAME.test(name)) fail(`scope name \"${name}\" is not [a-z0-9-]`)\n if (!isRecord(entry)) fail(`scope \"${name}\" must be an object`)\n const path = checkPath(name, entry.path)\n const ext = entry.extends ?? []\n if (!Array.isArray(ext) || !ext.every((t) => typeof t === 'string')) {\n fail(`scope \"${name}\" extends must be an array of scope names`)\n }\n scopes[name] = { path, extends: ext as string[] }\n }\n for (const [name, entry] of Object.entries(scopes)) {\n for (const target of entry.extends) {\n if (!Object.hasOwn(scopes, target)) fail(`scope \"${name}\" extends unknown scope \"${target}\"`)\n }\n }\n return scopes\n}\n\n/** Read and validate `<rnessDir>/rness.json`. Every error starts with `rness.json:`. */\nexport async function loadManifest(rnessDir: string): Promise<Manifest> {\n let raw: string\n try {\n raw = await readFile(join(rnessDir, 'rness.json'), 'utf8')\n } catch {\n fail('not found')\n }\n let data: unknown\n try {\n data = JSON.parse(raw)\n } catch (e) {\n fail(`invalid JSON (${e instanceof Error ? e.message : String(e)})`)\n }\n if (!isRecord(data)) fail('must be a JSON object')\n if (data.contract !== 1) fail(`unsupported contract: ${JSON.stringify(data.contract)} (expected 1)`)\n return { contract: 1, org: readOrg(data.org), repos: readRepos(data.repos), scopes: readScopes(data.scopes) }\n}\n","import type { Manifest } from './types.ts'\n\nfunction isPrefix(prefix: string, target: string): boolean {\n return prefix === target || target.startsWith(`${prefix}/`)\n}\n\n/** The scope whose `path` is the longest path-segment prefix of `relDir`; null = global. */\nexport function resolveScope(manifest: Manifest, relDir: string): string | null {\n let best: string | null = null\n let bestLen = -1\n for (const [name, entry] of Object.entries(manifest.scopes)) {\n if (isPrefix(entry.path, relDir) && entry.path.length > bestLen) {\n best = name\n bestLen = entry.path.length\n }\n }\n return best\n}\n\n/** `scope` then its transitive `extends`, nearest first, de-duplicated. Throws on a cycle. */\nexport function scopeChain(manifest: Manifest, scope: string | null): string[] {\n if (scope === null) return []\n const chain: string[] = []\n const seen = new Set<string>()\n const visit = (name: string, stack: Set<string>): void => {\n if (stack.has(name)) throw new Error(`extends cycle at scope \"${name}\"`)\n if (seen.has(name)) return\n seen.add(name)\n chain.push(name)\n stack.add(name)\n const entry = Object.hasOwn(manifest.scopes, name) ? manifest.scopes[name] : undefined\n for (const target of entry?.extends ?? []) visit(target, stack)\n stack.delete(name)\n }\n visit(scope, new Set())\n return chain\n}\n","import { parse } from 'yaml'\nimport type { Fields } from './types.ts'\n\n// The inner group is optional so that `---\\n---\\n` (an empty block with no line\n// between the fences) is still recognised as front matter.\nconst FRONT_MATTER = /^---\\r?\\n(?:([\\s\\S]*?)\\r?\\n)?---(?:\\r?\\n|$)/\n\nfunction fail(message: string): never {\n throw new Error(`front matter: ${message}`)\n}\n\n/** Strip a leading UTF-8 BOM so `---` is still recognised as the first thing in the file. */\nfunction stripBom(source: string): string {\n return source.startsWith('') ? source.slice(1) : source\n}\n\n/**\n * Parse the leading `---` block as YAML (1.2 core schema: `2026-09-07` stays a\n * string, `1` becomes a number). Returns null when there is no block, `{}`\n * for an empty block, and throws a `front matter:`-prefixed error when the\n * YAML is invalid or is not a mapping.\n */\nexport function parseFrontMatter(source: string): Fields | null {\n const match = stripBom(source).match(FRONT_MATTER)\n if (match === null) return null\n const block = match[1] ?? ''\n if (block.trim() === '') return {}\n let doc: unknown\n try {\n // 'error': suppress the printed YAMLWarning (e.g. an unresolved `!!tag`)\n // without silencing real parse errors — `logLevel: 'silent'` would do that too.\n doc = parse(block, { logLevel: 'error' })\n } catch (e) {\n fail(e instanceof Error ? (e.message.split('\\n')[0] ?? 'invalid YAML').replace(/:$/, '') : 'invalid YAML')\n }\n if (doc === null || doc === undefined) return {}\n if (typeof doc !== 'object' || Array.isArray(doc)) fail('block must be a mapping of keys to values')\n return doc as Fields\n}\n\n/**\n * The document text with its leading `---` block removed, along with the blank\n * lines that separated it from the body. Purely textual: a block whose YAML is\n * invalid is still stripped, so a broken file never leaks `---` fences into a\n * rendered block. Returns the (BOM-stripped) source unchanged when there is no\n * front matter.\n */\nexport function stripFrontMatter(source: string): string {\n const text = stripBom(source)\n const match = text.match(FRONT_MATTER)\n if (match === null) return text\n return text.slice(match[0].length).replace(/^(?:[ \\t]*\\r?\\n)+/, '')\n}\n\nexport function extractTitle(source: string): string | null {\n return stripBom(source).match(/^# (.+)$/m)?.[1]?.trim() ?? null\n}\n","import { glob, readFile } from 'node:fs/promises'\nimport { join, posix, sep } from 'node:path'\nimport { parseFrontMatter, extractTitle, stripFrontMatter } from './frontmatter.ts'\nimport type { MarkdownItem } from './types.ts'\n\nfunction toPosix(rel: string): string {\n return rel.split(sep).join(posix.sep)\n}\n\n/**\n * Every `*.md` under `dir`, recursively, sorted by `rel`. A missing directory\n * yields []. A file whose front matter fails to parse is kept with\n * `fields: null` and the error in `fieldsError`, so one broken file cannot\n * hide a whole collection.\n */\nexport async function collectMarkdown(dir: string): Promise<MarkdownItem[]> {\n const rels: string[] = []\n for await (const rel of glob('**/*.md', { cwd: dir })) rels.push(toPosix(rel))\n const items = await Promise.all(\n rels.map(async (rel): Promise<MarkdownItem> => {\n const path = join(dir, ...rel.split(posix.sep))\n const body = await readFile(path, 'utf8')\n let fields: MarkdownItem['fields'] = null\n let fieldsError: string | null = null\n try {\n fields = parseFrontMatter(body)\n } catch (e) {\n fieldsError = e instanceof Error ? e.message : String(e)\n }\n return { path, rel, fields, fieldsError, title: extractTitle(body), body, content: stripFrontMatter(body) }\n }),\n )\n return items.sort((a, b) => (a.rel < b.rel ? -1 : a.rel > b.rel ? 1 : 0))\n}\n","import { join } from 'node:path'\nimport { collectMarkdown } from './collect.ts'\nimport { scopeChain } from './scope.ts'\nimport type { CollectionName, Context, ContextCollection, ContextFile, Manifest, MarkdownItem } from './types.ts'\n\nexport const COLLECTIONS: readonly CollectionName[] = ['standards', 'adr', 'specs', 'plans', 'skills']\n\n/** The first path segment of `rel`, or null for a file at the collection root. */\nexport function ownerScope(rel: string): string | null {\n const slash = rel.indexOf('/')\n return slash === -1 ? null : rel.slice(0, slash)\n}\n\ntype Owned = MarkdownItem & { scope: string | null }\n\n/**\n * The file's place defines its scope (spec 0003 §4.0): collection-root files\n * are global, `<scope>/**` files belong to that scope. A file under a\n * directory outside the chain is ignored; front matter never re-routes.\n */\nasync function assembleCollection(dir: string, name: CollectionName, chain: string[]): Promise<ContextCollection> {\n const items = await collectMarkdown(dir)\n const groups = new Map<string, Owned[]>(chain.map((s) => [s, []]))\n const rootFiles: Owned[] = []\n for (const item of items) {\n const owner = ownerScope(item.rel)\n if (owner === null) rootFiles.push({ ...item, scope: null })\n else groups.get(owner)?.push({ ...item, scope: owner })\n }\n const files: ContextFile[] = []\n const push = (f: Owned): void => {\n files.push({ rel: f.rel, scope: f.scope, title: f.title, body: f.body, content: f.content })\n }\n for (const s of chain) for (const f of groups.get(s) ?? []) push(f)\n for (const f of rootFiles) push(f)\n return { name, files }\n}\n\nexport interface AssembleInput {\n rnessDir: string\n manifest: Manifest\n scope: string | null\n}\n\n/** Resolve every scoped collection for `scope` (null = global only). */\nexport async function assembleContext({ rnessDir, manifest, scope }: AssembleInput): Promise<Context> {\n const chain = scopeChain(manifest, scope)\n const collections = await Promise.all(\n COLLECTIONS.map((name) => assembleCollection(join(rnessDir, name), name, chain)),\n )\n return { scope, collections }\n}\n","/**\n * Shared CLI error contract: one line on stderr, and — only under\n * `RNESS_DEBUG=1` — the stack trace instead of the plain message (the stack\n * already starts with `Error: <message>`, so printing both would repeat it).\n */\nexport function reportError(e: unknown): number {\n const debug = process.env['RNESS_DEBUG'] === '1'\n if (debug && e instanceof Error && e.stack) {\n process.stderr.write(`${e.stack}\\n`)\n } else {\n const message = e instanceof Error ? e.message : String(e)\n process.stderr.write(`${message}\\n`)\n }\n return 1\n}\n","import { posix, relative, sep } from 'node:path'\nimport { findWorkspace } from '../core/workspace.ts'\nimport { loadManifest } from '../core/manifest.ts'\nimport { resolveScope } from '../core/scope.ts'\nimport { assembleContext } from '../core/context.ts'\nimport type { Context } from '../core/types.ts'\nimport { reportError } from '../report.ts'\n\nexport interface ContextOptions {\n /** Scope to resolve; default: the scope owning `cwd`. */\n scope?: string\n /** Print the resolved context as JSON instead of Markdown. */\n json?: boolean\n /** Internal (tests): directory to resolve from; default `process.cwd()`. */\n cwd?: string\n}\n\nexport function renderMarkdown(ctx: Context): string {\n const parts: string[] = []\n for (const collection of ctx.collections) {\n if (collection.files.length === 0) continue\n parts.push(`## ${collection.name}\\n`)\n for (const file of collection.files) {\n parts.push(`<!-- rness: ${collection.name}/${file.rel} -->\\n${file.content.trim()}\\n`)\n }\n }\n return `${parts.join('\\n')}\\n`\n}\n\n/** `rness context`: resolve and print the context for a scope. Returns the exit code. */\nexport async function contextCommand(opts: ContextOptions): Promise<number> {\n const cwd = opts.cwd ?? process.cwd()\n try {\n const ws = await findWorkspace(cwd)\n const manifest = await loadManifest(ws.rnessDir)\n\n let scope: string | null\n if (opts.scope !== undefined) {\n if (!Object.hasOwn(manifest.scopes, opts.scope)) {\n process.stderr.write(`unknown scope: ${opts.scope}\\n`)\n return 1\n }\n scope = opts.scope\n } else {\n const rel = relative(ws.root, cwd).split(sep).join(posix.sep)\n scope = resolveScope(manifest, rel)\n }\n\n const ctx = await assembleContext({ rnessDir: ws.rnessDir, manifest, scope })\n process.stdout.write(opts.json ? `${JSON.stringify(ctx, null, 2)}\\n` : renderMarkdown(ctx))\n return 0\n } catch (e) {\n return reportError(e)\n }\n}\n","import { join } from 'node:path'\nimport { collectMarkdown } from './collect.ts'\nimport { COLLECTIONS } from './context.ts'\nimport type { CollectionName } from './types.ts'\n\n/** Collections whose files must carry front matter with a `status`. */\nexport const STATUSES: Partial<Record<CollectionName, readonly string[]>> = {\n adr: ['Proposed', 'Accepted', 'Rejected', 'Superseded'],\n specs: ['Draft', 'Proposed', 'Approved', 'Implemented', 'Superseded', 'Rejected'],\n plans: ['Draft', 'Ready', 'In progress', 'Blocked', 'Completed', 'Abandoned'],\n}\nconst SKIP = new Set(['adr/0000-template.md'])\n/** Front-matter keys from the withdrawn routing feature — the directory decides. */\nconst PLACEMENT_KEYS = ['scopes', 'scope'] as const\n\n/** Human-readable problems across every collection; empty when the tree is valid. */\nexport async function checkContract(rnessDir: string): Promise<string[]> {\n const problems: string[] = []\n for (const name of COLLECTIONS) {\n const allowed = STATUSES[name]\n const items = await collectMarkdown(join(rnessDir, name))\n for (const item of items) {\n const where = `${name}/${item.rel}`\n if (SKIP.has(where)) continue\n if (item.fieldsError !== null) {\n problems.push(`${where}: invalid front matter (${item.fieldsError})`)\n continue\n }\n if (item.fields !== null) {\n for (const key of PLACEMENT_KEYS) {\n if (Object.hasOwn(item.fields, key)) {\n problems.push(`${where}: front matter \"${key}\" is not supported — the directory decides the scope; move the file`)\n }\n }\n }\n if (allowed === undefined) continue\n if (item.fields === null) {\n problems.push(`${where}: missing a front-matter block`)\n continue\n }\n if (item.title === null) problems.push(`${where}: missing a \"# \" title`)\n const status = item.fields['status']\n if (status === undefined || status === null || status === '') {\n problems.push(`${where}: missing \"status\"`)\n } else if (typeof status !== 'string' || !allowed.includes(status)) {\n problems.push(`${where}: unknown status ${JSON.stringify(status)} (expected ${allowed.join(', ')})`)\n }\n }\n }\n return problems\n}\n","import { createHash } from 'node:crypto'\nimport type { Context } from './types.ts'\n\nexport const BEGIN = '<!-- BEGIN rness -->'\nexport const END = '<!-- END rness -->'\n/** Blocks above this size are written with a warning (spec 0003 §4.2). */\nexport const BLOCK_SIZE_WARNING = 32 * 1024\n\nexport interface BlockInput {\n /** Scope name, or null for the workspace-root global block. */\n scope: string | null\n org: string\n /** Path segments between the scope directory and the workspace root (`org/web` → 2; root → 0). */\n depth: number\n context: Context\n version: string\n}\n\nexport interface RenderedBlock {\n /** The whole block, LF line endings, no trailing newline. */\n text: string\n hash: string\n bytes: number\n}\n\nexport interface BlockHeader {\n version: string\n scope: string\n hash: string\n}\n\nconst HEADER = /^<!-- rness (\\S+) · scope: (\\S+) · contract: 1 · hash: ([0-9a-f]{12}) · generated: run `rness sync`, never edit inside this block -->$/\n\nfunction toLf(s: string): string {\n return s.replace(/\\r\\n?/g, '\\n')\n}\n\n/** SHA-256 of the LF-normalised body, first 12 hex characters. */\nexport function blockHash(body: string): string {\n return createHash('sha256').update(toLf(body), 'utf8').digest('hex').slice(0, 12)\n}\n\nfunction intro(scope: string | null, org: string, depth: number): string {\n if (scope === null) {\n return [\n `This is the root of rness workspace \\`${org}\\`. Full context lives in \\`.rness/\\` —`,\n 'read `STATUS.md`, then task-relevant `adr/`, `specs/`, `plans/`; live: `rness context`.',\n 'Every `org/<repo>/` carries its own block with the rules that apply there.',\n ].join('\\n')\n }\n const rel = `${'../'.repeat(depth)}.rness/`\n return [\n `This directory is scope \\`${scope}\\` of rness workspace \\`${org}\\`. Full context lives in`,\n `\\`${rel}\\` — read \\`STATUS.md\\`, then task-relevant \\`adr/\\`, \\`specs/\\`, \\`plans/\\`;`,\n `live: \\`rness context --scope ${scope}\\`. If \\`.rness/\\` is not reachable, this is a`,\n 'standalone clone: the rules below are all you have.',\n ].join('\\n')\n}\n\nfunction header(version: string, scope: string | null, hash: string): string {\n return `<!-- rness ${version} · scope: ${scope ?? 'global'} · contract: 1 · hash: ${hash} · generated: run \\`rness sync\\`, never edit inside this block -->`\n}\n\n/** Render the block for one scope (or the root) from an already resolved context. */\nexport function renderBlock({ scope, org, depth, context, version }: BlockInput): RenderedBlock {\n const standards = context.collections.find((c) => c.name === 'standards')?.files ?? []\n const rules =\n standards.length === 0\n ? ['_No standards apply to this scope yet._']\n : standards.map((f) => `<!-- rness: standards/${f.rel} -->\\n${toLf(f.content).trim()}`)\n const body = `${intro(scope, org, depth)}\\n\\n## Rules\\n${rules.join('\\n\\n')}`\n const hash = blockHash(body)\n const text = [BEGIN, header(version, scope, hash), body, END].join('\\n')\n return { text, hash, bytes: Buffer.byteLength(text, 'utf8') }\n}\n\n/** Parse the header line of a block; null when the line is not a rness header. */\nexport function parseHeader(line: string): BlockHeader | null {\n const m = HEADER.exec(line.trimEnd())\n if (m === null) return null\n return { version: m[1] ?? '', scope: m[2] ?? '', hash: m[3] ?? '' }\n}\n\n/** The hashed body of a block given its lines (BEGIN, header, body…, END). */\nexport function bodyOf(blockLines: string[]): string {\n return blockLines.slice(2, -1).join('\\n')\n}\n","import { join } from 'node:path'\nimport { BEGIN, END } from './block.ts'\nimport { isSymlink, readOrNull, writeFileAtomic } from './fs.ts'\n\nexport type FindResult =\n | { kind: 'none' }\n | { kind: 'one'; begin: number; end: number }\n | { kind: 'error'; message: string }\n\n/** Locate the single rness span (line indexes, inclusive). Anything but 0 or 1 span is an error. */\nexport function findBlock(lines: string[]): FindResult {\n const begins: number[] = []\n const ends: number[] = []\n lines.forEach((line, i) => {\n const l = line.trimEnd()\n if (l === BEGIN) begins.push(i)\n if (l === END) ends.push(i)\n })\n if (begins.length === 0 && ends.length === 0) return { kind: 'none' }\n const begin = begins[0]\n const end = ends[0]\n if (begins.length !== 1 || ends.length !== 1 || begin === undefined || end === undefined) {\n return { kind: 'error', message: `expected exactly one ${BEGIN} … ${END} span, found ${begins.length} BEGIN and ${ends.length} END` }\n }\n if (end < begin) return { kind: 'error', message: `${END} comes before ${BEGIN}` }\n return { kind: 'one', begin, end }\n}\n\nexport type MergeResult = { ok: true; text: string; changed: boolean } | { ok: false; error: string }\n\n/**\n * Merge `block` (LF, no trailing newline) into `existing` (spec 0003 §4.3):\n * missing file → the block; one span → replaced in place; no span → after a\n * leading `# H1` + blank line, else at the top. Bytes outside the span are\n * preserved, including the file's line-ending style.\n */\nexport function mergeBlock(existing: string | null, block: string): MergeResult {\n if (existing === null) return { ok: true, text: `${block}\\n`, changed: true }\n const eol = existing.includes('\\r\\n') ? '\\r\\n' : '\\n'\n const lines = existing.split(/\\r?\\n/)\n const found = findBlock(lines)\n if (found.kind === 'error') return { ok: false, error: found.message }\n const rendered = block.split('\\n').join(eol)\n // Offsets of every line start in the original text, so the regions outside the\n // span are copied byte for byte — a file mixing LF and CRLF keeps every separator.\n const starts: number[] = [0]\n for (const m of existing.matchAll(/\\r?\\n/g)) starts.push((m.index ?? 0) + m[0].length)\n const lineStart = (i: number): number => starts[i] ?? existing.length\n let text: string\n if (found.kind === 'one') {\n const endLine = lines[found.end] ?? ''\n const afterEnd = lineStart(found.end) + endLine.length\n text = `${existing.slice(0, lineStart(found.begin))}${rendered}${existing.slice(afterEnd)}`\n } else if (lines.length >= 3 && (lines[0] ?? '').startsWith('# ') && lines[1] === '') {\n const at = lineStart(2)\n text = `${existing.slice(0, at)}${rendered}${eol}${eol}${existing.slice(at)}`\n } else {\n text = `${rendered}${eol}${eol}${existing}`\n }\n return { ok: true, text, changed: text !== existing }\n}\n\n/**\n * `CLAUDE.md` next to an `AGENTS.md`: create with `@AGENTS.md`, or prepend that\n * line when absent. A symlinked `CLAUDE.md` is left exactly as it is — reading\n * would follow it and the atomic rename would replace the link with a regular\n * file holding a copy of its target. (`sync` skips such a directory outright;\n * this guard is defence in depth for any other caller.)\n */\nexport async function ensureClaudeMd(dir: string): Promise<'created' | 'prepended' | 'unchanged'> {\n const file = join(dir, 'CLAUDE.md')\n if (await isSymlink(file)) return 'unchanged'\n const existing = await readOrNull(file)\n if (existing === null) {\n await writeFileAtomic(file, '@AGENTS.md\\n')\n return 'created'\n }\n if (existing.split(/\\r?\\n/).some((l) => l.trim() === '@AGENTS.md')) return 'unchanged'\n const eol = existing.includes('\\r\\n') ? '\\r\\n' : '\\n'\n await writeFileAtomic(file, `@AGENTS.md${eol}${existing}`)\n return 'prepended'\n}\n","import { join } from 'node:path'\nimport { VERSION } from '../version.ts'\nimport { assembleContext } from './context.ts'\nimport { blockHash, bodyOf, parseHeader, renderBlock } from './block.ts'\nimport { findBlock } from './merge.ts'\nimport { exists, readOrNull } from './fs.ts'\nimport type { Manifest } from './types.ts'\n\nexport interface CheckBlocksInput {\n root: string\n rnessDir: string\n manifest: Manifest\n org: string\n}\n\nexport interface CheckBlocksResult {\n problems: string[]\n warnings: string[]\n}\n\n/**\n * Compare every present block with a fresh render (spec 0003 §4.6): a\n * different hash is a problem, a missing block only a warning, and nothing\n * is checked where no `org/` directory exists (a standalone context checkout).\n */\nexport async function checkBlocks({ root, rnessDir, manifest, org }: CheckBlocksInput): Promise<CheckBlocksResult> {\n const problems: string[] = []\n const warnings: string[] = []\n if (!(await exists(join(root, 'org')))) return { problems, warnings }\n\n const targets: Array<{ scope: string | null; dir: string; depth: number; label: string }> = [\n { scope: null, dir: root, depth: 0, label: 'AGENTS.md' },\n ]\n for (const [name, entry] of Object.entries(manifest.scopes)) {\n const segments = entry.path.split('/')\n targets.push({ scope: name, dir: join(root, ...segments), depth: segments.length, label: `${entry.path}/AGENTS.md` })\n }\n\n for (const t of targets) {\n if (!(await exists(t.dir))) {\n warnings.push(`${t.label}: directory not present, block not checked`)\n continue\n }\n const text = await readOrNull(join(t.dir, 'AGENTS.md'))\n const lines = text === null ? [] : text.split(/\\r?\\n/)\n const found = findBlock(lines)\n if (found.kind === 'none') {\n warnings.push(`${t.label}: no rness block yet (run rness sync)`)\n continue\n }\n if (found.kind === 'error') {\n problems.push(`${t.label}: ${found.message}`)\n continue\n }\n const header = parseHeader(lines[found.begin + 1] ?? '')\n const context = await assembleContext({ rnessDir, manifest, scope: t.scope })\n const fresh = renderBlock({ scope: t.scope, org, depth: t.depth, context, version: VERSION })\n // Two ways to be stale: the header no longer matches a fresh render, or the\n // body no longer matches its own header — a hand edit inside the block.\n const actual = blockHash(bodyOf(lines.slice(found.begin, found.end + 1)))\n if (header === null || header.hash !== fresh.hash || header.hash !== actual) {\n problems.push(`${t.label}: stale rness block (run rness sync)`)\n }\n }\n return { problems, warnings }\n}\n","import { findWorkspace } from '../core/workspace.ts'\nimport { loadManifest, resolveOrg } from '../core/manifest.ts'\nimport { scopeChain } from '../core/scope.ts'\nimport { checkContract } from '../core/contract.ts'\nimport { checkBlocks } from '../core/blocks.ts'\nimport { reportError } from '../report.ts'\n\nexport interface ValidateOptions {\n /** Internal (tests): directory to resolve from; default `process.cwd()`. */\n cwd?: string\n}\n\n/** `rness validate`: manifest, extends cycles, front-matter contract, stale blocks. Returns the exit code. */\nexport async function validateCommand(opts: ValidateOptions): Promise<number> {\n const cwd = opts.cwd ?? process.cwd()\n try {\n const ws = await findWorkspace(cwd)\n const manifest = await loadManifest(ws.rnessDir)\n // loadManifest only checks that extends targets exist; walk every scope so\n // an extends cycle is reported here rather than breaking `context` later.\n for (const s of Object.keys(manifest.scopes)) scopeChain(manifest, s)\n const { org, warning } = resolveOrg(manifest, ws.root)\n const warnings: string[] = warning === null ? [] : [warning]\n const problems = await checkContract(ws.rnessDir)\n const blocks = await checkBlocks({ root: ws.root, rnessDir: ws.rnessDir, manifest, org })\n problems.push(...blocks.problems)\n warnings.push(...blocks.warnings)\n for (const p of problems) process.stderr.write(`${p}\\n`)\n for (const w of warnings) process.stderr.write(`warning: ${w}\\n`)\n if (problems.length > 0) return 1\n process.stdout.write('context ok\\n')\n return 0\n } catch (e) {\n return reportError(e)\n }\n}\n","import { join } from 'node:path'\nimport { VERSION } from '../version.ts'\nimport { reportError } from '../report.ts'\nimport { findWorkspace } from '../core/workspace.ts'\nimport { loadManifest, resolveOrg } from '../core/manifest.ts'\nimport { assembleContext } from '../core/context.ts'\nimport { BLOCK_SIZE_WARNING, renderBlock } from '../core/block.ts'\nimport { ensureClaudeMd, mergeBlock } from '../core/merge.ts'\nimport { exists, isSymlink, readOrNull, writeFileAtomic } from '../core/fs.ts'\nimport { clone, isClean, pullFastForward } from '../core/git.ts'\nimport type { Manifest } from '../core/types.ts'\n\nexport interface SyncOptions {\n /** Only this scope's block (the root block is skipped). */\n scope?: string\n /** Render and compare; write nothing; exit 1 when any block differs. */\n check?: boolean\n /** `git pull --ff-only` in every clean clone. */\n pull?: boolean\n /** Skip the confirmation prompt. */\n yes?: boolean\n /** Internal (tests): directory to resolve from; default `process.cwd()`. */\n cwd?: string\n}\n\ninterface Target {\n scope: string | null\n dir: string\n depth: number\n label: string\n}\n\n// Excluded from the cleanliness check whatever their status: sync writes them itself. A\n// user's uncommitted edit to a tracked AGENTS.md is therefore not a veto — git pull\n// --ff-only still refuses to overwrite it and that surfaces as a problem.\nconst MANAGED_FILES = ['AGENTS.md', 'CLAUDE.md']\n\nfunction targetsOf(manifest: Manifest, root: string, only: string | undefined): Target[] {\n const targets: Target[] = []\n if (only === undefined) targets.push({ scope: null, dir: root, depth: 0, label: 'AGENTS.md' })\n for (const [name, entry] of Object.entries(manifest.scopes)) {\n if (only !== undefined && name !== only) continue\n const segments = entry.path.split('/')\n targets.push({ scope: name, dir: join(root, ...segments), depth: segments.length, label: `${entry.path}/AGENTS.md` })\n }\n return targets\n}\n\nasync function confirmOrExit(org: string): Promise<number | null> {\n if (!process.stdin.isTTY || !process.stdout.isTTY) {\n process.stderr.write('rness sync writes files; pass --yes to run without a prompt\\n')\n return 2\n }\n const { confirm, isCancel } = await import('@clack/prompts')\n const answer = await confirm({ message: `Sync workspace \\`${org}\\`: clone missing repositories and rewrite the rness blocks?` })\n if (isCancel(answer) || answer !== true) {\n process.stderr.write('cancelled\\n')\n return 1\n }\n return null\n}\n\n/** `rness sync`: clone missing repositories, write every block (spec 0003 §4). Returns the exit code. */\nexport async function syncCommand(opts: SyncOptions): Promise<number> {\n const cwd = opts.cwd ?? process.cwd()\n const check = opts.check === true\n try {\n const ws = await findWorkspace(cwd)\n const manifest = await loadManifest(ws.rnessDir)\n const { org, warning } = resolveOrg(manifest, ws.root)\n if (warning !== null) process.stderr.write(`warning: ${warning}\\n`)\n if (opts.scope !== undefined && !Object.hasOwn(manifest.scopes, opts.scope)) {\n process.stderr.write(`unknown scope: ${opts.scope}\\n`)\n return 1\n }\n if (!check && opts.yes !== true) {\n const refused = await confirmOrExit(org)\n if (refused !== null) return refused\n }\n\n const lines: string[] = []\n const problems: string[] = []\n\n try {\n // 1. Repositories: clone what is missing; pull only on request, only clean trees.\n for (const [name, repo] of Object.entries(manifest.repos)) {\n const dir = join(ws.root, 'org', name)\n const label = `org/${name}`\n if (!(await exists(dir))) {\n if (check) {\n lines.push(`missing ${label} (would clone ${repo.url})`)\n continue\n }\n try {\n await clone(repo.url, dir)\n lines.push(`cloned ${label}`)\n } catch (e) {\n problems.push(`${label}: ${e instanceof Error ? e.message : String(e)}`)\n }\n } else if (opts.pull === true && !check) {\n try {\n if (!(await isClean(dir, MANAGED_FILES))) {\n lines.push(`skipped ${label} (working tree not clean)`)\n continue\n }\n await pullFastForward(dir)\n lines.push(`pulled ${label}`)\n } catch (e) {\n problems.push(`${label}: ${e instanceof Error ? e.message : String(e)}`)\n }\n }\n }\n\n // 2. Blocks — only where repositories live; a standalone context checkout has no org/.\n if (!(await exists(join(ws.root, 'org')))) {\n lines.push('skipped blocks (no org/ directory here)')\n } else {\n let differences = 0\n for (const t of targetsOf(manifest, ws.root, opts.scope)) {\n if (!(await exists(t.dir))) {\n lines.push(`skipped ${t.label} (directory not present)`)\n continue\n }\n // One of the pair symlinked to the other (the common `CLAUDE.md →\n // AGENTS.md`) is left untouched: reading follows the link, and the\n // atomic rename would replace the link with a duplicate of its target.\n const linked = await Promise.all(MANAGED_FILES.map((f) => isSymlink(join(t.dir, f))))\n if (linked.includes(true)) {\n lines.push(`skipped ${t.label} (symlink)`)\n continue\n }\n const context = await assembleContext({ rnessDir: ws.rnessDir, manifest, scope: t.scope })\n const block = renderBlock({ scope: t.scope, org, depth: t.depth, context, version: VERSION })\n if (block.bytes > BLOCK_SIZE_WARNING) {\n process.stderr.write(`warning: ${t.label}: block is ${Math.round(block.bytes / 1024)} KB (over 32 KB)\\n`)\n }\n const file = join(t.dir, 'AGENTS.md')\n const merged = mergeBlock(await readOrNull(file), block.text)\n if (!merged.ok) {\n problems.push(`${t.label}: ${merged.error}`)\n continue\n }\n if (!merged.changed) {\n lines.push(`unchanged ${t.label}`)\n if (!check) await ensureClaudeMd(t.dir)\n continue\n }\n if (check) {\n lines.push(`stale ${t.label}`)\n differences += 1\n continue\n }\n await writeFileAtomic(file, merged.text)\n await ensureClaudeMd(t.dir)\n lines.push(`updated ${t.label}`)\n }\n if (check && differences > 0) problems.push(`${differences} block(s) out of date — run rness sync`)\n }\n\n return problems.length > 0 ? 1 : 0\n } finally {\n // Both flushes run even when something above throws, and stdout precedes\n // stderr so the report reads in order. The exit code above is computed\n // before this block, so it is unaffected.\n for (const l of lines) process.stdout.write(`${l}\\n`)\n for (const p of problems) process.stderr.write(`${p}\\n`)\n }\n } catch (e) {\n return reportError(e)\n }\n}\n","import { execFile } from 'node:child_process'\nimport { dirname, resolve } from 'node:path'\nimport { promisify } from 'node:util'\n\nconst execFileP = promisify(execFile)\n\nasync function git(args: readonly string[], cwd?: string): Promise<string> {\n try {\n const { stdout } = await execFileP('git', [...args], {\n ...(cwd === undefined ? {} : { cwd }),\n env: {\n ...process.env,\n GIT_TERMINAL_PROMPT: '0',\n // Pin the command to `cwd` itself: without a ceiling, git walks up and\n // a plain directory under `org/` would report — or be pulled into —\n // whatever repository happens to sit above the workspace root. git\n // ignores a relative ceiling entry, hence the resolve().\n ...(cwd === undefined ? {} : { GIT_CEILING_DIRECTORIES: dirname(resolve(cwd)) }),\n },\n maxBuffer: 16 * 1024 * 1024,\n })\n return stdout\n } catch (e) {\n const err = e as { stderr?: string; message?: string }\n const text = err.stderr !== undefined && err.stderr !== '' ? err.stderr : (err.message ?? 'unknown error')\n const first = text.split('\\n').find((l) => l.trim() !== '') ?? 'unknown error'\n throw new Error(`git ${args[0] ?? ''} failed: ${first.trim()}`)\n }\n}\n\n/** Reject a value git could parse as an option (e.g. a `rness.json` URL starting with `-`). */\nfunction positional(value: string, what: string): string {\n if (value.startsWith('-')) throw new Error(`refusing suspicious ${what}: ${value}`)\n return value\n}\n\n/** `git clone <url> <dir>`; `dir` must not exist. */\nexport async function clone(url: string, dir: string): Promise<void> {\n await git(['clone', '--quiet', '--', positional(url, 'repository url'), positional(dir, 'directory')])\n}\n\n/**\n * True when `git status --porcelain` prints nothing, ignoring the paths in\n * `ignore` (rness-managed files such as `AGENTS.md`/`CLAUDE.md` that sync\n * itself writes into every clone and that should never veto an auto-pull).\n */\nexport async function isClean(dir: string, ignore: readonly string[] = []): Promise<boolean> {\n const pathspec = ignore.map((p) => `:!${p}`)\n return (await git(['status', '--porcelain', ...(pathspec.length > 0 ? ['--', ...pathspec] : [])], dir)).trim() === ''\n}\n\nexport async function pullFastForward(dir: string): Promise<void> {\n await git(['pull', '--ff-only', '--quiet'], dir)\n}\n\n/** The `origin` URL, or null when `dir` is not a clone with an origin. */\nexport async function originUrl(dir: string): Promise<string | null> {\n try {\n return (await git(['remote', 'get-url', 'origin'], dir)).trim()\n } catch {\n return null\n }\n}\n","import { Command, CommanderError, Option } from 'commander'\nimport { VERSION } from './version.ts'\nimport { contextCommand, type ContextOptions } from './commands/context.ts'\nimport { validateCommand, type ValidateOptions } from './commands/validate.ts'\nimport { syncCommand, type SyncOptions } from './commands/sync.ts'\n\ninterface RunState {\n code: number\n}\n\nfunction buildProgram(state: RunState): Command {\n const program = new Command()\n .name('rness')\n .description('Configuration-plane CLI for rness workspaces')\n .version(VERSION, '-v, --version', 'print the version')\n .exitOverride()\n .showHelpAfterError()\n .configureOutput({\n writeOut: (s) => {\n process.stdout.write(s)\n },\n writeErr: (s) => {\n process.stderr.write(s)\n },\n })\n\n program\n .command('context')\n .description('Resolve and print the context for a scope')\n .option('--scope <name>', 'scope to resolve (default: the scope owning the current directory)')\n .option('--json', 'print JSON instead of Markdown')\n .addOption(new Option('--cwd <dir>').hideHelp())\n .action(async (opts: ContextOptions) => {\n state.code = await contextCommand(opts)\n })\n\n program\n .command('validate')\n .description('Check the .rness/ tree against the contract and every generated block')\n .addOption(new Option('--cwd <dir>').hideHelp())\n .action(async (opts: ValidateOptions) => {\n state.code = await validateCommand(opts)\n })\n\n program\n .command('sync')\n .description('Clone missing repositories and write the rness block into every AGENTS.md')\n .option('--scope <name>', 'only this scope (the root block is skipped)')\n .option('--check', 'render and compare only; exit 1 when a block is out of date')\n .option('--pull', 'git pull --ff-only in every clean clone')\n .option('-y, --yes', 'do not ask for confirmation')\n .addOption(new Option('--cwd <dir>').hideHelp())\n .action(async (opts: SyncOptions) => {\n state.code = await syncCommand(opts)\n })\n\n return program\n}\n\n/**\n * Parse user arguments and run the matching command. Returns the exit code\n * and never calls process.exit: 0 success, 1 handled error, 2 bad usage.\n */\nexport async function run(argv: string[]): Promise<number> {\n const state: RunState = { code: 0 }\n const program = buildProgram(state)\n if (argv.length === 0) {\n process.stdout.write(program.helpInformation())\n return 0\n }\n try {\n await program.parseAsync(argv, { from: 'user' })\n } catch (e) {\n if (e instanceof CommanderError) {\n // Commander 15 reuses `commander.help`'s code for both the successful\n // `--help` path and error paths (e.g. `help wat`, a lone `--`), so the\n // exit code it already computed is the only reliable signal here.\n return e.exitCode === 0 ? 0 : 2\n }\n throw e\n }\n return state.code\n}\n"],"mappings":";AAEO,IAAM,UAAU;;;ACFvB,SAAS,QAAQ,OAAO,UAAU,QAAQ,IAAI,iBAAiB;AAC/D,SAAS,UAAU,SAAS,YAAY;AAExC,eAAsB,OAAO,GAA6B;AACxD,MAAI;AACF,UAAM,OAAO,CAAC;AACd,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAOA,eAAsB,UAAU,GAA6B;AAC3D,MAAI;AACF,YAAQ,MAAM,MAAM,CAAC,GA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AAG;AACrB,YAAQ,OAAO,MAAM,QAAQ,gBAAgB,CAAC;AAC9C,WAAO;AAAA,EACT;AACA,MAAI;AACF,UAAM,QAAQ,WAAW,MAAM,EAAE,MAAM,OAAO,CAAC;AAAA,EACjD,SAAS,GAAG;AACV,QAAI,aAAa,gBAAgB;AAI/B,aAAO,EAAE,aAAa,IAAI,IAAI;AAAA,IAChC;AACA,UAAM;AAAA,EACR;AACA,SAAO,MAAM;AACf;","names":["dirname","join","dirname","join","readFile","basename","join","parse","fail","readFile","join","join","readFile","join","join","posix","sep","sep","posix","join","join","join","join","join","join","header","join","dirname","resolve","join"]}