agentfootprint-lens 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sanjay Krishna Anbalagan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,227 @@
1
+ # agentfootprint-lens
2
+
3
+ > **See through your agent's decisions.**
4
+ >
5
+ > React components for debugging agents built on [`agentfootprint`](https://www.npmjs.com/package/agentfootprint): messages, prompt composition, tool calls, decision scope, and cost — in one scrub-able timeline.
6
+
7
+ [![npm version](https://img.shields.io/npm/v/agentfootprint-lens.svg)](https://www.npmjs.com/package/agentfootprint-lens)
8
+ [![license: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
9
+
10
+ ---
11
+
12
+ ## Why this exists
13
+
14
+ `footprint-explainable-ui` is the debugger for **pipelines** — stages, flowchart topology, commit log, data lineage. It's perfect for the person writing a footprintjs tool.
15
+
16
+ But an **agent** isn't a pipeline — it's a loop of (LLM call → parse → tool calls → repeat), steered by a decision scope and gated by skills. The questions an agent developer asks are different:
17
+
18
+ - "What prompt did the LLM actually see at iter 4?"
19
+ - "Why did the agent pick **this** tool over that one?"
20
+ - "Which skill was active when it went sideways?"
21
+ - "How many tokens did this turn cost me?"
22
+ - "What changed between turn 1 and the follow-up?"
23
+
24
+ **Lens** answers those. It reads `agent.getSnapshot()`, parses it into an agent-shaped timeline, and renders the agent-native surfaces:
25
+
26
+ 1. **Messages Panel** — chat bubbles with expandable tool-call cards, turn boundaries, iteration markers.
27
+ 2. **Iteration Strip** — horizontal ribbon of every LLM call in the run. Click to jump.
28
+ 3. **Tool Call Inspector** — flat sidebar of every tool invocation across all turns.
29
+
30
+ (phase-2: Prompt Composer, Decision Scope Ribbon, Cost & Latency Attribution.)
31
+
32
+ For tool-internal debugging (what did this tool's footprintjs flowchart actually do?), Lens composes [`footprint-explainable-ui`](https://www.npmjs.com/package/footprint-explainable-ui) as a drill-in drawer. The two libraries are siblings, not competitors.
33
+
34
+ ---
35
+
36
+ ## Install
37
+
38
+ ```bash
39
+ npm install agentfootprint-lens footprint-explainable-ui
40
+ ```
41
+
42
+ Peer deps: React 18+, `footprint-explainable-ui@^0.18.0`.
43
+
44
+ ---
45
+
46
+ ## Quick start
47
+
48
+ ```tsx
49
+ import { AgentLens } from 'agentfootprint-lens';
50
+ import { FootprintTheme, coolDark, coolLight } from 'footprint-explainable-ui';
51
+ import { Agent, anthropic } from 'agentfootprint';
52
+ import { useState, useEffect } from 'react';
53
+
54
+ export function MyApp() {
55
+ const [dark, setDark] = useState(true);
56
+ const [snapshot, setSnapshot] = useState(null);
57
+
58
+ useEffect(() => {
59
+ const agent = Agent.create({ provider: anthropic('claude-haiku-4-5') })
60
+ .system('You are a helpful agent.')
61
+ .build();
62
+ agent.run('What time is it?').then(() => setSnapshot(agent.getSnapshot()));
63
+ }, []);
64
+
65
+ return (
66
+ <FootprintTheme tokens={dark ? coolDark : coolLight}>
67
+ <div style={{ height: '100vh' }}>
68
+ <AgentLens runtimeSnapshot={snapshot} />
69
+ </div>
70
+ </FootprintTheme>
71
+ );
72
+ }
73
+ ```
74
+
75
+ That's it. Lens reads the same `FootprintTheme` context explainable-ui reads, so **the consumer owns theming** — flip `coolDark` ↔ `coolLight` at the app root and both the agent view (Lens) and any drill-in trace view (explainable-ui) follow together.
76
+
77
+ ---
78
+
79
+ ## Composition: drill-in to a tool's flowchart
80
+
81
+ Each tool in agentfootprint is typically a `flowChart<State>` underneath. When a user wants to debug *what that tool did internally*, open an explainable-ui drawer:
82
+
83
+ ```tsx
84
+ import { AgentLens, type AgentToolInvocation } from 'agentfootprint-lens';
85
+ import { ExplainableShell } from 'footprint-explainable-ui';
86
+
87
+ function Shell({ snapshot }) {
88
+ const [selected, setSelected] = useState<AgentToolInvocation | null>(null);
89
+ return (
90
+ <>
91
+ <AgentLens runtimeSnapshot={snapshot} onToolCallClick={setSelected} />
92
+ {selected && (
93
+ <Drawer onClose={() => setSelected(null)}>
94
+ <ExplainableShell
95
+ runtimeSnapshot={extractToolSubSnapshot(snapshot, selected.id)}
96
+ title={`${selected.name} · internals`}
97
+ />
98
+ </Drawer>
99
+ )}
100
+ </>
101
+ );
102
+ }
103
+ ```
104
+
105
+ Lens says "this is what the agent did." explainable-ui says "this is what each tool's flowchart did." Clean separation, no duplication.
106
+
107
+ ---
108
+
109
+ ## API surface
110
+
111
+ ### `<AgentLens>` — the one-stop shell
112
+
113
+ ```tsx
114
+ <AgentLens
115
+ runtimeSnapshot={agent.getSnapshot()}
116
+ onToolCallClick={(invocation) => /* open drill-in */}
117
+ />
118
+ ```
119
+
120
+ Props:
121
+ - `runtimeSnapshot` (any | null) — raw output of `agent.getSnapshot()`. Null renders an empty state.
122
+ - `timeline` (`AgentTimeline`) — pre-parsed timeline, overrides `runtimeSnapshot`. Useful for sharing across multiple Lens instances.
123
+ - `systemPrompt` (string) — override the system-prompt preview in MessagesPanel. Auto-derived from snapshot otherwise.
124
+ - `onToolCallClick` ((`AgentToolInvocation`) => void) — fires when any tool-call card is clicked.
125
+
126
+ ### Individual panels (composable)
127
+
128
+ - `<MessagesPanel timeline onToolCallClick systemPrompt />`
129
+ - `<IterationStrip timeline selectedKey onSelect />`
130
+ - `<ToolCallInspector timeline selectedId onSelect />`
131
+
132
+ ### Adapter
133
+
134
+ - `fromAgentSnapshot(runtimeSnapshot) → AgentTimeline` — pure function. Useful for non-UI consumers (eval scripts, exporters).
135
+
136
+ ### Theme
137
+
138
+ Lens reads `useFootprintTheme()` (from explainable-ui). Wrap your tree in `<FootprintTheme tokens={...}>` and Lens follows. No Lens-specific theme API.
139
+
140
+ ---
141
+
142
+ ## Data model
143
+
144
+ `AgentTimeline` is what Lens renders against. `fromAgentSnapshot` derives it from the raw runtime snapshot:
145
+
146
+ ```ts
147
+ interface AgentTimeline {
148
+ turns: AgentTurn[]; // one per agent.run() call
149
+ messages: AgentMessage[]; // full flat conversation
150
+ tools: AgentToolInvocation[]; // every tool call, across turns
151
+ finalDecision: Record<string, unknown>;
152
+ rawSnapshot: unknown; // escape hatch
153
+ }
154
+
155
+ interface AgentTurn {
156
+ index: number;
157
+ userPrompt: string;
158
+ iterations: AgentIteration[];
159
+ finalContent: string;
160
+ totalInputTokens: number;
161
+ totalOutputTokens: number;
162
+ totalDurationMs: number;
163
+ }
164
+
165
+ interface AgentIteration {
166
+ index: number;
167
+ model?: string;
168
+ inputTokens?: number;
169
+ outputTokens?: number;
170
+ durationMs?: number;
171
+ stopReason?: string;
172
+ assistantContent: string;
173
+ toolCalls: AgentToolInvocation[];
174
+ decisionAtStart: Record<string, unknown>;
175
+ matchedInstructions?: string[];
176
+ visibleTools: string[]; // tool names visible to the LLM that iter
177
+ }
178
+
179
+ interface AgentToolInvocation {
180
+ id: string;
181
+ name: string;
182
+ arguments: Record<string, unknown>;
183
+ result: string;
184
+ error?: boolean;
185
+ decisionUpdate?: Record<string, unknown>;
186
+ iterationIndex: number;
187
+ turnIndex: number;
188
+ durationMs?: number;
189
+ }
190
+ ```
191
+
192
+ ---
193
+
194
+ ## Roadmap
195
+
196
+ ### v0.1 (shipped)
197
+ - `<AgentLens>` shell + MessagesPanel + IterationStrip + ToolCallInspector
198
+ - Theme pass-through via FootprintTheme
199
+ - `fromAgentSnapshot` adapter
200
+
201
+ ### v0.2 — "why did the LLM decide that"
202
+ - **Prompt Composer** — assembled system prompt per iteration with diff-across-iterations highlighting (base + skill body + instruction injections + message window + tool list).
203
+ - **Decision Scope Ribbon** — horizontal pill timeline of decision scope fields; arrows back to the tool call that wrote each via `decisionUpdate`.
204
+
205
+ ### v0.3 — "is it shippable"
206
+ - **Cost & Latency Attribution** — token burn curve, per-iter/per-tool breakdown, pluggable price table.
207
+ - **Skill Dock** — loaded skills, activation state, tools-per-skill.
208
+
209
+ ### v1.0 — "Lens v1"
210
+ - Trace compare (two runs side-by-side)
211
+ - Eval grid (batch runs → pass/fail matrix)
212
+ - Exportable / importable traces via `TraceViewer` from explainable-ui
213
+
214
+ ---
215
+
216
+ ## Design decisions
217
+
218
+ - **Separate package, not a fork of explainable-ui.** Different audience (agent devs vs. pipeline/tool devs), different mental model (conversation loop vs. data-flow graph), different failure modes. Overloading explainable-ui would muddy both.
219
+ - **Theme via FootprintTheme context, not a Lens-specific prop.** One source of truth; automatic propagation to the drill-in drawer; consumers don't learn two theme APIs.
220
+ - **Adapter at the boundary.** `fromAgentSnapshot` is the single data-shape conversion. Panels render against the derived `AgentTimeline`, so agentfootprint's internal snapshot shape can evolve without breaking Lens.
221
+ - **No new agentfootprint library changes required to use Lens.** Every field Lens needs is already emitted today (messages, commitLog, recorder snapshots, emit events).
222
+
223
+ ---
224
+
225
+ ## License
226
+
227
+ MIT © Sanjay Krishna Anbalagan