@devtune/agentpicks 0.4.6 → 0.4.7

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.
Files changed (3) hide show
  1. package/README.md +12 -5
  2. package/dist/cli.js +593 -257
  3. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -1504,7 +1504,7 @@ var require_stringify = __commonJS({
1504
1504
  props.push(doc.directives.tagString(tag));
1505
1505
  return props.join(" ");
1506
1506
  }
1507
- function stringify3(item, ctx, onComment, onChompKeep) {
1507
+ function stringify4(item, ctx, onComment, onChompKeep) {
1508
1508
  if (identity.isPair(item))
1509
1509
  return item.toString(ctx, onComment, onChompKeep);
1510
1510
  if (identity.isAlias(item)) {
@@ -1533,7 +1533,7 @@ var require_stringify = __commonJS({
1533
1533
  ${ctx.indent}${str2}`;
1534
1534
  }
1535
1535
  exports2.createStringifyContext = createStringifyContext;
1536
- exports2.stringify = stringify3;
1536
+ exports2.stringify = stringify4;
1537
1537
  }
1538
1538
  });
1539
1539
 
@@ -1543,7 +1543,7 @@ var require_stringifyPair = __commonJS({
1543
1543
  "use strict";
1544
1544
  var identity = require_identity();
1545
1545
  var Scalar = require_Scalar();
1546
- var stringify3 = require_stringify();
1546
+ var stringify4 = require_stringify();
1547
1547
  var stringifyComment = require_stringifyComment();
1548
1548
  function stringifyPair({ key, value }, ctx, onComment, onChompKeep) {
1549
1549
  const { allNullValues, doc, indent, indentStep, options: { commentString, indentSeq, simpleKeys } } = ctx;
@@ -1565,7 +1565,7 @@ var require_stringifyPair = __commonJS({
1565
1565
  });
1566
1566
  let keyCommentDone = false;
1567
1567
  let chompKeep = false;
1568
- let str2 = stringify3.stringify(key, ctx, () => keyCommentDone = true, () => chompKeep = true);
1568
+ let str2 = stringify4.stringify(key, ctx, () => keyCommentDone = true, () => chompKeep = true);
1569
1569
  if (!explicitKey && !ctx.inFlow && str2.length > 1024) {
1570
1570
  if (simpleKeys)
1571
1571
  throw new Error("With simple keys, single line scalar must not span more than 1024 characters");
@@ -1617,7 +1617,7 @@ ${indent}:`;
1617
1617
  ctx.indent = ctx.indent.substring(2);
1618
1618
  }
1619
1619
  let valueCommentDone = false;
1620
- const valueStr = stringify3.stringify(value, ctx, () => valueCommentDone = true, () => chompKeep = true);
1620
+ const valueStr = stringify4.stringify(value, ctx, () => valueCommentDone = true, () => chompKeep = true);
1621
1621
  let ws = " ";
1622
1622
  if (keyComment || vsb || vcb) {
1623
1623
  ws = vsb ? "\n" : "";
@@ -1758,7 +1758,7 @@ var require_addPairToJSMap = __commonJS({
1758
1758
  "use strict";
1759
1759
  var log = require_log();
1760
1760
  var merge2 = require_merge();
1761
- var stringify3 = require_stringify();
1761
+ var stringify4 = require_stringify();
1762
1762
  var identity = require_identity();
1763
1763
  var toJS = require_toJS();
1764
1764
  function addPairToJSMap(ctx, map2, { key, value }) {
@@ -1794,7 +1794,7 @@ var require_addPairToJSMap = __commonJS({
1794
1794
  if (typeof jsKey !== "object")
1795
1795
  return String(jsKey);
1796
1796
  if (identity.isNode(key) && ctx?.doc) {
1797
- const strCtx = stringify3.createStringifyContext(ctx.doc, {});
1797
+ const strCtx = stringify4.createStringifyContext(ctx.doc, {});
1798
1798
  strCtx.anchors = /* @__PURE__ */ new Set();
1799
1799
  for (const node2 of ctx.anchors.keys())
1800
1800
  strCtx.anchors.add(node2.anchor);
@@ -1861,12 +1861,12 @@ var require_stringifyCollection = __commonJS({
1861
1861
  "../../node_modules/.pnpm/yaml@2.9.1/node_modules/yaml/dist/stringify/stringifyCollection.js"(exports2) {
1862
1862
  "use strict";
1863
1863
  var identity = require_identity();
1864
- var stringify3 = require_stringify();
1864
+ var stringify4 = require_stringify();
1865
1865
  var stringifyComment = require_stringifyComment();
1866
1866
  function stringifyCollection(collection, ctx, options) {
1867
1867
  const flow = ctx.inFlow ?? collection.flow;
1868
- const stringify4 = flow ? stringifyFlowCollection : stringifyBlockCollection;
1869
- return stringify4(collection, ctx, options);
1868
+ const stringify5 = flow ? stringifyFlowCollection : stringifyBlockCollection;
1869
+ return stringify5(collection, ctx, options);
1870
1870
  }
1871
1871
  function stringifyBlockCollection({ comment, items }, ctx, { blockItemPrefix, flowChars, itemIndent, onChompKeep, onComment }) {
1872
1872
  const { indent, options: { commentString } } = ctx;
@@ -1891,7 +1891,7 @@ var require_stringifyCollection = __commonJS({
1891
1891
  }
1892
1892
  }
1893
1893
  chompKeep = false;
1894
- let str3 = stringify3.stringify(item, itemCtx, () => comment2 = null, () => chompKeep = true);
1894
+ let str3 = stringify4.stringify(item, itemCtx, () => comment2 = null, () => chompKeep = true);
1895
1895
  if (comment2)
1896
1896
  str3 += stringifyComment.lineComment(str3, itemIndent, commentString(comment2));
1897
1897
  if (chompKeep && comment2)
@@ -1958,7 +1958,7 @@ ${indent}${line2}` : "\n";
1958
1958
  }
1959
1959
  if (comment)
1960
1960
  reqNewline = true;
1961
- let str2 = stringify3.stringify(item, itemCtx, () => comment = null);
1961
+ let str2 = stringify4.stringify(item, itemCtx, () => comment = null);
1962
1962
  reqNewline || (reqNewline = lines.length > linesAtValue || str2.includes("\n"));
1963
1963
  if (i < items.length - 1) {
1964
1964
  str2 += ",";
@@ -3319,7 +3319,7 @@ var require_stringifyDocument = __commonJS({
3319
3319
  "../../node_modules/.pnpm/yaml@2.9.1/node_modules/yaml/dist/stringify/stringifyDocument.js"(exports2) {
3320
3320
  "use strict";
3321
3321
  var identity = require_identity();
3322
- var stringify3 = require_stringify();
3322
+ var stringify4 = require_stringify();
3323
3323
  var stringifyComment = require_stringifyComment();
3324
3324
  function stringifyDocument(doc, options) {
3325
3325
  const lines = [];
@@ -3334,7 +3334,7 @@ var require_stringifyDocument = __commonJS({
3334
3334
  }
3335
3335
  if (hasDirectives)
3336
3336
  lines.push("---");
3337
- const ctx = stringify3.createStringifyContext(doc, options);
3337
+ const ctx = stringify4.createStringifyContext(doc, options);
3338
3338
  const { commentString } = ctx.options;
3339
3339
  if (doc.commentBefore) {
3340
3340
  if (lines.length !== 1)
@@ -3356,7 +3356,7 @@ var require_stringifyDocument = __commonJS({
3356
3356
  contentComment = doc.contents.comment;
3357
3357
  }
3358
3358
  const onChompKeep = contentComment ? void 0 : () => chompKeep = true;
3359
- let body = stringify3.stringify(doc.contents, ctx, () => contentComment = null, onChompKeep);
3359
+ let body = stringify4.stringify(doc.contents, ctx, () => contentComment = null, onChompKeep);
3360
3360
  if (contentComment)
3361
3361
  body += stringifyComment.lineComment(body, "", commentString(contentComment));
3362
3362
  if ((body[0] === "|" || body[0] === ">") && lines[lines.length - 1] === "---") {
@@ -3364,7 +3364,7 @@ var require_stringifyDocument = __commonJS({
3364
3364
  } else
3365
3365
  lines.push(body);
3366
3366
  } else {
3367
- lines.push(stringify3.stringify(doc.contents, ctx));
3367
+ lines.push(stringify4.stringify(doc.contents, ctx));
3368
3368
  }
3369
3369
  if (doc.directives?.docEnd) {
3370
3370
  if (doc.comment) {
@@ -5500,7 +5500,7 @@ var require_cst_scalar = __commonJS({
5500
5500
  var require_cst_stringify = __commonJS({
5501
5501
  "../../node_modules/.pnpm/yaml@2.9.1/node_modules/yaml/dist/parse/cst-stringify.js"(exports2) {
5502
5502
  "use strict";
5503
- var stringify3 = (cst) => "type" in cst ? stringifyToken(cst) : stringifyItem(cst);
5503
+ var stringify4 = (cst) => "type" in cst ? stringifyToken(cst) : stringifyItem(cst);
5504
5504
  function stringifyToken(token) {
5505
5505
  switch (token.type) {
5506
5506
  case "block-scalar": {
@@ -5553,7 +5553,7 @@ var require_cst_stringify = __commonJS({
5553
5553
  res += stringifyToken(value);
5554
5554
  return res;
5555
5555
  }
5556
- exports2.stringify = stringify3;
5556
+ exports2.stringify = stringify4;
5557
5557
  }
5558
5558
  });
5559
5559
 
@@ -7283,7 +7283,7 @@ var require_public_api = __commonJS({
7283
7283
  }
7284
7284
  return doc.toJS(Object.assign({ reviver: _reviver }, options));
7285
7285
  }
7286
- function stringify3(value, replacer, options) {
7286
+ function stringify4(value, replacer, options) {
7287
7287
  let _replacer = null;
7288
7288
  if (typeof replacer === "function" || Array.isArray(replacer)) {
7289
7289
  _replacer = replacer;
@@ -7308,7 +7308,7 @@ var require_public_api = __commonJS({
7308
7308
  exports2.parse = parse6;
7309
7309
  exports2.parseAllDocuments = parseAllDocuments;
7310
7310
  exports2.parseDocument = parseDocument3;
7311
- exports2.stringify = stringify3;
7311
+ exports2.stringify = stringify4;
7312
7312
  }
7313
7313
  });
7314
7314
 
@@ -7365,17 +7365,17 @@ var require_dist = __commonJS({
7365
7365
  });
7366
7366
 
7367
7367
  // src/cli.ts
7368
- var import_node_path20 = require("node:path");
7368
+ var import_node_path21 = require("node:path");
7369
7369
 
7370
7370
  // src/cli/main.ts
7371
7371
  var import_node_crypto10 = require("node:crypto");
7372
- var import_node_path19 = require("node:path");
7372
+ var import_node_path20 = require("node:path");
7373
7373
  var import_promises5 = require("node:readline/promises");
7374
7374
 
7375
7375
  // package.json
7376
7376
  var package_default = {
7377
7377
  name: "@devtune/agentpicks",
7378
- version: "0.4.6",
7378
+ version: "0.4.7",
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: {
@@ -8764,6 +8764,11 @@ function environmentRunsIn(slug2, categorySlug) {
8764
8764
  if (categorySlug.startsWith("job-")) return false;
8765
8765
  return !environment.categories || environment.categories.includes(categorySlug);
8766
8766
  }
8767
+ function setupEnvironments(runsIn) {
8768
+ return ENVIRONMENTS.filter(
8769
+ (env) => !isRetiredEnvironment(env.slug) && environmentRunsIn(env.slug, runsIn)
8770
+ );
8771
+ }
8767
8772
 
8768
8773
  // src/catalogue/prompt-intents.ts
8769
8774
  var PROMPT_INTENTS = [
@@ -28847,9 +28852,7 @@ function editedReason(category, file2, entries2, added) {
28847
28852
  return null;
28848
28853
  }
28849
28854
  function stackChoices(runsIn) {
28850
- return ENVIRONMENTS.filter(
28851
- (env) => !isRetiredEnvironment(env.slug) && environmentRunsIn(env.slug, runsIn)
28852
- ).map((env) => env.slug).join(", ");
28855
+ return setupEnvironments(runsIn).map((env) => env.slug).join(", ");
28853
28856
  }
28854
28857
  var escapeEre = (text3) => text3.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
28855
28858
  function watchedPackage(name) {
@@ -28872,10 +28875,10 @@ function mergeEarlyStop(base, entries2, listedKeys) {
28872
28875
  const configNames = unique(
28873
28876
  stopping.flatMap((tool) => tool.signals.configNames ?? [])
28874
28877
  ).map(escapeEre);
28875
- const join16 = (inherited, added) => [inherited, ...added].filter(Boolean).join("|") || NEVER_PATTERN;
28878
+ const join17 = (inherited, added) => [inherited, ...added].filter(Boolean).join("|") || NEVER_PATTERN;
28876
28879
  return {
28877
- installPattern: join16(base?.installPattern, packages),
28878
- codePattern: join16(base?.codePattern, configNames),
28880
+ installPattern: join17(base?.installPattern, packages),
28881
+ codePattern: join17(base?.codePattern, configNames),
28879
28882
  ...base?.pathPattern ? { pathPattern: base.pathPattern } : {}
28880
28883
  };
28881
28884
  }
@@ -78280,10 +78283,10 @@ function readRunOptions(argv) {
78280
78283
  })
78281
78284
  );
78282
78285
  }
78283
- function categoryArgs(values, hint = "") {
78286
+ function categoryArgs(values, hint2 = "") {
78284
78287
  if (!values.category)
78285
78288
  throw new UnknownCategoryError(
78286
- `Choose a category with --category: ${categoryList()}.${hint}`
78289
+ `Choose a category with --category: ${categoryList()}.${hint2}`
78287
78290
  );
78288
78291
  if (values.stack !== void 0 && values.repo !== void 0)
78289
78292
  throw new UsageError(
@@ -78513,6 +78516,73 @@ function stackList(categorySlug) {
78513
78516
  ).map((env) => env.slug).join(", ");
78514
78517
  }
78515
78518
 
78519
+ // src/cli/catalogue-command.ts
78520
+ var import_node_util2 = require("node:util");
78521
+ function catalogueCommand(argv, ctx) {
78522
+ const { json: json3, slug: slug2 } = parseCatalogueArgs(argv);
78523
+ const pairs = (items) => items.map(({ slug: slug3, name }) => ({ slug: slug3, name }));
78524
+ if (slug2 === null) {
78525
+ const categories = pairs(CATEGORY_REQUESTS);
78526
+ const stacks2 = pairs(setupEnvironments("job-"));
78527
+ if (json3) ctx.out(JSON.stringify({ categories, stacks: stacks2 }, null, 2));
78528
+ else
78529
+ for (const line2 of [
78530
+ "Categories:",
78531
+ ...columns(categories),
78532
+ "",
78533
+ "Stacks a job line can run in:",
78534
+ ...columns(stacks2)
78535
+ ])
78536
+ ctx.out(line2);
78537
+ return 0;
78538
+ }
78539
+ const found = findCategoryRequests(slug2);
78540
+ if (!found)
78541
+ throw new UsageError(
78542
+ `There is no category ${slug2}. List them with: agentpicks catalogue`
78543
+ );
78544
+ const category = { slug: found.slug, name: found.name };
78545
+ const tools = CATEGORY_TOOLS[found.slug] ?? [];
78546
+ const stacks = pairs(setupEnvironments(found.slug));
78547
+ if (json3) ctx.out(JSON.stringify({ category, tools, stacks }, null, 2));
78548
+ else
78549
+ for (const line2 of [
78550
+ ...columns([category]),
78551
+ "",
78552
+ "Tools:",
78553
+ ...tools.map((key) => ` ${key}`),
78554
+ "",
78555
+ "Stacks:",
78556
+ ...columns(stacks)
78557
+ ])
78558
+ ctx.out(line2);
78559
+ return 0;
78560
+ }
78561
+ function columns(items) {
78562
+ const width = Math.max(...items.map((item) => item.slug.length));
78563
+ return items.map((item) => ` ${item.slug.padEnd(width)} ${item.name}`);
78564
+ }
78565
+ function parseCatalogueArgs(argv) {
78566
+ let parsed2;
78567
+ try {
78568
+ parsed2 = (0, import_node_util2.parseArgs)({
78569
+ args: argv,
78570
+ strict: true,
78571
+ allowPositionals: true,
78572
+ options: { json: { type: "boolean", default: false } }
78573
+ });
78574
+ } catch (error62) {
78575
+ throw new UsageError(
78576
+ error62 instanceof Error ? error62.message : String(error62)
78577
+ );
78578
+ }
78579
+ if (parsed2.positionals.length > 1)
78580
+ throw new UsageError(
78581
+ "Name one category, or none to list them: agentpicks catalogue [<category>] [--json]"
78582
+ );
78583
+ return { json: parsed2.values.json, slug: parsed2.positionals[0] ?? null };
78584
+ }
78585
+
78516
78586
  // src/setup/link.ts
78517
78587
  var import_yaml2 = __toESM(require_dist());
78518
78588
  function syncState(file2, setup) {
@@ -80356,7 +80426,7 @@ var messages = {
80356
80426
  }
80357
80427
  };
80358
80428
  function loginPage(state) {
80359
- const { heading, message, hint } = messages[state];
80429
+ const { heading, message, hint: hint2 } = messages[state];
80360
80430
  return `<!doctype html>
80361
80431
  <html lang="en">
80362
80432
  <head>
@@ -80370,7 +80440,7 @@ function loginPage(state) {
80370
80440
  <main>
80371
80441
  <h1>${heading}</h1>
80372
80442
  <p>${message}</p>
80373
- <p class="hint">${hint}</p>
80443
+ <p class="hint">${hint2}</p>
80374
80444
  </main>
80375
80445
  </body>
80376
80446
  </html>`;
@@ -81626,9 +81696,9 @@ function dockerBuild(args) {
81626
81696
 
81627
81697
  // src/cli/init.ts
81628
81698
  var import_node_fs8 = require("node:fs");
81629
- var import_node_path13 = require("node:path");
81630
- var import_node_util2 = require("node:util");
81631
- var import_yaml5 = __toESM(require_dist());
81699
+ var import_node_path14 = require("node:path");
81700
+ var import_node_util3 = require("node:util");
81701
+ var import_yaml6 = __toESM(require_dist());
81632
81702
 
81633
81703
  // src/cli/init-detect.ts
81634
81704
  var import_node_fs7 = require("node:fs");
@@ -81893,199 +81963,98 @@ function setupSignals(drafted) {
81893
81963
  return Object.keys(packages).length > 0 || signals.configNames ? parsed2.data : null;
81894
81964
  }
81895
81965
 
81896
- // src/cli/init.ts
81897
- async function initCommand(argv, ctx) {
81898
- const { yes, force } = parseInitArgs(argv);
81899
- if (!yes && !ctx.interactive)
81966
+ // src/cli/init-job-line.ts
81967
+ var import_node_path13 = require("node:path");
81968
+ var import_yaml5 = __toESM(require_dist());
81969
+
81970
+ // src/cli/init-wizard.ts
81971
+ function readGiven(question) {
81972
+ if (question.keys)
81973
+ refuseListNumbers(question.flag, question.given, question.keys);
81974
+ const read = question.read(question.given.trim(), true);
81975
+ if ("problem" in read)
81900
81976
  throw new UsageError(
81901
- "agentpicks init asks questions, and this isn't a terminal. Run it on a terminal, or pass --yes to take every detected default."
81902
- );
81903
- const wizard = {
81904
- yes,
81905
- ask: ctx.ask,
81906
- out: ctx.out,
81907
- err: ctx.err,
81908
- detected: detectRepository(ctx.cwd, ctx.io),
81909
- drafting: null
81910
- };
81911
- if (!yes) ctx.out("Press Enter to take the default in brackets.");
81912
- const job = await askJob(wizard);
81913
- let file2;
81914
- if ("category" in job) file2 = await askCategoryTools(wizard, job.category);
81915
- else {
81916
- wizard.drafting = devtuneDrafting(ctx.io, ctx.err);
81917
- file2 = await askCustomJob(wizard, job.line);
81918
- }
81919
- Object.assign(file2, await askTests(wizard, file2.from));
81920
- const agents = await askAgents(wizard);
81921
- if (agents) file2.agents = agents;
81922
- const runs = await ask(wizard, {
81923
- label: "Runs per agent and stack",
81924
- fallback: "1",
81925
- read: (answer) => /^[1-9]\d*$/.test(answer) && Number(answer) <= 100 ? { value: Number(answer) } : { problem: "Give a whole number of runs, 1 to 100." }
81926
- });
81927
- if (runs !== 1) file2.runs = runs;
81928
- const dir = (0, import_node_path13.join)(wizard.detected.root, SETUPS_DIR);
81929
- const text3 = `${SCHEMA_LINE}
81930
- ${(0, import_yaml5.stringify)(file2)}`;
81931
- const name = await ask(wizard, {
81932
- label: "Name",
81933
- fallback: file2.from ?? slug(file2.job),
81934
- read: (answer) => {
81935
- if (!/^[a-z0-9][a-z0-9-]{0,62}$/.test(answer))
81936
- return {
81937
- problem: "A name is lowercase letters, digits and hyphens, such as error-tracking."
81938
- };
81939
- const path2 = setupPath(dir, answer);
81940
- if ((0, import_node_fs8.existsSync)(path2) && !force)
81941
- return {
81942
- problem: `${(0, import_node_path13.relative)(ctx.cwd, path2)} exists. Choose another name, or pass --force to replace it.`
81943
- };
81944
- const checked = checkSetupText(path2, text3);
81945
- return checked.problems.length > 0 ? {
81946
- problem: checked.problems.map((p) => `${p.field}: ${p.message}`).join("\n")
81947
- } : { value: answer };
81948
- }
81949
- });
81950
- const path = setupPath(dir, name);
81951
- writeSetup(dir, path, text3, force, ctx.cwd);
81952
- const shown3 = (0, import_node_path13.relative)(ctx.cwd, path) || path;
81953
- ctx.out("");
81954
- ctx.out(`Wrote ${shown3}:`);
81955
- ctx.out("");
81956
- for (const line2 of text3.trimEnd().split("\n").slice(1)) ctx.out(` ${line2}`);
81957
- ctx.out("");
81958
- if (!file2.agents)
81959
- ctx.out(
81960
- "It names no agents, so run uses the one agent installed where it runs."
81961
- );
81962
- const custom2 = checkSetupText(path, text3).setup.customReason !== null;
81963
- if (ctx.io.env.AGENTPICKS_NO_UPLOAD)
81964
- ctx.out(`Run it with: agentpicks run ${name}`);
81965
- else if (!signedIn(ctx.io)) {
81966
- ctx.out(`Run it with: agentpicks run ${name} --no-upload`);
81967
- ctx.out(
81968
- `That needs no DevTune account. To upload its runs to DevTune, sign in with agentpicks login${custom2 ? `, then run agentpicks push ${name}` : ""}.`
81977
+ `${question.flag}: ${read.problem}${question.keys ? ` List the keys with: ${question.keys}` : ""}`
81969
81978
  );
81970
- } else
81971
- ctx.out(
81972
- custom2 ? `To upload its runs, first run: agentpicks push ${name}, then agentpicks run ${name}. To keep bundles on this machine only, run: agentpicks run ${name} --no-upload.` : `Run it with: agentpicks run ${name}`
81973
- );
81974
- return 0;
81979
+ return read.value;
81975
81980
  }
81976
- function signedIn(io) {
81977
- try {
81978
- devtuneTarget(io);
81979
- return true;
81980
- } catch {
81981
- return false;
81982
- }
81983
- }
81984
- function parseInitArgs(argv) {
81985
- try {
81986
- const { values } = (0, import_node_util2.parseArgs)({
81987
- args: argv,
81988
- strict: true,
81989
- allowPositionals: false,
81990
- options: {
81991
- yes: { type: "boolean", short: "y", default: false },
81992
- force: { type: "boolean", default: false }
81993
- }
81994
- });
81995
- return { yes: values.yes, force: values.force };
81996
- } catch (error62) {
81981
+ function refuseListNumbers(flag, value, keys) {
81982
+ const number4 = entries(value).find((entry) => /^\d+(-\d+)?$/.test(entry));
81983
+ if (number4 !== void 0)
81997
81984
  throw new UsageError(
81998
- error62 instanceof Error ? error62.message : String(error62)
81985
+ `${flag} takes keys, not list numbers such as ${number4}. Give them from: ${keys}`
81999
81986
  );
82000
- }
82001
81987
  }
82002
81988
  async function ask(wizard, question) {
81989
+ if (question.given !== void 0)
81990
+ return readGiven({ ...question, given: question.given });
82003
81991
  if (wizard.yes) {
82004
81992
  if (question.fallback === null)
82005
81993
  throw new UsageError(
82006
81994
  `agentpicks init --yes ${question.missing ?? `has no default for ${question.label.toLowerCase()}. Run agentpicks init on a terminal to answer it.`}`
82007
81995
  );
82008
- const read = question.read(question.fallback);
81996
+ const read = question.read(question.fallback, false);
82009
81997
  if ("problem" in read) throw new UsageError(read.problem);
82010
81998
  return read.value;
82011
81999
  }
82000
+ if (!wizard.interactive) {
82001
+ const asked = `agentpicks init can't ask "${question.label}" without a terminal`;
82002
+ if (question.fallback !== null)
82003
+ throw new UsageError(
82004
+ `${asked}. Pass ${question.flag ? `${question.flag}, or --yes` : "--yes"} to take its default.`
82005
+ );
82006
+ throw new UsageError(
82007
+ `${asked}, and ${question.missing ?? "it has no default. Answer it on a terminal."}${question.flag ? ` Or pass ${question.flag}.` : ""}`
82008
+ );
82009
+ }
82010
+ hint(wizard);
82012
82011
  for (; ; ) {
82013
82012
  const shown3 = question.fallback === null ? "" : ` [${question.fallback}]`;
82014
82013
  const answer = (await wizard.ask(`${question.label}${shown3}: `)).trim() || question.fallback || "";
82015
- const read = question.read(answer);
82014
+ const read = question.read(answer, false);
82016
82015
  if ("value" in read) return read.value;
82017
82016
  wizard.err(read.problem);
82018
82017
  }
82019
82018
  }
82019
+ function hint(wizard) {
82020
+ if (wizard.hinted) return;
82021
+ wizard.out("Press Enter to take the default in brackets.");
82022
+ wizard.hinted = true;
82023
+ }
82024
+ function showNumbered(wizard, given, title, items, columns2 = items.length > 10 ? 3 : 1) {
82025
+ if (wizard.yes || !wizard.interactive || given !== void 0) return;
82026
+ hint(wizard);
82027
+ wizard.out(title);
82028
+ const rows = Math.ceil(items.length / columns2);
82029
+ const width = Math.max(...items.map((item) => item.length));
82030
+ for (let row = 0; row < rows; row++) {
82031
+ const cells = [];
82032
+ for (let column = 0; column < columns2; column++) {
82033
+ const i = column * rows + row;
82034
+ const item = items[i];
82035
+ if (item !== void 0)
82036
+ cells.push(`${String(i + 1).padStart(2)} ${item.padEnd(width)}`);
82037
+ }
82038
+ wizard.out(` ${cells.join(" ").trimEnd()}`);
82039
+ }
82040
+ }
82041
+ var pickKey = (answer, keys) => /^\d+$/.test(answer) ? keys[Number(answer) - 1] ?? null : keys.includes(answer) ? answer : null;
82020
82042
  var entries = (answer) => answer.split(",").map((entry) => entry.trim()).filter(Boolean);
82043
+ var withRanges = (answer, count) => entries(answer).flatMap((entry) => {
82044
+ const range = /^(\d+)-(\d+)$/.exec(entry);
82045
+ if (!range) return [entry];
82046
+ const [from, to] = [Number(range[1]), Number(range[2])];
82047
+ return from >= 1 && from <= to && to <= count ? Array.from({ length: to - from + 1 }, (_, i) => String(from + i)) : [entry];
82048
+ });
82021
82049
  var badLength = (text3) => {
82022
82050
  const problem = requestTextProblem(text3);
82023
82051
  return problem === "too_short" || problem === "too_long";
82024
82052
  };
82025
- async function askJob(wizard) {
82026
- const detected = wizard.detected.tool?.categories[0];
82027
- const index = CATEGORY_REQUESTS.findIndex((c) => c.slug === detected);
82028
- if (!wizard.yes) {
82029
- wizard.out("Categories:");
82030
- CATEGORY_REQUESTS.forEach(
82031
- (category, i) => wizard.out(` ${String(i + 1).padStart(2)} ${category.name}`)
82032
- );
82033
- }
82034
- return ask(wizard, {
82035
- label: "Job: a category number, or your own job line",
82036
- fallback: index >= 0 ? String(index + 1) : null,
82037
- missing: "can't choose a job: neither package.json nor the git remote names a catalogue tool. Run agentpicks init on a terminal to choose one.",
82038
- read: (answer) => {
82039
- const count = CATEGORY_REQUESTS.length;
82040
- if (/^\d+$/.test(answer)) {
82041
- const category2 = CATEGORY_REQUESTS[Number(answer) - 1];
82042
- return category2 ? { value: { category: category2.slug } } : {
82043
- problem: `Choose a category from 1 to ${count}, or write a job line.`
82044
- };
82045
- }
82046
- const category = findCategoryRequests(answer);
82047
- if (category) return { value: { category: category.slug } };
82048
- if (!/\s/.test(answer) || // A new job line meets a request's length; the guard is resolveSetup's, which names the field.
82049
- badLength(answer))
82050
- return {
82051
- problem: `Choose a category from 1 to ${count}, or write the job as a line of ${SETUP_REQUEST_MIN_LENGTH} to ${SETUP_TEXT_MAX_LENGTH} characters, such as Add feature flags.`
82052
- };
82053
- return { value: { line: answer } };
82054
- }
82055
- });
82056
- }
82057
- async function askCategoryTools(wizard, category) {
82058
- const keys = CATEGORY_TOOLS[category] ?? [];
82059
- const detected = wizard.detected.tool?.key;
82060
- const own2 = await ask(wizard, {
82061
- label: `Your tool: a ${category} tool key, or none`,
82062
- fallback: detected && keys.includes(detected) ? detected : "none",
82063
- read: (answer) => answer === "none" ? { value: null } : keys.includes(answer) ? { value: answer } : {
82064
- problem: `${category} has no tool ${answer}. Use one of ${keys.join(", ")}, or none.`
82065
- }
82066
- });
82067
- const competitors = await ask(wizard, {
82068
- label: `Competitors: ${category} tool keys separated by commas, or all`,
82069
- fallback: "all",
82070
- read: (answer) => {
82071
- if (answer === "all") return { value: null };
82072
- const chosen = [...new Set(entries(answer))];
82073
- const unknown2 = chosen.find((key) => !keys.includes(key) || key === own2);
82074
- if (!unknown2 && chosen.length > SETUP_MAX_COMPETITORS)
82075
- return {
82076
- problem: `List at most ${SETUP_MAX_COMPETITORS} competitors, or all.`
82077
- };
82078
- return unknown2 ? {
82079
- problem: unknown2 === own2 ? `${own2} is your tool. List only competitors.` : `${category} has no tool ${unknown2}. Use ${keys.join(", ")}, or all.`
82080
- } : { value: chosen };
82081
- }
82082
- });
82083
- const tools = {
82084
- ...own2 ? { own: own2 } : {},
82085
- ...competitors ? { competitors } : {}
82086
- };
82087
- return { from: category, ...own2 || competitors ? { tools } : {} };
82053
+ function slug(text3) {
82054
+ return text3.normalize("NFKD").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 63).replace(/-+$/, "") || "setup";
82088
82055
  }
82056
+
82057
+ // src/cli/init-job-line.ts
82089
82058
  var INTENTS = ["add", "recommend", "hosted"];
82090
82059
  async function askCustomJob(wizard, line2) {
82091
82060
  const drafted = await wizard.drafting?.job(line2) ?? null;
@@ -82113,8 +82082,15 @@ async function askCustomJob(wizard, line2) {
82113
82082
  (0, import_yaml5.stringify)(file2)
82114
82083
  );
82115
82084
  if (checked.problems.length === 0) return file2;
82116
- for (const problem of checked.problems)
82117
- wizard.err(`${problem.field}: ${problem.message}`);
82085
+ const problems = checked.problems.map(
82086
+ (problem) => `${problem.field}: ${problem.message}`
82087
+ );
82088
+ if (wizard.yes)
82089
+ throw new UsageError(
82090
+ `${problems.join("\n")}
82091
+ Run agentpicks init on a terminal to answer the requests and tools, or write the setup against agentpicks schema.`
82092
+ );
82093
+ for (const problem of problems) wizard.err(problem);
82118
82094
  wizard.err("Answer the requests and tools again.");
82119
82095
  }
82120
82096
  }
@@ -82216,33 +82192,346 @@ async function toolWithSignals(wizard, tool, job, others, toolDrafts, detected)
82216
82192
  signals: { packages: { npm: packages } }
82217
82193
  };
82218
82194
  }
82195
+
82196
+ // src/cli/init.ts
82197
+ async function initCommand(argv, ctx) {
82198
+ const flags = parseInitArgs(argv);
82199
+ const { yes, force } = flags;
82200
+ const wizard = {
82201
+ yes,
82202
+ interactive: Boolean(ctx.interactive),
82203
+ flags,
82204
+ cwd: ctx.cwd,
82205
+ ask: ctx.ask,
82206
+ out: ctx.out,
82207
+ err: ctx.err,
82208
+ detected: detectRepository(ctx.cwd, ctx.io),
82209
+ drafting: null,
82210
+ hinted: false
82211
+ };
82212
+ checkFlags(wizard);
82213
+ const job = await askJob(wizard);
82214
+ let file2;
82215
+ if ("category" in job) file2 = await askCategoryTools(wizard, job.category);
82216
+ else if (flags.tool !== void 0 || flags.competitors !== void 0)
82217
+ throw new UsageError(
82218
+ `--${flags.tool !== void 0 ? "tool" : "competitors"} answers a category's questions, and ${job.line} is a job line. Pass --category, or leave it out.`
82219
+ );
82220
+ else if (!yes && !wizard.interactive)
82221
+ throw new UsageError(
82222
+ "agentpicks init can't ask a job line's requests and tools without a terminal, and they have no flags. Pass --yes to take DevTune's drafts, which needs a sign-in, or write the setup against agentpicks schema."
82223
+ );
82224
+ else {
82225
+ wizard.drafting = devtuneDrafting(ctx.io, ctx.err);
82226
+ file2 = await askCustomJob(wizard, job.line);
82227
+ }
82228
+ Object.assign(file2, await askTests(wizard, file2.from));
82229
+ const agents = await ask(wizard, agentsQuestion(wizard));
82230
+ if (agents) file2.agents = agents;
82231
+ const runs = await ask(wizard, runsQuestion(wizard));
82232
+ if (runs !== 1) file2.runs = runs;
82233
+ const dir = (0, import_node_path14.join)(wizard.detected.root, SETUPS_DIR);
82234
+ const text3 = `${SCHEMA_LINE}
82235
+ ${(0, import_yaml6.stringify)(file2)}`;
82236
+ const name = await ask(
82237
+ wizard,
82238
+ nameQuestion(wizard, file2.from ?? slug(file2.job), (answer) => {
82239
+ const checked = checkSetupText(setupPath(dir, answer), text3);
82240
+ return checked.problems.length > 0 ? {
82241
+ problem: checked.problems.map((p) => `${p.field}: ${p.message}`).join("\n")
82242
+ } : { value: answer };
82243
+ })
82244
+ );
82245
+ const path = setupPath(dir, name);
82246
+ writeSetup(dir, path, text3, force, ctx.cwd);
82247
+ const shown3 = (0, import_node_path14.relative)(ctx.cwd, path) || path;
82248
+ ctx.out("");
82249
+ ctx.out(`Wrote ${shown3}:`);
82250
+ ctx.out("");
82251
+ for (const line2 of text3.trimEnd().split("\n").slice(1)) ctx.out(` ${line2}`);
82252
+ ctx.out("");
82253
+ if (file2.from)
82254
+ ctx.out(
82255
+ `To write the same setup in another repository: ${initAgain(file2, name)}`
82256
+ );
82257
+ if (!file2.agents)
82258
+ ctx.out(
82259
+ "It names no agents, so run uses the one agent installed where it runs."
82260
+ );
82261
+ const custom2 = checkSetupText(path, text3).setup.customReason !== null;
82262
+ if (ctx.io.env.AGENTPICKS_NO_UPLOAD)
82263
+ ctx.out(`Run it with: agentpicks run ${name}`);
82264
+ else if (!signedIn(ctx.io)) {
82265
+ ctx.out(`Run it with: agentpicks run ${name} --no-upload`);
82266
+ ctx.out(
82267
+ `That needs no DevTune account. To upload its runs to DevTune, sign in with agentpicks login${custom2 ? `, then run agentpicks push ${name}` : ""}.`
82268
+ );
82269
+ } else
82270
+ ctx.out(
82271
+ custom2 ? `To upload its runs, first run: agentpicks push ${name}, then agentpicks run ${name}. To keep bundles on this machine only, run: agentpicks run ${name} --no-upload.` : `Run it with: agentpicks run ${name}`
82272
+ );
82273
+ return 0;
82274
+ }
82275
+ function signedIn(io) {
82276
+ try {
82277
+ devtuneTarget(io);
82278
+ return true;
82279
+ } catch {
82280
+ return false;
82281
+ }
82282
+ }
82283
+ function initAgain(file2, name) {
82284
+ const { own: own2, competitors } = file2.tools ?? {};
82285
+ return [
82286
+ "agentpicks init",
82287
+ `--category ${file2.from}`,
82288
+ `--tool ${typeof own2 === "string" ? own2 : "none"}`,
82289
+ ...competitors ? [`--competitors ${competitors.join(",")}`] : [],
82290
+ ...file2.repo ? ["--repo ."] : (file2.stacks ?? []).map((stack) => `--stack ${stack}`),
82291
+ ...(file2.agents ?? ["any"]).map((agent) => `--agent ${agent}`),
82292
+ ...file2.runs ? [`--runs ${file2.runs}`] : [],
82293
+ `--name ${name}`,
82294
+ "--yes"
82295
+ ].join(" ");
82296
+ }
82297
+ function parseInitArgs(argv) {
82298
+ let values;
82299
+ try {
82300
+ ({ values } = (0, import_node_util3.parseArgs)({
82301
+ args: argv,
82302
+ strict: true,
82303
+ allowPositionals: false,
82304
+ options: {
82305
+ yes: { type: "boolean", short: "y", default: false },
82306
+ force: { type: "boolean", default: false },
82307
+ category: { type: "string" },
82308
+ job: { type: "string" },
82309
+ tool: { type: "string" },
82310
+ competitors: { type: "string" },
82311
+ repo: { type: "string" },
82312
+ stack: { type: "string", multiple: true, default: [] },
82313
+ agent: { type: "string", multiple: true, default: [] },
82314
+ runs: { type: "string" },
82315
+ name: { type: "string" }
82316
+ }
82317
+ }));
82318
+ } catch (error62) {
82319
+ throw new UsageError(
82320
+ error62 instanceof Error ? error62.message : String(error62)
82321
+ );
82322
+ }
82323
+ if (values.category !== void 0 && values.job !== void 0)
82324
+ throw new UsageError(
82325
+ "Pass --category or --job, not both: a setup tests a category or a job line of its own."
82326
+ );
82327
+ if (values.repo !== void 0 && values.stack.length > 0)
82328
+ throw new UsageError(
82329
+ "Pass --repo or --stack, not both: a setup tests this repository or stacks."
82330
+ );
82331
+ if (values.repo !== void 0 && values.repo !== ".")
82332
+ throw new UsageError(
82333
+ `--repo takes only . (this repository's committed files), not ${values.repo}.`
82334
+ );
82335
+ if (values.stack.some((stack) => entries(stack).includes(".")))
82336
+ throw new UsageError(
82337
+ "--stack takes stack slugs. To test this repository's committed files, pass --repo ."
82338
+ );
82339
+ return values;
82340
+ }
82341
+ function checkFlags(wizard) {
82342
+ const read = (question) => question.given === void 0 ? void 0 : readGiven({ ...question, given: question.given });
82343
+ const job = read(jobQuestion(wizard));
82344
+ const { tool, competitors, stack } = wizard.flags;
82345
+ if (job && "category" in job) {
82346
+ const own2 = read(toolQuestion(wizard, job.category));
82347
+ read(competitorsQuestion(wizard, job.category, own2 ?? null));
82348
+ } else
82349
+ for (const [flag, value] of [
82350
+ ["--tool", tool],
82351
+ ["--competitors", competitors]
82352
+ ])
82353
+ if (value !== void 0)
82354
+ refuseListNumbers(flag, value, "agentpicks catalogue <category>");
82355
+ if (job && stack.length > 0)
82356
+ read(testsQuestion(wizard, "category" in job ? job.category : void 0));
82357
+ else if (stack.length > 0) {
82358
+ const given = stack.join(",");
82359
+ refuseListNumbers("--stack", given, "agentpicks catalogue");
82360
+ const unknown2 = entries(given).find(
82361
+ (slug2) => !findEnvironment(slug2) || isRetiredEnvironment(slug2)
82362
+ );
82363
+ if (unknown2 !== void 0)
82364
+ throw new UsageError(
82365
+ `--stack: ${unknown2} isn't a stack. Give stack slugs. List the keys with: agentpicks catalogue`
82366
+ );
82367
+ }
82368
+ read(agentsQuestion(wizard));
82369
+ read(runsQuestion(wizard));
82370
+ read(nameQuestion(wizard, null, (answer) => ({ value: answer })));
82371
+ }
82372
+ async function askJob(wizard) {
82373
+ const question = jobQuestion(wizard);
82374
+ showNumbered(
82375
+ wizard,
82376
+ question.given,
82377
+ "DevTune's public categories. Choose one to write a setup that runs its tests on this machine:",
82378
+ CATEGORY_REQUESTS.map((category) => category.name)
82379
+ );
82380
+ return ask(wizard, question);
82381
+ }
82382
+ function jobQuestion(wizard) {
82383
+ const detected = wizard.detected.tool?.categories[0];
82384
+ const index = CATEGORY_REQUESTS.findIndex((c) => c.slug === detected);
82385
+ const { category, job } = wizard.flags;
82386
+ return {
82387
+ label: "Category number, or your own job line",
82388
+ fallback: index >= 0 ? String(index + 1) : null,
82389
+ missing: "can't choose a job: neither package.json nor the git remote names a catalogue tool. Run agentpicks init on a terminal to choose one.",
82390
+ flag: category !== void 0 ? "--category" : job !== void 0 ? "--job" : "--category or --job",
82391
+ given: category ?? job,
82392
+ keys: category !== void 0 ? "agentpicks catalogue" : void 0,
82393
+ read: (answer, flag) => {
82394
+ const read = readJob(answer, flag);
82395
+ if (category !== void 0 && !("value" in read && "category" in read.value))
82396
+ return { problem: `There is no category ${answer}.` };
82397
+ if ("problem" in read) return read;
82398
+ if (job !== void 0 && "category" in read.value)
82399
+ return {
82400
+ problem: `${answer} names a category. Pass it as --category ${read.value.category}.`
82401
+ };
82402
+ return read;
82403
+ }
82404
+ };
82405
+ }
82406
+ function readJob(answer, flag) {
82407
+ const count = CATEGORY_REQUESTS.length;
82408
+ const line2 = `${flag ? "Write" : `Choose a category from 1 to ${count}, or write`} the job as a line of ${SETUP_REQUEST_MIN_LENGTH} to ${SETUP_TEXT_MAX_LENGTH} characters, such as Add feature flags.`;
82409
+ if (/^\d+$/.test(answer)) {
82410
+ const category2 = CATEGORY_REQUESTS[Number(answer) - 1];
82411
+ return category2 ? { value: { category: category2.slug } } : {
82412
+ problem: flag ? line2 : `Choose a category from 1 to ${count}, or write a job line.`
82413
+ };
82414
+ }
82415
+ const category = findCategoryRequests(answer);
82416
+ if (category) return { value: { category: category.slug } };
82417
+ if (!/\s/.test(answer) || // A new job line meets a request's length; the guard is resolveSetup's, which names the field.
82418
+ badLength(answer))
82419
+ return { problem: line2 };
82420
+ return { value: { line: answer } };
82421
+ }
82422
+ async function askCategoryTools(wizard, category) {
82423
+ const { tool, competitors: rivals } = wizard.flags;
82424
+ showNumbered(
82425
+ wizard,
82426
+ tool !== void 0 && rivals !== void 0 ? tool : void 0,
82427
+ `${findCategoryRequests(category)?.name ?? category} tools DevTune tests:`,
82428
+ CATEGORY_TOOLS[category] ?? []
82429
+ );
82430
+ const own2 = await ask(wizard, toolQuestion(wizard, category));
82431
+ const competitors = await ask(
82432
+ wizard,
82433
+ competitorsQuestion(wizard, category, own2)
82434
+ );
82435
+ const tools = {
82436
+ ...own2 ? { own: own2 } : {},
82437
+ ...competitors ? { competitors } : {}
82438
+ };
82439
+ return { from: category, ...own2 || competitors ? { tools } : {} };
82440
+ }
82441
+ function toolQuestion(wizard, category) {
82442
+ const keys = CATEGORY_TOOLS[category] ?? [];
82443
+ return {
82444
+ label: "Your tool: its number, or none",
82445
+ fallback: toolDefault(wizard, category),
82446
+ flag: "--tool",
82447
+ given: wizard.flags.tool,
82448
+ keys: `agentpicks catalogue ${category}`,
82449
+ read: (answer, flag) => {
82450
+ if (answer === "none") return { value: null };
82451
+ const key = pickKey(answer, keys);
82452
+ return key ? { value: key } : {
82453
+ problem: `${answer} isn't on the list. Give ${flag ? "a tool key" : `a number from 1 to ${keys.length}`}, or none.`
82454
+ };
82455
+ }
82456
+ };
82457
+ }
82458
+ function competitorsQuestion(wizard, category, own2) {
82459
+ const keys = CATEGORY_TOOLS[category] ?? [];
82460
+ return {
82461
+ label: "Competitors: their numbers or ranges separated by commas (2, 5-8), or all",
82462
+ fallback: "all",
82463
+ flag: "--competitors",
82464
+ given: wizard.flags.competitors,
82465
+ keys: `agentpicks catalogue ${category}`,
82466
+ read: (answer, flag) => {
82467
+ if (answer === "all") return { value: null };
82468
+ const give = `Give ${flag ? "tool keys" : `numbers from 1 to ${keys.length}`}, or all.`;
82469
+ const chosen = [];
82470
+ const given = withRanges(answer, keys.length);
82471
+ if (given.length === 0) return { problem: give };
82472
+ for (const entry of given) {
82473
+ const key = pickKey(entry, keys);
82474
+ if (!key) return { problem: `${entry} isn't on the list. ${give}` };
82475
+ if (key === own2)
82476
+ return {
82477
+ problem: wizard.yes && wizard.flags.tool === void 0 ? `${own2} is your tool, as this repository names it. Pass --tool none, or leave ${own2} out.` : `${own2} is your tool. List only competitors.`
82478
+ };
82479
+ if (!chosen.includes(key)) chosen.push(key);
82480
+ }
82481
+ return chosen.length > SETUP_MAX_COMPETITORS ? {
82482
+ problem: `List at most ${SETUP_MAX_COMPETITORS} competitors, or all.`
82483
+ } : { value: chosen };
82484
+ }
82485
+ };
82486
+ }
82487
+ function toolDefault(wizard, category) {
82488
+ const detected = wizard.detected.tool?.key;
82489
+ return detected && (CATEGORY_TOOLS[category] ?? []).includes(detected) ? detected : "none";
82490
+ }
82219
82491
  async function askTests(wizard, from) {
82220
- const runsIn = from ?? "job-";
82221
- const choices = ENVIRONMENTS.filter(
82222
- (env) => !isRetiredEnvironment(env.slug) && environmentRunsIn(env.slug, runsIn)
82223
- ).map((env) => env.slug);
82492
+ const question = testsQuestion(wizard, from);
82493
+ showNumbered(
82494
+ wizard,
82495
+ question.given,
82496
+ "Stacks: starter apps a run can build in instead of this repository:",
82497
+ setupEnvironments(from ?? "job-").map((env) => env.name),
82498
+ 1
82499
+ );
82500
+ return ask(wizard, question);
82501
+ }
82502
+ function testsQuestion(wizard, from) {
82503
+ const choices = setupEnvironments(from ?? "job-").map((env) => env.slug);
82224
82504
  const { git, stacks, root } = wizard.detected;
82225
- const detected = stacks.filter((stack) => choices.includes(stack));
82226
- return ask(wizard, {
82227
- label: "Test in your repository (.) or in stacks separated by commas",
82505
+ const detected = stacks.filter((stack2) => choices.includes(stack2));
82506
+ const { repo, stack } = wizard.flags;
82507
+ return {
82508
+ label: "Test in this repository's committed files (.), or in stacks: their numbers or ranges separated by commas (1, 3-4)",
82228
82509
  fallback: git ? "." : detected.join(", ") || null,
82229
82510
  missing: `found nothing to test in: ${root} isn't a git repository, and its package.json and lockfiles name no framework of a stack (${choices.join(", ")}). Run it in a git repository, or on a terminal to choose stacks.`,
82230
- read: (answer) => {
82511
+ flag: repo !== void 0 ? "--repo" : stack.length > 0 || !git ? "--stack" : "--repo . or --stack",
82512
+ given: repo ?? (stack.length > 0 ? stack.join(",") : void 0),
82513
+ keys: repo === void 0 ? `agentpicks catalogue${from ? ` ${from}` : ""}` : void 0,
82514
+ read: (answer, flag) => {
82231
82515
  if (answer === ".") return { value: { repo: "." } };
82232
- const chosen = [...new Set(entries(answer))];
82233
- const unknown2 = chosen.find((stack) => !choices.includes(stack));
82234
- if (chosen.length === 0 || unknown2)
82516
+ const given = withRanges(answer, choices.length);
82517
+ const chosen = [
82518
+ ...new Set(given.map((entry) => pickKey(entry, choices)))
82519
+ ];
82520
+ const unknown2 = given.find((entry) => !pickKey(entry, choices));
82521
+ if (given.length === 0 || unknown2)
82235
82522
  return {
82236
- problem: `${unknown2 ?? "Nothing"} isn't a stack ${from ? `for ${from}` : "for your own job"}. Give . or stacks from ${choices.join(", ")}.`
82523
+ problem: `${unknown2 ?? "Nothing"} isn't a stack ${from ? `for ${from}` : "for your own job"}. Give ${flag ? "stack slugs" : `. or numbers from 1 to ${choices.length}`}.`
82237
82524
  };
82238
- return { value: { stacks: chosen } };
82525
+ return { value: { stacks: chosen.filter((stack2) => stack2 !== null) } };
82239
82526
  }
82240
- });
82527
+ };
82241
82528
  }
82242
- async function askAgents(wizard) {
82243
- return ask(wizard, {
82529
+ function agentsQuestion(wizard) {
82530
+ return {
82244
82531
  label: "Agents separated by commas, or any",
82245
82532
  fallback: wizard.detected.agents.join(", ") || "any",
82533
+ flag: "--agent",
82534
+ given: wizard.flags.agent.length > 0 ? wizard.flags.agent.join(",") : void 0,
82246
82535
  read: (answer) => {
82247
82536
  if (answer === "any") return { value: null };
82248
82537
  const chosen = entries(answer).map(
@@ -82258,31 +82547,57 @@ async function askAgents(wizard) {
82258
82547
  };
82259
82548
  return { value: unique };
82260
82549
  }
82261
- });
82550
+ };
82262
82551
  }
82263
- function slug(text3) {
82264
- return text3.normalize("NFKD").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 63).replace(/-+$/, "") || "setup";
82552
+ function runsQuestion(wizard) {
82553
+ return {
82554
+ label: "Runs per agent and stack",
82555
+ fallback: "1",
82556
+ flag: "--runs",
82557
+ given: wizard.flags.runs,
82558
+ read: (answer) => /^[1-9]\d*$/.test(answer) && Number(answer) <= 100 ? { value: Number(answer) } : { problem: "Give a whole number of runs, 1 to 100." }
82559
+ };
82560
+ }
82561
+ function nameQuestion(wizard, fallback, written) {
82562
+ return {
82563
+ label: `Setup name, saved as ${SETUPS_DIR}/<name>.yaml`,
82564
+ fallback,
82565
+ flag: "--name",
82566
+ given: wizard.flags.name,
82567
+ read: (answer) => {
82568
+ if (!/^[a-z0-9][a-z0-9-]{0,62}$/.test(answer))
82569
+ return {
82570
+ problem: "A name is lowercase letters, digits and hyphens, such as error-tracking."
82571
+ };
82572
+ const path = setupPath((0, import_node_path14.join)(wizard.detected.root, SETUPS_DIR), answer);
82573
+ if ((0, import_node_fs8.existsSync)(path) && !wizard.flags.force)
82574
+ return {
82575
+ problem: `${(0, import_node_path14.relative)(wizard.cwd, path)} exists. Choose another name, or pass --force to replace it.`
82576
+ };
82577
+ return written(answer);
82578
+ }
82579
+ };
82265
82580
  }
82266
82581
  function setupPath(dir, name) {
82267
- 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`);
82582
+ return [".yaml", ".yml"].map((ext) => (0, import_node_path14.join)(dir, `${name}${ext}`)).find(import_node_fs8.existsSync) ?? (0, import_node_path14.join)(dir, `${name}.yaml`);
82268
82583
  }
82269
82584
  function writeSetup(dir, path, text3, force, cwd) {
82270
82585
  try {
82271
82586
  writeSetupText(dir, path, text3, {
82272
82587
  replace: force,
82273
- shown: (target) => (0, import_node_path13.relative)(cwd, target) || target
82588
+ shown: (target) => (0, import_node_path14.relative)(cwd, target) || target
82274
82589
  });
82275
82590
  } catch (error62) {
82276
82591
  if (error62.code === "EEXIST")
82277
82592
  throw new UsageError(
82278
- `${(0, import_node_path13.relative)(cwd, path)} appeared while init ran. Run init again with another name, or pass --force to replace it.`
82593
+ `${(0, import_node_path14.relative)(cwd, path)} appeared while init ran. Run init again with another name, or pass --force to replace it.`
82279
82594
  );
82280
82595
  throw error62;
82281
82596
  }
82282
82597
  }
82283
82598
 
82284
82599
  // src/cli/list-command.ts
82285
- var import_node_path14 = require("node:path");
82600
+ var import_node_path15 = require("node:path");
82286
82601
  async function listCommand(argv, ctx) {
82287
82602
  if (argv.length > 0)
82288
82603
  throw new UsageError(
@@ -82305,7 +82620,7 @@ async function listCommand(argv, ctx) {
82305
82620
  if (devtune)
82306
82621
  return linkedTable(readSetupFiles(root, heldTools(devtune)), devtune, ctx);
82307
82622
  if (files.length === 0) {
82308
- ctx.out(`${(0, import_node_path14.join)(root, SETUPS_DIR)} holds no setup files. ${WRITE_ONE}`);
82623
+ ctx.out(`${(0, import_node_path15.join)(root, SETUPS_DIR)} holds no setup files. ${WRITE_ONE}`);
82309
82624
  return 0;
82310
82625
  }
82311
82626
  printSetups(
@@ -82610,8 +82925,8 @@ function logoPlayer(env, stdout) {
82610
82925
 
82611
82926
  // src/cli/pull-command.ts
82612
82927
  var import_node_fs9 = require("node:fs");
82613
- var import_node_path15 = require("node:path");
82614
- var import_node_util3 = require("node:util");
82928
+ var import_node_path16 = require("node:path");
82929
+ var import_node_util4 = require("node:util");
82615
82930
  async function pullCommand(argv, ctx) {
82616
82931
  const { values, positionals } = parse5(argv);
82617
82932
  if (positionals.length > 1)
@@ -82650,7 +82965,7 @@ async function pullCommand(argv, ctx) {
82650
82965
  }
82651
82966
  function parse5(argv) {
82652
82967
  try {
82653
- return (0, import_node_util3.parseArgs)({
82968
+ return (0, import_node_util4.parseArgs)({
82654
82969
  args: argv,
82655
82970
  strict: true,
82656
82971
  allowPositionals: true,
@@ -82662,7 +82977,7 @@ function parse5(argv) {
82662
82977
  );
82663
82978
  }
82664
82979
  }
82665
- var shown = (path, ctx) => (0, import_node_path15.relative)(ctx.cwd, path) || path;
82980
+ var shown = (path, ctx) => (0, import_node_path16.relative)(ctx.cwd, path) || path;
82666
82981
  function pullOne(setup, root, files, devtune, force, ctx) {
82667
82982
  const name = devtune.names.get(setup.id);
82668
82983
  const linked = files.filter((file2) => file2.content?.id === setup.id);
@@ -82673,7 +82988,7 @@ function pullOne(setup, root, files, devtune, force, ctx) {
82673
82988
  return false;
82674
82989
  }
82675
82990
  const [local] = linked;
82676
- const path = local?.path ?? (0, import_node_path15.join)(root, SETUPS_DIR, `${name}.yaml`);
82991
+ const path = local?.path ?? (0, import_node_path16.join)(root, SETUPS_DIR, `${name}.yaml`);
82677
82992
  if (local) {
82678
82993
  const state = syncState(local.content, setup);
82679
82994
  if (state === "in_sync") {
@@ -82702,7 +83017,7 @@ function pullOne(setup, root, files, devtune, force, ctx) {
82702
83017
  }
82703
83018
  try {
82704
83019
  writeSetupText(
82705
- (0, import_node_path15.join)(root, SETUPS_DIR),
83020
+ (0, import_node_path16.join)(root, SETUPS_DIR),
82706
83021
  path,
82707
83022
  `${SCHEMA_LINE}
82708
83023
  ${linkedSetupYaml(mapped.file, {
@@ -82731,7 +83046,7 @@ ${linkedSetupYaml(mapped.file, {
82731
83046
  }
82732
83047
 
82733
83048
  // src/cli/push-command.ts
82734
- var import_node_path16 = require("node:path");
83049
+ var import_node_path17 = require("node:path");
82735
83050
  async function pushCommand(argv, ctx) {
82736
83051
  const flag = argv.find((arg) => arg.startsWith("-"));
82737
83052
  if (flag)
@@ -82752,7 +83067,7 @@ async function pushCommand(argv, ctx) {
82752
83067
  return failed === 0 ? 0 : 1;
82753
83068
  }
82754
83069
  async function pushOne(file2, devtune, ctx) {
82755
- const shown3 = (0, import_node_path16.relative)(ctx.cwd, file2.path) || file2.path;
83070
+ const shown3 = (0, import_node_path17.relative)(ctx.cwd, file2.path) || file2.path;
82756
83071
  const content = file2.content;
82757
83072
  if (!file2.setup || !content) {
82758
83073
  for (const problem of file2.problems)
@@ -82776,7 +83091,7 @@ async function pushOne(file2, devtune, ctx) {
82776
83091
  return false;
82777
83092
  }
82778
83093
  }
82779
- const repositoryStacks = !current && file2.setup.repo ? detectStacks((0, import_node_path16.resolve)(file2.root, file2.setup.repo.path)).stacks : void 0;
83094
+ const repositoryStacks = !current && file2.setup.repo ? detectStacks((0, import_node_path17.resolve)(file2.root, file2.setup.repo.path)).stacks : void 0;
82780
83095
  let saved;
82781
83096
  try {
82782
83097
  const request2 = pushRequest(
@@ -82811,7 +83126,7 @@ async function pushOne(file2, devtune, ctx) {
82811
83126
  id: saved.setup.id,
82812
83127
  setupDigest: saved.snapshotDigest
82813
83128
  },
82814
- (path) => (0, import_node_path16.relative)(ctx.cwd, path) || path
83129
+ (path) => (0, import_node_path17.relative)(ctx.cwd, path) || path
82815
83130
  );
82816
83131
  ctx.out(
82817
83132
  current ? `Pushed ${shown3} to DevTune setup ${devtune.names.get(current.id)}.` : `Pushed ${shown3} to DevTune, and linked ${shown3} to the setup it saved.`
@@ -82835,7 +83150,7 @@ async function linkExisting(file2, content, ctx, shown3, repositoryStacks) {
82835
83150
  id: existing.id,
82836
83151
  setupDigest: existing.snapshot_digest
82837
83152
  },
82838
- (path) => (0, import_node_path16.relative)(ctx.cwd, path) || path
83153
+ (path) => (0, import_node_path17.relative)(ctx.cwd, path) || path
82839
83154
  );
82840
83155
  ctx.out(
82841
83156
  `DevTune already holds ${shown3} as setup ${after.names.get(existing.id)}; linked ${shown3} to it.`
@@ -82882,8 +83197,8 @@ function sameSubject(setup, content) {
82882
83197
 
82883
83198
  // src/cli/results.ts
82884
83199
  var import_node_fs10 = require("node:fs");
82885
- var import_node_path17 = require("node:path");
82886
- var import_node_util4 = require("node:util");
83200
+ var import_node_path18 = require("node:path");
83201
+ var import_node_util5 = require("node:util");
82887
83202
 
82888
83203
  // src/assets/watch-pick-rule.ts
82889
83204
  var POSIX_CLASSES = {
@@ -83132,7 +83447,7 @@ function resultsCommand(argv, ctx) {
83132
83447
  const rows = [
83133
83448
  ...new Set(
83134
83449
  dirs.flatMap(
83135
- (dir) => bundleDirs((0, import_node_path17.resolve)(ctx.cwd, dir)).map((bundle) => (0, import_node_path17.resolve)(bundle))
83450
+ (dir) => bundleDirs((0, import_node_path18.resolve)(ctx.cwd, dir)).map((bundle) => (0, import_node_path18.resolve)(bundle))
83136
83451
  )
83137
83452
  )
83138
83453
  ].map(resultRow).sort(
@@ -83148,7 +83463,7 @@ function resultsCommand(argv, ctx) {
83148
83463
  function parseResultsArgs(argv) {
83149
83464
  let parsed2;
83150
83465
  try {
83151
- parsed2 = (0, import_node_util4.parseArgs)({
83466
+ parsed2 = (0, import_node_util5.parseArgs)({
83152
83467
  args: argv,
83153
83468
  strict: true,
83154
83469
  allowPositionals: true,
@@ -83180,7 +83495,7 @@ function resultRow(dir) {
83180
83495
  if (!(error62 instanceof BundleError)) throw error62;
83181
83496
  return {
83182
83497
  dir,
83183
- runId: (0, import_node_path17.basename)(dir),
83498
+ runId: (0, import_node_path18.basename)(dir),
83184
83499
  setup: null,
83185
83500
  agent: null,
83186
83501
  model: null,
@@ -85370,7 +85685,7 @@ function isDockerSandbox(box) {
85370
85685
  }
85371
85686
 
85372
85687
  // src/cli/validate-command.ts
85373
- var import_node_path18 = require("node:path");
85688
+ var import_node_path19 = require("node:path");
85374
85689
  function validateCommand(argv, ctx) {
85375
85690
  const flag = argv.find((arg) => arg.startsWith("-"));
85376
85691
  if (flag)
@@ -85385,7 +85700,7 @@ function validateCommand(argv, ctx) {
85385
85700
  }
85386
85701
  }) : readSetupFiles(root);
85387
85702
  if (files.length === 0) {
85388
- ctx.out(`${(0, import_node_path18.join)(root, SETUPS_DIR)} holds no setup files. ${WRITE_ONE}`);
85703
+ ctx.out(`${(0, import_node_path19.join)(root, SETUPS_DIR)} holds no setup files. ${WRITE_ONE}`);
85389
85704
  return 0;
85390
85705
  }
85391
85706
  let failed = 0;
@@ -85396,7 +85711,7 @@ function validateCommand(argv, ctx) {
85396
85711
  continue;
85397
85712
  }
85398
85713
  if (file2.problems.length === 0) {
85399
- ctx.out(`${(0, import_node_path18.relative)(ctx.cwd, file2.path) || file2.path}: valid`);
85714
+ ctx.out(`${(0, import_node_path19.relative)(ctx.cwd, file2.path) || file2.path}: valid`);
85400
85715
  continue;
85401
85716
  }
85402
85717
  failed++;
@@ -85424,7 +85739,10 @@ var RUNNER = {
85424
85739
  version: package_default.version
85425
85740
  };
85426
85741
  var USAGE = `Usage:
85427
- agentpicks init [--yes] [--force]
85742
+ agentpicks init [--yes] [--force] [--category <category> | --job <line>] [--tool <tool>|none]
85743
+ [--competitors <tool>,...|all] [--repo . | --stack <stack>...]
85744
+ [--agent <agent>...|any] [--runs <n>] [--name <name>]
85745
+ agentpicks catalogue [<category>] [--json]
85428
85746
  agentpicks run [<setup>] [--stack <stack> | --repo <path> [--ref <commit>]]
85429
85747
  [--runs <n>] [--agent claude-code|codex|opencode|pi] [--model <model>]
85430
85748
  [--out <dir>] [--no-upload]
@@ -85446,6 +85764,22 @@ var USAGE = `Usage:
85446
85764
  init Writes a setup file, agentpicks/<name>.yaml, from questions whose defaults come from
85447
85765
  this repository. --yes takes every default without asking. --force replaces a setup
85448
85766
  of the same name. Signed in, DevTune drafts the requests and tools of your own job.
85767
+ Each flag answers one question: --category or --job, --tool, --competitors,
85768
+ --repo . or --stack, --agent, --runs and --name. Flags take keys, never list numbers;
85769
+ --stack and --agent repeat or take a comma list. A question a flag answers isn't
85770
+ asked. A flag value that doesn't read stops init before it asks anything, unless the
85771
+ check needs an earlier answer, such as --competitors against the tool this
85772
+ repository names, which waits for that question. Off a terminal, a question no flag
85773
+ answers takes its default with --yes, where it has one; without --yes, init stops at
85774
+ it and names its flag. A job line's requests and tools
85775
+ have no flags: answer them on a terminal or, signed in, take DevTune's drafts with
85776
+ --yes; off a terminal a job line needs --yes. For a category setup, init ends with
85777
+ the agentpicks init command that writes the same setup in another repository.
85778
+ Typed answers take list numbers or keys; the competitors and stacks answers also
85779
+ take ranges such as 2-4.
85780
+ catalogue Lists the category, tool and stack keys init's flags take: every category and the
85781
+ stacks a job line can run in, or with <category>, its tool keys and stacks. --json
85782
+ prints one JSON object.
85449
85783
  run Tests the coding agent installed here in a fresh Docker container per run, writes
85450
85784
  one bundle per completed run to --out (default ./agentpicks-runs), and uploads it to
85451
85785
  your DevTune project. --no-upload keeps bundles on this machine only, as every run
@@ -85499,11 +85833,12 @@ describes every field.
85499
85833
  `;
85500
85834
  var INTRO = `Test which tools coding agents pick when they build your kind of app.
85501
85835
 
85502
- agentpicks init Write a setup file for this repository
85503
- agentpicks run Run a setup with the coding agent installed here
85504
- agentpicks results Show which tool each run picked
85505
- agentpicks list List this repository's setups and your project's
85506
- agentpicks login Sign in to DevTune to upload runs for its analysis
85836
+ agentpicks init Write a setup file for this repository
85837
+ agentpicks catalogue List the categories, tools and stacks init takes by key
85838
+ agentpicks run Run a setup with the coding agent installed here
85839
+ agentpicks results Show which tool each run picked
85840
+ agentpicks list List this repository's setups and your project's
85841
+ agentpicks login Sign in to DevTune to upload runs for its analysis
85507
85842
 
85508
85843
  Runs need no DevTune account: pass --no-upload to run, or set AGENTPICKS_NO_UPLOAD=1, and
85509
85844
  bundles stay on this machine. To upload them later, sign up at ${signUpUrl()}
@@ -85567,6 +85902,7 @@ async function main(argv, given) {
85567
85902
  if (command === "validate") return validateCommand(rest, ctx);
85568
85903
  if (command === "schema") return schemaCommand(rest, ctx);
85569
85904
  if (command === "results") return resultsCommand(rest, ctx);
85905
+ if (command === "catalogue") return catalogueCommand(rest, ctx);
85570
85906
  ctx.err(`agentpicks has no ${command} command.
85571
85907
 
85572
85908
  ${USAGE}`);
@@ -85596,7 +85932,7 @@ async function runCommand(argv, ctx) {
85596
85932
  );
85597
85933
  const file2 = await runnableSetup(command.setup, ctx);
85598
85934
  if (file2 === null) return 1;
85599
- const shown3 = (0, import_node_path19.relative)(ctx.cwd, file2.path) || file2.path;
85935
+ const shown3 = (0, import_node_path20.relative)(ctx.cwd, file2.path) || file2.path;
85600
85936
  const plan = setupPlan(file2, command.flags, ctx.cwd);
85601
85937
  return runPlan(
85602
85938
  await linkUploads(plan, file2.setup, file2.content, shown3, ctx),
@@ -85636,7 +85972,7 @@ async function pickSetup(ctx) {
85636
85972
  const files = readSetupFiles(root);
85637
85973
  if (files.length === 0) {
85638
85974
  ctx.err(
85639
- `${(0, import_node_path19.join)(root, SETUPS_DIR)} holds no setup files. Write one with: agentpicks init
85975
+ `${(0, import_node_path20.join)(root, SETUPS_DIR)} holds no setup files. Write one with: agentpicks init
85640
85976
 
85641
85977
  Or run a built-in category: agentpicks run --category <category> --stack <stack>.`
85642
85978
  );
@@ -85684,7 +86020,7 @@ async function runPlan(given, ctx, link) {
85684
86020
  const platform = await dockerAccess.platform();
85685
86021
  for (const test of plan.tests) assertStackRuns(test.environment, platform);
85686
86022
  if (repository) assertRepositoryRuns(repository.install, platform);
85687
- const outDir = (0, import_node_path19.resolve)(ctx.cwd, plan.out);
86023
+ const outDir = (0, import_node_path20.resolve)(ctx.cwd, plan.out);
85688
86024
  const { runs } = plan;
85689
86025
  const cells = agentPlans.flatMap(
85690
86026
  (agentPlan, a) => plan.tests.map((test) => ({ agentPlan, a, test }))
@@ -85800,7 +86136,7 @@ async function uploadPrinted(dir, target, ctx, bundle) {
85800
86136
  }
85801
86137
  }
85802
86138
  async function uploadCommand(argv, ctx) {
85803
- const dirs = findBundles((0, import_node_path19.resolve)(ctx.cwd, parseUploadArgs(argv).dir));
86139
+ const dirs = findBundles((0, import_node_path20.resolve)(ctx.cwd, parseUploadArgs(argv).dir));
85804
86140
  let target;
85805
86141
  let uploaded = 0;
85806
86142
  for (const dir of dirs) {
@@ -85926,7 +86262,7 @@ function trackSandboxes(inner) {
85926
86262
  // src/cli.ts
85927
86263
  void main(
85928
86264
  process.argv.slice(2),
85929
- defaultContext((0, import_node_path20.join)(__dirname, "..", "docker"))
86265
+ defaultContext((0, import_node_path21.join)(__dirname, "..", "docker"))
85930
86266
  ).then((code) => {
85931
86267
  process.exitCode = code;
85932
86268
  });