@akon-labs/nexus-cli 0.1.10 → 0.1.11
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/dist/cli/require-login.d.ts.map +1 -1
- package/dist/cli/require-login.js +2 -2
- package/dist/cli/require-login.js.map +1 -1
- package/dist/cli.js +2492 -1088
- package/dist/core/agent-session.d.ts +3 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +4 -0
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +6 -0
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +7 -1
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +14 -0
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +18 -0
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/graph-rail-store.d.ts +10 -0
- package/dist/core/graph-rail-store.d.ts.map +1 -1
- package/dist/core/graph-rail-store.js +9 -0
- package/dist/core/graph-rail-store.js.map +1 -1
- package/dist/core/keybindings.d.ts +2 -1
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +4 -1
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +1 -1
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +1 -1
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/extensions/gitnexus/client.d.ts.map +1 -1
- package/dist/extensions/gitnexus/client.js +45 -14
- package/dist/extensions/gitnexus/client.js.map +1 -1
- package/dist/extensions/gitnexus/config.d.ts +15 -1
- package/dist/extensions/gitnexus/config.d.ts.map +1 -1
- package/dist/extensions/gitnexus/config.js +86 -2
- package/dist/extensions/gitnexus/config.js.map +1 -1
- package/dist/extensions/gitnexus/hub-api.d.ts +56 -0
- package/dist/extensions/gitnexus/hub-api.d.ts.map +1 -0
- package/dist/extensions/gitnexus/hub-api.js +105 -0
- package/dist/extensions/gitnexus/hub-api.js.map +1 -0
- package/dist/extensions/gitnexus/index-repo.d.ts +50 -0
- package/dist/extensions/gitnexus/index-repo.d.ts.map +1 -0
- package/dist/extensions/gitnexus/index-repo.js +162 -0
- package/dist/extensions/gitnexus/index-repo.js.map +1 -0
- package/dist/extensions/gitnexus/index.d.ts.map +1 -1
- package/dist/extensions/gitnexus/index.js +137 -17
- package/dist/extensions/gitnexus/index.js.map +1 -1
- package/dist/extensions/gitnexus/observatory.d.ts.map +1 -1
- package/dist/extensions/gitnexus/observatory.js +2 -2
- package/dist/extensions/gitnexus/observatory.js.map +1 -1
- package/dist/extensions/gitnexus/resolve.d.ts +9 -0
- package/dist/extensions/gitnexus/resolve.d.ts.map +1 -1
- package/dist/extensions/gitnexus/resolve.js +52 -2
- package/dist/extensions/gitnexus/resolve.js.map +1 -1
- package/dist/extensions/index.d.ts.map +1 -1
- package/dist/extensions/index.js +3 -0
- package/dist/extensions/index.js.map +1 -1
- package/dist/extensions/mcp/commands.d.ts +22 -2
- package/dist/extensions/mcp/commands.d.ts.map +1 -1
- package/dist/extensions/mcp/commands.js +201 -9
- package/dist/extensions/mcp/commands.js.map +1 -1
- package/dist/extensions/mcp/config.d.ts +2 -0
- package/dist/extensions/mcp/config.d.ts.map +1 -1
- package/dist/extensions/mcp/config.js +6 -1
- package/dist/extensions/mcp/config.js.map +1 -1
- package/dist/extensions/mcp/index.d.ts.map +1 -1
- package/dist/extensions/mcp/index.js +54 -5
- package/dist/extensions/mcp/index.js.map +1 -1
- package/dist/extensions/mcp/mcp-setup-panel.d.ts +63 -2
- package/dist/extensions/mcp/mcp-setup-panel.d.ts.map +1 -1
- package/dist/extensions/mcp/mcp-setup-panel.js +563 -77
- package/dist/extensions/mcp/mcp-setup-panel.js.map +1 -1
- package/dist/extensions/subagent/index.d.ts +2 -1
- package/dist/extensions/subagent/index.d.ts.map +1 -1
- package/dist/extensions/subagent/index.js +19 -6
- package/dist/extensions/subagent/index.js.map +1 -1
- package/dist/extensions/subagent-render.d.ts +3 -0
- package/dist/extensions/subagent-render.d.ts.map +1 -0
- package/dist/extensions/subagent-render.js +39 -0
- package/dist/extensions/subagent-render.js.map +1 -0
- package/dist/index.js +2524 -1120
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +2 -0
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/command-palette.d.ts +2 -1
- package/dist/modes/interactive/components/command-palette.d.ts.map +1 -1
- package/dist/modes/interactive/components/command-palette.js +11 -4
- package/dist/modes/interactive/components/command-palette.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +9 -3
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/graph-rail.d.ts.map +1 -1
- package/dist/modes/interactive/components/graph-rail.js +18 -3
- package/dist/modes/interactive/components/graph-rail.js.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.d.ts +1 -0
- package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.js +7 -1
- package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
- package/dist/modes/interactive/components/landing-panel.d.ts.map +1 -1
- package/dist/modes/interactive/components/landing-panel.js +15 -2
- package/dist/modes/interactive/components/landing-panel.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +3 -2
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +12 -2
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +3 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +42 -8
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/rpc-entry.js +2492 -1088
- package/dist/utils/hidden-spawn.d.ts +29 -0
- package/dist/utils/hidden-spawn.d.ts.map +1 -0
- package/dist/utils/hidden-spawn.js +101 -0
- package/dist/utils/hidden-spawn.js.map +1 -0
- package/dist/vendor/ai.js +233 -233
- package/dist/vendor/tui.js +1 -1
- package/native/win32/build.mjs +95 -0
- package/native/win32/prebuilds/win32-x64/hidden-spawn.exe +0 -0
- package/native/win32/src/hidden-spawn.c +157 -0
- package/npm-shrinkwrap.json +2 -37
- package/package.json +7 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assistant-message.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/assistant-message.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAY,KAAK,aAAa,EAAgB,MAAM,wBAAwB,CAAC;AAC/F,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAkB7E;;GAEG;AACH,qBAAa,yBAA0B,SAAQ,SAAS;IACvD,OAAO,CAAC,gBAAgB,CAAY;IACpC,OAAO,CAAC,iBAAiB,CAAU;IACnC,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,mBAAmB,CAAS;IACpC,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,oBAAoB,CAAiC;IAC7D,OAAO,CAAC,WAAW,CAAC,CAAmB;IACvC,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,WAAW,CAAS;IAE5B,YACC,OAAO,CAAC,EAAE,gBAAgB,EAC1B,iBAAiB,UAAQ,EACzB,aAAa,GAAE,aAAkC,EACjD,mBAAmB,SAAgB,EACnC,SAAS,SAAI,EACb,oBAAoB,GAAE,SAAS,mBAAmB,EAAO,EAiBzD;IAEQ,UAAU,IAAI,IAAI,CAK1B;IAED,oBAAoB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAKxC;IAED;;;;;OAKG;IACH,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CAEnC;IAED,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAK1C;IAED,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAKlC;IAEQ,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAevC;IAED,aAAa,CAAC,OAAO,EAAE,gBAAgB,EAAE,WAAW,UAAmB,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"assistant-message.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/assistant-message.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAY,KAAK,aAAa,EAAgB,MAAM,wBAAwB,CAAC;AAC/F,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAkB7E;;GAEG;AACH,qBAAa,yBAA0B,SAAQ,SAAS;IACvD,OAAO,CAAC,gBAAgB,CAAY;IACpC,OAAO,CAAC,iBAAiB,CAAU;IACnC,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,mBAAmB,CAAS;IACpC,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,oBAAoB,CAAiC;IAC7D,OAAO,CAAC,WAAW,CAAC,CAAmB;IACvC,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,WAAW,CAAS;IAE5B,YACC,OAAO,CAAC,EAAE,gBAAgB,EAC1B,iBAAiB,UAAQ,EACzB,aAAa,GAAE,aAAkC,EACjD,mBAAmB,SAAgB,EACnC,SAAS,SAAI,EACb,oBAAoB,GAAE,SAAS,mBAAmB,EAAO,EAiBzD;IAEQ,UAAU,IAAI,IAAI,CAK1B;IAED,oBAAoB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAKxC;IAED;;;;;OAKG;IACH,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CAEnC;IAED,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAK1C;IAED,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAKlC;IAEQ,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAevC;IAED,aAAa,CAAC,OAAO,EAAE,gBAAgB,EAAE,WAAW,UAAmB,GAAG,IAAI,CAgH7E;CACD","sourcesContent":["import type { AssistantMessage } from \"@earendil-works/pi-ai\";\nimport { Container, Markdown, type MarkdownTheme, Spacer, Text } from \"@earendil-works/pi-tui\";\nimport type { MarkdownTransformer } from \"../../../core/extensions/types.ts\";\nimport { getMarkdownTheme, theme } from \"../theme/theme.ts\";\nimport { createMarkdownTransform } from \"./markdown-transform.ts\";\nimport { MESSAGE_MAX_TEXT_WIDTH } from \"./message-layout.ts\";\nimport { panelize } from \"./panel.ts\";\n\n/** Crush-style raised panel around the thinking block. */\nclass ThinkingPanel extends Container {\n\toverride render(width: number): string[] {\n\t\tconst inner = super.render(Math.max(1, width - 5));\n\t\treturn panelize(inner, width, \"customMessageBg\", 1);\n\t}\n}\n\nconst OSC133_ZONE_START = \"\\x1b]133;A\\x07\";\nconst OSC133_ZONE_END = \"\\x1b]133;B\\x07\";\nconst OSC133_ZONE_FINAL = \"\\x1b]133;C\\x07\";\n\n/**\n * Component that renders a complete assistant message\n */\nexport class AssistantMessageComponent extends Container {\n\tprivate contentContainer: Container;\n\tprivate hideThinkingBlock: boolean;\n\tprivate markdownTheme: MarkdownTheme;\n\tprivate hiddenThinkingLabel: string;\n\tprivate outputPad: number;\n\tprivate markdownTransformers: readonly MarkdownTransformer[];\n\tprivate lastMessage?: AssistantMessage;\n\tprivate hasToolCalls = false;\n\tprivate isStreaming = false;\n\n\tconstructor(\n\t\tmessage?: AssistantMessage,\n\t\thideThinkingBlock = false,\n\t\tmarkdownTheme: MarkdownTheme = getMarkdownTheme(),\n\t\thiddenThinkingLabel = \"Thinking...\",\n\t\toutputPad = 1,\n\t\tmarkdownTransformers: readonly MarkdownTransformer[] = [],\n\t) {\n\t\tsuper();\n\n\t\tthis.hideThinkingBlock = hideThinkingBlock;\n\t\tthis.markdownTheme = markdownTheme;\n\t\tthis.hiddenThinkingLabel = hiddenThinkingLabel;\n\t\tthis.outputPad = outputPad;\n\t\tthis.markdownTransformers = markdownTransformers;\n\n\t\t// Container for text/thinking content\n\t\tthis.contentContainer = new Container();\n\t\tthis.addChild(this.contentContainer);\n\n\t\tif (message) {\n\t\t\tthis.updateContent(message);\n\t\t}\n\t}\n\n\toverride invalidate(): void {\n\t\tsuper.invalidate();\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage);\n\t\t}\n\t}\n\n\tsetHideThinkingBlock(hide: boolean): void {\n\t\tthis.hideThinkingBlock = hide;\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage);\n\t\t}\n\t}\n\n\t/**\n\t * Part of the ctrl+o expand toggle. Reasoning is \"detail\" in exactly the way\n\t * tool output is, so the one key reveals both; implementing this makes the\n\t * component visible to the same expandable-child sweep the tool blocks use,\n\t * with no separate rebuild path.\n\t */\n\tsetExpanded(expanded: boolean): void {\n\t\tthis.setHideThinkingBlock(!expanded);\n\t}\n\n\tsetHiddenThinkingLabel(label: string): void {\n\t\tthis.hiddenThinkingLabel = label;\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage);\n\t\t}\n\t}\n\n\tsetOutputPad(padding: number): void {\n\t\tthis.outputPad = padding;\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage);\n\t\t}\n\t}\n\n\toverride render(width: number): string[] {\n\t\t// Crush-style ▌ gutter bar on every line (dim for assistant), text\n\t\t// capped at MESSAGE_MAX_TEXT_WIDTH on wide terminals.\n\t\tconst contentWidth = Math.min(width - 2, MESSAGE_MAX_TEXT_WIDTH);\n\t\tconst bar = theme.fg(\"dim\", \"▌\");\n\t\tconst lines = super\n\t\t\t.render(Math.max(1, contentWidth))\n\t\t\t.map((line) => (line.length > 0 ? `${bar} ${line}` : `${bar}`));\n\t\tif (this.hasToolCalls || lines.length === 0) {\n\t\t\treturn lines;\n\t\t}\n\n\t\tlines[0] = OSC133_ZONE_START + lines[0];\n\t\tlines[lines.length - 1] = OSC133_ZONE_END + OSC133_ZONE_FINAL + lines[lines.length - 1];\n\t\treturn lines;\n\t}\n\n\tupdateContent(message: AssistantMessage, isStreaming = this.isStreaming): void {\n\t\tthis.lastMessage = message;\n\t\tthis.isStreaming = isStreaming;\n\n\t\t// Clear content container\n\t\tthis.contentContainer.clear();\n\n\t\tconst hasVisibleContent = message.content.some(\n\t\t\t(c) => (c.type === \"text\" && c.text.trim()) || (c.type === \"thinking\" && c.thinking.trim()),\n\t\t);\n\n\t\tif (hasVisibleContent) {\n\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t}\n\n\t\t// Render content in order\n\t\tfor (let i = 0; i < message.content.length; i++) {\n\t\t\tconst content = message.content[i];\n\t\t\tif (content.type === \"text\" && content.text.trim()) {\n\t\t\t\t// Assistant text messages with no background - trim the text\n\t\t\t\t// Set paddingY=0 to avoid extra spacing before tool executions\n\t\t\t\tthis.contentContainer.addChild(\n\t\t\t\t\tnew Markdown(content.text.trim(), this.outputPad, 0, this.markdownTheme, undefined, {\n\t\t\t\t\t\tshowHeadingMarkers: false,\n\t\t\t\t\t\ttransform: createMarkdownTransform(\"assistant\", this.isStreaming, this.markdownTransformers),\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t} else if (content.type === \"thinking\") {\n\t\t\t\tconst thinkingBlocks: string[] = [];\n\t\t\t\tfor (; i < message.content.length; i++) {\n\t\t\t\t\tconst thinkingContent = message.content[i];\n\t\t\t\t\tif (thinkingContent.type !== \"thinking\") {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tconst thinking = thinkingContent.thinking.trim();\n\t\t\t\t\tif (thinking) {\n\t\t\t\t\t\tthinkingBlocks.push(thinking);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\ti--;\n\n\t\t\t\tif (thinkingBlocks.length === 0) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// Add spacing only when another visible assistant content block follows.\n\t\t\t\t// This avoids a superfluous blank line before separately-rendered tool execution blocks.\n\t\t\t\tconst hasVisibleContentAfter = message.content\n\t\t\t\t\t.slice(i + 1)\n\t\t\t\t\t.some((c) => (c.type === \"text\" && c.text.trim()) || (c.type === \"thinking\" && c.thinking.trim()));\n\n\t\t\t\tif (this.hideThinkingBlock) {\n\t\t\t\t\t// Show one static label for each run of thinking blocks when hidden.\n\t\t\t\t\tthis.contentContainer.addChild(\n\t\t\t\t\t\tnew Text(theme.italic(theme.fg(\"thinkingText\", this.hiddenThinkingLabel)), this.outputPad, 0),\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\t// Render each run of thinking blocks as one Markdown section\n\t\t\t\t\t// inside a crush-style raised panel.\n\t\t\t\t\tconst panel = new ThinkingPanel();\n\t\t\t\t\tpanel.addChild(\n\t\t\t\t\t\tnew Markdown(\n\t\t\t\t\t\t\tthinkingBlocks.join(\"\\n\\n\"),\n\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\tthis.markdownTheme,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tcolor: (text: string) => theme.fg(\"thinkingText\", text),\n\t\t\t\t\t\t\t\titalic: true,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tshowHeadingMarkers: false,\n\t\t\t\t\t\t\t\ttransform: createMarkdownTransform(\n\t\t\t\t\t\t\t\t\t\"assistant-thinking\",\n\t\t\t\t\t\t\t\t\tthis.isStreaming,\n\t\t\t\t\t\t\t\t\tthis.markdownTransformers,\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t\tthis.contentContainer.addChild(panel);\n\t\t\t\t}\n\t\t\t\tif (hasVisibleContentAfter) {\n\t\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Check if incomplete/failed - show after partial content.\n\t\t// For aborted/error tool calls, tool execution components show the error.\n\t\t// Length stops can happen before a tool call is complete, so surface them here too.\n\t\tconst hasToolCalls = message.content.some((c) => c.type === \"toolCall\");\n\t\tthis.hasToolCalls = hasToolCalls;\n\t\tif (message.stopReason === \"length\") {\n\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\tthis.contentContainer.addChild(\n\t\t\t\tnew Text(theme.fg(\"error\", \"Response was truncated before completion.\"), this.outputPad, 0),\n\t\t\t);\n\t\t} else if (!hasToolCalls) {\n\t\t\tif (message.stopReason === \"aborted\") {\n\t\t\t\tconst abortMessage =\n\t\t\t\t\tmessage.errorMessage && message.errorMessage !== \"Request was aborted\"\n\t\t\t\t\t\t? message.errorMessage\n\t\t\t\t\t\t: \"Operation aborted\";\n\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\tthis.contentContainer.addChild(new Text(theme.fg(\"error\", abortMessage), this.outputPad, 0));\n\t\t\t} else if (message.stopReason === \"error\") {\n\t\t\t\tconst errorMsg = message.errorMessage || \"Unknown error\";\n\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\tthis.contentContainer.addChild(new Text(theme.fg(\"error\", `Error: ${errorMsg}`), this.outputPad, 0));\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
|
@@ -104,6 +104,7 @@ export class AssistantMessageComponent extends Container {
|
|
|
104
104
|
// Assistant text messages with no background - trim the text
|
|
105
105
|
// Set paddingY=0 to avoid extra spacing before tool executions
|
|
106
106
|
this.contentContainer.addChild(new Markdown(content.text.trim(), this.outputPad, 0, this.markdownTheme, undefined, {
|
|
107
|
+
showHeadingMarkers: false,
|
|
107
108
|
transform: createMarkdownTransform("assistant", this.isStreaming, this.markdownTransformers),
|
|
108
109
|
}));
|
|
109
110
|
}
|
|
@@ -140,6 +141,7 @@ export class AssistantMessageComponent extends Container {
|
|
|
140
141
|
color: (text) => theme.fg("thinkingText", text),
|
|
141
142
|
italic: true,
|
|
142
143
|
}, {
|
|
144
|
+
showHeadingMarkers: false,
|
|
143
145
|
transform: createMarkdownTransform("assistant-thinking", this.isStreaming, this.markdownTransformers),
|
|
144
146
|
}));
|
|
145
147
|
this.contentContainer.addChild(panel);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assistant-message.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/assistant-message.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAsB,MAAM,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAE/F,OAAO,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,0DAA0D;AAC1D,MAAM,aAAc,SAAQ,SAAS;IAC3B,MAAM,CAAC,KAAa,EAAY;QACxC,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC;QACnD,OAAO,QAAQ,CAAC,KAAK,EAAE,KAAK,EAAE,iBAAiB,EAAE,CAAC,CAAC,CAAC;IAAA,CACpD;CACD;AAED,MAAM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AAI,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,UAAU,QAAQ,EAAE,CAAC,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC;YACtG,CAAC;QACF,CAAC;IAAA,CACD;CACD","sourcesContent":["import type { AssistantMessage } from \"@earendil-works/pi-ai\";\nimport { Container, Markdown, type MarkdownTheme, Spacer, Text } from \"@earendil-works/pi-tui\";\nimport type { MarkdownTransformer } from \"../../../core/extensions/types.ts\";\nimport { getMarkdownTheme, theme } from \"../theme/theme.ts\";\nimport { createMarkdownTransform } from \"./markdown-transform.ts\";\nimport { MESSAGE_MAX_TEXT_WIDTH } from \"./message-layout.ts\";\nimport { panelize } from \"./panel.ts\";\n\n/** Crush-style raised panel around the thinking block. */\nclass ThinkingPanel extends Container {\n\toverride render(width: number): string[] {\n\t\tconst inner = super.render(Math.max(1, width - 5));\n\t\treturn panelize(inner, width, \"customMessageBg\", 1);\n\t}\n}\n\nconst OSC133_ZONE_START = \"\\x1b]133;A\\x07\";\nconst OSC133_ZONE_END = \"\\x1b]133;B\\x07\";\nconst OSC133_ZONE_FINAL = \"\\x1b]133;C\\x07\";\n\n/**\n * Component that renders a complete assistant message\n */\nexport class AssistantMessageComponent extends Container {\n\tprivate contentContainer: Container;\n\tprivate hideThinkingBlock: boolean;\n\tprivate markdownTheme: MarkdownTheme;\n\tprivate hiddenThinkingLabel: string;\n\tprivate outputPad: number;\n\tprivate markdownTransformers: readonly MarkdownTransformer[];\n\tprivate lastMessage?: AssistantMessage;\n\tprivate hasToolCalls = false;\n\tprivate isStreaming = false;\n\n\tconstructor(\n\t\tmessage?: AssistantMessage,\n\t\thideThinkingBlock = false,\n\t\tmarkdownTheme: MarkdownTheme = getMarkdownTheme(),\n\t\thiddenThinkingLabel = \"Thinking...\",\n\t\toutputPad = 1,\n\t\tmarkdownTransformers: readonly MarkdownTransformer[] = [],\n\t) {\n\t\tsuper();\n\n\t\tthis.hideThinkingBlock = hideThinkingBlock;\n\t\tthis.markdownTheme = markdownTheme;\n\t\tthis.hiddenThinkingLabel = hiddenThinkingLabel;\n\t\tthis.outputPad = outputPad;\n\t\tthis.markdownTransformers = markdownTransformers;\n\n\t\t// Container for text/thinking content\n\t\tthis.contentContainer = new Container();\n\t\tthis.addChild(this.contentContainer);\n\n\t\tif (message) {\n\t\t\tthis.updateContent(message);\n\t\t}\n\t}\n\n\toverride invalidate(): void {\n\t\tsuper.invalidate();\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage);\n\t\t}\n\t}\n\n\tsetHideThinkingBlock(hide: boolean): void {\n\t\tthis.hideThinkingBlock = hide;\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage);\n\t\t}\n\t}\n\n\t/**\n\t * Part of the ctrl+o expand toggle. Reasoning is \"detail\" in exactly the way\n\t * tool output is, so the one key reveals both; implementing this makes the\n\t * component visible to the same expandable-child sweep the tool blocks use,\n\t * with no separate rebuild path.\n\t */\n\tsetExpanded(expanded: boolean): void {\n\t\tthis.setHideThinkingBlock(!expanded);\n\t}\n\n\tsetHiddenThinkingLabel(label: string): void {\n\t\tthis.hiddenThinkingLabel = label;\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage);\n\t\t}\n\t}\n\n\tsetOutputPad(padding: number): void {\n\t\tthis.outputPad = padding;\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage);\n\t\t}\n\t}\n\n\toverride render(width: number): string[] {\n\t\t// Crush-style ▌ gutter bar on every line (dim for assistant), text\n\t\t// capped at MESSAGE_MAX_TEXT_WIDTH on wide terminals.\n\t\tconst contentWidth = Math.min(width - 2, MESSAGE_MAX_TEXT_WIDTH);\n\t\tconst bar = theme.fg(\"dim\", \"▌\");\n\t\tconst lines = super\n\t\t\t.render(Math.max(1, contentWidth))\n\t\t\t.map((line) => (line.length > 0 ? `${bar} ${line}` : `${bar}`));\n\t\tif (this.hasToolCalls || lines.length === 0) {\n\t\t\treturn lines;\n\t\t}\n\n\t\tlines[0] = OSC133_ZONE_START + lines[0];\n\t\tlines[lines.length - 1] = OSC133_ZONE_END + OSC133_ZONE_FINAL + lines[lines.length - 1];\n\t\treturn lines;\n\t}\n\n\tupdateContent(message: AssistantMessage, isStreaming = this.isStreaming): void {\n\t\tthis.lastMessage = message;\n\t\tthis.isStreaming = isStreaming;\n\n\t\t// Clear content container\n\t\tthis.contentContainer.clear();\n\n\t\tconst hasVisibleContent = message.content.some(\n\t\t\t(c) => (c.type === \"text\" && c.text.trim()) || (c.type === \"thinking\" && c.thinking.trim()),\n\t\t);\n\n\t\tif (hasVisibleContent) {\n\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t}\n\n\t\t// Render content in order\n\t\tfor (let i = 0; i < message.content.length; i++) {\n\t\t\tconst content = message.content[i];\n\t\t\tif (content.type === \"text\" && content.text.trim()) {\n\t\t\t\t// Assistant text messages with no background - trim the text\n\t\t\t\t// Set paddingY=0 to avoid extra spacing before tool executions\n\t\t\t\tthis.contentContainer.addChild(\n\t\t\t\t\tnew Markdown(content.text.trim(), this.outputPad, 0, this.markdownTheme, undefined, {\n\t\t\t\t\t\ttransform: createMarkdownTransform(\"assistant\", this.isStreaming, this.markdownTransformers),\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t} else if (content.type === \"thinking\") {\n\t\t\t\tconst thinkingBlocks: string[] = [];\n\t\t\t\tfor (; i < message.content.length; i++) {\n\t\t\t\t\tconst thinkingContent = message.content[i];\n\t\t\t\t\tif (thinkingContent.type !== \"thinking\") {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tconst thinking = thinkingContent.thinking.trim();\n\t\t\t\t\tif (thinking) {\n\t\t\t\t\t\tthinkingBlocks.push(thinking);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\ti--;\n\n\t\t\t\tif (thinkingBlocks.length === 0) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// Add spacing only when another visible assistant content block follows.\n\t\t\t\t// This avoids a superfluous blank line before separately-rendered tool execution blocks.\n\t\t\t\tconst hasVisibleContentAfter = message.content\n\t\t\t\t\t.slice(i + 1)\n\t\t\t\t\t.some((c) => (c.type === \"text\" && c.text.trim()) || (c.type === \"thinking\" && c.thinking.trim()));\n\n\t\t\t\tif (this.hideThinkingBlock) {\n\t\t\t\t\t// Show one static label for each run of thinking blocks when hidden.\n\t\t\t\t\tthis.contentContainer.addChild(\n\t\t\t\t\t\tnew Text(theme.italic(theme.fg(\"thinkingText\", this.hiddenThinkingLabel)), this.outputPad, 0),\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\t// Render each run of thinking blocks as one Markdown section\n\t\t\t\t\t// inside a crush-style raised panel.\n\t\t\t\t\tconst panel = new ThinkingPanel();\n\t\t\t\t\tpanel.addChild(\n\t\t\t\t\t\tnew Markdown(\n\t\t\t\t\t\t\tthinkingBlocks.join(\"\\n\\n\"),\n\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\tthis.markdownTheme,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tcolor: (text: string) => theme.fg(\"thinkingText\", text),\n\t\t\t\t\t\t\t\titalic: true,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttransform: createMarkdownTransform(\n\t\t\t\t\t\t\t\t\t\"assistant-thinking\",\n\t\t\t\t\t\t\t\t\tthis.isStreaming,\n\t\t\t\t\t\t\t\t\tthis.markdownTransformers,\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t\tthis.contentContainer.addChild(panel);\n\t\t\t\t}\n\t\t\t\tif (hasVisibleContentAfter) {\n\t\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Check if incomplete/failed - show after partial content.\n\t\t// For aborted/error tool calls, tool execution components show the error.\n\t\t// Length stops can happen before a tool call is complete, so surface them here too.\n\t\tconst hasToolCalls = message.content.some((c) => c.type === \"toolCall\");\n\t\tthis.hasToolCalls = hasToolCalls;\n\t\tif (message.stopReason === \"length\") {\n\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\tthis.contentContainer.addChild(\n\t\t\t\tnew Text(theme.fg(\"error\", \"Response was truncated before completion.\"), this.outputPad, 0),\n\t\t\t);\n\t\t} else if (!hasToolCalls) {\n\t\t\tif (message.stopReason === \"aborted\") {\n\t\t\t\tconst abortMessage =\n\t\t\t\t\tmessage.errorMessage && message.errorMessage !== \"Request was aborted\"\n\t\t\t\t\t\t? message.errorMessage\n\t\t\t\t\t\t: \"Operation aborted\";\n\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\tthis.contentContainer.addChild(new Text(theme.fg(\"error\", abortMessage), this.outputPad, 0));\n\t\t\t} else if (message.stopReason === \"error\") {\n\t\t\t\tconst errorMsg = message.errorMessage || \"Unknown error\";\n\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\tthis.contentContainer.addChild(new Text(theme.fg(\"error\", `Error: ${errorMsg}`), this.outputPad, 0));\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"assistant-message.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/assistant-message.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAsB,MAAM,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAE/F,OAAO,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,0DAA0D;AAC1D,M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Y,CAAC,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC;YAC9F,CAAC;iBAAM,IAAI,OAAO,CAAC,UAAU,KAAK,OAAO,EAAE,CAAC;gBAC3C,MAAM,QAAQ,GAAG,OAAO,CAAC,YAAY,IAAI,eAAe,CAAC;gBACzD,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC9C,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,UAAU,QAAQ,EAAE,CAAC,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC;YACtG,CAAC;QACF,CAAC;IAAA,CACD;CACD","sourcesContent":["import type { AssistantMessage } from \"@earendil-works/pi-ai\";\nimport { Container, Markdown, type MarkdownTheme, Spacer, Text } from \"@earendil-works/pi-tui\";\nimport type { MarkdownTransformer } from \"../../../core/extensions/types.ts\";\nimport { getMarkdownTheme, theme } from \"../theme/theme.ts\";\nimport { createMarkdownTransform } from \"./markdown-transform.ts\";\nimport { MESSAGE_MAX_TEXT_WIDTH } from \"./message-layout.ts\";\nimport { panelize } from \"./panel.ts\";\n\n/** Crush-style raised panel around the thinking block. */\nclass ThinkingPanel extends Container {\n\toverride render(width: number): string[] {\n\t\tconst inner = super.render(Math.max(1, width - 5));\n\t\treturn panelize(inner, width, \"customMessageBg\", 1);\n\t}\n}\n\nconst OSC133_ZONE_START = \"\\x1b]133;A\\x07\";\nconst OSC133_ZONE_END = \"\\x1b]133;B\\x07\";\nconst OSC133_ZONE_FINAL = \"\\x1b]133;C\\x07\";\n\n/**\n * Component that renders a complete assistant message\n */\nexport class AssistantMessageComponent extends Container {\n\tprivate contentContainer: Container;\n\tprivate hideThinkingBlock: boolean;\n\tprivate markdownTheme: MarkdownTheme;\n\tprivate hiddenThinkingLabel: string;\n\tprivate outputPad: number;\n\tprivate markdownTransformers: readonly MarkdownTransformer[];\n\tprivate lastMessage?: AssistantMessage;\n\tprivate hasToolCalls = false;\n\tprivate isStreaming = false;\n\n\tconstructor(\n\t\tmessage?: AssistantMessage,\n\t\thideThinkingBlock = false,\n\t\tmarkdownTheme: MarkdownTheme = getMarkdownTheme(),\n\t\thiddenThinkingLabel = \"Thinking...\",\n\t\toutputPad = 1,\n\t\tmarkdownTransformers: readonly MarkdownTransformer[] = [],\n\t) {\n\t\tsuper();\n\n\t\tthis.hideThinkingBlock = hideThinkingBlock;\n\t\tthis.markdownTheme = markdownTheme;\n\t\tthis.hiddenThinkingLabel = hiddenThinkingLabel;\n\t\tthis.outputPad = outputPad;\n\t\tthis.markdownTransformers = markdownTransformers;\n\n\t\t// Container for text/thinking content\n\t\tthis.contentContainer = new Container();\n\t\tthis.addChild(this.contentContainer);\n\n\t\tif (message) {\n\t\t\tthis.updateContent(message);\n\t\t}\n\t}\n\n\toverride invalidate(): void {\n\t\tsuper.invalidate();\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage);\n\t\t}\n\t}\n\n\tsetHideThinkingBlock(hide: boolean): void {\n\t\tthis.hideThinkingBlock = hide;\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage);\n\t\t}\n\t}\n\n\t/**\n\t * Part of the ctrl+o expand toggle. Reasoning is \"detail\" in exactly the way\n\t * tool output is, so the one key reveals both; implementing this makes the\n\t * component visible to the same expandable-child sweep the tool blocks use,\n\t * with no separate rebuild path.\n\t */\n\tsetExpanded(expanded: boolean): void {\n\t\tthis.setHideThinkingBlock(!expanded);\n\t}\n\n\tsetHiddenThinkingLabel(label: string): void {\n\t\tthis.hiddenThinkingLabel = label;\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage);\n\t\t}\n\t}\n\n\tsetOutputPad(padding: number): void {\n\t\tthis.outputPad = padding;\n\t\tif (this.lastMessage) {\n\t\t\tthis.updateContent(this.lastMessage);\n\t\t}\n\t}\n\n\toverride render(width: number): string[] {\n\t\t// Crush-style ▌ gutter bar on every line (dim for assistant), text\n\t\t// capped at MESSAGE_MAX_TEXT_WIDTH on wide terminals.\n\t\tconst contentWidth = Math.min(width - 2, MESSAGE_MAX_TEXT_WIDTH);\n\t\tconst bar = theme.fg(\"dim\", \"▌\");\n\t\tconst lines = super\n\t\t\t.render(Math.max(1, contentWidth))\n\t\t\t.map((line) => (line.length > 0 ? `${bar} ${line}` : `${bar}`));\n\t\tif (this.hasToolCalls || lines.length === 0) {\n\t\t\treturn lines;\n\t\t}\n\n\t\tlines[0] = OSC133_ZONE_START + lines[0];\n\t\tlines[lines.length - 1] = OSC133_ZONE_END + OSC133_ZONE_FINAL + lines[lines.length - 1];\n\t\treturn lines;\n\t}\n\n\tupdateContent(message: AssistantMessage, isStreaming = this.isStreaming): void {\n\t\tthis.lastMessage = message;\n\t\tthis.isStreaming = isStreaming;\n\n\t\t// Clear content container\n\t\tthis.contentContainer.clear();\n\n\t\tconst hasVisibleContent = message.content.some(\n\t\t\t(c) => (c.type === \"text\" && c.text.trim()) || (c.type === \"thinking\" && c.thinking.trim()),\n\t\t);\n\n\t\tif (hasVisibleContent) {\n\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t}\n\n\t\t// Render content in order\n\t\tfor (let i = 0; i < message.content.length; i++) {\n\t\t\tconst content = message.content[i];\n\t\t\tif (content.type === \"text\" && content.text.trim()) {\n\t\t\t\t// Assistant text messages with no background - trim the text\n\t\t\t\t// Set paddingY=0 to avoid extra spacing before tool executions\n\t\t\t\tthis.contentContainer.addChild(\n\t\t\t\t\tnew Markdown(content.text.trim(), this.outputPad, 0, this.markdownTheme, undefined, {\n\t\t\t\t\t\tshowHeadingMarkers: false,\n\t\t\t\t\t\ttransform: createMarkdownTransform(\"assistant\", this.isStreaming, this.markdownTransformers),\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t} else if (content.type === \"thinking\") {\n\t\t\t\tconst thinkingBlocks: string[] = [];\n\t\t\t\tfor (; i < message.content.length; i++) {\n\t\t\t\t\tconst thinkingContent = message.content[i];\n\t\t\t\t\tif (thinkingContent.type !== \"thinking\") {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tconst thinking = thinkingContent.thinking.trim();\n\t\t\t\t\tif (thinking) {\n\t\t\t\t\t\tthinkingBlocks.push(thinking);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\ti--;\n\n\t\t\t\tif (thinkingBlocks.length === 0) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// Add spacing only when another visible assistant content block follows.\n\t\t\t\t// This avoids a superfluous blank line before separately-rendered tool execution blocks.\n\t\t\t\tconst hasVisibleContentAfter = message.content\n\t\t\t\t\t.slice(i + 1)\n\t\t\t\t\t.some((c) => (c.type === \"text\" && c.text.trim()) || (c.type === \"thinking\" && c.thinking.trim()));\n\n\t\t\t\tif (this.hideThinkingBlock) {\n\t\t\t\t\t// Show one static label for each run of thinking blocks when hidden.\n\t\t\t\t\tthis.contentContainer.addChild(\n\t\t\t\t\t\tnew Text(theme.italic(theme.fg(\"thinkingText\", this.hiddenThinkingLabel)), this.outputPad, 0),\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\t// Render each run of thinking blocks as one Markdown section\n\t\t\t\t\t// inside a crush-style raised panel.\n\t\t\t\t\tconst panel = new ThinkingPanel();\n\t\t\t\t\tpanel.addChild(\n\t\t\t\t\t\tnew Markdown(\n\t\t\t\t\t\t\tthinkingBlocks.join(\"\\n\\n\"),\n\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\tthis.markdownTheme,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tcolor: (text: string) => theme.fg(\"thinkingText\", text),\n\t\t\t\t\t\t\t\titalic: true,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tshowHeadingMarkers: false,\n\t\t\t\t\t\t\t\ttransform: createMarkdownTransform(\n\t\t\t\t\t\t\t\t\t\"assistant-thinking\",\n\t\t\t\t\t\t\t\t\tthis.isStreaming,\n\t\t\t\t\t\t\t\t\tthis.markdownTransformers,\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t\tthis.contentContainer.addChild(panel);\n\t\t\t\t}\n\t\t\t\tif (hasVisibleContentAfter) {\n\t\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Check if incomplete/failed - show after partial content.\n\t\t// For aborted/error tool calls, tool execution components show the error.\n\t\t// Length stops can happen before a tool call is complete, so surface them here too.\n\t\tconst hasToolCalls = message.content.some((c) => c.type === \"toolCall\");\n\t\tthis.hasToolCalls = hasToolCalls;\n\t\tif (message.stopReason === \"length\") {\n\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\tthis.contentContainer.addChild(\n\t\t\t\tnew Text(theme.fg(\"error\", \"Response was truncated before completion.\"), this.outputPad, 0),\n\t\t\t);\n\t\t} else if (!hasToolCalls) {\n\t\t\tif (message.stopReason === \"aborted\") {\n\t\t\t\tconst abortMessage =\n\t\t\t\t\tmessage.errorMessage && message.errorMessage !== \"Request was aborted\"\n\t\t\t\t\t\t? message.errorMessage\n\t\t\t\t\t\t: \"Operation aborted\";\n\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\tthis.contentContainer.addChild(new Text(theme.fg(\"error\", abortMessage), this.outputPad, 0));\n\t\t\t} else if (message.stopReason === \"error\") {\n\t\t\t\tconst errorMsg = message.errorMessage || \"Unknown error\";\n\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\tthis.contentContainer.addChild(new Text(theme.fg(\"error\", `Error: ${errorMsg}`), this.outputPad, 0));\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
|
@@ -3,7 +3,8 @@ import type { HeightAware } from "./dialog-frame.ts";
|
|
|
3
3
|
export declare class CommandPaletteComponent extends Container implements HeightAware {
|
|
4
4
|
private readonly input;
|
|
5
5
|
private readonly list;
|
|
6
|
-
|
|
6
|
+
private readonly onComplete;
|
|
7
|
+
constructor(commands: SlashCommand[], onRun: (commandText: string) => void, onComplete: (commandText: string) => void, onCancel: () => void);
|
|
7
8
|
/** Shrink the command list so the palette fits the height the overlay allows. */
|
|
8
9
|
setMaxHeight(lines: number): void;
|
|
9
10
|
/** Keyboard goes to the filter input except navigation/confirm keys, which the list owns. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-palette.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/command-palette.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,SAAS,EAKT,KAAK,YAAY,EAEjB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAgBrD,qBAAa,uBAAwB,SAAQ,SAAU,YAAW,WAAW;IAC5E,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAQ;IAC9B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAa;
|
|
1
|
+
{"version":3,"file":"command-palette.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/command-palette.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,SAAS,EAKT,KAAK,YAAY,EAEjB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAgBrD,qBAAa,uBAAwB,SAAQ,SAAU,YAAW,WAAW;IAC5E,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAQ;IAC9B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAa;IAClC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAgC;IAE3D,YACC,QAAQ,EAAE,YAAY,EAAE,EACxB,KAAK,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,IAAI,EACpC,UAAU,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,IAAI,EACzC,QAAQ,EAAE,MAAM,IAAI,EAmCpB;IAED,iFAAiF;IACjF,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAEhC;IAED,6FAA6F;IAC7F,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAkB9B;CACD","sourcesContent":["import {\n\tContainer,\n\tgetKeybindings,\n\tInput,\n\ttype SelectItem,\n\tSelectList,\n\ttype SlashCommand,\n\tText,\n} from \"@earendil-works/pi-tui\";\nimport { gradientRule } from \"../theme/brand.ts\";\nimport { getSelectListTheme, theme } from \"../theme/theme.ts\";\nimport type { HeightAware } from \"./dialog-frame.ts\";\n\n/**\n * Crush-style centered command palette: hatched gradient title, filter input,\n * command list. Opens via ctrl+k (app.commands.palette); Enter runs the\n * selected slash command through the normal submit path — typing /commands in\n * the editor stays the primary, standard interface.\n *\n * The rounded border lives in {@link DialogFrame}, which wraps this and every\n * other overlay.\n */\n\n/** Non-list rows the palette renders: title, input, three spacers, and hint. */\nconst PALETTE_CHROME_ROWS = 6;\nconst DEFAULT_VISIBLE_ITEMS = 12;\n\nexport class CommandPaletteComponent extends Container implements HeightAware {\n\tprivate readonly input: Input;\n\tprivate readonly list: SelectList;\n\tprivate readonly onComplete: (commandText: string) => void;\n\n\tconstructor(\n\t\tcommands: SlashCommand[],\n\t\tonRun: (commandText: string) => void,\n\t\tonComplete: (commandText: string) => void,\n\t\tonCancel: () => void,\n\t) {\n\t\tsuper();\n\t\tthis.onComplete = onComplete;\n\t\tconst items: SelectItem[] = commands.map((command) => ({\n\t\t\tvalue: command.name,\n\t\t\tlabel: `/${command.name}`,\n\t\t\tdescription: command.description ?? \"\",\n\t\t}));\n\n\t\tthis.addChild(new Text(gradientRule(\"Commands\", 37), 1, 0));\n\t\tthis.addChild(new Text(\"\", 0, 0));\n\n\t\tthis.input = new Input();\n\t\tthis.addChild(this.input);\n\t\tthis.addChild(new Text(\"\", 0, 0));\n\n\t\tthis.list = new SelectList(items, DEFAULT_VISIBLE_ITEMS, getSelectListTheme(), {\n\t\t\tminPrimaryColumnWidth: 18,\n\t\t\tmaxPrimaryColumnWidth: 30,\n\t\t});\n\t\t// Both callbacks tear this palette down and often open another dialog, so\n\t\t// they must not run while the key that triggered them is still being\n\t\t// dispatched: the replacement overlay would be focused mid-event, receive\n\t\t// that same key, and close before rendering a single frame. Every command\n\t\t// that opens a dialog — /login, /model, /theme, /settings — was dead from\n\t\t// the palette because of this.\n\t\tthis.list.onSelect = (item) => setTimeout(() => onRun(`/${item.value}`), 0);\n\t\tthis.list.onCancel = () => setTimeout(onCancel, 0);\n\t\tthis.addChild(this.list);\n\n\t\tthis.addChild(new Text(\"\", 0, 0));\n\t\tthis.addChild(\n\t\t\tnew Text(theme.fg(\"muted\", \"↑/↓ choose · tab complete · enter run · esc cancel · type to filter\"), 1, 0),\n\t\t);\n\t}\n\n\t/** Shrink the command list so the palette fits the height the overlay allows. */\n\tsetMaxHeight(lines: number): void {\n\t\tthis.list.setMaxVisible(Math.min(DEFAULT_VISIBLE_ITEMS, lines - PALETTE_CHROME_ROWS));\n\t}\n\n\t/** Keyboard goes to the filter input except navigation/confirm keys, which the list owns. */\n\thandleInput(data: string): void {\n\t\tconst kb = getKeybindings();\n\t\tif (kb.matches(data, \"tui.input.tab\")) {\n\t\t\tconst selected = this.list.getSelectedItem();\n\t\t\tif (selected) setTimeout(() => this.onComplete(`/${selected.value}`), 0);\n\t\t\treturn;\n\t\t}\n\t\tconst isNavigation =\n\t\t\tkb.matches(data, \"tui.select.up\") ||\n\t\t\tkb.matches(data, \"tui.select.down\") ||\n\t\t\tkb.matches(data, \"tui.select.confirm\") ||\n\t\t\tkb.matches(data, \"tui.select.cancel\");\n\t\tif (isNavigation) {\n\t\t\tthis.list.handleInput(data);\n\t\t\treturn;\n\t\t}\n\t\tthis.input.handleInput(data);\n\t\tthis.list.setFilter(this.input.getValue().replace(/^\\//, \"\"));\n\t}\n}\n"]}
|
|
@@ -16,8 +16,10 @@ const DEFAULT_VISIBLE_ITEMS = 12;
|
|
|
16
16
|
export class CommandPaletteComponent extends Container {
|
|
17
17
|
input;
|
|
18
18
|
list;
|
|
19
|
-
|
|
19
|
+
onComplete;
|
|
20
|
+
constructor(commands, onRun, onComplete, onCancel) {
|
|
20
21
|
super();
|
|
22
|
+
this.onComplete = onComplete;
|
|
21
23
|
const items = commands.map((command) => ({
|
|
22
24
|
value: command.name,
|
|
23
25
|
label: `/${command.name}`,
|
|
@@ -42,7 +44,7 @@ export class CommandPaletteComponent extends Container {
|
|
|
42
44
|
this.list.onCancel = () => setTimeout(onCancel, 0);
|
|
43
45
|
this.addChild(this.list);
|
|
44
46
|
this.addChild(new Text("", 0, 0));
|
|
45
|
-
this.addChild(new Text(theme.fg("muted", "↑/↓ choose · enter run · esc cancel · type to filter"), 1, 0));
|
|
47
|
+
this.addChild(new Text(theme.fg("muted", "↑/↓ choose · tab complete · enter run · esc cancel · type to filter"), 1, 0));
|
|
46
48
|
}
|
|
47
49
|
/** Shrink the command list so the palette fits the height the overlay allows. */
|
|
48
50
|
setMaxHeight(lines) {
|
|
@@ -51,11 +53,16 @@ export class CommandPaletteComponent extends Container {
|
|
|
51
53
|
/** Keyboard goes to the filter input except navigation/confirm keys, which the list owns. */
|
|
52
54
|
handleInput(data) {
|
|
53
55
|
const kb = getKeybindings();
|
|
56
|
+
if (kb.matches(data, "tui.input.tab")) {
|
|
57
|
+
const selected = this.list.getSelectedItem();
|
|
58
|
+
if (selected)
|
|
59
|
+
setTimeout(() => this.onComplete(`/${selected.value}`), 0);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
54
62
|
const isNavigation = kb.matches(data, "tui.select.up") ||
|
|
55
63
|
kb.matches(data, "tui.select.down") ||
|
|
56
64
|
kb.matches(data, "tui.select.confirm") ||
|
|
57
|
-
kb.matches(data, "tui.select.cancel")
|
|
58
|
-
kb.matches(data, "tui.input.tab");
|
|
65
|
+
kb.matches(data, "tui.select.cancel");
|
|
59
66
|
if (isNavigation) {
|
|
60
67
|
this.list.handleInput(data);
|
|
61
68
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-palette.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/command-palette.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,SAAS,EACT,cAAc,EACd,KAAK,EAEL,UAAU,EAEV,IAAI,GACJ,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAG9D;;;;;;;;GAQG;AAEH,gFAAgF;AAChF,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAC9B,MAAM,qBAAqB,GAAG,EAAE,CAAC;AAEjC,MAAM,OAAO,uBAAwB,SAAQ,SAAS;IACpC,KAAK,CAAQ;IACb,IAAI,CAAa;
|
|
1
|
+
{"version":3,"file":"command-palette.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/command-palette.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,SAAS,EACT,cAAc,EACd,KAAK,EAEL,UAAU,EAEV,IAAI,GACJ,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAG9D;;;;;;;;GAQG;AAEH,gFAAgF;AAChF,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAC9B,MAAM,qBAAqB,GAAG,EAAE,CAAC;AAEjC,MAAM,OAAO,uBAAwB,SAAQ,SAAS;IACpC,KAAK,CAAQ;IACb,IAAI,CAAa;IACjB,UAAU,CAAgC;IAE3D,YACC,QAAwB,EACxB,KAAoC,EACpC,UAAyC,EACzC,QAAoB,EACnB;QACD,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,UAAU,G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YAC5B,OAAO;QACR,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QAC7B,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC;IAAA,CAC9D;CACD","sourcesContent":["import {\n\tContainer,\n\tgetKeybindings,\n\tInput,\n\ttype SelectItem,\n\tSelectList,\n\ttype SlashCommand,\n\tText,\n} from \"@earendil-works/pi-tui\";\nimport { gradientRule } from \"../theme/brand.ts\";\nimport { getSelectListTheme, theme } from \"../theme/theme.ts\";\nimport type { HeightAware } from \"./dialog-frame.ts\";\n\n/**\n * Crush-style centered command palette: hatched gradient title, filter input,\n * command list. Opens via ctrl+k (app.commands.palette); Enter runs the\n * selected slash command through the normal submit path — typing /commands in\n * the editor stays the primary, standard interface.\n *\n * The rounded border lives in {@link DialogFrame}, which wraps this and every\n * other overlay.\n */\n\n/** Non-list rows the palette renders: title, input, three spacers, and hint. */\nconst PALETTE_CHROME_ROWS = 6;\nconst DEFAULT_VISIBLE_ITEMS = 12;\n\nexport class CommandPaletteComponent extends Container implements HeightAware {\n\tprivate readonly input: Input;\n\tprivate readonly list: SelectList;\n\tprivate readonly onComplete: (commandText: string) => void;\n\n\tconstructor(\n\t\tcommands: SlashCommand[],\n\t\tonRun: (commandText: string) => void,\n\t\tonComplete: (commandText: string) => void,\n\t\tonCancel: () => void,\n\t) {\n\t\tsuper();\n\t\tthis.onComplete = onComplete;\n\t\tconst items: SelectItem[] = commands.map((command) => ({\n\t\t\tvalue: command.name,\n\t\t\tlabel: `/${command.name}`,\n\t\t\tdescription: command.description ?? \"\",\n\t\t}));\n\n\t\tthis.addChild(new Text(gradientRule(\"Commands\", 37), 1, 0));\n\t\tthis.addChild(new Text(\"\", 0, 0));\n\n\t\tthis.input = new Input();\n\t\tthis.addChild(this.input);\n\t\tthis.addChild(new Text(\"\", 0, 0));\n\n\t\tthis.list = new SelectList(items, DEFAULT_VISIBLE_ITEMS, getSelectListTheme(), {\n\t\t\tminPrimaryColumnWidth: 18,\n\t\t\tmaxPrimaryColumnWidth: 30,\n\t\t});\n\t\t// Both callbacks tear this palette down and often open another dialog, so\n\t\t// they must not run while the key that triggered them is still being\n\t\t// dispatched: the replacement overlay would be focused mid-event, receive\n\t\t// that same key, and close before rendering a single frame. Every command\n\t\t// that opens a dialog — /login, /model, /theme, /settings — was dead from\n\t\t// the palette because of this.\n\t\tthis.list.onSelect = (item) => setTimeout(() => onRun(`/${item.value}`), 0);\n\t\tthis.list.onCancel = () => setTimeout(onCancel, 0);\n\t\tthis.addChild(this.list);\n\n\t\tthis.addChild(new Text(\"\", 0, 0));\n\t\tthis.addChild(\n\t\t\tnew Text(theme.fg(\"muted\", \"↑/↓ choose · tab complete · enter run · esc cancel · type to filter\"), 1, 0),\n\t\t);\n\t}\n\n\t/** Shrink the command list so the palette fits the height the overlay allows. */\n\tsetMaxHeight(lines: number): void {\n\t\tthis.list.setMaxVisible(Math.min(DEFAULT_VISIBLE_ITEMS, lines - PALETTE_CHROME_ROWS));\n\t}\n\n\t/** Keyboard goes to the filter input except navigation/confirm keys, which the list owns. */\n\thandleInput(data: string): void {\n\t\tconst kb = getKeybindings();\n\t\tif (kb.matches(data, \"tui.input.tab\")) {\n\t\t\tconst selected = this.list.getSelectedItem();\n\t\t\tif (selected) setTimeout(() => this.onComplete(`/${selected.value}`), 0);\n\t\t\treturn;\n\t\t}\n\t\tconst isNavigation =\n\t\t\tkb.matches(data, \"tui.select.up\") ||\n\t\t\tkb.matches(data, \"tui.select.down\") ||\n\t\t\tkb.matches(data, \"tui.select.confirm\") ||\n\t\t\tkb.matches(data, \"tui.select.cancel\");\n\t\tif (isNavigation) {\n\t\t\tthis.list.handleInput(data);\n\t\t\treturn;\n\t\t}\n\t\tthis.input.handleInput(data);\n\t\tthis.list.setFilter(this.input.getValue().replace(/^\\//, \"\"));\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"footer.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/footer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAmB,MAAM,wBAAwB,CAAC;AACzE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,uCAAuC,CAAC;
|
|
1
|
+
{"version":3,"file":"footer.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/footer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAmB,MAAM,wBAAwB,CAAC;AACzE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,uCAAuC,CAAC;AAgBxF;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMlD;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAYhF;AAED;;;GAGG;AACH,qBAAa,eAAgB,YAAW,SAAS;IAChD,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,UAAU,CAA6B;IAE/C,YAAY,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,0BAA0B,EAGxE;IAED,UAAU,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,CAEtC;IAED;;;OAGG;IACH,UAAU,IAAI,IAAI,CAEjB;IAED;;;OAGG;IACH,OAAO,IAAI,IAAI,CAEd;IAED,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAmD9B;CACD","sourcesContent":["import { isAbsolute, relative, resolve, sep } from \"node:path\";\nimport { type Component, truncateToWidth } from \"@earendil-works/pi-tui\";\nimport type { AgentSession } from \"../../../core/agent-session.ts\";\nimport type { ReadonlyFooterDataProvider } from \"../../../core/footer-data-provider.ts\";\nimport { theme } from \"../theme/theme.ts\";\nimport { keyText } from \"./keybinding-hints.ts\";\n\n/**\n * Sanitize text for display in a single-line status.\n * Removes newlines, tabs, carriage returns, and other control characters.\n */\nfunction sanitizeStatusText(text: string): string {\n\t// Replace newlines, tabs, carriage returns with space, then collapse multiple spaces\n\treturn text\n\t\t.replace(/[\\r\\n\\t]/g, \" \")\n\t\t.replace(/ +/g, \" \")\n\t\t.trim();\n}\n\n/**\n * Format token counts for compact footer display.\n */\nexport function formatTokens(count: number): string {\n\tif (count < 1000) return count.toString();\n\tif (count < 10000) return `${(count / 1000).toFixed(1)}k`;\n\tif (count < 1000000) return `${Math.round(count / 1000)}k`;\n\tif (count < 10000000) return `${(count / 1000000).toFixed(1)}M`;\n\treturn `${Math.round(count / 1000000)}M`;\n}\n\nexport function formatCwdForFooter(cwd: string, home: string | undefined): string {\n\tif (!home) return cwd;\n\n\tconst resolvedCwd = resolve(cwd);\n\tconst resolvedHome = resolve(home);\n\tconst relativeToHome = relative(resolvedHome, resolvedCwd);\n\tconst isInsideHome =\n\t\trelativeToHome === \"\" ||\n\t\t(relativeToHome !== \"..\" && !relativeToHome.startsWith(`..${sep}`) && !isAbsolute(relativeToHome));\n\n\tif (!isInsideHome) return cwd;\n\treturn relativeToHome === \"\" ? \"~\" : `~${sep}${relativeToHome}`;\n}\n\n/**\n * Footer component that shows cwd, extension statuses, and command hints.\n * Session metrics live in the fullscreen side rail instead of being duplicated here.\n */\nexport class FooterComponent implements Component {\n\tprivate session: AgentSession;\n\tprivate footerData: ReadonlyFooterDataProvider;\n\n\tconstructor(session: AgentSession, footerData: ReadonlyFooterDataProvider) {\n\t\tthis.session = session;\n\t\tthis.footerData = footerData;\n\t}\n\n\tsetSession(session: AgentSession): void {\n\t\tthis.session = session;\n\t}\n\n\t/**\n\t * No-op: git branch caching now handled by provider.\n\t * Kept for compatibility with existing call sites in interactive-mode.\n\t */\n\tinvalidate(): void {\n\t\t// No-op: git branch is cached/invalidated by provider\n\t}\n\n\t/**\n\t * Clean up resources.\n\t * Git watcher cleanup now handled by provider.\n\t */\n\tdispose(): void {\n\t\t// Git watcher cleanup handled by provider\n\t}\n\n\trender(width: number): string[] {\n\t\t// Replace home directory with ~\n\t\tlet pwd = formatCwdForFooter(this.session.sessionManager.getCwd(), process.env.HOME || process.env.USERPROFILE);\n\n\t\t// Add git branch if available\n\t\tconst branch = this.footerData.getGitBranch();\n\t\tif (branch) {\n\t\t\tpwd = `${pwd} (${branch})`;\n\t\t}\n\n\t\t// Add session name if set\n\t\tconst sessionName = this.session.sessionManager.getSessionName();\n\t\tif (sessionName) {\n\t\t\tpwd = `${pwd} • ${sessionName}`;\n\t\t}\n\n\t\tconst pwdLine = truncateToWidth(theme.fg(\"dim\", pwd), width, theme.fg(\"dim\", \"...\"));\n\t\tconst lines = [pwdLine];\n\n\t\t// Add extension statuses on a single line, sorted by key alphabetically\n\t\tconst extensionStatuses = this.footerData.getExtensionStatuses();\n\t\tconst quitConfirmation = extensionStatuses.get(\"quit-confirmation\");\n\t\tconst regularStatuses = Array.from(extensionStatuses.entries()).filter(([key]) => key !== \"quit-confirmation\");\n\t\tif (regularStatuses.length > 0) {\n\t\t\tconst sortedStatuses = regularStatuses\n\t\t\t\t.sort(([a], [b]) => a.localeCompare(b))\n\t\t\t\t.map(([, text]) => sanitizeStatusText(text));\n\t\t\tconst statusLine = sortedStatuses.join(\" \");\n\t\t\t// Truncate to terminal width with dim ellipsis for consistency with footer style\n\t\t\tlines.push(truncateToWidth(statusLine, width, theme.fg(\"dim\", \"...\")));\n\t\t}\n\n\t\t// Crush-style key hints: bold keys, muted labels, • separators.\n\t\tconst hint = (key: string, label: string) => `${theme.bold(key)} ${theme.fg(\"muted\", label)}`;\n\t\tconst hintsLine = [\n\t\t\thint(\"/\", \"commands\"),\n\t\t\thint(\"!\", \"bash\"),\n\t\t\thint(\"ctrl+l\", \"models\"),\n\t\t\thint(\"ctrl+k\", \"palette\"),\n\t\t\thint(\"ctrl+o\", \"expand\"),\n\t\t\thint(keyText(\"app.clear\"), \"quit\"),\n\t\t].join(theme.fg(\"dim\", \" • \"));\n\t\tlines.push(truncateToWidth(hintsLine, width, theme.fg(\"dim\", \"...\")));\n\n\t\tif (quitConfirmation) {\n\t\t\tlines.push(\n\t\t\t\ttruncateToWidth(theme.fg(\"muted\", sanitizeStatusText(quitConfirmation)), width, theme.fg(\"dim\", \"...\")),\n\t\t\t);\n\t\t}\n\n\t\treturn lines;\n\t}\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isAbsolute, relative, resolve, sep } from "node:path";
|
|
2
2
|
import { truncateToWidth } from "@earendil-works/pi-tui";
|
|
3
3
|
import { theme } from "../theme/theme.js";
|
|
4
|
+
import { keyText } from "./keybinding-hints.js";
|
|
4
5
|
/**
|
|
5
6
|
* Sanitize text for display in a single-line status.
|
|
6
7
|
* Removes newlines, tabs, carriage returns, and other control characters.
|
|
@@ -83,8 +84,10 @@ export class FooterComponent {
|
|
|
83
84
|
const lines = [pwdLine];
|
|
84
85
|
// Add extension statuses on a single line, sorted by key alphabetically
|
|
85
86
|
const extensionStatuses = this.footerData.getExtensionStatuses();
|
|
86
|
-
|
|
87
|
-
|
|
87
|
+
const quitConfirmation = extensionStatuses.get("quit-confirmation");
|
|
88
|
+
const regularStatuses = Array.from(extensionStatuses.entries()).filter(([key]) => key !== "quit-confirmation");
|
|
89
|
+
if (regularStatuses.length > 0) {
|
|
90
|
+
const sortedStatuses = regularStatuses
|
|
88
91
|
.sort(([a], [b]) => a.localeCompare(b))
|
|
89
92
|
.map(([, text]) => sanitizeStatusText(text));
|
|
90
93
|
const statusLine = sortedStatuses.join(" ");
|
|
@@ -99,9 +102,12 @@ export class FooterComponent {
|
|
|
99
102
|
hint("ctrl+l", "models"),
|
|
100
103
|
hint("ctrl+k", "palette"),
|
|
101
104
|
hint("ctrl+o", "expand"),
|
|
102
|
-
hint("
|
|
105
|
+
hint(keyText("app.clear"), "quit"),
|
|
103
106
|
].join(theme.fg("dim", " • "));
|
|
104
107
|
lines.push(truncateToWidth(hintsLine, width, theme.fg("dim", "...")));
|
|
108
|
+
if (quitConfirmation) {
|
|
109
|
+
lines.push(truncateToWidth(theme.fg("muted", sanitizeStatusText(quitConfirmation)), width, theme.fg("dim", "...")));
|
|
110
|
+
}
|
|
105
111
|
return lines;
|
|
106
112
|
}
|
|
107
113
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"footer.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/footer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAkB,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAGzE,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"footer.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/footer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAkB,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAGzE,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEhD;;;GAGG;AACH,SAAS,kBAAkB,CAAC,IAAY,EAAU;IACjD,qFAAqF;IACrF,OAAO,IAAI;SACT,OAAO,CAAC,WAAW,EAAE,GAAG,CAAC;SACzB,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;SACnB,IAAI,EAAE,CAAC;AAAA,CACT;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,KAAa,EAAU;IACnD,IAAI,KAAK,GAAG,IAAI;QAAE,OAAO,KAAK,CAAC,QAAQ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K,CAAC,EAAE,CAAC,KAAK,EAAE,OAAK,CAAC,CAAC,CAAC;QAC/B,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,SAAS,EAAE,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;QAEtE,IAAI,gBAAgB,EAAE,CAAC;YACtB,KAAK,CAAC,IAAI,CACT,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,kBAAkB,CAAC,gBAAgB,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CACvG,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC;IAAA,CACb;CACD","sourcesContent":["import { isAbsolute, relative, resolve, sep } from \"node:path\";\nimport { type Component, truncateToWidth } from \"@earendil-works/pi-tui\";\nimport type { AgentSession } from \"../../../core/agent-session.ts\";\nimport type { ReadonlyFooterDataProvider } from \"../../../core/footer-data-provider.ts\";\nimport { theme } from \"../theme/theme.ts\";\nimport { keyText } from \"./keybinding-hints.ts\";\n\n/**\n * Sanitize text for display in a single-line status.\n * Removes newlines, tabs, carriage returns, and other control characters.\n */\nfunction sanitizeStatusText(text: string): string {\n\t// Replace newlines, tabs, carriage returns with space, then collapse multiple spaces\n\treturn text\n\t\t.replace(/[\\r\\n\\t]/g, \" \")\n\t\t.replace(/ +/g, \" \")\n\t\t.trim();\n}\n\n/**\n * Format token counts for compact footer display.\n */\nexport function formatTokens(count: number): string {\n\tif (count < 1000) return count.toString();\n\tif (count < 10000) return `${(count / 1000).toFixed(1)}k`;\n\tif (count < 1000000) return `${Math.round(count / 1000)}k`;\n\tif (count < 10000000) return `${(count / 1000000).toFixed(1)}M`;\n\treturn `${Math.round(count / 1000000)}M`;\n}\n\nexport function formatCwdForFooter(cwd: string, home: string | undefined): string {\n\tif (!home) return cwd;\n\n\tconst resolvedCwd = resolve(cwd);\n\tconst resolvedHome = resolve(home);\n\tconst relativeToHome = relative(resolvedHome, resolvedCwd);\n\tconst isInsideHome =\n\t\trelativeToHome === \"\" ||\n\t\t(relativeToHome !== \"..\" && !relativeToHome.startsWith(`..${sep}`) && !isAbsolute(relativeToHome));\n\n\tif (!isInsideHome) return cwd;\n\treturn relativeToHome === \"\" ? \"~\" : `~${sep}${relativeToHome}`;\n}\n\n/**\n * Footer component that shows cwd, extension statuses, and command hints.\n * Session metrics live in the fullscreen side rail instead of being duplicated here.\n */\nexport class FooterComponent implements Component {\n\tprivate session: AgentSession;\n\tprivate footerData: ReadonlyFooterDataProvider;\n\n\tconstructor(session: AgentSession, footerData: ReadonlyFooterDataProvider) {\n\t\tthis.session = session;\n\t\tthis.footerData = footerData;\n\t}\n\n\tsetSession(session: AgentSession): void {\n\t\tthis.session = session;\n\t}\n\n\t/**\n\t * No-op: git branch caching now handled by provider.\n\t * Kept for compatibility with existing call sites in interactive-mode.\n\t */\n\tinvalidate(): void {\n\t\t// No-op: git branch is cached/invalidated by provider\n\t}\n\n\t/**\n\t * Clean up resources.\n\t * Git watcher cleanup now handled by provider.\n\t */\n\tdispose(): void {\n\t\t// Git watcher cleanup handled by provider\n\t}\n\n\trender(width: number): string[] {\n\t\t// Replace home directory with ~\n\t\tlet pwd = formatCwdForFooter(this.session.sessionManager.getCwd(), process.env.HOME || process.env.USERPROFILE);\n\n\t\t// Add git branch if available\n\t\tconst branch = this.footerData.getGitBranch();\n\t\tif (branch) {\n\t\t\tpwd = `${pwd} (${branch})`;\n\t\t}\n\n\t\t// Add session name if set\n\t\tconst sessionName = this.session.sessionManager.getSessionName();\n\t\tif (sessionName) {\n\t\t\tpwd = `${pwd} • ${sessionName}`;\n\t\t}\n\n\t\tconst pwdLine = truncateToWidth(theme.fg(\"dim\", pwd), width, theme.fg(\"dim\", \"...\"));\n\t\tconst lines = [pwdLine];\n\n\t\t// Add extension statuses on a single line, sorted by key alphabetically\n\t\tconst extensionStatuses = this.footerData.getExtensionStatuses();\n\t\tconst quitConfirmation = extensionStatuses.get(\"quit-confirmation\");\n\t\tconst regularStatuses = Array.from(extensionStatuses.entries()).filter(([key]) => key !== \"quit-confirmation\");\n\t\tif (regularStatuses.length > 0) {\n\t\t\tconst sortedStatuses = regularStatuses\n\t\t\t\t.sort(([a], [b]) => a.localeCompare(b))\n\t\t\t\t.map(([, text]) => sanitizeStatusText(text));\n\t\t\tconst statusLine = sortedStatuses.join(\" \");\n\t\t\t// Truncate to terminal width with dim ellipsis for consistency with footer style\n\t\t\tlines.push(truncateToWidth(statusLine, width, theme.fg(\"dim\", \"...\")));\n\t\t}\n\n\t\t// Crush-style key hints: bold keys, muted labels, • separators.\n\t\tconst hint = (key: string, label: string) => `${theme.bold(key)} ${theme.fg(\"muted\", label)}`;\n\t\tconst hintsLine = [\n\t\t\thint(\"/\", \"commands\"),\n\t\t\thint(\"!\", \"bash\"),\n\t\t\thint(\"ctrl+l\", \"models\"),\n\t\t\thint(\"ctrl+k\", \"palette\"),\n\t\t\thint(\"ctrl+o\", \"expand\"),\n\t\t\thint(keyText(\"app.clear\"), \"quit\"),\n\t\t].join(theme.fg(\"dim\", \" • \"));\n\t\tlines.push(truncateToWidth(hintsLine, width, theme.fg(\"dim\", \"...\")));\n\n\t\tif (quitConfirmation) {\n\t\t\tlines.push(\n\t\t\t\ttruncateToWidth(theme.fg(\"muted\", sanitizeStatusText(quitConfirmation)), width, theme.fg(\"dim\", \"...\")),\n\t\t\t);\n\t\t}\n\n\t\treturn lines;\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph-rail.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/graph-rail.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAOxD;;;;GAIG;AAEH,eAAO,MAAM,UAAU,KAAK,CAAC;AAC7B,eAAO,MAAM,kBAAkB,MAAM,CAAC;AA2BtC,MAAM,MAAM,aAAa,GA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AC,EAAE,iBAAiB,GAAG,MAAM,GAAG,SAAS,CAiFxG","sourcesContent":["import type { Component } from \"@earendil-works/pi-tui\";\nimport { visibleWidth } from \"@earendil-works/pi-tui\";\nimport { type GraphRailState, graphRailStore } from \"../../../core/graph-rail-store.ts\";\nimport { diagonalFill, gradientText } from \"../theme/brand.ts\";\nimport { theme } from \"../theme/theme.ts\";\nimport { NEXUS_SMALL } from \"./nexus-logo.ts\";\n\n/**\n * GitNexus side rail (fullscreen UI mode, terminals >= MIN_TERMINAL_WIDTH).\n * Renders repo status, the latest blast radius, latest flows, and session\n * changes as stacked cards. Pure view over graphRailStore.\n */\n\nexport const RAIL_WIDTH = 36;\nexport const MIN_TERMINAL_WIDTH = 110;\n\nfunction clipVisible(line: string, width: number): string {\n\tif (visibleWidth(line) <= width) return line;\n\tlet out = \"\";\n\tlet visible = 0;\n\tfor (let i = 0; i < line.length; i++) {\n\t\tif (line[i] === \"\\x1b\") {\n\t\t\tconst match = line.slice(i).match(/^\\x1b\\[[0-9;]*m/);\n\t\t\tif (match) {\n\t\t\t\tout += match[0];\n\t\t\t\ti += match[0].length - 1;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\tif (visible >= width) break;\n\t\tout += line[i];\n\t\tvisible++;\n\t}\n\treturn `${out}\\x1b[0m`;\n}\n\nfunction basename(filePath: string | undefined): string {\n\tif (!filePath) return \"\";\n\treturn filePath.split(\"/\").pop() ?? filePath;\n}\n\nexport type GraphRailCard = \"status\" | \"repos\" | \"impact\" | \"flows\" | \"changes\" | \"skills\";\n\n/** Dim low-confidence graph edges below this threshold. */\nconst CONFIDENCE_DIM_THRESHOLD = 0.7;\n\nfunction formatSymbolCount(symbols: string): string {\n\tconst n = Number(symbols.replace(/,/g, \"\"));\n\tif (Number.isNaN(n)) return symbols;\n\tif (n >= 1_000_000) return `${(n / 1_000_000).toFixed(1)}M`;\n\tif (n >= 1_000) return `${Math.round(n / 1_000)}k`;\n\treturn String(n);\n}\n\nexport interface GraphRailSessionStatus {\n\ttitle?: string;\n\tcwd?: string;\n\tmodel?: string;\n\tprovider?: string;\n\treasoning?: string;\n\tcontext?: string;\n\tcost?: string;\n}\n\nexport interface GraphRailHostInfo {\n\tskills: string[];\n\tversion: string;\n\t/** Live session status for the crush-style sidebar header. */\n\tgetSessionStatus?: () => GraphRailSessionStatus;\n}\n\nexport class GraphRailComponent implements Component {\n\t/** Set by the host: invoked when a card is clicked (fullscreen mouse routing). */\n\tonCardClick: ((card: GraphRailCard) => void) | undefined;\n\n\tprivate hostInfo: GraphRailHostInfo | undefined;\n\n\tsetHostInfo(info: GraphRailHostInfo): void {\n\t\tthis.hostInfo = info;\n\t}\n\n\tgetHostInfo(): GraphRailHostInfo | undefined {\n\t\treturn this.hostInfo;\n\t}\n\n\tprivate cardRanges: Array<{ start: number; end: number; card: GraphRailCard }> = [];\n\n\tinvalidate(): void {\n\t\t// Stateless view over graphRailStore — nothing cached.\n\t}\n\n\thandleClick(_x: number, y: number): boolean {\n\t\tconst hit = this.cardRanges.find((range) => y >= range.start && y < range.end);\n\t\tif (!hit || !this.onCardClick) return false;\n\t\tthis.onCardClick(hit.card);\n\t\treturn true;\n\t}\n\n\trender(width: number): string[] {\n\t\tif (width < 20) return [];\n\t\tconst inner = Math.min(width, RAIL_WIDTH) - 2;\n\t\tconst s = graphRailStore.getState();\n\t\tconst lines: string[] = [];\n\t\tthis.cardRanges = [];\n\t\tlet cardStart = 0;\n\t\tconst beginCard = () => {\n\t\t\tcardStart = lines.length;\n\t\t};\n\t\tconst commitCard = (card: GraphRailCard) => {\n\t\t\tthis.cardRanges.push({ start: cardStart, end: lines.length, card });\n\t\t};\n\t\t// Crush-style section header: `Title ────────` (no card frames).\n\t\tconst rule = (title: string) =>\n\t\t\tlines.push(\n\t\t\t\t`${theme.fg(\"muted\", title)} ${theme.fg(\"dim\", \"─\".repeat(Math.max(0, inner - [...title].length - 1)))}`,\n\t\t\t);\n\t\tconst row = (text: string) => lines.push(clipVisible(text, inner));\n\t\tconst end = () => lines.push(\"\");\n\n\t\t// Logo band (small crush-style: hatch, wordmark, version).\n\t\tconst hatch = diagonalFill(inner + 2);\n\t\tlines.push(hatch);\n\t\tfor (const logoLine of NEXUS_SMALL) lines.push(` ${gradientText(logoLine)}`);\n\t\tif (this.hostInfo?.version) {\n\t\t\tlines.push(` ${theme.fg(\"muted\", `v${this.hostInfo.version}`)}`);\n\t\t}\n\t\tlines.push(hatch);\n\t\tlines.push(\"\");\n\n\t\t// Session header: title, cwd, model block (crush sidebar order).\n\t\tconst status = this.hostInfo?.getSessionStatus?.();\n\t\tif (status) {\n\t\t\tif (status.title) {\n\t\t\t\trow(theme.bold(status.title));\n\t\t\t\tlines.push(\"\");\n\t\t\t}\n\t\t\tif (status.cwd) {\n\t\t\t\trow(theme.fg(\"muted\", status.cwd));\n\t\t\t\tlines.push(\"\");\n\t\t\t}\n\t\t\tif (status.model) {\n\t\t\t\trow(\n\t\t\t\t\t`${theme.fg(\"muted\", \"◇\")} ${theme.bold(status.model)}${status.provider ? theme.fg(\"muted\", ` via ${status.provider}`) : \"\"}`,\n\t\t\t\t);\n\t\t\t\tif (status.reasoning) row(` ${theme.fg(\"muted\", `Reasoning ${status.reasoning}`)}`);\n\t\t\t\tif (status.context || status.cost) {\n\t\t\t\t\trow(` ${theme.fg(\"muted\", [status.context, status.cost].filter(Boolean).join(\" \"))}`);\n\t\t\t\t}\n\t\t\t\tlines.push(\"\");\n\t\t\t}\n\t\t}\n\n\t\tbeginCard();\n\t\tthis.renderChanges(s, rule, row, end);\n\t\tcommitCard(\"changes\");\n\t\tbeginCard();\n\t\tthis.renderStatus(s, rule, row, end);\n\t\tcommitCard(\"status\");\n\t\tbeginCard();\n\t\tthis.renderRepos(s, rule, row, end);\n\t\tcommitCard(\"repos\");\n\t\tbeginCard();\n\t\tthis.renderImpact(s, rule, row, end);\n\t\tcommitCard(\"impact\");\n\t\tbeginCard();\n\t\tthis.renderQuery(s, rule, row, end);\n\t\tcommitCard(\"flows\");\n\t\tbeginCard();\n\t\tthis.renderSkills(rule, row, end);\n\t\tcommitCard(\"skills\");\n\t\treturn lines;\n\t}\n\n\tprivate renderRepos(\n\t\ts: Readonly<GraphRailState>,\n\t\trule: (t: string) => void,\n\t\trow: (t: string) => void,\n\t\tend: () => void,\n\t): void {\n\t\tif (s.repos.length === 0) return;\n\t\trule(\"Repos\");\n\t\tconst activeName = s.repo?.name;\n\t\tfor (const repo of s.repos.slice(0, 5)) {\n\t\t\tconst short = repo.name.split(\"/\").pop() ?? repo.name;\n\t\t\tconst count = theme.fg(\"muted\", formatSymbolCount(repo.symbols));\n\t\t\tif (repo.name === activeName) {\n\t\t\t\trow(`${theme.fg(\"accent\", \"●\")} ${theme.fg(\"accent\", short)} ${count}`);\n\t\t\t} else {\n\t\t\t\trow(`${theme.fg(\"muted\", \"○\")} ${theme.fg(\"muted\", short)} ${count}`);\n\t\t\t}\n\t\t}\n\t\tif (s.repos.length > 5) row(theme.fg(\"muted\", ` … +${s.repos.length - 5} more`));\n\t\tend();\n\t}\n\n\tprivate renderStatus(\n\t\ts: Readonly<GraphRailState>,\n\t\trule: (t: string) => void,\n\t\trow: (t: string) => void,\n\t\tend: () => void,\n\t): void {\n\t\trule(\"GitNexus\");\n\t\tif (!s.repo) {\n\t\t\trow(theme.fg(\"muted\", \"not connected\"));\n\t\t\tend();\n\t\t\treturn;\n\t\t}\n\t\tif (s.currentIndexed) {\n\t\t\trow(theme.bold(s.repo.name.split(\"/\").pop() ?? s.repo.name));\n\t\t\trow(theme.fg(\"muted\", `${s.repo.symbols} symbols · ${s.repo.repoCount} repos`));\n\t\t\trow(theme.fg(\"muted\", `indexed ${s.repo.indexedAt.split(\" GMT\")[0] ?? s.repo.indexedAt}`));\n\t\t} else {\n\t\t\trow(theme.fg(\"warning\", \"repo not indexed\"));\n\t\t\trow(theme.fg(\"muted\", `${s.repo.repoCount} repos queryable`));\n\t\t}\n\t\trow(theme.fg(\"muted\", `graph calls ${s.graphCalls} · impact ${s.impactChecks}`));\n\t\tend();\n\t}\n\n\tprivate renderImpact(\n\t\ts: Readonly<GraphRailState>,\n\t\trule: (t: string) => void,\n\t\trow: (t: string) => void,\n\t\tend: () => void,\n\t): void {\n\t\tconst impact = s.impact;\n\t\tif (!impact) return;\n\t\trule(\"Blast Radius\");\n\t\tconst risk = impact.risk.toUpperCase();\n\t\tconst riskColor = risk === \"HIGH\" || risk === \"CRITICAL\" ? \"error\" : risk === \"MEDIUM\" ? \"warning\" : \"success\";\n\t\trow(`${theme.fg(\"accent\", \"◉\")} ${theme.bold(impact.target)}`);\n\t\trow(theme.fg(riskColor, `risk: ${risk}`));\n\t\tconst depths = Object.keys(impact.byDepth)\n\t\t\t.map(Number)\n\t\t\t.filter((d) => !Number.isNaN(d))\n\t\t\t.sort((a, b) => a - b);\n\t\tfor (const depth of depths.slice(0, 3)) {\n\t\t\tconst nodes = impact.byDepth[String(depth)] ?? [];\n\t\t\tif (nodes.length === 0) continue;\n\t\t\tconst color = depth === 1 ? \"error\" : depth === 2 ? \"warning\" : \"muted\";\n\t\t\tconst label = depth === 1 ? \"breaks\" : depth === 2 ? \"test\" : \"transitive\";\n\t\t\trow(theme.fg(color, `d${depth} ${label} (${nodes.length})`));\n\t\t\tfor (const node of nodes.slice(0, 3)) {\n\t\t\t\tconst lowConfidence = node.confidence !== undefined && node.confidence < CONFIDENCE_DIM_THRESHOLD;\n\t\t\t\tconst name = lowConfidence ? theme.fg(\"dim\", `${node.name}?`) : node.name;\n\t\t\t\trow(` ${theme.fg(lowConfidence ? \"dim\" : color, depth === 1 ? \"●\" : \"○\")} ${name}`);\n\t\t\t}\n\t\t\tif (nodes.length > 3) row(theme.fg(\"muted\", ` … +${nodes.length - 3}`));\n\t\t}\n\t\tif (impact.processes.length > 0) row(theme.fg(\"muted\", `flows: ${impact.processes.slice(0, 2).join(\", \")}`));\n\t\tif (impact.modules.length > 0) {\n\t\t\tconst maxHits = Math.max(...impact.modules.map((m) => m.hits), 1);\n\t\t\tfor (const module of impact.modules.slice(0, 3)) {\n\t\t\t\tconst filled = Math.max(1, Math.round((module.hits / maxHits) * 5));\n\t\t\t\tconst bar =\n\t\t\t\t\ttheme.fg(module.direct ? \"accent\" : \"muted\", \"▮\".repeat(filled)) +\n\t\t\t\t\ttheme.fg(\"dim\", \"▯\".repeat(5 - filled));\n\t\t\t\trow(`${bar} ${theme.fg(\"muted\", module.name)} ${theme.fg(\"dim\", String(module.hits))}`);\n\t\t\t}\n\t\t}\n\t\tend();\n\t}\n\n\tprivate renderQuery(\n\t\ts: Readonly<GraphRailState>,\n\t\trule: (t: string) => void,\n\t\trow: (t: string) => void,\n\t\tend: () => void,\n\t): void {\n\t\tconst query = s.query;\n\t\tif (!query) return;\n\t\trule(\"Flows\");\n\t\trow(theme.fg(\"muted\", clipQuery(query.query)));\n\t\tquery.flows.slice(0, 3).forEach((flow, i) => {\n\t\t\tconst marker = i === 0 ? theme.fg(\"accent\", \"◉\") : theme.fg(\"muted\", \"○\");\n\t\t\tconst steps = flow.stepCount ? theme.fg(\"muted\", ` ·${flow.stepCount}`) : \"\";\n\t\t\trow(`${marker} ${flow.summary}${steps}`);\n\t\t});\n\t\tend();\n\t}\n\n\tprivate renderSkills(rule: (t: string) => void, row: (t: string) => void, end: () => void): void {\n\t\tconst skills = this.hostInfo?.skills ?? [];\n\t\tif (skills.length === 0) return;\n\t\trule(\"Skills\");\n\t\tfor (const skill of skills.slice(0, 8)) {\n\t\t\trow(`${theme.fg(\"success\", \"\\u25cf\")} ${theme.fg(\"muted\", skill)}`);\n\t\t}\n\t\tif (skills.length > 8) row(theme.fg(\"muted\", ` \\u2026 +${skills.length - 8} more`));\n\t\tend();\n\t}\n\n\tprivate renderChanges(\n\t\ts: Readonly<GraphRailState>,\n\t\trule: (t: string) => void,\n\t\trow: (t: string) => void,\n\t\tend: () => void,\n\t): void {\n\t\trule(\"Modified Files\");\n\t\tif (s.changes.length === 0) {\n\t\t\trow(theme.fg(\"muted\", \"None\"));\n\t\t\tend();\n\t\t\treturn;\n\t\t}\n\t\tfor (const change of s.changes.slice(-5)) {\n\t\t\trow(\n\t\t\t\t`${basename(change.path)} ${theme.fg(\"success\", `+${change.added}`)} ${theme.fg(\"error\", `-${change.removed}`)}`,\n\t\t\t);\n\t\t}\n\t\tend();\n\t}\n}\n\nfunction clipQuery(query: string): string {\n\treturn query.length > 30 ? `${query.slice(0, 29)}…` : `“${query}”`;\n}\n\n/** Full-width expansion of a rail card, appended to the transcript on click. */\nexport function renderExpandedCard(card: GraphRailCard, hostInfo?: GraphRailHostInfo): string | undefined {\n\tconst s = graphRailStore.getState();\n\tconst header = (title: string) => theme.bold(theme.fg(\"accent\", `── GitNexus · ${title} ──`));\n\tif (card === \"repos\" && s.repos.length > 0) {\n\t\tconst lines: string[] = [header(\"indexed repos\")];\n\t\tfor (const repo of s.repos) {\n\t\t\tconst marker = repo.name === s.repo?.name ? theme.fg(\"accent\", \"●\") : theme.fg(\"muted\", \"○\");\n\t\t\tlines.push(`${marker} ${repo.name} ${theme.fg(\"muted\", `${repo.symbols} symbols`)}`);\n\t\t}\n\t\treturn lines.join(\"\\n\");\n\t}\n\tif (card === \"skills\" && hostInfo && hostInfo.skills.length > 0) {\n\t\tconst lines: string[] = [header(\"skills\")];\n\t\tfor (const skill of hostInfo.skills) {\n\t\t\tlines.push(`${theme.fg(\"success\", \"●\")} ${skill}`);\n\t\t}\n\t\treturn lines.join(\"\\n\");\n\t}\n\tif (card === \"impact\" && s.impact) {\n\t\tconst lines: string[] = [header(\"blast radius\")];\n\t\tconst risk = s.impact.risk.toUpperCase();\n\t\tconst riskColor = risk === \"HIGH\" || risk === \"CRITICAL\" ? \"error\" : risk === \"MEDIUM\" ? \"warning\" : \"success\";\n\t\tlines.push(\n\t\t\t`${theme.fg(\"accent\", \"◉\")} ${theme.bold(s.impact.target)} ${theme.fg(\"muted\", s.impact.filePath ?? \"\")} ${theme.bold(theme.fg(riskColor, `RISK: ${risk}`))}`,\n\t\t);\n\t\tconst depths = Object.keys(s.impact.byDepth)\n\t\t\t.map(Number)\n\t\t\t.filter((d) => !Number.isNaN(d))\n\t\t\t.sort((a, b) => a - b);\n\t\tfor (const depth of depths) {\n\t\t\tconst nodes = s.impact.byDepth[String(depth)] ?? [];\n\t\t\tif (nodes.length === 0) continue;\n\t\t\tconst color = depth === 1 ? \"error\" : depth === 2 ? \"warning\" : \"muted\";\n\t\t\tconst label = depth === 1 ? \"WILL BREAK\" : depth === 2 ? \"should test\" : \"transitive\";\n\t\t\tlines.push(theme.fg(color, `d=${depth} ${label} (${nodes.length})`));\n\t\t\tfor (const node of nodes) {\n\t\t\t\tconst rel = node.relationType ? theme.fg(\"muted\", ` (${node.relationType})`) : \"\";\n\t\t\t\tlines.push(\n\t\t\t\t\t` ${theme.fg(color, depth === 1 ? \"●\" : \"○\")} ${node.name} ${theme.fg(\"muted\", node.filePath ?? \"\")}${rel}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tif (s.impact.processes.length > 0)\n\t\t\tlines.push(theme.fg(\"muted\", `flows affected: ${s.impact.processes.join(\", \")}`));\n\t\tif (s.impact.modules.length > 0)\n\t\t\tlines.push(\n\t\t\t\ttheme.fg(\n\t\t\t\t\t\"muted\",\n\t\t\t\t\t`modules: ${s.impact.modules.map((m) => `${m.name} (${m.hits}${m.direct ? \", direct\" : \"\"})`).join(\", \")}`,\n\t\t\t\t),\n\t\t\t);\n\t\treturn lines.join(\"\\n\");\n\t}\n\tif (card === \"flows\" && s.query) {\n\t\tconst lines: string[] = [header(\"flows\"), theme.fg(\"muted\", `query: “${s.query.query}”`)];\n\t\ts.query.flows.forEach((flow, i) => {\n\t\t\tconst marker = i === 0 ? theme.fg(\"accent\", \"◉\") : theme.fg(\"muted\", \"○\");\n\t\t\tlines.push(\n\t\t\t\t`${marker} ${flow.summary}${flow.stepCount ? theme.fg(\"muted\", ` · ${flow.stepCount} steps`) : \"\"}`,\n\t\t\t);\n\t\t});\n\t\treturn lines.join(\"\\n\");\n\t}\n\tif (card === \"changes\" && s.changes.length > 0) {\n\t\tconst lines: string[] = [header(\"session changes\")];\n\t\tfor (const change of s.changes) {\n\t\t\tlines.push(\n\t\t\t\t`${theme.fg(\"success\", `+${change.added}`)} ${theme.fg(\"error\", `-${change.removed}`)} ${change.path}`,\n\t\t\t);\n\t\t}\n\t\treturn lines.join(\"\\n\");\n\t}\n\tif (card === \"status\" && s.repo) {\n\t\treturn [\n\t\t\theader(\"status\"),\n\t\t\t`repo: ${s.repo.name || \"(current dir not indexed)\"} · ${s.repo.symbols} symbols`,\n\t\t\t`indexed: ${s.repo.indexedAt || \"n/a\"} · ${s.repo.repoCount} repos on hub`,\n\t\t\t`graph calls: ${s.graphCalls} · impact checks: ${s.impactChecks}`,\n\t\t].join(\"\\n\");\n\t}\n\treturn undefined;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"graph-rail.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/graph-rail.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAOxD;;;;GAIG;AAEH,eAAO,MAAM,UAAU,KAAK,CAAC;AAC7B,eAAO,MAAM,kBAAkB,MAAM,CAAC;AA2BtC,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,GAAG,SAAS,GAAG,QAAQ,CAAC;AAa3F,MAAM,WAAW,sBAAsB;IACtC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,iBAAiB;IACjC,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,8DAA8D;IAC9D,gBAAgB,CAAC,EAAE,MAAM,sBAAsB,CAAC;CAChD;AAED,qBAAa,kBAAmB,YAAW,SAAS;IACnD,kFAAkF;IAClF,WAAW,EAAE,CAAC,CAAC,IAAI,EAAE,aAAa,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IAEzD,OAAO,CAAC,QAAQ,CAAgC;IAEhD,WAAW,CAAC,IAAI,EAAE,iBAAiB,GAAG,IAAI,CAEzC;IAED,WAAW,IAAI,iBAAiB,GAAG,SAAS,CAE3C;IAED,OAAO,CAAC,UAAU,CAAkE;IAEpF,UAAU,IAAI,IAAI,CAEjB;IAED,WAAW,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAK1C;IAED,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAyE9B;IAED,OAAO,CAAC,WAAW;IAsBnB,OAAO,CAAC,YAAY;IA2CpB,OAAO,CAAC,YAAY;IA4CpB,OAAO,CAAC,WAAW;IAkBnB,OAAO,CAAC,YAAY;IAWpB,OAAO,CAAC,aAAa;CAmBrB;AAMD,gFAAgF;AAChF,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,aAAa,EAAE,QAAQ,CAAC,EAAE,iBAAiB,GAAG,MAAM,GAAG,SAAS,CAiFxG","sourcesContent":["import type { Component } from \"@earendil-works/pi-tui\";\nimport { visibleWidth } from \"@earendil-works/pi-tui\";\nimport { formatCompactIndexPhase, type GraphRailState, graphRailStore } from \"../../../core/graph-rail-store.ts\";\nimport { diagonalFill, gradientText } from \"../theme/brand.ts\";\nimport { theme } from \"../theme/theme.ts\";\nimport { NEXUS_SMALL } from \"./nexus-logo.ts\";\n\n/**\n * GitNexus side rail (fullscreen UI mode, terminals >= MIN_TERMINAL_WIDTH).\n * Renders repo status, the latest blast radius, latest flows, and session\n * changes as stacked cards. Pure view over graphRailStore.\n */\n\nexport const RAIL_WIDTH = 36;\nexport const MIN_TERMINAL_WIDTH = 110;\n\nfunction clipVisible(line: string, width: number): string {\n\tif (visibleWidth(line) <= width) return line;\n\tlet out = \"\";\n\tlet visible = 0;\n\tfor (let i = 0; i < line.length; i++) {\n\t\tif (line[i] === \"\\x1b\") {\n\t\t\tconst match = line.slice(i).match(/^\\x1b\\[[0-9;]*m/);\n\t\t\tif (match) {\n\t\t\t\tout += match[0];\n\t\t\t\ti += match[0].length - 1;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\tif (visible >= width) break;\n\t\tout += line[i];\n\t\tvisible++;\n\t}\n\treturn `${out}\\x1b[0m`;\n}\n\nfunction basename(filePath: string | undefined): string {\n\tif (!filePath) return \"\";\n\treturn filePath.split(\"/\").pop() ?? filePath;\n}\n\nexport type GraphRailCard = \"status\" | \"repos\" | \"impact\" | \"flows\" | \"changes\" | \"skills\";\n\n/** Dim low-confidence graph edges below this threshold. */\nconst CONFIDENCE_DIM_THRESHOLD = 0.7;\n\nfunction formatSymbolCount(symbols: string): string {\n\tconst n = Number(symbols.replace(/,/g, \"\"));\n\tif (Number.isNaN(n)) return symbols;\n\tif (n >= 1_000_000) return `${(n / 1_000_000).toFixed(1)}M`;\n\tif (n >= 1_000) return `${Math.round(n / 1_000)}k`;\n\treturn String(n);\n}\n\nexport interface GraphRailSessionStatus {\n\ttitle?: string;\n\tcwd?: string;\n\tmodel?: string;\n\tprovider?: string;\n\treasoning?: string;\n\tcontext?: string;\n\tcost?: string;\n}\n\nexport interface GraphRailHostInfo {\n\tskills: string[];\n\tversion: string;\n\t/** Live session status for the crush-style sidebar header. */\n\tgetSessionStatus?: () => GraphRailSessionStatus;\n}\n\nexport class GraphRailComponent implements Component {\n\t/** Set by the host: invoked when a card is clicked (fullscreen mouse routing). */\n\tonCardClick: ((card: GraphRailCard) => void) | undefined;\n\n\tprivate hostInfo: GraphRailHostInfo | undefined;\n\n\tsetHostInfo(info: GraphRailHostInfo): void {\n\t\tthis.hostInfo = info;\n\t}\n\n\tgetHostInfo(): GraphRailHostInfo | undefined {\n\t\treturn this.hostInfo;\n\t}\n\n\tprivate cardRanges: Array<{ start: number; end: number; card: GraphRailCard }> = [];\n\n\tinvalidate(): void {\n\t\t// Stateless view over graphRailStore — nothing cached.\n\t}\n\n\thandleClick(_x: number, y: number): boolean {\n\t\tconst hit = this.cardRanges.find((range) => y >= range.start && y < range.end);\n\t\tif (!hit || !this.onCardClick) return false;\n\t\tthis.onCardClick(hit.card);\n\t\treturn true;\n\t}\n\n\trender(width: number): string[] {\n\t\tif (width < 20) return [];\n\t\tconst inner = Math.min(width, RAIL_WIDTH) - 2;\n\t\tconst s = graphRailStore.getState();\n\t\tconst lines: string[] = [];\n\t\tthis.cardRanges = [];\n\t\tlet cardStart = 0;\n\t\tconst beginCard = () => {\n\t\t\tcardStart = lines.length;\n\t\t};\n\t\tconst commitCard = (card: GraphRailCard) => {\n\t\t\tthis.cardRanges.push({ start: cardStart, end: lines.length, card });\n\t\t};\n\t\t// Crush-style section header: `Title ────────` (no card frames).\n\t\tconst rule = (title: string) =>\n\t\t\tlines.push(\n\t\t\t\t`${theme.fg(\"muted\", title)} ${theme.fg(\"dim\", \"─\".repeat(Math.max(0, inner - [...title].length - 1)))}`,\n\t\t\t);\n\t\tconst row = (text: string) => lines.push(clipVisible(text, inner));\n\t\tconst end = () => lines.push(\"\");\n\n\t\t// Logo band (small crush-style: hatch, wordmark, version).\n\t\tconst hatch = diagonalFill(inner + 2);\n\t\tlines.push(hatch);\n\t\tfor (const logoLine of NEXUS_SMALL) lines.push(` ${gradientText(logoLine)}`);\n\t\tif (this.hostInfo?.version) {\n\t\t\tlines.push(` ${theme.fg(\"muted\", `v${this.hostInfo.version}`)}`);\n\t\t}\n\t\tlines.push(hatch);\n\t\tlines.push(\"\");\n\n\t\t// Session header: title, cwd, model block (crush sidebar order).\n\t\tconst status = this.hostInfo?.getSessionStatus?.();\n\t\tif (status) {\n\t\t\tif (status.title) {\n\t\t\t\trow(theme.bold(status.title));\n\t\t\t\tlines.push(\"\");\n\t\t\t}\n\t\t\tif (status.cwd) {\n\t\t\t\trow(theme.fg(\"muted\", status.cwd));\n\t\t\t\tlines.push(\"\");\n\t\t\t}\n\t\t\tif (status.model) {\n\t\t\t\trow(\n\t\t\t\t\t`${theme.fg(\"muted\", \"◇\")} ${theme.bold(status.model)}${status.provider ? theme.fg(\"muted\", ` via ${status.provider}`) : \"\"}`,\n\t\t\t\t);\n\t\t\t\tif (status.reasoning) row(` ${theme.fg(\"muted\", `Reasoning ${status.reasoning}`)}`);\n\t\t\t\tif (status.context || status.cost) {\n\t\t\t\t\trow(` ${theme.fg(\"muted\", [status.context, status.cost].filter(Boolean).join(\" \"))}`);\n\t\t\t\t}\n\t\t\t\tlines.push(\"\");\n\t\t\t}\n\t\t}\n\n\t\tbeginCard();\n\t\tthis.renderChanges(s, rule, row, end);\n\t\tcommitCard(\"changes\");\n\t\tbeginCard();\n\t\tthis.renderStatus(s, inner, rule, row, end);\n\t\tcommitCard(\"status\");\n\t\tbeginCard();\n\t\tthis.renderRepos(s, rule, row, end);\n\t\tcommitCard(\"repos\");\n\t\tbeginCard();\n\t\tthis.renderImpact(s, rule, row, end);\n\t\tcommitCard(\"impact\");\n\t\tbeginCard();\n\t\tthis.renderQuery(s, rule, row, end);\n\t\tcommitCard(\"flows\");\n\t\tbeginCard();\n\t\tthis.renderSkills(rule, row, end);\n\t\tcommitCard(\"skills\");\n\t\treturn lines;\n\t}\n\n\tprivate renderRepos(\n\t\ts: Readonly<GraphRailState>,\n\t\trule: (t: string) => void,\n\t\trow: (t: string) => void,\n\t\tend: () => void,\n\t): void {\n\t\tif (s.repos.length === 0) return;\n\t\trule(\"Repos\");\n\t\tconst activeName = s.repo?.name;\n\t\tfor (const repo of s.repos.slice(0, 5)) {\n\t\t\tconst short = repo.name.split(\"/\").pop() ?? repo.name;\n\t\t\tconst count = theme.fg(\"muted\", formatSymbolCount(repo.symbols));\n\t\t\tif (repo.name === activeName) {\n\t\t\t\trow(`${theme.fg(\"accent\", \"●\")} ${theme.fg(\"accent\", short)} ${count}`);\n\t\t\t} else {\n\t\t\t\trow(`${theme.fg(\"muted\", \"○\")} ${theme.fg(\"muted\", short)} ${count}`);\n\t\t\t}\n\t\t}\n\t\tif (s.repos.length > 5) row(theme.fg(\"muted\", ` … +${s.repos.length - 5} more`));\n\t\tend();\n\t}\n\n\tprivate renderStatus(\n\t\ts: Readonly<GraphRailState>,\n\t\twidth: number,\n\t\trule: (t: string) => void,\n\t\trow: (t: string) => void,\n\t\tend: () => void,\n\t): void {\n\t\trule(\"GitNexus\");\n\t\tif (s.indexProgress) {\n\t\t\tconst progress = s.indexProgress;\n\t\t\tconst phase = formatCompactIndexPhase(progress.phase);\n\t\t\trow(theme.bold(progress.fullName.split(\"/\").pop() ?? progress.fullName));\n\t\t\tconst percent =\n\t\t\t\tprogress.percent === undefined ? undefined : Math.max(0, Math.min(100, Math.round(progress.percent)));\n\t\t\trow(\n\t\t\t\tpercent === undefined\n\t\t\t\t\t? theme.fg(\"muted\", phase)\n\t\t\t\t\t: `${theme.fg(\"muted\", phase)} ${theme.fg(\"accent\", `${percent}%`)}`,\n\t\t\t);\n\t\t\tif (percent !== undefined) {\n\t\t\t\tconst filled = Math.round((percent / 100) * width);\n\t\t\t\trow(theme.fg(\"accent\", \"━\".repeat(filled)) + theme.fg(\"dim\", \"─\".repeat(width - filled)));\n\t\t\t}\n\t\t\tend();\n\t\t\treturn;\n\t\t}\n\t\tif (!s.repo) {\n\t\t\trow(theme.fg(\"muted\", \"not connected\"));\n\t\t\tend();\n\t\t\treturn;\n\t\t}\n\t\tif (s.currentIndexed) {\n\t\t\trow(theme.bold(s.repo.name.split(\"/\").pop() ?? s.repo.name));\n\t\t\trow(theme.fg(\"muted\", `${s.repo.symbols} symbols · ${s.repo.repoCount} repos`));\n\t\t\trow(theme.fg(\"muted\", `indexed ${s.repo.indexedAt.split(\" GMT\")[0] ?? s.repo.indexedAt}`));\n\t\t} else {\n\t\t\trow(theme.fg(\"warning\", \"repo not indexed\"));\n\t\t\trow(theme.fg(\"muted\", `${s.repo.repoCount} repos queryable`));\n\t\t}\n\t\trow(theme.fg(\"muted\", `graph calls ${s.graphCalls} · impact ${s.impactChecks}`));\n\t\tend();\n\t}\n\n\tprivate renderImpact(\n\t\ts: Readonly<GraphRailState>,\n\t\trule: (t: string) => void,\n\t\trow: (t: string) => void,\n\t\tend: () => void,\n\t): void {\n\t\tconst impact = s.impact;\n\t\tif (!impact) return;\n\t\trule(\"Blast Radius\");\n\t\tconst risk = impact.risk.toUpperCase();\n\t\tconst riskColor = risk === \"HIGH\" || risk === \"CRITICAL\" ? \"error\" : risk === \"MEDIUM\" ? \"warning\" : \"success\";\n\t\trow(`${theme.fg(\"accent\", \"◉\")} ${theme.bold(impact.target)}`);\n\t\trow(theme.fg(riskColor, `risk: ${risk}`));\n\t\tconst depths = Object.keys(impact.byDepth)\n\t\t\t.map(Number)\n\t\t\t.filter((d) => !Number.isNaN(d))\n\t\t\t.sort((a, b) => a - b);\n\t\tfor (const depth of depths.slice(0, 3)) {\n\t\t\tconst nodes = impact.byDepth[String(depth)] ?? [];\n\t\t\tif (nodes.length === 0) continue;\n\t\t\tconst color = depth === 1 ? \"error\" : depth === 2 ? \"warning\" : \"muted\";\n\t\t\tconst label = depth === 1 ? \"breaks\" : depth === 2 ? \"test\" : \"transitive\";\n\t\t\trow(theme.fg(color, `d${depth} ${label} (${nodes.length})`));\n\t\t\tfor (const node of nodes.slice(0, 3)) {\n\t\t\t\tconst lowConfidence = node.confidence !== undefined && node.confidence < CONFIDENCE_DIM_THRESHOLD;\n\t\t\t\tconst name = lowConfidence ? theme.fg(\"dim\", `${node.name}?`) : node.name;\n\t\t\t\trow(` ${theme.fg(lowConfidence ? \"dim\" : color, depth === 1 ? \"●\" : \"○\")} ${name}`);\n\t\t\t}\n\t\t\tif (nodes.length > 3) row(theme.fg(\"muted\", ` … +${nodes.length - 3}`));\n\t\t}\n\t\tif (impact.processes.length > 0) row(theme.fg(\"muted\", `flows: ${impact.processes.slice(0, 2).join(\", \")}`));\n\t\tif (impact.modules.length > 0) {\n\t\t\tconst maxHits = Math.max(...impact.modules.map((m) => m.hits), 1);\n\t\t\tfor (const module of impact.modules.slice(0, 3)) {\n\t\t\t\tconst filled = Math.max(1, Math.round((module.hits / maxHits) * 5));\n\t\t\t\tconst bar =\n\t\t\t\t\ttheme.fg(module.direct ? \"accent\" : \"muted\", \"▮\".repeat(filled)) +\n\t\t\t\t\ttheme.fg(\"dim\", \"▯\".repeat(5 - filled));\n\t\t\t\trow(`${bar} ${theme.fg(\"muted\", module.name)} ${theme.fg(\"dim\", String(module.hits))}`);\n\t\t\t}\n\t\t}\n\t\tend();\n\t}\n\n\tprivate renderQuery(\n\t\ts: Readonly<GraphRailState>,\n\t\trule: (t: string) => void,\n\t\trow: (t: string) => void,\n\t\tend: () => void,\n\t): void {\n\t\tconst query = s.query;\n\t\tif (!query) return;\n\t\trule(\"Flows\");\n\t\trow(theme.fg(\"muted\", clipQuery(query.query)));\n\t\tquery.flows.slice(0, 3).forEach((flow, i) => {\n\t\t\tconst marker = i === 0 ? theme.fg(\"accent\", \"◉\") : theme.fg(\"muted\", \"○\");\n\t\t\tconst steps = flow.stepCount ? theme.fg(\"muted\", ` ·${flow.stepCount}`) : \"\";\n\t\t\trow(`${marker} ${flow.summary}${steps}`);\n\t\t});\n\t\tend();\n\t}\n\n\tprivate renderSkills(rule: (t: string) => void, row: (t: string) => void, end: () => void): void {\n\t\tconst skills = this.hostInfo?.skills ?? [];\n\t\tif (skills.length === 0) return;\n\t\trule(\"Skills\");\n\t\tfor (const skill of skills.slice(0, 8)) {\n\t\t\trow(`${theme.fg(\"success\", \"\\u25cf\")} ${theme.fg(\"muted\", skill)}`);\n\t\t}\n\t\tif (skills.length > 8) row(theme.fg(\"muted\", ` \\u2026 +${skills.length - 8} more`));\n\t\tend();\n\t}\n\n\tprivate renderChanges(\n\t\ts: Readonly<GraphRailState>,\n\t\trule: (t: string) => void,\n\t\trow: (t: string) => void,\n\t\tend: () => void,\n\t): void {\n\t\trule(\"Modified Files\");\n\t\tif (s.changes.length === 0) {\n\t\t\trow(theme.fg(\"muted\", \"None\"));\n\t\t\tend();\n\t\t\treturn;\n\t\t}\n\t\tfor (const change of s.changes.slice(-5)) {\n\t\t\trow(\n\t\t\t\t`${basename(change.path)} ${theme.fg(\"success\", `+${change.added}`)} ${theme.fg(\"error\", `-${change.removed}`)}`,\n\t\t\t);\n\t\t}\n\t\tend();\n\t}\n}\n\nfunction clipQuery(query: string): string {\n\treturn query.length > 30 ? `${query.slice(0, 29)}…` : `“${query}”`;\n}\n\n/** Full-width expansion of a rail card, appended to the transcript on click. */\nexport function renderExpandedCard(card: GraphRailCard, hostInfo?: GraphRailHostInfo): string | undefined {\n\tconst s = graphRailStore.getState();\n\tconst header = (title: string) => theme.bold(theme.fg(\"accent\", `── GitNexus · ${title} ──`));\n\tif (card === \"repos\" && s.repos.length > 0) {\n\t\tconst lines: string[] = [header(\"indexed repos\")];\n\t\tfor (const repo of s.repos) {\n\t\t\tconst marker = repo.name === s.repo?.name ? theme.fg(\"accent\", \"●\") : theme.fg(\"muted\", \"○\");\n\t\t\tlines.push(`${marker} ${repo.name} ${theme.fg(\"muted\", `${repo.symbols} symbols`)}`);\n\t\t}\n\t\treturn lines.join(\"\\n\");\n\t}\n\tif (card === \"skills\" && hostInfo && hostInfo.skills.length > 0) {\n\t\tconst lines: string[] = [header(\"skills\")];\n\t\tfor (const skill of hostInfo.skills) {\n\t\t\tlines.push(`${theme.fg(\"success\", \"●\")} ${skill}`);\n\t\t}\n\t\treturn lines.join(\"\\n\");\n\t}\n\tif (card === \"impact\" && s.impact) {\n\t\tconst lines: string[] = [header(\"blast radius\")];\n\t\tconst risk = s.impact.risk.toUpperCase();\n\t\tconst riskColor = risk === \"HIGH\" || risk === \"CRITICAL\" ? \"error\" : risk === \"MEDIUM\" ? \"warning\" : \"success\";\n\t\tlines.push(\n\t\t\t`${theme.fg(\"accent\", \"◉\")} ${theme.bold(s.impact.target)} ${theme.fg(\"muted\", s.impact.filePath ?? \"\")} ${theme.bold(theme.fg(riskColor, `RISK: ${risk}`))}`,\n\t\t);\n\t\tconst depths = Object.keys(s.impact.byDepth)\n\t\t\t.map(Number)\n\t\t\t.filter((d) => !Number.isNaN(d))\n\t\t\t.sort((a, b) => a - b);\n\t\tfor (const depth of depths) {\n\t\t\tconst nodes = s.impact.byDepth[String(depth)] ?? [];\n\t\t\tif (nodes.length === 0) continue;\n\t\t\tconst color = depth === 1 ? \"error\" : depth === 2 ? \"warning\" : \"muted\";\n\t\t\tconst label = depth === 1 ? \"WILL BREAK\" : depth === 2 ? \"should test\" : \"transitive\";\n\t\t\tlines.push(theme.fg(color, `d=${depth} ${label} (${nodes.length})`));\n\t\t\tfor (const node of nodes) {\n\t\t\t\tconst rel = node.relationType ? theme.fg(\"muted\", ` (${node.relationType})`) : \"\";\n\t\t\t\tlines.push(\n\t\t\t\t\t` ${theme.fg(color, depth === 1 ? \"●\" : \"○\")} ${node.name} ${theme.fg(\"muted\", node.filePath ?? \"\")}${rel}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tif (s.impact.processes.length > 0)\n\t\t\tlines.push(theme.fg(\"muted\", `flows affected: ${s.impact.processes.join(\", \")}`));\n\t\tif (s.impact.modules.length > 0)\n\t\t\tlines.push(\n\t\t\t\ttheme.fg(\n\t\t\t\t\t\"muted\",\n\t\t\t\t\t`modules: ${s.impact.modules.map((m) => `${m.name} (${m.hits}${m.direct ? \", direct\" : \"\"})`).join(\", \")}`,\n\t\t\t\t),\n\t\t\t);\n\t\treturn lines.join(\"\\n\");\n\t}\n\tif (card === \"flows\" && s.query) {\n\t\tconst lines: string[] = [header(\"flows\"), theme.fg(\"muted\", `query: “${s.query.query}”`)];\n\t\ts.query.flows.forEach((flow, i) => {\n\t\t\tconst marker = i === 0 ? theme.fg(\"accent\", \"◉\") : theme.fg(\"muted\", \"○\");\n\t\t\tlines.push(\n\t\t\t\t`${marker} ${flow.summary}${flow.stepCount ? theme.fg(\"muted\", ` · ${flow.stepCount} steps`) : \"\"}`,\n\t\t\t);\n\t\t});\n\t\treturn lines.join(\"\\n\");\n\t}\n\tif (card === \"changes\" && s.changes.length > 0) {\n\t\tconst lines: string[] = [header(\"session changes\")];\n\t\tfor (const change of s.changes) {\n\t\t\tlines.push(\n\t\t\t\t`${theme.fg(\"success\", `+${change.added}`)} ${theme.fg(\"error\", `-${change.removed}`)} ${change.path}`,\n\t\t\t);\n\t\t}\n\t\treturn lines.join(\"\\n\");\n\t}\n\tif (card === \"status\" && s.repo) {\n\t\treturn [\n\t\t\theader(\"status\"),\n\t\t\t`repo: ${s.repo.name || \"(current dir not indexed)\"} · ${s.repo.symbols} symbols`,\n\t\t\t`indexed: ${s.repo.indexedAt || \"n/a\"} · ${s.repo.repoCount} repos on hub`,\n\t\t\t`graph calls: ${s.graphCalls} · impact checks: ${s.impactChecks}`,\n\t\t].join(\"\\n\");\n\t}\n\treturn undefined;\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { visibleWidth } from "@earendil-works/pi-tui";
|
|
2
|
-
import { graphRailStore } from "../../../core/graph-rail-store.js";
|
|
2
|
+
import { formatCompactIndexPhase, graphRailStore } from "../../../core/graph-rail-store.js";
|
|
3
3
|
import { diagonalFill, gradientText } from "../theme/brand.js";
|
|
4
4
|
import { theme } from "../theme/theme.js";
|
|
5
5
|
import { NEXUS_SMALL } from "./nexus-logo.js";
|
|
@@ -122,7 +122,7 @@ export class GraphRailComponent {
|
|
|
122
122
|
this.renderChanges(s, rule, row, end);
|
|
123
123
|
commitCard("changes");
|
|
124
124
|
beginCard();
|
|
125
|
-
this.renderStatus(s, rule, row, end);
|
|
125
|
+
this.renderStatus(s, inner, rule, row, end);
|
|
126
126
|
commitCard("status");
|
|
127
127
|
beginCard();
|
|
128
128
|
this.renderRepos(s, rule, row, end);
|
|
@@ -157,8 +157,23 @@ export class GraphRailComponent {
|
|
|
157
157
|
row(theme.fg("muted", ` … +${s.repos.length - 5} more`));
|
|
158
158
|
end();
|
|
159
159
|
}
|
|
160
|
-
renderStatus(s, rule, row, end) {
|
|
160
|
+
renderStatus(s, width, rule, row, end) {
|
|
161
161
|
rule("GitNexus");
|
|
162
|
+
if (s.indexProgress) {
|
|
163
|
+
const progress = s.indexProgress;
|
|
164
|
+
const phase = formatCompactIndexPhase(progress.phase);
|
|
165
|
+
row(theme.bold(progress.fullName.split("/").pop() ?? progress.fullName));
|
|
166
|
+
const percent = progress.percent === undefined ? undefined : Math.max(0, Math.min(100, Math.round(progress.percent)));
|
|
167
|
+
row(percent === undefined
|
|
168
|
+
? theme.fg("muted", phase)
|
|
169
|
+
: `${theme.fg("muted", phase)} ${theme.fg("accent", `${percent}%`)}`);
|
|
170
|
+
if (percent !== undefined) {
|
|
171
|
+
const filled = Math.round((percent / 100) * width);
|
|
172
|
+
row(theme.fg("accent", "━".repeat(filled)) + theme.fg("dim", "─".repeat(width - filled)));
|
|
173
|
+
}
|
|
174
|
+
end();
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
162
177
|
if (!s.repo) {
|
|
163
178
|
row(theme.fg("muted", "not connected"));
|
|
164
179
|
end();
|