@microsoft/agentrc 2.0.1-7 → 2.0.1-70
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 +13 -0
- package/dist/index.js +2218 -992
- package/dist/index.js.map +1 -1
- package/dist/skills/area-instructions/SKILL.md +37 -0
- package/dist/skills/nested-detail/SKILL.md +22 -0
- package/dist/skills/nested-hub/SKILL.md +44 -0
- package/dist/skills/root-instructions/SKILL.md +29 -0
- 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() {
|
|
@@ -6958,7 +7708,7 @@ async function checkReposForInstructions2(token, repos, onProgress) {
|
|
|
6958
7708
|
|
|
6959
7709
|
// packages/core/src/services/instructions.ts
|
|
6960
7710
|
import fs5 from "fs/promises";
|
|
6961
|
-
import
|
|
7711
|
+
import path7 from "path";
|
|
6962
7712
|
|
|
6963
7713
|
// packages/core/src/services/copilot.ts
|
|
6964
7714
|
import fs4 from "fs/promises";
|
|
@@ -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) {
|
|
@@ -7378,6 +8152,25 @@ async function createCopilotClient(cliConfig) {
|
|
|
7378
8152
|
}
|
|
7379
8153
|
}
|
|
7380
8154
|
|
|
8155
|
+
// packages/core/src/services/skills.ts
|
|
8156
|
+
import path6 from "path";
|
|
8157
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
8158
|
+
var overrideSkillsDir;
|
|
8159
|
+
function getBuiltinSkillsDir() {
|
|
8160
|
+
if (overrideSkillsDir) {
|
|
8161
|
+
return overrideSkillsDir;
|
|
8162
|
+
}
|
|
8163
|
+
const thisFile = fileURLToPath2(import.meta.url);
|
|
8164
|
+
const thisDir = path6.dirname(thisFile);
|
|
8165
|
+
if (thisDir.includes(path6.join("packages", "core", "src"))) {
|
|
8166
|
+
return path6.resolve(thisDir, "..", "..", "..", "..", "plugin", "skills");
|
|
8167
|
+
}
|
|
8168
|
+
return path6.resolve(thisDir, "skills");
|
|
8169
|
+
}
|
|
8170
|
+
function getSkillDirectory(_skillName) {
|
|
8171
|
+
return getBuiltinSkillsDir();
|
|
8172
|
+
}
|
|
8173
|
+
|
|
7381
8174
|
// packages/core/src/services/instructions.ts
|
|
7382
8175
|
async function detectExistingInstructions(repoPath, detailDirName = ".agents") {
|
|
7383
8176
|
const { agentsMdFiles, claudeMdFiles } = await findInstructionMarkerFiles(repoPath);
|
|
@@ -7401,7 +8194,7 @@ async function findInstructionMarkerFiles(repoPath) {
|
|
|
7401
8194
|
claudeMdFiles.push(relPath ? `${relPath}/${entry.name}` : entry.name);
|
|
7402
8195
|
}
|
|
7403
8196
|
} else if (entry.isDirectory()) {
|
|
7404
|
-
await walk(
|
|
8197
|
+
await walk(path7.join(dir, entry.name), relPath ? `${relPath}/${entry.name}` : entry.name);
|
|
7405
8198
|
}
|
|
7406
8199
|
}
|
|
7407
8200
|
}
|
|
@@ -7409,7 +8202,7 @@ async function findInstructionMarkerFiles(repoPath) {
|
|
|
7409
8202
|
return { agentsMdFiles: agentsMdFiles.sort(), claudeMdFiles: claudeMdFiles.sort() };
|
|
7410
8203
|
}
|
|
7411
8204
|
async function findModularInstructionFiles(repoPath) {
|
|
7412
|
-
const dir =
|
|
8205
|
+
const dir = path7.join(repoPath, ".github", "instructions");
|
|
7413
8206
|
const entries = await fs5.readdir(dir, { withFileTypes: true }).catch(() => []);
|
|
7414
8207
|
return entries.filter((e) => !e.isSymbolicLink() && e.isFile() && e.name.endsWith(".instructions.md")).map((e) => `.github/instructions/${e.name}`).sort();
|
|
7415
8208
|
}
|
|
@@ -7423,7 +8216,7 @@ async function findDetailFiles(repoPath, detailDirName) {
|
|
|
7423
8216
|
if (entry.isSymbolicLink()) continue;
|
|
7424
8217
|
if (entry.isDirectory()) {
|
|
7425
8218
|
if (entry.name === detailDirName) {
|
|
7426
|
-
const detailDir =
|
|
8219
|
+
const detailDir = path7.join(dir, entry.name);
|
|
7427
8220
|
const detailEntries = await fs5.readdir(detailDir, { withFileTypes: true }).catch(() => []);
|
|
7428
8221
|
for (const de of detailEntries) {
|
|
7429
8222
|
if (!de.isSymbolicLink() && de.isFile() && de.name.endsWith(".md")) {
|
|
@@ -7432,7 +8225,7 @@ async function findDetailFiles(repoPath, detailDirName) {
|
|
|
7432
8225
|
}
|
|
7433
8226
|
}
|
|
7434
8227
|
} else {
|
|
7435
|
-
await walk(
|
|
8228
|
+
await walk(path7.join(dir, entry.name), relPath ? `${relPath}/${entry.name}` : entry.name);
|
|
7436
8229
|
}
|
|
7437
8230
|
}
|
|
7438
8231
|
}
|
|
@@ -7514,11 +8307,11 @@ function isCopilotAuthError(error) {
|
|
|
7514
8307
|
return error instanceof Error && error.message.includes("Copilot CLI not logged in.");
|
|
7515
8308
|
}
|
|
7516
8309
|
function resolveAreaWorkingDirectory(repoPath, area) {
|
|
7517
|
-
const repoRoot =
|
|
8310
|
+
const repoRoot = path7.resolve(repoPath);
|
|
7518
8311
|
const rawWorkingDirectory = area?.workingDirectory ?? area?.path;
|
|
7519
8312
|
if (!rawWorkingDirectory) return repoRoot;
|
|
7520
|
-
const resolved = area?.workingDirectory ?
|
|
7521
|
-
if (resolved !== repoRoot && !resolved.startsWith(repoRoot +
|
|
8313
|
+
const resolved = area?.workingDirectory ? path7.resolve(repoRoot, rawWorkingDirectory) : path7.isAbsolute(rawWorkingDirectory) ? path7.resolve(rawWorkingDirectory) : path7.resolve(repoRoot, rawWorkingDirectory);
|
|
8314
|
+
if (resolved !== repoRoot && !resolved.startsWith(repoRoot + path7.sep)) {
|
|
7522
8315
|
throw new Error(`Invalid workingDirectory "${rawWorkingDirectory}": escapes repo boundary`);
|
|
7523
8316
|
}
|
|
7524
8317
|
return resolved;
|
|
@@ -7550,6 +8343,7 @@ async function generateCopilotInstructions(options) {
|
|
|
7550
8343
|
const preferredModel = options.model ?? DEFAULT_MODEL;
|
|
7551
8344
|
const systemContent = hasExistingInstructions ? "You are an expert codebase analyst. Your task is to generate a concise .github/copilot-instructions.md that complements existing instruction files. Use the available tools (glob, view, grep) to explore the codebase. When done, call the emit_file_content tool with the final markdown." : "You are an expert codebase analyst. Your task is to generate a concise .github/copilot-instructions.md file. Use the available tools (glob, view, grep) to explore the codebase. When done, call the emit_file_content tool with the final markdown.";
|
|
7552
8345
|
const { tool: emitTool, getContent } = await createEmitTool();
|
|
8346
|
+
const rootSkillDir = getSkillDirectory("root-instructions");
|
|
7553
8347
|
const session = await client.createSession({
|
|
7554
8348
|
model: preferredModel,
|
|
7555
8349
|
streaming: true,
|
|
@@ -7560,7 +8354,8 @@ async function generateCopilotInstructions(options) {
|
|
|
7560
8354
|
tools: [emitTool],
|
|
7561
8355
|
excludedTools: INSTRUCTION_GENERATION_EXCLUDED_TOOLS,
|
|
7562
8356
|
onPermissionRequest: READ_ONLY_PERMISSION_HANDLER,
|
|
7563
|
-
infiniteSessions: { enabled: false }
|
|
8357
|
+
infiniteSessions: { enabled: false },
|
|
8358
|
+
skillDirectories: [rootSkillDir]
|
|
7564
8359
|
});
|
|
7565
8360
|
await trySetAutopilot(session);
|
|
7566
8361
|
let content = "";
|
|
@@ -7581,22 +8376,8 @@ async function generateCopilotInstructions(options) {
|
|
|
7581
8376
|
sessionError = getSessionError(errorMsg);
|
|
7582
8377
|
}
|
|
7583
8378
|
});
|
|
7584
|
-
const prompt =
|
|
7585
|
-
|
|
7586
|
-
Fan out multiple Explore subagents to map out the codebase in parallel:
|
|
7587
|
-
1. Check for existing instruction files: glob for **/{.github/copilot-instructions.md,AGENT.md,CLAUDE.md,.cursorrules,README.md}
|
|
7588
|
-
2. Identify the tech stack: look at package.json, tsconfig.json, pyproject.toml, Cargo.toml, go.mod, *.csproj, *.fsproj, *.sln, global.json, build.gradle, pom.xml, etc.
|
|
7589
|
-
3. Understand the structure: list key directories
|
|
7590
|
-
4. Detect monorepo structures: check for workspace configs (npm/pnpm/yarn workspaces, Cargo.toml [workspace], go.work, .sln solution files, settings.gradle include directives, pom.xml modules)
|
|
7591
|
-
|
|
7592
|
-
Generate concise instructions (~20-50 lines) covering:
|
|
7593
|
-
- Tech stack and architecture
|
|
7594
|
-
- Build/test commands
|
|
7595
|
-
- Project-specific conventions
|
|
7596
|
-
- Key files/directories
|
|
7597
|
-
- Monorepo structure and per-app layout (if this is a monorepo, describe the workspace organization, how apps relate to each other, and any shared libraries)
|
|
7598
|
-
${existingSection}
|
|
7599
|
-
When you have the complete markdown content, call the \`emit_file_content\` tool with it. Do NOT output the file content directly in chat.`;
|
|
8379
|
+
const prompt = `/root-instructions Analyze this codebase and generate a .github/copilot-instructions.md file.
|
|
8380
|
+
${existingSection}`;
|
|
7600
8381
|
progress("Analyzing codebase...");
|
|
7601
8382
|
let sendError;
|
|
7602
8383
|
try {
|
|
@@ -7633,6 +8414,7 @@ async function generateAreaInstructions(options) {
|
|
|
7633
8414
|
const preferredModel = options.model ?? DEFAULT_MODEL;
|
|
7634
8415
|
const areaSystemContent = hasExistingInstructions ? `You are an expert codebase analyst. Your task is to generate a concise .instructions.md file for a specific area of a codebase. This file will be used as an area instruction in VS Code, automatically applied when working on files matching certain patterns. This file should complement, not duplicate, existing instruction files. Use the Explore subagents and read-only tools to explore the codebase. When done, call the emit_file_content tool with the final markdown.` : `You are an expert codebase analyst. Your task is to generate a concise .instructions.md file for a specific area of a codebase. This file will be used as an area instruction in VS Code, automatically applied when working on files matching certain patterns. Use the Explore subagents and read-only tools to explore the codebase. When done, call the emit_file_content tool with the final markdown.`;
|
|
7635
8416
|
const { tool: emitTool, getContent } = await createEmitTool();
|
|
8417
|
+
const areaSkillDir = getSkillDirectory("area-instructions");
|
|
7636
8418
|
const session = await client.createSession({
|
|
7637
8419
|
model: preferredModel,
|
|
7638
8420
|
streaming: true,
|
|
@@ -7643,7 +8425,8 @@ async function generateAreaInstructions(options) {
|
|
|
7643
8425
|
tools: [emitTool],
|
|
7644
8426
|
excludedTools: INSTRUCTION_GENERATION_EXCLUDED_TOOLS,
|
|
7645
8427
|
onPermissionRequest: READ_ONLY_PERMISSION_HANDLER,
|
|
7646
|
-
infiniteSessions: { enabled: false }
|
|
8428
|
+
infiniteSessions: { enabled: false },
|
|
8429
|
+
skillDirectories: [areaSkillDir]
|
|
7647
8430
|
});
|
|
7648
8431
|
await trySetAutopilot(session);
|
|
7649
8432
|
let content = "";
|
|
@@ -7664,30 +8447,13 @@ async function generateAreaInstructions(options) {
|
|
|
7664
8447
|
sessionError = getSessionError(errorMsg);
|
|
7665
8448
|
}
|
|
7666
8449
|
});
|
|
7667
|
-
const prompt =
|
|
8450
|
+
const prompt = `/area-instructions Analyze the "${area.name}" area of this codebase and generate an area instruction file.
|
|
7668
8451
|
|
|
7669
8452
|
This area covers files matching: ${applyToStr}
|
|
7670
8453
|
${area.description ? `Description: ${area.description}` : ""}
|
|
7671
|
-
|
|
7672
|
-
|
|
7673
|
-
|
|
7674
|
-
2. Identify the tech stack, dependencies, and frameworks used in this area
|
|
7675
|
-
3. Look at key source files to understand patterns and conventions specific to this area
|
|
7676
|
-
|
|
7677
|
-
Generate concise instructions (~10-30 lines) covering:
|
|
7678
|
-
- What this area does and its role in the overall project
|
|
7679
|
-
- Area-specific tech stack, dependencies, and frameworks
|
|
7680
|
-
- Coding conventions and patterns specific to this area
|
|
7681
|
-
- Build/test commands relevant to this area (if different from root)
|
|
7682
|
-
- Key files and directory structure within this area
|
|
7683
|
-
|
|
7684
|
-
IMPORTANT:
|
|
7685
|
-
- Focus ONLY on this specific area, not the whole repo
|
|
7686
|
-
- Do NOT repeat repo-wide information (that goes in the root copilot-instructions.md)
|
|
7687
|
-
- Keep it complementary to root instructions
|
|
7688
|
-
${existingSection ? `- Do NOT duplicate content already covered by existing instruction files
|
|
7689
|
-
${existingSection}` : ""}
|
|
7690
|
-
- When you have the complete markdown content, call the \`emit_file_content\` tool with it. Do NOT output the file content directly in chat.`;
|
|
8454
|
+
${existingSection ? `
|
|
8455
|
+
Do NOT duplicate content already covered by existing instruction files
|
|
8456
|
+
${existingSection}` : ""}`;
|
|
7691
8457
|
progress(`Analyzing area "${area.name}"...`);
|
|
7692
8458
|
let sendError;
|
|
7693
8459
|
try {
|
|
@@ -7724,7 +8490,7 @@ ${body}
|
|
|
7724
8490
|
`;
|
|
7725
8491
|
}
|
|
7726
8492
|
function areaInstructionPath(repoPath, area) {
|
|
7727
|
-
return
|
|
8493
|
+
return path7.join(
|
|
7728
8494
|
repoPath,
|
|
7729
8495
|
".github",
|
|
7730
8496
|
"instructions",
|
|
@@ -7734,7 +8500,7 @@ function areaInstructionPath(repoPath, area) {
|
|
|
7734
8500
|
async function writeAreaInstruction(repoPath, area, body, force) {
|
|
7735
8501
|
const filePath = areaInstructionPath(repoPath, area);
|
|
7736
8502
|
if (!body.trim()) return { status: "empty", filePath };
|
|
7737
|
-
await ensureDir(
|
|
8503
|
+
await ensureDir(path7.dirname(filePath));
|
|
7738
8504
|
const { wrote, reason } = await safeWriteFile(
|
|
7739
8505
|
filePath,
|
|
7740
8506
|
buildAreaInstructionContent(area, body),
|
|
@@ -7746,13 +8512,13 @@ async function writeAreaInstruction(repoPath, area, body, force) {
|
|
|
7746
8512
|
return { status: "written", filePath };
|
|
7747
8513
|
}
|
|
7748
8514
|
async function writeInstructionFile(repoPath, relativePath, content, force) {
|
|
7749
|
-
const resolvedRoot =
|
|
7750
|
-
const filePath =
|
|
7751
|
-
if (!filePath.startsWith(resolvedRoot +
|
|
8515
|
+
const resolvedRoot = path7.resolve(repoPath);
|
|
8516
|
+
const filePath = path7.resolve(repoPath, relativePath);
|
|
8517
|
+
if (!filePath.startsWith(resolvedRoot + path7.sep) && filePath !== resolvedRoot) {
|
|
7752
8518
|
throw new Error(`Invalid path: escapes repository root (${relativePath})`);
|
|
7753
8519
|
}
|
|
7754
8520
|
if (!content.trim()) return { status: "empty", filePath };
|
|
7755
|
-
await ensureDir(
|
|
8521
|
+
await ensureDir(path7.dirname(filePath));
|
|
7756
8522
|
const { wrote, reason } = await safeWriteFile(filePath, content, Boolean(force));
|
|
7757
8523
|
if (!wrote) {
|
|
7758
8524
|
return { status: reason === "symlink" ? "symlink" : "skipped", filePath };
|
|
@@ -7836,6 +8602,7 @@ async function generateNestedHub(client, options) {
|
|
|
7836
8602
|
const existingCtx = await detectExistingInstructions(options.repoPath, options.detailDir);
|
|
7837
8603
|
const existingSection = buildExistingInstructionsSection(existingCtx);
|
|
7838
8604
|
const { tool: emitTool, getContent } = await createEmitTool();
|
|
8605
|
+
const nestedSkillDir = getSkillDirectory("nested-hub");
|
|
7839
8606
|
const session = await client.createSession({
|
|
7840
8607
|
model,
|
|
7841
8608
|
streaming: true,
|
|
@@ -7846,7 +8613,8 @@ async function generateNestedHub(client, options) {
|
|
|
7846
8613
|
tools: [emitTool],
|
|
7847
8614
|
excludedTools: INSTRUCTION_GENERATION_EXCLUDED_TOOLS,
|
|
7848
8615
|
onPermissionRequest: READ_ONLY_PERMISSION_HANDLER,
|
|
7849
|
-
infiniteSessions: { enabled: false }
|
|
8616
|
+
infiniteSessions: { enabled: false },
|
|
8617
|
+
skillDirectories: [nestedSkillDir]
|
|
7850
8618
|
});
|
|
7851
8619
|
await trySetAutopilot(session);
|
|
7852
8620
|
let content = "";
|
|
@@ -7878,29 +8646,14 @@ ${options.childAreas.map((c) => `- ${c.name} (${c.path ?? "unknown path"})`).joi
|
|
|
7878
8646
|
Include a "## Sub-Projects" section with links to each child's AGENTS.md.` : "";
|
|
7879
8647
|
const parentContext = options.area?.parentArea ? `
|
|
7880
8648
|
This is a sub-project of "${options.area.parentArea}". Include a note linking back to the parent area.` : "";
|
|
7881
|
-
const prompt =
|
|
8649
|
+
const prompt = `/nested-hub Generate a lean AGENTS.md hub file (~90-120 lines).${areaContext}${parentContext}
|
|
7882
8650
|
|
|
7883
|
-
|
|
8651
|
+
Detail files go in \`${options.detailDir}/\`.${childContext}
|
|
7884
8652
|
|
|
7885
|
-
|
|
7886
|
-
|
|
7887
|
-
|
|
7888
|
-
|
|
7889
|
-
- A "## Detailed Instructions" section listing links to detail files in \`${options.detailDir}/\`${childContext}
|
|
7890
|
-
|
|
7891
|
-
At the END of your output, emit a fenced JSON block with recommended topics for detail files:
|
|
7892
|
-
\`\`\`json
|
|
7893
|
-
[{"slug":"testing","title":"Testing Guide","description":"How to write and run tests"},{"slug":"architecture","title":"Architecture","description":"Codebase structure and patterns"}]
|
|
7894
|
-
\`\`\`
|
|
7895
|
-
|
|
7896
|
-
Recommend 3-5 topics that would benefit from deep-dive detail files. Each slug becomes a filename: \`${options.detailDir}/{slug}.md\`.
|
|
7897
|
-
|
|
7898
|
-
IMPORTANT:
|
|
7899
|
-
- Keep the hub LEAN \u2014 overview and guardrails only, details go in separate files
|
|
7900
|
-
- The JSON block will be parsed and removed from the final output
|
|
7901
|
-
${existingSection ? `- Do NOT duplicate content from existing instruction files
|
|
7902
|
-
${existingSection}` : ""}
|
|
7903
|
-
- When you have the complete markdown content (including the trailing JSON topic block), call the \`emit_file_content\` tool with it. Do NOT output the content directly in chat.`;
|
|
8653
|
+
Recommend 3-5 topics for deep-dive detail files. Each slug becomes: \`${options.detailDir}/{slug}.md\`.
|
|
8654
|
+
${existingSection ? `
|
|
8655
|
+
Do NOT duplicate content from existing instruction files
|
|
8656
|
+
${existingSection}` : ""}`;
|
|
7904
8657
|
let sendError;
|
|
7905
8658
|
try {
|
|
7906
8659
|
await session.sendAndWait({ prompt }, 18e4);
|
|
@@ -7924,6 +8677,7 @@ async function generateNestedDetail(client, options) {
|
|
|
7924
8677
|
});
|
|
7925
8678
|
const model = options.model ?? DEFAULT_MODEL;
|
|
7926
8679
|
const { tool: emitTool, getContent } = await createEmitTool();
|
|
8680
|
+
const detailSkillDir = getSkillDirectory("nested-detail");
|
|
7927
8681
|
const session = await client.createSession({
|
|
7928
8682
|
model,
|
|
7929
8683
|
streaming: true,
|
|
@@ -7934,7 +8688,8 @@ async function generateNestedDetail(client, options) {
|
|
|
7934
8688
|
tools: [emitTool],
|
|
7935
8689
|
excludedTools: INSTRUCTION_GENERATION_EXCLUDED_TOOLS,
|
|
7936
8690
|
onPermissionRequest: READ_ONLY_PERMISSION_HANDLER,
|
|
7937
|
-
infiniteSessions: { enabled: false }
|
|
8691
|
+
infiniteSessions: { enabled: false },
|
|
8692
|
+
skillDirectories: [detailSkillDir]
|
|
7938
8693
|
});
|
|
7939
8694
|
await trySetAutopilot(session);
|
|
7940
8695
|
let content = "";
|
|
@@ -7956,22 +8711,11 @@ async function generateNestedDetail(client, options) {
|
|
|
7956
8711
|
}
|
|
7957
8712
|
});
|
|
7958
8713
|
const areaContext = options.area ? `Focus on the "${options.area.name}" area (files matching: ${Array.isArray(options.area.applyTo) ? options.area.applyTo.join(", ") : options.area.applyTo}).` : "Focus on the entire repository.";
|
|
7959
|
-
const prompt =
|
|
8714
|
+
const prompt = `/nested-detail Generate a deep-dive instruction file about "${options.topic.title}" for this codebase.
|
|
7960
8715
|
${areaContext}
|
|
7961
8716
|
|
|
7962
8717
|
Topic: ${options.topic.title}
|
|
7963
|
-
Description: ${options.topic.description}
|
|
7964
|
-
|
|
7965
|
-
Use tools to explore the codebase and understand the specific patterns, APIs, and conventions related to this topic.
|
|
7966
|
-
|
|
7967
|
-
The file should:
|
|
7968
|
-
- Start with \`# ${options.topic.title}\`
|
|
7969
|
-
- Include \`**When to read:** {one-line trigger condition}\` right after the heading
|
|
7970
|
-
- Cover ~50-100 lines of practical, actionable guidance
|
|
7971
|
-
- Include code patterns and examples found in the actual codebase
|
|
7972
|
-
- Be specific to this codebase, not generic advice
|
|
7973
|
-
|
|
7974
|
-
When you have the complete markdown content, call the \`emit_file_content\` tool with it. Do NOT output the content directly in chat.`;
|
|
8718
|
+
Description: ${options.topic.description}`;
|
|
7975
8719
|
let sendError;
|
|
7976
8720
|
try {
|
|
7977
8721
|
await session.sendAndWait({ prompt }, 18e4);
|
|
@@ -8006,7 +8750,7 @@ async function generateNestedInstructions(options) {
|
|
|
8006
8750
|
onProgress: options.onProgress
|
|
8007
8751
|
});
|
|
8008
8752
|
const basePath = options.area?.path ?? ".";
|
|
8009
|
-
const hubRelativePath =
|
|
8753
|
+
const hubRelativePath = path7.join(basePath, "AGENTS.md");
|
|
8010
8754
|
let finalHubContent = hubContent;
|
|
8011
8755
|
if (options.area) {
|
|
8012
8756
|
finalHubContent = `${buildAreaFrontmatter(options.area)}
|
|
@@ -8030,7 +8774,7 @@ ${hubContent}`;
|
|
|
8030
8774
|
});
|
|
8031
8775
|
if (detailContent) {
|
|
8032
8776
|
result.details.push({
|
|
8033
|
-
relativePath:
|
|
8777
|
+
relativePath: path7.join(basePath, options.detailDir, `${topic.slug}.md`),
|
|
8034
8778
|
content: detailContent,
|
|
8035
8779
|
topic: topic.title
|
|
8036
8780
|
});
|
|
@@ -8045,7 +8789,7 @@ ${hubContent}`;
|
|
|
8045
8789
|
}
|
|
8046
8790
|
if (options.claudeMd) {
|
|
8047
8791
|
result.claudeMd = {
|
|
8048
|
-
relativePath:
|
|
8792
|
+
relativePath: path7.join(basePath, "CLAUDE.md"),
|
|
8049
8793
|
content: "@AGENTS.md\n"
|
|
8050
8794
|
};
|
|
8051
8795
|
}
|
|
@@ -8066,13 +8810,218 @@ async function generateNestedAreaInstructions(options) {
|
|
|
8066
8810
|
});
|
|
8067
8811
|
}
|
|
8068
8812
|
|
|
8069
|
-
// packages/core/src/services/readiness.ts
|
|
8070
|
-
import
|
|
8071
|
-
import path8 from "path";
|
|
8813
|
+
// packages/core/src/services/readiness/index.ts
|
|
8814
|
+
import path12 from "path";
|
|
8072
8815
|
|
|
8073
8816
|
// packages/core/src/services/policy.ts
|
|
8074
8817
|
import fs6 from "fs/promises";
|
|
8075
|
-
import
|
|
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
|
|
8076
9025
|
var DEFAULT_PASS_RATE = 0.8;
|
|
8077
9026
|
function validatePolicyConfig(obj, source, format = "module") {
|
|
8078
9027
|
if (typeof obj !== "object" || obj === null) {
|
|
@@ -8163,10 +9112,20 @@ function parsePolicySources(raw) {
|
|
|
8163
9112
|
const sources = raw.split(",").map((s) => s.trim()).filter(Boolean);
|
|
8164
9113
|
return sources.length ? sources : void 0;
|
|
8165
9114
|
}
|
|
9115
|
+
function normalizeNativePlugin(plugin) {
|
|
9116
|
+
return {
|
|
9117
|
+
...plugin,
|
|
9118
|
+
meta: {
|
|
9119
|
+
...plugin.meta,
|
|
9120
|
+
sourceType: "module",
|
|
9121
|
+
trust: "trusted-code"
|
|
9122
|
+
}
|
|
9123
|
+
};
|
|
9124
|
+
}
|
|
8166
9125
|
async function loadPolicy(source, options) {
|
|
8167
9126
|
const jsonOnly = options?.jsonOnly ?? false;
|
|
8168
|
-
if (source.startsWith(".") ||
|
|
8169
|
-
const resolved =
|
|
9127
|
+
if (source.startsWith(".") || path8.isAbsolute(source)) {
|
|
9128
|
+
const resolved = path8.resolve(source);
|
|
8170
9129
|
if (resolved.endsWith(".json")) {
|
|
8171
9130
|
const data = await readJson(resolved);
|
|
8172
9131
|
if (!data) {
|
|
@@ -8181,8 +9140,12 @@ async function loadPolicy(source, options) {
|
|
|
8181
9140
|
);
|
|
8182
9141
|
}
|
|
8183
9142
|
try {
|
|
8184
|
-
const mod = await import(resolved);
|
|
9143
|
+
const mod = await import(pathToFileURL(resolved).href);
|
|
8185
9144
|
const config = mod.default ?? mod;
|
|
9145
|
+
if (isNativePlugin(config)) {
|
|
9146
|
+
validateNativePlugin(config, source);
|
|
9147
|
+
return normalizeNativePlugin(config);
|
|
9148
|
+
}
|
|
8186
9149
|
return validatePolicyConfig(config, source);
|
|
8187
9150
|
} catch (err) {
|
|
8188
9151
|
if (err instanceof Error && (err.message.includes("Cannot find module") || err.message.includes("MODULE_NOT_FOUND"))) {
|
|
@@ -8193,7 +9156,7 @@ async function loadPolicy(source, options) {
|
|
|
8193
9156
|
}
|
|
8194
9157
|
try {
|
|
8195
9158
|
const raw = await fs6.readFile(resolved, "utf8");
|
|
8196
|
-
const data = JSON.parse(raw);
|
|
9159
|
+
const data = JSON.parse(stripJsonComments(raw));
|
|
8197
9160
|
return validatePolicyConfig(data, source, "json");
|
|
8198
9161
|
} catch {
|
|
8199
9162
|
throw new Error(
|
|
@@ -8209,6 +9172,10 @@ async function loadPolicy(source, options) {
|
|
|
8209
9172
|
try {
|
|
8210
9173
|
const mod = await import(source);
|
|
8211
9174
|
const config = mod.default ?? mod;
|
|
9175
|
+
if (isNativePlugin(config)) {
|
|
9176
|
+
validateNativePlugin(config, source);
|
|
9177
|
+
return normalizeNativePlugin(config);
|
|
9178
|
+
}
|
|
8212
9179
|
return validatePolicyConfig(config, source);
|
|
8213
9180
|
} catch (err) {
|
|
8214
9181
|
const message = err instanceof Error ? err.message : typeof err === "object" && err !== null && "message" in err ? String(err.message) : String(err);
|
|
@@ -8272,130 +9239,6 @@ function resolveChain(baseCriteria, baseExtras, policies) {
|
|
|
8272
9239
|
return { chain, criteria, extras, thresholds: { passRate } };
|
|
8273
9240
|
}
|
|
8274
9241
|
|
|
8275
|
-
// packages/core/src/services/policy/types.ts
|
|
8276
|
-
var IMPACT_WEIGHTS = {
|
|
8277
|
-
critical: 5,
|
|
8278
|
-
high: 4,
|
|
8279
|
-
medium: 3,
|
|
8280
|
-
low: 2,
|
|
8281
|
-
info: 0
|
|
8282
|
-
};
|
|
8283
|
-
function calculateScore(signals, recommendations) {
|
|
8284
|
-
const activeSignals = signals.filter((s) => s.status !== "not-detected");
|
|
8285
|
-
if (activeSignals.length === 0) {
|
|
8286
|
-
return { score: 1, grade: "A" };
|
|
8287
|
-
}
|
|
8288
|
-
const maxWeight = activeSignals.length * IMPACT_WEIGHTS.critical;
|
|
8289
|
-
const deductions = recommendations.reduce((sum, rec) => sum + IMPACT_WEIGHTS[rec.impact], 0);
|
|
8290
|
-
const score = Math.max(0, Math.min(1, 1 - deductions / maxWeight));
|
|
8291
|
-
return { score, grade: scoreToGrade(score) };
|
|
8292
|
-
}
|
|
8293
|
-
function scoreToGrade(score) {
|
|
8294
|
-
if (score >= 0.9) return "A";
|
|
8295
|
-
if (score >= 0.8) return "B";
|
|
8296
|
-
if (score >= 0.7) return "C";
|
|
8297
|
-
if (score >= 0.6) return "D";
|
|
8298
|
-
return "F";
|
|
8299
|
-
}
|
|
8300
|
-
function applySignalPatch(signals, patch, pluginName) {
|
|
8301
|
-
let result = [...signals];
|
|
8302
|
-
if (patch.remove?.length) {
|
|
8303
|
-
const removeSet = new Set(patch.remove);
|
|
8304
|
-
result = result.filter((s) => !removeSet.has(s.id));
|
|
8305
|
-
}
|
|
8306
|
-
if (patch.modify?.length) {
|
|
8307
|
-
for (const mod of patch.modify) {
|
|
8308
|
-
const idx = result.findIndex((s) => s.id === mod.id);
|
|
8309
|
-
if (idx >= 0) {
|
|
8310
|
-
const existing = result[idx];
|
|
8311
|
-
const changes = { ...mod.changes };
|
|
8312
|
-
if (changes.metadata && existing.metadata) {
|
|
8313
|
-
changes.metadata = { ...existing.metadata, ...changes.metadata };
|
|
8314
|
-
}
|
|
8315
|
-
result[idx] = {
|
|
8316
|
-
...existing,
|
|
8317
|
-
...changes,
|
|
8318
|
-
origin: {
|
|
8319
|
-
...existing.origin,
|
|
8320
|
-
modifiedBy: [...existing.origin.modifiedBy ?? [], pluginName]
|
|
8321
|
-
}
|
|
8322
|
-
};
|
|
8323
|
-
}
|
|
8324
|
-
}
|
|
8325
|
-
}
|
|
8326
|
-
if (patch.add?.length) {
|
|
8327
|
-
result.push(
|
|
8328
|
-
...patch.add.map((s) => ({
|
|
8329
|
-
...s,
|
|
8330
|
-
evidence: s.evidence ? [...s.evidence] : void 0,
|
|
8331
|
-
metadata: s.metadata ? { ...s.metadata } : void 0
|
|
8332
|
-
}))
|
|
8333
|
-
);
|
|
8334
|
-
}
|
|
8335
|
-
return result;
|
|
8336
|
-
}
|
|
8337
|
-
function applyRecommendationPatch(recommendations, patch, pluginName) {
|
|
8338
|
-
let result = [...recommendations];
|
|
8339
|
-
if (patch.remove?.length) {
|
|
8340
|
-
const removeSet = new Set(patch.remove);
|
|
8341
|
-
result = result.filter((r) => !removeSet.has(r.id));
|
|
8342
|
-
}
|
|
8343
|
-
if (patch.modify?.length) {
|
|
8344
|
-
for (const mod of patch.modify) {
|
|
8345
|
-
const idx = result.findIndex((r) => r.id === mod.id);
|
|
8346
|
-
if (idx >= 0) {
|
|
8347
|
-
const existing = result[idx];
|
|
8348
|
-
result[idx] = {
|
|
8349
|
-
...existing,
|
|
8350
|
-
...mod.changes,
|
|
8351
|
-
origin: {
|
|
8352
|
-
...existing.origin,
|
|
8353
|
-
modifiedBy: [...existing.origin.modifiedBy ?? [], pluginName]
|
|
8354
|
-
}
|
|
8355
|
-
};
|
|
8356
|
-
}
|
|
8357
|
-
}
|
|
8358
|
-
}
|
|
8359
|
-
if (patch.add?.length) {
|
|
8360
|
-
result.push(
|
|
8361
|
-
...patch.add.map((r) => ({
|
|
8362
|
-
...r,
|
|
8363
|
-
supersedes: r.supersedes ? [...r.supersedes] : void 0,
|
|
8364
|
-
metadata: r.metadata ? { ...r.metadata } : void 0
|
|
8365
|
-
}))
|
|
8366
|
-
);
|
|
8367
|
-
}
|
|
8368
|
-
return result;
|
|
8369
|
-
}
|
|
8370
|
-
function resolveSupersedes(recommendations) {
|
|
8371
|
-
const supersededIds = /* @__PURE__ */ new Set();
|
|
8372
|
-
const recIds = new Set(recommendations.map((r) => r.id));
|
|
8373
|
-
for (const rec of recommendations) {
|
|
8374
|
-
if (rec.supersedes?.length) {
|
|
8375
|
-
for (const id of rec.supersedes) {
|
|
8376
|
-
if (recIds.has(id)) {
|
|
8377
|
-
supersededIds.add(id);
|
|
8378
|
-
}
|
|
8379
|
-
}
|
|
8380
|
-
}
|
|
8381
|
-
}
|
|
8382
|
-
return recommendations.filter((r) => !supersededIds.has(r.id)).map((r) => {
|
|
8383
|
-
if (!r.supersedes?.length) return r;
|
|
8384
|
-
const actuallySuperseded = r.supersedes.filter((id) => supersededIds.has(id));
|
|
8385
|
-
if (actuallySuperseded.length === 0) return r;
|
|
8386
|
-
return {
|
|
8387
|
-
...r,
|
|
8388
|
-
origin: {
|
|
8389
|
-
...r.origin,
|
|
8390
|
-
modifiedBy: [
|
|
8391
|
-
...r.origin.modifiedBy ?? [],
|
|
8392
|
-
...actuallySuperseded.map((id) => `superseded:${id}`)
|
|
8393
|
-
]
|
|
8394
|
-
}
|
|
8395
|
-
};
|
|
8396
|
-
});
|
|
8397
|
-
}
|
|
8398
|
-
|
|
8399
9242
|
// packages/core/src/services/policy/engine.ts
|
|
8400
9243
|
async function executePlugins(plugins, ctx, options) {
|
|
8401
9244
|
const warnings = [];
|
|
@@ -8701,9 +9544,21 @@ async function loadPluginChain(policySources, options) {
|
|
|
8701
9544
|
const allDisabledIds = [];
|
|
8702
9545
|
let passRateThreshold = 0.8;
|
|
8703
9546
|
for (const source of policySources) {
|
|
8704
|
-
const
|
|
9547
|
+
const loaded = await loadPolicy(source, {
|
|
8705
9548
|
jsonOnly: options?.jsonOnly
|
|
8706
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;
|
|
8707
9562
|
if (isImperativePlugin(policyConfig)) {
|
|
8708
9563
|
const { plugin: imperativePlugin, compiled } = wrapImperativePolicy(
|
|
8709
9564
|
policyConfig,
|
|
@@ -8749,252 +9604,382 @@ function wrapImperativePolicy(config, baseCriteria) {
|
|
|
8749
9604
|
return { plugin, compiled };
|
|
8750
9605
|
}
|
|
8751
9606
|
|
|
8752
|
-
// packages/core/src/services/readiness.ts
|
|
8753
|
-
|
|
8754
|
-
|
|
8755
|
-
|
|
8756
|
-
|
|
8757
|
-
documentation: "repo-health",
|
|
8758
|
-
"dev-environment": "repo-health",
|
|
8759
|
-
"code-quality": "repo-health",
|
|
8760
|
-
observability: "repo-health",
|
|
8761
|
-
"security-governance": "repo-health",
|
|
8762
|
-
"ai-tooling": "ai-setup"
|
|
8763
|
-
};
|
|
8764
|
-
var PILLAR_GROUP_NAMES = {
|
|
8765
|
-
"repo-health": "Repo Health",
|
|
8766
|
-
"ai-setup": "AI Setup"
|
|
8767
|
-
};
|
|
8768
|
-
function groupPillars(pillars) {
|
|
8769
|
-
const groups = ["repo-health", "ai-setup"];
|
|
8770
|
-
return groups.map((group) => ({
|
|
8771
|
-
group,
|
|
8772
|
-
label: PILLAR_GROUP_NAMES[group],
|
|
8773
|
-
pillars: pillars.filter((p) => PILLAR_GROUPS[p.id] === group)
|
|
8774
|
-
}));
|
|
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));
|
|
8775
9612
|
}
|
|
8776
|
-
function
|
|
8777
|
-
const
|
|
8778
|
-
|
|
8779
|
-
|
|
8780
|
-
|
|
8781
|
-
|
|
8782
|
-
|
|
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
|
+
);
|
|
9618
|
+
}
|
|
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
|
+
]);
|
|
9638
|
+
}
|
|
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;
|
|
9680
|
+
}
|
|
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
|
+
}
|
|
9720
|
+
}
|
|
9721
|
+
return paths;
|
|
9722
|
+
}
|
|
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"])
|
|
8783
9735
|
};
|
|
8784
|
-
return names[level] || "Unknown";
|
|
8785
9736
|
}
|
|
8786
|
-
function
|
|
8787
|
-
|
|
8788
|
-
|
|
8789
|
-
|
|
8790
|
-
|
|
8791
|
-
4: "MCP servers, custom agents, and AI skills are set up. Agents have deep integration with project-specific tools and workflows.",
|
|
8792
|
-
5: "Full AI-native development: agents can independently plan, implement, test, and ship changes with minimal human oversight."
|
|
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]
|
|
8793
9742
|
};
|
|
8794
|
-
return descriptions[level] || "";
|
|
8795
9743
|
}
|
|
8796
|
-
async function
|
|
8797
|
-
const
|
|
8798
|
-
|
|
8799
|
-
|
|
8800
|
-
|
|
8801
|
-
const apps = analysis.apps?.length ? analysis.apps : [];
|
|
8802
|
-
const context = {
|
|
8803
|
-
repoPath,
|
|
8804
|
-
analysis,
|
|
8805
|
-
apps,
|
|
8806
|
-
rootFiles,
|
|
8807
|
-
rootPackageJson
|
|
9744
|
+
async function parseVscodeLocations(repoPath, rootFiles) {
|
|
9745
|
+
const empty = {
|
|
9746
|
+
instructionsLocations: [],
|
|
9747
|
+
agentLocations: [],
|
|
9748
|
+
skillsLocations: []
|
|
8808
9749
|
};
|
|
8809
|
-
let
|
|
8810
|
-
|
|
8811
|
-
if (
|
|
8812
|
-
|
|
8813
|
-
|
|
8814
|
-
|
|
8815
|
-
|
|
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
|
+
);
|
|
8816
9763
|
}
|
|
8817
9764
|
}
|
|
8818
|
-
|
|
8819
|
-
|
|
8820
|
-
|
|
8821
|
-
|
|
8822
|
-
|
|
8823
|
-
|
|
8824
|
-
|
|
8825
|
-
|
|
8826
|
-
|
|
8827
|
-
|
|
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);
|
|
8828
9788
|
}
|
|
8829
|
-
const resolved = resolveChain(baseCriteria, baseExtras, policyConfigs);
|
|
8830
|
-
resolvedCriteria = resolved.criteria;
|
|
8831
|
-
resolvedExtras = resolved.extras;
|
|
8832
|
-
passRateThreshold = resolved.thresholds.passRate;
|
|
8833
|
-
policyInfo = { chain: resolved.chain, criteriaCount: resolved.criteria.length };
|
|
8834
|
-
} else {
|
|
8835
|
-
resolvedCriteria = baseCriteria;
|
|
8836
|
-
resolvedExtras = baseExtras;
|
|
8837
9789
|
}
|
|
8838
|
-
|
|
8839
|
-
|
|
8840
|
-
|
|
8841
|
-
|
|
8842
|
-
|
|
8843
|
-
|
|
8844
|
-
|
|
8845
|
-
|
|
8846
|
-
|
|
8847
|
-
scope: criterion.scope,
|
|
8848
|
-
impact: criterion.impact,
|
|
8849
|
-
effort: criterion.effort,
|
|
8850
|
-
status: result.status,
|
|
8851
|
-
reason: result.reason,
|
|
8852
|
-
evidence: result.evidence
|
|
8853
|
-
});
|
|
8854
|
-
continue;
|
|
8855
|
-
}
|
|
8856
|
-
if (criterion.scope === "area") {
|
|
8857
|
-
if (!options.perArea) continue;
|
|
8858
|
-
const areas2 = analysis.areas ?? [];
|
|
8859
|
-
if (areas2.length === 0) continue;
|
|
8860
|
-
criteriaResults.push({
|
|
8861
|
-
id: criterion.id,
|
|
8862
|
-
title: criterion.title,
|
|
8863
|
-
pillar: criterion.pillar,
|
|
8864
|
-
level: criterion.level,
|
|
8865
|
-
scope: criterion.scope,
|
|
8866
|
-
impact: criterion.impact,
|
|
8867
|
-
effort: criterion.effort,
|
|
8868
|
-
status: "skip",
|
|
8869
|
-
reason: "Run with --per-area for area breakdown."
|
|
8870
|
-
});
|
|
8871
|
-
continue;
|
|
8872
|
-
}
|
|
8873
|
-
const appResults = await Promise.all(
|
|
8874
|
-
apps.map(async (app) => ({
|
|
8875
|
-
app,
|
|
8876
|
-
result: await criterion.check(context, app)
|
|
8877
|
-
}))
|
|
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}`)
|
|
8878
9799
|
);
|
|
8879
|
-
|
|
8880
|
-
|
|
8881
|
-
|
|
8882
|
-
|
|
8883
|
-
|
|
8884
|
-
|
|
8885
|
-
|
|
8886
|
-
|
|
8887
|
-
|
|
8888
|
-
|
|
8889
|
-
|
|
8890
|
-
});
|
|
8891
|
-
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 {
|
|
8892
9811
|
}
|
|
8893
|
-
const passed = appResults.filter((entry) => entry.result.status === "pass").length;
|
|
8894
|
-
const total = appResults.length;
|
|
8895
|
-
const passRate = total ? passed / total : 0;
|
|
8896
|
-
const status = passRate >= passRateThreshold ? "pass" : "fail";
|
|
8897
|
-
const failures = appResults.filter((entry) => entry.result.status !== "pass").map((entry) => entry.app.name);
|
|
8898
|
-
criteriaResults.push({
|
|
8899
|
-
id: criterion.id,
|
|
8900
|
-
title: criterion.title,
|
|
8901
|
-
pillar: criterion.pillar,
|
|
8902
|
-
level: criterion.level,
|
|
8903
|
-
scope: criterion.scope,
|
|
8904
|
-
impact: criterion.impact,
|
|
8905
|
-
effort: criterion.effort,
|
|
8906
|
-
status,
|
|
8907
|
-
reason: status === "pass" ? void 0 : `Only ${passed}/${total} apps pass this check.`,
|
|
8908
|
-
passRate,
|
|
8909
|
-
appSummary: { passed, total },
|
|
8910
|
-
appFailures: failures
|
|
8911
|
-
});
|
|
8912
9812
|
}
|
|
8913
|
-
|
|
8914
|
-
|
|
8915
|
-
|
|
8916
|
-
|
|
8917
|
-
|
|
8918
|
-
|
|
8919
|
-
|
|
8920
|
-
|
|
8921
|
-
|
|
8922
|
-
|
|
8923
|
-
|
|
8924
|
-
|
|
8925
|
-
|
|
8926
|
-
|
|
8927
|
-
|
|
8928
|
-
|
|
8929
|
-
|
|
8930
|
-
|
|
8931
|
-
|
|
8932
|
-
|
|
8933
|
-
|
|
8934
|
-
|
|
8935
|
-
|
|
8936
|
-
|
|
8937
|
-
|
|
8938
|
-
|
|
8939
|
-
|
|
8940
|
-
|
|
8941
|
-
|
|
8942
|
-
|
|
8943
|
-
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]);
|
|
8944
9843
|
}
|
|
8945
|
-
|
|
8946
|
-
|
|
8947
|
-
|
|
8948
|
-
|
|
8949
|
-
|
|
8950
|
-
|
|
8951
|
-
|
|
8952
|
-
|
|
8953
|
-
|
|
8954
|
-
|
|
8955
|
-
|
|
8956
|
-
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("");
|
|
8957
9855
|
}
|
|
8958
9856
|
}
|
|
8959
|
-
|
|
8960
|
-
|
|
8961
|
-
|
|
8962
|
-
|
|
8963
|
-
|
|
8964
|
-
if (options.shadow) {
|
|
8965
|
-
const policyCtx = {
|
|
8966
|
-
repoPath,
|
|
8967
|
-
rootFiles,
|
|
8968
|
-
rootPackageJson,
|
|
8969
|
-
cache: /* @__PURE__ */ new Map(),
|
|
8970
|
-
analysis,
|
|
8971
|
-
apps
|
|
8972
|
-
};
|
|
8973
|
-
const engineChain = await loadPluginChain(policySources ?? [], { jsonOnly: isConfigSourced });
|
|
8974
|
-
const engineReport = await executePlugins(engineChain.plugins, policyCtx, engineChain.options);
|
|
8975
|
-
engine = {
|
|
8976
|
-
signals: engineReport.signals,
|
|
8977
|
-
recommendations: engineReport.recommendations,
|
|
8978
|
-
policyWarnings: engineReport.policyWarnings,
|
|
8979
|
-
score: engineReport.score,
|
|
8980
|
-
grade: engineReport.grade
|
|
8981
|
-
};
|
|
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
|
+
}
|
|
8982
9862
|
}
|
|
8983
9863
|
return {
|
|
8984
|
-
|
|
8985
|
-
|
|
8986
|
-
|
|
8987
|
-
apps: apps.map((app) => ({ name: app.name, path: app.path })),
|
|
8988
|
-
pillars,
|
|
8989
|
-
levels,
|
|
8990
|
-
achievedLevel,
|
|
8991
|
-
criteria: criteriaResults,
|
|
8992
|
-
extras,
|
|
8993
|
-
areaReports,
|
|
8994
|
-
policies: policyInfo,
|
|
8995
|
-
engine
|
|
9864
|
+
unified: minSimilarity >= 0.9,
|
|
9865
|
+
files: foundFiles,
|
|
9866
|
+
similarity: Math.round(minSimilarity * 100) / 100
|
|
8996
9867
|
};
|
|
8997
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";
|
|
8998
9983
|
function buildCriteria() {
|
|
8999
9984
|
return [
|
|
9000
9985
|
{
|
|
@@ -9106,7 +10091,7 @@ function buildCriteria() {
|
|
|
9106
10091
|
impact: "medium",
|
|
9107
10092
|
effort: "low",
|
|
9108
10093
|
check: async (context) => {
|
|
9109
|
-
const found = await fileExists(
|
|
10094
|
+
const found = await fileExists(path10.join(context.repoPath, "CONTRIBUTING.md"));
|
|
9110
10095
|
return {
|
|
9111
10096
|
status: found ? "pass" : "fail",
|
|
9112
10097
|
reason: found ? void 0 : "Missing CONTRIBUTING.md for contributor workflows."
|
|
@@ -9207,7 +10192,7 @@ function buildCriteria() {
|
|
|
9207
10192
|
impact: "high",
|
|
9208
10193
|
effort: "low",
|
|
9209
10194
|
check: async (context) => {
|
|
9210
|
-
const found = await fileExists(
|
|
10195
|
+
const found = await fileExists(path10.join(context.repoPath, "SECURITY.md"));
|
|
9211
10196
|
return {
|
|
9212
10197
|
status: found ? "pass" : "fail",
|
|
9213
10198
|
reason: found ? void 0 : "Missing SECURITY.md policy."
|
|
@@ -9223,7 +10208,7 @@ function buildCriteria() {
|
|
|
9223
10208
|
impact: "medium",
|
|
9224
10209
|
effort: "medium",
|
|
9225
10210
|
check: async (context) => {
|
|
9226
|
-
const found = await fileExists(
|
|
10211
|
+
const found = await fileExists(path10.join(context.repoPath, ".github", "dependabot.yml"));
|
|
9227
10212
|
return {
|
|
9228
10213
|
status: found ? "pass" : "fail",
|
|
9229
10214
|
reason: found ? void 0 : "Missing .github/dependabot.yml configuration."
|
|
@@ -9272,7 +10257,10 @@ function buildCriteria() {
|
|
|
9272
10257
|
]
|
|
9273
10258
|
};
|
|
9274
10259
|
}
|
|
9275
|
-
const fileBasedInstructions = await hasFileBasedInstructions(
|
|
10260
|
+
const fileBasedInstructions = await hasFileBasedInstructions(
|
|
10261
|
+
context.repoPath,
|
|
10262
|
+
context.vscodeLocations?.instructionsLocations
|
|
10263
|
+
);
|
|
9276
10264
|
const areas = context.analysis.areas ?? [];
|
|
9277
10265
|
if (areas.length > 0) {
|
|
9278
10266
|
if (fileBasedInstructions.length === 0) {
|
|
@@ -9288,6 +10276,13 @@ function buildCriteria() {
|
|
|
9288
10276
|
evidence: [...rootFound, ...fileBasedInstructions]
|
|
9289
10277
|
};
|
|
9290
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
|
+
}
|
|
9291
10286
|
if (context.analysis.isMonorepo && context.apps.length > 1) {
|
|
9292
10287
|
const appsMissing = [];
|
|
9293
10288
|
for (const app of context.apps) {
|
|
@@ -9367,7 +10362,10 @@ function buildCriteria() {
|
|
|
9367
10362
|
impact: "medium",
|
|
9368
10363
|
effort: "medium",
|
|
9369
10364
|
check: async (context) => {
|
|
9370
|
-
const found = await hasCustomAgents(
|
|
10365
|
+
const found = await hasCustomAgents(
|
|
10366
|
+
context.repoPath,
|
|
10367
|
+
context.vscodeLocations?.agentLocations
|
|
10368
|
+
);
|
|
9371
10369
|
return {
|
|
9372
10370
|
status: found.length > 0 ? "pass" : "fail",
|
|
9373
10371
|
reason: "No custom AI agents configured (e.g. .github/agents/, .copilot/agents/).",
|
|
@@ -9384,7 +10382,10 @@ function buildCriteria() {
|
|
|
9384
10382
|
impact: "medium",
|
|
9385
10383
|
effort: "medium",
|
|
9386
10384
|
check: async (context) => {
|
|
9387
|
-
const found = await hasCopilotSkills(
|
|
10385
|
+
const found = await hasCopilotSkills(
|
|
10386
|
+
context.repoPath,
|
|
10387
|
+
context.vscodeLocations?.skillsLocations
|
|
10388
|
+
);
|
|
9388
10389
|
return {
|
|
9389
10390
|
status: found.length > 0 ? "pass" : "fail",
|
|
9390
10391
|
reason: "No Copilot or Claude skills found (e.g. .copilot/skills/, .github/skills/).",
|
|
@@ -9392,6 +10393,65 @@ function buildCriteria() {
|
|
|
9392
10393
|
};
|
|
9393
10394
|
}
|
|
9394
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
|
+
},
|
|
9395
10455
|
// ── Area-scoped criteria (only run when areaPath is set) ──
|
|
9396
10456
|
{
|
|
9397
10457
|
id: "area-readme",
|
|
@@ -9429,7 +10489,7 @@ function buildCriteria() {
|
|
|
9429
10489
|
if (area?.scripts?.build) {
|
|
9430
10490
|
return { status: "pass" };
|
|
9431
10491
|
}
|
|
9432
|
-
const pkgPath =
|
|
10492
|
+
const pkgPath = path10.join(context.areaPath, "package.json");
|
|
9433
10493
|
const pkg = await readJson(pkgPath);
|
|
9434
10494
|
const scripts = pkg?.scripts ?? {};
|
|
9435
10495
|
const found = Boolean(scripts.build);
|
|
@@ -9454,7 +10514,7 @@ function buildCriteria() {
|
|
|
9454
10514
|
if (area?.scripts?.test) {
|
|
9455
10515
|
return { status: "pass" };
|
|
9456
10516
|
}
|
|
9457
|
-
const pkgPath =
|
|
10517
|
+
const pkgPath = path10.join(context.areaPath, "package.json");
|
|
9458
10518
|
const pkg = await readJson(pkgPath);
|
|
9459
10519
|
const scripts = pkg?.scripts ?? {};
|
|
9460
10520
|
const found = Boolean(scripts.test);
|
|
@@ -9477,7 +10537,7 @@ function buildCriteria() {
|
|
|
9477
10537
|
return { status: "skip", reason: "No area context." };
|
|
9478
10538
|
}
|
|
9479
10539
|
const sanitized = sanitizeAreaName(area.name);
|
|
9480
|
-
const instructionPath =
|
|
10540
|
+
const instructionPath = path10.join(
|
|
9481
10541
|
context.repoPath,
|
|
9482
10542
|
".github",
|
|
9483
10543
|
"instructions",
|
|
@@ -9492,13 +10552,16 @@ function buildCriteria() {
|
|
|
9492
10552
|
}
|
|
9493
10553
|
];
|
|
9494
10554
|
}
|
|
10555
|
+
|
|
10556
|
+
// packages/core/src/services/readiness/extras.ts
|
|
10557
|
+
import path11 from "path";
|
|
9495
10558
|
function buildExtras() {
|
|
9496
10559
|
return [
|
|
9497
10560
|
{
|
|
9498
10561
|
id: "agents-doc",
|
|
9499
10562
|
title: "AGENTS.md present",
|
|
9500
10563
|
check: async (context) => {
|
|
9501
|
-
const found = await fileExists(
|
|
10564
|
+
const found = await fileExists(path11.join(context.repoPath, "AGENTS.md"));
|
|
9502
10565
|
return {
|
|
9503
10566
|
status: found ? "pass" : "fail",
|
|
9504
10567
|
reason: found ? void 0 : "Missing AGENTS.md to guide coding agents."
|
|
@@ -9540,18 +10603,65 @@ function buildExtras() {
|
|
|
9540
10603
|
}
|
|
9541
10604
|
];
|
|
9542
10605
|
}
|
|
9543
|
-
async function runExtras(context, extraDefs) {
|
|
9544
|
-
const results = [];
|
|
9545
|
-
for (const def of extraDefs) {
|
|
9546
|
-
const result = await def.check(context);
|
|
9547
|
-
results.push({
|
|
9548
|
-
id: def.id,
|
|
9549
|
-
title: def.title,
|
|
9550
|
-
status: result.status,
|
|
9551
|
-
reason: result.reason
|
|
9552
|
-
});
|
|
9553
|
-
}
|
|
9554
|
-
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] || "";
|
|
9555
10665
|
}
|
|
9556
10666
|
function summarizePillars(criteria) {
|
|
9557
10667
|
const pillarNames = {
|
|
@@ -9613,246 +10723,225 @@ function countStatus(items) {
|
|
|
9613
10723
|
const passed = relevant.filter((item) => item.status === "pass").length;
|
|
9614
10724
|
return { passed, total: relevant.length };
|
|
9615
10725
|
}
|
|
9616
|
-
|
|
9617
|
-
|
|
9618
|
-
|
|
9619
|
-
|
|
9620
|
-
const
|
|
9621
|
-
|
|
9622
|
-
|
|
9623
|
-
|
|
9624
|
-
|
|
9625
|
-
|
|
9626
|
-
|
|
9627
|
-
|
|
9628
|
-
|
|
9629
|
-
|
|
9630
|
-
|
|
9631
|
-
|
|
9632
|
-
|
|
9633
|
-
|
|
9634
|
-
|
|
9635
|
-
|
|
9636
|
-
|
|
9637
|
-
|
|
9638
|
-
|
|
9639
|
-
|
|
9640
|
-
".prettierrc.cjs",
|
|
9641
|
-
"prettier.config.js",
|
|
9642
|
-
"prettier.config.cjs"
|
|
9643
|
-
]);
|
|
9644
|
-
}
|
|
9645
|
-
async function hasFormatterConfig(repoPath) {
|
|
9646
|
-
return hasAnyFile(await safeReadDir(repoPath), [
|
|
9647
|
-
"biome.json",
|
|
9648
|
-
"biome.jsonc",
|
|
9649
|
-
".prettierrc",
|
|
9650
|
-
".prettierrc.json",
|
|
9651
|
-
".prettierrc.js",
|
|
9652
|
-
".prettierrc.cjs",
|
|
9653
|
-
"prettier.config.js",
|
|
9654
|
-
"prettier.config.cjs"
|
|
9655
|
-
]);
|
|
9656
|
-
}
|
|
9657
|
-
async function hasTypecheckConfig(repoPath) {
|
|
9658
|
-
return hasAnyFile(await safeReadDir(repoPath), [
|
|
9659
|
-
"tsconfig.json",
|
|
9660
|
-
"tsconfig.base.json",
|
|
9661
|
-
"pyproject.toml",
|
|
9662
|
-
"mypy.ini"
|
|
9663
|
-
]);
|
|
9664
|
-
}
|
|
9665
|
-
async function hasGithubWorkflows(repoPath) {
|
|
9666
|
-
return fileExists(path8.join(repoPath, ".github", "workflows"));
|
|
9667
|
-
}
|
|
9668
|
-
async function hasCodeowners(repoPath) {
|
|
9669
|
-
const root = await fileExists(path8.join(repoPath, "CODEOWNERS"));
|
|
9670
|
-
const github = await fileExists(path8.join(repoPath, ".github", "CODEOWNERS"));
|
|
9671
|
-
return root || github;
|
|
9672
|
-
}
|
|
9673
|
-
async function hasLicense(repoPath) {
|
|
9674
|
-
const files = await safeReadDir(repoPath);
|
|
9675
|
-
return files.some((file) => file.toLowerCase().startsWith("license"));
|
|
9676
|
-
}
|
|
9677
|
-
async function hasPullRequestTemplate(repoPath) {
|
|
9678
|
-
const direct = await fileExists(path8.join(repoPath, ".github", "PULL_REQUEST_TEMPLATE.md"));
|
|
9679
|
-
if (direct) return true;
|
|
9680
|
-
const dir = path8.join(repoPath, ".github", "PULL_REQUEST_TEMPLATE");
|
|
9681
|
-
try {
|
|
9682
|
-
const entries = await fs7.readdir(dir);
|
|
9683
|
-
return entries.some((entry) => entry.toLowerCase().endsWith(".md"));
|
|
9684
|
-
} catch {
|
|
9685
|
-
return false;
|
|
9686
|
-
}
|
|
9687
|
-
}
|
|
9688
|
-
async function hasPrecommitConfig(repoPath) {
|
|
9689
|
-
const precommit = await fileExists(path8.join(repoPath, ".pre-commit-config.yaml"));
|
|
9690
|
-
if (precommit) return true;
|
|
9691
|
-
return fileExists(path8.join(repoPath, ".husky"));
|
|
9692
|
-
}
|
|
9693
|
-
async function hasArchitectureDoc(repoPath) {
|
|
9694
|
-
const files = await safeReadDir(repoPath);
|
|
9695
|
-
if (files.some((file) => file.toLowerCase() === "architecture.md")) return true;
|
|
9696
|
-
return fileExists(path8.join(repoPath, "docs", "architecture.md"));
|
|
9697
|
-
}
|
|
9698
|
-
async function hasCustomInstructions(repoPath) {
|
|
9699
|
-
const found = [];
|
|
9700
|
-
const candidates = [
|
|
9701
|
-
".github/copilot-instructions.md",
|
|
9702
|
-
"CLAUDE.md",
|
|
9703
|
-
".claude/CLAUDE.md",
|
|
9704
|
-
"AGENTS.md",
|
|
9705
|
-
".github/AGENTS.md",
|
|
9706
|
-
".cursorrules",
|
|
9707
|
-
".cursorignore",
|
|
9708
|
-
".windsurfrules",
|
|
9709
|
-
".github/instructions.md",
|
|
9710
|
-
"copilot-instructions.md"
|
|
9711
|
-
];
|
|
9712
|
-
for (const candidate of candidates) {
|
|
9713
|
-
if (await fileExists(path8.join(repoPath, candidate))) {
|
|
9714
|
-
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;
|
|
9715
10750
|
}
|
|
9716
10751
|
}
|
|
9717
|
-
|
|
9718
|
-
|
|
9719
|
-
|
|
9720
|
-
|
|
9721
|
-
|
|
9722
|
-
|
|
9723
|
-
|
|
9724
|
-
|
|
9725
|
-
|
|
9726
|
-
|
|
9727
|
-
}
|
|
9728
|
-
|
|
9729
|
-
|
|
9730
|
-
|
|
9731
|
-
|
|
9732
|
-
|
|
9733
|
-
const setB = normalize(b);
|
|
9734
|
-
if (setA.size === 0 && setB.size === 0) return 1;
|
|
9735
|
-
let intersection = 0;
|
|
9736
|
-
for (const line of setA) {
|
|
9737
|
-
if (setB.has(line)) intersection++;
|
|
9738
|
-
}
|
|
9739
|
-
const union = (/* @__PURE__ */ new Set([...setA, ...setB])).size;
|
|
9740
|
-
return union === 0 ? 1 : intersection / union;
|
|
9741
|
-
}
|
|
9742
|
-
async function checkInstructionConsistency(repoPath, foundFiles) {
|
|
9743
|
-
if (foundFiles.length <= 1) {
|
|
9744
|
-
return { unified: true, files: foundFiles };
|
|
9745
|
-
}
|
|
9746
|
-
const realPathMap = /* @__PURE__ */ new Map();
|
|
9747
|
-
for (const file of foundFiles) {
|
|
9748
|
-
const fullPath = path8.join(repoPath, file);
|
|
9749
|
-
try {
|
|
9750
|
-
const real = await fs7.realpath(fullPath);
|
|
9751
|
-
const group = realPathMap.get(real) ?? [];
|
|
9752
|
-
group.push(file);
|
|
9753
|
-
realPathMap.set(real, group);
|
|
9754
|
-
} catch {
|
|
9755
|
-
realPathMap.set(fullPath, [file]);
|
|
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);
|
|
9756
10768
|
}
|
|
9757
|
-
|
|
9758
|
-
|
|
9759
|
-
|
|
9760
|
-
|
|
9761
|
-
|
|
9762
|
-
|
|
9763
|
-
|
|
9764
|
-
|
|
9765
|
-
|
|
9766
|
-
} catch {
|
|
9767
|
-
contents.push("");
|
|
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;
|
|
9768
10778
|
}
|
|
9769
|
-
|
|
9770
|
-
|
|
9771
|
-
for (let i = 0; i < contents.length; i++) {
|
|
9772
|
-
for (let j = i + 1; j < contents.length; j++) {
|
|
9773
|
-
minSimilarity = Math.min(minSimilarity, contentSimilarity(contents[i], contents[j]));
|
|
10779
|
+
if (hasNativePlugin && !options.shadow) {
|
|
10780
|
+
options = { ...options, shadow: true };
|
|
9774
10781
|
}
|
|
10782
|
+
} else {
|
|
10783
|
+
resolvedCriteria = baseCriteria;
|
|
10784
|
+
resolvedExtras = baseExtras;
|
|
9775
10785
|
}
|
|
9776
|
-
|
|
9777
|
-
|
|
9778
|
-
|
|
9779
|
-
|
|
9780
|
-
|
|
9781
|
-
|
|
9782
|
-
|
|
9783
|
-
|
|
9784
|
-
|
|
9785
|
-
|
|
9786
|
-
|
|
9787
|
-
|
|
9788
|
-
|
|
9789
|
-
|
|
9790
|
-
|
|
9791
|
-
|
|
9792
|
-
|
|
9793
|
-
|
|
9794
|
-
|
|
9795
|
-
|
|
9796
|
-
|
|
9797
|
-
|
|
9798
|
-
|
|
9799
|
-
|
|
9800
|
-
|
|
9801
|
-
|
|
9802
|
-
|
|
9803
|
-
|
|
9804
|
-
|
|
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;
|
|
9805
10820
|
}
|
|
9806
|
-
|
|
9807
|
-
|
|
9808
|
-
|
|
9809
|
-
|
|
9810
|
-
|
|
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;
|
|
9811
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
|
+
});
|
|
9812
10860
|
}
|
|
9813
|
-
|
|
9814
|
-
|
|
9815
|
-
|
|
9816
|
-
|
|
9817
|
-
|
|
9818
|
-
|
|
9819
|
-
|
|
9820
|
-
|
|
9821
|
-
|
|
9822
|
-
|
|
9823
|
-
|
|
9824
|
-
|
|
9825
|
-
|
|
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 });
|
|
10892
|
+
}
|
|
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);
|
|
9826
10905
|
}
|
|
9827
10906
|
}
|
|
9828
|
-
|
|
9829
|
-
|
|
9830
|
-
|
|
9831
|
-
const
|
|
9832
|
-
|
|
9833
|
-
|
|
9834
|
-
|
|
9835
|
-
|
|
9836
|
-
|
|
9837
|
-
|
|
9838
|
-
|
|
9839
|
-
|
|
9840
|
-
|
|
9841
|
-
|
|
9842
|
-
|
|
9843
|
-
);
|
|
9844
|
-
|
|
9845
|
-
|
|
9846
|
-
|
|
9847
|
-
|
|
9848
|
-
|
|
9849
|
-
|
|
9850
|
-
|
|
9851
|
-
...rootDevDeps
|
|
9852
|
-
})
|
|
9853
|
-
);
|
|
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
|
+
};
|
|
9854
10930
|
}
|
|
9855
|
-
return
|
|
10931
|
+
return {
|
|
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
|
|
10944
|
+
};
|
|
9856
10945
|
}
|
|
9857
10946
|
|
|
9858
10947
|
// packages/core/src/services/batch.ts
|
|
@@ -9874,7 +10963,7 @@ async function processRepo(params) {
|
|
|
9874
10963
|
} = params;
|
|
9875
10964
|
try {
|
|
9876
10965
|
progress?.update(`${label}: Cloning...`);
|
|
9877
|
-
const cacheRoot =
|
|
10966
|
+
const cacheRoot = path13.join(process.cwd(), ".agentrc-cache");
|
|
9878
10967
|
const repoPath = validateCachePath(cacheRoot, ...cacheParts);
|
|
9879
10968
|
await ensureDir(repoPath);
|
|
9880
10969
|
if (!await isGitRepo(repoPath)) {
|
|
@@ -9900,8 +10989,8 @@ async function processRepo(params) {
|
|
|
9900
10989
|
if (!instructions.trim()) {
|
|
9901
10990
|
throw new Error("Generated instructions were empty");
|
|
9902
10991
|
}
|
|
9903
|
-
const instructionsPath =
|
|
9904
|
-
await ensureDir(
|
|
10992
|
+
const instructionsPath = path13.join(repoPath, ".github", "copilot-instructions.md");
|
|
10993
|
+
await ensureDir(path13.dirname(instructionsPath));
|
|
9905
10994
|
const { wrote, reason } = await safeWriteFile(instructionsPath, instructions, true);
|
|
9906
10995
|
if (!wrote) {
|
|
9907
10996
|
throw new Error(
|
|
@@ -10038,7 +11127,7 @@ async function processBatchReadinessRepo(options) {
|
|
|
10038
11127
|
try {
|
|
10039
11128
|
progress(`Cloning ${repo.fullName}...`);
|
|
10040
11129
|
const authedUrl = buildAuthedUrl(repo.cloneUrl, token, "github");
|
|
10041
|
-
await ensureDir(
|
|
11130
|
+
await ensureDir(path13.dirname(repoDir));
|
|
10042
11131
|
await cloneRepo(authedUrl, repoDir, { shallow: true });
|
|
10043
11132
|
await setRemoteUrl(repoDir, repo.cloneUrl).catch(() => {
|
|
10044
11133
|
});
|
|
@@ -11088,7 +12177,7 @@ import { render as render2 } from "ink";
|
|
|
11088
12177
|
// src/ui/BatchReadinessTui.tsx
|
|
11089
12178
|
import fs8 from "fs/promises";
|
|
11090
12179
|
import os from "os";
|
|
11091
|
-
import
|
|
12180
|
+
import path14 from "path";
|
|
11092
12181
|
|
|
11093
12182
|
// packages/core/src/services/visualReport.ts
|
|
11094
12183
|
function generateVisualReport(options) {
|
|
@@ -12114,7 +13203,7 @@ function BatchReadinessTui({ token, outputPath, policies }) {
|
|
|
12114
13203
|
setStatus("processing");
|
|
12115
13204
|
const selectedRepos = Array.from(selectedRepoIndices).map((i) => repos[i]);
|
|
12116
13205
|
const results2 = [];
|
|
12117
|
-
const tmpDir =
|
|
13206
|
+
const tmpDir = path14.join(os.tmpdir(), `agentrc-batch-readiness-${Date.now()}`);
|
|
12118
13207
|
try {
|
|
12119
13208
|
await ensureDir(tmpDir);
|
|
12120
13209
|
for (let i = 0; i < selectedRepos.length; i++) {
|
|
@@ -12151,7 +13240,7 @@ function BatchReadinessTui({ token, outputPath, policies }) {
|
|
|
12151
13240
|
title: "Batch Readiness Report",
|
|
12152
13241
|
generatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
12153
13242
|
});
|
|
12154
|
-
const finalOutputPath = outputPath ??
|
|
13243
|
+
const finalOutputPath = outputPath ?? path14.join(process.cwd(), "batch-readiness-report.html");
|
|
12155
13244
|
const { wrote, reason } = await safeWriteFile(finalOutputPath, html, true);
|
|
12156
13245
|
if (!wrote) throw new Error(reason === "symlink" ? "Path is a symlink" : "Write failed");
|
|
12157
13246
|
setStatus("complete");
|
|
@@ -12333,7 +13422,7 @@ async function batchReadinessCommand(options) {
|
|
|
12333
13422
|
}
|
|
12334
13423
|
|
|
12335
13424
|
// src/commands/eval.ts
|
|
12336
|
-
import
|
|
13425
|
+
import path16 from "path";
|
|
12337
13426
|
|
|
12338
13427
|
// packages/core/src/services/evalScaffold.ts
|
|
12339
13428
|
var EVAL_SCAFFOLD_TIMEOUT_MS = 6e5;
|
|
@@ -12355,7 +13444,7 @@ async function generateEvalScaffold(options) {
|
|
|
12355
13444
|
streaming: true,
|
|
12356
13445
|
workingDirectory: repoPath,
|
|
12357
13446
|
systemMessage: {
|
|
12358
|
-
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})."
|
|
12359
13448
|
},
|
|
12360
13449
|
infiniteSessions: { enabled: false }
|
|
12361
13450
|
});
|
|
@@ -12397,32 +13486,37 @@ async function generateEvalScaffold(options) {
|
|
|
12397
13486
|
'For areas with a workspace (workingDirectory), include a "workingDirectory" field set to that workspace path so evals run scoped to the correct folder.'
|
|
12398
13487
|
].join("\n") : "";
|
|
12399
13488
|
const prompt = [
|
|
12400
|
-
`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.",
|
|
12401
13493
|
"",
|
|
12402
|
-
"
|
|
12403
|
-
"
|
|
12404
|
-
"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'",
|
|
12405
13503
|
"",
|
|
12406
|
-
"
|
|
12407
|
-
"-
|
|
12408
|
-
"-
|
|
12409
|
-
"-
|
|
12410
|
-
"-
|
|
12411
|
-
"-
|
|
12412
|
-
"- 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.",
|
|
12413
13510
|
"",
|
|
12414
|
-
"Bad
|
|
12415
|
-
"- 'What does this project do?' (
|
|
12416
|
-
"- '
|
|
12417
|
-
"-
|
|
12418
|
-
"- 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",
|
|
12419
13515
|
"",
|
|
12420
|
-
"
|
|
12421
|
-
"If this is a monorepo
|
|
12422
|
-
"Ensure cases cover cross-cutting concerns: data flow, error propagation, configuration impact, implicit coupling, architectural invariants.",
|
|
12423
|
-
"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.",
|
|
12424
13518
|
"Return JSON ONLY (no markdown, no commentary) in this schema:",
|
|
12425
|
-
'{\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}',
|
|
12426
13520
|
areaContext
|
|
12427
13521
|
].join("\n");
|
|
12428
13522
|
progress("Analyzing codebase...");
|
|
@@ -12468,7 +13562,8 @@ async function generateEvalScaffold(options) {
|
|
|
12468
13562
|
}
|
|
12469
13563
|
throw error;
|
|
12470
13564
|
}
|
|
12471
|
-
const
|
|
13565
|
+
const hasAreas = Boolean(options.areas?.length);
|
|
13566
|
+
const normalized = normalizeEvalConfig(parsed, count, hasAreas);
|
|
12472
13567
|
return normalized;
|
|
12473
13568
|
} finally {
|
|
12474
13569
|
await client.stop();
|
|
@@ -12492,41 +13587,47 @@ function parseEvalConfig(raw) {
|
|
|
12492
13587
|
}
|
|
12493
13588
|
return parsed;
|
|
12494
13589
|
}
|
|
12495
|
-
function normalizeEvalConfig(parsed, count) {
|
|
13590
|
+
function normalizeEvalConfig(parsed, count, hasAreas = true) {
|
|
12496
13591
|
const cases = (parsed.cases ?? []).slice(0, count).map((entry, index) => {
|
|
12497
13592
|
const id = typeof entry.id === "string" && entry.id.trim() ? entry.id : `case-${index + 1}`;
|
|
12498
13593
|
return {
|
|
12499
13594
|
id,
|
|
12500
13595
|
prompt: String(entry.prompt ?? "").trim(),
|
|
12501
|
-
expectation:
|
|
12502
|
-
|
|
13596
|
+
expectation: normalizeExpectation(entry.expectation),
|
|
13597
|
+
...hasAreas && typeof entry.area === "string" && entry.area.trim() ? { area: entry.area.trim() } : {},
|
|
12503
13598
|
workingDirectory: typeof entry.workingDirectory === "string" && entry.workingDirectory.trim() ? entry.workingDirectory.trim() : void 0
|
|
12504
13599
|
};
|
|
12505
13600
|
});
|
|
12506
13601
|
if (!cases.length) {
|
|
12507
13602
|
throw new Error("Eval scaffold JSON did not include any usable cases.");
|
|
12508
13603
|
}
|
|
12509
|
-
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.";
|
|
12510
13604
|
return {
|
|
12511
13605
|
instructionFile: parsed.instructionFile ?? ".github/copilot-instructions.md",
|
|
12512
|
-
systemMessage: parsed.systemMessage
|
|
13606
|
+
...parsed.systemMessage ? { systemMessage: parsed.systemMessage } : {},
|
|
12513
13607
|
cases
|
|
12514
13608
|
};
|
|
12515
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
|
+
}
|
|
12516
13617
|
|
|
12517
13618
|
// packages/core/src/services/evaluator.ts
|
|
12518
13619
|
import fs9 from "fs/promises";
|
|
12519
|
-
import
|
|
12520
|
-
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.";
|
|
12521
13622
|
async function runEval(options) {
|
|
12522
13623
|
const config = await loadConfig(options.configPath);
|
|
12523
13624
|
const instructionFile = config.instructionFile ?? ".github/copilot-instructions.md";
|
|
12524
|
-
const instructionPath =
|
|
13625
|
+
const instructionPath = path15.resolve(options.repoPath, instructionFile);
|
|
12525
13626
|
const instructionText = await readOptionalFile(instructionPath);
|
|
12526
13627
|
const baseSystemMessage = config.systemMessage ?? DEFAULT_SYSTEM_MESSAGE;
|
|
12527
13628
|
const progress = options.onProgress ?? (() => {
|
|
12528
13629
|
});
|
|
12529
|
-
const defaultOutputPath =
|
|
13630
|
+
const defaultOutputPath = path15.resolve(
|
|
12530
13631
|
options.repoPath,
|
|
12531
13632
|
".agentrc",
|
|
12532
13633
|
"evals",
|
|
@@ -12546,9 +13647,9 @@ async function runEval(options) {
|
|
|
12546
13647
|
const caseStartedAt = Date.now();
|
|
12547
13648
|
let caseWorkingDir;
|
|
12548
13649
|
if (testCase.workingDirectory) {
|
|
12549
|
-
const resolved =
|
|
12550
|
-
const root =
|
|
12551
|
-
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)) {
|
|
12552
13653
|
throw new Error(
|
|
12553
13654
|
`Invalid workingDirectory "${testCase.workingDirectory}": escapes repo boundary`
|
|
12554
13655
|
);
|
|
@@ -12620,7 +13721,7 @@ async function runEval(options) {
|
|
|
12620
13721
|
};
|
|
12621
13722
|
let viewerPath;
|
|
12622
13723
|
if (outputPath) {
|
|
12623
|
-
await fs9.mkdir(
|
|
13724
|
+
await fs9.mkdir(path15.dirname(outputPath), { recursive: true });
|
|
12624
13725
|
await safeWriteFile(outputPath, JSON.stringify(output, null, 2), true);
|
|
12625
13726
|
viewerPath = buildViewerPath(outputPath);
|
|
12626
13727
|
await safeWriteFile(viewerPath, buildTrajectoryViewerHtml(output), true);
|
|
@@ -12681,10 +13782,11 @@ async function judge(client, options) {
|
|
|
12681
13782
|
if (delta) content += delta;
|
|
12682
13783
|
}
|
|
12683
13784
|
});
|
|
13785
|
+
const expectationText = Array.isArray(options.expectation) ? options.expectation.join("\n") : options.expectation;
|
|
12684
13786
|
const prompt = [
|
|
12685
13787
|
"Evaluate which response best matches the expectation.",
|
|
12686
13788
|
"",
|
|
12687
|
-
`Expectation: ${
|
|
13789
|
+
`Expectation: ${expectationText}`,
|
|
12688
13790
|
"",
|
|
12689
13791
|
"Response A (without custom instructions):",
|
|
12690
13792
|
options.withoutInstructions,
|
|
@@ -12728,7 +13830,7 @@ function parseJudge(content) {
|
|
|
12728
13830
|
}
|
|
12729
13831
|
async function loadConfig(configPath) {
|
|
12730
13832
|
const raw = await fs9.readFile(configPath, "utf8");
|
|
12731
|
-
const parsed = JSON.parse(raw);
|
|
13833
|
+
const parsed = JSON.parse(stripJsonComments(raw));
|
|
12732
13834
|
if (!parsed || !Array.isArray(parsed.cases)) {
|
|
12733
13835
|
throw new Error("Eval config must have a 'cases' array.");
|
|
12734
13836
|
}
|
|
@@ -12934,7 +14036,7 @@ function formatTokenUsage(usage) {
|
|
|
12934
14036
|
function resolveOutputPath(repoPath, override, configValue) {
|
|
12935
14037
|
const chosen = override ?? configValue;
|
|
12936
14038
|
if (!chosen) return void 0;
|
|
12937
|
-
return
|
|
14039
|
+
return path15.isAbsolute(chosen) ? chosen : path15.resolve(repoPath, chosen);
|
|
12938
14040
|
}
|
|
12939
14041
|
function buildViewerPath(outputPath) {
|
|
12940
14042
|
if (outputPath.endsWith(".json")) {
|
|
@@ -13289,7 +14391,7 @@ function sanitizeValue(value, depth) {
|
|
|
13289
14391
|
|
|
13290
14392
|
// src/commands/eval.ts
|
|
13291
14393
|
async function evalCommand(configPathArg, options) {
|
|
13292
|
-
const repoPath =
|
|
14394
|
+
const repoPath = path16.resolve(options.repo ?? process.cwd());
|
|
13293
14395
|
if (options.listModels) {
|
|
13294
14396
|
try {
|
|
13295
14397
|
const models = await listCopilotModels();
|
|
@@ -13325,7 +14427,7 @@ async function evalCommand(configPathArg, options) {
|
|
|
13325
14427
|
return;
|
|
13326
14428
|
}
|
|
13327
14429
|
if (options.init) {
|
|
13328
|
-
const outputPath =
|
|
14430
|
+
const outputPath = path16.join(repoPath, "agentrc.eval.json");
|
|
13329
14431
|
const desiredCount = Math.max(1, Number.parseInt(options.count ?? "5", 10) || 5);
|
|
13330
14432
|
try {
|
|
13331
14433
|
const progress = createProgressReporter(!shouldLog(options));
|
|
@@ -13367,7 +14469,7 @@ async function evalCommand(configPathArg, options) {
|
|
|
13367
14469
|
}
|
|
13368
14470
|
return;
|
|
13369
14471
|
}
|
|
13370
|
-
const configPath =
|
|
14472
|
+
const configPath = path16.resolve(configPathArg ?? path16.join(repoPath, "agentrc.eval.json"));
|
|
13371
14473
|
try {
|
|
13372
14474
|
const progress = createProgressReporter(!shouldLog(options));
|
|
13373
14475
|
const { summary, results, viewerPath } = await runEval({
|
|
@@ -13414,32 +14516,43 @@ async function evalCommand(configPathArg, options) {
|
|
|
13414
14516
|
}
|
|
13415
14517
|
|
|
13416
14518
|
// src/commands/generate.ts
|
|
13417
|
-
import
|
|
14519
|
+
import path19 from "path";
|
|
13418
14520
|
|
|
13419
14521
|
// packages/core/src/services/generator.ts
|
|
13420
|
-
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
|
+
}
|
|
13421
14537
|
async function generateConfigs(options) {
|
|
13422
|
-
const { repoPath, analysis, selections, force } = options;
|
|
14538
|
+
const { repoPath, analysis, selections, force, dryRun } = options;
|
|
13423
14539
|
const files = [];
|
|
13424
14540
|
if (selections.includes("mcp")) {
|
|
13425
|
-
|
|
13426
|
-
|
|
13427
|
-
|
|
13428
|
-
|
|
13429
|
-
|
|
13430
|
-
|
|
13431
|
-
action: wrote ? "wrote" : "skipped"
|
|
13432
|
-
});
|
|
14541
|
+
files.push(
|
|
14542
|
+
await writeOrPreview(path17.join(repoPath, ".vscode", "mcp.json"), renderMcp(), {
|
|
14543
|
+
dryRun,
|
|
14544
|
+
force
|
|
14545
|
+
})
|
|
14546
|
+
);
|
|
13433
14547
|
}
|
|
13434
14548
|
if (selections.includes("vscode")) {
|
|
13435
|
-
|
|
13436
|
-
|
|
13437
|
-
|
|
13438
|
-
|
|
13439
|
-
|
|
13440
|
-
|
|
13441
|
-
|
|
13442
|
-
});
|
|
14549
|
+
files.push(
|
|
14550
|
+
await writeOrPreview(
|
|
14551
|
+
path17.join(repoPath, ".vscode", "settings.json"),
|
|
14552
|
+
renderVscodeSettings(analysis),
|
|
14553
|
+
{ dryRun, force }
|
|
14554
|
+
)
|
|
14555
|
+
);
|
|
13443
14556
|
}
|
|
13444
14557
|
return { files };
|
|
13445
14558
|
}
|
|
@@ -13488,16 +14601,16 @@ function renderVscodeSettings(analysis) {
|
|
|
13488
14601
|
}
|
|
13489
14602
|
|
|
13490
14603
|
// src/commands/instructions.ts
|
|
13491
|
-
import
|
|
14604
|
+
import path18 from "path";
|
|
13492
14605
|
function skipReason(action) {
|
|
13493
14606
|
if (action === "symlink") return "symlink";
|
|
13494
14607
|
if (action === "empty") return "empty content";
|
|
13495
14608
|
return "exists, use --force";
|
|
13496
14609
|
}
|
|
13497
14610
|
async function instructionsCommand(options) {
|
|
13498
|
-
const repoPath =
|
|
13499
|
-
const outputPath =
|
|
13500
|
-
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")
|
|
13501
14614
|
);
|
|
13502
14615
|
const progress = createProgressReporter(!shouldLog(options));
|
|
13503
14616
|
const wantAreas = options.areas || options.areasOnly || options.area;
|
|
@@ -13544,7 +14657,7 @@ async function instructionsCommand(options) {
|
|
|
13544
14657
|
] : []
|
|
13545
14658
|
];
|
|
13546
14659
|
for (const file of dryFiles) {
|
|
13547
|
-
const relPath =
|
|
14660
|
+
const relPath = path18.relative(process.cwd(), path18.join(repoPath, file.path));
|
|
13548
14661
|
if (shouldLog(options)) {
|
|
13549
14662
|
progress.update(
|
|
13550
14663
|
`[dry-run] Would write ${relPath} (${Buffer.byteLength(file.content, "utf8")} bytes)`
|
|
@@ -13565,7 +14678,7 @@ async function instructionsCommand(options) {
|
|
|
13565
14678
|
} else {
|
|
13566
14679
|
const actions = await writeNestedInstructions(repoPath, nestedResult, options.force);
|
|
13567
14680
|
for (const action of actions) {
|
|
13568
|
-
const relPath =
|
|
14681
|
+
const relPath = path18.relative(process.cwd(), action.path);
|
|
13569
14682
|
if (action.action === "wrote") {
|
|
13570
14683
|
if (shouldLog(options)) progress.succeed(`Wrote ${relPath}`);
|
|
13571
14684
|
} else if (shouldLog(options)) {
|
|
@@ -13608,8 +14721,8 @@ async function instructionsCommand(options) {
|
|
|
13608
14721
|
}
|
|
13609
14722
|
if (content) {
|
|
13610
14723
|
if (options.dryRun) {
|
|
13611
|
-
const relPath =
|
|
13612
|
-
const displayPath =
|
|
14724
|
+
const relPath = path18.relative(repoPath, outputPath);
|
|
14725
|
+
const displayPath = path18.relative(process.cwd(), outputPath);
|
|
13613
14726
|
const byteCount = Buffer.byteLength(content, "utf8");
|
|
13614
14727
|
if (shouldLog(options)) {
|
|
13615
14728
|
progress.update(`[dry-run] Would write ${displayPath} (${byteCount} bytes)`);
|
|
@@ -13618,14 +14731,14 @@ async function instructionsCommand(options) {
|
|
|
13618
14731
|
dryRunFiles.push({ path: relPath, bytes: byteCount });
|
|
13619
14732
|
}
|
|
13620
14733
|
} else {
|
|
13621
|
-
await ensureDir(
|
|
14734
|
+
await ensureDir(path18.dirname(outputPath));
|
|
13622
14735
|
const { wrote, reason } = await safeWriteFile(
|
|
13623
14736
|
outputPath,
|
|
13624
14737
|
content,
|
|
13625
14738
|
Boolean(options.force)
|
|
13626
14739
|
);
|
|
13627
14740
|
if (!wrote) {
|
|
13628
|
-
const relPath =
|
|
14741
|
+
const relPath = path18.relative(process.cwd(), outputPath);
|
|
13629
14742
|
const why = reason === "symlink" ? "path is a symlink" : "file exists (use --force)";
|
|
13630
14743
|
if (options.json) {
|
|
13631
14744
|
const result = {
|
|
@@ -13647,7 +14760,7 @@ async function instructionsCommand(options) {
|
|
|
13647
14760
|
};
|
|
13648
14761
|
outputResult(result, true);
|
|
13649
14762
|
} else if (shouldLog(options)) {
|
|
13650
|
-
progress.succeed(`Updated ${
|
|
14763
|
+
progress.succeed(`Updated ${path18.relative(process.cwd(), outputPath)}`);
|
|
13651
14764
|
}
|
|
13652
14765
|
}
|
|
13653
14766
|
}
|
|
@@ -13714,7 +14827,7 @@ async function instructionsCommand(options) {
|
|
|
13714
14827
|
] : []
|
|
13715
14828
|
];
|
|
13716
14829
|
for (const file of dryFiles) {
|
|
13717
|
-
const relPath =
|
|
14830
|
+
const relPath = path18.relative(process.cwd(), path18.join(repoPath, file.path));
|
|
13718
14831
|
if (shouldLog(options)) {
|
|
13719
14832
|
progress.update(
|
|
13720
14833
|
`[dry-run] Would write ${relPath} (${Buffer.byteLength(file.content, "utf8")} bytes)`
|
|
@@ -13732,7 +14845,7 @@ async function instructionsCommand(options) {
|
|
|
13732
14845
|
} else {
|
|
13733
14846
|
const actions = await writeNestedInstructions(repoPath, nestedResult, options.force);
|
|
13734
14847
|
for (const action of actions) {
|
|
13735
|
-
const relPath =
|
|
14848
|
+
const relPath = path18.relative(process.cwd(), action.path);
|
|
13736
14849
|
if (action.action === "wrote") {
|
|
13737
14850
|
if (shouldLog(options)) progress.succeed(`Wrote ${relPath}`);
|
|
13738
14851
|
} else if (shouldLog(options)) {
|
|
@@ -13764,7 +14877,7 @@ async function instructionsCommand(options) {
|
|
|
13764
14877
|
}
|
|
13765
14878
|
if (options.json) {
|
|
13766
14879
|
dryRunFiles.push({
|
|
13767
|
-
path:
|
|
14880
|
+
path: path18.relative(repoPath, areaInstructionPath(repoPath, area)),
|
|
13768
14881
|
bytes: Buffer.byteLength(body, "utf8")
|
|
13769
14882
|
});
|
|
13770
14883
|
}
|
|
@@ -13785,7 +14898,7 @@ async function instructionsCommand(options) {
|
|
|
13785
14898
|
continue;
|
|
13786
14899
|
}
|
|
13787
14900
|
if (shouldLog(options)) {
|
|
13788
|
-
progress.succeed(`Wrote ${
|
|
14901
|
+
progress.succeed(`Wrote ${path18.relative(process.cwd(), result.filePath)}`);
|
|
13789
14902
|
}
|
|
13790
14903
|
}
|
|
13791
14904
|
}
|
|
@@ -13820,7 +14933,7 @@ async function instructionsCommand(options) {
|
|
|
13820
14933
|
|
|
13821
14934
|
// src/commands/generate.ts
|
|
13822
14935
|
async function generateCommand(type, repoPathArg, options) {
|
|
13823
|
-
const repoPath =
|
|
14936
|
+
const repoPath = path19.resolve(repoPathArg ?? process.cwd());
|
|
13824
14937
|
if (type === "instructions" || type === "agents") {
|
|
13825
14938
|
if (!options.quiet) {
|
|
13826
14939
|
process.stderr.write(
|
|
@@ -13834,7 +14947,7 @@ async function generateCommand(type, repoPathArg, options) {
|
|
|
13834
14947
|
`
|
|
13835
14948
|
);
|
|
13836
14949
|
}
|
|
13837
|
-
const output = type === "agents" ?
|
|
14950
|
+
const output = type === "agents" ? path19.join(repoPath, "AGENTS.md") : void 0;
|
|
13838
14951
|
await instructionsCommand({
|
|
13839
14952
|
repo: repoPath,
|
|
13840
14953
|
output,
|
|
@@ -13843,7 +14956,8 @@ async function generateCommand(type, repoPathArg, options) {
|
|
|
13843
14956
|
json: options.json,
|
|
13844
14957
|
quiet: options.quiet,
|
|
13845
14958
|
areas: options.perApp,
|
|
13846
|
-
strategy: options.strategy
|
|
14959
|
+
strategy: options.strategy,
|
|
14960
|
+
dryRun: options.dryRun
|
|
13847
14961
|
});
|
|
13848
14962
|
return;
|
|
13849
14963
|
}
|
|
@@ -13864,7 +14978,8 @@ async function generateCommand(type, repoPathArg, options) {
|
|
|
13864
14978
|
repoPath,
|
|
13865
14979
|
analysis,
|
|
13866
14980
|
selections,
|
|
13867
|
-
force: Boolean(options.force)
|
|
14981
|
+
force: Boolean(options.force),
|
|
14982
|
+
dryRun: Boolean(options.dryRun)
|
|
13868
14983
|
});
|
|
13869
14984
|
} catch (error) {
|
|
13870
14985
|
outputError(
|
|
@@ -13878,14 +14993,16 @@ async function generateCommand(type, repoPathArg, options) {
|
|
|
13878
14993
|
const result = {
|
|
13879
14994
|
ok,
|
|
13880
14995
|
status,
|
|
13881
|
-
data: { type, files: genResult.files }
|
|
14996
|
+
data: { type, files: genResult.files, dryRun: options.dryRun }
|
|
13882
14997
|
};
|
|
13883
14998
|
outputResult(result, true);
|
|
13884
14999
|
if (!ok) process.exitCode = 1;
|
|
13885
15000
|
} else {
|
|
13886
15001
|
for (const file of genResult.files) {
|
|
13887
15002
|
if (shouldLog(options)) {
|
|
13888
|
-
|
|
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}
|
|
13889
15006
|
`);
|
|
13890
15007
|
}
|
|
13891
15008
|
}
|
|
@@ -13896,10 +15013,37 @@ async function generateCommand(type, repoPathArg, options) {
|
|
|
13896
15013
|
}
|
|
13897
15014
|
|
|
13898
15015
|
// src/commands/init.ts
|
|
13899
|
-
import
|
|
13900
|
-
import
|
|
15016
|
+
import { execFile as execFile3 } from "child_process";
|
|
15017
|
+
import path21 from "path";
|
|
15018
|
+
import { promisify as promisify3 } from "util";
|
|
15019
|
+
|
|
15020
|
+
// packages/core/src/services/configScaffold.ts
|
|
15021
|
+
import path20 from "path";
|
|
15022
|
+
async function scaffoldAgentrcConfig(repoPath, areas, force = false) {
|
|
15023
|
+
const configPath = path20.join(repoPath, "agentrc.config.json");
|
|
15024
|
+
const workspaces = areas.length > 0 ? await detectWorkspaces(repoPath, areas) : [];
|
|
15025
|
+
const workspacePaths = workspaces.map((ws) => ws.path + "/");
|
|
15026
|
+
const standaloneAreas = areas.filter((a) => {
|
|
15027
|
+
if (!a.path) return true;
|
|
15028
|
+
const rel = path20.relative(repoPath, a.path).replace(/\\/gu, "/");
|
|
15029
|
+
return !workspacePaths.some((prefix) => rel.startsWith(prefix));
|
|
15030
|
+
}).map((a) => ({
|
|
15031
|
+
name: a.name,
|
|
15032
|
+
applyTo: a.applyTo,
|
|
15033
|
+
...a.description ? { description: a.description } : {}
|
|
15034
|
+
}));
|
|
15035
|
+
const agentrcConfig = {};
|
|
15036
|
+
if (workspaces.length > 0) agentrcConfig.workspaces = workspaces;
|
|
15037
|
+
if (standaloneAreas.length > 0) agentrcConfig.areas = standaloneAreas;
|
|
15038
|
+
const configContent = JSON.stringify(agentrcConfig, null, 2) + "\n";
|
|
15039
|
+
const { wrote } = await safeWriteFile(configPath, configContent, force);
|
|
15040
|
+
return { wrote, configPath };
|
|
15041
|
+
}
|
|
15042
|
+
|
|
15043
|
+
// src/commands/init.ts
|
|
15044
|
+
import { checkbox, confirm, select } from "@inquirer/prompts";
|
|
13901
15045
|
async function initCommand(repoPathArg, options) {
|
|
13902
|
-
let repoPath =
|
|
15046
|
+
let repoPath = path21.resolve(repoPathArg ?? process.cwd());
|
|
13903
15047
|
const provider = options.provider ?? (options.github ? "github" : void 0);
|
|
13904
15048
|
if (provider && provider !== "github" && provider !== "azure") {
|
|
13905
15049
|
outputError("Invalid provider. Use github or azure.", Boolean(options.json));
|
|
@@ -13937,7 +15081,7 @@ async function initCommand(repoPathArg, options) {
|
|
|
13937
15081
|
value: repo
|
|
13938
15082
|
}))
|
|
13939
15083
|
});
|
|
13940
|
-
const cacheRoot =
|
|
15084
|
+
const cacheRoot = path21.join(process.cwd(), ".agentrc-cache");
|
|
13941
15085
|
repoPath = validateCachePath(cacheRoot, selection.owner, selection.name);
|
|
13942
15086
|
await ensureDir(repoPath);
|
|
13943
15087
|
const hasGit = await isGitRepo(repoPath);
|
|
@@ -13990,7 +15134,7 @@ async function initCommand(repoPathArg, options) {
|
|
|
13990
15134
|
value: repo
|
|
13991
15135
|
}))
|
|
13992
15136
|
});
|
|
13993
|
-
const cacheRoot =
|
|
15137
|
+
const cacheRoot = path21.join(process.cwd(), ".agentrc-cache");
|
|
13994
15138
|
repoPath = validateCachePath(
|
|
13995
15139
|
cacheRoot,
|
|
13996
15140
|
orgSelection.name,
|
|
@@ -14029,17 +15173,17 @@ async function initCommand(repoPathArg, options) {
|
|
|
14029
15173
|
});
|
|
14030
15174
|
const allFiles = [];
|
|
14031
15175
|
if (selections.includes("instructions")) {
|
|
14032
|
-
const outputPath =
|
|
14033
|
-
await ensureDir(
|
|
15176
|
+
const outputPath = path21.join(repoPath, ".github", "copilot-instructions.md");
|
|
15177
|
+
await ensureDir(path21.dirname(outputPath));
|
|
14034
15178
|
try {
|
|
14035
15179
|
const content = await generateCopilotInstructions({ repoPath, model: options.model });
|
|
14036
15180
|
const { wrote } = await safeWriteFile(outputPath, content, Boolean(options.force));
|
|
14037
15181
|
allFiles.push({
|
|
14038
|
-
path:
|
|
15182
|
+
path: path21.relative(process.cwd(), outputPath),
|
|
14039
15183
|
action: wrote ? "wrote" : "skipped"
|
|
14040
15184
|
});
|
|
14041
15185
|
if (shouldLog(options)) {
|
|
14042
|
-
const rel =
|
|
15186
|
+
const rel = path21.relative(process.cwd(), outputPath);
|
|
14043
15187
|
process.stderr.write((wrote ? `Wrote ${rel}` : `Skipped ${rel} (exists)`) + "\n");
|
|
14044
15188
|
}
|
|
14045
15189
|
} catch (error) {
|
|
@@ -14066,32 +15210,19 @@ async function initCommand(repoPathArg, options) {
|
|
|
14066
15210
|
return;
|
|
14067
15211
|
}
|
|
14068
15212
|
allFiles.push(...genResult.files);
|
|
14069
|
-
|
|
14070
|
-
const
|
|
14071
|
-
|
|
14072
|
-
|
|
14073
|
-
|
|
14074
|
-
|
|
14075
|
-
|
|
14076
|
-
|
|
14077
|
-
|
|
14078
|
-
|
|
14079
|
-
applyTo: a.applyTo,
|
|
14080
|
-
...a.description ? { description: a.description } : {}
|
|
14081
|
-
}));
|
|
14082
|
-
const agentrcConfig = {};
|
|
14083
|
-
if (workspaces.length > 0) agentrcConfig.workspaces = workspaces;
|
|
14084
|
-
if (standaloneAreas.length > 0) agentrcConfig.areas = standaloneAreas;
|
|
14085
|
-
if (agentrcConfig.workspaces || agentrcConfig.areas) {
|
|
14086
|
-
const configContent = JSON.stringify(agentrcConfig, null, 2) + "\n";
|
|
14087
|
-
const { wrote } = await safeWriteFile(configPath, configContent, Boolean(options.force));
|
|
14088
|
-
const rel = path16.relative(process.cwd(), configPath);
|
|
14089
|
-
allFiles.push({ path: rel, action: wrote ? "wrote" : "skipped" });
|
|
14090
|
-
if (shouldLog(options)) {
|
|
14091
|
-
process.stderr.write((wrote ? `Wrote ${rel}` : `Skipped ${rel} (exists)`) + "\n");
|
|
14092
|
-
}
|
|
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");
|
|
14093
15223
|
}
|
|
14094
15224
|
}
|
|
15225
|
+
await offerApmInit(repoPath, options);
|
|
14095
15226
|
if (options.json) {
|
|
14096
15227
|
const { ok, status } = deriveFileStatus(allFiles);
|
|
14097
15228
|
const result = {
|
|
@@ -14113,9 +15244,52 @@ async function initCommand(repoPathArg, options) {
|
|
|
14113
15244
|
process.stderr.write(" agentrc eval --init Scaffold evaluation test cases\n");
|
|
14114
15245
|
}
|
|
14115
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
|
+
}
|
|
14116
15290
|
|
|
14117
15291
|
// src/commands/pr.ts
|
|
14118
|
-
import
|
|
15292
|
+
import path22 from "path";
|
|
14119
15293
|
var DEFAULT_PR_BRANCH = "agentrc/add-ai-config";
|
|
14120
15294
|
async function prCommand(repo, options) {
|
|
14121
15295
|
const provider = options.provider ?? "github";
|
|
@@ -14149,7 +15323,7 @@ async function prCommand(repo, options) {
|
|
|
14149
15323
|
try {
|
|
14150
15324
|
progress.update("Fetching repo info...");
|
|
14151
15325
|
const repoInfo = await getRepo(token2, organization, project, name2);
|
|
14152
|
-
const cacheRoot =
|
|
15326
|
+
const cacheRoot = path22.join(process.cwd(), ".agentrc-cache");
|
|
14153
15327
|
const repoPath = validateCachePath(cacheRoot, organization, project, name2);
|
|
14154
15328
|
await ensureDir(repoPath);
|
|
14155
15329
|
if (!await isGitRepo(repoPath)) {
|
|
@@ -14163,8 +15337,8 @@ async function prCommand(repo, options) {
|
|
|
14163
15337
|
await checkoutBranch(repoPath, branch);
|
|
14164
15338
|
progress.update("Generating instructions...");
|
|
14165
15339
|
const instructions = await generateCopilotInstructions({ repoPath, model: options.model });
|
|
14166
|
-
const instructionsPath =
|
|
14167
|
-
await ensureDir(
|
|
15340
|
+
const instructionsPath = path22.join(repoPath, ".github", "copilot-instructions.md");
|
|
15341
|
+
await ensureDir(path22.dirname(instructionsPath));
|
|
14168
15342
|
const { wrote, reason } = await safeWriteFile(instructionsPath, instructions, true);
|
|
14169
15343
|
if (!wrote) {
|
|
14170
15344
|
throw new Error(
|
|
@@ -14231,7 +15405,7 @@ async function prCommand(repo, options) {
|
|
|
14231
15405
|
try {
|
|
14232
15406
|
progress.update("Fetching repo info...");
|
|
14233
15407
|
const repoInfo = await getRepo2(token, owner, name);
|
|
14234
|
-
const cacheRoot =
|
|
15408
|
+
const cacheRoot = path22.join(process.cwd(), ".agentrc-cache");
|
|
14235
15409
|
const repoPath = validateCachePath(cacheRoot, owner, name);
|
|
14236
15410
|
await ensureDir(repoPath);
|
|
14237
15411
|
if (!await isGitRepo(repoPath)) {
|
|
@@ -14243,8 +15417,8 @@ async function prCommand(repo, options) {
|
|
|
14243
15417
|
await checkoutBranch(repoPath, branch);
|
|
14244
15418
|
progress.update("Generating instructions...");
|
|
14245
15419
|
const instructions = await generateCopilotInstructions({ repoPath, model: options.model });
|
|
14246
|
-
const instructionsPath =
|
|
14247
|
-
await ensureDir(
|
|
15420
|
+
const instructionsPath = path22.join(repoPath, ".github", "copilot-instructions.md");
|
|
15421
|
+
await ensureDir(path22.dirname(instructionsPath));
|
|
14248
15422
|
const { wrote, reason } = await safeWriteFile(instructionsPath, instructions, true);
|
|
14249
15423
|
if (!wrote) {
|
|
14250
15424
|
throw new Error(
|
|
@@ -14293,13 +15467,13 @@ async function prCommand(repo, options) {
|
|
|
14293
15467
|
}
|
|
14294
15468
|
|
|
14295
15469
|
// src/commands/readiness.ts
|
|
14296
|
-
import
|
|
15470
|
+
import path23 from "path";
|
|
14297
15471
|
import chalk3 from "chalk";
|
|
14298
15472
|
async function readinessCommand(repoPathArg, options) {
|
|
14299
|
-
const repoPath =
|
|
14300
|
-
const repoName =
|
|
14301
|
-
const resolvedOutputPath = options.output ?
|
|
14302
|
-
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() : "";
|
|
14303
15477
|
let failLevelError;
|
|
14304
15478
|
let report;
|
|
14305
15479
|
try {
|
|
@@ -14361,7 +15535,7 @@ async function readinessCommand(repoPathArg, options) {
|
|
|
14361
15535
|
title: `Readiness Report: ${repoName}`,
|
|
14362
15536
|
generatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
14363
15537
|
});
|
|
14364
|
-
const outputPath = options.output ? resolvedOutputPath :
|
|
15538
|
+
const outputPath = options.output ? resolvedOutputPath : path23.join(repoPath, "readiness-report.html");
|
|
14365
15539
|
const { wrote, reason } = await safeWriteFile(outputPath, html, Boolean(options.force));
|
|
14366
15540
|
if (!wrote) {
|
|
14367
15541
|
const why = reason === "symlink" ? "path is a symlink" : "file exists (use --force)";
|
|
@@ -14596,26 +15770,32 @@ function formatReadinessMarkdown(report, repoName) {
|
|
|
14596
15770
|
}
|
|
14597
15771
|
|
|
14598
15772
|
// src/commands/tui.tsx
|
|
14599
|
-
import
|
|
15773
|
+
import path25 from "path";
|
|
14600
15774
|
import { render as render3 } from "ink";
|
|
14601
15775
|
|
|
14602
15776
|
// src/ui/tui.tsx
|
|
14603
15777
|
import fs10 from "fs/promises";
|
|
14604
|
-
import
|
|
15778
|
+
import path24 from "path";
|
|
14605
15779
|
import { Box as Box5, Text as Text5, useApp as useApp4, useInput as useInput4, useStdout, useIsScreenReaderEnabled as useIsScreenReaderEnabled5 } from "ink";
|
|
14606
15780
|
import { useEffect as useEffect5, useMemo, useState as useState5 } from "react";
|
|
14607
15781
|
import { Fragment, jsx as jsx7, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
14608
15782
|
var SPINNER_FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
14609
15783
|
function useTerminalColumns() {
|
|
14610
15784
|
const { stdout } = useStdout();
|
|
15785
|
+
const accessible = useIsScreenReaderEnabled5();
|
|
14611
15786
|
const [columns, setColumns] = useState5(stdout.columns ?? 80);
|
|
14612
15787
|
useEffect5(() => {
|
|
14613
|
-
const onResize = () =>
|
|
14614
|
-
|
|
15788
|
+
const onResize = () => {
|
|
15789
|
+
if (!accessible) {
|
|
15790
|
+
stdout.write("\x1B[2J\x1B[H");
|
|
15791
|
+
}
|
|
15792
|
+
setColumns(stdout.columns ?? 80);
|
|
15793
|
+
};
|
|
15794
|
+
stdout.prependListener("resize", onResize);
|
|
14615
15795
|
return () => {
|
|
14616
15796
|
stdout.off("resize", onResize);
|
|
14617
15797
|
};
|
|
14618
|
-
}, [stdout]);
|
|
15798
|
+
}, [stdout, accessible]);
|
|
14619
15799
|
return columns;
|
|
14620
15800
|
}
|
|
14621
15801
|
function useSpinner(active) {
|
|
@@ -14700,6 +15880,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14700
15880
|
const [modelPickTarget, setModelPickTarget] = useState5("eval");
|
|
14701
15881
|
const [modelCursor, setModelCursor] = useState5(0);
|
|
14702
15882
|
const [hasEvalConfig, setHasEvalConfig] = useState5(null);
|
|
15883
|
+
const [hasAgentrcConfig, setHasAgentrcConfig] = useState5(null);
|
|
14703
15884
|
const [activityLog, setActivityLog] = useState5([]);
|
|
14704
15885
|
const [generateTarget, setGenerateTarget] = useState5(
|
|
14705
15886
|
"copilot-instructions"
|
|
@@ -14709,7 +15890,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14709
15890
|
const [isMonorepo, setIsMonorepo] = useState5(false);
|
|
14710
15891
|
const [repoAreas, setRepoAreas] = useState5([]);
|
|
14711
15892
|
const [areaCursor, setAreaCursor] = useState5(0);
|
|
14712
|
-
const repoLabel = useMemo(() =>
|
|
15893
|
+
const repoLabel = useMemo(() => path24.basename(repoPath), [repoPath]);
|
|
14713
15894
|
const repoFull = useMemo(() => repoPath, [repoPath]);
|
|
14714
15895
|
const isLoading = status === "generating" || status === "bootstrapping" || status === "evaluating" || status === "generating-areas" || status === "readiness-running";
|
|
14715
15896
|
const isMenu = status === "model-pick" || status === "eval-pick" || status === "batch-pick" || status === "generate-pick" || status === "generate-app-pick" || status === "generate-area-pick";
|
|
@@ -14721,14 +15902,24 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14721
15902
|
setStatus("idle");
|
|
14722
15903
|
};
|
|
14723
15904
|
useEffect5(() => {
|
|
14724
|
-
const configPath =
|
|
15905
|
+
const configPath = path24.join(repoPath, "agentrc.eval.json");
|
|
14725
15906
|
fs10.access(configPath).then(() => setHasEvalConfig(true)).catch(() => setHasEvalConfig(false));
|
|
15907
|
+
const agentrcConfigCandidates = [
|
|
15908
|
+
path24.join(repoPath, "agentrc.config.json"),
|
|
15909
|
+
path24.join(repoPath, ".github", "agentrc.config.json")
|
|
15910
|
+
];
|
|
15911
|
+
Promise.all(
|
|
15912
|
+
agentrcConfigCandidates.map(
|
|
15913
|
+
(p) => fs10.access(p).then(() => true).catch(() => false)
|
|
15914
|
+
)
|
|
15915
|
+
).then((results) => setHasAgentrcConfig(results.some(Boolean))).catch(() => setHasAgentrcConfig(false));
|
|
14726
15916
|
analyzeRepo(repoPath).then((analysis) => {
|
|
14727
15917
|
const apps = analysis.apps ?? [];
|
|
14728
15918
|
setRepoApps(apps);
|
|
14729
15919
|
setIsMonorepo(analysis.isMonorepo ?? false);
|
|
14730
15920
|
setRepoAreas(analysis.areas ?? []);
|
|
14731
15921
|
}).catch((err) => {
|
|
15922
|
+
setRepoAreas([]);
|
|
14732
15923
|
addLog(`Repo analysis failed: ${err instanceof Error ? err.message : "unknown"}`, "error");
|
|
14733
15924
|
});
|
|
14734
15925
|
}, [repoPath]);
|
|
@@ -14736,17 +15927,17 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14736
15927
|
let active = true;
|
|
14737
15928
|
listCopilotModels().then((models) => {
|
|
14738
15929
|
if (!active) return;
|
|
14739
|
-
|
|
14740
|
-
|
|
15930
|
+
const list = models.length > 0 ? models : PREFERRED_MODELS;
|
|
15931
|
+
setAvailableModels(list);
|
|
14741
15932
|
setEvalModel(
|
|
14742
|
-
(current) =>
|
|
15933
|
+
(current) => list.includes(current) ? current : pickBestModel(list, current)
|
|
14743
15934
|
);
|
|
14744
15935
|
setJudgeModel(
|
|
14745
|
-
(current) =>
|
|
15936
|
+
(current) => list.includes(current) ? current : pickBestModel(list, current)
|
|
14746
15937
|
);
|
|
14747
15938
|
}).catch(() => {
|
|
14748
15939
|
if (!active) return;
|
|
14749
|
-
setAvailableModels(
|
|
15940
|
+
setAvailableModels(PREFERRED_MODELS);
|
|
14750
15941
|
});
|
|
14751
15942
|
return () => {
|
|
14752
15943
|
active = false;
|
|
@@ -14782,7 +15973,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14782
15973
|
};
|
|
14783
15974
|
useEffect5(() => {
|
|
14784
15975
|
let active = true;
|
|
14785
|
-
const configPath =
|
|
15976
|
+
const configPath = path24.join(repoPath, "agentrc.eval.json");
|
|
14786
15977
|
fs10.readFile(configPath, "utf8").then((raw) => {
|
|
14787
15978
|
if (!active) return;
|
|
14788
15979
|
const parsed = JSON.parse(raw);
|
|
@@ -14797,7 +15988,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14797
15988
|
};
|
|
14798
15989
|
}, [repoPath]);
|
|
14799
15990
|
const bootstrapEvalConfig = async (count, force) => {
|
|
14800
|
-
const configPath =
|
|
15991
|
+
const configPath = path24.join(repoPath, "agentrc.eval.json");
|
|
14801
15992
|
try {
|
|
14802
15993
|
setStatus("bootstrapping");
|
|
14803
15994
|
setMessage("Generating eval cases with Copilot SDK...");
|
|
@@ -14836,13 +16027,13 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14836
16027
|
if (status === "preview") {
|
|
14837
16028
|
if (input.toLowerCase() === "s") {
|
|
14838
16029
|
try {
|
|
14839
|
-
const outputPath = generateSavePath ||
|
|
14840
|
-
await fs10.mkdir(
|
|
16030
|
+
const outputPath = generateSavePath || path24.join(repoPath, ".github", "copilot-instructions.md");
|
|
16031
|
+
await fs10.mkdir(path24.dirname(outputPath), { recursive: true });
|
|
14841
16032
|
const { wrote, reason } = await safeWriteFile(outputPath, generatedContent, true);
|
|
14842
16033
|
if (!wrote)
|
|
14843
16034
|
throw new Error(reason === "symlink" ? "Path is a symlink" : "Write failed");
|
|
14844
16035
|
setStatus("done");
|
|
14845
|
-
const relPath =
|
|
16036
|
+
const relPath = path24.relative(repoPath, outputPath);
|
|
14846
16037
|
const msg = `Saved to ${relPath}`;
|
|
14847
16038
|
setMessage(msg);
|
|
14848
16039
|
addLog(msg, "success");
|
|
@@ -14876,7 +16067,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14876
16067
|
setMessage("Enter a positive number of eval cases, then press Enter.");
|
|
14877
16068
|
return;
|
|
14878
16069
|
}
|
|
14879
|
-
const configPath =
|
|
16070
|
+
const configPath = path24.join(repoPath, "agentrc.eval.json");
|
|
14880
16071
|
setEvalBootstrapCount(count);
|
|
14881
16072
|
try {
|
|
14882
16073
|
await fs10.access(configPath);
|
|
@@ -14935,7 +16126,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14935
16126
|
setStatus("generate-app-pick");
|
|
14936
16127
|
setMessage("Generate for root or per-app?");
|
|
14937
16128
|
} else {
|
|
14938
|
-
const savePath =
|
|
16129
|
+
const savePath = path24.join(repoPath, ".github", "copilot-instructions.md");
|
|
14939
16130
|
setGenerateSavePath(savePath);
|
|
14940
16131
|
await doGenerate(repoPath, savePath, "copilot-instructions");
|
|
14941
16132
|
}
|
|
@@ -14947,7 +16138,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14947
16138
|
setStatus("generate-app-pick");
|
|
14948
16139
|
setMessage("Generate for root or per-app?");
|
|
14949
16140
|
} else {
|
|
14950
|
-
const savePath =
|
|
16141
|
+
const savePath = path24.join(repoPath, "AGENTS.md");
|
|
14951
16142
|
setGenerateSavePath(savePath);
|
|
14952
16143
|
await doGenerate(repoPath, savePath, "agents-md");
|
|
14953
16144
|
}
|
|
@@ -14972,7 +16163,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14972
16163
|
}
|
|
14973
16164
|
if (status === "generate-app-pick") {
|
|
14974
16165
|
if (input.toLowerCase() === "r") {
|
|
14975
|
-
const savePath = generateTarget === "copilot-instructions" ?
|
|
16166
|
+
const savePath = generateTarget === "copilot-instructions" ? path24.join(repoPath, ".github", "copilot-instructions.md") : path24.join(repoPath, "AGENTS.md");
|
|
14976
16167
|
setGenerateSavePath(savePath);
|
|
14977
16168
|
await doGenerate(repoPath, savePath, generateTarget);
|
|
14978
16169
|
return;
|
|
@@ -14982,7 +16173,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14982
16173
|
addLog(`Generating ${generateTarget} for ${repoApps.length} apps...`, "progress");
|
|
14983
16174
|
let count = 0;
|
|
14984
16175
|
for (const app2 of repoApps) {
|
|
14985
|
-
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");
|
|
14986
16177
|
setMessage(`Generating for ${app2.name} (${count + 1}/${repoApps.length})...`);
|
|
14987
16178
|
try {
|
|
14988
16179
|
const content = await generateCopilotInstructions({
|
|
@@ -14990,11 +16181,11 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14990
16181
|
onProgress: (msg) => setMessage(`${app2.name}: ${msg}`)
|
|
14991
16182
|
});
|
|
14992
16183
|
if (content.trim()) {
|
|
14993
|
-
await fs10.mkdir(
|
|
16184
|
+
await fs10.mkdir(path24.dirname(savePath), { recursive: true });
|
|
14994
16185
|
const { wrote: saved } = await safeWriteFile(savePath, content, true);
|
|
14995
16186
|
if (!saved) continue;
|
|
14996
16187
|
count++;
|
|
14997
|
-
addLog(`${app2.name}: saved ${
|
|
16188
|
+
addLog(`${app2.name}: saved ${path24.basename(savePath)}`, "success");
|
|
14998
16189
|
}
|
|
14999
16190
|
} catch (error) {
|
|
15000
16191
|
const msg = error instanceof Error ? error.message : "Failed.";
|
|
@@ -15008,7 +16199,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
15008
16199
|
const num = Number.parseInt(input, 10);
|
|
15009
16200
|
if (Number.isFinite(num) && num >= 1 && num <= repoApps.length) {
|
|
15010
16201
|
const app2 = repoApps[num - 1];
|
|
15011
|
-
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");
|
|
15012
16203
|
setGenerateSavePath(savePath);
|
|
15013
16204
|
await doGenerate(app2.path, savePath, generateTarget);
|
|
15014
16205
|
return;
|
|
@@ -15036,7 +16227,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
15036
16227
|
const result = await writeAreaInstruction(repoPath, area, body);
|
|
15037
16228
|
if (result.status === "written") {
|
|
15038
16229
|
written++;
|
|
15039
|
-
addLog(`${area.name}: saved ${
|
|
16230
|
+
addLog(`${area.name}: saved ${path24.basename(result.filePath)}`, "success");
|
|
15040
16231
|
} else if (result.status === "skipped") {
|
|
15041
16232
|
addLog(`${area.name}: skipped (file exists)`, "info");
|
|
15042
16233
|
}
|
|
@@ -15130,8 +16321,8 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
15130
16321
|
}
|
|
15131
16322
|
if (status === "eval-pick") {
|
|
15132
16323
|
if (input.toLowerCase() === "r") {
|
|
15133
|
-
const configPath =
|
|
15134
|
-
const outputPath =
|
|
16324
|
+
const configPath = path24.join(repoPath, "agentrc.eval.json");
|
|
16325
|
+
const outputPath = path24.join(
|
|
15135
16326
|
repoPath,
|
|
15136
16327
|
".agentrc",
|
|
15137
16328
|
"evals",
|
|
@@ -15275,6 +16466,36 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
15275
16466
|
setMessage("Select eval action.");
|
|
15276
16467
|
return;
|
|
15277
16468
|
}
|
|
16469
|
+
if (input.toLowerCase() === "c") {
|
|
16470
|
+
if (hasAgentrcConfig) {
|
|
16471
|
+
setMessage("agentrc.config.json already exists.");
|
|
16472
|
+
return;
|
|
16473
|
+
}
|
|
16474
|
+
setStatus("generating");
|
|
16475
|
+
setMessage("Creating agentrc.config.json...");
|
|
16476
|
+
addLog("Scaffolding agentrc.config.json...", "progress");
|
|
16477
|
+
try {
|
|
16478
|
+
const result = await scaffoldAgentrcConfig(repoPath, repoAreas);
|
|
16479
|
+
if (result.wrote) {
|
|
16480
|
+
setHasAgentrcConfig(true);
|
|
16481
|
+
setStatus("done");
|
|
16482
|
+
const msg = `Created agentrc.config.json`;
|
|
16483
|
+
setMessage(msg);
|
|
16484
|
+
addLog(msg, "success");
|
|
16485
|
+
} else {
|
|
16486
|
+
setHasAgentrcConfig(true);
|
|
16487
|
+
setStatus("idle");
|
|
16488
|
+
setMessage("agentrc.config.json already exists (skipped).");
|
|
16489
|
+
addLog("agentrc.config.json already exists.", "info");
|
|
16490
|
+
}
|
|
16491
|
+
} catch (error) {
|
|
16492
|
+
setStatus("error");
|
|
16493
|
+
const msg = error instanceof Error ? error.message : "Failed to create config.";
|
|
16494
|
+
setMessage(msg);
|
|
16495
|
+
addLog(msg, "error");
|
|
16496
|
+
}
|
|
16497
|
+
return;
|
|
16498
|
+
}
|
|
15278
16499
|
if (input.toLowerCase() === "m") {
|
|
15279
16500
|
if (hideModelPicker) {
|
|
15280
16501
|
setMessage(
|
|
@@ -15389,6 +16610,10 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
15389
16610
|
/* @__PURE__ */ jsxs4(Text5, { children: [
|
|
15390
16611
|
/* @__PURE__ */ jsx7(Text5, { color: "gray", children: "Eval " }),
|
|
15391
16612
|
hasEvalConfig === null ? /* @__PURE__ */ jsx7(Text5, { color: "gray", dimColor: true, children: "checking..." }) : hasEvalConfig ? /* @__PURE__ */ jsx7(Text5, { color: "green", children: "agentrc.eval.json found" }) : /* @__PURE__ */ jsx7(Text5, { color: "yellow", children: "no eval config \u2014 press [I] to create" })
|
|
16613
|
+
] }),
|
|
16614
|
+
/* @__PURE__ */ jsxs4(Text5, { children: [
|
|
16615
|
+
/* @__PURE__ */ jsx7(Text5, { color: "gray", children: "Config " }),
|
|
16616
|
+
hasAgentrcConfig === null ? /* @__PURE__ */ jsx7(Text5, { color: "gray", dimColor: true, children: "checking..." }) : hasAgentrcConfig ? /* @__PURE__ */ jsx7(Text5, { color: "green", children: "agentrc.config.json found" }) : /* @__PURE__ */ jsx7(Text5, { color: "yellow", children: "no config \u2014 press [C] to create" })
|
|
15392
16617
|
] })
|
|
15393
16618
|
] }),
|
|
15394
16619
|
/* @__PURE__ */ jsx7(Divider, { columns: terminalColumns, label: "Activity", accessible }),
|
|
@@ -15464,7 +16689,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
15464
16689
|
/* @__PURE__ */ jsx7(Text5, { color: "white", children: app2.name }),
|
|
15465
16690
|
/* @__PURE__ */ jsxs4(Text5, { color: "gray", dimColor: true, children: [
|
|
15466
16691
|
" ",
|
|
15467
|
-
|
|
16692
|
+
path24.relative(repoPath, app2.path)
|
|
15468
16693
|
] })
|
|
15469
16694
|
] }, app2.name)) })
|
|
15470
16695
|
] }),
|
|
@@ -15498,7 +16723,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
15498
16723
|
children: [
|
|
15499
16724
|
/* @__PURE__ */ jsxs4(Text5, { color: "cyan", bold: true, children: [
|
|
15500
16725
|
"Preview (",
|
|
15501
|
-
|
|
16726
|
+
path24.relative(repoPath, generateSavePath) || generateTarget,
|
|
15502
16727
|
")"
|
|
15503
16728
|
] }),
|
|
15504
16729
|
/* @__PURE__ */ jsx7(Text5, { color: "gray", children: truncatedPreview })
|
|
@@ -15595,6 +16820,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
15595
16820
|
/* @__PURE__ */ jsxs4(Box5, { children: [
|
|
15596
16821
|
/* @__PURE__ */ jsx7(KeyHint, { k: "M", label: "Model" }),
|
|
15597
16822
|
/* @__PURE__ */ jsx7(KeyHint, { k: "J", label: "Judge" }),
|
|
16823
|
+
hasAgentrcConfig === false && /* @__PURE__ */ jsx7(KeyHint, { k: "C", label: "Create config" }),
|
|
15598
16824
|
/* @__PURE__ */ jsx7(KeyHint, { k: "Q", label: "Quit" })
|
|
15599
16825
|
] })
|
|
15600
16826
|
] }) })
|
|
@@ -15606,7 +16832,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
15606
16832
|
// src/commands/tui.tsx
|
|
15607
16833
|
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
15608
16834
|
async function tuiCommand(options) {
|
|
15609
|
-
const repoPath =
|
|
16835
|
+
const repoPath = path25.resolve(options.repo ?? process.cwd());
|
|
15610
16836
|
const skipAnimation = options.animation === false;
|
|
15611
16837
|
try {
|
|
15612
16838
|
const accessible = options.accessible ? true : void 0;
|
|
@@ -15621,7 +16847,7 @@ async function tuiCommand(options) {
|
|
|
15621
16847
|
}
|
|
15622
16848
|
|
|
15623
16849
|
// src/cli.ts
|
|
15624
|
-
var _require =
|
|
16850
|
+
var _require = createRequire2(import.meta.url);
|
|
15625
16851
|
var CLI_VERSION = _require("../package.json").version;
|
|
15626
16852
|
function withGlobalOpts(fn) {
|
|
15627
16853
|
return async (...raw) => {
|
|
@@ -15651,7 +16877,7 @@ function runCli(argv) {
|
|
|
15651
16877
|
"mcp",
|
|
15652
16878
|
"vscode"
|
|
15653
16879
|
])
|
|
15654
|
-
).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));
|
|
15655
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));
|
|
15656
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));
|
|
15657
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));
|