@moxt-ai/mobius 0.0.331 → 0.0.333

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/cli.js CHANGED
@@ -2086,7 +2086,7 @@ var init_package = __esm({
2086
2086
  "package.json"() {
2087
2087
  package_default = {
2088
2088
  name: "@moxt-ai/mobius",
2089
- version: "0.0.331",
2089
+ version: "0.0.333",
2090
2090
  description: "Mobius CLI for pairing and running local AI agent services.",
2091
2091
  type: "module",
2092
2092
  bin: {
@@ -75300,7 +75300,7 @@ function decode4(value, schema) {
75300
75300
  function encode3(value, schema) {
75301
75301
  return JSON.stringify(decode4(value, schema));
75302
75302
  }
75303
- var MAX_EVENT_COUNT, MAX_COLLECTION_SIZE2, MAX_CONTENT_LENGTH2, SESSION_EVENT_KIND, SESSION_EVENT_BATCH_MAX_SIZE, boundedString2, shortString, externalContentKeySchema, annotationsSchema, contentFields, textContentSchema, imageContentSchema, audioContentSchema, externalImageContentSchema, externalAudioContentSchema, externalResourceContentSchema, resourceLinkSchema, textResourceSchema, blobResourceSchema, embeddedResourceSchema, contentBlockSchema, toolCallContentSchema, toolKindSchema, toolStatusSchema, backgroundTaskSchema, toolPatchFields, planEntrySchema, planContentSchema, commandSchema, configSelectOptionSchema, configSelectGroupSchema, configBaseFields, sessionConfigOptionSchema2, contentChunkFields, acpSessionUpdateSchema, lifecycleBase, promptExecutionContextSchema, lifecycleMetadataSchema, sessionEventPayloadSchema, positionSchema, sharedSessionEventFields, sessionLiveEventFields, sessionEventSchema, sessionLiveEventSchema, sessionEventBatchSchema, sessionLiveEventBatchSchema, sessionExportSchema, mobiusSessionExportSchema, sessionEventEnvelopeSchema, sessionEventLogPageSchema, sessionEventOmissionSchema, nativeEventPageRequestSchema, queuedPromptRequestEventLogSchema, nativeSessionEventsSchema, decodeSessionEvent, decodeSessionEventEnvelope, encodeSessionEventEnvelope, decodeAcpSessionUpdate;
75303
+ var MAX_EVENT_COUNT, MAX_COLLECTION_SIZE2, MAX_CONTENT_LENGTH2, SESSION_EVENT_KIND, SESSION_EVENT_BATCH_MAX_SIZE, boundedString2, shortString, externalContentKeySchema, annotationsSchema, contentFields, textContentSchema, imageContentSchema, audioContentSchema, externalImageContentSchema, externalAudioContentSchema, externalResourceContentSchema, resourceLinkSchema, textResourceSchema, blobResourceSchema, embeddedResourceSchema, contentBlockSchema, toolCallContentSchema, toolKindSchema, toolStatusSchema, backgroundTaskSchema, toolPatchFields, planEntrySchema, planContentSchema, commandSchema, configSelectOptionSchema, configSelectGroupSchema, configBaseFields, sessionConfigOptionSchema2, contentChunkFields, acpSessionUpdateSchema, lifecycleBase, promptExecutionContextSchema, lifecycleMetadataSchema, sessionEventPayloadSchema, positionSchema, sharedSessionEventFields, sessionLiveEventFields, sessionEventSchema, sessionLiveEventSchema, wireLifecyclePayloadSchema, wireEventFields, sessionWireEventSchema, sessionWireEnvelopeSchema, sessionEventBatchSchema, sessionLiveEventBatchSchema, sessionExportSchema, mobiusSessionExportSchema, sessionEventEnvelopeSchema, sessionEventLogPageSchema, sessionEventOmissionSchema, nativeEventPageRequestSchema, queuedPromptRequestEventLogSchema, nativeSessionEventsSchema, decodeSessionEvent, decodeSessionEventEnvelope, encodeSessionEventEnvelope, decodeAcpSessionUpdate;
75304
75304
  var init_event_log = __esm({
75305
75305
  "../mobius-sdk/src/protocol/session/observability/event-log.ts"() {
75306
75306
  "use strict";
@@ -75619,6 +75619,37 @@ var init_event_log = __esm({
75619
75619
  type: external_exports.literal("lifecycle-metadata")
75620
75620
  }).readonly()
75621
75621
  ]);
75622
+ wireLifecyclePayloadSchema = external_exports.object({
75623
+ kind: identifierStringSchema,
75624
+ commandId: identifierStringSchema.optional(),
75625
+ context: promptExecutionContextSchema.unwrap().passthrough().readonly().optional(),
75626
+ event: external_exports.object({ interactionId: identifierStringSchema.optional() }).passthrough().readonly().optional()
75627
+ }).passthrough().readonly();
75628
+ wireEventFields = {
75629
+ ...sessionLiveEventFields,
75630
+ mobiusMetadata: external_exports.object({ omitted: external_exports.literal(true).optional() }).passthrough().readonly().optional()
75631
+ };
75632
+ sessionWireEventSchema = external_exports.union([
75633
+ external_exports.object({
75634
+ ...wireEventFields,
75635
+ type: external_exports.literal("acp"),
75636
+ payload: external_exports.object({ sessionUpdate: identifierStringSchema }).passthrough().readonly()
75637
+ }).passthrough().readonly(),
75638
+ external_exports.object({
75639
+ ...wireEventFields,
75640
+ type: external_exports.literal("lifecycle-metadata"),
75641
+ payload: wireLifecyclePayloadSchema
75642
+ }).passthrough().readonly(),
75643
+ external_exports.object({
75644
+ ...wireEventFields,
75645
+ type: identifierStringSchema.refine((type) => type !== "acp" && type !== "lifecycle-metadata"),
75646
+ payload: external_exports.record(external_exports.string(), external_exports.unknown()).readonly()
75647
+ }).passthrough().readonly()
75648
+ ]);
75649
+ sessionWireEnvelopeSchema = external_exports.object({
75650
+ kind: external_exports.literal(SESSION_EVENT_KIND),
75651
+ events: external_exports.array(sessionWireEventSchema).min(1).max(SESSION_EVENT_BATCH_MAX_SIZE).readonly()
75652
+ }).readonly();
75622
75653
  sessionEventBatchSchema = external_exports.array(sessionEventSchema).min(1).max(SESSION_EVENT_BATCH_MAX_SIZE).readonly();
75623
75654
  sessionLiveEventBatchSchema = external_exports.array(sessionLiveEventSchema).min(1).max(SESSION_EVENT_BATCH_MAX_SIZE).readonly();
75624
75655
  sessionExportSchema = external_exports.object({
@@ -75832,7 +75863,7 @@ var init_recorded_lifecycle_status = __esm({
75832
75863
  });
75833
75864
 
75834
75865
  // ../mobius-sdk/src/protocol/session/recording/recording.ts
75835
- var sessionRecordingWriteSchema, sessionRecordingHistorySchema, sessionRecordingStatusSchema, recordingCursorSchema, sessionRecordingHistoryPageSchema, sessionRecordingSummaryFields, sessionRecordingSummaryV2Schema, sessionRecordingDirectoryV2Schema, sessionRecordingSummarySchema, sessionRecordingDirectorySchema;
75866
+ var sessionRecordingWriteSchema, sessionRecordingWireWriteSchema, sessionRecordingHistorySchema, sessionRecordingStatusSchema, recordingCursorSchema, sessionRecordingHistoryPageSchema, sessionRecordingSummaryFields, sessionRecordingSummaryV2Schema, sessionRecordingDirectoryV2Schema, sessionRecordingSummarySchema, sessionRecordingDirectorySchema;
75836
75867
  var init_recording = __esm({
75837
75868
  "../mobius-sdk/src/protocol/session/recording/recording.ts"() {
75838
75869
  "use strict";
@@ -75845,6 +75876,11 @@ var init_recording = __esm({
75845
75876
  projectId: identifierStringSchema,
75846
75877
  runtimeId: identifierStringSchema
75847
75878
  }).readonly();
75879
+ sessionRecordingWireWriteSchema = external_exports.object({
75880
+ envelope: sessionWireEnvelopeSchema,
75881
+ projectId: identifierStringSchema,
75882
+ runtimeId: identifierStringSchema
75883
+ }).readonly();
75848
75884
  sessionRecordingHistorySchema = external_exports.object({
75849
75885
  events: external_exports.array(sessionLiveEventSchema).readonly(),
75850
75886
  sessionId: identifierStringSchema
@@ -93687,6 +93723,7 @@ var init_execution_receipt = __esm({
93687
93723
  sessionId: text("session_id").notNull(),
93688
93724
  commandHash: text("command_hash").notNull(),
93689
93725
  attemptId: text("attempt_id").notNull(),
93726
+ // Compatibility projection for older Runtimes; started and outcome own the facts.
93690
93727
  state: text("state").notNull(),
93691
93728
  started: integer2("started", { mode: "boolean" }).notNull(),
93692
93729
  outcome: text("outcome"),
@@ -93764,29 +93801,30 @@ var init_acp_session_table = __esm({
93764
93801
  });
93765
93802
 
93766
93803
  // src/storage/session/execution-receipt-table.ts
93767
- var receiptFields, receiptSchema, identitySchema, ExecutionReceiptTable;
93804
+ function legacyState(receipt) {
93805
+ if (receipt.outcome === null) {
93806
+ return receipt.started ? "running" : "dispatching";
93807
+ }
93808
+ const event = sessionEventPayloadSchema.parse(JSON.parse(receipt.outcome));
93809
+ return event.type === "lifecycle-metadata" && event.payload.kind === "prompt.completed" ? event.payload.stopReason === "cancelled" ? "cancelled" : "succeeded" : "failed";
93810
+ }
93811
+ var receiptSchema, identitySchema, ExecutionReceiptTable;
93768
93812
  var init_execution_receipt_table = __esm({
93769
93813
  "src/storage/session/execution-receipt-table.ts"() {
93770
93814
  "use strict";
93815
+ init_protocol();
93771
93816
  init_drizzle_orm();
93772
93817
  init_zod();
93773
93818
  init_acp_session_store();
93774
- receiptFields = external_exports.object({
93819
+ receiptSchema = external_exports.object({
93775
93820
  commandId: external_exports.string(),
93776
93821
  sessionId: external_exports.string(),
93777
93822
  commandHash: external_exports.string(),
93778
93823
  attemptId: external_exports.string(),
93779
- updatedAt: external_exports.string()
93780
- });
93781
- receiptSchema = external_exports.discriminatedUnion("state", [
93782
- receiptFields.extend({ state: external_exports.literal("dispatching"), started: external_exports.literal(false), outcome: external_exports.null() }),
93783
- receiptFields.extend({ state: external_exports.literal("running"), started: external_exports.literal(true), outcome: external_exports.string().nullable() }),
93784
- receiptFields.extend({
93785
- state: external_exports.enum(["succeeded", "failed", "cancelled"]),
93786
- started: external_exports.boolean(),
93787
- outcome: external_exports.string().nullable()
93788
- })
93789
- ]).readonly();
93824
+ updatedAt: external_exports.string(),
93825
+ started: external_exports.boolean(),
93826
+ outcome: external_exports.string().nullable()
93827
+ }).readonly();
93790
93828
  identitySchema = external_exports.object({ sessionId: external_exports.string(), commandHash: external_exports.string() }).readonly();
93791
93829
  ExecutionReceiptTable = class {
93792
93830
  #database;
@@ -93800,32 +93838,27 @@ var init_execution_receipt_table = __esm({
93800
93838
  list = () => receiptSchema.array().parse(
93801
93839
  this.#database.orm.select().from(executionReceipt).orderBy(asc(executionReceipt.updatedAt), asc(executionReceipt.commandId)).all()
93802
93840
  );
93803
- save = (receipt) => {
93804
- this.#database.transaction(() => {
93805
- this.#database.orm.insert(executionReceipt).values(receipt).onConflictDoUpdate({ target: executionReceipt.commandId, set: receipt }).run();
93806
- if (receipt.state === "dispatching" || receipt.state === "running") {
93807
- return;
93808
- }
93809
- const retained = this.#database.orm.select({ commandId: executionReceipt.commandId }).from(executionReceipt).where(
93841
+ save = (receipt, terminalLimit) => this.#database.transaction(() => {
93842
+ const row = { ...receipt, state: legacyState(receipt) };
93843
+ this.#database.orm.insert(executionReceipt).values(row).onConflictDoUpdate({ target: executionReceipt.commandId, set: row }).run();
93844
+ if (receipt.outcome === null) {
93845
+ return [];
93846
+ }
93847
+ const retained = this.#database.orm.select({ commandId: executionReceipt.commandId }).from(executionReceipt).where(and(eq2(executionReceipt.sessionId, receipt.sessionId), isNotNull(executionReceipt.outcome))).orderBy(desc(executionReceipt.updatedAt), desc(executionReceipt.commandId)).limit(terminalLimit).all();
93848
+ if (retained.length === terminalLimit) {
93849
+ return this.#remove(
93810
93850
  and(
93811
93851
  eq2(executionReceipt.sessionId, receipt.sessionId),
93812
- inArray(executionReceipt.state, ["succeeded", "failed", "cancelled"])
93813
- )
93814
- ).orderBy(desc(executionReceipt.updatedAt), desc(executionReceipt.commandId)).limit(1024).all();
93815
- if (retained.length === 1024) {
93816
- this.#remove(
93817
- and(
93818
- eq2(executionReceipt.sessionId, receipt.sessionId),
93819
- inArray(executionReceipt.state, ["succeeded", "failed", "cancelled"]),
93820
- notInArray(
93821
- executionReceipt.commandId,
93822
- retained.map((row) => row.commandId)
93823
- )
93852
+ isNotNull(executionReceipt.outcome),
93853
+ notInArray(
93854
+ executionReceipt.commandId,
93855
+ retained.map((row2) => row2.commandId)
93824
93856
  )
93825
- );
93826
- }
93827
- });
93828
- };
93857
+ )
93858
+ );
93859
+ }
93860
+ return [];
93861
+ });
93829
93862
  remove = (commandId) => {
93830
93863
  this.#database.transaction(() => this.#remove(eq2(executionReceipt.commandId, commandId)));
93831
93864
  };
@@ -93840,7 +93873,7 @@ var init_execution_receipt_table = __esm({
93840
93873
  commandHash: executionReceipt.commandHash
93841
93874
  }).from(executionReceipt).where(and(condition, eq2(executionReceipt.started, true)))
93842
93875
  ).onConflictDoNothing().run();
93843
- this.#database.orm.delete(executionReceipt).where(condition).run();
93876
+ return this.#database.orm.delete(executionReceipt).where(condition).returning({ commandId: executionReceipt.commandId }).all().map((row) => row.commandId);
93844
93877
  };
93845
93878
  };
93846
93879
  }
@@ -97069,7 +97102,6 @@ async function settleAbandonedTurn(projection, operations, cancellation) {
97069
97102
  "agent_execution_abandoned",
97070
97103
  "The local Agent execution was abandoned before it completed"
97071
97104
  );
97072
- operations.transitionExecution(cancellation.commandId, "failed");
97073
97105
  projection.publishTerminal(cancellation.sessionId, cancellation.commandId);
97074
97106
  }
97075
97107
  var PromptLifecycle;
@@ -97216,9 +97248,6 @@ var init_prompt_lifecycle = __esm({
97216
97248
 
97217
97249
  // src/session/turn/execution-receipts.ts
97218
97250
  import { createHash as createHash7, randomUUID as randomUUID16 } from "node:crypto";
97219
- function isTerminal(state) {
97220
- return state === "succeeded" || state === "failed" || state === "cancelled";
97221
- }
97222
97251
  var MAX_TERMINAL_RECEIPTS, ExecutionReceipts;
97223
97252
  var init_execution_receipts = __esm({
97224
97253
  "src/session/turn/execution-receipts.ts"() {
@@ -97229,7 +97258,6 @@ var init_execution_receipts = __esm({
97229
97258
  ExecutionReceipts = class {
97230
97259
  #executions = /* @__PURE__ */ new Map();
97231
97260
  #recoveredCommands = /* @__PURE__ */ new Set();
97232
- #terminalCountBySession = /* @__PURE__ */ new Map();
97233
97261
  #table;
97234
97262
  #closing = false;
97235
97263
  #activeCount = 0;
@@ -97240,36 +97268,22 @@ var init_execution_receipts = __esm({
97240
97268
  for (const row of table.list()) {
97241
97269
  this.#executions.set(row.commandId, row);
97242
97270
  this.#recoveredCommands.add(row.commandId);
97243
- if (!isTerminal(row.state)) {
97271
+ if (row.outcome === null) {
97244
97272
  this.#activeCount += 1;
97245
97273
  }
97246
- if (isTerminal(row.state)) {
97247
- this.#terminalCountBySession.set(
97248
- row.sessionId,
97249
- (this.#terminalCountBySession.get(row.sessionId) ?? 0) + 1
97250
- );
97251
- }
97252
97274
  }
97253
97275
  }
97254
97276
  #save = (commandId, receipt) => {
97255
- if (!this.#closing) {
97256
- this.#table.save({ ...receipt, commandId, updatedAt: (/* @__PURE__ */ new Date()).toISOString() });
97257
- }
97277
+ const evicted = this.#closing ? [] : this.#table.save({ ...receipt, commandId, updatedAt: (/* @__PURE__ */ new Date()).toISOString() }, MAX_TERMINAL_RECEIPTS);
97258
97278
  const previous = this.#executions.get(commandId);
97259
- const wasActive = previous !== void 0 && !isTerminal(previous.state);
97260
- if (isTerminal(receipt.state)) {
97261
- this.#executions.delete(commandId);
97262
- }
97279
+ const wasActive = previous?.outcome === null;
97263
97280
  this.#executions.set(commandId, receipt);
97264
- this.#activeCount += Number(!isTerminal(receipt.state)) - Number(wasActive);
97265
- this.#onCount(this.#activeCount);
97266
- if (isTerminal(receipt.state) && (previous === void 0 || !isTerminal(previous.state))) {
97267
- this.#terminalCountBySession.set(
97268
- receipt.sessionId,
97269
- (this.#terminalCountBySession.get(receipt.sessionId) ?? 0) + 1
97270
- );
97271
- this.pruneTerminalReceipts(receipt.sessionId);
97281
+ for (const evictedCommandId of evicted) {
97282
+ this.#executions.delete(evictedCommandId);
97283
+ this.#recoveredCommands.delete(evictedCommandId);
97272
97284
  }
97285
+ this.#activeCount += Number(receipt.outcome === null) - Number(wasActive);
97286
+ this.#onCount(this.#activeCount);
97273
97287
  };
97274
97288
  beginShutdown = () => {
97275
97289
  this.#closing = true;
@@ -97282,7 +97296,7 @@ var init_execution_receipts = __esm({
97282
97296
  recordCancellationBeforeAdmission = (commandId, sessionId) => {
97283
97297
  const existing = this.#executions.get(commandId);
97284
97298
  if (existing !== void 0) {
97285
- return existing.sessionId === sessionId && isTerminal(existing.state) ? this.outcome(commandId) : void 0;
97299
+ return existing.sessionId === sessionId ? this.outcome(commandId) : void 0;
97286
97300
  }
97287
97301
  const outcome = {
97288
97302
  type: "lifecycle-metadata",
@@ -97299,7 +97313,6 @@ var init_execution_receipts = __esm({
97299
97313
  attemptId: randomUUID16(),
97300
97314
  commandHash,
97301
97315
  sessionId,
97302
- state: "cancelled",
97303
97316
  started: false,
97304
97317
  outcome: JSON.stringify({ ...outcome, recordedAt: (/* @__PURE__ */ new Date()).toISOString() })
97305
97318
  });
@@ -97320,7 +97333,6 @@ var init_execution_receipts = __esm({
97320
97333
  const sanitized = payload.kind === "prompt.completed" ? payload : { ...payload, message: "The local Agent could not complete the request" };
97321
97334
  this.#save(payload.commandId, {
97322
97335
  ...receipt,
97323
- state: payload.kind === "prompt.completed" ? payload.stopReason === "cancelled" ? "cancelled" : "succeeded" : "failed",
97324
97336
  outcome: JSON.stringify({ type: "lifecycle-metadata", payload: sanitized, recordedAt: event.recordedAt })
97325
97337
  });
97326
97338
  };
@@ -97344,9 +97356,8 @@ var init_execution_receipts = __esm({
97344
97356
  } : sessionEventPayloadSchema.parse(JSON.parse(receipt.outcome));
97345
97357
  const recordedAt = receipt.outcome === null ? (/* @__PURE__ */ new Date()).toISOString() : external_exports.object({ recordedAt: external_exports.string() }).parse(JSON.parse(receipt.outcome)).recordedAt;
97346
97358
  recovered.push({ sessionId: receipt.sessionId, event, recordedAt });
97347
- if (!isTerminal(receipt.state)) {
97348
- const state = event.type === "lifecycle-metadata" && event.payload.kind === "prompt.completed" ? event.payload.stopReason === "cancelled" ? "cancelled" : "succeeded" : "failed";
97349
- this.#save(commandId, { ...receipt, state, outcome: JSON.stringify({ ...event, recordedAt }) });
97359
+ if (receipt.outcome === null) {
97360
+ this.#save(commandId, { ...receipt, outcome: JSON.stringify({ ...event, recordedAt }) });
97350
97361
  }
97351
97362
  }
97352
97363
  return recovered;
@@ -97359,10 +97370,6 @@ var init_execution_receipts = __esm({
97359
97370
  this.#table.remove(commandId);
97360
97371
  this.#executions.delete(commandId);
97361
97372
  this.#recoveredCommands.delete(commandId);
97362
- this.#terminalCountBySession.set(
97363
- sessionId,
97364
- Math.max(0, (this.#terminalCountBySession.get(sessionId) ?? 1) - 1)
97365
- );
97366
97373
  existing = void 0;
97367
97374
  }
97368
97375
  if (existing !== void 0) {
@@ -97373,7 +97380,6 @@ var init_execution_receipts = __esm({
97373
97380
  attemptId: existing.attemptId,
97374
97381
  commandId,
97375
97382
  kind: "duplicate",
97376
- state: existing.state,
97377
97383
  outcome: this.#recoveredCommands.has(commandId) ? this.outcome(commandId) : void 0
97378
97384
  };
97379
97385
  }
@@ -97386,66 +97392,37 @@ var init_execution_receipts = __esm({
97386
97392
  attemptId,
97387
97393
  commandHash,
97388
97394
  sessionId,
97389
- state: "dispatching",
97390
97395
  started: false,
97391
97396
  outcome: null
97392
97397
  });
97393
- return { attemptId, commandId, kind: "accepted", state: "dispatching" };
97398
+ return { attemptId, commandId, kind: "accepted" };
97394
97399
  };
97395
- transitionExecution = (commandId, state) => {
97400
+ markExecutionStarted = (commandId) => {
97396
97401
  const current = this.#executions.get(commandId);
97397
97402
  if (current === void 0) {
97398
97403
  throw new Error("The runtime execution receipt does not exist");
97399
97404
  }
97400
- if (current.state === state) {
97401
- return;
97402
- }
97403
- const allowed = current.state === "dispatching" && (state === "running" || state === "failed" || state === "cancelled") || current.state === "running" && isTerminal(state);
97404
- if (!allowed) {
97405
+ if (current.outcome !== null) {
97405
97406
  throw new Error("The runtime execution transition is invalid");
97406
97407
  }
97407
- if (state === "running") {
97408
- this.#save(commandId, { ...current, state, started: true });
97409
- } else if (isTerminal(state)) {
97410
- this.#save(commandId, { ...current, state });
97408
+ if (!current.started) {
97409
+ this.#save(commandId, { ...current, started: true });
97411
97410
  }
97412
97411
  };
97413
97412
  /** Only commands without a terminal result can still be cancelled. */
97414
97413
  findUnsettledAttemptId = (commandId, sessionId) => {
97415
97414
  const receipt = this.#executions.get(commandId);
97416
- return receipt?.sessionId === sessionId && !isTerminal(receipt.state) ? receipt.attemptId : null;
97415
+ return receipt?.sessionId === sessionId && receipt.outcome === null ? receipt.attemptId : null;
97417
97416
  };
97418
97417
  isTerminalExecution = (commandId, sessionId) => {
97419
97418
  const receipt = this.#executions.get(commandId);
97420
- return receipt?.sessionId === sessionId && isTerminal(receipt.state);
97419
+ return receipt?.sessionId === sessionId && receipt.outcome !== null;
97421
97420
  };
97422
97421
  close = () => {
97423
97422
  this.#executions.clear();
97424
97423
  this.#recoveredCommands.clear();
97425
- this.#terminalCountBySession.clear();
97426
97424
  this.#activeCount = 0;
97427
97425
  };
97428
- pruneTerminalReceipts = (sessionId) => {
97429
- if ((this.#terminalCountBySession.get(sessionId) ?? 0) <= MAX_TERMINAL_RECEIPTS) {
97430
- return;
97431
- }
97432
- for (const [commandId, receipt] of this.#executions) {
97433
- if (receipt.sessionId === sessionId && isTerminal(receipt.state)) {
97434
- this.#table.remove(commandId);
97435
- this.#executions.delete(commandId);
97436
- this.#recoveredCommands.delete(commandId);
97437
- const remaining = (this.#terminalCountBySession.get(sessionId) ?? 1) - 1;
97438
- if (remaining > 0) {
97439
- this.#terminalCountBySession.set(sessionId, remaining);
97440
- } else {
97441
- this.#terminalCountBySession.delete(sessionId);
97442
- }
97443
- if ((this.#terminalCountBySession.get(sessionId) ?? 0) <= MAX_TERMINAL_RECEIPTS) {
97444
- return;
97445
- }
97446
- }
97447
- }
97448
- };
97449
97426
  };
97450
97427
  }
97451
97428
  });
@@ -100736,7 +100713,7 @@ async function executePrompt({
100736
100713
  );
100737
100714
  prepared = await sessions.prepareExecutionSession(preparation);
100738
100715
  }
100739
- operations.transitionExecution(command.commandId, "running");
100716
+ operations.markExecutionStarted(command.commandId);
100740
100717
  if (availability.disposition === SessionPromptDisposition.Steer) {
100741
100718
  if (!recordSteeringPrompt()) {
100742
100719
  throw new AcpExecutionError(
@@ -100792,18 +100769,15 @@ async function executePrompt({
100792
100769
  stopReason = result.stopReason;
100793
100770
  }
100794
100771
  await eventProjection.completed(command.sessionId, command.commandId, stopReason);
100795
- operations.transitionExecution(command.commandId, stopReason === "cancelled" ? "cancelled" : "succeeded");
100796
100772
  } catch (error62) {
100797
100773
  if (signal.aborted && cancellationRequested()) {
100798
100774
  await eventProjection.completed(command.sessionId, command.commandId, "cancelled");
100799
- operations.transitionExecution(command.commandId, "cancelled");
100800
100775
  return;
100801
100776
  }
100802
100777
  const code = operationErrorCode(error62);
100803
100778
  const failureCode = code === "session_operation_failed" ? "agent_execution_failed" : code;
100804
100779
  const failureMessage = code === "session_operation_failed" ? "The local agent could not complete the request" : operationErrorMessage(error62);
100805
100780
  await eventProjection.failed(command.sessionId, command.commandId, failureCode, failureMessage);
100806
- operations.transitionExecution(command.commandId, "failed");
100807
100781
  reportFailure("session_prompt_failed", command.commandId, {
100808
100782
  agentId: command.agentId,
100809
100783
  code: failureCode,