agentfootprint-lens 0.52.2 → 0.53.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.
@@ -3022,10 +3022,189 @@ function servedRowForEpoch(recording, epoch) {
3022
3022
  return rowOf(recording, locations, at, false);
3023
3023
  }
3024
3024
 
3025
+ // src/core/served/sincePrevious.ts
3026
+ import { messageDigestInput } from "agentfootprint";
3027
+
3028
+ // src/core/utils/diffPrompts.ts
3029
+ function tokenize(s) {
3030
+ if (s.length === 0) return [];
3031
+ const matches = s.match(/\S+|\s+/g);
3032
+ return matches ?? [];
3033
+ }
3034
+ function lcsDiff(a, b) {
3035
+ const n = a.length;
3036
+ const m = b.length;
3037
+ if (n === 0 && m === 0) return [];
3038
+ if (n === 0) return [{ kind: "added", text: b.join("") }];
3039
+ if (m === 0) return [{ kind: "removed", text: a.join("") }];
3040
+ const dp = [];
3041
+ for (let i2 = 0; i2 <= n; i2++) dp.push(new Uint32Array(m + 1));
3042
+ for (let i2 = n - 1; i2 >= 0; i2--) {
3043
+ for (let j2 = m - 1; j2 >= 0; j2--) {
3044
+ if (a[i2] === b[j2]) {
3045
+ dp[i2][j2] = dp[i2 + 1][j2 + 1] + 1;
3046
+ } else {
3047
+ dp[i2][j2] = Math.max(dp[i2 + 1][j2], dp[i2][j2 + 1]);
3048
+ }
3049
+ }
3050
+ }
3051
+ const segments = [];
3052
+ let curKind;
3053
+ let curText = "";
3054
+ const push = (kind, text) => {
3055
+ if (kind === curKind) {
3056
+ curText += text;
3057
+ } else {
3058
+ if (curKind !== void 0 && curText.length > 0) {
3059
+ segments.push({ kind: curKind, text: curText });
3060
+ }
3061
+ curKind = kind;
3062
+ curText = text;
3063
+ }
3064
+ };
3065
+ let i = 0;
3066
+ let j = 0;
3067
+ while (i < n && j < m) {
3068
+ if (a[i] === b[j]) {
3069
+ push("equal", a[i]);
3070
+ i++;
3071
+ j++;
3072
+ } else if (dp[i + 1][j] >= dp[i][j + 1]) {
3073
+ push("removed", a[i]);
3074
+ i++;
3075
+ } else {
3076
+ push("added", b[j]);
3077
+ j++;
3078
+ }
3079
+ }
3080
+ while (i < n) {
3081
+ push("removed", a[i]);
3082
+ i++;
3083
+ }
3084
+ while (j < m) {
3085
+ push("added", b[j]);
3086
+ j++;
3087
+ }
3088
+ if (curKind !== void 0 && curText.length > 0) {
3089
+ segments.push({ kind: curKind, text: curText });
3090
+ }
3091
+ return segments;
3092
+ }
3093
+ var DIFF_CELL_CAP = 625e4;
3094
+ function commonHead(a, b) {
3095
+ const max = Math.min(a.length, b.length);
3096
+ let n = 0;
3097
+ while (n < max && a[n] === b[n]) n++;
3098
+ return n;
3099
+ }
3100
+ function commonTail(a, b, head) {
3101
+ const max = Math.min(a.length, b.length) - head;
3102
+ let n = 0;
3103
+ while (n < max && a[a.length - 1 - n] === b[b.length - 1 - n]) n++;
3104
+ return n;
3105
+ }
3106
+ function joinSegments(parts) {
3107
+ const out = [];
3108
+ for (const part of parts) {
3109
+ for (const s of part) {
3110
+ if (s.text.length === 0) continue;
3111
+ const last = out[out.length - 1];
3112
+ if (last !== void 0 && last.kind === s.kind) {
3113
+ out[out.length - 1] = { kind: last.kind, text: last.text + s.text };
3114
+ } else {
3115
+ out.push(s);
3116
+ }
3117
+ }
3118
+ }
3119
+ return out;
3120
+ }
3121
+ function diffPromptsBounded(a, b, maxCells = DIFF_CELL_CAP) {
3122
+ if (a === b) {
3123
+ return a.length === 0 ? [] : [{ kind: "equal", text: a }];
3124
+ }
3125
+ const ta = tokenize(a);
3126
+ const tb = tokenize(b);
3127
+ const head = commonHead(ta, tb);
3128
+ const tail2 = commonTail(ta, tb, head);
3129
+ const midA = ta.slice(head, ta.length - tail2);
3130
+ const midB = tb.slice(head, tb.length - tail2);
3131
+ if (midA.length * midB.length > maxCells) return void 0;
3132
+ return joinSegments([
3133
+ head > 0 ? [{ kind: "equal", text: ta.slice(0, head).join("") }] : [],
3134
+ lcsDiff(midA, midB),
3135
+ tail2 > 0 ? [{ kind: "equal", text: ta.slice(ta.length - tail2).join("") }] : []
3136
+ ]);
3137
+ }
3138
+
3139
+ // src/core/served/sincePrevious.ts
3140
+ function unmatchedIndexes(a, b) {
3141
+ const pool = /* @__PURE__ */ new Map();
3142
+ for (const item of b) pool.set(item, (pool.get(item) ?? 0) + 1);
3143
+ const out = [];
3144
+ for (const [i, item] of a.entries()) {
3145
+ const n = pool.get(item) ?? 0;
3146
+ if (n > 0) pool.set(item, n - 1);
3147
+ else out.push(i);
3148
+ }
3149
+ return out;
3150
+ }
3151
+ function sincePrevious(current, previous) {
3152
+ const now = current.view;
3153
+ const before = previous.view;
3154
+ const nowPieces = now.system.pieces.map((p) => p.text);
3155
+ const beforePieces = before.system.pieces.map((p) => p.text);
3156
+ const nowMessages = now.messages.asSent.map(messageDigestInput);
3157
+ const beforeMessages = before.messages.asSent.map(messageDigestInput);
3158
+ const nowNames = new Set(now.tools.names);
3159
+ const beforeNames = new Set(before.tools.names);
3160
+ const added = now.tools.names.filter((n) => !beforeNames.has(n));
3161
+ const removed = before.tools.names.filter((n) => !nowNames.has(n));
3162
+ const comparable = current.receipt !== void 0 && previous.receipt !== void 0;
3163
+ const schemaChanged = [];
3164
+ if (current.receipt !== void 0 && previous.receipt !== void 0) {
3165
+ for (const name of now.tools.names) {
3166
+ if (!beforeNames.has(name)) continue;
3167
+ const a = current.receipt.tools?.schemaHashes?.[name];
3168
+ const b = previous.receipt.tools?.schemaHashes?.[name];
3169
+ if (a !== void 0 && b !== void 0 && a !== b) schemaChanged.push(name);
3170
+ }
3171
+ }
3172
+ const piecesEntered = unmatchedIndexes(nowPieces, beforePieces);
3173
+ const piecesLeft = unmatchedIndexes(beforePieces, nowPieces);
3174
+ const messagesEntered = unmatchedIndexes(nowMessages, beforeMessages);
3175
+ const messagesLeft = unmatchedIndexes(beforeMessages, nowMessages);
3176
+ const changed = now.system.text !== before.system.text;
3177
+ const diff = changed ? diffPromptsBounded(before.system.text, now.system.text) : Object.freeze([]);
3178
+ return Object.freeze({
3179
+ fromEpoch: previous.epoch,
3180
+ toEpoch: current.epoch,
3181
+ system: Object.freeze({
3182
+ changed,
3183
+ ...diff !== void 0 ? { diff: Object.freeze([...diff]) } : {},
3184
+ piecesEntered: piecesEntered.length,
3185
+ piecesLeft: piecesLeft.length,
3186
+ enteredIndexes: Object.freeze(piecesEntered),
3187
+ leftPieces: Object.freeze(piecesLeft.map((i) => before.system.pieces[i]))
3188
+ }),
3189
+ messages: Object.freeze({
3190
+ entered: messagesEntered.length,
3191
+ left: messagesLeft.length,
3192
+ enteredIndexes: Object.freeze(messagesEntered),
3193
+ leftEntries: Object.freeze(messagesLeft.map((i) => before.messages.asSent[i]))
3194
+ }),
3195
+ tools: Object.freeze({
3196
+ added: Object.freeze(added),
3197
+ removed: Object.freeze(removed),
3198
+ schemaChanged: Object.freeze(schemaChanged),
3199
+ schemasComparable: comparable
3200
+ })
3201
+ });
3202
+ }
3203
+
3025
3204
  // src/core/served/verify.ts
3026
3205
  import * as agentfootprint2 from "agentfootprint";
3027
3206
  import {
3028
- messageDigestInput,
3207
+ messageDigestInput as messageDigestInput2,
3029
3208
  receiptHash
3030
3209
  } from "agentfootprint";
3031
3210
  function toolDigestOf() {
@@ -3138,7 +3317,7 @@ function verify(view, receipt, runId, cause) {
3138
3317
  const messagePairs = entriesExcused ? pairMessages(view.messages.asSent, receipt.messages.entries) : byPosition(view.messages.asSent.length, receipt.messages.entries.length);
3139
3318
  const messages = view.messages.asSent.map(
3140
3319
  (message, i) => against(
3141
- hash(messageDigestInput(message)),
3320
+ hash(messageDigestInput2(message)),
3142
3321
  receipt.messages.entries[messagePairs[i]]?.hash,
3143
3322
  "damaged",
3144
3323
  "damaged"
@@ -3152,7 +3331,7 @@ function verify(view, receipt, runId, cause) {
3152
3331
  const requestOnlyStatus = requestOnlyExcused ? "reconstructed" : "damaged";
3153
3332
  const requestOnly = view.messages.requestOnly.map(
3154
3333
  (line, i) => against(
3155
- hash(messageDigestInput({ role: line.role, content: line.text })),
3334
+ hash(messageDigestInput2({ role: line.role, content: line.text })),
3156
3335
  receipt.messages.requestOnly[requestOnlyPairs[i]]?.hash,
3157
3336
  requestOnlyStatus,
3158
3337
  requestOnlyStatus
@@ -3213,185 +3392,6 @@ function verify(view, receipt, runId, cause) {
3213
3392
  });
3214
3393
  }
3215
3394
 
3216
- // src/core/served/sincePrevious.ts
3217
- import { messageDigestInput as messageDigestInput2 } from "agentfootprint";
3218
-
3219
- // src/core/utils/diffPrompts.ts
3220
- function tokenize(s) {
3221
- if (s.length === 0) return [];
3222
- const matches = s.match(/\S+|\s+/g);
3223
- return matches ?? [];
3224
- }
3225
- function lcsDiff(a, b) {
3226
- const n = a.length;
3227
- const m = b.length;
3228
- if (n === 0 && m === 0) return [];
3229
- if (n === 0) return [{ kind: "added", text: b.join("") }];
3230
- if (m === 0) return [{ kind: "removed", text: a.join("") }];
3231
- const dp = [];
3232
- for (let i2 = 0; i2 <= n; i2++) dp.push(new Uint32Array(m + 1));
3233
- for (let i2 = n - 1; i2 >= 0; i2--) {
3234
- for (let j2 = m - 1; j2 >= 0; j2--) {
3235
- if (a[i2] === b[j2]) {
3236
- dp[i2][j2] = dp[i2 + 1][j2 + 1] + 1;
3237
- } else {
3238
- dp[i2][j2] = Math.max(dp[i2 + 1][j2], dp[i2][j2 + 1]);
3239
- }
3240
- }
3241
- }
3242
- const segments = [];
3243
- let curKind;
3244
- let curText = "";
3245
- const push = (kind, text) => {
3246
- if (kind === curKind) {
3247
- curText += text;
3248
- } else {
3249
- if (curKind !== void 0 && curText.length > 0) {
3250
- segments.push({ kind: curKind, text: curText });
3251
- }
3252
- curKind = kind;
3253
- curText = text;
3254
- }
3255
- };
3256
- let i = 0;
3257
- let j = 0;
3258
- while (i < n && j < m) {
3259
- if (a[i] === b[j]) {
3260
- push("equal", a[i]);
3261
- i++;
3262
- j++;
3263
- } else if (dp[i + 1][j] >= dp[i][j + 1]) {
3264
- push("removed", a[i]);
3265
- i++;
3266
- } else {
3267
- push("added", b[j]);
3268
- j++;
3269
- }
3270
- }
3271
- while (i < n) {
3272
- push("removed", a[i]);
3273
- i++;
3274
- }
3275
- while (j < m) {
3276
- push("added", b[j]);
3277
- j++;
3278
- }
3279
- if (curKind !== void 0 && curText.length > 0) {
3280
- segments.push({ kind: curKind, text: curText });
3281
- }
3282
- return segments;
3283
- }
3284
- var DIFF_CELL_CAP = 625e4;
3285
- function commonHead(a, b) {
3286
- const max = Math.min(a.length, b.length);
3287
- let n = 0;
3288
- while (n < max && a[n] === b[n]) n++;
3289
- return n;
3290
- }
3291
- function commonTail(a, b, head) {
3292
- const max = Math.min(a.length, b.length) - head;
3293
- let n = 0;
3294
- while (n < max && a[a.length - 1 - n] === b[b.length - 1 - n]) n++;
3295
- return n;
3296
- }
3297
- function joinSegments(parts) {
3298
- const out = [];
3299
- for (const part of parts) {
3300
- for (const s of part) {
3301
- if (s.text.length === 0) continue;
3302
- const last = out[out.length - 1];
3303
- if (last !== void 0 && last.kind === s.kind) {
3304
- out[out.length - 1] = { kind: last.kind, text: last.text + s.text };
3305
- } else {
3306
- out.push(s);
3307
- }
3308
- }
3309
- }
3310
- return out;
3311
- }
3312
- function diffPromptsBounded(a, b, maxCells = DIFF_CELL_CAP) {
3313
- if (a === b) {
3314
- return a.length === 0 ? [] : [{ kind: "equal", text: a }];
3315
- }
3316
- const ta = tokenize(a);
3317
- const tb = tokenize(b);
3318
- const head = commonHead(ta, tb);
3319
- const tail2 = commonTail(ta, tb, head);
3320
- const midA = ta.slice(head, ta.length - tail2);
3321
- const midB = tb.slice(head, tb.length - tail2);
3322
- if (midA.length * midB.length > maxCells) return void 0;
3323
- return joinSegments([
3324
- head > 0 ? [{ kind: "equal", text: ta.slice(0, head).join("") }] : [],
3325
- lcsDiff(midA, midB),
3326
- tail2 > 0 ? [{ kind: "equal", text: ta.slice(ta.length - tail2).join("") }] : []
3327
- ]);
3328
- }
3329
-
3330
- // src/core/served/sincePrevious.ts
3331
- function unmatchedIndexes(a, b) {
3332
- const pool = /* @__PURE__ */ new Map();
3333
- for (const item of b) pool.set(item, (pool.get(item) ?? 0) + 1);
3334
- const out = [];
3335
- for (const [i, item] of a.entries()) {
3336
- const n = pool.get(item) ?? 0;
3337
- if (n > 0) pool.set(item, n - 1);
3338
- else out.push(i);
3339
- }
3340
- return out;
3341
- }
3342
- function sincePrevious(current, previous) {
3343
- const now = current.view;
3344
- const before = previous.view;
3345
- const nowPieces = now.system.pieces.map((p) => p.text);
3346
- const beforePieces = before.system.pieces.map((p) => p.text);
3347
- const nowMessages = now.messages.asSent.map(messageDigestInput2);
3348
- const beforeMessages = before.messages.asSent.map(messageDigestInput2);
3349
- const nowNames = new Set(now.tools.names);
3350
- const beforeNames = new Set(before.tools.names);
3351
- const added = now.tools.names.filter((n) => !beforeNames.has(n));
3352
- const removed = before.tools.names.filter((n) => !nowNames.has(n));
3353
- const comparable = current.receipt !== void 0 && previous.receipt !== void 0;
3354
- const schemaChanged = [];
3355
- if (current.receipt !== void 0 && previous.receipt !== void 0) {
3356
- for (const name of now.tools.names) {
3357
- if (!beforeNames.has(name)) continue;
3358
- const a = current.receipt.tools?.schemaHashes?.[name];
3359
- const b = previous.receipt.tools?.schemaHashes?.[name];
3360
- if (a !== void 0 && b !== void 0 && a !== b) schemaChanged.push(name);
3361
- }
3362
- }
3363
- const piecesEntered = unmatchedIndexes(nowPieces, beforePieces);
3364
- const piecesLeft = unmatchedIndexes(beforePieces, nowPieces);
3365
- const messagesEntered = unmatchedIndexes(nowMessages, beforeMessages);
3366
- const messagesLeft = unmatchedIndexes(beforeMessages, nowMessages);
3367
- const changed = now.system.text !== before.system.text;
3368
- const diff = changed ? diffPromptsBounded(before.system.text, now.system.text) : Object.freeze([]);
3369
- return Object.freeze({
3370
- fromEpoch: previous.epoch,
3371
- toEpoch: current.epoch,
3372
- system: Object.freeze({
3373
- changed,
3374
- ...diff !== void 0 ? { diff: Object.freeze([...diff]) } : {},
3375
- piecesEntered: piecesEntered.length,
3376
- piecesLeft: piecesLeft.length,
3377
- enteredIndexes: Object.freeze(piecesEntered),
3378
- leftPieces: Object.freeze(piecesLeft.map((i) => before.system.pieces[i]))
3379
- }),
3380
- messages: Object.freeze({
3381
- entered: messagesEntered.length,
3382
- left: messagesLeft.length,
3383
- enteredIndexes: Object.freeze(messagesEntered),
3384
- leftEntries: Object.freeze(messagesLeft.map((i) => before.messages.asSent[i]))
3385
- }),
3386
- tools: Object.freeze({
3387
- added: Object.freeze(added),
3388
- removed: Object.freeze(removed),
3389
- schemaChanged: Object.freeze(schemaChanged),
3390
- schemasComparable: comparable
3391
- })
3392
- });
3393
- }
3394
-
3395
3395
  // src/core/served/foldFactsAt.ts
3396
3396
  import { stateAt } from "footprintjs/trace";
3397
3397
  var FOLD_FACT_KEYS = Object.freeze([
@@ -4114,9 +4114,9 @@ export {
4114
4114
  pairEvictedTurns,
4115
4115
  servedRowAt,
4116
4116
  servedRowForEpoch,
4117
+ sincePrevious,
4117
4118
  EXCUSING_GAPS,
4118
4119
  verify,
4119
- sincePrevious,
4120
4120
  FOLD_FACT_KEYS,
4121
4121
  foldFactsAt,
4122
4122
  SERVED_SLOTS,
@@ -4139,4 +4139,4 @@ export {
4139
4139
  tagStopsFor,
4140
4140
  tagAxisPositions
4141
4141
  };
4142
- //# sourceMappingURL=chunk-JHUSTIEW.js.map
4142
+ //# sourceMappingURL=chunk-BJ635YAV.js.map