@microsoft/agentrc 2.0.1-9 → 2.0.1-90
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/README.md +12 -0
- package/dist/index.js +2102 -917
- package/dist/index.js.map +1 -1
- package/package.json +7 -4
package/dist/index.js
CHANGED
|
@@ -3052,7 +3052,7 @@ var require_main = __commonJS({
|
|
|
3052
3052
|
exports.createMessageConnection = exports.createServerSocketTransport = exports.createClientSocketTransport = exports.createServerPipeTransport = exports.createClientPipeTransport = exports.generateRandomPipeName = exports.StreamMessageWriter = exports.StreamMessageReader = exports.SocketMessageWriter = exports.SocketMessageReader = exports.PortMessageWriter = exports.PortMessageReader = exports.IPCMessageWriter = exports.IPCMessageReader = void 0;
|
|
3053
3053
|
var ril_1 = require_ril();
|
|
3054
3054
|
ril_1.default.install();
|
|
3055
|
-
var
|
|
3055
|
+
var path26 = __require("path");
|
|
3056
3056
|
var os2 = __require("os");
|
|
3057
3057
|
var crypto_1 = __require("crypto");
|
|
3058
3058
|
var net_1 = __require("net");
|
|
@@ -3188,9 +3188,9 @@ var require_main = __commonJS({
|
|
|
3188
3188
|
}
|
|
3189
3189
|
let result;
|
|
3190
3190
|
if (XDG_RUNTIME_DIR) {
|
|
3191
|
-
result =
|
|
3191
|
+
result = path26.join(XDG_RUNTIME_DIR, `vscode-ipc-${randomSuffix}.sock`);
|
|
3192
3192
|
} else {
|
|
3193
|
-
result =
|
|
3193
|
+
result = path26.join(os2.tmpdir(), `vscode-${randomSuffix}.sock`);
|
|
3194
3194
|
}
|
|
3195
3195
|
const limit = safeIpcPathLengths.get(process.platform);
|
|
3196
3196
|
if (limit !== void 0 && result.length > limit) {
|
|
@@ -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
|
}
|
|
@@ -3331,26 +3346,120 @@ function createSessionRpc(connection, sessionId) {
|
|
|
3331
3346
|
readFile: async (params) => connection.sendRequest("session.workspace.readFile", { sessionId, ...params }),
|
|
3332
3347
|
createFile: async (params) => connection.sendRequest("session.workspace.createFile", { sessionId, ...params })
|
|
3333
3348
|
},
|
|
3349
|
+
/** @experimental */
|
|
3334
3350
|
fleet: {
|
|
3335
3351
|
start: async (params) => connection.sendRequest("session.fleet.start", { sessionId, ...params })
|
|
3336
3352
|
},
|
|
3353
|
+
/** @experimental */
|
|
3337
3354
|
agent: {
|
|
3338
3355
|
list: async () => connection.sendRequest("session.agent.list", { sessionId }),
|
|
3339
3356
|
getCurrent: async () => connection.sendRequest("session.agent.getCurrent", { sessionId }),
|
|
3340
3357
|
select: async (params) => connection.sendRequest("session.agent.select", { sessionId, ...params }),
|
|
3341
|
-
deselect: async () => connection.sendRequest("session.agent.deselect", { sessionId })
|
|
3358
|
+
deselect: async () => connection.sendRequest("session.agent.deselect", { sessionId }),
|
|
3359
|
+
reload: async () => connection.sendRequest("session.agent.reload", { sessionId })
|
|
3342
3360
|
},
|
|
3343
|
-
|
|
3344
|
-
|
|
3361
|
+
/** @experimental */
|
|
3362
|
+
skills: {
|
|
3363
|
+
list: async () => connection.sendRequest("session.skills.list", { sessionId }),
|
|
3364
|
+
enable: async (params) => connection.sendRequest("session.skills.enable", { sessionId, ...params }),
|
|
3365
|
+
disable: async (params) => connection.sendRequest("session.skills.disable", { sessionId, ...params }),
|
|
3366
|
+
reload: async () => connection.sendRequest("session.skills.reload", { sessionId })
|
|
3367
|
+
},
|
|
3368
|
+
/** @experimental */
|
|
3369
|
+
mcp: {
|
|
3370
|
+
list: async () => connection.sendRequest("session.mcp.list", { sessionId }),
|
|
3371
|
+
enable: async (params) => connection.sendRequest("session.mcp.enable", { sessionId, ...params }),
|
|
3372
|
+
disable: async (params) => connection.sendRequest("session.mcp.disable", { sessionId, ...params }),
|
|
3373
|
+
reload: async () => connection.sendRequest("session.mcp.reload", { sessionId })
|
|
3374
|
+
},
|
|
3375
|
+
/** @experimental */
|
|
3376
|
+
plugins: {
|
|
3377
|
+
list: async () => connection.sendRequest("session.plugins.list", { sessionId })
|
|
3378
|
+
},
|
|
3379
|
+
/** @experimental */
|
|
3380
|
+
extensions: {
|
|
3381
|
+
list: async () => connection.sendRequest("session.extensions.list", { sessionId }),
|
|
3382
|
+
enable: async (params) => connection.sendRequest("session.extensions.enable", { sessionId, ...params }),
|
|
3383
|
+
disable: async (params) => connection.sendRequest("session.extensions.disable", { sessionId, ...params }),
|
|
3384
|
+
reload: async () => connection.sendRequest("session.extensions.reload", { sessionId })
|
|
3345
3385
|
},
|
|
3346
3386
|
tools: {
|
|
3347
3387
|
handlePendingToolCall: async (params) => connection.sendRequest("session.tools.handlePendingToolCall", { sessionId, ...params })
|
|
3348
3388
|
},
|
|
3389
|
+
commands: {
|
|
3390
|
+
handlePendingCommand: async (params) => connection.sendRequest("session.commands.handlePendingCommand", { sessionId, ...params })
|
|
3391
|
+
},
|
|
3392
|
+
ui: {
|
|
3393
|
+
elicitation: async (params) => connection.sendRequest("session.ui.elicitation", { sessionId, ...params }),
|
|
3394
|
+
handlePendingElicitation: async (params) => connection.sendRequest("session.ui.handlePendingElicitation", { sessionId, ...params })
|
|
3395
|
+
},
|
|
3349
3396
|
permissions: {
|
|
3350
3397
|
handlePendingPermissionRequest: async (params) => connection.sendRequest("session.permissions.handlePendingPermissionRequest", { sessionId, ...params })
|
|
3398
|
+
},
|
|
3399
|
+
log: async (params) => connection.sendRequest("session.log", { sessionId, ...params }),
|
|
3400
|
+
shell: {
|
|
3401
|
+
exec: async (params) => connection.sendRequest("session.shell.exec", { sessionId, ...params }),
|
|
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 })
|
|
3351
3408
|
}
|
|
3352
3409
|
};
|
|
3353
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
|
+
}
|
|
3354
3463
|
var init_rpc = __esm({
|
|
3355
3464
|
"node_modules/@github/copilot-sdk/dist/generated/rpc.js"() {
|
|
3356
3465
|
"use strict";
|
|
@@ -3369,13 +3478,49 @@ var init_sdkProtocolVersion = __esm({
|
|
|
3369
3478
|
}
|
|
3370
3479
|
});
|
|
3371
3480
|
|
|
3481
|
+
// node_modules/@github/copilot-sdk/dist/telemetry.js
|
|
3482
|
+
async function getTraceContext(provider) {
|
|
3483
|
+
if (!provider) return {};
|
|
3484
|
+
try {
|
|
3485
|
+
return await provider() ?? {};
|
|
3486
|
+
} catch {
|
|
3487
|
+
return {};
|
|
3488
|
+
}
|
|
3489
|
+
}
|
|
3490
|
+
var init_telemetry = __esm({
|
|
3491
|
+
"node_modules/@github/copilot-sdk/dist/telemetry.js"() {
|
|
3492
|
+
"use strict";
|
|
3493
|
+
}
|
|
3494
|
+
});
|
|
3495
|
+
|
|
3372
3496
|
// node_modules/@github/copilot-sdk/dist/session.js
|
|
3373
|
-
|
|
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
|
+
}
|
|
3516
|
+
var import_node, NO_RESULT_PERMISSION_V2_ERROR, CopilotSession;
|
|
3374
3517
|
var init_session = __esm({
|
|
3375
3518
|
"node_modules/@github/copilot-sdk/dist/session.js"() {
|
|
3376
3519
|
"use strict";
|
|
3377
3520
|
import_node = __toESM(require_node(), 1);
|
|
3378
3521
|
init_rpc();
|
|
3522
|
+
init_telemetry();
|
|
3523
|
+
NO_RESULT_PERMISSION_V2_ERROR = "Permission handlers cannot return 'no-result' when connected to a protocol v2 server.";
|
|
3379
3524
|
CopilotSession = class {
|
|
3380
3525
|
/**
|
|
3381
3526
|
* Creates a new CopilotSession instance.
|
|
@@ -3383,20 +3528,29 @@ var init_session = __esm({
|
|
|
3383
3528
|
* @param sessionId - The unique identifier for this session
|
|
3384
3529
|
* @param connection - The JSON-RPC message connection to the Copilot CLI
|
|
3385
3530
|
* @param workspacePath - Path to the session workspace directory (when infinite sessions enabled)
|
|
3531
|
+
* @param traceContextProvider - Optional callback to get W3C Trace Context for outbound RPCs
|
|
3386
3532
|
* @internal This constructor is internal. Use {@link CopilotClient.createSession} to create sessions.
|
|
3387
3533
|
*/
|
|
3388
|
-
constructor(sessionId, connection, _workspacePath) {
|
|
3534
|
+
constructor(sessionId, connection, _workspacePath, traceContextProvider) {
|
|
3389
3535
|
this.sessionId = sessionId;
|
|
3390
3536
|
this.connection = connection;
|
|
3391
3537
|
this._workspacePath = _workspacePath;
|
|
3538
|
+
this.traceContextProvider = traceContextProvider;
|
|
3392
3539
|
}
|
|
3393
3540
|
eventHandlers = /* @__PURE__ */ new Set();
|
|
3394
3541
|
typedEventHandlers = /* @__PURE__ */ new Map();
|
|
3395
3542
|
toolHandlers = /* @__PURE__ */ new Map();
|
|
3543
|
+
commandHandlers = /* @__PURE__ */ new Map();
|
|
3396
3544
|
permissionHandler;
|
|
3397
3545
|
userInputHandler;
|
|
3546
|
+
elicitationHandler;
|
|
3398
3547
|
hooks;
|
|
3548
|
+
transformCallbacks;
|
|
3399
3549
|
_rpc = null;
|
|
3550
|
+
traceContextProvider;
|
|
3551
|
+
_capabilities = {};
|
|
3552
|
+
/** @internal Client session API handlers, populated by CopilotClient during create/resume. */
|
|
3553
|
+
clientSessionApis = {};
|
|
3400
3554
|
/**
|
|
3401
3555
|
* Typed session-scoped RPC methods.
|
|
3402
3556
|
*/
|
|
@@ -3414,6 +3568,33 @@ var init_session = __esm({
|
|
|
3414
3568
|
get workspacePath() {
|
|
3415
3569
|
return this._workspacePath;
|
|
3416
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
|
+
}
|
|
3417
3598
|
/**
|
|
3418
3599
|
* Sends a message to this session and waits for the response.
|
|
3419
3600
|
*
|
|
@@ -3434,6 +3615,7 @@ var init_session = __esm({
|
|
|
3434
3615
|
*/
|
|
3435
3616
|
async send(options) {
|
|
3436
3617
|
const response = await this.connection.sendRequest("session.send", {
|
|
3618
|
+
...await getTraceContext(this.traceContextProvider),
|
|
3437
3619
|
sessionId: this.sessionId,
|
|
3438
3620
|
prompt: options.prompt,
|
|
3439
3621
|
attachments: options.attachments,
|
|
@@ -3563,34 +3745,71 @@ var init_session = __esm({
|
|
|
3563
3745
|
const { requestId, toolName } = event.data;
|
|
3564
3746
|
const args2 = event.data.arguments;
|
|
3565
3747
|
const toolCallId = event.data.toolCallId;
|
|
3748
|
+
const traceparent = event.data.traceparent;
|
|
3749
|
+
const tracestate = event.data.tracestate;
|
|
3566
3750
|
const handler = this.toolHandlers.get(toolName);
|
|
3567
3751
|
if (handler) {
|
|
3568
|
-
void this._executeToolAndRespond(
|
|
3752
|
+
void this._executeToolAndRespond(
|
|
3753
|
+
requestId,
|
|
3754
|
+
toolName,
|
|
3755
|
+
toolCallId,
|
|
3756
|
+
args2,
|
|
3757
|
+
handler,
|
|
3758
|
+
traceparent,
|
|
3759
|
+
tracestate
|
|
3760
|
+
);
|
|
3569
3761
|
}
|
|
3570
3762
|
} else if (event.type === "permission.requested") {
|
|
3571
|
-
const { requestId, permissionRequest } = event.data;
|
|
3763
|
+
const { requestId, permissionRequest, resolvedByHook } = event.data;
|
|
3764
|
+
if (resolvedByHook) {
|
|
3765
|
+
return;
|
|
3766
|
+
}
|
|
3572
3767
|
if (this.permissionHandler) {
|
|
3573
3768
|
void this._executePermissionAndRespond(requestId, permissionRequest);
|
|
3574
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 };
|
|
3575
3790
|
}
|
|
3576
3791
|
}
|
|
3577
3792
|
/**
|
|
3578
3793
|
* Executes a tool handler and sends the result back via RPC.
|
|
3579
3794
|
* @internal
|
|
3580
3795
|
*/
|
|
3581
|
-
async _executeToolAndRespond(requestId, toolName, toolCallId, args2, handler) {
|
|
3796
|
+
async _executeToolAndRespond(requestId, toolName, toolCallId, args2, handler, traceparent, tracestate) {
|
|
3582
3797
|
try {
|
|
3583
3798
|
const rawResult = await handler(args2, {
|
|
3584
3799
|
sessionId: this.sessionId,
|
|
3585
3800
|
toolCallId,
|
|
3586
3801
|
toolName,
|
|
3587
|
-
arguments: args2
|
|
3802
|
+
arguments: args2,
|
|
3803
|
+
traceparent,
|
|
3804
|
+
tracestate
|
|
3588
3805
|
});
|
|
3589
3806
|
let result;
|
|
3590
3807
|
if (rawResult == null) {
|
|
3591
3808
|
result = "";
|
|
3592
3809
|
} else if (typeof rawResult === "string") {
|
|
3593
3810
|
result = rawResult;
|
|
3811
|
+
} else if (isToolResultObject(rawResult)) {
|
|
3812
|
+
result = rawResult;
|
|
3594
3813
|
} else {
|
|
3595
3814
|
result = JSON.stringify(rawResult);
|
|
3596
3815
|
}
|
|
@@ -3615,6 +3834,9 @@ var init_session = __esm({
|
|
|
3615
3834
|
const result = await this.permissionHandler(permissionRequest, {
|
|
3616
3835
|
sessionId: this.sessionId
|
|
3617
3836
|
});
|
|
3837
|
+
if (result.kind === "no-result") {
|
|
3838
|
+
return;
|
|
3839
|
+
}
|
|
3618
3840
|
await this.rpc.permissions.handlePendingPermissionRequest({ requestId, result });
|
|
3619
3841
|
} catch (_error) {
|
|
3620
3842
|
try {
|
|
@@ -3631,6 +3853,39 @@ var init_session = __esm({
|
|
|
3631
3853
|
}
|
|
3632
3854
|
}
|
|
3633
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
|
+
}
|
|
3634
3889
|
/**
|
|
3635
3890
|
* Registers custom tool handlers for this session.
|
|
3636
3891
|
*
|
|
@@ -3659,6 +3914,133 @@ var init_session = __esm({
|
|
|
3659
3914
|
getToolHandler(name) {
|
|
3660
3915
|
return this.toolHandlers.get(name);
|
|
3661
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
|
+
}
|
|
3662
4044
|
/**
|
|
3663
4045
|
* Registers a handler for permission requests.
|
|
3664
4046
|
*
|
|
@@ -3695,6 +4077,40 @@ var init_session = __esm({
|
|
|
3695
4077
|
registerHooks(hooks) {
|
|
3696
4078
|
this.hooks = hooks;
|
|
3697
4079
|
}
|
|
4080
|
+
/**
|
|
4081
|
+
* Registers transform callbacks for system message sections.
|
|
4082
|
+
*
|
|
4083
|
+
* @param callbacks - Map of section ID to transform callback, or undefined to clear
|
|
4084
|
+
* @internal This method is typically called internally when creating a session.
|
|
4085
|
+
*/
|
|
4086
|
+
registerTransformCallbacks(callbacks) {
|
|
4087
|
+
this.transformCallbacks = callbacks;
|
|
4088
|
+
}
|
|
4089
|
+
/**
|
|
4090
|
+
* Handles a systemMessage.transform request from the runtime.
|
|
4091
|
+
* Dispatches each section to its registered transform callback.
|
|
4092
|
+
*
|
|
4093
|
+
* @param sections - Map of section IDs to their current rendered content
|
|
4094
|
+
* @returns A promise that resolves with the transformed sections
|
|
4095
|
+
* @internal This method is for internal use by the SDK.
|
|
4096
|
+
*/
|
|
4097
|
+
async _handleSystemMessageTransform(sections) {
|
|
4098
|
+
const result = {};
|
|
4099
|
+
for (const [sectionId, { content }] of Object.entries(sections)) {
|
|
4100
|
+
const callback = this.transformCallbacks?.get(sectionId);
|
|
4101
|
+
if (callback) {
|
|
4102
|
+
try {
|
|
4103
|
+
const transformed = await callback(content);
|
|
4104
|
+
result[sectionId] = { content: transformed };
|
|
4105
|
+
} catch (_error) {
|
|
4106
|
+
result[sectionId] = { content };
|
|
4107
|
+
}
|
|
4108
|
+
} else {
|
|
4109
|
+
result[sectionId] = { content };
|
|
4110
|
+
}
|
|
4111
|
+
}
|
|
4112
|
+
return { sections: result };
|
|
4113
|
+
}
|
|
3698
4114
|
/**
|
|
3699
4115
|
* Handles a permission request in the v2 protocol format (synchronous RPC).
|
|
3700
4116
|
* Used as a back-compat adapter when connected to a v2 server.
|
|
@@ -3711,8 +4127,14 @@ var init_session = __esm({
|
|
|
3711
4127
|
const result = await this.permissionHandler(request, {
|
|
3712
4128
|
sessionId: this.sessionId
|
|
3713
4129
|
});
|
|
4130
|
+
if (result.kind === "no-result") {
|
|
4131
|
+
throw new Error(NO_RESULT_PERMISSION_V2_ERROR);
|
|
4132
|
+
}
|
|
3714
4133
|
return result;
|
|
3715
|
-
} catch (
|
|
4134
|
+
} catch (error) {
|
|
4135
|
+
if (error instanceof Error && error.message === NO_RESULT_PERMISSION_V2_ERROR) {
|
|
4136
|
+
throw error;
|
|
4137
|
+
}
|
|
3716
4138
|
return { kind: "denied-no-approval-rule-and-could-not-request-from-user" };
|
|
3717
4139
|
}
|
|
3718
4140
|
}
|
|
@@ -3868,14 +4290,35 @@ var init_session = __esm({
|
|
|
3868
4290
|
* The new model takes effect for the next message. Conversation history is preserved.
|
|
3869
4291
|
*
|
|
3870
4292
|
* @param model - Model ID to switch to
|
|
4293
|
+
* @param options - Optional settings for the new model
|
|
3871
4294
|
*
|
|
3872
4295
|
* @example
|
|
3873
4296
|
* ```typescript
|
|
3874
4297
|
* await session.setModel("gpt-4.1");
|
|
4298
|
+
* await session.setModel("claude-sonnet-4.6", { reasoningEffort: "high" });
|
|
3875
4299
|
* ```
|
|
3876
4300
|
*/
|
|
3877
|
-
async setModel(model) {
|
|
3878
|
-
await this.rpc.model.switchTo({ modelId: model });
|
|
4301
|
+
async setModel(model, options) {
|
|
4302
|
+
await this.rpc.model.switchTo({ modelId: model, ...options });
|
|
4303
|
+
}
|
|
4304
|
+
/**
|
|
4305
|
+
* Log a message to the session timeline.
|
|
4306
|
+
* The message appears in the session event stream and is visible to SDK consumers
|
|
4307
|
+
* and (for non-ephemeral messages) persisted to the session event log on disk.
|
|
4308
|
+
*
|
|
4309
|
+
* @param message - Human-readable message text
|
|
4310
|
+
* @param options - Optional log level and ephemeral flag
|
|
4311
|
+
*
|
|
4312
|
+
* @example
|
|
4313
|
+
* ```typescript
|
|
4314
|
+
* await session.log("Processing started");
|
|
4315
|
+
* await session.log("Disk usage high", { level: "warning" });
|
|
4316
|
+
* await session.log("Connection failed", { level: "error" });
|
|
4317
|
+
* await session.log("Debug info", { ephemeral: true });
|
|
4318
|
+
* ```
|
|
4319
|
+
*/
|
|
4320
|
+
async log(message, options) {
|
|
4321
|
+
await this.rpc.log({ message, ...options });
|
|
3879
4322
|
}
|
|
3880
4323
|
};
|
|
3881
4324
|
}
|
|
@@ -3883,7 +4326,9 @@ var init_session = __esm({
|
|
|
3883
4326
|
|
|
3884
4327
|
// node_modules/@github/copilot-sdk/dist/client.js
|
|
3885
4328
|
import { spawn } from "child_process";
|
|
4329
|
+
import { randomUUID } from "crypto";
|
|
3886
4330
|
import { existsSync } from "fs";
|
|
4331
|
+
import { createRequire } from "module";
|
|
3887
4332
|
import { Socket } from "net";
|
|
3888
4333
|
import { dirname, join } from "path";
|
|
3889
4334
|
import { fileURLToPath } from "url";
|
|
@@ -3897,6 +4342,30 @@ function toJsonSchema(parameters) {
|
|
|
3897
4342
|
}
|
|
3898
4343
|
return parameters;
|
|
3899
4344
|
}
|
|
4345
|
+
function extractTransformCallbacks(systemMessage) {
|
|
4346
|
+
if (!systemMessage || systemMessage.mode !== "customize" || !systemMessage.sections) {
|
|
4347
|
+
return { wirePayload: systemMessage, transformCallbacks: void 0 };
|
|
4348
|
+
}
|
|
4349
|
+
const transformCallbacks = /* @__PURE__ */ new Map();
|
|
4350
|
+
const wireSections = {};
|
|
4351
|
+
for (const [sectionId, override] of Object.entries(systemMessage.sections)) {
|
|
4352
|
+
if (!override) continue;
|
|
4353
|
+
if (typeof override.action === "function") {
|
|
4354
|
+
transformCallbacks.set(sectionId, override.action);
|
|
4355
|
+
wireSections[sectionId] = { action: "transform" };
|
|
4356
|
+
} else {
|
|
4357
|
+
wireSections[sectionId] = { action: override.action, content: override.content };
|
|
4358
|
+
}
|
|
4359
|
+
}
|
|
4360
|
+
if (transformCallbacks.size === 0) {
|
|
4361
|
+
return { wirePayload: systemMessage, transformCallbacks: void 0 };
|
|
4362
|
+
}
|
|
4363
|
+
const wirePayload = {
|
|
4364
|
+
...systemMessage,
|
|
4365
|
+
sections: wireSections
|
|
4366
|
+
};
|
|
4367
|
+
return { wirePayload, transformCallbacks };
|
|
4368
|
+
}
|
|
3900
4369
|
function getNodeExecPath() {
|
|
3901
4370
|
if (process.versions.bun) {
|
|
3902
4371
|
return "node";
|
|
@@ -3914,8 +4383,9 @@ var init_client = __esm({
|
|
|
3914
4383
|
init_rpc();
|
|
3915
4384
|
init_sdkProtocolVersion();
|
|
3916
4385
|
init_session();
|
|
4386
|
+
init_telemetry();
|
|
3917
4387
|
MIN_PROTOCOL_VERSION = 2;
|
|
3918
|
-
CopilotClient = class {
|
|
4388
|
+
CopilotClient = class _CopilotClient {
|
|
3919
4389
|
cliProcess = null;
|
|
3920
4390
|
connection = null;
|
|
3921
4391
|
socket = null;
|
|
@@ -3928,6 +4398,8 @@ var init_client = __esm({
|
|
|
3928
4398
|
options;
|
|
3929
4399
|
isExternalServer = false;
|
|
3930
4400
|
forceStopping = false;
|
|
4401
|
+
onListModels;
|
|
4402
|
+
onGetTraceContext;
|
|
3931
4403
|
modelsCache = null;
|
|
3932
4404
|
modelsCacheLock = Promise.resolve();
|
|
3933
4405
|
sessionLifecycleHandlers = /* @__PURE__ */ new Set();
|
|
@@ -3936,6 +4408,8 @@ var init_client = __esm({
|
|
|
3936
4408
|
processExitPromise = null;
|
|
3937
4409
|
// Rejects when CLI process exits
|
|
3938
4410
|
negotiatedProtocolVersion = null;
|
|
4411
|
+
/** Connection-level session filesystem config, set via constructor option. */
|
|
4412
|
+
sessionFsConfig = null;
|
|
3939
4413
|
/**
|
|
3940
4414
|
* Typed server-scoped RPC methods.
|
|
3941
4415
|
* @throws Error if the client is not connected
|
|
@@ -3984,6 +4458,9 @@ var init_client = __esm({
|
|
|
3984
4458
|
"githubToken and useLoggedInUser cannot be used with cliUrl (external server manages its own auth)"
|
|
3985
4459
|
);
|
|
3986
4460
|
}
|
|
4461
|
+
if (options.sessionFs) {
|
|
4462
|
+
this.validateSessionFsConfig(options.sessionFs);
|
|
4463
|
+
}
|
|
3987
4464
|
if (options.cliUrl) {
|
|
3988
4465
|
const { host, port } = this.parseCliUrl(options.cliUrl);
|
|
3989
4466
|
this.actualHost = host;
|
|
@@ -3993,8 +4470,12 @@ var init_client = __esm({
|
|
|
3993
4470
|
if (options.isChildProcess) {
|
|
3994
4471
|
this.isExternalServer = true;
|
|
3995
4472
|
}
|
|
4473
|
+
this.onListModels = options.onListModels;
|
|
4474
|
+
this.onGetTraceContext = options.onGetTraceContext;
|
|
4475
|
+
this.sessionFsConfig = options.sessionFs ?? null;
|
|
4476
|
+
const effectiveEnv = options.env ?? process.env;
|
|
3996
4477
|
this.options = {
|
|
3997
|
-
cliPath: options.cliPath || getBundledCliPath(),
|
|
4478
|
+
cliPath: options.cliUrl ? void 0 : options.cliPath || effectiveEnv.COPILOT_CLI_PATH || getBundledCliPath(),
|
|
3998
4479
|
cliArgs: options.cliArgs ?? [],
|
|
3999
4480
|
cwd: options.cwd ?? process.cwd(),
|
|
4000
4481
|
port: options.port || 0,
|
|
@@ -4004,11 +4485,12 @@ var init_client = __esm({
|
|
|
4004
4485
|
cliUrl: options.cliUrl,
|
|
4005
4486
|
logLevel: options.logLevel || "debug",
|
|
4006
4487
|
autoStart: options.autoStart ?? true,
|
|
4007
|
-
autoRestart:
|
|
4008
|
-
env:
|
|
4488
|
+
autoRestart: false,
|
|
4489
|
+
env: effectiveEnv,
|
|
4009
4490
|
githubToken: options.githubToken,
|
|
4010
4491
|
// Default useLoggedInUser to false when githubToken is provided, otherwise true
|
|
4011
|
-
useLoggedInUser: options.useLoggedInUser ?? (options.githubToken ? false : true)
|
|
4492
|
+
useLoggedInUser: options.useLoggedInUser ?? (options.githubToken ? false : true),
|
|
4493
|
+
telemetry: options.telemetry
|
|
4012
4494
|
};
|
|
4013
4495
|
}
|
|
4014
4496
|
/**
|
|
@@ -4033,6 +4515,17 @@ var init_client = __esm({
|
|
|
4033
4515
|
}
|
|
4034
4516
|
return { host, port };
|
|
4035
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
|
+
}
|
|
4036
4529
|
/**
|
|
4037
4530
|
* Starts the CLI server and establishes a connection.
|
|
4038
4531
|
*
|
|
@@ -4062,6 +4555,13 @@ var init_client = __esm({
|
|
|
4062
4555
|
}
|
|
4063
4556
|
await this.connectToServer();
|
|
4064
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
|
+
}
|
|
4065
4565
|
this.state = "connected";
|
|
4066
4566
|
} catch (error) {
|
|
4067
4567
|
this.state = "error";
|
|
@@ -4260,45 +4760,90 @@ var init_client = __esm({
|
|
|
4260
4760
|
throw new Error("Client not connected. Call start() first.");
|
|
4261
4761
|
}
|
|
4262
4762
|
}
|
|
4263
|
-
const
|
|
4264
|
-
|
|
4265
|
-
sessionId
|
|
4266
|
-
|
|
4267
|
-
|
|
4268
|
-
|
|
4269
|
-
|
|
4270
|
-
description: tool.description,
|
|
4271
|
-
parameters: toJsonSchema(tool.parameters),
|
|
4272
|
-
overridesBuiltInTool: tool.overridesBuiltInTool
|
|
4273
|
-
})),
|
|
4274
|
-
systemMessage: config.systemMessage,
|
|
4275
|
-
availableTools: config.availableTools,
|
|
4276
|
-
excludedTools: config.excludedTools,
|
|
4277
|
-
provider: config.provider,
|
|
4278
|
-
requestPermission: true,
|
|
4279
|
-
requestUserInput: !!config.onUserInputRequest,
|
|
4280
|
-
hooks: !!(config.hooks && Object.values(config.hooks).some(Boolean)),
|
|
4281
|
-
workingDirectory: config.workingDirectory,
|
|
4282
|
-
streaming: config.streaming,
|
|
4283
|
-
mcpServers: config.mcpServers,
|
|
4284
|
-
envValueMode: "direct",
|
|
4285
|
-
customAgents: config.customAgents,
|
|
4286
|
-
configDir: config.configDir,
|
|
4287
|
-
skillDirectories: config.skillDirectories,
|
|
4288
|
-
disabledSkills: config.disabledSkills,
|
|
4289
|
-
infiniteSessions: config.infiniteSessions
|
|
4290
|
-
});
|
|
4291
|
-
const { sessionId, workspacePath } = response;
|
|
4292
|
-
const session = new CopilotSession(sessionId, this.connection, workspacePath);
|
|
4763
|
+
const sessionId = config.sessionId ?? randomUUID();
|
|
4764
|
+
const session = new CopilotSession(
|
|
4765
|
+
sessionId,
|
|
4766
|
+
this.connection,
|
|
4767
|
+
void 0,
|
|
4768
|
+
this.onGetTraceContext
|
|
4769
|
+
);
|
|
4293
4770
|
session.registerTools(config.tools);
|
|
4771
|
+
session.registerCommands(config.commands);
|
|
4294
4772
|
session.registerPermissionHandler(config.onPermissionRequest);
|
|
4295
4773
|
if (config.onUserInputRequest) {
|
|
4296
4774
|
session.registerUserInputHandler(config.onUserInputRequest);
|
|
4297
4775
|
}
|
|
4776
|
+
if (config.onElicitationRequest) {
|
|
4777
|
+
session.registerElicitationHandler(config.onElicitationRequest);
|
|
4778
|
+
}
|
|
4298
4779
|
if (config.hooks) {
|
|
4299
4780
|
session.registerHooks(config.hooks);
|
|
4300
4781
|
}
|
|
4782
|
+
const { wirePayload: wireSystemMessage, transformCallbacks } = extractTransformCallbacks(
|
|
4783
|
+
config.systemMessage
|
|
4784
|
+
);
|
|
4785
|
+
if (transformCallbacks) {
|
|
4786
|
+
session.registerTransformCallbacks(transformCallbacks);
|
|
4787
|
+
}
|
|
4788
|
+
if (config.onEvent) {
|
|
4789
|
+
session.on(config.onEvent);
|
|
4790
|
+
}
|
|
4301
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
|
+
}
|
|
4801
|
+
try {
|
|
4802
|
+
const response = await this.connection.sendRequest("session.create", {
|
|
4803
|
+
...await getTraceContext(this.onGetTraceContext),
|
|
4804
|
+
model: config.model,
|
|
4805
|
+
sessionId,
|
|
4806
|
+
clientName: config.clientName,
|
|
4807
|
+
reasoningEffort: config.reasoningEffort,
|
|
4808
|
+
tools: config.tools?.map((tool) => ({
|
|
4809
|
+
name: tool.name,
|
|
4810
|
+
description: tool.description,
|
|
4811
|
+
parameters: toJsonSchema(tool.parameters),
|
|
4812
|
+
overridesBuiltInTool: tool.overridesBuiltInTool,
|
|
4813
|
+
skipPermission: tool.skipPermission
|
|
4814
|
+
})),
|
|
4815
|
+
commands: config.commands?.map((cmd) => ({
|
|
4816
|
+
name: cmd.name,
|
|
4817
|
+
description: cmd.description
|
|
4818
|
+
})),
|
|
4819
|
+
systemMessage: wireSystemMessage,
|
|
4820
|
+
availableTools: config.availableTools,
|
|
4821
|
+
excludedTools: config.excludedTools,
|
|
4822
|
+
provider: config.provider,
|
|
4823
|
+
modelCapabilities: config.modelCapabilities,
|
|
4824
|
+
requestPermission: true,
|
|
4825
|
+
requestUserInput: !!config.onUserInputRequest,
|
|
4826
|
+
requestElicitation: !!config.onElicitationRequest,
|
|
4827
|
+
hooks: !!(config.hooks && Object.values(config.hooks).some(Boolean)),
|
|
4828
|
+
workingDirectory: config.workingDirectory,
|
|
4829
|
+
streaming: config.streaming,
|
|
4830
|
+
mcpServers: config.mcpServers,
|
|
4831
|
+
envValueMode: "direct",
|
|
4832
|
+
customAgents: config.customAgents,
|
|
4833
|
+
agent: config.agent,
|
|
4834
|
+
configDir: config.configDir,
|
|
4835
|
+
enableConfigDiscovery: config.enableConfigDiscovery,
|
|
4836
|
+
skillDirectories: config.skillDirectories,
|
|
4837
|
+
disabledSkills: config.disabledSkills,
|
|
4838
|
+
infiniteSessions: config.infiniteSessions
|
|
4839
|
+
});
|
|
4840
|
+
const { workspacePath, capabilities } = response;
|
|
4841
|
+
session["_workspacePath"] = workspacePath;
|
|
4842
|
+
session.setCapabilities(capabilities);
|
|
4843
|
+
} catch (e) {
|
|
4844
|
+
this.sessions.delete(sessionId);
|
|
4845
|
+
throw e;
|
|
4846
|
+
}
|
|
4302
4847
|
return session;
|
|
4303
4848
|
}
|
|
4304
4849
|
/**
|
|
@@ -4338,46 +4883,90 @@ var init_client = __esm({
|
|
|
4338
4883
|
throw new Error("Client not connected. Call start() first.");
|
|
4339
4884
|
}
|
|
4340
4885
|
}
|
|
4341
|
-
const
|
|
4886
|
+
const session = new CopilotSession(
|
|
4342
4887
|
sessionId,
|
|
4343
|
-
|
|
4344
|
-
|
|
4345
|
-
|
|
4346
|
-
|
|
4347
|
-
availableTools: config.availableTools,
|
|
4348
|
-
excludedTools: config.excludedTools,
|
|
4349
|
-
tools: config.tools?.map((tool) => ({
|
|
4350
|
-
name: tool.name,
|
|
4351
|
-
description: tool.description,
|
|
4352
|
-
parameters: toJsonSchema(tool.parameters),
|
|
4353
|
-
overridesBuiltInTool: tool.overridesBuiltInTool
|
|
4354
|
-
})),
|
|
4355
|
-
provider: config.provider,
|
|
4356
|
-
requestPermission: true,
|
|
4357
|
-
requestUserInput: !!config.onUserInputRequest,
|
|
4358
|
-
hooks: !!(config.hooks && Object.values(config.hooks).some(Boolean)),
|
|
4359
|
-
workingDirectory: config.workingDirectory,
|
|
4360
|
-
configDir: config.configDir,
|
|
4361
|
-
streaming: config.streaming,
|
|
4362
|
-
mcpServers: config.mcpServers,
|
|
4363
|
-
envValueMode: "direct",
|
|
4364
|
-
customAgents: config.customAgents,
|
|
4365
|
-
skillDirectories: config.skillDirectories,
|
|
4366
|
-
disabledSkills: config.disabledSkills,
|
|
4367
|
-
infiniteSessions: config.infiniteSessions,
|
|
4368
|
-
disableResume: config.disableResume
|
|
4369
|
-
});
|
|
4370
|
-
const { sessionId: resumedSessionId, workspacePath } = response;
|
|
4371
|
-
const session = new CopilotSession(resumedSessionId, this.connection, workspacePath);
|
|
4888
|
+
this.connection,
|
|
4889
|
+
void 0,
|
|
4890
|
+
this.onGetTraceContext
|
|
4891
|
+
);
|
|
4372
4892
|
session.registerTools(config.tools);
|
|
4893
|
+
session.registerCommands(config.commands);
|
|
4373
4894
|
session.registerPermissionHandler(config.onPermissionRequest);
|
|
4374
4895
|
if (config.onUserInputRequest) {
|
|
4375
4896
|
session.registerUserInputHandler(config.onUserInputRequest);
|
|
4376
4897
|
}
|
|
4898
|
+
if (config.onElicitationRequest) {
|
|
4899
|
+
session.registerElicitationHandler(config.onElicitationRequest);
|
|
4900
|
+
}
|
|
4377
4901
|
if (config.hooks) {
|
|
4378
4902
|
session.registerHooks(config.hooks);
|
|
4379
4903
|
}
|
|
4380
|
-
|
|
4904
|
+
const { wirePayload: wireSystemMessage, transformCallbacks } = extractTransformCallbacks(
|
|
4905
|
+
config.systemMessage
|
|
4906
|
+
);
|
|
4907
|
+
if (transformCallbacks) {
|
|
4908
|
+
session.registerTransformCallbacks(transformCallbacks);
|
|
4909
|
+
}
|
|
4910
|
+
if (config.onEvent) {
|
|
4911
|
+
session.on(config.onEvent);
|
|
4912
|
+
}
|
|
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
|
+
}
|
|
4923
|
+
try {
|
|
4924
|
+
const response = await this.connection.sendRequest("session.resume", {
|
|
4925
|
+
...await getTraceContext(this.onGetTraceContext),
|
|
4926
|
+
sessionId,
|
|
4927
|
+
clientName: config.clientName,
|
|
4928
|
+
model: config.model,
|
|
4929
|
+
reasoningEffort: config.reasoningEffort,
|
|
4930
|
+
systemMessage: wireSystemMessage,
|
|
4931
|
+
availableTools: config.availableTools,
|
|
4932
|
+
excludedTools: config.excludedTools,
|
|
4933
|
+
tools: config.tools?.map((tool) => ({
|
|
4934
|
+
name: tool.name,
|
|
4935
|
+
description: tool.description,
|
|
4936
|
+
parameters: toJsonSchema(tool.parameters),
|
|
4937
|
+
overridesBuiltInTool: tool.overridesBuiltInTool,
|
|
4938
|
+
skipPermission: tool.skipPermission
|
|
4939
|
+
})),
|
|
4940
|
+
commands: config.commands?.map((cmd) => ({
|
|
4941
|
+
name: cmd.name,
|
|
4942
|
+
description: cmd.description
|
|
4943
|
+
})),
|
|
4944
|
+
provider: config.provider,
|
|
4945
|
+
modelCapabilities: config.modelCapabilities,
|
|
4946
|
+
requestPermission: true,
|
|
4947
|
+
requestUserInput: !!config.onUserInputRequest,
|
|
4948
|
+
requestElicitation: !!config.onElicitationRequest,
|
|
4949
|
+
hooks: !!(config.hooks && Object.values(config.hooks).some(Boolean)),
|
|
4950
|
+
workingDirectory: config.workingDirectory,
|
|
4951
|
+
configDir: config.configDir,
|
|
4952
|
+
enableConfigDiscovery: config.enableConfigDiscovery,
|
|
4953
|
+
streaming: config.streaming,
|
|
4954
|
+
mcpServers: config.mcpServers,
|
|
4955
|
+
envValueMode: "direct",
|
|
4956
|
+
customAgents: config.customAgents,
|
|
4957
|
+
agent: config.agent,
|
|
4958
|
+
skillDirectories: config.skillDirectories,
|
|
4959
|
+
disabledSkills: config.disabledSkills,
|
|
4960
|
+
infiniteSessions: config.infiniteSessions,
|
|
4961
|
+
disableResume: config.disableResume
|
|
4962
|
+
});
|
|
4963
|
+
const { workspacePath, capabilities } = response;
|
|
4964
|
+
session["_workspacePath"] = workspacePath;
|
|
4965
|
+
session.setCapabilities(capabilities);
|
|
4966
|
+
} catch (e) {
|
|
4967
|
+
this.sessions.delete(sessionId);
|
|
4968
|
+
throw e;
|
|
4969
|
+
}
|
|
4381
4970
|
return session;
|
|
4382
4971
|
}
|
|
4383
4972
|
/**
|
|
@@ -4438,15 +5027,15 @@ var init_client = __esm({
|
|
|
4438
5027
|
/**
|
|
4439
5028
|
* List available models with their metadata.
|
|
4440
5029
|
*
|
|
5030
|
+
* If an `onListModels` handler was provided in the client options,
|
|
5031
|
+
* it is called instead of querying the CLI server.
|
|
5032
|
+
*
|
|
4441
5033
|
* Results are cached after the first successful call to avoid rate limiting.
|
|
4442
5034
|
* The cache is cleared when the client disconnects.
|
|
4443
5035
|
*
|
|
4444
|
-
* @throws Error if not
|
|
5036
|
+
* @throws Error if not connected (when no custom handler is set)
|
|
4445
5037
|
*/
|
|
4446
5038
|
async listModels() {
|
|
4447
|
-
if (!this.connection) {
|
|
4448
|
-
throw new Error("Client not connected");
|
|
4449
|
-
}
|
|
4450
5039
|
await this.modelsCacheLock;
|
|
4451
5040
|
let resolveLock;
|
|
4452
5041
|
this.modelsCacheLock = new Promise((resolve) => {
|
|
@@ -4456,10 +5045,18 @@ var init_client = __esm({
|
|
|
4456
5045
|
if (this.modelsCache !== null) {
|
|
4457
5046
|
return [...this.modelsCache];
|
|
4458
5047
|
}
|
|
4459
|
-
|
|
4460
|
-
|
|
4461
|
-
|
|
4462
|
-
|
|
5048
|
+
let models;
|
|
5049
|
+
if (this.onListModels) {
|
|
5050
|
+
models = await this.onListModels();
|
|
5051
|
+
} else {
|
|
5052
|
+
if (!this.connection) {
|
|
5053
|
+
throw new Error("Client not connected");
|
|
5054
|
+
}
|
|
5055
|
+
const result = await this.connection.sendRequest("models.list", {});
|
|
5056
|
+
const response = result;
|
|
5057
|
+
models = response.models;
|
|
5058
|
+
}
|
|
5059
|
+
this.modelsCache = [...models];
|
|
4463
5060
|
return [...models];
|
|
4464
5061
|
} finally {
|
|
4465
5062
|
resolveLock();
|
|
@@ -4561,16 +5158,50 @@ var init_client = __esm({
|
|
|
4561
5158
|
if (!this.connection) {
|
|
4562
5159
|
throw new Error("Client not connected");
|
|
4563
5160
|
}
|
|
4564
|
-
const response = await this.connection.sendRequest("session.list", {
|
|
5161
|
+
const response = await this.connection.sendRequest("session.list", {
|
|
5162
|
+
filter
|
|
5163
|
+
});
|
|
4565
5164
|
const { sessions } = response;
|
|
4566
|
-
return sessions.map(
|
|
4567
|
-
|
|
4568
|
-
|
|
4569
|
-
|
|
4570
|
-
|
|
4571
|
-
|
|
4572
|
-
|
|
4573
|
-
|
|
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
|
+
};
|
|
4574
5205
|
}
|
|
4575
5206
|
/**
|
|
4576
5207
|
* Gets the foreground session ID in TUI+server mode.
|
|
@@ -4672,6 +5303,27 @@ var init_client = __esm({
|
|
|
4672
5303
|
if (this.options.githubToken) {
|
|
4673
5304
|
envWithoutNodeDebug.COPILOT_SDK_AUTH_TOKEN = this.options.githubToken;
|
|
4674
5305
|
}
|
|
5306
|
+
if (!this.options.cliPath) {
|
|
5307
|
+
throw new Error(
|
|
5308
|
+
"Path to Copilot CLI is required. Please provide it via the cliPath option, or use cliUrl to rely on a remote CLI."
|
|
5309
|
+
);
|
|
5310
|
+
}
|
|
5311
|
+
if (this.options.telemetry) {
|
|
5312
|
+
const t = this.options.telemetry;
|
|
5313
|
+
envWithoutNodeDebug.COPILOT_OTEL_ENABLED = "true";
|
|
5314
|
+
if (t.otlpEndpoint !== void 0)
|
|
5315
|
+
envWithoutNodeDebug.OTEL_EXPORTER_OTLP_ENDPOINT = t.otlpEndpoint;
|
|
5316
|
+
if (t.filePath !== void 0)
|
|
5317
|
+
envWithoutNodeDebug.COPILOT_OTEL_FILE_EXPORTER_PATH = t.filePath;
|
|
5318
|
+
if (t.exporterType !== void 0)
|
|
5319
|
+
envWithoutNodeDebug.COPILOT_OTEL_EXPORTER_TYPE = t.exporterType;
|
|
5320
|
+
if (t.sourceName !== void 0)
|
|
5321
|
+
envWithoutNodeDebug.COPILOT_OTEL_SOURCE_NAME = t.sourceName;
|
|
5322
|
+
if (t.captureContent !== void 0)
|
|
5323
|
+
envWithoutNodeDebug.OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT = String(
|
|
5324
|
+
t.captureContent
|
|
5325
|
+
);
|
|
5326
|
+
}
|
|
4675
5327
|
if (!existsSync(this.options.cliPath)) {
|
|
4676
5328
|
throw new Error(
|
|
4677
5329
|
`Copilot CLI not found at ${this.options.cliPath}. Ensure @github/copilot is installed.`
|
|
@@ -4771,8 +5423,6 @@ stderr: ${stderrOutput}`
|
|
|
4771
5423
|
} else {
|
|
4772
5424
|
reject(new Error(`CLI server exited with code ${code}`));
|
|
4773
5425
|
}
|
|
4774
|
-
} else if (this.options.autoRestart && this.state === "connected") {
|
|
4775
|
-
void this.reconnect();
|
|
4776
5426
|
}
|
|
4777
5427
|
});
|
|
4778
5428
|
setTimeout(() => {
|
|
@@ -4877,12 +5527,21 @@ stderr: ${stderrOutput}`
|
|
|
4877
5527
|
"hooks.invoke",
|
|
4878
5528
|
async (params) => await this.handleHooksInvoke(params)
|
|
4879
5529
|
);
|
|
5530
|
+
this.connection.onRequest(
|
|
5531
|
+
"systemMessage.transform",
|
|
5532
|
+
async (params) => await this.handleSystemMessageTransform(params)
|
|
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
|
+
});
|
|
4880
5540
|
this.connection.onClose(() => {
|
|
4881
|
-
|
|
4882
|
-
void this.reconnect();
|
|
4883
|
-
}
|
|
5541
|
+
this.state = "disconnected";
|
|
4884
5542
|
});
|
|
4885
5543
|
this.connection.onError((_error) => {
|
|
5544
|
+
this.state = "disconnected";
|
|
4886
5545
|
});
|
|
4887
5546
|
}
|
|
4888
5547
|
handleSessionEventNotification(notification) {
|
|
@@ -4941,6 +5600,16 @@ stderr: ${stderrOutput}`
|
|
|
4941
5600
|
const output = await session._handleHooksInvoke(params.hookType, params.input);
|
|
4942
5601
|
return { output };
|
|
4943
5602
|
}
|
|
5603
|
+
async handleSystemMessageTransform(params) {
|
|
5604
|
+
if (!params || typeof params.sessionId !== "string" || !params.sections || typeof params.sections !== "object") {
|
|
5605
|
+
throw new Error("Invalid systemMessage.transform payload");
|
|
5606
|
+
}
|
|
5607
|
+
const session = this.sessions.get(params.sessionId);
|
|
5608
|
+
if (!session) {
|
|
5609
|
+
throw new Error(`Session not found: ${params.sessionId}`);
|
|
5610
|
+
}
|
|
5611
|
+
return await session._handleSystemMessageTransform(params.sections);
|
|
5612
|
+
}
|
|
4944
5613
|
// ========================================================================
|
|
4945
5614
|
// Protocol v2 backward-compatibility adapters
|
|
4946
5615
|
// ========================================================================
|
|
@@ -4969,11 +5638,15 @@ stderr: ${stderrOutput}`
|
|
|
4969
5638
|
};
|
|
4970
5639
|
}
|
|
4971
5640
|
try {
|
|
5641
|
+
const traceparent = params.traceparent;
|
|
5642
|
+
const tracestate = params.tracestate;
|
|
4972
5643
|
const invocation = {
|
|
4973
5644
|
sessionId: params.sessionId,
|
|
4974
5645
|
toolCallId: params.toolCallId,
|
|
4975
5646
|
toolName: params.toolName,
|
|
4976
|
-
arguments: params.arguments
|
|
5647
|
+
arguments: params.arguments,
|
|
5648
|
+
traceparent,
|
|
5649
|
+
tracestate
|
|
4977
5650
|
};
|
|
4978
5651
|
const result = await handler(params.arguments, invocation);
|
|
4979
5652
|
return { result: this.normalizeToolResultV2(result) };
|
|
@@ -5003,7 +5676,10 @@ stderr: ${stderrOutput}`
|
|
|
5003
5676
|
try {
|
|
5004
5677
|
const result = await session._handlePermissionRequestV2(params.permissionRequest);
|
|
5005
5678
|
return { result };
|
|
5006
|
-
} catch (
|
|
5679
|
+
} catch (error) {
|
|
5680
|
+
if (error instanceof Error && error.message === NO_RESULT_PERMISSION_V2_ERROR) {
|
|
5681
|
+
throw error;
|
|
5682
|
+
}
|
|
5007
5683
|
return {
|
|
5008
5684
|
result: {
|
|
5009
5685
|
kind: "denied-no-approval-rule-and-could-not-request-from-user"
|
|
@@ -5033,17 +5709,6 @@ stderr: ${stderrOutput}`
|
|
|
5033
5709
|
isToolResultObject(value) {
|
|
5034
5710
|
return typeof value === "object" && value !== null && "textResultForLlm" in value && typeof value.textResultForLlm === "string" && "resultType" in value;
|
|
5035
5711
|
}
|
|
5036
|
-
/**
|
|
5037
|
-
* Attempt to reconnect to the server
|
|
5038
|
-
*/
|
|
5039
|
-
async reconnect() {
|
|
5040
|
-
this.state = "disconnected";
|
|
5041
|
-
try {
|
|
5042
|
-
await this.stop();
|
|
5043
|
-
await this.start();
|
|
5044
|
-
} catch (_error) {
|
|
5045
|
-
}
|
|
5046
|
-
}
|
|
5047
5712
|
};
|
|
5048
5713
|
}
|
|
5049
5714
|
});
|
|
@@ -5052,10 +5717,24 @@ stderr: ${stderrOutput}`
|
|
|
5052
5717
|
function defineTool(name, config) {
|
|
5053
5718
|
return { name, ...config };
|
|
5054
5719
|
}
|
|
5055
|
-
var approveAll;
|
|
5720
|
+
var SYSTEM_PROMPT_SECTIONS, approveAll;
|
|
5056
5721
|
var init_types = __esm({
|
|
5057
5722
|
"node_modules/@github/copilot-sdk/dist/types.js"() {
|
|
5058
5723
|
"use strict";
|
|
5724
|
+
SYSTEM_PROMPT_SECTIONS = {
|
|
5725
|
+
identity: { description: "Agent identity preamble and mode statement" },
|
|
5726
|
+
tone: { description: "Response style, conciseness rules, output formatting preferences" },
|
|
5727
|
+
tool_efficiency: { description: "Tool usage patterns, parallel calling, batching guidelines" },
|
|
5728
|
+
environment_context: { description: "CWD, OS, git root, directory listing, available tools" },
|
|
5729
|
+
code_change_rules: { description: "Coding rules, linting/testing, ecosystem tools, style" },
|
|
5730
|
+
guidelines: { description: "Tips, behavioral best practices, behavioral guidelines" },
|
|
5731
|
+
safety: { description: "Environment limitations, prohibited actions, security policies" },
|
|
5732
|
+
tool_instructions: { description: "Per-tool usage instructions" },
|
|
5733
|
+
custom_instructions: { description: "Repository and organization custom instructions" },
|
|
5734
|
+
last_instructions: {
|
|
5735
|
+
description: "End-of-prompt instructions: parallel tool calling, persistence, task completion"
|
|
5736
|
+
}
|
|
5737
|
+
};
|
|
5059
5738
|
approveAll = () => ({ kind: "approved" });
|
|
5060
5739
|
}
|
|
5061
5740
|
});
|
|
@@ -5065,6 +5744,7 @@ var dist_exports = {};
|
|
|
5065
5744
|
__export(dist_exports, {
|
|
5066
5745
|
CopilotClient: () => CopilotClient,
|
|
5067
5746
|
CopilotSession: () => CopilotSession,
|
|
5747
|
+
SYSTEM_PROMPT_SECTIONS: () => SYSTEM_PROMPT_SECTIONS,
|
|
5068
5748
|
approveAll: () => approveAll,
|
|
5069
5749
|
defineTool: () => defineTool
|
|
5070
5750
|
});
|
|
@@ -5078,7 +5758,7 @@ var init_dist = __esm({
|
|
|
5078
5758
|
});
|
|
5079
5759
|
|
|
5080
5760
|
// src/cli.ts
|
|
5081
|
-
import { createRequire } from "module";
|
|
5761
|
+
import { createRequire as createRequire2 } from "module";
|
|
5082
5762
|
|
|
5083
5763
|
// packages/core/src/config.ts
|
|
5084
5764
|
var DEFAULT_MODEL = "claude-sonnet-4.6";
|
|
@@ -5334,6 +6014,18 @@ async function fileExists(filePath) {
|
|
|
5334
6014
|
return false;
|
|
5335
6015
|
}
|
|
5336
6016
|
}
|
|
6017
|
+
async function canSafeWrite(filePath, force) {
|
|
6018
|
+
const resolved = path.resolve(filePath);
|
|
6019
|
+
if (await hasSymlinkAncestor(resolved)) return false;
|
|
6020
|
+
try {
|
|
6021
|
+
const stat = await fs.lstat(resolved);
|
|
6022
|
+
if (stat.isSymbolicLink()) return false;
|
|
6023
|
+
return force;
|
|
6024
|
+
} catch (error) {
|
|
6025
|
+
if (error.code === "ENOENT") return true;
|
|
6026
|
+
throw error;
|
|
6027
|
+
}
|
|
6028
|
+
}
|
|
5337
6029
|
async function safeReadDir(dirPath) {
|
|
5338
6030
|
try {
|
|
5339
6031
|
return await fs.readdir(dirPath);
|
|
@@ -5341,10 +6033,68 @@ async function safeReadDir(dirPath) {
|
|
|
5341
6033
|
return [];
|
|
5342
6034
|
}
|
|
5343
6035
|
}
|
|
6036
|
+
function stripJsonComments(text) {
|
|
6037
|
+
let result = "";
|
|
6038
|
+
let i = 0;
|
|
6039
|
+
while (i < text.length) {
|
|
6040
|
+
if (text[i] === '"') {
|
|
6041
|
+
let j = i + 1;
|
|
6042
|
+
while (j < text.length) {
|
|
6043
|
+
if (text[j] === "\\") {
|
|
6044
|
+
j += 2;
|
|
6045
|
+
continue;
|
|
6046
|
+
}
|
|
6047
|
+
if (text[j] === '"') {
|
|
6048
|
+
j++;
|
|
6049
|
+
break;
|
|
6050
|
+
}
|
|
6051
|
+
j++;
|
|
6052
|
+
}
|
|
6053
|
+
result += text.slice(i, j);
|
|
6054
|
+
i = j;
|
|
6055
|
+
continue;
|
|
6056
|
+
}
|
|
6057
|
+
if (text[i] === "/" && text[i + 1] === "/") {
|
|
6058
|
+
i += 2;
|
|
6059
|
+
while (i < text.length && text[i] !== "\n") i++;
|
|
6060
|
+
continue;
|
|
6061
|
+
}
|
|
6062
|
+
if (text[i] === "/" && text[i + 1] === "*") {
|
|
6063
|
+
i += 2;
|
|
6064
|
+
while (i < text.length && !(text[i] === "*" && text[i + 1] === "/")) i++;
|
|
6065
|
+
if (i < text.length) i += 2;
|
|
6066
|
+
continue;
|
|
6067
|
+
}
|
|
6068
|
+
if (text[i] === ",") {
|
|
6069
|
+
let j = i + 1;
|
|
6070
|
+
while (j < text.length) {
|
|
6071
|
+
if (text[j] === " " || text[j] === " " || text[j] === "\n" || text[j] === "\r") {
|
|
6072
|
+
j++;
|
|
6073
|
+
} else if (text[j] === "/" && text[j + 1] === "/") {
|
|
6074
|
+
j += 2;
|
|
6075
|
+
while (j < text.length && text[j] !== "\n") j++;
|
|
6076
|
+
} else if (text[j] === "/" && text[j + 1] === "*") {
|
|
6077
|
+
j += 2;
|
|
6078
|
+
while (j < text.length && !(text[j] === "*" && text[j + 1] === "/")) j++;
|
|
6079
|
+
if (j < text.length) j += 2;
|
|
6080
|
+
} else {
|
|
6081
|
+
break;
|
|
6082
|
+
}
|
|
6083
|
+
}
|
|
6084
|
+
if (j < text.length && (text[j] === "}" || text[j] === "]")) {
|
|
6085
|
+
i++;
|
|
6086
|
+
continue;
|
|
6087
|
+
}
|
|
6088
|
+
}
|
|
6089
|
+
result += text[i];
|
|
6090
|
+
i++;
|
|
6091
|
+
}
|
|
6092
|
+
return result;
|
|
6093
|
+
}
|
|
5344
6094
|
async function readJson(filePath) {
|
|
5345
6095
|
try {
|
|
5346
6096
|
const raw = await fs.readFile(filePath, "utf8");
|
|
5347
|
-
return JSON.parse(raw);
|
|
6097
|
+
return JSON.parse(stripJsonComments(raw));
|
|
5348
6098
|
} catch {
|
|
5349
6099
|
return void 0;
|
|
5350
6100
|
}
|
|
@@ -6674,7 +7424,7 @@ async function checkReposForInstructions(token, repos, onProgress) {
|
|
|
6674
7424
|
}
|
|
6675
7425
|
|
|
6676
7426
|
// packages/core/src/services/batch.ts
|
|
6677
|
-
import
|
|
7427
|
+
import path13 from "path";
|
|
6678
7428
|
|
|
6679
7429
|
// packages/core/src/utils/pr.ts
|
|
6680
7430
|
function buildInstructionsPrBody() {
|
|
@@ -7001,8 +7751,32 @@ async function assertCopilotCliReady() {
|
|
|
7001
7751
|
async function listCopilotModels() {
|
|
7002
7752
|
const config = await assertCopilotCliReady();
|
|
7003
7753
|
const [cmd, args2] = buildExecArgs(config, ["--help"]);
|
|
7004
|
-
|
|
7005
|
-
|
|
7754
|
+
let stdout = "";
|
|
7755
|
+
let stderr = "";
|
|
7756
|
+
let execError = null;
|
|
7757
|
+
try {
|
|
7758
|
+
const result = await execFileAsync2(cmd, args2, { timeout: 5e3 });
|
|
7759
|
+
stdout = result.stdout;
|
|
7760
|
+
stderr = result.stderr;
|
|
7761
|
+
} catch (err) {
|
|
7762
|
+
execError = err;
|
|
7763
|
+
const e = err;
|
|
7764
|
+
stdout = e.stdout ?? "";
|
|
7765
|
+
stderr = e.stderr ?? "";
|
|
7766
|
+
}
|
|
7767
|
+
const fromStdout = extractModelChoices(stdout);
|
|
7768
|
+
if (fromStdout.length > 0) return fromStdout;
|
|
7769
|
+
const fromStderr = extractModelChoices(stderr);
|
|
7770
|
+
if (fromStderr.length > 0) return fromStderr;
|
|
7771
|
+
if (execError) {
|
|
7772
|
+
const e = execError;
|
|
7773
|
+
const details = e.stderr || e.stdout;
|
|
7774
|
+
const detailMsg = details ? `
|
|
7775
|
+
Copilot CLI output:
|
|
7776
|
+
${details}` : "";
|
|
7777
|
+
throw new Error(`Failed to list Copilot models: ${e.message}${detailMsg}`);
|
|
7778
|
+
}
|
|
7779
|
+
return [];
|
|
7006
7780
|
}
|
|
7007
7781
|
function buildExecArgs(config, extraArgs) {
|
|
7008
7782
|
if (config.cliArgs && config.cliArgs.length > 0) {
|
|
@@ -8036,13 +8810,218 @@ async function generateNestedAreaInstructions(options) {
|
|
|
8036
8810
|
});
|
|
8037
8811
|
}
|
|
8038
8812
|
|
|
8039
|
-
// packages/core/src/services/readiness.ts
|
|
8040
|
-
import
|
|
8041
|
-
import path9 from "path";
|
|
8813
|
+
// packages/core/src/services/readiness/index.ts
|
|
8814
|
+
import path12 from "path";
|
|
8042
8815
|
|
|
8043
8816
|
// packages/core/src/services/policy.ts
|
|
8044
8817
|
import fs6 from "fs/promises";
|
|
8045
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
|
|
8046
9025
|
var DEFAULT_PASS_RATE = 0.8;
|
|
8047
9026
|
function validatePolicyConfig(obj, source, format = "module") {
|
|
8048
9027
|
if (typeof obj !== "object" || obj === null) {
|
|
@@ -8133,6 +9112,16 @@ function parsePolicySources(raw) {
|
|
|
8133
9112
|
const sources = raw.split(",").map((s) => s.trim()).filter(Boolean);
|
|
8134
9113
|
return sources.length ? sources : void 0;
|
|
8135
9114
|
}
|
|
9115
|
+
function normalizeNativePlugin(plugin) {
|
|
9116
|
+
return {
|
|
9117
|
+
...plugin,
|
|
9118
|
+
meta: {
|
|
9119
|
+
...plugin.meta,
|
|
9120
|
+
sourceType: "module",
|
|
9121
|
+
trust: "trusted-code"
|
|
9122
|
+
}
|
|
9123
|
+
};
|
|
9124
|
+
}
|
|
8136
9125
|
async function loadPolicy(source, options) {
|
|
8137
9126
|
const jsonOnly = options?.jsonOnly ?? false;
|
|
8138
9127
|
if (source.startsWith(".") || path8.isAbsolute(source)) {
|
|
@@ -8151,8 +9140,12 @@ async function loadPolicy(source, options) {
|
|
|
8151
9140
|
);
|
|
8152
9141
|
}
|
|
8153
9142
|
try {
|
|
8154
|
-
const mod = await import(resolved);
|
|
9143
|
+
const mod = await import(pathToFileURL(resolved).href);
|
|
8155
9144
|
const config = mod.default ?? mod;
|
|
9145
|
+
if (isNativePlugin(config)) {
|
|
9146
|
+
validateNativePlugin(config, source);
|
|
9147
|
+
return normalizeNativePlugin(config);
|
|
9148
|
+
}
|
|
8156
9149
|
return validatePolicyConfig(config, source);
|
|
8157
9150
|
} catch (err) {
|
|
8158
9151
|
if (err instanceof Error && (err.message.includes("Cannot find module") || err.message.includes("MODULE_NOT_FOUND"))) {
|
|
@@ -8163,7 +9156,7 @@ async function loadPolicy(source, options) {
|
|
|
8163
9156
|
}
|
|
8164
9157
|
try {
|
|
8165
9158
|
const raw = await fs6.readFile(resolved, "utf8");
|
|
8166
|
-
const data = JSON.parse(raw);
|
|
9159
|
+
const data = JSON.parse(stripJsonComments(raw));
|
|
8167
9160
|
return validatePolicyConfig(data, source, "json");
|
|
8168
9161
|
} catch {
|
|
8169
9162
|
throw new Error(
|
|
@@ -8179,6 +9172,10 @@ async function loadPolicy(source, options) {
|
|
|
8179
9172
|
try {
|
|
8180
9173
|
const mod = await import(source);
|
|
8181
9174
|
const config = mod.default ?? mod;
|
|
9175
|
+
if (isNativePlugin(config)) {
|
|
9176
|
+
validateNativePlugin(config, source);
|
|
9177
|
+
return normalizeNativePlugin(config);
|
|
9178
|
+
}
|
|
8182
9179
|
return validatePolicyConfig(config, source);
|
|
8183
9180
|
} catch (err) {
|
|
8184
9181
|
const message = err instanceof Error ? err.message : typeof err === "object" && err !== null && "message" in err ? String(err.message) : String(err);
|
|
@@ -8242,148 +9239,24 @@ function resolveChain(baseCriteria, baseExtras, policies) {
|
|
|
8242
9239
|
return { chain, criteria, extras, thresholds: { passRate } };
|
|
8243
9240
|
}
|
|
8244
9241
|
|
|
8245
|
-
// packages/core/src/services/policy/
|
|
8246
|
-
|
|
8247
|
-
|
|
8248
|
-
|
|
8249
|
-
|
|
8250
|
-
|
|
8251
|
-
|
|
8252
|
-
|
|
8253
|
-
|
|
8254
|
-
|
|
8255
|
-
|
|
8256
|
-
|
|
8257
|
-
|
|
8258
|
-
|
|
8259
|
-
|
|
8260
|
-
|
|
8261
|
-
|
|
8262
|
-
}
|
|
8263
|
-
function scoreToGrade(score) {
|
|
8264
|
-
if (score >= 0.9) return "A";
|
|
8265
|
-
if (score >= 0.8) return "B";
|
|
8266
|
-
if (score >= 0.7) return "C";
|
|
8267
|
-
if (score >= 0.6) return "D";
|
|
8268
|
-
return "F";
|
|
8269
|
-
}
|
|
8270
|
-
function applySignalPatch(signals, patch, pluginName) {
|
|
8271
|
-
let result = [...signals];
|
|
8272
|
-
if (patch.remove?.length) {
|
|
8273
|
-
const removeSet = new Set(patch.remove);
|
|
8274
|
-
result = result.filter((s) => !removeSet.has(s.id));
|
|
8275
|
-
}
|
|
8276
|
-
if (patch.modify?.length) {
|
|
8277
|
-
for (const mod of patch.modify) {
|
|
8278
|
-
const idx = result.findIndex((s) => s.id === mod.id);
|
|
8279
|
-
if (idx >= 0) {
|
|
8280
|
-
const existing = result[idx];
|
|
8281
|
-
const changes = { ...mod.changes };
|
|
8282
|
-
if (changes.metadata && existing.metadata) {
|
|
8283
|
-
changes.metadata = { ...existing.metadata, ...changes.metadata };
|
|
8284
|
-
}
|
|
8285
|
-
result[idx] = {
|
|
8286
|
-
...existing,
|
|
8287
|
-
...changes,
|
|
8288
|
-
origin: {
|
|
8289
|
-
...existing.origin,
|
|
8290
|
-
modifiedBy: [...existing.origin.modifiedBy ?? [], pluginName]
|
|
8291
|
-
}
|
|
8292
|
-
};
|
|
8293
|
-
}
|
|
8294
|
-
}
|
|
8295
|
-
}
|
|
8296
|
-
if (patch.add?.length) {
|
|
8297
|
-
result.push(
|
|
8298
|
-
...patch.add.map((s) => ({
|
|
8299
|
-
...s,
|
|
8300
|
-
evidence: s.evidence ? [...s.evidence] : void 0,
|
|
8301
|
-
metadata: s.metadata ? { ...s.metadata } : void 0
|
|
8302
|
-
}))
|
|
8303
|
-
);
|
|
8304
|
-
}
|
|
8305
|
-
return result;
|
|
8306
|
-
}
|
|
8307
|
-
function applyRecommendationPatch(recommendations, patch, pluginName) {
|
|
8308
|
-
let result = [...recommendations];
|
|
8309
|
-
if (patch.remove?.length) {
|
|
8310
|
-
const removeSet = new Set(patch.remove);
|
|
8311
|
-
result = result.filter((r) => !removeSet.has(r.id));
|
|
8312
|
-
}
|
|
8313
|
-
if (patch.modify?.length) {
|
|
8314
|
-
for (const mod of patch.modify) {
|
|
8315
|
-
const idx = result.findIndex((r) => r.id === mod.id);
|
|
8316
|
-
if (idx >= 0) {
|
|
8317
|
-
const existing = result[idx];
|
|
8318
|
-
result[idx] = {
|
|
8319
|
-
...existing,
|
|
8320
|
-
...mod.changes,
|
|
8321
|
-
origin: {
|
|
8322
|
-
...existing.origin,
|
|
8323
|
-
modifiedBy: [...existing.origin.modifiedBy ?? [], pluginName]
|
|
8324
|
-
}
|
|
8325
|
-
};
|
|
8326
|
-
}
|
|
8327
|
-
}
|
|
8328
|
-
}
|
|
8329
|
-
if (patch.add?.length) {
|
|
8330
|
-
result.push(
|
|
8331
|
-
...patch.add.map((r) => ({
|
|
8332
|
-
...r,
|
|
8333
|
-
supersedes: r.supersedes ? [...r.supersedes] : void 0,
|
|
8334
|
-
metadata: r.metadata ? { ...r.metadata } : void 0
|
|
8335
|
-
}))
|
|
8336
|
-
);
|
|
8337
|
-
}
|
|
8338
|
-
return result;
|
|
8339
|
-
}
|
|
8340
|
-
function resolveSupersedes(recommendations) {
|
|
8341
|
-
const supersededIds = /* @__PURE__ */ new Set();
|
|
8342
|
-
const recIds = new Set(recommendations.map((r) => r.id));
|
|
8343
|
-
for (const rec of recommendations) {
|
|
8344
|
-
if (rec.supersedes?.length) {
|
|
8345
|
-
for (const id of rec.supersedes) {
|
|
8346
|
-
if (recIds.has(id)) {
|
|
8347
|
-
supersededIds.add(id);
|
|
8348
|
-
}
|
|
8349
|
-
}
|
|
8350
|
-
}
|
|
8351
|
-
}
|
|
8352
|
-
return recommendations.filter((r) => !supersededIds.has(r.id)).map((r) => {
|
|
8353
|
-
if (!r.supersedes?.length) return r;
|
|
8354
|
-
const actuallySuperseded = r.supersedes.filter((id) => supersededIds.has(id));
|
|
8355
|
-
if (actuallySuperseded.length === 0) return r;
|
|
8356
|
-
return {
|
|
8357
|
-
...r,
|
|
8358
|
-
origin: {
|
|
8359
|
-
...r.origin,
|
|
8360
|
-
modifiedBy: [
|
|
8361
|
-
...r.origin.modifiedBy ?? [],
|
|
8362
|
-
...actuallySuperseded.map((id) => `superseded:${id}`)
|
|
8363
|
-
]
|
|
8364
|
-
}
|
|
8365
|
-
};
|
|
8366
|
-
});
|
|
8367
|
-
}
|
|
8368
|
-
|
|
8369
|
-
// packages/core/src/services/policy/engine.ts
|
|
8370
|
-
async function executePlugins(plugins, ctx, options) {
|
|
8371
|
-
const warnings = [];
|
|
8372
|
-
const disabledIds = options?.disabledRuleIds ?? /* @__PURE__ */ new Set();
|
|
8373
|
-
let signals = [];
|
|
8374
|
-
for (const plugin of plugins) {
|
|
8375
|
-
if (!plugin.detectors?.length) continue;
|
|
8376
|
-
for (const detector of plugin.detectors) {
|
|
8377
|
-
if (disabledIds.has(detector.id)) continue;
|
|
8378
|
-
try {
|
|
8379
|
-
const result = await detector.detect(ctx);
|
|
8380
|
-
const emitted = Array.isArray(result) ? result : [result];
|
|
8381
|
-
signals.push(...emitted);
|
|
8382
|
-
} catch (err) {
|
|
8383
|
-
const cont = handleError(plugin, err, "detect", ctx, warnings);
|
|
8384
|
-
if (!cont) break;
|
|
8385
|
-
}
|
|
8386
|
-
}
|
|
9242
|
+
// packages/core/src/services/policy/engine.ts
|
|
9243
|
+
async function executePlugins(plugins, ctx, options) {
|
|
9244
|
+
const warnings = [];
|
|
9245
|
+
const disabledIds = options?.disabledRuleIds ?? /* @__PURE__ */ new Set();
|
|
9246
|
+
let signals = [];
|
|
9247
|
+
for (const plugin of plugins) {
|
|
9248
|
+
if (!plugin.detectors?.length) continue;
|
|
9249
|
+
for (const detector of plugin.detectors) {
|
|
9250
|
+
if (disabledIds.has(detector.id)) continue;
|
|
9251
|
+
try {
|
|
9252
|
+
const result = await detector.detect(ctx);
|
|
9253
|
+
const emitted = Array.isArray(result) ? result : [result];
|
|
9254
|
+
signals.push(...emitted);
|
|
9255
|
+
} catch (err) {
|
|
9256
|
+
const cont = handleError(plugin, err, "detect", ctx, warnings);
|
|
9257
|
+
if (!cont) break;
|
|
9258
|
+
}
|
|
9259
|
+
}
|
|
8387
9260
|
}
|
|
8388
9261
|
for (const plugin of plugins) {
|
|
8389
9262
|
if (!plugin.afterDetect) continue;
|
|
@@ -8671,9 +9544,21 @@ async function loadPluginChain(policySources, options) {
|
|
|
8671
9544
|
const allDisabledIds = [];
|
|
8672
9545
|
let passRateThreshold = 0.8;
|
|
8673
9546
|
for (const source of policySources) {
|
|
8674
|
-
const
|
|
9547
|
+
const loaded = await loadPolicy(source, {
|
|
8675
9548
|
jsonOnly: options?.jsonOnly
|
|
8676
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;
|
|
8677
9562
|
if (isImperativePlugin(policyConfig)) {
|
|
8678
9563
|
const { plugin: imperativePlugin, compiled } = wrapImperativePolicy(
|
|
8679
9564
|
policyConfig,
|
|
@@ -8719,252 +9604,382 @@ function wrapImperativePolicy(config, baseCriteria) {
|
|
|
8719
9604
|
return { plugin, compiled };
|
|
8720
9605
|
}
|
|
8721
9606
|
|
|
8722
|
-
// packages/core/src/services/readiness.ts
|
|
8723
|
-
|
|
8724
|
-
|
|
8725
|
-
|
|
8726
|
-
|
|
8727
|
-
documentation: "repo-health",
|
|
8728
|
-
"dev-environment": "repo-health",
|
|
8729
|
-
"code-quality": "repo-health",
|
|
8730
|
-
observability: "repo-health",
|
|
8731
|
-
"security-governance": "repo-health",
|
|
8732
|
-
"ai-tooling": "ai-setup"
|
|
8733
|
-
};
|
|
8734
|
-
var PILLAR_GROUP_NAMES = {
|
|
8735
|
-
"repo-health": "Repo Health",
|
|
8736
|
-
"ai-setup": "AI Setup"
|
|
8737
|
-
};
|
|
8738
|
-
function groupPillars(pillars) {
|
|
8739
|
-
const groups = ["repo-health", "ai-setup"];
|
|
8740
|
-
return groups.map((group) => ({
|
|
8741
|
-
group,
|
|
8742
|
-
label: PILLAR_GROUP_NAMES[group],
|
|
8743
|
-
pillars: pillars.filter((p) => PILLAR_GROUPS[p.id] === group)
|
|
8744
|
-
}));
|
|
9607
|
+
// packages/core/src/services/readiness/checkers.ts
|
|
9608
|
+
import fs7 from "fs/promises";
|
|
9609
|
+
import path9 from "path";
|
|
9610
|
+
function hasAnyFile(files, candidates) {
|
|
9611
|
+
return candidates.some((candidate) => files.includes(candidate));
|
|
8745
9612
|
}
|
|
8746
|
-
function
|
|
8747
|
-
const
|
|
8748
|
-
|
|
8749
|
-
|
|
8750
|
-
|
|
8751
|
-
4: "Optimized",
|
|
8752
|
-
5: "Autonomous"
|
|
8753
|
-
};
|
|
8754
|
-
return names[level] || "Unknown";
|
|
9613
|
+
async function hasReadme(repoPath) {
|
|
9614
|
+
const files = await safeReadDir(repoPath);
|
|
9615
|
+
return files.some(
|
|
9616
|
+
(file) => file.toLowerCase() === "readme.md" || file.toLowerCase() === "readme"
|
|
9617
|
+
);
|
|
8755
9618
|
}
|
|
8756
|
-
function
|
|
8757
|
-
|
|
8758
|
-
|
|
8759
|
-
|
|
8760
|
-
|
|
8761
|
-
|
|
8762
|
-
|
|
8763
|
-
|
|
8764
|
-
|
|
9619
|
+
async function hasLintConfig(repoPath) {
|
|
9620
|
+
return hasAnyFile(await safeReadDir(repoPath), [
|
|
9621
|
+
"eslint.config.js",
|
|
9622
|
+
"eslint.config.mjs",
|
|
9623
|
+
".eslintrc",
|
|
9624
|
+
".eslintrc.js",
|
|
9625
|
+
".eslintrc.cjs",
|
|
9626
|
+
".eslintrc.json",
|
|
9627
|
+
".eslintrc.yml",
|
|
9628
|
+
".eslintrc.yaml",
|
|
9629
|
+
"biome.json",
|
|
9630
|
+
"biome.jsonc",
|
|
9631
|
+
".prettierrc",
|
|
9632
|
+
".prettierrc.json",
|
|
9633
|
+
".prettierrc.js",
|
|
9634
|
+
".prettierrc.cjs",
|
|
9635
|
+
"prettier.config.js",
|
|
9636
|
+
"prettier.config.cjs"
|
|
9637
|
+
]);
|
|
8765
9638
|
}
|
|
8766
|
-
async function
|
|
8767
|
-
|
|
8768
|
-
|
|
8769
|
-
|
|
8770
|
-
|
|
8771
|
-
|
|
8772
|
-
|
|
8773
|
-
|
|
8774
|
-
|
|
8775
|
-
|
|
8776
|
-
|
|
8777
|
-
|
|
8778
|
-
|
|
8779
|
-
|
|
8780
|
-
|
|
8781
|
-
|
|
8782
|
-
|
|
8783
|
-
|
|
8784
|
-
|
|
8785
|
-
|
|
8786
|
-
|
|
9639
|
+
async function hasFormatterConfig(repoPath) {
|
|
9640
|
+
return hasAnyFile(await safeReadDir(repoPath), [
|
|
9641
|
+
"biome.json",
|
|
9642
|
+
"biome.jsonc",
|
|
9643
|
+
".prettierrc",
|
|
9644
|
+
".prettierrc.json",
|
|
9645
|
+
".prettierrc.js",
|
|
9646
|
+
".prettierrc.cjs",
|
|
9647
|
+
"prettier.config.js",
|
|
9648
|
+
"prettier.config.cjs"
|
|
9649
|
+
]);
|
|
9650
|
+
}
|
|
9651
|
+
async function hasTypecheckConfig(repoPath) {
|
|
9652
|
+
return hasAnyFile(await safeReadDir(repoPath), [
|
|
9653
|
+
"tsconfig.json",
|
|
9654
|
+
"tsconfig.base.json",
|
|
9655
|
+
"pyproject.toml",
|
|
9656
|
+
"mypy.ini"
|
|
9657
|
+
]);
|
|
9658
|
+
}
|
|
9659
|
+
async function hasGithubWorkflows(repoPath) {
|
|
9660
|
+
return fileExists(path9.join(repoPath, ".github", "workflows"));
|
|
9661
|
+
}
|
|
9662
|
+
async function hasCodeowners(repoPath) {
|
|
9663
|
+
const root = await fileExists(path9.join(repoPath, "CODEOWNERS"));
|
|
9664
|
+
const github = await fileExists(path9.join(repoPath, ".github", "CODEOWNERS"));
|
|
9665
|
+
return root || github;
|
|
9666
|
+
}
|
|
9667
|
+
async function hasLicense(repoPath) {
|
|
9668
|
+
const files = await safeReadDir(repoPath);
|
|
9669
|
+
return files.some((file) => file.toLowerCase().startsWith("license"));
|
|
9670
|
+
}
|
|
9671
|
+
async function hasPullRequestTemplate(repoPath) {
|
|
9672
|
+
const direct = await fileExists(path9.join(repoPath, ".github", "PULL_REQUEST_TEMPLATE.md"));
|
|
9673
|
+
if (direct) return true;
|
|
9674
|
+
const dir = path9.join(repoPath, ".github", "PULL_REQUEST_TEMPLATE");
|
|
9675
|
+
try {
|
|
9676
|
+
const entries = await fs7.readdir(dir);
|
|
9677
|
+
return entries.some((entry) => entry.toLowerCase().endsWith(".md"));
|
|
9678
|
+
} catch {
|
|
9679
|
+
return false;
|
|
8787
9680
|
}
|
|
8788
|
-
|
|
8789
|
-
|
|
8790
|
-
|
|
8791
|
-
|
|
8792
|
-
|
|
8793
|
-
|
|
8794
|
-
|
|
8795
|
-
|
|
8796
|
-
|
|
8797
|
-
|
|
9681
|
+
}
|
|
9682
|
+
async function hasPrecommitConfig(repoPath) {
|
|
9683
|
+
const precommit = await fileExists(path9.join(repoPath, ".pre-commit-config.yaml"));
|
|
9684
|
+
if (precommit) return true;
|
|
9685
|
+
return fileExists(path9.join(repoPath, ".husky"));
|
|
9686
|
+
}
|
|
9687
|
+
async function hasArchitectureDoc(repoPath) {
|
|
9688
|
+
const files = await safeReadDir(repoPath);
|
|
9689
|
+
if (files.some((file) => file.toLowerCase() === "architecture.md")) return true;
|
|
9690
|
+
return fileExists(path9.join(repoPath, "docs", "architecture.md"));
|
|
9691
|
+
}
|
|
9692
|
+
function validateAndNormalize(raw) {
|
|
9693
|
+
const trimmed = raw.trim();
|
|
9694
|
+
if (!trimmed || path9.isAbsolute(trimmed)) return void 0;
|
|
9695
|
+
const segments = trimmed.split(/[/\\]+/u);
|
|
9696
|
+
if (segments.some((s) => s === "..")) return void 0;
|
|
9697
|
+
let normalized = path9.normalize(trimmed).replace(/\\/gu, "/");
|
|
9698
|
+
normalized = normalized.replace(/\/+$/u, "");
|
|
9699
|
+
if (!normalized || normalized === ".") return void 0;
|
|
9700
|
+
return normalized;
|
|
9701
|
+
}
|
|
9702
|
+
function extractLocationPaths(entries) {
|
|
9703
|
+
if (!entries || typeof entries !== "object") return [];
|
|
9704
|
+
const paths = [];
|
|
9705
|
+
if (Array.isArray(entries)) {
|
|
9706
|
+
for (const entry of entries) {
|
|
9707
|
+
let raw;
|
|
9708
|
+
if (typeof entry === "string") {
|
|
9709
|
+
raw = entry;
|
|
9710
|
+
} else if (entry && typeof entry === "object" && !Array.isArray(entry)) {
|
|
9711
|
+
const obj = entry;
|
|
9712
|
+
if (typeof obj.path === "string") {
|
|
9713
|
+
raw = obj.path;
|
|
9714
|
+
}
|
|
9715
|
+
}
|
|
9716
|
+
if (raw) {
|
|
9717
|
+
const normalized = validateAndNormalize(raw);
|
|
9718
|
+
if (normalized) paths.push(normalized);
|
|
9719
|
+
}
|
|
8798
9720
|
}
|
|
8799
|
-
|
|
8800
|
-
resolvedCriteria = resolved.criteria;
|
|
8801
|
-
resolvedExtras = resolved.extras;
|
|
8802
|
-
passRateThreshold = resolved.thresholds.passRate;
|
|
8803
|
-
policyInfo = { chain: resolved.chain, criteriaCount: resolved.criteria.length };
|
|
8804
|
-
} else {
|
|
8805
|
-
resolvedCriteria = baseCriteria;
|
|
8806
|
-
resolvedExtras = baseExtras;
|
|
9721
|
+
return paths;
|
|
8807
9722
|
}
|
|
8808
|
-
const
|
|
8809
|
-
|
|
8810
|
-
|
|
8811
|
-
|
|
8812
|
-
|
|
8813
|
-
|
|
8814
|
-
|
|
8815
|
-
|
|
8816
|
-
|
|
8817
|
-
|
|
8818
|
-
|
|
8819
|
-
|
|
8820
|
-
|
|
8821
|
-
|
|
8822
|
-
|
|
8823
|
-
|
|
8824
|
-
|
|
9723
|
+
for (const [key, value] of Object.entries(entries)) {
|
|
9724
|
+
if (value !== true) continue;
|
|
9725
|
+
const normalized = validateAndNormalize(key);
|
|
9726
|
+
if (normalized) paths.push(normalized);
|
|
9727
|
+
}
|
|
9728
|
+
return paths;
|
|
9729
|
+
}
|
|
9730
|
+
function extractLocationsFromSettings(settings) {
|
|
9731
|
+
return {
|
|
9732
|
+
instructionsLocations: extractLocationPaths(settings["chat.instructionsFilesLocations"]),
|
|
9733
|
+
agentLocations: extractLocationPaths(settings["chat.agentFilesLocations"]),
|
|
9734
|
+
skillsLocations: extractLocationPaths(settings["chat.agentSkillsLocations"])
|
|
9735
|
+
};
|
|
9736
|
+
}
|
|
9737
|
+
function mergeLocations(a, b) {
|
|
9738
|
+
return {
|
|
9739
|
+
instructionsLocations: [...a.instructionsLocations, ...b.instructionsLocations],
|
|
9740
|
+
agentLocations: [...a.agentLocations, ...b.agentLocations],
|
|
9741
|
+
skillsLocations: [...a.skillsLocations, ...b.skillsLocations]
|
|
9742
|
+
};
|
|
9743
|
+
}
|
|
9744
|
+
async function parseVscodeLocations(repoPath, rootFiles) {
|
|
9745
|
+
const empty = {
|
|
9746
|
+
instructionsLocations: [],
|
|
9747
|
+
agentLocations: [],
|
|
9748
|
+
skillsLocations: []
|
|
9749
|
+
};
|
|
9750
|
+
let result = { ...empty };
|
|
9751
|
+
const settings = await readJson(path9.join(repoPath, ".vscode", "settings.json"));
|
|
9752
|
+
if (settings) {
|
|
9753
|
+
result = mergeLocations(result, extractLocationsFromSettings(settings));
|
|
9754
|
+
}
|
|
9755
|
+
const workspaceFiles = rootFiles.filter((f) => f.endsWith(".code-workspace"));
|
|
9756
|
+
for (const wsFile of workspaceFiles) {
|
|
9757
|
+
const ws = await readJson(path9.join(repoPath, wsFile));
|
|
9758
|
+
if (ws?.settings && typeof ws.settings === "object" && !Array.isArray(ws.settings)) {
|
|
9759
|
+
result = mergeLocations(
|
|
9760
|
+
result,
|
|
9761
|
+
extractLocationsFromSettings(ws.settings)
|
|
9762
|
+
);
|
|
8825
9763
|
}
|
|
8826
|
-
|
|
8827
|
-
|
|
8828
|
-
|
|
8829
|
-
|
|
8830
|
-
|
|
8831
|
-
|
|
8832
|
-
|
|
8833
|
-
|
|
8834
|
-
|
|
8835
|
-
|
|
8836
|
-
|
|
8837
|
-
|
|
8838
|
-
|
|
8839
|
-
|
|
8840
|
-
|
|
8841
|
-
|
|
9764
|
+
}
|
|
9765
|
+
return {
|
|
9766
|
+
instructionsLocations: [...new Set(result.instructionsLocations)],
|
|
9767
|
+
agentLocations: [...new Set(result.agentLocations)],
|
|
9768
|
+
skillsLocations: [...new Set(result.skillsLocations)]
|
|
9769
|
+
};
|
|
9770
|
+
}
|
|
9771
|
+
async function hasCustomInstructions(repoPath) {
|
|
9772
|
+
const found = [];
|
|
9773
|
+
const candidates = [
|
|
9774
|
+
".github/copilot-instructions.md",
|
|
9775
|
+
"CLAUDE.md",
|
|
9776
|
+
".claude/CLAUDE.md",
|
|
9777
|
+
"AGENTS.md",
|
|
9778
|
+
".github/AGENTS.md",
|
|
9779
|
+
".cursorrules",
|
|
9780
|
+
".cursorignore",
|
|
9781
|
+
".windsurfrules",
|
|
9782
|
+
".github/instructions.md",
|
|
9783
|
+
"copilot-instructions.md"
|
|
9784
|
+
];
|
|
9785
|
+
for (const candidate of candidates) {
|
|
9786
|
+
if (await fileExists(path9.join(repoPath, candidate))) {
|
|
9787
|
+
found.push(candidate);
|
|
8842
9788
|
}
|
|
8843
|
-
|
|
8844
|
-
|
|
8845
|
-
|
|
8846
|
-
|
|
8847
|
-
|
|
9789
|
+
}
|
|
9790
|
+
return found;
|
|
9791
|
+
}
|
|
9792
|
+
async function hasFileBasedInstructions(repoPath, extraDirs) {
|
|
9793
|
+
const found = [];
|
|
9794
|
+
const defaultDir = path9.join(repoPath, ".github", "instructions");
|
|
9795
|
+
try {
|
|
9796
|
+
const entries = await fs7.readdir(defaultDir);
|
|
9797
|
+
found.push(
|
|
9798
|
+
...entries.filter((e) => e.endsWith(".instructions.md")).map((e) => `.github/instructions/${e}`)
|
|
8848
9799
|
);
|
|
8849
|
-
|
|
8850
|
-
|
|
8851
|
-
|
|
8852
|
-
|
|
8853
|
-
|
|
8854
|
-
|
|
8855
|
-
|
|
8856
|
-
|
|
8857
|
-
|
|
8858
|
-
|
|
8859
|
-
|
|
8860
|
-
});
|
|
8861
|
-
continue;
|
|
9800
|
+
} catch {
|
|
9801
|
+
}
|
|
9802
|
+
for (const dir of extraDirs ?? []) {
|
|
9803
|
+
const fullDir = path9.join(repoPath, dir);
|
|
9804
|
+
const normalizedDir = dir.replace(/\\/gu, "/").replace(/\/+$/u, "");
|
|
9805
|
+
try {
|
|
9806
|
+
const entries = await fs7.readdir(fullDir);
|
|
9807
|
+
found.push(
|
|
9808
|
+
...entries.filter((e) => e.endsWith(".instructions.md")).map((e) => `${normalizedDir}/${e}`)
|
|
9809
|
+
);
|
|
9810
|
+
} catch {
|
|
8862
9811
|
}
|
|
8863
|
-
const passed = appResults.filter((entry) => entry.result.status === "pass").length;
|
|
8864
|
-
const total = appResults.length;
|
|
8865
|
-
const passRate = total ? passed / total : 0;
|
|
8866
|
-
const status = passRate >= passRateThreshold ? "pass" : "fail";
|
|
8867
|
-
const failures = appResults.filter((entry) => entry.result.status !== "pass").map((entry) => entry.app.name);
|
|
8868
|
-
criteriaResults.push({
|
|
8869
|
-
id: criterion.id,
|
|
8870
|
-
title: criterion.title,
|
|
8871
|
-
pillar: criterion.pillar,
|
|
8872
|
-
level: criterion.level,
|
|
8873
|
-
scope: criterion.scope,
|
|
8874
|
-
impact: criterion.impact,
|
|
8875
|
-
effort: criterion.effort,
|
|
8876
|
-
status,
|
|
8877
|
-
reason: status === "pass" ? void 0 : `Only ${passed}/${total} apps pass this check.`,
|
|
8878
|
-
passRate,
|
|
8879
|
-
appSummary: { passed, total },
|
|
8880
|
-
appFailures: failures
|
|
8881
|
-
});
|
|
8882
9812
|
}
|
|
8883
|
-
|
|
8884
|
-
|
|
8885
|
-
|
|
8886
|
-
|
|
8887
|
-
|
|
8888
|
-
|
|
8889
|
-
|
|
8890
|
-
|
|
8891
|
-
|
|
8892
|
-
|
|
8893
|
-
|
|
8894
|
-
|
|
8895
|
-
|
|
8896
|
-
|
|
8897
|
-
|
|
8898
|
-
|
|
8899
|
-
|
|
8900
|
-
|
|
8901
|
-
|
|
8902
|
-
|
|
8903
|
-
|
|
8904
|
-
|
|
8905
|
-
|
|
8906
|
-
|
|
8907
|
-
|
|
8908
|
-
|
|
8909
|
-
|
|
8910
|
-
|
|
8911
|
-
|
|
8912
|
-
|
|
8913
|
-
areaReports.push({ area, criteria: areaResults, pillars: areaPillars });
|
|
9813
|
+
return [...new Set(found)];
|
|
9814
|
+
}
|
|
9815
|
+
function contentSimilarity(a, b) {
|
|
9816
|
+
const normalize = (s) => new Set(
|
|
9817
|
+
s.toLowerCase().split("\n").map((l) => l.trim().replace(/\s+/gu, " ")).filter((l) => l.length > 0)
|
|
9818
|
+
);
|
|
9819
|
+
const setA = normalize(a);
|
|
9820
|
+
const setB = normalize(b);
|
|
9821
|
+
if (setA.size === 0 && setB.size === 0) return 1;
|
|
9822
|
+
let intersection = 0;
|
|
9823
|
+
for (const line of setA) {
|
|
9824
|
+
if (setB.has(line)) intersection++;
|
|
9825
|
+
}
|
|
9826
|
+
const union = (/* @__PURE__ */ new Set([...setA, ...setB])).size;
|
|
9827
|
+
return union === 0 ? 1 : intersection / union;
|
|
9828
|
+
}
|
|
9829
|
+
async function checkInstructionConsistency(repoPath, foundFiles) {
|
|
9830
|
+
if (foundFiles.length <= 1) {
|
|
9831
|
+
return { unified: true, files: foundFiles };
|
|
9832
|
+
}
|
|
9833
|
+
const realPathMap = /* @__PURE__ */ new Map();
|
|
9834
|
+
for (const file of foundFiles) {
|
|
9835
|
+
const fullPath = path9.join(repoPath, file);
|
|
9836
|
+
try {
|
|
9837
|
+
const real = await fs7.realpath(fullPath);
|
|
9838
|
+
const group = realPathMap.get(real) ?? [];
|
|
9839
|
+
group.push(file);
|
|
9840
|
+
realPathMap.set(real, group);
|
|
9841
|
+
} catch {
|
|
9842
|
+
realPathMap.set(fullPath, [file]);
|
|
8914
9843
|
}
|
|
8915
|
-
|
|
8916
|
-
|
|
8917
|
-
|
|
8918
|
-
|
|
8919
|
-
|
|
8920
|
-
|
|
8921
|
-
|
|
8922
|
-
|
|
8923
|
-
|
|
8924
|
-
|
|
8925
|
-
|
|
8926
|
-
criterion.areaFailures = areaReports.filter((ar) => ar.criteria.find((c) => c.id === criterion.id)?.status !== "pass").map((ar) => ar.area.name);
|
|
9844
|
+
}
|
|
9845
|
+
const groups = [...realPathMap.values()];
|
|
9846
|
+
if (groups.length <= 1) {
|
|
9847
|
+
return { unified: true, files: foundFiles };
|
|
9848
|
+
}
|
|
9849
|
+
const contents = [];
|
|
9850
|
+
for (const group of groups) {
|
|
9851
|
+
try {
|
|
9852
|
+
contents.push(await fs7.readFile(path9.join(repoPath, group[0]), "utf8"));
|
|
9853
|
+
} catch {
|
|
9854
|
+
contents.push("");
|
|
8927
9855
|
}
|
|
8928
9856
|
}
|
|
8929
|
-
|
|
8930
|
-
|
|
8931
|
-
|
|
8932
|
-
|
|
8933
|
-
|
|
8934
|
-
if (options.shadow) {
|
|
8935
|
-
const policyCtx = {
|
|
8936
|
-
repoPath,
|
|
8937
|
-
rootFiles,
|
|
8938
|
-
rootPackageJson,
|
|
8939
|
-
cache: /* @__PURE__ */ new Map(),
|
|
8940
|
-
analysis,
|
|
8941
|
-
apps
|
|
8942
|
-
};
|
|
8943
|
-
const engineChain = await loadPluginChain(policySources ?? [], { jsonOnly: isConfigSourced });
|
|
8944
|
-
const engineReport = await executePlugins(engineChain.plugins, policyCtx, engineChain.options);
|
|
8945
|
-
engine = {
|
|
8946
|
-
signals: engineReport.signals,
|
|
8947
|
-
recommendations: engineReport.recommendations,
|
|
8948
|
-
policyWarnings: engineReport.policyWarnings,
|
|
8949
|
-
score: engineReport.score,
|
|
8950
|
-
grade: engineReport.grade
|
|
8951
|
-
};
|
|
9857
|
+
let minSimilarity = 1;
|
|
9858
|
+
for (let i = 0; i < contents.length; i++) {
|
|
9859
|
+
for (let j = i + 1; j < contents.length; j++) {
|
|
9860
|
+
minSimilarity = Math.min(minSimilarity, contentSimilarity(contents[i], contents[j]));
|
|
9861
|
+
}
|
|
8952
9862
|
}
|
|
8953
9863
|
return {
|
|
8954
|
-
|
|
8955
|
-
|
|
8956
|
-
|
|
8957
|
-
apps: apps.map((app) => ({ name: app.name, path: app.path })),
|
|
8958
|
-
pillars,
|
|
8959
|
-
levels,
|
|
8960
|
-
achievedLevel,
|
|
8961
|
-
criteria: criteriaResults,
|
|
8962
|
-
extras,
|
|
8963
|
-
areaReports,
|
|
8964
|
-
policies: policyInfo,
|
|
8965
|
-
engine
|
|
9864
|
+
unified: minSimilarity >= 0.9,
|
|
9865
|
+
files: foundFiles,
|
|
9866
|
+
similarity: Math.round(minSimilarity * 100) / 100
|
|
8966
9867
|
};
|
|
8967
9868
|
}
|
|
9869
|
+
async function hasMcpConfig(repoPath) {
|
|
9870
|
+
const found = [];
|
|
9871
|
+
if (await fileExists(path9.join(repoPath, ".vscode", "mcp.json"))) {
|
|
9872
|
+
found.push(".vscode/mcp.json");
|
|
9873
|
+
}
|
|
9874
|
+
if (await fileExists(path9.join(repoPath, "mcp.json"))) {
|
|
9875
|
+
found.push("mcp.json");
|
|
9876
|
+
}
|
|
9877
|
+
const settings = await readJson(path9.join(repoPath, ".vscode", "settings.json"));
|
|
9878
|
+
if (settings && (settings["mcp"] || settings["github.copilot.chat.mcp.enabled"])) {
|
|
9879
|
+
found.push(".vscode/settings.json (mcp section)");
|
|
9880
|
+
}
|
|
9881
|
+
if (await fileExists(path9.join(repoPath, ".claude", "mcp.json"))) {
|
|
9882
|
+
found.push(".claude/mcp.json");
|
|
9883
|
+
}
|
|
9884
|
+
return found;
|
|
9885
|
+
}
|
|
9886
|
+
async function hasCustomAgents(repoPath, extraDirs) {
|
|
9887
|
+
const found = [];
|
|
9888
|
+
const agentDirs = [".github/agents", ".copilot/agents", ".github/copilot/agents"];
|
|
9889
|
+
for (const dir of agentDirs) {
|
|
9890
|
+
if (await fileExists(path9.join(repoPath, dir))) {
|
|
9891
|
+
found.push(dir);
|
|
9892
|
+
}
|
|
9893
|
+
}
|
|
9894
|
+
const agentFiles = [".github/copilot-agents.yml", ".github/copilot-agents.yaml"];
|
|
9895
|
+
for (const agentFile of agentFiles) {
|
|
9896
|
+
if (await fileExists(path9.join(repoPath, agentFile))) {
|
|
9897
|
+
found.push(agentFile);
|
|
9898
|
+
}
|
|
9899
|
+
}
|
|
9900
|
+
for (const dir of extraDirs ?? []) {
|
|
9901
|
+
if (await fileExists(path9.join(repoPath, dir))) {
|
|
9902
|
+
found.push(dir);
|
|
9903
|
+
}
|
|
9904
|
+
}
|
|
9905
|
+
return [...new Set(found)];
|
|
9906
|
+
}
|
|
9907
|
+
async function hasCopilotSkills(repoPath, extraDirs) {
|
|
9908
|
+
const found = [];
|
|
9909
|
+
const skillDirs = [
|
|
9910
|
+
".copilot/skills",
|
|
9911
|
+
".github/skills",
|
|
9912
|
+
".claude/skills",
|
|
9913
|
+
".github/copilot/skills"
|
|
9914
|
+
];
|
|
9915
|
+
for (const dir of skillDirs) {
|
|
9916
|
+
if (await fileExists(path9.join(repoPath, dir))) {
|
|
9917
|
+
found.push(dir);
|
|
9918
|
+
}
|
|
9919
|
+
}
|
|
9920
|
+
for (const dir of extraDirs ?? []) {
|
|
9921
|
+
if (await fileExists(path9.join(repoPath, dir))) {
|
|
9922
|
+
found.push(dir);
|
|
9923
|
+
}
|
|
9924
|
+
}
|
|
9925
|
+
return [...new Set(found)];
|
|
9926
|
+
}
|
|
9927
|
+
async function hasApmConfig(repoPath) {
|
|
9928
|
+
return fileExists(path9.join(repoPath, "apm.yml"));
|
|
9929
|
+
}
|
|
9930
|
+
async function hasApmLockfile(repoPath) {
|
|
9931
|
+
return fileExists(path9.join(repoPath, "apm.lock.yaml"));
|
|
9932
|
+
}
|
|
9933
|
+
async function hasApmInWorkflows(repoPath) {
|
|
9934
|
+
const workflowDir = path9.join(repoPath, ".github", "workflows");
|
|
9935
|
+
let files;
|
|
9936
|
+
try {
|
|
9937
|
+
files = await fs7.readdir(workflowDir);
|
|
9938
|
+
} catch {
|
|
9939
|
+
return false;
|
|
9940
|
+
}
|
|
9941
|
+
for (const file of files) {
|
|
9942
|
+
if (!file.endsWith(".yml") && !file.endsWith(".yaml")) continue;
|
|
9943
|
+
try {
|
|
9944
|
+
const content = await fs7.readFile(path9.join(workflowDir, file), "utf8");
|
|
9945
|
+
if (/\bmicrosoft\/apm-action\b/.test(content) || /\bapm\s+(audit|install)\b/.test(content)) {
|
|
9946
|
+
return true;
|
|
9947
|
+
}
|
|
9948
|
+
} catch {
|
|
9949
|
+
}
|
|
9950
|
+
}
|
|
9951
|
+
return false;
|
|
9952
|
+
}
|
|
9953
|
+
async function readAllDependencies(context) {
|
|
9954
|
+
const dependencies = [];
|
|
9955
|
+
const apps = context.apps.length ? context.apps : [];
|
|
9956
|
+
for (const app of apps) {
|
|
9957
|
+
if (!app.packageJsonPath) continue;
|
|
9958
|
+
const pkg = await readJson(app.packageJsonPath);
|
|
9959
|
+
const deps = pkg?.dependencies ?? {};
|
|
9960
|
+
const devDeps = pkg?.devDependencies ?? {};
|
|
9961
|
+
dependencies.push(
|
|
9962
|
+
...Object.keys({
|
|
9963
|
+
...deps,
|
|
9964
|
+
...devDeps
|
|
9965
|
+
})
|
|
9966
|
+
);
|
|
9967
|
+
}
|
|
9968
|
+
if (!apps.length && context.rootPackageJson) {
|
|
9969
|
+
const rootDeps = context.rootPackageJson.dependencies ?? {};
|
|
9970
|
+
const rootDevDeps = context.rootPackageJson.devDependencies ?? {};
|
|
9971
|
+
dependencies.push(
|
|
9972
|
+
...Object.keys({
|
|
9973
|
+
...rootDeps,
|
|
9974
|
+
...rootDevDeps
|
|
9975
|
+
})
|
|
9976
|
+
);
|
|
9977
|
+
}
|
|
9978
|
+
return Array.from(new Set(dependencies));
|
|
9979
|
+
}
|
|
9980
|
+
|
|
9981
|
+
// packages/core/src/services/readiness/criteria.ts
|
|
9982
|
+
import path10 from "path";
|
|
8968
9983
|
function buildCriteria() {
|
|
8969
9984
|
return [
|
|
8970
9985
|
{
|
|
@@ -9076,7 +10091,7 @@ function buildCriteria() {
|
|
|
9076
10091
|
impact: "medium",
|
|
9077
10092
|
effort: "low",
|
|
9078
10093
|
check: async (context) => {
|
|
9079
|
-
const found = await fileExists(
|
|
10094
|
+
const found = await fileExists(path10.join(context.repoPath, "CONTRIBUTING.md"));
|
|
9080
10095
|
return {
|
|
9081
10096
|
status: found ? "pass" : "fail",
|
|
9082
10097
|
reason: found ? void 0 : "Missing CONTRIBUTING.md for contributor workflows."
|
|
@@ -9177,7 +10192,7 @@ function buildCriteria() {
|
|
|
9177
10192
|
impact: "high",
|
|
9178
10193
|
effort: "low",
|
|
9179
10194
|
check: async (context) => {
|
|
9180
|
-
const found = await fileExists(
|
|
10195
|
+
const found = await fileExists(path10.join(context.repoPath, "SECURITY.md"));
|
|
9181
10196
|
return {
|
|
9182
10197
|
status: found ? "pass" : "fail",
|
|
9183
10198
|
reason: found ? void 0 : "Missing SECURITY.md policy."
|
|
@@ -9193,7 +10208,7 @@ function buildCriteria() {
|
|
|
9193
10208
|
impact: "medium",
|
|
9194
10209
|
effort: "medium",
|
|
9195
10210
|
check: async (context) => {
|
|
9196
|
-
const found = await fileExists(
|
|
10211
|
+
const found = await fileExists(path10.join(context.repoPath, ".github", "dependabot.yml"));
|
|
9197
10212
|
return {
|
|
9198
10213
|
status: found ? "pass" : "fail",
|
|
9199
10214
|
reason: found ? void 0 : "Missing .github/dependabot.yml configuration."
|
|
@@ -9242,7 +10257,10 @@ function buildCriteria() {
|
|
|
9242
10257
|
]
|
|
9243
10258
|
};
|
|
9244
10259
|
}
|
|
9245
|
-
const fileBasedInstructions = await hasFileBasedInstructions(
|
|
10260
|
+
const fileBasedInstructions = await hasFileBasedInstructions(
|
|
10261
|
+
context.repoPath,
|
|
10262
|
+
context.vscodeLocations?.instructionsLocations
|
|
10263
|
+
);
|
|
9246
10264
|
const areas = context.analysis.areas ?? [];
|
|
9247
10265
|
if (areas.length > 0) {
|
|
9248
10266
|
if (fileBasedInstructions.length === 0) {
|
|
@@ -9258,6 +10276,13 @@ function buildCriteria() {
|
|
|
9258
10276
|
evidence: [...rootFound, ...fileBasedInstructions]
|
|
9259
10277
|
};
|
|
9260
10278
|
}
|
|
10279
|
+
if (fileBasedInstructions.length > 0) {
|
|
10280
|
+
return {
|
|
10281
|
+
status: "pass",
|
|
10282
|
+
reason: `Root + ${fileBasedInstructions.length} file-based instruction(s) found.`,
|
|
10283
|
+
evidence: [...rootFound, ...fileBasedInstructions]
|
|
10284
|
+
};
|
|
10285
|
+
}
|
|
9261
10286
|
if (context.analysis.isMonorepo && context.apps.length > 1) {
|
|
9262
10287
|
const appsMissing = [];
|
|
9263
10288
|
for (const app of context.apps) {
|
|
@@ -9337,7 +10362,10 @@ function buildCriteria() {
|
|
|
9337
10362
|
impact: "medium",
|
|
9338
10363
|
effort: "medium",
|
|
9339
10364
|
check: async (context) => {
|
|
9340
|
-
const found = await hasCustomAgents(
|
|
10365
|
+
const found = await hasCustomAgents(
|
|
10366
|
+
context.repoPath,
|
|
10367
|
+
context.vscodeLocations?.agentLocations
|
|
10368
|
+
);
|
|
9341
10369
|
return {
|
|
9342
10370
|
status: found.length > 0 ? "pass" : "fail",
|
|
9343
10371
|
reason: "No custom AI agents configured (e.g. .github/agents/, .copilot/agents/).",
|
|
@@ -9354,7 +10382,10 @@ function buildCriteria() {
|
|
|
9354
10382
|
impact: "medium",
|
|
9355
10383
|
effort: "medium",
|
|
9356
10384
|
check: async (context) => {
|
|
9357
|
-
const found = await hasCopilotSkills(
|
|
10385
|
+
const found = await hasCopilotSkills(
|
|
10386
|
+
context.repoPath,
|
|
10387
|
+
context.vscodeLocations?.skillsLocations
|
|
10388
|
+
);
|
|
9358
10389
|
return {
|
|
9359
10390
|
status: found.length > 0 ? "pass" : "fail",
|
|
9360
10391
|
reason: "No Copilot or Claude skills found (e.g. .copilot/skills/, .github/skills/).",
|
|
@@ -9362,6 +10393,65 @@ function buildCriteria() {
|
|
|
9362
10393
|
};
|
|
9363
10394
|
}
|
|
9364
10395
|
},
|
|
10396
|
+
{
|
|
10397
|
+
id: "apm-config",
|
|
10398
|
+
title: "APM package manifest present",
|
|
10399
|
+
pillar: "ai-tooling",
|
|
10400
|
+
level: 2,
|
|
10401
|
+
scope: "repo",
|
|
10402
|
+
impact: "medium",
|
|
10403
|
+
effort: "low",
|
|
10404
|
+
check: async (context) => {
|
|
10405
|
+
const found = await hasApmConfig(context.repoPath);
|
|
10406
|
+
return {
|
|
10407
|
+
status: found ? "pass" : "fail",
|
|
10408
|
+
reason: found ? void 0 : "No apm.yml found. Use APM to install shared agent packages and keep instructions in sync across repos. See: https://github.com/microsoft/apm",
|
|
10409
|
+
evidence: ["apm.yml"]
|
|
10410
|
+
};
|
|
10411
|
+
}
|
|
10412
|
+
},
|
|
10413
|
+
{
|
|
10414
|
+
id: "apm-locked-deps",
|
|
10415
|
+
title: "APM dependencies locked",
|
|
10416
|
+
pillar: "ai-tooling",
|
|
10417
|
+
level: 3,
|
|
10418
|
+
scope: "repo",
|
|
10419
|
+
impact: "medium",
|
|
10420
|
+
effort: "low",
|
|
10421
|
+
check: async (context) => {
|
|
10422
|
+
const hasConfig = await hasApmConfig(context.repoPath);
|
|
10423
|
+
if (!hasConfig) {
|
|
10424
|
+
return { status: "skip", reason: "No apm.yml found \u2014 skipping lockfile check." };
|
|
10425
|
+
}
|
|
10426
|
+
const found = await hasApmLockfile(context.repoPath);
|
|
10427
|
+
return {
|
|
10428
|
+
status: found ? "pass" : "fail",
|
|
10429
|
+
reason: found ? void 0 : "apm.yml found but dependencies are not locked. Run `apm install` to generate apm.lock.yaml.",
|
|
10430
|
+
evidence: ["apm.lock.yaml"]
|
|
10431
|
+
};
|
|
10432
|
+
}
|
|
10433
|
+
},
|
|
10434
|
+
{
|
|
10435
|
+
id: "apm-ci-integration",
|
|
10436
|
+
title: "APM integrated in CI pipeline",
|
|
10437
|
+
pillar: "ai-tooling",
|
|
10438
|
+
level: 4,
|
|
10439
|
+
scope: "repo",
|
|
10440
|
+
impact: "high",
|
|
10441
|
+
effort: "medium",
|
|
10442
|
+
check: async (context) => {
|
|
10443
|
+
const hasConfig = await hasApmConfig(context.repoPath);
|
|
10444
|
+
if (!hasConfig) {
|
|
10445
|
+
return { status: "skip", reason: "No apm.yml found \u2014 skipping CI check." };
|
|
10446
|
+
}
|
|
10447
|
+
const found = await hasApmInWorkflows(context.repoPath);
|
|
10448
|
+
return {
|
|
10449
|
+
status: found ? "pass" : "fail",
|
|
10450
|
+
reason: found ? void 0 : "No APM step found in CI. Add `microsoft/apm-action` to your workflow to audit agent packages on every PR. See: https://github.com/microsoft/apm-action",
|
|
10451
|
+
evidence: [".github/workflows/*.{yml,yaml}"]
|
|
10452
|
+
};
|
|
10453
|
+
}
|
|
10454
|
+
},
|
|
9365
10455
|
// ── Area-scoped criteria (only run when areaPath is set) ──
|
|
9366
10456
|
{
|
|
9367
10457
|
id: "area-readme",
|
|
@@ -9399,7 +10489,7 @@ function buildCriteria() {
|
|
|
9399
10489
|
if (area?.scripts?.build) {
|
|
9400
10490
|
return { status: "pass" };
|
|
9401
10491
|
}
|
|
9402
|
-
const pkgPath =
|
|
10492
|
+
const pkgPath = path10.join(context.areaPath, "package.json");
|
|
9403
10493
|
const pkg = await readJson(pkgPath);
|
|
9404
10494
|
const scripts = pkg?.scripts ?? {};
|
|
9405
10495
|
const found = Boolean(scripts.build);
|
|
@@ -9424,7 +10514,7 @@ function buildCriteria() {
|
|
|
9424
10514
|
if (area?.scripts?.test) {
|
|
9425
10515
|
return { status: "pass" };
|
|
9426
10516
|
}
|
|
9427
|
-
const pkgPath =
|
|
10517
|
+
const pkgPath = path10.join(context.areaPath, "package.json");
|
|
9428
10518
|
const pkg = await readJson(pkgPath);
|
|
9429
10519
|
const scripts = pkg?.scripts ?? {};
|
|
9430
10520
|
const found = Boolean(scripts.test);
|
|
@@ -9447,7 +10537,7 @@ function buildCriteria() {
|
|
|
9447
10537
|
return { status: "skip", reason: "No area context." };
|
|
9448
10538
|
}
|
|
9449
10539
|
const sanitized = sanitizeAreaName(area.name);
|
|
9450
|
-
const instructionPath =
|
|
10540
|
+
const instructionPath = path10.join(
|
|
9451
10541
|
context.repoPath,
|
|
9452
10542
|
".github",
|
|
9453
10543
|
"instructions",
|
|
@@ -9462,13 +10552,16 @@ function buildCriteria() {
|
|
|
9462
10552
|
}
|
|
9463
10553
|
];
|
|
9464
10554
|
}
|
|
10555
|
+
|
|
10556
|
+
// packages/core/src/services/readiness/extras.ts
|
|
10557
|
+
import path11 from "path";
|
|
9465
10558
|
function buildExtras() {
|
|
9466
10559
|
return [
|
|
9467
10560
|
{
|
|
9468
10561
|
id: "agents-doc",
|
|
9469
10562
|
title: "AGENTS.md present",
|
|
9470
10563
|
check: async (context) => {
|
|
9471
|
-
const found = await fileExists(
|
|
10564
|
+
const found = await fileExists(path11.join(context.repoPath, "AGENTS.md"));
|
|
9472
10565
|
return {
|
|
9473
10566
|
status: found ? "pass" : "fail",
|
|
9474
10567
|
reason: found ? void 0 : "Missing AGENTS.md to guide coding agents."
|
|
@@ -9510,18 +10603,65 @@ function buildExtras() {
|
|
|
9510
10603
|
}
|
|
9511
10604
|
];
|
|
9512
10605
|
}
|
|
9513
|
-
async function runExtras(context, extraDefs) {
|
|
9514
|
-
const results = [];
|
|
9515
|
-
for (const def of extraDefs) {
|
|
9516
|
-
const result = await def.check(context);
|
|
9517
|
-
results.push({
|
|
9518
|
-
id: def.id,
|
|
9519
|
-
title: def.title,
|
|
9520
|
-
status: result.status,
|
|
9521
|
-
reason: result.reason
|
|
9522
|
-
});
|
|
9523
|
-
}
|
|
9524
|
-
return results;
|
|
10606
|
+
async function runExtras(context, extraDefs) {
|
|
10607
|
+
const results = [];
|
|
10608
|
+
for (const def of extraDefs) {
|
|
10609
|
+
const result = await def.check(context);
|
|
10610
|
+
results.push({
|
|
10611
|
+
id: def.id,
|
|
10612
|
+
title: def.title,
|
|
10613
|
+
status: result.status,
|
|
10614
|
+
reason: result.reason
|
|
10615
|
+
});
|
|
10616
|
+
}
|
|
10617
|
+
return results;
|
|
10618
|
+
}
|
|
10619
|
+
|
|
10620
|
+
// packages/core/src/services/readiness/types.ts
|
|
10621
|
+
var PILLAR_GROUPS = {
|
|
10622
|
+
"style-validation": "repo-health",
|
|
10623
|
+
"build-system": "repo-health",
|
|
10624
|
+
testing: "repo-health",
|
|
10625
|
+
documentation: "repo-health",
|
|
10626
|
+
"dev-environment": "repo-health",
|
|
10627
|
+
"code-quality": "repo-health",
|
|
10628
|
+
observability: "repo-health",
|
|
10629
|
+
"security-governance": "repo-health",
|
|
10630
|
+
"ai-tooling": "ai-setup"
|
|
10631
|
+
};
|
|
10632
|
+
var PILLAR_GROUP_NAMES = {
|
|
10633
|
+
"repo-health": "Repo Health",
|
|
10634
|
+
"ai-setup": "AI Setup"
|
|
10635
|
+
};
|
|
10636
|
+
|
|
10637
|
+
// packages/core/src/services/readiness/scoring.ts
|
|
10638
|
+
function groupPillars(pillars) {
|
|
10639
|
+
const groups = ["repo-health", "ai-setup"];
|
|
10640
|
+
return groups.map((group) => ({
|
|
10641
|
+
group,
|
|
10642
|
+
label: PILLAR_GROUP_NAMES[group],
|
|
10643
|
+
pillars: pillars.filter((p) => PILLAR_GROUPS[p.id] === group)
|
|
10644
|
+
}));
|
|
10645
|
+
}
|
|
10646
|
+
function getLevelName(level) {
|
|
10647
|
+
const names = {
|
|
10648
|
+
1: "Functional",
|
|
10649
|
+
2: "Documented",
|
|
10650
|
+
3: "Standardized",
|
|
10651
|
+
4: "Optimized",
|
|
10652
|
+
5: "Autonomous"
|
|
10653
|
+
};
|
|
10654
|
+
return names[level] || "Unknown";
|
|
10655
|
+
}
|
|
10656
|
+
function getLevelDescription(level) {
|
|
10657
|
+
const descriptions = {
|
|
10658
|
+
1: "Repo builds, tests run, and basic tooling (linter, lockfile) is in place. AI agents can clone and get started.",
|
|
10659
|
+
2: "README, CONTRIBUTING guide, and custom instructions exist. Agents understand project context and conventions.",
|
|
10660
|
+
3: "CI/CD, security policies, CODEOWNERS, and observability are configured. Agents operate within well-defined guardrails.",
|
|
10661
|
+
4: "MCP servers, custom agents, and AI skills are set up. Agents have deep integration with project-specific tools and workflows.",
|
|
10662
|
+
5: "Full AI-native development: agents can independently plan, implement, test, and ship changes with minimal human oversight."
|
|
10663
|
+
};
|
|
10664
|
+
return descriptions[level] || "";
|
|
9525
10665
|
}
|
|
9526
10666
|
function summarizePillars(criteria) {
|
|
9527
10667
|
const pillarNames = {
|
|
@@ -9583,247 +10723,226 @@ function countStatus(items) {
|
|
|
9583
10723
|
const passed = relevant.filter((item) => item.status === "pass").length;
|
|
9584
10724
|
return { passed, total: relevant.length };
|
|
9585
10725
|
}
|
|
9586
|
-
|
|
9587
|
-
|
|
9588
|
-
|
|
9589
|
-
|
|
9590
|
-
const
|
|
9591
|
-
|
|
9592
|
-
|
|
9593
|
-
|
|
9594
|
-
|
|
9595
|
-
|
|
9596
|
-
|
|
9597
|
-
|
|
9598
|
-
|
|
9599
|
-
|
|
9600
|
-
|
|
9601
|
-
|
|
9602
|
-
|
|
9603
|
-
|
|
9604
|
-
|
|
9605
|
-
|
|
9606
|
-
|
|
9607
|
-
|
|
9608
|
-
|
|
9609
|
-
|
|
9610
|
-
".prettierrc.cjs",
|
|
9611
|
-
"prettier.config.js",
|
|
9612
|
-
"prettier.config.cjs"
|
|
9613
|
-
]);
|
|
9614
|
-
}
|
|
9615
|
-
async function hasFormatterConfig(repoPath) {
|
|
9616
|
-
return hasAnyFile(await safeReadDir(repoPath), [
|
|
9617
|
-
"biome.json",
|
|
9618
|
-
"biome.jsonc",
|
|
9619
|
-
".prettierrc",
|
|
9620
|
-
".prettierrc.json",
|
|
9621
|
-
".prettierrc.js",
|
|
9622
|
-
".prettierrc.cjs",
|
|
9623
|
-
"prettier.config.js",
|
|
9624
|
-
"prettier.config.cjs"
|
|
9625
|
-
]);
|
|
9626
|
-
}
|
|
9627
|
-
async function hasTypecheckConfig(repoPath) {
|
|
9628
|
-
return hasAnyFile(await safeReadDir(repoPath), [
|
|
9629
|
-
"tsconfig.json",
|
|
9630
|
-
"tsconfig.base.json",
|
|
9631
|
-
"pyproject.toml",
|
|
9632
|
-
"mypy.ini"
|
|
9633
|
-
]);
|
|
9634
|
-
}
|
|
9635
|
-
async function hasGithubWorkflows(repoPath) {
|
|
9636
|
-
return fileExists(path9.join(repoPath, ".github", "workflows"));
|
|
9637
|
-
}
|
|
9638
|
-
async function hasCodeowners(repoPath) {
|
|
9639
|
-
const root = await fileExists(path9.join(repoPath, "CODEOWNERS"));
|
|
9640
|
-
const github = await fileExists(path9.join(repoPath, ".github", "CODEOWNERS"));
|
|
9641
|
-
return root || github;
|
|
9642
|
-
}
|
|
9643
|
-
async function hasLicense(repoPath) {
|
|
9644
|
-
const files = await safeReadDir(repoPath);
|
|
9645
|
-
return files.some((file) => file.toLowerCase().startsWith("license"));
|
|
9646
|
-
}
|
|
9647
|
-
async function hasPullRequestTemplate(repoPath) {
|
|
9648
|
-
const direct = await fileExists(path9.join(repoPath, ".github", "PULL_REQUEST_TEMPLATE.md"));
|
|
9649
|
-
if (direct) return true;
|
|
9650
|
-
const dir = path9.join(repoPath, ".github", "PULL_REQUEST_TEMPLATE");
|
|
9651
|
-
try {
|
|
9652
|
-
const entries = await fs7.readdir(dir);
|
|
9653
|
-
return entries.some((entry) => entry.toLowerCase().endsWith(".md"));
|
|
9654
|
-
} catch {
|
|
9655
|
-
return false;
|
|
9656
|
-
}
|
|
9657
|
-
}
|
|
9658
|
-
async function hasPrecommitConfig(repoPath) {
|
|
9659
|
-
const precommit = await fileExists(path9.join(repoPath, ".pre-commit-config.yaml"));
|
|
9660
|
-
if (precommit) return true;
|
|
9661
|
-
return fileExists(path9.join(repoPath, ".husky"));
|
|
9662
|
-
}
|
|
9663
|
-
async function hasArchitectureDoc(repoPath) {
|
|
9664
|
-
const files = await safeReadDir(repoPath);
|
|
9665
|
-
if (files.some((file) => file.toLowerCase() === "architecture.md")) return true;
|
|
9666
|
-
return fileExists(path9.join(repoPath, "docs", "architecture.md"));
|
|
9667
|
-
}
|
|
9668
|
-
async function hasCustomInstructions(repoPath) {
|
|
9669
|
-
const found = [];
|
|
9670
|
-
const candidates = [
|
|
9671
|
-
".github/copilot-instructions.md",
|
|
9672
|
-
"CLAUDE.md",
|
|
9673
|
-
".claude/CLAUDE.md",
|
|
9674
|
-
"AGENTS.md",
|
|
9675
|
-
".github/AGENTS.md",
|
|
9676
|
-
".cursorrules",
|
|
9677
|
-
".cursorignore",
|
|
9678
|
-
".windsurfrules",
|
|
9679
|
-
".github/instructions.md",
|
|
9680
|
-
"copilot-instructions.md"
|
|
9681
|
-
];
|
|
9682
|
-
for (const candidate of candidates) {
|
|
9683
|
-
if (await fileExists(path9.join(repoPath, candidate))) {
|
|
9684
|
-
found.push(candidate);
|
|
10726
|
+
|
|
10727
|
+
// packages/core/src/services/readiness/index.ts
|
|
10728
|
+
async function runReadinessReport(options) {
|
|
10729
|
+
const repoPath = options.repoPath;
|
|
10730
|
+
const analysis = await analyzeRepo(repoPath);
|
|
10731
|
+
const rootFiles = await safeReadDir(repoPath);
|
|
10732
|
+
const rootPackageJson = await readJson(path12.join(repoPath, "package.json"));
|
|
10733
|
+
const apps = analysis.apps?.length ? analysis.apps : [];
|
|
10734
|
+
const vscodeLocations = await parseVscodeLocations(repoPath, rootFiles);
|
|
10735
|
+
const context = {
|
|
10736
|
+
repoPath,
|
|
10737
|
+
analysis,
|
|
10738
|
+
apps,
|
|
10739
|
+
rootFiles,
|
|
10740
|
+
rootPackageJson,
|
|
10741
|
+
vscodeLocations
|
|
10742
|
+
};
|
|
10743
|
+
let policySources = options.policies;
|
|
10744
|
+
let isConfigSourced = false;
|
|
10745
|
+
if (!policySources?.length) {
|
|
10746
|
+
const agentrcConfig = await loadAgentrcConfig(repoPath);
|
|
10747
|
+
if (agentrcConfig?.policies?.length) {
|
|
10748
|
+
policySources = agentrcConfig.policies;
|
|
10749
|
+
isConfigSourced = true;
|
|
9685
10750
|
}
|
|
9686
10751
|
}
|
|
9687
|
-
|
|
9688
|
-
|
|
9689
|
-
|
|
9690
|
-
|
|
9691
|
-
|
|
9692
|
-
|
|
9693
|
-
|
|
9694
|
-
|
|
9695
|
-
|
|
9696
|
-
|
|
9697
|
-
}
|
|
9698
|
-
|
|
9699
|
-
|
|
9700
|
-
|
|
9701
|
-
|
|
9702
|
-
|
|
9703
|
-
|
|
9704
|
-
|
|
9705
|
-
|
|
9706
|
-
|
|
9707
|
-
|
|
10752
|
+
const baseCriteria = buildCriteria();
|
|
10753
|
+
const baseExtras = buildExtras();
|
|
10754
|
+
let resolvedCriteria;
|
|
10755
|
+
let resolvedExtras;
|
|
10756
|
+
let passRateThreshold = 0.8;
|
|
10757
|
+
let policyInfo;
|
|
10758
|
+
if (policySources?.length) {
|
|
10759
|
+
const policyConfigs = [];
|
|
10760
|
+
let hasNativePlugin = false;
|
|
10761
|
+
for (const source of policySources) {
|
|
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 };
|
|
10781
|
+
}
|
|
10782
|
+
} else {
|
|
10783
|
+
resolvedCriteria = baseCriteria;
|
|
10784
|
+
resolvedExtras = baseExtras;
|
|
9708
10785
|
}
|
|
9709
|
-
const
|
|
9710
|
-
|
|
9711
|
-
|
|
9712
|
-
|
|
9713
|
-
|
|
9714
|
-
|
|
10786
|
+
const criteriaResults = [];
|
|
10787
|
+
for (const criterion of resolvedCriteria) {
|
|
10788
|
+
if (criterion.scope === "repo") {
|
|
10789
|
+
const result = await criterion.check(context);
|
|
10790
|
+
criteriaResults.push({
|
|
10791
|
+
id: criterion.id,
|
|
10792
|
+
title: criterion.title,
|
|
10793
|
+
pillar: criterion.pillar,
|
|
10794
|
+
level: criterion.level,
|
|
10795
|
+
scope: criterion.scope,
|
|
10796
|
+
impact: criterion.impact,
|
|
10797
|
+
effort: criterion.effort,
|
|
10798
|
+
status: result.status,
|
|
10799
|
+
reason: result.reason,
|
|
10800
|
+
evidence: result.evidence
|
|
10801
|
+
});
|
|
10802
|
+
continue;
|
|
10803
|
+
}
|
|
10804
|
+
if (criterion.scope === "area") {
|
|
10805
|
+
if (!options.perArea) continue;
|
|
10806
|
+
const areas2 = analysis.areas ?? [];
|
|
10807
|
+
if (areas2.length === 0) continue;
|
|
10808
|
+
criteriaResults.push({
|
|
10809
|
+
id: criterion.id,
|
|
10810
|
+
title: criterion.title,
|
|
10811
|
+
pillar: criterion.pillar,
|
|
10812
|
+
level: criterion.level,
|
|
10813
|
+
scope: criterion.scope,
|
|
10814
|
+
impact: criterion.impact,
|
|
10815
|
+
effort: criterion.effort,
|
|
10816
|
+
status: "skip",
|
|
10817
|
+
reason: "Run with --per-area for area breakdown."
|
|
10818
|
+
});
|
|
10819
|
+
continue;
|
|
10820
|
+
}
|
|
10821
|
+
const appResults = await Promise.all(
|
|
10822
|
+
apps.map(async (app) => ({
|
|
10823
|
+
app,
|
|
10824
|
+
result: await criterion.check(context, app)
|
|
10825
|
+
}))
|
|
10826
|
+
);
|
|
10827
|
+
if (!appResults.length) {
|
|
10828
|
+
criteriaResults.push({
|
|
10829
|
+
id: criterion.id,
|
|
10830
|
+
title: criterion.title,
|
|
10831
|
+
pillar: criterion.pillar,
|
|
10832
|
+
level: criterion.level,
|
|
10833
|
+
scope: criterion.scope,
|
|
10834
|
+
impact: criterion.impact,
|
|
10835
|
+
effort: criterion.effort,
|
|
10836
|
+
status: "skip",
|
|
10837
|
+
reason: "No application packages detected."
|
|
10838
|
+
});
|
|
10839
|
+
continue;
|
|
10840
|
+
}
|
|
10841
|
+
const passed = appResults.filter((entry) => entry.result.status === "pass").length;
|
|
10842
|
+
const total = appResults.length;
|
|
10843
|
+
const passRate = total ? passed / total : 0;
|
|
10844
|
+
const status = passRate >= passRateThreshold ? "pass" : "fail";
|
|
10845
|
+
const failures = appResults.filter((entry) => entry.result.status !== "pass").map((entry) => entry.app.name);
|
|
10846
|
+
criteriaResults.push({
|
|
10847
|
+
id: criterion.id,
|
|
10848
|
+
title: criterion.title,
|
|
10849
|
+
pillar: criterion.pillar,
|
|
10850
|
+
level: criterion.level,
|
|
10851
|
+
scope: criterion.scope,
|
|
10852
|
+
impact: criterion.impact,
|
|
10853
|
+
effort: criterion.effort,
|
|
10854
|
+
status,
|
|
10855
|
+
reason: status === "pass" ? void 0 : `Only ${passed}/${total} apps pass this check.`,
|
|
10856
|
+
passRate,
|
|
10857
|
+
appSummary: { passed, total },
|
|
10858
|
+
appFailures: failures
|
|
10859
|
+
});
|
|
9715
10860
|
}
|
|
9716
|
-
|
|
9717
|
-
|
|
9718
|
-
|
|
9719
|
-
|
|
9720
|
-
|
|
9721
|
-
|
|
9722
|
-
|
|
9723
|
-
|
|
9724
|
-
|
|
9725
|
-
|
|
10861
|
+
let areaReports;
|
|
10862
|
+
const areas = analysis.areas ?? [];
|
|
10863
|
+
if (options.perArea && areas.length > 0) {
|
|
10864
|
+
const areaCriteria = resolvedCriteria.filter((c) => c.scope === "area");
|
|
10865
|
+
areaReports = [];
|
|
10866
|
+
for (const area of areas) {
|
|
10867
|
+
if (!area.path) continue;
|
|
10868
|
+
const areaFiles = await safeReadDir(area.path);
|
|
10869
|
+
const areaContext = {
|
|
10870
|
+
...context,
|
|
10871
|
+
areaPath: area.path,
|
|
10872
|
+
areaFiles
|
|
10873
|
+
};
|
|
10874
|
+
const areaResults = [];
|
|
10875
|
+
for (const criterion of areaCriteria) {
|
|
10876
|
+
const result = await criterion.check(areaContext, void 0, area);
|
|
10877
|
+
areaResults.push({
|
|
10878
|
+
id: criterion.id,
|
|
10879
|
+
title: criterion.title,
|
|
10880
|
+
pillar: criterion.pillar,
|
|
10881
|
+
level: criterion.level,
|
|
10882
|
+
scope: criterion.scope,
|
|
10883
|
+
impact: criterion.impact,
|
|
10884
|
+
effort: criterion.effort,
|
|
10885
|
+
status: result.status,
|
|
10886
|
+
reason: result.reason,
|
|
10887
|
+
evidence: result.evidence
|
|
10888
|
+
});
|
|
10889
|
+
}
|
|
10890
|
+
const areaPillars = summarizePillars(areaResults);
|
|
10891
|
+
areaReports.push({ area, criteria: areaResults, pillars: areaPillars });
|
|
9726
10892
|
}
|
|
9727
|
-
|
|
9728
|
-
|
|
9729
|
-
|
|
9730
|
-
|
|
9731
|
-
|
|
9732
|
-
|
|
9733
|
-
|
|
9734
|
-
|
|
9735
|
-
|
|
9736
|
-
|
|
9737
|
-
|
|
10893
|
+
for (const criterion of criteriaResults) {
|
|
10894
|
+
if (criterion.scope !== "area") continue;
|
|
10895
|
+
const perAreaResults = areaReports.map((ar) => ar.criteria.find((c) => c.id === criterion.id)).filter(Boolean);
|
|
10896
|
+
if (!perAreaResults.length) continue;
|
|
10897
|
+
const passed = perAreaResults.filter((r) => r.status === "pass").length;
|
|
10898
|
+
const total = perAreaResults.length;
|
|
10899
|
+
const passRate = total ? passed / total : 0;
|
|
10900
|
+
criterion.status = passRate >= passRateThreshold ? "pass" : "fail";
|
|
10901
|
+
criterion.reason = criterion.status === "pass" ? void 0 : `Only ${passed}/${total} areas pass this check.`;
|
|
10902
|
+
criterion.passRate = passRate;
|
|
10903
|
+
criterion.areaSummary = { passed, total };
|
|
10904
|
+
criterion.areaFailures = areaReports.filter((ar) => ar.criteria.find((c) => c.id === criterion.id)?.status !== "pass").map((ar) => ar.area.name);
|
|
9738
10905
|
}
|
|
9739
10906
|
}
|
|
9740
|
-
|
|
9741
|
-
|
|
9742
|
-
|
|
9743
|
-
|
|
9744
|
-
|
|
10907
|
+
const pillars = summarizePillars(criteriaResults);
|
|
10908
|
+
const levels = summarizeLevels(criteriaResults, passRateThreshold);
|
|
10909
|
+
const achievedLevel = levels.filter((level) => level.achieved).reduce((acc, level) => Math.max(acc, level.level), 0);
|
|
10910
|
+
const extras = options.includeExtras === false ? [] : await runExtras(context, resolvedExtras);
|
|
10911
|
+
let engine;
|
|
10912
|
+
if (options.shadow) {
|
|
10913
|
+
const policyCtx = {
|
|
10914
|
+
repoPath,
|
|
10915
|
+
rootFiles,
|
|
10916
|
+
rootPackageJson,
|
|
10917
|
+
cache: /* @__PURE__ */ new Map(),
|
|
10918
|
+
analysis,
|
|
10919
|
+
apps
|
|
10920
|
+
};
|
|
10921
|
+
const engineChain = await loadPluginChain(policySources ?? [], { jsonOnly: isConfigSourced });
|
|
10922
|
+
const engineReport = await executePlugins(engineChain.plugins, policyCtx, engineChain.options);
|
|
10923
|
+
engine = {
|
|
10924
|
+
signals: engineReport.signals,
|
|
10925
|
+
recommendations: engineReport.recommendations,
|
|
10926
|
+
policyWarnings: engineReport.policyWarnings,
|
|
10927
|
+
score: engineReport.score,
|
|
10928
|
+
grade: engineReport.grade
|
|
10929
|
+
};
|
|
9745
10930
|
}
|
|
9746
10931
|
return {
|
|
9747
|
-
|
|
9748
|
-
|
|
9749
|
-
|
|
10932
|
+
repoPath,
|
|
10933
|
+
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
10934
|
+
isMonorepo: analysis.isMonorepo ?? false,
|
|
10935
|
+
apps: apps.map((app) => ({ name: app.name, path: app.path })),
|
|
10936
|
+
pillars,
|
|
10937
|
+
levels,
|
|
10938
|
+
achievedLevel,
|
|
10939
|
+
criteria: criteriaResults,
|
|
10940
|
+
extras,
|
|
10941
|
+
areaReports,
|
|
10942
|
+
policies: policyInfo,
|
|
10943
|
+
engine
|
|
9750
10944
|
};
|
|
9751
10945
|
}
|
|
9752
|
-
async function hasMcpConfig(repoPath) {
|
|
9753
|
-
const found = [];
|
|
9754
|
-
if (await fileExists(path9.join(repoPath, ".vscode", "mcp.json"))) {
|
|
9755
|
-
found.push(".vscode/mcp.json");
|
|
9756
|
-
}
|
|
9757
|
-
if (await fileExists(path9.join(repoPath, "mcp.json"))) {
|
|
9758
|
-
found.push("mcp.json");
|
|
9759
|
-
}
|
|
9760
|
-
const settings = await readJson(path9.join(repoPath, ".vscode", "settings.json"));
|
|
9761
|
-
if (settings && (settings["mcp"] || settings["github.copilot.chat.mcp.enabled"])) {
|
|
9762
|
-
found.push(".vscode/settings.json (mcp section)");
|
|
9763
|
-
}
|
|
9764
|
-
if (await fileExists(path9.join(repoPath, ".claude", "mcp.json"))) {
|
|
9765
|
-
found.push(".claude/mcp.json");
|
|
9766
|
-
}
|
|
9767
|
-
return found;
|
|
9768
|
-
}
|
|
9769
|
-
async function hasCustomAgents(repoPath) {
|
|
9770
|
-
const found = [];
|
|
9771
|
-
const agentDirs = [".github/agents", ".copilot/agents", ".github/copilot/agents"];
|
|
9772
|
-
for (const dir of agentDirs) {
|
|
9773
|
-
if (await fileExists(path9.join(repoPath, dir))) {
|
|
9774
|
-
found.push(dir);
|
|
9775
|
-
}
|
|
9776
|
-
}
|
|
9777
|
-
const agentFiles = [".github/copilot-agents.yml", ".github/copilot-agents.yaml"];
|
|
9778
|
-
for (const agentFile of agentFiles) {
|
|
9779
|
-
if (await fileExists(path9.join(repoPath, agentFile))) {
|
|
9780
|
-
found.push(agentFile);
|
|
9781
|
-
}
|
|
9782
|
-
}
|
|
9783
|
-
return found;
|
|
9784
|
-
}
|
|
9785
|
-
async function hasCopilotSkills(repoPath) {
|
|
9786
|
-
const found = [];
|
|
9787
|
-
const skillDirs = [
|
|
9788
|
-
".copilot/skills",
|
|
9789
|
-
".github/skills",
|
|
9790
|
-
".claude/skills",
|
|
9791
|
-
".github/copilot/skills"
|
|
9792
|
-
];
|
|
9793
|
-
for (const dir of skillDirs) {
|
|
9794
|
-
if (await fileExists(path9.join(repoPath, dir))) {
|
|
9795
|
-
found.push(dir);
|
|
9796
|
-
}
|
|
9797
|
-
}
|
|
9798
|
-
return found;
|
|
9799
|
-
}
|
|
9800
|
-
async function readAllDependencies(context) {
|
|
9801
|
-
const dependencies = [];
|
|
9802
|
-
const apps = context.apps.length ? context.apps : [];
|
|
9803
|
-
for (const app of apps) {
|
|
9804
|
-
if (!app.packageJsonPath) continue;
|
|
9805
|
-
const pkg = await readJson(app.packageJsonPath);
|
|
9806
|
-
const deps = pkg?.dependencies ?? {};
|
|
9807
|
-
const devDeps = pkg?.devDependencies ?? {};
|
|
9808
|
-
dependencies.push(
|
|
9809
|
-
...Object.keys({
|
|
9810
|
-
...deps,
|
|
9811
|
-
...devDeps
|
|
9812
|
-
})
|
|
9813
|
-
);
|
|
9814
|
-
}
|
|
9815
|
-
if (!apps.length && context.rootPackageJson) {
|
|
9816
|
-
const rootDeps = context.rootPackageJson.dependencies ?? {};
|
|
9817
|
-
const rootDevDeps = context.rootPackageJson.devDependencies ?? {};
|
|
9818
|
-
dependencies.push(
|
|
9819
|
-
...Object.keys({
|
|
9820
|
-
...rootDeps,
|
|
9821
|
-
...rootDevDeps
|
|
9822
|
-
})
|
|
9823
|
-
);
|
|
9824
|
-
}
|
|
9825
|
-
return Array.from(new Set(dependencies));
|
|
9826
|
-
}
|
|
9827
10946
|
|
|
9828
10947
|
// packages/core/src/services/batch.ts
|
|
9829
10948
|
function sanitizeError(raw) {
|
|
@@ -9844,7 +10963,7 @@ async function processRepo(params) {
|
|
|
9844
10963
|
} = params;
|
|
9845
10964
|
try {
|
|
9846
10965
|
progress?.update(`${label}: Cloning...`);
|
|
9847
|
-
const cacheRoot =
|
|
10966
|
+
const cacheRoot = path13.join(process.cwd(), ".agentrc-cache");
|
|
9848
10967
|
const repoPath = validateCachePath(cacheRoot, ...cacheParts);
|
|
9849
10968
|
await ensureDir(repoPath);
|
|
9850
10969
|
if (!await isGitRepo(repoPath)) {
|
|
@@ -9870,8 +10989,8 @@ async function processRepo(params) {
|
|
|
9870
10989
|
if (!instructions.trim()) {
|
|
9871
10990
|
throw new Error("Generated instructions were empty");
|
|
9872
10991
|
}
|
|
9873
|
-
const instructionsPath =
|
|
9874
|
-
await ensureDir(
|
|
10992
|
+
const instructionsPath = path13.join(repoPath, ".github", "copilot-instructions.md");
|
|
10993
|
+
await ensureDir(path13.dirname(instructionsPath));
|
|
9875
10994
|
const { wrote, reason } = await safeWriteFile(instructionsPath, instructions, true);
|
|
9876
10995
|
if (!wrote) {
|
|
9877
10996
|
throw new Error(
|
|
@@ -10008,7 +11127,7 @@ async function processBatchReadinessRepo(options) {
|
|
|
10008
11127
|
try {
|
|
10009
11128
|
progress(`Cloning ${repo.fullName}...`);
|
|
10010
11129
|
const authedUrl = buildAuthedUrl(repo.cloneUrl, token, "github");
|
|
10011
|
-
await ensureDir(
|
|
11130
|
+
await ensureDir(path13.dirname(repoDir));
|
|
10012
11131
|
await cloneRepo(authedUrl, repoDir, { shallow: true });
|
|
10013
11132
|
await setRemoteUrl(repoDir, repo.cloneUrl).catch(() => {
|
|
10014
11133
|
});
|
|
@@ -11058,7 +12177,7 @@ import { render as render2 } from "ink";
|
|
|
11058
12177
|
// src/ui/BatchReadinessTui.tsx
|
|
11059
12178
|
import fs8 from "fs/promises";
|
|
11060
12179
|
import os from "os";
|
|
11061
|
-
import
|
|
12180
|
+
import path14 from "path";
|
|
11062
12181
|
|
|
11063
12182
|
// packages/core/src/services/visualReport.ts
|
|
11064
12183
|
function generateVisualReport(options) {
|
|
@@ -12084,7 +13203,7 @@ function BatchReadinessTui({ token, outputPath, policies }) {
|
|
|
12084
13203
|
setStatus("processing");
|
|
12085
13204
|
const selectedRepos = Array.from(selectedRepoIndices).map((i) => repos[i]);
|
|
12086
13205
|
const results2 = [];
|
|
12087
|
-
const tmpDir =
|
|
13206
|
+
const tmpDir = path14.join(os.tmpdir(), `agentrc-batch-readiness-${Date.now()}`);
|
|
12088
13207
|
try {
|
|
12089
13208
|
await ensureDir(tmpDir);
|
|
12090
13209
|
for (let i = 0; i < selectedRepos.length; i++) {
|
|
@@ -12121,7 +13240,7 @@ function BatchReadinessTui({ token, outputPath, policies }) {
|
|
|
12121
13240
|
title: "Batch Readiness Report",
|
|
12122
13241
|
generatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
12123
13242
|
});
|
|
12124
|
-
const finalOutputPath = outputPath ??
|
|
13243
|
+
const finalOutputPath = outputPath ?? path14.join(process.cwd(), "batch-readiness-report.html");
|
|
12125
13244
|
const { wrote, reason } = await safeWriteFile(finalOutputPath, html, true);
|
|
12126
13245
|
if (!wrote) throw new Error(reason === "symlink" ? "Path is a symlink" : "Write failed");
|
|
12127
13246
|
setStatus("complete");
|
|
@@ -12303,7 +13422,7 @@ async function batchReadinessCommand(options) {
|
|
|
12303
13422
|
}
|
|
12304
13423
|
|
|
12305
13424
|
// src/commands/eval.ts
|
|
12306
|
-
import
|
|
13425
|
+
import path16 from "path";
|
|
12307
13426
|
|
|
12308
13427
|
// packages/core/src/services/evalScaffold.ts
|
|
12309
13428
|
var EVAL_SCAFFOLD_TIMEOUT_MS = 6e5;
|
|
@@ -12325,7 +13444,7 @@ async function generateEvalScaffold(options) {
|
|
|
12325
13444
|
streaming: true,
|
|
12326
13445
|
workingDirectory: repoPath,
|
|
12327
13446
|
systemMessage: {
|
|
12328
|
-
content: "
|
|
13447
|
+
content: "Generate challenging implementation planning tasks for this repository. Each task should require cross-cutting changes across multiple files. Tasks can range from specific feature additions to broader refactoring plans. Avoid trivial tasks or pure Q&A questions. Output ONLY JSON with keys: instructionFile, cases (array of {id,prompt,expectation})."
|
|
12329
13448
|
},
|
|
12330
13449
|
infiniteSessions: { enabled: false }
|
|
12331
13450
|
});
|
|
@@ -12367,32 +13486,37 @@ async function generateEvalScaffold(options) {
|
|
|
12367
13486
|
'For areas with a workspace (workingDirectory), include a "workingDirectory" field set to that workspace path so evals run scoped to the correct folder.'
|
|
12368
13487
|
].join("\n") : "";
|
|
12369
13488
|
const prompt = [
|
|
12370
|
-
`Analyze this repository and generate ${count}
|
|
13489
|
+
`Analyze this repository and generate ${count} implementation planning tasks.`,
|
|
13490
|
+
"",
|
|
13491
|
+
"Each task should represent a REAL developer request \u2014 the kind of thing someone would actually type into a coding agent.",
|
|
13492
|
+
"Tasks should require understanding MULTIPLE files and cross-cutting concerns.",
|
|
12371
13493
|
"",
|
|
12372
|
-
"
|
|
12373
|
-
"
|
|
12374
|
-
"Do NOT
|
|
13494
|
+
"PROMPT RULES (the prompt field is what the eval agent receives):",
|
|
13495
|
+
"- Write prompts as a developer would naturally phrase them \u2014 short, direct requests.",
|
|
13496
|
+
"- Do NOT describe expected output format or what the response should include.",
|
|
13497
|
+
"- Do NOT add meta-instructions like 'The output should show...' or 'Include in your plan...' or 'Your plan should cover...'",
|
|
13498
|
+
"- Do NOT embed implementation details in the prompt (pillar names, levels, specific output formats) \u2014 those belong in the expectation.",
|
|
13499
|
+
"- Good: 'Add a --dry-run flag to the generate command'",
|
|
13500
|
+
"- Good: 'Add a readiness criterion for CI/CD detection'",
|
|
13501
|
+
"- Bad: 'Add a --dry-run flag that previews what files would be created or modified. The output should show file paths and indicate whether each would be created, updated, or skipped.'",
|
|
13502
|
+
"- Bad: 'Add a readiness criterion that checks for CI/CD and classifies it under a new deployment pillar at level 3'",
|
|
12375
13503
|
"",
|
|
12376
|
-
"
|
|
12377
|
-
"-
|
|
12378
|
-
"-
|
|
12379
|
-
"-
|
|
12380
|
-
"-
|
|
12381
|
-
"-
|
|
12382
|
-
"- Questions that require understanding the type system, generics, or shared interfaces across module boundaries",
|
|
13504
|
+
"EXPECTATION RULES (the expectation field is checked by an LLM judge \u2014 be extremely specific):",
|
|
13505
|
+
"- MUST cite exact file paths (e.g., 'packages/core/src/services/generator.ts')",
|
|
13506
|
+
"- MUST cite exact function and type names (e.g., 'generateCopilotInstructions()', 'CommandResult<T>')",
|
|
13507
|
+
"- MUST cite specific CLI commands for verification (e.g., 'npm run typecheck', 'npm test')",
|
|
13508
|
+
"- MUST name the specific test file to update (e.g., 'src/services/__tests__/generator.test.ts')",
|
|
13509
|
+
"- Generic expectations like 'identify the generator service' are USELESS \u2014 name the actual function and file.",
|
|
12383
13510
|
"",
|
|
12384
|
-
"Bad
|
|
12385
|
-
"- 'What does this project do?' (
|
|
12386
|
-
"- '
|
|
12387
|
-
"-
|
|
12388
|
-
"- Any question answerable by reading one file or searching for one keyword",
|
|
13511
|
+
"Bad task examples (avoid these):",
|
|
13512
|
+
"- 'What does this project do?' (pure Q&A, not a planning task)",
|
|
13513
|
+
"- 'Explain the architecture' (no implementation expected)",
|
|
13514
|
+
"- Tasks with prescriptive output instructions baked into the prompt",
|
|
12389
13515
|
"",
|
|
12390
|
-
"
|
|
12391
|
-
"If this is a monorepo
|
|
12392
|
-
"Ensure cases cover cross-cutting concerns: data flow, error propagation, configuration impact, implicit coupling, architectural invariants.",
|
|
12393
|
-
"Include a systemMessage that keeps answers scoped to this repository (avoid generic Copilot CLI details unless asked).",
|
|
13516
|
+
"Do NOT generate a systemMessage \u2014 the default is used automatically.",
|
|
13517
|
+
"If this is a monorepo, generate tasks that involve cross-app dependencies and shared libraries.",
|
|
12394
13518
|
"Return JSON ONLY (no markdown, no commentary) in this schema:",
|
|
12395
|
-
'{\n "instructionFile": ".github/copilot-instructions.md",\n "
|
|
13519
|
+
options.areas?.length ? '{\n "instructionFile": ".github/copilot-instructions.md",\n "cases": [\n {"id": "case-1", "prompt": "...", "expectation": "...", "area": "optional-area-name"}\n ]\n}' : '{\n "instructionFile": ".github/copilot-instructions.md",\n "cases": [\n {"id": "case-1", "prompt": "...", "expectation": "..."}\n ]\n}',
|
|
12396
13520
|
areaContext
|
|
12397
13521
|
].join("\n");
|
|
12398
13522
|
progress("Analyzing codebase...");
|
|
@@ -12438,7 +13562,8 @@ async function generateEvalScaffold(options) {
|
|
|
12438
13562
|
}
|
|
12439
13563
|
throw error;
|
|
12440
13564
|
}
|
|
12441
|
-
const
|
|
13565
|
+
const hasAreas = Boolean(options.areas?.length);
|
|
13566
|
+
const normalized = normalizeEvalConfig(parsed, count, hasAreas);
|
|
12442
13567
|
return normalized;
|
|
12443
13568
|
} finally {
|
|
12444
13569
|
await client.stop();
|
|
@@ -12462,41 +13587,47 @@ function parseEvalConfig(raw) {
|
|
|
12462
13587
|
}
|
|
12463
13588
|
return parsed;
|
|
12464
13589
|
}
|
|
12465
|
-
function normalizeEvalConfig(parsed, count) {
|
|
13590
|
+
function normalizeEvalConfig(parsed, count, hasAreas = true) {
|
|
12466
13591
|
const cases = (parsed.cases ?? []).slice(0, count).map((entry, index) => {
|
|
12467
13592
|
const id = typeof entry.id === "string" && entry.id.trim() ? entry.id : `case-${index + 1}`;
|
|
12468
13593
|
return {
|
|
12469
13594
|
id,
|
|
12470
13595
|
prompt: String(entry.prompt ?? "").trim(),
|
|
12471
|
-
expectation:
|
|
12472
|
-
|
|
13596
|
+
expectation: normalizeExpectation(entry.expectation),
|
|
13597
|
+
...hasAreas && typeof entry.area === "string" && entry.area.trim() ? { area: entry.area.trim() } : {},
|
|
12473
13598
|
workingDirectory: typeof entry.workingDirectory === "string" && entry.workingDirectory.trim() ? entry.workingDirectory.trim() : void 0
|
|
12474
13599
|
};
|
|
12475
13600
|
});
|
|
12476
13601
|
if (!cases.length) {
|
|
12477
13602
|
throw new Error("Eval scaffold JSON did not include any usable cases.");
|
|
12478
13603
|
}
|
|
12479
|
-
const defaultSystemMessage = "You are answering questions about this repository. Use tools to inspect the repo and cite its files. Avoid generic Copilot CLI details unless the prompt explicitly asks for them.";
|
|
12480
13604
|
return {
|
|
12481
13605
|
instructionFile: parsed.instructionFile ?? ".github/copilot-instructions.md",
|
|
12482
|
-
systemMessage: parsed.systemMessage
|
|
13606
|
+
...parsed.systemMessage ? { systemMessage: parsed.systemMessage } : {},
|
|
12483
13607
|
cases
|
|
12484
13608
|
};
|
|
12485
13609
|
}
|
|
13610
|
+
function normalizeExpectation(value) {
|
|
13611
|
+
if (Array.isArray(value)) {
|
|
13612
|
+
const items = value.map((s) => String(s).trim()).filter(Boolean);
|
|
13613
|
+
return items.length === 1 ? items[0] : items;
|
|
13614
|
+
}
|
|
13615
|
+
return String(value ?? "").trim();
|
|
13616
|
+
}
|
|
12486
13617
|
|
|
12487
13618
|
// packages/core/src/services/evaluator.ts
|
|
12488
13619
|
import fs9 from "fs/promises";
|
|
12489
|
-
import
|
|
12490
|
-
var DEFAULT_SYSTEM_MESSAGE = "
|
|
13620
|
+
import path15 from "path";
|
|
13621
|
+
var DEFAULT_SYSTEM_MESSAGE = "Research using read-only tools and make a plan for the given task, including concrete implementation steps and verification steps.";
|
|
12491
13622
|
async function runEval(options) {
|
|
12492
13623
|
const config = await loadConfig(options.configPath);
|
|
12493
13624
|
const instructionFile = config.instructionFile ?? ".github/copilot-instructions.md";
|
|
12494
|
-
const instructionPath =
|
|
13625
|
+
const instructionPath = path15.resolve(options.repoPath, instructionFile);
|
|
12495
13626
|
const instructionText = await readOptionalFile(instructionPath);
|
|
12496
13627
|
const baseSystemMessage = config.systemMessage ?? DEFAULT_SYSTEM_MESSAGE;
|
|
12497
13628
|
const progress = options.onProgress ?? (() => {
|
|
12498
13629
|
});
|
|
12499
|
-
const defaultOutputPath =
|
|
13630
|
+
const defaultOutputPath = path15.resolve(
|
|
12500
13631
|
options.repoPath,
|
|
12501
13632
|
".agentrc",
|
|
12502
13633
|
"evals",
|
|
@@ -12516,9 +13647,9 @@ async function runEval(options) {
|
|
|
12516
13647
|
const caseStartedAt = Date.now();
|
|
12517
13648
|
let caseWorkingDir;
|
|
12518
13649
|
if (testCase.workingDirectory) {
|
|
12519
|
-
const resolved =
|
|
12520
|
-
const root =
|
|
12521
|
-
if (resolved !== root && !resolved.startsWith(root +
|
|
13650
|
+
const resolved = path15.resolve(options.repoPath, testCase.workingDirectory);
|
|
13651
|
+
const root = path15.resolve(options.repoPath);
|
|
13652
|
+
if (resolved !== root && !resolved.startsWith(root + path15.sep)) {
|
|
12522
13653
|
throw new Error(
|
|
12523
13654
|
`Invalid workingDirectory "${testCase.workingDirectory}": escapes repo boundary`
|
|
12524
13655
|
);
|
|
@@ -12590,7 +13721,7 @@ async function runEval(options) {
|
|
|
12590
13721
|
};
|
|
12591
13722
|
let viewerPath;
|
|
12592
13723
|
if (outputPath) {
|
|
12593
|
-
await fs9.mkdir(
|
|
13724
|
+
await fs9.mkdir(path15.dirname(outputPath), { recursive: true });
|
|
12594
13725
|
await safeWriteFile(outputPath, JSON.stringify(output, null, 2), true);
|
|
12595
13726
|
viewerPath = buildViewerPath(outputPath);
|
|
12596
13727
|
await safeWriteFile(viewerPath, buildTrajectoryViewerHtml(output), true);
|
|
@@ -12651,10 +13782,11 @@ async function judge(client, options) {
|
|
|
12651
13782
|
if (delta) content += delta;
|
|
12652
13783
|
}
|
|
12653
13784
|
});
|
|
13785
|
+
const expectationText = Array.isArray(options.expectation) ? options.expectation.join("\n") : options.expectation;
|
|
12654
13786
|
const prompt = [
|
|
12655
13787
|
"Evaluate which response best matches the expectation.",
|
|
12656
13788
|
"",
|
|
12657
|
-
`Expectation: ${
|
|
13789
|
+
`Expectation: ${expectationText}`,
|
|
12658
13790
|
"",
|
|
12659
13791
|
"Response A (without custom instructions):",
|
|
12660
13792
|
options.withoutInstructions,
|
|
@@ -12698,7 +13830,7 @@ function parseJudge(content) {
|
|
|
12698
13830
|
}
|
|
12699
13831
|
async function loadConfig(configPath) {
|
|
12700
13832
|
const raw = await fs9.readFile(configPath, "utf8");
|
|
12701
|
-
const parsed = JSON.parse(raw);
|
|
13833
|
+
const parsed = JSON.parse(stripJsonComments(raw));
|
|
12702
13834
|
if (!parsed || !Array.isArray(parsed.cases)) {
|
|
12703
13835
|
throw new Error("Eval config must have a 'cases' array.");
|
|
12704
13836
|
}
|
|
@@ -12904,7 +14036,7 @@ function formatTokenUsage(usage) {
|
|
|
12904
14036
|
function resolveOutputPath(repoPath, override, configValue) {
|
|
12905
14037
|
const chosen = override ?? configValue;
|
|
12906
14038
|
if (!chosen) return void 0;
|
|
12907
|
-
return
|
|
14039
|
+
return path15.isAbsolute(chosen) ? chosen : path15.resolve(repoPath, chosen);
|
|
12908
14040
|
}
|
|
12909
14041
|
function buildViewerPath(outputPath) {
|
|
12910
14042
|
if (outputPath.endsWith(".json")) {
|
|
@@ -13259,7 +14391,7 @@ function sanitizeValue(value, depth) {
|
|
|
13259
14391
|
|
|
13260
14392
|
// src/commands/eval.ts
|
|
13261
14393
|
async function evalCommand(configPathArg, options) {
|
|
13262
|
-
const repoPath =
|
|
14394
|
+
const repoPath = path16.resolve(options.repo ?? process.cwd());
|
|
13263
14395
|
if (options.listModels) {
|
|
13264
14396
|
try {
|
|
13265
14397
|
const models = await listCopilotModels();
|
|
@@ -13295,7 +14427,7 @@ async function evalCommand(configPathArg, options) {
|
|
|
13295
14427
|
return;
|
|
13296
14428
|
}
|
|
13297
14429
|
if (options.init) {
|
|
13298
|
-
const outputPath =
|
|
14430
|
+
const outputPath = path16.join(repoPath, "agentrc.eval.json");
|
|
13299
14431
|
const desiredCount = Math.max(1, Number.parseInt(options.count ?? "5", 10) || 5);
|
|
13300
14432
|
try {
|
|
13301
14433
|
const progress = createProgressReporter(!shouldLog(options));
|
|
@@ -13337,7 +14469,7 @@ async function evalCommand(configPathArg, options) {
|
|
|
13337
14469
|
}
|
|
13338
14470
|
return;
|
|
13339
14471
|
}
|
|
13340
|
-
const configPath =
|
|
14472
|
+
const configPath = path16.resolve(configPathArg ?? path16.join(repoPath, "agentrc.eval.json"));
|
|
13341
14473
|
try {
|
|
13342
14474
|
const progress = createProgressReporter(!shouldLog(options));
|
|
13343
14475
|
const { summary, results, viewerPath } = await runEval({
|
|
@@ -13384,32 +14516,43 @@ async function evalCommand(configPathArg, options) {
|
|
|
13384
14516
|
}
|
|
13385
14517
|
|
|
13386
14518
|
// src/commands/generate.ts
|
|
13387
|
-
import
|
|
14519
|
+
import path19 from "path";
|
|
13388
14520
|
|
|
13389
14521
|
// packages/core/src/services/generator.ts
|
|
13390
|
-
import
|
|
14522
|
+
import path17 from "path";
|
|
14523
|
+
async function writeOrPreview(filePath, content, opts) {
|
|
14524
|
+
const relPath = path17.relative(process.cwd(), filePath);
|
|
14525
|
+
if (opts.dryRun) {
|
|
14526
|
+
const wouldWrite = await canSafeWrite(filePath, opts.force);
|
|
14527
|
+
return {
|
|
14528
|
+
path: relPath,
|
|
14529
|
+
action: wouldWrite ? "wrote" : "skipped",
|
|
14530
|
+
bytes: Buffer.byteLength(content, "utf8")
|
|
14531
|
+
};
|
|
14532
|
+
}
|
|
14533
|
+
await ensureDir(path17.dirname(filePath));
|
|
14534
|
+
const { wrote } = await safeWriteFile(filePath, content, opts.force);
|
|
14535
|
+
return { path: relPath, action: wrote ? "wrote" : "skipped" };
|
|
14536
|
+
}
|
|
13391
14537
|
async function generateConfigs(options) {
|
|
13392
|
-
const { repoPath, analysis, selections, force } = options;
|
|
14538
|
+
const { repoPath, analysis, selections, force, dryRun } = options;
|
|
13393
14539
|
const files = [];
|
|
13394
14540
|
if (selections.includes("mcp")) {
|
|
13395
|
-
|
|
13396
|
-
|
|
13397
|
-
|
|
13398
|
-
|
|
13399
|
-
|
|
13400
|
-
|
|
13401
|
-
action: wrote ? "wrote" : "skipped"
|
|
13402
|
-
});
|
|
14541
|
+
files.push(
|
|
14542
|
+
await writeOrPreview(path17.join(repoPath, ".vscode", "mcp.json"), renderMcp(), {
|
|
14543
|
+
dryRun,
|
|
14544
|
+
force
|
|
14545
|
+
})
|
|
14546
|
+
);
|
|
13403
14547
|
}
|
|
13404
14548
|
if (selections.includes("vscode")) {
|
|
13405
|
-
|
|
13406
|
-
|
|
13407
|
-
|
|
13408
|
-
|
|
13409
|
-
|
|
13410
|
-
|
|
13411
|
-
|
|
13412
|
-
});
|
|
14549
|
+
files.push(
|
|
14550
|
+
await writeOrPreview(
|
|
14551
|
+
path17.join(repoPath, ".vscode", "settings.json"),
|
|
14552
|
+
renderVscodeSettings(analysis),
|
|
14553
|
+
{ dryRun, force }
|
|
14554
|
+
)
|
|
14555
|
+
);
|
|
13413
14556
|
}
|
|
13414
14557
|
return { files };
|
|
13415
14558
|
}
|
|
@@ -13458,16 +14601,16 @@ function renderVscodeSettings(analysis) {
|
|
|
13458
14601
|
}
|
|
13459
14602
|
|
|
13460
14603
|
// src/commands/instructions.ts
|
|
13461
|
-
import
|
|
14604
|
+
import path18 from "path";
|
|
13462
14605
|
function skipReason(action) {
|
|
13463
14606
|
if (action === "symlink") return "symlink";
|
|
13464
14607
|
if (action === "empty") return "empty content";
|
|
13465
14608
|
return "exists, use --force";
|
|
13466
14609
|
}
|
|
13467
14610
|
async function instructionsCommand(options) {
|
|
13468
|
-
const repoPath =
|
|
13469
|
-
const outputPath =
|
|
13470
|
-
options.output ??
|
|
14611
|
+
const repoPath = path18.resolve(options.repo ?? process.cwd());
|
|
14612
|
+
const outputPath = path18.resolve(
|
|
14613
|
+
options.output ?? path18.join(repoPath, ".github", "copilot-instructions.md")
|
|
13471
14614
|
);
|
|
13472
14615
|
const progress = createProgressReporter(!shouldLog(options));
|
|
13473
14616
|
const wantAreas = options.areas || options.areasOnly || options.area;
|
|
@@ -13514,7 +14657,7 @@ async function instructionsCommand(options) {
|
|
|
13514
14657
|
] : []
|
|
13515
14658
|
];
|
|
13516
14659
|
for (const file of dryFiles) {
|
|
13517
|
-
const relPath =
|
|
14660
|
+
const relPath = path18.relative(process.cwd(), path18.join(repoPath, file.path));
|
|
13518
14661
|
if (shouldLog(options)) {
|
|
13519
14662
|
progress.update(
|
|
13520
14663
|
`[dry-run] Would write ${relPath} (${Buffer.byteLength(file.content, "utf8")} bytes)`
|
|
@@ -13535,7 +14678,7 @@ async function instructionsCommand(options) {
|
|
|
13535
14678
|
} else {
|
|
13536
14679
|
const actions = await writeNestedInstructions(repoPath, nestedResult, options.force);
|
|
13537
14680
|
for (const action of actions) {
|
|
13538
|
-
const relPath =
|
|
14681
|
+
const relPath = path18.relative(process.cwd(), action.path);
|
|
13539
14682
|
if (action.action === "wrote") {
|
|
13540
14683
|
if (shouldLog(options)) progress.succeed(`Wrote ${relPath}`);
|
|
13541
14684
|
} else if (shouldLog(options)) {
|
|
@@ -13578,8 +14721,8 @@ async function instructionsCommand(options) {
|
|
|
13578
14721
|
}
|
|
13579
14722
|
if (content) {
|
|
13580
14723
|
if (options.dryRun) {
|
|
13581
|
-
const relPath =
|
|
13582
|
-
const displayPath =
|
|
14724
|
+
const relPath = path18.relative(repoPath, outputPath);
|
|
14725
|
+
const displayPath = path18.relative(process.cwd(), outputPath);
|
|
13583
14726
|
const byteCount = Buffer.byteLength(content, "utf8");
|
|
13584
14727
|
if (shouldLog(options)) {
|
|
13585
14728
|
progress.update(`[dry-run] Would write ${displayPath} (${byteCount} bytes)`);
|
|
@@ -13588,14 +14731,14 @@ async function instructionsCommand(options) {
|
|
|
13588
14731
|
dryRunFiles.push({ path: relPath, bytes: byteCount });
|
|
13589
14732
|
}
|
|
13590
14733
|
} else {
|
|
13591
|
-
await ensureDir(
|
|
14734
|
+
await ensureDir(path18.dirname(outputPath));
|
|
13592
14735
|
const { wrote, reason } = await safeWriteFile(
|
|
13593
14736
|
outputPath,
|
|
13594
14737
|
content,
|
|
13595
14738
|
Boolean(options.force)
|
|
13596
14739
|
);
|
|
13597
14740
|
if (!wrote) {
|
|
13598
|
-
const relPath =
|
|
14741
|
+
const relPath = path18.relative(process.cwd(), outputPath);
|
|
13599
14742
|
const why = reason === "symlink" ? "path is a symlink" : "file exists (use --force)";
|
|
13600
14743
|
if (options.json) {
|
|
13601
14744
|
const result = {
|
|
@@ -13617,7 +14760,7 @@ async function instructionsCommand(options) {
|
|
|
13617
14760
|
};
|
|
13618
14761
|
outputResult(result, true);
|
|
13619
14762
|
} else if (shouldLog(options)) {
|
|
13620
|
-
progress.succeed(`Updated ${
|
|
14763
|
+
progress.succeed(`Updated ${path18.relative(process.cwd(), outputPath)}`);
|
|
13621
14764
|
}
|
|
13622
14765
|
}
|
|
13623
14766
|
}
|
|
@@ -13684,7 +14827,7 @@ async function instructionsCommand(options) {
|
|
|
13684
14827
|
] : []
|
|
13685
14828
|
];
|
|
13686
14829
|
for (const file of dryFiles) {
|
|
13687
|
-
const relPath =
|
|
14830
|
+
const relPath = path18.relative(process.cwd(), path18.join(repoPath, file.path));
|
|
13688
14831
|
if (shouldLog(options)) {
|
|
13689
14832
|
progress.update(
|
|
13690
14833
|
`[dry-run] Would write ${relPath} (${Buffer.byteLength(file.content, "utf8")} bytes)`
|
|
@@ -13702,7 +14845,7 @@ async function instructionsCommand(options) {
|
|
|
13702
14845
|
} else {
|
|
13703
14846
|
const actions = await writeNestedInstructions(repoPath, nestedResult, options.force);
|
|
13704
14847
|
for (const action of actions) {
|
|
13705
|
-
const relPath =
|
|
14848
|
+
const relPath = path18.relative(process.cwd(), action.path);
|
|
13706
14849
|
if (action.action === "wrote") {
|
|
13707
14850
|
if (shouldLog(options)) progress.succeed(`Wrote ${relPath}`);
|
|
13708
14851
|
} else if (shouldLog(options)) {
|
|
@@ -13734,7 +14877,7 @@ async function instructionsCommand(options) {
|
|
|
13734
14877
|
}
|
|
13735
14878
|
if (options.json) {
|
|
13736
14879
|
dryRunFiles.push({
|
|
13737
|
-
path:
|
|
14880
|
+
path: path18.relative(repoPath, areaInstructionPath(repoPath, area)),
|
|
13738
14881
|
bytes: Buffer.byteLength(body, "utf8")
|
|
13739
14882
|
});
|
|
13740
14883
|
}
|
|
@@ -13755,7 +14898,7 @@ async function instructionsCommand(options) {
|
|
|
13755
14898
|
continue;
|
|
13756
14899
|
}
|
|
13757
14900
|
if (shouldLog(options)) {
|
|
13758
|
-
progress.succeed(`Wrote ${
|
|
14901
|
+
progress.succeed(`Wrote ${path18.relative(process.cwd(), result.filePath)}`);
|
|
13759
14902
|
}
|
|
13760
14903
|
}
|
|
13761
14904
|
}
|
|
@@ -13790,7 +14933,7 @@ async function instructionsCommand(options) {
|
|
|
13790
14933
|
|
|
13791
14934
|
// src/commands/generate.ts
|
|
13792
14935
|
async function generateCommand(type, repoPathArg, options) {
|
|
13793
|
-
const repoPath =
|
|
14936
|
+
const repoPath = path19.resolve(repoPathArg ?? process.cwd());
|
|
13794
14937
|
if (type === "instructions" || type === "agents") {
|
|
13795
14938
|
if (!options.quiet) {
|
|
13796
14939
|
process.stderr.write(
|
|
@@ -13804,7 +14947,7 @@ async function generateCommand(type, repoPathArg, options) {
|
|
|
13804
14947
|
`
|
|
13805
14948
|
);
|
|
13806
14949
|
}
|
|
13807
|
-
const output = type === "agents" ?
|
|
14950
|
+
const output = type === "agents" ? path19.join(repoPath, "AGENTS.md") : void 0;
|
|
13808
14951
|
await instructionsCommand({
|
|
13809
14952
|
repo: repoPath,
|
|
13810
14953
|
output,
|
|
@@ -13813,7 +14956,8 @@ async function generateCommand(type, repoPathArg, options) {
|
|
|
13813
14956
|
json: options.json,
|
|
13814
14957
|
quiet: options.quiet,
|
|
13815
14958
|
areas: options.perApp,
|
|
13816
|
-
strategy: options.strategy
|
|
14959
|
+
strategy: options.strategy,
|
|
14960
|
+
dryRun: options.dryRun
|
|
13817
14961
|
});
|
|
13818
14962
|
return;
|
|
13819
14963
|
}
|
|
@@ -13834,7 +14978,8 @@ async function generateCommand(type, repoPathArg, options) {
|
|
|
13834
14978
|
repoPath,
|
|
13835
14979
|
analysis,
|
|
13836
14980
|
selections,
|
|
13837
|
-
force: Boolean(options.force)
|
|
14981
|
+
force: Boolean(options.force),
|
|
14982
|
+
dryRun: Boolean(options.dryRun)
|
|
13838
14983
|
});
|
|
13839
14984
|
} catch (error) {
|
|
13840
14985
|
outputError(
|
|
@@ -13848,14 +14993,16 @@ async function generateCommand(type, repoPathArg, options) {
|
|
|
13848
14993
|
const result = {
|
|
13849
14994
|
ok,
|
|
13850
14995
|
status,
|
|
13851
|
-
data: { type, files: genResult.files }
|
|
14996
|
+
data: { type, files: genResult.files, dryRun: options.dryRun }
|
|
13852
14997
|
};
|
|
13853
14998
|
outputResult(result, true);
|
|
13854
14999
|
if (!ok) process.exitCode = 1;
|
|
13855
15000
|
} else {
|
|
13856
15001
|
for (const file of genResult.files) {
|
|
13857
15002
|
if (shouldLog(options)) {
|
|
13858
|
-
|
|
15003
|
+
const prefix = options.dryRun ? file.action === "wrote" ? "[dry-run] Would write" : "[dry-run] Would skip" : file.action === "wrote" ? "Wrote" : "Skipped";
|
|
15004
|
+
const suffix = options.dryRun && file.bytes !== void 0 ? ` (${file.bytes} bytes)` : "";
|
|
15005
|
+
process.stderr.write(`${prefix} ${file.path}${suffix}
|
|
13859
15006
|
`);
|
|
13860
15007
|
}
|
|
13861
15008
|
}
|
|
@@ -13866,18 +15013,19 @@ async function generateCommand(type, repoPathArg, options) {
|
|
|
13866
15013
|
}
|
|
13867
15014
|
|
|
13868
15015
|
// src/commands/init.ts
|
|
13869
|
-
import
|
|
15016
|
+
import { execFile as execFile3 } from "child_process";
|
|
15017
|
+
import path21 from "path";
|
|
15018
|
+
import { promisify as promisify3 } from "util";
|
|
13870
15019
|
|
|
13871
15020
|
// packages/core/src/services/configScaffold.ts
|
|
13872
|
-
import
|
|
15021
|
+
import path20 from "path";
|
|
13873
15022
|
async function scaffoldAgentrcConfig(repoPath, areas, force = false) {
|
|
13874
|
-
|
|
13875
|
-
const
|
|
13876
|
-
const workspaces = await detectWorkspaces(repoPath, areas);
|
|
15023
|
+
const configPath = path20.join(repoPath, "agentrc.config.json");
|
|
15024
|
+
const workspaces = areas.length > 0 ? await detectWorkspaces(repoPath, areas) : [];
|
|
13877
15025
|
const workspacePaths = workspaces.map((ws) => ws.path + "/");
|
|
13878
15026
|
const standaloneAreas = areas.filter((a) => {
|
|
13879
15027
|
if (!a.path) return true;
|
|
13880
|
-
const rel =
|
|
15028
|
+
const rel = path20.relative(repoPath, a.path).replace(/\\/gu, "/");
|
|
13881
15029
|
return !workspacePaths.some((prefix) => rel.startsWith(prefix));
|
|
13882
15030
|
}).map((a) => ({
|
|
13883
15031
|
name: a.name,
|
|
@@ -13887,16 +15035,15 @@ async function scaffoldAgentrcConfig(repoPath, areas, force = false) {
|
|
|
13887
15035
|
const agentrcConfig = {};
|
|
13888
15036
|
if (workspaces.length > 0) agentrcConfig.workspaces = workspaces;
|
|
13889
15037
|
if (standaloneAreas.length > 0) agentrcConfig.areas = standaloneAreas;
|
|
13890
|
-
if (!agentrcConfig.workspaces && !agentrcConfig.areas) return null;
|
|
13891
15038
|
const configContent = JSON.stringify(agentrcConfig, null, 2) + "\n";
|
|
13892
15039
|
const { wrote } = await safeWriteFile(configPath, configContent, force);
|
|
13893
15040
|
return { wrote, configPath };
|
|
13894
15041
|
}
|
|
13895
15042
|
|
|
13896
15043
|
// src/commands/init.ts
|
|
13897
|
-
import { checkbox, select } from "@inquirer/prompts";
|
|
15044
|
+
import { checkbox, confirm, select } from "@inquirer/prompts";
|
|
13898
15045
|
async function initCommand(repoPathArg, options) {
|
|
13899
|
-
let repoPath =
|
|
15046
|
+
let repoPath = path21.resolve(repoPathArg ?? process.cwd());
|
|
13900
15047
|
const provider = options.provider ?? (options.github ? "github" : void 0);
|
|
13901
15048
|
if (provider && provider !== "github" && provider !== "azure") {
|
|
13902
15049
|
outputError("Invalid provider. Use github or azure.", Boolean(options.json));
|
|
@@ -13934,7 +15081,7 @@ async function initCommand(repoPathArg, options) {
|
|
|
13934
15081
|
value: repo
|
|
13935
15082
|
}))
|
|
13936
15083
|
});
|
|
13937
|
-
const cacheRoot =
|
|
15084
|
+
const cacheRoot = path21.join(process.cwd(), ".agentrc-cache");
|
|
13938
15085
|
repoPath = validateCachePath(cacheRoot, selection.owner, selection.name);
|
|
13939
15086
|
await ensureDir(repoPath);
|
|
13940
15087
|
const hasGit = await isGitRepo(repoPath);
|
|
@@ -13987,7 +15134,7 @@ async function initCommand(repoPathArg, options) {
|
|
|
13987
15134
|
value: repo
|
|
13988
15135
|
}))
|
|
13989
15136
|
});
|
|
13990
|
-
const cacheRoot =
|
|
15137
|
+
const cacheRoot = path21.join(process.cwd(), ".agentrc-cache");
|
|
13991
15138
|
repoPath = validateCachePath(
|
|
13992
15139
|
cacheRoot,
|
|
13993
15140
|
orgSelection.name,
|
|
@@ -14026,17 +15173,17 @@ async function initCommand(repoPathArg, options) {
|
|
|
14026
15173
|
});
|
|
14027
15174
|
const allFiles = [];
|
|
14028
15175
|
if (selections.includes("instructions")) {
|
|
14029
|
-
const outputPath =
|
|
14030
|
-
await ensureDir(
|
|
15176
|
+
const outputPath = path21.join(repoPath, ".github", "copilot-instructions.md");
|
|
15177
|
+
await ensureDir(path21.dirname(outputPath));
|
|
14031
15178
|
try {
|
|
14032
15179
|
const content = await generateCopilotInstructions({ repoPath, model: options.model });
|
|
14033
15180
|
const { wrote } = await safeWriteFile(outputPath, content, Boolean(options.force));
|
|
14034
15181
|
allFiles.push({
|
|
14035
|
-
path:
|
|
15182
|
+
path: path21.relative(process.cwd(), outputPath),
|
|
14036
15183
|
action: wrote ? "wrote" : "skipped"
|
|
14037
15184
|
});
|
|
14038
15185
|
if (shouldLog(options)) {
|
|
14039
|
-
const rel =
|
|
15186
|
+
const rel = path21.relative(process.cwd(), outputPath);
|
|
14040
15187
|
process.stderr.write((wrote ? `Wrote ${rel}` : `Skipped ${rel} (exists)`) + "\n");
|
|
14041
15188
|
}
|
|
14042
15189
|
} catch (error) {
|
|
@@ -14063,16 +15210,19 @@ async function initCommand(repoPathArg, options) {
|
|
|
14063
15210
|
return;
|
|
14064
15211
|
}
|
|
14065
15212
|
allFiles.push(...genResult.files);
|
|
14066
|
-
|
|
14067
|
-
const result = await scaffoldAgentrcConfig(
|
|
14068
|
-
|
|
14069
|
-
|
|
14070
|
-
|
|
14071
|
-
|
|
14072
|
-
|
|
14073
|
-
|
|
15213
|
+
{
|
|
15214
|
+
const result = await scaffoldAgentrcConfig(
|
|
15215
|
+
repoPath,
|
|
15216
|
+
analysis.areas ?? [],
|
|
15217
|
+
Boolean(options.force)
|
|
15218
|
+
);
|
|
15219
|
+
const rel = path21.relative(process.cwd(), result.configPath);
|
|
15220
|
+
allFiles.push({ path: rel, action: result.wrote ? "wrote" : "skipped" });
|
|
15221
|
+
if (shouldLog(options)) {
|
|
15222
|
+
process.stderr.write((result.wrote ? `Wrote ${rel}` : `Skipped ${rel} (exists)`) + "\n");
|
|
14074
15223
|
}
|
|
14075
15224
|
}
|
|
15225
|
+
await offerApmInit(repoPath, options);
|
|
14076
15226
|
if (options.json) {
|
|
14077
15227
|
const { ok, status } = deriveFileStatus(allFiles);
|
|
14078
15228
|
const result = {
|
|
@@ -14094,9 +15244,52 @@ async function initCommand(repoPathArg, options) {
|
|
|
14094
15244
|
process.stderr.write(" agentrc eval --init Scaffold evaluation test cases\n");
|
|
14095
15245
|
}
|
|
14096
15246
|
}
|
|
15247
|
+
var execFileAsync3 = promisify3(execFile3);
|
|
15248
|
+
var APM_TIMEOUT_MS = 1e4;
|
|
15249
|
+
async function isApmInstalled() {
|
|
15250
|
+
try {
|
|
15251
|
+
await execFileAsync3("apm", ["--version"], { timeout: APM_TIMEOUT_MS });
|
|
15252
|
+
return true;
|
|
15253
|
+
} catch {
|
|
15254
|
+
return false;
|
|
15255
|
+
}
|
|
15256
|
+
}
|
|
15257
|
+
async function offerApmInit(repoPath, options) {
|
|
15258
|
+
if (options.json) return;
|
|
15259
|
+
const hasApmYml = await fileExists(path21.join(repoPath, "apm.yml"));
|
|
15260
|
+
if (hasApmYml) return;
|
|
15261
|
+
const apmAvailable = await isApmInstalled();
|
|
15262
|
+
if (apmAvailable) {
|
|
15263
|
+
const accepted = options.yes ? true : await confirm({
|
|
15264
|
+
message: "Set up APM to install and share agent packages across your team?",
|
|
15265
|
+
default: false
|
|
15266
|
+
});
|
|
15267
|
+
if (accepted) {
|
|
15268
|
+
try {
|
|
15269
|
+
await execFileAsync3("apm", ["init", "--yes"], { cwd: repoPath, timeout: APM_TIMEOUT_MS });
|
|
15270
|
+
if (shouldLog(options)) {
|
|
15271
|
+
process.stderr.write(
|
|
15272
|
+
"APM initialized \u2014 run `apm install <package>` to add shared agent packages.\n"
|
|
15273
|
+
);
|
|
15274
|
+
}
|
|
15275
|
+
} catch (error) {
|
|
15276
|
+
if (shouldLog(options)) {
|
|
15277
|
+
process.stderr.write(
|
|
15278
|
+
`Warning: APM init failed; continuing without APM: ${error instanceof Error ? error.message : String(error)}
|
|
15279
|
+
`
|
|
15280
|
+
);
|
|
15281
|
+
}
|
|
15282
|
+
}
|
|
15283
|
+
}
|
|
15284
|
+
} else if (shouldLog(options)) {
|
|
15285
|
+
process.stderr.write(
|
|
15286
|
+
"\nTip: use APM to install shared agent packages and distribute your instructions across repos.\n https://github.com/microsoft/apm\n"
|
|
15287
|
+
);
|
|
15288
|
+
}
|
|
15289
|
+
}
|
|
14097
15290
|
|
|
14098
15291
|
// src/commands/pr.ts
|
|
14099
|
-
import
|
|
15292
|
+
import path22 from "path";
|
|
14100
15293
|
var DEFAULT_PR_BRANCH = "agentrc/add-ai-config";
|
|
14101
15294
|
async function prCommand(repo, options) {
|
|
14102
15295
|
const provider = options.provider ?? "github";
|
|
@@ -14130,7 +15323,7 @@ async function prCommand(repo, options) {
|
|
|
14130
15323
|
try {
|
|
14131
15324
|
progress.update("Fetching repo info...");
|
|
14132
15325
|
const repoInfo = await getRepo(token2, organization, project, name2);
|
|
14133
|
-
const cacheRoot =
|
|
15326
|
+
const cacheRoot = path22.join(process.cwd(), ".agentrc-cache");
|
|
14134
15327
|
const repoPath = validateCachePath(cacheRoot, organization, project, name2);
|
|
14135
15328
|
await ensureDir(repoPath);
|
|
14136
15329
|
if (!await isGitRepo(repoPath)) {
|
|
@@ -14144,8 +15337,8 @@ async function prCommand(repo, options) {
|
|
|
14144
15337
|
await checkoutBranch(repoPath, branch);
|
|
14145
15338
|
progress.update("Generating instructions...");
|
|
14146
15339
|
const instructions = await generateCopilotInstructions({ repoPath, model: options.model });
|
|
14147
|
-
const instructionsPath =
|
|
14148
|
-
await ensureDir(
|
|
15340
|
+
const instructionsPath = path22.join(repoPath, ".github", "copilot-instructions.md");
|
|
15341
|
+
await ensureDir(path22.dirname(instructionsPath));
|
|
14149
15342
|
const { wrote, reason } = await safeWriteFile(instructionsPath, instructions, true);
|
|
14150
15343
|
if (!wrote) {
|
|
14151
15344
|
throw new Error(
|
|
@@ -14212,7 +15405,7 @@ async function prCommand(repo, options) {
|
|
|
14212
15405
|
try {
|
|
14213
15406
|
progress.update("Fetching repo info...");
|
|
14214
15407
|
const repoInfo = await getRepo2(token, owner, name);
|
|
14215
|
-
const cacheRoot =
|
|
15408
|
+
const cacheRoot = path22.join(process.cwd(), ".agentrc-cache");
|
|
14216
15409
|
const repoPath = validateCachePath(cacheRoot, owner, name);
|
|
14217
15410
|
await ensureDir(repoPath);
|
|
14218
15411
|
if (!await isGitRepo(repoPath)) {
|
|
@@ -14224,8 +15417,8 @@ async function prCommand(repo, options) {
|
|
|
14224
15417
|
await checkoutBranch(repoPath, branch);
|
|
14225
15418
|
progress.update("Generating instructions...");
|
|
14226
15419
|
const instructions = await generateCopilotInstructions({ repoPath, model: options.model });
|
|
14227
|
-
const instructionsPath =
|
|
14228
|
-
await ensureDir(
|
|
15420
|
+
const instructionsPath = path22.join(repoPath, ".github", "copilot-instructions.md");
|
|
15421
|
+
await ensureDir(path22.dirname(instructionsPath));
|
|
14229
15422
|
const { wrote, reason } = await safeWriteFile(instructionsPath, instructions, true);
|
|
14230
15423
|
if (!wrote) {
|
|
14231
15424
|
throw new Error(
|
|
@@ -14274,13 +15467,13 @@ async function prCommand(repo, options) {
|
|
|
14274
15467
|
}
|
|
14275
15468
|
|
|
14276
15469
|
// src/commands/readiness.ts
|
|
14277
|
-
import
|
|
15470
|
+
import path23 from "path";
|
|
14278
15471
|
import chalk3 from "chalk";
|
|
14279
15472
|
async function readinessCommand(repoPathArg, options) {
|
|
14280
|
-
const repoPath =
|
|
14281
|
-
const repoName =
|
|
14282
|
-
const resolvedOutputPath = options.output ?
|
|
14283
|
-
const outputExt = options.output ?
|
|
15473
|
+
const repoPath = path23.resolve(repoPathArg ?? process.cwd());
|
|
15474
|
+
const repoName = path23.basename(repoPath);
|
|
15475
|
+
const resolvedOutputPath = options.output ? path23.resolve(options.output) : "";
|
|
15476
|
+
const outputExt = options.output ? path23.extname(options.output).toLowerCase() : "";
|
|
14284
15477
|
let failLevelError;
|
|
14285
15478
|
let report;
|
|
14286
15479
|
try {
|
|
@@ -14342,7 +15535,7 @@ async function readinessCommand(repoPathArg, options) {
|
|
|
14342
15535
|
title: `Readiness Report: ${repoName}`,
|
|
14343
15536
|
generatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
14344
15537
|
});
|
|
14345
|
-
const outputPath = options.output ? resolvedOutputPath :
|
|
15538
|
+
const outputPath = options.output ? resolvedOutputPath : path23.join(repoPath, "readiness-report.html");
|
|
14346
15539
|
const { wrote, reason } = await safeWriteFile(outputPath, html, Boolean(options.force));
|
|
14347
15540
|
if (!wrote) {
|
|
14348
15541
|
const why = reason === "symlink" ? "path is a symlink" : "file exists (use --force)";
|
|
@@ -14577,12 +15770,12 @@ function formatReadinessMarkdown(report, repoName) {
|
|
|
14577
15770
|
}
|
|
14578
15771
|
|
|
14579
15772
|
// src/commands/tui.tsx
|
|
14580
|
-
import
|
|
15773
|
+
import path25 from "path";
|
|
14581
15774
|
import { render as render3 } from "ink";
|
|
14582
15775
|
|
|
14583
15776
|
// src/ui/tui.tsx
|
|
14584
15777
|
import fs10 from "fs/promises";
|
|
14585
|
-
import
|
|
15778
|
+
import path24 from "path";
|
|
14586
15779
|
import { Box as Box5, Text as Text5, useApp as useApp4, useInput as useInput4, useStdout, useIsScreenReaderEnabled as useIsScreenReaderEnabled5 } from "ink";
|
|
14587
15780
|
import { useEffect as useEffect5, useMemo, useState as useState5 } from "react";
|
|
14588
15781
|
import { Fragment, jsx as jsx7, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
@@ -14697,7 +15890,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14697
15890
|
const [isMonorepo, setIsMonorepo] = useState5(false);
|
|
14698
15891
|
const [repoAreas, setRepoAreas] = useState5([]);
|
|
14699
15892
|
const [areaCursor, setAreaCursor] = useState5(0);
|
|
14700
|
-
const repoLabel = useMemo(() =>
|
|
15893
|
+
const repoLabel = useMemo(() => path24.basename(repoPath), [repoPath]);
|
|
14701
15894
|
const repoFull = useMemo(() => repoPath, [repoPath]);
|
|
14702
15895
|
const isLoading = status === "generating" || status === "bootstrapping" || status === "evaluating" || status === "generating-areas" || status === "readiness-running";
|
|
14703
15896
|
const isMenu = status === "model-pick" || status === "eval-pick" || status === "batch-pick" || status === "generate-pick" || status === "generate-app-pick" || status === "generate-area-pick";
|
|
@@ -14709,11 +15902,11 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14709
15902
|
setStatus("idle");
|
|
14710
15903
|
};
|
|
14711
15904
|
useEffect5(() => {
|
|
14712
|
-
const configPath =
|
|
15905
|
+
const configPath = path24.join(repoPath, "agentrc.eval.json");
|
|
14713
15906
|
fs10.access(configPath).then(() => setHasEvalConfig(true)).catch(() => setHasEvalConfig(false));
|
|
14714
15907
|
const agentrcConfigCandidates = [
|
|
14715
|
-
|
|
14716
|
-
|
|
15908
|
+
path24.join(repoPath, "agentrc.config.json"),
|
|
15909
|
+
path24.join(repoPath, ".github", "agentrc.config.json")
|
|
14717
15910
|
];
|
|
14718
15911
|
Promise.all(
|
|
14719
15912
|
agentrcConfigCandidates.map(
|
|
@@ -14734,17 +15927,17 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14734
15927
|
let active = true;
|
|
14735
15928
|
listCopilotModels().then((models) => {
|
|
14736
15929
|
if (!active) return;
|
|
14737
|
-
|
|
14738
|
-
|
|
15930
|
+
const list = models.length > 0 ? models : PREFERRED_MODELS;
|
|
15931
|
+
setAvailableModels(list);
|
|
14739
15932
|
setEvalModel(
|
|
14740
|
-
(current) =>
|
|
15933
|
+
(current) => list.includes(current) ? current : pickBestModel(list, current)
|
|
14741
15934
|
);
|
|
14742
15935
|
setJudgeModel(
|
|
14743
|
-
(current) =>
|
|
15936
|
+
(current) => list.includes(current) ? current : pickBestModel(list, current)
|
|
14744
15937
|
);
|
|
14745
15938
|
}).catch(() => {
|
|
14746
15939
|
if (!active) return;
|
|
14747
|
-
setAvailableModels(
|
|
15940
|
+
setAvailableModels(PREFERRED_MODELS);
|
|
14748
15941
|
});
|
|
14749
15942
|
return () => {
|
|
14750
15943
|
active = false;
|
|
@@ -14780,7 +15973,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14780
15973
|
};
|
|
14781
15974
|
useEffect5(() => {
|
|
14782
15975
|
let active = true;
|
|
14783
|
-
const configPath =
|
|
15976
|
+
const configPath = path24.join(repoPath, "agentrc.eval.json");
|
|
14784
15977
|
fs10.readFile(configPath, "utf8").then((raw) => {
|
|
14785
15978
|
if (!active) return;
|
|
14786
15979
|
const parsed = JSON.parse(raw);
|
|
@@ -14795,7 +15988,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14795
15988
|
};
|
|
14796
15989
|
}, [repoPath]);
|
|
14797
15990
|
const bootstrapEvalConfig = async (count, force) => {
|
|
14798
|
-
const configPath =
|
|
15991
|
+
const configPath = path24.join(repoPath, "agentrc.eval.json");
|
|
14799
15992
|
try {
|
|
14800
15993
|
setStatus("bootstrapping");
|
|
14801
15994
|
setMessage("Generating eval cases with Copilot SDK...");
|
|
@@ -14834,13 +16027,13 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14834
16027
|
if (status === "preview") {
|
|
14835
16028
|
if (input.toLowerCase() === "s") {
|
|
14836
16029
|
try {
|
|
14837
|
-
const outputPath = generateSavePath ||
|
|
14838
|
-
await fs10.mkdir(
|
|
16030
|
+
const outputPath = generateSavePath || path24.join(repoPath, ".github", "copilot-instructions.md");
|
|
16031
|
+
await fs10.mkdir(path24.dirname(outputPath), { recursive: true });
|
|
14839
16032
|
const { wrote, reason } = await safeWriteFile(outputPath, generatedContent, true);
|
|
14840
16033
|
if (!wrote)
|
|
14841
16034
|
throw new Error(reason === "symlink" ? "Path is a symlink" : "Write failed");
|
|
14842
16035
|
setStatus("done");
|
|
14843
|
-
const relPath =
|
|
16036
|
+
const relPath = path24.relative(repoPath, outputPath);
|
|
14844
16037
|
const msg = `Saved to ${relPath}`;
|
|
14845
16038
|
setMessage(msg);
|
|
14846
16039
|
addLog(msg, "success");
|
|
@@ -14874,7 +16067,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14874
16067
|
setMessage("Enter a positive number of eval cases, then press Enter.");
|
|
14875
16068
|
return;
|
|
14876
16069
|
}
|
|
14877
|
-
const configPath =
|
|
16070
|
+
const configPath = path24.join(repoPath, "agentrc.eval.json");
|
|
14878
16071
|
setEvalBootstrapCount(count);
|
|
14879
16072
|
try {
|
|
14880
16073
|
await fs10.access(configPath);
|
|
@@ -14933,7 +16126,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14933
16126
|
setStatus("generate-app-pick");
|
|
14934
16127
|
setMessage("Generate for root or per-app?");
|
|
14935
16128
|
} else {
|
|
14936
|
-
const savePath =
|
|
16129
|
+
const savePath = path24.join(repoPath, ".github", "copilot-instructions.md");
|
|
14937
16130
|
setGenerateSavePath(savePath);
|
|
14938
16131
|
await doGenerate(repoPath, savePath, "copilot-instructions");
|
|
14939
16132
|
}
|
|
@@ -14945,7 +16138,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14945
16138
|
setStatus("generate-app-pick");
|
|
14946
16139
|
setMessage("Generate for root or per-app?");
|
|
14947
16140
|
} else {
|
|
14948
|
-
const savePath =
|
|
16141
|
+
const savePath = path24.join(repoPath, "AGENTS.md");
|
|
14949
16142
|
setGenerateSavePath(savePath);
|
|
14950
16143
|
await doGenerate(repoPath, savePath, "agents-md");
|
|
14951
16144
|
}
|
|
@@ -14970,7 +16163,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14970
16163
|
}
|
|
14971
16164
|
if (status === "generate-app-pick") {
|
|
14972
16165
|
if (input.toLowerCase() === "r") {
|
|
14973
|
-
const savePath = generateTarget === "copilot-instructions" ?
|
|
16166
|
+
const savePath = generateTarget === "copilot-instructions" ? path24.join(repoPath, ".github", "copilot-instructions.md") : path24.join(repoPath, "AGENTS.md");
|
|
14974
16167
|
setGenerateSavePath(savePath);
|
|
14975
16168
|
await doGenerate(repoPath, savePath, generateTarget);
|
|
14976
16169
|
return;
|
|
@@ -14980,7 +16173,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14980
16173
|
addLog(`Generating ${generateTarget} for ${repoApps.length} apps...`, "progress");
|
|
14981
16174
|
let count = 0;
|
|
14982
16175
|
for (const app2 of repoApps) {
|
|
14983
|
-
const savePath = generateTarget === "copilot-instructions" ?
|
|
16176
|
+
const savePath = generateTarget === "copilot-instructions" ? path24.join(app2.path, ".github", "copilot-instructions.md") : path24.join(app2.path, "AGENTS.md");
|
|
14984
16177
|
setMessage(`Generating for ${app2.name} (${count + 1}/${repoApps.length})...`);
|
|
14985
16178
|
try {
|
|
14986
16179
|
const content = await generateCopilotInstructions({
|
|
@@ -14988,11 +16181,11 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14988
16181
|
onProgress: (msg) => setMessage(`${app2.name}: ${msg}`)
|
|
14989
16182
|
});
|
|
14990
16183
|
if (content.trim()) {
|
|
14991
|
-
await fs10.mkdir(
|
|
16184
|
+
await fs10.mkdir(path24.dirname(savePath), { recursive: true });
|
|
14992
16185
|
const { wrote: saved } = await safeWriteFile(savePath, content, true);
|
|
14993
16186
|
if (!saved) continue;
|
|
14994
16187
|
count++;
|
|
14995
|
-
addLog(`${app2.name}: saved ${
|
|
16188
|
+
addLog(`${app2.name}: saved ${path24.basename(savePath)}`, "success");
|
|
14996
16189
|
}
|
|
14997
16190
|
} catch (error) {
|
|
14998
16191
|
const msg = error instanceof Error ? error.message : "Failed.";
|
|
@@ -15006,7 +16199,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
15006
16199
|
const num = Number.parseInt(input, 10);
|
|
15007
16200
|
if (Number.isFinite(num) && num >= 1 && num <= repoApps.length) {
|
|
15008
16201
|
const app2 = repoApps[num - 1];
|
|
15009
|
-
const savePath = generateTarget === "copilot-instructions" ?
|
|
16202
|
+
const savePath = generateTarget === "copilot-instructions" ? path24.join(app2.path, ".github", "copilot-instructions.md") : path24.join(app2.path, "AGENTS.md");
|
|
15010
16203
|
setGenerateSavePath(savePath);
|
|
15011
16204
|
await doGenerate(app2.path, savePath, generateTarget);
|
|
15012
16205
|
return;
|
|
@@ -15034,7 +16227,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
15034
16227
|
const result = await writeAreaInstruction(repoPath, area, body);
|
|
15035
16228
|
if (result.status === "written") {
|
|
15036
16229
|
written++;
|
|
15037
|
-
addLog(`${area.name}: saved ${
|
|
16230
|
+
addLog(`${area.name}: saved ${path24.basename(result.filePath)}`, "success");
|
|
15038
16231
|
} else if (result.status === "skipped") {
|
|
15039
16232
|
addLog(`${area.name}: skipped (file exists)`, "info");
|
|
15040
16233
|
}
|
|
@@ -15128,8 +16321,8 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
15128
16321
|
}
|
|
15129
16322
|
if (status === "eval-pick") {
|
|
15130
16323
|
if (input.toLowerCase() === "r") {
|
|
15131
|
-
const configPath =
|
|
15132
|
-
const outputPath =
|
|
16324
|
+
const configPath = path24.join(repoPath, "agentrc.eval.json");
|
|
16325
|
+
const outputPath = path24.join(
|
|
15133
16326
|
repoPath,
|
|
15134
16327
|
".agentrc",
|
|
15135
16328
|
"evals",
|
|
@@ -15278,20 +16471,12 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
15278
16471
|
setMessage("agentrc.config.json already exists.");
|
|
15279
16472
|
return;
|
|
15280
16473
|
}
|
|
15281
|
-
if (repoAreas.length === 0) {
|
|
15282
|
-
setMessage("No areas detected. Cannot scaffold agentrc.config.json.");
|
|
15283
|
-
return;
|
|
15284
|
-
}
|
|
15285
16474
|
setStatus("generating");
|
|
15286
16475
|
setMessage("Creating agentrc.config.json...");
|
|
15287
16476
|
addLog("Scaffolding agentrc.config.json...", "progress");
|
|
15288
16477
|
try {
|
|
15289
16478
|
const result = await scaffoldAgentrcConfig(repoPath, repoAreas);
|
|
15290
|
-
if (
|
|
15291
|
-
setStatus("idle");
|
|
15292
|
-
setMessage("Nothing to scaffold \u2014 no areas or workspaces detected.");
|
|
15293
|
-
addLog("No areas to scaffold into config.", "info");
|
|
15294
|
-
} else if (result.wrote) {
|
|
16479
|
+
if (result.wrote) {
|
|
15295
16480
|
setHasAgentrcConfig(true);
|
|
15296
16481
|
setStatus("done");
|
|
15297
16482
|
const msg = `Created agentrc.config.json`;
|
|
@@ -15504,7 +16689,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
15504
16689
|
/* @__PURE__ */ jsx7(Text5, { color: "white", children: app2.name }),
|
|
15505
16690
|
/* @__PURE__ */ jsxs4(Text5, { color: "gray", dimColor: true, children: [
|
|
15506
16691
|
" ",
|
|
15507
|
-
|
|
16692
|
+
path24.relative(repoPath, app2.path)
|
|
15508
16693
|
] })
|
|
15509
16694
|
] }, app2.name)) })
|
|
15510
16695
|
] }),
|
|
@@ -15538,7 +16723,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
15538
16723
|
children: [
|
|
15539
16724
|
/* @__PURE__ */ jsxs4(Text5, { color: "cyan", bold: true, children: [
|
|
15540
16725
|
"Preview (",
|
|
15541
|
-
|
|
16726
|
+
path24.relative(repoPath, generateSavePath) || generateTarget,
|
|
15542
16727
|
")"
|
|
15543
16728
|
] }),
|
|
15544
16729
|
/* @__PURE__ */ jsx7(Text5, { color: "gray", children: truncatedPreview })
|
|
@@ -15647,7 +16832,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
15647
16832
|
// src/commands/tui.tsx
|
|
15648
16833
|
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
15649
16834
|
async function tuiCommand(options) {
|
|
15650
|
-
const repoPath =
|
|
16835
|
+
const repoPath = path25.resolve(options.repo ?? process.cwd());
|
|
15651
16836
|
const skipAnimation = options.animation === false;
|
|
15652
16837
|
try {
|
|
15653
16838
|
const accessible = options.accessible ? true : void 0;
|
|
@@ -15662,7 +16847,7 @@ async function tuiCommand(options) {
|
|
|
15662
16847
|
}
|
|
15663
16848
|
|
|
15664
16849
|
// src/cli.ts
|
|
15665
|
-
var _require =
|
|
16850
|
+
var _require = createRequire2(import.meta.url);
|
|
15666
16851
|
var CLI_VERSION = _require("../package.json").version;
|
|
15667
16852
|
function withGlobalOpts(fn) {
|
|
15668
16853
|
return async (...raw) => {
|
|
@@ -15692,7 +16877,7 @@ function runCli(argv) {
|
|
|
15692
16877
|
"mcp",
|
|
15693
16878
|
"vscode"
|
|
15694
16879
|
])
|
|
15695
|
-
).argument("[path]", "Path to a local repository").option("--force", "Overwrite existing files").option("--per-app", "(deprecated) Use `agentrc instructions --areas` instead").option("--model <name>", "Model for instructions generation", DEFAULT_MODEL).option("--strategy <mode>", "Instruction strategy (flat or nested)").action(withGlobalOpts(generateCommand));
|
|
16880
|
+
).argument("[path]", "Path to a local repository").option("--force", "Overwrite existing files").option("--per-app", "(deprecated) Use `agentrc instructions --areas` instead").option("--model <name>", "Model for instructions generation", DEFAULT_MODEL).option("--strategy <mode>", "Instruction strategy (flat or nested)").option("--dry-run", "Preview generated files without writing anything").action(withGlobalOpts(generateCommand));
|
|
15696
16881
|
program.command("pr").description("Create a PR with generated configs on GitHub or Azure DevOps").argument("[repo]", "Repo identifier (github: owner/name, azure: org/project/repo)").option("--branch <name>", "Branch name").option("--provider <provider>", "Repo provider (github|azure)").option("--model <name>", "Model for instructions generation", DEFAULT_MODEL).action(withGlobalOpts(prCommand));
|
|
15697
16882
|
program.command("eval").description("Compare AI responses with and without instructions").argument("[path]", "Path to eval config JSON").option("--repo <path>", "Repository path", process.cwd()).option("--model <name>", "Model for responses", DEFAULT_MODEL).option("--judge-model <name>", "Model for judging", DEFAULT_JUDGE_MODEL).option("--list-models", "List Copilot CLI models and exit").option("--output <path>", "Write results JSON to file").option("--init", "Create a starter agentrc.eval.json file").option("--count <number>", "Number of eval cases to generate (with --init)").option("--fail-level <number>", "Exit with error if pass rate (%) falls below threshold").action(withGlobalOpts(evalCommand));
|
|
15698
16883
|
program.command("tui").description("Interactive terminal UI for generation, evaluation, and batch workflows").option("--repo <path>", "Repository path", process.cwd()).option("--no-animation", "Skip the animated banner intro").action(withGlobalOpts(tuiCommand));
|