@plune-ai/cli 0.39.7 → 0.39.9

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/dist/index.cjs CHANGED
@@ -1102,168 +1102,26 @@ var ConfigValidationError = class extends Error {
1102
1102
  }
1103
1103
  };
1104
1104
 
1105
- // src/config/env-overrides.ts
1106
- function applyEnvOverrides(config, env) {
1107
- const result = structuredClone(config);
1108
- const all = result.providers ?? [result.provider];
1109
- if (result.providers !== void 0) {
1110
- for (const name of ["PLUNE_PROVIDER", "PLUNE_MODEL"])
1111
- if (env[name] !== void 0)
1112
- throw new ConfigValidationError("Config validation failed", [
1113
- `${name} sets one model, but the config lists ${result.providers.length}: remove it or list a single model`
1114
- ]);
1115
- }
1116
- if (env["PLUNE_PROVIDER"] !== void 0) {
1117
- result.provider.type = env["PLUNE_PROVIDER"];
1118
- }
1119
- if (env["PLUNE_MODEL"] !== void 0) {
1120
- result.provider.model = env["PLUNE_MODEL"];
1121
- }
1122
- if (env["PLUNE_TIMEOUT"] !== void 0) {
1123
- const n = Number(env["PLUNE_TIMEOUT"]);
1124
- if (!isNaN(n)) for (const p of all) p.timeout = n;
1125
- }
1126
- if (env["PLUNE_MAX_RETRIES"] !== void 0) {
1127
- const n = Number(env["PLUNE_MAX_RETRIES"]);
1128
- if (!isNaN(n)) for (const p of all) p.max_retries = n;
1129
- }
1130
- return result;
1131
- }
1132
-
1133
- // src/config/discover.ts
1105
+ // src/config/schema.ts
1134
1106
  init_cjs_shims();
1135
- var fs = __toESM(require("fs"), 1);
1136
- var path = __toESM(require("path"), 1);
1137
- var FILENAME = "plune.yaml";
1138
- var MAX_STEPS = 50;
1139
- function discoverConfigPath(cwd, override) {
1140
- if (override !== void 0) {
1141
- if (fs.existsSync(override)) {
1142
- return override;
1143
- }
1144
- throw new ConfigNotFoundError(`Config file not found: ${override}`);
1145
- }
1146
- let dir = cwd;
1147
- let steps = 0;
1148
- while (steps < MAX_STEPS) {
1149
- const candidate = path.join(dir, FILENAME);
1150
- if (fs.existsSync(candidate)) {
1151
- return candidate;
1152
- }
1153
- const parent = path.dirname(dir);
1154
- if (parent === dir) {
1155
- break;
1156
- }
1157
- dir = parent;
1158
- steps++;
1159
- }
1160
- throw new ConfigNotFoundError(
1161
- `No ${FILENAME} found. Run "plune init" to create one.`
1162
- );
1163
- }
1107
+ var import_zod = require("zod");
1164
1108
 
1165
- // src/config/mcp.ts
1109
+ // src/util/duration.ts
1166
1110
  init_cjs_shims();
1167
- var path2 = __toESM(require("path"), 1);
1168
- var MCP_LIMIT_DEFAULTS = {
1169
- max_steps: 10,
1170
- max_tool_calls: 20,
1171
- max_total_tokens: 1e5,
1172
- timeout_ms: 12e4,
1173
- tool_timeout_ms: 3e4
1174
- };
1175
- function mcpLimits(config, evalConfig) {
1176
- return { ...MCP_LIMIT_DEFAULTS, ...config.mcp?.limits, ...evalConfig.mcp?.limits };
1177
- }
1178
- var REFERENCE = /\$\{([A-Za-z_][A-Za-z0-9_]*)(?::-([^}]*))?\}/g;
1179
- function expandVars(value, env) {
1180
- const literal = (text) => {
1181
- if (text.includes("${")) throw new Error('has a "${" that is not ${NAME} or ${NAME:-default}');
1182
- return text;
1183
- };
1184
- let out = "";
1185
- let last = 0;
1186
- for (const match of value.matchAll(REFERENCE)) {
1187
- const [whole, name, fallback] = match;
1188
- out += literal(value.slice(last, match.index));
1189
- const set = env[name];
1190
- if (set !== void 0 && set !== "") out += set;
1191
- else if (fallback !== void 0) out += fallback;
1192
- else
1193
- throw new Error(
1194
- `\${${name}} is not set or is empty, and has no default (\${${name}:-default})`
1195
- );
1196
- last = match.index + whole.length;
1197
- }
1198
- return out + literal(value.slice(last));
1199
- }
1200
- function serverValues(server) {
1201
- const out = [];
1202
- if (server.command !== void 0) out.push(["command", server.command]);
1203
- (server.args ?? []).forEach((arg, i) => out.push([`args.${i}`, arg]));
1204
- for (const [key, value] of Object.entries(server.env ?? {})) out.push([`env.${key}`, value]);
1205
- if (server.cwd !== void 0) out.push(["cwd", server.cwd]);
1206
- if (server.url !== void 0) out.push(["url", server.url]);
1207
- for (const [key, value] of Object.entries(server.headers ?? {}))
1208
- out.push([`headers.${key}`, value]);
1209
- return out;
1210
- }
1211
- function mcpVariableIssues(config, env) {
1212
- const issues = [];
1213
- for (const [name, server] of Object.entries(config.mcp?.servers ?? {})) {
1214
- for (const [field, value] of serverValues(server)) {
1215
- try {
1216
- expandVars(value, env);
1217
- } catch (err) {
1218
- issues.push(`mcp.servers.${name}.${field}: ${err.message}`);
1219
- }
1220
- }
1221
- }
1222
- return issues;
1223
- }
1224
- function resolveMcpServer(server, env = process.env, baseDir = process.cwd()) {
1225
- const fill = (value) => expandVars(value, env);
1226
- const fillAll = (entries = {}) => Object.fromEntries(Object.entries(entries).map(([key, value]) => [key, fill(value)]));
1227
- if (server.url !== void 0)
1228
- return { kind: "http", url: fill(server.url), headers: fillAll(server.headers) };
1229
- return {
1230
- kind: "stdio",
1231
- command: fill(server.command),
1232
- args: (server.args ?? []).map(fill),
1233
- env: fillAll(server.env),
1234
- ...server.cwd !== void 0 ? { cwd: path2.resolve(baseDir, fill(server.cwd)) } : {}
1235
- };
1236
- }
1237
- var SECRET_KEY = /authorization|token|key|secret|password/i;
1238
- function mcpSecretWarnings(config) {
1239
- const warnings = [];
1240
- for (const [name, server] of Object.entries(config.mcp?.servers ?? {})) {
1241
- for (const [field, entries] of [
1242
- ["env", server.env],
1243
- ["headers", server.headers]
1244
- ]) {
1245
- for (const [key, value] of Object.entries(entries ?? {})) {
1246
- if (SECRET_KEY.test(key) && !value.includes("${")) {
1247
- warnings.push(
1248
- `mcp.servers.${name}.${field}.${key} looks like a secret written into plune.yaml; use \${VAR} so it comes from the environment.`
1249
- );
1250
- }
1251
- }
1252
- }
1253
- }
1254
- return warnings;
1255
- }
1111
+ var MAX_TIMER_MS = 2147483647;
1256
1112
 
1257
1113
  // src/config/schema.ts
1258
- init_cjs_shims();
1259
- var import_zod = require("zod");
1114
+ var providerTimeoutSchema = import_zod.z.number().int().positive().max(
1115
+ MAX_TIMER_MS,
1116
+ `must be at most ${MAX_TIMER_MS} ms (about 24.8 days), the longest a timer can wait: a longer timeout ends every model call at once`
1117
+ );
1260
1118
  var providerConfigSchema = import_zod.z.object({
1261
1119
  type: import_zod.z.enum(["anthropic", "openai", "openrouter"]),
1262
1120
  model: import_zod.z.string().min(1),
1263
1121
  temperature: import_zod.z.number().min(0).max(2).optional(),
1264
1122
  max_tokens: import_zod.z.number().int().positive().optional(),
1265
1123
  concurrency: import_zod.z.number().int().positive().optional(),
1266
- timeout: import_zod.z.number().int().positive().optional(),
1124
+ timeout: providerTimeoutSchema.optional(),
1267
1125
  max_retries: import_zod.z.number().int().min(0).optional(),
1268
1126
  // The values the OpenAI SDK's Chat Completions `reasoning_effort` accepts; only `openai` sends it.
1269
1127
  reasoning_effort: import_zod.z.enum(["none", "minimal", "low", "medium", "high", "xhigh"]).optional()
@@ -1409,7 +1267,6 @@ var evalRepeatsShape = {
1409
1267
  runs: import_zod.z.number().int().min(1).max(MAX_RUNS).optional(),
1410
1268
  pass_threshold: import_zod.z.number().gt(0, SHARE_MESSAGE).max(1, SHARE_MESSAGE).optional()
1411
1269
  };
1412
- var MAX_TIMER_MS = 2147483647;
1413
1270
  var limit = import_zod.z.number().int().positive();
1414
1271
  var mcpLimitsSchema = import_zod.z.object({
1415
1272
  max_steps: limit.optional(),
@@ -1529,6 +1386,166 @@ var pluneConfigSchema = import_zod.z.object({
1529
1386
  return others.length === 0 ? { provider: first, ...rest } : { provider: first, providers: provider, ...rest };
1530
1387
  });
1531
1388
 
1389
+ // src/config/env-overrides.ts
1390
+ function applyEnvOverrides(config, env) {
1391
+ const result = structuredClone(config);
1392
+ const all = result.providers ?? [result.provider];
1393
+ if (result.providers !== void 0) {
1394
+ for (const name of ["PLUNE_PROVIDER", "PLUNE_MODEL"])
1395
+ if (env[name] !== void 0)
1396
+ throw new ConfigValidationError("Config validation failed", [
1397
+ `${name} sets one model, but the config lists ${result.providers.length}: remove it or list a single model`
1398
+ ]);
1399
+ }
1400
+ if (env["PLUNE_PROVIDER"] !== void 0) {
1401
+ result.provider.type = env["PLUNE_PROVIDER"];
1402
+ }
1403
+ if (env["PLUNE_MODEL"] !== void 0) {
1404
+ result.provider.model = env["PLUNE_MODEL"];
1405
+ }
1406
+ if (env["PLUNE_TIMEOUT"] !== void 0) {
1407
+ const n = Number(env["PLUNE_TIMEOUT"]);
1408
+ if (Number.isFinite(n)) {
1409
+ const r = providerTimeoutSchema.safeParse(n);
1410
+ if (!r.success)
1411
+ throw new ConfigValidationError(
1412
+ "Config validation failed",
1413
+ r.error.issues.map((issue) => `PLUNE_TIMEOUT=${env["PLUNE_TIMEOUT"]}: ${issue.message}`)
1414
+ );
1415
+ for (const p of all) p.timeout = n;
1416
+ }
1417
+ }
1418
+ if (env["PLUNE_MAX_RETRIES"] !== void 0) {
1419
+ const n = Number(env["PLUNE_MAX_RETRIES"]);
1420
+ if (!isNaN(n)) for (const p of all) p.max_retries = Number.isFinite(n) ? n : 0;
1421
+ }
1422
+ return result;
1423
+ }
1424
+
1425
+ // src/config/discover.ts
1426
+ init_cjs_shims();
1427
+ var fs = __toESM(require("fs"), 1);
1428
+ var path = __toESM(require("path"), 1);
1429
+ var FILENAME = "plune.yaml";
1430
+ var MAX_STEPS = 50;
1431
+ function discoverConfigPath(cwd, override) {
1432
+ if (override !== void 0) {
1433
+ if (fs.existsSync(override)) {
1434
+ return override;
1435
+ }
1436
+ throw new ConfigNotFoundError(`Config file not found: ${override}`);
1437
+ }
1438
+ let dir = cwd;
1439
+ let steps = 0;
1440
+ while (steps < MAX_STEPS) {
1441
+ const candidate = path.join(dir, FILENAME);
1442
+ if (fs.existsSync(candidate)) {
1443
+ return candidate;
1444
+ }
1445
+ const parent = path.dirname(dir);
1446
+ if (parent === dir) {
1447
+ break;
1448
+ }
1449
+ dir = parent;
1450
+ steps++;
1451
+ }
1452
+ throw new ConfigNotFoundError(
1453
+ `No ${FILENAME} found. Run "plune init" to create one.`
1454
+ );
1455
+ }
1456
+
1457
+ // src/config/mcp.ts
1458
+ init_cjs_shims();
1459
+ var path2 = __toESM(require("path"), 1);
1460
+ var MCP_LIMIT_DEFAULTS = {
1461
+ max_steps: 10,
1462
+ max_tool_calls: 20,
1463
+ max_total_tokens: 1e5,
1464
+ timeout_ms: 12e4,
1465
+ tool_timeout_ms: 3e4
1466
+ };
1467
+ function mcpLimits(config, evalConfig) {
1468
+ return { ...MCP_LIMIT_DEFAULTS, ...config.mcp?.limits, ...evalConfig.mcp?.limits };
1469
+ }
1470
+ var REFERENCE = /\$\{([A-Za-z_][A-Za-z0-9_]*)(?::-([^}]*))?\}/g;
1471
+ function expandVars(value, env) {
1472
+ const literal = (text) => {
1473
+ if (text.includes("${")) throw new Error('has a "${" that is not ${NAME} or ${NAME:-default}');
1474
+ return text;
1475
+ };
1476
+ let out = "";
1477
+ let last = 0;
1478
+ for (const match of value.matchAll(REFERENCE)) {
1479
+ const [whole, name, fallback] = match;
1480
+ out += literal(value.slice(last, match.index));
1481
+ const set = env[name];
1482
+ if (set !== void 0 && set !== "") out += set;
1483
+ else if (fallback !== void 0) out += fallback;
1484
+ else
1485
+ throw new Error(
1486
+ `\${${name}} is not set or is empty, and has no default (\${${name}:-default})`
1487
+ );
1488
+ last = match.index + whole.length;
1489
+ }
1490
+ return out + literal(value.slice(last));
1491
+ }
1492
+ function serverValues(server) {
1493
+ const out = [];
1494
+ if (server.command !== void 0) out.push(["command", server.command]);
1495
+ (server.args ?? []).forEach((arg, i) => out.push([`args.${i}`, arg]));
1496
+ for (const [key, value] of Object.entries(server.env ?? {})) out.push([`env.${key}`, value]);
1497
+ if (server.cwd !== void 0) out.push(["cwd", server.cwd]);
1498
+ if (server.url !== void 0) out.push(["url", server.url]);
1499
+ for (const [key, value] of Object.entries(server.headers ?? {}))
1500
+ out.push([`headers.${key}`, value]);
1501
+ return out;
1502
+ }
1503
+ function mcpVariableIssues(config, env) {
1504
+ const issues = [];
1505
+ for (const [name, server] of Object.entries(config.mcp?.servers ?? {})) {
1506
+ for (const [field, value] of serverValues(server)) {
1507
+ try {
1508
+ expandVars(value, env);
1509
+ } catch (err) {
1510
+ issues.push(`mcp.servers.${name}.${field}: ${err.message}`);
1511
+ }
1512
+ }
1513
+ }
1514
+ return issues;
1515
+ }
1516
+ function resolveMcpServer(server, env = process.env, baseDir = process.cwd()) {
1517
+ const fill = (value) => expandVars(value, env);
1518
+ const fillAll = (entries = {}) => Object.fromEntries(Object.entries(entries).map(([key, value]) => [key, fill(value)]));
1519
+ if (server.url !== void 0)
1520
+ return { kind: "http", url: fill(server.url), headers: fillAll(server.headers) };
1521
+ return {
1522
+ kind: "stdio",
1523
+ command: fill(server.command),
1524
+ args: (server.args ?? []).map(fill),
1525
+ env: fillAll(server.env),
1526
+ ...server.cwd !== void 0 ? { cwd: path2.resolve(baseDir, fill(server.cwd)) } : {}
1527
+ };
1528
+ }
1529
+ var SECRET_KEY = /authorization|token|key|secret|password/i;
1530
+ function mcpSecretWarnings(config) {
1531
+ const warnings = [];
1532
+ for (const [name, server] of Object.entries(config.mcp?.servers ?? {})) {
1533
+ for (const [field, entries] of [
1534
+ ["env", server.env],
1535
+ ["headers", server.headers]
1536
+ ]) {
1537
+ for (const [key, value] of Object.entries(entries ?? {})) {
1538
+ if (SECRET_KEY.test(key) && !value.includes("${")) {
1539
+ warnings.push(
1540
+ `mcp.servers.${name}.${field}.${key} looks like a secret written into plune.yaml; use \${VAR} so it comes from the environment.`
1541
+ );
1542
+ }
1543
+ }
1544
+ }
1545
+ }
1546
+ return warnings;
1547
+ }
1548
+
1532
1549
  // src/config/loader.ts
1533
1550
  async function loadConfig(opts = {}) {
1534
1551
  const { configPath, cwd = process.cwd(), env = process.env } = opts;
@@ -3980,13 +3997,11 @@ async function runAgentRow(p) {
3980
3997
  const clean = cleaned.get(c);
3981
3998
  if (out.result === void 0 || clean === void 0) return;
3982
3999
  const whole = Buffer.from(mask?.text(clean.text) ?? clean.text, "utf8");
3983
- const keep = Math.min(Buffer.byteLength(out.result.text, "utf8"), whole.length);
4000
+ const keep = Buffer.byteLength(out.result.text, "utf8");
3984
4001
  out.result = {
3985
4002
  ...out.result,
3986
- text: keep < whole.length ? firstBytes(whole, keep) : whole.toString("utf8"),
3987
- truncated: out.result.truncated || keep < whole.length
4003
+ text: out.result.truncated && keep < whole.length ? firstBytes(whole, keep) : whole.toString("utf8")
3988
4004
  };
3989
- if (out.result.truncated) agent.collection = "partial";
3990
4005
  if (clean.unread === void 0) return;
3991
4006
  const u = unread.get(c.name) ?? { steps: /* @__PURE__ */ new Set(), count: 0, why: clean.unread };
3992
4007
  u.steps.add(s.index);
@@ -7867,12 +7882,15 @@ async function readCairnRun(dir, deps = {}) {
7867
7882
  } else {
7868
7883
  cases = casesFromDesign(report);
7869
7884
  }
7885
+ const tokens = own(asRecord(own(report, "cost")), "totalTokens");
7870
7886
  return {
7871
7887
  schemaVersion: INGEST_SCHEMA_VERSION,
7872
7888
  run: {
7873
7889
  runId: str(report["runId"], path9.basename(dir)),
7874
7890
  mode,
7875
- target: str(report["url"], "unknown")
7891
+ target: str(report["url"], "unknown"),
7892
+ // Cairn states the run's tokens as `cost.totalTokens` in every mode; the platform copies it onto each proposal.
7893
+ ...Number.isInteger(tokens) && tokens >= 0 ? { cost: { tokens, cases: cases.length } } : {}
7876
7894
  },
7877
7895
  cases
7878
7896
  };
package/dist/index.d.cts CHANGED
@@ -1284,10 +1284,15 @@ interface CairnScreencast {
1284
1284
  }
1285
1285
  interface CairnIngestPayload {
1286
1286
  schemaVersion: typeof INGEST_SCHEMA_VERSION;
1287
+ /** `cost` is what the whole run spent, once per run; absent when the report counted nothing. */
1287
1288
  run: {
1288
1289
  runId: string;
1289
1290
  mode: CairnRunMode;
1290
1291
  target: string;
1292
+ cost?: {
1293
+ tokens: number;
1294
+ cases: number;
1295
+ };
1291
1296
  };
1292
1297
  cases: CairnIngestCase[];
1293
1298
  }
package/dist/index.d.ts CHANGED
@@ -1284,10 +1284,15 @@ interface CairnScreencast {
1284
1284
  }
1285
1285
  interface CairnIngestPayload {
1286
1286
  schemaVersion: typeof INGEST_SCHEMA_VERSION;
1287
+ /** `cost` is what the whole run spent, once per run; absent when the report counted nothing. */
1287
1288
  run: {
1288
1289
  runId: string;
1289
1290
  mode: CairnRunMode;
1290
1291
  target: string;
1292
+ cost?: {
1293
+ tokens: number;
1294
+ cases: number;
1295
+ };
1291
1296
  };
1292
1297
  cases: CairnIngestCase[];
1293
1298
  }