@moxt-ai/mobius 0.0.39 → 0.0.41
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.map +1 -1
- package/dist/acp/session-manager.js +485 -124
- package/dist/acp/session-manager.js.map +1 -1
- package/dist/agent-catalog/agent-discovery.d.ts +2 -2
- package/dist/agent-catalog/agent-discovery.d.ts.map +1 -1
- package/dist/agent-catalog/agent-discovery.js +3 -2
- package/dist/agent-catalog/agent-discovery.js.map +1 -1
- package/dist/agent-catalog/agents/grok-build-agent.d.ts +1 -1
- package/dist/agent-catalog/agents/grok-build-agent.d.ts.map +1 -1
- package/dist/agent-catalog/agents/grok-build-agent.js +18 -8
- package/dist/agent-catalog/agents/grok-build-agent.js.map +1 -1
- package/dist/agent-catalog/discover-agent.js +1 -1
- package/dist/agent-catalog/discover-agent.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/agent-installation/fixed-installation-executor.js +2 -2
- package/dist/agent-installation/fixed-installation-executor.js.map +1 -1
- package/dist/bots/local-bot-grant-store.d.ts +1 -8
- package/dist/bots/local-bot-grant-store.d.ts.map +1 -1
- package/dist/bots/local-bot-grant-store.js +79 -121
- package/dist/bots/local-bot-grant-store.js.map +1 -1
- package/dist/cli.js +1639 -1325
- package/dist/cli.js.map +4 -4
- package/dist/index.js +800 -369
- package/dist/index.js.map +3 -3
- package/dist/run-daemon.d.ts.map +1 -1
- package/dist/run-daemon.js +89 -57
- package/dist/run-daemon.js.map +1 -1
- package/dist/runtime.js +794 -363
- package/dist/runtime.js.map +3 -3
- package/package.json +1 -1
- package/dist/bots/bot-approve-command.d.ts +0 -2
- package/dist/bots/bot-approve-command.d.ts.map +0 -1
- package/dist/bots/bot-approve-command.js +0 -78
- package/dist/bots/bot-approve-command.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -20829,6 +20829,7 @@ var BotSessionPromptCommand = class {
|
|
|
20829
20829
|
commandId;
|
|
20830
20830
|
conversationId;
|
|
20831
20831
|
directoryId;
|
|
20832
|
+
disposition;
|
|
20832
20833
|
executionCapabilityId;
|
|
20833
20834
|
executionCapabilitySecret;
|
|
20834
20835
|
executionDeadlineAt;
|
|
@@ -20841,13 +20842,15 @@ var BotSessionPromptCommand = class {
|
|
|
20841
20842
|
resources;
|
|
20842
20843
|
sessionConfigurations;
|
|
20843
20844
|
sessionId;
|
|
20845
|
+
targetCommandId;
|
|
20844
20846
|
turnId;
|
|
20845
|
-
constructor(sessionId, commandId, agentId, bindingId, directoryId2, additionalDirectoryIds, images, resources, prompt, executionId, executionCapabilityId, executionCapabilitySecret, executionDeadlineAt, botId, conversationId, turnId, behaviorRevisionId, bindingRevision, localGrantId, behaviorInstructions, behaviorDigest, allowedDeliveryTargets, replyRoute, sessionConfigurations = []) {
|
|
20847
|
+
constructor(sessionId, commandId, agentId, bindingId, directoryId2, additionalDirectoryIds, images, resources, prompt, executionId, executionCapabilityId, executionCapabilitySecret, executionDeadlineAt, botId, conversationId, turnId, behaviorRevisionId, bindingRevision, localGrantId, behaviorInstructions, behaviorDigest, allowedDeliveryTargets, replyRoute, sessionConfigurations = [], disposition = SessionPromptDisposition.Reject, targetCommandId = "") {
|
|
20846
20848
|
this.sessionId = sessionId;
|
|
20847
20849
|
this.commandId = commandId;
|
|
20848
20850
|
this.agentId = agentId;
|
|
20849
20851
|
this.bindingId = bindingId;
|
|
20850
20852
|
this.directoryId = directoryId2;
|
|
20853
|
+
this.disposition = disposition;
|
|
20851
20854
|
this.additionalDirectoryIds = Object.freeze([...additionalDirectoryIds]);
|
|
20852
20855
|
this.images = Object.freeze([...images]);
|
|
20853
20856
|
this.resources = Object.freeze([...resources]);
|
|
@@ -20871,12 +20874,14 @@ var BotSessionPromptCommand = class {
|
|
|
20871
20874
|
);
|
|
20872
20875
|
this.replyRoute = replyRoute;
|
|
20873
20876
|
this.sessionConfigurations = Object.freeze([...sessionConfigurations]);
|
|
20877
|
+
this.targetCommandId = targetCommandId;
|
|
20874
20878
|
}
|
|
20875
20879
|
toJSON() {
|
|
20876
|
-
const { sessionConfigurations, ...command } = this;
|
|
20880
|
+
const { disposition, sessionConfigurations, targetCommandId, ...command } = this;
|
|
20877
20881
|
return {
|
|
20878
20882
|
...command,
|
|
20879
|
-
...sessionConfigurations.length === 0 ? {} : { sessionConfigurations }
|
|
20883
|
+
...sessionConfigurations.length === 0 ? {} : { sessionConfigurations },
|
|
20884
|
+
...disposition === SessionPromptDisposition.Reject ? {} : { disposition, targetCommandId }
|
|
20880
20885
|
};
|
|
20881
20886
|
}
|
|
20882
20887
|
};
|
|
@@ -21170,11 +21175,26 @@ function decodeBotSessionPromptCommand(encoded) {
|
|
|
21170
21175
|
"sessionId",
|
|
21171
21176
|
"turnId"
|
|
21172
21177
|
],
|
|
21173
|
-
["sessionConfigurations"]
|
|
21178
|
+
["disposition", "sessionConfigurations", "targetCommandId"]
|
|
21174
21179
|
);
|
|
21175
21180
|
if (value["kind"] !== BOT_SESSION_PROMPT_KIND) {
|
|
21176
21181
|
throw new ProtocolMessageError("Invalid Bot Session prompt kind");
|
|
21177
21182
|
}
|
|
21183
|
+
const rawDisposition = value["disposition"];
|
|
21184
|
+
let disposition;
|
|
21185
|
+
if (rawDisposition === void 0 || rawDisposition === SessionPromptDisposition.Reject) {
|
|
21186
|
+
disposition = SessionPromptDisposition.Reject;
|
|
21187
|
+
} else if (rawDisposition === SessionPromptDisposition.Queue) {
|
|
21188
|
+
disposition = SessionPromptDisposition.Queue;
|
|
21189
|
+
} else if (rawDisposition === SessionPromptDisposition.Steer) {
|
|
21190
|
+
disposition = SessionPromptDisposition.Steer;
|
|
21191
|
+
} else {
|
|
21192
|
+
throw new ProtocolMessageError("Invalid Bot Session prompt disposition");
|
|
21193
|
+
}
|
|
21194
|
+
const targetCommandId = value["targetCommandId"] === void 0 ? "" : readText2(value, "targetCommandId", 128, false);
|
|
21195
|
+
if (disposition === SessionPromptDisposition.Reject && targetCommandId.length > 0 || disposition !== SessionPromptDisposition.Reject && !IDENTIFIER_PATTERN3.test(targetCommandId)) {
|
|
21196
|
+
throw new ProtocolMessageError("Bot Session prompt disposition has an invalid target command");
|
|
21197
|
+
}
|
|
21178
21198
|
return new BotSessionPromptCommand(
|
|
21179
21199
|
readIdentifier2(value, "sessionId"),
|
|
21180
21200
|
readIdentifier2(value, "commandId"),
|
|
@@ -21199,7 +21219,9 @@ function decodeBotSessionPromptCommand(encoded) {
|
|
|
21199
21219
|
readDigest(value, "behaviorDigest"),
|
|
21200
21220
|
readTargets(value, "allowedDeliveryTargets"),
|
|
21201
21221
|
readReplyRoute(value["replyRoute"]),
|
|
21202
|
-
readSessionConfigurations(value)
|
|
21222
|
+
readSessionConfigurations(value),
|
|
21223
|
+
disposition,
|
|
21224
|
+
targetCommandId
|
|
21203
21225
|
);
|
|
21204
21226
|
}
|
|
21205
21227
|
|
|
@@ -27009,7 +27031,7 @@ var titleBefore = {
|
|
|
27009
27031
|
};
|
|
27010
27032
|
function tokenizeDefinition(effects, ok2, nok) {
|
|
27011
27033
|
const self = this;
|
|
27012
|
-
let
|
|
27034
|
+
let identifier2;
|
|
27013
27035
|
return start;
|
|
27014
27036
|
function start(code) {
|
|
27015
27037
|
effects.enter("definition");
|
|
@@ -27028,7 +27050,7 @@ function tokenizeDefinition(effects, ok2, nok) {
|
|
|
27028
27050
|
)(code);
|
|
27029
27051
|
}
|
|
27030
27052
|
function labelAfter(code) {
|
|
27031
|
-
|
|
27053
|
+
identifier2 = normalizeIdentifier(self.sliceSerialize(self.events[self.events.length - 1][1]).slice(1, -1));
|
|
27032
27054
|
if (code === 58) {
|
|
27033
27055
|
effects.enter("definitionMarker");
|
|
27034
27056
|
effects.consume(code);
|
|
@@ -27062,7 +27084,7 @@ function tokenizeDefinition(effects, ok2, nok) {
|
|
|
27062
27084
|
function afterWhitespace(code) {
|
|
27063
27085
|
if (code === null || markdownLineEnding(code)) {
|
|
27064
27086
|
effects.exit("definition");
|
|
27065
|
-
self.parser.defined.push(
|
|
27087
|
+
self.parser.defined.push(identifier2);
|
|
27066
27088
|
return ok2(code);
|
|
27067
27089
|
}
|
|
27068
27090
|
return nok(code);
|
|
@@ -30897,6 +30919,7 @@ var SqliteAcpSessionStore = class {
|
|
|
30897
30919
|
|
|
30898
30920
|
// src/acp/session-manager.ts
|
|
30899
30921
|
var PROCESS_STOP_TIMEOUT_MILLISECONDS = 1e3;
|
|
30922
|
+
var MAX_ACP_PROCESSES = 10;
|
|
30900
30923
|
var MAX_PRE_SESSION_UPDATES = 100;
|
|
30901
30924
|
var MAX_PRE_SESSION_UPDATE_BYTES = 1024 * 1024;
|
|
30902
30925
|
var SESSION_CONTROL_COMMAND_ID = "session-control";
|
|
@@ -30955,6 +30978,91 @@ var RetryableAcpInitializationError = class extends AcpExecutionError {
|
|
|
30955
30978
|
this.name = "RetryableAcpInitializationError";
|
|
30956
30979
|
}
|
|
30957
30980
|
};
|
|
30981
|
+
var AcpProcessCapacityLease = class {
|
|
30982
|
+
#releaseCapacity;
|
|
30983
|
+
#released = false;
|
|
30984
|
+
constructor(releaseCapacity) {
|
|
30985
|
+
this.#releaseCapacity = releaseCapacity;
|
|
30986
|
+
}
|
|
30987
|
+
release = () => {
|
|
30988
|
+
if (this.#released) {
|
|
30989
|
+
return;
|
|
30990
|
+
}
|
|
30991
|
+
this.#released = true;
|
|
30992
|
+
this.#releaseCapacity();
|
|
30993
|
+
};
|
|
30994
|
+
};
|
|
30995
|
+
var AcpProcessCapacityWaiter = class {
|
|
30996
|
+
completion = Promise.withResolvers();
|
|
30997
|
+
signal;
|
|
30998
|
+
constructor(signal) {
|
|
30999
|
+
this.signal = signal;
|
|
31000
|
+
}
|
|
31001
|
+
cancel = () => {
|
|
31002
|
+
try {
|
|
31003
|
+
this.signal.throwIfAborted();
|
|
31004
|
+
} catch (error62) {
|
|
31005
|
+
this.completion.reject(error62);
|
|
31006
|
+
}
|
|
31007
|
+
};
|
|
31008
|
+
};
|
|
31009
|
+
var AcpProcessCapacityLock = class {
|
|
31010
|
+
#locked = false;
|
|
31011
|
+
#waiters = [];
|
|
31012
|
+
acquire = async (signal) => {
|
|
31013
|
+
signal.throwIfAborted();
|
|
31014
|
+
if (!this.#locked) {
|
|
31015
|
+
this.#locked = true;
|
|
31016
|
+
return new AcpProcessCapacityLease(this.#release);
|
|
31017
|
+
}
|
|
31018
|
+
const waiter = new AcpProcessCapacityWaiter(signal);
|
|
31019
|
+
this.#waiters.push(waiter);
|
|
31020
|
+
signal.addEventListener("abort", waiter.cancel, { once: true });
|
|
31021
|
+
if (signal.aborted) {
|
|
31022
|
+
waiter.cancel();
|
|
31023
|
+
}
|
|
31024
|
+
try {
|
|
31025
|
+
return await waiter.completion.promise;
|
|
31026
|
+
} finally {
|
|
31027
|
+
signal.removeEventListener("abort", waiter.cancel);
|
|
31028
|
+
const index2 = this.#waiters.indexOf(waiter);
|
|
31029
|
+
if (index2 >= 0) {
|
|
31030
|
+
this.#waiters.splice(index2, 1);
|
|
31031
|
+
}
|
|
31032
|
+
}
|
|
31033
|
+
};
|
|
31034
|
+
#release = () => {
|
|
31035
|
+
while (this.#waiters.length > 0) {
|
|
31036
|
+
const waiter = this.#waiters.shift();
|
|
31037
|
+
if (waiter === void 0 || waiter.signal.aborted) {
|
|
31038
|
+
continue;
|
|
31039
|
+
}
|
|
31040
|
+
waiter.completion.resolve(new AcpProcessCapacityLease(this.#release));
|
|
31041
|
+
return;
|
|
31042
|
+
}
|
|
31043
|
+
this.#locked = false;
|
|
31044
|
+
};
|
|
31045
|
+
};
|
|
31046
|
+
async function waitForAcpProcessCapacity(completion, signal) {
|
|
31047
|
+
signal.throwIfAborted();
|
|
31048
|
+
const cancelled = Promise.withResolvers();
|
|
31049
|
+
const cancel = () => {
|
|
31050
|
+
try {
|
|
31051
|
+
signal.throwIfAborted();
|
|
31052
|
+
} catch (error62) {
|
|
31053
|
+
cancelled.reject(error62);
|
|
31054
|
+
}
|
|
31055
|
+
};
|
|
31056
|
+
signal.addEventListener("abort", cancel, { once: true });
|
|
31057
|
+
if (signal.aborted) {
|
|
31058
|
+
cancel();
|
|
31059
|
+
}
|
|
31060
|
+
try {
|
|
31061
|
+
await Promise.race([completion, cancelled.promise]);
|
|
31062
|
+
} finally {
|
|
31063
|
+
signal.removeEventListener("abort", cancel);
|
|
31064
|
+
}
|
|
31065
|
+
}
|
|
30958
31066
|
function readableWebStream(input2) {
|
|
30959
31067
|
let streamOpen = true;
|
|
30960
31068
|
return new ReadableStream({
|
|
@@ -32442,20 +32550,23 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
32442
32550
|
}
|
|
32443
32551
|
};
|
|
32444
32552
|
close = async () => {
|
|
32445
|
-
|
|
32446
|
-
|
|
32447
|
-
|
|
32448
|
-
|
|
32449
|
-
|
|
32450
|
-
|
|
32451
|
-
|
|
32452
|
-
|
|
32453
|
-
|
|
32454
|
-
|
|
32455
|
-
|
|
32553
|
+
try {
|
|
32554
|
+
await this.cancelPendingInteractions();
|
|
32555
|
+
if (this.#capabilities.closeSession && this.#nativeSessionId.length > 0) {
|
|
32556
|
+
try {
|
|
32557
|
+
await this.#connection.agent.request(
|
|
32558
|
+
methods3.agent.session.close,
|
|
32559
|
+
{ sessionId: this.#nativeSessionId },
|
|
32560
|
+
{
|
|
32561
|
+
cancellationSignal: AbortSignal.timeout(PROCESS_STOP_TIMEOUT_MILLISECONDS)
|
|
32562
|
+
}
|
|
32563
|
+
);
|
|
32564
|
+
} catch {
|
|
32565
|
+
}
|
|
32456
32566
|
}
|
|
32567
|
+
} finally {
|
|
32568
|
+
await this.closeProcess();
|
|
32457
32569
|
}
|
|
32458
|
-
await this.closeProcess();
|
|
32459
32570
|
};
|
|
32460
32571
|
closeProcess = async (capturedProcesses = []) => {
|
|
32461
32572
|
try {
|
|
@@ -32562,6 +32673,31 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
32562
32673
|
}
|
|
32563
32674
|
};
|
|
32564
32675
|
};
|
|
32676
|
+
var AcpProcessEvictionCandidate = class {
|
|
32677
|
+
};
|
|
32678
|
+
var MissingAcpProcessEvictionCandidate = class extends AcpProcessEvictionCandidate {
|
|
32679
|
+
};
|
|
32680
|
+
var FoundAcpProcessEvictionCandidate = class extends AcpProcessEvictionCandidate {
|
|
32681
|
+
runtime;
|
|
32682
|
+
constructor(runtime) {
|
|
32683
|
+
super();
|
|
32684
|
+
this.runtime = runtime;
|
|
32685
|
+
}
|
|
32686
|
+
};
|
|
32687
|
+
var FoundAcpSessionProcessEvictionCandidate = class extends FoundAcpProcessEvictionCandidate {
|
|
32688
|
+
sessionId;
|
|
32689
|
+
constructor(sessionId, runtime) {
|
|
32690
|
+
super(runtime);
|
|
32691
|
+
this.sessionId = sessionId;
|
|
32692
|
+
}
|
|
32693
|
+
};
|
|
32694
|
+
var FoundAcpNativeBrowserProcessEvictionCandidate = class extends FoundAcpProcessEvictionCandidate {
|
|
32695
|
+
sessionId;
|
|
32696
|
+
constructor(sessionId, runtime) {
|
|
32697
|
+
super(runtime);
|
|
32698
|
+
this.sessionId = sessionId;
|
|
32699
|
+
}
|
|
32700
|
+
};
|
|
32565
32701
|
var AcpSessionManager = class {
|
|
32566
32702
|
#activeCommandIds = /* @__PURE__ */ new Map();
|
|
32567
32703
|
#agentSettingsObserver = new NullAcpSessionObserver();
|
|
@@ -32570,10 +32706,18 @@ var AcpSessionManager = class {
|
|
|
32570
32706
|
#nativeBrowserPreparing = /* @__PURE__ */ new Map();
|
|
32571
32707
|
#nativeBrowserSessions = /* @__PURE__ */ new Map();
|
|
32572
32708
|
#nativeBrowserStore = new MemoryAcpSessionStore();
|
|
32709
|
+
#nativeBrowserUseCounts = /* @__PURE__ */ new Map();
|
|
32573
32710
|
#activeSessionIds = /* @__PURE__ */ new Set();
|
|
32574
32711
|
#cancellationRequests = /* @__PURE__ */ new Map();
|
|
32575
32712
|
#preparing = /* @__PURE__ */ new Map();
|
|
32713
|
+
#processCapacityChanged = Promise.withResolvers();
|
|
32714
|
+
#processCapacityLock = new AcpProcessCapacityLock();
|
|
32715
|
+
#retainedProcesses = /* @__PURE__ */ new Map();
|
|
32716
|
+
#retiringProcessCount = 0;
|
|
32717
|
+
#sessionUseCounts = /* @__PURE__ */ new Map();
|
|
32576
32718
|
#sessions = /* @__PURE__ */ new Map();
|
|
32719
|
+
#startingProcessCount = 0;
|
|
32720
|
+
#transientProcessCount = 0;
|
|
32577
32721
|
#store;
|
|
32578
32722
|
#observer;
|
|
32579
32723
|
constructor(observer = new NullAcpSessionObserver(), store = new MemoryAcpSessionStore()) {
|
|
@@ -32583,18 +32727,230 @@ var AcpSessionManager = class {
|
|
|
32583
32727
|
setObserver = (observer) => {
|
|
32584
32728
|
this.#observer = observer;
|
|
32585
32729
|
};
|
|
32730
|
+
#notifyProcessCapacityChanged() {
|
|
32731
|
+
const changed = this.#processCapacityChanged;
|
|
32732
|
+
this.#processCapacityChanged = Promise.withResolvers();
|
|
32733
|
+
changed.resolve();
|
|
32734
|
+
}
|
|
32735
|
+
#touchSession(sessionId) {
|
|
32736
|
+
const runtime = this.#sessions.get(sessionId);
|
|
32737
|
+
if (runtime === void 0) {
|
|
32738
|
+
return;
|
|
32739
|
+
}
|
|
32740
|
+
this.#touchProcess(runtime);
|
|
32741
|
+
}
|
|
32742
|
+
#touchExpectedSession(sessionId, expected) {
|
|
32743
|
+
if (this.#sessions.get(sessionId) !== expected) {
|
|
32744
|
+
return;
|
|
32745
|
+
}
|
|
32746
|
+
this.#touchProcess(expected);
|
|
32747
|
+
}
|
|
32748
|
+
#touchNativeBrowserSession(sessionId) {
|
|
32749
|
+
const runtime = this.#nativeBrowserSessions.get(sessionId);
|
|
32750
|
+
if (runtime === void 0) {
|
|
32751
|
+
return;
|
|
32752
|
+
}
|
|
32753
|
+
this.#touchProcess(runtime);
|
|
32754
|
+
}
|
|
32755
|
+
#touchExpectedNativeBrowserSession(sessionId, expected) {
|
|
32756
|
+
if (this.#nativeBrowserSessions.get(sessionId) !== expected) {
|
|
32757
|
+
return;
|
|
32758
|
+
}
|
|
32759
|
+
this.#touchProcess(expected);
|
|
32760
|
+
}
|
|
32761
|
+
#touchProcess(runtime) {
|
|
32762
|
+
const retained = this.#retainedProcesses.get(runtime);
|
|
32763
|
+
if (retained === void 0) {
|
|
32764
|
+
return;
|
|
32765
|
+
}
|
|
32766
|
+
this.#retainedProcesses.delete(runtime);
|
|
32767
|
+
this.#retainedProcesses.set(runtime, retained);
|
|
32768
|
+
}
|
|
32769
|
+
#beginSessionUse(sessionId) {
|
|
32770
|
+
this.#sessionUseCounts.set(sessionId, (this.#sessionUseCounts.get(sessionId) ?? 0) + 1);
|
|
32771
|
+
this.#touchSession(sessionId);
|
|
32772
|
+
}
|
|
32773
|
+
#endSessionUse(sessionId) {
|
|
32774
|
+
const count = this.#sessionUseCounts.get(sessionId) ?? 0;
|
|
32775
|
+
if (count <= 1) {
|
|
32776
|
+
this.#sessionUseCounts.delete(sessionId);
|
|
32777
|
+
} else {
|
|
32778
|
+
this.#sessionUseCounts.set(sessionId, count - 1);
|
|
32779
|
+
}
|
|
32780
|
+
this.#touchSession(sessionId);
|
|
32781
|
+
this.#notifyProcessCapacityChanged();
|
|
32782
|
+
}
|
|
32783
|
+
#beginNativeBrowserUse(sessionId) {
|
|
32784
|
+
this.#nativeBrowserUseCounts.set(sessionId, (this.#nativeBrowserUseCounts.get(sessionId) ?? 0) + 1);
|
|
32785
|
+
this.#touchNativeBrowserSession(sessionId);
|
|
32786
|
+
}
|
|
32787
|
+
#endNativeBrowserUse(sessionId) {
|
|
32788
|
+
const count = this.#nativeBrowserUseCounts.get(sessionId) ?? 0;
|
|
32789
|
+
if (count <= 1) {
|
|
32790
|
+
this.#nativeBrowserUseCounts.delete(sessionId);
|
|
32791
|
+
} else {
|
|
32792
|
+
this.#nativeBrowserUseCounts.set(sessionId, count - 1);
|
|
32793
|
+
}
|
|
32794
|
+
this.#touchNativeBrowserSession(sessionId);
|
|
32795
|
+
this.#notifyProcessCapacityChanged();
|
|
32796
|
+
}
|
|
32797
|
+
#isNativeSessionOperationActive(sessionId) {
|
|
32798
|
+
const stored = this.#store.read(sessionId);
|
|
32799
|
+
return stored instanceof FoundAcpStoredSession && this.#nativeOperations.has(`${stored.session.agentId}:${stored.session.nativeSessionId}`);
|
|
32800
|
+
}
|
|
32801
|
+
#leastRecentlyUsedEvictionCandidate() {
|
|
32802
|
+
for (const candidate of this.#retainedProcesses.values()) {
|
|
32803
|
+
if (candidate instanceof FoundAcpSessionProcessEvictionCandidate) {
|
|
32804
|
+
if (this.#activeSessionIds.has(candidate.sessionId) || this.#cancellationRequests.has(candidate.sessionId) || this.#preparing.has(candidate.sessionId) || (this.#sessionUseCounts.get(candidate.sessionId) ?? 0) > 0 || this.#isNativeSessionOperationActive(candidate.sessionId)) {
|
|
32805
|
+
continue;
|
|
32806
|
+
}
|
|
32807
|
+
return candidate;
|
|
32808
|
+
}
|
|
32809
|
+
if (candidate instanceof FoundAcpNativeBrowserProcessEvictionCandidate && !this.#nativeBrowserPreparing.has(candidate.sessionId) && (this.#nativeBrowserUseCounts.get(candidate.sessionId) ?? 0) === 0) {
|
|
32810
|
+
return candidate;
|
|
32811
|
+
}
|
|
32812
|
+
}
|
|
32813
|
+
return new MissingAcpProcessEvictionCandidate();
|
|
32814
|
+
}
|
|
32815
|
+
#ownedProcessCount() {
|
|
32816
|
+
return this.#retainedProcesses.size + this.#startingProcessCount + this.#transientProcessCount + this.#retiringProcessCount;
|
|
32817
|
+
}
|
|
32818
|
+
async #retireProcess(runtime, retained, close) {
|
|
32819
|
+
if (retained) {
|
|
32820
|
+
this.#retainedProcesses.delete(runtime);
|
|
32821
|
+
this.#retiringProcessCount += 1;
|
|
32822
|
+
}
|
|
32823
|
+
try {
|
|
32824
|
+
await close();
|
|
32825
|
+
} finally {
|
|
32826
|
+
if (retained) {
|
|
32827
|
+
this.#retiringProcessCount -= 1;
|
|
32828
|
+
this.#notifyProcessCapacityChanged();
|
|
32829
|
+
}
|
|
32830
|
+
}
|
|
32831
|
+
}
|
|
32832
|
+
async #retireSessionProcess(sessionId, runtime, close) {
|
|
32833
|
+
const retained = this.#sessions.get(sessionId) === runtime;
|
|
32834
|
+
if (retained) {
|
|
32835
|
+
this.#sessions.delete(sessionId);
|
|
32836
|
+
}
|
|
32837
|
+
await this.#retireProcess(runtime, retained, close);
|
|
32838
|
+
}
|
|
32839
|
+
async #retireNativeBrowserProcess(sessionId, runtime, close) {
|
|
32840
|
+
const retained = this.#nativeBrowserSessions.get(sessionId) === runtime;
|
|
32841
|
+
if (retained) {
|
|
32842
|
+
this.#nativeBrowserSessions.delete(sessionId);
|
|
32843
|
+
this.#nativeBrowserStore.remove(sessionId);
|
|
32844
|
+
}
|
|
32845
|
+
await this.#retireProcess(runtime, retained, close);
|
|
32846
|
+
}
|
|
32847
|
+
async #reserveProcessCapacity(signal) {
|
|
32848
|
+
const lease = await this.#processCapacityLock.acquire(signal);
|
|
32849
|
+
try {
|
|
32850
|
+
for (; ; ) {
|
|
32851
|
+
signal.throwIfAborted();
|
|
32852
|
+
if (this.#ownedProcessCount() < MAX_ACP_PROCESSES) {
|
|
32853
|
+
this.#startingProcessCount += 1;
|
|
32854
|
+
return;
|
|
32855
|
+
}
|
|
32856
|
+
const candidate = this.#leastRecentlyUsedEvictionCandidate();
|
|
32857
|
+
if (candidate instanceof FoundAcpSessionProcessEvictionCandidate) {
|
|
32858
|
+
await this.#retireSessionProcess(
|
|
32859
|
+
candidate.sessionId,
|
|
32860
|
+
candidate.runtime,
|
|
32861
|
+
async () => await candidate.runtime.close()
|
|
32862
|
+
);
|
|
32863
|
+
continue;
|
|
32864
|
+
}
|
|
32865
|
+
if (candidate instanceof FoundAcpNativeBrowserProcessEvictionCandidate) {
|
|
32866
|
+
await this.#retireNativeBrowserProcess(
|
|
32867
|
+
candidate.sessionId,
|
|
32868
|
+
candidate.runtime,
|
|
32869
|
+
async () => await candidate.runtime.close()
|
|
32870
|
+
);
|
|
32871
|
+
continue;
|
|
32872
|
+
}
|
|
32873
|
+
const changed = this.#processCapacityChanged.promise;
|
|
32874
|
+
await waitForAcpProcessCapacity(changed, signal);
|
|
32875
|
+
}
|
|
32876
|
+
} finally {
|
|
32877
|
+
lease.release();
|
|
32878
|
+
}
|
|
32879
|
+
}
|
|
32880
|
+
async #startRetainedSessionProcess(options, start) {
|
|
32881
|
+
await this.#reserveProcessCapacity(options.signal);
|
|
32882
|
+
try {
|
|
32883
|
+
const runtime = await start();
|
|
32884
|
+
this.#startingProcessCount -= 1;
|
|
32885
|
+
this.#sessions.set(options.sessionId, runtime);
|
|
32886
|
+
this.#retainedProcesses.set(
|
|
32887
|
+
runtime,
|
|
32888
|
+
new FoundAcpSessionProcessEvictionCandidate(options.sessionId, runtime)
|
|
32889
|
+
);
|
|
32890
|
+
this.#notifyProcessCapacityChanged();
|
|
32891
|
+
return runtime;
|
|
32892
|
+
} catch (error62) {
|
|
32893
|
+
this.#startingProcessCount -= 1;
|
|
32894
|
+
this.#notifyProcessCapacityChanged();
|
|
32895
|
+
throw error62;
|
|
32896
|
+
}
|
|
32897
|
+
}
|
|
32898
|
+
async #startRetainedNativeBrowserProcess(options, start) {
|
|
32899
|
+
await this.#reserveProcessCapacity(options.signal);
|
|
32900
|
+
try {
|
|
32901
|
+
const runtime = await start();
|
|
32902
|
+
this.#startingProcessCount -= 1;
|
|
32903
|
+
this.#nativeBrowserSessions.set(options.sessionId, runtime);
|
|
32904
|
+
this.#retainedProcesses.set(
|
|
32905
|
+
runtime,
|
|
32906
|
+
new FoundAcpNativeBrowserProcessEvictionCandidate(options.sessionId, runtime)
|
|
32907
|
+
);
|
|
32908
|
+
this.#notifyProcessCapacityChanged();
|
|
32909
|
+
return runtime;
|
|
32910
|
+
} catch (error62) {
|
|
32911
|
+
this.#startingProcessCount -= 1;
|
|
32912
|
+
this.#notifyProcessCapacityChanged();
|
|
32913
|
+
throw error62;
|
|
32914
|
+
}
|
|
32915
|
+
}
|
|
32916
|
+
async #runWithTransientProcess(signal, start, operation, close) {
|
|
32917
|
+
await this.#reserveProcessCapacity(signal);
|
|
32918
|
+
let runtime;
|
|
32919
|
+
try {
|
|
32920
|
+
runtime = await start();
|
|
32921
|
+
} catch (error62) {
|
|
32922
|
+
this.#startingProcessCount -= 1;
|
|
32923
|
+
this.#notifyProcessCapacityChanged();
|
|
32924
|
+
throw error62;
|
|
32925
|
+
}
|
|
32926
|
+
this.#startingProcessCount -= 1;
|
|
32927
|
+
this.#transientProcessCount += 1;
|
|
32928
|
+
this.#notifyProcessCapacityChanged();
|
|
32929
|
+
try {
|
|
32930
|
+
return await operation(runtime);
|
|
32931
|
+
} finally {
|
|
32932
|
+
try {
|
|
32933
|
+
await close(runtime);
|
|
32934
|
+
} finally {
|
|
32935
|
+
this.#transientProcessCount -= 1;
|
|
32936
|
+
this.#notifyProcessCapacityChanged();
|
|
32937
|
+
}
|
|
32938
|
+
}
|
|
32939
|
+
}
|
|
32586
32940
|
async #startNativeBrowserPreparation(options) {
|
|
32587
32941
|
const operation = (async () => {
|
|
32588
32942
|
try {
|
|
32589
|
-
|
|
32943
|
+
return await this.#startRetainedNativeBrowserProcess(
|
|
32590
32944
|
options,
|
|
32591
|
-
() =>
|
|
32592
|
-
|
|
32945
|
+
async () => await AcpProcessSession.startNativeSessionBrowser(
|
|
32946
|
+
options,
|
|
32947
|
+
() => this.#nativeBrowserObserver,
|
|
32948
|
+
this.#nativeBrowserStore
|
|
32949
|
+
)
|
|
32593
32950
|
);
|
|
32594
|
-
this.#nativeBrowserSessions.set(options.sessionId, runtime);
|
|
32595
|
-
return runtime;
|
|
32596
32951
|
} finally {
|
|
32597
32952
|
this.#nativeBrowserPreparing.delete(options.sessionId);
|
|
32953
|
+
this.#notifyProcessCapacityChanged();
|
|
32598
32954
|
}
|
|
32599
32955
|
})();
|
|
32600
32956
|
this.#nativeBrowserPreparing.set(options.sessionId, operation);
|
|
@@ -32603,18 +32959,18 @@ var AcpSessionManager = class {
|
|
|
32603
32959
|
async #replaceNativeBrowserPreparation(existing, options) {
|
|
32604
32960
|
const operation = (async () => {
|
|
32605
32961
|
try {
|
|
32606
|
-
this.#
|
|
32607
|
-
await
|
|
32608
|
-
this.#nativeBrowserStore.remove(options.sessionId);
|
|
32609
|
-
const runtime = await AcpProcessSession.startNativeSessionBrowser(
|
|
32962
|
+
await this.#retireNativeBrowserProcess(options.sessionId, existing, async () => await existing.close());
|
|
32963
|
+
return await this.#startRetainedNativeBrowserProcess(
|
|
32610
32964
|
options,
|
|
32611
|
-
() =>
|
|
32612
|
-
|
|
32965
|
+
async () => await AcpProcessSession.startNativeSessionBrowser(
|
|
32966
|
+
options,
|
|
32967
|
+
() => this.#nativeBrowserObserver,
|
|
32968
|
+
this.#nativeBrowserStore
|
|
32969
|
+
)
|
|
32613
32970
|
);
|
|
32614
|
-
this.#nativeBrowserSessions.set(options.sessionId, runtime);
|
|
32615
|
-
return runtime;
|
|
32616
32971
|
} finally {
|
|
32617
32972
|
this.#nativeBrowserPreparing.delete(options.sessionId);
|
|
32973
|
+
this.#notifyProcessCapacityChanged();
|
|
32618
32974
|
}
|
|
32619
32975
|
})();
|
|
32620
32976
|
this.#nativeBrowserPreparing.set(options.sessionId, operation);
|
|
@@ -32623,11 +32979,13 @@ var AcpSessionManager = class {
|
|
|
32623
32979
|
async #startPreparation(options, metrics = unmeasuredOperationMetrics) {
|
|
32624
32980
|
const operation = (async () => {
|
|
32625
32981
|
try {
|
|
32626
|
-
|
|
32627
|
-
|
|
32628
|
-
|
|
32982
|
+
return await this.#startRetainedSessionProcess(
|
|
32983
|
+
options,
|
|
32984
|
+
async () => await AcpProcessSession.start(options, () => this.#observer, this.#store, metrics)
|
|
32985
|
+
);
|
|
32629
32986
|
} finally {
|
|
32630
32987
|
this.#preparing.delete(options.sessionId);
|
|
32988
|
+
this.#notifyProcessCapacityChanged();
|
|
32631
32989
|
}
|
|
32632
32990
|
})();
|
|
32633
32991
|
this.#preparing.set(options.sessionId, operation);
|
|
@@ -32636,17 +32994,19 @@ var AcpSessionManager = class {
|
|
|
32636
32994
|
async #startSessionForkAtTurnPreparation(options, sourceNativeSessionId, forkPoint) {
|
|
32637
32995
|
const operation = (async () => {
|
|
32638
32996
|
try {
|
|
32639
|
-
|
|
32997
|
+
return await this.#startRetainedSessionProcess(
|
|
32640
32998
|
options,
|
|
32641
|
-
|
|
32642
|
-
|
|
32643
|
-
|
|
32644
|
-
|
|
32999
|
+
async () => await AcpProcessSession.startSessionForkAtTurn(
|
|
33000
|
+
options,
|
|
33001
|
+
sourceNativeSessionId,
|
|
33002
|
+
forkPoint,
|
|
33003
|
+
() => this.#observer,
|
|
33004
|
+
this.#store
|
|
33005
|
+
)
|
|
32645
33006
|
);
|
|
32646
|
-
this.#sessions.set(options.sessionId, runtime);
|
|
32647
|
-
return runtime;
|
|
32648
33007
|
} finally {
|
|
32649
33008
|
this.#preparing.delete(options.sessionId);
|
|
33009
|
+
this.#notifyProcessCapacityChanged();
|
|
32650
33010
|
}
|
|
32651
33011
|
})();
|
|
32652
33012
|
this.#preparing.set(options.sessionId, operation);
|
|
@@ -32655,14 +33015,19 @@ var AcpSessionManager = class {
|
|
|
32655
33015
|
async #replacePreparation(existing, options, metrics) {
|
|
32656
33016
|
const operation = (async () => {
|
|
32657
33017
|
try {
|
|
32658
|
-
this.#
|
|
32659
|
-
|
|
33018
|
+
await this.#retireSessionProcess(
|
|
33019
|
+
options.sessionId,
|
|
33020
|
+
existing,
|
|
33021
|
+
async () => await metrics.measure("runtime-replacement-close", async () => await existing.close())
|
|
33022
|
+
);
|
|
32660
33023
|
this.#store.remove(options.sessionId);
|
|
32661
|
-
|
|
32662
|
-
|
|
32663
|
-
|
|
33024
|
+
return await this.#startRetainedSessionProcess(
|
|
33025
|
+
options,
|
|
33026
|
+
async () => await AcpProcessSession.start(options, () => this.#observer, this.#store, metrics)
|
|
33027
|
+
);
|
|
32664
33028
|
} finally {
|
|
32665
33029
|
this.#preparing.delete(options.sessionId);
|
|
33030
|
+
this.#notifyProcessCapacityChanged();
|
|
32666
33031
|
}
|
|
32667
33032
|
})();
|
|
32668
33033
|
this.#preparing.set(options.sessionId, operation);
|
|
@@ -32672,10 +33037,12 @@ var AcpSessionManager = class {
|
|
|
32672
33037
|
const desiredConfigOptions = existing.prepared().configOptions;
|
|
32673
33038
|
const operation = (async () => {
|
|
32674
33039
|
try {
|
|
32675
|
-
this.#
|
|
32676
|
-
await existing.close();
|
|
33040
|
+
await this.#retireSessionProcess(options.sessionId, existing, async () => await existing.close());
|
|
32677
33041
|
this.#store.remove(options.sessionId);
|
|
32678
|
-
const runtime = await
|
|
33042
|
+
const runtime = await this.#startRetainedSessionProcess(
|
|
33043
|
+
options,
|
|
33044
|
+
async () => await AcpProcessSession.start(options, () => this.#observer, this.#store)
|
|
33045
|
+
);
|
|
32679
33046
|
try {
|
|
32680
33047
|
for (const desired of desiredConfigOptions) {
|
|
32681
33048
|
const current = runtime.prepared().configOptions.find((option2) => option2.id === desired.id);
|
|
@@ -32707,14 +33074,14 @@ var AcpSessionManager = class {
|
|
|
32707
33074
|
}
|
|
32708
33075
|
}
|
|
32709
33076
|
} catch (error62) {
|
|
32710
|
-
await runtime.close();
|
|
33077
|
+
await this.#retireSessionProcess(options.sessionId, runtime, async () => await runtime.close());
|
|
32711
33078
|
this.#store.remove(options.sessionId);
|
|
32712
33079
|
throw error62;
|
|
32713
33080
|
}
|
|
32714
|
-
this.#sessions.set(options.sessionId, runtime);
|
|
32715
33081
|
return runtime;
|
|
32716
33082
|
} finally {
|
|
32717
33083
|
this.#preparing.delete(options.sessionId);
|
|
33084
|
+
this.#notifyProcessCapacityChanged();
|
|
32718
33085
|
}
|
|
32719
33086
|
})();
|
|
32720
33087
|
this.#preparing.set(options.sessionId, operation);
|
|
@@ -32736,6 +33103,7 @@ var AcpSessionManager = class {
|
|
|
32736
33103
|
if (pending !== void 0) {
|
|
32737
33104
|
const runtime2 = await metrics.measure("session-preparation-wait", async () => await pending);
|
|
32738
33105
|
if (runtime2.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
|
|
33106
|
+
this.#touchExpectedSession(options.sessionId, runtime2);
|
|
32739
33107
|
return runtime2.prepared();
|
|
32740
33108
|
}
|
|
32741
33109
|
return await this.prepareSession(options, metrics);
|
|
@@ -32743,6 +33111,7 @@ var AcpSessionManager = class {
|
|
|
32743
33111
|
const existing = this.#sessions.get(options.sessionId);
|
|
32744
33112
|
if (existing !== void 0) {
|
|
32745
33113
|
if (existing.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
|
|
33114
|
+
this.#touchExpectedSession(options.sessionId, existing);
|
|
32746
33115
|
return existing.prepared();
|
|
32747
33116
|
}
|
|
32748
33117
|
if (!existing.canRebind()) {
|
|
@@ -32763,22 +33132,24 @@ var AcpSessionManager = class {
|
|
|
32763
33132
|
* authoritative settings. Its identity and store are private to this
|
|
32764
33133
|
* operation and never become a Mobius Session.
|
|
32765
33134
|
*/
|
|
32766
|
-
inspectAgentSettings = async (options) =>
|
|
32767
|
-
|
|
33135
|
+
inspectAgentSettings = async (options) => await this.#runWithTransientProcess(
|
|
33136
|
+
options.signal,
|
|
33137
|
+
async () => await AcpProcessSession.start(
|
|
32768
33138
|
{
|
|
32769
33139
|
...options,
|
|
32770
33140
|
sessionId: `agent-settings-${crypto.randomUUID()}`
|
|
32771
33141
|
},
|
|
32772
33142
|
() => this.#agentSettingsObserver,
|
|
32773
33143
|
new MemoryAcpSessionStore()
|
|
32774
|
-
)
|
|
32775
|
-
|
|
33144
|
+
),
|
|
33145
|
+
(runtime) => {
|
|
32776
33146
|
const prepared = runtime.prepared();
|
|
32777
|
-
return
|
|
32778
|
-
|
|
32779
|
-
|
|
32780
|
-
}
|
|
32781
|
-
|
|
33147
|
+
return Promise.resolve(
|
|
33148
|
+
new AcpAgentSettingsSnapshot(prepared.agentName, prepared.agentVersion, prepared.configOptions)
|
|
33149
|
+
);
|
|
33150
|
+
},
|
|
33151
|
+
async (runtime) => await runtime.close()
|
|
33152
|
+
);
|
|
32782
33153
|
/**
|
|
32783
33154
|
* @deprecated Retained for the Bot-scoped legacy Agent-configuration API.
|
|
32784
33155
|
* Use inspectAgentSettings for Agent-scoped settings discovery.
|
|
@@ -32787,18 +33158,20 @@ var AcpSessionManager = class {
|
|
|
32787
33158
|
if (this.#preparing.has(options.sessionId) || this.#sessions.has(options.sessionId)) {
|
|
32788
33159
|
throw new AcpExecutionError("The configuration inspection session is already in use", {}, "session_busy");
|
|
32789
33160
|
}
|
|
32790
|
-
|
|
33161
|
+
this.#beginSessionUse(options.sessionId);
|
|
32791
33162
|
try {
|
|
32792
|
-
|
|
32793
|
-
} finally {
|
|
32794
|
-
if (this.#sessions.get(options.sessionId) === runtime) {
|
|
32795
|
-
this.#sessions.delete(options.sessionId);
|
|
32796
|
-
}
|
|
33163
|
+
const runtime = await this.#startPreparation(options, metrics);
|
|
32797
33164
|
try {
|
|
32798
|
-
|
|
33165
|
+
return runtime.prepared();
|
|
32799
33166
|
} finally {
|
|
32800
|
-
|
|
33167
|
+
try {
|
|
33168
|
+
await this.#retireSessionProcess(options.sessionId, runtime, async () => await runtime.close());
|
|
33169
|
+
} finally {
|
|
33170
|
+
this.#store.remove(options.sessionId);
|
|
33171
|
+
}
|
|
32801
33172
|
}
|
|
33173
|
+
} finally {
|
|
33174
|
+
this.#endSessionUse(options.sessionId);
|
|
32802
33175
|
}
|
|
32803
33176
|
};
|
|
32804
33177
|
prepareExecutionSession = async (options) => {
|
|
@@ -32819,6 +33192,7 @@ var AcpSessionManager = class {
|
|
|
32819
33192
|
);
|
|
32820
33193
|
}
|
|
32821
33194
|
if (existing.usesEnvironment(options.agent.environment)) {
|
|
33195
|
+
this.#touchExpectedSession(options.sessionId, existing);
|
|
32822
33196
|
return existing.prepared();
|
|
32823
33197
|
}
|
|
32824
33198
|
if (!existing.canRebind()) {
|
|
@@ -32835,6 +33209,7 @@ var AcpSessionManager = class {
|
|
|
32835
33209
|
if (pending !== void 0) {
|
|
32836
33210
|
const runtime2 = await pending;
|
|
32837
33211
|
if (runtime2.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
|
|
33212
|
+
this.#touchExpectedNativeBrowserSession(options.sessionId, runtime2);
|
|
32838
33213
|
return runtime2.prepared();
|
|
32839
33214
|
}
|
|
32840
33215
|
return await this.prepareNativeSessionBrowser(options);
|
|
@@ -32842,6 +33217,7 @@ var AcpSessionManager = class {
|
|
|
32842
33217
|
const existing = this.#nativeBrowserSessions.get(options.sessionId);
|
|
32843
33218
|
if (existing !== void 0) {
|
|
32844
33219
|
if (existing.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
|
|
33220
|
+
this.#touchExpectedNativeBrowserSession(options.sessionId, existing);
|
|
32845
33221
|
return existing.prepared();
|
|
32846
33222
|
}
|
|
32847
33223
|
if (!existing.canRebind()) {
|
|
@@ -32858,8 +33234,13 @@ var AcpSessionManager = class {
|
|
|
32858
33234
|
return runtime.prepared();
|
|
32859
33235
|
};
|
|
32860
33236
|
configureSession = async (options) => {
|
|
32861
|
-
|
|
32862
|
-
|
|
33237
|
+
this.#beginSessionUse(options.sessionId);
|
|
33238
|
+
try {
|
|
33239
|
+
const runtime = await this.ensureSession(options);
|
|
33240
|
+
return await runtime.configure(options);
|
|
33241
|
+
} finally {
|
|
33242
|
+
this.#endSessionUse(options.sessionId);
|
|
33243
|
+
}
|
|
32863
33244
|
};
|
|
32864
33245
|
cancelPrompt = async (sessionId) => {
|
|
32865
33246
|
const existing = this.#cancellationRequests.get(sessionId);
|
|
@@ -32875,6 +33256,8 @@ var AcpSessionManager = class {
|
|
|
32875
33256
|
} finally {
|
|
32876
33257
|
if (this.#sessions.get(sessionId) === runtime) {
|
|
32877
33258
|
this.#sessions.delete(sessionId);
|
|
33259
|
+
this.#retainedProcesses.delete(runtime);
|
|
33260
|
+
this.#notifyProcessCapacityChanged();
|
|
32878
33261
|
}
|
|
32879
33262
|
}
|
|
32880
33263
|
}
|
|
@@ -32964,10 +33347,7 @@ var AcpSessionManager = class {
|
|
|
32964
33347
|
return this.#cancellationRequests.has(options.sessionId) ? { stopReason: "cancelled" } : result;
|
|
32965
33348
|
} catch (error62) {
|
|
32966
33349
|
if (this.#cancellationRequests.has(options.sessionId)) {
|
|
32967
|
-
|
|
32968
|
-
this.#sessions.delete(options.sessionId);
|
|
32969
|
-
}
|
|
32970
|
-
await runtime.closeProcess();
|
|
33350
|
+
await this.#cancellationRequests.get(options.sessionId);
|
|
32971
33351
|
return { stopReason: "cancelled" };
|
|
32972
33352
|
}
|
|
32973
33353
|
throw error62;
|
|
@@ -32975,8 +33355,11 @@ var AcpSessionManager = class {
|
|
|
32975
33355
|
} catch (error62) {
|
|
32976
33356
|
const failedRuntime = this.#sessions.get(options.sessionId);
|
|
32977
33357
|
if (failedRuntime !== void 0) {
|
|
32978
|
-
this.#
|
|
32979
|
-
|
|
33358
|
+
await this.#retireSessionProcess(
|
|
33359
|
+
options.sessionId,
|
|
33360
|
+
failedRuntime,
|
|
33361
|
+
async () => await failedRuntime.close()
|
|
33362
|
+
);
|
|
32980
33363
|
}
|
|
32981
33364
|
if (this.#cancellationRequests.has(options.sessionId)) {
|
|
32982
33365
|
return { stopReason: "cancelled" };
|
|
@@ -32997,6 +33380,8 @@ var AcpSessionManager = class {
|
|
|
32997
33380
|
this.#activeCommandIds.delete(options.sessionId);
|
|
32998
33381
|
}
|
|
32999
33382
|
this.#cancellationRequests.delete(options.sessionId);
|
|
33383
|
+
this.#touchSession(options.sessionId);
|
|
33384
|
+
this.#notifyProcessCapacityChanged();
|
|
33000
33385
|
}
|
|
33001
33386
|
}
|
|
33002
33387
|
};
|
|
@@ -33015,11 +33400,16 @@ var AcpSessionManager = class {
|
|
|
33015
33400
|
await runtime.respondElicitation(options);
|
|
33016
33401
|
};
|
|
33017
33402
|
close = async () => {
|
|
33018
|
-
const sessions = [...this.#sessions.
|
|
33019
|
-
const nativeBrowserSessions = [...this.#nativeBrowserSessions.
|
|
33020
|
-
|
|
33021
|
-
|
|
33022
|
-
|
|
33403
|
+
const sessions = [...this.#sessions.entries()];
|
|
33404
|
+
const nativeBrowserSessions = [...this.#nativeBrowserSessions.entries()];
|
|
33405
|
+
await Promise.all([
|
|
33406
|
+
...sessions.map(
|
|
33407
|
+
async ([sessionId, runtime]) => await this.#retireSessionProcess(sessionId, runtime, async () => await runtime.close())
|
|
33408
|
+
),
|
|
33409
|
+
...nativeBrowserSessions.map(
|
|
33410
|
+
async ([sessionId, runtime]) => await this.#retireNativeBrowserProcess(sessionId, runtime, async () => await runtime.close())
|
|
33411
|
+
)
|
|
33412
|
+
]);
|
|
33023
33413
|
};
|
|
33024
33414
|
hasPreparedSession = (sessionId, agentId, cwd, additionalDirectories) => this.#sessions.get(sessionId)?.belongsTo(agentId, cwd, additionalDirectories) === true;
|
|
33025
33415
|
ensureSession = async (options) => {
|
|
@@ -33032,6 +33422,7 @@ var AcpSessionManager = class {
|
|
|
33032
33422
|
"session_identity_mismatch"
|
|
33033
33423
|
);
|
|
33034
33424
|
}
|
|
33425
|
+
this.#touchExpectedSession(options.sessionId, existing);
|
|
33035
33426
|
return existing;
|
|
33036
33427
|
}
|
|
33037
33428
|
await this.prepareSession(options);
|
|
@@ -33051,6 +33442,7 @@ var AcpSessionManager = class {
|
|
|
33051
33442
|
"session_identity_mismatch"
|
|
33052
33443
|
);
|
|
33053
33444
|
}
|
|
33445
|
+
this.#touchExpectedNativeBrowserSession(options.sessionId, existing);
|
|
33054
33446
|
return existing;
|
|
33055
33447
|
}
|
|
33056
33448
|
await this.prepareNativeSessionBrowser(options);
|
|
@@ -33060,7 +33452,14 @@ var AcpSessionManager = class {
|
|
|
33060
33452
|
}
|
|
33061
33453
|
return started;
|
|
33062
33454
|
}
|
|
33063
|
-
listNativeSessions = async (options, cursor) =>
|
|
33455
|
+
listNativeSessions = async (options, cursor) => {
|
|
33456
|
+
this.#beginNativeBrowserUse(options.sessionId);
|
|
33457
|
+
try {
|
|
33458
|
+
return await (await this.#ensureNativeSessionBrowser(options)).listNativeSessions(cursor, options.signal);
|
|
33459
|
+
} finally {
|
|
33460
|
+
this.#endNativeBrowserUse(options.sessionId);
|
|
33461
|
+
}
|
|
33462
|
+
};
|
|
33064
33463
|
previewNativeSession = async (options, nativeSessionId) => {
|
|
33065
33464
|
const key = `${options.agent.id}:${nativeSessionId}`;
|
|
33066
33465
|
const linked = this.#store.findNative(options.agent.id, nativeSessionId);
|
|
@@ -33073,17 +33472,19 @@ var AcpSessionManager = class {
|
|
|
33073
33472
|
}
|
|
33074
33473
|
this.#nativeOperations.add(key);
|
|
33075
33474
|
try {
|
|
33076
|
-
|
|
33077
|
-
options,
|
|
33078
|
-
() =>
|
|
33079
|
-
|
|
33475
|
+
return await this.#runWithTransientProcess(
|
|
33476
|
+
options.signal,
|
|
33477
|
+
async () => await AcpProcessSession.startNativeSessionBrowser(
|
|
33478
|
+
options,
|
|
33479
|
+
() => this.#nativeBrowserObserver,
|
|
33480
|
+
new MemoryAcpSessionStore()
|
|
33481
|
+
),
|
|
33482
|
+
async (runtime) => {
|
|
33483
|
+
runtime.selectNativeSession(nativeSessionId);
|
|
33484
|
+
return await runtime.loadHistory(options.signal);
|
|
33485
|
+
},
|
|
33486
|
+
async (runtime) => await runtime.closeProcess()
|
|
33080
33487
|
);
|
|
33081
|
-
try {
|
|
33082
|
-
runtime.selectNativeSession(nativeSessionId);
|
|
33083
|
-
return await runtime.loadHistory(options.signal);
|
|
33084
|
-
} finally {
|
|
33085
|
-
await runtime.closeProcess();
|
|
33086
|
-
}
|
|
33087
33488
|
} finally {
|
|
33088
33489
|
this.#nativeOperations.delete(key);
|
|
33089
33490
|
}
|
|
@@ -33103,36 +33504,46 @@ var AcpSessionManager = class {
|
|
|
33103
33504
|
}
|
|
33104
33505
|
const existing = linked[0];
|
|
33105
33506
|
if (origin.kind === "import" && existing !== void 0) {
|
|
33106
|
-
|
|
33107
|
-
...options,
|
|
33108
|
-
sessionId: existing.sessionId
|
|
33109
|
-
});
|
|
33110
|
-
if (this.#activeSessionIds.has(existing.sessionId) || this.#nativeOperations.has(key)) {
|
|
33111
|
-
throw new AcpExecutionError(
|
|
33112
|
-
"Wait for the native session's running operation to finish",
|
|
33113
|
-
{},
|
|
33114
|
-
"session_busy"
|
|
33115
|
-
);
|
|
33116
|
-
}
|
|
33117
|
-
this.#nativeOperations.add(key);
|
|
33507
|
+
this.#beginSessionUse(existing.sessionId);
|
|
33118
33508
|
try {
|
|
33119
|
-
const
|
|
33120
|
-
|
|
33121
|
-
|
|
33122
|
-
|
|
33123
|
-
|
|
33124
|
-
|
|
33125
|
-
|
|
33126
|
-
|
|
33127
|
-
|
|
33128
|
-
|
|
33509
|
+
const runtime = await this.ensureSession({
|
|
33510
|
+
...options,
|
|
33511
|
+
sessionId: existing.sessionId
|
|
33512
|
+
});
|
|
33513
|
+
if (this.#activeSessionIds.has(existing.sessionId) || this.#nativeOperations.has(key)) {
|
|
33514
|
+
throw new AcpExecutionError(
|
|
33515
|
+
"Wait for the native session's running operation to finish",
|
|
33516
|
+
{},
|
|
33517
|
+
"session_busy"
|
|
33518
|
+
);
|
|
33519
|
+
}
|
|
33520
|
+
this.#nativeOperations.add(key);
|
|
33521
|
+
try {
|
|
33522
|
+
const history = await runtime.loadHistory(options.signal);
|
|
33523
|
+
return {
|
|
33524
|
+
prepared: runtime.prepared(),
|
|
33525
|
+
sessionId: existing.sessionId,
|
|
33526
|
+
history
|
|
33527
|
+
};
|
|
33528
|
+
} catch (error62) {
|
|
33529
|
+
await this.#retireSessionProcess(
|
|
33530
|
+
existing.sessionId,
|
|
33531
|
+
runtime,
|
|
33532
|
+
async () => await runtime.closeProcess()
|
|
33533
|
+
);
|
|
33534
|
+
throw error62;
|
|
33535
|
+
} finally {
|
|
33536
|
+
this.#nativeOperations.delete(key);
|
|
33537
|
+
this.#notifyProcessCapacityChanged();
|
|
33538
|
+
}
|
|
33129
33539
|
} finally {
|
|
33130
|
-
this.#
|
|
33540
|
+
this.#endSessionUse(existing.sessionId);
|
|
33131
33541
|
}
|
|
33132
33542
|
}
|
|
33133
33543
|
if (this.#sessions.has(options.sessionId) || this.#preparing.has(options.sessionId) || this.#store.read(options.sessionId) instanceof FoundAcpStoredSession || this.#store.read(options.sessionId) instanceof DeletedAcpStoredSession) {
|
|
33134
33544
|
throw new AcpExecutionError("The destination conversation already exists", {}, "session_identity_mismatch");
|
|
33135
33545
|
}
|
|
33546
|
+
this.#beginSessionUse(options.sessionId);
|
|
33136
33547
|
this.#nativeOperations.add(key);
|
|
33137
33548
|
try {
|
|
33138
33549
|
const runtime = await this.#startPreparation({ ...options, origin });
|
|
@@ -33146,23 +33557,23 @@ var AcpSessionManager = class {
|
|
|
33146
33557
|
history
|
|
33147
33558
|
};
|
|
33148
33559
|
} catch (error62) {
|
|
33149
|
-
this.#sessions.delete(options.sessionId);
|
|
33150
33560
|
this.#store.remove(options.sessionId);
|
|
33151
|
-
await runtime.closeProcess();
|
|
33561
|
+
await this.#retireSessionProcess(options.sessionId, runtime, async () => await runtime.closeProcess());
|
|
33152
33562
|
throw error62;
|
|
33153
33563
|
} finally {
|
|
33154
33564
|
this.#nativeOperations.delete(openedKey);
|
|
33565
|
+
this.#notifyProcessCapacityChanged();
|
|
33155
33566
|
}
|
|
33156
33567
|
} catch (error62) {
|
|
33157
33568
|
this.#store.remove(options.sessionId);
|
|
33158
33569
|
const runtime = this.#sessions.get(options.sessionId);
|
|
33159
|
-
this.#sessions.delete(options.sessionId);
|
|
33160
33570
|
if (runtime !== void 0) {
|
|
33161
|
-
await runtime.closeProcess();
|
|
33571
|
+
await this.#retireSessionProcess(options.sessionId, runtime, async () => await runtime.closeProcess());
|
|
33162
33572
|
}
|
|
33163
33573
|
throw error62;
|
|
33164
33574
|
} finally {
|
|
33165
33575
|
this.#nativeOperations.delete(key);
|
|
33576
|
+
this.#endSessionUse(options.sessionId);
|
|
33166
33577
|
}
|
|
33167
33578
|
};
|
|
33168
33579
|
forkSessionAtTurn = async (options, sourceSessionId, forkPoint) => {
|
|
@@ -33200,6 +33611,7 @@ var AcpSessionManager = class {
|
|
|
33200
33611
|
if (this.#sessions.has(options.sessionId) || this.#preparing.has(options.sessionId) || this.#store.read(options.sessionId) instanceof FoundAcpStoredSession || this.#store.read(options.sessionId) instanceof DeletedAcpStoredSession) {
|
|
33201
33612
|
throw new AcpExecutionError("The destination conversation already exists", {}, "session_identity_mismatch");
|
|
33202
33613
|
}
|
|
33614
|
+
this.#beginSessionUse(options.sessionId);
|
|
33203
33615
|
this.#nativeOperations.add(key);
|
|
33204
33616
|
try {
|
|
33205
33617
|
const runtime = await this.#startSessionForkAtTurnPreparation(
|
|
@@ -33216,48 +33628,58 @@ var AcpSessionManager = class {
|
|
|
33216
33628
|
sessionId: options.sessionId
|
|
33217
33629
|
};
|
|
33218
33630
|
} catch (error62) {
|
|
33219
|
-
this.#sessions.delete(options.sessionId);
|
|
33220
33631
|
this.#store.remove(options.sessionId);
|
|
33221
|
-
await runtime.closeProcess();
|
|
33632
|
+
await this.#retireSessionProcess(options.sessionId, runtime, async () => await runtime.closeProcess());
|
|
33222
33633
|
throw error62;
|
|
33223
33634
|
} finally {
|
|
33224
33635
|
this.#nativeOperations.delete(openedKey);
|
|
33636
|
+
this.#notifyProcessCapacityChanged();
|
|
33225
33637
|
}
|
|
33226
33638
|
} finally {
|
|
33227
33639
|
this.#nativeOperations.delete(key);
|
|
33640
|
+
this.#endSessionUse(options.sessionId);
|
|
33228
33641
|
}
|
|
33229
33642
|
};
|
|
33230
33643
|
deleteNativeSession = async (options, nativeSessionId) => {
|
|
33231
|
-
|
|
33232
|
-
const key = `${options.agent.id}:${nativeSessionId}`;
|
|
33233
|
-
const linked = this.#store.findNative(options.agent.id, nativeSessionId);
|
|
33234
|
-
if (this.#nativeOperations.has(key) || linked.some((entry) => this.#activeSessionIds.has(entry.sessionId) || this.#preparing.has(entry.sessionId))) {
|
|
33235
|
-
throw new AcpExecutionError(
|
|
33236
|
-
"Wait for the native session's running operation to finish",
|
|
33237
|
-
{},
|
|
33238
|
-
"session_busy"
|
|
33239
|
-
);
|
|
33240
|
-
}
|
|
33241
|
-
this.#nativeOperations.add(key);
|
|
33644
|
+
this.#beginNativeBrowserUse(options.sessionId);
|
|
33242
33645
|
try {
|
|
33243
|
-
|
|
33244
|
-
|
|
33245
|
-
|
|
33246
|
-
|
|
33247
|
-
|
|
33646
|
+
const runtime = await this.#ensureNativeSessionBrowser(options);
|
|
33647
|
+
const key = `${options.agent.id}:${nativeSessionId}`;
|
|
33648
|
+
const linked = this.#store.findNative(options.agent.id, nativeSessionId);
|
|
33649
|
+
if (this.#nativeOperations.has(key) || linked.some(
|
|
33650
|
+
(entry) => this.#activeSessionIds.has(entry.sessionId) || this.#preparing.has(entry.sessionId)
|
|
33651
|
+
)) {
|
|
33652
|
+
throw new AcpExecutionError(
|
|
33653
|
+
"Wait for the native session's running operation to finish",
|
|
33654
|
+
{},
|
|
33655
|
+
"session_busy"
|
|
33656
|
+
);
|
|
33657
|
+
}
|
|
33658
|
+
this.#nativeOperations.add(key);
|
|
33659
|
+
try {
|
|
33660
|
+
for (const entry of linked) {
|
|
33661
|
+
const active = this.#sessions.get(entry.sessionId);
|
|
33662
|
+
if (active !== void 0 && active !== runtime) {
|
|
33663
|
+
await this.#retireSessionProcess(entry.sessionId, active, async () => await active.close());
|
|
33664
|
+
}
|
|
33248
33665
|
}
|
|
33666
|
+
options.signal.throwIfAborted();
|
|
33667
|
+
await runtime.deleteNativeSession(nativeSessionId, options.signal);
|
|
33668
|
+
const deleted = this.#store.markDeleted(options.agent.id, nativeSessionId);
|
|
33669
|
+
if (runtime.nativeSessionId() === nativeSessionId) {
|
|
33670
|
+
await this.#retireNativeBrowserProcess(
|
|
33671
|
+
options.sessionId,
|
|
33672
|
+
runtime,
|
|
33673
|
+
async () => await runtime.close()
|
|
33674
|
+
);
|
|
33675
|
+
}
|
|
33676
|
+
return deleted;
|
|
33677
|
+
} finally {
|
|
33678
|
+
this.#nativeOperations.delete(key);
|
|
33679
|
+
this.#notifyProcessCapacityChanged();
|
|
33249
33680
|
}
|
|
33250
|
-
options.signal.throwIfAborted();
|
|
33251
|
-
await runtime.deleteNativeSession(nativeSessionId, options.signal);
|
|
33252
|
-
const deleted = this.#store.markDeleted(options.agent.id, nativeSessionId);
|
|
33253
|
-
if (runtime.nativeSessionId() === nativeSessionId) {
|
|
33254
|
-
this.#nativeBrowserSessions.delete(options.sessionId);
|
|
33255
|
-
this.#nativeBrowserStore.remove(options.sessionId);
|
|
33256
|
-
await runtime.close();
|
|
33257
|
-
}
|
|
33258
|
-
return deleted;
|
|
33259
33681
|
} finally {
|
|
33260
|
-
this.#
|
|
33682
|
+
this.#endNativeBrowserUse(options.sessionId);
|
|
33261
33683
|
}
|
|
33262
33684
|
};
|
|
33263
33685
|
};
|
|
@@ -33346,21 +33768,8 @@ import { randomBytes } from "node:crypto";
|
|
|
33346
33768
|
|
|
33347
33769
|
// src/bots/local-bot-grant-store.ts
|
|
33348
33770
|
import { createHash, randomUUID } from "node:crypto";
|
|
33349
|
-
import { stat as stat3 } from "node:fs/promises";
|
|
33350
33771
|
import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
|
|
33351
33772
|
var LOCAL_BOT_GRANT_LIFETIME_MILLISECONDS = 90 * 24 * 60 * 60 * 1e3;
|
|
33352
|
-
var identifier2 = external_exports.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/);
|
|
33353
|
-
var savedApprovalSchema = external_exports.object({
|
|
33354
|
-
local_grant_id: identifier2,
|
|
33355
|
-
bot_id: identifier2,
|
|
33356
|
-
binding_id: identifier2,
|
|
33357
|
-
binding_revision: external_exports.number().int().positive(),
|
|
33358
|
-
agent_ref: identifier2,
|
|
33359
|
-
workspace_ref: external_exports.string().min(1).max(2048),
|
|
33360
|
-
revocation_epoch: external_exports.number().int().nonnegative(),
|
|
33361
|
-
agent_identity_digest: external_exports.string().regex(/^[a-f0-9]{64}$/),
|
|
33362
|
-
workspace_identity_digest: external_exports.string().regex(/^[a-f0-9]{64}$/)
|
|
33363
|
-
}).readonly();
|
|
33364
33773
|
var LocalBotAuthorizationError = class extends Error {
|
|
33365
33774
|
code;
|
|
33366
33775
|
constructor(code, message, options = {}) {
|
|
@@ -33415,19 +33824,8 @@ function agentDigest(agent) {
|
|
|
33415
33824
|
})
|
|
33416
33825
|
);
|
|
33417
33826
|
}
|
|
33418
|
-
|
|
33419
|
-
|
|
33420
|
-
if (!metadata.isDirectory()) {
|
|
33421
|
-
throw new LocalBotAuthorizationError("binding_incompatible", "The Bot workspace is not a directory");
|
|
33422
|
-
}
|
|
33423
|
-
return digest(
|
|
33424
|
-
JSON.stringify({
|
|
33425
|
-
changedAtMilliseconds: metadata.ctimeMs,
|
|
33426
|
-
device: metadata.dev,
|
|
33427
|
-
inode: metadata.ino,
|
|
33428
|
-
path: path2
|
|
33429
|
-
})
|
|
33430
|
-
);
|
|
33827
|
+
function workspaceDigest(path2) {
|
|
33828
|
+
return digest(path2);
|
|
33431
33829
|
}
|
|
33432
33830
|
function exactTargets(left, right) {
|
|
33433
33831
|
if (left.length !== right.length) {
|
|
@@ -33461,6 +33859,16 @@ function rowInteger(row, key) {
|
|
|
33461
33859
|
}
|
|
33462
33860
|
return value;
|
|
33463
33861
|
}
|
|
33862
|
+
function rowHasInteger(row, key) {
|
|
33863
|
+
const value = Reflect.get(row, key);
|
|
33864
|
+
if (value === null) {
|
|
33865
|
+
return false;
|
|
33866
|
+
}
|
|
33867
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value)) {
|
|
33868
|
+
throw new LocalBotAuthorizationError("local_grant_invalid", "The local Bot grant is invalid");
|
|
33869
|
+
}
|
|
33870
|
+
return true;
|
|
33871
|
+
}
|
|
33464
33872
|
function parseTargets(encoded) {
|
|
33465
33873
|
let value;
|
|
33466
33874
|
try {
|
|
@@ -33484,17 +33892,6 @@ function parseSessionConfigurations(encoded) {
|
|
|
33484
33892
|
}
|
|
33485
33893
|
var LocalBotGrantStore = class {
|
|
33486
33894
|
#database;
|
|
33487
|
-
static containsBot = (path2, botId) => {
|
|
33488
|
-
const database = new DatabaseSync3(path2, { readOnly: true });
|
|
33489
|
-
try {
|
|
33490
|
-
if (database.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'local_bot_grants'").get() === void 0) {
|
|
33491
|
-
return false;
|
|
33492
|
-
}
|
|
33493
|
-
return database.prepare("SELECT local_grant_id FROM local_bot_grants WHERE bot_id = ? LIMIT 1").get(botId) !== void 0;
|
|
33494
|
-
} finally {
|
|
33495
|
-
database.close();
|
|
33496
|
-
}
|
|
33497
|
-
};
|
|
33498
33895
|
constructor(path2) {
|
|
33499
33896
|
this.#database = new DatabaseSync3(path2);
|
|
33500
33897
|
this.#database.exec(`
|
|
@@ -33532,78 +33929,6 @@ var LocalBotGrantStore = class {
|
|
|
33532
33929
|
) STRICT;
|
|
33533
33930
|
`);
|
|
33534
33931
|
}
|
|
33535
|
-
/** Only the local CLI may invoke this explicit approval transition. */
|
|
33536
|
-
reapprove = async (botId, catalog, directories, bindingAuthorityId, now, signal) => {
|
|
33537
|
-
signal.throwIfAborted();
|
|
33538
|
-
if (!identifier2.safeParse(botId).success) {
|
|
33539
|
-
throw new LocalBotAuthorizationError("invalid_request", "The Bot ID is invalid");
|
|
33540
|
-
}
|
|
33541
|
-
const row = this.#database.prepare("SELECT * FROM local_bot_grants WHERE bot_id = ? ORDER BY binding_revision DESC LIMIT 1").get(botId);
|
|
33542
|
-
if (row === void 0) {
|
|
33543
|
-
throw new LocalBotAuthorizationError("bot_not_found", "This machine has no saved approval for that Bot");
|
|
33544
|
-
}
|
|
33545
|
-
const parsed = savedApprovalSchema.safeParse(row);
|
|
33546
|
-
if (!parsed.success) {
|
|
33547
|
-
throw new LocalBotAuthorizationError("local_grant_invalid", "The saved Bot approval is invalid", {
|
|
33548
|
-
cause: parsed.error
|
|
33549
|
-
});
|
|
33550
|
-
}
|
|
33551
|
-
const saved = parsed.data;
|
|
33552
|
-
const agent = catalog.find(saved.agent_ref);
|
|
33553
|
-
if (!agent.capabilities.embeddedContextPrompt) {
|
|
33554
|
-
throw new LocalBotAuthorizationError("binding_incompatible", "The local Agent cannot apply Bot context");
|
|
33555
|
-
}
|
|
33556
|
-
const [adapterUnchanged, agentUnchanged] = await Promise.all([
|
|
33557
|
-
revalidateExecutable(agent.adapterIdentity),
|
|
33558
|
-
revalidateExecutable(agent.agentIdentity)
|
|
33559
|
-
]);
|
|
33560
|
-
signal.throwIfAborted();
|
|
33561
|
-
if (!adapterUnchanged || !agentUnchanged) {
|
|
33562
|
-
throw new LocalBotAuthorizationError(
|
|
33563
|
-
"binding_incompatible",
|
|
33564
|
-
"The local Agent executable changed before approval"
|
|
33565
|
-
);
|
|
33566
|
-
}
|
|
33567
|
-
const workspacePath = await directories.resolve(bindingAuthorityId, saved.workspace_ref, signal);
|
|
33568
|
-
const workspaceIdentityDigest = await workspaceDigest(workspacePath);
|
|
33569
|
-
signal.throwIfAborted();
|
|
33570
|
-
this.#database.exec("BEGIN IMMEDIATE");
|
|
33571
|
-
try {
|
|
33572
|
-
const result = this.#database.prepare(`UPDATE local_bot_grants
|
|
33573
|
-
SET agent_identity_digest = ?, workspace_identity_digest = ?, workspace_path = ?,
|
|
33574
|
-
revoked_at = NULL, expires_at = ?, revocation_epoch = revocation_epoch + 1
|
|
33575
|
-
WHERE local_grant_id = ? AND revocation_epoch = ?
|
|
33576
|
-
AND agent_identity_digest = ? AND workspace_identity_digest = ?
|
|
33577
|
-
AND binding_revision = (SELECT MAX(binding_revision) FROM local_bot_grants WHERE bot_id = ?)`).run(
|
|
33578
|
-
agentDigest(agent),
|
|
33579
|
-
workspaceIdentityDigest,
|
|
33580
|
-
workspacePath,
|
|
33581
|
-
now + LOCAL_BOT_GRANT_LIFETIME_MILLISECONDS,
|
|
33582
|
-
saved.local_grant_id,
|
|
33583
|
-
saved.revocation_epoch,
|
|
33584
|
-
saved.agent_identity_digest,
|
|
33585
|
-
saved.workspace_identity_digest,
|
|
33586
|
-
botId
|
|
33587
|
-
);
|
|
33588
|
-
if (result.changes !== 1) {
|
|
33589
|
-
throw new LocalBotAuthorizationError(
|
|
33590
|
-
"binding_not_approved",
|
|
33591
|
-
"The Bot binding changed during approval; run the command again"
|
|
33592
|
-
);
|
|
33593
|
-
}
|
|
33594
|
-
this.#database.prepare(`INSERT INTO audit_events (recorded_at, event, command_id, session_id, details_json)
|
|
33595
|
-
VALUES (?, 'bot_binding_locally_reapproved', ?, '', ?)`).run(
|
|
33596
|
-
new Date(now).toISOString(),
|
|
33597
|
-
saved.binding_id,
|
|
33598
|
-
JSON.stringify({ botId, bindingId: saved.binding_id, agentRef: saved.agent_ref })
|
|
33599
|
-
);
|
|
33600
|
-
this.#database.exec("COMMIT");
|
|
33601
|
-
} catch (cause) {
|
|
33602
|
-
this.#database.exec("ROLLBACK");
|
|
33603
|
-
throw cause;
|
|
33604
|
-
}
|
|
33605
|
-
return { bindingId: saved.binding_id, workspacePath, agentRef: saved.agent_ref };
|
|
33606
|
-
};
|
|
33607
33932
|
approve = async (request, catalog, directories, bindingAuthorityId, now, signal) => {
|
|
33608
33933
|
signal.throwIfAborted();
|
|
33609
33934
|
const existing = this.#database.prepare(
|
|
@@ -33693,8 +34018,7 @@ var LocalBotGrantStore = class {
|
|
|
33693
34018
|
WHERE grants.local_grant_id = ? AND grants.bot_id = ?
|
|
33694
34019
|
AND behavior_revision_id = ? AND behavior_digest = ?
|
|
33695
34020
|
AND binding_id = ? AND binding_revision = ?
|
|
33696
|
-
AND agent_ref =
|
|
33697
|
-
AND revoked_at IS NULL AND expires_at > ?`
|
|
34021
|
+
AND agent_ref = ?`
|
|
33698
34022
|
).get(
|
|
33699
34023
|
command.localGrantId,
|
|
33700
34024
|
command.botId,
|
|
@@ -33702,8 +34026,7 @@ var LocalBotGrantStore = class {
|
|
|
33702
34026
|
command.behaviorDigest,
|
|
33703
34027
|
command.bindingId,
|
|
33704
34028
|
command.bindingRevision,
|
|
33705
|
-
command.agentId
|
|
33706
|
-
now
|
|
34029
|
+
command.agentId
|
|
33707
34030
|
);
|
|
33708
34031
|
if (row === void 0) {
|
|
33709
34032
|
throw new LocalBotAuthorizationError(
|
|
@@ -33716,14 +34039,14 @@ var LocalBotGrantStore = class {
|
|
|
33716
34039
|
if (!exactTargets(approvedTargets, requestedTargets)) {
|
|
33717
34040
|
throw new LocalBotAuthorizationError(
|
|
33718
34041
|
"binding_not_approved",
|
|
33719
|
-
"The Bot execution target policy
|
|
34042
|
+
"The Bot execution target policy differs from its binding"
|
|
33720
34043
|
);
|
|
33721
34044
|
}
|
|
33722
34045
|
const approvedConfigurations = parseSessionConfigurations(rowString(row, "session_configurations_json"));
|
|
33723
34046
|
if (!exactSessionConfigurations(approvedConfigurations, command.sessionConfigurations)) {
|
|
33724
34047
|
throw new LocalBotAuthorizationError(
|
|
33725
34048
|
"binding_not_approved",
|
|
33726
|
-
"The Bot Agent configuration
|
|
34049
|
+
"The Bot Agent configuration differs from its binding"
|
|
33727
34050
|
);
|
|
33728
34051
|
}
|
|
33729
34052
|
const agent = catalog.find(command.agentId);
|
|
@@ -33732,17 +34055,29 @@ var LocalBotGrantStore = class {
|
|
|
33732
34055
|
revalidateExecutable(agent.agentIdentity)
|
|
33733
34056
|
]);
|
|
33734
34057
|
signal.throwIfAborted();
|
|
34058
|
+
if (!adapterUnchanged || !agentUnchanged) {
|
|
34059
|
+
throw new LocalBotAuthorizationError(
|
|
34060
|
+
"binding_incompatible",
|
|
34061
|
+
"The local Agent executable changed while the Runtime is active; restart the Runtime"
|
|
34062
|
+
);
|
|
34063
|
+
}
|
|
33735
34064
|
const workspaceRef = rowString(row, "workspace_ref");
|
|
33736
34065
|
const workspacePath = await directories.resolve(bindingAuthorityId, workspaceRef, signal);
|
|
33737
34066
|
const currentAgentDigest = agentDigest(agent);
|
|
33738
|
-
const currentWorkspaceDigest =
|
|
34067
|
+
const currentWorkspaceDigest = workspaceDigest(workspacePath);
|
|
33739
34068
|
signal.throwIfAborted();
|
|
33740
|
-
|
|
33741
|
-
|
|
33742
|
-
|
|
33743
|
-
|
|
33744
|
-
|
|
34069
|
+
let expiresAt = rowInteger(row, "expires_at");
|
|
34070
|
+
let revocationEpoch = rowInteger(row, "revocation_epoch");
|
|
34071
|
+
if (currentAgentDigest !== rowString(row, "agent_identity_digest") || currentWorkspaceDigest !== rowString(row, "workspace_identity_digest") || workspacePath !== rowString(row, "workspace_path") || expiresAt <= now || rowHasInteger(row, "revoked_at")) {
|
|
34072
|
+
const refreshed = this.refreshTarget(
|
|
34073
|
+
rowString(row, "local_grant_id"),
|
|
34074
|
+
currentAgentDigest,
|
|
34075
|
+
currentWorkspaceDigest,
|
|
34076
|
+
workspacePath,
|
|
34077
|
+
now
|
|
33745
34078
|
);
|
|
34079
|
+
expiresAt = refreshed.expiresAt;
|
|
34080
|
+
revocationEpoch = refreshed.revocationEpoch;
|
|
33746
34081
|
}
|
|
33747
34082
|
if (command.behaviorInstructions.length > 0 && !agent.capabilities.embeddedContextPrompt) {
|
|
33748
34083
|
throw new LocalBotAuthorizationError(
|
|
@@ -33763,8 +34098,8 @@ var LocalBotGrantStore = class {
|
|
|
33763
34098
|
workspacePath,
|
|
33764
34099
|
currentWorkspaceDigest,
|
|
33765
34100
|
approvedTargets,
|
|
33766
|
-
|
|
33767
|
-
|
|
34101
|
+
expiresAt,
|
|
34102
|
+
revocationEpoch
|
|
33768
34103
|
);
|
|
33769
34104
|
};
|
|
33770
34105
|
recordUnavailable = (request, code, message, now) => {
|
|
@@ -33807,16 +34142,65 @@ var LocalBotGrantStore = class {
|
|
|
33807
34142
|
return {
|
|
33808
34143
|
agent,
|
|
33809
34144
|
agentIdentityDigest: agentDigest(agent),
|
|
33810
|
-
workspaceIdentityDigest:
|
|
34145
|
+
workspaceIdentityDigest: workspaceDigest(workspacePath),
|
|
33811
34146
|
workspacePath
|
|
33812
34147
|
};
|
|
33813
34148
|
};
|
|
33814
|
-
|
|
33815
|
-
|
|
33816
|
-
|
|
33817
|
-
|
|
33818
|
-
|
|
33819
|
-
|
|
34149
|
+
refreshTarget = (localGrantId, agentIdentityDigest, workspaceIdentityDigest, workspacePath, now) => {
|
|
34150
|
+
const expiresAt = now + LOCAL_BOT_GRANT_LIFETIME_MILLISECONDS;
|
|
34151
|
+
this.#database.exec("BEGIN IMMEDIATE");
|
|
34152
|
+
try {
|
|
34153
|
+
const current = this.#database.prepare("SELECT * FROM local_bot_grants WHERE local_grant_id = ?").get(localGrantId);
|
|
34154
|
+
if (current === void 0) {
|
|
34155
|
+
throw new LocalBotAuthorizationError("local_grant_invalid", "The local Bot grant is missing");
|
|
34156
|
+
}
|
|
34157
|
+
const currentExpiresAt = rowInteger(current, "expires_at");
|
|
34158
|
+
const currentRevocationEpoch = rowInteger(current, "revocation_epoch");
|
|
34159
|
+
if (agentIdentityDigest === rowString(current, "agent_identity_digest") && workspaceIdentityDigest === rowString(current, "workspace_identity_digest") && workspacePath === rowString(current, "workspace_path") && currentExpiresAt > now && !rowHasInteger(current, "revoked_at")) {
|
|
34160
|
+
this.#database.exec("COMMIT");
|
|
34161
|
+
return { expiresAt: currentExpiresAt, revocationEpoch: currentRevocationEpoch };
|
|
34162
|
+
}
|
|
34163
|
+
const result = this.#database.prepare(
|
|
34164
|
+
`UPDATE local_bot_grants
|
|
34165
|
+
SET agent_identity_digest = ?, workspace_identity_digest = ?, workspace_path = ?,
|
|
34166
|
+
expires_at = ?, revoked_at = NULL, revocation_epoch = revocation_epoch + 1
|
|
34167
|
+
WHERE local_grant_id = ? AND revocation_epoch = ?`
|
|
34168
|
+
).run(
|
|
34169
|
+
agentIdentityDigest,
|
|
34170
|
+
workspaceIdentityDigest,
|
|
34171
|
+
workspacePath,
|
|
34172
|
+
expiresAt,
|
|
34173
|
+
localGrantId,
|
|
34174
|
+
currentRevocationEpoch
|
|
34175
|
+
);
|
|
34176
|
+
if (result.changes !== 1) {
|
|
34177
|
+
throw new LocalBotAuthorizationError(
|
|
34178
|
+
"local_grant_invalid",
|
|
34179
|
+
"The local Bot grant target could not be refreshed"
|
|
34180
|
+
);
|
|
34181
|
+
}
|
|
34182
|
+
this.#database.prepare(
|
|
34183
|
+
`INSERT INTO audit_events (recorded_at, event, command_id, session_id, details_json)
|
|
34184
|
+
VALUES (?, 'bot_binding_target_refreshed', ?, '', ?)`
|
|
34185
|
+
).run(
|
|
34186
|
+
new Date(now).toISOString(),
|
|
34187
|
+
rowString(current, "binding_id"),
|
|
34188
|
+
JSON.stringify({
|
|
34189
|
+
agentIdentityChanged: agentIdentityDigest !== rowString(current, "agent_identity_digest"),
|
|
34190
|
+
bindingId: rowString(current, "binding_id"),
|
|
34191
|
+
botId: rowString(current, "bot_id"),
|
|
34192
|
+
expired: currentExpiresAt <= now,
|
|
34193
|
+
revived: rowHasInteger(current, "revoked_at"),
|
|
34194
|
+
workspaceIdentityChanged: workspaceIdentityDigest !== rowString(current, "workspace_identity_digest"),
|
|
34195
|
+
workspacePathChanged: workspacePath !== rowString(current, "workspace_path")
|
|
34196
|
+
})
|
|
34197
|
+
);
|
|
34198
|
+
this.#database.exec("COMMIT");
|
|
34199
|
+
return { expiresAt, revocationEpoch: currentRevocationEpoch + 1 };
|
|
34200
|
+
} catch (cause) {
|
|
34201
|
+
this.#database.exec("ROLLBACK");
|
|
34202
|
+
throw cause;
|
|
34203
|
+
}
|
|
33820
34204
|
};
|
|
33821
34205
|
};
|
|
33822
34206
|
|
|
@@ -34314,7 +34698,7 @@ var BotOutboundIpcServer = class {
|
|
|
34314
34698
|
|
|
34315
34699
|
// src/pairing/pair-local-machine.ts
|
|
34316
34700
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
34317
|
-
import { mkdir as mkdir4, open as open4, realpath as realpath7, rename as rename3, stat as
|
|
34701
|
+
import { mkdir as mkdir4, open as open4, realpath as realpath7, rename as rename3, stat as stat6, writeFile as writeFile2 } from "node:fs/promises";
|
|
34318
34702
|
import { hostname as hostname3 } from "node:os";
|
|
34319
34703
|
import { basename as basename2, join as join15, resolve as resolve3 } from "node:path";
|
|
34320
34704
|
import { fetch as fetch3 } from "undici";
|
|
@@ -34381,10 +34765,11 @@ var IntegrationProbeFailed = class extends UnavailableInstalledAgent {
|
|
|
34381
34765
|
};
|
|
34382
34766
|
var IncompatibleAdapter = class extends UnavailableInstalledAgent {
|
|
34383
34767
|
code = "acp_incompatible";
|
|
34384
|
-
message
|
|
34768
|
+
message;
|
|
34385
34769
|
status = "incompatible_adapter";
|
|
34386
|
-
constructor(specification, agent) {
|
|
34770
|
+
constructor(specification, agent, message) {
|
|
34387
34771
|
super(specification, agent);
|
|
34772
|
+
this.message = message;
|
|
34388
34773
|
}
|
|
34389
34774
|
};
|
|
34390
34775
|
var AuthenticationRequiredAgent = class extends UnavailableInstalledAgent {
|
|
@@ -34425,7 +34810,7 @@ var LocalAgentInventory = class {
|
|
|
34425
34810
|
};
|
|
34426
34811
|
|
|
34427
34812
|
// src/agent-installation/managed-npm-package.ts
|
|
34428
|
-
import { mkdir as mkdir2, mkdtemp, open as open2, realpath as realpath3, rename, rm, stat as
|
|
34813
|
+
import { mkdir as mkdir2, mkdtemp, open as open2, realpath as realpath3, rename, rm, stat as stat3 } from "node:fs/promises";
|
|
34429
34814
|
import { delimiter, dirname as dirname4, isAbsolute as isAbsolute3, join as join4, relative as relative2, sep as sep2 } from "node:path";
|
|
34430
34815
|
var INSTALL_TIMEOUT_MILLISECONDS = 5 * 60 * 1e3;
|
|
34431
34816
|
var PACKAGE_METADATA_LIMIT_BYTES = 64 * 1024;
|
|
@@ -34647,7 +35032,7 @@ var ManagedNpmPackageInstaller = class {
|
|
|
34647
35032
|
install = async (root, definition2, environment, signal) => {
|
|
34648
35033
|
signal.throwIfAborted();
|
|
34649
35034
|
try {
|
|
34650
|
-
const metadata = await
|
|
35035
|
+
const metadata = await stat3(root);
|
|
34651
35036
|
if (metadata.isDirectory()) {
|
|
34652
35037
|
return await validateManagedNpmPackage(root, definition2);
|
|
34653
35038
|
}
|
|
@@ -34969,7 +35354,7 @@ var CursorCliAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
34969
35354
|
};
|
|
34970
35355
|
|
|
34971
35356
|
// src/agent-catalog/agents/deepseek-harness-agent.ts
|
|
34972
|
-
import { realpath as realpath4, stat as
|
|
35357
|
+
import { realpath as realpath4, stat as stat4 } from "node:fs/promises";
|
|
34973
35358
|
import { isAbsolute as isAbsolute5, join as join7, normalize as normalize2 } from "node:path";
|
|
34974
35359
|
|
|
34975
35360
|
// src/agent-installation/deepseek-managed-package.ts
|
|
@@ -34993,7 +35378,7 @@ async function validateAgentHome(path2) {
|
|
|
34993
35378
|
}
|
|
34994
35379
|
try {
|
|
34995
35380
|
const resolved = await realpath4(path2);
|
|
34996
|
-
const metadata = await
|
|
35381
|
+
const metadata = await stat4(resolved);
|
|
34997
35382
|
if (!metadata.isDirectory() || typeof process.getuid === "function" && metadata.uid !== process.getuid()) {
|
|
34998
35383
|
throw new Error("Agent home is not a user-owned directory");
|
|
34999
35384
|
}
|
|
@@ -35109,6 +35494,9 @@ var GeminiCliAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
35109
35494
|
// src/agent-catalog/agents/grok-build-agent.ts
|
|
35110
35495
|
import { realpath as realpath5 } from "node:fs/promises";
|
|
35111
35496
|
import { isAbsolute as isAbsolute6, join as join8, relative as relative3, sep as sep3 } from "node:path";
|
|
35497
|
+
import {
|
|
35498
|
+
RequestError as RequestError2
|
|
35499
|
+
} from "@agentclientprotocol/sdk";
|
|
35112
35500
|
|
|
35113
35501
|
// src/agent-installation/grok-managed-package.ts
|
|
35114
35502
|
var GROK_BUILD_MANAGED_VERSION = "1.0.21";
|
|
@@ -35221,11 +35609,23 @@ var GrokBuildAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
35221
35609
|
};
|
|
35222
35610
|
verifyAcp = async (connection, initialized, defaultWorkspace, signal) => {
|
|
35223
35611
|
const capabilities = initialized.agentCapabilities ?? {};
|
|
35224
|
-
|
|
35225
|
-
|
|
35226
|
-
|
|
35612
|
+
if (capabilities.loadSession !== true) {
|
|
35613
|
+
throw new AgentProbeError("acp_incompatible", "Grok Build did not report ACP session loading");
|
|
35614
|
+
}
|
|
35615
|
+
const authMethods = initialized.authMethods ?? [];
|
|
35616
|
+
if (authMethods.length === 0) {
|
|
35617
|
+
throw new AgentProbeError("acp_incompatible", "Grok Build did not report an ACP authentication method");
|
|
35618
|
+
}
|
|
35619
|
+
try {
|
|
35620
|
+
await verifySessionCreation(connection, capabilities, defaultWorkspace, signal, this.label);
|
|
35621
|
+
} catch (cause) {
|
|
35622
|
+
const detail = cause instanceof RequestError2 ? `ACP error ${cause.code}: ${cause.message}` : cause instanceof Error ? `${cause.name}: ${cause.message}` : "unknown error";
|
|
35623
|
+
throw new AgentProbeError(
|
|
35624
|
+
"acp_incompatible",
|
|
35625
|
+
`Grok Build could not create an ACP session (${detail}; auth methods: ${authMethods.map(({ id }) => id).join(", ")})`,
|
|
35626
|
+
{ cause }
|
|
35627
|
+
);
|
|
35227
35628
|
}
|
|
35228
|
-
await verifySessionCreation(connection, capabilities, defaultWorkspace, signal, this.label);
|
|
35229
35629
|
};
|
|
35230
35630
|
};
|
|
35231
35631
|
|
|
@@ -35260,7 +35660,7 @@ import { join as join10 } from "node:path";
|
|
|
35260
35660
|
// src/agent-installation/managed-agent-archive.ts
|
|
35261
35661
|
import { createHash as createHash2 } from "node:crypto";
|
|
35262
35662
|
import { createReadStream } from "node:fs";
|
|
35263
|
-
import { chmod as chmod2, copyFile, mkdir as mkdir3, mkdtemp as mkdtemp2, open as open3, realpath as realpath6, rename as rename2, rm as rm2, stat as
|
|
35663
|
+
import { chmod as chmod2, copyFile, mkdir as mkdir3, mkdtemp as mkdtemp2, open as open3, realpath as realpath6, rename as rename2, rm as rm2, stat as stat5, writeFile } from "node:fs/promises";
|
|
35264
35664
|
import { delimiter as delimiter2, dirname as dirname5, isAbsolute as isAbsolute7, join as join9, relative as relative4, sep as sep4 } from "node:path";
|
|
35265
35665
|
|
|
35266
35666
|
// src/agent-installation/verified-download.ts
|
|
@@ -35442,7 +35842,7 @@ async function readManifest(path2) {
|
|
|
35442
35842
|
async function validateManagedAgentArchive(root, definition2, signal) {
|
|
35443
35843
|
try {
|
|
35444
35844
|
const rootPath = await realpath6(root);
|
|
35445
|
-
const rootMetadata = await
|
|
35845
|
+
const rootMetadata = await stat5(rootPath);
|
|
35446
35846
|
if (!rootMetadata.isDirectory() || typeof process.getuid === "function" && rootMetadata.uid !== process.getuid()) {
|
|
35447
35847
|
throw new Error("Managed Agent root is not user-owned");
|
|
35448
35848
|
}
|
|
@@ -35768,7 +36168,7 @@ import {
|
|
|
35768
36168
|
methods as methods6,
|
|
35769
36169
|
ndJsonStream as ndJsonStream2,
|
|
35770
36170
|
PROTOCOL_VERSION as PROTOCOL_VERSION2,
|
|
35771
|
-
RequestError as
|
|
36171
|
+
RequestError as RequestError3
|
|
35772
36172
|
} from "@agentclientprotocol/sdk";
|
|
35773
36173
|
var ACP_OUTPUT_LIMIT_BYTES = 1024 * 1024;
|
|
35774
36174
|
var VerifiedAcpReadiness = class {
|
|
@@ -35917,7 +36317,7 @@ async function probeAcpReadiness(specification, agent, environment, defaultWorks
|
|
|
35917
36317
|
if (error62 instanceof AgentProbeError) {
|
|
35918
36318
|
throw error62;
|
|
35919
36319
|
}
|
|
35920
|
-
if (error62 instanceof
|
|
36320
|
+
if (error62 instanceof RequestError3 && error62.code === -32e3 && specification.authenticationCommand().length > 0) {
|
|
35921
36321
|
throw new AgentProbeError("authentication_required", "Agent authentication is required", { cause: error62 });
|
|
35922
36322
|
}
|
|
35923
36323
|
throw new AgentProbeError("acp_incompatible", "ACP adapter initialization failed", { cause: error62 });
|
|
@@ -36154,7 +36554,7 @@ function integrationProbeFailure(specification, agent, error62) {
|
|
|
36154
36554
|
if (error62.code === "authentication_required") {
|
|
36155
36555
|
return new AuthenticationRequiredAgent(specification, agent);
|
|
36156
36556
|
}
|
|
36157
|
-
return error62.code === "acp_incompatible" ? new IncompatibleAdapter(specification, agent) : new IntegrationProbeFailed(specification, agent, error62.code, error62.message);
|
|
36557
|
+
return error62.code === "acp_incompatible" ? new IncompatibleAdapter(specification, agent, error62.message) : new IntegrationProbeFailed(specification, agent, error62.code, error62.message);
|
|
36158
36558
|
}
|
|
36159
36559
|
if (error62 instanceof ProcessExecutionError) {
|
|
36160
36560
|
const code = error62.code === "process_timeout" ? "adapter_probe_timeout" : "adapter_probe_failed";
|
|
@@ -36405,7 +36805,7 @@ async function resolveDefaultWorkspace(path2) {
|
|
|
36405
36805
|
try {
|
|
36406
36806
|
await mkdir4(requestedWorkspace, { recursive: true, mode: 448 });
|
|
36407
36807
|
const defaultWorkspace = await realpath7(requestedWorkspace);
|
|
36408
|
-
const metadata = await
|
|
36808
|
+
const metadata = await stat6(defaultWorkspace);
|
|
36409
36809
|
if (!metadata.isDirectory()) {
|
|
36410
36810
|
throw new PairingClientError("invalid_workspace", "The default workspace is not a directory");
|
|
36411
36811
|
}
|
|
@@ -37104,14 +37504,14 @@ var FixedInstallationExecutor = class {
|
|
|
37104
37504
|
if (initialDiscovery instanceof MissingAgent) {
|
|
37105
37505
|
throw new InstallationManagerError(
|
|
37106
37506
|
"agent_not_installed",
|
|
37107
|
-
`Install ${specification.label} on this machine, then
|
|
37507
|
+
`Install ${specification.label} on this machine, then check local Agents again.`
|
|
37108
37508
|
);
|
|
37109
37509
|
}
|
|
37110
37510
|
const verifiedAgent = await findVerifiedAgentExecutable(specification, discoveryOptions);
|
|
37111
37511
|
if (verifiedAgent === null) {
|
|
37112
37512
|
throw new InstallationManagerError(
|
|
37113
37513
|
"agent_not_installed",
|
|
37114
|
-
`Install ${specification.label} on this machine, then
|
|
37514
|
+
`Install ${specification.label} on this machine, then check local Agents again.`
|
|
37115
37515
|
);
|
|
37116
37516
|
}
|
|
37117
37517
|
const agent = verifiedAgent.executable;
|
|
@@ -37588,7 +37988,7 @@ async function uploadRuntimeArtifact(config2, sessionId, image, signal) {
|
|
|
37588
37988
|
}
|
|
37589
37989
|
|
|
37590
37990
|
// src/authorization/workspace-directory.ts
|
|
37591
|
-
import { readdir as readdir2, realpath as realpath8, stat as
|
|
37991
|
+
import { readdir as readdir2, realpath as realpath8, stat as stat7 } from "node:fs/promises";
|
|
37592
37992
|
import { homedir as homedir2 } from "node:os";
|
|
37593
37993
|
import { basename as basename3, dirname as dirname6, isAbsolute as isAbsolute10, join as join16, normalize as normalize3, relative as relative5 } from "node:path";
|
|
37594
37994
|
var WorkspaceDirectoryListing = class {
|
|
@@ -37656,7 +38056,7 @@ var WorkspaceDirectoryService = class {
|
|
|
37656
38056
|
try {
|
|
37657
38057
|
const target = await realpath8(requested);
|
|
37658
38058
|
signal.throwIfAborted();
|
|
37659
|
-
const metadata = await
|
|
38059
|
+
const metadata = await stat7(target);
|
|
37660
38060
|
signal.throwIfAborted();
|
|
37661
38061
|
if (!isAbsolute10(target) || normalize3(target) !== target || !metadata.isDirectory()) {
|
|
37662
38062
|
throw new LocalAuthorizationError("The selected location is not a directory");
|
|
@@ -40564,32 +40964,9 @@ async function executeBotPrompt(outbox, publisher, command, config2, directories
|
|
|
40564
40964
|
}
|
|
40565
40965
|
const attachments = await resolvePromptArtifacts(config2, command, signal);
|
|
40566
40966
|
const applied = await applicator.apply(command, grant, attachments.resources, signal);
|
|
40567
|
-
const
|
|
40568
|
-
|
|
40569
|
-
|
|
40570
|
-
const executionSignal = AbortSignal.any([signal, deadlineSignal]);
|
|
40571
|
-
const agent = botExecutionAgent(grant.agent, lease.context.contextHandle, ipc.socketPath);
|
|
40572
|
-
await sessions.prepareExecutionSession({
|
|
40573
|
-
additionalDirectories: resolved.additionalDirectories,
|
|
40574
|
-
agent,
|
|
40575
|
-
cwd: resolved.cwd,
|
|
40576
|
-
sessionId: command.sessionId,
|
|
40577
|
-
signal: executionSignal
|
|
40578
|
-
});
|
|
40579
|
-
for (const selection of command.sessionConfigurations) {
|
|
40580
|
-
await sessions.configureSession({
|
|
40581
|
-
additionalDirectories: resolved.additionalDirectories,
|
|
40582
|
-
agent,
|
|
40583
|
-
booleanValue: selection.booleanValue,
|
|
40584
|
-
configId: selection.configId,
|
|
40585
|
-
cwd: resolved.cwd,
|
|
40586
|
-
requestId: `cfg_${randomUUID6()}`,
|
|
40587
|
-
sessionId: command.sessionId,
|
|
40588
|
-
signal: executionSignal,
|
|
40589
|
-
value: selection.value,
|
|
40590
|
-
valueType: selection.valueType
|
|
40591
|
-
});
|
|
40592
|
-
}
|
|
40967
|
+
const deadlineSignal = AbortSignal.timeout(remaining);
|
|
40968
|
+
const executionSignal = AbortSignal.any([signal, deadlineSignal]);
|
|
40969
|
+
const startExecution = () => {
|
|
40593
40970
|
audit.record({
|
|
40594
40971
|
commandId: command.commandId,
|
|
40595
40972
|
details: {
|
|
@@ -40614,56 +40991,106 @@ async function executeBotPrompt(outbox, publisher, command, config2, directories
|
|
|
40614
40991
|
attemptId
|
|
40615
40992
|
);
|
|
40616
40993
|
activateAttempt();
|
|
40617
|
-
|
|
40994
|
+
};
|
|
40995
|
+
let stopReason = "steered";
|
|
40996
|
+
if (command.disposition === SessionPromptDisposition.Steer) {
|
|
40997
|
+
startExecution();
|
|
40998
|
+
await sessions.steerPrompt({
|
|
40618
40999
|
additionalDirectories: resolved.additionalDirectories,
|
|
40619
|
-
agent,
|
|
41000
|
+
agent: grant.agent,
|
|
40620
41001
|
commandId: command.commandId,
|
|
40621
41002
|
cwd: resolved.cwd,
|
|
40622
41003
|
images: attachments.images,
|
|
40623
|
-
onActivity: activities.record,
|
|
40624
|
-
onText: (text3, messageId) => {
|
|
40625
|
-
publisher.recordAttempt(
|
|
40626
|
-
command.sessionId,
|
|
40627
|
-
encodeAgentMessageDeltaEvent({
|
|
40628
|
-
commandId: command.commandId,
|
|
40629
|
-
kind: AGENT_MESSAGE_DELTA_KIND,
|
|
40630
|
-
messageId,
|
|
40631
|
-
sessionId: command.sessionId,
|
|
40632
|
-
text: text3
|
|
40633
|
-
}),
|
|
40634
|
-
attemptId
|
|
40635
|
-
);
|
|
40636
|
-
return Promise.resolve();
|
|
40637
|
-
},
|
|
40638
41004
|
prompt: command.prompt,
|
|
40639
41005
|
resources: applied.resources,
|
|
40640
41006
|
sessionId: command.sessionId,
|
|
40641
|
-
signal: executionSignal
|
|
41007
|
+
signal: executionSignal,
|
|
41008
|
+
targetCommandId: command.targetCommandId
|
|
40642
41009
|
});
|
|
40643
|
-
|
|
40644
|
-
|
|
40645
|
-
|
|
40646
|
-
|
|
41010
|
+
} else {
|
|
41011
|
+
if (command.disposition === SessionPromptDisposition.Queue && !outbox.isTerminalExecution(command.targetCommandId, command.sessionId)) {
|
|
41012
|
+
throw new AcpExecutionError(
|
|
41013
|
+
"The queued Bot prompt target is unavailable",
|
|
41014
|
+
{},
|
|
41015
|
+
"prompt_queue_target_unavailable"
|
|
41016
|
+
);
|
|
41017
|
+
}
|
|
41018
|
+
const lease = contexts.activate(command);
|
|
41019
|
+
try {
|
|
41020
|
+
const agent = botExecutionAgent(grant.agent, lease.context.contextHandle, ipc.socketPath);
|
|
41021
|
+
await sessions.prepareExecutionSession({
|
|
41022
|
+
additionalDirectories: resolved.additionalDirectories,
|
|
41023
|
+
agent,
|
|
41024
|
+
cwd: resolved.cwd,
|
|
41025
|
+
sessionId: command.sessionId,
|
|
41026
|
+
signal: executionSignal
|
|
41027
|
+
});
|
|
41028
|
+
for (const selection of command.sessionConfigurations) {
|
|
41029
|
+
await sessions.configureSession({
|
|
41030
|
+
additionalDirectories: resolved.additionalDirectories,
|
|
41031
|
+
agent,
|
|
41032
|
+
booleanValue: selection.booleanValue,
|
|
41033
|
+
configId: selection.configId,
|
|
41034
|
+
cwd: resolved.cwd,
|
|
41035
|
+
requestId: `cfg_${randomUUID6()}`,
|
|
41036
|
+
sessionId: command.sessionId,
|
|
41037
|
+
signal: executionSignal,
|
|
41038
|
+
value: selection.value,
|
|
41039
|
+
valueType: selection.valueType
|
|
41040
|
+
});
|
|
41041
|
+
}
|
|
41042
|
+
startExecution();
|
|
41043
|
+
const result = await sessions.runPrompt({
|
|
41044
|
+
additionalDirectories: resolved.additionalDirectories,
|
|
41045
|
+
agent,
|
|
40647
41046
|
commandId: command.commandId,
|
|
40648
|
-
|
|
41047
|
+
cwd: resolved.cwd,
|
|
41048
|
+
disposition: command.disposition,
|
|
41049
|
+
images: attachments.images,
|
|
41050
|
+
onActivity: activities.record,
|
|
41051
|
+
onText: (text3, messageId) => {
|
|
41052
|
+
publisher.recordAttempt(
|
|
41053
|
+
command.sessionId,
|
|
41054
|
+
encodeAgentMessageDeltaEvent({
|
|
41055
|
+
commandId: command.commandId,
|
|
41056
|
+
kind: AGENT_MESSAGE_DELTA_KIND,
|
|
41057
|
+
messageId,
|
|
41058
|
+
sessionId: command.sessionId,
|
|
41059
|
+
text: text3
|
|
41060
|
+
}),
|
|
41061
|
+
attemptId
|
|
41062
|
+
);
|
|
41063
|
+
return Promise.resolve();
|
|
41064
|
+
},
|
|
41065
|
+
prompt: command.prompt,
|
|
41066
|
+
resources: applied.resources,
|
|
40649
41067
|
sessionId: command.sessionId,
|
|
40650
|
-
|
|
40651
|
-
|
|
40652
|
-
|
|
40653
|
-
|
|
40654
|
-
|
|
40655
|
-
|
|
40656
|
-
|
|
40657
|
-
);
|
|
40658
|
-
audit.record({
|
|
40659
|
-
commandId: command.commandId,
|
|
40660
|
-
details: { botId: command.botId, executionId: command.executionId },
|
|
40661
|
-
event: result.stopReason === "cancelled" ? "bot_session_cancelled" : "bot_session_completed",
|
|
40662
|
-
sessionId: command.sessionId
|
|
40663
|
-
});
|
|
40664
|
-
} finally {
|
|
40665
|
-
lease.release();
|
|
41068
|
+
signal: executionSignal,
|
|
41069
|
+
targetCommandId: command.targetCommandId
|
|
41070
|
+
});
|
|
41071
|
+
stopReason = result.stopReason;
|
|
41072
|
+
} finally {
|
|
41073
|
+
lease.release();
|
|
41074
|
+
}
|
|
40666
41075
|
}
|
|
41076
|
+
activities.flush();
|
|
41077
|
+
publisher.recordAttempt(
|
|
41078
|
+
command.sessionId,
|
|
41079
|
+
encodeSessionCompletedEvent({
|
|
41080
|
+
commandId: command.commandId,
|
|
41081
|
+
kind: SESSION_COMPLETED_KIND,
|
|
41082
|
+
sessionId: command.sessionId,
|
|
41083
|
+
stopReason
|
|
41084
|
+
}),
|
|
41085
|
+
attemptId
|
|
41086
|
+
);
|
|
41087
|
+
outbox.transitionExecution(command.commandId, stopReason === "cancelled" ? "cancelled" : "succeeded");
|
|
41088
|
+
audit.record({
|
|
41089
|
+
commandId: command.commandId,
|
|
41090
|
+
details: { botId: command.botId, executionId: command.executionId },
|
|
41091
|
+
event: stopReason === "cancelled" ? "bot_session_cancelled" : "bot_session_completed",
|
|
41092
|
+
sessionId: command.sessionId
|
|
41093
|
+
});
|
|
40667
41094
|
} catch (error62) {
|
|
40668
41095
|
activities.flush();
|
|
40669
41096
|
const failure2 = Date.parse(command.executionDeadlineAt) <= Date.now() ? new LocalBotAuthorizationError("turn_expired", "The Bot execution deadline has expired", {
|
|
@@ -40914,7 +41341,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
40914
41341
|
await processDeliveredPrompt(
|
|
40915
41342
|
delivery,
|
|
40916
41343
|
command,
|
|
40917
|
-
|
|
41344
|
+
command.disposition !== SessionPromptDisposition.Steer,
|
|
40918
41345
|
(attemptId, activateAttempt, executionSignal) => executeBotPrompt(
|
|
40919
41346
|
outbox,
|
|
40920
41347
|
publisher,
|
|
@@ -41567,7 +41994,11 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
41567
41994
|
applicator,
|
|
41568
41995
|
ipc,
|
|
41569
41996
|
receipt2.attemptId,
|
|
41570
|
-
() =>
|
|
41997
|
+
() => {
|
|
41998
|
+
if (command2.disposition !== SessionPromptDisposition.Steer) {
|
|
41999
|
+
activeAttemptIds.set(command2.sessionId, receipt2.attemptId);
|
|
42000
|
+
}
|
|
42001
|
+
},
|
|
41571
42002
|
timer,
|
|
41572
42003
|
turn2.signal
|
|
41573
42004
|
).catch((error62) => {
|
|
@@ -41838,7 +42269,7 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
|
|
|
41838
42269
|
}
|
|
41839
42270
|
|
|
41840
42271
|
// src/runtime.ts
|
|
41841
|
-
import { mkdir as mkdir5, realpath as realpath9, stat as
|
|
42272
|
+
import { mkdir as mkdir5, realpath as realpath9, stat as stat8 } from "node:fs/promises";
|
|
41842
42273
|
import { dirname as dirname8, join as join18, resolve as resolve5 } from "node:path";
|
|
41843
42274
|
var IDENTIFIER_PATTERN9 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
|
|
41844
42275
|
var RUNTIME_CREDENTIAL_PATTERN = /^[a-zA-Z0-9_-]{43}$/;
|
|
@@ -41908,7 +42339,7 @@ async function resolveWorkspace(path2) {
|
|
|
41908
42339
|
try {
|
|
41909
42340
|
await mkdir5(requested, { recursive: true, mode: 448 });
|
|
41910
42341
|
const resolved = await realpath9(requested);
|
|
41911
|
-
const metadata = await
|
|
42342
|
+
const metadata = await stat8(resolved);
|
|
41912
42343
|
if (!metadata.isDirectory()) {
|
|
41913
42344
|
throw new MobiusRuntimeConfigurationError("The Runtime workspace is not a directory");
|
|
41914
42345
|
}
|