agentfootprint-lens 0.35.0 → 0.37.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.
package/README.md CHANGED
@@ -503,6 +503,163 @@ pane.
503
503
 
504
504
  ---
505
505
 
506
+ ## Scrubbing by group — the active group is a named place
507
+
508
+ One causal trace, replayed at two zoom levels. On the **per-step** ruler each
509
+ commit is a stop; on the **grouped** ruler each boundary is a stop, and ◀ ▶ moves
510
+ a whole group at a time.
511
+
512
+ The chart used to paint both the same way, and that was wrong for the second one.
513
+ A stage's styling is by TYPE — the LLM call carries a hero emphasis (accent
514
+ border, tint, glow) and the cursor's one node pulses — so landing on a group of
515
+ six nodes pulled the eye to the LLM box. The group, the thing the ruler had
516
+ actually moved by, never read as the position at all.
517
+
518
+ Pass `granularity="group"` and it does:
519
+
520
+ - **one accent for every member.** An LLM call, a tool and a context pill light
521
+ identically — same tint, same intensity. What a node IS stays legible in its
522
+ icon and its shape; how loud it is no longer depends on its type.
523
+ - **everything else recedes uniformly** — one dim, not a second ranking.
524
+ - **a boundary is drawn around the members**, from their real measured positions,
525
+ with the group's **name** on its top edge. Scrubbing group to group animates it
526
+ (and doesn't, under `prefers-reduced-motion: reduce`).
527
+
528
+ The name is `groupDisplayName` — the same spelling the WHAT HAPPENED boundary
529
+ list uses. One place, one name.
530
+
531
+ ```tsx
532
+ <Lens recorder={recorder} runner={runner} granularity="group" />
533
+ ```
534
+
535
+ Or, in a shell that owns its own canvas and its own cursor:
536
+
537
+ ```tsx
538
+ import { LensFlow, useChartGroup } from 'agentfootprint-lens';
539
+
540
+ function WhyLensChart({ recorder, chart, cursorCommitIdx }) {
541
+ // The group the cursor stands in, as chart node ids. Derived from the
542
+ // boundary ranges the grouped ruler already computes its stops from —
543
+ // no extra fetch, no second cursor.
544
+ const group = useChartGroup(recorder, cursorCommitIdx);
545
+ return <LensFlow chart={chart} granularity="group" activeGroup={group} />;
546
+ }
547
+ ```
548
+
549
+ `granularity` defaults to `'step'`, and on that path nothing changes: no classes,
550
+ no boundary, the same chart the Flow Lens has always drawn. `'group'` at a commit
551
+ no boundary encloses also renders as `'step'` — a mode with nothing to draw draws
552
+ nothing, rather than boxing the whole chart.
553
+
554
+ Restyle it with one variable (`--lens-group-accent`, falling back to
555
+ `--fp-group-accent`), or target the classes directly: `.lens-group-node--member`,
556
+ `.lens-group-node--outsider`, `.lens-group-boundary`, `.lens-group-boundary-name`.
557
+
558
+ Headless: `activeChartGroup({ groups, commits, commitIdx })` on
559
+ `agentfootprint-lens/core` is the pure function behind the hook — same answer for
560
+ a Vue or CLI shell.
561
+
562
+ ---
563
+
564
+ ## Driving the cursor from your app
565
+
566
+ **Omitting these props keeps the lens self-driving.** It holds the position
567
+ itself, follows the live run, and needs nothing from you — that is the default
568
+ and it has not changed.
569
+
570
+ Pass `step` and you own the cursor. That is the difference between a lens that
571
+ happens to be on your page and a lens that is part of your app: two tabs can
572
+ show the same moment, a "jump to the failure" button in your own UI can move it,
573
+ and switching tabs no longer loses the position.
574
+
575
+ ```tsx
576
+ function Debugger({ recorder, runner }) {
577
+ // ONE cursor, held by you. Both lenses show the same moment.
578
+ const [step, setStep] = useState(0);
579
+
580
+ return (
581
+ <>
582
+ <Lens recorder={recorder} runner={runner} step={step} onStepChange={setStep} />
583
+ <Lens recorder={recorder} runner={runner} step={step} onStepChange={setStep} view="analyst" />
584
+ <button onClick={() => setStep(0)}>Back to the start</button>
585
+ </>
586
+ );
587
+ }
588
+ ```
589
+
590
+ Just want to *watch* the cursor? Pass `onStepChange` alone. The lens keeps
591
+ owning the state and calls you on every move — the same contract
592
+ `<TraceExplorerShell onSelectionChange>` has in `footprint-explainable-ui`.
593
+
594
+ ### The unit is a step, and the callback carries the rest
595
+
596
+ A **step** is one stop on the lens's scrub axis — the same number the transport
597
+ counts ("3 / 12"), the same one the WHAT HAPPENED rail dots. Valid values are
598
+ `0 … totalSteps - 1`, and `totalSteps` **grows** while a run is live.
599
+
600
+ Every call hands you the other two units of the same position, so you never
601
+ invert the mapping yourself:
602
+
603
+ ```ts
604
+ onStepChange(step, at)
605
+ // at = { step, totalSteps, runtimeStageId, commitIdx, label, kind?, clamped }
606
+ ```
607
+
608
+ - `at.runtimeStageId` — footprintjs's address, the string
609
+ `<TraceExplorerShell selectedRuntimeStageId>` and `<RunSlider cursorRuntimeStageId>` take.
610
+ - `at.commitIdx` — the commit-log index the position anchors to.
611
+
612
+ Why the step is the controlled unit and not one of those: it is the only one
613
+ that is **one-to-one** with a position the lens can show. A group's start and
614
+ its end are the same group, so "Run · start" and "Run · end" are both
615
+ `__root__#0`; a parallel fork's branches open at the same commit. Address the
616
+ cursor by either and the second of every such pair becomes unreachable — half
617
+ the positions silently unselectable, which is the exact failure this prop
618
+ exists to prevent.
619
+
620
+ Move it out of range and the lens **clamps and says so**: it renders the nearest
621
+ real position, calls `onStepChange(clamped, { clamped: true })`, and warns once
622
+ on the console. It clamps rather than refuses because the axis grows under you —
623
+ a step you stored from a finished run is a perfectly good value that the same
624
+ run, earlier, does not have yet. Store what the callback hands back and the two
625
+ cursors agree again.
626
+
627
+ Every mover reports: the step strip, ◀ ▶ ⟳Live, the arrow keys, a chart node
628
+ click, a WHAT HAPPENED moment, a provenance jump, and the auto-advance that
629
+ follows a live run. One cursor, one funnel — a mover that moved without telling
630
+ you would be a second cursor wearing the first one's clothes.
631
+
632
+ ---
633
+
634
+ ## Rendering your own detail pane
635
+
636
+ `slots.detail` replaces the CONTENT of the shipped right column. The column
637
+ itself — its width, its border, its collapse pill, its cursor — is unchanged.
638
+ Omit `slots` and the built-in timeline renders exactly as before.
639
+
640
+ ```tsx
641
+ const Detail: React.FC<LensDetailSlotProps> = ({ step, cursorRuntimeStageId, node, onNavigate }) => (
642
+ <div>
643
+ <h3>{node?.label ?? 'nothing focused'}</h3>
644
+ <code>{cursorRuntimeStageId}</code>
645
+ <button onClick={() => onNavigate(0)}>rewind</button>
646
+ </div>
647
+ );
648
+
649
+ <Lens recorder={recorder} runner={runner} slots={{ detail: Detail }} />
650
+ ```
651
+
652
+ The slot receives the cursor in every unit (`step`, `totalSteps`,
653
+ `cursorRuntimeStageId`, `commitIdx`, `label`, `kind`), the `StepNode` it sits on
654
+ and the ones that ran inside its scope (`node`, `relatedNodes`), the `recorder`
655
+ for anything else, and `onNavigate` — the same funnel every built-in mover uses,
656
+ so your pane moves the ONE cursor rather than starting a second one.
657
+
658
+ Keep the slots object stable across renders (module scope or `useMemo`), same as
659
+ `<TraceExplorerShell slots>`.
660
+
661
+ ---
662
+
506
663
  ## Theming
507
664
 
508
665
  **Lens inherits theme tokens from your app via CSS variables.** Set `--fp-*`
@@ -579,9 +736,22 @@ if a strict CSP blocks the automatic injection.
579
736
 
580
737
  ## Responsive
581
738
 
582
- Lens resizes to whatever space you give it. Below ~640px wide it stacks panels
583
- vertically (like `<ExplainableShell>` does). Drop it in a splitter, a drawer, or
584
- a full-screen tab — no config needed.
739
+ Lens resizes to whatever space you give it. The engineer view is a chart column
740
+ beside an inspector with a 300px minimum, and below **`LENS_NARROW_BREAKPOINT`
741
+ (690px of available row width)** that pair stops fitting — so the columns
742
+ **stack** instead of clipping. Nothing is hidden and nothing is cut off; the
743
+ same panes are read top to bottom instead of left to right. A split panel
744
+ dragged down to 392px gets a readable lens, not a sliver of one.
745
+
746
+ The threshold is exported, so a shell that lays out around Lens can use the same
747
+ number rather than guessing it:
748
+
749
+ ```ts
750
+ import { LENS_NARROW_BREAKPOINT, isNarrowRow } from 'agentfootprint-lens';
751
+ ```
752
+
753
+ Drop it in a splitter, a drawer, or a full-screen tab — no config needed, both
754
+ themes.
585
755
 
586
756
  ---
587
757
 
@@ -614,6 +784,28 @@ graph in one call. Returns an unsubscribe. Call it once per run.
614
784
  | `chart` | `LensFlowProps['chart']?` | Render YOUR graph instead of the derived one. |
615
785
  | `stepGraph` | `StepGraph?` | Bring your own step graph; by default Lens uses the recorder's. |
616
786
  | `toolChoice` | `ToolChoiceSource?` | Mount the per-iteration tool-choice panel. |
787
+ | `granularity` | `'step' \| 'group'?` | Which ruler is scrubbing the chart. `'group'` paints the cursor's group as a named place. Default `'step'`. See [Scrubbing by group](#scrubbing-by-group--the-active-group-is-a-named-place). |
788
+ | `step` | `number?` | Controlled cursor. **Omit it and the lens is self-driving, exactly as before.** Pass it and you own the position; out-of-range values are clamped and reported. See [Driving the cursor](#driving-the-cursor-from-your-app). |
789
+ | `onStepChange` | `(step, at) => void?` | Fires on every cursor move — required for movement in controlled mode, an observation hook otherwise. `at` carries `runtimeStageId`, `commitIdx`, `label`, `kind` and `clamped`. |
790
+ | `slots` | `LensSlots?` | Slot overrides. `slots.detail` renders your content in the shipped right column. Omit for the built-in timeline. See [Rendering your own detail pane](#rendering-your-own-detail-pane). |
791
+
792
+ ### `<LensFlow>` — the chart canvas on its own
793
+
794
+ The chart without the shell, for consumers who own their layout and their
795
+ cursor. Takes `chart`, the runtime overlay, the cursor, and — for the grouped
796
+ ruler — `granularity="group"` plus `activeGroup` (from `useChartGroup`). Every
797
+ other prop is unchanged by group mode.
798
+
799
+ ### `useChartGroup(recorder, commitIdx, options?)` / `activeChartGroup(...)`
800
+
801
+ The group the cursor stands in, resolved to CHART NODE IDS: the boundary's
802
+ commit range read off the recording, each commit's `runtimeStageId` stripped of
803
+ its `#executionIndex` (the id rule every chart-click and co-active highlight in
804
+ the ecosystem already uses), plus the group's own mount. Returns `undefined`
805
+ when no boundary encloses the cursor. `options.includeRoot` opts into the
806
+ synthetic Run root, which is off by default because a box around the whole chart
807
+ states nothing. `activeChartGroup` is the pure, React-free twin on
808
+ `agentfootprint-lens/core`.
617
809
 
618
810
  ### `observeRecording(recording, options?)`
619
811
 
@@ -2296,6 +2296,126 @@ function selectToolChoiceCall(calls, cursorRuntimeStageId, cursorKind) {
2296
2296
  return within ?? prev;
2297
2297
  }
2298
2298
 
2299
+ // src/core/group/groupDisplayName.ts
2300
+ function groupDisplayName(label) {
2301
+ const named = label.subflowName ?? label.compositionName ?? label.primitiveKind;
2302
+ if (named !== void 0 && named !== "") return named;
2303
+ if (label.type === "run.entry") return "Run";
2304
+ return label.runtimeStageId;
2305
+ }
2306
+ function groupDisplayNameForLabel(label) {
2307
+ return groupDisplayName(label);
2308
+ }
2309
+
2310
+ // src/core/group/Group.ts
2311
+ function groupContainsCommit(group, commitIdx) {
2312
+ if (commitIdx < group.opensAtCommitIdx) return false;
2313
+ if (group.closesAtCommitIdx === void 0) return true;
2314
+ return commitIdx <= group.closesAtCommitIdx;
2315
+ }
2316
+
2317
+ // src/core/group/activeChartGroup.ts
2318
+ function chartNodeIdOf(runtimeStageId) {
2319
+ const hash = runtimeStageId.lastIndexOf("#");
2320
+ return hash < 0 ? runtimeStageId : runtimeStageId.slice(0, hash);
2321
+ }
2322
+ function activeChartGroup(args) {
2323
+ const { groups, commits, commitIdx, includeRoot = false } = args;
2324
+ if (!Number.isFinite(commitIdx) || commitIdx < 0) return void 0;
2325
+ let best;
2326
+ for (const group of groups) {
2327
+ if (group.isRoot && !includeRoot) continue;
2328
+ if (!groupContainsCommit(group, commitIdx)) continue;
2329
+ if (best === void 0) {
2330
+ best = group;
2331
+ continue;
2332
+ }
2333
+ if (group.depth > best.depth) best = group;
2334
+ else if (group.depth === best.depth && group.opensAtCommitIdx >= best.opensAtCommitIdx) best = group;
2335
+ }
2336
+ if (best === void 0) return void 0;
2337
+ const memberNodeIds = /* @__PURE__ */ new Set();
2338
+ memberNodeIds.add(chartNodeIdOf(best.runtimeGroupId));
2339
+ const from = Math.max(0, best.opensAtCommitIdx);
2340
+ const to = Math.min(commits.length - 1, best.closesAtCommitIdx ?? commits.length - 1);
2341
+ for (let i = from; i <= to; i++) {
2342
+ const rid = commits[i]?.runtimeStageId;
2343
+ if (rid === void 0 || rid === "") continue;
2344
+ memberNodeIds.add(chartNodeIdOf(rid));
2345
+ }
2346
+ return {
2347
+ runtimeGroupId: best.runtimeGroupId,
2348
+ name: best.name,
2349
+ memberNodeIds,
2350
+ opensAtCommitIdx: best.opensAtCommitIdx,
2351
+ closesAtCommitIdx: best.closesAtCommitIdx,
2352
+ depth: best.depth
2353
+ };
2354
+ }
2355
+
2356
+ // src/core/group/buildGroups.ts
2357
+ function samePath(a, b) {
2358
+ return a.length === b.length && a.every((s, i) => s === b[i]);
2359
+ }
2360
+ function buildGroups(boundaryIndex) {
2361
+ const all = boundaryIndex.overlapping(0, Number.MAX_SAFE_INTEGER);
2362
+ if (all.length === 0) return [];
2363
+ const seen = /* @__PURE__ */ new Set();
2364
+ const result = [];
2365
+ for (let i = 0; i < all.length; i++) {
2366
+ const entry = all[i];
2367
+ const label = entry.label;
2368
+ if (seen.has(label.runtimeStageId)) continue;
2369
+ seen.add(label.runtimeStageId);
2370
+ let parentGroupId;
2371
+ if (label.type === "subflow.entry") {
2372
+ const enclosing = boundaryIndex.enclosing(entry.startIdx);
2373
+ const parentPath = label.subflowPath.slice(0, -1);
2374
+ for (let j = enclosing.length - 1; j >= 0; j--) {
2375
+ const cand = enclosing[j].label;
2376
+ if (cand.runtimeStageId === label.runtimeStageId) continue;
2377
+ if (samePath(cand.subflowPath, parentPath)) {
2378
+ parentGroupId = cand.runtimeStageId;
2379
+ break;
2380
+ }
2381
+ }
2382
+ if (parentGroupId === void 0) {
2383
+ for (let j = enclosing.length - 1; j >= 0; j--) {
2384
+ const cand = enclosing[j].label;
2385
+ if (cand.runtimeStageId === label.runtimeStageId) continue;
2386
+ parentGroupId = cand.runtimeStageId;
2387
+ break;
2388
+ }
2389
+ }
2390
+ } else if (label.type === "composition.start") {
2391
+ const enclosing = boundaryIndex.enclosing(entry.startIdx);
2392
+ for (let j = enclosing.length - 1; j >= 0; j--) {
2393
+ const cand = enclosing[j].label;
2394
+ if (cand.runtimeStageId === label.runtimeStageId) continue;
2395
+ parentGroupId = cand.runtimeStageId;
2396
+ break;
2397
+ }
2398
+ }
2399
+ const isRoot = label.type === "run.entry";
2400
+ const name = groupDisplayNameForLabel(label);
2401
+ const compositionKind = label.type === "composition.start" ? label.compositionKind : void 0;
2402
+ result.push({
2403
+ runtimeGroupId: label.runtimeStageId,
2404
+ name,
2405
+ parentGroupId,
2406
+ subflowPath: label.subflowPath,
2407
+ depth: label.depth,
2408
+ opensAtCommitIdx: entry.startIdx,
2409
+ closesAtCommitIdx: entry.endIdx,
2410
+ isRoot,
2411
+ ...compositionKind !== void 0 ? { compositionKind } : {},
2412
+ ...label.slotKind !== void 0 ? { slotKind: label.slotKind } : {},
2413
+ ...label.primitiveKind !== void 0 ? { primitiveKind: label.primitiveKind } : {}
2414
+ });
2415
+ }
2416
+ return result;
2417
+ }
2418
+
2299
2419
  // src/core/translate/helpers/makeNodeId.ts
2300
2420
  function makeRootNodeId(kind, id) {
2301
2421
  return `${kind.toLowerCase()}:${id}`;
@@ -3486,6 +3606,12 @@ export {
3486
3606
  selectCommentaryAt,
3487
3607
  selectCommentaryRanges,
3488
3608
  selectToolChoiceCall,
3609
+ groupDisplayName,
3610
+ groupDisplayNameForLabel,
3611
+ groupContainsCommit,
3612
+ chartNodeIdOf,
3613
+ activeChartGroup,
3614
+ buildGroups,
3489
3615
  makeRootNodeId,
3490
3616
  makeChildNodeId,
3491
3617
  translateAgent,
@@ -3525,4 +3651,4 @@ export {
3525
3651
  decisionSentence,
3526
3652
  isConsentDecision
3527
3653
  };
3528
- //# sourceMappingURL=chunk-PBRAJNVI.js.map
3654
+ //# sourceMappingURL=chunk-EGU4GZVH.js.map