@agent-inspect/viewer 6.31.33 → 6.31.35

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/dist/index.mjs CHANGED
@@ -2209,11 +2209,27 @@ function eventTimestamp(finding, eventById) {
2209
2209
  const eventId = finding.evidence[0]?.eventId;
2210
2210
  return eventId ? eventById.get(eventId)?.timestamp ?? "" : "";
2211
2211
  }
2212
+ function isObservedToolPolicyFinding(finding) {
2213
+ return finding.ruleId === "tool.usage" && finding.evidence[0]?.eventId !== void 0;
2214
+ }
2215
+ function isMissingToolConsequenceFinding(finding) {
2216
+ if (finding.evidence[0]?.eventId !== void 0) return false;
2217
+ if (finding.ruleId === "tool.usage" && /did not appear/.test(finding.message)) {
2218
+ return true;
2219
+ }
2220
+ return finding.ruleId.startsWith("contract.tool.arguments") && /^No finished tool named /.test(finding.message);
2221
+ }
2212
2222
  function compareFindings(eventById) {
2213
2223
  return (a, b) => {
2214
2224
  if (SEVERITY_RANK[a.severity] !== SEVERITY_RANK[b.severity]) {
2215
2225
  return SEVERITY_RANK[a.severity] - SEVERITY_RANK[b.severity];
2216
2226
  }
2227
+ const aPolicy = isObservedToolPolicyFinding(a);
2228
+ const bPolicy = isObservedToolPolicyFinding(b);
2229
+ const aMissing = isMissingToolConsequenceFinding(a);
2230
+ const bMissing = isMissingToolConsequenceFinding(b);
2231
+ if (aPolicy && bMissing) return -1;
2232
+ if (bPolicy && aMissing) return 1;
2217
2233
  const byRule = a.ruleId.localeCompare(b.ruleId);
2218
2234
  if (byRule !== 0) return byRule;
2219
2235
  if (STATUS_RANK[a.status] !== STATUS_RANK[b.status]) {
@@ -2342,20 +2358,43 @@ function failFinding(ruleId, message, evidence, expected, actual, meta) {
2342
2358
  function toolName(event) {
2343
2359
  return resolveCanonicalToolName(event);
2344
2360
  }
2361
+ var MAX_TOOL_NAME_CODEPOINT_DETAILS = 3;
2362
+ function isAsciiLetterCodePoint(codePoint) {
2363
+ return codePoint >= 65 && codePoint <= 90 || codePoint >= 97 && codePoint <= 122;
2364
+ }
2365
+ function isRiskyToolNameCodePoint(codePoint) {
2366
+ if (codePoint <= 31 || codePoint >= 127 && codePoint <= 159) return true;
2367
+ return codePoint === 1564 || codePoint === 8203 || codePoint === 8204 || codePoint === 8205 || codePoint === 8206 || codePoint === 8207 || codePoint >= 8234 && codePoint <= 8238 || codePoint >= 8294 && codePoint <= 8297 || codePoint === 65279;
2368
+ }
2369
+ function formatCodePointDetail(codePoint, index) {
2370
+ return `U+${codePoint.toString(16).toUpperCase().padStart(4, "0")} at index ${index}`;
2371
+ }
2345
2372
  function formatToolNameForMessage(name) {
2373
+ let hasAsciiLetter = false;
2374
+ let hasNonAscii = false;
2375
+ let hasRisky = false;
2346
2376
  const details = [];
2347
2377
  for (let index = 0; index < name.length; ) {
2348
2378
  const codePoint = name.codePointAt(index);
2349
2379
  const width = codePoint > 65535 ? 2 : 1;
2380
+ if (isAsciiLetterCodePoint(codePoint)) hasAsciiLetter = true;
2381
+ const risky = isRiskyToolNameCodePoint(codePoint);
2382
+ if (risky) hasRisky = true;
2350
2383
  if (codePoint > 127) {
2351
- details.push(
2352
- `U+${codePoint.toString(16).toUpperCase().padStart(4, "0")} at index ${index}`
2353
- );
2384
+ hasNonAscii = true;
2385
+ details.push(formatCodePointDetail(codePoint, index));
2386
+ } else if (risky) {
2387
+ details.push(formatCodePointDetail(codePoint, index));
2354
2388
  }
2355
2389
  index += width;
2356
2390
  }
2357
- if (details.length === 0) return name;
2358
- return `"${name}" (contains ${details.join("; ")})`;
2391
+ if (!hasRisky && !(hasAsciiLetter && hasNonAscii) || details.length === 0) {
2392
+ return name;
2393
+ }
2394
+ const shown = details.slice(0, MAX_TOOL_NAME_CODEPOINT_DETAILS);
2395
+ const remaining = details.length - shown.length;
2396
+ const detailText = remaining > 0 ? `${shown.join("; ")}; and ${remaining} more` : shown.join("; ");
2397
+ return `"${name}" (contains ${detailText})`;
2359
2398
  }
2360
2399
  function describeRunningEvent(event) {
2361
2400
  if (event.kind === "TOOL") {