agent-inspect 6.31.21 → 6.31.22

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 (47) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +1 -1
  3. package/package.json +1 -1
  4. package/packages/cli/dist/{chunk-N5JN26MW.mjs → chunk-EMWA5EKU.mjs} +300 -31
  5. package/packages/cli/dist/chunk-EMWA5EKU.mjs.map +1 -0
  6. package/packages/cli/dist/index.cjs +379 -56
  7. package/packages/cli/dist/index.cjs.map +1 -1
  8. package/packages/cli/dist/index.mjs +75 -31
  9. package/packages/cli/dist/index.mjs.map +1 -1
  10. package/packages/cli/dist/{src-VMGRSTG7.mjs → src-VZHGOLTO.mjs} +3 -3
  11. package/packages/cli/dist/{src-VMGRSTG7.mjs.map → src-VZHGOLTO.mjs.map} +1 -1
  12. package/packages/core/dist/advanced.cjs +247 -5
  13. package/packages/core/dist/advanced.cjs.map +1 -1
  14. package/packages/core/dist/advanced.mjs +6 -5
  15. package/packages/core/dist/advanced.mjs.map +1 -1
  16. package/packages/core/dist/checks.cjs +160 -27
  17. package/packages/core/dist/checks.cjs.map +1 -1
  18. package/packages/core/dist/checks.mjs +2 -1
  19. package/packages/core/dist/chunk-GCZUWY47.mjs +182 -0
  20. package/packages/core/dist/chunk-GCZUWY47.mjs.map +1 -0
  21. package/packages/core/dist/{chunk-JE3TUFAQ.mjs → chunk-RBXD7BNX.mjs} +3 -3
  22. package/packages/core/dist/{chunk-JE3TUFAQ.mjs.map → chunk-RBXD7BNX.mjs.map} +1 -1
  23. package/packages/core/dist/{chunk-YU6XT5A2.mjs → chunk-S4NU55LU.mjs} +45 -3
  24. package/packages/core/dist/chunk-S4NU55LU.mjs.map +1 -0
  25. package/packages/core/dist/{chunk-EIP5CNEL.mjs → chunk-UPGBMRL4.mjs} +49 -3
  26. package/packages/core/dist/chunk-UPGBMRL4.mjs.map +1 -0
  27. package/packages/core/dist/{chunk-4CDX5GDS.mjs → chunk-ZOF6ON65.mjs} +104 -99
  28. package/packages/core/dist/chunk-ZOF6ON65.mjs.map +1 -0
  29. package/packages/core/dist/exporters.cjs +82 -27
  30. package/packages/core/dist/exporters.cjs.map +1 -1
  31. package/packages/core/dist/exporters.mjs +72 -27
  32. package/packages/core/dist/exporters.mjs.map +1 -1
  33. package/packages/core/dist/logs.cjs +197 -1
  34. package/packages/core/dist/logs.cjs.map +1 -1
  35. package/packages/core/dist/logs.mjs +3 -2
  36. package/packages/core/dist/logs.mjs.map +1 -1
  37. package/packages/core/dist/persisted.cjs +197 -1
  38. package/packages/core/dist/persisted.cjs.map +1 -1
  39. package/packages/core/dist/persisted.mjs +4 -3
  40. package/packages/core/dist/persisted.mjs.map +1 -1
  41. package/packages/core/dist/readers.cjs +243 -1
  42. package/packages/core/dist/readers.cjs.map +1 -1
  43. package/packages/core/dist/readers.mjs +4 -3
  44. package/packages/cli/dist/chunk-N5JN26MW.mjs.map +0 -1
  45. package/packages/core/dist/chunk-4CDX5GDS.mjs.map +0 -1
  46. package/packages/core/dist/chunk-EIP5CNEL.mjs.map +0 -1
  47. package/packages/core/dist/chunk-YU6XT5A2.mjs.map +0 -1
@@ -708,6 +708,162 @@ var EventNormalizer = class {
708
708
  }
709
709
  };
710
710
 
711
+ // packages/core/src/checks/canonical-equality.ts
712
+ var DEFAULT_MAX_DEPTH = 8;
713
+ var DEFAULT_MAX_BYTES = 16384;
714
+ function sortKeysDeep(input, depth, maxDepth) {
715
+ if (depth > maxDepth) {
716
+ throw new Error("AI_CHECK_CANONICAL_DEPTH_EXCEEDED");
717
+ }
718
+ if (input === null || typeof input !== "object") return input;
719
+ if (Array.isArray(input)) {
720
+ return input.map((item) => sortKeysDeep(item, depth + 1, maxDepth));
721
+ }
722
+ const record = input;
723
+ const out = {};
724
+ for (const key of Object.keys(record).sort()) {
725
+ out[key] = sortKeysDeep(record[key], depth + 1, maxDepth);
726
+ }
727
+ return out;
728
+ }
729
+ function encodeCanonicalStructured(value, limits) {
730
+ const maxDepth = DEFAULT_MAX_DEPTH;
731
+ const maxBytes = DEFAULT_MAX_BYTES;
732
+ try {
733
+ const sorted = sortKeysDeep(value, 0, maxDepth);
734
+ const encoded = JSON.stringify(sorted);
735
+ if (encoded === void 0) {
736
+ return {
737
+ ok: false,
738
+ reason: "Value is not JSON-serializable for canonical comparison.",
739
+ code: "AI_CHECK_CANONICAL_UNSERIALIZABLE"
740
+ };
741
+ }
742
+ if (Buffer.byteLength(encoded, "utf8") > maxBytes) {
743
+ return {
744
+ ok: false,
745
+ reason: "Canonical structured value exceeds bounded size limit.",
746
+ code: "AI_CHECK_CANONICAL_SIZE_EXCEEDED"
747
+ };
748
+ }
749
+ return { ok: true, value: encoded };
750
+ } catch (error) {
751
+ const message = error instanceof Error ? error.message : String(error);
752
+ if (message === "AI_CHECK_CANONICAL_DEPTH_EXCEEDED") {
753
+ return {
754
+ ok: false,
755
+ reason: "Canonical structured value exceeds bounded depth limit.",
756
+ code: "AI_CHECK_CANONICAL_DEPTH_EXCEEDED"
757
+ };
758
+ }
759
+ return {
760
+ ok: false,
761
+ reason: "Canonical structured encoding failed.",
762
+ code: "AI_CHECK_CANONICAL_UNSERIALIZABLE"
763
+ };
764
+ }
765
+ }
766
+
767
+ // packages/core/src/persisted/delivery-identity.ts
768
+ var DELIVERY_CONFLICT_ATTR = "agent_inspect.delivery_conflict";
769
+ var SYNTHETIC_DELIVERY_ID = /^(?:manual|inspect):[A-Za-z0-9_-]+:[A-Za-z0-9_-]+:[A-Za-z0-9_-]+:\d+$/;
770
+ function stripReaderDeliveryDiscriminator(eventId) {
771
+ if (!SYNTHETIC_DELIVERY_ID.test(eventId)) return eventId;
772
+ return eventId.replace(/:\d+$/, "");
773
+ }
774
+ function canonicalDigest(value) {
775
+ if (value === void 0) return null;
776
+ const encoded = encodeCanonicalStructured(value);
777
+ return encoded.ok ? encoded.value : `unencodable:${encoded.code}`;
778
+ }
779
+ function capturedContentDigest(attributes) {
780
+ if (!attributes || typeof attributes !== "object") {
781
+ return { args: null, result: null };
782
+ }
783
+ const nested = attributes.metadata && typeof attributes.metadata === "object" ? attributes.metadata : void 0;
784
+ const args = attributes.arguments ?? attributes.args ?? attributes.input ?? nested?.arguments ?? nested?.args ?? nested?.input;
785
+ const result = attributes.result ?? attributes.output ?? attributes.response ?? nested?.result ?? nested?.output ?? nested?.response;
786
+ return {
787
+ args: args === void 0 ? null : canonicalDigest(args),
788
+ result: result === void 0 ? null : canonicalDigest(result)
789
+ };
790
+ }
791
+ function timeKey(fields) {
792
+ if (typeof fields.startedAt === "string" && fields.startedAt.trim() !== "") {
793
+ return fields.startedAt;
794
+ }
795
+ if (typeof fields.timestamp === "string" && fields.timestamp.trim() !== "") {
796
+ return fields.timestamp;
797
+ }
798
+ if (typeof fields.timestamp === "number" && Number.isFinite(fields.timestamp)) {
799
+ return String(fields.timestamp);
800
+ }
801
+ return null;
802
+ }
803
+ function deliverySemanticFingerprint(fields) {
804
+ const content = capturedContentDigest(fields.attributes);
805
+ return JSON.stringify({
806
+ stableEventId: stripReaderDeliveryDiscriminator(fields.eventId),
807
+ runId: fields.runId,
808
+ kind: fields.kind,
809
+ name: fields.name,
810
+ status: fields.status ?? null,
811
+ parentId: fields.parentId ?? null,
812
+ sourceType: fields.sourceType ?? null,
813
+ time: timeKey(fields),
814
+ operationId: fields.operationId ?? null,
815
+ attemptId: fields.attemptId ?? null,
816
+ attemptNumber: fields.attemptNumber ?? null,
817
+ retryOf: fields.retryOf ?? null,
818
+ argsDigest: content.args,
819
+ resultDigest: content.result
820
+ });
821
+ }
822
+ function identityFieldsFromAttributes(attributes) {
823
+ if (!attributes || typeof attributes !== "object") {
824
+ return {
825
+ operationId: null,
826
+ attemptId: null,
827
+ attemptNumber: null,
828
+ retryOf: null
829
+ };
830
+ }
831
+ const nested = attributes.metadata && typeof attributes.metadata === "object" && !Array.isArray(attributes.metadata) ? attributes.metadata : void 0;
832
+ const pickString = (key) => {
833
+ const direct = attributes[key];
834
+ if (typeof direct === "string" && direct.trim() !== "") return direct.trim();
835
+ const nestedValue = nested?.[key];
836
+ if (typeof nestedValue === "string" && nestedValue.trim() !== "") {
837
+ return nestedValue.trim();
838
+ }
839
+ return null;
840
+ };
841
+ const pickNumber = () => {
842
+ const direct = attributes.attemptNumber ?? attributes.attempt;
843
+ if (typeof direct === "number" && Number.isFinite(direct)) return direct;
844
+ const nestedValue = nested?.attemptNumber ?? nested?.attempt;
845
+ if (typeof nestedValue === "number" && Number.isFinite(nestedValue)) {
846
+ return nestedValue;
847
+ }
848
+ return null;
849
+ };
850
+ return {
851
+ operationId: pickString("operationId"),
852
+ attemptId: pickString("attemptId"),
853
+ retryOf: pickString("retryOf"),
854
+ attemptNumber: pickNumber()
855
+ };
856
+ }
857
+ function stampDeliveryConflict(event) {
858
+ return {
859
+ ...event,
860
+ attributes: {
861
+ ...event.attributes ?? {},
862
+ [DELIVERY_CONFLICT_ATTR]: true
863
+ }
864
+ };
865
+ }
866
+
711
867
  // packages/core/src/logs/tree-builder.ts
712
868
  function inc(map, key) {
713
869
  map[key] = (map[key] ?? 0) + 1;
@@ -839,7 +995,47 @@ var TreeBuilder = class {
839
995
  const sorted = [...runEvents].sort((a, b) => a.timestamp - b.timestamp);
840
996
  const nodes = /* @__PURE__ */ new Map();
841
997
  for (const e of sorted) {
842
- nodes.set(e.eventId, { event: e, children: [], depth: 0 });
998
+ const existing = nodes.get(e.eventId);
999
+ if (!existing) {
1000
+ nodes.set(e.eventId, { event: e, children: [], depth: 0 });
1001
+ continue;
1002
+ }
1003
+ const existingAttrs = existing.event.attributes && typeof existing.event.attributes === "object" ? existing.event.attributes : void 0;
1004
+ const nextAttrs = e.attributes && typeof e.attributes === "object" ? e.attributes : void 0;
1005
+ const existingIdentity = identityFieldsFromAttributes(existingAttrs);
1006
+ const nextIdentity = identityFieldsFromAttributes(nextAttrs);
1007
+ const existingFp = deliverySemanticFingerprint({
1008
+ eventId: existing.event.eventId,
1009
+ runId: existing.event.runId,
1010
+ kind: existing.event.kind,
1011
+ name: existing.event.name,
1012
+ status: existing.event.status,
1013
+ parentId: existing.event.parentId,
1014
+ timestamp: existing.event.timestamp,
1015
+ sourceType: existing.event.source?.type,
1016
+ attributes: existingAttrs,
1017
+ ...existingIdentity
1018
+ });
1019
+ const nextFp = deliverySemanticFingerprint({
1020
+ eventId: e.eventId,
1021
+ runId: e.runId,
1022
+ kind: e.kind,
1023
+ name: e.name,
1024
+ status: e.status,
1025
+ parentId: e.parentId,
1026
+ timestamp: e.timestamp,
1027
+ sourceType: e.source?.type,
1028
+ attributes: nextAttrs,
1029
+ ...nextIdentity
1030
+ });
1031
+ if (existingFp === nextFp) {
1032
+ continue;
1033
+ }
1034
+ nodes.set(e.eventId, {
1035
+ event: stampDeliveryConflict(e),
1036
+ children: [],
1037
+ depth: 0
1038
+ });
843
1039
  }
844
1040
  const { roots, summary } = linkNodesVisibilityFirst(nodes);
845
1041
  const confidenceBreakdown = {