@bastani/atomic 0.9.13 → 0.9.14-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/builtin/i-have-adhd/package.json +1 -1
  3. package/dist/builtin/intercom/package.json +1 -1
  4. package/dist/builtin/mcp/package.json +1 -1
  5. package/dist/builtin/subagents/package.json +1 -1
  6. package/dist/builtin/web-access/package.json +1 -1
  7. package/dist/builtin/workflows/CHANGELOG.md +12 -0
  8. package/dist/builtin/workflows/README.md +9 -0
  9. package/dist/builtin/workflows/builtin/adversarial-verification.ts +4 -0
  10. package/dist/builtin/workflows/builtin/classify-and-act.ts +4 -0
  11. package/dist/builtin/workflows/builtin/fan-out-and-synthesize.ts +4 -0
  12. package/dist/builtin/workflows/builtin/generate-and-filter.ts +4 -0
  13. package/dist/builtin/workflows/builtin/goal.ts +4 -0
  14. package/dist/builtin/workflows/builtin/loop-until-done.ts +4 -0
  15. package/dist/builtin/workflows/builtin/open-claude-design.ts +4 -0
  16. package/dist/builtin/workflows/builtin/ralph.ts +4 -0
  17. package/dist/builtin/workflows/builtin/tournament.ts +4 -0
  18. package/dist/builtin/workflows/package.json +1 -1
  19. package/dist/builtin/workflows/src/authoring/workflow.ts +9 -0
  20. package/dist/builtin/workflows/src/authoring.d.ts +3 -0
  21. package/dist/builtin/workflows/src/durable/completed-catalog.ts +13 -2
  22. package/dist/builtin/workflows/src/durable/workflow-heartbeat-anchor.ts +153 -0
  23. package/dist/builtin/workflows/src/engine/run-durable-stage-session.ts +28 -0
  24. package/dist/builtin/workflows/src/engine/run.ts +1 -0
  25. package/dist/builtin/workflows/src/extension/extension-runtime-state.ts +138 -0
  26. package/dist/builtin/workflows/src/extension/index.bundle.mjs +766 -4
  27. package/dist/builtin/workflows/src/extension/workflow-heartbeat-delivery.ts +197 -0
  28. package/dist/builtin/workflows/src/extension/workflow-heartbeat-notice.ts +115 -0
  29. package/dist/builtin/workflows/src/extension/workflow-heartbeat-scheduler.ts +962 -0
  30. package/dist/builtin/workflows/src/sdk-surface.ts +9 -0
  31. package/dist/builtin/workflows/src/shared/authoring-contract-ui.d.ts +1 -0
  32. package/dist/builtin/workflows/src/shared/authoring-contract-ui.ts +1 -0
  33. package/dist/builtin/workflows/src/shared/persistence-restore.ts +12 -0
  34. package/dist/builtin/workflows/src/shared/workflow-authoring-types.d.ts +1 -0
  35. package/dist/builtin/workflows/src/shared/workflow-authoring-types.ts +1 -0
  36. package/dist/builtin/workflows/src/shared/workflow-heartbeat-contract.d.ts +21 -0
  37. package/dist/builtin/workflows/src/shared/workflow-heartbeat-contract.ts +25 -0
  38. package/dist/core/extensions/index.d.ts +1 -0
  39. package/dist/core/extensions/index.d.ts.map +1 -1
  40. package/dist/core/extensions/index.js +1 -0
  41. package/dist/core/extensions/index.js.map +1 -1
  42. package/dist/core/extensions/ui-types.d.ts +26 -0
  43. package/dist/core/extensions/ui-types.d.ts.map +1 -1
  44. package/dist/core/extensions/ui-types.js +17 -1
  45. package/dist/core/extensions/ui-types.js.map +1 -1
  46. package/dist/core/tools/ask-user-question/ask-user-question.d.ts +21 -0
  47. package/dist/core/tools/ask-user-question/ask-user-question.d.ts.map +1 -1
  48. package/dist/core/tools/ask-user-question/ask-user-question.js +34 -9
  49. package/dist/core/tools/ask-user-question/ask-user-question.js.map +1 -1
  50. package/dist/core/tools/ask-user-question/view/components/multi-select-view.d.ts.map +1 -1
  51. package/dist/core/tools/ask-user-question/view/components/multi-select-view.js +5 -2
  52. package/dist/core/tools/ask-user-question/view/components/multi-select-view.js.map +1 -1
  53. package/dist/core/tools/ask-user-question/view/components/submit-picker.d.ts.map +1 -1
  54. package/dist/core/tools/ask-user-question/view/components/submit-picker.js +3 -1
  55. package/dist/core/tools/ask-user-question/view/components/submit-picker.js.map +1 -1
  56. package/dist/core/tools/ask-user-question/view/components/wrapping-select.d.ts.map +1 -1
  57. package/dist/core/tools/ask-user-question/view/components/wrapping-select.js +8 -1
  58. package/dist/core/tools/ask-user-question/view/components/wrapping-select.js.map +1 -1
  59. package/dist/index-extensions.d.ts +1 -1
  60. package/dist/index-extensions.d.ts.map +1 -1
  61. package/dist/index-extensions.js +1 -1
  62. package/dist/index-extensions.js.map +1 -1
  63. package/dist/modes/interactive/components/reserved-bottom-overlay.d.ts +95 -0
  64. package/dist/modes/interactive/components/reserved-bottom-overlay.d.ts.map +1 -0
  65. package/dist/modes/interactive/components/reserved-bottom-overlay.js +234 -0
  66. package/dist/modes/interactive/components/reserved-bottom-overlay.js.map +1 -0
  67. package/dist/modes/interactive/interactive-extension-custom-ui.js +94 -6
  68. package/dist/modes/interactive/interactive-extension-custom-ui.js.map +1 -1
  69. package/dist/modes/interactive/interactive-mode-base.d.ts +3 -0
  70. package/dist/modes/interactive/interactive-mode-base.d.ts.map +1 -1
  71. package/dist/modes/interactive/interactive-mode-base.js +5 -1
  72. package/dist/modes/interactive/interactive-mode-base.js.map +1 -1
  73. package/dist/modes/interactive/interactive-mode-surface.d.ts +2 -0
  74. package/dist/modes/interactive/interactive-mode-surface.d.ts.map +1 -1
  75. package/dist/modes/interactive/interactive-mode-surface.js.map +1 -1
  76. package/dist/modes/interactive/interactive-tui.d.ts +3 -0
  77. package/dist/modes/interactive/interactive-tui.d.ts.map +1 -1
  78. package/dist/modes/interactive/interactive-tui.js +14 -0
  79. package/dist/modes/interactive/interactive-tui.js.map +1 -1
  80. package/dist/modes/interactive-engine/engine-custom-ui.d.ts +2 -0
  81. package/dist/modes/interactive-engine/engine-custom-ui.d.ts.map +1 -1
  82. package/dist/modes/interactive-engine/engine-custom-ui.js +1 -0
  83. package/dist/modes/interactive-engine/engine-custom-ui.js.map +1 -1
  84. package/dist/modes/interactive-engine/protocol.d.ts +1 -0
  85. package/dist/modes/interactive-engine/protocol.d.ts.map +1 -1
  86. package/dist/modes/interactive-engine/protocol.js +1 -0
  87. package/dist/modes/interactive-engine/protocol.js.map +1 -1
  88. package/dist/modes/interactive-engine/remote-component.d.ts +3 -1
  89. package/dist/modes/interactive-engine/remote-component.d.ts.map +1 -1
  90. package/dist/modes/interactive-engine/remote-component.js +3 -2
  91. package/dist/modes/interactive-engine/remote-component.js.map +1 -1
  92. package/docs/extensions.md +27 -0
  93. package/docs/keybindings.md +1 -0
  94. package/docs/workflows.md +34 -0
  95. package/npm-shrinkwrap.json +29 -29
  96. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../../src/modes/interactive-engine/protocol.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,MAAM,CAAC,MAAM,mCAAmC,GAAG,CAAC,CAAC;AAkIrD,MAAM,cAAc,GAAoC;IACvD,gBAAgB;IAChB,UAAU;IACV,cAAc;IACd,cAAc;IACd,mBAAmB;IACnB,cAAc;IACd,wBAAwB;CACxB,CAAC;AAEF,MAAM,UAAU,WAAW,CAAC,KAAgD;IAC3E,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC7D,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;IAC1E,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,SAAS,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;AACtF,CAAC;AAED,SAAS,YAAY,CAAC,KAAgB;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC7E,CAAC;AAED,SAAS,cAAc,CAAC,KAAgB;IACvC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,cAAc,CA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MAAM,CAAC,MAAM,iCAAiC,GAAG,+BAA+B,CAAC","sourcesContent":["import type { CallbackActivity, CallbackActivityKind } from \"../../core/callback-activity.ts\";\nimport type { HostInputFormField, HostSessionPickerRow } from \"../../core/extensions/ui-types.ts\";\nimport type { KeyId } from \"../../core/keybindings.ts\";\n\n/**\n * Version 3 adds correlated replies for `engine_custom_input`. The host uses\n * those replies to decide whether a matching fullscreen viewport key should be\n * replayed, so a child that cannot send them must not be treated as compatible.\n */\nexport const INTERACTIVE_ENGINE_PROTOCOL_VERSION = 3;\n\nexport interface JsonObject {\n\t[key: string]: JsonValue;\n}\n\nexport type JsonValue = boolean | JsonObject | JsonValue[] | null | number | string;\n\nexport interface SerializableOverlayOptions {\n\tanchor?: string;\n\tcol?: number | string;\n\tmargin?: number | { top?: number; right?: number; bottom?: number; left?: number };\n\tmaxHeight?: number | string;\n\tmaxWidth?: number | string;\n\tminHeight?: number;\n\tminWidth?: number;\n\toffsetX?: number;\n\toffsetY?: number;\n\trow?: number | string;\n\twidth?: number | string;\n}\n\n/**\n * Allowlisted terminal-mode control a remote custom component may ask the host\n * to apply to the real host TTY. Deliberately NOT a raw byte channel: the child\n * names an intent and the host owns the concrete escape sequence, so a buggy or\n * compromised child can only toggle this documented mode.\n */\nexport type EngineTerminalControl = { kind: \"autowrap\"; enabled: boolean };\n\nexport interface EngineExtensionShortcut {\n\tkey: string;\n\tdescription?: string;\n}\n\nexport type SerializableKeybindingsConfig = Record<string, KeyId | KeyId[]>;\n\nexport interface EngineKeybindingState {\n\tuserBindings: SerializableKeybindingsConfig;\n\teffectiveBindings: SerializableKeybindingsConfig;\n\tshortcuts: EngineExtensionShortcut[];\n}\n\nexport type InteractiveEngineMessage =\n\t| { type: \"engine_ready\"; protocolVersion: typeof INTERACTIVE_ENGINE_PROTOCOL_VERSION; pid: number }\n\t| { type: \"engine_bound\" }\n\t| { type: \"engine_keybindings_reloaded\"; state: EngineKeybindingState }\n\t| { type: \"engine_heartbeat\"; at: number }\n\t| { type: \"engine_activity_started\"; activity: CallbackActivity }\n\t| { type: \"engine_activity_finished\"; activityId: string }\n\t/**\n\t * The child took ownership of a correlated RPC request: it has parsed the\n\t * command and is about to run it. Emitted and flushed BEFORE any handler\n\t * work, so a later transport failure can be told apart from a send that\n\t * never landed. Output is not a substitute: a command can run to completion\n\t * with side effects and produce nothing.\n\t */\n\t| { type: \"engine_request_accepted\"; requestId: string; command: string }\n\t| {\n\t\t\ttype: \"engine_custom_open\";\n\t\t\tcomponentId: string;\n\t\t\toverlay: boolean;\n\t\t\tdeferInlineCustomUiFocus?: boolean;\n\t\t\thandlesCtrlC?: boolean;\n\t\t\thandlesInternalUiAction?: boolean;\n\t\t\toverlayOptions?: SerializableOverlayOptions;\n\t\t\twidgetKey?: string;\n\t\t\twidgetPlacement?: \"aboveEditor\" | \"belowEditor\";\n\t }\n\t| { type: \"engine_custom_close\"; componentId: string }\n\t| { type: \"engine_custom_frame\"; componentId: string; requestId: number; lines: string[] }\n\t| { type: \"engine_custom_input_result\"; componentId: string; requestId: number; handled: boolean }\n\t| { type: \"engine_custom_invalidate\"; componentId: string }\n\t| { type: \"engine_custom_done\"; componentId: string; result?: JsonValue }\n\t| { type: \"engine_custom_terminal\"; componentId: string; control: EngineTerminalControl }\n\t| { type: \"engine_custom_control\"; componentId: string; action: \"focus\" | \"hide\" | \"show\" | \"unfocus\" }\n\t| {\n\t\t\ttype: \"engine_session_picker_open\";\n\t\t\tcomponentId: string;\n\t\t\tsessions: HostSessionPickerRow[];\n\t\t\tshowRenameHint?: boolean;\n\t }\n\t| { type: \"engine_session_picker_update\"; componentId: string; sessions: HostSessionPickerRow[] }\n\t| { type: \"engine_session_picker_error\"; componentId: string; message: string }\n\t| { type: \"engine_session_picker_close\"; componentId: string }\n\t| {\n\t\t\ttype: \"engine_input_form_open\";\n\t\t\tcomponentId: string;\n\t\t\ttitle: string;\n\t\t\tfields: HostInputFormField[];\n\t\t\theading?: string;\n\t\t\tsubmitLabel?: string;\n\t }\n\t| { type: \"engine_input_form_close\"; componentId: string };\nexport type InteractiveEngineCommand =\n\t| { type: \"engine_custom_render\"; componentId: string; requestId: number; width: number; rows: number }\n\t| { type: \"engine_custom_input\"; componentId: string; requestId: number; data: string }\n\t| { type: \"engine_custom_dispose\"; componentId: string }\n\t| {\n\t\t\ttype: \"engine_tool_render\";\n\t\t\tcomponentId: string;\n\t\t\trequestId: number;\n\t\t\twidth: number;\n\t\t\ttoolName: string;\n\t\t\ttoolCallId: string;\n\t\t\targs: JsonValue;\n\t\t\tresult?: JsonObject;\n\t\t\texecutionStarted: boolean;\n\t\t\targsComplete: boolean;\n\t\t\tisPartial: boolean;\n\t\t\texpanded: boolean;\n\t\t\tshowImages: boolean;\n\t\t\timageWidthCells: number;\n\t }\n\t| {\n\t\t\ttype: \"engine_message_render\";\n\t\t\tcomponentId: string;\n\t\t\trequestId: number;\n\t\t\twidth: number;\n\t\t\tmessage: JsonObject;\n\t\t\texpanded: boolean;\n\t\t\toutputPad: number;\n\t }\n\t| { type: \"engine_render_dispose\"; componentId: string }\n\t| { type: \"engine_session_picker_select\"; componentId: string; path: string }\n\t| { type: \"engine_session_picker_cancel\"; componentId: string }\n\t| { type: \"engine_session_picker_delete\"; componentId: string; path: string }\n\t| { type: \"engine_input_form_submit\"; componentId: string; values: Record<string, string> }\n\t| { type: \"engine_input_form_cancel\"; componentId: string };\n\nconst ACTIVITY_KINDS: readonly CallbackActivityKind[] = [\n\t\"extension.hook\",\n\t\"renderer\",\n\t\"tool.execute\",\n\t\"tool.prepare\",\n\t\"workflow.ctx_tool\",\n\t\"workflow.run\",\n\t\"workflow.stage_adapter\",\n];\n\nexport function isJsonValue(value: object | boolean | null | number | string): value is JsonValue {\n\tif (value === null || typeof value !== \"object\") return true;\n\tif (Array.isArray(value)) return value.every((item) => isJsonValue(item));\n\treturn Object.values(value).every((item) => item !== undefined && isJsonValue(item));\n}\n\nfunction isJsonObject(value: JsonValue): value is JsonObject {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction isActivityKind(value: JsonValue): value is CallbackActivityKind {\n\treturn typeof value === \"string\" && ACTIVITY_KINDS.includes(value as CallbackActivityKind);\n}\n\nfunction isCallbackActivity(value: JsonValue): value is JsonObject & CallbackActivity {\n\treturn (\n\t\tisJsonObject(value) &&\n\t\ttypeof value.id === \"string\" &&\n\t\tisActivityKind(value.kind) &&\n\t\ttypeof value.name === \"string\" &&\n\t\ttypeof value.startedAt === \"number\"\n\t);\n}\n\nfunction parseEngineTerminalControl(value: JsonValue | undefined): EngineTerminalControl | undefined {\n\tif (value === undefined || !isJsonObject(value) || value.kind !== \"autowrap\" || typeof value.enabled !== \"boolean\") {\n\t\treturn undefined;\n\t}\n\treturn { kind: \"autowrap\", enabled: value.enabled };\n}\n\nconst SESSION_PICKER_MESSAGE_COLORS = [\"success\", \"warning\", \"accent\", \"error\"] as const;\n\nfunction parseSessionPickerRow(value: JsonValue): HostSessionPickerRow | undefined {\n\tif (!isJsonObject(value)) return undefined;\n\tconst {\n\t\tpath,\n\t\tid,\n\t\tcwd,\n\t\tcreatedAt,\n\t\tmodifiedAt,\n\t\tmessageCount,\n\t\tfirstMessage,\n\t\tsummary,\n\t\tallMessagesText,\n\t\tname,\n\t\tmessageColor,\n\t} = value;\n\tif (\n\t\ttypeof path !== \"string\" ||\n\t\ttypeof id !== \"string\" ||\n\t\ttypeof cwd !== \"string\" ||\n\t\ttypeof createdAt !== \"number\" ||\n\t\ttypeof modifiedAt !== \"number\" ||\n\t\ttypeof messageCount !== \"number\" ||\n\t\ttypeof firstMessage !== \"string\"\n\t)\n\t\treturn undefined;\n\tif (summary !== undefined && typeof summary !== \"string\") return undefined;\n\tif (allMessagesText !== undefined && typeof allMessagesText !== \"string\") return undefined;\n\tif (name !== undefined && typeof name !== \"string\") return undefined;\n\tif (\n\t\tmessageColor !== undefined &&\n\t\t!SESSION_PICKER_MESSAGE_COLORS.includes(messageColor as (typeof SESSION_PICKER_MESSAGE_COLORS)[number])\n\t)\n\t\treturn undefined;\n\treturn {\n\t\tpath,\n\t\tid,\n\t\tcwd,\n\t\tcreatedAt,\n\t\tmodifiedAt,\n\t\tmessageCount,\n\t\tfirstMessage,\n\t\t...(summary !== undefined ? { summary } : {}),\n\t\t...(allMessagesText !== undefined ? { allMessagesText } : {}),\n\t\t...(name !== undefined ? { name } : {}),\n\t\t...(messageColor !== undefined\n\t\t\t? { messageColor: messageColor as (typeof SESSION_PICKER_MESSAGE_COLORS)[number] }\n\t\t\t: {}),\n\t};\n}\n\nfunction parseSessionPickerRows(value: JsonValue | undefined): HostSessionPickerRow[] | undefined {\n\tif (!Array.isArray(value)) return undefined;\n\tconst rows: HostSessionPickerRow[] = [];\n\tfor (const entry of value) {\n\t\tconst row = parseSessionPickerRow(entry);\n\t\tif (!row) return undefined;\n\t\trows.push(row);\n\t}\n\treturn rows;\n}\n\nconst INPUT_FORM_FIELD_TYPES = [\"string\", \"text\", \"number\", \"integer\", \"boolean\", \"select\"] as const;\n\nfunction parseInputFormFields(value: JsonValue | undefined): HostInputFormField[] | undefined {\n\tif (!Array.isArray(value)) return undefined;\n\tconst fields: HostInputFormField[] = [];\n\tfor (const entry of value) {\n\t\tif (!isJsonObject(entry)) return undefined;\n\t\tconst { name, type, description, required, choices, placeholder, initialValue } = entry;\n\t\tif (\n\t\t\ttypeof name !== \"string\" ||\n\t\t\t!INPUT_FORM_FIELD_TYPES.includes(type as HostInputFormField[\"type\"]) ||\n\t\t\ttypeof initialValue !== \"string\"\n\t\t)\n\t\t\treturn undefined;\n\t\tif (description !== undefined && typeof description !== \"string\") return undefined;\n\t\tif (required !== undefined && typeof required !== \"boolean\") return undefined;\n\t\tif (choices !== undefined && (!Array.isArray(choices) || !choices.every((choice) => typeof choice === \"string\")))\n\t\t\treturn undefined;\n\t\tif (placeholder !== undefined && typeof placeholder !== \"string\") return undefined;\n\t\tfields.push({\n\t\t\tname,\n\t\t\ttype: type as HostInputFormField[\"type\"],\n\t\t\tinitialValue,\n\t\t\t...(typeof description === \"string\" ? { description } : {}),\n\t\t\t...(typeof required === \"boolean\" ? { required } : {}),\n\t\t\t...(Array.isArray(choices) ? { choices: choices as string[] } : {}),\n\t\t\t...(typeof placeholder === \"string\" ? { placeholder } : {}),\n\t\t});\n\t}\n\treturn fields;\n}\n\nfunction parseStringRecord(value: JsonValue | undefined): Record<string, string> | undefined {\n\tif (value === undefined || !isJsonObject(value)) return undefined;\n\tconst entries = Object.entries(value);\n\tif (entries.some(([, entry]) => typeof entry !== \"string\")) return undefined;\n\treturn Object.fromEntries(entries) as Record<string, string>;\n}\n\nfunction parseKeybindingsConfig(value: JsonValue | undefined): SerializableKeybindingsConfig | undefined {\n\tif (value === undefined || !isJsonObject(value)) return undefined;\n\tconst config: SerializableKeybindingsConfig = {};\n\tfor (const [key, binding] of Object.entries(value)) {\n\t\tif (typeof binding === \"string\") config[key] = binding as SerializableKeybindingsConfig[string];\n\t\telse if (Array.isArray(binding) && binding.every((entry) => typeof entry === \"string\")) {\n\t\t\tconfig[key] = binding as SerializableKeybindingsConfig[string];\n\t\t} else return undefined;\n\t}\n\treturn config;\n}\n\nfunction parseKeybindingState(value: JsonValue | undefined): EngineKeybindingState | undefined {\n\tif (value === undefined || !isJsonObject(value) || !Array.isArray(value.shortcuts)) return undefined;\n\tconst userBindings = parseKeybindingsConfig(value.userBindings);\n\tconst effectiveBindings = parseKeybindingsConfig(value.effectiveBindings);\n\tif (!userBindings || !effectiveBindings) return undefined;\n\tconst shortcuts: EngineExtensionShortcut[] = [];\n\tfor (const shortcut of value.shortcuts) {\n\t\tif (\n\t\t\t!isJsonObject(shortcut) ||\n\t\t\ttypeof shortcut.key !== \"string\" ||\n\t\t\t(shortcut.description !== undefined && typeof shortcut.description !== \"string\")\n\t\t)\n\t\t\treturn undefined;\n\t\tshortcuts.push({\n\t\t\tkey: shortcut.key,\n\t\t\t...(typeof shortcut.description === \"string\" ? { description: shortcut.description } : {}),\n\t\t});\n\t}\n\treturn { userBindings, effectiveBindings, shortcuts };\n}\n\nfunction parseJsonObject(line: string): JsonObject | undefined {\n\tlet value: JsonValue;\n\ttry {\n\t\tvalue = JSON.parse(line) as JsonValue;\n\t} catch {\n\t\treturn undefined;\n\t}\n\treturn isJsonObject(value) ? value : undefined;\n}\n\nexport function parseInteractiveEngineMessage(line: string): InteractiveEngineMessage | undefined {\n\tconst value = parseJsonObject(line);\n\tif (!value || typeof value.type !== \"string\") return undefined;\n\tswitch (value.type) {\n\t\tcase \"engine_ready\":\n\t\t\treturn value.protocolVersion === INTERACTIVE_ENGINE_PROTOCOL_VERSION && typeof value.pid === \"number\"\n\t\t\t\t? { type: value.type, protocolVersion: INTERACTIVE_ENGINE_PROTOCOL_VERSION, pid: value.pid }\n\t\t\t\t: undefined;\n\t\tcase \"engine_bound\":\n\t\t\treturn { type: value.type };\n\t\tcase \"engine_keybindings_reloaded\": {\n\t\t\tconst state = parseKeybindingState(value.state);\n\t\t\treturn state ? { type: value.type, state } : undefined;\n\t\t}\n\t\tcase \"engine_heartbeat\":\n\t\t\treturn typeof value.at === \"number\" ? { type: value.type, at: value.at } : undefined;\n\t\tcase \"engine_activity_started\":\n\t\t\treturn isCallbackActivity(value.activity) ? { type: value.type, activity: value.activity } : undefined;\n\t\tcase \"engine_activity_finished\":\n\t\t\treturn typeof value.activityId === \"string\" ? { type: value.type, activityId: value.activityId } : undefined;\n\t\tcase \"engine_request_accepted\":\n\t\t\treturn typeof value.requestId === \"string\" && typeof value.command === \"string\"\n\t\t\t\t? { type: value.type, requestId: value.requestId, command: value.command }\n\t\t\t\t: undefined;\n\t\tcase \"engine_custom_open\":\n\t\t\treturn typeof value.componentId === \"string\" && typeof value.overlay === \"boolean\"\n\t\t\t\t? {\n\t\t\t\t\t\ttype: value.type,\n\t\t\t\t\t\tcomponentId: value.componentId,\n\t\t\t\t\t\toverlay: value.overlay,\n\t\t\t\t\t\tdeferInlineCustomUiFocus: value.deferInlineCustomUiFocus === true,\n\t\t\t\t\t\thandlesCtrlC: value.handlesCtrlC === true,\n\t\t\t\t\t\thandlesInternalUiAction: value.handlesInternalUiAction === true,\n\t\t\t\t\t\toverlayOptions: isJsonObject(value.overlayOptions)\n\t\t\t\t\t\t\t? (value.overlayOptions as SerializableOverlayOptions)\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\twidgetKey: typeof value.widgetKey === \"string\" ? value.widgetKey : undefined,\n\t\t\t\t\t\twidgetPlacement:\n\t\t\t\t\t\t\tvalue.widgetPlacement === \"belowEditor\"\n\t\t\t\t\t\t\t\t? \"belowEditor\"\n\t\t\t\t\t\t\t\t: value.widgetPlacement === \"aboveEditor\"\n\t\t\t\t\t\t\t\t\t? \"aboveEditor\"\n\t\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t}\n\t\t\t\t: undefined;\n\t\tcase \"engine_custom_close\":\n\t\t\treturn typeof value.componentId === \"string\"\n\t\t\t\t? { type: value.type, componentId: value.componentId }\n\t\t\t\t: undefined;\n\t\tcase \"engine_custom_frame\":\n\t\t\treturn typeof value.componentId === \"string\" &&\n\t\t\t\ttypeof value.requestId === \"number\" &&\n\t\t\t\tArray.isArray(value.lines) &&\n\t\t\t\tvalue.lines.every((entry) => typeof entry === \"string\")\n\t\t\t\t? { type: value.type, componentId: value.componentId, requestId: value.requestId, lines: value.lines }\n\t\t\t\t: undefined;\n\t\tcase \"engine_custom_input_result\":\n\t\t\treturn typeof value.componentId === \"string\" &&\n\t\t\t\ttypeof value.requestId === \"number\" &&\n\t\t\t\ttypeof value.handled === \"boolean\"\n\t\t\t\t? { type: value.type, componentId: value.componentId, requestId: value.requestId, handled: value.handled }\n\t\t\t\t: undefined;\n\t\tcase \"engine_custom_invalidate\":\n\t\t\treturn typeof value.componentId === \"string\"\n\t\t\t\t? { type: value.type, componentId: value.componentId }\n\t\t\t\t: undefined;\n\t\tcase \"engine_custom_done\":\n\t\t\treturn typeof value.componentId === \"string\"\n\t\t\t\t? { type: value.type, componentId: value.componentId, result: value.result }\n\t\t\t\t: undefined;\n\t\tcase \"engine_custom_terminal\": {\n\t\t\tconst control = parseEngineTerminalControl(value.control);\n\t\t\treturn typeof value.componentId === \"string\" && control\n\t\t\t\t? { type: value.type, componentId: value.componentId, control }\n\t\t\t\t: undefined;\n\t\t}\n\t\tcase \"engine_custom_control\":\n\t\t\treturn typeof value.componentId === \"string\" &&\n\t\t\t\t[\"focus\", \"hide\", \"show\", \"unfocus\"].includes(String(value.action))\n\t\t\t\t? {\n\t\t\t\t\t\ttype: value.type,\n\t\t\t\t\t\tcomponentId: value.componentId,\n\t\t\t\t\t\taction: value.action as \"focus\" | \"hide\" | \"show\" | \"unfocus\",\n\t\t\t\t\t}\n\t\t\t\t: undefined;\n\t\tcase \"engine_session_picker_open\": {\n\t\t\tconst sessions = parseSessionPickerRows(value.sessions);\n\t\t\treturn typeof value.componentId === \"string\" &&\n\t\t\t\tsessions &&\n\t\t\t\t(value.showRenameHint === undefined || typeof value.showRenameHint === \"boolean\")\n\t\t\t\t? {\n\t\t\t\t\t\ttype: value.type,\n\t\t\t\t\t\tcomponentId: value.componentId,\n\t\t\t\t\t\tsessions,\n\t\t\t\t\t\t...(typeof value.showRenameHint === \"boolean\" ? { showRenameHint: value.showRenameHint } : {}),\n\t\t\t\t\t}\n\t\t\t\t: undefined;\n\t\t}\n\t\tcase \"engine_session_picker_update\": {\n\t\t\tconst sessions = parseSessionPickerRows(value.sessions);\n\t\t\treturn typeof value.componentId === \"string\" && sessions\n\t\t\t\t? { type: value.type, componentId: value.componentId, sessions }\n\t\t\t\t: undefined;\n\t\t}\n\t\tcase \"engine_session_picker_error\":\n\t\t\treturn typeof value.componentId === \"string\" && typeof value.message === \"string\"\n\t\t\t\t? { type: value.type, componentId: value.componentId, message: value.message }\n\t\t\t\t: undefined;\n\t\tcase \"engine_session_picker_close\":\n\t\tcase \"engine_input_form_close\":\n\t\t\treturn typeof value.componentId === \"string\"\n\t\t\t\t? { type: value.type, componentId: value.componentId }\n\t\t\t\t: undefined;\n\t\tcase \"engine_input_form_open\": {\n\t\t\tconst fields = parseInputFormFields(value.fields);\n\t\t\treturn typeof value.componentId === \"string\" && typeof value.title === \"string\" && fields\n\t\t\t\t? {\n\t\t\t\t\t\ttype: value.type,\n\t\t\t\t\t\tcomponentId: value.componentId,\n\t\t\t\t\t\ttitle: value.title,\n\t\t\t\t\t\tfields,\n\t\t\t\t\t\t...(typeof value.heading === \"string\" ? { heading: value.heading } : {}),\n\t\t\t\t\t\t...(typeof value.submitLabel === \"string\" ? { submitLabel: value.submitLabel } : {}),\n\t\t\t\t\t}\n\t\t\t\t: undefined;\n\t\t}\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n}\n\nexport function parseInteractiveEngineCommand(line: string): InteractiveEngineCommand | undefined {\n\tconst value = parseJsonObject(line);\n\tif (!value || typeof value.type !== \"string\" || typeof value.componentId !== \"string\") return undefined;\n\tif (\n\t\tvalue.type === \"engine_custom_render\" &&\n\t\ttypeof value.requestId === \"number\" &&\n\t\ttypeof value.width === \"number\" &&\n\t\ttypeof value.rows === \"number\"\n\t) {\n\t\treturn {\n\t\t\ttype: value.type,\n\t\t\tcomponentId: value.componentId,\n\t\t\trequestId: value.requestId,\n\t\t\twidth: value.width,\n\t\t\trows: value.rows,\n\t\t};\n\t}\n\tif (value.type === \"engine_custom_input\" && typeof value.requestId === \"number\" && typeof value.data === \"string\")\n\t\treturn { type: value.type, componentId: value.componentId, requestId: value.requestId, data: value.data };\n\tif (value.type === \"engine_custom_dispose\" || value.type === \"engine_render_dispose\")\n\t\treturn { type: value.type, componentId: value.componentId };\n\tif (\n\t\t(value.type === \"engine_session_picker_select\" || value.type === \"engine_session_picker_delete\") &&\n\t\ttypeof value.path === \"string\"\n\t) {\n\t\treturn { type: value.type, componentId: value.componentId, path: value.path };\n\t}\n\tif (value.type === \"engine_session_picker_cancel\") return { type: value.type, componentId: value.componentId };\n\tif (value.type === \"engine_input_form_cancel\") return { type: value.type, componentId: value.componentId };\n\tif (value.type === \"engine_input_form_submit\") {\n\t\tconst values = parseStringRecord(value.values);\n\t\treturn values ? { type: value.type, componentId: value.componentId, values } : undefined;\n\t}\n\tif (\n\t\tvalue.type === \"engine_tool_render\" &&\n\t\ttypeof value.requestId === \"number\" &&\n\t\ttypeof value.width === \"number\" &&\n\t\ttypeof value.toolName === \"string\" &&\n\t\ttypeof value.toolCallId === \"string\" &&\n\t\ttypeof value.executionStarted === \"boolean\" &&\n\t\ttypeof value.argsComplete === \"boolean\" &&\n\t\ttypeof value.isPartial === \"boolean\" &&\n\t\ttypeof value.expanded === \"boolean\" &&\n\t\ttypeof value.showImages === \"boolean\" &&\n\t\ttypeof value.imageWidthCells === \"number\"\n\t) {\n\t\treturn {\n\t\t\ttype: value.type,\n\t\t\tcomponentId: value.componentId,\n\t\t\trequestId: value.requestId,\n\t\t\twidth: value.width,\n\t\t\ttoolName: value.toolName,\n\t\t\ttoolCallId: value.toolCallId,\n\t\t\targs: value.args,\n\t\t\tresult: isJsonObject(value.result) ? value.result : undefined,\n\t\t\texecutionStarted: value.executionStarted,\n\t\t\targsComplete: value.argsComplete,\n\t\t\tisPartial: value.isPartial,\n\t\t\texpanded: value.expanded,\n\t\t\tshowImages: value.showImages,\n\t\t\timageWidthCells: value.imageWidthCells,\n\t\t};\n\t}\n\tif (\n\t\tvalue.type === \"engine_message_render\" &&\n\t\ttypeof value.requestId === \"number\" &&\n\t\ttypeof value.width === \"number\" &&\n\t\tisJsonObject(value.message) &&\n\t\ttypeof value.expanded === \"boolean\" &&\n\t\ttypeof value.outputPad === \"number\"\n\t) {\n\t\treturn {\n\t\t\ttype: value.type,\n\t\t\tcomponentId: value.componentId,\n\t\t\trequestId: value.requestId,\n\t\t\twidth: value.width,\n\t\t\tmessage: value.message,\n\t\t\texpanded: value.expanded,\n\t\t\toutputPad: value.outputPad,\n\t\t};\n\t}\n\treturn undefined;\n}\n\nexport function serializeInteractiveEngineFrame(message: InteractiveEngineMessage | InteractiveEngineCommand): string {\n\treturn `${JSON.stringify(message)}\\n`;\n}\n\nexport const serializeInteractiveEngineMessage = serializeInteractiveEngineFrame;\n"]}
1
+ {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../../src/modes/interactive-engine/protocol.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,MAAM,CAAC,MAAM,mCAAmC,GAAG,CAAC,CAAC;AAmIrD,MAAM,cAAc,GAAoC;IACvD,gBAAgB;IAChB,UAAU;IACV,cAAc;IACd,cAAc;IACd,mBAAmB;IACnB,cAAc;IACd,wBAAwB;CACxB,CAAC;AAEF,MAAM,UAAU,WAAW,CAAC,KAAgD;IAC3E,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC7D,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;IAC1E,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,SAAS,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;AACtF,CAAC;AAED,SAAS,YAAY,CAAC,KAAgB;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC7E,CAAC;AAED,SAAS,cAAc,CAAC,KAAgB;IACvC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,cAAc,CAAC,QAAQ,CAAC,KAA6B,CAAC,CAAC;AAC5F,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAgB;IAC3C,OAAO,CACN,YAAY,CAAC,KAAK,CAAC;QACnB,OAAO,KAAK,CAAC,EAAE,KAAK,QAAQ;QAC5B,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC;QAC1B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AE,YAAY,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;YAC7D,gBAAgB,EAAE,KAAK,CAAC,gBAAgB;YACxC,YAAY,EAAE,KAAK,CAAC,YAAY;YAChC,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,UAAU,EAAE,KAAK,CAAC,UAAU;YAC5B,eAAe,EAAE,KAAK,CAAC,eAAe;SACtC,CAAC;IACH,CAAC;IACD,IACC,KAAK,CAAC,IAAI,KAAK,uBAAuB;QACtC,OAAO,KAAK,CAAC,SAAS,KAAK,QAAQ;QACnC,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ;QAC/B,YAAY,CAAC,KAAK,CAAC,OAAO,CAAC;QAC3B,OAAO,KAAK,CAAC,QAAQ,KAAK,SAAS;QACnC,OAAO,KAAK,CAAC,SAAS,KAAK,QAAQ,EAClC,CAAC;QACF,OAAO;YACN,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,WAAW,EAAE,KAAK,CAAC,WAAW;YAC9B,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,SAAS,EAAE,KAAK,CAAC,SAAS;SAC1B,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,+BAA+B,CAAC,OAA4D;IAC3G,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC;AACvC,CAAC;AAED,MAAM,CAAC,MAAM,iCAAiC,GAAG,+BAA+B,CAAC","sourcesContent":["import type { CallbackActivity, CallbackActivityKind } from \"../../core/callback-activity.ts\";\nimport type { HostInputFormField, HostSessionPickerRow } from \"../../core/extensions/ui-types.ts\";\nimport type { KeyId } from \"../../core/keybindings.ts\";\n\n/**\n * Version 3 adds correlated replies for `engine_custom_input`. The host uses\n * those replies to decide whether a matching fullscreen viewport key should be\n * replayed, so a child that cannot send them must not be treated as compatible.\n */\nexport const INTERACTIVE_ENGINE_PROTOCOL_VERSION = 3;\n\nexport interface JsonObject {\n\t[key: string]: JsonValue;\n}\n\nexport type JsonValue = boolean | JsonObject | JsonValue[] | null | number | string;\n\nexport interface SerializableOverlayOptions {\n\tanchor?: string;\n\tcol?: number | string;\n\tmargin?: number | { top?: number; right?: number; bottom?: number; left?: number };\n\tmaxHeight?: number | string;\n\tmaxWidth?: number | string;\n\tminHeight?: number;\n\tminWidth?: number;\n\toffsetX?: number;\n\toffsetY?: number;\n\trow?: number | string;\n\twidth?: number | string;\n}\n\n/**\n * Allowlisted terminal-mode control a remote custom component may ask the host\n * to apply to the real host TTY. Deliberately NOT a raw byte channel: the child\n * names an intent and the host owns the concrete escape sequence, so a buggy or\n * compromised child can only toggle this documented mode.\n */\nexport type EngineTerminalControl = { kind: \"autowrap\"; enabled: boolean };\n\nexport interface EngineExtensionShortcut {\n\tkey: string;\n\tdescription?: string;\n}\n\nexport type SerializableKeybindingsConfig = Record<string, KeyId | KeyId[]>;\n\nexport interface EngineKeybindingState {\n\tuserBindings: SerializableKeybindingsConfig;\n\teffectiveBindings: SerializableKeybindingsConfig;\n\tshortcuts: EngineExtensionShortcut[];\n}\n\nexport type InteractiveEngineMessage =\n\t| { type: \"engine_ready\"; protocolVersion: typeof INTERACTIVE_ENGINE_PROTOCOL_VERSION; pid: number }\n\t| { type: \"engine_bound\" }\n\t| { type: \"engine_keybindings_reloaded\"; state: EngineKeybindingState }\n\t| { type: \"engine_heartbeat\"; at: number }\n\t| { type: \"engine_activity_started\"; activity: CallbackActivity }\n\t| { type: \"engine_activity_finished\"; activityId: string }\n\t/**\n\t * The child took ownership of a correlated RPC request: it has parsed the\n\t * command and is about to run it. Emitted and flushed BEFORE any handler\n\t * work, so a later transport failure can be told apart from a send that\n\t * never landed. Output is not a substitute: a command can run to completion\n\t * with side effects and produce nothing.\n\t */\n\t| { type: \"engine_request_accepted\"; requestId: string; command: string }\n\t| {\n\t\t\ttype: \"engine_custom_open\";\n\t\t\tcomponentId: string;\n\t\t\toverlay: boolean;\n\t\t\tdeferInlineCustomUiFocus?: boolean;\n\t\t\thandlesCtrlC?: boolean;\n\t\t\thandlesInternalUiAction?: boolean;\n\t\t\treserveTranscriptRows?: boolean;\n\t\t\toverlayOptions?: SerializableOverlayOptions;\n\t\t\twidgetKey?: string;\n\t\t\twidgetPlacement?: \"aboveEditor\" | \"belowEditor\";\n\t }\n\t| { type: \"engine_custom_close\"; componentId: string }\n\t| { type: \"engine_custom_frame\"; componentId: string; requestId: number; lines: string[] }\n\t| { type: \"engine_custom_input_result\"; componentId: string; requestId: number; handled: boolean }\n\t| { type: \"engine_custom_invalidate\"; componentId: string }\n\t| { type: \"engine_custom_done\"; componentId: string; result?: JsonValue }\n\t| { type: \"engine_custom_terminal\"; componentId: string; control: EngineTerminalControl }\n\t| { type: \"engine_custom_control\"; componentId: string; action: \"focus\" | \"hide\" | \"show\" | \"unfocus\" }\n\t| {\n\t\t\ttype: \"engine_session_picker_open\";\n\t\t\tcomponentId: string;\n\t\t\tsessions: HostSessionPickerRow[];\n\t\t\tshowRenameHint?: boolean;\n\t }\n\t| { type: \"engine_session_picker_update\"; componentId: string; sessions: HostSessionPickerRow[] }\n\t| { type: \"engine_session_picker_error\"; componentId: string; message: string }\n\t| { type: \"engine_session_picker_close\"; componentId: string }\n\t| {\n\t\t\ttype: \"engine_input_form_open\";\n\t\t\tcomponentId: string;\n\t\t\ttitle: string;\n\t\t\tfields: HostInputFormField[];\n\t\t\theading?: string;\n\t\t\tsubmitLabel?: string;\n\t }\n\t| { type: \"engine_input_form_close\"; componentId: string };\nexport type InteractiveEngineCommand =\n\t| { type: \"engine_custom_render\"; componentId: string; requestId: number; width: number; rows: number }\n\t| { type: \"engine_custom_input\"; componentId: string; requestId: number; data: string }\n\t| { type: \"engine_custom_dispose\"; componentId: string }\n\t| {\n\t\t\ttype: \"engine_tool_render\";\n\t\t\tcomponentId: string;\n\t\t\trequestId: number;\n\t\t\twidth: number;\n\t\t\ttoolName: string;\n\t\t\ttoolCallId: string;\n\t\t\targs: JsonValue;\n\t\t\tresult?: JsonObject;\n\t\t\texecutionStarted: boolean;\n\t\t\targsComplete: boolean;\n\t\t\tisPartial: boolean;\n\t\t\texpanded: boolean;\n\t\t\tshowImages: boolean;\n\t\t\timageWidthCells: number;\n\t }\n\t| {\n\t\t\ttype: \"engine_message_render\";\n\t\t\tcomponentId: string;\n\t\t\trequestId: number;\n\t\t\twidth: number;\n\t\t\tmessage: JsonObject;\n\t\t\texpanded: boolean;\n\t\t\toutputPad: number;\n\t }\n\t| { type: \"engine_render_dispose\"; componentId: string }\n\t| { type: \"engine_session_picker_select\"; componentId: string; path: string }\n\t| { type: \"engine_session_picker_cancel\"; componentId: string }\n\t| { type: \"engine_session_picker_delete\"; componentId: string; path: string }\n\t| { type: \"engine_input_form_submit\"; componentId: string; values: Record<string, string> }\n\t| { type: \"engine_input_form_cancel\"; componentId: string };\n\nconst ACTIVITY_KINDS: readonly CallbackActivityKind[] = [\n\t\"extension.hook\",\n\t\"renderer\",\n\t\"tool.execute\",\n\t\"tool.prepare\",\n\t\"workflow.ctx_tool\",\n\t\"workflow.run\",\n\t\"workflow.stage_adapter\",\n];\n\nexport function isJsonValue(value: object | boolean | null | number | string): value is JsonValue {\n\tif (value === null || typeof value !== \"object\") return true;\n\tif (Array.isArray(value)) return value.every((item) => isJsonValue(item));\n\treturn Object.values(value).every((item) => item !== undefined && isJsonValue(item));\n}\n\nfunction isJsonObject(value: JsonValue): value is JsonObject {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction isActivityKind(value: JsonValue): value is CallbackActivityKind {\n\treturn typeof value === \"string\" && ACTIVITY_KINDS.includes(value as CallbackActivityKind);\n}\n\nfunction isCallbackActivity(value: JsonValue): value is JsonObject & CallbackActivity {\n\treturn (\n\t\tisJsonObject(value) &&\n\t\ttypeof value.id === \"string\" &&\n\t\tisActivityKind(value.kind) &&\n\t\ttypeof value.name === \"string\" &&\n\t\ttypeof value.startedAt === \"number\"\n\t);\n}\n\nfunction parseEngineTerminalControl(value: JsonValue | undefined): EngineTerminalControl | undefined {\n\tif (value === undefined || !isJsonObject(value) || value.kind !== \"autowrap\" || typeof value.enabled !== \"boolean\") {\n\t\treturn undefined;\n\t}\n\treturn { kind: \"autowrap\", enabled: value.enabled };\n}\n\nconst SESSION_PICKER_MESSAGE_COLORS = [\"success\", \"warning\", \"accent\", \"error\"] as const;\n\nfunction parseSessionPickerRow(value: JsonValue): HostSessionPickerRow | undefined {\n\tif (!isJsonObject(value)) return undefined;\n\tconst {\n\t\tpath,\n\t\tid,\n\t\tcwd,\n\t\tcreatedAt,\n\t\tmodifiedAt,\n\t\tmessageCount,\n\t\tfirstMessage,\n\t\tsummary,\n\t\tallMessagesText,\n\t\tname,\n\t\tmessageColor,\n\t} = value;\n\tif (\n\t\ttypeof path !== \"string\" ||\n\t\ttypeof id !== \"string\" ||\n\t\ttypeof cwd !== \"string\" ||\n\t\ttypeof createdAt !== \"number\" ||\n\t\ttypeof modifiedAt !== \"number\" ||\n\t\ttypeof messageCount !== \"number\" ||\n\t\ttypeof firstMessage !== \"string\"\n\t)\n\t\treturn undefined;\n\tif (summary !== undefined && typeof summary !== \"string\") return undefined;\n\tif (allMessagesText !== undefined && typeof allMessagesText !== \"string\") return undefined;\n\tif (name !== undefined && typeof name !== \"string\") return undefined;\n\tif (\n\t\tmessageColor !== undefined &&\n\t\t!SESSION_PICKER_MESSAGE_COLORS.includes(messageColor as (typeof SESSION_PICKER_MESSAGE_COLORS)[number])\n\t)\n\t\treturn undefined;\n\treturn {\n\t\tpath,\n\t\tid,\n\t\tcwd,\n\t\tcreatedAt,\n\t\tmodifiedAt,\n\t\tmessageCount,\n\t\tfirstMessage,\n\t\t...(summary !== undefined ? { summary } : {}),\n\t\t...(allMessagesText !== undefined ? { allMessagesText } : {}),\n\t\t...(name !== undefined ? { name } : {}),\n\t\t...(messageColor !== undefined\n\t\t\t? { messageColor: messageColor as (typeof SESSION_PICKER_MESSAGE_COLORS)[number] }\n\t\t\t: {}),\n\t};\n}\n\nfunction parseSessionPickerRows(value: JsonValue | undefined): HostSessionPickerRow[] | undefined {\n\tif (!Array.isArray(value)) return undefined;\n\tconst rows: HostSessionPickerRow[] = [];\n\tfor (const entry of value) {\n\t\tconst row = parseSessionPickerRow(entry);\n\t\tif (!row) return undefined;\n\t\trows.push(row);\n\t}\n\treturn rows;\n}\n\nconst INPUT_FORM_FIELD_TYPES = [\"string\", \"text\", \"number\", \"integer\", \"boolean\", \"select\"] as const;\n\nfunction parseInputFormFields(value: JsonValue | undefined): HostInputFormField[] | undefined {\n\tif (!Array.isArray(value)) return undefined;\n\tconst fields: HostInputFormField[] = [];\n\tfor (const entry of value) {\n\t\tif (!isJsonObject(entry)) return undefined;\n\t\tconst { name, type, description, required, choices, placeholder, initialValue } = entry;\n\t\tif (\n\t\t\ttypeof name !== \"string\" ||\n\t\t\t!INPUT_FORM_FIELD_TYPES.includes(type as HostInputFormField[\"type\"]) ||\n\t\t\ttypeof initialValue !== \"string\"\n\t\t)\n\t\t\treturn undefined;\n\t\tif (description !== undefined && typeof description !== \"string\") return undefined;\n\t\tif (required !== undefined && typeof required !== \"boolean\") return undefined;\n\t\tif (choices !== undefined && (!Array.isArray(choices) || !choices.every((choice) => typeof choice === \"string\")))\n\t\t\treturn undefined;\n\t\tif (placeholder !== undefined && typeof placeholder !== \"string\") return undefined;\n\t\tfields.push({\n\t\t\tname,\n\t\t\ttype: type as HostInputFormField[\"type\"],\n\t\t\tinitialValue,\n\t\t\t...(typeof description === \"string\" ? { description } : {}),\n\t\t\t...(typeof required === \"boolean\" ? { required } : {}),\n\t\t\t...(Array.isArray(choices) ? { choices: choices as string[] } : {}),\n\t\t\t...(typeof placeholder === \"string\" ? { placeholder } : {}),\n\t\t});\n\t}\n\treturn fields;\n}\n\nfunction parseStringRecord(value: JsonValue | undefined): Record<string, string> | undefined {\n\tif (value === undefined || !isJsonObject(value)) return undefined;\n\tconst entries = Object.entries(value);\n\tif (entries.some(([, entry]) => typeof entry !== \"string\")) return undefined;\n\treturn Object.fromEntries(entries) as Record<string, string>;\n}\n\nfunction parseKeybindingsConfig(value: JsonValue | undefined): SerializableKeybindingsConfig | undefined {\n\tif (value === undefined || !isJsonObject(value)) return undefined;\n\tconst config: SerializableKeybindingsConfig = {};\n\tfor (const [key, binding] of Object.entries(value)) {\n\t\tif (typeof binding === \"string\") config[key] = binding as SerializableKeybindingsConfig[string];\n\t\telse if (Array.isArray(binding) && binding.every((entry) => typeof entry === \"string\")) {\n\t\t\tconfig[key] = binding as SerializableKeybindingsConfig[string];\n\t\t} else return undefined;\n\t}\n\treturn config;\n}\n\nfunction parseKeybindingState(value: JsonValue | undefined): EngineKeybindingState | undefined {\n\tif (value === undefined || !isJsonObject(value) || !Array.isArray(value.shortcuts)) return undefined;\n\tconst userBindings = parseKeybindingsConfig(value.userBindings);\n\tconst effectiveBindings = parseKeybindingsConfig(value.effectiveBindings);\n\tif (!userBindings || !effectiveBindings) return undefined;\n\tconst shortcuts: EngineExtensionShortcut[] = [];\n\tfor (const shortcut of value.shortcuts) {\n\t\tif (\n\t\t\t!isJsonObject(shortcut) ||\n\t\t\ttypeof shortcut.key !== \"string\" ||\n\t\t\t(shortcut.description !== undefined && typeof shortcut.description !== \"string\")\n\t\t)\n\t\t\treturn undefined;\n\t\tshortcuts.push({\n\t\t\tkey: shortcut.key,\n\t\t\t...(typeof shortcut.description === \"string\" ? { description: shortcut.description } : {}),\n\t\t});\n\t}\n\treturn { userBindings, effectiveBindings, shortcuts };\n}\n\nfunction parseJsonObject(line: string): JsonObject | undefined {\n\tlet value: JsonValue;\n\ttry {\n\t\tvalue = JSON.parse(line) as JsonValue;\n\t} catch {\n\t\treturn undefined;\n\t}\n\treturn isJsonObject(value) ? value : undefined;\n}\n\nexport function parseInteractiveEngineMessage(line: string): InteractiveEngineMessage | undefined {\n\tconst value = parseJsonObject(line);\n\tif (!value || typeof value.type !== \"string\") return undefined;\n\tswitch (value.type) {\n\t\tcase \"engine_ready\":\n\t\t\treturn value.protocolVersion === INTERACTIVE_ENGINE_PROTOCOL_VERSION && typeof value.pid === \"number\"\n\t\t\t\t? { type: value.type, protocolVersion: INTERACTIVE_ENGINE_PROTOCOL_VERSION, pid: value.pid }\n\t\t\t\t: undefined;\n\t\tcase \"engine_bound\":\n\t\t\treturn { type: value.type };\n\t\tcase \"engine_keybindings_reloaded\": {\n\t\t\tconst state = parseKeybindingState(value.state);\n\t\t\treturn state ? { type: value.type, state } : undefined;\n\t\t}\n\t\tcase \"engine_heartbeat\":\n\t\t\treturn typeof value.at === \"number\" ? { type: value.type, at: value.at } : undefined;\n\t\tcase \"engine_activity_started\":\n\t\t\treturn isCallbackActivity(value.activity) ? { type: value.type, activity: value.activity } : undefined;\n\t\tcase \"engine_activity_finished\":\n\t\t\treturn typeof value.activityId === \"string\" ? { type: value.type, activityId: value.activityId } : undefined;\n\t\tcase \"engine_request_accepted\":\n\t\t\treturn typeof value.requestId === \"string\" && typeof value.command === \"string\"\n\t\t\t\t? { type: value.type, requestId: value.requestId, command: value.command }\n\t\t\t\t: undefined;\n\t\tcase \"engine_custom_open\":\n\t\t\treturn typeof value.componentId === \"string\" && typeof value.overlay === \"boolean\"\n\t\t\t\t? {\n\t\t\t\t\t\ttype: value.type,\n\t\t\t\t\t\tcomponentId: value.componentId,\n\t\t\t\t\t\toverlay: value.overlay,\n\t\t\t\t\t\tdeferInlineCustomUiFocus: value.deferInlineCustomUiFocus === true,\n\t\t\t\t\t\thandlesCtrlC: value.handlesCtrlC === true,\n\t\t\t\t\t\thandlesInternalUiAction: value.handlesInternalUiAction === true,\n\t\t\t\t\t\treserveTranscriptRows: value.reserveTranscriptRows === true,\n\t\t\t\t\t\toverlayOptions: isJsonObject(value.overlayOptions)\n\t\t\t\t\t\t\t? (value.overlayOptions as SerializableOverlayOptions)\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\twidgetKey: typeof value.widgetKey === \"string\" ? value.widgetKey : undefined,\n\t\t\t\t\t\twidgetPlacement:\n\t\t\t\t\t\t\tvalue.widgetPlacement === \"belowEditor\"\n\t\t\t\t\t\t\t\t? \"belowEditor\"\n\t\t\t\t\t\t\t\t: value.widgetPlacement === \"aboveEditor\"\n\t\t\t\t\t\t\t\t\t? \"aboveEditor\"\n\t\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t}\n\t\t\t\t: undefined;\n\t\tcase \"engine_custom_close\":\n\t\t\treturn typeof value.componentId === \"string\"\n\t\t\t\t? { type: value.type, componentId: value.componentId }\n\t\t\t\t: undefined;\n\t\tcase \"engine_custom_frame\":\n\t\t\treturn typeof value.componentId === \"string\" &&\n\t\t\t\ttypeof value.requestId === \"number\" &&\n\t\t\t\tArray.isArray(value.lines) &&\n\t\t\t\tvalue.lines.every((entry) => typeof entry === \"string\")\n\t\t\t\t? { type: value.type, componentId: value.componentId, requestId: value.requestId, lines: value.lines }\n\t\t\t\t: undefined;\n\t\tcase \"engine_custom_input_result\":\n\t\t\treturn typeof value.componentId === \"string\" &&\n\t\t\t\ttypeof value.requestId === \"number\" &&\n\t\t\t\ttypeof value.handled === \"boolean\"\n\t\t\t\t? { type: value.type, componentId: value.componentId, requestId: value.requestId, handled: value.handled }\n\t\t\t\t: undefined;\n\t\tcase \"engine_custom_invalidate\":\n\t\t\treturn typeof value.componentId === \"string\"\n\t\t\t\t? { type: value.type, componentId: value.componentId }\n\t\t\t\t: undefined;\n\t\tcase \"engine_custom_done\":\n\t\t\treturn typeof value.componentId === \"string\"\n\t\t\t\t? { type: value.type, componentId: value.componentId, result: value.result }\n\t\t\t\t: undefined;\n\t\tcase \"engine_custom_terminal\": {\n\t\t\tconst control = parseEngineTerminalControl(value.control);\n\t\t\treturn typeof value.componentId === \"string\" && control\n\t\t\t\t? { type: value.type, componentId: value.componentId, control }\n\t\t\t\t: undefined;\n\t\t}\n\t\tcase \"engine_custom_control\":\n\t\t\treturn typeof value.componentId === \"string\" &&\n\t\t\t\t[\"focus\", \"hide\", \"show\", \"unfocus\"].includes(String(value.action))\n\t\t\t\t? {\n\t\t\t\t\t\ttype: value.type,\n\t\t\t\t\t\tcomponentId: value.componentId,\n\t\t\t\t\t\taction: value.action as \"focus\" | \"hide\" | \"show\" | \"unfocus\",\n\t\t\t\t\t}\n\t\t\t\t: undefined;\n\t\tcase \"engine_session_picker_open\": {\n\t\t\tconst sessions = parseSessionPickerRows(value.sessions);\n\t\t\treturn typeof value.componentId === \"string\" &&\n\t\t\t\tsessions &&\n\t\t\t\t(value.showRenameHint === undefined || typeof value.showRenameHint === \"boolean\")\n\t\t\t\t? {\n\t\t\t\t\t\ttype: value.type,\n\t\t\t\t\t\tcomponentId: value.componentId,\n\t\t\t\t\t\tsessions,\n\t\t\t\t\t\t...(typeof value.showRenameHint === \"boolean\" ? { showRenameHint: value.showRenameHint } : {}),\n\t\t\t\t\t}\n\t\t\t\t: undefined;\n\t\t}\n\t\tcase \"engine_session_picker_update\": {\n\t\t\tconst sessions = parseSessionPickerRows(value.sessions);\n\t\t\treturn typeof value.componentId === \"string\" && sessions\n\t\t\t\t? { type: value.type, componentId: value.componentId, sessions }\n\t\t\t\t: undefined;\n\t\t}\n\t\tcase \"engine_session_picker_error\":\n\t\t\treturn typeof value.componentId === \"string\" && typeof value.message === \"string\"\n\t\t\t\t? { type: value.type, componentId: value.componentId, message: value.message }\n\t\t\t\t: undefined;\n\t\tcase \"engine_session_picker_close\":\n\t\tcase \"engine_input_form_close\":\n\t\t\treturn typeof value.componentId === \"string\"\n\t\t\t\t? { type: value.type, componentId: value.componentId }\n\t\t\t\t: undefined;\n\t\tcase \"engine_input_form_open\": {\n\t\t\tconst fields = parseInputFormFields(value.fields);\n\t\t\treturn typeof value.componentId === \"string\" && typeof value.title === \"string\" && fields\n\t\t\t\t? {\n\t\t\t\t\t\ttype: value.type,\n\t\t\t\t\t\tcomponentId: value.componentId,\n\t\t\t\t\t\ttitle: value.title,\n\t\t\t\t\t\tfields,\n\t\t\t\t\t\t...(typeof value.heading === \"string\" ? { heading: value.heading } : {}),\n\t\t\t\t\t\t...(typeof value.submitLabel === \"string\" ? { submitLabel: value.submitLabel } : {}),\n\t\t\t\t\t}\n\t\t\t\t: undefined;\n\t\t}\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n}\n\nexport function parseInteractiveEngineCommand(line: string): InteractiveEngineCommand | undefined {\n\tconst value = parseJsonObject(line);\n\tif (!value || typeof value.type !== \"string\" || typeof value.componentId !== \"string\") return undefined;\n\tif (\n\t\tvalue.type === \"engine_custom_render\" &&\n\t\ttypeof value.requestId === \"number\" &&\n\t\ttypeof value.width === \"number\" &&\n\t\ttypeof value.rows === \"number\"\n\t) {\n\t\treturn {\n\t\t\ttype: value.type,\n\t\t\tcomponentId: value.componentId,\n\t\t\trequestId: value.requestId,\n\t\t\twidth: value.width,\n\t\t\trows: value.rows,\n\t\t};\n\t}\n\tif (value.type === \"engine_custom_input\" && typeof value.requestId === \"number\" && typeof value.data === \"string\")\n\t\treturn { type: value.type, componentId: value.componentId, requestId: value.requestId, data: value.data };\n\tif (value.type === \"engine_custom_dispose\" || value.type === \"engine_render_dispose\")\n\t\treturn { type: value.type, componentId: value.componentId };\n\tif (\n\t\t(value.type === \"engine_session_picker_select\" || value.type === \"engine_session_picker_delete\") &&\n\t\ttypeof value.path === \"string\"\n\t) {\n\t\treturn { type: value.type, componentId: value.componentId, path: value.path };\n\t}\n\tif (value.type === \"engine_session_picker_cancel\") return { type: value.type, componentId: value.componentId };\n\tif (value.type === \"engine_input_form_cancel\") return { type: value.type, componentId: value.componentId };\n\tif (value.type === \"engine_input_form_submit\") {\n\t\tconst values = parseStringRecord(value.values);\n\t\treturn values ? { type: value.type, componentId: value.componentId, values } : undefined;\n\t}\n\tif (\n\t\tvalue.type === \"engine_tool_render\" &&\n\t\ttypeof value.requestId === \"number\" &&\n\t\ttypeof value.width === \"number\" &&\n\t\ttypeof value.toolName === \"string\" &&\n\t\ttypeof value.toolCallId === \"string\" &&\n\t\ttypeof value.executionStarted === \"boolean\" &&\n\t\ttypeof value.argsComplete === \"boolean\" &&\n\t\ttypeof value.isPartial === \"boolean\" &&\n\t\ttypeof value.expanded === \"boolean\" &&\n\t\ttypeof value.showImages === \"boolean\" &&\n\t\ttypeof value.imageWidthCells === \"number\"\n\t) {\n\t\treturn {\n\t\t\ttype: value.type,\n\t\t\tcomponentId: value.componentId,\n\t\t\trequestId: value.requestId,\n\t\t\twidth: value.width,\n\t\t\ttoolName: value.toolName,\n\t\t\ttoolCallId: value.toolCallId,\n\t\t\targs: value.args,\n\t\t\tresult: isJsonObject(value.result) ? value.result : undefined,\n\t\t\texecutionStarted: value.executionStarted,\n\t\t\targsComplete: value.argsComplete,\n\t\t\tisPartial: value.isPartial,\n\t\t\texpanded: value.expanded,\n\t\t\tshowImages: value.showImages,\n\t\t\timageWidthCells: value.imageWidthCells,\n\t\t};\n\t}\n\tif (\n\t\tvalue.type === \"engine_message_render\" &&\n\t\ttypeof value.requestId === \"number\" &&\n\t\ttypeof value.width === \"number\" &&\n\t\tisJsonObject(value.message) &&\n\t\ttypeof value.expanded === \"boolean\" &&\n\t\ttypeof value.outputPad === \"number\"\n\t) {\n\t\treturn {\n\t\t\ttype: value.type,\n\t\t\tcomponentId: value.componentId,\n\t\t\trequestId: value.requestId,\n\t\t\twidth: value.width,\n\t\t\tmessage: value.message,\n\t\t\texpanded: value.expanded,\n\t\t\toutputPad: value.outputPad,\n\t\t};\n\t}\n\treturn undefined;\n}\n\nexport function serializeInteractiveEngineFrame(message: InteractiveEngineMessage | InteractiveEngineCommand): string {\n\treturn `${JSON.stringify(message)}\\n`;\n}\n\nexport const serializeInteractiveEngineMessage = serializeInteractiveEngineFrame;\n"]}
@@ -1,5 +1,7 @@
1
1
  import type { ExtensionUIContext } from "../../core/extensions/index.ts";
2
2
  import type { IsolatedInteractiveRuntime } from "./isolated-runtime.ts";
3
+ export type RemoteComponentRuntime = Pick<IsolatedInteractiveRuntime, "onEngineMessage" | "onGenerationEnded" | "sendEngineCommand">;
4
+ export type RemoteComponentUI = Pick<ExtensionUIContext, "custom" | "requestRender" | "setWidget">;
3
5
  /**
4
6
  * A stalled engine must not make fullscreen input wait forever. A timed-out
5
7
  * reply is treated as unhandled and lets the viewport process the key.
@@ -17,7 +19,7 @@ export declare class RemoteComponentController {
17
19
  private readonly unsubscribeTuiRendererReplaced;
18
20
  private readonly runtime;
19
21
  private readonly ui;
20
- constructor(runtime: IsolatedInteractiveRuntime, ui: ExtensionUIContext, tuiRendererLifecycle: TuiRendererLifecycle);
22
+ constructor(runtime: RemoteComponentRuntime, ui: RemoteComponentUI, tuiRendererLifecycle: TuiRendererLifecycle);
21
23
  dispose(): void;
22
24
  /** The remote overlay proxy that currently holds focus (see remote-input-ownership.ts). */
23
25
  focusedRemoteOverlay(): unknown;
@@ -1 +1 @@
1
- {"version":3,"file":"remote-component.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive-engine/remote-component.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AAiBxE;;;GAGG;AACH,eAAO,MAAM,6BAA6B,MAAM,CAAC;AA+IjD,MAAM,WAAW,oBAAoB;IACpC,YAAY,IAAI,OAAO,CAAC;IACxB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC;CACrD;AAED,qBAAa,yBAAyB;IACrC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA6C;IACrE,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAa;IACzC,OAAO,CAAC,QAAQ,CAAC,0BAA0B,CAAa;IACxD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAyB;IACvD,OAAO,CAAC,QAAQ,CAAC,8BAA8B,CAAa;IAE5D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA6B;IACrD,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAqB;IAExC,YACC,OAAO,EAAE,0BAA0B,EACnC,EAAE,EAAE,kBAAkB,EACtB,oBAAoB,EAAE,oBAAoB,EAa1C;IAED,OAAO,IAAI,IAAI,CAKd;IAED,2FAA2F;IAC3F,oBAAoB,IAAI,OAAO,CAK9B;IAED,sFAAsF;IACtF,gBAAgB,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,CAM5C;IAED,iFAAiF;IACjF,uBAAuB,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,CAKnD;IAED;;;;;;;;;;OAUG;IACH,kBAAkB,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,CAQ9C;IAED;;;;;;;;;;;;;;;;;OAiBG;IACH,OAAO,CAAC,UAAU;IAalB,OAAO,CAAC,aAAa;IAkDrB,OAAO,CAAC,IAAI;IA6EZ,OAAO,CAAC,KAAK;IASb,OAAO,CAAC,OAAO;CAkBf"}
1
+ {"version":3,"file":"remote-component.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive-engine/remote-component.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AAKxE,MAAM,MAAM,sBAAsB,GAAG,IAAI,CACxC,0BAA0B,EAC1B,iBAAiB,GAAG,mBAAmB,GAAG,mBAAmB,CAC7D,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAAC,kBAAkB,EAAE,QAAQ,GAAG,eAAe,GAAG,WAAW,CAAC,CAAC;AAcnG;;;GAGG;AACH,eAAO,MAAM,6BAA6B,MAAM,CAAC;AA+IjD,MAAM,WAAW,oBAAoB;IACpC,YAAY,IAAI,OAAO,CAAC;IACxB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC;CACrD;AAED,qBAAa,yBAAyB;IACrC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA6C;IACrE,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAa;IACzC,OAAO,CAAC,QAAQ,CAAC,0BAA0B,CAAa;IACxD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAyB;IACvD,OAAO,CAAC,QAAQ,CAAC,8BAA8B,CAAa;IAE5D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAyB;IACjD,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAoB;IAEvC,YAAY,OAAO,EAAE,sBAAsB,EAAE,EAAE,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,oBAAoB,EAY7G;IAED,OAAO,IAAI,IAAI,CAKd;IAED,2FAA2F;IAC3F,oBAAoB,IAAI,OAAO,CAK9B;IAED,sFAAsF;IACtF,gBAAgB,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,CAM5C;IAED,iFAAiF;IACjF,uBAAuB,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,CAKnD;IAED;;;;;;;;;;OAUG;IACH,kBAAkB,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,CAQ9C;IAED;;;;;;;;;;;;;;;;;OAiBG;IACH,OAAO,CAAC,UAAU;IAalB,OAAO,CAAC,aAAa;IAmDrB,OAAO,CAAC,IAAI;IA+EZ,OAAO,CAAC,KAAK;IASb,OAAO,CAAC,OAAO;CAkBf"}
@@ -234,7 +234,7 @@ export class RemoteComponentController {
234
234
  this.disposeAll("generation-lost");
235
235
  break;
236
236
  case "engine_custom_open":
237
- this.open(message.componentId, message.overlay, message.deferInlineCustomUiFocus, message.overlayOptions, message.widgetKey, message.widgetPlacement, message.handlesCtrlC === true, message.handlesInternalUiAction === true);
237
+ this.open(message.componentId, message.overlay, message.deferInlineCustomUiFocus, message.overlayOptions, message.widgetKey, message.widgetPlacement, message.handlesCtrlC === true, message.handlesInternalUiAction === true, message.reserveTranscriptRows === true);
238
238
  break;
239
239
  case "engine_custom_close":
240
240
  this.close(message.componentId);
@@ -264,7 +264,7 @@ export class RemoteComponentController {
264
264
  break;
265
265
  }
266
266
  }
267
- open(componentId, overlay, deferInlineCustomUiFocus, options, widgetKey, widgetPlacement, handlesCtrlC = false, handlesInternalUiAction = false) {
267
+ open(componentId, overlay, deferInlineCustomUiFocus, options, widgetKey, widgetPlacement, handlesCtrlC = false, handlesInternalUiAction = false, reserveTranscriptRows = false) {
268
268
  if (this.mounted.has(componentId))
269
269
  return;
270
270
  if (widgetKey) {
@@ -298,6 +298,7 @@ export class RemoteComponentController {
298
298
  overlay,
299
299
  deferInlineCustomUiFocus,
300
300
  handlesInternalUiAction,
301
+ reserveTranscriptRows,
301
302
  overlayOptions: overlayOptions(options),
302
303
  onHandle: (handle) => {
303
304
  if (mounted)
@@ -1 +1 @@
1
- {"version":3,"file":"remote-component.js","sourceRoot":"","sources":["../../../src/modes/interactive-engine/remote-component.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAcvE;;;GAGG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,GAAG,CAAC;AAOjD,MAAM,eAAe;IAmBpB,YACC,WAAmB,EACnB,OAAmC,EACnC,aAAyB,EACzB,OAAqB,EACrB,uBAAuB,GAAG,KAAK;QAvBhC,oBAAe,GAAG,IAAI,CAAC;QAEf,UAAK,GAAG,CAAC,2BAA2B,CAAC,CAAC;QACtC,UAAK,GAAG,CAAC,CAAC;QACV,SAAI,GAAG,CAAC,CAAC;QACT,cAAS,GAAG,CAAC,CAAC;QACd,mBAAc,GAAG,CAAC,CAAC;QACnB,qBAAgB,GAAG,CAAC,CAAC;QACrB,UAAK,GAAG,IAAI,CAAC;QACb,aAAQ,GAAG,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M,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;QACrD,IAAI,CAAC,MAAM;YAAE,OAAO;QACpB,QAAQ,MAAM,EAAE,CAAC;YAChB,KAAK,OAAO;gBACX,MAAM,CAAC,KAAK,EAAE,CAAC;gBACf,MAAM;YACP,KAAK,MAAM;gBACV,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;gBACvB,MAAM;YACP,KAAK,MAAM;gBACV,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;gBACxB,MAAM;YACP,KAAK,SAAS;gBACb,MAAM,CAAC,OAAO,EAAE,CAAC;gBACjB,MAAM;QACR,CAAC;IACF,CAAC;CACD","sourcesContent":["import type { Component, OverlayHandle, OverlayOptions, TUI } from \"@earendil-works/pi-tui\";\nimport type { ExtensionUIContext } from \"../../core/extensions/index.ts\";\nimport type { IsolatedInteractiveRuntime } from \"./isolated-runtime.ts\";\nimport type { InteractiveEngineMessage, JsonValue, SerializableOverlayOptions } from \"./protocol.ts\";\nimport { RemoteFrameWidthClamp } from \"./remote-frame-clamp.ts\";\nimport { TerminalModeController } from \"./terminal-mode-controller.ts\";\n\ninterface MountedRemoteComponent {\n\tcomponent: RemoteComponent;\n\tdone: (result: JsonValue | undefined) => void;\n\tengineDone: boolean;\n\t/** The extension declared that this component binds Ctrl+C itself. */\n\thandlesCtrlC: boolean;\n\t/** The extension declared that this component claims internal UI actions. */\n\thandlesInternalUiAction: boolean;\n\thandle?: OverlayHandle;\n\twidgetKey?: string;\n}\n\n/**\n * A stalled engine must not make fullscreen input wait forever. A timed-out\n * reply is treated as unhandled and lets the viewport process the key.\n */\nexport const REMOTE_INPUT_REPLY_TIMEOUT_MS = 250;\n\ninterface PendingInput {\n\tresolve: (handled: boolean | undefined) => void;\n\ttimer: ReturnType<typeof setTimeout>;\n}\n\nclass RemoteComponent implements Component {\n\twantsKeyRelease = true;\n\treadonly handlesInternalUiAction: boolean;\n\tprivate lines = [\"Loading remote component…\"];\n\tprivate width = 0;\n\tprivate rows = 0;\n\tprivate requestId = 0;\n\tprivate inputRequestId = 0;\n\tprivate appliedRequestId = 0;\n\tprivate dirty = true;\n\tprivate disposed = false;\n\tprivate readonly pendingInputs = new Map<number, PendingInput>();\n\tprivate readonly frameClamp = new RemoteFrameWidthClamp();\n\n\tprivate readonly componentId: string;\n\tprivate readonly runtime: IsolatedInteractiveRuntime;\n\tprivate readonly requestRender: () => void;\n\tprivate readonly getRows: () => number;\n\n\tconstructor(\n\t\tcomponentId: string,\n\t\truntime: IsolatedInteractiveRuntime,\n\t\trequestRender: () => void,\n\t\tgetRows: () => number,\n\t\thandlesInternalUiAction = false,\n\t) {\n\t\tthis.componentId = componentId;\n\t\tthis.runtime = runtime;\n\t\tthis.requestRender = requestRender;\n\t\tthis.getRows = getRows;\n\t\tthis.handlesInternalUiAction = handlesInternalUiAction;\n\t}\n\n\trender(width: number): string[] {\n\t\tconst rows = this.getRows();\n\t\tif (!this.disposed && (this.dirty || width !== this.width || rows !== this.rows)) {\n\t\t\tthis.width = width;\n\t\t\tthis.rows = rows;\n\t\t\tthis.dirty = false;\n\t\t\tthis.runtime.sendEngineCommand({\n\t\t\t\ttype: \"engine_custom_render\",\n\t\t\t\tcomponentId: this.componentId,\n\t\t\t\trequestId: ++this.requestId,\n\t\t\t\twidth,\n\t\t\t\trows,\n\t\t\t});\n\t\t}\n\t\t// The engine child re-renders asynchronously; until the fresh frame\n\t\t// arrives, the previous frame may be wrapped for an older terminal\n\t\t// width. Clamp so a resize never replays overflowing lines (pi-tui\n\t\t// crashes on any rendered line wider than the terminal).\n\t\treturn this.frameClamp.clamp(this.lines, width);\n\t}\n\n\thandleInput(data: string): Promise<boolean | undefined> {\n\t\tif (this.disposed) return Promise.resolve(undefined);\n\t\tconst requestId = ++this.inputRequestId;\n\t\tconst result = new Promise<boolean | undefined>((resolve) => {\n\t\t\tconst timer = setTimeout(() => this.resolveInput(requestId, false), REMOTE_INPUT_REPLY_TIMEOUT_MS);\n\t\t\ttimer.unref?.();\n\t\t\tthis.pendingInputs.set(requestId, { resolve, timer });\n\t\t});\n\t\ttry {\n\t\t\tthis.runtime.sendEngineCommand({\n\t\t\t\ttype: \"engine_custom_input\",\n\t\t\t\tcomponentId: this.componentId,\n\t\t\t\trequestId,\n\t\t\t\tdata,\n\t\t\t});\n\t\t} catch {\n\t\t\tthis.resolveInput(requestId, false);\n\t\t}\n\t\t// Engine commands are delivered in order, so a frame requested now is\n\t\t// rendered by the child only AFTER it has applied this input. Pipelining\n\t\t// the request keeps keypress latency at a single round trip and repaints\n\t\t// components that never self-invalidate, instead of waiting for a\n\t\t// child-side invalidate (or an unrelated refresh) to trigger a frame.\n\t\tthis.dirty = true;\n\t\tthis.requestRender();\n\t\treturn result;\n\t}\n\n\tresolveInput(requestId: number, handled: boolean | undefined): void {\n\t\tconst pending = this.pendingInputs.get(requestId);\n\t\tif (!pending) return;\n\t\tthis.pendingInputs.delete(requestId);\n\t\tclearTimeout(pending.timer);\n\t\tpending.resolve(handled);\n\t}\n\n\tinvalidate(): void {\n\t\tthis.dirty = true;\n\t}\n\n\tapplyFrame(requestId: number, lines: string[]): void {\n\t\tif (this.disposed || requestId < this.appliedRequestId) return;\n\t\tthis.appliedRequestId = requestId;\n\t\tthis.lines = lines;\n\t\tthis.requestRender();\n\t}\n\n\trequestRemoteRender(): void {\n\t\tif (this.disposed) return;\n\t\tthis.dirty = true;\n\t\tthis.requestRender();\n\t}\n\n\t/**\n\t * Tear the proxy down. `notifyEngine` must be false once the writer no longer\n\t * points at the generation that owns this component: component IDs restart at\n\t * `remote_component_1` for every child, so a late dispose would address an\n\t * unrelated component in the replacement engine.\n\t */\n\tdispose(notifyEngine = true): void {\n\t\tif (this.disposed) return;\n\t\tthis.disposed = true;\n\t\tfor (const requestId of [...this.pendingInputs.keys()]) this.resolveInput(requestId, undefined);\n\t\tif (notifyEngine)\n\t\t\tthis.runtime.sendEngineCommand({ type: \"engine_custom_dispose\", componentId: this.componentId });\n\t}\n}\n\nfunction overlayOptions(options: SerializableOverlayOptions | undefined): OverlayOptions | undefined {\n\treturn options as OverlayOptions | undefined;\n}\n\n/**\n * Resolve the real host terminal from the pi-tui TUI handed to the overlay\n * factory. Optional: some hosts / test seams do not surface `tui.terminal`, in\n * which case terminal-mode controls harmlessly no-op.\n */\nfunction hostTerminal(tui: TUI): { write(data: string): void } {\n\tconst terminal = (tui as { terminal?: { write?(data: string): void } }).terminal;\n\treturn typeof terminal?.write === \"function\" ? (terminal as { write(data: string): void }) : { write: () => {} };\n}\n\nexport interface TuiRendererLifecycle {\n\tisFullscreen(): boolean;\n\tonRendererReplaced(listener: () => void): () => void;\n}\n\nexport class RemoteComponentController {\n\tprivate readonly mounted = new Map<string, MountedRemoteComponent>();\n\tprivate readonly unsubscribe: () => void;\n\tprivate readonly unsubscribeGenerationEnded: () => void;\n\tprivate readonly terminalModes: TerminalModeController;\n\tprivate readonly unsubscribeTuiRendererReplaced: () => void;\n\n\tprivate readonly runtime: IsolatedInteractiveRuntime;\n\tprivate readonly ui: ExtensionUIContext;\n\n\tconstructor(\n\t\truntime: IsolatedInteractiveRuntime,\n\t\tui: ExtensionUIContext,\n\t\ttuiRendererLifecycle: TuiRendererLifecycle,\n\t) {\n\t\tthis.runtime = runtime;\n\t\tthis.ui = ui;\n\t\tthis.terminalModes = new TerminalModeController(() => tuiRendererLifecycle.isFullscreen());\n\t\tthis.unsubscribeTuiRendererReplaced = tuiRendererLifecycle.onRendererReplaced(() =>\n\t\t\tthis.terminalModes.rebindTui(),\n\t\t);\n\t\tthis.unsubscribe = runtime.onEngineMessage((message) => this.handleMessage(message));\n\t\t// Teardown is driven by engine death rather than the NEXT generation's\n\t\t// `engine_ready`, so a crash with no restart, or a hung/failed restart,\n\t\t// still releases the host editor, focus, and inline-custom-UI depth.\n\t\tthis.unsubscribeGenerationEnded = runtime.onGenerationEnded(() => this.disposeAll(\"generation-lost\"));\n\t}\n\n\tdispose(): void {\n\t\tthis.unsubscribeTuiRendererReplaced();\n\t\tthis.unsubscribe();\n\t\tthis.unsubscribeGenerationEnded();\n\t\tthis.disposeAll(\"host-shutdown\");\n\t}\n\n\t/** The remote overlay proxy that currently holds focus (see remote-input-ownership.ts). */\n\tfocusedRemoteOverlay(): unknown {\n\t\tfor (const record of this.mounted.values()) {\n\t\t\tif (record.handle?.isFocused() === true) return record.component;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/** `component` itself when it is one of this generation's live non-widget proxies. */\n\tremoteProxyOwner(component: unknown): unknown {\n\t\tif (!(component instanceof RemoteComponent)) return undefined;\n\t\tfor (const record of this.mounted.values()) {\n\t\t\tif (record.component === component) return record.widgetKey === undefined ? component : undefined;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/** True when the extension that mounted `component` declared it binds Ctrl+C. */\n\tremoteProxyHandlesCtrlC(component: unknown): boolean {\n\t\tfor (const record of this.mounted.values()) {\n\t\t\tif (record.component === component) return record.handlesCtrlC;\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Close exactly one live proxy through the ordinary host close path.\n\t *\n\t * The host escape from a component that traps Ctrl+C, and deliberately not\n\t * `disposeAll()`: that is generation-death teardown, which would also close\n\t * unrelated nested components and suppress the child notification. Here the\n\t * record stays registered while `done` runs, so `showExtensionCustom()`\n\t * hides this overlay (or remounts the editor) and its finalizer disposes the\n\t * proxy normally — which tells the healthy child to resolve its own\n\t * `ui.custom()` promise with `undefined`, exactly like a user cancel.\n\t */\n\tdismissRemoteProxy(component: unknown): boolean {\n\t\tfor (const record of this.mounted.values()) {\n\t\t\tif (record.component !== component || record.widgetKey !== undefined) continue;\n\t\t\trecord.done(undefined);\n\t\t\tthis.ui.requestRender();\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Close every mounted component.\n\t *\n\t * `\"generation-lost\"` closes through the real host close path: it hides the\n\t * overlay or remounts the editor into `editorContainer`, restores the saved\n\t * draft and focus, releases `blockingInlineCustomUiDepth`, and resolves the\n\t * extension's `ui.custom()` promise. Records are removed BEFORE each `done`\n\t * runs so the settlement path cannot re-enter the controller, and proxy\n\t * disposal is local-only because the writer already points at a replacement\n\t * child whose component IDs restart at `remote_component_1`.\n\t *\n\t * Order is newest-first, matching the TUI's overlay stack. Closing oldest\n\t * first would let an overlay mounted above an inline proxy restore focus to\n\t * that inline proxy after it had already been disposed.\n\t *\n\t * `\"host-shutdown\"` notifies the still-live engine child instead and leaves\n\t * host mounts alone: the TUI is already stopping and must not repaint.\n\t */\n\tprivate disposeAll(reason: \"generation-lost\" | \"host-shutdown\"): void {\n\t\tconst records = [...this.mounted.entries()].reverse();\n\t\tthis.mounted.clear();\n\t\tfor (const [componentId, record] of records) {\n\t\t\tthis.terminalModes.onUnmount(componentId);\n\t\t\trecord.component.dispose(reason === \"host-shutdown\" && !record.engineDone);\n\t\t\tif (record.widgetKey) this.ui.setWidget(record.widgetKey, undefined);\n\t\t\telse if (reason === \"generation-lost\") record.done(undefined);\n\t\t}\n\t\tthis.terminalModes.resetAll();\n\t\tif (reason === \"generation-lost\" && records.length > 0) this.ui.requestRender();\n\t}\n\n\tprivate handleMessage(message: InteractiveEngineMessage): void {\n\t\tswitch (message.type) {\n\t\t\tcase \"engine_ready\":\n\t\t\t\t// Idempotent fallback for a generation replacement whose death event\n\t\t\t\t// was already handled: stale records must be gone before the new child\n\t\t\t\t// can reuse `remote_component_1`, and any terminal modes the dead\n\t\t\t\t// generation left on are reset here too.\n\t\t\t\tthis.disposeAll(\"generation-lost\");\n\t\t\t\tbreak;\n\t\t\tcase \"engine_custom_open\":\n\t\t\t\tthis.open(\n\t\t\t\t\tmessage.componentId,\n\t\t\t\t\tmessage.overlay,\n\t\t\t\t\tmessage.deferInlineCustomUiFocus,\n\t\t\t\t\tmessage.overlayOptions,\n\t\t\t\t\tmessage.widgetKey,\n\t\t\t\t\tmessage.widgetPlacement,\n\t\t\t\t\tmessage.handlesCtrlC === true,\n\t\t\t\t\tmessage.handlesInternalUiAction === true,\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\tcase \"engine_custom_close\":\n\t\t\t\tthis.close(message.componentId);\n\t\t\t\tbreak;\n\t\t\tcase \"engine_custom_frame\":\n\t\t\t\tthis.mounted.get(message.componentId)?.component.applyFrame(message.requestId, message.lines);\n\t\t\t\tbreak;\n\t\t\tcase \"engine_custom_input_result\":\n\t\t\t\tthis.mounted.get(message.componentId)?.component.resolveInput(message.requestId, message.handled);\n\t\t\t\tbreak;\n\t\t\tcase \"engine_custom_invalidate\":\n\t\t\t\tthis.mounted.get(message.componentId)?.component.requestRemoteRender();\n\t\t\t\tbreak;\n\t\t\tcase \"engine_custom_terminal\":\n\t\t\t\tthis.terminalModes.applyControl(message.componentId, message.control);\n\t\t\t\tbreak;\n\t\t\tcase \"engine_custom_done\": {\n\t\t\t\tconst record = this.mounted.get(message.componentId);\n\t\t\t\tif (record) {\n\t\t\t\t\trecord.engineDone = true;\n\t\t\t\t\trecord.done(message.result);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"engine_custom_control\":\n\t\t\t\tthis.control(message.componentId, message.action);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tprivate open(\n\t\tcomponentId: string,\n\t\toverlay: boolean,\n\t\tdeferInlineCustomUiFocus: boolean | undefined,\n\t\toptions: SerializableOverlayOptions | undefined,\n\t\twidgetKey?: string,\n\t\twidgetPlacement?: \"aboveEditor\" | \"belowEditor\",\n\t\thandlesCtrlC = false,\n\t\thandlesInternalUiAction = false,\n\t): void {\n\t\tif (this.mounted.has(componentId)) return;\n\t\tif (widgetKey) {\n\t\t\tlet rows = 24;\n\t\t\tconst component = new RemoteComponent(\n\t\t\t\tcomponentId,\n\t\t\t\tthis.runtime,\n\t\t\t\t() => this.ui.requestRender(),\n\t\t\t\t() => rows,\n\t\t\t\thandlesInternalUiAction,\n\t\t\t);\n\t\t\tthis.mounted.set(componentId, {\n\t\t\t\tcomponent,\n\t\t\t\tdone: () => {},\n\t\t\t\tengineDone: false,\n\t\t\t\thandlesCtrlC,\n\t\t\t\thandlesInternalUiAction,\n\t\t\t\twidgetKey,\n\t\t\t});\n\t\t\tthis.ui.setWidget(\n\t\t\t\twidgetKey,\n\t\t\t\t(tui) => {\n\t\t\t\t\trows = tui.terminal.rows;\n\t\t\t\t\treturn component;\n\t\t\t\t},\n\t\t\t\t{ placement: widgetPlacement },\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tlet mounted: MountedRemoteComponent | undefined;\n\t\tvoid this.ui\n\t\t\t.custom<JsonValue | undefined>(\n\t\t\t\t(tui, _theme, _keybindings, done) => {\n\t\t\t\t\tconst component = new RemoteComponent(\n\t\t\t\t\t\tcomponentId,\n\t\t\t\t\t\tthis.runtime,\n\t\t\t\t\t\t() => this.ui.requestRender(),\n\t\t\t\t\t\t() => tui.terminal.rows,\n\t\t\t\t\t\thandlesInternalUiAction,\n\t\t\t\t\t);\n\t\t\t\t\tmounted = { component, done, engineDone: false, handlesCtrlC, handlesInternalUiAction };\n\t\t\t\t\tthis.mounted.set(componentId, mounted);\n\t\t\t\t\t// Bind this component to the real host terminal so a buffered\n\t\t\t\t\t// autowrap control emitted before the mount frame applies to the host TTY.\n\t\t\t\t\tthis.terminalModes.onMount(componentId, hostTerminal(tui));\n\t\t\t\t\treturn component;\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\toverlay,\n\t\t\t\t\tdeferInlineCustomUiFocus,\n\t\t\t\t\thandlesInternalUiAction,\n\t\t\t\t\toverlayOptions: overlayOptions(options),\n\t\t\t\t\tonHandle: (handle) => {\n\t\t\t\t\t\tif (mounted) mounted.handle = handle;\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t)\n\t\t\t.catch(() => undefined)\n\t\t\t.finally(() => {\n\t\t\t\tthis.terminalModes.onUnmount(componentId);\n\t\t\t\tconst record = this.mounted.get(componentId);\n\t\t\t\tif (!record) return;\n\t\t\t\tthis.mounted.delete(componentId);\n\t\t\t\tif (record.engineDone) record.component.dispose(false);\n\t\t\t\telse record.component.dispose();\n\t\t\t});\n\t}\n\n\tprivate close(componentId: string): void {\n\t\tconst record = this.mounted.get(componentId);\n\t\tif (!record) return;\n\t\tthis.terminalModes.onUnmount(componentId);\n\t\tthis.mounted.delete(componentId);\n\t\tif (record.widgetKey) this.ui.setWidget(record.widgetKey, undefined);\n\t\trecord.component.dispose();\n\t}\n\n\tprivate control(componentId: string, action: \"focus\" | \"hide\" | \"show\" | \"unfocus\"): void {\n\t\tconst handle = this.mounted.get(componentId)?.handle;\n\t\tif (!handle) return;\n\t\tswitch (action) {\n\t\t\tcase \"focus\":\n\t\t\t\thandle.focus();\n\t\t\t\tbreak;\n\t\t\tcase \"hide\":\n\t\t\t\thandle.setHidden(true);\n\t\t\t\tbreak;\n\t\t\tcase \"show\":\n\t\t\t\thandle.setHidden(false);\n\t\t\t\tbreak;\n\t\t\tcase \"unfocus\":\n\t\t\t\thandle.unfocus();\n\t\t\t\tbreak;\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"remote-component.js","sourceRoot":"","sources":["../../../src/modes/interactive-engine/remote-component.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAqBvE;;;GAGG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,GAAG,CAAC;AAOjD,MAAM,eAAe;IAmBpB,YACC,WAAmB,EACnB,OAA+B,EAC/B,aAAyB,EACzB,OAAqB,EACrB,uBAAuB,GAAG,KAAK;QAvBhC,oBAAe,GAAG,IAAI,CAAC;QAEf,UAAK,GAAG,CAAC,2BAA2B,CAAC,CAAC;QACtC,UAAK,GAAG,CAAC,CAAC;QACV,SAAI,GAAG,CAAC,CAAC;QACT,cAAS,GAAG,CAAC,CAAC;QACd,mBAAc,GAAG,CAAC,CAAC;QACnB,qBAAgB,GAAG,C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EAAE,SAAS,CAAC,CAAC;QACrE,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;IAC5B,CAAC;IAEO,OAAO,CAAC,WAAmB,EAAE,MAA6C;QACjF,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;QACrD,IAAI,CAAC,MAAM;YAAE,OAAO;QACpB,QAAQ,MAAM,EAAE,CAAC;YAChB,KAAK,OAAO;gBACX,MAAM,CAAC,KAAK,EAAE,CAAC;gBACf,MAAM;YACP,KAAK,MAAM;gBACV,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;gBACvB,MAAM;YACP,KAAK,MAAM;gBACV,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;gBACxB,MAAM;YACP,KAAK,SAAS;gBACb,MAAM,CAAC,OAAO,EAAE,CAAC;gBACjB,MAAM;QACR,CAAC;IACF,CAAC;CACD","sourcesContent":["import type { Component, OverlayHandle, OverlayOptions, TUI } from \"@earendil-works/pi-tui\";\nimport type { ExtensionUIContext } from \"../../core/extensions/index.ts\";\nimport type { IsolatedInteractiveRuntime } from \"./isolated-runtime.ts\";\nimport type { InteractiveEngineMessage, JsonValue, SerializableOverlayOptions } from \"./protocol.ts\";\nimport { RemoteFrameWidthClamp } from \"./remote-frame-clamp.ts\";\nimport { TerminalModeController } from \"./terminal-mode-controller.ts\";\n\nexport type RemoteComponentRuntime = Pick<\n\tIsolatedInteractiveRuntime,\n\t\"onEngineMessage\" | \"onGenerationEnded\" | \"sendEngineCommand\"\n>;\n\nexport type RemoteComponentUI = Pick<ExtensionUIContext, \"custom\" | \"requestRender\" | \"setWidget\">;\n\ninterface MountedRemoteComponent {\n\tcomponent: RemoteComponent;\n\tdone: (result: JsonValue | undefined) => void;\n\tengineDone: boolean;\n\t/** The extension declared that this component binds Ctrl+C itself. */\n\thandlesCtrlC: boolean;\n\t/** The extension declared that this component claims internal UI actions. */\n\thandlesInternalUiAction: boolean;\n\thandle?: OverlayHandle;\n\twidgetKey?: string;\n}\n\n/**\n * A stalled engine must not make fullscreen input wait forever. A timed-out\n * reply is treated as unhandled and lets the viewport process the key.\n */\nexport const REMOTE_INPUT_REPLY_TIMEOUT_MS = 250;\n\ninterface PendingInput {\n\tresolve: (handled: boolean | undefined) => void;\n\ttimer: ReturnType<typeof setTimeout>;\n}\n\nclass RemoteComponent implements Component {\n\twantsKeyRelease = true;\n\treadonly handlesInternalUiAction: boolean;\n\tprivate lines = [\"Loading remote component…\"];\n\tprivate width = 0;\n\tprivate rows = 0;\n\tprivate requestId = 0;\n\tprivate inputRequestId = 0;\n\tprivate appliedRequestId = 0;\n\tprivate dirty = true;\n\tprivate disposed = false;\n\tprivate readonly pendingInputs = new Map<number, PendingInput>();\n\tprivate readonly frameClamp = new RemoteFrameWidthClamp();\n\n\tprivate readonly componentId: string;\n\tprivate readonly runtime: RemoteComponentRuntime;\n\tprivate readonly requestRender: () => void;\n\tprivate readonly getRows: () => number;\n\n\tconstructor(\n\t\tcomponentId: string,\n\t\truntime: RemoteComponentRuntime,\n\t\trequestRender: () => void,\n\t\tgetRows: () => number,\n\t\thandlesInternalUiAction = false,\n\t) {\n\t\tthis.componentId = componentId;\n\t\tthis.runtime = runtime;\n\t\tthis.requestRender = requestRender;\n\t\tthis.getRows = getRows;\n\t\tthis.handlesInternalUiAction = handlesInternalUiAction;\n\t}\n\n\trender(width: number): string[] {\n\t\tconst rows = this.getRows();\n\t\tif (!this.disposed && (this.dirty || width !== this.width || rows !== this.rows)) {\n\t\t\tthis.width = width;\n\t\t\tthis.rows = rows;\n\t\t\tthis.dirty = false;\n\t\t\tthis.runtime.sendEngineCommand({\n\t\t\t\ttype: \"engine_custom_render\",\n\t\t\t\tcomponentId: this.componentId,\n\t\t\t\trequestId: ++this.requestId,\n\t\t\t\twidth,\n\t\t\t\trows,\n\t\t\t});\n\t\t}\n\t\t// The engine child re-renders asynchronously; until the fresh frame\n\t\t// arrives, the previous frame may be wrapped for an older terminal\n\t\t// width. Clamp so a resize never replays overflowing lines (pi-tui\n\t\t// crashes on any rendered line wider than the terminal).\n\t\treturn this.frameClamp.clamp(this.lines, width);\n\t}\n\n\thandleInput(data: string): Promise<boolean | undefined> {\n\t\tif (this.disposed) return Promise.resolve(undefined);\n\t\tconst requestId = ++this.inputRequestId;\n\t\tconst result = new Promise<boolean | undefined>((resolve) => {\n\t\t\tconst timer = setTimeout(() => this.resolveInput(requestId, false), REMOTE_INPUT_REPLY_TIMEOUT_MS);\n\t\t\ttimer.unref?.();\n\t\t\tthis.pendingInputs.set(requestId, { resolve, timer });\n\t\t});\n\t\ttry {\n\t\t\tthis.runtime.sendEngineCommand({\n\t\t\t\ttype: \"engine_custom_input\",\n\t\t\t\tcomponentId: this.componentId,\n\t\t\t\trequestId,\n\t\t\t\tdata,\n\t\t\t});\n\t\t} catch {\n\t\t\tthis.resolveInput(requestId, false);\n\t\t}\n\t\t// Engine commands are delivered in order, so a frame requested now is\n\t\t// rendered by the child only AFTER it has applied this input. Pipelining\n\t\t// the request keeps keypress latency at a single round trip and repaints\n\t\t// components that never self-invalidate, instead of waiting for a\n\t\t// child-side invalidate (or an unrelated refresh) to trigger a frame.\n\t\tthis.dirty = true;\n\t\tthis.requestRender();\n\t\treturn result;\n\t}\n\n\tresolveInput(requestId: number, handled: boolean | undefined): void {\n\t\tconst pending = this.pendingInputs.get(requestId);\n\t\tif (!pending) return;\n\t\tthis.pendingInputs.delete(requestId);\n\t\tclearTimeout(pending.timer);\n\t\tpending.resolve(handled);\n\t}\n\n\tinvalidate(): void {\n\t\tthis.dirty = true;\n\t}\n\n\tapplyFrame(requestId: number, lines: string[]): void {\n\t\tif (this.disposed || requestId < this.appliedRequestId) return;\n\t\tthis.appliedRequestId = requestId;\n\t\tthis.lines = lines;\n\t\tthis.requestRender();\n\t}\n\n\trequestRemoteRender(): void {\n\t\tif (this.disposed) return;\n\t\tthis.dirty = true;\n\t\tthis.requestRender();\n\t}\n\n\t/**\n\t * Tear the proxy down. `notifyEngine` must be false once the writer no longer\n\t * points at the generation that owns this component: component IDs restart at\n\t * `remote_component_1` for every child, so a late dispose would address an\n\t * unrelated component in the replacement engine.\n\t */\n\tdispose(notifyEngine = true): void {\n\t\tif (this.disposed) return;\n\t\tthis.disposed = true;\n\t\tfor (const requestId of [...this.pendingInputs.keys()]) this.resolveInput(requestId, undefined);\n\t\tif (notifyEngine)\n\t\t\tthis.runtime.sendEngineCommand({ type: \"engine_custom_dispose\", componentId: this.componentId });\n\t}\n}\n\nfunction overlayOptions(options: SerializableOverlayOptions | undefined): OverlayOptions | undefined {\n\treturn options as OverlayOptions | undefined;\n}\n\n/**\n * Resolve the real host terminal from the pi-tui TUI handed to the overlay\n * factory. Optional: some hosts / test seams do not surface `tui.terminal`, in\n * which case terminal-mode controls harmlessly no-op.\n */\nfunction hostTerminal(tui: TUI): { write(data: string): void } {\n\tconst terminal = (tui as { terminal?: { write?(data: string): void } }).terminal;\n\treturn typeof terminal?.write === \"function\" ? (terminal as { write(data: string): void }) : { write: () => {} };\n}\n\nexport interface TuiRendererLifecycle {\n\tisFullscreen(): boolean;\n\tonRendererReplaced(listener: () => void): () => void;\n}\n\nexport class RemoteComponentController {\n\tprivate readonly mounted = new Map<string, MountedRemoteComponent>();\n\tprivate readonly unsubscribe: () => void;\n\tprivate readonly unsubscribeGenerationEnded: () => void;\n\tprivate readonly terminalModes: TerminalModeController;\n\tprivate readonly unsubscribeTuiRendererReplaced: () => void;\n\n\tprivate readonly runtime: RemoteComponentRuntime;\n\tprivate readonly ui: RemoteComponentUI;\n\n\tconstructor(runtime: RemoteComponentRuntime, ui: RemoteComponentUI, tuiRendererLifecycle: TuiRendererLifecycle) {\n\t\tthis.runtime = runtime;\n\t\tthis.ui = ui;\n\t\tthis.terminalModes = new TerminalModeController(() => tuiRendererLifecycle.isFullscreen());\n\t\tthis.unsubscribeTuiRendererReplaced = tuiRendererLifecycle.onRendererReplaced(() =>\n\t\t\tthis.terminalModes.rebindTui(),\n\t\t);\n\t\tthis.unsubscribe = runtime.onEngineMessage((message) => this.handleMessage(message));\n\t\t// Teardown is driven by engine death rather than the NEXT generation's\n\t\t// `engine_ready`, so a crash with no restart, or a hung/failed restart,\n\t\t// still releases the host editor, focus, and inline-custom-UI depth.\n\t\tthis.unsubscribeGenerationEnded = runtime.onGenerationEnded(() => this.disposeAll(\"generation-lost\"));\n\t}\n\n\tdispose(): void {\n\t\tthis.unsubscribeTuiRendererReplaced();\n\t\tthis.unsubscribe();\n\t\tthis.unsubscribeGenerationEnded();\n\t\tthis.disposeAll(\"host-shutdown\");\n\t}\n\n\t/** The remote overlay proxy that currently holds focus (see remote-input-ownership.ts). */\n\tfocusedRemoteOverlay(): unknown {\n\t\tfor (const record of this.mounted.values()) {\n\t\t\tif (record.handle?.isFocused() === true) return record.component;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/** `component` itself when it is one of this generation's live non-widget proxies. */\n\tremoteProxyOwner(component: unknown): unknown {\n\t\tif (!(component instanceof RemoteComponent)) return undefined;\n\t\tfor (const record of this.mounted.values()) {\n\t\t\tif (record.component === component) return record.widgetKey === undefined ? component : undefined;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/** True when the extension that mounted `component` declared it binds Ctrl+C. */\n\tremoteProxyHandlesCtrlC(component: unknown): boolean {\n\t\tfor (const record of this.mounted.values()) {\n\t\t\tif (record.component === component) return record.handlesCtrlC;\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Close exactly one live proxy through the ordinary host close path.\n\t *\n\t * The host escape from a component that traps Ctrl+C, and deliberately not\n\t * `disposeAll()`: that is generation-death teardown, which would also close\n\t * unrelated nested components and suppress the child notification. Here the\n\t * record stays registered while `done` runs, so `showExtensionCustom()`\n\t * hides this overlay (or remounts the editor) and its finalizer disposes the\n\t * proxy normally — which tells the healthy child to resolve its own\n\t * `ui.custom()` promise with `undefined`, exactly like a user cancel.\n\t */\n\tdismissRemoteProxy(component: unknown): boolean {\n\t\tfor (const record of this.mounted.values()) {\n\t\t\tif (record.component !== component || record.widgetKey !== undefined) continue;\n\t\t\trecord.done(undefined);\n\t\t\tthis.ui.requestRender();\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Close every mounted component.\n\t *\n\t * `\"generation-lost\"` closes through the real host close path: it hides the\n\t * overlay or remounts the editor into `editorContainer`, restores the saved\n\t * draft and focus, releases `blockingInlineCustomUiDepth`, and resolves the\n\t * extension's `ui.custom()` promise. Records are removed BEFORE each `done`\n\t * runs so the settlement path cannot re-enter the controller, and proxy\n\t * disposal is local-only because the writer already points at a replacement\n\t * child whose component IDs restart at `remote_component_1`.\n\t *\n\t * Order is newest-first, matching the TUI's overlay stack. Closing oldest\n\t * first would let an overlay mounted above an inline proxy restore focus to\n\t * that inline proxy after it had already been disposed.\n\t *\n\t * `\"host-shutdown\"` notifies the still-live engine child instead and leaves\n\t * host mounts alone: the TUI is already stopping and must not repaint.\n\t */\n\tprivate disposeAll(reason: \"generation-lost\" | \"host-shutdown\"): void {\n\t\tconst records = [...this.mounted.entries()].reverse();\n\t\tthis.mounted.clear();\n\t\tfor (const [componentId, record] of records) {\n\t\t\tthis.terminalModes.onUnmount(componentId);\n\t\t\trecord.component.dispose(reason === \"host-shutdown\" && !record.engineDone);\n\t\t\tif (record.widgetKey) this.ui.setWidget(record.widgetKey, undefined);\n\t\t\telse if (reason === \"generation-lost\") record.done(undefined);\n\t\t}\n\t\tthis.terminalModes.resetAll();\n\t\tif (reason === \"generation-lost\" && records.length > 0) this.ui.requestRender();\n\t}\n\n\tprivate handleMessage(message: InteractiveEngineMessage): void {\n\t\tswitch (message.type) {\n\t\t\tcase \"engine_ready\":\n\t\t\t\t// Idempotent fallback for a generation replacement whose death event\n\t\t\t\t// was already handled: stale records must be gone before the new child\n\t\t\t\t// can reuse `remote_component_1`, and any terminal modes the dead\n\t\t\t\t// generation left on are reset here too.\n\t\t\t\tthis.disposeAll(\"generation-lost\");\n\t\t\t\tbreak;\n\t\t\tcase \"engine_custom_open\":\n\t\t\t\tthis.open(\n\t\t\t\t\tmessage.componentId,\n\t\t\t\t\tmessage.overlay,\n\t\t\t\t\tmessage.deferInlineCustomUiFocus,\n\t\t\t\t\tmessage.overlayOptions,\n\t\t\t\t\tmessage.widgetKey,\n\t\t\t\t\tmessage.widgetPlacement,\n\t\t\t\t\tmessage.handlesCtrlC === true,\n\t\t\t\t\tmessage.handlesInternalUiAction === true,\n\t\t\t\t\tmessage.reserveTranscriptRows === true,\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\tcase \"engine_custom_close\":\n\t\t\t\tthis.close(message.componentId);\n\t\t\t\tbreak;\n\t\t\tcase \"engine_custom_frame\":\n\t\t\t\tthis.mounted.get(message.componentId)?.component.applyFrame(message.requestId, message.lines);\n\t\t\t\tbreak;\n\t\t\tcase \"engine_custom_input_result\":\n\t\t\t\tthis.mounted.get(message.componentId)?.component.resolveInput(message.requestId, message.handled);\n\t\t\t\tbreak;\n\t\t\tcase \"engine_custom_invalidate\":\n\t\t\t\tthis.mounted.get(message.componentId)?.component.requestRemoteRender();\n\t\t\t\tbreak;\n\t\t\tcase \"engine_custom_terminal\":\n\t\t\t\tthis.terminalModes.applyControl(message.componentId, message.control);\n\t\t\t\tbreak;\n\t\t\tcase \"engine_custom_done\": {\n\t\t\t\tconst record = this.mounted.get(message.componentId);\n\t\t\t\tif (record) {\n\t\t\t\t\trecord.engineDone = true;\n\t\t\t\t\trecord.done(message.result);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"engine_custom_control\":\n\t\t\t\tthis.control(message.componentId, message.action);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tprivate open(\n\t\tcomponentId: string,\n\t\toverlay: boolean,\n\t\tdeferInlineCustomUiFocus: boolean | undefined,\n\t\toptions: SerializableOverlayOptions | undefined,\n\t\twidgetKey?: string,\n\t\twidgetPlacement?: \"aboveEditor\" | \"belowEditor\",\n\t\thandlesCtrlC = false,\n\t\thandlesInternalUiAction = false,\n\t\treserveTranscriptRows = false,\n\t): void {\n\t\tif (this.mounted.has(componentId)) return;\n\t\tif (widgetKey) {\n\t\t\tlet rows = 24;\n\t\t\tconst component = new RemoteComponent(\n\t\t\t\tcomponentId,\n\t\t\t\tthis.runtime,\n\t\t\t\t() => this.ui.requestRender(),\n\t\t\t\t() => rows,\n\t\t\t\thandlesInternalUiAction,\n\t\t\t);\n\t\t\tthis.mounted.set(componentId, {\n\t\t\t\tcomponent,\n\t\t\t\tdone: () => {},\n\t\t\t\tengineDone: false,\n\t\t\t\thandlesCtrlC,\n\t\t\t\thandlesInternalUiAction,\n\t\t\t\twidgetKey,\n\t\t\t});\n\t\t\tthis.ui.setWidget(\n\t\t\t\twidgetKey,\n\t\t\t\t(tui) => {\n\t\t\t\t\trows = tui.terminal.rows;\n\t\t\t\t\treturn component;\n\t\t\t\t},\n\t\t\t\t{ placement: widgetPlacement },\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tlet mounted: MountedRemoteComponent | undefined;\n\t\tvoid this.ui\n\t\t\t.custom<JsonValue | undefined>(\n\t\t\t\t(tui, _theme, _keybindings, done) => {\n\t\t\t\t\tconst component = new RemoteComponent(\n\t\t\t\t\t\tcomponentId,\n\t\t\t\t\t\tthis.runtime,\n\t\t\t\t\t\t() => this.ui.requestRender(),\n\t\t\t\t\t\t() => tui.terminal.rows,\n\t\t\t\t\t\thandlesInternalUiAction,\n\t\t\t\t\t);\n\t\t\t\t\tmounted = { component, done, engineDone: false, handlesCtrlC, handlesInternalUiAction };\n\t\t\t\t\tthis.mounted.set(componentId, mounted);\n\t\t\t\t\t// Bind this component to the real host terminal so a buffered\n\t\t\t\t\t// autowrap control emitted before the mount frame applies to the host TTY.\n\t\t\t\t\tthis.terminalModes.onMount(componentId, hostTerminal(tui));\n\t\t\t\t\treturn component;\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\toverlay,\n\t\t\t\t\tdeferInlineCustomUiFocus,\n\t\t\t\t\thandlesInternalUiAction,\n\t\t\t\t\treserveTranscriptRows,\n\t\t\t\t\toverlayOptions: overlayOptions(options),\n\t\t\t\t\tonHandle: (handle) => {\n\t\t\t\t\t\tif (mounted) mounted.handle = handle;\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t)\n\t\t\t.catch(() => undefined)\n\t\t\t.finally(() => {\n\t\t\t\tthis.terminalModes.onUnmount(componentId);\n\t\t\t\tconst record = this.mounted.get(componentId);\n\t\t\t\tif (!record) return;\n\t\t\t\tthis.mounted.delete(componentId);\n\t\t\t\tif (record.engineDone) record.component.dispose(false);\n\t\t\t\telse record.component.dispose();\n\t\t\t});\n\t}\n\n\tprivate close(componentId: string): void {\n\t\tconst record = this.mounted.get(componentId);\n\t\tif (!record) return;\n\t\tthis.terminalModes.onUnmount(componentId);\n\t\tthis.mounted.delete(componentId);\n\t\tif (record.widgetKey) this.ui.setWidget(record.widgetKey, undefined);\n\t\trecord.component.dispose();\n\t}\n\n\tprivate control(componentId: string, action: \"focus\" | \"hide\" | \"show\" | \"unfocus\"): void {\n\t\tconst handle = this.mounted.get(componentId)?.handle;\n\t\tif (!handle) return;\n\t\tswitch (action) {\n\t\t\tcase \"focus\":\n\t\t\t\thandle.focus();\n\t\t\t\tbreak;\n\t\t\tcase \"hide\":\n\t\t\t\thandle.setHidden(true);\n\t\t\t\tbreak;\n\t\t\tcase \"show\":\n\t\t\t\thandle.setHidden(false);\n\t\t\t\tbreak;\n\t\t\tcase \"unfocus\":\n\t\t\t\thandle.unfocus();\n\t\t\t\tbreak;\n\t\t}\n\t}\n}\n"]}
@@ -2743,6 +2743,33 @@ const result = await ctx.ui.custom<string | null>(
2743
2743
 
2744
2744
  See [TUI components](/tui) for the full `OverlayOptions` API and [overlay-qa-tests.ts](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/examples/extensions/overlay-qa-tests.ts) for examples.
2745
2745
 
2746
+ Pass `{ reserveTranscriptRows: true }` for a blocking bottom-anchored dialog. A reserving overlay must set `overlayOptions.anchor` to `bottom-left`, `bottom-center`, or `bottom-right`; `row` and a nonzero `offsetY` are rejected because they invalidate the transcript-intersection model. Horizontal placement options remain supported. An overlay is composited over the transcript rather than measured into the layout, so without this option a tall dialog can cover the whole screen and the transcript rows it covers can never be scrolled above it. With it, the host bounds the overlay so at least six transcript rows stay visible. Top and bottom margins limit the wrapper before pi-tui composition, preventing a second fixed-head crop. Numeric and percentage `maxHeight` values are also resolved before active-row windowing and removed from the options passed to pi-tui. The host computes each visible bottom overlay's real intersection with the transcript and reserves the connected covered suffix once, so scrolling to the end keeps the newest output readable. A measured height change on mount or resize requests one automatic settling repaint. Margins, overlapping overlays, resize, and temporary visibility changes are reflected each frame. A temporarily hidden overlay — through `OverlayHandle.setHidden(true)` or a false `OverlayOptions.visible` result — contributes no intersection until it becomes visible again. Permanent handle removal, closure, and raw host removal release that exact overlay's registration; the shared reserve remains until its final overlay leaves. Leave the option unset for an overlay that is meant to take the screen, such as a full-screen graph. The built-in `ask_user_question` dialog sets it.
2747
+
2748
+ ```typescript
2749
+ const result = await ctx.ui.custom<string | null>(
2750
+ (tui, theme, keybindings, done) => new MyDialog({ onClose: done }),
2751
+ {
2752
+ overlay: true,
2753
+ reserveTranscriptRows: true,
2754
+ overlayOptions: { anchor: "bottom-center", width: "100%" },
2755
+ }
2756
+ );
2757
+ ```
2758
+
2759
+ A component mounted with `reserveTranscriptRows` always releases configured fullscreen transcript actions and vertical wheel input to the host viewport, including while a nested input has focus. The component keeps all other keyboard and mouse input, including text editing, arrows, confirmation, cancellation, and clicks. This rule applies only to reserving overlays; other focused overlays still receive page and wheel input first and can keep it by returning `true`.
2760
+
2761
+ Bounding a tall dialog means dropping rows, and the host would otherwise have to guess which. Embed `OVERLAY_ACTIVE_ROW_MARKER` in the line your component most needs kept — the selected row of a list — and the host places what it keeps around that row instead of taking a fixed head, even when the effective `maxHeight` is only one row. The mark is a zero-width APC sequence that `visibleWidth` measures as zero, and the host strips it before the line is painted, so it never reaches the terminal. Embed it once per frame; the host uses the first line that carries it. The `ask_user_question` dialog marks every active selectable row, including single- and multi-select options, Next, Submit, Cancel, and inline sentinel rows. Focused pi-tui inputs also anchor the bound through their cursor marker, so arrow keys and text input stay visible on a 16-row terminal.
2762
+
2763
+ ```typescript
2764
+ import { OVERLAY_ACTIVE_ROW_MARKER } from "@bastani/atomic";
2765
+
2766
+ render(width: number): string[] {
2767
+ return this.items.map((item, index) =>
2768
+ index === this.selected ? `${this.row(item, width)}${OVERLAY_ACTIVE_ROW_MARKER}` : this.row(item, width),
2769
+ );
2770
+ }
2771
+ ```
2772
+
2746
2773
  ### Custom Editor
2747
2774
 
2748
2775
  Replace the main input editor with a custom implementation (vim mode, emacs mode, etc.):
@@ -99,6 +99,7 @@ Fullscreen transcript bindings take precedence over editor bindings while the ma
99
99
 
100
100
  This routing remains configurable through the ordinary action bindings. For example, `"tui.altScreen.pageUp": "ctrl+pageUp"` makes `pageUp` control the editor and `ctrl+pageUp` control the transcript in fullscreen mode. Bind `tui.altScreen.halfPageUp` and `tui.altScreen.halfPageDown` for smaller transcript steps while keeping the full-page bindings. Setting `"tui.altScreen.pageUp": []` disables that transcript shortcut entirely. User bindings replace the defaults for that action.
101
101
  When a fullscreen overlay or inline custom component owns focus, it receives matching `pageUp`, `pageDown`, `home`, `end`, and custom `tui.altScreen.*` bindings before transcript scrolling. Its handler returns `true` when it consumes the key; an unhandled result lets transcript scrolling proceed. Remote components receive a correlated reply and have a bounded fallback if the engine stalls. Mouse-wheel and click sequences follow the same focused-component route, so workflow graphs and stage chats can consume them before unhandled events fall through to the fullscreen viewport.
102
+ The blocking `ask_user_question` dialog is pinned to the bottom of the screen as an overlay rather than measured into the layout, so opening it does not shrink the transcript viewport or the page step: `pageUp`, `pageDown`, `home`, `end`, and the wheel move by the same amount and reach every line of the scrollback, including the newest ones, in the strip that stays visible above the dialog. Those transcript actions still work while the Notes editor is open. Notes keeps ordinary text and edit actions, including the default `ctrl+home` and `ctrl+end`; a key moves the transcript instead only when configured for a `tui.altScreen.*` action. The dialog is bounded so the visible strip survives on a short terminal, and the active questionnaire row stays visible inside the bound as you move through single-select choices, multi-select choices, Next, Submit, Cancel, and inline inputs. It keeps its own arrow, `enter`, `tab`, `space`, `esc`, click, and selection input.
102
103
 
103
104
  | Keybinding id | Default | Description |
104
105
  |--------|---------|-------------|
package/docs/workflows.md CHANGED
@@ -934,6 +934,7 @@ Authoring basics:
934
934
  - Workflow names normalize for lookup: trim, lowercase, convert whitespace/underscore to hyphen, remove other punctuation, and collapse hyphens.
935
935
  - `description` sets the listing text.
936
936
  - `autoAttach: true` opens the graph overlay when an interactive top-level named launch through `/workflow <name>` or the registered `workflow` tool is accepted. Only exact `true` is retained on the compiled definition; omission and `false` do not opt a definition into auto-attachment. Existing input-form launch behavior is unchanged.
937
+ - `heartbeatIntervalMinutes` declares the workflow's heartbeat cadence in minutes. Omission uses the `15`-minute default; `0` disables heartbeats for the workflow. Negative and non-finite values are rejected when the definition is authored. While a run is active, each boundary at `startedAt + n × interval` delivers a heartbeat card to the main chat as a queued steer that never interrupts an in-flight response. See [`heartbeatIntervalMinutes`](#heartbeatintervalminutes).
937
938
  - `inputs` declares typed user inputs.
938
939
  - `worktreeFromInputs` optionally maps input names to workflow-wide reusable Git worktree defaults.
939
940
  - `outputs` declares typed outputs that parent workflows receive from `ctx.workflow(childWorkflow, ...)`.
@@ -1900,6 +1901,36 @@ readonly autoAttach?: boolean;
1900
1901
 
1901
1902
  Exact `true` opts interactive top-level named launches through `/workflow <name>` and the registered `workflow` tool into opening the graph overlay immediately. Omission and `false` do not opt in. This option does not affect headless launches, nested `ctx.workflow(...)` calls, or the existing input-form launch path. Compiled definitions retain this field only as literal `true`.
1902
1903
 
1904
+ ### `heartbeatIntervalMinutes`
1905
+
1906
+ ```typescript
1907
+ readonly heartbeatIntervalMinutes?: number;
1908
+ ```
1909
+
1910
+ The heartbeat cadence for the workflow, in minutes, measured from the run's persisted start time. Omission resolves to the `15`-minute default and `0` explicitly disables heartbeats; negative and non-finite values are rejected with a `TypeError` when the definition is authored. Every compiled definition carries the resolved value, so consumers read a number rather than re-deriving the default.
1911
+
1912
+ ```ts
1913
+ export default workflow({
1914
+ name: "audit-auth",
1915
+ description: "Audit the authentication module.",
1916
+ heartbeatIntervalMinutes: 30,
1917
+ outputs: {},
1918
+ run: async (ctx) => ({}),
1919
+ });
1920
+ ```
1921
+
1922
+ That example heartbeats every 30 minutes: a run started at 09:00 raises boundaries at 09:30, 10:00, 10:30, and so on, until it reaches a terminal state. Boundaries are `startedAt + n × interval` computed from the run's persisted start time, never from the previous delivery, so a slow delivery, a retry, or a restart cannot drift the cadence.
1923
+
1924
+ Each heartbeat arrives in the main chat as a `workflows:workflow-heartbeat` card naming the workflow, the run id, the cadence, and elapsed run time, with `/workflow status <runId>` as the inspection hint. It is delivered as a queued steer that waits for the parent's next protocol-safe boundary, so it never interrupts a response that is already streaming. Only one heartbeat per run is outstanding at a time: an outstanding heartbeat holds its slot until its card is actually consumed into the conversation — not merely until the parent's turn ends, which can happen while the card is still queued or its queue is paused — so a boundary that falls before that is skipped rather than stacked behind it, and the cadence then resumes at the first future boundary. Pickup resolves the typed `workflows:workflow-heartbeat` entry and releases only the exact `runId + scheduledAt` identity, never a rendered-text match, so another custom message cannot free the slot by copying the card text. However long the parent stays busy, and however often its queue is paused, at most one unread heartbeat per run is ever waiting on a host that reports message consumption, which Atomic's chat host does.
1925
+
1926
+ Paused runs emit nothing and are never backfilled. A resumed or restarted run picks up at the first future boundary on the original cadence rather than bursting the boundaries it missed. Holding to the *original* cadence across a durable resume takes one stored value: a resume re-dispatches under the original run id but records a fresh start time, so each run writes a single reserved durable anchor record as soon as it has durable progress of its own, before its first boundary comes due. The anchor is only ever read as the earlier of itself and the run's current start time, so it can restore the original cadence but can never move a boundary or raise one that was missed. A run that reaches a terminal state is re-checked immediately before a heartbeat is queued, again immediately before it is processed, and again before every delivery attempt including retries, so a run that finishes mid-flight stays silent. A card the host has already accepted into the parent's queue is past all three of those checks, so it is checked once more when the parent reads it — see the terminal-cleanup paragraphs below. When several runs are due at once, they reach the parent in `scheduledAt` order with the run id as the stable tie-break, and a heartbeat that has to be retried holds its place rather than letting a later one overtake it. Nested workflow runs never heartbeat the parent chat; only top-level runs do. A run keeps the cadence its own definition was authored with: editing, renaming, deleting, or reloading a workflow changes what the next launch uses, and leaves runs already in flight on their launch cadence — including across a durable resume, because the anchor record carries that cadence alongside the start time. A run that launched with heartbeats disabled and is later resumed in a new process is the one exception: a disabled run writes no durable record at all, so nothing preserves that it launched disabled and it adopts whatever the workflow then declares. Cadences below a millisecond are accepted; each raises its next boundary at the finest instant the clock can represent, and the one-outstanding-heartbeat rule still bounds delivery to one card per parent turn. Heartbeat cadences carry a documented representable upper limit. Above roughly 3 × 10^303 minutes, `startedAt + interval` exceeds the largest finite timestamp a double can hold, so the series has no first boundary: nothing is scheduled, no durable record is written, and `ATOMIC_WORKFLOW_DEBUG=1` says so. Such a cadence is still a valid positive interval and is still reported as authored, but it delivers no heartbeat. `0` remains the only value that declares heartbeats off.
1927
+
1928
+ When a run reaches a terminal state — completed, failed, blocked, skipped, cancelled, or killed — one cleanup pass drops everything the cadence held for it: its armed wake-up, its next scheduled boundary, its outstanding slot, any heartbeat of its own still waiting in the delivery queue along with the retry timer that belonged to it, and its cadence and durable-anchor memos. Cleanup is idempotent: running it again on the same run creates no state, resurrects no schedule, and reports that there was nothing left to clear. It reacts to the run's observed state rather than to a transition event, which is what also makes it the recovery pass. At startup, and on every subsequent store change, a run that is already terminal has its stale durable anchor and any leftover queued record discarded rather than replayed, and its anchor is neither read nor rewritten; a run the store no longer holds at all is dropped the same way. Active runs are untouched by another run's cleanup, and recovery still selects the first future boundary rather than replaying a missed one ([#1975](https://github.com/bastani-inc/atomic/issues/1975)).
1929
+
1930
+ A recoverable provider or rate-limit block is not the terminal `blocked` status: the run remains stored as `running` and resumable. It raises no new heartbeat while blocked, but keeps its cadence state and any card already waiting with the parent; cleanup runs only once the run's own status becomes terminal.
1931
+
1932
+ A heartbeat the host has already accepted into the parent's queue is beyond that pass, because nothing withdraws a queued message. It is invalidated instead at the moment the parent reads it: the typed card's exact `runId + scheduledAt` identity must still be pending for a current nonterminal run. If the run has since reached a terminal state, this process no longer knows that run, or a durable resume has reused the run id with a later pending boundary, the old heartbeat is excluded from the model's context and cannot steer the parent. That covers all ways a stale card survives — one parked through a long turn while its run finished, one recovered from a previous process at startup, and one admitted before a same-ID durable resume. The card already rendered in your transcript is deliberately left alone: it is a true record that the heartbeat was raised, and rewriting scrollback after the fact would be worse than leaving it. Only the model-facing steer is invalidated.
1933
+
1903
1934
  ### `inputs`
1904
1935
 
1905
1936
  ```typescript
@@ -1976,6 +2007,7 @@ interface WorkflowDefinition<
1976
2007
  readonly normalizedName: string;
1977
2008
  readonly description: string;
1978
2009
  readonly autoAttach?: true;
2010
+ readonly heartbeatIntervalMinutes: number;
1979
2011
  readonly inputs: WorkflowInputSchemaMap;
1980
2012
  readonly outputs?: WorkflowOutputSchemaMap;
1981
2013
  readonly inputBindings?: { readonly worktree?: WorkflowWorktreeInputBinding };
@@ -3169,6 +3201,8 @@ Deliberate control actions on a top-level run report themselves too. `/workflow
3169
3201
 
3170
3202
  Configure lifecycle behavior with `workflowNotifications.enabled` (default `true`) and `workflowNotifications.notifyOn` (default `["started", "completed", "failed", "blocked", "awaiting_input", "paused", "quit", "resumed"]`). A config that pins `notifyOn` explicitly keeps exactly the kinds it lists, so `notifyOn: ["failed"]` suppresses every control notice.
3171
3203
 
3204
+ **Heartbeats are separate from lifecycle notices.** A lifecycle notice reports a transition; a heartbeat reports that nothing has transitioned yet. While a top-level run is active, Atomic raises one `workflows:workflow-heartbeat` card per `startedAt + n × heartbeatIntervalMinutes` boundary, on the same queued-steer delivery (`triggerTurn`, `deliverAs: "steer"`, `persistWhenStreaming`) and the same notice-card renderer, under its own custom type. The cadence is per workflow definition — `15` minutes by default, `0` to disable — and is documented under [`heartbeatIntervalMinutes`](#heartbeatintervalminutes). `workflowNotifications.notifyOn` selects lifecycle kinds only; it does not list or filter heartbeats. Heartbeats stop when the run reaches a terminal state: one idempotent cleanup pass drops its timer, its schedule, and any heartbeat still queued inside the scheduler, a later process discards those records rather than replaying them, and a card the parent's queue had already accepted is excluded from the model's context when it is read ([#1975](https://github.com/bastani-inc/atomic/issues/1975)).
3205
+
3172
3206
  Human input is runtime-only: call `ctx.ui.input`, `ctx.ui.confirm`, `ctx.ui.select`, `ctx.ui.editor`, or `ctx.ui.custom<T>` when the workflow needs a decision. No builder-level declaration is required or supported.
3173
3207
 
3174
3208
  Human-in-the-loop prompts from `ctx.ui.input`, `ctx.ui.confirm`, `ctx.ui.select`, `ctx.ui.editor`, and `ctx.ui.custom<T>` appear as awaiting-input nodes in the workflow UI/graph viewer, not as ordinary chat modals. Workflow definitions do not declare HIL; runtime `ctx.ui.*` calls create prompt nodes. If the prompt lives inside an imported child workflow, it still appears in the same expanded parent graph so the user can focus and answer it without switching to a separate child status entry. When the attached stage has a pending prompt, its attribution banner is headed `AWAITING INPUT` and shows the full run id in a two-row identity block; the question and its options continue through the existing prompt UI below the banner.