@agent-native/core 0.34.0 → 0.35.2

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.
Files changed (135) hide show
  1. package/dist/agent/context-xray/actions/context-evict.d.ts +3 -0
  2. package/dist/agent/context-xray/actions/context-evict.d.ts.map +1 -0
  3. package/dist/agent/context-xray/actions/context-evict.js +35 -0
  4. package/dist/agent/context-xray/actions/context-evict.js.map +1 -0
  5. package/dist/agent/context-xray/actions/context-manifest-get.d.ts +3 -0
  6. package/dist/agent/context-xray/actions/context-manifest-get.d.ts.map +1 -0
  7. package/dist/agent/context-xray/actions/context-manifest-get.js +67 -0
  8. package/dist/agent/context-xray/actions/context-manifest-get.js.map +1 -0
  9. package/dist/agent/context-xray/actions/context-pin.d.ts +3 -0
  10. package/dist/agent/context-xray/actions/context-pin.d.ts.map +1 -0
  11. package/dist/agent/context-xray/actions/context-pin.js +35 -0
  12. package/dist/agent/context-xray/actions/context-pin.js.map +1 -0
  13. package/dist/agent/context-xray/actions/context-report.d.ts +3 -0
  14. package/dist/agent/context-xray/actions/context-report.d.ts.map +1 -0
  15. package/dist/agent/context-xray/actions/context-report.js +59 -0
  16. package/dist/agent/context-xray/actions/context-report.js.map +1 -0
  17. package/dist/agent/context-xray/actions/context-restore.d.ts +3 -0
  18. package/dist/agent/context-xray/actions/context-restore.d.ts.map +1 -0
  19. package/dist/agent/context-xray/actions/context-restore.js +33 -0
  20. package/dist/agent/context-xray/actions/context-restore.js.map +1 -0
  21. package/dist/agent/context-xray/actions/errors.d.ts +7 -0
  22. package/dist/agent/context-xray/actions/errors.d.ts.map +1 -0
  23. package/dist/agent/context-xray/actions/errors.js +15 -0
  24. package/dist/agent/context-xray/actions/errors.js.map +1 -0
  25. package/dist/agent/context-xray/apply-directives.d.ts +10 -0
  26. package/dist/agent/context-xray/apply-directives.d.ts.map +1 -0
  27. package/dist/agent/context-xray/apply-directives.js +100 -0
  28. package/dist/agent/context-xray/apply-directives.js.map +1 -0
  29. package/dist/agent/context-xray/directives-store.d.ts +26 -0
  30. package/dist/agent/context-xray/directives-store.d.ts.map +1 -0
  31. package/dist/agent/context-xray/directives-store.js +131 -0
  32. package/dist/agent/context-xray/directives-store.js.map +1 -0
  33. package/dist/agent/context-xray/identity.d.ts +5 -0
  34. package/dist/agent/context-xray/identity.d.ts.map +1 -0
  35. package/dist/agent/context-xray/identity.js +33 -0
  36. package/dist/agent/context-xray/identity.js.map +1 -0
  37. package/dist/agent/context-xray/manifest.d.ts +19 -0
  38. package/dist/agent/context-xray/manifest.d.ts.map +1 -0
  39. package/dist/agent/context-xray/manifest.js +115 -0
  40. package/dist/agent/context-xray/manifest.js.map +1 -0
  41. package/dist/agent/context-xray/migrations.d.ts +3 -0
  42. package/dist/agent/context-xray/migrations.d.ts.map +1 -0
  43. package/dist/agent/context-xray/migrations.js +31 -0
  44. package/dist/agent/context-xray/migrations.js.map +1 -0
  45. package/dist/agent/context-xray/plugin.d.ts +5 -0
  46. package/dist/agent/context-xray/plugin.d.ts.map +1 -0
  47. package/dist/agent/context-xray/plugin.js +15 -0
  48. package/dist/agent/context-xray/plugin.js.map +1 -0
  49. package/dist/agent/context-xray/schema.d.ts +249 -0
  50. package/dist/agent/context-xray/schema.d.ts.map +1 -0
  51. package/dist/agent/context-xray/schema.js +17 -0
  52. package/dist/agent/context-xray/schema.js.map +1 -0
  53. package/dist/agent/context-xray/segments.d.ts +19 -0
  54. package/dist/agent/context-xray/segments.d.ts.map +1 -0
  55. package/dist/agent/context-xray/segments.js +154 -0
  56. package/dist/agent/context-xray/segments.js.map +1 -0
  57. package/dist/agent/context-xray/tokenize.d.ts +10 -0
  58. package/dist/agent/context-xray/tokenize.d.ts.map +1 -0
  59. package/dist/agent/context-xray/tokenize.js +70 -0
  60. package/dist/agent/context-xray/tokenize.js.map +1 -0
  61. package/dist/agent/production-agent.d.ts +2 -0
  62. package/dist/agent/production-agent.d.ts.map +1 -1
  63. package/dist/agent/production-agent.js +45 -5
  64. package/dist/agent/production-agent.js.map +1 -1
  65. package/dist/cli/context-xray-local.d.ts +16 -0
  66. package/dist/cli/context-xray-local.d.ts.map +1 -0
  67. package/dist/cli/context-xray-local.js +738 -0
  68. package/dist/cli/context-xray-local.js.map +1 -0
  69. package/dist/cli/create.d.ts.map +1 -1
  70. package/dist/cli/create.js +1 -0
  71. package/dist/cli/create.js.map +1 -1
  72. package/dist/cli/skills.d.ts +3 -0
  73. package/dist/cli/skills.d.ts.map +1 -1
  74. package/dist/cli/skills.js +200 -73
  75. package/dist/cli/skills.js.map +1 -1
  76. package/dist/cli/templates-meta.js +5 -5
  77. package/dist/cli/templates-meta.js.map +1 -1
  78. package/dist/client/AssistantChat.d.ts.map +1 -1
  79. package/dist/client/AssistantChat.js +2 -1
  80. package/dist/client/AssistantChat.js.map +1 -1
  81. package/dist/client/components/ui/sheet.d.ts +16 -0
  82. package/dist/client/components/ui/sheet.d.ts.map +1 -0
  83. package/dist/client/components/ui/sheet.js +23 -0
  84. package/dist/client/components/ui/sheet.js.map +1 -0
  85. package/dist/client/context-xray/ContextMeter.d.ts +4 -0
  86. package/dist/client/context-xray/ContextMeter.d.ts.map +1 -0
  87. package/dist/client/context-xray/ContextMeter.js +76 -0
  88. package/dist/client/context-xray/ContextMeter.js.map +1 -0
  89. package/dist/client/context-xray/ContextSegmentRow.d.ts +9 -0
  90. package/dist/client/context-xray/ContextSegmentRow.d.ts.map +1 -0
  91. package/dist/client/context-xray/ContextSegmentRow.js +22 -0
  92. package/dist/client/context-xray/ContextSegmentRow.js.map +1 -0
  93. package/dist/client/context-xray/ContextTreemap.d.ts +6 -0
  94. package/dist/client/context-xray/ContextTreemap.d.ts.map +1 -0
  95. package/dist/client/context-xray/ContextTreemap.js +49 -0
  96. package/dist/client/context-xray/ContextTreemap.js.map +1 -0
  97. package/dist/client/context-xray/ContextXRayPanel.d.ts +11 -0
  98. package/dist/client/context-xray/ContextXRayPanel.d.ts.map +1 -0
  99. package/dist/client/context-xray/ContextXRayPanel.js +87 -0
  100. package/dist/client/context-xray/ContextXRayPanel.js.map +1 -0
  101. package/dist/client/context-xray/SegmentProvenancePopover.d.ts +7 -0
  102. package/dist/client/context-xray/SegmentProvenancePopover.d.ts.map +1 -0
  103. package/dist/client/context-xray/SegmentProvenancePopover.js +7 -0
  104. package/dist/client/context-xray/SegmentProvenancePopover.js.map +1 -0
  105. package/dist/client/context-xray/format.d.ts +7 -0
  106. package/dist/client/context-xray/format.d.ts.map +1 -0
  107. package/dist/client/context-xray/format.js +47 -0
  108. package/dist/client/context-xray/format.js.map +1 -0
  109. package/dist/deploy/route-discovery.d.ts.map +1 -1
  110. package/dist/deploy/route-discovery.js +1 -0
  111. package/dist/deploy/route-discovery.js.map +1 -1
  112. package/dist/deploy/workspace-core.d.ts +1 -1
  113. package/dist/deploy/workspace-core.d.ts.map +1 -1
  114. package/dist/deploy/workspace-core.js +1 -0
  115. package/dist/deploy/workspace-core.js.map +1 -1
  116. package/dist/server/action-discovery.d.ts.map +1 -1
  117. package/dist/server/action-discovery.js +20 -0
  118. package/dist/server/action-discovery.js.map +1 -1
  119. package/dist/server/framework-request-handler.d.ts.map +1 -1
  120. package/dist/server/framework-request-handler.js +2 -0
  121. package/dist/server/framework-request-handler.js.map +1 -1
  122. package/dist/server/index.d.ts +1 -0
  123. package/dist/server/index.d.ts.map +1 -1
  124. package/dist/server/index.js +1 -0
  125. package/dist/server/index.js.map +1 -1
  126. package/dist/shared/context-xray.d.ts +58 -0
  127. package/dist/shared/context-xray.d.ts.map +1 -0
  128. package/dist/shared/context-xray.js +17 -0
  129. package/dist/shared/context-xray.js.map +1 -0
  130. package/dist/templates/default/package.json +3 -3
  131. package/dist/vite/action-types-plugin.d.ts.map +1 -1
  132. package/dist/vite/action-types-plugin.js +20 -0
  133. package/dist/vite/action-types-plugin.js.map +1 -1
  134. package/package.json +15 -7
  135. package/src/templates/default/package.json +3 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-xray-local.js","sourceRoot":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ACtB,SAAS,CACP,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,QAAQ,EAAE,cAAc,EAAE,UAAU,CAAC,EAC5D,qBAAqB,EACrB,OAAO,CACR,CAAC;QACF,SAAS,CACP,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,UAAU,EAAE,iBAAiB,CAAC,EACrD,uBAAuB,EACvB,OAAO,CACR,CAAC;IACJ,CAAC;IAED,IAAI,OAAO,CAAC,KAAK,KAAK,SAAS,IAAI,WAAW,EAAE,CAAC;QAC/C,SAAS,CACP,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,cAAc,EAAE,UAAU,CAAC,EACxE,qBAAqB,EACrB,OAAO,CACR,CAAC;QACF,SAAS,CACP,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,UAAU,EAAE,iBAAiB,CAAC,EACjE,uBAAuB,EACvB,OAAO,CACR,CAAC;IACJ,CAAC;IAED,OAAO;QACL,QAAQ,EAAE,CAAC,qBAAqB,CAAC;QACjC,UAAU;QACV,OAAO;KACR,CAAC;AACJ,CAAC","sourcesContent":["import fs from \"node:fs\";\nimport os from \"node:os\";\nimport path from \"node:path\";\n\nimport type { ClientId } from \"./mcp-config-writers.js\";\n\nexport interface InstallLocalContextXrayOptions {\n baseDir?: string;\n clients: ClientId[];\n scope: string;\n dryRun?: boolean;\n}\n\nexport interface InstallLocalContextXrayResult {\n commands: string[];\n scriptPath: string;\n written: string[];\n}\n\nconst CONTEXT_XRAY_EXECUTABLE = String.raw`#!/usr/bin/env node\n\"use strict\";\n\nconst childProcess = require(\"node:child_process\");\nconst fs = require(\"node:fs\");\nconst os = require(\"node:os\");\nconst path = require(\"node:path\");\nconst { pathToFileURL } = require(\"node:url\");\n\nconst HOME = os.homedir();\nconst CODEX_DIR = process.env.CODEX_HOME && process.env.CODEX_HOME.trim() ? process.env.CODEX_HOME.trim() : path.join(HOME, \".codex\");\nconst CLAUDE_DIR = path.join(HOME, \".claude\");\nconst OUT_DIR = path.join(CODEX_DIR, \"context-xray\");\nconst SESSION_ID_RE = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i;\nconst CATEGORIES = [\"user\", \"assistant\", \"tool_call\", \"tool_output\", \"reasoning\", \"instructions\", \"attachment\", \"metadata\", \"other\"];\nconst LABELS = {\n user: \"User asks\",\n assistant: \"Assistant text\",\n tool_call: \"Tool calls\",\n tool_output: \"Tool output\",\n reasoning: \"Reasoning\",\n instructions: \"Instructions/context\",\n attachment: \"Attachments\",\n metadata: \"Metadata\",\n other: \"Other\",\n};\nconst COLORS = {\n user: \"#8ba8ff\",\n assistant: \"#55b982\",\n tool_call: \"#f0a85b\",\n tool_output: \"#e06b73\",\n reasoning: \"#a77be8\",\n instructions: \"#6ac3d5\",\n attachment: \"#d6a85a\",\n metadata: \"#9aa3ad\",\n other: \"#c3c8ce\",\n};\n\nfunction parseArgs(argv) {\n const out = {\n mode: \"current\",\n source: \"both\",\n since: \"7d\",\n last: 12,\n scanLimit: 80,\n project: process.cwd(),\n allProjects: false,\n sessionId: \"\",\n format: \"html\",\n out: \"\",\n open: false,\n port: 0,\n };\n for (let i = 0; i < argv.length; i++) {\n const arg = argv[i];\n const eat = (flag) => {\n if (arg === flag) return argv[++i] || \"\";\n if (arg.startsWith(flag + \"=\")) return arg.slice(flag.length + 1);\n return undefined;\n };\n let value;\n if (arg === \"threads\" || arg === \"--threads\") out.mode = \"threads\";\n else if (arg === \"trends\" || arg === \"--trends\") out.mode = \"trends\";\n else if (arg === \"current\" || arg === \"--current\") out.mode = \"current\";\n else if ((value = eat(\"--source\")) !== undefined) out.source = value;\n else if ((value = eat(\"--since\")) !== undefined) out.since = value;\n else if ((value = eat(\"--last\")) !== undefined) out.last = Number(value) || out.last;\n else if ((value = eat(\"--scan-limit\")) !== undefined) out.scanLimit = Number(value) || out.scanLimit;\n else if ((value = eat(\"--project\")) !== undefined) out.project = value;\n else if ((value = eat(\"--session-id\")) !== undefined) out.sessionId = value;\n else if ((value = eat(\"--format\")) !== undefined) out.format = value;\n else if ((value = eat(\"--out\")) !== undefined) out.out = value;\n else if ((value = eat(\"--port\")) !== undefined) out.port = Number(value) || 0;\n else if (arg === \"--all-projects\") out.allProjects = true;\n else if (arg === \"--open\") out.open = true;\n else if (arg === \"--json\") out.format = \"json\";\n else if (arg === \"--help\" || arg === \"-h\") out.help = true;\n }\n if (process.env.CLAUDE_CODE_SESSION_ID && !out.sessionId && out.mode === \"current\") {\n out.sessionId = process.env.CLAUDE_CODE_SESSION_ID;\n }\n if (out.mode === \"threads\") {\n out.allProjects = true;\n out.last = Math.max(out.last, 30);\n }\n if (out.mode === \"trends\") {\n out.allProjects = true;\n out.last = Math.max(out.last, 60);\n }\n if (out.mode === \"current\") {\n out.last = 1;\n }\n return out;\n}\n\nfunction help() {\n console.log([\n \"Context X-Ray\",\n \"\",\n \"Usage:\",\n \" context-xray --open Visualize the current/recent local thread\",\n \" context-xray threads --open Pick from recent Codex/Claude sessions\",\n \" context-xray trends --since 7d --open Show recent usage trends\",\n \" context-xray --session-id <id> --open Analyze one exact session\",\n \"\",\n \"Options:\",\n \" --source codex|claude|both\",\n \" --since 24h|7d|2w|ISO\",\n \" --last <n>\",\n \" --all-projects\",\n \" --format html|json\",\n \" --out <path>\",\n ].join(\"\\n\"));\n}\n\nfunction mkdirp(dir) {\n fs.mkdirSync(dir, { recursive: true });\n}\n\nfunction parseSince(value) {\n const now = Date.now();\n const match = String(value || \"7d\").trim().toLowerCase().match(/^(\\d+)([hdw])$/);\n if (match) {\n const amount = Number(match[1]);\n const unit = match[2];\n const mult = unit === \"h\" ? 3600000 : unit === \"d\" ? 86400000 : 604800000;\n return now - amount * mult;\n }\n const parsed = Date.parse(value);\n return Number.isFinite(parsed) ? parsed : now - 7 * 86400000;\n}\n\nfunction readJsonl(file) {\n try {\n return fs.readFileSync(file, \"utf8\").split(/\\r?\\n/).filter(Boolean).map((line) => {\n try {\n return JSON.parse(line);\n } catch {\n return null;\n }\n }).filter(Boolean);\n } catch {\n return [];\n }\n}\n\nfunction compact(value) {\n try {\n const text = JSON.stringify(value);\n return text.length > 250000 ? text.slice(0, 250000) : text;\n } catch {\n return String(value || \"\");\n }\n}\n\nfunction textFrom(value, depth) {\n if (depth > 8 || value == null) return \"\";\n if (typeof value === \"string\") return value.length > 250000 ? value.slice(0, 250000) : value;\n if (typeof value !== \"object\") return \"\";\n if (Array.isArray(value)) return value.map((item) => textFrom(item, depth + 1)).filter(Boolean).join(\"\\n\");\n const skip = new Set([\"encrypted_content\", \"id\", \"uuid\", \"call_id\", \"sessionId\", \"parentUuid\"]);\n const keys = new Set([\"text\", \"message\", \"output\", \"result\", \"content\", \"summary\", \"arguments\", \"args\", \"input\", \"stdout\", \"stderr\", \"attachment\"]);\n const parts = [];\n for (const key of Object.keys(value)) {\n if (skip.has(key)) continue;\n const item = value[key];\n if (keys.has(key) || typeof item === \"object\") {\n const text = textFrom(item, depth + 1);\n if (text) parts.push(text);\n }\n }\n return parts.join(\"\\n\");\n}\n\nfunction addCounter(counter, key, amount) {\n if (!key || !amount) return;\n counter[key] = (counter[key] || 0) + amount;\n}\n\nfunction mergeCounter(into, from) {\n for (const key of Object.keys(from || {})) addCounter(into, key, from[key]);\n}\n\nfunction estimateTokens(chars) {\n return chars > 0 ? Math.max(1, Math.ceil(chars / 4)) : 0;\n}\n\nfunction fmtTokens(tokens) {\n if (tokens >= 1000000) return (tokens / 1000000).toFixed(1) + \"m\";\n if (tokens >= 1000) return (tokens / 1000).toFixed(1) + \"k\";\n return String(tokens);\n}\n\nfunction pct(part, total) {\n return total > 0 ? Math.max(0, Math.min(100, (part / total) * 100)) : 0;\n}\n\nfunction pathCounts(text) {\n const out = {};\n const matches = String(text || \"\").match(/(?:(?:\\/[\\w@.+,=-]+)+|(?:[\\w.-]+\\/)+[\\w.+,=-]+)(?:\\.[A-Za-z0-9_+-]+)?/g) || [];\n for (const raw of matches) {\n const value = raw.replace(/['\",.)]+$/g, \"\");\n if (value.length > 5 && !value.startsWith(\"http\") && value.includes(\"/\")) addCounter(out, value, 1);\n }\n return out;\n}\n\nfunction codexTitle(id) {\n const index = path.join(CODEX_DIR, \"session_index.jsonl\");\n for (const record of readJsonl(index)) {\n if (record.id === id && record.thread_name) return String(record.thread_name);\n }\n return \"\";\n}\n\nfunction observedCodexTokens(payload) {\n if (!payload || payload.type !== \"token_count\" || !payload.info) return 0;\n const last = payload.info.last_token_usage;\n if (last && Number(last.total_tokens)) return Number(last.total_tokens);\n const total = payload.info.total_token_usage;\n if (total && Number(total.total_tokens)) return Number(total.total_tokens);\n if (total && typeof total === \"object\") {\n return [\"input_tokens\", \"cached_input_tokens\", \"output_tokens\", \"reasoning_output_tokens\"].reduce((sum, key) => sum + (Number(total[key]) || 0), 0);\n }\n return 0;\n}\n\nfunction claudeUsageTokens(usage) {\n if (!usage || typeof usage !== \"object\") return 0;\n return (Number(usage.input_tokens) || 0) + (Number(usage.output_tokens) || 0) + (Number(usage.cache_creation_input_tokens) || 0) + (Number(usage.cache_read_input_tokens) || 0);\n}\n\nfunction sessionIdFromPath(file) {\n const match = path.basename(file).match(SESSION_ID_RE);\n return match ? match[0] : path.basename(file, \".jsonl\");\n}\n\nfunction classifyCodex(record) {\n const top = String(record.type || \"\");\n const payload = record.payload && typeof record.payload === \"object\" ? record.payload : {};\n const ptype = String(payload.type || \"\");\n let category = \"other\";\n const tools = {};\n if (top === \"session_meta\") category = \"metadata\";\n else if (top === \"turn_context\") category = \"instructions\";\n else if (top === \"event_msg\") category = ptype === \"user_message\" ? \"user\" : \"metadata\";\n else if (top === \"response_item\") {\n if ([\"function_call\", \"custom_tool_call\", \"web_search_call\", \"tool_search_call\", \"tool_call\"].includes(ptype) || payload.name && payload.call_id) {\n category = \"tool_call\";\n if (payload.name) addCounter(tools, String(payload.name), 1);\n } else if ([\"function_call_output\", \"custom_tool_call_output\", \"tool_search_output\", \"tool_result\"].includes(ptype) || Object.prototype.hasOwnProperty.call(payload, \"output\")) category = \"tool_output\";\n else if (ptype === \"reasoning\" || payload.summary) category = \"reasoning\";\n else if (payload.role === \"assistant\") category = \"assistant\";\n else if (payload.role === \"user\" || payload.role === \"developer\") category = \"user\";\n }\n const text = textFrom(record, 0) || (category === \"metadata\" ? compact(record) : \"\");\n return { category, chars: text.length, tools, paths: pathCounts(text) };\n}\n\nfunction classifyClaude(record) {\n let category = \"other\";\n const tools = {};\n const message = record.message && typeof record.message === \"object\" ? record.message : null;\n let text = \"\";\n if (message) {\n if (message.role === \"user\") category = \"user\";\n else if (message.role === \"assistant\") category = \"assistant\";\n const content = Array.isArray(message.content) ? message.content : [message.content];\n const parts = [];\n for (const part of content) {\n if (part && typeof part === \"object\") {\n if (part.type === \"tool_use\") {\n category = \"tool_call\";\n if (part.name) addCounter(tools, String(part.name), 1);\n } else if (part.type === \"tool_result\") category = \"tool_output\";\n else if (part.type === \"thinking\") category = \"reasoning\";\n }\n parts.push(textFrom(part, 0));\n }\n text = parts.join(\"\\n\");\n } else if (record.toolUseResult) {\n category = \"tool_output\";\n text = textFrom(record.toolUseResult, 0);\n } else if (record.attachment) {\n category = \"attachment\";\n text = textFrom(record.attachment, 0);\n } else {\n text = textFrom(record, 0);\n }\n return { category, chars: text.length, tools, paths: pathCounts(text) };\n}\n\nfunction summarizeCodex(file) {\n const stat = fs.statSync(file);\n const summary = {\n source: \"codex\",\n path: file,\n sessionId: sessionIdFromPath(file),\n title: \"\",\n cwd: \"\",\n startedAt: \"\",\n updatedAt: \"\",\n categories: {},\n tools: {},\n paths: {},\n observedTokens: 0,\n bytes: stat.size,\n mtime: stat.mtimeMs,\n };\n const records = readJsonl(file);\n for (const record of records) {\n const payload = record.payload && typeof record.payload === \"object\" ? record.payload : {};\n if (record.type === \"session_meta\") {\n summary.sessionId = String(payload.id || summary.sessionId);\n summary.cwd = String(payload.cwd || summary.cwd);\n summary.startedAt = String(payload.timestamp || summary.startedAt);\n }\n if (payload.cwd && !summary.cwd) summary.cwd = String(payload.cwd);\n if (record.timestamp) summary.updatedAt = String(record.timestamp);\n summary.observedTokens = Math.max(summary.observedTokens, observedCodexTokens(payload));\n const stats = classifyCodex(record);\n addCounter(summary.categories, stats.category, stats.chars);\n mergeCounter(summary.tools, stats.tools);\n mergeCounter(summary.paths, stats.paths);\n }\n summary.title = codexTitle(summary.sessionId) || summary.sessionId;\n return finalizeSummary(summary);\n}\n\nfunction summarizeClaude(file) {\n const stat = fs.statSync(file);\n const summary = {\n source: \"claude\",\n path: file,\n sessionId: sessionIdFromPath(file),\n title: \"\",\n cwd: \"\",\n startedAt: \"\",\n updatedAt: \"\",\n categories: {},\n tools: {},\n paths: {},\n observedTokens: 0,\n bytes: stat.size,\n mtime: stat.mtimeMs,\n };\n const records = readJsonl(file);\n for (const record of records) {\n summary.sessionId = String(record.sessionId || summary.sessionId);\n summary.cwd = String(record.cwd || summary.cwd);\n if (record.timestamp) {\n summary.updatedAt = String(record.timestamp);\n if (!summary.startedAt) summary.startedAt = String(record.timestamp);\n }\n if (record.message && typeof record.message === \"object\") {\n summary.observedTokens = Math.max(summary.observedTokens, claudeUsageTokens(record.message.usage));\n if (!summary.title && record.message.role === \"user\") summary.title = cleanTitle(textFrom(record.message, 0)).slice(0, 90);\n }\n const stats = classifyClaude(record);\n addCounter(summary.categories, stats.category, stats.chars);\n mergeCounter(summary.tools, stats.tools);\n mergeCounter(summary.paths, stats.paths);\n }\n if (!summary.title) summary.title = summary.sessionId;\n return finalizeSummary(summary);\n}\n\nfunction finalizeSummary(summary) {\n const totalChars = Object.values(summary.categories).reduce((sum, value) => sum + value, 0);\n summary.totalChars = totalChars;\n summary.tokens = summary.observedTokens || estimateTokens(totalChars);\n summary.tokenMethod = summary.observedTokens ? \"observed\" : \"estimated\";\n return summary;\n}\n\nfunction walk(root) {\n const out = [];\n if (!fs.existsSync(root)) return out;\n const visit = (dir) => {\n let entries = [];\n try {\n entries = fs.readdirSync(dir, { withFileTypes: true });\n } catch {\n return;\n }\n for (const entry of entries) {\n const file = path.join(dir, entry.name);\n if (entry.isDirectory()) visit(file);\n else if (entry.isFile() && entry.name.endsWith(\".jsonl\")) out.push(file);\n }\n };\n visit(root);\n return out;\n}\n\nfunction encodedProject(project) {\n return path.resolve(project).replace(/\\//g, \"-\");\n}\n\nfunction pathInsideOrEqual(value, parent) {\n const relative = path.relative(parent, value);\n return relative === \"\" || (!!relative && !relative.startsWith(\"..\") && !path.isAbsolute(relative));\n}\n\nfunction candidateFiles(source, args) {\n if (args.sessionId) {\n const roots = source === \"codex\" ? [path.join(CODEX_DIR, \"sessions\"), path.join(CODEX_DIR, \"archived_sessions\")] : [path.join(CLAUDE_DIR, \"projects\")];\n return roots.flatMap(walk).filter((file) => file.includes(args.sessionId));\n }\n const since = parseSince(args.since);\n const roots = source === \"codex\" ? [path.join(CODEX_DIR, \"sessions\"), path.join(CODEX_DIR, \"archived_sessions\")] : [path.join(CLAUDE_DIR, \"projects\")];\n const projectFragment = encodedProject(args.project);\n const files = roots.flatMap(walk).filter((file) => {\n let stat;\n try {\n stat = fs.statSync(file);\n } catch {\n return false;\n }\n if (stat.mtimeMs < since) return false;\n if (args.allProjects || source === \"codex\") return true;\n return file.includes(projectFragment) || file.includes(path.basename(args.project));\n }).sort((a, b) => fs.statSync(b).mtimeMs - fs.statSync(a).mtimeMs);\n return source === \"codex\" && !args.allProjects ? files : files.slice(0, args.scanLimit);\n}\n\nfunction projectMatches(session, args) {\n if (args.allProjects || args.sessionId) return true;\n const project = path.resolve(args.project);\n if (session.cwd && pathInsideOrEqual(path.resolve(session.cwd), project)) return true;\n return session.path.includes(encodedProject(project));\n}\n\nfunction collectSessions(args) {\n const sources = args.source === \"both\" ? [\"codex\", \"claude\"] : [args.source];\n const sessions = [];\n for (const source of sources) {\n for (const file of candidateFiles(source, args)) {\n try {\n const summary = source === \"codex\" ? summarizeCodex(file) : summarizeClaude(file);\n if (projectMatches(summary, args)) sessions.push(summary);\n } catch {}\n }\n }\n if (args.mode === \"current\" || args.sessionId) sessions.sort((a, b) => b.mtime - a.mtime);\n else sessions.sort((a, b) => b.tokens - a.tokens || b.mtime - a.mtime);\n return sessions.slice(0, args.last);\n}\n\nfunction aggregate(sessions) {\n const out = { categories: {}, tools: {}, paths: {} };\n for (const session of sessions) {\n mergeCounter(out.categories, session.categories);\n mergeCounter(out.tools, session.tools);\n mergeCounter(out.paths, session.paths);\n }\n return out;\n}\n\nfunction sortedEntries(counter, limit) {\n return Object.entries(counter || {}).sort((a, b) => b[1] - a[1]).slice(0, limit);\n}\n\nfunction recommendations(sessions) {\n if (!sessions.length) return [\"No matching sessions found. Try context-xray threads --all-projects --since 2w --open.\"];\n const agg = aggregate(sessions);\n const total = Object.values(agg.categories).reduce((sum, value) => sum + value, 0);\n const tips = [];\n const toolOutput = pct(agg.categories.tool_output || 0, total);\n const instructions = pct(agg.categories.instructions || 0, total);\n const assistant = pct(agg.categories.assistant || 0, total);\n const maxSession = sessions.reduce((a, b) => a.tokens > b.tokens ? a : b);\n if (toolOutput > 45) tips.push(\"Tool output dominates context. Prefer targeted rg/sed ranges, cap logs, and ask agents to summarize failing blocks instead of pasting full output.\");\n if (instructions > 25) tips.push(\"Instructions are a large share. Move stable workflow rules into skills or AGENTS/CLAUDE files and keep per-turn prompts short.\");\n if (assistant > 45) tips.push(\"Assistant prose is heavy. Ask for terse progress updates during long runs and save rationale only when it changes decisions.\");\n if (maxSession.tokens > 80000) tips.push(\"The largest session is about \" + fmtTokens(maxSession.tokens) + \" \" + maxSession.tokenMethod + \" tokens. Compact or start a fresh handoff before another big implementation pass.\");\n const topTool = sortedEntries(agg.tools, 1)[0];\n if (topTool && topTool[1] > 20) tips.push(topTool[0] + \" appears \" + topTool[1] + \" times. Batch independent inspection and use parallel reads/searches.\");\n const topPath = sortedEntries(agg.paths, 1)[0];\n if (topPath && topPath[1] > 12) tips.push(topPath[0] + \" appears repeatedly (\" + topPath[1] + \" mentions). Pin a short role summary instead of rereading it.\");\n return tips.length ? tips.slice(0, 6) : [\"Recent sessions look balanced. Keep using focused reads, compact after milestones, and preserve decisions in a skill or repo doc.\"];\n}\n\nfunction escapeHtml(value) {\n return String(value || \"\").replace(/[&<>\"']/g, (ch) => ({ \"&\": \"&amp;\", \"<\": \"&lt;\", \">\": \"&gt;\", \"\\\"\": \"&quot;\", \"'\": \"&#39;\" }[ch]));\n}\n\nfunction cleanTitle(value) {\n return String(value || \"\").replace(/<[^>]+>/g, \" \").replace(/\\s+/g, \" \").trim();\n}\n\nfunction categoryBar(categories) {\n const total = Object.values(categories || {}).reduce((sum, value) => sum + value, 0);\n if (!total) return \"<div class=\\\"bar\\\"></div>\";\n return \"<div class=\\\"bar\\\">\" + CATEGORIES.map((cat) => {\n const value = categories[cat] || 0;\n if (!value) return \"\";\n const width = Math.max(1, pct(value, total));\n return \"<span title=\\\"\" + escapeHtml(LABELS[cat]) + \"\\\" style=\\\"width:\" + width.toFixed(2) + \"%;background:\" + COLORS[cat] + \"\\\"></span>\";\n }).join(\"\") + \"</div>\";\n}\n\nfunction renderHtml(sessions, args) {\n const agg = aggregate(sessions);\n const totalTokens = sessions.reduce((sum, s) => sum + s.tokens, 0);\n const tips = recommendations(sessions);\n const categoryRows = CATEGORIES.map((cat) => {\n const chars = agg.categories[cat] || 0;\n if (!chars) return \"\";\n return \"<tr><td>\" + escapeHtml(LABELS[cat]) + \"</td><td>\" + fmtTokens(estimateTokens(chars)) + \"</td><td>\" + pct(chars, Object.values(agg.categories).reduce((sum, value) => sum + value, 0)).toFixed(0) + \"%</td></tr>\";\n }).join(\"\");\n const sessionCards = sessions.map((session) => {\n const cats = Object.entries(session.categories).sort((a, b) => b[1] - a[1]).map((entry) => \"<tr><td>\" + escapeHtml(LABELS[entry[0]] || entry[0]) + \"</td><td>\" + fmtTokens(estimateTokens(entry[1])) + \"</td><td>\" + pct(entry[1], session.totalChars).toFixed(0) + \"%</td></tr>\").join(\"\");\n const tools = sortedEntries(session.tools, 6).map((entry) => \"<span class=\\\"badge\\\">\" + escapeHtml(entry[0]) + \" x\" + entry[1] + \"</span>\").join(\"\");\n const paths = sortedEntries(session.paths, 5).map((entry) => \"<span class=\\\"badge muted\\\">\" + escapeHtml(entry[0]) + \" x\" + entry[1] + \"</span>\").join(\"\");\n return \"<article class=\\\"card session\\\"><div class=\\\"session-head\\\"><div><div class=\\\"eyebrow\\\">\" + escapeHtml(session.source) + \" - \" + escapeHtml(session.updatedAt || \"unknown time\") + \"</div><h3>\" + escapeHtml(session.title || session.sessionId) + \"</h3><p class=\\\"path\\\">\" + escapeHtml(session.cwd || session.path) + \"</p></div><div class=\\\"token-big\\\">\" + fmtTokens(session.tokens) + \"</div></div>\" + categoryBar(session.categories) + \"<div class=\\\"session-grid\\\"><table><tbody>\" + cats + \"</tbody></table><div><div class=\\\"mini-label\\\">Frequent tools</div><div class=\\\"badges\\\">\" + (tools || \"<span class=\\\"muted-text\\\">none detected</span>\") + \"</div><div class=\\\"mini-label\\\">Repeated paths</div><div class=\\\"badges\\\">\" + (paths || \"<span class=\\\"muted-text\\\">none detected</span>\") + \"</div></div></div></article>\";\n }).join(\"\");\n const topTools = sortedEntries(agg.tools, 10).map((entry) => \"<tr><td>\" + escapeHtml(entry[0]) + \"</td><td>\" + entry[1] + \"</td></tr>\").join(\"\");\n const topPaths = sortedEntries(agg.paths, 10).map((entry) => \"<tr><td>\" + escapeHtml(entry[0]) + \"</td><td>\" + entry[1] + \"</td></tr>\").join(\"\");\n const sourceCounts = sessions.reduce((counts, s) => (counts[s.source] = (counts[s.source] || 0) + 1, counts), {});\n return \"<!doctype html><html><head><meta charset=\\\"utf-8\\\"><meta name=\\\"viewport\\\" content=\\\"width=device-width,initial-scale=1\\\"><title>Context X-Ray</title><style>\" +\n \"body{margin:0;background:#0e1116;color:#f3f5f8;font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;line-height:1.45}main{max-width:1180px;margin:0 auto;padding:32px 20px 56px}header{display:flex;justify-content:space-between;gap:24px;align-items:flex-end;margin-bottom:24px}h1{margin:0;font-size:clamp(28px,5vw,52px);letter-spacing:0}h2{margin:0 0 14px;font-size:18px}h3{margin:3px 0 4px;font-size:17px}p{margin:0}.muted,.path,.eyebrow,.muted-text{color:#9aa3ad}.eyebrow{text-transform:uppercase;letter-spacing:.08em;font-size:11px}.summary{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:12px;margin:18px 0}.card{background:linear-gradient(180deg,#151922,#1c2230);border:1px solid #2a3140;border-radius:8px;padding:16px;box-shadow:0 12px 40px rgba(0,0,0,.22)}.stat strong{display:block;font-size:28px;line-height:1.1}.grid{display:grid;grid-template-columns:minmax(0,1.5fr) minmax(280px,.8fr);gap:16px;align-items:start}.bar{display:flex;overflow:hidden;height:14px;border-radius:999px;background:#252b37;margin:12px 0}.bar span{display:block;min-width:2px}.tips li{margin:0 0 9px}.session{margin-top:14px}.session-head{display:flex;justify-content:space-between;gap:16px}.token-big{font-weight:700;font-size:28px;color:#8ba8ff;white-space:nowrap}.session-grid{display:grid;grid-template-columns:260px minmax(0,1fr);gap:14px;margin-top:12px}table{width:100%;border-collapse:collapse;font-size:13px}td{border-top:1px solid #2a3140;padding:7px 0;vertical-align:top}td:last-child{text-align:right;color:#9aa3ad}.mini-label{margin:7px 0 6px;font-size:11px;text-transform:uppercase;letter-spacing:.08em;color:#9aa3ad}.badges{display:flex;flex-wrap:wrap;gap:6px}.badge{display:inline-flex;border:1px solid #2a3140;border-radius:999px;padding:3px 8px;font-size:12px;background:rgba(255,255,255,.04)}.badge.muted{color:#9aa3ad}footer{color:#9aa3ad;margin-top:24px;font-size:12px}@media(max-width:840px){header,.grid,.session-grid{grid-template-columns:1fr;display:grid}.summary{grid-template-columns:repeat(2,minmax(0,1fr))}}\" +\n \"</style></head><body><main><header><div><div class=\\\"eyebrow\\\">Local coding context profile</div><h1>Context X-Ray</h1><p class=\\\"muted\\\">Generated \" + escapeHtml(new Date().toLocaleString()) + \" - mode=\" + escapeHtml(args.mode) + \" - source=\" + escapeHtml(args.source) + \" - since=\" + escapeHtml(args.since) + \"</p></div></header><section class=\\\"summary\\\"><div class=\\\"card stat\\\"><span class=\\\"muted\\\">Sessions</span><strong>\" + sessions.length + \"</strong></div><div class=\\\"card stat\\\"><span class=\\\"muted\\\">Observed/estimated tokens</span><strong>\" + fmtTokens(totalTokens) + \"</strong></div><div class=\\\"card stat\\\"><span class=\\\"muted\\\">Codex</span><strong>\" + (sourceCounts.codex || 0) + \"</strong></div><div class=\\\"card stat\\\"><span class=\\\"muted\\\">Claude</span><strong>\" + (sourceCounts.claude || 0) + \"</strong></div></section><section class=\\\"card\\\"><h2>Where The Context Is Going</h2>\" + categoryBar(agg.categories) + \"<table><tbody>\" + categoryRows + \"</tbody></table></section><div class=\\\"grid\\\" style=\\\"margin-top:16px\\\"><section class=\\\"card tips\\\"><h2>Warnings And Optimizations</h2><ol>\" + tips.map((tip) => \"<li>\" + escapeHtml(tip) + \"</li>\").join(\"\") + \"</ol></section><section class=\\\"card\\\"><h2>Hotspots</h2><div class=\\\"mini-label\\\">Top tools</div><table><tbody>\" + (topTools || \"<tr><td>None detected</td><td></td></tr>\") + \"</tbody></table><div class=\\\"mini-label\\\">Top paths</div><table><tbody>\" + (topPaths || \"<tr><td>None detected</td><td></td></tr>\") + \"</tbody></table></section></div><section style=\\\"margin-top:16px\\\"><h2>Sessions</h2>\" + sessionCards + \"</section><footer>Reads local transcript files only. No transcript content is uploaded.</footer></main></body></html>\";\n}\n\nfunction writeJson(sessions, args, file) {\n const agg = aggregate(sessions);\n fs.writeFileSync(file, JSON.stringify({\n generatedAt: new Date().toISOString(),\n mode: args.mode,\n source: args.source,\n since: args.since,\n totalTokens: sessions.reduce((sum, s) => sum + s.tokens, 0),\n categories: agg.categories,\n tools: sortedEntries(agg.tools, 25),\n paths: sortedEntries(agg.paths, 25),\n recommendations: recommendations(sessions),\n sessions,\n }, null, 2));\n}\n\nfunction openUrl(url) {\n const cmd = process.platform === \"darwin\" ? \"open\" : process.platform === \"win32\" ? \"cmd\" : \"xdg-open\";\n const args = process.platform === \"win32\" ? [\"/c\", \"start\", \"\", url] : [url];\n try {\n childProcess.spawn(cmd, args, { detached: true, stdio: \"ignore\" }).unref();\n } catch {}\n}\n\nfunction printSummary(sessions, args, file, url) {\n const total = sessions.reduce((sum, s) => sum + s.tokens, 0);\n console.log(\"Context X-Ray: analyzed \" + sessions.length + \" session(s), about \" + fmtTokens(total) + \" observed/estimated tokens.\");\n if (url) console.log(\"Open: \" + url);\n else console.log(\"Report: \" + file);\n console.log(\"\");\n for (const tip of recommendations(sessions).slice(0, 4)) console.log(\"- \" + tip);\n const tools = sortedEntries(aggregate(sessions).tools, 5);\n if (tools.length) console.log(\"- Frequent tools: \" + tools.map((entry) => entry[0] + \" x\" + entry[1]).join(\", \"));\n}\n\nfunction main() {\n const args = parseArgs(process.argv.slice(2));\n if (args.help) return help();\n const sessions = collectSessions(args);\n mkdirp(OUT_DIR);\n const suffix = args.format === \"json\" ? \"json\" : \"html\";\n const file = args.out || path.join(OUT_DIR, \"context-xray-\" + new Date().toISOString().replace(/[:.]/g, \"-\") + \".\" + suffix);\n mkdirp(path.dirname(file));\n if (args.format === \"json\") writeJson(sessions, args, file);\n else fs.writeFileSync(file, renderHtml(sessions, args));\n const url = args.open && args.format === \"html\" ? pathToFileURL(file).href : \"\";\n if (url) openUrl(url);\n printSummary(sessions, args, file, url);\n}\n\nmain();\n`;\n\nexport const CONTEXT_XRAY_SKILL_MD = `---\nname: context-xray\ndescription: >-\n Visualize local Codex and Claude Code context usage, open an inline/browser\n report, flag warnings, and suggest prompt/tooling optimizations. Use when the\n user types /context-xray, asks where context is going, wants recent local\n coding-agent trends, or wants to improve context efficiency.\nmetadata:\n visibility: exported\n---\n\n# Context X-Ray\n\nUse the locally installed Context X-Ray command to visualize recent Codex and\nClaude Code context usage. It reads local transcript files only and does not\nupload transcript content.\n\nProject-scoped installs write only project \\`.agents\\` skill and command\nartifacts; user-scoped installs write global Codex/Claude instructions.\n\n## Run\n\nCurrent or most recent local thread:\n\n\\`\\`\\`sh\n~/.agent-native/context-xray/context-xray --open\n\\`\\`\\`\n\nThread picker / recent sessions:\n\n\\`\\`\\`sh\n~/.agent-native/context-xray/context-xray threads --open\n\\`\\`\\`\n\nWeekly trends:\n\n\\`\\`\\`sh\n~/.agent-native/context-xray/context-xray trends --since 7d --open\n\\`\\`\\`\n\nExact session when the host exposes one:\n\n\\`\\`\\`sh\n~/.agent-native/context-xray/context-xray --session-id \"$CLAUDE_CODE_SESSION_ID\" --open\n\\`\\`\\`\n\nAfter running, report the link, the number of sessions analyzed, the largest\ncontext buckets, and 3-5 specific optimizations.\n\\`--open\\` opens the generated local HTML file directly and does not keep a\nbackground report server running.\n\n## Interpret\n\n- Tool output heavy: use narrower commands, smaller file ranges, and summarized\n logs.\n- Instructions heavy: move stable behavior into skills or AGENTS/CLAUDE files.\n- Assistant prose heavy: ask for shorter status updates during long runs.\n- One huge session: compact or start a follow-up thread with a handoff summary.\n- Repeated path: pin a short file-role summary instead of rereading the file.\n- Repeated tool: batch independent searches or delegate parallel inspection.\n`;\n\nexport const CONTEXT_XRAY_COMMAND_MD = `---\ndescription: Visualize local Codex/Claude context usage and get optimization tips.\nargument-hint: [current|threads|trends|--since 7d]\n---\n\nRun Context X-Ray locally and show the user the generated report link plus the\ntop warnings.\n\nChoose the command from the user's arguments:\n\n- No arguments or \\`current\\`:\n \\`~/.agent-native/context-xray/context-xray --open\\`\n- \\`threads\\`:\n \\`~/.agent-native/context-xray/context-xray threads --open\\`\n- \\`trends\\`:\n \\`~/.agent-native/context-xray/context-xray trends --since 7d --open\\`\n\nIf \\`$ARGUMENTS\\` includes flags such as \\`--since 24h\\`, \\`--last 20\\`, or\n\\`--all-projects\\`, pass them through to the command. If the host exposes\n\\`CLAUDE_CODE_SESSION_ID\\`, prefer:\n\n\\`\\`\\`sh\n~/.agent-native/context-xray/context-xray --session-id \"$CLAUDE_CODE_SESSION_ID\" --open\n\\`\\`\\`\n\n\\`--open\\` opens a local HTML report file directly; there should not be a\nlong-running server process to monitor.\n\nAfter the command finishes, summarize:\n\n- the report link\n- sessions analyzed\n- the largest context bucket\n- the most important warning\n- two or three concrete ways to improve this thread\n`;\n\nfunction codexHome(): string {\n return process.env.CODEX_HOME?.trim() || path.join(os.homedir(), \".codex\");\n}\n\nfunction writeExecutable(file: string, content: string): void {\n fs.mkdirSync(path.dirname(file), { recursive: true });\n fs.writeFileSync(file, content, \"utf-8\");\n fs.chmodSync(file, 0o755);\n}\n\nfunction writeFile(file: string, content: string, written: string[]): void {\n fs.mkdirSync(path.dirname(file), { recursive: true });\n fs.writeFileSync(file, content, \"utf-8\");\n written.push(file);\n}\n\nfunction installProjectArtifacts(baseDir: string, written: string[]): void {\n writeFile(\n path.join(baseDir, \".agents\", \"skills\", \"context-xray\", \"SKILL.md\"),\n CONTEXT_XRAY_SKILL_MD,\n written,\n );\n writeFile(\n path.join(baseDir, \".agents\", \"commands\", \"context-xray.md\"),\n CONTEXT_XRAY_COMMAND_MD,\n written,\n );\n}\n\nexport function installLocalContextXray(\n options: InstallLocalContextXrayOptions,\n): InstallLocalContextXrayResult {\n const installDir = path.join(os.homedir(), \".agent-native\", \"context-xray\");\n const scriptPath = path.join(installDir, \"context-xray\");\n const binPath = path.join(os.homedir(), \".local\", \"bin\", \"context-xray\");\n const written: string[] = [];\n\n if (options.dryRun) {\n return {\n commands: [\"context-xray --open\"],\n scriptPath,\n written,\n };\n }\n\n writeExecutable(scriptPath, CONTEXT_XRAY_EXECUTABLE);\n written.push(scriptPath);\n if (process.platform === \"win32\") {\n const cmdPath = `${binPath}.cmd`;\n writeExecutable(\n cmdPath,\n `@echo off\\r\\nnode ${JSON.stringify(scriptPath)} %*\\r\\n`,\n );\n written.push(cmdPath);\n } else {\n writeExecutable(\n binPath,\n `#!/usr/bin/env sh\\nexec ${JSON.stringify(scriptPath)} \"$@\"\\n`,\n );\n written.push(binPath);\n }\n\n const clientSet = new Set(options.clients);\n const wantsCodex = clientSet.has(\"codex\");\n const wantsClaude =\n clientSet.has(\"claude-code\") || clientSet.has(\"claude-code-cli\");\n\n if (options.scope === \"project\" && options.baseDir) {\n installProjectArtifacts(options.baseDir, written);\n } else if (wantsCodex) {\n writeFile(\n path.join(codexHome(), \"skills\", \"context-xray\", \"SKILL.md\"),\n CONTEXT_XRAY_SKILL_MD,\n written,\n );\n writeFile(\n path.join(codexHome(), \"commands\", \"context-xray.md\"),\n CONTEXT_XRAY_COMMAND_MD,\n written,\n );\n }\n\n if (options.scope !== \"project\" && wantsClaude) {\n writeFile(\n path.join(os.homedir(), \".claude\", \"skills\", \"context-xray\", \"SKILL.md\"),\n CONTEXT_XRAY_SKILL_MD,\n written,\n );\n writeFile(\n path.join(os.homedir(), \".claude\", \"commands\", \"context-xray.md\"),\n CONTEXT_XRAY_COMMAND_MD,\n written,\n );\n }\n\n return {\n commands: [\"context-xray --open\"],\n scriptPath,\n written,\n };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/cli/create.ts"],"names":[],"mappings":"AAKA,OAAO,EAAkB,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAuBvE;;;;;GAKG;AACH,qBAAa,eAAgB,SAAQ,KAAK;gBAC5B,OAAO,EAAE,MAAM;CAI5B;AA8BD,MAAM,WAAW,gBAAgB;IAC/B,iFAAiF;IACjF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iFAAiF;IACjF,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,0DAA0D;IAC1D,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;;;;;;;GAQG;AACH,wBAAsB,SAAS,CAC7B,IAAI,CAAC,EAAE,MAAM,EACb,IAAI,CAAC,EAAE,gBAAgB,GACtB,OAAO,CAAC,IAAI,CAAC,CA6Bf;AAgLD,iBAAe,qBAAqB,CAClC,SAAS,EAA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mB,EACzC,wBAAwB,IAAI,yBAAyB,EACrD,4BAA4B,IAAI,6BAA6B,EAC7D,oBAAoB,IAAI,qBAAqB,EAC7C,8BAA8B,IAAI,+BAA+B,EACjE,uBAAuB,IAAI,wBAAwB,EACnD,cAAc,IAAI,eAAe,GAClC,CAAC;AAcF,iBAAS,cAAc,CACrB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,OAAO,GAAE;IAAE,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAAO,GAC5C,MAAM,EAAE,CAQV;AA4ED;;;;;GAKG;AACH,iBAAS,WAAW,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA+B7C;AA8BD,iBAAS,kBAAkB,CACzB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,YAAY,CAAC,EAAE,MAAM,GACpB,IAAI,CAqBN;AA4BD,iBAAS,wBAAwB,IAAI,MAAM,CAW1C;AAED,iBAAS,4BAA4B,IAAI,MAAM,CAO9C;AAcD;;;;;;;;;;;GAWG;AACH,iBAAS,8BAA8B,IAAI,MAAM,EAAE,CASlD;AAED;;qDAEqD;AACrD,iBAAS,oBAAoB,IAAI,MAAM,CAEtC;AAoID,iBAAS,kBAAkB,CACzB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,YAAY,GAAG,WAAW,GAC/B,IAAI,CA0CN;AAqED,iBAAS,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAI1C;AAyED,iBAAS,uBAAuB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CA2BxE"}
@@ -1302,6 +1302,7 @@ function shouldSkipScaffoldEntry(name, srcPath) {
1302
1302
  name === ".agent-native" ||
1303
1303
  name === ".env" ||
1304
1304
  name === ".env.local" ||
1305
+ name === "pnpm-lock.yaml" ||
1305
1306
  name === ".netlify" ||
1306
1307
  name === ".vercel" ||
1307
1308
  name === ".generated" ||