@bastani/atomic 0.9.13-alpha.3 → 0.9.13

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 (99) hide show
  1. package/CHANGELOG.md +97 -0
  2. package/dist/builtin/i-have-adhd/CHANGELOG.md +13 -0
  3. package/dist/builtin/i-have-adhd/package.json +1 -1
  4. package/dist/builtin/intercom/CHANGELOG.md +26 -0
  5. package/dist/builtin/intercom/package.json +1 -1
  6. package/dist/builtin/mcp/CHANGELOG.md +15 -0
  7. package/dist/builtin/mcp/package.json +1 -1
  8. package/dist/builtin/subagents/CHANGELOG.md +41 -0
  9. package/dist/builtin/subagents/package.json +1 -1
  10. package/dist/builtin/web-access/CHANGELOG.md +14 -0
  11. package/dist/builtin/web-access/package.json +1 -1
  12. package/dist/builtin/workflows/CHANGELOG.md +57 -0
  13. package/dist/builtin/workflows/package.json +1 -1
  14. package/dist/builtin/workflows/src/extension/index.bundle.mjs +70 -16
  15. package/dist/builtin/workflows/src/extension/ui-surface.ts +2 -0
  16. package/dist/builtin/workflows/src/tui/keybindings-adapter.ts +1 -0
  17. package/dist/builtin/workflows/src/tui/overlay-adapter.ts +1 -0
  18. package/dist/builtin/workflows/src/tui/stage-chat-view-archive-history.ts +27 -8
  19. package/dist/builtin/workflows/src/tui/stage-chat-view-input.ts +17 -1
  20. package/dist/builtin/workflows/src/tui/stage-chat-view.ts +20 -3
  21. package/dist/builtin/workflows/src/tui/workflow-attach-pane.ts +10 -1
  22. package/dist/core/agent-session-events.d.ts.map +1 -1
  23. package/dist/core/agent-session-events.js +6 -0
  24. package/dist/core/agent-session-events.js.map +1 -1
  25. package/dist/core/agent-session-methods.d.ts +2 -0
  26. package/dist/core/agent-session-methods.d.ts.map +1 -1
  27. package/dist/core/agent-session-methods.js.map +1 -1
  28. package/dist/core/agent-session-prompt.d.ts.map +1 -1
  29. package/dist/core/agent-session-prompt.js +63 -0
  30. package/dist/core/agent-session-prompt.js.map +1 -1
  31. package/dist/core/agent-session-queue-pause.d.ts.map +1 -1
  32. package/dist/core/agent-session-queue-pause.js +6 -0
  33. package/dist/core/agent-session-queue-pause.js.map +1 -1
  34. package/dist/core/agent-session.d.ts +14 -0
  35. package/dist/core/agent-session.d.ts.map +1 -1
  36. package/dist/core/agent-session.js +14 -0
  37. package/dist/core/agent-session.js.map +1 -1
  38. package/dist/core/extensions/ui-types.d.ts +2 -0
  39. package/dist/core/extensions/ui-types.d.ts.map +1 -1
  40. package/dist/core/extensions/ui-types.js.map +1 -1
  41. package/dist/core/keybindings.d.ts +0 -5
  42. package/dist/core/keybindings.d.ts.map +1 -1
  43. package/dist/core/keybindings.js +0 -2
  44. package/dist/core/keybindings.js.map +1 -1
  45. package/dist/index.d.ts +1 -1
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +1 -1
  48. package/dist/index.js.map +1 -1
  49. package/dist/modes/interactive/components/index.d.ts +1 -0
  50. package/dist/modes/interactive/components/index.d.ts.map +1 -1
  51. package/dist/modes/interactive/components/index.js +1 -0
  52. package/dist/modes/interactive/components/index.js.map +1 -1
  53. package/dist/modes/interactive/components/transcript-follow-indicator.d.ts +14 -0
  54. package/dist/modes/interactive/components/transcript-follow-indicator.d.ts.map +1 -0
  55. package/dist/modes/interactive/components/transcript-follow-indicator.js +36 -0
  56. package/dist/modes/interactive/components/transcript-follow-indicator.js.map +1 -0
  57. package/dist/modes/interactive/interactive-extension-custom-ui.js +3 -0
  58. package/dist/modes/interactive/interactive-extension-custom-ui.js.map +1 -1
  59. package/dist/modes/interactive/interactive-input-handling.js +0 -3
  60. package/dist/modes/interactive/interactive-input-handling.js.map +1 -1
  61. package/dist/modes/interactive/interactive-mode-base.d.ts +1 -0
  62. package/dist/modes/interactive/interactive-mode-base.d.ts.map +1 -1
  63. package/dist/modes/interactive/interactive-mode-base.js +7 -1
  64. package/dist/modes/interactive/interactive-mode-base.js.map +1 -1
  65. package/dist/modes/interactive/interactive-mode-surface.d.ts +3 -3
  66. package/dist/modes/interactive/interactive-mode-surface.d.ts.map +1 -1
  67. package/dist/modes/interactive/interactive-mode-surface.js.map +1 -1
  68. package/dist/modes/interactive/interactive-mode.d.ts +1 -0
  69. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  70. package/dist/modes/interactive/interactive-mode.js +1 -0
  71. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  72. package/dist/modes/interactive/interactive-slash-commands.js +2 -5
  73. package/dist/modes/interactive/interactive-slash-commands.js.map +1 -1
  74. package/dist/modes/interactive/interactive-startup.d.ts.map +1 -1
  75. package/dist/modes/interactive/interactive-startup.js +6 -0
  76. package/dist/modes/interactive/interactive-startup.js.map +1 -1
  77. package/dist/modes/interactive/interactive-transcript-follow.d.ts +2 -0
  78. package/dist/modes/interactive/interactive-transcript-follow.d.ts.map +1 -0
  79. package/dist/modes/interactive/interactive-transcript-follow.js +6 -0
  80. package/dist/modes/interactive/interactive-transcript-follow.js.map +1 -0
  81. package/dist/modes/interactive/interactive-tui.d.ts +13 -1
  82. package/dist/modes/interactive/interactive-tui.d.ts.map +1 -1
  83. package/dist/modes/interactive/interactive-tui.js +59 -1
  84. package/dist/modes/interactive/interactive-tui.js.map +1 -1
  85. package/dist/modes/interactive-engine/engine-custom-ui.d.ts +2 -0
  86. package/dist/modes/interactive-engine/engine-custom-ui.d.ts.map +1 -1
  87. package/dist/modes/interactive-engine/engine-custom-ui.js +1 -0
  88. package/dist/modes/interactive-engine/engine-custom-ui.js.map +1 -1
  89. package/dist/modes/interactive-engine/protocol.d.ts +1 -0
  90. package/dist/modes/interactive-engine/protocol.d.ts.map +1 -1
  91. package/dist/modes/interactive-engine/protocol.js +1 -0
  92. package/dist/modes/interactive-engine/protocol.js.map +1 -1
  93. package/dist/modes/interactive-engine/remote-component.d.ts.map +1 -1
  94. package/dist/modes/interactive-engine/remote-component.js +21 -9
  95. package/dist/modes/interactive-engine/remote-component.js.map +1 -1
  96. package/docs/keybindings.md +2 -5
  97. package/docs/usage.md +2 -0
  98. package/npm-shrinkwrap.json +29 -29
  99. package/package.json +2 -2
@@ -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;AAexE;;;GAGG;AACH,eAAO,MAAM,6BAA6B,MAAM,CAAC;AAyIjD,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;IAiDrB,OAAO,CAAC,IAAI;IAkEZ,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;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"}
@@ -6,10 +6,11 @@ import { TerminalModeController } from "./terminal-mode-controller.js";
6
6
  */
7
7
  export const REMOTE_INPUT_REPLY_TIMEOUT_MS = 250;
8
8
  class RemoteComponent {
9
- constructor(componentId, runtime, requestRender, getRows) {
9
+ constructor(componentId, runtime, requestRender, getRows, handlesInternalUiAction = false) {
10
10
  this.wantsKeyRelease = true;
11
11
  this.lines = ["Loading remote component…"];
12
12
  this.width = 0;
13
+ this.rows = 0;
13
14
  this.requestId = 0;
14
15
  this.inputRequestId = 0;
15
16
  this.appliedRequestId = 0;
@@ -21,17 +22,20 @@ class RemoteComponent {
21
22
  this.runtime = runtime;
22
23
  this.requestRender = requestRender;
23
24
  this.getRows = getRows;
25
+ this.handlesInternalUiAction = handlesInternalUiAction;
24
26
  }
25
27
  render(width) {
26
- if (!this.disposed && (this.dirty || width !== this.width)) {
28
+ const rows = this.getRows();
29
+ if (!this.disposed && (this.dirty || width !== this.width || rows !== this.rows)) {
27
30
  this.width = width;
31
+ this.rows = rows;
28
32
  this.dirty = false;
29
33
  this.runtime.sendEngineCommand({
30
34
  type: "engine_custom_render",
31
35
  componentId: this.componentId,
32
36
  requestId: ++this.requestId,
33
37
  width,
34
- rows: this.getRows(),
38
+ rows,
35
39
  });
36
40
  }
37
41
  // The engine child re-renders asynchronously; until the fresh frame
@@ -230,7 +234,7 @@ export class RemoteComponentController {
230
234
  this.disposeAll("generation-lost");
231
235
  break;
232
236
  case "engine_custom_open":
233
- this.open(message.componentId, message.overlay, message.deferInlineCustomUiFocus, message.overlayOptions, message.widgetKey, message.widgetPlacement, message.handlesCtrlC === true);
237
+ this.open(message.componentId, message.overlay, message.deferInlineCustomUiFocus, message.overlayOptions, message.widgetKey, message.widgetPlacement, message.handlesCtrlC === true, message.handlesInternalUiAction === true);
234
238
  break;
235
239
  case "engine_custom_close":
236
240
  this.close(message.componentId);
@@ -260,13 +264,20 @@ export class RemoteComponentController {
260
264
  break;
261
265
  }
262
266
  }
263
- open(componentId, overlay, deferInlineCustomUiFocus, options, widgetKey, widgetPlacement, handlesCtrlC = false) {
267
+ open(componentId, overlay, deferInlineCustomUiFocus, options, widgetKey, widgetPlacement, handlesCtrlC = false, handlesInternalUiAction = false) {
264
268
  if (this.mounted.has(componentId))
265
269
  return;
266
270
  if (widgetKey) {
267
271
  let rows = 24;
268
- const component = new RemoteComponent(componentId, this.runtime, () => this.ui.requestRender(), () => rows);
269
- this.mounted.set(componentId, { component, done: () => { }, engineDone: false, handlesCtrlC, widgetKey });
272
+ const component = new RemoteComponent(componentId, this.runtime, () => this.ui.requestRender(), () => rows, handlesInternalUiAction);
273
+ this.mounted.set(componentId, {
274
+ component,
275
+ done: () => { },
276
+ engineDone: false,
277
+ handlesCtrlC,
278
+ handlesInternalUiAction,
279
+ widgetKey,
280
+ });
270
281
  this.ui.setWidget(widgetKey, (tui) => {
271
282
  rows = tui.terminal.rows;
272
283
  return component;
@@ -276,8 +287,8 @@ export class RemoteComponentController {
276
287
  let mounted;
277
288
  void this.ui
278
289
  .custom((tui, _theme, _keybindings, done) => {
279
- const component = new RemoteComponent(componentId, this.runtime, () => this.ui.requestRender(), () => tui.terminal.rows);
280
- mounted = { component, done, engineDone: false, handlesCtrlC };
290
+ const component = new RemoteComponent(componentId, this.runtime, () => this.ui.requestRender(), () => tui.terminal.rows, handlesInternalUiAction);
291
+ mounted = { component, done, engineDone: false, handlesCtrlC, handlesInternalUiAction };
281
292
  this.mounted.set(componentId, mounted);
282
293
  // Bind this component to the real host terminal so a buffered
283
294
  // autowrap control emitted before the mount frame applies to the host TTY.
@@ -286,6 +297,7 @@ export class RemoteComponentController {
286
297
  }, {
287
298
  overlay,
288
299
  deferInlineCustomUiFocus,
300
+ handlesInternalUiAction,
289
301
  overlayOptions: overlayOptions(options),
290
302
  onHandle: (handle) => {
291
303
  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;AAYvE;;;GAGG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,GAAG,CAAC;AAOjD,MAAM,eAAe;IAiBpB,YACC,WAAmB,EACnB,OAAmC,EACnC,aAAyB,EACzB,OAAqB;QApBtB,oBAAe,GAAG,IAAI,CAAC;QACf,UAAK,GAAG,CAAC,2BAA2B,CAAC,CAAC;QACtC,UAAK,GAAG,CAAC,CAAC;QACV,cAAS,GAAG,CAAC,CAAC;QACd,mBAAc,GAAG,CAAC,CAAC;QACnB,qBAAgB,GAAG,CAAC,CAAC;QACrB,UAAK,GAAG,IAAI,CAAC;QACb,aAAQ,GAAG,KAAK,CAAC;QACR,kBAAa,GAAG,IAAI,GAAG,EAAwB,CAAC;QAChD,eAAU,GAAG,IAAI,qBAAqB,EAAE,CAAC;QAazD,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;IAED,MAAM,CAAC,KAAa;QACnB,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,KAAK,KAAK,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YAC5D,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;YACnB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;YACnB,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC;gBAC9B,IAAI,EAAE,sBAAs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AE,OAAO;QACpB,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;QAC1C,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;QACjC,IAAI,MAAM,CAAC,SAAS;YAAE,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,SAAS,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\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\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\tprivate lines = [\"Loading remote component…\"];\n\tprivate width = 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) {\n\t\tthis.componentId = componentId;\n\t\tthis.runtime = runtime;\n\t\tthis.requestRender = requestRender;\n\t\tthis.getRows = getRows;\n\t}\n\n\trender(width: number): string[] {\n\t\tif (!this.disposed && (this.dirty || width !== this.width)) {\n\t\t\tthis.width = width;\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: this.getRows(),\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);\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): 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);\n\t\t\tthis.mounted.set(componentId, { component, done: () => {}, engineDone: false, handlesCtrlC, widgetKey });\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);\n\t\t\t\t\tmounted = { component, done, engineDone: false, handlesCtrlC };\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\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;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,KAAK,CAAC;QACR,kBAAa,GAAG,IAA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AAG,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"]}
@@ -84,7 +84,7 @@ The dedicated history actions always change history entries, regardless of the c
84
84
 
85
85
  ### TUI Fullscreen Viewport
86
86
 
87
- Interactive sessions always use this fullscreen viewport for the primary transcript scroll region. Mouse-wheel input scrolls the region under the pointer, falling back to the transcript over the fixed editor/status/footer dock. Clicking an OSC 8 hyperlink opens it in the default handler. Dragging with the primary mouse button selects text and copies it to the clipboard.
87
+ Interactive sessions always use this fullscreen viewport for the primary transcript scroll region. Mouse-wheel input scrolls the region under the pointer, falling back to the transcript over the fixed editor/status/footer dock. Clicking an OSC 8 hyperlink opens it in the default handler; the jump-to-bottom indicator's internal OSC 8 link returns the focused transcript surface to its live end, including an attached workflow stage chat. Dragging with the primary mouse button selects text and copies it to the clipboard.
88
88
 
89
89
 
90
90
  Fullscreen text selection comes from the installed pi-tui 0.84.1 renderer. Drag with the primary button to select characters; double-click selects a word and triple-click selects a line. Focus changes and non-drag clicks clear transient selection state, preventing a stale highlight from appearing. The renderer also reduces mouse tracking in tmux, Zellij, and GNU Screen.
@@ -117,15 +117,12 @@ On Windows, pressing the secondary mouse button in fullscreen pastes text from t
117
117
 
118
118
  | Keybinding id | Default | Description |
119
119
  |--------|---------|-------------|
120
- | `app.interrupt` | `escape` | Abort active or queued work and restore queued steering/follow-up messages to the editor; the session remains paused until an ordinary submission |
120
+ | `app.interrupt` | `escape` | Abort active or queued work and restore still-queued steering/follow-up messages to the editor; the session remains paused until an ordinary submission. A message the agent already picked up is answered instead of restored |
121
121
  | `app.clear` | `ctrl+c` | Interrupt active or queued work, or terminate an unresponsive interactive engine; once idle, clear the editor (press twice while idle to exit) |
122
122
  | `app.exit` | `ctrl+d` | Exit (when editor empty) |
123
123
  | `app.suspend` | `ctrl+z` (none on Windows) | Suspend to background |
124
124
  | `app.editor.external` | `ctrl+g` | Open in external editor (`$VISUAL` or `$EDITOR`) |
125
125
  | `app.clipboard.pasteImage` | `ctrl+v` (`alt+v` on Windows) | Paste image or text from clipboard |
126
- | `app.message.copy` | `ctrl+x` | Copy the last assistant message (or the selected message in `/tree`) |
127
-
128
- In fullscreen mode, a successful `app.message.copy` shortcut shows a short `Copied!` flash without adding a row to the fixed status dock. The `/copy` command keeps its normal status-line confirmation.
129
126
 
130
127
  When `app.clipboard.pasteImage` finds text rather than an image, Atomic inserts that clipboard text into the editor instead of reporting an image-paste failure.
131
128
 
package/docs/usage.md CHANGED
@@ -74,6 +74,8 @@ You can submit messages while the agent is still working:
74
74
  - **Ctrl+C** aborts active/queued work and pauses queued messages in place. They remain queued, in their original per-queue order, until you submit the next ordinary chat message; that submission resumes the chat and makes each queued item eligible once. After the abort settles, a later idle Ctrl+C clears the editor without releasing the hold, and a second quick idle press exits.
75
75
  - **ALT+Up** explicitly retrieves queued messages back to the editor without aborting active work or resuming a paused session. Even when retrieval empties the queue, the pause remains active until the next ordinary submission.
76
76
 
77
+ Both interrupts hold a queued message only while it is still waiting in the queue. A message the agent has already picked up is written into the transcript, and an interrupt that cancels its reply before any output appears no longer strands it: Atomic answers it instead of returning it to the editor. A reply that had already started printing is left as-is and is not restarted. Sending a message while that recovered reply is still streaming is safe — it is delivered as soon as the reply finishes.
78
+
77
79
  Both abort routes are cooperative: they ask the agent to stop and wait for it — Escape waits as long as the agent needs — and never terminate the engine that runs your tools. Ctrl+C additionally acts as an escape hatch: it always reaches Atomic when an extension's custom UI has taken over the screen — closing that UI if it does not handle the key itself — and it replaces the engine when it stops answering entirely, including a replacement that hangs before it finishes starting or one that failed to start. A message that could not be sent comes back to the editor rather than being lost: exactly as you typed it, with pasted content intact, placed above anything you typed while the send was pending and separated by a blank line, together with anything still queued behind it in the order you entered it. Atomic does not also show a red error for it. See [Keybindings](/keybindings#application).
78
80
 
79
81
  On Windows Terminal, ALT+Enter is fullscreen by default. Remap it as described in [Terminal setup](/terminal-setup) if you want Atomic to receive the shortcut.
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@bastani/atomic",
3
- "version": "0.9.13-alpha.3",
3
+ "version": "0.9.13",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@bastani/atomic",
9
- "version": "0.9.13-alpha.3",
9
+ "version": "0.9.13",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
- "@bastani/atomic-natives": "0.9.13-alpha.3",
12
+ "@bastani/atomic-natives": "0.9.13",
13
13
  "@dbos-inc/dbos-sdk": "4.24.16",
14
14
  "@earendil-works/pi-agent-core": "^0.84.1",
15
15
  "@earendil-works/pi-ai": "^0.84.1",
@@ -517,18 +517,18 @@
517
517
  }
518
518
  },
519
519
  "node_modules/@bastani/atomic-natives": {
520
- "version": "0.9.13-alpha.3",
521
- "resolved": "https://registry.npmjs.org/@bastani/atomic-natives/-/atomic-natives-0.9.13-alpha.3.tgz",
520
+ "version": "0.9.13",
521
+ "resolved": "https://registry.npmjs.org/@bastani/atomic-natives/-/atomic-natives-0.9.13.tgz",
522
522
  "license": "MIT",
523
523
  "optionalDependencies": {
524
- "@bastani/atomic-natives-darwin-arm64": "0.9.13-alpha.3",
525
- "@bastani/atomic-natives-darwin-x64": "0.9.13-alpha.3",
526
- "@bastani/atomic-natives-linux-arm64-gnu": "0.9.13-alpha.3",
527
- "@bastani/atomic-natives-linux-arm64-musl": "0.9.13-alpha.3",
528
- "@bastani/atomic-natives-linux-x64-gnu": "0.9.13-alpha.3",
529
- "@bastani/atomic-natives-linux-x64-musl": "0.9.13-alpha.3",
530
- "@bastani/atomic-natives-win32-arm64-msvc": "0.9.13-alpha.3",
531
- "@bastani/atomic-natives-win32-x64-msvc": "0.9.13-alpha.3"
524
+ "@bastani/atomic-natives-darwin-arm64": "0.9.13",
525
+ "@bastani/atomic-natives-darwin-x64": "0.9.13",
526
+ "@bastani/atomic-natives-linux-arm64-gnu": "0.9.13",
527
+ "@bastani/atomic-natives-linux-arm64-musl": "0.9.13",
528
+ "@bastani/atomic-natives-linux-x64-gnu": "0.9.13",
529
+ "@bastani/atomic-natives-linux-x64-musl": "0.9.13",
530
+ "@bastani/atomic-natives-win32-arm64-msvc": "0.9.13",
531
+ "@bastani/atomic-natives-win32-x64-msvc": "0.9.13"
532
532
  },
533
533
  "engines": {
534
534
  "bun": ">=1.3.14",
@@ -536,8 +536,8 @@
536
536
  }
537
537
  },
538
538
  "node_modules/@bastani/atomic-natives-darwin-arm64": {
539
- "version": "0.9.13-alpha.3",
540
- "resolved": "https://registry.npmjs.org/@bastani/atomic-natives-darwin-arm64/-/atomic-natives-darwin-arm64-0.9.13-alpha.3.tgz",
539
+ "version": "0.9.13",
540
+ "resolved": "https://registry.npmjs.org/@bastani/atomic-natives-darwin-arm64/-/atomic-natives-darwin-arm64-0.9.13.tgz",
541
541
  "license": "MIT",
542
542
  "os": [
543
543
  "darwin"
@@ -548,8 +548,8 @@
548
548
  "optional": true
549
549
  },
550
550
  "node_modules/@bastani/atomic-natives-darwin-x64": {
551
- "version": "0.9.13-alpha.3",
552
- "resolved": "https://registry.npmjs.org/@bastani/atomic-natives-darwin-x64/-/atomic-natives-darwin-x64-0.9.13-alpha.3.tgz",
551
+ "version": "0.9.13",
552
+ "resolved": "https://registry.npmjs.org/@bastani/atomic-natives-darwin-x64/-/atomic-natives-darwin-x64-0.9.13.tgz",
553
553
  "license": "MIT",
554
554
  "os": [
555
555
  "darwin"
@@ -560,8 +560,8 @@
560
560
  "optional": true
561
561
  },
562
562
  "node_modules/@bastani/atomic-natives-linux-arm64-gnu": {
563
- "version": "0.9.13-alpha.3",
564
- "resolved": "https://registry.npmjs.org/@bastani/atomic-natives-linux-arm64-gnu/-/atomic-natives-linux-arm64-gnu-0.9.13-alpha.3.tgz",
563
+ "version": "0.9.13",
564
+ "resolved": "https://registry.npmjs.org/@bastani/atomic-natives-linux-arm64-gnu/-/atomic-natives-linux-arm64-gnu-0.9.13.tgz",
565
565
  "license": "MIT",
566
566
  "os": [
567
567
  "linux"
@@ -575,8 +575,8 @@
575
575
  "optional": true
576
576
  },
577
577
  "node_modules/@bastani/atomic-natives-linux-arm64-musl": {
578
- "version": "0.9.13-alpha.3",
579
- "resolved": "https://registry.npmjs.org/@bastani/atomic-natives-linux-arm64-musl/-/atomic-natives-linux-arm64-musl-0.9.13-alpha.3.tgz",
578
+ "version": "0.9.13",
579
+ "resolved": "https://registry.npmjs.org/@bastani/atomic-natives-linux-arm64-musl/-/atomic-natives-linux-arm64-musl-0.9.13.tgz",
580
580
  "license": "MIT",
581
581
  "os": [
582
582
  "linux"
@@ -590,8 +590,8 @@
590
590
  "optional": true
591
591
  },
592
592
  "node_modules/@bastani/atomic-natives-linux-x64-gnu": {
593
- "version": "0.9.13-alpha.3",
594
- "resolved": "https://registry.npmjs.org/@bastani/atomic-natives-linux-x64-gnu/-/atomic-natives-linux-x64-gnu-0.9.13-alpha.3.tgz",
593
+ "version": "0.9.13",
594
+ "resolved": "https://registry.npmjs.org/@bastani/atomic-natives-linux-x64-gnu/-/atomic-natives-linux-x64-gnu-0.9.13.tgz",
595
595
  "license": "MIT",
596
596
  "os": [
597
597
  "linux"
@@ -605,8 +605,8 @@
605
605
  "optional": true
606
606
  },
607
607
  "node_modules/@bastani/atomic-natives-linux-x64-musl": {
608
- "version": "0.9.13-alpha.3",
609
- "resolved": "https://registry.npmjs.org/@bastani/atomic-natives-linux-x64-musl/-/atomic-natives-linux-x64-musl-0.9.13-alpha.3.tgz",
608
+ "version": "0.9.13",
609
+ "resolved": "https://registry.npmjs.org/@bastani/atomic-natives-linux-x64-musl/-/atomic-natives-linux-x64-musl-0.9.13.tgz",
610
610
  "license": "MIT",
611
611
  "os": [
612
612
  "linux"
@@ -620,8 +620,8 @@
620
620
  "optional": true
621
621
  },
622
622
  "node_modules/@bastani/atomic-natives-win32-arm64-msvc": {
623
- "version": "0.9.13-alpha.3",
624
- "resolved": "https://registry.npmjs.org/@bastani/atomic-natives-win32-arm64-msvc/-/atomic-natives-win32-arm64-msvc-0.9.13-alpha.3.tgz",
623
+ "version": "0.9.13",
624
+ "resolved": "https://registry.npmjs.org/@bastani/atomic-natives-win32-arm64-msvc/-/atomic-natives-win32-arm64-msvc-0.9.13.tgz",
625
625
  "license": "MIT",
626
626
  "os": [
627
627
  "win32"
@@ -632,8 +632,8 @@
632
632
  "optional": true
633
633
  },
634
634
  "node_modules/@bastani/atomic-natives-win32-x64-msvc": {
635
- "version": "0.9.13-alpha.3",
636
- "resolved": "https://registry.npmjs.org/@bastani/atomic-natives-win32-x64-msvc/-/atomic-natives-win32-x64-msvc-0.9.13-alpha.3.tgz",
635
+ "version": "0.9.13",
636
+ "resolved": "https://registry.npmjs.org/@bastani/atomic-natives-win32-x64-msvc/-/atomic-natives-win32-x64-msvc-0.9.13.tgz",
637
637
  "license": "MIT",
638
638
  "os": [
639
639
  "win32"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bastani/atomic",
3
- "version": "0.9.13-alpha.3",
3
+ "version": "0.9.13",
4
4
  "description": "Atomic coding agent CLI with read, bash, edit, write tools and session management",
5
5
  "type": "module",
6
6
  "atomicConfig": {
@@ -83,7 +83,7 @@
83
83
  "prepublishOnly": "bun run clean && bun run build && bun run shrinkwrap"
84
84
  },
85
85
  "dependencies": {
86
- "@bastani/atomic-natives": "0.9.13-alpha.3",
86
+ "@bastani/atomic-natives": "0.9.13",
87
87
  "@dbos-inc/dbos-sdk": "4.24.16",
88
88
  "@earendil-works/pi-agent-core": "^0.84.1",
89
89
  "@earendil-works/pi-ai": "^0.84.1",