@tomsun28/pizza 0.1.0 → 0.1.1
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/README.md +20 -143
- package/README.zh-CN.md +36 -0
- package/dist/bun/cli.d.ts +2 -0
- package/dist/bun/cli.js +6 -0
- package/dist/bun/register-bedrock.d.ts +1 -0
- package/dist/bun/register-bedrock.js +3 -0
- package/dist/cli/args.d.ts +48 -0
- package/dist/cli/args.js +330 -0
- package/dist/cli/config-selector.d.ts +13 -0
- package/dist/cli/config-selector.js +30 -0
- package/dist/cli/file-processor.d.ts +14 -0
- package/dist/cli/file-processor.js +82 -0
- package/dist/cli/initial-message.d.ts +17 -0
- package/dist/cli/initial-message.js +21 -0
- package/dist/cli/list-models.d.ts +8 -0
- package/dist/cli/list-models.js +96 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +68 -0
- package/dist/config.d.ts +79 -0
- package/dist/config.js +223 -0
- package/dist/core/agent/index.d.ts +6 -0
- package/dist/core/agent/index.js +6 -0
- package/dist/core/agent/types.d.ts +202 -0
- package/dist/core/agent/types.js +51 -0
- package/dist/core/auth-storage.d.ts +135 -0
- package/dist/core/auth-storage.js +417 -0
- package/dist/core/bash-executor.d.ts +31 -0
- package/dist/core/bash-executor.js +107 -0
- package/dist/core/compaction/branch-summarization.d.ts +87 -0
- package/dist/core/compaction/branch-summarization.js +242 -0
- package/dist/core/compaction/compaction-engine.d.ts +40 -0
- package/dist/core/compaction/compaction-engine.js +292 -0
- package/dist/core/compaction/compaction.d.ts +106 -0
- package/dist/core/compaction/compaction.js +295 -0
- package/dist/core/compaction/index.d.ts +7 -0
- package/dist/core/compaction/index.js +7 -0
- package/dist/core/compaction/utils.d.ts +37 -0
- package/dist/core/compaction/utils.js +152 -0
- package/dist/core/defaults.d.ts +2 -0
- package/dist/core/defaults.js +1 -0
- package/dist/core/diagnostics.d.ts +14 -0
- package/dist/core/diagnostics.js +1 -0
- package/dist/core/event-bus.d.ts +8 -0
- package/dist/core/event-bus.js +24 -0
- package/dist/core/event-store/events.d.ts +465 -0
- package/dist/core/event-store/events.js +6 -0
- package/dist/core/event-store/index.d.ts +10 -0
- package/dist/core/event-store/index.js +10 -0
- package/dist/core/event-store/sqlite-store.d.ts +27 -0
- package/dist/core/event-store/sqlite-store.js +275 -0
- package/dist/core/event-store/store.d.ts +91 -0
- package/dist/core/event-store/store.js +7 -0
- package/dist/core/event-store/thread-scoped-store.d.ts +29 -0
- package/dist/core/event-store/thread-scoped-store.js +50 -0
- package/dist/core/event-store/types.d.ts +70 -0
- package/dist/core/event-store/types.js +7 -0
- package/dist/core/event-store/workspace.d.ts +37 -0
- package/dist/core/event-store/workspace.js +71 -0
- package/dist/core/exec.d.ts +28 -0
- package/dist/core/exec.js +74 -0
- package/dist/core/export-html/ansi-to-html.d.ts +21 -0
- package/dist/core/export-html/ansi-to-html.js +248 -0
- package/dist/core/export-html/index.d.ts +29 -0
- package/dist/core/export-html/index.js +186 -0
- package/dist/core/export-html/template.css +1017 -0
- package/dist/core/export-html/template.html +55 -0
- package/dist/core/export-html/template.js +1742 -0
- package/dist/core/export-html/tool-renderer.d.ts +39 -0
- package/dist/core/export-html/tool-renderer.js +94 -0
- package/dist/core/export-html/vendor/highlight.min.js +1213 -0
- package/dist/core/export-html/vendor/marked.min.js +6 -0
- package/dist/core/extensions/index.d.ts +12 -0
- package/dist/core/extensions/index.js +9 -0
- package/dist/core/extensions/loader.d.ts +24 -0
- package/dist/core/extensions/loader.js +492 -0
- package/dist/core/extensions/runner.d.ts +167 -0
- package/dist/core/extensions/runner.js +898 -0
- package/dist/core/extensions/session-context.d.ts +67 -0
- package/dist/core/extensions/session-context.js +272 -0
- package/dist/core/extensions/types.d.ts +1147 -0
- package/dist/core/extensions/types.js +44 -0
- package/dist/core/extensions/wrapper.d.ts +19 -0
- package/dist/core/extensions/wrapper.js +21 -0
- package/dist/core/footer-data-provider.d.ts +47 -0
- package/dist/core/footer-data-provider.js +321 -0
- package/dist/core/goal/index.d.ts +3 -0
- package/dist/core/goal/index.js +1 -0
- package/dist/core/goal/scheduler.d.ts +83 -0
- package/dist/core/goal/scheduler.js +154 -0
- package/dist/core/goal/types.d.ts +182 -0
- package/dist/core/goal/types.js +11 -0
- package/dist/core/index.d.ts +8 -0
- package/dist/core/index.js +8 -0
- package/dist/core/intent/classifier.d.ts +53 -0
- package/dist/core/intent/classifier.js +353 -0
- package/dist/core/intent/index.d.ts +8 -0
- package/dist/core/intent/index.js +8 -0
- package/dist/core/intent/tool-adapter.d.ts +31 -0
- package/dist/core/intent/tool-adapter.js +168 -0
- package/dist/core/intent/types.d.ts +71 -0
- package/dist/core/intent/types.js +6 -0
- package/dist/core/keybindings.d.ts +297 -0
- package/dist/core/keybindings.js +250 -0
- package/dist/core/messages.d.ts +30 -0
- package/dist/core/messages.js +134 -0
- package/dist/core/model-registry.d.ts +131 -0
- package/dist/core/model-registry.js +634 -0
- package/dist/core/model-resolver.d.ts +109 -0
- package/dist/core/model-resolver.js +486 -0
- package/dist/core/output-guard.d.ts +5 -0
- package/dist/core/output-guard.js +58 -0
- package/dist/core/package-manager.d.ts +196 -0
- package/dist/core/package-manager.js +1873 -0
- package/dist/core/projection/boundary-inferrer.d.ts +58 -0
- package/dist/core/projection/boundary-inferrer.js +122 -0
- package/dist/core/projection/event-to-message.d.ts +35 -0
- package/dist/core/projection/event-to-message.js +253 -0
- package/dist/core/projection/goal-projection.d.ts +67 -0
- package/dist/core/projection/goal-projection.js +339 -0
- package/dist/core/projection/index.d.ts +13 -0
- package/dist/core/projection/index.js +13 -0
- package/dist/core/projection/session-manager.d.ts +100 -0
- package/dist/core/projection/session-manager.js +331 -0
- package/dist/core/projection/session-projection.d.ts +58 -0
- package/dist/core/projection/session-projection.js +257 -0
- package/dist/core/projection/task-history.d.ts +13 -0
- package/dist/core/projection/task-history.js +61 -0
- package/dist/core/projection/timeline-projection.d.ts +82 -0
- package/dist/core/projection/timeline-projection.js +276 -0
- package/dist/core/projection/types.d.ts +69 -0
- package/dist/core/projection/types.js +6 -0
- package/dist/core/prompt-templates.d.ts +51 -0
- package/dist/core/prompt-templates.js +249 -0
- package/dist/core/resolve-config-value.d.ts +22 -0
- package/dist/core/resolve-config-value.js +125 -0
- package/dist/core/resource-loader.d.ts +193 -0
- package/dist/core/resource-loader.js +685 -0
- package/dist/core/runtime/ai-client.d.ts +12 -0
- package/dist/core/runtime/ai-client.js +153 -0
- package/dist/core/runtime/checkpoint.d.ts +12 -0
- package/dist/core/runtime/checkpoint.js +78 -0
- package/dist/core/runtime/index.d.ts +12 -0
- package/dist/core/runtime/index.js +12 -0
- package/dist/core/runtime/llm-types.d.ts +99 -0
- package/dist/core/runtime/llm-types.js +6 -0
- package/dist/core/runtime/local-runtime.d.ts +23 -0
- package/dist/core/runtime/local-runtime.js +59 -0
- package/dist/core/runtime/policies.d.ts +72 -0
- package/dist/core/runtime/policies.js +37 -0
- package/dist/core/runtime/reactor.d.ts +213 -0
- package/dist/core/runtime/reactor.js +992 -0
- package/dist/core/runtime/runtime.d.ts +191 -0
- package/dist/core/runtime/runtime.js +449 -0
- package/dist/core/runtime/types.d.ts +42 -0
- package/dist/core/runtime/types.js +1 -0
- package/dist/core/sdk.d.ts +12 -0
- package/dist/core/sdk.js +10 -0
- package/dist/core/session-context-builder.d.ts +9 -0
- package/dist/core/session-context-builder.js +87 -0
- package/dist/core/session-cwd.d.ts +18 -0
- package/dist/core/session-cwd.js +36 -0
- package/dist/core/session-facade-factory.d.ts +79 -0
- package/dist/core/session-facade-factory.js +460 -0
- package/dist/core/session-facade.d.ts +57 -0
- package/dist/core/session-facade.js +91 -0
- package/dist/core/session-listing.d.ts +30 -0
- package/dist/core/session-listing.js +168 -0
- package/dist/core/session-reader.d.ts +19 -0
- package/dist/core/session-reader.js +101 -0
- package/dist/core/session-ref.d.ts +7 -0
- package/dist/core/session-ref.js +25 -0
- package/dist/core/session-services.d.ts +51 -0
- package/dist/core/session-services.js +90 -0
- package/dist/core/session-stats.d.ts +43 -0
- package/dist/core/session-stats.js +41 -0
- package/dist/core/settings-manager.d.ts +236 -0
- package/dist/core/settings-manager.js +706 -0
- package/dist/core/skill-block-parser.d.ts +12 -0
- package/dist/core/skill-block-parser.js +15 -0
- package/dist/core/skills.d.ts +59 -0
- package/dist/core/skills.js +408 -0
- package/dist/core/slash-commands.d.ts +13 -0
- package/dist/core/slash-commands.js +17 -0
- package/dist/core/source-info.d.ts +17 -0
- package/dist/core/source-info.js +18 -0
- package/dist/core/system-prompt.d.ts +27 -0
- package/dist/core/system-prompt.js +179 -0
- package/dist/core/timings.d.ts +7 -0
- package/dist/core/timings.js +30 -0
- package/dist/core/tools/bash.d.ts +95 -0
- package/dist/core/tools/bash.js +513 -0
- package/dist/core/tools/builtin-commands.d.ts +75 -0
- package/dist/core/tools/builtin-commands.js +503 -0
- package/dist/core/tools/compat-commands.d.ts +12 -0
- package/dist/core/tools/compat-commands.js +1280 -0
- package/dist/core/tools/edit-diff.d.ts +59 -0
- package/dist/core/tools/edit-diff.js +263 -0
- package/dist/core/tools/edit.d.ts +49 -0
- package/dist/core/tools/edit.js +340 -0
- package/dist/core/tools/file-mutation-queue.d.ts +5 -0
- package/dist/core/tools/file-mutation-queue.js +36 -0
- package/dist/core/tools/find.d.ts +34 -0
- package/dist/core/tools/find.js +459 -0
- package/dist/core/tools/grep.d.ts +36 -0
- package/dist/core/tools/grep.js +422 -0
- package/dist/core/tools/index.d.ts +70 -0
- package/dist/core/tools/index.js +129 -0
- package/dist/core/tools/line-anchors.d.ts +33 -0
- package/dist/core/tools/line-anchors.js +151 -0
- package/dist/core/tools/ls.d.ts +36 -0
- package/dist/core/tools/ls.js +268 -0
- package/dist/core/tools/path-utils.d.ts +7 -0
- package/dist/core/tools/path-utils.js +80 -0
- package/dist/core/tools/read.d.ts +35 -0
- package/dist/core/tools/read.js +244 -0
- package/dist/core/tools/render-utils.d.ts +20 -0
- package/dist/core/tools/render-utils.js +48 -0
- package/dist/core/tools/session-split.d.ts +9 -0
- package/dist/core/tools/session-split.js +77 -0
- package/dist/core/tools/tool-definition-wrapper.d.ts +13 -0
- package/dist/core/tools/tool-definition-wrapper.js +32 -0
- package/dist/core/tools/truncate.d.ts +69 -0
- package/dist/core/tools/truncate.js +204 -0
- package/dist/core/tools/write.d.ts +25 -0
- package/dist/core/tools/write.js +211 -0
- package/dist/core/types/session-types.d.ts +123 -0
- package/dist/core/types/session-types.js +8 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +38 -0
- package/dist/main.d.ts +11 -2
- package/dist/main.js +577 -149
- package/dist/modes/event-mapper.d.ts +115 -0
- package/dist/modes/event-mapper.js +200 -0
- package/dist/modes/gui/server.d.ts +14 -0
- package/dist/modes/gui/server.js +1032 -0
- package/dist/modes/index.d.ts +10 -0
- package/dist/modes/index.js +9 -0
- package/dist/modes/interactive/assets/clankolas.png +0 -0
- package/dist/modes/interactive/components/armin.d.ts +33 -0
- package/dist/modes/interactive/components/armin.js +328 -0
- package/dist/modes/interactive/components/assistant-message.d.ts +19 -0
- package/dist/modes/interactive/components/assistant-message.js +115 -0
- package/dist/modes/interactive/components/bash-execution.d.ts +33 -0
- package/dist/modes/interactive/components/bash-execution.js +169 -0
- package/dist/modes/interactive/components/bordered-loader.d.ts +15 -0
- package/dist/modes/interactive/components/bordered-loader.js +50 -0
- package/dist/modes/interactive/components/branch-summary-message.d.ts +15 -0
- package/dist/modes/interactive/components/branch-summary-message.js +41 -0
- package/dist/modes/interactive/components/brand-header.d.ts +33 -0
- package/dist/modes/interactive/components/brand-header.js +235 -0
- package/dist/modes/interactive/components/compaction-summary-message.d.ts +15 -0
- package/dist/modes/interactive/components/compaction-summary-message.js +42 -0
- package/dist/modes/interactive/components/config-selector.d.ts +70 -0
- package/dist/modes/interactive/components/config-selector.js +469 -0
- package/dist/modes/interactive/components/countdown-timer.d.ts +13 -0
- package/dist/modes/interactive/components/countdown-timer.js +27 -0
- package/dist/modes/interactive/components/custom-editor.d.ts +27 -0
- package/dist/modes/interactive/components/custom-editor.js +94 -0
- package/dist/modes/interactive/components/custom-message.d.ts +19 -0
- package/dist/modes/interactive/components/custom-message.js +73 -0
- package/dist/modes/interactive/components/daxnuts.d.ts +22 -0
- package/dist/modes/interactive/components/daxnuts.js +137 -0
- package/dist/modes/interactive/components/diff.d.ts +11 -0
- package/dist/modes/interactive/components/diff.js +132 -0
- package/dist/modes/interactive/components/dynamic-border.d.ts +14 -0
- package/dist/modes/interactive/components/dynamic-border.js +19 -0
- package/dist/modes/interactive/components/earendil-announcement.d.ts +4 -0
- package/dist/modes/interactive/components/earendil-announcement.js +39 -0
- package/dist/modes/interactive/components/extension-editor.d.ts +19 -0
- package/dist/modes/interactive/components/extension-editor.js +105 -0
- package/dist/modes/interactive/components/extension-input.d.ts +22 -0
- package/dist/modes/interactive/components/extension-input.js +54 -0
- package/dist/modes/interactive/components/extension-selector.d.ts +23 -0
- package/dist/modes/interactive/components/extension-selector.js +70 -0
- package/dist/modes/interactive/components/footer.d.ts +55 -0
- package/dist/modes/interactive/components/footer.js +207 -0
- package/dist/modes/interactive/components/index.d.ts +31 -0
- package/dist/modes/interactive/components/index.js +32 -0
- package/dist/modes/interactive/components/keybinding-hints.d.ts +7 -0
- package/dist/modes/interactive/components/keybinding-hints.js +21 -0
- package/dist/modes/interactive/components/login-dialog.d.ts +41 -0
- package/dist/modes/interactive/components/login-dialog.js +138 -0
- package/dist/modes/interactive/components/model-selector.d.ts +32 -0
- package/dist/modes/interactive/components/model-selector.js +209 -0
- package/dist/modes/interactive/components/oauth-selector.d.ts +18 -0
- package/dist/modes/interactive/components/oauth-selector.js +91 -0
- package/dist/modes/interactive/components/settings-selector.d.ts +57 -0
- package/dist/modes/interactive/components/settings-selector.js +299 -0
- package/dist/modes/interactive/components/show-images-selector.d.ts +9 -0
- package/dist/modes/interactive/components/show-images-selector.js +37 -0
- package/dist/modes/interactive/components/skill-invocation-message.d.ts +16 -0
- package/dist/modes/interactive/components/skill-invocation-message.js +44 -0
- package/dist/modes/interactive/components/theme-selector.d.ts +10 -0
- package/dist/modes/interactive/components/theme-selector.js +47 -0
- package/dist/modes/interactive/components/thinking-selector.d.ts +10 -0
- package/dist/modes/interactive/components/thinking-selector.js +50 -0
- package/dist/modes/interactive/components/timeline-view.d.ts +31 -0
- package/dist/modes/interactive/components/timeline-view.js +81 -0
- package/dist/modes/interactive/components/tool-execution.d.ts +64 -0
- package/dist/modes/interactive/components/tool-execution.js +305 -0
- package/dist/modes/interactive/components/tree-selector.d.ts +88 -0
- package/dist/modes/interactive/components/tree-selector.js +1072 -0
- package/dist/modes/interactive/components/user-message-selector.d.ts +29 -0
- package/dist/modes/interactive/components/user-message-selector.js +110 -0
- package/dist/modes/interactive/components/user-message.d.ts +9 -0
- package/dist/modes/interactive/components/user-message.js +27 -0
- package/dist/modes/interactive/components/visual-truncate.d.ts +23 -0
- package/dist/modes/interactive/components/visual-truncate.js +32 -0
- package/dist/modes/interactive/interactive-mode.d.ts +394 -0
- package/dist/modes/interactive/interactive-mode.js +4116 -0
- package/dist/modes/interactive/theme/dark.json +85 -0
- package/dist/modes/interactive/theme/light.json +84 -0
- package/dist/modes/interactive/theme/theme-schema.json +335 -0
- package/dist/modes/interactive/theme/theme.d.ts +80 -0
- package/dist/modes/interactive/theme/theme.js +973 -0
- package/dist/modes/print-mode.d.ts +27 -0
- package/dist/modes/print-mode.js +102 -0
- package/dist/modes/rpc/jsonl.d.ts +16 -0
- package/dist/modes/rpc/jsonl.js +48 -0
- package/dist/modes/rpc/rpc-client.d.ts +219 -0
- package/dist/modes/rpc/rpc-client.js +405 -0
- package/dist/modes/rpc/rpc-mode.d.ts +19 -0
- package/dist/modes/rpc/rpc-mode.js +381 -0
- package/dist/modes/rpc/rpc-types.d.ts +406 -0
- package/dist/modes/rpc/rpc-types.js +7 -0
- package/dist/package-manager-cli.d.ts +3 -0
- package/dist/package-manager-cli.js +233 -0
- package/dist/utils/changelog.d.ts +20 -0
- package/dist/utils/changelog.js +86 -0
- package/dist/utils/child-process.d.ts +10 -0
- package/dist/utils/child-process.js +77 -0
- package/dist/utils/clipboard-image.d.ts +10 -0
- package/dist/utils/clipboard-image.js +244 -0
- package/dist/utils/clipboard-native.d.ts +7 -0
- package/dist/utils/clipboard-native.js +13 -0
- package/dist/utils/clipboard.d.ts +1 -0
- package/dist/utils/clipboard.js +77 -0
- package/dist/utils/exif-orientation.d.ts +4 -0
- package/dist/utils/exif-orientation.js +157 -0
- package/dist/utils/frontmatter.d.ts +7 -0
- package/dist/utils/frontmatter.js +25 -0
- package/dist/utils/git.d.ts +25 -0
- package/dist/utils/git.js +162 -0
- package/dist/utils/image-convert.d.ts +8 -0
- package/dist/utils/image-convert.js +38 -0
- package/dist/utils/image-resize.d.ts +35 -0
- package/dist/utils/image-resize.js +136 -0
- package/dist/utils/mime.d.ts +1 -0
- package/dist/utils/mime.js +25 -0
- package/dist/utils/path-shims.d.ts +1 -0
- package/dist/utils/path-shims.js +90 -0
- package/dist/utils/paths.d.ts +6 -0
- package/dist/utils/paths.js +18 -0
- package/dist/utils/photon.d.ts +20 -0
- package/dist/utils/photon.js +120 -0
- package/dist/utils/shell.d.ts +29 -0
- package/dist/utils/shell.js +189 -0
- package/dist/utils/sleep.d.ts +4 -0
- package/dist/utils/sleep.js +16 -0
- package/dist/utils/tools-manager.d.ts +3 -0
- package/dist/utils/tools-manager.js +101 -0
- package/dist/vendor/bin/darwin-arm64/fd +0 -0
- package/dist/vendor/bin/darwin-arm64/rg +0 -0
- package/dist/vendor/bin/darwin-x64/fd +0 -0
- package/dist/vendor/bin/darwin-x64/rg +0 -0
- package/dist/vendor/bin/linux-arm64/fd +0 -0
- package/dist/vendor/bin/linux-arm64/rg +0 -0
- package/dist/vendor/bin/linux-x64/fd +0 -0
- package/dist/vendor/bin/linux-x64/rg +0 -0
- package/dist/vendor/bin/win32-arm64/fd.exe +0 -0
- package/dist/vendor/bin/win32-arm64/rg.exe +0 -0
- package/dist/vendor/bin/win32-x64/fd.exe +0 -0
- package/dist/vendor/bin/win32-x64/rg.exe +0 -0
- package/package.json +90 -26
- package/dist/extension/core.d.ts +0 -69
- package/dist/extension/core.js +0 -270
- package/dist/extension/core.js.map +0 -1
- package/dist/extension/index.d.ts +0 -14
- package/dist/extension/index.js +0 -374
- package/dist/extension/index.js.map +0 -1
- package/dist/main.js.map +0 -1
- package/themes/pizza.json +0 -87
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared command execution utilities for extensions and custom tools.
|
|
3
|
+
*/
|
|
4
|
+
import { spawn } from "node:child_process";
|
|
5
|
+
import { waitForChildProcess } from "../utils/child-process.js";
|
|
6
|
+
/**
|
|
7
|
+
* Execute a shell command and return stdout/stderr/code.
|
|
8
|
+
* Supports timeout and abort signal.
|
|
9
|
+
*/
|
|
10
|
+
export async function execCommand(command, args, cwd, options) {
|
|
11
|
+
return new Promise((resolve) => {
|
|
12
|
+
const proc = spawn(command, args, {
|
|
13
|
+
cwd,
|
|
14
|
+
shell: false,
|
|
15
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
16
|
+
});
|
|
17
|
+
let stdout = "";
|
|
18
|
+
let stderr = "";
|
|
19
|
+
let killed = false;
|
|
20
|
+
let timeoutId;
|
|
21
|
+
const killProcess = () => {
|
|
22
|
+
if (!killed) {
|
|
23
|
+
killed = true;
|
|
24
|
+
proc.kill("SIGTERM");
|
|
25
|
+
// Force kill after 5 seconds if SIGTERM doesn't work
|
|
26
|
+
setTimeout(() => {
|
|
27
|
+
if (!proc.killed) {
|
|
28
|
+
proc.kill("SIGKILL");
|
|
29
|
+
}
|
|
30
|
+
}, 5000);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
// Handle abort signal
|
|
34
|
+
if (options?.signal) {
|
|
35
|
+
if (options.signal.aborted) {
|
|
36
|
+
killProcess();
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
options.signal.addEventListener("abort", killProcess, { once: true });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// Handle timeout
|
|
43
|
+
if (options?.timeout && options.timeout > 0) {
|
|
44
|
+
timeoutId = setTimeout(() => {
|
|
45
|
+
killProcess();
|
|
46
|
+
}, options.timeout);
|
|
47
|
+
}
|
|
48
|
+
proc.stdout?.on("data", (data) => {
|
|
49
|
+
stdout += data.toString();
|
|
50
|
+
});
|
|
51
|
+
proc.stderr?.on("data", (data) => {
|
|
52
|
+
stderr += data.toString();
|
|
53
|
+
});
|
|
54
|
+
// Wait for process termination without hanging on inherited stdio handles
|
|
55
|
+
// held open by detached descendants.
|
|
56
|
+
waitForChildProcess(proc)
|
|
57
|
+
.then((code) => {
|
|
58
|
+
if (timeoutId)
|
|
59
|
+
clearTimeout(timeoutId);
|
|
60
|
+
if (options?.signal) {
|
|
61
|
+
options.signal.removeEventListener("abort", killProcess);
|
|
62
|
+
}
|
|
63
|
+
resolve({ stdout, stderr, code: code ?? 0, killed });
|
|
64
|
+
})
|
|
65
|
+
.catch((_err) => {
|
|
66
|
+
if (timeoutId)
|
|
67
|
+
clearTimeout(timeoutId);
|
|
68
|
+
if (options?.signal) {
|
|
69
|
+
options.signal.removeEventListener("abort", killProcess);
|
|
70
|
+
}
|
|
71
|
+
resolve({ stdout, stderr, code: 1, killed });
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
/**
|
|
14
|
+
* Convert ANSI-escaped text to HTML with inline styles.
|
|
15
|
+
*/
|
|
16
|
+
export declare function ansiToHtml(text: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Convert array of ANSI-escaped lines to HTML.
|
|
19
|
+
* Each line is wrapped in a div element.
|
|
20
|
+
*/
|
|
21
|
+
export declare function ansiLinesToHtml(lines: string[]): string;
|
|
@@ -0,0 +1,248 @@
|
|
|
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, "&")
|
|
61
|
+
.replace(/</g, "<")
|
|
62
|
+
.replace(/>/g, ">")
|
|
63
|
+
.replace(/"/g, """)
|
|
64
|
+
.replace(/'/g, "'");
|
|
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) || " "}</div>`).join("\n");
|
|
248
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface for rendering custom tools to HTML.
|
|
3
|
+
* Used by the session facade to pre-render extension tool output.
|
|
4
|
+
*/
|
|
5
|
+
export interface ToolHtmlRenderer {
|
|
6
|
+
/** Render a tool call to HTML. Returns undefined if tool has no custom renderer. */
|
|
7
|
+
renderCall(toolCallId: string, toolName: string, args: unknown): string | undefined;
|
|
8
|
+
/** Render a tool result to HTML. Returns collapsed/expanded or undefined if tool has no custom renderer. */
|
|
9
|
+
renderResult(toolCallId: string, toolName: string, result: Array<{
|
|
10
|
+
type: string;
|
|
11
|
+
text?: string;
|
|
12
|
+
data?: string;
|
|
13
|
+
mimeType?: string;
|
|
14
|
+
}>, details: unknown, isError: boolean): {
|
|
15
|
+
collapsed?: string;
|
|
16
|
+
expanded?: string;
|
|
17
|
+
} | undefined;
|
|
18
|
+
}
|
|
19
|
+
export interface ExportOptions {
|
|
20
|
+
outputPath?: string;
|
|
21
|
+
themeName?: string;
|
|
22
|
+
/** Optional tool renderer for custom tools */
|
|
23
|
+
toolRenderer?: ToolHtmlRenderer;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Export a persisted event session to HTML (standalone, without AgentState).
|
|
27
|
+
* Used by CLI for exporting a session reference or exact session id.
|
|
28
|
+
*/
|
|
29
|
+
export declare function exportFromFile(inputPath: string, options?: ExportOptions | string): Promise<string>;
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync } from "fs";
|
|
2
|
+
import { join } from "path";
|
|
3
|
+
import { APP_NAME, getExportTemplateDir } from "../../config.js";
|
|
4
|
+
import { getResolvedThemeColors, getThemeExportColors } from "../../modes/interactive/theme/theme.js";
|
|
5
|
+
import { readSessionForExport } from "../session-reader.js";
|
|
6
|
+
function sanitizeFileNameSegment(value) {
|
|
7
|
+
return value.replace(/[^a-zA-Z0-9._-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "") || "session";
|
|
8
|
+
}
|
|
9
|
+
/** Parse a color string to RGB values. Supports hex (#RRGGBB) and rgb(r,g,b) formats. */
|
|
10
|
+
function parseColor(color) {
|
|
11
|
+
const hexMatch = color.match(/^#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/);
|
|
12
|
+
if (hexMatch) {
|
|
13
|
+
return {
|
|
14
|
+
r: Number.parseInt(hexMatch[1], 16),
|
|
15
|
+
g: Number.parseInt(hexMatch[2], 16),
|
|
16
|
+
b: Number.parseInt(hexMatch[3], 16),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
const rgbMatch = color.match(/^rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/);
|
|
20
|
+
if (rgbMatch) {
|
|
21
|
+
return {
|
|
22
|
+
r: Number.parseInt(rgbMatch[1], 10),
|
|
23
|
+
g: Number.parseInt(rgbMatch[2], 10),
|
|
24
|
+
b: Number.parseInt(rgbMatch[3], 10),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
/** Calculate relative luminance of a color (0-1, higher = lighter). */
|
|
30
|
+
function getLuminance(r, g, b) {
|
|
31
|
+
const toLinear = (c) => {
|
|
32
|
+
const s = c / 255;
|
|
33
|
+
return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
|
|
34
|
+
};
|
|
35
|
+
return 0.2126 * toLinear(r) + 0.7152 * toLinear(g) + 0.0722 * toLinear(b);
|
|
36
|
+
}
|
|
37
|
+
/** Adjust color brightness. Factor > 1 lightens, < 1 darkens. */
|
|
38
|
+
function adjustBrightness(color, factor) {
|
|
39
|
+
const parsed = parseColor(color);
|
|
40
|
+
if (!parsed)
|
|
41
|
+
return color;
|
|
42
|
+
const adjust = (c) => Math.min(255, Math.max(0, Math.round(c * factor)));
|
|
43
|
+
return `rgb(${adjust(parsed.r)}, ${adjust(parsed.g)}, ${adjust(parsed.b)})`;
|
|
44
|
+
}
|
|
45
|
+
/** Derive export background colors from a base color (e.g., userMessageBg). */
|
|
46
|
+
function deriveExportColors(baseColor) {
|
|
47
|
+
const parsed = parseColor(baseColor);
|
|
48
|
+
if (!parsed) {
|
|
49
|
+
return {
|
|
50
|
+
pageBg: "rgb(24, 24, 30)",
|
|
51
|
+
cardBg: "rgb(30, 30, 36)",
|
|
52
|
+
infoBg: "rgb(60, 55, 40)",
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const luminance = getLuminance(parsed.r, parsed.g, parsed.b);
|
|
56
|
+
const isLight = luminance > 0.5;
|
|
57
|
+
if (isLight) {
|
|
58
|
+
return {
|
|
59
|
+
pageBg: adjustBrightness(baseColor, 0.96),
|
|
60
|
+
cardBg: baseColor,
|
|
61
|
+
infoBg: `rgb(${Math.min(255, parsed.r + 10)}, ${Math.min(255, parsed.g + 5)}, ${Math.max(0, parsed.b - 20)})`,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
pageBg: adjustBrightness(baseColor, 0.7),
|
|
66
|
+
cardBg: adjustBrightness(baseColor, 0.85),
|
|
67
|
+
infoBg: `rgb(${Math.min(255, parsed.r + 20)}, ${Math.min(255, parsed.g + 15)}, ${parsed.b})`,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Generate CSS custom property declarations from theme colors.
|
|
72
|
+
*/
|
|
73
|
+
function generateThemeVars(themeName) {
|
|
74
|
+
const colors = getResolvedThemeColors(themeName);
|
|
75
|
+
const lines = [];
|
|
76
|
+
for (const [key, value] of Object.entries(colors)) {
|
|
77
|
+
lines.push(`--${key}: ${value};`);
|
|
78
|
+
}
|
|
79
|
+
// Use explicit theme export colors if available, otherwise derive from userMessageBg
|
|
80
|
+
const themeExport = getThemeExportColors(themeName);
|
|
81
|
+
const userMessageBg = colors.userMessageBg || "#343541";
|
|
82
|
+
const derivedColors = deriveExportColors(userMessageBg);
|
|
83
|
+
lines.push(`--exportPageBg: ${themeExport.pageBg ?? derivedColors.pageBg};`);
|
|
84
|
+
lines.push(`--exportCardBg: ${themeExport.cardBg ?? derivedColors.cardBg};`);
|
|
85
|
+
lines.push(`--exportInfoBg: ${themeExport.infoBg ?? derivedColors.infoBg};`);
|
|
86
|
+
return lines.join("\n ");
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Core HTML generation logic shared by both export functions.
|
|
90
|
+
*/
|
|
91
|
+
function generateHtml(sessionData, themeName) {
|
|
92
|
+
const templateDir = getExportTemplateDir();
|
|
93
|
+
const template = readFileSync(join(templateDir, "template.html"), "utf-8");
|
|
94
|
+
const templateCss = readFileSync(join(templateDir, "template.css"), "utf-8");
|
|
95
|
+
const templateJs = readFileSync(join(templateDir, "template.js"), "utf-8");
|
|
96
|
+
const markedJs = readFileSync(join(templateDir, "vendor", "marked.min.js"), "utf-8");
|
|
97
|
+
const hljsJs = readFileSync(join(templateDir, "vendor", "highlight.min.js"), "utf-8");
|
|
98
|
+
const themeVars = generateThemeVars(themeName);
|
|
99
|
+
const colors = getResolvedThemeColors(themeName);
|
|
100
|
+
const themeExport = getThemeExportColors(themeName);
|
|
101
|
+
const derivedExportColors = deriveExportColors(colors.userMessageBg || "#343541");
|
|
102
|
+
const bodyBg = themeExport.pageBg ?? derivedExportColors.pageBg;
|
|
103
|
+
const containerBg = themeExport.cardBg ?? derivedExportColors.cardBg;
|
|
104
|
+
const infoBg = themeExport.infoBg ?? derivedExportColors.infoBg;
|
|
105
|
+
// Base64 encode session data to avoid escaping issues
|
|
106
|
+
const sessionDataBase64 = Buffer.from(JSON.stringify(sessionData)).toString("base64");
|
|
107
|
+
// Build the CSS with theme variables injected
|
|
108
|
+
const css = templateCss
|
|
109
|
+
.replace("{{THEME_VARS}}", themeVars)
|
|
110
|
+
.replace("{{BODY_BG}}", bodyBg)
|
|
111
|
+
.replace("{{CONTAINER_BG}}", containerBg)
|
|
112
|
+
.replace("{{INFO_BG}}", infoBg);
|
|
113
|
+
return template
|
|
114
|
+
.replace("{{CSS}}", css)
|
|
115
|
+
.replace("{{JS}}", templateJs)
|
|
116
|
+
.replace("{{SESSION_DATA}}", sessionDataBase64)
|
|
117
|
+
.replace("{{MARKED_JS}}", markedJs)
|
|
118
|
+
.replace("{{HIGHLIGHT_JS}}", hljsJs);
|
|
119
|
+
}
|
|
120
|
+
/** Tools rendered directly by the HTML template (not pre-rendered via TUI→ANSI→HTML pipeline) */
|
|
121
|
+
const TEMPLATE_RENDERED_TOOLS = new Set(["cli", "bash", "read", "write", "edit", "ls"]);
|
|
122
|
+
/**
|
|
123
|
+
* Pre-render custom tools to HTML using their TUI renderers.
|
|
124
|
+
*/
|
|
125
|
+
function preRenderCustomTools(entries, toolRenderer) {
|
|
126
|
+
const renderedTools = {};
|
|
127
|
+
for (const entry of entries) {
|
|
128
|
+
if (entry.type !== "message")
|
|
129
|
+
continue;
|
|
130
|
+
const msg = entry.message;
|
|
131
|
+
// Find tool calls in assistant messages
|
|
132
|
+
if (msg.role === "assistant" && Array.isArray(msg.content)) {
|
|
133
|
+
for (const block of msg.content) {
|
|
134
|
+
if (block.type === "toolCall" && !TEMPLATE_RENDERED_TOOLS.has(block.name)) {
|
|
135
|
+
const callHtml = toolRenderer.renderCall(block.id, block.name, block.arguments);
|
|
136
|
+
if (callHtml) {
|
|
137
|
+
renderedTools[block.id] = { callHtml };
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
// Find tool results
|
|
143
|
+
if (msg.role === "toolResult" && msg.toolCallId) {
|
|
144
|
+
const toolName = msg.toolName || "";
|
|
145
|
+
// Only render if we have a pre-rendered call OR it's not template-rendered
|
|
146
|
+
const existing = renderedTools[msg.toolCallId];
|
|
147
|
+
if (existing || !TEMPLATE_RENDERED_TOOLS.has(toolName)) {
|
|
148
|
+
const rendered = toolRenderer.renderResult(msg.toolCallId, toolName, msg.content, msg.details, msg.isError || false);
|
|
149
|
+
if (rendered) {
|
|
150
|
+
renderedTools[msg.toolCallId] = {
|
|
151
|
+
...existing,
|
|
152
|
+
resultHtmlCollapsed: rendered.collapsed,
|
|
153
|
+
resultHtmlExpanded: rendered.expanded,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return renderedTools;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Export a persisted event session to HTML (standalone, without AgentState).
|
|
163
|
+
* Used by CLI for exporting a session reference or exact session id.
|
|
164
|
+
*/
|
|
165
|
+
export async function exportFromFile(inputPath, options) {
|
|
166
|
+
const opts = typeof options === "string" ? { outputPath: options } : options || {};
|
|
167
|
+
if (inputPath.includes("/") || inputPath.includes("\\") || inputPath.endsWith(".jsonl")) {
|
|
168
|
+
throw new Error("Legacy JSONL session export is no longer supported; pass an event session reference instead.");
|
|
169
|
+
}
|
|
170
|
+
const { header, entries, leafId, sessionId } = readSessionForExport(inputPath);
|
|
171
|
+
const sessionData = {
|
|
172
|
+
header,
|
|
173
|
+
entries,
|
|
174
|
+
leafId,
|
|
175
|
+
systemPrompt: undefined,
|
|
176
|
+
tools: undefined,
|
|
177
|
+
};
|
|
178
|
+
const html = generateHtml(sessionData, opts.themeName);
|
|
179
|
+
let outputPath = opts.outputPath;
|
|
180
|
+
if (!outputPath) {
|
|
181
|
+
const inputBasename = sanitizeFileNameSegment(sessionId || inputPath);
|
|
182
|
+
outputPath = `${APP_NAME}-session-${inputBasename}.html`;
|
|
183
|
+
}
|
|
184
|
+
writeFileSync(outputPath, html, "utf8");
|
|
185
|
+
return outputPath;
|
|
186
|
+
}
|