@microsoft/agentrc 2.0.1-56 → 2.0.1-58

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/index.js CHANGED
@@ -3308,6 +3308,21 @@ function createServerRpc(connection) {
3308
3308
  },
3309
3309
  account: {
3310
3310
  getQuota: async () => connection.sendRequest("account.getQuota", {})
3311
+ },
3312
+ mcp: {
3313
+ config: {
3314
+ list: async () => connection.sendRequest("mcp.config.list", {}),
3315
+ add: async (params) => connection.sendRequest("mcp.config.add", params),
3316
+ update: async (params) => connection.sendRequest("mcp.config.update", params),
3317
+ remove: async (params) => connection.sendRequest("mcp.config.remove", params)
3318
+ }
3319
+ },
3320
+ sessionFs: {
3321
+ setProvider: async (params) => connection.sendRequest("sessionFs.setProvider", params)
3322
+ },
3323
+ /** @experimental */
3324
+ sessions: {
3325
+ fork: async (params) => connection.sendRequest("sessions.fork", params)
3311
3326
  }
3312
3327
  };
3313
3328
  }
@@ -3368,10 +3383,6 @@ function createSessionRpc(connection, sessionId) {
3368
3383
  disable: async (params) => connection.sendRequest("session.extensions.disable", { sessionId, ...params }),
3369
3384
  reload: async () => connection.sendRequest("session.extensions.reload", { sessionId })
3370
3385
  },
3371
- /** @experimental */
3372
- compaction: {
3373
- compact: async () => connection.sendRequest("session.compaction.compact", { sessionId })
3374
- },
3375
3386
  tools: {
3376
3387
  handlePendingToolCall: async (params) => connection.sendRequest("session.tools.handlePendingToolCall", { sessionId, ...params })
3377
3388
  },
@@ -3379,7 +3390,8 @@ function createSessionRpc(connection, sessionId) {
3379
3390
  handlePendingCommand: async (params) => connection.sendRequest("session.commands.handlePendingCommand", { sessionId, ...params })
3380
3391
  },
3381
3392
  ui: {
3382
- elicitation: async (params) => connection.sendRequest("session.ui.elicitation", { sessionId, ...params })
3393
+ elicitation: async (params) => connection.sendRequest("session.ui.elicitation", { sessionId, ...params }),
3394
+ handlePendingElicitation: async (params) => connection.sendRequest("session.ui.handlePendingElicitation", { sessionId, ...params })
3383
3395
  },
3384
3396
  permissions: {
3385
3397
  handlePendingPermissionRequest: async (params) => connection.sendRequest("session.permissions.handlePendingPermissionRequest", { sessionId, ...params })
@@ -3388,9 +3400,66 @@ function createSessionRpc(connection, sessionId) {
3388
3400
  shell: {
3389
3401
  exec: async (params) => connection.sendRequest("session.shell.exec", { sessionId, ...params }),
3390
3402
  kill: async (params) => connection.sendRequest("session.shell.kill", { sessionId, ...params })
3403
+ },
3404
+ /** @experimental */
3405
+ history: {
3406
+ compact: async () => connection.sendRequest("session.history.compact", { sessionId }),
3407
+ truncate: async (params) => connection.sendRequest("session.history.truncate", { sessionId, ...params })
3391
3408
  }
3392
3409
  };
3393
3410
  }
3411
+ function registerClientSessionApiHandlers(connection, getHandlers) {
3412
+ connection.onRequest("sessionFs.readFile", async (params) => {
3413
+ const handler = getHandlers(params.sessionId).sessionFs;
3414
+ if (!handler) throw new Error(`No sessionFs handler registered for session: ${params.sessionId}`);
3415
+ return handler.readFile(params);
3416
+ });
3417
+ connection.onRequest("sessionFs.writeFile", async (params) => {
3418
+ const handler = getHandlers(params.sessionId).sessionFs;
3419
+ if (!handler) throw new Error(`No sessionFs handler registered for session: ${params.sessionId}`);
3420
+ return handler.writeFile(params);
3421
+ });
3422
+ connection.onRequest("sessionFs.appendFile", async (params) => {
3423
+ const handler = getHandlers(params.sessionId).sessionFs;
3424
+ if (!handler) throw new Error(`No sessionFs handler registered for session: ${params.sessionId}`);
3425
+ return handler.appendFile(params);
3426
+ });
3427
+ connection.onRequest("sessionFs.exists", async (params) => {
3428
+ const handler = getHandlers(params.sessionId).sessionFs;
3429
+ if (!handler) throw new Error(`No sessionFs handler registered for session: ${params.sessionId}`);
3430
+ return handler.exists(params);
3431
+ });
3432
+ connection.onRequest("sessionFs.stat", async (params) => {
3433
+ const handler = getHandlers(params.sessionId).sessionFs;
3434
+ if (!handler) throw new Error(`No sessionFs handler registered for session: ${params.sessionId}`);
3435
+ return handler.stat(params);
3436
+ });
3437
+ connection.onRequest("sessionFs.mkdir", async (params) => {
3438
+ const handler = getHandlers(params.sessionId).sessionFs;
3439
+ if (!handler) throw new Error(`No sessionFs handler registered for session: ${params.sessionId}`);
3440
+ return handler.mkdir(params);
3441
+ });
3442
+ connection.onRequest("sessionFs.readdir", async (params) => {
3443
+ const handler = getHandlers(params.sessionId).sessionFs;
3444
+ if (!handler) throw new Error(`No sessionFs handler registered for session: ${params.sessionId}`);
3445
+ return handler.readdir(params);
3446
+ });
3447
+ connection.onRequest("sessionFs.readdirWithTypes", async (params) => {
3448
+ const handler = getHandlers(params.sessionId).sessionFs;
3449
+ if (!handler) throw new Error(`No sessionFs handler registered for session: ${params.sessionId}`);
3450
+ return handler.readdirWithTypes(params);
3451
+ });
3452
+ connection.onRequest("sessionFs.rm", async (params) => {
3453
+ const handler = getHandlers(params.sessionId).sessionFs;
3454
+ if (!handler) throw new Error(`No sessionFs handler registered for session: ${params.sessionId}`);
3455
+ return handler.rm(params);
3456
+ });
3457
+ connection.onRequest("sessionFs.rename", async (params) => {
3458
+ const handler = getHandlers(params.sessionId).sessionFs;
3459
+ if (!handler) throw new Error(`No sessionFs handler registered for session: ${params.sessionId}`);
3460
+ return handler.rename(params);
3461
+ });
3462
+ }
3394
3463
  var init_rpc = __esm({
3395
3464
  "node_modules/@github/copilot-sdk/dist/generated/rpc.js"() {
3396
3465
  "use strict";
@@ -3425,6 +3494,25 @@ var init_telemetry = __esm({
3425
3494
  });
3426
3495
 
3427
3496
  // node_modules/@github/copilot-sdk/dist/session.js
3497
+ function isToolResultObject(value) {
3498
+ if (typeof value !== "object" || value === null) {
3499
+ return false;
3500
+ }
3501
+ if (!("textResultForLlm" in value) || typeof value.textResultForLlm !== "string") {
3502
+ return false;
3503
+ }
3504
+ if (!("resultType" in value) || typeof value.resultType !== "string") {
3505
+ return false;
3506
+ }
3507
+ const allowedResultTypes = [
3508
+ "success",
3509
+ "failure",
3510
+ "rejected",
3511
+ "denied",
3512
+ "timeout"
3513
+ ];
3514
+ return allowedResultTypes.includes(value.resultType);
3515
+ }
3428
3516
  var import_node, NO_RESULT_PERMISSION_V2_ERROR, CopilotSession;
3429
3517
  var init_session = __esm({
3430
3518
  "node_modules/@github/copilot-sdk/dist/session.js"() {
@@ -3452,12 +3540,17 @@ var init_session = __esm({
3452
3540
  eventHandlers = /* @__PURE__ */ new Set();
3453
3541
  typedEventHandlers = /* @__PURE__ */ new Map();
3454
3542
  toolHandlers = /* @__PURE__ */ new Map();
3543
+ commandHandlers = /* @__PURE__ */ new Map();
3455
3544
  permissionHandler;
3456
3545
  userInputHandler;
3546
+ elicitationHandler;
3457
3547
  hooks;
3458
3548
  transformCallbacks;
3459
3549
  _rpc = null;
3460
3550
  traceContextProvider;
3551
+ _capabilities = {};
3552
+ /** @internal Client session API handlers, populated by CopilotClient during create/resume. */
3553
+ clientSessionApis = {};
3461
3554
  /**
3462
3555
  * Typed session-scoped RPC methods.
3463
3556
  */
@@ -3475,6 +3568,33 @@ var init_session = __esm({
3475
3568
  get workspacePath() {
3476
3569
  return this._workspacePath;
3477
3570
  }
3571
+ /**
3572
+ * Host capabilities reported when the session was created or resumed.
3573
+ * Use this to check feature support before calling capability-gated APIs.
3574
+ */
3575
+ get capabilities() {
3576
+ return this._capabilities;
3577
+ }
3578
+ /**
3579
+ * Interactive UI methods for showing dialogs to the user.
3580
+ * Only available when the CLI host supports elicitation
3581
+ * (`session.capabilities.ui?.elicitation === true`).
3582
+ *
3583
+ * @example
3584
+ * ```typescript
3585
+ * if (session.capabilities.ui?.elicitation) {
3586
+ * const ok = await session.ui.confirm("Deploy to production?");
3587
+ * }
3588
+ * ```
3589
+ */
3590
+ get ui() {
3591
+ return {
3592
+ elicitation: (params) => this._elicitation(params),
3593
+ confirm: (message) => this._confirm(message),
3594
+ select: (message, options) => this._select(message, options),
3595
+ input: (message, options) => this._input(message, options)
3596
+ };
3597
+ }
3478
3598
  /**
3479
3599
  * Sends a message to this session and waits for the response.
3480
3600
  *
@@ -3640,10 +3760,33 @@ var init_session = __esm({
3640
3760
  );
3641
3761
  }
3642
3762
  } else if (event.type === "permission.requested") {
3643
- const { requestId, permissionRequest } = event.data;
3763
+ const { requestId, permissionRequest, resolvedByHook } = event.data;
3764
+ if (resolvedByHook) {
3765
+ return;
3766
+ }
3644
3767
  if (this.permissionHandler) {
3645
3768
  void this._executePermissionAndRespond(requestId, permissionRequest);
3646
3769
  }
3770
+ } else if (event.type === "command.execute") {
3771
+ const { requestId, commandName, command, args: args2 } = event.data;
3772
+ void this._executeCommandAndRespond(requestId, commandName, command, args2);
3773
+ } else if (event.type === "elicitation.requested") {
3774
+ if (this.elicitationHandler) {
3775
+ const { message, requestedSchema, mode, elicitationSource, url, requestId } = event.data;
3776
+ void this._handleElicitationRequest(
3777
+ {
3778
+ sessionId: this.sessionId,
3779
+ message,
3780
+ requestedSchema,
3781
+ mode,
3782
+ elicitationSource,
3783
+ url
3784
+ },
3785
+ requestId
3786
+ );
3787
+ }
3788
+ } else if (event.type === "capabilities.changed") {
3789
+ this._capabilities = { ...this._capabilities, ...event.data };
3647
3790
  }
3648
3791
  }
3649
3792
  /**
@@ -3665,6 +3808,8 @@ var init_session = __esm({
3665
3808
  result = "";
3666
3809
  } else if (typeof rawResult === "string") {
3667
3810
  result = rawResult;
3811
+ } else if (isToolResultObject(rawResult)) {
3812
+ result = rawResult;
3668
3813
  } else {
3669
3814
  result = JSON.stringify(rawResult);
3670
3815
  }
@@ -3708,6 +3853,39 @@ var init_session = __esm({
3708
3853
  }
3709
3854
  }
3710
3855
  }
3856
+ /**
3857
+ * Executes a command handler and sends the result back via RPC.
3858
+ * @internal
3859
+ */
3860
+ async _executeCommandAndRespond(requestId, commandName, command, args2) {
3861
+ const handler = this.commandHandlers.get(commandName);
3862
+ if (!handler) {
3863
+ try {
3864
+ await this.rpc.commands.handlePendingCommand({
3865
+ requestId,
3866
+ error: `Unknown command: ${commandName}`
3867
+ });
3868
+ } catch (rpcError) {
3869
+ if (!(rpcError instanceof import_node.ConnectionError || rpcError instanceof import_node.ResponseError)) {
3870
+ throw rpcError;
3871
+ }
3872
+ }
3873
+ return;
3874
+ }
3875
+ try {
3876
+ await handler({ sessionId: this.sessionId, command, commandName, args: args2 });
3877
+ await this.rpc.commands.handlePendingCommand({ requestId });
3878
+ } catch (error) {
3879
+ const message = error instanceof Error ? error.message : String(error);
3880
+ try {
3881
+ await this.rpc.commands.handlePendingCommand({ requestId, error: message });
3882
+ } catch (rpcError) {
3883
+ if (!(rpcError instanceof import_node.ConnectionError || rpcError instanceof import_node.ResponseError)) {
3884
+ throw rpcError;
3885
+ }
3886
+ }
3887
+ }
3888
+ }
3711
3889
  /**
3712
3890
  * Registers custom tool handlers for this session.
3713
3891
  *
@@ -3736,6 +3914,133 @@ var init_session = __esm({
3736
3914
  getToolHandler(name) {
3737
3915
  return this.toolHandlers.get(name);
3738
3916
  }
3917
+ /**
3918
+ * Registers command handlers for this session.
3919
+ *
3920
+ * @param commands - An array of command definitions with handlers, or undefined to clear
3921
+ * @internal This method is typically called internally when creating/resuming a session.
3922
+ */
3923
+ registerCommands(commands) {
3924
+ this.commandHandlers.clear();
3925
+ if (!commands) {
3926
+ return;
3927
+ }
3928
+ for (const cmd of commands) {
3929
+ this.commandHandlers.set(cmd.name, cmd.handler);
3930
+ }
3931
+ }
3932
+ /**
3933
+ * Registers the elicitation handler for this session.
3934
+ *
3935
+ * @param handler - The handler to invoke when the server dispatches an elicitation request
3936
+ * @internal This method is typically called internally when creating/resuming a session.
3937
+ */
3938
+ registerElicitationHandler(handler) {
3939
+ this.elicitationHandler = handler;
3940
+ }
3941
+ /**
3942
+ * Handles an elicitation.requested broadcast event.
3943
+ * Invokes the registered handler and responds via handlePendingElicitation RPC.
3944
+ * @internal
3945
+ */
3946
+ async _handleElicitationRequest(context, requestId) {
3947
+ if (!this.elicitationHandler) {
3948
+ return;
3949
+ }
3950
+ try {
3951
+ const result = await this.elicitationHandler(context);
3952
+ await this.rpc.ui.handlePendingElicitation({ requestId, result });
3953
+ } catch {
3954
+ try {
3955
+ await this.rpc.ui.handlePendingElicitation({
3956
+ requestId,
3957
+ result: { action: "cancel" }
3958
+ });
3959
+ } catch (rpcError) {
3960
+ if (!(rpcError instanceof import_node.ConnectionError || rpcError instanceof import_node.ResponseError)) {
3961
+ throw rpcError;
3962
+ }
3963
+ }
3964
+ }
3965
+ }
3966
+ /**
3967
+ * Sets the host capabilities for this session.
3968
+ *
3969
+ * @param capabilities - The capabilities object from the create/resume response
3970
+ * @internal This method is typically called internally when creating/resuming a session.
3971
+ */
3972
+ setCapabilities(capabilities) {
3973
+ this._capabilities = capabilities ?? {};
3974
+ }
3975
+ assertElicitation() {
3976
+ if (!this._capabilities.ui?.elicitation) {
3977
+ throw new Error(
3978
+ "Elicitation is not supported by the host. Check session.capabilities.ui?.elicitation before calling UI methods."
3979
+ );
3980
+ }
3981
+ }
3982
+ async _elicitation(params) {
3983
+ this.assertElicitation();
3984
+ return this.rpc.ui.elicitation({
3985
+ message: params.message,
3986
+ requestedSchema: params.requestedSchema
3987
+ });
3988
+ }
3989
+ async _confirm(message) {
3990
+ this.assertElicitation();
3991
+ const result = await this.rpc.ui.elicitation({
3992
+ message,
3993
+ requestedSchema: {
3994
+ type: "object",
3995
+ properties: {
3996
+ confirmed: { type: "boolean", default: true }
3997
+ },
3998
+ required: ["confirmed"]
3999
+ }
4000
+ });
4001
+ return result.action === "accept" && result.content?.confirmed === true;
4002
+ }
4003
+ async _select(message, options) {
4004
+ this.assertElicitation();
4005
+ const result = await this.rpc.ui.elicitation({
4006
+ message,
4007
+ requestedSchema: {
4008
+ type: "object",
4009
+ properties: {
4010
+ selection: { type: "string", enum: options }
4011
+ },
4012
+ required: ["selection"]
4013
+ }
4014
+ });
4015
+ if (result.action === "accept" && result.content?.selection != null) {
4016
+ return result.content.selection;
4017
+ }
4018
+ return null;
4019
+ }
4020
+ async _input(message, options) {
4021
+ this.assertElicitation();
4022
+ const field = { type: "string" };
4023
+ if (options?.title) field.title = options.title;
4024
+ if (options?.description) field.description = options.description;
4025
+ if (options?.minLength != null) field.minLength = options.minLength;
4026
+ if (options?.maxLength != null) field.maxLength = options.maxLength;
4027
+ if (options?.format) field.format = options.format;
4028
+ if (options?.default != null) field.default = options.default;
4029
+ const result = await this.rpc.ui.elicitation({
4030
+ message,
4031
+ requestedSchema: {
4032
+ type: "object",
4033
+ properties: {
4034
+ value: field
4035
+ },
4036
+ required: ["value"]
4037
+ }
4038
+ });
4039
+ if (result.action === "accept" && result.content?.value != null) {
4040
+ return result.content.value;
4041
+ }
4042
+ return null;
4043
+ }
3739
4044
  /**
3740
4045
  * Registers a handler for permission requests.
3741
4046
  *
@@ -4080,7 +4385,7 @@ var init_client = __esm({
4080
4385
  init_session();
4081
4386
  init_telemetry();
4082
4387
  MIN_PROTOCOL_VERSION = 2;
4083
- CopilotClient = class {
4388
+ CopilotClient = class _CopilotClient {
4084
4389
  cliProcess = null;
4085
4390
  connection = null;
4086
4391
  socket = null;
@@ -4103,6 +4408,8 @@ var init_client = __esm({
4103
4408
  processExitPromise = null;
4104
4409
  // Rejects when CLI process exits
4105
4410
  negotiatedProtocolVersion = null;
4411
+ /** Connection-level session filesystem config, set via constructor option. */
4412
+ sessionFsConfig = null;
4106
4413
  /**
4107
4414
  * Typed server-scoped RPC methods.
4108
4415
  * @throws Error if the client is not connected
@@ -4151,6 +4458,9 @@ var init_client = __esm({
4151
4458
  "githubToken and useLoggedInUser cannot be used with cliUrl (external server manages its own auth)"
4152
4459
  );
4153
4460
  }
4461
+ if (options.sessionFs) {
4462
+ this.validateSessionFsConfig(options.sessionFs);
4463
+ }
4154
4464
  if (options.cliUrl) {
4155
4465
  const { host, port } = this.parseCliUrl(options.cliUrl);
4156
4466
  this.actualHost = host;
@@ -4162,8 +4472,10 @@ var init_client = __esm({
4162
4472
  }
4163
4473
  this.onListModels = options.onListModels;
4164
4474
  this.onGetTraceContext = options.onGetTraceContext;
4475
+ this.sessionFsConfig = options.sessionFs ?? null;
4476
+ const effectiveEnv = options.env ?? process.env;
4165
4477
  this.options = {
4166
- cliPath: options.cliUrl ? void 0 : options.cliPath || getBundledCliPath(),
4478
+ cliPath: options.cliUrl ? void 0 : options.cliPath || effectiveEnv.COPILOT_CLI_PATH || getBundledCliPath(),
4167
4479
  cliArgs: options.cliArgs ?? [],
4168
4480
  cwd: options.cwd ?? process.cwd(),
4169
4481
  port: options.port || 0,
@@ -4174,7 +4486,7 @@ var init_client = __esm({
4174
4486
  logLevel: options.logLevel || "debug",
4175
4487
  autoStart: options.autoStart ?? true,
4176
4488
  autoRestart: false,
4177
- env: options.env ?? process.env,
4489
+ env: effectiveEnv,
4178
4490
  githubToken: options.githubToken,
4179
4491
  // Default useLoggedInUser to false when githubToken is provided, otherwise true
4180
4492
  useLoggedInUser: options.useLoggedInUser ?? (options.githubToken ? false : true),
@@ -4203,6 +4515,17 @@ var init_client = __esm({
4203
4515
  }
4204
4516
  return { host, port };
4205
4517
  }
4518
+ validateSessionFsConfig(config) {
4519
+ if (!config.initialCwd) {
4520
+ throw new Error("sessionFs.initialCwd is required");
4521
+ }
4522
+ if (!config.sessionStatePath) {
4523
+ throw new Error("sessionFs.sessionStatePath is required");
4524
+ }
4525
+ if (config.conventions !== "windows" && config.conventions !== "posix") {
4526
+ throw new Error("sessionFs.conventions must be either 'windows' or 'posix'");
4527
+ }
4528
+ }
4206
4529
  /**
4207
4530
  * Starts the CLI server and establishes a connection.
4208
4531
  *
@@ -4232,6 +4555,13 @@ var init_client = __esm({
4232
4555
  }
4233
4556
  await this.connectToServer();
4234
4557
  await this.verifyProtocolVersion();
4558
+ if (this.sessionFsConfig) {
4559
+ await this.connection.sendRequest("sessionFs.setProvider", {
4560
+ initialCwd: this.sessionFsConfig.initialCwd,
4561
+ sessionStatePath: this.sessionFsConfig.sessionStatePath,
4562
+ conventions: this.sessionFsConfig.conventions
4563
+ });
4564
+ }
4235
4565
  this.state = "connected";
4236
4566
  } catch (error) {
4237
4567
  this.state = "error";
@@ -4438,10 +4768,14 @@ var init_client = __esm({
4438
4768
  this.onGetTraceContext
4439
4769
  );
4440
4770
  session.registerTools(config.tools);
4771
+ session.registerCommands(config.commands);
4441
4772
  session.registerPermissionHandler(config.onPermissionRequest);
4442
4773
  if (config.onUserInputRequest) {
4443
4774
  session.registerUserInputHandler(config.onUserInputRequest);
4444
4775
  }
4776
+ if (config.onElicitationRequest) {
4777
+ session.registerElicitationHandler(config.onElicitationRequest);
4778
+ }
4445
4779
  if (config.hooks) {
4446
4780
  session.registerHooks(config.hooks);
4447
4781
  }
@@ -4455,6 +4789,15 @@ var init_client = __esm({
4455
4789
  session.on(config.onEvent);
4456
4790
  }
4457
4791
  this.sessions.set(sessionId, session);
4792
+ if (this.sessionFsConfig) {
4793
+ if (config.createSessionFsHandler) {
4794
+ session.clientSessionApis.sessionFs = config.createSessionFsHandler(session);
4795
+ } else {
4796
+ throw new Error(
4797
+ "createSessionFsHandler is required in session config when sessionFs is enabled in client options."
4798
+ );
4799
+ }
4800
+ }
4458
4801
  try {
4459
4802
  const response = await this.connection.sendRequest("session.create", {
4460
4803
  ...await getTraceContext(this.onGetTraceContext),
@@ -4469,12 +4812,18 @@ var init_client = __esm({
4469
4812
  overridesBuiltInTool: tool.overridesBuiltInTool,
4470
4813
  skipPermission: tool.skipPermission
4471
4814
  })),
4815
+ commands: config.commands?.map((cmd) => ({
4816
+ name: cmd.name,
4817
+ description: cmd.description
4818
+ })),
4472
4819
  systemMessage: wireSystemMessage,
4473
4820
  availableTools: config.availableTools,
4474
4821
  excludedTools: config.excludedTools,
4475
4822
  provider: config.provider,
4823
+ modelCapabilities: config.modelCapabilities,
4476
4824
  requestPermission: true,
4477
4825
  requestUserInput: !!config.onUserInputRequest,
4826
+ requestElicitation: !!config.onElicitationRequest,
4478
4827
  hooks: !!(config.hooks && Object.values(config.hooks).some(Boolean)),
4479
4828
  workingDirectory: config.workingDirectory,
4480
4829
  streaming: config.streaming,
@@ -4483,12 +4832,14 @@ var init_client = __esm({
4483
4832
  customAgents: config.customAgents,
4484
4833
  agent: config.agent,
4485
4834
  configDir: config.configDir,
4835
+ enableConfigDiscovery: config.enableConfigDiscovery,
4486
4836
  skillDirectories: config.skillDirectories,
4487
4837
  disabledSkills: config.disabledSkills,
4488
4838
  infiniteSessions: config.infiniteSessions
4489
4839
  });
4490
- const { workspacePath } = response;
4840
+ const { workspacePath, capabilities } = response;
4491
4841
  session["_workspacePath"] = workspacePath;
4842
+ session.setCapabilities(capabilities);
4492
4843
  } catch (e) {
4493
4844
  this.sessions.delete(sessionId);
4494
4845
  throw e;
@@ -4539,10 +4890,14 @@ var init_client = __esm({
4539
4890
  this.onGetTraceContext
4540
4891
  );
4541
4892
  session.registerTools(config.tools);
4893
+ session.registerCommands(config.commands);
4542
4894
  session.registerPermissionHandler(config.onPermissionRequest);
4543
4895
  if (config.onUserInputRequest) {
4544
4896
  session.registerUserInputHandler(config.onUserInputRequest);
4545
4897
  }
4898
+ if (config.onElicitationRequest) {
4899
+ session.registerElicitationHandler(config.onElicitationRequest);
4900
+ }
4546
4901
  if (config.hooks) {
4547
4902
  session.registerHooks(config.hooks);
4548
4903
  }
@@ -4556,6 +4911,15 @@ var init_client = __esm({
4556
4911
  session.on(config.onEvent);
4557
4912
  }
4558
4913
  this.sessions.set(sessionId, session);
4914
+ if (this.sessionFsConfig) {
4915
+ if (config.createSessionFsHandler) {
4916
+ session.clientSessionApis.sessionFs = config.createSessionFsHandler(session);
4917
+ } else {
4918
+ throw new Error(
4919
+ "createSessionFsHandler is required in session config when sessionFs is enabled in client options."
4920
+ );
4921
+ }
4922
+ }
4559
4923
  try {
4560
4924
  const response = await this.connection.sendRequest("session.resume", {
4561
4925
  ...await getTraceContext(this.onGetTraceContext),
@@ -4573,12 +4937,19 @@ var init_client = __esm({
4573
4937
  overridesBuiltInTool: tool.overridesBuiltInTool,
4574
4938
  skipPermission: tool.skipPermission
4575
4939
  })),
4940
+ commands: config.commands?.map((cmd) => ({
4941
+ name: cmd.name,
4942
+ description: cmd.description
4943
+ })),
4576
4944
  provider: config.provider,
4945
+ modelCapabilities: config.modelCapabilities,
4577
4946
  requestPermission: true,
4578
4947
  requestUserInput: !!config.onUserInputRequest,
4948
+ requestElicitation: !!config.onElicitationRequest,
4579
4949
  hooks: !!(config.hooks && Object.values(config.hooks).some(Boolean)),
4580
4950
  workingDirectory: config.workingDirectory,
4581
4951
  configDir: config.configDir,
4952
+ enableConfigDiscovery: config.enableConfigDiscovery,
4582
4953
  streaming: config.streaming,
4583
4954
  mcpServers: config.mcpServers,
4584
4955
  envValueMode: "direct",
@@ -4589,8 +4960,9 @@ var init_client = __esm({
4589
4960
  infiniteSessions: config.infiniteSessions,
4590
4961
  disableResume: config.disableResume
4591
4962
  });
4592
- const { workspacePath } = response;
4963
+ const { workspacePath, capabilities } = response;
4593
4964
  session["_workspacePath"] = workspacePath;
4965
+ session.setCapabilities(capabilities);
4594
4966
  } catch (e) {
4595
4967
  this.sessions.delete(sessionId);
4596
4968
  throw e;
@@ -4786,16 +5158,50 @@ var init_client = __esm({
4786
5158
  if (!this.connection) {
4787
5159
  throw new Error("Client not connected");
4788
5160
  }
4789
- const response = await this.connection.sendRequest("session.list", { filter });
5161
+ const response = await this.connection.sendRequest("session.list", {
5162
+ filter
5163
+ });
4790
5164
  const { sessions } = response;
4791
- return sessions.map((s) => ({
4792
- sessionId: s.sessionId,
4793
- startTime: new Date(s.startTime),
4794
- modifiedTime: new Date(s.modifiedTime),
4795
- summary: s.summary,
4796
- isRemote: s.isRemote,
4797
- context: s.context
4798
- }));
5165
+ return sessions.map(_CopilotClient.toSessionMetadata);
5166
+ }
5167
+ /**
5168
+ * Gets metadata for a specific session by ID.
5169
+ *
5170
+ * This provides an efficient O(1) lookup of a single session's metadata
5171
+ * instead of listing all sessions. Returns undefined if the session is not found.
5172
+ *
5173
+ * @param sessionId - The ID of the session to look up
5174
+ * @returns A promise that resolves with the session metadata, or undefined if not found
5175
+ * @throws Error if the client is not connected
5176
+ *
5177
+ * @example
5178
+ * ```typescript
5179
+ * const metadata = await client.getSessionMetadata("session-123");
5180
+ * if (metadata) {
5181
+ * console.log(`Session started at: ${metadata.startTime}`);
5182
+ * }
5183
+ * ```
5184
+ */
5185
+ async getSessionMetadata(sessionId) {
5186
+ if (!this.connection) {
5187
+ throw new Error("Client not connected");
5188
+ }
5189
+ const response = await this.connection.sendRequest("session.getMetadata", { sessionId });
5190
+ const { session } = response;
5191
+ if (!session) {
5192
+ return void 0;
5193
+ }
5194
+ return _CopilotClient.toSessionMetadata(session);
5195
+ }
5196
+ static toSessionMetadata(raw) {
5197
+ return {
5198
+ sessionId: raw.sessionId,
5199
+ startTime: new Date(raw.startTime),
5200
+ modifiedTime: new Date(raw.modifiedTime),
5201
+ summary: raw.summary,
5202
+ isRemote: raw.isRemote,
5203
+ context: raw.context
5204
+ };
4799
5205
  }
4800
5206
  /**
4801
5207
  * Gets the foreground session ID in TUI+server mode.
@@ -5125,6 +5531,12 @@ stderr: ${stderrOutput}`
5125
5531
  "systemMessage.transform",
5126
5532
  async (params) => await this.handleSystemMessageTransform(params)
5127
5533
  );
5534
+ const sessions = this.sessions;
5535
+ registerClientSessionApiHandlers(this.connection, (sessionId) => {
5536
+ const session = sessions.get(sessionId);
5537
+ if (!session) throw new Error(`No session found for sessionId: ${sessionId}`);
5538
+ return session.clientSessionApis;
5539
+ });
5128
5540
  this.connection.onClose(() => {
5129
5541
  this.state = "disconnected";
5130
5542
  });
@@ -8404,6 +8816,212 @@ import path12 from "path";
8404
8816
  // packages/core/src/services/policy.ts
8405
8817
  import fs6 from "fs/promises";
8406
8818
  import path8 from "path";
8819
+ import { pathToFileURL } from "url";
8820
+
8821
+ // packages/core/src/services/policy/types.ts
8822
+ function isNativePlugin(obj) {
8823
+ if (typeof obj !== "object" || obj === null) return false;
8824
+ const record = obj;
8825
+ if (typeof record.meta !== "object" || record.meta === null) return false;
8826
+ if (typeof record.name === "string") return false;
8827
+ const meta = record.meta;
8828
+ if (typeof meta.name !== "string" || meta.name.trim().length === 0) return false;
8829
+ if (meta.sourceType !== void 0 && !["module", "json", "builtin"].includes(meta.sourceType))
8830
+ return false;
8831
+ if (meta.trust !== void 0 && !["trusted-code", "safe-declarative"].includes(meta.trust))
8832
+ return false;
8833
+ return true;
8834
+ }
8835
+ function validateNativePlugin(obj, source) {
8836
+ const { meta } = obj;
8837
+ if (!meta.name?.trim()) {
8838
+ throw new Error(`Native plugin "${source}" is invalid: meta.name is required`);
8839
+ }
8840
+ if (obj.afterDetect !== void 0 && typeof obj.afterDetect !== "function") {
8841
+ throw new Error(`Native plugin "${source}" is invalid: afterDetect must be a function`);
8842
+ }
8843
+ if (obj.beforeRecommend !== void 0 && typeof obj.beforeRecommend !== "function") {
8844
+ throw new Error(`Native plugin "${source}" is invalid: beforeRecommend must be a function`);
8845
+ }
8846
+ if (obj.afterRecommend !== void 0 && typeof obj.afterRecommend !== "function") {
8847
+ throw new Error(`Native plugin "${source}" is invalid: afterRecommend must be a function`);
8848
+ }
8849
+ if (obj.onError !== void 0 && typeof obj.onError !== "function") {
8850
+ throw new Error(`Native plugin "${source}" is invalid: onError must be a function`);
8851
+ }
8852
+ if (obj.detectors !== void 0) {
8853
+ if (!Array.isArray(obj.detectors)) {
8854
+ throw new Error(`Native plugin "${source}" is invalid: detectors must be an array`);
8855
+ }
8856
+ for (const [i, d] of obj.detectors.entries()) {
8857
+ if (typeof d !== "object" || d === null) {
8858
+ throw new Error(`Native plugin "${source}" is invalid: detectors[${i}] must be an object`);
8859
+ }
8860
+ if (typeof d.id !== "string" || !d.id.trim()) {
8861
+ throw new Error(
8862
+ `Native plugin "${source}" is invalid: detectors[${i}].id must be a non-empty string`
8863
+ );
8864
+ }
8865
+ if (typeof d.detect !== "function") {
8866
+ throw new Error(
8867
+ `Native plugin "${source}" is invalid: detectors[${i}].detect must be a function`
8868
+ );
8869
+ }
8870
+ }
8871
+ }
8872
+ if (obj.recommenders !== void 0) {
8873
+ if (!Array.isArray(obj.recommenders)) {
8874
+ throw new Error(`Native plugin "${source}" is invalid: recommenders must be an array`);
8875
+ }
8876
+ for (const [i, r] of obj.recommenders.entries()) {
8877
+ if (typeof r !== "object" || r === null) {
8878
+ throw new Error(
8879
+ `Native plugin "${source}" is invalid: recommenders[${i}] must be an object`
8880
+ );
8881
+ }
8882
+ if (typeof r.id !== "string" || !r.id.trim()) {
8883
+ throw new Error(
8884
+ `Native plugin "${source}" is invalid: recommenders[${i}].id must be a non-empty string`
8885
+ );
8886
+ }
8887
+ if (typeof r.recommend !== "function") {
8888
+ throw new Error(
8889
+ `Native plugin "${source}" is invalid: recommenders[${i}].recommend must be a function`
8890
+ );
8891
+ }
8892
+ }
8893
+ }
8894
+ const hasHooks = obj.detectors?.length || obj.afterDetect || obj.beforeRecommend || obj.recommenders?.length || obj.afterRecommend;
8895
+ if (!hasHooks) {
8896
+ throw new Error(
8897
+ `Native plugin "${source}" is invalid: must implement at least one hook (detectors, afterDetect, beforeRecommend, recommenders, or afterRecommend)`
8898
+ );
8899
+ }
8900
+ }
8901
+ var IMPACT_WEIGHTS = {
8902
+ critical: 5,
8903
+ high: 4,
8904
+ medium: 3,
8905
+ low: 2,
8906
+ info: 0
8907
+ };
8908
+ function calculateScore(signals, recommendations) {
8909
+ const activeSignals = signals.filter((s) => s.status !== "not-detected");
8910
+ if (activeSignals.length === 0) {
8911
+ return { score: 1, grade: "A" };
8912
+ }
8913
+ const maxWeight = activeSignals.length * IMPACT_WEIGHTS.critical;
8914
+ const deductions = recommendations.reduce((sum, rec) => sum + IMPACT_WEIGHTS[rec.impact], 0);
8915
+ const score = Math.max(0, Math.min(1, 1 - deductions / maxWeight));
8916
+ return { score, grade: scoreToGrade(score) };
8917
+ }
8918
+ function scoreToGrade(score) {
8919
+ if (score >= 0.9) return "A";
8920
+ if (score >= 0.8) return "B";
8921
+ if (score >= 0.7) return "C";
8922
+ if (score >= 0.6) return "D";
8923
+ return "F";
8924
+ }
8925
+ function applySignalPatch(signals, patch, pluginName) {
8926
+ let result = [...signals];
8927
+ if (patch.remove?.length) {
8928
+ const removeSet = new Set(patch.remove);
8929
+ result = result.filter((s) => !removeSet.has(s.id));
8930
+ }
8931
+ if (patch.modify?.length) {
8932
+ for (const mod of patch.modify) {
8933
+ const idx = result.findIndex((s) => s.id === mod.id);
8934
+ if (idx >= 0) {
8935
+ const existing = result[idx];
8936
+ const changes = { ...mod.changes };
8937
+ if (changes.metadata && existing.metadata) {
8938
+ changes.metadata = { ...existing.metadata, ...changes.metadata };
8939
+ }
8940
+ result[idx] = {
8941
+ ...existing,
8942
+ ...changes,
8943
+ origin: {
8944
+ ...existing.origin,
8945
+ modifiedBy: [...existing.origin.modifiedBy ?? [], pluginName]
8946
+ }
8947
+ };
8948
+ }
8949
+ }
8950
+ }
8951
+ if (patch.add?.length) {
8952
+ result.push(
8953
+ ...patch.add.map((s) => ({
8954
+ ...s,
8955
+ evidence: s.evidence ? [...s.evidence] : void 0,
8956
+ metadata: s.metadata ? { ...s.metadata } : void 0
8957
+ }))
8958
+ );
8959
+ }
8960
+ return result;
8961
+ }
8962
+ function applyRecommendationPatch(recommendations, patch, pluginName) {
8963
+ let result = [...recommendations];
8964
+ if (patch.remove?.length) {
8965
+ const removeSet = new Set(patch.remove);
8966
+ result = result.filter((r) => !removeSet.has(r.id));
8967
+ }
8968
+ if (patch.modify?.length) {
8969
+ for (const mod of patch.modify) {
8970
+ const idx = result.findIndex((r) => r.id === mod.id);
8971
+ if (idx >= 0) {
8972
+ const existing = result[idx];
8973
+ result[idx] = {
8974
+ ...existing,
8975
+ ...mod.changes,
8976
+ origin: {
8977
+ ...existing.origin,
8978
+ modifiedBy: [...existing.origin.modifiedBy ?? [], pluginName]
8979
+ }
8980
+ };
8981
+ }
8982
+ }
8983
+ }
8984
+ if (patch.add?.length) {
8985
+ result.push(
8986
+ ...patch.add.map((r) => ({
8987
+ ...r,
8988
+ supersedes: r.supersedes ? [...r.supersedes] : void 0,
8989
+ metadata: r.metadata ? { ...r.metadata } : void 0
8990
+ }))
8991
+ );
8992
+ }
8993
+ return result;
8994
+ }
8995
+ function resolveSupersedes(recommendations) {
8996
+ const supersededIds = /* @__PURE__ */ new Set();
8997
+ const recIds = new Set(recommendations.map((r) => r.id));
8998
+ for (const rec of recommendations) {
8999
+ if (rec.supersedes?.length) {
9000
+ for (const id of rec.supersedes) {
9001
+ if (recIds.has(id)) {
9002
+ supersededIds.add(id);
9003
+ }
9004
+ }
9005
+ }
9006
+ }
9007
+ return recommendations.filter((r) => !supersededIds.has(r.id)).map((r) => {
9008
+ if (!r.supersedes?.length) return r;
9009
+ const actuallySuperseded = r.supersedes.filter((id) => supersededIds.has(id));
9010
+ if (actuallySuperseded.length === 0) return r;
9011
+ return {
9012
+ ...r,
9013
+ origin: {
9014
+ ...r.origin,
9015
+ modifiedBy: [
9016
+ ...r.origin.modifiedBy ?? [],
9017
+ ...actuallySuperseded.map((id) => `superseded:${id}`)
9018
+ ]
9019
+ }
9020
+ };
9021
+ });
9022
+ }
9023
+
9024
+ // packages/core/src/services/policy.ts
8407
9025
  var DEFAULT_PASS_RATE = 0.8;
8408
9026
  function validatePolicyConfig(obj, source, format = "module") {
8409
9027
  if (typeof obj !== "object" || obj === null) {
@@ -8494,6 +9112,16 @@ function parsePolicySources(raw) {
8494
9112
  const sources = raw.split(",").map((s) => s.trim()).filter(Boolean);
8495
9113
  return sources.length ? sources : void 0;
8496
9114
  }
9115
+ function normalizeNativePlugin(plugin) {
9116
+ return {
9117
+ ...plugin,
9118
+ meta: {
9119
+ ...plugin.meta,
9120
+ sourceType: "module",
9121
+ trust: "trusted-code"
9122
+ }
9123
+ };
9124
+ }
8497
9125
  async function loadPolicy(source, options) {
8498
9126
  const jsonOnly = options?.jsonOnly ?? false;
8499
9127
  if (source.startsWith(".") || path8.isAbsolute(source)) {
@@ -8512,8 +9140,12 @@ async function loadPolicy(source, options) {
8512
9140
  );
8513
9141
  }
8514
9142
  try {
8515
- const mod = await import(resolved);
9143
+ const mod = await import(pathToFileURL(resolved).href);
8516
9144
  const config = mod.default ?? mod;
9145
+ if (isNativePlugin(config)) {
9146
+ validateNativePlugin(config, source);
9147
+ return normalizeNativePlugin(config);
9148
+ }
8517
9149
  return validatePolicyConfig(config, source);
8518
9150
  } catch (err) {
8519
9151
  if (err instanceof Error && (err.message.includes("Cannot find module") || err.message.includes("MODULE_NOT_FOUND"))) {
@@ -8540,6 +9172,10 @@ async function loadPolicy(source, options) {
8540
9172
  try {
8541
9173
  const mod = await import(source);
8542
9174
  const config = mod.default ?? mod;
9175
+ if (isNativePlugin(config)) {
9176
+ validateNativePlugin(config, source);
9177
+ return normalizeNativePlugin(config);
9178
+ }
8543
9179
  return validatePolicyConfig(config, source);
8544
9180
  } catch (err) {
8545
9181
  const message = err instanceof Error ? err.message : typeof err === "object" && err !== null && "message" in err ? String(err.message) : String(err);
@@ -8603,130 +9239,6 @@ function resolveChain(baseCriteria, baseExtras, policies) {
8603
9239
  return { chain, criteria, extras, thresholds: { passRate } };
8604
9240
  }
8605
9241
 
8606
- // packages/core/src/services/policy/types.ts
8607
- var IMPACT_WEIGHTS = {
8608
- critical: 5,
8609
- high: 4,
8610
- medium: 3,
8611
- low: 2,
8612
- info: 0
8613
- };
8614
- function calculateScore(signals, recommendations) {
8615
- const activeSignals = signals.filter((s) => s.status !== "not-detected");
8616
- if (activeSignals.length === 0) {
8617
- return { score: 1, grade: "A" };
8618
- }
8619
- const maxWeight = activeSignals.length * IMPACT_WEIGHTS.critical;
8620
- const deductions = recommendations.reduce((sum, rec) => sum + IMPACT_WEIGHTS[rec.impact], 0);
8621
- const score = Math.max(0, Math.min(1, 1 - deductions / maxWeight));
8622
- return { score, grade: scoreToGrade(score) };
8623
- }
8624
- function scoreToGrade(score) {
8625
- if (score >= 0.9) return "A";
8626
- if (score >= 0.8) return "B";
8627
- if (score >= 0.7) return "C";
8628
- if (score >= 0.6) return "D";
8629
- return "F";
8630
- }
8631
- function applySignalPatch(signals, patch, pluginName) {
8632
- let result = [...signals];
8633
- if (patch.remove?.length) {
8634
- const removeSet = new Set(patch.remove);
8635
- result = result.filter((s) => !removeSet.has(s.id));
8636
- }
8637
- if (patch.modify?.length) {
8638
- for (const mod of patch.modify) {
8639
- const idx = result.findIndex((s) => s.id === mod.id);
8640
- if (idx >= 0) {
8641
- const existing = result[idx];
8642
- const changes = { ...mod.changes };
8643
- if (changes.metadata && existing.metadata) {
8644
- changes.metadata = { ...existing.metadata, ...changes.metadata };
8645
- }
8646
- result[idx] = {
8647
- ...existing,
8648
- ...changes,
8649
- origin: {
8650
- ...existing.origin,
8651
- modifiedBy: [...existing.origin.modifiedBy ?? [], pluginName]
8652
- }
8653
- };
8654
- }
8655
- }
8656
- }
8657
- if (patch.add?.length) {
8658
- result.push(
8659
- ...patch.add.map((s) => ({
8660
- ...s,
8661
- evidence: s.evidence ? [...s.evidence] : void 0,
8662
- metadata: s.metadata ? { ...s.metadata } : void 0
8663
- }))
8664
- );
8665
- }
8666
- return result;
8667
- }
8668
- function applyRecommendationPatch(recommendations, patch, pluginName) {
8669
- let result = [...recommendations];
8670
- if (patch.remove?.length) {
8671
- const removeSet = new Set(patch.remove);
8672
- result = result.filter((r) => !removeSet.has(r.id));
8673
- }
8674
- if (patch.modify?.length) {
8675
- for (const mod of patch.modify) {
8676
- const idx = result.findIndex((r) => r.id === mod.id);
8677
- if (idx >= 0) {
8678
- const existing = result[idx];
8679
- result[idx] = {
8680
- ...existing,
8681
- ...mod.changes,
8682
- origin: {
8683
- ...existing.origin,
8684
- modifiedBy: [...existing.origin.modifiedBy ?? [], pluginName]
8685
- }
8686
- };
8687
- }
8688
- }
8689
- }
8690
- if (patch.add?.length) {
8691
- result.push(
8692
- ...patch.add.map((r) => ({
8693
- ...r,
8694
- supersedes: r.supersedes ? [...r.supersedes] : void 0,
8695
- metadata: r.metadata ? { ...r.metadata } : void 0
8696
- }))
8697
- );
8698
- }
8699
- return result;
8700
- }
8701
- function resolveSupersedes(recommendations) {
8702
- const supersededIds = /* @__PURE__ */ new Set();
8703
- const recIds = new Set(recommendations.map((r) => r.id));
8704
- for (const rec of recommendations) {
8705
- if (rec.supersedes?.length) {
8706
- for (const id of rec.supersedes) {
8707
- if (recIds.has(id)) {
8708
- supersededIds.add(id);
8709
- }
8710
- }
8711
- }
8712
- }
8713
- return recommendations.filter((r) => !supersededIds.has(r.id)).map((r) => {
8714
- if (!r.supersedes?.length) return r;
8715
- const actuallySuperseded = r.supersedes.filter((id) => supersededIds.has(id));
8716
- if (actuallySuperseded.length === 0) return r;
8717
- return {
8718
- ...r,
8719
- origin: {
8720
- ...r.origin,
8721
- modifiedBy: [
8722
- ...r.origin.modifiedBy ?? [],
8723
- ...actuallySuperseded.map((id) => `superseded:${id}`)
8724
- ]
8725
- }
8726
- };
8727
- });
8728
- }
8729
-
8730
9242
  // packages/core/src/services/policy/engine.ts
8731
9243
  async function executePlugins(plugins, ctx, options) {
8732
9244
  const warnings = [];
@@ -9032,9 +9544,21 @@ async function loadPluginChain(policySources, options) {
9032
9544
  const allDisabledIds = [];
9033
9545
  let passRateThreshold = 0.8;
9034
9546
  for (const source of policySources) {
9035
- const policyConfig = await loadPolicy(source, {
9547
+ const loaded = await loadPolicy(source, {
9036
9548
  jsonOnly: options?.jsonOnly
9037
9549
  });
9550
+ if (isNativePlugin(loaded)) {
9551
+ plugins.push({
9552
+ ...loaded,
9553
+ meta: {
9554
+ ...loaded.meta,
9555
+ sourceType: "module",
9556
+ trust: "trusted-code"
9557
+ }
9558
+ });
9559
+ continue;
9560
+ }
9561
+ const policyConfig = loaded;
9038
9562
  if (isImperativePlugin(policyConfig)) {
9039
9563
  const { plugin: imperativePlugin, compiled } = wrapImperativePolicy(
9040
9564
  policyConfig,
@@ -10233,14 +10757,28 @@ async function runReadinessReport(options) {
10233
10757
  let policyInfo;
10234
10758
  if (policySources?.length) {
10235
10759
  const policyConfigs = [];
10760
+ let hasNativePlugin = false;
10236
10761
  for (const source of policySources) {
10237
- policyConfigs.push(await loadPolicy(source, { jsonOnly: isConfigSourced }));
10762
+ const loaded = await loadPolicy(source, { jsonOnly: isConfigSourced });
10763
+ if (isNativePlugin(loaded)) {
10764
+ hasNativePlugin = true;
10765
+ continue;
10766
+ }
10767
+ policyConfigs.push(loaded);
10768
+ }
10769
+ if (policyConfigs.length > 0) {
10770
+ const resolved = resolveChain(baseCriteria, baseExtras, policyConfigs);
10771
+ resolvedCriteria = resolved.criteria;
10772
+ resolvedExtras = resolved.extras;
10773
+ passRateThreshold = resolved.thresholds.passRate;
10774
+ policyInfo = { chain: resolved.chain, criteriaCount: resolved.criteria.length };
10775
+ } else {
10776
+ resolvedCriteria = baseCriteria;
10777
+ resolvedExtras = baseExtras;
10778
+ }
10779
+ if (hasNativePlugin && !options.shadow) {
10780
+ options = { ...options, shadow: true };
10238
10781
  }
10239
- const resolved = resolveChain(baseCriteria, baseExtras, policyConfigs);
10240
- resolvedCriteria = resolved.criteria;
10241
- resolvedExtras = resolved.extras;
10242
- passRateThreshold = resolved.thresholds.passRate;
10243
- policyInfo = { chain: resolved.chain, criteriaCount: resolved.criteria.length };
10244
10782
  } else {
10245
10783
  resolvedCriteria = baseCriteria;
10246
10784
  resolvedExtras = baseExtras;