@plune-ai/cli 0.39.6 → 0.39.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.
package/dist/index.cjs CHANGED
@@ -1700,7 +1700,7 @@ function readHeader(headers, name) {
1700
1700
  }
1701
1701
  async function withRetry(fn, options) {
1702
1702
  const { base_delay_ms = 500, sleep: sleep2 = defaultSleep, random = Math.random } = options;
1703
- const maxRetries = Math.max(0, Math.floor(options.max_retries));
1703
+ const maxRetries = Number.isFinite(options.max_retries) ? Math.max(0, Math.floor(options.max_retries)) : 0;
1704
1704
  let attempt = 0;
1705
1705
  for (; ; ) {
1706
1706
  try {
@@ -3340,14 +3340,17 @@ var DEFAULT_MAX_TOKENS = 1024;
3340
3340
  function buildJudge(provider, cfg, onUsage) {
3341
3341
  return {
3342
3342
  async ask(prompt5) {
3343
+ const maxTokens = cfg.max_tokens ?? DEFAULT_MAX_TOKENS;
3343
3344
  const res = await provider.complete({
3344
3345
  provider: cfg.type,
3345
3346
  model: cfg.model,
3346
3347
  ...cfg.temperature !== void 0 ? { temperature: cfg.temperature } : {},
3347
- max_tokens: cfg.max_tokens ?? DEFAULT_MAX_TOKENS,
3348
+ max_tokens: maxTokens,
3348
3349
  prompt_resolved: prompt5
3349
3350
  });
3350
3351
  onUsage(res.usage);
3352
+ if (res.finish_reason === "length")
3353
+ throw new Error(`judge reply was cut off at max_tokens (${maxTokens}); raise max_tokens for the judge model`);
3351
3354
  return res.output;
3352
3355
  }
3353
3356
  };
@@ -3533,6 +3536,70 @@ function scanIds(result) {
3533
3536
  values: [...found.values].map(([hash, at]) => ({ hash, paths: [...at].sort() }))
3534
3537
  };
3535
3538
  }
3539
+ var ID_MARK = "<id>";
3540
+ 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;
3541
+ var redactUuids = (text) => text.replace(UUID_IN_TEXT, ID_MARK);
3542
+ var STR = String.raw`"(?:[^"\\]|\\.)*?(?:"|(?= \(cut\)))`;
3543
+ var NUM = String.raw`-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?`;
3544
+ var VAL = `(?:${STR}|${NUM})`;
3545
+ var PAIR = new RegExp(
3546
+ String.raw`"((?:[^"\\]|\\.)*)":(${VAL}|\[(?:${VAL}(?:,${VAL})*)?(?:\]|(?= \(cut\))))`,
3547
+ "g"
3548
+ );
3549
+ var redactReason = (text) => redactUuids(
3550
+ text.replace(
3551
+ PAIR,
3552
+ (whole, key) => isIdKey(key) ? `"${key}":${JSON.stringify(ID_MARK)}` : whole
3553
+ )
3554
+ );
3555
+ function strip(value, depth, st) {
3556
+ if (typeof value === "string") return redactUuids(value);
3557
+ if (depth > SCAN_DEPTH) {
3558
+ if (typeof value === "object" && value !== null) st.whole = false;
3559
+ return value;
3560
+ }
3561
+ if (Array.isArray(value)) {
3562
+ if (value.length > SCAN_ITEMS) st.whole = false;
3563
+ return value.map((v, i) => i < SCAN_ITEMS ? strip(v, depth + 1, st) : v);
3564
+ }
3565
+ if (!isRecord3(value)) return value;
3566
+ const out = {};
3567
+ for (const [key, v] of Object.entries(value)) {
3568
+ let name = redactUuids(key);
3569
+ for (let n = 2; name !== key && Object.hasOwn(out, name); n++) name = `${ID_MARK}#${n}`;
3570
+ 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);
3571
+ }
3572
+ return out;
3573
+ }
3574
+ function redactIds(value) {
3575
+ const st = { whole: true };
3576
+ return { value: strip(value, 0, st), whole: st.whole };
3577
+ }
3578
+ function redactAnswer(result) {
3579
+ let unread;
3580
+ const ids = (v) => {
3581
+ const r = redactIds(v);
3582
+ if (!r.whole)
3583
+ unread ??= `the answer is deeper than ${SCAN_DEPTH} levels or has more than ${SCAN_ITEMS} items in a list`;
3584
+ return r.value;
3585
+ };
3586
+ if (!isRecord3(result))
3587
+ return { result: ids(result), ...unread !== void 0 ? { unread } : {} };
3588
+ const out = { ...result };
3589
+ if (result.structuredContent !== void 0) out.structuredContent = ids(result.structuredContent);
3590
+ if (Array.isArray(result.content))
3591
+ out.content = result.content.map((block) => {
3592
+ if (!isRecord3(block) || block.type !== "text" || typeof block.text !== "string")
3593
+ return ids(block);
3594
+ try {
3595
+ return { ...block, text: JSON.stringify(ids(JSON.parse(block.text))) };
3596
+ } catch {
3597
+ unread ??= "the answer is not JSON";
3598
+ return { ...block, text: redactUuids(block.text) };
3599
+ }
3600
+ });
3601
+ return { result: out, ...unread !== void 0 ? { unread } : {} };
3602
+ }
3536
3603
  var list = (steps) => steps.join(", ");
3537
3604
  function frictionAdvice(calls) {
3538
3605
  const acc = /* @__PURE__ */ new Map();
@@ -3640,6 +3707,7 @@ function resultText(result) {
3640
3707
  (b) => isRecord4(b) && b.type === "text" && typeof b.text === "string" ? b.text : JSON.stringify(b)
3641
3708
  ).join("\n");
3642
3709
  }
3710
+ var firstBytes = (whole, keep) => whole.subarray(0, keep).toString("utf8").replace(/�$/, "");
3643
3711
  function excerpts() {
3644
3712
  let left = TRANSCRIPT_BYTES;
3645
3713
  const state = {
@@ -3650,7 +3718,7 @@ function excerpts() {
3650
3718
  left -= keep;
3651
3719
  const truncated = keep < whole.length;
3652
3720
  if (truncated) state.any = true;
3653
- const kept = truncated ? whole.subarray(0, keep).toString("utf8").replace(/�$/, "") : text;
3721
+ const kept = truncated ? firstBytes(whole, keep) : text;
3654
3722
  return { text: kept, bytes: whole.length, truncated };
3655
3723
  }
3656
3724
  };
@@ -3704,6 +3772,7 @@ async function runAgentRow(p) {
3704
3772
  let error;
3705
3773
  let session;
3706
3774
  const scanned = /* @__PURE__ */ new Map();
3775
+ const cleaned = /* @__PURE__ */ new Map();
3707
3776
  const overrides = p.toolDescriptions ?? {};
3708
3777
  const replaced = /* @__PURE__ */ new Set();
3709
3778
  try {
@@ -3849,6 +3918,17 @@ async function runAgentRow(p) {
3849
3918
  succeeded ||= !rec.is_error;
3850
3919
  if (got.kind === "result" && !rec.is_error) scanned.set(rec, scanIds(got.result));
3851
3920
  rec.result = kept.cut(text);
3921
+ if (got.kind === "result") {
3922
+ const r = redactAnswer(got.result);
3923
+ cleaned.set(rec, {
3924
+ text: resultText(r.result),
3925
+ ...r.unread !== void 0 ? { unread: r.unread } : {}
3926
+ });
3927
+ } else
3928
+ cleaned.set(rec, {
3929
+ text: redactUuids(text),
3930
+ unread: "the answer is an error message, not JSON"
3931
+ });
3852
3932
  answer(rec, c, text);
3853
3933
  }
3854
3934
  messages.push(
@@ -3889,8 +3969,46 @@ async function runAgentRow(p) {
3889
3969
  tool,
3890
3970
  sha256: sha256(overrides[tool])
3891
3971
  }));
3972
+ const storeWithoutIds = (said = [], err) => {
3973
+ for (const r of said) if (r.reason !== void 0) r.reason = redactReason(r.reason);
3974
+ if (err !== void 0) err.message = redactReason(err.message);
3975
+ const unread = /* @__PURE__ */ new Map();
3976
+ transcript.steps.forEach(
3977
+ (s, si) => s.calls.forEach((c, ci) => {
3978
+ const out = agent.steps[si].calls[ci];
3979
+ out.args = redactIds(out.args).value;
3980
+ const clean = cleaned.get(c);
3981
+ if (out.result === void 0 || clean === void 0) return;
3982
+ const whole = Buffer.from(mask?.text(clean.text) ?? clean.text, "utf8");
3983
+ const keep = Math.min(Buffer.byteLength(out.result.text, "utf8"), whole.length);
3984
+ out.result = {
3985
+ ...out.result,
3986
+ text: keep < whole.length ? firstBytes(whole, keep) : whole.toString("utf8"),
3987
+ truncated: out.result.truncated || keep < whole.length
3988
+ };
3989
+ if (out.result.truncated) agent.collection = "partial";
3990
+ if (clean.unread === void 0) return;
3991
+ const u = unread.get(c.name) ?? { steps: /* @__PURE__ */ new Set(), count: 0, why: clean.unread };
3992
+ u.steps.add(s.index);
3993
+ u.count++;
3994
+ unread.set(c.name, u);
3995
+ })
3996
+ );
3997
+ return [...unread].map(([tool, u]) => {
3998
+ const steps = [...u.steps].sort((x, y) => x - y);
3999
+ return {
4000
+ type: "ids-not-redacted",
4001
+ tool,
4002
+ steps,
4003
+ count: u.count,
4004
+ reason: `${tool}: ${u.why}, so only UUID-shaped values were replaced in its stored answer; other identifiers may remain (steps ${steps.join(", ")})`
4005
+ };
4006
+ });
4007
+ };
3892
4008
  const spent = usages.length > 0 ? { usage: sumUsage(usages) } : {};
3893
4009
  if (error !== void 0) {
4010
+ const notes = storeWithoutIds();
4011
+ if (notes.length > 0) agent.advice = notes;
3894
4012
  return {
3895
4013
  vars: p.row.vars,
3896
4014
  output: null,
@@ -3911,7 +4029,11 @@ async function runAgentRow(p) {
3911
4029
  const signals = (mask?.value(friction) ?? friction).filter(
3912
4030
  (f) => !(f.type === "identical-retry" && covered.some((c) => c.tool === void 0 || c.tool === f.tool))
3913
4031
  );
3914
- const findings = [...advice, ...signals];
4032
+ const findings = [
4033
+ ...advice,
4034
+ ...signals,
4035
+ ...storeWithoutIds([...records, ...advice], assertionError)
4036
+ ];
3915
4037
  if (findings.length > 0) agent.advice = findings;
3916
4038
  const usage = sumUsage(usages);
3917
4039
  return {
@@ -4728,8 +4850,26 @@ var evalResultSchema = import_zod3.z.object({
4728
4850
  model: import_zod3.z.string().optional()
4729
4851
  }).optional(),
4730
4852
  /** The type and model of a cell of a multi-model run. Optional and additive. */
4731
- provider: import_zod3.z.object({ type: import_zod3.z.string(), model: import_zod3.z.string() }).optional()
4853
+ provider: import_zod3.z.object({ type: import_zod3.z.string(), model: import_zod3.z.string() }).optional(),
4854
+ /** The link to the eval's trace in your own observability (Langfuse, OTel). Optional and additive; `plune sync` drops one `traceUrlProblem` refuses. */
4855
+ traceUrl: import_zod3.z.string().optional()
4732
4856
  });
4857
+ var TRACE_URL_MAX = 2048;
4858
+ function traceUrlProblem(value) {
4859
+ if (typeof value !== "string") return "not a string";
4860
+ const url = value.trim();
4861
+ if (url.length > TRACE_URL_MAX) return `longer than ${TRACE_URL_MAX} characters`;
4862
+ if (!/^[^\s\p{Cc}\p{Cf}]+$/u.test(url)) return "must not contain spaces or control characters";
4863
+ let parsed2;
4864
+ try {
4865
+ parsed2 = new URL(url);
4866
+ } catch {
4867
+ return "must be an https address";
4868
+ }
4869
+ if (parsed2.protocol !== "https:" || parsed2.hostname === "") return "must be an https address";
4870
+ if (parsed2.username !== "" || parsed2.password !== "") return "must carry no user name or password";
4871
+ return void 0;
4872
+ }
4733
4873
  var runResultSchema = import_zod3.z.object({
4734
4874
  schemaVersion: import_zod3.z.literal(RUN_RESULT_SCHEMA_VERSION),
4735
4875
  plune_version: import_zod3.z.string(),
@@ -4900,7 +5040,7 @@ var SyncHttpError = class extends Error {
4900
5040
  }
4901
5041
  status;
4902
5042
  };
4903
- function readRun(cwd, file) {
5043
+ function readRun(cwd, file, warn) {
4904
5044
  const target = file !== void 0 ? path6.resolve(cwd, file) : path6.join(cwd, ".plune", "last-run.json");
4905
5045
  let raw;
4906
5046
  try {
@@ -4916,12 +5056,29 @@ function readRun(cwd, file) {
4916
5056
  } catch {
4917
5057
  throw new SyncFileError(`Run file is not valid JSON: ${target}`);
4918
5058
  }
5059
+ dropBadTraceLinks(json, warn);
4919
5060
  try {
4920
5061
  return parseRunResult(json);
4921
5062
  } catch {
4922
5063
  throw new SyncFileError(`Run file does not match the RunResult schema: ${target}`);
4923
5064
  }
4924
5065
  }
5066
+ function dropBadTraceLinks(json, warn) {
5067
+ const evals = json?.evals;
5068
+ if (!Array.isArray(evals)) return;
5069
+ for (const e of evals) {
5070
+ if (typeof e !== "object" || e === null || !("traceUrl" in e)) continue;
5071
+ const entry = e;
5072
+ const problem = traceUrlProblem(entry.traceUrl);
5073
+ if (problem === void 0) {
5074
+ entry.traceUrl = entry.traceUrl.trim();
5075
+ continue;
5076
+ }
5077
+ delete entry.traceUrl;
5078
+ warn(`plune: eval "${String(entry.id)}": trace link not sent (${problem}) \u2014 the eval is synced without it.
5079
+ `);
5080
+ }
5081
+ }
4925
5082
  async function safeErrorDetail(res) {
4926
5083
  try {
4927
5084
  const body = await res.json();
@@ -4935,7 +5092,7 @@ async function handleSync(deps = {}) {
4935
5092
  const apiUrl = resolveApiUrl(deps.apiUrl);
4936
5093
  const token = (deps.loadToken ?? loadToken)();
4937
5094
  if (token === null) throw new NotLoggedInError();
4938
- const run = readRun(cwd, deps.file);
5095
+ const run = readRun(cwd, deps.file, deps.warn ?? ((line) => process.stderr.write(line)));
4939
5096
  const doFetch = deps.fetchImpl ?? fetch;
4940
5097
  const endpoint = `${apiUrl}/v1/runs`;
4941
5098
  const payload = JSON.stringify(run);
package/dist/index.d.cts CHANGED
@@ -174,7 +174,10 @@ interface AgentCall {
174
174
  */
175
175
  error_kind?: 'content' | 'protocol' | 'timeout' | 'not-offered' | 'bad-arguments';
176
176
  duration_ms?: number;
177
- /** The answer as text: `bytes` is its size before `text` was cut to the stored excerpt. */
177
+ /**
178
+ * The answer as text: `bytes` is its size before `text` was cut to the stored excerpt. Identifier values in `text`
179
+ * and in `args` are stored as `"<id>"` (the checks read them first); see `ids-not-redacted` for a text answer.
180
+ */
178
181
  result?: {
179
182
  text: string;
180
183
  bytes: number;
@@ -694,6 +697,8 @@ interface SyncDeps {
694
697
  fetchImpl?: typeof fetch;
695
698
  /** `--fail-on-failures`: read the run's summary back once after the upload and judge it. */
696
699
  failOnFailures?: boolean;
700
+ /** Where a warning line goes (a trace link not sent). Defaults to stderr. */
701
+ warn?: (line: string) => void;
697
702
  }
698
703
  interface SyncResult {
699
704
  /** Server-assigned run id. */
@@ -1067,6 +1072,7 @@ declare const runResultSchema: z.ZodObject<{
1067
1072
  type: z.ZodString;
1068
1073
  model: z.ZodString;
1069
1074
  }, z.core.$strip>>;
1075
+ traceUrl: z.ZodOptional<z.ZodString>;
1070
1076
  }, z.core.$strip>>;
1071
1077
  }, z.core.$strip>;
1072
1078
  /**
package/dist/index.d.ts CHANGED
@@ -174,7 +174,10 @@ interface AgentCall {
174
174
  */
175
175
  error_kind?: 'content' | 'protocol' | 'timeout' | 'not-offered' | 'bad-arguments';
176
176
  duration_ms?: number;
177
- /** The answer as text: `bytes` is its size before `text` was cut to the stored excerpt. */
177
+ /**
178
+ * The answer as text: `bytes` is its size before `text` was cut to the stored excerpt. Identifier values in `text`
179
+ * and in `args` are stored as `"<id>"` (the checks read them first); see `ids-not-redacted` for a text answer.
180
+ */
178
181
  result?: {
179
182
  text: string;
180
183
  bytes: number;
@@ -694,6 +697,8 @@ interface SyncDeps {
694
697
  fetchImpl?: typeof fetch;
695
698
  /** `--fail-on-failures`: read the run's summary back once after the upload and judge it. */
696
699
  failOnFailures?: boolean;
700
+ /** Where a warning line goes (a trace link not sent). Defaults to stderr. */
701
+ warn?: (line: string) => void;
697
702
  }
698
703
  interface SyncResult {
699
704
  /** Server-assigned run id. */
@@ -1067,6 +1072,7 @@ declare const runResultSchema: z.ZodObject<{
1067
1072
  type: z.ZodString;
1068
1073
  model: z.ZodString;
1069
1074
  }, z.core.$strip>>;
1075
+ traceUrl: z.ZodOptional<z.ZodString>;
1070
1076
  }, z.core.$strip>>;
1071
1077
  }, z.core.$strip>;
1072
1078
  /**
package/dist/index.js CHANGED
@@ -1662,7 +1662,7 @@ function readHeader(headers, name) {
1662
1662
  }
1663
1663
  async function withRetry(fn, options) {
1664
1664
  const { base_delay_ms = 500, sleep: sleep2 = defaultSleep, random = Math.random } = options;
1665
- const maxRetries = Math.max(0, Math.floor(options.max_retries));
1665
+ const maxRetries = Number.isFinite(options.max_retries) ? Math.max(0, Math.floor(options.max_retries)) : 0;
1666
1666
  let attempt = 0;
1667
1667
  for (; ; ) {
1668
1668
  try {
@@ -3302,14 +3302,17 @@ var DEFAULT_MAX_TOKENS = 1024;
3302
3302
  function buildJudge(provider, cfg, onUsage) {
3303
3303
  return {
3304
3304
  async ask(prompt5) {
3305
+ const maxTokens = cfg.max_tokens ?? DEFAULT_MAX_TOKENS;
3305
3306
  const res = await provider.complete({
3306
3307
  provider: cfg.type,
3307
3308
  model: cfg.model,
3308
3309
  ...cfg.temperature !== void 0 ? { temperature: cfg.temperature } : {},
3309
- max_tokens: cfg.max_tokens ?? DEFAULT_MAX_TOKENS,
3310
+ max_tokens: maxTokens,
3310
3311
  prompt_resolved: prompt5
3311
3312
  });
3312
3313
  onUsage(res.usage);
3314
+ if (res.finish_reason === "length")
3315
+ throw new Error(`judge reply was cut off at max_tokens (${maxTokens}); raise max_tokens for the judge model`);
3313
3316
  return res.output;
3314
3317
  }
3315
3318
  };
@@ -3495,6 +3498,70 @@ function scanIds(result) {
3495
3498
  values: [...found.values].map(([hash, at]) => ({ hash, paths: [...at].sort() }))
3496
3499
  };
3497
3500
  }
3501
+ var ID_MARK = "<id>";
3502
+ 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;
3503
+ var redactUuids = (text) => text.replace(UUID_IN_TEXT, ID_MARK);
3504
+ var STR = String.raw`"(?:[^"\\]|\\.)*?(?:"|(?= \(cut\)))`;
3505
+ var NUM = String.raw`-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?`;
3506
+ var VAL = `(?:${STR}|${NUM})`;
3507
+ var PAIR = new RegExp(
3508
+ String.raw`"((?:[^"\\]|\\.)*)":(${VAL}|\[(?:${VAL}(?:,${VAL})*)?(?:\]|(?= \(cut\))))`,
3509
+ "g"
3510
+ );
3511
+ var redactReason = (text) => redactUuids(
3512
+ text.replace(
3513
+ PAIR,
3514
+ (whole, key) => isIdKey(key) ? `"${key}":${JSON.stringify(ID_MARK)}` : whole
3515
+ )
3516
+ );
3517
+ function strip(value, depth, st) {
3518
+ if (typeof value === "string") return redactUuids(value);
3519
+ if (depth > SCAN_DEPTH) {
3520
+ if (typeof value === "object" && value !== null) st.whole = false;
3521
+ return value;
3522
+ }
3523
+ if (Array.isArray(value)) {
3524
+ if (value.length > SCAN_ITEMS) st.whole = false;
3525
+ return value.map((v, i) => i < SCAN_ITEMS ? strip(v, depth + 1, st) : v);
3526
+ }
3527
+ if (!isRecord3(value)) return value;
3528
+ const out = {};
3529
+ for (const [key, v] of Object.entries(value)) {
3530
+ let name = redactUuids(key);
3531
+ for (let n = 2; name !== key && Object.hasOwn(out, name); n++) name = `${ID_MARK}#${n}`;
3532
+ 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);
3533
+ }
3534
+ return out;
3535
+ }
3536
+ function redactIds(value) {
3537
+ const st = { whole: true };
3538
+ return { value: strip(value, 0, st), whole: st.whole };
3539
+ }
3540
+ function redactAnswer(result) {
3541
+ let unread;
3542
+ const ids = (v) => {
3543
+ const r = redactIds(v);
3544
+ if (!r.whole)
3545
+ unread ??= `the answer is deeper than ${SCAN_DEPTH} levels or has more than ${SCAN_ITEMS} items in a list`;
3546
+ return r.value;
3547
+ };
3548
+ if (!isRecord3(result))
3549
+ return { result: ids(result), ...unread !== void 0 ? { unread } : {} };
3550
+ const out = { ...result };
3551
+ if (result.structuredContent !== void 0) out.structuredContent = ids(result.structuredContent);
3552
+ if (Array.isArray(result.content))
3553
+ out.content = result.content.map((block) => {
3554
+ if (!isRecord3(block) || block.type !== "text" || typeof block.text !== "string")
3555
+ return ids(block);
3556
+ try {
3557
+ return { ...block, text: JSON.stringify(ids(JSON.parse(block.text))) };
3558
+ } catch {
3559
+ unread ??= "the answer is not JSON";
3560
+ return { ...block, text: redactUuids(block.text) };
3561
+ }
3562
+ });
3563
+ return { result: out, ...unread !== void 0 ? { unread } : {} };
3564
+ }
3498
3565
  var list = (steps) => steps.join(", ");
3499
3566
  function frictionAdvice(calls) {
3500
3567
  const acc = /* @__PURE__ */ new Map();
@@ -3602,6 +3669,7 @@ function resultText(result) {
3602
3669
  (b) => isRecord4(b) && b.type === "text" && typeof b.text === "string" ? b.text : JSON.stringify(b)
3603
3670
  ).join("\n");
3604
3671
  }
3672
+ var firstBytes = (whole, keep) => whole.subarray(0, keep).toString("utf8").replace(/�$/, "");
3605
3673
  function excerpts() {
3606
3674
  let left = TRANSCRIPT_BYTES;
3607
3675
  const state = {
@@ -3612,7 +3680,7 @@ function excerpts() {
3612
3680
  left -= keep;
3613
3681
  const truncated = keep < whole.length;
3614
3682
  if (truncated) state.any = true;
3615
- const kept = truncated ? whole.subarray(0, keep).toString("utf8").replace(/�$/, "") : text;
3683
+ const kept = truncated ? firstBytes(whole, keep) : text;
3616
3684
  return { text: kept, bytes: whole.length, truncated };
3617
3685
  }
3618
3686
  };
@@ -3666,6 +3734,7 @@ async function runAgentRow(p) {
3666
3734
  let error;
3667
3735
  let session;
3668
3736
  const scanned = /* @__PURE__ */ new Map();
3737
+ const cleaned = /* @__PURE__ */ new Map();
3669
3738
  const overrides = p.toolDescriptions ?? {};
3670
3739
  const replaced = /* @__PURE__ */ new Set();
3671
3740
  try {
@@ -3811,6 +3880,17 @@ async function runAgentRow(p) {
3811
3880
  succeeded ||= !rec.is_error;
3812
3881
  if (got.kind === "result" && !rec.is_error) scanned.set(rec, scanIds(got.result));
3813
3882
  rec.result = kept.cut(text);
3883
+ if (got.kind === "result") {
3884
+ const r = redactAnswer(got.result);
3885
+ cleaned.set(rec, {
3886
+ text: resultText(r.result),
3887
+ ...r.unread !== void 0 ? { unread: r.unread } : {}
3888
+ });
3889
+ } else
3890
+ cleaned.set(rec, {
3891
+ text: redactUuids(text),
3892
+ unread: "the answer is an error message, not JSON"
3893
+ });
3814
3894
  answer(rec, c, text);
3815
3895
  }
3816
3896
  messages.push(
@@ -3851,8 +3931,46 @@ async function runAgentRow(p) {
3851
3931
  tool,
3852
3932
  sha256: sha256(overrides[tool])
3853
3933
  }));
3934
+ const storeWithoutIds = (said = [], err) => {
3935
+ for (const r of said) if (r.reason !== void 0) r.reason = redactReason(r.reason);
3936
+ if (err !== void 0) err.message = redactReason(err.message);
3937
+ const unread = /* @__PURE__ */ new Map();
3938
+ transcript.steps.forEach(
3939
+ (s, si) => s.calls.forEach((c, ci) => {
3940
+ const out = agent.steps[si].calls[ci];
3941
+ out.args = redactIds(out.args).value;
3942
+ const clean = cleaned.get(c);
3943
+ if (out.result === void 0 || clean === void 0) return;
3944
+ const whole = Buffer.from(mask?.text(clean.text) ?? clean.text, "utf8");
3945
+ const keep = Math.min(Buffer.byteLength(out.result.text, "utf8"), whole.length);
3946
+ out.result = {
3947
+ ...out.result,
3948
+ text: keep < whole.length ? firstBytes(whole, keep) : whole.toString("utf8"),
3949
+ truncated: out.result.truncated || keep < whole.length
3950
+ };
3951
+ if (out.result.truncated) agent.collection = "partial";
3952
+ if (clean.unread === void 0) return;
3953
+ const u = unread.get(c.name) ?? { steps: /* @__PURE__ */ new Set(), count: 0, why: clean.unread };
3954
+ u.steps.add(s.index);
3955
+ u.count++;
3956
+ unread.set(c.name, u);
3957
+ })
3958
+ );
3959
+ return [...unread].map(([tool, u]) => {
3960
+ const steps = [...u.steps].sort((x, y) => x - y);
3961
+ return {
3962
+ type: "ids-not-redacted",
3963
+ tool,
3964
+ steps,
3965
+ count: u.count,
3966
+ reason: `${tool}: ${u.why}, so only UUID-shaped values were replaced in its stored answer; other identifiers may remain (steps ${steps.join(", ")})`
3967
+ };
3968
+ });
3969
+ };
3854
3970
  const spent = usages.length > 0 ? { usage: sumUsage(usages) } : {};
3855
3971
  if (error !== void 0) {
3972
+ const notes = storeWithoutIds();
3973
+ if (notes.length > 0) agent.advice = notes;
3856
3974
  return {
3857
3975
  vars: p.row.vars,
3858
3976
  output: null,
@@ -3873,7 +3991,11 @@ async function runAgentRow(p) {
3873
3991
  const signals = (mask?.value(friction) ?? friction).filter(
3874
3992
  (f) => !(f.type === "identical-retry" && covered.some((c) => c.tool === void 0 || c.tool === f.tool))
3875
3993
  );
3876
- const findings = [...advice, ...signals];
3994
+ const findings = [
3995
+ ...advice,
3996
+ ...signals,
3997
+ ...storeWithoutIds([...records, ...advice], assertionError)
3998
+ ];
3877
3999
  if (findings.length > 0) agent.advice = findings;
3878
4000
  const usage = sumUsage(usages);
3879
4001
  return {
@@ -4690,8 +4812,26 @@ var evalResultSchema = z3.object({
4690
4812
  model: z3.string().optional()
4691
4813
  }).optional(),
4692
4814
  /** 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()
4815
+ provider: z3.object({ type: z3.string(), model: z3.string() }).optional(),
4816
+ /** The link to the eval's trace in your own observability (Langfuse, OTel). Optional and additive; `plune sync` drops one `traceUrlProblem` refuses. */
4817
+ traceUrl: z3.string().optional()
4694
4818
  });
4819
+ var TRACE_URL_MAX = 2048;
4820
+ function traceUrlProblem(value) {
4821
+ if (typeof value !== "string") return "not a string";
4822
+ const url = value.trim();
4823
+ if (url.length > TRACE_URL_MAX) return `longer than ${TRACE_URL_MAX} characters`;
4824
+ if (!/^[^\s\p{Cc}\p{Cf}]+$/u.test(url)) return "must not contain spaces or control characters";
4825
+ let parsed2;
4826
+ try {
4827
+ parsed2 = new URL(url);
4828
+ } catch {
4829
+ return "must be an https address";
4830
+ }
4831
+ if (parsed2.protocol !== "https:" || parsed2.hostname === "") return "must be an https address";
4832
+ if (parsed2.username !== "" || parsed2.password !== "") return "must carry no user name or password";
4833
+ return void 0;
4834
+ }
4695
4835
  var runResultSchema = z3.object({
4696
4836
  schemaVersion: z3.literal(RUN_RESULT_SCHEMA_VERSION),
4697
4837
  plune_version: z3.string(),
@@ -4862,7 +5002,7 @@ var SyncHttpError = class extends Error {
4862
5002
  }
4863
5003
  status;
4864
5004
  };
4865
- function readRun(cwd, file) {
5005
+ function readRun(cwd, file, warn) {
4866
5006
  const target = file !== void 0 ? path7.resolve(cwd, file) : path7.join(cwd, ".plune", "last-run.json");
4867
5007
  let raw;
4868
5008
  try {
@@ -4878,12 +5018,29 @@ function readRun(cwd, file) {
4878
5018
  } catch {
4879
5019
  throw new SyncFileError(`Run file is not valid JSON: ${target}`);
4880
5020
  }
5021
+ dropBadTraceLinks(json, warn);
4881
5022
  try {
4882
5023
  return parseRunResult(json);
4883
5024
  } catch {
4884
5025
  throw new SyncFileError(`Run file does not match the RunResult schema: ${target}`);
4885
5026
  }
4886
5027
  }
5028
+ function dropBadTraceLinks(json, warn) {
5029
+ const evals = json?.evals;
5030
+ if (!Array.isArray(evals)) return;
5031
+ for (const e of evals) {
5032
+ if (typeof e !== "object" || e === null || !("traceUrl" in e)) continue;
5033
+ const entry = e;
5034
+ const problem = traceUrlProblem(entry.traceUrl);
5035
+ if (problem === void 0) {
5036
+ entry.traceUrl = entry.traceUrl.trim();
5037
+ continue;
5038
+ }
5039
+ delete entry.traceUrl;
5040
+ warn(`plune: eval "${String(entry.id)}": trace link not sent (${problem}) \u2014 the eval is synced without it.
5041
+ `);
5042
+ }
5043
+ }
4887
5044
  async function safeErrorDetail(res) {
4888
5045
  try {
4889
5046
  const body = await res.json();
@@ -4897,7 +5054,7 @@ async function handleSync(deps = {}) {
4897
5054
  const apiUrl = resolveApiUrl(deps.apiUrl);
4898
5055
  const token = (deps.loadToken ?? loadToken)();
4899
5056
  if (token === null) throw new NotLoggedInError();
4900
- const run = readRun(cwd, deps.file);
5057
+ const run = readRun(cwd, deps.file, deps.warn ?? ((line) => process.stderr.write(line)));
4901
5058
  const doFetch = deps.fetchImpl ?? fetch;
4902
5059
  const endpoint = `${apiUrl}/v1/runs`;
4903
5060
  const payload = JSON.stringify(run);