@moxt-ai/mobius 0.0.34 → 0.0.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/acp/session-manager.d.ts +10 -2
  2. package/dist/acp/session-manager.d.ts.map +1 -1
  3. package/dist/acp/session-manager.js +71 -18
  4. package/dist/acp/session-manager.js.map +1 -1
  5. package/dist/agent-catalog/discover-local-agents.d.ts +0 -1
  6. package/dist/agent-catalog/discover-local-agents.d.ts.map +1 -1
  7. package/dist/agent-catalog/discover-local-agents.js +0 -1
  8. package/dist/agent-catalog/discover-local-agents.js.map +1 -1
  9. package/dist/agent-catalog/publish-agent-catalog.d.ts.map +1 -1
  10. package/dist/agent-catalog/publish-agent-catalog.js +1 -0
  11. package/dist/agent-catalog/publish-agent-catalog.js.map +1 -1
  12. package/dist/bots/local-bot-grant-store.d.ts.map +1 -1
  13. package/dist/bots/local-bot-grant-store.js +43 -3
  14. package/dist/bots/local-bot-grant-store.js.map +1 -1
  15. package/dist/cli.js +394 -109
  16. package/dist/cli.js.map +4 -4
  17. package/dist/index.js +393 -108
  18. package/dist/index.js.map +4 -4
  19. package/dist/infra/operation-metrics.d.ts +18 -0
  20. package/dist/infra/operation-metrics.d.ts.map +1 -0
  21. package/dist/infra/operation-metrics.js +31 -0
  22. package/dist/infra/operation-metrics.js.map +1 -0
  23. package/dist/native-sessions/service.d.ts.map +1 -1
  24. package/dist/native-sessions/service.js +14 -0
  25. package/dist/native-sessions/service.js.map +1 -1
  26. package/dist/pairing/pair-local-machine.d.ts.map +1 -1
  27. package/dist/pairing/pair-local-machine.js +1 -0
  28. package/dist/pairing/pair-local-machine.js.map +1 -1
  29. package/dist/run-daemon.d.ts.map +1 -1
  30. package/dist/run-daemon.js +55 -4
  31. package/dist/run-daemon.js.map +1 -1
  32. package/dist/runtime.js +393 -108
  33. package/dist/runtime.js.map +4 -4
  34. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -19821,7 +19821,7 @@ var configValueSchema = external_exports.strictObject({
19821
19821
  name: external_exports.string().min(1).max(255),
19822
19822
  value: external_exports.string().min(1).max(500)
19823
19823
  }).readonly();
19824
- var configOptionSchema = external_exports.strictObject({
19824
+ var sessionConfigOptionSchema = external_exports.strictObject({
19825
19825
  booleanValue: external_exports.boolean(),
19826
19826
  category: external_exports.string().max(128),
19827
19827
  currentValue: external_exports.string().max(500),
@@ -19831,6 +19831,26 @@ var configOptionSchema = external_exports.strictObject({
19831
19831
  type: external_exports.enum(["boolean", "select"]),
19832
19832
  values: external_exports.array(configValueSchema).max(500).readonly()
19833
19833
  }).readonly();
19834
+ var sessionConfigOptionsSchema = external_exports.array(sessionConfigOptionSchema).max(100).readonly();
19835
+ var sessionConfigurationSelectionSchema = external_exports.strictObject({
19836
+ booleanValue: external_exports.boolean(),
19837
+ configId: IDENTIFIER,
19838
+ value: external_exports.string().max(500),
19839
+ valueType: external_exports.enum(["boolean", "select"])
19840
+ }).readonly();
19841
+ var sessionConfigurationSelectionsSchema = external_exports.array(sessionConfigurationSelectionSchema).max(100).superRefine((selections, context) => {
19842
+ const identifiers = /* @__PURE__ */ new Set();
19843
+ for (const [index, selection] of selections.entries()) {
19844
+ if (identifiers.has(selection.configId)) {
19845
+ context.addIssue({
19846
+ code: "custom",
19847
+ message: "Session configuration identifiers must be unique",
19848
+ path: [index, "configId"]
19849
+ });
19850
+ }
19851
+ identifiers.add(selection.configId);
19852
+ }
19853
+ }).readonly();
19834
19854
  var sessionCapabilitiesSchema = external_exports.strictObject({
19835
19855
  additionalDirectories: external_exports.boolean(),
19836
19856
  audioPrompt: external_exports.boolean(),
@@ -19940,8 +19960,15 @@ var sessionIdentityFields = {
19940
19960
  };
19941
19961
  var sessionPrepareCommandSchema = external_exports.strictObject({
19942
19962
  ...sessionIdentityFields,
19963
+ configuration: external_exports.strictObject({
19964
+ booleanValue: external_exports.boolean(),
19965
+ configId: external_exports.string().min(1).max(128),
19966
+ value: external_exports.string().max(500),
19967
+ valueType: external_exports.enum(["boolean", "select"])
19968
+ }).readonly().optional(),
19943
19969
  kind: external_exports.literal(SESSION_PREPARE_KIND),
19944
- requestId: IDENTIFIER
19970
+ requestId: IDENTIFIER,
19971
+ transient: external_exports.boolean().optional()
19945
19972
  }).readonly();
19946
19973
  var sessionReadyEventSchema = external_exports.strictObject({
19947
19974
  additionalDirectories: external_exports.array(workspaceEntrySchema).max(16).readonly(),
@@ -19950,12 +19977,18 @@ var sessionReadyEventSchema = external_exports.strictObject({
19950
19977
  agentVersion: external_exports.string().max(128),
19951
19978
  capabilities: sessionCapabilitiesSchema,
19952
19979
  commands: external_exports.array(sessionCommandSchema).max(500).readonly(),
19953
- configOptions: external_exports.array(configOptionSchema).max(100).readonly(),
19980
+ configOptions: sessionConfigOptionsSchema,
19954
19981
  directoryId: DIRECTORY_IDENTIFIER,
19955
19982
  directoryLabel: external_exports.string().min(1).max(2048),
19956
19983
  kind: external_exports.literal(SESSION_READY_KIND),
19957
19984
  requestId: IDENTIFIER,
19958
19985
  restored: external_exports.boolean(),
19986
+ runtimeTimings: external_exports.array(
19987
+ external_exports.strictObject({
19988
+ durationMilliseconds: external_exports.number().finite().nonnegative().max(12e4),
19989
+ name: external_exports.string().regex(/^[a-z][a-z0-9-]{0,63}$/)
19990
+ }).readonly()
19991
+ ).max(16).readonly().optional(),
19959
19992
  sessionId: IDENTIFIER
19960
19993
  }).readonly();
19961
19994
  var sessionConfigureCommandSchema = external_exports.strictObject({
@@ -19968,7 +20001,7 @@ var sessionConfigureCommandSchema = external_exports.strictObject({
19968
20001
  valueType: external_exports.enum(["boolean", "select"])
19969
20002
  }).readonly();
19970
20003
  var sessionConfigUpdatedEventSchema = external_exports.strictObject({
19971
- configOptions: external_exports.array(configOptionSchema).max(100).readonly(),
20004
+ configOptions: sessionConfigOptionsSchema,
19972
20005
  kind: external_exports.literal(SESSION_CONFIG_UPDATED_KIND),
19973
20006
  requestId: IDENTIFIER,
19974
20007
  sessionId: IDENTIFIER
@@ -20144,6 +20177,7 @@ var decodeAgentDisplayContentValue = (value) => decodeValue(value, displayConten
20144
20177
  var decodeRecordedAgentContentValue = (value) => decodeValue(value, recordedDisplayContentSchema);
20145
20178
  var decodePromptImagesValue = (value) => decodeValue(value, external_exports.array(promptImageSchema).max(8).readonly());
20146
20179
  var decodePromptResourcesValue = (value) => decodeValue(value, external_exports.array(promptResourceSchema).max(16).readonly());
20180
+ var decodeSessionConfigurationSelections = (value) => decodeValue(value, sessionConfigurationSelectionsSchema);
20147
20181
  var encode3 = (message, schema) => JSON.stringify(decodeValue(message, schema));
20148
20182
  var decodeWorkspaceListCommand = (encoded) => decode3(encoded, workspaceListCommandSchema);
20149
20183
  var encodeWorkspaceEntriesEvent = (message) => encode3(message, workspaceEntriesEventSchema);
@@ -20680,8 +20714,9 @@ var BotExecutionBindingApprovalRequest = class {
20680
20714
  requestId;
20681
20715
  requiredCapabilities;
20682
20716
  runtimeId;
20717
+ sessionConfigurations;
20683
20718
  workspaceRef;
20684
- constructor(requestId, botId, behaviorRevisionId, bindingId, bindingRevision, runtimeId, agentRef, workspaceRef, agentConfigRevision, behaviorInstructions, behaviorDigest, requiredCapabilities, allowedDeliveryTargets, completionPolicy) {
20719
+ constructor(requestId, botId, behaviorRevisionId, bindingId, bindingRevision, runtimeId, agentRef, workspaceRef, agentConfigRevision, behaviorInstructions, behaviorDigest, requiredCapabilities, allowedDeliveryTargets, completionPolicy, sessionConfigurations = []) {
20685
20720
  this.requestId = requestId;
20686
20721
  this.botId = botId;
20687
20722
  this.behaviorRevisionId = behaviorRevisionId;
@@ -20694,6 +20729,7 @@ var BotExecutionBindingApprovalRequest = class {
20694
20729
  this.behaviorInstructions = behaviorInstructions;
20695
20730
  this.behaviorDigest = behaviorDigest;
20696
20731
  this.requiredCapabilities = Object.freeze([...requiredCapabilities]);
20732
+ this.sessionConfigurations = Object.freeze([...sessionConfigurations]);
20697
20733
  this.allowedDeliveryTargets = Object.freeze(
20698
20734
  allowedDeliveryTargets.map(
20699
20735
  (target) => new BotDeliveryTargetReference(target.alias, target.deliveryTargetId)
@@ -20701,6 +20737,13 @@ var BotExecutionBindingApprovalRequest = class {
20701
20737
  );
20702
20738
  this.completionPolicy = completionPolicy;
20703
20739
  }
20740
+ toJSON() {
20741
+ const { sessionConfigurations, ...request } = this;
20742
+ return {
20743
+ ...request,
20744
+ ...sessionConfigurations.length === 0 ? {} : { sessionConfigurations }
20745
+ };
20746
+ }
20704
20747
  };
20705
20748
  var BotExecutionBindingApprovedEvent = class {
20706
20749
  agentIdentityDigest;
@@ -20765,9 +20808,10 @@ var BotSessionPromptCommand = class {
20765
20808
  prompt;
20766
20809
  replyRoute;
20767
20810
  resources;
20811
+ sessionConfigurations;
20768
20812
  sessionId;
20769
20813
  turnId;
20770
- constructor(sessionId, commandId, agentId, bindingId, directoryId2, additionalDirectoryIds, images, resources, prompt, executionId, executionCapabilityId, executionCapabilitySecret, executionDeadlineAt, botId, conversationId, turnId, behaviorRevisionId, bindingRevision, localGrantId, behaviorInstructions, behaviorDigest, allowedDeliveryTargets, replyRoute) {
20814
+ 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 = []) {
20771
20815
  this.sessionId = sessionId;
20772
20816
  this.commandId = commandId;
20773
20817
  this.agentId = agentId;
@@ -20795,6 +20839,14 @@ var BotSessionPromptCommand = class {
20795
20839
  )
20796
20840
  );
20797
20841
  this.replyRoute = replyRoute;
20842
+ this.sessionConfigurations = Object.freeze([...sessionConfigurations]);
20843
+ }
20844
+ toJSON() {
20845
+ const { sessionConfigurations, ...command } = this;
20846
+ return {
20847
+ ...command,
20848
+ ...sessionConfigurations.length === 0 ? {} : { sessionConfigurations }
20849
+ };
20798
20850
  }
20799
20851
  };
20800
20852
  function isRecord2(value) {
@@ -20818,6 +20870,12 @@ function assertExactKeys2(value, expected) {
20818
20870
  throw new ProtocolMessageError("Message fields do not match the Bot protocol");
20819
20871
  }
20820
20872
  }
20873
+ function assertKeysWithOptional(value, expected, optional2) {
20874
+ const keys = Object.keys(value);
20875
+ if (keys.length < expected.length || keys.length > expected.length + optional2.length || expected.some((key) => !Object.hasOwn(value, key)) || keys.some((key) => !expected.includes(key) && !optional2.includes(key))) {
20876
+ throw new ProtocolMessageError("Message fields do not match the Bot protocol");
20877
+ }
20878
+ }
20821
20879
  function readText2(value, key, maximumLength, allowEmpty) {
20822
20880
  const field = value[key];
20823
20881
  if (typeof field !== "string" || field.length > maximumLength || !allowEmpty && field.length === 0) {
@@ -20907,6 +20965,12 @@ function readTargets(value, key) {
20907
20965
  }
20908
20966
  return Object.freeze(targets);
20909
20967
  }
20968
+ function readSessionConfigurations(value) {
20969
+ if (!Object.hasOwn(value, "sessionConfigurations")) {
20970
+ return [];
20971
+ }
20972
+ return decodeSessionConfigurationSelections(value["sessionConfigurations"]);
20973
+ }
20910
20974
  function readCompletionPolicy(value) {
20911
20975
  if (!isRecord2(value)) {
20912
20976
  throw new ProtocolMessageError("Invalid Bot completion policy");
@@ -20945,23 +21009,27 @@ function readReplyRoute(value) {
20945
21009
  }
20946
21010
  function decodeBotExecutionBindingApprovalRequest(encoded) {
20947
21011
  const value = parseJson3(encoded);
20948
- assertExactKeys2(value, [
20949
- "agentConfigRevision",
20950
- "agentRef",
20951
- "allowedDeliveryTargets",
20952
- "behaviorDigest",
20953
- "behaviorInstructions",
20954
- "behaviorRevisionId",
20955
- "bindingId",
20956
- "bindingRevision",
20957
- "botId",
20958
- "completionPolicy",
20959
- "kind",
20960
- "requestId",
20961
- "requiredCapabilities",
20962
- "runtimeId",
20963
- "workspaceRef"
20964
- ]);
21012
+ assertKeysWithOptional(
21013
+ value,
21014
+ [
21015
+ "agentConfigRevision",
21016
+ "agentRef",
21017
+ "allowedDeliveryTargets",
21018
+ "behaviorDigest",
21019
+ "behaviorInstructions",
21020
+ "behaviorRevisionId",
21021
+ "bindingId",
21022
+ "bindingRevision",
21023
+ "botId",
21024
+ "completionPolicy",
21025
+ "kind",
21026
+ "requestId",
21027
+ "requiredCapabilities",
21028
+ "runtimeId",
21029
+ "workspaceRef"
21030
+ ],
21031
+ ["sessionConfigurations"]
21032
+ );
20965
21033
  if (value["kind"] !== BOT_BINDING_APPROVAL_REQUEST_KIND) {
20966
21034
  throw new ProtocolMessageError("Invalid Bot binding approval request kind");
20967
21035
  }
@@ -20979,7 +21047,8 @@ function decodeBotExecutionBindingApprovalRequest(encoded) {
20979
21047
  readDigest(value, "behaviorDigest"),
20980
21048
  readIdentifiers(value, "requiredCapabilities", 32),
20981
21049
  readTargets(value, "allowedDeliveryTargets"),
20982
- readCompletionPolicy(value["completionPolicy"])
21050
+ readCompletionPolicy(value["completionPolicy"]),
21051
+ readSessionConfigurations(value)
20983
21052
  );
20984
21053
  }
20985
21054
  function decodeBotExecutionBindingApprovedEvent(encoded) {
@@ -21042,32 +21111,36 @@ function encodeBotExecutionBindingUnavailableEvent(event) {
21042
21111
  }
21043
21112
  function decodeBotSessionPromptCommand(encoded) {
21044
21113
  const value = parseJson3(encoded);
21045
- assertExactKeys2(value, [
21046
- "additionalDirectoryIds",
21047
- "agentId",
21048
- "allowedDeliveryTargets",
21049
- "behaviorDigest",
21050
- "behaviorInstructions",
21051
- "behaviorRevisionId",
21052
- "bindingId",
21053
- "bindingRevision",
21054
- "botId",
21055
- "commandId",
21056
- "conversationId",
21057
- "directoryId",
21058
- "executionCapabilityId",
21059
- "executionCapabilitySecret",
21060
- "executionDeadlineAt",
21061
- "executionId",
21062
- "images",
21063
- "kind",
21064
- "localGrantId",
21065
- "prompt",
21066
- "replyRoute",
21067
- "resources",
21068
- "sessionId",
21069
- "turnId"
21070
- ]);
21114
+ assertKeysWithOptional(
21115
+ value,
21116
+ [
21117
+ "additionalDirectoryIds",
21118
+ "agentId",
21119
+ "allowedDeliveryTargets",
21120
+ "behaviorDigest",
21121
+ "behaviorInstructions",
21122
+ "behaviorRevisionId",
21123
+ "bindingId",
21124
+ "bindingRevision",
21125
+ "botId",
21126
+ "commandId",
21127
+ "conversationId",
21128
+ "directoryId",
21129
+ "executionCapabilityId",
21130
+ "executionCapabilitySecret",
21131
+ "executionDeadlineAt",
21132
+ "executionId",
21133
+ "images",
21134
+ "kind",
21135
+ "localGrantId",
21136
+ "prompt",
21137
+ "replyRoute",
21138
+ "resources",
21139
+ "sessionId",
21140
+ "turnId"
21141
+ ],
21142
+ ["sessionConfigurations"]
21143
+ );
21071
21144
  if (value["kind"] !== BOT_SESSION_PROMPT_KIND) {
21072
21145
  throw new ProtocolMessageError("Invalid Bot Session prompt kind");
21073
21146
  }
@@ -21094,7 +21167,8 @@ function decodeBotSessionPromptCommand(encoded) {
21094
21167
  readText2(value, "behaviorInstructions", MAX_INSTRUCTIONS_LENGTH, true),
21095
21168
  readDigest(value, "behaviorDigest"),
21096
21169
  readTargets(value, "allowedDeliveryTargets"),
21097
- readReplyRoute(value["replyRoute"])
21170
+ readReplyRoute(value["replyRoute"]),
21171
+ readSessionConfigurations(value)
21098
21172
  );
21099
21173
  }
21100
21174
 
@@ -21217,6 +21291,7 @@ var nativeSessionTurnForkCommandSchema = external_exports.strictObject({
21217
21291
  title: external_exports.string().max(500)
21218
21292
  }).readonly();
21219
21293
  var nativeSessionCommandSchema = external_exports.discriminatedUnion("action", [
21294
+ external_exports.strictObject({ ...identity, action: external_exports.literal("preview"), entryId: identifier }).readonly(),
21220
21295
  external_exports.strictObject({
21221
21296
  ...identity,
21222
21297
  action: external_exports.literal("list"),
@@ -21267,7 +21342,7 @@ var nativeSessionResultSchema = external_exports.discriminatedUnion("action", [
21267
21342
  action: external_exports.literal("preview"),
21268
21343
  entryId: identifier,
21269
21344
  targetSessionId: identifier,
21270
- reason: external_exports.literal("continuation_unavailable"),
21345
+ reason: external_exports.enum(["continuation_unavailable", "requested"]),
21271
21346
  history: sessionHistorySchema,
21272
21347
  title: external_exports.string().max(500)
21273
21348
  }).readonly(),
@@ -22296,6 +22371,38 @@ async function readAuthorizedRaster(uri, roots, signal) {
22296
22371
  return new LocalRasterImage(basename(target) || "Image", mimeType, bytes);
22297
22372
  }
22298
22373
 
22374
+ // src/infra/operation-metrics.ts
22375
+ var AccumulatingOperationMetrics = class {
22376
+ #durations = /* @__PURE__ */ new Map();
22377
+ measure = async (name, operation) => {
22378
+ const startedAt = performance.now();
22379
+ try {
22380
+ return await operation();
22381
+ } finally {
22382
+ this.record(name, performance.now() - startedAt);
22383
+ }
22384
+ };
22385
+ measureSync = (name, operation) => {
22386
+ const startedAt = performance.now();
22387
+ try {
22388
+ return operation();
22389
+ } finally {
22390
+ this.record(name, performance.now() - startedAt);
22391
+ }
22392
+ };
22393
+ snapshot = () => Object.freeze(
22394
+ [...this.#durations].map(([name, durationMilliseconds]) => Object.freeze({ durationMilliseconds, name }))
22395
+ );
22396
+ record = (name, durationMilliseconds) => {
22397
+ this.#durations.set(name, (this.#durations.get(name) ?? 0) + Math.max(0, durationMilliseconds));
22398
+ };
22399
+ };
22400
+ var unmeasuredOperationMetrics = Object.freeze({
22401
+ measure: async (_name, operation) => await operation(),
22402
+ measureSync: (_name, operation) => operation(),
22403
+ snapshot: () => Object.freeze([])
22404
+ });
22405
+
22299
22406
  // src/native-sessions/history-images.ts
22300
22407
  var IMAGE_MARKER = /\[@image\]\(([^)\r\n]*)(?:\)|$)/g;
22301
22408
  async function embedLocalHistoryImages(history, roots, signal) {
@@ -24036,6 +24143,7 @@ var AcpProcessSession = class _AcpProcessSession {
24036
24143
  #pendingPermissions = /* @__PURE__ */ new Map();
24037
24144
  #preSessionUpdates = [];
24038
24145
  #processExit;
24146
+ #metrics;
24039
24147
  #sessionConfigProtocol;
24040
24148
  #store;
24041
24149
  #verifiedAgentVersion;
@@ -24069,13 +24177,14 @@ var AcpProcessSession = class _AcpProcessSession {
24069
24177
  #sessionUpdatedAt = "";
24070
24178
  #turn = new IdleAcpTurn();
24071
24179
  #updateTail = Promise.resolve();
24072
- constructor(agent, cwd, additionalDirectories, mobiusSessionId, getObserver, store) {
24180
+ constructor(agent, cwd, additionalDirectories, mobiusSessionId, getObserver, store, metrics) {
24073
24181
  this.#additionalDirectories = [...additionalDirectories];
24074
24182
  this.#agentId = agent.id;
24075
24183
  this.#cwd = cwd;
24076
24184
  this.#environment = agent.environment;
24077
24185
  this.#getObserver = getObserver;
24078
24186
  this.#mobiusSessionId = mobiusSessionId;
24187
+ this.#metrics = metrics;
24079
24188
  this.#sessionConfigProtocol = sessionConfigProtocolForAgent(agent.id);
24080
24189
  this.#store = store;
24081
24190
  this.#verifiedAgentVersion = agent.agentVersion;
@@ -24104,13 +24213,16 @@ var AcpProcessSession = class _AcpProcessSession {
24104
24213
  const stream = ndJsonStream(createWritableAcpStream(stdin), readableWebStream(stdout));
24105
24214
  this.#connection = createAcpClient(this).connect(stream);
24106
24215
  }
24107
- static async #start(options, getObserver, store, initialize) {
24216
+ static async #start(options, getObserver, store, initialize, metrics) {
24108
24217
  for (let attempt = 1; attempt <= 2; attempt += 1) {
24109
24218
  options.signal.throwIfAborted();
24110
- const [adapterUnchanged, agentUnchanged] = await Promise.all([
24111
- revalidateExecutable(options.agent.adapterIdentity),
24112
- revalidateExecutable(options.agent.agentIdentity)
24113
- ]);
24219
+ const [adapterUnchanged, agentUnchanged] = await metrics.measure(
24220
+ "executable-validation",
24221
+ async () => await Promise.all([
24222
+ revalidateExecutable(options.agent.adapterIdentity),
24223
+ revalidateExecutable(options.agent.agentIdentity)
24224
+ ])
24225
+ );
24114
24226
  options.signal.throwIfAborted();
24115
24227
  if (!adapterUnchanged || !agentUnchanged) {
24116
24228
  throw new AcpExecutionError(
@@ -24119,13 +24231,17 @@ var AcpProcessSession = class _AcpProcessSession {
24119
24231
  "agent_runtime_changed"
24120
24232
  );
24121
24233
  }
24122
- const runtime = new _AcpProcessSession(
24123
- options.agent,
24124
- options.cwd,
24125
- options.additionalDirectories,
24126
- options.sessionId,
24127
- getObserver,
24128
- store
24234
+ const runtime = metrics.measureSync(
24235
+ "process-spawn",
24236
+ () => new _AcpProcessSession(
24237
+ options.agent,
24238
+ options.cwd,
24239
+ options.additionalDirectories,
24240
+ options.sessionId,
24241
+ getObserver,
24242
+ store,
24243
+ metrics
24244
+ )
24129
24245
  );
24130
24246
  try {
24131
24247
  await initialize(runtime);
@@ -24147,17 +24263,19 @@ var AcpProcessSession = class _AcpProcessSession {
24147
24263
  }
24148
24264
  throw new AcpExecutionError("ACP agent initialization failed");
24149
24265
  }
24150
- static start = async (options, getObserver, store) => await _AcpProcessSession.#start(
24266
+ static start = async (options, getObserver, store, metrics = unmeasuredOperationMetrics) => await _AcpProcessSession.#start(
24151
24267
  options,
24152
24268
  getObserver,
24153
24269
  store,
24154
- async (runtime) => await runtime.initialize(options.signal, options.origin)
24270
+ async (runtime) => await runtime.initialize(options.signal, options.origin),
24271
+ metrics
24155
24272
  );
24156
24273
  static startNativeSessionBrowser = async (options, getObserver, store) => await _AcpProcessSession.#start(
24157
24274
  options,
24158
24275
  getObserver,
24159
24276
  store,
24160
- async (runtime) => await runtime.#initializeAgent(options.signal)
24277
+ async (runtime) => await runtime.#initializeAgent(options.signal),
24278
+ unmeasuredOperationMetrics
24161
24279
  );
24162
24280
  static startSessionForkAtTurn = async (options, sourceNativeSessionId, forkPoint, getObserver, store) => await _AcpProcessSession.#start(
24163
24281
  options,
@@ -24167,7 +24285,8 @@ var AcpProcessSession = class _AcpProcessSession {
24167
24285
  options.signal,
24168
24286
  { kind: "fork", nativeSessionId: sourceNativeSessionId },
24169
24287
  forkPoint
24170
- )
24288
+ ),
24289
+ unmeasuredOperationMetrics
24171
24290
  );
24172
24291
  belongsTo = (agentId, cwd, additionalDirectories) => this.#agentId === agentId && this.#cwd === cwd && arraysEqual(this.#additionalDirectories, additionalDirectories);
24173
24292
  usesEnvironment = (environment) => recordsEqual(this.#environment, environment);
@@ -24286,6 +24405,9 @@ var AcpProcessSession = class _AcpProcessSession {
24286
24405
  );
24287
24406
  };
24288
24407
  async #initializeAgent(signal) {
24408
+ await this.#metrics.measure("agent-initialize", async () => await this.#initializeAgentOperation(signal));
24409
+ }
24410
+ async #initializeAgentOperation(signal) {
24289
24411
  const initialized = await this.race(
24290
24412
  this.#connection.agent.request(
24291
24413
  methods3.agent.initialize,
@@ -24456,18 +24578,21 @@ var AcpProcessSession = class _AcpProcessSession {
24456
24578
  }
24457
24579
  this.#store.remove(this.#mobiusSessionId);
24458
24580
  }
24459
- const created = await this.race(
24460
- this.#connection.agent.request(
24461
- methods3.agent.session.new,
24462
- {
24463
- additionalDirectories: [...this.#additionalDirectories],
24464
- cwd: this.#cwd,
24465
- mcpServers: []
24466
- },
24467
- { cancellationSignal: signal }
24468
- ),
24469
- "ACP agent exited while starting a session",
24470
- signal
24581
+ const created = await this.#metrics.measure(
24582
+ "session-new",
24583
+ async () => await this.race(
24584
+ this.#connection.agent.request(
24585
+ methods3.agent.session.new,
24586
+ {
24587
+ additionalDirectories: [...this.#additionalDirectories],
24588
+ cwd: this.#cwd,
24589
+ mcpServers: []
24590
+ },
24591
+ { cancellationSignal: signal }
24592
+ ),
24593
+ "ACP agent exited while starting a session",
24594
+ signal
24595
+ )
24471
24596
  );
24472
24597
  this.selectNativeSession(created.sessionId);
24473
24598
  lifecycleResponse = created;
@@ -25270,10 +25395,10 @@ var AcpSessionManager = class {
25270
25395
  this.#nativeBrowserPreparing.set(options.sessionId, operation);
25271
25396
  return await operation;
25272
25397
  }
25273
- async #startPreparation(options) {
25398
+ async #startPreparation(options, metrics = unmeasuredOperationMetrics) {
25274
25399
  const operation = (async () => {
25275
25400
  try {
25276
- const runtime = await AcpProcessSession.start(options, () => this.#observer, this.#store);
25401
+ const runtime = await AcpProcessSession.start(options, () => this.#observer, this.#store, metrics);
25277
25402
  this.#sessions.set(options.sessionId, runtime);
25278
25403
  return runtime;
25279
25404
  } finally {
@@ -25302,13 +25427,13 @@ var AcpSessionManager = class {
25302
25427
  this.#preparing.set(options.sessionId, operation);
25303
25428
  return await operation;
25304
25429
  }
25305
- async #replacePreparation(existing, options) {
25430
+ async #replacePreparation(existing, options, metrics) {
25306
25431
  const operation = (async () => {
25307
25432
  try {
25308
25433
  this.#sessions.delete(options.sessionId);
25309
25434
  await existing.close();
25310
25435
  this.#store.remove(options.sessionId);
25311
- const runtime = await AcpProcessSession.start(options, () => this.#observer, this.#store);
25436
+ const runtime = await AcpProcessSession.start(options, () => this.#observer, this.#store, metrics);
25312
25437
  this.#sessions.set(options.sessionId, runtime);
25313
25438
  return runtime;
25314
25439
  } finally {
@@ -25370,7 +25495,7 @@ var AcpSessionManager = class {
25370
25495
  this.#preparing.set(options.sessionId, operation);
25371
25496
  return await operation;
25372
25497
  }
25373
- prepareSession = async (options) => {
25498
+ prepareSession = async (options, metrics = unmeasuredOperationMetrics) => {
25374
25499
  const stored = this.#store.read(options.sessionId);
25375
25500
  if (stored instanceof DeletedAcpStoredSession) {
25376
25501
  throw new AcpExecutionError(
@@ -25388,7 +25513,7 @@ var AcpSessionManager = class {
25388
25513
  if (runtime2.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
25389
25514
  return runtime2.prepared();
25390
25515
  }
25391
- return await this.prepareSession(options);
25516
+ return await this.prepareSession(options, metrics);
25392
25517
  }
25393
25518
  const existing = this.#sessions.get(options.sessionId);
25394
25519
  if (existing !== void 0) {
@@ -25402,12 +25527,35 @@ var AcpSessionManager = class {
25402
25527
  "session_identity_mismatch"
25403
25528
  );
25404
25529
  }
25405
- const runtime2 = await this.#replacePreparation(existing, options);
25530
+ const runtime2 = await this.#replacePreparation(existing, options, metrics);
25406
25531
  return runtime2.prepared();
25407
25532
  }
25408
- const runtime = await this.#startPreparation(options);
25533
+ const runtime = await this.#startPreparation(options, metrics);
25409
25534
  return runtime.prepared();
25410
25535
  };
25536
+ /**
25537
+ * Opens a short-lived ACP session only to read the Agent's authoritative
25538
+ * configuration options. The runtime and any persisted native-session
25539
+ * record are released before this method resolves.
25540
+ */
25541
+ inspectSession = async (options) => {
25542
+ if (this.#preparing.has(options.sessionId) || this.#sessions.has(options.sessionId)) {
25543
+ throw new AcpExecutionError("The configuration inspection session is already in use", {}, "session_busy");
25544
+ }
25545
+ const runtime = await this.#startPreparation(options);
25546
+ try {
25547
+ return runtime.prepared();
25548
+ } finally {
25549
+ if (this.#sessions.get(options.sessionId) === runtime) {
25550
+ this.#sessions.delete(options.sessionId);
25551
+ }
25552
+ try {
25553
+ await runtime.close();
25554
+ } finally {
25555
+ this.#store.remove(options.sessionId);
25556
+ }
25557
+ }
25558
+ };
25411
25559
  prepareExecutionSession = async (options) => {
25412
25560
  const pending = this.#preparing.get(options.sessionId);
25413
25561
  if (pending !== void 0) {
@@ -25668,6 +25816,33 @@ var AcpSessionManager = class {
25668
25816
  return started;
25669
25817
  }
25670
25818
  listNativeSessions = async (options, cursor) => await (await this.#ensureNativeSessionBrowser(options)).listNativeSessions(cursor, options.signal);
25819
+ previewNativeSession = async (options, nativeSessionId) => {
25820
+ const key = `${options.agent.id}:${nativeSessionId}`;
25821
+ const linked = this.#store.findNative(options.agent.id, nativeSessionId);
25822
+ if (this.#nativeOperations.has(key) || linked.some((entry) => this.#activeSessionIds.has(entry.sessionId) || this.#preparing.has(entry.sessionId))) {
25823
+ throw new AcpExecutionError(
25824
+ "Wait for the native session's running operation to finish",
25825
+ {},
25826
+ "session_busy"
25827
+ );
25828
+ }
25829
+ this.#nativeOperations.add(key);
25830
+ try {
25831
+ const runtime = await AcpProcessSession.startNativeSessionBrowser(
25832
+ options,
25833
+ () => this.#nativeBrowserObserver,
25834
+ new MemoryAcpSessionStore()
25835
+ );
25836
+ try {
25837
+ runtime.selectNativeSession(nativeSessionId);
25838
+ return await runtime.loadHistory(options.signal);
25839
+ } finally {
25840
+ await runtime.closeProcess();
25841
+ }
25842
+ } finally {
25843
+ this.#nativeOperations.delete(key);
25844
+ }
25845
+ };
25671
25846
  openNativeSession = async (options, origin) => {
25672
25847
  const key = `${options.agent.id}:${origin.nativeSessionId}`;
25673
25848
  if (this.#nativeOperations.has(key)) {
@@ -26017,6 +26192,16 @@ function exactTargets(left, right) {
26017
26192
  const actual = [...right].sort();
26018
26193
  return expected.every((target, index) => target === actual[index]);
26019
26194
  }
26195
+ function exactSessionConfigurations(left, right) {
26196
+ if (left.length !== right.length) {
26197
+ return false;
26198
+ }
26199
+ const expected = new Map(left.map((selection) => [selection.configId, selection]));
26200
+ return right.every((selection) => {
26201
+ const approved = expected.get(selection.configId);
26202
+ return approved !== void 0 && approved.booleanValue === selection.booleanValue && approved.value === selection.value && approved.valueType === selection.valueType;
26203
+ });
26204
+ }
26020
26205
  function rowString(row, key) {
26021
26206
  const value = Reflect.get(row, key);
26022
26207
  if (typeof value !== "string") {
@@ -26043,6 +26228,15 @@ function parseTargets(encoded) {
26043
26228
  }
26044
26229
  return value.filter((target) => typeof target === "string");
26045
26230
  }
26231
+ function parseSessionConfigurations(encoded) {
26232
+ let value;
26233
+ try {
26234
+ value = JSON.parse(encoded);
26235
+ return decodeSessionConfigurationSelections(value);
26236
+ } catch (cause) {
26237
+ throw new LocalBotAuthorizationError("local_grant_invalid", "The local Bot grant is invalid", { cause });
26238
+ }
26239
+ }
26046
26240
  var LocalBotGrantStore = class {
26047
26241
  #database;
26048
26242
  static containsBot = (path2, botId) => {
@@ -26087,6 +26281,10 @@ var LocalBotGrantStore = class {
26087
26281
  error_code TEXT,
26088
26282
  error_message TEXT
26089
26283
  ) STRICT;
26284
+ CREATE TABLE IF NOT EXISTS local_bot_grant_configurations (
26285
+ local_grant_id TEXT PRIMARY KEY,
26286
+ session_configurations_json TEXT NOT NULL
26287
+ ) STRICT;
26090
26288
  `);
26091
26289
  }
26092
26290
  /** Only the local CLI may invoke this explicit approval transition. */
@@ -26212,6 +26410,11 @@ var LocalBotGrantStore = class {
26212
26410
  now,
26213
26411
  expiresAt
26214
26412
  );
26413
+ this.#database.prepare(
26414
+ `INSERT INTO local_bot_grant_configurations (
26415
+ local_grant_id, session_configurations_json
26416
+ ) VALUES (?, ?)`
26417
+ ).run(localGrantId, JSON.stringify(request.sessionConfigurations));
26215
26418
  this.#database.prepare(
26216
26419
  `INSERT INTO local_bot_binding_resolutions (
26217
26420
  request_id, binding_id, local_grant_id, resolved_at, result
@@ -26237,8 +26440,12 @@ var LocalBotGrantStore = class {
26237
26440
  resolveExecution = async (command, catalog, directories, bindingAuthorityId, now, signal) => {
26238
26441
  signal.throwIfAborted();
26239
26442
  const row = this.#database.prepare(
26240
- `SELECT * FROM local_bot_grants
26241
- WHERE local_grant_id = ? AND bot_id = ?
26443
+ `SELECT grants.*, COALESCE(configurations.session_configurations_json, '[]')
26444
+ AS session_configurations_json
26445
+ FROM local_bot_grants AS grants
26446
+ LEFT JOIN local_bot_grant_configurations AS configurations
26447
+ ON configurations.local_grant_id = grants.local_grant_id
26448
+ WHERE grants.local_grant_id = ? AND grants.bot_id = ?
26242
26449
  AND behavior_revision_id = ? AND behavior_digest = ?
26243
26450
  AND binding_id = ? AND binding_revision = ?
26244
26451
  AND agent_ref = ?
@@ -26267,6 +26474,13 @@ var LocalBotGrantStore = class {
26267
26474
  "The Bot execution target policy changed after local approval"
26268
26475
  );
26269
26476
  }
26477
+ const approvedConfigurations = parseSessionConfigurations(rowString(row, "session_configurations_json"));
26478
+ if (!exactSessionConfigurations(approvedConfigurations, command.sessionConfigurations)) {
26479
+ throw new LocalBotAuthorizationError(
26480
+ "binding_not_approved",
26481
+ "The Bot Agent configuration changed after local approval"
26482
+ );
26483
+ }
26270
26484
  const agent = catalog.find(command.agentId);
26271
26485
  const [adapterUnchanged, agentUnchanged] = await Promise.all([
26272
26486
  revalidateExecutable(agent.adapterIdentity),
@@ -29002,6 +29216,7 @@ async function claimPairing(options, defaultWorkspace, localAgents, installableA
29002
29216
  const agents = localAgents.map((agent) => ({
29003
29217
  agentPath: agent.agentIdentity.requestedPath,
29004
29218
  agentVersion: agent.agentVersion,
29219
+ botSessionConfiguration: true,
29005
29220
  capabilities: agent.capabilities,
29006
29221
  id: agent.id,
29007
29222
  label: agent.label
@@ -29242,6 +29457,7 @@ async function publishAgentCatalog(config2, signal) {
29242
29457
  agents: catalog.agents.map((agent) => ({
29243
29458
  agentPath: agent.agentIdentity.requestedPath,
29244
29459
  agentVersion: agent.agentVersion,
29460
+ botSessionConfiguration: true,
29245
29461
  capabilities: agent.capabilities,
29246
29462
  id: agent.id,
29247
29463
  label: agent.label
@@ -30443,6 +30659,23 @@ var NativeSessionService = class {
30443
30659
  );
30444
30660
  }
30445
30661
  const target = await this.resolveTarget(command, options, selected);
30662
+ if (command.action === "preview") {
30663
+ const history = await this.#sessions.previewNativeSession(
30664
+ { ...options, cwd: target.cwd, additionalDirectories: target.additionalDirectories },
30665
+ target.info.sessionId
30666
+ );
30667
+ signal.throwIfAborted();
30668
+ this.record(command, "native_session_previewed");
30669
+ return {
30670
+ ...envelope2,
30671
+ action: "preview",
30672
+ entryId: command.entryId,
30673
+ targetSessionId: command.sessionId,
30674
+ reason: "requested",
30675
+ title: target.info.title ?? "Untitled session",
30676
+ history
30677
+ };
30678
+ }
30446
30679
  if (command.action === "delete") {
30447
30680
  if (!prepared.capabilities.deleteSession) {
30448
30681
  throw new AcpExecutionError(
@@ -32442,35 +32675,73 @@ async function executeSessionPrepare(publisher, socket, command, config2, direct
32442
32675
  signal
32443
32676
  );
32444
32677
  const agent = config2.catalog.find(command.agentId);
32445
- const prepared = await sessions.prepareSession({
32678
+ const metrics = new AccumulatingOperationMetrics();
32679
+ const preparation = {
32446
32680
  additionalDirectories: resolved.additionalDirectories,
32447
32681
  agent,
32448
32682
  cwd: resolved.cwd,
32449
32683
  sessionId: command.sessionId,
32450
32684
  signal
32451
- });
32685
+ };
32686
+ const prepared = command.transient === true ? await sessions.inspectSession(preparation) : await sessions.prepareSession(preparation, metrics);
32687
+ const configuration = command.configuration;
32688
+ const configOptions = configuration === void 0 ? prepared.configOptions : await metrics.measure(
32689
+ "configuration",
32690
+ async () => await sessions.configureSession({
32691
+ ...preparation,
32692
+ booleanValue: configuration.booleanValue,
32693
+ configId: configuration.configId,
32694
+ requestId: command.requestId,
32695
+ value: configuration.value,
32696
+ valueType: configuration.valueType
32697
+ })
32698
+ );
32452
32699
  const listing = await directories.list(config2.bindingId, command.directoryId, signal);
32453
32700
  audit.record({
32454
32701
  commandId: command.requestId,
32455
32702
  event: "session_prepared",
32456
32703
  sessionId: command.sessionId
32457
32704
  });
32458
- publisher.recordRuntime(
32459
- command.sessionId,
32460
- encodeSessionReadyEvent({
32461
- additionalDirectories: resolved.additionalDirectoryEntries,
32462
- agentId: command.agentId,
32463
- agentName: prepared.agentName,
32464
- agentVersion: prepared.agentVersion,
32465
- capabilities: prepared.capabilities,
32466
- commands: prepared.commands,
32467
- configOptions: prepared.configOptions,
32468
- directoryId: command.directoryId,
32469
- directoryLabel: listing.directoryLabel,
32470
- kind: "session.ready",
32471
- requestId: command.requestId,
32472
- restored: prepared.restored,
32705
+ if (command.configuration !== void 0) {
32706
+ audit.record({
32707
+ commandId: command.requestId,
32708
+ event: "session_configured",
32473
32709
  sessionId: command.sessionId
32710
+ });
32711
+ publisher.recordRuntime(
32712
+ command.sessionId,
32713
+ encodeSessionConfigUpdatedEvent({
32714
+ configOptions,
32715
+ kind: "session.config.updated",
32716
+ requestId: command.requestId,
32717
+ sessionId: command.sessionId
32718
+ })
32719
+ );
32720
+ }
32721
+ const readyEvent = {
32722
+ additionalDirectories: resolved.additionalDirectoryEntries,
32723
+ agentId: command.agentId,
32724
+ agentName: prepared.agentName,
32725
+ agentVersion: prepared.agentVersion,
32726
+ capabilities: prepared.capabilities,
32727
+ commands: prepared.commands,
32728
+ configOptions,
32729
+ directoryId: command.directoryId,
32730
+ directoryLabel: listing.directoryLabel,
32731
+ kind: "session.ready",
32732
+ requestId: command.requestId,
32733
+ restored: prepared.restored,
32734
+ sessionId: command.sessionId,
32735
+ runtimeTimings: metrics.snapshot()
32736
+ };
32737
+ metrics.measureSync("readiness-commit", () => {
32738
+ publisher.recordRuntime(command.sessionId, encodeSessionReadyEvent(readyEvent));
32739
+ });
32740
+ send(
32741
+ socket,
32742
+ encodeSessionReadyEvent({
32743
+ ...readyEvent,
32744
+ runtimeTimings: metrics.snapshot()
32474
32745
  })
32475
32746
  );
32476
32747
  } catch (error62) {
@@ -32727,6 +32998,20 @@ async function executeBotPrompt(outbox, publisher, command, config2, directories
32727
32998
  sessionId: command.sessionId,
32728
32999
  signal: executionSignal
32729
33000
  });
33001
+ for (const selection of command.sessionConfigurations) {
33002
+ await sessions.configureSession({
33003
+ additionalDirectories: resolved.additionalDirectories,
33004
+ agent,
33005
+ booleanValue: selection.booleanValue,
33006
+ configId: selection.configId,
33007
+ cwd: resolved.cwd,
33008
+ requestId: `cfg_${randomUUID6()}`,
33009
+ sessionId: command.sessionId,
33010
+ signal: executionSignal,
33011
+ value: selection.value,
33012
+ valueType: selection.valueType
33013
+ });
33014
+ }
32730
33015
  audit.record({
32731
33016
  commandId: command.commandId,
32732
33017
  details: {