@microsoft/agentrc 2.0.1-3 → 2.0.1-30
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 -230
- package/dist/index.js +1544 -856
- 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 +3 -3
package/dist/index.js
CHANGED
|
@@ -3052,7 +3052,7 @@ var require_main = __commonJS({
|
|
|
3052
3052
|
exports.createMessageConnection = exports.createServerSocketTransport = exports.createClientSocketTransport = exports.createServerPipeTransport = exports.createClientPipeTransport = exports.generateRandomPipeName = exports.StreamMessageWriter = exports.StreamMessageReader = exports.SocketMessageWriter = exports.SocketMessageReader = exports.PortMessageWriter = exports.PortMessageReader = exports.IPCMessageWriter = exports.IPCMessageReader = void 0;
|
|
3053
3053
|
var ril_1 = require_ril();
|
|
3054
3054
|
ril_1.default.install();
|
|
3055
|
-
var
|
|
3055
|
+
var path26 = __require("path");
|
|
3056
3056
|
var os2 = __require("os");
|
|
3057
3057
|
var crypto_1 = __require("crypto");
|
|
3058
3058
|
var net_1 = __require("net");
|
|
@@ -3188,9 +3188,9 @@ var require_main = __commonJS({
|
|
|
3188
3188
|
}
|
|
3189
3189
|
let result;
|
|
3190
3190
|
if (XDG_RUNTIME_DIR) {
|
|
3191
|
-
result =
|
|
3191
|
+
result = path26.join(XDG_RUNTIME_DIR, `vscode-ipc-${randomSuffix}.sock`);
|
|
3192
3192
|
} else {
|
|
3193
|
-
result =
|
|
3193
|
+
result = path26.join(os2.tmpdir(), `vscode-${randomSuffix}.sock`);
|
|
3194
3194
|
}
|
|
3195
3195
|
const limit = safeIpcPathLengths.get(process.platform);
|
|
3196
3196
|
if (limit !== void 0 && result.length > limit) {
|
|
@@ -3331,23 +3331,63 @@ function createSessionRpc(connection, sessionId) {
|
|
|
3331
3331
|
readFile: async (params) => connection.sendRequest("session.workspace.readFile", { sessionId, ...params }),
|
|
3332
3332
|
createFile: async (params) => connection.sendRequest("session.workspace.createFile", { sessionId, ...params })
|
|
3333
3333
|
},
|
|
3334
|
+
/** @experimental */
|
|
3334
3335
|
fleet: {
|
|
3335
3336
|
start: async (params) => connection.sendRequest("session.fleet.start", { sessionId, ...params })
|
|
3336
3337
|
},
|
|
3338
|
+
/** @experimental */
|
|
3337
3339
|
agent: {
|
|
3338
3340
|
list: async () => connection.sendRequest("session.agent.list", { sessionId }),
|
|
3339
3341
|
getCurrent: async () => connection.sendRequest("session.agent.getCurrent", { sessionId }),
|
|
3340
3342
|
select: async (params) => connection.sendRequest("session.agent.select", { sessionId, ...params }),
|
|
3341
|
-
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 })
|
|
3342
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 */
|
|
3343
3372
|
compaction: {
|
|
3344
3373
|
compact: async () => connection.sendRequest("session.compaction.compact", { sessionId })
|
|
3345
3374
|
},
|
|
3346
3375
|
tools: {
|
|
3347
3376
|
handlePendingToolCall: async (params) => connection.sendRequest("session.tools.handlePendingToolCall", { sessionId, ...params })
|
|
3348
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
|
+
},
|
|
3349
3384
|
permissions: {
|
|
3350
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 })
|
|
3351
3391
|
}
|
|
3352
3392
|
};
|
|
3353
3393
|
}
|
|
@@ -3369,13 +3409,30 @@ var init_sdkProtocolVersion = __esm({
|
|
|
3369
3409
|
}
|
|
3370
3410
|
});
|
|
3371
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
|
+
|
|
3372
3427
|
// node_modules/@github/copilot-sdk/dist/session.js
|
|
3373
|
-
var import_node, CopilotSession;
|
|
3428
|
+
var import_node, NO_RESULT_PERMISSION_V2_ERROR, CopilotSession;
|
|
3374
3429
|
var init_session = __esm({
|
|
3375
3430
|
"node_modules/@github/copilot-sdk/dist/session.js"() {
|
|
3376
3431
|
"use strict";
|
|
3377
3432
|
import_node = __toESM(require_node(), 1);
|
|
3378
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.";
|
|
3379
3436
|
CopilotSession = class {
|
|
3380
3437
|
/**
|
|
3381
3438
|
* Creates a new CopilotSession instance.
|
|
@@ -3383,12 +3440,14 @@ var init_session = __esm({
|
|
|
3383
3440
|
* @param sessionId - The unique identifier for this session
|
|
3384
3441
|
* @param connection - The JSON-RPC message connection to the Copilot CLI
|
|
3385
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
|
|
3386
3444
|
* @internal This constructor is internal. Use {@link CopilotClient.createSession} to create sessions.
|
|
3387
3445
|
*/
|
|
3388
|
-
constructor(sessionId, connection, _workspacePath) {
|
|
3446
|
+
constructor(sessionId, connection, _workspacePath, traceContextProvider) {
|
|
3389
3447
|
this.sessionId = sessionId;
|
|
3390
3448
|
this.connection = connection;
|
|
3391
3449
|
this._workspacePath = _workspacePath;
|
|
3450
|
+
this.traceContextProvider = traceContextProvider;
|
|
3392
3451
|
}
|
|
3393
3452
|
eventHandlers = /* @__PURE__ */ new Set();
|
|
3394
3453
|
typedEventHandlers = /* @__PURE__ */ new Map();
|
|
@@ -3396,7 +3455,9 @@ var init_session = __esm({
|
|
|
3396
3455
|
permissionHandler;
|
|
3397
3456
|
userInputHandler;
|
|
3398
3457
|
hooks;
|
|
3458
|
+
transformCallbacks;
|
|
3399
3459
|
_rpc = null;
|
|
3460
|
+
traceContextProvider;
|
|
3400
3461
|
/**
|
|
3401
3462
|
* Typed session-scoped RPC methods.
|
|
3402
3463
|
*/
|
|
@@ -3434,6 +3495,7 @@ var init_session = __esm({
|
|
|
3434
3495
|
*/
|
|
3435
3496
|
async send(options) {
|
|
3436
3497
|
const response = await this.connection.sendRequest("session.send", {
|
|
3498
|
+
...await getTraceContext(this.traceContextProvider),
|
|
3437
3499
|
sessionId: this.sessionId,
|
|
3438
3500
|
prompt: options.prompt,
|
|
3439
3501
|
attachments: options.attachments,
|
|
@@ -3563,9 +3625,19 @@ var init_session = __esm({
|
|
|
3563
3625
|
const { requestId, toolName } = event.data;
|
|
3564
3626
|
const args2 = event.data.arguments;
|
|
3565
3627
|
const toolCallId = event.data.toolCallId;
|
|
3628
|
+
const traceparent = event.data.traceparent;
|
|
3629
|
+
const tracestate = event.data.tracestate;
|
|
3566
3630
|
const handler = this.toolHandlers.get(toolName);
|
|
3567
3631
|
if (handler) {
|
|
3568
|
-
void this._executeToolAndRespond(
|
|
3632
|
+
void this._executeToolAndRespond(
|
|
3633
|
+
requestId,
|
|
3634
|
+
toolName,
|
|
3635
|
+
toolCallId,
|
|
3636
|
+
args2,
|
|
3637
|
+
handler,
|
|
3638
|
+
traceparent,
|
|
3639
|
+
tracestate
|
|
3640
|
+
);
|
|
3569
3641
|
}
|
|
3570
3642
|
} else if (event.type === "permission.requested") {
|
|
3571
3643
|
const { requestId, permissionRequest } = event.data;
|
|
@@ -3578,13 +3650,15 @@ var init_session = __esm({
|
|
|
3578
3650
|
* Executes a tool handler and sends the result back via RPC.
|
|
3579
3651
|
* @internal
|
|
3580
3652
|
*/
|
|
3581
|
-
async _executeToolAndRespond(requestId, toolName, toolCallId, args2, handler) {
|
|
3653
|
+
async _executeToolAndRespond(requestId, toolName, toolCallId, args2, handler, traceparent, tracestate) {
|
|
3582
3654
|
try {
|
|
3583
3655
|
const rawResult = await handler(args2, {
|
|
3584
3656
|
sessionId: this.sessionId,
|
|
3585
3657
|
toolCallId,
|
|
3586
3658
|
toolName,
|
|
3587
|
-
arguments: args2
|
|
3659
|
+
arguments: args2,
|
|
3660
|
+
traceparent,
|
|
3661
|
+
tracestate
|
|
3588
3662
|
});
|
|
3589
3663
|
let result;
|
|
3590
3664
|
if (rawResult == null) {
|
|
@@ -3615,6 +3689,9 @@ var init_session = __esm({
|
|
|
3615
3689
|
const result = await this.permissionHandler(permissionRequest, {
|
|
3616
3690
|
sessionId: this.sessionId
|
|
3617
3691
|
});
|
|
3692
|
+
if (result.kind === "no-result") {
|
|
3693
|
+
return;
|
|
3694
|
+
}
|
|
3618
3695
|
await this.rpc.permissions.handlePendingPermissionRequest({ requestId, result });
|
|
3619
3696
|
} catch (_error) {
|
|
3620
3697
|
try {
|
|
@@ -3695,6 +3772,40 @@ var init_session = __esm({
|
|
|
3695
3772
|
registerHooks(hooks) {
|
|
3696
3773
|
this.hooks = hooks;
|
|
3697
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
|
+
}
|
|
3698
3809
|
/**
|
|
3699
3810
|
* Handles a permission request in the v2 protocol format (synchronous RPC).
|
|
3700
3811
|
* Used as a back-compat adapter when connected to a v2 server.
|
|
@@ -3711,8 +3822,14 @@ var init_session = __esm({
|
|
|
3711
3822
|
const result = await this.permissionHandler(request, {
|
|
3712
3823
|
sessionId: this.sessionId
|
|
3713
3824
|
});
|
|
3825
|
+
if (result.kind === "no-result") {
|
|
3826
|
+
throw new Error(NO_RESULT_PERMISSION_V2_ERROR);
|
|
3827
|
+
}
|
|
3714
3828
|
return result;
|
|
3715
|
-
} catch (
|
|
3829
|
+
} catch (error) {
|
|
3830
|
+
if (error instanceof Error && error.message === NO_RESULT_PERMISSION_V2_ERROR) {
|
|
3831
|
+
throw error;
|
|
3832
|
+
}
|
|
3716
3833
|
return { kind: "denied-no-approval-rule-and-could-not-request-from-user" };
|
|
3717
3834
|
}
|
|
3718
3835
|
}
|
|
@@ -3868,14 +3985,35 @@ var init_session = __esm({
|
|
|
3868
3985
|
* The new model takes effect for the next message. Conversation history is preserved.
|
|
3869
3986
|
*
|
|
3870
3987
|
* @param model - Model ID to switch to
|
|
3988
|
+
* @param options - Optional settings for the new model
|
|
3871
3989
|
*
|
|
3872
3990
|
* @example
|
|
3873
3991
|
* ```typescript
|
|
3874
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 });
|
|
3875
4013
|
* ```
|
|
3876
4014
|
*/
|
|
3877
|
-
async
|
|
3878
|
-
await this.rpc.
|
|
4015
|
+
async log(message, options) {
|
|
4016
|
+
await this.rpc.log({ message, ...options });
|
|
3879
4017
|
}
|
|
3880
4018
|
};
|
|
3881
4019
|
}
|
|
@@ -3883,7 +4021,9 @@ var init_session = __esm({
|
|
|
3883
4021
|
|
|
3884
4022
|
// node_modules/@github/copilot-sdk/dist/client.js
|
|
3885
4023
|
import { spawn } from "child_process";
|
|
4024
|
+
import { randomUUID } from "crypto";
|
|
3886
4025
|
import { existsSync } from "fs";
|
|
4026
|
+
import { createRequire } from "module";
|
|
3887
4027
|
import { Socket } from "net";
|
|
3888
4028
|
import { dirname, join } from "path";
|
|
3889
4029
|
import { fileURLToPath } from "url";
|
|
@@ -3897,6 +4037,30 @@ function toJsonSchema(parameters) {
|
|
|
3897
4037
|
}
|
|
3898
4038
|
return parameters;
|
|
3899
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
|
+
}
|
|
3900
4064
|
function getNodeExecPath() {
|
|
3901
4065
|
if (process.versions.bun) {
|
|
3902
4066
|
return "node";
|
|
@@ -3914,6 +4078,7 @@ var init_client = __esm({
|
|
|
3914
4078
|
init_rpc();
|
|
3915
4079
|
init_sdkProtocolVersion();
|
|
3916
4080
|
init_session();
|
|
4081
|
+
init_telemetry();
|
|
3917
4082
|
MIN_PROTOCOL_VERSION = 2;
|
|
3918
4083
|
CopilotClient = class {
|
|
3919
4084
|
cliProcess = null;
|
|
@@ -3928,6 +4093,8 @@ var init_client = __esm({
|
|
|
3928
4093
|
options;
|
|
3929
4094
|
isExternalServer = false;
|
|
3930
4095
|
forceStopping = false;
|
|
4096
|
+
onListModels;
|
|
4097
|
+
onGetTraceContext;
|
|
3931
4098
|
modelsCache = null;
|
|
3932
4099
|
modelsCacheLock = Promise.resolve();
|
|
3933
4100
|
sessionLifecycleHandlers = /* @__PURE__ */ new Set();
|
|
@@ -3993,8 +4160,10 @@ var init_client = __esm({
|
|
|
3993
4160
|
if (options.isChildProcess) {
|
|
3994
4161
|
this.isExternalServer = true;
|
|
3995
4162
|
}
|
|
4163
|
+
this.onListModels = options.onListModels;
|
|
4164
|
+
this.onGetTraceContext = options.onGetTraceContext;
|
|
3996
4165
|
this.options = {
|
|
3997
|
-
cliPath: options.cliPath || getBundledCliPath(),
|
|
4166
|
+
cliPath: options.cliUrl ? void 0 : options.cliPath || getBundledCliPath(),
|
|
3998
4167
|
cliArgs: options.cliArgs ?? [],
|
|
3999
4168
|
cwd: options.cwd ?? process.cwd(),
|
|
4000
4169
|
port: options.port || 0,
|
|
@@ -4004,11 +4173,12 @@ var init_client = __esm({
|
|
|
4004
4173
|
cliUrl: options.cliUrl,
|
|
4005
4174
|
logLevel: options.logLevel || "debug",
|
|
4006
4175
|
autoStart: options.autoStart ?? true,
|
|
4007
|
-
autoRestart:
|
|
4176
|
+
autoRestart: false,
|
|
4008
4177
|
env: options.env ?? process.env,
|
|
4009
4178
|
githubToken: options.githubToken,
|
|
4010
4179
|
// Default useLoggedInUser to false when githubToken is provided, otherwise true
|
|
4011
|
-
useLoggedInUser: options.useLoggedInUser ?? (options.githubToken ? false : true)
|
|
4180
|
+
useLoggedInUser: options.useLoggedInUser ?? (options.githubToken ? false : true),
|
|
4181
|
+
telemetry: options.telemetry
|
|
4012
4182
|
};
|
|
4013
4183
|
}
|
|
4014
4184
|
/**
|
|
@@ -4260,36 +4430,13 @@ var init_client = __esm({
|
|
|
4260
4430
|
throw new Error("Client not connected. Call start() first.");
|
|
4261
4431
|
}
|
|
4262
4432
|
}
|
|
4263
|
-
const
|
|
4264
|
-
|
|
4265
|
-
sessionId
|
|
4266
|
-
|
|
4267
|
-
|
|
4268
|
-
|
|
4269
|
-
|
|
4270
|
-
description: tool.description,
|
|
4271
|
-
parameters: toJsonSchema(tool.parameters),
|
|
4272
|
-
overridesBuiltInTool: tool.overridesBuiltInTool
|
|
4273
|
-
})),
|
|
4274
|
-
systemMessage: config.systemMessage,
|
|
4275
|
-
availableTools: config.availableTools,
|
|
4276
|
-
excludedTools: config.excludedTools,
|
|
4277
|
-
provider: config.provider,
|
|
4278
|
-
requestPermission: true,
|
|
4279
|
-
requestUserInput: !!config.onUserInputRequest,
|
|
4280
|
-
hooks: !!(config.hooks && Object.values(config.hooks).some(Boolean)),
|
|
4281
|
-
workingDirectory: config.workingDirectory,
|
|
4282
|
-
streaming: config.streaming,
|
|
4283
|
-
mcpServers: config.mcpServers,
|
|
4284
|
-
envValueMode: "direct",
|
|
4285
|
-
customAgents: config.customAgents,
|
|
4286
|
-
configDir: config.configDir,
|
|
4287
|
-
skillDirectories: config.skillDirectories,
|
|
4288
|
-
disabledSkills: config.disabledSkills,
|
|
4289
|
-
infiniteSessions: config.infiniteSessions
|
|
4290
|
-
});
|
|
4291
|
-
const { sessionId, workspacePath } = response;
|
|
4292
|
-
const session = new CopilotSession(sessionId, this.connection, workspacePath);
|
|
4433
|
+
const sessionId = config.sessionId ?? randomUUID();
|
|
4434
|
+
const session = new CopilotSession(
|
|
4435
|
+
sessionId,
|
|
4436
|
+
this.connection,
|
|
4437
|
+
void 0,
|
|
4438
|
+
this.onGetTraceContext
|
|
4439
|
+
);
|
|
4293
4440
|
session.registerTools(config.tools);
|
|
4294
4441
|
session.registerPermissionHandler(config.onPermissionRequest);
|
|
4295
4442
|
if (config.onUserInputRequest) {
|
|
@@ -4298,7 +4445,54 @@ var init_client = __esm({
|
|
|
4298
4445
|
if (config.hooks) {
|
|
4299
4446
|
session.registerHooks(config.hooks);
|
|
4300
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
|
+
}
|
|
4301
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
|
+
}
|
|
4302
4496
|
return session;
|
|
4303
4497
|
}
|
|
4304
4498
|
/**
|
|
@@ -4338,37 +4532,12 @@ var init_client = __esm({
|
|
|
4338
4532
|
throw new Error("Client not connected. Call start() first.");
|
|
4339
4533
|
}
|
|
4340
4534
|
}
|
|
4341
|
-
const
|
|
4535
|
+
const session = new CopilotSession(
|
|
4342
4536
|
sessionId,
|
|
4343
|
-
|
|
4344
|
-
|
|
4345
|
-
|
|
4346
|
-
|
|
4347
|
-
availableTools: config.availableTools,
|
|
4348
|
-
excludedTools: config.excludedTools,
|
|
4349
|
-
tools: config.tools?.map((tool) => ({
|
|
4350
|
-
name: tool.name,
|
|
4351
|
-
description: tool.description,
|
|
4352
|
-
parameters: toJsonSchema(tool.parameters),
|
|
4353
|
-
overridesBuiltInTool: tool.overridesBuiltInTool
|
|
4354
|
-
})),
|
|
4355
|
-
provider: config.provider,
|
|
4356
|
-
requestPermission: true,
|
|
4357
|
-
requestUserInput: !!config.onUserInputRequest,
|
|
4358
|
-
hooks: !!(config.hooks && Object.values(config.hooks).some(Boolean)),
|
|
4359
|
-
workingDirectory: config.workingDirectory,
|
|
4360
|
-
configDir: config.configDir,
|
|
4361
|
-
streaming: config.streaming,
|
|
4362
|
-
mcpServers: config.mcpServers,
|
|
4363
|
-
envValueMode: "direct",
|
|
4364
|
-
customAgents: config.customAgents,
|
|
4365
|
-
skillDirectories: config.skillDirectories,
|
|
4366
|
-
disabledSkills: config.disabledSkills,
|
|
4367
|
-
infiniteSessions: config.infiniteSessions,
|
|
4368
|
-
disableResume: config.disableResume
|
|
4369
|
-
});
|
|
4370
|
-
const { sessionId: resumedSessionId, workspacePath } = response;
|
|
4371
|
-
const session = new CopilotSession(resumedSessionId, this.connection, workspacePath);
|
|
4537
|
+
this.connection,
|
|
4538
|
+
void 0,
|
|
4539
|
+
this.onGetTraceContext
|
|
4540
|
+
);
|
|
4372
4541
|
session.registerTools(config.tools);
|
|
4373
4542
|
session.registerPermissionHandler(config.onPermissionRequest);
|
|
4374
4543
|
if (config.onUserInputRequest) {
|
|
@@ -4377,7 +4546,55 @@ var init_client = __esm({
|
|
|
4377
4546
|
if (config.hooks) {
|
|
4378
4547
|
session.registerHooks(config.hooks);
|
|
4379
4548
|
}
|
|
4380
|
-
|
|
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
|
+
}
|
|
4381
4598
|
return session;
|
|
4382
4599
|
}
|
|
4383
4600
|
/**
|
|
@@ -4438,15 +4655,15 @@ var init_client = __esm({
|
|
|
4438
4655
|
/**
|
|
4439
4656
|
* List available models with their metadata.
|
|
4440
4657
|
*
|
|
4658
|
+
* If an `onListModels` handler was provided in the client options,
|
|
4659
|
+
* it is called instead of querying the CLI server.
|
|
4660
|
+
*
|
|
4441
4661
|
* Results are cached after the first successful call to avoid rate limiting.
|
|
4442
4662
|
* The cache is cleared when the client disconnects.
|
|
4443
4663
|
*
|
|
4444
|
-
* @throws Error if not
|
|
4664
|
+
* @throws Error if not connected (when no custom handler is set)
|
|
4445
4665
|
*/
|
|
4446
4666
|
async listModels() {
|
|
4447
|
-
if (!this.connection) {
|
|
4448
|
-
throw new Error("Client not connected");
|
|
4449
|
-
}
|
|
4450
4667
|
await this.modelsCacheLock;
|
|
4451
4668
|
let resolveLock;
|
|
4452
4669
|
this.modelsCacheLock = new Promise((resolve) => {
|
|
@@ -4456,10 +4673,18 @@ var init_client = __esm({
|
|
|
4456
4673
|
if (this.modelsCache !== null) {
|
|
4457
4674
|
return [...this.modelsCache];
|
|
4458
4675
|
}
|
|
4459
|
-
|
|
4460
|
-
|
|
4461
|
-
|
|
4462
|
-
|
|
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];
|
|
4463
4688
|
return [...models];
|
|
4464
4689
|
} finally {
|
|
4465
4690
|
resolveLock();
|
|
@@ -4672,6 +4897,27 @@ var init_client = __esm({
|
|
|
4672
4897
|
if (this.options.githubToken) {
|
|
4673
4898
|
envWithoutNodeDebug.COPILOT_SDK_AUTH_TOKEN = this.options.githubToken;
|
|
4674
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
|
+
}
|
|
4675
4921
|
if (!existsSync(this.options.cliPath)) {
|
|
4676
4922
|
throw new Error(
|
|
4677
4923
|
`Copilot CLI not found at ${this.options.cliPath}. Ensure @github/copilot is installed.`
|
|
@@ -4771,8 +5017,6 @@ stderr: ${stderrOutput}`
|
|
|
4771
5017
|
} else {
|
|
4772
5018
|
reject(new Error(`CLI server exited with code ${code}`));
|
|
4773
5019
|
}
|
|
4774
|
-
} else if (this.options.autoRestart && this.state === "connected") {
|
|
4775
|
-
void this.reconnect();
|
|
4776
5020
|
}
|
|
4777
5021
|
});
|
|
4778
5022
|
setTimeout(() => {
|
|
@@ -4877,12 +5121,15 @@ stderr: ${stderrOutput}`
|
|
|
4877
5121
|
"hooks.invoke",
|
|
4878
5122
|
async (params) => await this.handleHooksInvoke(params)
|
|
4879
5123
|
);
|
|
5124
|
+
this.connection.onRequest(
|
|
5125
|
+
"systemMessage.transform",
|
|
5126
|
+
async (params) => await this.handleSystemMessageTransform(params)
|
|
5127
|
+
);
|
|
4880
5128
|
this.connection.onClose(() => {
|
|
4881
|
-
|
|
4882
|
-
void this.reconnect();
|
|
4883
|
-
}
|
|
5129
|
+
this.state = "disconnected";
|
|
4884
5130
|
});
|
|
4885
5131
|
this.connection.onError((_error) => {
|
|
5132
|
+
this.state = "disconnected";
|
|
4886
5133
|
});
|
|
4887
5134
|
}
|
|
4888
5135
|
handleSessionEventNotification(notification) {
|
|
@@ -4941,6 +5188,16 @@ stderr: ${stderrOutput}`
|
|
|
4941
5188
|
const output = await session._handleHooksInvoke(params.hookType, params.input);
|
|
4942
5189
|
return { output };
|
|
4943
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
|
+
}
|
|
4944
5201
|
// ========================================================================
|
|
4945
5202
|
// Protocol v2 backward-compatibility adapters
|
|
4946
5203
|
// ========================================================================
|
|
@@ -4969,11 +5226,15 @@ stderr: ${stderrOutput}`
|
|
|
4969
5226
|
};
|
|
4970
5227
|
}
|
|
4971
5228
|
try {
|
|
5229
|
+
const traceparent = params.traceparent;
|
|
5230
|
+
const tracestate = params.tracestate;
|
|
4972
5231
|
const invocation = {
|
|
4973
5232
|
sessionId: params.sessionId,
|
|
4974
5233
|
toolCallId: params.toolCallId,
|
|
4975
5234
|
toolName: params.toolName,
|
|
4976
|
-
arguments: params.arguments
|
|
5235
|
+
arguments: params.arguments,
|
|
5236
|
+
traceparent,
|
|
5237
|
+
tracestate
|
|
4977
5238
|
};
|
|
4978
5239
|
const result = await handler(params.arguments, invocation);
|
|
4979
5240
|
return { result: this.normalizeToolResultV2(result) };
|
|
@@ -5003,7 +5264,10 @@ stderr: ${stderrOutput}`
|
|
|
5003
5264
|
try {
|
|
5004
5265
|
const result = await session._handlePermissionRequestV2(params.permissionRequest);
|
|
5005
5266
|
return { result };
|
|
5006
|
-
} catch (
|
|
5267
|
+
} catch (error) {
|
|
5268
|
+
if (error instanceof Error && error.message === NO_RESULT_PERMISSION_V2_ERROR) {
|
|
5269
|
+
throw error;
|
|
5270
|
+
}
|
|
5007
5271
|
return {
|
|
5008
5272
|
result: {
|
|
5009
5273
|
kind: "denied-no-approval-rule-and-could-not-request-from-user"
|
|
@@ -5033,17 +5297,6 @@ stderr: ${stderrOutput}`
|
|
|
5033
5297
|
isToolResultObject(value) {
|
|
5034
5298
|
return typeof value === "object" && value !== null && "textResultForLlm" in value && typeof value.textResultForLlm === "string" && "resultType" in value;
|
|
5035
5299
|
}
|
|
5036
|
-
/**
|
|
5037
|
-
* Attempt to reconnect to the server
|
|
5038
|
-
*/
|
|
5039
|
-
async reconnect() {
|
|
5040
|
-
this.state = "disconnected";
|
|
5041
|
-
try {
|
|
5042
|
-
await this.stop();
|
|
5043
|
-
await this.start();
|
|
5044
|
-
} catch (_error) {
|
|
5045
|
-
}
|
|
5046
|
-
}
|
|
5047
5300
|
};
|
|
5048
5301
|
}
|
|
5049
5302
|
});
|
|
@@ -5052,10 +5305,24 @@ stderr: ${stderrOutput}`
|
|
|
5052
5305
|
function defineTool(name, config) {
|
|
5053
5306
|
return { name, ...config };
|
|
5054
5307
|
}
|
|
5055
|
-
var approveAll;
|
|
5308
|
+
var SYSTEM_PROMPT_SECTIONS, approveAll;
|
|
5056
5309
|
var init_types = __esm({
|
|
5057
5310
|
"node_modules/@github/copilot-sdk/dist/types.js"() {
|
|
5058
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
|
+
};
|
|
5059
5326
|
approveAll = () => ({ kind: "approved" });
|
|
5060
5327
|
}
|
|
5061
5328
|
});
|
|
@@ -5065,6 +5332,7 @@ var dist_exports = {};
|
|
|
5065
5332
|
__export(dist_exports, {
|
|
5066
5333
|
CopilotClient: () => CopilotClient,
|
|
5067
5334
|
CopilotSession: () => CopilotSession,
|
|
5335
|
+
SYSTEM_PROMPT_SECTIONS: () => SYSTEM_PROMPT_SECTIONS,
|
|
5068
5336
|
approveAll: () => approveAll,
|
|
5069
5337
|
defineTool: () => defineTool
|
|
5070
5338
|
});
|
|
@@ -5078,7 +5346,7 @@ var init_dist = __esm({
|
|
|
5078
5346
|
});
|
|
5079
5347
|
|
|
5080
5348
|
// src/cli.ts
|
|
5081
|
-
import { createRequire } from "module";
|
|
5349
|
+
import { createRequire as createRequire2 } from "module";
|
|
5082
5350
|
|
|
5083
5351
|
// packages/core/src/config.ts
|
|
5084
5352
|
var DEFAULT_MODEL = "claude-sonnet-4.6";
|
|
@@ -5334,6 +5602,18 @@ async function fileExists(filePath) {
|
|
|
5334
5602
|
return false;
|
|
5335
5603
|
}
|
|
5336
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
|
+
}
|
|
5337
5617
|
async function safeReadDir(dirPath) {
|
|
5338
5618
|
try {
|
|
5339
5619
|
return await fs.readdir(dirPath);
|
|
@@ -5341,10 +5621,68 @@ async function safeReadDir(dirPath) {
|
|
|
5341
5621
|
return [];
|
|
5342
5622
|
}
|
|
5343
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
|
+
}
|
|
5344
5682
|
async function readJson(filePath) {
|
|
5345
5683
|
try {
|
|
5346
5684
|
const raw = await fs.readFile(filePath, "utf8");
|
|
5347
|
-
return JSON.parse(raw);
|
|
5685
|
+
return JSON.parse(stripJsonComments(raw));
|
|
5348
5686
|
} catch {
|
|
5349
5687
|
return void 0;
|
|
5350
5688
|
}
|
|
@@ -6674,7 +7012,7 @@ async function checkReposForInstructions(token, repos, onProgress) {
|
|
|
6674
7012
|
}
|
|
6675
7013
|
|
|
6676
7014
|
// packages/core/src/services/batch.ts
|
|
6677
|
-
import
|
|
7015
|
+
import path13 from "path";
|
|
6678
7016
|
|
|
6679
7017
|
// packages/core/src/utils/pr.ts
|
|
6680
7018
|
function buildInstructionsPrBody() {
|
|
@@ -6958,7 +7296,7 @@ async function checkReposForInstructions2(token, repos, onProgress) {
|
|
|
6958
7296
|
|
|
6959
7297
|
// packages/core/src/services/instructions.ts
|
|
6960
7298
|
import fs5 from "fs/promises";
|
|
6961
|
-
import
|
|
7299
|
+
import path7 from "path";
|
|
6962
7300
|
|
|
6963
7301
|
// packages/core/src/services/copilot.ts
|
|
6964
7302
|
import fs4 from "fs/promises";
|
|
@@ -7001,8 +7339,32 @@ async function assertCopilotCliReady() {
|
|
|
7001
7339
|
async function listCopilotModels() {
|
|
7002
7340
|
const config = await assertCopilotCliReady();
|
|
7003
7341
|
const [cmd, args2] = buildExecArgs(config, ["--help"]);
|
|
7004
|
-
|
|
7005
|
-
|
|
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 [];
|
|
7006
7368
|
}
|
|
7007
7369
|
function buildExecArgs(config, extraArgs) {
|
|
7008
7370
|
if (config.cliArgs && config.cliArgs.length > 0) {
|
|
@@ -7378,6 +7740,25 @@ async function createCopilotClient(cliConfig) {
|
|
|
7378
7740
|
}
|
|
7379
7741
|
}
|
|
7380
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
|
+
|
|
7381
7762
|
// packages/core/src/services/instructions.ts
|
|
7382
7763
|
async function detectExistingInstructions(repoPath, detailDirName = ".agents") {
|
|
7383
7764
|
const { agentsMdFiles, claudeMdFiles } = await findInstructionMarkerFiles(repoPath);
|
|
@@ -7401,7 +7782,7 @@ async function findInstructionMarkerFiles(repoPath) {
|
|
|
7401
7782
|
claudeMdFiles.push(relPath ? `${relPath}/${entry.name}` : entry.name);
|
|
7402
7783
|
}
|
|
7403
7784
|
} else if (entry.isDirectory()) {
|
|
7404
|
-
await walk(
|
|
7785
|
+
await walk(path7.join(dir, entry.name), relPath ? `${relPath}/${entry.name}` : entry.name);
|
|
7405
7786
|
}
|
|
7406
7787
|
}
|
|
7407
7788
|
}
|
|
@@ -7409,7 +7790,7 @@ async function findInstructionMarkerFiles(repoPath) {
|
|
|
7409
7790
|
return { agentsMdFiles: agentsMdFiles.sort(), claudeMdFiles: claudeMdFiles.sort() };
|
|
7410
7791
|
}
|
|
7411
7792
|
async function findModularInstructionFiles(repoPath) {
|
|
7412
|
-
const dir =
|
|
7793
|
+
const dir = path7.join(repoPath, ".github", "instructions");
|
|
7413
7794
|
const entries = await fs5.readdir(dir, { withFileTypes: true }).catch(() => []);
|
|
7414
7795
|
return entries.filter((e) => !e.isSymbolicLink() && e.isFile() && e.name.endsWith(".instructions.md")).map((e) => `.github/instructions/${e.name}`).sort();
|
|
7415
7796
|
}
|
|
@@ -7423,7 +7804,7 @@ async function findDetailFiles(repoPath, detailDirName) {
|
|
|
7423
7804
|
if (entry.isSymbolicLink()) continue;
|
|
7424
7805
|
if (entry.isDirectory()) {
|
|
7425
7806
|
if (entry.name === detailDirName) {
|
|
7426
|
-
const detailDir =
|
|
7807
|
+
const detailDir = path7.join(dir, entry.name);
|
|
7427
7808
|
const detailEntries = await fs5.readdir(detailDir, { withFileTypes: true }).catch(() => []);
|
|
7428
7809
|
for (const de of detailEntries) {
|
|
7429
7810
|
if (!de.isSymbolicLink() && de.isFile() && de.name.endsWith(".md")) {
|
|
@@ -7432,7 +7813,7 @@ async function findDetailFiles(repoPath, detailDirName) {
|
|
|
7432
7813
|
}
|
|
7433
7814
|
}
|
|
7434
7815
|
} else {
|
|
7435
|
-
await walk(
|
|
7816
|
+
await walk(path7.join(dir, entry.name), relPath ? `${relPath}/${entry.name}` : entry.name);
|
|
7436
7817
|
}
|
|
7437
7818
|
}
|
|
7438
7819
|
}
|
|
@@ -7514,11 +7895,11 @@ function isCopilotAuthError(error) {
|
|
|
7514
7895
|
return error instanceof Error && error.message.includes("Copilot CLI not logged in.");
|
|
7515
7896
|
}
|
|
7516
7897
|
function resolveAreaWorkingDirectory(repoPath, area) {
|
|
7517
|
-
const repoRoot =
|
|
7898
|
+
const repoRoot = path7.resolve(repoPath);
|
|
7518
7899
|
const rawWorkingDirectory = area?.workingDirectory ?? area?.path;
|
|
7519
7900
|
if (!rawWorkingDirectory) return repoRoot;
|
|
7520
|
-
const resolved = area?.workingDirectory ?
|
|
7521
|
-
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)) {
|
|
7522
7903
|
throw new Error(`Invalid workingDirectory "${rawWorkingDirectory}": escapes repo boundary`);
|
|
7523
7904
|
}
|
|
7524
7905
|
return resolved;
|
|
@@ -7550,6 +7931,7 @@ async function generateCopilotInstructions(options) {
|
|
|
7550
7931
|
const preferredModel = options.model ?? DEFAULT_MODEL;
|
|
7551
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.";
|
|
7552
7933
|
const { tool: emitTool, getContent } = await createEmitTool();
|
|
7934
|
+
const rootSkillDir = getSkillDirectory("root-instructions");
|
|
7553
7935
|
const session = await client.createSession({
|
|
7554
7936
|
model: preferredModel,
|
|
7555
7937
|
streaming: true,
|
|
@@ -7560,7 +7942,8 @@ async function generateCopilotInstructions(options) {
|
|
|
7560
7942
|
tools: [emitTool],
|
|
7561
7943
|
excludedTools: INSTRUCTION_GENERATION_EXCLUDED_TOOLS,
|
|
7562
7944
|
onPermissionRequest: READ_ONLY_PERMISSION_HANDLER,
|
|
7563
|
-
infiniteSessions: { enabled: false }
|
|
7945
|
+
infiniteSessions: { enabled: false },
|
|
7946
|
+
skillDirectories: [rootSkillDir]
|
|
7564
7947
|
});
|
|
7565
7948
|
await trySetAutopilot(session);
|
|
7566
7949
|
let content = "";
|
|
@@ -7581,22 +7964,8 @@ async function generateCopilotInstructions(options) {
|
|
|
7581
7964
|
sessionError = getSessionError(errorMsg);
|
|
7582
7965
|
}
|
|
7583
7966
|
});
|
|
7584
|
-
const prompt =
|
|
7585
|
-
|
|
7586
|
-
Fan out multiple Explore subagents to map out the codebase in parallel:
|
|
7587
|
-
1. Check for existing instruction files: glob for **/{.github/copilot-instructions.md,AGENT.md,CLAUDE.md,.cursorrules,README.md}
|
|
7588
|
-
2. Identify the tech stack: look at package.json, tsconfig.json, pyproject.toml, Cargo.toml, go.mod, *.csproj, *.fsproj, *.sln, global.json, build.gradle, pom.xml, etc.
|
|
7589
|
-
3. Understand the structure: list key directories
|
|
7590
|
-
4. Detect monorepo structures: check for workspace configs (npm/pnpm/yarn workspaces, Cargo.toml [workspace], go.work, .sln solution files, settings.gradle include directives, pom.xml modules)
|
|
7591
|
-
|
|
7592
|
-
Generate concise instructions (~20-50 lines) covering:
|
|
7593
|
-
- Tech stack and architecture
|
|
7594
|
-
- Build/test commands
|
|
7595
|
-
- Project-specific conventions
|
|
7596
|
-
- Key files/directories
|
|
7597
|
-
- Monorepo structure and per-app layout (if this is a monorepo, describe the workspace organization, how apps relate to each other, and any shared libraries)
|
|
7598
|
-
${existingSection}
|
|
7599
|
-
When you have the complete markdown content, call the \`emit_file_content\` tool with it. Do NOT output the file content directly in chat.`;
|
|
7967
|
+
const prompt = `/root-instructions Analyze this codebase and generate a .github/copilot-instructions.md file.
|
|
7968
|
+
${existingSection}`;
|
|
7600
7969
|
progress("Analyzing codebase...");
|
|
7601
7970
|
let sendError;
|
|
7602
7971
|
try {
|
|
@@ -7633,6 +8002,7 @@ async function generateAreaInstructions(options) {
|
|
|
7633
8002
|
const preferredModel = options.model ?? DEFAULT_MODEL;
|
|
7634
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.`;
|
|
7635
8004
|
const { tool: emitTool, getContent } = await createEmitTool();
|
|
8005
|
+
const areaSkillDir = getSkillDirectory("area-instructions");
|
|
7636
8006
|
const session = await client.createSession({
|
|
7637
8007
|
model: preferredModel,
|
|
7638
8008
|
streaming: true,
|
|
@@ -7643,7 +8013,8 @@ async function generateAreaInstructions(options) {
|
|
|
7643
8013
|
tools: [emitTool],
|
|
7644
8014
|
excludedTools: INSTRUCTION_GENERATION_EXCLUDED_TOOLS,
|
|
7645
8015
|
onPermissionRequest: READ_ONLY_PERMISSION_HANDLER,
|
|
7646
|
-
infiniteSessions: { enabled: false }
|
|
8016
|
+
infiniteSessions: { enabled: false },
|
|
8017
|
+
skillDirectories: [areaSkillDir]
|
|
7647
8018
|
});
|
|
7648
8019
|
await trySetAutopilot(session);
|
|
7649
8020
|
let content = "";
|
|
@@ -7664,30 +8035,13 @@ async function generateAreaInstructions(options) {
|
|
|
7664
8035
|
sessionError = getSessionError(errorMsg);
|
|
7665
8036
|
}
|
|
7666
8037
|
});
|
|
7667
|
-
const prompt =
|
|
8038
|
+
const prompt = `/area-instructions Analyze the "${area.name}" area of this codebase and generate an area instruction file.
|
|
7668
8039
|
|
|
7669
8040
|
This area covers files matching: ${applyToStr}
|
|
7670
8041
|
${area.description ? `Description: ${area.description}` : ""}
|
|
7671
|
-
|
|
7672
|
-
|
|
7673
|
-
|
|
7674
|
-
2. Identify the tech stack, dependencies, and frameworks used in this area
|
|
7675
|
-
3. Look at key source files to understand patterns and conventions specific to this area
|
|
7676
|
-
|
|
7677
|
-
Generate concise instructions (~10-30 lines) covering:
|
|
7678
|
-
- What this area does and its role in the overall project
|
|
7679
|
-
- Area-specific tech stack, dependencies, and frameworks
|
|
7680
|
-
- Coding conventions and patterns specific to this area
|
|
7681
|
-
- Build/test commands relevant to this area (if different from root)
|
|
7682
|
-
- Key files and directory structure within this area
|
|
7683
|
-
|
|
7684
|
-
IMPORTANT:
|
|
7685
|
-
- Focus ONLY on this specific area, not the whole repo
|
|
7686
|
-
- Do NOT repeat repo-wide information (that goes in the root copilot-instructions.md)
|
|
7687
|
-
- Keep it complementary to root instructions
|
|
7688
|
-
${existingSection ? `- Do NOT duplicate content already covered by existing instruction files
|
|
7689
|
-
${existingSection}` : ""}
|
|
7690
|
-
- When you have the complete markdown content, call the \`emit_file_content\` tool with it. Do NOT output the file content directly in chat.`;
|
|
8042
|
+
${existingSection ? `
|
|
8043
|
+
Do NOT duplicate content already covered by existing instruction files
|
|
8044
|
+
${existingSection}` : ""}`;
|
|
7691
8045
|
progress(`Analyzing area "${area.name}"...`);
|
|
7692
8046
|
let sendError;
|
|
7693
8047
|
try {
|
|
@@ -7724,7 +8078,7 @@ ${body}
|
|
|
7724
8078
|
`;
|
|
7725
8079
|
}
|
|
7726
8080
|
function areaInstructionPath(repoPath, area) {
|
|
7727
|
-
return
|
|
8081
|
+
return path7.join(
|
|
7728
8082
|
repoPath,
|
|
7729
8083
|
".github",
|
|
7730
8084
|
"instructions",
|
|
@@ -7734,7 +8088,7 @@ function areaInstructionPath(repoPath, area) {
|
|
|
7734
8088
|
async function writeAreaInstruction(repoPath, area, body, force) {
|
|
7735
8089
|
const filePath = areaInstructionPath(repoPath, area);
|
|
7736
8090
|
if (!body.trim()) return { status: "empty", filePath };
|
|
7737
|
-
await ensureDir(
|
|
8091
|
+
await ensureDir(path7.dirname(filePath));
|
|
7738
8092
|
const { wrote, reason } = await safeWriteFile(
|
|
7739
8093
|
filePath,
|
|
7740
8094
|
buildAreaInstructionContent(area, body),
|
|
@@ -7746,13 +8100,13 @@ async function writeAreaInstruction(repoPath, area, body, force) {
|
|
|
7746
8100
|
return { status: "written", filePath };
|
|
7747
8101
|
}
|
|
7748
8102
|
async function writeInstructionFile(repoPath, relativePath, content, force) {
|
|
7749
|
-
const resolvedRoot =
|
|
7750
|
-
const filePath =
|
|
7751
|
-
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) {
|
|
7752
8106
|
throw new Error(`Invalid path: escapes repository root (${relativePath})`);
|
|
7753
8107
|
}
|
|
7754
8108
|
if (!content.trim()) return { status: "empty", filePath };
|
|
7755
|
-
await ensureDir(
|
|
8109
|
+
await ensureDir(path7.dirname(filePath));
|
|
7756
8110
|
const { wrote, reason } = await safeWriteFile(filePath, content, Boolean(force));
|
|
7757
8111
|
if (!wrote) {
|
|
7758
8112
|
return { status: reason === "symlink" ? "symlink" : "skipped", filePath };
|
|
@@ -7836,6 +8190,7 @@ async function generateNestedHub(client, options) {
|
|
|
7836
8190
|
const existingCtx = await detectExistingInstructions(options.repoPath, options.detailDir);
|
|
7837
8191
|
const existingSection = buildExistingInstructionsSection(existingCtx);
|
|
7838
8192
|
const { tool: emitTool, getContent } = await createEmitTool();
|
|
8193
|
+
const nestedSkillDir = getSkillDirectory("nested-hub");
|
|
7839
8194
|
const session = await client.createSession({
|
|
7840
8195
|
model,
|
|
7841
8196
|
streaming: true,
|
|
@@ -7846,7 +8201,8 @@ async function generateNestedHub(client, options) {
|
|
|
7846
8201
|
tools: [emitTool],
|
|
7847
8202
|
excludedTools: INSTRUCTION_GENERATION_EXCLUDED_TOOLS,
|
|
7848
8203
|
onPermissionRequest: READ_ONLY_PERMISSION_HANDLER,
|
|
7849
|
-
infiniteSessions: { enabled: false }
|
|
8204
|
+
infiniteSessions: { enabled: false },
|
|
8205
|
+
skillDirectories: [nestedSkillDir]
|
|
7850
8206
|
});
|
|
7851
8207
|
await trySetAutopilot(session);
|
|
7852
8208
|
let content = "";
|
|
@@ -7878,29 +8234,14 @@ ${options.childAreas.map((c) => `- ${c.name} (${c.path ?? "unknown path"})`).joi
|
|
|
7878
8234
|
Include a "## Sub-Projects" section with links to each child's AGENTS.md.` : "";
|
|
7879
8235
|
const parentContext = options.area?.parentArea ? `
|
|
7880
8236
|
This is a sub-project of "${options.area.parentArea}". Include a note linking back to the parent area.` : "";
|
|
7881
|
-
const prompt =
|
|
7882
|
-
|
|
7883
|
-
Use tools to explore the codebase structure, tech stack, and conventions.
|
|
8237
|
+
const prompt = `/nested-hub Generate a lean AGENTS.md hub file (~90-120 lines).${areaContext}${parentContext}
|
|
7884
8238
|
|
|
7885
|
-
|
|
7886
|
-
- Project overview and purpose
|
|
7887
|
-
- Key concepts and architecture
|
|
7888
|
-
- Coding conventions and guardrails
|
|
7889
|
-
- A "## Detailed Instructions" section listing links to detail files in \`${options.detailDir}/\`${childContext}
|
|
8239
|
+
Detail files go in \`${options.detailDir}/\`.${childContext}
|
|
7890
8240
|
|
|
7891
|
-
|
|
7892
|
-
|
|
7893
|
-
|
|
7894
|
-
|
|
7895
|
-
|
|
7896
|
-
Recommend 3-5 topics that would benefit from deep-dive detail files. Each slug becomes a filename: \`${options.detailDir}/{slug}.md\`.
|
|
7897
|
-
|
|
7898
|
-
IMPORTANT:
|
|
7899
|
-
- Keep the hub LEAN \u2014 overview and guardrails only, details go in separate files
|
|
7900
|
-
- The JSON block will be parsed and removed from the final output
|
|
7901
|
-
${existingSection ? `- Do NOT duplicate content from existing instruction files
|
|
7902
|
-
${existingSection}` : ""}
|
|
7903
|
-
- When you have the complete markdown content (including the trailing JSON topic block), call the \`emit_file_content\` tool with it. Do NOT output the content directly in chat.`;
|
|
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}` : ""}`;
|
|
7904
8245
|
let sendError;
|
|
7905
8246
|
try {
|
|
7906
8247
|
await session.sendAndWait({ prompt }, 18e4);
|
|
@@ -7924,6 +8265,7 @@ async function generateNestedDetail(client, options) {
|
|
|
7924
8265
|
});
|
|
7925
8266
|
const model = options.model ?? DEFAULT_MODEL;
|
|
7926
8267
|
const { tool: emitTool, getContent } = await createEmitTool();
|
|
8268
|
+
const detailSkillDir = getSkillDirectory("nested-detail");
|
|
7927
8269
|
const session = await client.createSession({
|
|
7928
8270
|
model,
|
|
7929
8271
|
streaming: true,
|
|
@@ -7934,7 +8276,8 @@ async function generateNestedDetail(client, options) {
|
|
|
7934
8276
|
tools: [emitTool],
|
|
7935
8277
|
excludedTools: INSTRUCTION_GENERATION_EXCLUDED_TOOLS,
|
|
7936
8278
|
onPermissionRequest: READ_ONLY_PERMISSION_HANDLER,
|
|
7937
|
-
infiniteSessions: { enabled: false }
|
|
8279
|
+
infiniteSessions: { enabled: false },
|
|
8280
|
+
skillDirectories: [detailSkillDir]
|
|
7938
8281
|
});
|
|
7939
8282
|
await trySetAutopilot(session);
|
|
7940
8283
|
let content = "";
|
|
@@ -7956,22 +8299,11 @@ async function generateNestedDetail(client, options) {
|
|
|
7956
8299
|
}
|
|
7957
8300
|
});
|
|
7958
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.";
|
|
7959
|
-
const prompt =
|
|
8302
|
+
const prompt = `/nested-detail Generate a deep-dive instruction file about "${options.topic.title}" for this codebase.
|
|
7960
8303
|
${areaContext}
|
|
7961
8304
|
|
|
7962
8305
|
Topic: ${options.topic.title}
|
|
7963
|
-
Description: ${options.topic.description}
|
|
7964
|
-
|
|
7965
|
-
Use tools to explore the codebase and understand the specific patterns, APIs, and conventions related to this topic.
|
|
7966
|
-
|
|
7967
|
-
The file should:
|
|
7968
|
-
- Start with \`# ${options.topic.title}\`
|
|
7969
|
-
- Include \`**When to read:** {one-line trigger condition}\` right after the heading
|
|
7970
|
-
- Cover ~50-100 lines of practical, actionable guidance
|
|
7971
|
-
- Include code patterns and examples found in the actual codebase
|
|
7972
|
-
- Be specific to this codebase, not generic advice
|
|
7973
|
-
|
|
7974
|
-
When you have the complete markdown content, call the \`emit_file_content\` tool with it. Do NOT output the content directly in chat.`;
|
|
8306
|
+
Description: ${options.topic.description}`;
|
|
7975
8307
|
let sendError;
|
|
7976
8308
|
try {
|
|
7977
8309
|
await session.sendAndWait({ prompt }, 18e4);
|
|
@@ -8006,7 +8338,7 @@ async function generateNestedInstructions(options) {
|
|
|
8006
8338
|
onProgress: options.onProgress
|
|
8007
8339
|
});
|
|
8008
8340
|
const basePath = options.area?.path ?? ".";
|
|
8009
|
-
const hubRelativePath =
|
|
8341
|
+
const hubRelativePath = path7.join(basePath, "AGENTS.md");
|
|
8010
8342
|
let finalHubContent = hubContent;
|
|
8011
8343
|
if (options.area) {
|
|
8012
8344
|
finalHubContent = `${buildAreaFrontmatter(options.area)}
|
|
@@ -8030,7 +8362,7 @@ ${hubContent}`;
|
|
|
8030
8362
|
});
|
|
8031
8363
|
if (detailContent) {
|
|
8032
8364
|
result.details.push({
|
|
8033
|
-
relativePath:
|
|
8365
|
+
relativePath: path7.join(basePath, options.detailDir, `${topic.slug}.md`),
|
|
8034
8366
|
content: detailContent,
|
|
8035
8367
|
topic: topic.title
|
|
8036
8368
|
});
|
|
@@ -8045,7 +8377,7 @@ ${hubContent}`;
|
|
|
8045
8377
|
}
|
|
8046
8378
|
if (options.claudeMd) {
|
|
8047
8379
|
result.claudeMd = {
|
|
8048
|
-
relativePath:
|
|
8380
|
+
relativePath: path7.join(basePath, "CLAUDE.md"),
|
|
8049
8381
|
content: "@AGENTS.md\n"
|
|
8050
8382
|
};
|
|
8051
8383
|
}
|
|
@@ -8066,13 +8398,12 @@ async function generateNestedAreaInstructions(options) {
|
|
|
8066
8398
|
});
|
|
8067
8399
|
}
|
|
8068
8400
|
|
|
8069
|
-
// packages/core/src/services/readiness.ts
|
|
8070
|
-
import
|
|
8071
|
-
import path8 from "path";
|
|
8401
|
+
// packages/core/src/services/readiness/index.ts
|
|
8402
|
+
import path12 from "path";
|
|
8072
8403
|
|
|
8073
8404
|
// packages/core/src/services/policy.ts
|
|
8074
8405
|
import fs6 from "fs/promises";
|
|
8075
|
-
import
|
|
8406
|
+
import path8 from "path";
|
|
8076
8407
|
var DEFAULT_PASS_RATE = 0.8;
|
|
8077
8408
|
function validatePolicyConfig(obj, source, format = "module") {
|
|
8078
8409
|
if (typeof obj !== "object" || obj === null) {
|
|
@@ -8165,8 +8496,8 @@ function parsePolicySources(raw) {
|
|
|
8165
8496
|
}
|
|
8166
8497
|
async function loadPolicy(source, options) {
|
|
8167
8498
|
const jsonOnly = options?.jsonOnly ?? false;
|
|
8168
|
-
if (source.startsWith(".") ||
|
|
8169
|
-
const resolved =
|
|
8499
|
+
if (source.startsWith(".") || path8.isAbsolute(source)) {
|
|
8500
|
+
const resolved = path8.resolve(source);
|
|
8170
8501
|
if (resolved.endsWith(".json")) {
|
|
8171
8502
|
const data = await readJson(resolved);
|
|
8172
8503
|
if (!data) {
|
|
@@ -8193,7 +8524,7 @@ async function loadPolicy(source, options) {
|
|
|
8193
8524
|
}
|
|
8194
8525
|
try {
|
|
8195
8526
|
const raw = await fs6.readFile(resolved, "utf8");
|
|
8196
|
-
const data = JSON.parse(raw);
|
|
8527
|
+
const data = JSON.parse(stripJsonComments(raw));
|
|
8197
8528
|
return validatePolicyConfig(data, source, "json");
|
|
8198
8529
|
} catch {
|
|
8199
8530
|
throw new Error(
|
|
@@ -8749,252 +9080,382 @@ function wrapImperativePolicy(config, baseCriteria) {
|
|
|
8749
9080
|
return { plugin, compiled };
|
|
8750
9081
|
}
|
|
8751
9082
|
|
|
8752
|
-
// packages/core/src/services/readiness.ts
|
|
8753
|
-
|
|
8754
|
-
|
|
8755
|
-
|
|
8756
|
-
|
|
8757
|
-
documentation: "repo-health",
|
|
8758
|
-
"dev-environment": "repo-health",
|
|
8759
|
-
"code-quality": "repo-health",
|
|
8760
|
-
observability: "repo-health",
|
|
8761
|
-
"security-governance": "repo-health",
|
|
8762
|
-
"ai-tooling": "ai-setup"
|
|
8763
|
-
};
|
|
8764
|
-
var PILLAR_GROUP_NAMES = {
|
|
8765
|
-
"repo-health": "Repo Health",
|
|
8766
|
-
"ai-setup": "AI Setup"
|
|
8767
|
-
};
|
|
8768
|
-
function groupPillars(pillars) {
|
|
8769
|
-
const groups = ["repo-health", "ai-setup"];
|
|
8770
|
-
return groups.map((group) => ({
|
|
8771
|
-
group,
|
|
8772
|
-
label: PILLAR_GROUP_NAMES[group],
|
|
8773
|
-
pillars: pillars.filter((p) => PILLAR_GROUPS[p.id] === group)
|
|
8774
|
-
}));
|
|
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));
|
|
8775
9088
|
}
|
|
8776
|
-
function
|
|
8777
|
-
const
|
|
8778
|
-
|
|
8779
|
-
|
|
8780
|
-
|
|
8781
|
-
4: "Optimized",
|
|
8782
|
-
5: "Autonomous"
|
|
8783
|
-
};
|
|
8784
|
-
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
|
+
);
|
|
8785
9094
|
}
|
|
8786
|
-
function
|
|
8787
|
-
|
|
8788
|
-
|
|
8789
|
-
|
|
8790
|
-
|
|
8791
|
-
|
|
8792
|
-
|
|
8793
|
-
|
|
8794
|
-
|
|
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
|
+
]);
|
|
8795
9114
|
}
|
|
8796
|
-
async function
|
|
8797
|
-
|
|
8798
|
-
|
|
8799
|
-
|
|
8800
|
-
|
|
8801
|
-
|
|
8802
|
-
|
|
8803
|
-
|
|
8804
|
-
|
|
8805
|
-
|
|
8806
|
-
|
|
8807
|
-
|
|
8808
|
-
|
|
8809
|
-
|
|
8810
|
-
|
|
8811
|
-
|
|
8812
|
-
|
|
8813
|
-
|
|
8814
|
-
|
|
8815
|
-
|
|
8816
|
-
|
|
8817
|
-
|
|
8818
|
-
|
|
8819
|
-
|
|
8820
|
-
|
|
8821
|
-
|
|
8822
|
-
|
|
8823
|
-
|
|
8824
|
-
|
|
8825
|
-
|
|
8826
|
-
|
|
8827
|
-
|
|
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
|
+
}
|
|
8828
9196
|
}
|
|
8829
|
-
|
|
8830
|
-
resolvedCriteria = resolved.criteria;
|
|
8831
|
-
resolvedExtras = resolved.extras;
|
|
8832
|
-
passRateThreshold = resolved.thresholds.passRate;
|
|
8833
|
-
policyInfo = { chain: resolved.chain, criteriaCount: resolved.criteria.length };
|
|
8834
|
-
} else {
|
|
8835
|
-
resolvedCriteria = baseCriteria;
|
|
8836
|
-
resolvedExtras = baseExtras;
|
|
9197
|
+
return paths;
|
|
8837
9198
|
}
|
|
8838
|
-
const
|
|
8839
|
-
|
|
8840
|
-
|
|
8841
|
-
|
|
8842
|
-
|
|
8843
|
-
|
|
8844
|
-
|
|
8845
|
-
|
|
8846
|
-
|
|
8847
|
-
|
|
8848
|
-
|
|
8849
|
-
|
|
8850
|
-
|
|
8851
|
-
|
|
8852
|
-
|
|
8853
|
-
|
|
8854
|
-
|
|
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"])
|
|
9211
|
+
};
|
|
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
|
+
);
|
|
8855
9239
|
}
|
|
8856
|
-
|
|
8857
|
-
|
|
8858
|
-
|
|
8859
|
-
|
|
8860
|
-
|
|
8861
|
-
|
|
8862
|
-
|
|
8863
|
-
|
|
8864
|
-
|
|
8865
|
-
|
|
8866
|
-
|
|
8867
|
-
|
|
8868
|
-
|
|
8869
|
-
|
|
8870
|
-
|
|
8871
|
-
|
|
9240
|
+
}
|
|
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);
|
|
8872
9264
|
}
|
|
8873
|
-
|
|
8874
|
-
|
|
8875
|
-
|
|
8876
|
-
|
|
8877
|
-
|
|
9265
|
+
}
|
|
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}`)
|
|
8878
9275
|
);
|
|
8879
|
-
|
|
8880
|
-
|
|
8881
|
-
|
|
8882
|
-
|
|
8883
|
-
|
|
8884
|
-
|
|
8885
|
-
|
|
8886
|
-
|
|
8887
|
-
|
|
8888
|
-
|
|
8889
|
-
|
|
8890
|
-
});
|
|
8891
|
-
continue;
|
|
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 {
|
|
8892
9287
|
}
|
|
8893
|
-
const passed = appResults.filter((entry) => entry.result.status === "pass").length;
|
|
8894
|
-
const total = appResults.length;
|
|
8895
|
-
const passRate = total ? passed / total : 0;
|
|
8896
|
-
const status = passRate >= passRateThreshold ? "pass" : "fail";
|
|
8897
|
-
const failures = appResults.filter((entry) => entry.result.status !== "pass").map((entry) => entry.app.name);
|
|
8898
|
-
criteriaResults.push({
|
|
8899
|
-
id: criterion.id,
|
|
8900
|
-
title: criterion.title,
|
|
8901
|
-
pillar: criterion.pillar,
|
|
8902
|
-
level: criterion.level,
|
|
8903
|
-
scope: criterion.scope,
|
|
8904
|
-
impact: criterion.impact,
|
|
8905
|
-
effort: criterion.effort,
|
|
8906
|
-
status,
|
|
8907
|
-
reason: status === "pass" ? void 0 : `Only ${passed}/${total} apps pass this check.`,
|
|
8908
|
-
passRate,
|
|
8909
|
-
appSummary: { passed, total },
|
|
8910
|
-
appFailures: failures
|
|
8911
|
-
});
|
|
8912
9288
|
}
|
|
8913
|
-
|
|
8914
|
-
|
|
8915
|
-
|
|
8916
|
-
|
|
8917
|
-
|
|
8918
|
-
|
|
8919
|
-
|
|
8920
|
-
|
|
8921
|
-
|
|
8922
|
-
|
|
8923
|
-
|
|
8924
|
-
|
|
8925
|
-
|
|
8926
|
-
|
|
8927
|
-
|
|
8928
|
-
|
|
8929
|
-
|
|
8930
|
-
|
|
8931
|
-
|
|
8932
|
-
|
|
8933
|
-
|
|
8934
|
-
|
|
8935
|
-
|
|
8936
|
-
|
|
8937
|
-
|
|
8938
|
-
|
|
8939
|
-
|
|
8940
|
-
|
|
8941
|
-
|
|
8942
|
-
|
|
8943
|
-
areaReports.push({ area, criteria: areaResults, pillars: areaPillars });
|
|
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]);
|
|
8944
9319
|
}
|
|
8945
|
-
|
|
8946
|
-
|
|
8947
|
-
|
|
8948
|
-
|
|
8949
|
-
|
|
8950
|
-
|
|
8951
|
-
|
|
8952
|
-
|
|
8953
|
-
|
|
8954
|
-
|
|
8955
|
-
|
|
8956
|
-
criterion.areaFailures = areaReports.filter((ar) => ar.criteria.find((c) => c.id === criterion.id)?.status !== "pass").map((ar) => ar.area.name);
|
|
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("");
|
|
8957
9331
|
}
|
|
8958
9332
|
}
|
|
8959
|
-
|
|
8960
|
-
|
|
8961
|
-
|
|
8962
|
-
|
|
8963
|
-
|
|
8964
|
-
if (options.shadow) {
|
|
8965
|
-
const policyCtx = {
|
|
8966
|
-
repoPath,
|
|
8967
|
-
rootFiles,
|
|
8968
|
-
rootPackageJson,
|
|
8969
|
-
cache: /* @__PURE__ */ new Map(),
|
|
8970
|
-
analysis,
|
|
8971
|
-
apps
|
|
8972
|
-
};
|
|
8973
|
-
const engineChain = await loadPluginChain(policySources ?? [], { jsonOnly: isConfigSourced });
|
|
8974
|
-
const engineReport = await executePlugins(engineChain.plugins, policyCtx, engineChain.options);
|
|
8975
|
-
engine = {
|
|
8976
|
-
signals: engineReport.signals,
|
|
8977
|
-
recommendations: engineReport.recommendations,
|
|
8978
|
-
policyWarnings: engineReport.policyWarnings,
|
|
8979
|
-
score: engineReport.score,
|
|
8980
|
-
grade: engineReport.grade
|
|
8981
|
-
};
|
|
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]));
|
|
9337
|
+
}
|
|
8982
9338
|
}
|
|
8983
9339
|
return {
|
|
8984
|
-
|
|
8985
|
-
|
|
8986
|
-
|
|
8987
|
-
apps: apps.map((app) => ({ name: app.name, path: app.path })),
|
|
8988
|
-
pillars,
|
|
8989
|
-
levels,
|
|
8990
|
-
achievedLevel,
|
|
8991
|
-
criteria: criteriaResults,
|
|
8992
|
-
extras,
|
|
8993
|
-
areaReports,
|
|
8994
|
-
policies: policyInfo,
|
|
8995
|
-
engine
|
|
9340
|
+
unified: minSimilarity >= 0.9,
|
|
9341
|
+
files: foundFiles,
|
|
9342
|
+
similarity: Math.round(minSimilarity * 100) / 100
|
|
8996
9343
|
};
|
|
8997
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);
|
|
9379
|
+
}
|
|
9380
|
+
}
|
|
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
|
+
);
|
|
9453
|
+
}
|
|
9454
|
+
return Array.from(new Set(dependencies));
|
|
9455
|
+
}
|
|
9456
|
+
|
|
9457
|
+
// packages/core/src/services/readiness/criteria.ts
|
|
9458
|
+
import path10 from "path";
|
|
8998
9459
|
function buildCriteria() {
|
|
8999
9460
|
return [
|
|
9000
9461
|
{
|
|
@@ -9106,7 +9567,7 @@ function buildCriteria() {
|
|
|
9106
9567
|
impact: "medium",
|
|
9107
9568
|
effort: "low",
|
|
9108
9569
|
check: async (context) => {
|
|
9109
|
-
const found = await fileExists(
|
|
9570
|
+
const found = await fileExists(path10.join(context.repoPath, "CONTRIBUTING.md"));
|
|
9110
9571
|
return {
|
|
9111
9572
|
status: found ? "pass" : "fail",
|
|
9112
9573
|
reason: found ? void 0 : "Missing CONTRIBUTING.md for contributor workflows."
|
|
@@ -9207,7 +9668,7 @@ function buildCriteria() {
|
|
|
9207
9668
|
impact: "high",
|
|
9208
9669
|
effort: "low",
|
|
9209
9670
|
check: async (context) => {
|
|
9210
|
-
const found = await fileExists(
|
|
9671
|
+
const found = await fileExists(path10.join(context.repoPath, "SECURITY.md"));
|
|
9211
9672
|
return {
|
|
9212
9673
|
status: found ? "pass" : "fail",
|
|
9213
9674
|
reason: found ? void 0 : "Missing SECURITY.md policy."
|
|
@@ -9223,7 +9684,7 @@ function buildCriteria() {
|
|
|
9223
9684
|
impact: "medium",
|
|
9224
9685
|
effort: "medium",
|
|
9225
9686
|
check: async (context) => {
|
|
9226
|
-
const found = await fileExists(
|
|
9687
|
+
const found = await fileExists(path10.join(context.repoPath, ".github", "dependabot.yml"));
|
|
9227
9688
|
return {
|
|
9228
9689
|
status: found ? "pass" : "fail",
|
|
9229
9690
|
reason: found ? void 0 : "Missing .github/dependabot.yml configuration."
|
|
@@ -9272,7 +9733,10 @@ function buildCriteria() {
|
|
|
9272
9733
|
]
|
|
9273
9734
|
};
|
|
9274
9735
|
}
|
|
9275
|
-
const fileBasedInstructions = await hasFileBasedInstructions(
|
|
9736
|
+
const fileBasedInstructions = await hasFileBasedInstructions(
|
|
9737
|
+
context.repoPath,
|
|
9738
|
+
context.vscodeLocations?.instructionsLocations
|
|
9739
|
+
);
|
|
9276
9740
|
const areas = context.analysis.areas ?? [];
|
|
9277
9741
|
if (areas.length > 0) {
|
|
9278
9742
|
if (fileBasedInstructions.length === 0) {
|
|
@@ -9288,6 +9752,13 @@ function buildCriteria() {
|
|
|
9288
9752
|
evidence: [...rootFound, ...fileBasedInstructions]
|
|
9289
9753
|
};
|
|
9290
9754
|
}
|
|
9755
|
+
if (fileBasedInstructions.length > 0) {
|
|
9756
|
+
return {
|
|
9757
|
+
status: "pass",
|
|
9758
|
+
reason: `Root + ${fileBasedInstructions.length} file-based instruction(s) found.`,
|
|
9759
|
+
evidence: [...rootFound, ...fileBasedInstructions]
|
|
9760
|
+
};
|
|
9761
|
+
}
|
|
9291
9762
|
if (context.analysis.isMonorepo && context.apps.length > 1) {
|
|
9292
9763
|
const appsMissing = [];
|
|
9293
9764
|
for (const app of context.apps) {
|
|
@@ -9367,7 +9838,10 @@ function buildCriteria() {
|
|
|
9367
9838
|
impact: "medium",
|
|
9368
9839
|
effort: "medium",
|
|
9369
9840
|
check: async (context) => {
|
|
9370
|
-
const found = await hasCustomAgents(
|
|
9841
|
+
const found = await hasCustomAgents(
|
|
9842
|
+
context.repoPath,
|
|
9843
|
+
context.vscodeLocations?.agentLocations
|
|
9844
|
+
);
|
|
9371
9845
|
return {
|
|
9372
9846
|
status: found.length > 0 ? "pass" : "fail",
|
|
9373
9847
|
reason: "No custom AI agents configured (e.g. .github/agents/, .copilot/agents/).",
|
|
@@ -9384,7 +9858,10 @@ function buildCriteria() {
|
|
|
9384
9858
|
impact: "medium",
|
|
9385
9859
|
effort: "medium",
|
|
9386
9860
|
check: async (context) => {
|
|
9387
|
-
const found = await hasCopilotSkills(
|
|
9861
|
+
const found = await hasCopilotSkills(
|
|
9862
|
+
context.repoPath,
|
|
9863
|
+
context.vscodeLocations?.skillsLocations
|
|
9864
|
+
);
|
|
9388
9865
|
return {
|
|
9389
9866
|
status: found.length > 0 ? "pass" : "fail",
|
|
9390
9867
|
reason: "No Copilot or Claude skills found (e.g. .copilot/skills/, .github/skills/).",
|
|
@@ -9392,6 +9869,65 @@ function buildCriteria() {
|
|
|
9392
9869
|
};
|
|
9393
9870
|
}
|
|
9394
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
|
+
},
|
|
9395
9931
|
// ── Area-scoped criteria (only run when areaPath is set) ──
|
|
9396
9932
|
{
|
|
9397
9933
|
id: "area-readme",
|
|
@@ -9429,7 +9965,7 @@ function buildCriteria() {
|
|
|
9429
9965
|
if (area?.scripts?.build) {
|
|
9430
9966
|
return { status: "pass" };
|
|
9431
9967
|
}
|
|
9432
|
-
const pkgPath =
|
|
9968
|
+
const pkgPath = path10.join(context.areaPath, "package.json");
|
|
9433
9969
|
const pkg = await readJson(pkgPath);
|
|
9434
9970
|
const scripts = pkg?.scripts ?? {};
|
|
9435
9971
|
const found = Boolean(scripts.build);
|
|
@@ -9454,7 +9990,7 @@ function buildCriteria() {
|
|
|
9454
9990
|
if (area?.scripts?.test) {
|
|
9455
9991
|
return { status: "pass" };
|
|
9456
9992
|
}
|
|
9457
|
-
const pkgPath =
|
|
9993
|
+
const pkgPath = path10.join(context.areaPath, "package.json");
|
|
9458
9994
|
const pkg = await readJson(pkgPath);
|
|
9459
9995
|
const scripts = pkg?.scripts ?? {};
|
|
9460
9996
|
const found = Boolean(scripts.test);
|
|
@@ -9477,7 +10013,7 @@ function buildCriteria() {
|
|
|
9477
10013
|
return { status: "skip", reason: "No area context." };
|
|
9478
10014
|
}
|
|
9479
10015
|
const sanitized = sanitizeAreaName(area.name);
|
|
9480
|
-
const instructionPath =
|
|
10016
|
+
const instructionPath = path10.join(
|
|
9481
10017
|
context.repoPath,
|
|
9482
10018
|
".github",
|
|
9483
10019
|
"instructions",
|
|
@@ -9492,13 +10028,16 @@ function buildCriteria() {
|
|
|
9492
10028
|
}
|
|
9493
10029
|
];
|
|
9494
10030
|
}
|
|
10031
|
+
|
|
10032
|
+
// packages/core/src/services/readiness/extras.ts
|
|
10033
|
+
import path11 from "path";
|
|
9495
10034
|
function buildExtras() {
|
|
9496
10035
|
return [
|
|
9497
10036
|
{
|
|
9498
10037
|
id: "agents-doc",
|
|
9499
10038
|
title: "AGENTS.md present",
|
|
9500
10039
|
check: async (context) => {
|
|
9501
|
-
const found = await fileExists(
|
|
10040
|
+
const found = await fileExists(path11.join(context.repoPath, "AGENTS.md"));
|
|
9502
10041
|
return {
|
|
9503
10042
|
status: found ? "pass" : "fail",
|
|
9504
10043
|
reason: found ? void 0 : "Missing AGENTS.md to guide coding agents."
|
|
@@ -9540,18 +10079,65 @@ function buildExtras() {
|
|
|
9540
10079
|
}
|
|
9541
10080
|
];
|
|
9542
10081
|
}
|
|
9543
|
-
async function runExtras(context, extraDefs) {
|
|
9544
|
-
const results = [];
|
|
9545
|
-
for (const def of extraDefs) {
|
|
9546
|
-
const result = await def.check(context);
|
|
9547
|
-
results.push({
|
|
9548
|
-
id: def.id,
|
|
9549
|
-
title: def.title,
|
|
9550
|
-
status: result.status,
|
|
9551
|
-
reason: result.reason
|
|
9552
|
-
});
|
|
9553
|
-
}
|
|
9554
|
-
return results;
|
|
10082
|
+
async function runExtras(context, extraDefs) {
|
|
10083
|
+
const results = [];
|
|
10084
|
+
for (const def of extraDefs) {
|
|
10085
|
+
const result = await def.check(context);
|
|
10086
|
+
results.push({
|
|
10087
|
+
id: def.id,
|
|
10088
|
+
title: def.title,
|
|
10089
|
+
status: result.status,
|
|
10090
|
+
reason: result.reason
|
|
10091
|
+
});
|
|
10092
|
+
}
|
|
10093
|
+
return results;
|
|
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] || "";
|
|
9555
10141
|
}
|
|
9556
10142
|
function summarizePillars(criteria) {
|
|
9557
10143
|
const pillarNames = {
|
|
@@ -9613,246 +10199,211 @@ function countStatus(items) {
|
|
|
9613
10199
|
const passed = relevant.filter((item) => item.status === "pass").length;
|
|
9614
10200
|
return { passed, total: relevant.length };
|
|
9615
10201
|
}
|
|
9616
|
-
|
|
9617
|
-
|
|
9618
|
-
|
|
9619
|
-
|
|
9620
|
-
const
|
|
9621
|
-
|
|
9622
|
-
|
|
9623
|
-
|
|
9624
|
-
|
|
9625
|
-
|
|
9626
|
-
|
|
9627
|
-
|
|
9628
|
-
|
|
9629
|
-
|
|
9630
|
-
|
|
9631
|
-
|
|
9632
|
-
|
|
9633
|
-
|
|
9634
|
-
|
|
9635
|
-
|
|
9636
|
-
|
|
9637
|
-
|
|
9638
|
-
|
|
9639
|
-
|
|
9640
|
-
".prettierrc.cjs",
|
|
9641
|
-
"prettier.config.js",
|
|
9642
|
-
"prettier.config.cjs"
|
|
9643
|
-
]);
|
|
9644
|
-
}
|
|
9645
|
-
async function hasFormatterConfig(repoPath) {
|
|
9646
|
-
return hasAnyFile(await safeReadDir(repoPath), [
|
|
9647
|
-
"biome.json",
|
|
9648
|
-
"biome.jsonc",
|
|
9649
|
-
".prettierrc",
|
|
9650
|
-
".prettierrc.json",
|
|
9651
|
-
".prettierrc.js",
|
|
9652
|
-
".prettierrc.cjs",
|
|
9653
|
-
"prettier.config.js",
|
|
9654
|
-
"prettier.config.cjs"
|
|
9655
|
-
]);
|
|
9656
|
-
}
|
|
9657
|
-
async function hasTypecheckConfig(repoPath) {
|
|
9658
|
-
return hasAnyFile(await safeReadDir(repoPath), [
|
|
9659
|
-
"tsconfig.json",
|
|
9660
|
-
"tsconfig.base.json",
|
|
9661
|
-
"pyproject.toml",
|
|
9662
|
-
"mypy.ini"
|
|
9663
|
-
]);
|
|
9664
|
-
}
|
|
9665
|
-
async function hasGithubWorkflows(repoPath) {
|
|
9666
|
-
return fileExists(path8.join(repoPath, ".github", "workflows"));
|
|
9667
|
-
}
|
|
9668
|
-
async function hasCodeowners(repoPath) {
|
|
9669
|
-
const root = await fileExists(path8.join(repoPath, "CODEOWNERS"));
|
|
9670
|
-
const github = await fileExists(path8.join(repoPath, ".github", "CODEOWNERS"));
|
|
9671
|
-
return root || github;
|
|
9672
|
-
}
|
|
9673
|
-
async function hasLicense(repoPath) {
|
|
9674
|
-
const files = await safeReadDir(repoPath);
|
|
9675
|
-
return files.some((file) => file.toLowerCase().startsWith("license"));
|
|
9676
|
-
}
|
|
9677
|
-
async function hasPullRequestTemplate(repoPath) {
|
|
9678
|
-
const direct = await fileExists(path8.join(repoPath, ".github", "PULL_REQUEST_TEMPLATE.md"));
|
|
9679
|
-
if (direct) return true;
|
|
9680
|
-
const dir = path8.join(repoPath, ".github", "PULL_REQUEST_TEMPLATE");
|
|
9681
|
-
try {
|
|
9682
|
-
const entries = await fs7.readdir(dir);
|
|
9683
|
-
return entries.some((entry) => entry.toLowerCase().endsWith(".md"));
|
|
9684
|
-
} catch {
|
|
9685
|
-
return false;
|
|
9686
|
-
}
|
|
9687
|
-
}
|
|
9688
|
-
async function hasPrecommitConfig(repoPath) {
|
|
9689
|
-
const precommit = await fileExists(path8.join(repoPath, ".pre-commit-config.yaml"));
|
|
9690
|
-
if (precommit) return true;
|
|
9691
|
-
return fileExists(path8.join(repoPath, ".husky"));
|
|
9692
|
-
}
|
|
9693
|
-
async function hasArchitectureDoc(repoPath) {
|
|
9694
|
-
const files = await safeReadDir(repoPath);
|
|
9695
|
-
if (files.some((file) => file.toLowerCase() === "architecture.md")) return true;
|
|
9696
|
-
return fileExists(path8.join(repoPath, "docs", "architecture.md"));
|
|
9697
|
-
}
|
|
9698
|
-
async function hasCustomInstructions(repoPath) {
|
|
9699
|
-
const found = [];
|
|
9700
|
-
const candidates = [
|
|
9701
|
-
".github/copilot-instructions.md",
|
|
9702
|
-
"CLAUDE.md",
|
|
9703
|
-
".claude/CLAUDE.md",
|
|
9704
|
-
"AGENTS.md",
|
|
9705
|
-
".github/AGENTS.md",
|
|
9706
|
-
".cursorrules",
|
|
9707
|
-
".cursorignore",
|
|
9708
|
-
".windsurfrules",
|
|
9709
|
-
".github/instructions.md",
|
|
9710
|
-
"copilot-instructions.md"
|
|
9711
|
-
];
|
|
9712
|
-
for (const candidate of candidates) {
|
|
9713
|
-
if (await fileExists(path8.join(repoPath, candidate))) {
|
|
9714
|
-
found.push(candidate);
|
|
9715
|
-
}
|
|
9716
|
-
}
|
|
9717
|
-
return found;
|
|
9718
|
-
}
|
|
9719
|
-
async function hasFileBasedInstructions(repoPath) {
|
|
9720
|
-
const instructionsDir = path8.join(repoPath, ".github", "instructions");
|
|
9721
|
-
try {
|
|
9722
|
-
const entries = await fs7.readdir(instructionsDir);
|
|
9723
|
-
return entries.filter((e) => e.endsWith(".instructions.md")).map((e) => `.github/instructions/${e}`);
|
|
9724
|
-
} catch {
|
|
9725
|
-
return [];
|
|
9726
|
-
}
|
|
9727
|
-
}
|
|
9728
|
-
function contentSimilarity(a, b) {
|
|
9729
|
-
const normalize = (s) => new Set(
|
|
9730
|
-
s.toLowerCase().split("\n").map((l) => l.trim().replace(/\s+/gu, " ")).filter((l) => l.length > 0)
|
|
9731
|
-
);
|
|
9732
|
-
const setA = normalize(a);
|
|
9733
|
-
const setB = normalize(b);
|
|
9734
|
-
if (setA.size === 0 && setB.size === 0) return 1;
|
|
9735
|
-
let intersection = 0;
|
|
9736
|
-
for (const line of setA) {
|
|
9737
|
-
if (setB.has(line)) intersection++;
|
|
9738
|
-
}
|
|
9739
|
-
const union = (/* @__PURE__ */ new Set([...setA, ...setB])).size;
|
|
9740
|
-
return union === 0 ? 1 : intersection / union;
|
|
9741
|
-
}
|
|
9742
|
-
async function checkInstructionConsistency(repoPath, foundFiles) {
|
|
9743
|
-
if (foundFiles.length <= 1) {
|
|
9744
|
-
return { unified: true, files: foundFiles };
|
|
9745
|
-
}
|
|
9746
|
-
const realPathMap = /* @__PURE__ */ new Map();
|
|
9747
|
-
for (const file of foundFiles) {
|
|
9748
|
-
const fullPath = path8.join(repoPath, file);
|
|
9749
|
-
try {
|
|
9750
|
-
const real = await fs7.realpath(fullPath);
|
|
9751
|
-
const group = realPathMap.get(real) ?? [];
|
|
9752
|
-
group.push(file);
|
|
9753
|
-
realPathMap.set(real, group);
|
|
9754
|
-
} catch {
|
|
9755
|
-
realPathMap.set(fullPath, [file]);
|
|
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;
|
|
9756
10226
|
}
|
|
9757
10227
|
}
|
|
9758
|
-
const
|
|
9759
|
-
|
|
9760
|
-
|
|
9761
|
-
|
|
9762
|
-
|
|
9763
|
-
|
|
9764
|
-
|
|
9765
|
-
|
|
9766
|
-
|
|
9767
|
-
|
|
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 }));
|
|
9768
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;
|
|
9769
10247
|
}
|
|
9770
|
-
|
|
9771
|
-
for (
|
|
9772
|
-
|
|
9773
|
-
|
|
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;
|
|
9774
10265
|
}
|
|
9775
|
-
|
|
9776
|
-
|
|
9777
|
-
|
|
9778
|
-
|
|
9779
|
-
|
|
9780
|
-
|
|
9781
|
-
|
|
9782
|
-
|
|
9783
|
-
|
|
9784
|
-
|
|
9785
|
-
|
|
9786
|
-
|
|
9787
|
-
|
|
9788
|
-
|
|
9789
|
-
|
|
9790
|
-
|
|
9791
|
-
if (settings && (settings["mcp"] || settings["github.copilot.chat.mcp.enabled"])) {
|
|
9792
|
-
found.push(".vscode/settings.json (mcp section)");
|
|
9793
|
-
}
|
|
9794
|
-
if (await fileExists(path8.join(repoPath, ".claude", "mcp.json"))) {
|
|
9795
|
-
found.push(".claude/mcp.json");
|
|
9796
|
-
}
|
|
9797
|
-
return found;
|
|
9798
|
-
}
|
|
9799
|
-
async function hasCustomAgents(repoPath) {
|
|
9800
|
-
const found = [];
|
|
9801
|
-
const agentDirs = [".github/agents", ".copilot/agents", ".github/copilot/agents"];
|
|
9802
|
-
for (const dir of agentDirs) {
|
|
9803
|
-
if (await fileExists(path8.join(repoPath, dir))) {
|
|
9804
|
-
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;
|
|
9805
10282
|
}
|
|
9806
|
-
|
|
9807
|
-
|
|
9808
|
-
|
|
9809
|
-
|
|
9810
|
-
|
|
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;
|
|
9811
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
|
+
});
|
|
9812
10322
|
}
|
|
9813
|
-
|
|
9814
|
-
|
|
9815
|
-
|
|
9816
|
-
|
|
9817
|
-
|
|
9818
|
-
|
|
9819
|
-
|
|
9820
|
-
|
|
9821
|
-
|
|
9822
|
-
|
|
9823
|
-
|
|
9824
|
-
|
|
9825
|
-
|
|
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);
|
|
9826
10367
|
}
|
|
9827
10368
|
}
|
|
9828
|
-
|
|
9829
|
-
|
|
9830
|
-
|
|
9831
|
-
const
|
|
9832
|
-
|
|
9833
|
-
|
|
9834
|
-
|
|
9835
|
-
|
|
9836
|
-
|
|
9837
|
-
|
|
9838
|
-
|
|
9839
|
-
|
|
9840
|
-
|
|
9841
|
-
|
|
9842
|
-
|
|
9843
|
-
);
|
|
9844
|
-
|
|
9845
|
-
|
|
9846
|
-
|
|
9847
|
-
|
|
9848
|
-
|
|
9849
|
-
|
|
9850
|
-
|
|
9851
|
-
...rootDevDeps
|
|
9852
|
-
})
|
|
9853
|
-
);
|
|
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
|
+
};
|
|
9854
10392
|
}
|
|
9855
|
-
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
|
+
};
|
|
9856
10407
|
}
|
|
9857
10408
|
|
|
9858
10409
|
// packages/core/src/services/batch.ts
|
|
@@ -9874,7 +10425,7 @@ async function processRepo(params) {
|
|
|
9874
10425
|
} = params;
|
|
9875
10426
|
try {
|
|
9876
10427
|
progress?.update(`${label}: Cloning...`);
|
|
9877
|
-
const cacheRoot =
|
|
10428
|
+
const cacheRoot = path13.join(process.cwd(), ".agentrc-cache");
|
|
9878
10429
|
const repoPath = validateCachePath(cacheRoot, ...cacheParts);
|
|
9879
10430
|
await ensureDir(repoPath);
|
|
9880
10431
|
if (!await isGitRepo(repoPath)) {
|
|
@@ -9900,8 +10451,8 @@ async function processRepo(params) {
|
|
|
9900
10451
|
if (!instructions.trim()) {
|
|
9901
10452
|
throw new Error("Generated instructions were empty");
|
|
9902
10453
|
}
|
|
9903
|
-
const instructionsPath =
|
|
9904
|
-
await ensureDir(
|
|
10454
|
+
const instructionsPath = path13.join(repoPath, ".github", "copilot-instructions.md");
|
|
10455
|
+
await ensureDir(path13.dirname(instructionsPath));
|
|
9905
10456
|
const { wrote, reason } = await safeWriteFile(instructionsPath, instructions, true);
|
|
9906
10457
|
if (!wrote) {
|
|
9907
10458
|
throw new Error(
|
|
@@ -10038,7 +10589,7 @@ async function processBatchReadinessRepo(options) {
|
|
|
10038
10589
|
try {
|
|
10039
10590
|
progress(`Cloning ${repo.fullName}...`);
|
|
10040
10591
|
const authedUrl = buildAuthedUrl(repo.cloneUrl, token, "github");
|
|
10041
|
-
await ensureDir(
|
|
10592
|
+
await ensureDir(path13.dirname(repoDir));
|
|
10042
10593
|
await cloneRepo(authedUrl, repoDir, { shallow: true });
|
|
10043
10594
|
await setRemoteUrl(repoDir, repo.cloneUrl).catch(() => {
|
|
10044
10595
|
});
|
|
@@ -11088,7 +11639,7 @@ import { render as render2 } from "ink";
|
|
|
11088
11639
|
// src/ui/BatchReadinessTui.tsx
|
|
11089
11640
|
import fs8 from "fs/promises";
|
|
11090
11641
|
import os from "os";
|
|
11091
|
-
import
|
|
11642
|
+
import path14 from "path";
|
|
11092
11643
|
|
|
11093
11644
|
// packages/core/src/services/visualReport.ts
|
|
11094
11645
|
function generateVisualReport(options) {
|
|
@@ -12114,7 +12665,7 @@ function BatchReadinessTui({ token, outputPath, policies }) {
|
|
|
12114
12665
|
setStatus("processing");
|
|
12115
12666
|
const selectedRepos = Array.from(selectedRepoIndices).map((i) => repos[i]);
|
|
12116
12667
|
const results2 = [];
|
|
12117
|
-
const tmpDir =
|
|
12668
|
+
const tmpDir = path14.join(os.tmpdir(), `agentrc-batch-readiness-${Date.now()}`);
|
|
12118
12669
|
try {
|
|
12119
12670
|
await ensureDir(tmpDir);
|
|
12120
12671
|
for (let i = 0; i < selectedRepos.length; i++) {
|
|
@@ -12151,7 +12702,7 @@ function BatchReadinessTui({ token, outputPath, policies }) {
|
|
|
12151
12702
|
title: "Batch Readiness Report",
|
|
12152
12703
|
generatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
12153
12704
|
});
|
|
12154
|
-
const finalOutputPath = outputPath ??
|
|
12705
|
+
const finalOutputPath = outputPath ?? path14.join(process.cwd(), "batch-readiness-report.html");
|
|
12155
12706
|
const { wrote, reason } = await safeWriteFile(finalOutputPath, html, true);
|
|
12156
12707
|
if (!wrote) throw new Error(reason === "symlink" ? "Path is a symlink" : "Write failed");
|
|
12157
12708
|
setStatus("complete");
|
|
@@ -12333,7 +12884,7 @@ async function batchReadinessCommand(options) {
|
|
|
12333
12884
|
}
|
|
12334
12885
|
|
|
12335
12886
|
// src/commands/eval.ts
|
|
12336
|
-
import
|
|
12887
|
+
import path16 from "path";
|
|
12337
12888
|
|
|
12338
12889
|
// packages/core/src/services/evalScaffold.ts
|
|
12339
12890
|
var EVAL_SCAFFOLD_TIMEOUT_MS = 6e5;
|
|
@@ -12355,7 +12906,7 @@ async function generateEvalScaffold(options) {
|
|
|
12355
12906
|
streaming: true,
|
|
12356
12907
|
workingDirectory: repoPath,
|
|
12357
12908
|
systemMessage: {
|
|
12358
|
-
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})."
|
|
12359
12910
|
},
|
|
12360
12911
|
infiniteSessions: { enabled: false }
|
|
12361
12912
|
});
|
|
@@ -12397,32 +12948,37 @@ async function generateEvalScaffold(options) {
|
|
|
12397
12948
|
'For areas with a workspace (workingDirectory), include a "workingDirectory" field set to that workspace path so evals run scoped to the correct folder.'
|
|
12398
12949
|
].join("\n") : "";
|
|
12399
12950
|
const prompt = [
|
|
12400
|
-
`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.",
|
|
12401
12955
|
"",
|
|
12402
|
-
"
|
|
12403
|
-
"
|
|
12404
|
-
"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'",
|
|
12405
12965
|
"",
|
|
12406
|
-
"
|
|
12407
|
-
"-
|
|
12408
|
-
"-
|
|
12409
|
-
"-
|
|
12410
|
-
"-
|
|
12411
|
-
"-
|
|
12412
|
-
"- 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.",
|
|
12413
12972
|
"",
|
|
12414
|
-
"Bad
|
|
12415
|
-
"- 'What does this project do?' (
|
|
12416
|
-
"- '
|
|
12417
|
-
"-
|
|
12418
|
-
"- 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",
|
|
12419
12977
|
"",
|
|
12420
|
-
"
|
|
12421
|
-
"If this is a monorepo
|
|
12422
|
-
"Ensure cases cover cross-cutting concerns: data flow, error propagation, configuration impact, implicit coupling, architectural invariants.",
|
|
12423
|
-
"Include a systemMessage that keeps answers scoped to this repository (avoid generic Copilot CLI details unless asked).",
|
|
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.",
|
|
12424
12980
|
"Return JSON ONLY (no markdown, no commentary) in this schema:",
|
|
12425
|
-
'{\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}',
|
|
12426
12982
|
areaContext
|
|
12427
12983
|
].join("\n");
|
|
12428
12984
|
progress("Analyzing codebase...");
|
|
@@ -12468,7 +13024,8 @@ async function generateEvalScaffold(options) {
|
|
|
12468
13024
|
}
|
|
12469
13025
|
throw error;
|
|
12470
13026
|
}
|
|
12471
|
-
const
|
|
13027
|
+
const hasAreas = Boolean(options.areas?.length);
|
|
13028
|
+
const normalized = normalizeEvalConfig(parsed, count, hasAreas);
|
|
12472
13029
|
return normalized;
|
|
12473
13030
|
} finally {
|
|
12474
13031
|
await client.stop();
|
|
@@ -12492,41 +13049,47 @@ function parseEvalConfig(raw) {
|
|
|
12492
13049
|
}
|
|
12493
13050
|
return parsed;
|
|
12494
13051
|
}
|
|
12495
|
-
function normalizeEvalConfig(parsed, count) {
|
|
13052
|
+
function normalizeEvalConfig(parsed, count, hasAreas = true) {
|
|
12496
13053
|
const cases = (parsed.cases ?? []).slice(0, count).map((entry, index) => {
|
|
12497
13054
|
const id = typeof entry.id === "string" && entry.id.trim() ? entry.id : `case-${index + 1}`;
|
|
12498
13055
|
return {
|
|
12499
13056
|
id,
|
|
12500
13057
|
prompt: String(entry.prompt ?? "").trim(),
|
|
12501
|
-
expectation:
|
|
12502
|
-
|
|
13058
|
+
expectation: normalizeExpectation(entry.expectation),
|
|
13059
|
+
...hasAreas && typeof entry.area === "string" && entry.area.trim() ? { area: entry.area.trim() } : {},
|
|
12503
13060
|
workingDirectory: typeof entry.workingDirectory === "string" && entry.workingDirectory.trim() ? entry.workingDirectory.trim() : void 0
|
|
12504
13061
|
};
|
|
12505
13062
|
});
|
|
12506
13063
|
if (!cases.length) {
|
|
12507
13064
|
throw new Error("Eval scaffold JSON did not include any usable cases.");
|
|
12508
13065
|
}
|
|
12509
|
-
const defaultSystemMessage = "You are answering questions about this repository. Use tools to inspect the repo and cite its files. Avoid generic Copilot CLI details unless the prompt explicitly asks for them.";
|
|
12510
13066
|
return {
|
|
12511
13067
|
instructionFile: parsed.instructionFile ?? ".github/copilot-instructions.md",
|
|
12512
|
-
systemMessage: parsed.systemMessage
|
|
13068
|
+
...parsed.systemMessage ? { systemMessage: parsed.systemMessage } : {},
|
|
12513
13069
|
cases
|
|
12514
13070
|
};
|
|
12515
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
|
+
}
|
|
12516
13079
|
|
|
12517
13080
|
// packages/core/src/services/evaluator.ts
|
|
12518
13081
|
import fs9 from "fs/promises";
|
|
12519
|
-
import
|
|
12520
|
-
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.";
|
|
12521
13084
|
async function runEval(options) {
|
|
12522
13085
|
const config = await loadConfig(options.configPath);
|
|
12523
13086
|
const instructionFile = config.instructionFile ?? ".github/copilot-instructions.md";
|
|
12524
|
-
const instructionPath =
|
|
13087
|
+
const instructionPath = path15.resolve(options.repoPath, instructionFile);
|
|
12525
13088
|
const instructionText = await readOptionalFile(instructionPath);
|
|
12526
13089
|
const baseSystemMessage = config.systemMessage ?? DEFAULT_SYSTEM_MESSAGE;
|
|
12527
13090
|
const progress = options.onProgress ?? (() => {
|
|
12528
13091
|
});
|
|
12529
|
-
const defaultOutputPath =
|
|
13092
|
+
const defaultOutputPath = path15.resolve(
|
|
12530
13093
|
options.repoPath,
|
|
12531
13094
|
".agentrc",
|
|
12532
13095
|
"evals",
|
|
@@ -12546,9 +13109,9 @@ async function runEval(options) {
|
|
|
12546
13109
|
const caseStartedAt = Date.now();
|
|
12547
13110
|
let caseWorkingDir;
|
|
12548
13111
|
if (testCase.workingDirectory) {
|
|
12549
|
-
const resolved =
|
|
12550
|
-
const root =
|
|
12551
|
-
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)) {
|
|
12552
13115
|
throw new Error(
|
|
12553
13116
|
`Invalid workingDirectory "${testCase.workingDirectory}": escapes repo boundary`
|
|
12554
13117
|
);
|
|
@@ -12620,7 +13183,7 @@ async function runEval(options) {
|
|
|
12620
13183
|
};
|
|
12621
13184
|
let viewerPath;
|
|
12622
13185
|
if (outputPath) {
|
|
12623
|
-
await fs9.mkdir(
|
|
13186
|
+
await fs9.mkdir(path15.dirname(outputPath), { recursive: true });
|
|
12624
13187
|
await safeWriteFile(outputPath, JSON.stringify(output, null, 2), true);
|
|
12625
13188
|
viewerPath = buildViewerPath(outputPath);
|
|
12626
13189
|
await safeWriteFile(viewerPath, buildTrajectoryViewerHtml(output), true);
|
|
@@ -12681,10 +13244,11 @@ async function judge(client, options) {
|
|
|
12681
13244
|
if (delta) content += delta;
|
|
12682
13245
|
}
|
|
12683
13246
|
});
|
|
13247
|
+
const expectationText = Array.isArray(options.expectation) ? options.expectation.join("\n") : options.expectation;
|
|
12684
13248
|
const prompt = [
|
|
12685
13249
|
"Evaluate which response best matches the expectation.",
|
|
12686
13250
|
"",
|
|
12687
|
-
`Expectation: ${
|
|
13251
|
+
`Expectation: ${expectationText}`,
|
|
12688
13252
|
"",
|
|
12689
13253
|
"Response A (without custom instructions):",
|
|
12690
13254
|
options.withoutInstructions,
|
|
@@ -12728,7 +13292,7 @@ function parseJudge(content) {
|
|
|
12728
13292
|
}
|
|
12729
13293
|
async function loadConfig(configPath) {
|
|
12730
13294
|
const raw = await fs9.readFile(configPath, "utf8");
|
|
12731
|
-
const parsed = JSON.parse(raw);
|
|
13295
|
+
const parsed = JSON.parse(stripJsonComments(raw));
|
|
12732
13296
|
if (!parsed || !Array.isArray(parsed.cases)) {
|
|
12733
13297
|
throw new Error("Eval config must have a 'cases' array.");
|
|
12734
13298
|
}
|
|
@@ -12934,7 +13498,7 @@ function formatTokenUsage(usage) {
|
|
|
12934
13498
|
function resolveOutputPath(repoPath, override, configValue) {
|
|
12935
13499
|
const chosen = override ?? configValue;
|
|
12936
13500
|
if (!chosen) return void 0;
|
|
12937
|
-
return
|
|
13501
|
+
return path15.isAbsolute(chosen) ? chosen : path15.resolve(repoPath, chosen);
|
|
12938
13502
|
}
|
|
12939
13503
|
function buildViewerPath(outputPath) {
|
|
12940
13504
|
if (outputPath.endsWith(".json")) {
|
|
@@ -13289,7 +13853,7 @@ function sanitizeValue(value, depth) {
|
|
|
13289
13853
|
|
|
13290
13854
|
// src/commands/eval.ts
|
|
13291
13855
|
async function evalCommand(configPathArg, options) {
|
|
13292
|
-
const repoPath =
|
|
13856
|
+
const repoPath = path16.resolve(options.repo ?? process.cwd());
|
|
13293
13857
|
if (options.listModels) {
|
|
13294
13858
|
try {
|
|
13295
13859
|
const models = await listCopilotModels();
|
|
@@ -13325,7 +13889,7 @@ async function evalCommand(configPathArg, options) {
|
|
|
13325
13889
|
return;
|
|
13326
13890
|
}
|
|
13327
13891
|
if (options.init) {
|
|
13328
|
-
const outputPath =
|
|
13892
|
+
const outputPath = path16.join(repoPath, "agentrc.eval.json");
|
|
13329
13893
|
const desiredCount = Math.max(1, Number.parseInt(options.count ?? "5", 10) || 5);
|
|
13330
13894
|
try {
|
|
13331
13895
|
const progress = createProgressReporter(!shouldLog(options));
|
|
@@ -13367,7 +13931,7 @@ async function evalCommand(configPathArg, options) {
|
|
|
13367
13931
|
}
|
|
13368
13932
|
return;
|
|
13369
13933
|
}
|
|
13370
|
-
const configPath =
|
|
13934
|
+
const configPath = path16.resolve(configPathArg ?? path16.join(repoPath, "agentrc.eval.json"));
|
|
13371
13935
|
try {
|
|
13372
13936
|
const progress = createProgressReporter(!shouldLog(options));
|
|
13373
13937
|
const { summary, results, viewerPath } = await runEval({
|
|
@@ -13414,32 +13978,43 @@ async function evalCommand(configPathArg, options) {
|
|
|
13414
13978
|
}
|
|
13415
13979
|
|
|
13416
13980
|
// src/commands/generate.ts
|
|
13417
|
-
import
|
|
13981
|
+
import path19 from "path";
|
|
13418
13982
|
|
|
13419
13983
|
// packages/core/src/services/generator.ts
|
|
13420
|
-
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
|
+
}
|
|
13421
13999
|
async function generateConfigs(options) {
|
|
13422
|
-
const { repoPath, analysis, selections, force } = options;
|
|
14000
|
+
const { repoPath, analysis, selections, force, dryRun } = options;
|
|
13423
14001
|
const files = [];
|
|
13424
14002
|
if (selections.includes("mcp")) {
|
|
13425
|
-
|
|
13426
|
-
|
|
13427
|
-
|
|
13428
|
-
|
|
13429
|
-
|
|
13430
|
-
|
|
13431
|
-
action: wrote ? "wrote" : "skipped"
|
|
13432
|
-
});
|
|
14003
|
+
files.push(
|
|
14004
|
+
await writeOrPreview(path17.join(repoPath, ".vscode", "mcp.json"), renderMcp(), {
|
|
14005
|
+
dryRun,
|
|
14006
|
+
force
|
|
14007
|
+
})
|
|
14008
|
+
);
|
|
13433
14009
|
}
|
|
13434
14010
|
if (selections.includes("vscode")) {
|
|
13435
|
-
|
|
13436
|
-
|
|
13437
|
-
|
|
13438
|
-
|
|
13439
|
-
|
|
13440
|
-
|
|
13441
|
-
|
|
13442
|
-
});
|
|
14011
|
+
files.push(
|
|
14012
|
+
await writeOrPreview(
|
|
14013
|
+
path17.join(repoPath, ".vscode", "settings.json"),
|
|
14014
|
+
renderVscodeSettings(analysis),
|
|
14015
|
+
{ dryRun, force }
|
|
14016
|
+
)
|
|
14017
|
+
);
|
|
13443
14018
|
}
|
|
13444
14019
|
return { files };
|
|
13445
14020
|
}
|
|
@@ -13488,16 +14063,16 @@ function renderVscodeSettings(analysis) {
|
|
|
13488
14063
|
}
|
|
13489
14064
|
|
|
13490
14065
|
// src/commands/instructions.ts
|
|
13491
|
-
import
|
|
14066
|
+
import path18 from "path";
|
|
13492
14067
|
function skipReason(action) {
|
|
13493
14068
|
if (action === "symlink") return "symlink";
|
|
13494
14069
|
if (action === "empty") return "empty content";
|
|
13495
14070
|
return "exists, use --force";
|
|
13496
14071
|
}
|
|
13497
14072
|
async function instructionsCommand(options) {
|
|
13498
|
-
const repoPath =
|
|
13499
|
-
const outputPath =
|
|
13500
|
-
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")
|
|
13501
14076
|
);
|
|
13502
14077
|
const progress = createProgressReporter(!shouldLog(options));
|
|
13503
14078
|
const wantAreas = options.areas || options.areasOnly || options.area;
|
|
@@ -13544,7 +14119,7 @@ async function instructionsCommand(options) {
|
|
|
13544
14119
|
] : []
|
|
13545
14120
|
];
|
|
13546
14121
|
for (const file of dryFiles) {
|
|
13547
|
-
const relPath =
|
|
14122
|
+
const relPath = path18.relative(process.cwd(), path18.join(repoPath, file.path));
|
|
13548
14123
|
if (shouldLog(options)) {
|
|
13549
14124
|
progress.update(
|
|
13550
14125
|
`[dry-run] Would write ${relPath} (${Buffer.byteLength(file.content, "utf8")} bytes)`
|
|
@@ -13565,7 +14140,7 @@ async function instructionsCommand(options) {
|
|
|
13565
14140
|
} else {
|
|
13566
14141
|
const actions = await writeNestedInstructions(repoPath, nestedResult, options.force);
|
|
13567
14142
|
for (const action of actions) {
|
|
13568
|
-
const relPath =
|
|
14143
|
+
const relPath = path18.relative(process.cwd(), action.path);
|
|
13569
14144
|
if (action.action === "wrote") {
|
|
13570
14145
|
if (shouldLog(options)) progress.succeed(`Wrote ${relPath}`);
|
|
13571
14146
|
} else if (shouldLog(options)) {
|
|
@@ -13608,8 +14183,8 @@ async function instructionsCommand(options) {
|
|
|
13608
14183
|
}
|
|
13609
14184
|
if (content) {
|
|
13610
14185
|
if (options.dryRun) {
|
|
13611
|
-
const relPath =
|
|
13612
|
-
const displayPath =
|
|
14186
|
+
const relPath = path18.relative(repoPath, outputPath);
|
|
14187
|
+
const displayPath = path18.relative(process.cwd(), outputPath);
|
|
13613
14188
|
const byteCount = Buffer.byteLength(content, "utf8");
|
|
13614
14189
|
if (shouldLog(options)) {
|
|
13615
14190
|
progress.update(`[dry-run] Would write ${displayPath} (${byteCount} bytes)`);
|
|
@@ -13618,14 +14193,14 @@ async function instructionsCommand(options) {
|
|
|
13618
14193
|
dryRunFiles.push({ path: relPath, bytes: byteCount });
|
|
13619
14194
|
}
|
|
13620
14195
|
} else {
|
|
13621
|
-
await ensureDir(
|
|
14196
|
+
await ensureDir(path18.dirname(outputPath));
|
|
13622
14197
|
const { wrote, reason } = await safeWriteFile(
|
|
13623
14198
|
outputPath,
|
|
13624
14199
|
content,
|
|
13625
14200
|
Boolean(options.force)
|
|
13626
14201
|
);
|
|
13627
14202
|
if (!wrote) {
|
|
13628
|
-
const relPath =
|
|
14203
|
+
const relPath = path18.relative(process.cwd(), outputPath);
|
|
13629
14204
|
const why = reason === "symlink" ? "path is a symlink" : "file exists (use --force)";
|
|
13630
14205
|
if (options.json) {
|
|
13631
14206
|
const result = {
|
|
@@ -13647,7 +14222,7 @@ async function instructionsCommand(options) {
|
|
|
13647
14222
|
};
|
|
13648
14223
|
outputResult(result, true);
|
|
13649
14224
|
} else if (shouldLog(options)) {
|
|
13650
|
-
progress.succeed(`Updated ${
|
|
14225
|
+
progress.succeed(`Updated ${path18.relative(process.cwd(), outputPath)}`);
|
|
13651
14226
|
}
|
|
13652
14227
|
}
|
|
13653
14228
|
}
|
|
@@ -13714,7 +14289,7 @@ async function instructionsCommand(options) {
|
|
|
13714
14289
|
] : []
|
|
13715
14290
|
];
|
|
13716
14291
|
for (const file of dryFiles) {
|
|
13717
|
-
const relPath =
|
|
14292
|
+
const relPath = path18.relative(process.cwd(), path18.join(repoPath, file.path));
|
|
13718
14293
|
if (shouldLog(options)) {
|
|
13719
14294
|
progress.update(
|
|
13720
14295
|
`[dry-run] Would write ${relPath} (${Buffer.byteLength(file.content, "utf8")} bytes)`
|
|
@@ -13732,7 +14307,7 @@ async function instructionsCommand(options) {
|
|
|
13732
14307
|
} else {
|
|
13733
14308
|
const actions = await writeNestedInstructions(repoPath, nestedResult, options.force);
|
|
13734
14309
|
for (const action of actions) {
|
|
13735
|
-
const relPath =
|
|
14310
|
+
const relPath = path18.relative(process.cwd(), action.path);
|
|
13736
14311
|
if (action.action === "wrote") {
|
|
13737
14312
|
if (shouldLog(options)) progress.succeed(`Wrote ${relPath}`);
|
|
13738
14313
|
} else if (shouldLog(options)) {
|
|
@@ -13764,7 +14339,7 @@ async function instructionsCommand(options) {
|
|
|
13764
14339
|
}
|
|
13765
14340
|
if (options.json) {
|
|
13766
14341
|
dryRunFiles.push({
|
|
13767
|
-
path:
|
|
14342
|
+
path: path18.relative(repoPath, areaInstructionPath(repoPath, area)),
|
|
13768
14343
|
bytes: Buffer.byteLength(body, "utf8")
|
|
13769
14344
|
});
|
|
13770
14345
|
}
|
|
@@ -13785,7 +14360,7 @@ async function instructionsCommand(options) {
|
|
|
13785
14360
|
continue;
|
|
13786
14361
|
}
|
|
13787
14362
|
if (shouldLog(options)) {
|
|
13788
|
-
progress.succeed(`Wrote ${
|
|
14363
|
+
progress.succeed(`Wrote ${path18.relative(process.cwd(), result.filePath)}`);
|
|
13789
14364
|
}
|
|
13790
14365
|
}
|
|
13791
14366
|
}
|
|
@@ -13820,7 +14395,7 @@ async function instructionsCommand(options) {
|
|
|
13820
14395
|
|
|
13821
14396
|
// src/commands/generate.ts
|
|
13822
14397
|
async function generateCommand(type, repoPathArg, options) {
|
|
13823
|
-
const repoPath =
|
|
14398
|
+
const repoPath = path19.resolve(repoPathArg ?? process.cwd());
|
|
13824
14399
|
if (type === "instructions" || type === "agents") {
|
|
13825
14400
|
if (!options.quiet) {
|
|
13826
14401
|
process.stderr.write(
|
|
@@ -13834,7 +14409,7 @@ async function generateCommand(type, repoPathArg, options) {
|
|
|
13834
14409
|
`
|
|
13835
14410
|
);
|
|
13836
14411
|
}
|
|
13837
|
-
const output = type === "agents" ?
|
|
14412
|
+
const output = type === "agents" ? path19.join(repoPath, "AGENTS.md") : void 0;
|
|
13838
14413
|
await instructionsCommand({
|
|
13839
14414
|
repo: repoPath,
|
|
13840
14415
|
output,
|
|
@@ -13843,7 +14418,8 @@ async function generateCommand(type, repoPathArg, options) {
|
|
|
13843
14418
|
json: options.json,
|
|
13844
14419
|
quiet: options.quiet,
|
|
13845
14420
|
areas: options.perApp,
|
|
13846
|
-
strategy: options.strategy
|
|
14421
|
+
strategy: options.strategy,
|
|
14422
|
+
dryRun: options.dryRun
|
|
13847
14423
|
});
|
|
13848
14424
|
return;
|
|
13849
14425
|
}
|
|
@@ -13864,7 +14440,8 @@ async function generateCommand(type, repoPathArg, options) {
|
|
|
13864
14440
|
repoPath,
|
|
13865
14441
|
analysis,
|
|
13866
14442
|
selections,
|
|
13867
|
-
force: Boolean(options.force)
|
|
14443
|
+
force: Boolean(options.force),
|
|
14444
|
+
dryRun: Boolean(options.dryRun)
|
|
13868
14445
|
});
|
|
13869
14446
|
} catch (error) {
|
|
13870
14447
|
outputError(
|
|
@@ -13878,14 +14455,16 @@ async function generateCommand(type, repoPathArg, options) {
|
|
|
13878
14455
|
const result = {
|
|
13879
14456
|
ok,
|
|
13880
14457
|
status,
|
|
13881
|
-
data: { type, files: genResult.files }
|
|
14458
|
+
data: { type, files: genResult.files, dryRun: options.dryRun }
|
|
13882
14459
|
};
|
|
13883
14460
|
outputResult(result, true);
|
|
13884
14461
|
if (!ok) process.exitCode = 1;
|
|
13885
14462
|
} else {
|
|
13886
14463
|
for (const file of genResult.files) {
|
|
13887
14464
|
if (shouldLog(options)) {
|
|
13888
|
-
|
|
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}
|
|
13889
14468
|
`);
|
|
13890
14469
|
}
|
|
13891
14470
|
}
|
|
@@ -13896,10 +14475,37 @@ async function generateCommand(type, repoPathArg, options) {
|
|
|
13896
14475
|
}
|
|
13897
14476
|
|
|
13898
14477
|
// src/commands/init.ts
|
|
13899
|
-
import
|
|
13900
|
-
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";
|
|
13901
14507
|
async function initCommand(repoPathArg, options) {
|
|
13902
|
-
let repoPath =
|
|
14508
|
+
let repoPath = path21.resolve(repoPathArg ?? process.cwd());
|
|
13903
14509
|
const provider = options.provider ?? (options.github ? "github" : void 0);
|
|
13904
14510
|
if (provider && provider !== "github" && provider !== "azure") {
|
|
13905
14511
|
outputError("Invalid provider. Use github or azure.", Boolean(options.json));
|
|
@@ -13937,7 +14543,7 @@ async function initCommand(repoPathArg, options) {
|
|
|
13937
14543
|
value: repo
|
|
13938
14544
|
}))
|
|
13939
14545
|
});
|
|
13940
|
-
const cacheRoot =
|
|
14546
|
+
const cacheRoot = path21.join(process.cwd(), ".agentrc-cache");
|
|
13941
14547
|
repoPath = validateCachePath(cacheRoot, selection.owner, selection.name);
|
|
13942
14548
|
await ensureDir(repoPath);
|
|
13943
14549
|
const hasGit = await isGitRepo(repoPath);
|
|
@@ -13990,7 +14596,7 @@ async function initCommand(repoPathArg, options) {
|
|
|
13990
14596
|
value: repo
|
|
13991
14597
|
}))
|
|
13992
14598
|
});
|
|
13993
|
-
const cacheRoot =
|
|
14599
|
+
const cacheRoot = path21.join(process.cwd(), ".agentrc-cache");
|
|
13994
14600
|
repoPath = validateCachePath(
|
|
13995
14601
|
cacheRoot,
|
|
13996
14602
|
orgSelection.name,
|
|
@@ -14029,17 +14635,17 @@ async function initCommand(repoPathArg, options) {
|
|
|
14029
14635
|
});
|
|
14030
14636
|
const allFiles = [];
|
|
14031
14637
|
if (selections.includes("instructions")) {
|
|
14032
|
-
const outputPath =
|
|
14033
|
-
await ensureDir(
|
|
14638
|
+
const outputPath = path21.join(repoPath, ".github", "copilot-instructions.md");
|
|
14639
|
+
await ensureDir(path21.dirname(outputPath));
|
|
14034
14640
|
try {
|
|
14035
14641
|
const content = await generateCopilotInstructions({ repoPath, model: options.model });
|
|
14036
14642
|
const { wrote } = await safeWriteFile(outputPath, content, Boolean(options.force));
|
|
14037
14643
|
allFiles.push({
|
|
14038
|
-
path:
|
|
14644
|
+
path: path21.relative(process.cwd(), outputPath),
|
|
14039
14645
|
action: wrote ? "wrote" : "skipped"
|
|
14040
14646
|
});
|
|
14041
14647
|
if (shouldLog(options)) {
|
|
14042
|
-
const rel =
|
|
14648
|
+
const rel = path21.relative(process.cwd(), outputPath);
|
|
14043
14649
|
process.stderr.write((wrote ? `Wrote ${rel}` : `Skipped ${rel} (exists)`) + "\n");
|
|
14044
14650
|
}
|
|
14045
14651
|
} catch (error) {
|
|
@@ -14066,32 +14672,19 @@ async function initCommand(repoPathArg, options) {
|
|
|
14066
14672
|
return;
|
|
14067
14673
|
}
|
|
14068
14674
|
allFiles.push(...genResult.files);
|
|
14069
|
-
|
|
14070
|
-
const
|
|
14071
|
-
|
|
14072
|
-
|
|
14073
|
-
|
|
14074
|
-
|
|
14075
|
-
|
|
14076
|
-
|
|
14077
|
-
|
|
14078
|
-
|
|
14079
|
-
applyTo: a.applyTo,
|
|
14080
|
-
...a.description ? { description: a.description } : {}
|
|
14081
|
-
}));
|
|
14082
|
-
const agentrcConfig = {};
|
|
14083
|
-
if (workspaces.length > 0) agentrcConfig.workspaces = workspaces;
|
|
14084
|
-
if (standaloneAreas.length > 0) agentrcConfig.areas = standaloneAreas;
|
|
14085
|
-
if (agentrcConfig.workspaces || agentrcConfig.areas) {
|
|
14086
|
-
const configContent = JSON.stringify(agentrcConfig, null, 2) + "\n";
|
|
14087
|
-
const { wrote } = await safeWriteFile(configPath, configContent, Boolean(options.force));
|
|
14088
|
-
const rel = path16.relative(process.cwd(), configPath);
|
|
14089
|
-
allFiles.push({ path: rel, action: wrote ? "wrote" : "skipped" });
|
|
14090
|
-
if (shouldLog(options)) {
|
|
14091
|
-
process.stderr.write((wrote ? `Wrote ${rel}` : `Skipped ${rel} (exists)`) + "\n");
|
|
14092
|
-
}
|
|
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");
|
|
14093
14685
|
}
|
|
14094
14686
|
}
|
|
14687
|
+
await offerApmInit(repoPath, options);
|
|
14095
14688
|
if (options.json) {
|
|
14096
14689
|
const { ok, status } = deriveFileStatus(allFiles);
|
|
14097
14690
|
const result = {
|
|
@@ -14113,9 +14706,52 @@ async function initCommand(repoPathArg, options) {
|
|
|
14113
14706
|
process.stderr.write(" agentrc eval --init Scaffold evaluation test cases\n");
|
|
14114
14707
|
}
|
|
14115
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
|
+
}
|
|
14116
14752
|
|
|
14117
14753
|
// src/commands/pr.ts
|
|
14118
|
-
import
|
|
14754
|
+
import path22 from "path";
|
|
14119
14755
|
var DEFAULT_PR_BRANCH = "agentrc/add-ai-config";
|
|
14120
14756
|
async function prCommand(repo, options) {
|
|
14121
14757
|
const provider = options.provider ?? "github";
|
|
@@ -14149,7 +14785,7 @@ async function prCommand(repo, options) {
|
|
|
14149
14785
|
try {
|
|
14150
14786
|
progress.update("Fetching repo info...");
|
|
14151
14787
|
const repoInfo = await getRepo(token2, organization, project, name2);
|
|
14152
|
-
const cacheRoot =
|
|
14788
|
+
const cacheRoot = path22.join(process.cwd(), ".agentrc-cache");
|
|
14153
14789
|
const repoPath = validateCachePath(cacheRoot, organization, project, name2);
|
|
14154
14790
|
await ensureDir(repoPath);
|
|
14155
14791
|
if (!await isGitRepo(repoPath)) {
|
|
@@ -14163,8 +14799,8 @@ async function prCommand(repo, options) {
|
|
|
14163
14799
|
await checkoutBranch(repoPath, branch);
|
|
14164
14800
|
progress.update("Generating instructions...");
|
|
14165
14801
|
const instructions = await generateCopilotInstructions({ repoPath, model: options.model });
|
|
14166
|
-
const instructionsPath =
|
|
14167
|
-
await ensureDir(
|
|
14802
|
+
const instructionsPath = path22.join(repoPath, ".github", "copilot-instructions.md");
|
|
14803
|
+
await ensureDir(path22.dirname(instructionsPath));
|
|
14168
14804
|
const { wrote, reason } = await safeWriteFile(instructionsPath, instructions, true);
|
|
14169
14805
|
if (!wrote) {
|
|
14170
14806
|
throw new Error(
|
|
@@ -14231,7 +14867,7 @@ async function prCommand(repo, options) {
|
|
|
14231
14867
|
try {
|
|
14232
14868
|
progress.update("Fetching repo info...");
|
|
14233
14869
|
const repoInfo = await getRepo2(token, owner, name);
|
|
14234
|
-
const cacheRoot =
|
|
14870
|
+
const cacheRoot = path22.join(process.cwd(), ".agentrc-cache");
|
|
14235
14871
|
const repoPath = validateCachePath(cacheRoot, owner, name);
|
|
14236
14872
|
await ensureDir(repoPath);
|
|
14237
14873
|
if (!await isGitRepo(repoPath)) {
|
|
@@ -14243,8 +14879,8 @@ async function prCommand(repo, options) {
|
|
|
14243
14879
|
await checkoutBranch(repoPath, branch);
|
|
14244
14880
|
progress.update("Generating instructions...");
|
|
14245
14881
|
const instructions = await generateCopilotInstructions({ repoPath, model: options.model });
|
|
14246
|
-
const instructionsPath =
|
|
14247
|
-
await ensureDir(
|
|
14882
|
+
const instructionsPath = path22.join(repoPath, ".github", "copilot-instructions.md");
|
|
14883
|
+
await ensureDir(path22.dirname(instructionsPath));
|
|
14248
14884
|
const { wrote, reason } = await safeWriteFile(instructionsPath, instructions, true);
|
|
14249
14885
|
if (!wrote) {
|
|
14250
14886
|
throw new Error(
|
|
@@ -14293,13 +14929,13 @@ async function prCommand(repo, options) {
|
|
|
14293
14929
|
}
|
|
14294
14930
|
|
|
14295
14931
|
// src/commands/readiness.ts
|
|
14296
|
-
import
|
|
14932
|
+
import path23 from "path";
|
|
14297
14933
|
import chalk3 from "chalk";
|
|
14298
14934
|
async function readinessCommand(repoPathArg, options) {
|
|
14299
|
-
const repoPath =
|
|
14300
|
-
const repoName =
|
|
14301
|
-
const resolvedOutputPath = options.output ?
|
|
14302
|
-
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() : "";
|
|
14303
14939
|
let failLevelError;
|
|
14304
14940
|
let report;
|
|
14305
14941
|
try {
|
|
@@ -14361,7 +14997,7 @@ async function readinessCommand(repoPathArg, options) {
|
|
|
14361
14997
|
title: `Readiness Report: ${repoName}`,
|
|
14362
14998
|
generatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
14363
14999
|
});
|
|
14364
|
-
const outputPath = options.output ? resolvedOutputPath :
|
|
15000
|
+
const outputPath = options.output ? resolvedOutputPath : path23.join(repoPath, "readiness-report.html");
|
|
14365
15001
|
const { wrote, reason } = await safeWriteFile(outputPath, html, Boolean(options.force));
|
|
14366
15002
|
if (!wrote) {
|
|
14367
15003
|
const why = reason === "symlink" ? "path is a symlink" : "file exists (use --force)";
|
|
@@ -14596,26 +15232,32 @@ function formatReadinessMarkdown(report, repoName) {
|
|
|
14596
15232
|
}
|
|
14597
15233
|
|
|
14598
15234
|
// src/commands/tui.tsx
|
|
14599
|
-
import
|
|
15235
|
+
import path25 from "path";
|
|
14600
15236
|
import { render as render3 } from "ink";
|
|
14601
15237
|
|
|
14602
15238
|
// src/ui/tui.tsx
|
|
14603
15239
|
import fs10 from "fs/promises";
|
|
14604
|
-
import
|
|
15240
|
+
import path24 from "path";
|
|
14605
15241
|
import { Box as Box5, Text as Text5, useApp as useApp4, useInput as useInput4, useStdout, useIsScreenReaderEnabled as useIsScreenReaderEnabled5 } from "ink";
|
|
14606
15242
|
import { useEffect as useEffect5, useMemo, useState as useState5 } from "react";
|
|
14607
15243
|
import { Fragment, jsx as jsx7, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
14608
15244
|
var SPINNER_FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
14609
15245
|
function useTerminalColumns() {
|
|
14610
15246
|
const { stdout } = useStdout();
|
|
15247
|
+
const accessible = useIsScreenReaderEnabled5();
|
|
14611
15248
|
const [columns, setColumns] = useState5(stdout.columns ?? 80);
|
|
14612
15249
|
useEffect5(() => {
|
|
14613
|
-
const onResize = () =>
|
|
14614
|
-
|
|
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);
|
|
14615
15257
|
return () => {
|
|
14616
15258
|
stdout.off("resize", onResize);
|
|
14617
15259
|
};
|
|
14618
|
-
}, [stdout]);
|
|
15260
|
+
}, [stdout, accessible]);
|
|
14619
15261
|
return columns;
|
|
14620
15262
|
}
|
|
14621
15263
|
function useSpinner(active) {
|
|
@@ -14700,6 +15342,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14700
15342
|
const [modelPickTarget, setModelPickTarget] = useState5("eval");
|
|
14701
15343
|
const [modelCursor, setModelCursor] = useState5(0);
|
|
14702
15344
|
const [hasEvalConfig, setHasEvalConfig] = useState5(null);
|
|
15345
|
+
const [hasAgentrcConfig, setHasAgentrcConfig] = useState5(null);
|
|
14703
15346
|
const [activityLog, setActivityLog] = useState5([]);
|
|
14704
15347
|
const [generateTarget, setGenerateTarget] = useState5(
|
|
14705
15348
|
"copilot-instructions"
|
|
@@ -14709,7 +15352,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14709
15352
|
const [isMonorepo, setIsMonorepo] = useState5(false);
|
|
14710
15353
|
const [repoAreas, setRepoAreas] = useState5([]);
|
|
14711
15354
|
const [areaCursor, setAreaCursor] = useState5(0);
|
|
14712
|
-
const repoLabel = useMemo(() =>
|
|
15355
|
+
const repoLabel = useMemo(() => path24.basename(repoPath), [repoPath]);
|
|
14713
15356
|
const repoFull = useMemo(() => repoPath, [repoPath]);
|
|
14714
15357
|
const isLoading = status === "generating" || status === "bootstrapping" || status === "evaluating" || status === "generating-areas" || status === "readiness-running";
|
|
14715
15358
|
const isMenu = status === "model-pick" || status === "eval-pick" || status === "batch-pick" || status === "generate-pick" || status === "generate-app-pick" || status === "generate-area-pick";
|
|
@@ -14721,14 +15364,24 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14721
15364
|
setStatus("idle");
|
|
14722
15365
|
};
|
|
14723
15366
|
useEffect5(() => {
|
|
14724
|
-
const configPath =
|
|
15367
|
+
const configPath = path24.join(repoPath, "agentrc.eval.json");
|
|
14725
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));
|
|
14726
15378
|
analyzeRepo(repoPath).then((analysis) => {
|
|
14727
15379
|
const apps = analysis.apps ?? [];
|
|
14728
15380
|
setRepoApps(apps);
|
|
14729
15381
|
setIsMonorepo(analysis.isMonorepo ?? false);
|
|
14730
15382
|
setRepoAreas(analysis.areas ?? []);
|
|
14731
15383
|
}).catch((err) => {
|
|
15384
|
+
setRepoAreas([]);
|
|
14732
15385
|
addLog(`Repo analysis failed: ${err instanceof Error ? err.message : "unknown"}`, "error");
|
|
14733
15386
|
});
|
|
14734
15387
|
}, [repoPath]);
|
|
@@ -14736,17 +15389,17 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14736
15389
|
let active = true;
|
|
14737
15390
|
listCopilotModels().then((models) => {
|
|
14738
15391
|
if (!active) return;
|
|
14739
|
-
|
|
14740
|
-
|
|
15392
|
+
const list = models.length > 0 ? models : PREFERRED_MODELS;
|
|
15393
|
+
setAvailableModels(list);
|
|
14741
15394
|
setEvalModel(
|
|
14742
|
-
(current) =>
|
|
15395
|
+
(current) => list.includes(current) ? current : pickBestModel(list, current)
|
|
14743
15396
|
);
|
|
14744
15397
|
setJudgeModel(
|
|
14745
|
-
(current) =>
|
|
15398
|
+
(current) => list.includes(current) ? current : pickBestModel(list, current)
|
|
14746
15399
|
);
|
|
14747
15400
|
}).catch(() => {
|
|
14748
15401
|
if (!active) return;
|
|
14749
|
-
setAvailableModels(
|
|
15402
|
+
setAvailableModels(PREFERRED_MODELS);
|
|
14750
15403
|
});
|
|
14751
15404
|
return () => {
|
|
14752
15405
|
active = false;
|
|
@@ -14782,7 +15435,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14782
15435
|
};
|
|
14783
15436
|
useEffect5(() => {
|
|
14784
15437
|
let active = true;
|
|
14785
|
-
const configPath =
|
|
15438
|
+
const configPath = path24.join(repoPath, "agentrc.eval.json");
|
|
14786
15439
|
fs10.readFile(configPath, "utf8").then((raw) => {
|
|
14787
15440
|
if (!active) return;
|
|
14788
15441
|
const parsed = JSON.parse(raw);
|
|
@@ -14797,7 +15450,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14797
15450
|
};
|
|
14798
15451
|
}, [repoPath]);
|
|
14799
15452
|
const bootstrapEvalConfig = async (count, force) => {
|
|
14800
|
-
const configPath =
|
|
15453
|
+
const configPath = path24.join(repoPath, "agentrc.eval.json");
|
|
14801
15454
|
try {
|
|
14802
15455
|
setStatus("bootstrapping");
|
|
14803
15456
|
setMessage("Generating eval cases with Copilot SDK...");
|
|
@@ -14836,13 +15489,13 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14836
15489
|
if (status === "preview") {
|
|
14837
15490
|
if (input.toLowerCase() === "s") {
|
|
14838
15491
|
try {
|
|
14839
|
-
const outputPath = generateSavePath ||
|
|
14840
|
-
await fs10.mkdir(
|
|
15492
|
+
const outputPath = generateSavePath || path24.join(repoPath, ".github", "copilot-instructions.md");
|
|
15493
|
+
await fs10.mkdir(path24.dirname(outputPath), { recursive: true });
|
|
14841
15494
|
const { wrote, reason } = await safeWriteFile(outputPath, generatedContent, true);
|
|
14842
15495
|
if (!wrote)
|
|
14843
15496
|
throw new Error(reason === "symlink" ? "Path is a symlink" : "Write failed");
|
|
14844
15497
|
setStatus("done");
|
|
14845
|
-
const relPath =
|
|
15498
|
+
const relPath = path24.relative(repoPath, outputPath);
|
|
14846
15499
|
const msg = `Saved to ${relPath}`;
|
|
14847
15500
|
setMessage(msg);
|
|
14848
15501
|
addLog(msg, "success");
|
|
@@ -14876,7 +15529,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14876
15529
|
setMessage("Enter a positive number of eval cases, then press Enter.");
|
|
14877
15530
|
return;
|
|
14878
15531
|
}
|
|
14879
|
-
const configPath =
|
|
15532
|
+
const configPath = path24.join(repoPath, "agentrc.eval.json");
|
|
14880
15533
|
setEvalBootstrapCount(count);
|
|
14881
15534
|
try {
|
|
14882
15535
|
await fs10.access(configPath);
|
|
@@ -14935,7 +15588,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14935
15588
|
setStatus("generate-app-pick");
|
|
14936
15589
|
setMessage("Generate for root or per-app?");
|
|
14937
15590
|
} else {
|
|
14938
|
-
const savePath =
|
|
15591
|
+
const savePath = path24.join(repoPath, ".github", "copilot-instructions.md");
|
|
14939
15592
|
setGenerateSavePath(savePath);
|
|
14940
15593
|
await doGenerate(repoPath, savePath, "copilot-instructions");
|
|
14941
15594
|
}
|
|
@@ -14947,7 +15600,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14947
15600
|
setStatus("generate-app-pick");
|
|
14948
15601
|
setMessage("Generate for root or per-app?");
|
|
14949
15602
|
} else {
|
|
14950
|
-
const savePath =
|
|
15603
|
+
const savePath = path24.join(repoPath, "AGENTS.md");
|
|
14951
15604
|
setGenerateSavePath(savePath);
|
|
14952
15605
|
await doGenerate(repoPath, savePath, "agents-md");
|
|
14953
15606
|
}
|
|
@@ -14972,7 +15625,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14972
15625
|
}
|
|
14973
15626
|
if (status === "generate-app-pick") {
|
|
14974
15627
|
if (input.toLowerCase() === "r") {
|
|
14975
|
-
const savePath = generateTarget === "copilot-instructions" ?
|
|
15628
|
+
const savePath = generateTarget === "copilot-instructions" ? path24.join(repoPath, ".github", "copilot-instructions.md") : path24.join(repoPath, "AGENTS.md");
|
|
14976
15629
|
setGenerateSavePath(savePath);
|
|
14977
15630
|
await doGenerate(repoPath, savePath, generateTarget);
|
|
14978
15631
|
return;
|
|
@@ -14982,7 +15635,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14982
15635
|
addLog(`Generating ${generateTarget} for ${repoApps.length} apps...`, "progress");
|
|
14983
15636
|
let count = 0;
|
|
14984
15637
|
for (const app2 of repoApps) {
|
|
14985
|
-
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");
|
|
14986
15639
|
setMessage(`Generating for ${app2.name} (${count + 1}/${repoApps.length})...`);
|
|
14987
15640
|
try {
|
|
14988
15641
|
const content = await generateCopilotInstructions({
|
|
@@ -14990,11 +15643,11 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
14990
15643
|
onProgress: (msg) => setMessage(`${app2.name}: ${msg}`)
|
|
14991
15644
|
});
|
|
14992
15645
|
if (content.trim()) {
|
|
14993
|
-
await fs10.mkdir(
|
|
15646
|
+
await fs10.mkdir(path24.dirname(savePath), { recursive: true });
|
|
14994
15647
|
const { wrote: saved } = await safeWriteFile(savePath, content, true);
|
|
14995
15648
|
if (!saved) continue;
|
|
14996
15649
|
count++;
|
|
14997
|
-
addLog(`${app2.name}: saved ${
|
|
15650
|
+
addLog(`${app2.name}: saved ${path24.basename(savePath)}`, "success");
|
|
14998
15651
|
}
|
|
14999
15652
|
} catch (error) {
|
|
15000
15653
|
const msg = error instanceof Error ? error.message : "Failed.";
|
|
@@ -15008,7 +15661,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
15008
15661
|
const num = Number.parseInt(input, 10);
|
|
15009
15662
|
if (Number.isFinite(num) && num >= 1 && num <= repoApps.length) {
|
|
15010
15663
|
const app2 = repoApps[num - 1];
|
|
15011
|
-
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");
|
|
15012
15665
|
setGenerateSavePath(savePath);
|
|
15013
15666
|
await doGenerate(app2.path, savePath, generateTarget);
|
|
15014
15667
|
return;
|
|
@@ -15036,7 +15689,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
15036
15689
|
const result = await writeAreaInstruction(repoPath, area, body);
|
|
15037
15690
|
if (result.status === "written") {
|
|
15038
15691
|
written++;
|
|
15039
|
-
addLog(`${area.name}: saved ${
|
|
15692
|
+
addLog(`${area.name}: saved ${path24.basename(result.filePath)}`, "success");
|
|
15040
15693
|
} else if (result.status === "skipped") {
|
|
15041
15694
|
addLog(`${area.name}: skipped (file exists)`, "info");
|
|
15042
15695
|
}
|
|
@@ -15130,8 +15783,8 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
15130
15783
|
}
|
|
15131
15784
|
if (status === "eval-pick") {
|
|
15132
15785
|
if (input.toLowerCase() === "r") {
|
|
15133
|
-
const configPath =
|
|
15134
|
-
const outputPath =
|
|
15786
|
+
const configPath = path24.join(repoPath, "agentrc.eval.json");
|
|
15787
|
+
const outputPath = path24.join(
|
|
15135
15788
|
repoPath,
|
|
15136
15789
|
".agentrc",
|
|
15137
15790
|
"evals",
|
|
@@ -15275,6 +15928,36 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
15275
15928
|
setMessage("Select eval action.");
|
|
15276
15929
|
return;
|
|
15277
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
|
+
}
|
|
15278
15961
|
if (input.toLowerCase() === "m") {
|
|
15279
15962
|
if (hideModelPicker) {
|
|
15280
15963
|
setMessage(
|
|
@@ -15389,6 +16072,10 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
15389
16072
|
/* @__PURE__ */ jsxs4(Text5, { children: [
|
|
15390
16073
|
/* @__PURE__ */ jsx7(Text5, { color: "gray", children: "Eval " }),
|
|
15391
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" })
|
|
15392
16079
|
] })
|
|
15393
16080
|
] }),
|
|
15394
16081
|
/* @__PURE__ */ jsx7(Divider, { columns: terminalColumns, label: "Activity", accessible }),
|
|
@@ -15464,7 +16151,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
15464
16151
|
/* @__PURE__ */ jsx7(Text5, { color: "white", children: app2.name }),
|
|
15465
16152
|
/* @__PURE__ */ jsxs4(Text5, { color: "gray", dimColor: true, children: [
|
|
15466
16153
|
" ",
|
|
15467
|
-
|
|
16154
|
+
path24.relative(repoPath, app2.path)
|
|
15468
16155
|
] })
|
|
15469
16156
|
] }, app2.name)) })
|
|
15470
16157
|
] }),
|
|
@@ -15498,7 +16185,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
15498
16185
|
children: [
|
|
15499
16186
|
/* @__PURE__ */ jsxs4(Text5, { color: "cyan", bold: true, children: [
|
|
15500
16187
|
"Preview (",
|
|
15501
|
-
|
|
16188
|
+
path24.relative(repoPath, generateSavePath) || generateTarget,
|
|
15502
16189
|
")"
|
|
15503
16190
|
] }),
|
|
15504
16191
|
/* @__PURE__ */ jsx7(Text5, { color: "gray", children: truncatedPreview })
|
|
@@ -15595,6 +16282,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
15595
16282
|
/* @__PURE__ */ jsxs4(Box5, { children: [
|
|
15596
16283
|
/* @__PURE__ */ jsx7(KeyHint, { k: "M", label: "Model" }),
|
|
15597
16284
|
/* @__PURE__ */ jsx7(KeyHint, { k: "J", label: "Judge" }),
|
|
16285
|
+
hasAgentrcConfig === false && /* @__PURE__ */ jsx7(KeyHint, { k: "C", label: "Create config" }),
|
|
15598
16286
|
/* @__PURE__ */ jsx7(KeyHint, { k: "Q", label: "Quit" })
|
|
15599
16287
|
] })
|
|
15600
16288
|
] }) })
|
|
@@ -15606,7 +16294,7 @@ function AgentRCTui({ repoPath, skipAnimation = false }) {
|
|
|
15606
16294
|
// src/commands/tui.tsx
|
|
15607
16295
|
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
15608
16296
|
async function tuiCommand(options) {
|
|
15609
|
-
const repoPath =
|
|
16297
|
+
const repoPath = path25.resolve(options.repo ?? process.cwd());
|
|
15610
16298
|
const skipAnimation = options.animation === false;
|
|
15611
16299
|
try {
|
|
15612
16300
|
const accessible = options.accessible ? true : void 0;
|
|
@@ -15621,7 +16309,7 @@ async function tuiCommand(options) {
|
|
|
15621
16309
|
}
|
|
15622
16310
|
|
|
15623
16311
|
// src/cli.ts
|
|
15624
|
-
var _require =
|
|
16312
|
+
var _require = createRequire2(import.meta.url);
|
|
15625
16313
|
var CLI_VERSION = _require("../package.json").version;
|
|
15626
16314
|
function withGlobalOpts(fn) {
|
|
15627
16315
|
return async (...raw) => {
|
|
@@ -15651,7 +16339,7 @@ function runCli(argv) {
|
|
|
15651
16339
|
"mcp",
|
|
15652
16340
|
"vscode"
|
|
15653
16341
|
])
|
|
15654
|
-
).argument("[path]", "Path to a local repository").option("--force", "Overwrite existing files").option("--per-app", "(deprecated) Use `agentrc instructions --areas` instead").option("--model <name>", "Model for instructions generation", DEFAULT_MODEL).option("--strategy <mode>", "Instruction strategy (flat or nested)").action(withGlobalOpts(generateCommand));
|
|
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));
|
|
15655
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));
|
|
15656
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));
|
|
15657
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));
|