@moxt-ai/mobius 0.0.76 → 0.0.77

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.
package/dist/index.js CHANGED
@@ -34927,10 +34927,29 @@ var threadStartResponseSchema = external_exports.object({
34927
34927
  serviceTier: boundedText(256).nullish(),
34928
34928
  thread: external_exports.object({ id: boundedText(256) })
34929
34929
  });
34930
- var threadResumeResponseSchema = external_exports.object({
34930
+ var threadLifecycleResponseSchema = external_exports.object({
34931
34931
  model: boundedText(256).nullish(),
34932
34932
  reasoningEffort: boundedText(256).nullish(),
34933
- thread: external_exports.object({ id: boundedText(256) }).nullish()
34933
+ serviceTier: boundedText(256).nullish(),
34934
+ thread: external_exports.object({ id: boundedText(256) }),
34935
+ turns: external_exports.array(
34936
+ external_exports.object({
34937
+ items: external_exports.array(external_exports.unknown()).max(1e5)
34938
+ })
34939
+ ).max(1e5).nullish()
34940
+ });
34941
+ var threadResumeResponseSchema = threadLifecycleResponseSchema;
34942
+ var threadForkResponseSchema = threadLifecycleResponseSchema;
34943
+ var threadSummarySchema = external_exports.object({
34944
+ cwd: boundedText(2048),
34945
+ id: boundedText(256),
34946
+ name: boundedText(500).nullish(),
34947
+ preview: boundedText(500).nullish(),
34948
+ updatedAt: external_exports.number().int().nonnegative()
34949
+ });
34950
+ var threadListResponseSchema = external_exports.object({
34951
+ data: external_exports.array(threadSummarySchema).max(500),
34952
+ nextCursor: boundedText(1024).nullish()
34934
34953
  });
34935
34954
  var reasoningEffortOptionSchema = external_exports.object({
34936
34955
  description: boundedText(4096).nullish(),
@@ -34949,19 +34968,6 @@ var modelListResponseSchema = external_exports.object({
34949
34968
  data: external_exports.array(modelSchema).max(1e3),
34950
34969
  nextCursor: boundedText(1024).nullish()
34951
34970
  });
34952
- var threadSchema = external_exports.object({
34953
- createdAt: external_exports.number().nullish(),
34954
- cwd: boundedText(4096).nullish(),
34955
- id: boundedText(256),
34956
- name: boundedText(4096).nullish(),
34957
- preview: boundedText(4096).nullish(),
34958
- updatedAt: external_exports.number().nullish()
34959
- });
34960
- var threadListResponseSchema = external_exports.object({
34961
- data: external_exports.array(threadSchema).max(1e4),
34962
- nextCursor: boundedText(1024).nullish()
34963
- });
34964
- var turnSteerResponseSchema = external_exports.object({ turnId: boundedText(256) });
34965
34971
 
34966
34972
  // src/acp/codex/app-server-client.ts
34967
34973
  var INITIALIZE_TIMEOUT_MILLISECONDS = 3e4;
@@ -35301,7 +35307,7 @@ function agentMessageMeta(phase) {
35301
35307
  var APPROVAL_REASON_CHARACTER_LIMIT = 500;
35302
35308
  var APPROVAL_TIMEOUT_MILLISECONDS = 36e5;
35303
35309
  var CODEX_AGENT_VERSION = "0.154.0";
35304
- var STEERING_METHOD = "_session/steering";
35310
+ var SESSION_LIST_TIMEOUT_MILLISECONDS = 3e4;
35305
35311
  var MODEL_SETTING_ID = "model";
35306
35312
  var REASONING_EFFORT_SETTING_ID = "reasoning_effort";
35307
35313
  var MODE_SETTING_ID = "mode";
@@ -35352,26 +35358,6 @@ function initialMode(environment) {
35352
35358
  function capitalize(value) {
35353
35359
  return value.length === 0 ? value : value.charAt(0).toUpperCase() + value.slice(1);
35354
35360
  }
35355
- function threadTitle(thread) {
35356
- const named = thread.name?.trim() ?? "";
35357
- if (named.length > 0) {
35358
- return named;
35359
- }
35360
- return thread.preview?.trim() ?? "";
35361
- }
35362
- function isoTimestamp(seconds) {
35363
- if (seconds == null || !Number.isFinite(seconds)) {
35364
- return null;
35365
- }
35366
- return new Date(seconds * 1e3).toISOString();
35367
- }
35368
- function steeringParams(params) {
35369
- const prompt = typeof params === "object" && params !== null ? Reflect.get(params, "prompt") : void 0;
35370
- if (!Array.isArray(prompt)) {
35371
- throw new AcpExecutionError("The steering prompt is invalid", {}, "steering_failed");
35372
- }
35373
- return { prompt };
35374
- }
35375
35361
  var APPROVAL_OPTIONS = Object.freeze([
35376
35362
  { kind: "allow_once", name: "Allow once", optionId: "accept" },
35377
35363
  { kind: "allow_always", name: "Allow for this session", optionId: "acceptForSession" },
@@ -35543,14 +35529,12 @@ var CodexAcpAgent = class {
35543
35529
  this.#connection = connection;
35544
35530
  }).onRequest(methods4.agent.initialize, async () => ({
35545
35531
  agentCapabilities: {
35546
- loadSession: false,
35532
+ loadSession: true,
35547
35533
  promptCapabilities: { embeddedContext: true, image: true },
35548
- sessionCapabilities: { close: {}, delete: {}, list: {}, resume: {} }
35534
+ sessionCapabilities: { close: {}, fork: {}, list: {} }
35549
35535
  },
35550
35536
  agentInfo: { name: "Codex", version: CODEX_AGENT_VERSION },
35551
35537
  authMethods: [],
35552
- // Mobius reads this to decide whether mid-turn steering can be attempted at all.
35553
- _meta: { steering: { supported: true } },
35554
35538
  protocolVersion: PROTOCOL_VERSION2
35555
35539
  })).onRequest(methods4.agent.session.new, async (context) => {
35556
35540
  const created = threadStartResponseSchema.parse(
@@ -35567,86 +35551,68 @@ var CodexAcpAgent = class {
35567
35551
  model: created.model ?? ""
35568
35552
  };
35569
35553
  return { configOptions: this.#configOptions(), sessionId: created.thread.id };
35554
+ }).onRequest(methods4.agent.session.setConfigOption, async (context) => {
35555
+ this.#applySelection(context.params.configId, context.params.value);
35556
+ return { configOptions: this.#configOptions() };
35557
+ }).onRequest(methods4.agent.session.setMode, async (context) => {
35558
+ this.#applySelection(MODE_SETTING_ID, context.params.modeId);
35559
+ return {};
35560
+ }).onRequest(methods4.agent.session.load, async (context) => {
35561
+ const resumed = threadResumeResponseSchema.parse(
35562
+ await this.#appServer.request(
35563
+ "thread/resume",
35564
+ { cwd: context.params.cwd, excludeTurns: false, threadId: context.params.sessionId },
35565
+ AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
35566
+ )
35567
+ );
35568
+ this.#selectRestoredThread(resumed);
35569
+ await this.#replayHistory(resumed.turns);
35570
+ return {};
35571
+ }).onRequest(methods4.agent.session.fork, async (context) => {
35572
+ const forked = threadForkResponseSchema.parse(
35573
+ await this.#appServer.request(
35574
+ "thread/fork",
35575
+ {
35576
+ cwd: context.params.cwd,
35577
+ excludeTurns: false,
35578
+ threadId: context.params.sessionId
35579
+ },
35580
+ AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
35581
+ )
35582
+ );
35583
+ this.#selectRestoredThread(forked);
35584
+ await this.#replayHistory(forked.turns);
35585
+ return { sessionId: forked.thread.id };
35570
35586
  }).onRequest(methods4.agent.session.resume, async (context) => {
35571
35587
  const resumed = threadResumeResponseSchema.parse(
35572
35588
  await this.#appServer.request(
35573
35589
  "thread/resume",
35574
- { cwd: context.params.cwd, threadId: context.params.sessionId },
35590
+ { cwd: context.params.cwd, excludeTurns: true, threadId: context.params.sessionId },
35575
35591
  AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
35576
35592
  )
35577
35593
  );
35578
- if (resumed.thread == null) {
35579
- throw new AcpExecutionError(
35580
- "Codex no longer has the native session this conversation belongs to",
35581
- {},
35582
- "session_restore_unsupported"
35583
- );
35584
- }
35585
- this.#nativeSessionId = resumed.thread.id;
35586
- this.#selection = {
35587
- ...this.#selection,
35588
- effort: resumed.reasoningEffort ?? this.#selection.effort,
35589
- model: resumed.model ?? this.#selection.model
35590
- };
35591
- return { configOptions: this.#configOptions() };
35594
+ this.#selectRestoredThread(resumed);
35595
+ return {};
35596
+ }).onRequest(methods4.agent.session.prompt, async (context) => {
35597
+ return await this.#runTurn(promptInput(context.params.prompt), context.signal);
35592
35598
  }).onRequest(methods4.agent.session.list, async (context) => {
35593
- const listed = threadListResponseSchema.parse(
35599
+ const decoded = threadListResponseSchema.parse(
35594
35600
  await this.#appServer.request(
35595
35601
  "thread/list",
35596
- context.params.cursor === void 0 || context.params.cursor === null ? {} : { cursor: context.params.cursor },
35597
- AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
35602
+ { cursor: context.params.cursor ?? null },
35603
+ AbortSignal.any([context.signal, AbortSignal.timeout(SESSION_LIST_TIMEOUT_MILLISECONDS)])
35598
35604
  )
35599
35605
  );
35600
35606
  return {
35601
- nextCursor: listed.nextCursor ?? null,
35602
- sessions: listed.data.map((thread) => ({
35603
- // The thread id is a UUID, which satisfies the native session id contract.
35607
+ nextCursor: decoded.nextCursor ?? null,
35608
+ sessions: decoded.data.map((thread) => ({
35604
35609
  additionalDirectories: [],
35605
- cwd: thread.cwd ?? "",
35610
+ cwd: thread.cwd,
35606
35611
  sessionId: thread.id,
35607
- title: threadTitle(thread),
35608
- updatedAt: isoTimestamp(thread.updatedAt)
35612
+ title: thread.name ?? thread.preview ?? null,
35613
+ updatedAt: new Date(thread.updatedAt * 1e3).toISOString()
35609
35614
  }))
35610
35615
  };
35611
- }).onRequest(methods4.agent.session.delete, async (context) => {
35612
- await this.#appServer.request(
35613
- "thread/archive",
35614
- { threadId: context.params.sessionId },
35615
- AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
35616
- );
35617
- return {};
35618
- }).onRequest(methods4.agent.session.setConfigOption, async (context) => {
35619
- this.#applySelection(context.params.configId, context.params.value);
35620
- return { configOptions: this.#configOptions() };
35621
- }).onRequest(methods4.agent.session.setMode, async (context) => {
35622
- this.#applySelection(MODE_SETTING_ID, context.params.modeId);
35623
- return {};
35624
- }).onRequest(methods4.agent.session.prompt, async (context) => {
35625
- return await this.#runTurn(promptInput(context.params.prompt), context.signal);
35626
- }).onRequest(STEERING_METHOD, steeringParams, async (context) => {
35627
- const turn = this.#turn;
35628
- if (turn === null || turn.turn.id.length === 0) {
35629
- return { outcome: "promptRequired" };
35630
- }
35631
- try {
35632
- const steered = turnSteerResponseSchema.parse(
35633
- await this.#appServer.request(
35634
- "turn/steer",
35635
- {
35636
- expectedTurnId: turn.turn.id,
35637
- input: promptInput(context.params.prompt),
35638
- threadId: this.#nativeSessionId
35639
- },
35640
- AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
35641
- )
35642
- );
35643
- return { outcome: steered.turnId === turn.turn.id ? "injected" : "startedNewTurn" };
35644
- } catch (error62) {
35645
- if (error62 instanceof CodexAppServerError) {
35646
- return { outcome: "promptRequired" };
35647
- }
35648
- throw error62;
35649
- }
35650
35616
  }).onRequest(methods4.agent.session.close, async () => {
35651
35617
  await this.#interruptTurn();
35652
35618
  }).onNotification(methods4.agent.session.cancel, async () => {
@@ -35716,6 +35682,56 @@ var CodexAcpAgent = class {
35716
35682
  options.push(modeSetting(this.#selection.mode));
35717
35683
  return options;
35718
35684
  };
35685
+ #selectRestoredThread = (thread) => {
35686
+ this.#nativeSessionId = thread.thread.id;
35687
+ this.#selection = {
35688
+ ...this.#selection,
35689
+ effort: thread.reasoningEffort ?? this.#selection.effort,
35690
+ model: thread.model ?? this.#selection.model,
35691
+ fastMode: thread.serviceTier === SERVICE_TIER_FAST
35692
+ };
35693
+ };
35694
+ #replayHistory = async (turns) => {
35695
+ for (const turn of turns ?? []) {
35696
+ for (const rawItem of turn.items) {
35697
+ const item = decodeThreadItem(rawItem);
35698
+ if (item === null) {
35699
+ continue;
35700
+ }
35701
+ if (item.type === "userMessage") {
35702
+ const text3 = item.content.flatMap((content3) => {
35703
+ if (typeof content3 !== "object" || content3 === null) {
35704
+ return [];
35705
+ }
35706
+ const type = Reflect.get(content3, "type");
35707
+ const text4 = Reflect.get(content3, "text");
35708
+ return type === "text" && typeof text4 === "string" ? [text4] : [];
35709
+ }).join("");
35710
+ if (text3.length > 0) {
35711
+ await this.#emit({
35712
+ content: { text: text3, type: "text" },
35713
+ messageId: item.id,
35714
+ sessionUpdate: "user_message_chunk"
35715
+ });
35716
+ }
35717
+ continue;
35718
+ }
35719
+ if (item.type === "agentMessage") {
35720
+ await this.#emit({
35721
+ _meta: agentMessageMeta(item.phase),
35722
+ content: { text: item.text, type: "text" },
35723
+ messageId: item.id,
35724
+ sessionUpdate: "agent_message_chunk"
35725
+ });
35726
+ continue;
35727
+ }
35728
+ const update = toolCallUpdate(item);
35729
+ if (update !== null) {
35730
+ await this.#emit({ ...update, sessionUpdate: "tool_call_update" });
35731
+ }
35732
+ }
35733
+ }
35734
+ };
35719
35735
  /**
35720
35736
  * Applies one `session/set_config_option`. Switching models re-resolves the effort the way Codex
35721
35737
  * does — the current effort when the new model supports it, otherwise the model's own default —
@@ -39625,7 +39641,7 @@ var responseSchema = external_exports.union([
39625
39641
  external_exports.object({ id: external_exports.number(), result: external_exports.unknown() }),
39626
39642
  external_exports.object({ method: external_exports.string() })
39627
39643
  ]);
39628
- var threadSchema2 = external_exports.object({
39644
+ var threadSchema = external_exports.object({
39629
39645
  thread: external_exports.object({
39630
39646
  id: nativeSessionIdSchema,
39631
39647
  cwd: external_exports.string().min(1).max(2048).refine((path2) => !path2.includes("\0"))
@@ -39929,7 +39945,7 @@ async function readCodexHistoryWithOptions(agent, cwd, nativeSessionId, signal,
39929
39945
  });
39930
39946
  break;
39931
39947
  case "metadata": {
39932
- const { thread } = threadSchema2.parse(message.result);
39948
+ const { thread } = threadSchema.parse(message.result);
39933
39949
  state = { kind: "turns", requestId: 3, thread };
39934
39950
  send2({
39935
39951
  id: state.requestId,