@ikie-dev/cli 9.8.6 → 9.8.7

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 (28) hide show
  1. package/package.json +1 -1
  2. package/scripts/prepublish-npm.js +24 -8
  3. package/src/core/export-html/ansi-to-html.js +249 -0
  4. package/src/core/export-html/index.js +226 -0
  5. package/src/core/export-html/template.css +1066 -0
  6. package/src/core/export-html/template.html +66 -0
  7. package/src/core/export-html/template.js +1864 -0
  8. package/src/core/export-html/tool-renderer.js +108 -0
  9. package/src/core/export-html/vendor/highlight.min.js +1213 -0
  10. package/src/core/export-html/vendor/marked.min.js +6 -0
  11. package/src/modes/interactive/theme/catppuccin-macchiato.json +82 -0
  12. package/src/modes/interactive/theme/dark.json +87 -0
  13. package/src/modes/interactive/theme/dracula.json +79 -0
  14. package/src/modes/interactive/theme/github-dark.json +80 -0
  15. package/src/modes/interactive/theme/github-light.json +80 -0
  16. package/src/modes/interactive/theme/ikie-light.json +92 -0
  17. package/src/modes/interactive/theme/ikie-minimal.json +79 -0
  18. package/src/modes/interactive/theme/ikie.json +96 -0
  19. package/src/modes/interactive/theme/light.json +86 -0
  20. package/src/modes/interactive/theme/lucent-orng.json +79 -0
  21. package/src/modes/interactive/theme/monokai.json +78 -0
  22. package/src/modes/interactive/theme/neon.json +87 -0
  23. package/src/modes/interactive/theme/night-owl.json +87 -0
  24. package/src/modes/interactive/theme/nord.json +82 -0
  25. package/src/modes/interactive/theme/one-dark.json +79 -0
  26. package/src/modes/interactive/theme/solarized-dark.json +81 -0
  27. package/src/modes/interactive/theme/solarized-light.json +81 -0
  28. package/src/modes/interactive/theme/theme-schema.json +335 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ikie-dev/cli",
3
- "version": "9.8.6",
3
+ "version": "9.8.7",
4
4
  "description": "ikie \u2014 a coding agent CLI powered by ikie AI",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -2,10 +2,9 @@
2
2
  //
3
3
  // The published tarball needs:
4
4
  // - theme/dark.json, theme/light.json, theme/theme-schema.json
5
+ // - src/modes/interactive/theme/<same theme files> (upstream pi-coding-agent looks there)
6
+ // - src/core/export-html/<templates> (upstream pi-coding-agent looks there)
5
7
  // - package.json at the package root
6
- //
7
- // so that src/auxiliary-files/resolver.ts can find a valid PI_PACKAGE_DIR inside
8
- // the installed package (e.g. ~/.bun/install/global/node_modules/@ikie-dev/cli/).
9
8
 
10
9
  import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs"
11
10
  import { dirname, join } from "node:path"
@@ -13,21 +12,20 @@ import { fileURLToPath } from "node:url"
13
12
 
14
13
  const projectRoot = dirname(dirname(fileURLToPath(import.meta.url)))
15
14
 
16
- // Ensure upstream + custom themes are staged into src/modes/interactive/theme.
15
+ // Ensure upstream + custom themes and export-html templates are staged into src/.
17
16
  const copyResources = join(projectRoot, "scripts", "copy-resources.js")
18
17
  if (existsSync(copyResources)) {
19
18
  await import(copyResources)
20
19
  }
21
20
 
22
21
  const srcThemeDir = join(projectRoot, "src", "modes", "interactive", "theme")
23
- const destThemeDir = join(projectRoot, "theme")
24
-
25
22
  if (!existsSync(srcThemeDir)) {
26
23
  console.error(`Theme source directory not found: ${srcThemeDir}`)
27
24
  console.error("Run `node scripts/copy-resources.js --dev` first.")
28
25
  process.exit(1)
29
26
  }
30
27
 
28
+ const destThemeDir = join(projectRoot, "theme")
31
29
  mkdirSync(destThemeDir, { recursive: true })
32
30
 
33
31
  const requiredThemeFiles = ["dark.json", "light.json", "theme-schema.json"]
@@ -41,12 +39,13 @@ for (const file of requiredThemeFiles) {
41
39
  cpSync(src, dest)
42
40
  }
43
41
 
44
- // Also copy ikie custom themes so the published package has the full set.
42
+ // Also copy ikie custom themes to both locations.
45
43
  const customThemesSrc = join(projectRoot, "themes")
46
44
  if (existsSync(customThemesSrc)) {
47
45
  for (const file of readdirSync(customThemesSrc)) {
48
46
  if (file.endsWith(".json")) {
49
47
  cpSync(join(customThemesSrc, file), join(destThemeDir, file))
48
+ cpSync(join(customThemesSrc, file), join(srcThemeDir, file))
50
49
  }
51
50
  }
52
51
  }
@@ -57,4 +56,21 @@ if (!existsSync(join(projectRoot, "package.json"))) {
57
56
  process.exit(1)
58
57
  }
59
58
 
60
- console.log(`Published theme dir ready: ${destThemeDir}`)
59
+ // Generate an .npmignore that does NOT exclude the generated asset directories,
60
+ // because npm falls back to .gitignore when .npmignore is absent, and .gitignore
61
+ // excludes the very files the published package needs at runtime.
62
+ const gitignorePath = join(projectRoot, ".gitignore")
63
+ if (existsSync(gitignorePath)) {
64
+ const gitignore = readFileSync(gitignorePath, "utf-8")
65
+ const npmignore = gitignore
66
+ .split("\n")
67
+ .filter((line) => {
68
+ const trimmed = line.trim()
69
+ // Keep the generated asset directories in the published tarball.
70
+ return trimmed !== "src/modes/interactive/theme/" && trimmed !== "src/core/export-html/"
71
+ })
72
+ .join("\n")
73
+ writeFileSync(join(projectRoot, ".npmignore"), npmignore)
74
+ }
75
+
76
+ console.log(`Published theme dirs ready: ${destThemeDir} and ${srcThemeDir}`)
@@ -0,0 +1,249 @@
1
+ /**
2
+ * ANSI escape code to HTML converter.
3
+ *
4
+ * Converts terminal ANSI color/style codes to HTML with inline styles.
5
+ * Supports:
6
+ * - Standard foreground colors (30-37) and bright variants (90-97)
7
+ * - Standard background colors (40-47) and bright variants (100-107)
8
+ * - 256-color palette (38;5;N and 48;5;N)
9
+ * - RGB true color (38;2;R;G;B and 48;2;R;G;B)
10
+ * - Text styles: bold (1), dim (2), italic (3), underline (4)
11
+ * - Reset (0)
12
+ */
13
+ // Standard ANSI color palette (0-15)
14
+ const ANSI_COLORS = [
15
+ "#000000", // 0: black
16
+ "#800000", // 1: red
17
+ "#008000", // 2: green
18
+ "#808000", // 3: yellow
19
+ "#000080", // 4: blue
20
+ "#800080", // 5: magenta
21
+ "#008080", // 6: cyan
22
+ "#c0c0c0", // 7: white
23
+ "#808080", // 8: bright black
24
+ "#ff0000", // 9: bright red
25
+ "#00ff00", // 10: bright green
26
+ "#ffff00", // 11: bright yellow
27
+ "#0000ff", // 12: bright blue
28
+ "#ff00ff", // 13: bright magenta
29
+ "#00ffff", // 14: bright cyan
30
+ "#ffffff", // 15: bright white
31
+ ];
32
+ /**
33
+ * Convert 256-color index to hex.
34
+ */
35
+ function color256ToHex(index) {
36
+ // Standard colors (0-15)
37
+ if (index < 16) {
38
+ return ANSI_COLORS[index];
39
+ }
40
+ // Color cube (16-231): 6x6x6 = 216 colors
41
+ if (index < 232) {
42
+ const cubeIndex = index - 16;
43
+ const r = Math.floor(cubeIndex / 36);
44
+ const g = Math.floor((cubeIndex % 36) / 6);
45
+ const b = cubeIndex % 6;
46
+ const toComponent = (n) => (n === 0 ? 0 : 55 + n * 40);
47
+ const toHex = (n) => toComponent(n).toString(16).padStart(2, "0");
48
+ return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
49
+ }
50
+ // Grayscale (232-255): 24 shades
51
+ const gray = 8 + (index - 232) * 10;
52
+ const grayHex = gray.toString(16).padStart(2, "0");
53
+ return `#${grayHex}${grayHex}${grayHex}`;
54
+ }
55
+ /**
56
+ * Escape HTML special characters.
57
+ */
58
+ function escapeHtml(text) {
59
+ return text
60
+ .replace(/&/g, "&amp;")
61
+ .replace(/</g, "&lt;")
62
+ .replace(/>/g, "&gt;")
63
+ .replace(/"/g, "&quot;")
64
+ .replace(/'/g, "&#039;");
65
+ }
66
+ function createEmptyStyle() {
67
+ return {
68
+ fg: null,
69
+ bg: null,
70
+ bold: false,
71
+ dim: false,
72
+ italic: false,
73
+ underline: false,
74
+ };
75
+ }
76
+ function styleToInlineCSS(style) {
77
+ const parts = [];
78
+ if (style.fg)
79
+ parts.push(`color:${style.fg}`);
80
+ if (style.bg)
81
+ parts.push(`background-color:${style.bg}`);
82
+ if (style.bold)
83
+ parts.push("font-weight:bold");
84
+ if (style.dim)
85
+ parts.push("opacity:0.6");
86
+ if (style.italic)
87
+ parts.push("font-style:italic");
88
+ if (style.underline)
89
+ parts.push("text-decoration:underline");
90
+ return parts.join(";");
91
+ }
92
+ function hasStyle(style) {
93
+ return style.fg !== null || style.bg !== null || style.bold || style.dim || style.italic || style.underline;
94
+ }
95
+ /**
96
+ * Parse ANSI SGR (Select Graphic Rendition) codes and update style.
97
+ */
98
+ function applySgrCode(params, style) {
99
+ let i = 0;
100
+ while (i < params.length) {
101
+ const code = params[i];
102
+ if (code === 0) {
103
+ // Reset all
104
+ style.fg = null;
105
+ style.bg = null;
106
+ style.bold = false;
107
+ style.dim = false;
108
+ style.italic = false;
109
+ style.underline = false;
110
+ }
111
+ else if (code === 1) {
112
+ style.bold = true;
113
+ }
114
+ else if (code === 2) {
115
+ style.dim = true;
116
+ }
117
+ else if (code === 3) {
118
+ style.italic = true;
119
+ }
120
+ else if (code === 4) {
121
+ style.underline = true;
122
+ }
123
+ else if (code === 22) {
124
+ // Reset bold/dim
125
+ style.bold = false;
126
+ style.dim = false;
127
+ }
128
+ else if (code === 23) {
129
+ style.italic = false;
130
+ }
131
+ else if (code === 24) {
132
+ style.underline = false;
133
+ }
134
+ else if (code >= 30 && code <= 37) {
135
+ // Standard foreground colors
136
+ style.fg = ANSI_COLORS[code - 30];
137
+ }
138
+ else if (code === 38) {
139
+ // Extended foreground color
140
+ if (params[i + 1] === 5 && params.length > i + 2) {
141
+ // 256-color: 38;5;N
142
+ style.fg = color256ToHex(params[i + 2]);
143
+ i += 2;
144
+ }
145
+ else if (params[i + 1] === 2 && params.length > i + 4) {
146
+ // RGB: 38;2;R;G;B
147
+ const r = params[i + 2];
148
+ const g = params[i + 3];
149
+ const b = params[i + 4];
150
+ style.fg = `rgb(${r},${g},${b})`;
151
+ i += 4;
152
+ }
153
+ }
154
+ else if (code === 39) {
155
+ // Default foreground
156
+ style.fg = null;
157
+ }
158
+ else if (code >= 40 && code <= 47) {
159
+ // Standard background colors
160
+ style.bg = ANSI_COLORS[code - 40];
161
+ }
162
+ else if (code === 48) {
163
+ // Extended background color
164
+ if (params[i + 1] === 5 && params.length > i + 2) {
165
+ // 256-color: 48;5;N
166
+ style.bg = color256ToHex(params[i + 2]);
167
+ i += 2;
168
+ }
169
+ else if (params[i + 1] === 2 && params.length > i + 4) {
170
+ // RGB: 48;2;R;G;B
171
+ const r = params[i + 2];
172
+ const g = params[i + 3];
173
+ const b = params[i + 4];
174
+ style.bg = `rgb(${r},${g},${b})`;
175
+ i += 4;
176
+ }
177
+ }
178
+ else if (code === 49) {
179
+ // Default background
180
+ style.bg = null;
181
+ }
182
+ else if (code >= 90 && code <= 97) {
183
+ // Bright foreground colors
184
+ style.fg = ANSI_COLORS[code - 90 + 8];
185
+ }
186
+ else if (code >= 100 && code <= 107) {
187
+ // Bright background colors
188
+ style.bg = ANSI_COLORS[code - 100 + 8];
189
+ }
190
+ // Ignore unrecognized codes
191
+ i++;
192
+ }
193
+ }
194
+ // Match ANSI escape sequences: ESC[ followed by params and ending with 'm'
195
+ const ANSI_REGEX = /\x1b\[([\d;]*)m/g;
196
+ /**
197
+ * Convert ANSI-escaped text to HTML with inline styles.
198
+ */
199
+ export function ansiToHtml(text) {
200
+ const style = createEmptyStyle();
201
+ let result = "";
202
+ let lastIndex = 0;
203
+ let inSpan = false;
204
+ // Reset regex state
205
+ ANSI_REGEX.lastIndex = 0;
206
+ let match = ANSI_REGEX.exec(text);
207
+ while (match !== null) {
208
+ // Add text before this escape sequence
209
+ const beforeText = text.slice(lastIndex, match.index);
210
+ if (beforeText) {
211
+ result += escapeHtml(beforeText);
212
+ }
213
+ // Parse SGR parameters
214
+ const paramStr = match[1];
215
+ const params = paramStr ? paramStr.split(";").map((p) => parseInt(p, 10) || 0) : [0];
216
+ // Close existing span if we have one
217
+ if (inSpan) {
218
+ result += "</span>";
219
+ inSpan = false;
220
+ }
221
+ // Apply the codes
222
+ applySgrCode(params, style);
223
+ // Open new span if we have any styling
224
+ if (hasStyle(style)) {
225
+ result += `<span style="${styleToInlineCSS(style)}">`;
226
+ inSpan = true;
227
+ }
228
+ lastIndex = match.index + match[0].length;
229
+ match = ANSI_REGEX.exec(text);
230
+ }
231
+ // Add remaining text
232
+ const remainingText = text.slice(lastIndex);
233
+ if (remainingText) {
234
+ result += escapeHtml(remainingText);
235
+ }
236
+ // Close any open span
237
+ if (inSpan) {
238
+ result += "</span>";
239
+ }
240
+ return result;
241
+ }
242
+ /**
243
+ * Convert array of ANSI-escaped lines to HTML.
244
+ * Each line is wrapped in a div element.
245
+ */
246
+ export function ansiLinesToHtml(lines) {
247
+ return lines.map((line) => `<div class="ansi-line">${ansiToHtml(line) || "&nbsp;"}</div>`).join("");
248
+ }
249
+ //# sourceMappingURL=ansi-to-html.js.map
@@ -0,0 +1,226 @@
1
+ import { existsSync, readFileSync, writeFileSync } from "fs";
2
+ import { basename, join } from "path";
3
+ import { APP_NAME, getExportTemplateDir } from "../../config.js";
4
+ import { getResolvedThemeColors, getThemeExportColors } from "../../modes/interactive/theme/theme.js";
5
+ import { normalizePath, resolvePath } from "../../utils/paths.js";
6
+ import { SessionManager } from "../session-manager.js";
7
+ /** Parse a color string to RGB values. Supports hex (#RRGGBB) and rgb(r,g,b) formats. */
8
+ function parseColor(color) {
9
+ const hexMatch = color.match(/^#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/);
10
+ if (hexMatch) {
11
+ return {
12
+ r: Number.parseInt(hexMatch[1], 16),
13
+ g: Number.parseInt(hexMatch[2], 16),
14
+ b: Number.parseInt(hexMatch[3], 16),
15
+ };
16
+ }
17
+ const rgbMatch = color.match(/^rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/);
18
+ if (rgbMatch) {
19
+ return {
20
+ r: Number.parseInt(rgbMatch[1], 10),
21
+ g: Number.parseInt(rgbMatch[2], 10),
22
+ b: Number.parseInt(rgbMatch[3], 10),
23
+ };
24
+ }
25
+ return undefined;
26
+ }
27
+ /** Calculate relative luminance of a color (0-1, higher = lighter). */
28
+ function getLuminance(r, g, b) {
29
+ const toLinear = (c) => {
30
+ const s = c / 255;
31
+ return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
32
+ };
33
+ return 0.2126 * toLinear(r) + 0.7152 * toLinear(g) + 0.0722 * toLinear(b);
34
+ }
35
+ /** Adjust color brightness. Factor > 1 lightens, < 1 darkens. */
36
+ function adjustBrightness(color, factor) {
37
+ const parsed = parseColor(color);
38
+ if (!parsed)
39
+ return color;
40
+ const adjust = (c) => Math.min(255, Math.max(0, Math.round(c * factor)));
41
+ return `rgb(${adjust(parsed.r)}, ${adjust(parsed.g)}, ${adjust(parsed.b)})`;
42
+ }
43
+ /** Derive export background colors from a base color (e.g., userMessageBg). */
44
+ function deriveExportColors(baseColor) {
45
+ const parsed = parseColor(baseColor);
46
+ if (!parsed) {
47
+ return {
48
+ pageBg: "rgb(24, 24, 30)",
49
+ cardBg: "rgb(30, 30, 36)",
50
+ infoBg: "rgb(60, 55, 40)",
51
+ };
52
+ }
53
+ const luminance = getLuminance(parsed.r, parsed.g, parsed.b);
54
+ const isLight = luminance > 0.5;
55
+ if (isLight) {
56
+ return {
57
+ pageBg: adjustBrightness(baseColor, 0.96),
58
+ cardBg: baseColor,
59
+ infoBg: `rgb(${Math.min(255, parsed.r + 10)}, ${Math.min(255, parsed.g + 5)}, ${Math.max(0, parsed.b - 20)})`,
60
+ };
61
+ }
62
+ return {
63
+ pageBg: adjustBrightness(baseColor, 0.7),
64
+ cardBg: adjustBrightness(baseColor, 0.85),
65
+ infoBg: `rgb(${Math.min(255, parsed.r + 20)}, ${Math.min(255, parsed.g + 15)}, ${parsed.b})`,
66
+ };
67
+ }
68
+ /**
69
+ * Generate CSS custom property declarations from theme colors.
70
+ */
71
+ function generateThemeVars(themeName) {
72
+ const colors = getResolvedThemeColors(themeName);
73
+ const lines = [];
74
+ for (const [key, value] of Object.entries(colors)) {
75
+ lines.push(`--${key}: ${value};`);
76
+ }
77
+ // Use explicit theme export colors if available, otherwise derive from userMessageBg
78
+ const themeExport = getThemeExportColors(themeName);
79
+ const userMessageBg = colors.userMessageBg || "#343541";
80
+ const derivedColors = deriveExportColors(userMessageBg);
81
+ lines.push(`--exportPageBg: ${themeExport.pageBg ?? derivedColors.pageBg};`);
82
+ lines.push(`--exportCardBg: ${themeExport.cardBg ?? derivedColors.cardBg};`);
83
+ lines.push(`--exportInfoBg: ${themeExport.infoBg ?? derivedColors.infoBg};`);
84
+ return lines.join("\n ");
85
+ }
86
+ /**
87
+ * Core HTML generation logic shared by both export functions.
88
+ */
89
+ function generateHtml(sessionData, themeName) {
90
+ const templateDir = getExportTemplateDir();
91
+ const template = readFileSync(join(templateDir, "template.html"), "utf-8");
92
+ const templateCss = readFileSync(join(templateDir, "template.css"), "utf-8");
93
+ const templateJs = readFileSync(join(templateDir, "template.js"), "utf-8");
94
+ const markedJs = readFileSync(join(templateDir, "vendor", "marked.min.js"), "utf-8");
95
+ const hljsJs = readFileSync(join(templateDir, "vendor", "highlight.min.js"), "utf-8");
96
+ const themeVars = generateThemeVars(themeName);
97
+ const colors = getResolvedThemeColors(themeName);
98
+ const themeExport = getThemeExportColors(themeName);
99
+ const derivedExportColors = deriveExportColors(colors.userMessageBg || "#343541");
100
+ const bodyBg = themeExport.pageBg ?? derivedExportColors.pageBg;
101
+ const containerBg = themeExport.cardBg ?? derivedExportColors.cardBg;
102
+ const infoBg = themeExport.infoBg ?? derivedExportColors.infoBg;
103
+ // Base64 encode session data to avoid escaping issues
104
+ const sessionDataBase64 = Buffer.from(JSON.stringify(sessionData)).toString("base64");
105
+ // Build the CSS with theme variables injected
106
+ const css = templateCss
107
+ .replace("{{THEME_VARS}}", themeVars)
108
+ .replace("{{BODY_BG}}", bodyBg)
109
+ .replace("{{CONTAINER_BG}}", containerBg)
110
+ .replace("{{INFO_BG}}", infoBg);
111
+ return template
112
+ .replace("{{CSS}}", css)
113
+ .replace("{{JS}}", templateJs)
114
+ .replace("{{SESSION_DATA}}", sessionDataBase64)
115
+ .replace("{{MARKED_JS}}", markedJs)
116
+ .replace("{{HIGHLIGHT_JS}}", hljsJs);
117
+ }
118
+ /** Tools rendered directly by the HTML template (not pre-rendered via TUI→ANSI→HTML pipeline) */
119
+ const TEMPLATE_RENDERED_TOOLS = new Set(["bash", "read", "write", "edit", "ls"]);
120
+ /**
121
+ * Pre-render custom tools to HTML using their TUI renderers.
122
+ */
123
+ function preRenderCustomTools(entries, toolRenderer) {
124
+ const renderedTools = {};
125
+ for (const entry of entries) {
126
+ if (entry.type !== "message")
127
+ continue;
128
+ const msg = entry.message;
129
+ // Find tool calls in assistant messages
130
+ if (msg.role === "assistant" && Array.isArray(msg.content)) {
131
+ for (const block of msg.content) {
132
+ if (block.type === "toolCall" && !TEMPLATE_RENDERED_TOOLS.has(block.name)) {
133
+ const callHtml = toolRenderer.renderCall(block.id, block.name, block.arguments);
134
+ if (callHtml) {
135
+ renderedTools[block.id] = { callHtml };
136
+ }
137
+ }
138
+ }
139
+ }
140
+ // Find tool results
141
+ if (msg.role === "toolResult" && msg.toolCallId) {
142
+ const toolName = msg.toolName || "";
143
+ // Only render if we have a pre-rendered call OR it's not template-rendered
144
+ const existing = renderedTools[msg.toolCallId];
145
+ if (existing || !TEMPLATE_RENDERED_TOOLS.has(toolName)) {
146
+ const rendered = toolRenderer.renderResult(msg.toolCallId, toolName, msg.content, msg.details, msg.isError || false);
147
+ if (rendered) {
148
+ renderedTools[msg.toolCallId] = {
149
+ ...existing,
150
+ resultHtmlCollapsed: rendered.collapsed,
151
+ resultHtmlExpanded: rendered.expanded,
152
+ };
153
+ }
154
+ }
155
+ }
156
+ }
157
+ return renderedTools;
158
+ }
159
+ /**
160
+ * Export session to HTML using SessionManager and AgentState.
161
+ * Used by TUI's /export command.
162
+ */
163
+ export async function exportSessionToHtml(sm, state, options) {
164
+ const opts = typeof options === "string" ? { outputPath: options } : options || {};
165
+ const sessionFile = sm.getSessionFile();
166
+ if (!sessionFile) {
167
+ throw new Error("Cannot export in-memory session to HTML");
168
+ }
169
+ if (!existsSync(sessionFile)) {
170
+ throw new Error("Nothing to export yet - start a conversation first");
171
+ }
172
+ const entries = sm.getEntries();
173
+ // Pre-render custom tools if a tool renderer is provided
174
+ let renderedTools;
175
+ if (opts.toolRenderer) {
176
+ renderedTools = preRenderCustomTools(entries, opts.toolRenderer);
177
+ // Only include if we actually rendered something
178
+ if (Object.keys(renderedTools).length === 0) {
179
+ renderedTools = undefined;
180
+ }
181
+ }
182
+ const sessionData = {
183
+ header: sm.getHeader(),
184
+ entries,
185
+ leafId: sm.getLeafId(),
186
+ systemPrompt: state?.systemPrompt,
187
+ tools: state?.tools?.map((t) => ({ name: t.name, description: t.description, parameters: t.parameters })),
188
+ renderedTools,
189
+ };
190
+ const html = generateHtml(sessionData, opts.themeName);
191
+ let outputPath = opts.outputPath ? normalizePath(opts.outputPath) : undefined;
192
+ if (!outputPath) {
193
+ const sessionBasename = basename(sessionFile, ".jsonl");
194
+ outputPath = `${APP_NAME}-session-${sessionBasename}.html`;
195
+ }
196
+ writeFileSync(outputPath, html, "utf8");
197
+ return outputPath;
198
+ }
199
+ /**
200
+ * Export session file to HTML (standalone, without AgentState).
201
+ * Used by CLI for exporting arbitrary session files.
202
+ */
203
+ export async function exportFromFile(inputPath, options) {
204
+ const opts = typeof options === "string" ? { outputPath: options } : options || {};
205
+ const resolvedInputPath = resolvePath(inputPath);
206
+ if (!existsSync(resolvedInputPath)) {
207
+ throw new Error(`File not found: ${resolvedInputPath}`);
208
+ }
209
+ const sm = SessionManager.open(resolvedInputPath);
210
+ const sessionData = {
211
+ header: sm.getHeader(),
212
+ entries: sm.getEntries(),
213
+ leafId: sm.getLeafId(),
214
+ systemPrompt: undefined,
215
+ tools: undefined,
216
+ };
217
+ const html = generateHtml(sessionData, opts.themeName);
218
+ let outputPath = opts.outputPath ? normalizePath(opts.outputPath) : undefined;
219
+ if (!outputPath) {
220
+ const inputBasename = basename(resolvedInputPath, ".jsonl");
221
+ outputPath = `${APP_NAME}-session-${inputBasename}.html`;
222
+ }
223
+ writeFileSync(outputPath, html, "utf8");
224
+ return outputPath;
225
+ }
226
+ //# sourceMappingURL=index.js.map