@plune-ai/cli 0.39.6 → 0.39.8

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.js CHANGED
@@ -1064,168 +1064,26 @@ var ConfigValidationError = class extends Error {
1064
1064
  }
1065
1065
  };
1066
1066
 
1067
- // src/config/env-overrides.ts
1068
- function applyEnvOverrides(config, env) {
1069
- const result = structuredClone(config);
1070
- const all = result.providers ?? [result.provider];
1071
- if (result.providers !== void 0) {
1072
- for (const name of ["PLUNE_PROVIDER", "PLUNE_MODEL"])
1073
- if (env[name] !== void 0)
1074
- throw new ConfigValidationError("Config validation failed", [
1075
- `${name} sets one model, but the config lists ${result.providers.length}: remove it or list a single model`
1076
- ]);
1077
- }
1078
- if (env["PLUNE_PROVIDER"] !== void 0) {
1079
- result.provider.type = env["PLUNE_PROVIDER"];
1080
- }
1081
- if (env["PLUNE_MODEL"] !== void 0) {
1082
- result.provider.model = env["PLUNE_MODEL"];
1083
- }
1084
- if (env["PLUNE_TIMEOUT"] !== void 0) {
1085
- const n = Number(env["PLUNE_TIMEOUT"]);
1086
- if (!isNaN(n)) for (const p of all) p.timeout = n;
1087
- }
1088
- if (env["PLUNE_MAX_RETRIES"] !== void 0) {
1089
- const n = Number(env["PLUNE_MAX_RETRIES"]);
1090
- if (!isNaN(n)) for (const p of all) p.max_retries = n;
1091
- }
1092
- return result;
1093
- }
1094
-
1095
- // src/config/discover.ts
1067
+ // src/config/schema.ts
1096
1068
  init_esm_shims();
1097
- import * as fs from "fs";
1098
- import * as path2 from "path";
1099
- var FILENAME = "plune.yaml";
1100
- var MAX_STEPS = 50;
1101
- function discoverConfigPath(cwd, override) {
1102
- if (override !== void 0) {
1103
- if (fs.existsSync(override)) {
1104
- return override;
1105
- }
1106
- throw new ConfigNotFoundError(`Config file not found: ${override}`);
1107
- }
1108
- let dir = cwd;
1109
- let steps = 0;
1110
- while (steps < MAX_STEPS) {
1111
- const candidate = path2.join(dir, FILENAME);
1112
- if (fs.existsSync(candidate)) {
1113
- return candidate;
1114
- }
1115
- const parent = path2.dirname(dir);
1116
- if (parent === dir) {
1117
- break;
1118
- }
1119
- dir = parent;
1120
- steps++;
1121
- }
1122
- throw new ConfigNotFoundError(
1123
- `No ${FILENAME} found. Run "plune init" to create one.`
1124
- );
1125
- }
1069
+ import { z } from "zod";
1126
1070
 
1127
- // src/config/mcp.ts
1071
+ // src/util/duration.ts
1128
1072
  init_esm_shims();
1129
- import * as path3 from "path";
1130
- var MCP_LIMIT_DEFAULTS = {
1131
- max_steps: 10,
1132
- max_tool_calls: 20,
1133
- max_total_tokens: 1e5,
1134
- timeout_ms: 12e4,
1135
- tool_timeout_ms: 3e4
1136
- };
1137
- function mcpLimits(config, evalConfig) {
1138
- return { ...MCP_LIMIT_DEFAULTS, ...config.mcp?.limits, ...evalConfig.mcp?.limits };
1139
- }
1140
- var REFERENCE = /\$\{([A-Za-z_][A-Za-z0-9_]*)(?::-([^}]*))?\}/g;
1141
- function expandVars(value, env) {
1142
- const literal = (text) => {
1143
- if (text.includes("${")) throw new Error('has a "${" that is not ${NAME} or ${NAME:-default}');
1144
- return text;
1145
- };
1146
- let out = "";
1147
- let last = 0;
1148
- for (const match of value.matchAll(REFERENCE)) {
1149
- const [whole, name, fallback] = match;
1150
- out += literal(value.slice(last, match.index));
1151
- const set = env[name];
1152
- if (set !== void 0 && set !== "") out += set;
1153
- else if (fallback !== void 0) out += fallback;
1154
- else
1155
- throw new Error(
1156
- `\${${name}} is not set or is empty, and has no default (\${${name}:-default})`
1157
- );
1158
- last = match.index + whole.length;
1159
- }
1160
- return out + literal(value.slice(last));
1161
- }
1162
- function serverValues(server) {
1163
- const out = [];
1164
- if (server.command !== void 0) out.push(["command", server.command]);
1165
- (server.args ?? []).forEach((arg, i) => out.push([`args.${i}`, arg]));
1166
- for (const [key, value] of Object.entries(server.env ?? {})) out.push([`env.${key}`, value]);
1167
- if (server.cwd !== void 0) out.push(["cwd", server.cwd]);
1168
- if (server.url !== void 0) out.push(["url", server.url]);
1169
- for (const [key, value] of Object.entries(server.headers ?? {}))
1170
- out.push([`headers.${key}`, value]);
1171
- return out;
1172
- }
1173
- function mcpVariableIssues(config, env) {
1174
- const issues = [];
1175
- for (const [name, server] of Object.entries(config.mcp?.servers ?? {})) {
1176
- for (const [field, value] of serverValues(server)) {
1177
- try {
1178
- expandVars(value, env);
1179
- } catch (err) {
1180
- issues.push(`mcp.servers.${name}.${field}: ${err.message}`);
1181
- }
1182
- }
1183
- }
1184
- return issues;
1185
- }
1186
- function resolveMcpServer(server, env = process.env, baseDir = process.cwd()) {
1187
- const fill = (value) => expandVars(value, env);
1188
- const fillAll = (entries = {}) => Object.fromEntries(Object.entries(entries).map(([key, value]) => [key, fill(value)]));
1189
- if (server.url !== void 0)
1190
- return { kind: "http", url: fill(server.url), headers: fillAll(server.headers) };
1191
- return {
1192
- kind: "stdio",
1193
- command: fill(server.command),
1194
- args: (server.args ?? []).map(fill),
1195
- env: fillAll(server.env),
1196
- ...server.cwd !== void 0 ? { cwd: path3.resolve(baseDir, fill(server.cwd)) } : {}
1197
- };
1198
- }
1199
- var SECRET_KEY = /authorization|token|key|secret|password/i;
1200
- function mcpSecretWarnings(config) {
1201
- const warnings = [];
1202
- for (const [name, server] of Object.entries(config.mcp?.servers ?? {})) {
1203
- for (const [field, entries] of [
1204
- ["env", server.env],
1205
- ["headers", server.headers]
1206
- ]) {
1207
- for (const [key, value] of Object.entries(entries ?? {})) {
1208
- if (SECRET_KEY.test(key) && !value.includes("${")) {
1209
- warnings.push(
1210
- `mcp.servers.${name}.${field}.${key} looks like a secret written into plune.yaml; use \${VAR} so it comes from the environment.`
1211
- );
1212
- }
1213
- }
1214
- }
1215
- }
1216
- return warnings;
1217
- }
1073
+ var MAX_TIMER_MS = 2147483647;
1218
1074
 
1219
1075
  // src/config/schema.ts
1220
- init_esm_shims();
1221
- import { z } from "zod";
1076
+ var providerTimeoutSchema = z.number().int().positive().max(
1077
+ MAX_TIMER_MS,
1078
+ `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`
1079
+ );
1222
1080
  var providerConfigSchema = z.object({
1223
1081
  type: z.enum(["anthropic", "openai", "openrouter"]),
1224
1082
  model: z.string().min(1),
1225
1083
  temperature: z.number().min(0).max(2).optional(),
1226
1084
  max_tokens: z.number().int().positive().optional(),
1227
1085
  concurrency: z.number().int().positive().optional(),
1228
- timeout: z.number().int().positive().optional(),
1086
+ timeout: providerTimeoutSchema.optional(),
1229
1087
  max_retries: z.number().int().min(0).optional(),
1230
1088
  // The values the OpenAI SDK's Chat Completions `reasoning_effort` accepts; only `openai` sends it.
1231
1089
  reasoning_effort: z.enum(["none", "minimal", "low", "medium", "high", "xhigh"]).optional()
@@ -1371,7 +1229,6 @@ var evalRepeatsShape = {
1371
1229
  runs: z.number().int().min(1).max(MAX_RUNS).optional(),
1372
1230
  pass_threshold: z.number().gt(0, SHARE_MESSAGE).max(1, SHARE_MESSAGE).optional()
1373
1231
  };
1374
- var MAX_TIMER_MS = 2147483647;
1375
1232
  var limit = z.number().int().positive();
1376
1233
  var mcpLimitsSchema = z.object({
1377
1234
  max_steps: limit.optional(),
@@ -1491,6 +1348,166 @@ var pluneConfigSchema = z.object({
1491
1348
  return others.length === 0 ? { provider: first, ...rest } : { provider: first, providers: provider, ...rest };
1492
1349
  });
1493
1350
 
1351
+ // src/config/env-overrides.ts
1352
+ function applyEnvOverrides(config, env) {
1353
+ const result = structuredClone(config);
1354
+ const all = result.providers ?? [result.provider];
1355
+ if (result.providers !== void 0) {
1356
+ for (const name of ["PLUNE_PROVIDER", "PLUNE_MODEL"])
1357
+ if (env[name] !== void 0)
1358
+ throw new ConfigValidationError("Config validation failed", [
1359
+ `${name} sets one model, but the config lists ${result.providers.length}: remove it or list a single model`
1360
+ ]);
1361
+ }
1362
+ if (env["PLUNE_PROVIDER"] !== void 0) {
1363
+ result.provider.type = env["PLUNE_PROVIDER"];
1364
+ }
1365
+ if (env["PLUNE_MODEL"] !== void 0) {
1366
+ result.provider.model = env["PLUNE_MODEL"];
1367
+ }
1368
+ if (env["PLUNE_TIMEOUT"] !== void 0) {
1369
+ const n = Number(env["PLUNE_TIMEOUT"]);
1370
+ if (Number.isFinite(n)) {
1371
+ const r = providerTimeoutSchema.safeParse(n);
1372
+ if (!r.success)
1373
+ throw new ConfigValidationError(
1374
+ "Config validation failed",
1375
+ r.error.issues.map((issue) => `PLUNE_TIMEOUT=${env["PLUNE_TIMEOUT"]}: ${issue.message}`)
1376
+ );
1377
+ for (const p of all) p.timeout = n;
1378
+ }
1379
+ }
1380
+ if (env["PLUNE_MAX_RETRIES"] !== void 0) {
1381
+ const n = Number(env["PLUNE_MAX_RETRIES"]);
1382
+ if (!isNaN(n)) for (const p of all) p.max_retries = Number.isFinite(n) ? n : 0;
1383
+ }
1384
+ return result;
1385
+ }
1386
+
1387
+ // src/config/discover.ts
1388
+ init_esm_shims();
1389
+ import * as fs from "fs";
1390
+ import * as path2 from "path";
1391
+ var FILENAME = "plune.yaml";
1392
+ var MAX_STEPS = 50;
1393
+ function discoverConfigPath(cwd, override) {
1394
+ if (override !== void 0) {
1395
+ if (fs.existsSync(override)) {
1396
+ return override;
1397
+ }
1398
+ throw new ConfigNotFoundError(`Config file not found: ${override}`);
1399
+ }
1400
+ let dir = cwd;
1401
+ let steps = 0;
1402
+ while (steps < MAX_STEPS) {
1403
+ const candidate = path2.join(dir, FILENAME);
1404
+ if (fs.existsSync(candidate)) {
1405
+ return candidate;
1406
+ }
1407
+ const parent = path2.dirname(dir);
1408
+ if (parent === dir) {
1409
+ break;
1410
+ }
1411
+ dir = parent;
1412
+ steps++;
1413
+ }
1414
+ throw new ConfigNotFoundError(
1415
+ `No ${FILENAME} found. Run "plune init" to create one.`
1416
+ );
1417
+ }
1418
+
1419
+ // src/config/mcp.ts
1420
+ init_esm_shims();
1421
+ import * as path3 from "path";
1422
+ var MCP_LIMIT_DEFAULTS = {
1423
+ max_steps: 10,
1424
+ max_tool_calls: 20,
1425
+ max_total_tokens: 1e5,
1426
+ timeout_ms: 12e4,
1427
+ tool_timeout_ms: 3e4
1428
+ };
1429
+ function mcpLimits(config, evalConfig) {
1430
+ return { ...MCP_LIMIT_DEFAULTS, ...config.mcp?.limits, ...evalConfig.mcp?.limits };
1431
+ }
1432
+ var REFERENCE = /\$\{([A-Za-z_][A-Za-z0-9_]*)(?::-([^}]*))?\}/g;
1433
+ function expandVars(value, env) {
1434
+ const literal = (text) => {
1435
+ if (text.includes("${")) throw new Error('has a "${" that is not ${NAME} or ${NAME:-default}');
1436
+ return text;
1437
+ };
1438
+ let out = "";
1439
+ let last = 0;
1440
+ for (const match of value.matchAll(REFERENCE)) {
1441
+ const [whole, name, fallback] = match;
1442
+ out += literal(value.slice(last, match.index));
1443
+ const set = env[name];
1444
+ if (set !== void 0 && set !== "") out += set;
1445
+ else if (fallback !== void 0) out += fallback;
1446
+ else
1447
+ throw new Error(
1448
+ `\${${name}} is not set or is empty, and has no default (\${${name}:-default})`
1449
+ );
1450
+ last = match.index + whole.length;
1451
+ }
1452
+ return out + literal(value.slice(last));
1453
+ }
1454
+ function serverValues(server) {
1455
+ const out = [];
1456
+ if (server.command !== void 0) out.push(["command", server.command]);
1457
+ (server.args ?? []).forEach((arg, i) => out.push([`args.${i}`, arg]));
1458
+ for (const [key, value] of Object.entries(server.env ?? {})) out.push([`env.${key}`, value]);
1459
+ if (server.cwd !== void 0) out.push(["cwd", server.cwd]);
1460
+ if (server.url !== void 0) out.push(["url", server.url]);
1461
+ for (const [key, value] of Object.entries(server.headers ?? {}))
1462
+ out.push([`headers.${key}`, value]);
1463
+ return out;
1464
+ }
1465
+ function mcpVariableIssues(config, env) {
1466
+ const issues = [];
1467
+ for (const [name, server] of Object.entries(config.mcp?.servers ?? {})) {
1468
+ for (const [field, value] of serverValues(server)) {
1469
+ try {
1470
+ expandVars(value, env);
1471
+ } catch (err) {
1472
+ issues.push(`mcp.servers.${name}.${field}: ${err.message}`);
1473
+ }
1474
+ }
1475
+ }
1476
+ return issues;
1477
+ }
1478
+ function resolveMcpServer(server, env = process.env, baseDir = process.cwd()) {
1479
+ const fill = (value) => expandVars(value, env);
1480
+ const fillAll = (entries = {}) => Object.fromEntries(Object.entries(entries).map(([key, value]) => [key, fill(value)]));
1481
+ if (server.url !== void 0)
1482
+ return { kind: "http", url: fill(server.url), headers: fillAll(server.headers) };
1483
+ return {
1484
+ kind: "stdio",
1485
+ command: fill(server.command),
1486
+ args: (server.args ?? []).map(fill),
1487
+ env: fillAll(server.env),
1488
+ ...server.cwd !== void 0 ? { cwd: path3.resolve(baseDir, fill(server.cwd)) } : {}
1489
+ };
1490
+ }
1491
+ var SECRET_KEY = /authorization|token|key|secret|password/i;
1492
+ function mcpSecretWarnings(config) {
1493
+ const warnings = [];
1494
+ for (const [name, server] of Object.entries(config.mcp?.servers ?? {})) {
1495
+ for (const [field, entries] of [
1496
+ ["env", server.env],
1497
+ ["headers", server.headers]
1498
+ ]) {
1499
+ for (const [key, value] of Object.entries(entries ?? {})) {
1500
+ if (SECRET_KEY.test(key) && !value.includes("${")) {
1501
+ warnings.push(
1502
+ `mcp.servers.${name}.${field}.${key} looks like a secret written into plune.yaml; use \${VAR} so it comes from the environment.`
1503
+ );
1504
+ }
1505
+ }
1506
+ }
1507
+ }
1508
+ return warnings;
1509
+ }
1510
+
1494
1511
  // src/config/loader.ts
1495
1512
  async function loadConfig(opts = {}) {
1496
1513
  const { configPath, cwd = process.cwd(), env = process.env } = opts;
@@ -1662,7 +1679,7 @@ function readHeader(headers, name) {
1662
1679
  }
1663
1680
  async function withRetry(fn, options) {
1664
1681
  const { base_delay_ms = 500, sleep: sleep2 = defaultSleep, random = Math.random } = options;
1665
- const maxRetries = Math.max(0, Math.floor(options.max_retries));
1682
+ const maxRetries = Number.isFinite(options.max_retries) ? Math.max(0, Math.floor(options.max_retries)) : 0;
1666
1683
  let attempt = 0;
1667
1684
  for (; ; ) {
1668
1685
  try {
@@ -3302,14 +3319,17 @@ var DEFAULT_MAX_TOKENS = 1024;
3302
3319
  function buildJudge(provider, cfg, onUsage) {
3303
3320
  return {
3304
3321
  async ask(prompt5) {
3322
+ const maxTokens = cfg.max_tokens ?? DEFAULT_MAX_TOKENS;
3305
3323
  const res = await provider.complete({
3306
3324
  provider: cfg.type,
3307
3325
  model: cfg.model,
3308
3326
  ...cfg.temperature !== void 0 ? { temperature: cfg.temperature } : {},
3309
- max_tokens: cfg.max_tokens ?? DEFAULT_MAX_TOKENS,
3327
+ max_tokens: maxTokens,
3310
3328
  prompt_resolved: prompt5
3311
3329
  });
3312
3330
  onUsage(res.usage);
3331
+ if (res.finish_reason === "length")
3332
+ throw new Error(`judge reply was cut off at max_tokens (${maxTokens}); raise max_tokens for the judge model`);
3313
3333
  return res.output;
3314
3334
  }
3315
3335
  };
@@ -3495,6 +3515,70 @@ function scanIds(result) {
3495
3515
  values: [...found.values].map(([hash, at]) => ({ hash, paths: [...at].sort() }))
3496
3516
  };
3497
3517
  }
3518
+ var ID_MARK = "<id>";
3519
+ var UUID_IN_TEXT = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi;
3520
+ var redactUuids = (text) => text.replace(UUID_IN_TEXT, ID_MARK);
3521
+ var STR = String.raw`"(?:[^"\\]|\\.)*?(?:"|(?= \(cut\)))`;
3522
+ var NUM = String.raw`-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?`;
3523
+ var VAL = `(?:${STR}|${NUM})`;
3524
+ var PAIR = new RegExp(
3525
+ String.raw`"((?:[^"\\]|\\.)*)":(${VAL}|\[(?:${VAL}(?:,${VAL})*)?(?:\]|(?= \(cut\))))`,
3526
+ "g"
3527
+ );
3528
+ var redactReason = (text) => redactUuids(
3529
+ text.replace(
3530
+ PAIR,
3531
+ (whole, key) => isIdKey(key) ? `"${key}":${JSON.stringify(ID_MARK)}` : whole
3532
+ )
3533
+ );
3534
+ function strip(value, depth, st) {
3535
+ if (typeof value === "string") return redactUuids(value);
3536
+ if (depth > SCAN_DEPTH) {
3537
+ if (typeof value === "object" && value !== null) st.whole = false;
3538
+ return value;
3539
+ }
3540
+ if (Array.isArray(value)) {
3541
+ if (value.length > SCAN_ITEMS) st.whole = false;
3542
+ return value.map((v, i) => i < SCAN_ITEMS ? strip(v, depth + 1, st) : v);
3543
+ }
3544
+ if (!isRecord3(value)) return value;
3545
+ const out = {};
3546
+ for (const [key, v] of Object.entries(value)) {
3547
+ let name = redactUuids(key);
3548
+ for (let n = 2; name !== key && Object.hasOwn(out, name); n++) name = `${ID_MARK}#${n}`;
3549
+ out[name] = isIdKey(key) && (isScalar(v) || Array.isArray(v) && v.length > 0 && v.every(isScalar)) ? Array.isArray(v) ? v.map(() => ID_MARK) : ID_MARK : strip(v, depth + 1, st);
3550
+ }
3551
+ return out;
3552
+ }
3553
+ function redactIds(value) {
3554
+ const st = { whole: true };
3555
+ return { value: strip(value, 0, st), whole: st.whole };
3556
+ }
3557
+ function redactAnswer(result) {
3558
+ let unread;
3559
+ const ids = (v) => {
3560
+ const r = redactIds(v);
3561
+ if (!r.whole)
3562
+ unread ??= `the answer is deeper than ${SCAN_DEPTH} levels or has more than ${SCAN_ITEMS} items in a list`;
3563
+ return r.value;
3564
+ };
3565
+ if (!isRecord3(result))
3566
+ return { result: ids(result), ...unread !== void 0 ? { unread } : {} };
3567
+ const out = { ...result };
3568
+ if (result.structuredContent !== void 0) out.structuredContent = ids(result.structuredContent);
3569
+ if (Array.isArray(result.content))
3570
+ out.content = result.content.map((block) => {
3571
+ if (!isRecord3(block) || block.type !== "text" || typeof block.text !== "string")
3572
+ return ids(block);
3573
+ try {
3574
+ return { ...block, text: JSON.stringify(ids(JSON.parse(block.text))) };
3575
+ } catch {
3576
+ unread ??= "the answer is not JSON";
3577
+ return { ...block, text: redactUuids(block.text) };
3578
+ }
3579
+ });
3580
+ return { result: out, ...unread !== void 0 ? { unread } : {} };
3581
+ }
3498
3582
  var list = (steps) => steps.join(", ");
3499
3583
  function frictionAdvice(calls) {
3500
3584
  const acc = /* @__PURE__ */ new Map();
@@ -3602,6 +3686,7 @@ function resultText(result) {
3602
3686
  (b) => isRecord4(b) && b.type === "text" && typeof b.text === "string" ? b.text : JSON.stringify(b)
3603
3687
  ).join("\n");
3604
3688
  }
3689
+ var firstBytes = (whole, keep) => whole.subarray(0, keep).toString("utf8").replace(/�$/, "");
3605
3690
  function excerpts() {
3606
3691
  let left = TRANSCRIPT_BYTES;
3607
3692
  const state = {
@@ -3612,7 +3697,7 @@ function excerpts() {
3612
3697
  left -= keep;
3613
3698
  const truncated = keep < whole.length;
3614
3699
  if (truncated) state.any = true;
3615
- const kept = truncated ? whole.subarray(0, keep).toString("utf8").replace(/�$/, "") : text;
3700
+ const kept = truncated ? firstBytes(whole, keep) : text;
3616
3701
  return { text: kept, bytes: whole.length, truncated };
3617
3702
  }
3618
3703
  };
@@ -3666,6 +3751,7 @@ async function runAgentRow(p) {
3666
3751
  let error;
3667
3752
  let session;
3668
3753
  const scanned = /* @__PURE__ */ new Map();
3754
+ const cleaned = /* @__PURE__ */ new Map();
3669
3755
  const overrides = p.toolDescriptions ?? {};
3670
3756
  const replaced = /* @__PURE__ */ new Set();
3671
3757
  try {
@@ -3811,6 +3897,17 @@ async function runAgentRow(p) {
3811
3897
  succeeded ||= !rec.is_error;
3812
3898
  if (got.kind === "result" && !rec.is_error) scanned.set(rec, scanIds(got.result));
3813
3899
  rec.result = kept.cut(text);
3900
+ if (got.kind === "result") {
3901
+ const r = redactAnswer(got.result);
3902
+ cleaned.set(rec, {
3903
+ text: resultText(r.result),
3904
+ ...r.unread !== void 0 ? { unread: r.unread } : {}
3905
+ });
3906
+ } else
3907
+ cleaned.set(rec, {
3908
+ text: redactUuids(text),
3909
+ unread: "the answer is an error message, not JSON"
3910
+ });
3814
3911
  answer(rec, c, text);
3815
3912
  }
3816
3913
  messages.push(
@@ -3851,8 +3948,44 @@ async function runAgentRow(p) {
3851
3948
  tool,
3852
3949
  sha256: sha256(overrides[tool])
3853
3950
  }));
3951
+ const storeWithoutIds = (said = [], err) => {
3952
+ for (const r of said) if (r.reason !== void 0) r.reason = redactReason(r.reason);
3953
+ if (err !== void 0) err.message = redactReason(err.message);
3954
+ const unread = /* @__PURE__ */ new Map();
3955
+ transcript.steps.forEach(
3956
+ (s, si) => s.calls.forEach((c, ci) => {
3957
+ const out = agent.steps[si].calls[ci];
3958
+ out.args = redactIds(out.args).value;
3959
+ const clean = cleaned.get(c);
3960
+ if (out.result === void 0 || clean === void 0) return;
3961
+ const whole = Buffer.from(mask?.text(clean.text) ?? clean.text, "utf8");
3962
+ const keep = Buffer.byteLength(out.result.text, "utf8");
3963
+ out.result = {
3964
+ ...out.result,
3965
+ text: out.result.truncated && keep < whole.length ? firstBytes(whole, keep) : whole.toString("utf8")
3966
+ };
3967
+ if (clean.unread === void 0) return;
3968
+ const u = unread.get(c.name) ?? { steps: /* @__PURE__ */ new Set(), count: 0, why: clean.unread };
3969
+ u.steps.add(s.index);
3970
+ u.count++;
3971
+ unread.set(c.name, u);
3972
+ })
3973
+ );
3974
+ return [...unread].map(([tool, u]) => {
3975
+ const steps = [...u.steps].sort((x, y) => x - y);
3976
+ return {
3977
+ type: "ids-not-redacted",
3978
+ tool,
3979
+ steps,
3980
+ count: u.count,
3981
+ reason: `${tool}: ${u.why}, so only UUID-shaped values were replaced in its stored answer; other identifiers may remain (steps ${steps.join(", ")})`
3982
+ };
3983
+ });
3984
+ };
3854
3985
  const spent = usages.length > 0 ? { usage: sumUsage(usages) } : {};
3855
3986
  if (error !== void 0) {
3987
+ const notes = storeWithoutIds();
3988
+ if (notes.length > 0) agent.advice = notes;
3856
3989
  return {
3857
3990
  vars: p.row.vars,
3858
3991
  output: null,
@@ -3873,7 +4006,11 @@ async function runAgentRow(p) {
3873
4006
  const signals = (mask?.value(friction) ?? friction).filter(
3874
4007
  (f) => !(f.type === "identical-retry" && covered.some((c) => c.tool === void 0 || c.tool === f.tool))
3875
4008
  );
3876
- const findings = [...advice, ...signals];
4009
+ const findings = [
4010
+ ...advice,
4011
+ ...signals,
4012
+ ...storeWithoutIds([...records, ...advice], assertionError)
4013
+ ];
3877
4014
  if (findings.length > 0) agent.advice = findings;
3878
4015
  const usage = sumUsage(usages);
3879
4016
  return {
@@ -4690,8 +4827,26 @@ var evalResultSchema = z3.object({
4690
4827
  model: z3.string().optional()
4691
4828
  }).optional(),
4692
4829
  /** The type and model of a cell of a multi-model run. Optional and additive. */
4693
- provider: z3.object({ type: z3.string(), model: z3.string() }).optional()
4830
+ provider: z3.object({ type: z3.string(), model: z3.string() }).optional(),
4831
+ /** The link to the eval's trace in your own observability (Langfuse, OTel). Optional and additive; `plune sync` drops one `traceUrlProblem` refuses. */
4832
+ traceUrl: z3.string().optional()
4694
4833
  });
4834
+ var TRACE_URL_MAX = 2048;
4835
+ function traceUrlProblem(value) {
4836
+ if (typeof value !== "string") return "not a string";
4837
+ const url = value.trim();
4838
+ if (url.length > TRACE_URL_MAX) return `longer than ${TRACE_URL_MAX} characters`;
4839
+ if (!/^[^\s\p{Cc}\p{Cf}]+$/u.test(url)) return "must not contain spaces or control characters";
4840
+ let parsed2;
4841
+ try {
4842
+ parsed2 = new URL(url);
4843
+ } catch {
4844
+ return "must be an https address";
4845
+ }
4846
+ if (parsed2.protocol !== "https:" || parsed2.hostname === "") return "must be an https address";
4847
+ if (parsed2.username !== "" || parsed2.password !== "") return "must carry no user name or password";
4848
+ return void 0;
4849
+ }
4695
4850
  var runResultSchema = z3.object({
4696
4851
  schemaVersion: z3.literal(RUN_RESULT_SCHEMA_VERSION),
4697
4852
  plune_version: z3.string(),
@@ -4862,7 +5017,7 @@ var SyncHttpError = class extends Error {
4862
5017
  }
4863
5018
  status;
4864
5019
  };
4865
- function readRun(cwd, file) {
5020
+ function readRun(cwd, file, warn) {
4866
5021
  const target = file !== void 0 ? path7.resolve(cwd, file) : path7.join(cwd, ".plune", "last-run.json");
4867
5022
  let raw;
4868
5023
  try {
@@ -4878,12 +5033,29 @@ function readRun(cwd, file) {
4878
5033
  } catch {
4879
5034
  throw new SyncFileError(`Run file is not valid JSON: ${target}`);
4880
5035
  }
5036
+ dropBadTraceLinks(json, warn);
4881
5037
  try {
4882
5038
  return parseRunResult(json);
4883
5039
  } catch {
4884
5040
  throw new SyncFileError(`Run file does not match the RunResult schema: ${target}`);
4885
5041
  }
4886
5042
  }
5043
+ function dropBadTraceLinks(json, warn) {
5044
+ const evals = json?.evals;
5045
+ if (!Array.isArray(evals)) return;
5046
+ for (const e of evals) {
5047
+ if (typeof e !== "object" || e === null || !("traceUrl" in e)) continue;
5048
+ const entry = e;
5049
+ const problem = traceUrlProblem(entry.traceUrl);
5050
+ if (problem === void 0) {
5051
+ entry.traceUrl = entry.traceUrl.trim();
5052
+ continue;
5053
+ }
5054
+ delete entry.traceUrl;
5055
+ warn(`plune: eval "${String(entry.id)}": trace link not sent (${problem}) \u2014 the eval is synced without it.
5056
+ `);
5057
+ }
5058
+ }
4887
5059
  async function safeErrorDetail(res) {
4888
5060
  try {
4889
5061
  const body = await res.json();
@@ -4897,7 +5069,7 @@ async function handleSync(deps = {}) {
4897
5069
  const apiUrl = resolveApiUrl(deps.apiUrl);
4898
5070
  const token = (deps.loadToken ?? loadToken)();
4899
5071
  if (token === null) throw new NotLoggedInError();
4900
- const run = readRun(cwd, deps.file);
5072
+ const run = readRun(cwd, deps.file, deps.warn ?? ((line) => process.stderr.write(line)));
4901
5073
  const doFetch = deps.fetchImpl ?? fetch;
4902
5074
  const endpoint = `${apiUrl}/v1/runs`;
4903
5075
  const payload = JSON.stringify(run);