github-router 0.3.378 → 0.3.379
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.
- package/dist/{attribution-settings-BR5Umj2L.js → attribution-settings-BWYL2b8N.js} +2 -2
- package/dist/{attribution-settings-BR5Umj2L.js.map → attribution-settings-BWYL2b8N.js.map} +1 -1
- package/dist/browser-ext/manifest.json +1 -1
- package/dist/{claude--4O3wHRq.js → claude-CSuIdaLV.js} +3 -3
- package/dist/{claude--4O3wHRq.js.map → claude-CSuIdaLV.js.map} +1 -1
- package/dist/{codex-DHRMLpSo.js → codex-BG0pfud9.js} +2 -2
- package/dist/{codex-DHRMLpSo.js.map → codex-BG0pfud9.js.map} +1 -1
- package/dist/main.js +5 -5
- package/dist/{pi-B0EFY6l7.js → pi-DmeBxzIo.js} +344 -40
- package/dist/pi-DmeBxzIo.js.map +1 -0
- package/dist/pi-foreign-artifacts-DZ4tioyO.js +660 -0
- package/dist/pi-foreign-artifacts-DZ4tioyO.js.map +1 -0
- package/dist/pi-memory-bridge-Bp9AnYw9.js +1 -0
- package/dist/{pi-memory-bridge-Dvj1T3e3.js → pi-memory-bridge-CICIdDVP.js} +15 -5
- package/dist/pi-memory-bridge-CICIdDVP.js.map +1 -0
- package/dist/{serve-C13q-9w0.js → serve-zbQKfx1E.js} +3 -3
- package/dist/{serve-C13q-9w0.js.map → serve-zbQKfx1E.js.map} +1 -1
- package/dist/{server-setup-CptI7SUT.js → server-setup-ClZdV33Q.js} +2 -2
- package/dist/{server-setup-CptI7SUT.js.map → server-setup-ClZdV33Q.js.map} +1 -1
- package/dist/{start-DioCGjM8.js → start-mnedD5cH.js} +2 -2
- package/dist/{start-DioCGjM8.js.map → start-mnedD5cH.js.map} +1 -1
- package/package.json +1 -1
- package/dist/pi-B0EFY6l7.js.map +0 -1
- package/dist/pi-memory-bridge-Dvj1T3e3.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pi-memory-bridge-Dvj1T3e3.js","names":[],"sources":["../src/lib/pi-memory-bridge.ts"],"sourcesContent":["import fs from \"node:fs/promises\"\nimport os from \"node:os\"\nimport path from \"node:path\"\n\n/**\n * Pi memory bridge: repo instruction + user-global + auto-memory surfacing.\n *\n * Pi natively loads per-dir first-win\n * `AGENTS.override.md > AGENTS.md > AGENTS.MD > CLAUDE.md > CLAUDE.MD`\n * (agentDir global + fs-root → cwd, concatenated, no trust gate).\n * It does NOT load `.github/copilot-instructions.md`,\n * `.github/instructions/*.instructions.md` (`applyTo`), `.claude/rules/`\n * (`paths:`), `@path` imports, `CLAUDE.local.md`, `./.claude/CLAUDE.md`,\n * `~/.claude/CLAUDE.md`, or Claude auto-memory.\n *\n * Strategy (per approved plan): synthesize the static repo-wide slice into\n * the per-launch mirror's `AGENTS.md` (a Pi-native candidate, so no new\n * loader is needed) and lazy-attach path-scoped rules via the\n * `gh-router-pi` extension's `tool_result` hook (mirrors\n * `pi-code/claude-rules.ts`). Auto-memory is on-demand only (`/memory`\n * command + explicit read), never auto-injected.\n *\n * All filesystem access is best-effort: missing/unreadable files are\n * skipped, never fatal. Pure helpers are exported for unit tests.\n */\n\nexport const PI_BRIDGE_STATIC_BUDGET_BYTES = 24_000 as const\nexport const PI_BRIDGE_IMPORT_MAX_DEPTH = 4 as const\nexport const PI_BRIDGE_IMPORT_MAX_FILES = 10 as const\nexport const PI_BRIDGE_MEMORY_INDEX_MAX_LINES = 200 as const\nexport const PI_BRIDGE_MEMORY_INDEX_MAX_BYTES = 25_000 as const\nexport const PI_BRIDGE_FENCE_BEGIN = \"<!-- gh-router memory-bridge begin -->\"\nexport const PI_BRIDGE_FENCE_END = \"<!-- gh-router memory-bridge end -->\"\n\nexport interface PiBridgeScopedRule {\n /** Display path (absolute or repo-relative) for attribution. */\n file: string\n /** Rule body with frontmatter stripped. */\n body: string\n /** Glob list from `paths:` / `applyTo:` / `globs:`. Empty = unscoped. */\n globs: Array<string>\n /** Where the rule came from (for `/context` surfacing). */\n source: string\n}\n\nexport interface PiBridgeCollected {\n /** Repo-wide copilot instructions that were found (after import expansion). */\n copilotInstructions: Array<{ file: string; content: string }>\n /** Unscoped Claude rules (inlined statically). */\n unscopedRules: Array<{ file: string; content: string }>\n /** Path-scoped rules (lazy-attached, not inlined). */\n scopedRules: Array<PiBridgeScopedRule>\n /** User-global files found (capped, inlined). */\n userGlobal: Array<{ file: string; content: string }>\n /** Resolved `@` imports (appended once, deduped). */\n imports: Array<{ file: string; content: string }>\n /** Skipped files with reasons (for `/context`). */\n skipped: Array<{ file: string; reason: string }>\n}\n\nexport interface PiBridgeStats {\n staticFiles: number\n scopedRules: number\n imports: number\n skipped: number\n truncated: boolean\n}\n\nfunction byteLength(s: string): number {\n return Buffer.byteLength(s, \"utf8\")\n}\n\nfunction capBytes(s: string, max: number): { text: string; truncated: boolean } {\n if (byteLength(s) <= max) return { text: s, truncated: false }\n let low = 0\n let high = s.length\n while (low < high) {\n const mid = Math.floor((low + high) / 2)\n if (byteLength(s.slice(0, mid)) <= max) low = mid + 1\n else high = mid\n }\n return { text: `${s.slice(0, Math.max(0, low - 1))}\\n…[truncated by gh-router memory bridge]` , truncated: true }\n}\n\n/** Strip YAML frontmatter (`--- ... ---`) and return body + raw frontmatter. */\nexport function splitFrontmatter(raw: string): { frontmatter: string; body: string } {\n const normalized = raw.replace(/\\r\\n/g, \"\\n\")\n if (!normalized.startsWith(\"---\")) return { frontmatter: \"\", body: normalized }\n const end = normalized.indexOf(\"\\n---\", 3)\n if (end === -1) return { frontmatter: \"\", body: normalized }\n return {\n frontmatter: normalized.slice(3, end).trim(),\n body: normalized.slice(end + 4).replace(/^\\n/, \"\"),\n }\n}\n\n/**\n * Minimal frontmatter glob extraction for `paths:` / `applyTo:` / `globs:`.\n * Supports `key: \"glob\"`, `key: a, b`, and YAML lists. Case-insensitive keys.\n * Returns [] when no scoping key is present (unscoped rule).\n */\nexport function extractScopeGlobs(frontmatter: string): Array<string> {\n const out: Array<string> = []\n const lines = frontmatter.split(\"\\n\")\n let i = 0\n while (i < lines.length) {\n const line = lines[i] ?? \"\"\n const m = /^\\s*(paths|applyTo|globs)\\s*:\\s*(.*)$/i.exec(line)\n if (!m) {\n i++\n continue\n }\n const rest = (m[2] ?? \"\").trim()\n if (rest.startsWith(\"[\") && rest.endsWith(\"]\")) {\n for (const part of rest.slice(1, -1).split(\",\")) {\n const v = part.trim().replace(/^[\"']|[\"']$/g, \"\")\n if (v) out.push(v)\n }\n i++\n continue\n }\n if (rest && !rest.startsWith(\"|\") && !rest.startsWith(\">\")) {\n const v = rest.replace(/^[\"']|[\"']$/g, \"\").split(\"#\")[0]?.trim() ?? \"\"\n if (v) {\n for (const part of v.split(\",\")) {\n const p = part.trim()\n if (p) out.push(p)\n }\n }\n i++\n continue\n }\n // Block list on following indented lines (`- \"glob\"`).\n i++\n while (i < lines.length) {\n const item = lines[i] ?? \"\"\n const im = /^\\s+-\\s+(.+)$/.exec(item)\n if (!im) break\n const v = (im[1] ?? \"\").trim().replace(/^[\"']|[\"']$/g, \"\")\n if (v) out.push(v)\n i++\n }\n }\n return out\n}\n\n/** Convert a single glob to RegExp. `*` stays in-segment, `**` crosses. */\nfunction globToRegExp(glob: string): RegExp {\n const g = glob.trim().replace(/^\\.\\//, \"\").replace(/^\\/+/, \"\")\n let re = \"\"\n let k = 0\n while (k < g.length) {\n const c = g[k]\n if (c === \"*\") {\n if (g[k + 1] === \"*\") {\n // `**/` → optional any-prefix; trailing `/**` → any suffix.\n if (g[k + 2] === \"/\") {\n re += \"(?:.*/)?\"\n k += 3\n } else {\n re += \".*\"\n k += 2\n }\n } else {\n re += \"[^/]*\"\n k += 1\n }\n continue\n }\n if (c === \"?\") {\n re += \"[^/]\"\n k += 1\n continue\n }\n if (\"+()|^$.{}[]\\\\\".includes(c ?? \"\")) re += `\\\\${c}`\n else re += c\n k += 1\n }\n // Slashless patterns (`*.ts`) match basename at any depth (gitignore-style).\n if (!g.includes(\"/\")) re = `(?:.*/)?${re}`\n return new RegExp(`^${re}$`)\n}\n\n/**\n * Does a touched file match any of the rule globs?\n * `touchedAbs` may be absolute or repo-relative; `ruleRoot` scopes\n * project-relative globs. Falls back to basename matching.\n */\nexport function ruleMatchesFile(\n globs: ReadonlyArray<string>,\n touchedAbs: string,\n ruleRoot: string,\n): boolean {\n if (globs.length === 0) return false\n const candidates = new Set<string>()\n const norm = touchedAbs.replace(/\\\\/g, \"/\")\n candidates.add(norm)\n const rel = path.relative(ruleRoot, touchedAbs).replace(/\\\\/g, \"/\")\n if (rel && !rel.startsWith(\"..\")) candidates.add(rel)\n candidates.add(path.basename(touchedAbs))\n for (const glob of globs) {\n let re: RegExp\n try {\n re = globToRegExp(glob)\n } catch {\n continue\n }\n for (const c of candidates) {\n if (re.test(c)) return true\n }\n }\n return false\n}\n\n/** Extract `@path` references (whole-line or trailing) ending in a text extension. */\nexport function extractAtImports(content: string): Array<string> {\n const refs: Array<string> = []\n const seen = new Set<string>()\n const pattern = /@([~.]?[\\w./\\\\-]+\\.(?:md|txt|yaml|yml|json|toml))(?:\\s|$)/g\n for (const line of content.split(\"\\n\")) {\n const trimmed = line.trim()\n if (!trimmed.includes(\"@\")) continue\n // Skip fenced-code `@` mentions (commented-out imports must not expand).\n pattern.lastIndex = 0\n let m: RegExpExecArray | null\n while ((m = pattern.exec(trimmed)) !== null) {\n const ref = m[1] ?? \"\"\n if (ref && !seen.has(ref)) {\n seen.add(ref)\n refs.push(ref)\n }\n }\n }\n return refs\n}\n\n/**\n * Resolve `@` imports against an in-memory file map (pure, testable).\n * Depth-capped, cycle-safe, budget-capped. Returns appended bodies only\n * (base files are never re-appended by the caller).\n */\nexport function resolveImportsPure(\n baseFiles: ReadonlyArray<{ file: string; content: string }>,\n readFile: (absPath: string) => string | undefined,\n homeDir: string,\n maxDepth = PI_BRIDGE_IMPORT_MAX_DEPTH,\n maxFiles = PI_BRIDGE_IMPORT_MAX_FILES,\n): Array<{ file: string; content: string }> {\n const out: Array<{ file: string; content: string }> = []\n const visited = new Set<string>()\n for (const base of baseFiles) {\n try {\n visited.add(path.resolve(base.file))\n } catch {\n visited.add(base.file)\n }\n }\n const visit = (importerAbs: string, content: string, depth: number): void => {\n if (depth > maxDepth || out.length >= maxFiles) return\n const baseDir = path.dirname(importerAbs)\n for (const ref of extractAtImports(content)) {\n if (out.length >= maxFiles) return\n let expanded = ref\n if (expanded.startsWith(\"~\")) expanded = path.join(homeDir, expanded.slice(1))\n const abs = path.isAbsolute(expanded) ? path.normalize(expanded) : path.resolve(baseDir, expanded)\n if (visited.has(abs)) continue\n visited.add(abs)\n const body = readFile(abs)\n if (body === undefined) continue\n out.push({ file: abs, content: splitFrontmatter(body).body })\n visit(abs, body, depth + 1)\n }\n }\n for (const base of baseFiles) {\n let abs = base.file\n try {\n abs = path.resolve(base.file)\n } catch {\n // keep as-is\n }\n visit(abs, base.content, 1)\n }\n return out\n}\n\n/** Cap Claude auto-memory index the way Claude Code measures it. */\nexport function capMemoryIndex(raw: string): string {\n const lines = raw.split(\"\\n\").slice(0, PI_BRIDGE_MEMORY_INDEX_MAX_LINES)\n let text = lines.join(\"\\n\")\n if (byteLength(text) > PI_BRIDGE_MEMORY_INDEX_MAX_BYTES) {\n text = capBytes(text, PI_BRIDGE_MEMORY_INDEX_MAX_BYTES).text\n }\n return text\n}\n\n/** Redact likely secrets before persisting synthesized bridge content. */\nexport function redactSecrets(text: string): string {\n return text\n .replace(/-----BEGIN [A-Z ]*PRIVATE KEY-----[\\s\\S]*?-----END [A-Z ]*PRIVATE KEY-----/g, \"[REDACTED private key]\")\n .replace(/(sk-(live|test)-[A-Za-z0-9_-]{8,})/g, \"[REDACTED]\")\n .replace(/(gh[pousr]_[A-Za-z0-9_]{8,})/g, \"[REDACTED]\")\n .replace(/(xox[baprs]-[A-Za-z0-9-]{8,})/g, \"[REDACTED]\")\n .replace(/eyJ[A-Za-z0-9_-]{8,}\\.[A-Za-z0-9_-]{8,}\\.[A-Za-z0-9_-]{8,}/g, \"[REDACTED jwt]\")\n}\n\nasync function readIfExists(file: string): Promise<string | undefined> {\n try {\n return await fs.readFile(file, \"utf8\")\n } catch {\n return undefined\n }\n}\n\n/**\n * Collect bridge inputs from disk (best-effort). Repo root is the cwd's\n * git top-level when resolvable, else cwd. Only reads files; never writes.\n */\nexport async function collectBridgeInputs(\n cwd = process.cwd(),\n homeDir = os.homedir(),\n): Promise<PiBridgeCollected> {\n const collected: PiBridgeCollected = {\n copilotInstructions: [],\n unscopedRules: [],\n scopedRules: [],\n userGlobal: [],\n imports: [],\n skipped: [],\n }\n // Repo root: walk up for `.git` (cheap, no subprocess).\n let repoRoot = cwd\n try {\n let dir = path.resolve(cwd)\n for (let depth = 0; depth < 12; depth++) {\n try {\n await fs.stat(path.join(dir, \".git\"))\n repoRoot = dir\n break\n } catch {\n const parent = path.dirname(dir)\n if (parent === dir) break\n dir = parent\n }\n }\n } catch {\n repoRoot = cwd\n }\n\n // 1. Repo-wide Copilot instructions (+ `@` expansion later).\n const copilotFile = path.join(repoRoot, \".github\", \"copilot-instructions.md\")\n const copilotBody = await readIfExists(copilotFile)\n const baseForImports: Array<{ file: string; content: string }> = []\n if (copilotBody !== undefined) {\n collected.copilotInstructions.push({ file: copilotFile, content: splitFrontmatter(copilotBody).body })\n baseForImports.push({ file: copilotFile, content: copilotBody })\n }\n\n // 2. Path-specific Copilot instructions (applyTo).\n try {\n const dir = path.join(repoRoot, \".github\", \"instructions\")\n const entries = await fs.readdir(dir)\n for (const name of entries.sort()) {\n if (!name.endsWith(\".instructions.md\")) continue\n const file = path.join(dir, name)\n const raw = await readIfExists(file)\n if (raw === undefined) continue\n const { frontmatter, body } = splitFrontmatter(raw)\n const globs = extractScopeGlobs(frontmatter)\n if (globs.length === 0 || globs.includes(\"**\") || globs.includes(\"**/*\")) {\n collected.unscopedRules.push({ file, content: body })\n } else {\n collected.scopedRules.push({ file, body, globs, source: \"copilot-instructions\" })\n }\n }\n } catch {\n // no instructions dir — not an error\n }\n\n // 3. Claude rules (nearest `.claude/rules` at-or-above cwd).\n try {\n let dir: string | null = null\n let walk = path.resolve(cwd)\n for (let depth = 0; depth < 12; depth++) {\n try {\n await fs.stat(path.join(walk, \".claude\", \"rules\"))\n dir = path.join(walk, \".claude\", \"rules\")\n break\n } catch {\n const parent = path.dirname(walk)\n if (parent === walk) break\n walk = parent\n }\n }\n if (dir) {\n const entries = await fs.readdir(dir)\n for (const name of entries.sort()) {\n if (!name.endsWith(\".md\")) continue\n const file = path.join(dir, name)\n const raw = await readIfExists(file)\n if (raw === undefined) continue\n const { frontmatter, body } = splitFrontmatter(raw)\n if (!body.trim()) {\n collected.skipped.push({ file, reason: \"empty after frontmatter strip\" })\n continue\n }\n const globs = extractScopeGlobs(frontmatter)\n if (globs.length === 0) collected.unscopedRules.push({ file, content: body })\n else collected.scopedRules.push({ file, body, globs, source: \"claude-rules\" })\n }\n }\n } catch {\n // unreadable rules dir — skip\n }\n\n // 4. Alternate project memory `./.claude/CLAUDE.md` (deduped later\n // against Pi-native context; approval-gated by the caller).\n const dotClaude = path.join(repoRoot, \".claude\", \"CLAUDE.md\")\n const dotBody = await readIfExists(dotClaude)\n if (dotBody !== undefined && dotBody.trim()) {\n collected.unscopedRules.push({ file: dotClaude, content: splitFrontmatter(dotBody).body })\n baseForImports.push({ file: dotClaude, content: dotBody })\n }\n\n // 5. User-global files (inlined, capped downstream).\n for (const file of [\n path.join(homeDir, \".claude\", \"CLAUDE.md\"),\n path.join(homeDir, \".copilot\", \"copilot-instructions.md\"),\n ]) {\n const raw = await readIfExists(file)\n if (raw !== undefined && raw.trim()) {\n collected.userGlobal.push({ file, content: splitFrontmatter(raw).body })\n baseForImports.push({ file, content: raw })\n }\n }\n\n // 6. `@` imports across everything collected so far.\n const fileMap = new Map<string, string>()\n for (const group of [collected.copilotInstructions, collected.unscopedRules, collected.userGlobal]) {\n for (const entry of group) {\n try {\n fileMap.set(path.resolve(entry.file), entry.content)\n } catch {\n fileMap.set(entry.file, entry.content)\n }\n }\n }\n // Async BFS over `@` imports (map first, disk fallback). Seeds `seen`\n // with base files so a self-import never re-appends the base body.\n const seen = new Set<string>()\n for (const b of baseForImports) {\n try {\n seen.add(path.resolve(b.file))\n } catch {\n seen.add(b.file)\n }\n }\n const queue: Array<{ importer: string; content: string; depth: number }> = baseForImports.map((b) => ({\n importer: b.file,\n content: b.content,\n depth: 1,\n }))\n while (queue.length > 0 && collected.imports.length < PI_BRIDGE_IMPORT_MAX_FILES) {\n const head = queue.shift()\n if (!head || head.depth > PI_BRIDGE_IMPORT_MAX_DEPTH) continue\n let importerAbs = head.importer\n try {\n importerAbs = path.resolve(head.importer)\n } catch {\n // keep\n }\n const baseDir = path.dirname(importerAbs)\n for (const ref of extractAtImports(head.content)) {\n if (collected.imports.length + seen.size >= PI_BRIDGE_IMPORT_MAX_FILES) break\n let expanded = ref\n if (expanded.startsWith(\"~\")) expanded = path.join(homeDir, expanded.slice(1))\n const abs = path.isAbsolute(expanded) ? path.normalize(expanded) : path.resolve(baseDir, expanded)\n if (seen.has(abs)) continue\n seen.add(abs)\n const hit = fileMap.get(abs) ?? (await readIfExists(abs))\n if (hit === undefined) {\n collected.skipped.push({ file: abs, reason: `import of ${head.importer} not found` })\n continue\n }\n const body = splitFrontmatter(hit).body\n collected.imports.push({ file: abs, content: body })\n queue.push({ importer: abs, content: hit, depth: head.depth + 1 })\n }\n }\n\n return collected\n}\n\n/** Build the static mirror `AGENTS.md` bridge section. */\nexport function buildMirrorBridgeSection(\n collected: PiBridgeCollected,\n opts: { repoRoot?: string } = {},\n): { section: string; stats: PiBridgeStats } {\n const parts: Array<string> = [PI_BRIDGE_FENCE_BEGIN, \"\", \"# gh-router memory bridge\", \"\"]\n let truncated = false\n\n const pushCapped = (title: string, file: string, content: string, budgetLeft: () => number): void => {\n // Strip NUL bytes: a literal U+0000 in synthesized context breaks\n // strict downstream JSON consumers (workflow-preflight parse errors).\n const body = content.replaceAll(\"\\0\", \"\").trim()\n if (!body) return\n const block = `## ${title}\\n<!-- source: ${file} -->\\n\\n${body}\\n`\n const capped = capBytes(block, Math.max(0, budgetLeft()))\n parts.push(capped.text, \"\")\n if (capped.truncated) truncated = true\n }\n let used = byteLength(parts.join(\"\\n\"))\n const budgetLeft = (): number => Math.max(0, PI_BRIDGE_STATIC_BUDGET_BYTES - used - 512)\n const account = (): void => {\n used = byteLength(parts.join(\"\\n\"))\n }\n\n for (const entry of collected.copilotInstructions) {\n pushCapped(\"Copilot repo instructions\", entry.file, entry.content, budgetLeft)\n account()\n }\n for (const entry of collected.unscopedRules) {\n pushCapped(\"Unscoped project rules\", entry.file, entry.content, budgetLeft)\n account()\n }\n for (const entry of collected.userGlobal) {\n pushCapped(\"User-global instructions\", entry.file, entry.content, budgetLeft)\n account()\n }\n for (const entry of collected.imports) {\n pushCapped(\"Imported context (@path)\", entry.file, entry.content, budgetLeft)\n account()\n }\n\n if (collected.scopedRules.length > 0) {\n parts.push(\n \"## Path-scoped rules (lazy)\",\n \"\",\n \"The following rule files apply only to matching paths and are attached\",\n \"when a matching file is read/edited/written (once per session):\",\n \"\",\n )\n for (const rule of collected.scopedRules) {\n parts.push(`- \\`${rule.file.replaceAll(\"\\0\", \"\")}\\` → \\`${rule.globs.join(\", \").replaceAll(\"\\0\", \"\")}\\` (${rule.source.replaceAll(\"\\0\", \"\")})`)\n }\n parts.push(\"\")\n account()\n }\n\n if (opts.repoRoot) parts.push(`<!-- repo: ${opts.repoRoot.replaceAll(\"\\0\", \"\")} -->`, \"\")\n parts.push(PI_BRIDGE_FENCE_END, \"\")\n const section = redactSecrets(parts.join(\"\\n\")).replaceAll(\"\\0\", \"\")\n return {\n section,\n stats: {\n staticFiles:\n collected.copilotInstructions.length + collected.unscopedRules.length + collected.userGlobal.length,\n scopedRules: collected.scopedRules.length,\n imports: collected.imports.length,\n skipped: collected.skipped.length,\n truncated,\n },\n }\n}\n\n/**\n * Merge a bridge section into mirror `AGENTS.md`: append when absent,\n * replace the fenced block when present (idempotent across relaunches).\n */\nexport function mergeBridgeIntoAgentsMd(existing: string | undefined, section: string): string {\n const body = (existing ?? \"\").replace(/\\r\\n/g, \"\\n\")\n if (!body.trim()) return `${section}\\n`\n const begin = body.indexOf(PI_BRIDGE_FENCE_BEGIN)\n const end = body.indexOf(PI_BRIDGE_FENCE_END)\n if (begin !== -1 && end !== -1 && end > begin) {\n const after = body.slice(end + PI_BRIDGE_FENCE_END.length)\n return `${body.slice(0, begin)}${section}${after.startsWith(\"\\n\") ? after : `\\n${after}`}`\n }\n return `${body.endsWith(\"\\n\") ? body : `${body}\\n`}\\n${section}\\n`\n}\n\n/** Resolve the Claude auto-memory index path for a repo (on-demand read). */\nexport function claudeAutoMemoryIndex(homeDir: string, repoRoot: string): string {\n const slug = repoRoot.replace(/^\\//, \"\").replace(/\\//g, \"-\")\n return path.join(homeDir, \".claude\", \"projects\", slug || \"-\", \"memory\", \"MEMORY.md\")\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAa,gCAAgC;AAK7C,MAAa,wBAAwB;AACrC,MAAa,sBAAsB;AAoCnC,SAAS,WAAW,GAAmB;CACrC,OAAO,OAAO,WAAW,GAAG,MAAM;AACpC;AAEA,SAAS,SAAS,GAAW,KAAmD;CAC9E,IAAI,WAAW,CAAC,KAAK,KAAK,OAAO;EAAE,MAAM;EAAG,WAAW;CAAM;CAC7D,IAAI,MAAM;CACV,IAAI,OAAO,EAAE;CACb,OAAO,MAAM,MAAM;EACjB,MAAM,MAAM,KAAK,OAAO,MAAM,QAAQ,CAAC;EACvC,IAAI,WAAW,EAAE,MAAM,GAAG,GAAG,CAAC,KAAK,KAAK,MAAM,MAAM;OAC/C,OAAO;CACd;CACA,OAAO;EAAE,MAAM,GAAG,EAAE,MAAM,GAAG,KAAK,IAAI,GAAG,MAAM,CAAC,CAAC,EAAE;EAA6C,WAAW;CAAK;AAClH;;AAGA,SAAgB,iBAAiB,KAAoD;CACnF,MAAM,aAAa,IAAI,QAAQ,SAAS,IAAI;CAC5C,IAAI,CA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