@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/acp/activity-content.d.ts +29 -0
- package/dist/acp/activity-content.d.ts.map +1 -0
- package/dist/acp/activity-content.js +301 -0
- package/dist/acp/activity-content.js.map +1 -0
- package/dist/acp/activity.d.ts +3 -9
- package/dist/acp/activity.d.ts.map +1 -1
- package/dist/acp/activity.js +2 -300
- package/dist/acp/activity.js.map +1 -1
- package/dist/acp/agent-session.js +1 -1
- package/dist/acp/agent-session.js.map +1 -1
- package/dist/acp/session-history.d.ts.map +1 -1
- package/dist/acp/session-history.js +2 -1
- package/dist/acp/session-history.js.map +1 -1
- package/dist/cli.js +402 -400
- package/dist/cli.js.map +4 -4
- package/dist/daemon-turn-registry.d.ts +13 -13
- package/dist/index.js +799 -797
- package/dist/index.js.map +4 -4
- package/dist/runtime.js +401 -399
- package/dist/runtime.js.map +4 -4
- package/package.json +1 -1
package/dist/runtime.js
CHANGED
|
@@ -26843,73 +26843,11 @@ async function replaceImageMarkers(text2, replace) {
|
|
|
26843
26843
|
return `${rewritten}${text2.slice(cursor)}`;
|
|
26844
26844
|
}
|
|
26845
26845
|
|
|
26846
|
-
// src/acp/activity.ts
|
|
26846
|
+
// src/acp/activity-content.ts
|
|
26847
26847
|
var TRUNCATION_MARKER = "\n\u2026 output truncated by Mobius";
|
|
26848
|
-
var AcpActivityNarration = class {
|
|
26849
|
-
activityId;
|
|
26850
|
-
activityType;
|
|
26851
|
-
sequence;
|
|
26852
|
-
text;
|
|
26853
|
-
constructor(activityId, activityType, sequence, text2) {
|
|
26854
|
-
this.activityId = activityId;
|
|
26855
|
-
this.activityType = activityType;
|
|
26856
|
-
this.sequence = sequence;
|
|
26857
|
-
this.text = text2;
|
|
26858
|
-
}
|
|
26859
|
-
};
|
|
26860
26848
|
function isRecord5(value) {
|
|
26861
26849
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
26862
26850
|
}
|
|
26863
|
-
var AcpActivity = class _AcpActivity {
|
|
26864
|
-
activityId;
|
|
26865
|
-
activityType;
|
|
26866
|
-
input;
|
|
26867
|
-
locations;
|
|
26868
|
-
name;
|
|
26869
|
-
output;
|
|
26870
|
-
sequence;
|
|
26871
|
-
status;
|
|
26872
|
-
title;
|
|
26873
|
-
toolKind;
|
|
26874
|
-
content;
|
|
26875
|
-
detail;
|
|
26876
|
-
constructor(activityId, activityType, input2, locations, name, output2, sequence, status, title2, toolKind, content = [], detail = captureActivityDetail(content, input2, output2)) {
|
|
26877
|
-
this.activityId = activityId;
|
|
26878
|
-
this.activityType = activityType;
|
|
26879
|
-
this.input = input2;
|
|
26880
|
-
this.locations = locations;
|
|
26881
|
-
this.name = name;
|
|
26882
|
-
this.output = output2;
|
|
26883
|
-
this.sequence = sequence;
|
|
26884
|
-
this.status = status;
|
|
26885
|
-
this.title = title2;
|
|
26886
|
-
this.toolKind = toolKind;
|
|
26887
|
-
this.content = content;
|
|
26888
|
-
this.detail = detail;
|
|
26889
|
-
}
|
|
26890
|
-
complete = () => (this.activityType === "progress" || this.activityType === "reasoning") && (this.status === "pending" || this.status === "running") ? new _AcpActivity(
|
|
26891
|
-
this.activityId,
|
|
26892
|
-
this.activityType,
|
|
26893
|
-
this.input,
|
|
26894
|
-
this.locations,
|
|
26895
|
-
this.name,
|
|
26896
|
-
this.output,
|
|
26897
|
-
this.sequence,
|
|
26898
|
-
"completed",
|
|
26899
|
-
this.title,
|
|
26900
|
-
this.toolKind,
|
|
26901
|
-
this.content,
|
|
26902
|
-
this.detail
|
|
26903
|
-
) : this;
|
|
26904
|
-
};
|
|
26905
|
-
var ActivityIdentity = class {
|
|
26906
|
-
id;
|
|
26907
|
-
sequence;
|
|
26908
|
-
constructor(id, sequence) {
|
|
26909
|
-
this.id = id;
|
|
26910
|
-
this.sequence = sequence;
|
|
26911
|
-
}
|
|
26912
|
-
};
|
|
26913
26851
|
function truncate2(value, maximumLength) {
|
|
26914
26852
|
if (value.length <= maximumLength) {
|
|
26915
26853
|
return value;
|
|
@@ -27186,346 +27124,95 @@ function contentPhase(content) {
|
|
|
27186
27124
|
function isProgressMessage(content) {
|
|
27187
27125
|
return contentPhase(content) === "commentary";
|
|
27188
27126
|
}
|
|
27189
|
-
|
|
27190
|
-
|
|
27191
|
-
|
|
27192
|
-
|
|
27193
|
-
|
|
27194
|
-
|
|
27195
|
-
|
|
27196
|
-
|
|
27197
|
-
|
|
27198
|
-
|
|
27199
|
-
|
|
27200
|
-
|
|
27201
|
-
|
|
27202
|
-
|
|
27203
|
-
|
|
27204
|
-
|
|
27205
|
-
|
|
27206
|
-
|
|
27207
|
-
|
|
27208
|
-
|
|
27209
|
-
|
|
27210
|
-
|
|
27211
|
-
|
|
27212
|
-
|
|
27213
|
-
|
|
27214
|
-
|
|
27215
|
-
|
|
27216
|
-
|
|
27217
|
-
|
|
27218
|
-
|
|
27219
|
-
|
|
27220
|
-
|
|
27221
|
-
|
|
27127
|
+
|
|
27128
|
+
// src/acp/agent-connection.ts
|
|
27129
|
+
import { spawn as spawn4 } from "node:child_process";
|
|
27130
|
+
import { ndJsonStream as ndJsonStream2, RequestError as RequestError3 } from "@agentclientprotocol/sdk";
|
|
27131
|
+
|
|
27132
|
+
// src/acp/value-utils.ts
|
|
27133
|
+
function truncate3(value, maximumLength) {
|
|
27134
|
+
return value.length <= maximumLength ? value : `${value.slice(0, Math.max(0, maximumLength - 1))}\u2026`;
|
|
27135
|
+
}
|
|
27136
|
+
function isRecord6(value) {
|
|
27137
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
27138
|
+
}
|
|
27139
|
+
function readString2(value, fallback = "") {
|
|
27140
|
+
return typeof value === "string" ? value : fallback;
|
|
27141
|
+
}
|
|
27142
|
+
|
|
27143
|
+
// src/acp/agent-connection.ts
|
|
27144
|
+
function readableWebStream(input2) {
|
|
27145
|
+
let streamOpen = true;
|
|
27146
|
+
return new ReadableStream({
|
|
27147
|
+
start(controller) {
|
|
27148
|
+
input2.on("data", (chunk) => {
|
|
27149
|
+
if (!streamOpen) {
|
|
27150
|
+
return;
|
|
27151
|
+
}
|
|
27152
|
+
if (chunk instanceof Uint8Array) {
|
|
27153
|
+
controller.enqueue(new Uint8Array(chunk));
|
|
27154
|
+
return;
|
|
27155
|
+
}
|
|
27156
|
+
streamOpen = false;
|
|
27157
|
+
controller.error(new Error("ACP process produced a non-binary chunk"));
|
|
27158
|
+
});
|
|
27159
|
+
input2.once("end", () => {
|
|
27160
|
+
if (!streamOpen) {
|
|
27161
|
+
return;
|
|
27162
|
+
}
|
|
27163
|
+
streamOpen = false;
|
|
27164
|
+
controller.close();
|
|
27165
|
+
});
|
|
27166
|
+
input2.once("error", (error62) => {
|
|
27167
|
+
if (!streamOpen) {
|
|
27168
|
+
return;
|
|
27169
|
+
}
|
|
27170
|
+
streamOpen = false;
|
|
27171
|
+
controller.error(error62);
|
|
27172
|
+
});
|
|
27173
|
+
},
|
|
27174
|
+
cancel() {
|
|
27175
|
+
streamOpen = false;
|
|
27222
27176
|
}
|
|
27223
|
-
|
|
27224
|
-
|
|
27225
|
-
|
|
27177
|
+
});
|
|
27178
|
+
}
|
|
27179
|
+
function createWritableAcpStream(output2) {
|
|
27180
|
+
let outputFailure;
|
|
27181
|
+
const pendingWriteFailures = /* @__PURE__ */ new Set();
|
|
27182
|
+
const fail = (error62) => {
|
|
27183
|
+
outputFailure = error62;
|
|
27184
|
+
for (const reject of pendingWriteFailures) {
|
|
27185
|
+
reject(error62);
|
|
27226
27186
|
}
|
|
27187
|
+
pendingWriteFailures.clear();
|
|
27227
27188
|
};
|
|
27228
|
-
|
|
27229
|
-
|
|
27230
|
-
|
|
27231
|
-
|
|
27232
|
-
[],
|
|
27233
|
-
"",
|
|
27234
|
-
truncate2(output2, AGENT_ACTIVITY_DETAIL_LIMIT),
|
|
27235
|
-
identity2.sequence,
|
|
27236
|
-
status,
|
|
27237
|
-
activityType === "reasoning" ? "Reasoning" : "Progress update",
|
|
27238
|
-
activityType === "reasoning" ? "think" : ""
|
|
27239
|
-
);
|
|
27240
|
-
recordPlan = async (plan) => {
|
|
27241
|
-
await this.finishNarrative();
|
|
27242
|
-
await this.#recordPlanEntries("plan:default", plan.entries);
|
|
27243
|
-
};
|
|
27244
|
-
recordPlanUpdate = async (update) => {
|
|
27245
|
-
await this.finishNarrative();
|
|
27246
|
-
const plan = update.plan;
|
|
27247
|
-
const key = `plan:${plan.planId}`;
|
|
27248
|
-
if (plan.type === "items") {
|
|
27249
|
-
await this.#recordPlanEntries(key, plan.entries);
|
|
27250
|
-
return;
|
|
27189
|
+
output2.on("error", fail);
|
|
27190
|
+
output2.once("close", () => {
|
|
27191
|
+
if (outputFailure === void 0) {
|
|
27192
|
+
fail(new Error("ACP process input closed"));
|
|
27251
27193
|
}
|
|
27252
|
-
|
|
27253
|
-
|
|
27254
|
-
|
|
27255
|
-
|
|
27256
|
-
|
|
27257
|
-
|
|
27258
|
-
|
|
27259
|
-
|
|
27260
|
-
|
|
27261
|
-
|
|
27262
|
-
|
|
27263
|
-
|
|
27264
|
-
|
|
27265
|
-
|
|
27266
|
-
|
|
27267
|
-
|
|
27268
|
-
|
|
27269
|
-
|
|
27270
|
-
|
|
27271
|
-
|
|
27272
|
-
|
|
27273
|
-
|
|
27274
|
-
if (previous !== void 0) {
|
|
27275
|
-
await this.#record(
|
|
27276
|
-
key,
|
|
27277
|
-
new AcpActivity(
|
|
27278
|
-
previous.activityId,
|
|
27279
|
-
previous.activityType,
|
|
27280
|
-
previous.input,
|
|
27281
|
-
previous.locations,
|
|
27282
|
-
previous.name,
|
|
27283
|
-
previous.output,
|
|
27284
|
-
previous.sequence,
|
|
27285
|
-
"completed",
|
|
27286
|
-
previous.title,
|
|
27287
|
-
previous.toolKind,
|
|
27288
|
-
previous.content,
|
|
27289
|
-
previous.detail
|
|
27290
|
-
)
|
|
27291
|
-
);
|
|
27292
|
-
}
|
|
27293
|
-
};
|
|
27294
|
-
recordToolCall = async (update) => {
|
|
27295
|
-
await this.finishNarrative();
|
|
27296
|
-
const key = `tool:${update.toolCallId}`;
|
|
27297
|
-
const identity2 = this.#identity(key);
|
|
27298
|
-
const output2 = update.rawOutput === void 0 ? readContentOutput(update.content) : formatUnknown(update.rawOutput);
|
|
27299
|
-
const detailInput = update.rawInput === void 0 ? "" : formatUnknownDetail(update.rawInput);
|
|
27300
|
-
const detailOutput = update.rawOutput === void 0 ? readContentOutputDetail(update.content) : formatUnknownDetail(update.rawOutput);
|
|
27301
|
-
const detailContent = await normalizeToolContent(
|
|
27302
|
-
toolContent(update.content, update.rawOutput),
|
|
27303
|
-
this.#prepareContent
|
|
27304
|
-
);
|
|
27305
|
-
await this.#record(
|
|
27306
|
-
key,
|
|
27307
|
-
new AcpActivity(
|
|
27308
|
-
identity2.id,
|
|
27309
|
-
"tool",
|
|
27310
|
-
update.rawInput === void 0 ? "" : formatUnknown(update.rawInput),
|
|
27311
|
-
normalizeLocations(update.locations ?? []),
|
|
27312
|
-
truncate2(update.name ?? "", 128),
|
|
27313
|
-
output2,
|
|
27314
|
-
identity2.sequence,
|
|
27315
|
-
normalizeToolStatus(update.status ?? "pending", "pending"),
|
|
27316
|
-
normalizeTitle(update.title, "Tool call"),
|
|
27317
|
-
update.kind ?? "other",
|
|
27318
|
-
detailContent.slice(0, 100).map(summarizeDisplayContent),
|
|
27319
|
-
captureActivityDetail(detailContent, detailInput, detailOutput)
|
|
27320
|
-
)
|
|
27321
|
-
);
|
|
27322
|
-
};
|
|
27323
|
-
recordToolCallUpdate = async (update) => {
|
|
27324
|
-
await this.finishNarrative();
|
|
27325
|
-
const key = `tool:${update.toolCallId}`;
|
|
27326
|
-
const previous = this.#activities.get(key);
|
|
27327
|
-
const identity2 = this.#identity(key);
|
|
27328
|
-
const previousDetail = recordedDetail(previous);
|
|
27329
|
-
const output2 = update.rawOutput !== void 0 ? formatUnknown(update.rawOutput) : update.content !== void 0 && update.content !== null ? readContentOutput(update.content) : previous?.output ?? "";
|
|
27330
|
-
const nextContent = toolContent(update.content, update.rawOutput);
|
|
27331
|
-
const content = nextContent.length === 0 ? previous?.content ?? [] : await normalizeToolContent(nextContent, this.#prepareContent);
|
|
27332
|
-
const detailInput = update.rawInput === void 0 ? previousDetail?.input ?? previous?.input ?? "" : formatUnknownDetail(update.rawInput);
|
|
27333
|
-
const detailOutput = update.rawOutput !== void 0 ? formatUnknownDetail(update.rawOutput) : update.content !== void 0 && update.content !== null ? readContentOutputDetail(update.content) : previousDetail?.output ?? previous?.output ?? "";
|
|
27334
|
-
const detailContent = nextContent.length === 0 ? previousDetail?.content ?? previous?.content ?? [] : content;
|
|
27335
|
-
await this.#record(
|
|
27336
|
-
key,
|
|
27337
|
-
new AcpActivity(
|
|
27338
|
-
identity2.id,
|
|
27339
|
-
"tool",
|
|
27340
|
-
update.rawInput === void 0 ? previous?.input ?? "" : formatUnknown(update.rawInput),
|
|
27341
|
-
update.locations === void 0 || update.locations === null ? previous?.locations ?? [] : normalizeLocations(update.locations),
|
|
27342
|
-
update.name === void 0 || update.name === null ? previous?.name ?? "" : truncate2(update.name, 128),
|
|
27343
|
-
output2,
|
|
27344
|
-
identity2.sequence,
|
|
27345
|
-
update.status === void 0 || update.status === null ? previous?.status ?? "pending" : normalizeToolStatus(update.status, previous?.status ?? "pending"),
|
|
27346
|
-
update.title === void 0 || update.title === null ? previous?.title ?? "Tool call" : normalizeTitle(update.title, "Tool call"),
|
|
27347
|
-
update.kind === void 0 || update.kind === null ? previous?.toolKind ?? "other" : update.kind,
|
|
27348
|
-
content.slice(0, 100).map(summarizeDisplayContent),
|
|
27349
|
-
captureActivityDetail(detailContent, detailInput, detailOutput)
|
|
27350
|
-
)
|
|
27351
|
-
);
|
|
27352
|
-
};
|
|
27353
|
-
finishNarrative = async () => {
|
|
27354
|
-
const key = this.#activeNarrativeKey;
|
|
27355
|
-
if (key.length === 0) {
|
|
27356
|
-
return;
|
|
27357
|
-
}
|
|
27358
|
-
this.#activeNarrativeKey = "";
|
|
27359
|
-
await this.#completeNarrative(key);
|
|
27360
|
-
};
|
|
27361
|
-
finish = async () => {
|
|
27362
|
-
await this.finishNarrative();
|
|
27363
|
-
for (const key of this.#narrations.keys()) {
|
|
27364
|
-
await this.#completeNarrative(key);
|
|
27365
|
-
}
|
|
27366
|
-
const entries = [...this.#activities.entries()].sort((left, right) => left[1].sequence - right[1].sequence);
|
|
27367
|
-
for (const [key, activity2] of entries) {
|
|
27368
|
-
const completed = activity2.complete();
|
|
27369
|
-
if (completed !== activity2) {
|
|
27370
|
-
await this.#record(key, completed);
|
|
27371
|
-
}
|
|
27372
|
-
}
|
|
27373
|
-
};
|
|
27374
|
-
// Materialize a streamed narration as one completed snapshot activity. The
|
|
27375
|
-
// incremental events carried the text; this final event gives consumers the
|
|
27376
|
-
// whole narration with its terminal status, as a single bounded item.
|
|
27377
|
-
#completeNarrative = async (key) => {
|
|
27378
|
-
const narration = this.#narrations.get(key);
|
|
27379
|
-
if (narration === void 0) {
|
|
27380
|
-
return;
|
|
27381
|
-
}
|
|
27382
|
-
this.#narrations.delete(key);
|
|
27383
|
-
const previous = this.#activities.get(key);
|
|
27384
|
-
const detail = narration.truncated ? {
|
|
27385
|
-
capturedBytes: encodedByteLength({ content: [], input: "", output: narration.output }),
|
|
27386
|
-
kind: "truncated",
|
|
27387
|
-
originalBytes: narration.originalBytes
|
|
27388
|
-
} : captureActivityDetail([], "", narration.output);
|
|
27389
|
-
await this.#record(
|
|
27390
|
-
key,
|
|
27391
|
-
new AcpActivity(
|
|
27392
|
-
narration.activityId,
|
|
27393
|
-
narration.activityType,
|
|
27394
|
-
"",
|
|
27395
|
-
[],
|
|
27396
|
-
"",
|
|
27397
|
-
truncate2(narration.output, AGENT_ACTIVITY_DETAIL_LIMIT),
|
|
27398
|
-
narration.sequence,
|
|
27399
|
-
"completed",
|
|
27400
|
-
narration.activityType === "reasoning" ? "Reasoning" : "Progress update",
|
|
27401
|
-
narration.activityType === "reasoning" ? "think" : "",
|
|
27402
|
-
previous?.content ?? [],
|
|
27403
|
-
detail
|
|
27404
|
-
)
|
|
27405
|
-
);
|
|
27406
|
-
};
|
|
27407
|
-
#identity = (key) => {
|
|
27408
|
-
const existing = this.#identities.get(key);
|
|
27409
|
-
if (existing !== void 0) {
|
|
27410
|
-
return existing;
|
|
27411
|
-
}
|
|
27412
|
-
const identity2 = new ActivityIdentity(`activity-${crypto.randomUUID()}`, this.#nextSequence);
|
|
27413
|
-
this.#nextSequence += 1;
|
|
27414
|
-
this.#identities.set(key, identity2);
|
|
27415
|
-
return identity2;
|
|
27416
|
-
};
|
|
27417
|
-
#record = async (key, activity2) => {
|
|
27418
|
-
this.#activities.set(key, activity2);
|
|
27419
|
-
await this.#onActivity(activity2);
|
|
27420
|
-
};
|
|
27421
|
-
#recordPlanEntries = async (key, entries) => {
|
|
27422
|
-
const identity2 = this.#identity(key);
|
|
27423
|
-
await this.#record(
|
|
27424
|
-
key,
|
|
27425
|
-
new AcpActivity(
|
|
27426
|
-
identity2.id,
|
|
27427
|
-
"plan",
|
|
27428
|
-
"",
|
|
27429
|
-
[],
|
|
27430
|
-
"",
|
|
27431
|
-
formatPlanEntries(entries),
|
|
27432
|
-
identity2.sequence,
|
|
27433
|
-
planStatus(entries),
|
|
27434
|
-
"Plan",
|
|
27435
|
-
""
|
|
27436
|
-
)
|
|
27437
|
-
);
|
|
27438
|
-
};
|
|
27439
|
-
};
|
|
27440
|
-
|
|
27441
|
-
// src/acp/agent-connection.ts
|
|
27442
|
-
import { spawn as spawn4 } from "node:child_process";
|
|
27443
|
-
import { ndJsonStream as ndJsonStream2, RequestError as RequestError3 } from "@agentclientprotocol/sdk";
|
|
27444
|
-
|
|
27445
|
-
// src/acp/value-utils.ts
|
|
27446
|
-
function truncate3(value, maximumLength) {
|
|
27447
|
-
return value.length <= maximumLength ? value : `${value.slice(0, Math.max(0, maximumLength - 1))}\u2026`;
|
|
27448
|
-
}
|
|
27449
|
-
function isRecord6(value) {
|
|
27450
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
27451
|
-
}
|
|
27452
|
-
function readString2(value, fallback = "") {
|
|
27453
|
-
return typeof value === "string" ? value : fallback;
|
|
27454
|
-
}
|
|
27455
|
-
|
|
27456
|
-
// src/acp/agent-connection.ts
|
|
27457
|
-
function readableWebStream(input2) {
|
|
27458
|
-
let streamOpen = true;
|
|
27459
|
-
return new ReadableStream({
|
|
27460
|
-
start(controller) {
|
|
27461
|
-
input2.on("data", (chunk) => {
|
|
27462
|
-
if (!streamOpen) {
|
|
27463
|
-
return;
|
|
27464
|
-
}
|
|
27465
|
-
if (chunk instanceof Uint8Array) {
|
|
27466
|
-
controller.enqueue(new Uint8Array(chunk));
|
|
27467
|
-
return;
|
|
27468
|
-
}
|
|
27469
|
-
streamOpen = false;
|
|
27470
|
-
controller.error(new Error("ACP process produced a non-binary chunk"));
|
|
27471
|
-
});
|
|
27472
|
-
input2.once("end", () => {
|
|
27473
|
-
if (!streamOpen) {
|
|
27474
|
-
return;
|
|
27475
|
-
}
|
|
27476
|
-
streamOpen = false;
|
|
27477
|
-
controller.close();
|
|
27478
|
-
});
|
|
27479
|
-
input2.once("error", (error62) => {
|
|
27480
|
-
if (!streamOpen) {
|
|
27481
|
-
return;
|
|
27482
|
-
}
|
|
27483
|
-
streamOpen = false;
|
|
27484
|
-
controller.error(error62);
|
|
27485
|
-
});
|
|
27486
|
-
},
|
|
27487
|
-
cancel() {
|
|
27488
|
-
streamOpen = false;
|
|
27489
|
-
}
|
|
27490
|
-
});
|
|
27491
|
-
}
|
|
27492
|
-
function createWritableAcpStream(output2) {
|
|
27493
|
-
let outputFailure;
|
|
27494
|
-
const pendingWriteFailures = /* @__PURE__ */ new Set();
|
|
27495
|
-
const fail = (error62) => {
|
|
27496
|
-
outputFailure = error62;
|
|
27497
|
-
for (const reject of pendingWriteFailures) {
|
|
27498
|
-
reject(error62);
|
|
27499
|
-
}
|
|
27500
|
-
pendingWriteFailures.clear();
|
|
27501
|
-
};
|
|
27502
|
-
output2.on("error", fail);
|
|
27503
|
-
output2.once("close", () => {
|
|
27504
|
-
if (outputFailure === void 0) {
|
|
27505
|
-
fail(new Error("ACP process input closed"));
|
|
27506
|
-
}
|
|
27507
|
-
});
|
|
27508
|
-
return new WritableStream({
|
|
27509
|
-
write(chunk) {
|
|
27510
|
-
if (outputFailure !== void 0) {
|
|
27511
|
-
return Promise.reject(outputFailure);
|
|
27512
|
-
}
|
|
27513
|
-
return new Promise((resolve9, reject) => {
|
|
27514
|
-
pendingWriteFailures.add(reject);
|
|
27515
|
-
output2.write(chunk, (error62) => {
|
|
27516
|
-
pendingWriteFailures.delete(reject);
|
|
27517
|
-
if (error62) {
|
|
27518
|
-
outputFailure = error62;
|
|
27519
|
-
reject(error62);
|
|
27520
|
-
return;
|
|
27521
|
-
}
|
|
27522
|
-
if (outputFailure !== void 0) {
|
|
27523
|
-
reject(outputFailure);
|
|
27524
|
-
return;
|
|
27525
|
-
}
|
|
27526
|
-
resolve9();
|
|
27527
|
-
});
|
|
27528
|
-
});
|
|
27194
|
+
});
|
|
27195
|
+
return new WritableStream({
|
|
27196
|
+
write(chunk) {
|
|
27197
|
+
if (outputFailure !== void 0) {
|
|
27198
|
+
return Promise.reject(outputFailure);
|
|
27199
|
+
}
|
|
27200
|
+
return new Promise((resolve9, reject) => {
|
|
27201
|
+
pendingWriteFailures.add(reject);
|
|
27202
|
+
output2.write(chunk, (error62) => {
|
|
27203
|
+
pendingWriteFailures.delete(reject);
|
|
27204
|
+
if (error62) {
|
|
27205
|
+
outputFailure = error62;
|
|
27206
|
+
reject(error62);
|
|
27207
|
+
return;
|
|
27208
|
+
}
|
|
27209
|
+
if (outputFailure !== void 0) {
|
|
27210
|
+
reject(outputFailure);
|
|
27211
|
+
return;
|
|
27212
|
+
}
|
|
27213
|
+
resolve9();
|
|
27214
|
+
});
|
|
27215
|
+
});
|
|
27529
27216
|
}
|
|
27530
27217
|
});
|
|
27531
27218
|
}
|
|
@@ -27959,6 +27646,321 @@ var AcpAgentSettingsSnapshot = class {
|
|
|
27959
27646
|
}
|
|
27960
27647
|
};
|
|
27961
27648
|
|
|
27649
|
+
// src/acp/activity.ts
|
|
27650
|
+
var AcpActivityNarration = class {
|
|
27651
|
+
activityId;
|
|
27652
|
+
activityType;
|
|
27653
|
+
sequence;
|
|
27654
|
+
text;
|
|
27655
|
+
constructor(activityId, activityType, sequence, text2) {
|
|
27656
|
+
this.activityId = activityId;
|
|
27657
|
+
this.activityType = activityType;
|
|
27658
|
+
this.sequence = sequence;
|
|
27659
|
+
this.text = text2;
|
|
27660
|
+
}
|
|
27661
|
+
};
|
|
27662
|
+
var AcpActivity = class _AcpActivity {
|
|
27663
|
+
activityId;
|
|
27664
|
+
activityType;
|
|
27665
|
+
input;
|
|
27666
|
+
locations;
|
|
27667
|
+
name;
|
|
27668
|
+
output;
|
|
27669
|
+
sequence;
|
|
27670
|
+
status;
|
|
27671
|
+
title;
|
|
27672
|
+
toolKind;
|
|
27673
|
+
content;
|
|
27674
|
+
detail;
|
|
27675
|
+
constructor(activityId, activityType, input2, locations, name, output2, sequence, status, title2, toolKind, content = [], detail = captureActivityDetail(content, input2, output2)) {
|
|
27676
|
+
this.activityId = activityId;
|
|
27677
|
+
this.activityType = activityType;
|
|
27678
|
+
this.input = input2;
|
|
27679
|
+
this.locations = locations;
|
|
27680
|
+
this.name = name;
|
|
27681
|
+
this.output = output2;
|
|
27682
|
+
this.sequence = sequence;
|
|
27683
|
+
this.status = status;
|
|
27684
|
+
this.title = title2;
|
|
27685
|
+
this.toolKind = toolKind;
|
|
27686
|
+
this.content = content;
|
|
27687
|
+
this.detail = detail;
|
|
27688
|
+
}
|
|
27689
|
+
complete = () => (this.activityType === "progress" || this.activityType === "reasoning") && (this.status === "pending" || this.status === "running") ? new _AcpActivity(
|
|
27690
|
+
this.activityId,
|
|
27691
|
+
this.activityType,
|
|
27692
|
+
this.input,
|
|
27693
|
+
this.locations,
|
|
27694
|
+
this.name,
|
|
27695
|
+
this.output,
|
|
27696
|
+
this.sequence,
|
|
27697
|
+
"completed",
|
|
27698
|
+
this.title,
|
|
27699
|
+
this.toolKind,
|
|
27700
|
+
this.content,
|
|
27701
|
+
this.detail
|
|
27702
|
+
) : this;
|
|
27703
|
+
};
|
|
27704
|
+
var ActivityIdentity = class {
|
|
27705
|
+
id;
|
|
27706
|
+
sequence;
|
|
27707
|
+
constructor(id, sequence) {
|
|
27708
|
+
this.id = id;
|
|
27709
|
+
this.sequence = sequence;
|
|
27710
|
+
}
|
|
27711
|
+
};
|
|
27712
|
+
var AcpActivityTracker = class {
|
|
27713
|
+
#activities = /* @__PURE__ */ new Map();
|
|
27714
|
+
#identities = /* @__PURE__ */ new Map();
|
|
27715
|
+
#narrations = /* @__PURE__ */ new Map();
|
|
27716
|
+
#onActivity;
|
|
27717
|
+
#onNarration;
|
|
27718
|
+
#prepareContent;
|
|
27719
|
+
#activeNarrativeKey = "";
|
|
27720
|
+
#nextSequence = 0;
|
|
27721
|
+
constructor(onActivity, onNarration, prepareContent = (content) => Promise.resolve(content)) {
|
|
27722
|
+
this.#onActivity = onActivity;
|
|
27723
|
+
this.#onNarration = onNarration;
|
|
27724
|
+
this.#prepareContent = prepareContent;
|
|
27725
|
+
}
|
|
27726
|
+
recordNarrative = async (activityType, messageId, text2) => {
|
|
27727
|
+
const key = `${activityType}:${messageId}`;
|
|
27728
|
+
if (this.#activeNarrativeKey !== key) {
|
|
27729
|
+
await this.finishNarrative();
|
|
27730
|
+
}
|
|
27731
|
+
const identity2 = this.#identity(key);
|
|
27732
|
+
const previous = this.#narrations.get(key);
|
|
27733
|
+
const previousOutput = previous?.output ?? "";
|
|
27734
|
+
const remaining = Math.max(0, AGENT_ACTIVITY_DETAIL_LIMIT - previousOutput.length);
|
|
27735
|
+
this.#narrations.set(key, {
|
|
27736
|
+
activityId: identity2.id,
|
|
27737
|
+
activityType,
|
|
27738
|
+
output: `${previousOutput}${text2.slice(0, remaining)}`,
|
|
27739
|
+
originalBytes: (previous?.originalBytes ?? 0) + new TextEncoder().encode(text2).byteLength,
|
|
27740
|
+
sequence: identity2.sequence,
|
|
27741
|
+
truncated: (previous?.truncated ?? false) || text2.length > remaining
|
|
27742
|
+
});
|
|
27743
|
+
if (previous === void 0) {
|
|
27744
|
+
await this.#record(key, this.#narrativeSnapshot(identity2, activityType, "", "running"));
|
|
27745
|
+
}
|
|
27746
|
+
this.#activeNarrativeKey = key;
|
|
27747
|
+
if (text2.length > 0) {
|
|
27748
|
+
await this.#onNarration(new AcpActivityNarration(identity2.id, activityType, identity2.sequence, text2));
|
|
27749
|
+
}
|
|
27750
|
+
};
|
|
27751
|
+
#narrativeSnapshot = (identity2, activityType, output2, status) => new AcpActivity(
|
|
27752
|
+
identity2.id,
|
|
27753
|
+
activityType,
|
|
27754
|
+
"",
|
|
27755
|
+
[],
|
|
27756
|
+
"",
|
|
27757
|
+
truncate2(output2, AGENT_ACTIVITY_DETAIL_LIMIT),
|
|
27758
|
+
identity2.sequence,
|
|
27759
|
+
status,
|
|
27760
|
+
activityType === "reasoning" ? "Reasoning" : "Progress update",
|
|
27761
|
+
activityType === "reasoning" ? "think" : ""
|
|
27762
|
+
);
|
|
27763
|
+
recordPlan = async (plan) => {
|
|
27764
|
+
await this.finishNarrative();
|
|
27765
|
+
await this.#recordPlanEntries("plan:default", plan.entries);
|
|
27766
|
+
};
|
|
27767
|
+
recordPlanUpdate = async (update) => {
|
|
27768
|
+
await this.finishNarrative();
|
|
27769
|
+
const plan = update.plan;
|
|
27770
|
+
const key = `plan:${plan.planId}`;
|
|
27771
|
+
if (plan.type === "items") {
|
|
27772
|
+
await this.#recordPlanEntries(key, plan.entries);
|
|
27773
|
+
return;
|
|
27774
|
+
}
|
|
27775
|
+
const identity2 = this.#identity(key);
|
|
27776
|
+
const output2 = plan.type === "markdown" ? plan.content : `Plan file: ${plan.uri}`;
|
|
27777
|
+
await this.#record(
|
|
27778
|
+
key,
|
|
27779
|
+
new AcpActivity(
|
|
27780
|
+
identity2.id,
|
|
27781
|
+
"plan",
|
|
27782
|
+
"",
|
|
27783
|
+
[],
|
|
27784
|
+
"",
|
|
27785
|
+
truncate2(output2, AGENT_ACTIVITY_DETAIL_LIMIT),
|
|
27786
|
+
identity2.sequence,
|
|
27787
|
+
"running",
|
|
27788
|
+
"Plan",
|
|
27789
|
+
""
|
|
27790
|
+
)
|
|
27791
|
+
);
|
|
27792
|
+
};
|
|
27793
|
+
removePlan = async (update) => {
|
|
27794
|
+
await this.finishNarrative();
|
|
27795
|
+
const key = `plan:${update.planId}`;
|
|
27796
|
+
const previous = this.#activities.get(key);
|
|
27797
|
+
if (previous !== void 0) {
|
|
27798
|
+
await this.#record(
|
|
27799
|
+
key,
|
|
27800
|
+
new AcpActivity(
|
|
27801
|
+
previous.activityId,
|
|
27802
|
+
previous.activityType,
|
|
27803
|
+
previous.input,
|
|
27804
|
+
previous.locations,
|
|
27805
|
+
previous.name,
|
|
27806
|
+
previous.output,
|
|
27807
|
+
previous.sequence,
|
|
27808
|
+
"completed",
|
|
27809
|
+
previous.title,
|
|
27810
|
+
previous.toolKind,
|
|
27811
|
+
previous.content,
|
|
27812
|
+
previous.detail
|
|
27813
|
+
)
|
|
27814
|
+
);
|
|
27815
|
+
}
|
|
27816
|
+
};
|
|
27817
|
+
recordToolCall = async (update) => {
|
|
27818
|
+
await this.finishNarrative();
|
|
27819
|
+
const key = `tool:${update.toolCallId}`;
|
|
27820
|
+
const identity2 = this.#identity(key);
|
|
27821
|
+
const output2 = update.rawOutput === void 0 ? readContentOutput(update.content) : formatUnknown(update.rawOutput);
|
|
27822
|
+
const detailInput = update.rawInput === void 0 ? "" : formatUnknownDetail(update.rawInput);
|
|
27823
|
+
const detailOutput = update.rawOutput === void 0 ? readContentOutputDetail(update.content) : formatUnknownDetail(update.rawOutput);
|
|
27824
|
+
const detailContent = await normalizeToolContent(
|
|
27825
|
+
toolContent(update.content, update.rawOutput),
|
|
27826
|
+
this.#prepareContent
|
|
27827
|
+
);
|
|
27828
|
+
await this.#record(
|
|
27829
|
+
key,
|
|
27830
|
+
new AcpActivity(
|
|
27831
|
+
identity2.id,
|
|
27832
|
+
"tool",
|
|
27833
|
+
update.rawInput === void 0 ? "" : formatUnknown(update.rawInput),
|
|
27834
|
+
normalizeLocations(update.locations ?? []),
|
|
27835
|
+
truncate2(update.name ?? "", 128),
|
|
27836
|
+
output2,
|
|
27837
|
+
identity2.sequence,
|
|
27838
|
+
normalizeToolStatus(update.status ?? "pending", "pending"),
|
|
27839
|
+
normalizeTitle(update.title, "Tool call"),
|
|
27840
|
+
update.kind ?? "other",
|
|
27841
|
+
detailContent.slice(0, 100).map(summarizeDisplayContent),
|
|
27842
|
+
captureActivityDetail(detailContent, detailInput, detailOutput)
|
|
27843
|
+
)
|
|
27844
|
+
);
|
|
27845
|
+
};
|
|
27846
|
+
recordToolCallUpdate = async (update) => {
|
|
27847
|
+
await this.finishNarrative();
|
|
27848
|
+
const key = `tool:${update.toolCallId}`;
|
|
27849
|
+
const previous = this.#activities.get(key);
|
|
27850
|
+
const identity2 = this.#identity(key);
|
|
27851
|
+
const previousDetail = recordedDetail(previous);
|
|
27852
|
+
const output2 = update.rawOutput !== void 0 ? formatUnknown(update.rawOutput) : update.content !== void 0 && update.content !== null ? readContentOutput(update.content) : previous?.output ?? "";
|
|
27853
|
+
const nextContent = toolContent(update.content, update.rawOutput);
|
|
27854
|
+
const content = nextContent.length === 0 ? previous?.content ?? [] : await normalizeToolContent(nextContent, this.#prepareContent);
|
|
27855
|
+
const detailInput = update.rawInput === void 0 ? previousDetail?.input ?? previous?.input ?? "" : formatUnknownDetail(update.rawInput);
|
|
27856
|
+
const detailOutput = update.rawOutput !== void 0 ? formatUnknownDetail(update.rawOutput) : update.content !== void 0 && update.content !== null ? readContentOutputDetail(update.content) : previousDetail?.output ?? previous?.output ?? "";
|
|
27857
|
+
const detailContent = nextContent.length === 0 ? previousDetail?.content ?? previous?.content ?? [] : content;
|
|
27858
|
+
await this.#record(
|
|
27859
|
+
key,
|
|
27860
|
+
new AcpActivity(
|
|
27861
|
+
identity2.id,
|
|
27862
|
+
"tool",
|
|
27863
|
+
update.rawInput === void 0 ? previous?.input ?? "" : formatUnknown(update.rawInput),
|
|
27864
|
+
update.locations === void 0 || update.locations === null ? previous?.locations ?? [] : normalizeLocations(update.locations),
|
|
27865
|
+
update.name === void 0 || update.name === null ? previous?.name ?? "" : truncate2(update.name, 128),
|
|
27866
|
+
output2,
|
|
27867
|
+
identity2.sequence,
|
|
27868
|
+
update.status === void 0 || update.status === null ? previous?.status ?? "pending" : normalizeToolStatus(update.status, previous?.status ?? "pending"),
|
|
27869
|
+
update.title === void 0 || update.title === null ? previous?.title ?? "Tool call" : normalizeTitle(update.title, "Tool call"),
|
|
27870
|
+
update.kind === void 0 || update.kind === null ? previous?.toolKind ?? "other" : update.kind,
|
|
27871
|
+
content.slice(0, 100).map(summarizeDisplayContent),
|
|
27872
|
+
captureActivityDetail(detailContent, detailInput, detailOutput)
|
|
27873
|
+
)
|
|
27874
|
+
);
|
|
27875
|
+
};
|
|
27876
|
+
finishNarrative = async () => {
|
|
27877
|
+
const key = this.#activeNarrativeKey;
|
|
27878
|
+
if (key.length === 0) {
|
|
27879
|
+
return;
|
|
27880
|
+
}
|
|
27881
|
+
this.#activeNarrativeKey = "";
|
|
27882
|
+
await this.#completeNarrative(key);
|
|
27883
|
+
};
|
|
27884
|
+
finish = async () => {
|
|
27885
|
+
await this.finishNarrative();
|
|
27886
|
+
for (const key of this.#narrations.keys()) {
|
|
27887
|
+
await this.#completeNarrative(key);
|
|
27888
|
+
}
|
|
27889
|
+
const entries = [...this.#activities.entries()].sort((left, right) => left[1].sequence - right[1].sequence);
|
|
27890
|
+
for (const [key, activity2] of entries) {
|
|
27891
|
+
const completed = activity2.complete();
|
|
27892
|
+
if (completed !== activity2) {
|
|
27893
|
+
await this.#record(key, completed);
|
|
27894
|
+
}
|
|
27895
|
+
}
|
|
27896
|
+
};
|
|
27897
|
+
// Materialize a streamed narration as one completed snapshot activity. The
|
|
27898
|
+
// incremental events carried the text; this final event gives consumers the
|
|
27899
|
+
// whole narration with its terminal status, as a single bounded item.
|
|
27900
|
+
#completeNarrative = async (key) => {
|
|
27901
|
+
const narration = this.#narrations.get(key);
|
|
27902
|
+
if (narration === void 0) {
|
|
27903
|
+
return;
|
|
27904
|
+
}
|
|
27905
|
+
this.#narrations.delete(key);
|
|
27906
|
+
const previous = this.#activities.get(key);
|
|
27907
|
+
const detail = narration.truncated ? {
|
|
27908
|
+
capturedBytes: encodedByteLength({ content: [], input: "", output: narration.output }),
|
|
27909
|
+
kind: "truncated",
|
|
27910
|
+
originalBytes: narration.originalBytes
|
|
27911
|
+
} : captureActivityDetail([], "", narration.output);
|
|
27912
|
+
await this.#record(
|
|
27913
|
+
key,
|
|
27914
|
+
new AcpActivity(
|
|
27915
|
+
narration.activityId,
|
|
27916
|
+
narration.activityType,
|
|
27917
|
+
"",
|
|
27918
|
+
[],
|
|
27919
|
+
"",
|
|
27920
|
+
truncate2(narration.output, AGENT_ACTIVITY_DETAIL_LIMIT),
|
|
27921
|
+
narration.sequence,
|
|
27922
|
+
"completed",
|
|
27923
|
+
narration.activityType === "reasoning" ? "Reasoning" : "Progress update",
|
|
27924
|
+
narration.activityType === "reasoning" ? "think" : "",
|
|
27925
|
+
previous?.content ?? [],
|
|
27926
|
+
detail
|
|
27927
|
+
)
|
|
27928
|
+
);
|
|
27929
|
+
};
|
|
27930
|
+
#identity = (key) => {
|
|
27931
|
+
const existing = this.#identities.get(key);
|
|
27932
|
+
if (existing !== void 0) {
|
|
27933
|
+
return existing;
|
|
27934
|
+
}
|
|
27935
|
+
const identity2 = new ActivityIdentity(`activity-${crypto.randomUUID()}`, this.#nextSequence);
|
|
27936
|
+
this.#nextSequence += 1;
|
|
27937
|
+
this.#identities.set(key, identity2);
|
|
27938
|
+
return identity2;
|
|
27939
|
+
};
|
|
27940
|
+
#record = async (key, activity2) => {
|
|
27941
|
+
this.#activities.set(key, activity2);
|
|
27942
|
+
await this.#onActivity(activity2);
|
|
27943
|
+
};
|
|
27944
|
+
#recordPlanEntries = async (key, entries) => {
|
|
27945
|
+
const identity2 = this.#identity(key);
|
|
27946
|
+
await this.#record(
|
|
27947
|
+
key,
|
|
27948
|
+
new AcpActivity(
|
|
27949
|
+
identity2.id,
|
|
27950
|
+
"plan",
|
|
27951
|
+
"",
|
|
27952
|
+
[],
|
|
27953
|
+
"",
|
|
27954
|
+
formatPlanEntries(entries),
|
|
27955
|
+
identity2.sequence,
|
|
27956
|
+
planStatus(entries),
|
|
27957
|
+
"Plan",
|
|
27958
|
+
""
|
|
27959
|
+
)
|
|
27960
|
+
);
|
|
27961
|
+
};
|
|
27962
|
+
};
|
|
27963
|
+
|
|
27962
27964
|
// src/acp/session-history.ts
|
|
27963
27965
|
var HISTORY_ACTIVITY_FIELD_LIMIT = 1e5;
|
|
27964
27966
|
var HISTORY_ACTIVITY_LIMIT = 100;
|