@faithfulalabi/agent-lens 0.5.0 → 0.6.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.
@@ -128,6 +128,7 @@ export function readTurns(db, session_id) {
128
128
  }
129
129
  const EVENT_COLUMNS = `id, turn_id, seq, kind, ts, request_id, block_index, name, status,
130
130
  duration_ms, duration_source, input, input_bytes, input_storage,
131
+ wire_input, wire_input_bytes, wire_input_storage,
131
132
  text, text_bytes, output_storage, spill_path, spill_bytes,
132
133
  model, tokens_in, tokens_out, tokens_cache_read, tokens_cache_write, est_cost,
133
134
  child_session_id, agent_type, agent_status, raw_type, raw_subtype`;
@@ -1,4 +1,4 @@
1
- export const SCHEMA_VERSION = 3;
1
+ export const SCHEMA_VERSION = 4;
2
2
  export const SCHEMA_DDL = `-- ~/.agent-lens/cache.db
3
3
  --
4
4
  -- THIS FILE IS A CACHE. Every byte is a pure function of ~/.agent-lens/archive/** --
@@ -21,7 +21,7 @@ export const SCHEMA_DDL = `-- ~/.agent-lens/cache.db
21
21
  PRAGMA journal_mode = WAL;
22
22
  PRAGMA synchronous = NORMAL;
23
23
  PRAGMA foreign_keys = OFF; -- projections are dropped wholesale, per session, by hand
24
- PRAGMA user_version = 3; -- SCHEMA_VERSION; mismatch => unlink + recreate
24
+ PRAGMA user_version = 4; -- SCHEMA_VERSION; mismatch => unlink + recreate
25
25
 
26
26
  -- ===================================================================== sessions
27
27
  -- The file index AND the session-list row AND the projection freshness header,
@@ -227,6 +227,15 @@ CREATE TABLE events (
227
227
  -- tools.ts:118, unwitnessed by its own comment.
228
228
  -- 'line_ref' is live at exactly 1 row. Keep the
229
229
  -- arms; see task 0.12.
230
+
231
+ -- wireToolInputs[tool_use.id]: the form the harness SENT, which is not always the
232
+ -- form the model asked for. NULL means THE TWO AGREED -- never that nothing was
233
+ -- recorded. Storage words and the cap are input_storage's, written by the same
234
+ -- tools.ts:toolInput.
235
+ wire_input TEXT,
236
+ wire_input_bytes INTEGER,
237
+ wire_input_storage TEXT,
238
+
230
239
  text TEXT, -- prose / thinking / prompt / tool output
231
240
  text_bytes INTEGER,
232
241
  output_storage TEXT, -- inline | line_ref | spill | missing | absent
@@ -63,12 +63,13 @@ const INSERT_TURN_SQL = `INSERT INTO turns
63
63
  VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`;
64
64
  const INSERT_EVENT_SQL = `INSERT INTO events
65
65
  (id, session_id, turn_id, seq, kind, ts, request_id, block_index, name, status,
66
- duration_ms, duration_source, input, input_bytes, input_storage, text, text_bytes,
66
+ duration_ms, duration_source, input, input_bytes, input_storage,
67
+ wire_input, wire_input_bytes, wire_input_storage, text, text_bytes,
67
68
  output_storage, spill_path, spill_bytes, src_offset, src_len, result_offset,
68
69
  result_len, result_block, model, tokens_in, tokens_out, tokens_cache_read,
69
70
  tokens_cache_write, est_cost, child_session_id, agent_type, agent_status, raw_type,
70
71
  raw_subtype, attrs)
71
- VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`;
72
+ VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`;
72
73
  const POPULATE_FTS_SQL = `INSERT INTO events_fts(rowid, text, input)
73
74
  SELECT rowid, text, input FROM events WHERE session_id = ?`;
74
75
  const WRITE_HEADER_SQL = `UPDATE sessions SET
@@ -178,7 +179,7 @@ function insertEvents(db, events, spills) {
178
179
  cache_read: event.tokens_cache_read,
179
180
  cache_write: event.tokens_cache_write,
180
181
  });
181
- insert.run(event.id, event.session_id, event.turn_id, event.seq, event.kind, event.ts, event.request_id ?? null, event.block_index, event.name ?? null, event.status ?? null, event.duration_ms ?? null, event.duration_source ?? null, event.input ?? null, event.input_bytes ?? null, event.input_storage ?? null, event.text ?? null, event.text_bytes ?? null, output.output_storage, output.spill_path, output.spill_bytes, event.src_offset, event.src_len, event.result_offset ?? null, event.result_len ?? null, event.result_block ?? null, event.model ?? null, event.tokens_in ?? null, event.tokens_out ?? null, event.tokens_cache_read ?? null, event.tokens_cache_write ?? null, est_cost, event.child_session_id ?? null, event.agent_type ?? null, event.agent_status ?? null, event.raw_type, event.raw_subtype ?? null, event.attrs);
182
+ insert.run(event.id, event.session_id, event.turn_id, event.seq, event.kind, event.ts, event.request_id ?? null, event.block_index, event.name ?? null, event.status ?? null, event.duration_ms ?? null, event.duration_source ?? null, event.input ?? null, event.input_bytes ?? null, event.input_storage ?? null, event.wire_input ?? null, event.wire_input_bytes ?? null, event.wire_input_storage ?? null, event.text ?? null, event.text_bytes ?? null, output.output_storage, output.spill_path, output.spill_bytes, event.src_offset, event.src_len, event.result_offset ?? null, event.result_len ?? null, event.result_block ?? null, event.model ?? null, event.tokens_in ?? null, event.tokens_out ?? null, event.tokens_cache_read ?? null, event.tokens_cache_write ?? null, est_cost, event.child_session_id ?? null, event.agent_type ?? null, event.agent_status ?? null, event.raw_type, event.raw_subtype ?? null, event.attrs);
182
183
  }
183
184
  }
184
185
  function spillColumns(event, spills) {
@@ -4,7 +4,8 @@ import { contentBlocks } from '../transcript/blocks.js';
4
4
  import { isHumanPrompt, MACHINERY_TAGS } from '../transcript/human.js';
5
5
  import { foldControlLines, foldSessionEnvelope, promptGroupId, toolDenialKind, turnDurationMs, } from '../transcript/line.js';
6
6
  import { foldRequestGroup, groupByRequestId, modelOfRequestGroup, requestIdOf, } from '../transcript/usage.js';
7
- import { joinToolCalls, NO_INPUT, toolInput, } from './tools.js';
7
+ import { joinToolCalls, NO_INPUT, NO_WIRE_INPUT, toolInput, wireInput, } from './tools.js';
8
+ import { wireInputOf } from '../transcript/wire.js';
8
9
  const MAX_TITLE_CHARS = 200;
9
10
  const NO_BLOCKS = Object.freeze([]);
10
11
  const MS_PER_DAY = 86_400_000;
@@ -205,6 +206,9 @@ export function runPipeline(lines, ctx) {
205
206
  child_session_id: undefined,
206
207
  agent_type: undefined,
207
208
  ...(block?.kind === 'tool_use' ? toolInput(block.input) : NO_INPUT),
209
+ ...(block?.kind === 'tool_use'
210
+ ? wireInput(wireInputOf(line.raw, block.id), block.input)
211
+ : NO_WIRE_INPUT),
208
212
  text: kind === 'tool_call' ? undefined : (blockText(block) ?? lineText),
209
213
  text_bytes: undefined,
210
214
  output_storage: kind === 'tool_call' ? 'absent' : undefined,
@@ -1,4 +1,5 @@
1
1
  import { claimsPersistedOutput, } from '../transcript/agents.js';
2
+ import { sameValue } from '../transcript/wire.js';
2
3
  import { epochMs } from './pipeline.js';
3
4
  export const INLINE_MAX = 65536;
4
5
  export const PREVIEW_MAX = 8192;
@@ -7,6 +8,11 @@ export const NO_INPUT = Object.freeze({
7
8
  input_bytes: undefined,
8
9
  input_storage: undefined,
9
10
  });
11
+ export const NO_WIRE_INPUT = Object.freeze({
12
+ wire_input: undefined,
13
+ wire_input_bytes: undefined,
14
+ wire_input_storage: undefined,
15
+ });
10
16
  function byteLength(text) {
11
17
  return Buffer.byteLength(text, 'utf8');
12
18
  }
@@ -29,6 +35,16 @@ export function toolInput(input) {
29
35
  ? { input: headPreview(text), input_bytes: bytes, input_storage: 'line_ref' }
30
36
  : { input: text, input_bytes: bytes, input_storage: 'inline' };
31
37
  }
38
+ export function wireInput(wire, request) {
39
+ if (wire === undefined || sameValue(wire, request))
40
+ return NO_WIRE_INPUT;
41
+ const stored = toolInput(wire);
42
+ return {
43
+ wire_input: stored.input,
44
+ wire_input_bytes: stored.input_bytes,
45
+ wire_input_storage: stored.input_storage === 'line_ref' ? 'line_ref' : 'inline',
46
+ };
47
+ }
32
48
  function elapsedMs(call, result) {
33
49
  const ms = epochMs(result) - epochMs(call);
34
50
  return ms < 0 ? 0 : ms;
@@ -1 +1 @@
1
- export const PROJECTOR_VERSION = 12;
1
+ export const PROJECTOR_VERSION = 13;
@@ -0,0 +1,39 @@
1
+ import { arr, obj } from './accessors.js';
2
+ export function wireInputOf(raw, toolUseId) {
3
+ try {
4
+ const field = obj(obj(raw, undefined)?.wireToolInputs, undefined);
5
+ if (field === undefined || !Object.hasOwn(field, toolUseId))
6
+ return undefined;
7
+ return obj(field[toolUseId], undefined);
8
+ }
9
+ catch {
10
+ return undefined;
11
+ }
12
+ }
13
+ export function sameValue(a, b) {
14
+ try {
15
+ return same(a, b);
16
+ }
17
+ catch {
18
+ return true;
19
+ }
20
+ }
21
+ function same(a, b) {
22
+ if (a === b)
23
+ return true;
24
+ const aList = arr(a, undefined);
25
+ const bList = arr(b, undefined);
26
+ if (aList !== undefined || bList !== undefined) {
27
+ if (aList === undefined || bList === undefined || aList.length !== bList.length)
28
+ return false;
29
+ return aList.every((item, index) => same(item, bList[index]));
30
+ }
31
+ const aObj = obj(a, undefined);
32
+ const bObj = obj(b, undefined);
33
+ if (aObj === undefined || bObj === undefined)
34
+ return false;
35
+ const aKeys = Object.keys(aObj);
36
+ if (aKeys.length !== Object.keys(bObj).length)
37
+ return false;
38
+ return aKeys.every((key) => Object.hasOwn(bObj, key) && same(aObj[key], bObj[key]));
39
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faithfulalabi/agent-lens",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Local-first agentic tracing platform: inspect everything your agent did in a session.",
5
5
  "type": "module",
6
6
  "license": "MIT",