@devtune/agentpicks 0.3.0 → 0.4.0
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 +20 -14
- package/dist/cli.js +1278 -1104
- package/package.json +1 -1
- package/schema/setup.v1.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -7375,7 +7375,7 @@ var import_promises4 = require("node:readline/promises");
|
|
|
7375
7375
|
// package.json
|
|
7376
7376
|
var package_default = {
|
|
7377
7377
|
name: "@devtune/agentpicks",
|
|
7378
|
-
version: "0.
|
|
7378
|
+
version: "0.4.0",
|
|
7379
7379
|
description: "The open Agent Picks runner: the agentpicks CLI, which tests the coding agents installed on your machine in fresh Docker containers, and the sandbox code DevTune runs its managed tests on",
|
|
7380
7380
|
license: "Apache-2.0",
|
|
7381
7381
|
engines: {
|
|
@@ -8749,6 +8749,10 @@ function findEnvironment(slug2) {
|
|
|
8749
8749
|
function isRetiredEnvironment(slug2) {
|
|
8750
8750
|
return RETIRED_ENVIRONMENT_SLUGS.includes(slug2);
|
|
8751
8751
|
}
|
|
8752
|
+
function isSelectedByDefault(slug2) {
|
|
8753
|
+
const environment = findEnvironment(slug2);
|
|
8754
|
+
return environment !== void 0 && environment.defaultSelected !== false && !isRetiredEnvironment(slug2);
|
|
8755
|
+
}
|
|
8752
8756
|
function environmentRunsIn(slug2, categorySlug) {
|
|
8753
8757
|
const environment = findEnvironment(slug2);
|
|
8754
8758
|
if (!environment?.categories && !environment?.context) return true;
|
|
@@ -35186,7 +35190,7 @@ var setupFileSchema = external_exports.object({
|
|
|
35186
35190
|
own: toolRef.optional(),
|
|
35187
35191
|
competitors: external_exports.array(toolRef).max(40).optional()
|
|
35188
35192
|
}).strict().optional().describe(
|
|
35189
|
-
"Your tool and its competitors: a tool
|
|
35193
|
+
"Your tool and its competitors: the key of a tool in DevTune's catalogue (such as sentry), or a full entry with key, name and signals, and optionally domain."
|
|
35190
35194
|
),
|
|
35191
35195
|
stacks: external_exports.array(
|
|
35192
35196
|
external_exports.enum(stackSlugs, {
|
|
@@ -35213,8 +35217,9 @@ var setupFileSchema = external_exports.object({
|
|
|
35213
35217
|
}).strict();
|
|
35214
35218
|
|
|
35215
35219
|
// src/setup/resolve.ts
|
|
35220
|
+
var CATALOGUE_KEYS = new Set(Object.values(CATEGORY_TOOLS).flat());
|
|
35216
35221
|
var NEVER_PATTERN = "__no-pick__";
|
|
35217
|
-
function resolveSetup(name, file2) {
|
|
35222
|
+
function resolveSetup(name, file2, held) {
|
|
35218
35223
|
const problems = [];
|
|
35219
35224
|
const category = file2.from ? findCategoryRequests(file2.from) : void 0;
|
|
35220
35225
|
if (!file2.from && !file2.job)
|
|
@@ -35237,7 +35242,7 @@ function resolveSetup(name, file2) {
|
|
|
35237
35242
|
if (!file2.from && tools.length === 0)
|
|
35238
35243
|
problems.push({
|
|
35239
35244
|
field: "tools",
|
|
35240
|
-
message: "Give your tool under tools.own, or competitors under tools.competitors, each with its signals, so a run can recognise a pick."
|
|
35245
|
+
message: "Give your tool under tools.own, or competitors under tools.competitors, each with its signals or, for a tool in DevTune's catalogue, by its key, so a run can recognise a pick."
|
|
35241
35246
|
});
|
|
35242
35247
|
const catalogueKeys = file2.from ? CATEGORY_TOOLS[file2.from] ?? [] : [];
|
|
35243
35248
|
for (const { ref, field } of tools) {
|
|
@@ -35254,15 +35259,18 @@ function resolveSetup(name, file2) {
|
|
|
35254
35259
|
});
|
|
35255
35260
|
continue;
|
|
35256
35261
|
}
|
|
35257
|
-
|
|
35258
|
-
|
|
35259
|
-
|
|
35260
|
-
|
|
35261
|
-
|
|
35262
|
-
|
|
35262
|
+
const row = held?.find((each) => each.tool_key === ref);
|
|
35263
|
+
if (file2.from) {
|
|
35264
|
+
const unchecked = !held && file2.id && CATALOGUE_KEYS.has(ref);
|
|
35265
|
+
if (!catalogueKeys.includes(ref) && !row && !unchecked)
|
|
35266
|
+
problems.push({
|
|
35267
|
+
field,
|
|
35268
|
+
message: `${file2.from} has no tool ${ref}. Use one of ${catalogueKeys.join(", ")}, or add ${ref} to a category copy in the DevTune app, then run agentpicks pull.`
|
|
35269
|
+
});
|
|
35270
|
+
} else if (!CATALOGUE_KEYS.has(ref) && row?.signals !== null)
|
|
35263
35271
|
problems.push({
|
|
35264
35272
|
field,
|
|
35265
|
-
message: `${
|
|
35273
|
+
message: row ? `${ref} is a tool of your own, which a file gives in full. Run agentpicks pull to write its entry, or give the full entry: key, name and signals, and optionally domain.` : `${ref} isn't a tool in this version of agentpicks' catalogue. Give the full entry: key, name and signals, and optionally domain; or, for a tool DevTune's catalogue has added since, update agentpicks.`
|
|
35266
35274
|
});
|
|
35267
35275
|
}
|
|
35268
35276
|
const entries2 = tools.flatMap(
|
|
@@ -35293,12 +35301,27 @@ function resolveSetup(name, file2) {
|
|
|
35293
35301
|
(intent) => [`requests.${intent}`, file2.requests?.[intent]]
|
|
35294
35302
|
)
|
|
35295
35303
|
]) {
|
|
35296
|
-
const
|
|
35297
|
-
if (
|
|
35304
|
+
const refusal2 = text3 == null ? void 0 : requestRefusal(text3);
|
|
35305
|
+
if (refusal2) problems.push({ field, message: refusal2 });
|
|
35298
35306
|
}
|
|
35299
35307
|
for (const intent of PROMPT_INTENTS) {
|
|
35300
35308
|
const text3 = file2.requests?.[intent];
|
|
35301
|
-
const named = text3 &&
|
|
35309
|
+
const named = text3 && [
|
|
35310
|
+
...entries2.map((tool) => ({
|
|
35311
|
+
name: tool.name,
|
|
35312
|
+
words: entryWords(tool)
|
|
35313
|
+
})),
|
|
35314
|
+
// A tool by key: its key, and the name DevTune gives it, where DevTune sent one.
|
|
35315
|
+
...tools.flatMap(({ ref }) => {
|
|
35316
|
+
if (typeof ref !== "string") return [];
|
|
35317
|
+
const shown3 = held?.find(
|
|
35318
|
+
(each) => each.tool_key === ref
|
|
35319
|
+
)?.display_name;
|
|
35320
|
+
return [
|
|
35321
|
+
{ name: shown3 ?? ref, words: [ref, ...shown3 ? [shown3] : []] }
|
|
35322
|
+
];
|
|
35323
|
+
})
|
|
35324
|
+
].find((tool) => namesWord(text3, tool.words));
|
|
35302
35325
|
if (named)
|
|
35303
35326
|
problems.push({
|
|
35304
35327
|
field: `requests.${intent}`,
|
|
@@ -35327,7 +35350,17 @@ function resolveSetup(name, file2) {
|
|
|
35327
35350
|
}
|
|
35328
35351
|
return environment;
|
|
35329
35352
|
});
|
|
35330
|
-
const
|
|
35353
|
+
const unrecognised = [
|
|
35354
|
+
...keys.filter(
|
|
35355
|
+
(key, i) => typeof tools[i].ref === "string" && !catalogueKeys.includes(key)
|
|
35356
|
+
),
|
|
35357
|
+
// A catalogue tool the linked setup measures that is neither yours nor a competitor, which a
|
|
35358
|
+
// file can't name: a run here can't recognise it either.
|
|
35359
|
+
...(held ?? []).filter(
|
|
35360
|
+
(row) => row.signals === null && !keys.includes(row.tool_key) && !catalogueKeys.includes(row.tool_key)
|
|
35361
|
+
).map((row) => row.tool_key)
|
|
35362
|
+
];
|
|
35363
|
+
const customReason = file2.from ? editedReason(category, file2, entries2, unrecognised) : "it has its own job";
|
|
35331
35364
|
if (customReason && findCategoryRequests(name))
|
|
35332
35365
|
problems.push({
|
|
35333
35366
|
field: "(file)",
|
|
@@ -35337,7 +35370,7 @@ function resolveSetup(name, file2) {
|
|
|
35337
35370
|
...catalogueKeys,
|
|
35338
35371
|
...keys
|
|
35339
35372
|
]);
|
|
35340
|
-
if (!file2.from && entries2.length > 0 && earlyStop.installPattern === NEVER_PATTERN && earlyStop.codePattern === NEVER_PATTERN)
|
|
35373
|
+
if (!file2.from && entries2.length > 0 && unrecognised.length === 0 && earlyStop.installPattern === NEVER_PATTERN && earlyStop.codePattern === NEVER_PATTERN)
|
|
35341
35374
|
problems.push({
|
|
35342
35375
|
field: "tools",
|
|
35343
35376
|
message: "Give at least one tool a package or config name under signals, so a run can tell that a pick landed. A tool that yields to another tool in the setup doesn't count."
|
|
@@ -35355,6 +35388,7 @@ function resolveSetup(name, file2) {
|
|
|
35355
35388
|
request: { intent: "add", text: add },
|
|
35356
35389
|
earlyStop,
|
|
35357
35390
|
customReason,
|
|
35391
|
+
unrecognised,
|
|
35358
35392
|
stacks: file2.stacks ? stacks.filter((env) => env !== null) : null,
|
|
35359
35393
|
repo: file2.repo === void 0 ? null : typeof file2.repo === "string" ? { path: file2.repo } : file2.repo,
|
|
35360
35394
|
agents: file2.agents ?? null,
|
|
@@ -35385,7 +35419,7 @@ function hasSignal(entry) {
|
|
|
35385
35419
|
s.selfHosted
|
|
35386
35420
|
].some((list) => (list?.length ?? 0) > 0);
|
|
35387
35421
|
}
|
|
35388
|
-
function editedReason(category, file2, entries2) {
|
|
35422
|
+
function editedReason(category, file2, entries2, added) {
|
|
35389
35423
|
for (const intent of PROMPT_INTENTS) {
|
|
35390
35424
|
const text3 = file2.requests?.[intent];
|
|
35391
35425
|
const published = category.prompts.find((p) => p.intent === intent)?.text;
|
|
@@ -35397,6 +35431,8 @@ function editedReason(category, file2, entries2) {
|
|
|
35397
35431
|
}
|
|
35398
35432
|
if (entries2.length > 0)
|
|
35399
35433
|
return `it gives ${entries2.map((e) => e.key).join(", ")} signals of its own`;
|
|
35434
|
+
if (added.length > 0)
|
|
35435
|
+
return `it measures ${added.join(", ")}, which ${category.slug} doesn't`;
|
|
35400
35436
|
return null;
|
|
35401
35437
|
}
|
|
35402
35438
|
function stackChoices(runsIn) {
|
|
@@ -35466,13 +35502,16 @@ var REQUEST_REFUSALS = [
|
|
|
35466
35502
|
function requestRefusal(text3) {
|
|
35467
35503
|
return REQUEST_REFUSALS.find(([pattern2]) => pattern2.test(text3))?.[1];
|
|
35468
35504
|
}
|
|
35469
|
-
function
|
|
35505
|
+
function entryWords(tool) {
|
|
35470
35506
|
return [
|
|
35471
35507
|
tool.name,
|
|
35472
35508
|
...tool.signals.aliases ?? [],
|
|
35473
35509
|
...tool.signals.brandDomains ?? [],
|
|
35474
35510
|
...tool.domain ? [tool.domain] : []
|
|
35475
|
-
]
|
|
35511
|
+
];
|
|
35512
|
+
}
|
|
35513
|
+
function namesWord(text3, words) {
|
|
35514
|
+
return words.some(
|
|
35476
35515
|
(word) => word.trim() !== "" && new RegExp(
|
|
35477
35516
|
`(^|[^\\p{L}\\p{N}])${escapeEre(word.trim())}($|[^\\p{L}\\p{N}])`,
|
|
35478
35517
|
"iu"
|
|
@@ -35497,8 +35536,8 @@ function listSetupFiles(root) {
|
|
|
35497
35536
|
if (!isDirectory(dir)) return [];
|
|
35498
35537
|
return (0, import_node_fs.readdirSync)(dir).filter((name) => EXTENSIONS.includes((0, import_node_path.extname)(name))).map((name) => (0, import_node_path.join)(dir, name)).filter((path) => !isDirectory(path)).sort();
|
|
35499
35538
|
}
|
|
35500
|
-
function readSetupFiles(root) {
|
|
35501
|
-
const files = listSetupFiles(root).map(readSetupFile);
|
|
35539
|
+
function readSetupFiles(root, held) {
|
|
35540
|
+
const files = listSetupFiles(root).map((path) => readSetupFile(path, held));
|
|
35502
35541
|
return files.map((file2) => {
|
|
35503
35542
|
const twin = files.find(
|
|
35504
35543
|
(other) => other !== file2 && other.name === file2.name
|
|
@@ -35516,16 +35555,16 @@ function readSetupFiles(root) {
|
|
|
35516
35555
|
} : file2;
|
|
35517
35556
|
});
|
|
35518
35557
|
}
|
|
35519
|
-
function readSetupFile(path) {
|
|
35558
|
+
function readSetupFile(path, held) {
|
|
35520
35559
|
let text3;
|
|
35521
35560
|
try {
|
|
35522
35561
|
text3 = (0, import_node_fs.readFileSync)(path, "utf8");
|
|
35523
35562
|
} catch (error62) {
|
|
35524
35563
|
return checkSetupText(path, null, error62);
|
|
35525
35564
|
}
|
|
35526
|
-
return checkSetupText(path, text3);
|
|
35565
|
+
return checkSetupText(path, text3, void 0, held);
|
|
35527
35566
|
}
|
|
35528
|
-
function checkSetupText(path, text3, readError) {
|
|
35567
|
+
function checkSetupText(path, text3, readError, held) {
|
|
35529
35568
|
const name = (0, import_node_path.basename)(path, (0, import_node_path.extname)(path));
|
|
35530
35569
|
const dir = (0, import_node_path.dirname)(path);
|
|
35531
35570
|
const root = gitRoot(dir) ?? ((0, import_node_path.basename)(dir) === SETUPS_DIR ? (0, import_node_path.dirname)(dir) : dir);
|
|
@@ -35561,7 +35600,11 @@ function checkSetupText(path, text3, readError) {
|
|
|
35561
35600
|
]);
|
|
35562
35601
|
const parsed2 = setupFileSchema.safeParse(value);
|
|
35563
35602
|
if (!parsed2.success) return fail(parsed2.error.issues.map(issueProblem));
|
|
35564
|
-
const resolved = resolveSetup(
|
|
35603
|
+
const resolved = resolveSetup(
|
|
35604
|
+
name,
|
|
35605
|
+
parsed2.data,
|
|
35606
|
+
parsed2.data.id ? held?.(parsed2.data.id) : void 0
|
|
35607
|
+
);
|
|
35565
35608
|
if (!("setup" in resolved))
|
|
35566
35609
|
return { ...fail(resolved.problems), content: parsed2.data };
|
|
35567
35610
|
return {
|
|
@@ -77650,7 +77693,9 @@ var bundleSetupSchema = external_exports.object({
|
|
|
77650
77693
|
/** The job line. */
|
|
77651
77694
|
job: external_exports.string().min(1),
|
|
77652
77695
|
/** Set when the run asked a linked file's changes not yet pushed, so it can't file under its setup. */
|
|
77653
|
-
unpushed: external_exports.boolean().optional()
|
|
77696
|
+
unpushed: external_exports.boolean().optional(),
|
|
77697
|
+
/** The catalogue tools the setup names by key that the run's early stop doesn't hold. */
|
|
77698
|
+
unrecognised: external_exports.array(external_exports.string().min(1)).optional()
|
|
77654
77699
|
});
|
|
77655
77700
|
var bundleEarlyStopSchema = external_exports.object({
|
|
77656
77701
|
installPattern: external_exports.string().min(1),
|
|
@@ -77931,12 +77976,12 @@ function readTree(git, commit) {
|
|
|
77931
77976
|
);
|
|
77932
77977
|
return entries2;
|
|
77933
77978
|
}
|
|
77934
|
-
function utf8(bytes,
|
|
77979
|
+
function utf8(bytes, refusal2) {
|
|
77935
77980
|
try {
|
|
77936
77981
|
return new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
77937
77982
|
} catch {
|
|
77938
77983
|
throw new RepositoryContentError(
|
|
77939
|
-
`${
|
|
77984
|
+
`${refusal2}, which the copy cannot carry. Rename it to test this repository.`
|
|
77940
77985
|
);
|
|
77941
77986
|
}
|
|
77942
77987
|
}
|
|
@@ -78303,7 +78348,8 @@ function setupPlan(file2, flags, cwd) {
|
|
|
78303
78348
|
name: setup.name,
|
|
78304
78349
|
from: setup.from,
|
|
78305
78350
|
id: setup.id,
|
|
78306
|
-
job: setup.job
|
|
78351
|
+
job: setup.job,
|
|
78352
|
+
...setup.unrecognised.length ? { unrecognised: setup.unrecognised } : {}
|
|
78307
78353
|
},
|
|
78308
78354
|
path: file2.path,
|
|
78309
78355
|
customReason: setup.customReason
|
|
@@ -78343,17 +78389,510 @@ function stackList(categorySlug) {
|
|
|
78343
78389
|
).map((env) => env.slug).join(", ");
|
|
78344
78390
|
}
|
|
78345
78391
|
|
|
78346
|
-
// src/
|
|
78347
|
-
var
|
|
78392
|
+
// src/setup/link.ts
|
|
78393
|
+
var import_node_crypto3 = require("node:crypto");
|
|
78394
|
+
var import_yaml2 = __toESM(require_dist());
|
|
78395
|
+
var LOCAL_ONLY = ["id", "synced", "repo", "runs"];
|
|
78396
|
+
function canonical(value) {
|
|
78397
|
+
if (Array.isArray(value)) return `[${value.map(canonical).join(",")}]`;
|
|
78398
|
+
if (value && typeof value === "object")
|
|
78399
|
+
return `{${Object.keys(value).filter((key) => value[key] !== void 0).sort().map(
|
|
78400
|
+
(key) => `${JSON.stringify(key)}:${canonical(value[key])}`
|
|
78401
|
+
).join(",")}}`;
|
|
78402
|
+
return JSON.stringify(value);
|
|
78403
|
+
}
|
|
78404
|
+
function fileDigest(file2) {
|
|
78405
|
+
const content = { ...file2 };
|
|
78406
|
+
for (const key of LOCAL_ONLY) delete content[key];
|
|
78407
|
+
return (0, import_node_crypto3.createHash)("sha256").update(canonical(content)).digest("hex");
|
|
78408
|
+
}
|
|
78409
|
+
function syncState(file2, setup) {
|
|
78410
|
+
if (!setup) return "orphaned";
|
|
78411
|
+
if (!file2.synced) return "both_changed";
|
|
78412
|
+
const local = fileDigest(file2) !== file2.synced.file;
|
|
78413
|
+
const devtune = setup.snapshot_digest !== file2.synced.setup;
|
|
78414
|
+
if (local && devtune) return "both_changed";
|
|
78415
|
+
if (local) return "local_changed";
|
|
78416
|
+
if (devtune) return "devtune_changed";
|
|
78417
|
+
return "in_sync";
|
|
78418
|
+
}
|
|
78419
|
+
var SYNC_STATE_LABELS = {
|
|
78420
|
+
in_sync: "in sync",
|
|
78421
|
+
local_changed: "local changed",
|
|
78422
|
+
devtune_changed: "DevTune changed",
|
|
78423
|
+
both_changed: "both changed",
|
|
78424
|
+
orphaned: "not in DevTune"
|
|
78425
|
+
};
|
|
78426
|
+
var AGENT_KINDS2 = new Map(
|
|
78427
|
+
SELF_RUN_AGENTS.map((agent) => [agent.aliases[0], agent.kind])
|
|
78428
|
+
);
|
|
78429
|
+
var devtuneAgent = (name) => AGENT_KINDS2.get(name) ?? name;
|
|
78430
|
+
var fileAgent = (kind) => SETUP_AGENTS.find((name) => AGENT_KINDS2.get(name) === kind);
|
|
78431
|
+
function nameableStack(slug2, runsIn) {
|
|
78432
|
+
return ENVIRONMENTS.some((env) => env.slug === slug2) && !isRetiredEnvironment(slug2) && environmentRunsIn(slug2, runsIn);
|
|
78433
|
+
}
|
|
78434
|
+
function slugName(text3) {
|
|
78435
|
+
return text3.normalize("NFKD").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60).replace(/-+$/, "") || "setup";
|
|
78436
|
+
}
|
|
78437
|
+
function devtuneSetupNames(setups) {
|
|
78438
|
+
const names2 = /* @__PURE__ */ new Map();
|
|
78439
|
+
const taken = /* @__PURE__ */ new Set();
|
|
78440
|
+
for (const setup of setups) {
|
|
78441
|
+
const file2 = devtuneSetupFile(setup);
|
|
78442
|
+
const unedited = "file" in file2 && file2.file.from !== void 0 && !file2.file.requests && !hasOwnTools(file2.file);
|
|
78443
|
+
let base = unedited && setup.source_category_slug ? setup.source_category_slug : slugName(setup.name);
|
|
78444
|
+
if (!unedited && findCategoryRequests(base)) base = `${base}-setup`;
|
|
78445
|
+
let name = base;
|
|
78446
|
+
for (let n = 2; taken.has(name); n++) name = `${base}-${n}`;
|
|
78447
|
+
taken.add(name);
|
|
78448
|
+
names2.set(setup.id, name);
|
|
78449
|
+
}
|
|
78450
|
+
return names2;
|
|
78451
|
+
}
|
|
78452
|
+
function hasOwnTools(file2) {
|
|
78453
|
+
if (!file2.from) return false;
|
|
78454
|
+
const categoryKeys = CATEGORY_TOOLS[file2.from] ?? [];
|
|
78455
|
+
return [file2.tools?.own, ...file2.tools?.competitors ?? []].some(
|
|
78456
|
+
(ref) => ref !== void 0 && (typeof ref !== "string" || !categoryKeys.includes(ref))
|
|
78457
|
+
);
|
|
78458
|
+
}
|
|
78459
|
+
function fileSignals(signals) {
|
|
78460
|
+
const { dismissedYieldsTo: _dismissed, packages, ...rest } = signals;
|
|
78461
|
+
const kept = {};
|
|
78462
|
+
for (const [key, value] of Object.entries(rest))
|
|
78463
|
+
if (!(Array.isArray(value) && value.length === 0) && value !== void 0)
|
|
78464
|
+
kept[key] = value;
|
|
78465
|
+
const named = Object.fromEntries(
|
|
78466
|
+
Object.entries(packages ?? {}).filter(
|
|
78467
|
+
([, list]) => Array.isArray(list) && list.length > 0
|
|
78468
|
+
)
|
|
78469
|
+
);
|
|
78470
|
+
if (Object.keys(named).length) kept.packages = named;
|
|
78471
|
+
return kept;
|
|
78472
|
+
}
|
|
78473
|
+
function fileTool(row) {
|
|
78474
|
+
return {
|
|
78475
|
+
key: row.tool_key,
|
|
78476
|
+
name: row.display_name,
|
|
78477
|
+
...row.brand_domain ? { domain: row.brand_domain } : {},
|
|
78478
|
+
signals: fileSignals(row.signals)
|
|
78479
|
+
};
|
|
78480
|
+
}
|
|
78481
|
+
function devtuneSetupFile(setup, keep = {}) {
|
|
78482
|
+
const from = setup.kind === "job" ? null : findCategoryRequests(setup.source_category_slug ?? "");
|
|
78483
|
+
if (setup.kind !== "job" && !from)
|
|
78484
|
+
return {
|
|
78485
|
+
problem: `It is a setup of the category ${setup.source_category_slug}, which this version of agentpicks doesn't have. Update agentpicks, then try again.`
|
|
78486
|
+
};
|
|
78487
|
+
const catalogueKeys = from ? CATEGORY_TOOLS[from.slug] ?? [] : [];
|
|
78488
|
+
const tool = (key) => {
|
|
78489
|
+
if (catalogueKeys.includes(key)) return key;
|
|
78490
|
+
const row = setup.tools.find((each) => each.tool_key === key);
|
|
78491
|
+
if (!row?.signals) return key;
|
|
78492
|
+
return fileTool({ ...row, signals: row.signals });
|
|
78493
|
+
};
|
|
78494
|
+
const requests = Object.fromEntries(
|
|
78495
|
+
PROMPT_INTENTS.flatMap((intent) => {
|
|
78496
|
+
const text3 = setup.requests[intent];
|
|
78497
|
+
if (!from) return !text3 || intent === "improve" ? [] : [[intent, text3]];
|
|
78498
|
+
const published = from.prompts.find((p) => p.intent === intent)?.text;
|
|
78499
|
+
if (!text3) return published ? [[intent, null]] : [];
|
|
78500
|
+
return text3 === published ? [] : [[intent, text3]];
|
|
78501
|
+
})
|
|
78502
|
+
);
|
|
78503
|
+
const own2 = setup.own_tool_key ? tool(setup.own_tool_key) : void 0;
|
|
78504
|
+
const competitors = setup.competitor_tool_keys.map(tool);
|
|
78505
|
+
const stacks = setup.environments.map((env) => env.slug).filter((slug2) => nameableStack(slug2, from?.slug ?? "job-"));
|
|
78506
|
+
const agents = [
|
|
78507
|
+
...new Set(
|
|
78508
|
+
setup.agent_models.flatMap((entry) => fileAgent(entry.agent) ?? [])
|
|
78509
|
+
)
|
|
78510
|
+
];
|
|
78511
|
+
const parsed2 = setupFileSchema.safeParse({
|
|
78512
|
+
...from ? { from: from.slug } : { job: setup.name },
|
|
78513
|
+
...Object.keys(requests).length ? { requests } : {},
|
|
78514
|
+
...own2 !== void 0 || competitors.length ? {
|
|
78515
|
+
tools: {
|
|
78516
|
+
...own2 !== void 0 ? { own: own2 } : {},
|
|
78517
|
+
...competitors.length ? { competitors } : {}
|
|
78518
|
+
}
|
|
78519
|
+
} : {},
|
|
78520
|
+
...keep.repo !== void 0 ? { repo: keep.repo } : stacks.length ? { stacks } : {},
|
|
78521
|
+
...agents.length ? { agents } : {},
|
|
78522
|
+
...keep.runs !== void 0 ? { runs: keep.runs } : {}
|
|
78523
|
+
});
|
|
78524
|
+
if (!parsed2.success) {
|
|
78525
|
+
const [issue2] = parsed2.error.issues;
|
|
78526
|
+
return {
|
|
78527
|
+
problem: `DevTune holds ${issue2.path.join(".") || "a field"} in a form a setup file can't: ${issue2.message} Change it in DevTune, then pull again.`
|
|
78528
|
+
};
|
|
78529
|
+
}
|
|
78530
|
+
return { file: parsed2.data };
|
|
78531
|
+
}
|
|
78532
|
+
function devtuneSetupProblems(setup, name, file2) {
|
|
78533
|
+
const resolved = resolveSetup(name, file2, setup.tools);
|
|
78534
|
+
return "setup" in resolved ? [] : resolved.problems;
|
|
78535
|
+
}
|
|
78536
|
+
function linkedSetupYaml(file2, link) {
|
|
78537
|
+
const { id: _id, synced: _synced, ...content } = file2;
|
|
78538
|
+
const linked = {
|
|
78539
|
+
id: link.id,
|
|
78540
|
+
synced: { setup: link.setupDigest, file: fileDigest(content) },
|
|
78541
|
+
...content
|
|
78542
|
+
};
|
|
78543
|
+
return (0, import_yaml2.stringify)(linked, { lineWidth: 0 });
|
|
78544
|
+
}
|
|
78545
|
+
|
|
78546
|
+
// src/cli/upload.ts
|
|
78547
|
+
var import_node_crypto4 = require("node:crypto");
|
|
78548
|
+
var import_node_fs2 = require("node:fs");
|
|
78549
|
+
var import_node_path5 = require("node:path");
|
|
78550
|
+
var API_TIMEOUT_MS = 6e4;
|
|
78551
|
+
var PUT_TIMEOUT_MS = 10 * 6e4;
|
|
78552
|
+
var BUNDLE_JSON_MAX_BYTES = 1024 * 1024;
|
|
78553
|
+
function readBundle(dir) {
|
|
78554
|
+
const raw = readJson(dir, BUNDLE_PATHS.manifest);
|
|
78555
|
+
const manifest = bundleManifestSchema.safeParse(raw);
|
|
78556
|
+
if (!manifest.success)
|
|
78557
|
+
throw new BundleError(
|
|
78558
|
+
`${dir} is not a bundle agentpicks wrote: ${external_exports.prettifyError(manifest.error)}`
|
|
78559
|
+
);
|
|
78560
|
+
const redactions = redactionSummarySchema.safeParse(
|
|
78561
|
+
readJson(dir, BUNDLE_PATHS.redactions)
|
|
78562
|
+
);
|
|
78563
|
+
if (!redactions.success)
|
|
78564
|
+
throw new BundleError(
|
|
78565
|
+
`${dir} is not a bundle agentpicks wrote: ${BUNDLE_PATHS.redactions} doesn't match the bundle format.`
|
|
78566
|
+
);
|
|
78567
|
+
const files = [
|
|
78568
|
+
{
|
|
78569
|
+
path: BUNDLE_PATHS.manifest,
|
|
78570
|
+
bytes: (0, import_node_fs2.lstatSync)((0, import_node_path5.join)(dir, BUNDLE_PATHS.manifest)).size
|
|
78571
|
+
}
|
|
78572
|
+
];
|
|
78573
|
+
const contents = /* @__PURE__ */ new Map();
|
|
78574
|
+
for (const artifact of manifest.data.artifacts) {
|
|
78575
|
+
const path = `${BUNDLE_PATHS.artifacts}/${artifact.name}`;
|
|
78576
|
+
const limit = uploadArtifactByteLimit(artifact.name);
|
|
78577
|
+
if (artifact.bytes > limit)
|
|
78578
|
+
throw new BundleError(
|
|
78579
|
+
`${(0, import_node_path5.join)(dir, path)} is ${artifact.bytes} bytes; DevTune takes at most ${limit} for ${artifact.name}.`
|
|
78580
|
+
);
|
|
78581
|
+
const bytes = readRegularFile(dir, path, artifact.bytes);
|
|
78582
|
+
if (bytes === null || (0, import_node_crypto4.createHash)("sha256").update(bytes).digest("hex") !== artifact.sha256)
|
|
78583
|
+
throw new BundleError(
|
|
78584
|
+
`${(0, import_node_path5.join)(dir, path)} isn't the file its manifest declares: the bundle changed after agentpicks wrote it.`
|
|
78585
|
+
);
|
|
78586
|
+
files.push({ path, bytes: bytes.length });
|
|
78587
|
+
contents.set(artifact.name, bytes);
|
|
78588
|
+
}
|
|
78589
|
+
const setup = bundleSetupSchema.safeParse(
|
|
78590
|
+
raw && typeof raw === "object" && "setup" in raw ? raw.setup : void 0
|
|
78591
|
+
);
|
|
78592
|
+
const earlyStop = bundleEarlyStopSchema.safeParse(
|
|
78593
|
+
raw && typeof raw === "object" && "earlyStop" in raw ? raw.earlyStop : void 0
|
|
78594
|
+
);
|
|
78595
|
+
return {
|
|
78596
|
+
dir,
|
|
78597
|
+
manifest: manifest.data,
|
|
78598
|
+
files,
|
|
78599
|
+
redactions: redactions.data,
|
|
78600
|
+
contents,
|
|
78601
|
+
...setup.success ? { setup: setup.data } : {},
|
|
78602
|
+
...earlyStop.success ? { earlyStop: earlyStop.data } : {}
|
|
78603
|
+
};
|
|
78604
|
+
}
|
|
78605
|
+
function findBundles(dir) {
|
|
78606
|
+
if (isFile((0, import_node_path5.join)(dir, BUNDLE_PATHS.manifest))) return [dir];
|
|
78607
|
+
let names2;
|
|
78608
|
+
try {
|
|
78609
|
+
names2 = (0, import_node_fs2.readdirSync)(dir);
|
|
78610
|
+
} catch (error62) {
|
|
78611
|
+
throw new BundleError(
|
|
78612
|
+
`${dir} can't be read: ${error62 instanceof Error ? error62.message : String(error62)}`
|
|
78613
|
+
);
|
|
78614
|
+
}
|
|
78615
|
+
const bundles = names2.filter((name) => !name.startsWith(".")).sort().map((name) => (0, import_node_path5.join)(dir, name)).filter((path) => isFile((0, import_node_path5.join)(path, BUNDLE_PATHS.manifest)));
|
|
78616
|
+
if (bundles.length === 0)
|
|
78617
|
+
throw new BundleError(
|
|
78618
|
+
`${dir} holds no bundle: pass a bundle directory, or the --out directory of agentpicks run.`
|
|
78619
|
+
);
|
|
78620
|
+
return bundles;
|
|
78621
|
+
}
|
|
78622
|
+
var uploadStatusSchema = external_exports.object({
|
|
78623
|
+
run_id: external_exports.string(),
|
|
78624
|
+
status: external_exports.enum(["open", "completed", "expired"]),
|
|
78625
|
+
run: external_exports.object({ id: external_exports.string(), analysis: external_exports.string() }).nullable()
|
|
78626
|
+
});
|
|
78627
|
+
var createdSchema = uploadStatusSchema.extend({
|
|
78628
|
+
uploads: external_exports.array(external_exports.object({ name: external_exports.string(), url: external_exports.string().nullable() }))
|
|
78629
|
+
});
|
|
78630
|
+
async function uploadBundle(bundle, target) {
|
|
78631
|
+
const uploads = `${target.baseUrl}/projects/${target.projectId}/agent-picks/uploads`;
|
|
78632
|
+
const created = await callApi(target, createdSchema, uploads, {
|
|
78633
|
+
method: "POST",
|
|
78634
|
+
body: JSON.stringify(bundle.manifest)
|
|
78635
|
+
});
|
|
78636
|
+
const statusUrl = `${uploads}/${created.run_id}`;
|
|
78637
|
+
if (created.status === "expired")
|
|
78638
|
+
throw new UploadError(
|
|
78639
|
+
`DevTune reports the upload of run ${created.run_id} as expired.`
|
|
78640
|
+
);
|
|
78641
|
+
if (created.status === "completed")
|
|
78642
|
+
return {
|
|
78643
|
+
runId: created.run_id,
|
|
78644
|
+
statusUrl,
|
|
78645
|
+
sent: 0,
|
|
78646
|
+
analysis: created.run?.analysis ?? null
|
|
78647
|
+
};
|
|
78648
|
+
let sent = 0;
|
|
78649
|
+
for (const { name, url: url2 } of created.uploads) {
|
|
78650
|
+
if (url2 === null) continue;
|
|
78651
|
+
const bytes = bundle.contents.get(name);
|
|
78652
|
+
if (!bytes)
|
|
78653
|
+
throw new UploadError(
|
|
78654
|
+
`DevTune asked for ${name}, which the bundle's manifest doesn't declare.`
|
|
78655
|
+
);
|
|
78656
|
+
if (await putArtifact(url2, bytes, `${BUNDLE_PATHS.artifacts}/${name}`))
|
|
78657
|
+
sent++;
|
|
78658
|
+
}
|
|
78659
|
+
const completed = await callApi(
|
|
78660
|
+
target,
|
|
78661
|
+
uploadStatusSchema,
|
|
78662
|
+
`${statusUrl}/complete`,
|
|
78663
|
+
{ method: "POST" }
|
|
78664
|
+
);
|
|
78665
|
+
return {
|
|
78666
|
+
runId: completed.run_id,
|
|
78667
|
+
statusUrl,
|
|
78668
|
+
sent,
|
|
78669
|
+
analysis: completed.run?.analysis ?? null
|
|
78670
|
+
};
|
|
78671
|
+
}
|
|
78672
|
+
var connectionSchema = external_exports.object({
|
|
78673
|
+
project: external_exports.object({ id: external_exports.uuid(), name: external_exports.string() }),
|
|
78674
|
+
credential: external_exports.object({ type: external_exports.string() }),
|
|
78675
|
+
scopes: external_exports.array(external_exports.string())
|
|
78676
|
+
});
|
|
78677
|
+
async function discoverProject(target) {
|
|
78678
|
+
return callApi(target, connectionSchema, `${target.baseUrl}/connection`, {
|
|
78679
|
+
method: "GET"
|
|
78680
|
+
});
|
|
78681
|
+
}
|
|
78682
|
+
async function putArtifact(url2, bytes, path) {
|
|
78683
|
+
let response;
|
|
78684
|
+
try {
|
|
78685
|
+
response = await fetch(url2, {
|
|
78686
|
+
method: "PUT",
|
|
78687
|
+
headers: { "Content-Type": "application/octet-stream" },
|
|
78688
|
+
body: new Uint8Array(bytes),
|
|
78689
|
+
redirect: "error",
|
|
78690
|
+
signal: AbortSignal.timeout(PUT_TIMEOUT_MS)
|
|
78691
|
+
});
|
|
78692
|
+
} catch (error62) {
|
|
78693
|
+
throw new UploadError(
|
|
78694
|
+
`Uploading ${path} to storage failed (${transportCode(error62)}). Run agentpicks upload again to send what isn't stored.`
|
|
78695
|
+
);
|
|
78696
|
+
}
|
|
78697
|
+
if (response.ok) {
|
|
78698
|
+
await response.body?.cancel();
|
|
78699
|
+
return true;
|
|
78700
|
+
}
|
|
78701
|
+
let text3 = "";
|
|
78702
|
+
try {
|
|
78703
|
+
text3 = await response.text();
|
|
78704
|
+
} catch {
|
|
78705
|
+
}
|
|
78706
|
+
if (response.status === 409 || /"statusCode"\s*:\s*"409"/.test(text3))
|
|
78707
|
+
return false;
|
|
78708
|
+
throw new UploadError(
|
|
78709
|
+
`Uploading ${path} failed: Storage answered ${response.status}.`
|
|
78710
|
+
);
|
|
78711
|
+
}
|
|
78712
|
+
var apiErrorSchema = external_exports.object({
|
|
78713
|
+
message: external_exports.string().min(1),
|
|
78714
|
+
reason: external_exports.string().optional()
|
|
78715
|
+
});
|
|
78716
|
+
async function callApi(target, schema, url2, init) {
|
|
78717
|
+
let bearer;
|
|
78718
|
+
try {
|
|
78719
|
+
bearer = "apiKey" in target ? target.apiKey : await target.session.accessToken();
|
|
78720
|
+
} catch (error62) {
|
|
78721
|
+
if (error62 instanceof SignInError)
|
|
78722
|
+
throw new UploadError(error62.message, { transient: error62.transient });
|
|
78723
|
+
throw error62;
|
|
78724
|
+
}
|
|
78725
|
+
let response;
|
|
78726
|
+
try {
|
|
78727
|
+
response = await fetch(url2, {
|
|
78728
|
+
...init,
|
|
78729
|
+
headers: {
|
|
78730
|
+
Authorization: `Bearer ${bearer}`,
|
|
78731
|
+
Accept: "application/json",
|
|
78732
|
+
...init.body === void 0 ? {} : { "Content-Type": "application/json" }
|
|
78733
|
+
},
|
|
78734
|
+
redirect: "error",
|
|
78735
|
+
signal: AbortSignal.timeout(API_TIMEOUT_MS)
|
|
78736
|
+
});
|
|
78737
|
+
} catch (error62) {
|
|
78738
|
+
throw new UploadError(
|
|
78739
|
+
`Couldn't reach DevTune at ${target.baseUrl} (${transportCode(error62)}). Check the connection and try again.`,
|
|
78740
|
+
{ transient: true }
|
|
78741
|
+
);
|
|
78742
|
+
}
|
|
78743
|
+
let body = null;
|
|
78744
|
+
try {
|
|
78745
|
+
body = await response.json();
|
|
78746
|
+
} catch {
|
|
78747
|
+
}
|
|
78748
|
+
if (!response.ok) {
|
|
78749
|
+
const message = apiErrorSchema.safeParse(body);
|
|
78750
|
+
const refused = {
|
|
78751
|
+
status: response.status,
|
|
78752
|
+
...message.data?.reason ? { reason: message.data.reason } : {}
|
|
78753
|
+
};
|
|
78754
|
+
if (isTransientStatus(response.status))
|
|
78755
|
+
throw new UploadError(
|
|
78756
|
+
message.success ? message.data.message : `DevTune answered ${response.status}.`,
|
|
78757
|
+
{ transient: true, ...refused }
|
|
78758
|
+
);
|
|
78759
|
+
if ("session" in target) {
|
|
78760
|
+
if (message.success)
|
|
78761
|
+
throw new UploadError(
|
|
78762
|
+
message.data.message.replaceAll("devtune login", "agentpicks login"),
|
|
78763
|
+
refused
|
|
78764
|
+
);
|
|
78765
|
+
throw new UploadError(
|
|
78766
|
+
response.status === 401 ? "DevTune refused the sign-in. Run agentpicks login again." : `DevTune answered ${response.status}.`,
|
|
78767
|
+
refused
|
|
78768
|
+
);
|
|
78769
|
+
}
|
|
78770
|
+
if (!message.success)
|
|
78771
|
+
throw new UploadError(`DevTune answered ${response.status}.`, refused);
|
|
78772
|
+
throw new UploadError(
|
|
78773
|
+
response.status === 401 ? `${message.data.message.replace(/\.?$/, ".")} Run agentpicks login, or set DEVTUNE_API_KEY.` : message.data.message,
|
|
78774
|
+
refused
|
|
78775
|
+
);
|
|
78776
|
+
}
|
|
78777
|
+
const data = external_exports.object({ data: schema }).safeParse(body);
|
|
78778
|
+
if (!data.success)
|
|
78779
|
+
throw new UploadError(
|
|
78780
|
+
`DevTune's answer from ${new URL(url2).pathname} wasn't the expected shape.`
|
|
78781
|
+
);
|
|
78782
|
+
return data.data.data;
|
|
78783
|
+
}
|
|
78784
|
+
function readJson(dir, path) {
|
|
78785
|
+
const bytes = readRegularFile(dir, path, null, BUNDLE_JSON_MAX_BYTES);
|
|
78786
|
+
try {
|
|
78787
|
+
if (bytes === null) throw new Error("not a regular file within its limit");
|
|
78788
|
+
return JSON.parse(bytes.toString("utf8"));
|
|
78789
|
+
} catch {
|
|
78790
|
+
throw new BundleError(
|
|
78791
|
+
`${dir} is not a bundle agentpicks wrote: ${path} is missing, too large or isn't JSON.`
|
|
78792
|
+
);
|
|
78793
|
+
}
|
|
78794
|
+
}
|
|
78795
|
+
function readRegularFile(dir, path, bytes, max = Infinity) {
|
|
78796
|
+
const full = (0, import_node_path5.join)(dir, path);
|
|
78797
|
+
let fd = null;
|
|
78798
|
+
try {
|
|
78799
|
+
const stat = (0, import_node_fs2.lstatSync)(full);
|
|
78800
|
+
if (!stat.isFile() || stat.size > max) return null;
|
|
78801
|
+
if (bytes !== null && stat.size !== bytes) return null;
|
|
78802
|
+
fd = (0, import_node_fs2.openSync)(full, import_node_fs2.constants.O_RDONLY | (import_node_fs2.constants.O_NOFOLLOW ?? 0));
|
|
78803
|
+
const buffer = Buffer.alloc(stat.size);
|
|
78804
|
+
let read = 0;
|
|
78805
|
+
while (read < buffer.length) {
|
|
78806
|
+
const n = (0, import_node_fs2.readSync)(fd, buffer, read, buffer.length - read, read);
|
|
78807
|
+
if (n === 0) return null;
|
|
78808
|
+
read += n;
|
|
78809
|
+
}
|
|
78810
|
+
return buffer;
|
|
78811
|
+
} catch {
|
|
78812
|
+
return null;
|
|
78813
|
+
} finally {
|
|
78814
|
+
if (fd !== null) (0, import_node_fs2.closeSync)(fd);
|
|
78815
|
+
}
|
|
78816
|
+
}
|
|
78817
|
+
function isFile(path) {
|
|
78818
|
+
try {
|
|
78819
|
+
return (0, import_node_fs2.statSync)(path).isFile();
|
|
78820
|
+
} catch {
|
|
78821
|
+
return false;
|
|
78822
|
+
}
|
|
78823
|
+
}
|
|
78824
|
+
function transportCode(error62) {
|
|
78825
|
+
if (!(error62 instanceof Error)) return "unknown error";
|
|
78826
|
+
if (error62.name === "TimeoutError") return "timed out";
|
|
78827
|
+
const code = error62.cause?.code ?? error62.code;
|
|
78828
|
+
const name = typeof code === "string" ? code : error62.name;
|
|
78829
|
+
return /^\w+$/.test(name) ? name : "unknown error";
|
|
78830
|
+
}
|
|
78831
|
+
|
|
78832
|
+
// src/cli/devtune-setups.ts
|
|
78833
|
+
var idSlug = external_exports.object({ id: external_exports.string(), slug: external_exports.string() });
|
|
78834
|
+
var devtuneSetupSchema = external_exports.object({
|
|
78835
|
+
id: external_exports.string(),
|
|
78836
|
+
category_slug: external_exports.string(),
|
|
78837
|
+
name: external_exports.string(),
|
|
78838
|
+
kind: external_exports.enum(["job", "copy", "category"]),
|
|
78839
|
+
source_category_slug: external_exports.string().nullable(),
|
|
78840
|
+
snapshot_digest: external_exports.string(),
|
|
78841
|
+
requests: external_exports.record(external_exports.string(), external_exports.string().nullable()),
|
|
78842
|
+
tools: external_exports.array(
|
|
78843
|
+
external_exports.object({
|
|
78844
|
+
tool_key: external_exports.string(),
|
|
78845
|
+
display_name: external_exports.string(),
|
|
78846
|
+
brand_domain: external_exports.string().nullable(),
|
|
78847
|
+
signals: external_exports.record(external_exports.string(), external_exports.unknown()).nullable()
|
|
78848
|
+
})
|
|
78849
|
+
),
|
|
78850
|
+
own_tool_key: external_exports.string().nullable(),
|
|
78851
|
+
competitor_tool_keys: external_exports.array(external_exports.string()),
|
|
78852
|
+
environments: external_exports.array(idSlug),
|
|
78853
|
+
agent_models: external_exports.array(external_exports.object({ agent: external_exports.string(), model: external_exports.string() })),
|
|
78854
|
+
building_blocks: external_exports.record(external_exports.string(), external_exports.unknown()).nullable()
|
|
78855
|
+
});
|
|
78856
|
+
var setupListSchema = external_exports.object({
|
|
78857
|
+
setups: external_exports.array(devtuneSetupSchema),
|
|
78858
|
+
catalogue: external_exports.object({
|
|
78859
|
+
categories: external_exports.array(idSlug),
|
|
78860
|
+
environments: external_exports.array(idSlug),
|
|
78861
|
+
agents: external_exports.array(
|
|
78862
|
+
external_exports.object({
|
|
78863
|
+
agent: external_exports.string(),
|
|
78864
|
+
models: external_exports.array(external_exports.string()),
|
|
78865
|
+
included_in_plan: external_exports.boolean()
|
|
78866
|
+
})
|
|
78867
|
+
)
|
|
78868
|
+
})
|
|
78869
|
+
});
|
|
78870
|
+
var savedSchema = external_exports.object({
|
|
78871
|
+
setup: external_exports.object({ id: external_exports.string(), category_slug: external_exports.string() }).nullable(),
|
|
78872
|
+
snapshot_digest: external_exports.string()
|
|
78873
|
+
});
|
|
78874
|
+
var setupUrl = (target, path) => `${target.baseUrl}/projects/${target.projectId}/agent-picks/${path}`;
|
|
78875
|
+
function readDevtuneSetups(target) {
|
|
78876
|
+
return callApi(target, setupListSchema, setupUrl(target, "setup"), {
|
|
78877
|
+
method: "GET"
|
|
78878
|
+
});
|
|
78879
|
+
}
|
|
78880
|
+
async function saveDevtuneSetup(target, route, body) {
|
|
78881
|
+
const saved = await callApi(target, savedSchema, setupUrl(target, route), {
|
|
78882
|
+
method: "PUT",
|
|
78883
|
+
body: JSON.stringify(body)
|
|
78884
|
+
});
|
|
78885
|
+
return { setup: saved.setup, snapshotDigest: saved.snapshot_digest };
|
|
78886
|
+
}
|
|
78348
78887
|
|
|
78349
78888
|
// src/cli/discover.ts
|
|
78350
|
-
var
|
|
78889
|
+
var import_node_path7 = require("node:path");
|
|
78351
78890
|
|
|
78352
78891
|
// src/cli/host.ts
|
|
78353
78892
|
var import_node_child_process3 = require("node:child_process");
|
|
78354
|
-
var
|
|
78893
|
+
var import_node_fs3 = require("node:fs");
|
|
78355
78894
|
var import_node_os = require("node:os");
|
|
78356
|
-
var
|
|
78895
|
+
var import_node_path6 = require("node:path");
|
|
78357
78896
|
|
|
78358
78897
|
// ../../node_modules/.pnpm/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/scanner.js
|
|
78359
78898
|
function createScanner(text3, ignoreTrivia = false) {
|
|
@@ -79223,12 +79762,12 @@ function hostIo() {
|
|
|
79223
79762
|
platform: process.platform,
|
|
79224
79763
|
arch: process.arch,
|
|
79225
79764
|
which(command) {
|
|
79226
|
-
for (const dir of (env.PATH ?? "").split(
|
|
79765
|
+
for (const dir of (env.PATH ?? "").split(import_node_path6.delimiter)) {
|
|
79227
79766
|
if (!dir) continue;
|
|
79228
|
-
const path = (0,
|
|
79767
|
+
const path = (0, import_node_path6.join)(dir, command);
|
|
79229
79768
|
try {
|
|
79230
|
-
(0,
|
|
79231
|
-
if ((0,
|
|
79769
|
+
(0, import_node_fs3.accessSync)(path, import_node_fs3.constants.X_OK);
|
|
79770
|
+
if ((0, import_node_fs3.statSync)(path).isFile()) return path;
|
|
79232
79771
|
} catch {
|
|
79233
79772
|
}
|
|
79234
79773
|
}
|
|
@@ -79245,7 +79784,7 @@ ${r.stderr}`;
|
|
|
79245
79784
|
},
|
|
79246
79785
|
readFile(path) {
|
|
79247
79786
|
try {
|
|
79248
|
-
return (0,
|
|
79787
|
+
return (0, import_node_fs3.readFileSync)(path, "utf8");
|
|
79249
79788
|
} catch {
|
|
79250
79789
|
return null;
|
|
79251
79790
|
}
|
|
@@ -79352,43 +79891,43 @@ function configuredModel(io, kind) {
|
|
|
79352
79891
|
if (kind === "claude_code") {
|
|
79353
79892
|
if (io.env.ANTHROPIC_MODEL)
|
|
79354
79893
|
return { model: io.env.ANTHROPIC_MODEL, modelSource: "ANTHROPIC_MODEL" };
|
|
79355
|
-
const path2 = (0,
|
|
79894
|
+
const path2 = (0, import_node_path7.join)(claudeConfigDir(io), "settings.json");
|
|
79356
79895
|
const settings2 = readJsonObject(io, path2);
|
|
79357
79896
|
const env = settings2?.env;
|
|
79358
79897
|
const model2 = (env && typeof env === "object" ? stringField(env, "ANTHROPIC_MODEL") : void 0) ?? stringField(settings2, "model");
|
|
79359
79898
|
return model2 ? { model: model2, modelSource: path2 } : fallback;
|
|
79360
79899
|
}
|
|
79361
79900
|
if (kind === "codex") {
|
|
79362
|
-
const path2 = (0,
|
|
79901
|
+
const path2 = (0, import_node_path7.join)(codexHome(io), "config.toml");
|
|
79363
79902
|
const model2 = topLevelTomlString(io.readFile(path2), "model");
|
|
79364
79903
|
return model2 ? { model: model2, modelSource: path2 } : fallback;
|
|
79365
79904
|
}
|
|
79366
79905
|
if (kind === "opencode") {
|
|
79367
|
-
const dir = (0,
|
|
79368
|
-
io.env.XDG_CONFIG_HOME || (0,
|
|
79906
|
+
const dir = (0, import_node_path7.join)(
|
|
79907
|
+
io.env.XDG_CONFIG_HOME || (0, import_node_path7.join)(io.home, ".config"),
|
|
79369
79908
|
"opencode"
|
|
79370
79909
|
);
|
|
79371
79910
|
for (const name of ["opencode.json", "opencode.jsonc"]) {
|
|
79372
|
-
const path2 = (0,
|
|
79911
|
+
const path2 = (0, import_node_path7.join)(dir, name);
|
|
79373
79912
|
const model2 = stringField(readJsonObject(io, path2), "model");
|
|
79374
79913
|
if (model2) return { model: model2, modelSource: path2 };
|
|
79375
79914
|
}
|
|
79376
79915
|
return fallback;
|
|
79377
79916
|
}
|
|
79378
|
-
const path = (0,
|
|
79917
|
+
const path = (0, import_node_path7.join)(piAgentDir(io), "settings.json");
|
|
79379
79918
|
const settings = readJsonObject(io, path);
|
|
79380
79919
|
const model = stringField(settings, "defaultModel");
|
|
79381
79920
|
const provider = stringField(settings, "defaultProvider");
|
|
79382
79921
|
return model ? { model: provider ? `${provider}/${model}` : model, modelSource: path } : fallback;
|
|
79383
79922
|
}
|
|
79384
79923
|
function claudeConfigDir(io) {
|
|
79385
|
-
return io.env.CLAUDE_CONFIG_DIR || (0,
|
|
79924
|
+
return io.env.CLAUDE_CONFIG_DIR || (0, import_node_path7.join)(io.home, ".claude");
|
|
79386
79925
|
}
|
|
79387
79926
|
function codexHome(io) {
|
|
79388
|
-
return io.env.CODEX_HOME || (0,
|
|
79927
|
+
return io.env.CODEX_HOME || (0, import_node_path7.join)(io.home, ".codex");
|
|
79389
79928
|
}
|
|
79390
79929
|
function piAgentDir(io) {
|
|
79391
|
-
return io.env.PI_CODING_AGENT_DIR || (0,
|
|
79930
|
+
return io.env.PI_CODING_AGENT_DIR || (0, import_node_path7.join)(io.home, ".pi", "agent");
|
|
79392
79931
|
}
|
|
79393
79932
|
function topLevelTomlString(text3, key) {
|
|
79394
79933
|
for (const line2 of (text3 ?? "").split("\n")) {
|
|
@@ -79401,180 +79940,204 @@ function topLevelTomlString(text3, key) {
|
|
|
79401
79940
|
return void 0;
|
|
79402
79941
|
}
|
|
79403
79942
|
|
|
79404
|
-
// src/cli/
|
|
79405
|
-
var
|
|
79406
|
-
|
|
79407
|
-
|
|
79408
|
-
"
|
|
79409
|
-
|
|
79410
|
-
]
|
|
79411
|
-
|
|
79412
|
-
|
|
79413
|
-
const
|
|
79414
|
-
|
|
79415
|
-
|
|
79416
|
-
|
|
79417
|
-
|
|
79418
|
-
|
|
79419
|
-
|
|
79420
|
-
|
|
79421
|
-
|
|
79422
|
-
|
|
79423
|
-
|
|
79424
|
-
|
|
79425
|
-
|
|
79426
|
-
summary: [passes([key], "your environment", agent.name)]
|
|
79943
|
+
// src/cli/push-payload.ts
|
|
79944
|
+
var NO_BUILDING_BLOCKS = { packages: {}, codePatterns: [] };
|
|
79945
|
+
function pushRequest(file2, current, list, shown3, repositoryStacks) {
|
|
79946
|
+
const from = file2.from ? findCategoryRequests(file2.from) : void 0;
|
|
79947
|
+
const runsIn = from?.slug ?? "job-";
|
|
79948
|
+
const tools = [
|
|
79949
|
+
...file2.tools?.own !== void 0 ? [file2.tools.own] : [],
|
|
79950
|
+
...file2.tools?.competitors ?? []
|
|
79951
|
+
];
|
|
79952
|
+
const key = (ref) => typeof ref === "string" ? ref : ref.key;
|
|
79953
|
+
const shared = {
|
|
79954
|
+
environment_ids: environmentIds(
|
|
79955
|
+
file2,
|
|
79956
|
+
current,
|
|
79957
|
+
list,
|
|
79958
|
+
runsIn,
|
|
79959
|
+
shown3,
|
|
79960
|
+
repositoryStacks
|
|
79961
|
+
),
|
|
79962
|
+
agent_models: agentModels(file2, current, list, shown3),
|
|
79963
|
+
snapshot_digest: current ? file2.synced?.setup ?? null : null,
|
|
79964
|
+
...current ? { setup: current.id } : {}
|
|
79427
79965
|
};
|
|
79428
|
-
|
|
79429
|
-
|
|
79430
|
-
|
|
79431
|
-
|
|
79432
|
-
|
|
79433
|
-
|
|
79434
|
-
const keys = CLAUDE_KEYS.map(read).filter((k) => k !== null);
|
|
79435
|
-
if (keys.length > 0) {
|
|
79436
|
-
const baseUrl = read("ANTHROPIC_BASE_URL");
|
|
79437
|
-
const passed = baseUrl ? [...keys, baseUrl] : keys;
|
|
79966
|
+
if (from) {
|
|
79967
|
+
for (const ref of tools)
|
|
79968
|
+
if (typeof ref === "string" ? !CATEGORY_TOOLS[from.slug]?.includes(ref) && !current?.tools.some((row) => row.tool_key === ref) : !heldAsWritten(ref, current))
|
|
79969
|
+
throw new UsageError(
|
|
79970
|
+
`${shown3}: ${key(ref)} isn't a tool of ${from.slug}. Add it to a category copy in the DevTune app, then run agentpicks pull.`
|
|
79971
|
+
);
|
|
79438
79972
|
return {
|
|
79439
|
-
|
|
79440
|
-
|
|
79441
|
-
|
|
79442
|
-
|
|
79443
|
-
(
|
|
79444
|
-
|
|
79445
|
-
|
|
79446
|
-
|
|
79447
|
-
)
|
|
79448
|
-
)
|
|
79973
|
+
route: "setup",
|
|
79974
|
+
body: {
|
|
79975
|
+
category_id: categoryId(list, from.slug, shown3),
|
|
79976
|
+
tool_key: file2.tools?.own === void 0 ? null : key(file2.tools.own),
|
|
79977
|
+
competitor_tool_keys: (file2.tools?.competitors ?? []).map(key),
|
|
79978
|
+
...setupRequests(file2, current, from),
|
|
79979
|
+
...shared
|
|
79980
|
+
}
|
|
79449
79981
|
};
|
|
79450
79982
|
}
|
|
79451
|
-
|
|
79452
|
-
|
|
79453
|
-
|
|
79454
|
-
const accessToken = stringField(login, "accessToken");
|
|
79455
|
-
if (login && accessToken) {
|
|
79456
|
-
const expiresAt = typeof login.expiresAt === "number" && login.expiresAt > 0 ? login.expiresAt : null;
|
|
79457
|
-
if (expiresAt !== null && expiresAt < io.now() + RUN_WINDOW_MS)
|
|
79458
|
-
throw new LoginExpiringError(
|
|
79459
|
-
`Claude Code's sign-in on this machine ${expiresIn(expiresAt, io)}, before a run could finish. Run \`claude\` here so it renews, then try again, or set CLAUDE_CODE_OAUTH_TOKEN from \`claude setup-token\`.`
|
|
79460
|
-
);
|
|
79461
|
-
const copy = Object.fromEntries(
|
|
79462
|
-
Object.entries(login).filter(([key]) => key !== "refreshToken")
|
|
79983
|
+
if (file2.requests?.improve != null)
|
|
79984
|
+
throw new UsageError(
|
|
79985
|
+
`${shown3}: requests.improve can't be saved on a job. Remove it, and change it in DevTune instead.`
|
|
79463
79986
|
);
|
|
79464
|
-
|
|
79465
|
-
|
|
79466
|
-
|
|
79467
|
-
|
|
79468
|
-
source: path,
|
|
79469
|
-
path: "/root/.claude/.credentials.json",
|
|
79470
|
-
content: JSON.stringify({ claudeAiOauth: copy })
|
|
79471
|
-
}
|
|
79472
|
-
],
|
|
79473
|
-
secrets: [accessToken],
|
|
79474
|
-
summary: [copies("Claude Code", path, "/root/.claude/.credentials.json")]
|
|
79475
|
-
};
|
|
79476
|
-
}
|
|
79477
|
-
if (io.platform === "darwin")
|
|
79478
|
-
throw new KeychainLoginError(
|
|
79479
|
-
"Claude Code on macOS keeps its sign-in in the Keychain, which agentpicks doesn't read. Run `claude setup-token`, set CLAUDE_CODE_OAUTH_TOKEN to the token it prints, and try again. An ANTHROPIC_API_KEY works too."
|
|
79987
|
+
const recommend = file2.requests?.recommend;
|
|
79988
|
+
if (!recommend)
|
|
79989
|
+
throw new UsageError(
|
|
79990
|
+
`${shown3}: give requests.recommend. DevTune saves a job with its add and recommend requests.`
|
|
79480
79991
|
);
|
|
79481
|
-
|
|
79482
|
-
|
|
79483
|
-
|
|
79484
|
-
|
|
79485
|
-
|
|
79486
|
-
|
|
79487
|
-
|
|
79488
|
-
|
|
79489
|
-
|
|
79490
|
-
|
|
79491
|
-
|
|
79492
|
-
|
|
79493
|
-
|
|
79494
|
-
|
|
79495
|
-
|
|
79496
|
-
|
|
79497
|
-
|
|
79498
|
-
|
|
79499
|
-
|
|
79500
|
-
|
|
79501
|
-
);
|
|
79502
|
-
if (store === "keyring") throw keyring;
|
|
79503
|
-
const path = (0, import_node_path7.join)(home, "auth.json");
|
|
79504
|
-
const auth = readJsonObject(io, path);
|
|
79505
|
-
const tokens2 = auth?.tokens && typeof auth.tokens === "object" ? auth.tokens : null;
|
|
79506
|
-
const accessToken = stringField(tokens2, "access_token");
|
|
79507
|
-
const apiKey = stringField(auth, "OPENAI_API_KEY");
|
|
79508
|
-
if (auth && (accessToken || apiKey)) {
|
|
79509
|
-
const expiresAt = accessToken ? jwtExpiry(accessToken) : null;
|
|
79510
|
-
if (expiresAt !== null && expiresAt < io.now() + RUN_WINDOW_MS)
|
|
79511
|
-
throw new LoginExpiringError(
|
|
79512
|
-
`Codex's sign-in on this machine ${expiresIn(expiresAt, io)}, before a run could finish. Run \`codex\` here so it renews, then try again, or set OPENAI_API_KEY.`
|
|
79513
|
-
);
|
|
79514
|
-
const copy = tokens2 ? {
|
|
79515
|
-
...auth,
|
|
79516
|
-
tokens: { ...tokens2, refresh_token: "" },
|
|
79517
|
-
last_refresh: new Date(io.now()).toISOString()
|
|
79518
|
-
} : auth;
|
|
79519
|
-
return {
|
|
79520
|
-
env: {},
|
|
79521
|
-
files: [
|
|
79522
|
-
{
|
|
79523
|
-
source: path,
|
|
79524
|
-
path: "/root/.codex/auth.json",
|
|
79525
|
-
content: JSON.stringify(copy)
|
|
79526
|
-
}
|
|
79992
|
+
const listed = new Set(tools.map(key));
|
|
79993
|
+
const held = /* @__PURE__ */ new Set([
|
|
79994
|
+
...current?.own_tool_key ? [current.own_tool_key] : [],
|
|
79995
|
+
...current?.competitor_tool_keys ?? []
|
|
79996
|
+
]);
|
|
79997
|
+
return {
|
|
79998
|
+
route: "job",
|
|
79999
|
+
body: {
|
|
80000
|
+
job: file2.job,
|
|
80001
|
+
source_category_id: null,
|
|
80002
|
+
requests: {
|
|
80003
|
+
add: file2.requests?.add,
|
|
80004
|
+
recommend,
|
|
80005
|
+
hosted: file2.requests?.hosted ?? null
|
|
80006
|
+
},
|
|
80007
|
+
building_blocks: current?.building_blocks ?? NO_BUILDING_BLOCKS,
|
|
80008
|
+
tools: [
|
|
80009
|
+
...tools.map((ref) => jobTool(ref, current)),
|
|
80010
|
+
// A tool DevTune measures that is neither yours nor a competitor, which a file can't name.
|
|
80011
|
+
...(current?.tools ?? []).filter((row) => !listed.has(row.tool_key) && !held.has(row.tool_key)).map(heldJobTool)
|
|
79527
80012
|
],
|
|
79528
|
-
|
|
79529
|
-
|
|
79530
|
-
|
|
79531
|
-
|
|
79532
|
-
|
|
79533
|
-
|
|
79534
|
-
|
|
79535
|
-
|
|
80013
|
+
own_tool_key: file2.tools?.own === void 0 ? null : key(file2.tools.own),
|
|
80014
|
+
competitor_tool_keys: (file2.tools?.competitors ?? []).map(key),
|
|
80015
|
+
...shared
|
|
80016
|
+
}
|
|
80017
|
+
};
|
|
80018
|
+
}
|
|
80019
|
+
var OMITTED_REQUEST = "omitted";
|
|
80020
|
+
function setupRequests(file2, current, from) {
|
|
80021
|
+
const requests = {};
|
|
80022
|
+
for (const intent of PROMPT_INTENTS) {
|
|
80023
|
+
const text3 = file2.requests?.[intent];
|
|
80024
|
+
const published = from.prompts.find((p) => p.intent === intent)?.text;
|
|
80025
|
+
const held = current?.requests[intent] ?? null;
|
|
80026
|
+
if (text3 === null) requests[intent] = OMITTED_REQUEST;
|
|
80027
|
+
else if (text3 !== void 0) requests[intent] = text3;
|
|
80028
|
+
else if (current && published && held !== published)
|
|
80029
|
+
requests[intent] = published;
|
|
79536
80030
|
}
|
|
79537
|
-
|
|
79538
|
-
|
|
79539
|
-
|
|
80031
|
+
return Object.keys(requests).length ? { requests } : {};
|
|
80032
|
+
}
|
|
80033
|
+
function heldAsWritten(entry, current) {
|
|
80034
|
+
const row = current?.tools.find((each) => each.tool_key === entry.key);
|
|
80035
|
+
return row?.signals != null && canonical(fileTool({ ...row, signals: row.signals })) === canonical(entry);
|
|
80036
|
+
}
|
|
80037
|
+
function heldJobTool(row) {
|
|
80038
|
+
return row.signals === null ? { tool_key: row.tool_key } : {
|
|
80039
|
+
tool_key: row.tool_key,
|
|
80040
|
+
display_name: row.display_name,
|
|
80041
|
+
brand_domain: row.brand_domain,
|
|
80042
|
+
signals: row.signals
|
|
80043
|
+
};
|
|
80044
|
+
}
|
|
80045
|
+
function jobTool(ref, current) {
|
|
80046
|
+
const row = current?.tools.find(
|
|
80047
|
+
(each) => each.tool_key === (typeof ref === "string" ? ref : ref.key)
|
|
79540
80048
|
);
|
|
80049
|
+
if (typeof ref === "string")
|
|
80050
|
+
return row ? heldJobTool(row) : { tool_key: ref };
|
|
80051
|
+
return {
|
|
80052
|
+
tool_key: ref.key,
|
|
80053
|
+
display_name: ref.name,
|
|
80054
|
+
brand_domain: ref.domain ?? null,
|
|
80055
|
+
signals: jobSignals(ref, row?.signals ?? null)
|
|
80056
|
+
};
|
|
79541
80057
|
}
|
|
79542
|
-
function
|
|
79543
|
-
|
|
79544
|
-
|
|
79545
|
-
|
|
79546
|
-
|
|
79547
|
-
|
|
79548
|
-
|
|
79549
|
-
|
|
79550
|
-
|
|
79551
|
-
}
|
|
80058
|
+
function jobSignals(entry, held) {
|
|
80059
|
+
const { packages, configNames, importPatterns, brandDomains, ...rest } = entry.signals;
|
|
80060
|
+
return {
|
|
80061
|
+
packages: packages ?? {},
|
|
80062
|
+
configNames: configNames ?? [],
|
|
80063
|
+
importPatterns: importPatterns ?? [],
|
|
80064
|
+
brandDomains: brandDomains ?? [],
|
|
80065
|
+
...rest,
|
|
80066
|
+
...Array.isArray(held?.dismissedYieldsTo) ? { dismissedYieldsTo: held.dismissedYieldsTo } : {}
|
|
80067
|
+
};
|
|
79552
80068
|
}
|
|
79553
|
-
function
|
|
79554
|
-
const
|
|
79555
|
-
|
|
80069
|
+
function categoryId(list, slug2, shown3) {
|
|
80070
|
+
const category = list.catalogue.categories.find((c) => c.slug === slug2);
|
|
80071
|
+
if (!category)
|
|
80072
|
+
throw new UsageError(
|
|
80073
|
+
`${shown3}: DevTune has no published category ${slug2}. Choose another from:, or update agentpicks.`
|
|
80074
|
+
);
|
|
80075
|
+
return category.id;
|
|
79556
80076
|
}
|
|
79557
|
-
function
|
|
79558
|
-
|
|
80077
|
+
function environmentIds(file2, current, list, runsIn, shown3, repositoryStacks) {
|
|
80078
|
+
const stacks = file2.stacks ?? repositoryStacks?.filter((slug2) => nameableStack(slug2, runsIn));
|
|
80079
|
+
if (!stacks && current) return current.environments.map((env) => env.id);
|
|
80080
|
+
if (!stacks?.length)
|
|
80081
|
+
throw new UsageError(
|
|
80082
|
+
`${shown3}: couldn't detect any supported stacks for this repository. Replace repo: with stacks: (for example, stacks: [nextjs]), then push again. To test the repository, pass --repo to agentpicks run.`
|
|
80083
|
+
);
|
|
80084
|
+
const ids = stacks.map((slug2) => {
|
|
80085
|
+
const env = list.catalogue.environments.find((each) => each.slug === slug2);
|
|
80086
|
+
if (!env)
|
|
80087
|
+
throw new UsageError(
|
|
80088
|
+
`${shown3}: DevTune has no stack ${slug2}. Remove it from stacks:, or update agentpicks.`
|
|
80089
|
+
);
|
|
80090
|
+
return env.id;
|
|
80091
|
+
});
|
|
80092
|
+
const kept = (current?.environments ?? []).filter((env) => !nameableStack(env.slug, runsIn)).map((env) => env.id);
|
|
80093
|
+
return [.../* @__PURE__ */ new Set([...ids, ...kept])];
|
|
79559
80094
|
}
|
|
79560
|
-
function
|
|
79561
|
-
|
|
80095
|
+
function agentModels(file2, current, list, shown3) {
|
|
80096
|
+
const held = current?.agent_models ?? [];
|
|
80097
|
+
if (!file2.agents) {
|
|
80098
|
+
if (current) return held;
|
|
80099
|
+
throw new UsageError(
|
|
80100
|
+
`${shown3}: give agents:, the agents DevTune tests the setup with.`
|
|
80101
|
+
);
|
|
80102
|
+
}
|
|
80103
|
+
const named = file2.agents.map(devtuneAgent);
|
|
80104
|
+
return [
|
|
80105
|
+
...named.flatMap((agent) => {
|
|
80106
|
+
const models = held.filter((entry) => entry.agent === agent);
|
|
80107
|
+
if (models.length) return models;
|
|
80108
|
+
const model = list.catalogue.agents.find((each) => each.agent === agent)?.models[0];
|
|
80109
|
+
if (!model)
|
|
80110
|
+
throw new UsageError(
|
|
80111
|
+
`${shown3}: DevTune offers no model for ${agent}. Remove it from agents:.`
|
|
80112
|
+
);
|
|
80113
|
+
return [{ agent, model }];
|
|
80114
|
+
}),
|
|
80115
|
+
...held.filter(
|
|
80116
|
+
(entry) => !named.includes(entry.agent) && !SETUP_AGENT_KINDS.includes(entry.agent)
|
|
80117
|
+
)
|
|
80118
|
+
];
|
|
79562
80119
|
}
|
|
80120
|
+
var SETUP_AGENT_KINDS = SELF_RUN_AGENTS.map((agent) => agent.kind);
|
|
80121
|
+
|
|
80122
|
+
// src/cli/setup-links.ts
|
|
80123
|
+
var import_node_fs6 = require("node:fs");
|
|
80124
|
+
var import_node_path10 = require("node:path");
|
|
80125
|
+
var import_yaml3 = __toESM(require_dist());
|
|
79563
80126
|
|
|
79564
80127
|
// src/cli/devtune-login.ts
|
|
79565
|
-
var
|
|
80128
|
+
var import_node_crypto7 = require("node:crypto");
|
|
79566
80129
|
var import_node_fs4 = require("node:fs");
|
|
79567
80130
|
var import_promises2 = require("node:fs/promises");
|
|
79568
|
-
var
|
|
80131
|
+
var import_node_path8 = require("node:path");
|
|
79569
80132
|
var import_promises3 = require("node:timers/promises");
|
|
79570
80133
|
|
|
79571
80134
|
// src/cli/oauth.ts
|
|
79572
80135
|
var import_node_child_process4 = require("node:child_process");
|
|
79573
|
-
var
|
|
80136
|
+
var import_node_crypto6 = require("node:crypto");
|
|
79574
80137
|
var import_node_http = require("node:http");
|
|
79575
80138
|
|
|
79576
80139
|
// src/cli/login-page.ts
|
|
79577
|
-
var
|
|
80140
|
+
var import_node_crypto5 = require("node:crypto");
|
|
79578
80141
|
var styles = `
|
|
79579
80142
|
:root { color-scheme: light dark; --canvas: #fafafa; --text: #1a1a1c; --muted: #62626c; }
|
|
79580
80143
|
* { box-sizing: border-box; }
|
|
@@ -79585,7 +80148,7 @@ p { margin: 0; color: var(--muted); font-size: 16px; line-height: 1.65; text-wra
|
|
|
79585
80148
|
.hint { margin-top: 32px; font-size: 13px; }
|
|
79586
80149
|
@media (prefers-color-scheme: dark) { :root { --canvas: #0a0a0a; --text: #fafafa; --muted: #8a8a8a; } }
|
|
79587
80150
|
`;
|
|
79588
|
-
var loginPageCsp = `default-src 'none'; style-src 'sha256-${(0,
|
|
80151
|
+
var loginPageCsp = `default-src 'none'; style-src 'sha256-${(0, import_node_crypto5.createHash)("sha256").update(styles).digest("base64")}'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'`;
|
|
79589
80152
|
var messages = {
|
|
79590
80153
|
success: {
|
|
79591
80154
|
heading: "You're signed in",
|
|
@@ -79629,292 +80192,6 @@ function loginPage(state) {
|
|
|
79629
80192
|
</html>`;
|
|
79630
80193
|
}
|
|
79631
80194
|
|
|
79632
|
-
// src/cli/upload.ts
|
|
79633
|
-
var import_node_crypto4 = require("node:crypto");
|
|
79634
|
-
var import_node_fs3 = require("node:fs");
|
|
79635
|
-
var import_node_path8 = require("node:path");
|
|
79636
|
-
var API_TIMEOUT_MS = 6e4;
|
|
79637
|
-
var PUT_TIMEOUT_MS = 10 * 6e4;
|
|
79638
|
-
var BUNDLE_JSON_MAX_BYTES = 1024 * 1024;
|
|
79639
|
-
function readBundle(dir) {
|
|
79640
|
-
const raw = readJson(dir, BUNDLE_PATHS.manifest);
|
|
79641
|
-
const manifest = bundleManifestSchema.safeParse(raw);
|
|
79642
|
-
if (!manifest.success)
|
|
79643
|
-
throw new BundleError(
|
|
79644
|
-
`${dir} is not a bundle agentpicks wrote: ${external_exports.prettifyError(manifest.error)}`
|
|
79645
|
-
);
|
|
79646
|
-
const redactions = redactionSummarySchema.safeParse(
|
|
79647
|
-
readJson(dir, BUNDLE_PATHS.redactions)
|
|
79648
|
-
);
|
|
79649
|
-
if (!redactions.success)
|
|
79650
|
-
throw new BundleError(
|
|
79651
|
-
`${dir} is not a bundle agentpicks wrote: ${BUNDLE_PATHS.redactions} doesn't match the bundle format.`
|
|
79652
|
-
);
|
|
79653
|
-
const files = [
|
|
79654
|
-
{
|
|
79655
|
-
path: BUNDLE_PATHS.manifest,
|
|
79656
|
-
bytes: (0, import_node_fs3.lstatSync)((0, import_node_path8.join)(dir, BUNDLE_PATHS.manifest)).size
|
|
79657
|
-
}
|
|
79658
|
-
];
|
|
79659
|
-
const contents = /* @__PURE__ */ new Map();
|
|
79660
|
-
for (const artifact of manifest.data.artifacts) {
|
|
79661
|
-
const path = `${BUNDLE_PATHS.artifacts}/${artifact.name}`;
|
|
79662
|
-
const limit = uploadArtifactByteLimit(artifact.name);
|
|
79663
|
-
if (artifact.bytes > limit)
|
|
79664
|
-
throw new BundleError(
|
|
79665
|
-
`${(0, import_node_path8.join)(dir, path)} is ${artifact.bytes} bytes; DevTune takes at most ${limit} for ${artifact.name}.`
|
|
79666
|
-
);
|
|
79667
|
-
const bytes = readRegularFile(dir, path, artifact.bytes);
|
|
79668
|
-
if (bytes === null || (0, import_node_crypto4.createHash)("sha256").update(bytes).digest("hex") !== artifact.sha256)
|
|
79669
|
-
throw new BundleError(
|
|
79670
|
-
`${(0, import_node_path8.join)(dir, path)} isn't the file its manifest declares: the bundle changed after agentpicks wrote it.`
|
|
79671
|
-
);
|
|
79672
|
-
files.push({ path, bytes: bytes.length });
|
|
79673
|
-
contents.set(artifact.name, bytes);
|
|
79674
|
-
}
|
|
79675
|
-
const setup = bundleSetupSchema.safeParse(
|
|
79676
|
-
raw && typeof raw === "object" && "setup" in raw ? raw.setup : void 0
|
|
79677
|
-
);
|
|
79678
|
-
const earlyStop = bundleEarlyStopSchema.safeParse(
|
|
79679
|
-
raw && typeof raw === "object" && "earlyStop" in raw ? raw.earlyStop : void 0
|
|
79680
|
-
);
|
|
79681
|
-
return {
|
|
79682
|
-
dir,
|
|
79683
|
-
manifest: manifest.data,
|
|
79684
|
-
files,
|
|
79685
|
-
redactions: redactions.data,
|
|
79686
|
-
contents,
|
|
79687
|
-
...setup.success ? { setup: setup.data } : {},
|
|
79688
|
-
...earlyStop.success ? { earlyStop: earlyStop.data } : {}
|
|
79689
|
-
};
|
|
79690
|
-
}
|
|
79691
|
-
function findBundles(dir) {
|
|
79692
|
-
if (isFile((0, import_node_path8.join)(dir, BUNDLE_PATHS.manifest))) return [dir];
|
|
79693
|
-
let names2;
|
|
79694
|
-
try {
|
|
79695
|
-
names2 = (0, import_node_fs3.readdirSync)(dir);
|
|
79696
|
-
} catch (error62) {
|
|
79697
|
-
throw new BundleError(
|
|
79698
|
-
`${dir} can't be read: ${error62 instanceof Error ? error62.message : String(error62)}`
|
|
79699
|
-
);
|
|
79700
|
-
}
|
|
79701
|
-
const bundles = names2.filter((name) => !name.startsWith(".")).sort().map((name) => (0, import_node_path8.join)(dir, name)).filter((path) => isFile((0, import_node_path8.join)(path, BUNDLE_PATHS.manifest)));
|
|
79702
|
-
if (bundles.length === 0)
|
|
79703
|
-
throw new BundleError(
|
|
79704
|
-
`${dir} holds no bundle: pass a bundle directory, or the --out directory of agentpicks run.`
|
|
79705
|
-
);
|
|
79706
|
-
return bundles;
|
|
79707
|
-
}
|
|
79708
|
-
var uploadStatusSchema = external_exports.object({
|
|
79709
|
-
run_id: external_exports.string(),
|
|
79710
|
-
status: external_exports.enum(["open", "completed", "expired"]),
|
|
79711
|
-
run: external_exports.object({ id: external_exports.string(), analysis: external_exports.string() }).nullable()
|
|
79712
|
-
});
|
|
79713
|
-
var createdSchema = uploadStatusSchema.extend({
|
|
79714
|
-
uploads: external_exports.array(external_exports.object({ name: external_exports.string(), url: external_exports.string().nullable() }))
|
|
79715
|
-
});
|
|
79716
|
-
async function uploadBundle(bundle, target) {
|
|
79717
|
-
const uploads = `${target.baseUrl}/projects/${target.projectId}/agent-picks/uploads`;
|
|
79718
|
-
const created = await callApi(target, createdSchema, uploads, {
|
|
79719
|
-
method: "POST",
|
|
79720
|
-
body: JSON.stringify(bundle.manifest)
|
|
79721
|
-
});
|
|
79722
|
-
const statusUrl = `${uploads}/${created.run_id}`;
|
|
79723
|
-
if (created.status === "expired")
|
|
79724
|
-
throw new UploadError(
|
|
79725
|
-
`DevTune reports the upload of run ${created.run_id} as expired.`
|
|
79726
|
-
);
|
|
79727
|
-
if (created.status === "completed")
|
|
79728
|
-
return {
|
|
79729
|
-
runId: created.run_id,
|
|
79730
|
-
statusUrl,
|
|
79731
|
-
sent: 0,
|
|
79732
|
-
analysis: created.run?.analysis ?? null
|
|
79733
|
-
};
|
|
79734
|
-
let sent = 0;
|
|
79735
|
-
for (const { name, url: url2 } of created.uploads) {
|
|
79736
|
-
if (url2 === null) continue;
|
|
79737
|
-
const bytes = bundle.contents.get(name);
|
|
79738
|
-
if (!bytes)
|
|
79739
|
-
throw new UploadError(
|
|
79740
|
-
`DevTune asked for ${name}, which the bundle's manifest doesn't declare.`
|
|
79741
|
-
);
|
|
79742
|
-
if (await putArtifact(url2, bytes, `${BUNDLE_PATHS.artifacts}/${name}`))
|
|
79743
|
-
sent++;
|
|
79744
|
-
}
|
|
79745
|
-
const completed = await callApi(
|
|
79746
|
-
target,
|
|
79747
|
-
uploadStatusSchema,
|
|
79748
|
-
`${statusUrl}/complete`,
|
|
79749
|
-
{ method: "POST" }
|
|
79750
|
-
);
|
|
79751
|
-
return {
|
|
79752
|
-
runId: completed.run_id,
|
|
79753
|
-
statusUrl,
|
|
79754
|
-
sent,
|
|
79755
|
-
analysis: completed.run?.analysis ?? null
|
|
79756
|
-
};
|
|
79757
|
-
}
|
|
79758
|
-
var connectionSchema = external_exports.object({
|
|
79759
|
-
project: external_exports.object({ id: external_exports.uuid(), name: external_exports.string() }),
|
|
79760
|
-
credential: external_exports.object({ type: external_exports.string() }),
|
|
79761
|
-
scopes: external_exports.array(external_exports.string())
|
|
79762
|
-
});
|
|
79763
|
-
async function discoverProject(target) {
|
|
79764
|
-
return callApi(target, connectionSchema, `${target.baseUrl}/connection`, {
|
|
79765
|
-
method: "GET"
|
|
79766
|
-
});
|
|
79767
|
-
}
|
|
79768
|
-
async function putArtifact(url2, bytes, path) {
|
|
79769
|
-
let response;
|
|
79770
|
-
try {
|
|
79771
|
-
response = await fetch(url2, {
|
|
79772
|
-
method: "PUT",
|
|
79773
|
-
headers: { "Content-Type": "application/octet-stream" },
|
|
79774
|
-
body: new Uint8Array(bytes),
|
|
79775
|
-
redirect: "error",
|
|
79776
|
-
signal: AbortSignal.timeout(PUT_TIMEOUT_MS)
|
|
79777
|
-
});
|
|
79778
|
-
} catch (error62) {
|
|
79779
|
-
throw new UploadError(
|
|
79780
|
-
`Uploading ${path} to storage failed (${transportCode(error62)}). Run agentpicks upload again to send what isn't stored.`
|
|
79781
|
-
);
|
|
79782
|
-
}
|
|
79783
|
-
if (response.ok) {
|
|
79784
|
-
await response.body?.cancel();
|
|
79785
|
-
return true;
|
|
79786
|
-
}
|
|
79787
|
-
let text3 = "";
|
|
79788
|
-
try {
|
|
79789
|
-
text3 = await response.text();
|
|
79790
|
-
} catch {
|
|
79791
|
-
}
|
|
79792
|
-
if (response.status === 409 || /"statusCode"\s*:\s*"409"/.test(text3))
|
|
79793
|
-
return false;
|
|
79794
|
-
throw new UploadError(
|
|
79795
|
-
`Uploading ${path} failed: Storage answered ${response.status}.`
|
|
79796
|
-
);
|
|
79797
|
-
}
|
|
79798
|
-
var apiErrorSchema = external_exports.object({
|
|
79799
|
-
message: external_exports.string().min(1),
|
|
79800
|
-
reason: external_exports.string().optional()
|
|
79801
|
-
});
|
|
79802
|
-
async function callApi(target, schema, url2, init) {
|
|
79803
|
-
let bearer;
|
|
79804
|
-
try {
|
|
79805
|
-
bearer = "apiKey" in target ? target.apiKey : await target.session.accessToken();
|
|
79806
|
-
} catch (error62) {
|
|
79807
|
-
if (error62 instanceof SignInError)
|
|
79808
|
-
throw new UploadError(error62.message, { transient: error62.transient });
|
|
79809
|
-
throw error62;
|
|
79810
|
-
}
|
|
79811
|
-
let response;
|
|
79812
|
-
try {
|
|
79813
|
-
response = await fetch(url2, {
|
|
79814
|
-
...init,
|
|
79815
|
-
headers: {
|
|
79816
|
-
Authorization: `Bearer ${bearer}`,
|
|
79817
|
-
Accept: "application/json",
|
|
79818
|
-
...init.body === void 0 ? {} : { "Content-Type": "application/json" }
|
|
79819
|
-
},
|
|
79820
|
-
redirect: "error",
|
|
79821
|
-
signal: AbortSignal.timeout(API_TIMEOUT_MS)
|
|
79822
|
-
});
|
|
79823
|
-
} catch (error62) {
|
|
79824
|
-
throw new UploadError(
|
|
79825
|
-
`Couldn't reach DevTune at ${target.baseUrl} (${transportCode(error62)}). Check the connection and try again.`,
|
|
79826
|
-
{ transient: true }
|
|
79827
|
-
);
|
|
79828
|
-
}
|
|
79829
|
-
let body = null;
|
|
79830
|
-
try {
|
|
79831
|
-
body = await response.json();
|
|
79832
|
-
} catch {
|
|
79833
|
-
}
|
|
79834
|
-
if (!response.ok) {
|
|
79835
|
-
const message = apiErrorSchema.safeParse(body);
|
|
79836
|
-
const refused = {
|
|
79837
|
-
status: response.status,
|
|
79838
|
-
...message.data?.reason ? { reason: message.data.reason } : {}
|
|
79839
|
-
};
|
|
79840
|
-
if (isTransientStatus(response.status))
|
|
79841
|
-
throw new UploadError(
|
|
79842
|
-
message.success ? message.data.message : `DevTune answered ${response.status}.`,
|
|
79843
|
-
{ transient: true, ...refused }
|
|
79844
|
-
);
|
|
79845
|
-
if ("session" in target) {
|
|
79846
|
-
if (message.success)
|
|
79847
|
-
throw new UploadError(
|
|
79848
|
-
message.data.message.replaceAll("devtune login", "agentpicks login"),
|
|
79849
|
-
refused
|
|
79850
|
-
);
|
|
79851
|
-
throw new UploadError(
|
|
79852
|
-
response.status === 401 ? "DevTune refused the sign-in. Run agentpicks login again." : `DevTune answered ${response.status}.`,
|
|
79853
|
-
refused
|
|
79854
|
-
);
|
|
79855
|
-
}
|
|
79856
|
-
if (!message.success)
|
|
79857
|
-
throw new UploadError(`DevTune answered ${response.status}.`, refused);
|
|
79858
|
-
throw new UploadError(
|
|
79859
|
-
response.status === 401 ? `${message.data.message.replace(/\.?$/, ".")} Run agentpicks login, or set DEVTUNE_API_KEY.` : message.data.message,
|
|
79860
|
-
refused
|
|
79861
|
-
);
|
|
79862
|
-
}
|
|
79863
|
-
const data = external_exports.object({ data: schema }).safeParse(body);
|
|
79864
|
-
if (!data.success)
|
|
79865
|
-
throw new UploadError(
|
|
79866
|
-
`DevTune's answer from ${new URL(url2).pathname} wasn't the expected shape.`
|
|
79867
|
-
);
|
|
79868
|
-
return data.data.data;
|
|
79869
|
-
}
|
|
79870
|
-
function readJson(dir, path) {
|
|
79871
|
-
const bytes = readRegularFile(dir, path, null, BUNDLE_JSON_MAX_BYTES);
|
|
79872
|
-
try {
|
|
79873
|
-
if (bytes === null) throw new Error("not a regular file within its limit");
|
|
79874
|
-
return JSON.parse(bytes.toString("utf8"));
|
|
79875
|
-
} catch {
|
|
79876
|
-
throw new BundleError(
|
|
79877
|
-
`${dir} is not a bundle agentpicks wrote: ${path} is missing, too large or isn't JSON.`
|
|
79878
|
-
);
|
|
79879
|
-
}
|
|
79880
|
-
}
|
|
79881
|
-
function readRegularFile(dir, path, bytes, max = Infinity) {
|
|
79882
|
-
const full = (0, import_node_path8.join)(dir, path);
|
|
79883
|
-
let fd = null;
|
|
79884
|
-
try {
|
|
79885
|
-
const stat = (0, import_node_fs3.lstatSync)(full);
|
|
79886
|
-
if (!stat.isFile() || stat.size > max) return null;
|
|
79887
|
-
if (bytes !== null && stat.size !== bytes) return null;
|
|
79888
|
-
fd = (0, import_node_fs3.openSync)(full, import_node_fs3.constants.O_RDONLY | (import_node_fs3.constants.O_NOFOLLOW ?? 0));
|
|
79889
|
-
const buffer = Buffer.alloc(stat.size);
|
|
79890
|
-
let read = 0;
|
|
79891
|
-
while (read < buffer.length) {
|
|
79892
|
-
const n = (0, import_node_fs3.readSync)(fd, buffer, read, buffer.length - read, read);
|
|
79893
|
-
if (n === 0) return null;
|
|
79894
|
-
read += n;
|
|
79895
|
-
}
|
|
79896
|
-
return buffer;
|
|
79897
|
-
} catch {
|
|
79898
|
-
return null;
|
|
79899
|
-
} finally {
|
|
79900
|
-
if (fd !== null) (0, import_node_fs3.closeSync)(fd);
|
|
79901
|
-
}
|
|
79902
|
-
}
|
|
79903
|
-
function isFile(path) {
|
|
79904
|
-
try {
|
|
79905
|
-
return (0, import_node_fs3.statSync)(path).isFile();
|
|
79906
|
-
} catch {
|
|
79907
|
-
return false;
|
|
79908
|
-
}
|
|
79909
|
-
}
|
|
79910
|
-
function transportCode(error62) {
|
|
79911
|
-
if (!(error62 instanceof Error)) return "unknown error";
|
|
79912
|
-
if (error62.name === "TimeoutError") return "timed out";
|
|
79913
|
-
const code = error62.cause?.code ?? error62.code;
|
|
79914
|
-
const name = typeof code === "string" ? code : error62.name;
|
|
79915
|
-
return /^\w+$/.test(name) ? name : "unknown error";
|
|
79916
|
-
}
|
|
79917
|
-
|
|
79918
80195
|
// src/cli/oauth.ts
|
|
79919
80196
|
var AGENTPICKS_SCOPES = [
|
|
79920
80197
|
"agent_picks.run",
|
|
@@ -80106,7 +80383,7 @@ async function callback(state, timeoutMs = LOGIN_TIMEOUT_MS) {
|
|
|
80106
80383
|
return;
|
|
80107
80384
|
}
|
|
80108
80385
|
const supplied = url2.searchParams.get("state") ?? "";
|
|
80109
|
-
const validState = Buffer.byteLength(supplied) === Buffer.byteLength(state) && (0,
|
|
80386
|
+
const validState = Buffer.byteLength(supplied) === Buffer.byteLength(state) && (0, import_node_crypto6.timingSafeEqual)(Buffer.from(supplied), Buffer.from(state));
|
|
80110
80387
|
if (consumed || request2.method !== "GET" || request2.headers.host !== expectedHost || url2.pathname !== "/oauth/callback" || !validState || url2.searchParams.getAll("state").length !== 1 || url2.searchParams.getAll("code").length > 1 || url2.searchParams.getAll("error").length > 1 || url2.searchParams.getAll("iss").length > 1) {
|
|
80111
80388
|
response.writeHead(400);
|
|
80112
80389
|
response.end(loginPage("invalid"));
|
|
@@ -80188,8 +80465,8 @@ async function openBrowser(url2) {
|
|
|
80188
80465
|
async function browserLogin(options) {
|
|
80189
80466
|
const { baseUrl } = options;
|
|
80190
80467
|
const config2 = await discover(baseUrl);
|
|
80191
|
-
const state = (0,
|
|
80192
|
-
const verifier = (0,
|
|
80468
|
+
const state = (0, import_node_crypto6.randomBytes)(32).toString("base64url");
|
|
80469
|
+
const verifier = (0, import_node_crypto6.randomBytes)(32).toString("base64url");
|
|
80193
80470
|
const listener = await callback(state);
|
|
80194
80471
|
try {
|
|
80195
80472
|
const registration = await json2(config2.registrationEndpoint, {
|
|
@@ -80212,7 +80489,7 @@ async function browserLogin(options) {
|
|
|
80212
80489
|
redirect_uri: listener.url,
|
|
80213
80490
|
scope: "email offline_access",
|
|
80214
80491
|
state,
|
|
80215
|
-
code_challenge: (0,
|
|
80492
|
+
code_challenge: (0, import_node_crypto6.createHash)("sha256").update(verifier).digest("base64url"),
|
|
80216
80493
|
code_challenge_method: "S256",
|
|
80217
80494
|
resource: baseUrl
|
|
80218
80495
|
}).toString();
|
|
@@ -80304,8 +80581,8 @@ var savedSessionSchema = external_exports.object({
|
|
|
80304
80581
|
);
|
|
80305
80582
|
var savedLoginSchema = external_exports.union([savedSessionSchema, savedKeySchema]);
|
|
80306
80583
|
function loginPath(io) {
|
|
80307
|
-
const config2 = io.env.XDG_CONFIG_HOME || io.platform === "win32" && io.env.APPDATA || (0,
|
|
80308
|
-
return (0,
|
|
80584
|
+
const config2 = io.env.XDG_CONFIG_HOME || io.platform === "win32" && io.env.APPDATA || (0, import_node_path8.join)(io.home, ".config");
|
|
80585
|
+
return (0, import_node_path8.join)(config2, "agentpicks", "credentials.json");
|
|
80309
80586
|
}
|
|
80310
80587
|
function apiRoot(value) {
|
|
80311
80588
|
let url2;
|
|
@@ -80438,7 +80715,7 @@ async function finishBeforeExit(work) {
|
|
|
80438
80715
|
var LOCK_WAIT_MS = 9e4;
|
|
80439
80716
|
var NO_LOCK = "agentpicks can't lock its saved login on this machine, which a browser sign-in needs. Set DEVTUNE_API_KEY and DEVTUNE_PROJECT_ID, or save a project API key with agentpicks login --api-key.";
|
|
80440
80717
|
async function withLoginLock(path, action, options = {}) {
|
|
80441
|
-
await ensureLoginDirectory((0,
|
|
80718
|
+
await ensureLoginDirectory((0, import_node_path8.dirname)(path));
|
|
80442
80719
|
const unsupported = () => {
|
|
80443
80720
|
if (!options.unlockedIfUnsupported) throw new SignInError(NO_LOCK);
|
|
80444
80721
|
let saved = null;
|
|
@@ -80498,11 +80775,11 @@ async function ensureLoginDirectory(dir) {
|
|
|
80498
80775
|
);
|
|
80499
80776
|
}
|
|
80500
80777
|
async function saveLogin(path, login) {
|
|
80501
|
-
const dir = (0,
|
|
80778
|
+
const dir = (0, import_node_path8.dirname)(path);
|
|
80502
80779
|
await ensureLoginDirectory(dir);
|
|
80503
|
-
const partial2 = (0,
|
|
80780
|
+
const partial2 = (0, import_node_path8.join)(
|
|
80504
80781
|
dir,
|
|
80505
|
-
`.credentials.${(0,
|
|
80782
|
+
`.credentials.${(0, import_node_crypto7.randomBytes)(16).toString("hex")}.partial`
|
|
80506
80783
|
);
|
|
80507
80784
|
try {
|
|
80508
80785
|
await (0, import_promises2.writeFile)(partial2, `${JSON.stringify(login, null, 2)}
|
|
@@ -80556,6 +80833,445 @@ async function readSecretLine(prompt) {
|
|
|
80556
80833
|
}
|
|
80557
80834
|
}
|
|
80558
80835
|
|
|
80836
|
+
// src/cli/setup-write.ts
|
|
80837
|
+
var import_node_crypto8 = require("node:crypto");
|
|
80838
|
+
var import_node_fs5 = require("node:fs");
|
|
80839
|
+
var import_node_path9 = require("node:path");
|
|
80840
|
+
function isSymlink(path) {
|
|
80841
|
+
try {
|
|
80842
|
+
return (0, import_node_fs5.lstatSync)(path).isSymbolicLink();
|
|
80843
|
+
} catch (error62) {
|
|
80844
|
+
if (error62.code === "ENOENT") return false;
|
|
80845
|
+
throw error62;
|
|
80846
|
+
}
|
|
80847
|
+
}
|
|
80848
|
+
function writeSetupText(dir, path, text3, options) {
|
|
80849
|
+
for (const target of [dir, path])
|
|
80850
|
+
if (isSymlink(target))
|
|
80851
|
+
throw new UsageError(
|
|
80852
|
+
`${options.shown(target)} is a symbolic link, and agentpicks writes setup files only to a real file in a real directory. Remove the link and run the command again.`
|
|
80853
|
+
);
|
|
80854
|
+
(0, import_node_fs5.mkdirSync)(dir, { recursive: true });
|
|
80855
|
+
const temporary = (0, import_node_path9.join)(dir, `.agentpicks-${(0, import_node_crypto8.randomUUID)()}.tmp`);
|
|
80856
|
+
try {
|
|
80857
|
+
(0, import_node_fs5.writeFileSync)(temporary, text3, { flag: "wx" });
|
|
80858
|
+
if (options.replace) (0, import_node_fs5.renameSync)(temporary, path);
|
|
80859
|
+
else linkOrCopy(temporary, path);
|
|
80860
|
+
} finally {
|
|
80861
|
+
if ((0, import_node_fs5.existsSync)(temporary)) (0, import_node_fs5.unlinkSync)(temporary);
|
|
80862
|
+
}
|
|
80863
|
+
}
|
|
80864
|
+
function linkOrCopy(temporary, path) {
|
|
80865
|
+
try {
|
|
80866
|
+
(0, import_node_fs5.linkSync)(temporary, path);
|
|
80867
|
+
} catch (error62) {
|
|
80868
|
+
const code = error62.code;
|
|
80869
|
+
if (code !== "EPERM" && code !== "ENOTSUP" && code !== "ENOSYS")
|
|
80870
|
+
throw error62;
|
|
80871
|
+
(0, import_node_fs5.copyFileSync)(temporary, path, import_node_fs5.constants.COPYFILE_EXCL);
|
|
80872
|
+
}
|
|
80873
|
+
}
|
|
80874
|
+
|
|
80875
|
+
// src/cli/setup-links.ts
|
|
80876
|
+
async function readSetups(ctx, purpose = "setups") {
|
|
80877
|
+
const target = devtuneTarget(ctx.io, purpose);
|
|
80878
|
+
const list = await readDevtuneSetups(target);
|
|
80879
|
+
return { target, list, names: devtuneSetupNames(list.setups) };
|
|
80880
|
+
}
|
|
80881
|
+
function heldTools(setups) {
|
|
80882
|
+
return (id) => setups.list.setups.find((setup) => setup.id === id)?.tools;
|
|
80883
|
+
}
|
|
80884
|
+
function findDevtuneSetup(setups, arg) {
|
|
80885
|
+
return setups.list.setups.find(
|
|
80886
|
+
(setup) => setups.names.get(setup.id) === arg || setup.id === arg || setup.category_slug === arg
|
|
80887
|
+
);
|
|
80888
|
+
}
|
|
80889
|
+
function writeLink(path, content, link, shown3) {
|
|
80890
|
+
const document = (0, import_yaml3.parseDocument)((0, import_node_fs6.readFileSync)(path, "utf8"));
|
|
80891
|
+
document.set("id", link.id);
|
|
80892
|
+
document.set("synced", {
|
|
80893
|
+
setup: link.setupDigest,
|
|
80894
|
+
file: fileDigest(content)
|
|
80895
|
+
});
|
|
80896
|
+
writeSetupText((0, import_node_path10.dirname)(path), path, document.toString({ lineWidth: 0 }), {
|
|
80897
|
+
replace: true,
|
|
80898
|
+
shown: shown3
|
|
80899
|
+
});
|
|
80900
|
+
}
|
|
80901
|
+
function orphanedMessage(shown3, id) {
|
|
80902
|
+
return `${shown3} is linked to DevTune setup ${id}, which the project no longer has. Remove id and synced from it to push it as a new setup, or delete the file.`;
|
|
80903
|
+
}
|
|
80904
|
+
async function devtuneRunSetup(name, root, ctx) {
|
|
80905
|
+
let setups;
|
|
80906
|
+
try {
|
|
80907
|
+
setups = await readSetups(ctx);
|
|
80908
|
+
} catch (error62) {
|
|
80909
|
+
if (error62 instanceof NotLoggedInError) return null;
|
|
80910
|
+
throw error62;
|
|
80911
|
+
}
|
|
80912
|
+
const setup = findDevtuneSetup(setups, name);
|
|
80913
|
+
return setup ? runSetupOf(setups, setup, root) : null;
|
|
80914
|
+
}
|
|
80915
|
+
function runSetupOf(setups, setup, root) {
|
|
80916
|
+
const name = setups.names.get(setup.id);
|
|
80917
|
+
const shown3 = `DevTune setup ${name}`;
|
|
80918
|
+
const mapped = devtuneSetupFile(setup);
|
|
80919
|
+
if ("problem" in mapped) throw new UsageError(`${shown3}: ${mapped.problem}`);
|
|
80920
|
+
const resolved = resolveSetup(
|
|
80921
|
+
name,
|
|
80922
|
+
{ ...mapped.file, id: setup.id },
|
|
80923
|
+
setup.tools
|
|
80924
|
+
);
|
|
80925
|
+
if (!("setup" in resolved))
|
|
80926
|
+
throw new UsageError(
|
|
80927
|
+
`${shown3} can't run as it stands: ${resolved.problems.map((p) => `${p.field}: ${p.message}`).join(" ")} Pull it with agentpicks pull ${name}, fix the file, and run that.`
|
|
80928
|
+
);
|
|
80929
|
+
const published = resolved.setup.from ? findCategoryRequests(resolved.setup.from)?.prompts[0].text : void 0;
|
|
80930
|
+
if (resolved.setup.request.text !== published)
|
|
80931
|
+
throw new UsageError(
|
|
80932
|
+
`${shown3} asks its own add request, which agentpicks runs only from a setup file. Write it as a file with agentpicks pull ${name}, then run that file; commit it for a workflow to run.`
|
|
80933
|
+
);
|
|
80934
|
+
return {
|
|
80935
|
+
path: shown3,
|
|
80936
|
+
name: resolved.setup.name,
|
|
80937
|
+
root,
|
|
80938
|
+
setup: resolved.setup
|
|
80939
|
+
};
|
|
80940
|
+
}
|
|
80941
|
+
function unpushedMessage(shown3, name) {
|
|
80942
|
+
return `${shown3} has changes not pushed to its DevTune setup, so its runs would ask what DevTune doesn't hold. Run agentpicks push ${name}, then run it again, or pass --no-upload to keep the bundles on this machine.`;
|
|
80943
|
+
}
|
|
80944
|
+
function hasUnpushedChanges(content) {
|
|
80945
|
+
return !content.synced || fileDigest(content) !== content.synced.file;
|
|
80946
|
+
}
|
|
80947
|
+
function devtuneChangedMessage(shown3, name) {
|
|
80948
|
+
return `${shown3}'s DevTune setup changed since the file last saw it, so its runs would ask what DevTune no longer holds. Run agentpicks pull ${name}, then run it again, or pass --no-upload to keep the bundles on this machine.`;
|
|
80949
|
+
}
|
|
80950
|
+
async function linkedSetup(id, shown3, ctx) {
|
|
80951
|
+
const setups = await readSetups(ctx, "upload");
|
|
80952
|
+
const setup = setups.list.setups.find((each) => each.id === id);
|
|
80953
|
+
if (!setup) throw new UsageError(orphanedMessage(shown3, id));
|
|
80954
|
+
return setup;
|
|
80955
|
+
}
|
|
80956
|
+
async function linkUploads(plan, setup, content, shown3, ctx) {
|
|
80957
|
+
const unpushed = setup.id !== null && content !== void 0 && hasUnpushedChanges(content);
|
|
80958
|
+
if (!plan.upload)
|
|
80959
|
+
return unpushed && plan.setup ? {
|
|
80960
|
+
...plan,
|
|
80961
|
+
setup: {
|
|
80962
|
+
...plan.setup,
|
|
80963
|
+
record: { ...plan.setup.record, unpushed: true }
|
|
80964
|
+
}
|
|
80965
|
+
} : plan;
|
|
80966
|
+
if (setup.id === null) {
|
|
80967
|
+
if (setup.customReason && content && hasOwnTools(content))
|
|
80968
|
+
throw new UsageError(
|
|
80969
|
+
`${shown3} is a custom setup (${setup.customReason}), so its runs have no DevTune setup to upload under, and push can't save tools ${setup.from} doesn't have. Add them to a category copy in the DevTune app, run agentpicks pull, and run the pulled setup, or pass --no-upload to keep the bundles on this machine.`
|
|
80970
|
+
);
|
|
80971
|
+
if (setup.customReason)
|
|
80972
|
+
throw new UsageError(
|
|
80973
|
+
`${shown3} is a custom setup (${setup.customReason}), so its runs have no DevTune setup to upload under. Run agentpicks push ${setup.name} to save it to DevTune first, or pass --no-upload to keep the bundles on this machine.`
|
|
80974
|
+
);
|
|
80975
|
+
return plan;
|
|
80976
|
+
}
|
|
80977
|
+
const linked = await linkedSetup(setup.id, shown3, ctx);
|
|
80978
|
+
if (content?.synced && linked.snapshot_digest !== content.synced.setup)
|
|
80979
|
+
throw new UsageError(devtuneChangedMessage(shown3, setup.name));
|
|
80980
|
+
if (unpushed) throw new UsageError(unpushedMessage(shown3, setup.name));
|
|
80981
|
+
const slug2 = linked.category_slug;
|
|
80982
|
+
return {
|
|
80983
|
+
...plan,
|
|
80984
|
+
tests: plan.tests.map((test) => ({
|
|
80985
|
+
...test,
|
|
80986
|
+
category: { ...test.category, slug: slug2 }
|
|
80987
|
+
}))
|
|
80988
|
+
};
|
|
80989
|
+
}
|
|
80990
|
+
async function linkedBundle(bundle, ctx) {
|
|
80991
|
+
const id = bundle.setup?.id;
|
|
80992
|
+
if (!id) return null;
|
|
80993
|
+
const shown3 = `${bundle.dir} (a run of ${bundle.setup.name})`;
|
|
80994
|
+
if (bundle.setup.unpushed)
|
|
80995
|
+
throw new UsageError(
|
|
80996
|
+
`${shown3} ran with changes not pushed to its DevTune setup, so it can't file under it. Run agentpicks push ${bundle.setup.name}, then run the setup again.`
|
|
80997
|
+
);
|
|
80998
|
+
const slug2 = (await linkedSetup(id, shown3, ctx)).category_slug;
|
|
80999
|
+
return {
|
|
81000
|
+
...bundle,
|
|
81001
|
+
manifest: {
|
|
81002
|
+
...bundle.manifest,
|
|
81003
|
+
request: { ...bundle.manifest.request, category: slug2 }
|
|
81004
|
+
}
|
|
81005
|
+
};
|
|
81006
|
+
}
|
|
81007
|
+
|
|
81008
|
+
// src/cli/category-copy.ts
|
|
81009
|
+
async function categoryCopyPlan(args, ctx) {
|
|
81010
|
+
const slug2 = args.category;
|
|
81011
|
+
let setups = await refusable(
|
|
81012
|
+
`reading the project's setups`,
|
|
81013
|
+
() => readSetups(ctx, "upload")
|
|
81014
|
+
);
|
|
81015
|
+
let copy = projectCopy(setups, slug2, ctx);
|
|
81016
|
+
if (!copy) {
|
|
81017
|
+
const created = await createCopy(setups, args, ctx);
|
|
81018
|
+
setups = await refusable(
|
|
81019
|
+
`reading the project's setups`,
|
|
81020
|
+
() => readSetups(ctx, "upload")
|
|
81021
|
+
);
|
|
81022
|
+
copy = created?.id ? setups.list.setups.find((setup) => setup.id === created.id) : projectCopy(setups, slug2, ctx);
|
|
81023
|
+
if (!copy)
|
|
81024
|
+
throw new UsageError(
|
|
81025
|
+
`DevTune made no copy of ${slug2} that agentpicks can find. Run agentpicks list to see the project's setups, or pass --no-upload to keep the bundles on this machine.`
|
|
81026
|
+
);
|
|
81027
|
+
const name = setups.names.get(copy.id);
|
|
81028
|
+
ctx.out(
|
|
81029
|
+
created ? `Created the project's copy of ${slug2}, DevTune setup ${name}. Write it as a file with: agentpicks pull ${name}` : `Another save made the project's copy of ${slug2} meanwhile, DevTune setup ${name}.`
|
|
81030
|
+
);
|
|
81031
|
+
}
|
|
81032
|
+
const run = runSetupOf(setups, copy, setupsRoot(ctx.cwd));
|
|
81033
|
+
ctx.out(
|
|
81034
|
+
`Runs the project's setup of ${slug2}, DevTune setup ${setups.names.get(copy.id)}, and uploads under it.`
|
|
81035
|
+
);
|
|
81036
|
+
const { category: _category, ...flags } = args;
|
|
81037
|
+
return linkUploads(
|
|
81038
|
+
setupPlan(run, flags, ctx.cwd),
|
|
81039
|
+
run.setup,
|
|
81040
|
+
void 0,
|
|
81041
|
+
run.path,
|
|
81042
|
+
ctx
|
|
81043
|
+
);
|
|
81044
|
+
}
|
|
81045
|
+
function projectCopy(setups, slug2, ctx) {
|
|
81046
|
+
const copies2 = setups.list.setups.filter(
|
|
81047
|
+
(setup) => (setup.kind === "copy" || setup.kind === "category") && setup.source_category_slug === slug2
|
|
81048
|
+
);
|
|
81049
|
+
if (copies2.length < 2) return copies2[0];
|
|
81050
|
+
const copy = copies2.find((setup) => setups.names.get(setup.id) === slug2) ?? copies2[0];
|
|
81051
|
+
ctx.out(
|
|
81052
|
+
`The project has ${copies2.length} setups of ${slug2}: ${copies2.map((setup) => setups.names.get(setup.id)).join(", ")}. Running ${setups.names.get(copy.id)}.`
|
|
81053
|
+
);
|
|
81054
|
+
return copy;
|
|
81055
|
+
}
|
|
81056
|
+
async function createCopy(setups, args, ctx) {
|
|
81057
|
+
const slug2 = args.category;
|
|
81058
|
+
if (!setups.list.catalogue.categories.some((each) => each.slug === slug2))
|
|
81059
|
+
throw new UsageError(
|
|
81060
|
+
`DevTune hasn't published ${slug2}, so the project can't have a copy of it to upload under. Choose another category, or pass --no-upload to keep the bundles on this machine.`
|
|
81061
|
+
);
|
|
81062
|
+
const { kind } = chooseAgent(ctx.io, { agent: args.agent });
|
|
81063
|
+
const agent = SELF_RUN_AGENTS.find((each) => each.kind === kind).aliases[0];
|
|
81064
|
+
const request2 = pushRequest(
|
|
81065
|
+
{
|
|
81066
|
+
from: slug2,
|
|
81067
|
+
stacks: setups.list.catalogue.environments.map((env) => env.slug).filter(
|
|
81068
|
+
(stack) => nameableStack(stack, slug2) && isSelectedByDefault(stack)
|
|
81069
|
+
),
|
|
81070
|
+
agents: [agent]
|
|
81071
|
+
},
|
|
81072
|
+
null,
|
|
81073
|
+
setups.list,
|
|
81074
|
+
`The project's copy of ${slug2}`
|
|
81075
|
+
);
|
|
81076
|
+
try {
|
|
81077
|
+
const saved = await saveDevtuneSetup(
|
|
81078
|
+
setups.target,
|
|
81079
|
+
request2.route,
|
|
81080
|
+
request2.body
|
|
81081
|
+
);
|
|
81082
|
+
return { id: saved.setup?.id };
|
|
81083
|
+
} catch (error62) {
|
|
81084
|
+
if (error62 instanceof UploadError && (error62.reason === "category_in_use" || error62.reason === "setup_changed"))
|
|
81085
|
+
return null;
|
|
81086
|
+
throw refusal(`creating the project's copy of ${slug2}`, error62);
|
|
81087
|
+
}
|
|
81088
|
+
}
|
|
81089
|
+
async function refusable(step, call) {
|
|
81090
|
+
try {
|
|
81091
|
+
return await call();
|
|
81092
|
+
} catch (error62) {
|
|
81093
|
+
throw refusal(step, error62);
|
|
81094
|
+
}
|
|
81095
|
+
}
|
|
81096
|
+
function refusal(step, error62) {
|
|
81097
|
+
if (!(error62 instanceof UploadError) || error62.transient) return error62;
|
|
81098
|
+
return new UsageError(
|
|
81099
|
+
`A --category run uploads under the project's own copy of the category, and DevTune refused ${step}: ${error62.message.replace(/\.?$/, ".")}${fix(error62)} Or pass --no-upload to keep the bundles on this machine.`
|
|
81100
|
+
);
|
|
81101
|
+
}
|
|
81102
|
+
function fix(error62) {
|
|
81103
|
+
if (error62.reason === "agent_not_in_plan")
|
|
81104
|
+
return " Choose an agent the plan includes with --agent.";
|
|
81105
|
+
if (error62.message.startsWith("API key scope does not allow"))
|
|
81106
|
+
return " Use a project API key with that scope, or run agentpicks login.";
|
|
81107
|
+
if (error62.message.startsWith("Managing this project is required"))
|
|
81108
|
+
return " The signed-in member, or the API key's creator, needs DevTune management permission on the account and edit rights on the project.";
|
|
81109
|
+
if (error62.message.startsWith("Agent Picks is not available"))
|
|
81110
|
+
return " The account's plan doesn't include Agent Picks; choose a plan that does.";
|
|
81111
|
+
return "";
|
|
81112
|
+
}
|
|
81113
|
+
|
|
81114
|
+
// src/cli/credentials.ts
|
|
81115
|
+
var import_node_path11 = require("node:path");
|
|
81116
|
+
var RUN_WINDOW_MS = SANDBOX_LIFETIME_MIN * 6e4;
|
|
81117
|
+
var CLAUDE_KEYS = [
|
|
81118
|
+
"ANTHROPIC_AUTH_TOKEN",
|
|
81119
|
+
"ANTHROPIC_API_KEY",
|
|
81120
|
+
"CLAUDE_CODE_OAUTH_TOKEN"
|
|
81121
|
+
];
|
|
81122
|
+
var CODEX_KEYS = ["OPENAI_API_KEY", "CODEX_API_KEY"];
|
|
81123
|
+
function resolveCredentials(plan, io) {
|
|
81124
|
+
const { agent } = plan;
|
|
81125
|
+
if (agent.kind === "claude_code") return claudeCredentials(io);
|
|
81126
|
+
if (agent.kind === "codex") return codexCredentials(io);
|
|
81127
|
+
const key = plan.provider === "anthropic" ? "ANTHROPIC_API_KEY" : "OPENAI_API_KEY";
|
|
81128
|
+
const value = io.env[key];
|
|
81129
|
+
if (!value)
|
|
81130
|
+
throw new MissingCredentialsError(
|
|
81131
|
+
`${agent.name} runs here use ${key} from your environment, which isn't set. Set it and try again.`
|
|
81132
|
+
);
|
|
81133
|
+
return {
|
|
81134
|
+
env: { [key]: value },
|
|
81135
|
+
files: [],
|
|
81136
|
+
secrets: [value],
|
|
81137
|
+
summary: [passes([key], "your environment", agent.name)]
|
|
81138
|
+
};
|
|
81139
|
+
}
|
|
81140
|
+
function claudeCredentials(io) {
|
|
81141
|
+
const settingsPath = (0, import_node_path11.join)(claudeConfigDir(io), "settings.json");
|
|
81142
|
+
const settings = readJsonObject(io, settingsPath);
|
|
81143
|
+
const settingsEnv = settings?.env && typeof settings.env === "object" ? settings.env : null;
|
|
81144
|
+
const read = (key) => io.env[key] ? { key, value: io.env[key], source: "your environment" } : stringField(settingsEnv, key) ? { key, value: stringField(settingsEnv, key), source: settingsPath } : null;
|
|
81145
|
+
const keys = CLAUDE_KEYS.map(read).filter((k) => k !== null);
|
|
81146
|
+
if (keys.length > 0) {
|
|
81147
|
+
const baseUrl = read("ANTHROPIC_BASE_URL");
|
|
81148
|
+
const passed = baseUrl ? [...keys, baseUrl] : keys;
|
|
81149
|
+
return {
|
|
81150
|
+
env: Object.fromEntries(passed.map((k) => [k.key, k.value])),
|
|
81151
|
+
files: [],
|
|
81152
|
+
secrets: keys.map((k) => k.value),
|
|
81153
|
+
summary: [...new Set(passed.map((k) => k.source))].map(
|
|
81154
|
+
(source) => passes(
|
|
81155
|
+
passed.filter((k) => k.source === source).map((k) => k.key),
|
|
81156
|
+
source,
|
|
81157
|
+
"Claude Code"
|
|
81158
|
+
)
|
|
81159
|
+
)
|
|
81160
|
+
};
|
|
81161
|
+
}
|
|
81162
|
+
const path = (0, import_node_path11.join)(claudeConfigDir(io), ".credentials.json");
|
|
81163
|
+
const oauth = readJsonObject(io, path)?.claudeAiOauth;
|
|
81164
|
+
const login = oauth && typeof oauth === "object" ? oauth : null;
|
|
81165
|
+
const accessToken = stringField(login, "accessToken");
|
|
81166
|
+
if (login && accessToken) {
|
|
81167
|
+
const expiresAt = typeof login.expiresAt === "number" && login.expiresAt > 0 ? login.expiresAt : null;
|
|
81168
|
+
if (expiresAt !== null && expiresAt < io.now() + RUN_WINDOW_MS)
|
|
81169
|
+
throw new LoginExpiringError(
|
|
81170
|
+
`Claude Code's sign-in on this machine ${expiresIn(expiresAt, io)}, before a run could finish. Run \`claude\` here so it renews, then try again, or set CLAUDE_CODE_OAUTH_TOKEN from \`claude setup-token\`.`
|
|
81171
|
+
);
|
|
81172
|
+
const copy = Object.fromEntries(
|
|
81173
|
+
Object.entries(login).filter(([key]) => key !== "refreshToken")
|
|
81174
|
+
);
|
|
81175
|
+
return {
|
|
81176
|
+
env: {},
|
|
81177
|
+
files: [
|
|
81178
|
+
{
|
|
81179
|
+
source: path,
|
|
81180
|
+
path: "/root/.claude/.credentials.json",
|
|
81181
|
+
content: JSON.stringify({ claudeAiOauth: copy })
|
|
81182
|
+
}
|
|
81183
|
+
],
|
|
81184
|
+
secrets: [accessToken],
|
|
81185
|
+
summary: [copies("Claude Code", path, "/root/.claude/.credentials.json")]
|
|
81186
|
+
};
|
|
81187
|
+
}
|
|
81188
|
+
if (io.platform === "darwin")
|
|
81189
|
+
throw new KeychainLoginError(
|
|
81190
|
+
"Claude Code on macOS keeps its sign-in in the Keychain, which agentpicks doesn't read. Run `claude setup-token`, set CLAUDE_CODE_OAUTH_TOKEN to the token it prints, and try again. An ANTHROPIC_API_KEY works too."
|
|
81191
|
+
);
|
|
81192
|
+
throw new MissingCredentialsError(
|
|
81193
|
+
"Claude Code has no sign-in on this machine. Run `claude` and log in, or set ANTHROPIC_API_KEY or CLAUDE_CODE_OAUTH_TOKEN (from `claude setup-token`)."
|
|
81194
|
+
);
|
|
81195
|
+
}
|
|
81196
|
+
function codexCredentials(io) {
|
|
81197
|
+
const keys = CODEX_KEYS.filter((key) => io.env[key]);
|
|
81198
|
+
if (keys.length > 0)
|
|
81199
|
+
return {
|
|
81200
|
+
env: Object.fromEntries(keys.map((key) => [key, io.env[key]])),
|
|
81201
|
+
files: [],
|
|
81202
|
+
secrets: keys.map((key) => io.env[key]),
|
|
81203
|
+
summary: [passes(keys, "your environment", "Codex")]
|
|
81204
|
+
};
|
|
81205
|
+
const home = codexHome(io);
|
|
81206
|
+
const store = topLevelTomlString(
|
|
81207
|
+
io.readFile((0, import_node_path11.join)(home, "config.toml")),
|
|
81208
|
+
"cli_auth_credentials_store"
|
|
81209
|
+
);
|
|
81210
|
+
const keyring = new KeychainLoginError(
|
|
81211
|
+
`Codex keeps its sign-in in the system keyring (cli_auth_credentials_store = "${store}" in ${(0, import_node_path11.join)(home, "config.toml")}), which agentpicks doesn't read. Set OPENAI_API_KEY, or set cli_auth_credentials_store = "file", run \`codex login\` and try again.`
|
|
81212
|
+
);
|
|
81213
|
+
if (store === "keyring") throw keyring;
|
|
81214
|
+
const path = (0, import_node_path11.join)(home, "auth.json");
|
|
81215
|
+
const auth = readJsonObject(io, path);
|
|
81216
|
+
const tokens2 = auth?.tokens && typeof auth.tokens === "object" ? auth.tokens : null;
|
|
81217
|
+
const accessToken = stringField(tokens2, "access_token");
|
|
81218
|
+
const apiKey = stringField(auth, "OPENAI_API_KEY");
|
|
81219
|
+
if (auth && (accessToken || apiKey)) {
|
|
81220
|
+
const expiresAt = accessToken ? jwtExpiry(accessToken) : null;
|
|
81221
|
+
if (expiresAt !== null && expiresAt < io.now() + RUN_WINDOW_MS)
|
|
81222
|
+
throw new LoginExpiringError(
|
|
81223
|
+
`Codex's sign-in on this machine ${expiresIn(expiresAt, io)}, before a run could finish. Run \`codex\` here so it renews, then try again, or set OPENAI_API_KEY.`
|
|
81224
|
+
);
|
|
81225
|
+
const copy = tokens2 ? {
|
|
81226
|
+
...auth,
|
|
81227
|
+
tokens: { ...tokens2, refresh_token: "" },
|
|
81228
|
+
last_refresh: new Date(io.now()).toISOString()
|
|
81229
|
+
} : auth;
|
|
81230
|
+
return {
|
|
81231
|
+
env: {},
|
|
81232
|
+
files: [
|
|
81233
|
+
{
|
|
81234
|
+
source: path,
|
|
81235
|
+
path: "/root/.codex/auth.json",
|
|
81236
|
+
content: JSON.stringify(copy)
|
|
81237
|
+
}
|
|
81238
|
+
],
|
|
81239
|
+
secrets: [
|
|
81240
|
+
accessToken,
|
|
81241
|
+
stringField(tokens2, "id_token"),
|
|
81242
|
+
stringField(tokens2, "refresh_token"),
|
|
81243
|
+
apiKey
|
|
81244
|
+
].filter((v) => Boolean(v)),
|
|
81245
|
+
summary: [copies("Codex", path, "/root/.codex/auth.json")]
|
|
81246
|
+
};
|
|
81247
|
+
}
|
|
81248
|
+
if (store === "auto") throw keyring;
|
|
81249
|
+
throw new MissingCredentialsError(
|
|
81250
|
+
"Codex has no sign-in on this machine. Run `codex login`, or set OPENAI_API_KEY."
|
|
81251
|
+
);
|
|
81252
|
+
}
|
|
81253
|
+
function jwtExpiry(token) {
|
|
81254
|
+
try {
|
|
81255
|
+
const payload = JSON.parse(
|
|
81256
|
+
Buffer.from(token.split(".")[1] ?? "", "base64url").toString("utf8")
|
|
81257
|
+
);
|
|
81258
|
+
const exp = payload && typeof payload === "object" ? payload.exp : void 0;
|
|
81259
|
+
return typeof exp === "number" ? exp * 1e3 : null;
|
|
81260
|
+
} catch {
|
|
81261
|
+
return null;
|
|
81262
|
+
}
|
|
81263
|
+
}
|
|
81264
|
+
function expiresIn(at, io) {
|
|
81265
|
+
const minutes = Math.round((at - io.now()) / 6e4);
|
|
81266
|
+
return minutes <= 0 ? "has expired" : `expires in ${minutes} min`;
|
|
81267
|
+
}
|
|
81268
|
+
function passes(keys, source, agent) {
|
|
81269
|
+
return `Passes ${keys.join(", ")} from ${source} to ${agent}, for each run only.`;
|
|
81270
|
+
}
|
|
81271
|
+
function copies(agent, source, target) {
|
|
81272
|
+
return `Copies ${agent}'s sign-in from ${source} into each run's container as ${target}, without its refresh token. It is deleted with the container.`;
|
|
81273
|
+
}
|
|
81274
|
+
|
|
80559
81275
|
// src/cli/image.ts
|
|
80560
81276
|
var import_node_child_process5 = require("node:child_process");
|
|
80561
81277
|
var SANDBOX_IMAGE_REPOSITORY = "agentpicks-sandbox";
|
|
@@ -80686,15 +81402,15 @@ function dockerBuild(args) {
|
|
|
80686
81402
|
}
|
|
80687
81403
|
|
|
80688
81404
|
// src/cli/init.ts
|
|
80689
|
-
var
|
|
80690
|
-
var
|
|
81405
|
+
var import_node_fs8 = require("node:fs");
|
|
81406
|
+
var import_node_path13 = require("node:path");
|
|
80691
81407
|
var import_node_util2 = require("node:util");
|
|
80692
|
-
var
|
|
81408
|
+
var import_yaml5 = __toESM(require_dist());
|
|
80693
81409
|
|
|
80694
81410
|
// src/cli/init-detect.ts
|
|
80695
|
-
var
|
|
80696
|
-
var
|
|
80697
|
-
var
|
|
81411
|
+
var import_node_fs7 = require("node:fs");
|
|
81412
|
+
var import_node_path12 = require("node:path");
|
|
81413
|
+
var import_yaml4 = __toESM(require_dist());
|
|
80698
81414
|
var STACK_PACKAGES = [
|
|
80699
81415
|
{ stack: "nextjs", npm: ["next"] },
|
|
80700
81416
|
{
|
|
@@ -80715,7 +81431,7 @@ function detectStacks(root) {
|
|
|
80715
81431
|
}
|
|
80716
81432
|
function detectRepository(cwd, io) {
|
|
80717
81433
|
const root = setupsRoot(cwd);
|
|
80718
|
-
const manifest = readJson2((0,
|
|
81434
|
+
const manifest = readJson2((0, import_node_path12.join)(root, "package.json"));
|
|
80719
81435
|
const fullName = typeof manifest?.name === "string" ? manifest.name.toLowerCase() : null;
|
|
80720
81436
|
const git = gitRoot(cwd) !== null;
|
|
80721
81437
|
return {
|
|
@@ -80741,8 +81457,8 @@ function readPackages(root) {
|
|
|
80741
81457
|
const value = manifest?.[field];
|
|
80742
81458
|
return value && typeof value === "object" ? Object.keys(value) : [];
|
|
80743
81459
|
});
|
|
80744
|
-
add(npm, dependencies(readJson2((0,
|
|
80745
|
-
const pnpm = readText((0,
|
|
81460
|
+
add(npm, dependencies(readJson2((0, import_node_path12.join)(root, "package.json"))), "package.json");
|
|
81461
|
+
const pnpm = readText((0, import_node_path12.join)(root, "pnpm-lock.yaml"));
|
|
80746
81462
|
if (pnpm !== null) {
|
|
80747
81463
|
const lock = safeYaml(pnpm);
|
|
80748
81464
|
const importers = lock?.importers && typeof lock.importers === "object" ? Object.values(lock.importers) : [];
|
|
@@ -80755,7 +81471,7 @@ function readPackages(root) {
|
|
|
80755
81471
|
"pnpm-lock.yaml"
|
|
80756
81472
|
);
|
|
80757
81473
|
}
|
|
80758
|
-
const npmLock = readJson2((0,
|
|
81474
|
+
const npmLock = readJson2((0, import_node_path12.join)(root, "package-lock.json"));
|
|
80759
81475
|
if (npmLock?.packages && typeof npmLock.packages === "object") {
|
|
80760
81476
|
for (const [path, entry] of Object.entries(
|
|
80761
81477
|
npmLock.packages
|
|
@@ -80768,11 +81484,11 @@ function readPackages(root) {
|
|
|
80768
81484
|
);
|
|
80769
81485
|
}
|
|
80770
81486
|
for (const file2 of ["requirements.txt", "pyproject.toml", "uv.lock"]) {
|
|
80771
|
-
const text3 = readText((0,
|
|
81487
|
+
const text3 = readText((0, import_node_path12.join)(root, file2));
|
|
80772
81488
|
if (text3 !== null && /(^|["'])fastapi(?=\s*($|["'<>=!~;[,@]))/im.test(text3))
|
|
80773
81489
|
add(pypi, ["fastapi"], file2);
|
|
80774
81490
|
}
|
|
80775
|
-
const gemfile = readText((0,
|
|
81491
|
+
const gemfile = readText((0, import_node_path12.join)(root, "Gemfile.lock"));
|
|
80776
81492
|
if (gemfile !== null && /^ {4}rails \(/m.test(gemfile))
|
|
80777
81493
|
add(gem, ["rails"], "Gemfile.lock");
|
|
80778
81494
|
return { npm, pypi, gem, sources };
|
|
@@ -80813,7 +81529,7 @@ function signedInAgents(io) {
|
|
|
80813
81529
|
try {
|
|
80814
81530
|
resolveCredentials(planAgent(agent), io);
|
|
80815
81531
|
} catch (error62) {
|
|
80816
|
-
if (CREDENTIAL_REFUSALS.some((
|
|
81532
|
+
if (CREDENTIAL_REFUSALS.some((refusal2) => error62 instanceof refusal2))
|
|
80817
81533
|
return [];
|
|
80818
81534
|
throw error62;
|
|
80819
81535
|
}
|
|
@@ -80823,7 +81539,7 @@ function signedInAgents(io) {
|
|
|
80823
81539
|
}
|
|
80824
81540
|
function readText(path) {
|
|
80825
81541
|
try {
|
|
80826
|
-
return (0,
|
|
81542
|
+
return (0, import_node_fs7.readFileSync)(path, "utf8");
|
|
80827
81543
|
} catch {
|
|
80828
81544
|
return null;
|
|
80829
81545
|
}
|
|
@@ -80840,7 +81556,7 @@ function readJson2(path) {
|
|
|
80840
81556
|
}
|
|
80841
81557
|
function safeYaml(text3) {
|
|
80842
81558
|
try {
|
|
80843
|
-
const value = (0,
|
|
81559
|
+
const value = (0, import_yaml4.parse)(text3);
|
|
80844
81560
|
return value && typeof value === "object" ? value : null;
|
|
80845
81561
|
} catch {
|
|
80846
81562
|
return null;
|
|
@@ -80955,45 +81671,6 @@ function setupSignals(drafted) {
|
|
|
80955
81671
|
return Object.keys(packages).length > 0 || signals.configNames ? parsed2.data : null;
|
|
80956
81672
|
}
|
|
80957
81673
|
|
|
80958
|
-
// src/cli/setup-write.ts
|
|
80959
|
-
var import_node_crypto7 = require("node:crypto");
|
|
80960
|
-
var import_node_fs6 = require("node:fs");
|
|
80961
|
-
var import_node_path11 = require("node:path");
|
|
80962
|
-
function isSymlink(path) {
|
|
80963
|
-
try {
|
|
80964
|
-
return (0, import_node_fs6.lstatSync)(path).isSymbolicLink();
|
|
80965
|
-
} catch (error62) {
|
|
80966
|
-
if (error62.code === "ENOENT") return false;
|
|
80967
|
-
throw error62;
|
|
80968
|
-
}
|
|
80969
|
-
}
|
|
80970
|
-
function writeSetupText(dir, path, text3, options) {
|
|
80971
|
-
for (const target of [dir, path])
|
|
80972
|
-
if (isSymlink(target))
|
|
80973
|
-
throw new UsageError(
|
|
80974
|
-
`${options.shown(target)} is a symbolic link, and agentpicks writes setup files only to a real file in a real directory. Remove the link and run the command again.`
|
|
80975
|
-
);
|
|
80976
|
-
(0, import_node_fs6.mkdirSync)(dir, { recursive: true });
|
|
80977
|
-
const temporary = (0, import_node_path11.join)(dir, `.agentpicks-${(0, import_node_crypto7.randomUUID)()}.tmp`);
|
|
80978
|
-
try {
|
|
80979
|
-
(0, import_node_fs6.writeFileSync)(temporary, text3, { flag: "wx" });
|
|
80980
|
-
if (options.replace) (0, import_node_fs6.renameSync)(temporary, path);
|
|
80981
|
-
else linkOrCopy(temporary, path);
|
|
80982
|
-
} finally {
|
|
80983
|
-
if ((0, import_node_fs6.existsSync)(temporary)) (0, import_node_fs6.unlinkSync)(temporary);
|
|
80984
|
-
}
|
|
80985
|
-
}
|
|
80986
|
-
function linkOrCopy(temporary, path) {
|
|
80987
|
-
try {
|
|
80988
|
-
(0, import_node_fs6.linkSync)(temporary, path);
|
|
80989
|
-
} catch (error62) {
|
|
80990
|
-
const code = error62.code;
|
|
80991
|
-
if (code !== "EPERM" && code !== "ENOTSUP" && code !== "ENOSYS")
|
|
80992
|
-
throw error62;
|
|
80993
|
-
(0, import_node_fs6.copyFileSync)(temporary, path, import_node_fs6.constants.COPYFILE_EXCL);
|
|
80994
|
-
}
|
|
80995
|
-
}
|
|
80996
|
-
|
|
80997
81674
|
// src/cli/init.ts
|
|
80998
81675
|
async function initCommand(argv, ctx) {
|
|
80999
81676
|
const { yes, force } = parseInitArgs(argv);
|
|
@@ -81026,8 +81703,8 @@ async function initCommand(argv, ctx) {
|
|
|
81026
81703
|
read: (answer) => /^[1-9]\d*$/.test(answer) && Number(answer) <= 100 ? { value: Number(answer) } : { problem: "Give a whole number of runs, 1 to 100." }
|
|
81027
81704
|
});
|
|
81028
81705
|
if (runs !== 1) file2.runs = runs;
|
|
81029
|
-
const dir = (0,
|
|
81030
|
-
const text3 = (0,
|
|
81706
|
+
const dir = (0, import_node_path13.join)(wizard.detected.root, SETUPS_DIR);
|
|
81707
|
+
const text3 = (0, import_yaml5.stringify)(file2);
|
|
81031
81708
|
const name = await ask(wizard, {
|
|
81032
81709
|
label: "Name",
|
|
81033
81710
|
fallback: file2.from ?? slug(file2.job),
|
|
@@ -81037,9 +81714,9 @@ async function initCommand(argv, ctx) {
|
|
|
81037
81714
|
problem: "A name is lowercase letters, digits and hyphens, such as error-tracking."
|
|
81038
81715
|
};
|
|
81039
81716
|
const path2 = setupPath(dir, answer);
|
|
81040
|
-
if ((0,
|
|
81717
|
+
if ((0, import_node_fs8.existsSync)(path2) && !force)
|
|
81041
81718
|
return {
|
|
81042
|
-
problem: `${(0,
|
|
81719
|
+
problem: `${(0, import_node_path13.relative)(ctx.cwd, path2)} exists. Choose another name, or pass --force to replace it.`
|
|
81043
81720
|
};
|
|
81044
81721
|
const checked = checkSetupText(path2, text3);
|
|
81045
81722
|
return checked.problems.length > 0 ? {
|
|
@@ -81049,7 +81726,7 @@ async function initCommand(argv, ctx) {
|
|
|
81049
81726
|
});
|
|
81050
81727
|
const path = setupPath(dir, name);
|
|
81051
81728
|
writeSetup(dir, path, text3, force, ctx.cwd);
|
|
81052
|
-
const shown3 = (0,
|
|
81729
|
+
const shown3 = (0, import_node_path13.relative)(ctx.cwd, path) || path;
|
|
81053
81730
|
ctx.out("");
|
|
81054
81731
|
ctx.out(`Wrote ${shown3}:`);
|
|
81055
81732
|
ctx.out("");
|
|
@@ -81184,8 +81861,8 @@ async function askCustomJob(wizard, line2) {
|
|
|
81184
81861
|
...competitors.length > 0 ? { competitors } : {}
|
|
81185
81862
|
};
|
|
81186
81863
|
const checked = checkSetupText(
|
|
81187
|
-
(0,
|
|
81188
|
-
(0,
|
|
81864
|
+
(0, import_node_path13.join)(wizard.detected.root, SETUPS_DIR, "init.yaml"),
|
|
81865
|
+
(0, import_yaml5.stringify)(file2)
|
|
81189
81866
|
);
|
|
81190
81867
|
if (checked.problems.length === 0) return file2;
|
|
81191
81868
|
for (const problem of checked.problems)
|
|
@@ -81338,18 +82015,18 @@ function slug(text3) {
|
|
|
81338
82015
|
return text3.normalize("NFKD").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 63).replace(/-+$/, "") || "setup";
|
|
81339
82016
|
}
|
|
81340
82017
|
function setupPath(dir, name) {
|
|
81341
|
-
return [".yaml", ".yml"].map((ext) => (0,
|
|
82018
|
+
return [".yaml", ".yml"].map((ext) => (0, import_node_path13.join)(dir, `${name}${ext}`)).find(import_node_fs8.existsSync) ?? (0, import_node_path13.join)(dir, `${name}.yaml`);
|
|
81342
82019
|
}
|
|
81343
82020
|
function writeSetup(dir, path, text3, force, cwd) {
|
|
81344
82021
|
try {
|
|
81345
82022
|
writeSetupText(dir, path, text3, {
|
|
81346
82023
|
replace: force,
|
|
81347
|
-
shown: (target) => (0,
|
|
82024
|
+
shown: (target) => (0, import_node_path13.relative)(cwd, target) || target
|
|
81348
82025
|
});
|
|
81349
82026
|
} catch (error62) {
|
|
81350
82027
|
if (error62.code === "EEXIST")
|
|
81351
82028
|
throw new UsageError(
|
|
81352
|
-
`${(0,
|
|
82029
|
+
`${(0, import_node_path13.relative)(cwd, path)} appeared while init ran. Run init again with another name, or pass --force to replace it.`
|
|
81353
82030
|
);
|
|
81354
82031
|
throw error62;
|
|
81355
82032
|
}
|
|
@@ -81357,343 +82034,6 @@ function writeSetup(dir, path, text3, force, cwd) {
|
|
|
81357
82034
|
|
|
81358
82035
|
// src/cli/list-command.ts
|
|
81359
82036
|
var import_node_path14 = require("node:path");
|
|
81360
|
-
|
|
81361
|
-
// src/setup/link.ts
|
|
81362
|
-
var import_node_crypto8 = require("node:crypto");
|
|
81363
|
-
var import_yaml4 = __toESM(require_dist());
|
|
81364
|
-
var LOCAL_ONLY = ["id", "synced", "repo", "runs"];
|
|
81365
|
-
function canonical(value) {
|
|
81366
|
-
if (Array.isArray(value)) return `[${value.map(canonical).join(",")}]`;
|
|
81367
|
-
if (value && typeof value === "object")
|
|
81368
|
-
return `{${Object.keys(value).filter((key) => value[key] !== void 0).sort().map(
|
|
81369
|
-
(key) => `${JSON.stringify(key)}:${canonical(value[key])}`
|
|
81370
|
-
).join(",")}}`;
|
|
81371
|
-
return JSON.stringify(value);
|
|
81372
|
-
}
|
|
81373
|
-
function fileDigest(file2) {
|
|
81374
|
-
const content = { ...file2 };
|
|
81375
|
-
for (const key of LOCAL_ONLY) delete content[key];
|
|
81376
|
-
return (0, import_node_crypto8.createHash)("sha256").update(canonical(content)).digest("hex");
|
|
81377
|
-
}
|
|
81378
|
-
function syncState(file2, setup) {
|
|
81379
|
-
if (!setup) return "orphaned";
|
|
81380
|
-
if (!file2.synced) return "both_changed";
|
|
81381
|
-
const local = fileDigest(file2) !== file2.synced.file;
|
|
81382
|
-
const devtune = setup.snapshot_digest !== file2.synced.setup;
|
|
81383
|
-
if (local && devtune) return "both_changed";
|
|
81384
|
-
if (local) return "local_changed";
|
|
81385
|
-
if (devtune) return "devtune_changed";
|
|
81386
|
-
return "in_sync";
|
|
81387
|
-
}
|
|
81388
|
-
var SYNC_STATE_LABELS = {
|
|
81389
|
-
in_sync: "in sync",
|
|
81390
|
-
local_changed: "local changed",
|
|
81391
|
-
devtune_changed: "DevTune changed",
|
|
81392
|
-
both_changed: "both changed",
|
|
81393
|
-
orphaned: "not in DevTune"
|
|
81394
|
-
};
|
|
81395
|
-
var AGENT_KINDS2 = new Map(
|
|
81396
|
-
SELF_RUN_AGENTS.map((agent) => [agent.aliases[0], agent.kind])
|
|
81397
|
-
);
|
|
81398
|
-
var devtuneAgent = (name) => AGENT_KINDS2.get(name) ?? name;
|
|
81399
|
-
var fileAgent = (kind) => SETUP_AGENTS.find((name) => AGENT_KINDS2.get(name) === kind);
|
|
81400
|
-
function nameableStack(slug2, runsIn) {
|
|
81401
|
-
return ENVIRONMENTS.some((env) => env.slug === slug2) && !isRetiredEnvironment(slug2) && environmentRunsIn(slug2, runsIn);
|
|
81402
|
-
}
|
|
81403
|
-
function slugName(text3) {
|
|
81404
|
-
return text3.normalize("NFKD").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60).replace(/-+$/, "") || "setup";
|
|
81405
|
-
}
|
|
81406
|
-
function devtuneSetupNames(setups) {
|
|
81407
|
-
const names2 = /* @__PURE__ */ new Map();
|
|
81408
|
-
const taken = /* @__PURE__ */ new Set();
|
|
81409
|
-
for (const setup of setups) {
|
|
81410
|
-
const file2 = devtuneSetupFile(setup);
|
|
81411
|
-
const unedited = "file" in file2 && file2.file.from !== void 0 && !file2.file.requests && !hasEntries(file2.file);
|
|
81412
|
-
let base = unedited && setup.source_category_slug ? setup.source_category_slug : slugName(setup.name);
|
|
81413
|
-
if (!unedited && findCategoryRequests(base)) base = `${base}-setup`;
|
|
81414
|
-
let name = base;
|
|
81415
|
-
for (let n = 2; taken.has(name); n++) name = `${base}-${n}`;
|
|
81416
|
-
taken.add(name);
|
|
81417
|
-
names2.set(setup.id, name);
|
|
81418
|
-
}
|
|
81419
|
-
return names2;
|
|
81420
|
-
}
|
|
81421
|
-
function hasEntries(file2) {
|
|
81422
|
-
return [file2.tools?.own, ...file2.tools?.competitors ?? []].some(
|
|
81423
|
-
(ref) => ref !== void 0 && typeof ref !== "string"
|
|
81424
|
-
);
|
|
81425
|
-
}
|
|
81426
|
-
function fileSignals(signals) {
|
|
81427
|
-
const { dismissedYieldsTo: _dismissed, packages, ...rest } = signals;
|
|
81428
|
-
const kept = {};
|
|
81429
|
-
for (const [key, value] of Object.entries(rest))
|
|
81430
|
-
if (!(Array.isArray(value) && value.length === 0) && value !== void 0)
|
|
81431
|
-
kept[key] = value;
|
|
81432
|
-
const named = Object.fromEntries(
|
|
81433
|
-
Object.entries(packages ?? {}).filter(
|
|
81434
|
-
([, list]) => Array.isArray(list) && list.length > 0
|
|
81435
|
-
)
|
|
81436
|
-
);
|
|
81437
|
-
if (Object.keys(named).length) kept.packages = named;
|
|
81438
|
-
return kept;
|
|
81439
|
-
}
|
|
81440
|
-
function fileTool(row) {
|
|
81441
|
-
return {
|
|
81442
|
-
key: row.tool_key,
|
|
81443
|
-
name: row.display_name,
|
|
81444
|
-
...row.brand_domain ? { domain: row.brand_domain } : {},
|
|
81445
|
-
signals: fileSignals(row.signals)
|
|
81446
|
-
};
|
|
81447
|
-
}
|
|
81448
|
-
function catalogueToolProblem(key) {
|
|
81449
|
-
return `It measures ${key}, a tool from DevTune's catalogue, whose signals DevTune doesn't send, so a setup file can't hold it. Change the setup in the DevTune app.`;
|
|
81450
|
-
}
|
|
81451
|
-
function devtuneSetupFile(setup, keep = {}) {
|
|
81452
|
-
const from = setup.kind === "job" ? null : findCategoryRequests(setup.source_category_slug ?? "");
|
|
81453
|
-
if (setup.kind !== "job" && !from)
|
|
81454
|
-
return {
|
|
81455
|
-
problem: `It is a setup of the category ${setup.source_category_slug}, which this version of agentpicks doesn't have. Update agentpicks, then try again.`
|
|
81456
|
-
};
|
|
81457
|
-
const withheld = from ? void 0 : setup.tools.find((row) => row.signals === null);
|
|
81458
|
-
if (withheld) return { problem: catalogueToolProblem(withheld.tool_key) };
|
|
81459
|
-
const catalogueKeys = from ? CATEGORY_TOOLS[from.slug] ?? [] : [];
|
|
81460
|
-
const tool = (key) => {
|
|
81461
|
-
if (catalogueKeys.includes(key)) return key;
|
|
81462
|
-
const row = setup.tools.find((each) => each.tool_key === key);
|
|
81463
|
-
if (!row?.signals) return key;
|
|
81464
|
-
return fileTool({ ...row, signals: row.signals });
|
|
81465
|
-
};
|
|
81466
|
-
const requests = Object.fromEntries(
|
|
81467
|
-
PROMPT_INTENTS.flatMap((intent) => {
|
|
81468
|
-
const text3 = setup.requests[intent];
|
|
81469
|
-
if (!from) return !text3 || intent === "improve" ? [] : [[intent, text3]];
|
|
81470
|
-
const published = from.prompts.find((p) => p.intent === intent)?.text;
|
|
81471
|
-
if (!text3) return published ? [[intent, null]] : [];
|
|
81472
|
-
return text3 === published ? [] : [[intent, text3]];
|
|
81473
|
-
})
|
|
81474
|
-
);
|
|
81475
|
-
const own2 = setup.own_tool_key ? tool(setup.own_tool_key) : void 0;
|
|
81476
|
-
const competitors = setup.competitor_tool_keys.map(tool);
|
|
81477
|
-
const stacks = setup.environments.map((env) => env.slug).filter((slug2) => nameableStack(slug2, from?.slug ?? "job-"));
|
|
81478
|
-
const agents = [
|
|
81479
|
-
...new Set(
|
|
81480
|
-
setup.agent_models.flatMap((entry) => fileAgent(entry.agent) ?? [])
|
|
81481
|
-
)
|
|
81482
|
-
];
|
|
81483
|
-
const parsed2 = setupFileSchema.safeParse({
|
|
81484
|
-
...from ? { from: from.slug } : { job: setup.name },
|
|
81485
|
-
...Object.keys(requests).length ? { requests } : {},
|
|
81486
|
-
...own2 !== void 0 || competitors.length ? {
|
|
81487
|
-
tools: {
|
|
81488
|
-
...own2 !== void 0 ? { own: own2 } : {},
|
|
81489
|
-
...competitors.length ? { competitors } : {}
|
|
81490
|
-
}
|
|
81491
|
-
} : {},
|
|
81492
|
-
...keep.repo !== void 0 ? { repo: keep.repo } : stacks.length ? { stacks } : {},
|
|
81493
|
-
...agents.length ? { agents } : {},
|
|
81494
|
-
...keep.runs !== void 0 ? { runs: keep.runs } : {}
|
|
81495
|
-
});
|
|
81496
|
-
if (!parsed2.success) {
|
|
81497
|
-
const [issue2] = parsed2.error.issues;
|
|
81498
|
-
return {
|
|
81499
|
-
problem: `DevTune holds ${issue2.path.join(".") || "a field"} in a form a setup file can't: ${issue2.message} Change it in DevTune, then pull again.`
|
|
81500
|
-
};
|
|
81501
|
-
}
|
|
81502
|
-
return { file: parsed2.data };
|
|
81503
|
-
}
|
|
81504
|
-
function devtuneSetupProblems(name, file2) {
|
|
81505
|
-
const resolved = resolveSetup(name, file2);
|
|
81506
|
-
return "setup" in resolved ? [] : resolved.problems;
|
|
81507
|
-
}
|
|
81508
|
-
function linkedSetupYaml(file2, link) {
|
|
81509
|
-
const { id: _id, synced: _synced, ...content } = file2;
|
|
81510
|
-
const linked = {
|
|
81511
|
-
id: link.id,
|
|
81512
|
-
synced: { setup: link.setupDigest, file: fileDigest(content) },
|
|
81513
|
-
...content
|
|
81514
|
-
};
|
|
81515
|
-
return (0, import_yaml4.stringify)(linked, { lineWidth: 0 });
|
|
81516
|
-
}
|
|
81517
|
-
|
|
81518
|
-
// src/cli/setup-links.ts
|
|
81519
|
-
var import_node_fs8 = require("node:fs");
|
|
81520
|
-
var import_node_path13 = require("node:path");
|
|
81521
|
-
var import_yaml5 = __toESM(require_dist());
|
|
81522
|
-
|
|
81523
|
-
// src/cli/devtune-setups.ts
|
|
81524
|
-
var idSlug = external_exports.object({ id: external_exports.string(), slug: external_exports.string() });
|
|
81525
|
-
var devtuneSetupSchema = external_exports.object({
|
|
81526
|
-
id: external_exports.string(),
|
|
81527
|
-
category_slug: external_exports.string(),
|
|
81528
|
-
name: external_exports.string(),
|
|
81529
|
-
kind: external_exports.enum(["job", "copy", "category"]),
|
|
81530
|
-
source_category_slug: external_exports.string().nullable(),
|
|
81531
|
-
snapshot_digest: external_exports.string(),
|
|
81532
|
-
requests: external_exports.record(external_exports.string(), external_exports.string().nullable()),
|
|
81533
|
-
tools: external_exports.array(
|
|
81534
|
-
external_exports.object({
|
|
81535
|
-
tool_key: external_exports.string(),
|
|
81536
|
-
display_name: external_exports.string(),
|
|
81537
|
-
brand_domain: external_exports.string().nullable(),
|
|
81538
|
-
signals: external_exports.record(external_exports.string(), external_exports.unknown()).nullable()
|
|
81539
|
-
})
|
|
81540
|
-
),
|
|
81541
|
-
own_tool_key: external_exports.string().nullable(),
|
|
81542
|
-
competitor_tool_keys: external_exports.array(external_exports.string()),
|
|
81543
|
-
environments: external_exports.array(idSlug),
|
|
81544
|
-
agent_models: external_exports.array(external_exports.object({ agent: external_exports.string(), model: external_exports.string() })),
|
|
81545
|
-
building_blocks: external_exports.record(external_exports.string(), external_exports.unknown()).nullable()
|
|
81546
|
-
});
|
|
81547
|
-
var setupListSchema = external_exports.object({
|
|
81548
|
-
setups: external_exports.array(devtuneSetupSchema),
|
|
81549
|
-
catalogue: external_exports.object({
|
|
81550
|
-
categories: external_exports.array(idSlug),
|
|
81551
|
-
environments: external_exports.array(idSlug),
|
|
81552
|
-
agents: external_exports.array(
|
|
81553
|
-
external_exports.object({
|
|
81554
|
-
agent: external_exports.string(),
|
|
81555
|
-
models: external_exports.array(external_exports.string()),
|
|
81556
|
-
included_in_plan: external_exports.boolean()
|
|
81557
|
-
})
|
|
81558
|
-
)
|
|
81559
|
-
})
|
|
81560
|
-
});
|
|
81561
|
-
var savedSchema = external_exports.object({
|
|
81562
|
-
setup: external_exports.object({ id: external_exports.string(), category_slug: external_exports.string() }).nullable(),
|
|
81563
|
-
snapshot_digest: external_exports.string()
|
|
81564
|
-
});
|
|
81565
|
-
var setupUrl = (target, path) => `${target.baseUrl}/projects/${target.projectId}/agent-picks/${path}`;
|
|
81566
|
-
function readDevtuneSetups(target) {
|
|
81567
|
-
return callApi(target, setupListSchema, setupUrl(target, "setup"), {
|
|
81568
|
-
method: "GET"
|
|
81569
|
-
});
|
|
81570
|
-
}
|
|
81571
|
-
async function saveDevtuneSetup(target, route, body) {
|
|
81572
|
-
const saved = await callApi(target, savedSchema, setupUrl(target, route), {
|
|
81573
|
-
method: "PUT",
|
|
81574
|
-
body: JSON.stringify(body)
|
|
81575
|
-
});
|
|
81576
|
-
return { setup: saved.setup, snapshotDigest: saved.snapshot_digest };
|
|
81577
|
-
}
|
|
81578
|
-
|
|
81579
|
-
// src/cli/setup-links.ts
|
|
81580
|
-
async function readSetups(ctx, purpose = "setups") {
|
|
81581
|
-
const target = devtuneTarget(ctx.io, purpose);
|
|
81582
|
-
const list = await readDevtuneSetups(target);
|
|
81583
|
-
return { target, list, names: devtuneSetupNames(list.setups) };
|
|
81584
|
-
}
|
|
81585
|
-
function findDevtuneSetup(setups, arg) {
|
|
81586
|
-
return setups.list.setups.find(
|
|
81587
|
-
(setup) => setups.names.get(setup.id) === arg || setup.id === arg || setup.category_slug === arg
|
|
81588
|
-
);
|
|
81589
|
-
}
|
|
81590
|
-
function writeLink(path, content, link, shown3) {
|
|
81591
|
-
const document = (0, import_yaml5.parseDocument)((0, import_node_fs8.readFileSync)(path, "utf8"));
|
|
81592
|
-
document.set("id", link.id);
|
|
81593
|
-
document.set("synced", {
|
|
81594
|
-
setup: link.setupDigest,
|
|
81595
|
-
file: fileDigest(content)
|
|
81596
|
-
});
|
|
81597
|
-
writeSetupText((0, import_node_path13.dirname)(path), path, document.toString({ lineWidth: 0 }), {
|
|
81598
|
-
replace: true,
|
|
81599
|
-
shown: shown3
|
|
81600
|
-
});
|
|
81601
|
-
}
|
|
81602
|
-
function orphanedMessage(shown3, id) {
|
|
81603
|
-
return `${shown3} is linked to DevTune setup ${id}, which the project no longer has. Remove id and synced from it to push it as a new setup, or delete the file.`;
|
|
81604
|
-
}
|
|
81605
|
-
async function devtuneRunSetup(name, root, ctx) {
|
|
81606
|
-
let setups;
|
|
81607
|
-
try {
|
|
81608
|
-
setups = await readSetups(ctx);
|
|
81609
|
-
} catch (error62) {
|
|
81610
|
-
if (error62 instanceof NotLoggedInError) return null;
|
|
81611
|
-
throw error62;
|
|
81612
|
-
}
|
|
81613
|
-
const setup = findDevtuneSetup(setups, name);
|
|
81614
|
-
if (!setup) return null;
|
|
81615
|
-
const shown3 = `DevTune setup ${setups.names.get(setup.id)}`;
|
|
81616
|
-
const mapped = devtuneSetupFile(setup);
|
|
81617
|
-
if ("problem" in mapped) throw new UsageError(`${shown3}: ${mapped.problem}`);
|
|
81618
|
-
const resolved = resolveSetup(setups.names.get(setup.id), {
|
|
81619
|
-
...mapped.file,
|
|
81620
|
-
id: setup.id
|
|
81621
|
-
});
|
|
81622
|
-
if (!("setup" in resolved))
|
|
81623
|
-
throw new UsageError(
|
|
81624
|
-
`${shown3} can't run as it stands: ${resolved.problems.map((p) => `${p.field}: ${p.message}`).join(" ")} Pull it with agentpicks pull ${setups.names.get(setup.id)}, fix the file, and run that.`
|
|
81625
|
-
);
|
|
81626
|
-
return {
|
|
81627
|
-
path: shown3,
|
|
81628
|
-
name: resolved.setup.name,
|
|
81629
|
-
root,
|
|
81630
|
-
setup: resolved.setup
|
|
81631
|
-
};
|
|
81632
|
-
}
|
|
81633
|
-
function unpushedMessage(shown3, name) {
|
|
81634
|
-
return `${shown3} has changes not pushed to its DevTune setup, so its runs would ask what DevTune doesn't hold. Run agentpicks push ${name}, then run it again, or pass --no-upload to keep the bundles on this machine.`;
|
|
81635
|
-
}
|
|
81636
|
-
function hasUnpushedChanges(content) {
|
|
81637
|
-
return !content.synced || fileDigest(content) !== content.synced.file;
|
|
81638
|
-
}
|
|
81639
|
-
function devtuneChangedMessage(shown3, name) {
|
|
81640
|
-
return `${shown3}'s DevTune setup changed since the file last saw it, so its runs would ask what DevTune no longer holds. Run agentpicks pull ${name}, then run it again, or pass --no-upload to keep the bundles on this machine.`;
|
|
81641
|
-
}
|
|
81642
|
-
async function linkedSetup(id, shown3, ctx) {
|
|
81643
|
-
const setups = await readSetups(ctx, "upload");
|
|
81644
|
-
const setup = setups.list.setups.find((each) => each.id === id);
|
|
81645
|
-
if (!setup) throw new UsageError(orphanedMessage(shown3, id));
|
|
81646
|
-
return setup;
|
|
81647
|
-
}
|
|
81648
|
-
async function linkUploads(plan, setup, content, shown3, ctx) {
|
|
81649
|
-
const unpushed = setup.id !== null && content !== void 0 && hasUnpushedChanges(content);
|
|
81650
|
-
if (!plan.upload)
|
|
81651
|
-
return unpushed && plan.setup ? {
|
|
81652
|
-
...plan,
|
|
81653
|
-
setup: {
|
|
81654
|
-
...plan.setup,
|
|
81655
|
-
record: { ...plan.setup.record, unpushed: true }
|
|
81656
|
-
}
|
|
81657
|
-
} : plan;
|
|
81658
|
-
if (setup.id === null) {
|
|
81659
|
-
if (setup.customReason)
|
|
81660
|
-
throw new UsageError(
|
|
81661
|
-
`${shown3} is a custom setup (${setup.customReason}), so its runs have no DevTune setup to upload under. Run agentpicks push ${setup.name} to save it to DevTune first, or pass --no-upload to keep the bundles on this machine.`
|
|
81662
|
-
);
|
|
81663
|
-
return plan;
|
|
81664
|
-
}
|
|
81665
|
-
const linked = await linkedSetup(setup.id, shown3, ctx);
|
|
81666
|
-
if (content?.synced && linked.snapshot_digest !== content.synced.setup)
|
|
81667
|
-
throw new UsageError(devtuneChangedMessage(shown3, setup.name));
|
|
81668
|
-
if (unpushed) throw new UsageError(unpushedMessage(shown3, setup.name));
|
|
81669
|
-
const slug2 = linked.category_slug;
|
|
81670
|
-
return {
|
|
81671
|
-
...plan,
|
|
81672
|
-
tests: plan.tests.map((test) => ({
|
|
81673
|
-
...test,
|
|
81674
|
-
category: { ...test.category, slug: slug2 }
|
|
81675
|
-
}))
|
|
81676
|
-
};
|
|
81677
|
-
}
|
|
81678
|
-
async function linkedBundle(bundle, ctx) {
|
|
81679
|
-
const id = bundle.setup?.id;
|
|
81680
|
-
if (!id) return null;
|
|
81681
|
-
const shown3 = `${bundle.dir} (a run of ${bundle.setup.name})`;
|
|
81682
|
-
if (bundle.setup.unpushed)
|
|
81683
|
-
throw new UsageError(
|
|
81684
|
-
`${shown3} ran with changes not pushed to its DevTune setup, so it can't file under it. Run agentpicks push ${bundle.setup.name}, then run the setup again.`
|
|
81685
|
-
);
|
|
81686
|
-
const slug2 = (await linkedSetup(id, shown3, ctx)).category_slug;
|
|
81687
|
-
return {
|
|
81688
|
-
...bundle,
|
|
81689
|
-
manifest: {
|
|
81690
|
-
...bundle.manifest,
|
|
81691
|
-
request: { ...bundle.manifest.request, category: slug2 }
|
|
81692
|
-
}
|
|
81693
|
-
};
|
|
81694
|
-
}
|
|
81695
|
-
|
|
81696
|
-
// src/cli/list-command.ts
|
|
81697
82037
|
async function listCommand(argv, ctx) {
|
|
81698
82038
|
if (argv.length > 0)
|
|
81699
82039
|
throw new UsageError(
|
|
@@ -81713,7 +82053,8 @@ async function listCommand(argv, ctx) {
|
|
|
81713
82053
|
ctx.err(`DevTune setups aren't listed: ${error62.message}`);
|
|
81714
82054
|
else throw error62;
|
|
81715
82055
|
}
|
|
81716
|
-
if (devtune)
|
|
82056
|
+
if (devtune)
|
|
82057
|
+
return linkedTable(readSetupFiles(root, heldTools(devtune)), devtune, ctx);
|
|
81717
82058
|
if (files.length === 0) {
|
|
81718
82059
|
ctx.out(`${(0, import_node_path14.join)(root, SETUPS_DIR)} holds no setup files. ${WRITE_ONE}`);
|
|
81719
82060
|
return 0;
|
|
@@ -81751,7 +82092,7 @@ function linkedTable(files, devtune, ctx) {
|
|
|
81751
82092
|
const mapped = devtuneSetupFile(setup);
|
|
81752
82093
|
if ("problem" in mapped)
|
|
81753
82094
|
return { name, cells: null, problem: mapped.problem };
|
|
81754
|
-
const resolved = resolveSetup(name, mapped.file);
|
|
82095
|
+
const resolved = resolveSetup(name, mapped.file, setup.tools);
|
|
81755
82096
|
if (!("setup" in resolved)) {
|
|
81756
82097
|
const [first] = resolved.problems;
|
|
81757
82098
|
return {
|
|
@@ -81820,13 +82161,14 @@ function setupCells(setup) {
|
|
|
81820
82161
|
}
|
|
81821
82162
|
|
|
81822
82163
|
// src/cli/login-command.ts
|
|
81823
|
-
async function assertSignedIn(target, ctx) {
|
|
82164
|
+
async function assertSignedIn(target, ctx, { quiet = false } = {}) {
|
|
81824
82165
|
if (!("session" in target)) return;
|
|
81825
82166
|
let connection;
|
|
81826
82167
|
try {
|
|
81827
82168
|
connection = await discoverProject(target);
|
|
81828
82169
|
} catch (error62) {
|
|
81829
82170
|
if (!(error62 instanceof UploadError && error62.transient)) throw error62;
|
|
82171
|
+
if (quiet) return;
|
|
81830
82172
|
ctx.err(
|
|
81831
82173
|
`Couldn't check the DevTune sign-in before starting; uploading checks it again. ${error62.message}`
|
|
81832
82174
|
);
|
|
@@ -81925,8 +82267,8 @@ async function pullCommand(argv, ctx) {
|
|
|
81925
82267
|
);
|
|
81926
82268
|
const [arg] = positionals;
|
|
81927
82269
|
const root = setupsRoot(ctx.cwd);
|
|
81928
|
-
const files = readSetupFiles(root);
|
|
81929
82270
|
const devtune = await readSetups(ctx);
|
|
82271
|
+
const files = readSetupFiles(root, heldTools(devtune));
|
|
81930
82272
|
let setups = devtune.list.setups;
|
|
81931
82273
|
if (arg !== void 0) {
|
|
81932
82274
|
const file2 = files.find((each) => each.name === arg && each.content?.id);
|
|
@@ -82023,7 +82365,11 @@ function pullOne(setup, root, files, devtune, force, ctx) {
|
|
|
82023
82365
|
return false;
|
|
82024
82366
|
}
|
|
82025
82367
|
ctx.out(`Pulled DevTune setup ${name} to ${shown(path, ctx)}.`);
|
|
82026
|
-
for (const problem of devtuneSetupProblems(
|
|
82368
|
+
for (const problem of devtuneSetupProblems(
|
|
82369
|
+
setup,
|
|
82370
|
+
local?.name ?? name,
|
|
82371
|
+
mapped.file
|
|
82372
|
+
))
|
|
82027
82373
|
ctx.err(
|
|
82028
82374
|
`${shown(path, ctx)}: ${problem.field}: ${problem.message} Fix it before running the setup.`
|
|
82029
82375
|
);
|
|
@@ -82032,199 +82378,6 @@ function pullOne(setup, root, files, devtune, force, ctx) {
|
|
|
82032
82378
|
|
|
82033
82379
|
// src/cli/push-command.ts
|
|
82034
82380
|
var import_node_path16 = require("node:path");
|
|
82035
|
-
|
|
82036
|
-
// src/cli/push-payload.ts
|
|
82037
|
-
var NO_BUILDING_BLOCKS = { packages: {}, codePatterns: [] };
|
|
82038
|
-
function pushRequest(file2, current, list, shown3, repositoryStacks) {
|
|
82039
|
-
const from = file2.from ? findCategoryRequests(file2.from) : void 0;
|
|
82040
|
-
const runsIn = from?.slug ?? "job-";
|
|
82041
|
-
const tools = [
|
|
82042
|
-
...file2.tools?.own !== void 0 ? [file2.tools.own] : [],
|
|
82043
|
-
...file2.tools?.competitors ?? []
|
|
82044
|
-
];
|
|
82045
|
-
const key = (ref) => typeof ref === "string" ? ref : ref.key;
|
|
82046
|
-
const shared = {
|
|
82047
|
-
environment_ids: environmentIds(
|
|
82048
|
-
file2,
|
|
82049
|
-
current,
|
|
82050
|
-
list,
|
|
82051
|
-
runsIn,
|
|
82052
|
-
shown3,
|
|
82053
|
-
repositoryStacks
|
|
82054
|
-
),
|
|
82055
|
-
agent_models: agentModels(file2, current, list, shown3),
|
|
82056
|
-
snapshot_digest: current ? file2.synced?.setup ?? null : null,
|
|
82057
|
-
...current ? { setup: current.id } : {}
|
|
82058
|
-
};
|
|
82059
|
-
if (from) {
|
|
82060
|
-
for (const ref of tools)
|
|
82061
|
-
if (typeof ref !== "string" && !heldAsWritten(ref, current))
|
|
82062
|
-
throw new UsageError(
|
|
82063
|
-
`${shown3}: ${ref.key} isn't a tool of ${from.slug}. Add your own tool to a category copy in the DevTune app, then run agentpicks pull.`
|
|
82064
|
-
);
|
|
82065
|
-
return {
|
|
82066
|
-
route: "setup",
|
|
82067
|
-
body: {
|
|
82068
|
-
category_id: categoryId(list, from.slug, shown3),
|
|
82069
|
-
tool_key: file2.tools?.own === void 0 ? null : key(file2.tools.own),
|
|
82070
|
-
competitor_tool_keys: (file2.tools?.competitors ?? []).map(key),
|
|
82071
|
-
...setupRequests(file2, current, from),
|
|
82072
|
-
...shared
|
|
82073
|
-
}
|
|
82074
|
-
};
|
|
82075
|
-
}
|
|
82076
|
-
const withheld = current?.tools.find((row) => row.signals === null);
|
|
82077
|
-
if (withheld)
|
|
82078
|
-
throw new UsageError(
|
|
82079
|
-
`${shown3}: ${catalogueToolProblem(withheld.tool_key)}`
|
|
82080
|
-
);
|
|
82081
|
-
if (file2.requests?.improve != null)
|
|
82082
|
-
throw new UsageError(
|
|
82083
|
-
`${shown3}: requests.improve can't be saved on a job. Remove it, and change it in DevTune instead.`
|
|
82084
|
-
);
|
|
82085
|
-
const recommend = file2.requests?.recommend;
|
|
82086
|
-
if (!recommend)
|
|
82087
|
-
throw new UsageError(
|
|
82088
|
-
`${shown3}: give requests.recommend. DevTune saves a job with its add and recommend requests.`
|
|
82089
|
-
);
|
|
82090
|
-
const listed = new Set(tools.map(key));
|
|
82091
|
-
const held = /* @__PURE__ */ new Set([
|
|
82092
|
-
...current?.own_tool_key ? [current.own_tool_key] : [],
|
|
82093
|
-
...current?.competitor_tool_keys ?? []
|
|
82094
|
-
]);
|
|
82095
|
-
return {
|
|
82096
|
-
route: "job",
|
|
82097
|
-
body: {
|
|
82098
|
-
job: file2.job,
|
|
82099
|
-
source_category_id: null,
|
|
82100
|
-
requests: {
|
|
82101
|
-
add: file2.requests?.add,
|
|
82102
|
-
recommend,
|
|
82103
|
-
hosted: file2.requests?.hosted ?? null
|
|
82104
|
-
},
|
|
82105
|
-
building_blocks: current?.building_blocks ?? NO_BUILDING_BLOCKS,
|
|
82106
|
-
tools: [
|
|
82107
|
-
...tools.map((ref) => jobTool(ref, current, shown3)),
|
|
82108
|
-
// A tool DevTune measures that is neither yours nor a competitor, which a file can't name.
|
|
82109
|
-
...(current?.tools ?? []).filter((row) => !listed.has(row.tool_key) && !held.has(row.tool_key)).map((row) => ({
|
|
82110
|
-
tool_key: row.tool_key,
|
|
82111
|
-
display_name: row.display_name,
|
|
82112
|
-
brand_domain: row.brand_domain,
|
|
82113
|
-
signals: row.signals
|
|
82114
|
-
}))
|
|
82115
|
-
],
|
|
82116
|
-
own_tool_key: file2.tools?.own === void 0 ? null : key(file2.tools.own),
|
|
82117
|
-
competitor_tool_keys: (file2.tools?.competitors ?? []).map(key),
|
|
82118
|
-
...shared
|
|
82119
|
-
}
|
|
82120
|
-
};
|
|
82121
|
-
}
|
|
82122
|
-
var OMITTED_REQUEST = "omitted";
|
|
82123
|
-
function setupRequests(file2, current, from) {
|
|
82124
|
-
const requests = {};
|
|
82125
|
-
for (const intent of PROMPT_INTENTS) {
|
|
82126
|
-
const text3 = file2.requests?.[intent];
|
|
82127
|
-
const published = from.prompts.find((p) => p.intent === intent)?.text;
|
|
82128
|
-
const held = current?.requests[intent] ?? null;
|
|
82129
|
-
if (text3 === null) requests[intent] = OMITTED_REQUEST;
|
|
82130
|
-
else if (text3 !== void 0) requests[intent] = text3;
|
|
82131
|
-
else if (current && published && held !== published)
|
|
82132
|
-
requests[intent] = published;
|
|
82133
|
-
}
|
|
82134
|
-
return Object.keys(requests).length ? { requests } : {};
|
|
82135
|
-
}
|
|
82136
|
-
function heldAsWritten(entry, current) {
|
|
82137
|
-
const row = current?.tools.find((each) => each.tool_key === entry.key);
|
|
82138
|
-
return row?.signals != null && canonical(fileTool({ ...row, signals: row.signals })) === canonical(entry);
|
|
82139
|
-
}
|
|
82140
|
-
function jobTool(ref, current, shown3) {
|
|
82141
|
-
const row = current?.tools.find(
|
|
82142
|
-
(each) => each.tool_key === (typeof ref === "string" ? ref : ref.key)
|
|
82143
|
-
);
|
|
82144
|
-
if (typeof ref === "string") {
|
|
82145
|
-
if (!row?.signals)
|
|
82146
|
-
throw new UsageError(
|
|
82147
|
-
`${shown3}: DevTune's setup doesn't hold ${ref}, so push can't send how to recognise it. Give it as a full entry, with key, name and signals.`
|
|
82148
|
-
);
|
|
82149
|
-
return {
|
|
82150
|
-
tool_key: row.tool_key,
|
|
82151
|
-
display_name: row.display_name,
|
|
82152
|
-
brand_domain: row.brand_domain,
|
|
82153
|
-
signals: row.signals
|
|
82154
|
-
};
|
|
82155
|
-
}
|
|
82156
|
-
return {
|
|
82157
|
-
tool_key: ref.key,
|
|
82158
|
-
display_name: ref.name,
|
|
82159
|
-
brand_domain: ref.domain ?? null,
|
|
82160
|
-
signals: jobSignals(ref, row?.signals ?? null)
|
|
82161
|
-
};
|
|
82162
|
-
}
|
|
82163
|
-
function jobSignals(entry, held) {
|
|
82164
|
-
const { packages, configNames, importPatterns, brandDomains, ...rest } = entry.signals;
|
|
82165
|
-
return {
|
|
82166
|
-
packages: packages ?? {},
|
|
82167
|
-
configNames: configNames ?? [],
|
|
82168
|
-
importPatterns: importPatterns ?? [],
|
|
82169
|
-
brandDomains: brandDomains ?? [],
|
|
82170
|
-
...rest,
|
|
82171
|
-
...Array.isArray(held?.dismissedYieldsTo) ? { dismissedYieldsTo: held.dismissedYieldsTo } : {}
|
|
82172
|
-
};
|
|
82173
|
-
}
|
|
82174
|
-
function categoryId(list, slug2, shown3) {
|
|
82175
|
-
const category = list.catalogue.categories.find((c) => c.slug === slug2);
|
|
82176
|
-
if (!category)
|
|
82177
|
-
throw new UsageError(
|
|
82178
|
-
`${shown3}: DevTune has no published category ${slug2}. Choose another from:, or update agentpicks.`
|
|
82179
|
-
);
|
|
82180
|
-
return category.id;
|
|
82181
|
-
}
|
|
82182
|
-
function environmentIds(file2, current, list, runsIn, shown3, repositoryStacks) {
|
|
82183
|
-
const stacks = file2.stacks ?? repositoryStacks?.filter((slug2) => nameableStack(slug2, runsIn));
|
|
82184
|
-
if (!stacks && current) return current.environments.map((env) => env.id);
|
|
82185
|
-
if (!stacks?.length)
|
|
82186
|
-
throw new UsageError(
|
|
82187
|
-
`${shown3}: couldn't detect any supported stacks for this repository. Replace repo: with stacks: (for example, stacks: [nextjs]), then push again. To test the repository, pass --repo to agentpicks run.`
|
|
82188
|
-
);
|
|
82189
|
-
const ids = stacks.map((slug2) => {
|
|
82190
|
-
const env = list.catalogue.environments.find((each) => each.slug === slug2);
|
|
82191
|
-
if (!env)
|
|
82192
|
-
throw new UsageError(
|
|
82193
|
-
`${shown3}: DevTune has no stack ${slug2}. Remove it from stacks:, or update agentpicks.`
|
|
82194
|
-
);
|
|
82195
|
-
return env.id;
|
|
82196
|
-
});
|
|
82197
|
-
const kept = (current?.environments ?? []).filter((env) => !nameableStack(env.slug, runsIn)).map((env) => env.id);
|
|
82198
|
-
return [.../* @__PURE__ */ new Set([...ids, ...kept])];
|
|
82199
|
-
}
|
|
82200
|
-
function agentModels(file2, current, list, shown3) {
|
|
82201
|
-
const held = current?.agent_models ?? [];
|
|
82202
|
-
if (!file2.agents) {
|
|
82203
|
-
if (current) return held;
|
|
82204
|
-
throw new UsageError(
|
|
82205
|
-
`${shown3}: give agents:, the agents DevTune tests the setup with.`
|
|
82206
|
-
);
|
|
82207
|
-
}
|
|
82208
|
-
const named = file2.agents.map(devtuneAgent);
|
|
82209
|
-
return [
|
|
82210
|
-
...named.flatMap((agent) => {
|
|
82211
|
-
const models = held.filter((entry) => entry.agent === agent);
|
|
82212
|
-
if (models.length) return models;
|
|
82213
|
-
const model = list.catalogue.agents.find((each) => each.agent === agent)?.models[0];
|
|
82214
|
-
if (!model)
|
|
82215
|
-
throw new UsageError(
|
|
82216
|
-
`${shown3}: DevTune offers no model for ${agent}. Remove it from agents:.`
|
|
82217
|
-
);
|
|
82218
|
-
return [{ agent, model }];
|
|
82219
|
-
}),
|
|
82220
|
-
...held.filter(
|
|
82221
|
-
(entry) => !named.includes(entry.agent) && !SETUP_AGENT_KINDS.includes(entry.agent)
|
|
82222
|
-
)
|
|
82223
|
-
];
|
|
82224
|
-
}
|
|
82225
|
-
var SETUP_AGENT_KINDS = SELF_RUN_AGENTS.map((agent) => agent.kind);
|
|
82226
|
-
|
|
82227
|
-
// src/cli/push-command.ts
|
|
82228
82381
|
async function pushCommand(argv, ctx) {
|
|
82229
82382
|
const flag = argv.find((arg) => arg.startsWith("-"));
|
|
82230
82383
|
if (flag)
|
|
@@ -82233,12 +82386,13 @@ async function pushCommand(argv, ctx) {
|
|
|
82233
82386
|
throw new UsageError(
|
|
82234
82387
|
`Name one setup to push, or none for every one, not ${argv.join(", ")}.`
|
|
82235
82388
|
);
|
|
82236
|
-
const
|
|
82237
|
-
if (
|
|
82389
|
+
const read = (held) => argv.length === 1 ? [readSetupFile(findSetup(argv[0], ctx.cwd), held)] : readSetupFiles(setupsRoot(ctx.cwd), held);
|
|
82390
|
+
if (read().length === 0)
|
|
82238
82391
|
throw new UsageError(
|
|
82239
82392
|
"There are no setup files to push. Write one, or pull a DevTune setup with agentpicks pull."
|
|
82240
82393
|
);
|
|
82241
82394
|
const devtune = await readSetups(ctx);
|
|
82395
|
+
const files = read(heldTools(devtune));
|
|
82242
82396
|
let failed = 0;
|
|
82243
82397
|
for (const file2 of files) if (!await pushOne(file2, devtune, ctx)) failed++;
|
|
82244
82398
|
return failed === 0 ? 0 : 1;
|
|
@@ -82686,7 +82840,7 @@ function resultRow(dir) {
|
|
|
82686
82840
|
const { manifest, setup, earlyStop } = bundle;
|
|
82687
82841
|
const { category } = manifest.request;
|
|
82688
82842
|
const custom2 = category.startsWith(CUSTOM_SETUP_CATEGORY_PREFIX);
|
|
82689
|
-
const
|
|
82843
|
+
const watched = earlyStop ? readWatchPick(
|
|
82690
82844
|
Object.fromEntries(
|
|
82691
82845
|
[...bundle.contents].map(([name, bytes]) => [
|
|
82692
82846
|
name,
|
|
@@ -82698,6 +82852,10 @@ function resultRow(dir) {
|
|
|
82698
82852
|
status: "unmeasured",
|
|
82699
82853
|
reason: "the bundle was written before agentpicks recorded the early-stop patterns a run watches for. Run it again to read its pick."
|
|
82700
82854
|
};
|
|
82855
|
+
const pick2 = watched.status === "none" && setup?.unrecognised?.length ? {
|
|
82856
|
+
status: "unmeasured",
|
|
82857
|
+
reason: `${setup.name} measures ${setup.unrecognised.join(", ")} from DevTune's catalogue, and this machine has no signals for ${setup.unrecognised.length === 1 ? "it" : "them"}.`
|
|
82858
|
+
} : watched;
|
|
82701
82859
|
return {
|
|
82702
82860
|
dir,
|
|
82703
82861
|
runId: manifest.runId,
|
|
@@ -84890,12 +85048,15 @@ run Tests the coding agent installed here in a fresh Docker container per
|
|
|
84890
85048
|
your repository's committed files at HEAD, or at --ref; uncommitted changes aren't
|
|
84891
85049
|
included. Uploading a --repo run needs the repository to have a remote.
|
|
84892
85050
|
<setup> is a setup file's name in the repository's agentpicks folder, or its path,
|
|
84893
|
-
or signed in, the name of a DevTune setup with no file
|
|
85051
|
+
or signed in, the name of a DevTune setup with no file that asks its category's
|
|
85052
|
+
add request as published (pull a job or an edited copy and run the file). The setup says what to
|
|
84894
85053
|
test; flags override it. On a terminal, run with no setup and no --category
|
|
84895
85054
|
offers the setups to choose from. A setup linked to DevTune (it has an id)
|
|
84896
85055
|
uploads under its DevTune setup. An unlinked setup from: a category, with no
|
|
84897
85056
|
requests or tool signals of its own, uploads as that category; any other is
|
|
84898
|
-
custom and uploads once agentpicks push links it.
|
|
85057
|
+
custom and uploads once agentpicks push links it. Uploading, --category runs
|
|
85058
|
+
the project's copy of the category as run <copy> would, creating the copy
|
|
85059
|
+
first when the project has none; with --no-upload it runs the category itself.
|
|
84899
85060
|
list Lists the setup files in agentpicks/*.yaml at the repository root, flagging any
|
|
84900
85061
|
that fails its checks. Signed in, it lists the project's DevTune setups too:
|
|
84901
85062
|
where each lives (local, DevTune or both) and whether a linked pair is in sync.
|
|
@@ -84994,7 +85155,11 @@ function docker2(ctx) {
|
|
|
84994
85155
|
async function runCommand(argv, ctx) {
|
|
84995
85156
|
const command = parseRunCommand(argv, { picker: Boolean(ctx.interactive) });
|
|
84996
85157
|
if (command.kind === "category")
|
|
84997
|
-
return runPlan(
|
|
85158
|
+
return runPlan(
|
|
85159
|
+
categoryPlan(command.args, ctx.cwd),
|
|
85160
|
+
ctx,
|
|
85161
|
+
() => categoryCopyPlan(command.args, ctx)
|
|
85162
|
+
);
|
|
84998
85163
|
const file2 = await runnableSetup(command.setup, ctx);
|
|
84999
85164
|
if (file2 === null) return 1;
|
|
85000
85165
|
const shown3 = (0, import_node_path18.relative)(ctx.cwd, file2.path) || file2.path;
|
|
@@ -85015,7 +85180,15 @@ async function runnableSetup(name, ctx) {
|
|
|
85015
85180
|
throw error62;
|
|
85016
85181
|
}
|
|
85017
85182
|
if (path === null) return null;
|
|
85018
|
-
|
|
85183
|
+
let file2 = readSetupFile(path);
|
|
85184
|
+
if (!file2.setup && file2.content?.id) {
|
|
85185
|
+
const devtune = await readSetups(ctx).catch((error62) => {
|
|
85186
|
+
if (error62 instanceof NotLoggedInError || error62 instanceof UploadError)
|
|
85187
|
+
return null;
|
|
85188
|
+
throw error62;
|
|
85189
|
+
});
|
|
85190
|
+
if (devtune) file2 = readSetupFile(path, heldTools(devtune));
|
|
85191
|
+
}
|
|
85019
85192
|
if (!file2.setup) {
|
|
85020
85193
|
for (const problem of file2.problems)
|
|
85021
85194
|
ctx.err(formatProblem(path, problem, ctx.cwd));
|
|
@@ -85057,14 +85230,15 @@ async function askLine(question) {
|
|
|
85057
85230
|
rl.close();
|
|
85058
85231
|
}
|
|
85059
85232
|
}
|
|
85060
|
-
async function runPlan(
|
|
85061
|
-
const repository =
|
|
85062
|
-
const target =
|
|
85233
|
+
async function runPlan(given, ctx, link) {
|
|
85234
|
+
const repository = given.repo === void 0 ? void 0 : readRepository(given.repo, given.ref);
|
|
85235
|
+
const target = given.upload ? devtuneTarget(ctx.io) : null;
|
|
85063
85236
|
if (target && repository && repository.remoteUrl === null)
|
|
85064
85237
|
throw new RepositoryRemoteError(
|
|
85065
85238
|
`DevTune groups a repository's runs by its remote, and ${repository.root} has none agentpicks can record. Add an origin remote with a network address, or pass --no-upload to keep the bundles on this machine only.`
|
|
85066
85239
|
);
|
|
85067
|
-
if (target) await assertSignedIn(target, ctx);
|
|
85240
|
+
if (target) await assertSignedIn(target, ctx, { quiet: link !== void 0 });
|
|
85241
|
+
const plan = target && link ? await link(given) : given;
|
|
85068
85242
|
const agentPlans = plan.agents.map(
|
|
85069
85243
|
(choice) => planAgent(chooseAgent(ctx.io, choice))
|
|
85070
85244
|
);
|