@vandeepunk/pi-coding-agent 0.0.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/CHANGELOG.md +2564 -0
- package/README.md +555 -0
- package/dist/cli/args.d.ts +47 -0
- package/dist/cli/args.d.ts.map +1 -0
- package/dist/cli/args.js +286 -0
- package/dist/cli/args.js.map +1 -0
- package/dist/cli/config-selector.d.ts +14 -0
- package/dist/cli/config-selector.d.ts.map +1 -0
- package/dist/cli/config-selector.js +31 -0
- package/dist/cli/config-selector.js.map +1 -0
- package/dist/cli/file-processor.d.ts +15 -0
- package/dist/cli/file-processor.d.ts.map +1 -0
- package/dist/cli/file-processor.js +79 -0
- package/dist/cli/file-processor.js.map +1 -0
- package/dist/cli/list-models.d.ts +9 -0
- package/dist/cli/list-models.d.ts.map +1 -0
- package/dist/cli/list-models.js +92 -0
- package/dist/cli/list-models.js.map +1 -0
- package/dist/cli/session-picker.d.ts +9 -0
- package/dist/cli/session-picker.d.ts.map +1 -0
- package/dist/cli/session-picker.js +34 -0
- package/dist/cli/session-picker.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +11 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +68 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +203 -0
- package/dist/config.js.map +1 -0
- package/dist/core/agent-session.d.ts +574 -0
- package/dist/core/agent-session.d.ts.map +1 -0
- package/dist/core/agent-session.js +2260 -0
- package/dist/core/agent-session.js.map +1 -0
- package/dist/core/auth-storage.d.ts +102 -0
- package/dist/core/auth-storage.d.ts.map +1 -0
- package/dist/core/auth-storage.js +282 -0
- package/dist/core/auth-storage.js.map +1 -0
- package/dist/core/bash-executor.d.ts +47 -0
- package/dist/core/bash-executor.d.ts.map +1 -0
- package/dist/core/bash-executor.js +212 -0
- package/dist/core/bash-executor.js.map +1 -0
- package/dist/core/compaction/branch-summarization.d.ts +86 -0
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -0
- package/dist/core/compaction/branch-summarization.js +242 -0
- package/dist/core/compaction/branch-summarization.js.map +1 -0
- package/dist/core/compaction/compaction.d.ts +121 -0
- package/dist/core/compaction/compaction.d.ts.map +1 -0
- package/dist/core/compaction/compaction.js +607 -0
- package/dist/core/compaction/compaction.js.map +1 -0
- package/dist/core/compaction/index.d.ts +7 -0
- package/dist/core/compaction/index.d.ts.map +1 -0
- package/dist/core/compaction/index.js +7 -0
- package/dist/core/compaction/index.js.map +1 -0
- package/dist/core/compaction/utils.d.ts +35 -0
- package/dist/core/compaction/utils.d.ts.map +1 -0
- package/dist/core/compaction/utils.js +138 -0
- package/dist/core/compaction/utils.js.map +1 -0
- package/dist/core/defaults.d.ts +3 -0
- package/dist/core/defaults.d.ts.map +1 -0
- package/dist/core/defaults.js +2 -0
- package/dist/core/defaults.js.map +1 -0
- package/dist/core/diagnostics.d.ts +15 -0
- package/dist/core/diagnostics.d.ts.map +1 -0
- package/dist/core/diagnostics.js +2 -0
- package/dist/core/diagnostics.js.map +1 -0
- package/dist/core/event-bus.d.ts +9 -0
- package/dist/core/event-bus.d.ts.map +1 -0
- package/dist/core/event-bus.js +25 -0
- package/dist/core/event-bus.js.map +1 -0
- package/dist/core/exec.d.ts +29 -0
- package/dist/core/exec.d.ts.map +1 -0
- package/dist/core/exec.js +71 -0
- package/dist/core/exec.js.map +1 -0
- package/dist/core/export-html/ansi-to-html.d.ts +22 -0
- package/dist/core/export-html/ansi-to-html.d.ts.map +1 -0
- package/dist/core/export-html/ansi-to-html.js +249 -0
- package/dist/core/export-html/ansi-to-html.js.map +1 -0
- package/dist/core/export-html/index.d.ts +34 -0
- package/dist/core/export-html/index.d.ts.map +1 -0
- package/dist/core/export-html/index.js +222 -0
- package/dist/core/export-html/index.js.map +1 -0
- package/dist/core/export-html/template.css +909 -0
- package/dist/core/export-html/template.html +54 -0
- package/dist/core/export-html/template.js +1549 -0
- package/dist/core/export-html/tool-renderer.d.ts +35 -0
- package/dist/core/export-html/tool-renderer.d.ts.map +1 -0
- package/dist/core/export-html/tool-renderer.js +57 -0
- package/dist/core/export-html/tool-renderer.js.map +1 -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 +11 -0
- package/dist/core/extensions/index.d.ts.map +1 -0
- package/dist/core/extensions/index.js +9 -0
- package/dist/core/extensions/index.js.map +1 -0
- package/dist/core/extensions/loader.d.ts +25 -0
- package/dist/core/extensions/loader.d.ts.map +1 -0
- package/dist/core/extensions/loader.js +400 -0
- package/dist/core/extensions/loader.js.map +1 -0
- package/dist/core/extensions/runner.d.ts +129 -0
- package/dist/core/extensions/runner.d.ts.map +1 -0
- package/dist/core/extensions/runner.js +576 -0
- package/dist/core/extensions/runner.js.map +1 -0
- package/dist/core/extensions/types.d.ts +928 -0
- package/dist/core/extensions/types.d.ts.map +1 -0
- package/dist/core/extensions/types.js +35 -0
- package/dist/core/extensions/types.js.map +1 -0
- package/dist/core/extensions/wrapper.d.ts +27 -0
- package/dist/core/extensions/wrapper.d.ts.map +1 -0
- package/dist/core/extensions/wrapper.js +102 -0
- package/dist/core/extensions/wrapper.js.map +1 -0
- package/dist/core/footer-data-provider.d.ts +32 -0
- package/dist/core/footer-data-provider.d.ts.map +1 -0
- package/dist/core/footer-data-provider.js +134 -0
- package/dist/core/footer-data-provider.js.map +1 -0
- package/dist/core/index.d.ts +9 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +9 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/keybindings.d.ts +55 -0
- package/dist/core/keybindings.d.ts.map +1 -0
- package/dist/core/keybindings.js +153 -0
- package/dist/core/keybindings.js.map +1 -0
- package/dist/core/messages.d.ts +77 -0
- package/dist/core/messages.d.ts.map +1 -0
- package/dist/core/messages.js +123 -0
- package/dist/core/messages.js.map +1 -0
- package/dist/core/model-registry.d.ts +100 -0
- package/dist/core/model-registry.d.ts.map +1 -0
- package/dist/core/model-registry.js +419 -0
- package/dist/core/model-registry.js.map +1 -0
- package/dist/core/model-resolver.d.ts +76 -0
- package/dist/core/model-resolver.d.ts.map +1 -0
- package/dist/core/model-resolver.js +313 -0
- package/dist/core/model-resolver.js.map +1 -0
- package/dist/core/package-manager.d.ts +131 -0
- package/dist/core/package-manager.d.ts.map +1 -0
- package/dist/core/package-manager.js +1290 -0
- package/dist/core/package-manager.js.map +1 -0
- package/dist/core/prompt-templates.d.ts +50 -0
- package/dist/core/prompt-templates.d.ts.map +1 -0
- package/dist/core/prompt-templates.js +251 -0
- package/dist/core/prompt-templates.js.map +1 -0
- package/dist/core/resolve-config-value.d.ts +17 -0
- package/dist/core/resolve-config-value.d.ts.map +1 -0
- package/dist/core/resolve-config-value.js +59 -0
- package/dist/core/resolve-config-value.js.map +1 -0
- package/dist/core/resource-loader.d.ts +184 -0
- package/dist/core/resource-loader.d.ts.map +1 -0
- package/dist/core/resource-loader.js +673 -0
- package/dist/core/resource-loader.js.map +1 -0
- package/dist/core/sdk.d.ts +90 -0
- package/dist/core/sdk.d.ts.map +1 -0
- package/dist/core/sdk.js +234 -0
- package/dist/core/sdk.js.map +1 -0
- package/dist/core/session-manager.d.ts +323 -0
- package/dist/core/session-manager.d.ts.map +1 -0
- package/dist/core/session-manager.js +1091 -0
- package/dist/core/session-manager.js.map +1 -0
- package/dist/core/settings-manager.d.ts +187 -0
- package/dist/core/settings-manager.d.ts.map +1 -0
- package/dist/core/settings-manager.js +552 -0
- package/dist/core/settings-manager.js.map +1 -0
- package/dist/core/skills.d.ts +58 -0
- package/dist/core/skills.d.ts.map +1 -0
- package/dist/core/skills.js +310 -0
- package/dist/core/skills.js.map +1 -0
- package/dist/core/slash-commands.d.ts +15 -0
- package/dist/core/slash-commands.d.ts.map +1 -0
- package/dist/core/slash-commands.js +21 -0
- package/dist/core/slash-commands.js.map +1 -0
- package/dist/core/system-prompt.d.ts +24 -0
- package/dist/core/system-prompt.d.ts.map +1 -0
- package/dist/core/system-prompt.js +137 -0
- package/dist/core/system-prompt.js.map +1 -0
- package/dist/core/timings.d.ts +7 -0
- package/dist/core/timings.d.ts.map +1 -0
- package/dist/core/timings.js +25 -0
- package/dist/core/timings.js.map +1 -0
- package/dist/core/tools/bash.d.ts +55 -0
- package/dist/core/tools/bash.d.ts.map +1 -0
- package/dist/core/tools/bash.js +242 -0
- package/dist/core/tools/bash.js.map +1 -0
- package/dist/core/tools/edit-diff.d.ts +63 -0
- package/dist/core/tools/edit-diff.d.ts.map +1 -0
- package/dist/core/tools/edit-diff.js +243 -0
- package/dist/core/tools/edit-diff.js.map +1 -0
- package/dist/core/tools/edit.d.ts +39 -0
- package/dist/core/tools/edit.d.ts.map +1 -0
- package/dist/core/tools/edit.js +146 -0
- package/dist/core/tools/edit.js.map +1 -0
- package/dist/core/tools/find.d.ts +39 -0
- package/dist/core/tools/find.d.ts.map +1 -0
- package/dist/core/tools/find.js +206 -0
- package/dist/core/tools/find.js.map +1 -0
- package/dist/core/tools/grep.d.ts +45 -0
- package/dist/core/tools/grep.d.ts.map +1 -0
- package/dist/core/tools/grep.js +239 -0
- package/dist/core/tools/grep.js.map +1 -0
- package/dist/core/tools/index.d.ts +73 -0
- package/dist/core/tools/index.d.ts.map +1 -0
- package/dist/core/tools/index.js +61 -0
- package/dist/core/tools/index.js.map +1 -0
- package/dist/core/tools/ls.d.ts +40 -0
- package/dist/core/tools/ls.d.ts.map +1 -0
- package/dist/core/tools/ls.js +118 -0
- package/dist/core/tools/ls.js.map +1 -0
- package/dist/core/tools/path-utils.d.ts +8 -0
- package/dist/core/tools/path-utils.d.ts.map +1 -0
- package/dist/core/tools/path-utils.js +81 -0
- package/dist/core/tools/path-utils.js.map +1 -0
- package/dist/core/tools/read.d.ts +39 -0
- package/dist/core/tools/read.d.ts.map +1 -0
- package/dist/core/tools/read.js +166 -0
- package/dist/core/tools/read.js.map +1 -0
- package/dist/core/tools/truncate.d.ts +70 -0
- package/dist/core/tools/truncate.d.ts.map +1 -0
- package/dist/core/tools/truncate.js +205 -0
- package/dist/core/tools/truncate.js.map +1 -0
- package/dist/core/tools/write.d.ts +29 -0
- package/dist/core/tools/write.d.ts.map +1 -0
- package/dist/core/tools/write.js +78 -0
- package/dist/core/tools/write.js.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +42 -0
- package/dist/index.js.map +1 -0
- package/dist/main.d.ts +8 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +623 -0
- package/dist/main.js.map +1 -0
- package/dist/migrations.d.ts +33 -0
- package/dist/migrations.d.ts.map +1 -0
- package/dist/migrations.js +261 -0
- package/dist/migrations.js.map +1 -0
- package/dist/modes/index.d.ts +9 -0
- package/dist/modes/index.d.ts.map +1 -0
- package/dist/modes/index.js +8 -0
- package/dist/modes/index.js.map +1 -0
- package/dist/modes/interactive/components/armin.d.ts +34 -0
- package/dist/modes/interactive/components/armin.d.ts.map +1 -0
- package/dist/modes/interactive/components/armin.js +333 -0
- package/dist/modes/interactive/components/armin.js.map +1 -0
- package/dist/modes/interactive/components/assistant-message.d.ts +16 -0
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/assistant-message.js +91 -0
- package/dist/modes/interactive/components/assistant-message.js.map +1 -0
- package/dist/modes/interactive/components/bash-execution.d.ts +35 -0
- package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -0
- package/dist/modes/interactive/components/bash-execution.js +162 -0
- package/dist/modes/interactive/components/bash-execution.js.map +1 -0
- package/dist/modes/interactive/components/bordered-loader.d.ts +16 -0
- package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -0
- package/dist/modes/interactive/components/bordered-loader.js +51 -0
- package/dist/modes/interactive/components/bordered-loader.js.map +1 -0
- package/dist/modes/interactive/components/branch-summary-message.d.ts +16 -0
- package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/branch-summary-message.js +44 -0
- package/dist/modes/interactive/components/branch-summary-message.js.map +1 -0
- package/dist/modes/interactive/components/compaction-summary-message.d.ts +16 -0
- package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/compaction-summary-message.js +45 -0
- package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -0
- package/dist/modes/interactive/components/config-selector.d.ts +71 -0
- package/dist/modes/interactive/components/config-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/config-selector.js +479 -0
- package/dist/modes/interactive/components/config-selector.js.map +1 -0
- package/dist/modes/interactive/components/countdown-timer.d.ts +14 -0
- package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -0
- package/dist/modes/interactive/components/countdown-timer.js +33 -0
- package/dist/modes/interactive/components/countdown-timer.js.map +1 -0
- package/dist/modes/interactive/components/custom-editor.d.ts +21 -0
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -0
- package/dist/modes/interactive/components/custom-editor.js +70 -0
- package/dist/modes/interactive/components/custom-editor.js.map +1 -0
- package/dist/modes/interactive/components/custom-message.d.ts +20 -0
- package/dist/modes/interactive/components/custom-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/custom-message.js +79 -0
- package/dist/modes/interactive/components/custom-message.js.map +1 -0
- package/dist/modes/interactive/components/daxnuts.d.ts +23 -0
- package/dist/modes/interactive/components/daxnuts.d.ts.map +1 -0
- package/dist/modes/interactive/components/daxnuts.js +140 -0
- package/dist/modes/interactive/components/daxnuts.js.map +1 -0
- package/dist/modes/interactive/components/diff.d.ts +12 -0
- package/dist/modes/interactive/components/diff.d.ts.map +1 -0
- package/dist/modes/interactive/components/diff.js +133 -0
- package/dist/modes/interactive/components/diff.js.map +1 -0
- package/dist/modes/interactive/components/dynamic-border.d.ts +15 -0
- package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -0
- package/dist/modes/interactive/components/dynamic-border.js +21 -0
- package/dist/modes/interactive/components/dynamic-border.js.map +1 -0
- package/dist/modes/interactive/components/extension-editor.d.ts +17 -0
- package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -0
- package/dist/modes/interactive/components/extension-editor.js +102 -0
- package/dist/modes/interactive/components/extension-editor.js.map +1 -0
- package/dist/modes/interactive/components/extension-input.d.ts +23 -0
- package/dist/modes/interactive/components/extension-input.d.ts.map +1 -0
- package/dist/modes/interactive/components/extension-input.js +61 -0
- package/dist/modes/interactive/components/extension-input.js.map +1 -0
- package/dist/modes/interactive/components/extension-selector.d.ts +24 -0
- package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/extension-selector.js +78 -0
- package/dist/modes/interactive/components/extension-selector.js.map +1 -0
- package/dist/modes/interactive/components/footer.d.ts +26 -0
- package/dist/modes/interactive/components/footer.d.ts.map +1 -0
- package/dist/modes/interactive/components/footer.js +220 -0
- package/dist/modes/interactive/components/footer.js.map +1 -0
- package/dist/modes/interactive/components/index.d.ts +32 -0
- package/dist/modes/interactive/components/index.d.ts.map +1 -0
- package/dist/modes/interactive/components/index.js +33 -0
- package/dist/modes/interactive/components/index.js.map +1 -0
- package/dist/modes/interactive/components/keybinding-hints.d.ts +41 -0
- package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -0
- package/dist/modes/interactive/components/keybinding-hints.js +61 -0
- package/dist/modes/interactive/components/keybinding-hints.js.map +1 -0
- package/dist/modes/interactive/components/login-dialog.d.ts +42 -0
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -0
- package/dist/modes/interactive/components/login-dialog.js +145 -0
- package/dist/modes/interactive/components/login-dialog.js.map +1 -0
- package/dist/modes/interactive/components/model-selector.d.ts +47 -0
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/model-selector.js +266 -0
- package/dist/modes/interactive/components/model-selector.js.map +1 -0
- package/dist/modes/interactive/components/oauth-selector.d.ts +19 -0
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/oauth-selector.js +97 -0
- package/dist/modes/interactive/components/oauth-selector.js.map +1 -0
- package/dist/modes/interactive/components/scoped-models-selector.d.ts +49 -0
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/scoped-models-selector.js +270 -0
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -0
- package/dist/modes/interactive/components/session-selector-search.d.ts +23 -0
- package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -0
- package/dist/modes/interactive/components/session-selector-search.js +155 -0
- package/dist/modes/interactive/components/session-selector-search.js.map +1 -0
- package/dist/modes/interactive/components/session-selector.d.ts +95 -0
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/session-selector.js +851 -0
- package/dist/modes/interactive/components/session-selector.js.map +1 -0
- package/dist/modes/interactive/components/settings-selector.d.ts +53 -0
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/settings-selector.js +277 -0
- package/dist/modes/interactive/components/settings-selector.js.map +1 -0
- package/dist/modes/interactive/components/show-images-selector.d.ts +10 -0
- package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/show-images-selector.js +35 -0
- package/dist/modes/interactive/components/show-images-selector.js.map +1 -0
- package/dist/modes/interactive/components/skill-invocation-message.d.ts +17 -0
- package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/skill-invocation-message.js +47 -0
- package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -0
- package/dist/modes/interactive/components/theme-selector.d.ts +11 -0
- package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/theme-selector.js +46 -0
- package/dist/modes/interactive/components/theme-selector.js.map +1 -0
- package/dist/modes/interactive/components/thinking-selector.d.ts +11 -0
- package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/thinking-selector.js +47 -0
- package/dist/modes/interactive/components/thinking-selector.js.map +1 -0
- package/dist/modes/interactive/components/tool-execution.d.ts +70 -0
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -0
- package/dist/modes/interactive/components/tool-execution.js +621 -0
- package/dist/modes/interactive/components/tool-execution.js.map +1 -0
- package/dist/modes/interactive/components/tree-selector.d.ts +68 -0
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/tree-selector.js +934 -0
- package/dist/modes/interactive/components/tree-selector.js.map +1 -0
- package/dist/modes/interactive/components/user-message-selector.d.ts +30 -0
- package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/user-message-selector.js +113 -0
- package/dist/modes/interactive/components/user-message-selector.js.map +1 -0
- package/dist/modes/interactive/components/user-message.d.ts +8 -0
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/user-message.js +16 -0
- package/dist/modes/interactive/components/user-message.js.map +1 -0
- package/dist/modes/interactive/components/visual-truncate.d.ts +24 -0
- package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -0
- package/dist/modes/interactive/components/visual-truncate.js +33 -0
- package/dist/modes/interactive/components/visual-truncate.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts +313 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-mode.js +3664 -0
- package/dist/modes/interactive/interactive-mode.js.map +1 -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 +78 -0
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -0
- package/dist/modes/interactive/theme/theme.js +944 -0
- package/dist/modes/interactive/theme/theme.js.map +1 -0
- package/dist/modes/print-mode.d.ts +28 -0
- package/dist/modes/print-mode.d.ts.map +1 -0
- package/dist/modes/print-mode.js +98 -0
- package/dist/modes/print-mode.js.map +1 -0
- package/dist/modes/rpc/rpc-client.d.ts +217 -0
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -0
- package/dist/modes/rpc/rpc-client.js +405 -0
- package/dist/modes/rpc/rpc-client.js.map +1 -0
- package/dist/modes/rpc/rpc-mode.d.ts +20 -0
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -0
- package/dist/modes/rpc/rpc-mode.js +500 -0
- package/dist/modes/rpc/rpc-mode.js.map +1 -0
- package/dist/modes/rpc/rpc-types.d.ts +409 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -0
- package/dist/modes/rpc/rpc-types.js +8 -0
- package/dist/modes/rpc/rpc-types.js.map +1 -0
- package/dist/utils/changelog.d.ts +21 -0
- package/dist/utils/changelog.d.ts.map +1 -0
- package/dist/utils/changelog.js +87 -0
- package/dist/utils/changelog.js.map +1 -0
- package/dist/utils/clipboard-image.d.ts +11 -0
- package/dist/utils/clipboard-image.d.ts.map +1 -0
- package/dist/utils/clipboard-image.js +162 -0
- package/dist/utils/clipboard-image.js.map +1 -0
- package/dist/utils/clipboard-native.d.ts +7 -0
- package/dist/utils/clipboard-native.d.ts.map +1 -0
- package/dist/utils/clipboard-native.js +14 -0
- package/dist/utils/clipboard-native.js.map +1 -0
- package/dist/utils/clipboard.d.ts +2 -0
- package/dist/utils/clipboard.d.ts.map +1 -0
- package/dist/utils/clipboard.js +67 -0
- package/dist/utils/clipboard.js.map +1 -0
- package/dist/utils/frontmatter.d.ts +8 -0
- package/dist/utils/frontmatter.d.ts.map +1 -0
- package/dist/utils/frontmatter.js +26 -0
- package/dist/utils/frontmatter.js.map +1 -0
- package/dist/utils/git.d.ts +2 -0
- package/dist/utils/git.d.ts.map +1 -0
- package/dist/utils/git.js +6 -0
- package/dist/utils/git.js.map +1 -0
- package/dist/utils/image-convert.d.ts +9 -0
- package/dist/utils/image-convert.d.ts.map +1 -0
- package/dist/utils/image-convert.js +35 -0
- package/dist/utils/image-convert.js.map +1 -0
- package/dist/utils/image-resize.d.ts +36 -0
- package/dist/utils/image-resize.d.ts.map +1 -0
- package/dist/utils/image-resize.js +181 -0
- package/dist/utils/image-resize.js.map +1 -0
- package/dist/utils/mime.d.ts +2 -0
- package/dist/utils/mime.d.ts.map +1 -0
- package/dist/utils/mime.js +26 -0
- package/dist/utils/mime.js.map +1 -0
- package/dist/utils/photon.d.ts +21 -0
- package/dist/utils/photon.d.ts.map +1 -0
- package/dist/utils/photon.js +121 -0
- package/dist/utils/photon.js.map +1 -0
- package/dist/utils/shell.d.ts +26 -0
- package/dist/utils/shell.d.ts.map +1 -0
- package/dist/utils/shell.js +186 -0
- package/dist/utils/shell.js.map +1 -0
- package/dist/utils/sleep.d.ts +5 -0
- package/dist/utils/sleep.d.ts.map +1 -0
- package/dist/utils/sleep.js +17 -0
- package/dist/utils/sleep.js.map +1 -0
- package/dist/utils/tools-manager.d.ts +3 -0
- package/dist/utils/tools-manager.d.ts.map +1 -0
- package/dist/utils/tools-manager.js +201 -0
- package/dist/utils/tools-manager.js.map +1 -0
- package/docs/compaction.md +390 -0
- package/docs/custom-provider.md +539 -0
- package/docs/development.md +69 -0
- package/docs/extensions.md +1827 -0
- package/docs/images/doom-extension.png +0 -0
- package/docs/images/exy.png +0 -0
- package/docs/images/interactive-mode.png +0 -0
- package/docs/images/tree-view.png +0 -0
- package/docs/json.md +79 -0
- package/docs/keybindings.md +174 -0
- package/docs/models.md +254 -0
- package/docs/packages.md +191 -0
- package/docs/prompt-templates.md +67 -0
- package/docs/providers.md +168 -0
- package/docs/rpc.md +1311 -0
- package/docs/sdk.md +957 -0
- package/docs/session.md +412 -0
- package/docs/settings.md +221 -0
- package/docs/shell-aliases.md +13 -0
- package/docs/skills.md +227 -0
- package/docs/terminal-setup.md +70 -0
- package/docs/termux.md +127 -0
- package/docs/themes.md +295 -0
- package/docs/tree.md +219 -0
- package/docs/tui.md +887 -0
- package/docs/windows.md +17 -0
- package/examples/README.md +25 -0
- package/examples/extensions/README.md +202 -0
- package/examples/extensions/antigravity-image-gen.ts +413 -0
- package/examples/extensions/auto-commit-on-exit.ts +49 -0
- package/examples/extensions/bash-spawn-hook.ts +30 -0
- package/examples/extensions/bookmark.ts +50 -0
- package/examples/extensions/claude-rules.ts +86 -0
- package/examples/extensions/commands.ts +72 -0
- package/examples/extensions/confirm-destructive.ts +59 -0
- package/examples/extensions/custom-compaction.ts +114 -0
- package/examples/extensions/custom-footer.ts +64 -0
- package/examples/extensions/custom-header.ts +73 -0
- package/examples/extensions/custom-provider-anthropic/index.ts +604 -0
- package/examples/extensions/custom-provider-anthropic/package-lock.json +24 -0
- package/examples/extensions/custom-provider-anthropic/package.json +19 -0
- package/examples/extensions/custom-provider-gitlab-duo/index.ts +349 -0
- package/examples/extensions/custom-provider-gitlab-duo/package.json +16 -0
- package/examples/extensions/custom-provider-gitlab-duo/test.ts +82 -0
- package/examples/extensions/custom-provider-qwen-cli/index.ts +345 -0
- package/examples/extensions/custom-provider-qwen-cli/package.json +16 -0
- package/examples/extensions/dirty-repo-guard.ts +56 -0
- package/examples/extensions/doom-overlay/README.md +46 -0
- package/examples/extensions/doom-overlay/doom/build/doom.js +21 -0
- package/examples/extensions/doom-overlay/doom/build/doom.wasm +0 -0
- package/examples/extensions/doom-overlay/doom/build.sh +152 -0
- package/examples/extensions/doom-overlay/doom/doomgeneric_pi.c +72 -0
- package/examples/extensions/doom-overlay/doom-component.ts +132 -0
- package/examples/extensions/doom-overlay/doom-engine.ts +173 -0
- package/examples/extensions/doom-overlay/doom-keys.ts +104 -0
- package/examples/extensions/doom-overlay/index.ts +74 -0
- package/examples/extensions/doom-overlay/wad-finder.ts +51 -0
- package/examples/extensions/dynamic-resources/SKILL.md +8 -0
- package/examples/extensions/dynamic-resources/dynamic.json +79 -0
- package/examples/extensions/dynamic-resources/dynamic.md +5 -0
- package/examples/extensions/dynamic-resources/index.ts +15 -0
- package/examples/extensions/event-bus.ts +43 -0
- package/examples/extensions/file-trigger.ts +41 -0
- package/examples/extensions/git-checkpoint.ts +53 -0
- package/examples/extensions/handoff.ts +150 -0
- package/examples/extensions/hello.ts +25 -0
- package/examples/extensions/inline-bash.ts +94 -0
- package/examples/extensions/input-transform.ts +43 -0
- package/examples/extensions/interactive-shell.ts +196 -0
- package/examples/extensions/mac-system-theme.ts +47 -0
- package/examples/extensions/message-renderer.ts +59 -0
- package/examples/extensions/minimal-mode.ts +426 -0
- package/examples/extensions/modal-editor.ts +85 -0
- package/examples/extensions/model-status.ts +31 -0
- package/examples/extensions/notify.ts +55 -0
- package/examples/extensions/overlay-qa-tests.ts +881 -0
- package/examples/extensions/overlay-test.ts +150 -0
- package/examples/extensions/permission-gate.ts +34 -0
- package/examples/extensions/pirate.ts +47 -0
- package/examples/extensions/plan-mode/README.md +65 -0
- package/examples/extensions/plan-mode/index.ts +340 -0
- package/examples/extensions/plan-mode/utils.ts +168 -0
- package/examples/extensions/preset.ts +398 -0
- package/examples/extensions/protected-paths.ts +30 -0
- package/examples/extensions/qna.ts +119 -0
- package/examples/extensions/question.ts +264 -0
- package/examples/extensions/questionnaire.ts +427 -0
- package/examples/extensions/rainbow-editor.ts +88 -0
- package/examples/extensions/rpc-demo.ts +124 -0
- package/examples/extensions/sandbox/index.ts +318 -0
- package/examples/extensions/sandbox/package-lock.json +92 -0
- package/examples/extensions/sandbox/package.json +19 -0
- package/examples/extensions/send-user-message.ts +97 -0
- package/examples/extensions/session-name.ts +27 -0
- package/examples/extensions/shutdown-command.ts +63 -0
- package/examples/extensions/snake.ts +343 -0
- package/examples/extensions/space-invaders.ts +560 -0
- package/examples/extensions/ssh.ts +220 -0
- package/examples/extensions/status-line.ts +40 -0
- package/examples/extensions/subagent/README.md +172 -0
- package/examples/extensions/subagent/agents/planner.md +37 -0
- package/examples/extensions/subagent/agents/reviewer.md +35 -0
- package/examples/extensions/subagent/agents/scout.md +50 -0
- package/examples/extensions/subagent/agents/worker.md +24 -0
- package/examples/extensions/subagent/agents.ts +127 -0
- package/examples/extensions/subagent/index.ts +963 -0
- package/examples/extensions/subagent/prompts/implement-and-review.md +10 -0
- package/examples/extensions/subagent/prompts/implement.md +10 -0
- package/examples/extensions/subagent/prompts/scout-and-plan.md +9 -0
- package/examples/extensions/summarize.ts +195 -0
- package/examples/extensions/system-prompt-header.ts +17 -0
- package/examples/extensions/timed-confirm.ts +70 -0
- package/examples/extensions/titlebar-spinner.ts +58 -0
- package/examples/extensions/todo.ts +299 -0
- package/examples/extensions/tool-override.ts +143 -0
- package/examples/extensions/tools.ts +146 -0
- package/examples/extensions/trigger-compact.ts +40 -0
- package/examples/extensions/truncated-tool.ts +192 -0
- package/examples/extensions/widget-placement.ts +17 -0
- package/examples/extensions/with-deps/index.ts +36 -0
- package/examples/extensions/with-deps/package-lock.json +31 -0
- package/examples/extensions/with-deps/package.json +22 -0
- package/examples/rpc-extension-ui.ts +632 -0
- package/examples/sdk/01-minimal.ts +22 -0
- package/examples/sdk/02-custom-model.ts +49 -0
- package/examples/sdk/03-custom-prompt.ts +55 -0
- package/examples/sdk/04-skills.ts +46 -0
- package/examples/sdk/05-tools.ts +56 -0
- package/examples/sdk/06-extensions.ts +88 -0
- package/examples/sdk/07-context-files.ts +40 -0
- package/examples/sdk/08-prompt-templates.ts +47 -0
- package/examples/sdk/09-api-keys-and-oauth.ts +48 -0
- package/examples/sdk/10-settings.ts +38 -0
- package/examples/sdk/11-sessions.ts +48 -0
- package/examples/sdk/12-full-control.ts +82 -0
- package/examples/sdk/README.md +144 -0
- package/package.json +97 -0
|
@@ -0,0 +1,1549 @@
|
|
|
1
|
+
(function() {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
// ============================================================
|
|
5
|
+
// DATA LOADING
|
|
6
|
+
// ============================================================
|
|
7
|
+
|
|
8
|
+
const base64 = document.getElementById('session-data').textContent;
|
|
9
|
+
const binary = atob(base64);
|
|
10
|
+
const bytes = new Uint8Array(binary.length);
|
|
11
|
+
for (let i = 0; i < binary.length; i++) {
|
|
12
|
+
bytes[i] = binary.charCodeAt(i);
|
|
13
|
+
}
|
|
14
|
+
const data = JSON.parse(new TextDecoder('utf-8').decode(bytes));
|
|
15
|
+
const { header, entries, leafId: defaultLeafId, systemPrompt, tools, renderedTools } = data;
|
|
16
|
+
|
|
17
|
+
// ============================================================
|
|
18
|
+
// URL PARAMETER HANDLING
|
|
19
|
+
// ============================================================
|
|
20
|
+
|
|
21
|
+
// Parse URL parameters for deep linking: leafId and targetId
|
|
22
|
+
// Check for injected params (when loaded in iframe via srcdoc) or use window.location
|
|
23
|
+
const injectedParams = document.querySelector('meta[name="pi-url-params"]');
|
|
24
|
+
const searchString = injectedParams ? injectedParams.content : window.location.search.substring(1);
|
|
25
|
+
const urlParams = new URLSearchParams(searchString);
|
|
26
|
+
const urlLeafId = urlParams.get('leafId');
|
|
27
|
+
const urlTargetId = urlParams.get('targetId');
|
|
28
|
+
// Use URL leafId if provided, otherwise fall back to session default
|
|
29
|
+
const leafId = urlLeafId || defaultLeafId;
|
|
30
|
+
|
|
31
|
+
// ============================================================
|
|
32
|
+
// DATA STRUCTURES
|
|
33
|
+
// ============================================================
|
|
34
|
+
|
|
35
|
+
// Entry lookup by ID
|
|
36
|
+
const byId = new Map();
|
|
37
|
+
for (const entry of entries) {
|
|
38
|
+
byId.set(entry.id, entry);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Tool call lookup (toolCallId -> {name, arguments})
|
|
42
|
+
const toolCallMap = new Map();
|
|
43
|
+
for (const entry of entries) {
|
|
44
|
+
if (entry.type === 'message' && entry.message.role === 'assistant') {
|
|
45
|
+
const content = entry.message.content;
|
|
46
|
+
if (Array.isArray(content)) {
|
|
47
|
+
for (const block of content) {
|
|
48
|
+
if (block.type === 'toolCall') {
|
|
49
|
+
toolCallMap.set(block.id, { name: block.name, arguments: block.arguments });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Label lookup (entryId -> label string)
|
|
57
|
+
// Labels are stored in 'label' entries that reference their target via targetId
|
|
58
|
+
const labelMap = new Map();
|
|
59
|
+
for (const entry of entries) {
|
|
60
|
+
if (entry.type === 'label' && entry.targetId && entry.label) {
|
|
61
|
+
labelMap.set(entry.targetId, entry.label);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// ============================================================
|
|
66
|
+
// TREE DATA PREPARATION (no DOM, pure data)
|
|
67
|
+
// ============================================================
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Build tree structure from flat entries.
|
|
71
|
+
* Returns array of root nodes, each with { entry, children, label }.
|
|
72
|
+
*/
|
|
73
|
+
function buildTree() {
|
|
74
|
+
const nodeMap = new Map();
|
|
75
|
+
const roots = [];
|
|
76
|
+
|
|
77
|
+
// Create nodes
|
|
78
|
+
for (const entry of entries) {
|
|
79
|
+
nodeMap.set(entry.id, {
|
|
80
|
+
entry,
|
|
81
|
+
children: [],
|
|
82
|
+
label: labelMap.get(entry.id)
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Build parent-child relationships
|
|
87
|
+
for (const entry of entries) {
|
|
88
|
+
const node = nodeMap.get(entry.id);
|
|
89
|
+
if (entry.parentId === null || entry.parentId === undefined || entry.parentId === entry.id) {
|
|
90
|
+
roots.push(node);
|
|
91
|
+
} else {
|
|
92
|
+
const parent = nodeMap.get(entry.parentId);
|
|
93
|
+
if (parent) {
|
|
94
|
+
parent.children.push(node);
|
|
95
|
+
} else {
|
|
96
|
+
roots.push(node);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Sort children by timestamp
|
|
102
|
+
function sortChildren(node) {
|
|
103
|
+
node.children.sort((a, b) =>
|
|
104
|
+
new Date(a.entry.timestamp).getTime() - new Date(b.entry.timestamp).getTime()
|
|
105
|
+
);
|
|
106
|
+
node.children.forEach(sortChildren);
|
|
107
|
+
}
|
|
108
|
+
roots.forEach(sortChildren);
|
|
109
|
+
|
|
110
|
+
return roots;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Build set of entry IDs on path from root to target.
|
|
115
|
+
*/
|
|
116
|
+
function buildActivePathIds(targetId) {
|
|
117
|
+
const ids = new Set();
|
|
118
|
+
let current = byId.get(targetId);
|
|
119
|
+
while (current) {
|
|
120
|
+
ids.add(current.id);
|
|
121
|
+
// Stop if no parent or self-referencing (root)
|
|
122
|
+
if (!current.parentId || current.parentId === current.id) {
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
current = byId.get(current.parentId);
|
|
126
|
+
}
|
|
127
|
+
return ids;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Get array of entries from root to target (the conversation path).
|
|
132
|
+
*/
|
|
133
|
+
function getPath(targetId) {
|
|
134
|
+
const path = [];
|
|
135
|
+
let current = byId.get(targetId);
|
|
136
|
+
while (current) {
|
|
137
|
+
path.unshift(current);
|
|
138
|
+
// Stop if no parent or self-referencing (root)
|
|
139
|
+
if (!current.parentId || current.parentId === current.id) {
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
current = byId.get(current.parentId);
|
|
143
|
+
}
|
|
144
|
+
return path;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Tree node lookup for finding leaves
|
|
148
|
+
let treeNodeMap = null;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Find the newest leaf node reachable from a given node.
|
|
152
|
+
* This allows clicking any node in a branch to show the full branch.
|
|
153
|
+
* Children are sorted by timestamp, so the newest is always last.
|
|
154
|
+
*/
|
|
155
|
+
function findNewestLeaf(nodeId) {
|
|
156
|
+
// Build tree node map lazily
|
|
157
|
+
if (!treeNodeMap) {
|
|
158
|
+
treeNodeMap = new Map();
|
|
159
|
+
const tree = buildTree();
|
|
160
|
+
function mapNodes(node) {
|
|
161
|
+
treeNodeMap.set(node.entry.id, node);
|
|
162
|
+
node.children.forEach(mapNodes);
|
|
163
|
+
}
|
|
164
|
+
tree.forEach(mapNodes);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const node = treeNodeMap.get(nodeId);
|
|
168
|
+
if (!node) return nodeId;
|
|
169
|
+
|
|
170
|
+
// Follow the newest (last) child at each level
|
|
171
|
+
let current = node;
|
|
172
|
+
while (current.children.length > 0) {
|
|
173
|
+
current = current.children[current.children.length - 1];
|
|
174
|
+
}
|
|
175
|
+
return current.entry.id;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Flatten tree into list with indentation and connector info.
|
|
180
|
+
* Returns array of { node, indent, showConnector, isLast, gutters, isVirtualRootChild, multipleRoots }.
|
|
181
|
+
* Matches tree-selector.ts logic exactly.
|
|
182
|
+
*/
|
|
183
|
+
function flattenTree(roots, activePathIds) {
|
|
184
|
+
const result = [];
|
|
185
|
+
const multipleRoots = roots.length > 1;
|
|
186
|
+
|
|
187
|
+
// Mark which subtrees contain the active leaf
|
|
188
|
+
const containsActive = new Map();
|
|
189
|
+
function markActive(node) {
|
|
190
|
+
let has = activePathIds.has(node.entry.id);
|
|
191
|
+
for (const child of node.children) {
|
|
192
|
+
if (markActive(child)) has = true;
|
|
193
|
+
}
|
|
194
|
+
containsActive.set(node, has);
|
|
195
|
+
return has;
|
|
196
|
+
}
|
|
197
|
+
roots.forEach(markActive);
|
|
198
|
+
|
|
199
|
+
// Stack: [node, indent, justBranched, showConnector, isLast, gutters, isVirtualRootChild]
|
|
200
|
+
const stack = [];
|
|
201
|
+
|
|
202
|
+
// Add roots (prioritize branch containing active leaf)
|
|
203
|
+
const orderedRoots = [...roots].sort((a, b) =>
|
|
204
|
+
Number(containsActive.get(b)) - Number(containsActive.get(a))
|
|
205
|
+
);
|
|
206
|
+
for (let i = orderedRoots.length - 1; i >= 0; i--) {
|
|
207
|
+
const isLast = i === orderedRoots.length - 1;
|
|
208
|
+
stack.push([orderedRoots[i], multipleRoots ? 1 : 0, multipleRoots, multipleRoots, isLast, [], multipleRoots]);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
while (stack.length > 0) {
|
|
212
|
+
const [node, indent, justBranched, showConnector, isLast, gutters, isVirtualRootChild] = stack.pop();
|
|
213
|
+
|
|
214
|
+
result.push({ node, indent, showConnector, isLast, gutters, isVirtualRootChild, multipleRoots });
|
|
215
|
+
|
|
216
|
+
const children = node.children;
|
|
217
|
+
const multipleChildren = children.length > 1;
|
|
218
|
+
|
|
219
|
+
// Order children (active branch first)
|
|
220
|
+
const orderedChildren = [...children].sort((a, b) =>
|
|
221
|
+
Number(containsActive.get(b)) - Number(containsActive.get(a))
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
// Calculate child indent (matches tree-selector.ts)
|
|
225
|
+
let childIndent;
|
|
226
|
+
if (multipleChildren) {
|
|
227
|
+
// Parent branches: children get +1
|
|
228
|
+
childIndent = indent + 1;
|
|
229
|
+
} else if (justBranched && indent > 0) {
|
|
230
|
+
// First generation after a branch: +1 for visual grouping
|
|
231
|
+
childIndent = indent + 1;
|
|
232
|
+
} else {
|
|
233
|
+
// Single-child chain: stay flat
|
|
234
|
+
childIndent = indent;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// Build gutters for children
|
|
238
|
+
const connectorDisplayed = showConnector && !isVirtualRootChild;
|
|
239
|
+
const currentDisplayIndent = multipleRoots ? Math.max(0, indent - 1) : indent;
|
|
240
|
+
const connectorPosition = Math.max(0, currentDisplayIndent - 1);
|
|
241
|
+
const childGutters = connectorDisplayed
|
|
242
|
+
? [...gutters, { position: connectorPosition, show: !isLast }]
|
|
243
|
+
: gutters;
|
|
244
|
+
|
|
245
|
+
// Add children in reverse order for stack
|
|
246
|
+
for (let i = orderedChildren.length - 1; i >= 0; i--) {
|
|
247
|
+
const childIsLast = i === orderedChildren.length - 1;
|
|
248
|
+
stack.push([orderedChildren[i], childIndent, multipleChildren, multipleChildren, childIsLast, childGutters, false]);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
return result;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Build ASCII prefix string for tree node.
|
|
257
|
+
*/
|
|
258
|
+
function buildTreePrefix(flatNode) {
|
|
259
|
+
const { indent, showConnector, isLast, gutters, isVirtualRootChild, multipleRoots } = flatNode;
|
|
260
|
+
const displayIndent = multipleRoots ? Math.max(0, indent - 1) : indent;
|
|
261
|
+
const connector = showConnector && !isVirtualRootChild ? (isLast ? '└─ ' : '├─ ') : '';
|
|
262
|
+
const connectorPosition = connector ? displayIndent - 1 : -1;
|
|
263
|
+
|
|
264
|
+
const totalChars = displayIndent * 3;
|
|
265
|
+
const prefixChars = [];
|
|
266
|
+
for (let i = 0; i < totalChars; i++) {
|
|
267
|
+
const level = Math.floor(i / 3);
|
|
268
|
+
const posInLevel = i % 3;
|
|
269
|
+
|
|
270
|
+
const gutter = gutters.find(g => g.position === level);
|
|
271
|
+
if (gutter) {
|
|
272
|
+
prefixChars.push(posInLevel === 0 ? (gutter.show ? '│' : ' ') : ' ');
|
|
273
|
+
} else if (connector && level === connectorPosition) {
|
|
274
|
+
if (posInLevel === 0) {
|
|
275
|
+
prefixChars.push(isLast ? '└' : '├');
|
|
276
|
+
} else if (posInLevel === 1) {
|
|
277
|
+
prefixChars.push('─');
|
|
278
|
+
} else {
|
|
279
|
+
prefixChars.push(' ');
|
|
280
|
+
}
|
|
281
|
+
} else {
|
|
282
|
+
prefixChars.push(' ');
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return prefixChars.join('');
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// ============================================================
|
|
289
|
+
// FILTERING (pure data)
|
|
290
|
+
// ============================================================
|
|
291
|
+
|
|
292
|
+
let filterMode = 'default';
|
|
293
|
+
let searchQuery = '';
|
|
294
|
+
|
|
295
|
+
function hasTextContent(content) {
|
|
296
|
+
if (typeof content === 'string') return content.trim().length > 0;
|
|
297
|
+
if (Array.isArray(content)) {
|
|
298
|
+
for (const c of content) {
|
|
299
|
+
if (c.type === 'text' && c.text && c.text.trim().length > 0) return true;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
return false;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function extractContent(content) {
|
|
306
|
+
if (typeof content === 'string') return content;
|
|
307
|
+
if (Array.isArray(content)) {
|
|
308
|
+
return content
|
|
309
|
+
.filter(c => c.type === 'text' && c.text)
|
|
310
|
+
.map(c => c.text)
|
|
311
|
+
.join('');
|
|
312
|
+
}
|
|
313
|
+
return '';
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function getSearchableText(entry, label) {
|
|
317
|
+
const parts = [];
|
|
318
|
+
if (label) parts.push(label);
|
|
319
|
+
|
|
320
|
+
switch (entry.type) {
|
|
321
|
+
case 'message': {
|
|
322
|
+
const msg = entry.message;
|
|
323
|
+
parts.push(msg.role);
|
|
324
|
+
if (msg.content) parts.push(extractContent(msg.content));
|
|
325
|
+
if (msg.role === 'bashExecution' && msg.command) parts.push(msg.command);
|
|
326
|
+
break;
|
|
327
|
+
}
|
|
328
|
+
case 'custom_message':
|
|
329
|
+
parts.push(entry.customType);
|
|
330
|
+
parts.push(typeof entry.content === 'string' ? entry.content : extractContent(entry.content));
|
|
331
|
+
break;
|
|
332
|
+
case 'compaction':
|
|
333
|
+
parts.push('compaction');
|
|
334
|
+
break;
|
|
335
|
+
case 'branch_summary':
|
|
336
|
+
parts.push('branch summary', entry.summary);
|
|
337
|
+
break;
|
|
338
|
+
case 'model_change':
|
|
339
|
+
parts.push('model', entry.modelId);
|
|
340
|
+
break;
|
|
341
|
+
case 'thinking_level_change':
|
|
342
|
+
parts.push('thinking', entry.thinkingLevel);
|
|
343
|
+
break;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
return parts.join(' ').toLowerCase();
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Filter flat nodes based on current filterMode and searchQuery.
|
|
351
|
+
*/
|
|
352
|
+
function filterNodes(flatNodes, currentLeafId) {
|
|
353
|
+
const searchTokens = searchQuery.toLowerCase().split(/\s+/).filter(Boolean);
|
|
354
|
+
|
|
355
|
+
const filtered = flatNodes.filter(flatNode => {
|
|
356
|
+
const entry = flatNode.node.entry;
|
|
357
|
+
const label = flatNode.node.label;
|
|
358
|
+
const isCurrentLeaf = entry.id === currentLeafId;
|
|
359
|
+
|
|
360
|
+
// Always show current leaf
|
|
361
|
+
if (isCurrentLeaf) return true;
|
|
362
|
+
|
|
363
|
+
// Hide assistant messages with only tool calls (no text) unless error/aborted
|
|
364
|
+
if (entry.type === 'message' && entry.message.role === 'assistant') {
|
|
365
|
+
const msg = entry.message;
|
|
366
|
+
const hasText = hasTextContent(msg.content);
|
|
367
|
+
const isErrorOrAborted = msg.stopReason && msg.stopReason !== 'stop' && msg.stopReason !== 'toolUse';
|
|
368
|
+
if (!hasText && !isErrorOrAborted) return false;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// Apply filter mode
|
|
372
|
+
const isSettingsEntry = ['label', 'custom', 'model_change', 'thinking_level_change'].includes(entry.type);
|
|
373
|
+
let passesFilter = true;
|
|
374
|
+
|
|
375
|
+
switch (filterMode) {
|
|
376
|
+
case 'user-only':
|
|
377
|
+
passesFilter = entry.type === 'message' && entry.message.role === 'user';
|
|
378
|
+
break;
|
|
379
|
+
case 'no-tools':
|
|
380
|
+
passesFilter = !isSettingsEntry && !(entry.type === 'message' && entry.message.role === 'toolResult');
|
|
381
|
+
break;
|
|
382
|
+
case 'labeled-only':
|
|
383
|
+
passesFilter = label !== undefined;
|
|
384
|
+
break;
|
|
385
|
+
case 'all':
|
|
386
|
+
passesFilter = true;
|
|
387
|
+
break;
|
|
388
|
+
default: // 'default'
|
|
389
|
+
passesFilter = !isSettingsEntry;
|
|
390
|
+
break;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
if (!passesFilter) return false;
|
|
394
|
+
|
|
395
|
+
// Apply search filter
|
|
396
|
+
if (searchTokens.length > 0) {
|
|
397
|
+
const nodeText = getSearchableText(entry, label);
|
|
398
|
+
if (!searchTokens.every(t => nodeText.includes(t))) return false;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
return true;
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
// Recalculate visual structure based on visible tree
|
|
405
|
+
recalculateVisualStructure(filtered, flatNodes);
|
|
406
|
+
|
|
407
|
+
return filtered;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* Recompute indentation/connectors for the filtered view
|
|
412
|
+
*
|
|
413
|
+
* Filtering can hide intermediate entries; descendants attach to the nearest visible ancestor.
|
|
414
|
+
* Keep indentation semantics aligned with flattenTree() so single-child chains don't drift right.
|
|
415
|
+
*/
|
|
416
|
+
function recalculateVisualStructure(filteredNodes, allFlatNodes) {
|
|
417
|
+
if (filteredNodes.length === 0) return;
|
|
418
|
+
|
|
419
|
+
const visibleIds = new Set(filteredNodes.map(n => n.node.entry.id));
|
|
420
|
+
|
|
421
|
+
// Build entry map for parent lookup (using full tree)
|
|
422
|
+
const entryMap = new Map();
|
|
423
|
+
for (const flatNode of allFlatNodes) {
|
|
424
|
+
entryMap.set(flatNode.node.entry.id, flatNode);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
// Find nearest visible ancestor for a node
|
|
428
|
+
function findVisibleAncestor(nodeId) {
|
|
429
|
+
let currentId = entryMap.get(nodeId)?.node.entry.parentId;
|
|
430
|
+
while (currentId != null) {
|
|
431
|
+
if (visibleIds.has(currentId)) {
|
|
432
|
+
return currentId;
|
|
433
|
+
}
|
|
434
|
+
currentId = entryMap.get(currentId)?.node.entry.parentId;
|
|
435
|
+
}
|
|
436
|
+
return null;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// Build visible tree structure
|
|
440
|
+
const visibleParent = new Map();
|
|
441
|
+
const visibleChildren = new Map();
|
|
442
|
+
visibleChildren.set(null, []); // root-level nodes
|
|
443
|
+
|
|
444
|
+
for (const flatNode of filteredNodes) {
|
|
445
|
+
const nodeId = flatNode.node.entry.id;
|
|
446
|
+
const ancestorId = findVisibleAncestor(nodeId);
|
|
447
|
+
visibleParent.set(nodeId, ancestorId);
|
|
448
|
+
|
|
449
|
+
if (!visibleChildren.has(ancestorId)) {
|
|
450
|
+
visibleChildren.set(ancestorId, []);
|
|
451
|
+
}
|
|
452
|
+
visibleChildren.get(ancestorId).push(nodeId);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
// Update multipleRoots based on visible roots
|
|
456
|
+
const visibleRootIds = visibleChildren.get(null);
|
|
457
|
+
const multipleRoots = visibleRootIds.length > 1;
|
|
458
|
+
|
|
459
|
+
// Build a map for quick lookup: nodeId → FlatNode
|
|
460
|
+
const filteredNodeMap = new Map();
|
|
461
|
+
for (const flatNode of filteredNodes) {
|
|
462
|
+
filteredNodeMap.set(flatNode.node.entry.id, flatNode);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
// DFS traversal of visible tree, applying same indentation rules as flattenTree()
|
|
466
|
+
// Stack items: [nodeId, indent, justBranched, showConnector, isLast, gutters, isVirtualRootChild]
|
|
467
|
+
const stack = [];
|
|
468
|
+
|
|
469
|
+
// Add visible roots in reverse order (to process in forward order via stack)
|
|
470
|
+
for (let i = visibleRootIds.length - 1; i >= 0; i--) {
|
|
471
|
+
const isLast = i === visibleRootIds.length - 1;
|
|
472
|
+
stack.push([
|
|
473
|
+
visibleRootIds[i],
|
|
474
|
+
multipleRoots ? 1 : 0,
|
|
475
|
+
multipleRoots,
|
|
476
|
+
multipleRoots,
|
|
477
|
+
isLast,
|
|
478
|
+
[],
|
|
479
|
+
multipleRoots
|
|
480
|
+
]);
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
while (stack.length > 0) {
|
|
484
|
+
const [nodeId, indent, justBranched, showConnector, isLast, gutters, isVirtualRootChild] = stack.pop();
|
|
485
|
+
|
|
486
|
+
const flatNode = filteredNodeMap.get(nodeId);
|
|
487
|
+
if (!flatNode) continue;
|
|
488
|
+
|
|
489
|
+
// Update this node's visual properties
|
|
490
|
+
flatNode.indent = indent;
|
|
491
|
+
flatNode.showConnector = showConnector;
|
|
492
|
+
flatNode.isLast = isLast;
|
|
493
|
+
flatNode.gutters = gutters;
|
|
494
|
+
flatNode.isVirtualRootChild = isVirtualRootChild;
|
|
495
|
+
flatNode.multipleRoots = multipleRoots;
|
|
496
|
+
|
|
497
|
+
// Get visible children of this node
|
|
498
|
+
const children = visibleChildren.get(nodeId) || [];
|
|
499
|
+
const multipleChildren = children.length > 1;
|
|
500
|
+
|
|
501
|
+
// Calculate child indent using same rules as flattenTree():
|
|
502
|
+
// - Parent branches (multiple children): children get +1
|
|
503
|
+
// - Just branched and indent > 0: children get +1 for visual grouping
|
|
504
|
+
// - Single-child chain: stay flat
|
|
505
|
+
let childIndent;
|
|
506
|
+
if (multipleChildren) {
|
|
507
|
+
childIndent = indent + 1;
|
|
508
|
+
} else if (justBranched && indent > 0) {
|
|
509
|
+
childIndent = indent + 1;
|
|
510
|
+
} else {
|
|
511
|
+
childIndent = indent;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
// Build gutters for children (same logic as flattenTree)
|
|
515
|
+
const connectorDisplayed = showConnector && !isVirtualRootChild;
|
|
516
|
+
const currentDisplayIndent = multipleRoots ? Math.max(0, indent - 1) : indent;
|
|
517
|
+
const connectorPosition = Math.max(0, currentDisplayIndent - 1);
|
|
518
|
+
const childGutters = connectorDisplayed
|
|
519
|
+
? [...gutters, { position: connectorPosition, show: !isLast }]
|
|
520
|
+
: gutters;
|
|
521
|
+
|
|
522
|
+
// Add children in reverse order (to process in forward order via stack)
|
|
523
|
+
for (let i = children.length - 1; i >= 0; i--) {
|
|
524
|
+
const childIsLast = i === children.length - 1;
|
|
525
|
+
stack.push([
|
|
526
|
+
children[i],
|
|
527
|
+
childIndent,
|
|
528
|
+
multipleChildren,
|
|
529
|
+
multipleChildren,
|
|
530
|
+
childIsLast,
|
|
531
|
+
childGutters,
|
|
532
|
+
false
|
|
533
|
+
]);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
// ============================================================
|
|
539
|
+
// TREE DISPLAY TEXT (pure data -> string)
|
|
540
|
+
// ============================================================
|
|
541
|
+
|
|
542
|
+
function shortenPath(p) {
|
|
543
|
+
if (p.startsWith('/Users/')) {
|
|
544
|
+
const parts = p.split('/');
|
|
545
|
+
if (parts.length > 2) return '~' + p.slice(('/Users/' + parts[2]).length);
|
|
546
|
+
}
|
|
547
|
+
if (p.startsWith('/home/')) {
|
|
548
|
+
const parts = p.split('/');
|
|
549
|
+
if (parts.length > 2) return '~' + p.slice(('/home/' + parts[2]).length);
|
|
550
|
+
}
|
|
551
|
+
return p;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
function formatToolCall(name, args) {
|
|
555
|
+
switch (name) {
|
|
556
|
+
case 'read': {
|
|
557
|
+
const path = shortenPath(String(args.path || args.file_path || ''));
|
|
558
|
+
const offset = args.offset;
|
|
559
|
+
const limit = args.limit;
|
|
560
|
+
let display = path;
|
|
561
|
+
if (offset !== undefined || limit !== undefined) {
|
|
562
|
+
const start = offset ?? 1;
|
|
563
|
+
const end = limit !== undefined ? start + limit - 1 : '';
|
|
564
|
+
display += `:${start}${end ? `-${end}` : ''}`;
|
|
565
|
+
}
|
|
566
|
+
return `[read: ${display}]`;
|
|
567
|
+
}
|
|
568
|
+
case 'write':
|
|
569
|
+
return `[write: ${shortenPath(String(args.path || args.file_path || ''))}]`;
|
|
570
|
+
case 'edit':
|
|
571
|
+
return `[edit: ${shortenPath(String(args.path || args.file_path || ''))}]`;
|
|
572
|
+
case 'bash': {
|
|
573
|
+
const rawCmd = String(args.command || '');
|
|
574
|
+
const cmd = rawCmd.replace(/[\n\t]/g, ' ').trim().slice(0, 50);
|
|
575
|
+
return `[bash: ${cmd}${rawCmd.length > 50 ? '...' : ''}]`;
|
|
576
|
+
}
|
|
577
|
+
case 'grep':
|
|
578
|
+
return `[grep: /${args.pattern || ''}/ in ${shortenPath(String(args.path || '.'))}]`;
|
|
579
|
+
case 'find':
|
|
580
|
+
return `[find: ${args.pattern || ''} in ${shortenPath(String(args.path || '.'))}]`;
|
|
581
|
+
case 'ls':
|
|
582
|
+
return `[ls: ${shortenPath(String(args.path || '.'))}]`;
|
|
583
|
+
default: {
|
|
584
|
+
const argsStr = JSON.stringify(args).slice(0, 40);
|
|
585
|
+
return `[${name}: ${argsStr}${JSON.stringify(args).length > 40 ? '...' : ''}]`;
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
function escapeHtml(text) {
|
|
591
|
+
const div = document.createElement('div');
|
|
592
|
+
div.textContent = text;
|
|
593
|
+
return div.innerHTML;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* Truncate string to maxLen chars, append "..." if truncated.
|
|
598
|
+
*/
|
|
599
|
+
function truncate(s, maxLen = 100) {
|
|
600
|
+
if (s.length <= maxLen) return s;
|
|
601
|
+
return s.slice(0, maxLen) + '...';
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
/**
|
|
605
|
+
* Get display text for tree node (returns HTML string).
|
|
606
|
+
*/
|
|
607
|
+
function getTreeNodeDisplayHtml(entry, label) {
|
|
608
|
+
const normalize = s => s.replace(/[\n\t]/g, ' ').trim();
|
|
609
|
+
const labelHtml = label ? `<span class="tree-label">[${escapeHtml(label)}]</span> ` : '';
|
|
610
|
+
|
|
611
|
+
switch (entry.type) {
|
|
612
|
+
case 'message': {
|
|
613
|
+
const msg = entry.message;
|
|
614
|
+
if (msg.role === 'user') {
|
|
615
|
+
const content = truncate(normalize(extractContent(msg.content)));
|
|
616
|
+
return labelHtml + `<span class="tree-role-user">user:</span> ${escapeHtml(content)}`;
|
|
617
|
+
}
|
|
618
|
+
if (msg.role === 'assistant') {
|
|
619
|
+
const textContent = truncate(normalize(extractContent(msg.content)));
|
|
620
|
+
if (textContent) {
|
|
621
|
+
return labelHtml + `<span class="tree-role-assistant">assistant:</span> ${escapeHtml(textContent)}`;
|
|
622
|
+
}
|
|
623
|
+
if (msg.stopReason === 'aborted') {
|
|
624
|
+
return labelHtml + `<span class="tree-role-assistant">assistant:</span> <span class="tree-muted">(aborted)</span>`;
|
|
625
|
+
}
|
|
626
|
+
if (msg.errorMessage) {
|
|
627
|
+
return labelHtml + `<span class="tree-role-assistant">assistant:</span> <span class="tree-error">${escapeHtml(truncate(msg.errorMessage))}</span>`;
|
|
628
|
+
}
|
|
629
|
+
return labelHtml + `<span class="tree-role-assistant">assistant:</span> <span class="tree-muted">(no text)</span>`;
|
|
630
|
+
}
|
|
631
|
+
if (msg.role === 'toolResult') {
|
|
632
|
+
const toolCall = msg.toolCallId ? toolCallMap.get(msg.toolCallId) : null;
|
|
633
|
+
if (toolCall) {
|
|
634
|
+
return labelHtml + `<span class="tree-role-tool">${escapeHtml(formatToolCall(toolCall.name, toolCall.arguments))}</span>`;
|
|
635
|
+
}
|
|
636
|
+
return labelHtml + `<span class="tree-role-tool">[${msg.toolName || 'tool'}]</span>`;
|
|
637
|
+
}
|
|
638
|
+
if (msg.role === 'bashExecution') {
|
|
639
|
+
const cmd = truncate(normalize(msg.command || ''));
|
|
640
|
+
return labelHtml + `<span class="tree-role-tool">[bash]:</span> ${escapeHtml(cmd)}`;
|
|
641
|
+
}
|
|
642
|
+
return labelHtml + `<span class="tree-muted">[${msg.role}]</span>`;
|
|
643
|
+
}
|
|
644
|
+
case 'compaction':
|
|
645
|
+
return labelHtml + `<span class="tree-compaction">[compaction: ${Math.round(entry.tokensBefore/1000)}k tokens]</span>`;
|
|
646
|
+
case 'branch_summary': {
|
|
647
|
+
const summary = truncate(normalize(entry.summary || ''));
|
|
648
|
+
return labelHtml + `<span class="tree-branch-summary">[branch summary]:</span> ${escapeHtml(summary)}`;
|
|
649
|
+
}
|
|
650
|
+
case 'custom_message': {
|
|
651
|
+
const content = typeof entry.content === 'string' ? entry.content : extractContent(entry.content);
|
|
652
|
+
return labelHtml + `<span class="tree-custom">[${escapeHtml(entry.customType)}]:</span> ${escapeHtml(truncate(normalize(content)))}`;
|
|
653
|
+
}
|
|
654
|
+
case 'model_change':
|
|
655
|
+
return labelHtml + `<span class="tree-muted">[model: ${entry.modelId}]</span>`;
|
|
656
|
+
case 'thinking_level_change':
|
|
657
|
+
return labelHtml + `<span class="tree-muted">[thinking: ${entry.thinkingLevel}]</span>`;
|
|
658
|
+
default:
|
|
659
|
+
return labelHtml + `<span class="tree-muted">[${entry.type}]</span>`;
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
// ============================================================
|
|
664
|
+
// TREE RENDERING (DOM manipulation)
|
|
665
|
+
// ============================================================
|
|
666
|
+
|
|
667
|
+
let currentLeafId = leafId;
|
|
668
|
+
let currentTargetId = urlTargetId || leafId;
|
|
669
|
+
let treeRendered = false;
|
|
670
|
+
|
|
671
|
+
function renderTree() {
|
|
672
|
+
const tree = buildTree();
|
|
673
|
+
const activePathIds = buildActivePathIds(currentLeafId);
|
|
674
|
+
const flatNodes = flattenTree(tree, activePathIds);
|
|
675
|
+
const filtered = filterNodes(flatNodes, currentLeafId);
|
|
676
|
+
const container = document.getElementById('tree-container');
|
|
677
|
+
|
|
678
|
+
// Full render only on first call or when filter/search changes
|
|
679
|
+
if (!treeRendered) {
|
|
680
|
+
container.innerHTML = '';
|
|
681
|
+
|
|
682
|
+
for (const flatNode of filtered) {
|
|
683
|
+
const entry = flatNode.node.entry;
|
|
684
|
+
const isOnPath = activePathIds.has(entry.id);
|
|
685
|
+
const isTarget = entry.id === currentTargetId;
|
|
686
|
+
|
|
687
|
+
const div = document.createElement('div');
|
|
688
|
+
div.className = 'tree-node';
|
|
689
|
+
if (isOnPath) div.classList.add('in-path');
|
|
690
|
+
if (isTarget) div.classList.add('active');
|
|
691
|
+
div.dataset.id = entry.id;
|
|
692
|
+
|
|
693
|
+
const prefix = buildTreePrefix(flatNode);
|
|
694
|
+
const prefixSpan = document.createElement('span');
|
|
695
|
+
prefixSpan.className = 'tree-prefix';
|
|
696
|
+
prefixSpan.textContent = prefix;
|
|
697
|
+
|
|
698
|
+
const marker = document.createElement('span');
|
|
699
|
+
marker.className = 'tree-marker';
|
|
700
|
+
marker.textContent = isOnPath ? '•' : ' ';
|
|
701
|
+
|
|
702
|
+
const content = document.createElement('span');
|
|
703
|
+
content.className = 'tree-content';
|
|
704
|
+
content.innerHTML = getTreeNodeDisplayHtml(entry, flatNode.node.label);
|
|
705
|
+
|
|
706
|
+
div.appendChild(prefixSpan);
|
|
707
|
+
div.appendChild(marker);
|
|
708
|
+
div.appendChild(content);
|
|
709
|
+
// Navigate to the newest leaf through this node, but scroll to the clicked node
|
|
710
|
+
div.addEventListener('click', () => {
|
|
711
|
+
const leafId = findNewestLeaf(entry.id);
|
|
712
|
+
navigateTo(leafId, 'target', entry.id);
|
|
713
|
+
});
|
|
714
|
+
|
|
715
|
+
container.appendChild(div);
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
treeRendered = true;
|
|
719
|
+
} else {
|
|
720
|
+
// Just update markers and classes
|
|
721
|
+
const nodes = container.querySelectorAll('.tree-node');
|
|
722
|
+
for (const node of nodes) {
|
|
723
|
+
const id = node.dataset.id;
|
|
724
|
+
const isOnPath = activePathIds.has(id);
|
|
725
|
+
const isTarget = id === currentTargetId;
|
|
726
|
+
|
|
727
|
+
node.classList.toggle('in-path', isOnPath);
|
|
728
|
+
node.classList.toggle('active', isTarget);
|
|
729
|
+
|
|
730
|
+
const marker = node.querySelector('.tree-marker');
|
|
731
|
+
if (marker) {
|
|
732
|
+
marker.textContent = isOnPath ? '•' : ' ';
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
document.getElementById('tree-status').textContent = `${filtered.length} / ${flatNodes.length} entries`;
|
|
738
|
+
|
|
739
|
+
// Scroll active node into view after layout
|
|
740
|
+
setTimeout(() => {
|
|
741
|
+
const activeNode = container.querySelector('.tree-node.active');
|
|
742
|
+
if (activeNode) {
|
|
743
|
+
activeNode.scrollIntoView({ block: 'nearest' });
|
|
744
|
+
}
|
|
745
|
+
}, 0);
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
function forceTreeRerender() {
|
|
749
|
+
treeRendered = false;
|
|
750
|
+
renderTree();
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
// ============================================================
|
|
754
|
+
// MESSAGE RENDERING
|
|
755
|
+
// ============================================================
|
|
756
|
+
|
|
757
|
+
function formatTokens(count) {
|
|
758
|
+
if (count < 1000) return count.toString();
|
|
759
|
+
if (count < 10000) return (count / 1000).toFixed(1) + 'k';
|
|
760
|
+
if (count < 1000000) return Math.round(count / 1000) + 'k';
|
|
761
|
+
return (count / 1000000).toFixed(1) + 'M';
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
function formatTimestamp(ts) {
|
|
765
|
+
if (!ts) return '';
|
|
766
|
+
const date = new Date(ts);
|
|
767
|
+
return date.toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit', second: '2-digit' });
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
function replaceTabs(text) {
|
|
771
|
+
return text.replace(/\t/g, ' ');
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
function getLanguageFromPath(filePath) {
|
|
775
|
+
const ext = filePath.split('.').pop()?.toLowerCase();
|
|
776
|
+
const extToLang = {
|
|
777
|
+
ts: 'typescript', tsx: 'typescript', js: 'javascript', jsx: 'javascript',
|
|
778
|
+
py: 'python', rb: 'ruby', rs: 'rust', go: 'go', java: 'java',
|
|
779
|
+
c: 'c', cpp: 'cpp', h: 'c', hpp: 'cpp', cs: 'csharp',
|
|
780
|
+
php: 'php', sh: 'bash', bash: 'bash', zsh: 'bash',
|
|
781
|
+
sql: 'sql', html: 'html', css: 'css', scss: 'scss',
|
|
782
|
+
json: 'json', yaml: 'yaml', yml: 'yaml', xml: 'xml',
|
|
783
|
+
md: 'markdown', dockerfile: 'dockerfile'
|
|
784
|
+
};
|
|
785
|
+
return extToLang[ext];
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
function findToolResult(toolCallId) {
|
|
789
|
+
for (const entry of entries) {
|
|
790
|
+
if (entry.type === 'message' && entry.message.role === 'toolResult') {
|
|
791
|
+
if (entry.message.toolCallId === toolCallId) {
|
|
792
|
+
return entry.message;
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
return null;
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
function formatExpandableOutput(text, maxLines, lang) {
|
|
800
|
+
text = replaceTabs(text);
|
|
801
|
+
const lines = text.split('\n');
|
|
802
|
+
const displayLines = lines.slice(0, maxLines);
|
|
803
|
+
const remaining = lines.length - maxLines;
|
|
804
|
+
|
|
805
|
+
if (lang) {
|
|
806
|
+
let highlighted;
|
|
807
|
+
try {
|
|
808
|
+
highlighted = hljs.highlight(text, { language: lang }).value;
|
|
809
|
+
} catch {
|
|
810
|
+
highlighted = escapeHtml(text);
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
if (remaining > 0) {
|
|
814
|
+
const previewCode = displayLines.join('\n');
|
|
815
|
+
let previewHighlighted;
|
|
816
|
+
try {
|
|
817
|
+
previewHighlighted = hljs.highlight(previewCode, { language: lang }).value;
|
|
818
|
+
} catch {
|
|
819
|
+
previewHighlighted = escapeHtml(previewCode);
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
return `<div class="tool-output expandable" onclick="this.classList.toggle('expanded')">
|
|
823
|
+
<div class="output-preview"><pre><code class="hljs">${previewHighlighted}</code></pre>
|
|
824
|
+
<div class="expand-hint">... (${remaining} more lines)</div></div>
|
|
825
|
+
<div class="output-full"><pre><code class="hljs">${highlighted}</code></pre></div></div>`;
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
return `<div class="tool-output"><pre><code class="hljs">${highlighted}</code></pre></div>`;
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
// Plain text output
|
|
832
|
+
if (remaining > 0) {
|
|
833
|
+
let out = '<div class="tool-output expandable" onclick="this.classList.toggle(\'expanded\')">';
|
|
834
|
+
out += '<div class="output-preview">';
|
|
835
|
+
for (const line of displayLines) {
|
|
836
|
+
out += `<div>${escapeHtml(replaceTabs(line))}</div>`;
|
|
837
|
+
}
|
|
838
|
+
out += `<div class="expand-hint">... (${remaining} more lines)</div></div>`;
|
|
839
|
+
out += '<div class="output-full">';
|
|
840
|
+
for (const line of lines) {
|
|
841
|
+
out += `<div>${escapeHtml(replaceTabs(line))}</div>`;
|
|
842
|
+
}
|
|
843
|
+
out += '</div></div>';
|
|
844
|
+
return out;
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
let out = '<div class="tool-output">';
|
|
848
|
+
for (const line of displayLines) {
|
|
849
|
+
out += `<div>${escapeHtml(replaceTabs(line))}</div>`;
|
|
850
|
+
}
|
|
851
|
+
out += '</div>';
|
|
852
|
+
return out;
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
function renderToolCall(call) {
|
|
856
|
+
const result = findToolResult(call.id);
|
|
857
|
+
const isError = result?.isError || false;
|
|
858
|
+
const statusClass = result ? (isError ? 'error' : 'success') : 'pending';
|
|
859
|
+
|
|
860
|
+
const getResultText = () => {
|
|
861
|
+
if (!result) return '';
|
|
862
|
+
const textBlocks = result.content.filter(c => c.type === 'text');
|
|
863
|
+
return textBlocks.map(c => c.text).join('\n');
|
|
864
|
+
};
|
|
865
|
+
|
|
866
|
+
const getResultImages = () => {
|
|
867
|
+
if (!result) return [];
|
|
868
|
+
return result.content.filter(c => c.type === 'image');
|
|
869
|
+
};
|
|
870
|
+
|
|
871
|
+
const renderResultImages = () => {
|
|
872
|
+
const images = getResultImages();
|
|
873
|
+
if (images.length === 0) return '';
|
|
874
|
+
return '<div class="tool-images">' +
|
|
875
|
+
images.map(img => `<img src="data:${img.mimeType};base64,${img.data}" class="tool-image" />`).join('') +
|
|
876
|
+
'</div>';
|
|
877
|
+
};
|
|
878
|
+
|
|
879
|
+
let html = `<div class="tool-execution ${statusClass}">`;
|
|
880
|
+
const args = call.arguments || {};
|
|
881
|
+
const name = call.name;
|
|
882
|
+
|
|
883
|
+
switch (name) {
|
|
884
|
+
case 'bash': {
|
|
885
|
+
const command = args.command || '';
|
|
886
|
+
html += `<div class="tool-command">$ ${escapeHtml(command)}</div>`;
|
|
887
|
+
if (result) {
|
|
888
|
+
const output = getResultText().trim();
|
|
889
|
+
if (output) html += formatExpandableOutput(output, 5);
|
|
890
|
+
}
|
|
891
|
+
break;
|
|
892
|
+
}
|
|
893
|
+
case 'read': {
|
|
894
|
+
const filePath = args.file_path || args.path || '';
|
|
895
|
+
const offset = args.offset;
|
|
896
|
+
const limit = args.limit;
|
|
897
|
+
const lang = getLanguageFromPath(filePath);
|
|
898
|
+
|
|
899
|
+
let pathHtml = escapeHtml(shortenPath(filePath));
|
|
900
|
+
if (offset !== undefined || limit !== undefined) {
|
|
901
|
+
const startLine = offset ?? 1;
|
|
902
|
+
const endLine = limit !== undefined ? startLine + limit - 1 : '';
|
|
903
|
+
pathHtml += `<span class="line-numbers">:${startLine}${endLine ? '-' + endLine : ''}</span>`;
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
html += `<div class="tool-header"><span class="tool-name">read</span> <span class="tool-path">${pathHtml}</span></div>`;
|
|
907
|
+
if (result) {
|
|
908
|
+
html += renderResultImages();
|
|
909
|
+
const output = getResultText();
|
|
910
|
+
if (output) html += formatExpandableOutput(output, 10, lang);
|
|
911
|
+
}
|
|
912
|
+
break;
|
|
913
|
+
}
|
|
914
|
+
case 'write': {
|
|
915
|
+
const filePath = args.file_path || args.path || '';
|
|
916
|
+
const content = args.content || '';
|
|
917
|
+
const lines = content.split('\n');
|
|
918
|
+
const lang = getLanguageFromPath(filePath);
|
|
919
|
+
|
|
920
|
+
html += `<div class="tool-header"><span class="tool-name">write</span> <span class="tool-path">${escapeHtml(shortenPath(filePath))}</span>`;
|
|
921
|
+
if (lines.length > 10) html += ` <span class="line-count">(${lines.length} lines)</span>`;
|
|
922
|
+
html += '</div>';
|
|
923
|
+
|
|
924
|
+
if (content) html += formatExpandableOutput(content, 10, lang);
|
|
925
|
+
if (result) {
|
|
926
|
+
const output = getResultText().trim();
|
|
927
|
+
if (output) html += `<div class="tool-output"><div>${escapeHtml(output)}</div></div>`;
|
|
928
|
+
}
|
|
929
|
+
break;
|
|
930
|
+
}
|
|
931
|
+
case 'edit': {
|
|
932
|
+
const filePath = args.file_path || args.path || '';
|
|
933
|
+
html += `<div class="tool-header"><span class="tool-name">edit</span> <span class="tool-path">${escapeHtml(shortenPath(filePath))}</span></div>`;
|
|
934
|
+
|
|
935
|
+
if (result?.details?.diff) {
|
|
936
|
+
const diffLines = result.details.diff.split('\n');
|
|
937
|
+
html += '<div class="tool-diff">';
|
|
938
|
+
for (const line of diffLines) {
|
|
939
|
+
const cls = line.match(/^\+/) ? 'diff-added' : line.match(/^-/) ? 'diff-removed' : 'diff-context';
|
|
940
|
+
html += `<div class="${cls}">${escapeHtml(replaceTabs(line))}</div>`;
|
|
941
|
+
}
|
|
942
|
+
html += '</div>';
|
|
943
|
+
} else if (result) {
|
|
944
|
+
const output = getResultText().trim();
|
|
945
|
+
if (output) html += `<div class="tool-output"><pre>${escapeHtml(output)}</pre></div>`;
|
|
946
|
+
}
|
|
947
|
+
break;
|
|
948
|
+
}
|
|
949
|
+
default: {
|
|
950
|
+
// Check for pre-rendered custom tool HTML
|
|
951
|
+
const rendered = renderedTools?.[call.id];
|
|
952
|
+
if (rendered?.callHtml || rendered?.resultHtml) {
|
|
953
|
+
// Custom tool with pre-rendered HTML from TUI renderer
|
|
954
|
+
if (rendered.callHtml) {
|
|
955
|
+
html += `<div class="tool-header ansi-rendered">${rendered.callHtml}</div>`;
|
|
956
|
+
} else {
|
|
957
|
+
html += `<div class="tool-header"><span class="tool-name">${escapeHtml(name)}</span></div>`;
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
if (rendered.resultHtml) {
|
|
961
|
+
// Apply same truncation as built-in tools (10 lines)
|
|
962
|
+
const lines = rendered.resultHtml.split('\n');
|
|
963
|
+
if (lines.length > 10) {
|
|
964
|
+
const preview = lines.slice(0, 10).join('\n');
|
|
965
|
+
html += `<div class="tool-output expandable ansi-rendered" onclick="this.classList.toggle('expanded')">
|
|
966
|
+
<div class="output-preview">${preview}<div class="expand-hint">... (${lines.length - 10} more lines)</div></div>
|
|
967
|
+
<div class="output-full">${rendered.resultHtml}</div>
|
|
968
|
+
</div>`;
|
|
969
|
+
} else {
|
|
970
|
+
html += `<div class="tool-output ansi-rendered">${rendered.resultHtml}</div>`;
|
|
971
|
+
}
|
|
972
|
+
} else if (result) {
|
|
973
|
+
// Fallback to JSON for result if no pre-rendered HTML
|
|
974
|
+
const output = getResultText();
|
|
975
|
+
if (output) html += formatExpandableOutput(output, 10);
|
|
976
|
+
}
|
|
977
|
+
} else {
|
|
978
|
+
// Fallback to JSON display (existing behavior)
|
|
979
|
+
html += `<div class="tool-header"><span class="tool-name">${escapeHtml(name)}</span></div>`;
|
|
980
|
+
html += `<div class="tool-output"><pre>${escapeHtml(JSON.stringify(args, null, 2))}</pre></div>`;
|
|
981
|
+
if (result) {
|
|
982
|
+
const output = getResultText();
|
|
983
|
+
if (output) html += formatExpandableOutput(output, 10);
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
html += '</div>';
|
|
990
|
+
return html;
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
/**
|
|
994
|
+
* Download the session data as a JSONL file.
|
|
995
|
+
* Reconstructs the original format: header line + entry lines.
|
|
996
|
+
*/
|
|
997
|
+
window.downloadSessionJson = function() {
|
|
998
|
+
// Build JSONL content: header first, then all entries
|
|
999
|
+
const lines = [];
|
|
1000
|
+
if (header) {
|
|
1001
|
+
lines.push(JSON.stringify({ type: 'header', ...header }));
|
|
1002
|
+
}
|
|
1003
|
+
for (const entry of entries) {
|
|
1004
|
+
lines.push(JSON.stringify(entry));
|
|
1005
|
+
}
|
|
1006
|
+
const jsonlContent = lines.join('\n');
|
|
1007
|
+
|
|
1008
|
+
// Create download
|
|
1009
|
+
const blob = new Blob([jsonlContent], { type: 'application/x-ndjson' });
|
|
1010
|
+
const url = URL.createObjectURL(blob);
|
|
1011
|
+
const a = document.createElement('a');
|
|
1012
|
+
a.href = url;
|
|
1013
|
+
a.download = `${header?.id || 'session'}.jsonl`;
|
|
1014
|
+
document.body.appendChild(a);
|
|
1015
|
+
a.click();
|
|
1016
|
+
document.body.removeChild(a);
|
|
1017
|
+
URL.revokeObjectURL(url);
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
/**
|
|
1021
|
+
* Build a shareable URL for a specific message.
|
|
1022
|
+
* URL format: base?gistId&leafId=<leafId>&targetId=<entryId>
|
|
1023
|
+
*/
|
|
1024
|
+
function buildShareUrl(entryId) {
|
|
1025
|
+
// Check for injected base URL (used when loaded in iframe via srcdoc)
|
|
1026
|
+
const baseUrlMeta = document.querySelector('meta[name="pi-share-base-url"]');
|
|
1027
|
+
const baseUrl = baseUrlMeta ? baseUrlMeta.content : window.location.href.split('?')[0];
|
|
1028
|
+
|
|
1029
|
+
const url = new URL(window.location.href);
|
|
1030
|
+
// Find the gist ID (first query param without value, e.g., ?abc123)
|
|
1031
|
+
const gistId = Array.from(url.searchParams.keys()).find(k => !url.searchParams.get(k));
|
|
1032
|
+
|
|
1033
|
+
// Build the share URL
|
|
1034
|
+
const params = new URLSearchParams();
|
|
1035
|
+
params.set('leafId', currentLeafId);
|
|
1036
|
+
params.set('targetId', entryId);
|
|
1037
|
+
|
|
1038
|
+
// If we have an injected base URL (iframe context), use it directly
|
|
1039
|
+
if (baseUrlMeta) {
|
|
1040
|
+
return `${baseUrl}&${params.toString()}`;
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
// Otherwise build from current location (direct file access)
|
|
1044
|
+
url.search = gistId ? `?${gistId}&${params.toString()}` : `?${params.toString()}`;
|
|
1045
|
+
return url.toString();
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
/**
|
|
1049
|
+
* Copy text to clipboard with visual feedback.
|
|
1050
|
+
* Uses navigator.clipboard with fallback to execCommand for HTTP contexts.
|
|
1051
|
+
*/
|
|
1052
|
+
async function copyToClipboard(text, button) {
|
|
1053
|
+
let success = false;
|
|
1054
|
+
try {
|
|
1055
|
+
if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
1056
|
+
await navigator.clipboard.writeText(text);
|
|
1057
|
+
success = true;
|
|
1058
|
+
}
|
|
1059
|
+
} catch (err) {
|
|
1060
|
+
// Clipboard API failed, try fallback
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
// Fallback for HTTP or when Clipboard API is unavailable
|
|
1064
|
+
if (!success) {
|
|
1065
|
+
try {
|
|
1066
|
+
const textarea = document.createElement('textarea');
|
|
1067
|
+
textarea.value = text;
|
|
1068
|
+
textarea.style.position = 'fixed';
|
|
1069
|
+
textarea.style.opacity = '0';
|
|
1070
|
+
document.body.appendChild(textarea);
|
|
1071
|
+
textarea.select();
|
|
1072
|
+
success = document.execCommand('copy');
|
|
1073
|
+
document.body.removeChild(textarea);
|
|
1074
|
+
} catch (err) {
|
|
1075
|
+
console.error('Failed to copy:', err);
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
if (success && button) {
|
|
1080
|
+
const originalHtml = button.innerHTML;
|
|
1081
|
+
button.innerHTML = '✓';
|
|
1082
|
+
button.classList.add('copied');
|
|
1083
|
+
setTimeout(() => {
|
|
1084
|
+
button.innerHTML = originalHtml;
|
|
1085
|
+
button.classList.remove('copied');
|
|
1086
|
+
}, 1500);
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
/**
|
|
1091
|
+
* Render the copy-link button HTML for a message.
|
|
1092
|
+
*/
|
|
1093
|
+
function renderCopyLinkButton(entryId) {
|
|
1094
|
+
return `<button class="copy-link-btn" data-entry-id="${entryId}" title="Copy link to this message">
|
|
1095
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
1096
|
+
<path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/>
|
|
1097
|
+
<path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/>
|
|
1098
|
+
</svg>
|
|
1099
|
+
</button>`;
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
function renderEntry(entry) {
|
|
1103
|
+
const ts = formatTimestamp(entry.timestamp);
|
|
1104
|
+
const tsHtml = ts ? `<div class="message-timestamp">${ts}</div>` : '';
|
|
1105
|
+
const entryId = `entry-${entry.id}`;
|
|
1106
|
+
const copyBtnHtml = renderCopyLinkButton(entry.id);
|
|
1107
|
+
|
|
1108
|
+
if (entry.type === 'message') {
|
|
1109
|
+
const msg = entry.message;
|
|
1110
|
+
|
|
1111
|
+
if (msg.role === 'user') {
|
|
1112
|
+
let html = `<div class="user-message" id="${entryId}">${copyBtnHtml}${tsHtml}`;
|
|
1113
|
+
const content = msg.content;
|
|
1114
|
+
|
|
1115
|
+
if (Array.isArray(content)) {
|
|
1116
|
+
const images = content.filter(c => c.type === 'image');
|
|
1117
|
+
if (images.length > 0) {
|
|
1118
|
+
html += '<div class="message-images">';
|
|
1119
|
+
for (const img of images) {
|
|
1120
|
+
html += `<img src="data:${img.mimeType};base64,${img.data}" class="message-image" />`;
|
|
1121
|
+
}
|
|
1122
|
+
html += '</div>';
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
const text = typeof content === 'string' ? content :
|
|
1127
|
+
content.filter(c => c.type === 'text').map(c => c.text).join('\n');
|
|
1128
|
+
if (text.trim()) {
|
|
1129
|
+
html += `<div class="markdown-content">${safeMarkedParse(text)}</div>`;
|
|
1130
|
+
}
|
|
1131
|
+
html += '</div>';
|
|
1132
|
+
return html;
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
if (msg.role === 'assistant') {
|
|
1136
|
+
let html = `<div class="assistant-message" id="${entryId}">${copyBtnHtml}${tsHtml}`;
|
|
1137
|
+
|
|
1138
|
+
for (const block of msg.content) {
|
|
1139
|
+
if (block.type === 'text' && block.text.trim()) {
|
|
1140
|
+
html += `<div class="assistant-text markdown-content">${safeMarkedParse(block.text)}</div>`;
|
|
1141
|
+
} else if (block.type === 'thinking' && block.thinking.trim()) {
|
|
1142
|
+
html += `<div class="thinking-block">
|
|
1143
|
+
<div class="thinking-text">${escapeHtml(block.thinking)}</div>
|
|
1144
|
+
<div class="thinking-collapsed">Thinking ...</div>
|
|
1145
|
+
</div>`;
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
for (const block of msg.content) {
|
|
1150
|
+
if (block.type === 'toolCall') {
|
|
1151
|
+
html += renderToolCall(block);
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
if (msg.stopReason === 'aborted') {
|
|
1156
|
+
html += '<div class="error-text">Aborted</div>';
|
|
1157
|
+
} else if (msg.stopReason === 'error') {
|
|
1158
|
+
html += `<div class="error-text">Error: ${escapeHtml(msg.errorMessage || 'Unknown error')}</div>`;
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
html += '</div>';
|
|
1162
|
+
return html;
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
if (msg.role === 'bashExecution') {
|
|
1166
|
+
const isError = msg.cancelled || (msg.exitCode !== 0 && msg.exitCode !== null);
|
|
1167
|
+
let html = `<div class="tool-execution ${isError ? 'error' : 'success'}" id="${entryId}">${tsHtml}`;
|
|
1168
|
+
html += `<div class="tool-command">$ ${escapeHtml(msg.command)}</div>`;
|
|
1169
|
+
if (msg.output) html += formatExpandableOutput(msg.output, 10);
|
|
1170
|
+
if (msg.cancelled) {
|
|
1171
|
+
html += '<div style="color: var(--warning)">(cancelled)</div>';
|
|
1172
|
+
} else if (msg.exitCode !== 0 && msg.exitCode !== null) {
|
|
1173
|
+
html += `<div style="color: var(--error)">(exit ${msg.exitCode})</div>`;
|
|
1174
|
+
}
|
|
1175
|
+
html += '</div>';
|
|
1176
|
+
return html;
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
if (msg.role === 'toolResult') return '';
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
if (entry.type === 'model_change') {
|
|
1183
|
+
return `<div class="model-change" id="${entryId}">${tsHtml}Switched to model: <span class="model-name">${escapeHtml(entry.provider)}/${escapeHtml(entry.modelId)}</span></div>`;
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
if (entry.type === 'compaction') {
|
|
1187
|
+
return `<div class="compaction" id="${entryId}" onclick="this.classList.toggle('expanded')">
|
|
1188
|
+
<div class="compaction-label">[compaction]</div>
|
|
1189
|
+
<div class="compaction-collapsed">Compacted from ${entry.tokensBefore.toLocaleString()} tokens</div>
|
|
1190
|
+
<div class="compaction-content"><strong>Compacted from ${entry.tokensBefore.toLocaleString()} tokens</strong>\n\n${escapeHtml(entry.summary)}</div>
|
|
1191
|
+
</div>`;
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
if (entry.type === 'branch_summary') {
|
|
1195
|
+
return `<div class="branch-summary" id="${entryId}">${tsHtml}
|
|
1196
|
+
<div class="branch-summary-header">Branch Summary</div>
|
|
1197
|
+
<div class="markdown-content">${safeMarkedParse(entry.summary)}</div>
|
|
1198
|
+
</div>`;
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
if (entry.type === 'custom_message' && entry.display) {
|
|
1202
|
+
return `<div class="hook-message" id="${entryId}">${tsHtml}
|
|
1203
|
+
<div class="hook-type">[${escapeHtml(entry.customType)}]</div>
|
|
1204
|
+
<div class="markdown-content">${safeMarkedParse(typeof entry.content === 'string' ? entry.content : JSON.stringify(entry.content))}</div>
|
|
1205
|
+
</div>`;
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
return '';
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
// ============================================================
|
|
1212
|
+
// HEADER / STATS
|
|
1213
|
+
// ============================================================
|
|
1214
|
+
|
|
1215
|
+
function computeStats(entryList) {
|
|
1216
|
+
let userMessages = 0, assistantMessages = 0, toolResults = 0;
|
|
1217
|
+
let customMessages = 0, compactions = 0, branchSummaries = 0, toolCalls = 0;
|
|
1218
|
+
const tokens = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 };
|
|
1219
|
+
const cost = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 };
|
|
1220
|
+
const models = new Set();
|
|
1221
|
+
|
|
1222
|
+
for (const entry of entryList) {
|
|
1223
|
+
if (entry.type === 'message') {
|
|
1224
|
+
const msg = entry.message;
|
|
1225
|
+
if (msg.role === 'user') userMessages++;
|
|
1226
|
+
if (msg.role === 'assistant') {
|
|
1227
|
+
assistantMessages++;
|
|
1228
|
+
if (msg.model) models.add(msg.provider ? `${msg.provider}/${msg.model}` : msg.model);
|
|
1229
|
+
if (msg.usage) {
|
|
1230
|
+
tokens.input += msg.usage.input || 0;
|
|
1231
|
+
tokens.output += msg.usage.output || 0;
|
|
1232
|
+
tokens.cacheRead += msg.usage.cacheRead || 0;
|
|
1233
|
+
tokens.cacheWrite += msg.usage.cacheWrite || 0;
|
|
1234
|
+
if (msg.usage.cost) {
|
|
1235
|
+
cost.input += msg.usage.cost.input || 0;
|
|
1236
|
+
cost.output += msg.usage.cost.output || 0;
|
|
1237
|
+
cost.cacheRead += msg.usage.cost.cacheRead || 0;
|
|
1238
|
+
cost.cacheWrite += msg.usage.cost.cacheWrite || 0;
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
toolCalls += msg.content.filter(c => c.type === 'toolCall').length;
|
|
1242
|
+
}
|
|
1243
|
+
if (msg.role === 'toolResult') toolResults++;
|
|
1244
|
+
} else if (entry.type === 'compaction') {
|
|
1245
|
+
compactions++;
|
|
1246
|
+
} else if (entry.type === 'branch_summary') {
|
|
1247
|
+
branchSummaries++;
|
|
1248
|
+
} else if (entry.type === 'custom_message') {
|
|
1249
|
+
customMessages++;
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
return { userMessages, assistantMessages, toolResults, customMessages, compactions, branchSummaries, toolCalls, tokens, cost, models: Array.from(models) };
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
const globalStats = computeStats(entries);
|
|
1257
|
+
|
|
1258
|
+
function renderHeader() {
|
|
1259
|
+
const totalCost = globalStats.cost.input + globalStats.cost.output + globalStats.cost.cacheRead + globalStats.cost.cacheWrite;
|
|
1260
|
+
|
|
1261
|
+
const tokenParts = [];
|
|
1262
|
+
if (globalStats.tokens.input) tokenParts.push(`↑${formatTokens(globalStats.tokens.input)}`);
|
|
1263
|
+
if (globalStats.tokens.output) tokenParts.push(`↓${formatTokens(globalStats.tokens.output)}`);
|
|
1264
|
+
if (globalStats.tokens.cacheRead) tokenParts.push(`R${formatTokens(globalStats.tokens.cacheRead)}`);
|
|
1265
|
+
if (globalStats.tokens.cacheWrite) tokenParts.push(`W${formatTokens(globalStats.tokens.cacheWrite)}`);
|
|
1266
|
+
|
|
1267
|
+
const msgParts = [];
|
|
1268
|
+
if (globalStats.userMessages) msgParts.push(`${globalStats.userMessages} user`);
|
|
1269
|
+
if (globalStats.assistantMessages) msgParts.push(`${globalStats.assistantMessages} assistant`);
|
|
1270
|
+
if (globalStats.toolResults) msgParts.push(`${globalStats.toolResults} tool results`);
|
|
1271
|
+
if (globalStats.customMessages) msgParts.push(`${globalStats.customMessages} custom`);
|
|
1272
|
+
if (globalStats.compactions) msgParts.push(`${globalStats.compactions} compactions`);
|
|
1273
|
+
if (globalStats.branchSummaries) msgParts.push(`${globalStats.branchSummaries} branch summaries`);
|
|
1274
|
+
|
|
1275
|
+
let html = `
|
|
1276
|
+
<div class="header">
|
|
1277
|
+
<h1>Session: ${escapeHtml(header?.id || 'unknown')}</h1>
|
|
1278
|
+
<div class="help-bar">
|
|
1279
|
+
<span>Ctrl+T toggle thinking · Ctrl+O toggle tools</span>
|
|
1280
|
+
<button class="download-json-btn" onclick="downloadSessionJson()" title="Download session as JSONL">↓ JSONL</button>
|
|
1281
|
+
</div>
|
|
1282
|
+
<div class="header-info">
|
|
1283
|
+
<div class="info-item"><span class="info-label">Date:</span><span class="info-value">${header?.timestamp ? new Date(header.timestamp).toLocaleString() : 'unknown'}</span></div>
|
|
1284
|
+
<div class="info-item"><span class="info-label">Models:</span><span class="info-value">${globalStats.models.join(', ') || 'unknown'}</span></div>
|
|
1285
|
+
<div class="info-item"><span class="info-label">Messages:</span><span class="info-value">${msgParts.join(', ') || '0'}</span></div>
|
|
1286
|
+
<div class="info-item"><span class="info-label">Tool Calls:</span><span class="info-value">${globalStats.toolCalls}</span></div>
|
|
1287
|
+
<div class="info-item"><span class="info-label">Tokens:</span><span class="info-value">${tokenParts.join(' ') || '0'}</span></div>
|
|
1288
|
+
<div class="info-item"><span class="info-label">Cost:</span><span class="info-value">$${totalCost.toFixed(3)}</span></div>
|
|
1289
|
+
</div>
|
|
1290
|
+
</div>`;
|
|
1291
|
+
|
|
1292
|
+
// Render system prompt (user's base prompt, applies to all providers)
|
|
1293
|
+
if (systemPrompt) {
|
|
1294
|
+
const lines = systemPrompt.split('\n');
|
|
1295
|
+
const previewLines = 10;
|
|
1296
|
+
if (lines.length > previewLines) {
|
|
1297
|
+
const preview = lines.slice(0, previewLines).join('\n');
|
|
1298
|
+
const remaining = lines.length - previewLines;
|
|
1299
|
+
html += `<div class="system-prompt expandable" onclick="this.classList.toggle('expanded')">
|
|
1300
|
+
<div class="system-prompt-header">System Prompt</div>
|
|
1301
|
+
<div class="system-prompt-preview">${escapeHtml(preview)}</div>
|
|
1302
|
+
<div class="system-prompt-expand-hint">... (${remaining} more lines, click to expand)</div>
|
|
1303
|
+
<div class="system-prompt-full">${escapeHtml(systemPrompt)}</div>
|
|
1304
|
+
</div>`;
|
|
1305
|
+
} else {
|
|
1306
|
+
html += `<div class="system-prompt">
|
|
1307
|
+
<div class="system-prompt-header">System Prompt</div>
|
|
1308
|
+
<div class="system-prompt-full" style="display: block">${escapeHtml(systemPrompt)}</div>
|
|
1309
|
+
</div>`;
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
if (tools && tools.length > 0) {
|
|
1314
|
+
html += `<div class="tools-list">
|
|
1315
|
+
<div class="tools-header">Available Tools</div>
|
|
1316
|
+
<div class="tools-content">
|
|
1317
|
+
${tools.map(t => `<div class="tool-item"><span class="tool-item-name">${escapeHtml(t.name)}</span> - <span class="tool-item-desc">${escapeHtml(t.description)}</span></div>`).join('')}
|
|
1318
|
+
</div>
|
|
1319
|
+
</div>`;
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
return html;
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1325
|
+
// ============================================================
|
|
1326
|
+
// NAVIGATION
|
|
1327
|
+
// ============================================================
|
|
1328
|
+
|
|
1329
|
+
// Cache for rendered entry DOM nodes
|
|
1330
|
+
const entryCache = new Map();
|
|
1331
|
+
|
|
1332
|
+
function renderEntryToNode(entry) {
|
|
1333
|
+
// Check cache first
|
|
1334
|
+
if (entryCache.has(entry.id)) {
|
|
1335
|
+
return entryCache.get(entry.id).cloneNode(true);
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
// Render to HTML string, then parse to node
|
|
1339
|
+
const html = renderEntry(entry);
|
|
1340
|
+
if (!html) return null;
|
|
1341
|
+
|
|
1342
|
+
const template = document.createElement('template');
|
|
1343
|
+
template.innerHTML = html;
|
|
1344
|
+
const node = template.content.firstElementChild;
|
|
1345
|
+
|
|
1346
|
+
// Cache the node
|
|
1347
|
+
if (node) {
|
|
1348
|
+
entryCache.set(entry.id, node.cloneNode(true));
|
|
1349
|
+
}
|
|
1350
|
+
return node;
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1353
|
+
function navigateTo(targetId, scrollMode = 'target', scrollToEntryId = null) {
|
|
1354
|
+
currentLeafId = targetId;
|
|
1355
|
+
currentTargetId = scrollToEntryId || targetId;
|
|
1356
|
+
const path = getPath(targetId);
|
|
1357
|
+
|
|
1358
|
+
renderTree();
|
|
1359
|
+
|
|
1360
|
+
document.getElementById('header-container').innerHTML = renderHeader();
|
|
1361
|
+
|
|
1362
|
+
// Build messages using cached DOM nodes
|
|
1363
|
+
const messagesEl = document.getElementById('messages');
|
|
1364
|
+
const fragment = document.createDocumentFragment();
|
|
1365
|
+
|
|
1366
|
+
for (const entry of path) {
|
|
1367
|
+
const node = renderEntryToNode(entry);
|
|
1368
|
+
if (node) {
|
|
1369
|
+
fragment.appendChild(node);
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
messagesEl.innerHTML = '';
|
|
1374
|
+
messagesEl.appendChild(fragment);
|
|
1375
|
+
|
|
1376
|
+
// Attach click handlers for copy-link buttons
|
|
1377
|
+
messagesEl.querySelectorAll('.copy-link-btn').forEach(btn => {
|
|
1378
|
+
btn.addEventListener('click', (e) => {
|
|
1379
|
+
e.stopPropagation();
|
|
1380
|
+
const entryId = btn.dataset.entryId;
|
|
1381
|
+
const shareUrl = buildShareUrl(entryId);
|
|
1382
|
+
copyToClipboard(shareUrl, btn);
|
|
1383
|
+
});
|
|
1384
|
+
});
|
|
1385
|
+
|
|
1386
|
+
// Use setTimeout(0) to ensure DOM is fully laid out before scrolling
|
|
1387
|
+
setTimeout(() => {
|
|
1388
|
+
const content = document.getElementById('content');
|
|
1389
|
+
if (scrollMode === 'bottom') {
|
|
1390
|
+
content.scrollTop = content.scrollHeight;
|
|
1391
|
+
} else if (scrollMode === 'target') {
|
|
1392
|
+
// If scrollToEntryId is provided, scroll to that specific entry
|
|
1393
|
+
const scrollTargetId = scrollToEntryId || targetId;
|
|
1394
|
+
const targetEl = document.getElementById(`entry-${scrollTargetId}`);
|
|
1395
|
+
if (targetEl) {
|
|
1396
|
+
targetEl.scrollIntoView({ block: 'center' });
|
|
1397
|
+
// Briefly highlight the target message
|
|
1398
|
+
if (scrollToEntryId) {
|
|
1399
|
+
targetEl.classList.add('highlight');
|
|
1400
|
+
setTimeout(() => targetEl.classList.remove('highlight'), 2000);
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
}, 0);
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
// ============================================================
|
|
1408
|
+
// INITIALIZATION
|
|
1409
|
+
// ============================================================
|
|
1410
|
+
|
|
1411
|
+
// Escape HTML tags in text (but not code blocks)
|
|
1412
|
+
function escapeHtmlTags(text) {
|
|
1413
|
+
return text.replace(/<(?=[a-zA-Z\/])/g, '<');
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
// Configure marked with syntax highlighting and HTML escaping for text
|
|
1417
|
+
marked.use({
|
|
1418
|
+
breaks: true,
|
|
1419
|
+
gfm: true,
|
|
1420
|
+
renderer: {
|
|
1421
|
+
// Code blocks: syntax highlight, no HTML escaping
|
|
1422
|
+
code(token) {
|
|
1423
|
+
const code = token.text;
|
|
1424
|
+
const lang = token.lang;
|
|
1425
|
+
let highlighted;
|
|
1426
|
+
if (lang && hljs.getLanguage(lang)) {
|
|
1427
|
+
try {
|
|
1428
|
+
highlighted = hljs.highlight(code, { language: lang }).value;
|
|
1429
|
+
} catch {
|
|
1430
|
+
highlighted = escapeHtml(code);
|
|
1431
|
+
}
|
|
1432
|
+
} else {
|
|
1433
|
+
// Auto-detect language if not specified
|
|
1434
|
+
try {
|
|
1435
|
+
highlighted = hljs.highlightAuto(code).value;
|
|
1436
|
+
} catch {
|
|
1437
|
+
highlighted = escapeHtml(code);
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
return `<pre><code class="hljs">${highlighted}</code></pre>`;
|
|
1441
|
+
},
|
|
1442
|
+
// Text content: escape HTML tags
|
|
1443
|
+
text(token) {
|
|
1444
|
+
return escapeHtmlTags(escapeHtml(token.text));
|
|
1445
|
+
},
|
|
1446
|
+
// Inline code: escape HTML
|
|
1447
|
+
codespan(token) {
|
|
1448
|
+
return `<code>${escapeHtml(token.text)}</code>`;
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
});
|
|
1452
|
+
|
|
1453
|
+
// Simple marked parse (escaping handled in renderers)
|
|
1454
|
+
function safeMarkedParse(text) {
|
|
1455
|
+
return marked.parse(text);
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1458
|
+
// Search input
|
|
1459
|
+
const searchInput = document.getElementById('tree-search');
|
|
1460
|
+
searchInput.addEventListener('input', (e) => {
|
|
1461
|
+
searchQuery = e.target.value;
|
|
1462
|
+
forceTreeRerender();
|
|
1463
|
+
});
|
|
1464
|
+
|
|
1465
|
+
// Filter buttons
|
|
1466
|
+
document.querySelectorAll('.filter-btn').forEach(btn => {
|
|
1467
|
+
btn.addEventListener('click', () => {
|
|
1468
|
+
document.querySelectorAll('.filter-btn').forEach(b => b.classList.remove('active'));
|
|
1469
|
+
btn.classList.add('active');
|
|
1470
|
+
filterMode = btn.dataset.filter;
|
|
1471
|
+
forceTreeRerender();
|
|
1472
|
+
});
|
|
1473
|
+
});
|
|
1474
|
+
|
|
1475
|
+
// Sidebar toggle
|
|
1476
|
+
const sidebar = document.getElementById('sidebar');
|
|
1477
|
+
const overlay = document.getElementById('sidebar-overlay');
|
|
1478
|
+
const hamburger = document.getElementById('hamburger');
|
|
1479
|
+
|
|
1480
|
+
hamburger.addEventListener('click', () => {
|
|
1481
|
+
sidebar.classList.add('open');
|
|
1482
|
+
overlay.classList.add('open');
|
|
1483
|
+
hamburger.style.display = 'none';
|
|
1484
|
+
});
|
|
1485
|
+
|
|
1486
|
+
const closeSidebar = () => {
|
|
1487
|
+
sidebar.classList.remove('open');
|
|
1488
|
+
overlay.classList.remove('open');
|
|
1489
|
+
hamburger.style.display = '';
|
|
1490
|
+
};
|
|
1491
|
+
|
|
1492
|
+
overlay.addEventListener('click', closeSidebar);
|
|
1493
|
+
document.getElementById('sidebar-close').addEventListener('click', closeSidebar);
|
|
1494
|
+
|
|
1495
|
+
// Toggle states
|
|
1496
|
+
let thinkingExpanded = true;
|
|
1497
|
+
let toolOutputsExpanded = false;
|
|
1498
|
+
|
|
1499
|
+
const toggleThinking = () => {
|
|
1500
|
+
thinkingExpanded = !thinkingExpanded;
|
|
1501
|
+
document.querySelectorAll('.thinking-text').forEach(el => {
|
|
1502
|
+
el.style.display = thinkingExpanded ? '' : 'none';
|
|
1503
|
+
});
|
|
1504
|
+
document.querySelectorAll('.thinking-collapsed').forEach(el => {
|
|
1505
|
+
el.style.display = thinkingExpanded ? 'none' : 'block';
|
|
1506
|
+
});
|
|
1507
|
+
};
|
|
1508
|
+
|
|
1509
|
+
const toggleToolOutputs = () => {
|
|
1510
|
+
toolOutputsExpanded = !toolOutputsExpanded;
|
|
1511
|
+
document.querySelectorAll('.tool-output.expandable').forEach(el => {
|
|
1512
|
+
el.classList.toggle('expanded', toolOutputsExpanded);
|
|
1513
|
+
});
|
|
1514
|
+
document.querySelectorAll('.compaction').forEach(el => {
|
|
1515
|
+
el.classList.toggle('expanded', toolOutputsExpanded);
|
|
1516
|
+
});
|
|
1517
|
+
};
|
|
1518
|
+
|
|
1519
|
+
// Keyboard shortcuts
|
|
1520
|
+
document.addEventListener('keydown', (e) => {
|
|
1521
|
+
if (e.key === 'Escape') {
|
|
1522
|
+
searchInput.value = '';
|
|
1523
|
+
searchQuery = '';
|
|
1524
|
+
navigateTo(leafId, 'bottom');
|
|
1525
|
+
}
|
|
1526
|
+
if (e.ctrlKey && e.key === 't') {
|
|
1527
|
+
e.preventDefault();
|
|
1528
|
+
toggleThinking();
|
|
1529
|
+
}
|
|
1530
|
+
if (e.ctrlKey && e.key === 'o') {
|
|
1531
|
+
e.preventDefault();
|
|
1532
|
+
toggleToolOutputs();
|
|
1533
|
+
}
|
|
1534
|
+
});
|
|
1535
|
+
|
|
1536
|
+
// Initial render
|
|
1537
|
+
// If URL has targetId, scroll to that specific message; otherwise stay at top
|
|
1538
|
+
if (leafId) {
|
|
1539
|
+
if (urlTargetId && byId.has(urlTargetId)) {
|
|
1540
|
+
// Deep link: navigate to leaf and scroll to target message
|
|
1541
|
+
navigateTo(leafId, 'target', urlTargetId);
|
|
1542
|
+
} else {
|
|
1543
|
+
navigateTo(leafId, 'none');
|
|
1544
|
+
}
|
|
1545
|
+
} else if (entries.length > 0) {
|
|
1546
|
+
// Fallback: use last entry if no leafId
|
|
1547
|
+
navigateTo(entries[entries.length - 1].id, 'none');
|
|
1548
|
+
}
|
|
1549
|
+
})();
|