@moxt-ai/mobius 0.0.131 → 0.0.132
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.map +1 -1
- package/dist/acp/agent-query-processes.js +2 -1
- package/dist/acp/agent-query-processes.js.map +1 -1
- package/dist/acp/agent-runtime-manager.d.ts.map +1 -1
- package/dist/acp/agent-runtime-manager.js +57 -52
- package/dist/acp/agent-runtime-manager.js.map +1 -1
- package/dist/acp/runtime-operations.d.ts +11 -0
- package/dist/acp/runtime-operations.d.ts.map +1 -0
- package/dist/acp/runtime-operations.js +45 -0
- package/dist/acp/runtime-operations.js.map +1 -0
- package/dist/cli.js +203 -147
- package/dist/cli.js.map +4 -4
- package/dist/index.js +202 -146
- package/dist/index.js.map +4 -4
- package/dist/runtime.js +202 -146
- package/dist/runtime.js.map +4 -4
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -3381,7 +3381,7 @@ var program = new Command();
|
|
|
3381
3381
|
// package.json
|
|
3382
3382
|
var package_default = {
|
|
3383
3383
|
name: "@moxt-ai/mobius",
|
|
3384
|
-
version: "0.0.
|
|
3384
|
+
version: "0.0.132",
|
|
3385
3385
|
description: "Mobius CLI for pairing and running local AI agent services.",
|
|
3386
3386
|
type: "module",
|
|
3387
3387
|
bin: {
|
|
@@ -39762,6 +39762,48 @@ var RetainedAgentProcesses = class {
|
|
|
39762
39762
|
};
|
|
39763
39763
|
};
|
|
39764
39764
|
|
|
39765
|
+
// src/acp/runtime-operations.ts
|
|
39766
|
+
var RuntimeOperations = class {
|
|
39767
|
+
#shutdown = new AbortController();
|
|
39768
|
+
#pending = /* @__PURE__ */ new Set();
|
|
39769
|
+
#closing = null;
|
|
39770
|
+
run = async (options, operation) => {
|
|
39771
|
+
const signal = AbortSignal.any([options.signal, this.#shutdown.signal]);
|
|
39772
|
+
signal.throwIfAborted();
|
|
39773
|
+
const pending = Promise.resolve().then(() => operation({ ...options, signal }));
|
|
39774
|
+
this.#pending.add(pending);
|
|
39775
|
+
try {
|
|
39776
|
+
const result = await pending;
|
|
39777
|
+
signal.throwIfAborted();
|
|
39778
|
+
return result;
|
|
39779
|
+
} finally {
|
|
39780
|
+
this.#pending.delete(pending);
|
|
39781
|
+
}
|
|
39782
|
+
};
|
|
39783
|
+
close = (release) => {
|
|
39784
|
+
if (this.#closing !== null) {
|
|
39785
|
+
return this.#closing;
|
|
39786
|
+
}
|
|
39787
|
+
this.#shutdown.abort();
|
|
39788
|
+
this.#closing = (async () => {
|
|
39789
|
+
await Promise.allSettled([...this.#pending]);
|
|
39790
|
+
await release();
|
|
39791
|
+
})();
|
|
39792
|
+
return this.#closing;
|
|
39793
|
+
};
|
|
39794
|
+
};
|
|
39795
|
+
async function waitForPreparation(pending, signal) {
|
|
39796
|
+
signal.throwIfAborted();
|
|
39797
|
+
const cancelled = Promise.withResolvers();
|
|
39798
|
+
const abort = () => cancelled.reject(signal.reason);
|
|
39799
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
39800
|
+
try {
|
|
39801
|
+
return await Promise.race([pending, cancelled.promise]);
|
|
39802
|
+
} finally {
|
|
39803
|
+
signal.removeEventListener("abort", abort);
|
|
39804
|
+
}
|
|
39805
|
+
}
|
|
39806
|
+
|
|
39765
39807
|
// src/acp/agent-query-processes.ts
|
|
39766
39808
|
var AgentQueryProcesses = class {
|
|
39767
39809
|
#processesByQuery;
|
|
@@ -39808,7 +39850,7 @@ var AgentQueryProcesses = class {
|
|
|
39808
39850
|
prepare = async (options) => {
|
|
39809
39851
|
const pending = this.#processesByQuery.pending(options.sessionId);
|
|
39810
39852
|
if (pending !== void 0) {
|
|
39811
|
-
const runtime2 = await pending;
|
|
39853
|
+
const runtime2 = await waitForPreparation(pending, options.signal);
|
|
39812
39854
|
if (runtime2.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
|
|
39813
39855
|
this.#processesByQuery.touch(options.sessionId, runtime2);
|
|
39814
39856
|
return runtime2.prepared();
|
|
@@ -40087,6 +40129,7 @@ var AgentProcessPool = class {
|
|
|
40087
40129
|
// src/acp/agent-runtime-manager.ts
|
|
40088
40130
|
var SESSION_CONTROL_TIMEOUT_MILLISECONDS = 3e4;
|
|
40089
40131
|
var AgentRuntimeManager = class {
|
|
40132
|
+
#operations = new RuntimeOperations();
|
|
40090
40133
|
#processes = new AgentProcessPool();
|
|
40091
40134
|
#executionProcesses = new RetainedAgentProcesses({
|
|
40092
40135
|
touch: this.#processes.touch,
|
|
@@ -40209,8 +40252,8 @@ var AgentRuntimeManager = class {
|
|
|
40209
40252
|
return runtime;
|
|
40210
40253
|
});
|
|
40211
40254
|
}
|
|
40212
|
-
prepareSession = async (options, metrics = unmeasuredOperationMetrics) => {
|
|
40213
|
-
const stored = metrics.measureSync("session-state-read", () => this.#store.read(
|
|
40255
|
+
prepareSession = async (options, metrics = unmeasuredOperationMetrics) => this.#operations.run(options, async (options2) => {
|
|
40256
|
+
const stored = metrics.measureSync("session-state-read", () => this.#store.read(options2.sessionId));
|
|
40214
40257
|
if (stored instanceof DeletedAcpStoredSession) {
|
|
40215
40258
|
throw new AcpExecutionError(
|
|
40216
40259
|
"The native Agent session was deleted. Start a new chat.",
|
|
@@ -40221,19 +40264,22 @@ var AgentRuntimeManager = class {
|
|
|
40221
40264
|
if (stored instanceof FoundAcpStoredSession && this.#nativeOperations.has(`${stored.session.agentId}:${stored.session.nativeSessionId}`)) {
|
|
40222
40265
|
throw new AcpExecutionError("The native session is being managed", {}, "session_busy");
|
|
40223
40266
|
}
|
|
40224
|
-
const pending = this.#executionProcesses.pending(
|
|
40267
|
+
const pending = this.#executionProcesses.pending(options2.sessionId);
|
|
40225
40268
|
if (pending !== void 0) {
|
|
40226
|
-
const runtime2 = await metrics.measure(
|
|
40227
|
-
|
|
40228
|
-
|
|
40269
|
+
const runtime2 = await metrics.measure(
|
|
40270
|
+
"session-preparation-wait",
|
|
40271
|
+
async () => await waitForPreparation(pending, options2.signal)
|
|
40272
|
+
);
|
|
40273
|
+
if (runtime2.belongsTo(options2.agent.id, options2.cwd, options2.additionalDirectories)) {
|
|
40274
|
+
this.#executionProcesses.touch(options2.sessionId, runtime2);
|
|
40229
40275
|
return runtime2.prepared();
|
|
40230
40276
|
}
|
|
40231
|
-
return await this.prepareSession(
|
|
40277
|
+
return await this.prepareSession(options2, metrics);
|
|
40232
40278
|
}
|
|
40233
|
-
const existing = this.#executionProcesses.get(
|
|
40279
|
+
const existing = this.#executionProcesses.get(options2.sessionId);
|
|
40234
40280
|
if (existing !== void 0) {
|
|
40235
|
-
if (existing.belongsTo(
|
|
40236
|
-
this.#executionProcesses.touch(
|
|
40281
|
+
if (existing.belongsTo(options2.agent.id, options2.cwd, options2.additionalDirectories)) {
|
|
40282
|
+
this.#executionProcesses.touch(options2.sessionId, existing);
|
|
40237
40283
|
return existing.prepared();
|
|
40238
40284
|
}
|
|
40239
40285
|
if (!existing.canRebind()) {
|
|
@@ -40243,85 +40289,91 @@ var AgentRuntimeManager = class {
|
|
|
40243
40289
|
"session_identity_mismatch"
|
|
40244
40290
|
);
|
|
40245
40291
|
}
|
|
40246
|
-
const runtime2 = await this.#replacePreparation(existing,
|
|
40292
|
+
const runtime2 = await this.#replacePreparation(existing, options2, metrics);
|
|
40247
40293
|
return runtime2.prepared();
|
|
40248
40294
|
}
|
|
40249
|
-
const runtime = await this.#startPreparation(
|
|
40295
|
+
const runtime = await this.#startPreparation(options2, metrics);
|
|
40250
40296
|
return runtime.prepared();
|
|
40251
|
-
};
|
|
40297
|
+
});
|
|
40252
40298
|
/**
|
|
40253
40299
|
* Opens a short-lived native ACP session only to read the local Agent's
|
|
40254
40300
|
* authoritative settings. Its identity and store are private to this
|
|
40255
40301
|
* operation and never become a Mobius Session.
|
|
40256
40302
|
*/
|
|
40257
|
-
inspectAgentSettings = async (options) =>
|
|
40258
|
-
|
|
40259
|
-
|
|
40260
|
-
|
|
40261
|
-
|
|
40262
|
-
|
|
40303
|
+
inspectAgentSettings = async (options) => this.#operations.run(options, async (options2) => {
|
|
40304
|
+
return await this.#processes.runTransient(
|
|
40305
|
+
options2.signal,
|
|
40306
|
+
async () => await AgentSession.start(
|
|
40307
|
+
{
|
|
40308
|
+
...options2,
|
|
40309
|
+
sessionId: `agent-settings-${crypto.randomUUID()}`
|
|
40310
|
+
},
|
|
40311
|
+
() => this.#agentSettingsObserver,
|
|
40312
|
+
new MemoryAcpSessionStore()
|
|
40313
|
+
),
|
|
40314
|
+
async (runtime) => {
|
|
40315
|
+
const prepared = runtime.prepared();
|
|
40316
|
+
const model = options2.model;
|
|
40317
|
+
const configOptions = model === void 0 ? prepared.configOptions : await runtime.configure({
|
|
40318
|
+
...options2,
|
|
40319
|
+
booleanValue: false,
|
|
40320
|
+
configId: prepared.configOptions.find(
|
|
40321
|
+
(option) => option.id === "model" || option.category === "model"
|
|
40322
|
+
)?.id ?? "model",
|
|
40323
|
+
requestId: "agent-settings-model",
|
|
40324
|
+
sessionId: `agent-settings-${crypto.randomUUID()}`,
|
|
40325
|
+
value: model,
|
|
40326
|
+
valueType: "select"
|
|
40327
|
+
});
|
|
40328
|
+
return new AcpAgentSettingsSnapshot(prepared.agentName, prepared.agentVersion, configOptions);
|
|
40263
40329
|
},
|
|
40264
|
-
() =>
|
|
40265
|
-
|
|
40266
|
-
|
|
40267
|
-
async (runtime) => {
|
|
40268
|
-
const prepared = runtime.prepared();
|
|
40269
|
-
const model = options.model;
|
|
40270
|
-
const configOptions = model === void 0 ? prepared.configOptions : await runtime.configure({
|
|
40271
|
-
...options,
|
|
40272
|
-
booleanValue: false,
|
|
40273
|
-
configId: prepared.configOptions.find(
|
|
40274
|
-
(option) => option.id === "model" || option.category === "model"
|
|
40275
|
-
)?.id ?? "model",
|
|
40276
|
-
requestId: "agent-settings-model",
|
|
40277
|
-
sessionId: `agent-settings-${crypto.randomUUID()}`,
|
|
40278
|
-
value: model,
|
|
40279
|
-
valueType: "select"
|
|
40280
|
-
});
|
|
40281
|
-
return new AcpAgentSettingsSnapshot(prepared.agentName, prepared.agentVersion, configOptions);
|
|
40282
|
-
},
|
|
40283
|
-
async (runtime) => await runtime.close()
|
|
40284
|
-
);
|
|
40330
|
+
async (runtime) => await runtime.close()
|
|
40331
|
+
);
|
|
40332
|
+
});
|
|
40285
40333
|
/**
|
|
40286
40334
|
* Retained for Agents that expose a separate persisted configuration channel.
|
|
40287
40335
|
* Use inspectAgentSettings for Agent-scoped settings discovery.
|
|
40288
40336
|
*/
|
|
40289
|
-
inspectSession = async (options, metrics = unmeasuredOperationMetrics) => {
|
|
40290
|
-
if (this.#executionProcesses.pending(
|
|
40291
|
-
throw new AcpExecutionError(
|
|
40337
|
+
inspectSession = async (options, metrics = unmeasuredOperationMetrics) => this.#operations.run(options, async (options2) => {
|
|
40338
|
+
if (this.#executionProcesses.pending(options2.sessionId) !== void 0 || this.#executionProcesses.get(options2.sessionId) !== void 0) {
|
|
40339
|
+
throw new AcpExecutionError(
|
|
40340
|
+
"The configuration inspection session is already in use",
|
|
40341
|
+
{},
|
|
40342
|
+
"session_busy"
|
|
40343
|
+
);
|
|
40292
40344
|
}
|
|
40293
|
-
return await this.#executionProcesses.use(
|
|
40294
|
-
const runtime = await this.#startPreparation(
|
|
40345
|
+
return await this.#executionProcesses.use(options2.sessionId, async () => {
|
|
40346
|
+
const runtime = await this.#startPreparation(options2, metrics);
|
|
40295
40347
|
try {
|
|
40296
40348
|
return runtime.prepared();
|
|
40297
40349
|
} finally {
|
|
40298
40350
|
try {
|
|
40299
|
-
await this.#retireSessionProcess(
|
|
40351
|
+
await this.#retireSessionProcess(options2.sessionId, runtime, async () => await runtime.close());
|
|
40300
40352
|
} finally {
|
|
40301
|
-
this.#store.remove(
|
|
40353
|
+
this.#store.remove(options2.sessionId);
|
|
40302
40354
|
}
|
|
40303
40355
|
}
|
|
40304
40356
|
});
|
|
40305
|
-
};
|
|
40306
|
-
prepareExecutionSession = async (options) => {
|
|
40307
|
-
const pending = this.#executionProcesses.pending(
|
|
40357
|
+
});
|
|
40358
|
+
prepareExecutionSession = async (options) => this.#operations.run(options, async (options2) => {
|
|
40359
|
+
const pending = this.#executionProcesses.pending(options2.sessionId);
|
|
40308
40360
|
if (pending !== void 0) {
|
|
40309
|
-
await pending;
|
|
40310
|
-
return await this.prepareExecutionSession(
|
|
40361
|
+
await waitForPreparation(pending, options2.signal);
|
|
40362
|
+
return await this.prepareExecutionSession(options2);
|
|
40311
40363
|
}
|
|
40312
|
-
const existing = this.#executionProcesses.get(
|
|
40364
|
+
const existing = this.#executionProcesses.get(options2.sessionId);
|
|
40313
40365
|
if (existing === void 0) {
|
|
40314
|
-
return (await this.#startPreparation(
|
|
40366
|
+
return (await this.#startPreparation(options2)).prepared();
|
|
40315
40367
|
}
|
|
40316
|
-
if (!existing.belongsTo(
|
|
40368
|
+
if (!existing.belongsTo(options2.agent.id, options2.cwd, options2.additionalDirectories)) {
|
|
40317
40369
|
throw new AcpExecutionError(
|
|
40318
40370
|
"The agent or workspace cannot change after a conversation has started",
|
|
40319
40371
|
{},
|
|
40320
40372
|
"session_identity_mismatch"
|
|
40321
40373
|
);
|
|
40322
40374
|
}
|
|
40323
|
-
if (existing.usesEnvironment(
|
|
40324
|
-
this.#executionProcesses.touch(
|
|
40375
|
+
if (existing.usesEnvironment(options2.agent.environment)) {
|
|
40376
|
+
this.#executionProcesses.touch(options2.sessionId, existing);
|
|
40325
40377
|
return existing.prepared();
|
|
40326
40378
|
}
|
|
40327
40379
|
if (existing.hasRunningTurn()) {
|
|
@@ -40331,15 +40383,15 @@ var AgentRuntimeManager = class {
|
|
|
40331
40383
|
"session_busy"
|
|
40332
40384
|
);
|
|
40333
40385
|
}
|
|
40334
|
-
return (await this.#replaceExecutionPreparation(existing,
|
|
40335
|
-
};
|
|
40336
|
-
prepareNativeSessionBrowser = (options) => this.#queryProcesses.prepare(
|
|
40337
|
-
configureSession = async (options) => {
|
|
40338
|
-
return await this.#executionProcesses.use(
|
|
40339
|
-
const runtime = await this.ensureSession(
|
|
40340
|
-
return await runtime.configure(
|
|
40386
|
+
return (await this.#replaceExecutionPreparation(existing, options2)).prepared();
|
|
40387
|
+
});
|
|
40388
|
+
prepareNativeSessionBrowser = (options) => this.#operations.run(options, (scoped) => this.#queryProcesses.prepare(scoped));
|
|
40389
|
+
configureSession = async (options) => this.#operations.run(options, async (options2) => {
|
|
40390
|
+
return await this.#executionProcesses.use(options2.sessionId, async () => {
|
|
40391
|
+
const runtime = await this.ensureSession(options2);
|
|
40392
|
+
return await runtime.configure(options2);
|
|
40341
40393
|
});
|
|
40342
|
-
};
|
|
40394
|
+
});
|
|
40343
40395
|
cancelPrompt = async (sessionId) => {
|
|
40344
40396
|
await this.#executions.cancel(sessionId, async () => {
|
|
40345
40397
|
const runtime = this.#executionProcesses.get(sessionId);
|
|
@@ -40354,19 +40406,19 @@ var AgentRuntimeManager = class {
|
|
|
40354
40406
|
}
|
|
40355
40407
|
});
|
|
40356
40408
|
};
|
|
40357
|
-
steerPrompt = async (options) => {
|
|
40358
|
-
if (this.#executions.command(
|
|
40409
|
+
steerPrompt = async (options) => this.#operations.run(options, async (options2) => {
|
|
40410
|
+
if (this.#executions.command(options2.sessionId) !== options2.targetCommandId) {
|
|
40359
40411
|
throw new AcpExecutionError("The target turn is no longer active", {}, "steering_target_unavailable");
|
|
40360
40412
|
}
|
|
40361
|
-
const pending = this.#executionProcesses.pending(
|
|
40413
|
+
const pending = this.#executionProcesses.pending(options2.sessionId);
|
|
40362
40414
|
if (pending !== void 0) {
|
|
40363
|
-
await pending;
|
|
40415
|
+
await waitForPreparation(pending, options2.signal);
|
|
40364
40416
|
}
|
|
40365
|
-
if (this.#executions.command(
|
|
40417
|
+
if (this.#executions.command(options2.sessionId) !== options2.targetCommandId) {
|
|
40366
40418
|
throw new AcpExecutionError("The target turn is no longer active", {}, "steering_target_unavailable");
|
|
40367
40419
|
}
|
|
40368
|
-
const runtime = this.#executionProcesses.get(
|
|
40369
|
-
if (runtime === void 0 || !runtime.belongsTo(
|
|
40420
|
+
const runtime = this.#executionProcesses.get(options2.sessionId);
|
|
40421
|
+
if (runtime === void 0 || !runtime.belongsTo(options2.agent.id, options2.cwd, options2.additionalDirectories)) {
|
|
40370
40422
|
throw new AcpExecutionError(
|
|
40371
40423
|
"The target turn execution context is unavailable",
|
|
40372
40424
|
{},
|
|
@@ -40383,8 +40435,8 @@ var AgentRuntimeManager = class {
|
|
|
40383
40435
|
deadline.unref();
|
|
40384
40436
|
try {
|
|
40385
40437
|
return await runtime.steer({
|
|
40386
|
-
...
|
|
40387
|
-
signal: AbortSignal.any([
|
|
40438
|
+
...options2,
|
|
40439
|
+
signal: AbortSignal.any([options2.signal, deadlineController.signal])
|
|
40388
40440
|
});
|
|
40389
40441
|
} catch (error62) {
|
|
40390
40442
|
if (error62 instanceof AcpExecutionError) {
|
|
@@ -40394,44 +40446,44 @@ var AgentRuntimeManager = class {
|
|
|
40394
40446
|
} finally {
|
|
40395
40447
|
clearTimeout(deadline);
|
|
40396
40448
|
}
|
|
40397
|
-
};
|
|
40398
|
-
runPrompt = async (options) => {
|
|
40399
|
-
const stored = this.#store.read(
|
|
40449
|
+
});
|
|
40450
|
+
runPrompt = async (options) => this.#operations.run(options, async (options2) => {
|
|
40451
|
+
const stored = this.#store.read(options2.sessionId);
|
|
40400
40452
|
if (stored instanceof FoundAcpStoredSession && this.#nativeOperations.has(`${stored.session.agentId}:${stored.session.nativeSessionId}`)) {
|
|
40401
40453
|
throw new AcpExecutionError("The native session is being managed", {}, "session_busy");
|
|
40402
40454
|
}
|
|
40403
|
-
this.#executions.begin(
|
|
40455
|
+
this.#executions.begin(options2.sessionId, options2.commandId);
|
|
40404
40456
|
try {
|
|
40405
|
-
if (this.#executions.cancellation(
|
|
40457
|
+
if (this.#executions.cancellation(options2.sessionId) !== void 0) {
|
|
40406
40458
|
return { stopReason: "cancelled" };
|
|
40407
40459
|
}
|
|
40408
|
-
const runtime = await this.ensureSession(
|
|
40409
|
-
if (this.#nativeOperations.has(`${
|
|
40460
|
+
const runtime = await this.ensureSession(options2);
|
|
40461
|
+
if (this.#nativeOperations.has(`${options2.agent.id}:${runtime.nativeSessionId()}`)) {
|
|
40410
40462
|
throw new AcpExecutionError("The native session is being managed", {}, "session_busy");
|
|
40411
40463
|
}
|
|
40412
|
-
if (this.#executions.cancellation(
|
|
40464
|
+
if (this.#executions.cancellation(options2.sessionId) !== void 0) {
|
|
40413
40465
|
return { stopReason: "cancelled" };
|
|
40414
40466
|
}
|
|
40415
40467
|
try {
|
|
40416
|
-
const result = await runtime.prompt(
|
|
40417
|
-
return this.#executions.cancellation(
|
|
40468
|
+
const result = await runtime.prompt(options2);
|
|
40469
|
+
return this.#executions.cancellation(options2.sessionId) !== void 0 ? { stopReason: "cancelled" } : result;
|
|
40418
40470
|
} catch (error62) {
|
|
40419
|
-
if (this.#executions.cancellation(
|
|
40420
|
-
await this.#executions.cancellation(
|
|
40471
|
+
if (this.#executions.cancellation(options2.sessionId) !== void 0) {
|
|
40472
|
+
await this.#executions.cancellation(options2.sessionId);
|
|
40421
40473
|
return { stopReason: "cancelled" };
|
|
40422
40474
|
}
|
|
40423
40475
|
throw error62;
|
|
40424
40476
|
}
|
|
40425
40477
|
} catch (error62) {
|
|
40426
|
-
const failedRuntime = this.#executionProcesses.get(
|
|
40478
|
+
const failedRuntime = this.#executionProcesses.get(options2.sessionId);
|
|
40427
40479
|
if (failedRuntime !== void 0) {
|
|
40428
40480
|
await this.#retireSessionProcess(
|
|
40429
|
-
|
|
40481
|
+
options2.sessionId,
|
|
40430
40482
|
failedRuntime,
|
|
40431
40483
|
async () => await failedRuntime.close()
|
|
40432
40484
|
);
|
|
40433
40485
|
}
|
|
40434
|
-
if (this.#executions.cancellation(
|
|
40486
|
+
if (this.#executions.cancellation(options2.sessionId) !== void 0) {
|
|
40435
40487
|
return { stopReason: "cancelled" };
|
|
40436
40488
|
}
|
|
40437
40489
|
if (error62 instanceof AcpExecutionError) {
|
|
@@ -40442,14 +40494,14 @@ var AgentRuntimeManager = class {
|
|
|
40442
40494
|
});
|
|
40443
40495
|
} finally {
|
|
40444
40496
|
try {
|
|
40445
|
-
await this.#executions.cancellation(
|
|
40497
|
+
await this.#executions.cancellation(options2.sessionId);
|
|
40446
40498
|
} finally {
|
|
40447
|
-
this.#executions.finish(
|
|
40448
|
-
this.#executionProcesses.touch(
|
|
40499
|
+
this.#executions.finish(options2.sessionId, options2.commandId);
|
|
40500
|
+
this.#executionProcesses.touch(options2.sessionId);
|
|
40449
40501
|
this.#processes.notifyChanged();
|
|
40450
40502
|
}
|
|
40451
40503
|
}
|
|
40452
|
-
};
|
|
40504
|
+
});
|
|
40453
40505
|
respondPermission = async (options) => {
|
|
40454
40506
|
const runtime = this.#executionProcesses.get(options.sessionId);
|
|
40455
40507
|
if (runtime === void 0) {
|
|
@@ -40464,7 +40516,7 @@ var AgentRuntimeManager = class {
|
|
|
40464
40516
|
}
|
|
40465
40517
|
await runtime.respondElicitation(options);
|
|
40466
40518
|
};
|
|
40467
|
-
close = async () => {
|
|
40519
|
+
close = async () => this.#operations.close(async () => {
|
|
40468
40520
|
const sessions = [...this.#executionProcesses.entries()];
|
|
40469
40521
|
await Promise.all([
|
|
40470
40522
|
...sessions.map(
|
|
@@ -40472,23 +40524,23 @@ var AgentRuntimeManager = class {
|
|
|
40472
40524
|
),
|
|
40473
40525
|
this.#queryProcesses.close()
|
|
40474
40526
|
]);
|
|
40475
|
-
};
|
|
40527
|
+
});
|
|
40476
40528
|
findSessions = (sessionIds) => sessionIds.flatMap((sessionId) => {
|
|
40477
40529
|
const stored = this.#store.read(sessionId);
|
|
40478
40530
|
return stored instanceof FoundAcpStoredSession ? [stored.session] : [];
|
|
40479
40531
|
});
|
|
40480
40532
|
findLinkedSessions = (agentId, nativeSessionId) => this.#store.findNative(agentId, nativeSessionId);
|
|
40481
40533
|
hasPreparedSession = (sessionId, agentId, cwd, additionalDirectories) => this.#executionProcesses.get(sessionId)?.belongsTo(agentId, cwd, additionalDirectories) === true;
|
|
40482
|
-
createNativeSession = async (options) => {
|
|
40534
|
+
createNativeSession = async (options) => this.#operations.run(options, async (options2) => {
|
|
40483
40535
|
const temporarySessionId = `new-${crypto.randomUUID()}`;
|
|
40484
|
-
const temporaryOptions = { ...
|
|
40536
|
+
const temporaryOptions = { ...options2, sessionId: temporarySessionId };
|
|
40485
40537
|
return await this.#executionProcesses.use(temporarySessionId, async () => {
|
|
40486
40538
|
try {
|
|
40487
40539
|
const runtime = await this.#startPreparation(temporaryOptions);
|
|
40488
40540
|
let adopted = false;
|
|
40489
40541
|
try {
|
|
40490
40542
|
const nativeSessionId = runtime.nativeSessionId();
|
|
40491
|
-
if (!isNativeChatSessionId(
|
|
40543
|
+
if (!isNativeChatSessionId(options2.agent.id, nativeSessionId) || this.#executionProcesses.get(nativeSessionId) !== void 0 || !(this.#store.read(nativeSessionId) instanceof MissingAcpStoredSession)) {
|
|
40492
40544
|
throw new AcpExecutionError(
|
|
40493
40545
|
"The Agent returned an invalid new Session ID",
|
|
40494
40546
|
{},
|
|
@@ -40514,36 +40566,36 @@ var AgentRuntimeManager = class {
|
|
|
40514
40566
|
this.#store.remove(temporarySessionId);
|
|
40515
40567
|
}
|
|
40516
40568
|
});
|
|
40517
|
-
};
|
|
40518
|
-
ensureSession = async (options) => {
|
|
40519
|
-
const existing = this.#executionProcesses.get(
|
|
40569
|
+
});
|
|
40570
|
+
ensureSession = async (options) => this.#operations.run(options, async (options2) => {
|
|
40571
|
+
const existing = this.#executionProcesses.get(options2.sessionId);
|
|
40520
40572
|
if (existing !== void 0) {
|
|
40521
|
-
if (!existing.belongsTo(
|
|
40573
|
+
if (!existing.belongsTo(options2.agent.id, options2.cwd, options2.additionalDirectories)) {
|
|
40522
40574
|
throw new AcpExecutionError(
|
|
40523
40575
|
"The agent or workspace cannot change after a conversation has started",
|
|
40524
40576
|
{},
|
|
40525
40577
|
"session_identity_mismatch"
|
|
40526
40578
|
);
|
|
40527
40579
|
}
|
|
40528
|
-
this.#executionProcesses.touch(
|
|
40580
|
+
this.#executionProcesses.touch(options2.sessionId, existing);
|
|
40529
40581
|
return existing;
|
|
40530
40582
|
}
|
|
40531
|
-
await this.prepareSession(
|
|
40532
|
-
const started = this.#executionProcesses.get(
|
|
40583
|
+
await this.prepareSession(options2);
|
|
40584
|
+
const started = this.#executionProcesses.get(options2.sessionId);
|
|
40533
40585
|
if (started === void 0) {
|
|
40534
40586
|
throw new AcpExecutionError("ACP session did not start");
|
|
40535
40587
|
}
|
|
40536
40588
|
return started;
|
|
40537
|
-
};
|
|
40538
|
-
listNativeSessions = async (options, cursor) => {
|
|
40589
|
+
});
|
|
40590
|
+
listNativeSessions = async (options, cursor) => this.#operations.run(options, async (options2) => {
|
|
40539
40591
|
return await this.#queryProcesses.use(
|
|
40540
|
-
|
|
40541
|
-
async (runtime) => await runtime.listNativeSessions(cursor,
|
|
40592
|
+
options2,
|
|
40593
|
+
async (runtime) => await runtime.listNativeSessions(cursor, options2.signal)
|
|
40542
40594
|
);
|
|
40543
|
-
};
|
|
40544
|
-
previewNativeSession = async (options, nativeSessionId) => {
|
|
40545
|
-
const key = `${
|
|
40546
|
-
const linked = this.#store.findNative(
|
|
40595
|
+
});
|
|
40596
|
+
previewNativeSession = async (options, nativeSessionId) => this.#operations.run(options, async (options2) => {
|
|
40597
|
+
const key = `${options2.agent.id}:${nativeSessionId}`;
|
|
40598
|
+
const linked = this.#store.findNative(options2.agent.id, nativeSessionId);
|
|
40547
40599
|
if (this.#nativeOperations.has(key) || linked.some(
|
|
40548
40600
|
(entry) => this.#executions.command(entry.sessionId) !== void 0 || this.#executionProcesses.pending(entry.sessionId) !== void 0
|
|
40549
40601
|
)) {
|
|
@@ -40555,18 +40607,18 @@ var AgentRuntimeManager = class {
|
|
|
40555
40607
|
}
|
|
40556
40608
|
this.#nativeOperations.add(key);
|
|
40557
40609
|
try {
|
|
40558
|
-
return await this.#queryProcesses.preview(
|
|
40610
|
+
return await this.#queryProcesses.preview(options2, nativeSessionId);
|
|
40559
40611
|
} finally {
|
|
40560
40612
|
this.#nativeOperations.delete(key);
|
|
40561
40613
|
}
|
|
40562
|
-
};
|
|
40563
|
-
loadSessionHistory = async (options) => {
|
|
40564
|
-
return await this.#executionProcesses.use(
|
|
40565
|
-
const runtime = await this.ensureSession(
|
|
40566
|
-
const stored = this.#store.read(
|
|
40614
|
+
});
|
|
40615
|
+
loadSessionHistory = async (options) => this.#operations.run(options, async (options2) => {
|
|
40616
|
+
return await this.#executionProcesses.use(options2.sessionId, async () => {
|
|
40617
|
+
const runtime = await this.ensureSession(options2);
|
|
40618
|
+
const stored = this.#store.read(options2.sessionId);
|
|
40567
40619
|
if (stored instanceof FoundAcpStoredSession && this.#nativeHistoryReader !== null) {
|
|
40568
40620
|
const history = await this.#nativeHistoryReader.read(
|
|
40569
|
-
|
|
40621
|
+
options2,
|
|
40570
40622
|
stored.session.nativeSessionId,
|
|
40571
40623
|
runtime.nativeHistoryTurn
|
|
40572
40624
|
);
|
|
@@ -40574,15 +40626,15 @@ var AgentRuntimeManager = class {
|
|
|
40574
40626
|
return history;
|
|
40575
40627
|
}
|
|
40576
40628
|
}
|
|
40577
|
-
return await runtime.loadHistory(
|
|
40629
|
+
return await runtime.loadHistory(options2.signal);
|
|
40578
40630
|
});
|
|
40579
|
-
};
|
|
40580
|
-
openNativeSession = async (options, origin) => {
|
|
40581
|
-
const key = `${
|
|
40631
|
+
});
|
|
40632
|
+
openNativeSession = async (options, origin) => this.#operations.run(options, async (options2) => {
|
|
40633
|
+
const key = `${options2.agent.id}:${origin.nativeSessionId}`;
|
|
40582
40634
|
if (this.#nativeOperations.has(key)) {
|
|
40583
40635
|
throw new AcpExecutionError("The native session is being managed", {}, "session_busy");
|
|
40584
40636
|
}
|
|
40585
|
-
const linked = this.#store.findNative(
|
|
40637
|
+
const linked = this.#store.findNative(options2.agent.id, origin.nativeSessionId);
|
|
40586
40638
|
if (linked.some(
|
|
40587
40639
|
(entry) => this.#executions.command(entry.sessionId) !== void 0 || this.#executionProcesses.pending(entry.sessionId) !== void 0
|
|
40588
40640
|
)) {
|
|
@@ -40596,7 +40648,7 @@ var AgentRuntimeManager = class {
|
|
|
40596
40648
|
if (origin.kind === "import" && existing !== void 0) {
|
|
40597
40649
|
return await this.#executionProcesses.use(existing.sessionId, async () => {
|
|
40598
40650
|
const runtime = await this.ensureSession({
|
|
40599
|
-
...
|
|
40651
|
+
...options2,
|
|
40600
40652
|
sessionId: existing.sessionId
|
|
40601
40653
|
});
|
|
40602
40654
|
if (this.#executions.command(existing.sessionId) !== void 0 || this.#nativeOperations.has(key)) {
|
|
@@ -40618,18 +40670,22 @@ var AgentRuntimeManager = class {
|
|
|
40618
40670
|
}
|
|
40619
40671
|
});
|
|
40620
40672
|
}
|
|
40621
|
-
if (this.#executionProcesses.get(
|
|
40622
|
-
throw new AcpExecutionError(
|
|
40673
|
+
if (this.#executionProcesses.get(options2.sessionId) !== void 0 || this.#executionProcesses.pending(options2.sessionId) !== void 0 || this.#store.read(options2.sessionId) instanceof FoundAcpStoredSession || this.#store.read(options2.sessionId) instanceof DeletedAcpStoredSession) {
|
|
40674
|
+
throw new AcpExecutionError(
|
|
40675
|
+
"The destination conversation already exists",
|
|
40676
|
+
{},
|
|
40677
|
+
"session_identity_mismatch"
|
|
40678
|
+
);
|
|
40623
40679
|
}
|
|
40624
|
-
return await this.#executionProcesses.use(
|
|
40680
|
+
return await this.#executionProcesses.use(options2.sessionId, async () => {
|
|
40625
40681
|
this.#nativeOperations.add(key);
|
|
40626
40682
|
try {
|
|
40627
|
-
const runtime = await this.#startPreparation({ ...
|
|
40628
|
-
const openedKey = `${
|
|
40683
|
+
const runtime = await this.#startPreparation({ ...options2, origin });
|
|
40684
|
+
const openedKey = `${options2.agent.id}:${runtime.nativeSessionId()}`;
|
|
40629
40685
|
this.#nativeOperations.add(openedKey);
|
|
40630
40686
|
try {
|
|
40631
40687
|
return {
|
|
40632
|
-
sessionId:
|
|
40688
|
+
sessionId: options2.sessionId,
|
|
40633
40689
|
prepared: runtime.prepared()
|
|
40634
40690
|
};
|
|
40635
40691
|
} finally {
|
|
@@ -40637,11 +40693,11 @@ var AgentRuntimeManager = class {
|
|
|
40637
40693
|
this.#processes.notifyChanged();
|
|
40638
40694
|
}
|
|
40639
40695
|
} catch (error62) {
|
|
40640
|
-
this.#store.remove(
|
|
40641
|
-
const runtime = this.#executionProcesses.get(
|
|
40696
|
+
this.#store.remove(options2.sessionId);
|
|
40697
|
+
const runtime = this.#executionProcesses.get(options2.sessionId);
|
|
40642
40698
|
if (runtime !== void 0) {
|
|
40643
40699
|
await this.#retireSessionProcess(
|
|
40644
|
-
|
|
40700
|
+
options2.sessionId,
|
|
40645
40701
|
runtime,
|
|
40646
40702
|
async () => await runtime.closeProcess()
|
|
40647
40703
|
);
|
|
@@ -40651,11 +40707,11 @@ var AgentRuntimeManager = class {
|
|
|
40651
40707
|
this.#nativeOperations.delete(key);
|
|
40652
40708
|
}
|
|
40653
40709
|
});
|
|
40654
|
-
};
|
|
40655
|
-
deleteNativeSession = async (options, nativeSessionId) => {
|
|
40656
|
-
return await this.#queryProcesses.use(
|
|
40657
|
-
const key = `${
|
|
40658
|
-
const linked = this.#store.findNative(
|
|
40710
|
+
});
|
|
40711
|
+
deleteNativeSession = async (options, nativeSessionId) => this.#operations.run(options, async (options2) => {
|
|
40712
|
+
return await this.#queryProcesses.use(options2, async (runtime) => {
|
|
40713
|
+
const key = `${options2.agent.id}:${nativeSessionId}`;
|
|
40714
|
+
const linked = this.#store.findNative(options2.agent.id, nativeSessionId);
|
|
40659
40715
|
if (this.#nativeOperations.has(key) || linked.some(
|
|
40660
40716
|
(entry) => this.#executions.command(entry.sessionId) !== void 0 || this.#executionProcesses.pending(entry.sessionId) !== void 0
|
|
40661
40717
|
)) {
|
|
@@ -40673,11 +40729,11 @@ var AgentRuntimeManager = class {
|
|
|
40673
40729
|
await this.#retireSessionProcess(entry.sessionId, active, async () => await active.close());
|
|
40674
40730
|
}
|
|
40675
40731
|
}
|
|
40676
|
-
|
|
40677
|
-
await runtime.deleteNativeSession(nativeSessionId,
|
|
40678
|
-
const deleted = this.#store.markDeleted(
|
|
40732
|
+
options2.signal.throwIfAborted();
|
|
40733
|
+
await runtime.deleteNativeSession(nativeSessionId, options2.signal);
|
|
40734
|
+
const deleted = this.#store.markDeleted(options2.agent.id, nativeSessionId);
|
|
40679
40735
|
if (runtime.nativeSessionId() === nativeSessionId) {
|
|
40680
|
-
await this.#queryProcesses.retire(
|
|
40736
|
+
await this.#queryProcesses.retire(options2.sessionId, runtime);
|
|
40681
40737
|
}
|
|
40682
40738
|
return deleted;
|
|
40683
40739
|
} finally {
|
|
@@ -40685,7 +40741,7 @@ var AgentRuntimeManager = class {
|
|
|
40685
40741
|
this.#processes.notifyChanged();
|
|
40686
40742
|
}
|
|
40687
40743
|
});
|
|
40688
|
-
};
|
|
40744
|
+
});
|
|
40689
40745
|
};
|
|
40690
40746
|
|
|
40691
40747
|
// src/agent-catalog/publish-agent-catalog.ts
|