@microsoft/agentrc 2.0.1-2 → 2.0.1-20
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 +61 -221
- package/dist/index.js +1834 -970
- 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 +4 -4
package/dist/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { createRequire as __bannerCreateRequire } from "node:module";
|
|
3
|
+
const require = __bannerCreateRequire(import.meta.url);
|
|
2
4
|
var __create = Object.create;
|
|
3
5
|
var __defProp = Object.defineProperty;
|
|
4
6
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -3050,7 +3052,7 @@ var require_main = __commonJS({
|
|
|
3050
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;
|
|
3051
3053
|
var ril_1 = require_ril();
|
|
3052
3054
|
ril_1.default.install();
|
|
3053
|
-
var
|
|
3055
|
+
var path26 = __require("path");
|
|
3054
3056
|
var os2 = __require("os");
|
|
3055
3057
|
var crypto_1 = __require("crypto");
|
|
3056
3058
|
var net_1 = __require("net");
|
|
@@ -3186,9 +3188,9 @@ var require_main = __commonJS({
|
|
|
3186
3188
|
}
|
|
3187
3189
|
let result;
|
|
3188
3190
|
if (XDG_RUNTIME_DIR) {
|
|
3189
|
-
result =
|
|
3191
|
+
result = path26.join(XDG_RUNTIME_DIR, `vscode-ipc-${randomSuffix}.sock`);
|
|
3190
3192
|
} else {
|
|
3191
|
-
result =
|
|
3193
|
+
result = path26.join(os2.tmpdir(), `vscode-${randomSuffix}.sock`);
|
|
3192
3194
|
}
|
|
3193
3195
|
const limit = safeIpcPathLengths.get(process.platform);
|
|
3194
3196
|
if (limit !== void 0 && result.length > limit) {
|
|
@@ -3329,23 +3331,63 @@ function createSessionRpc(connection, sessionId) {
|
|
|
3329
3331
|
readFile: async (params) => connection.sendRequest("session.workspace.readFile", { sessionId, ...params }),
|
|
3330
3332
|
createFile: async (params) => connection.sendRequest("session.workspace.createFile", { sessionId, ...params })
|
|
3331
3333
|
},
|
|
3334
|
+
/** @experimental */
|
|
3332
3335
|
fleet: {
|
|
3333
3336
|
start: async (params) => connection.sendRequest("session.fleet.start", { sessionId, ...params })
|
|
3334
3337
|
},
|
|
3338
|
+
/** @experimental */
|
|
3335
3339
|
agent: {
|
|
3336
3340
|
list: async () => connection.sendRequest("session.agent.list", { sessionId }),
|
|
3337
3341
|
getCurrent: async () => connection.sendRequest("session.agent.getCurrent", { sessionId }),
|
|
3338
3342
|
select: async (params) => connection.sendRequest("session.agent.select", { sessionId, ...params }),
|
|
3339
|
-
deselect: async () => connection.sendRequest("session.agent.deselect", { sessionId })
|
|
3343
|
+
deselect: async () => connection.sendRequest("session.agent.deselect", { sessionId }),
|
|
3344
|
+
reload: async () => connection.sendRequest("session.agent.reload", { sessionId })
|
|
3340
3345
|
},
|
|
3346
|
+
/** @experimental */
|
|
3347
|
+
skills: {
|
|
3348
|
+
list: async () => connection.sendRequest("session.skills.list", { sessionId }),
|
|
3349
|
+
enable: async (params) => connection.sendRequest("session.skills.enable", { sessionId, ...params }),
|
|
3350
|
+
disable: async (params) => connection.sendRequest("session.skills.disable", { sessionId, ...params }),
|
|
3351
|
+
reload: async () => connection.sendRequest("session.skills.reload", { sessionId })
|
|
3352
|
+
},
|
|
3353
|
+
/** @experimental */
|
|
3354
|
+
mcp: {
|
|
3355
|
+
list: async () => connection.sendRequest("session.mcp.list", { sessionId }),
|
|
3356
|
+
enable: async (params) => connection.sendRequest("session.mcp.enable", { sessionId, ...params }),
|
|
3357
|
+
disable: async (params) => connection.sendRequest("session.mcp.disable", { sessionId, ...params }),
|
|
3358
|
+
reload: async () => connection.sendRequest("session.mcp.reload", { sessionId })
|
|
3359
|
+
},
|
|
3360
|
+
/** @experimental */
|
|
3361
|
+
plugins: {
|
|
3362
|
+
list: async () => connection.sendRequest("session.plugins.list", { sessionId })
|
|
3363
|
+
},
|
|
3364
|
+
/** @experimental */
|
|
3365
|
+
extensions: {
|
|
3366
|
+
list: async () => connection.sendRequest("session.extensions.list", { sessionId }),
|
|
3367
|
+
enable: async (params) => connection.sendRequest("session.extensions.enable", { sessionId, ...params }),
|
|
3368
|
+
disable: async (params) => connection.sendRequest("session.extensions.disable", { sessionId, ...params }),
|
|
3369
|
+
reload: async () => connection.sendRequest("session.extensions.reload", { sessionId })
|
|
3370
|
+
},
|
|
3371
|
+
/** @experimental */
|
|
3341
3372
|
compaction: {
|
|
3342
3373
|
compact: async () => connection.sendRequest("session.compaction.compact", { sessionId })
|
|
3343
3374
|
},
|
|
3344
3375
|
tools: {
|
|
3345
3376
|
handlePendingToolCall: async (params) => connection.sendRequest("session.tools.handlePendingToolCall", { sessionId, ...params })
|
|
3346
3377
|
},
|
|
3378
|
+
commands: {
|
|
3379
|
+
handlePendingCommand: async (params) => connection.sendRequest("session.commands.handlePendingCommand", { sessionId, ...params })
|
|
3380
|
+
},
|
|
3381
|
+
ui: {
|
|
3382
|
+
elicitation: async (params) => connection.sendRequest("session.ui.elicitation", { sessionId, ...params })
|
|
3383
|
+
},
|
|
3347
3384
|
permissions: {
|
|
3348
3385
|
handlePendingPermissionRequest: async (params) => connection.sendRequest("session.permissions.handlePendingPermissionRequest", { sessionId, ...params })
|
|
3386
|
+
},
|
|
3387
|
+
log: async (params) => connection.sendRequest("session.log", { sessionId, ...params }),
|
|
3388
|
+
shell: {
|
|
3389
|
+
exec: async (params) => connection.sendRequest("session.shell.exec", { sessionId, ...params }),
|
|
3390
|
+
kill: async (params) => connection.sendRequest("session.shell.kill", { sessionId, ...params })
|
|
3349
3391
|
}
|
|
3350
3392
|
};
|
|
3351
3393
|
}
|
|
@@ -3367,13 +3409,30 @@ var init_sdkProtocolVersion = __esm({
|
|
|
3367
3409
|
}
|
|
3368
3410
|
});
|
|
3369
3411
|
|
|
3412
|
+
// node_modules/@github/copilot-sdk/dist/telemetry.js
|
|
3413
|
+
async function getTraceContext(provider) {
|
|
3414
|
+
if (!provider) return {};
|
|
3415
|
+
try {
|
|
3416
|
+
return await provider() ?? {};
|
|
3417
|
+
} catch {
|
|
3418
|
+
return {};
|
|
3419
|
+
}
|
|
3420
|
+
}
|
|
3421
|
+
var init_telemetry = __esm({
|
|
3422
|
+
"node_modules/@github/copilot-sdk/dist/telemetry.js"() {
|
|
3423
|
+
"use strict";
|
|
3424
|
+
}
|
|
3425
|
+
});
|
|
3426
|
+
|
|
3370
3427
|
// node_modules/@github/copilot-sdk/dist/session.js
|
|
3371
|
-
var import_node, CopilotSession;
|
|
3428
|
+
var import_node, NO_RESULT_PERMISSION_V2_ERROR, CopilotSession;
|
|
3372
3429
|
var init_session = __esm({
|
|
3373
3430
|
"node_modules/@github/copilot-sdk/dist/session.js"() {
|
|
3374
3431
|
"use strict";
|
|
3375
3432
|
import_node = __toESM(require_node(), 1);
|
|
3376
3433
|
init_rpc();
|
|
3434
|
+
init_telemetry();
|
|
3435
|
+
NO_RESULT_PERMISSION_V2_ERROR = "Permission handlers cannot return 'no-result' when connected to a protocol v2 server.";
|
|
3377
3436
|
CopilotSession = class {
|
|
3378
3437
|
/**
|
|
3379
3438
|
* Creates a new CopilotSession instance.
|
|
@@ -3381,12 +3440,14 @@ var init_session = __esm({
|
|
|
3381
3440
|
* @param sessionId - The unique identifier for this session
|
|
3382
3441
|
* @param connection - The JSON-RPC message connection to the Copilot CLI
|
|
3383
3442
|
* @param workspacePath - Path to the session workspace directory (when infinite sessions enabled)
|
|
3443
|
+
* @param traceContextProvider - Optional callback to get W3C Trace Context for outbound RPCs
|
|
3384
3444
|
* @internal This constructor is internal. Use {@link CopilotClient.createSession} to create sessions.
|
|
3385
3445
|
*/
|
|
3386
|
-
constructor(sessionId, connection, _workspacePath) {
|
|
3446
|
+
constructor(sessionId, connection, _workspacePath, traceContextProvider) {
|
|
3387
3447
|
this.sessionId = sessionId;
|
|
3388
3448
|
this.connection = connection;
|
|
3389
3449
|
this._workspacePath = _workspacePath;
|
|
3450
|
+
this.traceContextProvider = traceContextProvider;
|
|
3390
3451
|
}
|
|
3391
3452
|
eventHandlers = /* @__PURE__ */ new Set();
|
|
3392
3453
|
typedEventHandlers = /* @__PURE__ */ new Map();
|
|
@@ -3394,7 +3455,9 @@ var init_session = __esm({
|
|
|
3394
3455
|
permissionHandler;
|
|
3395
3456
|
userInputHandler;
|
|
3396
3457
|
hooks;
|
|
3458
|
+
transformCallbacks;
|
|
3397
3459
|
_rpc = null;
|
|
3460
|
+
traceContextProvider;
|
|
3398
3461
|
/**
|
|
3399
3462
|
* Typed session-scoped RPC methods.
|
|
3400
3463
|
*/
|
|
@@ -3432,6 +3495,7 @@ var init_session = __esm({
|
|
|
3432
3495
|
*/
|
|
3433
3496
|
async send(options) {
|
|
3434
3497
|
const response = await this.connection.sendRequest("session.send", {
|
|
3498
|
+
...await getTraceContext(this.traceContextProvider),
|
|
3435
3499
|
sessionId: this.sessionId,
|
|
3436
3500
|
prompt: options.prompt,
|
|
3437
3501
|
attachments: options.attachments,
|
|
@@ -3561,9 +3625,19 @@ var init_session = __esm({
|
|
|
3561
3625
|
const { requestId, toolName } = event.data;
|
|
3562
3626
|
const args2 = event.data.arguments;
|
|
3563
3627
|
const toolCallId = event.data.toolCallId;
|
|
3628
|
+
const traceparent = event.data.traceparent;
|
|
3629
|
+
const tracestate = event.data.tracestate;
|
|
3564
3630
|
const handler = this.toolHandlers.get(toolName);
|
|
3565
3631
|
if (handler) {
|
|
3566
|
-
void this._executeToolAndRespond(
|
|
3632
|
+
void this._executeToolAndRespond(
|
|
3633
|
+
requestId,
|
|
3634
|
+
toolName,
|
|
3635
|
+
toolCallId,
|
|
3636
|
+
args2,
|
|
3637
|
+
handler,
|
|
3638
|
+
traceparent,
|
|
3639
|
+
tracestate
|
|
3640
|
+
);
|
|
3567
3641
|
}
|
|
3568
3642
|
} else if (event.type === "permission.requested") {
|
|
3569
3643
|
const { requestId, permissionRequest } = event.data;
|
|
@@ -3576,13 +3650,15 @@ var init_session = __esm({
|
|
|
3576
3650
|
* Executes a tool handler and sends the result back via RPC.
|
|
3577
3651
|
* @internal
|
|
3578
3652
|
*/
|
|
3579
|
-
async _executeToolAndRespond(requestId, toolName, toolCallId, args2, handler) {
|
|
3653
|
+
async _executeToolAndRespond(requestId, toolName, toolCallId, args2, handler, traceparent, tracestate) {
|
|
3580
3654
|
try {
|
|
3581
3655
|
const rawResult = await handler(args2, {
|
|
3582
3656
|
sessionId: this.sessionId,
|
|
3583
3657
|
toolCallId,
|
|
3584
3658
|
toolName,
|
|
3585
|
-
arguments: args2
|
|
3659
|
+
arguments: args2,
|
|
3660
|
+
traceparent,
|
|
3661
|
+
tracestate
|
|
3586
3662
|
});
|
|
3587
3663
|
let result;
|
|
3588
3664
|
if (rawResult == null) {
|
|
@@ -3613,6 +3689,9 @@ var init_session = __esm({
|
|
|
3613
3689
|
const result = await this.permissionHandler(permissionRequest, {
|
|
3614
3690
|
sessionId: this.sessionId
|
|
3615
3691
|
});
|
|
3692
|
+
if (result.kind === "no-result") {
|
|
3693
|
+
return;
|
|
3694
|
+
}
|
|
3616
3695
|
await this.rpc.permissions.handlePendingPermissionRequest({ requestId, result });
|
|
3617
3696
|
} catch (_error) {
|
|
3618
3697
|
try {
|
|
@@ -3693,6 +3772,40 @@ var init_session = __esm({
|
|
|
3693
3772
|
registerHooks(hooks) {
|
|
3694
3773
|
this.hooks = hooks;
|
|
3695
3774
|
}
|
|
3775
|
+
/**
|
|
3776
|
+
* Registers transform callbacks for system message sections.
|
|
3777
|
+
*
|
|
3778
|
+
* @param callbacks - Map of section ID to transform callback, or undefined to clear
|
|
3779
|
+
* @internal This method is typically called internally when creating a session.
|
|
3780
|
+
*/
|
|
3781
|
+
registerTransformCallbacks(callbacks) {
|
|
3782
|
+
this.transformCallbacks = callbacks;
|
|
3783
|
+
}
|
|
3784
|
+
/**
|
|
3785
|
+
* Handles a systemMessage.transform request from the runtime.
|
|
3786
|
+
* Dispatches each section to its registered transform callback.
|
|
3787
|
+
*
|
|
3788
|
+
* @param sections - Map of section IDs to their current rendered content
|
|
3789
|
+
* @returns A promise that resolves with the transformed sections
|
|
3790
|
+
* @internal This method is for internal use by the SDK.
|
|
3791
|
+
*/
|
|
3792
|
+
async _handleSystemMessageTransform(sections) {
|
|
3793
|
+
const result = {};
|
|
3794
|
+
for (const [sectionId, { content }] of Object.entries(sections)) {
|
|
3795
|
+
const callback = this.transformCallbacks?.get(sectionId);
|
|
3796
|
+
if (callback) {
|
|
3797
|
+
try {
|
|
3798
|
+
const transformed = await callback(content);
|
|
3799
|
+
result[sectionId] = { content: transformed };
|
|
3800
|
+
} catch (_error) {
|
|
3801
|
+
result[sectionId] = { content };
|
|
3802
|
+
}
|
|
3803
|
+
} else {
|
|
3804
|
+
result[sectionId] = { content };
|
|
3805
|
+
}
|
|
3806
|
+
}
|
|
3807
|
+
return { sections: result };
|
|
3808
|
+
}
|
|
3696
3809
|
/**
|
|
3697
3810
|
* Handles a permission request in the v2 protocol format (synchronous RPC).
|
|
3698
3811
|
* Used as a back-compat adapter when connected to a v2 server.
|
|
@@ -3709,8 +3822,14 @@ var init_session = __esm({
|
|
|
3709
3822
|
const result = await this.permissionHandler(request, {
|
|
3710
3823
|
sessionId: this.sessionId
|
|
3711
3824
|
});
|
|
3825
|
+
if (result.kind === "no-result") {
|
|
3826
|
+
throw new Error(NO_RESULT_PERMISSION_V2_ERROR);
|
|
3827
|
+
}
|
|
3712
3828
|
return result;
|
|
3713
|
-
} catch (
|
|
3829
|
+
} catch (error) {
|
|
3830
|
+
if (error instanceof Error && error.message === NO_RESULT_PERMISSION_V2_ERROR) {
|
|
3831
|
+
throw error;
|
|
3832
|
+
}
|
|
3714
3833
|
return { kind: "denied-no-approval-rule-and-could-not-request-from-user" };
|
|
3715
3834
|
}
|
|
3716
3835
|
}
|
|
@@ -3866,14 +3985,35 @@ var init_session = __esm({
|
|
|
3866
3985
|
* The new model takes effect for the next message. Conversation history is preserved.
|
|
3867
3986
|
*
|
|
3868
3987
|
* @param model - Model ID to switch to
|
|
3988
|
+
* @param options - Optional settings for the new model
|
|
3869
3989
|
*
|
|
3870
3990
|
* @example
|
|
3871
3991
|
* ```typescript
|
|
3872
3992
|
* await session.setModel("gpt-4.1");
|
|
3993
|
+
* await session.setModel("claude-sonnet-4.6", { reasoningEffort: "high" });
|
|
3994
|
+
* ```
|
|
3995
|
+
*/
|
|
3996
|
+
async setModel(model, options) {
|
|
3997
|
+
await this.rpc.model.switchTo({ modelId: model, ...options });
|
|
3998
|
+
}
|
|
3999
|
+
/**
|
|
4000
|
+
* Log a message to the session timeline.
|
|
4001
|
+
* The message appears in the session event stream and is visible to SDK consumers
|
|
4002
|
+
* and (for non-ephemeral messages) persisted to the session event log on disk.
|
|
4003
|
+
*
|
|
4004
|
+
* @param message - Human-readable message text
|
|
4005
|
+
* @param options - Optional log level and ephemeral flag
|
|
4006
|
+
*
|
|
4007
|
+
* @example
|
|
4008
|
+
* ```typescript
|
|
4009
|
+
* await session.log("Processing started");
|
|
4010
|
+
* await session.log("Disk usage high", { level: "warning" });
|
|
4011
|
+
* await session.log("Connection failed", { level: "error" });
|
|
4012
|
+
* await session.log("Debug info", { ephemeral: true });
|
|
3873
4013
|
* ```
|
|
3874
4014
|
*/
|
|
3875
|
-
async
|
|
3876
|
-
await this.rpc.
|
|
4015
|
+
async log(message, options) {
|
|
4016
|
+
await this.rpc.log({ message, ...options });
|
|
3877
4017
|
}
|
|
3878
4018
|
};
|
|
3879
4019
|
}
|
|
@@ -3881,7 +4021,9 @@ var init_session = __esm({
|
|
|
3881
4021
|
|
|
3882
4022
|
// node_modules/@github/copilot-sdk/dist/client.js
|
|
3883
4023
|
import { spawn } from "child_process";
|
|
4024
|
+
import { randomUUID } from "crypto";
|
|
3884
4025
|
import { existsSync } from "fs";
|
|
4026
|
+
import { createRequire } from "module";
|
|
3885
4027
|
import { Socket } from "net";
|
|
3886
4028
|
import { dirname, join } from "path";
|
|
3887
4029
|
import { fileURLToPath } from "url";
|
|
@@ -3895,6 +4037,30 @@ function toJsonSchema(parameters) {
|
|
|
3895
4037
|
}
|
|
3896
4038
|
return parameters;
|
|
3897
4039
|
}
|
|
4040
|
+
function extractTransformCallbacks(systemMessage) {
|
|
4041
|
+
if (!systemMessage || systemMessage.mode !== "customize" || !systemMessage.sections) {
|
|
4042
|
+
return { wirePayload: systemMessage, transformCallbacks: void 0 };
|
|
4043
|
+
}
|
|
4044
|
+
const transformCallbacks = /* @__PURE__ */ new Map();
|
|
4045
|
+
const wireSections = {};
|
|
4046
|
+
for (const [sectionId, override] of Object.entries(systemMessage.sections)) {
|
|
4047
|
+
if (!override) continue;
|
|
4048
|
+
if (typeof override.action === "function") {
|
|
4049
|
+
transformCallbacks.set(sectionId, override.action);
|
|
4050
|
+
wireSections[sectionId] = { action: "transform" };
|
|
4051
|
+
} else {
|
|
4052
|
+
wireSections[sectionId] = { action: override.action, content: override.content };
|
|
4053
|
+
}
|
|
4054
|
+
}
|
|
4055
|
+
if (transformCallbacks.size === 0) {
|
|
4056
|
+
return { wirePayload: systemMessage, transformCallbacks: void 0 };
|
|
4057
|
+
}
|
|
4058
|
+
const wirePayload = {
|
|
4059
|
+
...systemMessage,
|
|
4060
|
+
sections: wireSections
|
|
4061
|
+
};
|
|
4062
|
+
return { wirePayload, transformCallbacks };
|
|
4063
|
+
}
|
|
3898
4064
|
function getNodeExecPath() {
|
|
3899
4065
|
if (process.versions.bun) {
|
|
3900
4066
|
return "node";
|
|
@@ -3912,6 +4078,7 @@ var init_client = __esm({
|
|
|
3912
4078
|
init_rpc();
|
|
3913
4079
|
init_sdkProtocolVersion();
|
|
3914
4080
|
init_session();
|
|
4081
|
+
init_telemetry();
|
|
3915
4082
|
MIN_PROTOCOL_VERSION = 2;
|
|
3916
4083
|
CopilotClient = class {
|
|
3917
4084
|
cliProcess = null;
|
|
@@ -3926,6 +4093,8 @@ var init_client = __esm({
|
|
|
3926
4093
|
options;
|
|
3927
4094
|
isExternalServer = false;
|
|
3928
4095
|
forceStopping = false;
|
|
4096
|
+
onListModels;
|
|
4097
|
+
onGetTraceContext;
|
|
3929
4098
|
modelsCache = null;
|
|
3930
4099
|
modelsCacheLock = Promise.resolve();
|
|
3931
4100
|
sessionLifecycleHandlers = /* @__PURE__ */ new Set();
|
|
@@ -3991,8 +4160,10 @@ var init_client = __esm({
|
|
|
3991
4160
|
if (options.isChildProcess) {
|
|
3992
4161
|
this.isExternalServer = true;
|
|
3993
4162
|
}
|
|
4163
|
+
this.onListModels = options.onListModels;
|
|
4164
|
+
this.onGetTraceContext = options.onGetTraceContext;
|
|
3994
4165
|
this.options = {
|
|
3995
|
-
cliPath: options.cliPath || getBundledCliPath(),
|
|
4166
|
+
cliPath: options.cliUrl ? void 0 : options.cliPath || getBundledCliPath(),
|
|
3996
4167
|
cliArgs: options.cliArgs ?? [],
|
|
3997
4168
|
cwd: options.cwd ?? process.cwd(),
|
|
3998
4169
|
port: options.port || 0,
|
|
@@ -4002,11 +4173,12 @@ var init_client = __esm({
|
|
|
4002
4173
|
cliUrl: options.cliUrl,
|
|
4003
4174
|
logLevel: options.logLevel || "debug",
|
|
4004
4175
|
autoStart: options.autoStart ?? true,
|
|
4005
|
-
autoRestart:
|
|
4176
|
+
autoRestart: false,
|
|
4006
4177
|
env: options.env ?? process.env,
|
|
4007
4178
|
githubToken: options.githubToken,
|
|
4008
4179
|
// Default useLoggedInUser to false when githubToken is provided, otherwise true
|
|
4009
|
-
useLoggedInUser: options.useLoggedInUser ?? (options.githubToken ? false : true)
|
|
4180
|
+
useLoggedInUser: options.useLoggedInUser ?? (options.githubToken ? false : true),
|
|
4181
|
+
telemetry: options.telemetry
|
|
4010
4182
|
};
|
|
4011
4183
|
}
|
|
4012
4184
|
/**
|
|
@@ -4258,36 +4430,13 @@ var init_client = __esm({
|
|
|
4258
4430
|
throw new Error("Client not connected. Call start() first.");
|
|
4259
4431
|
}
|
|
4260
4432
|
}
|
|
4261
|
-
const
|
|
4262
|
-
|
|
4263
|
-
sessionId
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
|
|
4267
|
-
|
|
4268
|
-
description: tool.description,
|
|
4269
|
-
parameters: toJsonSchema(tool.parameters),
|
|
4270
|
-
overridesBuiltInTool: tool.overridesBuiltInTool
|
|
4271
|
-
})),
|
|
4272
|
-
systemMessage: config.systemMessage,
|
|
4273
|
-
availableTools: config.availableTools,
|
|
4274
|
-
excludedTools: config.excludedTools,
|
|
4275
|
-
provider: config.provider,
|
|
4276
|
-
requestPermission: true,
|
|
4277
|
-
requestUserInput: !!config.onUserInputRequest,
|
|
4278
|
-
hooks: !!(config.hooks && Object.values(config.hooks).some(Boolean)),
|
|
4279
|
-
workingDirectory: config.workingDirectory,
|
|
4280
|
-
streaming: config.streaming,
|
|
4281
|
-
mcpServers: config.mcpServers,
|
|
4282
|
-
envValueMode: "direct",
|
|
4283
|
-
customAgents: config.customAgents,
|
|
4284
|
-
configDir: config.configDir,
|
|
4285
|
-
skillDirectories: config.skillDirectories,
|
|
4286
|
-
disabledSkills: config.disabledSkills,
|
|
4287
|
-
infiniteSessions: config.infiniteSessions
|
|
4288
|
-
});
|
|
4289
|
-
const { sessionId, workspacePath } = response;
|
|
4290
|
-
const session = new CopilotSession(sessionId, this.connection, workspacePath);
|
|
4433
|
+
const sessionId = config.sessionId ?? randomUUID();
|
|
4434
|
+
const session = new CopilotSession(
|
|
4435
|
+
sessionId,
|
|
4436
|
+
this.connection,
|
|
4437
|
+
void 0,
|
|
4438
|
+
this.onGetTraceContext
|
|
4439
|
+
);
|
|
4291
4440
|
session.registerTools(config.tools);
|
|
4292
4441
|
session.registerPermissionHandler(config.onPermissionRequest);
|
|
4293
4442
|
if (config.onUserInputRequest) {
|
|
@@ -4296,7 +4445,54 @@ var init_client = __esm({
|
|
|
4296
4445
|
if (config.hooks) {
|
|
4297
4446
|
session.registerHooks(config.hooks);
|
|
4298
4447
|
}
|
|
4448
|
+
const { wirePayload: wireSystemMessage, transformCallbacks } = extractTransformCallbacks(
|
|
4449
|
+
config.systemMessage
|
|
4450
|
+
);
|
|
4451
|
+
if (transformCallbacks) {
|
|
4452
|
+
session.registerTransformCallbacks(transformCallbacks);
|
|
4453
|
+
}
|
|
4454
|
+
if (config.onEvent) {
|
|
4455
|
+
session.on(config.onEvent);
|
|
4456
|
+
}
|
|
4299
4457
|
this.sessions.set(sessionId, session);
|
|
4458
|
+
try {
|
|
4459
|
+
const response = await this.connection.sendRequest("session.create", {
|
|
4460
|
+
...await getTraceContext(this.onGetTraceContext),
|
|
4461
|
+
model: config.model,
|
|
4462
|
+
sessionId,
|
|
4463
|
+
clientName: config.clientName,
|
|
4464
|
+
reasoningEffort: config.reasoningEffort,
|
|
4465
|
+
tools: config.tools?.map((tool) => ({
|
|
4466
|
+
name: tool.name,
|
|
4467
|
+
description: tool.description,
|
|
4468
|
+
parameters: toJsonSchema(tool.parameters),
|
|
4469
|
+
overridesBuiltInTool: tool.overridesBuiltInTool,
|
|
4470
|
+
skipPermission: tool.skipPermission
|
|
4471
|
+
})),
|
|
4472
|
+
systemMessage: wireSystemMessage,
|
|
4473
|
+
availableTools: config.availableTools,
|
|
4474
|
+
excludedTools: config.excludedTools,
|
|
4475
|
+
provider: config.provider,
|
|
4476
|
+
requestPermission: true,
|
|
4477
|
+
requestUserInput: !!config.onUserInputRequest,
|
|
4478
|
+
hooks: !!(config.hooks && Object.values(config.hooks).some(Boolean)),
|
|
4479
|
+
workingDirectory: config.workingDirectory,
|
|
4480
|
+
streaming: config.streaming,
|
|
4481
|
+
mcpServers: config.mcpServers,
|
|
4482
|
+
envValueMode: "direct",
|
|
4483
|
+
customAgents: config.customAgents,
|
|
4484
|
+
agent: config.agent,
|
|
4485
|
+
configDir: config.configDir,
|
|
4486
|
+
skillDirectories: config.skillDirectories,
|
|
4487
|
+
disabledSkills: config.disabledSkills,
|
|
4488
|
+
infiniteSessions: config.infiniteSessions
|
|
4489
|
+
});
|
|
4490
|
+
const { workspacePath } = response;
|
|
4491
|
+
session["_workspacePath"] = workspacePath;
|
|
4492
|
+
} catch (e) {
|
|
4493
|
+
this.sessions.delete(sessionId);
|
|
4494
|
+
throw e;
|
|
4495
|
+
}
|
|
4300
4496
|
return session;
|
|
4301
4497
|
}
|
|
4302
4498
|
/**
|
|
@@ -4336,37 +4532,12 @@ var init_client = __esm({
|
|
|
4336
4532
|
throw new Error("Client not connected. Call start() first.");
|
|
4337
4533
|
}
|
|
4338
4534
|
}
|
|
4339
|
-
const
|
|
4535
|
+
const session = new CopilotSession(
|
|
4340
4536
|
sessionId,
|
|
4341
|
-
|
|
4342
|
-
|
|
4343
|
-
|
|
4344
|
-
|
|
4345
|
-
availableTools: config.availableTools,
|
|
4346
|
-
excludedTools: config.excludedTools,
|
|
4347
|
-
tools: config.tools?.map((tool) => ({
|
|
4348
|
-
name: tool.name,
|
|
4349
|
-
description: tool.description,
|
|
4350
|
-
parameters: toJsonSchema(tool.parameters),
|
|
4351
|
-
overridesBuiltInTool: tool.overridesBuiltInTool
|
|
4352
|
-
})),
|
|
4353
|
-
provider: config.provider,
|
|
4354
|
-
requestPermission: true,
|
|
4355
|
-
requestUserInput: !!config.onUserInputRequest,
|
|
4356
|
-
hooks: !!(config.hooks && Object.values(config.hooks).some(Boolean)),
|
|
4357
|
-
workingDirectory: config.workingDirectory,
|
|
4358
|
-
configDir: config.configDir,
|
|
4359
|
-
streaming: config.streaming,
|
|
4360
|
-
mcpServers: config.mcpServers,
|
|
4361
|
-
envValueMode: "direct",
|
|
4362
|
-
customAgents: config.customAgents,
|
|
4363
|
-
skillDirectories: config.skillDirectories,
|
|
4364
|
-
disabledSkills: config.disabledSkills,
|
|
4365
|
-
infiniteSessions: config.infiniteSessions,
|
|
4366
|
-
disableResume: config.disableResume
|
|
4367
|
-
});
|
|
4368
|
-
const { sessionId: resumedSessionId, workspacePath } = response;
|
|
4369
|
-
const session = new CopilotSession(resumedSessionId, this.connection, workspacePath);
|
|
4537
|
+
this.connection,
|
|
4538
|
+
void 0,
|
|
4539
|
+
this.onGetTraceContext
|
|
4540
|
+
);
|
|
4370
4541
|
session.registerTools(config.tools);
|
|
4371
4542
|
session.registerPermissionHandler(config.onPermissionRequest);
|
|
4372
4543
|
if (config.onUserInputRequest) {
|
|
@@ -4375,7 +4546,55 @@ var init_client = __esm({
|
|
|
4375
4546
|
if (config.hooks) {
|
|
4376
4547
|
session.registerHooks(config.hooks);
|
|
4377
4548
|
}
|
|
4378
|
-
|
|
4549
|
+
const { wirePayload: wireSystemMessage, transformCallbacks } = extractTransformCallbacks(
|
|
4550
|
+
config.systemMessage
|
|
4551
|
+
);
|
|
4552
|
+
if (transformCallbacks) {
|
|
4553
|
+
session.registerTransformCallbacks(transformCallbacks);
|
|
4554
|
+
}
|
|
4555
|
+
if (config.onEvent) {
|
|
4556
|
+
session.on(config.onEvent);
|
|
4557
|
+
}
|
|
4558
|
+
this.sessions.set(sessionId, session);
|
|
4559
|
+
try {
|
|
4560
|
+
const response = await this.connection.sendRequest("session.resume", {
|
|
4561
|
+
...await getTraceContext(this.onGetTraceContext),
|
|
4562
|
+
sessionId,
|
|
4563
|
+
clientName: config.clientName,
|
|
4564
|
+
model: config.model,
|
|
4565
|
+
reasoningEffort: config.reasoningEffort,
|
|
4566
|
+
systemMessage: wireSystemMessage,
|
|
4567
|
+
availableTools: config.availableTools,
|
|
4568
|
+
excludedTools: config.excludedTools,
|
|
4569
|
+
tools: config.tools?.map((tool) => ({
|
|
4570
|
+
name: tool.name,
|
|
4571
|
+
description: tool.description,
|
|
4572
|
+
parameters: toJsonSchema(tool.parameters),
|
|
4573
|
+
overridesBuiltInTool: tool.overridesBuiltInTool,
|
|
4574
|
+
skipPermission: tool.skipPermission
|
|
4575
|
+
})),
|
|
4576
|
+
provider: config.provider,
|
|
4577
|
+
requestPermission: true,
|
|
4578
|
+
requestUserInput: !!config.onUserInputRequest,
|
|
4579
|
+
hooks: !!(config.hooks && Object.values(config.hooks).some(Boolean)),
|
|
4580
|
+
workingDirectory: config.workingDirectory,
|
|
4581
|
+
configDir: config.configDir,
|
|
4582
|
+
streaming: config.streaming,
|
|
4583
|
+
mcpServers: config.mcpServers,
|
|
4584
|
+
envValueMode: "direct",
|
|
4585
|
+
customAgents: config.customAgents,
|
|
4586
|
+
agent: config.agent,
|
|
4587
|
+
skillDirectories: config.skillDirectories,
|
|
4588
|
+
disabledSkills: config.disabledSkills,
|
|
4589
|
+
infiniteSessions: config.infiniteSessions,
|
|
4590
|
+
disableResume: config.disableResume
|
|
4591
|
+
});
|
|
4592
|
+
const { workspacePath } = response;
|
|
4593
|
+
session["_workspacePath"] = workspacePath;
|
|
4594
|
+
} catch (e) {
|
|
4595
|
+
this.sessions.delete(sessionId);
|
|
4596
|
+
throw e;
|
|
4597
|
+
}
|
|
4379
4598
|
return session;
|
|
4380
4599
|
}
|
|
4381
4600
|
/**
|
|
@@ -4436,15 +4655,15 @@ var init_client = __esm({
|
|
|
4436
4655
|
/**
|
|
4437
4656
|
* List available models with their metadata.
|
|
4438
4657
|
*
|
|
4658
|
+
* If an `onListModels` handler was provided in the client options,
|
|
4659
|
+
* it is called instead of querying the CLI server.
|
|
4660
|
+
*
|
|
4439
4661
|
* Results are cached after the first successful call to avoid rate limiting.
|
|
4440
4662
|
* The cache is cleared when the client disconnects.
|
|
4441
4663
|
*
|
|
4442
|
-
* @throws Error if not
|
|
4664
|
+
* @throws Error if not connected (when no custom handler is set)
|
|
4443
4665
|
*/
|
|
4444
4666
|
async listModels() {
|
|
4445
|
-
if (!this.connection) {
|
|
4446
|
-
throw new Error("Client not connected");
|
|
4447
|
-
}
|
|
4448
4667
|
await this.modelsCacheLock;
|
|
4449
4668
|
let resolveLock;
|
|
4450
4669
|
this.modelsCacheLock = new Promise((resolve) => {
|
|
@@ -4454,10 +4673,18 @@ var init_client = __esm({
|
|
|
4454
4673
|
if (this.modelsCache !== null) {
|
|
4455
4674
|
return [...this.modelsCache];
|
|
4456
4675
|
}
|
|
4457
|
-
|
|
4458
|
-
|
|
4459
|
-
|
|
4460
|
-
|
|
4676
|
+
let models;
|
|
4677
|
+
if (this.onListModels) {
|
|
4678
|
+
models = await this.onListModels();
|
|
4679
|
+
} else {
|
|
4680
|
+
if (!this.connection) {
|
|
4681
|
+
throw new Error("Client not connected");
|
|
4682
|
+
}
|
|
4683
|
+
const result = await this.connection.sendRequest("models.list", {});
|
|
4684
|
+
const response = result;
|
|
4685
|
+
models = response.models;
|
|
4686
|
+
}
|
|
4687
|
+
this.modelsCache = [...models];
|
|
4461
4688
|
return [...models];
|
|
4462
4689
|
} finally {
|
|
4463
4690
|
resolveLock();
|
|
@@ -4670,6 +4897,27 @@ var init_client = __esm({
|
|
|
4670
4897
|
if (this.options.githubToken) {
|
|
4671
4898
|
envWithoutNodeDebug.COPILOT_SDK_AUTH_TOKEN = this.options.githubToken;
|
|
4672
4899
|
}
|
|
4900
|
+
if (!this.options.cliPath) {
|
|
4901
|
+
throw new Error(
|
|
4902
|
+
"Path to Copilot CLI is required. Please provide it via the cliPath option, or use cliUrl to rely on a remote CLI."
|
|
4903
|
+
);
|
|
4904
|
+
}
|
|
4905
|
+
if (this.options.telemetry) {
|
|
4906
|
+
const t = this.options.telemetry;
|
|
4907
|
+
envWithoutNodeDebug.COPILOT_OTEL_ENABLED = "true";
|
|
4908
|
+
if (t.otlpEndpoint !== void 0)
|
|
4909
|
+
envWithoutNodeDebug.OTEL_EXPORTER_OTLP_ENDPOINT = t.otlpEndpoint;
|
|
4910
|
+
if (t.filePath !== void 0)
|
|
4911
|
+
envWithoutNodeDebug.COPILOT_OTEL_FILE_EXPORTER_PATH = t.filePath;
|
|
4912
|
+
if (t.exporterType !== void 0)
|
|
4913
|
+
envWithoutNodeDebug.COPILOT_OTEL_EXPORTER_TYPE = t.exporterType;
|
|
4914
|
+
if (t.sourceName !== void 0)
|
|
4915
|
+
envWithoutNodeDebug.COPILOT_OTEL_SOURCE_NAME = t.sourceName;
|
|
4916
|
+
if (t.captureContent !== void 0)
|
|
4917
|
+
envWithoutNodeDebug.OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT = String(
|
|
4918
|
+
t.captureContent
|
|
4919
|
+
);
|
|
4920
|
+
}
|
|
4673
4921
|
if (!existsSync(this.options.cliPath)) {
|
|
4674
4922
|
throw new Error(
|
|
4675
4923
|
`Copilot CLI not found at ${this.options.cliPath}. Ensure @github/copilot is installed.`
|
|
@@ -4769,8 +5017,6 @@ stderr: ${stderrOutput}`
|
|
|
4769
5017
|
} else {
|
|
4770
5018
|
reject(new Error(`CLI server exited with code ${code}`));
|
|
4771
5019
|
}
|
|
4772
|
-
} else if (this.options.autoRestart && this.state === "connected") {
|
|
4773
|
-
void this.reconnect();
|
|
4774
5020
|
}
|
|
4775
5021
|
});
|
|
4776
5022
|
setTimeout(() => {
|
|
@@ -4875,12 +5121,15 @@ stderr: ${stderrOutput}`
|
|
|
4875
5121
|
"hooks.invoke",
|
|
4876
5122
|
async (params) => await this.handleHooksInvoke(params)
|
|
4877
5123
|
);
|
|
5124
|
+
this.connection.onRequest(
|
|
5125
|
+
"systemMessage.transform",
|
|
5126
|
+
async (params) => await this.handleSystemMessageTransform(params)
|
|
5127
|
+
);
|
|
4878
5128
|
this.connection.onClose(() => {
|
|
4879
|
-
|
|
4880
|
-
void this.reconnect();
|
|
4881
|
-
}
|
|
5129
|
+
this.state = "disconnected";
|
|
4882
5130
|
});
|
|
4883
5131
|
this.connection.onError((_error) => {
|
|
5132
|
+
this.state = "disconnected";
|
|
4884
5133
|
});
|
|
4885
5134
|
}
|
|
4886
5135
|
handleSessionEventNotification(notification) {
|
|
@@ -4939,6 +5188,16 @@ stderr: ${stderrOutput}`
|
|
|
4939
5188
|
const output = await session._handleHooksInvoke(params.hookType, params.input);
|
|
4940
5189
|
return { output };
|
|
4941
5190
|
}
|
|
5191
|
+
async handleSystemMessageTransform(params) {
|
|
5192
|
+
if (!params || typeof params.sessionId !== "string" || !params.sections || typeof params.sections !== "object") {
|
|
5193
|
+
throw new Error("Invalid systemMessage.transform payload");
|
|
5194
|
+
}
|
|
5195
|
+
const session = this.sessions.get(params.sessionId);
|
|
5196
|
+
if (!session) {
|
|
5197
|
+
throw new Error(`Session not found: ${params.sessionId}`);
|
|
5198
|
+
}
|
|
5199
|
+
return await session._handleSystemMessageTransform(params.sections);
|
|
5200
|
+
}
|
|
4942
5201
|
// ========================================================================
|
|
4943
5202
|
// Protocol v2 backward-compatibility adapters
|
|
4944
5203
|
// ========================================================================
|
|
@@ -4967,11 +5226,15 @@ stderr: ${stderrOutput}`
|
|
|
4967
5226
|
};
|
|
4968
5227
|
}
|
|
4969
5228
|
try {
|
|
5229
|
+
const traceparent = params.traceparent;
|
|
5230
|
+
const tracestate = params.tracestate;
|
|
4970
5231
|
const invocation = {
|
|
4971
5232
|
sessionId: params.sessionId,
|
|
4972
5233
|
toolCallId: params.toolCallId,
|
|
4973
5234
|
toolName: params.toolName,
|
|
4974
|
-
arguments: params.arguments
|
|
5235
|
+
arguments: params.arguments,
|
|
5236
|
+
traceparent,
|
|
5237
|
+
tracestate
|
|
4975
5238
|
};
|
|
4976
5239
|
const result = await handler(params.arguments, invocation);
|
|
4977
5240
|
return { result: this.normalizeToolResultV2(result) };
|
|
@@ -5001,7 +5264,10 @@ stderr: ${stderrOutput}`
|
|
|
5001
5264
|
try {
|
|
5002
5265
|
const result = await session._handlePermissionRequestV2(params.permissionRequest);
|
|
5003
5266
|
return { result };
|
|
5004
|
-
} catch (
|
|
5267
|
+
} catch (error) {
|
|
5268
|
+
if (error instanceof Error && error.message === NO_RESULT_PERMISSION_V2_ERROR) {
|
|
5269
|
+
throw error;
|
|
5270
|
+
}
|
|
5005
5271
|
return {
|
|
5006
5272
|
result: {
|
|
5007
5273
|
kind: "denied-no-approval-rule-and-could-not-request-from-user"
|
|
@@ -5031,17 +5297,6 @@ stderr: ${stderrOutput}`
|
|
|
5031
5297
|
isToolResultObject(value) {
|
|
5032
5298
|
return typeof value === "object" && value !== null && "textResultForLlm" in value && typeof value.textResultForLlm === "string" && "resultType" in value;
|
|
5033
5299
|
}
|
|
5034
|
-
/**
|
|
5035
|
-
* Attempt to reconnect to the server
|
|
5036
|
-
*/
|
|
5037
|
-
async reconnect() {
|
|
5038
|
-
this.state = "disconnected";
|
|
5039
|
-
try {
|
|
5040
|
-
await this.stop();
|
|
5041
|
-
await this.start();
|
|
5042
|
-
} catch (_error) {
|
|
5043
|
-
}
|
|
5044
|
-
}
|
|
5045
5300
|
};
|
|
5046
5301
|
}
|
|
5047
5302
|
});
|
|
@@ -5050,10 +5305,24 @@ stderr: ${stderrOutput}`
|
|
|
5050
5305
|
function defineTool(name, config) {
|
|
5051
5306
|
return { name, ...config };
|
|
5052
5307
|
}
|
|
5053
|
-
var approveAll;
|
|
5308
|
+
var SYSTEM_PROMPT_SECTIONS, approveAll;
|
|
5054
5309
|
var init_types = __esm({
|
|
5055
5310
|
"node_modules/@github/copilot-sdk/dist/types.js"() {
|
|
5056
5311
|
"use strict";
|
|
5312
|
+
SYSTEM_PROMPT_SECTIONS = {
|
|
5313
|
+
identity: { description: "Agent identity preamble and mode statement" },
|
|
5314
|
+
tone: { description: "Response style, conciseness rules, output formatting preferences" },
|
|
5315
|
+
tool_efficiency: { description: "Tool usage patterns, parallel calling, batching guidelines" },
|
|
5316
|
+
environment_context: { description: "CWD, OS, git root, directory listing, available tools" },
|
|
5317
|
+
code_change_rules: { description: "Coding rules, linting/testing, ecosystem tools, style" },
|
|
5318
|
+
guidelines: { description: "Tips, behavioral best practices, behavioral guidelines" },
|
|
5319
|
+
safety: { description: "Environment limitations, prohibited actions, security policies" },
|
|
5320
|
+
tool_instructions: { description: "Per-tool usage instructions" },
|
|
5321
|
+
custom_instructions: { description: "Repository and organization custom instructions" },
|
|
5322
|
+
last_instructions: {
|
|
5323
|
+
description: "End-of-prompt instructions: parallel tool calling, persistence, task completion"
|
|
5324
|
+
}
|
|
5325
|
+
};
|
|
5057
5326
|
approveAll = () => ({ kind: "approved" });
|
|
5058
5327
|
}
|
|
5059
5328
|
});
|
|
@@ -5063,6 +5332,7 @@ var dist_exports = {};
|
|
|
5063
5332
|
__export(dist_exports, {
|
|
5064
5333
|
CopilotClient: () => CopilotClient,
|
|
5065
5334
|
CopilotSession: () => CopilotSession,
|
|
5335
|
+
SYSTEM_PROMPT_SECTIONS: () => SYSTEM_PROMPT_SECTIONS,
|
|
5066
5336
|
approveAll: () => approveAll,
|
|
5067
5337
|
defineTool: () => defineTool
|
|
5068
5338
|
});
|
|
@@ -5076,7 +5346,7 @@ var init_dist = __esm({
|
|
|
5076
5346
|
});
|
|
5077
5347
|
|
|
5078
5348
|
// src/cli.ts
|
|
5079
|
-
import { createRequire } from "module";
|
|
5349
|
+
import { createRequire as createRequire2 } from "module";
|
|
5080
5350
|
|
|
5081
5351
|
// packages/core/src/config.ts
|
|
5082
5352
|
var DEFAULT_MODEL = "claude-sonnet-4.6";
|
|
@@ -5332,6 +5602,18 @@ async function fileExists(filePath) {
|
|
|
5332
5602
|
return false;
|
|
5333
5603
|
}
|
|
5334
5604
|
}
|
|
5605
|
+
async function canSafeWrite(filePath, force) {
|
|
5606
|
+
const resolved = path.resolve(filePath);
|
|
5607
|
+
if (await hasSymlinkAncestor(resolved)) return false;
|
|
5608
|
+
try {
|
|
5609
|
+
const stat = await fs.lstat(resolved);
|
|
5610
|
+
if (stat.isSymbolicLink()) return false;
|
|
5611
|
+
return force;
|
|
5612
|
+
} catch (error) {
|
|
5613
|
+
if (error.code === "ENOENT") return true;
|
|
5614
|
+
throw error;
|
|
5615
|
+
}
|
|
5616
|
+
}
|
|
5335
5617
|
async function safeReadDir(dirPath) {
|
|
5336
5618
|
try {
|
|
5337
5619
|
return await fs.readdir(dirPath);
|
|
@@ -5339,10 +5621,68 @@ async function safeReadDir(dirPath) {
|
|
|
5339
5621
|
return [];
|
|
5340
5622
|
}
|
|
5341
5623
|
}
|
|
5624
|
+
function stripJsonComments(text) {
|
|
5625
|
+
let result = "";
|
|
5626
|
+
let i = 0;
|
|
5627
|
+
while (i < text.length) {
|
|
5628
|
+
if (text[i] === '"') {
|
|
5629
|
+
let j = i + 1;
|
|
5630
|
+
while (j < text.length) {
|
|
5631
|
+
if (text[j] === "\\") {
|
|
5632
|
+
j += 2;
|
|
5633
|
+
continue;
|
|
5634
|
+
}
|
|
5635
|
+
if (text[j] === '"') {
|
|
5636
|
+
j++;
|
|
5637
|
+
break;
|
|
5638
|
+
}
|
|
5639
|
+
j++;
|
|
5640
|
+
}
|
|
5641
|
+
result += text.slice(i, j);
|
|
5642
|
+
i = j;
|
|
5643
|
+
continue;
|
|
5644
|
+
}
|
|
5645
|
+
if (text[i] === "/" && text[i + 1] === "/") {
|
|
5646
|
+
i += 2;
|
|
5647
|
+
while (i < text.length && text[i] !== "\n") i++;
|
|
5648
|
+
continue;
|
|
5649
|
+
}
|
|
5650
|
+
if (text[i] === "/" && text[i + 1] === "*") {
|
|
5651
|
+
i += 2;
|
|
5652
|
+
while (i < text.length && !(text[i] === "*" && text[i + 1] === "/")) i++;
|
|
5653
|
+
if (i < text.length) i += 2;
|
|
5654
|
+
continue;
|
|
5655
|
+
}
|
|
5656
|
+
if (text[i] === ",") {
|
|
5657
|
+
let j = i + 1;
|
|
5658
|
+
while (j < text.length) {
|
|
5659
|
+
if (text[j] === " " || text[j] === " " || text[j] === "\n" || text[j] === "\r") {
|
|
5660
|
+
j++;
|
|
5661
|
+
} else if (text[j] === "/" && text[j + 1] === "/") {
|
|
5662
|
+
j += 2;
|
|
5663
|
+
while (j < text.length && text[j] !== "\n") j++;
|
|
5664
|
+
} else if (text[j] === "/" && text[j + 1] === "*") {
|
|
5665
|
+
j += 2;
|
|
5666
|
+
while (j < text.length && !(text[j] === "*" && text[j + 1] === "/")) j++;
|
|
5667
|
+
if (j < text.length) j += 2;
|
|
5668
|
+
} else {
|
|
5669
|
+
break;
|
|
5670
|
+
}
|
|
5671
|
+
}
|
|
5672
|
+
if (j < text.length && (text[j] === "}" || text[j] === "]")) {
|
|
5673
|
+
i++;
|
|
5674
|
+
continue;
|
|
5675
|
+
}
|
|
5676
|
+
}
|
|
5677
|
+
result += text[i];
|
|
5678
|
+
i++;
|
|
5679
|
+
}
|
|
5680
|
+
return result;
|
|
5681
|
+
}
|
|
5342
5682
|
async function readJson(filePath) {
|
|
5343
5683
|
try {
|
|
5344
5684
|
const raw = await fs.readFile(filePath, "utf8");
|
|
5345
|
-
return JSON.parse(raw);
|
|
5685
|
+
return JSON.parse(stripJsonComments(raw));
|
|
5346
5686
|
} catch {
|
|
5347
5687
|
return void 0;
|
|
5348
5688
|
}
|
|
@@ -5357,7 +5697,8 @@ var PACKAGE_MANAGERS = [
|
|
|
5357
5697
|
{ file: "pnpm-lock.yaml", name: "pnpm" },
|
|
5358
5698
|
{ file: "yarn.lock", name: "yarn" },
|
|
5359
5699
|
{ file: "package-lock.json", name: "npm" },
|
|
5360
|
-
{ file: "bun.lockb", name: "bun" }
|
|
5700
|
+
{ file: "bun.lockb", name: "bun" },
|
|
5701
|
+
{ file: "packages.lock.json", name: "nuget" }
|
|
5361
5702
|
];
|
|
5362
5703
|
async function analyzeRepo(repoPath) {
|
|
5363
5704
|
const files = await safeReadDir(repoPath);
|
|
@@ -5379,9 +5720,11 @@ async function analyzeRepo(repoPath) {
|
|
|
5379
5720
|
const hasRequirements = files.includes("requirements.txt");
|
|
5380
5721
|
const hasGoMod = files.includes("go.mod");
|
|
5381
5722
|
const hasCargo = files.includes("Cargo.toml");
|
|
5382
|
-
const
|
|
5383
|
-
(f) => f.endsWith(".csproj") || f.endsWith(".sln") || f.endsWith(".slnx")
|
|
5723
|
+
const hasDotnet = files.some(
|
|
5724
|
+
(f) => f.endsWith(".csproj") || f.endsWith(".fsproj") || f.endsWith(".sln") || f.endsWith(".slnx") || f === "global.json" || f === "Directory.Build.props"
|
|
5384
5725
|
);
|
|
5726
|
+
const hasCsproj = hasDotnet && files.some((f) => f.endsWith(".csproj"));
|
|
5727
|
+
const hasFsproj = files.some((f) => f.endsWith(".fsproj"));
|
|
5385
5728
|
const hasPomXml = files.includes("pom.xml");
|
|
5386
5729
|
const hasBuildGradle = files.includes("build.gradle") || files.includes("build.gradle.kts");
|
|
5387
5730
|
const hasGemfile = files.includes("Gemfile");
|
|
@@ -5396,7 +5739,8 @@ async function analyzeRepo(repoPath) {
|
|
|
5396
5739
|
if (hasPyProject || hasRequirements) analysis.languages.push("Python");
|
|
5397
5740
|
if (hasGoMod) analysis.languages.push("Go");
|
|
5398
5741
|
if (hasCargo) analysis.languages.push("Rust");
|
|
5399
|
-
if (hasCsproj) analysis.languages.push("C#");
|
|
5742
|
+
if (hasCsproj || hasDotnet && !hasFsproj) analysis.languages.push("C#");
|
|
5743
|
+
if (hasFsproj) analysis.languages.push("F#");
|
|
5400
5744
|
if (hasPomXml || hasBuildGradle) analysis.languages.push("Java");
|
|
5401
5745
|
if (hasGemfile) analysis.languages.push("Ruby");
|
|
5402
5746
|
if (hasComposerJson) analysis.languages.push("PHP");
|
|
@@ -5412,6 +5756,10 @@ async function analyzeRepo(repoPath) {
|
|
|
5412
5756
|
});
|
|
5413
5757
|
analysis.frameworks.push(...detectFrameworks(deps, files));
|
|
5414
5758
|
}
|
|
5759
|
+
if (hasDotnet) {
|
|
5760
|
+
const dotnetFrameworks = await detectDotnetFrameworks(repoPath);
|
|
5761
|
+
analysis.frameworks.push(...dotnetFrameworks);
|
|
5762
|
+
}
|
|
5415
5763
|
const workspace = await detectWorkspace(repoPath, files, rootPackageJson);
|
|
5416
5764
|
if (workspace) {
|
|
5417
5765
|
analysis.workspaceType = workspace.type;
|
|
@@ -5472,6 +5820,44 @@ function detectFrameworks(deps, files) {
|
|
|
5472
5820
|
if (deps.includes("fastify")) frameworks.push("Fastify");
|
|
5473
5821
|
return frameworks;
|
|
5474
5822
|
}
|
|
5823
|
+
async function detectDotnetFrameworks(repoPath) {
|
|
5824
|
+
const projectFiles = await fg("**/*.{csproj,fsproj}", {
|
|
5825
|
+
cwd: repoPath,
|
|
5826
|
+
onlyFiles: true,
|
|
5827
|
+
ignore: ["**/node_modules/**", "**/bin/**", "**/obj/**"]
|
|
5828
|
+
});
|
|
5829
|
+
const frameworks = [];
|
|
5830
|
+
for (const projFile of projectFiles) {
|
|
5831
|
+
try {
|
|
5832
|
+
const content = await fs2.readFile(path2.join(repoPath, projFile), "utf8");
|
|
5833
|
+
frameworks.push(...parseDotnetProject(content));
|
|
5834
|
+
} catch {
|
|
5835
|
+
}
|
|
5836
|
+
}
|
|
5837
|
+
return frameworks;
|
|
5838
|
+
}
|
|
5839
|
+
function parseDotnetProject(content) {
|
|
5840
|
+
const frameworks = [];
|
|
5841
|
+
const hasPackage = (pkg) => content.includes(`Include="${pkg}"`);
|
|
5842
|
+
if (content.includes('Sdk="Microsoft.NET.Sdk.Web"')) frameworks.push("ASP.NET Core");
|
|
5843
|
+
if (content.includes('Sdk="Microsoft.NET.Sdk.BlazorWebAssembly"'))
|
|
5844
|
+
frameworks.push("Blazor WebAssembly");
|
|
5845
|
+
if (hasPackage("Microsoft.AspNetCore") || hasPackage("Microsoft.AspNetCore.App"))
|
|
5846
|
+
frameworks.push("ASP.NET Core");
|
|
5847
|
+
if (hasPackage("Microsoft.AspNetCore.Components")) frameworks.push("Blazor");
|
|
5848
|
+
if (hasPackage("Microsoft.EntityFrameworkCore")) frameworks.push("Entity Framework");
|
|
5849
|
+
if (hasPackage("Microsoft.Maui.Controls")) frameworks.push(".NET MAUI");
|
|
5850
|
+
if (hasPackage("Xamarin.Forms") || hasPackage("Xamarin.Essentials")) frameworks.push("Xamarin");
|
|
5851
|
+
if (content.includes("<UseWPF>true</UseWPF>")) frameworks.push("WPF");
|
|
5852
|
+
if (content.includes("<UseWindowsForms>true</UseWindowsForms>")) frameworks.push("Windows Forms");
|
|
5853
|
+
if (hasPackage("xunit") || hasPackage("xunit.core")) frameworks.push("xUnit");
|
|
5854
|
+
if (hasPackage("NUnit") || hasPackage("nunit.framework")) frameworks.push("NUnit");
|
|
5855
|
+
if (hasPackage("MSTest.TestFramework")) frameworks.push("MSTest");
|
|
5856
|
+
if (frameworks.length === 0 && content.includes("<OutputType>Exe</OutputType>") && content.includes('Sdk="Microsoft.NET.Sdk"')) {
|
|
5857
|
+
frameworks.push("Console");
|
|
5858
|
+
}
|
|
5859
|
+
return frameworks;
|
|
5860
|
+
}
|
|
5475
5861
|
async function safeReadFile(filePath) {
|
|
5476
5862
|
try {
|
|
5477
5863
|
return await fs2.readFile(filePath, "utf8");
|
|
@@ -6626,14 +7012,14 @@ async function checkReposForInstructions(token, repos, onProgress) {
|
|
|
6626
7012
|
}
|
|
6627
7013
|
|
|
6628
7014
|
// packages/core/src/services/batch.ts
|
|
6629
|
-
import
|
|
7015
|
+
import path13 from "path";
|
|
6630
7016
|
|
|
6631
7017
|
// packages/core/src/utils/pr.ts
|
|
6632
7018
|
function buildInstructionsPrBody() {
|
|
6633
7019
|
return [
|
|
6634
|
-
"## \u{1F916}
|
|
7020
|
+
"## \u{1F916} Instructions Added",
|
|
6635
7021
|
"",
|
|
6636
|
-
"This PR adds a `.github/copilot-instructions.md` file to help
|
|
7022
|
+
"This PR adds a `.github/copilot-instructions.md` file to help AI coding assistants understand this codebase better.",
|
|
6637
7023
|
"",
|
|
6638
7024
|
"### What's Included",
|
|
6639
7025
|
"",
|
|
@@ -6645,7 +7031,7 @@ function buildInstructionsPrBody() {
|
|
|
6645
7031
|
"",
|
|
6646
7032
|
"### Benefits",
|
|
6647
7033
|
"",
|
|
6648
|
-
"With these instructions,
|
|
7034
|
+
"With these instructions, AI coding assistants will:",
|
|
6649
7035
|
"- Generate more contextually-aware code suggestions",
|
|
6650
7036
|
"- Follow project-specific patterns and conventions",
|
|
6651
7037
|
"- Understand the codebase structure",
|
|
@@ -6664,7 +7050,7 @@ function buildFullPrBody() {
|
|
|
6664
7050
|
"",
|
|
6665
7051
|
"| File | Purpose |",
|
|
6666
7052
|
"|------|---------|",
|
|
6667
|
-
"| `.github/copilot-instructions.md` | Custom instructions for
|
|
7053
|
+
"| `.github/copilot-instructions.md` | Custom instructions for AI coding assistants |",
|
|
6668
7054
|
"| `.vscode/settings.json` | VS Code settings for optimal AI assistance |",
|
|
6669
7055
|
"| `.vscode/mcp.json` | Model Context Protocol server configuration |",
|
|
6670
7056
|
"",
|
|
@@ -6678,7 +7064,7 @@ function buildFullPrBody() {
|
|
|
6678
7064
|
"",
|
|
6679
7065
|
"### Benefits",
|
|
6680
7066
|
"",
|
|
6681
|
-
"With these configurations,
|
|
7067
|
+
"With these configurations, AI coding assistants will:",
|
|
6682
7068
|
"- Generate more contextually-aware code suggestions",
|
|
6683
7069
|
"- Follow project-specific patterns and conventions",
|
|
6684
7070
|
"- Understand the codebase structure",
|
|
@@ -6688,7 +7074,7 @@ function buildFullPrBody() {
|
|
|
6688
7074
|
"",
|
|
6689
7075
|
"1. Merge this PR",
|
|
6690
7076
|
"2. Open the project in VS Code",
|
|
6691
|
-
"3. Start
|
|
7077
|
+
"3. Start using AI assistants \u2014 they now understand your project!",
|
|
6692
7078
|
"",
|
|
6693
7079
|
"---",
|
|
6694
7080
|
"*Generated by [AgentRC](https://github.com/microsoft/agentrc) - Prime your repos for AI*"
|
|
@@ -6910,7 +7296,7 @@ async function checkReposForInstructions2(token, repos, onProgress) {
|
|
|
6910
7296
|
|
|
6911
7297
|
// packages/core/src/services/instructions.ts
|
|
6912
7298
|
import fs5 from "fs/promises";
|
|
6913
|
-
import
|
|
7299
|
+
import path7 from "path";
|
|
6914
7300
|
|
|
6915
7301
|
// packages/core/src/services/copilot.ts
|
|
6916
7302
|
import fs4 from "fs/promises";
|
|
@@ -6953,8 +7339,32 @@ async function assertCopilotCliReady() {
|
|
|
6953
7339
|
async function listCopilotModels() {
|
|
6954
7340
|
const config = await assertCopilotCliReady();
|
|
6955
7341
|
const [cmd, args2] = buildExecArgs(config, ["--help"]);
|
|
6956
|
-
|
|
6957
|
-
|
|
7342
|
+
let stdout = "";
|
|
7343
|
+
let stderr = "";
|
|
7344
|
+
let execError = null;
|
|
7345
|
+
try {
|
|
7346
|
+
const result = await execFileAsync2(cmd, args2, { timeout: 5e3 });
|
|
7347
|
+
stdout = result.stdout;
|
|
7348
|
+
stderr = result.stderr;
|
|
7349
|
+
} catch (err) {
|
|
7350
|
+
execError = err;
|
|
7351
|
+
const e = err;
|
|
7352
|
+
stdout = e.stdout ?? "";
|
|
7353
|
+
stderr = e.stderr ?? "";
|
|
7354
|
+
}
|
|
7355
|
+
const fromStdout = extractModelChoices(stdout);
|
|
7356
|
+
if (fromStdout.length > 0) return fromStdout;
|
|
7357
|
+
const fromStderr = extractModelChoices(stderr);
|
|
7358
|
+
if (fromStderr.length > 0) return fromStderr;
|
|
7359
|
+
if (execError) {
|
|
7360
|
+
const e = execError;
|
|
7361
|
+
const details = e.stderr || e.stdout;
|
|
7362
|
+
const detailMsg = details ? `
|
|
7363
|
+
Copilot CLI output:
|
|
7364
|
+
${details}` : "";
|
|
7365
|
+
throw new Error(`Failed to list Copilot models: ${e.message}${detailMsg}`);
|
|
7366
|
+
}
|
|
7367
|
+
return [];
|
|
6958
7368
|
}
|
|
6959
7369
|
function buildExecArgs(config, extraArgs) {
|
|
6960
7370
|
if (config.cliArgs && config.cliArgs.length > 0) {
|
|
@@ -7163,7 +7573,9 @@ function normalizeError(error) {
|
|
|
7163
7573
|
}
|
|
7164
7574
|
function shouldFallbackToExternalServer(error) {
|
|
7165
7575
|
const message = normalizeError(error).message.toLowerCase();
|
|
7166
|
-
return message.includes("unknown option '--headless'") || message.includes("unknown option '--no-auto-update'") ||
|
|
7576
|
+
return message.includes("unknown option '--headless'") || message.includes("unknown option '--no-auto-update'") || // SDK's internal CLI resolution couldn't find the binary
|
|
7577
|
+
message.includes("copilot cli not found") || // Node's spawn() can't execute .bat/.cmd directly on Windows
|
|
7578
|
+
message.includes("spawn einval");
|
|
7167
7579
|
}
|
|
7168
7580
|
async function startExternalServer(cliConfig) {
|
|
7169
7581
|
const [cmd, args2] = buildExecArgs(cliConfig, ["--headless", "--log-level", "debug"]);
|
|
@@ -7281,8 +7693,11 @@ async function createCopilotClient(cliConfig) {
|
|
|
7281
7693
|
const desc = cliConfig.cliArgs ? `${cliConfig.cliPath} ${cliConfig.cliArgs.join(" ")}` : cliConfig.cliPath;
|
|
7282
7694
|
logCopilotDebug(`creating SDK client with cliPath=${desc} useStdio=false`);
|
|
7283
7695
|
const isNpx = /\bnpx(?:\.cmd)?$/iu.test(cliConfig.cliPath);
|
|
7284
|
-
|
|
7285
|
-
|
|
7696
|
+
const isBatShim = process.platform === "win32" && /\.(?:bat|cmd)$/iu.test(cliConfig.cliPath);
|
|
7697
|
+
if (isNpx || isBatShim) {
|
|
7698
|
+
logCopilotDebug(
|
|
7699
|
+
`${isNpx ? "npx wrapper" : ".bat/.cmd shim"} detected; using external server mode directly`
|
|
7700
|
+
);
|
|
7286
7701
|
const external = await startExternalServer(cliConfig);
|
|
7287
7702
|
const client = new sdk.CopilotClient({ cliUrl: external.cliUrl });
|
|
7288
7703
|
try {
|
|
@@ -7325,6 +7740,25 @@ async function createCopilotClient(cliConfig) {
|
|
|
7325
7740
|
}
|
|
7326
7741
|
}
|
|
7327
7742
|
|
|
7743
|
+
// packages/core/src/services/skills.ts
|
|
7744
|
+
import path6 from "path";
|
|
7745
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
7746
|
+
var overrideSkillsDir;
|
|
7747
|
+
function getBuiltinSkillsDir() {
|
|
7748
|
+
if (overrideSkillsDir) {
|
|
7749
|
+
return overrideSkillsDir;
|
|
7750
|
+
}
|
|
7751
|
+
const thisFile = fileURLToPath2(import.meta.url);
|
|
7752
|
+
const thisDir = path6.dirname(thisFile);
|
|
7753
|
+
if (thisDir.includes(path6.join("packages", "core", "src"))) {
|
|
7754
|
+
return path6.resolve(thisDir, "..", "..", "..", "..", "plugin", "skills");
|
|
7755
|
+
}
|
|
7756
|
+
return path6.resolve(thisDir, "skills");
|
|
7757
|
+
}
|
|
7758
|
+
function getSkillDirectory(_skillName) {
|
|
7759
|
+
return getBuiltinSkillsDir();
|
|
7760
|
+
}
|
|
7761
|
+
|
|
7328
7762
|
// packages/core/src/services/instructions.ts
|
|
7329
7763
|
async function detectExistingInstructions(repoPath, detailDirName = ".agents") {
|
|
7330
7764
|
const { agentsMdFiles, claudeMdFiles } = await findInstructionMarkerFiles(repoPath);
|
|
@@ -7348,7 +7782,7 @@ async function findInstructionMarkerFiles(repoPath) {
|
|
|
7348
7782
|
claudeMdFiles.push(relPath ? `${relPath}/${entry.name}` : entry.name);
|
|
7349
7783
|
}
|
|
7350
7784
|
} else if (entry.isDirectory()) {
|
|
7351
|
-
await walk(
|
|
7785
|
+
await walk(path7.join(dir, entry.name), relPath ? `${relPath}/${entry.name}` : entry.name);
|
|
7352
7786
|
}
|
|
7353
7787
|
}
|
|
7354
7788
|
}
|
|
@@ -7356,7 +7790,7 @@ async function findInstructionMarkerFiles(repoPath) {
|
|
|
7356
7790
|
return { agentsMdFiles: agentsMdFiles.sort(), claudeMdFiles: claudeMdFiles.sort() };
|
|
7357
7791
|
}
|
|
7358
7792
|
async function findModularInstructionFiles(repoPath) {
|
|
7359
|
-
const dir =
|
|
7793
|
+
const dir = path7.join(repoPath, ".github", "instructions");
|
|
7360
7794
|
const entries = await fs5.readdir(dir, { withFileTypes: true }).catch(() => []);
|
|
7361
7795
|
return entries.filter((e) => !e.isSymbolicLink() && e.isFile() && e.name.endsWith(".instructions.md")).map((e) => `.github/instructions/${e.name}`).sort();
|
|
7362
7796
|
}
|
|
@@ -7370,7 +7804,7 @@ async function findDetailFiles(repoPath, detailDirName) {
|
|
|
7370
7804
|
if (entry.isSymbolicLink()) continue;
|
|
7371
7805
|
if (entry.isDirectory()) {
|
|
7372
7806
|
if (entry.name === detailDirName) {
|
|
7373
|
-
const detailDir =
|
|
7807
|
+
const detailDir = path7.join(dir, entry.name);
|
|
7374
7808
|
const detailEntries = await fs5.readdir(detailDir, { withFileTypes: true }).catch(() => []);
|
|
7375
7809
|
for (const de of detailEntries) {
|
|
7376
7810
|
if (!de.isSymbolicLink() && de.isFile() && de.name.endsWith(".md")) {
|
|
@@ -7379,7 +7813,7 @@ async function findDetailFiles(repoPath, detailDirName) {
|
|
|
7379
7813
|
}
|
|
7380
7814
|
}
|
|
7381
7815
|
} else {
|
|
7382
|
-
await walk(
|
|
7816
|
+
await walk(path7.join(dir, entry.name), relPath ? `${relPath}/${entry.name}` : entry.name);
|
|
7383
7817
|
}
|
|
7384
7818
|
}
|
|
7385
7819
|
}
|
|
@@ -7461,11 +7895,11 @@ function isCopilotAuthError(error) {
|
|
|
7461
7895
|
return error instanceof Error && error.message.includes("Copilot CLI not logged in.");
|
|
7462
7896
|
}
|
|
7463
7897
|
function resolveAreaWorkingDirectory(repoPath, area) {
|
|
7464
|
-
const repoRoot =
|
|
7898
|
+
const repoRoot = path7.resolve(repoPath);
|
|
7465
7899
|
const rawWorkingDirectory = area?.workingDirectory ?? area?.path;
|
|
7466
7900
|
if (!rawWorkingDirectory) return repoRoot;
|
|
7467
|
-
const resolved = area?.workingDirectory ?
|
|
7468
|
-
if (resolved !== repoRoot && !resolved.startsWith(repoRoot +
|
|
7901
|
+
const resolved = area?.workingDirectory ? path7.resolve(repoRoot, rawWorkingDirectory) : path7.isAbsolute(rawWorkingDirectory) ? path7.resolve(rawWorkingDirectory) : path7.resolve(repoRoot, rawWorkingDirectory);
|
|
7902
|
+
if (resolved !== repoRoot && !resolved.startsWith(repoRoot + path7.sep)) {
|
|
7469
7903
|
throw new Error(`Invalid workingDirectory "${rawWorkingDirectory}": escapes repo boundary`);
|
|
7470
7904
|
}
|
|
7471
7905
|
return resolved;
|
|
@@ -7497,6 +7931,7 @@ async function generateCopilotInstructions(options) {
|
|
|
7497
7931
|
const preferredModel = options.model ?? DEFAULT_MODEL;
|
|
7498
7932
|
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.";
|
|
7499
7933
|
const { tool: emitTool, getContent } = await createEmitTool();
|
|
7934
|
+
const rootSkillDir = getSkillDirectory("root-instructions");
|
|
7500
7935
|
const session = await client.createSession({
|
|
7501
7936
|
model: preferredModel,
|
|
7502
7937
|
streaming: true,
|
|
@@ -7507,7 +7942,8 @@ async function generateCopilotInstructions(options) {
|
|
|
7507
7942
|
tools: [emitTool],
|
|
7508
7943
|
excludedTools: INSTRUCTION_GENERATION_EXCLUDED_TOOLS,
|
|
7509
7944
|
onPermissionRequest: READ_ONLY_PERMISSION_HANDLER,
|
|
7510
|
-
infiniteSessions: { enabled: false }
|
|
7945
|
+
infiniteSessions: { enabled: false },
|
|
7946
|
+
skillDirectories: [rootSkillDir]
|
|
7511
7947
|
});
|
|
7512
7948
|
await trySetAutopilot(session);
|
|
7513
7949
|
let content = "";
|
|
@@ -7528,22 +7964,8 @@ async function generateCopilotInstructions(options) {
|
|
|
7528
7964
|
sessionError = getSessionError(errorMsg);
|
|
7529
7965
|
}
|
|
7530
7966
|
});
|
|
7531
|
-
const prompt =
|
|
7532
|
-
|
|
7533
|
-
Fan out multiple Explore subagents to map out the codebase in parallel:
|
|
7534
|
-
1. Check for existing instruction files: glob for **/{.github/copilot-instructions.md,AGENT.md,CLAUDE.md,.cursorrules,README.md}
|
|
7535
|
-
2. Identify the tech stack: look at package.json, tsconfig.json, pyproject.toml, Cargo.toml, go.mod, *.csproj, *.sln, build.gradle, pom.xml, etc.
|
|
7536
|
-
3. Understand the structure: list key directories
|
|
7537
|
-
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)
|
|
7538
|
-
|
|
7539
|
-
Generate concise instructions (~20-50 lines) covering:
|
|
7540
|
-
- Tech stack and architecture
|
|
7541
|
-
- Build/test commands
|
|
7542
|
-
- Project-specific conventions
|
|
7543
|
-
- Key files/directories
|
|
7544
|
-
- 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)
|
|
7545
|
-
${existingSection}
|
|
7546
|
-
When you have the complete markdown content, call the \`emit_file_content\` tool with it. Do NOT output the file content directly in chat.`;
|
|
7967
|
+
const prompt = `/root-instructions Analyze this codebase and generate a .github/copilot-instructions.md file.
|
|
7968
|
+
${existingSection}`;
|
|
7547
7969
|
progress("Analyzing codebase...");
|
|
7548
7970
|
let sendError;
|
|
7549
7971
|
try {
|
|
@@ -7578,8 +8000,9 @@ async function generateAreaInstructions(options) {
|
|
|
7578
8000
|
const applyToStr = applyToPatterns.join(", ");
|
|
7579
8001
|
progress(`Creating session for area "${area.name}"...`);
|
|
7580
8002
|
const preferredModel = options.model ?? DEFAULT_MODEL;
|
|
7581
|
-
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
|
|
8003
|
+
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.`;
|
|
7582
8004
|
const { tool: emitTool, getContent } = await createEmitTool();
|
|
8005
|
+
const areaSkillDir = getSkillDirectory("area-instructions");
|
|
7583
8006
|
const session = await client.createSession({
|
|
7584
8007
|
model: preferredModel,
|
|
7585
8008
|
streaming: true,
|
|
@@ -7590,7 +8013,8 @@ async function generateAreaInstructions(options) {
|
|
|
7590
8013
|
tools: [emitTool],
|
|
7591
8014
|
excludedTools: INSTRUCTION_GENERATION_EXCLUDED_TOOLS,
|
|
7592
8015
|
onPermissionRequest: READ_ONLY_PERMISSION_HANDLER,
|
|
7593
|
-
infiniteSessions: { enabled: false }
|
|
8016
|
+
infiniteSessions: { enabled: false },
|
|
8017
|
+
skillDirectories: [areaSkillDir]
|
|
7594
8018
|
});
|
|
7595
8019
|
await trySetAutopilot(session);
|
|
7596
8020
|
let content = "";
|
|
@@ -7611,30 +8035,13 @@ async function generateAreaInstructions(options) {
|
|
|
7611
8035
|
sessionError = getSessionError(errorMsg);
|
|
7612
8036
|
}
|
|
7613
8037
|
});
|
|
7614
|
-
const prompt =
|
|
8038
|
+
const prompt = `/area-instructions Analyze the "${area.name}" area of this codebase and generate an area instruction file.
|
|
7615
8039
|
|
|
7616
8040
|
This area covers files matching: ${applyToStr}
|
|
7617
8041
|
${area.description ? `Description: ${area.description}` : ""}
|
|
7618
|
-
|
|
7619
|
-
|
|
7620
|
-
|
|
7621
|
-
2. Identify the tech stack, dependencies, and frameworks used in this area
|
|
7622
|
-
3. Look at key source files to understand patterns and conventions specific to this area
|
|
7623
|
-
|
|
7624
|
-
Generate concise instructions (~10-30 lines) covering:
|
|
7625
|
-
- What this area does and its role in the overall project
|
|
7626
|
-
- Area-specific tech stack, dependencies, and frameworks
|
|
7627
|
-
- Coding conventions and patterns specific to this area
|
|
7628
|
-
- Build/test commands relevant to this area (if different from root)
|
|
7629
|
-
- Key files and directory structure within this area
|
|
7630
|
-
|
|
7631
|
-
IMPORTANT:
|
|
7632
|
-
- Focus ONLY on this specific area, not the whole repo
|
|
7633
|
-
- Do NOT repeat repo-wide information (that goes in the root copilot-instructions.md)
|
|
7634
|
-
- Keep it complementary to root instructions
|
|
7635
|
-
${existingSection ? `- Do NOT duplicate content already covered by existing instruction files
|
|
7636
|
-
${existingSection}` : ""}
|
|
7637
|
-
- When you have the complete markdown content, call the \`emit_file_content\` tool with it. Do NOT output the file content directly in chat.`;
|
|
8042
|
+
${existingSection ? `
|
|
8043
|
+
Do NOT duplicate content already covered by existing instruction files
|
|
8044
|
+
${existingSection}` : ""}`;
|
|
7638
8045
|
progress(`Analyzing area "${area.name}"...`);
|
|
7639
8046
|
let sendError;
|
|
7640
8047
|
try {
|
|
@@ -7671,7 +8078,7 @@ ${body}
|
|
|
7671
8078
|
`;
|
|
7672
8079
|
}
|
|
7673
8080
|
function areaInstructionPath(repoPath, area) {
|
|
7674
|
-
return
|
|
8081
|
+
return path7.join(
|
|
7675
8082
|
repoPath,
|
|
7676
8083
|
".github",
|
|
7677
8084
|
"instructions",
|
|
@@ -7681,7 +8088,7 @@ function areaInstructionPath(repoPath, area) {
|
|
|
7681
8088
|
async function writeAreaInstruction(repoPath, area, body, force) {
|
|
7682
8089
|
const filePath = areaInstructionPath(repoPath, area);
|
|
7683
8090
|
if (!body.trim()) return { status: "empty", filePath };
|
|
7684
|
-
await ensureDir(
|
|
8091
|
+
await ensureDir(path7.dirname(filePath));
|
|
7685
8092
|
const { wrote, reason } = await safeWriteFile(
|
|
7686
8093
|
filePath,
|
|
7687
8094
|
buildAreaInstructionContent(area, body),
|
|
@@ -7693,13 +8100,13 @@ async function writeAreaInstruction(repoPath, area, body, force) {
|
|
|
7693
8100
|
return { status: "written", filePath };
|
|
7694
8101
|
}
|
|
7695
8102
|
async function writeInstructionFile(repoPath, relativePath, content, force) {
|
|
7696
|
-
const resolvedRoot =
|
|
7697
|
-
const filePath =
|
|
7698
|
-
if (!filePath.startsWith(resolvedRoot +
|
|
8103
|
+
const resolvedRoot = path7.resolve(repoPath);
|
|
8104
|
+
const filePath = path7.resolve(repoPath, relativePath);
|
|
8105
|
+
if (!filePath.startsWith(resolvedRoot + path7.sep) && filePath !== resolvedRoot) {
|
|
7699
8106
|
throw new Error(`Invalid path: escapes repository root (${relativePath})`);
|
|
7700
8107
|
}
|
|
7701
8108
|
if (!content.trim()) return { status: "empty", filePath };
|
|
7702
|
-
await ensureDir(
|
|
8109
|
+
await ensureDir(path7.dirname(filePath));
|
|
7703
8110
|
const { wrote, reason } = await safeWriteFile(filePath, content, Boolean(force));
|
|
7704
8111
|
if (!wrote) {
|
|
7705
8112
|
return { status: reason === "symlink" ? "symlink" : "skipped", filePath };
|
|
@@ -7783,6 +8190,7 @@ async function generateNestedHub(client, options) {
|
|
|
7783
8190
|
const existingCtx = await detectExistingInstructions(options.repoPath, options.detailDir);
|
|
7784
8191
|
const existingSection = buildExistingInstructionsSection(existingCtx);
|
|
7785
8192
|
const { tool: emitTool, getContent } = await createEmitTool();
|
|
8193
|
+
const nestedSkillDir = getSkillDirectory("nested-hub");
|
|
7786
8194
|
const session = await client.createSession({
|
|
7787
8195
|
model,
|
|
7788
8196
|
streaming: true,
|
|
@@ -7793,7 +8201,8 @@ async function generateNestedHub(client, options) {
|
|
|
7793
8201
|
tools: [emitTool],
|
|
7794
8202
|
excludedTools: INSTRUCTION_GENERATION_EXCLUDED_TOOLS,
|
|
7795
8203
|
onPermissionRequest: READ_ONLY_PERMISSION_HANDLER,
|
|
7796
|
-
infiniteSessions: { enabled: false }
|
|
8204
|
+
infiniteSessions: { enabled: false },
|
|
8205
|
+
skillDirectories: [nestedSkillDir]
|
|
7797
8206
|
});
|
|
7798
8207
|
await trySetAutopilot(session);
|
|
7799
8208
|
let content = "";
|
|
@@ -7825,29 +8234,14 @@ ${options.childAreas.map((c) => `- ${c.name} (${c.path ?? "unknown path"})`).joi
|
|
|
7825
8234
|
Include a "## Sub-Projects" section with links to each child's AGENTS.md.` : "";
|
|
7826
8235
|
const parentContext = options.area?.parentArea ? `
|
|
7827
8236
|
This is a sub-project of "${options.area.parentArea}". Include a note linking back to the parent area.` : "";
|
|
7828
|
-
const prompt =
|
|
8237
|
+
const prompt = `/nested-hub Generate a lean AGENTS.md hub file (~90-120 lines).${areaContext}${parentContext}
|
|
7829
8238
|
|
|
7830
|
-
|
|
8239
|
+
Detail files go in \`${options.detailDir}/\`.${childContext}
|
|
7831
8240
|
|
|
7832
|
-
|
|
7833
|
-
|
|
7834
|
-
|
|
7835
|
-
|
|
7836
|
-
- A "## Detailed Instructions" section listing links to detail files in \`${options.detailDir}/\`${childContext}
|
|
7837
|
-
|
|
7838
|
-
At the END of your output, emit a fenced JSON block with recommended topics for detail files:
|
|
7839
|
-
\`\`\`json
|
|
7840
|
-
[{"slug":"testing","title":"Testing Guide","description":"How to write and run tests"},{"slug":"architecture","title":"Architecture","description":"Codebase structure and patterns"}]
|
|
7841
|
-
\`\`\`
|
|
7842
|
-
|
|
7843
|
-
Recommend 3-5 topics that would benefit from deep-dive detail files. Each slug becomes a filename: \`${options.detailDir}/{slug}.md\`.
|
|
7844
|
-
|
|
7845
|
-
IMPORTANT:
|
|
7846
|
-
- Keep the hub LEAN \u2014 overview and guardrails only, details go in separate files
|
|
7847
|
-
- The JSON block will be parsed and removed from the final output
|
|
7848
|
-
${existingSection ? `- Do NOT duplicate content from existing instruction files
|
|
7849
|
-
${existingSection}` : ""}
|
|
7850
|
-
- 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.`;
|
|
8241
|
+
Recommend 3-5 topics for deep-dive detail files. Each slug becomes: \`${options.detailDir}/{slug}.md\`.
|
|
8242
|
+
${existingSection ? `
|
|
8243
|
+
Do NOT duplicate content from existing instruction files
|
|
8244
|
+
${existingSection}` : ""}`;
|
|
7851
8245
|
let sendError;
|
|
7852
8246
|
try {
|
|
7853
8247
|
await session.sendAndWait({ prompt }, 18e4);
|
|
@@ -7871,6 +8265,7 @@ async function generateNestedDetail(client, options) {
|
|
|
7871
8265
|
});
|
|
7872
8266
|
const model = options.model ?? DEFAULT_MODEL;
|
|
7873
8267
|
const { tool: emitTool, getContent } = await createEmitTool();
|
|
8268
|
+
const detailSkillDir = getSkillDirectory("nested-detail");
|
|
7874
8269
|
const session = await client.createSession({
|
|
7875
8270
|
model,
|
|
7876
8271
|
streaming: true,
|
|
@@ -7881,7 +8276,8 @@ async function generateNestedDetail(client, options) {
|
|
|
7881
8276
|
tools: [emitTool],
|
|
7882
8277
|
excludedTools: INSTRUCTION_GENERATION_EXCLUDED_TOOLS,
|
|
7883
8278
|
onPermissionRequest: READ_ONLY_PERMISSION_HANDLER,
|
|
7884
|
-
infiniteSessions: { enabled: false }
|
|
8279
|
+
infiniteSessions: { enabled: false },
|
|
8280
|
+
skillDirectories: [detailSkillDir]
|
|
7885
8281
|
});
|
|
7886
8282
|
await trySetAutopilot(session);
|
|
7887
8283
|
let content = "";
|
|
@@ -7903,22 +8299,11 @@ async function generateNestedDetail(client, options) {
|
|
|
7903
8299
|
}
|
|
7904
8300
|
});
|
|
7905
8301
|
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.";
|
|
7906
|
-
const prompt =
|
|
8302
|
+
const prompt = `/nested-detail Generate a deep-dive instruction file about "${options.topic.title}" for this codebase.
|
|
7907
8303
|
${areaContext}
|
|
7908
8304
|
|
|
7909
8305
|
Topic: ${options.topic.title}
|
|
7910
|
-
Description: ${options.topic.description}
|
|
7911
|
-
|
|
7912
|
-
Use tools to explore the codebase and understand the specific patterns, APIs, and conventions related to this topic.
|
|
7913
|
-
|
|
7914
|
-
The file should:
|
|
7915
|
-
- Start with \`# ${options.topic.title}\`
|
|
7916
|
-
- Include \`**When to read:** {one-line trigger condition}\` right after the heading
|
|
7917
|
-
- Cover ~50-100 lines of practical, actionable guidance
|
|
7918
|
-
- Include code patterns and examples found in the actual codebase
|
|
7919
|
-
- Be specific to this codebase, not generic advice
|
|
7920
|
-
|
|
7921
|
-
When you have the complete markdown content, call the \`emit_file_content\` tool with it. Do NOT output the content directly in chat.`;
|
|
8306
|
+
Description: ${options.topic.description}`;
|
|
7922
8307
|
let sendError;
|
|
7923
8308
|
try {
|
|
7924
8309
|
await session.sendAndWait({ prompt }, 18e4);
|
|
@@ -7953,7 +8338,7 @@ async function generateNestedInstructions(options) {
|
|
|
7953
8338
|
onProgress: options.onProgress
|
|
7954
8339
|
});
|
|
7955
8340
|
const basePath = options.area?.path ?? ".";
|
|
7956
|
-
const hubRelativePath =
|
|
8341
|
+
const hubRelativePath = path7.join(basePath, "AGENTS.md");
|
|
7957
8342
|
let finalHubContent = hubContent;
|
|
7958
8343
|
if (options.area) {
|
|
7959
8344
|
finalHubContent = `${buildAreaFrontmatter(options.area)}
|
|
@@ -7977,7 +8362,7 @@ ${hubContent}`;
|
|
|
7977
8362
|
});
|
|
7978
8363
|
if (detailContent) {
|
|
7979
8364
|
result.details.push({
|
|
7980
|
-
relativePath:
|
|
8365
|
+
relativePath: path7.join(basePath, options.detailDir, `${topic.slug}.md`),
|
|
7981
8366
|
content: detailContent,
|
|
7982
8367
|
topic: topic.title
|
|
7983
8368
|
});
|
|
@@ -7992,7 +8377,7 @@ ${hubContent}`;
|
|
|
7992
8377
|
}
|
|
7993
8378
|
if (options.claudeMd) {
|
|
7994
8379
|
result.claudeMd = {
|
|
7995
|
-
relativePath:
|
|
8380
|
+
relativePath: path7.join(basePath, "CLAUDE.md"),
|
|
7996
8381
|
content: "@AGENTS.md\n"
|
|
7997
8382
|
};
|
|
7998
8383
|
}
|
|
@@ -8013,13 +8398,12 @@ async function generateNestedAreaInstructions(options) {
|
|
|
8013
8398
|
});
|
|
8014
8399
|
}
|
|
8015
8400
|
|
|
8016
|
-
// packages/core/src/services/readiness.ts
|
|
8017
|
-
import
|
|
8018
|
-
import path8 from "path";
|
|
8401
|
+
// packages/core/src/services/readiness/index.ts
|
|
8402
|
+
import path12 from "path";
|
|
8019
8403
|
|
|
8020
8404
|
// packages/core/src/services/policy.ts
|
|
8021
8405
|
import fs6 from "fs/promises";
|
|
8022
|
-
import
|
|
8406
|
+
import path8 from "path";
|
|
8023
8407
|
var DEFAULT_PASS_RATE = 0.8;
|
|
8024
8408
|
function validatePolicyConfig(obj, source, format = "module") {
|
|
8025
8409
|
if (typeof obj !== "object" || obj === null) {
|
|
@@ -8112,8 +8496,8 @@ function parsePolicySources(raw) {
|
|
|
8112
8496
|
}
|
|
8113
8497
|
async function loadPolicy(source, options) {
|
|
8114
8498
|
const jsonOnly = options?.jsonOnly ?? false;
|
|
8115
|
-
if (source.startsWith(".") ||
|
|
8116
|
-
const resolved =
|
|
8499
|
+
if (source.startsWith(".") || path8.isAbsolute(source)) {
|
|
8500
|
+
const resolved = path8.resolve(source);
|
|
8117
8501
|
if (resolved.endsWith(".json")) {
|
|
8118
8502
|
const data = await readJson(resolved);
|
|
8119
8503
|
if (!data) {
|
|
@@ -8140,7 +8524,7 @@ async function loadPolicy(source, options) {
|
|
|
8140
8524
|
}
|
|
8141
8525
|
try {
|
|
8142
8526
|
const raw = await fs6.readFile(resolved, "utf8");
|
|
8143
|
-
const data = JSON.parse(raw);
|
|
8527
|
+
const data = JSON.parse(stripJsonComments(raw));
|
|
8144
8528
|
return validatePolicyConfig(data, source, "json");
|
|
8145
8529
|
} catch {
|
|
8146
8530
|
throw new Error(
|
|
@@ -8696,252 +9080,382 @@ function wrapImperativePolicy(config, baseCriteria) {
|
|
|
8696
9080
|
return { plugin, compiled };
|
|
8697
9081
|
}
|
|
8698
9082
|
|
|
8699
|
-
// packages/core/src/services/readiness.ts
|
|
8700
|
-
|
|
8701
|
-
|
|
8702
|
-
|
|
8703
|
-
|
|
8704
|
-
documentation: "repo-health",
|
|
8705
|
-
"dev-environment": "repo-health",
|
|
8706
|
-
"code-quality": "repo-health",
|
|
8707
|
-
observability: "repo-health",
|
|
8708
|
-
"security-governance": "repo-health",
|
|
8709
|
-
"ai-tooling": "ai-setup"
|
|
8710
|
-
};
|
|
8711
|
-
var PILLAR_GROUP_NAMES = {
|
|
8712
|
-
"repo-health": "Repo Health",
|
|
8713
|
-
"ai-setup": "AI Setup"
|
|
8714
|
-
};
|
|
8715
|
-
function groupPillars(pillars) {
|
|
8716
|
-
const groups = ["repo-health", "ai-setup"];
|
|
8717
|
-
return groups.map((group) => ({
|
|
8718
|
-
group,
|
|
8719
|
-
label: PILLAR_GROUP_NAMES[group],
|
|
8720
|
-
pillars: pillars.filter((p) => PILLAR_GROUPS[p.id] === group)
|
|
8721
|
-
}));
|
|
9083
|
+
// packages/core/src/services/readiness/checkers.ts
|
|
9084
|
+
import fs7 from "fs/promises";
|
|
9085
|
+
import path9 from "path";
|
|
9086
|
+
function hasAnyFile(files, candidates) {
|
|
9087
|
+
return candidates.some((candidate) => files.includes(candidate));
|
|
8722
9088
|
}
|
|
8723
|
-
function
|
|
8724
|
-
const
|
|
8725
|
-
|
|
8726
|
-
|
|
8727
|
-
|
|
8728
|
-
4: "Optimized",
|
|
8729
|
-
5: "Autonomous"
|
|
8730
|
-
};
|
|
8731
|
-
return names[level] || "Unknown";
|
|
9089
|
+
async function hasReadme(repoPath) {
|
|
9090
|
+
const files = await safeReadDir(repoPath);
|
|
9091
|
+
return files.some(
|
|
9092
|
+
(file) => file.toLowerCase() === "readme.md" || file.toLowerCase() === "readme"
|
|
9093
|
+
);
|
|
8732
9094
|
}
|
|
8733
|
-
function
|
|
8734
|
-
|
|
8735
|
-
|
|
8736
|
-
|
|
8737
|
-
|
|
8738
|
-
|
|
8739
|
-
|
|
8740
|
-
|
|
8741
|
-
|
|
9095
|
+
async function hasLintConfig(repoPath) {
|
|
9096
|
+
return hasAnyFile(await safeReadDir(repoPath), [
|
|
9097
|
+
"eslint.config.js",
|
|
9098
|
+
"eslint.config.mjs",
|
|
9099
|
+
".eslintrc",
|
|
9100
|
+
".eslintrc.js",
|
|
9101
|
+
".eslintrc.cjs",
|
|
9102
|
+
".eslintrc.json",
|
|
9103
|
+
".eslintrc.yml",
|
|
9104
|
+
".eslintrc.yaml",
|
|
9105
|
+
"biome.json",
|
|
9106
|
+
"biome.jsonc",
|
|
9107
|
+
".prettierrc",
|
|
9108
|
+
".prettierrc.json",
|
|
9109
|
+
".prettierrc.js",
|
|
9110
|
+
".prettierrc.cjs",
|
|
9111
|
+
"prettier.config.js",
|
|
9112
|
+
"prettier.config.cjs"
|
|
9113
|
+
]);
|
|
8742
9114
|
}
|
|
8743
|
-
async function
|
|
8744
|
-
|
|
8745
|
-
|
|
8746
|
-
|
|
8747
|
-
|
|
8748
|
-
|
|
8749
|
-
|
|
8750
|
-
|
|
8751
|
-
|
|
8752
|
-
|
|
8753
|
-
|
|
8754
|
-
|
|
9115
|
+
async function hasFormatterConfig(repoPath) {
|
|
9116
|
+
return hasAnyFile(await safeReadDir(repoPath), [
|
|
9117
|
+
"biome.json",
|
|
9118
|
+
"biome.jsonc",
|
|
9119
|
+
".prettierrc",
|
|
9120
|
+
".prettierrc.json",
|
|
9121
|
+
".prettierrc.js",
|
|
9122
|
+
".prettierrc.cjs",
|
|
9123
|
+
"prettier.config.js",
|
|
9124
|
+
"prettier.config.cjs"
|
|
9125
|
+
]);
|
|
9126
|
+
}
|
|
9127
|
+
async function hasTypecheckConfig(repoPath) {
|
|
9128
|
+
return hasAnyFile(await safeReadDir(repoPath), [
|
|
9129
|
+
"tsconfig.json",
|
|
9130
|
+
"tsconfig.base.json",
|
|
9131
|
+
"pyproject.toml",
|
|
9132
|
+
"mypy.ini"
|
|
9133
|
+
]);
|
|
9134
|
+
}
|
|
9135
|
+
async function hasGithubWorkflows(repoPath) {
|
|
9136
|
+
return fileExists(path9.join(repoPath, ".github", "workflows"));
|
|
9137
|
+
}
|
|
9138
|
+
async function hasCodeowners(repoPath) {
|
|
9139
|
+
const root = await fileExists(path9.join(repoPath, "CODEOWNERS"));
|
|
9140
|
+
const github = await fileExists(path9.join(repoPath, ".github", "CODEOWNERS"));
|
|
9141
|
+
return root || github;
|
|
9142
|
+
}
|
|
9143
|
+
async function hasLicense(repoPath) {
|
|
9144
|
+
const files = await safeReadDir(repoPath);
|
|
9145
|
+
return files.some((file) => file.toLowerCase().startsWith("license"));
|
|
9146
|
+
}
|
|
9147
|
+
async function hasPullRequestTemplate(repoPath) {
|
|
9148
|
+
const direct = await fileExists(path9.join(repoPath, ".github", "PULL_REQUEST_TEMPLATE.md"));
|
|
9149
|
+
if (direct) return true;
|
|
9150
|
+
const dir = path9.join(repoPath, ".github", "PULL_REQUEST_TEMPLATE");
|
|
9151
|
+
try {
|
|
9152
|
+
const entries = await fs7.readdir(dir);
|
|
9153
|
+
return entries.some((entry) => entry.toLowerCase().endsWith(".md"));
|
|
9154
|
+
} catch {
|
|
9155
|
+
return false;
|
|
9156
|
+
}
|
|
9157
|
+
}
|
|
9158
|
+
async function hasPrecommitConfig(repoPath) {
|
|
9159
|
+
const precommit = await fileExists(path9.join(repoPath, ".pre-commit-config.yaml"));
|
|
9160
|
+
if (precommit) return true;
|
|
9161
|
+
return fileExists(path9.join(repoPath, ".husky"));
|
|
9162
|
+
}
|
|
9163
|
+
async function hasArchitectureDoc(repoPath) {
|
|
9164
|
+
const files = await safeReadDir(repoPath);
|
|
9165
|
+
if (files.some((file) => file.toLowerCase() === "architecture.md")) return true;
|
|
9166
|
+
return fileExists(path9.join(repoPath, "docs", "architecture.md"));
|
|
9167
|
+
}
|
|
9168
|
+
function validateAndNormalize(raw) {
|
|
9169
|
+
const trimmed = raw.trim();
|
|
9170
|
+
if (!trimmed || path9.isAbsolute(trimmed)) return void 0;
|
|
9171
|
+
const segments = trimmed.split(/[/\\]+/u);
|
|
9172
|
+
if (segments.some((s) => s === "..")) return void 0;
|
|
9173
|
+
let normalized = path9.normalize(trimmed).replace(/\\/gu, "/");
|
|
9174
|
+
normalized = normalized.replace(/\/+$/u, "");
|
|
9175
|
+
if (!normalized || normalized === ".") return void 0;
|
|
9176
|
+
return normalized;
|
|
9177
|
+
}
|
|
9178
|
+
function extractLocationPaths(entries) {
|
|
9179
|
+
if (!entries || typeof entries !== "object") return [];
|
|
9180
|
+
const paths = [];
|
|
9181
|
+
if (Array.isArray(entries)) {
|
|
9182
|
+
for (const entry of entries) {
|
|
9183
|
+
let raw;
|
|
9184
|
+
if (typeof entry === "string") {
|
|
9185
|
+
raw = entry;
|
|
9186
|
+
} else if (entry && typeof entry === "object" && !Array.isArray(entry)) {
|
|
9187
|
+
const obj = entry;
|
|
9188
|
+
if (typeof obj.path === "string") {
|
|
9189
|
+
raw = obj.path;
|
|
9190
|
+
}
|
|
9191
|
+
}
|
|
9192
|
+
if (raw) {
|
|
9193
|
+
const normalized = validateAndNormalize(raw);
|
|
9194
|
+
if (normalized) paths.push(normalized);
|
|
9195
|
+
}
|
|
9196
|
+
}
|
|
9197
|
+
return paths;
|
|
9198
|
+
}
|
|
9199
|
+
for (const [key, value] of Object.entries(entries)) {
|
|
9200
|
+
if (value !== true) continue;
|
|
9201
|
+
const normalized = validateAndNormalize(key);
|
|
9202
|
+
if (normalized) paths.push(normalized);
|
|
9203
|
+
}
|
|
9204
|
+
return paths;
|
|
9205
|
+
}
|
|
9206
|
+
function extractLocationsFromSettings(settings) {
|
|
9207
|
+
return {
|
|
9208
|
+
instructionsLocations: extractLocationPaths(settings["chat.instructionsFilesLocations"]),
|
|
9209
|
+
agentLocations: extractLocationPaths(settings["chat.agentFilesLocations"]),
|
|
9210
|
+
skillsLocations: extractLocationPaths(settings["chat.agentSkillsLocations"])
|
|
8755
9211
|
};
|
|
8756
|
-
|
|
8757
|
-
|
|
8758
|
-
|
|
8759
|
-
|
|
8760
|
-
|
|
8761
|
-
|
|
8762
|
-
|
|
9212
|
+
}
|
|
9213
|
+
function mergeLocations(a, b) {
|
|
9214
|
+
return {
|
|
9215
|
+
instructionsLocations: [...a.instructionsLocations, ...b.instructionsLocations],
|
|
9216
|
+
agentLocations: [...a.agentLocations, ...b.agentLocations],
|
|
9217
|
+
skillsLocations: [...a.skillsLocations, ...b.skillsLocations]
|
|
9218
|
+
};
|
|
9219
|
+
}
|
|
9220
|
+
async function parseVscodeLocations(repoPath, rootFiles) {
|
|
9221
|
+
const empty = {
|
|
9222
|
+
instructionsLocations: [],
|
|
9223
|
+
agentLocations: [],
|
|
9224
|
+
skillsLocations: []
|
|
9225
|
+
};
|
|
9226
|
+
let result = { ...empty };
|
|
9227
|
+
const settings = await readJson(path9.join(repoPath, ".vscode", "settings.json"));
|
|
9228
|
+
if (settings) {
|
|
9229
|
+
result = mergeLocations(result, extractLocationsFromSettings(settings));
|
|
9230
|
+
}
|
|
9231
|
+
const workspaceFiles = rootFiles.filter((f) => f.endsWith(".code-workspace"));
|
|
9232
|
+
for (const wsFile of workspaceFiles) {
|
|
9233
|
+
const ws = await readJson(path9.join(repoPath, wsFile));
|
|
9234
|
+
if (ws?.settings && typeof ws.settings === "object" && !Array.isArray(ws.settings)) {
|
|
9235
|
+
result = mergeLocations(
|
|
9236
|
+
result,
|
|
9237
|
+
extractLocationsFromSettings(ws.settings)
|
|
9238
|
+
);
|
|
8763
9239
|
}
|
|
8764
9240
|
}
|
|
8765
|
-
|
|
8766
|
-
|
|
8767
|
-
|
|
8768
|
-
|
|
8769
|
-
|
|
8770
|
-
|
|
8771
|
-
|
|
8772
|
-
|
|
8773
|
-
|
|
8774
|
-
|
|
9241
|
+
return {
|
|
9242
|
+
instructionsLocations: [...new Set(result.instructionsLocations)],
|
|
9243
|
+
agentLocations: [...new Set(result.agentLocations)],
|
|
9244
|
+
skillsLocations: [...new Set(result.skillsLocations)]
|
|
9245
|
+
};
|
|
9246
|
+
}
|
|
9247
|
+
async function hasCustomInstructions(repoPath) {
|
|
9248
|
+
const found = [];
|
|
9249
|
+
const candidates = [
|
|
9250
|
+
".github/copilot-instructions.md",
|
|
9251
|
+
"CLAUDE.md",
|
|
9252
|
+
".claude/CLAUDE.md",
|
|
9253
|
+
"AGENTS.md",
|
|
9254
|
+
".github/AGENTS.md",
|
|
9255
|
+
".cursorrules",
|
|
9256
|
+
".cursorignore",
|
|
9257
|
+
".windsurfrules",
|
|
9258
|
+
".github/instructions.md",
|
|
9259
|
+
"copilot-instructions.md"
|
|
9260
|
+
];
|
|
9261
|
+
for (const candidate of candidates) {
|
|
9262
|
+
if (await fileExists(path9.join(repoPath, candidate))) {
|
|
9263
|
+
found.push(candidate);
|
|
8775
9264
|
}
|
|
8776
|
-
const resolved = resolveChain(baseCriteria, baseExtras, policyConfigs);
|
|
8777
|
-
resolvedCriteria = resolved.criteria;
|
|
8778
|
-
resolvedExtras = resolved.extras;
|
|
8779
|
-
passRateThreshold = resolved.thresholds.passRate;
|
|
8780
|
-
policyInfo = { chain: resolved.chain, criteriaCount: resolved.criteria.length };
|
|
8781
|
-
} else {
|
|
8782
|
-
resolvedCriteria = baseCriteria;
|
|
8783
|
-
resolvedExtras = baseExtras;
|
|
8784
9265
|
}
|
|
8785
|
-
|
|
8786
|
-
|
|
8787
|
-
|
|
8788
|
-
|
|
8789
|
-
|
|
8790
|
-
|
|
8791
|
-
|
|
8792
|
-
|
|
8793
|
-
|
|
8794
|
-
|
|
8795
|
-
|
|
8796
|
-
|
|
8797
|
-
|
|
8798
|
-
|
|
8799
|
-
|
|
8800
|
-
|
|
8801
|
-
|
|
9266
|
+
return found;
|
|
9267
|
+
}
|
|
9268
|
+
async function hasFileBasedInstructions(repoPath, extraDirs) {
|
|
9269
|
+
const found = [];
|
|
9270
|
+
const defaultDir = path9.join(repoPath, ".github", "instructions");
|
|
9271
|
+
try {
|
|
9272
|
+
const entries = await fs7.readdir(defaultDir);
|
|
9273
|
+
found.push(
|
|
9274
|
+
...entries.filter((e) => e.endsWith(".instructions.md")).map((e) => `.github/instructions/${e}`)
|
|
9275
|
+
);
|
|
9276
|
+
} catch {
|
|
9277
|
+
}
|
|
9278
|
+
for (const dir of extraDirs ?? []) {
|
|
9279
|
+
const fullDir = path9.join(repoPath, dir);
|
|
9280
|
+
const normalizedDir = dir.replace(/\\/gu, "/").replace(/\/+$/u, "");
|
|
9281
|
+
try {
|
|
9282
|
+
const entries = await fs7.readdir(fullDir);
|
|
9283
|
+
found.push(
|
|
9284
|
+
...entries.filter((e) => e.endsWith(".instructions.md")).map((e) => `${normalizedDir}/${e}`)
|
|
9285
|
+
);
|
|
9286
|
+
} catch {
|
|
8802
9287
|
}
|
|
8803
|
-
|
|
8804
|
-
|
|
8805
|
-
|
|
8806
|
-
|
|
8807
|
-
|
|
8808
|
-
|
|
8809
|
-
|
|
8810
|
-
|
|
8811
|
-
|
|
8812
|
-
|
|
8813
|
-
|
|
8814
|
-
|
|
8815
|
-
|
|
8816
|
-
|
|
8817
|
-
|
|
8818
|
-
|
|
9288
|
+
}
|
|
9289
|
+
return [...new Set(found)];
|
|
9290
|
+
}
|
|
9291
|
+
function contentSimilarity(a, b) {
|
|
9292
|
+
const normalize = (s) => new Set(
|
|
9293
|
+
s.toLowerCase().split("\n").map((l) => l.trim().replace(/\s+/gu, " ")).filter((l) => l.length > 0)
|
|
9294
|
+
);
|
|
9295
|
+
const setA = normalize(a);
|
|
9296
|
+
const setB = normalize(b);
|
|
9297
|
+
if (setA.size === 0 && setB.size === 0) return 1;
|
|
9298
|
+
let intersection = 0;
|
|
9299
|
+
for (const line of setA) {
|
|
9300
|
+
if (setB.has(line)) intersection++;
|
|
9301
|
+
}
|
|
9302
|
+
const union = (/* @__PURE__ */ new Set([...setA, ...setB])).size;
|
|
9303
|
+
return union === 0 ? 1 : intersection / union;
|
|
9304
|
+
}
|
|
9305
|
+
async function checkInstructionConsistency(repoPath, foundFiles) {
|
|
9306
|
+
if (foundFiles.length <= 1) {
|
|
9307
|
+
return { unified: true, files: foundFiles };
|
|
9308
|
+
}
|
|
9309
|
+
const realPathMap = /* @__PURE__ */ new Map();
|
|
9310
|
+
for (const file of foundFiles) {
|
|
9311
|
+
const fullPath = path9.join(repoPath, file);
|
|
9312
|
+
try {
|
|
9313
|
+
const real = await fs7.realpath(fullPath);
|
|
9314
|
+
const group = realPathMap.get(real) ?? [];
|
|
9315
|
+
group.push(file);
|
|
9316
|
+
realPathMap.set(real, group);
|
|
9317
|
+
} catch {
|
|
9318
|
+
realPathMap.set(fullPath, [file]);
|
|
8819
9319
|
}
|
|
8820
|
-
|
|
8821
|
-
|
|
8822
|
-
|
|
8823
|
-
|
|
8824
|
-
|
|
8825
|
-
|
|
8826
|
-
|
|
8827
|
-
|
|
8828
|
-
|
|
8829
|
-
|
|
8830
|
-
|
|
8831
|
-
level: criterion.level,
|
|
8832
|
-
scope: criterion.scope,
|
|
8833
|
-
impact: criterion.impact,
|
|
8834
|
-
effort: criterion.effort,
|
|
8835
|
-
status: "skip",
|
|
8836
|
-
reason: "No application packages detected."
|
|
8837
|
-
});
|
|
8838
|
-
continue;
|
|
9320
|
+
}
|
|
9321
|
+
const groups = [...realPathMap.values()];
|
|
9322
|
+
if (groups.length <= 1) {
|
|
9323
|
+
return { unified: true, files: foundFiles };
|
|
9324
|
+
}
|
|
9325
|
+
const contents = [];
|
|
9326
|
+
for (const group of groups) {
|
|
9327
|
+
try {
|
|
9328
|
+
contents.push(await fs7.readFile(path9.join(repoPath, group[0]), "utf8"));
|
|
9329
|
+
} catch {
|
|
9330
|
+
contents.push("");
|
|
8839
9331
|
}
|
|
8840
|
-
const passed = appResults.filter((entry) => entry.result.status === "pass").length;
|
|
8841
|
-
const total = appResults.length;
|
|
8842
|
-
const passRate = total ? passed / total : 0;
|
|
8843
|
-
const status = passRate >= passRateThreshold ? "pass" : "fail";
|
|
8844
|
-
const failures = appResults.filter((entry) => entry.result.status !== "pass").map((entry) => entry.app.name);
|
|
8845
|
-
criteriaResults.push({
|
|
8846
|
-
id: criterion.id,
|
|
8847
|
-
title: criterion.title,
|
|
8848
|
-
pillar: criterion.pillar,
|
|
8849
|
-
level: criterion.level,
|
|
8850
|
-
scope: criterion.scope,
|
|
8851
|
-
impact: criterion.impact,
|
|
8852
|
-
effort: criterion.effort,
|
|
8853
|
-
status,
|
|
8854
|
-
reason: status === "pass" ? void 0 : `Only ${passed}/${total} apps pass this check.`,
|
|
8855
|
-
passRate,
|
|
8856
|
-
appSummary: { passed, total },
|
|
8857
|
-
appFailures: failures
|
|
8858
|
-
});
|
|
8859
9332
|
}
|
|
8860
|
-
let
|
|
8861
|
-
|
|
8862
|
-
|
|
8863
|
-
|
|
8864
|
-
areaReports = [];
|
|
8865
|
-
for (const area of areas) {
|
|
8866
|
-
if (!area.path) continue;
|
|
8867
|
-
const areaFiles = await safeReadDir(area.path);
|
|
8868
|
-
const areaContext = {
|
|
8869
|
-
...context,
|
|
8870
|
-
areaPath: area.path,
|
|
8871
|
-
areaFiles
|
|
8872
|
-
};
|
|
8873
|
-
const areaResults = [];
|
|
8874
|
-
for (const criterion of areaCriteria) {
|
|
8875
|
-
const result = await criterion.check(areaContext, void 0, area);
|
|
8876
|
-
areaResults.push({
|
|
8877
|
-
id: criterion.id,
|
|
8878
|
-
title: criterion.title,
|
|
8879
|
-
pillar: criterion.pillar,
|
|
8880
|
-
level: criterion.level,
|
|
8881
|
-
scope: criterion.scope,
|
|
8882
|
-
impact: criterion.impact,
|
|
8883
|
-
effort: criterion.effort,
|
|
8884
|
-
status: result.status,
|
|
8885
|
-
reason: result.reason,
|
|
8886
|
-
evidence: result.evidence
|
|
8887
|
-
});
|
|
8888
|
-
}
|
|
8889
|
-
const areaPillars = summarizePillars(areaResults);
|
|
8890
|
-
areaReports.push({ area, criteria: areaResults, pillars: areaPillars });
|
|
9333
|
+
let minSimilarity = 1;
|
|
9334
|
+
for (let i = 0; i < contents.length; i++) {
|
|
9335
|
+
for (let j = i + 1; j < contents.length; j++) {
|
|
9336
|
+
minSimilarity = Math.min(minSimilarity, contentSimilarity(contents[i], contents[j]));
|
|
8891
9337
|
}
|
|
8892
|
-
|
|
8893
|
-
|
|
8894
|
-
|
|
8895
|
-
|
|
8896
|
-
|
|
8897
|
-
|
|
8898
|
-
|
|
8899
|
-
|
|
8900
|
-
|
|
8901
|
-
|
|
8902
|
-
|
|
8903
|
-
|
|
9338
|
+
}
|
|
9339
|
+
return {
|
|
9340
|
+
unified: minSimilarity >= 0.9,
|
|
9341
|
+
files: foundFiles,
|
|
9342
|
+
similarity: Math.round(minSimilarity * 100) / 100
|
|
9343
|
+
};
|
|
9344
|
+
}
|
|
9345
|
+
async function hasMcpConfig(repoPath) {
|
|
9346
|
+
const found = [];
|
|
9347
|
+
if (await fileExists(path9.join(repoPath, ".vscode", "mcp.json"))) {
|
|
9348
|
+
found.push(".vscode/mcp.json");
|
|
9349
|
+
}
|
|
9350
|
+
if (await fileExists(path9.join(repoPath, "mcp.json"))) {
|
|
9351
|
+
found.push("mcp.json");
|
|
9352
|
+
}
|
|
9353
|
+
const settings = await readJson(path9.join(repoPath, ".vscode", "settings.json"));
|
|
9354
|
+
if (settings && (settings["mcp"] || settings["github.copilot.chat.mcp.enabled"])) {
|
|
9355
|
+
found.push(".vscode/settings.json (mcp section)");
|
|
9356
|
+
}
|
|
9357
|
+
if (await fileExists(path9.join(repoPath, ".claude", "mcp.json"))) {
|
|
9358
|
+
found.push(".claude/mcp.json");
|
|
9359
|
+
}
|
|
9360
|
+
return found;
|
|
9361
|
+
}
|
|
9362
|
+
async function hasCustomAgents(repoPath, extraDirs) {
|
|
9363
|
+
const found = [];
|
|
9364
|
+
const agentDirs = [".github/agents", ".copilot/agents", ".github/copilot/agents"];
|
|
9365
|
+
for (const dir of agentDirs) {
|
|
9366
|
+
if (await fileExists(path9.join(repoPath, dir))) {
|
|
9367
|
+
found.push(dir);
|
|
9368
|
+
}
|
|
9369
|
+
}
|
|
9370
|
+
const agentFiles = [".github/copilot-agents.yml", ".github/copilot-agents.yaml"];
|
|
9371
|
+
for (const agentFile of agentFiles) {
|
|
9372
|
+
if (await fileExists(path9.join(repoPath, agentFile))) {
|
|
9373
|
+
found.push(agentFile);
|
|
9374
|
+
}
|
|
9375
|
+
}
|
|
9376
|
+
for (const dir of extraDirs ?? []) {
|
|
9377
|
+
if (await fileExists(path9.join(repoPath, dir))) {
|
|
9378
|
+
found.push(dir);
|
|
8904
9379
|
}
|
|
8905
9380
|
}
|
|
8906
|
-
|
|
8907
|
-
|
|
8908
|
-
|
|
8909
|
-
const
|
|
8910
|
-
|
|
8911
|
-
|
|
8912
|
-
|
|
8913
|
-
|
|
8914
|
-
|
|
8915
|
-
|
|
8916
|
-
|
|
8917
|
-
|
|
8918
|
-
|
|
8919
|
-
}
|
|
8920
|
-
|
|
8921
|
-
|
|
8922
|
-
|
|
8923
|
-
|
|
8924
|
-
|
|
8925
|
-
|
|
8926
|
-
|
|
8927
|
-
|
|
8928
|
-
|
|
9381
|
+
return [...new Set(found)];
|
|
9382
|
+
}
|
|
9383
|
+
async function hasCopilotSkills(repoPath, extraDirs) {
|
|
9384
|
+
const found = [];
|
|
9385
|
+
const skillDirs = [
|
|
9386
|
+
".copilot/skills",
|
|
9387
|
+
".github/skills",
|
|
9388
|
+
".claude/skills",
|
|
9389
|
+
".github/copilot/skills"
|
|
9390
|
+
];
|
|
9391
|
+
for (const dir of skillDirs) {
|
|
9392
|
+
if (await fileExists(path9.join(repoPath, dir))) {
|
|
9393
|
+
found.push(dir);
|
|
9394
|
+
}
|
|
9395
|
+
}
|
|
9396
|
+
for (const dir of extraDirs ?? []) {
|
|
9397
|
+
if (await fileExists(path9.join(repoPath, dir))) {
|
|
9398
|
+
found.push(dir);
|
|
9399
|
+
}
|
|
9400
|
+
}
|
|
9401
|
+
return [...new Set(found)];
|
|
9402
|
+
}
|
|
9403
|
+
async function hasApmConfig(repoPath) {
|
|
9404
|
+
return fileExists(path9.join(repoPath, "apm.yml"));
|
|
9405
|
+
}
|
|
9406
|
+
async function hasApmLockfile(repoPath) {
|
|
9407
|
+
return fileExists(path9.join(repoPath, "apm.lock.yaml"));
|
|
9408
|
+
}
|
|
9409
|
+
async function hasApmInWorkflows(repoPath) {
|
|
9410
|
+
const workflowDir = path9.join(repoPath, ".github", "workflows");
|
|
9411
|
+
let files;
|
|
9412
|
+
try {
|
|
9413
|
+
files = await fs7.readdir(workflowDir);
|
|
9414
|
+
} catch {
|
|
9415
|
+
return false;
|
|
9416
|
+
}
|
|
9417
|
+
for (const file of files) {
|
|
9418
|
+
if (!file.endsWith(".yml") && !file.endsWith(".yaml")) continue;
|
|
9419
|
+
try {
|
|
9420
|
+
const content = await fs7.readFile(path9.join(workflowDir, file), "utf8");
|
|
9421
|
+
if (/\bmicrosoft\/apm-action\b/.test(content) || /\bapm\s+(audit|install)\b/.test(content)) {
|
|
9422
|
+
return true;
|
|
9423
|
+
}
|
|
9424
|
+
} catch {
|
|
9425
|
+
}
|
|
9426
|
+
}
|
|
9427
|
+
return false;
|
|
9428
|
+
}
|
|
9429
|
+
async function readAllDependencies(context) {
|
|
9430
|
+
const dependencies = [];
|
|
9431
|
+
const apps = context.apps.length ? context.apps : [];
|
|
9432
|
+
for (const app of apps) {
|
|
9433
|
+
if (!app.packageJsonPath) continue;
|
|
9434
|
+
const pkg = await readJson(app.packageJsonPath);
|
|
9435
|
+
const deps = pkg?.dependencies ?? {};
|
|
9436
|
+
const devDeps = pkg?.devDependencies ?? {};
|
|
9437
|
+
dependencies.push(
|
|
9438
|
+
...Object.keys({
|
|
9439
|
+
...deps,
|
|
9440
|
+
...devDeps
|
|
9441
|
+
})
|
|
9442
|
+
);
|
|
9443
|
+
}
|
|
9444
|
+
if (!apps.length && context.rootPackageJson) {
|
|
9445
|
+
const rootDeps = context.rootPackageJson.dependencies ?? {};
|
|
9446
|
+
const rootDevDeps = context.rootPackageJson.devDependencies ?? {};
|
|
9447
|
+
dependencies.push(
|
|
9448
|
+
...Object.keys({
|
|
9449
|
+
...rootDeps,
|
|
9450
|
+
...rootDevDeps
|
|
9451
|
+
})
|
|
9452
|
+
);
|
|
8929
9453
|
}
|
|
8930
|
-
return
|
|
8931
|
-
repoPath,
|
|
8932
|
-
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
8933
|
-
isMonorepo: analysis.isMonorepo ?? false,
|
|
8934
|
-
apps: apps.map((app) => ({ name: app.name, path: app.path })),
|
|
8935
|
-
pillars,
|
|
8936
|
-
levels,
|
|
8937
|
-
achievedLevel,
|
|
8938
|
-
criteria: criteriaResults,
|
|
8939
|
-
extras,
|
|
8940
|
-
areaReports,
|
|
8941
|
-
policies: policyInfo,
|
|
8942
|
-
engine
|
|
8943
|
-
};
|
|
9454
|
+
return Array.from(new Set(dependencies));
|
|
8944
9455
|
}
|
|
9456
|
+
|
|
9457
|
+
// packages/core/src/services/readiness/criteria.ts
|
|
9458
|
+
import path10 from "path";
|
|
8945
9459
|
function buildCriteria() {
|
|
8946
9460
|
return [
|
|
8947
9461
|
{
|
|
@@ -9053,7 +9567,7 @@ function buildCriteria() {
|
|
|
9053
9567
|
impact: "medium",
|
|
9054
9568
|
effort: "low",
|
|
9055
9569
|
check: async (context) => {
|
|
9056
|
-
const found = await fileExists(
|
|
9570
|
+
const found = await fileExists(path10.join(context.repoPath, "CONTRIBUTING.md"));
|
|
9057
9571
|
return {
|
|
9058
9572
|
status: found ? "pass" : "fail",
|
|
9059
9573
|
reason: found ? void 0 : "Missing CONTRIBUTING.md for contributor workflows."
|
|
@@ -9154,7 +9668,7 @@ function buildCriteria() {
|
|
|
9154
9668
|
impact: "high",
|
|
9155
9669
|
effort: "low",
|
|
9156
9670
|
check: async (context) => {
|
|
9157
|
-
const found = await fileExists(
|
|
9671
|
+
const found = await fileExists(path10.join(context.repoPath, "SECURITY.md"));
|
|
9158
9672
|
return {
|
|
9159
9673
|
status: found ? "pass" : "fail",
|
|
9160
9674
|
reason: found ? void 0 : "Missing SECURITY.md policy."
|
|
@@ -9170,7 +9684,7 @@ function buildCriteria() {
|
|
|
9170
9684
|
impact: "medium",
|
|
9171
9685
|
effort: "medium",
|
|
9172
9686
|
check: async (context) => {
|
|
9173
|
-
const found = await fileExists(
|
|
9687
|
+
const found = await fileExists(path10.join(context.repoPath, ".github", "dependabot.yml"));
|
|
9174
9688
|
return {
|
|
9175
9689
|
status: found ? "pass" : "fail",
|
|
9176
9690
|
reason: found ? void 0 : "Missing .github/dependabot.yml configuration."
|
|
@@ -9198,7 +9712,7 @@ function buildCriteria() {
|
|
|
9198
9712
|
},
|
|
9199
9713
|
{
|
|
9200
9714
|
id: "custom-instructions",
|
|
9201
|
-
title: "Custom
|
|
9715
|
+
title: "Custom instructions or agent guidance",
|
|
9202
9716
|
pillar: "ai-tooling",
|
|
9203
9717
|
level: 1,
|
|
9204
9718
|
scope: "repo",
|
|
@@ -9209,7 +9723,7 @@ function buildCriteria() {
|
|
|
9209
9723
|
if (rootFound.length === 0) {
|
|
9210
9724
|
return {
|
|
9211
9725
|
status: "fail",
|
|
9212
|
-
reason: "Missing custom
|
|
9726
|
+
reason: "Missing custom instructions (e.g. copilot-instructions.md, CLAUDE.md, AGENTS.md, .cursorrules).",
|
|
9213
9727
|
evidence: [
|
|
9214
9728
|
"copilot-instructions.md",
|
|
9215
9729
|
"CLAUDE.md",
|
|
@@ -9219,16 +9733,26 @@ function buildCriteria() {
|
|
|
9219
9733
|
]
|
|
9220
9734
|
};
|
|
9221
9735
|
}
|
|
9222
|
-
const fileBasedInstructions = await hasFileBasedInstructions(
|
|
9736
|
+
const fileBasedInstructions = await hasFileBasedInstructions(
|
|
9737
|
+
context.repoPath,
|
|
9738
|
+
context.vscodeLocations?.instructionsLocations
|
|
9739
|
+
);
|
|
9223
9740
|
const areas = context.analysis.areas ?? [];
|
|
9224
9741
|
if (areas.length > 0) {
|
|
9225
9742
|
if (fileBasedInstructions.length === 0) {
|
|
9226
9743
|
return {
|
|
9227
9744
|
status: "pass",
|
|
9228
|
-
reason: `Root instructions found, but no
|
|
9745
|
+
reason: `Root instructions found, but no area instructions for ${areas.length} detected areas. Run \`agentrc instructions --areas\` to generate.`,
|
|
9229
9746
|
evidence: [...rootFound, ...areas.map((a) => `${a.name}: missing .instructions.md`)]
|
|
9230
9747
|
};
|
|
9231
9748
|
}
|
|
9749
|
+
return {
|
|
9750
|
+
status: "pass",
|
|
9751
|
+
reason: `Root + ${fileBasedInstructions.length} area instruction(s) found.`,
|
|
9752
|
+
evidence: [...rootFound, ...fileBasedInstructions]
|
|
9753
|
+
};
|
|
9754
|
+
}
|
|
9755
|
+
if (fileBasedInstructions.length > 0) {
|
|
9232
9756
|
return {
|
|
9233
9757
|
status: "pass",
|
|
9234
9758
|
reason: `Root + ${fileBasedInstructions.length} file-based instruction(s) found.`,
|
|
@@ -9314,7 +9838,10 @@ function buildCriteria() {
|
|
|
9314
9838
|
impact: "medium",
|
|
9315
9839
|
effort: "medium",
|
|
9316
9840
|
check: async (context) => {
|
|
9317
|
-
const found = await hasCustomAgents(
|
|
9841
|
+
const found = await hasCustomAgents(
|
|
9842
|
+
context.repoPath,
|
|
9843
|
+
context.vscodeLocations?.agentLocations
|
|
9844
|
+
);
|
|
9318
9845
|
return {
|
|
9319
9846
|
status: found.length > 0 ? "pass" : "fail",
|
|
9320
9847
|
reason: "No custom AI agents configured (e.g. .github/agents/, .copilot/agents/).",
|
|
@@ -9331,7 +9858,10 @@ function buildCriteria() {
|
|
|
9331
9858
|
impact: "medium",
|
|
9332
9859
|
effort: "medium",
|
|
9333
9860
|
check: async (context) => {
|
|
9334
|
-
const found = await hasCopilotSkills(
|
|
9861
|
+
const found = await hasCopilotSkills(
|
|
9862
|
+
context.repoPath,
|
|
9863
|
+
context.vscodeLocations?.skillsLocations
|
|
9864
|
+
);
|
|
9335
9865
|
return {
|
|
9336
9866
|
status: found.length > 0 ? "pass" : "fail",
|
|
9337
9867
|
reason: "No Copilot or Claude skills found (e.g. .copilot/skills/, .github/skills/).",
|
|
@@ -9339,6 +9869,65 @@ function buildCriteria() {
|
|
|
9339
9869
|
};
|
|
9340
9870
|
}
|
|
9341
9871
|
},
|
|
9872
|
+
{
|
|
9873
|
+
id: "apm-config",
|
|
9874
|
+
title: "APM package manifest present",
|
|
9875
|
+
pillar: "ai-tooling",
|
|
9876
|
+
level: 2,
|
|
9877
|
+
scope: "repo",
|
|
9878
|
+
impact: "medium",
|
|
9879
|
+
effort: "low",
|
|
9880
|
+
check: async (context) => {
|
|
9881
|
+
const found = await hasApmConfig(context.repoPath);
|
|
9882
|
+
return {
|
|
9883
|
+
status: found ? "pass" : "fail",
|
|
9884
|
+
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",
|
|
9885
|
+
evidence: ["apm.yml"]
|
|
9886
|
+
};
|
|
9887
|
+
}
|
|
9888
|
+
},
|
|
9889
|
+
{
|
|
9890
|
+
id: "apm-locked-deps",
|
|
9891
|
+
title: "APM dependencies locked",
|
|
9892
|
+
pillar: "ai-tooling",
|
|
9893
|
+
level: 3,
|
|
9894
|
+
scope: "repo",
|
|
9895
|
+
impact: "medium",
|
|
9896
|
+
effort: "low",
|
|
9897
|
+
check: async (context) => {
|
|
9898
|
+
const hasConfig = await hasApmConfig(context.repoPath);
|
|
9899
|
+
if (!hasConfig) {
|
|
9900
|
+
return { status: "skip", reason: "No apm.yml found \u2014 skipping lockfile check." };
|
|
9901
|
+
}
|
|
9902
|
+
const found = await hasApmLockfile(context.repoPath);
|
|
9903
|
+
return {
|
|
9904
|
+
status: found ? "pass" : "fail",
|
|
9905
|
+
reason: found ? void 0 : "apm.yml found but dependencies are not locked. Run `apm install` to generate apm.lock.yaml.",
|
|
9906
|
+
evidence: ["apm.lock.yaml"]
|
|
9907
|
+
};
|
|
9908
|
+
}
|
|
9909
|
+
},
|
|
9910
|
+
{
|
|
9911
|
+
id: "apm-ci-integration",
|
|
9912
|
+
title: "APM integrated in CI pipeline",
|
|
9913
|
+
pillar: "ai-tooling",
|
|
9914
|
+
level: 4,
|
|
9915
|
+
scope: "repo",
|
|
9916
|
+
impact: "high",
|
|
9917
|
+
effort: "medium",
|
|
9918
|
+
check: async (context) => {
|
|
9919
|
+
const hasConfig = await hasApmConfig(context.repoPath);
|
|
9920
|
+
if (!hasConfig) {
|
|
9921
|
+
return { status: "skip", reason: "No apm.yml found \u2014 skipping CI check." };
|
|
9922
|
+
}
|
|
9923
|
+
const found = await hasApmInWorkflows(context.repoPath);
|
|
9924
|
+
return {
|
|
9925
|
+
status: found ? "pass" : "fail",
|
|
9926
|
+
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",
|
|
9927
|
+
evidence: [".github/workflows/*.{yml,yaml}"]
|
|
9928
|
+
};
|
|
9929
|
+
}
|
|
9930
|
+
},
|
|
9342
9931
|
// ── Area-scoped criteria (only run when areaPath is set) ──
|
|
9343
9932
|
{
|
|
9344
9933
|
id: "area-readme",
|
|
@@ -9376,7 +9965,7 @@ function buildCriteria() {
|
|
|
9376
9965
|
if (area?.scripts?.build) {
|
|
9377
9966
|
return { status: "pass" };
|
|
9378
9967
|
}
|
|
9379
|
-
const pkgPath =
|
|
9968
|
+
const pkgPath = path10.join(context.areaPath, "package.json");
|
|
9380
9969
|
const pkg = await readJson(pkgPath);
|
|
9381
9970
|
const scripts = pkg?.scripts ?? {};
|
|
9382
9971
|
const found = Boolean(scripts.build);
|
|
@@ -9401,7 +9990,7 @@ function buildCriteria() {
|
|
|
9401
9990
|
if (area?.scripts?.test) {
|
|
9402
9991
|
return { status: "pass" };
|
|
9403
9992
|
}
|
|
9404
|
-
const pkgPath =
|
|
9993
|
+
const pkgPath = path10.join(context.areaPath, "package.json");
|
|
9405
9994
|
const pkg = await readJson(pkgPath);
|
|
9406
9995
|
const scripts = pkg?.scripts ?? {};
|
|
9407
9996
|
const found = Boolean(scripts.test);
|
|
@@ -9424,7 +10013,7 @@ function buildCriteria() {
|
|
|
9424
10013
|
return { status: "skip", reason: "No area context." };
|
|
9425
10014
|
}
|
|
9426
10015
|
const sanitized = sanitizeAreaName(area.name);
|
|
9427
|
-
const instructionPath =
|
|
10016
|
+
const instructionPath = path10.join(
|
|
9428
10017
|
context.repoPath,
|
|
9429
10018
|
".github",
|
|
9430
10019
|
"instructions",
|
|
@@ -9439,13 +10028,16 @@ function buildCriteria() {
|
|
|
9439
10028
|
}
|
|
9440
10029
|
];
|
|
9441
10030
|
}
|
|
10031
|
+
|
|
10032
|
+
// packages/core/src/services/readiness/extras.ts
|
|
10033
|
+
import path11 from "path";
|
|
9442
10034
|
function buildExtras() {
|
|
9443
10035
|
return [
|
|
9444
10036
|
{
|
|
9445
10037
|
id: "agents-doc",
|
|
9446
10038
|
title: "AGENTS.md present",
|
|
9447
10039
|
check: async (context) => {
|
|
9448
|
-
const found = await fileExists(
|
|
10040
|
+
const found = await fileExists(path11.join(context.repoPath, "AGENTS.md"));
|
|
9449
10041
|
return {
|
|
9450
10042
|
status: found ? "pass" : "fail",
|
|
9451
10043
|
reason: found ? void 0 : "Missing AGENTS.md to guide coding agents."
|
|
@@ -9500,6 +10092,53 @@ async function runExtras(context, extraDefs) {
|
|
|
9500
10092
|
}
|
|
9501
10093
|
return results;
|
|
9502
10094
|
}
|
|
10095
|
+
|
|
10096
|
+
// packages/core/src/services/readiness/types.ts
|
|
10097
|
+
var PILLAR_GROUPS = {
|
|
10098
|
+
"style-validation": "repo-health",
|
|
10099
|
+
"build-system": "repo-health",
|
|
10100
|
+
testing: "repo-health",
|
|
10101
|
+
documentation: "repo-health",
|
|
10102
|
+
"dev-environment": "repo-health",
|
|
10103
|
+
"code-quality": "repo-health",
|
|
10104
|
+
observability: "repo-health",
|
|
10105
|
+
"security-governance": "repo-health",
|
|
10106
|
+
"ai-tooling": "ai-setup"
|
|
10107
|
+
};
|
|
10108
|
+
var PILLAR_GROUP_NAMES = {
|
|
10109
|
+
"repo-health": "Repo Health",
|
|
10110
|
+
"ai-setup": "AI Setup"
|
|
10111
|
+
};
|
|
10112
|
+
|
|
10113
|
+
// packages/core/src/services/readiness/scoring.ts
|
|
10114
|
+
function groupPillars(pillars) {
|
|
10115
|
+
const groups = ["repo-health", "ai-setup"];
|
|
10116
|
+
return groups.map((group) => ({
|
|
10117
|
+
group,
|
|
10118
|
+
label: PILLAR_GROUP_NAMES[group],
|
|
10119
|
+
pillars: pillars.filter((p) => PILLAR_GROUPS[p.id] === group)
|
|
10120
|
+
}));
|
|
10121
|
+
}
|
|
10122
|
+
function getLevelName(level) {
|
|
10123
|
+
const names = {
|
|
10124
|
+
1: "Functional",
|
|
10125
|
+
2: "Documented",
|
|
10126
|
+
3: "Standardized",
|
|
10127
|
+
4: "Optimized",
|
|
10128
|
+
5: "Autonomous"
|
|
10129
|
+
};
|
|
10130
|
+
return names[level] || "Unknown";
|
|
10131
|
+
}
|
|
10132
|
+
function getLevelDescription(level) {
|
|
10133
|
+
const descriptions = {
|
|
10134
|
+
1: "Repo builds, tests run, and basic tooling (linter, lockfile) is in place. AI agents can clone and get started.",
|
|
10135
|
+
2: "README, CONTRIBUTING guide, and custom instructions exist. Agents understand project context and conventions.",
|
|
10136
|
+
3: "CI/CD, security policies, CODEOWNERS, and observability are configured. Agents operate within well-defined guardrails.",
|
|
10137
|
+
4: "MCP servers, custom agents, and AI skills are set up. Agents have deep integration with project-specific tools and workflows.",
|
|
10138
|
+
5: "Full AI-native development: agents can independently plan, implement, test, and ship changes with minimal human oversight."
|
|
10139
|
+
};
|
|
10140
|
+
return descriptions[level] || "";
|
|
10141
|
+
}
|
|
9503
10142
|
function summarizePillars(criteria) {
|
|
9504
10143
|
const pillarNames = {
|
|
9505
10144
|
"style-validation": "Style & Validation",
|
|
@@ -9546,260 +10185,225 @@ function summarizeLevels(criteria, passRateThreshold = 0.8) {
|
|
|
9546
10185
|
achieved: false
|
|
9547
10186
|
});
|
|
9548
10187
|
}
|
|
9549
|
-
for (const summary of summaries) {
|
|
9550
|
-
const allPrior = summaries.filter((candidate) => candidate.level <= summary.level);
|
|
9551
|
-
const achieved = allPrior.every(
|
|
9552
|
-
(candidate) => candidate.total > 0 && candidate.passRate >= passRateThreshold
|
|
9553
|
-
);
|
|
9554
|
-
summary.achieved = achieved;
|
|
9555
|
-
}
|
|
9556
|
-
return summaries;
|
|
9557
|
-
}
|
|
9558
|
-
function countStatus(items) {
|
|
9559
|
-
const relevant = items.filter((item) => item.status !== "skip");
|
|
9560
|
-
const passed = relevant.filter((item) => item.status === "pass").length;
|
|
9561
|
-
return { passed, total: relevant.length };
|
|
9562
|
-
}
|
|
9563
|
-
function hasAnyFile(files, candidates) {
|
|
9564
|
-
return candidates.some((candidate) => files.includes(candidate));
|
|
9565
|
-
}
|
|
9566
|
-
async function hasReadme(repoPath) {
|
|
9567
|
-
const files = await safeReadDir(repoPath);
|
|
9568
|
-
return files.some(
|
|
9569
|
-
(file) => file.toLowerCase() === "readme.md" || file.toLowerCase() === "readme"
|
|
9570
|
-
);
|
|
9571
|
-
}
|
|
9572
|
-
async function hasLintConfig(repoPath) {
|
|
9573
|
-
return hasAnyFile(await safeReadDir(repoPath), [
|
|
9574
|
-
"eslint.config.js",
|
|
9575
|
-
"eslint.config.mjs",
|
|
9576
|
-
".eslintrc",
|
|
9577
|
-
".eslintrc.js",
|
|
9578
|
-
".eslintrc.cjs",
|
|
9579
|
-
".eslintrc.json",
|
|
9580
|
-
".eslintrc.yml",
|
|
9581
|
-
".eslintrc.yaml",
|
|
9582
|
-
"biome.json",
|
|
9583
|
-
"biome.jsonc",
|
|
9584
|
-
".prettierrc",
|
|
9585
|
-
".prettierrc.json",
|
|
9586
|
-
".prettierrc.js",
|
|
9587
|
-
".prettierrc.cjs",
|
|
9588
|
-
"prettier.config.js",
|
|
9589
|
-
"prettier.config.cjs"
|
|
9590
|
-
]);
|
|
9591
|
-
}
|
|
9592
|
-
async function hasFormatterConfig(repoPath) {
|
|
9593
|
-
return hasAnyFile(await safeReadDir(repoPath), [
|
|
9594
|
-
"biome.json",
|
|
9595
|
-
"biome.jsonc",
|
|
9596
|
-
".prettierrc",
|
|
9597
|
-
".prettierrc.json",
|
|
9598
|
-
".prettierrc.js",
|
|
9599
|
-
".prettierrc.cjs",
|
|
9600
|
-
"prettier.config.js",
|
|
9601
|
-
"prettier.config.cjs"
|
|
9602
|
-
]);
|
|
9603
|
-
}
|
|
9604
|
-
async function hasTypecheckConfig(repoPath) {
|
|
9605
|
-
return hasAnyFile(await safeReadDir(repoPath), [
|
|
9606
|
-
"tsconfig.json",
|
|
9607
|
-
"tsconfig.base.json",
|
|
9608
|
-
"pyproject.toml",
|
|
9609
|
-
"mypy.ini"
|
|
9610
|
-
]);
|
|
9611
|
-
}
|
|
9612
|
-
async function hasGithubWorkflows(repoPath) {
|
|
9613
|
-
return fileExists(path8.join(repoPath, ".github", "workflows"));
|
|
9614
|
-
}
|
|
9615
|
-
async function hasCodeowners(repoPath) {
|
|
9616
|
-
const root = await fileExists(path8.join(repoPath, "CODEOWNERS"));
|
|
9617
|
-
const github = await fileExists(path8.join(repoPath, ".github", "CODEOWNERS"));
|
|
9618
|
-
return root || github;
|
|
9619
|
-
}
|
|
9620
|
-
async function hasLicense(repoPath) {
|
|
9621
|
-
const files = await safeReadDir(repoPath);
|
|
9622
|
-
return files.some((file) => file.toLowerCase().startsWith("license"));
|
|
9623
|
-
}
|
|
9624
|
-
async function hasPullRequestTemplate(repoPath) {
|
|
9625
|
-
const direct = await fileExists(path8.join(repoPath, ".github", "PULL_REQUEST_TEMPLATE.md"));
|
|
9626
|
-
if (direct) return true;
|
|
9627
|
-
const dir = path8.join(repoPath, ".github", "PULL_REQUEST_TEMPLATE");
|
|
9628
|
-
try {
|
|
9629
|
-
const entries = await fs7.readdir(dir);
|
|
9630
|
-
return entries.some((entry) => entry.toLowerCase().endsWith(".md"));
|
|
9631
|
-
} catch {
|
|
9632
|
-
return false;
|
|
9633
|
-
}
|
|
9634
|
-
}
|
|
9635
|
-
async function hasPrecommitConfig(repoPath) {
|
|
9636
|
-
const precommit = await fileExists(path8.join(repoPath, ".pre-commit-config.yaml"));
|
|
9637
|
-
if (precommit) return true;
|
|
9638
|
-
return fileExists(path8.join(repoPath, ".husky"));
|
|
9639
|
-
}
|
|
9640
|
-
async function hasArchitectureDoc(repoPath) {
|
|
9641
|
-
const files = await safeReadDir(repoPath);
|
|
9642
|
-
if (files.some((file) => file.toLowerCase() === "architecture.md")) return true;
|
|
9643
|
-
return fileExists(path8.join(repoPath, "docs", "architecture.md"));
|
|
9644
|
-
}
|
|
9645
|
-
async function hasCustomInstructions(repoPath) {
|
|
9646
|
-
const found = [];
|
|
9647
|
-
const candidates = [
|
|
9648
|
-
".github/copilot-instructions.md",
|
|
9649
|
-
"CLAUDE.md",
|
|
9650
|
-
".claude/CLAUDE.md",
|
|
9651
|
-
"AGENTS.md",
|
|
9652
|
-
".github/AGENTS.md",
|
|
9653
|
-
".cursorrules",
|
|
9654
|
-
".cursorignore",
|
|
9655
|
-
".windsurfrules",
|
|
9656
|
-
".github/instructions.md",
|
|
9657
|
-
"copilot-instructions.md"
|
|
9658
|
-
];
|
|
9659
|
-
for (const candidate of candidates) {
|
|
9660
|
-
if (await fileExists(path8.join(repoPath, candidate))) {
|
|
9661
|
-
found.push(candidate);
|
|
9662
|
-
}
|
|
9663
|
-
}
|
|
9664
|
-
return found;
|
|
9665
|
-
}
|
|
9666
|
-
async function hasFileBasedInstructions(repoPath) {
|
|
9667
|
-
const instructionsDir = path8.join(repoPath, ".github", "instructions");
|
|
9668
|
-
try {
|
|
9669
|
-
const entries = await fs7.readdir(instructionsDir);
|
|
9670
|
-
return entries.filter((e) => e.endsWith(".instructions.md")).map((e) => `.github/instructions/${e}`);
|
|
9671
|
-
} catch {
|
|
9672
|
-
return [];
|
|
10188
|
+
for (const summary of summaries) {
|
|
10189
|
+
const allPrior = summaries.filter((candidate) => candidate.level <= summary.level);
|
|
10190
|
+
const achieved = allPrior.every(
|
|
10191
|
+
(candidate) => candidate.total > 0 && candidate.passRate >= passRateThreshold
|
|
10192
|
+
);
|
|
10193
|
+
summary.achieved = achieved;
|
|
9673
10194
|
}
|
|
10195
|
+
return summaries;
|
|
9674
10196
|
}
|
|
9675
|
-
function
|
|
9676
|
-
const
|
|
9677
|
-
|
|
9678
|
-
|
|
9679
|
-
const setA = normalize(a);
|
|
9680
|
-
const setB = normalize(b);
|
|
9681
|
-
if (setA.size === 0 && setB.size === 0) return 1;
|
|
9682
|
-
let intersection = 0;
|
|
9683
|
-
for (const line of setA) {
|
|
9684
|
-
if (setB.has(line)) intersection++;
|
|
9685
|
-
}
|
|
9686
|
-
const union = (/* @__PURE__ */ new Set([...setA, ...setB])).size;
|
|
9687
|
-
return union === 0 ? 1 : intersection / union;
|
|
10197
|
+
function countStatus(items) {
|
|
10198
|
+
const relevant = items.filter((item) => item.status !== "skip");
|
|
10199
|
+
const passed = relevant.filter((item) => item.status === "pass").length;
|
|
10200
|
+
return { passed, total: relevant.length };
|
|
9688
10201
|
}
|
|
9689
|
-
|
|
9690
|
-
|
|
9691
|
-
|
|
9692
|
-
|
|
9693
|
-
const
|
|
9694
|
-
|
|
9695
|
-
|
|
9696
|
-
|
|
9697
|
-
|
|
9698
|
-
|
|
9699
|
-
|
|
9700
|
-
|
|
9701
|
-
|
|
9702
|
-
|
|
10202
|
+
|
|
10203
|
+
// packages/core/src/services/readiness/index.ts
|
|
10204
|
+
async function runReadinessReport(options) {
|
|
10205
|
+
const repoPath = options.repoPath;
|
|
10206
|
+
const analysis = await analyzeRepo(repoPath);
|
|
10207
|
+
const rootFiles = await safeReadDir(repoPath);
|
|
10208
|
+
const rootPackageJson = await readJson(path12.join(repoPath, "package.json"));
|
|
10209
|
+
const apps = analysis.apps?.length ? analysis.apps : [];
|
|
10210
|
+
const vscodeLocations = await parseVscodeLocations(repoPath, rootFiles);
|
|
10211
|
+
const context = {
|
|
10212
|
+
repoPath,
|
|
10213
|
+
analysis,
|
|
10214
|
+
apps,
|
|
10215
|
+
rootFiles,
|
|
10216
|
+
rootPackageJson,
|
|
10217
|
+
vscodeLocations
|
|
10218
|
+
};
|
|
10219
|
+
let policySources = options.policies;
|
|
10220
|
+
let isConfigSourced = false;
|
|
10221
|
+
if (!policySources?.length) {
|
|
10222
|
+
const agentrcConfig = await loadAgentrcConfig(repoPath);
|
|
10223
|
+
if (agentrcConfig?.policies?.length) {
|
|
10224
|
+
policySources = agentrcConfig.policies;
|
|
10225
|
+
isConfigSourced = true;
|
|
9703
10226
|
}
|
|
9704
10227
|
}
|
|
9705
|
-
const
|
|
9706
|
-
|
|
9707
|
-
|
|
9708
|
-
|
|
9709
|
-
|
|
9710
|
-
|
|
9711
|
-
|
|
9712
|
-
|
|
9713
|
-
|
|
9714
|
-
|
|
10228
|
+
const baseCriteria = buildCriteria();
|
|
10229
|
+
const baseExtras = buildExtras();
|
|
10230
|
+
let resolvedCriteria;
|
|
10231
|
+
let resolvedExtras;
|
|
10232
|
+
let passRateThreshold = 0.8;
|
|
10233
|
+
let policyInfo;
|
|
10234
|
+
if (policySources?.length) {
|
|
10235
|
+
const policyConfigs = [];
|
|
10236
|
+
for (const source of policySources) {
|
|
10237
|
+
policyConfigs.push(await loadPolicy(source, { jsonOnly: isConfigSourced }));
|
|
9715
10238
|
}
|
|
10239
|
+
const resolved = resolveChain(baseCriteria, baseExtras, policyConfigs);
|
|
10240
|
+
resolvedCriteria = resolved.criteria;
|
|
10241
|
+
resolvedExtras = resolved.extras;
|
|
10242
|
+
passRateThreshold = resolved.thresholds.passRate;
|
|
10243
|
+
policyInfo = { chain: resolved.chain, criteriaCount: resolved.criteria.length };
|
|
10244
|
+
} else {
|
|
10245
|
+
resolvedCriteria = baseCriteria;
|
|
10246
|
+
resolvedExtras = baseExtras;
|
|
9716
10247
|
}
|
|
9717
|
-
|
|
9718
|
-
for (
|
|
9719
|
-
|
|
9720
|
-
|
|
10248
|
+
const criteriaResults = [];
|
|
10249
|
+
for (const criterion of resolvedCriteria) {
|
|
10250
|
+
if (criterion.scope === "repo") {
|
|
10251
|
+
const result = await criterion.check(context);
|
|
10252
|
+
criteriaResults.push({
|
|
10253
|
+
id: criterion.id,
|
|
10254
|
+
title: criterion.title,
|
|
10255
|
+
pillar: criterion.pillar,
|
|
10256
|
+
level: criterion.level,
|
|
10257
|
+
scope: criterion.scope,
|
|
10258
|
+
impact: criterion.impact,
|
|
10259
|
+
effort: criterion.effort,
|
|
10260
|
+
status: result.status,
|
|
10261
|
+
reason: result.reason,
|
|
10262
|
+
evidence: result.evidence
|
|
10263
|
+
});
|
|
10264
|
+
continue;
|
|
9721
10265
|
}
|
|
9722
|
-
|
|
9723
|
-
|
|
9724
|
-
|
|
9725
|
-
|
|
9726
|
-
|
|
9727
|
-
|
|
9728
|
-
|
|
9729
|
-
|
|
9730
|
-
|
|
9731
|
-
|
|
9732
|
-
|
|
9733
|
-
|
|
9734
|
-
|
|
9735
|
-
|
|
9736
|
-
|
|
9737
|
-
|
|
9738
|
-
if (settings && (settings["mcp"] || settings["github.copilot.chat.mcp.enabled"])) {
|
|
9739
|
-
found.push(".vscode/settings.json (mcp section)");
|
|
9740
|
-
}
|
|
9741
|
-
if (await fileExists(path8.join(repoPath, ".claude", "mcp.json"))) {
|
|
9742
|
-
found.push(".claude/mcp.json");
|
|
9743
|
-
}
|
|
9744
|
-
return found;
|
|
9745
|
-
}
|
|
9746
|
-
async function hasCustomAgents(repoPath) {
|
|
9747
|
-
const found = [];
|
|
9748
|
-
const agentDirs = [".github/agents", ".copilot/agents", ".github/copilot/agents"];
|
|
9749
|
-
for (const dir of agentDirs) {
|
|
9750
|
-
if (await fileExists(path8.join(repoPath, dir))) {
|
|
9751
|
-
found.push(dir);
|
|
10266
|
+
if (criterion.scope === "area") {
|
|
10267
|
+
if (!options.perArea) continue;
|
|
10268
|
+
const areas2 = analysis.areas ?? [];
|
|
10269
|
+
if (areas2.length === 0) continue;
|
|
10270
|
+
criteriaResults.push({
|
|
10271
|
+
id: criterion.id,
|
|
10272
|
+
title: criterion.title,
|
|
10273
|
+
pillar: criterion.pillar,
|
|
10274
|
+
level: criterion.level,
|
|
10275
|
+
scope: criterion.scope,
|
|
10276
|
+
impact: criterion.impact,
|
|
10277
|
+
effort: criterion.effort,
|
|
10278
|
+
status: "skip",
|
|
10279
|
+
reason: "Run with --per-area for area breakdown."
|
|
10280
|
+
});
|
|
10281
|
+
continue;
|
|
9752
10282
|
}
|
|
9753
|
-
|
|
9754
|
-
|
|
9755
|
-
|
|
9756
|
-
|
|
9757
|
-
|
|
10283
|
+
const appResults = await Promise.all(
|
|
10284
|
+
apps.map(async (app) => ({
|
|
10285
|
+
app,
|
|
10286
|
+
result: await criterion.check(context, app)
|
|
10287
|
+
}))
|
|
10288
|
+
);
|
|
10289
|
+
if (!appResults.length) {
|
|
10290
|
+
criteriaResults.push({
|
|
10291
|
+
id: criterion.id,
|
|
10292
|
+
title: criterion.title,
|
|
10293
|
+
pillar: criterion.pillar,
|
|
10294
|
+
level: criterion.level,
|
|
10295
|
+
scope: criterion.scope,
|
|
10296
|
+
impact: criterion.impact,
|
|
10297
|
+
effort: criterion.effort,
|
|
10298
|
+
status: "skip",
|
|
10299
|
+
reason: "No application packages detected."
|
|
10300
|
+
});
|
|
10301
|
+
continue;
|
|
9758
10302
|
}
|
|
10303
|
+
const passed = appResults.filter((entry) => entry.result.status === "pass").length;
|
|
10304
|
+
const total = appResults.length;
|
|
10305
|
+
const passRate = total ? passed / total : 0;
|
|
10306
|
+
const status = passRate >= passRateThreshold ? "pass" : "fail";
|
|
10307
|
+
const failures = appResults.filter((entry) => entry.result.status !== "pass").map((entry) => entry.app.name);
|
|
10308
|
+
criteriaResults.push({
|
|
10309
|
+
id: criterion.id,
|
|
10310
|
+
title: criterion.title,
|
|
10311
|
+
pillar: criterion.pillar,
|
|
10312
|
+
level: criterion.level,
|
|
10313
|
+
scope: criterion.scope,
|
|
10314
|
+
impact: criterion.impact,
|
|
10315
|
+
effort: criterion.effort,
|
|
10316
|
+
status,
|
|
10317
|
+
reason: status === "pass" ? void 0 : `Only ${passed}/${total} apps pass this check.`,
|
|
10318
|
+
passRate,
|
|
10319
|
+
appSummary: { passed, total },
|
|
10320
|
+
appFailures: failures
|
|
10321
|
+
});
|
|
9759
10322
|
}
|
|
9760
|
-
|
|
9761
|
-
|
|
9762
|
-
|
|
9763
|
-
|
|
9764
|
-
|
|
9765
|
-
|
|
9766
|
-
|
|
9767
|
-
|
|
9768
|
-
|
|
9769
|
-
|
|
9770
|
-
|
|
9771
|
-
|
|
9772
|
-
|
|
10323
|
+
let areaReports;
|
|
10324
|
+
const areas = analysis.areas ?? [];
|
|
10325
|
+
if (options.perArea && areas.length > 0) {
|
|
10326
|
+
const areaCriteria = resolvedCriteria.filter((c) => c.scope === "area");
|
|
10327
|
+
areaReports = [];
|
|
10328
|
+
for (const area of areas) {
|
|
10329
|
+
if (!area.path) continue;
|
|
10330
|
+
const areaFiles = await safeReadDir(area.path);
|
|
10331
|
+
const areaContext = {
|
|
10332
|
+
...context,
|
|
10333
|
+
areaPath: area.path,
|
|
10334
|
+
areaFiles
|
|
10335
|
+
};
|
|
10336
|
+
const areaResults = [];
|
|
10337
|
+
for (const criterion of areaCriteria) {
|
|
10338
|
+
const result = await criterion.check(areaContext, void 0, area);
|
|
10339
|
+
areaResults.push({
|
|
10340
|
+
id: criterion.id,
|
|
10341
|
+
title: criterion.title,
|
|
10342
|
+
pillar: criterion.pillar,
|
|
10343
|
+
level: criterion.level,
|
|
10344
|
+
scope: criterion.scope,
|
|
10345
|
+
impact: criterion.impact,
|
|
10346
|
+
effort: criterion.effort,
|
|
10347
|
+
status: result.status,
|
|
10348
|
+
reason: result.reason,
|
|
10349
|
+
evidence: result.evidence
|
|
10350
|
+
});
|
|
10351
|
+
}
|
|
10352
|
+
const areaPillars = summarizePillars(areaResults);
|
|
10353
|
+
areaReports.push({ area, criteria: areaResults, pillars: areaPillars });
|
|
10354
|
+
}
|
|
10355
|
+
for (const criterion of criteriaResults) {
|
|
10356
|
+
if (criterion.scope !== "area") continue;
|
|
10357
|
+
const perAreaResults = areaReports.map((ar) => ar.criteria.find((c) => c.id === criterion.id)).filter(Boolean);
|
|
10358
|
+
if (!perAreaResults.length) continue;
|
|
10359
|
+
const passed = perAreaResults.filter((r) => r.status === "pass").length;
|
|
10360
|
+
const total = perAreaResults.length;
|
|
10361
|
+
const passRate = total ? passed / total : 0;
|
|
10362
|
+
criterion.status = passRate >= passRateThreshold ? "pass" : "fail";
|
|
10363
|
+
criterion.reason = criterion.status === "pass" ? void 0 : `Only ${passed}/${total} areas pass this check.`;
|
|
10364
|
+
criterion.passRate = passRate;
|
|
10365
|
+
criterion.areaSummary = { passed, total };
|
|
10366
|
+
criterion.areaFailures = areaReports.filter((ar) => ar.criteria.find((c) => c.id === criterion.id)?.status !== "pass").map((ar) => ar.area.name);
|
|
9773
10367
|
}
|
|
9774
10368
|
}
|
|
9775
|
-
|
|
9776
|
-
|
|
9777
|
-
|
|
9778
|
-
const
|
|
9779
|
-
|
|
9780
|
-
|
|
9781
|
-
|
|
9782
|
-
|
|
9783
|
-
|
|
9784
|
-
|
|
9785
|
-
|
|
9786
|
-
|
|
9787
|
-
|
|
9788
|
-
|
|
9789
|
-
|
|
9790
|
-
);
|
|
9791
|
-
|
|
9792
|
-
|
|
9793
|
-
|
|
9794
|
-
|
|
9795
|
-
|
|
9796
|
-
|
|
9797
|
-
|
|
9798
|
-
...rootDevDeps
|
|
9799
|
-
})
|
|
9800
|
-
);
|
|
10369
|
+
const pillars = summarizePillars(criteriaResults);
|
|
10370
|
+
const levels = summarizeLevels(criteriaResults, passRateThreshold);
|
|
10371
|
+
const achievedLevel = levels.filter((level) => level.achieved).reduce((acc, level) => Math.max(acc, level.level), 0);
|
|
10372
|
+
const extras = options.includeExtras === false ? [] : await runExtras(context, resolvedExtras);
|
|
10373
|
+
let engine;
|
|
10374
|
+
if (options.shadow) {
|
|
10375
|
+
const policyCtx = {
|
|
10376
|
+
repoPath,
|
|
10377
|
+
rootFiles,
|
|
10378
|
+
rootPackageJson,
|
|
10379
|
+
cache: /* @__PURE__ */ new Map(),
|
|
10380
|
+
analysis,
|
|
10381
|
+
apps
|
|
10382
|
+
};
|
|
10383
|
+
const engineChain = await loadPluginChain(policySources ?? [], { jsonOnly: isConfigSourced });
|
|
10384
|
+
const engineReport = await executePlugins(engineChain.plugins, policyCtx, engineChain.options);
|
|
10385
|
+
engine = {
|
|
10386
|
+
signals: engineReport.signals,
|
|
10387
|
+
recommendations: engineReport.recommendations,
|
|
10388
|
+
policyWarnings: engineReport.policyWarnings,
|
|
10389
|
+
score: engineReport.score,
|
|
10390
|
+
grade: engineReport.grade
|
|
10391
|
+
};
|
|
9801
10392
|
}
|
|
9802
|
-
return
|
|
10393
|
+
return {
|
|
10394
|
+
repoPath,
|
|
10395
|
+
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
10396
|
+
isMonorepo: analysis.isMonorepo ?? false,
|
|
10397
|
+
apps: apps.map((app) => ({ name: app.name, path: app.path })),
|
|
10398
|
+
pillars,
|
|
10399
|
+
levels,
|
|
10400
|
+
achievedLevel,
|
|
10401
|
+
criteria: criteriaResults,
|
|
10402
|
+
extras,
|
|
10403
|
+
areaReports,
|
|
10404
|
+
policies: policyInfo,
|
|
10405
|
+
engine
|
|
10406
|
+
};
|
|
9803
10407
|
}
|
|
9804
10408
|
|
|
9805
10409
|
// packages/core/src/services/batch.ts
|
|
@@ -9821,7 +10425,7 @@ async function processRepo(params) {
|
|
|
9821
10425
|
} = params;
|
|
9822
10426
|
try {
|
|
9823
10427
|
progress?.update(`${label}: Cloning...`);
|
|
9824
|
-
const cacheRoot =
|
|
10428
|
+
const cacheRoot = path13.join(process.cwd(), ".agentrc-cache");
|
|
9825
10429
|
const repoPath = validateCachePath(cacheRoot, ...cacheParts);
|
|
9826
10430
|
await ensureDir(repoPath);
|
|
9827
10431
|
if (!await isGitRepo(repoPath)) {
|
|
@@ -9847,8 +10451,8 @@ async function processRepo(params) {
|
|
|
9847
10451
|
if (!instructions.trim()) {
|
|
9848
10452
|
throw new Error("Generated instructions were empty");
|
|
9849
10453
|
}
|
|
9850
|
-
const instructionsPath =
|
|
9851
|
-
await ensureDir(
|
|
10454
|
+
const instructionsPath = path13.join(repoPath, ".github", "copilot-instructions.md");
|
|
10455
|
+
await ensureDir(path13.dirname(instructionsPath));
|
|
9852
10456
|
const { wrote, reason } = await safeWriteFile(instructionsPath, instructions, true);
|
|
9853
10457
|
if (!wrote) {
|
|
9854
10458
|
throw new Error(
|
|
@@ -9856,7 +10460,7 @@ async function processRepo(params) {
|
|
|
9856
10460
|
);
|
|
9857
10461
|
}
|
|
9858
10462
|
progress?.update(`${label}: Committing...`);
|
|
9859
|
-
await commitAll(repoPath, "chore: add
|
|
10463
|
+
await commitAll(repoPath, "chore: add instructions via AgentRC");
|
|
9860
10464
|
progress?.update(`${label}: Pushing...`);
|
|
9861
10465
|
await pushBranch(repoPath, branch, token, provider);
|
|
9862
10466
|
progress?.update(`${label}: Creating PR...`);
|
|
@@ -9892,7 +10496,7 @@ async function processGitHubRepo(options) {
|
|
|
9892
10496
|
token,
|
|
9893
10497
|
owner: repo.owner,
|
|
9894
10498
|
repo: repo.name,
|
|
9895
|
-
title: "\u{1F916} Add
|
|
10499
|
+
title: "\u{1F916} Add instructions via AgentRC",
|
|
9896
10500
|
body: buildInstructionsPrBody(),
|
|
9897
10501
|
head: branchName,
|
|
9898
10502
|
base: repo.defaultBranch
|
|
@@ -9924,7 +10528,7 @@ async function processAzureRepo(options) {
|
|
|
9924
10528
|
project: repo.project,
|
|
9925
10529
|
repoId: repo.id,
|
|
9926
10530
|
repoName: repo.name,
|
|
9927
|
-
title: "\u{1F916} Add
|
|
10531
|
+
title: "\u{1F916} Add instructions via AgentRC",
|
|
9928
10532
|
body: buildInstructionsPrBody(),
|
|
9929
10533
|
sourceBranch: branchName,
|
|
9930
10534
|
targetBranch: repo.defaultBranch
|
|
@@ -9985,7 +10589,7 @@ async function processBatchReadinessRepo(options) {
|
|
|
9985
10589
|
try {
|
|
9986
10590
|
progress(`Cloning ${repo.fullName}...`);
|
|
9987
10591
|
const authedUrl = buildAuthedUrl(repo.cloneUrl, token, "github");
|
|
9988
|
-
await ensureDir(
|
|
10592
|
+
await ensureDir(path13.dirname(repoDir));
|
|
9989
10593
|
await cloneRepo(authedUrl, repoDir, { shallow: true });
|
|
9990
10594
|
await setRemoteUrl(repoDir, repo.cloneUrl).catch(() => {
|
|
9991
10595
|
});
|
|
@@ -11035,15 +11639,11 @@ import { render as render2 } from "ink";
|
|
|
11035
11639
|
// src/ui/BatchReadinessTui.tsx
|
|
11036
11640
|
import fs8 from "fs/promises";
|
|
11037
11641
|
import os from "os";
|
|
11038
|
-
import
|
|
11642
|
+
import path14 from "path";
|
|
11039
11643
|
|
|
11040
11644
|
// packages/core/src/services/visualReport.ts
|
|
11041
11645
|
function generateVisualReport(options) {
|
|
11042
|
-
const {
|
|
11043
|
-
reports,
|
|
11044
|
-
title = "AI Readiness Report",
|
|
11045
|
-
generatedAt = (/* @__PURE__ */ new Date()).toISOString()
|
|
11046
|
-
} = options;
|
|
11646
|
+
const { reports, title = "Readiness Report", generatedAt = (/* @__PURE__ */ new Date()).toISOString() } = options;
|
|
11047
11647
|
const successfulReports = reports.filter((r) => !r.error);
|
|
11048
11648
|
const failedReports = reports.filter((r) => r.error);
|
|
11049
11649
|
const totalRepos = reports.length;
|
|
@@ -11612,7 +12212,7 @@ function generateVisualReport(options) {
|
|
|
11612
12212
|
` : ""}
|
|
11613
12213
|
|
|
11614
12214
|
<div class="footer">
|
|
11615
|
-
<p>Generated with <a href="https://github.com/microsoft/agentrc">AgentRC</a> ·
|
|
12215
|
+
<p>Generated with <a href="https://github.com/microsoft/agentrc">AgentRC</a> · Readiness Tool</p>
|
|
11616
12216
|
</div>
|
|
11617
12217
|
</div>
|
|
11618
12218
|
<script>
|
|
@@ -12065,7 +12665,7 @@ function BatchReadinessTui({ token, outputPath, policies }) {
|
|
|
12065
12665
|
setStatus("processing");
|
|
12066
12666
|
const selectedRepos = Array.from(selectedRepoIndices).map((i) => repos[i]);
|
|
12067
12667
|
const results2 = [];
|
|
12068
|
-
const tmpDir =
|
|
12668
|
+
const tmpDir = path14.join(os.tmpdir(), `agentrc-batch-readiness-${Date.now()}`);
|
|
12069
12669
|
try {
|
|
12070
12670
|
await ensureDir(tmpDir);
|
|
12071
12671
|
for (let i = 0; i < selectedRepos.length; i++) {
|
|
@@ -12099,10 +12699,10 @@ function BatchReadinessTui({ token, outputPath, policies }) {
|
|
|
12099
12699
|
},
|
|
12100
12700
|
error: r.error
|
|
12101
12701
|
})),
|
|
12102
|
-
title: "Batch
|
|
12702
|
+
title: "Batch Readiness Report",
|
|
12103
12703
|
generatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
12104
12704
|
});
|
|
12105
|
-
const finalOutputPath = outputPath ??
|
|
12705
|
+
const finalOutputPath = outputPath ?? path14.join(process.cwd(), "batch-readiness-report.html");
|
|
12106
12706
|
const { wrote, reason } = await safeWriteFile(finalOutputPath, html, true);
|
|
12107
12707
|
if (!wrote) throw new Error(reason === "symlink" ? "Path is a symlink" : "Write failed");
|
|
12108
12708
|
setStatus("complete");
|
|
@@ -12284,7 +12884,7 @@ async function batchReadinessCommand(options) {
|
|
|
12284
12884
|
}
|
|
12285
12885
|
|
|
12286
12886
|
// src/commands/eval.ts
|
|
12287
|
-
import
|
|
12887
|
+
import path16 from "path";
|
|
12288
12888
|
|
|
12289
12889
|
// packages/core/src/services/evalScaffold.ts
|
|
12290
12890
|
var EVAL_SCAFFOLD_TIMEOUT_MS = 6e5;
|
|
@@ -12306,7 +12906,7 @@ async function generateEvalScaffold(options) {
|
|
|
12306
12906
|
streaming: true,
|
|
12307
12907
|
workingDirectory: repoPath,
|
|
12308
12908
|
systemMessage: {
|
|
12309
|
-
content: "
|
|
12909
|
+
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})."
|
|
12310
12910
|
},
|
|
12311
12911
|
infiniteSessions: { enabled: false }
|
|
12312
12912
|
});
|
|
@@ -12348,32 +12948,37 @@ async function generateEvalScaffold(options) {
|
|
|
12348
12948
|
'For areas with a workspace (workingDirectory), include a "workingDirectory" field set to that workspace path so evals run scoped to the correct folder.'
|
|
12349
12949
|
].join("\n") : "";
|
|
12350
12950
|
const prompt = [
|
|
12351
|
-
`Analyze this repository and generate ${count}
|
|
12951
|
+
`Analyze this repository and generate ${count} implementation planning tasks.`,
|
|
12952
|
+
"",
|
|
12953
|
+
"Each task should represent a REAL developer request \u2014 the kind of thing someone would actually type into a coding agent.",
|
|
12954
|
+
"Tasks should require understanding MULTIPLE files and cross-cutting concerns.",
|
|
12352
12955
|
"",
|
|
12353
|
-
"
|
|
12354
|
-
"
|
|
12355
|
-
"Do NOT
|
|
12956
|
+
"PROMPT RULES (the prompt field is what the eval agent receives):",
|
|
12957
|
+
"- Write prompts as a developer would naturally phrase them \u2014 short, direct requests.",
|
|
12958
|
+
"- Do NOT describe expected output format or what the response should include.",
|
|
12959
|
+
"- Do NOT add meta-instructions like 'The output should show...' or 'Include in your plan...' or 'Your plan should cover...'",
|
|
12960
|
+
"- Do NOT embed implementation details in the prompt (pillar names, levels, specific output formats) \u2014 those belong in the expectation.",
|
|
12961
|
+
"- Good: 'Add a --dry-run flag to the generate command'",
|
|
12962
|
+
"- Good: 'Add a readiness criterion for CI/CD detection'",
|
|
12963
|
+
"- 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.'",
|
|
12964
|
+
"- Bad: 'Add a readiness criterion that checks for CI/CD and classifies it under a new deployment pillar at level 3'",
|
|
12356
12965
|
"",
|
|
12357
|
-
"
|
|
12358
|
-
"-
|
|
12359
|
-
"-
|
|
12360
|
-
"-
|
|
12361
|
-
"-
|
|
12362
|
-
"-
|
|
12363
|
-
"- Questions that require understanding the type system, generics, or shared interfaces across module boundaries",
|
|
12966
|
+
"EXPECTATION RULES (the expectation field is checked by an LLM judge \u2014 be extremely specific):",
|
|
12967
|
+
"- MUST cite exact file paths (e.g., 'packages/core/src/services/generator.ts')",
|
|
12968
|
+
"- MUST cite exact function and type names (e.g., 'generateCopilotInstructions()', 'CommandResult<T>')",
|
|
12969
|
+
"- MUST cite specific CLI commands for verification (e.g., 'npm run typecheck', 'npm test')",
|
|
12970
|
+
"- MUST name the specific test file to update (e.g., 'src/services/__tests__/generator.test.ts')",
|
|
12971
|
+
"- Generic expectations like 'identify the generator service' are USELESS \u2014 name the actual function and file.",
|
|
12364
12972
|
"",
|
|
12365
|
-
"Bad
|
|
12366
|
-
"- 'What does this project do?' (
|
|
12367
|
-
"- '
|
|
12368
|
-
"-
|
|
12369
|
-
"- Any question answerable by reading one file or searching for one keyword",
|
|
12973
|
+
"Bad task examples (avoid these):",
|
|
12974
|
+
"- 'What does this project do?' (pure Q&A, not a planning task)",
|
|
12975
|
+
"- 'Explain the architecture' (no implementation expected)",
|
|
12976
|
+
"- Tasks with prescriptive output instructions baked into the prompt",
|
|
12370
12977
|
"",
|
|
12371
|
-
"
|
|
12372
|
-
"If this is a monorepo
|
|
12373
|
-
"Ensure cases cover cross-cutting concerns: data flow, error propagation, configuration impact, implicit coupling, architectural invariants.",
|
|
12374
|
-
"Include a systemMessage that keeps answers scoped to this repository (avoid generic Copilot CLI details unless asked).",
|
|
12978
|
+
"Do NOT generate a systemMessage \u2014 the default is used automatically.",
|
|
12979
|
+
"If this is a monorepo, generate tasks that involve cross-app dependencies and shared libraries.",
|
|
12375
12980
|
"Return JSON ONLY (no markdown, no commentary) in this schema:",
|
|
12376
|
-
'{\n "instructionFile": ".github/copilot-instructions.md",\n "
|
|
12981
|
+
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}',
|
|
12377
12982
|
areaContext
|
|
12378
12983
|
].join("\n");
|
|
12379
12984
|
progress("Analyzing codebase...");
|
|
@@ -12419,7 +13024,8 @@ async function generateEvalScaffold(options) {
|
|
|
12419
13024
|
}
|
|
12420
13025
|
throw error;
|
|
12421
13026
|
}
|
|
12422
|
-
const
|
|
13027
|
+
const hasAreas = Boolean(options.areas?.length);
|
|
13028
|
+
const normalized = normalizeEvalConfig(parsed, count, hasAreas);
|
|
12423
13029
|
return normalized;
|
|
12424
13030
|
} finally {
|
|
12425
13031
|
await client.stop();
|
|
@@ -12443,41 +13049,47 @@ function parseEvalConfig(raw) {
|
|
|
12443
13049
|
}
|
|
12444
13050
|
return parsed;
|
|
12445
13051
|
}
|
|
12446
|
-
function normalizeEvalConfig(parsed, count) {
|
|
13052
|
+
function normalizeEvalConfig(parsed, count, hasAreas = true) {
|
|
12447
13053
|
const cases = (parsed.cases ?? []).slice(0, count).map((entry, index) => {
|
|
12448
13054
|
const id = typeof entry.id === "string" && entry.id.trim() ? entry.id : `case-${index + 1}`;
|
|
12449
13055
|
return {
|
|
12450
13056
|
id,
|
|
12451
13057
|
prompt: String(entry.prompt ?? "").trim(),
|
|
12452
|
-
expectation:
|
|
12453
|
-
|
|
13058
|
+
expectation: normalizeExpectation(entry.expectation),
|
|
13059
|
+
...hasAreas && typeof entry.area === "string" && entry.area.trim() ? { area: entry.area.trim() } : {},
|
|
12454
13060
|
workingDirectory: typeof entry.workingDirectory === "string" && entry.workingDirectory.trim() ? entry.workingDirectory.trim() : void 0
|
|
12455
13061
|
};
|
|
12456
13062
|
});
|
|
12457
13063
|
if (!cases.length) {
|
|
12458
13064
|
throw new Error("Eval scaffold JSON did not include any usable cases.");
|
|
12459
13065
|
}
|
|
12460
|
-
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.";
|
|
12461
13066
|
return {
|
|
12462
13067
|
instructionFile: parsed.instructionFile ?? ".github/copilot-instructions.md",
|
|
12463
|
-
systemMessage: parsed.systemMessage
|
|
13068
|
+
...parsed.systemMessage ? { systemMessage: parsed.systemMessage } : {},
|
|
12464
13069
|
cases
|
|
12465
13070
|
};
|
|
12466
13071
|
}
|
|
13072
|
+
function normalizeExpectation(value) {
|
|
13073
|
+
if (Array.isArray(value)) {
|
|
13074
|
+
const items = value.map((s) => String(s).trim()).filter(Boolean);
|
|
13075
|
+
return items.length === 1 ? items[0] : items;
|
|
13076
|
+
}
|
|
13077
|
+
return String(value ?? "").trim();
|
|
13078
|
+
}
|
|
12467
13079
|
|
|
12468
13080
|
// packages/core/src/services/evaluator.ts
|
|
12469
13081
|
import fs9 from "fs/promises";
|
|
12470
|
-
import
|
|
12471
|
-
var DEFAULT_SYSTEM_MESSAGE = "
|
|
13082
|
+
import path15 from "path";
|
|
13083
|
+
var DEFAULT_SYSTEM_MESSAGE = "Research using read-only tools and make a plan for the given task, including concrete implementation steps and verification steps.";
|
|
12472
13084
|
async function runEval(options) {
|
|
12473
13085
|
const config = await loadConfig(options.configPath);
|
|
12474
13086
|
const instructionFile = config.instructionFile ?? ".github/copilot-instructions.md";
|
|
12475
|
-
const instructionPath =
|
|
13087
|
+
const instructionPath = path15.resolve(options.repoPath, instructionFile);
|
|
12476
13088
|
const instructionText = await readOptionalFile(instructionPath);
|
|
12477
13089
|
const baseSystemMessage = config.systemMessage ?? DEFAULT_SYSTEM_MESSAGE;
|
|
12478
13090
|
const progress = options.onProgress ?? (() => {
|
|
12479
13091
|
});
|
|
12480
|
-
const defaultOutputPath =
|
|
13092
|
+
const defaultOutputPath = path15.resolve(
|
|
12481
13093
|
options.repoPath,
|
|
12482
13094
|
".agentrc",
|
|
12483
13095
|
"evals",
|
|
@@ -12497,9 +13109,9 @@ async function runEval(options) {
|
|
|
12497
13109
|
const caseStartedAt = Date.now();
|
|
12498
13110
|
let caseWorkingDir;
|
|
12499
13111
|
if (testCase.workingDirectory) {
|
|
12500
|
-
const resolved =
|
|
12501
|
-
const root =
|
|
12502
|
-
if (resolved !== root && !resolved.startsWith(root +
|
|
13112
|
+
const resolved = path15.resolve(options.repoPath, testCase.workingDirectory);
|
|
13113
|
+
const root = path15.resolve(options.repoPath);
|
|
13114
|
+
if (resolved !== root && !resolved.startsWith(root + path15.sep)) {
|
|
12503
13115
|
throw new Error(
|
|
12504
13116
|
`Invalid workingDirectory "${testCase.workingDirectory}": escapes repo boundary`
|
|
12505
13117
|
);
|
|
@@ -12571,7 +13183,7 @@ async function runEval(options) {
|
|
|
12571
13183
|
};
|
|
12572
13184
|
let viewerPath;
|
|
12573
13185
|
if (outputPath) {
|
|
12574
|
-
await fs9.mkdir(
|
|
13186
|
+
await fs9.mkdir(path15.dirname(outputPath), { recursive: true });
|
|
12575
13187
|
await safeWriteFile(outputPath, JSON.stringify(output, null, 2), true);
|
|
12576
13188
|
viewerPath = buildViewerPath(outputPath);
|
|
12577
13189
|
await safeWriteFile(viewerPath, buildTrajectoryViewerHtml(output), true);
|
|
@@ -12632,10 +13244,11 @@ async function judge(client, options) {
|
|
|
12632
13244
|
if (delta) content += delta;
|
|
12633
13245
|
}
|
|
12634
13246
|
});
|
|
13247
|
+
const expectationText = Array.isArray(options.expectation) ? options.expectation.join("\n") : options.expectation;
|
|
12635
13248
|
const prompt = [
|
|
12636
13249
|
"Evaluate which response best matches the expectation.",
|
|
12637
13250
|
"",
|
|
12638
|
-
`Expectation: ${
|
|
13251
|
+
`Expectation: ${expectationText}`,
|
|
12639
13252
|
"",
|
|
12640
13253
|
"Response A (without custom instructions):",
|
|
12641
13254
|
options.withoutInstructions,
|
|
@@ -12679,7 +13292,7 @@ function parseJudge(content) {
|
|
|
12679
13292
|
}
|
|
12680
13293
|
async function loadConfig(configPath) {
|
|
12681
13294
|
const raw = await fs9.readFile(configPath, "utf8");
|
|
12682
|
-
const parsed = JSON.parse(raw);
|
|
13295
|
+
const parsed = JSON.parse(stripJsonComments(raw));
|
|
12683
13296
|
if (!parsed || !Array.isArray(parsed.cases)) {
|
|
12684
13297
|
throw new Error("Eval config must have a 'cases' array.");
|
|
12685
13298
|
}
|
|
@@ -12885,7 +13498,7 @@ function formatTokenUsage(usage) {
|
|
|
12885
13498
|
function resolveOutputPath(repoPath, override, configValue) {
|
|
12886
13499
|
const chosen = override ?? configValue;
|
|
12887
13500
|
if (!chosen) return void 0;
|
|
12888
|
-
return
|
|
13501
|
+
return path15.isAbsolute(chosen) ? chosen : path15.resolve(repoPath, chosen);
|
|
12889
13502
|
}
|
|
12890
13503
|
function buildViewerPath(outputPath) {
|
|
12891
13504
|
if (outputPath.endsWith(".json")) {
|
|
@@ -13240,7 +13853,7 @@ function sanitizeValue(value, depth) {
|
|
|
13240
13853
|
|
|
13241
13854
|
// src/commands/eval.ts
|
|
13242
13855
|
async function evalCommand(configPathArg, options) {
|
|
13243
|
-
const repoPath =
|
|
13856
|
+
const repoPath = path16.resolve(options.repo ?? process.cwd());
|
|
13244
13857
|
if (options.listModels) {
|
|
13245
13858
|
try {
|
|
13246
13859
|
const models = await listCopilotModels();
|
|
@@ -13276,7 +13889,7 @@ async function evalCommand(configPathArg, options) {
|
|
|
13276
13889
|
return;
|
|
13277
13890
|
}
|
|
13278
13891
|
if (options.init) {
|
|
13279
|
-
const outputPath =
|
|
13892
|
+
const outputPath = path16.join(repoPath, "agentrc.eval.json");
|
|
13280
13893
|
const desiredCount = Math.max(1, Number.parseInt(options.count ?? "5", 10) || 5);
|
|
13281
13894
|
try {
|
|
13282
13895
|
const progress = createProgressReporter(!shouldLog(options));
|
|
@@ -13318,7 +13931,7 @@ async function evalCommand(configPathArg, options) {
|
|
|
13318
13931
|
}
|
|
13319
13932
|
return;
|
|
13320
13933
|
}
|
|
13321
|
-
const configPath =
|
|
13934
|
+
const configPath = path16.resolve(configPathArg ?? path16.join(repoPath, "agentrc.eval.json"));
|
|
13322
13935
|
try {
|
|
13323
13936
|
const progress = createProgressReporter(!shouldLog(options));
|
|
13324
13937
|
const { summary, results, viewerPath } = await runEval({
|
|
@@ -13365,32 +13978,43 @@ async function evalCommand(configPathArg, options) {
|
|
|
13365
13978
|
}
|
|
13366
13979
|
|
|
13367
13980
|
// src/commands/generate.ts
|
|
13368
|
-
import
|
|
13981
|
+
import path19 from "path";
|
|
13369
13982
|
|
|
13370
13983
|
// packages/core/src/services/generator.ts
|
|
13371
|
-
import
|
|
13984
|
+
import path17 from "path";
|
|
13985
|
+
async function writeOrPreview(filePath, content, opts) {
|
|
13986
|
+
const relPath = path17.relative(process.cwd(), filePath);
|
|
13987
|
+
if (opts.dryRun) {
|
|
13988
|
+
const wouldWrite = await canSafeWrite(filePath, opts.force);
|
|
13989
|
+
return {
|
|
13990
|
+
path: relPath,
|
|
13991
|
+
action: wouldWrite ? "wrote" : "skipped",
|
|
13992
|
+
bytes: Buffer.byteLength(content, "utf8")
|
|
13993
|
+
};
|
|
13994
|
+
}
|
|
13995
|
+
await ensureDir(path17.dirname(filePath));
|
|
13996
|
+
const { wrote } = await safeWriteFile(filePath, content, opts.force);
|
|
13997
|
+
return { path: relPath, action: wrote ? "wrote" : "skipped" };
|
|
13998
|
+
}
|
|
13372
13999
|
async function generateConfigs(options) {
|
|
13373
|
-
const { repoPath, analysis, selections, force } = options;
|
|
14000
|
+
const { repoPath, analysis, selections, force, dryRun } = options;
|
|
13374
14001
|
const files = [];
|
|
13375
14002
|
if (selections.includes("mcp")) {
|
|
13376
|
-
|
|
13377
|
-
|
|
13378
|
-
|
|
13379
|
-
|
|
13380
|
-
|
|
13381
|
-
|
|
13382
|
-
action: wrote ? "wrote" : "skipped"
|
|
13383
|
-
});
|
|
14003
|
+
files.push(
|
|
14004
|
+
await writeOrPreview(path17.join(repoPath, ".vscode", "mcp.json"), renderMcp(), {
|
|
14005
|
+
dryRun,
|
|
14006
|
+
force
|
|
14007
|
+
})
|
|
14008
|
+
);
|
|
13384
14009
|
}
|
|
13385
14010
|
if (selections.includes("vscode")) {
|
|
13386
|
-
|
|
13387
|
-
|
|
13388
|
-
|
|
13389
|
-
|
|
13390
|
-
|
|
13391
|
-
|
|
13392
|
-
|
|
13393
|
-
});
|
|
14011
|
+
files.push(
|
|
14012
|
+
await writeOrPreview(
|
|
14013
|
+
path17.join(repoPath, ".vscode", "settings.json"),
|
|
14014
|
+
renderVscodeSettings(analysis),
|
|
14015
|
+
{ dryRun, force }
|
|
14016
|
+
)
|
|
14017
|
+
);
|
|
13394
14018
|
}
|
|
13395
14019
|
return { files };
|
|
13396
14020
|
}
|
|
@@ -13439,16 +14063,16 @@ function renderVscodeSettings(analysis) {
|
|
|
13439
14063
|
}
|
|
13440
14064
|
|
|
13441
14065
|
// src/commands/instructions.ts
|
|
13442
|
-
import
|
|
14066
|
+
import path18 from "path";
|
|
13443
14067
|
function skipReason(action) {
|
|
13444
14068
|
if (action === "symlink") return "symlink";
|
|
13445
14069
|
if (action === "empty") return "empty content";
|
|
13446
14070
|
return "exists, use --force";
|
|
13447
14071
|
}
|
|
13448
14072
|
async function instructionsCommand(options) {
|
|
13449
|
-
const repoPath =
|
|
13450
|
-
const outputPath =
|
|
13451
|
-
options.output ??
|
|
14073
|
+
const repoPath = path18.resolve(options.repo ?? process.cwd());
|
|
14074
|
+
const outputPath = path18.resolve(
|
|
14075
|
+
options.output ?? path18.join(repoPath, ".github", "copilot-instructions.md")
|
|
13452
14076
|
);
|
|
13453
14077
|
const progress = createProgressReporter(!shouldLog(options));
|
|
13454
14078
|
const wantAreas = options.areas || options.areasOnly || options.area;
|
|
@@ -13471,6 +14095,7 @@ async function instructionsCommand(options) {
|
|
|
13471
14095
|
return;
|
|
13472
14096
|
}
|
|
13473
14097
|
try {
|
|
14098
|
+
const dryRunFiles = [];
|
|
13474
14099
|
if (!options.areasOnly && !options.area) {
|
|
13475
14100
|
if (strategy === "nested") {
|
|
13476
14101
|
try {
|
|
@@ -13482,25 +14107,57 @@ async function instructionsCommand(options) {
|
|
|
13482
14107
|
detailDir,
|
|
13483
14108
|
claudeMd
|
|
13484
14109
|
});
|
|
13485
|
-
|
|
13486
|
-
|
|
13487
|
-
|
|
13488
|
-
|
|
13489
|
-
|
|
13490
|
-
|
|
13491
|
-
|
|
14110
|
+
if (options.dryRun) {
|
|
14111
|
+
const dryFiles = [
|
|
14112
|
+
{ path: nestedResult.hub.relativePath, content: nestedResult.hub.content },
|
|
14113
|
+
...nestedResult.details.map((d) => ({ path: d.relativePath, content: d.content })),
|
|
14114
|
+
...nestedResult.claudeMd ? [
|
|
14115
|
+
{
|
|
14116
|
+
path: nestedResult.claudeMd.relativePath,
|
|
14117
|
+
content: nestedResult.claudeMd.content
|
|
14118
|
+
}
|
|
14119
|
+
] : []
|
|
14120
|
+
];
|
|
14121
|
+
for (const file of dryFiles) {
|
|
14122
|
+
const relPath = path18.relative(process.cwd(), path18.join(repoPath, file.path));
|
|
14123
|
+
if (shouldLog(options)) {
|
|
14124
|
+
progress.update(
|
|
14125
|
+
`[dry-run] Would write ${relPath} (${Buffer.byteLength(file.content, "utf8")} bytes)`
|
|
14126
|
+
);
|
|
14127
|
+
}
|
|
14128
|
+
}
|
|
14129
|
+
if (options.json) {
|
|
14130
|
+
dryRunFiles.push(
|
|
14131
|
+
...dryFiles.map((f) => ({
|
|
14132
|
+
path: f.path,
|
|
14133
|
+
bytes: Buffer.byteLength(f.content, "utf8")
|
|
14134
|
+
}))
|
|
14135
|
+
);
|
|
14136
|
+
}
|
|
14137
|
+
for (const warning of nestedResult.warnings) {
|
|
14138
|
+
if (shouldLog(options)) progress.update(`Warning: ${warning}`);
|
|
14139
|
+
}
|
|
14140
|
+
} else {
|
|
14141
|
+
const actions = await writeNestedInstructions(repoPath, nestedResult, options.force);
|
|
14142
|
+
for (const action of actions) {
|
|
14143
|
+
const relPath = path18.relative(process.cwd(), action.path);
|
|
14144
|
+
if (action.action === "wrote") {
|
|
14145
|
+
if (shouldLog(options)) progress.succeed(`Wrote ${relPath}`);
|
|
14146
|
+
} else if (shouldLog(options)) {
|
|
14147
|
+
progress.update(`Skipped ${relPath} (${skipReason(action.action)})`);
|
|
14148
|
+
}
|
|
14149
|
+
}
|
|
14150
|
+
for (const warning of nestedResult.warnings) {
|
|
14151
|
+
if (shouldLog(options)) progress.update(`Warning: ${warning}`);
|
|
14152
|
+
}
|
|
14153
|
+
if (options.json) {
|
|
14154
|
+
const result = {
|
|
14155
|
+
ok: true,
|
|
14156
|
+
status: "success",
|
|
14157
|
+
data: { files: actions }
|
|
14158
|
+
};
|
|
14159
|
+
outputResult(result, true);
|
|
13492
14160
|
}
|
|
13493
|
-
}
|
|
13494
|
-
for (const warning of nestedResult.warnings) {
|
|
13495
|
-
if (shouldLog(options)) progress.update(`Warning: ${warning}`);
|
|
13496
|
-
}
|
|
13497
|
-
if (options.json) {
|
|
13498
|
-
const result = {
|
|
13499
|
-
ok: true,
|
|
13500
|
-
status: "success",
|
|
13501
|
-
data: { files: actions }
|
|
13502
|
-
};
|
|
13503
|
-
outputResult(result, true);
|
|
13504
14161
|
}
|
|
13505
14162
|
} catch (error) {
|
|
13506
14163
|
const msg = "Failed to generate nested instructions. " + (error instanceof Error ? error.message : String(error));
|
|
@@ -13525,36 +14182,48 @@ async function instructionsCommand(options) {
|
|
|
13525
14182
|
return;
|
|
13526
14183
|
}
|
|
13527
14184
|
if (content) {
|
|
13528
|
-
|
|
13529
|
-
|
|
13530
|
-
outputPath
|
|
13531
|
-
content,
|
|
13532
|
-
|
|
13533
|
-
|
|
13534
|
-
|
|
13535
|
-
const relPath = path14.relative(process.cwd(), outputPath);
|
|
13536
|
-
const why = reason === "symlink" ? "path is a symlink" : "file exists (use --force)";
|
|
14185
|
+
if (options.dryRun) {
|
|
14186
|
+
const relPath = path18.relative(repoPath, outputPath);
|
|
14187
|
+
const displayPath = path18.relative(process.cwd(), outputPath);
|
|
14188
|
+
const byteCount = Buffer.byteLength(content, "utf8");
|
|
14189
|
+
if (shouldLog(options)) {
|
|
14190
|
+
progress.update(`[dry-run] Would write ${displayPath} (${byteCount} bytes)`);
|
|
14191
|
+
}
|
|
13537
14192
|
if (options.json) {
|
|
13538
|
-
|
|
13539
|
-
ok: true,
|
|
13540
|
-
status: "noop",
|
|
13541
|
-
data: { outputPath, skipped: true, reason: why }
|
|
13542
|
-
};
|
|
13543
|
-
outputResult(result, true);
|
|
13544
|
-
} else if (shouldLog(options)) {
|
|
13545
|
-
progress.update(`Skipped ${relPath}: ${why}`);
|
|
14193
|
+
dryRunFiles.push({ path: relPath, bytes: byteCount });
|
|
13546
14194
|
}
|
|
13547
14195
|
} else {
|
|
13548
|
-
|
|
13549
|
-
|
|
13550
|
-
|
|
13551
|
-
|
|
13552
|
-
|
|
13553
|
-
|
|
13554
|
-
|
|
13555
|
-
|
|
13556
|
-
|
|
13557
|
-
|
|
14196
|
+
await ensureDir(path18.dirname(outputPath));
|
|
14197
|
+
const { wrote, reason } = await safeWriteFile(
|
|
14198
|
+
outputPath,
|
|
14199
|
+
content,
|
|
14200
|
+
Boolean(options.force)
|
|
14201
|
+
);
|
|
14202
|
+
if (!wrote) {
|
|
14203
|
+
const relPath = path18.relative(process.cwd(), outputPath);
|
|
14204
|
+
const why = reason === "symlink" ? "path is a symlink" : "file exists (use --force)";
|
|
14205
|
+
if (options.json) {
|
|
14206
|
+
const result = {
|
|
14207
|
+
ok: true,
|
|
14208
|
+
status: "noop",
|
|
14209
|
+
data: { outputPath, skipped: true, reason: why }
|
|
14210
|
+
};
|
|
14211
|
+
outputResult(result, true);
|
|
14212
|
+
} else if (shouldLog(options)) {
|
|
14213
|
+
progress.update(`Skipped ${relPath}: ${why}`);
|
|
14214
|
+
}
|
|
14215
|
+
} else {
|
|
14216
|
+
const byteCount = Buffer.byteLength(content, "utf8");
|
|
14217
|
+
if (options.json) {
|
|
14218
|
+
const result = {
|
|
14219
|
+
ok: true,
|
|
14220
|
+
status: "success",
|
|
14221
|
+
data: { outputPath, model: options.model ?? "default", byteCount }
|
|
14222
|
+
};
|
|
14223
|
+
outputResult(result, true);
|
|
14224
|
+
} else if (shouldLog(options)) {
|
|
14225
|
+
progress.succeed(`Updated ${path18.relative(process.cwd(), outputPath)}`);
|
|
14226
|
+
}
|
|
13558
14227
|
}
|
|
13559
14228
|
}
|
|
13560
14229
|
}
|
|
@@ -13588,7 +14257,7 @@ async function instructionsCommand(options) {
|
|
|
13588
14257
|
return;
|
|
13589
14258
|
}
|
|
13590
14259
|
if (shouldLog(options)) {
|
|
13591
|
-
progress.update(`Generating
|
|
14260
|
+
progress.update(`Generating instructions for ${targetAreas.length} area(s)...`);
|
|
13592
14261
|
}
|
|
13593
14262
|
for (const area of targetAreas) {
|
|
13594
14263
|
try {
|
|
@@ -13608,17 +14277,46 @@ async function instructionsCommand(options) {
|
|
|
13608
14277
|
detailDir,
|
|
13609
14278
|
claudeMd
|
|
13610
14279
|
});
|
|
13611
|
-
|
|
13612
|
-
|
|
13613
|
-
|
|
13614
|
-
|
|
13615
|
-
|
|
13616
|
-
|
|
13617
|
-
|
|
14280
|
+
if (options.dryRun) {
|
|
14281
|
+
const dryFiles = [
|
|
14282
|
+
{ path: nestedResult.hub.relativePath, content: nestedResult.hub.content },
|
|
14283
|
+
...nestedResult.details.map((d) => ({ path: d.relativePath, content: d.content })),
|
|
14284
|
+
...nestedResult.claudeMd ? [
|
|
14285
|
+
{
|
|
14286
|
+
path: nestedResult.claudeMd.relativePath,
|
|
14287
|
+
content: nestedResult.claudeMd.content
|
|
14288
|
+
}
|
|
14289
|
+
] : []
|
|
14290
|
+
];
|
|
14291
|
+
for (const file of dryFiles) {
|
|
14292
|
+
const relPath = path18.relative(process.cwd(), path18.join(repoPath, file.path));
|
|
14293
|
+
if (shouldLog(options)) {
|
|
14294
|
+
progress.update(
|
|
14295
|
+
`[dry-run] Would write ${relPath} (${Buffer.byteLength(file.content, "utf8")} bytes)`
|
|
14296
|
+
);
|
|
14297
|
+
}
|
|
14298
|
+
}
|
|
14299
|
+
if (options.json) {
|
|
14300
|
+
dryRunFiles.push(
|
|
14301
|
+
...dryFiles.map((f) => ({
|
|
14302
|
+
path: f.path,
|
|
14303
|
+
bytes: Buffer.byteLength(f.content, "utf8")
|
|
14304
|
+
}))
|
|
14305
|
+
);
|
|
14306
|
+
}
|
|
14307
|
+
} else {
|
|
14308
|
+
const actions = await writeNestedInstructions(repoPath, nestedResult, options.force);
|
|
14309
|
+
for (const action of actions) {
|
|
14310
|
+
const relPath = path18.relative(process.cwd(), action.path);
|
|
14311
|
+
if (action.action === "wrote") {
|
|
14312
|
+
if (shouldLog(options)) progress.succeed(`Wrote ${relPath}`);
|
|
14313
|
+
} else if (shouldLog(options)) {
|
|
14314
|
+
progress.update(`Skipped ${relPath} (${skipReason(action.action)})`);
|
|
14315
|
+
}
|
|
14316
|
+
}
|
|
14317
|
+
for (const warning of nestedResult.warnings) {
|
|
14318
|
+
if (shouldLog(options)) progress.update(`Warning: ${warning}`);
|
|
13618
14319
|
}
|
|
13619
|
-
}
|
|
13620
|
-
for (const warning of nestedResult.warnings) {
|
|
13621
|
-
if (shouldLog(options)) progress.update(`Warning: ${warning}`);
|
|
13622
14320
|
}
|
|
13623
14321
|
} else {
|
|
13624
14322
|
const body = await generateAreaInstructions({
|
|
@@ -13633,21 +14331,37 @@ async function instructionsCommand(options) {
|
|
|
13633
14331
|
}
|
|
13634
14332
|
continue;
|
|
13635
14333
|
}
|
|
13636
|
-
|
|
13637
|
-
if (result.status === "skipped") {
|
|
14334
|
+
if (options.dryRun) {
|
|
13638
14335
|
if (shouldLog(options)) {
|
|
13639
|
-
progress.update(
|
|
14336
|
+
progress.update(
|
|
14337
|
+
`[dry-run] Would write area "${area.name}" (${Buffer.byteLength(body, "utf8")} bytes)`
|
|
14338
|
+
);
|
|
14339
|
+
}
|
|
14340
|
+
if (options.json) {
|
|
14341
|
+
dryRunFiles.push({
|
|
14342
|
+
path: path18.relative(repoPath, areaInstructionPath(repoPath, area)),
|
|
14343
|
+
bytes: Buffer.byteLength(body, "utf8")
|
|
14344
|
+
});
|
|
14345
|
+
}
|
|
14346
|
+
} else {
|
|
14347
|
+
const result = await writeAreaInstruction(repoPath, area, body, options.force);
|
|
14348
|
+
if (result.status === "skipped") {
|
|
14349
|
+
if (shouldLog(options)) {
|
|
14350
|
+
progress.update(
|
|
14351
|
+
`Skipped "${area.name}" \u2014 file exists (use --force to overwrite).`
|
|
14352
|
+
);
|
|
14353
|
+
}
|
|
14354
|
+
continue;
|
|
14355
|
+
}
|
|
14356
|
+
if (result.status === "symlink") {
|
|
14357
|
+
if (shouldLog(options)) {
|
|
14358
|
+
progress.update(`Skipped "${area.name}" \u2014 path is a symlink.`);
|
|
14359
|
+
}
|
|
14360
|
+
continue;
|
|
13640
14361
|
}
|
|
13641
|
-
continue;
|
|
13642
|
-
}
|
|
13643
|
-
if (result.status === "symlink") {
|
|
13644
14362
|
if (shouldLog(options)) {
|
|
13645
|
-
progress.
|
|
14363
|
+
progress.succeed(`Wrote ${path18.relative(process.cwd(), result.filePath)}`);
|
|
13646
14364
|
}
|
|
13647
|
-
continue;
|
|
13648
|
-
}
|
|
13649
|
-
if (shouldLog(options)) {
|
|
13650
|
-
progress.succeed(`Wrote ${path14.relative(process.cwd(), result.filePath)}`);
|
|
13651
14365
|
}
|
|
13652
14366
|
}
|
|
13653
14367
|
} catch (error) {
|
|
@@ -13659,6 +14373,12 @@ async function instructionsCommand(options) {
|
|
|
13659
14373
|
}
|
|
13660
14374
|
}
|
|
13661
14375
|
}
|
|
14376
|
+
if (options.dryRun && options.json) {
|
|
14377
|
+
outputResult(
|
|
14378
|
+
{ ok: true, status: "noop", data: { dryRun: true, files: dryRunFiles } },
|
|
14379
|
+
true
|
|
14380
|
+
);
|
|
14381
|
+
}
|
|
13662
14382
|
if (!wantAreas && shouldLog(options) && !options.json) {
|
|
13663
14383
|
process.stderr.write("\nNext steps:\n");
|
|
13664
14384
|
process.stderr.write(" agentrc eval --init Scaffold evaluation test cases\n");
|
|
@@ -13675,9 +14395,21 @@ async function instructionsCommand(options) {
|
|
|
13675
14395
|
|
|
13676
14396
|
// src/commands/generate.ts
|
|
13677
14397
|
async function generateCommand(type, repoPathArg, options) {
|
|
13678
|
-
const repoPath =
|
|
14398
|
+
const repoPath = path19.resolve(repoPathArg ?? process.cwd());
|
|
13679
14399
|
if (type === "instructions" || type === "agents") {
|
|
13680
|
-
|
|
14400
|
+
if (!options.quiet) {
|
|
14401
|
+
process.stderr.write(
|
|
14402
|
+
`\u26A0 \`generate ${type}\` is deprecated \u2014 use \`agentrc instructions\` directly.
|
|
14403
|
+
`
|
|
14404
|
+
);
|
|
14405
|
+
}
|
|
14406
|
+
if (options.perApp && !options.quiet) {
|
|
14407
|
+
process.stderr.write(
|
|
14408
|
+
`\u26A0 --per-app is deprecated \u2014 use \`agentrc instructions --areas\` instead.
|
|
14409
|
+
`
|
|
14410
|
+
);
|
|
14411
|
+
}
|
|
14412
|
+
const output = type === "agents" ? path19.join(repoPath, "AGENTS.md") : void 0;
|
|
13681
14413
|
await instructionsCommand({
|
|
13682
14414
|
repo: repoPath,
|
|
13683
14415
|
output,
|
|
@@ -13686,7 +14418,8 @@ async function generateCommand(type, repoPathArg, options) {
|
|
|
13686
14418
|
json: options.json,
|
|
13687
14419
|
quiet: options.quiet,
|
|
13688
14420
|
areas: options.perApp,
|
|
13689
|
-
strategy: options.strategy
|
|
14421
|
+
strategy: options.strategy,
|
|
14422
|
+
dryRun: options.dryRun
|
|
13690
14423
|
});
|
|
13691
14424
|
return;
|
|
13692
14425
|
}
|
|
@@ -13707,7 +14440,8 @@ async function generateCommand(type, repoPathArg, options) {
|
|
|
13707
14440
|
repoPath,
|
|
13708
14441
|
analysis,
|
|
13709
14442
|
selections,
|
|
13710
|
-
force: Boolean(options.force)
|
|
14443
|
+
force: Boolean(options.force),
|
|
14444
|
+
dryRun: Boolean(options.dryRun)
|
|
13711
14445
|
});
|
|
13712
14446
|
} catch (error) {
|
|
13713
14447
|
outputError(
|
|
@@ -13721,14 +14455,16 @@ async function generateCommand(type, repoPathArg, options) {
|
|
|
13721
14455
|
const result = {
|
|
13722
14456
|
ok,
|
|
13723
14457
|
status,
|
|
13724
|
-
data: { type, files: genResult.files }
|
|
14458
|
+
data: { type, files: genResult.files, dryRun: options.dryRun }
|
|
13725
14459
|
};
|
|
13726
14460
|
outputResult(result, true);
|
|
13727
14461
|
if (!ok) process.exitCode = 1;
|
|
13728
14462
|
} else {
|
|
13729
14463
|
for (const file of genResult.files) {
|
|
13730
14464
|
if (shouldLog(options)) {
|
|
13731
|
-
|
|
14465
|
+
const prefix = options.dryRun ? file.action === "wrote" ? "[dry-run] Would write" : "[dry-run] Would skip" : file.action === "wrote" ? "Wrote" : "Skipped";
|
|
14466
|
+
const suffix = options.dryRun && file.bytes !== void 0 ? ` (${file.bytes} bytes)` : "";
|
|
14467
|
+
process.stderr.write(`${prefix} ${file.path}${suffix}
|
|
13732
14468
|
`);
|
|
13733
14469
|
}
|
|
13734
14470
|
}
|
|
@@ -13739,10 +14475,37 @@ async function generateCommand(type, repoPathArg, options) {
|
|
|
13739
14475
|
}
|
|
13740
14476
|
|
|
13741
14477
|
// src/commands/init.ts
|
|
13742
|
-
import
|
|
13743
|
-
import
|
|
14478
|
+
import { execFile as execFile3 } from "child_process";
|
|
14479
|
+
import path21 from "path";
|
|
14480
|
+
import { promisify as promisify3 } from "util";
|
|
14481
|
+
|
|
14482
|
+
// packages/core/src/services/configScaffold.ts
|
|
14483
|
+
import path20 from "path";
|
|
14484
|
+
async function scaffoldAgentrcConfig(repoPath, areas, force = false) {
|
|
14485
|
+
const configPath = path20.join(repoPath, "agentrc.config.json");
|
|
14486
|
+
const workspaces = areas.length > 0 ? await detectWorkspaces(repoPath, areas) : [];
|
|
14487
|
+
const workspacePaths = workspaces.map((ws) => ws.path + "/");
|
|
14488
|
+
const standaloneAreas = areas.filter((a) => {
|
|
14489
|
+
if (!a.path) return true;
|
|
14490
|
+
const rel = path20.relative(repoPath, a.path).replace(/\\/gu, "/");
|
|
14491
|
+
return !workspacePaths.some((prefix) => rel.startsWith(prefix));
|
|
14492
|
+
}).map((a) => ({
|
|
14493
|
+
name: a.name,
|
|
14494
|
+
applyTo: a.applyTo,
|
|
14495
|
+
...a.description ? { description: a.description } : {}
|
|
14496
|
+
}));
|
|
14497
|
+
const agentrcConfig = {};
|
|
14498
|
+
if (workspaces.length > 0) agentrcConfig.workspaces = workspaces;
|
|
14499
|
+
if (standaloneAreas.length > 0) agentrcConfig.areas = standaloneAreas;
|
|
14500
|
+
const configContent = JSON.stringify(agentrcConfig, null, 2) + "\n";
|
|
14501
|
+
const { wrote } = await safeWriteFile(configPath, configContent, force);
|
|
14502
|
+
return { wrote, configPath };
|
|
14503
|
+
}
|
|
14504
|
+
|
|
14505
|
+
// src/commands/init.ts
|
|
14506
|
+
import { checkbox, confirm, select } from "@inquirer/prompts";
|
|
13744
14507
|
async function initCommand(repoPathArg, options) {
|
|
13745
|
-
let repoPath =
|
|
14508
|
+
let repoPath = path21.resolve(repoPathArg ?? process.cwd());
|
|
13746
14509
|
const provider = options.provider ?? (options.github ? "github" : void 0);
|
|
13747
14510
|
if (provider && provider !== "github" && provider !== "azure") {
|
|
13748
14511
|
outputError("Invalid provider. Use github or azure.", Boolean(options.json));
|
|
@@ -13780,7 +14543,7 @@ async function initCommand(repoPathArg, options) {
|
|
|
13780
14543
|
value: repo
|
|
13781
14544
|
}))
|
|
13782
14545
|
});
|
|
13783
|
-
const cacheRoot =
|
|
14546
|
+
const cacheRoot = path21.join(process.cwd(), ".agentrc-cache");
|
|
13784
14547
|
repoPath = validateCachePath(cacheRoot, selection.owner, selection.name);
|
|
13785
14548
|
await ensureDir(repoPath);
|
|
13786
14549
|
const hasGit = await isGitRepo(repoPath);
|
|
@@ -13833,7 +14596,7 @@ async function initCommand(repoPathArg, options) {
|
|
|
13833
14596
|
value: repo
|
|
13834
14597
|
}))
|
|
13835
14598
|
});
|
|
13836
|
-
const cacheRoot =
|
|
14599
|
+
const cacheRoot = path21.join(process.cwd(), ".agentrc-cache");
|
|
13837
14600
|
repoPath = validateCachePath(
|
|
13838
14601
|
cacheRoot,
|
|
13839
14602
|
orgSelection.name,
|
|
@@ -13872,17 +14635,17 @@ async function initCommand(repoPathArg, options) {
|
|
|
13872
14635
|
});
|
|
13873
14636
|
const allFiles = [];
|
|
13874
14637
|
if (selections.includes("instructions")) {
|
|
13875
|
-
const outputPath =
|
|
13876
|
-
await ensureDir(
|
|
14638
|
+
const outputPath = path21.join(repoPath, ".github", "copilot-instructions.md");
|
|
14639
|
+
await ensureDir(path21.dirname(outputPath));
|
|
13877
14640
|
try {
|
|
13878
14641
|
const content = await generateCopilotInstructions({ repoPath, model: options.model });
|
|
13879
14642
|
const { wrote } = await safeWriteFile(outputPath, content, Boolean(options.force));
|
|
13880
14643
|
allFiles.push({
|
|
13881
|
-
path:
|
|
14644
|
+
path: path21.relative(process.cwd(), outputPath),
|
|
13882
14645
|
action: wrote ? "wrote" : "skipped"
|
|
13883
14646
|
});
|
|
13884
14647
|
if (shouldLog(options)) {
|
|
13885
|
-
const rel =
|
|
14648
|
+
const rel = path21.relative(process.cwd(), outputPath);
|
|
13886
14649
|
process.stderr.write((wrote ? `Wrote ${rel}` : `Skipped ${rel} (exists)`) + "\n");
|
|
13887
14650
|
}
|
|
13888
14651
|
} catch (error) {
|
|
@@ -13909,32 +14672,19 @@ async function initCommand(repoPathArg, options) {
|
|
|
13909
14672
|
return;
|
|
13910
14673
|
}
|
|
13911
14674
|
allFiles.push(...genResult.files);
|
|
13912
|
-
|
|
13913
|
-
const
|
|
13914
|
-
|
|
13915
|
-
|
|
13916
|
-
|
|
13917
|
-
|
|
13918
|
-
|
|
13919
|
-
|
|
13920
|
-
|
|
13921
|
-
|
|
13922
|
-
applyTo: a.applyTo,
|
|
13923
|
-
...a.description ? { description: a.description } : {}
|
|
13924
|
-
}));
|
|
13925
|
-
const agentrcConfig = {};
|
|
13926
|
-
if (workspaces.length > 0) agentrcConfig.workspaces = workspaces;
|
|
13927
|
-
if (standaloneAreas.length > 0) agentrcConfig.areas = standaloneAreas;
|
|
13928
|
-
if (agentrcConfig.workspaces || agentrcConfig.areas) {
|
|
13929
|
-
const configContent = JSON.stringify(agentrcConfig, null, 2) + "\n";
|
|
13930
|
-
const { wrote } = await safeWriteFile(configPath, configContent, Boolean(options.force));
|
|
13931
|
-
const rel = path16.relative(process.cwd(), configPath);
|
|
13932
|
-
allFiles.push({ path: rel, action: wrote ? "wrote" : "skipped" });
|
|
13933
|
-
if (shouldLog(options)) {
|
|
13934
|
-
process.stderr.write((wrote ? `Wrote ${rel}` : `Skipped ${rel} (exists)`) + "\n");
|
|
13935
|
-
}
|
|
14675
|
+
{
|
|
14676
|
+
const result = await scaffoldAgentrcConfig(
|
|
14677
|
+
repoPath,
|
|
14678
|
+
analysis.areas ?? [],
|
|
14679
|
+
Boolean(options.force)
|
|
14680
|
+
);
|
|
14681
|
+
const rel = path21.relative(process.cwd(), result.configPath);
|
|
14682
|
+
allFiles.push({ path: rel, action: result.wrote ? "wrote" : "skipped" });
|
|
14683
|
+
if (shouldLog(options)) {
|
|
14684
|
+
process.stderr.write((result.wrote ? `Wrote ${rel}` : `Skipped ${rel} (exists)`) + "\n");
|
|
13936
14685
|
}
|
|
13937
14686
|
}
|
|
14687
|
+
await offerApmInit(repoPath, options);
|
|
13938
14688
|
if (options.json) {
|
|
13939
14689
|
const { ok, status } = deriveFileStatus(allFiles);
|
|
13940
14690
|
const result = {
|
|
@@ -13949,16 +14699,59 @@ async function initCommand(repoPathArg, options) {
|
|
|
13949
14699
|
`);
|
|
13950
14700
|
}
|
|
13951
14701
|
process.stderr.write("\nNext steps:\n");
|
|
13952
|
-
process.stderr.write(" agentrc readiness
|
|
14702
|
+
process.stderr.write(" agentrc readiness Run readiness report across 9 pillars\n");
|
|
13953
14703
|
if (analysis.areas && analysis.areas.length > 0) {
|
|
13954
14704
|
process.stderr.write(" agentrc instructions --areas Generate per-area instructions\n");
|
|
13955
14705
|
}
|
|
13956
14706
|
process.stderr.write(" agentrc eval --init Scaffold evaluation test cases\n");
|
|
13957
14707
|
}
|
|
13958
14708
|
}
|
|
14709
|
+
var execFileAsync3 = promisify3(execFile3);
|
|
14710
|
+
var APM_TIMEOUT_MS = 1e4;
|
|
14711
|
+
async function isApmInstalled() {
|
|
14712
|
+
try {
|
|
14713
|
+
await execFileAsync3("apm", ["--version"], { timeout: APM_TIMEOUT_MS });
|
|
14714
|
+
return true;
|
|
14715
|
+
} catch {
|
|
14716
|
+
return false;
|
|
14717
|
+
}
|
|
14718
|
+
}
|
|
14719
|
+
async function offerApmInit(repoPath, options) {
|
|
14720
|
+
if (options.json) return;
|
|
14721
|
+
const hasApmYml = await fileExists(path21.join(repoPath, "apm.yml"));
|
|
14722
|
+
if (hasApmYml) return;
|
|
14723
|
+
const apmAvailable = await isApmInstalled();
|
|
14724
|
+
if (apmAvailable) {
|
|
14725
|
+
const accepted = options.yes ? true : await confirm({
|
|
14726
|
+
message: "Set up APM to install and share agent packages across your team?",
|
|
14727
|
+
default: false
|
|
14728
|
+
});
|
|
14729
|
+
if (accepted) {
|
|
14730
|
+
try {
|
|
14731
|
+
await execFileAsync3("apm", ["init", "--yes"], { cwd: repoPath, timeout: APM_TIMEOUT_MS });
|
|
14732
|
+
if (shouldLog(options)) {
|
|
14733
|
+
process.stderr.write(
|
|
14734
|
+
"APM initialized \u2014 run `apm install <package>` to add shared agent packages.\n"
|
|
14735
|
+
);
|
|
14736
|
+
}
|
|
14737
|
+
} catch (error) {
|
|
14738
|
+
if (shouldLog(options)) {
|
|
14739
|
+
process.stderr.write(
|
|
14740
|
+
`Warning: APM init failed; continuing without APM: ${error instanceof Error ? error.message : String(error)}
|
|
14741
|
+
`
|
|
14742
|
+
);
|
|
14743
|
+
}
|
|
14744
|
+
}
|
|
14745
|
+
}
|
|
14746
|
+
} else if (shouldLog(options)) {
|
|
14747
|
+
process.stderr.write(
|
|
14748
|
+
"\nTip: use APM to install shared agent packages and distribute your instructions across repos.\n https://github.com/microsoft/apm\n"
|
|
14749
|
+
);
|
|
14750
|
+
}
|
|
14751
|
+
}
|
|
13959
14752
|
|
|
13960
14753
|
// src/commands/pr.ts
|
|
13961
|
-
import
|
|
14754
|
+
import path22 from "path";
|
|
13962
14755
|
var DEFAULT_PR_BRANCH = "agentrc/add-ai-config";
|
|
13963
14756
|
async function prCommand(repo, options) {
|
|
13964
14757
|
const provider = options.provider ?? "github";
|
|
@@ -13992,7 +14785,7 @@ async function prCommand(repo, options) {
|
|
|
13992
14785
|
try {
|
|
13993
14786
|
progress.update("Fetching repo info...");
|
|
13994
14787
|
const repoInfo = await getRepo(token2, organization, project, name2);
|
|
13995
|
-
const cacheRoot =
|
|
14788
|
+
const cacheRoot = path22.join(process.cwd(), ".agentrc-cache");
|
|
13996
14789
|
const repoPath = validateCachePath(cacheRoot, organization, project, name2);
|
|
13997
14790
|
await ensureDir(repoPath);
|
|
13998
14791
|
if (!await isGitRepo(repoPath)) {
|
|
@@ -14006,8 +14799,8 @@ async function prCommand(repo, options) {
|
|
|
14006
14799
|
await checkoutBranch(repoPath, branch);
|
|
14007
14800
|
progress.update("Generating instructions...");
|
|
14008
14801
|
const instructions = await generateCopilotInstructions({ repoPath, model: options.model });
|
|
14009
|
-
const instructionsPath =
|
|
14010
|
-
await ensureDir(
|
|
14802
|
+
const instructionsPath = path22.join(repoPath, ".github", "copilot-instructions.md");
|
|
14803
|
+
await ensureDir(path22.dirname(instructionsPath));
|
|
14011
14804
|
const { wrote, reason } = await safeWriteFile(instructionsPath, instructions, true);
|
|
14012
14805
|
if (!wrote) {
|
|
14013
14806
|
throw new Error(
|
|
@@ -14074,7 +14867,7 @@ async function prCommand(repo, options) {
|
|
|
14074
14867
|
try {
|
|
14075
14868
|
progress.update("Fetching repo info...");
|
|
14076
14869
|
const repoInfo = await getRepo2(token, owner, name);
|
|
14077
|
-
const cacheRoot =
|
|
14870
|
+
const cacheRoot = path22.join(process.cwd(), ".agentrc-cache");
|
|
14078
14871
|
const repoPath = validateCachePath(cacheRoot, owner, name);
|
|
14079
14872
|
await ensureDir(repoPath);
|
|
14080
14873
|
if (!await isGitRepo(repoPath)) {
|
|
@@ -14086,8 +14879,8 @@ async function prCommand(repo, options) {
|
|
|
14086
14879
|
await checkoutBranch(repoPath, branch);
|
|
14087
14880
|
progress.update("Generating instructions...");
|
|
14088
14881
|
const instructions = await generateCopilotInstructions({ repoPath, model: options.model });
|
|
14089
|
-
const instructionsPath =
|
|
14090
|
-
await ensureDir(
|
|
14882
|
+
const instructionsPath = path22.join(repoPath, ".github", "copilot-instructions.md");
|
|
14883
|
+
await ensureDir(path22.dirname(instructionsPath));
|
|
14091
14884
|
const { wrote, reason } = await safeWriteFile(instructionsPath, instructions, true);
|
|
14092
14885
|
if (!wrote) {
|
|
14093
14886
|
throw new Error(
|
|
@@ -14136,13 +14929,13 @@ async function prCommand(repo, options) {
|
|
|
14136
14929
|
}
|
|
14137
14930
|
|
|
14138
14931
|
// src/commands/readiness.ts
|
|
14139
|
-
import
|
|
14932
|
+
import path23 from "path";
|
|
14140
14933
|
import chalk3 from "chalk";
|
|
14141
14934
|
async function readinessCommand(repoPathArg, options) {
|
|
14142
|
-
const repoPath =
|
|
14143
|
-
const repoName =
|
|
14144
|
-
const resolvedOutputPath = options.output ?
|
|
14145
|
-
const outputExt = options.output ?
|
|
14935
|
+
const repoPath = path23.resolve(repoPathArg ?? process.cwd());
|
|
14936
|
+
const repoName = path23.basename(repoPath);
|
|
14937
|
+
const resolvedOutputPath = options.output ? path23.resolve(options.output) : "";
|
|
14938
|
+
const outputExt = options.output ? path23.extname(options.output).toLowerCase() : "";
|
|
14146
14939
|
let failLevelError;
|
|
14147
14940
|
let report;
|
|
14148
14941
|
try {
|
|
@@ -14201,10 +14994,10 @@ async function readinessCommand(repoPathArg, options) {
|
|
|
14201
14994
|
if (options.visual || outputExt === ".html") {
|
|
14202
14995
|
const html = generateVisualReport({
|
|
14203
14996
|
reports: [{ repo: repoName, report }],
|
|
14204
|
-
title: `
|
|
14997
|
+
title: `Readiness Report: ${repoName}`,
|
|
14205
14998
|
generatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
14206
14999
|
});
|
|
14207
|
-
const outputPath = options.output ? resolvedOutputPath :
|
|
15000
|
+
const outputPath = options.output ? resolvedOutputPath : path23.join(repoPath, "readiness-report.html");
|
|
14208
15001
|
const { wrote, reason } = await safeWriteFile(outputPath, html, Boolean(options.force));
|
|
14209
15002
|
if (!wrote) {
|
|
14210
15003
|
const why = reason === "symlink" ? "path is a symlink" : "file exists (use --force)";
|
|
@@ -14301,7 +15094,7 @@ ${label}`));
|
|
|
14301
15094
|
}
|
|
14302
15095
|
}
|
|
14303
15096
|
if (report.extras.length) {
|
|
14304
|
-
log(chalk3.bold("\
|
|
15097
|
+
log(chalk3.bold("\nReadiness extras"));
|
|
14305
15098
|
for (const extra of report.extras) {
|
|
14306
15099
|
const icon = extra.status === "pass" ? chalk3.green("\u2714") : chalk3.red("\u2716");
|
|
14307
15100
|
log(`${icon} ${extra.title}`);
|
|
@@ -14366,7 +15159,7 @@ function printAreaBreakdown(areaReports) {
|
|
|
14366
15159
|
}
|
|
14367
15160
|
function formatReadinessMarkdown(report, repoName) {
|
|
14368
15161
|
const lines = [];
|
|
14369
|
-
lines.push(`#
|
|
15162
|
+
lines.push(`# Readiness Report: ${repoName}`);
|
|
14370
15163
|
lines.push("");
|
|
14371
15164
|
lines.push(`**Level ${report.achievedLevel}** \u2014 ${levelName(report.achievedLevel)}`);
|
|
14372
15165
|
lines.push("");
|
|
@@ -14399,7 +15192,7 @@ function formatReadinessMarkdown(report, repoName) {
|
|
|
14399
15192
|
lines.push("");
|
|
14400
15193
|
}
|
|
14401
15194
|
if (report.extras.length > 0) {
|
|
14402
|
-
lines.push("##
|
|
15195
|
+
lines.push("## Readiness Extras");
|
|
14403
15196
|
lines.push("");
|
|
14404
15197
|
for (const extra of report.extras) {
|
|
14405
15198
|
const icon = extra.status === "pass" ? "\u2705" : "\u274C";
|
|
@@ -14439,26 +15232,32 @@ function formatReadinessMarkdown(report, repoName) {
|
|
|
14439
15232
|
}
|
|
14440
15233
|
|
|
14441
15234
|
// src/commands/tui.tsx
|
|
14442
|
-
import
|
|
15235
|
+
import path25 from "path";
|
|
14443
15236
|
import { render as render3 } from "ink";
|
|
14444
15237
|
|
|
14445
15238
|
// src/ui/tui.tsx
|
|
14446
15239
|
import fs10 from "fs/promises";
|
|
14447
|
-
import
|
|
15240
|
+
import path24 from "path";
|
|
14448
15241
|
import { Box as Box5, Text as Text5, useApp as useApp4, useInput as useInput4, useStdout, useIsScreenReaderEnabled as useIsScreenReaderEnabled5 } from "ink";
|
|
14449
15242
|
import { useEffect as useEffect5, useMemo, useState as useState5 } from "react";
|
|
14450
15243
|
import { Fragment, jsx as jsx7, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
14451
15244
|
var SPINNER_FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
14452
15245
|
function useTerminalColumns() {
|
|
14453
15246
|
const { stdout } = useStdout();
|
|
15247
|
+
const accessible = useIsScreenReaderEnabled5();
|
|
14454
15248
|
const [columns, setColumns] = useState5(stdout.columns ?? 80);
|
|
14455
15249
|
useEffect5(() => {
|
|
14456
|
-
const onResize = () =>
|
|
14457
|
-
|
|
15250
|
+
const onResize = () => {
|
|
15251
|
+
if (!accessible) {
|
|
15252
|
+
stdout.write("\x1B[2J\x1B[H");
|
|
15253
|
+
}
|
|
15254
|
+
setColumns(stdout.columns ?? 80);
|
|
15255
|
+
};
|
|
15256
|
+
stdout.prependListener("resize", onResize);
|
|
14458
15257
|
return () => {
|
|
14459
15258
|
stdout.off("resize", onResize);
|
|
14460
15259
|
};
|
|
14461
|
-
}, [stdout]);
|
|
15260
|
+
}, [stdout, accessible]);
|
|
14462
15261
|
return columns;
|
|
14463
15262
|
}
|
|
14464
15263
|
function useSpinner(active) {
|
|
@@ -14543,6 +15342,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14543
15342
|
const [modelPickTarget, setModelPickTarget] = useState5("eval");
|
|
14544
15343
|
const [modelCursor, setModelCursor] = useState5(0);
|
|
14545
15344
|
const [hasEvalConfig, setHasEvalConfig] = useState5(null);
|
|
15345
|
+
const [hasAgentrcConfig, setHasAgentrcConfig] = useState5(null);
|
|
14546
15346
|
const [activityLog, setActivityLog] = useState5([]);
|
|
14547
15347
|
const [generateTarget, setGenerateTarget] = useState5(
|
|
14548
15348
|
"copilot-instructions"
|
|
@@ -14552,9 +15352,9 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14552
15352
|
const [isMonorepo, setIsMonorepo] = useState5(false);
|
|
14553
15353
|
const [repoAreas, setRepoAreas] = useState5([]);
|
|
14554
15354
|
const [areaCursor, setAreaCursor] = useState5(0);
|
|
14555
|
-
const repoLabel = useMemo(() =>
|
|
15355
|
+
const repoLabel = useMemo(() => path24.basename(repoPath), [repoPath]);
|
|
14556
15356
|
const repoFull = useMemo(() => repoPath, [repoPath]);
|
|
14557
|
-
const isLoading = status === "generating" || status === "bootstrapping" || status === "evaluating" || status === "generating-areas";
|
|
15357
|
+
const isLoading = status === "generating" || status === "bootstrapping" || status === "evaluating" || status === "generating-areas" || status === "readiness-running";
|
|
14558
15358
|
const isMenu = status === "model-pick" || status === "eval-pick" || status === "batch-pick" || status === "generate-pick" || status === "generate-app-pick" || status === "generate-area-pick";
|
|
14559
15359
|
const spinner = useSpinner(isLoading);
|
|
14560
15360
|
const addLog = (text, type = "info") => {
|
|
@@ -14564,14 +15364,24 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14564
15364
|
setStatus("idle");
|
|
14565
15365
|
};
|
|
14566
15366
|
useEffect5(() => {
|
|
14567
|
-
const configPath =
|
|
15367
|
+
const configPath = path24.join(repoPath, "agentrc.eval.json");
|
|
14568
15368
|
fs10.access(configPath).then(() => setHasEvalConfig(true)).catch(() => setHasEvalConfig(false));
|
|
15369
|
+
const agentrcConfigCandidates = [
|
|
15370
|
+
path24.join(repoPath, "agentrc.config.json"),
|
|
15371
|
+
path24.join(repoPath, ".github", "agentrc.config.json")
|
|
15372
|
+
];
|
|
15373
|
+
Promise.all(
|
|
15374
|
+
agentrcConfigCandidates.map(
|
|
15375
|
+
(p) => fs10.access(p).then(() => true).catch(() => false)
|
|
15376
|
+
)
|
|
15377
|
+
).then((results) => setHasAgentrcConfig(results.some(Boolean))).catch(() => setHasAgentrcConfig(false));
|
|
14569
15378
|
analyzeRepo(repoPath).then((analysis) => {
|
|
14570
15379
|
const apps = analysis.apps ?? [];
|
|
14571
15380
|
setRepoApps(apps);
|
|
14572
15381
|
setIsMonorepo(analysis.isMonorepo ?? false);
|
|
14573
15382
|
setRepoAreas(analysis.areas ?? []);
|
|
14574
15383
|
}).catch((err) => {
|
|
15384
|
+
setRepoAreas([]);
|
|
14575
15385
|
addLog(`Repo analysis failed: ${err instanceof Error ? err.message : "unknown"}`, "error");
|
|
14576
15386
|
});
|
|
14577
15387
|
}, [repoPath]);
|
|
@@ -14579,17 +15389,17 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14579
15389
|
let active = true;
|
|
14580
15390
|
listCopilotModels().then((models) => {
|
|
14581
15391
|
if (!active) return;
|
|
14582
|
-
|
|
14583
|
-
|
|
15392
|
+
const list = models.length > 0 ? models : PREFERRED_MODELS;
|
|
15393
|
+
setAvailableModels(list);
|
|
14584
15394
|
setEvalModel(
|
|
14585
|
-
(current) =>
|
|
15395
|
+
(current) => list.includes(current) ? current : pickBestModel(list, current)
|
|
14586
15396
|
);
|
|
14587
15397
|
setJudgeModel(
|
|
14588
|
-
(current) =>
|
|
15398
|
+
(current) => list.includes(current) ? current : pickBestModel(list, current)
|
|
14589
15399
|
);
|
|
14590
15400
|
}).catch(() => {
|
|
14591
15401
|
if (!active) return;
|
|
14592
|
-
setAvailableModels(
|
|
15402
|
+
setAvailableModels(PREFERRED_MODELS);
|
|
14593
15403
|
});
|
|
14594
15404
|
return () => {
|
|
14595
15405
|
active = false;
|
|
@@ -14625,7 +15435,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14625
15435
|
};
|
|
14626
15436
|
useEffect5(() => {
|
|
14627
15437
|
let active = true;
|
|
14628
|
-
const configPath =
|
|
15438
|
+
const configPath = path24.join(repoPath, "agentrc.eval.json");
|
|
14629
15439
|
fs10.readFile(configPath, "utf8").then((raw) => {
|
|
14630
15440
|
if (!active) return;
|
|
14631
15441
|
const parsed = JSON.parse(raw);
|
|
@@ -14640,7 +15450,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14640
15450
|
};
|
|
14641
15451
|
}, [repoPath]);
|
|
14642
15452
|
const bootstrapEvalConfig = async (count, force) => {
|
|
14643
|
-
const configPath =
|
|
15453
|
+
const configPath = path24.join(repoPath, "agentrc.eval.json");
|
|
14644
15454
|
try {
|
|
14645
15455
|
setStatus("bootstrapping");
|
|
14646
15456
|
setMessage("Generating eval cases with Copilot SDK...");
|
|
@@ -14679,13 +15489,13 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14679
15489
|
if (status === "preview") {
|
|
14680
15490
|
if (input.toLowerCase() === "s") {
|
|
14681
15491
|
try {
|
|
14682
|
-
const outputPath = generateSavePath ||
|
|
14683
|
-
await fs10.mkdir(
|
|
15492
|
+
const outputPath = generateSavePath || path24.join(repoPath, ".github", "copilot-instructions.md");
|
|
15493
|
+
await fs10.mkdir(path24.dirname(outputPath), { recursive: true });
|
|
14684
15494
|
const { wrote, reason } = await safeWriteFile(outputPath, generatedContent, true);
|
|
14685
15495
|
if (!wrote)
|
|
14686
15496
|
throw new Error(reason === "symlink" ? "Path is a symlink" : "Write failed");
|
|
14687
15497
|
setStatus("done");
|
|
14688
|
-
const relPath =
|
|
15498
|
+
const relPath = path24.relative(repoPath, outputPath);
|
|
14689
15499
|
const msg = `Saved to ${relPath}`;
|
|
14690
15500
|
setMessage(msg);
|
|
14691
15501
|
addLog(msg, "success");
|
|
@@ -14719,7 +15529,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14719
15529
|
setMessage("Enter a positive number of eval cases, then press Enter.");
|
|
14720
15530
|
return;
|
|
14721
15531
|
}
|
|
14722
|
-
const configPath =
|
|
15532
|
+
const configPath = path24.join(repoPath, "agentrc.eval.json");
|
|
14723
15533
|
setEvalBootstrapCount(count);
|
|
14724
15534
|
try {
|
|
14725
15535
|
await fs10.access(configPath);
|
|
@@ -14778,7 +15588,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14778
15588
|
setStatus("generate-app-pick");
|
|
14779
15589
|
setMessage("Generate for root or per-app?");
|
|
14780
15590
|
} else {
|
|
14781
|
-
const savePath =
|
|
15591
|
+
const savePath = path24.join(repoPath, ".github", "copilot-instructions.md");
|
|
14782
15592
|
setGenerateSavePath(savePath);
|
|
14783
15593
|
await doGenerate(repoPath, savePath, "copilot-instructions");
|
|
14784
15594
|
}
|
|
@@ -14790,20 +15600,20 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14790
15600
|
setStatus("generate-app-pick");
|
|
14791
15601
|
setMessage("Generate for root or per-app?");
|
|
14792
15602
|
} else {
|
|
14793
|
-
const savePath =
|
|
15603
|
+
const savePath = path24.join(repoPath, "AGENTS.md");
|
|
14794
15604
|
setGenerateSavePath(savePath);
|
|
14795
15605
|
await doGenerate(repoPath, savePath, "agents-md");
|
|
14796
15606
|
}
|
|
14797
15607
|
return;
|
|
14798
15608
|
}
|
|
14799
|
-
if (input.toLowerCase() === "
|
|
15609
|
+
if (input.toLowerCase() === "n") {
|
|
14800
15610
|
if (repoAreas.length === 0) {
|
|
14801
15611
|
setMessage("No areas detected. Add agentrc.config.json to define areas.");
|
|
14802
15612
|
return;
|
|
14803
15613
|
}
|
|
14804
15614
|
setAreaCursor(0);
|
|
14805
15615
|
setStatus("generate-area-pick");
|
|
14806
|
-
setMessage("Generate
|
|
15616
|
+
setMessage("Generate nested instructions for areas.");
|
|
14807
15617
|
return;
|
|
14808
15618
|
}
|
|
14809
15619
|
if (key.escape) {
|
|
@@ -14815,7 +15625,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14815
15625
|
}
|
|
14816
15626
|
if (status === "generate-app-pick") {
|
|
14817
15627
|
if (input.toLowerCase() === "r") {
|
|
14818
|
-
const savePath = generateTarget === "copilot-instructions" ?
|
|
15628
|
+
const savePath = generateTarget === "copilot-instructions" ? path24.join(repoPath, ".github", "copilot-instructions.md") : path24.join(repoPath, "AGENTS.md");
|
|
14819
15629
|
setGenerateSavePath(savePath);
|
|
14820
15630
|
await doGenerate(repoPath, savePath, generateTarget);
|
|
14821
15631
|
return;
|
|
@@ -14825,7 +15635,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14825
15635
|
addLog(`Generating ${generateTarget} for ${repoApps.length} apps...`, "progress");
|
|
14826
15636
|
let count = 0;
|
|
14827
15637
|
for (const app2 of repoApps) {
|
|
14828
|
-
const savePath = generateTarget === "copilot-instructions" ?
|
|
15638
|
+
const savePath = generateTarget === "copilot-instructions" ? path24.join(app2.path, ".github", "copilot-instructions.md") : path24.join(app2.path, "AGENTS.md");
|
|
14829
15639
|
setMessage(`Generating for ${app2.name} (${count + 1}/${repoApps.length})...`);
|
|
14830
15640
|
try {
|
|
14831
15641
|
const content = await generateCopilotInstructions({
|
|
@@ -14833,11 +15643,11 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14833
15643
|
onProgress: (msg) => setMessage(`${app2.name}: ${msg}`)
|
|
14834
15644
|
});
|
|
14835
15645
|
if (content.trim()) {
|
|
14836
|
-
await fs10.mkdir(
|
|
15646
|
+
await fs10.mkdir(path24.dirname(savePath), { recursive: true });
|
|
14837
15647
|
const { wrote: saved } = await safeWriteFile(savePath, content, true);
|
|
14838
15648
|
if (!saved) continue;
|
|
14839
15649
|
count++;
|
|
14840
|
-
addLog(`${app2.name}: saved ${
|
|
15650
|
+
addLog(`${app2.name}: saved ${path24.basename(savePath)}`, "success");
|
|
14841
15651
|
}
|
|
14842
15652
|
} catch (error) {
|
|
14843
15653
|
const msg = error instanceof Error ? error.message : "Failed.";
|
|
@@ -14851,7 +15661,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14851
15661
|
const num = Number.parseInt(input, 10);
|
|
14852
15662
|
if (Number.isFinite(num) && num >= 1 && num <= repoApps.length) {
|
|
14853
15663
|
const app2 = repoApps[num - 1];
|
|
14854
|
-
const savePath = generateTarget === "copilot-instructions" ?
|
|
15664
|
+
const savePath = generateTarget === "copilot-instructions" ? path24.join(app2.path, ".github", "copilot-instructions.md") : path24.join(app2.path, "AGENTS.md");
|
|
14855
15665
|
setGenerateSavePath(savePath);
|
|
14856
15666
|
await doGenerate(app2.path, savePath, generateTarget);
|
|
14857
15667
|
return;
|
|
@@ -14866,10 +15676,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14866
15676
|
if (status === "generate-area-pick") {
|
|
14867
15677
|
if (input.toLowerCase() === "a") {
|
|
14868
15678
|
setStatus("generating-areas");
|
|
14869
|
-
addLog(
|
|
14870
|
-
`Generating file-based instructions for ${repoAreas.length} areas...`,
|
|
14871
|
-
"progress"
|
|
14872
|
-
);
|
|
15679
|
+
addLog(`Generating nested instructions for ${repoAreas.length} areas...`, "progress");
|
|
14873
15680
|
let written = 0;
|
|
14874
15681
|
for (const [i, area] of repoAreas.entries()) {
|
|
14875
15682
|
setMessage(`Generating for "${area.name}" (${i + 1}/${repoAreas.length})...`);
|
|
@@ -14882,7 +15689,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14882
15689
|
const result = await writeAreaInstruction(repoPath, area, body);
|
|
14883
15690
|
if (result.status === "written") {
|
|
14884
15691
|
written++;
|
|
14885
|
-
addLog(`${area.name}: saved ${
|
|
15692
|
+
addLog(`${area.name}: saved ${path24.basename(result.filePath)}`, "success");
|
|
14886
15693
|
} else if (result.status === "skipped") {
|
|
14887
15694
|
addLog(`${area.name}: skipped (file exists)`, "info");
|
|
14888
15695
|
}
|
|
@@ -14892,9 +15699,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14892
15699
|
}
|
|
14893
15700
|
}
|
|
14894
15701
|
setStatus("done");
|
|
14895
|
-
setMessage(
|
|
14896
|
-
`Generated file-based instructions for ${written}/${repoAreas.length} areas.`
|
|
14897
|
-
);
|
|
15702
|
+
setMessage(`Generated nested instructions for ${written}/${repoAreas.length} areas.`);
|
|
14898
15703
|
return;
|
|
14899
15704
|
}
|
|
14900
15705
|
if (key.upArrow) {
|
|
@@ -14910,7 +15715,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14910
15715
|
if (!area) return;
|
|
14911
15716
|
setStatus("generating-areas");
|
|
14912
15717
|
setMessage(`Generating for "${area.name}"...`);
|
|
14913
|
-
addLog(`Generating
|
|
15718
|
+
addLog(`Generating nested instructions for "${area.name}"...`, "progress");
|
|
14914
15719
|
try {
|
|
14915
15720
|
const body = await generateAreaInstructions({
|
|
14916
15721
|
repoPath,
|
|
@@ -14978,8 +15783,8 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14978
15783
|
}
|
|
14979
15784
|
if (status === "eval-pick") {
|
|
14980
15785
|
if (input.toLowerCase() === "r") {
|
|
14981
|
-
const configPath =
|
|
14982
|
-
const outputPath =
|
|
15786
|
+
const configPath = path24.join(repoPath, "agentrc.eval.json");
|
|
15787
|
+
const outputPath = path24.join(
|
|
14983
15788
|
repoPath,
|
|
14984
15789
|
".agentrc",
|
|
14985
15790
|
"evals",
|
|
@@ -15083,6 +15888,36 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
15083
15888
|
setMessage("Select what to generate.");
|
|
15084
15889
|
return;
|
|
15085
15890
|
}
|
|
15891
|
+
if (input.toLowerCase() === "r") {
|
|
15892
|
+
setStatus("readiness-running");
|
|
15893
|
+
setMessage("Running readiness report\u2026");
|
|
15894
|
+
addLog("Running readiness report\u2026", "progress");
|
|
15895
|
+
try {
|
|
15896
|
+
let policies;
|
|
15897
|
+
try {
|
|
15898
|
+
const config = await loadAgentrcConfig(repoPath);
|
|
15899
|
+
policies = config?.policies;
|
|
15900
|
+
} catch {
|
|
15901
|
+
}
|
|
15902
|
+
const report = await runReadinessReport({ repoPath, policies });
|
|
15903
|
+
const levelName2 = getLevelName(report.achievedLevel);
|
|
15904
|
+
const failCount = report.criteria.filter((c) => c.status === "fail").length;
|
|
15905
|
+
addLog(
|
|
15906
|
+
`Level ${report.achievedLevel} (${levelName2}) \u2014 ${failCount} item(s) to fix`,
|
|
15907
|
+
"success"
|
|
15908
|
+
);
|
|
15909
|
+
setStatus("done");
|
|
15910
|
+
setMessage(
|
|
15911
|
+
`Readiness: Level ${report.achievedLevel} (${levelName2}). ${failCount} improvement(s) available.`
|
|
15912
|
+
);
|
|
15913
|
+
} catch (error) {
|
|
15914
|
+
const msg = error instanceof Error ? error.message : "Failed.";
|
|
15915
|
+
addLog(`Readiness failed: ${msg}`, "error");
|
|
15916
|
+
setStatus("error");
|
|
15917
|
+
setMessage(`Readiness failed: ${msg}`);
|
|
15918
|
+
}
|
|
15919
|
+
return;
|
|
15920
|
+
}
|
|
15086
15921
|
if (input.toLowerCase() === "b") {
|
|
15087
15922
|
setStatus("batch-pick");
|
|
15088
15923
|
setMessage("Select batch provider.");
|
|
@@ -15093,6 +15928,36 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
15093
15928
|
setMessage("Select eval action.");
|
|
15094
15929
|
return;
|
|
15095
15930
|
}
|
|
15931
|
+
if (input.toLowerCase() === "c") {
|
|
15932
|
+
if (hasAgentrcConfig) {
|
|
15933
|
+
setMessage("agentrc.config.json already exists.");
|
|
15934
|
+
return;
|
|
15935
|
+
}
|
|
15936
|
+
setStatus("generating");
|
|
15937
|
+
setMessage("Creating agentrc.config.json...");
|
|
15938
|
+
addLog("Scaffolding agentrc.config.json...", "progress");
|
|
15939
|
+
try {
|
|
15940
|
+
const result = await scaffoldAgentrcConfig(repoPath, repoAreas);
|
|
15941
|
+
if (result.wrote) {
|
|
15942
|
+
setHasAgentrcConfig(true);
|
|
15943
|
+
setStatus("done");
|
|
15944
|
+
const msg = `Created agentrc.config.json`;
|
|
15945
|
+
setMessage(msg);
|
|
15946
|
+
addLog(msg, "success");
|
|
15947
|
+
} else {
|
|
15948
|
+
setHasAgentrcConfig(true);
|
|
15949
|
+
setStatus("idle");
|
|
15950
|
+
setMessage("agentrc.config.json already exists (skipped).");
|
|
15951
|
+
addLog("agentrc.config.json already exists.", "info");
|
|
15952
|
+
}
|
|
15953
|
+
} catch (error) {
|
|
15954
|
+
setStatus("error");
|
|
15955
|
+
const msg = error instanceof Error ? error.message : "Failed to create config.";
|
|
15956
|
+
setMessage(msg);
|
|
15957
|
+
addLog(msg, "error");
|
|
15958
|
+
}
|
|
15959
|
+
return;
|
|
15960
|
+
}
|
|
15096
15961
|
if (input.toLowerCase() === "m") {
|
|
15097
15962
|
if (hideModelPicker) {
|
|
15098
15963
|
setMessage(
|
|
@@ -15135,7 +16000,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
15135
16000
|
{ isActive: inputActive }
|
|
15136
16001
|
);
|
|
15137
16002
|
const statusIcon = status === "error" ? accessible ? "ERROR" : "\u2717" : status === "done" ? accessible ? "OK" : "\u2713" : isLoading ? spinner : accessible ? "*" : "\u25CF";
|
|
15138
|
-
const statusLabel = status === "intro" ? "starting" : status === "idle" ? "ready" : status === "bootstrapEvalCount" ? "input" : status === "bootstrapEvalConfirm" ? "confirm" : status === "eval-pick" ? "eval" : status === "batch-pick" ? "batch" : status === "model-pick" ? "models" : status;
|
|
16003
|
+
const statusLabel = status === "intro" ? "starting" : status === "idle" ? "ready" : status === "bootstrapEvalCount" ? "input" : status === "bootstrapEvalConfirm" ? "confirm" : status === "eval-pick" ? "eval" : status === "batch-pick" ? "batch" : status === "model-pick" ? "models" : status === "readiness-running" ? "readiness" : status;
|
|
15139
16004
|
const statusColor = status === "error" ? "red" : status === "done" ? "green" : isLoading ? "yellow" : isMenu ? "magentaBright" : "cyanBright";
|
|
15140
16005
|
const formatTokens = (result) => {
|
|
15141
16006
|
const withUsage = result.metrics?.withInstructions?.tokenUsage;
|
|
@@ -15207,6 +16072,10 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
15207
16072
|
/* @__PURE__ */ jsxs4(Text5, { children: [
|
|
15208
16073
|
/* @__PURE__ */ jsx7(Text5, { color: "gray", children: "Eval " }),
|
|
15209
16074
|
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" })
|
|
16075
|
+
] }),
|
|
16076
|
+
/* @__PURE__ */ jsxs4(Text5, { children: [
|
|
16077
|
+
/* @__PURE__ */ jsx7(Text5, { color: "gray", children: "Config " }),
|
|
16078
|
+
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" })
|
|
15210
16079
|
] })
|
|
15211
16080
|
] }),
|
|
15212
16081
|
/* @__PURE__ */ jsx7(Divider, { columns: terminalColumns, label: "Activity", accessible }),
|
|
@@ -15282,19 +16151,12 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
15282
16151
|
/* @__PURE__ */ jsx7(Text5, { color: "white", children: app2.name }),
|
|
15283
16152
|
/* @__PURE__ */ jsxs4(Text5, { color: "gray", dimColor: true, children: [
|
|
15284
16153
|
" ",
|
|
15285
|
-
|
|
16154
|
+
path24.relative(repoPath, app2.path)
|
|
15286
16155
|
] })
|
|
15287
16156
|
] }, app2.name)) })
|
|
15288
16157
|
] }),
|
|
15289
16158
|
status === "generate-area-pick" && repoAreas.length > 0 && /* @__PURE__ */ jsxs4(Fragment, { children: [
|
|
15290
|
-
/* @__PURE__ */ jsx7(
|
|
15291
|
-
Divider,
|
|
15292
|
-
{
|
|
15293
|
-
columns: terminalColumns,
|
|
15294
|
-
label: "File-based instructions",
|
|
15295
|
-
accessible
|
|
15296
|
-
}
|
|
15297
|
-
),
|
|
16159
|
+
/* @__PURE__ */ jsx7(Divider, { columns: terminalColumns, label: "Nested instructions", accessible }),
|
|
15298
16160
|
/* @__PURE__ */ jsx7(Box5, { flexDirection: "column", paddingLeft: 1, children: repoAreas.map((area, i) => /* @__PURE__ */ jsxs4(Text5, { children: [
|
|
15299
16161
|
/* @__PURE__ */ jsx7(Text5, { color: i === areaCursor ? "cyanBright" : "gray", children: i === areaCursor ? accessible ? ">" : "\u25B6" : " " }),
|
|
15300
16162
|
/* @__PURE__ */ jsx7(Text5, { color: "gray", children: " " }),
|
|
@@ -15323,7 +16185,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
15323
16185
|
children: [
|
|
15324
16186
|
/* @__PURE__ */ jsxs4(Text5, { color: "cyan", bold: true, children: [
|
|
15325
16187
|
"Preview (",
|
|
15326
|
-
|
|
16188
|
+
path24.relative(repoPath, generateSavePath) || generateTarget,
|
|
15327
16189
|
")"
|
|
15328
16190
|
] }),
|
|
15329
16191
|
/* @__PURE__ */ jsx7(Text5, { color: "gray", children: truncatedPreview })
|
|
@@ -15375,9 +16237,9 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
15375
16237
|
/* @__PURE__ */ jsx7(Text5, { color: "cyan", children: " to select " }),
|
|
15376
16238
|
/* @__PURE__ */ jsx7(KeyHint, { k: "Esc", label: "Back" })
|
|
15377
16239
|
] }) : status === "generate-pick" ? /* @__PURE__ */ jsxs4(Box5, { children: [
|
|
15378
|
-
/* @__PURE__ */ jsx7(KeyHint, { k: "C", label: "
|
|
15379
|
-
/* @__PURE__ */ jsx7(KeyHint, { k: "A", label: "
|
|
15380
|
-
repoAreas.length > 0 && /* @__PURE__ */ jsx7(KeyHint, { k: "
|
|
16240
|
+
/* @__PURE__ */ jsx7(KeyHint, { k: "C", label: "Instructions" }),
|
|
16241
|
+
/* @__PURE__ */ jsx7(KeyHint, { k: "A", label: "Agents" }),
|
|
16242
|
+
repoAreas.length > 0 && /* @__PURE__ */ jsx7(KeyHint, { k: "N", label: "Nested (areas)" }),
|
|
15381
16243
|
/* @__PURE__ */ jsx7(KeyHint, { k: "Esc", label: "Back" })
|
|
15382
16244
|
] }) : status === "generate-app-pick" ? /* @__PURE__ */ jsxs4(Box5, { children: [
|
|
15383
16245
|
/* @__PURE__ */ jsx7(KeyHint, { k: "R", label: "Root only" }),
|
|
@@ -15413,12 +16275,14 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
15413
16275
|
] }) : isLoading ? /* @__PURE__ */ jsx7(Box5, { children: /* @__PURE__ */ jsx7(KeyHint, { k: "Q", label: "Quit" }) }) : /* @__PURE__ */ jsxs4(Box5, { flexDirection: "column", children: [
|
|
15414
16276
|
/* @__PURE__ */ jsxs4(Box5, { children: [
|
|
15415
16277
|
/* @__PURE__ */ jsx7(KeyHint, { k: "G", label: "Generate" }),
|
|
16278
|
+
/* @__PURE__ */ jsx7(KeyHint, { k: "R", label: "Readiness" }),
|
|
15416
16279
|
/* @__PURE__ */ jsx7(KeyHint, { k: "E", label: "Eval" }),
|
|
15417
16280
|
/* @__PURE__ */ jsx7(KeyHint, { k: "B", label: "Batch" })
|
|
15418
16281
|
] }),
|
|
15419
16282
|
/* @__PURE__ */ jsxs4(Box5, { children: [
|
|
15420
16283
|
/* @__PURE__ */ jsx7(KeyHint, { k: "M", label: "Model" }),
|
|
15421
16284
|
/* @__PURE__ */ jsx7(KeyHint, { k: "J", label: "Judge" }),
|
|
16285
|
+
hasAgentrcConfig === false && /* @__PURE__ */ jsx7(KeyHint, { k: "C", label: "Create config" }),
|
|
15422
16286
|
/* @__PURE__ */ jsx7(KeyHint, { k: "Q", label: "Quit" })
|
|
15423
16287
|
] })
|
|
15424
16288
|
] }) })
|
|
@@ -15430,7 +16294,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
15430
16294
|
// src/commands/tui.tsx
|
|
15431
16295
|
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
15432
16296
|
async function tuiCommand(options) {
|
|
15433
|
-
const repoPath =
|
|
16297
|
+
const repoPath = path25.resolve(options.repo ?? process.cwd());
|
|
15434
16298
|
const skipAnimation = options.animation === false;
|
|
15435
16299
|
try {
|
|
15436
16300
|
const accessible = options.accessible ? true : void 0;
|
|
@@ -15445,7 +16309,7 @@ async function tuiCommand(options) {
|
|
|
15445
16309
|
}
|
|
15446
16310
|
|
|
15447
16311
|
// src/cli.ts
|
|
15448
|
-
var _require =
|
|
16312
|
+
var _require = createRequire2(import.meta.url);
|
|
15449
16313
|
var CLI_VERSION = _require("../package.json").version;
|
|
15450
16314
|
function withGlobalOpts(fn) {
|
|
15451
16315
|
return async (...raw) => {
|
|
@@ -15466,7 +16330,7 @@ function withGlobalOpts(fn) {
|
|
|
15466
16330
|
function runCli(argv) {
|
|
15467
16331
|
const program = new Command();
|
|
15468
16332
|
program.name("agentrc").description("Set up repositories for AI-assisted development").version(CLI_VERSION).option("--json", "Output machine-readable JSON to stdout").option("--quiet", "Suppress stderr progress output").option("--accessible", "Enable screen reader friendly output");
|
|
15469
|
-
program.command("init").description("
|
|
16333
|
+
program.command("init").description("Init repository \u2014 analyze & generate instructions").argument("[path]", "Path to a local repository").option("--github", "Use a GitHub repository").option("--provider <provider>", "Repo provider (github|azure)").option("--yes", "Accept defaults (generates instructions, MCP, and VS Code configs)").option("--force", "Overwrite existing files").option("--model <name>", "Model for instructions generation", DEFAULT_MODEL).action(withGlobalOpts(initCommand));
|
|
15470
16334
|
program.command("analyze").description("Detect languages, frameworks, monorepo structure, and areas").argument("[path]", "Path to a local repository").option("--output <path>", "Write report to file (.json or .md)").option("--force", "Overwrite existing output file").action(withGlobalOpts(analyzeCommand));
|
|
15471
16335
|
program.command("generate").description("Generate instructions, agents, MCP, or VS Code configs").addArgument(
|
|
15472
16336
|
new Argument("<type>", "Config type to generate").choices([
|
|
@@ -15475,14 +16339,14 @@ function runCli(argv) {
|
|
|
15475
16339
|
"mcp",
|
|
15476
16340
|
"vscode"
|
|
15477
16341
|
])
|
|
15478
|
-
).argument("[path]", "Path to a local repository").option("--force", "Overwrite existing files").option("--per-app", "
|
|
16342
|
+
).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));
|
|
15479
16343
|
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));
|
|
15480
16344
|
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));
|
|
15481
16345
|
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));
|
|
15482
|
-
program.command("instructions").description("Generate
|
|
15483
|
-
program.command("readiness").description("
|
|
16346
|
+
program.command("instructions").description("Generate instructions for the repository").option("--repo <path>", "Repository path", process.cwd()).option("--output <path>", "Output path for instructions").option("--model <name>", "Model for instructions generation", DEFAULT_MODEL).option("--force", "Overwrite existing area instruction files").option("--areas", "Also generate instructions for detected areas").option("--areas-only", "Generate only area instructions (skip root)").option("--area <name>", "Generate instructions for a specific area").option("--strategy <mode>", "Instruction strategy (flat or nested)").option("--claude-md", "Generate CLAUDE.md files alongside AGENTS.md (nested strategy)").option("--dry-run", "Preview generated files without writing anything").action(withGlobalOpts(instructionsCommand));
|
|
16347
|
+
program.command("readiness").description("Run readiness report across 9 maturity pillars").argument("[path]", "Path to a local repository").option("--output <path>", "Write report to file (.json, .md, or .html)").option("--force", "Overwrite existing output file").option("--visual", "Generate visual HTML report").option("--per-area", "Show per-area readiness breakdown").option("--policy <sources>", "Policy sources (comma-separated: paths, npm packages)").option("--fail-level <number>", "Exit with error if readiness level is below threshold (1\u20135)").action(withGlobalOpts(readinessCommand));
|
|
15484
16348
|
program.command("batch").description("Batch process multiple repos across orgs").argument("[repos...]", "Repos in owner/name form (GitHub) or org/project/repo (Azure)").option("--output <path>", "Write results JSON to file").option("--provider <provider>", "Repo provider (github|azure)", "github").option("--model <name>", "Model for instructions generation", DEFAULT_MODEL).option("--branch <name>", "Branch name for PRs").action(withGlobalOpts(batchCommand));
|
|
15485
|
-
program.command("batch-readiness").description("
|
|
16349
|
+
program.command("batch-readiness").description("Run batch readiness report for multiple repos").option("--output <path>", "Write HTML report to file").option("--policy <sources>", "Policy sources (comma-separated: paths, npm packages)").action(withGlobalOpts(batchReadinessCommand));
|
|
15486
16350
|
program.parse(argv);
|
|
15487
16351
|
}
|
|
15488
16352
|
|