@tangle-network/agent-runtime 0.121.0 → 0.123.1

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 (62) hide show
  1. package/dist/{activation-DdIpwQ0k.js → activation-DhWJ3p8N.js} +3 -3
  2. package/dist/{activation-DdIpwQ0k.js.map → activation-DhWJ3p8N.js.map} +1 -1
  3. package/dist/agent.d.ts +1 -1
  4. package/dist/agent.js +3 -3
  5. package/dist/candidate-execution/index.js +4 -4
  6. package/dist/{candidate-execution-DDkSRPjY.js → candidate-execution-BFpq-Xi6.js} +4 -4
  7. package/dist/{candidate-execution-DDkSRPjY.js.map → candidate-execution-BFpq-Xi6.js.map} +1 -1
  8. package/dist/{environment-provider-DChfYm2-.js → environment-provider-DqFS6FSZ.js} +6 -86
  9. package/dist/environment-provider-DqFS6FSZ.js.map +1 -0
  10. package/dist/{environment-provider-Bh4nX2qt.d.ts → environment-provider-PM9PeW_J.d.ts} +109 -11
  11. package/dist/environment-provider.d.ts +1 -1
  12. package/dist/environment-provider.js +1 -1
  13. package/dist/{improvement-cycle-zjR-MXwK.js → improvement-cycle-IJgCbKWQ.js} +6 -6
  14. package/dist/improvement-cycle-IJgCbKWQ.js.map +1 -0
  15. package/dist/{index-BLsKcxNd.d.ts → index-4NcThsDc.d.ts} +3 -3
  16. package/dist/{index-I35151Fr.d.ts → index-CQBioeAj.d.ts} +5 -5
  17. package/dist/{index-CGADWaa_.d.ts → index-xP27vtnt.d.ts} +1213 -849
  18. package/dist/index.d.ts +6 -6
  19. package/dist/index.js +12 -12
  20. package/dist/intelligence.d.ts +1 -1
  21. package/dist/intelligence.js +6 -6
  22. package/dist/kernel.d.ts +3 -3
  23. package/dist/kernel.js +7 -7
  24. package/dist/{knowledge-B1B3BsQZ.js → knowledge-BOHj6nGh.js} +5 -5
  25. package/dist/{knowledge-B1B3BsQZ.js.map → knowledge-BOHj6nGh.js.map} +1 -1
  26. package/dist/knowledge.d.ts +1 -1
  27. package/dist/knowledge.js +1 -1
  28. package/dist/{loop-runner-bin-BeG9vTdE.d.ts → loop-runner-bin-DMnNxZHw.d.ts} +3 -3
  29. package/dist/{loop-runner-bin-CXJWdfJ4.js → loop-runner-bin-DUM37LLw.js} +3 -3
  30. package/dist/{loop-runner-bin-CXJWdfJ4.js.map → loop-runner-bin-DUM37LLw.js.map} +1 -1
  31. package/dist/loop-runner-bin.d.ts +1 -1
  32. package/dist/loop-runner-bin.js +1 -1
  33. package/dist/mcp/bin.js +2 -2
  34. package/dist/mcp/index.d.ts +3 -3
  35. package/dist/mcp/index.js +5 -5
  36. package/dist/{openai-tools-CVgLNp04.js → openai-tools-Bm1SDJIp.js} +2 -2
  37. package/dist/{openai-tools-CVgLNp04.js.map → openai-tools-Bm1SDJIp.js.map} +1 -1
  38. package/dist/{prepare-DpV6np9e.js → prepare--8EvLqCr.js} +2 -2
  39. package/dist/{prepare-DpV6np9e.js.map → prepare--8EvLqCr.js.map} +1 -1
  40. package/dist/primeintellect/index.d.ts +1 -1
  41. package/dist/{protected-model-port-vQLBRoAQ.js → protected-model-port-CXVfOUu_.js} +2 -2
  42. package/dist/{protected-model-port-vQLBRoAQ.js.map → protected-model-port-CXVfOUu_.js.map} +1 -1
  43. package/dist/{runtime-Bp3NwC0A.js → runtime-DZblIf3R.js} +468 -56
  44. package/dist/runtime-DZblIf3R.js.map +1 -0
  45. package/dist/{spawn-journal-IeXpidO2.js → spawn-journal-DsZKDqeh.js} +5 -3
  46. package/dist/spawn-journal-DsZKDqeh.js.map +1 -0
  47. package/dist/{structural-rollout-DQHO3b2Y.js → structural-rollout-zY0oqQzO.js} +3 -3
  48. package/dist/{structural-rollout-DQHO3b2Y.js.map → structural-rollout-zY0oqQzO.js.map} +1 -1
  49. package/dist/{supervise-BHHMtwP9.js → supervise-Cx24b3lw.js} +480 -92
  50. package/dist/supervise-Cx24b3lw.js.map +1 -0
  51. package/dist/{supervisor-CpT9yAxL.js → supervisor-DpjO0Gmy.js} +231 -29
  52. package/dist/supervisor-DpjO0Gmy.js.map +1 -0
  53. package/dist/testing.js +12 -12
  54. package/dist/{workspace-archive-B4SkNJjw.js → workspace-archive-BQxvkypI.js} +2 -2
  55. package/dist/{workspace-archive-B4SkNJjw.js.map → workspace-archive-BQxvkypI.js.map} +1 -1
  56. package/package.json +10 -9
  57. package/dist/environment-provider-DChfYm2-.js.map +0 -1
  58. package/dist/improvement-cycle-zjR-MXwK.js.map +0 -1
  59. package/dist/runtime-Bp3NwC0A.js.map +0 -1
  60. package/dist/spawn-journal-IeXpidO2.js.map +0 -1
  61. package/dist/supervise-BHHMtwP9.js.map +0 -1
  62. package/dist/supervisor-CpT9yAxL.js.map +0 -1
@@ -1,8 +1,8 @@
1
- import { c as RuntimeRunStateError, u as ValidationError } from "./errors-DEAvWQPy.js";
2
- import { S as detachedSnapshot, _ as captureWorkerTraceEvidence, c as replaySpawnTree, f as attestNestedDriverTreeOwner, h as runtimeOwnedNestedDriverTreeRoot, m as nestedDriverTreeRoot, o as materializeTreeView, p as driverRuntime, s as pendingWaits, x as contentAddress } from "./spawn-journal-IeXpidO2.js";
1
+ import { c as RuntimeRunStateError, i as ConfigError, u as ValidationError } from "./errors-DEAvWQPy.js";
2
+ import { S as detachedSnapshot, _ as captureWorkerTraceEvidence, c as replaySpawnTree, f as attestNestedDriverTreeOwner, h as runtimeOwnedNestedDriverTreeRoot, m as nestedDriverTreeRoot, o as materializeTreeView, p as driverRuntime, s as pendingWaits, x as contentAddress } from "./spawn-journal-DsZKDqeh.js";
3
3
  import { f as zeroTokenUsage, t as addTokenUsage } from "./util-MVgdwuIS.js";
4
4
  import { i as notifyRuntimeHookEvent } from "./runtime-hooks-C7iJOWm3.js";
5
- import { estimateCost, isModelPriced } from "@tangle-network/agent-eval";
5
+ import { HARNESS_NATIVE_MODEL, estimateCost, isModelPriced } from "@tangle-network/agent-eval";
6
6
  import { AGENT_PROFILE_MATERIALIZATION_AXES, agentProfileSchema, canonicalCandidateDigest, profileMaterializationAxes, sha256DigestSchema } from "@tangle-network/agent-interface";
7
7
  import { createHash, randomUUID } from "node:crypto";
8
8
  import { applyWorkspacePlan, hashWorkspacePlan, materializeProfile, resolveAgentProfileResources } from "@tangle-network/agent-profile-materialize";
@@ -12,6 +12,67 @@ import { basename, delimiter, dirname, isAbsolute, join, resolve, sep, win32 } f
12
12
  import { spawn } from "node:child_process";
13
13
  import { homedir, tmpdir } from "node:os";
14
14
  import { stripVTControlCharacters } from "node:util";
15
+ import { deriveHexId, isW3CSpanId, isW3CTraceId } from "@tangle-network/agent-trace-contract";
16
+ //#region src/runtime/supervise/model-policy.ts
17
+ /**
18
+ * `assertModelAllowed` — a fail-loud guard that restricts a run to a chosen subset of
19
+ * models. The two front doors (`supervise()` / `improve()`) call it once per configured
20
+ * model at resolve time, so a run that names a model outside the allowed set throws before
21
+ * any compute is spent — never silently swapped or silently allowed.
22
+ */
23
+ /**
24
+ * Return the model id an executor may send to a provider.
25
+ *
26
+ * Eval stamps {@link HARNESS_NATIVE_MODEL} into a profile when model selection is deliberately
27
+ * delegated to the configured runtime. That marker belongs in experiment identity and cost
28
+ * admission; it is not a provider model id.
29
+ */
30
+ function concreteModelId(model) {
31
+ if (model === void 0) return void 0;
32
+ const id = model.trim();
33
+ return id.length > 0 && !isHarnessNativeModel(id) ? id : void 0;
34
+ }
35
+ /** Whether a model value delegates selection to the chosen execution system. */
36
+ function isHarnessNativeModel(model) {
37
+ return model?.trim() === HARNESS_NATIVE_MODEL;
38
+ }
39
+ /** Return a profile's explicitly selected provider model, if it has one. */
40
+ function concreteProfileModel(profile) {
41
+ return concreteModelId(profile.model?.default);
42
+ }
43
+ /**
44
+ * Remove only Eval's runtime-selected model marker before a profile crosses an execution boundary.
45
+ * Every other model hint remains intact, including provider, reasoning effort, and small-model
46
+ * preferences. The input profile is never mutated.
47
+ */
48
+ function profileForExecution(profile) {
49
+ const model = profile.model;
50
+ if (!isHarnessNativeModel(model?.default) || model === void 0) return profile;
51
+ const { default: _runtimeSelected, ...remainingModel } = model;
52
+ const { model: _model, ...remainingProfile } = profile;
53
+ return Object.keys(remainingModel).length > 0 ? {
54
+ ...remainingProfile,
55
+ model: remainingModel
56
+ } : remainingProfile;
57
+ }
58
+ /**
59
+ * Throw a `ConfigError` when `allowed` is set, `model` is defined, and `model` is not a
60
+ * member of `allowed`. No-op when `allowed` is unset (the unrestricted default) or when
61
+ * `model` is undefined (nothing was configured to check).
62
+ */
63
+ function assertModelAllowed(model, allowed) {
64
+ if (!allowed || model === void 0) return;
65
+ if (!allowed.includes(model)) throw new ConfigError(`model ${JSON.stringify(model)} is not in the allowed set ${JSON.stringify([...allowed])}`);
66
+ }
67
+ /** Check every canonical model-bearing field in a complete profile, including the models a
68
+ * backend may select for cheap work, named subagents, or modes. */
69
+ function assertProfileModelsAllowed(profile, allowed) {
70
+ assertModelAllowed(profile.model?.default, allowed);
71
+ assertModelAllowed(profile.model?.small, allowed);
72
+ for (const subagent of Object.values(profile.subagents ?? {})) assertModelAllowed(subagent.model, allowed);
73
+ for (const mode of Object.values(profile.modes ?? {})) assertModelAllowed(mode.model, allowed);
74
+ }
75
+ //#endregion
15
76
  //#region src/mcp/codex-diagnostics.ts
16
77
  /** Thrown when reproducible Codex exits without one valid terminal usage event. */
17
78
  var CodexExecutionDiagnosticError = class extends Error {
@@ -289,8 +350,7 @@ function harnessInvocation(harness, profile, taskPrompt, options = {}) {
289
350
  const invocation = HARNESS_INVOCATIONS[harness];
290
351
  if (!invocation) throw new Error(`harnessInvocation: unknown harness ${String(harness)}`);
291
352
  if (options.codexReproducible) {
292
- const model = profile.model?.default;
293
- if (typeof model !== "string" || model.trim().length === 0) throw new Error("harnessInvocation: codexReproducible requires profile.model.default");
353
+ if (!concreteProfileModel(profile)) throw new Error("harnessInvocation: codexReproducible requires profile.model.default");
294
354
  if (profile.model?.reasoningEffort === void 0) throw new Error("harnessInvocation: codexReproducible requires profile.model.reasoningEffort");
295
355
  }
296
356
  const systemPrompt = profile.prompt?.systemPrompt;
@@ -302,8 +362,8 @@ function harnessInvocation(harness, profile, taskPrompt, options = {}) {
302
362
  taskPrompt
303
363
  ].join("\n\n");
304
364
  const args = buildHarnessArgs(harness, composedPrompt, options);
305
- const model = profile.model?.default;
306
- if (typeof model === "string" && model.length > 0) args.push(...invocation.modelArgs(model));
365
+ const model = concreteProfileModel(profile);
366
+ if (model) args.push(...invocation.modelArgs(model));
307
367
  const reasoningEffort = profile.model?.reasoningEffort;
308
368
  if (reasoningEffort !== void 0) args.push(...harnessReasoningArgs(harness, reasoningEffort));
309
369
  return {
@@ -4391,11 +4451,30 @@ function toOtelAttributes(record) {
4391
4451
  function msToNs(ms) {
4392
4452
  return (BigInt(Math.floor(Number.isFinite(ms) ? ms : Date.now())) * 1000000n).toString();
4393
4453
  }
4454
+ /**
4455
+ * Map a caller-supplied span id onto the 16-hex OTLP encoding. An id that is already a valid W3C
4456
+ * span id passes through UNCHANGED — that is what lets an inherited `PARENT_SPAN_ID`/`TRACEPARENT`
4457
+ * id keep parenting the same trace. A DASHED hex id (a UUID-form id) passes through dash-stripped:
4458
+ * that is the exact wire id every earlier release exported for it, so cross-version joins survive
4459
+ * the strict-W3C upgrade. Anything else (a human run id) is DERIVED via the zero-dep contract's
4460
+ * `deriveHexId`, the one legal derivation: the old slice-and-pad produced ids that embedded the
4461
+ * raw input in the wire id and were not even valid hex (the contract's own `non-hex-id` validator
4462
+ * rejected what this module exported). Exported as the ONE wire-id normalization every writer
4463
+ * shares — `traceContextToEnv` builds the child's `TRACEPARENT` through these same functions, so
4464
+ * a parent's exported spans and the context it hands its children always name the same trace.
4465
+ */
4394
4466
  function padSpanId(id) {
4395
- return id.replace(/-/g, "").slice(0, 16).padEnd(16, "0");
4467
+ if (isW3CSpanId(id)) return id;
4468
+ const dashless = id.replace(/-/g, "");
4469
+ return isW3CSpanId(dashless) ? dashless : deriveHexId(id, 8);
4396
4470
  }
4471
+ /** Trace-id counterpart of {@link padSpanId}: valid W3C trace ids pass through (dash-stripped when
4472
+ * UUID-form, preserving the pre-strict-W3C wire id), everything else is derived with
4473
+ * `deriveHexId(id, 16)` so every process derives the SAME wire id for the same run. */
4397
4474
  function padTraceId(id) {
4398
- return id.replace(/-/g, "").slice(0, 32).padEnd(32, "0");
4475
+ if (isW3CTraceId(id)) return id;
4476
+ const dashless = id.replace(/-/g, "");
4477
+ return isW3CTraceId(dashless) ? dashless : deriveHexId(id, 16);
4399
4478
  }
4400
4479
  /** Mint a fresh 16-hex-character OTLP span id. Exported so a producer that must know a span's id
4401
4480
  * BEFORE the span closes (a node opened at spawn and parented by its children) uses this one
@@ -4452,18 +4531,63 @@ async function exportEvalRuns(events, config) {
4452
4531
  //#endregion
4453
4532
  //#region src/mcp/trace-propagation.ts
4454
4533
  /**
4455
- * Read trace context from the process environment.
4456
- * Returns a context with inherited ids or a freshly generated root.
4534
+ *
4535
+ * Trace context propagation across process-spawn boundaries.
4536
+ *
4537
+ * CANONICAL WIRE: the W3C `TRACEPARENT` environment variable
4538
+ * (`00-<32 hex trace id>-<16 hex span id>-<2 hex flags>`), the convention the wider ecosystem —
4539
+ * OTel SDKs, collectors, the Claude Code harness binary — already reads at spawn. The bespoke
4540
+ * `TRACE_ID` / `PARENT_SPAN_ID` pair this package shipped first is the FORK, not the standard:
4541
+ * it is still read as a fallback and still written alongside `TRACEPARENT` for one release, so
4542
+ * a child running either version of this package joins the same trace. The legacy pair is
4543
+ * scheduled for removal in the next major.
4544
+ *
4545
+ * read: TRACEPARENT first, then TRACE_ID / PARENT_SPAN_ID, else a fresh root.
4546
+ * write: BOTH — TRACEPARENT (+ TRACESTATE untouched) and TRACE_ID / PARENT_SPAN_ID.
4547
+ *
4548
+ * A fresh root minted because NO context reached this process is a severed hop, not a normal
4549
+ * start: it is marked `unpropagated: true` and every span tree it emits carries
4550
+ * `tangle.trace.unpropagated=true`, so a disconnected trace is a queryable fact instead of a
4551
+ * silent stranger.
4552
+ *
4553
+ * @experimental
4457
4554
  */
4458
- function readTraceContextFromEnv() {
4555
+ /** `00-<traceId>-<spanId>-<flags>`, any version prefix, case-insensitive per the W3C grammar. */
4556
+ const TRACEPARENT_PATTERN = /^[0-9a-f]{2}-([0-9a-f]{32})-([0-9a-f]{16})-[0-9a-f]{2}$/i;
4557
+ /** Parse a W3C `traceparent` header/env value, or `undefined` when malformed. Fails closed: a
4558
+ * half-formed value yields no context rather than an unjoinable id. */
4559
+ function parseTraceparent(value) {
4560
+ if (typeof value !== "string") return void 0;
4561
+ const match = TRACEPARENT_PATTERN.exec(value.trim());
4562
+ if (!match) return void 0;
4563
+ const traceId = match[1].toLowerCase();
4564
+ const parentSpanId = match[2].toLowerCase();
4565
+ if (!isW3CTraceId(traceId) || !isW3CSpanId(parentSpanId)) return void 0;
4459
4566
  return {
4460
- traceId: process.env.TRACE_ID || generateTraceId(),
4461
- parentSpanId: process.env.PARENT_SPAN_ID || void 0
4567
+ traceId,
4568
+ parentSpanId
4569
+ };
4570
+ }
4571
+ /**
4572
+ * Read trace context from a process environment (defaults to `process.env`).
4573
+ * `TRACEPARENT` wins; the legacy `TRACE_ID` / `PARENT_SPAN_ID` pair is the fallback; with
4574
+ * neither present a fresh root is generated AND marked `unpropagated` — see {@link TraceContext}.
4575
+ */
4576
+ function readTraceContextFromEnv(env = process.env) {
4577
+ const fromTraceparent = parseTraceparent(env.TRACEPARENT);
4578
+ if (fromTraceparent) return fromTraceparent;
4579
+ if (env.TRACE_ID) return {
4580
+ traceId: env.TRACE_ID,
4581
+ ...env.PARENT_SPAN_ID ? { parentSpanId: env.PARENT_SPAN_ID } : {}
4582
+ };
4583
+ return {
4584
+ traceId: generateTraceId(),
4585
+ unpropagated: true
4462
4586
  };
4463
4587
  }
4464
4588
  /**
4465
4589
  * Create a LoopTraceEmitter that:
4466
- * 1. Parents all spans under the inherited PARENT_SPAN_ID.
4590
+ * 1. Parents all spans under the inherited parent span id.
4467
4591
  * 2. Exports spans to OTEL when OTEL_EXPORTER_OTLP_ENDPOINT is set.
4468
4592
  *
4469
4593
  * Returns both the emitter and the optional exporter handle for shutdown.
@@ -4480,7 +4604,13 @@ function createPropagatingTraceEmitter(ctx) {
4480
4604
  if (event.kind === "loop.ended") {
4481
4605
  const events = buffers.get(event.runId) ?? [event];
4482
4606
  buffers.delete(event.runId);
4483
- for (const span of buildLoopOtelSpans(events, ctx.traceId, ctx.parentSpanId)) exporter.exportSpan(span);
4607
+ for (const span of buildLoopOtelSpans(events, ctx.traceId, ctx.parentSpanId)) exporter.exportSpan(ctx.unpropagated === true ? {
4608
+ ...span,
4609
+ attributes: [...span.attributes ?? [], {
4610
+ key: "tangle.trace.unpropagated",
4611
+ value: { boolValue: true }
4612
+ }]
4613
+ } : span);
4484
4614
  }
4485
4615
  } },
4486
4616
  exporter,
@@ -4488,14 +4618,49 @@ function createPropagatingTraceEmitter(ctx) {
4488
4618
  };
4489
4619
  }
4490
4620
  /**
4491
- * Build env vars to pass to a child MCP subprocess so it inherits the
4492
- * current trace context.
4621
+ * Build env vars to pass to a child subprocess so it inherits the current trace context.
4622
+ *
4623
+ * Writes BOTH conventions (see the module doc): `TRACEPARENT` carries the W3C-hex ids — mapped
4624
+ * through the exporter's own `padTraceId`/`padSpanId` (dashed hex passes through dash-stripped, a
4625
+ * human id is derived through the contract's `deriveHexId`), the SAME normalization every emitted
4626
+ * span uses, so both spellings and the parent's own spans all name ONE trace — and the legacy
4627
+ * pair carries the caller's ids verbatim. `TRACEPARENT` needs a parent span id by grammar; when
4628
+ * the context has none, the legacy pair still propagates the trace id alone.
4493
4629
  */
4494
4630
  function traceContextToEnv(ctx) {
4495
4631
  const env = { TRACE_ID: ctx.traceId };
4496
4632
  if (ctx.parentSpanId) env.PARENT_SPAN_ID = ctx.parentSpanId;
4633
+ if (ctx.parentSpanId) env.TRACEPARENT = `00-${padTraceId(ctx.traceId)}-${padSpanId(ctx.parentSpanId)}-01`;
4497
4634
  return env;
4498
4635
  }
4636
+ /**
4637
+ * Merge a spawned child's environment from lowest to highest precedence — ambient env, the
4638
+ * recorder's stamped trace env, the caller's own overrides — while keeping the ONE cross-key
4639
+ * invariant a plain spread cannot: `TRACEPARENT` and the legacy pair must name the SAME trace.
4640
+ * A caller override that declares `TRACE_ID` / `PARENT_SPAN_ID` without its own `TRACEPARENT`
4641
+ * would otherwise keep the recorder's W3C wire — the child would join the caller's trace on the
4642
+ * legacy pair and the RECORDER's on the standard one. The dual-write is performed on the
4643
+ * caller's behalf: the merged `TRACEPARENT` is rebuilt from the merged legacy pair through the
4644
+ * same {@link traceContextToEnv} derivation (`deriveHexId` for human ids), or dropped when no
4645
+ * parent span id survives the merge (the W3C grammar requires one).
4646
+ */
4647
+ function mergeTraceEnv(ambient, traceEnv, overrides) {
4648
+ const merged = {
4649
+ ...ambient,
4650
+ ...traceEnv,
4651
+ ...overrides ?? {}
4652
+ };
4653
+ if (!(overrides !== void 0 && overrides.TRACEPARENT === void 0 && (overrides.TRACE_ID !== void 0 || overrides.PARENT_SPAN_ID !== void 0))) return merged;
4654
+ delete merged.TRACEPARENT;
4655
+ if (merged.TRACE_ID !== void 0) {
4656
+ const rewritten = traceContextToEnv({
4657
+ traceId: merged.TRACE_ID,
4658
+ ...merged.PARENT_SPAN_ID !== void 0 ? { parentSpanId: merged.PARENT_SPAN_ID } : {}
4659
+ });
4660
+ if (rewritten.TRACEPARENT !== void 0) merged.TRACEPARENT = rewritten.TRACEPARENT;
4661
+ }
4662
+ return merged;
4663
+ }
4499
4664
  function generateTraceId() {
4500
4665
  const bytes = /* @__PURE__ */ new Uint8Array(16);
4501
4666
  if (typeof globalThis.crypto?.getRandomValues === "function") globalThis.crypto.getRandomValues(bytes);
@@ -4513,11 +4678,13 @@ function generateTraceId() {
4513
4678
  * parent's trace id and the spawning node's span id emits spans that JOIN the parent's trace, and
4514
4679
  * the viewer assembles the whole cross-machine tree with no viewer change.
4515
4680
  *
4516
- * NO NEW FORMAT. The wire is the env-var convention this package already ships and already reads:
4517
- * `TRACE_ID` / `PARENT_SPAN_ID`, written by {@link traceContextToEnv} and read back by
4518
- * `readTraceContextFromEnv()` (`src/mcp/trace-propagation.ts`). Nothing here invents a second
4519
- * encoding; W3C `traceparent` would be the standard alternative, but adopting it alongside this one
4520
- * would fork the contract, and the reader for THIS one is already in the package.
4681
+ * THE WIRE IS W3C `TRACEPARENT`, dual-written with the legacy pair. `traceContextToEnv`
4682
+ * (`src/mcp/trace-propagation.ts`) writes `TRACEPARENT` (the convention the ecosystem OTel SDKs,
4683
+ * collectors, the Claude Code harness binary — reads at spawn) ALONGSIDE the bespoke
4684
+ * `TRACE_ID` / `PARENT_SPAN_ID` pair this package shipped first, and `readTraceContextFromEnv()`
4685
+ * reads `TRACEPARENT` first with the legacy pair as fallback. The bespoke pair is the fork, not
4686
+ * the standard; it is kept for one release so children on the previous package version still join,
4687
+ * then removed in the next major.
4521
4688
  *
4522
4689
  * WHICH SPAN. The stamped `PARENT_SPAN_ID` is the span of the node that DID the spawning — the
4523
4690
  * scope's own `parentId` — not the span of the worker's own node. At depth 0 that is the run's root
@@ -4545,7 +4712,10 @@ function generateTraceId() {
4545
4712
  * 2. the trace context stamped here,
4546
4713
  * 3. the caller's own seam env (`CliSeam.env`).
4547
4714
  * A caller who sets `TRACE_ID` / `PARENT_SPAN_ID` on a seam wins — theirs is a deliberate
4548
- * declaration about the worker. Ambient `process.env` does NOT win: when the supervisor process was
4715
+ * declaration about the worker and the W3C wire follows: a seam that overrides the legacy pair
4716
+ * without its own `TRACEPARENT` gets `TRACEPARENT` rebuilt from ITS ids (`mergeTraceEnv` performs
4717
+ * the dual-write on the caller's behalf), never left as the recorder's, so both spellings always
4718
+ * name the same trace. Ambient `process.env` does NOT win: when the supervisor process was
4549
4719
  * itself launched as someone's worker, its inherited ids describe the SUPERVISOR's place in an
4550
4720
  * outer trace, and reusing them for a child would file the child's spans under the wrong parent.
4551
4721
  * The supported way to join that outer trace is `SupervisorSpanOptions.traceId` / `parentSpanId`
@@ -4566,6 +4736,23 @@ function generateTraceId() {
4566
4736
  * - `provider` NO — `AgentEnvironmentProvider` has no environment field on its port.
4567
4737
  */
4568
4738
  /**
4739
+ * The census above, as a value the compiler checks. `satisfies` against every `ExecutorConfig`
4740
+ * discriminant means an EIGHTH backend arm cannot be added without classifying it here — the prose
4741
+ * alone could go stale silently, which is the failure this table exists to prevent.
4742
+ *
4743
+ * `true` = the arm has a real environment channel to the worker and stamps the context.
4744
+ * `false` = it has none today; it is honestly unpropagated rather than silently dropping.
4745
+ */
4746
+ const WORKER_TRACE_PROPAGATION = {
4747
+ cli: true,
4748
+ sandbox: true,
4749
+ router: false,
4750
+ "router-tools": false,
4751
+ bridge: false,
4752
+ "cli-worktree": false,
4753
+ provider: false
4754
+ };
4755
+ /**
4569
4756
  * Seam key the `Scope` seeds a {@link TraceContext} under on each child's `ExecutorContext.seams`.
4570
4757
  * Single-sourced here so the scope and every backend agree on it without a circular import — the
4571
4758
  * same arrangement `nestedScopeSeamKey` uses.
@@ -4587,7 +4774,8 @@ function readWorkerTraceContext(ctx) {
4587
4774
  };
4588
4775
  }
4589
4776
  /**
4590
- * The `TRACE_ID` / `PARENT_SPAN_ID` pair to merge into a worker's environment — EMPTY when the run
4777
+ * The trace env to merge into a worker's environment — `TRACEPARENT` plus the legacy
4778
+ * `TRACE_ID` / `PARENT_SPAN_ID` pair (dual-written for one release) — EMPTY when the run
4591
4779
  * records no spans, which is what keeps the untraced path byte-identical. Merge it BELOW the
4592
4780
  * caller's own seam env so a deliberately-set id wins (see the precedence note above).
4593
4781
  */
@@ -4657,6 +4845,7 @@ function makeNestedScopeSeam(args, liveWorkerCapacity, childNodeId, childBudget,
4657
4845
  ...args.now ? { now: args.now } : {},
4658
4846
  ...args.hooks ? { hooks: args.hooks } : {},
4659
4847
  ...args.workerTrace ? { workerTrace: args.workerTrace } : {},
4848
+ ...args.workerTraceUnpropagated ? { workerTraceUnpropagated: args.workerTraceUnpropagated } : {},
4660
4849
  ...deferredOwner.ownerMaterialization === void 0 ? {} : { ownerMaterialization: deferredOwner.ownerMaterialization }
4661
4850
  });
4662
4851
  }
@@ -4917,6 +5106,17 @@ function createScope(args) {
4917
5106
  ...identity ? { identity } : {},
4918
5107
  seq: ordinal,
4919
5108
  at: new Date(now()).toISOString()
5109
+ }).then(async () => {
5110
+ if (args.workerTraceUnpropagated === void 0 || workerTrace === void 0) return;
5111
+ await args.journal.appendEvent(args.root, {
5112
+ kind: "trace-unpropagated",
5113
+ id,
5114
+ expectedTraceId: workerTrace.traceId,
5115
+ backend: args.workerTraceUnpropagated.backend,
5116
+ reason: args.workerTraceUnpropagated.reason,
5117
+ seq: ordinal,
5118
+ at: new Date(now()).toISOString()
5119
+ });
4920
5120
  }).then(async () => {
4921
5121
  const profileDigest = identity?.profileDigest ?? authoredProfileDigest(spec.profile);
4922
5122
  let receipt;
@@ -6659,7 +6859,7 @@ function describeRejection(error) {
6659
6859
  function createSupervisor() {
6660
6860
  let attached;
6661
6861
  async function run(root, task, opts) {
6662
- const { budget, rootIdentity, rootMaterialization, runId, journal: journalStore, blobs: blobStore, executors: executorRegistry, probes, maxDepth, maxLiveWorkers, maxRestarts, withinMs, resume, now: suppliedNow, signal, hooks, workerTrace } = opts;
6862
+ const { budget, rootIdentity, rootMaterialization, runId, journal: journalStore, blobs: blobStore, executors: executorRegistry, probes, maxDepth, maxLiveWorkers, maxRestarts, withinMs, resume, now: suppliedNow, signal, hooks, workerTrace, workerTraceUnpropagated } = opts;
6663
6863
  const input = detachedSnapshot({
6664
6864
  task,
6665
6865
  options: {
@@ -6683,7 +6883,8 @@ function createSupervisor() {
6683
6883
  ...suppliedNow === void 0 ? {} : { now: suppliedNow },
6684
6884
  ...signal === void 0 ? {} : { signal },
6685
6885
  ...hooks === void 0 ? {} : { hooks },
6686
- ...workerTrace === void 0 ? {} : { workerTrace }
6886
+ ...workerTrace === void 0 ? {} : { workerTrace },
6887
+ ...workerTraceUnpropagated === void 0 ? {} : { workerTraceUnpropagated }
6687
6888
  });
6688
6889
  task = input.task;
6689
6890
  const rootAct = root.act.bind(root);
@@ -6790,6 +6991,7 @@ function createSupervisor() {
6790
6991
  } } : {},
6791
6992
  ...opts.probes ? { probes: opts.probes } : {},
6792
6993
  ...opts.workerTrace ? { workerTrace: opts.workerTrace } : {},
6994
+ ...opts.workerTraceUnpropagated ? { workerTraceUnpropagated: opts.workerTraceUnpropagated } : {},
6793
6995
  ...resumeFrom ? { resumeFrom } : {}
6794
6996
  });
6795
6997
  const openScope = scope;
@@ -7186,6 +7388,6 @@ function isNonEmptySpend(s) {
7186
7388
  return s.iterations > 0 || s.tokens.input > 0 || s.tokens.output > 0 || s.usd > 0 || s.ms > 0 || s.tokensKnown === false || s.usdKnown === false;
7187
7389
  }
7188
7390
  //#endregion
7189
- export { WORKER_TOKEN_FLOOR as $, loopEventToOtelSpan as A, promptControlProfileMaterialization as At, timerAt as B, harnessInvocation as Bt, buildLoopSpanNodes as C, removeWorktree as Ct, exportEvalRuns as D, defineProfileMaterializationContract as Dt, createOtelExporter as E, controlProfileMaterialization as Et, sanitizeKnowledgeReadinessReport as F, sandboxActProfileMaterialization as Ft, describeToolArgs as G, CodexExecutionDiagnosticError as Gt, waitUntil as H, localHarnessExecutable as Ht, sanitizeRuntimeStreamEvent as I, validateProfileMaterialization as It, freeSlots as J, readWorkerProgress as K, createWaitProbes as L, worktreeCliProfileMaterialization as Lt, createRuntimeEventCollector as M, promptOnlyProfileMaterialization as Mt, createRuntimeStreamEventCollector as N, promptResourceProfileMaterialization as Nt, flatOtelSpan as O, fullProfileMaterialization as Ot, sanitizeAgentRuntimeEvent as P, renderProfileMaterializationIssues as Pt, teardownExecutor as Q, isWaitOutcome as R, DEFAULT_LOCAL_HARNESS as Rt, buildLoopOtelSpans as S, createWorktree as St, createOpenInferenceFileExporter as T, assertProfileMaterialization as Tt, DEFAULT_STALL_AFTER_MS as U, parseCodexTokenUsage as Ut, validateWaitSpec as V, harnessSupportsReasoningEffort as Vt, createActivityLog as W, runLocalHarness as Wt, rollingDispatch as X, queueOf as Y, DEFAULT_SUCCESSFUL_SHUTDOWN_MS as Z, workerTraceSeamKey as _, runSettledCommand as _t, pickBestDelivered as a, attestRuntimeOwnedScopeOwner as at, traceContextToEnv as b, worktreeProfileExecutionPlan as bt, driverChild as c, runtimeOwnedExecutorExecutionBinding as ct, deriveNodeExecutionIdentity as d, routerBrain as dt, workerTokenFloor as et, recordScopeOwnerMaterialization as f, routerChatWithTools as ft, workerTraceEnv as g, runBrainLoop as gt, readWorkerTraceContext as h, streamRouterChatWithTools as ht, collectDelivered as i, attestRuntimeOwnedExecutor as it, toOtelAttributes as j, promptModelProfileMaterialization as jt, generateSpanId as k, profileMaterializationAxes as kt, withDriverExecutor as l, runtimeOwnedExecutorMaterialization as lt, settledToIteration as m, routerToolLoop as mt, createSupervisor as n, createBudgetPool as nt, runFinalizer as o, inheritRuntimeOwnedExecutorAttestation as ot, scopeOwnerExecutorNodeContext as p, routerChatWithUsage as pt, effectiveConcurrency as q, bestDelivered as r, spendFromUsageEvents as rt, runTree as s, newExecutionAttemptId as st, createRootHandle as t, assertValidBudget as tt, createScope as u, runtimeOwnedScopeOwnerRuntime as ut, createPropagatingTraceEmitter as v, runWorktreeChecks as vt, buildRuntimeEventOtelSpans as w, AGENT_PROFILE_MATERIALIZATION_AXES as wt, INTELLIGENCE_WIRE_VERSION as x, captureWorktreeDiff as xt, readTraceContextFromEnv as y, runWorktreeHarness as yt, pollFor as z, LOCAL_HARNESSES as zt };
7391
+ export { queueOf as $, concreteProfileModel as $t, flatOtelSpan as A, controlProfileMaterialization as At, sanitizeRuntimeStreamEvent as B, validateProfileMaterialization as Bt, INTELLIGENCE_WIRE_VERSION as C, runWorktreeHarness as Ct, createOpenInferenceFileExporter as D, removeWorktree as Dt, buildRuntimeEventOtelSpans as E, createWorktree as Et, toOtelAttributes as F, promptModelProfileMaterialization as Ft, validateWaitSpec as G, harnessSupportsReasoningEffort as Gt, isWaitOutcome as H, DEFAULT_LOCAL_HARNESS as Ht, createRuntimeEventCollector as I, promptOnlyProfileMaterialization as It, createActivityLog as J, runLocalHarness as Jt, waitUntil as K, localHarnessExecutable as Kt, createRuntimeStreamEventCollector as L, promptResourceProfileMaterialization as Lt, loopEventToOtelSpan as M, fullProfileMaterialization as Mt, padSpanId as N, profileMaterializationAxes as Nt, createOtelExporter as O, AGENT_PROFILE_MATERIALIZATION_AXES as Ot, padTraceId as P, promptControlProfileMaterialization as Pt, freeSlots as Q, concreteModelId as Qt, sanitizeAgentRuntimeEvent as R, renderProfileMaterializationIssues as Rt, traceContextToEnv as S, runWorktreeChecks as St, buildLoopSpanNodes as T, captureWorktreeDiff as Tt, pollFor as U, LOCAL_HARNESSES as Ut, createWaitProbes as V, worktreeCliProfileMaterialization as Vt, timerAt as W, harnessInvocation as Wt, readWorkerProgress as X, assertModelAllowed as Xt, describeToolArgs as Y, CodexExecutionDiagnosticError as Yt, effectiveConcurrency as Z, assertProfileModelsAllowed as Zt, workerTraceEnv as _, routerChatWithUsage as _t, pickBestDelivered as a, assertValidBudget as at, mergeTraceEnv as b, runBrainLoop as bt, driverChild as c, attestRuntimeOwnedExecutor as ct, deriveNodeExecutionIdentity as d, newExecutionAttemptId as dt, isHarnessNativeModel as en, rollingDispatch as et, recordScopeOwnerMaterialization as f, runtimeOwnedExecutorExecutionBinding as ft, readWorkerTraceContext as g, routerChatWithTools as gt, WORKER_TRACE_PROPAGATION as h, routerBrain as ht, collectDelivered as i, workerTokenFloor as it, generateSpanId as j, defineProfileMaterializationContract as jt, exportEvalRuns as k, assertProfileMaterialization as kt, withDriverExecutor as l, attestRuntimeOwnedScopeOwner as lt, settledToIteration as m, runtimeOwnedScopeOwnerRuntime as mt, createSupervisor as n, teardownExecutor as nt, runFinalizer as o, createBudgetPool as ot, scopeOwnerExecutorNodeContext as p, runtimeOwnedExecutorMaterialization as pt, DEFAULT_STALL_AFTER_MS as q, parseCodexTokenUsage as qt, bestDelivered as r, WORKER_TOKEN_FLOOR as rt, runTree as s, spendFromUsageEvents as st, createRootHandle as t, profileForExecution as tn, DEFAULT_SUCCESSFUL_SHUTDOWN_MS as tt, createScope as u, inheritRuntimeOwnedExecutorAttestation as ut, workerTraceSeamKey as v, routerToolLoop as vt, buildLoopOtelSpans as w, worktreeProfileExecutionPlan as wt, readTraceContextFromEnv as x, runSettledCommand as xt, createPropagatingTraceEmitter as y, streamRouterChatWithTools as yt, sanitizeKnowledgeReadinessReport as z, sandboxActProfileMaterialization as zt };
7190
7392
 
7191
- //# sourceMappingURL=supervisor-CpT9yAxL.js.map
7393
+ //# sourceMappingURL=supervisor-DpjO0Gmy.js.map