@contextline/contextline 0.1.1

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.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/cli.ts","../src/tools/appendFragment.ts","../src/config.ts","../src/paths.ts","../src/core/errors.ts","../src/core/atomicWrite.ts","../src/core/markdown.ts","../src/core/details.ts","../src/core/lock.ts","../src/tools/init.ts","../src/core/instructions.ts","../src/tools/hydrate.ts","../src/tools/inspect.ts","../src/core/topology.ts","../src/core/links.ts","../src/tools/validateTopology.ts","../src/hook.ts","../src/setup.ts","../src/host/codex.ts","../src/tools/updateDeepPointer.ts","../src/tools/updateIndexPointer.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport { appendFragment } from \"./tools/appendFragment.js\";\nimport { hydrate } from \"./tools/hydrate.js\";\nimport { initContextLine } from \"./tools/init.js\";\nimport { resolveRoot, getMemoryRoot } from \"./config.js\";\nimport { inspect } from \"./tools/inspect.js\";\nimport { validateTopology } from \"./tools/validateTopology.js\";\nimport { runHook } from \"./hook.js\";\nimport { runSetup } from \"./setup.js\";\nimport { updateDeepPointer } from \"./tools/updateDeepPointer.js\";\nimport { updateIndexPointer } from \"./tools/updateIndexPointer.js\";\n\nfunction print(data: unknown) {\n console.log(JSON.stringify(data, null, 2));\n}\n\nconst program = new Command();\n\nprogram.name(\"contextline\").description(\"Local-first pointer-chain memory for AI agents.\").version(\"0.1.0\");\n\nprogram\n .command(\"init\")\n .argument(\"[root]\")\n .description(\"Create a .contextline memory folder.\")\n .action(async (root?: string) => print(await initContextLine(resolveRoot(root))));\n\nprogram\n .command(\"hydrate\")\n .argument(\"[root]\")\n .description(\"Read L1_Quick.md as the bounded quick memory cache.\")\n .action(async (root?: string) => print(await hydrate(root)));\n\nprogram\n .command(\"validate\")\n .argument(\"[root]\")\n .description(\"Validate ContextLine topology.\")\n .action(async (root?: string) => {\n const result = await validateTopology(root);\n print(result);\n if (!result.ok) process.exitCode = 1;\n });\n\nprogram\n .command(\"inspect\")\n .argument(\"[root]\")\n .description(\"Inspect ContextLine folder counts and paths.\")\n .action(async (root?: string) => print(await inspect(root)));\n\nprogram\n .command(\"append\")\n .argument(\"<text>\")\n .argument(\"[root]\")\n .option(\"--date <date>\", \"Date in YYYY-MM-DD format\")\n .description(\"Append an immutable L3 detail fragment.\")\n .action(async (text: string, root: string | undefined, options: { date?: string }) => print(await appendFragment(text, options.date, root)));\n\nprogram\n .command(\"update-deep\")\n .argument(\"<file>\")\n .argument(\"<fact-text>\")\n .argument(\"<detail-file>\")\n .argument(\"[root]\")\n .description(\"Update an L2 deep memory line with a pointer to an L3 detail file.\")\n .action(async (file: string, factText: string, detailFile: string, root?: string) => print(await updateDeepPointer(file, factText, detailFile, root)));\n\nprogram\n .command(\"update-index\")\n .argument(\"<index-line>\")\n .argument(\"<files...>\")\n .option(\"--root <root>\", \"Memory folder path\")\n .description(\"Update an L1 quick memory line with pointers to L2 deep memory files.\")\n .action(async (indexLine: string, files: string[], options: { root?: string }) => print(await updateIndexPointer(indexLine, files, options.root)));\n\nprogram\n .command(\"setup\")\n .option(\"--host <host>\", \"Host adapter: auto, codex, none\", \"auto\")\n .option(\"--verbose\", \"Print full JSON result\")\n .description(\"Initialize memory and configure supported host integrations.\")\n .action(async (options: { host?: string; verbose?: boolean }) => {\n const result = await runSetup(options);\n if (options.verbose) {\n print(result);\n } else {\n process.stdout.write(result.ok ? `ContextLine ready at ${result.root}\\n` : `Setup failed.\\n`);\n }\n if (!result.ok) process.exitCode = 1;\n });\n\nprogram\n .command(\"hook\")\n .option(\"--root <root>\", \"Memory folder path\")\n .description(\"Run ContextLine host hook. Reads hook JSON from stdin.\")\n .action(async (options: { root?: string }) => runHook(options.root));\n\nprogram.parseAsync(process.argv).catch((error) => {\n console.error(error instanceof Error ? error.message : error);\n process.exit(1);\n});\n","import fs from \"node:fs/promises\";\nimport { resolveRoot } from \"../config.js\";\nimport { detailPath } from \"../paths.js\";\nimport { atomicWriteFile } from \"../core/atomicWrite.js\";\nimport { ensureTrailingNewline } from \"../core/markdown.js\";\nimport { detailFilename, detailHeader, detailLine } from \"../core/details.js\";\nimport { withLock } from \"../core/lock.js\";\nimport { initContextLine } from \"./init.js\";\n\nexport async function appendFragment(text: string, date?: string, rootInput?: string) {\n const root = resolveRoot(rootInput);\n await initContextLine(root);\n return withLock(root, async () => {\n const detail_file = detailFilename(date);\n const filePath = detailPath(root, detail_file);\n let content: string;\n try {\n content = await fs.readFile(filePath, \"utf8\");\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") {\n throw error;\n }\n content = detailHeader(date);\n }\n const fragment = detailLine(text, date);\n await atomicWriteFile(filePath, `${ensureTrailingNewline(content)}${fragment}\\n`);\n return {\n ok: true as const,\n detail_file,\n fragment,\n next_required_steps: [\n \"Call contextline with action save_memory to save L3, L2, and L1 together.\",\n \"If manually continuing, call contextline action update_deep for every relevant L2_Deep file and action update_index for compact L1_Quick facts.\"\n ],\n display: `ContextLine L3 detail appended\\n- Detail file: ${detail_file}`\n };\n });\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\n\nexport function getMemoryRoot(): string {\n if (process.env.CONTEXTLINE_ROOT) return path.resolve(process.env.CONTEXTLINE_ROOT);\n // v1: memory lives in the current working directory.\n // The dream is to support a user-configured global root (OneDrive, GDrive, etc.)\n // so memory is shared across projects and synced across machines.\n // Blocked by host sandbox policies (e.g. Codex auto-review) that deny MCP access\n // to paths outside the project folder. Contributions welcome:\n // https://github.com/contextline/core/issues\n return path.join(process.cwd(), \".contextline\");\n}\n\nexport function resolveRoot(folder?: string): string {\n if (folder) return path.resolve(folder);\n return getMemoryRoot();\n}\n\nexport function ensureGlobalConfigDir(): void {\n const dir = getMemoryRoot();\n if (!fs.existsSync(dir)) {\n fs.mkdirSync(dir, { recursive: true });\n }\n}\n","import path from \"node:path\";\nimport { PathSafetyError } from \"./core/errors.js\";\n\nexport const L1_FILE = \"L1_Quick.md\";\nexport const L2_DIR = \"L2_Deep\";\nexport const L3_DIR = \"L3_Details\";\n\nexport function assertSafeRelative(input: string): void {\n if (!input || input.trim() !== input) {\n throw new PathSafetyError(\"Path input must be non-empty and contain no leading/trailing whitespace.\");\n }\n if (path.isAbsolute(input)) {\n throw new PathSafetyError(\"Absolute paths are not allowed in tool inputs.\");\n }\n const parts = input.split(/[\\\\/]+/);\n if (parts.includes(\"..\") || parts.includes(\"\")) {\n throw new PathSafetyError(\"Path traversal and empty path segments are not allowed.\");\n }\n}\n\nexport function assertSafeRelativeFile(input: string): void {\n assertSafeRelative(input);\n if (!input.endsWith(\".md\")) {\n throw new PathSafetyError(\"Memory file paths must end with .md.\");\n }\n}\n\nexport function safeJoin(root: string, ...segments: string[]): string {\n for (const segment of segments) {\n assertSafeRelative(segment);\n }\n const resolvedRoot = path.resolve(root);\n const target = path.resolve(resolvedRoot, ...segments);\n const rel = path.relative(resolvedRoot, target);\n if (rel.startsWith(\"..\") || path.isAbsolute(rel)) {\n throw new PathSafetyError(\"Resolved path escapes ContextLine root.\");\n }\n return target;\n}\n\nexport function deepPath(root: string, file: string): string {\n assertSafeRelativeFile(file);\n if (file.includes(\"/\") || file.includes(\"\\\\\")) {\n throw new PathSafetyError(\"L2 deep memory files must be flat filenames inside L2_Deep for V1.\");\n }\n return safeJoin(root, L2_DIR, file);\n}\n\nexport function detailPath(root: string, file: string): string {\n assertSafeRelativeFile(file);\n return safeJoin(root, L3_DIR, file);\n}\n\n\nexport function l1Path(root: string): string {\n return safeJoin(root, L1_FILE);\n}\n","export class ContextLineError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"ContextLineError\";\n }\n}\n\nexport class PathSafetyError extends ContextLineError {\n constructor(message: string) {\n super(message);\n this.name = \"PathSafetyError\";\n }\n}\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\n\nexport async function atomicWriteFile(filePath: string, content: string): Promise<void> {\n await fs.mkdir(path.dirname(filePath), { recursive: true });\n const tmp = path.join(path.dirname(filePath), `.${path.basename(filePath)}.${process.pid}.${Date.now()}.tmp`);\n const handle = await fs.open(tmp, \"w\");\n try {\n await handle.writeFile(content, \"utf8\");\n await handle.sync();\n } finally {\n await handle.close();\n }\n await fs.rename(tmp, filePath);\n}\n","export function ensureTrailingNewline(content: string): string {\n return content.endsWith(\"\\n\") ? content : `${content}\\n`;\n}\n\nexport function upsertLineByPrefix(content: string, prefix: string, nextLine: string): string {\n const lines = ensureTrailingNewline(content).split(\"\\n\");\n const index = lines.findIndex((line) => line.trimStart().startsWith(prefix));\n if (index >= 0) {\n lines[index] = nextLine;\n } else {\n lines.splice(Math.max(0, lines.length - 1), 0, nextLine);\n }\n return ensureTrailingNewline(lines.join(\"\\n\").replace(/\\n{3,}/g, \"\\n\\n\"));\n}\n","import { format, parseISO } from \"date-fns\";\n\nexport function detailFilename(dateInput?: string): string {\n const date = dateInput ? parseISO(dateInput) : new Date();\n if (Number.isNaN(date.getTime())) {\n throw new Error(\"Invalid date. Expected YYYY-MM-DD.\");\n }\n return `L3_${format(date, \"yyyy_MM\")}.md`;\n}\n\nexport function detailHeader(dateInput?: string): string {\n const date = dateInput ? parseISO(dateInput) : new Date();\n if (Number.isNaN(date.getTime())) {\n throw new Error(\"Invalid date. Expected YYYY-MM-DD.\");\n }\n return `# ${format(date, \"MMMM yyyy\")} Detailed Memory\\n\\n`;\n}\n\nexport function detailLine(text: string, dateInput?: string): string {\n const date = dateInput ? parseISO(dateInput) : new Date();\n if (Number.isNaN(date.getTime())) {\n throw new Error(\"Invalid date. Expected YYYY-MM-DD.\");\n }\n const clean = text.replace(/\\s+/g, \" \").trim();\n if (!clean) {\n throw new Error(\"Detail text must be non-empty.\");\n }\n return `* [${format(date, \"yyyy-MM-dd\")}]: ${clean}`;\n}\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\n\nconst sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));\n\nexport async function withLock<T>(root: string, fn: () => Promise<T>): Promise<T> {\n const lockPath = path.join(root, \".lock\");\n const start = Date.now();\n let handle: fs.FileHandle | undefined;\n while (!handle) {\n try {\n await fs.mkdir(root, { recursive: true });\n handle = await fs.open(lockPath, \"wx\");\n } catch (error) {\n const code = (error as NodeJS.ErrnoException).code;\n if (code !== \"EEXIST\" || Date.now() - start > 5000) {\n throw error;\n }\n await sleep(50);\n }\n }\n try {\n return await fn();\n } finally {\n await handle.close();\n await fs.rm(lockPath, { force: true });\n }\n}\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { CONTEXTLINE_INSTRUCTIONS_FILE, DEFAULT_CONTEXTLINE_INSTRUCTIONS } from \"../core/instructions.js\";\nimport { L1_FILE, L2_DIR, L3_DIR, safeJoin } from \"../paths.js\";\nimport type { InitResult } from \"../core/types.js\";\n\nconst DEFAULT_L1 = `# ContextLine L1 Index\n\nThis is the quick memory cache: compact facts, summaries, and active pointers.\n\n## Quick Facts\n\n`;\n\nexport async function initContextLine(root: string): Promise<InitResult> {\n const created: string[] = [];\n await fs.mkdir(root, { recursive: true });\n\n for (const dir of [\n L2_DIR,\n L3_DIR,\n \"maintenance\",\n \"maintenance/proposals\"\n ]) {\n const target = safeJoin(root, ...dir.split(\"/\"));\n await fs.mkdir(target, { recursive: true });\n created.push(path.relative(root, target));\n }\n\n const files: Array<[string, string]> = [\n [L1_FILE, DEFAULT_L1],\n [CONTEXTLINE_INSTRUCTIONS_FILE, DEFAULT_CONTEXTLINE_INSTRUCTIONS],\n [\"config.json\", `${JSON.stringify({ version: 1, capture: { promotion: \"selective\" } }, null, 2)}\\n`]\n ];\n\n for (const [file, content] of files) {\n const target = safeJoin(root, file);\n try {\n await fs.writeFile(target, content, { encoding: \"utf8\", flag: \"wx\" });\n created.push(path.relative(root, target));\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"EEXIST\") {\n throw error;\n }\n }\n }\n\n return { ok: true, root, created };\n}\n","export const CONTEXTLINE_INSTRUCTIONS_FILE = \"contextline_instructions.md\";\n\nexport const DEFAULT_CONTEXTLINE_INSTRUCTIONS = `# ContextLine Instructions\n\nCONTEXTLINE-INSTRUCTIONS-V1\nThis file contains generic operating instructions for ContextLine memory.\nUse the single MCP tool named \"contextline\" for all ContextLine reads and writes.\nDo not use shell commands to read or write .contextline files.\nDo not mention memory saving unless the user asks.\n\n## Operating Policy\n\nUse the single ContextLine MCP tool \"contextline\" silently for durable memory. Do not use shell commands to read or write .contextline files. Do not mention memory saving unless asked.\n\nDurable memory means stable facts likely to help future sessions: user/project facts, preferences, goals, constraints, decisions, relationships, recurring patterns, and important events. Do not save filler, acknowledgements, or one-off chatter.\n\nDo not save every message. Periodically batch-save useful durable memory since the last ContextLine save in this session.\n\nUse ContextLine as a human-like cache:\n\n- L1_Quick.md stores compact facts, summaries, and active pointers.\n- L2_Deep/ stores deeper facts per important object, person, event, project, preference area, or decision thread.\n- L3_Details/ stores timestamped specifics, receipts, and supporting history.\n\nFor V1, use flat L2 filenames with semantic prefixes instead of folders. Prefer names like person_user.md, project_contextline.md, area_work.md, place_san_jose.md, preference_media.md, preference_language.md, decision_memory_architecture.md, event_launch.md, or org_meta.md.\n\nWhen saving durable memory, complete the full chain. Do not stop after writing L3_Details:\n\n1. Append one L3_Details receipt when supporting specifics are useful.\n2. Cross-save extracted meaning into every relevant L2_Deep file.\n3. Update L1_Quick only for compact high-level facts or active pointers.\n4. Link every L1 line to relevant L2 files.\n5. Link every L2 line to relevant L3 details when supporting detail exists.\n\nTypical tool sequence:\n\nCall \"contextline\" once with action \"save_memory\", including:\n\n- detail.text for the L3_Details receipt\n- deep[] entries for every relevant L2_Deep file, such as person_user.md, area_work.md, place_san_jose.md, or preference_media.md\n- quick[] entries for compact L1_Quick facts linked to L2 files\n\nIf you write L3_Details but do not update L2_Deep and L1_Quick, the memory is incomplete. Prefer the bundled \"save_memory\" action so the full chain is saved together.\n`;\n","import fs from \"node:fs/promises\";\nimport { CONTEXTLINE_INSTRUCTIONS_FILE } from \"../core/instructions.js\";\nimport { resolveRoot } from \"../config.js\";\nimport { l1Path, safeJoin } from \"../paths.js\";\nimport { initContextLine } from \"./init.js\";\n\nexport async function hydrate(rootInput?: string) {\n const root = resolveRoot(rootInput);\n await initContextLine(root);\n const l1_path = l1Path(root);\n const instructions_path = safeJoin(root, CONTEXTLINE_INSTRUCTIONS_FILE);\n const content = await fs.readFile(l1_path, \"utf8\");\n const instructions = await fs.readFile(instructions_path, \"utf8\");\n return {\n ok: true,\n root,\n l1_path,\n instructions_path,\n content,\n instructions,\n instruction: \"Use this L1 content as quick memory. Follow the included ContextLine instructions for reading and saving memory.\",\n display: `ContextLine hydrated\\n- Quick memory: ${l1_path}\\n- Instructions: ${instructions_path}`\n };\n}\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { resolveRoot } from \"../config.js\";\nimport { L1_FILE, L2_DIR, L3_DIR, safeJoin } from \"../paths.js\";\n\nasync function countFiles(dir: string): Promise<number> {\n try {\n return (await fs.readdir(dir)).length;\n } catch {\n return 0;\n }\n}\n\nexport async function inspect(rootInput?: string) {\n const root = resolveRoot(rootInput);\n return {\n root,\n l1: path.join(root, L1_FILE),\n l2_deep_files: await countFiles(safeJoin(root, L2_DIR)),\n l3_detail_files: await countFiles(safeJoin(root, L3_DIR))\n };\n}\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { L1_FILE, L2_DIR, L3_DIR, l1Path, safeJoin } from \"../paths.js\";\nimport { extractWikiLinks } from \"./links.js\";\nimport type { ValidationResult } from \"./types.js\";\n\nasync function exists(target: string): Promise<boolean> {\n try {\n await fs.access(target);\n return true;\n } catch {\n return false;\n }\n}\n\nasync function listMarkdown(dir: string): Promise<string[]> {\n const out: string[] = [];\n try {\n const entries = await fs.readdir(dir, { withFileTypes: true });\n for (const entry of entries) {\n const full = path.join(dir, entry.name);\n if (entry.isDirectory()) {\n const nested = await listMarkdown(full);\n out.push(...nested.map((file) => path.join(entry.name, file)));\n } else if (entry.name.endsWith(\".md\")) {\n out.push(entry.name);\n }\n }\n return out;\n } catch {\n return [];\n }\n}\n\nexport async function validateTopology(root: string): Promise<ValidationResult> {\n const errors: string[] = [];\n const warnings: string[] = [];\n const l1 = l1Path(root);\n const l2 = safeJoin(root, L2_DIR);\n const l3 = safeJoin(root, L3_DIR);\n\n if (!(await exists(l1))) errors.push(\"L1_Quick.md is missing.\");\n if (!(await exists(l2))) errors.push(\"L2_Deep directory is missing.\");\n if (!(await exists(l3))) errors.push(\"L3_Details directory is missing.\");\n\n if (errors.length) return { ok: false, errors, warnings };\n\n const l1Content = await fs.readFile(l1, \"utf8\");\n for (const link of extractWikiLinks(l1Content)) {\n if (link.startsWith(\"L3_\")) {\n errors.push(`L1 must not link directly to L3 detail file: ${link}`);\n } else if (!(await exists(path.join(l2, link)))) {\n errors.push(`L1 links to missing L2 deep memory file: ${link}`);\n }\n }\n\n for (const file of await listMarkdown(l2)) {\n const content = await fs.readFile(path.join(l2, file), \"utf8\");\n for (const link of extractWikiLinks(content)) {\n if (link === L1_FILE) {\n errors.push(`L2 deep memory file ${file} must not link upward to L1_Quick.md.`);\n } else if (!link.startsWith(\"L3_\")) {\n warnings.push(`L2 deep memory file ${file} links to non-L3 file: ${link}`);\n } else if (!(await exists(path.join(l3, link)))) {\n errors.push(`L2 deep memory file ${file} links to missing L3 detail file: ${link}`);\n }\n }\n }\n\n for (const file of await listMarkdown(l3)) {\n const content = await fs.readFile(path.join(l3, file), \"utf8\");\n const links = extractWikiLinks(content);\n if (links.length) {\n errors.push(`L3 detail file ${file} must not contain wiki links.`);\n }\n }\n\n return { ok: errors.length === 0, errors, warnings };\n}\n","export const WIKI_LINK_RE = /\\[\\[([^\\]]+)\\]\\]/g;\n\nexport function extractWikiLinks(content: string): string[] {\n return [...content.matchAll(WIKI_LINK_RE)].map((match) => match[1]);\n}\n\nexport function hasWikiLink(line: string, filename: string): boolean {\n return extractWikiLinks(line).includes(filename);\n}\n\nexport function ensureWikiLink(line: string, filename: string): string {\n return hasWikiLink(line, filename) ? line : `${line.trim()} [[${filename}]]`;\n}\n","import { resolveRoot } from \"../config.js\";\nimport { validateTopology as validate } from \"../core/topology.js\";\nimport { initContextLine } from \"./init.js\";\n\nexport async function validateTopology(rootInput?: string) {\n const root = resolveRoot(rootInput);\n await initContextLine(root);\n const result = await validate(root);\n return {\n ...result,\n display: result.ok ? \"ContextLine topology valid\" : `ContextLine topology invalid\\n- Errors: ${result.errors.length}\\n- Warnings: ${result.warnings.length}`\n };\n}\n","import { resolveRoot } from \"./config.js\";\nimport path from \"node:path\";\nimport type { HookEvent } from \"./core/types.js\";\nimport { CONTEXTLINE_INSTRUCTIONS_FILE } from \"./core/instructions.js\";\n\nasync function readStdin(): Promise<string> {\n const chunks: Buffer[] = [];\n for await (const chunk of process.stdin) chunks.push(Buffer.from(chunk));\n return Buffer.concat(chunks).toString(\"utf8\");\n}\n\nexport async function runHook(rootInput?: string): Promise<void> {\n const raw = await readStdin();\n const event = raw.trim() ? (JSON.parse(raw) as HookEvent) : {};\n const root = rootInput ? path.resolve(rootInput) : resolveRoot();\n\n if (event.hook_event_name === \"SessionStart\") {\n process.stdout.write(\n JSON.stringify({\n continue: true,\n hookSpecificOutput: {\n hookEventName: \"SessionStart\",\n additionalContext: `ContextLine memory is available. Call the \"contextline\" MCP tool with action \"hydrate\" and root ${JSON.stringify(root)} to load your memory index. This reads only files inside the .contextline folder at that path — it does not scan or ingest the parent directory. Use that same root for all ContextLine calls this session, then follow the returned instructions.`\n }\n })\n );\n return;\n }\n}\n","import { cwd } from \"node:process\";\nimport { getMemoryRoot } from \"./config.js\";\nimport { detectCodex, setupCodex } from \"./host/codex.js\";\nimport { initContextLine } from \"./tools/init.js\";\nimport { validateTopology } from \"./tools/validateTopology.js\";\n\nexport interface SetupOptions {\n host?: string;\n}\n\nexport async function runSetup(options: SetupOptions = {}) {\n const projectRoot = cwd();\n const root = getMemoryRoot();\n const requestedHost = options.host ?? \"auto\";\n\n let host = requestedHost;\n let detectionDetails: string[] = [];\n if (requestedHost === \"auto\") {\n const detected = await detectCodex(projectRoot);\n host = detected.host === \"codex\" ? \"codex\" : \"none\";\n detectionDetails = detected.details;\n }\n\n await initContextLine(root);\n let hostSetup: unknown = null;\n if (host === \"codex\") {\n hostSetup = await setupCodex(projectRoot, root);\n }\n\n const validation = await validateTopology(root);\n return {\n ok: validation.ok,\n root,\n host,\n detectionDetails,\n hostSetup,\n validation,\n mcpConfig: {\n mcpServers: {\n contextline: {\n command: \"contextline-mcp\",\n args: [],\n env: {\n CONTEXTLINE_ROOT: root\n }\n }\n }\n }\n };\n}\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport os from \"node:os\";\nimport { initContextLine } from \"../tools/init.js\";\nimport type { HostDetection } from \"../core/types.js\";\n\nfunction contextlineMcpBlock(contextlineRoot: string): string {\n return `[mcp_servers.contextline]\ntype = \"stdio\"\ncommand = \"contextline-mcp\"\nargs = []\nenv = { CONTEXTLINE_ROOT = ${JSON.stringify(contextlineRoot)} }\nstartup_timeout_sec = 10\ntool_timeout_sec = 10\n`;\n}\n\nasync function upsertContextlineMcpConfig(configTomlPath: string, contextlineRoot: string) {\n let existingConfig = \"\";\n try {\n existingConfig = await fs.readFile(configTomlPath, \"utf8\");\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n }\n const withoutContextLine = existingConfig.replace(/\\n?\\[mcp_servers\\.contextline\\][\\s\\S]*?(?=\\n\\[|$)/, \"\").trim();\n const mcpBlock = contextlineMcpBlock(contextlineRoot);\n await fs.writeFile(configTomlPath, `${withoutContextLine ? `${withoutContextLine}\\n\\n` : \"\"}${mcpBlock}\\n`, \"utf8\");\n}\n\nasync function writeHookScript(scriptPath: string, contextlineRoot: string) {\n const script = `#!/usr/bin/env node\nimport { spawnSync } from \"node:child_process\";\nimport fs from \"node:fs\";\n\nconst input = fs.readFileSync(0, \"utf8\");\nconst result = spawnSync(\"contextline\", [\"hook\", \"--root\", ${JSON.stringify(contextlineRoot)}], {\n input,\n encoding: \"utf8\",\n shell: process.platform === \"win32\"\n});\n\nif (result.stderr) process.stderr.write(result.stderr);\nif (result.stdout) process.stdout.write(result.stdout);\nprocess.exit(result.status ?? 0);\n`;\n await fs.writeFile(scriptPath, script, \"utf8\");\n}\n\nasync function upsertHooksJson(hooksJsonPath: string, hookScriptPath: string) {\n let existing: Record<string, unknown> = {};\n try {\n const raw = await fs.readFile(hooksJsonPath, \"utf8\");\n existing = JSON.parse(raw);\n } catch {\n // missing or unparseable — start fresh\n }\n\n if (!existing.hooks || typeof existing.hooks !== \"object\") {\n existing.hooks = {};\n }\n const hooks = existing.hooks as Record<string, unknown[]>;\n const sessionStart: unknown[] = Array.isArray(hooks.SessionStart) ? hooks.SessionStart : [];\n\n // Remove any existing contextline entry\n const filtered = sessionStart.filter((entry) => {\n if (!entry || typeof entry !== \"object\") return true;\n const e = entry as { hooks?: { command?: string }[] };\n return !e.hooks?.some((h) => h.command?.includes(\"contextline\"));\n });\n\n const contextlineEntry = {\n matcher: \"startup|resume|clear|compact\",\n hooks: [{ type: \"command\", command: `node ${JSON.stringify(hookScriptPath)}` }]\n };\n\n hooks.SessionStart = [contextlineEntry, ...filtered];\n await fs.writeFile(hooksJsonPath, `${JSON.stringify(existing, null, 2)}\\n`, \"utf8\");\n}\n\nexport async function detectCodex(projectRoot: string): Promise<HostDetection> {\n const details: string[] = [];\n const candidates = [\n path.join(os.homedir(), \".codex\"),\n path.join(projectRoot, \".codex\"),\n process.env.CODEX_HOME\n ].filter(Boolean) as string[];\n for (const candidate of candidates) {\n try {\n await fs.access(candidate);\n details.push(`found ${candidate}`);\n } catch {\n // ignore\n }\n }\n if (details.length) return { host: \"codex\", confidence: \"high\", details };\n return { host: \"none\", confidence: \"none\", details: [] };\n}\n\nexport async function setupCodex(projectRoot: string, contextlineRoot: string) {\n await initContextLine(contextlineRoot);\n\n // Project-level setup\n const codexDir = path.join(projectRoot, \".codex\");\n const hooksDir = path.join(codexDir, \"hooks\");\n await fs.mkdir(hooksDir, { recursive: true });\n\n const hookScriptPath = path.join(hooksDir, \"contextline-hook.mjs\");\n await writeHookScript(hookScriptPath, contextlineRoot);\n\n const hooksJsonPath = path.join(codexDir, \"hooks.json\");\n await upsertHooksJson(hooksJsonPath, hookScriptPath);\n\n const configTomlPath = path.join(codexDir, \"config.toml\");\n await upsertContextlineMcpConfig(configTomlPath, contextlineRoot);\n\n // Global setup — configures Codex UI for all sessions\n const globalCodexDir = process.env.CODEX_HOME ?? path.join(os.homedir(), \".codex\");\n const globalHooksDir = path.join(globalCodexDir, \"hooks\");\n await fs.mkdir(globalHooksDir, { recursive: true });\n\n const globalHookScriptPath = path.join(globalHooksDir, \"contextline-hook.mjs\");\n await writeHookScript(globalHookScriptPath, contextlineRoot);\n\n const globalHooksJsonPath = path.join(globalCodexDir, \"hooks.json\");\n await upsertHooksJson(globalHooksJsonPath, globalHookScriptPath);\n\n const globalConfigTomlPath = path.join(globalCodexDir, \"config.toml\");\n if (path.resolve(globalConfigTomlPath) !== path.resolve(configTomlPath)) {\n await upsertContextlineMcpConfig(globalConfigTomlPath, contextlineRoot);\n }\n\n const agentsPath = path.join(projectRoot, \"AGENTS.md\");\n try {\n const existingAgents = await fs.readFile(agentsPath, \"utf8\");\n if (existingAgents.includes(\"# ContextLine Memory\")) {\n const cleanedAgents = existingAgents.slice(0, existingAgents.indexOf(\"# ContextLine Memory\")).trim();\n if (cleanedAgents) {\n await fs.writeFile(agentsPath, `${cleanedAgents}\\n`, \"utf8\");\n } else {\n await fs.rm(agentsPath, { force: true });\n }\n }\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n }\n\n return { hooksJsonPath, hookScriptPath, configTomlPath, globalHooksJsonPath, globalHookScriptPath, globalConfigTomlPath };\n}\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { resolveRoot } from \"../config.js\";\nimport { deepPath, detailPath } from \"../paths.js\";\nimport { atomicWriteFile } from \"../core/atomicWrite.js\";\nimport { ensureWikiLink } from \"../core/links.js\";\nimport { ensureTrailingNewline, upsertLineByPrefix } from \"../core/markdown.js\";\nimport { withLock } from \"../core/lock.js\";\nimport { initContextLine } from \"./init.js\";\n\nexport async function updateDeepPointer(file: string, factText: string, detailFile: string, rootInput?: string) {\n const root = resolveRoot(rootInput);\n await initContextLine(root);\n detailPath(root, detailFile);\n return withLock(root, async () => {\n const filePath = deepPath(root, file);\n let content = \"\";\n try {\n content = await fs.readFile(filePath, \"utf8\");\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") {\n throw error;\n }\n content = `# ${path.basename(file, \".md\")}\\n\\n`;\n }\n const updated_line = ensureWikiLink(factText, detailFile);\n const next = upsertLineByPrefix(ensureTrailingNewline(content), factText.trim(), updated_line);\n await atomicWriteFile(filePath, next);\n return { ok: true as const, file, updated_line, display: `ContextLine L2 updated\\n- File: ${file}` };\n });\n}\n","import fs from \"node:fs/promises\";\nimport { resolveRoot } from \"../config.js\";\nimport { deepPath, l1Path } from \"../paths.js\";\nimport { atomicWriteFile } from \"../core/atomicWrite.js\";\nimport { ensureWikiLink } from \"../core/links.js\";\nimport { ensureTrailingNewline, upsertLineByPrefix } from \"../core/markdown.js\";\nimport { withLock } from \"../core/lock.js\";\nimport { initContextLine } from \"./init.js\";\n\nexport async function updateIndexPointer(indexLine: string, files: string[], rootInput?: string) {\n if (files.some((file) => file.startsWith(\"L3_\"))) {\n throw new Error(\"L1 quick memory pointers may only reference L2 deep memory files.\");\n }\n const root = resolveRoot(rootInput);\n await initContextLine(root);\n for (const file of files) {\n deepPath(root, file);\n }\n return withLock(root, async () => {\n const filePath = l1Path(root);\n const content = await fs.readFile(filePath, \"utf8\");\n const updated_line = files.reduce((line, file) => ensureWikiLink(line, file), indexLine);\n const next = upsertLineByPrefix(ensureTrailingNewline(content), indexLine.trim(), updated_line);\n await atomicWriteFile(filePath, next);\n return { ok: true as const, updated_line, display: \"ContextLine L1 updated\" };\n });\n}\n"],"mappings":";;;AAAA,SAAS,eAAe;;;ACAxB,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,OAAO,OAAO,YAA+B,QAAQ,QAAQ,IAAI,CAAC;AAErE,QAAQ,WAAW,QAAQ,IAAI,EAAE,MAAM,CAAC,UAAU;AAChD,UAAQ,MAAM,iBAAiB,QAAQ,MAAM,UAAU,KAAK;AAC5D,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":["fs","path","path","fs","path","fs","path","fs","path","fs","path","fs","fs","fs","fs","path","fs","path","fs","path","fs","path","validateTopology","path","fs","path","fs","path","validateTopology","fs","path","fs","path","fs","fs","validateTopology"]}
@@ -0,0 +1,2 @@
1
+
2
+ export { }