@moxt-ai/mobius 0.0.166 → 0.0.168
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/agent-query-processes.d.ts +2 -1
- package/dist/acp/agent-query-processes.d.ts.map +1 -1
- package/dist/acp/agent-query-processes.js +6 -4
- package/dist/acp/agent-query-processes.js.map +1 -1
- package/dist/acp/agent-runtime-manager.d.ts +2 -1
- package/dist/acp/agent-runtime-manager.d.ts.map +1 -1
- package/dist/acp/agent-runtime-manager.js +11 -6
- package/dist/acp/agent-runtime-manager.js.map +1 -1
- package/dist/acp/agent-session.d.ts +3 -2
- package/dist/acp/agent-session.d.ts.map +1 -1
- package/dist/acp/agent-session.js +10 -7
- package/dist/acp/agent-session.js.map +1 -1
- package/dist/artifacts/local-file-streamer.d.ts +2 -1
- package/dist/artifacts/local-file-streamer.d.ts.map +1 -1
- package/dist/artifacts/local-file-streamer.js +6 -5
- package/dist/artifacts/local-file-streamer.js.map +1 -1
- package/dist/authorization/local-raster.d.ts +1 -0
- package/dist/authorization/local-raster.d.ts.map +1 -1
- package/dist/authorization/local-raster.js +1 -1
- package/dist/authorization/local-raster.js.map +1 -1
- package/dist/cli.js +565 -99
- package/dist/cli.js.map +4 -4
- package/dist/config.d.ts +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -1
- package/dist/config.js.map +1 -1
- package/dist/daemon-command-handler.d.ts +3 -1
- package/dist/daemon-command-handler.d.ts.map +1 -1
- package/dist/daemon-command-handler.js +2 -2
- package/dist/daemon-command-handler.js.map +1 -1
- package/dist/external-content/acp-content-externalizer.d.ts +12 -0
- package/dist/external-content/acp-content-externalizer.d.ts.map +1 -0
- package/dist/external-content/acp-content-externalizer.js +233 -0
- package/dist/external-content/acp-content-externalizer.js.map +1 -0
- package/dist/external-content/local-external-content-store.d.ts +34 -0
- package/dist/external-content/local-external-content-store.d.ts.map +1 -0
- package/dist/external-content/local-external-content-store.js +174 -0
- package/dist/external-content/local-external-content-store.js.map +1 -0
- package/dist/index.js +639 -179
- package/dist/index.js.map +4 -4
- package/dist/relay-connection/run-relay-connection.d.ts +3 -1
- package/dist/relay-connection/run-relay-connection.d.ts.map +1 -1
- package/dist/relay-connection/run-relay-connection.js +2 -1
- package/dist/relay-connection/run-relay-connection.js.map +1 -1
- package/dist/run-daemon.d.ts.map +1 -1
- package/dist/run-daemon.js +208 -140
- package/dist/run-daemon.js.map +1 -1
- package/dist/runtime.d.ts +2 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +572 -111
- package/dist/runtime.js.map +4 -4
- package/package.json +16 -10
package/dist/index.js
CHANGED
|
@@ -21215,6 +21215,7 @@ var MAX_JSON_KEYS = 1e3;
|
|
|
21215
21215
|
var SESSION_EVENT_V2_KIND = "session.event.v2";
|
|
21216
21216
|
var boundedString = external_exports.string().max(MAX_CONTENT_LENGTH);
|
|
21217
21217
|
var shortString = external_exports.string().max(2048);
|
|
21218
|
+
var externalContentKeySchema = external_exports.string().regex(/^[a-f0-9]{64}$/u);
|
|
21218
21219
|
function boundedJsonIssue(value, depth = 0) {
|
|
21219
21220
|
if (depth > MAX_JSON_DEPTH) {
|
|
21220
21221
|
return "JSON nesting exceeds the maximum depth";
|
|
@@ -21282,6 +21283,30 @@ var imageContentSchema = external_exports.object({
|
|
|
21282
21283
|
uri: boundedString.nullable().optional()
|
|
21283
21284
|
}).readonly();
|
|
21284
21285
|
var audioContentSchema = external_exports.object({ ...contentFields, data: boundedString, mimeType: shortString, type: external_exports.literal("audio") }).readonly();
|
|
21286
|
+
var externalImageContentSchema = external_exports.strictObject({
|
|
21287
|
+
...contentFields,
|
|
21288
|
+
byteLength: external_exports.number().int().positive().safe(),
|
|
21289
|
+
imageKey: externalContentKeySchema,
|
|
21290
|
+
mimeType: shortString,
|
|
21291
|
+
type: external_exports.literal("external_image"),
|
|
21292
|
+
uri: boundedString.nullable().optional()
|
|
21293
|
+
}).readonly();
|
|
21294
|
+
var externalAudioContentSchema = external_exports.strictObject({
|
|
21295
|
+
...contentFields,
|
|
21296
|
+
audioKey: externalContentKeySchema,
|
|
21297
|
+
byteLength: external_exports.number().int().positive().safe(),
|
|
21298
|
+
mimeType: shortString,
|
|
21299
|
+
type: external_exports.literal("external_audio")
|
|
21300
|
+
}).readonly();
|
|
21301
|
+
var externalResourceContentSchema = external_exports.strictObject({
|
|
21302
|
+
...contentFields,
|
|
21303
|
+
byteLength: external_exports.number().int().positive().safe(),
|
|
21304
|
+
encoding: external_exports.enum(["binary", "text"]),
|
|
21305
|
+
mimeType: shortString.nullable().optional(),
|
|
21306
|
+
resourceKey: externalContentKeySchema,
|
|
21307
|
+
type: external_exports.literal("external_resource"),
|
|
21308
|
+
uri: boundedString
|
|
21309
|
+
}).readonly();
|
|
21285
21310
|
var resourceLinkSchema = external_exports.object({
|
|
21286
21311
|
...contentFields,
|
|
21287
21312
|
description: boundedString.nullable().optional(),
|
|
@@ -21314,7 +21339,10 @@ var contentBlockV2Schema = external_exports.discriminatedUnion("type", [
|
|
|
21314
21339
|
imageContentSchema,
|
|
21315
21340
|
audioContentSchema,
|
|
21316
21341
|
resourceLinkSchema,
|
|
21317
|
-
embeddedResourceSchema
|
|
21342
|
+
embeddedResourceSchema,
|
|
21343
|
+
externalImageContentSchema,
|
|
21344
|
+
externalAudioContentSchema,
|
|
21345
|
+
externalResourceContentSchema
|
|
21318
21346
|
]);
|
|
21319
21347
|
var toolCallContentSchema = external_exports.discriminatedUnion("type", [
|
|
21320
21348
|
external_exports.object({ _meta: optionalMetadata, content: contentBlockV2Schema, type: external_exports.literal("content") }).readonly(),
|
|
@@ -26365,7 +26393,7 @@ function sql(strings, ...params) {
|
|
|
26365
26393
|
return new SQL([new StringChunk(str)]);
|
|
26366
26394
|
}
|
|
26367
26395
|
sql2.raw = raw;
|
|
26368
|
-
function
|
|
26396
|
+
function join20(chunks, separator) {
|
|
26369
26397
|
const result = [];
|
|
26370
26398
|
for (const [i, chunk] of chunks.entries()) {
|
|
26371
26399
|
if (i > 0 && separator !== void 0) {
|
|
@@ -26375,7 +26403,7 @@ function sql(strings, ...params) {
|
|
|
26375
26403
|
}
|
|
26376
26404
|
return new SQL(result);
|
|
26377
26405
|
}
|
|
26378
|
-
sql2.join =
|
|
26406
|
+
sql2.join = join20;
|
|
26379
26407
|
function identifier(value) {
|
|
26380
26408
|
return new Name(value);
|
|
26381
26409
|
}
|
|
@@ -28919,7 +28947,7 @@ var SQLiteSelectQueryBuilderBase = class extends TypedQueryBuilder {
|
|
|
28919
28947
|
const baseTableName = this.tableName;
|
|
28920
28948
|
const tableName = getTableLikeName(table);
|
|
28921
28949
|
for (const item of extractUsedTable(table)) this.usedTables.add(item);
|
|
28922
|
-
if (typeof tableName === "string" && this.config.joins?.some((
|
|
28950
|
+
if (typeof tableName === "string" && this.config.joins?.some((join20) => join20.alias === tableName)) {
|
|
28923
28951
|
throw new Error(`Alias "${tableName}" is already used in this query`);
|
|
28924
28952
|
}
|
|
28925
28953
|
if (!this.isPartialSelect) {
|
|
@@ -29778,7 +29806,7 @@ var SQLiteUpdateBase = class extends QueryPromise {
|
|
|
29778
29806
|
createJoin(joinType) {
|
|
29779
29807
|
return (table, on) => {
|
|
29780
29808
|
const tableName = getTableLikeName(table);
|
|
29781
|
-
if (typeof tableName === "string" && this.config.joins.some((
|
|
29809
|
+
if (typeof tableName === "string" && this.config.joins.some((join20) => join20.alias === tableName)) {
|
|
29782
29810
|
throw new Error(`Alias "${tableName}" is already used in this query`);
|
|
29783
29811
|
}
|
|
29784
29812
|
if (typeof on === "function") {
|
|
@@ -31101,6 +31129,7 @@ function recordsEqual(left, right) {
|
|
|
31101
31129
|
}
|
|
31102
31130
|
var AgentSession = class _AgentSession {
|
|
31103
31131
|
#connection;
|
|
31132
|
+
#contentExternalizer;
|
|
31104
31133
|
#interactions;
|
|
31105
31134
|
#additionalDirectories;
|
|
31106
31135
|
#agentId;
|
|
@@ -31128,7 +31157,7 @@ var AgentSession = class _AgentSession {
|
|
|
31128
31157
|
#sessionTitle = null;
|
|
31129
31158
|
#sessionUpdatedAt = "";
|
|
31130
31159
|
#turn = new IdleAcpTurn();
|
|
31131
|
-
constructor(agent, cwd, additionalDirectories, mobiusSessionId, getObserver, store, metrics) {
|
|
31160
|
+
constructor(agent, cwd, additionalDirectories, mobiusSessionId, getObserver, store, metrics, contentExternalizer) {
|
|
31132
31161
|
this.#updates = new AgentUpdateStream((notification) => this.#processUpdate(notification));
|
|
31133
31162
|
this.#additionalDirectories = [...additionalDirectories];
|
|
31134
31163
|
this.#agentId = agent.id;
|
|
@@ -31148,8 +31177,9 @@ var AgentSession = class _AgentSession {
|
|
|
31148
31177
|
observer: getObserver
|
|
31149
31178
|
});
|
|
31150
31179
|
this.#connection = new AgentConnection(agent, cwd, this);
|
|
31180
|
+
this.#contentExternalizer = contentExternalizer;
|
|
31151
31181
|
}
|
|
31152
|
-
static async #start(options, getObserver, store, initialize, metrics) {
|
|
31182
|
+
static async #start(options, getObserver, store, initialize, metrics, contentExternalizer) {
|
|
31153
31183
|
for (let attempt = 1; attempt <= 2; attempt += 1) {
|
|
31154
31184
|
options.signal.throwIfAborted();
|
|
31155
31185
|
const unchanged = await metrics.measure(
|
|
@@ -31177,7 +31207,8 @@ var AgentSession = class _AgentSession {
|
|
|
31177
31207
|
options.sessionId,
|
|
31178
31208
|
getObserver,
|
|
31179
31209
|
store,
|
|
31180
|
-
metrics
|
|
31210
|
+
metrics,
|
|
31211
|
+
contentExternalizer
|
|
31181
31212
|
)
|
|
31182
31213
|
);
|
|
31183
31214
|
try {
|
|
@@ -31200,19 +31231,21 @@ var AgentSession = class _AgentSession {
|
|
|
31200
31231
|
}
|
|
31201
31232
|
throw new AcpExecutionError("ACP agent initialization failed");
|
|
31202
31233
|
}
|
|
31203
|
-
static start = async (options, getObserver, store, metrics
|
|
31234
|
+
static start = async (options, getObserver, store, metrics, contentExternalizer) => await _AgentSession.#start(
|
|
31204
31235
|
options,
|
|
31205
31236
|
getObserver,
|
|
31206
31237
|
store,
|
|
31207
31238
|
async (runtime) => await runtime.initialize(options.signal, options.origin),
|
|
31208
|
-
metrics
|
|
31239
|
+
metrics,
|
|
31240
|
+
contentExternalizer
|
|
31209
31241
|
);
|
|
31210
|
-
static startNativeSessionBrowser = async (options, getObserver, store) => await _AgentSession.#start(
|
|
31242
|
+
static startNativeSessionBrowser = async (options, getObserver, store, contentExternalizer) => await _AgentSession.#start(
|
|
31211
31243
|
options,
|
|
31212
31244
|
getObserver,
|
|
31213
31245
|
store,
|
|
31214
31246
|
async (runtime) => await runtime.#initializeAgent(options.signal),
|
|
31215
|
-
unmeasuredOperationMetrics
|
|
31247
|
+
unmeasuredOperationMetrics,
|
|
31248
|
+
contentExternalizer
|
|
31216
31249
|
);
|
|
31217
31250
|
belongsTo = (agentId, cwd, additionalDirectories) => this.#agentId === agentId && this.#cwd === cwd && arraysEqual(this.#additionalDirectories, additionalDirectories);
|
|
31218
31251
|
usesEnvironment = (environment) => recordsEqual(this.#environment, environment);
|
|
@@ -31916,8 +31949,13 @@ var AgentSession = class _AgentSession {
|
|
|
31916
31949
|
};
|
|
31917
31950
|
#processUpdate = async (notification) => {
|
|
31918
31951
|
this.assertNativeSession(notification.sessionId);
|
|
31919
|
-
const
|
|
31920
|
-
|
|
31952
|
+
const externalized = await this.#contentExternalizer.update(
|
|
31953
|
+
this.#mobiusSessionId,
|
|
31954
|
+
notification.update,
|
|
31955
|
+
AbortSignal.timeout(3e4)
|
|
31956
|
+
);
|
|
31957
|
+
const update = externalized.agent;
|
|
31958
|
+
const rawUpdate = decodeAcpSessionUpdateV2(JSON.stringify(externalized.event));
|
|
31921
31959
|
if (this.#sessionLoad.kind === "capturing") {
|
|
31922
31960
|
await this.#sessionLoad.history.record(update, rawUpdate);
|
|
31923
31961
|
} else {
|
|
@@ -32204,8 +32242,10 @@ var AgentQueryProcesses = class {
|
|
|
32204
32242
|
#processes;
|
|
32205
32243
|
#observer = new NullAcpSessionObserver();
|
|
32206
32244
|
#store = new MemoryAcpSessionStore();
|
|
32207
|
-
|
|
32245
|
+
#contentExternalizer;
|
|
32246
|
+
constructor(processes, contentExternalizer) {
|
|
32208
32247
|
this.#processes = processes;
|
|
32248
|
+
this.#contentExternalizer = contentExternalizer;
|
|
32209
32249
|
this.#processesByQuery = new RetainedAgentProcesses({
|
|
32210
32250
|
touch: processes.touch,
|
|
32211
32251
|
changed: processes.notifyChanged
|
|
@@ -32221,7 +32261,12 @@ var AgentQueryProcesses = class {
|
|
|
32221
32261
|
async #startRetained(options) {
|
|
32222
32262
|
const runtime = await this.#processes.startRetained(
|
|
32223
32263
|
options.signal,
|
|
32224
|
-
() => AgentSession.startNativeSessionBrowser(
|
|
32264
|
+
() => AgentSession.startNativeSessionBrowser(
|
|
32265
|
+
options,
|
|
32266
|
+
() => this.#observer,
|
|
32267
|
+
this.#store,
|
|
32268
|
+
this.#contentExternalizer
|
|
32269
|
+
),
|
|
32225
32270
|
{
|
|
32226
32271
|
isBusy: () => this.#processesByQuery.isBusy(options.sessionId),
|
|
32227
32272
|
retire: (runtime2) => this.retire(options.sessionId, runtime2)
|
|
@@ -32297,7 +32342,8 @@ var AgentQueryProcesses = class {
|
|
|
32297
32342
|
async () => await AgentSession.startNativeSessionBrowser(
|
|
32298
32343
|
options,
|
|
32299
32344
|
() => this.#observer,
|
|
32300
|
-
new MemoryAcpSessionStore()
|
|
32345
|
+
new MemoryAcpSessionStore(),
|
|
32346
|
+
this.#contentExternalizer
|
|
32301
32347
|
),
|
|
32302
32348
|
async (runtime) => {
|
|
32303
32349
|
runtime.selectNativeSession(nativeSessionId);
|
|
@@ -32312,7 +32358,8 @@ var AgentQueryProcesses = class {
|
|
|
32312
32358
|
async () => await AgentSession.startNativeSessionBrowser(
|
|
32313
32359
|
options,
|
|
32314
32360
|
() => this.#observer,
|
|
32315
|
-
new MemoryAcpSessionStore()
|
|
32361
|
+
new MemoryAcpSessionStore(),
|
|
32362
|
+
this.#contentExternalizer
|
|
32316
32363
|
),
|
|
32317
32364
|
async (runtime) => {
|
|
32318
32365
|
runtime.selectNativeSession(nativeSessionId);
|
|
@@ -32328,6 +32375,393 @@ var AgentQueryProcesses = class {
|
|
|
32328
32375
|
};
|
|
32329
32376
|
};
|
|
32330
32377
|
|
|
32378
|
+
// src/external-content/acp-content-externalizer.ts
|
|
32379
|
+
var MAXIMUM_ENCODED_CONTENT_CHARACTERS = 4e6;
|
|
32380
|
+
function decodeBase64(data) {
|
|
32381
|
+
if (data.length > MAXIMUM_ENCODED_CONTENT_CHARACTERS || data.length % 4 !== 0 || !/^[A-Za-z0-9+/]*={0,2}$/u.test(data)) {
|
|
32382
|
+
throw new Error("The ACP embedded content is not valid bounded base64");
|
|
32383
|
+
}
|
|
32384
|
+
const bytes = Buffer.from(data, "base64");
|
|
32385
|
+
if (bytes.toString("base64") !== data) {
|
|
32386
|
+
throw new Error("The ACP embedded content is not canonical base64");
|
|
32387
|
+
}
|
|
32388
|
+
return bytes;
|
|
32389
|
+
}
|
|
32390
|
+
var embeddedImageSchema = external_exports.looseObject({
|
|
32391
|
+
type: external_exports.literal("image"),
|
|
32392
|
+
data: external_exports.string(),
|
|
32393
|
+
mimeType: external_exports.string()
|
|
32394
|
+
});
|
|
32395
|
+
function isRecord6(value) {
|
|
32396
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
32397
|
+
}
|
|
32398
|
+
var AcpContentExternalizer = class {
|
|
32399
|
+
#store;
|
|
32400
|
+
constructor(store) {
|
|
32401
|
+
this.#store = store;
|
|
32402
|
+
}
|
|
32403
|
+
async #content(sessionId, content, signal) {
|
|
32404
|
+
switch (content.type) {
|
|
32405
|
+
case "text":
|
|
32406
|
+
case "resource_link":
|
|
32407
|
+
return { agent: content, event: content };
|
|
32408
|
+
case "image": {
|
|
32409
|
+
if (content.data.length === 0) {
|
|
32410
|
+
return { agent: content, event: content };
|
|
32411
|
+
}
|
|
32412
|
+
try {
|
|
32413
|
+
const bytes = decodeBase64(content.data);
|
|
32414
|
+
if (sniffRasterMime(bytes) !== content.mimeType) {
|
|
32415
|
+
throw new Error("Embedded image bytes do not match a supported image MIME type");
|
|
32416
|
+
}
|
|
32417
|
+
const stored = await this.#store.put({
|
|
32418
|
+
bytes,
|
|
32419
|
+
kind: "image",
|
|
32420
|
+
mediaType: content.mimeType,
|
|
32421
|
+
name: "image",
|
|
32422
|
+
sessionId,
|
|
32423
|
+
signal
|
|
32424
|
+
});
|
|
32425
|
+
return {
|
|
32426
|
+
agent: { ...content, data: "", uri: `mobius-content:image:${stored.key}` },
|
|
32427
|
+
event: {
|
|
32428
|
+
_meta: content._meta,
|
|
32429
|
+
annotations: content.annotations,
|
|
32430
|
+
byteLength: stored.byteLength,
|
|
32431
|
+
imageKey: stored.key,
|
|
32432
|
+
mimeType: content.mimeType,
|
|
32433
|
+
type: "external_image",
|
|
32434
|
+
uri: content.uri
|
|
32435
|
+
}
|
|
32436
|
+
};
|
|
32437
|
+
} catch {
|
|
32438
|
+
signal.throwIfAborted();
|
|
32439
|
+
const unavailable = { type: "text", text: "[Image unavailable]" };
|
|
32440
|
+
return { agent: unavailable, event: unavailable };
|
|
32441
|
+
}
|
|
32442
|
+
}
|
|
32443
|
+
case "audio": {
|
|
32444
|
+
if (content.data.length === 0) {
|
|
32445
|
+
return { agent: content, event: content };
|
|
32446
|
+
}
|
|
32447
|
+
const stored = await this.#store.put({
|
|
32448
|
+
bytes: decodeBase64(content.data),
|
|
32449
|
+
kind: "audio",
|
|
32450
|
+
mediaType: content.mimeType,
|
|
32451
|
+
name: "audio",
|
|
32452
|
+
sessionId,
|
|
32453
|
+
signal
|
|
32454
|
+
});
|
|
32455
|
+
return {
|
|
32456
|
+
agent: content,
|
|
32457
|
+
event: {
|
|
32458
|
+
_meta: content._meta,
|
|
32459
|
+
annotations: content.annotations,
|
|
32460
|
+
audioKey: stored.key,
|
|
32461
|
+
byteLength: stored.byteLength,
|
|
32462
|
+
mimeType: content.mimeType,
|
|
32463
|
+
type: "external_audio"
|
|
32464
|
+
}
|
|
32465
|
+
};
|
|
32466
|
+
}
|
|
32467
|
+
case "resource": {
|
|
32468
|
+
const embedded = content.resource;
|
|
32469
|
+
const encoding = "text" in embedded ? "text" : "binary";
|
|
32470
|
+
const bytes = "text" in embedded ? Buffer.from(embedded.text, "utf8") : decodeBase64(embedded.blob);
|
|
32471
|
+
if (bytes.byteLength === 0) {
|
|
32472
|
+
return { agent: content, event: content };
|
|
32473
|
+
}
|
|
32474
|
+
const mediaType = embedded.mimeType ?? "application/octet-stream";
|
|
32475
|
+
const stored = await this.#store.put({
|
|
32476
|
+
bytes,
|
|
32477
|
+
kind: "resource",
|
|
32478
|
+
mediaType,
|
|
32479
|
+
name: "resource",
|
|
32480
|
+
sessionId,
|
|
32481
|
+
signal
|
|
32482
|
+
});
|
|
32483
|
+
return {
|
|
32484
|
+
agent: content,
|
|
32485
|
+
event: {
|
|
32486
|
+
_meta: content._meta,
|
|
32487
|
+
annotations: content.annotations,
|
|
32488
|
+
byteLength: stored.byteLength,
|
|
32489
|
+
encoding,
|
|
32490
|
+
mimeType: embedded.mimeType,
|
|
32491
|
+
resourceKey: stored.key,
|
|
32492
|
+
type: "external_resource",
|
|
32493
|
+
uri: embedded.uri
|
|
32494
|
+
}
|
|
32495
|
+
};
|
|
32496
|
+
}
|
|
32497
|
+
}
|
|
32498
|
+
}
|
|
32499
|
+
async #rawOutput(sessionId, value, images, signal, depth = 0) {
|
|
32500
|
+
signal.throwIfAborted();
|
|
32501
|
+
if (depth > 16) {
|
|
32502
|
+
throw new Error("ACP tool output exceeds the maximum nesting depth");
|
|
32503
|
+
}
|
|
32504
|
+
if (Array.isArray(value)) {
|
|
32505
|
+
const result2 = [];
|
|
32506
|
+
for (const item of value) {
|
|
32507
|
+
result2.push(await this.#rawOutput(sessionId, item, images, signal, depth + 1));
|
|
32508
|
+
}
|
|
32509
|
+
return result2;
|
|
32510
|
+
}
|
|
32511
|
+
if (!isRecord6(value)) {
|
|
32512
|
+
return value;
|
|
32513
|
+
}
|
|
32514
|
+
const image = embeddedImageSchema.safeParse(value);
|
|
32515
|
+
if (image.success && image.data.data.length > 0) {
|
|
32516
|
+
const prepared = await this.#content(sessionId, image.data, signal);
|
|
32517
|
+
if (isRecord6(prepared.event) && typeof prepared.event["imageKey"] === "string") {
|
|
32518
|
+
images.set(prepared.event["imageKey"], prepared);
|
|
32519
|
+
} else {
|
|
32520
|
+
images.set(`unavailable:${images.size}`, prepared);
|
|
32521
|
+
}
|
|
32522
|
+
return prepared.event;
|
|
32523
|
+
}
|
|
32524
|
+
const result = {};
|
|
32525
|
+
for (const [key, item] of Object.entries(value)) {
|
|
32526
|
+
result[key] = await this.#rawOutput(sessionId, item, images, signal, depth + 1);
|
|
32527
|
+
}
|
|
32528
|
+
return result;
|
|
32529
|
+
}
|
|
32530
|
+
async #toolUpdate(sessionId, update, signal) {
|
|
32531
|
+
const images = /* @__PURE__ */ new Map();
|
|
32532
|
+
const rawOutput = update.rawOutput === void 0 ? void 0 : await this.#rawOutput(sessionId, update.rawOutput, images, signal);
|
|
32533
|
+
const originalJson = images.size === 0 ? void 0 : JSON.stringify(update.rawOutput);
|
|
32534
|
+
const rewrittenJson = images.size === 0 ? void 0 : JSON.stringify(rawOutput);
|
|
32535
|
+
const agentContent = [];
|
|
32536
|
+
const eventContent = [];
|
|
32537
|
+
for (const item of update.content ?? []) {
|
|
32538
|
+
if (item.type !== "content") {
|
|
32539
|
+
agentContent.push(item);
|
|
32540
|
+
eventContent.push(item);
|
|
32541
|
+
continue;
|
|
32542
|
+
}
|
|
32543
|
+
const content = item.content.type === "text" && item.content.text === originalJson && rewrittenJson !== void 0 ? { ...item.content, text: rewrittenJson } : item.content;
|
|
32544
|
+
const prepared = await this.#content(sessionId, content, signal);
|
|
32545
|
+
agentContent.push({ ...item, content: prepared.agent });
|
|
32546
|
+
eventContent.push({ ...item, content: prepared.event });
|
|
32547
|
+
if (isRecord6(prepared.event) && typeof prepared.event["imageKey"] === "string") {
|
|
32548
|
+
images.delete(prepared.event["imageKey"]);
|
|
32549
|
+
}
|
|
32550
|
+
}
|
|
32551
|
+
for (const prepared of images.values()) {
|
|
32552
|
+
agentContent.push({ type: "content", content: prepared.agent });
|
|
32553
|
+
eventContent.push({ type: "content", content: prepared.event });
|
|
32554
|
+
}
|
|
32555
|
+
const output2 = update.rawOutput === void 0 ? {} : { rawOutput };
|
|
32556
|
+
const hasContent = update.content !== void 0 && update.content !== null || agentContent.length > 0;
|
|
32557
|
+
return {
|
|
32558
|
+
agent: { ...update, ...output2, ...hasContent ? { content: agentContent } : {} },
|
|
32559
|
+
event: { ...update, ...output2, ...hasContent ? { content: eventContent } : {} }
|
|
32560
|
+
};
|
|
32561
|
+
}
|
|
32562
|
+
update = async (sessionId, update, signal) => {
|
|
32563
|
+
switch (update.sessionUpdate) {
|
|
32564
|
+
case "user_message_chunk":
|
|
32565
|
+
case "agent_message_chunk":
|
|
32566
|
+
case "agent_thought_chunk":
|
|
32567
|
+
case "compaction_summary_chunk": {
|
|
32568
|
+
const content = await this.#content(sessionId, update.content, signal);
|
|
32569
|
+
return {
|
|
32570
|
+
agent: { ...update, content: content.agent },
|
|
32571
|
+
event: { ...update, content: content.event }
|
|
32572
|
+
};
|
|
32573
|
+
}
|
|
32574
|
+
case "tool_call":
|
|
32575
|
+
case "tool_call_update":
|
|
32576
|
+
return await this.#toolUpdate(sessionId, update, signal);
|
|
32577
|
+
case "compaction_update": {
|
|
32578
|
+
if (update.summary === void 0 || update.summary === null) {
|
|
32579
|
+
return { agent: update, event: update };
|
|
32580
|
+
}
|
|
32581
|
+
const content = await Promise.all(
|
|
32582
|
+
update.summary.map(async (item) => await this.#content(sessionId, item, signal))
|
|
32583
|
+
);
|
|
32584
|
+
return {
|
|
32585
|
+
agent: { ...update, summary: content.map((item) => item.agent) },
|
|
32586
|
+
event: { ...update, summary: content.map((item) => item.event) }
|
|
32587
|
+
};
|
|
32588
|
+
}
|
|
32589
|
+
case "plan":
|
|
32590
|
+
case "plan_update":
|
|
32591
|
+
case "plan_removed":
|
|
32592
|
+
case "available_commands_update":
|
|
32593
|
+
case "current_mode_update":
|
|
32594
|
+
case "config_option_update":
|
|
32595
|
+
case "session_info_update":
|
|
32596
|
+
case "usage_update":
|
|
32597
|
+
return { agent: update, event: update };
|
|
32598
|
+
}
|
|
32599
|
+
};
|
|
32600
|
+
};
|
|
32601
|
+
|
|
32602
|
+
// src/external-content/local-external-content-store.ts
|
|
32603
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
32604
|
+
import { lstat, mkdir, readdir as readdir2, realpath as realpath3, rename, rm, stat as stat3, utimes, writeFile } from "node:fs/promises";
|
|
32605
|
+
import { dirname as dirname2, join as join4 } from "node:path";
|
|
32606
|
+
var contentRequest = /^mobius-content:(image|audio|resource):([a-f0-9]{64})$/u;
|
|
32607
|
+
var CONTENT_LIFETIME_MILLISECONDS = 24 * 60 * 60 * 1e3;
|
|
32608
|
+
var metadataSchema2 = external_exports.strictObject({
|
|
32609
|
+
kind: external_exports.enum(["image", "audio", "resource"]),
|
|
32610
|
+
mediaType: external_exports.string().min(1).max(2048).regex(/^[\u0020-\u007e]+$/u),
|
|
32611
|
+
name: external_exports.string().min(1).max(500)
|
|
32612
|
+
});
|
|
32613
|
+
var UnretainedExternalContentStore = class {
|
|
32614
|
+
put = async ({ bytes, signal }) => {
|
|
32615
|
+
signal.throwIfAborted();
|
|
32616
|
+
return { byteLength: bytes.byteLength, key: createHash("sha256").update(bytes).digest("hex") };
|
|
32617
|
+
};
|
|
32618
|
+
resolve = (_sessionId, _request, signal) => {
|
|
32619
|
+
signal.throwIfAborted();
|
|
32620
|
+
return Promise.resolve(null);
|
|
32621
|
+
};
|
|
32622
|
+
};
|
|
32623
|
+
async function atomicWrite(path2, bytes, signal) {
|
|
32624
|
+
const temporary = `${path2}.${randomUUID()}.tmp`;
|
|
32625
|
+
try {
|
|
32626
|
+
await writeFile(temporary, bytes, { mode: 384, signal });
|
|
32627
|
+
signal.throwIfAborted();
|
|
32628
|
+
await rename(temporary, path2);
|
|
32629
|
+
} finally {
|
|
32630
|
+
await rm(temporary, { force: true });
|
|
32631
|
+
}
|
|
32632
|
+
}
|
|
32633
|
+
var LocalExternalContentStore = class {
|
|
32634
|
+
#root;
|
|
32635
|
+
#entries = /* @__PURE__ */ new Map();
|
|
32636
|
+
#operations = /* @__PURE__ */ new Set();
|
|
32637
|
+
#lifetime = new AbortController();
|
|
32638
|
+
#expirationTimer;
|
|
32639
|
+
#cleanup = Promise.resolve();
|
|
32640
|
+
constructor(stateDirectory) {
|
|
32641
|
+
this.#root = join4(stateDirectory, "tmp", "session-content", randomUUID());
|
|
32642
|
+
this.#expirationTimer = setInterval(() => {
|
|
32643
|
+
void this.#expire().catch(() => void 0);
|
|
32644
|
+
}, 6e4);
|
|
32645
|
+
this.#expirationTimer.unref();
|
|
32646
|
+
}
|
|
32647
|
+
#expire = () => {
|
|
32648
|
+
this.#cleanup = this.#cleanup.catch(() => void 0).then(async () => {
|
|
32649
|
+
await mkdir(this.#root, { mode: 448, recursive: true });
|
|
32650
|
+
const now = /* @__PURE__ */ new Date();
|
|
32651
|
+
await utimes(this.#root, now, now);
|
|
32652
|
+
for (const directory of await readdir2(dirname2(this.#root), { withFileTypes: true })) {
|
|
32653
|
+
if (!directory.isDirectory() || !/^[a-f0-9-]{36}$/u.test(directory.name)) {
|
|
32654
|
+
continue;
|
|
32655
|
+
}
|
|
32656
|
+
const path2 = join4(dirname2(this.#root), directory.name);
|
|
32657
|
+
if (path2 === this.#root) {
|
|
32658
|
+
continue;
|
|
32659
|
+
}
|
|
32660
|
+
const modified = await stat3(path2).then(
|
|
32661
|
+
(entry) => entry.mtimeMs,
|
|
32662
|
+
() => Date.now()
|
|
32663
|
+
);
|
|
32664
|
+
if (modified + CONTENT_LIFETIME_MILLISECONDS <= Date.now()) {
|
|
32665
|
+
await rm(path2, { force: true, recursive: true });
|
|
32666
|
+
}
|
|
32667
|
+
}
|
|
32668
|
+
for (const [request, entry] of this.#entries) {
|
|
32669
|
+
if (entry.expiresAt > Date.now()) {
|
|
32670
|
+
continue;
|
|
32671
|
+
}
|
|
32672
|
+
await rm(entry.path, { force: true });
|
|
32673
|
+
this.#entries.delete(request);
|
|
32674
|
+
}
|
|
32675
|
+
});
|
|
32676
|
+
return this.#cleanup;
|
|
32677
|
+
};
|
|
32678
|
+
#track = async (operation) => {
|
|
32679
|
+
this.#lifetime.signal.throwIfAborted();
|
|
32680
|
+
const pending = operation();
|
|
32681
|
+
this.#operations.add(pending);
|
|
32682
|
+
try {
|
|
32683
|
+
return await pending;
|
|
32684
|
+
} finally {
|
|
32685
|
+
this.#operations.delete(pending);
|
|
32686
|
+
}
|
|
32687
|
+
};
|
|
32688
|
+
put = (input2) => this.#track(() => this.#put(input2));
|
|
32689
|
+
#put = async ({ bytes, kind, mediaType, name, sessionId, signal }) => {
|
|
32690
|
+
const active = AbortSignal.any([signal, this.#lifetime.signal]);
|
|
32691
|
+
active.throwIfAborted();
|
|
32692
|
+
const metadata = metadataSchema2.parse({ kind, mediaType, name });
|
|
32693
|
+
const key = createHash("sha256").update(bytes).digest("hex");
|
|
32694
|
+
const request = `mobius-content:${kind}:${key}`;
|
|
32695
|
+
const existing = this.#entries.get(request);
|
|
32696
|
+
if (existing !== void 0 && existing.expiresAt > Date.now()) {
|
|
32697
|
+
this.#entries.set(request, {
|
|
32698
|
+
...existing,
|
|
32699
|
+
expiresAt: Date.now() + CONTENT_LIFETIME_MILLISECONDS,
|
|
32700
|
+
sessions: /* @__PURE__ */ new Set([...existing.sessions, sessionId])
|
|
32701
|
+
});
|
|
32702
|
+
return { byteLength: existing.byteLength, key };
|
|
32703
|
+
}
|
|
32704
|
+
await this.#expire();
|
|
32705
|
+
active.throwIfAborted();
|
|
32706
|
+
const directory = join4(this.#root, kind);
|
|
32707
|
+
await mkdir(directory, { mode: 448, recursive: true });
|
|
32708
|
+
active.throwIfAborted();
|
|
32709
|
+
const path2 = join4(directory, key);
|
|
32710
|
+
const write = atomicWrite(path2, bytes, active);
|
|
32711
|
+
await write;
|
|
32712
|
+
active.throwIfAborted();
|
|
32713
|
+
const retained = this.#entries.get(request);
|
|
32714
|
+
this.#entries.set(request, {
|
|
32715
|
+
byteLength: bytes.byteLength,
|
|
32716
|
+
expiresAt: Date.now() + CONTENT_LIFETIME_MILLISECONDS,
|
|
32717
|
+
mediaType: metadata.mediaType,
|
|
32718
|
+
name: metadata.name,
|
|
32719
|
+
path: path2,
|
|
32720
|
+
sessions: /* @__PURE__ */ new Set([...retained?.sessions ?? [], sessionId])
|
|
32721
|
+
});
|
|
32722
|
+
return { byteLength: bytes.byteLength, key };
|
|
32723
|
+
};
|
|
32724
|
+
resolve = (sessionId, request, signal) => this.#track(() => this.#resolve(sessionId, request, AbortSignal.any([signal, this.#lifetime.signal])));
|
|
32725
|
+
#resolve = async (sessionId, request, signal) => {
|
|
32726
|
+
signal.throwIfAborted();
|
|
32727
|
+
this.#lifetime.signal.throwIfAborted();
|
|
32728
|
+
if (!contentRequest.test(request)) {
|
|
32729
|
+
return null;
|
|
32730
|
+
}
|
|
32731
|
+
const entry = this.#entries.get(request);
|
|
32732
|
+
if (entry === void 0 || !entry.sessions.has(sessionId)) {
|
|
32733
|
+
return null;
|
|
32734
|
+
}
|
|
32735
|
+
if (entry.expiresAt <= Date.now()) {
|
|
32736
|
+
await this.#expire();
|
|
32737
|
+
signal.throwIfAborted();
|
|
32738
|
+
return null;
|
|
32739
|
+
}
|
|
32740
|
+
try {
|
|
32741
|
+
const [resolvedDirectory, resolvedPath, file2] = await Promise.all([
|
|
32742
|
+
realpath3(dirname2(entry.path)),
|
|
32743
|
+
realpath3(entry.path),
|
|
32744
|
+
lstat(entry.path)
|
|
32745
|
+
]);
|
|
32746
|
+
signal.throwIfAborted();
|
|
32747
|
+
if (!file2.isFile() || file2.isSymbolicLink() || dirname2(resolvedPath) !== resolvedDirectory) {
|
|
32748
|
+
return null;
|
|
32749
|
+
}
|
|
32750
|
+
return { mediaType: entry.mediaType, name: entry.name, path: resolvedPath };
|
|
32751
|
+
} catch {
|
|
32752
|
+
signal.throwIfAborted();
|
|
32753
|
+
return null;
|
|
32754
|
+
}
|
|
32755
|
+
};
|
|
32756
|
+
[Symbol.asyncDispose] = async () => {
|
|
32757
|
+
clearInterval(this.#expirationTimer);
|
|
32758
|
+
this.#lifetime.abort();
|
|
32759
|
+
await Promise.allSettled([...this.#operations, this.#cleanup]);
|
|
32760
|
+
this.#entries.clear();
|
|
32761
|
+
await rm(this.#root, { force: true, recursive: true });
|
|
32762
|
+
};
|
|
32763
|
+
};
|
|
32764
|
+
|
|
32331
32765
|
// src/native-sessions/chat-agent.ts
|
|
32332
32766
|
function supportsNativeChat(agentId) {
|
|
32333
32767
|
return agentId === "codex" || agentId === "claude" || agentId === "opencode" || agentId === "pi";
|
|
@@ -32544,7 +32978,7 @@ var AgentRuntimeManager = class {
|
|
|
32544
32978
|
touch: this.#processes.touch,
|
|
32545
32979
|
changed: this.#processes.notifyChanged
|
|
32546
32980
|
});
|
|
32547
|
-
#queryProcesses
|
|
32981
|
+
#queryProcesses;
|
|
32548
32982
|
#executions = new ActiveExecutions();
|
|
32549
32983
|
#agentSettingsObserver = new NullAcpSessionObserver();
|
|
32550
32984
|
#nativeOperations = /* @__PURE__ */ new Set();
|
|
@@ -32552,13 +32986,16 @@ var AgentRuntimeManager = class {
|
|
|
32552
32986
|
#nativeHistoryReader;
|
|
32553
32987
|
#sessionIdentity;
|
|
32554
32988
|
#onSessionStatusChanged;
|
|
32989
|
+
#contentExternalizer;
|
|
32555
32990
|
#observer;
|
|
32556
|
-
constructor(observer = new NullAcpSessionObserver(), store = new MemoryAcpSessionStore(), nativeHistoryReader = null, sessionIdentity = "assigned", onSessionStatusChanged = () => void 0) {
|
|
32991
|
+
constructor(observer = new NullAcpSessionObserver(), store = new MemoryAcpSessionStore(), nativeHistoryReader = null, sessionIdentity = "assigned", onSessionStatusChanged = () => void 0, contentExternalizer = new AcpContentExternalizer(new UnretainedExternalContentStore())) {
|
|
32557
32992
|
this.#observer = observer;
|
|
32558
32993
|
this.#store = store;
|
|
32559
32994
|
this.#nativeHistoryReader = nativeHistoryReader;
|
|
32560
32995
|
this.#sessionIdentity = sessionIdentity;
|
|
32561
32996
|
this.#onSessionStatusChanged = onSessionStatusChanged;
|
|
32997
|
+
this.#contentExternalizer = contentExternalizer;
|
|
32998
|
+
this.#queryProcesses = new AgentQueryProcesses(this.#processes, contentExternalizer);
|
|
32562
32999
|
}
|
|
32563
33000
|
setObserver = (observer) => {
|
|
32564
33001
|
this.#observer = observer;
|
|
@@ -32599,7 +33036,8 @@ var AgentRuntimeManager = class {
|
|
|
32599
33036
|
options.origin === void 0 && this.#sessionIdentity === "native" && isNativeChatSessionId(options.agent.id, options.sessionId) && this.#store.read(options.sessionId) instanceof MissingAcpStoredSession ? { ...options, origin: { kind: "import", nativeSessionId: options.sessionId } } : options,
|
|
32600
33037
|
() => this.#observer,
|
|
32601
33038
|
this.#store,
|
|
32602
|
-
metrics
|
|
33039
|
+
metrics,
|
|
33040
|
+
this.#contentExternalizer
|
|
32603
33041
|
)
|
|
32604
33042
|
);
|
|
32605
33043
|
});
|
|
@@ -32614,7 +33052,13 @@ var AgentRuntimeManager = class {
|
|
|
32614
33052
|
this.#store.remove(options.sessionId);
|
|
32615
33053
|
return await this.#startRetainedSessionProcess(
|
|
32616
33054
|
options,
|
|
32617
|
-
async () => await AgentSession.start(
|
|
33055
|
+
async () => await AgentSession.start(
|
|
33056
|
+
options,
|
|
33057
|
+
() => this.#observer,
|
|
33058
|
+
this.#store,
|
|
33059
|
+
metrics,
|
|
33060
|
+
this.#contentExternalizer
|
|
33061
|
+
)
|
|
32618
33062
|
);
|
|
32619
33063
|
});
|
|
32620
33064
|
}
|
|
@@ -32624,7 +33068,13 @@ var AgentRuntimeManager = class {
|
|
|
32624
33068
|
await this.#retireSessionProcess(options.sessionId, existing, async () => await existing.close());
|
|
32625
33069
|
const runtime = await this.#startRetainedSessionProcess(
|
|
32626
33070
|
options,
|
|
32627
|
-
async () => await AgentSession.start(
|
|
33071
|
+
async () => await AgentSession.start(
|
|
33072
|
+
options,
|
|
33073
|
+
() => this.#observer,
|
|
33074
|
+
this.#store,
|
|
33075
|
+
unmeasuredOperationMetrics,
|
|
33076
|
+
this.#contentExternalizer
|
|
33077
|
+
)
|
|
32628
33078
|
);
|
|
32629
33079
|
try {
|
|
32630
33080
|
for (const desired of desiredConfigOptions) {
|
|
@@ -32720,7 +33170,9 @@ var AgentRuntimeManager = class {
|
|
|
32720
33170
|
sessionId: `agent-settings-${crypto.randomUUID()}`
|
|
32721
33171
|
},
|
|
32722
33172
|
() => this.#agentSettingsObserver,
|
|
32723
|
-
new MemoryAcpSessionStore()
|
|
33173
|
+
new MemoryAcpSessionStore(),
|
|
33174
|
+
unmeasuredOperationMetrics,
|
|
33175
|
+
this.#contentExternalizer
|
|
32724
33176
|
),
|
|
32725
33177
|
async (runtime) => {
|
|
32726
33178
|
const prepared = runtime.prepared();
|
|
@@ -33250,7 +33702,7 @@ var LocalAuthorizationError = class extends Error {
|
|
|
33250
33702
|
};
|
|
33251
33703
|
|
|
33252
33704
|
// src/pairing/pair-local-machine.ts
|
|
33253
|
-
import { mkdir as
|
|
33705
|
+
import { mkdir as mkdir6, realpath as realpath8, stat as stat7 } from "node:fs/promises";
|
|
33254
33706
|
import { hostname as hostname3 } from "node:os";
|
|
33255
33707
|
import { basename as basename3, resolve as resolve5 } from "node:path";
|
|
33256
33708
|
import { fetch as fetch2 } from "undici";
|
|
@@ -33395,8 +33847,8 @@ var LocalAgentInventory = class {
|
|
|
33395
33847
|
};
|
|
33396
33848
|
|
|
33397
33849
|
// src/agent-installation/managed-npm-package.ts
|
|
33398
|
-
import { mkdir, mkdtemp, open as open3, realpath as
|
|
33399
|
-
import { delimiter, dirname as
|
|
33850
|
+
import { mkdir as mkdir2, mkdtemp, open as open3, realpath as realpath4, rename as rename2, rm as rm2, stat as stat4 } from "node:fs/promises";
|
|
33851
|
+
import { delimiter, dirname as dirname3, isAbsolute as isAbsolute2, join as join5, relative, sep } from "node:path";
|
|
33400
33852
|
var INSTALL_TIMEOUT_MILLISECONDS = 5 * 60 * 1e3;
|
|
33401
33853
|
var PACKAGE_METADATA_LIMIT_BYTES = 64 * 1024;
|
|
33402
33854
|
var PACKAGE_LOCK_LIMIT_BYTES = 8 * 1024 * 1024;
|
|
@@ -33443,11 +33895,11 @@ var ManagedNpmPackageError = class extends Error {
|
|
|
33443
33895
|
this.name = "ManagedNpmPackageError";
|
|
33444
33896
|
}
|
|
33445
33897
|
};
|
|
33446
|
-
function
|
|
33898
|
+
function isRecord7(value) {
|
|
33447
33899
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
33448
33900
|
}
|
|
33449
33901
|
function packagePath(root, packageName) {
|
|
33450
|
-
return
|
|
33902
|
+
return join5(root, "node_modules", ...packageName.split("/"));
|
|
33451
33903
|
}
|
|
33452
33904
|
function isContainedPath(root, candidate) {
|
|
33453
33905
|
const difference = relative(root, candidate);
|
|
@@ -33465,7 +33917,7 @@ async function readJsonRecord(path2, maximumBytes) {
|
|
|
33465
33917
|
);
|
|
33466
33918
|
}
|
|
33467
33919
|
const value = JSON.parse(await handle.readFile({ encoding: "utf8" }));
|
|
33468
|
-
if (!
|
|
33920
|
+
if (!isRecord7(value)) {
|
|
33469
33921
|
throw new ManagedNpmPackageError(
|
|
33470
33922
|
"managed_package_verification_failed",
|
|
33471
33923
|
"The managed npm package metadata is invalid"
|
|
@@ -33491,7 +33943,7 @@ function readBinPath(packageMetadata, executableName) {
|
|
|
33491
33943
|
if (typeof bin === "string") {
|
|
33492
33944
|
return bin;
|
|
33493
33945
|
}
|
|
33494
|
-
if (
|
|
33946
|
+
if (isRecord7(bin) && typeof bin[executableName] === "string") {
|
|
33495
33947
|
return bin[executableName];
|
|
33496
33948
|
}
|
|
33497
33949
|
throw new ManagedNpmPackageError(
|
|
@@ -33507,7 +33959,7 @@ function verifyPackageLockEntry(lock, definition, verifyDependencyClosure) {
|
|
|
33507
33959
|
);
|
|
33508
33960
|
}
|
|
33509
33961
|
const packages = lock["packages"];
|
|
33510
|
-
if (!
|
|
33962
|
+
if (!isRecord7(packages)) {
|
|
33511
33963
|
throw new ManagedNpmPackageError(
|
|
33512
33964
|
"managed_package_verification_failed",
|
|
33513
33965
|
"The managed npm package lockfile is invalid"
|
|
@@ -33521,7 +33973,7 @@ function verifyPackageLockEntry(lock, definition, verifyDependencyClosure) {
|
|
|
33521
33973
|
if (verifyDependencyClosure && normalizedKey.length > 0) {
|
|
33522
33974
|
let resolved;
|
|
33523
33975
|
try {
|
|
33524
|
-
if (!normalizedKey.split("/").includes("node_modules") || !
|
|
33976
|
+
if (!normalizedKey.split("/").includes("node_modules") || !isRecord7(candidate) || typeof candidate["version"] !== "string" || candidate["version"].length === 0 || typeof candidate["integrity"] !== "string" || !/^sha512-[A-Za-z0-9+/]{86}==$/.test(candidate["integrity"]) || typeof candidate["resolved"] !== "string") {
|
|
33525
33977
|
throw new Error("Invalid locked dependency");
|
|
33526
33978
|
}
|
|
33527
33979
|
resolved = new URL(candidate["resolved"]);
|
|
@@ -33544,7 +33996,7 @@ function verifyPackageLockEntry(lock, definition, verifyDependencyClosure) {
|
|
|
33544
33996
|
matches += 1;
|
|
33545
33997
|
}
|
|
33546
33998
|
}
|
|
33547
|
-
if (matches !== 1 || !
|
|
33999
|
+
if (matches !== 1 || !isRecord7(entry) || entry["integrity"] !== definition.integrity || entry["resolved"] !== definition.tarballUrl || entry["version"] !== definition.version) {
|
|
33548
34000
|
throw new ManagedNpmPackageError(
|
|
33549
34001
|
"managed_package_verification_failed",
|
|
33550
34002
|
"The managed npm package lockfile does not match the pinned artifact"
|
|
@@ -33552,14 +34004,14 @@ function verifyPackageLockEntry(lock, definition, verifyDependencyClosure) {
|
|
|
33552
34004
|
}
|
|
33553
34005
|
}
|
|
33554
34006
|
async function verifyRequiredDependency(rootPath, lock, definition) {
|
|
33555
|
-
const dependencyRoot = await
|
|
34007
|
+
const dependencyRoot = await realpath4(packagePath(rootPath, definition.packageName));
|
|
33556
34008
|
if (!isContainedPath(rootPath, dependencyRoot)) {
|
|
33557
34009
|
throw new ManagedNpmPackageError(
|
|
33558
34010
|
"managed_package_verification_failed",
|
|
33559
34011
|
"The required managed npm dependency escaped its private cache"
|
|
33560
34012
|
);
|
|
33561
34013
|
}
|
|
33562
|
-
const metadata = await readJsonRecord(
|
|
34014
|
+
const metadata = await readJsonRecord(join5(dependencyRoot, "package.json"), PACKAGE_METADATA_LIMIT_BYTES);
|
|
33563
34015
|
if (metadata["name"] !== definition.packageName || metadata["version"] !== definition.version) {
|
|
33564
34016
|
throw new ManagedNpmPackageError(
|
|
33565
34017
|
"managed_package_verification_failed",
|
|
@@ -33581,15 +34033,15 @@ async function validateManagedNpmPackage(root, definition) {
|
|
|
33581
34033
|
}
|
|
33582
34034
|
}
|
|
33583
34035
|
async function validateManagedNpmPackageContents(root, definition) {
|
|
33584
|
-
const rootPath = await
|
|
33585
|
-
const packageRoot = await
|
|
34036
|
+
const rootPath = await realpath4(root);
|
|
34037
|
+
const packageRoot = await realpath4(packagePath(rootPath, definition.packageName));
|
|
33586
34038
|
if (!isContainedPath(rootPath, packageRoot)) {
|
|
33587
34039
|
throw new ManagedNpmPackageError(
|
|
33588
34040
|
"managed_package_verification_failed",
|
|
33589
34041
|
"The managed npm package escaped its private cache"
|
|
33590
34042
|
);
|
|
33591
34043
|
}
|
|
33592
|
-
const metadata = await readJsonRecord(
|
|
34044
|
+
const metadata = await readJsonRecord(join5(packageRoot, "package.json"), PACKAGE_METADATA_LIMIT_BYTES);
|
|
33593
34045
|
if (metadata["name"] !== definition.packageName || metadata["version"] !== definition.version) {
|
|
33594
34046
|
throw new ManagedNpmPackageError(
|
|
33595
34047
|
"managed_package_verification_failed",
|
|
@@ -33597,14 +34049,14 @@ async function validateManagedNpmPackageContents(root, definition) {
|
|
|
33597
34049
|
);
|
|
33598
34050
|
}
|
|
33599
34051
|
if (definition instanceof SriManagedNpmPackageDefinition) {
|
|
33600
|
-
const lock = await readJsonRecord(
|
|
34052
|
+
const lock = await readJsonRecord(join5(rootPath, "package-lock.json"), PACKAGE_LOCK_LIMIT_BYTES);
|
|
33601
34053
|
verifyPackageLockEntry(lock, definition, definition.verifyDependencyClosure);
|
|
33602
34054
|
for (const dependency of definition.requiredDependencies) {
|
|
33603
34055
|
await verifyRequiredDependency(rootPath, lock, dependency);
|
|
33604
34056
|
}
|
|
33605
34057
|
}
|
|
33606
34058
|
const declaredBin = readBinPath(metadata, definition.executableName);
|
|
33607
|
-
const executable = await resolveExecutablePath(
|
|
34059
|
+
const executable = await resolveExecutablePath(join5(packageRoot, declaredBin));
|
|
33608
34060
|
if (executable === null || !isContainedPath(rootPath, executable.path)) {
|
|
33609
34061
|
throw new ManagedNpmPackageError(
|
|
33610
34062
|
"managed_package_verification_failed",
|
|
@@ -33617,7 +34069,7 @@ var ManagedNpmPackageInstaller = class {
|
|
|
33617
34069
|
install = async (root, definition, environment, signal) => {
|
|
33618
34070
|
signal.throwIfAborted();
|
|
33619
34071
|
try {
|
|
33620
|
-
const metadata = await
|
|
34072
|
+
const metadata = await stat4(root);
|
|
33621
34073
|
if (metadata.isDirectory()) {
|
|
33622
34074
|
return await validateManagedNpmPackage(root, definition);
|
|
33623
34075
|
}
|
|
@@ -33626,9 +34078,9 @@ var ManagedNpmPackageInstaller = class {
|
|
|
33626
34078
|
throw error62;
|
|
33627
34079
|
}
|
|
33628
34080
|
}
|
|
33629
|
-
const parent =
|
|
33630
|
-
await
|
|
33631
|
-
const staging = await mkdtemp(
|
|
34081
|
+
const parent = dirname3(root);
|
|
34082
|
+
await mkdir2(parent, { mode: 448, recursive: true });
|
|
34083
|
+
const staging = await mkdtemp(join5(parent, `.${definition.version}.staging-`));
|
|
33632
34084
|
try {
|
|
33633
34085
|
const npm = await findExecutableOnPath(process.platform === "win32" ? "npm.cmd" : "npm", environment);
|
|
33634
34086
|
if (npm === null) {
|
|
@@ -33654,14 +34106,14 @@ var ManagedNpmPackageInstaller = class {
|
|
|
33654
34106
|
`${definition.packageName}@${definition.version}`
|
|
33655
34107
|
);
|
|
33656
34108
|
const installEnvironment = {
|
|
33657
|
-
HOME:
|
|
34109
|
+
HOME: join5(staging, "home"),
|
|
33658
34110
|
NPM_CONFIG_AUDIT: "false",
|
|
33659
|
-
NPM_CONFIG_CACHE:
|
|
34111
|
+
NPM_CONFIG_CACHE: join5(staging, ".npm-cache"),
|
|
33660
34112
|
NPM_CONFIG_FUND: "false",
|
|
33661
34113
|
NPM_CONFIG_IGNORE_SCRIPTS: "true",
|
|
33662
34114
|
NPM_CONFIG_PACKAGE_LOCK: "true",
|
|
33663
34115
|
NPM_CONFIG_REGISTRY: "https://registry.npmjs.org/",
|
|
33664
|
-
PATH: `${
|
|
34116
|
+
PATH: `${dirname3(process.execPath)}${delimiter}/usr/bin${delimiter}/bin`
|
|
33665
34117
|
};
|
|
33666
34118
|
if (definition.includeOptionalDependencies) {
|
|
33667
34119
|
installEnvironment["NPM_CONFIG_INCLUDE"] = "optional";
|
|
@@ -33678,12 +34130,12 @@ var ManagedNpmPackageInstaller = class {
|
|
|
33678
34130
|
timeoutMilliseconds: INSTALL_TIMEOUT_MILLISECONDS
|
|
33679
34131
|
});
|
|
33680
34132
|
await Promise.all([
|
|
33681
|
-
|
|
33682
|
-
|
|
34133
|
+
rm2(join5(staging, ".npm-cache"), { force: true, recursive: true }),
|
|
34134
|
+
rm2(join5(staging, "home"), { force: true, recursive: true })
|
|
33683
34135
|
]);
|
|
33684
34136
|
await validateManagedNpmPackage(staging, definition);
|
|
33685
34137
|
try {
|
|
33686
|
-
await
|
|
34138
|
+
await rename2(staging, root);
|
|
33687
34139
|
} catch (error62) {
|
|
33688
34140
|
try {
|
|
33689
34141
|
return await validateManagedNpmPackage(root, definition);
|
|
@@ -33709,13 +34161,13 @@ var ManagedNpmPackageInstaller = class {
|
|
|
33709
34161
|
{ cause: error62 }
|
|
33710
34162
|
);
|
|
33711
34163
|
} finally {
|
|
33712
|
-
await
|
|
34164
|
+
await rm2(staging, { force: true, recursive: true });
|
|
33713
34165
|
}
|
|
33714
34166
|
};
|
|
33715
34167
|
};
|
|
33716
34168
|
|
|
33717
34169
|
// src/agent-catalog/agent-specification.ts
|
|
33718
|
-
import { join as
|
|
34170
|
+
import { join as join6 } from "node:path";
|
|
33719
34171
|
|
|
33720
34172
|
// src/agent-catalog/version-output.ts
|
|
33721
34173
|
function normalizeVersionOutput(output2) {
|
|
@@ -33738,7 +34190,7 @@ var LocalAgentSpecification = class {
|
|
|
33738
34190
|
resolveManagedAgent = async (stateDirectory, platform, signal) => {
|
|
33739
34191
|
signal.throwIfAborted();
|
|
33740
34192
|
const executable = await resolveExecutablePath(
|
|
33741
|
-
|
|
34193
|
+
join6(stateDirectory, ...this.managedAgentExecutablePath),
|
|
33742
34194
|
platform
|
|
33743
34195
|
);
|
|
33744
34196
|
signal.throwIfAborted();
|
|
@@ -35664,7 +36116,7 @@ var AgentProbeError = class extends Error {
|
|
|
35664
36116
|
};
|
|
35665
36117
|
|
|
35666
36118
|
// src/agent-catalog/agents/resolve-user-local-executable.ts
|
|
35667
|
-
import { isAbsolute as isAbsolute3, join as
|
|
36119
|
+
import { isAbsolute as isAbsolute3, join as join7 } from "node:path";
|
|
35668
36120
|
async function resolveUserLocalExecutable(executableName, context) {
|
|
35669
36121
|
context.signal.throwIfAborted();
|
|
35670
36122
|
const platform = context.platform ?? process.platform;
|
|
@@ -35672,7 +36124,7 @@ async function resolveUserLocalExecutable(executableName, context) {
|
|
|
35672
36124
|
if (platform === "win32" || homeDirectory === void 0 || !isAbsolute3(homeDirectory)) {
|
|
35673
36125
|
return [];
|
|
35674
36126
|
}
|
|
35675
|
-
const executable = await resolveExecutablePath(
|
|
36127
|
+
const executable = await resolveExecutablePath(join7(homeDirectory, ".local", "bin", executableName), platform);
|
|
35676
36128
|
context.signal.throwIfAborted();
|
|
35677
36129
|
return executable === null ? [] : [executable];
|
|
35678
36130
|
}
|
|
@@ -35761,8 +36213,8 @@ var CursorCliAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
35761
36213
|
};
|
|
35762
36214
|
|
|
35763
36215
|
// src/agent-catalog/agents/deepseek-harness-agent.ts
|
|
35764
|
-
import { mkdir as
|
|
35765
|
-
import { isAbsolute as isAbsolute4, join as
|
|
36216
|
+
import { mkdir as mkdir3, realpath as realpath5, stat as stat5, writeFile as writeFile2 } from "node:fs/promises";
|
|
36217
|
+
import { isAbsolute as isAbsolute4, join as join8, normalize as normalize2 } from "node:path";
|
|
35766
36218
|
|
|
35767
36219
|
// src/agent-installation/deepseek-managed-package.ts
|
|
35768
36220
|
var DeepSeekHarnessManagedPackage = class extends SriManagedNpmPackageDefinition {
|
|
@@ -35791,15 +36243,15 @@ async function prepareAgentHome(path2, imagePrompts) {
|
|
|
35791
36243
|
}
|
|
35792
36244
|
try {
|
|
35793
36245
|
if (imagePrompts) {
|
|
35794
|
-
await
|
|
36246
|
+
await mkdir3(path2, { mode: 448, recursive: true });
|
|
35795
36247
|
}
|
|
35796
|
-
const resolved = await
|
|
35797
|
-
const metadata = await
|
|
36248
|
+
const resolved = await realpath5(path2);
|
|
36249
|
+
const metadata = await stat5(resolved);
|
|
35798
36250
|
if (!metadata.isDirectory() || typeof process.getuid === "function" && metadata.uid !== process.getuid()) {
|
|
35799
36251
|
throw new Error("Agent home is not a user-owned directory");
|
|
35800
36252
|
}
|
|
35801
36253
|
if (imagePrompts) {
|
|
35802
|
-
await
|
|
36254
|
+
await writeFile2(join8(resolved, "cordis.patch.yml"), DEEPSEEK_HARNESS_IMAGE_PROMPT_PATCH, {
|
|
35803
36255
|
mode: 384
|
|
35804
36256
|
});
|
|
35805
36257
|
}
|
|
@@ -35847,7 +36299,7 @@ var DeepSeekHarnessAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
35847
36299
|
context.signal
|
|
35848
36300
|
);
|
|
35849
36301
|
if (managed.path === agent.path) {
|
|
35850
|
-
selectedHome =
|
|
36302
|
+
selectedHome = join8(readStateDirectory(context.environment), "agents", this.id, "home");
|
|
35851
36303
|
managedHome = true;
|
|
35852
36304
|
}
|
|
35853
36305
|
} catch {
|
|
@@ -35863,7 +36315,7 @@ var DeepSeekHarnessAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
35863
36315
|
resolveManagedAgent = async (stateDirectory, _platform, signal) => {
|
|
35864
36316
|
signal.throwIfAborted();
|
|
35865
36317
|
const executable = await validateManagedNpmPackage(
|
|
35866
|
-
|
|
36318
|
+
join8(stateDirectory, "agents", this.id, DEEPSEEK_HARNESS_PACKAGE.version),
|
|
35867
36319
|
DEEPSEEK_HARNESS_PACKAGE
|
|
35868
36320
|
);
|
|
35869
36321
|
signal.throwIfAborted();
|
|
@@ -35917,8 +36369,8 @@ var GeminiCliAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
35917
36369
|
};
|
|
35918
36370
|
|
|
35919
36371
|
// src/agent-catalog/agents/grok-build-agent.ts
|
|
35920
|
-
import { realpath as
|
|
35921
|
-
import { isAbsolute as isAbsolute5, join as
|
|
36372
|
+
import { realpath as realpath6 } from "node:fs/promises";
|
|
36373
|
+
import { isAbsolute as isAbsolute5, join as join9, relative as relative2, sep as sep2 } from "node:path";
|
|
35922
36374
|
import {
|
|
35923
36375
|
RequestError as RequestError2
|
|
35924
36376
|
} from "@agentclientprotocol/sdk";
|
|
@@ -36013,8 +36465,8 @@ var GrokBuildAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
36013
36465
|
);
|
|
36014
36466
|
if (managed.path === agent.path) {
|
|
36015
36467
|
return Object.freeze({
|
|
36016
|
-
GROK_HOME: await
|
|
36017
|
-
|
|
36468
|
+
GROK_HOME: await realpath6(
|
|
36469
|
+
join9(stateDirectory, "agents", this.id, GROK_BUILD_MANAGED_VERSION, "home")
|
|
36018
36470
|
)
|
|
36019
36471
|
});
|
|
36020
36472
|
}
|
|
@@ -36025,9 +36477,9 @@ var GrokBuildAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
36025
36477
|
};
|
|
36026
36478
|
resolveManagedAgent = async (stateDirectory, platform, signal) => {
|
|
36027
36479
|
signal.throwIfAborted();
|
|
36028
|
-
const versionRoot = await
|
|
36029
|
-
await validateManagedNpmPackage(
|
|
36030
|
-
const executable = await resolveExecutablePath(
|
|
36480
|
+
const versionRoot = await realpath6(join9(stateDirectory, "agents", this.id, GROK_BUILD_MANAGED_VERSION));
|
|
36481
|
+
await validateManagedNpmPackage(join9(versionRoot, "package"), grokBuildManagedPackage(platform, process.arch));
|
|
36482
|
+
const executable = await resolveExecutablePath(join9(versionRoot, "home", "bin", "grok"), platform);
|
|
36031
36483
|
signal.throwIfAborted();
|
|
36032
36484
|
if (executable === null || !isContainedPath2(versionRoot, executable.path)) {
|
|
36033
36485
|
throw new AgentProbeError("managed_agent_invalid", "The managed Grok Build executable is invalid");
|
|
@@ -36127,13 +36579,13 @@ var OhMyPiAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
36127
36579
|
};
|
|
36128
36580
|
|
|
36129
36581
|
// src/agent-catalog/agents/opencode-agent.ts
|
|
36130
|
-
import { join as
|
|
36582
|
+
import { join as join11 } from "node:path";
|
|
36131
36583
|
|
|
36132
36584
|
// src/agent-installation/managed-agent-archive.ts
|
|
36133
|
-
import { createHash } from "node:crypto";
|
|
36585
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
36134
36586
|
import { createReadStream } from "node:fs";
|
|
36135
|
-
import { chmod, copyFile, mkdir as
|
|
36136
|
-
import { delimiter as delimiter2, dirname as
|
|
36587
|
+
import { chmod, copyFile, mkdir as mkdir4, mkdtemp as mkdtemp2, open as open4, realpath as realpath7, rename as rename3, rm as rm3, stat as stat6, writeFile as writeFile3 } from "node:fs/promises";
|
|
36588
|
+
import { delimiter as delimiter2, dirname as dirname4, isAbsolute as isAbsolute6, join as join10, relative as relative3, sep as sep3 } from "node:path";
|
|
36137
36589
|
|
|
36138
36590
|
// src/agent-installation/verified-download.ts
|
|
36139
36591
|
import { fetch } from "undici";
|
|
@@ -36234,7 +36686,7 @@ var ManagedAgentArchiveError = class extends Error {
|
|
|
36234
36686
|
this.name = "ManagedAgentArchiveError";
|
|
36235
36687
|
}
|
|
36236
36688
|
};
|
|
36237
|
-
function
|
|
36689
|
+
function isRecord8(value) {
|
|
36238
36690
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
36239
36691
|
}
|
|
36240
36692
|
function isContainedPath3(root, candidate) {
|
|
@@ -36243,7 +36695,7 @@ function isContainedPath3(root, candidate) {
|
|
|
36243
36695
|
}
|
|
36244
36696
|
async function hashFile(path2, signal) {
|
|
36245
36697
|
signal.throwIfAborted();
|
|
36246
|
-
const digest =
|
|
36698
|
+
const digest = createHash2("sha256");
|
|
36247
36699
|
const stream = createReadStream(path2, { signal });
|
|
36248
36700
|
try {
|
|
36249
36701
|
for await (const chunk of stream) {
|
|
@@ -36291,7 +36743,7 @@ async function readManifest(path2) {
|
|
|
36291
36743
|
);
|
|
36292
36744
|
}
|
|
36293
36745
|
const parsed = JSON.parse(await handle.readFile({ encoding: "utf8" }));
|
|
36294
|
-
if (!
|
|
36746
|
+
if (!isRecord8(parsed)) {
|
|
36295
36747
|
throw new ManagedAgentArchiveError(
|
|
36296
36748
|
"managed_archive_verification_failed",
|
|
36297
36749
|
"The managed Agent archive manifest is invalid"
|
|
@@ -36313,16 +36765,16 @@ async function readManifest(path2) {
|
|
|
36313
36765
|
}
|
|
36314
36766
|
async function validateManagedAgentArchive(root, definition, signal) {
|
|
36315
36767
|
try {
|
|
36316
|
-
const rootPath = await
|
|
36317
|
-
const rootMetadata = await
|
|
36768
|
+
const rootPath = await realpath7(root);
|
|
36769
|
+
const rootMetadata = await stat6(rootPath);
|
|
36318
36770
|
if (!rootMetadata.isDirectory() || typeof process.getuid === "function" && rootMetadata.uid !== process.getuid()) {
|
|
36319
36771
|
throw new Error("Managed Agent root is not user-owned");
|
|
36320
36772
|
}
|
|
36321
|
-
const manifest = await readManifest(
|
|
36773
|
+
const manifest = await readManifest(join10(rootPath, "archive.json"));
|
|
36322
36774
|
if (manifest["archiveSha256"] !== definition.archiveSha256 || manifest["archiveUrl"] !== definition.archiveUrl.toString() || manifest["version"] !== definition.version || typeof manifest["executableSha256"] !== "string") {
|
|
36323
36775
|
throw new Error("Managed Agent archive identity is invalid");
|
|
36324
36776
|
}
|
|
36325
|
-
const executable = await resolveExecutablePath(
|
|
36777
|
+
const executable = await resolveExecutablePath(join10(rootPath, "bin", definition.executableName));
|
|
36326
36778
|
if (executable === null || !isContainedPath3(rootPath, executable.path) || await hashFile(executable.path, signal) !== manifest["executableSha256"]) {
|
|
36327
36779
|
throw new Error("Managed Agent executable is invalid");
|
|
36328
36780
|
}
|
|
@@ -36514,7 +36966,7 @@ var OpenCodeAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
36514
36966
|
return Object.freeze(environment);
|
|
36515
36967
|
};
|
|
36516
36968
|
resolveManagedAgent = async (stateDirectory, platform, signal) => await validateManagedAgentArchive(
|
|
36517
|
-
|
|
36969
|
+
join11(stateDirectory, "agents", this.id, OPENCODE_MANAGED_VERSION),
|
|
36518
36970
|
openCodeManagedArchive(platform, process.arch),
|
|
36519
36971
|
signal
|
|
36520
36972
|
);
|
|
@@ -36532,7 +36984,7 @@ var OpenCodeAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
36532
36984
|
};
|
|
36533
36985
|
|
|
36534
36986
|
// src/agent-catalog/agents/pi-agent.ts
|
|
36535
|
-
import { join as
|
|
36987
|
+
import { join as join12 } from "node:path";
|
|
36536
36988
|
import {
|
|
36537
36989
|
methods as methods7
|
|
36538
36990
|
} from "@agentclientprotocol/sdk";
|
|
@@ -36591,7 +37043,7 @@ var PiAgentSpecification = class extends BridgedAcpAgentDefinition {
|
|
|
36591
37043
|
resolveManagedAgent = async (stateDirectory, _platform, signal) => {
|
|
36592
37044
|
signal.throwIfAborted();
|
|
36593
37045
|
const executable = await validateManagedNpmPackage(
|
|
36594
|
-
|
|
37046
|
+
join12(stateDirectory, "agents", this.id, PI_AGENT_PACKAGE.version),
|
|
36595
37047
|
PI_AGENT_PACKAGE
|
|
36596
37048
|
);
|
|
36597
37049
|
signal.throwIfAborted();
|
|
@@ -36629,7 +37081,7 @@ var PiAgentSpecification = class extends BridgedAcpAgentDefinition {
|
|
|
36629
37081
|
};
|
|
36630
37082
|
|
|
36631
37083
|
// src/agent-catalog/agents/workbuddy-agent.ts
|
|
36632
|
-
import { isAbsolute as isAbsolute7, join as
|
|
37084
|
+
import { isAbsolute as isAbsolute7, join as join13 } from "node:path";
|
|
36633
37085
|
|
|
36634
37086
|
// src/agent-installation/workbuddy-managed-package.ts
|
|
36635
37087
|
var WORKBUDDY_MANAGED_VERSION = "2.146.0";
|
|
@@ -36684,7 +37136,7 @@ var WorkBuddyAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
36684
37136
|
resolveManagedAgent = async (stateDirectory, _platform, signal) => {
|
|
36685
37137
|
signal.throwIfAborted();
|
|
36686
37138
|
const executable = await validateManagedNpmPackage(
|
|
36687
|
-
|
|
37139
|
+
join13(stateDirectory, "agents", this.id, WORKBUDDY_MANAGED_VERSION),
|
|
36688
37140
|
WORKBUDDY_MANAGED_PACKAGE
|
|
36689
37141
|
);
|
|
36690
37142
|
signal.throwIfAborted();
|
|
@@ -36695,10 +37147,10 @@ var WorkBuddyAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
36695
37147
|
if ((context.platform ?? process.platform) !== "darwin") {
|
|
36696
37148
|
return [];
|
|
36697
37149
|
}
|
|
36698
|
-
const requestedPaths = [
|
|
37150
|
+
const requestedPaths = [join13("/Applications", ...WORKBUDDY_MACOS_EXECUTABLE_PATH)];
|
|
36699
37151
|
const homeDirectory = context.environment["HOME"];
|
|
36700
37152
|
if (homeDirectory !== void 0 && isAbsolute7(homeDirectory)) {
|
|
36701
|
-
requestedPaths.unshift(
|
|
37153
|
+
requestedPaths.unshift(join13(homeDirectory, "Applications", ...WORKBUDDY_MACOS_EXECUTABLE_PATH));
|
|
36702
37154
|
}
|
|
36703
37155
|
const executables = [];
|
|
36704
37156
|
for (const requestedPath2 of requestedPaths) {
|
|
@@ -37033,10 +37485,10 @@ function isAgentVersionSupported(reportedVersion, minimumSupportedVersion) {
|
|
|
37033
37485
|
}
|
|
37034
37486
|
|
|
37035
37487
|
// src/agent-catalog/executable-discovery.ts
|
|
37036
|
-
import { isAbsolute as isAbsolute8, join as
|
|
37488
|
+
import { isAbsolute as isAbsolute8, join as join15 } from "node:path";
|
|
37037
37489
|
|
|
37038
37490
|
// src/agent-installation/managed-adapter-installer.ts
|
|
37039
|
-
import { join as
|
|
37491
|
+
import { join as join14 } from "node:path";
|
|
37040
37492
|
var ManagedAdapterInstallError = class extends Error {
|
|
37041
37493
|
code;
|
|
37042
37494
|
constructor(code, message, options = {}) {
|
|
@@ -37093,7 +37545,7 @@ var ManagedAdapterInstaller = class {
|
|
|
37093
37545
|
this.#stateDirectory = options.stateDirectory;
|
|
37094
37546
|
}
|
|
37095
37547
|
install = async (specification, signal) => {
|
|
37096
|
-
const root =
|
|
37548
|
+
const root = join14(this.#stateDirectory, "adapters", specification.id, specification.adapterVersion);
|
|
37097
37549
|
try {
|
|
37098
37550
|
return await this.#npmInstaller.install(
|
|
37099
37551
|
root,
|
|
@@ -37127,7 +37579,7 @@ async function resolveManagedAdapterExecutable(specification, context) {
|
|
|
37127
37579
|
let managed;
|
|
37128
37580
|
try {
|
|
37129
37581
|
managed = await validateManagedAdapter(
|
|
37130
|
-
|
|
37582
|
+
join15(readStateDirectory(context.environment), "adapters", specification.id, specification.adapterVersion),
|
|
37131
37583
|
specification
|
|
37132
37584
|
);
|
|
37133
37585
|
} catch {
|
|
@@ -37441,9 +37893,9 @@ async function discoverLocalAgentInventory(options) {
|
|
|
37441
37893
|
}
|
|
37442
37894
|
|
|
37443
37895
|
// src/storage/runtime-installation-store.ts
|
|
37444
|
-
import { createHash as
|
|
37445
|
-
import { mkdir as
|
|
37446
|
-
import { dirname as
|
|
37896
|
+
import { createHash as createHash3, randomUUID as randomUUID2 } from "node:crypto";
|
|
37897
|
+
import { mkdir as mkdir5, open as open5, readdir as readdir3, rename as rename4, unlink, writeFile as writeFile4 } from "node:fs/promises";
|
|
37898
|
+
import { dirname as dirname5, join as join16, resolve as resolve4 } from "node:path";
|
|
37447
37899
|
var APPLICATION_ID_PATTERN = /^[a-z][a-z0-9]*(?:[.-][a-z0-9]+){1,31}$/;
|
|
37448
37900
|
var CONNECTION_ID_PATTERN = /^mcn_[a-f0-9]{32}$/;
|
|
37449
37901
|
var INSTALLATION_ID_PATTERN = /^min_[a-f0-9]{32}$/;
|
|
@@ -37507,7 +37959,7 @@ var VerifiedRuntimeConnection = class {
|
|
|
37507
37959
|
this.runtimeId = runtimeId;
|
|
37508
37960
|
}
|
|
37509
37961
|
};
|
|
37510
|
-
function
|
|
37962
|
+
function isRecord9(value) {
|
|
37511
37963
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
37512
37964
|
}
|
|
37513
37965
|
function hasExactKeys(value, expectedKeys) {
|
|
@@ -37571,16 +38023,16 @@ function parseRelayOrigin(value) {
|
|
|
37571
38023
|
return origin;
|
|
37572
38024
|
}
|
|
37573
38025
|
function connectionId() {
|
|
37574
|
-
return `mcn_${
|
|
38026
|
+
return `mcn_${randomUUID2().replaceAll("-", "")}`;
|
|
37575
38027
|
}
|
|
37576
38028
|
function installationId() {
|
|
37577
|
-
return `min_${
|
|
38029
|
+
return `min_${randomUUID2().replaceAll("-", "")}`;
|
|
37578
38030
|
}
|
|
37579
38031
|
function channelIndexFileName(channelId) {
|
|
37580
|
-
return `mci_${
|
|
38032
|
+
return `mci_${createHash3("sha256").update(channelId).digest("hex")}.json`;
|
|
37581
38033
|
}
|
|
37582
38034
|
function decodeInstallationPointer(value) {
|
|
37583
|
-
if (!
|
|
38035
|
+
if (!isRecord9(value) || !hasExactKeys(value, INSTALLATION_POINTER_KEYS) || value["version"] !== 1) {
|
|
37584
38036
|
throw new RuntimeInstallationStoreError("invalid_installation", "The local installation record is invalid");
|
|
37585
38037
|
}
|
|
37586
38038
|
const storedInstallationId = value["installationId"];
|
|
@@ -37590,7 +38042,7 @@ function decodeInstallationPointer(value) {
|
|
|
37590
38042
|
return { installationId: validateInstallationId(storedInstallationId) };
|
|
37591
38043
|
}
|
|
37592
38044
|
function decodeChannelIndex(value) {
|
|
37593
|
-
if (!
|
|
38045
|
+
if (!isRecord9(value) || !hasExactKeys(value, CHANNEL_INDEX_KEYS) || value["version"] !== 1) {
|
|
37594
38046
|
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
|
|
37595
38047
|
}
|
|
37596
38048
|
const applicationId = value["applicationId"];
|
|
@@ -37640,7 +38092,7 @@ function decodeVerifiedConnection(value) {
|
|
|
37640
38092
|
);
|
|
37641
38093
|
}
|
|
37642
38094
|
function decodeConnection(value) {
|
|
37643
|
-
if (!
|
|
38095
|
+
if (!isRecord9(value)) {
|
|
37644
38096
|
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
|
|
37645
38097
|
}
|
|
37646
38098
|
return decodeVerifiedConnection(value);
|
|
@@ -37685,15 +38137,15 @@ async function readJsonFile(path2, signal, missingCode) {
|
|
|
37685
38137
|
}
|
|
37686
38138
|
async function writeJsonAtomically(path2, value, signal) {
|
|
37687
38139
|
signal.throwIfAborted();
|
|
37688
|
-
const directory =
|
|
37689
|
-
const temporaryPath =
|
|
38140
|
+
const directory = dirname5(path2);
|
|
38141
|
+
const temporaryPath = join16(directory, `.${randomUUID2()}.tmp`);
|
|
37690
38142
|
try {
|
|
37691
|
-
await
|
|
38143
|
+
await mkdir5(directory, { mode: 448, recursive: true });
|
|
37692
38144
|
signal.throwIfAborted();
|
|
37693
|
-
await
|
|
38145
|
+
await writeFile4(temporaryPath, `${JSON.stringify(value, null, 2)}
|
|
37694
38146
|
`, { flag: "wx", mode: 384 });
|
|
37695
38147
|
signal.throwIfAborted();
|
|
37696
|
-
await
|
|
38148
|
+
await rename4(temporaryPath, path2);
|
|
37697
38149
|
} catch (cause) {
|
|
37698
38150
|
await unlink(temporaryPath).catch(() => void 0);
|
|
37699
38151
|
signal.throwIfAborted();
|
|
@@ -37712,16 +38164,16 @@ var RuntimeInstallationStore = class _RuntimeInstallationStore {
|
|
|
37712
38164
|
this.applicationId = applicationId;
|
|
37713
38165
|
this.installationId = installationId2;
|
|
37714
38166
|
this.stateDirectory = stateDirectory;
|
|
37715
|
-
this.#channelDirectory =
|
|
37716
|
-
this.#connectionDirectory =
|
|
38167
|
+
this.#channelDirectory = join16(stateDirectory, "channels");
|
|
38168
|
+
this.#connectionDirectory = join16(stateDirectory, "connections");
|
|
37717
38169
|
}
|
|
37718
38170
|
static open = async (options, signal) => {
|
|
37719
38171
|
signal.throwIfAborted();
|
|
37720
38172
|
const applicationId = validateApplicationId(options.applicationId);
|
|
37721
38173
|
const rootDirectory = resolve4(options.stateDirectory);
|
|
37722
|
-
const applicationDirectory =
|
|
38174
|
+
const applicationDirectory = join16(rootDirectory, "installations", applicationId);
|
|
37723
38175
|
try {
|
|
37724
|
-
await
|
|
38176
|
+
await mkdir5(applicationDirectory, { mode: 448, recursive: true });
|
|
37725
38177
|
} catch (cause) {
|
|
37726
38178
|
throw new RuntimeInstallationStoreError(
|
|
37727
38179
|
"installation_unavailable",
|
|
@@ -37732,9 +38184,9 @@ var RuntimeInstallationStore = class _RuntimeInstallationStore {
|
|
|
37732
38184
|
);
|
|
37733
38185
|
}
|
|
37734
38186
|
const storedInstallationId = await readOrCreateInstallationId(applicationDirectory, signal);
|
|
37735
|
-
const stateDirectory =
|
|
38187
|
+
const stateDirectory = join16(applicationDirectory, storedInstallationId);
|
|
37736
38188
|
try {
|
|
37737
|
-
await
|
|
38189
|
+
await mkdir5(stateDirectory, { mode: 448, recursive: true });
|
|
37738
38190
|
} catch (cause) {
|
|
37739
38191
|
throw new RuntimeInstallationStoreError(
|
|
37740
38192
|
"installation_unavailable",
|
|
@@ -37747,8 +38199,8 @@ var RuntimeInstallationStore = class _RuntimeInstallationStore {
|
|
|
37747
38199
|
signal.throwIfAborted();
|
|
37748
38200
|
return new _RuntimeInstallationStore(applicationId, storedInstallationId, stateDirectory);
|
|
37749
38201
|
};
|
|
37750
|
-
connectionPath = (connectionId2) =>
|
|
37751
|
-
channelIndexPath = (channelId) =>
|
|
38202
|
+
connectionPath = (connectionId2) => join16(this.#connectionDirectory, `${validateConnectionId(connectionId2)}.json`);
|
|
38203
|
+
channelIndexPath = (channelId) => join16(this.#channelDirectory, channelIndexFileName(validateIdentifier(channelId, "invalid_channel_id")));
|
|
37752
38204
|
readConnection = async (connectionId2, signal) => {
|
|
37753
38205
|
const stored = decodeConnection(
|
|
37754
38206
|
await readJsonFile(this.connectionPath(connectionId2), signal, "connection_not_found")
|
|
@@ -37821,7 +38273,7 @@ var RuntimeInstallationStore = class _RuntimeInstallationStore {
|
|
|
37821
38273
|
signal.throwIfAborted();
|
|
37822
38274
|
let entries;
|
|
37823
38275
|
try {
|
|
37824
|
-
entries = await
|
|
38276
|
+
entries = await readdir3(this.#connectionDirectory);
|
|
37825
38277
|
} catch (cause) {
|
|
37826
38278
|
if (isNodeError(cause, "ENOENT")) {
|
|
37827
38279
|
return [];
|
|
@@ -37910,7 +38362,7 @@ var RuntimeInstallationStore = class _RuntimeInstallationStore {
|
|
|
37910
38362
|
};
|
|
37911
38363
|
};
|
|
37912
38364
|
async function readOrCreateInstallationId(applicationDirectory, signal) {
|
|
37913
|
-
const pointerPath =
|
|
38365
|
+
const pointerPath = join16(applicationDirectory, "current.json");
|
|
37914
38366
|
try {
|
|
37915
38367
|
return decodeInstallationPointer(await readJsonFile(pointerPath, signal, "installation_not_found")).installationId;
|
|
37916
38368
|
} catch (cause) {
|
|
@@ -37920,7 +38372,7 @@ async function readOrCreateInstallationId(applicationDirectory, signal) {
|
|
|
37920
38372
|
}
|
|
37921
38373
|
const candidate = installationId();
|
|
37922
38374
|
try {
|
|
37923
|
-
await
|
|
38375
|
+
await writeFile4(pointerPath, `${JSON.stringify({ installationId: candidate, version: 1 })}
|
|
37924
38376
|
`, {
|
|
37925
38377
|
flag: "wx",
|
|
37926
38378
|
mode: 384
|
|
@@ -37958,7 +38410,7 @@ var PairingClientError = class extends Error {
|
|
|
37958
38410
|
this.name = "PairingClientError";
|
|
37959
38411
|
}
|
|
37960
38412
|
};
|
|
37961
|
-
function
|
|
38413
|
+
function isRecord10(value) {
|
|
37962
38414
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
37963
38415
|
}
|
|
37964
38416
|
function hasExactKeys2(value, expectedKeys) {
|
|
@@ -38050,9 +38502,9 @@ function parseResumeConnectionId(arguments_) {
|
|
|
38050
38502
|
async function resolveDefaultWorkspace(path2) {
|
|
38051
38503
|
const requestedWorkspace = resolve5(path2);
|
|
38052
38504
|
try {
|
|
38053
|
-
await
|
|
38054
|
-
const defaultWorkspace = await
|
|
38055
|
-
const metadata = await
|
|
38505
|
+
await mkdir6(requestedWorkspace, { recursive: true, mode: 448 });
|
|
38506
|
+
const defaultWorkspace = await realpath8(requestedWorkspace);
|
|
38507
|
+
const metadata = await stat7(defaultWorkspace);
|
|
38056
38508
|
if (!metadata.isDirectory()) {
|
|
38057
38509
|
throw new PairingClientError("invalid_workspace", "The default workspace is not a directory");
|
|
38058
38510
|
}
|
|
@@ -38081,9 +38533,9 @@ async function readJsonResponse(response) {
|
|
|
38081
38533
|
}
|
|
38082
38534
|
}
|
|
38083
38535
|
function readRelayError(value) {
|
|
38084
|
-
if (
|
|
38536
|
+
if (isRecord10(value)) {
|
|
38085
38537
|
const error62 = value["error"];
|
|
38086
|
-
if (
|
|
38538
|
+
if (isRecord10(error62)) {
|
|
38087
38539
|
const code = error62["code"];
|
|
38088
38540
|
const message = error62["message"];
|
|
38089
38541
|
if (typeof code === "string" && typeof message === "string") {
|
|
@@ -38094,7 +38546,7 @@ function readRelayError(value) {
|
|
|
38094
38546
|
return new PairingClientError("pairing_failed", "The relay could not pair this machine");
|
|
38095
38547
|
}
|
|
38096
38548
|
function decodePairingResponse(value, credentialField, expectedKeys) {
|
|
38097
|
-
if (!
|
|
38549
|
+
if (!isRecord10(value) || !hasExactKeys2(value, expectedKeys)) {
|
|
38098
38550
|
throw new PairingClientError("invalid_relay_response", "The relay returned an invalid pairing response");
|
|
38099
38551
|
}
|
|
38100
38552
|
const appId = value["appId"];
|
|
@@ -38276,8 +38728,8 @@ function isRuntimeRelayRevocation(closeCode, closeReason) {
|
|
|
38276
38728
|
}
|
|
38277
38729
|
|
|
38278
38730
|
// src/run-daemon.ts
|
|
38279
|
-
import { createHash as
|
|
38280
|
-
import { join as
|
|
38731
|
+
import { createHash as createHash8, randomUUID as randomUUID8 } from "node:crypto";
|
|
38732
|
+
import { join as join19 } from "node:path";
|
|
38281
38733
|
import { styleText } from "node:util";
|
|
38282
38734
|
|
|
38283
38735
|
// src/agent-catalog/publish-agent-catalog.ts
|
|
@@ -38309,7 +38761,7 @@ var AgentCatalogPublishError = class extends Error {
|
|
|
38309
38761
|
this.name = "AgentCatalogPublishError";
|
|
38310
38762
|
}
|
|
38311
38763
|
};
|
|
38312
|
-
function
|
|
38764
|
+
function isRecord11(value) {
|
|
38313
38765
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
38314
38766
|
}
|
|
38315
38767
|
function isSafeRelayErrorMessage(value) {
|
|
@@ -38322,7 +38774,7 @@ async function rejectedCatalogError(response) {
|
|
|
38322
38774
|
} catch {
|
|
38323
38775
|
return new AgentCatalogPublishError("The Relay rejected the Agent catalog update");
|
|
38324
38776
|
}
|
|
38325
|
-
if (!
|
|
38777
|
+
if (!isRecord11(value) || !isRecord11(value["error"])) {
|
|
38326
38778
|
return new AgentCatalogPublishError("The Relay rejected the Agent catalog update");
|
|
38327
38779
|
}
|
|
38328
38780
|
const code = value["error"]["code"];
|
|
@@ -38853,9 +39305,9 @@ var FixedInstallationExecutor = class {
|
|
|
38853
39305
|
};
|
|
38854
39306
|
|
|
38855
39307
|
// src/authorization/workspace-directory.ts
|
|
38856
|
-
import { readdir as
|
|
39308
|
+
import { readdir as readdir4, realpath as realpath9, stat as stat8 } from "node:fs/promises";
|
|
38857
39309
|
import { homedir as homedir2 } from "node:os";
|
|
38858
|
-
import { basename as basename4, dirname as
|
|
39310
|
+
import { basename as basename4, dirname as dirname6, isAbsolute as isAbsolute9, join as join17, normalize as normalize3, relative as relative4 } from "node:path";
|
|
38859
39311
|
var WorkspaceDirectoryListing = class {
|
|
38860
39312
|
directoryId;
|
|
38861
39313
|
directoryLabel;
|
|
@@ -38923,9 +39375,9 @@ var WorkspaceDirectoryService = class {
|
|
|
38923
39375
|
throw new LocalAuthorizationError("The local directory path is invalid");
|
|
38924
39376
|
}
|
|
38925
39377
|
try {
|
|
38926
|
-
const target = await
|
|
39378
|
+
const target = await realpath9(requested);
|
|
38927
39379
|
signal.throwIfAborted();
|
|
38928
|
-
const metadata = await
|
|
39380
|
+
const metadata = await stat8(target);
|
|
38929
39381
|
signal.throwIfAborted();
|
|
38930
39382
|
if (!isAbsolute9(target) || normalize3(target) !== target || !metadata.isDirectory()) {
|
|
38931
39383
|
throw new LocalAuthorizationError("The selected location is not a directory");
|
|
@@ -38962,7 +39414,7 @@ var WorkspaceDirectoryService = class {
|
|
|
38962
39414
|
list = async (bindingId, id, signal) => {
|
|
38963
39415
|
const target = await this.resolve(bindingId, id, signal);
|
|
38964
39416
|
try {
|
|
38965
|
-
const children = await
|
|
39417
|
+
const children = await readdir4(target, { withFileTypes: true });
|
|
38966
39418
|
signal.throwIfAborted();
|
|
38967
39419
|
const entries = [];
|
|
38968
39420
|
for (const child2 of children) {
|
|
@@ -38973,7 +39425,7 @@ var WorkspaceDirectoryService = class {
|
|
|
38973
39425
|
continue;
|
|
38974
39426
|
}
|
|
38975
39427
|
try {
|
|
38976
|
-
const path2 = await this.resolvePath(
|
|
39428
|
+
const path2 = await this.resolvePath(join17(target, child2.name), signal);
|
|
38977
39429
|
entries.push({ directoryId: encodePath(path2), name: child2.name });
|
|
38978
39430
|
} catch (cause) {
|
|
38979
39431
|
signal.throwIfAborted();
|
|
@@ -38983,7 +39435,7 @@ var WorkspaceDirectoryService = class {
|
|
|
38983
39435
|
}
|
|
38984
39436
|
}
|
|
38985
39437
|
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
38986
|
-
const parent =
|
|
39438
|
+
const parent = dirname6(target);
|
|
38987
39439
|
return new WorkspaceDirectoryListing(
|
|
38988
39440
|
id,
|
|
38989
39441
|
this.label(target),
|
|
@@ -39009,15 +39461,15 @@ var WorkspaceDirectoryService = class {
|
|
|
39009
39461
|
|
|
39010
39462
|
// src/daemon-diagnostic-log.ts
|
|
39011
39463
|
import { appendFileSync, mkdirSync as mkdirSync2, readFileSync as readFileSync2, renameSync, statSync as statSync3, writeFileSync } from "node:fs";
|
|
39012
|
-
import { join as
|
|
39464
|
+
import { join as join18 } from "node:path";
|
|
39013
39465
|
var MAXIMUM_DAEMON_LOG_BYTES = 1 * 1024 * 1024;
|
|
39014
39466
|
var DaemonDiagnosticLog = class {
|
|
39015
39467
|
#directory;
|
|
39016
39468
|
#path;
|
|
39017
39469
|
#maximumBytes;
|
|
39018
39470
|
constructor(stateDirectory, maximumBytes = MAXIMUM_DAEMON_LOG_BYTES) {
|
|
39019
|
-
this.#directory =
|
|
39020
|
-
this.#path =
|
|
39471
|
+
this.#directory = join18(stateDirectory, "logs");
|
|
39472
|
+
this.#path = join18(this.#directory, "daemon.log");
|
|
39021
39473
|
this.#maximumBytes = maximumBytes;
|
|
39022
39474
|
}
|
|
39023
39475
|
record = (diagnostic) => {
|
|
@@ -39062,7 +39514,7 @@ import { WebSocket as WebSocket2 } from "undici";
|
|
|
39062
39514
|
import { WebSocket } from "undici";
|
|
39063
39515
|
|
|
39064
39516
|
// src/prompt-artifact-resolver.ts
|
|
39065
|
-
import { createHash as
|
|
39517
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
39066
39518
|
import { fetch as fetch4 } from "undici";
|
|
39067
39519
|
var ARTIFACT_SCHEME = "mobius-artifact:";
|
|
39068
39520
|
var ARTIFACT_DOWNLOAD_TIMEOUT_MILLISECONDS = 2e4;
|
|
@@ -39200,7 +39652,7 @@ async function download(config2, command, reference, signal) {
|
|
|
39200
39652
|
);
|
|
39201
39653
|
}
|
|
39202
39654
|
const bytes = await responseBytes(response, reference.byteLength, requestSignal);
|
|
39203
|
-
if (
|
|
39655
|
+
if (createHash4("sha256").update(bytes).digest("hex") !== reference.sha256) {
|
|
39204
39656
|
throw new PromptArtifactError(
|
|
39205
39657
|
"artifact_integrity_failed",
|
|
39206
39658
|
"The prompt artifact failed integrity validation"
|
|
@@ -39505,7 +39957,7 @@ var DaemonInstallationObserver = class {
|
|
|
39505
39957
|
};
|
|
39506
39958
|
|
|
39507
39959
|
// src/daemon-active-turn.ts
|
|
39508
|
-
import { randomUUID as
|
|
39960
|
+
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
39509
39961
|
function activeMessageCharacters(message) {
|
|
39510
39962
|
return message.text.length + (message.role === "assistant" ? JSON.stringify(message.activities).length + JSON.stringify(message.content).length : 0);
|
|
39511
39963
|
}
|
|
@@ -39539,7 +39991,7 @@ var ActiveDaemonTurn = class {
|
|
|
39539
39991
|
#timeline;
|
|
39540
39992
|
#sequence = 0;
|
|
39541
39993
|
#interaction = null;
|
|
39542
|
-
#epoch = decodeIdentifier(
|
|
39994
|
+
#epoch = decodeIdentifier(randomUUID3());
|
|
39543
39995
|
constructor(command, attemptId) {
|
|
39544
39996
|
this.attemptId = attemptId;
|
|
39545
39997
|
this.command = command;
|
|
@@ -39601,7 +40053,7 @@ var ActiveDaemonTurn = class {
|
|
|
39601
40053
|
if (!this.#activities.has(event.activityId)) {
|
|
39602
40054
|
this.#timeline = [
|
|
39603
40055
|
...this.#timeline,
|
|
39604
|
-
{ activityId: event.activityId, id: decodeIdentifier(
|
|
40056
|
+
{ activityId: event.activityId, id: decodeIdentifier(randomUUID3()), kind: "activity" }
|
|
39605
40057
|
];
|
|
39606
40058
|
}
|
|
39607
40059
|
this.#activities.set(event.activityId, {
|
|
@@ -39622,7 +40074,7 @@ var ActiveDaemonTurn = class {
|
|
|
39622
40074
|
if (previous === void 0) {
|
|
39623
40075
|
this.#timeline = [
|
|
39624
40076
|
...this.#timeline,
|
|
39625
|
-
{ activityId: event.activityId, id: decodeIdentifier(
|
|
40077
|
+
{ activityId: event.activityId, id: decodeIdentifier(randomUUID3()), kind: "activity" }
|
|
39626
40078
|
];
|
|
39627
40079
|
}
|
|
39628
40080
|
this.#activities.set(event.activityId, {
|
|
@@ -39647,7 +40099,7 @@ var ActiveDaemonTurn = class {
|
|
|
39647
40099
|
...this.#timeline,
|
|
39648
40100
|
{
|
|
39649
40101
|
content: /* @__PURE__ */ new Map([[event.contentId, event.content]]),
|
|
39650
|
-
id: decodeIdentifier(
|
|
40102
|
+
id: decodeIdentifier(randomUUID3()),
|
|
39651
40103
|
kind: "message",
|
|
39652
40104
|
sourceMessageId: event.messageId,
|
|
39653
40105
|
text: ""
|
|
@@ -39687,7 +40139,7 @@ var ActiveDaemonTurn = class {
|
|
|
39687
40139
|
...this.#timeline,
|
|
39688
40140
|
{
|
|
39689
40141
|
content: /* @__PURE__ */ new Map(),
|
|
39690
|
-
id: decodeIdentifier(
|
|
40142
|
+
id: decodeIdentifier(randomUUID3()),
|
|
39691
40143
|
kind: "message",
|
|
39692
40144
|
sourceMessageId: messageId,
|
|
39693
40145
|
text: remaining.slice(0, ACTIVE_TURN_TEXT_CHUNK_LIMIT)
|
|
@@ -40663,7 +41115,7 @@ var readCodexFullHistory = async (agent, cwd, nativeSessionId, signal, nativeTur
|
|
|
40663
41115
|
});
|
|
40664
41116
|
|
|
40665
41117
|
// src/native-sessions/service.ts
|
|
40666
|
-
import { randomUUID as
|
|
41118
|
+
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
40667
41119
|
import { basename as basename5 } from "node:path";
|
|
40668
41120
|
|
|
40669
41121
|
// src/native-sessions/acp-history.ts
|
|
@@ -40878,7 +41330,7 @@ var NativeSessionService = class {
|
|
|
40878
41330
|
if (authorized === null) {
|
|
40879
41331
|
return null;
|
|
40880
41332
|
}
|
|
40881
|
-
const entryId = decodeIdentifier(
|
|
41333
|
+
const entryId = decodeIdentifier(randomUUID4());
|
|
40882
41334
|
if (this.#entries.size >= 5e3) {
|
|
40883
41335
|
this.#entries.clear();
|
|
40884
41336
|
}
|
|
@@ -40934,7 +41386,7 @@ var NativeSessionService = class {
|
|
|
40934
41386
|
"invalid_native_session_response"
|
|
40935
41387
|
);
|
|
40936
41388
|
}
|
|
40937
|
-
nextCursor = decodeIdentifier(
|
|
41389
|
+
nextCursor = decodeIdentifier(randomUUID4());
|
|
40938
41390
|
if (this.#cursors.size >= 500) {
|
|
40939
41391
|
this.#cursors.clear();
|
|
40940
41392
|
}
|
|
@@ -41216,7 +41668,7 @@ var NativeSessionService = class {
|
|
|
41216
41668
|
};
|
|
41217
41669
|
|
|
41218
41670
|
// src/relay-connection/daemon-operation-state.ts
|
|
41219
|
-
import { createHash as
|
|
41671
|
+
import { createHash as createHash5, randomUUID as randomUUID5 } from "node:crypto";
|
|
41220
41672
|
var MAX_TERMINAL_RECEIPTS = 1024;
|
|
41221
41673
|
function isTerminal(state) {
|
|
41222
41674
|
return state === "succeeded" || state === "failed" || state === "cancelled";
|
|
@@ -41225,7 +41677,7 @@ var DaemonOperationState = class {
|
|
|
41225
41677
|
#executions = /* @__PURE__ */ new Map();
|
|
41226
41678
|
#terminalCount = 0;
|
|
41227
41679
|
claimExecution = (commandId, sessionId, commandJson) => {
|
|
41228
|
-
const commandHash =
|
|
41680
|
+
const commandHash = createHash5("sha256").update(commandJson).digest("hex");
|
|
41229
41681
|
const existing = this.#executions.get(commandId);
|
|
41230
41682
|
if (existing !== void 0) {
|
|
41231
41683
|
if (existing.sessionId !== sessionId || existing.commandHash !== commandHash) {
|
|
@@ -41233,7 +41685,7 @@ var DaemonOperationState = class {
|
|
|
41233
41685
|
}
|
|
41234
41686
|
return { attemptId: existing.attemptId, commandId, kind: "duplicate", state: existing.state };
|
|
41235
41687
|
}
|
|
41236
|
-
const attemptId =
|
|
41688
|
+
const attemptId = randomUUID5();
|
|
41237
41689
|
this.#executions.set(commandId, { attemptId, commandHash, sessionId, state: "dispatching" });
|
|
41238
41690
|
return { attemptId, commandId, kind: "accepted", state: "dispatching" };
|
|
41239
41691
|
};
|
|
@@ -41569,7 +42021,7 @@ function createAgentCatalogRefreshHandler(dependencies) {
|
|
|
41569
42021
|
import { WebSocket as WebSocket4 } from "undici";
|
|
41570
42022
|
|
|
41571
42023
|
// src/agent-catalog/discover-agent-settings.ts
|
|
41572
|
-
import { createHash as
|
|
42024
|
+
import { createHash as createHash6 } from "node:crypto";
|
|
41573
42025
|
|
|
41574
42026
|
// src/agent-catalog/agent-settings-base.ts
|
|
41575
42027
|
var AgentSettingsConfigurationError = class extends Error {
|
|
@@ -42033,7 +42485,7 @@ function settingsRevision(agent, reportedAgentVersion, settings, modelEffort) {
|
|
|
42033
42485
|
unsupportedModelIds: modelEffort.unsupportedModelIds,
|
|
42034
42486
|
valuesByModel: {}
|
|
42035
42487
|
};
|
|
42036
|
-
return
|
|
42488
|
+
return createHash6("sha256").update(
|
|
42037
42489
|
JSON.stringify({
|
|
42038
42490
|
adapterVersion: agent.kind === "acp-adapter-process" ? agent.adapterVersion : agent.agentVersion,
|
|
42039
42491
|
agentId: agent.id,
|
|
@@ -42184,7 +42636,7 @@ function createAgentSettingsDiscoveryHandler(dependencies) {
|
|
|
42184
42636
|
|
|
42185
42637
|
// src/artifacts/local-file-streamer.ts
|
|
42186
42638
|
import { createReadStream as createReadStream2 } from "node:fs";
|
|
42187
|
-
import { realpath as
|
|
42639
|
+
import { realpath as realpath10, stat as stat9 } from "node:fs/promises";
|
|
42188
42640
|
import { basename as basename6, isAbsolute as isAbsolute10, normalize as normalize4, resolve as resolve7 } from "node:path";
|
|
42189
42641
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
42190
42642
|
var CHUNK_BYTES = 192 * 1024;
|
|
@@ -42212,7 +42664,7 @@ async function resolveFile(value, workingDirectory, signal) {
|
|
|
42212
42664
|
return null;
|
|
42213
42665
|
}
|
|
42214
42666
|
try {
|
|
42215
|
-
const target = await
|
|
42667
|
+
const target = await realpath10(requested);
|
|
42216
42668
|
signal.throwIfAborted();
|
|
42217
42669
|
return isAbsolute10(target) && normalize4(target) === target ? target : null;
|
|
42218
42670
|
} catch {
|
|
@@ -42220,23 +42672,24 @@ async function resolveFile(value, workingDirectory, signal) {
|
|
|
42220
42672
|
return null;
|
|
42221
42673
|
}
|
|
42222
42674
|
}
|
|
42223
|
-
async function streamLocalFile(command, send2, signal, workingDirectory) {
|
|
42224
|
-
const
|
|
42675
|
+
async function streamLocalFile(command, send2, signal, workingDirectory, externalContent) {
|
|
42676
|
+
const external = await externalContent.resolve(command.sessionId, command.path, signal);
|
|
42677
|
+
const target = external?.path ?? await resolveFile(command.path, workingDirectory, signal);
|
|
42225
42678
|
if (target === null) {
|
|
42226
42679
|
throw new Error("The local file is unavailable");
|
|
42227
42680
|
}
|
|
42228
|
-
const before = await
|
|
42681
|
+
const before = await stat9(target);
|
|
42229
42682
|
signal.throwIfAborted();
|
|
42230
42683
|
if (!before.isFile() || before.size < 1 || before.size > command.maxBytes) {
|
|
42231
42684
|
throw new Error("The local file is too large to read");
|
|
42232
42685
|
}
|
|
42233
|
-
const raster = await readLocalRaster(target, signal);
|
|
42686
|
+
const raster = external === null ? await readLocalRaster(target, signal) : null;
|
|
42234
42687
|
send2({
|
|
42235
42688
|
byteLength: before.size,
|
|
42236
42689
|
kind: FILE_BEGIN_KIND,
|
|
42237
|
-
mediaType: raster?.mimeType ?? "application/octet-stream",
|
|
42690
|
+
mediaType: external?.mediaType ?? raster?.mimeType ?? "application/octet-stream",
|
|
42238
42691
|
modifiedAt: before.mtime.toISOString(),
|
|
42239
|
-
name: basename6(target) || "file",
|
|
42692
|
+
name: external?.name ?? (basename6(target) || "file"),
|
|
42240
42693
|
requestId: command.requestId,
|
|
42241
42694
|
sessionId: command.sessionId
|
|
42242
42695
|
});
|
|
@@ -42253,7 +42706,7 @@ async function streamLocalFile(command, send2, signal, workingDirectory) {
|
|
|
42253
42706
|
});
|
|
42254
42707
|
sequence += 1;
|
|
42255
42708
|
}
|
|
42256
|
-
const after = await
|
|
42709
|
+
const after = await stat9(target);
|
|
42257
42710
|
signal.throwIfAborted();
|
|
42258
42711
|
if (after.size !== before.size || after.mtimeMs !== before.mtimeMs) {
|
|
42259
42712
|
throw new Error("The local file changed during transfer");
|
|
@@ -42266,7 +42719,7 @@ async function streamLocalFile(command, send2, signal, workingDirectory) {
|
|
|
42266
42719
|
}
|
|
42267
42720
|
|
|
42268
42721
|
// src/daemon-history-commands.ts
|
|
42269
|
-
import { createHash as
|
|
42722
|
+
import { createHash as createHash7 } from "node:crypto";
|
|
42270
42723
|
|
|
42271
42724
|
// src/authorization/resolve-session-directories.ts
|
|
42272
42725
|
import { basename as basename7 } from "node:path";
|
|
@@ -42660,7 +43113,7 @@ async function executeSessionLiveHistoryPageLoad(socket, command, config2, direc
|
|
|
42660
43113
|
}
|
|
42661
43114
|
function replayEvent(sessionId, position, update) {
|
|
42662
43115
|
const encoded = JSON.stringify(update);
|
|
42663
|
-
const eventId = `native-${
|
|
43116
|
+
const eventId = `native-${createHash7("sha256").update(sessionId).update(":").update(position.toString()).update(":").update(encoded).digest("hex")}`;
|
|
42664
43117
|
return {
|
|
42665
43118
|
eventId,
|
|
42666
43119
|
payload: update,
|
|
@@ -42743,7 +43196,7 @@ async function executeSessionLiveHistoryV2PageLoad(socket, command, config2, dir
|
|
|
42743
43196
|
}
|
|
42744
43197
|
|
|
42745
43198
|
// src/acp/session-config/apply-session-configuration.ts
|
|
42746
|
-
import { randomUUID as
|
|
43199
|
+
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
42747
43200
|
function invalidSessionConfiguration(message) {
|
|
42748
43201
|
return new AcpExecutionError(message, {}, "invalid_session_configuration");
|
|
42749
43202
|
}
|
|
@@ -42884,7 +43337,7 @@ async function applySessionConfigurationSelection(sessions, audit, options, sele
|
|
|
42884
43337
|
booleanValue: selection.booleanValue,
|
|
42885
43338
|
configId: selection.configId,
|
|
42886
43339
|
cwd,
|
|
42887
|
-
requestId: `cfg_${
|
|
43340
|
+
requestId: `cfg_${randomUUID6()}`,
|
|
42888
43341
|
sessionId,
|
|
42889
43342
|
signal,
|
|
42890
43343
|
value: selection.value,
|
|
@@ -43558,6 +44011,7 @@ function createDaemonCommandHandler({
|
|
|
43558
44011
|
operations,
|
|
43559
44012
|
publisher,
|
|
43560
44013
|
eventLogV2,
|
|
44014
|
+
externalContent,
|
|
43561
44015
|
activeTurns,
|
|
43562
44016
|
diagnostics,
|
|
43563
44017
|
socket,
|
|
@@ -43666,7 +44120,8 @@ function createDaemonCommandHandler({
|
|
|
43666
44120
|
command2,
|
|
43667
44121
|
(message2) => send(socket, message2),
|
|
43668
44122
|
signal,
|
|
43669
|
-
sessions.findSessions([command2.sessionId])[0]?.cwd ?? null
|
|
44123
|
+
sessions.findSessions([command2.sessionId])[0]?.cwd ?? null,
|
|
44124
|
+
externalContent
|
|
43670
44125
|
).catch((error62) => {
|
|
43671
44126
|
if (socket.readyState !== WebSocket6.OPEN || signal.aborted) {
|
|
43672
44127
|
return;
|
|
@@ -43985,7 +44440,7 @@ function connectRelay(url2, signal) {
|
|
|
43985
44440
|
}
|
|
43986
44441
|
|
|
43987
44442
|
// src/relay-connection/liveness.ts
|
|
43988
|
-
import { randomUUID as
|
|
44443
|
+
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
43989
44444
|
var HEARTBEAT_ACK_TIMEOUT_MILLISECONDS = 1e4;
|
|
43990
44445
|
var HEARTBEAT_INTERVAL_MILLISECONDS = 2e4;
|
|
43991
44446
|
var RelayLivenessState = class {
|
|
@@ -44074,7 +44529,7 @@ var RelayConnectionLiveness = class {
|
|
|
44074
44529
|
}
|
|
44075
44530
|
throw new Error("Heartbeat was scheduled in an invalid state");
|
|
44076
44531
|
}
|
|
44077
|
-
const heartbeatId =
|
|
44532
|
+
const heartbeatId = randomUUID7();
|
|
44078
44533
|
this.#state = new AwaitingHeartbeatAckState(
|
|
44079
44534
|
heartbeatId,
|
|
44080
44535
|
this.#timer.schedule(this.#handleTimeout, HEARTBEAT_ACK_TIMEOUT_MILLISECONDS)
|
|
@@ -44114,6 +44569,7 @@ async function runRelayConnection({
|
|
|
44114
44569
|
operations,
|
|
44115
44570
|
publisher,
|
|
44116
44571
|
eventLogV2,
|
|
44572
|
+
externalContent,
|
|
44117
44573
|
activeTurns,
|
|
44118
44574
|
connectionEpoch,
|
|
44119
44575
|
diagnostics,
|
|
@@ -44137,6 +44593,7 @@ async function runRelayConnection({
|
|
|
44137
44593
|
operations,
|
|
44138
44594
|
publisher,
|
|
44139
44595
|
eventLogV2,
|
|
44596
|
+
externalContent,
|
|
44140
44597
|
activeTurns,
|
|
44141
44598
|
diagnostics,
|
|
44142
44599
|
socket,
|
|
@@ -44615,7 +45072,7 @@ async function installDetectedAgentIntegrations(config2, installations, signal)
|
|
|
44615
45072
|
{
|
|
44616
45073
|
agentId: agent.id,
|
|
44617
45074
|
kind: AGENT_INSTALL_REQUEST_KIND,
|
|
44618
|
-
requestId: `automatic-integration-${
|
|
45075
|
+
requestId: `automatic-integration-${randomUUID8()}`
|
|
44619
45076
|
},
|
|
44620
45077
|
signal
|
|
44621
45078
|
);
|
|
@@ -44634,8 +45091,9 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
|
|
|
44634
45091
|
stateDirectory
|
|
44635
45092
|
});
|
|
44636
45093
|
const sessionStore = new SqliteAcpSessionStore(
|
|
44637
|
-
|
|
45094
|
+
join19(stateDirectory, "sessions", `${createHash8("sha256").update(config2.channelId).digest("hex")}.sqlite`)
|
|
44638
45095
|
);
|
|
45096
|
+
await using externalContent = new LocalExternalContentStore(stateDirectory);
|
|
44639
45097
|
const operations = new DaemonOperationState();
|
|
44640
45098
|
const publisher = new DaemonSessionEventPublisher(sessionStore);
|
|
44641
45099
|
const eventLogV2 = new DaemonSessionEventLogV2(publisher, sessionStore);
|
|
@@ -44656,7 +45114,8 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
|
|
|
44656
45114
|
)).history : null
|
|
44657
45115
|
},
|
|
44658
45116
|
"native",
|
|
44659
|
-
publisher.publishStatus
|
|
45117
|
+
publisher.publishStatus,
|
|
45118
|
+
new AcpContentExternalizer(externalContent)
|
|
44660
45119
|
);
|
|
44661
45120
|
const directories = new WorkspaceDirectoryService(config2.bindingId, config2.defaultWorkspace);
|
|
44662
45121
|
const installationObserver = new DaemonInstallationObserver();
|
|
@@ -44770,6 +45229,7 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
|
|
|
44770
45229
|
operations,
|
|
44771
45230
|
publisher,
|
|
44772
45231
|
eventLogV2,
|
|
45232
|
+
externalContent,
|
|
44773
45233
|
activeTurns,
|
|
44774
45234
|
connectionEpoch,
|
|
44775
45235
|
diagnostics,
|
|
@@ -44826,7 +45286,7 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
|
|
|
44826
45286
|
}
|
|
44827
45287
|
|
|
44828
45288
|
// src/runtime.ts
|
|
44829
|
-
import { mkdir as
|
|
45289
|
+
import { mkdir as mkdir7, realpath as realpath11, stat as stat10 } from "node:fs/promises";
|
|
44830
45290
|
import { resolve as resolve8 } from "node:path";
|
|
44831
45291
|
var RUNTIME_CREDENTIAL_PATTERN2 = /^[a-zA-Z0-9_-]{32,256}$/;
|
|
44832
45292
|
var MobiusRuntimeConfigurationError = class extends Error {
|
|
@@ -44892,9 +45352,9 @@ function loadMobiusRuntimeConnection(environment = process.env) {
|
|
|
44892
45352
|
async function resolveWorkspace(path2) {
|
|
44893
45353
|
const requested = resolve8(path2);
|
|
44894
45354
|
try {
|
|
44895
|
-
await
|
|
44896
|
-
const resolved = await
|
|
44897
|
-
const metadata = await
|
|
45355
|
+
await mkdir7(requested, { recursive: true, mode: 448 });
|
|
45356
|
+
const resolved = await realpath11(requested);
|
|
45357
|
+
const metadata = await stat10(resolved);
|
|
44898
45358
|
if (!metadata.isDirectory()) {
|
|
44899
45359
|
throw new MobiusRuntimeConfigurationError("The Runtime workspace is not a directory");
|
|
44900
45360
|
}
|