@oxbit/cli 0.11.3 → 0.11.4

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.
@@ -6,11 +6,11 @@ import { c as contextLegend, a as contextGrid, f as formatTokens, b as contextNo
6
6
  import { writeFile } from "node:fs/promises";
7
7
  import { homedir } from "node:os";
8
8
  import { resolve } from "node:path";
9
- import { memoryTuiConnection, fileHistory } from "./memory-Bdy8hvTl.js";
9
+ import { memoryTuiConnection, fileHistory } from "./memory-C3ixKimB.js";
10
+ import "node:child_process";
10
11
  import "node:util";
11
12
  import "node:readline";
12
13
  import "node:crypto";
13
- import "node:child_process";
14
14
  import "node:http";
15
15
  import "node:fs";
16
16
  const THEMES = {
@@ -1195,6 +1195,7 @@ function applyStatus(status, update) {
1195
1195
  return next;
1196
1196
  }
1197
1197
  const modelName = (status) => status.models.find((model) => model.value === status.model)?.name ?? status.model;
1198
+ const NO_SESSION = "There is no open session. Run /new to start one.";
1198
1199
  const STOP_NOTES = {
1199
1200
  cancelled: "Interrupted",
1200
1201
  max_tokens: "The response reached the output token limit",
@@ -1227,6 +1228,7 @@ class SessionController {
1227
1228
  timer;
1228
1229
  hintTimer;
1229
1230
  early;
1231
+ opening;
1230
1232
  stop;
1231
1233
  onExit;
1232
1234
  subscribe = (listener) => {
@@ -1281,7 +1283,15 @@ class SessionController {
1281
1283
  if (this.state.running) return this.notice("Wait for the agent to finish, or press Esc to stop it", "warn");
1282
1284
  await this.load(this.state.status.sessionId, false);
1283
1285
  }
1284
- async load(sessionId, replay) {
1286
+ /** Opens the session; prompts sent before it resolves wait for it. */
1287
+ load(sessionId, replay) {
1288
+ const opening = this.connect(sessionId, replay);
1289
+ this.opening = opening;
1290
+ return opening.finally(() => {
1291
+ if (this.opening === opening) this.opening = void 0;
1292
+ });
1293
+ }
1294
+ async connect(sessionId, replay) {
1285
1295
  this.early = [];
1286
1296
  let session;
1287
1297
  try {
@@ -1303,12 +1313,14 @@ class SessionController {
1303
1313
  if (replay) this.transcript(endTurn);
1304
1314
  }
1305
1315
  async send(text) {
1306
- const sessionId = this.state.status.sessionId;
1307
- if (!sessionId) return this.notice("There is no open session. Run /new to start one.", "error");
1316
+ if (!this.state.status.sessionId && !this.opening) return this.notice(NO_SESSION, "error");
1308
1317
  this.set({ transcript: append(this.state.transcript, { type: "user", text }), running: true, startedAt: Date.now() });
1309
1318
  let failed;
1310
1319
  let stopReason = "end_turn";
1311
1320
  try {
1321
+ await this.opening;
1322
+ const sessionId = this.state.status.sessionId;
1323
+ if (!sessionId) throw new Error(NO_SESSION);
1312
1324
  stopReason = (await this.connection.prompt(sessionId, [{ type: "text", text }])).stopReason;
1313
1325
  } catch (error) {
1314
1326
  failed = message(error);
@@ -2480,4 +2492,4 @@ export {
2480
2492
  run,
2481
2493
  runTui
2482
2494
  };
2483
- //# sourceMappingURL=index-DU-a4mnM.js.map
2495
+ //# sourceMappingURL=index-Crr8fCGQ.js.map
@@ -2,12 +2,12 @@
2
2
  import { mkdirSync, appendFileSync, readFileSync, writeFileSync } from "node:fs";
3
3
  import { dirname } from "node:path";
4
4
  import { w as walkFiles } from "../index.js";
5
+ import "node:child_process";
5
6
  import "node:util";
6
7
  import "node:readline";
7
8
  import "node:fs/promises";
8
9
  import "node:crypto";
9
10
  import "node:os";
10
- import "node:child_process";
11
11
  import "node:http";
12
12
  const FILE_LIST_TTL_MS = 1e4;
13
13
  const FILE_MATCHES = 2e3;
@@ -22,6 +22,7 @@ const subsequence = (query, path) => {
22
22
  };
23
23
  function memoryTuiConnection(initial, options = {}) {
24
24
  let connection = initial;
25
+ let { modes, model } = options;
25
26
  let info = { provider: options.provider, usingChatGPTPlan: options.usingChatGPTPlan };
26
27
  let mode = options.mode;
27
28
  const listeners = /* @__PURE__ */ new Set();
@@ -51,7 +52,8 @@ function memoryTuiConnection(initial, options = {}) {
51
52
  get connection() {
52
53
  return connection;
53
54
  },
54
- async replace(next, nextInfo) {
55
+ async replace(next, nextInfo, nextOptions = {}) {
56
+ ({ modes, model } = nextOptions);
55
57
  const previous = connection;
56
58
  for (const stop of detach) stop();
57
59
  connection = next;
@@ -61,10 +63,12 @@ function memoryTuiConnection(initial, options = {}) {
61
63
  },
62
64
  info: () => ({ ...info }),
63
65
  async newSession(cwd) {
64
- const state = await connection.newSession({ cwd });
65
- if (!mode || !state.modes || state.modes.currentModeId === mode) return state;
66
- await connection.setMode(state.sessionId, mode);
67
- return { ...state, modes: { ...state.modes, currentModeId: mode } };
66
+ let state = await connection.newSession({ cwd });
67
+ if (model) state = { ...state, ...await connection.setModel(state.sessionId, model) };
68
+ const modeId = mode && (modes?.[mode] ?? mode);
69
+ if (!modeId || !state.modes || state.modes.currentModeId === modeId) return state;
70
+ await connection.setMode(state.sessionId, modeId);
71
+ return { ...state, modes: { ...state.modes, currentModeId: modeId } };
68
72
  },
69
73
  loadSession: async (sessionId, cwd) => await connection.loadSession(sessionId, { cwd }),
70
74
  listSessions: async (cwd) => (await connection.listSessions(cwd)).sessions,
@@ -132,4 +136,4 @@ export {
132
136
  fileHistory,
133
137
  memoryTuiConnection
134
138
  };
135
- //# sourceMappingURL=memory-Bdy8hvTl.js.map
139
+ //# sourceMappingURL=memory-C3ixKimB.js.map