@bastani/atomic 0.9.26-alpha.3 → 0.9.26-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/builtin/intercom/CHANGELOG.md +6 -0
  3. package/dist/builtin/intercom/broker/broker.ts +9 -1
  4. package/dist/builtin/intercom/index.bundle.mjs +11 -2
  5. package/dist/builtin/intercom/package.json +2 -2
  6. package/dist/builtin/intercom/types.ts +13 -0
  7. package/dist/builtin/mcp/package.json +1 -1
  8. package/dist/builtin/subagents/package.json +3 -3
  9. package/dist/builtin/web-access/package.json +2 -2
  10. package/dist/builtin/workflows/CHANGELOG.md +16 -0
  11. package/dist/builtin/workflows/builtin/{chunk-kfsnh3w7.js → chunk-613yaa53.js} +128 -45
  12. package/dist/builtin/workflows/builtin/{chunk-rqmasd3d.js → chunk-6kqrk0pf.js} +1 -1
  13. package/dist/builtin/workflows/builtin/{chunk-wz783pvd.js → chunk-ea6nrbn3.js} +1 -1
  14. package/dist/builtin/workflows/builtin/goal.js +2 -2
  15. package/dist/builtin/workflows/builtin/index.js +3 -3
  16. package/dist/builtin/workflows/builtin/ralph.js +2 -2
  17. package/dist/builtin/workflows/package.json +2 -2
  18. package/dist/builtin/workflows/src/extension/index.bundle.mjs +653 -303
  19. package/dist/builtin/workflows/src/index.js +201 -77
  20. package/dist/core/agent-session-export.js +1 -1
  21. package/dist/core/agent-session-export.js.map +1 -1
  22. package/dist/core/export-html/tool-renderer.d.ts +3 -3
  23. package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
  24. package/dist/core/export-html/tool-renderer.js +3 -3
  25. package/dist/core/export-html/tool-renderer.js.map +1 -1
  26. package/dist/core/extensions/api-types.d.ts +3 -1
  27. package/dist/core/extensions/api-types.d.ts.map +1 -1
  28. package/dist/core/extensions/api-types.js.map +1 -1
  29. package/dist/core/extensions/context-types.d.ts +5 -2
  30. package/dist/core/extensions/context-types.d.ts.map +1 -1
  31. package/dist/core/extensions/context-types.js.map +1 -1
  32. package/dist/core/extensions/index.d.ts +1 -1
  33. package/dist/core/extensions/index.d.ts.map +1 -1
  34. package/dist/core/extensions/index.js.map +1 -1
  35. package/dist/core/extensions/loader-api.d.ts.map +1 -1
  36. package/dist/core/extensions/loader-api.js +5 -0
  37. package/dist/core/extensions/loader-api.js.map +1 -1
  38. package/dist/core/extensions/loader-bindings.d.ts +1 -1
  39. package/dist/core/extensions/loader-bindings.d.ts.map +1 -1
  40. package/dist/core/extensions/loader-bindings.js +1 -0
  41. package/dist/core/extensions/loader-bindings.js.map +1 -1
  42. package/dist/core/extensions/runner.d.ts +3 -1
  43. package/dist/core/extensions/runner.d.ts.map +1 -1
  44. package/dist/core/extensions/runner.js +6 -0
  45. package/dist/core/extensions/runner.js.map +1 -1
  46. package/dist/core/extensions/runtime-types.d.ts +2 -1
  47. package/dist/core/extensions/runtime-types.d.ts.map +1 -1
  48. package/dist/core/extensions/runtime-types.js.map +1 -1
  49. package/dist/core/extensions/tool-types.d.ts +3 -0
  50. package/dist/core/extensions/tool-types.d.ts.map +1 -1
  51. package/dist/core/extensions/tool-types.js.map +1 -1
  52. package/dist/core/extensions/ui-types.d.ts +2 -2
  53. package/dist/core/extensions/ui-types.d.ts.map +1 -1
  54. package/dist/core/extensions/ui-types.js.map +1 -1
  55. package/dist/core/model-resolver-defaults.js +1 -1
  56. package/dist/core/model-resolver-defaults.js.map +1 -1
  57. package/dist/core/package-manager-auto-resources.d.ts.map +1 -1
  58. package/dist/core/package-manager-auto-resources.js +6 -2
  59. package/dist/core/package-manager-auto-resources.js.map +1 -1
  60. package/dist/core/package-manager-resolver.d.ts.map +1 -1
  61. package/dist/core/package-manager-resolver.js +4 -2
  62. package/dist/core/package-manager-resolver.js.map +1 -1
  63. package/dist/core/settings-manager-resource-accessors.js +7 -3
  64. package/dist/core/settings-manager-resource-accessors.js.map +1 -1
  65. package/dist/core/settings-merge.d.ts.map +1 -1
  66. package/dist/core/settings-merge.js +10 -0
  67. package/dist/core/settings-merge.js.map +1 -1
  68. package/dist/core/settings-types.d.ts +7 -1
  69. package/dist/core/settings-types.d.ts.map +1 -1
  70. package/dist/core/settings-types.js.map +1 -1
  71. package/dist/extensions/mcp/index.d.ts.map +1 -1
  72. package/dist/extensions/mcp/index.js +20 -1
  73. package/dist/extensions/mcp/index.js.map +1 -1
  74. package/dist/extensions/mcp/tools.d.ts +3 -1
  75. package/dist/extensions/mcp/tools.d.ts.map +1 -1
  76. package/dist/extensions/mcp/tools.js +19 -13
  77. package/dist/extensions/mcp/tools.js.map +1 -1
  78. package/dist/index.d.ts +2 -2
  79. package/dist/index.d.ts.map +1 -1
  80. package/dist/index.js.map +1 -1
  81. package/dist/modes/interactive/components/chat-message-renderer.d.ts +2 -3
  82. package/dist/modes/interactive/components/chat-message-renderer.d.ts.map +1 -1
  83. package/dist/modes/interactive/components/chat-message-renderer.js.map +1 -1
  84. package/dist/modes/interactive/components/config-selector-list.d.ts.map +1 -1
  85. package/dist/modes/interactive/components/config-selector-list.js +3 -1
  86. package/dist/modes/interactive/components/config-selector-list.js.map +1 -1
  87. package/dist/modes/interactive/components/config-selector-project-scope.d.ts.map +1 -1
  88. package/dist/modes/interactive/components/config-selector-project-scope.js +2 -1
  89. package/dist/modes/interactive/components/config-selector-project-scope.js.map +1 -1
  90. package/dist/modes/interactive/components/tool-execution.d.ts +2 -5
  91. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  92. package/dist/modes/interactive/components/tool-execution.js +14 -40
  93. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  94. package/dist/modes/interactive/interactive-mode-surface.d.ts +3 -3
  95. package/dist/modes/interactive/interactive-mode-surface.d.ts.map +1 -1
  96. package/dist/modes/interactive/interactive-mode-surface.js.map +1 -1
  97. package/dist/modes/interactive/interactive-session-runtime.js +6 -1
  98. package/dist/modes/interactive/interactive-session-runtime.js.map +1 -1
  99. package/dist/modes/interactive/interactive-startup.d.ts.map +1 -1
  100. package/dist/modes/interactive/interactive-startup.js +5 -0
  101. package/dist/modes/interactive/interactive-startup.js.map +1 -1
  102. package/dist/modes/interactive-engine/engine-custom-ui.d.ts.map +1 -1
  103. package/dist/modes/interactive-engine/engine-custom-ui.js +9 -0
  104. package/dist/modes/interactive-engine/engine-custom-ui.js.map +1 -1
  105. package/dist/modes/interactive-engine/engine-render-service.d.ts.map +1 -1
  106. package/dist/modes/interactive-engine/engine-render-service.js +10 -1
  107. package/dist/modes/interactive-engine/engine-render-service.js.map +1 -1
  108. package/dist/utils/image-convert.d.ts +5 -0
  109. package/dist/utils/image-convert.d.ts.map +1 -1
  110. package/dist/utils/image-convert.js +36 -6
  111. package/dist/utils/image-convert.js.map +1 -1
  112. package/docs/extensions.md +6 -0
  113. package/docs/intercom/reference.md +13 -1
  114. package/docs/providers.md +10 -0
  115. package/docs/settings.md +28 -1
  116. package/docs/workflows/operations.md +27 -3
  117. package/npm-shrinkwrap.json +71 -92
  118. package/package.json +9 -9
@@ -1 +1 @@
1
- {"version":3,"file":"engine-custom-ui.js","sourceRoot":"","sources":["../../../src/modes/interactive-engine/engine-custom-ui.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,YAAY,EAKZ,aAAa,GACb,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAK9D,OAAO,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAC;AACtD,OAAO,EAGN,WAAW,EAEX,6BAA6B,EAE7B,iCAAiC,GACjC,MAAM,eAAe,CAAC;AAkCvB,MAAM,cAAc;IACnB,OAAO,GAAG,EAAE,CAAC;IACb,IAAI,GAAG,EAAE,CAAC;IACV,mBAAmB,GAAG,KAAK,CAAC;IACX,UAAU,CAAa;IACvB,OAAO,CAAyD;IAChE,IAAI,CAA0D;IACvE,UAAU,GAAG,CAAC,CAAC;IACN,a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AK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;YAC5F,CAAC;YACD,QAAQ,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,MAAM,KAAK,IAAI;YAC7D,KAAK,EAAE,GAAG,EAAE;gBACX,OAAO,GAAG,IAAI,CAAC;gBACf,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;YAC5E,CAAC;YACD,OAAO,EAAE,GAAG,EAAE;gBACb,OAAO,GAAG,KAAK,CAAC;gBAChB,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;YAC9E,CAAC;YACD,SAAS,EAAE,GAAG,EAAE,CAAC,OAAO;YACxB,SAAS,EAAE,GAAG,EAAE,CAAC,SAAS;SAC1B,CAAC;IACH,CAAC;IAEO,QAAQ,CAAI,WAAmB,EAAE,MAAS;QACjD,IAAI,CAAC,IAAI,CAAC;YACT,IAAI,EAAE,oBAAoB;YAC1B,WAAW;YACX,MAAM,EAAE,UAAU,CAAC,MAA+D,CAAC;SACnF,CAAC,CAAC;IACJ,CAAC;IAEO,IAAI,CAAC,OAAiC;QAC7C,IAAI,CAAC,KAAK,CAAC,iCAAiC,CAAC,OAAO,CAAC,CAAC,CAAC;IACxD,CAAC;CACD","sourcesContent":["import {\n\ttype Component,\n\tisKeyRelease,\n\ttype OverlayHandle,\n\ttype OverlayOptions,\n\ttype Terminal,\n\ttype TUI,\n\tTuiMainScreen,\n} from \"@earendil-works/pi-tui\";\nimport { getAgentDir } from \"../../config.js\";\nimport { runCallback } from \"../../core/callback-activity.ts\";\nimport type { HostCustomUiState, HostCustomUiStateListener } from \"../../core/extensions/index.js\";\nimport type { ScrollableWidgetComponent } from \"../../core/extensions/ui-types.js\";\nimport type { KeybindingsManager } from \"../../core/keybindings.ts\";\nimport type { Theme } from \"../interactive/theme/theme.js\";\nimport { theme } from \"../interactive/theme/theme.js\";\nimport {\n\ttype EngineTerminalControl,\n\ttype InteractiveEngineMessage,\n\tisJsonValue,\n\ttype JsonValue,\n\tparseInteractiveEngineCommand,\n\ttype SerializableOverlayOptions,\n\tserializeInteractiveEngineMessage,\n} from \"./protocol.ts\";\n\ninterface CustomUiOptions {\n\tpurpose?: \"prompt\" | \"navigation\";\n\toverlay?: boolean;\n\tdeferInlineCustomUiFocus?: boolean;\n\t/** The component binds Ctrl+C itself; see ExtensionUIContext.custom options. */\n\thandlesCtrlC?: boolean;\n\t/** The component claims internal UI actions such as the jump-to-bottom URL. */\n\thandlesInternalUiAction?: boolean;\n\t/** Bound this overlay and reserve transcript scroll extent on the host. */\n\treserveTranscriptRows?: boolean;\n\toverlayOptions?: OverlayOptions | (() => OverlayOptions);\n\tonHandle?: (handle: OverlayHandle) => void;\n\tsignal?: AbortSignal;\n}\n\ninterface ActiveComponent {\n\tcomponent: Component & { dispose?(): void };\n\tresolve: (value: JsonValue | undefined) => void;\n\toverlay: boolean;\n\tpurpose?: \"prompt\" | \"navigation\";\n\tterminal: RemoteTerminal;\n\ttui: TUI;\n\twidgetKey?: string;\n\t/**\n\t * Overlay visibility as last driven through the remote OverlayHandle.\n\t * Hidden components are skipped by the extension-level `requestRender()`\n\t * broadcast (#1856) — invalidating a hidden overlay only produced host\n\t * render work and terminal writes for frames the user cannot see.\n\t */\n\thidden?: boolean;\n}\n\nclass RemoteTerminal implements Terminal {\n\tcolumns = 80;\n\trows = 24;\n\tkittyProtocolActive = false;\n\tprivate readonly invalidate: () => void;\n\tprivate readonly control: ((control: EngineTerminalControl) => void) | undefined;\n\tprivate readonly copy: ((requestId: number, text: string) => void) | undefined;\n\tprivate nextCopyId = 0;\n\tprivate readonly pendingCopies = new Map<\n\t\tnumber,\n\t\t{ resolve: () => void; reject: (error: Error) => void; timer: ReturnType<typeof setTimeout> }\n\t>();\n\tconstructor(\n\t\tinvalidate: () => void,\n\t\tcontrol?: (control: EngineTerminalControl) => void,\n\t\tcopy?: (requestId: number, text: string) => void,\n\t) {\n\t\tthis.invalidate = invalidate;\n\t\tthis.control = control;\n\t\tthis.copy = copy;\n\t}\n\tcopyTextToHost(text: string): Promise<void> {\n\t\tif (!this.copy) return Promise.reject(new Error(\"Host clipboard unavailable\"));\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst requestId = ++this.nextCopyId;\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tthis.pendingCopies.delete(requestId);\n\t\t\t\treject(new Error(\"Host clipboard did not respond\"));\n\t\t\t}, 15_000);\n\t\t\tthis.pendingCopies.set(requestId, { resolve, reject, timer });\n\t\t\tthis.copy?.(requestId, text);\n\t\t});\n\t}\n\tresolveCopy(requestId: number, error?: string): void {\n\t\tconst pending = this.pendingCopies.get(requestId);\n\t\tif (!pending) return;\n\t\tclearTimeout(pending.timer);\n\t\tthis.pendingCopies.delete(requestId);\n\t\tif (error) pending.reject(new Error(error));\n\t\telse pending.resolve();\n\t}\n\tclose(): void {\n\t\tfor (const requestId of this.pendingCopies.keys()) this.resolveCopy(requestId, \"Sign-in screen closed\");\n\t}\n\tstart(): void {}\n\tstop(): void {}\n\tasync drainInput(): Promise<void> {}\n\twrite(): void {\n\t\tthis.invalidate();\n\t}\n\tmoveBy(): void {}\n\thideCursor(): void {}\n\tshowCursor(): void {}\n\tclearLine(): void {}\n\tclearFromCursor(): void {}\n\tclearScreen(): void {}\n\tsetTitle(): void {}\n\tsetProgress(): void {}\n\t/** Ask the host to toggle host-TTY autowrap (DECAWM) for this component. */\n\tsetAutowrap(enabled: boolean): void {\n\t\tthis.control?.({ kind: \"autowrap\", enabled });\n\t}\n}\n\nfunction serializableOverlayOptions(\n\toptions: CustomUiOptions[\"overlayOptions\"],\n): SerializableOverlayOptions | undefined {\n\tconst value = typeof options === \"function\" ? options() : options;\n\tif (!value) return undefined;\n\tconst { anchor, col, margin, maxHeight, minWidth, offsetX, offsetY, row, width } = value;\n\treturn { anchor, col, margin, maxHeight, minWidth, offsetX, offsetY, row, width };\n}\n\nfunction jsonResult(value: object | boolean | null | number | string | undefined): JsonValue | undefined {\n\tif (value === undefined) return undefined;\n\tconst encoded = JSON.stringify(value);\n\tif (encoded === undefined) return undefined;\n\tconst decoded = JSON.parse(encoded) as JsonValue;\n\tif (!isJsonValue(decoded)) throw new Error(\"Custom UI result is not JSON-safe\");\n\treturn decoded;\n}\n\nexport class EngineCustomUiService {\n\tprivate readonly widgetIds = new Map<string, string>();\n\tprivate readonly active = new Map<string, ActiveComponent>();\n\tprivate nextId = 0;\n\tprivate readonly write: (line: string) => void;\n\tprivate readonly keybindings: KeybindingsManager;\n\tprivate readonly stateListeners = new Set<HostCustomUiStateListener>();\n\tprivate readonly widgetReleaseListeners = new Map<string, Set<() => void>>();\n\n\tsetWidget(\n\t\tkey: string,\n\t\tfactory: ((tui: TUI, theme: Theme) => Component & { dispose?(): void }) | undefined,\n\t\tplacement?: \"aboveEditor\" | \"belowEditor\",\n\t\tscroll?: { maxHeight: number; maxHeightFraction?: number },\n\t): void {\n\t\tconst previous = this.widgetIds.get(key);\n\t\tif (previous) this.disposeComponent(previous, false, false);\n\t\tif (!factory) {\n\t\t\tthis.notifyWidgetRelease(key);\n\t\t\treturn;\n\t\t}\n\t\tconst componentId = `remote_widget_${++this.nextId}`;\n\t\tthis.widgetIds.set(key, componentId);\n\t\tconst terminal = new RemoteTerminal(() => this.send({ type: \"engine_custom_invalidate\", componentId }));\n\t\tconst tui = new TuiMainScreen(terminal, undefined, getAgentDir());\n\t\tvoid runCallback({ kind: \"renderer\", name: `widget:${key}` }, () => factory(tui, theme))\n\t\t\t.then((component) => {\n\t\t\t\tif (this.widgetIds.get(key) !== componentId) {\n\t\t\t\t\tcomponent.dispose?.();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\ttui.addChild(component);\n\t\t\t\tthis.active.set(componentId, {\n\t\t\t\t\tcomponent,\n\t\t\t\t\tresolve: () => {},\n\t\t\t\t\toverlay: false,\n\t\t\t\t\tterminal,\n\t\t\t\t\ttui,\n\t\t\t\t\twidgetKey: key,\n\t\t\t\t});\n\t\t\t\tthis.send({\n\t\t\t\t\ttype: \"engine_custom_open\",\n\t\t\t\t\tcomponentId,\n\t\t\t\t\toverlay: false,\n\t\t\t\t\twidgetKey: key,\n\t\t\t\t\twidgetPlacement: placement,\n\t\t\t\t\t...(scroll ? { widgetScroll: scroll } : {}),\n\t\t\t\t});\n\t\t\t})\n\t\t\t.catch((error: Error) => {\n\t\t\t\tif (this.widgetIds.get(key) === componentId) this.widgetIds.delete(key);\n\t\t\t\tthis.send({\n\t\t\t\t\ttype: \"engine_custom_frame\",\n\t\t\t\t\tcomponentId,\n\t\t\t\t\trequestId: 0,\n\t\t\t\t\tlines: [`Widget ${key} failed: ${error.message}`],\n\t\t\t\t});\n\t\t\t});\n\t}\n\tconstructor(write: (line: string) => void, keybindings: KeybindingsManager) {\n\t\tthis.write = write;\n\t\tthis.keybindings = keybindings;\n\t}\n\n\tasync custom<T>(\n\t\tfactory: (\n\t\t\ttui: TUI,\n\t\t\ttheme: Theme,\n\t\t\tkeybindings: KeybindingsManager,\n\t\t\tdone: (result: T) => void,\n\t\t) => (Component & { dispose?(): void }) | Promise<Component & { dispose?(): void }>,\n\t\toptions?: CustomUiOptions,\n\t): Promise<T> {\n\t\tconst componentId = `remote_component_${++this.nextId}`;\n\t\tlet resolveCompletion!: (value: T) => void;\n\t\tconst completion = new Promise<T>((resolve) => {\n\t\t\tresolveCompletion = resolve;\n\t\t});\n\t\tlet opened = false;\n\t\tlet pendingDone: T | undefined;\n\t\tlet doneCalled = false;\n\t\tconst done = (result: T): void => {\n\t\t\tif (doneCalled) return;\n\t\t\tdoneCalled = true;\n\t\t\tpendingDone = result;\n\t\t\tresolveCompletion(result);\n\t\t\tif (opened) this.sendDone(componentId, result);\n\t\t};\n\t\tconst terminal = new RemoteTerminal(\n\t\t\t() => this.send({ type: \"engine_custom_invalidate\", componentId }),\n\t\t\t(control) => this.send({ type: \"engine_custom_terminal\", componentId, control }),\n\t\t\t(requestId, text) => this.send({ type: \"engine_custom_copy\", componentId, requestId, text }),\n\t\t);\n\t\tconst tui = new TuiMainScreen(terminal, undefined, getAgentDir());\n\t\tconst component = await factory(tui, theme, this.keybindings, done);\n\t\ttui.addChild(component);\n\t\ttui.setFocus(component);\n\t\tconst record: ActiveComponent = {\n\t\t\tcomponent,\n\t\t\t// Cancellation must settle through the same guarded host completion as done().\n\t\t\tresolve: (value) => done(value as T),\n\t\t\tterminal,\n\t\t\ttui,\n\t\t\toverlay: options?.overlay === true,\n\t\t\tpurpose: options?.purpose,\n\t\t};\n\t\tthis.active.set(componentId, record);\n\t\tthis.notifyState();\n\t\topened = true;\n\t\tthis.send({\n\t\t\ttype: \"engine_custom_open\",\n\t\t\tcomponentId,\n\t\t\toverlay: options?.overlay === true,\n\t\t\tpurpose: options?.purpose,\n\t\t\tdeferInlineCustomUiFocus: options?.deferInlineCustomUiFocus,\n\t\t\thandlesCtrlC: options?.handlesCtrlC,\n\t\t\thandlesInternalUiAction: options?.handlesInternalUiAction,\n\t\t\treserveTranscriptRows: options?.reserveTranscriptRows,\n\t\t\toverlayOptions: serializableOverlayOptions(options?.overlayOptions),\n\t\t});\n\t\tif (options?.onHandle) options.onHandle(this.remoteHandle(componentId));\n\t\tif (doneCalled) this.sendDone(componentId, pendingDone as T);\n\t\tconst onAbort = () => this.disposeComponent(componentId, true);\n\t\toptions?.signal?.addEventListener(\"abort\", onAbort, { once: true });\n\t\ttry {\n\t\t\treturn await completion;\n\t\t} finally {\n\t\t\toptions?.signal?.removeEventListener(\"abort\", onAbort);\n\t\t\tthis.disposeComponent(componentId, false);\n\t\t}\n\t}\n\tgetHostCustomUiState(): HostCustomUiState {\n\t\tconst inline = [...this.active.values()].filter((record) => !record.overlay && !record.widgetKey);\n\t\tconst navigation = inline.filter((record) => record.purpose === \"navigation\").length;\n\t\treturn {\n\t\t\tblockingInlineCustomUiDepth: inline.length,\n\t\t\tblockingInlineCustomUiActive: inline.length > 0,\n\t\t\t...(navigation > 0 ? { blockingInlineCustomUiNeedsInput: inline.length > navigation } : {}),\n\t\t};\n\t}\n\n\tonHostCustomUiStateChange(listener: HostCustomUiStateListener): () => void {\n\t\tthis.stateListeners.add(listener);\n\t\treturn () => this.stateListeners.delete(listener);\n\t}\n\tonWidgetRelease(key: string, listener: () => void): () => void {\n\t\tconst listeners = this.widgetReleaseListeners.get(key) ?? new Set<() => void>();\n\t\tlisteners.add(listener);\n\t\tthis.widgetReleaseListeners.set(key, listeners);\n\t\treturn () => {\n\t\t\tlisteners.delete(listener);\n\t\t\tif (listeners.size === 0) this.widgetReleaseListeners.delete(key);\n\t\t};\n\t}\n\n\tfocusHostInlineCustomUi(): boolean {\n\t\treturn this.getHostCustomUiState().blockingInlineCustomUiActive;\n\t}\n\n\trequestRender(): void {\n\t\tfor (const [componentId, record] of this.active) {\n\t\t\tif (record.hidden === true) continue;\n\t\t\tthis.send({ type: \"engine_custom_invalidate\", componentId });\n\t\t}\n\t}\n\n\thandleLine(line: string): boolean {\n\t\tconst command = parseInteractiveEngineCommand(line);\n\t\tif (!command) return false;\n\t\tif (!command.type.startsWith(\"engine_custom_\")) return false;\n\t\tconst record = this.active.get(command.componentId);\n\t\tif (!record) {\n\t\t\tif (command.type === \"engine_custom_input\")\n\t\t\t\tthis.send({\n\t\t\t\t\ttype: \"engine_custom_input_result\",\n\t\t\t\t\tcomponentId: command.componentId,\n\t\t\t\t\trequestId: command.requestId,\n\t\t\t\t\thandled: false,\n\t\t\t\t});\n\t\t\treturn true;\n\t\t}\n\t\tswitch (command.type) {\n\t\t\tcase \"engine_custom_scroll\":\n\t\t\t\t(record.component as ScrollableWidgetComponent).onScroll?.(command.state);\n\t\t\t\tbreak;\n\t\t\tcase \"engine_custom_render\":\n\t\t\t\trecord.terminal.columns = Math.max(1, command.width);\n\t\t\t\trecord.terminal.rows = Math.max(1, command.rows);\n\t\t\t\tvoid runCallback({ kind: \"renderer\", name: command.componentId }, () =>\n\t\t\t\t\trecord.component.render(record.terminal.columns),\n\t\t\t\t)\n\t\t\t\t\t.then((lines) => {\n\t\t\t\t\t\tconst scrollRequest = (record.component as ScrollableWidgetComponent).getScrollRequest?.();\n\t\t\t\t\t\tthis.send({\n\t\t\t\t\t\t\ttype: \"engine_custom_frame\",\n\t\t\t\t\t\t\tcomponentId: command.componentId,\n\t\t\t\t\t\t\trequestId: command.requestId,\n\t\t\t\t\t\t\tlines,\n\t\t\t\t\t\t\t...(scrollRequest ? { scrollRequest } : {}),\n\t\t\t\t\t\t});\n\t\t\t\t\t})\n\t\t\t\t\t.catch((error: Error) =>\n\t\t\t\t\t\tthis.send({\n\t\t\t\t\t\t\ttype: \"engine_custom_frame\",\n\t\t\t\t\t\t\tcomponentId: command.componentId,\n\t\t\t\t\t\t\trequestId: command.requestId,\n\t\t\t\t\t\t\tlines: [`Remote component render failed: ${error.message}`],\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\tcase \"engine_custom_input\":\n\t\t\t\tvoid runCallback({ kind: \"renderer\", name: command.componentId }, () => {\n\t\t\t\t\tif (isKeyRelease(command.data) && record.component.wantsKeyRelease !== true) return false;\n\t\t\t\t\tconst handleInput = record.component.handleInput as ((data: string) => boolean | undefined) | undefined;\n\t\t\t\t\treturn handleInput?.call(record.component, command.data) === true;\n\t\t\t\t})\n\t\t\t\t\t.then((handled) =>\n\t\t\t\t\t\tthis.send({\n\t\t\t\t\t\t\ttype: \"engine_custom_input_result\",\n\t\t\t\t\t\t\tcomponentId: command.componentId,\n\t\t\t\t\t\t\trequestId: command.requestId,\n\t\t\t\t\t\t\thandled,\n\t\t\t\t\t\t}),\n\t\t\t\t\t)\n\t\t\t\t\t.catch(() =>\n\t\t\t\t\t\tthis.send({\n\t\t\t\t\t\t\ttype: \"engine_custom_input_result\",\n\t\t\t\t\t\t\tcomponentId: command.componentId,\n\t\t\t\t\t\t\trequestId: command.requestId,\n\t\t\t\t\t\t\thandled: false,\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\tcase \"engine_custom_copy_result\":\n\t\t\t\trecord.terminal.resolveCopy(command.requestId, command.error);\n\t\t\t\tbreak;\n\t\t\tcase \"engine_custom_dispose\":\n\t\t\t\tthis.disposeComponent(command.componentId, true);\n\t\t\t\tbreak;\n\t\t}\n\t\treturn true;\n\t}\n\n\tdispose(): void {\n\t\tfor (const componentId of [...this.active.keys()]) this.disposeComponent(componentId, true, false);\n\t}\n\tprivate disposeComponent(componentId: string, resolve: boolean, notifyWidgetRelease = true): void {\n\t\tconst record = this.active.get(componentId);\n\t\tif (!record) return;\n\t\tthis.active.delete(componentId);\n\t\trecord.terminal.close();\n\t\t// Claim cancellation before user disposal code can call done() reentrantly.\n\t\tif (resolve) record.resolve(undefined);\n\t\trecord.component.dispose?.();\n\t\trecord.tui.stop();\n\t\tif (record.widgetKey) {\n\t\t\tif (this.widgetIds.get(record.widgetKey) === componentId) this.widgetIds.delete(record.widgetKey);\n\t\t\tthis.send({ type: \"engine_custom_close\", componentId });\n\t\t\tif (notifyWidgetRelease) this.notifyWidgetRelease(record.widgetKey);\n\t\t}\n\t\tthis.notifyState();\n\t}\n\tprivate notifyWidgetRelease(key: string): void {\n\t\tfor (const listener of this.widgetReleaseListeners.get(key) ?? []) {\n\t\t\ttry {\n\t\t\t\tlistener();\n\t\t\t} catch {\n\t\t\t\t// A release observer must not break engine UI teardown.\n\t\t\t}\n\t\t}\n\t}\n\tprivate notifyState(): void {\n\t\tconst state = this.getHostCustomUiState();\n\t\tfor (const listener of this.stateListeners) listener(state);\n\t}\n\n\tprivate remoteHandle(componentId: string): OverlayHandle {\n\t\tlet focused = true;\n\t\tconst setHiddenFlag = (value: boolean): void => {\n\t\t\tconst record = this.active.get(componentId);\n\t\t\tif (record) record.hidden = value;\n\t\t};\n\t\treturn {\n\t\t\thide: () => {\n\t\t\t\tsetHiddenFlag(true);\n\t\t\t\tthis.send({ type: \"engine_custom_control\", componentId, action: \"hide\" });\n\t\t\t},\n\t\t\tsetHidden: (value) => {\n\t\t\t\tsetHiddenFlag(value);\n\t\t\t\tthis.send({ type: \"engine_custom_control\", componentId, action: value ? \"hide\" : \"show\" });\n\t\t\t},\n\t\t\tisHidden: () => this.active.get(componentId)?.hidden === true,\n\t\t\tfocus: () => {\n\t\t\t\tfocused = true;\n\t\t\t\tthis.send({ type: \"engine_custom_control\", componentId, action: \"focus\" });\n\t\t\t},\n\t\t\tunfocus: () => {\n\t\t\t\tfocused = false;\n\t\t\t\tthis.send({ type: \"engine_custom_control\", componentId, action: \"unfocus\" });\n\t\t\t},\n\t\t\tisFocused: () => focused,\n\t\t\tgetBounds: () => undefined,\n\t\t};\n\t}\n\n\tprivate sendDone<T>(componentId: string, result: T): void {\n\t\tthis.send({\n\t\t\ttype: \"engine_custom_done\",\n\t\t\tcomponentId,\n\t\t\tresult: jsonResult(result as object | boolean | null | number | string | undefined),\n\t\t});\n\t}\n\n\tprivate send(message: InteractiveEngineMessage): void {\n\t\tthis.write(serializeInteractiveEngineMessage(message));\n\t}\n}\n"]}
1
+ {"version":3,"file":"engine-custom-ui.js","sourceRoot":"","sources":["../../../src/modes/interactive-engine/engine-custom-ui.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,YAAY,EAKZ,aAAa,GACb,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAI9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAEnE,OAAO,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAC;AACtD,OAAO,EAGN,WAAW,EAEX,6BAA6B,EAE7B,iCAAiC,GACjC,MAAM,eAAe,CAAC;AAkC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MAAM,EAAE,UAAU,CAAC,MAA+D,CAAC;SACnF,CAAC,CAAC;IACJ,CAAC;IAEO,IAAI,CAAC,OAAiC;QAC7C,IAAI,CAAC,KAAK,CAAC,iCAAiC,CAAC,OAAO,CAAC,CAAC,CAAC;IACxD,CAAC;CACD","sourcesContent":["import {\n\ttype Component,\n\tisKeyRelease,\n\ttype OverlayHandle,\n\ttype OverlayOptions,\n\ttype Terminal,\n\ttype TUI,\n\tTuiMainScreen,\n} from \"@earendil-works/pi-tui\";\nimport { getAgentDir } from \"../../config.js\";\nimport { runCallback } from \"../../core/callback-activity.ts\";\nimport type { HostCustomUiState, HostCustomUiStateListener } from \"../../core/extensions/index.js\";\nimport type { ScrollableWidgetComponent } from \"../../core/extensions/ui-types.js\";\nimport type { KeybindingsManager } from \"../../core/keybindings.ts\";\nimport { ensurePngTranscoder } from \"../../utils/image-convert.ts\";\nimport type { Theme } from \"../interactive/theme/theme.js\";\nimport { theme } from \"../interactive/theme/theme.js\";\nimport {\n\ttype EngineTerminalControl,\n\ttype InteractiveEngineMessage,\n\tisJsonValue,\n\ttype JsonValue,\n\tparseInteractiveEngineCommand,\n\ttype SerializableOverlayOptions,\n\tserializeInteractiveEngineMessage,\n} from \"./protocol.ts\";\n\ninterface CustomUiOptions {\n\tpurpose?: \"prompt\" | \"navigation\";\n\toverlay?: boolean;\n\tdeferInlineCustomUiFocus?: boolean;\n\t/** The component binds Ctrl+C itself; see ExtensionUIContext.custom options. */\n\thandlesCtrlC?: boolean;\n\t/** The component claims internal UI actions such as the jump-to-bottom URL. */\n\thandlesInternalUiAction?: boolean;\n\t/** Bound this overlay and reserve transcript scroll extent on the host. */\n\treserveTranscriptRows?: boolean;\n\toverlayOptions?: OverlayOptions | (() => OverlayOptions);\n\tonHandle?: (handle: OverlayHandle) => void;\n\tsignal?: AbortSignal;\n}\n\ninterface ActiveComponent {\n\tcomponent: Component & { dispose?(): void };\n\tresolve: (value: JsonValue | undefined) => void;\n\toverlay: boolean;\n\tpurpose?: \"prompt\" | \"navigation\";\n\tterminal: RemoteTerminal;\n\ttui: TUI;\n\twidgetKey?: string;\n\t/**\n\t * Overlay visibility as last driven through the remote OverlayHandle.\n\t * Hidden components are skipped by the extension-level `requestRender()`\n\t * broadcast (#1856) — invalidating a hidden overlay only produced host\n\t * render work and terminal writes for frames the user cannot see.\n\t */\n\thidden?: boolean;\n}\n\nclass RemoteTerminal implements Terminal {\n\tcolumns = 80;\n\trows = 24;\n\tkittyProtocolActive = false;\n\tprivate readonly invalidate: () => void;\n\tprivate readonly control: ((control: EngineTerminalControl) => void) | undefined;\n\tprivate readonly copy: ((requestId: number, text: string) => void) | undefined;\n\tprivate nextCopyId = 0;\n\tprivate readonly pendingCopies = new Map<\n\t\tnumber,\n\t\t{ resolve: () => void; reject: (error: Error) => void; timer: ReturnType<typeof setTimeout> }\n\t>();\n\tconstructor(\n\t\tinvalidate: () => void,\n\t\tcontrol?: (control: EngineTerminalControl) => void,\n\t\tcopy?: (requestId: number, text: string) => void,\n\t) {\n\t\tthis.invalidate = invalidate;\n\t\tthis.control = control;\n\t\tthis.copy = copy;\n\t}\n\tcopyTextToHost(text: string): Promise<void> {\n\t\tif (!this.copy) return Promise.reject(new Error(\"Host clipboard unavailable\"));\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst requestId = ++this.nextCopyId;\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tthis.pendingCopies.delete(requestId);\n\t\t\t\treject(new Error(\"Host clipboard did not respond\"));\n\t\t\t}, 15_000);\n\t\t\tthis.pendingCopies.set(requestId, { resolve, reject, timer });\n\t\t\tthis.copy?.(requestId, text);\n\t\t});\n\t}\n\tresolveCopy(requestId: number, error?: string): void {\n\t\tconst pending = this.pendingCopies.get(requestId);\n\t\tif (!pending) return;\n\t\tclearTimeout(pending.timer);\n\t\tthis.pendingCopies.delete(requestId);\n\t\tif (error) pending.reject(new Error(error));\n\t\telse pending.resolve();\n\t}\n\tclose(): void {\n\t\tfor (const requestId of this.pendingCopies.keys()) this.resolveCopy(requestId, \"Sign-in screen closed\");\n\t}\n\tstart(): void {}\n\tstop(): void {}\n\tasync drainInput(): Promise<void> {}\n\twrite(): void {\n\t\tthis.invalidate();\n\t}\n\tmoveBy(): void {}\n\thideCursor(): void {}\n\tshowCursor(): void {}\n\tclearLine(): void {}\n\tclearFromCursor(): void {}\n\tclearScreen(): void {}\n\tsetTitle(): void {}\n\tsetProgress(): void {}\n\t/** Ask the host to toggle host-TTY autowrap (DECAWM) for this component. */\n\tsetAutowrap(enabled: boolean): void {\n\t\tthis.control?.({ kind: \"autowrap\", enabled });\n\t}\n}\n\nfunction serializableOverlayOptions(\n\toptions: CustomUiOptions[\"overlayOptions\"],\n): SerializableOverlayOptions | undefined {\n\tconst value = typeof options === \"function\" ? options() : options;\n\tif (!value) return undefined;\n\tconst { anchor, col, margin, maxHeight, minWidth, offsetX, offsetY, row, width } = value;\n\treturn { anchor, col, margin, maxHeight, minWidth, offsetX, offsetY, row, width };\n}\n\nfunction jsonResult(value: object | boolean | null | number | string | undefined): JsonValue | undefined {\n\tif (value === undefined) return undefined;\n\tconst encoded = JSON.stringify(value);\n\tif (encoded === undefined) return undefined;\n\tconst decoded = JSON.parse(encoded) as JsonValue;\n\tif (!isJsonValue(decoded)) throw new Error(\"Custom UI result is not JSON-safe\");\n\treturn decoded;\n}\n\nexport class EngineCustomUiService {\n\tprivate readonly widgetIds = new Map<string, string>();\n\tprivate readonly active = new Map<string, ActiveComponent>();\n\tprivate nextId = 0;\n\tprivate readonly write: (line: string) => void;\n\tprivate readonly keybindings: KeybindingsManager;\n\tprivate readonly stateListeners = new Set<HostCustomUiStateListener>();\n\tprivate readonly widgetReleaseListeners = new Map<string, Set<() => void>>();\n\n\tsetWidget(\n\t\tkey: string,\n\t\tfactory: ((tui: TUI, theme: Theme) => Component & { dispose?(): void }) | undefined,\n\t\tplacement?: \"aboveEditor\" | \"belowEditor\",\n\t\tscroll?: { maxHeight: number; maxHeightFraction?: number },\n\t): void {\n\t\tconst previous = this.widgetIds.get(key);\n\t\tif (previous) this.disposeComponent(previous, false, false);\n\t\tif (!factory) {\n\t\t\tthis.notifyWidgetRelease(key);\n\t\t\treturn;\n\t\t}\n\t\tconst componentId = `remote_widget_${++this.nextId}`;\n\t\tthis.widgetIds.set(key, componentId);\n\t\tconst terminal = new RemoteTerminal(() => this.send({ type: \"engine_custom_invalidate\", componentId }));\n\t\tconst tui = new TuiMainScreen(terminal, undefined, getAgentDir());\n\t\tensurePngTranscoder(() => {\n\t\t\ttui.invalidate();\n\t\t\ttui.requestRender();\n\t\t});\n\t\tvoid runCallback({ kind: \"renderer\", name: `widget:${key}` }, () => factory(tui, theme))\n\t\t\t.then((component) => {\n\t\t\t\tif (this.widgetIds.get(key) !== componentId) {\n\t\t\t\t\tcomponent.dispose?.();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\ttui.addChild(component);\n\t\t\t\tthis.active.set(componentId, {\n\t\t\t\t\tcomponent,\n\t\t\t\t\tresolve: () => {},\n\t\t\t\t\toverlay: false,\n\t\t\t\t\tterminal,\n\t\t\t\t\ttui,\n\t\t\t\t\twidgetKey: key,\n\t\t\t\t});\n\t\t\t\tthis.send({\n\t\t\t\t\ttype: \"engine_custom_open\",\n\t\t\t\t\tcomponentId,\n\t\t\t\t\toverlay: false,\n\t\t\t\t\twidgetKey: key,\n\t\t\t\t\twidgetPlacement: placement,\n\t\t\t\t\t...(scroll ? { widgetScroll: scroll } : {}),\n\t\t\t\t});\n\t\t\t})\n\t\t\t.catch((error: Error) => {\n\t\t\t\tif (this.widgetIds.get(key) === componentId) this.widgetIds.delete(key);\n\t\t\t\tthis.send({\n\t\t\t\t\ttype: \"engine_custom_frame\",\n\t\t\t\t\tcomponentId,\n\t\t\t\t\trequestId: 0,\n\t\t\t\t\tlines: [`Widget ${key} failed: ${error.message}`],\n\t\t\t\t});\n\t\t\t});\n\t}\n\tconstructor(write: (line: string) => void, keybindings: KeybindingsManager) {\n\t\tthis.write = write;\n\t\tthis.keybindings = keybindings;\n\t}\n\n\tasync custom<T>(\n\t\tfactory: (\n\t\t\ttui: TUI,\n\t\t\ttheme: Theme,\n\t\t\tkeybindings: KeybindingsManager,\n\t\t\tdone: (result: T) => void,\n\t\t) => (Component & { dispose?(): void }) | Promise<Component & { dispose?(): void }>,\n\t\toptions?: CustomUiOptions,\n\t): Promise<T> {\n\t\tconst componentId = `remote_component_${++this.nextId}`;\n\t\tlet resolveCompletion!: (value: T) => void;\n\t\tconst completion = new Promise<T>((resolve) => {\n\t\t\tresolveCompletion = resolve;\n\t\t});\n\t\tlet opened = false;\n\t\tlet pendingDone: T | undefined;\n\t\tlet doneCalled = false;\n\t\tconst done = (result: T): void => {\n\t\t\tif (doneCalled) return;\n\t\t\tdoneCalled = true;\n\t\t\tpendingDone = result;\n\t\t\tresolveCompletion(result);\n\t\t\tif (opened) this.sendDone(componentId, result);\n\t\t};\n\t\tconst terminal = new RemoteTerminal(\n\t\t\t() => this.send({ type: \"engine_custom_invalidate\", componentId }),\n\t\t\t(control) => this.send({ type: \"engine_custom_terminal\", componentId, control }),\n\t\t\t(requestId, text) => this.send({ type: \"engine_custom_copy\", componentId, requestId, text }),\n\t\t);\n\t\tconst tui = new TuiMainScreen(terminal, undefined, getAgentDir());\n\t\tensurePngTranscoder(() => {\n\t\t\ttui.invalidate();\n\t\t\ttui.requestRender();\n\t\t});\n\t\tconst component = await factory(tui, theme, this.keybindings, done);\n\t\ttui.addChild(component);\n\t\ttui.setFocus(component);\n\t\tconst record: ActiveComponent = {\n\t\t\tcomponent,\n\t\t\t// Cancellation must settle through the same guarded host completion as done().\n\t\t\tresolve: (value) => done(value as T),\n\t\t\tterminal,\n\t\t\ttui,\n\t\t\toverlay: options?.overlay === true,\n\t\t\tpurpose: options?.purpose,\n\t\t};\n\t\tthis.active.set(componentId, record);\n\t\tthis.notifyState();\n\t\topened = true;\n\t\tthis.send({\n\t\t\ttype: \"engine_custom_open\",\n\t\t\tcomponentId,\n\t\t\toverlay: options?.overlay === true,\n\t\t\tpurpose: options?.purpose,\n\t\t\tdeferInlineCustomUiFocus: options?.deferInlineCustomUiFocus,\n\t\t\thandlesCtrlC: options?.handlesCtrlC,\n\t\t\thandlesInternalUiAction: options?.handlesInternalUiAction,\n\t\t\treserveTranscriptRows: options?.reserveTranscriptRows,\n\t\t\toverlayOptions: serializableOverlayOptions(options?.overlayOptions),\n\t\t});\n\t\tif (options?.onHandle) options.onHandle(this.remoteHandle(componentId));\n\t\tif (doneCalled) this.sendDone(componentId, pendingDone as T);\n\t\tconst onAbort = () => this.disposeComponent(componentId, true);\n\t\toptions?.signal?.addEventListener(\"abort\", onAbort, { once: true });\n\t\ttry {\n\t\t\treturn await completion;\n\t\t} finally {\n\t\t\toptions?.signal?.removeEventListener(\"abort\", onAbort);\n\t\t\tthis.disposeComponent(componentId, false);\n\t\t}\n\t}\n\tgetHostCustomUiState(): HostCustomUiState {\n\t\tconst inline = [...this.active.values()].filter((record) => !record.overlay && !record.widgetKey);\n\t\tconst navigation = inline.filter((record) => record.purpose === \"navigation\").length;\n\t\treturn {\n\t\t\tblockingInlineCustomUiDepth: inline.length,\n\t\t\tblockingInlineCustomUiActive: inline.length > 0,\n\t\t\t...(navigation > 0 ? { blockingInlineCustomUiNeedsInput: inline.length > navigation } : {}),\n\t\t};\n\t}\n\n\tonHostCustomUiStateChange(listener: HostCustomUiStateListener): () => void {\n\t\tthis.stateListeners.add(listener);\n\t\treturn () => this.stateListeners.delete(listener);\n\t}\n\tonWidgetRelease(key: string, listener: () => void): () => void {\n\t\tconst listeners = this.widgetReleaseListeners.get(key) ?? new Set<() => void>();\n\t\tlisteners.add(listener);\n\t\tthis.widgetReleaseListeners.set(key, listeners);\n\t\treturn () => {\n\t\t\tlisteners.delete(listener);\n\t\t\tif (listeners.size === 0) this.widgetReleaseListeners.delete(key);\n\t\t};\n\t}\n\n\tfocusHostInlineCustomUi(): boolean {\n\t\treturn this.getHostCustomUiState().blockingInlineCustomUiActive;\n\t}\n\n\trequestRender(): void {\n\t\tfor (const [componentId, record] of this.active) {\n\t\t\tif (record.hidden === true) continue;\n\t\t\tthis.send({ type: \"engine_custom_invalidate\", componentId });\n\t\t}\n\t}\n\n\thandleLine(line: string): boolean {\n\t\tconst command = parseInteractiveEngineCommand(line);\n\t\tif (!command) return false;\n\t\tif (!command.type.startsWith(\"engine_custom_\")) return false;\n\t\tconst record = this.active.get(command.componentId);\n\t\tif (!record) {\n\t\t\tif (command.type === \"engine_custom_input\")\n\t\t\t\tthis.send({\n\t\t\t\t\ttype: \"engine_custom_input_result\",\n\t\t\t\t\tcomponentId: command.componentId,\n\t\t\t\t\trequestId: command.requestId,\n\t\t\t\t\thandled: false,\n\t\t\t\t});\n\t\t\treturn true;\n\t\t}\n\t\tswitch (command.type) {\n\t\t\tcase \"engine_custom_scroll\":\n\t\t\t\t(record.component as ScrollableWidgetComponent).onScroll?.(command.state);\n\t\t\t\tbreak;\n\t\t\tcase \"engine_custom_render\":\n\t\t\t\trecord.terminal.columns = Math.max(1, command.width);\n\t\t\t\trecord.terminal.rows = Math.max(1, command.rows);\n\t\t\t\tvoid runCallback({ kind: \"renderer\", name: command.componentId }, () =>\n\t\t\t\t\trecord.component.render(record.terminal.columns),\n\t\t\t\t)\n\t\t\t\t\t.then((lines) => {\n\t\t\t\t\t\tconst scrollRequest = (record.component as ScrollableWidgetComponent).getScrollRequest?.();\n\t\t\t\t\t\tthis.send({\n\t\t\t\t\t\t\ttype: \"engine_custom_frame\",\n\t\t\t\t\t\t\tcomponentId: command.componentId,\n\t\t\t\t\t\t\trequestId: command.requestId,\n\t\t\t\t\t\t\tlines,\n\t\t\t\t\t\t\t...(scrollRequest ? { scrollRequest } : {}),\n\t\t\t\t\t\t});\n\t\t\t\t\t})\n\t\t\t\t\t.catch((error: Error) =>\n\t\t\t\t\t\tthis.send({\n\t\t\t\t\t\t\ttype: \"engine_custom_frame\",\n\t\t\t\t\t\t\tcomponentId: command.componentId,\n\t\t\t\t\t\t\trequestId: command.requestId,\n\t\t\t\t\t\t\tlines: [`Remote component render failed: ${error.message}`],\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\tcase \"engine_custom_input\":\n\t\t\t\tvoid runCallback({ kind: \"renderer\", name: command.componentId }, () => {\n\t\t\t\t\tif (isKeyRelease(command.data) && record.component.wantsKeyRelease !== true) return false;\n\t\t\t\t\tconst handleInput = record.component.handleInput as ((data: string) => boolean | undefined) | undefined;\n\t\t\t\t\treturn handleInput?.call(record.component, command.data) === true;\n\t\t\t\t})\n\t\t\t\t\t.then((handled) =>\n\t\t\t\t\t\tthis.send({\n\t\t\t\t\t\t\ttype: \"engine_custom_input_result\",\n\t\t\t\t\t\t\tcomponentId: command.componentId,\n\t\t\t\t\t\t\trequestId: command.requestId,\n\t\t\t\t\t\t\thandled,\n\t\t\t\t\t\t}),\n\t\t\t\t\t)\n\t\t\t\t\t.catch(() =>\n\t\t\t\t\t\tthis.send({\n\t\t\t\t\t\t\ttype: \"engine_custom_input_result\",\n\t\t\t\t\t\t\tcomponentId: command.componentId,\n\t\t\t\t\t\t\trequestId: command.requestId,\n\t\t\t\t\t\t\thandled: false,\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\tcase \"engine_custom_copy_result\":\n\t\t\t\trecord.terminal.resolveCopy(command.requestId, command.error);\n\t\t\t\tbreak;\n\t\t\tcase \"engine_custom_dispose\":\n\t\t\t\tthis.disposeComponent(command.componentId, true);\n\t\t\t\tbreak;\n\t\t}\n\t\treturn true;\n\t}\n\n\tdispose(): void {\n\t\tfor (const componentId of [...this.active.keys()]) this.disposeComponent(componentId, true, false);\n\t}\n\tprivate disposeComponent(componentId: string, resolve: boolean, notifyWidgetRelease = true): void {\n\t\tconst record = this.active.get(componentId);\n\t\tif (!record) return;\n\t\tthis.active.delete(componentId);\n\t\trecord.terminal.close();\n\t\t// Claim cancellation before user disposal code can call done() reentrantly.\n\t\tif (resolve) record.resolve(undefined);\n\t\trecord.component.dispose?.();\n\t\trecord.tui.stop();\n\t\tif (record.widgetKey) {\n\t\t\tif (this.widgetIds.get(record.widgetKey) === componentId) this.widgetIds.delete(record.widgetKey);\n\t\t\tthis.send({ type: \"engine_custom_close\", componentId });\n\t\t\tif (notifyWidgetRelease) this.notifyWidgetRelease(record.widgetKey);\n\t\t}\n\t\tthis.notifyState();\n\t}\n\tprivate notifyWidgetRelease(key: string): void {\n\t\tfor (const listener of this.widgetReleaseListeners.get(key) ?? []) {\n\t\t\ttry {\n\t\t\t\tlistener();\n\t\t\t} catch {\n\t\t\t\t// A release observer must not break engine UI teardown.\n\t\t\t}\n\t\t}\n\t}\n\tprivate notifyState(): void {\n\t\tconst state = this.getHostCustomUiState();\n\t\tfor (const listener of this.stateListeners) listener(state);\n\t}\n\n\tprivate remoteHandle(componentId: string): OverlayHandle {\n\t\tlet focused = true;\n\t\tconst setHiddenFlag = (value: boolean): void => {\n\t\t\tconst record = this.active.get(componentId);\n\t\t\tif (record) record.hidden = value;\n\t\t};\n\t\treturn {\n\t\t\thide: () => {\n\t\t\t\tsetHiddenFlag(true);\n\t\t\t\tthis.send({ type: \"engine_custom_control\", componentId, action: \"hide\" });\n\t\t\t},\n\t\t\tsetHidden: (value) => {\n\t\t\t\tsetHiddenFlag(value);\n\t\t\t\tthis.send({ type: \"engine_custom_control\", componentId, action: value ? \"hide\" : \"show\" });\n\t\t\t},\n\t\t\tisHidden: () => this.active.get(componentId)?.hidden === true,\n\t\t\tfocus: () => {\n\t\t\t\tfocused = true;\n\t\t\t\tthis.send({ type: \"engine_custom_control\", componentId, action: \"focus\" });\n\t\t\t},\n\t\t\tunfocus: () => {\n\t\t\t\tfocused = false;\n\t\t\t\tthis.send({ type: \"engine_custom_control\", componentId, action: \"unfocus\" });\n\t\t\t},\n\t\t\tisFocused: () => focused,\n\t\t\tgetBounds: () => undefined,\n\t\t};\n\t}\n\n\tprivate sendDone<T>(componentId: string, result: T): void {\n\t\tthis.send({\n\t\t\ttype: \"engine_custom_done\",\n\t\t\tcomponentId,\n\t\t\tresult: jsonResult(result as object | boolean | null | number | string | undefined),\n\t\t});\n\t}\n\n\tprivate send(message: InteractiveEngineMessage): void {\n\t\tthis.write(serializeInteractiveEngineMessage(message));\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"engine-render-service.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive-engine/engine-render-service.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAsDhE,qBAAa,mBAAmB;IAC/B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAmC;IAC3D,OAAO,CAAC,OAAO,CAA2B;IAC1C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAyB;IAE/C,YAAY,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,EAExC;IAED,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,CAGvC;IAED,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAgChC;IAED,OAAO,IAAI,IAAI,CAEd;IAED,OAAO,CAAC,YAAY;IAMpB,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,UAAU;IAuClB,OAAO,CAAC,aAAa;IA0BrB,OAAO,CAAC,aAAa;IAQrB,OAAO,CAAC,IAAI;CAGZ"}
1
+ {"version":3,"file":"engine-render-service.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive-engine/engine-render-service.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAuDhE,qBAAa,mBAAmB;IAC/B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAmC;IAC3D,OAAO,CAAC,OAAO,CAA2B;IAC1C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAyB;IAE/C,YAAY,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,EAExC;IAED,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,CAGvC;IAED,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAgChC;IAED,OAAO,IAAI,IAAI,CAEd;IAED,OAAO,CAAC,YAAY;IAMpB,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,UAAU;IA6ClB,OAAO,CAAC,aAAa;IA8BrB,OAAO,CAAC,aAAa;IAQrB,OAAO,CAAC,IAAI;CAGZ"}
@@ -1,6 +1,7 @@
1
1
  import { TuiMainScreen } from "@earendil-works/pi-tui";
2
2
  import { getAgentDir } from "../../config.js";
3
3
  import { runCallback } from "../../core/callback-activity.js";
4
+ import { ensurePngTranscoder } from "../../utils/image-convert.js";
4
5
  import { CustomMessageComponent } from "../interactive/components/custom-message.js";
5
6
  import { ToolExecutionComponent } from "../interactive/components/tool-execution.js";
6
7
  import { parseInteractiveEngineCommand, serializeInteractiveEngineMessage, } from "./protocol.js";
@@ -89,7 +90,11 @@ export class EngineRenderService {
89
90
  const terminal = this.createTerminal(command.componentId);
90
91
  terminal.columns = Math.max(1, command.width);
91
92
  const tui = new TuiMainScreen(terminal, undefined, getAgentDir());
92
- const component = new ToolExecutionComponent(command.toolName, command.toolCallId, command.args, { showImages: command.showImages, imageWidthCells: command.imageWidthCells }, session.getToolDefinition(command.toolName), tui, session.sessionManager.getCwd());
93
+ ensurePngTranscoder(() => {
94
+ tui.invalidate();
95
+ tui.requestRender();
96
+ });
97
+ const component = new ToolExecutionComponent(command.toolName, command.toolCallId, command.args, { showImages: command.showImages, imageWidthCells: command.imageWidthCells }, session.extensionRunner.resolveToolRenderers(command.toolName, () => session.getToolDefinition(command.toolName)), tui, session.sessionManager.getCwd());
93
98
  tui.addChild(component);
94
99
  record = { kind: "tool", component, terminal, tui };
95
100
  this.records.set(command.componentId, record);
@@ -119,6 +124,10 @@ export class EngineRenderService {
119
124
  const terminal = this.createTerminal(command.componentId);
120
125
  terminal.columns = Math.max(1, command.width);
121
126
  const tui = new TuiMainScreen(terminal, undefined, getAgentDir());
127
+ ensurePngTranscoder(() => {
128
+ tui.invalidate();
129
+ tui.requestRender();
130
+ });
122
131
  const message = command.message;
123
132
  const component = new CustomMessageComponent(message, session.extensionRunner.getMessageRenderer(message.customType), undefined, command.outputPad);
124
133
  tui.addChild(component);
@@ -1 +1 @@
1
- {"version":3,"file":"engine-render-service.js","sourceRoot":"","sources":["../../../src/modes/interactive-engine/engine-render-service.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAE9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,6CAA6C,CAAC;AACrF,OAAO,EAAE,sBAAsB,EAAE,MAAM,6CAA6C,CAAC;AACrF,OAAO,EAGN,6BAA6B,EAC7B,iCAAiC,GACjC,MAAM,eAAe,CAAC;AAoBvB,MAAM,cAAc;IACnB,OAAO,GAAG,EAAE,CAAC;IACb,IAAI,GAAG,EAAE,CAAC;IACV,mBAAmB,GAAG,KAAK,CAAC;IACX,aAAa,CAAa;IAC3C,YAAY,aAAyB;QACpC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACpC,CAAC;IACD,KAAK,KAAU,CAAC;IAChB,IAAI,KAAU,CAAC;IACf,KAAK,CAAC,UAAU,KAAmB,CAAC;IACpC,KAAK;QACJ,IAAI,CAAC,aAAa,EAAE,CAAC;IACtB,CAAC;IACD,MAAM,KAAU,CAAC;IACjB,UAAU,KAAU,CAAC;IACrB,UAAU,KAAU,CAAC;IACrB,SAAS,KAAU,CAAC;IACpB,eAAe,KAAU,CAAC;IAC1B,WAAW,KAAU,CAAC;IACtB,QAAQ,KAAU,CAAC;IACnB,WAAW,KAAU,CAAC;CACtB;AAED,MAAM,OAAO,mBAAmB;IACd,OAAO,GAAG,IAAI,GAAG,EAAwB,CAAC;IACnD,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I,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC;YACvD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;QAC/C,CAAC;aAAM,CAAC;YACP,MAAM,CAAC,QAAQ,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;QACtD,CAAC;QACD,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAC/C,MAAM,CAAC,SAAS,CAAC,YAAY,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QACjD,OAAO,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC/C,CAAC;IAEO,aAAa,CAAC,EAAU;QAC/B,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACpC,IAAI,CAAC,MAAM;YAAE,OAAO;QACpB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACxB,IAAI,MAAM,CAAC,IAAI,KAAK,MAAM;YAAE,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;QACvD,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;IACnB,CAAC;IAEO,IAAI,CAAC,OAAiC;QAC7C,IAAI,CAAC,KAAK,CAAC,iCAAiC,CAAC,OAAO,CAAC,CAAC,CAAC;IACxD,CAAC;CACD","sourcesContent":["import type { Terminal } from \"@earendil-works/pi-tui\";\nimport { type TUI, TuiMainScreen } from \"@earendil-works/pi-tui\";\nimport { getAgentDir } from \"../../config.js\";\nimport type { AgentSession } from \"../../core/agent-session.js\";\nimport { runCallback } from \"../../core/callback-activity.ts\";\nimport type { CustomMessage } from \"../../core/messages.ts\";\nimport { CustomMessageComponent } from \"../interactive/components/custom-message.ts\";\nimport { ToolExecutionComponent } from \"../interactive/components/tool-execution.ts\";\nimport {\n\ttype InteractiveEngineCommand,\n\ttype InteractiveEngineMessage,\n\tparseInteractiveEngineCommand,\n\tserializeInteractiveEngineMessage,\n} from \"./protocol.ts\";\n\ntype ToolRenderCommand = Extract<InteractiveEngineCommand, { type: \"engine_tool_render\" }>;\ntype MessageRenderCommand = Extract<InteractiveEngineCommand, { type: \"engine_message_render\" }>;\n\n/**\n * Cached per-componentId render state. Records are REUSED across render\n * requests: recreating (and re-seeding) the component on every request made\n * the seeding setters call `ui.requestRender()` each time, whose eventual\n * terminal write emitted `engine_custom_invalidate` back to the host, which\n * re-sent the render request — a self-sustaining host⇄engine render\n * ping-pong that presented as full-screen TUI flicker (quit/pause while a\n * workflow stage streams). Reuse plus idempotent seeding setters lets the\n * loop converge after at most one round trip while still forwarding\n * legitimate async invalidations (e.g. image conversion).\n */\ntype RenderRecord =\n\t| { kind: \"message\"; component: CustomMessageComponent; terminal: RenderTerminal; tui: TUI }\n\t| { kind: \"tool\"; component: ToolExecutionComponent; terminal: RenderTerminal; tui: TUI };\n\nclass RenderTerminal implements Terminal {\n\tcolumns = 80;\n\trows = 24;\n\tkittyProtocolActive = false;\n\tprivate readonly requestRender: () => void;\n\tconstructor(requestRender: () => void) {\n\t\tthis.requestRender = requestRender;\n\t}\n\tstart(): void {}\n\tstop(): void {}\n\tasync drainInput(): Promise<void> {}\n\twrite(): void {\n\t\tthis.requestRender();\n\t}\n\tmoveBy(): void {}\n\thideCursor(): void {}\n\tshowCursor(): void {}\n\tclearLine(): void {}\n\tclearFromCursor(): void {}\n\tclearScreen(): void {}\n\tsetTitle(): void {}\n\tsetProgress(): void {}\n}\n\nexport class EngineRenderService {\n\tprivate readonly records = new Map<string, RenderRecord>();\n\tprivate session: AgentSession | undefined;\n\tprivate readonly write: (line: string) => void;\n\n\tconstructor(write: (line: string) => void) {\n\t\tthis.write = write;\n\t}\n\n\tbindSession(session: AgentSession): void {\n\t\tthis.dispose();\n\t\tthis.session = session;\n\t}\n\n\thandleLine(line: string): boolean {\n\t\tconst command = parseInteractiveEngineCommand(line);\n\t\tif (!command?.type.startsWith(\"engine_\") || command.type.startsWith(\"engine_custom_\")) return false;\n\t\tif (command.type === \"engine_render_dispose\") {\n\t\t\tthis.disposeRecord(command.componentId);\n\t\t\treturn true;\n\t\t}\n\t\tif (command.type !== \"engine_tool_render\" && command.type !== \"engine_message_render\") return false;\n\t\tconst name =\n\t\t\tcommand.type === \"engine_tool_render\"\n\t\t\t\t? `tool:${command.toolName}`\n\t\t\t\t: `message:${command.message.customType ?? \"custom\"}`;\n\t\tvoid runCallback({ kind: \"renderer\", name }, async () => {\n\t\t\treturn command.type === \"engine_tool_render\" ? this.renderTool(command) : this.renderMessage(command);\n\t\t})\n\t\t\t.then((lines) =>\n\t\t\t\tthis.send({\n\t\t\t\t\ttype: \"engine_custom_frame\",\n\t\t\t\t\tcomponentId: command.componentId,\n\t\t\t\t\trequestId: command.requestId,\n\t\t\t\t\tlines,\n\t\t\t\t}),\n\t\t\t)\n\t\t\t.catch((error: Error) =>\n\t\t\t\tthis.send({\n\t\t\t\t\ttype: \"engine_custom_frame\",\n\t\t\t\t\tcomponentId: command.componentId,\n\t\t\t\t\trequestId: command.requestId,\n\t\t\t\t\tlines: [`Remote renderer failed: ${error.message}`],\n\t\t\t\t}),\n\t\t\t);\n\t\treturn true;\n\t}\n\n\tdispose(): void {\n\t\tfor (const id of [...this.records.keys()]) this.disposeRecord(id);\n\t}\n\n\tprivate boundSession(): AgentSession {\n\t\tconst session = this.session;\n\t\tif (!session) throw new Error(\"Renderer session is not bound\");\n\t\treturn session;\n\t}\n\n\tprivate createTerminal(componentId: string): RenderTerminal {\n\t\treturn new RenderTerminal(() => this.send({ type: \"engine_custom_invalidate\", componentId }));\n\t}\n\n\tprivate renderTool(command: ToolRenderCommand): string[] {\n\t\tlet record = this.records.get(command.componentId);\n\t\tif (record?.kind !== \"tool\") {\n\t\t\tconst session = this.boundSession();\n\t\t\tthis.disposeRecord(command.componentId);\n\t\t\tconst terminal = this.createTerminal(command.componentId);\n\t\t\tterminal.columns = Math.max(1, command.width);\n\t\t\tconst tui = new TuiMainScreen(terminal, undefined, getAgentDir());\n\t\t\tconst component = new ToolExecutionComponent(\n\t\t\t\tcommand.toolName,\n\t\t\t\tcommand.toolCallId,\n\t\t\t\tcommand.args,\n\t\t\t\t{ showImages: command.showImages, imageWidthCells: command.imageWidthCells },\n\t\t\t\tsession.getToolDefinition(command.toolName),\n\t\t\t\ttui,\n\t\t\t\tsession.sessionManager.getCwd(),\n\t\t\t);\n\t\t\ttui.addChild(component);\n\t\t\trecord = { kind: \"tool\", component, terminal, tui };\n\t\t\tthis.records.set(command.componentId, record);\n\t\t} else {\n\t\t\trecord.terminal.columns = Math.max(1, command.width);\n\t\t\trecord.component.updateArgs(command.args);\n\t\t\trecord.component.setShowImages(command.showImages);\n\t\t\trecord.component.setImageWidthCells(command.imageWidthCells);\n\t\t}\n\t\tconst tool = record.component;\n\t\tif (command.executionStarted) tool.markExecutionStarted();\n\t\tif (command.argsComplete) tool.setArgsComplete();\n\t\ttool.setExpanded(command.expanded);\n\t\tif (command.result) {\n\t\t\ttool.updateResult(\n\t\t\t\tcommand.result as unknown as Parameters<ToolExecutionComponent[\"updateResult\"]>[0],\n\t\t\t\tcommand.isPartial,\n\t\t\t);\n\t\t}\n\t\treturn tool.render(command.width);\n\t}\n\n\tprivate renderMessage(command: MessageRenderCommand): string[] {\n\t\tlet record = this.records.get(command.componentId);\n\t\tif (record?.kind !== \"message\") {\n\t\t\tconst session = this.boundSession();\n\t\t\tthis.disposeRecord(command.componentId);\n\t\t\tconst terminal = this.createTerminal(command.componentId);\n\t\t\tterminal.columns = Math.max(1, command.width);\n\t\t\tconst tui = new TuiMainScreen(terminal, undefined, getAgentDir());\n\t\t\tconst message = command.message as unknown as CustomMessage<object>;\n\t\t\tconst component = new CustomMessageComponent(\n\t\t\t\tmessage,\n\t\t\t\tsession.extensionRunner.getMessageRenderer(message.customType),\n\t\t\t\tundefined,\n\t\t\t\tcommand.outputPad,\n\t\t\t);\n\t\t\ttui.addChild(component);\n\t\t\trecord = { kind: \"message\", component, terminal, tui };\n\t\t\tthis.records.set(command.componentId, record);\n\t\t} else {\n\t\t\trecord.terminal.columns = Math.max(1, command.width);\n\t\t}\n\t\trecord.component.setExpanded(command.expanded);\n\t\trecord.component.setOutputPad(command.outputPad);\n\t\treturn record.component.render(command.width);\n\t}\n\n\tprivate disposeRecord(id: string): void {\n\t\tconst record = this.records.get(id);\n\t\tif (!record) return;\n\t\tthis.records.delete(id);\n\t\tif (record.kind === \"tool\") record.component.dispose();\n\t\trecord.tui.stop();\n\t}\n\n\tprivate send(message: InteractiveEngineMessage): void {\n\t\tthis.write(serializeInteractiveEngineMessage(message));\n\t}\n}\n"]}
1
+ {"version":3,"file":"engine-render-service.js","sourceRoot":"","sources":["../../../src/modes/interactive-engine/engine-render-service.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAE9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAE,MAAM,6CAA6C,CAAC;AACrF,OAAO,EAAE,sBAAsB,EAAE,MAAM,6CAA6C,CAAC;AACrF,OAAO,EAGN,6BAA6B,EAC7B,iCAAiC,GACjC,MAAM,eAAe,CAAC;AAoBvB,MAAM,cAAc;IACnB,OAAO,GAAG,EAAE,CAAC;IACb,IAAI,GAAG,EAAE,CAAC;IACV,mBAAmB,GAAG,KAAK,CAAC;IACX,aAAa,CAAa;IAC3C,YAAY,aAAyB;QACpC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACpC,CAAC;IACD,KAAK,KAAU,CAAC;IAChB,IAAI,KAAU,CA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AAC;IAC/C,CAAC;IAEO,aAAa,CAAC,EAAU;QAC/B,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACpC,IAAI,CAAC,MAAM;YAAE,OAAO;QACpB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACxB,IAAI,MAAM,CAAC,IAAI,KAAK,MAAM;YAAE,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;QACvD,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;IACnB,CAAC;IAEO,IAAI,CAAC,OAAiC;QAC7C,IAAI,CAAC,KAAK,CAAC,iCAAiC,CAAC,OAAO,CAAC,CAAC,CAAC;IACxD,CAAC;CACD","sourcesContent":["import type { Terminal } from \"@earendil-works/pi-tui\";\nimport { type TUI, TuiMainScreen } from \"@earendil-works/pi-tui\";\nimport { getAgentDir } from \"../../config.js\";\nimport type { AgentSession } from \"../../core/agent-session.js\";\nimport { runCallback } from \"../../core/callback-activity.ts\";\nimport type { CustomMessage } from \"../../core/messages.ts\";\nimport { ensurePngTranscoder } from \"../../utils/image-convert.ts\";\nimport { CustomMessageComponent } from \"../interactive/components/custom-message.ts\";\nimport { ToolExecutionComponent } from \"../interactive/components/tool-execution.ts\";\nimport {\n\ttype InteractiveEngineCommand,\n\ttype InteractiveEngineMessage,\n\tparseInteractiveEngineCommand,\n\tserializeInteractiveEngineMessage,\n} from \"./protocol.ts\";\n\ntype ToolRenderCommand = Extract<InteractiveEngineCommand, { type: \"engine_tool_render\" }>;\ntype MessageRenderCommand = Extract<InteractiveEngineCommand, { type: \"engine_message_render\" }>;\n\n/**\n * Cached per-componentId render state. Records are REUSED across render\n * requests: recreating (and re-seeding) the component on every request made\n * the seeding setters call `ui.requestRender()` each time, whose eventual\n * terminal write emitted `engine_custom_invalidate` back to the host, which\n * re-sent the render request — a self-sustaining host⇄engine render\n * ping-pong that presented as full-screen TUI flicker (quit/pause while a\n * workflow stage streams). Reuse plus idempotent seeding setters lets the\n * loop converge after at most one round trip while still forwarding\n * legitimate async invalidations (e.g. image conversion).\n */\ntype RenderRecord =\n\t| { kind: \"message\"; component: CustomMessageComponent; terminal: RenderTerminal; tui: TUI }\n\t| { kind: \"tool\"; component: ToolExecutionComponent; terminal: RenderTerminal; tui: TUI };\n\nclass RenderTerminal implements Terminal {\n\tcolumns = 80;\n\trows = 24;\n\tkittyProtocolActive = false;\n\tprivate readonly requestRender: () => void;\n\tconstructor(requestRender: () => void) {\n\t\tthis.requestRender = requestRender;\n\t}\n\tstart(): void {}\n\tstop(): void {}\n\tasync drainInput(): Promise<void> {}\n\twrite(): void {\n\t\tthis.requestRender();\n\t}\n\tmoveBy(): void {}\n\thideCursor(): void {}\n\tshowCursor(): void {}\n\tclearLine(): void {}\n\tclearFromCursor(): void {}\n\tclearScreen(): void {}\n\tsetTitle(): void {}\n\tsetProgress(): void {}\n}\n\nexport class EngineRenderService {\n\tprivate readonly records = new Map<string, RenderRecord>();\n\tprivate session: AgentSession | undefined;\n\tprivate readonly write: (line: string) => void;\n\n\tconstructor(write: (line: string) => void) {\n\t\tthis.write = write;\n\t}\n\n\tbindSession(session: AgentSession): void {\n\t\tthis.dispose();\n\t\tthis.session = session;\n\t}\n\n\thandleLine(line: string): boolean {\n\t\tconst command = parseInteractiveEngineCommand(line);\n\t\tif (!command?.type.startsWith(\"engine_\") || command.type.startsWith(\"engine_custom_\")) return false;\n\t\tif (command.type === \"engine_render_dispose\") {\n\t\t\tthis.disposeRecord(command.componentId);\n\t\t\treturn true;\n\t\t}\n\t\tif (command.type !== \"engine_tool_render\" && command.type !== \"engine_message_render\") return false;\n\t\tconst name =\n\t\t\tcommand.type === \"engine_tool_render\"\n\t\t\t\t? `tool:${command.toolName}`\n\t\t\t\t: `message:${command.message.customType ?? \"custom\"}`;\n\t\tvoid runCallback({ kind: \"renderer\", name }, async () => {\n\t\t\treturn command.type === \"engine_tool_render\" ? this.renderTool(command) : this.renderMessage(command);\n\t\t})\n\t\t\t.then((lines) =>\n\t\t\t\tthis.send({\n\t\t\t\t\ttype: \"engine_custom_frame\",\n\t\t\t\t\tcomponentId: command.componentId,\n\t\t\t\t\trequestId: command.requestId,\n\t\t\t\t\tlines,\n\t\t\t\t}),\n\t\t\t)\n\t\t\t.catch((error: Error) =>\n\t\t\t\tthis.send({\n\t\t\t\t\ttype: \"engine_custom_frame\",\n\t\t\t\t\tcomponentId: command.componentId,\n\t\t\t\t\trequestId: command.requestId,\n\t\t\t\t\tlines: [`Remote renderer failed: ${error.message}`],\n\t\t\t\t}),\n\t\t\t);\n\t\treturn true;\n\t}\n\n\tdispose(): void {\n\t\tfor (const id of [...this.records.keys()]) this.disposeRecord(id);\n\t}\n\n\tprivate boundSession(): AgentSession {\n\t\tconst session = this.session;\n\t\tif (!session) throw new Error(\"Renderer session is not bound\");\n\t\treturn session;\n\t}\n\n\tprivate createTerminal(componentId: string): RenderTerminal {\n\t\treturn new RenderTerminal(() => this.send({ type: \"engine_custom_invalidate\", componentId }));\n\t}\n\n\tprivate renderTool(command: ToolRenderCommand): string[] {\n\t\tlet record = this.records.get(command.componentId);\n\t\tif (record?.kind !== \"tool\") {\n\t\t\tconst session = this.boundSession();\n\t\t\tthis.disposeRecord(command.componentId);\n\t\t\tconst terminal = this.createTerminal(command.componentId);\n\t\t\tterminal.columns = Math.max(1, command.width);\n\t\t\tconst tui = new TuiMainScreen(terminal, undefined, getAgentDir());\n\t\t\tensurePngTranscoder(() => {\n\t\t\t\ttui.invalidate();\n\t\t\t\ttui.requestRender();\n\t\t\t});\n\t\t\tconst component = new ToolExecutionComponent(\n\t\t\t\tcommand.toolName,\n\t\t\t\tcommand.toolCallId,\n\t\t\t\tcommand.args,\n\t\t\t\t{ showImages: command.showImages, imageWidthCells: command.imageWidthCells },\n\t\t\t\tsession.extensionRunner.resolveToolRenderers(command.toolName, () =>\n\t\t\t\t\tsession.getToolDefinition(command.toolName),\n\t\t\t\t),\n\t\t\t\ttui,\n\t\t\t\tsession.sessionManager.getCwd(),\n\t\t\t);\n\t\t\ttui.addChild(component);\n\t\t\trecord = { kind: \"tool\", component, terminal, tui };\n\t\t\tthis.records.set(command.componentId, record);\n\t\t} else {\n\t\t\trecord.terminal.columns = Math.max(1, command.width);\n\t\t\trecord.component.updateArgs(command.args);\n\t\t\trecord.component.setShowImages(command.showImages);\n\t\t\trecord.component.setImageWidthCells(command.imageWidthCells);\n\t\t}\n\t\tconst tool = record.component;\n\t\tif (command.executionStarted) tool.markExecutionStarted();\n\t\tif (command.argsComplete) tool.setArgsComplete();\n\t\ttool.setExpanded(command.expanded);\n\t\tif (command.result) {\n\t\t\ttool.updateResult(\n\t\t\t\tcommand.result as unknown as Parameters<ToolExecutionComponent[\"updateResult\"]>[0],\n\t\t\t\tcommand.isPartial,\n\t\t\t);\n\t\t}\n\t\treturn tool.render(command.width);\n\t}\n\n\tprivate renderMessage(command: MessageRenderCommand): string[] {\n\t\tlet record = this.records.get(command.componentId);\n\t\tif (record?.kind !== \"message\") {\n\t\t\tconst session = this.boundSession();\n\t\t\tthis.disposeRecord(command.componentId);\n\t\t\tconst terminal = this.createTerminal(command.componentId);\n\t\t\tterminal.columns = Math.max(1, command.width);\n\t\t\tconst tui = new TuiMainScreen(terminal, undefined, getAgentDir());\n\t\t\tensurePngTranscoder(() => {\n\t\t\t\ttui.invalidate();\n\t\t\t\ttui.requestRender();\n\t\t\t});\n\t\t\tconst message = command.message as unknown as CustomMessage<object>;\n\t\t\tconst component = new CustomMessageComponent(\n\t\t\t\tmessage,\n\t\t\t\tsession.extensionRunner.getMessageRenderer(message.customType),\n\t\t\t\tundefined,\n\t\t\t\tcommand.outputPad,\n\t\t\t);\n\t\t\ttui.addChild(component);\n\t\t\trecord = { kind: \"message\", component, terminal, tui };\n\t\t\tthis.records.set(command.componentId, record);\n\t\t} else {\n\t\t\trecord.terminal.columns = Math.max(1, command.width);\n\t\t}\n\t\trecord.component.setExpanded(command.expanded);\n\t\trecord.component.setOutputPad(command.outputPad);\n\t\treturn record.component.render(command.width);\n\t}\n\n\tprivate disposeRecord(id: string): void {\n\t\tconst record = this.records.get(id);\n\t\tif (!record) return;\n\t\tthis.records.delete(id);\n\t\tif (record.kind === \"tool\") record.component.dispose();\n\t\trecord.tui.stop();\n\t}\n\n\tprivate send(message: InteractiveEngineMessage): void {\n\t\tthis.write(serializeInteractiveEngineMessage(message));\n\t}\n}\n"]}
@@ -1,3 +1,4 @@
1
+ import { type ImageTranscoder } from "@earendil-works/pi-tui";
1
2
  export declare function convertImageBytesToPng(bytes: Uint8Array): Promise<Uint8Array | null>;
2
3
  /**
3
4
  * Convert image to PNG format for terminal display.
@@ -7,4 +8,8 @@ export declare function convertToPng(base64Data: string, mimeType: string): Prom
7
8
  data: string;
8
9
  mimeType: string;
9
10
  } | null>;
11
+ /** Load photon once and return a synchronous PNG transcoder for Kitty image rendering. */
12
+ export declare function loadPngTranscoder(): Promise<ImageTranscoder | undefined>;
13
+ /** Register the PNG transcoder on Kitty terminals, then redraw callers' fallback images. */
14
+ export declare function ensurePngTranscoder(onRegistered: () => void): void;
10
15
  //# sourceMappingURL=image-convert.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"image-convert.d.ts","sourceRoot":"","sources":["../../src/utils/image-convert.ts"],"names":[],"mappings":"AAGA,wBAAsB,sBAAsB,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAoB1F;AAED;;;GAGG;AACH,wBAAsB,YAAY,CACjC,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,GACd,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,CAgBpD"}
1
+ {"version":3,"file":"image-convert.d.ts","sourceRoot":"","sources":["../../src/utils/image-convert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,eAAe,EAAsB,MAAM,wBAAwB,CAAC;AAsBnG,wBAAsB,sBAAsB,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAI1F;AAED;;;GAGG;AACH,wBAAsB,YAAY,CACjC,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,GACd,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,CAgBpD;AAED,0FAA0F;AAC1F,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC,CAO9E;AAKD,4FAA4F;AAC5F,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,MAAM,IAAI,GAAG,IAAI,CAWlE"}
@@ -1,11 +1,7 @@
1
+ import { getCapabilities, setImageTranscoder } from "@earendil-works/pi-tui";
1
2
  import { applyExifOrientation } from "./exif-orientation.js";
2
3
  import { loadPhoton } from "./photon.js";
3
- export async function convertImageBytesToPng(bytes) {
4
- const photon = await loadPhoton();
5
- if (!photon) {
6
- // Photon not available, can't convert
7
- return null;
8
- }
4
+ function encodePng(photon, bytes) {
9
5
  try {
10
6
  const rawImage = photon.PhotonImage.new_from_byteslice(bytes);
11
7
  const image = applyExifOrientation(photon, rawImage, bytes);
@@ -23,6 +19,12 @@ export async function convertImageBytesToPng(bytes) {
23
19
  return null;
24
20
  }
25
21
  }
22
+ export async function convertImageBytesToPng(bytes) {
23
+ const photon = await loadPhoton();
24
+ if (!photon)
25
+ return null;
26
+ return encodePng(photon, bytes);
27
+ }
26
28
  /**
27
29
  * Convert image to PNG format for terminal display.
28
30
  * Kitty graphics protocol requires PNG format (f=100).
@@ -42,4 +44,32 @@ export async function convertToPng(base64Data, mimeType) {
42
44
  mimeType: "image/png",
43
45
  };
44
46
  }
47
+ /** Load photon once and return a synchronous PNG transcoder for Kitty image rendering. */
48
+ export async function loadPngTranscoder() {
49
+ const photon = await loadPhoton();
50
+ if (!photon)
51
+ return undefined;
52
+ return (base64Data) => {
53
+ const pngBytes = encodePng(photon, new Uint8Array(Buffer.from(base64Data, "base64")));
54
+ return pngBytes ? Buffer.from(pngBytes).toString("base64") : null;
55
+ };
56
+ }
57
+ let pngTranscoderLoad;
58
+ let pngTranscoderRegistered = false;
59
+ /** Register the PNG transcoder on Kitty terminals, then redraw callers' fallback images. */
60
+ export function ensurePngTranscoder(onRegistered) {
61
+ if (pngTranscoderRegistered || getCapabilities().images !== "kitty")
62
+ return;
63
+ pngTranscoderLoad ??= loadPngTranscoder().then((transcoder) => {
64
+ if (!transcoder)
65
+ return false;
66
+ setImageTranscoder(transcoder);
67
+ pngTranscoderRegistered = true;
68
+ return true;
69
+ });
70
+ void pngTranscoderLoad.then((registered) => {
71
+ if (registered)
72
+ onRegistered();
73
+ });
74
+ }
45
75
  //# sourceMappingURL=image-convert.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"image-convert.js","sourceRoot":"","sources":["../../src/utils/image-convert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,KAAiB;IAC7D,MAAM,MAAM,GAAG,MAAM,UAAU,EAAE,CAAC;IAClC,IAAI,CAAC,MAAM,EAAE,CAAC;QACb,sCAAsC;QACtC,OAAO,IAAI,CAAC;IACb,CAAC;IAED,IAAI,CAAC;QACJ,MAAM,QAAQ,GAAG,MAAM,CAAC,WAAW,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;QAC9D,MAAM,KAAK,GAAG,oBAAoB,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;QAC5D,IAAI,KAAK,KAAK,QAAQ;YAAE,QAAQ,CAAC,IAAI,EAAE,CAAC;QACxC,IAAI,CAAC;YACJ,OAAO,IAAI,UAAU,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC;QAC1C,CAAC;gBAAS,CAAC;YACV,KAAK,CAAC,IAAI,EAAE,CAAC;QACd,CAAC;IACF,CAAC;IAAC,MAAM,CAAC;QACR,oBAAoB;QACpB,OAAO,IAAI,CAAC;IACb,CAAC;AACF,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CACjC,UAAkB,EAClB,QAAgB;IAEhB,oCAAoC;IACpC,IAAI,QAAQ,KAAK,WAAW,EAAE,CAAC;QAC9B,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC;IACvC,CAAC;IAED,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC;IAChE,MAAM,QAAQ,GAAG,MAAM,sBAAsB,CAAC,KAAK,CAAC,CAAC;IACrD,IAAI,CAAC,QAAQ,EAAE,CAAC;QACf,OAAO,IAAI,CAAC;IACb,CAAC;IAED,OAAO;QACN,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAC9C,QAAQ,EAAE,WAAW;KACrB,CAAC;AACH,CAAC","sourcesContent":["import { applyExifOrientation } from \"./exif-orientation.ts\";\nimport { loadPhoton } from \"./photon.ts\";\n\nexport async function convertImageBytesToPng(bytes: Uint8Array): Promise<Uint8Array | null> {\n\tconst photon = await loadPhoton();\n\tif (!photon) {\n\t\t// Photon not available, can't convert\n\t\treturn null;\n\t}\n\n\ttry {\n\t\tconst rawImage = photon.PhotonImage.new_from_byteslice(bytes);\n\t\tconst image = applyExifOrientation(photon, rawImage, bytes);\n\t\tif (image !== rawImage) rawImage.free();\n\t\ttry {\n\t\t\treturn new Uint8Array(image.get_bytes());\n\t\t} finally {\n\t\t\timage.free();\n\t\t}\n\t} catch {\n\t\t// Conversion failed\n\t\treturn null;\n\t}\n}\n\n/**\n * Convert image to PNG format for terminal display.\n * Kitty graphics protocol requires PNG format (f=100).\n */\nexport async function convertToPng(\n\tbase64Data: string,\n\tmimeType: string,\n): Promise<{ data: string; mimeType: string } | null> {\n\t// Already PNG, no conversion needed\n\tif (mimeType === \"image/png\") {\n\t\treturn { data: base64Data, mimeType };\n\t}\n\n\tconst bytes = new Uint8Array(Buffer.from(base64Data, \"base64\"));\n\tconst pngBytes = await convertImageBytesToPng(bytes);\n\tif (!pngBytes) {\n\t\treturn null;\n\t}\n\n\treturn {\n\t\tdata: Buffer.from(pngBytes).toString(\"base64\"),\n\t\tmimeType: \"image/png\",\n\t};\n}\n"]}
1
+ {"version":3,"file":"image-convert.js","sourceRoot":"","sources":["../../src/utils/image-convert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAwB,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACnG,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAIzC,SAAS,SAAS,CAAC,MAAc,EAAE,KAAiB;IACnD,IAAI,CAAC;QACJ,MAAM,QAAQ,GAAG,MAAM,CAAC,WAAW,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;QAC9D,MAAM,KAAK,GAAG,oBAAoB,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;QAC5D,IAAI,KAAK,KAAK,QAAQ;YAAE,QAAQ,CAAC,IAAI,EAAE,CAAC;QACxC,IAAI,CAAC;YACJ,OAAO,IAAI,UAAU,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC;QAC1C,CAAC;gBAAS,CAAC;YACV,KAAK,CAAC,IAAI,EAAE,CAAC;QACd,CAAC;IACF,CAAC;IAAC,MAAM,CAAC;QACR,oBAAoB;QACpB,OAAO,IAAI,CAAC;IACb,CAAC;AACF,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,KAAiB;IAC7D,MAAM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AED,IAAI,iBAA+C,CAAC;AACpD,IAAI,uBAAuB,GAAG,KAAK,CAAC;AAEpC,4FAA4F;AAC5F,MAAM,UAAU,mBAAmB,CAAC,YAAwB;IAC3D,IAAI,uBAAuB,IAAI,eAAe,EAAE,CAAC,MAAM,KAAK,OAAO;QAAE,OAAO;IAC5E,iBAAiB,KAAK,iBAAiB,EAAE,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE;QAC7D,IAAI,CAAC,UAAU;YAAE,OAAO,KAAK,CAAC;QAC9B,kBAAkB,CAAC,UAAU,CAAC,CAAC;QAC/B,uBAAuB,GAAG,IAAI,CAAC;QAC/B,OAAO,IAAI,CAAC;IACb,CAAC,CAAC,CAAC;IACH,KAAK,iBAAiB,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE;QAC1C,IAAI,UAAU;YAAE,YAAY,EAAE,CAAC;IAChC,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { getCapabilities, type ImageTranscoder, setImageTranscoder } from \"@earendil-works/pi-tui\";\nimport { applyExifOrientation } from \"./exif-orientation.ts\";\nimport { loadPhoton } from \"./photon.ts\";\n\ntype Photon = NonNullable<Awaited<ReturnType<typeof loadPhoton>>>;\n\nfunction encodePng(photon: Photon, bytes: Uint8Array): Uint8Array | null {\n\ttry {\n\t\tconst rawImage = photon.PhotonImage.new_from_byteslice(bytes);\n\t\tconst image = applyExifOrientation(photon, rawImage, bytes);\n\t\tif (image !== rawImage) rawImage.free();\n\t\ttry {\n\t\t\treturn new Uint8Array(image.get_bytes());\n\t\t} finally {\n\t\t\timage.free();\n\t\t}\n\t} catch {\n\t\t// Conversion failed\n\t\treturn null;\n\t}\n}\n\nexport async function convertImageBytesToPng(bytes: Uint8Array): Promise<Uint8Array | null> {\n\tconst photon = await loadPhoton();\n\tif (!photon) return null;\n\treturn encodePng(photon, bytes);\n}\n\n/**\n * Convert image to PNG format for terminal display.\n * Kitty graphics protocol requires PNG format (f=100).\n */\nexport async function convertToPng(\n\tbase64Data: string,\n\tmimeType: string,\n): Promise<{ data: string; mimeType: string } | null> {\n\t// Already PNG, no conversion needed\n\tif (mimeType === \"image/png\") {\n\t\treturn { data: base64Data, mimeType };\n\t}\n\n\tconst bytes = new Uint8Array(Buffer.from(base64Data, \"base64\"));\n\tconst pngBytes = await convertImageBytesToPng(bytes);\n\tif (!pngBytes) {\n\t\treturn null;\n\t}\n\n\treturn {\n\t\tdata: Buffer.from(pngBytes).toString(\"base64\"),\n\t\tmimeType: \"image/png\",\n\t};\n}\n\n/** Load photon once and return a synchronous PNG transcoder for Kitty image rendering. */\nexport async function loadPngTranscoder(): Promise<ImageTranscoder | undefined> {\n\tconst photon = await loadPhoton();\n\tif (!photon) return undefined;\n\treturn (base64Data) => {\n\t\tconst pngBytes = encodePng(photon, new Uint8Array(Buffer.from(base64Data, \"base64\")));\n\t\treturn pngBytes ? Buffer.from(pngBytes).toString(\"base64\") : null;\n\t};\n}\n\nlet pngTranscoderLoad: Promise<boolean> | undefined;\nlet pngTranscoderRegistered = false;\n\n/** Register the PNG transcoder on Kitty terminals, then redraw callers' fallback images. */\nexport function ensurePngTranscoder(onRegistered: () => void): void {\n\tif (pngTranscoderRegistered || getCapabilities().images !== \"kitty\") return;\n\tpngTranscoderLoad ??= loadPngTranscoder().then((transcoder) => {\n\t\tif (!transcoder) return false;\n\t\tsetImageTranscoder(transcoder);\n\t\tpngTranscoderRegistered = true;\n\t\treturn true;\n\t});\n\tvoid pngTranscoderLoad.then((registered) => {\n\t\tif (registered) onRegistered();\n\t});\n}\n"]}
@@ -660,6 +660,12 @@ Moved to [Writing extensions](/extensions/authoring#multiple-tools).
660
660
 
661
661
  Moved to [Writing extensions](/extensions/authoring#custom-rendering).
662
662
 
663
+ #### Tool rendering
664
+
665
+ A tool's `renderCall` and `renderResult` draw its calls in the interactive transcript and HTML exports. Use `pi.registerToolRenderer((toolName, next) => renderers)` to choose renderers for any tool, including MCP tools in resumed sessions before their server connects. Resolvers run in extension load order. `next()` returns the remaining resolvers' choice, then the registered tool's renderers, so `next() ?? mine` only fills in when none exist.
666
+
667
+ Extension `Image` components render JPEG, GIF, and WebP images on Kitty-protocol terminals automatically, just like tool result images.
668
+
663
669
  #### renderCall
664
670
 
665
671
  Moved to [Writing extensions](/extensions/authoring#rendercall).
@@ -81,7 +81,19 @@ Send material updates through Intercom to every affected workflow stage, includi
81
81
 
82
82
  Name and pattern paths remain sticky for every future matching stage until the root terminates. When shared scope or acceptance criteria change, broadcast one authoritative update to `workflow:<rootRunId>/**` (or a narrower path pattern) rather than enumerating stages: `**` reaches every live stage now and every future descendant. A syntactically valid path outside the persisted known set still queues and returns `notInKnownSet`; if it never delivers, root-terminal settlement sends the correlated undeliverable notification. A sticky entry delivered at least once is not reported undeliverable.
83
83
 
84
- The workflows extension persists up to **50 queued messages per target** with workflow state. Messages survive resume/replay and broker restart, and logical message IDs prevent redelivery to the same materialized stage across stage-attempt restarts. When a matching stage session initializes, it receives the FIFO entries through the ordinary Intercom inbound path before its first model turn, under the heading **Messages received before you started**, with sender identity and `Sent:` timestamps visible separately from the task prompt.
84
+ The `[future]` queued count is the number of retained sticky messages, not the number unread by a particular stage. A message remains queued for later matches after earlier stages receive it. Inspect the per-stage `deliveryStates` in `intercom list` and `workflow({ action: "status", runId: "<rootRunId>" })` to check receipt or why delivery was skipped. `delivered` confirms admission to stage context, not that the model followed the instruction. `receipt-unverified` means only transport delivery or an older receipt is known; inspect the stage transcript before resending.
85
+
86
+ `[delivery]` rows retain per-stage evidence for sticky targets missing from the future-target list, including exact targets after materialization. They do not indicate that a stage is still in the future or currently live. Use the per-stage state to decide what to do; an ended stage without confirmed context admission shows `stage-terminal`, even when transport delivery was acknowledged.
87
+
88
+ | State | What to do |
89
+ | --- | --- |
90
+ | `queued` | Wait for the matching stage to finish startup. |
91
+ | `session-replaced` | Check startup status. The new session must receive retained context before its first turn. |
92
+ | `delivery-unavailable` | Enable Intercom for that stage and keep it in the workflow invocation group. |
93
+ | `stage-terminal` | Steer a live stage or start separately authorized work; the ended stage cannot consume the update. |
94
+ | `root-unresolved` | Check the reported ownership problem before retrying. Preserve the run ID and diagnostic when reporting it. |
95
+
96
+ The workflows extension persists up to **50 queued messages per target** with workflow state. Messages survive resume/replay and broker restart. Reusing a stage's existing session transcript does not duplicate acknowledged messages; a replacement session with a new transcript receives the retained sticky context again. When a matching stage session initializes, it receives the FIFO entries through the ordinary Intercom inbound path before its first model turn, under the heading **Messages received before you started**, with sender identity and `Sent:` timestamps visible separately from the task prompt.
85
97
 
86
98
  Only a workflow invocation member with eligible invocation-control authority can queue to its invocation-owned stages; this includes a main-chat session that explicitly joined `workflow:<rootRunId>`. Subgroup peers and another root run remain refused even if they add that membership. An explicit stage `group: "default"` is a shared-group escape, is not workflow-owned, and does not receive pending invocation delivery. An ineligible attempt is refused with `Target workflow run is in a different intercom group`. The 51st queued message is refused with `Pending stage message queue is full (limit 50)` rather than evicting an earlier entry.
87
99
 
package/docs/providers.md CHANGED
@@ -334,6 +334,16 @@ Legacy uppercase env-var-like values such as `MY_API_KEY` are migrated to `$MY_A
334
334
 
335
335
  The providers below have additional setup, need additional settings, or can use credentials supplied by their platform.
336
336
 
337
+ ### NVIDIA NIM
338
+
339
+ NVIDIA's built-in default is `nvidia/nemotron-3-ultra-550b-a55b`. Saved and explicit model choices still take precedence. To select this model explicitly:
340
+
341
+ ```bash
342
+ atomic --provider nvidia --model nvidia/nemotron-3-ultra-550b-a55b
343
+ ```
344
+
345
+ Use `--list-models` or `/model` to check the current catalog and replace a missing saved model. A catalog listing does not verify account access or serving availability.
346
+
337
347
  ### Azure OpenAI
338
348
 
339
349
  ```bash
package/docs/settings.md CHANGED
@@ -532,11 +532,38 @@ Paths in `~/.atomic/agent/settings.json` resolve relative to `~/.atomic/agent`.
532
532
  | `skills` | string[] | `[]` | Local skill file paths or directories |
533
533
  | `prompts` | string[] | `[]` | Local prompt template paths or directories |
534
534
  | `themes` | string[] | `[]` | Local theme file paths or directories |
535
- | `workflows` | string[] | `[]` | Local workflow file paths or directories |
535
+ | `workflows` | string[] or object | `[]` | Local workflow paths, or `{ "paths": [...], "durability": {...} }`; see [Workflow database](#workflow-database) |
536
536
  | `enableSkillCommands` | boolean | `true` | Register skills as `/skill:name` commands |
537
537
 
538
538
  Arrays support glob patterns and exclusions. Use `!pattern` to exclude. Use `+path` to force-include an exact path and `-path` to force-exclude an exact path.
539
539
 
540
+ #### Workflow database
541
+
542
+ Choose an existing PostgreSQL database in global or trusted project settings:
543
+
544
+ ```json
545
+ {
546
+ "workflows": {
547
+ "paths": ["./workflows"],
548
+ "durability": {
549
+ "systemDatabaseUrlFile": "~/.atomic/neon/direct.url"
550
+ }
551
+ }
552
+ }
553
+ ```
554
+
555
+ | Setting | Type | Default | Description |
556
+ |---------|------|---------|-------------|
557
+ | `workflows.paths` | string[] | `[]` | Workflow resource paths in object-form settings; existing `workflows: [...]` settings remain supported |
558
+ | `workflows.durability.systemDatabaseUrl` | string | - | PostgreSQL URL for the workflow database |
559
+ | `workflows.durability.systemDatabaseUrlFile` | string | - | Read the PostgreSQL URL from a UTF-8 file instead of storing credentials in settings |
560
+
561
+ Set only one URL source per scope. A project `durability` object replaces the global database selection; project settings are ignored unless trusted. Relative URL-file paths resolve beside the settings file that declares them: `~/.atomic/agent` for global settings and `.atomic` for project settings, or the matching `.pi` directory for inherited pi settings. Absolute paths and `~/` are supported. Protect credential files with permissions appropriate for your account, and do not commit them.
562
+
563
+ Precedence is nonempty `DBOS_SYSTEM_DATABASE_URL`, then settings, then managed embedded PostgreSQL with Docker as its provisioning fallback. URLs and file contents are trimmed. Invalid settings, including unrecognized `durability` keys, or missing, empty, or invalid URL files stop workflow initialization instead of silently choosing a local database. An explicit URL never starts managed PostgreSQL or Docker, even if the endpoint is unavailable. Existing non-durable fallback warnings still apply when DBOS cannot connect.
564
+
565
+ Restart Atomic after changing the database selection. Selection takes effect on the first workflow action. Interactive and RPC sessions then report the selected provider and host without credentials; headless sessions report only a Docker fallback, on stderr. Changing databases does not migrate existing runs; use the original database to inspect or resume them. See [Durable workflows](/workflows/operations#durable-workflows-and-cross-session-resume).
566
+
540
567
  #### packages
541
568
 
542
569
  String form loads all resources from a package:
@@ -35,6 +35,8 @@ intercom({
35
35
 
36
36
  Send material updates through Intercom to every affected workflow stage, including stages that have not started. Name and pattern sends remain sticky for every future matching stage until root termination. When shared scope or acceptance criteria change, broadcast one authoritative update to `workflow:<rootRunId>/**` (or a narrower path pattern) rather than enumerating stages; live matches receive it immediately and future descendants receive it before their first model turn. A syntactically valid path outside the persisted known set queues with a `notInKnownSet` warning and settles undeliverable at terminal only if never delivered; an entry delivered at least once is not reported undeliverable. Use `ask` once the stage session is live and can reply.
37
37
 
38
+ To verify a sticky update, inspect its per-stage `deliveryStates` in `intercom list` or `workflow({ action: "status", runId: "<rootRunId>" })`. The future target's queued count includes messages retained for stages that have not started yet, even after delivery to earlier stages. It is not an unread count or proof of receipt by every stage. `delivered` confirms admission to stage context, not compliance with the update. A transport-only or older receipt appears as `receipt-unverified`; check the stage transcript before resending. See [pending delivery states](/intercom/reference#deferred-delivery-to-pending-stages) for skip reasons and recovery.
39
+
38
40
  ### Reading and scrolling the panel
39
41
 
40
42
  At 80 columns and wider, each `BACKGROUND` card shows the full run identity, mode, progress, live-tool details, and elapsed/status metadata. Remaining row space may show pending stages. Each target appears exactly or is replaced by a `stage`-labeled canonical ID; `… N more` counts omitted stages. If neither form fits, the pending label is omitted rather than displacing existing metadata. Tool nodes are read-only durable graph nodes, not attachable stage chats.
@@ -456,7 +458,7 @@ The readiness prompt can be answered in the attached stage UI or with `workflow(
456
458
 
457
459
  ## Durable Workflows and Cross-Session Resume
458
460
 
459
- Atomic workflows use **DBOS/Postgres as their sole persistent workflow backend**. Atomic configures and launches DBOS lazily on the first workflow action, reuses that process-wide instance, and awaits readiness before workflow execution, resume, inspection, or deletion can access durable state. `DBOS_SYSTEM_DATABASE_URL` may select an existing database. Once DBOS is ready, query and write failures fail the workflow action and never switch backends.
461
+ Atomic workflows use **DBOS/Postgres as their sole persistent workflow backend**. Atomic configures and launches DBOS lazily on the first workflow action, reuses that process-wide instance, and awaits readiness before workflow execution, resume, inspection, or deletion can access durable state. `DBOS_SYSTEM_DATABASE_URL` or `workflows.durability` in settings may select an existing database. Once DBOS is ready, query and write failures fail the workflow action and never switch backends.
460
462
 
461
463
  SDK callers can choose the backend and database for each `run()` call, and require durable state so a run fails fast instead of using the in-memory fallback; see [Choosing the durable backend](/workflows/api-reference#choosing-the-durable-backend).
462
464
 
@@ -482,7 +484,7 @@ Awaited checkpoint writes also have a 10-second database deadline. If a checkpoi
482
484
 
483
485
  If recovery reports `Workflow definition not found`, restore the matching workflow definition and run `/workflow reload`, then retry resume with the same full run ID. A failed resume preparation does not discard the recovery target or saved receipts. Do not start a new run to bypass the missing definition.
484
486
 
485
- **Zero-configuration local database.** Without `DBOS_SYSTEM_DATABASE_URL`, Atomic uses its own embedded Postgres for DBOS. It requires no Docker daemon, system Postgres install, install lifecycle script, or first-run download.
487
+ **Zero-configuration local database.** Without an explicit database URL from the environment or settings, Atomic uses its own embedded Postgres for DBOS. It requires no Docker daemon, system Postgres install, install lifecycle script, or first-run download.
486
488
 
487
489
  Supported targets are Linux x64/ARM64 with glibc or musl, macOS x64/ARM64, and Windows x64/ARM64 using x64 emulation. Linux musl uses PostgreSQL 18.6; other targets use 18.4. Both use the compatible major-version-18 cluster at `~/.atomic/postgres/v18`, with preferred port `5439`.
488
490
 
@@ -512,6 +514,8 @@ Atomic checks PostgreSQL readiness and matches the server to the managed data an
512
514
 
513
515
  After attachment, Atomic checks the managed server's SQL and process identity before borrowing database connections and every five seconds while idle. Lost health discards old connections. One elected process may restart the existing managed cluster under the shared setup lock; other sessions reconnect to its verified, persisted port. Recovery never initializes missing data, signals an unrelated listener, switches to Docker, or restarts the DBOS executor.
514
516
 
517
+ If the managed server has stopped, the next workflow database action can restart the existing cluster even when `postmaster.opts` is missing. Atomic still requires trusted ownership records, the original cluster identity, and a verified runtime. A hard identity, ownership, or filesystem failure refuses recovery rather than guessing which server or data to use.
518
+
515
519
  Each process makes at most three recovery attempts per check, with short
516
520
  backoffs. Later health checks retry after a cooldown if the problem persists.
517
521
  If the retained PostgreSQL runtime is damaged or missing, reinstall a complete
@@ -557,6 +561,8 @@ effect succeeded. Inspect `/workflow status <full-run-uuid>` for the original ru
557
561
  and explicitly resume it when eligible. Do not start a duplicate run or delete
558
562
  `v18` or `v18.shared` to bypass an identity or availability error.
559
563
 
564
+ Database-unavailable admission errors and status `dependencyError` include the selected database provider, its endpoint without credentials or URL options, and the last retained health-probe or recovery failure. A cooldown error keeps the recovery failure visible. Use that reason to repair a missing runtime or configuration; preserve data and ownership records when identity or filesystem checks fail. After repair, inspect and explicitly resume the original run ID.
565
+
560
566
  For an explicit `DBOS_SYSTEM_DATABASE_URL`, Atomic does not manage the external
561
567
  database. Restore that endpoint or correct its credentials and TLS settings,
562
568
  then inspect and resume the original workflow. If the Docker fallback is in use,
@@ -731,13 +737,31 @@ That history does not authorize any live release action.
731
737
 
732
738
  ### Configuring DBOS/Postgres
733
739
 
740
+ Choose a hosted or separately managed database persistently in `~/.atomic/agent/settings.json` or trusted project `.atomic/settings.json`:
741
+
742
+ ```json
743
+ {
744
+ "workflows": {
745
+ "durability": {
746
+ "systemDatabaseUrlFile": "~/.atomic/neon/direct.url"
747
+ }
748
+ }
749
+ }
750
+ ```
751
+
752
+ The file contains only the PostgreSQL connection URL; surrounding whitespace and a trailing newline are trimmed. Use `systemDatabaseUrl` instead for an inline URL, but do not set both. Relative file paths resolve beside the settings file that declares them, such as the global agent directory or project `.atomic` directory. Protect the file from other accounts and keep credentials out of version control. Existing workflow path arrays remain supported; when using the object form, put resource paths in `workflows.paths`.
753
+
754
+ `DBOS_SYSTEM_DATABASE_URL` overrides settings. A trusted project `durability` object replaces the global selection. Without either, Atomic provisions managed PostgreSQL, then tries Docker if provisioning fails. An explicit URL uses only its chosen endpoint, even on connection failure. Invalid settings, including unrecognized `durability` keys, and unreadable or empty credential files stop initialization rather than choosing another database. Restart Atomic to change the selection; existing runs stay in their original database and are not migrated.
755
+
756
+ On first database initialization, interactive and RPC sessions display the selected provider and host without credentials or URL options. A Docker selection is labelled `Docker fallback`. Headless sessions, including SDK hosts without a UI, write only the Docker fallback notice to stderr; managed and configured selections stay silent there. In-memory degradation retains its existing warning. See [Workflow database settings](/settings#workflow-database).
757
+
734
758
  **Linux musl and Windows ARM64.** Musl installations include Alpine/musl PostgreSQL 18.6. Windows ARM64 runs PostgreSQL 18.4 x64 through emulation and requires Windows 11 plus the Microsoft Visual C++ x64 v14 Redistributable. This is not native PostgreSQL ARM64; Windows 10 on ARM is unsupported.
735
759
 
736
760
  Set `ATOMIC_POSTGRES_RUNTIME_DIR` to a complete extracted runtime containing `bin/initdb`, `bin/pg_ctl`, and `bin/postgres` to override packaged runtime discovery, including in air-gapped deployments. Otherwise DBOS/Postgres durability requires no setup on supported local platforms. To use an existing Postgres database, set `DBOS_SYSTEM_DATABASE_URL` before starting Atomic; that explicit URL retains precedence over embedded provisioning. Atomic provisions embedded Postgres next (with drop-privilege support when running as root on Linux), then Docker as a platform fallback. The DBOS SDK ships with `@bastani/atomic`. If no durable backend can be provisioned, workflows run on a process-local in-memory backend with a loud non-durable warning — never on the legacy per-workflow file store under `~/.atomic/workflow-durable` — and cross-process resume is unavailable until Postgres provisioning is fixed. Interactive and RPC actions show the warning as a display-only notification that is not added to agent/model context. Print and other headless actions, where no usable UI exists, write the actionable diagnostic to the console instead.
737
761
 
738
762
  Keep the complete extracted archive, not only the `atomic` executable. `ATOMIC_POSTGRES_RUNTIME_DIR` accepts complete legacy runtimes without provenance; an incomplete override falls through to installed candidates. Packaging failures do not require deleting or reinitializing the v18 cluster.
739
763
 
740
- If starting workflows reports a missing PostgreSQL executable or library, such as `libzstd.1.dylib` on macOS, download a repaired release and reinstall the complete archive. The installers do not check the bundled PostgreSQL runtime, so the problem shows up the first time Atomic starts its embedded database. With `DBOS_SYSTEM_DATABASE_URL` set, Atomic never uses the bundled runtime. If embedded startup fails and the Docker fallback succeeds, workflows run on Docker without reporting the embedded failure. Check `~/.atomic/postgres/v18.log` if the managed database never starts. Do not copy libraries from another version or delete your PostgreSQL data directory: this is an installation problem, not database corruption. An already-running server does not prove that the new installation is usable.
764
+ If starting workflows reports a missing PostgreSQL executable or library, such as `libzstd.1.dylib` on macOS, download a repaired release and reinstall the complete archive. The installers do not check the bundled PostgreSQL runtime, so the problem shows up the first time Atomic starts its embedded database. With an explicit database URL from the environment or settings, Atomic never uses the bundled runtime. If embedded startup fails and the Docker fallback succeeds, workflows run on Docker and the backend notice identifies that fallback. Check `~/.atomic/postgres/v18.log` if the managed database never starts. Do not copy libraries from another version or delete your PostgreSQL data directory: this is an installation problem, not database corruption. An already-running server does not prove that the new installation is usable.
741
765
 
742
766
  To check an archive runtime, set `runtime` to its `node_modules/@bastani/atomic-natives/postgres-runtime`, then run `"$runtime/bin/postgres" --version` and `"$runtime/bin/pg_ctl" --version`. On Windows use the corresponding `.exe` files in PowerShell. Both must succeed. If a library-link or copy error is reported, repair the complete installation instead of mixing libraries from different releases.
743
767