harness-evolve 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +254 -0
- package/dist/cli.js +1685 -0
- package/dist/cli.js.map +1 -0
- package/dist/delivery/run-evolve.d.ts +2 -0
- package/dist/delivery/run-evolve.js +2069 -0
- package/dist/delivery/run-evolve.js.map +1 -0
- package/dist/hooks/permission-request.d.ts +8 -0
- package/dist/hooks/permission-request.js +405 -0
- package/dist/hooks/permission-request.js.map +1 -0
- package/dist/hooks/post-tool-use-failure.d.ts +9 -0
- package/dist/hooks/post-tool-use-failure.js +437 -0
- package/dist/hooks/post-tool-use-failure.js.map +1 -0
- package/dist/hooks/post-tool-use.d.ts +9 -0
- package/dist/hooks/post-tool-use.js +441 -0
- package/dist/hooks/post-tool-use.js.map +1 -0
- package/dist/hooks/pre-tool-use.d.ts +8 -0
- package/dist/hooks/pre-tool-use.js +434 -0
- package/dist/hooks/pre-tool-use.js.map +1 -0
- package/dist/hooks/stop.d.ts +8 -0
- package/dist/hooks/stop.js +1609 -0
- package/dist/hooks/stop.js.map +1 -0
- package/dist/hooks/user-prompt-submit.d.ts +8 -0
- package/dist/hooks/user-prompt-submit.js +442 -0
- package/dist/hooks/user-prompt-submit.js.map +1 -0
- package/dist/index.d.ts +1029 -0
- package/dist/index.js +3131 -0
- package/dist/index.js.map +1 -0
- package/package.json +104 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/schemas/config.ts","../src/schemas/log-entry.ts","../src/schemas/counter.ts","../src/schemas/hook-input.ts","../src/hooks/shared.ts","../src/storage/counter.ts","../src/storage/dirs.ts","../src/storage/config.ts","../src/analysis/jsonl-reader.ts","../src/analysis/schemas.ts","../src/analysis/pre-processor.ts","../src/analysis/environment-scanner.ts","../src/analysis/classifiers/repeated-prompts.ts","../src/analysis/classifiers/long-prompts.ts","../src/analysis/classifiers/permission-patterns.ts","../src/analysis/classifiers/code-corrections.ts","../src/analysis/classifiers/personal-info.ts","../src/analysis/classifiers/config-drift.ts","../src/analysis/classifiers/ecosystem-adapter.ts","../src/analysis/experience-level.ts","../src/analysis/classifiers/onboarding.ts","../src/analysis/classifiers/index.ts","../src/schemas/recommendation.ts","../src/analysis/analyzer.ts","../src/analysis/outcome-tracker.ts","../src/delivery/state.ts","../src/schemas/delivery.ts","../src/schemas/onboarding.ts","../src/analysis/trigger.ts","../src/hooks/stop.ts","../src/scrubber/patterns.ts","../src/scrubber/scrub.ts","../src/storage/logger.ts","../src/delivery/renderer.ts","../src/delivery/rotator.ts","../src/delivery/notification.ts","../src/delivery/auto-apply.ts","../src/delivery/appliers/index.ts","../src/delivery/appliers/settings-applier.ts","../src/delivery/appliers/rule-applier.ts","../src/delivery/appliers/hook-applier.ts","../src/generators/schemas.ts","../src/generators/hook-generator.ts","../src/cli/utils.ts","../src/delivery/appliers/claude-md-applier.ts","../src/scan/context-builder.ts","../src/scan/schemas.ts","../src/scan/scanners/redundancy.ts","../src/scan/scanners/mechanization.ts","../src/scan/scanners/staleness.ts","../src/scan/scanners/index.ts","../src/scan/index.ts","../src/generators/skill-generator.ts","../src/generators/claude-md-generator.ts","../src/cli/scan.ts","../src/cli/apply.ts"],"sourcesContent":["import { z } from 'zod/v4';\n\nexport const configSchema = z.object({\n version: z.number().default(1),\n analysis: z.object({\n threshold: z.number().min(1).default(50),\n enabled: z.boolean().default(true),\n classifierThresholds: z.record(z.string(), z.number()).default({}),\n }).default({ threshold: 50, enabled: true, classifierThresholds: {} }),\n hooks: z.object({\n capturePrompts: z.boolean().default(true),\n captureTools: z.boolean().default(true),\n capturePermissions: z.boolean().default(true),\n captureSessions: z.boolean().default(true),\n }).default({\n capturePrompts: true,\n captureTools: true,\n capturePermissions: true,\n captureSessions: true,\n }),\n scrubbing: z.object({\n enabled: z.boolean().default(true),\n highEntropyDetection: z.boolean().default(false),\n customPatterns: z.array(z.object({\n name: z.string(),\n regex: z.string(),\n replacement: z.string(),\n })).default([]),\n }).default({\n enabled: true,\n highEntropyDetection: false,\n customPatterns: [],\n }),\n delivery: z.object({\n stdoutInjection: z.boolean().default(true),\n maxTokens: z.number().default(200),\n fullAuto: z.boolean().default(false),\n maxRecommendationsInFile: z.number().default(20),\n archiveAfterDays: z.number().default(7),\n }).default({\n stdoutInjection: true,\n maxTokens: 200,\n fullAuto: false,\n maxRecommendationsInFile: 20,\n archiveAfterDays: 7,\n }),\n}).strict();\n\nexport type Config = z.infer<typeof configSchema>;\n","import { z } from 'zod/v4';\n\nexport const promptEntrySchema = z.object({\n timestamp: z.iso.datetime(),\n session_id: z.string(),\n cwd: z.string(),\n prompt: z.string(),\n prompt_length: z.number(),\n transcript_path: z.string().optional(),\n});\nexport type PromptEntry = z.infer<typeof promptEntrySchema>;\n\nexport const toolEntrySchema = z.object({\n timestamp: z.iso.datetime(),\n session_id: z.string(),\n event: z.enum(['pre', 'post', 'failure']),\n tool_name: z.string(),\n input_summary: z.string().optional(),\n duration_ms: z.number().optional(),\n success: z.boolean().optional(),\n});\nexport type ToolEntry = z.infer<typeof toolEntrySchema>;\n\nexport const permissionEntrySchema = z.object({\n timestamp: z.iso.datetime(),\n session_id: z.string(),\n tool_name: z.string(),\n decision: z.enum(['approved', 'denied', 'unknown']),\n});\nexport type PermissionEntry = z.infer<typeof permissionEntrySchema>;\n\nexport const sessionEntrySchema = z.object({\n timestamp: z.iso.datetime(),\n session_id: z.string(),\n event: z.enum(['start', 'end']),\n cwd: z.string().optional(),\n});\nexport type SessionEntry = z.infer<typeof sessionEntrySchema>;\n","import { z } from 'zod/v4';\n\nexport const counterSchema = z.object({\n total: z.number().default(0),\n session: z.record(z.string(), z.number()).default({}),\n last_analysis: z.iso.datetime().optional(),\n last_updated: z.iso.datetime(),\n});\nexport type Counter = z.infer<typeof counterSchema>;\n","import { z } from 'zod/v4';\n\n// Common fields present in ALL Claude Code hook events\nexport const hookCommonSchema = z.object({\n session_id: z.string(),\n transcript_path: z.string(),\n cwd: z.string(),\n permission_mode: z.string(),\n});\nexport type HookCommon = z.infer<typeof hookCommonSchema>;\n\n// UserPromptSubmit: fires when user submits a prompt\nexport const userPromptSubmitInputSchema = hookCommonSchema.extend({\n hook_event_name: z.literal('UserPromptSubmit'),\n prompt: z.string(),\n});\nexport type UserPromptSubmitInput = z.infer<typeof userPromptSubmitInputSchema>;\n\n// PreToolUse: fires before a tool is invoked\nexport const preToolUseInputSchema = hookCommonSchema.extend({\n hook_event_name: z.literal('PreToolUse'),\n tool_name: z.string(),\n tool_input: z.record(z.string(), z.unknown()),\n tool_use_id: z.string(),\n});\nexport type PreToolUseInput = z.infer<typeof preToolUseInputSchema>;\n\n// PostToolUse: fires after a tool completes successfully\nexport const postToolUseInputSchema = hookCommonSchema.extend({\n hook_event_name: z.literal('PostToolUse'),\n tool_name: z.string(),\n tool_input: z.record(z.string(), z.unknown()),\n tool_response: z.unknown().optional(),\n tool_use_id: z.string(),\n});\nexport type PostToolUseInput = z.infer<typeof postToolUseInputSchema>;\n\n// PostToolUseFailure: fires after a tool execution fails\nexport const postToolUseFailureInputSchema = hookCommonSchema.extend({\n hook_event_name: z.literal('PostToolUseFailure'),\n tool_name: z.string(),\n tool_input: z.record(z.string(), z.unknown()),\n tool_use_id: z.string(),\n error: z.string().optional(),\n is_interrupt: z.boolean().optional(),\n});\nexport type PostToolUseFailureInput = z.infer<typeof postToolUseFailureInputSchema>;\n\n// PermissionRequest: fires before user sees permission dialog\nexport const permissionRequestInputSchema = hookCommonSchema.extend({\n hook_event_name: z.literal('PermissionRequest'),\n tool_name: z.string(),\n tool_input: z.record(z.string(), z.unknown()),\n permission_suggestions: z.array(z.unknown()).optional(),\n});\nexport type PermissionRequestInput = z.infer<typeof permissionRequestInputSchema>;\n\n// Stop: fires after Claude Code completes a response\nexport const stopInputSchema = hookCommonSchema.extend({\n hook_event_name: z.literal('Stop'),\n stop_hook_active: z.boolean(),\n last_assistant_message: z.string().optional(),\n});\nexport type StopInput = z.infer<typeof stopInputSchema>;\n","// Shared utilities for hook handlers: stdin reading and tool input summarization\n\nconst MAX_LEN = 200;\n\n/**\n * Truncate a string to maxLen characters, appending '...' if truncated.\n */\nfunction truncate(str: string, maxLen: number): string {\n return str.length > maxLen ? str.slice(0, maxLen) + '...' : str;\n}\n\n/**\n * Read all data from a readable stream into a string buffer.\n * Used for testability -- readStdin() delegates to this with process.stdin.\n */\nexport function readFromStream(stream: NodeJS.ReadableStream): Promise<string> {\n return new Promise((resolve, reject) => {\n let data = '';\n stream.setEncoding('utf-8');\n stream.on('data', (chunk: string) => {\n data += chunk;\n });\n stream.on('end', () => resolve(data));\n stream.on('error', reject);\n });\n}\n\n/**\n * Read all stdin data into a string buffer.\n * Claude Code pipes JSON to hook stdin; this collects all chunks before parsing.\n */\nexport function readStdin(): Promise<string> {\n return readFromStream(process.stdin);\n}\n\n/**\n * Produce a concise summary of tool_input, capped at 200 characters.\n * Prevents Write/Edit tool inputs (with full file content) from bloating logs.\n */\nexport function summarizeToolInput(\n toolName: string,\n toolInput: Record<string, unknown>,\n): string {\n switch (toolName) {\n case 'Bash':\n return truncate(String(toolInput.command ?? ''), MAX_LEN);\n case 'Write':\n case 'Edit':\n case 'Read':\n return truncate(String(toolInput.file_path ?? ''), MAX_LEN);\n case 'Glob':\n return truncate(String(toolInput.pattern ?? ''), MAX_LEN);\n case 'Grep':\n return truncate(String(toolInput.pattern ?? ''), MAX_LEN);\n default: {\n // MCP tools and others: stringify then truncate\n const str = JSON.stringify(toolInput);\n return truncate(str, MAX_LEN);\n }\n }\n}\n","import { readFile } from 'node:fs/promises';\nimport { lock } from 'proper-lockfile';\nimport writeFileAtomic from 'write-file-atomic';\nimport { counterSchema, type Counter } from '../schemas/counter.js';\nimport { paths, ensureInit } from './dirs.js';\n\n/**\n * Read the current counter state from disk.\n * Returns defaults (total=0, session={}) if no counter file exists.\n */\nexport async function readCounter(): Promise<Counter> {\n await ensureInit();\n try {\n const raw = await readFile(paths.counter, 'utf-8');\n return counterSchema.parse(JSON.parse(raw));\n } catch {\n // File doesn't exist or invalid -- return defaults\n return {\n total: 0,\n session: {},\n last_updated: new Date().toISOString(),\n };\n }\n}\n\n/**\n * Atomically increment the interaction counter with cross-process safety.\n *\n * Uses proper-lockfile (mkdir-based, macOS-safe) for cross-process locking\n * and write-file-atomic for crash-safe writes inside the lock.\n *\n * Pattern: ensure-file -> lock -> read -> increment -> atomic-write -> unlock\n */\nexport async function incrementCounter(sessionId: string): Promise<number> {\n await ensureInit();\n\n // Ensure counter file exists before locking (proper-lockfile requires existing file)\n try {\n await readFile(paths.counter, 'utf-8');\n } catch {\n const initial: Counter = {\n total: 0,\n session: {},\n last_updated: new Date().toISOString(),\n };\n await writeFileAtomic(paths.counter, JSON.stringify(initial, null, 2));\n }\n\n const release = await lock(paths.counter, {\n retries: { retries: 50, minTimeout: 20, maxTimeout: 1000, randomize: true },\n stale: 10000, // Consider lock stale after 10 seconds\n });\n\n try {\n const raw = await readFile(paths.counter, 'utf-8');\n const data = counterSchema.parse(JSON.parse(raw));\n data.total += 1;\n data.session[sessionId] = (data.session[sessionId] ?? 0) + 1;\n data.last_updated = new Date().toISOString();\n await writeFileAtomic(paths.counter, JSON.stringify(data, null, 2));\n return data.total;\n } finally {\n await release();\n }\n}\n\n/**\n * Reset the counter to zero. Used for testing and post-analysis reset.\n */\nexport async function resetCounter(): Promise<void> {\n await ensureInit();\n const data: Counter = {\n total: 0,\n session: {},\n last_updated: new Date().toISOString(),\n };\n await writeFileAtomic(paths.counter, JSON.stringify(data, null, 2));\n}\n","import { mkdir } from 'node:fs/promises';\nimport { join } from 'node:path';\n\nconst BASE_DIR = join(process.env.HOME ?? '', '.harness-evolve');\n\nexport const paths = {\n base: BASE_DIR,\n logs: {\n prompts: join(BASE_DIR, 'logs', 'prompts'),\n tools: join(BASE_DIR, 'logs', 'tools'),\n permissions: join(BASE_DIR, 'logs', 'permissions'),\n sessions: join(BASE_DIR, 'logs', 'sessions'),\n },\n analysis: join(BASE_DIR, 'analysis'),\n analysisPreProcessed: join(BASE_DIR, 'analysis', 'pre-processed'),\n summary: join(BASE_DIR, 'analysis', 'pre-processed', 'summary.json'),\n environmentSnapshot: join(BASE_DIR, 'analysis', 'environment-snapshot.json'),\n analysisResult: join(BASE_DIR, 'analysis', 'analysis-result.json'),\n pending: join(BASE_DIR, 'pending'),\n config: join(BASE_DIR, 'config.json'),\n counter: join(BASE_DIR, 'counter.json'),\n recommendations: join(BASE_DIR, 'recommendations.md'),\n recommendationState: join(BASE_DIR, 'analysis', 'recommendation-state.json'),\n recommendationArchive: join(BASE_DIR, 'analysis', 'recommendations-archive'),\n notificationFlag: join(BASE_DIR, 'analysis', 'has-pending-notifications'),\n autoApplyLog: join(BASE_DIR, 'analysis', 'auto-apply-log.jsonl'),\n outcomeHistory: join(BASE_DIR, 'analysis', 'outcome-history.jsonl'),\n} as const;\n\nlet initialized = false;\n\nexport async function ensureInit(): Promise<void> {\n if (initialized) return;\n await mkdir(paths.logs.prompts, { recursive: true });\n await mkdir(paths.logs.tools, { recursive: true });\n await mkdir(paths.logs.permissions, { recursive: true });\n await mkdir(paths.logs.sessions, { recursive: true });\n await mkdir(paths.analysis, { recursive: true });\n await mkdir(paths.analysisPreProcessed, { recursive: true });\n await mkdir(paths.pending, { recursive: true });\n await mkdir(paths.recommendationArchive, { recursive: true });\n initialized = true;\n}\n\n// For testing: reset the initialized flag\nexport function resetInit(): void {\n initialized = false;\n}\n","import { readFile } from 'node:fs/promises';\nimport writeFileAtomic from 'write-file-atomic';\nimport { configSchema, type Config } from '../schemas/config.js';\nimport { paths } from './dirs.js';\n\nexport async function loadConfig(): Promise<Config> {\n try {\n const raw = await readFile(paths.config, 'utf-8');\n return configSchema.parse(JSON.parse(raw));\n } catch {\n // File doesn't exist, is invalid JSON, or fails strict validation\n const defaults = configSchema.parse({});\n await writeFileAtomic(paths.config, JSON.stringify(defaults, null, 2));\n return defaults;\n }\n}\n","// Streaming JSONL reader with date-range filtering and schema validation.\n// Reads daily-rotated .jsonl log files (YYYY-MM-DD.jsonl) and returns\n// validated, typed entries. Malformed or schema-invalid lines are silently\n// skipped to ensure robustness against partial writes or corruption.\n\nimport { createReadStream } from 'node:fs';\nimport { readdir } from 'node:fs/promises';\nimport { createInterface } from 'node:readline';\nimport { join } from 'node:path';\nimport type { z } from 'zod/v4';\n\n/**\n * Format a Date as YYYY-MM-DD for filename comparison.\n */\nfunction formatDate(d: Date): string {\n return d.toISOString().slice(0, 10);\n}\n\n/**\n * Read and parse all JSONL entries from a log directory, optionally\n * filtered by date range. Files are read in chronological order\n * (sorted by YYYY-MM-DD filename).\n *\n * @param logDir - Directory containing YYYY-MM-DD.jsonl files\n * @param schema - Zod schema for parsing and type inference\n * @param options - Optional date range filter (inclusive boundaries)\n * @returns Array of validated, typed entries\n */\nexport async function readLogEntries<T>(\n logDir: string,\n schema: z.ZodType<T>,\n options?: { since?: Date; until?: Date },\n): Promise<T[]> {\n let fileNames: string[];\n try {\n fileNames = await readdir(logDir);\n } catch {\n // Directory does not exist or is unreadable\n return [];\n }\n\n // Keep only .jsonl files\n let jsonlFiles = fileNames.filter((f) => f.endsWith('.jsonl'));\n\n // Apply date range filtering based on filename (YYYY-MM-DD.jsonl)\n const sinceStr = options?.since ? formatDate(options.since) : undefined;\n const untilStr = options?.until ? formatDate(options.until) : undefined;\n\n if (sinceStr || untilStr) {\n jsonlFiles = jsonlFiles.filter((f) => {\n const dateStr = f.replace('.jsonl', '');\n if (sinceStr && dateStr < sinceStr) return false;\n if (untilStr && dateStr > untilStr) return false;\n return true;\n });\n }\n\n // Sort alphabetically for chronological order (YYYY-MM-DD sorts lexically)\n jsonlFiles.sort();\n\n const entries: T[] = [];\n\n for (const file of jsonlFiles) {\n const filePath = join(logDir, file);\n const rl = createInterface({\n input: createReadStream(filePath, 'utf-8'),\n crlfDelay: Infinity,\n });\n\n for await (const line of rl) {\n if (!line.trim()) continue;\n try {\n const parsed = schema.parse(JSON.parse(line));\n entries.push(parsed);\n } catch {\n // Silently skip malformed JSON or schema validation failures\n }\n }\n }\n\n return entries;\n}\n","// Output schemas for analysis results.\n// Defines the shape of summary.json and environment-snapshot.json.\n\nimport { z } from 'zod/v4';\n\n// Summary schema: aggregated usage statistics from log pre-processing\nexport const summarySchema = z.object({\n generated_at: z.iso.datetime(),\n period: z.object({\n since: z.string(), // YYYY-MM-DD\n until: z.string(), // YYYY-MM-DD\n days: z.number(),\n }),\n stats: z.object({\n total_prompts: z.number(),\n total_tool_uses: z.number(),\n total_permissions: z.number(),\n unique_sessions: z.number(),\n }),\n top_repeated_prompts: z\n .array(\n z.object({\n prompt: z.string(),\n count: z.number(),\n sessions: z.number(),\n }),\n )\n .max(20),\n tool_frequency: z.array(\n z.object({\n tool_name: z.string(),\n count: z.number(),\n avg_duration_ms: z.number().optional(),\n }),\n ),\n permission_patterns: z.array(\n z.object({\n tool_name: z.string(),\n count: z.number(),\n sessions: z.number(),\n }),\n ),\n long_prompts: z\n .array(\n z.object({\n prompt_preview: z.string(),\n length: z.number(),\n count: z.number(),\n }),\n )\n .max(10),\n});\nexport type Summary = z.infer<typeof summarySchema>;\n\n// Environment snapshot schema: discovered tools, settings, and ecosystems\nexport const environmentSnapshotSchema = z.object({\n generated_at: z.iso.datetime(),\n claude_code: z.object({\n version: z.string(),\n version_known: z.boolean(),\n compatible: z.boolean(),\n }),\n settings: z.object({\n user: z.unknown().nullable(),\n project: z.unknown().nullable(),\n local: z.unknown().nullable(),\n }),\n installed_tools: z.object({\n plugins: z.array(\n z.object({\n name: z.string(),\n marketplace: z.string(),\n enabled: z.boolean(),\n scope: z.string(),\n capabilities: z.array(z.string()),\n }),\n ),\n skills: z.array(\n z.object({\n name: z.string(),\n scope: z.enum(['user', 'project']),\n }),\n ),\n rules: z.array(\n z.object({\n name: z.string(),\n scope: z.enum(['user', 'project']),\n }),\n ),\n hooks: z.array(\n z.object({\n event: z.string(),\n scope: z.enum(['user', 'project', 'local']),\n type: z.string(),\n }),\n ),\n claude_md: z.array(\n z.object({\n path: z.string(),\n exists: z.boolean(),\n }),\n ),\n }),\n detected_ecosystems: z.array(z.string()),\n});\nexport type EnvironmentSnapshot = z.infer<typeof environmentSnapshotSchema>;\n","// Pre-processing pipeline: reads accumulated JSONL logs, computes frequency\n// counts with cross-session tracking, extracts top-N patterns, and writes\n// a compact summary.json under 50KB for the analysis agent's context window.\n\nimport { readLogEntries } from './jsonl-reader.js';\nimport { summarySchema, type Summary } from './schemas.js';\nimport {\n promptEntrySchema,\n toolEntrySchema,\n permissionEntrySchema,\n} from '../schemas/log-entry.js';\nimport type { PromptEntry, ToolEntry } from '../schemas/log-entry.js';\nimport { paths, ensureInit } from '../storage/dirs.js';\nimport writeFileAtomic from 'write-file-atomic';\n\nconst PROMPT_TRUNCATE_LEN = 100;\nconst LONG_PROMPT_THRESHOLD = 200; // word count\nconst DEFAULT_TOP_N = 20;\nconst DEFAULT_DAYS = 30;\nconst MAX_LONG_PROMPTS = 10;\n\n/**\n * Normalize a prompt string for deduplication:\n * trim, lowercase, collapse all whitespace to a single space.\n */\nfunction normalizePrompt(prompt: string): string {\n return prompt.trim().toLowerCase().replace(/\\s+/g, ' ');\n}\n\n/**\n * Format a Date as YYYY-MM-DD.\n */\nfunction formatDate(d: Date): string {\n return d.toISOString().slice(0, 10);\n}\n\n/**\n * Count items with cross-session tracking.\n * Returns a Map keyed by the normalized identifier with count and unique sessions.\n */\nfunction countWithSessions(\n items: Array<{ key: string; session: string }>,\n): Map<string, { count: number; sessions: Set<string> }> {\n const map = new Map<string, { count: number; sessions: Set<string> }>();\n for (const { key, session } of items) {\n const existing = map.get(key);\n if (existing) {\n existing.count += 1;\n existing.sessions.add(session);\n } else {\n map.set(key, { count: 1, sessions: new Set([session]) });\n }\n }\n return map;\n}\n\n/**\n * Compute tool frequency with average duration from 'post' events.\n */\nfunction computeToolFrequency(\n tools: ToolEntry[],\n): Summary['tool_frequency'] {\n const map = new Map<string, { count: number; durations: number[] }>();\n for (const entry of tools) {\n const existing = map.get(entry.tool_name);\n if (existing) {\n existing.count += 1;\n if (entry.event === 'post' && entry.duration_ms != null) {\n existing.durations.push(entry.duration_ms);\n }\n } else {\n const durations: number[] = [];\n if (entry.event === 'post' && entry.duration_ms != null) {\n durations.push(entry.duration_ms);\n }\n map.set(entry.tool_name, { count: 1, durations });\n }\n }\n\n return Array.from(map.entries())\n .map(([tool_name, { count, durations }]) => ({\n tool_name,\n count,\n avg_duration_ms:\n durations.length > 0\n ? Math.round(\n durations.reduce((sum, d) => sum + d, 0) / durations.length,\n )\n : undefined,\n }))\n .sort((a, b) => b.count - a.count);\n}\n\n/**\n * Detect long prompts (over LONG_PROMPT_THRESHOLD words).\n * Groups by normalized text, counts occurrences, returns top MAX_LONG_PROMPTS.\n */\nfunction detectLongPrompts(prompts: PromptEntry[]): Summary['long_prompts'] {\n const map = new Map<string, { length: number; count: number }>();\n for (const entry of prompts) {\n const words = entry.prompt.trim().split(/\\s+/);\n if (words.length <= LONG_PROMPT_THRESHOLD) continue;\n const key = normalizePrompt(entry.prompt);\n const existing = map.get(key);\n if (existing) {\n existing.count += 1;\n } else {\n map.set(key, { length: words.length, count: 1 });\n }\n }\n\n return Array.from(map.entries())\n .sort((a, b) => b[1].count - a[1].count)\n .slice(0, MAX_LONG_PROMPTS)\n .map(([normalized, { length, count }]) => ({\n prompt_preview: normalized.slice(0, PROMPT_TRUNCATE_LEN),\n length,\n count,\n }));\n}\n\n/**\n * Pre-process accumulated JSONL logs and produce a compact summary.\n *\n * Reads prompt, tool, and permission logs within the specified date range,\n * computes frequency counts with cross-session aggregation, and writes\n * the result atomically to paths.summary.\n *\n * @param options.since - Start of date range (defaults to 30 days ago)\n * @param options.until - End of date range (defaults to now)\n * @param options.topN - Max entries in top_repeated_prompts (defaults to 20)\n * @returns The validated Summary object\n */\nexport async function preProcess(options?: {\n since?: Date;\n until?: Date;\n topN?: number;\n}): Promise<Summary> {\n const until = options?.until ?? new Date();\n const since =\n options?.since ?? new Date(until.getTime() - DEFAULT_DAYS * 86_400_000);\n const topN = options?.topN ?? DEFAULT_TOP_N;\n\n // Read all log entries within the date range\n const [prompts, tools, permissions] = await Promise.all([\n readLogEntries(paths.logs.prompts, promptEntrySchema, { since, until }),\n readLogEntries(paths.logs.tools, toolEntrySchema, { since, until }),\n readLogEntries(paths.logs.permissions, permissionEntrySchema, {\n since,\n until,\n }),\n ]);\n\n // Unique sessions across all entry types\n const sessionSet = new Set<string>();\n for (const p of prompts) sessionSet.add(p.session_id);\n for (const t of tools) sessionSet.add(t.session_id);\n for (const perm of permissions) sessionSet.add(perm.session_id);\n\n // Prompt frequency with cross-session tracking\n const promptCounts = countWithSessions(\n prompts.map((p) => ({\n key: normalizePrompt(p.prompt),\n session: p.session_id,\n })),\n );\n\n const topRepeatedPrompts = Array.from(promptCounts.entries())\n .sort((a, b) => b[1].count - a[1].count)\n .slice(0, topN)\n .map(([key, { count, sessions }]) => ({\n prompt: key.slice(0, PROMPT_TRUNCATE_LEN),\n count,\n sessions: sessions.size,\n }));\n\n // Tool frequency with average duration\n const toolFrequency = computeToolFrequency(tools);\n\n // Permission patterns with cross-session tracking\n const permissionCounts = countWithSessions(\n permissions.map((p) => ({\n key: p.tool_name,\n session: p.session_id,\n })),\n );\n\n const permissionPatterns = Array.from(permissionCounts.entries())\n .sort((a, b) => b[1].count - a[1].count)\n .map(([tool_name, { count, sessions }]) => ({\n tool_name,\n count,\n sessions: sessions.size,\n }));\n\n // Long prompt detection\n const longPrompts = detectLongPrompts(prompts);\n\n // Construct and validate summary\n const summary: Summary = summarySchema.parse({\n generated_at: new Date().toISOString(),\n period: {\n since: formatDate(since),\n until: formatDate(until),\n days: DEFAULT_DAYS,\n },\n stats: {\n total_prompts: prompts.length,\n total_tool_uses: tools.length,\n total_permissions: permissions.length,\n unique_sessions: sessionSet.size,\n },\n top_repeated_prompts: topRepeatedPrompts,\n tool_frequency: toolFrequency,\n permission_patterns: permissionPatterns,\n long_prompts: longPrompts,\n });\n\n // Write atomically to disk\n await ensureInit();\n await writeFileAtomic(paths.summary, JSON.stringify(summary));\n\n return summary;\n}\n","// Environment scanner: discovers installed Claude Code tools via filesystem\n// scanning, reads settings at all scopes, detects Claude Code version, and\n// identifies ecosystem presence (GSD, Cog, etc.).\n\nimport { readdir, readFile, access } from 'node:fs/promises';\nimport { execFileSync } from 'node:child_process';\nimport { join } from 'node:path';\nimport { constants } from 'node:fs';\nimport writeFileAtomic from 'write-file-atomic';\nimport {\n environmentSnapshotSchema,\n type EnvironmentSnapshot,\n} from './schemas.js';\nimport { paths, ensureInit } from '../storage/dirs.js';\n\n// Version compatibility range -- tested and verified\nconst KNOWN_COMPATIBLE_MIN = '2.1.0';\nconst KNOWN_COMPATIBLE_MAX = '2.1.99';\n\n/**\n * Scan the user's environment to discover installed Claude Code tools,\n * settings, version info, and ecosystem presence. Writes the snapshot\n * atomically to paths.environmentSnapshot.\n *\n * @param cwd - Current working directory (project root)\n * @param home - User home directory (defaults to process.env.HOME)\n * @returns Validated EnvironmentSnapshot\n */\nexport async function scanEnvironment(\n cwd: string,\n home?: string,\n): Promise<EnvironmentSnapshot> {\n const homeDir = home ?? process.env.HOME ?? '';\n\n // Read all 3 settings files in parallel\n const [userSettings, projectSettings, localSettings] = await Promise.all([\n readSettingsSafe(join(homeDir, '.claude', 'settings.json')),\n readSettingsSafe(join(cwd, '.claude', 'settings.json')),\n readSettingsSafe(join(cwd, '.claude', 'settings.local.json')),\n ]);\n\n // Extract enabledPlugins from user settings if present\n const enabledPluginNames = extractEnabledPlugins(userSettings);\n\n // Run all discovery functions in parallel\n const [claudeVersion, plugins, skills, rules, hooks, claudeMds, ecosystems] =\n await Promise.all([\n Promise.resolve(detectClaudeCodeVersion()),\n discoverPlugins(homeDir, enabledPluginNames),\n discoverSkills(homeDir, cwd),\n discoverRules(cwd),\n Promise.resolve(\n discoverHooks(userSettings, projectSettings, localSettings),\n ),\n discoverClaudeMd(homeDir, cwd),\n detectEcosystems(cwd, homeDir),\n ]);\n\n const snapshot: EnvironmentSnapshot = {\n generated_at: new Date().toISOString(),\n claude_code: claudeVersion,\n settings: {\n user: userSettings,\n project: projectSettings,\n local: localSettings,\n },\n installed_tools: {\n plugins,\n skills,\n rules,\n hooks,\n claude_md: claudeMds,\n },\n detected_ecosystems: ecosystems,\n };\n\n // Validate against schema before writing\n const validated = environmentSnapshotSchema.parse(snapshot);\n\n // Write atomically to analysis directory\n await ensureInit();\n await writeFileAtomic(\n paths.environmentSnapshot,\n JSON.stringify(validated),\n );\n\n return validated;\n}\n\n// --- Internal helpers ---\n\n/**\n * Detect Claude Code version by running `claude --version`.\n * Returns { version, version_known, compatible }.\n */\nfunction detectClaudeCodeVersion(): EnvironmentSnapshot['claude_code'] {\n try {\n const output = execFileSync('claude', ['--version'], {\n timeout: 3000,\n encoding: 'utf-8',\n stdio: ['pipe', 'pipe', 'pipe'],\n }).trim();\n\n const match = output.match(/^(\\d+\\.\\d+\\.\\d+)/);\n if (!match) {\n return { version: 'unknown', version_known: false, compatible: false };\n }\n\n const version = match[1];\n const compatible =\n compareSemver(version, KNOWN_COMPATIBLE_MIN) >= 0 &&\n compareSemver(version, KNOWN_COMPATIBLE_MAX) <= 0;\n\n return { version, version_known: true, compatible };\n } catch {\n return { version: 'unknown', version_known: false, compatible: false };\n }\n}\n\n/**\n * Safely read and parse a JSON settings file.\n * Returns parsed object or null if file is missing or invalid.\n */\nasync function readSettingsSafe(\n filePath: string,\n): Promise<unknown | null> {\n try {\n const raw = await readFile(filePath, 'utf-8');\n return JSON.parse(raw) as unknown;\n } catch {\n return null;\n }\n}\n\n/**\n * Extract enabled plugin names from user settings.\n */\nfunction extractEnabledPlugins(settings: unknown): string[] {\n if (!settings || typeof settings !== 'object') return [];\n const obj = settings as Record<string, unknown>;\n if (!Array.isArray(obj.enabledPlugins)) return [];\n\n return obj.enabledPlugins\n .map((p: unknown) => {\n if (typeof p === 'string') return p;\n if (p && typeof p === 'object' && 'name' in p) {\n return String((p as { name: unknown }).name);\n }\n return null;\n })\n .filter((n): n is string => n !== null);\n}\n\n/**\n * Discover installed plugins from ~/.claude/plugins/installed_plugins.json.\n * Cross-references with enabledPlugins from settings for accuracy.\n */\nasync function discoverPlugins(\n home: string,\n enabledPluginNames: string[],\n): Promise<EnvironmentSnapshot['installed_tools']['plugins']> {\n try {\n const pluginsFile = join(home, '.claude', 'plugins', 'installed_plugins.json');\n const raw = await readFile(pluginsFile, 'utf-8');\n const installed = JSON.parse(raw) as unknown[];\n\n if (!Array.isArray(installed)) return [];\n\n const plugins: EnvironmentSnapshot['installed_tools']['plugins'] = [];\n\n for (const entry of installed) {\n if (!entry || typeof entry !== 'object') continue;\n const plugin = entry as Record<string, unknown>;\n const name = String(plugin.name ?? '');\n const marketplace = String(plugin.marketplace ?? 'unknown');\n const scope = String(plugin.scope ?? 'user');\n const version = String(plugin.version ?? 'latest');\n\n const enabled = enabledPluginNames.includes(name);\n\n // Scan plugin cache for capabilities\n const capabilities = await scanPluginCapabilities(\n home,\n marketplace,\n name,\n version,\n );\n\n plugins.push({ name, marketplace, enabled, scope, capabilities });\n }\n\n return plugins;\n } catch {\n return [];\n }\n}\n\n/**\n * Scan plugin cache directory for capability subdirectories.\n */\nasync function scanPluginCapabilities(\n home: string,\n marketplace: string,\n pluginName: string,\n version: string,\n): Promise<string[]> {\n const knownCapabilities = ['commands', 'skills', 'hooks', 'agents'];\n const capabilities: string[] = [];\n\n try {\n const cacheDir = join(\n home, '.claude', 'plugins', 'cache',\n marketplace, pluginName, version,\n );\n const entries = await readdir(cacheDir, { withFileTypes: true });\n for (const entry of entries) {\n if (entry.isDirectory() && knownCapabilities.includes(entry.name)) {\n capabilities.push(entry.name);\n }\n }\n } catch {\n // Cache directory does not exist or is unreadable\n }\n\n return capabilities;\n}\n\n/**\n * Discover skill directories at user and project scopes.\n */\nasync function discoverSkills(\n home: string,\n cwd: string,\n): Promise<EnvironmentSnapshot['installed_tools']['skills']> {\n const skills: EnvironmentSnapshot['installed_tools']['skills'] = [];\n\n // User-scope skills: ~/.claude/skills/\n try {\n const userSkillsDir = join(home, '.claude', 'skills');\n const entries = await readdir(userSkillsDir, { withFileTypes: true });\n for (const entry of entries) {\n if (entry.isDirectory()) {\n skills.push({ name: entry.name, scope: 'user' });\n }\n }\n } catch {\n // Directory does not exist\n }\n\n // Project-scope skills: {cwd}/.claude/skills/\n try {\n const projectSkillsDir = join(cwd, '.claude', 'skills');\n const entries = await readdir(projectSkillsDir, { withFileTypes: true });\n for (const entry of entries) {\n if (entry.isDirectory()) {\n skills.push({ name: entry.name, scope: 'project' });\n }\n }\n } catch {\n // Directory does not exist\n }\n\n return skills;\n}\n\n/**\n * Discover rule directories at project scope.\n */\nasync function discoverRules(\n cwd: string,\n): Promise<EnvironmentSnapshot['installed_tools']['rules']> {\n const rules: EnvironmentSnapshot['installed_tools']['rules'] = [];\n\n try {\n const rulesDir = join(cwd, '.claude', 'rules');\n const entries = await readdir(rulesDir, { withFileTypes: true });\n for (const entry of entries) {\n if (entry.isDirectory()) {\n rules.push({ name: entry.name, scope: 'project' });\n }\n }\n } catch {\n // Directory does not exist\n }\n\n return rules;\n}\n\n/**\n * Extract hook definitions from settings objects at all 3 scopes.\n */\nfunction discoverHooks(\n userSettings: unknown,\n projectSettings: unknown,\n localSettings: unknown,\n): EnvironmentSnapshot['installed_tools']['hooks'] {\n const hooks: EnvironmentSnapshot['installed_tools']['hooks'] = [];\n\n extractHooksFromSettings(userSettings, 'user', hooks);\n extractHooksFromSettings(projectSettings, 'project', hooks);\n extractHooksFromSettings(localSettings, 'local', hooks);\n\n return hooks;\n}\n\n/**\n * Extract hooks from a single settings object and append to the hooks array.\n */\nfunction extractHooksFromSettings(\n settings: unknown,\n scope: 'user' | 'project' | 'local',\n hooks: EnvironmentSnapshot['installed_tools']['hooks'],\n): void {\n if (!settings || typeof settings !== 'object') return;\n const obj = settings as Record<string, unknown>;\n if (!obj.hooks || typeof obj.hooks !== 'object') return;\n\n const hooksConfig = obj.hooks as Record<string, unknown>;\n for (const [event, defs] of Object.entries(hooksConfig)) {\n if (!Array.isArray(defs)) continue;\n for (const def of defs) {\n if (!def || typeof def !== 'object') continue;\n const hookDef = def as Record<string, unknown>;\n const type = String(hookDef.type ?? 'command');\n hooks.push({ event, scope, type });\n }\n }\n}\n\n/**\n * Discover CLAUDE.md files at common locations.\n */\nasync function discoverClaudeMd(\n home: string,\n cwd: string,\n): Promise<EnvironmentSnapshot['installed_tools']['claude_md']> {\n const locations = [\n join(cwd, 'CLAUDE.md'),\n join(cwd, '.claude', 'CLAUDE.md'),\n join(home, '.claude', 'CLAUDE.md'),\n ];\n\n const results: EnvironmentSnapshot['installed_tools']['claude_md'] = [];\n\n for (const path of locations) {\n let exists = false;\n try {\n await access(path, constants.F_OK);\n exists = true;\n } catch {\n // File does not exist\n }\n results.push({ path, exists });\n }\n\n return results;\n}\n\n/**\n * Detect known ecosystems by checking for characteristic directories.\n */\nasync function detectEcosystems(\n cwd: string,\n home: string,\n): Promise<string[]> {\n const ecosystems: string[] = [];\n\n // GSD: check for .planning/ directory\n try {\n await access(join(cwd, '.planning'), constants.F_OK);\n ecosystems.push('gsd');\n } catch {\n // No GSD detected\n }\n\n // Cog: check for 'cog' in ~/.claude/skills/\n try {\n const skillsDir = join(home, '.claude', 'skills');\n const entries = await readdir(skillsDir);\n if (entries.some((e) => e.toLowerCase().includes('cog'))) {\n ecosystems.push('cog');\n }\n } catch {\n // Skills directory does not exist\n }\n\n return ecosystems;\n}\n\n/**\n * Compare two semver strings (X.Y.Z format).\n * Returns -1, 0, or 1.\n */\nfunction compareSemver(a: string, b: string): number {\n const partsA = a.split('.').map(Number);\n const partsB = b.split('.').map(Number);\n\n for (let i = 0; i < 3; i++) {\n const numA = partsA[i] ?? 0;\n const numB = partsB[i] ?? 0;\n if (numA < numB) return -1;\n if (numA > numB) return 1;\n }\n\n return 0;\n}\n","// Classifier for repeated short prompts.\n// Detects prompts used multiple times across sessions and recommends\n// creating a hook for automation. Short = under 50 words.\n\nimport type { Summary, EnvironmentSnapshot } from '../schemas.js';\nimport type { Recommendation, AnalysisConfig } from '../../schemas/recommendation.js';\n\n/**\n * Truncate a string to maxLen characters, adding ellipsis if truncated.\n */\nfunction truncate(str: string, maxLen: number): string {\n if (str.length <= maxLen) return str;\n return str.slice(0, maxLen - 3) + '...';\n}\n\n/**\n * Classify repeated short prompts (< 50 words) as HOOK recommendations.\n *\n * HIGH confidence: count >= 10 AND sessions >= 3\n * MEDIUM confidence: count >= 5 (already past min threshold)\n *\n * Skips prompts with word count > 50 (handled by long-prompts classifier).\n */\nexport function classifyRepeatedPrompts(\n summary: Summary,\n _snapshot: EnvironmentSnapshot,\n config: AnalysisConfig,\n): Recommendation[] {\n const recommendations: Recommendation[] = [];\n const threshold = config.thresholds.repeated_prompt_min_count;\n\n for (let i = 0; i < summary.top_repeated_prompts.length; i++) {\n const entry = summary.top_repeated_prompts[i];\n\n if (entry.count < threshold) continue;\n\n // Skip long prompts -- handled by long-prompts classifier\n const wordCount = entry.prompt.split(/\\s+/).length;\n if (wordCount > 50) continue;\n\n const confidence: 'HIGH' | 'MEDIUM' =\n entry.count >= config.thresholds.repeated_prompt_high_count &&\n entry.sessions >= config.thresholds.repeated_prompt_high_sessions\n ? 'HIGH'\n : 'MEDIUM';\n\n const truncatedPrompt = truncate(entry.prompt, 60);\n\n recommendations.push({\n id: `rec-repeated-${i}`,\n target: 'HOOK',\n confidence,\n pattern_type: 'repeated_prompt',\n title: `Repeated prompt: \"${truncatedPrompt}\"`,\n description: `This prompt has been used ${entry.count} times across ${entry.sessions} sessions. Consider creating a hook or alias to automate this.`,\n evidence: {\n count: entry.count,\n sessions: entry.sessions,\n examples: [entry.prompt],\n },\n suggested_action: `Create a UserPromptSubmit hook that detects \"${truncatedPrompt}\" and auto-executes the intended action.`,\n });\n }\n\n return recommendations;\n}\n","// Classifier for long repeated prompts.\n// Detects prompts with high word count that are repeated, and recommends\n// converting them into a reusable skill.\n\nimport type { Summary, EnvironmentSnapshot } from '../schemas.js';\nimport type { Recommendation, AnalysisConfig } from '../../schemas/recommendation.js';\n\n/**\n * Classify long repeated prompts as SKILL recommendations.\n *\n * HIGH confidence: length >= 300 words AND count >= 3\n * MEDIUM confidence: length >= 200 words AND count >= 2 (past min thresholds)\n *\n * Skips entries below long_prompt_min_words or long_prompt_min_count.\n */\nexport function classifyLongPrompts(\n summary: Summary,\n _snapshot: EnvironmentSnapshot,\n config: AnalysisConfig,\n): Recommendation[] {\n const recommendations: Recommendation[] = [];\n\n for (let i = 0; i < summary.long_prompts.length; i++) {\n const entry = summary.long_prompts[i];\n\n if (entry.length < config.thresholds.long_prompt_min_words) continue;\n if (entry.count < config.thresholds.long_prompt_min_count) continue;\n\n const confidence: 'HIGH' | 'MEDIUM' =\n entry.count >= config.thresholds.long_prompt_high_count &&\n entry.length >= config.thresholds.long_prompt_high_words\n ? 'HIGH'\n : 'MEDIUM';\n\n recommendations.push({\n id: `rec-long-${i}`,\n target: 'SKILL',\n confidence,\n pattern_type: 'long_prompt',\n title: `Long repeated prompt (${entry.length} words, ${entry.count}x)`,\n description: `A ${entry.length}-word prompt has been used ${entry.count} times. Consider converting it to a reusable skill.`,\n evidence: {\n count: entry.count,\n examples: [entry.prompt_preview],\n },\n suggested_action: 'Create a skill in .claude/skills/ that encapsulates this prompt as a reusable workflow.',\n });\n }\n\n return recommendations;\n}\n","// Classifier for permission approval patterns.\n// Detects tools that are frequently approved across multiple sessions\n// and recommends adding them to allowedTools in settings.json.\n\nimport type { Summary, EnvironmentSnapshot } from '../schemas.js';\nimport type { Recommendation, AnalysisConfig } from '../../schemas/recommendation.js';\n\n/**\n * Classify permission approval patterns as SETTINGS recommendations.\n *\n * HIGH confidence: count >= 15 AND sessions >= 4\n * MEDIUM confidence: count >= 10 AND sessions >= 3 (past min thresholds)\n *\n * Skips entries below permission_approval_min_count or permission_approval_min_sessions.\n */\nexport function classifyPermissionPatterns(\n summary: Summary,\n _snapshot: EnvironmentSnapshot,\n config: AnalysisConfig,\n): Recommendation[] {\n const recommendations: Recommendation[] = [];\n\n for (let i = 0; i < summary.permission_patterns.length; i++) {\n const entry = summary.permission_patterns[i];\n\n if (entry.count < config.thresholds.permission_approval_min_count) continue;\n if (entry.sessions < config.thresholds.permission_approval_min_sessions) continue;\n\n const confidence: 'HIGH' | 'MEDIUM' =\n entry.count >= config.thresholds.permission_approval_high_count &&\n entry.sessions >= config.thresholds.permission_approval_high_sessions\n ? 'HIGH'\n : 'MEDIUM';\n\n recommendations.push({\n id: `rec-permission-always-approved-${i}`,\n target: 'SETTINGS',\n confidence,\n pattern_type: 'permission-always-approved',\n title: `Frequently approved tool: ${entry.tool_name}`,\n description: `You have approved \"${entry.tool_name}\" ${entry.count} times across ${entry.sessions} sessions. Consider adding it to allowedTools in settings.json.`,\n evidence: {\n count: entry.count,\n sessions: entry.sessions,\n examples: [`${entry.tool_name} approved ${entry.count} times`],\n },\n suggested_action: `Add \"${entry.tool_name}\" to the \"allow\" array in ~/.claude/settings.json permissions.`,\n });\n }\n\n return recommendations;\n}\n","// Classifier for code correction patterns.\n// Detects high-usage code-modification tools (Write, Edit, MultiEdit) and\n// recommends creating rules to standardize recurring modification patterns.\n// This is a LOW-confidence heuristic: the summary pre-aggregates tool usage\n// without per-tool failure rates, so we use a simplified approach.\n\nimport type { Summary, EnvironmentSnapshot } from '../schemas.js';\nimport type { Recommendation, AnalysisConfig } from '../../schemas/recommendation.js';\n\n// Tools that modify code -- high usage suggests recurring patterns\nconst CODE_MODIFICATION_TOOLS = new Set(['Write', 'Edit', 'MultiEdit']);\n\n// Minimum usage count to suggest rule creation (heuristic threshold)\nconst HIGH_USAGE_THRESHOLD = 20;\n\n/**\n * Classify code correction patterns as RULE recommendations.\n *\n * LOW confidence: code-modification tool count >= 20 uses.\n *\n * Since summary.tool_frequency does not track per-tool failure rates,\n * this classifier uses a simplified heuristic: tools that modify files\n * (Write, Edit, MultiEdit) with high usage counts are candidates for\n * coding rules or conventions.\n */\nexport function classifyCodeCorrections(\n summary: Summary,\n _snapshot: EnvironmentSnapshot,\n _config: AnalysisConfig,\n): Recommendation[] {\n const recommendations: Recommendation[] = [];\n let index = 0;\n\n for (const entry of summary.tool_frequency) {\n // Only consider code-modification tools\n if (!CODE_MODIFICATION_TOOLS.has(entry.tool_name)) continue;\n\n // Require high usage count as a proxy for recurring patterns\n if (entry.count < HIGH_USAGE_THRESHOLD) continue;\n\n recommendations.push({\n id: `rec-correction-${index}`,\n target: 'RULE',\n confidence: 'LOW',\n pattern_type: 'code_correction',\n title: `Frequent code modifications with ${entry.tool_name} (${entry.count} uses)`,\n description: `The ${entry.tool_name} tool has been used ${entry.count} times. Review for recurring patterns that could become a coding rule or convention.`,\n evidence: {\n count: entry.count,\n examples: [entry.tool_name],\n },\n suggested_action: `Review recent ${entry.tool_name} usage for recurring patterns. If a consistent code style or approach emerges, create a rule in .claude/rules/.`,\n });\n\n index++;\n }\n\n return recommendations;\n}\n","// Classifier for personal information mentions.\n// Detects prompts containing personal keywords (name, location, preferences)\n// and recommends storing them in memory for automatic context.\n\nimport type { Summary, EnvironmentSnapshot } from '../schemas.js';\nimport type { Recommendation, AnalysisConfig } from '../../schemas/recommendation.js';\n\n// Keywords that indicate personal information or preferences\nconst PERSONAL_KEYWORDS = [\n 'my name is',\n 'i live in',\n 'i work at',\n 'i prefer',\n 'my email',\n 'my project',\n 'always use',\n 'never use',\n];\n\n// Minimum repeat count to avoid flagging one-off mentions\nconst MIN_COUNT = 2;\n\n/**\n * Classify personal info mentions as MEMORY recommendations.\n *\n * LOW confidence for all matches -- keyword matching is inherently heuristic.\n *\n * Deduplicates by keyword: each keyword produces at most one recommendation,\n * using the first matching prompt as the example.\n */\nexport function classifyPersonalInfo(\n summary: Summary,\n _snapshot: EnvironmentSnapshot,\n _config: AnalysisConfig,\n): Recommendation[] {\n const recommendations: Recommendation[] = [];\n const matchedKeywords = new Set<string>();\n let index = 0;\n\n for (const entry of summary.top_repeated_prompts) {\n if (entry.count < MIN_COUNT) continue;\n\n const lowerPrompt = entry.prompt.toLowerCase();\n\n for (const keyword of PERSONAL_KEYWORDS) {\n if (matchedKeywords.has(keyword)) continue;\n if (!lowerPrompt.includes(keyword)) continue;\n\n matchedKeywords.add(keyword);\n\n recommendations.push({\n id: `rec-personal-${index}`,\n target: 'MEMORY',\n confidence: 'LOW',\n pattern_type: 'personal_info',\n title: `Personal preference detected: \"${keyword}...\"`,\n description: `A prompt mentioning personal information (\"${keyword}\") has appeared ${entry.count} times. Consider storing this in memory for automatic context.`,\n evidence: {\n count: entry.count,\n sessions: entry.sessions,\n examples: [entry.prompt],\n },\n suggested_action: 'Add this information to memory (e.g., CLAUDE.md or a memory file) so Claude Code can use it without being reminded.',\n });\n\n index++;\n }\n }\n\n return recommendations;\n}\n","// Classifier for configuration drift detection.\n// Detects potential conflicts and redundancies in the user's Claude Code\n// configuration: hook-rule overlaps, multiple CLAUDE.md files, and\n// excessive hook counts.\n\nimport type { Summary, EnvironmentSnapshot } from '../schemas.js';\nimport type { Recommendation, AnalysisConfig } from '../../schemas/recommendation.js';\n\n// Threshold for excessive hooks across all scopes\nconst MAX_HOOKS_BEFORE_REVIEW = 10;\n\n/**\n * Classify configuration drift patterns.\n *\n * All config drift recommendations are LOW confidence.\n *\n * Check 1: Hook-Rule overlap -- hooks and rules with matching names/events\n * suggest duplicated behavior that should be consolidated.\n * Check 2: Multiple CLAUDE.md -- multiple existing CLAUDE.md files may\n * contain contradictory instructions.\n * Check 3: Hook count heuristic -- more than 10 hooks suggests potential\n * redundancy that warrants review.\n */\nexport function classifyConfigDrift(\n _summary: Summary,\n snapshot: EnvironmentSnapshot,\n _config: AnalysisConfig,\n): Recommendation[] {\n const recommendations: Recommendation[] = [];\n let index = 0;\n\n // Check 1: Hook-Rule overlap\n const hookEvents = new Set(snapshot.installed_tools.hooks.map(h => h.event));\n const ruleNames = new Set(snapshot.installed_tools.rules.map(r => r.name));\n\n for (const overlap of hookEvents) {\n if (!ruleNames.has(overlap)) continue;\n\n recommendations.push({\n id: `rec-drift-${index}`,\n target: 'RULE',\n confidence: 'LOW',\n pattern_type: 'config_drift',\n title: `Hook-rule overlap detected: \"${overlap}\"`,\n description: `Both a hook (event: \"${overlap}\") and a rule (name: \"${overlap}\") exist. This may indicate duplicated behavior that should be consolidated into one mechanism.`,\n evidence: {\n count: 2,\n examples: [`Hook event: ${overlap}`, `Rule name: ${overlap}`],\n },\n suggested_action: `Review the hook and rule for \"${overlap}\". If they serve the same purpose, consolidate into the more appropriate mechanism (hooks for 100% reliability, rules for guidance).`,\n });\n\n index++;\n }\n\n // Check 2: Multiple CLAUDE.md files\n const existingClaudeMd = snapshot.installed_tools.claude_md.filter(c => c.exists);\n if (existingClaudeMd.length > 1) {\n recommendations.push({\n id: `rec-drift-${index}`,\n target: 'CLAUDE_MD',\n confidence: 'LOW',\n pattern_type: 'config_drift',\n title: `Multiple CLAUDE.md files detected (${existingClaudeMd.length})`,\n description: `Found ${existingClaudeMd.length} existing CLAUDE.md files. Multiple CLAUDE.md files may contain contradictory instructions. Review for consistency.`,\n evidence: {\n count: existingClaudeMd.length,\n examples: existingClaudeMd.slice(0, 3).map(c => c.path),\n },\n suggested_action: 'Review all CLAUDE.md files for contradictions or redundancies. Consider consolidating shared instructions into the most appropriate scope.',\n });\n\n index++;\n }\n\n // Check 3: Hook count heuristic\n if (snapshot.installed_tools.hooks.length > MAX_HOOKS_BEFORE_REVIEW) {\n recommendations.push({\n id: `rec-drift-${index}`,\n target: 'HOOK',\n confidence: 'LOW',\n pattern_type: 'config_drift',\n title: `Excessive hook count (${snapshot.installed_tools.hooks.length} hooks)`,\n description: `Found ${snapshot.installed_tools.hooks.length} hooks across all scopes. This many hooks may indicate redundancy or performance concerns. Review for consolidation.`,\n evidence: {\n count: snapshot.installed_tools.hooks.length,\n examples: snapshot.installed_tools.hooks.slice(0, 3).map(h => `${h.event} (${h.scope})`),\n },\n suggested_action: 'Review all hooks for overlapping functionality. Consider combining hooks that trigger on the same event or serve similar purposes.',\n });\n }\n\n return recommendations;\n}\n","// Classifier for ecosystem-aware routing adaptations.\n// Produces recommendations based on detected ecosystems (GSD, Cog) and\n// Claude Code version compatibility. Enhances routing suggestions with\n// ecosystem-specific context.\n\nimport type { Summary, EnvironmentSnapshot } from '../schemas.js';\nimport type { Recommendation, AnalysisConfig } from '../../schemas/recommendation.js';\n\n// Minimum prompt repeat count to consider it a multi-step workflow candidate\nconst MULTI_STEP_MIN_COUNT = 3;\n\n/**\n * Classify ecosystem-specific adaptations and version recommendations.\n *\n * Version check (RTG-10): MEDIUM confidence when Claude Code version is\n * outside the tested compatible range.\n *\n * GSD ecosystem (RTG-09): LOW confidence SKILL recommendation when GSD\n * is detected and repeated multi-step prompts exist.\n *\n * Cog ecosystem (RTG-09): LOW confidence MEMORY recommendation when Cog\n * is detected, routing memory management to Cog tiers.\n */\nexport function classifyEcosystemAdaptations(\n summary: Summary,\n snapshot: EnvironmentSnapshot,\n _config: AnalysisConfig,\n): Recommendation[] {\n const recommendations: Recommendation[] = [];\n let index = 0;\n\n // Version check (RTG-10)\n if (\n snapshot.claude_code.version_known &&\n !snapshot.claude_code.compatible &&\n snapshot.claude_code.version !== 'unknown'\n ) {\n recommendations.push({\n id: `rec-ecosystem-${index}`,\n target: 'CLAUDE_MD',\n confidence: 'MEDIUM',\n pattern_type: 'version_update',\n title: `Claude Code version ${snapshot.claude_code.version} detected (outside tested range)`,\n description: `Your Claude Code version (${snapshot.claude_code.version}) is outside the tested compatible range. New features may be available that change optimal configuration strategies.`,\n evidence: {\n count: 1,\n examples: [`Version: ${snapshot.claude_code.version}`],\n },\n suggested_action: `Review Claude Code changelog for version ${snapshot.claude_code.version}. New hook events, permission models, or settings may require harness-evolve configuration updates.`,\n });\n index++;\n }\n\n // GSD ecosystem (RTG-09)\n if (snapshot.detected_ecosystems.includes('gsd')) {\n // Look for repeated multi-step prompts that could be GSD workflows\n const multiStepPrompts = summary.top_repeated_prompts.filter(\n p => p.count >= MULTI_STEP_MIN_COUNT,\n );\n\n if (multiStepPrompts.length > 0) {\n const topPrompt = multiStepPrompts[0];\n recommendations.push({\n id: `rec-ecosystem-${index}`,\n target: 'SKILL',\n confidence: 'LOW',\n pattern_type: 'ecosystem_gsd',\n title: 'GSD workflow detected -- consider /gsd slash commands',\n description: 'GSD is installed in this project. Repeated multi-step prompts may be better served by GSD planning phases or slash commands rather than standalone skills.',\n evidence: {\n count: multiStepPrompts.length,\n examples: [topPrompt.prompt],\n },\n suggested_action: 'Review repeated prompts and consider if they map to GSD phases (/gsd:plan-phase, /gsd:execute-phase) or custom slash commands.',\n ecosystem_context: 'GSD detected: Use /gsd slash commands and .planning patterns for multi-step workflows instead of standalone skills',\n });\n index++;\n }\n }\n\n // Cog ecosystem (RTG-09)\n if (snapshot.detected_ecosystems.includes('cog')) {\n recommendations.push({\n id: `rec-ecosystem-${index}`,\n target: 'MEMORY',\n confidence: 'LOW',\n pattern_type: 'ecosystem_cog',\n title: 'Cog memory system detected -- route memory to Cog tiers',\n description: \"Cog is installed. Personal information and contextual preferences should be routed to Cog's tiered memory system rather than raw CLAUDE.md entries.\",\n evidence: {\n count: 1,\n examples: ['Cog detected in ~/.claude/skills/'],\n },\n suggested_action: 'Use /reflect and /evolve Cog commands for memory management instead of manually editing CLAUDE.md.',\n ecosystem_context: 'Cog detected: Route memory entries to Cog tiers (/reflect, /evolve) instead of raw CLAUDE.md',\n });\n }\n\n return recommendations;\n}\n","// Pure function to compute user experience level from environment snapshot.\n// Scores each tool category by weight and maps total score to a tier:\n// 0 -> newcomer, 1-29 -> intermediate, 30+ -> power_user.\n// Weights reflect automation investment: plugins (10), hooks (8), ecosystems (7),\n// rules (6), skills (5), claude_md (3).\n\nimport type { EnvironmentSnapshot } from './schemas.js';\nimport type { ExperienceLevel, ExperienceTier } from '../schemas/onboarding.js';\n\nexport function computeExperienceLevel(snapshot: EnvironmentSnapshot): ExperienceLevel {\n const hooks = snapshot.installed_tools.hooks.length;\n const rules = snapshot.installed_tools.rules.length;\n const skills = snapshot.installed_tools.skills.length;\n const plugins = snapshot.installed_tools.plugins.length;\n const claudeMd = snapshot.installed_tools.claude_md.filter(c => c.exists).length;\n const ecosystems = snapshot.detected_ecosystems.length;\n\n const score = Math.min(100,\n hooks * 8 + rules * 6 + skills * 5 +\n plugins * 10 + claudeMd * 3 + ecosystems * 7,\n );\n\n const tier: ExperienceTier =\n score === 0 ? 'newcomer' :\n score < 30 ? 'intermediate' :\n 'power_user';\n\n return {\n tier,\n score,\n breakdown: { hooks, rules, skills, plugins, claude_md: claudeMd, ecosystems },\n };\n}\n","// Classifier for tiered onboarding detection.\n// Produces tier-appropriate recommendations based on user experience level:\n// newcomer (score=0) gets \"start here\" guidance for missing config,\n// power_user (score>=30) gets \"optimize\" suggestions,\n// intermediate (1-29) gets no onboarding-specific recs (handled by other classifiers).\n\nimport type { Summary, EnvironmentSnapshot } from '../schemas.js';\nimport type { Recommendation, AnalysisConfig } from '../../schemas/recommendation.js';\nimport { computeExperienceLevel } from '../experience-level.js';\n\n/**\n * Classify onboarding needs based on user experience tier.\n *\n * Newcomer (score=0): Up to 3 MEDIUM-confidence \"start here\" recommendations\n * for missing hooks, rules, and CLAUDE.md.\n *\n * Power user (score>=30): 1 LOW-confidence \"optimize\" recommendation\n * suggesting consolidation review.\n *\n * Intermediate (1-29): No recommendations (existing classifiers handle\n * pattern-specific suggestions).\n */\nexport function classifyOnboarding(\n _summary: Summary,\n snapshot: EnvironmentSnapshot,\n _config: AnalysisConfig,\n): Recommendation[] {\n const level = computeExperienceLevel(snapshot);\n const recommendations: Recommendation[] = [];\n let index = 0;\n\n if (level.tier === 'newcomer') {\n // Suggest missing hooks\n if (level.breakdown.hooks === 0) {\n recommendations.push({\n id: `rec-onboarding-${index}`,\n target: 'HOOK',\n confidence: 'MEDIUM',\n pattern_type: 'onboarding_start_hooks',\n title: 'Start automating: create your first hook',\n description:\n 'Hooks run automatically on Claude Code lifecycle events (pre-commit, tool use, session start). ' +\n 'Start with a formatting or test-on-save hook to experience automation benefits.',\n evidence: {\n count: 0,\n examples: ['No hooks detected in your environment'],\n },\n suggested_action:\n 'Add a hook in .claude/settings.json hooks section for automation.',\n });\n index++;\n }\n\n // Suggest missing rules\n if (level.breakdown.rules === 0) {\n recommendations.push({\n id: `rec-onboarding-${index}`,\n target: 'RULE',\n confidence: 'MEDIUM',\n pattern_type: 'onboarding_start_rules',\n title: 'Define coding preferences: add your first rule',\n description:\n 'Rules (.claude/rules/) codify conventions that Claude follows automatically. ' +\n 'They persist across sessions and ensure consistent behavior.',\n evidence: {\n count: 0,\n examples: ['No rules detected in your environment'],\n },\n suggested_action:\n 'Create .claude/rules/ directory with a rule for your preferred coding style.',\n });\n index++;\n }\n\n // Suggest missing CLAUDE.md\n if (level.breakdown.claude_md === 0) {\n recommendations.push({\n id: `rec-onboarding-${index}`,\n target: 'CLAUDE_MD',\n confidence: 'MEDIUM',\n pattern_type: 'onboarding_start_claudemd',\n title: 'Set project context: create CLAUDE.md',\n description:\n 'CLAUDE.md gives Claude project-specific context — tech stack, conventions, and constraints. ' +\n 'It is loaded automatically at the start of every conversation.',\n evidence: {\n count: 0,\n examples: ['No CLAUDE.md files detected in your environment'],\n },\n suggested_action:\n 'Create CLAUDE.md in your project root with project description and conventions.',\n });\n }\n } else if (level.tier === 'power_user') {\n recommendations.push({\n id: 'rec-onboarding-3',\n target: 'SETTINGS',\n confidence: 'LOW',\n pattern_type: 'onboarding_optimize',\n title: 'Consider mechanizing recurring patterns',\n description:\n 'Your extensive configuration suggests active automation investment. ' +\n 'Review for redundancy or upgrade opportunities — hooks and rules with overlapping concerns can be consolidated.',\n evidence: {\n count: level.score,\n examples: [\n `${level.breakdown.hooks} hooks, ${level.breakdown.rules} rules, ${level.breakdown.plugins} plugins installed`,\n ],\n },\n suggested_action:\n 'Review your hooks and rules for overlapping concerns that could be consolidated.',\n });\n }\n // Intermediate: return empty array\n\n return recommendations;\n}\n","// Classifier registry: defines the Classifier type and holds all registered\n// classifier functions. New classifiers are added by importing and pushing\n// to the classifiers array.\n\nimport type { Summary, EnvironmentSnapshot } from '../schemas.js';\nimport type { Recommendation, AnalysisConfig } from '../../schemas/recommendation.js';\nimport { classifyRepeatedPrompts } from './repeated-prompts.js';\nimport { classifyLongPrompts } from './long-prompts.js';\nimport { classifyPermissionPatterns } from './permission-patterns.js';\nimport { classifyCodeCorrections } from './code-corrections.js';\nimport { classifyPersonalInfo } from './personal-info.js';\nimport { classifyConfigDrift } from './config-drift.js';\nimport { classifyEcosystemAdaptations } from './ecosystem-adapter.js';\nimport { classifyOnboarding } from './onboarding.js';\n\nexport type Classifier = (\n summary: Summary,\n snapshot: EnvironmentSnapshot,\n config: AnalysisConfig,\n) => Recommendation[];\n\n// Registered classifiers, evaluated in order by the analyzer\nexport const classifiers: Classifier[] = [\n classifyRepeatedPrompts,\n classifyLongPrompts,\n classifyPermissionPatterns,\n classifyCodeCorrections,\n classifyPersonalInfo,\n classifyConfigDrift,\n classifyEcosystemAdaptations,\n classifyOnboarding,\n];\n","// Recommendation and analysis result schemas.\n// Defines the output contracts for the analysis engine: routing targets,\n// confidence tiers, recommendation structure, and analysis configuration.\n\nimport { z } from 'zod/v4';\n\nexport const routingTargetSchema = z.enum([\n 'HOOK',\n 'SKILL',\n 'RULE',\n 'CLAUDE_MD',\n 'MEMORY',\n 'SETTINGS',\n]);\nexport type RoutingTarget = z.infer<typeof routingTargetSchema>;\n\nexport const confidenceSchema = z.enum(['HIGH', 'MEDIUM', 'LOW']);\nexport type Confidence = z.infer<typeof confidenceSchema>;\n\nexport const patternTypeSchema = z.enum([\n 'repeated_prompt',\n 'long_prompt',\n 'permission-always-approved',\n 'code_correction',\n 'personal_info',\n 'config_drift',\n 'version_update',\n 'ecosystem_gsd',\n 'ecosystem_cog',\n 'onboarding_start_hooks',\n 'onboarding_start_rules',\n 'onboarding_start_claudemd',\n 'onboarding_optimize',\n 'scan_redundancy',\n 'scan_missing_mechanization',\n 'scan_stale_reference',\n]);\nexport type PatternType = z.infer<typeof patternTypeSchema>;\n\nexport const recommendationSchema = z.object({\n id: z.string(),\n target: routingTargetSchema,\n confidence: confidenceSchema,\n pattern_type: patternTypeSchema,\n title: z.string(),\n description: z.string(),\n evidence: z.object({\n count: z.number(),\n sessions: z.number().optional(),\n examples: z.array(z.string()).max(3),\n }),\n suggested_action: z.string(),\n ecosystem_context: z.string().optional(),\n});\nexport type Recommendation = z.infer<typeof recommendationSchema>;\n\n// Default threshold values for classifiers\nconst DEFAULT_THRESHOLDS = {\n repeated_prompt_min_count: 5,\n repeated_prompt_high_count: 10,\n repeated_prompt_high_sessions: 3,\n repeated_prompt_medium_sessions: 2,\n long_prompt_min_words: 200,\n long_prompt_min_count: 2,\n long_prompt_high_words: 300,\n long_prompt_high_count: 3,\n permission_approval_min_count: 10,\n permission_approval_min_sessions: 3,\n permission_approval_high_count: 15,\n permission_approval_high_sessions: 4,\n code_correction_min_failure_rate: 0.3,\n code_correction_min_failures: 3,\n} as const;\n\nexport const analysisConfigSchema = z.object({\n thresholds: z.object({\n repeated_prompt_min_count: z.number().default(DEFAULT_THRESHOLDS.repeated_prompt_min_count),\n repeated_prompt_high_count: z.number().default(DEFAULT_THRESHOLDS.repeated_prompt_high_count),\n repeated_prompt_high_sessions: z.number().default(DEFAULT_THRESHOLDS.repeated_prompt_high_sessions),\n repeated_prompt_medium_sessions: z.number().default(DEFAULT_THRESHOLDS.repeated_prompt_medium_sessions),\n long_prompt_min_words: z.number().default(DEFAULT_THRESHOLDS.long_prompt_min_words),\n long_prompt_min_count: z.number().default(DEFAULT_THRESHOLDS.long_prompt_min_count),\n long_prompt_high_words: z.number().default(DEFAULT_THRESHOLDS.long_prompt_high_words),\n long_prompt_high_count: z.number().default(DEFAULT_THRESHOLDS.long_prompt_high_count),\n permission_approval_min_count: z.number().default(DEFAULT_THRESHOLDS.permission_approval_min_count),\n permission_approval_min_sessions: z.number().default(DEFAULT_THRESHOLDS.permission_approval_min_sessions),\n permission_approval_high_count: z.number().default(DEFAULT_THRESHOLDS.permission_approval_high_count),\n permission_approval_high_sessions: z.number().default(DEFAULT_THRESHOLDS.permission_approval_high_sessions),\n code_correction_min_failure_rate: z.number().default(DEFAULT_THRESHOLDS.code_correction_min_failure_rate),\n code_correction_min_failures: z.number().default(DEFAULT_THRESHOLDS.code_correction_min_failures),\n }).default(() => ({ ...DEFAULT_THRESHOLDS })),\n max_recommendations: z.number().default(20),\n}).default(() => ({\n thresholds: { ...DEFAULT_THRESHOLDS },\n max_recommendations: 20,\n}));\nexport type AnalysisConfig = z.infer<typeof analysisConfigSchema>;\n\nexport const analysisResultSchema = z.object({\n generated_at: z.iso.datetime(),\n summary_period: z.object({\n since: z.string(),\n until: z.string(),\n days: z.number(),\n }),\n recommendations: z.array(recommendationSchema),\n metadata: z.object({\n classifier_count: z.number(),\n patterns_evaluated: z.number(),\n environment_ecosystems: z.array(z.string()),\n claude_code_version: z.string(),\n }),\n});\nexport type AnalysisResult = z.infer<typeof analysisResultSchema>;\n","// Main analysis orchestrator: iterates all registered classifiers,\n// collects recommendations, sorts by confidence and evidence, caps\n// at max_recommendations, and returns a validated AnalysisResult.\n\nimport { classifiers } from './classifiers/index.js';\nimport type { Summary, EnvironmentSnapshot } from './schemas.js';\nimport {\n analysisConfigSchema,\n analysisResultSchema,\n type AnalysisConfig,\n type AnalysisResult,\n type Recommendation,\n} from '../schemas/recommendation.js';\nimport type { OutcomeSummary } from '../schemas/onboarding.js';\n\n// Confidence tier numeric ordering for sorting (ascending = higher priority)\nconst CONFIDENCE_ORDER: Record<string, number> = {\n HIGH: 0,\n MEDIUM: 1,\n LOW: 2,\n};\n\n/**\n * Sort recommendations by confidence (HIGH first), then by evidence.count\n * descending within the same tier.\n */\nfunction sortRecommendations(a: Recommendation, b: Recommendation): number {\n const confDiff =\n (CONFIDENCE_ORDER[a.confidence] ?? 3) -\n (CONFIDENCE_ORDER[b.confidence] ?? 3);\n if (confDiff !== 0) return confDiff;\n return b.evidence.count - a.evidence.count;\n}\n\n/**\n * Adjust recommendation confidence based on historical outcome data.\n * Pattern types with >30% revert rate (persistence_rate < 0.7) get\n * downgraded by one tier: HIGH->MEDIUM, MEDIUM->LOW, LOW stays LOW.\n */\nexport function adjustConfidence(\n recommendations: Recommendation[],\n summaries: OutcomeSummary[],\n): Recommendation[] {\n const rateByType = new Map(\n summaries.map((s) => [s.pattern_type, s.persistence_rate]),\n );\n\n return recommendations.map((rec) => {\n const rate = rateByType.get(rec.pattern_type);\n if (rate === undefined || rate >= 0.7) return rec;\n\n // Downgrade one tier\n const downgraded: Record<string, string> = {\n HIGH: 'MEDIUM',\n MEDIUM: 'LOW',\n LOW: 'LOW',\n };\n\n return {\n ...rec,\n confidence: (downgraded[rec.confidence] ??\n rec.confidence) as Recommendation['confidence'],\n };\n });\n}\n\n/**\n * Analyze a pre-processed summary and environment snapshot to produce\n * structured recommendations.\n *\n * @param summary - Pre-processed usage summary from pre-processor\n * @param snapshot - Environment snapshot from environment-scanner\n * @param config - Optional analysis configuration (defaults applied if omitted)\n * @param outcomeSummaries - Optional outcome summaries for confidence adjustment\n * @returns Validated AnalysisResult with sorted, capped recommendations\n */\nexport function analyze(\n summary: Summary,\n snapshot: EnvironmentSnapshot,\n config?: AnalysisConfig,\n outcomeSummaries?: OutcomeSummary[],\n): AnalysisResult {\n const mergedConfig = config ?? analysisConfigSchema.parse({});\n\n // Collect recommendations from all classifiers\n const recommendations: Recommendation[] = [];\n for (const classify of classifiers) {\n const results = classify(summary, snapshot, mergedConfig);\n recommendations.push(...results);\n }\n\n // Adjust confidence based on outcome history (if provided)\n const adjusted =\n outcomeSummaries && outcomeSummaries.length > 0\n ? adjustConfidence(recommendations, outcomeSummaries)\n : recommendations;\n\n // Sort by confidence tier, then by evidence count\n adjusted.sort(sortRecommendations);\n\n // Cap at max_recommendations\n const capped = adjusted.slice(0, mergedConfig.max_recommendations);\n\n // Compute patterns_evaluated as sum of all pattern source arrays\n const patternsEvaluated =\n summary.top_repeated_prompts.length +\n summary.long_prompts.length +\n summary.permission_patterns.length +\n summary.tool_frequency.length;\n\n return analysisResultSchema.parse({\n generated_at: new Date().toISOString(),\n summary_period: summary.period,\n recommendations: capped,\n metadata: {\n classifier_count: classifiers.length,\n patterns_evaluated: patternsEvaluated,\n environment_ecosystems: snapshot.detected_ecosystems,\n claude_code_version: snapshot.claude_code.version,\n },\n });\n}\n","// Outcome tracker: cross-references applied recommendations against\n// the current environment snapshot to determine whether changes persist.\n// Persists outcomes as JSONL and computes pattern-level summaries for\n// confidence adjustment in subsequent analysis runs.\n\nimport { readFile, appendFile } from 'node:fs/promises';\nimport { paths } from '../storage/dirs.js';\nimport { loadState } from '../delivery/state.js';\nimport {\n outcomeEntrySchema,\n type OutcomeEntry,\n type OutcomeSummary,\n} from '../schemas/onboarding.js';\nimport type { RecommendationStateEntry } from '../schemas/delivery.js';\nimport type { EnvironmentSnapshot } from './schemas.js';\n\n/**\n * Track outcomes for all applied recommendations by checking their\n * persistence in the current environment snapshot.\n *\n * For each applied recommendation:\n * 1. Check if the change still exists in the environment\n * 2. Determine outcome: positive (persisted 5+ checks), negative (reverted),\n * or monitoring (persisted but < 5 checks)\n * 3. Append outcome entry to JSONL history\n *\n * @param snapshot - Current environment snapshot\n * @returns Array of outcome entries for all applied recommendations\n */\nexport async function trackOutcomes(\n snapshot: EnvironmentSnapshot,\n): Promise<OutcomeEntry[]> {\n const state = await loadState();\n const applied = state.entries.filter((e) => e.status === 'applied');\n\n if (applied.length === 0) return [];\n\n const history = await loadOutcomeHistory();\n const results: OutcomeEntry[] = [];\n\n for (const entry of applied) {\n // Find most recent outcome for this recommendation\n const priorEntries = history.filter(\n (h) => h.recommendation_id === entry.id,\n );\n const latest = priorEntries.length > 0\n ? priorEntries[priorEntries.length - 1]\n : undefined;\n\n const checksCount = latest\n ? latest.checks_since_applied + 1\n : 1;\n\n const persisted = checkPersistence(entry, snapshot);\n\n // Determine outcome\n let outcome: 'positive' | 'negative' | 'monitoring';\n if (!persisted) {\n outcome = 'negative';\n } else if (checksCount >= 5) {\n outcome = 'positive';\n } else {\n outcome = 'monitoring';\n }\n\n // Infer pattern_type from the recommendation ID prefix\n const patternType = inferPatternType(entry.id);\n\n // Infer target from the recommendation ID prefix\n const target = inferTarget(entry.id);\n\n const outcomeEntry: OutcomeEntry = {\n recommendation_id: entry.id,\n pattern_type: patternType,\n target,\n applied_at: entry.updated_at,\n checked_at: new Date().toISOString(),\n persisted,\n checks_since_applied: checksCount,\n outcome,\n };\n\n results.push(outcomeEntry);\n await appendOutcome(outcomeEntry);\n }\n\n return results;\n}\n\n/**\n * Check whether an applied recommendation's change still persists\n * in the current environment.\n *\n * Detection heuristics by recommendation type:\n * - SETTINGS (allowedTools): check if tool exists in snapshot settings\n * - HOOK (rec-repeated-*): check if hooks exist in snapshot\n * - SKILL (rec-long-*): check if skills exist in snapshot\n * - RULE (rec-correction-*): check if rules exist in snapshot\n * - Default: assume persisted when persistence cannot be verified\n */\nfunction checkPersistence(\n entry: RecommendationStateEntry,\n snapshot: EnvironmentSnapshot,\n): boolean {\n // SETTINGS persistence: check allowedTools\n if (entry.applied_details) {\n const toolMatch = entry.applied_details.match(/Added (\\w+) to allowedTools/);\n if (toolMatch) {\n const toolName = toolMatch[1];\n const userSettings = snapshot.settings.user as Record<string, unknown> | null;\n if (!userSettings) return false;\n const allowedTools = userSettings.allowedTools;\n if (!Array.isArray(allowedTools)) return false;\n return allowedTools.includes(toolName);\n }\n }\n\n // HOOK persistence: rec-repeated-* prefix\n if (entry.id.startsWith('rec-repeated-')) {\n return snapshot.installed_tools.hooks.length > 0;\n }\n\n // SKILL persistence: rec-long-* prefix\n if (entry.id.startsWith('rec-long-')) {\n return snapshot.installed_tools.skills.length > 0;\n }\n\n // RULE persistence: rec-correction-* prefix\n if (entry.id.startsWith('rec-correction-')) {\n return snapshot.installed_tools.rules.length > 0;\n }\n\n // Default: assume persisted when we cannot verify\n return true;\n}\n\n/**\n * Append an outcome entry to the JSONL history file.\n */\nasync function appendOutcome(entry: OutcomeEntry): Promise<void> {\n await appendFile(\n paths.outcomeHistory,\n JSON.stringify(entry) + '\\n',\n 'utf-8',\n );\n}\n\n/**\n * Load outcome history from the JSONL file.\n * Returns empty array when the file does not exist.\n * Silently skips invalid or malformed lines.\n */\nexport async function loadOutcomeHistory(): Promise<OutcomeEntry[]> {\n let raw: string;\n try {\n raw = await readFile(paths.outcomeHistory, 'utf-8');\n } catch (err: unknown) {\n if (isNodeError(err) && err.code === 'ENOENT') {\n return [];\n }\n throw err;\n }\n\n const entries: OutcomeEntry[] = [];\n const lines = raw.split('\\n').filter((line) => line.trim().length > 0);\n\n for (const line of lines) {\n try {\n const parsed = JSON.parse(line);\n const result = outcomeEntrySchema.safeParse(parsed);\n if (result.success) {\n entries.push(result.data);\n }\n } catch {\n // Skip malformed JSON lines silently\n }\n }\n\n return entries;\n}\n\n/**\n * Compute outcome summaries grouped by pattern_type.\n * For each group: counts unique recommendation_ids, tallies positive\n * (persisted) and negative (reverted) outcomes, and computes\n * persistence_rate = persisted / total_applied.\n *\n * Uses the latest outcome per recommendation_id for determination.\n */\nexport function computeOutcomeSummaries(\n history: OutcomeEntry[],\n): OutcomeSummary[] {\n if (history.length === 0) return [];\n\n // Group by pattern_type\n const groups = new Map<string, OutcomeEntry[]>();\n for (const entry of history) {\n const group = groups.get(entry.pattern_type) ?? [];\n group.push(entry);\n groups.set(entry.pattern_type, group);\n }\n\n const summaries: OutcomeSummary[] = [];\n\n for (const [patternType, entries] of groups) {\n // Get the latest entry per recommendation_id\n const latestByRec = new Map<string, OutcomeEntry>();\n for (const entry of entries) {\n latestByRec.set(entry.recommendation_id, entry);\n }\n\n let totalPersisted = 0;\n let totalReverted = 0;\n\n for (const entry of latestByRec.values()) {\n if (entry.outcome === 'positive') {\n totalPersisted++;\n } else if (entry.outcome === 'negative') {\n totalReverted++;\n }\n // 'monitoring' entries don't count toward either\n }\n\n const totalApplied = latestByRec.size;\n const persistenceRate = totalApplied > 0\n ? totalPersisted / totalApplied\n : 0;\n\n summaries.push({\n pattern_type: patternType,\n total_applied: totalApplied,\n total_persisted: totalPersisted,\n total_reverted: totalReverted,\n persistence_rate: persistenceRate,\n });\n }\n\n return summaries;\n}\n\n/**\n * Infer the pattern type from a recommendation ID prefix.\n * Values must match the exact strings produced by each classifier.\n * For prefixes that map to multiple sub-types (ecosystem, onboarding),\n * the most common sub-type is returned as a best-effort default.\n */\nfunction inferPatternType(id: string): string {\n if (id.startsWith('rec-repeated-')) return 'repeated_prompt';\n if (id.startsWith('rec-long-')) return 'long_prompt';\n if (id.startsWith('rec-permission-always-approved-')) return 'permission-always-approved';\n if (id.startsWith('rec-correction-')) return 'code_correction';\n if (id.startsWith('rec-personal-')) return 'personal_info';\n if (id.startsWith('rec-drift-')) return 'config_drift';\n if (id.startsWith('rec-ecosystem-')) return 'version_update';\n if (id.startsWith('rec-onboarding-')) return 'onboarding_start_hooks';\n if (id.startsWith('rec-tool-preference-')) return 'tool-preference';\n return 'unknown';\n}\n\n/**\n * Infer the routing target from a recommendation ID prefix.\n * Covers all 8 classifier prefixes plus tool-preference.\n */\nfunction inferTarget(id: string): string {\n if (id.startsWith('rec-repeated-')) return 'HOOK';\n if (id.startsWith('rec-long-')) return 'SKILL';\n if (id.startsWith('rec-permission-always-approved-')) return 'SETTINGS';\n if (id.startsWith('rec-correction-')) return 'RULE';\n if (id.startsWith('rec-personal-')) return 'MEMORY';\n if (id.startsWith('rec-drift-')) return 'CLAUDE_MD';\n if (id.startsWith('rec-ecosystem-')) return 'CLAUDE_MD';\n if (id.startsWith('rec-tool-preference-')) return 'SETTINGS';\n if (id.startsWith('rec-onboarding-')) return 'HOOK';\n return 'MEMORY';\n}\n\n// Type guard for Node.js errors with code property\nfunction isNodeError(err: unknown): err is NodeJS.ErrnoException {\n return err instanceof Error && 'code' in err;\n}\n","// Recommendation state lifecycle management.\n// Tracks recommendation statuses (pending/applied/dismissed) in a JSON file\n// that survives across analysis re-runs and sessions.\n\nimport { readFile } from 'node:fs/promises';\nimport writeFileAtomic from 'write-file-atomic';\nimport { paths } from '../storage/dirs.js';\nimport {\n recommendationStateSchema,\n type RecommendationState,\n type RecommendationStatus,\n} from '../schemas/delivery.js';\n\n/**\n * Load the recommendation state from disk.\n * Returns an empty state when the file does not exist.\n */\nexport async function loadState(): Promise<RecommendationState> {\n try {\n const raw = await readFile(paths.recommendationState, 'utf-8');\n return recommendationStateSchema.parse(JSON.parse(raw));\n } catch (err: unknown) {\n // File not found or invalid JSON: return empty state\n if (isNodeError(err) && err.code === 'ENOENT') {\n return { entries: [], last_updated: new Date().toISOString() };\n }\n // Re-throw unexpected errors\n throw err;\n }\n}\n\n/**\n * Save the recommendation state atomically to disk.\n */\nexport async function saveState(state: RecommendationState): Promise<void> {\n await writeFileAtomic(\n paths.recommendationState,\n JSON.stringify(state, null, 2),\n );\n}\n\n/**\n * Update the status of a recommendation by ID.\n * Creates a new entry if the ID is not found.\n */\nexport async function updateStatus(\n id: string,\n status: RecommendationStatus,\n details?: string,\n): Promise<void> {\n const state = await loadState();\n const now = new Date().toISOString();\n\n const existing = state.entries.find((e) => e.id === id);\n if (existing) {\n existing.status = status;\n existing.updated_at = now;\n if (status === 'applied' && details !== undefined) {\n existing.applied_details = details;\n } else if (status !== 'applied') {\n // Clear applied_details when not in applied status\n existing.applied_details = undefined;\n }\n } else {\n state.entries.push({\n id,\n status,\n updated_at: now,\n ...(status === 'applied' && details !== undefined\n ? { applied_details: details }\n : {}),\n });\n }\n\n state.last_updated = now;\n await saveState(state);\n}\n\n/**\n * Get a Map of recommendation ID to status for quick lookups.\n */\nexport async function getStatusMap(): Promise<Map<string, RecommendationStatus>> {\n const state = await loadState();\n return new Map(state.entries.map((e) => [e.id, e.status]));\n}\n\n// Type guard for Node.js errors with code property\nfunction isNodeError(err: unknown): err is NodeJS.ErrnoException {\n return err instanceof Error && 'code' in err;\n}\n","// Delivery schemas for recommendation state tracking and auto-apply logging.\n// Defines: recommendation status lifecycle (pending/applied/dismissed),\n// state entries persisted in JSON, and auto-apply audit log entries.\n\nimport { z } from 'zod/v4';\n\nexport const recommendationStatusSchema = z.enum(['pending', 'applied', 'dismissed']);\nexport type RecommendationStatus = z.infer<typeof recommendationStatusSchema>;\n\nexport const recommendationStateEntrySchema = z.object({\n id: z.string(),\n status: recommendationStatusSchema,\n updated_at: z.iso.datetime(),\n applied_details: z.string().optional(),\n});\nexport type RecommendationStateEntry = z.infer<typeof recommendationStateEntrySchema>;\n\nexport const recommendationStateSchema = z.object({\n entries: z.array(recommendationStateEntrySchema),\n last_updated: z.iso.datetime(),\n});\nexport type RecommendationState = z.infer<typeof recommendationStateSchema>;\n\nexport const autoApplyLogEntrySchema = z.object({\n timestamp: z.iso.datetime(),\n recommendation_id: z.string(),\n target: z.string(),\n action: z.string(),\n success: z.boolean(),\n details: z.string().optional(),\n backup_path: z.string().optional(),\n});\nexport type AutoApplyLogEntry = z.infer<typeof autoApplyLogEntrySchema>;\n","// Phase 6 schemas for onboarding detection and outcome tracking.\n// Defines: experience tier classification, experience level with score\n// breakdown, outcome tracking entries, and outcome summary aggregation.\n\nimport { z } from 'zod/v4';\n\n// Experience level types\nexport const experienceTierSchema = z.enum(['newcomer', 'intermediate', 'power_user']);\nexport type ExperienceTier = z.infer<typeof experienceTierSchema>;\n\nexport const experienceLevelSchema = z.object({\n tier: experienceTierSchema,\n score: z.number().min(0).max(100),\n breakdown: z.object({\n hooks: z.number(),\n rules: z.number(),\n skills: z.number(),\n plugins: z.number(),\n claude_md: z.number(),\n ecosystems: z.number(),\n }),\n});\nexport type ExperienceLevel = z.infer<typeof experienceLevelSchema>;\n\n// Outcome tracking types (used by Plan 02)\nexport const outcomeEntrySchema = z.object({\n recommendation_id: z.string(),\n pattern_type: z.string(),\n target: z.string(),\n applied_at: z.iso.datetime(),\n checked_at: z.iso.datetime(),\n persisted: z.boolean(),\n checks_since_applied: z.number(),\n outcome: z.enum(['positive', 'negative', 'monitoring']),\n});\nexport type OutcomeEntry = z.infer<typeof outcomeEntrySchema>;\n\nexport const outcomeSummarySchema = z.object({\n pattern_type: z.string(),\n total_applied: z.number(),\n total_persisted: z.number(),\n total_reverted: z.number(),\n persistence_rate: z.number(),\n});\nexport type OutcomeSummary = z.infer<typeof outcomeSummarySchema>;\n","// Threshold trigger: orchestrates analysis when counter reaches the configured\n// threshold. Respects cooldown period, resets counter after success, preserves\n// counter on failure for automatic retry at next threshold check.\n\nimport { readCounter } from '../storage/counter.js';\nimport { loadConfig } from '../storage/config.js';\nimport { paths, ensureInit } from '../storage/dirs.js';\nimport { preProcess } from './pre-processor.js';\nimport { scanEnvironment } from './environment-scanner.js';\nimport { analyze } from './analyzer.js';\nimport {\n trackOutcomes,\n loadOutcomeHistory,\n computeOutcomeSummaries,\n} from './outcome-tracker.js';\nimport type { OutcomeSummary } from '../schemas/onboarding.js';\nimport type { AnalysisResult } from '../schemas/recommendation.js';\nimport writeFileAtomic from 'write-file-atomic';\nimport { readFile } from 'node:fs/promises';\nimport { lock } from 'proper-lockfile';\n\n// Cooldown period: prevent re-triggering analysis within 60 seconds of last run\nconst COOLDOWN_MS = 60_000;\n\n/**\n * Write an AnalysisResult to the analysis-result.json path atomically.\n */\nexport async function writeAnalysisResult(\n result: AnalysisResult,\n): Promise<void> {\n await ensureInit();\n await writeFileAtomic(paths.analysisResult, JSON.stringify(result, null, 2));\n}\n\n/**\n * Run the full analysis pipeline: preProcess -> scanEnvironment -> analyze -> write.\n *\n * @param cwd - Current working directory for environment scanning\n * @returns The generated AnalysisResult\n */\nexport async function runAnalysis(cwd: string): Promise<AnalysisResult> {\n const summary = await preProcess();\n const snapshot = await scanEnvironment(cwd);\n\n // Wire outcome tracking: track current state, compute summaries for confidence adjustment (QUA-04)\n let outcomeSummaries: OutcomeSummary[] | undefined;\n try {\n await trackOutcomes(snapshot);\n const history = await loadOutcomeHistory();\n outcomeSummaries = computeOutcomeSummaries(history);\n } catch {\n // Outcome tracking failure must not block analysis\n }\n\n const result = analyze(summary, snapshot, undefined, outcomeSummaries);\n await writeAnalysisResult(result);\n return result;\n}\n\n/**\n * Reset the counter with a last_analysis timestamp atomically.\n * Uses proper-lockfile for cross-process safety.\n */\nasync function resetCounterWithTimestamp(): Promise<void> {\n // Ensure counter file exists before locking\n try {\n await readFile(paths.counter, 'utf-8');\n } catch {\n const initial = {\n total: 0,\n session: {},\n last_updated: new Date().toISOString(),\n };\n await writeFileAtomic(paths.counter, JSON.stringify(initial, null, 2));\n }\n\n const release = await lock(paths.counter, {\n retries: { retries: 50, minTimeout: 20, maxTimeout: 1000, randomize: true },\n stale: 10000,\n });\n\n try {\n const now = new Date().toISOString();\n const data = {\n total: 0,\n session: {},\n last_analysis: now,\n last_updated: now,\n };\n await writeFileAtomic(paths.counter, JSON.stringify(data, null, 2));\n } finally {\n await release();\n }\n}\n\n/**\n * Check if analysis should be triggered and run it if conditions are met.\n *\n * Conditions:\n * 1. analysis.enabled is true in config\n * 2. counter.total >= config.analysis.threshold\n * 3. Not within cooldown period since last_analysis\n *\n * On success: resets counter and records last_analysis timestamp.\n * On failure: preserves counter data for retry at next check.\n *\n * @param cwd - Current working directory\n * @returns true if analysis was triggered, false otherwise\n */\nexport async function checkAndTriggerAnalysis(\n cwd: string,\n): Promise<boolean> {\n const config = await loadConfig();\n if (!config.analysis.enabled) return false;\n\n const counter = await readCounter();\n if (counter.total < config.analysis.threshold) return false;\n\n // Check cooldown\n if (counter.last_analysis) {\n const elapsed = Date.now() - new Date(counter.last_analysis).getTime();\n if (elapsed < COOLDOWN_MS) return false;\n }\n\n // Attempt analysis -- preserve counter on failure\n try {\n await runAnalysis(cwd);\n } catch {\n return false;\n }\n\n // Reset counter with timestamp after successful analysis\n await resetCounterWithTimestamp();\n return true;\n}\n","// Stop hook handler: triggers analysis when interaction counter reaches threshold.\n// Invoked by Claude Code after each response completes.\n// Reads JSON from stdin, validates, checks threshold, runs analysis if needed.\n\nimport { stopInputSchema } from '../schemas/hook-input.js';\nimport { checkAndTriggerAnalysis } from '../analysis/trigger.js';\nimport { readStdin } from './shared.js';\n\n/**\n * Core handler logic, exported for testability.\n * Validates input, guards against infinite loops, triggers analysis.\n * Swallows all errors to never block Claude Code.\n */\nexport async function handleStop(rawJson: string): Promise<void> {\n try {\n const input = stopInputSchema.parse(JSON.parse(rawJson));\n\n // Prevent infinite loop: if this hook invocation was triggered\n // by a Stop hook agent, do not re-trigger analysis\n if (input.stop_hook_active) return;\n\n await checkAndTriggerAnalysis(input.cwd);\n } catch {\n // Never block Claude Code\n }\n}\n\n// Entry point when invoked by Claude Code as a command hook\nasync function main(): Promise<void> {\n try {\n const raw = await readStdin();\n await handleStop(raw);\n } catch {\n // Never block Claude Code\n }\n process.exit(0);\n}\n\nmain();\n","// Secret detection regex patterns with [REDACTED:type] markers.\n// Based on top-15 patterns from secrets-patterns-db research.\n// 14 regex patterns included; high-entropy detection (pattern 15)\n// is deferred to config.scrubbing.highEntropyDetection enablement.\n\nexport interface ScrubPattern {\n name: string;\n regex: RegExp;\n replacement: string;\n}\n\nexport const SCRUB_PATTERNS: ScrubPattern[] = [\n {\n name: 'aws_key',\n regex: /AKIA[0-9A-Z]{16}/g,\n replacement: '[REDACTED:aws_key]',\n },\n {\n name: 'aws_secret',\n regex: /(?:aws_secret_access_key|AWS_SECRET_ACCESS_KEY)[\\s=:]+[A-Za-z0-9/+=]{40}/g,\n replacement: '[REDACTED:aws_secret]',\n },\n {\n name: 'github_token',\n regex: /gh[ps]_[A-Za-z0-9_]{36,}/g,\n replacement: '[REDACTED:github_token]',\n },\n {\n name: 'github_oauth',\n regex: /gho_[A-Za-z0-9_]{36,}/g,\n replacement: '[REDACTED:github_oauth]',\n },\n {\n name: 'bearer_token',\n regex: /[Bb]earer\\s+[A-Za-z0-9\\-._~+/]+=*/g,\n replacement: '[REDACTED:bearer_token]',\n },\n {\n name: 'jwt',\n regex: /eyJ[A-Za-z0-9\\-_]+\\.eyJ[A-Za-z0-9\\-_]+\\.[A-Za-z0-9\\-_]+/g,\n replacement: '[REDACTED:jwt]',\n },\n {\n name: 'api_key',\n regex: /(?:api[_-]?key|apikey)[\\s=:]+['\"]?[A-Za-z0-9\\-._]{20,}['\"]?/gi,\n replacement: '[REDACTED:api_key]',\n },\n {\n name: 'secret',\n regex: /(?:secret|SECRET)[\\s=:]+['\"]?[A-Za-z0-9\\-._]{20,}['\"]?/g,\n replacement: '[REDACTED:secret]',\n },\n {\n name: 'private_key',\n regex: /-----BEGIN (?:RSA |EC |OPENSSH |DSA )?PRIVATE KEY-----/g,\n replacement: '[REDACTED:private_key]',\n },\n {\n name: 'password',\n regex: /(?:password|passwd|pwd)[\\s=:]+['\"]?[^\\s'\"]{8,}['\"]?/gi,\n replacement: '[REDACTED:password]',\n },\n {\n name: 'slack_token',\n regex: /xox[bpors]-[A-Za-z0-9-]{10,}/g,\n replacement: '[REDACTED:slack_token]',\n },\n {\n name: 'google_api_key',\n regex: /AIza[0-9A-Za-z\\-_]{35}/g,\n replacement: '[REDACTED:google_api_key]',\n },\n {\n name: 'stripe_key',\n regex: /[sr]k_(?:test|live)_[A-Za-z0-9]{20,}/g,\n replacement: '[REDACTED:stripe_key]',\n },\n {\n name: 'db_url',\n regex: /(?:postgres|mysql|mongodb):\\/\\/[^\\s]+:[^\\s]+@[^\\s]+/g,\n replacement: '[REDACTED:db_url]',\n },\n // Pattern 15: High-entropy string detection is intentionally omitted.\n // It requires Shannon entropy calculation and is deferred to when\n // config.scrubbing.highEntropyDetection is enabled.\n];\n","// String and object scrubbing functions.\n// Applies regex-based secret detection patterns to replace\n// sensitive values with [REDACTED:type] markers (D-01, D-02).\n\nimport { SCRUB_PATTERNS, type ScrubPattern } from './patterns.js';\n\n/**\n * Scrub secrets from a string using built-in patterns\n * plus optional extra patterns (e.g., user-defined custom patterns).\n */\nexport function scrubString(input: string, extraPatterns?: ScrubPattern[]): string {\n let result = input;\n const patterns = extraPatterns\n ? [...SCRUB_PATTERNS, ...extraPatterns]\n : SCRUB_PATTERNS;\n for (const pattern of patterns) {\n // Reset regex lastIndex for global patterns to ensure\n // correct matching when regex objects are reused across calls\n pattern.regex.lastIndex = 0;\n result = result.replace(pattern.regex, pattern.replacement);\n }\n return result;\n}\n\n/**\n * Recursively scrub all string values in an object/array structure.\n * Non-string primitives (numbers, booleans, null, undefined) pass through unchanged.\n */\nexport function scrubObject<T>(obj: T, extraPatterns?: ScrubPattern[]): T {\n if (typeof obj === 'string') {\n return scrubString(obj, extraPatterns) as T;\n }\n if (Array.isArray(obj)) {\n return obj.map(item => scrubObject(item, extraPatterns)) as T;\n }\n if (obj !== null && typeof obj === 'object') {\n const result: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(obj)) {\n result[key] = scrubObject(value, extraPatterns);\n }\n return result as T;\n }\n return obj; // numbers, booleans, null, undefined pass through\n}\n","// JSONL logger with scrub-before-write pipeline and daily rotation.\n// Pipeline: raw data -> validate schema -> scrub strings -> append JSONL\n// Implements D-01 (scrub on write), D-03 (separate dirs), D-04 (daily rotation).\n\nimport { appendFile } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { z } from 'zod/v4';\nimport {\n promptEntrySchema,\n toolEntrySchema,\n permissionEntrySchema,\n sessionEntrySchema,\n} from '../schemas/log-entry.js';\nimport { scrubObject } from '../scrubber/scrub.js';\nimport { paths, ensureInit } from './dirs.js';\n\n// Schema map (schemas are static, safe to capture at module level)\nconst SCHEMA_MAP = {\n prompts: promptEntrySchema,\n tools: toolEntrySchema,\n permissions: permissionEntrySchema,\n sessions: sessionEntrySchema,\n} as const;\n\nexport type LogType = keyof typeof SCHEMA_MAP;\n\n// Resolve directory path at call time (not module load) to support testing\nfunction getLogDir(type: LogType): string {\n return paths.logs[type];\n}\n\nfunction getLogFilePath(type: LogType, date?: Date): string {\n const dateStr = (date ?? new Date()).toISOString().slice(0, 10); // YYYY-MM-DD per D-04\n return join(getLogDir(type), `${dateStr}.jsonl`);\n}\n\n/**\n * Validate, scrub, and append a log entry as a JSONL line.\n *\n * Uses native fs.appendFile (NOT write-file-atomic) because:\n * - JSONL is append-only, not replace\n * - appendFile is atomic for writes <4KB on POSIX\n * - write-file-atomic replaces entire file (anti-pattern for appends)\n */\nexport async function appendLogEntry(type: LogType, rawEntry: unknown): Promise<void> {\n await ensureInit();\n const schema = SCHEMA_MAP[type];\n const validated = (schema as z.ZodType).parse(rawEntry);\n const scrubbed = scrubObject(validated); // D-01: scrub before write\n const line = JSON.stringify(scrubbed) + '\\n';\n const filePath = getLogFilePath(type);\n await appendFile(filePath, line, 'utf-8');\n}\n","// Markdown renderer for analysis results.\n// Produces structured recommendations grouped by confidence tier\n// with status prefixes, evidence, and suggested actions.\n\nimport type { AnalysisResult } from '../schemas/recommendation.js';\nimport type { RecommendationStatus } from '../schemas/delivery.js';\n\nconst TIER_ORDER: readonly string[] = ['HIGH', 'MEDIUM', 'LOW'] as const;\n\n/**\n * Render an AnalysisResult to a markdown string grouped by confidence tier.\n * Status prefixes (PENDING/APPLIED/DISMISSED) are looked up from the states map.\n */\nexport function renderRecommendations(\n result: AnalysisResult,\n states: Map<string, RecommendationStatus>,\n): string {\n const lines: string[] = [];\n\n // Header\n lines.push('# harness-evolve Recommendations');\n lines.push('');\n lines.push(`*Generated: ${result.generated_at}*`);\n lines.push(\n `*Period: ${result.summary_period.since} to ${result.summary_period.until} (${result.summary_period.days} days)*`,\n );\n lines.push('');\n\n // Empty case\n if (result.recommendations.length === 0) {\n lines.push('No recommendations at this time.');\n lines.push('');\n lines.push('---');\n lines.push('*Run /evolve to refresh or manage recommendations.*');\n return lines.join('\\n');\n }\n\n // Group by confidence tier\n for (const tier of TIER_ORDER) {\n const tierRecs = result.recommendations.filter(\n (r) => r.confidence === tier,\n );\n if (tierRecs.length === 0) continue;\n\n lines.push(`## ${tier} Confidence`);\n lines.push('');\n\n for (const rec of tierRecs) {\n const status = (states.get(rec.id) ?? 'pending').toUpperCase();\n\n lines.push(`### [${status}] ${rec.title}`);\n lines.push('');\n lines.push(`**Target:** ${rec.target} | **Pattern:** ${rec.pattern_type}`);\n\n // Evidence line\n const evidenceParts = [`${rec.evidence.count} occurrences`];\n if (rec.evidence.sessions !== undefined) {\n evidenceParts.push(`across ${rec.evidence.sessions} sessions`);\n }\n lines.push(`**Evidence:** ${evidenceParts.join(' ')}`);\n lines.push('');\n\n // Description\n lines.push(rec.description);\n lines.push('');\n\n // Evidence examples\n if (rec.evidence.examples.length > 0) {\n lines.push('**Examples:**');\n for (const ex of rec.evidence.examples) {\n lines.push(`- \\`${ex}\\``);\n }\n lines.push('');\n }\n\n // Suggested action\n lines.push(`**Suggested action:** ${rec.suggested_action}`);\n lines.push('');\n\n // Ecosystem context (optional)\n if (rec.ecosystem_context !== undefined) {\n lines.push(`**Ecosystem note:** ${rec.ecosystem_context}`);\n lines.push('');\n }\n }\n }\n\n // Footer\n lines.push('---');\n lines.push('*Run /evolve to refresh or manage recommendations.*');\n\n return lines.join('\\n');\n}\n","// Recommendation rotator for bounding the state file size.\n// Archives applied/dismissed entries older than archiveAfterDays\n// to dated JSON files in the archive directory.\n\nimport { mkdir } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport writeFileAtomic from 'write-file-atomic';\nimport { paths } from '../storage/dirs.js';\nimport { loadState, saveState } from './state.js';\n\ninterface RotatorConfig {\n maxRecommendationsInFile: number;\n archiveAfterDays: number;\n}\n\n/**\n * Rotate old applied/dismissed recommendations to archive files.\n * Pending entries are never archived regardless of age.\n */\nexport async function rotateRecommendations(\n config: RotatorConfig,\n): Promise<void> {\n const state = await loadState();\n const cutoff = new Date(Date.now() - config.archiveAfterDays * 86400_000);\n\n const toArchive = state.entries.filter(\n (e) =>\n (e.status === 'applied' || e.status === 'dismissed') &&\n new Date(e.updated_at) < cutoff,\n );\n\n if (toArchive.length === 0) {\n return;\n }\n\n const toKeep = state.entries.filter(\n (e) => !toArchive.some((a) => a.id === e.id),\n );\n\n // Write archive file with today's date\n const today = new Date().toISOString().slice(0, 10); // YYYY-MM-DD\n const archivePath = join(paths.recommendationArchive, `${today}.json`);\n await mkdir(paths.recommendationArchive, { recursive: true });\n await writeFileAtomic(archivePath, JSON.stringify(toArchive, null, 2));\n\n // Update state with only kept entries\n await saveState({\n entries: toKeep,\n last_updated: new Date().toISOString(),\n });\n}\n","// Notification module for harness-evolve delivery.\n// Builds one-line notification messages and manages the notification flag file\n// that signals pending recommendations to the UserPromptSubmit hook.\n\nimport { existsSync } from 'node:fs';\nimport { readFile, unlink, writeFile } from 'node:fs/promises';\nimport { paths } from '../storage/dirs.js';\n\n/**\n * Build a one-line notification string referencing /evolve:apply.\n * Output is always under 200 characters (well under 200 tokens).\n */\nexport function buildNotification(pendingCount: number): string {\n const plural = pendingCount === 1 ? '' : 's';\n return `[harness-evolve] ${pendingCount} new suggestion${plural} found. Run /evolve:apply to review.`;\n}\n\n/**\n * Write the notification flag file with the pending recommendation count.\n * The UserPromptSubmit hook reads this flag to decide whether to inject a notification.\n */\nexport async function writeNotificationFlag(pendingCount: number): Promise<void> {\n await writeFile(paths.notificationFlag, String(pendingCount), 'utf-8');\n}\n\n/**\n * Check whether a notification flag file exists.\n */\nexport async function hasNotificationFlag(): Promise<boolean> {\n return existsSync(paths.notificationFlag);\n}\n\n/**\n * Remove the notification flag file.\n * Does not throw when the flag file does not exist.\n */\nexport async function clearNotificationFlag(): Promise<void> {\n try {\n await unlink(paths.notificationFlag);\n } catch {\n // Flag already cleared or never existed\n }\n}\n\n/**\n * Read the pending count from the notification flag file.\n * Returns 0 if the file cannot be read or parsed.\n */\nexport async function readNotificationFlagCount(): Promise<number> {\n try {\n const content = await readFile(paths.notificationFlag, 'utf-8');\n return parseInt(content.trim(), 10) || 0;\n } catch {\n return 0;\n }\n}\n","// Auto-apply module for high-confidence recommendations.\n// When fullAuto mode is enabled (config.delivery.fullAuto=true), this module\n// automatically applies HIGH-confidence recommendations that have a registered\n// applier. Dispatches to the correct applier via the strategy pattern registry.\n// v1 appliers: SettingsApplier (permission-always-approved), RuleApplier (create-only rules).\n// v2 appliers: HookApplier (hook script generation + settings registration), ClaudeMdApplier (CLAUDE.md append).\n\nimport { appendFile } from 'node:fs/promises';\nimport { paths, ensureInit } from '../storage/dirs.js';\nimport { loadConfig } from '../storage/config.js';\nimport { updateStatus, getStatusMap } from './state.js';\nimport {\n registerApplier,\n getApplier,\n hasApplier,\n} from './appliers/index.js';\nimport { SettingsApplier } from './appliers/settings-applier.js';\nimport { RuleApplier } from './appliers/rule-applier.js';\nimport { HookApplier } from './appliers/hook-applier.js';\nimport { ClaudeMdApplier } from './appliers/claude-md-applier.js';\nimport type { Recommendation } from '../schemas/recommendation.js';\nimport type { AutoApplyLogEntry } from '../schemas/delivery.js';\nimport type { ApplierOptions } from './appliers/index.js';\n\nexport interface AutoApplyResult {\n recommendation_id: string;\n success: boolean;\n details: string;\n}\n\nexport interface AutoApplyOptions extends ApplierOptions {}\n\n// Register all built-in appliers\nregisterApplier(new SettingsApplier());\nregisterApplier(new RuleApplier());\nregisterApplier(new HookApplier());\nregisterApplier(new ClaudeMdApplier());\n\n/**\n * Auto-apply HIGH-confidence recommendations when fullAuto is enabled.\n * Returns an empty array when fullAuto is false (default, per QUA-01).\n *\n * Dispatches to the appropriate Applier based on rec.target via the\n * applier registry. Only processes recommendations whose target has a\n * registered applier and whose applier.canApply() returns true.\n */\nexport async function autoApplyRecommendations(\n recommendations: Recommendation[],\n options?: AutoApplyOptions,\n): Promise<AutoApplyResult[]> {\n const config = await loadConfig();\n if (!config.delivery.fullAuto) return [];\n\n await ensureInit();\n const stateMap = await getStatusMap();\n const results: AutoApplyResult[] = [];\n\n // Filter: only HIGH confidence + has registered applier + pending status\n const candidates = recommendations.filter(\n (rec) =>\n rec.confidence === 'HIGH' &&\n hasApplier(rec.target) &&\n (stateMap.get(rec.id) ?? 'pending') === 'pending',\n );\n\n for (const rec of candidates) {\n const applier = getApplier(rec.target);\n let result: AutoApplyResult;\n\n if (!applier || !applier.canApply(rec)) {\n result = {\n recommendation_id: rec.id,\n success: false,\n details: `No applicable applier for target '${rec.target}' with pattern_type '${rec.pattern_type}'`,\n };\n } else {\n result = await applier.apply(rec, options);\n }\n\n results.push(result);\n\n // Log the attempt\n const logEntry: AutoApplyLogEntry = {\n timestamp: new Date().toISOString(),\n recommendation_id: rec.id,\n target: rec.target,\n action: rec.suggested_action,\n success: result.success,\n details: result.details,\n backup_path: undefined,\n };\n await appendFile(\n paths.autoApplyLog,\n JSON.stringify(logEntry) + '\\n',\n 'utf-8',\n );\n\n // Update status on success\n if (result.success) {\n await updateStatus(rec.id, 'applied', `Auto-applied: ${result.details}`);\n }\n }\n\n return results;\n}\n","// Applier interface, options, and registry for auto-apply dispatch.\n// The registry maps routing targets (e.g. 'SETTINGS', 'RULE') to their\n// corresponding Applier implementations. Adding a new applier requires\n// only implementing the Applier interface and calling registerApplier().\n\nimport type { Recommendation } from '../../schemas/recommendation.js';\nimport type { AutoApplyResult } from '../auto-apply.js';\n\nexport interface ApplierOptions {\n /** Override settings.json path (used in testing) */\n settingsPath?: string;\n /** Override rules directory (used in testing) */\n rulesDir?: string;\n /** Override hooks directory (used in testing) */\n hooksDir?: string;\n /** Override CLAUDE.md path (used in testing) */\n claudeMdPath?: string;\n}\n\nexport interface Applier {\n readonly target: string;\n canApply(rec: Recommendation): boolean;\n apply(rec: Recommendation, options?: ApplierOptions): Promise<AutoApplyResult>;\n}\n\nconst registry = new Map<string, Applier>();\n\nexport function registerApplier(applier: Applier): void {\n registry.set(applier.target, applier);\n}\n\nexport function getApplier(target: string): Applier | undefined {\n return registry.get(target);\n}\n\nexport function hasApplier(target: string): boolean {\n return registry.has(target);\n}\n","// SettingsApplier: handles auto-apply for SETTINGS/permission-always-approved.\n// Extracted from auto-apply.ts — adds tools to allowedTools in settings.json\n// with atomic writes and backup creation before modification.\n\nimport { readFile, copyFile, mkdir } from 'node:fs/promises';\nimport { join, dirname } from 'node:path';\nimport writeFileAtomic from 'write-file-atomic';\nimport type { Applier, ApplierOptions } from './index.js';\nimport type { Recommendation } from '../../schemas/recommendation.js';\nimport type { AutoApplyResult } from '../auto-apply.js';\nimport { paths } from '../../storage/dirs.js';\n\nexport class SettingsApplier implements Applier {\n readonly target = 'SETTINGS';\n\n canApply(rec: Recommendation): boolean {\n return (\n rec.confidence === 'HIGH' &&\n rec.target === 'SETTINGS' &&\n rec.pattern_type === 'permission-always-approved'\n );\n }\n\n async apply(\n rec: Recommendation,\n options?: ApplierOptions,\n ): Promise<AutoApplyResult> {\n try {\n // v1 scope: only handle permission-always-approved pattern\n if (rec.pattern_type !== 'permission-always-approved') {\n return {\n recommendation_id: rec.id,\n success: false,\n details: `Skipped: pattern_type '${rec.pattern_type}' not supported for auto-apply in v1`,\n };\n }\n\n const settingsFilePath =\n options?.settingsPath ??\n join(process.env.HOME ?? '', '.claude', 'settings.json');\n\n // Read current settings\n const raw = await readFile(settingsFilePath, 'utf-8');\n const settings = JSON.parse(raw) as Record<string, unknown>;\n\n // Create backup before modification\n const backup = join(\n paths.analysis,\n 'backups',\n `settings-backup-${rec.id}.json`,\n );\n await mkdir(dirname(backup), { recursive: true });\n await copyFile(settingsFilePath, backup);\n\n // Extract tool name from evidence\n const toolName = extractToolName(rec);\n if (!toolName) {\n return {\n recommendation_id: rec.id,\n success: false,\n details:\n 'Could not extract tool name from recommendation evidence',\n };\n }\n\n // Get or create allowedTools array\n const allowedTools = Array.isArray(settings.allowedTools)\n ? (settings.allowedTools as string[])\n : [];\n\n // Add tool if not already present\n if (!allowedTools.includes(toolName)) {\n allowedTools.push(toolName);\n }\n settings.allowedTools = allowedTools;\n\n // Write modified settings atomically\n await writeFileAtomic(\n settingsFilePath,\n JSON.stringify(settings, null, 2),\n );\n\n return {\n recommendation_id: rec.id,\n success: true,\n details: `Added ${toolName} to allowedTools`,\n };\n } catch (err: unknown) {\n const message = err instanceof Error ? err.message : String(err);\n return {\n recommendation_id: rec.id,\n success: false,\n details: message,\n };\n }\n }\n}\n\n/**\n * Extract tool name from recommendation evidence examples.\n * Looks for patterns like \"Bash(npm test)\" -> \"Bash\"\n * or \"ToolName(args)\" -> \"ToolName\".\n */\nfunction extractToolName(rec: Recommendation): string | undefined {\n for (const example of rec.evidence.examples) {\n const match = example.match(/^(\\w+)\\(/);\n if (match) return match[1];\n }\n return undefined;\n}\n","// RuleApplier: handles auto-apply for HIGH-confidence RULE recommendations.\n// Creates .claude/rules/evolve-{pattern_type}.md files with the recommendation\n// title, description, and suggested action. Create-only: never overwrites\n// existing rule files to respect user customizations (Pitfall 18).\n\nimport { writeFile, access, mkdir } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport type { Applier, ApplierOptions } from './index.js';\nimport type { Recommendation } from '../../schemas/recommendation.js';\nimport type { AutoApplyResult } from '../auto-apply.js';\n\nexport class RuleApplier implements Applier {\n readonly target = 'RULE';\n\n canApply(rec: Recommendation): boolean {\n return rec.confidence === 'HIGH' && rec.target === 'RULE';\n }\n\n async apply(\n rec: Recommendation,\n options?: ApplierOptions,\n ): Promise<AutoApplyResult> {\n const rulesDir =\n options?.rulesDir ??\n join(process.env.HOME ?? '', '.claude', 'rules');\n const fileName = `evolve-${rec.pattern_type}.md`;\n const filePath = join(rulesDir, fileName);\n\n // Create-only guard: never overwrite existing files (Pitfall 18)\n try {\n await access(filePath);\n return {\n recommendation_id: rec.id,\n success: false,\n details: `Rule file already exists: ${fileName}`,\n };\n } catch {\n // File does not exist — proceed to create\n }\n\n try {\n await mkdir(rulesDir, { recursive: true });\n\n const content = [\n `# ${rec.title}`,\n '',\n rec.description,\n '',\n '## Action',\n '',\n rec.suggested_action,\n '',\n '---',\n `*Auto-generated by harness-evolve (${rec.id})*`,\n ].join('\\n');\n\n await writeFile(filePath, content, 'utf-8');\n\n return {\n recommendation_id: rec.id,\n success: true,\n details: `Created rule file: ${fileName}`,\n };\n } catch (err: unknown) {\n const message = err instanceof Error ? err.message : String(err);\n return {\n recommendation_id: rec.id,\n success: false,\n details: message,\n };\n }\n }\n}\n","// HookApplier: handles auto-apply for HIGH-confidence HOOK recommendations.\n// Generates a bash hook script via generateHook(), writes it to disk with +x\n// permission, and registers the hook in settings.json via mergeHooks().\n// Create-only: never overwrites existing hook files.\n\nimport { writeFile, access, mkdir, chmod, copyFile } from 'node:fs/promises';\nimport { join, basename, dirname } from 'node:path';\nimport type { Applier, ApplierOptions } from './index.js';\nimport type { Recommendation } from '../../schemas/recommendation.js';\nimport type { AutoApplyResult } from '../auto-apply.js';\nimport { generateHook } from '../../generators/hook-generator.js';\nimport {\n readSettings,\n writeSettings,\n mergeHooks,\n} from '../../cli/utils.js';\nimport { paths } from '../../storage/dirs.js';\n\nexport class HookApplier implements Applier {\n readonly target = 'HOOK';\n\n canApply(rec: Recommendation): boolean {\n return rec.confidence === 'HIGH' && rec.target === 'HOOK';\n }\n\n async apply(\n rec: Recommendation,\n options?: ApplierOptions,\n ): Promise<AutoApplyResult> {\n try {\n // Generate hook script from recommendation\n const artifact = generateHook(rec);\n if (!artifact) {\n return {\n recommendation_id: rec.id,\n success: false,\n details: 'Generator returned null — recommendation not applicable for hook generation',\n };\n }\n\n // Resolve hooks directory\n const hooksDir =\n options?.hooksDir ??\n join(process.env.HOME ?? '', '.claude', 'hooks');\n\n // Extract script filename from artifact path\n const scriptFilename = basename(artifact.filename);\n const scriptPath = join(hooksDir, scriptFilename);\n\n // Create-only guard: never overwrite existing hook files\n try {\n await access(scriptPath);\n return {\n recommendation_id: rec.id,\n success: false,\n details: `Hook file already exists: ${scriptFilename}`,\n };\n } catch {\n // File does not exist — proceed to create\n }\n\n // Create hooks directory\n await mkdir(hooksDir, { recursive: true });\n\n // Write hook script file\n await writeFile(scriptPath, artifact.content, 'utf-8');\n\n // Set executable permission\n await chmod(scriptPath, 0o755);\n\n // Resolve settings.json path\n const settingsPath =\n options?.settingsPath ??\n join(process.env.HOME ?? '', '.claude', 'settings.json');\n\n // Read current settings\n const settings = await readSettings(settingsPath);\n\n // Create backup before modification\n const backupDir = join(paths.analysis, 'backups');\n await mkdir(backupDir, { recursive: true });\n const backupFile = join(backupDir, `settings-backup-${rec.id}.json`);\n // Only backup if settings file exists and has content\n try {\n await copyFile(settingsPath, backupFile);\n } catch {\n // Settings file may not exist yet — write current state as backup\n await writeFile(backupFile, JSON.stringify(settings, null, 2), 'utf-8');\n }\n\n // Extract hook event from generated content\n const eventMatch = artifact.content.match(/# Hook event: (\\w+)/);\n const hookEvent = eventMatch?.[1] ?? 'PreToolUse';\n\n // Merge hook into settings\n const merged = mergeHooks(settings, [\n {\n event: hookEvent,\n command: `bash \"${scriptPath}\"`,\n timeout: 10,\n async: true,\n },\n ]);\n\n // Write merged settings\n await writeSettings(merged, settingsPath);\n\n return {\n recommendation_id: rec.id,\n success: true,\n details: `Created hook script: ${scriptFilename} and registered under ${hookEvent}`,\n };\n } catch (err: unknown) {\n const message = err instanceof Error ? err.message : String(err);\n return {\n recommendation_id: rec.id,\n success: false,\n details: message,\n };\n }\n }\n}\n","// Generator module schemas and shared utilities.\n// Defines the GeneratedArtifact output contract for all generators,\n// plus helper functions (toSlug, escapeYaml) used across generator implementations.\n\nimport { z } from 'zod/v4';\n\n// Version stamp embedded in every generated artifact\nexport const GENERATOR_VERSION = '1.0.0';\n\n// Return current time as ISO 8601 string\nexport function nowISO(): string {\n return new Date().toISOString();\n}\n\n/**\n * Convert text to a URL/filename-safe slug.\n * Lowercases, replaces non-alphanumeric with hyphens,\n * collapses consecutive hyphens, strips leading/trailing hyphens,\n * and caps at 50 characters.\n */\nexport function toSlug(text: string): string {\n if (!text) return '';\n return text\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, '-')\n .replace(/-+/g, '-')\n .replace(/^-|-$/g, '')\n .slice(0, 50);\n}\n\n// Characters that require quoting in YAML values\nconst YAML_SPECIAL = /[:\"'{}[\\]#&*!|>\\\\,\\n]/;\n\n/**\n * Escape a string for safe inclusion as a YAML frontmatter value.\n * Wraps in double quotes and escapes internal double quotes\n * when the text contains YAML-special characters.\n */\nexport function escapeYaml(text: string): string {\n if (!YAML_SPECIAL.test(text)) return text;\n return `\"${text.replace(/\"/g, '\\\\\"')}\"`;\n}\n\nexport const generatedArtifactSchema = z.object({\n type: z.enum(['skill', 'hook', 'claude_md_patch']),\n filename: z.string(),\n content: z.string(),\n source_recommendation_id: z.string(),\n metadata: z.object({\n generated_at: z.iso.datetime(),\n generator_version: z.string(),\n pattern_type: z.string(),\n }),\n});\nexport type GeneratedArtifact = z.infer<typeof generatedArtifactSchema>;\n\nexport interface GeneratorOptions {\n projectRoot?: string;\n}\n","// Hook generator: converts HOOK-targeted recommendations into bash hook\n// script drafts. Handles both scan_missing_mechanization and repeated_prompt\n// pattern types. Pure function -- no filesystem access, no side effects.\n// Returns null for non-applicable recommendations.\n\nimport type { Recommendation } from '../schemas/recommendation.js';\nimport type { GeneratedArtifact } from './schemas.js';\nimport { toSlug, GENERATOR_VERSION, nowISO } from './schemas.js';\n\n/**\n * Extract the hook event name from a recommendation's description\n * or suggested_action field.\n *\n * Tries these patterns in order:\n * 1. \"suitable for a <HookEvent> hook\" in description\n * 2. \"Create a <HookEvent> hook\" in suggested_action\n * 3. Falls back to 'PreToolUse' if no match\n */\nfunction extractHookEvent(rec: Recommendation): string {\n const descMatch = rec.description.match(/suitable for a (\\w+) hook/i);\n if (descMatch) return descMatch[1];\n\n const actionMatch = rec.suggested_action.match(/Create a (\\w+) hook/i);\n if (actionMatch) return actionMatch[1];\n\n return 'PreToolUse';\n}\n\n/**\n * Generate a bash hook script draft from a HOOK-targeted recommendation.\n *\n * @param rec - A Recommendation object (from mechanization scanner or repeated-prompts classifier)\n * @returns GeneratedArtifact with type 'hook', or null if the recommendation\n * is not applicable (wrong target)\n */\nexport function generateHook(rec: Recommendation): GeneratedArtifact | null {\n if (rec.target !== 'HOOK') return null;\n\n const hookEvent = extractHookEvent(rec);\n const slugName = toSlug(rec.title);\n\n const content = [\n '#!/usr/bin/env bash',\n `# Auto-generated hook for: ${rec.title}`,\n `# Hook event: ${hookEvent}`,\n `# Source: harness-evolve (${rec.id})`,\n '#',\n '# TODO: Review and customize this script before use.',\n '',\n '# Read hook input from stdin',\n 'INPUT=$(cat)',\n '',\n '# Extract relevant fields',\n `# Adjust jq path based on your ${hookEvent} event schema`,\n '',\n `# ${rec.suggested_action}`,\n '',\n '# Exit 0 to allow, exit 2 to block',\n 'exit 0',\n ].join('\\n');\n\n return {\n type: 'hook',\n filename: `.claude/hooks/evolve-${slugName}.sh`,\n content,\n source_recommendation_id: rec.id,\n metadata: {\n generated_at: nowISO(),\n generator_version: GENERATOR_VERSION,\n pattern_type: rec.pattern_type,\n },\n };\n}\n","// Shared CLI utilities: hook definitions, settings I/O, path resolution, confirm prompt\n\nimport { readFile } from 'node:fs/promises';\nimport { dirname, join } from 'node:path';\nimport { createInterface } from 'node:readline/promises';\nimport writeFileAtomic from 'write-file-atomic';\n\n/**\n * Marker string used to identify harness-evolve hook entries in settings.json.\n * When scanning existing hooks, any command containing this string is ours.\n */\nexport const HARNESS_EVOLVE_MARKER = 'harness-evolve';\n\n/**\n * Default path to Claude Code user-scope settings.json.\n */\nexport const SETTINGS_PATH = join(\n process.env.HOME ?? '',\n '.claude',\n 'settings.json',\n);\n\n/**\n * Hook registration definition.\n */\nexport interface HookRegistration {\n event: string;\n hookFile: string;\n timeout: number;\n async: boolean;\n description: string;\n}\n\n/**\n * All 6 hook events that harness-evolve registers.\n * Each entry maps an event name to the compiled JS hook file.\n */\nexport const HOOK_REGISTRATIONS: HookRegistration[] = [\n {\n event: 'UserPromptSubmit',\n hookFile: 'user-prompt-submit.js',\n timeout: 10,\n async: false,\n description: 'Captures prompts and delivers optimization notifications',\n },\n {\n event: 'PreToolUse',\n hookFile: 'pre-tool-use.js',\n timeout: 10,\n async: true,\n description: 'Tracks tool usage patterns before execution',\n },\n {\n event: 'PostToolUse',\n hookFile: 'post-tool-use.js',\n timeout: 10,\n async: true,\n description: 'Records tool outcomes for pattern analysis',\n },\n {\n event: 'PostToolUseFailure',\n hookFile: 'post-tool-use-failure.js',\n timeout: 10,\n async: true,\n description: 'Logs tool failures to detect correction patterns',\n },\n {\n event: 'PermissionRequest',\n hookFile: 'permission-request.js',\n timeout: 10,\n async: true,\n description: 'Monitors permission decisions for auto-approval suggestions',\n },\n {\n event: 'Stop',\n hookFile: 'stop.js',\n timeout: 10,\n async: true,\n description: 'Triggers analysis when interaction threshold is reached',\n },\n];\n\n/**\n * Resolve absolute path to a hook JS file.\n *\n * In production, import.meta.dirname of the compiled dist/cli/utils.js\n * points to <install>/dist/cli/. We go up one level to <install>/dist/,\n * then into hooks/<hookFile>.\n *\n * @param hookFile - The hook filename (e.g., 'user-prompt-submit.js')\n * @param baseDirOverride - Override for import.meta.dirname (for testing)\n */\nexport function resolveHookPath(\n hookFile: string,\n baseDirOverride?: string,\n): string {\n const baseDir = baseDirOverride ?? import.meta.dirname;\n return join(baseDir, 'hooks', hookFile);\n}\n\n/**\n * Read and parse Claude Code settings.json.\n * Returns empty object if file does not exist or JSON is invalid.\n */\nexport async function readSettings(\n settingsPath?: string,\n): Promise<Record<string, unknown>> {\n const filePath = settingsPath ?? SETTINGS_PATH;\n try {\n const raw = await readFile(filePath, 'utf-8');\n return JSON.parse(raw) as Record<string, unknown>;\n } catch {\n // ENOENT (file missing) or SyntaxError (invalid JSON)\n return {};\n }\n}\n\n/**\n * Write settings.json atomically with 2-space indentation.\n */\nexport async function writeSettings(\n settings: Record<string, unknown>,\n settingsPath?: string,\n): Promise<void> {\n const filePath = settingsPath ?? SETTINGS_PATH;\n await writeFileAtomic(filePath, JSON.stringify(settings, null, 2));\n}\n\n/**\n * Hook command entry for merge logic.\n */\ninterface HookCommand {\n event: string;\n command: string;\n timeout: number;\n async: boolean;\n}\n\n/**\n * Merge harness-evolve hooks into existing settings without destroying user hooks.\n *\n * For each hook command:\n * - If the event already has a harness-evolve entry (identified by HARNESS_EVOLVE_MARKER\n * in the command string), skip it.\n * - Otherwise, append a new matcher entry to the event array.\n *\n * User hooks are preserved untouched.\n */\nexport function mergeHooks(\n existing: Record<string, unknown>,\n hookCommands: HookCommand[],\n): Record<string, unknown> {\n const hooks = (\n existing.hooks != null ? { ...(existing.hooks as Record<string, unknown>) } : {}\n ) as Record<string, unknown[]>;\n\n for (const hc of hookCommands) {\n const eventArray = (\n Array.isArray(hooks[hc.event]) ? [...hooks[hc.event]] : []\n ) as Array<Record<string, unknown>>;\n\n // Check if harness-evolve hook already registered for this event\n const alreadyRegistered = eventArray.some((entry) => {\n const innerHooks = entry.hooks as\n | Array<Record<string, unknown>>\n | undefined;\n if (!Array.isArray(innerHooks)) return false;\n return innerHooks.some((h) =>\n String(h.command ?? '').includes(HARNESS_EVOLVE_MARKER),\n );\n });\n\n if (!alreadyRegistered) {\n const hookEntry: Record<string, unknown> = {\n type: 'command',\n command: hc.command,\n timeout: hc.timeout,\n };\n if (hc.async) {\n hookEntry.async = true;\n }\n\n eventArray.push({\n matcher: '*',\n hooks: [hookEntry],\n });\n }\n\n hooks[hc.event] = eventArray;\n }\n\n return { ...existing, hooks };\n}\n\n/**\n * Interactive confirmation prompt.\n * Returns true if user answers 'y' or 'yes' (case-insensitive).\n */\nexport async function confirm(message: string): Promise<boolean> {\n const rl = createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n\n try {\n const answer = await rl.question(`${message} [y/N] `);\n return /^y(es)?$/i.test(answer.trim());\n } finally {\n rl.close();\n }\n}\n","// ClaudeMdApplier: handles auto-apply for HIGH-confidence CLAUDE_MD recommendations.\n// Appends new sections to CLAUDE.md for generic pattern types. Refuses to\n// auto-apply destructive patterns (scan_stale_reference, scan_redundancy) that\n// require manual review. Uses write-file-atomic for safe writes.\n// Creates backup of original CLAUDE.md before modification.\n\nimport { readFile, mkdir } from 'node:fs/promises';\nimport { join, dirname } from 'node:path';\nimport writeFileAtomic from 'write-file-atomic';\nimport type { Applier, ApplierOptions } from './index.js';\nimport type { Recommendation } from '../../schemas/recommendation.js';\nimport type { AutoApplyResult } from '../auto-apply.js';\nimport { paths } from '../../storage/dirs.js';\n\n/** Pattern types that require manual review — no destructive auto-apply. */\nconst DESTRUCTIVE_PATTERNS = new Set([\n 'scan_stale_reference',\n 'scan_redundancy',\n]);\n\nexport class ClaudeMdApplier implements Applier {\n readonly target = 'CLAUDE_MD';\n\n canApply(rec: Recommendation): boolean {\n return rec.confidence === 'HIGH' && rec.target === 'CLAUDE_MD';\n }\n\n async apply(\n rec: Recommendation,\n options?: ApplierOptions,\n ): Promise<AutoApplyResult> {\n try {\n // Pattern-type guard: refuse destructive patterns\n if (DESTRUCTIVE_PATTERNS.has(rec.pattern_type)) {\n return {\n recommendation_id: rec.id,\n success: false,\n details: `Pattern type '${rec.pattern_type}' requires manual review — cannot safely auto-apply`,\n };\n }\n\n // Resolve CLAUDE.md path\n const claudeMdPath =\n options?.claudeMdPath ??\n join(process.cwd(), 'CLAUDE.md');\n\n // Read existing content (empty string if file doesn't exist)\n let existingContent = '';\n try {\n existingContent = await readFile(claudeMdPath, 'utf-8');\n } catch {\n // File does not exist — will be created\n }\n\n // Create backup if content exists\n if (existingContent) {\n const backupDir = join(paths.analysis, 'backups');\n await mkdir(backupDir, { recursive: true });\n const backupFile = join(backupDir, `claudemd-backup-${rec.id}.md`);\n await writeFileAtomic(backupFile, existingContent);\n }\n\n // Build new section to append\n const newSection = [\n '',\n '',\n `## ${rec.title}`,\n '',\n rec.suggested_action,\n '',\n '---',\n `*Auto-generated by harness-evolve (${rec.id})*`,\n '',\n ].join('\\n');\n\n // Append section to existing content\n const updatedContent = existingContent + newSection;\n\n // Ensure parent directory exists\n await mkdir(dirname(claudeMdPath), { recursive: true });\n\n // Write updated content atomically\n await writeFileAtomic(claudeMdPath, updatedContent);\n\n return {\n recommendation_id: rec.id,\n success: true,\n details: `Appended section: ${rec.title}`,\n };\n } catch (err: unknown) {\n const message = err instanceof Error ? err.message : String(err);\n return {\n recommendation_id: rec.id,\n success: false,\n details: message,\n };\n }\n }\n}\n","// Context builder for deep scan module.\n// Reads all Claude Code configuration sources (CLAUDE.md files, rules,\n// settings, commands, hooks) from the filesystem and produces a validated\n// ScanContext object for scanner analysis.\n\nimport { readFile, readdir } from 'node:fs/promises';\nimport { join, basename } from 'node:path';\nimport { scanContextSchema, type ScanContext } from './schemas.js';\n\n/**\n * Safely read a file, returning its content or null if it cannot be read.\n */\nasync function readFileSafe(path: string): Promise<string | null> {\n try {\n return await readFile(path, 'utf-8');\n } catch {\n return null;\n }\n}\n\n/**\n * Extract markdown headings (# through ######) from content.\n */\nexport function extractHeadings(content: string): string[] {\n const headings: string[] = [];\n const regex = /^#{1,6}\\s+(.+)$/gm;\n let match: RegExpExecArray | null;\n while ((match = regex.exec(content)) !== null) {\n headings.push(match[1].trim());\n }\n return headings;\n}\n\n/**\n * Extract @-reference paths from content (e.g., @docs/guide.md).\n * Filters out email-like patterns (user@domain).\n */\nexport function extractReferences(content: string): string[] {\n const refs: string[] = [];\n const regex = /@([\\w./-]+)/g;\n let match: RegExpExecArray | null;\n while ((match = regex.exec(content)) !== null) {\n const ref = match[1];\n // Filter out email-like patterns: if preceded by a word char, skip\n const idx = match.index;\n if (idx > 0 && /\\w/.test(content[idx - 1])) {\n continue;\n }\n // Strip trailing dots only if they don't look like file extensions\n // e.g., \"file.ts.\" -> \"file.ts\", but \"file.md\" stays as-is\n const cleaned = ref.replace(/\\.$/, '');\n refs.push(cleaned);\n }\n return refs;\n}\n\n/**\n * Read CLAUDE.md files from the 3 standard locations.\n */\nasync function readClaudeMdFiles(\n cwd: string,\n home: string,\n): Promise<ScanContext['claude_md_files']> {\n const locations: Array<{ path: string; scope: 'user' | 'project' | 'local' }> = [\n { path: join(cwd, 'CLAUDE.md'), scope: 'project' },\n { path: join(cwd, '.claude', 'CLAUDE.md'), scope: 'local' },\n { path: join(home, '.claude', 'CLAUDE.md'), scope: 'user' },\n ];\n\n const files: ScanContext['claude_md_files'] = [];\n\n for (const loc of locations) {\n const content = await readFileSafe(loc.path);\n if (content !== null) {\n files.push({\n path: loc.path,\n scope: loc.scope,\n content,\n line_count: content.split('\\n').length,\n headings: extractHeadings(content),\n references: extractReferences(content),\n });\n }\n }\n\n return files;\n}\n\n/**\n * Recursively collect all .md files from a directory.\n */\nasync function collectMdFiles(dir: string): Promise<string[]> {\n const results: string[] = [];\n try {\n const entries = await readdir(dir, { withFileTypes: true });\n for (const entry of entries) {\n const fullPath = join(dir, entry.name);\n if (entry.isDirectory()) {\n const nested = await collectMdFiles(fullPath);\n results.push(...nested);\n } else if (entry.isFile() && entry.name.endsWith('.md')) {\n results.push(fullPath);\n }\n }\n } catch {\n // Directory does not exist or is unreadable\n }\n return results;\n}\n\n/**\n * Parse simple YAML frontmatter from markdown content.\n * Looks for --- delimiters and extracts paths array if present.\n */\nfunction parseFrontmatter(\n content: string,\n): { paths?: string[] } | undefined {\n const match = content.match(/^---\\n([\\s\\S]*?)\\n---/);\n if (!match) return undefined;\n\n const frontmatter = match[1];\n const pathsMatch = frontmatter.match(\n /paths:\\s*\\n((?:\\s*-\\s*.+\\n?)*)/,\n );\n if (!pathsMatch) return {};\n\n const paths = pathsMatch[1]\n .split('\\n')\n .map((line) => line.replace(/^\\s*-\\s*/, '').trim())\n .filter((line) => line.length > 0);\n\n return paths.length > 0 ? { paths } : {};\n}\n\n/**\n * Read all rule files from .claude/rules/ recursively.\n */\nasync function readRuleFiles(cwd: string): Promise<ScanContext['rules']> {\n const rulesDir = join(cwd, '.claude', 'rules');\n const mdFiles = await collectMdFiles(rulesDir);\n\n const rules: ScanContext['rules'] = [];\n for (const filePath of mdFiles) {\n const content = await readFileSafe(filePath);\n if (content !== null) {\n rules.push({\n path: filePath,\n filename: basename(filePath),\n content,\n frontmatter: parseFrontmatter(content),\n headings: extractHeadings(content),\n });\n }\n }\n\n return rules;\n}\n\n/**\n * Read settings.json from all 3 scopes (user, project, local).\n */\nasync function readAllSettings(\n cwd: string,\n home: string,\n): Promise<ScanContext['settings']> {\n const settingsPaths = {\n user: join(home, '.claude', 'settings.json'),\n project: join(cwd, '.claude', 'settings.json'),\n local: join(cwd, '.claude', 'settings.local.json'),\n };\n\n const readJsonSafe = async (path: string): Promise<unknown | null> => {\n try {\n const raw = await readFile(path, 'utf-8');\n return JSON.parse(raw) as unknown;\n } catch {\n return null;\n }\n };\n\n const [user, project, local] = await Promise.all([\n readJsonSafe(settingsPaths.user),\n readJsonSafe(settingsPaths.project),\n readJsonSafe(settingsPaths.local),\n ]);\n\n return { user, project, local };\n}\n\n/**\n * Read command files from .claude/commands/ directory.\n */\nasync function readCommandFiles(\n cwd: string,\n): Promise<ScanContext['commands']> {\n const commandsDir = join(cwd, '.claude', 'commands');\n const commands: ScanContext['commands'] = [];\n\n try {\n const entries = await readdir(commandsDir, { withFileTypes: true });\n for (const entry of entries) {\n if (entry.isFile() && entry.name.endsWith('.md')) {\n const filePath = join(commandsDir, entry.name);\n const content = await readFileSafe(filePath);\n if (content !== null) {\n commands.push({\n path: filePath,\n name: entry.name.replace(/\\.md$/, ''),\n content,\n });\n }\n }\n }\n } catch {\n // Directory does not exist\n }\n\n return commands;\n}\n\n/**\n * Extract hook registrations from all settings scopes.\n */\nfunction extractHooksFromAllSettings(\n settings: ScanContext['settings'],\n): ScanContext['hooks_registered'] {\n const hooks: ScanContext['hooks_registered'] = [];\n\n const extractFromScope = (\n settingsObj: unknown,\n scope: 'user' | 'project' | 'local',\n ): void => {\n if (!settingsObj || typeof settingsObj !== 'object') return;\n const obj = settingsObj as Record<string, unknown>;\n if (!obj.hooks || typeof obj.hooks !== 'object') return;\n\n const hooksConfig = obj.hooks as Record<string, unknown>;\n for (const [event, defs] of Object.entries(hooksConfig)) {\n if (!Array.isArray(defs)) continue;\n for (const def of defs) {\n if (!def || typeof def !== 'object') continue;\n const hookDef = def as Record<string, unknown>;\n const type = String(hookDef.type ?? 'command');\n const command =\n typeof hookDef.command === 'string' ? hookDef.command : undefined;\n hooks.push({ event, scope, type, command });\n }\n }\n };\n\n extractFromScope(settings.user, 'user');\n extractFromScope(settings.project, 'project');\n extractFromScope(settings.local, 'local');\n\n return hooks;\n}\n\n/**\n * Build a complete ScanContext by reading all configuration sources.\n * Returns a validated ScanContext or throws if validation fails.\n *\n * @param cwd - Project root directory\n * @param home - User home directory (defaults to process.env.HOME)\n */\nexport async function buildScanContext(\n cwd: string,\n home?: string,\n): Promise<ScanContext> {\n const homeDir = home ?? process.env.HOME ?? '';\n\n const [claudeMdFiles, rules, settings, commands] = await Promise.all([\n readClaudeMdFiles(cwd, homeDir),\n readRuleFiles(cwd),\n readAllSettings(cwd, homeDir),\n readCommandFiles(cwd),\n ]);\n\n const hooksRegistered = extractHooksFromAllSettings(settings);\n\n const ctx = {\n generated_at: new Date().toISOString(),\n project_root: cwd,\n claude_md_files: claudeMdFiles,\n rules,\n settings,\n commands,\n hooks_registered: hooksRegistered,\n };\n\n return scanContextSchema.parse(ctx);\n}\n","// Scan module schemas.\n// Defines the ScanContext shape that captures all Claude Code configuration\n// sources (CLAUDE.md, rules, settings, commands, hooks) for deep analysis.\n\nimport { z } from 'zod/v4';\n\nexport const scanContextSchema = z.object({\n generated_at: z.iso.datetime(),\n project_root: z.string(),\n claude_md_files: z.array(\n z.object({\n path: z.string(),\n scope: z.enum(['user', 'project', 'local']),\n content: z.string(),\n line_count: z.number(),\n headings: z.array(z.string()),\n references: z.array(z.string()),\n }),\n ),\n rules: z.array(\n z.object({\n path: z.string(),\n filename: z.string(),\n content: z.string(),\n frontmatter: z\n .object({\n paths: z.array(z.string()).optional(),\n })\n .optional(),\n headings: z.array(z.string()),\n }),\n ),\n settings: z.object({\n user: z.unknown().nullable(),\n project: z.unknown().nullable(),\n local: z.unknown().nullable(),\n }),\n commands: z.array(\n z.object({\n path: z.string(),\n name: z.string(),\n content: z.string(),\n }),\n ),\n hooks_registered: z.array(\n z.object({\n event: z.string(),\n scope: z.enum(['user', 'project', 'local']),\n type: z.string(),\n command: z.string().optional(),\n }),\n ),\n});\nexport type ScanContext = z.infer<typeof scanContextSchema>;\n","// Redundancy scanner for deep scan module.\n// Detects duplicate headings across CLAUDE.md and rule files, and\n// duplicate rule files with highly similar heading sets.\n\nimport type { ScanContext } from '../schemas.js';\nimport type { Recommendation } from '../../schemas/recommendation.js';\n\n/**\n * Normalize text for comparison: lowercase, trim, collapse whitespace.\n */\nexport function normalizeText(text: string): string {\n return text.toLowerCase().trim().replace(/\\s+/g, ' ');\n}\n\n/**\n * Scan for redundant configuration: duplicate headings across CLAUDE.md\n * and rules, and duplicate rule files with matching heading sets.\n */\nexport function scanRedundancy(context: ScanContext): Recommendation[] {\n const recommendations: Recommendation[] = [];\n let index = 0;\n\n // Check 1: CLAUDE.md headings vs rule headings\n const claudeMdHeadings = context.claude_md_files.flatMap(f =>\n f.headings.map(h => ({ heading: normalizeText(h), source: f.path })),\n );\n const ruleHeadings = context.rules.flatMap(r =>\n r.headings.map(h => ({ heading: normalizeText(h), source: r.path })),\n );\n\n for (const cmdH of claudeMdHeadings) {\n const match = ruleHeadings.find(rH => rH.heading === cmdH.heading);\n if (match) {\n recommendations.push({\n id: `rec-scan-redundancy-${index++}`,\n target: 'RULE',\n confidence: 'MEDIUM',\n pattern_type: 'scan_redundancy',\n title: `Redundant section: \"${cmdH.heading}\"`,\n description:\n `The heading \"${cmdH.heading}\" appears in both ` +\n `${cmdH.source} and ${match.source}. ` +\n `This may indicate duplicated instructions.`,\n evidence: {\n count: 2,\n examples: [cmdH.source, match.source],\n },\n suggested_action:\n 'Consolidate into one location. If it belongs in rules, ' +\n 'remove from CLAUDE.md. If it belongs in CLAUDE.md, remove the rule file.',\n });\n }\n }\n\n // Check 2: Duplicate rule files (same heading set in 2+ rule files)\n const rulesByHeadingSet = new Map<string, string[]>();\n for (const rule of context.rules) {\n const key = rule.headings\n .map(h => normalizeText(h))\n .sort()\n .join('||');\n if (!key) continue; // Skip rules with no headings\n const existing = rulesByHeadingSet.get(key) ?? [];\n existing.push(rule.path);\n rulesByHeadingSet.set(key, existing);\n }\n\n for (const [, paths] of rulesByHeadingSet) {\n if (paths.length < 2) continue;\n recommendations.push({\n id: `rec-scan-redundancy-${index++}`,\n target: 'RULE',\n confidence: 'MEDIUM',\n pattern_type: 'scan_redundancy',\n title: `Duplicate rule files detected (${paths.length} files with same headings)`,\n description:\n `${paths.length} rule files share the same heading structure: ` +\n `${paths.join(', ')}. They may contain redundant content.`,\n evidence: {\n count: paths.length,\n examples: paths.slice(0, 3),\n },\n suggested_action:\n 'Review these rule files and merge them into a single file, ' +\n 'or differentiate their content.',\n });\n }\n\n return recommendations;\n}\n","// Mechanization scanner for deep scan module.\n// Detects operations described in rules/CLAUDE.md text that should be\n// enforced via hooks for 100% reliable execution.\n\nimport type { ScanContext } from '../schemas.js';\nimport type { Recommendation } from '../../schemas/recommendation.js';\n\n/**\n * Patterns in rule/CLAUDE.md text that suggest hookable operations.\n * Each indicator maps a text pattern to the hook event that could enforce it.\n */\nexport const MECHANIZATION_INDICATORS = [\n { regex: /always\\s+run\\s+[\"`']?(\\S+)/i, hookEvent: 'PreToolUse', label: 'always run' },\n {\n regex: /before\\s+committing?,?\\s+run\\s+[\"`']?(\\S+)/i,\n hookEvent: 'PreToolUse',\n label: 'pre-commit check',\n },\n {\n regex: /after\\s+every\\s+(?:edit|change|write)/i,\n hookEvent: 'PostToolUse',\n label: 'post-edit action',\n },\n {\n regex: /must\\s+(?:always\\s+)?check\\s+[\"`']?(\\S+)/i,\n hookEvent: 'PreToolUse',\n label: 'mandatory check',\n },\n {\n regex: /never\\s+(?:allow|permit|run)\\s+[\"`']?(\\S+)/i,\n hookEvent: 'PreToolUse',\n label: 'forbidden operation',\n },\n {\n regex: /forbidden.*(?:rm\\s+-rf|drop\\s+|delete\\s+|truncate)/i,\n hookEvent: 'PreToolUse',\n label: 'dangerous command guard',\n },\n] as const;\n\n/**\n * Scan for operations described in text that should be enforced via hooks.\n * Skips patterns that are already covered by a registered hook for the\n * corresponding event type.\n */\nexport function scanMechanization(context: ScanContext): Recommendation[] {\n const recommendations: Recommendation[] = [];\n let index = 0;\n\n // Collect all text sources: CLAUDE.md files and rule files\n const allTextSources = [\n ...context.claude_md_files.map(f => ({ content: f.content, source: f.path })),\n ...context.rules.map(r => ({ content: r.content, source: r.path })),\n ];\n\n for (const source of allTextSources) {\n for (const indicator of MECHANIZATION_INDICATORS) {\n const match = source.content.match(indicator.regex);\n if (!match) continue;\n\n // Check if a hook already covers this event\n const alreadyCovered = context.hooks_registered.some(\n h => h.event === indicator.hookEvent,\n );\n if (alreadyCovered) continue;\n\n recommendations.push({\n id: `rec-scan-mechanize-${index++}`,\n target: 'HOOK',\n confidence: 'MEDIUM',\n pattern_type: 'scan_missing_mechanization',\n title: `Mechanizable rule: \"${match[0].substring(0, 60)}\"`,\n description:\n `Found a rule in ${source.source} that describes an operation ` +\n `suitable for a ${indicator.hookEvent} hook: \"${match[0]}\". ` +\n 'Hooks provide 100% reliable execution, while rules depend on ' +\n \"Claude's probabilistic compliance.\",\n evidence: {\n count: 1,\n examples: [match[0].substring(0, 100)],\n },\n suggested_action:\n `Create a ${indicator.hookEvent} hook to enforce this rule ` +\n `automatically. See Claude Code hooks docs for ${indicator.hookEvent} event.`,\n });\n }\n }\n\n return recommendations;\n}\n","// Staleness scanner for deep scan module.\n// Detects broken @references in CLAUDE.md files and hook commands\n// pointing to non-existent scripts.\n\nimport type { ScanContext } from '../schemas.js';\nimport type { Recommendation } from '../../schemas/recommendation.js';\nimport { access } from 'node:fs/promises';\nimport { constants } from 'node:fs';\nimport { resolve, dirname } from 'node:path';\n\n/**\n * Check if a file exists on disk.\n */\nasync function fileExistsOnDisk(filePath: string): Promise<boolean> {\n try {\n await access(filePath, constants.F_OK);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Extract a file path from a hook command string.\n * Handles patterns like:\n * node \"path/to/script.js\"\n * node 'path/to/script.js'\n * node path/to/script.js\n * sh /path/to/script.sh\n * /usr/bin/node /path/to/file.js\n */\nfunction extractPathFromCommand(command: string): string | null {\n // Match quoted path: node \"path\" or node 'path'\n const quotedMatch = command.match(/(?:node|sh|bash|python)\\s+[\"']([^\"']+)[\"']/i);\n if (quotedMatch) return quotedMatch[1];\n\n // Match unquoted path after common interpreters\n const unquotedMatch = command.match(\n /(?:node|sh|bash|python)\\s+(\\S+\\.(?:js|ts|sh|py|mjs|cjs))/i,\n );\n if (unquotedMatch) return unquotedMatch[1];\n\n return null;\n}\n\n/**\n * Scan for stale references: broken @references in CLAUDE.md files and\n * hook commands pointing to non-existent scripts.\n *\n * This scanner is async because it needs to check the filesystem for\n * reference targets not present in the ScanContext.\n */\nexport async function scanStaleness(context: ScanContext): Promise<Recommendation[]> {\n const recommendations: Recommendation[] = [];\n let index = 0;\n\n // Check 1: Stale @references in CLAUDE.md files\n for (const claudeMd of context.claude_md_files) {\n for (const ref of claudeMd.references) {\n const resolved = resolve(dirname(claudeMd.path), ref);\n\n // Check if referenced path exists in context data\n const inContext =\n context.rules.some(r => r.path === resolved) ||\n context.claude_md_files.some(f => f.path === resolved) ||\n context.commands.some(c => c.path === resolved);\n\n if (inContext) continue;\n\n // Check filesystem as fallback\n const existsOnDisk = await fileExistsOnDisk(resolved);\n if (existsOnDisk) continue;\n\n recommendations.push({\n id: `rec-scan-stale-${index++}`,\n target: 'CLAUDE_MD',\n confidence: 'HIGH',\n pattern_type: 'scan_stale_reference',\n title: `Stale reference: @${ref}`,\n description: `${claudeMd.path} references @${ref}, but this file does not exist.`,\n evidence: {\n count: 1,\n examples: [`@${ref} in ${claudeMd.path}`],\n },\n suggested_action:\n `Remove the @${ref} reference from ${claudeMd.path}, ` +\n 'or create the missing file.',\n });\n }\n }\n\n // Check 2: Hook commands pointing to non-existent scripts\n for (const hook of context.hooks_registered) {\n if (!hook.command) continue;\n\n const scriptPath = extractPathFromCommand(hook.command);\n if (!scriptPath) continue;\n\n const exists = await fileExistsOnDisk(scriptPath);\n if (exists) continue;\n\n recommendations.push({\n id: `rec-scan-stale-${index++}`,\n target: 'SETTINGS',\n confidence: 'HIGH',\n pattern_type: 'scan_stale_reference',\n title: `Stale hook script: ${scriptPath}`,\n description:\n `Hook (${hook.event}, ${hook.scope}) references script \"${scriptPath}\", ` +\n 'but this file does not exist. The hook will fail when triggered.',\n evidence: {\n count: 1,\n examples: [`${hook.event} hook command: ${hook.command}`],\n },\n suggested_action:\n `Create the missing script at \"${scriptPath}\", ` +\n 'or update the hook command in settings.json.',\n });\n }\n\n return recommendations;\n}\n","// Scanner registry for deep scan module.\n// Defines the Scanner type signature and holds all registered scanner\n// functions. Supports both sync and async scanners.\n\nimport type { ScanContext } from '../schemas.js';\nimport type { Recommendation } from '../../schemas/recommendation.js';\nimport { scanRedundancy } from './redundancy.js';\nimport { scanMechanization } from './mechanization.js';\nimport { scanStaleness } from './staleness.js';\n\nexport type Scanner = (context: ScanContext) => Recommendation[] | Promise<Recommendation[]>;\n\n// Scanner registry -- all 3 scanners registered\nexport const scanners: Scanner[] = [scanRedundancy, scanMechanization, scanStaleness];\n","// Deep scan orchestrator: builds context from config files and runs all scanners.\n// Entry point for the scan module -- coordinates context building with scanner\n// execution and returns merged recommendations.\n\nimport { buildScanContext } from './context-builder.js';\nimport { scanners } from './scanners/index.js';\nimport type { ScanContext } from './schemas.js';\nimport type { Recommendation } from '../schemas/recommendation.js';\nimport type { Scanner } from './scanners/index.js';\n\nexport interface ScanResult {\n generated_at: string;\n scan_context: ScanContext;\n recommendations: Recommendation[];\n}\n\n/**\n * Run a deep scan of Claude Code configuration at the given directory.\n * Reads all config files into a ScanContext, then runs all registered\n * scanners to detect quality issues. Returns merged recommendations.\n *\n * Errors in individual scanners are caught and logged, not propagated.\n * An empty recommendations array means no issues detected.\n */\nexport async function runDeepScan(\n cwd: string,\n home?: string,\n): Promise<ScanResult> {\n const scanContext = await buildScanContext(cwd, home);\n const recommendations: Recommendation[] = [];\n\n for (const scanner of scanners) {\n try {\n const result = await scanner(scanContext);\n recommendations.push(...result);\n } catch (err) {\n // Log but don't propagate -- scan is advisory, not critical\n console.error(\n `Scanner error: ${err instanceof Error ? err.message : String(err)}`,\n );\n }\n }\n\n return {\n generated_at: new Date().toISOString(),\n scan_context: scanContext,\n recommendations,\n };\n}\n\n// Re-export key types for consumers\nexport type { ScanContext } from './schemas.js';\nexport type { Scanner } from './scanners/index.js';\n","// Skill generator: converts long_prompt SKILL recommendations into\n// .claude/commands/<name>.md file drafts. Pure function -- no filesystem\n// access, no side effects. Returns null for non-applicable recommendations.\n\nimport type { Recommendation } from '../schemas/recommendation.js';\nimport type { GeneratedArtifact } from './schemas.js';\nimport { toSlug, escapeYaml, GENERATOR_VERSION, nowISO } from './schemas.js';\n\n/**\n * Generate a skill file draft from a long_prompt SKILL recommendation.\n *\n * @param rec - A Recommendation object (typically from the long-prompts classifier)\n * @returns GeneratedArtifact with type 'skill', or null if the recommendation\n * is not applicable (wrong target or pattern_type)\n */\nexport function generateSkill(rec: Recommendation): GeneratedArtifact | null {\n if (rec.target !== 'SKILL') return null;\n if (rec.pattern_type !== 'long_prompt') return null;\n\n const promptPreview = rec.evidence.examples[0] ?? '';\n const slugName = toSlug(rec.title);\n const firstSentence = rec.description.split('.')[0];\n\n const content = [\n '---',\n `name: ${escapeYaml(slugName)}`,\n `description: ${escapeYaml(firstSentence)}`,\n '---',\n '',\n `# ${rec.title}`,\n '',\n '## Instructions',\n '',\n promptPreview,\n '',\n '---',\n `*Auto-generated by harness-evolve (${rec.id})*`,\n ].join('\\n');\n\n return {\n type: 'skill',\n filename: `.claude/commands/${slugName}.md`,\n content,\n source_recommendation_id: rec.id,\n metadata: {\n generated_at: nowISO(),\n generator_version: GENERATOR_VERSION,\n pattern_type: rec.pattern_type,\n },\n };\n}\n","// CLAUDE.md patch generator: converts CLAUDE_MD-targeted recommendations\n// into simplified unified diff format patches. Handles scan_stale_reference,\n// scan_redundancy, and generic CLAUDE_MD pattern types. Pure function --\n// no filesystem access, no side effects. Returns null for non-applicable\n// recommendations.\n\nimport type { Recommendation } from '../schemas/recommendation.js';\nimport type { GeneratedArtifact } from './schemas.js';\nimport { GENERATOR_VERSION, nowISO } from './schemas.js';\n\n/**\n * Build a patch for stale reference removal.\n * Shows the stale reference as a removed line and a comment replacement.\n */\nfunction buildStaleReferencePatch(rec: Recommendation): string {\n const staleRef = rec.evidence.examples[0] ?? '';\n return [\n '--- a/CLAUDE.md',\n '+++ b/CLAUDE.md',\n '@@ Stale reference removal @@',\n `- ${staleRef}`,\n `+ # (removed stale reference: ${staleRef})`,\n ].join('\\n');\n}\n\n/**\n * Build a patch for redundancy consolidation.\n * Shows the suggested consolidation action as added lines.\n */\nfunction buildRedundancyPatch(rec: Recommendation): string {\n return [\n '--- a/CLAUDE.md',\n '+++ b/CLAUDE.md',\n `@@ Redundancy consolidation: ${rec.title} @@`,\n '+ # Consolidation needed',\n '+',\n `+ ${rec.suggested_action}`,\n ].join('\\n');\n}\n\n/**\n * Build a generic patch for other CLAUDE_MD recommendations.\n * Adds a new section with the recommendation title and suggested action.\n */\nfunction buildGenericPatch(rec: Recommendation): string {\n return [\n '--- a/CLAUDE.md',\n '+++ b/CLAUDE.md',\n `@@ ${rec.title} @@`,\n `+ ## ${rec.title}`,\n '+',\n `+ ${rec.suggested_action}`,\n ].join('\\n');\n}\n\n/**\n * Generate a CLAUDE.md patch from a CLAUDE_MD-targeted recommendation.\n *\n * @param rec - A Recommendation object (from deep scan or analysis classifiers)\n * @returns GeneratedArtifact with type 'claude_md_patch', or null if the\n * recommendation is not applicable (wrong target)\n */\nexport function generateClaudeMdPatch(\n rec: Recommendation,\n): GeneratedArtifact | null {\n if (rec.target !== 'CLAUDE_MD') return null;\n\n let patchContent: string;\n\n switch (rec.pattern_type) {\n case 'scan_stale_reference':\n patchContent = buildStaleReferencePatch(rec);\n break;\n case 'scan_redundancy':\n patchContent = buildRedundancyPatch(rec);\n break;\n default:\n patchContent = buildGenericPatch(rec);\n break;\n }\n\n return {\n type: 'claude_md_patch',\n filename: 'CLAUDE.md',\n content: patchContent,\n source_recommendation_id: rec.id,\n metadata: {\n generated_at: nowISO(),\n generator_version: GENERATOR_VERSION,\n pattern_type: rec.pattern_type,\n },\n };\n}\n","// Scan CLI subcommand -- triggers deep configuration scan and outputs JSON results.\n// Used by the /evolve:scan slash command to programmatically invoke scanning.\n\nimport type { Command } from '@commander-js/extra-typings';\nimport { runDeepScan } from '../scan/index.js';\n\n/** Confidence tier ordering: HIGH (0) -> MEDIUM (1) -> LOW (2) */\nconst CONFIDENCE_ORDER: Record<string, number> = { HIGH: 0, MEDIUM: 1, LOW: 2 };\n\n/**\n * Register the 'scan' subcommand on a Commander.js program.\n *\n * Runs a full deep configuration scan (CLAUDE.md, rules, settings, hooks)\n * and outputs the results as structured JSON to stdout. The output omits\n * scan_context to keep it concise for slash command consumers.\n */\nexport function registerScanCommand(program: Command): void {\n program\n .command('scan')\n .description('Run deep configuration scan and output results as JSON')\n .action(async () => {\n try {\n const result = await runDeepScan(process.cwd());\n // Sort recommendations by confidence: HIGH -> MEDIUM -> LOW\n const sorted = [...result.recommendations].sort((a, b) =>\n (CONFIDENCE_ORDER[a.confidence] ?? 3) - (CONFIDENCE_ORDER[b.confidence] ?? 3)\n );\n // Output minimal JSON (no scan_context to keep output clean for slash command)\n const output = {\n generated_at: result.generated_at,\n recommendation_count: sorted.length,\n recommendations: sorted,\n };\n console.log(JSON.stringify(output, null, 2));\n } catch (err) {\n console.log(JSON.stringify({\n error: err instanceof Error ? err.message : String(err),\n recommendations: [],\n }, null, 2));\n process.exitCode = 1;\n }\n });\n}\n","// Apply CLI subcommands -- pending, apply-one, dismiss.\n// Used by the /evolve:apply slash command for interactive recommendation management.\n\nimport { readFile, appendFile } from 'node:fs/promises';\nimport type { Command } from '@commander-js/extra-typings';\nimport { loadState, updateStatus } from '../delivery/state.js';\nimport { paths } from '../storage/dirs.js';\nimport type { Recommendation } from '../schemas/recommendation.js';\nimport { analysisResultSchema } from '../schemas/recommendation.js';\n\n// Trigger applier registration by importing auto-apply (registers all 4 appliers as side effect)\nimport '../delivery/auto-apply.js';\nimport { getApplier } from '../delivery/appliers/index.js';\n\n/** Confidence tier ordering: HIGH (0) -> MEDIUM (1) -> LOW (2) */\nconst CONFIDENCE_ORDER: Record<string, number> = { HIGH: 0, MEDIUM: 1, LOW: 2 };\n\n/**\n * Load recommendations from the analysis result file.\n * Returns an empty array when the file does not exist or is invalid.\n */\nasync function loadAnalysisResult(): Promise<Recommendation[]> {\n try {\n const raw = await readFile(paths.analysisResult, 'utf-8');\n const parsed = analysisResultSchema.parse(JSON.parse(raw));\n return parsed.recommendations;\n } catch {\n return [];\n }\n}\n\n/**\n * Register the 'pending' subcommand on a Commander.js program.\n *\n * Reads the analysis result and recommendation state, filters to\n * recommendations that are not yet applied or dismissed, and outputs\n * the pending list as structured JSON.\n */\nexport function registerPendingCommand(program: Command): void {\n program\n .command('pending')\n .description('List pending recommendations as JSON')\n .action(async () => {\n const allRecs = await loadAnalysisResult();\n const state = await loadState();\n const statusMap = new Map(state.entries.map(e => [e.id, e.status]));\n\n // Filter to pending: recommendations not in state, or explicitly pending\n // Sort by confidence: HIGH -> MEDIUM -> LOW\n const pending = allRecs\n .filter(rec => {\n const status = statusMap.get(rec.id);\n return status === undefined || status === 'pending';\n })\n .sort((a, b) =>\n (CONFIDENCE_ORDER[a.confidence] ?? 3) - (CONFIDENCE_ORDER[b.confidence] ?? 3)\n );\n\n console.log(JSON.stringify({ pending, count: pending.length }, null, 2));\n });\n}\n\n/**\n * Register the 'apply-one' subcommand on a Commander.js program.\n *\n * Loads the recommendation by ID from analysis result, finds the correct\n * applier from the registry, applies the recommendation, logs the attempt,\n * and updates the recommendation status on success.\n */\nexport function registerApplyOneCommand(program: Command): void {\n program\n .command('apply-one')\n .description('Apply a single recommendation by ID')\n .argument('<id>', 'Recommendation ID to apply')\n .action(async (id) => {\n try {\n const allRecs = await loadAnalysisResult();\n const rec = allRecs.find(r => r.id === id);\n if (!rec) {\n console.log(JSON.stringify({\n recommendation_id: id,\n success: false,\n details: `Recommendation '${id}' not found`,\n }));\n process.exitCode = 1;\n return;\n }\n\n const applier = getApplier(rec.target);\n if (!applier || !applier.canApply(rec)) {\n console.log(JSON.stringify({\n recommendation_id: id,\n success: false,\n details: `No applicable applier for target '${rec.target}'`,\n }));\n process.exitCode = 1;\n return;\n }\n\n const result = await applier.apply(rec);\n\n // Log the attempt (non-critical -- ignore write failures)\n const logEntry = {\n timestamp: new Date().toISOString(),\n recommendation_id: rec.id,\n target: rec.target,\n action: rec.suggested_action,\n success: result.success,\n details: result.details,\n };\n try {\n await appendFile(paths.autoApplyLog, JSON.stringify(logEntry) + '\\n', 'utf-8');\n } catch {\n // Log failure is non-critical\n }\n\n // Update status to applied on success\n if (result.success) {\n await updateStatus(id, 'applied', `Applied via /evolve:apply: ${result.details}`);\n }\n\n console.log(JSON.stringify(result, null, 2));\n } catch (err) {\n console.log(JSON.stringify({\n recommendation_id: id,\n success: false,\n details: err instanceof Error ? err.message : String(err),\n }));\n process.exitCode = 1;\n }\n });\n}\n\n/**\n * Register the 'dismiss' subcommand on a Commander.js program.\n *\n * Permanently dismisses a recommendation by updating its status to 'dismissed'.\n * Outputs JSON confirmation with the recommendation ID and status.\n */\nexport function registerDismissCommand(program: Command): void {\n program\n .command('dismiss')\n .description('Permanently dismiss a recommendation by ID')\n .argument('<id>', 'Recommendation ID to dismiss')\n .action(async (id) => {\n try {\n await updateStatus(id, 'dismissed', 'Dismissed by user via /evolve:apply');\n console.log(JSON.stringify({ id, status: 'dismissed' }, null, 2));\n } catch (err) {\n console.log(JSON.stringify({\n id,\n error: err instanceof Error ? err.message : String(err),\n }));\n process.exitCode = 1;\n }\n });\n}\n"],"mappings":";AAAA,SAAS,SAAS;AAEX,IAAM,eAAe,EAAE,OAAO;AAAA,EACnC,SAAS,EAAE,OAAO,EAAE,QAAQ,CAAC;AAAA,EAC7B,UAAU,EAAE,OAAO;AAAA,IACjB,WAAW,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,QAAQ,EAAE;AAAA,IACvC,SAAS,EAAE,QAAQ,EAAE,QAAQ,IAAI;AAAA,IACjC,sBAAsB,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC,EAAE,QAAQ,CAAC,CAAC;AAAA,EACnE,CAAC,EAAE,QAAQ,EAAE,WAAW,IAAI,SAAS,MAAM,sBAAsB,CAAC,EAAE,CAAC;AAAA,EACrE,OAAO,EAAE,OAAO;AAAA,IACd,gBAA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AAAA,QACnB,SAAS;AAAA,QACT,SAAS,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;AAAA,MAC1D,CAAC,CAAC;AACF,cAAQ,WAAW;AAAA,IACrB;AAAA,EACF,CAAC;AACL;AAQO,SAAS,uBAAuB,SAAwB;AAC7D,UACG,QAAQ,SAAS,EACjB,YAAY,4CAA4C,EACxD,SAAS,QAAQ,8BAA8B,EAC/C,OAAO,OAAO,OAAO;AACpB,QAAI;AACF,YAAM,aAAa,IAAI,aAAa,qCAAqC;AACzE,cAAQ,IAAI,KAAK,UAAU,EAAE,IAAI,QAAQ,YAAY,GAAG,MAAM,CAAC,CAAC;AAAA,IAClE,SAAS,KAAK;AACZ,cAAQ,IAAI,KAAK,UAAU;AAAA,QACzB;AAAA,QACA,OAAO,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;AAAA,MACxD,CAAC,CAAC;AACF,cAAQ,WAAW;AAAA,IACrB;AAAA,EACF,CAAC;AACL;","names":["z","z","z","resolve","readFile","writeFileAtomic","readFile","writeFileAtomic","join","z","writeFileAtomic","formatDate","readdir","readFile","join","writeFileAtomic","join","writeFileAtomic","readFile","readdir","truncate","z","readFile","readFile","writeFileAtomic","z","readFile","writeFileAtomic","z","readFile","isNodeError","writeFileAtomic","readFile","lock","appendFile","join","join","appendFile","mkdir","join","writeFileAtomic","join","mkdir","writeFileAtomic","readFile","readFile","appendFile","readFile","mkdir","join","writeFileAtomic","join","readFile","mkdir","writeFileAtomic","writeFile","access","mkdir","join","writeFile","access","mkdir","copyFile","join","z","readFile","join","createInterface","writeFileAtomic","readFile","writeFileAtomic","join","access","mkdir","writeFile","copyFile","readFile","mkdir","join","dirname","writeFileAtomic","join","readFile","mkdir","writeFileAtomic","dirname","appendFile","readFile","readdir","join","basename","z","readFile","join","readdir","paths","basename","paths","access","constants","dirname","CONFIDENCE_ORDER","readFile","appendFile","CONFIDENCE_ORDER","readFile","appendFile"]}
|