@moxt-ai/mobius 0.0.128 → 0.0.129

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
@@ -3381,7 +3381,7 @@ var program = new Command();
3381
3381
  // package.json
3382
3382
  var package_default = {
3383
3383
  name: "@moxt-ai/mobius",
3384
- version: "0.0.128",
3384
+ version: "0.0.129",
3385
3385
  description: "Mobius CLI for pairing and running local AI agent services.",
3386
3386
  type: "module",
3387
3387
  bin: {
@@ -31162,73 +31162,11 @@ async function replaceImageMarkers(text2, replace) {
31162
31162
  return `${rewritten}${text2.slice(cursor)}`;
31163
31163
  }
31164
31164
 
31165
- // src/acp/activity.ts
31165
+ // src/acp/activity-content.ts
31166
31166
  var TRUNCATION_MARKER = "\n\u2026 output truncated by Mobius";
31167
- var AcpActivityNarration = class {
31168
- activityId;
31169
- activityType;
31170
- sequence;
31171
- text;
31172
- constructor(activityId, activityType, sequence, text2) {
31173
- this.activityId = activityId;
31174
- this.activityType = activityType;
31175
- this.sequence = sequence;
31176
- this.text = text2;
31177
- }
31178
- };
31179
31167
  function isRecord7(value) {
31180
31168
  return typeof value === "object" && value !== null && !Array.isArray(value);
31181
31169
  }
31182
- var AcpActivity = class _AcpActivity {
31183
- activityId;
31184
- activityType;
31185
- input;
31186
- locations;
31187
- name;
31188
- output;
31189
- sequence;
31190
- status;
31191
- title;
31192
- toolKind;
31193
- content;
31194
- detail;
31195
- constructor(activityId, activityType, input2, locations, name, output2, sequence, status, title2, toolKind, content = [], detail = captureActivityDetail(content, input2, output2)) {
31196
- this.activityId = activityId;
31197
- this.activityType = activityType;
31198
- this.input = input2;
31199
- this.locations = locations;
31200
- this.name = name;
31201
- this.output = output2;
31202
- this.sequence = sequence;
31203
- this.status = status;
31204
- this.title = title2;
31205
- this.toolKind = toolKind;
31206
- this.content = content;
31207
- this.detail = detail;
31208
- }
31209
- complete = () => (this.activityType === "progress" || this.activityType === "reasoning") && (this.status === "pending" || this.status === "running") ? new _AcpActivity(
31210
- this.activityId,
31211
- this.activityType,
31212
- this.input,
31213
- this.locations,
31214
- this.name,
31215
- this.output,
31216
- this.sequence,
31217
- "completed",
31218
- this.title,
31219
- this.toolKind,
31220
- this.content,
31221
- this.detail
31222
- ) : this;
31223
- };
31224
- var ActivityIdentity = class {
31225
- id;
31226
- sequence;
31227
- constructor(id, sequence) {
31228
- this.id = id;
31229
- this.sequence = sequence;
31230
- }
31231
- };
31232
31170
  function truncate2(value, maximumLength) {
31233
31171
  if (value.length <= maximumLength) {
31234
31172
  return value;
@@ -31505,346 +31443,95 @@ function contentPhase(content) {
31505
31443
  function isProgressMessage(content) {
31506
31444
  return contentPhase(content) === "commentary";
31507
31445
  }
31508
- var AcpActivityTracker = class {
31509
- #activities = /* @__PURE__ */ new Map();
31510
- #identities = /* @__PURE__ */ new Map();
31511
- #narrations = /* @__PURE__ */ new Map();
31512
- #onActivity;
31513
- #onNarration;
31514
- #prepareContent;
31515
- #activeNarrativeKey = "";
31516
- #nextSequence = 0;
31517
- constructor(onActivity, onNarration, prepareContent = (content) => Promise.resolve(content)) {
31518
- this.#onActivity = onActivity;
31519
- this.#onNarration = onNarration;
31520
- this.#prepareContent = prepareContent;
31521
- }
31522
- recordNarrative = async (activityType, messageId, text2) => {
31523
- const key = `${activityType}:${messageId}`;
31524
- if (this.#activeNarrativeKey !== key) {
31525
- await this.finishNarrative();
31526
- }
31527
- const identity2 = this.#identity(key);
31528
- const previous = this.#narrations.get(key);
31529
- const previousOutput = previous?.output ?? "";
31530
- const remaining = Math.max(0, AGENT_ACTIVITY_DETAIL_LIMIT - previousOutput.length);
31531
- this.#narrations.set(key, {
31532
- activityId: identity2.id,
31533
- activityType,
31534
- output: `${previousOutput}${text2.slice(0, remaining)}`,
31535
- originalBytes: (previous?.originalBytes ?? 0) + new TextEncoder().encode(text2).byteLength,
31536
- sequence: identity2.sequence,
31537
- truncated: (previous?.truncated ?? false) || text2.length > remaining
31538
- });
31539
- if (previous === void 0) {
31540
- await this.#record(key, this.#narrativeSnapshot(identity2, activityType, "", "running"));
31446
+
31447
+ // src/acp/agent-connection.ts
31448
+ import { spawn as spawn4 } from "node:child_process";
31449
+ import { ndJsonStream as ndJsonStream2, RequestError as RequestError3 } from "@agentclientprotocol/sdk";
31450
+
31451
+ // src/acp/value-utils.ts
31452
+ function truncate3(value, maximumLength) {
31453
+ return value.length <= maximumLength ? value : `${value.slice(0, Math.max(0, maximumLength - 1))}\u2026`;
31454
+ }
31455
+ function isRecord8(value) {
31456
+ return typeof value === "object" && value !== null && !Array.isArray(value);
31457
+ }
31458
+ function readString2(value, fallback = "") {
31459
+ return typeof value === "string" ? value : fallback;
31460
+ }
31461
+
31462
+ // src/acp/agent-connection.ts
31463
+ function readableWebStream(input2) {
31464
+ let streamOpen = true;
31465
+ return new ReadableStream({
31466
+ start(controller) {
31467
+ input2.on("data", (chunk) => {
31468
+ if (!streamOpen) {
31469
+ return;
31470
+ }
31471
+ if (chunk instanceof Uint8Array) {
31472
+ controller.enqueue(new Uint8Array(chunk));
31473
+ return;
31474
+ }
31475
+ streamOpen = false;
31476
+ controller.error(new Error("ACP process produced a non-binary chunk"));
31477
+ });
31478
+ input2.once("end", () => {
31479
+ if (!streamOpen) {
31480
+ return;
31481
+ }
31482
+ streamOpen = false;
31483
+ controller.close();
31484
+ });
31485
+ input2.once("error", (error62) => {
31486
+ if (!streamOpen) {
31487
+ return;
31488
+ }
31489
+ streamOpen = false;
31490
+ controller.error(error62);
31491
+ });
31492
+ },
31493
+ cancel() {
31494
+ streamOpen = false;
31541
31495
  }
31542
- this.#activeNarrativeKey = key;
31543
- if (text2.length > 0) {
31544
- await this.#onNarration(new AcpActivityNarration(identity2.id, activityType, identity2.sequence, text2));
31496
+ });
31497
+ }
31498
+ function createWritableAcpStream(output2) {
31499
+ let outputFailure;
31500
+ const pendingWriteFailures = /* @__PURE__ */ new Set();
31501
+ const fail = (error62) => {
31502
+ outputFailure = error62;
31503
+ for (const reject of pendingWriteFailures) {
31504
+ reject(error62);
31545
31505
  }
31506
+ pendingWriteFailures.clear();
31546
31507
  };
31547
- #narrativeSnapshot = (identity2, activityType, output2, status) => new AcpActivity(
31548
- identity2.id,
31549
- activityType,
31550
- "",
31551
- [],
31552
- "",
31553
- truncate2(output2, AGENT_ACTIVITY_DETAIL_LIMIT),
31554
- identity2.sequence,
31555
- status,
31556
- activityType === "reasoning" ? "Reasoning" : "Progress update",
31557
- activityType === "reasoning" ? "think" : ""
31558
- );
31559
- recordPlan = async (plan) => {
31560
- await this.finishNarrative();
31561
- await this.#recordPlanEntries("plan:default", plan.entries);
31562
- };
31563
- recordPlanUpdate = async (update) => {
31564
- await this.finishNarrative();
31565
- const plan = update.plan;
31566
- const key = `plan:${plan.planId}`;
31567
- if (plan.type === "items") {
31568
- await this.#recordPlanEntries(key, plan.entries);
31569
- return;
31508
+ output2.on("error", fail);
31509
+ output2.once("close", () => {
31510
+ if (outputFailure === void 0) {
31511
+ fail(new Error("ACP process input closed"));
31570
31512
  }
31571
- const identity2 = this.#identity(key);
31572
- const output2 = plan.type === "markdown" ? plan.content : `Plan file: ${plan.uri}`;
31573
- await this.#record(
31574
- key,
31575
- new AcpActivity(
31576
- identity2.id,
31577
- "plan",
31578
- "",
31579
- [],
31580
- "",
31581
- truncate2(output2, AGENT_ACTIVITY_DETAIL_LIMIT),
31582
- identity2.sequence,
31583
- "running",
31584
- "Plan",
31585
- ""
31586
- )
31587
- );
31588
- };
31589
- removePlan = async (update) => {
31590
- await this.finishNarrative();
31591
- const key = `plan:${update.planId}`;
31592
- const previous = this.#activities.get(key);
31593
- if (previous !== void 0) {
31594
- await this.#record(
31595
- key,
31596
- new AcpActivity(
31597
- previous.activityId,
31598
- previous.activityType,
31599
- previous.input,
31600
- previous.locations,
31601
- previous.name,
31602
- previous.output,
31603
- previous.sequence,
31604
- "completed",
31605
- previous.title,
31606
- previous.toolKind,
31607
- previous.content,
31608
- previous.detail
31609
- )
31610
- );
31611
- }
31612
- };
31613
- recordToolCall = async (update) => {
31614
- await this.finishNarrative();
31615
- const key = `tool:${update.toolCallId}`;
31616
- const identity2 = this.#identity(key);
31617
- const output2 = update.rawOutput === void 0 ? readContentOutput(update.content) : formatUnknown(update.rawOutput);
31618
- const detailInput = update.rawInput === void 0 ? "" : formatUnknownDetail(update.rawInput);
31619
- const detailOutput = update.rawOutput === void 0 ? readContentOutputDetail(update.content) : formatUnknownDetail(update.rawOutput);
31620
- const detailContent = await normalizeToolContent(
31621
- toolContent(update.content, update.rawOutput),
31622
- this.#prepareContent
31623
- );
31624
- await this.#record(
31625
- key,
31626
- new AcpActivity(
31627
- identity2.id,
31628
- "tool",
31629
- update.rawInput === void 0 ? "" : formatUnknown(update.rawInput),
31630
- normalizeLocations(update.locations ?? []),
31631
- truncate2(update.name ?? "", 128),
31632
- output2,
31633
- identity2.sequence,
31634
- normalizeToolStatus(update.status ?? "pending", "pending"),
31635
- normalizeTitle(update.title, "Tool call"),
31636
- update.kind ?? "other",
31637
- detailContent.slice(0, 100).map(summarizeDisplayContent),
31638
- captureActivityDetail(detailContent, detailInput, detailOutput)
31639
- )
31640
- );
31641
- };
31642
- recordToolCallUpdate = async (update) => {
31643
- await this.finishNarrative();
31644
- const key = `tool:${update.toolCallId}`;
31645
- const previous = this.#activities.get(key);
31646
- const identity2 = this.#identity(key);
31647
- const previousDetail = recordedDetail(previous);
31648
- const output2 = update.rawOutput !== void 0 ? formatUnknown(update.rawOutput) : update.content !== void 0 && update.content !== null ? readContentOutput(update.content) : previous?.output ?? "";
31649
- const nextContent = toolContent(update.content, update.rawOutput);
31650
- const content = nextContent.length === 0 ? previous?.content ?? [] : await normalizeToolContent(nextContent, this.#prepareContent);
31651
- const detailInput = update.rawInput === void 0 ? previousDetail?.input ?? previous?.input ?? "" : formatUnknownDetail(update.rawInput);
31652
- const detailOutput = update.rawOutput !== void 0 ? formatUnknownDetail(update.rawOutput) : update.content !== void 0 && update.content !== null ? readContentOutputDetail(update.content) : previousDetail?.output ?? previous?.output ?? "";
31653
- const detailContent = nextContent.length === 0 ? previousDetail?.content ?? previous?.content ?? [] : content;
31654
- await this.#record(
31655
- key,
31656
- new AcpActivity(
31657
- identity2.id,
31658
- "tool",
31659
- update.rawInput === void 0 ? previous?.input ?? "" : formatUnknown(update.rawInput),
31660
- update.locations === void 0 || update.locations === null ? previous?.locations ?? [] : normalizeLocations(update.locations),
31661
- update.name === void 0 || update.name === null ? previous?.name ?? "" : truncate2(update.name, 128),
31662
- output2,
31663
- identity2.sequence,
31664
- update.status === void 0 || update.status === null ? previous?.status ?? "pending" : normalizeToolStatus(update.status, previous?.status ?? "pending"),
31665
- update.title === void 0 || update.title === null ? previous?.title ?? "Tool call" : normalizeTitle(update.title, "Tool call"),
31666
- update.kind === void 0 || update.kind === null ? previous?.toolKind ?? "other" : update.kind,
31667
- content.slice(0, 100).map(summarizeDisplayContent),
31668
- captureActivityDetail(detailContent, detailInput, detailOutput)
31669
- )
31670
- );
31671
- };
31672
- finishNarrative = async () => {
31673
- const key = this.#activeNarrativeKey;
31674
- if (key.length === 0) {
31675
- return;
31676
- }
31677
- this.#activeNarrativeKey = "";
31678
- await this.#completeNarrative(key);
31679
- };
31680
- finish = async () => {
31681
- await this.finishNarrative();
31682
- for (const key of this.#narrations.keys()) {
31683
- await this.#completeNarrative(key);
31684
- }
31685
- const entries = [...this.#activities.entries()].sort((left, right) => left[1].sequence - right[1].sequence);
31686
- for (const [key, activity2] of entries) {
31687
- const completed = activity2.complete();
31688
- if (completed !== activity2) {
31689
- await this.#record(key, completed);
31690
- }
31691
- }
31692
- };
31693
- // Materialize a streamed narration as one completed snapshot activity. The
31694
- // incremental events carried the text; this final event gives consumers the
31695
- // whole narration with its terminal status, as a single bounded item.
31696
- #completeNarrative = async (key) => {
31697
- const narration = this.#narrations.get(key);
31698
- if (narration === void 0) {
31699
- return;
31700
- }
31701
- this.#narrations.delete(key);
31702
- const previous = this.#activities.get(key);
31703
- const detail = narration.truncated ? {
31704
- capturedBytes: encodedByteLength({ content: [], input: "", output: narration.output }),
31705
- kind: "truncated",
31706
- originalBytes: narration.originalBytes
31707
- } : captureActivityDetail([], "", narration.output);
31708
- await this.#record(
31709
- key,
31710
- new AcpActivity(
31711
- narration.activityId,
31712
- narration.activityType,
31713
- "",
31714
- [],
31715
- "",
31716
- truncate2(narration.output, AGENT_ACTIVITY_DETAIL_LIMIT),
31717
- narration.sequence,
31718
- "completed",
31719
- narration.activityType === "reasoning" ? "Reasoning" : "Progress update",
31720
- narration.activityType === "reasoning" ? "think" : "",
31721
- previous?.content ?? [],
31722
- detail
31723
- )
31724
- );
31725
- };
31726
- #identity = (key) => {
31727
- const existing = this.#identities.get(key);
31728
- if (existing !== void 0) {
31729
- return existing;
31730
- }
31731
- const identity2 = new ActivityIdentity(`activity-${crypto.randomUUID()}`, this.#nextSequence);
31732
- this.#nextSequence += 1;
31733
- this.#identities.set(key, identity2);
31734
- return identity2;
31735
- };
31736
- #record = async (key, activity2) => {
31737
- this.#activities.set(key, activity2);
31738
- await this.#onActivity(activity2);
31739
- };
31740
- #recordPlanEntries = async (key, entries) => {
31741
- const identity2 = this.#identity(key);
31742
- await this.#record(
31743
- key,
31744
- new AcpActivity(
31745
- identity2.id,
31746
- "plan",
31747
- "",
31748
- [],
31749
- "",
31750
- formatPlanEntries(entries),
31751
- identity2.sequence,
31752
- planStatus(entries),
31753
- "Plan",
31754
- ""
31755
- )
31756
- );
31757
- };
31758
- };
31759
-
31760
- // src/acp/agent-connection.ts
31761
- import { spawn as spawn4 } from "node:child_process";
31762
- import { ndJsonStream as ndJsonStream2, RequestError as RequestError3 } from "@agentclientprotocol/sdk";
31763
-
31764
- // src/acp/value-utils.ts
31765
- function truncate3(value, maximumLength) {
31766
- return value.length <= maximumLength ? value : `${value.slice(0, Math.max(0, maximumLength - 1))}\u2026`;
31767
- }
31768
- function isRecord8(value) {
31769
- return typeof value === "object" && value !== null && !Array.isArray(value);
31770
- }
31771
- function readString2(value, fallback = "") {
31772
- return typeof value === "string" ? value : fallback;
31773
- }
31774
-
31775
- // src/acp/agent-connection.ts
31776
- function readableWebStream(input2) {
31777
- let streamOpen = true;
31778
- return new ReadableStream({
31779
- start(controller) {
31780
- input2.on("data", (chunk) => {
31781
- if (!streamOpen) {
31782
- return;
31783
- }
31784
- if (chunk instanceof Uint8Array) {
31785
- controller.enqueue(new Uint8Array(chunk));
31786
- return;
31787
- }
31788
- streamOpen = false;
31789
- controller.error(new Error("ACP process produced a non-binary chunk"));
31790
- });
31791
- input2.once("end", () => {
31792
- if (!streamOpen) {
31793
- return;
31794
- }
31795
- streamOpen = false;
31796
- controller.close();
31797
- });
31798
- input2.once("error", (error62) => {
31799
- if (!streamOpen) {
31800
- return;
31801
- }
31802
- streamOpen = false;
31803
- controller.error(error62);
31804
- });
31805
- },
31806
- cancel() {
31807
- streamOpen = false;
31808
- }
31809
- });
31810
- }
31811
- function createWritableAcpStream(output2) {
31812
- let outputFailure;
31813
- const pendingWriteFailures = /* @__PURE__ */ new Set();
31814
- const fail = (error62) => {
31815
- outputFailure = error62;
31816
- for (const reject of pendingWriteFailures) {
31817
- reject(error62);
31818
- }
31819
- pendingWriteFailures.clear();
31820
- };
31821
- output2.on("error", fail);
31822
- output2.once("close", () => {
31823
- if (outputFailure === void 0) {
31824
- fail(new Error("ACP process input closed"));
31825
- }
31826
- });
31827
- return new WritableStream({
31828
- write(chunk) {
31829
- if (outputFailure !== void 0) {
31830
- return Promise.reject(outputFailure);
31831
- }
31832
- return new Promise((resolve9, reject) => {
31833
- pendingWriteFailures.add(reject);
31834
- output2.write(chunk, (error62) => {
31835
- pendingWriteFailures.delete(reject);
31836
- if (error62) {
31837
- outputFailure = error62;
31838
- reject(error62);
31839
- return;
31840
- }
31841
- if (outputFailure !== void 0) {
31842
- reject(outputFailure);
31843
- return;
31844
- }
31845
- resolve9();
31846
- });
31847
- });
31513
+ });
31514
+ return new WritableStream({
31515
+ write(chunk) {
31516
+ if (outputFailure !== void 0) {
31517
+ return Promise.reject(outputFailure);
31518
+ }
31519
+ return new Promise((resolve9, reject) => {
31520
+ pendingWriteFailures.add(reject);
31521
+ output2.write(chunk, (error62) => {
31522
+ pendingWriteFailures.delete(reject);
31523
+ if (error62) {
31524
+ outputFailure = error62;
31525
+ reject(error62);
31526
+ return;
31527
+ }
31528
+ if (outputFailure !== void 0) {
31529
+ reject(outputFailure);
31530
+ return;
31531
+ }
31532
+ resolve9();
31533
+ });
31534
+ });
31848
31535
  }
31849
31536
  });
31850
31537
  }
@@ -32278,6 +31965,321 @@ var AcpAgentSettingsSnapshot = class {
32278
31965
  }
32279
31966
  };
32280
31967
 
31968
+ // src/acp/activity.ts
31969
+ var AcpActivityNarration = class {
31970
+ activityId;
31971
+ activityType;
31972
+ sequence;
31973
+ text;
31974
+ constructor(activityId, activityType, sequence, text2) {
31975
+ this.activityId = activityId;
31976
+ this.activityType = activityType;
31977
+ this.sequence = sequence;
31978
+ this.text = text2;
31979
+ }
31980
+ };
31981
+ var AcpActivity = class _AcpActivity {
31982
+ activityId;
31983
+ activityType;
31984
+ input;
31985
+ locations;
31986
+ name;
31987
+ output;
31988
+ sequence;
31989
+ status;
31990
+ title;
31991
+ toolKind;
31992
+ content;
31993
+ detail;
31994
+ constructor(activityId, activityType, input2, locations, name, output2, sequence, status, title2, toolKind, content = [], detail = captureActivityDetail(content, input2, output2)) {
31995
+ this.activityId = activityId;
31996
+ this.activityType = activityType;
31997
+ this.input = input2;
31998
+ this.locations = locations;
31999
+ this.name = name;
32000
+ this.output = output2;
32001
+ this.sequence = sequence;
32002
+ this.status = status;
32003
+ this.title = title2;
32004
+ this.toolKind = toolKind;
32005
+ this.content = content;
32006
+ this.detail = detail;
32007
+ }
32008
+ complete = () => (this.activityType === "progress" || this.activityType === "reasoning") && (this.status === "pending" || this.status === "running") ? new _AcpActivity(
32009
+ this.activityId,
32010
+ this.activityType,
32011
+ this.input,
32012
+ this.locations,
32013
+ this.name,
32014
+ this.output,
32015
+ this.sequence,
32016
+ "completed",
32017
+ this.title,
32018
+ this.toolKind,
32019
+ this.content,
32020
+ this.detail
32021
+ ) : this;
32022
+ };
32023
+ var ActivityIdentity = class {
32024
+ id;
32025
+ sequence;
32026
+ constructor(id, sequence) {
32027
+ this.id = id;
32028
+ this.sequence = sequence;
32029
+ }
32030
+ };
32031
+ var AcpActivityTracker = class {
32032
+ #activities = /* @__PURE__ */ new Map();
32033
+ #identities = /* @__PURE__ */ new Map();
32034
+ #narrations = /* @__PURE__ */ new Map();
32035
+ #onActivity;
32036
+ #onNarration;
32037
+ #prepareContent;
32038
+ #activeNarrativeKey = "";
32039
+ #nextSequence = 0;
32040
+ constructor(onActivity, onNarration, prepareContent = (content) => Promise.resolve(content)) {
32041
+ this.#onActivity = onActivity;
32042
+ this.#onNarration = onNarration;
32043
+ this.#prepareContent = prepareContent;
32044
+ }
32045
+ recordNarrative = async (activityType, messageId, text2) => {
32046
+ const key = `${activityType}:${messageId}`;
32047
+ if (this.#activeNarrativeKey !== key) {
32048
+ await this.finishNarrative();
32049
+ }
32050
+ const identity2 = this.#identity(key);
32051
+ const previous = this.#narrations.get(key);
32052
+ const previousOutput = previous?.output ?? "";
32053
+ const remaining = Math.max(0, AGENT_ACTIVITY_DETAIL_LIMIT - previousOutput.length);
32054
+ this.#narrations.set(key, {
32055
+ activityId: identity2.id,
32056
+ activityType,
32057
+ output: `${previousOutput}${text2.slice(0, remaining)}`,
32058
+ originalBytes: (previous?.originalBytes ?? 0) + new TextEncoder().encode(text2).byteLength,
32059
+ sequence: identity2.sequence,
32060
+ truncated: (previous?.truncated ?? false) || text2.length > remaining
32061
+ });
32062
+ if (previous === void 0) {
32063
+ await this.#record(key, this.#narrativeSnapshot(identity2, activityType, "", "running"));
32064
+ }
32065
+ this.#activeNarrativeKey = key;
32066
+ if (text2.length > 0) {
32067
+ await this.#onNarration(new AcpActivityNarration(identity2.id, activityType, identity2.sequence, text2));
32068
+ }
32069
+ };
32070
+ #narrativeSnapshot = (identity2, activityType, output2, status) => new AcpActivity(
32071
+ identity2.id,
32072
+ activityType,
32073
+ "",
32074
+ [],
32075
+ "",
32076
+ truncate2(output2, AGENT_ACTIVITY_DETAIL_LIMIT),
32077
+ identity2.sequence,
32078
+ status,
32079
+ activityType === "reasoning" ? "Reasoning" : "Progress update",
32080
+ activityType === "reasoning" ? "think" : ""
32081
+ );
32082
+ recordPlan = async (plan) => {
32083
+ await this.finishNarrative();
32084
+ await this.#recordPlanEntries("plan:default", plan.entries);
32085
+ };
32086
+ recordPlanUpdate = async (update) => {
32087
+ await this.finishNarrative();
32088
+ const plan = update.plan;
32089
+ const key = `plan:${plan.planId}`;
32090
+ if (plan.type === "items") {
32091
+ await this.#recordPlanEntries(key, plan.entries);
32092
+ return;
32093
+ }
32094
+ const identity2 = this.#identity(key);
32095
+ const output2 = plan.type === "markdown" ? plan.content : `Plan file: ${plan.uri}`;
32096
+ await this.#record(
32097
+ key,
32098
+ new AcpActivity(
32099
+ identity2.id,
32100
+ "plan",
32101
+ "",
32102
+ [],
32103
+ "",
32104
+ truncate2(output2, AGENT_ACTIVITY_DETAIL_LIMIT),
32105
+ identity2.sequence,
32106
+ "running",
32107
+ "Plan",
32108
+ ""
32109
+ )
32110
+ );
32111
+ };
32112
+ removePlan = async (update) => {
32113
+ await this.finishNarrative();
32114
+ const key = `plan:${update.planId}`;
32115
+ const previous = this.#activities.get(key);
32116
+ if (previous !== void 0) {
32117
+ await this.#record(
32118
+ key,
32119
+ new AcpActivity(
32120
+ previous.activityId,
32121
+ previous.activityType,
32122
+ previous.input,
32123
+ previous.locations,
32124
+ previous.name,
32125
+ previous.output,
32126
+ previous.sequence,
32127
+ "completed",
32128
+ previous.title,
32129
+ previous.toolKind,
32130
+ previous.content,
32131
+ previous.detail
32132
+ )
32133
+ );
32134
+ }
32135
+ };
32136
+ recordToolCall = async (update) => {
32137
+ await this.finishNarrative();
32138
+ const key = `tool:${update.toolCallId}`;
32139
+ const identity2 = this.#identity(key);
32140
+ const output2 = update.rawOutput === void 0 ? readContentOutput(update.content) : formatUnknown(update.rawOutput);
32141
+ const detailInput = update.rawInput === void 0 ? "" : formatUnknownDetail(update.rawInput);
32142
+ const detailOutput = update.rawOutput === void 0 ? readContentOutputDetail(update.content) : formatUnknownDetail(update.rawOutput);
32143
+ const detailContent = await normalizeToolContent(
32144
+ toolContent(update.content, update.rawOutput),
32145
+ this.#prepareContent
32146
+ );
32147
+ await this.#record(
32148
+ key,
32149
+ new AcpActivity(
32150
+ identity2.id,
32151
+ "tool",
32152
+ update.rawInput === void 0 ? "" : formatUnknown(update.rawInput),
32153
+ normalizeLocations(update.locations ?? []),
32154
+ truncate2(update.name ?? "", 128),
32155
+ output2,
32156
+ identity2.sequence,
32157
+ normalizeToolStatus(update.status ?? "pending", "pending"),
32158
+ normalizeTitle(update.title, "Tool call"),
32159
+ update.kind ?? "other",
32160
+ detailContent.slice(0, 100).map(summarizeDisplayContent),
32161
+ captureActivityDetail(detailContent, detailInput, detailOutput)
32162
+ )
32163
+ );
32164
+ };
32165
+ recordToolCallUpdate = async (update) => {
32166
+ await this.finishNarrative();
32167
+ const key = `tool:${update.toolCallId}`;
32168
+ const previous = this.#activities.get(key);
32169
+ const identity2 = this.#identity(key);
32170
+ const previousDetail = recordedDetail(previous);
32171
+ const output2 = update.rawOutput !== void 0 ? formatUnknown(update.rawOutput) : update.content !== void 0 && update.content !== null ? readContentOutput(update.content) : previous?.output ?? "";
32172
+ const nextContent = toolContent(update.content, update.rawOutput);
32173
+ const content = nextContent.length === 0 ? previous?.content ?? [] : await normalizeToolContent(nextContent, this.#prepareContent);
32174
+ const detailInput = update.rawInput === void 0 ? previousDetail?.input ?? previous?.input ?? "" : formatUnknownDetail(update.rawInput);
32175
+ const detailOutput = update.rawOutput !== void 0 ? formatUnknownDetail(update.rawOutput) : update.content !== void 0 && update.content !== null ? readContentOutputDetail(update.content) : previousDetail?.output ?? previous?.output ?? "";
32176
+ const detailContent = nextContent.length === 0 ? previousDetail?.content ?? previous?.content ?? [] : content;
32177
+ await this.#record(
32178
+ key,
32179
+ new AcpActivity(
32180
+ identity2.id,
32181
+ "tool",
32182
+ update.rawInput === void 0 ? previous?.input ?? "" : formatUnknown(update.rawInput),
32183
+ update.locations === void 0 || update.locations === null ? previous?.locations ?? [] : normalizeLocations(update.locations),
32184
+ update.name === void 0 || update.name === null ? previous?.name ?? "" : truncate2(update.name, 128),
32185
+ output2,
32186
+ identity2.sequence,
32187
+ update.status === void 0 || update.status === null ? previous?.status ?? "pending" : normalizeToolStatus(update.status, previous?.status ?? "pending"),
32188
+ update.title === void 0 || update.title === null ? previous?.title ?? "Tool call" : normalizeTitle(update.title, "Tool call"),
32189
+ update.kind === void 0 || update.kind === null ? previous?.toolKind ?? "other" : update.kind,
32190
+ content.slice(0, 100).map(summarizeDisplayContent),
32191
+ captureActivityDetail(detailContent, detailInput, detailOutput)
32192
+ )
32193
+ );
32194
+ };
32195
+ finishNarrative = async () => {
32196
+ const key = this.#activeNarrativeKey;
32197
+ if (key.length === 0) {
32198
+ return;
32199
+ }
32200
+ this.#activeNarrativeKey = "";
32201
+ await this.#completeNarrative(key);
32202
+ };
32203
+ finish = async () => {
32204
+ await this.finishNarrative();
32205
+ for (const key of this.#narrations.keys()) {
32206
+ await this.#completeNarrative(key);
32207
+ }
32208
+ const entries = [...this.#activities.entries()].sort((left, right) => left[1].sequence - right[1].sequence);
32209
+ for (const [key, activity2] of entries) {
32210
+ const completed = activity2.complete();
32211
+ if (completed !== activity2) {
32212
+ await this.#record(key, completed);
32213
+ }
32214
+ }
32215
+ };
32216
+ // Materialize a streamed narration as one completed snapshot activity. The
32217
+ // incremental events carried the text; this final event gives consumers the
32218
+ // whole narration with its terminal status, as a single bounded item.
32219
+ #completeNarrative = async (key) => {
32220
+ const narration = this.#narrations.get(key);
32221
+ if (narration === void 0) {
32222
+ return;
32223
+ }
32224
+ this.#narrations.delete(key);
32225
+ const previous = this.#activities.get(key);
32226
+ const detail = narration.truncated ? {
32227
+ capturedBytes: encodedByteLength({ content: [], input: "", output: narration.output }),
32228
+ kind: "truncated",
32229
+ originalBytes: narration.originalBytes
32230
+ } : captureActivityDetail([], "", narration.output);
32231
+ await this.#record(
32232
+ key,
32233
+ new AcpActivity(
32234
+ narration.activityId,
32235
+ narration.activityType,
32236
+ "",
32237
+ [],
32238
+ "",
32239
+ truncate2(narration.output, AGENT_ACTIVITY_DETAIL_LIMIT),
32240
+ narration.sequence,
32241
+ "completed",
32242
+ narration.activityType === "reasoning" ? "Reasoning" : "Progress update",
32243
+ narration.activityType === "reasoning" ? "think" : "",
32244
+ previous?.content ?? [],
32245
+ detail
32246
+ )
32247
+ );
32248
+ };
32249
+ #identity = (key) => {
32250
+ const existing = this.#identities.get(key);
32251
+ if (existing !== void 0) {
32252
+ return existing;
32253
+ }
32254
+ const identity2 = new ActivityIdentity(`activity-${crypto.randomUUID()}`, this.#nextSequence);
32255
+ this.#nextSequence += 1;
32256
+ this.#identities.set(key, identity2);
32257
+ return identity2;
32258
+ };
32259
+ #record = async (key, activity2) => {
32260
+ this.#activities.set(key, activity2);
32261
+ await this.#onActivity(activity2);
32262
+ };
32263
+ #recordPlanEntries = async (key, entries) => {
32264
+ const identity2 = this.#identity(key);
32265
+ await this.#record(
32266
+ key,
32267
+ new AcpActivity(
32268
+ identity2.id,
32269
+ "plan",
32270
+ "",
32271
+ [],
32272
+ "",
32273
+ formatPlanEntries(entries),
32274
+ identity2.sequence,
32275
+ planStatus(entries),
32276
+ "Plan",
32277
+ ""
32278
+ )
32279
+ );
32280
+ };
32281
+ };
32282
+
32281
32283
  // src/acp/session-history.ts
32282
32284
  var HISTORY_ACTIVITY_FIELD_LIMIT = 1e5;
32283
32285
  var HISTORY_ACTIVITY_LIMIT = 100;