@ouro.bot/cli 0.1.0-alpha.1015 → 0.1.0-alpha.1018

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.
@@ -597,11 +597,11 @@ function InputArea({ onSubmit, onCtrlC, history, queuedInputs, onPopQueue, agent
597
597
  })() }) })), (0, jsx_runtime_1.jsx)(ink_1.Text, { dimColor: true, children: "─".repeat(termWidth()) }), (0, jsx_runtime_1.jsxs)(ink_1.Box, { children: [(0, jsx_runtime_1.jsxs)(ink_1.Text, { dimColor: true, children: [" ", agentName, model ? ` · ${model}` : "", " \u00B7 /help"] }), (0, jsx_runtime_1.jsx)(ink_1.Box, { flexGrow: 1 }), tooltip ? (0, jsx_runtime_1.jsx)(ink_1.Text, { dimColor: true, children: tooltip }) : (0, jsx_runtime_1.jsx)(ink_1.Text, { dimColor: true, children: "opt+enter for newline" })] })] }));
598
598
  }
599
599
  // ─── Main TUI Component ─────────────────────────────────────────────
600
- function OuroTui({ agentName, model, completedMessages, inputHistory, queuedInputs, live, elapsedSeconds, contextPercent, onSubmit, onCtrlC, onPopQueue, cwd, resumeInfo, onImageMap, onHistoryAdd, }) {
600
+ function OuroTui({ agentName, model, completedMessages, inputHistory, queuedInputs, live, elapsedSeconds, contextPercent, onSubmit, onCtrlC, onPopQueue, cwd, resumeInfo, onImageMap, onHistoryAdd, paused, }) {
601
601
  return ((0, jsx_runtime_1.jsxs)(ink_1.Box, { flexDirection: "column", children: [(0, jsx_runtime_1.jsx)(ink_1.Static, { items: [{ id: "__header__" }, ...completedMessages], children: (item, index) => {
602
602
  if (index === 0) {
603
603
  return ((0, jsx_runtime_1.jsxs)(ink_1.Box, { flexDirection: "column", marginBottom: 2, children: [(0, jsx_runtime_1.jsx)(ink_1.Box, { marginTop: 1, children: (0, jsx_runtime_1.jsx)(ink_1.Text, { children: "" }) }), (0, jsx_runtime_1.jsx)(Header, { agentName: agentName, model: model, contextPercent: contextPercent, cwd: cwd, resumeInfo: resumeInfo }), (0, jsx_runtime_1.jsx)(ink_1.Text, { color: OURO.shadow, dimColor: true, children: " Ctrl-C twice to exit \u00b7 \u2191\u2193 history \u00b7 Esc clear \u00b7 opt+Enter newline" })] }, "header"));
604
604
  }
605
605
  return (0, jsx_runtime_1.jsx)(MessageBlock, { msg: item }, item.id);
606
- } }), (live.loading || live.streamingText || live.activeTool) ? (0, jsx_runtime_1.jsx)(ink_1.Box, { marginTop: 1, children: (0, jsx_runtime_1.jsx)(ink_1.Text, { children: "" }) }) : null, (0, jsx_runtime_1.jsx)(LiveArea, { live: live, elapsed: elapsedSeconds }), (live.loading || live.streamingText || live.activeTool) ? (0, jsx_runtime_1.jsx)(ink_1.Box, { marginBottom: 1, children: (0, jsx_runtime_1.jsx)(ink_1.Text, { children: "" }) }) : null, queuedInputs.length > 0 ? (0, jsx_runtime_1.jsx)(QueuedMessages, { items: queuedInputs }) : null, (0, jsx_runtime_1.jsx)(ink_1.Box, { marginTop: 1, children: (0, jsx_runtime_1.jsx)(ink_1.Text, { children: "" }) }), (0, jsx_runtime_1.jsx)(InputArea, { onSubmit: onSubmit, onCtrlC: onCtrlC, history: inputHistory, queuedInputs: queuedInputs, onPopQueue: onPopQueue, agentName: agentName, model: model, onImageMap: onImageMap, onHistoryAdd: onHistoryAdd })] }));
606
+ } }), paused ? null : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(live.loading || live.streamingText || live.activeTool) ? (0, jsx_runtime_1.jsx)(ink_1.Box, { marginTop: 1, children: (0, jsx_runtime_1.jsx)(ink_1.Text, { children: "" }) }) : null, (0, jsx_runtime_1.jsx)(LiveArea, { live: live, elapsed: elapsedSeconds }), (live.loading || live.streamingText || live.activeTool) ? (0, jsx_runtime_1.jsx)(ink_1.Box, { marginBottom: 1, children: (0, jsx_runtime_1.jsx)(ink_1.Text, { children: "" }) }) : null, queuedInputs.length > 0 ? (0, jsx_runtime_1.jsx)(QueuedMessages, { items: queuedInputs }) : null, (0, jsx_runtime_1.jsx)(ink_1.Box, { marginTop: 1, children: (0, jsx_runtime_1.jsx)(ink_1.Text, { children: "" }) }), (0, jsx_runtime_1.jsx)(InputArea, { onSubmit: onSubmit, onCtrlC: onCtrlC, history: inputHistory, queuedInputs: queuedInputs, onPopQueue: onPopQueue, agentName: agentName, model: model, onImageMap: onImageMap, onHistoryAdd: onHistoryAdd })] }))] }));
607
607
  }
@@ -33,11 +33,14 @@ class TuiStore {
33
33
  _headerShown = false;
34
34
  _inputHistory = [];
35
35
  _queuedInputs = [];
36
+ _paused = false;
36
37
  get completedMessages() { return this._completed; }
37
38
  get live() { return this._live; }
38
39
  get headerShown() { return this._headerShown; }
39
40
  get inputHistory() { return this._inputHistory; }
40
41
  get queuedInputs() { return this._queuedInputs; }
42
+ /** True while a hidden terminal prompt has the terminal (no live area, no input box). */
43
+ get paused() { return this._paused; }
41
44
  /** Elapsed seconds since spinner started — computed on demand, not stored */
42
45
  getElapsed() {
43
46
  if (this._live.loading && this._spinnerStart > 0) {
@@ -128,6 +131,14 @@ class TuiStore {
128
131
  this._live = { ...this._live, loading: false, kickMessage: (0, format_1.formatKick)() };
129
132
  this.notify();
130
133
  }
134
+ pause() {
135
+ this._paused = true;
136
+ this.notify();
137
+ }
138
+ resume() {
139
+ this._paused = false;
140
+ this.notify();
141
+ }
131
142
  suppressInput() {
132
143
  this._live = { ...this._live, inputSuppressed: true };
133
144
  this.notify();
@@ -46,6 +46,7 @@ exports.addHistory = addHistory;
46
46
  exports.renderMarkdown = renderMarkdown;
47
47
  exports.createCliCallbacks = createCliCallbacks;
48
48
  exports.createDebouncedLines = createDebouncedLines;
49
+ exports.createExitOnToolCallExecTool = createExitOnToolCallExecTool;
49
50
  exports.runCliSession = runCliSession;
50
51
  exports.main = main;
51
52
  const readline = __importStar(require("readline"));
@@ -77,6 +78,7 @@ const cli_layout_1 = require("./cli-layout");
77
78
  const image_paste_1 = require("./cli/image-paste");
78
79
  const spinner_imperative_1 = require("./cli/spinner-imperative");
79
80
  const tool_display_1 = require("./cli/tool-display");
81
+ const terminal_handoff_1 = require("./terminal-handoff");
80
82
  var cli_layout_2 = require("./cli-layout");
81
83
  Object.defineProperty(exports, "formatEchoedInputSummary", { enumerable: true, get: function () { return cli_layout_2.formatEchoedInputSummary; } });
82
84
  Object.defineProperty(exports, "wrapCliText", { enumerable: true, get: function () { return cli_layout_2.wrapCliText; } });
@@ -511,6 +513,25 @@ class InputQueue {
511
513
  }
512
514
  }
513
515
  exports.InputQueue = InputQueue;
516
+ /** Wrap execTool so a call to `toolName` ends the session, unless `shouldExit` rejects its result. */
517
+ function createExitOnToolCallExecTool(execTool, toolName, shouldExit, onExit) {
518
+ return async (name, args, ctx) => {
519
+ const result = await execTool(name, args, ctx);
520
+ if (name !== toolName)
521
+ return result;
522
+ if (shouldExit && !shouldExit(result)) {
523
+ (0, runtime_1.emitNervesEvent)({
524
+ component: "senses",
525
+ event: "senses.cli_exit_tool_declined",
526
+ message: "exit tool result did not end the session",
527
+ meta: { tool: name },
528
+ });
529
+ return result;
530
+ }
531
+ onExit(result);
532
+ return result;
533
+ };
534
+ }
514
535
  async function runCliSession(options) {
515
536
  /* v8 ignore start -- integration: runCliSession is interactive, tested via E2E @preserve */
516
537
  const registry = (0, commands_1.createCommandRegistry)();
@@ -528,6 +549,7 @@ async function runCliSession(options) {
528
549
  let cliCallbacks;
529
550
  let tuiStore = null;
530
551
  let inkRef = null;
552
+ let releaseTerminal = null;
531
553
  const inputQueue = useTui ? new InputQueue() : null;
532
554
  let rl = null;
533
555
  if (useTui) {
@@ -623,6 +645,7 @@ async function runCliSession(options) {
623
645
  onCtrlC: handleCtrlC,
624
646
  onPopQueue: () => { const items = storeRef.popAllQueuedForEditing(); inputQueue.drainAll(); return items; },
625
647
  headerShown: storeRef.headerShown,
648
+ paused: storeRef.paused,
626
649
  cwd: process.cwd().replace(process.env.HOME ?? "", "~"),
627
650
  resumeInfo,
628
651
  onImageMap: (images) => { pendingImages = images; },
@@ -630,6 +653,15 @@ async function runCliSession(options) {
630
653
  });
631
654
  }
632
655
  inkRef = ink.render(React.createElement(TuiRoot), { exitOnCtrlC: false, patchConsole: false });
656
+ releaseTerminal = (0, terminal_handoff_1.claimTerminal)({
657
+ suspend: async () => {
658
+ storeRef.pause();
659
+ // Ink throttles repaints to 32 ms and drops its stdin listener in an effect cleanup;
660
+ // let both land before the prompt starts reading keystrokes.
661
+ await new Promise((resolve) => setTimeout(resolve, 80));
662
+ },
663
+ resume: () => storeRef.resume(),
664
+ });
633
665
  }
634
666
  catch (err) {
635
667
  // Ink failed to load (CJS compat, missing deps, etc.) — fall through to imperative
@@ -702,15 +734,11 @@ async function runCliSession(options) {
702
734
  let exitToolFired = false;
703
735
  const resolvedExecTool = options.execTool;
704
736
  const wrappedExecTool = options.exitOnToolCall && resolvedExecTool
705
- ? async (name, args, ctx) => {
706
- const result = await resolvedExecTool(name, args, ctx);
707
- if (name === options.exitOnToolCall) {
708
- exitToolResult = result;
709
- exitToolFired = true;
710
- currentAbort?.abort();
711
- }
712
- return result;
713
- }
737
+ ? createExitOnToolCallExecTool(resolvedExecTool, options.exitOnToolCall, options.exitOnToolResult, (result) => {
738
+ exitToolResult = result;
739
+ exitToolFired = true;
740
+ currentAbort?.abort();
741
+ })
714
742
  : resolvedExecTool;
715
743
  // Resolve toolChoiceRequired: use explicit option if set, else fall back to toggle
716
744
  const getEffectiveToolChoiceRequired = () => options.toolChoiceRequired !== undefined ? options.toolChoiceRequired : (0, commands_1.getToolChoiceRequired)();
@@ -900,6 +928,7 @@ async function runCliSession(options) {
900
928
  }
901
929
  finally {
902
930
  rl?.close();
931
+ releaseTerminal?.();
903
932
  if (inkRef) {
904
933
  // Suppress React "state update on unmounted component" warnings during cleanup.
905
934
  // Ink's useInput hook fires after unmount — this is harmless but noisy.
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.claimTerminal = claimTerminal;
4
+ exports.withTerminalHandedOff = withTerminalHandedOff;
5
+ /**
6
+ * Lets a hidden terminal prompt (for example the hatchling vault unlock secret) borrow the
7
+ * terminal from a live full-screen session. While the prompt runs, the session's owner stops
8
+ * repainting and stops reading stdin, so the prompt is visible and keystrokes reach only it.
9
+ */
10
+ const runtime_1 = require("../nerves/runtime");
11
+ let currentOwner = null;
12
+ /** Register the live session that owns the terminal. Returns a release function. */
13
+ function claimTerminal(owner) {
14
+ currentOwner = owner;
15
+ return () => {
16
+ if (currentOwner === owner)
17
+ currentOwner = null;
18
+ };
19
+ }
20
+ /** Run `prompt` with the terminal handed to it, then give the terminal back. */
21
+ async function withTerminalHandedOff(prompt) {
22
+ const owner = currentOwner;
23
+ if (!owner)
24
+ return prompt();
25
+ (0, runtime_1.emitNervesEvent)({
26
+ component: "senses",
27
+ event: "senses.terminal_handed_off",
28
+ message: "live session suspended for a terminal prompt",
29
+ meta: {},
30
+ });
31
+ await owner.suspend();
32
+ try {
33
+ return await prompt();
34
+ }
35
+ finally {
36
+ owner.resume();
37
+ (0, runtime_1.emitNervesEvent)({
38
+ component: "senses",
39
+ event: "senses.terminal_taken_back",
40
+ message: "live session resumed after a terminal prompt",
41
+ meta: {},
42
+ });
43
+ }
44
+ }