@moxt-ai/mobius 0.0.353 → 0.0.354

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.353",
2089
+ version: "0.0.354",
2090
2090
  description: "Mobius CLI for pairing and running local AI agent services.",
2091
2091
  type: "module",
2092
2092
  bin: {
@@ -66262,14 +66262,16 @@ var init_environment_session_list = __esm({
66262
66262
  });
66263
66263
 
66264
66264
  // src/engine/acp/harness/claude/upstream/dist/environment-session-messages.js
66265
- function getEnvironmentSessionMessages(environment, sessionId, signal) {
66265
+ function getEnvironmentSessionMessages(environment, sessionId, cancellationSignal) {
66266
+ const signal = AbortSignal.any([cancellationSignal, AbortSignal.timeout(SESSION_MESSAGES_TIMEOUT_MILLISECONDS)]);
66266
66267
  return withEnvironment(environment, () => withDeadline(signal, SESSION_MESSAGES_TIMEOUT_MILLISECONDS, async () => {
66267
- const messages = await FZt(sessionId);
66268
66268
  const authenticationFailures = /* @__PURE__ */ new Set();
66269
+ const transcript = [];
66269
66270
  const nativeMetadata = /* @__PURE__ */ new Map();
66270
66271
  await GZt(sessionId, {
66271
66272
  append: async (_key, entries) => {
66272
66273
  signal.throwIfAborted();
66274
+ transcript.push(...entries);
66273
66275
  for (const entry of entries) {
66274
66276
  if (entry.type === "user" && typeof entry.uuid === "string") {
66275
66277
  nativeMetadata.set(entry.uuid, {
@@ -66285,16 +66287,151 @@ function getEnvironmentSessionMessages(environment, sessionId, signal) {
66285
66287
  load: async () => null
66286
66288
  }, { includeSubagents: false });
66287
66289
  signal.throwIfAborted();
66290
+ const messages = await readFullHistory(transcript, sessionId, signal) ?? await FZt(sessionId);
66288
66291
  return messages.filter((message) => !authenticationFailures.has(message.uuid)).map((message) => ({ ...message, ...nativeMetadata.get(message.uuid) }));
66289
66292
  }));
66290
66293
  }
66291
- var SESSION_MESSAGES_TIMEOUT_MILLISECONDS;
66294
+ async function readFullHistory(transcript, sessionId, signal) {
66295
+ const entries = /* @__PURE__ */ new Map();
66296
+ for (const [index2, raw] of transcript.entries()) {
66297
+ signal.throwIfAborted();
66298
+ if (typeof raw.uuid !== "string") {
66299
+ continue;
66300
+ }
66301
+ if (!["user", "assistant", "system", "progress", "attachment"].includes(raw.type)) {
66302
+ continue;
66303
+ }
66304
+ const parsed = chainEntrySchema.safeParse(raw);
66305
+ if (!parsed.success) {
66306
+ return null;
66307
+ }
66308
+ entries.set(parsed.data.uuid, { entry: parsed.data, index: index2 });
66309
+ }
66310
+ const validated = /* @__PURE__ */ new Set();
66311
+ for (const uuid3 of entries.keys()) {
66312
+ signal.throwIfAborted();
66313
+ const visiting = /* @__PURE__ */ new Set();
66314
+ let current = uuid3;
66315
+ while (current !== null && !validated.has(current)) {
66316
+ const node2 = entries.get(current);
66317
+ if (node2 === void 0 || visiting.has(current)) {
66318
+ return null;
66319
+ }
66320
+ visiting.add(current);
66321
+ const entry = node2.entry;
66322
+ current = entry.subtype === "compact_boundary" ? entry.logicalParentUuid ?? entry.parentUuid : entry.parentUuid;
66323
+ }
66324
+ for (const id of visiting) {
66325
+ validated.add(id);
66326
+ }
66327
+ }
66328
+ for (const { entry } of entries.values()) {
66329
+ if (entry.subtype !== "compact_boundary") {
66330
+ continue;
66331
+ }
66332
+ const preserved = entry.compactMetadata;
66333
+ const references = preserved?.preservedMessages !== void 0 ? [...preserved.preservedMessages.uuids, preserved.preservedMessages.anchorUuid] : preserved?.preservedSegment !== void 0 ? [
66334
+ preserved.preservedSegment.headUuid,
66335
+ preserved.preservedSegment.tailUuid,
66336
+ preserved.preservedSegment.anchorUuid
66337
+ ] : [];
66338
+ if (references.some((id) => !entries.has(id))) {
66339
+ return null;
66340
+ }
66341
+ }
66342
+ const project = async (source) => {
66343
+ signal.throwIfAborted();
66344
+ const messages = await FZt(sessionId, {
66345
+ includeSystemMessages: true,
66346
+ sessionStore: { append: async () => {
66347
+ }, load: async () => source }
66348
+ });
66349
+ signal.throwIfAborted();
66350
+ return messages;
66351
+ };
66352
+ const result = [];
66353
+ const seen = /* @__PURE__ */ new Set();
66354
+ const expanding = /* @__PURE__ */ new Set();
66355
+ const append = async (messages) => {
66356
+ let compactionId;
66357
+ for (const message of messages) {
66358
+ signal.throwIfAborted();
66359
+ const node2 = entries.get(message.uuid);
66360
+ if (node2 === void 0) {
66361
+ return false;
66362
+ }
66363
+ if (node2.entry.subtype === "compact_boundary") {
66364
+ compactionId = message.uuid;
66365
+ if (seen.has(message.uuid)) {
66366
+ continue;
66367
+ }
66368
+ if (expanding.has(message.uuid)) {
66369
+ return false;
66370
+ }
66371
+ expanding.add(message.uuid);
66372
+ const parent = node2.entry.logicalParentUuid;
66373
+ if (typeof parent === "string") {
66374
+ const ancestor = entries.get(parent);
66375
+ if (ancestor === void 0 || ancestor.index >= node2.index) {
66376
+ return false;
66377
+ }
66378
+ const anchor2 = `history-anchor-${message.uuid}`;
66379
+ if (entries.has(anchor2)) {
66380
+ return false;
66381
+ }
66382
+ const earlier = await project([
66383
+ ...transcript.slice(0, node2.index),
66384
+ {
66385
+ type: "user",
66386
+ uuid: anchor2,
66387
+ parentUuid: parent,
66388
+ sessionId,
66389
+ message: { role: "user", content: "" }
66390
+ }
66391
+ ]);
66392
+ if (!await append(earlier.filter((entry) => entry.uuid !== anchor2))) {
66393
+ return false;
66394
+ }
66395
+ }
66396
+ expanding.delete(message.uuid);
66397
+ seen.add(message.uuid);
66398
+ result.push({ ...message, nativeCompaction: { kind: "boundary", id: message.uuid } });
66399
+ } else if (!seen.has(message.uuid)) {
66400
+ seen.add(message.uuid);
66401
+ if (node2.entry.isCompactSummary === true) {
66402
+ if (compactionId === void 0) {
66403
+ return false;
66404
+ }
66405
+ result.push({ ...message, nativeCompaction: { kind: "summary", id: compactionId } });
66406
+ } else if (message.type !== "system") {
66407
+ result.push(message);
66408
+ }
66409
+ }
66410
+ }
66411
+ return true;
66412
+ };
66413
+ return await append(await project([...transcript])) ? result : null;
66414
+ }
66415
+ var SESSION_MESSAGES_TIMEOUT_MILLISECONDS, chainEntrySchema;
66292
66416
  var init_environment_session_messages = __esm({
66293
66417
  "src/engine/acp/harness/claude/upstream/dist/environment-session-messages.js"() {
66294
66418
  "use strict";
66295
66419
  init_sdk();
66420
+ init_zod();
66296
66421
  init_utils();
66297
66422
  SESSION_MESSAGES_TIMEOUT_MILLISECONDS = 3e4;
66423
+ chainEntrySchema = external_exports.object({
66424
+ type: external_exports.enum(["user", "assistant", "system", "progress", "attachment"]),
66425
+ uuid: external_exports.string(),
66426
+ parentUuid: external_exports.string().nullable(),
66427
+ logicalParentUuid: external_exports.string().nullable().optional(),
66428
+ subtype: external_exports.string().optional(),
66429
+ isCompactSummary: external_exports.boolean().optional(),
66430
+ compactMetadata: external_exports.object({
66431
+ preservedSegment: external_exports.object({ headUuid: external_exports.string(), tailUuid: external_exports.string(), anchorUuid: external_exports.string() }).optional(),
66432
+ preservedMessages: external_exports.object({ uuids: external_exports.array(external_exports.string()), anchorUuid: external_exports.string() }).optional()
66433
+ }).passthrough().optional()
66434
+ }).passthrough();
66298
66435
  }
66299
66436
  });
66300
66437
 
@@ -69215,9 +69352,16 @@ function stripMarkerTags(text2) {
69215
69352
  }
69216
69353
  return result + text2.slice(copiedUpTo);
69217
69354
  }
69218
- function stripLocalCommandMetadata(content) {
69355
+ function stripLocalCommandMetadata(content, options) {
69356
+ const strip = (text2) => {
69357
+ if (options?.preserveCompactionCommand === true && /<command-name>\/compact<\/command-name>/u.test(text2)) {
69358
+ const args = /<command-args>([\s\S]*?)<\/command-args>/u.exec(text2)?.[1]?.trim() ?? "";
69359
+ return stripMarkerTags(text2.replace(/<command-name>\/compact<\/command-name>/u, () => args.length > 0 ? `/compact ${args}` : "/compact")).trim();
69360
+ }
69361
+ return stripMarkerTags(text2);
69362
+ };
69219
69363
  if (typeof content === "string") {
69220
- const stripped = stripMarkerTags(content);
69364
+ const stripped = strip(content);
69221
69365
  return stripped.trim() === "" ? null : stripped;
69222
69366
  }
69223
69367
  if (!Array.isArray(content)) {
@@ -69226,7 +69370,7 @@ function stripLocalCommandMetadata(content) {
69226
69370
  const kept = [];
69227
69371
  for (const block of content) {
69228
69372
  if (block && typeof block === "object" && "type" in block && block.type === "text" && "text" in block && typeof block.text === "string") {
69229
- const stripped = stripMarkerTags(block.text);
69373
+ const stripped = strip(block.text);
69230
69374
  if (stripped.trim() === "") {
69231
69375
  continue;
69232
69376
  }
@@ -72851,6 +72995,35 @@ ${message.api_refusal_explanation}` : "";
72851
72995
  const forwardSubagentText = this.sessions[sessionId]?.forwardSubagentText ?? supportsSubagentTranscript(this.clientCapabilities);
72852
72996
  const seenTools = /* @__PURE__ */ new Set();
72853
72997
  for (const message of messages) {
72998
+ signal.throwIfAborted();
72999
+ if (message.nativeCompaction !== void 0) {
73000
+ const compaction = message.nativeCompaction;
73001
+ if (compaction.kind === "boundary") {
73002
+ await this.client.sessionUpdate({
73003
+ sessionId,
73004
+ update: {
73005
+ sessionUpdate: "compaction_update",
73006
+ compactionId: compaction.id,
73007
+ status: "completed"
73008
+ }
73009
+ });
73010
+ } else {
73011
+ const body = message.message;
73012
+ const content2 = typeof body === "object" && body !== null && "content" in body ? body.content : void 0;
73013
+ const text2 = typeof content2 === "string" ? content2 : Array.isArray(content2) ? content2.flatMap((block) => typeof block === "object" && block !== null && "type" in block && block.type === "text" && "text" in block && typeof block.text === "string" ? [block.text] : []).join("\n") : "";
73014
+ if (text2.length > 0) {
73015
+ await this.client.sessionUpdate({
73016
+ sessionId,
73017
+ update: {
73018
+ sessionUpdate: "compaction_summary_chunk",
73019
+ compactionId: compaction.id,
73020
+ content: { type: "text", text: text2 }
73021
+ }
73022
+ });
73023
+ }
73024
+ }
73025
+ continue;
73026
+ }
72854
73027
  if (isTaskNotificationOrigin(message.nativeOrigin)) {
72855
73028
  const body = message.message;
72856
73029
  const content2 = typeof body === "object" && body !== null && "content" in body ? body.content : void 0;
@@ -72872,7 +73045,7 @@ ${message.api_refusal_explanation}` : "";
72872
73045
  }
72873
73046
  let content = message.message.content;
72874
73047
  if (message.message.role === "user") {
72875
- content = stripLocalCommandMetadata(content);
73048
+ content = stripLocalCommandMetadata(content, { preserveCompactionCommand: true });
72876
73049
  if (content === null) {
72877
73050
  continue;
72878
73051
  }