personal-ai 0.2.1 → 0.2.3
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/SKILL.md +132 -267
- package/dist/entry.mjs +270 -50
- package/dist/entry.mjs.map +1 -1
- package/dist/index.mjs +267 -47
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -1
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["console.spinner","console.spinner","console.spinner"],"sources":["../src/config/paths.ts","../src/config/schema.ts","../src/config/io.ts","../src/utils/slug.ts","../src/utils/frontmatter.ts","../src/raw/add.ts","../src/utils/console.ts","../src/scraper/index.ts","../src/utils/process.ts","../src/search/index.ts","../src/llm/client.ts","../src/prompts/extract.ts","../src/distill/extract.ts","../src/vault/writer.ts","../src/memory/journal.ts","../src/distill/index.ts","../src/prompts/generate.ts","../src/generate/index.ts","../src/profile/compile.ts","../src/connectors/sanitize.ts","../src/connectors/mac/collectors.ts","../src/profile/index.ts"],"sourcesContent":["import os from \"node:os\";\nimport path from \"node:path\";\n\n/** Root data directory for pai */\nexport function getPaiHome(): string {\n return process.env.PAI_HOME ?? path.join(os.homedir(), \".pai\");\n}\n\nexport function getRawDir(): string {\n return path.join(getPaiHome(), \"raw\");\n}\n\nexport function getVaultDir(): string {\n return path.join(getPaiHome(), \"vault\");\n}\n\nexport function getMemoryDir(): string {\n return path.join(getPaiHome(), \"memory\");\n}\n\nexport function getWeeklyDir(): string {\n return path.join(getMemoryDir(), \"weekly\");\n}\n\n/** Get the journal file path for a given date (YYYY-MM-DD) */\nexport function getJournalPath(date: string): string {\n return path.join(getMemoryDir(), `${date}.md`);\n}\n\n/** Get today's date as YYYY-MM-DD */\nexport function getTodayDate(): string {\n return new Date().toISOString().split(\"T\")[0]!;\n}\n\nexport function getSkillsDir(): string {\n return path.join(getPaiHome(), \"skills\", \"profiles\");\n}\n\nexport function getConfigDir(): string {\n return path.join(getPaiHome(), \"config\");\n}\n\nexport function getConfigPath(): string {\n return path.join(getConfigDir(), \"pai.json5\");\n}\n\nexport function getProfilesPath(): string {\n return path.join(getConfigDir(), \"profiles.json5\");\n}\n\nexport function getPreferencesPath(): string {\n return path.join(getConfigDir(), \"preferences.md\");\n}\n\n/** Compiled user profile — the core output of pai */\nexport function getProfilePath(): string {\n return path.join(getPaiHome(), \"profile.md\");\n}\n","import { z } from \"zod\";\n\nexport const QmdConfigSchema = z.object({\n rawCollection: z.string().default(\"raw\"),\n vaultCollection: z.string().default(\"vault\"),\n});\n\nexport const LlmConfigSchema = z.object({\n apiKeyEnv: z.string().default(\"OPENAI_API_KEY\"),\n baseUrl: z.string().optional(),\n cheapModel: z.string().default(\"gpt-4o-mini\"),\n expensiveModel: z.string().default(\"gpt-4o\"),\n});\n\nexport const ScraperConfigSchema = z.object({\n timeout: z.number().default(30_000),\n});\n\nexport const VaultConfigSchema = z.object({\n maxFileTokens: z.number().default(4000),\n warnFileTokens: z.number().default(3000),\n});\n\nexport const PaiConfigSchema = z\n .object({\n version: z.string().default(\"0.1\"),\n qmd: QmdConfigSchema.default(() => QmdConfigSchema.parse({})),\n llm: LlmConfigSchema.default(() => LlmConfigSchema.parse({})),\n scraper: ScraperConfigSchema.default(() => ScraperConfigSchema.parse({})),\n vault: VaultConfigSchema.default(() => VaultConfigSchema.parse({})),\n })\n .strict();\n\nexport type PaiConfig = z.infer<typeof PaiConfigSchema>;\n","import fs from \"node:fs/promises\";\nimport JSON5 from \"json5\";\nimport { PaiConfigSchema, type PaiConfig } from \"./schema.js\";\nimport { getConfigPath, getProfilesPath } from \"./paths.js\";\nimport type { ProfilesConfig } from \"../types.js\";\n\n/** Load and validate pai.json5 config */\nexport async function loadConfig(): Promise<PaiConfig> {\n const configPath = getConfigPath();\n try {\n const raw = await fs.readFile(configPath, \"utf-8\");\n const parsed = JSON5.parse(raw);\n return PaiConfigSchema.parse(parsed);\n } catch (err: unknown) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") {\n // Return defaults if config file doesn't exist\n return PaiConfigSchema.parse({});\n }\n throw err;\n }\n}\n\n/** Load profiles.json5 */\nexport async function loadProfiles(): Promise<ProfilesConfig> {\n const profilesPath = getProfilesPath();\n try {\n const raw = await fs.readFile(profilesPath, \"utf-8\");\n return JSON5.parse(raw) as ProfilesConfig;\n } catch (err: unknown) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") {\n return { profiles: {} };\n }\n throw err;\n }\n}\n\n/** Write config file (with JSON5 formatting) */\nexport async function saveConfig(\n filePath: string,\n content: string,\n): Promise<void> {\n await fs.writeFile(filePath, content, \"utf-8\");\n}\n","/** Generate a URL-safe slug from a title string */\nexport function generateSlug(title: string): string {\n return title\n .toLowerCase()\n .replace(/[^a-z0-9\\s-]/g, \"\") // remove special chars\n .replace(/\\s+/g, \"-\") // spaces to hyphens\n .replace(/-+/g, \"-\") // collapse multiple hyphens\n .replace(/^-|-$/g, \"\") // trim leading/trailing hyphens\n .slice(0, 50); // max 50 chars\n}\n\n/** Generate a timestamped filename: YYYY-MM-DDTHH-MM-{slug}.md */\nexport function generateRawFilename(title: string): string {\n const now = new Date();\n const ts = now\n .toISOString()\n .replace(/:\\d{2}\\.\\d{3}Z$/, \"\")\n .replace(/:/g, \"-\");\n const slug = generateSlug(title) || \"untitled\";\n return `${ts}-${slug}.md`;\n}\n","import matter from \"gray-matter\";\nimport type { RawFrontmatter } from \"../types.js\";\n\n/** Parse a markdown file with frontmatter */\nexport function parseFrontmatter<T = Record<string, unknown>>(\n content: string,\n): { data: T; content: string } {\n const result = matter(content);\n return { data: result.data as T, content: result.content };\n}\n\n/** Stringify data + content into a frontmatter markdown string */\nexport function stringifyFrontmatter(\n data: Record<string, unknown>,\n content: string,\n): string {\n return matter.stringify(content, data);\n}\n\n/** Create a raw file with proper frontmatter */\nexport function createRawFile(\n frontmatter: RawFrontmatter,\n title: string,\n body: string,\n): string {\n const content = `\\n# ${title}\\n\\n${body}\\n`;\n return stringifyFrontmatter(frontmatter as unknown as Record<string, unknown>, content);\n}\n\n/** Update frontmatter fields in a raw file */\nexport function updateRawFrontmatter(\n fileContent: string,\n updates: Partial<RawFrontmatter>,\n): string {\n const { data, content } = parseFrontmatter<RawFrontmatter>(fileContent);\n const updated = { ...data, ...updates };\n return stringifyFrontmatter(updated as unknown as Record<string, unknown>, content);\n}\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { getRawDir } from \"../config/paths.js\";\nimport { generateRawFilename } from \"../utils/slug.js\";\nimport { createRawFile, parseFrontmatter } from \"../utils/frontmatter.js\";\nimport type { CollectorResult, RawFrontmatter } from \"../types.js\";\n\n/** Add plain text content to raw/local/ */\nexport async function addText(\n content: string,\n source: string = \"local\",\n): Promise<string> {\n const title = extractTitle(content);\n const filename = generateRawFilename(title);\n const dir = path.join(getRawDir(), \"local\");\n await fs.mkdir(dir, { recursive: true });\n\n const fm: RawFrontmatter = {\n source,\n timestamp: new Date().toISOString(),\n status: \"pending\",\n };\n\n const fileContent = createRawFile(fm, title, content);\n const filePath = path.join(dir, filename);\n await fs.writeFile(filePath, fileContent, \"utf-8\");\n return filePath;\n}\n\n/** Add a local file's content to raw/local/ */\nexport async function addFile(\n filePath: string,\n source: string = \"local\",\n): Promise<string> {\n const content = await fs.readFile(filePath, \"utf-8\");\n const basename = path.basename(filePath, path.extname(filePath));\n const filename = generateRawFilename(basename);\n const dir = path.join(getRawDir(), \"local\");\n await fs.mkdir(dir, { recursive: true });\n\n const fm: RawFrontmatter = {\n source,\n timestamp: new Date().toISOString(),\n status: \"pending\",\n };\n\n const fileContent = createRawFile(fm, basename, content);\n const outPath = path.join(dir, filename);\n await fs.writeFile(outPath, fileContent, \"utf-8\");\n return outPath;\n}\n\n/** Add URL-scraped content to raw/web/ */\nexport async function addUrl(\n url: string,\n title: string,\n markdown: string,\n): Promise<string> {\n const filename = generateRawFilename(title);\n const dir = path.join(getRawDir(), \"web\");\n await fs.mkdir(dir, { recursive: true });\n\n const fm: RawFrontmatter = {\n source: \"web\",\n timestamp: new Date().toISOString(),\n url,\n status: \"pending\",\n };\n\n const fileContent = createRawFile(fm, title, markdown);\n const filePath = path.join(dir, filename);\n await fs.writeFile(filePath, fileContent, \"utf-8\");\n return filePath;\n}\n\n/**\n * Add or update a connector-scanned entry to raw/connector/{name}/.\n * Uses scan_id in frontmatter for dedup:\n * - If no existing file with same scan_id → create new\n * - If existing file with same content body → skip (\"skipped\")\n * - If existing file with different content → overwrite (\"updated\")\n * Returns \"created\" | \"updated\" | \"skipped\".\n */\nexport async function addConnectorEntry(\n connectorName: string,\n entry: CollectorResult,\n): Promise<\"created\" | \"updated\" | \"skipped\"> {\n const dir = path.join(getRawDir(), \"connector\", connectorName);\n await fs.mkdir(dir, { recursive: true });\n\n const scanId = `${connectorName}/${entry.id}`;\n\n // Check for existing file with same scan_id\n const existingPath = await findByScanId(dir, scanId);\n\n const fm: RawFrontmatter = {\n source: `connector/${connectorName}`,\n timestamp: new Date().toISOString(),\n status: \"pending\",\n scan_id: scanId,\n };\n\n if (existingPath) {\n // Compare content body\n const oldRaw = await fs.readFile(existingPath, \"utf-8\");\n const { content: oldBody } = parseFrontmatter(oldRaw);\n const newBody = `\\n# ${entry.title}\\n\\n${entry.content}\\n`;\n\n if (oldBody.trim() === newBody.trim()) {\n return \"skipped\";\n }\n\n // Overwrite with updated content (preserve filename)\n const fileContent = createRawFile(fm, entry.title, entry.content);\n await fs.writeFile(existingPath, fileContent, \"utf-8\");\n return \"updated\";\n }\n\n // Create new entry\n const filename = generateRawFilename(entry.id);\n const fileContent = createRawFile(fm, entry.title, entry.content);\n const filePath = path.join(dir, filename);\n await fs.writeFile(filePath, fileContent, \"utf-8\");\n return \"created\";\n}\n\n/** Find a raw file in a directory whose frontmatter scan_id matches */\nasync function findByScanId(dir: string, scanId: string): Promise<string | null> {\n try {\n const entries = await fs.readdir(dir);\n for (const name of entries) {\n if (!name.endsWith(\".md\")) continue;\n const filePath = path.join(dir, name);\n const content = await fs.readFile(filePath, \"utf-8\");\n if (content.includes(`scan_id: ${scanId}`) || content.includes(`scan_id: '${scanId}'`)) {\n return filePath;\n }\n }\n } catch {\n // Directory doesn't exist or read error\n }\n return null;\n}\n\n/** List all pending raw files (status: pending) */\nexport async function listPending(): Promise<string[]> {\n const rawDir = getRawDir();\n const pending: string[] = [];\n\n const subdirs = [\"local\", \"web\", \"connector\"];\n for (const sub of subdirs) {\n const dir = path.join(rawDir, sub);\n try {\n const entries = await walkDir(dir);\n for (const entry of entries) {\n if (entry.endsWith(\".md\")) {\n const content = await fs.readFile(entry, \"utf-8\");\n if (content.includes(\"status: pending\")) {\n pending.push(entry);\n }\n }\n }\n } catch {\n // Directory might not exist\n }\n }\n return pending;\n}\n\n/** List all raw files regardless of status */\nexport async function listAll(): Promise<string[]> {\n const rawDir = getRawDir();\n const files: string[] = [];\n\n const subdirs = [\"local\", \"web\", \"connector\"];\n for (const sub of subdirs) {\n const dir = path.join(rawDir, sub);\n try {\n const entries = await walkDir(dir);\n files.push(...entries.filter((e) => e.endsWith(\".md\")));\n } catch {\n // Directory might not exist\n }\n }\n return files;\n}\n\n/** Recursively walk a directory and return file paths */\nasync function walkDir(dir: string): Promise<string[]> {\n const results: string[] = [];\n try {\n const entries = await fs.readdir(dir, { withFileTypes: true });\n for (const entry of entries) {\n const fullPath = path.join(dir, entry.name);\n if (entry.isDirectory()) {\n results.push(...(await walkDir(fullPath)));\n } else {\n results.push(fullPath);\n }\n }\n } catch {\n // Ignore errors (dir doesn't exist, etc.)\n }\n return results;\n}\n\n/** Extract a title from content (first line or first N words) */\nfunction extractTitle(content: string): string {\n const firstLine = content.split(\"\\n\")[0]?.trim() ?? \"\";\n // Remove markdown heading syntax\n const cleaned = firstLine.replace(/^#+\\s*/, \"\");\n if (cleaned.length > 0 && cleaned.length <= 100) {\n return cleaned;\n }\n // Fall back to first 8 words\n return content.split(/\\s+/).slice(0, 8).join(\" \").slice(0, 100) || \"untitled\";\n}\n","import chalk from \"chalk\";\nimport ora, { type Ora } from \"ora\";\n\nexport function log(message: string): void {\n // eslint-disable-next-line no-console\n console.log(message);\n}\n\nexport function info(message: string): void {\n // eslint-disable-next-line no-console\n console.log(chalk.blue(\"ℹ\"), message);\n}\n\nexport function success(message: string): void {\n // eslint-disable-next-line no-console\n console.log(chalk.green(\"✓\"), message);\n}\n\nexport function warn(message: string): void {\n // eslint-disable-next-line no-console\n console.warn(chalk.yellow(\"⚠\"), message);\n}\n\nexport function error(message: string): void {\n // eslint-disable-next-line no-console\n console.error(chalk.red(\"✗\"), message);\n}\n\nexport function spinner(text: string): Ora {\n return ora({ text, color: \"cyan\" }).start();\n}\n\nexport function dim(message: string): string {\n return chalk.dim(message);\n}\n\nexport function bold(message: string): string {\n return chalk.bold(message);\n}\n","import * as console from \"../utils/console.js\";\n\ninterface ScrapeResult {\n url: string;\n title: string;\n markdown: string;\n}\n\n/**\n * Scrape a URL and return title + markdown content.\n * Uses fetch + defuddle for content extraction.\n * Falls back to basic HTML extraction if defuddle is unavailable.\n */\nexport async function scrapeUrl(\n url: string,\n timeout: number = 30_000,\n): Promise<ScrapeResult> {\n // Fetch the HTML\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), timeout);\n\n let html: string;\n try {\n const response = await fetch(url, {\n signal: controller.signal,\n headers: {\n \"User-Agent\":\n \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36\",\n Accept: \"text/html,application/xhtml+xml\",\n },\n });\n if (!response.ok) {\n throw new Error(`HTTP ${response.status}: ${response.statusText}`);\n }\n html = await response.text();\n } finally {\n clearTimeout(timer);\n }\n\n // Try defuddle for content extraction\n try {\n // Dynamic import — gracefully fails if defuddle is not installed\n const defuddleMod = await import(\"defuddle/node\" as string);\n const Defuddle = defuddleMod.Defuddle ?? defuddleMod.default;\n if (Defuddle) {\n const result = new Defuddle(html, { url }).parse();\n const title = result.title || extractTitleFromHtml(html);\n const markdown = result.content\n ? htmlToSimpleMarkdown(result.content)\n : extractTextFromHtml(html);\n return { url, title, markdown };\n }\n } catch {\n console.warn(\"defuddle not available, using basic HTML extraction\");\n }\n\n // Fallback: basic HTML extraction\n const title = extractTitleFromHtml(html);\n const markdown = extractTextFromHtml(html);\n return { url, title, markdown };\n}\n\n/** Extract <title> from HTML */\nfunction extractTitleFromHtml(html: string): string {\n const match = html.match(/<title[^>]*>([^<]+)<\\/title>/i);\n return match?.[1]?.trim() ?? \"Untitled\";\n}\n\n/** Basic HTML to text extraction (fallback) */\nfunction extractTextFromHtml(html: string): string {\n return (\n html\n // Remove script and style blocks\n .replace(/<script[\\s\\S]*?<\\/script>/gi, \"\")\n .replace(/<style[\\s\\S]*?<\\/style>/gi, \"\")\n // Remove HTML tags\n .replace(/<[^>]+>/g, \" \")\n // Decode common entities\n .replace(/&/g, \"&\")\n .replace(/</g, \"<\")\n .replace(/>/g, \">\")\n .replace(/"/g, '\"')\n .replace(/'/g, \"'\")\n .replace(/ /g, \" \")\n // Collapse whitespace\n .replace(/\\s+/g, \" \")\n .trim()\n .slice(0, 10000)\n );\n}\n\n/** Convert simple HTML to markdown */\nfunction htmlToSimpleMarkdown(html: string): string {\n return (\n html\n // Headings\n .replace(/<h1[^>]*>([\\s\\S]*?)<\\/h1>/gi, \"# $1\\n\\n\")\n .replace(/<h2[^>]*>([\\s\\S]*?)<\\/h2>/gi, \"## $1\\n\\n\")\n .replace(/<h3[^>]*>([\\s\\S]*?)<\\/h3>/gi, \"### $1\\n\\n\")\n // Paragraphs\n .replace(/<p[^>]*>([\\s\\S]*?)<\\/p>/gi, \"$1\\n\\n\")\n // Line breaks\n .replace(/<br\\s*\\/?>/gi, \"\\n\")\n // Bold and italic\n .replace(/<strong[^>]*>([\\s\\S]*?)<\\/strong>/gi, \"**$1**\")\n .replace(/<em[^>]*>([\\s\\S]*?)<\\/em>/gi, \"*$1*\")\n // Links\n .replace(/<a[^>]*href=\"([^\"]*)\"[^>]*>([\\s\\S]*?)<\\/a>/gi, \"[$2]($1)\")\n // Lists\n .replace(/<li[^>]*>([\\s\\S]*?)<\\/li>/gi, \"- $1\\n\")\n // Code\n .replace(/<code[^>]*>([\\s\\S]*?)<\\/code>/gi, \"`$1`\")\n .replace(/<pre[^>]*>([\\s\\S]*?)<\\/pre>/gi, \"```\\n$1\\n```\\n\")\n // Remove remaining tags\n .replace(/<[^>]+>/g, \"\")\n // Decode entities\n .replace(/&/g, \"&\")\n .replace(/</g, \"<\")\n .replace(/>/g, \">\")\n .replace(/"/g, '\"')\n .replace(/'/g, \"'\")\n .replace(/ /g, \" \")\n // Clean up whitespace\n .replace(/\\n{3,}/g, \"\\n\\n\")\n .trim()\n );\n}\n","import { execFile } from \"node:child_process\";\n\n/** Execute QMD CLI command and return stdout */\nexport async function execQmd(args: string[]): Promise<string> {\n return new Promise((resolve, reject) => {\n execFile(\"qmd\", args, { encoding: \"utf-8\", timeout: 60_000 }, (err, stdout, stderr) => {\n if (err) {\n const msg = stderr?.trim() || err.message;\n reject(new Error(`qmd ${args[0]} failed: ${msg}`));\n } else {\n resolve(stdout);\n }\n });\n });\n}\n\n/** Check if QMD is available on PATH */\nexport async function isQmdAvailable(): Promise<boolean> {\n try {\n await execQmd([\"status\"]);\n return true;\n } catch {\n return false;\n }\n}\n","import { execFile } from \"node:child_process\";\nimport fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { execQmd, isQmdAvailable } from \"../utils/process.js\";\nimport { getVaultDir, getRawDir } from \"../config/paths.js\";\nimport type { SearchResult } from \"../types.js\";\n\nexport type SearchMode = \"query\" | \"search\" | \"vsearch\";\n\n/**\n * Search with automatic fallback:\n * 1. QMD available → use QMD (query/search/vsearch modes)\n * 2. QMD not available → built-in grep search (keyword matching, no install needed)\n *\n * QMD modes:\n * - \"query\" (default): BM25 + vector + expansion + reranking (~5s, best quality)\n * - \"search\": BM25 keyword (~50ms, fast)\n * - \"vsearch\": Vector similarity only (~2s, semantic)\n *\n * For \"search\" (fast) mode, QMD BM25 doesn't support CJK tokenization,\n * so we supplement with grep to cover Chinese/Japanese/Korean.\n */\nexport async function search(\n query: string,\n collection: string = \"vault\",\n n: number = 5,\n mode: SearchMode = \"query\",\n): Promise<SearchResult[]> {\n // Fallback to built-in search when QMD is not available\n if (!(await isQmdAvailable())) {\n return builtinSearch(query, collection, n);\n }\n\n const stdout = await execQmd([\n mode,\n query,\n \"--collection\",\n collection,\n \"--json\",\n \"-n\",\n String(n),\n ]);\n\n let results = parseSearchResults(stdout);\n\n // BM25 can't tokenize CJK — supplement with grep for fast mode\n if (mode === \"search\" && results.length === 0 && hasCjk(query)) {\n results = await grepFallback(query, collection, n);\n }\n\n return results;\n}\n\n/**\n * Built-in keyword search — zero external dependencies.\n * Reads markdown files and does case-insensitive substring matching.\n * Good enough for small-medium collections (< 10k files).\n */\nasync function builtinSearch(\n query: string,\n collection: string,\n n: number,\n): Promise<SearchResult[]> {\n const baseDir = collection === \"raw\" ? getRawDir() : getVaultDir();\n\n // Try grep first (fast, available on all unix systems)\n const grepResults = await grepFallback(query, collection, n);\n if (grepResults.length > 0) return grepResults;\n\n // Final fallback: pure Node.js file scan (no external tools at all)\n return nodeFsSearch(query, baseDir, collection, n);\n}\n\n/**\n * Pure Node.js file search — absolute zero dependencies.\n * Recursively reads .md files and matches query as case-insensitive substring.\n */\nasync function nodeFsSearch(\n query: string,\n baseDir: string,\n collection: string,\n n: number,\n): Promise<SearchResult[]> {\n const results: SearchResult[] = [];\n const queryLower = query.toLowerCase();\n\n async function walk(dir: string): Promise<void> {\n let entries;\n try {\n entries = await fs.readdir(dir, { withFileTypes: true });\n } catch {\n return;\n }\n for (const entry of entries) {\n if (results.length >= n) return;\n const full = path.join(dir, entry.name);\n if (entry.isDirectory()) {\n await walk(full);\n } else if (entry.name.endsWith(\".md\")) {\n try {\n const content = await fs.readFile(full, \"utf-8\");\n const idx = content.toLowerCase().indexOf(queryLower);\n if (idx !== -1) {\n const snippetStart = Math.max(0, idx - 40);\n const snippetEnd = Math.min(content.length, idx + query.length + 120);\n const snippet = content.slice(snippetStart, snippetEnd).replace(/\\n/g, \" \").trim();\n const titleMatch = content.match(/^#\\s+(.+)/m);\n const relative = path.relative(baseDir, full);\n results.push({\n file: `${collection}/${relative}`,\n title: titleMatch?.[1]?.trim() ?? path.basename(full, \".md\"),\n snippet,\n score: 1.0,\n });\n }\n } catch {\n // Skip unreadable files\n }\n }\n }\n }\n\n await walk(baseDir);\n return results;\n}\n\n/** Parse QMD JSON search output into SearchResult[] */\nfunction parseSearchResults(stdout: string): SearchResult[] {\n try {\n const parsed = JSON.parse(stdout);\n if (!Array.isArray(parsed)) return [];\n return parsed.map((item: Record<string, unknown>) => ({\n file: (item.file as string) ?? \"\",\n title: (item.title as string) ?? undefined,\n snippet:\n (item.snippet as string) ??\n (item.content as string)?.slice(0, 200) ??\n \"\",\n score: item.score as number | undefined,\n }));\n } catch {\n return [];\n }\n}\n\n/** Check if a string contains CJK characters */\nfunction hasCjk(text: string): boolean {\n return /[\\u4e00-\\u9fff\\u3040-\\u30ff\\uac00-\\ud7af]/.test(text);\n}\n\n/**\n * grep fallback for CJK text that BM25 can't tokenize.\n * Runs: grep -rl \"query\" <dir> --include=\"*.md\"\n * Then reads matched files and extracts context.\n */\nasync function grepFallback(\n query: string,\n collection: string,\n n: number,\n): Promise<SearchResult[]> {\n const baseDir = collection === \"raw\" ? getRawDir() : getVaultDir();\n\n // grep -rl: recursive, list filenames only\n const stdout = await new Promise<string>((resolve) => {\n execFile(\n \"grep\",\n [\"-rl\", \"--include=*.md\", query, baseDir],\n { encoding: \"utf-8\", timeout: 5_000 },\n (_err, out) => {\n // grep exits 1 when no matches — that's fine\n resolve(out ?? \"\");\n },\n );\n });\n\n if (!stdout.trim()) return [];\n\n const files = stdout.trim().split(\"\\n\").slice(0, n);\n const results: SearchResult[] = [];\n\n for (const filePath of files) {\n if (!filePath) continue;\n // Get context line with grep -m1 (first match with surrounding text)\n const context = await new Promise<string>((resolve) => {\n execFile(\n \"grep\",\n [\"-m1\", \"-C1\", query, filePath],\n { encoding: \"utf-8\", timeout: 2_000 },\n (_err, out) => resolve(out ?? \"\"),\n );\n });\n\n const snippet = context.replace(/\\n/g, \" \").trim().slice(0, 160);\n const relative = path.relative(baseDir, filePath);\n // Extract title: first H1 line via grep\n const titleLine = await new Promise<string>((resolve) => {\n execFile(\n \"grep\",\n [\"-m1\", \"^# \", filePath],\n { encoding: \"utf-8\", timeout: 1_000 },\n (_err, out) => resolve(out?.replace(/^#\\s+/, \"\").trim() ?? \"\"),\n );\n });\n\n results.push({\n file: `qmd://${collection}/${relative}`,\n title: titleLine || path.basename(filePath, \".md\"),\n snippet,\n score: 1.0,\n });\n }\n\n return results;\n}\n\n/** Update QMD index: runs `qmd update` + `qmd embed` */\nexport async function updateIndex(): Promise<void> {\n if (!(await isQmdAvailable())) {\n throw new Error(\n \"QMD is not installed. Built-in search works without indexing.\\n\" +\n \"For better search quality, install QMD: npm install -g https://github.com/tobi/qmd\",\n );\n }\n await execQmd([\"update\"]);\n await execQmd([\"embed\"]);\n}\n","import fs from \"node:fs/promises\";\nimport OpenAI from \"openai\";\nimport { loadConfig } from \"../config/index.js\";\nimport { getPreferencesPath } from \"../config/paths.js\";\nimport type { PaiConfig } from \"../config/index.js\";\n\nlet cachedConfig: PaiConfig | null = null;\nlet cachedPreferences: string | null = null;\n\nasync function getConfig(): Promise<PaiConfig> {\n if (!cachedConfig) {\n cachedConfig = await loadConfig();\n }\n return cachedConfig;\n}\n\n/** Load user preferences.md (cached per process) */\nasync function getPreferences(): Promise<string> {\n if (cachedPreferences !== null) return cachedPreferences;\n try {\n cachedPreferences = await fs.readFile(getPreferencesPath(), \"utf-8\");\n } catch {\n cachedPreferences = \"\";\n }\n return cachedPreferences;\n}\n\n/** Create an OpenAI-compatible client from config */\nexport async function createLlmClient(): Promise<OpenAI> {\n const config = await getConfig();\n const apiKey = process.env[config.llm.apiKeyEnv];\n if (!apiKey) {\n throw new Error(\n `Missing API key: set ${config.llm.apiKeyEnv} environment variable`,\n );\n }\n return new OpenAI({\n apiKey,\n baseURL: config.llm.baseUrl || undefined,\n });\n}\n\n/**\n * Single LLM call with system + user messages.\n * Automatically prepends user preferences to the system prompt.\n * Retries once on failure.\n */\nexport async function llmCall(\n prompt: string,\n system: string,\n model?: string,\n): Promise<string> {\n const config = await getConfig();\n const client = await createLlmClient();\n const modelName = model ?? config.llm.cheapModel;\n\n // Inject user preferences into system prompt\n const prefs = await getPreferences();\n const fullSystem = prefs\n ? `${system}\\n\\n---USER PREFERENCES (always respect these)---\\n${prefs}`\n : system;\n\n for (let attempt = 0; attempt < 2; attempt++) {\n try {\n const response = await client.chat.completions.create({\n model: modelName,\n messages: [\n { role: \"system\", content: fullSystem },\n { role: \"user\", content: prompt },\n ],\n temperature: 0.3,\n });\n return response.choices[0]?.message?.content ?? \"\";\n } catch (err) {\n if (attempt === 0) {\n // Retry once\n await new Promise((r) => setTimeout(r, 1000));\n continue;\n }\n throw err;\n }\n }\n return \"\"; // unreachable\n}\n\n/** Reset cached config and preferences (for testing) */\nexport function resetConfigCache(): void {\n cachedConfig = null;\n cachedPreferences = null;\n}\n","/** Build system prompt for the PINData extract step (replaces triage + distill) */\nexport function extractSystemPrompt(): string {\n return `Extract PINData entries from the input. Each entry is ONE atomic piece of personal knowledge.\n\nEntry types:\n- fact: concrete data point (name, number, date, account, version, error, relationship)\n- pref: implied choice or habit (tool preference, workflow pattern, interest signal)\n- decision: explicit decision with reasoning\n- entity: person, organization, or project with attributes\n- event: time-bound occurrence (meeting, deployment, payment, conference)\n\nTopic routing (pick the best fit):\n- context/identity — user's name, email, linked accounts\n- context/projects — project/repo/app names, deployments, tech stack\n- context/services — services/tools used, account IDs, subscriptions\n- preferences/tools — tool choices and why (e.g. Vercel for hosting, Airtable for PM)\n- preferences/workflow — work habits, communication style, patterns\n- work/activity — tasks, assignments, colleagues, meetings\n- work/finance — invoices, payments, amounts, subscriptions\n- life/interests — interests, events, communities, conferences\n- coding/lessons — coding lessons, debugging insights, tech decisions\n\nRules:\n- Each entry.content = ONE concrete fact with names/numbers/dates. Never generic advice.\n- Return [] (empty array) if input is pure marketing/spam with zero personal signal.\n- Prefer multiple small entries over one big entry.\n- Do NOT extract generic platitudes like \"monitor deployments regularly\".\n\nExamples:\n\nInput: \"Vercel: Failed deployment for pin-sandman on team pinai\"\nOutput: [\n {\"type\":\"fact\",\"content\":\"pin-sandman: Vercel production deployment failed, team pinai\",\"topic\":\"context/projects\",\"tags\":[\"vercel\",\"pin-sandman\"]},\n {\"type\":\"pref\",\"content\":\"Vercel: used for production deployment\",\"topic\":\"preferences/tools\",\"tags\":[\"vercel\"]}\n]\n\nInput: \"50% off all shoes this weekend only!\"\nOutput: []\n\nRespond with valid JSON array only (no markdown fences).`;\n}\n\n/** Build user prompt for extract */\nexport function extractUserPrompt(rawContent: string, source?: string): string {\n const sourceHint = source ? `\\n(Source: ${source})` : \"\";\n return `Extract PINData entries from this input:\n\n---INPUT---\n${rawContent}\n---END INPUT---\n${sourceHint}\nRespond with JSON array only.`;\n}\n\n/** Build system prompt for the daily digest */\nexport function digestSystemPrompt(): string {\n return `Summarize the day's journal entries and extracted knowledge into 3-5 key bullet points.\n\nRules:\n- Each bullet = one concrete takeaway (what happened, what was decided, what matters)\n- Include names, projects, and specific details — never vague\n- If there are action items or follow-ups, list them\n- Keep it under 200 words total\n- Output plain markdown bullets only, no JSON`;\n}\n\n/** Build user prompt for digest */\nexport function digestUserPrompt(\n journalContent: string,\n newPinData: string,\n date: string,\n): string {\n return `Summarize this day (${date}):\n\n---JOURNAL---\n${journalContent || \"(no journal entries)\"}\n---END JOURNAL---\n\n---NEW KNOWLEDGE EXTRACTED---\n${newPinData || \"(no new entries)\"}\n---END KNOWLEDGE---\n\nWrite 3-5 bullet points summarizing the day.`;\n}\n","import { llmCall } from \"../llm/index.js\";\nimport { extractSystemPrompt, extractUserPrompt } from \"../prompts/extract.js\";\nimport type { PINDataEntry, PINDataType, ExtractResult } from \"../types.js\";\n\nconst VALID_TYPES = new Set<string>([\"fact\", \"pref\", \"decision\", \"entity\", \"event\"]);\n\n/** Extract PINData entries from raw/journal content via a single LLM call */\nexport async function extractPinData(\n content: string,\n source?: string,\n): Promise<ExtractResult> {\n const system = extractSystemPrompt();\n const prompt = extractUserPrompt(content, source);\n\n const response = await llmCall(prompt, system);\n\n try {\n // Strip markdown code fences if present\n const cleaned = response.replace(/```json?\\n?/g, \"\").replace(/```/g, \"\").trim();\n const raw = JSON.parse(cleaned) as unknown;\n\n // Handle both array and object-with-entries responses\n let rawEntries: unknown[];\n if (Array.isArray(raw)) {\n rawEntries = raw;\n } else if (raw && typeof raw === \"object\" && \"entries\" in raw && Array.isArray((raw as Record<string, unknown>).entries)) {\n rawEntries = (raw as Record<string, unknown>).entries as unknown[];\n } else {\n return { entries: [], summary: \"\" };\n }\n\n // Validate and parse each entry\n const entries: PINDataEntry[] = [];\n for (const item of rawEntries) {\n if (!item || typeof item !== \"object\") continue;\n const obj = item as Record<string, unknown>;\n\n const type = obj.type as string;\n const content = obj.content as string;\n const topic = obj.topic as string;\n\n if (!type || !content || !topic) continue;\n if (!VALID_TYPES.has(type)) continue;\n\n entries.push({\n type: type as PINDataType,\n content: content.trim(),\n topic: topic.trim(),\n tags: Array.isArray(obj.tags)\n ? (obj.tags as unknown[]).filter((t): t is string => typeof t === \"string\")\n : undefined,\n });\n }\n\n // Build summary from entries\n const summary =\n entries.length > 0\n ? entries\n .slice(0, 3)\n .map((e) => e.content)\n .join(\"; \")\n : \"no extractable signal\";\n\n return { entries, summary };\n } catch {\n return {\n entries: [],\n summary: `Failed to parse extract response: ${response.slice(0, 100)}`,\n };\n }\n}\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { getVaultDir } from \"../config/paths.js\";\nimport type { PINDataEntry, PINDataType } from \"../types.js\";\n\n/** Format a PINData entry as a markdown bullet line */\nexport function formatEntry(entry: PINDataEntry, date: string, ref?: string): string {\n const parts: string[] = [];\n parts.push(date);\n if (ref) parts.push(`ref:${ref}`);\n const meta = parts.join(\" | \");\n return `- [${entry.type}] ${entry.content} (${meta})`;\n}\n\n/** Parse a PINData line back into structured data */\nexport function parsePinDataLine(line: string): {\n type: PINDataType;\n content: string;\n date?: string;\n verified?: number;\n} | null {\n // Match: - [type] content (date | optional-meta | verified:N)\n const match = line.match(\n /^- \\[(\\w+)\\] (.+?) \\((\\d{4}-\\d{2}-\\d{2})([^)]*)\\)$/,\n );\n if (!match) return null;\n\n const meta = match[4] ?? \"\";\n const verifiedMatch = meta.match(/verified:(\\d+)/);\n\n return {\n type: match[1] as PINDataType,\n content: match[2]!,\n date: match[3],\n verified: verifiedMatch ? parseInt(verifiedMatch[1]!, 10) : undefined,\n };\n}\n\n/** Check if two PINData entries are semantically duplicate (same type + similar content) */\nfunction isDuplicate(existingContent: string, newEntry: PINDataEntry): {\n lineIndex: number;\n line: string;\n} | null {\n const lines = existingContent.split(\"\\n\");\n const newLower = newEntry.content.toLowerCase();\n // Extract key tokens from new entry (remove common words)\n const newTokens = new Set(\n newLower.split(/[\\s:,;]+/).filter((t) => t.length > 2),\n );\n\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i]!;\n // Must match the same type tag\n if (!line.startsWith(`- [${newEntry.type}]`)) continue;\n\n const parsed = parsePinDataLine(line);\n if (!parsed) continue;\n\n const existLower = parsed.content.toLowerCase();\n const existTokens = new Set(\n existLower.split(/[\\s:,;]+/).filter((t) => t.length > 2),\n );\n\n // Calculate Jaccard similarity on significant tokens\n const intersection = [...newTokens].filter((t) => existTokens.has(t));\n const union = new Set([...newTokens, ...existTokens]);\n const similarity = union.size > 0 ? intersection.length / union.size : 0;\n\n // Threshold: 60% token overlap = duplicate\n if (similarity >= 0.6) {\n return { lineIndex: i, line };\n }\n }\n return null;\n}\n\n/**\n * Append PINData entries to the appropriate vault files.\n * - Routes each entry to vault/{topic}.md based on entry.topic\n * - Creates file + H1 header if new\n * - Deduplicates: if similar entry exists, bumps verified count + updates date\n * Returns number of new entries added and duplicates updated.\n */\nexport async function appendPinData(\n entries: PINDataEntry[],\n options: { date?: string; ref?: string } = {},\n): Promise<{ added: number; updated: number }> {\n const vaultDir = getVaultDir();\n const date = options.date ?? new Date().toISOString().split(\"T\")[0]!;\n let added = 0;\n let updated = 0;\n\n // Group entries by topic\n const byTopic = new Map<string, PINDataEntry[]>();\n for (const entry of entries) {\n const topic = entry.topic;\n if (!byTopic.has(topic)) byTopic.set(topic, []);\n byTopic.get(topic)!.push(entry);\n }\n\n for (const [topic, topicEntries] of byTopic) {\n const filePath = path.join(vaultDir, `${topic}.md`);\n await fs.mkdir(path.dirname(filePath), { recursive: true });\n\n // Read existing content\n let content: string;\n try {\n content = await fs.readFile(filePath, \"utf-8\");\n } catch {\n // Create new file with H1 title derived from topic\n const title = topic\n .split(\"/\")\n .pop()!\n .replace(/-/g, \" \")\n .replace(/\\b\\w/g, (c) => c.toUpperCase());\n content = `# ${title}\\n`;\n }\n\n for (const entry of topicEntries) {\n const dup = isDuplicate(content, entry);\n if (dup) {\n // Bump verified count and update date\n const parsed = parsePinDataLine(dup.line);\n const newVerified = (parsed?.verified ?? 1) + 1;\n const updatedLine = `- [${entry.type}] ${entry.content} (${date} | verified:${newVerified})`;\n const lines = content.split(\"\\n\");\n lines[dup.lineIndex] = updatedLine;\n content = lines.join(\"\\n\");\n updated++;\n } else {\n // Append new entry\n const line = formatEntry(entry, date, options.ref);\n content = content.trimEnd() + \"\\n\" + line + \"\\n\";\n added++;\n }\n }\n\n await fs.writeFile(filePath, content, \"utf-8\");\n }\n\n return { added, updated };\n}\n\n/** Read a vault file's content. Returns null if not found. */\nexport async function readVaultFile(topic: string): Promise<string | null> {\n const filePath = path.join(getVaultDir(), `${topic}.md`);\n try {\n return await fs.readFile(filePath, \"utf-8\");\n } catch {\n return null;\n }\n}\n\n/** List all PINData entries across all vault files */\nexport async function listVaultEntries(): Promise<\n Array<{ topic: string; line: string; parsed: ReturnType<typeof parsePinDataLine> }>\n> {\n const vaultDir = getVaultDir();\n const results: Array<{\n topic: string;\n line: string;\n parsed: ReturnType<typeof parsePinDataLine>;\n }> = [];\n\n async function walk(dir: string): Promise<void> {\n try {\n const entries = await fs.readdir(dir, { withFileTypes: true });\n for (const entry of entries) {\n const fullPath = path.join(dir, entry.name);\n if (entry.isDirectory()) {\n await walk(fullPath);\n } else if (entry.name.endsWith(\".md\")) {\n const topic = path.relative(vaultDir, fullPath).replace(/\\.md$/, \"\");\n const content = await fs.readFile(fullPath, \"utf-8\");\n for (const line of content.split(\"\\n\")) {\n if (line.startsWith(\"- [\")) {\n const parsed = parsePinDataLine(line);\n results.push({ topic, line, parsed });\n }\n }\n }\n }\n } catch {\n // Directory might not exist\n }\n }\n\n await walk(vaultDir);\n return results;\n}\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { getMemoryDir, getJournalPath, getTodayDate } from \"../config/paths.js\";\n\n/** Append a log entry to today's journal file (memory/YYYY-MM-DD.md) */\nexport async function appendJournal(\n text: string,\n date?: string,\n): Promise<{ path: string; entryCount: number }> {\n const targetDate = date ?? getTodayDate();\n const filePath = getJournalPath(targetDate);\n\n await fs.mkdir(getMemoryDir(), { recursive: true });\n\n const now = new Date();\n const time = now.toTimeString().slice(0, 5); // HH:MM\n const entry = `- ${time} ${text}\\n`;\n\n let existed = false;\n let existingContent = \"\";\n try {\n existingContent = await fs.readFile(filePath, \"utf-8\");\n existed = true;\n } catch {\n // File doesn't exist yet\n }\n\n if (!existed) {\n // Create new journal file with header\n const header = `# ${targetDate}\\n\\n`;\n await fs.writeFile(filePath, header + entry, \"utf-8\");\n } else {\n // Insert entry BEFORE extracted marker / digest section, and remove marker\n // so the journal will be re-processed on next distill\n const markerIdx = existingContent.indexOf(\"\\n<!-- extracted -->\");\n const digestIdx = existingContent.indexOf(\"\\n## Digest\");\n const insertIdx = Math.min(\n markerIdx >= 0 ? markerIdx : Infinity,\n digestIdx >= 0 ? digestIdx : Infinity,\n );\n\n if (insertIdx < Infinity) {\n // Insert before marker/digest, remove extracted marker\n const before = existingContent.slice(0, insertIdx).trimEnd();\n const after = existingContent.slice(insertIdx).replace(\"<!-- extracted -->\", \"\").trimStart();\n const newContent = before + \"\\n\" + entry + (after ? \"\\n\" + after : \"\") + \"\\n\";\n await fs.writeFile(filePath, newContent, \"utf-8\");\n } else {\n await fs.appendFile(filePath, entry, \"utf-8\");\n }\n }\n\n // Count entries in file\n const content = await fs.readFile(filePath, \"utf-8\");\n const entryCount = (content.match(/^- \\d{2}:\\d{2} /gm) || []).length;\n\n return { path: filePath, entryCount };\n}\n\n/** Read a journal file's content. Returns null if not found. */\nexport async function readJournal(date?: string): Promise<string | null> {\n const targetDate = date ?? getTodayDate();\n const filePath = getJournalPath(targetDate);\n try {\n return await fs.readFile(filePath, \"utf-8\");\n } catch {\n return null;\n }\n}\n\n/** List all journal dates (YYYY-MM-DD) sorted descending */\nexport async function listJournalDates(): Promise<string[]> {\n const memDir = getMemoryDir();\n try {\n const entries = await fs.readdir(memDir);\n const dates = entries\n .filter((f) => /^\\d{4}-\\d{2}-\\d{2}\\.md$/.test(f))\n .map((f) => f.replace(\".md\", \"\"))\n .sort()\n .reverse();\n return dates;\n } catch {\n return [];\n }\n}\n\n/** Get status of a journal: entry count and whether it has a digest */\nexport async function getJournalStatus(\n date: string,\n): Promise<{ entries: number; hasDigest: boolean } | null> {\n const content = await readJournal(date);\n if (!content) return null;\n\n const entries = (content.match(/^- \\d{2}:\\d{2} /gm) || []).length;\n const hasDigest = content.includes(\"## Digest\");\n return { entries, hasDigest };\n}\n\n/** Find journal dates with missing entries in the last N days */\nexport async function findGaps(days: number = 30): Promise<string[]> {\n const existing = new Set(await listJournalDates());\n const gaps: string[] = [];\n\n const now = new Date();\n for (let i = 0; i < days; i++) {\n const d = new Date(now);\n d.setDate(d.getDate() - i);\n const dateStr = d.toISOString().split(\"T\")[0]!;\n if (!existing.has(dateStr)) {\n gaps.push(dateStr);\n }\n }\n\n return gaps;\n}\n\n/** Append a digest section to a journal file */\nexport async function appendDigest(\n digest: string,\n date?: string,\n): Promise<string> {\n const targetDate = date ?? getTodayDate();\n const filePath = getJournalPath(targetDate);\n\n let content: string;\n try {\n content = await fs.readFile(filePath, \"utf-8\");\n } catch {\n // Create the file if it doesn't exist\n content = `# ${targetDate}\\n\\n`;\n }\n\n // Remove existing digest section if present (replace)\n const digestIndex = content.indexOf(\"\\n## Digest\");\n if (digestIndex !== -1) {\n content = content.slice(0, digestIndex);\n }\n\n const digestSection = `\\n## Digest\\n\\n${digest.trim()}\\n`;\n await fs.mkdir(path.dirname(filePath), { recursive: true });\n await fs.writeFile(filePath, content.trimEnd() + \"\\n\" + digestSection, \"utf-8\");\n\n return filePath;\n}\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { listPending } from \"../raw/index.js\";\nimport { extractPinData } from \"./extract.js\";\nimport { appendPinData } from \"../vault/index.js\";\nimport { readJournal } from \"../memory/index.js\";\nimport { getPaiHome, getTodayDate } from \"../config/paths.js\";\nimport { parseFrontmatter, updateRawFrontmatter } from \"../utils/frontmatter.js\";\nimport * as console from \"../utils/console.js\";\nimport type { RawFrontmatter, ExtractPipelineResult } from \"../types.js\";\n\nexport type { ExtractPipelineResult };\n\n/**\n * Run the PINData extract pipeline on pending raw files + unprocessed journals.\n * Flow: raw/journal content → 1 LLM extract call → PINData[] → code-append to vault\n */\nexport async function distillPipeline(\n options: { dryRun?: boolean; singleFile?: string; today?: boolean } = {},\n): Promise<ExtractPipelineResult> {\n const result: ExtractPipelineResult = {\n processed: 0,\n extracted: 0,\n discarded: 0,\n errors: [],\n };\n\n // Collect inputs: pending raw files + today's journal\n const inputs: Array<{ label: string; content: string; rawPath?: string; source: string }> = [];\n\n // 1) Pending raw files\n if (options.singleFile) {\n const raw = await fs.readFile(options.singleFile, \"utf-8\");\n const { content } = parseFrontmatter<RawFrontmatter>(raw);\n inputs.push({\n label: path.basename(options.singleFile),\n content,\n rawPath: options.singleFile,\n source: options.singleFile,\n });\n } else if (!options.today) {\n const pendingFiles = await listPending();\n for (const filePath of pendingFiles) {\n const raw = await fs.readFile(filePath, \"utf-8\");\n const { content } = parseFrontmatter<RawFrontmatter>(raw);\n inputs.push({\n label: path.basename(filePath),\n content,\n rawPath: filePath,\n source: filePath,\n });\n }\n }\n\n // 2) Today's journal (if --today or default run)\n if (!options.singleFile) {\n const todayDate = getTodayDate();\n const journal = await readJournal(todayDate);\n if (journal && journal.trim().length > 0) {\n // Only include if not already processed (check for marker)\n if (!journal.includes(\"<!-- extracted -->\")) {\n inputs.push({\n label: `journal/${todayDate}`,\n content: journal,\n source: `memory/${todayDate}.md`,\n });\n }\n }\n }\n\n if (inputs.length === 0) {\n console.info(\"No pending raw files or journal entries to process.\");\n return result;\n }\n\n console.info(`Found ${inputs.length} input(s) to process.`);\n\n for (const input of inputs) {\n const spin = console.spinner(`Extracting ${input.label}...`);\n\n try {\n // Single LLM call: extract PINData entries\n const extracted = await extractPinData(input.content, input.source);\n result.processed++;\n\n if (extracted.entries.length === 0) {\n spin.succeed(`Skipped: ${input.label} — ${extracted.summary}`);\n result.discarded++;\n\n // Mark raw file as discarded\n if (input.rawPath && !options.dryRun) {\n const rawContent = await fs.readFile(input.rawPath, \"utf-8\");\n const updated = updateRawFrontmatter(rawContent, { status: \"discarded\" });\n await fs.writeFile(input.rawPath, updated, \"utf-8\");\n }\n continue;\n }\n\n if (options.dryRun) {\n const topics = [...new Set(extracted.entries.map((e) => e.topic))];\n spin.succeed(\n `[DRY RUN] ${input.label} → ${extracted.entries.length} entries → ${topics.join(\", \")}`,\n );\n result.extracted += extracted.entries.length;\n continue;\n }\n\n // Code-controlled append to vault files (no LLM merge needed)\n const date = new Date().toISOString().split(\"T\")[0]!;\n const { added, updated } = await appendPinData(extracted.entries, {\n date,\n ref: input.source,\n });\n\n result.extracted += extracted.entries.length;\n const topics = [...new Set(extracted.entries.map((e) => e.topic))];\n\n // Mark raw file as processed\n if (input.rawPath) {\n const rawContent = await fs.readFile(input.rawPath, \"utf-8\");\n const updatedRaw = updateRawFrontmatter(rawContent, {\n status: \"processed\",\n distilled_to: topics.join(\", \"),\n });\n await fs.writeFile(input.rawPath, updatedRaw, \"utf-8\");\n }\n\n // Mark journal as extracted\n if (!input.rawPath && input.source.startsWith(\"memory/\")) {\n const journalPath = path.join(getPaiHome(), input.source);\n try {\n const journalContent = await fs.readFile(journalPath, \"utf-8\");\n if (!journalContent.includes(\"<!-- extracted -->\")) {\n await fs.appendFile(journalPath, \"\\n<!-- extracted -->\\n\", \"utf-8\");\n }\n } catch {\n // Journal file might not exist\n }\n }\n\n spin.succeed(\n `Extracted ${input.label} → ${added} new, ${updated} updated → ${topics.join(\", \")}`,\n );\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n spin.fail(`Error processing ${input.label}: ${msg}`);\n result.errors.push(`${input.label}: ${msg}`);\n }\n }\n\n return result;\n}\n","/** Build system prompt for SKILL.md generation */\nexport function generateSystemPrompt(): string {\n return `You generate a SKILL.md — a minimal, high-density context file for an AI agent to understand the user.\nEvery line MUST be useful to an AI agent. If a line wouldn't change how an agent responds, delete it.\n\nCOMPRESSION RULES:\n- Identity: pack into 2-3 lines max (name | email | role | languages | timezone — merge onto fewer lines)\n- Preferences: write as \"prefers X for Y\" not just \"uses X\". State the WHY or CONTEXT.\n GOOD: \"Deploys on Vercel (team pinai), manages tasks in Airtable, meetings via Zoom (paid)\"\n BAD: \"Tools: Vercel, Zoom, Docker, npm, Airtable\" (just a list, no context)\n- Interests: compress bookmarks/domains/events into TAGS, not raw lists\n GOOD: \"Interests: AI/LLM, Web3 (ETHDenver 2026), GIS, iOS, prediction markets (Kalshi)\"\n BAD: \"Bookmarks: Favorites Bar 106项, Read 78项, Tools 67项...\" (raw data dump)\n- Current Work: what are they ACTIVELY building? Project names + what they do, not directory paths\n GOOD: \"Building personal-ai (v0.1.0, npm published), PINAI ecosystem (PIN-APP-IOS, pin-sandman on Vercel)\"\n BAD: \"Recent Working Directories: ..: 8次, backend: 2次\"\n- Lessons: ONLY copy verbatim lessons that exist in vault/coding/ or vault/work/ files.\n NEVER INVENT OR PARAPHRASE lessons. If the vault has no explicit lesson, write \"None recorded yet.\"\n A deployment failure is a FACT (goes in Current Work), NOT a lesson.\n GOOD: \"FastAPI CORS: must explicitly list allowed_origins, wildcard doesn't work with credentials\"\n BAD: \"生产环境部署失败可能导致项目延误\" ← THIS IS INVENTED, NEVER DO THIS\n BAD: \"及时关注部署通知有助于快速定位问题\" ← THIS IS GENERIC ADVICE, NEVER DO THIS\n- Financial/services: compress into 1-2 lines\n GOOD: \"Paid services: Zoom (acct 5144380543), BytePlus (acct 3000767749, ~200 USD credits)\"\n- Team: mention key collaborators briefly\n GOOD: \"Works with Ethan Liu (pinai team) on Prediction project via Airtable\"\n\nANTI-PATTERNS — never do these:\n- Raw data dumps (bookmark counts, domain visit counts, directory lists)\n- Generic advice disguised as lessons\n- Separate lines for each identity field (merge them)\n- Lists of tool names without context on how/why they're used\n- \"Account Activities\" as a separate section (fold into Preferences or Current Work)`;\n}\n\n/** Build user prompt for SKILL.md generation */\nexport function generateUserPrompt(\n profileName: string,\n vaultContents: string,\n maxLines: number,\n): string {\n return `Generate SKILL.md \"${profileName}\" from vault content. Max ${maxLines} lines.\n\nSections:\n# Personal Context — ${profileName}\n## Who I Am (2-4 lines: identity, languages, timezone — packed dense)\n## Preferences (tool choices WITH context, workflow habits, communication style)\n## Interests (compressed tags from bookmarks/domains/events, NOT raw lists)\n## Current Work (active projects with names, what they do, team members)\n## Paid Services (services with account IDs, amounts — 1-3 lines)\n## Hard-won Lessons (ONLY real lessons from vault, or 1 line \"None yet\")\n\n---VAULT CONTENT---\n${vaultContents}\n---END VAULT CONTENT---\n\nCRITICAL: Compress, don't dump. Every line must be useful to an AI agent.\n- Merge identity fields onto fewer lines (name | email | timezone on one line)\n- Write preferences as \"prefers X for Y\" not bare lists\n- Convert bookmark counts and domain visits into interest TAGS\n- Never write generic advice as lessons\n- Never write raw data (dir paths, bookmark counts, visit numbers)`;\n}\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { minimatch } from \"minimatch\";\nimport { loadProfiles } from \"../config/io.js\";\nimport { getVaultDir, getSkillsDir } from \"../config/paths.js\";\nimport { llmCall } from \"../llm/index.js\";\nimport {\n generateSystemPrompt,\n generateUserPrompt,\n} from \"../prompts/generate.js\";\nimport * as console from \"../utils/console.js\";\n\n/** Recursively list all markdown files in a directory */\nasync function walkMd(dir: string): Promise<string[]> {\n const results: 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 results.push(...(await walkMd(full)));\n } else if (entry.name.endsWith(\".md\")) {\n results.push(full);\n }\n }\n } catch {\n // Ignore errors\n }\n return results;\n}\n\n/** Collect vault file contents matching scope patterns */\nasync function collectVaultContent(scope: string[]): Promise<string> {\n const vaultDir = getVaultDir();\n const allFiles = await walkMd(vaultDir);\n const matched: string[] = [];\n\n for (const file of allFiles) {\n const relative = \"vault/\" + path.relative(vaultDir, file);\n // Check if this file matches any scope pattern\n for (const pattern of scope) {\n if (minimatch(relative, pattern)) {\n matched.push(file);\n break;\n }\n }\n }\n\n // Read and concatenate all matched files\n const contents: string[] = [];\n for (const file of matched) {\n try {\n const content = await fs.readFile(file, \"utf-8\");\n contents.push(`--- ${path.relative(vaultDir, file)} ---\\n${content}`);\n } catch {\n // Skip unreadable files\n }\n }\n\n return contents.join(\"\\n\\n\");\n}\n\n/** Generate a single SKILL.md profile */\nexport async function generateProfile(profileName: string): Promise<string> {\n const profiles = await loadProfiles();\n const profileDef = profiles.profiles[profileName];\n\n if (!profileDef) {\n throw new Error(`Profile \"${profileName}\" not found in profiles.json5`);\n }\n\n const vaultContent = await collectVaultContent(profileDef.scope);\n\n if (!vaultContent.trim()) {\n throw new Error(\n `No vault content found for profile \"${profileName}\". Run 'pai distill' first.`,\n );\n }\n\n const system = generateSystemPrompt();\n const prompt = generateUserPrompt(\n profileName,\n vaultContent,\n profileDef.maxLines,\n );\n\n const skillMd = await llmCall(prompt, system);\n\n // Write to skills/profiles/\n const skillsDir = getSkillsDir();\n await fs.mkdir(skillsDir, { recursive: true });\n const outPath = path.join(skillsDir, `${profileName}.md`);\n await fs.writeFile(outPath, skillMd.trim() + \"\\n\", \"utf-8\");\n\n return outPath;\n}\n\n/** Generate all profiles defined in profiles.json5 */\nexport async function generateAll(): Promise<string[]> {\n const profiles = await loadProfiles();\n const profileNames = Object.keys(profiles.profiles);\n\n if (profileNames.length === 0) {\n console.warn(\"No profiles defined in profiles.json5\");\n return [];\n }\n\n const results: string[] = [];\n for (const name of profileNames) {\n const spin = console.spinner(`Generating profile: ${name}...`);\n try {\n const outPath = await generateProfile(name);\n spin.succeed(`Generated ${name} → ${outPath}`);\n results.push(outPath);\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n spin.fail(`Failed to generate ${name}: ${msg}`);\n }\n }\n\n return results;\n}\n","/**\n * Profile compiler — transforms raw CollectorResult[] into a structured profile.md.\n * Zero LLM dependency: pure template + data formatting.\n */\n\nimport type { CollectorResult } from \"../types.js\";\n\n/** Mapping from collector IDs to profile sections */\ninterface SectionDef {\n heading: string;\n /** Collector IDs that feed this section (in order) */\n collectors: string[];\n}\n\nconst PROFILE_SECTIONS: SectionDef[] = [\n {\n heading: \"Identity\",\n collectors: [\"identity-profile\", \"github-profile\"],\n },\n {\n heading: \"Environment & Tools\",\n collectors: [\"dev-environment\", \"dev-preferences\"],\n },\n {\n heading: \"Work Style & Habits\",\n collectors: [\"shell-habits\", \"coding-rules\"],\n },\n {\n heading: \"Active Projects & Recent Focus\",\n collectors: [\"active-projects\", \"recent-focus\"],\n },\n {\n heading: \"Digital Footprint\",\n collectors: [\"browser-bookmarks\", \"browser-domains\", \"productivity-setup\"],\n },\n {\n heading: \"Registry & Cloud Accounts\",\n collectors: [\"social-profiles\"],\n },\n {\n heading: \"Context\",\n collectors: [\"calendar-context\", \"file-organization\"],\n },\n];\n\n/**\n * Compile CollectorResult[] into a structured profile markdown string.\n * No LLM involved — pure formatting.\n */\nexport function compileProfile(results: CollectorResult[]): string {\n const index = new Map<string, CollectorResult>();\n for (const r of results) {\n index.set(r.id, r);\n }\n\n const sections: string[] = [\"# Personal Profile\", \"\"];\n\n for (const section of PROFILE_SECTIONS) {\n const parts: string[] = [];\n\n for (const cid of section.collectors) {\n const result = index.get(cid);\n if (result?.content?.trim()) {\n parts.push(result.content.trim());\n }\n }\n\n if (parts.length === 0) continue;\n\n sections.push(`## ${section.heading}`, \"\");\n sections.push(parts.join(\"\\n\\n\"));\n sections.push(\"\");\n }\n\n // Append any collectors not covered by the predefined sections\n const coveredIds = new Set(PROFILE_SECTIONS.flatMap((s) => s.collectors));\n const extras: string[] = [];\n\n for (const r of results) {\n if (!coveredIds.has(r.id) && r.content?.trim()) {\n extras.push(`## ${r.title}`, \"\", r.content.trim(), \"\");\n }\n }\n\n if (extras.length > 0) {\n sections.push(...extras);\n }\n\n // Footer\n sections.push(\"---\");\n sections.push(`Last updated: ${new Date().toISOString()}`);\n sections.push(\"\");\n\n return sections.join(\"\\n\");\n}\n\n/**\n * Generate a compact profile summary suitable for agent injection.\n * Strips verbose sub-sections and keeps high-signal data only.\n */\nexport function compileCompactProfile(results: CollectorResult[]): string {\n const index = new Map<string, CollectorResult>();\n for (const r of results) {\n index.set(r.id, r);\n }\n\n const parts: string[] = [\"# Personal Profile (Compact)\", \"\"];\n\n // Identity — always include in full\n const identity = index.get(\"identity-profile\");\n if (identity?.content?.trim()) {\n parts.push(identity.content.trim(), \"\");\n }\n\n // Dev environment — keep runtime versions and package managers\n const devEnv = index.get(\"dev-environment\");\n if (devEnv?.content?.trim()) {\n parts.push(devEnv.content.trim(), \"\");\n }\n\n // Active projects — keep repo list\n const projects = index.get(\"active-projects\");\n if (projects?.content?.trim()) {\n parts.push(projects.content.trim(), \"\");\n }\n\n // Shell habits — keep top commands only\n const habits = index.get(\"shell-habits\");\n if (habits?.content?.trim()) {\n // Take only the first 15 lines (header + top commands)\n const lines = habits.content.trim().split(\"\\n\");\n parts.push(lines.slice(0, 17).join(\"\\n\"), \"\");\n }\n\n parts.push(\"---\");\n parts.push(`Last updated: ${new Date().toISOString()}`);\n parts.push(\"\");\n\n return parts.join(\"\\n\");\n}\n","/**\n * Security sanitization utilities for connector-scanned content.\n * Strips secrets, credentials, and sensitive paths before writing to raw layer.\n */\n\n/** Pattern matching shell export lines containing secrets */\nconst SECRET_EXPORT_RE =\n /^(\\s*export\\s+)\\w*(KEY|TOKEN|SECRET|PASSWORD|CREDENTIAL|PASSWD)\\w*\\s*=.*/i;\n\n/** Pattern matching lines that look like inline secret assignments (no export) */\nconst SECRET_ASSIGN_RE =\n /^\\s*\\w*(KEY|TOKEN|SECRET|PASSWORD|CREDENTIAL|PASSWD)\\w*\\s*=\\s*[\"']?\\S+/i;\n\n/**\n * Strip secret export/assignment lines from shell config content.\n * Preserves comments and non-secret lines intact.\n */\nexport function stripSecretExports(content: string): string {\n return content\n .split(\"\\n\")\n .map((line) => {\n if (SECRET_EXPORT_RE.test(line) || SECRET_ASSIGN_RE.test(line)) {\n return \"# [REDACTED by pai — secret removed]\";\n }\n return line;\n })\n .join(\"\\n\");\n}\n\n/**\n * Strip [credential] sections from git config content.\n * Removes the section header and all lines until the next section.\n */\nexport function stripGitCredentials(content: string): string {\n const lines = content.split(\"\\n\");\n const result: string[] = [];\n let inCredentialSection = false;\n\n for (const line of lines) {\n // Detect section headers like [credential] or [credential \"...\"]\n if (/^\\s*\\[credential/i.test(line)) {\n inCredentialSection = true;\n result.push(\"# [REDACTED by pai — credential section removed]\");\n continue;\n }\n // New section starts → exit credential section\n if (inCredentialSection && /^\\s*\\[/.test(line)) {\n inCredentialSection = false;\n }\n if (!inCredentialSection) {\n result.push(line);\n }\n }\n\n return result.join(\"\\n\");\n}\n\n/**\n * Strip IdentityFile lines from SSH config.\n * Keeps Host, HostName, User, Port — removes key paths.\n */\nexport function stripSshIdentityFiles(content: string): string {\n return content\n .split(\"\\n\")\n .map((line) => {\n if (/^\\s*IdentityFile\\s/i.test(line)) {\n return \" # [REDACTED by pai — IdentityFile removed]\";\n }\n return line;\n })\n .join(\"\\n\");\n}\n","/**\n * Mac system context collectors.\n * Each collector gathers a specific category of personalized context\n * from the local macOS environment and returns a CollectorResult.\n */\n\nimport { execFile } from \"node:child_process\";\nimport fs from \"node:fs/promises\";\nimport os from \"node:os\";\nimport path from \"node:path\";\nimport type { CollectorResult } from \"../../types.js\";\nimport {\n stripSecretExports,\n stripGitCredentials,\n stripSshIdentityFiles,\n} from \"../sanitize.js\";\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\n/** Run a shell command and return stdout (empty string on failure) */\nasync function exec(cmd: string, args: string[]): Promise<string> {\n return new Promise((resolve) => {\n execFile(cmd, args, { encoding: \"utf-8\", timeout: 15_000 }, (err, stdout) => {\n resolve(err ? \"\" : stdout.trim());\n });\n });\n}\n\n/** Read a file, return empty string on failure */\nasync function readSafe(filePath: string): Promise<string> {\n try {\n return await fs.readFile(filePath, \"utf-8\");\n } catch {\n return \"\";\n }\n}\n\n/** Check if path exists */\nasync function exists(p: string): Promise<boolean> {\n try {\n await fs.access(p);\n return true;\n } catch {\n return false;\n }\n}\n\n/** Run osascript and return output */\nasync function osascript(script: string): Promise<string> {\n return exec(\"osascript\", [\"-e\", script]);\n}\n\n/** Run defaults read and return output */\nasync function defaultsRead(...args: string[]): Promise<string> {\n return exec(\"defaults\", [\"read\", ...args]);\n}\n\nconst HOME = os.homedir();\n\n// ---------------------------------------------------------------------------\n// 1. Identity Profile\n// ---------------------------------------------------------------------------\n\nexport async function collectIdentityProfile(): Promise<CollectorResult> {\n const lines: string[] = [\"## User Identity\"];\n\n // macOS username\n const username = await exec(\"id\", [\"-un\"]);\n if (username) lines.push(`- macOS Username: ${username}`);\n\n // Real name from directory service\n const realName = await exec(\"dscl\", [\".\", \"-read\", `/Users/${username}`, \"RealName\"]);\n const nameMatch = realName.split(\"\\n\").find((l) => l.trim() && !l.includes(\"RealName\"));\n if (nameMatch?.trim()) lines.push(`- Real Name (local): ${nameMatch.trim()}`);\n\n // Apple ID / iCloud\n const mobileMe = await defaultsRead(\"MobileMeAccounts\");\n const appleIdMatch = mobileMe.match(/AccountID\\s*=\\s*\"?([^\";\\n]+)/);\n const displayNameMatch = mobileMe.match(/DisplayName\\s*=\\s*\"?([^\";\\n]+)/);\n if (displayNameMatch) lines.push(`- Apple ID Display Name: ${displayNameMatch[1].trim()}`);\n if (appleIdMatch) lines.push(`- Apple ID: ${appleIdMatch[1].trim()}`);\n\n // Computer name\n const computerName = await exec(\"scutil\", [\"--get\", \"ComputerName\"]);\n if (computerName) lines.push(`- Computer Name: ${computerName}`);\n\n // Git identity\n const gitName = await exec(\"git\", [\"config\", \"--global\", \"user.name\"]);\n const gitEmail = await exec(\"git\", [\"config\", \"--global\", \"user.email\"]);\n if (gitName) lines.push(`- Git Name: ${gitName}`);\n if (gitEmail) lines.push(`- Git Email: ${gitEmail}`);\n\n // Locale & Language\n lines.push(\"\", \"## Locale & Language\");\n const langs = await defaultsRead(\"NSGlobalDomain\", \"AppleLanguages\");\n const langList = langs.match(/\"([^\"]+)\"/g)?.map((s) => s.replace(/\"/g, \"\")) ?? [];\n if (langList.length > 0) lines.push(`- Languages: ${langList.join(\", \")}`);\n\n const locale = await defaultsRead(\"NSGlobalDomain\", \"AppleLocale\");\n if (locale) lines.push(`- Locale: ${locale}`);\n\n // Input methods\n const inputSources = await defaultsRead(\"com.apple.HIToolbox\", \"AppleSelectedInputSources\");\n const inputMethods = inputSources.match(/\"Input Mode\"\\s*=\\s*\"([^\"]+)\"/g) ?? [];\n const bundleIds = inputSources.match(/\"Bundle ID\"\\s*=\\s*\"([^\"]+)\"/g) ?? [];\n const inputs = [...inputMethods, ...bundleIds]\n .map((s) => s.replace(/.*\"([^\"]+)\"$/, \"$1\"))\n .filter((s) => !s.includes(\"PressAndHold\"));\n if (inputs.length > 0) lines.push(`- Input Methods: ${inputs.join(\", \")}`);\n\n // System appearance\n const appearance = await defaultsRead(\"-g\", \"AppleInterfaceStyle\");\n lines.push(`- System Appearance: ${appearance || \"Light\"}`);\n\n // Timezone\n const tz = Intl.DateTimeFormat().resolvedOptions().timeZone;\n lines.push(`- Timezone: ${tz}`);\n\n return {\n id: \"identity-profile\",\n title: \"Mac User Identity Profile\",\n content: lines.join(\"\\n\"),\n };\n}\n\n// ---------------------------------------------------------------------------\n// 2. Calendar Context\n// ---------------------------------------------------------------------------\n\nexport async function collectCalendarContext(): Promise<CollectorResult> {\n let calNames: string[] = [];\n const raw = await osascript(\n 'tell application \"Calendar\" to get name of every calendar',\n );\n if (raw) {\n calNames = raw.split(\", \").map((s) => s.trim()).filter(Boolean);\n }\n\n const lines = [\n \"## Calendar Subscriptions\",\n \"\",\n `Total calendars: ${calNames.length}`,\n \"\",\n ...calNames.map((name) => `- ${name}`),\n ];\n\n return {\n id: \"calendar-context\",\n title: \"Calendar Context\",\n content: calNames.length > 0\n ? lines.join(\"\\n\")\n : \"No calendar data accessible (Calendar app may not be running).\",\n };\n}\n\n// ---------------------------------------------------------------------------\n// 3. File Organization\n// ---------------------------------------------------------------------------\n\nexport async function collectFileOrganization(): Promise<CollectorResult> {\n const lines: string[] = [];\n\n // Documents top-level folders\n const docsDir = path.join(HOME, \"Documents\");\n try {\n const entries = await fs.readdir(docsDir, { withFileTypes: true });\n const dirs = entries.filter((e) => e.isDirectory()).map((e) => e.name);\n lines.push(\"## Documents Folders\", \"\", ...dirs.map((d) => `- ${d}`));\n } catch {\n lines.push(\"## Documents Folders\", \"\", \"(not accessible)\");\n }\n\n // Desktop items\n const desktopDir = path.join(HOME, \"Desktop\");\n try {\n const entries = await fs.readdir(desktopDir);\n lines.push(\"\", \"## Desktop Items\", \"\", ...entries.slice(0, 20).map((e) => `- ${e}`));\n if (entries.length > 20) lines.push(`- ... and ${entries.length - 20} more`);\n } catch {\n lines.push(\"\", \"## Desktop Items\", \"\", \"(not accessible)\");\n }\n\n // Recent downloads (file names only)\n const dlDir = path.join(HOME, \"Downloads\");\n try {\n const entries = await fs.readdir(dlDir);\n // Sort by name only (stat would be slow), take first 15\n lines.push(\n \"\",\n \"## Recent Downloads (latest 15 by name)\",\n \"\",\n ...entries.slice(0, 15).map((e) => `- ${e}`),\n );\n } catch {\n lines.push(\"\", \"## Recent Downloads\", \"\", \"(not accessible)\");\n }\n\n return {\n id: \"file-organization\",\n title: \"File Organization Structure\",\n content: lines.join(\"\\n\"),\n };\n}\n\n// ---------------------------------------------------------------------------\n// 4. Dev Environment\n// ---------------------------------------------------------------------------\n\nexport async function collectDevEnvironment(): Promise<CollectorResult> {\n const lines: string[] = [\"## Runtime Versions\"];\n\n // Language runtimes\n const runtimes: [string, string, string[]][] = [\n [\"Node.js\", \"node\", [\"--version\"]],\n [\"Python\", \"python3\", [\"--version\"]],\n [\"Go\", \"go\", [\"version\"]],\n [\"Rust\", \"rustc\", [\"--version\"]],\n [\"Java\", \"java\", [\"--version\"]],\n ];\n\n for (const [name, cmd, args] of runtimes) {\n const ver = await exec(cmd, args);\n if (ver) {\n // Extract just the version string\n const first = ver.split(\"\\n\")[0] ?? ver;\n lines.push(`- ${name}: ${first}`);\n }\n }\n\n // Package managers\n lines.push(\"\", \"## Package Managers\");\n const pkgMgrs = [\"brew\", \"pnpm\", \"npm\", \"pip3\", \"cargo\"];\n for (const pm of pkgMgrs) {\n const which = await exec(\"which\", [pm]);\n if (which) lines.push(`- ${pm}: ${which}`);\n }\n\n // Docker\n const docker = await exec(\"docker\", [\"--version\"]);\n if (docker) lines.push(\"\", \"## Docker\", \"\", `- ${docker}`);\n\n // Shell info\n lines.push(\"\", \"## Shell\");\n const shell = process.env.SHELL ?? \"\";\n lines.push(`- Shell: ${shell}`);\n const zshrc = await readSafe(path.join(HOME, \".zshrc\"));\n const themeMatch = zshrc.match(/^ZSH_THEME=\"?([^\"\\n]+)/m);\n const pluginsMatch = zshrc.match(/^plugins=\\(([^)]+)\\)/m);\n if (themeMatch) lines.push(`- Oh-My-Zsh Theme: ${themeMatch[1]}`);\n if (pluginsMatch) lines.push(`- Oh-My-Zsh Plugins: ${pluginsMatch[1].trim()}`);\n\n // Global npm packages\n const npmGlobal = await exec(\"npm\", [\"list\", \"-g\", \"--depth=0\"]);\n if (npmGlobal) {\n const pkgs = npmGlobal\n .split(\"\\n\")\n .filter((l) => l.startsWith(\"├\") || l.startsWith(\"└\"))\n .map((l) => l.replace(/^[├└─┬│\\s]+/, \"\").trim())\n .filter(Boolean);\n if (pkgs.length > 0) {\n lines.push(\"\", \"## Global npm Packages\", \"\", ...pkgs.map((p) => `- ${p}`));\n }\n }\n\n // Homebrew casks (installed apps via brew)\n const casks = await exec(\"brew\", [\"list\", \"--cask\"]);\n if (casks) {\n const caskList = casks.split(\"\\n\").filter(Boolean);\n lines.push(\"\", \"## Homebrew Casks\", \"\", ...caskList.map((c) => `- ${c}`));\n }\n\n return {\n id: \"dev-environment\",\n title: \"Development Environment\",\n content: lines.join(\"\\n\"),\n };\n}\n\n// ---------------------------------------------------------------------------\n// 5. Dev Preferences\n// ---------------------------------------------------------------------------\n\nexport async function collectDevPreferences(): Promise<CollectorResult> {\n const lines: string[] = [];\n\n // Shell aliases (sanitized)\n const zshrc = await readSafe(path.join(HOME, \".zshrc\"));\n if (zshrc) {\n const sanitized = stripSecretExports(zshrc);\n const aliases = sanitized\n .split(\"\\n\")\n .filter((l) => l.match(/^\\s*alias\\s/));\n if (aliases.length > 0) {\n lines.push(\"## Shell Aliases\", \"\", ...aliases);\n }\n\n // PATH additions\n const pathLines = sanitized\n .split(\"\\n\")\n .filter((l) => l.match(/^\\s*export\\s+PATH/) && !l.includes(\"REDACTED\"));\n if (pathLines.length > 0) {\n lines.push(\"\", \"## PATH Additions\", \"\", ...pathLines);\n }\n }\n\n // Git config (sanitized)\n const gitconfigPath = path.join(HOME, \".gitconfig\");\n const gitconfig = await readSafe(gitconfigPath);\n if (gitconfig) {\n const sanitized = stripGitCredentials(gitconfig);\n lines.push(\"\", \"## Git Config\", \"\", \"```\", sanitized.trim(), \"```\");\n }\n\n // Git aliases\n const gitAliases = await exec(\"git\", [\"config\", \"--global\", \"--get-regexp\", \"alias\"]);\n if (gitAliases) {\n lines.push(\"\", \"## Git Aliases\", \"\", ...gitAliases.split(\"\\n\").map((l) => `- ${l}`));\n }\n\n // Default branch\n const defaultBranch = await exec(\"git\", [\"config\", \"--global\", \"init.defaultBranch\"]);\n if (defaultBranch) lines.push(\"\", `## Default Git Branch: ${defaultBranch}`);\n\n // Cursor extensions\n const extDir = path.join(HOME, \".cursor\", \"extensions\");\n try {\n const entries = await fs.readdir(extDir);\n const exts = entries.filter((e) => !e.startsWith(\".\") && e !== \"extensions.json\");\n if (exts.length > 0) {\n lines.push(\"\", \"## Cursor Extensions\", \"\", ...exts.map((e) => `- ${e}`));\n }\n } catch {\n // No Cursor extensions dir\n }\n\n return {\n id: \"dev-preferences\",\n title: \"Development Preferences\",\n content: lines.join(\"\\n\"),\n };\n}\n\n// ---------------------------------------------------------------------------\n// 6. Shell Habits\n// ---------------------------------------------------------------------------\n\nexport async function collectShellHabits(): Promise<CollectorResult> {\n const histPath = path.join(HOME, \".zsh_history\");\n const raw = await readSafe(histPath);\n\n if (!raw) {\n return {\n id: \"shell-habits\",\n title: \"Shell Command Habits\",\n content: \"No zsh history found.\",\n };\n }\n\n const rawLines = raw.split(\"\\n\");\n const totalEntries = rawLines.length;\n\n // Parse commands: zsh history format is `: timestamp:0;command`\n const freq = new Map<string, number>();\n for (const line of rawLines) {\n // Strip zsh extended history prefix\n const cmd = line.replace(/^:\\s*\\d+:\\d+;/, \"\").trim();\n const firstWord = cmd.split(/\\s+/)[0];\n if (firstWord && firstWord.length > 0 && firstWord.length < 50) {\n freq.set(firstWord, (freq.get(firstWord) ?? 0) + 1);\n }\n }\n\n const top30 = [...freq.entries()]\n .sort((a, b) => b[1] - a[1])\n .slice(0, 30);\n\n const lines = [\n `Total history entries: ${totalEntries}`,\n \"\",\n \"## Most Used Commands (Top 30)\",\n \"\",\n ...top30.map(([cmd, count]) => `- ${cmd}: ${count} times`),\n ];\n\n return {\n id: \"shell-habits\",\n title: \"Shell Command Habits\",\n content: lines.join(\"\\n\"),\n };\n}\n\n// ---------------------------------------------------------------------------\n// 7. Coding Rules\n// ---------------------------------------------------------------------------\n\nexport async function collectCodingRules(): Promise<CollectorResult> {\n const sections: string[] = [];\n\n // Global CLAUDE.md files\n const claudePaths = [\n path.join(HOME, \"CLAUDE.md\"),\n path.join(HOME, \".claude\", \"CLAUDE.md\"),\n ];\n\n for (const p of claudePaths) {\n const content = await readSafe(p);\n if (content) {\n const relPath = p.replace(HOME, \"~\");\n sections.push(`## ${relPath}`, \"\", content.trim(), \"\");\n }\n }\n\n // Claude custom commands\n const cmdDir = path.join(HOME, \".claude\", \"commands\");\n try {\n const entries = await fs.readdir(cmdDir);\n const mdFiles = entries.filter((e) => e.endsWith(\".md\"));\n if (mdFiles.length > 0) {\n sections.push(\"## Claude Custom Commands\", \"\");\n for (const f of mdFiles) {\n const content = await readSafe(path.join(cmdDir, f));\n if (content) {\n sections.push(`### ${f}`, \"\", content.trim(), \"\");\n }\n }\n }\n } catch {\n // No commands dir\n }\n\n // Scan active project repos for CLAUDE.md / AGENTS.md / .cursorrules\n const activeRepos = await findRecentGitRepos(30);\n const projectRules: string[] = [];\n\n for (const repo of activeRepos.slice(0, 10)) {\n // Only scan top 10 most recent\n for (const ruleFile of [\"CLAUDE.md\", \"AGENTS.md\", \".cursorrules\"]) {\n const rulePath = path.join(repo, ruleFile);\n const content = await readSafe(rulePath);\n if (content && content.length > 10) {\n const repoName = path.basename(repo);\n projectRules.push(\n `### ${repoName}/${ruleFile}`,\n \"\",\n content.trim().slice(0, 2000), // Cap at 2000 chars per file\n \"\",\n );\n }\n }\n }\n\n if (projectRules.length > 0) {\n sections.push(\"## Project-Level Rules\", \"\", ...projectRules);\n }\n\n // Cursor rules directory\n const cursorRulesDir = path.join(HOME, \".cursor\", \"rules\");\n try {\n const entries = await fs.readdir(cursorRulesDir);\n const mdFiles = entries.filter((e) => e.endsWith(\".md\") || e.endsWith(\".mdc\"));\n if (mdFiles.length > 0) {\n sections.push(\"## Global Cursor Rules\", \"\");\n for (const f of mdFiles) {\n const content = await readSafe(path.join(cursorRulesDir, f));\n if (content) {\n sections.push(`### ${f}`, \"\", content.trim().slice(0, 1000), \"\");\n }\n }\n }\n } catch {\n // No cursor rules dir\n }\n\n return {\n id: \"coding-rules\",\n title: \"Coding Rules and AI Agent Config\",\n content: sections.length > 0\n ? sections.join(\"\\n\")\n : \"No coding rules found.\",\n };\n}\n\n// ---------------------------------------------------------------------------\n// 8. Active Projects\n// ---------------------------------------------------------------------------\n\nexport async function collectActiveProjects(): Promise<CollectorResult> {\n const lines: string[] = [];\n\n // Recent git repos\n const repos = await findRecentGitRepos(30);\n if (repos.length > 0) {\n lines.push(\"## Active Git Repositories (last 30 days)\", \"\");\n for (const repo of repos) {\n const name = repo.replace(HOME, \"~\");\n lines.push(`- ${name}`);\n }\n }\n\n // SSH config hosts\n const sshConfig = await readSafe(path.join(HOME, \".ssh\", \"config\"));\n if (sshConfig) {\n const sanitized = stripSshIdentityFiles(sshConfig);\n const hosts = sanitized\n .split(\"\\n\")\n .filter((l) => /^\\s*Host\\s/i.test(l) && !l.includes(\"*\"))\n .map((l) => l.replace(/^\\s*Host\\s+/i, \"\").trim());\n if (hosts.length > 0) {\n lines.push(\"\", \"## SSH Hosts\", \"\", ...hosts.map((h) => `- ${h}`));\n }\n }\n\n // Cloud storage\n const cloudDir = path.join(HOME, \"Library\", \"CloudStorage\");\n try {\n const entries = await fs.readdir(cloudDir);\n if (entries.length > 0) {\n lines.push(\"\", \"## Cloud Storage\", \"\", ...entries.map((e) => `- ${e}`));\n }\n } catch {\n // No cloud storage\n }\n\n return {\n id: \"active-projects\",\n title: \"Active Projects and Infrastructure\",\n content: lines.join(\"\\n\"),\n };\n}\n\n// ---------------------------------------------------------------------------\n// 9. Productivity Setup\n// ---------------------------------------------------------------------------\n\nexport async function collectProductivitySetup(): Promise<CollectorResult> {\n const lines: string[] = [];\n\n // Installed applications\n try {\n const entries = await fs.readdir(\"/Applications\");\n const apps = entries\n .filter((e) => e.endsWith(\".app\"))\n .map((e) => e.replace(\".app\", \"\"));\n lines.push(\"## Installed Applications\", \"\", ...apps.map((a) => `- ${a}`));\n } catch {\n lines.push(\"## Installed Applications\", \"\", \"(not accessible)\");\n }\n\n // Dock persistent apps\n const dockApps = await defaultsRead(\"com.apple.dock\", \"persistent-apps\");\n if (dockApps) {\n const labels = [...dockApps.matchAll(/\"file-label\"\\s*=\\s*\"?([^\";\\n}]+)/g)]\n .map((m) => m[1].trim())\n .filter(Boolean);\n if (labels.length > 0) {\n lines.push(\"\", \"## Dock Apps (pinned)\", \"\", ...labels.map((a) => `- ${a}`));\n }\n }\n\n // Default browser\n const handlers = await defaultsRead(\n \"com.apple.LaunchServices/com.apple.launchservices.secure\",\n \"LSHandlers\",\n );\n const browserMatch = handlers.match(/LSHandlerRoleAll\\s*=\\s*\"([^\"]+)\"/);\n if (browserMatch) {\n const bundleId = browserMatch[1];\n const browserName = bundleId.includes(\"edge\")\n ? \"Microsoft Edge\"\n : bundleId.includes(\"chrome\")\n ? \"Google Chrome\"\n : bundleId.includes(\"firefox\")\n ? \"Firefox\"\n : bundleId.includes(\"safari\")\n ? \"Safari\"\n : bundleId;\n lines.push(\"\", `## Default Browser: ${browserName}`);\n }\n\n // Screen resolution\n const displayInfo = await exec(\"system_profiler\", [\"SPDisplaysDataType\"]);\n const resolutions = [...displayInfo.matchAll(/Resolution:\\s*(.+)/g)].map((m) => m[1].trim());\n if (resolutions.length > 0) {\n lines.push(\"\", \"## Screen Resolution\", \"\", ...resolutions.map((r) => `- ${r}`));\n }\n\n return {\n id: \"productivity-setup\",\n title: \"Productivity Setup\",\n content: lines.join(\"\\n\"),\n };\n}\n\n// ---------------------------------------------------------------------------\n// 10. Browser Bookmarks\n// ---------------------------------------------------------------------------\n\nexport async function collectBrowserBookmarks(): Promise<CollectorResult> {\n const bmPath = path.join(\n HOME,\n \"Library\",\n \"Application Support\",\n \"Microsoft Edge\",\n \"Default\",\n \"Bookmarks\",\n );\n\n const raw = await readSafe(bmPath);\n if (!raw) {\n return {\n id: \"browser-bookmarks\",\n title: \"Browser Bookmark Structure\",\n content: \"No Edge bookmarks found.\",\n };\n }\n\n try {\n const data = JSON.parse(raw);\n const folders: { name: string; count: number; depth: number }[] = [];\n let totalUrls = 0;\n\n function walk(\n node: Record<string, unknown>,\n depth: number,\n ): void {\n if (node.type === \"folder\") {\n const children = (node.children ?? []) as Record<string, unknown>[];\n const name = (node.name as string) ?? \"\";\n if (children.length > 0) {\n folders.push({ name, count: children.length, depth });\n }\n for (const child of children) {\n walk(child, depth + 1);\n }\n } else if (node.type === \"url\") {\n totalUrls++;\n }\n }\n\n const roots = data.roots as Record<string, unknown>;\n for (const root of Object.values(roots)) {\n if (root && typeof root === \"object\" && \"children\" in (root as Record<string, unknown>)) {\n walk(root as Record<string, unknown>, 0);\n }\n }\n\n // Sort by count descending\n folders.sort((a, b) => b.count - a.count);\n\n const lines = [\n `Total bookmarks: ${totalUrls}`,\n `Total folders: ${folders.length}`,\n \"\",\n \"## Top Bookmark Folders (by item count)\",\n \"\",\n ...folders.slice(0, 40).map((f) => `- ${\" \".repeat(Math.min(f.depth, 2))}${f.name}: ${f.count} items`),\n ];\n\n return {\n id: \"browser-bookmarks\",\n title: \"Browser Bookmark Structure\",\n content: lines.join(\"\\n\"),\n };\n } catch {\n return {\n id: \"browser-bookmarks\",\n title: \"Browser Bookmark Structure\",\n content: \"Failed to parse Edge bookmarks.\",\n };\n }\n}\n\n// ---------------------------------------------------------------------------\n// 11. Browser Domains\n// ---------------------------------------------------------------------------\n\nexport async function collectBrowserDomains(): Promise<CollectorResult> {\n const histPath = path.join(\n HOME,\n \"Library\",\n \"Application Support\",\n \"Microsoft Edge\",\n \"Default\",\n \"History\",\n );\n\n if (!(await exists(histPath))) {\n return {\n id: \"browser-domains\",\n title: \"Browser Top Domains (30 days)\",\n content: \"No Edge history found.\",\n };\n }\n\n // Copy the locked DB to a temp file for reading\n const tmpDb = path.join(os.tmpdir(), `pai-edge-history-${Date.now()}.db`);\n try {\n await fs.copyFile(histPath, tmpDb);\n\n const query = `\n SELECT\n REPLACE(REPLACE(SUBSTR(url, 1, INSTR(SUBSTR(url, 9), '/') + 8), 'https://', ''), 'http://', '') as domain,\n COUNT(*) as visits\n FROM urls\n WHERE last_visit_time > (strftime('%s', 'now', '-30 days') + 11644473600) * 1000000\n GROUP BY domain\n ORDER BY visits DESC\n LIMIT 30;\n `.trim();\n\n const output = await exec(\"sqlite3\", [tmpDb, query]);\n\n if (!output) {\n return {\n id: \"browser-domains\",\n title: \"Browser Top Domains (30 days)\",\n content: \"Could not query Edge history (DB may be locked).\",\n };\n }\n\n const lines = [\n \"## Top 30 Domains (last 30 days)\",\n \"\",\n ...output.split(\"\\n\").map((line) => {\n const [domain, visits] = line.split(\"|\");\n return `- ${domain}: ${visits} visits`;\n }),\n ];\n\n return {\n id: \"browser-domains\",\n title: \"Browser Top Domains (30 days)\",\n content: lines.join(\"\\n\"),\n };\n } finally {\n try {\n await fs.unlink(tmpDb);\n } catch {\n // Cleanup failure is ok\n }\n }\n}\n\n// ---------------------------------------------------------------------------\n// 12. GitHub Profile\n// ---------------------------------------------------------------------------\n\nexport async function collectGitHubProfile(): Promise<CollectorResult> {\n const lines: string[] = [];\n\n // Check if gh CLI is available\n const ghVersion = await exec(\"gh\", [\"--version\"]);\n if (!ghVersion) {\n return {\n id: \"github-profile\",\n title: \"GitHub Profile\",\n content: \"GitHub CLI (gh) not installed.\",\n };\n }\n\n // Check auth status\n const authStatus = await exec(\"gh\", [\"auth\", \"status\"]);\n if (!authStatus) {\n return {\n id: \"github-profile\",\n title: \"GitHub Profile\",\n content: \"GitHub CLI not authenticated. Run `gh auth login` to enable.\",\n };\n }\n\n // Get user profile\n const userJson = await exec(\"gh\", [\n \"api\", \"user\",\n \"--jq\", '[.login, .name, .bio, .company, .location, .blog, .public_repos, .followers, .following, .created_at] | @tsv',\n ]);\n\n if (userJson) {\n const parts = userJson.split(\"\\t\");\n const [login, name, bio, company, location, blog, publicRepos, followers, following, createdAt] = parts;\n lines.push(\"## GitHub Profile\", \"\");\n if (login) lines.push(`- Username: ${login}`);\n if (name) lines.push(`- Name: ${name}`);\n if (bio) lines.push(`- Bio: ${bio}`);\n if (company) lines.push(`- Company: ${company}`);\n if (location) lines.push(`- Location: ${location}`);\n if (blog) lines.push(`- Website: ${blog}`);\n if (publicRepos) lines.push(`- Public Repos: ${publicRepos}`);\n if (followers || following) lines.push(`- Followers/Following: ${followers}/${following}`);\n if (createdAt) lines.push(`- Member since: ${createdAt}`);\n }\n\n // Get recent repos (owned, sorted by push date)\n const reposJson = await exec(\"gh\", [\n \"repo\", \"list\", \"--limit\", \"10\", \"--sort\", \"updated\", \"--json\",\n \"name,description,primaryLanguage,pushedAt,isPrivate\",\n \"--jq\", '.[] | [.name, .description, (.primaryLanguage.name // \"\"), .pushedAt, .isPrivate] | @tsv',\n ]);\n\n if (reposJson) {\n const repos = reposJson.split(\"\\n\").filter(Boolean);\n if (repos.length > 0) {\n lines.push(\"\", \"## Recent GitHub Repos (by push date)\", \"\");\n for (const repo of repos) {\n const [name, desc, lang, _pushed, isPrivate] = repo.split(\"\\t\");\n const visibility = isPrivate === \"true\" ? \"private\" : \"public\";\n const langTag = lang ? ` [${lang}]` : \"\";\n const descTag = desc ? ` — ${desc}` : \"\";\n lines.push(`- ${name}${langTag} (${visibility})${descTag}`);\n }\n }\n }\n\n // Get starred repos (recent 20 for interest signals)\n const starsJson = await exec(\"gh\", [\n \"api\", \"user/starred?per_page=20&sort=created&direction=desc\",\n \"--jq\", '.[].full_name',\n ]);\n\n if (starsJson) {\n const stars = starsJson.split(\"\\n\").filter(Boolean);\n if (stars.length > 0) {\n lines.push(\"\", \"## Recently Starred Repos (interest signals)\", \"\");\n lines.push(stars.map((s) => `- ${s}`).join(\"\\n\"));\n }\n }\n\n return {\n id: \"github-profile\",\n title: \"GitHub Profile & Activity\",\n content: lines.length > 0 ? lines.join(\"\\n\") : \"No GitHub data accessible.\",\n };\n}\n\n// ---------------------------------------------------------------------------\n// 13. Recent Focus (inferred from git commits + shell history)\n// ---------------------------------------------------------------------------\n\nexport async function collectRecentFocus(): Promise<CollectorResult> {\n const lines: string[] = [];\n\n // Analyze recent commit messages across active repos for topic signals\n const repos = await findRecentGitRepos(14); // Last 2 weeks\n const commitTopics = new Map<string, number>();\n const recentMessages: string[] = [];\n\n for (const repo of repos.slice(0, 8)) {\n // Get recent commit subjects from this repo\n const log = await exec(\"git\", [\n \"-C\", repo,\n \"log\", \"--oneline\", \"--since=14 days ago\",\n \"--format=%s\", \"-n\", \"20\",\n ]);\n if (log) {\n for (const msg of log.split(\"\\n\").filter(Boolean)) {\n recentMessages.push(msg);\n // Extract first word (often a conventional commit type)\n const type = msg.match(/^(feat|fix|refactor|test|docs|chore|perf|ci|build|style)/i);\n if (type) {\n const key = type[1].toLowerCase();\n commitTopics.set(key, (commitTopics.get(key) ?? 0) + 1);\n }\n }\n }\n }\n\n if (commitTopics.size > 0) {\n const sorted = [...commitTopics.entries()].sort((a, b) => b[1] - a[1]);\n lines.push(\"## Recent Commit Activity (last 2 weeks)\", \"\");\n lines.push(`Total commits analyzed: ${recentMessages.length}`);\n lines.push(\"\", \"Commit types:\");\n for (const [type, count] of sorted) {\n lines.push(`- ${type}: ${count}`);\n }\n }\n\n // Extract recent commit subjects for topic inference\n if (recentMessages.length > 0) {\n lines.push(\"\", \"## Recent Commit Messages (sample)\", \"\");\n // Take a diverse sample (first 15 unique-ish messages)\n const unique = [...new Set(recentMessages)].slice(0, 15);\n for (const msg of unique) {\n lines.push(`- ${msg}`);\n }\n }\n\n // Recent shell commands that indicate current work context\n const histPath = path.join(HOME, \".zsh_history\");\n const histRaw = await readSafe(histPath);\n if (histRaw) {\n const histLines = histRaw.split(\"\\n\");\n // Take last 200 history entries and extract project-related patterns\n const recent = histLines.slice(-200);\n const cdPaths = new Map<string, number>();\n const tools = new Map<string, number>();\n\n for (const line of recent) {\n const cmd = line.replace(/^:\\s*\\d+:\\d+;/, \"\").trim();\n // Track cd destinations\n const cdMatch = cmd.match(/^cd\\s+(.+)/);\n if (cdMatch) {\n const dest = cdMatch[1].trim().replace(/^~/, HOME);\n cdPaths.set(dest, (cdPaths.get(dest) ?? 0) + 1);\n }\n // Track tool usage\n const toolMatch = cmd.match(/^(docker|kubectl|terraform|aws|gcloud|firebase|vercel|netlify|npm|pnpm|yarn|bun|cargo|go|python|pip|uv)\\b/);\n if (toolMatch) {\n tools.set(toolMatch[1], (tools.get(toolMatch[1]) ?? 0) + 1);\n }\n }\n\n if (cdPaths.size > 0) {\n const topDirs = [...cdPaths.entries()].sort((a, b) => b[1] - a[1]).slice(0, 8);\n lines.push(\"\", \"## Recent Working Directories\", \"\");\n for (const [dir, count] of topDirs) {\n lines.push(`- ${dir.replace(HOME, \"~\")}: ${count}x`);\n }\n }\n\n if (tools.size > 0) {\n const topTools = [...tools.entries()].sort((a, b) => b[1] - a[1]);\n lines.push(\"\", \"## Recently Used Tools (from history)\", \"\");\n for (const [tool, count] of topTools) {\n lines.push(`- ${tool}: ${count}x`);\n }\n }\n }\n\n return {\n id: \"recent-focus\",\n title: \"Recent Focus & Activity\",\n content: lines.length > 0\n ? lines.join(\"\\n\")\n : \"No recent activity data found.\",\n };\n}\n\n// ---------------------------------------------------------------------------\n// 14. Social & Registry Profiles\n// ---------------------------------------------------------------------------\n\nexport async function collectSocialProfiles(): Promise<CollectorResult> {\n const lines: string[] = [];\n\n // npm registry identity\n const npmrc = await readSafe(path.join(HOME, \".npmrc\"));\n if (npmrc) {\n // Extract registry URL (but not tokens)\n const registryMatch = npmrc.match(/^registry\\s*=\\s*(.+)/m);\n if (registryMatch) lines.push(`- npm registry: ${registryMatch[1].trim()}`);\n // Check for scope configs\n const scopes = npmrc.match(/^@[\\w-]+:registry/gm);\n if (scopes) {\n for (const s of scopes) {\n lines.push(`- npm scope: ${s.split(\":\")[0]}`);\n }\n }\n }\n\n // npm whoami\n const npmUser = await exec(\"npm\", [\"whoami\"]);\n if (npmUser) lines.push(`- npm username: ${npmUser}`);\n\n // PyPI config\n const pypirc = await readSafe(path.join(HOME, \".pypirc\"));\n if (pypirc) {\n const repoMatch = pypirc.match(/repository\\s*=\\s*(.+)/);\n if (repoMatch) lines.push(`- PyPI repository: ${repoMatch[1].trim()}`);\n const usernameMatch = pypirc.match(/username\\s*=\\s*(.+)/);\n if (usernameMatch) lines.push(`- PyPI username: ${usernameMatch[1].trim()}`);\n }\n\n // Docker Hub\n const dockerConfig = await readSafe(path.join(HOME, \".docker\", \"config.json\"));\n if (dockerConfig) {\n try {\n const cfg = JSON.parse(dockerConfig);\n const auths = Object.keys(cfg.auths ?? {});\n if (auths.length > 0) {\n lines.push(`- Docker registries: ${auths.join(\", \")}`);\n }\n } catch {\n // Ignore parse errors\n }\n }\n\n // Cargo / crates.io\n const cargoConfig = await readSafe(path.join(HOME, \".cargo\", \"config.toml\"));\n if (cargoConfig) {\n const registries = cargoConfig.match(/\\[registries\\.(\\w+)\\]/g);\n if (registries) {\n lines.push(`- Cargo registries: ${registries.map((r) => r.replace(/\\[registries\\.|\\]/g, \"\")).join(\", \")}`);\n }\n }\n\n // Cloud provider CLIs\n const awsIdentity = await exec(\"aws\", [\"sts\", \"get-caller-identity\", \"--query\", \"Account\", \"--output\", \"text\"]);\n if (awsIdentity) lines.push(`- AWS Account: ${awsIdentity}`);\n\n const gcpProject = await exec(\"gcloud\", [\"config\", \"get-value\", \"project\"]);\n if (gcpProject && !gcpProject.includes(\"unset\")) lines.push(`- GCP Project: ${gcpProject}`);\n\n const vercelUser = await exec(\"vercel\", [\"whoami\"]);\n if (vercelUser) lines.push(`- Vercel: ${vercelUser}`);\n\n return {\n id: \"social-profiles\",\n title: \"Registry & Cloud Profiles\",\n content: lines.length > 0\n ? [\"## Registry & Cloud Accounts\", \"\", ...lines].join(\"\\n\")\n : \"No registry or cloud profiles detected.\",\n };\n}\n\n// ---------------------------------------------------------------------------\n// Shared utilities\n// ---------------------------------------------------------------------------\n\n/** Find git repos under ~/Documents modified in the last N days */\nasync function findRecentGitRepos(days: number): Promise<string[]> {\n const output = await exec(\"find\", [\n path.join(HOME, \"Documents\"),\n \"-maxdepth\", \"4\",\n \"-name\", \".git\",\n \"-type\", \"d\",\n \"-mtime\", `-${days}`,\n ]);\n\n if (!output) return [];\n return output\n .split(\"\\n\")\n .filter(Boolean)\n .map((p) => p.replace(/\\/.git$/, \"\"));\n}\n\n// ---------------------------------------------------------------------------\n// Export all collectors\n// ---------------------------------------------------------------------------\n\n/** All available Mac collectors in execution order */\nexport const ALL_COLLECTORS = [\n collectIdentityProfile,\n collectCalendarContext,\n collectFileOrganization,\n collectDevEnvironment,\n collectDevPreferences,\n collectShellHabits,\n collectCodingRules,\n collectActiveProjects,\n collectProductivitySetup,\n collectBrowserBookmarks,\n collectBrowserDomains,\n collectGitHubProfile,\n collectRecentFocus,\n collectSocialProfiles,\n] as const;\n","/**\n * Profile module — compile, load, and rebuild user profiles.\n */\n\nimport fs from \"node:fs/promises\";\nimport { getProfilePath } from \"../config/paths.js\";\nimport { addConnectorEntry } from \"../raw/add.js\";\nimport * as console from \"../utils/console.js\";\nimport { compileProfile, compileCompactProfile } from \"./compile.js\";\nimport type { CollectorResult } from \"../types.js\";\nimport { ALL_COLLECTORS } from \"../connectors/mac/collectors.js\";\n\nexport { compileProfile, compileCompactProfile } from \"./compile.js\";\n\n/** Load the current profile from disk. Returns null if not found. */\nexport async function loadProfile(): Promise<string | null> {\n try {\n return await fs.readFile(getProfilePath(), \"utf-8\");\n } catch {\n return null;\n }\n}\n\n/** Save profile markdown to disk. */\nexport async function saveProfile(content: string): Promise<string> {\n const profilePath = getProfilePath();\n await fs.writeFile(profilePath, content, \"utf-8\");\n return profilePath;\n}\n\n/**\n * Full rebuild: scan local machine → compile profile → write to disk.\n * Also writes raw files for the scan data (for vault/distill pipeline compatibility).\n */\nexport async function rebuildProfile(opts?: {\n /** If true, skip writing raw files (profile-only mode) */\n skipRaw?: boolean;\n /** If true, show progress spinners */\n verbose?: boolean;\n}): Promise<{ profilePath: string; results: CollectorResult[] }> {\n const verbose = opts?.verbose ?? true;\n\n // 1. Run all collectors concurrently\n const spin = verbose ? console.spinner(\"Scanning local machine...\") : null;\n\n const settled = await Promise.allSettled(\n ALL_COLLECTORS.map((collector) => collector()),\n );\n\n const results: CollectorResult[] = [];\n const failed: string[] = [];\n\n for (let i = 0; i < settled.length; i++) {\n const s = settled[i];\n if (s.status === \"fulfilled\") {\n results.push(s.value);\n } else {\n const name = ALL_COLLECTORS[i].name;\n failed.push(name);\n if (verbose) console.warn(`Collector ${name} failed: ${String(s.reason)}`);\n }\n }\n\n spin?.succeed(`Scanned ${results.length} sources (${failed.length} failed)`);\n\n // 2. Optionally write raw files (for backward compat with vault/distill)\n if (!opts?.skipRaw) {\n for (const entry of results) {\n try {\n await addConnectorEntry(\"mac\", entry);\n } catch {\n // Non-critical — profile compilation doesn't depend on raw writes\n }\n }\n }\n\n // 3. Compile and save profile\n const profileContent = compileProfile(results);\n const profilePath = await saveProfile(profileContent);\n\n return { profilePath, results };\n}\n"],"mappings":";;;;;;;;;;;;;;AAIA,SAAgB,aAAqB;AACnC,QAAO,QAAQ,IAAI,YAAY,KAAK,KAAK,GAAG,SAAS,EAAE,OAAO;;AAGhE,SAAgB,YAAoB;AAClC,QAAO,KAAK,KAAK,YAAY,EAAE,MAAM;;AAGvC,SAAgB,cAAsB;AACpC,QAAO,KAAK,KAAK,YAAY,EAAE,QAAQ;;AAGzC,SAAgB,eAAuB;AACrC,QAAO,KAAK,KAAK,YAAY,EAAE,SAAS;;;AAQ1C,SAAgB,eAAe,MAAsB;AACnD,QAAO,KAAK,KAAK,cAAc,EAAE,GAAG,KAAK,KAAK;;;AAIhD,SAAgB,eAAuB;AACrC,yBAAO,IAA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CAEtE,MAAM,UAAU,MAAM,QAAQ,WAC5B,eAAe,KAAK,cAAc,WAAW,CAAC,CAC/C;CAED,MAAM,UAA6B,EAAE;CACrC,MAAM,SAAmB,EAAE;AAE3B,MAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;EACvC,MAAM,IAAI,QAAQ;AAClB,MAAI,EAAE,WAAW,YACf,SAAQ,KAAK,EAAE,MAAM;OAChB;GACL,MAAM,OAAO,eAAe,GAAG;AAC/B,UAAO,KAAK,KAAK;AACjB,OAAI,QAAS,MAAa,aAAa,KAAK,WAAW,OAAO,EAAE,OAAO,GAAG;;;AAI9E,OAAM,QAAQ,WAAW,QAAQ,OAAO,YAAY,OAAO,OAAO,UAAU;AAG5E,KAAI,CAAC,MAAM,QACT,MAAK,MAAM,SAAS,QAClB,KAAI;AACF,QAAM,kBAAkB,OAAO,MAAM;SAC/B;AAUZ,QAAO;EAAE,aAFW,MAAM,YADH,eAAe,QAAQ,CACO;EAE/B;EAAS"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["console.spinner","console.spinner","console.spinner"],"sources":["../src/config/paths.ts","../src/config/schema.ts","../src/config/io.ts","../src/utils/slug.ts","../src/utils/frontmatter.ts","../src/raw/add.ts","../src/utils/console.ts","../src/scraper/index.ts","../src/utils/process.ts","../src/search/index.ts","../src/llm/client.ts","../src/prompts/extract.ts","../src/distill/extract.ts","../src/vault/writer.ts","../src/memory/journal.ts","../src/distill/index.ts","../src/prompts/generate.ts","../src/generate/index.ts","../src/profile/compile.ts","../src/connectors/sanitize.ts","../src/connectors/mac/collectors.ts","../src/profile/index.ts"],"sourcesContent":["import os from \"node:os\";\nimport path from \"node:path\";\n\n/** Root data directory for pai */\nexport function getPaiHome(): string {\n return process.env.PAI_HOME ?? path.join(os.homedir(), \".pai\");\n}\n\nexport function getRawDir(): string {\n return path.join(getPaiHome(), \"raw\");\n}\n\nexport function getVaultDir(): string {\n return path.join(getPaiHome(), \"vault\");\n}\n\nexport function getMemoryDir(): string {\n return path.join(getPaiHome(), \"memory\");\n}\n\nexport function getWeeklyDir(): string {\n return path.join(getMemoryDir(), \"weekly\");\n}\n\n/** Get the journal file path for a given date (YYYY-MM-DD) */\nexport function getJournalPath(date: string): string {\n return path.join(getMemoryDir(), `${date}.md`);\n}\n\n/** Get today's date as YYYY-MM-DD */\nexport function getTodayDate(): string {\n return new Date().toISOString().split(\"T\")[0]!;\n}\n\nexport function getSkillsDir(): string {\n return path.join(getPaiHome(), \"skills\", \"profiles\");\n}\n\nexport function getConfigDir(): string {\n return path.join(getPaiHome(), \"config\");\n}\n\nexport function getConfigPath(): string {\n return path.join(getConfigDir(), \"pai.json5\");\n}\n\nexport function getProfilesPath(): string {\n return path.join(getConfigDir(), \"profiles.json5\");\n}\n\nexport function getPreferencesPath(): string {\n return path.join(getConfigDir(), \"preferences.md\");\n}\n\n/** Compiled user profile — the core output of pai */\nexport function getProfilePath(): string {\n return path.join(getPaiHome(), \"profile.md\");\n}\n","import { z } from \"zod\";\n\nexport const QmdConfigSchema = z.object({\n rawCollection: z.string().default(\"raw\"),\n vaultCollection: z.string().default(\"vault\"),\n});\n\nexport const LlmConfigSchema = z.object({\n apiKeyEnv: z.string().default(\"OPENAI_API_KEY\"),\n baseUrl: z.string().optional(),\n cheapModel: z.string().default(\"gpt-4o-mini\"),\n expensiveModel: z.string().default(\"gpt-4o\"),\n});\n\nexport const ScraperConfigSchema = z.object({\n timeout: z.number().default(30_000),\n});\n\nexport const VaultConfigSchema = z.object({\n maxFileTokens: z.number().default(4000),\n warnFileTokens: z.number().default(3000),\n});\n\nexport const PaiConfigSchema = z\n .object({\n version: z.string().default(\"0.1\"),\n qmd: QmdConfigSchema.default(() => QmdConfigSchema.parse({})),\n llm: LlmConfigSchema.default(() => LlmConfigSchema.parse({})),\n scraper: ScraperConfigSchema.default(() => ScraperConfigSchema.parse({})),\n vault: VaultConfigSchema.default(() => VaultConfigSchema.parse({})),\n })\n .strict();\n\nexport type PaiConfig = z.infer<typeof PaiConfigSchema>;\n","import fs from \"node:fs/promises\";\nimport JSON5 from \"json5\";\nimport { PaiConfigSchema, type PaiConfig } from \"./schema.js\";\nimport { getConfigPath, getProfilesPath } from \"./paths.js\";\nimport type { ProfilesConfig } from \"../types.js\";\n\n/** Load and validate pai.json5 config */\nexport async function loadConfig(): Promise<PaiConfig> {\n const configPath = getConfigPath();\n try {\n const raw = await fs.readFile(configPath, \"utf-8\");\n const parsed = JSON5.parse(raw);\n return PaiConfigSchema.parse(parsed);\n } catch (err: unknown) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") {\n // Return defaults if config file doesn't exist\n return PaiConfigSchema.parse({});\n }\n throw err;\n }\n}\n\n/** Load profiles.json5 */\nexport async function loadProfiles(): Promise<ProfilesConfig> {\n const profilesPath = getProfilesPath();\n try {\n const raw = await fs.readFile(profilesPath, \"utf-8\");\n return JSON5.parse(raw) as ProfilesConfig;\n } catch (err: unknown) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") {\n return { profiles: {} };\n }\n throw err;\n }\n}\n\n/** Write config file (with JSON5 formatting) */\nexport async function saveConfig(\n filePath: string,\n content: string,\n): Promise<void> {\n await fs.writeFile(filePath, content, \"utf-8\");\n}\n","/** Generate a URL-safe slug from a title string */\nexport function generateSlug(title: string): string {\n return title\n .toLowerCase()\n .replace(/[^a-z0-9\\s-]/g, \"\") // remove special chars\n .replace(/\\s+/g, \"-\") // spaces to hyphens\n .replace(/-+/g, \"-\") // collapse multiple hyphens\n .replace(/^-|-$/g, \"\") // trim leading/trailing hyphens\n .slice(0, 50); // max 50 chars\n}\n\n/** Generate a timestamped filename: YYYY-MM-DDTHH-MM-{slug}.md */\nexport function generateRawFilename(title: string): string {\n const now = new Date();\n const ts = now\n .toISOString()\n .replace(/:\\d{2}\\.\\d{3}Z$/, \"\")\n .replace(/:/g, \"-\");\n const slug = generateSlug(title) || \"untitled\";\n return `${ts}-${slug}.md`;\n}\n","import matter from \"gray-matter\";\nimport type { RawFrontmatter } from \"../types.js\";\n\n/** Parse a markdown file with frontmatter */\nexport function parseFrontmatter<T = Record<string, unknown>>(\n content: string,\n): { data: T; content: string } {\n const result = matter(content);\n return { data: result.data as T, content: result.content };\n}\n\n/** Stringify data + content into a frontmatter markdown string */\nexport function stringifyFrontmatter(\n data: Record<string, unknown>,\n content: string,\n): string {\n return matter.stringify(content, data);\n}\n\n/** Create a raw file with proper frontmatter */\nexport function createRawFile(\n frontmatter: RawFrontmatter,\n title: string,\n body: string,\n): string {\n const content = `\\n# ${title}\\n\\n${body}\\n`;\n return stringifyFrontmatter(frontmatter as unknown as Record<string, unknown>, content);\n}\n\n/** Update frontmatter fields in a raw file */\nexport function updateRawFrontmatter(\n fileContent: string,\n updates: Partial<RawFrontmatter>,\n): string {\n const { data, content } = parseFrontmatter<RawFrontmatter>(fileContent);\n const updated = { ...data, ...updates };\n return stringifyFrontmatter(updated as unknown as Record<string, unknown>, content);\n}\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { getRawDir } from \"../config/paths.js\";\nimport { generateRawFilename } from \"../utils/slug.js\";\nimport { createRawFile, parseFrontmatter } from \"../utils/frontmatter.js\";\nimport type { CollectorResult, RawFrontmatter } from \"../types.js\";\n\n/** Add plain text content to raw/local/ */\nexport async function addText(\n content: string,\n source: string = \"local\",\n): Promise<string> {\n const title = extractTitle(content);\n const filename = generateRawFilename(title);\n const dir = path.join(getRawDir(), \"local\");\n await fs.mkdir(dir, { recursive: true });\n\n const fm: RawFrontmatter = {\n source,\n timestamp: new Date().toISOString(),\n status: \"pending\",\n };\n\n const fileContent = createRawFile(fm, title, content);\n const filePath = path.join(dir, filename);\n await fs.writeFile(filePath, fileContent, \"utf-8\");\n return filePath;\n}\n\n/** Add a local file's content to raw/local/ */\nexport async function addFile(\n filePath: string,\n source: string = \"local\",\n): Promise<string> {\n const content = await fs.readFile(filePath, \"utf-8\");\n const basename = path.basename(filePath, path.extname(filePath));\n const filename = generateRawFilename(basename);\n const dir = path.join(getRawDir(), \"local\");\n await fs.mkdir(dir, { recursive: true });\n\n const fm: RawFrontmatter = {\n source,\n timestamp: new Date().toISOString(),\n status: \"pending\",\n };\n\n const fileContent = createRawFile(fm, basename, content);\n const outPath = path.join(dir, filename);\n await fs.writeFile(outPath, fileContent, \"utf-8\");\n return outPath;\n}\n\n/** Add URL-scraped content to raw/web/ */\nexport async function addUrl(\n url: string,\n title: string,\n markdown: string,\n): Promise<string> {\n const filename = generateRawFilename(title);\n const dir = path.join(getRawDir(), \"web\");\n await fs.mkdir(dir, { recursive: true });\n\n const fm: RawFrontmatter = {\n source: \"web\",\n timestamp: new Date().toISOString(),\n url,\n status: \"pending\",\n };\n\n const fileContent = createRawFile(fm, title, markdown);\n const filePath = path.join(dir, filename);\n await fs.writeFile(filePath, fileContent, \"utf-8\");\n return filePath;\n}\n\n/**\n * Add or update a connector-scanned entry to raw/connector/{name}/.\n * Uses scan_id in frontmatter for dedup:\n * - If no existing file with same scan_id → create new\n * - If existing file with same content body → skip (\"skipped\")\n * - If existing file with different content → overwrite (\"updated\")\n * Returns \"created\" | \"updated\" | \"skipped\".\n */\nexport async function addConnectorEntry(\n connectorName: string,\n entry: CollectorResult,\n): Promise<\"created\" | \"updated\" | \"skipped\"> {\n const dir = path.join(getRawDir(), \"connector\", connectorName);\n await fs.mkdir(dir, { recursive: true });\n\n const scanId = `${connectorName}/${entry.id}`;\n\n // Check for existing file with same scan_id\n const existingPath = await findByScanId(dir, scanId);\n\n const fm: RawFrontmatter = {\n source: `connector/${connectorName}`,\n timestamp: new Date().toISOString(),\n status: \"pending\",\n scan_id: scanId,\n };\n\n if (existingPath) {\n // Compare content body\n const oldRaw = await fs.readFile(existingPath, \"utf-8\");\n const { content: oldBody } = parseFrontmatter(oldRaw);\n const newBody = `\\n# ${entry.title}\\n\\n${entry.content}\\n`;\n\n if (oldBody.trim() === newBody.trim()) {\n return \"skipped\";\n }\n\n // Overwrite with updated content (preserve filename)\n const fileContent = createRawFile(fm, entry.title, entry.content);\n await fs.writeFile(existingPath, fileContent, \"utf-8\");\n return \"updated\";\n }\n\n // Create new entry\n const filename = generateRawFilename(entry.id);\n const fileContent = createRawFile(fm, entry.title, entry.content);\n const filePath = path.join(dir, filename);\n await fs.writeFile(filePath, fileContent, \"utf-8\");\n return \"created\";\n}\n\n/** Find a raw file in a directory whose frontmatter scan_id matches */\nasync function findByScanId(dir: string, scanId: string): Promise<string | null> {\n try {\n const entries = await fs.readdir(dir);\n for (const name of entries) {\n if (!name.endsWith(\".md\")) continue;\n const filePath = path.join(dir, name);\n const content = await fs.readFile(filePath, \"utf-8\");\n if (content.includes(`scan_id: ${scanId}`) || content.includes(`scan_id: '${scanId}'`)) {\n return filePath;\n }\n }\n } catch {\n // Directory doesn't exist or read error\n }\n return null;\n}\n\n/** List all pending raw files (status: pending) */\nexport async function listPending(): Promise<string[]> {\n const rawDir = getRawDir();\n const pending: string[] = [];\n\n const subdirs = [\"local\", \"web\", \"connector\"];\n for (const sub of subdirs) {\n const dir = path.join(rawDir, sub);\n try {\n const entries = await walkDir(dir);\n for (const entry of entries) {\n if (entry.endsWith(\".md\")) {\n const content = await fs.readFile(entry, \"utf-8\");\n if (content.includes(\"status: pending\")) {\n pending.push(entry);\n }\n }\n }\n } catch {\n // Directory might not exist\n }\n }\n return pending;\n}\n\n/** List all raw files regardless of status */\nexport async function listAll(): Promise<string[]> {\n const rawDir = getRawDir();\n const files: string[] = [];\n\n const subdirs = [\"local\", \"web\", \"connector\"];\n for (const sub of subdirs) {\n const dir = path.join(rawDir, sub);\n try {\n const entries = await walkDir(dir);\n files.push(...entries.filter((e) => e.endsWith(\".md\")));\n } catch {\n // Directory might not exist\n }\n }\n return files;\n}\n\n/** Recursively walk a directory and return file paths */\nasync function walkDir(dir: string): Promise<string[]> {\n const results: string[] = [];\n try {\n const entries = await fs.readdir(dir, { withFileTypes: true });\n for (const entry of entries) {\n const fullPath = path.join(dir, entry.name);\n if (entry.isDirectory()) {\n results.push(...(await walkDir(fullPath)));\n } else {\n results.push(fullPath);\n }\n }\n } catch {\n // Ignore errors (dir doesn't exist, etc.)\n }\n return results;\n}\n\n/** Extract a title from content (first line or first N words) */\nfunction extractTitle(content: string): string {\n const firstLine = content.split(\"\\n\")[0]?.trim() ?? \"\";\n // Remove markdown heading syntax\n const cleaned = firstLine.replace(/^#+\\s*/, \"\");\n if (cleaned.length > 0 && cleaned.length <= 100) {\n return cleaned;\n }\n // Fall back to first 8 words\n return content.split(/\\s+/).slice(0, 8).join(\" \").slice(0, 100) || \"untitled\";\n}\n","import chalk from \"chalk\";\nimport ora, { type Ora } from \"ora\";\n\nexport function log(message: string): void {\n // eslint-disable-next-line no-console\n console.log(message);\n}\n\nexport function info(message: string): void {\n // eslint-disable-next-line no-console\n console.log(chalk.blue(\"ℹ\"), message);\n}\n\nexport function success(message: string): void {\n // eslint-disable-next-line no-console\n console.log(chalk.green(\"✓\"), message);\n}\n\nexport function warn(message: string): void {\n // eslint-disable-next-line no-console\n console.warn(chalk.yellow(\"⚠\"), message);\n}\n\nexport function error(message: string): void {\n // eslint-disable-next-line no-console\n console.error(chalk.red(\"✗\"), message);\n}\n\nexport function spinner(text: string): Ora {\n return ora({ text, color: \"cyan\" }).start();\n}\n\nexport function dim(message: string): string {\n return chalk.dim(message);\n}\n\nexport function bold(message: string): string {\n return chalk.bold(message);\n}\n","/**\n * Web scraper: three-tier strategy for content extraction.\n *\n * 1. GitHub blob URLs → convert to raw.githubusercontent.com, fetch raw markdown (zero rendering)\n * 2. General URLs → Playwright headless browser + DOM preprocessing + Defuddle extraction\n * 3. Fallback → plain fetch + Defuddle (for when Playwright is unavailable)\n *\n * Reference: linkmind-master/src/scraper.ts\n */\n\nimport * as console from \"../utils/console.js\";\n\nconst CHROME_UA =\n \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36\";\n\n/** Minimum markdown length to consider a scrape successful */\nconst MIN_CONTENT_LENGTH = 100;\n\nexport interface ScrapeResult {\n url: string;\n title: string;\n markdown: string;\n}\n\n// ---------------------------------------------------------------------------\n// Domain-specific fast paths\n// ---------------------------------------------------------------------------\n\n/** Check if a URL points to a file on GitHub (blob view) */\nfunction isGithubBlobUrl(url: string): boolean {\n try {\n const u = new URL(url);\n return u.hostname === \"github.com\" && /\\/blob\\//.test(u.pathname);\n } catch {\n return false;\n }\n}\n\n/** Convert GitHub blob URL to raw.githubusercontent.com URL */\nfunction toRawGithubUrl(url: string): string {\n // github.com/OWNER/REPO/blob/BRANCH/PATH\n // → raw.githubusercontent.com/OWNER/REPO/BRANCH/PATH\n return url\n .replace(\"https://github.com/\", \"https://raw.githubusercontent.com/\")\n .replace(\"/blob/\", \"/\");\n}\n\n/** Fast path: fetch raw content directly from GitHub (returns markdown/text as-is) */\nasync function scrapeGithubRaw(\n url: string,\n timeout: number,\n): Promise<ScrapeResult> {\n const rawUrl = toRawGithubUrl(url);\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), timeout);\n\n try {\n const resp = await fetch(rawUrl, {\n signal: controller.signal,\n headers: { \"User-Agent\": CHROME_UA },\n });\n if (!resp.ok) {\n throw new Error(`GitHub raw fetch failed: HTTP ${resp.status}`);\n }\n const markdown = await resp.text();\n\n // Extract title from first heading or filename\n const titleMatch = markdown.match(/^#\\s+(.+)$/m);\n const pathParts = new URL(url).pathname.split(\"/\");\n const filename = pathParts[pathParts.length - 1] ?? \"Untitled\";\n const title = titleMatch?.[1]?.trim() ?? filename;\n\n return { url, title, markdown };\n } finally {\n clearTimeout(timer);\n }\n}\n\n// ---------------------------------------------------------------------------\n// Playwright scraper (primary path for general URLs)\n// ---------------------------------------------------------------------------\n\n/**\n * DOM preprocessing script executed inside the browser.\n * Removes navigation, ads, cookie banners, and other non-content elements\n * before Defuddle extraction. (Borrowed from linkmind)\n */\nconst DOM_PREPROCESS_SCRIPT = `(() => {\n // Remove script, style, stylesheet links\n document.querySelectorAll(\"script, style, link[rel='stylesheet']\").forEach(el => el.remove());\n // Remove navigation elements\n document.querySelectorAll(\"nav, footer, aside\").forEach(el => el.remove());\n // Remove headers not inside article/main\n document.querySelectorAll(\"header\").forEach(el => {\n if (!el.closest(\"article\") && !el.closest(\"main\")) el.remove();\n });\n // Remove ARIA landmark roles\n document.querySelectorAll('[role=\"navigation\"], [role=\"banner\"], [role=\"contentinfo\"], [role=\"complementary\"], [role=\"search\"]').forEach(el => el.remove());\n // Remove cookie/share/comment noise\n document.querySelectorAll('[class*=\"cookie-banner\"], [id*=\"cookie-banner\"], [class*=\"cookie-consent\"], [class*=\"share-buttons\"], [class*=\"social-share\"], [class*=\"comment-section\"], [id*=\"comments\"]').forEach(el => el.remove());\n // Remove hidden elements\n document.querySelectorAll('[hidden], [aria-hidden=\"true\"]').forEach(el => el.remove());\n\n return {\n title: document.title,\n html: document.documentElement.outerHTML,\n };\n})()`;\n\n/** Scrape with Playwright headless browser + Defuddle */\nasync function scrapeWithPlaywright(\n url: string,\n timeout: number,\n): Promise<ScrapeResult> {\n // Dynamic import so the module still loads when playwright is not installed\n const pw = await import(\"playwright\");\n const { Defuddle } = await import(\"defuddle/node\");\n\n const browser = await pw.chromium.launch({\n headless: true,\n args: [\"--disable-blink-features=AutomationControlled\"],\n });\n\n try {\n const context = await browser.newContext({\n viewport: { width: 1280, height: 900 },\n userAgent: CHROME_UA,\n locale: \"en-US\",\n });\n\n const page = await context.newPage();\n await page.goto(url, { waitUntil: \"domcontentloaded\", timeout });\n // Wait for JS rendering (dynamic content, SPAs)\n await page.waitForTimeout(2000);\n\n // Preprocess DOM and grab cleaned HTML\n const { title: pageTitle, html } = (await page.evaluate(\n DOM_PREPROCESS_SCRIPT,\n )) as { title: string; html: string };\n\n await browser.close();\n\n // Defuddle content extraction (suppress noisy log)\n const origLog = globalThis.console.log;\n globalThis.console.log = (msg: unknown, ...args: unknown[]) => {\n if (\n typeof msg === \"string\" &&\n msg.includes(\"Initial parse returned very little content\")\n )\n return;\n origLog(msg, ...args);\n };\n const result = await Defuddle(html, url);\n globalThis.console.log = origLog;\n\n const title = result.title || pageTitle || \"Untitled\";\n const markdown = result.content\n ? htmlToSimpleMarkdown(result.content)\n : \"\";\n\n return { url, title, markdown };\n } catch (err) {\n await browser.close().catch(() => {});\n throw err;\n }\n}\n\n// ---------------------------------------------------------------------------\n// Fetch fallback (when Playwright is unavailable)\n// ---------------------------------------------------------------------------\n\n/** Lightweight scrape: plain HTTP fetch + Defuddle (no JS rendering) */\nasync function scrapeWithFetch(\n url: string,\n timeout: number,\n): Promise<ScrapeResult> {\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), timeout);\n\n let html: string;\n try {\n const response = await fetch(url, {\n signal: controller.signal,\n headers: {\n \"User-Agent\": CHROME_UA,\n Accept: \"text/html,application/xhtml+xml\",\n },\n });\n if (!response.ok) {\n throw new Error(`HTTP ${response.status}: ${response.statusText}`);\n }\n html = await response.text();\n } finally {\n clearTimeout(timer);\n }\n\n // Try Defuddle\n try {\n const { Defuddle } = await import(\"defuddle/node\");\n const result = await Defuddle(html, url);\n const title = result.title || extractTitleFromHtml(html);\n const markdown = result.content\n ? htmlToSimpleMarkdown(result.content)\n : extractTextFromHtml(html);\n return { url, title, markdown };\n } catch {\n // Defuddle unavailable — raw HTML stripping\n console.warn(\"defuddle not available, using basic HTML extraction\");\n }\n\n const title = extractTitleFromHtml(html);\n const markdown = extractTextFromHtml(html);\n return { url, title, markdown };\n}\n\n// ---------------------------------------------------------------------------\n// Public API\n// ---------------------------------------------------------------------------\n\n/**\n * Scrape a URL and return title + markdown content.\n *\n * Strategy:\n * 1. GitHub blob URL → raw.githubusercontent.com (instant, perfect fidelity)\n * 2. Playwright + Defuddle (handles JS-rendered pages)\n * 3. Fetch + Defuddle fallback (static pages, or when Playwright missing)\n */\nexport async function scrapeUrl(\n url: string,\n timeout: number = 30_000,\n): Promise<ScrapeResult> {\n // --- Fast path: GitHub blob → raw fetch ---\n if (isGithubBlobUrl(url)) {\n console.info(\"GitHub blob detected — fetching raw content directly\");\n return scrapeGithubRaw(url, timeout);\n }\n\n // --- Primary: Playwright ---\n try {\n const result = await scrapeWithPlaywright(url, timeout);\n\n // Quality check: if Playwright returned too little content, try fetch fallback\n if (result.markdown.length < MIN_CONTENT_LENGTH) {\n console.warn(\n `Playwright extracted only ${result.markdown.length} chars — trying fetch fallback`,\n );\n const fallback = await scrapeWithFetch(url, timeout);\n // Return whichever got more content\n return fallback.markdown.length > result.markdown.length\n ? fallback\n : result;\n }\n\n return result;\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n console.warn(`Playwright scrape failed (${msg}) — falling back to fetch`);\n }\n\n // --- Fallback: plain fetch ---\n return scrapeWithFetch(url, timeout);\n}\n\n// ---------------------------------------------------------------------------\n// HTML helpers\n// ---------------------------------------------------------------------------\n\n/** Extract <title> from HTML */\nfunction extractTitleFromHtml(html: string): string {\n const match = html.match(/<title[^>]*>([^<]+)<\\/title>/i);\n return match?.[1]?.trim() ?? \"Untitled\";\n}\n\n/** Basic HTML to text extraction (last-resort fallback) */\nfunction extractTextFromHtml(html: string): string {\n return html\n .replace(/<script[\\s\\S]*?<\\/script>/gi, \"\")\n .replace(/<style[\\s\\S]*?<\\/style>/gi, \"\")\n .replace(/<[^>]+>/g, \" \")\n .replace(/&/g, \"&\")\n .replace(/</g, \"<\")\n .replace(/>/g, \">\")\n .replace(/"/g, '\"')\n .replace(/'/g, \"'\")\n .replace(/ /g, \" \")\n .replace(/\\s+/g, \" \")\n .trim()\n .slice(0, 10000);\n}\n\n/** Convert HTML fragment to simple Markdown (from linkmind, extended) */\nfunction htmlToSimpleMarkdown(html: string): string {\n if (!html) return \"\";\n\n let md = html;\n\n // Headings\n md = md.replace(/<h1[^>]*>(.*?)<\\/h1>/gi, \"# $1\\n\\n\");\n md = md.replace(/<h2[^>]*>(.*?)<\\/h2>/gi, \"## $1\\n\\n\");\n md = md.replace(/<h3[^>]*>(.*?)<\\/h3>/gi, \"### $1\\n\\n\");\n md = md.replace(/<h4[^>]*>(.*?)<\\/h4>/gi, \"#### $1\\n\\n\");\n md = md.replace(/<h5[^>]*>(.*?)<\\/h5>/gi, \"##### $1\\n\\n\");\n md = md.replace(/<h6[^>]*>(.*?)<\\/h6>/gi, \"###### $1\\n\\n\");\n\n // Paragraphs and line breaks\n md = md.replace(/<p[^>]*>/gi, \"\\n\\n\");\n md = md.replace(/<\\/p>/gi, \"\");\n md = md.replace(/<br\\s*\\/?>/gi, \"\\n\");\n\n // Bold and italic\n md = md.replace(/<(strong|b)[^>]*>(.*?)<\\/(strong|b)>/gi, \"**$2**\");\n md = md.replace(/<(em|i)[^>]*>(.*?)<\\/(em|i)>/gi, \"*$2*\");\n\n // Links\n md = md.replace(/<a[^>]*href=\"([^\"]*)\"[^>]*>(.*?)<\\/a>/gi, \"[$2]($1)\");\n\n // Code\n md = md.replace(/<code[^>]*>(.*?)<\\/code>/gi, \"`$1`\");\n md = md.replace(/<pre[^>]*>(.*?)<\\/pre>/gis, \"\\n```\\n$1\\n```\\n\");\n\n // Lists\n md = md.replace(/<li[^>]*>/gi, \"- \");\n md = md.replace(/<\\/li>/gi, \"\\n\");\n md = md.replace(/<\\/?[uo]l[^>]*>/gi, \"\\n\");\n\n // Blockquote\n md = md.replace(/<blockquote[^>]*>(.*?)<\\/blockquote>/gis, (_, content) => {\n return (content as string)\n .split(\"\\n\")\n .map((line: string) => `> ${line}`)\n .join(\"\\n\");\n });\n\n // Images\n md = md.replace(\n /<img[^>]*src=\"([^\"]*)\"[^>]*alt=\"([^\"]*)\"[^>]*\\/?>/gi,\n \"\",\n );\n md = md.replace(/<img[^>]*src=\"([^\"]*)\"[^>]*\\/?>/gi, \"\");\n\n // Strip remaining tags\n md = md.replace(/<[^>]+>/g, \"\");\n\n // Decode entities\n md = md.replace(/&/g, \"&\");\n md = md.replace(/</g, \"<\");\n md = md.replace(/>/g, \">\");\n md = md.replace(/"/g, '\"');\n md = md.replace(/'/g, \"'\");\n md = md.replace(/ /g, \" \");\n\n // Clean up whitespace\n md = md.replace(/\\n{3,}/g, \"\\n\\n\");\n md = md.trim();\n\n return md;\n}\n","import { execFile } from \"node:child_process\";\n\n/** Execute QMD CLI command and return stdout */\nexport async function execQmd(args: string[]): Promise<string> {\n return new Promise((resolve, reject) => {\n execFile(\"qmd\", args, { encoding: \"utf-8\", timeout: 60_000 }, (err, stdout, stderr) => {\n if (err) {\n const msg = stderr?.trim() || err.message;\n reject(new Error(`qmd ${args[0]} failed: ${msg}`));\n } else {\n resolve(stdout);\n }\n });\n });\n}\n\n/** Check if QMD is available on PATH */\nexport async function isQmdAvailable(): Promise<boolean> {\n try {\n await execQmd([\"status\"]);\n return true;\n } catch {\n return false;\n }\n}\n","import { execFile } from \"node:child_process\";\nimport fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { execQmd, isQmdAvailable } from \"../utils/process.js\";\nimport { getVaultDir, getRawDir } from \"../config/paths.js\";\nimport type { SearchResult } from \"../types.js\";\n\nexport type SearchMode = \"query\" | \"search\" | \"vsearch\";\n\n/**\n * Search with automatic fallback:\n * 1. QMD available → use QMD (query/search/vsearch modes)\n * 2. QMD not available → built-in grep search (keyword matching, no install needed)\n *\n * QMD modes:\n * - \"query\" (default): BM25 + vector + expansion + reranking (~5s, best quality)\n * - \"search\": BM25 keyword (~50ms, fast)\n * - \"vsearch\": Vector similarity only (~2s, semantic)\n *\n * For \"search\" (fast) mode, QMD BM25 doesn't support CJK tokenization,\n * so we supplement with grep to cover Chinese/Japanese/Korean.\n */\nexport async function search(\n query: string,\n collection: string = \"vault\",\n n: number = 5,\n mode: SearchMode = \"query\",\n): Promise<SearchResult[]> {\n // Fallback to built-in search when QMD is not available\n if (!(await isQmdAvailable())) {\n return builtinSearch(query, collection, n);\n }\n\n const stdout = await execQmd([\n mode,\n query,\n \"--collection\",\n collection,\n \"--json\",\n \"-n\",\n String(n),\n ]);\n\n let results = parseSearchResults(stdout);\n\n // BM25 can't tokenize CJK — supplement with grep for fast mode\n if (mode === \"search\" && results.length === 0 && hasCjk(query)) {\n results = await grepFallback(query, collection, n);\n }\n\n return results;\n}\n\n/**\n * Built-in keyword search — zero external dependencies.\n * Reads markdown files and does case-insensitive substring matching.\n * Good enough for small-medium collections (< 10k files).\n */\nasync function builtinSearch(\n query: string,\n collection: string,\n n: number,\n): Promise<SearchResult[]> {\n const baseDir = collection === \"raw\" ? getRawDir() : getVaultDir();\n\n // Try grep first (fast, available on all unix systems)\n const grepResults = await grepFallback(query, collection, n);\n if (grepResults.length > 0) return grepResults;\n\n // Final fallback: pure Node.js file scan (no external tools at all)\n return nodeFsSearch(query, baseDir, collection, n);\n}\n\n/**\n * Pure Node.js file search — absolute zero dependencies.\n * Recursively reads .md files and matches query as case-insensitive substring.\n */\nasync function nodeFsSearch(\n query: string,\n baseDir: string,\n collection: string,\n n: number,\n): Promise<SearchResult[]> {\n const results: SearchResult[] = [];\n const queryLower = query.toLowerCase();\n\n async function walk(dir: string): Promise<void> {\n let entries;\n try {\n entries = await fs.readdir(dir, { withFileTypes: true });\n } catch {\n return;\n }\n for (const entry of entries) {\n if (results.length >= n) return;\n const full = path.join(dir, entry.name);\n if (entry.isDirectory()) {\n await walk(full);\n } else if (entry.name.endsWith(\".md\")) {\n try {\n const content = await fs.readFile(full, \"utf-8\");\n const idx = content.toLowerCase().indexOf(queryLower);\n if (idx !== -1) {\n const snippetStart = Math.max(0, idx - 40);\n const snippetEnd = Math.min(content.length, idx + query.length + 120);\n const snippet = content.slice(snippetStart, snippetEnd).replace(/\\n/g, \" \").trim();\n const titleMatch = content.match(/^#\\s+(.+)/m);\n const relative = path.relative(baseDir, full);\n results.push({\n file: `${collection}/${relative}`,\n title: titleMatch?.[1]?.trim() ?? path.basename(full, \".md\"),\n snippet,\n score: 1.0,\n });\n }\n } catch {\n // Skip unreadable files\n }\n }\n }\n }\n\n await walk(baseDir);\n return results;\n}\n\n/** Parse QMD JSON search output into SearchResult[] */\nfunction parseSearchResults(stdout: string): SearchResult[] {\n try {\n const parsed = JSON.parse(stdout);\n if (!Array.isArray(parsed)) return [];\n return parsed.map((item: Record<string, unknown>) => ({\n file: (item.file as string) ?? \"\",\n title: (item.title as string) ?? undefined,\n snippet:\n (item.snippet as string) ??\n (item.content as string)?.slice(0, 200) ??\n \"\",\n score: item.score as number | undefined,\n }));\n } catch {\n return [];\n }\n}\n\n/** Check if a string contains CJK characters */\nfunction hasCjk(text: string): boolean {\n return /[\\u4e00-\\u9fff\\u3040-\\u30ff\\uac00-\\ud7af]/.test(text);\n}\n\n/**\n * grep fallback for CJK text that BM25 can't tokenize.\n * Runs: grep -rl \"query\" <dir> --include=\"*.md\"\n * Then reads matched files and extracts context.\n */\nasync function grepFallback(\n query: string,\n collection: string,\n n: number,\n): Promise<SearchResult[]> {\n const baseDir = collection === \"raw\" ? getRawDir() : getVaultDir();\n\n // grep -rl: recursive, list filenames only\n const stdout = await new Promise<string>((resolve) => {\n execFile(\n \"grep\",\n [\"-rl\", \"--include=*.md\", query, baseDir],\n { encoding: \"utf-8\", timeout: 5_000 },\n (_err, out) => {\n // grep exits 1 when no matches — that's fine\n resolve(out ?? \"\");\n },\n );\n });\n\n if (!stdout.trim()) return [];\n\n const files = stdout.trim().split(\"\\n\").slice(0, n);\n const results: SearchResult[] = [];\n\n for (const filePath of files) {\n if (!filePath) continue;\n // Get context line with grep -m1 (first match with surrounding text)\n const context = await new Promise<string>((resolve) => {\n execFile(\n \"grep\",\n [\"-m1\", \"-C1\", query, filePath],\n { encoding: \"utf-8\", timeout: 2_000 },\n (_err, out) => resolve(out ?? \"\"),\n );\n });\n\n const snippet = context.replace(/\\n/g, \" \").trim().slice(0, 160);\n const relative = path.relative(baseDir, filePath);\n // Extract title: first H1 line via grep\n const titleLine = await new Promise<string>((resolve) => {\n execFile(\n \"grep\",\n [\"-m1\", \"^# \", filePath],\n { encoding: \"utf-8\", timeout: 1_000 },\n (_err, out) => resolve(out?.replace(/^#\\s+/, \"\").trim() ?? \"\"),\n );\n });\n\n results.push({\n file: `qmd://${collection}/${relative}`,\n title: titleLine || path.basename(filePath, \".md\"),\n snippet,\n score: 1.0,\n });\n }\n\n return results;\n}\n\n/** Update QMD index: runs `qmd update` + `qmd embed` */\nexport async function updateIndex(): Promise<void> {\n if (!(await isQmdAvailable())) {\n throw new Error(\n \"QMD is not installed. Built-in search works without indexing.\\n\" +\n \"For better search quality, install QMD: npm install -g https://github.com/tobi/qmd\",\n );\n }\n await execQmd([\"update\"]);\n await execQmd([\"embed\"]);\n}\n","import fs from \"node:fs/promises\";\nimport OpenAI from \"openai\";\nimport { loadConfig } from \"../config/index.js\";\nimport { getPreferencesPath } from \"../config/paths.js\";\nimport type { PaiConfig } from \"../config/index.js\";\n\nlet cachedConfig: PaiConfig | null = null;\nlet cachedPreferences: string | null = null;\n\nasync function getConfig(): Promise<PaiConfig> {\n if (!cachedConfig) {\n cachedConfig = await loadConfig();\n }\n return cachedConfig;\n}\n\n/** Load user preferences.md (cached per process) */\nasync function getPreferences(): Promise<string> {\n if (cachedPreferences !== null) return cachedPreferences;\n try {\n cachedPreferences = await fs.readFile(getPreferencesPath(), \"utf-8\");\n } catch {\n cachedPreferences = \"\";\n }\n return cachedPreferences;\n}\n\n/** Create an OpenAI-compatible client from config */\nexport async function createLlmClient(): Promise<OpenAI> {\n const config = await getConfig();\n const apiKey = process.env[config.llm.apiKeyEnv];\n if (!apiKey) {\n throw new Error(\n `Missing API key: set ${config.llm.apiKeyEnv} environment variable`,\n );\n }\n return new OpenAI({\n apiKey,\n baseURL: config.llm.baseUrl || undefined,\n });\n}\n\n/**\n * Single LLM call with system + user messages.\n * Automatically prepends user preferences to the system prompt.\n * Retries once on failure.\n */\nexport async function llmCall(\n prompt: string,\n system: string,\n model?: string,\n): Promise<string> {\n const config = await getConfig();\n const client = await createLlmClient();\n const modelName = model ?? config.llm.cheapModel;\n\n // Inject user preferences into system prompt\n const prefs = await getPreferences();\n const fullSystem = prefs\n ? `${system}\\n\\n---USER PREFERENCES (always respect these)---\\n${prefs}`\n : system;\n\n for (let attempt = 0; attempt < 2; attempt++) {\n try {\n const response = await client.chat.completions.create({\n model: modelName,\n messages: [\n { role: \"system\", content: fullSystem },\n { role: \"user\", content: prompt },\n ],\n temperature: 0.3,\n });\n return response.choices[0]?.message?.content ?? \"\";\n } catch (err) {\n if (attempt === 0) {\n // Retry once\n await new Promise((r) => setTimeout(r, 1000));\n continue;\n }\n throw err;\n }\n }\n return \"\"; // unreachable\n}\n\n/** Reset cached config and preferences (for testing) */\nexport function resetConfigCache(): void {\n cachedConfig = null;\n cachedPreferences = null;\n}\n","/** Build system prompt for the PINData extract step (replaces triage + distill) */\nexport function extractSystemPrompt(): string {\n return `Extract PINData entries from the input. Each entry is ONE atomic piece of personal knowledge.\n\nEntry types:\n- fact: concrete data point (name, number, date, account, version, error, relationship)\n- pref: implied choice or habit (tool preference, workflow pattern, interest signal)\n- decision: explicit decision with reasoning\n- entity: person, organization, or project with attributes\n- event: time-bound occurrence (meeting, deployment, payment, conference)\n\nTopic routing (pick the best fit):\n- context/identity — user's name, email, linked accounts\n- context/projects — project/repo/app names, deployments, tech stack\n- context/services — services/tools used, account IDs, subscriptions\n- preferences/tools — tool choices and why (e.g. Vercel for hosting, Airtable for PM)\n- preferences/workflow — work habits, communication style, patterns\n- work/activity — tasks, assignments, colleagues, meetings\n- work/finance — invoices, payments, amounts, subscriptions\n- life/interests — interests, events, communities, conferences\n- coding/lessons — coding lessons, debugging insights, tech decisions\n\nRules:\n- Each entry.content = ONE concrete fact with names/numbers/dates. Never generic advice.\n- Return [] (empty array) if input is pure marketing/spam with zero personal signal.\n- Prefer multiple small entries over one big entry.\n- Do NOT extract generic platitudes like \"monitor deployments regularly\".\n\nExamples:\n\nInput: \"Vercel: Failed deployment for pin-sandman on team pinai\"\nOutput: [\n {\"type\":\"fact\",\"content\":\"pin-sandman: Vercel production deployment failed, team pinai\",\"topic\":\"context/projects\",\"tags\":[\"vercel\",\"pin-sandman\"]},\n {\"type\":\"pref\",\"content\":\"Vercel: used for production deployment\",\"topic\":\"preferences/tools\",\"tags\":[\"vercel\"]}\n]\n\nInput: \"50% off all shoes this weekend only!\"\nOutput: []\n\nRespond with valid JSON array only (no markdown fences).`;\n}\n\n/** Build user prompt for extract */\nexport function extractUserPrompt(rawContent: string, source?: string): string {\n const sourceHint = source ? `\\n(Source: ${source})` : \"\";\n return `Extract PINData entries from this input:\n\n---INPUT---\n${rawContent}\n---END INPUT---\n${sourceHint}\nRespond with JSON array only.`;\n}\n\n/** Build system prompt for the daily digest */\nexport function digestSystemPrompt(): string {\n return `Summarize the day's journal entries and extracted knowledge into 3-5 key bullet points.\n\nRules:\n- Each bullet = one concrete takeaway (what happened, what was decided, what matters)\n- Include names, projects, and specific details — never vague\n- If there are action items or follow-ups, list them\n- Keep it under 200 words total\n- Output plain markdown bullets only, no JSON`;\n}\n\n/** Build user prompt for digest */\nexport function digestUserPrompt(\n journalContent: string,\n newPinData: string,\n date: string,\n): string {\n return `Summarize this day (${date}):\n\n---JOURNAL---\n${journalContent || \"(no journal entries)\"}\n---END JOURNAL---\n\n---NEW KNOWLEDGE EXTRACTED---\n${newPinData || \"(no new entries)\"}\n---END KNOWLEDGE---\n\nWrite 3-5 bullet points summarizing the day.`;\n}\n","import { llmCall } from \"../llm/index.js\";\nimport { extractSystemPrompt, extractUserPrompt } from \"../prompts/extract.js\";\nimport * as console from \"../utils/console.js\";\nimport type { PINDataEntry, PINDataType, ExtractResult } from \"../types.js\";\n\nconst VALID_TYPES = new Set<string>([\"fact\", \"pref\", \"decision\", \"entity\", \"event\"]);\n\n/**\n * Budget for the total text sent to LLM.\n * ~10K chars ≈ ~2.5K tokens (English) / ~5K tokens (CJK).\n * PINData extraction only needs gist, not full content.\n */\nconst MAX_INPUT_CHARS = 10_000;\n\n/** Head portion gets the lion's share — title, intro, overview */\nconst HEAD_CHARS = 4_000;\n/** Tail portion — conclusions, takeaways, resource lists */\nconst TAIL_CHARS = 3_000;\n/** Remaining budget goes to random middle samples */\nconst MIDDLE_BUDGET = MAX_INPUT_CHARS - HEAD_CHARS - TAIL_CHARS; // 3000\n/** Number of random middle samples to pick */\nconst MIDDLE_SAMPLES = 2;\n\n// ---------------------------------------------------------------------------\n// Content preparation — sampling > chunking\n// ---------------------------------------------------------------------------\n\n/**\n * For content that fits the budget, return as-is.\n * For long content, sample: head + tail + random middle paragraphs.\n *\n * Rationale: PINData extraction asks \"what does this mean to the USER\",\n * not \"summarize the entire document\". The head (title/intro) and tail\n * (conclusions/resources) carry 80%+ of personal signal. Middle sections\n * of long articles (paper tables, code listings, repetitive data) are\n * mostly noise for personal knowledge extraction.\n */\nfunction prepareContent(text: string): string {\n if (text.length <= MAX_INPUT_CHARS) return text;\n\n const head = text.slice(0, HEAD_CHARS);\n const tail = text.slice(-TAIL_CHARS);\n\n // Middle region: everything between head and tail\n const middleStart = HEAD_CHARS;\n const middleEnd = text.length - TAIL_CHARS;\n const middleText = text.slice(middleStart, middleEnd);\n\n // Split middle into paragraphs (double newline) and pick random samples\n const paragraphs = middleText\n .split(/\\n{2,}/)\n .map((p) => p.trim())\n .filter((p) => p.length > 100); // skip tiny fragments\n\n const samples: string[] = [];\n let sampledChars = 0;\n const perSampleBudget = Math.floor(MIDDLE_BUDGET / MIDDLE_SAMPLES);\n\n if (paragraphs.length > 0) {\n // Pick evenly spaced paragraphs (deterministic, not truly random — reproducible)\n const step = Math.max(1, Math.floor(paragraphs.length / MIDDLE_SAMPLES));\n for (let i = 0; i < MIDDLE_SAMPLES && i * step < paragraphs.length; i++) {\n const para = paragraphs[i * step]!;\n const truncated = para.slice(0, perSampleBudget);\n samples.push(truncated);\n sampledChars += truncated.length;\n }\n }\n\n const middlePart =\n samples.length > 0\n ? `\\n\\n[... middle section sampled — ${(middleEnd - middleStart).toLocaleString()} chars total ...]\\n\\n${samples.join(\"\\n\\n---\\n\\n\")}`\n : \"\";\n\n const assembled = `${head}${middlePart}\\n\\n[... end section ...]\\n\\n${tail}`;\n\n console.info(\n `Content ${text.length.toLocaleString()} chars → sampled to ${assembled.length.toLocaleString()} chars ` +\n `(head:${HEAD_CHARS} + ${samples.length} mid-samples:${sampledChars} + tail:${TAIL_CHARS})`,\n );\n\n return assembled;\n}\n\n// ---------------------------------------------------------------------------\n// LLM response parsing\n// ---------------------------------------------------------------------------\n\n/** Parse one LLM JSON response into validated PINDataEntry[] */\nfunction parseExtractResponse(response: string): PINDataEntry[] {\n const cleaned = response\n .replace(/```json?\\n?/g, \"\")\n .replace(/```/g, \"\")\n .trim();\n const raw = JSON.parse(cleaned) as unknown;\n\n let rawEntries: unknown[];\n if (Array.isArray(raw)) {\n rawEntries = raw;\n } else if (\n raw &&\n typeof raw === \"object\" &&\n \"entries\" in raw &&\n Array.isArray((raw as Record<string, unknown>).entries)\n ) {\n rawEntries = (raw as Record<string, unknown>).entries as unknown[];\n } else {\n return [];\n }\n\n const entries: PINDataEntry[] = [];\n for (const item of rawEntries) {\n if (!item || typeof item !== \"object\") continue;\n const obj = item as Record<string, unknown>;\n\n const type = obj.type as string;\n const entryContent = obj.content as string;\n const topic = obj.topic as string;\n\n if (!type || !entryContent || !topic) continue;\n if (!VALID_TYPES.has(type)) continue;\n\n entries.push({\n type: type as PINDataType,\n content: entryContent.trim(),\n topic: topic.trim(),\n tags: Array.isArray(obj.tags)\n ? (obj.tags as unknown[]).filter(\n (t): t is string => typeof t === \"string\",\n )\n : undefined,\n });\n }\n\n return entries;\n}\n\n// ---------------------------------------------------------------------------\n// Public API\n// ---------------------------------------------------------------------------\n\n/**\n * Extract PINData entries from raw/journal content via a single LLM call.\n * Long content is sampled (head + tail + middle samples) to fit the budget.\n */\nexport async function extractPinData(\n content: string,\n source?: string,\n): Promise<ExtractResult> {\n const system = extractSystemPrompt();\n const prepared = prepareContent(content);\n const prompt = extractUserPrompt(prepared, source);\n\n try {\n const response = await llmCall(prompt, system);\n const entries = parseExtractResponse(response);\n\n const summary =\n entries.length > 0\n ? entries\n .slice(0, 3)\n .map((e) => e.content)\n .join(\"; \")\n : \"no extractable signal\";\n\n return { entries, summary };\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n return {\n entries: [],\n summary: `Failed to parse extract response: ${msg.slice(0, 100)}`,\n };\n }\n}\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { getVaultDir } from \"../config/paths.js\";\nimport type { PINDataEntry, PINDataType } from \"../types.js\";\n\n/** Format a PINData entry as a markdown bullet line */\nexport function formatEntry(entry: PINDataEntry, date: string, ref?: string): string {\n const parts: string[] = [];\n parts.push(date);\n if (ref) parts.push(`ref:${ref}`);\n const meta = parts.join(\" | \");\n return `- [${entry.type}] ${entry.content} (${meta})`;\n}\n\n/** Parse a PINData line back into structured data */\nexport function parsePinDataLine(line: string): {\n type: PINDataType;\n content: string;\n date?: string;\n verified?: number;\n} | null {\n // Match: - [type] content (date | optional-meta | verified:N)\n const match = line.match(\n /^- \\[(\\w+)\\] (.+?) \\((\\d{4}-\\d{2}-\\d{2})([^)]*)\\)$/,\n );\n if (!match) return null;\n\n const meta = match[4] ?? \"\";\n const verifiedMatch = meta.match(/verified:(\\d+)/);\n\n return {\n type: match[1] as PINDataType,\n content: match[2]!,\n date: match[3],\n verified: verifiedMatch ? parseInt(verifiedMatch[1]!, 10) : undefined,\n };\n}\n\n/** Check if two PINData entries are semantically duplicate (same type + similar content) */\nfunction isDuplicate(existingContent: string, newEntry: PINDataEntry): {\n lineIndex: number;\n line: string;\n} | null {\n const lines = existingContent.split(\"\\n\");\n const newLower = newEntry.content.toLowerCase();\n // Extract key tokens from new entry (remove common words)\n const newTokens = new Set(\n newLower.split(/[\\s:,;]+/).filter((t) => t.length > 2),\n );\n\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i]!;\n // Must match the same type tag\n if (!line.startsWith(`- [${newEntry.type}]`)) continue;\n\n const parsed = parsePinDataLine(line);\n if (!parsed) continue;\n\n const existLower = parsed.content.toLowerCase();\n const existTokens = new Set(\n existLower.split(/[\\s:,;]+/).filter((t) => t.length > 2),\n );\n\n // Calculate Jaccard similarity on significant tokens\n const intersection = [...newTokens].filter((t) => existTokens.has(t));\n const union = new Set([...newTokens, ...existTokens]);\n const similarity = union.size > 0 ? intersection.length / union.size : 0;\n\n // Threshold: 60% token overlap = duplicate\n if (similarity >= 0.6) {\n return { lineIndex: i, line };\n }\n }\n return null;\n}\n\n/**\n * Append PINData entries to the appropriate vault files.\n * - Routes each entry to vault/{topic}.md based on entry.topic\n * - Creates file + H1 header if new\n * - Deduplicates: if similar entry exists, bumps verified count + updates date\n * Returns number of new entries added and duplicates updated.\n */\nexport async function appendPinData(\n entries: PINDataEntry[],\n options: { date?: string; ref?: string } = {},\n): Promise<{ added: number; updated: number }> {\n const vaultDir = getVaultDir();\n const date = options.date ?? new Date().toISOString().split(\"T\")[0]!;\n let added = 0;\n let updated = 0;\n\n // Group entries by topic\n const byTopic = new Map<string, PINDataEntry[]>();\n for (const entry of entries) {\n const topic = entry.topic;\n if (!byTopic.has(topic)) byTopic.set(topic, []);\n byTopic.get(topic)!.push(entry);\n }\n\n for (const [topic, topicEntries] of byTopic) {\n const filePath = path.join(vaultDir, `${topic}.md`);\n await fs.mkdir(path.dirname(filePath), { recursive: true });\n\n // Read existing content\n let content: string;\n try {\n content = await fs.readFile(filePath, \"utf-8\");\n } catch {\n // Create new file with H1 title derived from topic\n const title = topic\n .split(\"/\")\n .pop()!\n .replace(/-/g, \" \")\n .replace(/\\b\\w/g, (c) => c.toUpperCase());\n content = `# ${title}\\n`;\n }\n\n for (const entry of topicEntries) {\n const dup = isDuplicate(content, entry);\n if (dup) {\n // Bump verified count and update date\n const parsed = parsePinDataLine(dup.line);\n const newVerified = (parsed?.verified ?? 1) + 1;\n const updatedLine = `- [${entry.type}] ${entry.content} (${date} | verified:${newVerified})`;\n const lines = content.split(\"\\n\");\n lines[dup.lineIndex] = updatedLine;\n content = lines.join(\"\\n\");\n updated++;\n } else {\n // Append new entry\n const line = formatEntry(entry, date, options.ref);\n content = content.trimEnd() + \"\\n\" + line + \"\\n\";\n added++;\n }\n }\n\n await fs.writeFile(filePath, content, \"utf-8\");\n }\n\n return { added, updated };\n}\n\n/** Read a vault file's content. Returns null if not found. */\nexport async function readVaultFile(topic: string): Promise<string | null> {\n const filePath = path.join(getVaultDir(), `${topic}.md`);\n try {\n return await fs.readFile(filePath, \"utf-8\");\n } catch {\n return null;\n }\n}\n\n/** List all PINData entries across all vault files */\nexport async function listVaultEntries(): Promise<\n Array<{ topic: string; line: string; parsed: ReturnType<typeof parsePinDataLine> }>\n> {\n const vaultDir = getVaultDir();\n const results: Array<{\n topic: string;\n line: string;\n parsed: ReturnType<typeof parsePinDataLine>;\n }> = [];\n\n async function walk(dir: string): Promise<void> {\n try {\n const entries = await fs.readdir(dir, { withFileTypes: true });\n for (const entry of entries) {\n const fullPath = path.join(dir, entry.name);\n if (entry.isDirectory()) {\n await walk(fullPath);\n } else if (entry.name.endsWith(\".md\")) {\n const topic = path.relative(vaultDir, fullPath).replace(/\\.md$/, \"\");\n const content = await fs.readFile(fullPath, \"utf-8\");\n for (const line of content.split(\"\\n\")) {\n if (line.startsWith(\"- [\")) {\n const parsed = parsePinDataLine(line);\n results.push({ topic, line, parsed });\n }\n }\n }\n }\n } catch {\n // Directory might not exist\n }\n }\n\n await walk(vaultDir);\n return results;\n}\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { getMemoryDir, getJournalPath, getTodayDate } from \"../config/paths.js\";\n\n/** Append a log entry to today's journal file (memory/YYYY-MM-DD.md) */\nexport async function appendJournal(\n text: string,\n date?: string,\n): Promise<{ path: string; entryCount: number }> {\n const targetDate = date ?? getTodayDate();\n const filePath = getJournalPath(targetDate);\n\n await fs.mkdir(getMemoryDir(), { recursive: true });\n\n const now = new Date();\n const time = now.toTimeString().slice(0, 5); // HH:MM\n const entry = `- ${time} ${text}\\n`;\n\n let existed = false;\n let existingContent = \"\";\n try {\n existingContent = await fs.readFile(filePath, \"utf-8\");\n existed = true;\n } catch {\n // File doesn't exist yet\n }\n\n if (!existed) {\n // Create new journal file with header\n const header = `# ${targetDate}\\n\\n`;\n await fs.writeFile(filePath, header + entry, \"utf-8\");\n } else {\n // Insert entry BEFORE extracted marker / digest section, and remove marker\n // so the journal will be re-processed on next distill\n const markerIdx = existingContent.indexOf(\"\\n<!-- extracted -->\");\n const digestIdx = existingContent.indexOf(\"\\n## Digest\");\n const insertIdx = Math.min(\n markerIdx >= 0 ? markerIdx : Infinity,\n digestIdx >= 0 ? digestIdx : Infinity,\n );\n\n if (insertIdx < Infinity) {\n // Insert before marker/digest, remove extracted marker\n const before = existingContent.slice(0, insertIdx).trimEnd();\n const after = existingContent.slice(insertIdx).replace(\"<!-- extracted -->\", \"\").trimStart();\n const newContent = before + \"\\n\" + entry + (after ? \"\\n\" + after : \"\") + \"\\n\";\n await fs.writeFile(filePath, newContent, \"utf-8\");\n } else {\n await fs.appendFile(filePath, entry, \"utf-8\");\n }\n }\n\n // Count entries in file\n const content = await fs.readFile(filePath, \"utf-8\");\n const entryCount = (content.match(/^- \\d{2}:\\d{2} /gm) || []).length;\n\n return { path: filePath, entryCount };\n}\n\n/** Read a journal file's content. Returns null if not found. */\nexport async function readJournal(date?: string): Promise<string | null> {\n const targetDate = date ?? getTodayDate();\n const filePath = getJournalPath(targetDate);\n try {\n return await fs.readFile(filePath, \"utf-8\");\n } catch {\n return null;\n }\n}\n\n/** List all journal dates (YYYY-MM-DD) sorted descending */\nexport async function listJournalDates(): Promise<string[]> {\n const memDir = getMemoryDir();\n try {\n const entries = await fs.readdir(memDir);\n const dates = entries\n .filter((f) => /^\\d{4}-\\d{2}-\\d{2}\\.md$/.test(f))\n .map((f) => f.replace(\".md\", \"\"))\n .sort()\n .reverse();\n return dates;\n } catch {\n return [];\n }\n}\n\n/** Get status of a journal: entry count and whether it has a digest */\nexport async function getJournalStatus(\n date: string,\n): Promise<{ entries: number; hasDigest: boolean } | null> {\n const content = await readJournal(date);\n if (!content) return null;\n\n const entries = (content.match(/^- \\d{2}:\\d{2} /gm) || []).length;\n const hasDigest = content.includes(\"## Digest\");\n return { entries, hasDigest };\n}\n\n/** Find journal dates with missing entries in the last N days */\nexport async function findGaps(days: number = 30): Promise<string[]> {\n const existing = new Set(await listJournalDates());\n const gaps: string[] = [];\n\n const now = new Date();\n for (let i = 0; i < days; i++) {\n const d = new Date(now);\n d.setDate(d.getDate() - i);\n const dateStr = d.toISOString().split(\"T\")[0]!;\n if (!existing.has(dateStr)) {\n gaps.push(dateStr);\n }\n }\n\n return gaps;\n}\n\n/** Append a digest section to a journal file */\nexport async function appendDigest(\n digest: string,\n date?: string,\n): Promise<string> {\n const targetDate = date ?? getTodayDate();\n const filePath = getJournalPath(targetDate);\n\n let content: string;\n try {\n content = await fs.readFile(filePath, \"utf-8\");\n } catch {\n // Create the file if it doesn't exist\n content = `# ${targetDate}\\n\\n`;\n }\n\n // Remove existing digest section if present (replace)\n const digestIndex = content.indexOf(\"\\n## Digest\");\n if (digestIndex !== -1) {\n content = content.slice(0, digestIndex);\n }\n\n const digestSection = `\\n## Digest\\n\\n${digest.trim()}\\n`;\n await fs.mkdir(path.dirname(filePath), { recursive: true });\n await fs.writeFile(filePath, content.trimEnd() + \"\\n\" + digestSection, \"utf-8\");\n\n return filePath;\n}\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { listPending } from \"../raw/index.js\";\nimport { extractPinData } from \"./extract.js\";\nimport { appendPinData } from \"../vault/index.js\";\nimport { readJournal } from \"../memory/index.js\";\nimport { getPaiHome, getTodayDate } from \"../config/paths.js\";\nimport { parseFrontmatter, updateRawFrontmatter } from \"../utils/frontmatter.js\";\nimport * as console from \"../utils/console.js\";\nimport type { RawFrontmatter, ExtractPipelineResult } from \"../types.js\";\n\nexport type { ExtractPipelineResult };\n\n/**\n * Run the PINData extract pipeline on pending raw files + unprocessed journals.\n * Flow: raw/journal content → 1 LLM extract call → PINData[] → code-append to vault\n */\nexport async function distillPipeline(\n options: { dryRun?: boolean; singleFile?: string; today?: boolean } = {},\n): Promise<ExtractPipelineResult> {\n const result: ExtractPipelineResult = {\n processed: 0,\n extracted: 0,\n discarded: 0,\n errors: [],\n };\n\n // Collect inputs: pending raw files + today's journal\n const inputs: Array<{ label: string; content: string; rawPath?: string; source: string }> = [];\n\n // 1) Pending raw files\n if (options.singleFile) {\n const raw = await fs.readFile(options.singleFile, \"utf-8\");\n const { content } = parseFrontmatter<RawFrontmatter>(raw);\n inputs.push({\n label: path.basename(options.singleFile),\n content,\n rawPath: options.singleFile,\n source: options.singleFile,\n });\n } else if (!options.today) {\n const pendingFiles = await listPending();\n for (const filePath of pendingFiles) {\n const raw = await fs.readFile(filePath, \"utf-8\");\n const { content } = parseFrontmatter<RawFrontmatter>(raw);\n inputs.push({\n label: path.basename(filePath),\n content,\n rawPath: filePath,\n source: filePath,\n });\n }\n }\n\n // 2) Today's journal (if --today or default run)\n if (!options.singleFile) {\n const todayDate = getTodayDate();\n const journal = await readJournal(todayDate);\n if (journal && journal.trim().length > 0) {\n // Only include if not already processed (check for marker)\n if (!journal.includes(\"<!-- extracted -->\")) {\n inputs.push({\n label: `journal/${todayDate}`,\n content: journal,\n source: `memory/${todayDate}.md`,\n });\n }\n }\n }\n\n if (inputs.length === 0) {\n console.info(\"No pending raw files or journal entries to process.\");\n return result;\n }\n\n console.info(`Found ${inputs.length} input(s) to process.`);\n\n for (const input of inputs) {\n const spin = console.spinner(`Extracting ${input.label}...`);\n\n try {\n // Single LLM call: extract PINData entries\n const extracted = await extractPinData(input.content, input.source);\n result.processed++;\n\n if (extracted.entries.length === 0) {\n spin.succeed(`Skipped: ${input.label} — ${extracted.summary}`);\n result.discarded++;\n\n // Mark raw file as discarded\n if (input.rawPath && !options.dryRun) {\n const rawContent = await fs.readFile(input.rawPath, \"utf-8\");\n const updated = updateRawFrontmatter(rawContent, { status: \"discarded\" });\n await fs.writeFile(input.rawPath, updated, \"utf-8\");\n }\n continue;\n }\n\n if (options.dryRun) {\n const topics = [...new Set(extracted.entries.map((e) => e.topic))];\n spin.succeed(\n `[DRY RUN] ${input.label} → ${extracted.entries.length} entries → ${topics.join(\", \")}`,\n );\n result.extracted += extracted.entries.length;\n continue;\n }\n\n // Code-controlled append to vault files (no LLM merge needed)\n const date = new Date().toISOString().split(\"T\")[0]!;\n const { added, updated } = await appendPinData(extracted.entries, {\n date,\n ref: input.source,\n });\n\n result.extracted += extracted.entries.length;\n const topics = [...new Set(extracted.entries.map((e) => e.topic))];\n\n // Mark raw file as processed\n if (input.rawPath) {\n const rawContent = await fs.readFile(input.rawPath, \"utf-8\");\n const updatedRaw = updateRawFrontmatter(rawContent, {\n status: \"processed\",\n distilled_to: topics.join(\", \"),\n });\n await fs.writeFile(input.rawPath, updatedRaw, \"utf-8\");\n }\n\n // Mark journal as extracted\n if (!input.rawPath && input.source.startsWith(\"memory/\")) {\n const journalPath = path.join(getPaiHome(), input.source);\n try {\n const journalContent = await fs.readFile(journalPath, \"utf-8\");\n if (!journalContent.includes(\"<!-- extracted -->\")) {\n await fs.appendFile(journalPath, \"\\n<!-- extracted -->\\n\", \"utf-8\");\n }\n } catch {\n // Journal file might not exist\n }\n }\n\n spin.succeed(\n `Extracted ${input.label} → ${added} new, ${updated} updated → ${topics.join(\", \")}`,\n );\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n spin.fail(`Error processing ${input.label}: ${msg}`);\n result.errors.push(`${input.label}: ${msg}`);\n }\n }\n\n return result;\n}\n","/** Build system prompt for SKILL.md generation */\nexport function generateSystemPrompt(): string {\n return `You generate a SKILL.md — a minimal, high-density context file for an AI agent to understand the user.\nEvery line MUST be useful to an AI agent. If a line wouldn't change how an agent responds, delete it.\n\nCOMPRESSION RULES:\n- Identity: pack into 2-3 lines max (name | email | role | languages | timezone — merge onto fewer lines)\n- Preferences: write as \"prefers X for Y\" not just \"uses X\". State the WHY or CONTEXT.\n GOOD: \"Deploys on Vercel (team pinai), manages tasks in Airtable, meetings via Zoom (paid)\"\n BAD: \"Tools: Vercel, Zoom, Docker, npm, Airtable\" (just a list, no context)\n- Interests: compress bookmarks/domains/events into TAGS, not raw lists\n GOOD: \"Interests: AI/LLM, Web3 (ETHDenver 2026), GIS, iOS, prediction markets (Kalshi)\"\n BAD: \"Bookmarks: Favorites Bar 106项, Read 78项, Tools 67项...\" (raw data dump)\n- Current Work: what are they ACTIVELY building? Project names + what they do, not directory paths\n GOOD: \"Building personal-ai (v0.1.0, npm published), PINAI ecosystem (PIN-APP-IOS, pin-sandman on Vercel)\"\n BAD: \"Recent Working Directories: ..: 8次, backend: 2次\"\n- Lessons: ONLY copy verbatim lessons that exist in vault/coding/ or vault/work/ files.\n NEVER INVENT OR PARAPHRASE lessons. If the vault has no explicit lesson, write \"None recorded yet.\"\n A deployment failure is a FACT (goes in Current Work), NOT a lesson.\n GOOD: \"FastAPI CORS: must explicitly list allowed_origins, wildcard doesn't work with credentials\"\n BAD: \"生产环境部署失败可能导致项目延误\" ← THIS IS INVENTED, NEVER DO THIS\n BAD: \"及时关注部署通知有助于快速定位问题\" ← THIS IS GENERIC ADVICE, NEVER DO THIS\n- Financial/services: compress into 1-2 lines\n GOOD: \"Paid services: Zoom (acct 5144380543), BytePlus (acct 3000767749, ~200 USD credits)\"\n- Team: mention key collaborators briefly\n GOOD: \"Works with Ethan Liu (pinai team) on Prediction project via Airtable\"\n\nANTI-PATTERNS — never do these:\n- Raw data dumps (bookmark counts, domain visit counts, directory lists)\n- Generic advice disguised as lessons\n- Separate lines for each identity field (merge them)\n- Lists of tool names without context on how/why they're used\n- \"Account Activities\" as a separate section (fold into Preferences or Current Work)`;\n}\n\n/** Build user prompt for SKILL.md generation */\nexport function generateUserPrompt(\n profileName: string,\n vaultContents: string,\n maxLines: number,\n): string {\n return `Generate SKILL.md \"${profileName}\" from vault content. Max ${maxLines} lines.\n\nSections:\n# Personal Context — ${profileName}\n## Who I Am (2-4 lines: identity, languages, timezone — packed dense)\n## Preferences (tool choices WITH context, workflow habits, communication style)\n## Interests (compressed tags from bookmarks/domains/events, NOT raw lists)\n## Current Work (active projects with names, what they do, team members)\n## Paid Services (services with account IDs, amounts — 1-3 lines)\n## Hard-won Lessons (ONLY real lessons from vault, or 1 line \"None yet\")\n\n---VAULT CONTENT---\n${vaultContents}\n---END VAULT CONTENT---\n\nCRITICAL: Compress, don't dump. Every line must be useful to an AI agent.\n- Merge identity fields onto fewer lines (name | email | timezone on one line)\n- Write preferences as \"prefers X for Y\" not bare lists\n- Convert bookmark counts and domain visits into interest TAGS\n- Never write generic advice as lessons\n- Never write raw data (dir paths, bookmark counts, visit numbers)`;\n}\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { minimatch } from \"minimatch\";\nimport { loadProfiles } from \"../config/io.js\";\nimport { getVaultDir, getSkillsDir } from \"../config/paths.js\";\nimport { llmCall } from \"../llm/index.js\";\nimport {\n generateSystemPrompt,\n generateUserPrompt,\n} from \"../prompts/generate.js\";\nimport * as console from \"../utils/console.js\";\n\n/** Recursively list all markdown files in a directory */\nasync function walkMd(dir: string): Promise<string[]> {\n const results: 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 results.push(...(await walkMd(full)));\n } else if (entry.name.endsWith(\".md\")) {\n results.push(full);\n }\n }\n } catch {\n // Ignore errors\n }\n return results;\n}\n\n/** Collect vault file contents matching scope patterns */\nasync function collectVaultContent(scope: string[]): Promise<string> {\n const vaultDir = getVaultDir();\n const allFiles = await walkMd(vaultDir);\n const matched: string[] = [];\n\n for (const file of allFiles) {\n const relative = \"vault/\" + path.relative(vaultDir, file);\n // Check if this file matches any scope pattern\n for (const pattern of scope) {\n if (minimatch(relative, pattern)) {\n matched.push(file);\n break;\n }\n }\n }\n\n // Read and concatenate all matched files\n const contents: string[] = [];\n for (const file of matched) {\n try {\n const content = await fs.readFile(file, \"utf-8\");\n contents.push(`--- ${path.relative(vaultDir, file)} ---\\n${content}`);\n } catch {\n // Skip unreadable files\n }\n }\n\n return contents.join(\"\\n\\n\");\n}\n\n/** Generate a single SKILL.md profile */\nexport async function generateProfile(profileName: string): Promise<string> {\n const profiles = await loadProfiles();\n const profileDef = profiles.profiles[profileName];\n\n if (!profileDef) {\n throw new Error(`Profile \"${profileName}\" not found in profiles.json5`);\n }\n\n const vaultContent = await collectVaultContent(profileDef.scope);\n\n if (!vaultContent.trim()) {\n throw new Error(\n `No vault content found for profile \"${profileName}\". Run 'pai distill' first.`,\n );\n }\n\n const system = generateSystemPrompt();\n const prompt = generateUserPrompt(\n profileName,\n vaultContent,\n profileDef.maxLines,\n );\n\n const skillMd = await llmCall(prompt, system);\n\n // Write to skills/profiles/\n const skillsDir = getSkillsDir();\n await fs.mkdir(skillsDir, { recursive: true });\n const outPath = path.join(skillsDir, `${profileName}.md`);\n await fs.writeFile(outPath, skillMd.trim() + \"\\n\", \"utf-8\");\n\n return outPath;\n}\n\n/** Generate all profiles defined in profiles.json5 */\nexport async function generateAll(): Promise<string[]> {\n const profiles = await loadProfiles();\n const profileNames = Object.keys(profiles.profiles);\n\n if (profileNames.length === 0) {\n console.warn(\"No profiles defined in profiles.json5\");\n return [];\n }\n\n const results: string[] = [];\n for (const name of profileNames) {\n const spin = console.spinner(`Generating profile: ${name}...`);\n try {\n const outPath = await generateProfile(name);\n spin.succeed(`Generated ${name} → ${outPath}`);\n results.push(outPath);\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n spin.fail(`Failed to generate ${name}: ${msg}`);\n }\n }\n\n return results;\n}\n","/**\n * Profile compiler — transforms raw CollectorResult[] into a structured profile.md.\n * Zero LLM dependency: pure template + data formatting.\n */\n\nimport type { CollectorResult } from \"../types.js\";\n\n/** Mapping from collector IDs to profile sections */\ninterface SectionDef {\n heading: string;\n /** Collector IDs that feed this section (in order) */\n collectors: string[];\n}\n\nconst PROFILE_SECTIONS: SectionDef[] = [\n {\n heading: \"Identity\",\n collectors: [\"identity-profile\", \"github-profile\"],\n },\n {\n heading: \"Environment & Tools\",\n collectors: [\"dev-environment\", \"dev-preferences\"],\n },\n {\n heading: \"Work Style & Habits\",\n collectors: [\"shell-habits\", \"coding-rules\"],\n },\n {\n heading: \"Active Projects & Recent Focus\",\n collectors: [\"active-projects\", \"recent-focus\"],\n },\n {\n heading: \"Digital Footprint\",\n collectors: [\"browser-bookmarks\", \"browser-domains\", \"productivity-setup\"],\n },\n {\n heading: \"Registry & Cloud Accounts\",\n collectors: [\"social-profiles\"],\n },\n {\n heading: \"Context\",\n collectors: [\"calendar-context\", \"file-organization\"],\n },\n];\n\n/**\n * Compile CollectorResult[] into a structured profile markdown string.\n * No LLM involved — pure formatting.\n */\nexport function compileProfile(results: CollectorResult[]): string {\n const index = new Map<string, CollectorResult>();\n for (const r of results) {\n index.set(r.id, r);\n }\n\n const sections: string[] = [\"# Personal Profile\", \"\"];\n\n for (const section of PROFILE_SECTIONS) {\n const parts: string[] = [];\n\n for (const cid of section.collectors) {\n const result = index.get(cid);\n if (result?.content?.trim()) {\n parts.push(result.content.trim());\n }\n }\n\n if (parts.length === 0) continue;\n\n sections.push(`## ${section.heading}`, \"\");\n sections.push(parts.join(\"\\n\\n\"));\n sections.push(\"\");\n }\n\n // Append any collectors not covered by the predefined sections\n const coveredIds = new Set(PROFILE_SECTIONS.flatMap((s) => s.collectors));\n const extras: string[] = [];\n\n for (const r of results) {\n if (!coveredIds.has(r.id) && r.content?.trim()) {\n extras.push(`## ${r.title}`, \"\", r.content.trim(), \"\");\n }\n }\n\n if (extras.length > 0) {\n sections.push(...extras);\n }\n\n // Footer\n sections.push(\"---\");\n sections.push(`Last updated: ${new Date().toISOString()}`);\n sections.push(\"\");\n\n return sections.join(\"\\n\");\n}\n\n/**\n * Generate a compact profile summary suitable for agent injection.\n * Strips verbose sub-sections and keeps high-signal data only.\n */\nexport function compileCompactProfile(results: CollectorResult[]): string {\n const index = new Map<string, CollectorResult>();\n for (const r of results) {\n index.set(r.id, r);\n }\n\n const parts: string[] = [\"# Personal Profile (Compact)\", \"\"];\n\n // Identity — always include in full\n const identity = index.get(\"identity-profile\");\n if (identity?.content?.trim()) {\n parts.push(identity.content.trim(), \"\");\n }\n\n // Dev environment — keep runtime versions and package managers\n const devEnv = index.get(\"dev-environment\");\n if (devEnv?.content?.trim()) {\n parts.push(devEnv.content.trim(), \"\");\n }\n\n // Active projects — keep repo list\n const projects = index.get(\"active-projects\");\n if (projects?.content?.trim()) {\n parts.push(projects.content.trim(), \"\");\n }\n\n // Shell habits — keep top commands only\n const habits = index.get(\"shell-habits\");\n if (habits?.content?.trim()) {\n // Take only the first 15 lines (header + top commands)\n const lines = habits.content.trim().split(\"\\n\");\n parts.push(lines.slice(0, 17).join(\"\\n\"), \"\");\n }\n\n parts.push(\"---\");\n parts.push(`Last updated: ${new Date().toISOString()}`);\n parts.push(\"\");\n\n return parts.join(\"\\n\");\n}\n","/**\n * Security sanitization utilities for connector-scanned content.\n * Strips secrets, credentials, and sensitive paths before writing to raw layer.\n */\n\n/** Pattern matching shell export lines containing secrets */\nconst SECRET_EXPORT_RE =\n /^(\\s*export\\s+)\\w*(KEY|TOKEN|SECRET|PASSWORD|CREDENTIAL|PASSWD)\\w*\\s*=.*/i;\n\n/** Pattern matching lines that look like inline secret assignments (no export) */\nconst SECRET_ASSIGN_RE =\n /^\\s*\\w*(KEY|TOKEN|SECRET|PASSWORD|CREDENTIAL|PASSWD)\\w*\\s*=\\s*[\"']?\\S+/i;\n\n/**\n * Strip secret export/assignment lines from shell config content.\n * Preserves comments and non-secret lines intact.\n */\nexport function stripSecretExports(content: string): string {\n return content\n .split(\"\\n\")\n .map((line) => {\n if (SECRET_EXPORT_RE.test(line) || SECRET_ASSIGN_RE.test(line)) {\n return \"# [REDACTED by pai — secret removed]\";\n }\n return line;\n })\n .join(\"\\n\");\n}\n\n/**\n * Strip [credential] sections from git config content.\n * Removes the section header and all lines until the next section.\n */\nexport function stripGitCredentials(content: string): string {\n const lines = content.split(\"\\n\");\n const result: string[] = [];\n let inCredentialSection = false;\n\n for (const line of lines) {\n // Detect section headers like [credential] or [credential \"...\"]\n if (/^\\s*\\[credential/i.test(line)) {\n inCredentialSection = true;\n result.push(\"# [REDACTED by pai — credential section removed]\");\n continue;\n }\n // New section starts → exit credential section\n if (inCredentialSection && /^\\s*\\[/.test(line)) {\n inCredentialSection = false;\n }\n if (!inCredentialSection) {\n result.push(line);\n }\n }\n\n return result.join(\"\\n\");\n}\n\n/**\n * Strip IdentityFile lines from SSH config.\n * Keeps Host, HostName, User, Port — removes key paths.\n */\nexport function stripSshIdentityFiles(content: string): string {\n return content\n .split(\"\\n\")\n .map((line) => {\n if (/^\\s*IdentityFile\\s/i.test(line)) {\n return \" # [REDACTED by pai — IdentityFile removed]\";\n }\n return line;\n })\n .join(\"\\n\");\n}\n","/**\n * Mac system context collectors.\n * Each collector gathers a specific category of personalized context\n * from the local macOS environment and returns a CollectorResult.\n */\n\nimport { execFile } from \"node:child_process\";\nimport fs from \"node:fs/promises\";\nimport os from \"node:os\";\nimport path from \"node:path\";\nimport type { CollectorResult } from \"../../types.js\";\nimport {\n stripSecretExports,\n stripGitCredentials,\n stripSshIdentityFiles,\n} from \"../sanitize.js\";\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\n/** Run a shell command and return stdout (empty string on failure) */\nasync function exec(cmd: string, args: string[]): Promise<string> {\n return new Promise((resolve) => {\n execFile(cmd, args, { encoding: \"utf-8\", timeout: 15_000 }, (err, stdout) => {\n resolve(err ? \"\" : stdout.trim());\n });\n });\n}\n\n/** Read a file, return empty string on failure */\nasync function readSafe(filePath: string): Promise<string> {\n try {\n return await fs.readFile(filePath, \"utf-8\");\n } catch {\n return \"\";\n }\n}\n\n/** Check if path exists */\nasync function exists(p: string): Promise<boolean> {\n try {\n await fs.access(p);\n return true;\n } catch {\n return false;\n }\n}\n\n/** Run osascript and return output */\nasync function osascript(script: string): Promise<string> {\n return exec(\"osascript\", [\"-e\", script]);\n}\n\n/** Run defaults read and return output */\nasync function defaultsRead(...args: string[]): Promise<string> {\n return exec(\"defaults\", [\"read\", ...args]);\n}\n\nconst HOME = os.homedir();\n\n// ---------------------------------------------------------------------------\n// 1. Identity Profile\n// ---------------------------------------------------------------------------\n\nexport async function collectIdentityProfile(): Promise<CollectorResult> {\n const lines: string[] = [\"## User Identity\"];\n\n // macOS username\n const username = await exec(\"id\", [\"-un\"]);\n if (username) lines.push(`- macOS Username: ${username}`);\n\n // Real name from directory service\n const realName = await exec(\"dscl\", [\".\", \"-read\", `/Users/${username}`, \"RealName\"]);\n const nameMatch = realName.split(\"\\n\").find((l) => l.trim() && !l.includes(\"RealName\"));\n if (nameMatch?.trim()) lines.push(`- Real Name (local): ${nameMatch.trim()}`);\n\n // Apple ID / iCloud\n const mobileMe = await defaultsRead(\"MobileMeAccounts\");\n const appleIdMatch = mobileMe.match(/AccountID\\s*=\\s*\"?([^\";\\n]+)/);\n const displayNameMatch = mobileMe.match(/DisplayName\\s*=\\s*\"?([^\";\\n]+)/);\n if (displayNameMatch) lines.push(`- Apple ID Display Name: ${displayNameMatch[1].trim()}`);\n if (appleIdMatch) lines.push(`- Apple ID: ${appleIdMatch[1].trim()}`);\n\n // Computer name\n const computerName = await exec(\"scutil\", [\"--get\", \"ComputerName\"]);\n if (computerName) lines.push(`- Computer Name: ${computerName}`);\n\n // Git identity\n const gitName = await exec(\"git\", [\"config\", \"--global\", \"user.name\"]);\n const gitEmail = await exec(\"git\", [\"config\", \"--global\", \"user.email\"]);\n if (gitName) lines.push(`- Git Name: ${gitName}`);\n if (gitEmail) lines.push(`- Git Email: ${gitEmail}`);\n\n // Locale & Language\n lines.push(\"\", \"## Locale & Language\");\n const langs = await defaultsRead(\"NSGlobalDomain\", \"AppleLanguages\");\n const langList = langs.match(/\"([^\"]+)\"/g)?.map((s) => s.replace(/\"/g, \"\")) ?? [];\n if (langList.length > 0) lines.push(`- Languages: ${langList.join(\", \")}`);\n\n const locale = await defaultsRead(\"NSGlobalDomain\", \"AppleLocale\");\n if (locale) lines.push(`- Locale: ${locale}`);\n\n // Input methods\n const inputSources = await defaultsRead(\"com.apple.HIToolbox\", \"AppleSelectedInputSources\");\n const inputMethods = inputSources.match(/\"Input Mode\"\\s*=\\s*\"([^\"]+)\"/g) ?? [];\n const bundleIds = inputSources.match(/\"Bundle ID\"\\s*=\\s*\"([^\"]+)\"/g) ?? [];\n const inputs = [...inputMethods, ...bundleIds]\n .map((s) => s.replace(/.*\"([^\"]+)\"$/, \"$1\"))\n .filter((s) => !s.includes(\"PressAndHold\"));\n if (inputs.length > 0) lines.push(`- Input Methods: ${inputs.join(\", \")}`);\n\n // System appearance\n const appearance = await defaultsRead(\"-g\", \"AppleInterfaceStyle\");\n lines.push(`- System Appearance: ${appearance || \"Light\"}`);\n\n // Timezone\n const tz = Intl.DateTimeFormat().resolvedOptions().timeZone;\n lines.push(`- Timezone: ${tz}`);\n\n return {\n id: \"identity-profile\",\n title: \"Mac User Identity Profile\",\n content: lines.join(\"\\n\"),\n };\n}\n\n// ---------------------------------------------------------------------------\n// 2. Calendar Context\n// ---------------------------------------------------------------------------\n\nexport async function collectCalendarContext(): Promise<CollectorResult> {\n let calNames: string[] = [];\n const raw = await osascript(\n 'tell application \"Calendar\" to get name of every calendar',\n );\n if (raw) {\n calNames = raw.split(\", \").map((s) => s.trim()).filter(Boolean);\n }\n\n const lines = [\n \"## Calendar Subscriptions\",\n \"\",\n `Total calendars: ${calNames.length}`,\n \"\",\n ...calNames.map((name) => `- ${name}`),\n ];\n\n return {\n id: \"calendar-context\",\n title: \"Calendar Context\",\n content: calNames.length > 0\n ? lines.join(\"\\n\")\n : \"No calendar data accessible (Calendar app may not be running).\",\n };\n}\n\n// ---------------------------------------------------------------------------\n// 3. File Organization\n// ---------------------------------------------------------------------------\n\nexport async function collectFileOrganization(): Promise<CollectorResult> {\n const lines: string[] = [];\n\n // Documents top-level folders\n const docsDir = path.join(HOME, \"Documents\");\n try {\n const entries = await fs.readdir(docsDir, { withFileTypes: true });\n const dirs = entries.filter((e) => e.isDirectory()).map((e) => e.name);\n lines.push(\"## Documents Folders\", \"\", ...dirs.map((d) => `- ${d}`));\n } catch {\n lines.push(\"## Documents Folders\", \"\", \"(not accessible)\");\n }\n\n // Desktop items\n const desktopDir = path.join(HOME, \"Desktop\");\n try {\n const entries = await fs.readdir(desktopDir);\n lines.push(\"\", \"## Desktop Items\", \"\", ...entries.slice(0, 20).map((e) => `- ${e}`));\n if (entries.length > 20) lines.push(`- ... and ${entries.length - 20} more`);\n } catch {\n lines.push(\"\", \"## Desktop Items\", \"\", \"(not accessible)\");\n }\n\n // Recent downloads (file names only)\n const dlDir = path.join(HOME, \"Downloads\");\n try {\n const entries = await fs.readdir(dlDir);\n // Sort by name only (stat would be slow), take first 15\n lines.push(\n \"\",\n \"## Recent Downloads (latest 15 by name)\",\n \"\",\n ...entries.slice(0, 15).map((e) => `- ${e}`),\n );\n } catch {\n lines.push(\"\", \"## Recent Downloads\", \"\", \"(not accessible)\");\n }\n\n return {\n id: \"file-organization\",\n title: \"File Organization Structure\",\n content: lines.join(\"\\n\"),\n };\n}\n\n// ---------------------------------------------------------------------------\n// 4. Dev Environment\n// ---------------------------------------------------------------------------\n\nexport async function collectDevEnvironment(): Promise<CollectorResult> {\n const lines: string[] = [\"## Runtime Versions\"];\n\n // Language runtimes\n const runtimes: [string, string, string[]][] = [\n [\"Node.js\", \"node\", [\"--version\"]],\n [\"Python\", \"python3\", [\"--version\"]],\n [\"Go\", \"go\", [\"version\"]],\n [\"Rust\", \"rustc\", [\"--version\"]],\n [\"Java\", \"java\", [\"--version\"]],\n ];\n\n for (const [name, cmd, args] of runtimes) {\n const ver = await exec(cmd, args);\n if (ver) {\n // Extract just the version string\n const first = ver.split(\"\\n\")[0] ?? ver;\n lines.push(`- ${name}: ${first}`);\n }\n }\n\n // Package managers\n lines.push(\"\", \"## Package Managers\");\n const pkgMgrs = [\"brew\", \"pnpm\", \"npm\", \"pip3\", \"cargo\"];\n for (const pm of pkgMgrs) {\n const which = await exec(\"which\", [pm]);\n if (which) lines.push(`- ${pm}: ${which}`);\n }\n\n // Docker\n const docker = await exec(\"docker\", [\"--version\"]);\n if (docker) lines.push(\"\", \"## Docker\", \"\", `- ${docker}`);\n\n // Shell info\n lines.push(\"\", \"## Shell\");\n const shell = process.env.SHELL ?? \"\";\n lines.push(`- Shell: ${shell}`);\n const zshrc = await readSafe(path.join(HOME, \".zshrc\"));\n const themeMatch = zshrc.match(/^ZSH_THEME=\"?([^\"\\n]+)/m);\n const pluginsMatch = zshrc.match(/^plugins=\\(([^)]+)\\)/m);\n if (themeMatch) lines.push(`- Oh-My-Zsh Theme: ${themeMatch[1]}`);\n if (pluginsMatch) lines.push(`- Oh-My-Zsh Plugins: ${pluginsMatch[1].trim()}`);\n\n // Global npm packages\n const npmGlobal = await exec(\"npm\", [\"list\", \"-g\", \"--depth=0\"]);\n if (npmGlobal) {\n const pkgs = npmGlobal\n .split(\"\\n\")\n .filter((l) => l.startsWith(\"├\") || l.startsWith(\"└\"))\n .map((l) => l.replace(/^[├└─┬│\\s]+/, \"\").trim())\n .filter(Boolean);\n if (pkgs.length > 0) {\n lines.push(\"\", \"## Global npm Packages\", \"\", ...pkgs.map((p) => `- ${p}`));\n }\n }\n\n // Homebrew casks (installed apps via brew)\n const casks = await exec(\"brew\", [\"list\", \"--cask\"]);\n if (casks) {\n const caskList = casks.split(\"\\n\").filter(Boolean);\n lines.push(\"\", \"## Homebrew Casks\", \"\", ...caskList.map((c) => `- ${c}`));\n }\n\n return {\n id: \"dev-environment\",\n title: \"Development Environment\",\n content: lines.join(\"\\n\"),\n };\n}\n\n// ---------------------------------------------------------------------------\n// 5. Dev Preferences\n// ---------------------------------------------------------------------------\n\nexport async function collectDevPreferences(): Promise<CollectorResult> {\n const lines: string[] = [];\n\n // Shell aliases (sanitized)\n const zshrc = await readSafe(path.join(HOME, \".zshrc\"));\n if (zshrc) {\n const sanitized = stripSecretExports(zshrc);\n const aliases = sanitized\n .split(\"\\n\")\n .filter((l) => l.match(/^\\s*alias\\s/));\n if (aliases.length > 0) {\n lines.push(\"## Shell Aliases\", \"\", ...aliases);\n }\n\n // PATH additions\n const pathLines = sanitized\n .split(\"\\n\")\n .filter((l) => l.match(/^\\s*export\\s+PATH/) && !l.includes(\"REDACTED\"));\n if (pathLines.length > 0) {\n lines.push(\"\", \"## PATH Additions\", \"\", ...pathLines);\n }\n }\n\n // Git config (sanitized)\n const gitconfigPath = path.join(HOME, \".gitconfig\");\n const gitconfig = await readSafe(gitconfigPath);\n if (gitconfig) {\n const sanitized = stripGitCredentials(gitconfig);\n lines.push(\"\", \"## Git Config\", \"\", \"```\", sanitized.trim(), \"```\");\n }\n\n // Git aliases\n const gitAliases = await exec(\"git\", [\"config\", \"--global\", \"--get-regexp\", \"alias\"]);\n if (gitAliases) {\n lines.push(\"\", \"## Git Aliases\", \"\", ...gitAliases.split(\"\\n\").map((l) => `- ${l}`));\n }\n\n // Default branch\n const defaultBranch = await exec(\"git\", [\"config\", \"--global\", \"init.defaultBranch\"]);\n if (defaultBranch) lines.push(\"\", `## Default Git Branch: ${defaultBranch}`);\n\n // Cursor extensions\n const extDir = path.join(HOME, \".cursor\", \"extensions\");\n try {\n const entries = await fs.readdir(extDir);\n const exts = entries.filter((e) => !e.startsWith(\".\") && e !== \"extensions.json\");\n if (exts.length > 0) {\n lines.push(\"\", \"## Cursor Extensions\", \"\", ...exts.map((e) => `- ${e}`));\n }\n } catch {\n // No Cursor extensions dir\n }\n\n return {\n id: \"dev-preferences\",\n title: \"Development Preferences\",\n content: lines.join(\"\\n\"),\n };\n}\n\n// ---------------------------------------------------------------------------\n// 6. Shell Habits\n// ---------------------------------------------------------------------------\n\nexport async function collectShellHabits(): Promise<CollectorResult> {\n const histPath = path.join(HOME, \".zsh_history\");\n const raw = await readSafe(histPath);\n\n if (!raw) {\n return {\n id: \"shell-habits\",\n title: \"Shell Command Habits\",\n content: \"No zsh history found.\",\n };\n }\n\n const rawLines = raw.split(\"\\n\");\n const totalEntries = rawLines.length;\n\n // Parse commands: zsh history format is `: timestamp:0;command`\n const freq = new Map<string, number>();\n for (const line of rawLines) {\n // Strip zsh extended history prefix\n const cmd = line.replace(/^:\\s*\\d+:\\d+;/, \"\").trim();\n const firstWord = cmd.split(/\\s+/)[0];\n if (firstWord && firstWord.length > 0 && firstWord.length < 50) {\n freq.set(firstWord, (freq.get(firstWord) ?? 0) + 1);\n }\n }\n\n const top30 = [...freq.entries()]\n .sort((a, b) => b[1] - a[1])\n .slice(0, 30);\n\n const lines = [\n `Total history entries: ${totalEntries}`,\n \"\",\n \"## Most Used Commands (Top 30)\",\n \"\",\n ...top30.map(([cmd, count]) => `- ${cmd}: ${count} times`),\n ];\n\n return {\n id: \"shell-habits\",\n title: \"Shell Command Habits\",\n content: lines.join(\"\\n\"),\n };\n}\n\n// ---------------------------------------------------------------------------\n// 7. Coding Rules\n// ---------------------------------------------------------------------------\n\nexport async function collectCodingRules(): Promise<CollectorResult> {\n const sections: string[] = [];\n\n // Global CLAUDE.md files\n const claudePaths = [\n path.join(HOME, \"CLAUDE.md\"),\n path.join(HOME, \".claude\", \"CLAUDE.md\"),\n ];\n\n for (const p of claudePaths) {\n const content = await readSafe(p);\n if (content) {\n const relPath = p.replace(HOME, \"~\");\n sections.push(`## ${relPath}`, \"\", content.trim(), \"\");\n }\n }\n\n // Claude custom commands\n const cmdDir = path.join(HOME, \".claude\", \"commands\");\n try {\n const entries = await fs.readdir(cmdDir);\n const mdFiles = entries.filter((e) => e.endsWith(\".md\"));\n if (mdFiles.length > 0) {\n sections.push(\"## Claude Custom Commands\", \"\");\n for (const f of mdFiles) {\n const content = await readSafe(path.join(cmdDir, f));\n if (content) {\n sections.push(`### ${f}`, \"\", content.trim(), \"\");\n }\n }\n }\n } catch {\n // No commands dir\n }\n\n // Scan active project repos for CLAUDE.md / AGENTS.md / .cursorrules\n const activeRepos = await findRecentGitRepos(30);\n const projectRules: string[] = [];\n\n for (const repo of activeRepos.slice(0, 10)) {\n // Only scan top 10 most recent\n for (const ruleFile of [\"CLAUDE.md\", \"AGENTS.md\", \".cursorrules\"]) {\n const rulePath = path.join(repo, ruleFile);\n const content = await readSafe(rulePath);\n if (content && content.length > 10) {\n const repoName = path.basename(repo);\n projectRules.push(\n `### ${repoName}/${ruleFile}`,\n \"\",\n content.trim().slice(0, 2000), // Cap at 2000 chars per file\n \"\",\n );\n }\n }\n }\n\n if (projectRules.length > 0) {\n sections.push(\"## Project-Level Rules\", \"\", ...projectRules);\n }\n\n // Cursor rules directory\n const cursorRulesDir = path.join(HOME, \".cursor\", \"rules\");\n try {\n const entries = await fs.readdir(cursorRulesDir);\n const mdFiles = entries.filter((e) => e.endsWith(\".md\") || e.endsWith(\".mdc\"));\n if (mdFiles.length > 0) {\n sections.push(\"## Global Cursor Rules\", \"\");\n for (const f of mdFiles) {\n const content = await readSafe(path.join(cursorRulesDir, f));\n if (content) {\n sections.push(`### ${f}`, \"\", content.trim().slice(0, 1000), \"\");\n }\n }\n }\n } catch {\n // No cursor rules dir\n }\n\n return {\n id: \"coding-rules\",\n title: \"Coding Rules and AI Agent Config\",\n content: sections.length > 0\n ? sections.join(\"\\n\")\n : \"No coding rules found.\",\n };\n}\n\n// ---------------------------------------------------------------------------\n// 8. Active Projects\n// ---------------------------------------------------------------------------\n\nexport async function collectActiveProjects(): Promise<CollectorResult> {\n const lines: string[] = [];\n\n // Recent git repos\n const repos = await findRecentGitRepos(30);\n if (repos.length > 0) {\n lines.push(\"## Active Git Repositories (last 30 days)\", \"\");\n for (const repo of repos) {\n const name = repo.replace(HOME, \"~\");\n lines.push(`- ${name}`);\n }\n }\n\n // SSH config hosts\n const sshConfig = await readSafe(path.join(HOME, \".ssh\", \"config\"));\n if (sshConfig) {\n const sanitized = stripSshIdentityFiles(sshConfig);\n const hosts = sanitized\n .split(\"\\n\")\n .filter((l) => /^\\s*Host\\s/i.test(l) && !l.includes(\"*\"))\n .map((l) => l.replace(/^\\s*Host\\s+/i, \"\").trim());\n if (hosts.length > 0) {\n lines.push(\"\", \"## SSH Hosts\", \"\", ...hosts.map((h) => `- ${h}`));\n }\n }\n\n // Cloud storage\n const cloudDir = path.join(HOME, \"Library\", \"CloudStorage\");\n try {\n const entries = await fs.readdir(cloudDir);\n if (entries.length > 0) {\n lines.push(\"\", \"## Cloud Storage\", \"\", ...entries.map((e) => `- ${e}`));\n }\n } catch {\n // No cloud storage\n }\n\n return {\n id: \"active-projects\",\n title: \"Active Projects and Infrastructure\",\n content: lines.join(\"\\n\"),\n };\n}\n\n// ---------------------------------------------------------------------------\n// 9. Productivity Setup\n// ---------------------------------------------------------------------------\n\nexport async function collectProductivitySetup(): Promise<CollectorResult> {\n const lines: string[] = [];\n\n // Installed applications\n try {\n const entries = await fs.readdir(\"/Applications\");\n const apps = entries\n .filter((e) => e.endsWith(\".app\"))\n .map((e) => e.replace(\".app\", \"\"));\n lines.push(\"## Installed Applications\", \"\", ...apps.map((a) => `- ${a}`));\n } catch {\n lines.push(\"## Installed Applications\", \"\", \"(not accessible)\");\n }\n\n // Dock persistent apps\n const dockApps = await defaultsRead(\"com.apple.dock\", \"persistent-apps\");\n if (dockApps) {\n const labels = [...dockApps.matchAll(/\"file-label\"\\s*=\\s*\"?([^\";\\n}]+)/g)]\n .map((m) => m[1].trim())\n .filter(Boolean);\n if (labels.length > 0) {\n lines.push(\"\", \"## Dock Apps (pinned)\", \"\", ...labels.map((a) => `- ${a}`));\n }\n }\n\n // Default browser\n const handlers = await defaultsRead(\n \"com.apple.LaunchServices/com.apple.launchservices.secure\",\n \"LSHandlers\",\n );\n const browserMatch = handlers.match(/LSHandlerRoleAll\\s*=\\s*\"([^\"]+)\"/);\n if (browserMatch) {\n const bundleId = browserMatch[1];\n const browserName = bundleId.includes(\"edge\")\n ? \"Microsoft Edge\"\n : bundleId.includes(\"chrome\")\n ? \"Google Chrome\"\n : bundleId.includes(\"firefox\")\n ? \"Firefox\"\n : bundleId.includes(\"safari\")\n ? \"Safari\"\n : bundleId;\n lines.push(\"\", `## Default Browser: ${browserName}`);\n }\n\n // Screen resolution\n const displayInfo = await exec(\"system_profiler\", [\"SPDisplaysDataType\"]);\n const resolutions = [...displayInfo.matchAll(/Resolution:\\s*(.+)/g)].map((m) => m[1].trim());\n if (resolutions.length > 0) {\n lines.push(\"\", \"## Screen Resolution\", \"\", ...resolutions.map((r) => `- ${r}`));\n }\n\n return {\n id: \"productivity-setup\",\n title: \"Productivity Setup\",\n content: lines.join(\"\\n\"),\n };\n}\n\n// ---------------------------------------------------------------------------\n// 10. Browser Bookmarks\n// ---------------------------------------------------------------------------\n\nexport async function collectBrowserBookmarks(): Promise<CollectorResult> {\n const bmPath = path.join(\n HOME,\n \"Library\",\n \"Application Support\",\n \"Microsoft Edge\",\n \"Default\",\n \"Bookmarks\",\n );\n\n const raw = await readSafe(bmPath);\n if (!raw) {\n return {\n id: \"browser-bookmarks\",\n title: \"Browser Bookmark Structure\",\n content: \"No Edge bookmarks found.\",\n };\n }\n\n try {\n const data = JSON.parse(raw);\n const folders: { name: string; count: number; depth: number }[] = [];\n let totalUrls = 0;\n\n function walk(\n node: Record<string, unknown>,\n depth: number,\n ): void {\n if (node.type === \"folder\") {\n const children = (node.children ?? []) as Record<string, unknown>[];\n const name = (node.name as string) ?? \"\";\n if (children.length > 0) {\n folders.push({ name, count: children.length, depth });\n }\n for (const child of children) {\n walk(child, depth + 1);\n }\n } else if (node.type === \"url\") {\n totalUrls++;\n }\n }\n\n const roots = data.roots as Record<string, unknown>;\n for (const root of Object.values(roots)) {\n if (root && typeof root === \"object\" && \"children\" in (root as Record<string, unknown>)) {\n walk(root as Record<string, unknown>, 0);\n }\n }\n\n // Sort by count descending\n folders.sort((a, b) => b.count - a.count);\n\n const lines = [\n `Total bookmarks: ${totalUrls}`,\n `Total folders: ${folders.length}`,\n \"\",\n \"## Top Bookmark Folders (by item count)\",\n \"\",\n ...folders.slice(0, 40).map((f) => `- ${\" \".repeat(Math.min(f.depth, 2))}${f.name}: ${f.count} items`),\n ];\n\n return {\n id: \"browser-bookmarks\",\n title: \"Browser Bookmark Structure\",\n content: lines.join(\"\\n\"),\n };\n } catch {\n return {\n id: \"browser-bookmarks\",\n title: \"Browser Bookmark Structure\",\n content: \"Failed to parse Edge bookmarks.\",\n };\n }\n}\n\n// ---------------------------------------------------------------------------\n// 11. Browser Domains\n// ---------------------------------------------------------------------------\n\nexport async function collectBrowserDomains(): Promise<CollectorResult> {\n const histPath = path.join(\n HOME,\n \"Library\",\n \"Application Support\",\n \"Microsoft Edge\",\n \"Default\",\n \"History\",\n );\n\n if (!(await exists(histPath))) {\n return {\n id: \"browser-domains\",\n title: \"Browser Top Domains (30 days)\",\n content: \"No Edge history found.\",\n };\n }\n\n // Copy the locked DB to a temp file for reading\n const tmpDb = path.join(os.tmpdir(), `pai-edge-history-${Date.now()}.db`);\n try {\n await fs.copyFile(histPath, tmpDb);\n\n const query = `\n SELECT\n REPLACE(REPLACE(SUBSTR(url, 1, INSTR(SUBSTR(url, 9), '/') + 8), 'https://', ''), 'http://', '') as domain,\n COUNT(*) as visits\n FROM urls\n WHERE last_visit_time > (strftime('%s', 'now', '-30 days') + 11644473600) * 1000000\n GROUP BY domain\n ORDER BY visits DESC\n LIMIT 30;\n `.trim();\n\n const output = await exec(\"sqlite3\", [tmpDb, query]);\n\n if (!output) {\n return {\n id: \"browser-domains\",\n title: \"Browser Top Domains (30 days)\",\n content: \"Could not query Edge history (DB may be locked).\",\n };\n }\n\n const lines = [\n \"## Top 30 Domains (last 30 days)\",\n \"\",\n ...output.split(\"\\n\").map((line) => {\n const [domain, visits] = line.split(\"|\");\n return `- ${domain}: ${visits} visits`;\n }),\n ];\n\n return {\n id: \"browser-domains\",\n title: \"Browser Top Domains (30 days)\",\n content: lines.join(\"\\n\"),\n };\n } finally {\n try {\n await fs.unlink(tmpDb);\n } catch {\n // Cleanup failure is ok\n }\n }\n}\n\n// ---------------------------------------------------------------------------\n// 12. GitHub Profile\n// ---------------------------------------------------------------------------\n\nexport async function collectGitHubProfile(): Promise<CollectorResult> {\n const lines: string[] = [];\n\n // Check if gh CLI is available\n const ghVersion = await exec(\"gh\", [\"--version\"]);\n if (!ghVersion) {\n return {\n id: \"github-profile\",\n title: \"GitHub Profile\",\n content: \"GitHub CLI (gh) not installed.\",\n };\n }\n\n // Check auth status\n const authStatus = await exec(\"gh\", [\"auth\", \"status\"]);\n if (!authStatus) {\n return {\n id: \"github-profile\",\n title: \"GitHub Profile\",\n content: \"GitHub CLI not authenticated. Run `gh auth login` to enable.\",\n };\n }\n\n // Get user profile\n const userJson = await exec(\"gh\", [\n \"api\", \"user\",\n \"--jq\", '[.login, .name, .bio, .company, .location, .blog, .public_repos, .followers, .following, .created_at] | @tsv',\n ]);\n\n if (userJson) {\n const parts = userJson.split(\"\\t\");\n const [login, name, bio, company, location, blog, publicRepos, followers, following, createdAt] = parts;\n lines.push(\"## GitHub Profile\", \"\");\n if (login) lines.push(`- Username: ${login}`);\n if (name) lines.push(`- Name: ${name}`);\n if (bio) lines.push(`- Bio: ${bio}`);\n if (company) lines.push(`- Company: ${company}`);\n if (location) lines.push(`- Location: ${location}`);\n if (blog) lines.push(`- Website: ${blog}`);\n if (publicRepos) lines.push(`- Public Repos: ${publicRepos}`);\n if (followers || following) lines.push(`- Followers/Following: ${followers}/${following}`);\n if (createdAt) lines.push(`- Member since: ${createdAt}`);\n }\n\n // Get recent repos (owned, sorted by push date)\n const reposJson = await exec(\"gh\", [\n \"repo\", \"list\", \"--limit\", \"10\", \"--sort\", \"updated\", \"--json\",\n \"name,description,primaryLanguage,pushedAt,isPrivate\",\n \"--jq\", '.[] | [.name, .description, (.primaryLanguage.name // \"\"), .pushedAt, .isPrivate] | @tsv',\n ]);\n\n if (reposJson) {\n const repos = reposJson.split(\"\\n\").filter(Boolean);\n if (repos.length > 0) {\n lines.push(\"\", \"## Recent GitHub Repos (by push date)\", \"\");\n for (const repo of repos) {\n const [name, desc, lang, _pushed, isPrivate] = repo.split(\"\\t\");\n const visibility = isPrivate === \"true\" ? \"private\" : \"public\";\n const langTag = lang ? ` [${lang}]` : \"\";\n const descTag = desc ? ` — ${desc}` : \"\";\n lines.push(`- ${name}${langTag} (${visibility})${descTag}`);\n }\n }\n }\n\n // Get starred repos (recent 20 for interest signals)\n const starsJson = await exec(\"gh\", [\n \"api\", \"user/starred?per_page=20&sort=created&direction=desc\",\n \"--jq\", '.[].full_name',\n ]);\n\n if (starsJson) {\n const stars = starsJson.split(\"\\n\").filter(Boolean);\n if (stars.length > 0) {\n lines.push(\"\", \"## Recently Starred Repos (interest signals)\", \"\");\n lines.push(stars.map((s) => `- ${s}`).join(\"\\n\"));\n }\n }\n\n return {\n id: \"github-profile\",\n title: \"GitHub Profile & Activity\",\n content: lines.length > 0 ? lines.join(\"\\n\") : \"No GitHub data accessible.\",\n };\n}\n\n// ---------------------------------------------------------------------------\n// 13. Recent Focus (inferred from git commits + shell history)\n// ---------------------------------------------------------------------------\n\nexport async function collectRecentFocus(): Promise<CollectorResult> {\n const lines: string[] = [];\n\n // Analyze recent commit messages across active repos for topic signals\n const repos = await findRecentGitRepos(14); // Last 2 weeks\n const commitTopics = new Map<string, number>();\n const recentMessages: string[] = [];\n\n for (const repo of repos.slice(0, 8)) {\n // Get recent commit subjects from this repo\n const log = await exec(\"git\", [\n \"-C\", repo,\n \"log\", \"--oneline\", \"--since=14 days ago\",\n \"--format=%s\", \"-n\", \"20\",\n ]);\n if (log) {\n for (const msg of log.split(\"\\n\").filter(Boolean)) {\n recentMessages.push(msg);\n // Extract first word (often a conventional commit type)\n const type = msg.match(/^(feat|fix|refactor|test|docs|chore|perf|ci|build|style)/i);\n if (type) {\n const key = type[1].toLowerCase();\n commitTopics.set(key, (commitTopics.get(key) ?? 0) + 1);\n }\n }\n }\n }\n\n if (commitTopics.size > 0) {\n const sorted = [...commitTopics.entries()].sort((a, b) => b[1] - a[1]);\n lines.push(\"## Recent Commit Activity (last 2 weeks)\", \"\");\n lines.push(`Total commits analyzed: ${recentMessages.length}`);\n lines.push(\"\", \"Commit types:\");\n for (const [type, count] of sorted) {\n lines.push(`- ${type}: ${count}`);\n }\n }\n\n // Extract recent commit subjects for topic inference\n if (recentMessages.length > 0) {\n lines.push(\"\", \"## Recent Commit Messages (sample)\", \"\");\n // Take a diverse sample (first 15 unique-ish messages)\n const unique = [...new Set(recentMessages)].slice(0, 15);\n for (const msg of unique) {\n lines.push(`- ${msg}`);\n }\n }\n\n // Recent shell commands that indicate current work context\n const histPath = path.join(HOME, \".zsh_history\");\n const histRaw = await readSafe(histPath);\n if (histRaw) {\n const histLines = histRaw.split(\"\\n\");\n // Take last 200 history entries and extract project-related patterns\n const recent = histLines.slice(-200);\n const cdPaths = new Map<string, number>();\n const tools = new Map<string, number>();\n\n for (const line of recent) {\n const cmd = line.replace(/^:\\s*\\d+:\\d+;/, \"\").trim();\n // Track cd destinations\n const cdMatch = cmd.match(/^cd\\s+(.+)/);\n if (cdMatch) {\n const dest = cdMatch[1].trim().replace(/^~/, HOME);\n cdPaths.set(dest, (cdPaths.get(dest) ?? 0) + 1);\n }\n // Track tool usage\n const toolMatch = cmd.match(/^(docker|kubectl|terraform|aws|gcloud|firebase|vercel|netlify|npm|pnpm|yarn|bun|cargo|go|python|pip|uv)\\b/);\n if (toolMatch) {\n tools.set(toolMatch[1], (tools.get(toolMatch[1]) ?? 0) + 1);\n }\n }\n\n if (cdPaths.size > 0) {\n const topDirs = [...cdPaths.entries()].sort((a, b) => b[1] - a[1]).slice(0, 8);\n lines.push(\"\", \"## Recent Working Directories\", \"\");\n for (const [dir, count] of topDirs) {\n lines.push(`- ${dir.replace(HOME, \"~\")}: ${count}x`);\n }\n }\n\n if (tools.size > 0) {\n const topTools = [...tools.entries()].sort((a, b) => b[1] - a[1]);\n lines.push(\"\", \"## Recently Used Tools (from history)\", \"\");\n for (const [tool, count] of topTools) {\n lines.push(`- ${tool}: ${count}x`);\n }\n }\n }\n\n return {\n id: \"recent-focus\",\n title: \"Recent Focus & Activity\",\n content: lines.length > 0\n ? lines.join(\"\\n\")\n : \"No recent activity data found.\",\n };\n}\n\n// ---------------------------------------------------------------------------\n// 14. Social & Registry Profiles\n// ---------------------------------------------------------------------------\n\nexport async function collectSocialProfiles(): Promise<CollectorResult> {\n const lines: string[] = [];\n\n // npm registry identity\n const npmrc = await readSafe(path.join(HOME, \".npmrc\"));\n if (npmrc) {\n // Extract registry URL (but not tokens)\n const registryMatch = npmrc.match(/^registry\\s*=\\s*(.+)/m);\n if (registryMatch) lines.push(`- npm registry: ${registryMatch[1].trim()}`);\n // Check for scope configs\n const scopes = npmrc.match(/^@[\\w-]+:registry/gm);\n if (scopes) {\n for (const s of scopes) {\n lines.push(`- npm scope: ${s.split(\":\")[0]}`);\n }\n }\n }\n\n // npm whoami\n const npmUser = await exec(\"npm\", [\"whoami\"]);\n if (npmUser) lines.push(`- npm username: ${npmUser}`);\n\n // PyPI config\n const pypirc = await readSafe(path.join(HOME, \".pypirc\"));\n if (pypirc) {\n const repoMatch = pypirc.match(/repository\\s*=\\s*(.+)/);\n if (repoMatch) lines.push(`- PyPI repository: ${repoMatch[1].trim()}`);\n const usernameMatch = pypirc.match(/username\\s*=\\s*(.+)/);\n if (usernameMatch) lines.push(`- PyPI username: ${usernameMatch[1].trim()}`);\n }\n\n // Docker Hub\n const dockerConfig = await readSafe(path.join(HOME, \".docker\", \"config.json\"));\n if (dockerConfig) {\n try {\n const cfg = JSON.parse(dockerConfig);\n const auths = Object.keys(cfg.auths ?? {});\n if (auths.length > 0) {\n lines.push(`- Docker registries: ${auths.join(\", \")}`);\n }\n } catch {\n // Ignore parse errors\n }\n }\n\n // Cargo / crates.io\n const cargoConfig = await readSafe(path.join(HOME, \".cargo\", \"config.toml\"));\n if (cargoConfig) {\n const registries = cargoConfig.match(/\\[registries\\.(\\w+)\\]/g);\n if (registries) {\n lines.push(`- Cargo registries: ${registries.map((r) => r.replace(/\\[registries\\.|\\]/g, \"\")).join(\", \")}`);\n }\n }\n\n // Cloud provider CLIs\n const awsIdentity = await exec(\"aws\", [\"sts\", \"get-caller-identity\", \"--query\", \"Account\", \"--output\", \"text\"]);\n if (awsIdentity) lines.push(`- AWS Account: ${awsIdentity}`);\n\n const gcpProject = await exec(\"gcloud\", [\"config\", \"get-value\", \"project\"]);\n if (gcpProject && !gcpProject.includes(\"unset\")) lines.push(`- GCP Project: ${gcpProject}`);\n\n const vercelUser = await exec(\"vercel\", [\"whoami\"]);\n if (vercelUser) lines.push(`- Vercel: ${vercelUser}`);\n\n return {\n id: \"social-profiles\",\n title: \"Registry & Cloud Profiles\",\n content: lines.length > 0\n ? [\"## Registry & Cloud Accounts\", \"\", ...lines].join(\"\\n\")\n : \"No registry or cloud profiles detected.\",\n };\n}\n\n// ---------------------------------------------------------------------------\n// Shared utilities\n// ---------------------------------------------------------------------------\n\n/** Find git repos under ~/Documents modified in the last N days */\nasync function findRecentGitRepos(days: number): Promise<string[]> {\n const output = await exec(\"find\", [\n path.join(HOME, \"Documents\"),\n \"-maxdepth\", \"4\",\n \"-name\", \".git\",\n \"-type\", \"d\",\n \"-mtime\", `-${days}`,\n ]);\n\n if (!output) return [];\n return output\n .split(\"\\n\")\n .filter(Boolean)\n .map((p) => p.replace(/\\/.git$/, \"\"));\n}\n\n// ---------------------------------------------------------------------------\n// Export all collectors\n// ---------------------------------------------------------------------------\n\n/** All available Mac collectors in execution order */\nexport const ALL_COLLECTORS = [\n collectIdentityProfile,\n collectCalendarContext,\n collectFileOrganization,\n collectDevEnvironment,\n collectDevPreferences,\n collectShellHabits,\n collectCodingRules,\n collectActiveProjects,\n collectProductivitySetup,\n collectBrowserBookmarks,\n collectBrowserDomains,\n collectGitHubProfile,\n collectRecentFocus,\n collectSocialProfiles,\n] as const;\n","/**\n * Profile module — compile, load, and rebuild user profiles.\n */\n\nimport fs from \"node:fs/promises\";\nimport { getProfilePath } from \"../config/paths.js\";\nimport { addConnectorEntry } from \"../raw/add.js\";\nimport * as console from \"../utils/console.js\";\nimport { compileProfile, compileCompactProfile } from \"./compile.js\";\nimport type { CollectorResult } from \"../types.js\";\nimport { ALL_COLLECTORS } from \"../connectors/mac/collectors.js\";\n\nexport { compileProfile, compileCompactProfile } from \"./compile.js\";\n\n/** Load the current profile from disk. Returns null if not found. */\nexport async function loadProfile(): Promise<string | null> {\n try {\n return await fs.readFile(getProfilePath(), \"utf-8\");\n } catch {\n return null;\n }\n}\n\n/** Save profile markdown to disk. */\nexport async function saveProfile(content: string): Promise<string> {\n const profilePath = getProfilePath();\n await fs.writeFile(profilePath, content, \"utf-8\");\n return profilePath;\n}\n\n/**\n * Full rebuild: scan local machine → compile profile → write to disk.\n * Also writes raw files for the scan data (for vault/distill pipeline compatibility).\n */\nexport async function rebuildProfile(opts?: {\n /** If true, skip writing raw files (profile-only mode) */\n skipRaw?: boolean;\n /** If true, show progress spinners */\n verbose?: boolean;\n}): Promise<{ profilePath: string; results: CollectorResult[] }> {\n const verbose = opts?.verbose ?? true;\n\n // 1. Run all collectors concurrently\n const spin = verbose ? console.spinner(\"Scanning local machine...\") : null;\n\n const settled = await Promise.allSettled(\n ALL_COLLECTORS.map((collector) => collector()),\n );\n\n const results: CollectorResult[] = [];\n const failed: string[] = [];\n\n for (let i = 0; i < settled.length; i++) {\n const s = settled[i];\n if (s.status === \"fulfilled\") {\n results.push(s.value);\n } else {\n const name = ALL_COLLECTORS[i].name;\n failed.push(name);\n if (verbose) console.warn(`Collector ${name} failed: ${String(s.reason)}`);\n }\n }\n\n spin?.succeed(`Scanned ${results.length} sources (${failed.length} failed)`);\n\n // 2. Optionally write raw files (for backward compat with vault/distill)\n if (!opts?.skipRaw) {\n for (const entry of results) {\n try {\n await addConnectorEntry(\"mac\", entry);\n } catch {\n // Non-critical — profile compilation doesn't depend on raw writes\n }\n }\n }\n\n // 3. Compile and save profile\n const profileContent = compileProfile(results);\n const profilePath = await saveProfile(profileContent);\n\n return { profilePath, results };\n}\n"],"mappings":";;;;;;;;;;;;;;AAIA,SAAgB,aAAqB;AACnC,QAAO,QAAQ,IAAI,YAAY,KAAK,KAAK,GAAG,SAAS,EAAE,OAAO;;AAGhE,SAAgB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