@rulvar/cli 1.116.0 → 1.117.0

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 (2) hide show
  1. package/dist/index.js +31 -9
  2. package/package.json +7 -7
package/dist/index.js CHANGED
@@ -850,11 +850,15 @@ function createWorker(engine, options) {
850
850
  * agent > tool > child), with start/end timestamps from the lifecycle
851
851
  * events; each agent:phase pair additionally becomes a child span of
852
852
  * its agent span keyed (spanId, invocation), carrying the phase's role,
853
- * model, usage, and cost. Events without an own span (log,
854
- * budget:update) attach as span events on their enclosing span. An
855
- * opener for an already-open span never duplicates it (replayed
856
- * re-emissions mark the original; a pre-RV-207 stream's extra per-phase
857
- * agent:start cannot leak the agent span unended).
853
+ * model, usage, and cost, and each tool execution becomes a child span
854
+ * of its agent span under a synthetic FIFO pair key (RV802: tool events
855
+ * ride the agent's spanId and carry no per-call id), so the agent span
856
+ * lives to agent:end and keeps its closing usage, cost, and exploration
857
+ * attributes. Events without an own span (log, budget:update) attach as
858
+ * span events on their enclosing span. An opener for an already-open
859
+ * span never duplicates it (replayed re-emissions mark the original; a
860
+ * pre-RV-207 stream's extra per-phase agent:start cannot leak the agent
861
+ * span unended).
858
862
  *
859
863
  * `@opentelemetry/api` ^1.9 is an OPTIONAL peer: the CLI has no OTel
860
864
  * dependency, and the exporter is typed against a minimal structural
@@ -868,7 +872,6 @@ const SPAN_OPENERS = /* @__PURE__ */ new Set([
868
872
  "run:start",
869
873
  "phase:start",
870
874
  "agent:start",
871
- "tool:start",
872
875
  "child:start"
873
876
  ]);
874
877
  function msOf(ts) {
@@ -934,6 +937,9 @@ async function toOtel(run, tracer, options = {}) {
934
937
  const openBySpanId = /* @__PURE__ */ new Map();
935
938
  const stack = [];
936
939
  let created = 0;
940
+ let toolMint = 0;
941
+ const openToolPairs = /* @__PURE__ */ new Map();
942
+ const toolPairOf = (spanId, toolName) => `${spanId} ${toolName}`;
937
943
  const { contextApi, setSpan } = options;
938
944
  const masker = options.patterns === void 0 ? void 0 : compileSecretMasker(options.patterns, "toOtel patterns");
939
945
  const maskText = (text) => masker === void 0 ? maskSecrets(text) : masker.maskText(text);
@@ -1009,10 +1015,26 @@ async function toOtel(run, tracer, options = {}) {
1009
1015
  endSpan(event.spanId, event.ts, event.status);
1010
1016
  break;
1011
1017
  }
1012
- case "tool:end":
1013
- if (event.guard !== void 0) openBySpanId.get(event.spanId)?.span.setAttribute("rulvar.tool.guard", event.guard);
1014
- endSpan(event.spanId, event.ts, event.outcome);
1018
+ case "tool:start": {
1019
+ const key = `${event.spanId}#tool${String(toolMint)}`;
1020
+ toolMint += 1;
1021
+ const pair = toolPairOf(event.spanId, event.toolName);
1022
+ const fifo = openToolPairs.get(pair);
1023
+ if (fifo === void 0) openToolPairs.set(pair, [key]);
1024
+ else fifo.push(key);
1025
+ startSpan(event, key, event.spanId);
1015
1026
  break;
1027
+ }
1028
+ case "tool:end": {
1029
+ const key = openToolPairs.get(toolPairOf(event.spanId, event.toolName))?.shift();
1030
+ if (key === void 0) {
1031
+ (openBySpanId.get(event.spanId) ?? stack[stack.length - 1])?.span.addEvent(event.type, { "rulvar.entry_seq": event.seq });
1032
+ break;
1033
+ }
1034
+ if (event.guard !== void 0) openBySpanId.get(key)?.span.setAttribute("rulvar.tool.guard", event.guard);
1035
+ endSpan(key, event.ts, event.outcome);
1036
+ break;
1037
+ }
1016
1038
  case "child:end":
1017
1039
  endSpan(event.spanId, event.ts, event.status);
1018
1040
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rulvar/cli",
3
- "version": "1.116.0",
3
+ "version": "1.117.0",
4
4
  "description": "Rulvar shell: run/resume/runs/inspect/plan/kb commands, TUI progress, createServer, createWorker, OTel exporter.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -22,17 +22,17 @@
22
22
  "access": "public"
23
23
  },
24
24
  "dependencies": {
25
- "@rulvar/core": "1.116.0"
25
+ "@rulvar/core": "1.117.0"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@types/node": "^22.20.1",
29
29
  "tsdown": "^0.22.14",
30
30
  "typescript": "~6.0.3",
31
- "@rulvar/testing": "1.116.0",
32
- "@rulvar/store-sqlite": "1.116.0",
33
- "@rulvar/planner": "1.116.0",
34
- "@rulvar/evals": "1.116.0",
35
- "@rulvar/plan": "1.116.0"
31
+ "@rulvar/testing": "1.117.0",
32
+ "@rulvar/store-sqlite": "1.117.0",
33
+ "@rulvar/planner": "1.117.0",
34
+ "@rulvar/plan": "1.117.0",
35
+ "@rulvar/evals": "1.117.0"
36
36
  },
37
37
  "bin": {
38
38
  "rulvar": "./dist/cli.js"