@moxt-ai/mobius 0.0.35 → 0.0.36
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/session-manager.d.ts +3 -2
- package/dist/acp/session-manager.d.ts.map +1 -1
- package/dist/acp/session-manager.js +24 -18
- package/dist/acp/session-manager.js.map +1 -1
- package/dist/agent-catalog/discover-local-agents.d.ts +0 -1
- package/dist/agent-catalog/discover-local-agents.d.ts.map +1 -1
- package/dist/agent-catalog/discover-local-agents.js +0 -1
- package/dist/agent-catalog/discover-local-agents.js.map +1 -1
- package/dist/cli.js +153 -54
- package/dist/cli.js.map +3 -3
- package/dist/index.js +152 -53
- package/dist/index.js.map +3 -3
- package/dist/infra/operation-metrics.d.ts +18 -0
- package/dist/infra/operation-metrics.d.ts.map +1 -0
- package/dist/infra/operation-metrics.js +31 -0
- package/dist/infra/operation-metrics.js.map +1 -0
- package/dist/run-daemon.d.ts.map +1 -1
- package/dist/run-daemon.js +37 -3
- package/dist/run-daemon.js.map +1 -1
- package/dist/runtime.js +152 -53
- package/dist/runtime.js.map +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -19960,6 +19960,12 @@ var sessionIdentityFields = {
|
|
|
19960
19960
|
};
|
|
19961
19961
|
var sessionPrepareCommandSchema = external_exports.strictObject({
|
|
19962
19962
|
...sessionIdentityFields,
|
|
19963
|
+
configuration: external_exports.strictObject({
|
|
19964
|
+
booleanValue: external_exports.boolean(),
|
|
19965
|
+
configId: external_exports.string().min(1).max(128),
|
|
19966
|
+
value: external_exports.string().max(500),
|
|
19967
|
+
valueType: external_exports.enum(["boolean", "select"])
|
|
19968
|
+
}).readonly().optional(),
|
|
19963
19969
|
kind: external_exports.literal(SESSION_PREPARE_KIND),
|
|
19964
19970
|
requestId: IDENTIFIER,
|
|
19965
19971
|
transient: external_exports.boolean().optional()
|
|
@@ -19977,6 +19983,12 @@ var sessionReadyEventSchema = external_exports.strictObject({
|
|
|
19977
19983
|
kind: external_exports.literal(SESSION_READY_KIND),
|
|
19978
19984
|
requestId: IDENTIFIER,
|
|
19979
19985
|
restored: external_exports.boolean(),
|
|
19986
|
+
runtimeTimings: external_exports.array(
|
|
19987
|
+
external_exports.strictObject({
|
|
19988
|
+
durationMilliseconds: external_exports.number().finite().nonnegative().max(12e4),
|
|
19989
|
+
name: external_exports.string().regex(/^[a-z][a-z0-9-]{0,63}$/)
|
|
19990
|
+
}).readonly()
|
|
19991
|
+
).max(16).readonly().optional(),
|
|
19980
19992
|
sessionId: IDENTIFIER
|
|
19981
19993
|
}).readonly();
|
|
19982
19994
|
var sessionConfigureCommandSchema = external_exports.strictObject({
|
|
@@ -22359,6 +22371,38 @@ async function readAuthorizedRaster(uri, roots, signal) {
|
|
|
22359
22371
|
return new LocalRasterImage(basename(target) || "Image", mimeType, bytes);
|
|
22360
22372
|
}
|
|
22361
22373
|
|
|
22374
|
+
// src/infra/operation-metrics.ts
|
|
22375
|
+
var AccumulatingOperationMetrics = class {
|
|
22376
|
+
#durations = /* @__PURE__ */ new Map();
|
|
22377
|
+
measure = async (name, operation) => {
|
|
22378
|
+
const startedAt = performance.now();
|
|
22379
|
+
try {
|
|
22380
|
+
return await operation();
|
|
22381
|
+
} finally {
|
|
22382
|
+
this.record(name, performance.now() - startedAt);
|
|
22383
|
+
}
|
|
22384
|
+
};
|
|
22385
|
+
measureSync = (name, operation) => {
|
|
22386
|
+
const startedAt = performance.now();
|
|
22387
|
+
try {
|
|
22388
|
+
return operation();
|
|
22389
|
+
} finally {
|
|
22390
|
+
this.record(name, performance.now() - startedAt);
|
|
22391
|
+
}
|
|
22392
|
+
};
|
|
22393
|
+
snapshot = () => Object.freeze(
|
|
22394
|
+
[...this.#durations].map(([name, durationMilliseconds]) => Object.freeze({ durationMilliseconds, name }))
|
|
22395
|
+
);
|
|
22396
|
+
record = (name, durationMilliseconds) => {
|
|
22397
|
+
this.#durations.set(name, (this.#durations.get(name) ?? 0) + Math.max(0, durationMilliseconds));
|
|
22398
|
+
};
|
|
22399
|
+
};
|
|
22400
|
+
var unmeasuredOperationMetrics = Object.freeze({
|
|
22401
|
+
measure: async (_name, operation) => await operation(),
|
|
22402
|
+
measureSync: (_name, operation) => operation(),
|
|
22403
|
+
snapshot: () => Object.freeze([])
|
|
22404
|
+
});
|
|
22405
|
+
|
|
22362
22406
|
// src/native-sessions/history-images.ts
|
|
22363
22407
|
var IMAGE_MARKER = /\[@image\]\(([^)\r\n]*)(?:\)|$)/g;
|
|
22364
22408
|
async function embedLocalHistoryImages(history, roots, signal) {
|
|
@@ -24099,6 +24143,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
24099
24143
|
#pendingPermissions = /* @__PURE__ */ new Map();
|
|
24100
24144
|
#preSessionUpdates = [];
|
|
24101
24145
|
#processExit;
|
|
24146
|
+
#metrics;
|
|
24102
24147
|
#sessionConfigProtocol;
|
|
24103
24148
|
#store;
|
|
24104
24149
|
#verifiedAgentVersion;
|
|
@@ -24132,13 +24177,14 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
24132
24177
|
#sessionUpdatedAt = "";
|
|
24133
24178
|
#turn = new IdleAcpTurn();
|
|
24134
24179
|
#updateTail = Promise.resolve();
|
|
24135
|
-
constructor(agent, cwd, additionalDirectories, mobiusSessionId, getObserver, store) {
|
|
24180
|
+
constructor(agent, cwd, additionalDirectories, mobiusSessionId, getObserver, store, metrics) {
|
|
24136
24181
|
this.#additionalDirectories = [...additionalDirectories];
|
|
24137
24182
|
this.#agentId = agent.id;
|
|
24138
24183
|
this.#cwd = cwd;
|
|
24139
24184
|
this.#environment = agent.environment;
|
|
24140
24185
|
this.#getObserver = getObserver;
|
|
24141
24186
|
this.#mobiusSessionId = mobiusSessionId;
|
|
24187
|
+
this.#metrics = metrics;
|
|
24142
24188
|
this.#sessionConfigProtocol = sessionConfigProtocolForAgent(agent.id);
|
|
24143
24189
|
this.#store = store;
|
|
24144
24190
|
this.#verifiedAgentVersion = agent.agentVersion;
|
|
@@ -24167,13 +24213,16 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
24167
24213
|
const stream = ndJsonStream(createWritableAcpStream(stdin), readableWebStream(stdout));
|
|
24168
24214
|
this.#connection = createAcpClient(this).connect(stream);
|
|
24169
24215
|
}
|
|
24170
|
-
static async #start(options, getObserver, store, initialize) {
|
|
24216
|
+
static async #start(options, getObserver, store, initialize, metrics) {
|
|
24171
24217
|
for (let attempt = 1; attempt <= 2; attempt += 1) {
|
|
24172
24218
|
options.signal.throwIfAborted();
|
|
24173
|
-
const [adapterUnchanged, agentUnchanged] = await
|
|
24174
|
-
|
|
24175
|
-
|
|
24176
|
-
|
|
24219
|
+
const [adapterUnchanged, agentUnchanged] = await metrics.measure(
|
|
24220
|
+
"executable-validation",
|
|
24221
|
+
async () => await Promise.all([
|
|
24222
|
+
revalidateExecutable(options.agent.adapterIdentity),
|
|
24223
|
+
revalidateExecutable(options.agent.agentIdentity)
|
|
24224
|
+
])
|
|
24225
|
+
);
|
|
24177
24226
|
options.signal.throwIfAborted();
|
|
24178
24227
|
if (!adapterUnchanged || !agentUnchanged) {
|
|
24179
24228
|
throw new AcpExecutionError(
|
|
@@ -24182,13 +24231,17 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
24182
24231
|
"agent_runtime_changed"
|
|
24183
24232
|
);
|
|
24184
24233
|
}
|
|
24185
|
-
const runtime =
|
|
24186
|
-
|
|
24187
|
-
|
|
24188
|
-
|
|
24189
|
-
|
|
24190
|
-
|
|
24191
|
-
|
|
24234
|
+
const runtime = metrics.measureSync(
|
|
24235
|
+
"process-spawn",
|
|
24236
|
+
() => new _AcpProcessSession(
|
|
24237
|
+
options.agent,
|
|
24238
|
+
options.cwd,
|
|
24239
|
+
options.additionalDirectories,
|
|
24240
|
+
options.sessionId,
|
|
24241
|
+
getObserver,
|
|
24242
|
+
store,
|
|
24243
|
+
metrics
|
|
24244
|
+
)
|
|
24192
24245
|
);
|
|
24193
24246
|
try {
|
|
24194
24247
|
await initialize(runtime);
|
|
@@ -24210,17 +24263,19 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
24210
24263
|
}
|
|
24211
24264
|
throw new AcpExecutionError("ACP agent initialization failed");
|
|
24212
24265
|
}
|
|
24213
|
-
static start = async (options, getObserver, store) => await _AcpProcessSession.#start(
|
|
24266
|
+
static start = async (options, getObserver, store, metrics = unmeasuredOperationMetrics) => await _AcpProcessSession.#start(
|
|
24214
24267
|
options,
|
|
24215
24268
|
getObserver,
|
|
24216
24269
|
store,
|
|
24217
|
-
async (runtime) => await runtime.initialize(options.signal, options.origin)
|
|
24270
|
+
async (runtime) => await runtime.initialize(options.signal, options.origin),
|
|
24271
|
+
metrics
|
|
24218
24272
|
);
|
|
24219
24273
|
static startNativeSessionBrowser = async (options, getObserver, store) => await _AcpProcessSession.#start(
|
|
24220
24274
|
options,
|
|
24221
24275
|
getObserver,
|
|
24222
24276
|
store,
|
|
24223
|
-
async (runtime) => await runtime.#initializeAgent(options.signal)
|
|
24277
|
+
async (runtime) => await runtime.#initializeAgent(options.signal),
|
|
24278
|
+
unmeasuredOperationMetrics
|
|
24224
24279
|
);
|
|
24225
24280
|
static startSessionForkAtTurn = async (options, sourceNativeSessionId, forkPoint, getObserver, store) => await _AcpProcessSession.#start(
|
|
24226
24281
|
options,
|
|
@@ -24230,7 +24285,8 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
24230
24285
|
options.signal,
|
|
24231
24286
|
{ kind: "fork", nativeSessionId: sourceNativeSessionId },
|
|
24232
24287
|
forkPoint
|
|
24233
|
-
)
|
|
24288
|
+
),
|
|
24289
|
+
unmeasuredOperationMetrics
|
|
24234
24290
|
);
|
|
24235
24291
|
belongsTo = (agentId, cwd, additionalDirectories) => this.#agentId === agentId && this.#cwd === cwd && arraysEqual(this.#additionalDirectories, additionalDirectories);
|
|
24236
24292
|
usesEnvironment = (environment) => recordsEqual(this.#environment, environment);
|
|
@@ -24349,6 +24405,9 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
24349
24405
|
);
|
|
24350
24406
|
};
|
|
24351
24407
|
async #initializeAgent(signal) {
|
|
24408
|
+
await this.#metrics.measure("agent-initialize", async () => await this.#initializeAgentOperation(signal));
|
|
24409
|
+
}
|
|
24410
|
+
async #initializeAgentOperation(signal) {
|
|
24352
24411
|
const initialized = await this.race(
|
|
24353
24412
|
this.#connection.agent.request(
|
|
24354
24413
|
methods3.agent.initialize,
|
|
@@ -24519,18 +24578,21 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
24519
24578
|
}
|
|
24520
24579
|
this.#store.remove(this.#mobiusSessionId);
|
|
24521
24580
|
}
|
|
24522
|
-
const created = await this.
|
|
24523
|
-
|
|
24524
|
-
|
|
24525
|
-
|
|
24526
|
-
|
|
24527
|
-
|
|
24528
|
-
|
|
24529
|
-
|
|
24530
|
-
|
|
24531
|
-
|
|
24532
|
-
|
|
24533
|
-
|
|
24581
|
+
const created = await this.#metrics.measure(
|
|
24582
|
+
"session-new",
|
|
24583
|
+
async () => await this.race(
|
|
24584
|
+
this.#connection.agent.request(
|
|
24585
|
+
methods3.agent.session.new,
|
|
24586
|
+
{
|
|
24587
|
+
additionalDirectories: [...this.#additionalDirectories],
|
|
24588
|
+
cwd: this.#cwd,
|
|
24589
|
+
mcpServers: []
|
|
24590
|
+
},
|
|
24591
|
+
{ cancellationSignal: signal }
|
|
24592
|
+
),
|
|
24593
|
+
"ACP agent exited while starting a session",
|
|
24594
|
+
signal
|
|
24595
|
+
)
|
|
24534
24596
|
);
|
|
24535
24597
|
this.selectNativeSession(created.sessionId);
|
|
24536
24598
|
lifecycleResponse = created;
|
|
@@ -25333,10 +25395,10 @@ var AcpSessionManager = class {
|
|
|
25333
25395
|
this.#nativeBrowserPreparing.set(options.sessionId, operation);
|
|
25334
25396
|
return await operation;
|
|
25335
25397
|
}
|
|
25336
|
-
async #startPreparation(options) {
|
|
25398
|
+
async #startPreparation(options, metrics = unmeasuredOperationMetrics) {
|
|
25337
25399
|
const operation = (async () => {
|
|
25338
25400
|
try {
|
|
25339
|
-
const runtime = await AcpProcessSession.start(options, () => this.#observer, this.#store);
|
|
25401
|
+
const runtime = await AcpProcessSession.start(options, () => this.#observer, this.#store, metrics);
|
|
25340
25402
|
this.#sessions.set(options.sessionId, runtime);
|
|
25341
25403
|
return runtime;
|
|
25342
25404
|
} finally {
|
|
@@ -25365,13 +25427,13 @@ var AcpSessionManager = class {
|
|
|
25365
25427
|
this.#preparing.set(options.sessionId, operation);
|
|
25366
25428
|
return await operation;
|
|
25367
25429
|
}
|
|
25368
|
-
async #replacePreparation(existing, options) {
|
|
25430
|
+
async #replacePreparation(existing, options, metrics) {
|
|
25369
25431
|
const operation = (async () => {
|
|
25370
25432
|
try {
|
|
25371
25433
|
this.#sessions.delete(options.sessionId);
|
|
25372
25434
|
await existing.close();
|
|
25373
25435
|
this.#store.remove(options.sessionId);
|
|
25374
|
-
const runtime = await AcpProcessSession.start(options, () => this.#observer, this.#store);
|
|
25436
|
+
const runtime = await AcpProcessSession.start(options, () => this.#observer, this.#store, metrics);
|
|
25375
25437
|
this.#sessions.set(options.sessionId, runtime);
|
|
25376
25438
|
return runtime;
|
|
25377
25439
|
} finally {
|
|
@@ -25433,7 +25495,7 @@ var AcpSessionManager = class {
|
|
|
25433
25495
|
this.#preparing.set(options.sessionId, operation);
|
|
25434
25496
|
return await operation;
|
|
25435
25497
|
}
|
|
25436
|
-
prepareSession = async (options) => {
|
|
25498
|
+
prepareSession = async (options, metrics = unmeasuredOperationMetrics) => {
|
|
25437
25499
|
const stored = this.#store.read(options.sessionId);
|
|
25438
25500
|
if (stored instanceof DeletedAcpStoredSession) {
|
|
25439
25501
|
throw new AcpExecutionError(
|
|
@@ -25451,7 +25513,7 @@ var AcpSessionManager = class {
|
|
|
25451
25513
|
if (runtime2.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
|
|
25452
25514
|
return runtime2.prepared();
|
|
25453
25515
|
}
|
|
25454
|
-
return await this.prepareSession(options);
|
|
25516
|
+
return await this.prepareSession(options, metrics);
|
|
25455
25517
|
}
|
|
25456
25518
|
const existing = this.#sessions.get(options.sessionId);
|
|
25457
25519
|
if (existing !== void 0) {
|
|
@@ -25465,10 +25527,10 @@ var AcpSessionManager = class {
|
|
|
25465
25527
|
"session_identity_mismatch"
|
|
25466
25528
|
);
|
|
25467
25529
|
}
|
|
25468
|
-
const runtime2 = await this.#replacePreparation(existing, options);
|
|
25530
|
+
const runtime2 = await this.#replacePreparation(existing, options, metrics);
|
|
25469
25531
|
return runtime2.prepared();
|
|
25470
25532
|
}
|
|
25471
|
-
const runtime = await this.#startPreparation(options);
|
|
25533
|
+
const runtime = await this.#startPreparation(options, metrics);
|
|
25472
25534
|
return runtime.prepared();
|
|
25473
25535
|
};
|
|
25474
25536
|
/**
|
|
@@ -32613,6 +32675,7 @@ async function executeSessionPrepare(publisher, socket, command, config2, direct
|
|
|
32613
32675
|
signal
|
|
32614
32676
|
);
|
|
32615
32677
|
const agent = config2.catalog.find(command.agentId);
|
|
32678
|
+
const metrics = new AccumulatingOperationMetrics();
|
|
32616
32679
|
const preparation = {
|
|
32617
32680
|
additionalDirectories: resolved.additionalDirectories,
|
|
32618
32681
|
agent,
|
|
@@ -32620,29 +32683,65 @@ async function executeSessionPrepare(publisher, socket, command, config2, direct
|
|
|
32620
32683
|
sessionId: command.sessionId,
|
|
32621
32684
|
signal
|
|
32622
32685
|
};
|
|
32623
|
-
const prepared = command.transient === true ? await sessions.inspectSession(preparation) : await sessions.prepareSession(preparation);
|
|
32686
|
+
const prepared = command.transient === true ? await sessions.inspectSession(preparation) : await sessions.prepareSession(preparation, metrics);
|
|
32687
|
+
const configuration = command.configuration;
|
|
32688
|
+
const configOptions = configuration === void 0 ? prepared.configOptions : await metrics.measure(
|
|
32689
|
+
"configuration",
|
|
32690
|
+
async () => await sessions.configureSession({
|
|
32691
|
+
...preparation,
|
|
32692
|
+
booleanValue: configuration.booleanValue,
|
|
32693
|
+
configId: configuration.configId,
|
|
32694
|
+
requestId: command.requestId,
|
|
32695
|
+
value: configuration.value,
|
|
32696
|
+
valueType: configuration.valueType
|
|
32697
|
+
})
|
|
32698
|
+
);
|
|
32624
32699
|
const listing = await directories.list(config2.bindingId, command.directoryId, signal);
|
|
32625
32700
|
audit.record({
|
|
32626
32701
|
commandId: command.requestId,
|
|
32627
32702
|
event: "session_prepared",
|
|
32628
32703
|
sessionId: command.sessionId
|
|
32629
32704
|
});
|
|
32630
|
-
|
|
32631
|
-
|
|
32632
|
-
|
|
32633
|
-
|
|
32634
|
-
agentId: command.agentId,
|
|
32635
|
-
agentName: prepared.agentName,
|
|
32636
|
-
agentVersion: prepared.agentVersion,
|
|
32637
|
-
capabilities: prepared.capabilities,
|
|
32638
|
-
commands: prepared.commands,
|
|
32639
|
-
configOptions: prepared.configOptions,
|
|
32640
|
-
directoryId: command.directoryId,
|
|
32641
|
-
directoryLabel: listing.directoryLabel,
|
|
32642
|
-
kind: "session.ready",
|
|
32643
|
-
requestId: command.requestId,
|
|
32644
|
-
restored: prepared.restored,
|
|
32705
|
+
if (command.configuration !== void 0) {
|
|
32706
|
+
audit.record({
|
|
32707
|
+
commandId: command.requestId,
|
|
32708
|
+
event: "session_configured",
|
|
32645
32709
|
sessionId: command.sessionId
|
|
32710
|
+
});
|
|
32711
|
+
publisher.recordRuntime(
|
|
32712
|
+
command.sessionId,
|
|
32713
|
+
encodeSessionConfigUpdatedEvent({
|
|
32714
|
+
configOptions,
|
|
32715
|
+
kind: "session.config.updated",
|
|
32716
|
+
requestId: command.requestId,
|
|
32717
|
+
sessionId: command.sessionId
|
|
32718
|
+
})
|
|
32719
|
+
);
|
|
32720
|
+
}
|
|
32721
|
+
const readyEvent = {
|
|
32722
|
+
additionalDirectories: resolved.additionalDirectoryEntries,
|
|
32723
|
+
agentId: command.agentId,
|
|
32724
|
+
agentName: prepared.agentName,
|
|
32725
|
+
agentVersion: prepared.agentVersion,
|
|
32726
|
+
capabilities: prepared.capabilities,
|
|
32727
|
+
commands: prepared.commands,
|
|
32728
|
+
configOptions,
|
|
32729
|
+
directoryId: command.directoryId,
|
|
32730
|
+
directoryLabel: listing.directoryLabel,
|
|
32731
|
+
kind: "session.ready",
|
|
32732
|
+
requestId: command.requestId,
|
|
32733
|
+
restored: prepared.restored,
|
|
32734
|
+
sessionId: command.sessionId,
|
|
32735
|
+
runtimeTimings: metrics.snapshot()
|
|
32736
|
+
};
|
|
32737
|
+
metrics.measureSync("readiness-commit", () => {
|
|
32738
|
+
publisher.recordRuntime(command.sessionId, encodeSessionReadyEvent(readyEvent));
|
|
32739
|
+
});
|
|
32740
|
+
send(
|
|
32741
|
+
socket,
|
|
32742
|
+
encodeSessionReadyEvent({
|
|
32743
|
+
...readyEvent,
|
|
32744
|
+
runtimeTimings: metrics.snapshot()
|
|
32646
32745
|
})
|
|
32647
32746
|
);
|
|
32648
32747
|
} catch (error62) {
|