@phosphorco/bb-cross-references 0.3.0 → 0.4.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/dist/bb.js CHANGED
@@ -365,7 +365,7 @@ function referenceLabelError(value) {
365
365
  }
366
366
 
367
367
  // src/index.ts
368
- import { z as z3 } from "zod";
368
+ import { z as z4 } from "zod";
369
369
 
370
370
  // src/recognition.ts
371
371
  import { z } from "zod";
@@ -415,9 +415,631 @@ function verifiedFileIdentityRecord(value) {
415
415
  throw new Error("Verified file mapping exceeds its bound.");
416
416
  return json;
417
417
  }
418
- // src/evidence-v2.ts
418
+ // src/producer.ts
419
419
  import { z as z2 } from "zod";
420
- import { ContextBundleV1Schema, SafeHrefSchema as SafeHrefSchema2, CandidateV1Schema, SourceIdentitySchema as SourceIdentitySchema2 } from "@phosphorco/bb-context-recognition";
420
+ import { canonicalJson as canonicalJson2, SafeHrefSchema as SafeHrefSchema2, SourceIdentitySchema as SourceIdentitySchema2 } from "@phosphorco/bb-context-recognition";
421
+ var PRODUCER_METHODS = Object.freeze({ describe: "crossReferencesProducer.describe", getState: "crossReferencesProducerV1GetState", apply: "crossReferencesProducerV1Apply", reportStatus: "crossReferencesProducerV1ReportStatus" });
422
+ var BRIEF_NAVIGATION_METHODS = Object.freeze({ describe: "threadBriefNavigation.describe", resolve: "threadBriefNavigationV1ResolveHeading" });
423
+ var BRIEF_LIMITS = Object.freeze({ inputBytes: 1048576, statusBytes: 16384, responseBytes: 1048576, locations: 512, perTarget: 100, headingBytes: 256, describeMs: 1000, callMs: 5000, readMs: 2000, navigationInputBytes: 8192, navigationOutputBytes: 16384 });
424
+ var DISPLAY_POLICY_LIMITS = Object.freeze({ valueChars: 1048576, valueBytes: 1048576, fields: 8192, distinct: 4096, sourceBytes: 2097152, work: 8388608, views: 4, tokens: 128, tokenChars: 4096, tokenBytes: 16384 });
425
+ var BRIEF_LIMIT_CODES = ["target-count", "projection-bytes", "occurrence-count", "per-target-occurrences", "heading-bytes", "envelope-bytes", "presentation-label-bytes", "presentation-detail-bytes", "presentation-url-bytes", "presentation-bytes"];
426
+ var roles = ["heading", "source-label", "target-label", "detail", "presentation-href", "provenance", "codec", "authored-url", "required-identity"];
427
+ function wellFormed(s) {
428
+ for (const c of s) {
429
+ const n = c.codePointAt(0);
430
+ if (n >= 55296 && n <= 57343)
431
+ return false;
432
+ }
433
+ return true;
434
+ }
435
+ function control(s) {
436
+ for (const c of s) {
437
+ const n = c.codePointAt(0);
438
+ if (n < 32 || n >= 127 && n <= 159)
439
+ return true;
440
+ }
441
+ return false;
442
+ }
443
+ var space = (c) => c.trim() === "";
444
+
445
+ class PolicyStop {
446
+ reason;
447
+ constructor(reason) {
448
+ this.reason = reason;
449
+ }
450
+ }
451
+
452
+ class PolicyHit {
453
+ reason;
454
+ constructor(reason) {
455
+ this.reason = reason;
456
+ }
457
+ }
458
+ function charge(m, n) {
459
+ if (n < 0 || m.work + n > DISPLAY_POLICY_LIMITS.work)
460
+ throw new PolicyStop("source-work-limit");
461
+ m.work += n;
462
+ }
463
+ var entities = { amp: "&", colon: ":", sol: "/", bsol: "\\", quest: "?", num: "#", percnt: "%", equals: "=", commat: "@", semi: ";", Tab: "\t", NewLine: `
464
+ ` };
465
+ function decodeView(s, m) {
466
+ charge(m, s.length * 2);
467
+ const out = [];
468
+ let changed = false;
469
+ for (let i = 0;i < s.length; ) {
470
+ const c = s[i];
471
+ if (c === "%" && /[0-9a-f]/i.test(s[i + 1] ?? "")) {
472
+ const bytes = [];
473
+ while (s[i] === "%") {
474
+ const h = s.slice(i + 1, i + 3);
475
+ if (h.length !== 2 || !/^[0-9a-f]{2}$/i.test(h))
476
+ throw new PolicyStop("encoding-ambiguity");
477
+ bytes.push(parseInt(h, 16));
478
+ i += 3;
479
+ }
480
+ try {
481
+ out.push(new TextDecoder("utf-8", { fatal: true }).decode(Uint8Array.from(bytes)));
482
+ } catch {
483
+ throw new PolicyStop("encoding-ambiguity");
484
+ }
485
+ changed = true;
486
+ continue;
487
+ }
488
+ if (c === "\\") {
489
+ const n = s[i + 1];
490
+ if (n === "u") {
491
+ const h = s.slice(i + 2, i + 6);
492
+ if (!/^[0-9a-f]{4}$/i.test(h))
493
+ throw new PolicyStop("encoding-ambiguity");
494
+ let value = String.fromCharCode(parseInt(h, 16));
495
+ i += 6;
496
+ if (value.charCodeAt(0) >= 55296 && value.charCodeAt(0) <= 56319) {
497
+ if (s.slice(i, i + 2) !== "\\u" || !/^[0-9a-f]{4}$/i.test(s.slice(i + 2, i + 6)))
498
+ throw new PolicyStop("encoding-ambiguity");
499
+ value += String.fromCharCode(parseInt(s.slice(i + 2, i + 6), 16));
500
+ i += 6;
501
+ }
502
+ if (!wellFormed(value))
503
+ throw new PolicyStop("encoding-ambiguity");
504
+ out.push(value);
505
+ changed = true;
506
+ continue;
507
+ }
508
+ const escape = { "/": "/", "\\": "\\", '"': '"', b: "\b", f: "\f", n: `
509
+ `, r: "\r", t: "\t" };
510
+ if (n === undefined || escape[n] === undefined)
511
+ throw new PolicyStop("encoding-ambiguity");
512
+ out.push(escape[n]);
513
+ i += 2;
514
+ changed = true;
515
+ continue;
516
+ }
517
+ if (c === "&" && /[A-Za-z0-9_#]/.test(s[i + 1] ?? "")) {
518
+ let j = i + 1;
519
+ while (j < s.length && j - i <= 32 && !space(s[j]) && s[j] !== ";" && s[j] !== "&")
520
+ j++;
521
+ if (s[j] === ";") {
522
+ const name = s.slice(i + 1, j);
523
+ let decoded;
524
+ if (name.startsWith("#")) {
525
+ const hex = name[1]?.toLowerCase() === "x", digits = name.slice(hex ? 2 : 1);
526
+ if (!(hex ? /^[a-f0-9]+$/i : /^[0-9]+$/).test(digits))
527
+ throw new PolicyStop("encoding-ambiguity");
528
+ const cp = parseInt(digits, hex ? 16 : 10);
529
+ if (cp > 1114111 || cp >= 55296 && cp <= 57343)
530
+ throw new PolicyStop("encoding-ambiguity");
531
+ decoded = String.fromCodePoint(cp);
532
+ } else
533
+ decoded = Object.hasOwn(entities, name) ? entities[name] : undefined;
534
+ if (decoded === undefined)
535
+ throw new PolicyStop("encoding-ambiguity");
536
+ out.push(decoded);
537
+ i = j + 1;
538
+ changed = true;
539
+ continue;
540
+ }
541
+ const partial = s.slice(i + 1, j);
542
+ if (s[i + 1] === "#" || j - i > 32 || !partial.includes("=") && Object.keys(entities).some((name) => name.startsWith(partial) || partial.startsWith(name)))
543
+ throw new PolicyStop("encoding-ambiguity");
544
+ }
545
+ out.push(c);
546
+ i++;
547
+ }
548
+ return { text: out.join(""), changed };
549
+ }
550
+ function scanPolicy(s, m, tokens) {
551
+ charge(m, s.length * 4);
552
+ const token = (value) => {
553
+ if (++tokens.count > DISPLAY_POLICY_LIMITS.tokens)
554
+ throw new PolicyStop("token-limit");
555
+ if (value.length > DISPLAY_POLICY_LIMITS.tokenChars)
556
+ throw new PolicyStop("token-limit");
557
+ charge(m, value.length * 2);
558
+ if (utf8ByteLength(value) > DISPLAY_POLICY_LIMITS.tokenBytes)
559
+ throw new PolicyStop("token-limit");
560
+ };
561
+ const url = (value) => {
562
+ token(value);
563
+ let u;
564
+ try {
565
+ u = new URL(value, "https://display-policy.invalid");
566
+ } catch {
567
+ throw new PolicyStop("encoding-ambiguity");
568
+ }
569
+ if (u.username || u.password)
570
+ throw new PolicyHit("url-credentials");
571
+ if (hasSensitiveUrlParameter(u))
572
+ throw new PolicyHit("sensitive-url-parameter");
573
+ if (!SafeHrefSchema2.safeParse(value).success)
574
+ throw new PolicyHit("unsafe-url-form");
575
+ };
576
+ for (let at = 0;at < s.length; ) {
577
+ while (at < s.length && space(s[at]))
578
+ at++;
579
+ const start = at;
580
+ while (at < s.length && !space(s[at]))
581
+ at++;
582
+ const run = s.slice(start, at);
583
+ if (!run)
584
+ continue;
585
+ let hasScheme = false;
586
+ for (let i = 0;i < run.length; i++) {
587
+ const tail = run.slice(i, i + 8).toLowerCase();
588
+ if (tail.startsWith("http://") || tail.startsWith("https://")) {
589
+ hasScheme = true;
590
+ if (run.length - i > DISPLAY_POLICY_LIMITS.tokenChars)
591
+ throw new PolicyStop("token-limit");
592
+ url(run.slice(i));
593
+ } else if (run[i] === ":" && run.slice(i + 1, i + 3) === "//" && i > 0 && !run.slice(Math.max(0, i - 5), i).toLowerCase().endsWith("http") && !run.slice(Math.max(0, i - 5), i).toLowerCase().endsWith("https"))
594
+ throw new PolicyHit("unsafe-url-form");
595
+ }
596
+ if (!hasScheme) {
597
+ const slash = run.indexOf("/");
598
+ if (slash >= 0) {
599
+ if (run.length - slash > DISPLAY_POLICY_LIMITS.tokenChars)
600
+ throw new PolicyStop("token-limit");
601
+ url(run.slice(slash));
602
+ }
603
+ }
604
+ for (let i = 0;i < run.length; i++)
605
+ if (run[i] === "=") {
606
+ let begin = i;
607
+ while (begin > 0 && /[A-Za-z0-9_%.-]/.test(run[begin - 1]))
608
+ begin--;
609
+ const name = run.slice(begin, i);
610
+ if (!name)
611
+ continue;
612
+ token(name);
613
+ const u = new URL("https://display-policy.invalid");
614
+ u.search = "?" + name + "=value";
615
+ if (hasSensitiveUrlParameter(u))
616
+ throw new PolicyHit("credential-shaped-token");
617
+ }
618
+ }
619
+ }
620
+ function classify(value, m) {
621
+ const before = m.work;
622
+ let views = 0;
623
+ const tokens = { count: 0 };
624
+ const result = (extra) => ({ version: 1, workUnits: m.work - before, decodedViews: views, ...extra });
625
+ try {
626
+ if (value.length > DISPLAY_POLICY_LIMITS.valueChars)
627
+ throw new PolicyStop("input-limit");
628
+ charge(m, value.length * 3);
629
+ if (!wellFormed(value))
630
+ throw new PolicyStop("ill-formed-unicode");
631
+ if (utf8ByteLength(value) > DISPLAY_POLICY_LIMITS.valueBytes)
632
+ throw new PolicyStop("input-limit");
633
+ let current = value;
634
+ for (let i = 0;i < DISPLAY_POLICY_LIMITS.views; i++) {
635
+ views++;
636
+ if (control(current))
637
+ throw new PolicyStop("control-character");
638
+ scanPolicy(current, m, tokens);
639
+ const decoded = decodeView(current, m);
640
+ if (!decoded.changed)
641
+ return result({ state: "safe", coverage: "complete" });
642
+ if (i === DISPLAY_POLICY_LIMITS.views - 1)
643
+ throw new PolicyStop("encoding-limit");
644
+ current = decoded.text;
645
+ }
646
+ throw new PolicyStop("encoding-limit");
647
+ } catch (e) {
648
+ if (e instanceof PolicyHit)
649
+ return result({ state: "unsafe", coverage: "complete-for-hit", reason: e.reason });
650
+ if (e instanceof PolicyStop)
651
+ return result({ state: "unclassified", coverage: "incomplete", reason: e.reason });
652
+ throw e;
653
+ }
654
+ }
655
+ function classifyBriefDisplayTextV1(value) {
656
+ if (typeof value !== "string")
657
+ throw new Error("Invalid display-policy argument.");
658
+ return classify(value, { work: 0 });
659
+ }
660
+ function classifyBriefDisplayFieldsV1(fields) {
661
+ if (!Array.isArray(fields) || fields.length > DISPLAY_POLICY_LIMITS.fields)
662
+ return { version: 1, state: "unclassified", reason: "field-limit", results: [], usage: { distinctValues: 0, originalUtf8Bytes: 0, workUnits: 0 }, complete: false };
663
+ for (const f of fields)
664
+ if (!f || !Array.isArray(f.key) || f.key.length > 8 || f.key.some((n) => typeof n !== "number" || !Number.isSafeInteger(n) || n < 0 || n > 8191) || !roles.includes(f.role) || typeof f.value !== "string")
665
+ throw new Error("Invalid display-policy field.");
666
+ const ordered = fields.map((f, i) => ({ f, i })).sort((a, b) => Number(b.f.role === "required-identity") - Number(a.f.role === "required-identity") || compareNumbers(a.f.key, b.f.key) || a.i - b.i);
667
+ const meter = { work: 0 }, cache = new Map, results = { version: 1, state: "classified", results: [], usage: { distinctValues: 0, originalUtf8Bytes: 0, workUnits: 0 }, complete: true };
668
+ for (const { f, i } of ordered) {
669
+ let r = cache.get(f.value);
670
+ if (!r) {
671
+ const incomplete = (reason) => ({ version: 1, state: "unclassified", coverage: "incomplete", reason, workUnits: 0, decodedViews: 0 });
672
+ if (cache.size >= DISPLAY_POLICY_LIMITS.distinct)
673
+ r = incomplete("field-limit");
674
+ else {
675
+ try {
676
+ if (f.value.length > DISPLAY_POLICY_LIMITS.valueChars)
677
+ r = incomplete("input-limit");
678
+ else {
679
+ charge(meter, f.value.length);
680
+ const bytes = utf8ByteLength(f.value);
681
+ if (results.usage.originalUtf8Bytes + bytes > DISPLAY_POLICY_LIMITS.sourceBytes)
682
+ r = incomplete("source-work-limit");
683
+ else {
684
+ results.usage.originalUtf8Bytes += bytes;
685
+ r = classify(f.value, meter);
686
+ }
687
+ }
688
+ } catch (e) {
689
+ if (e instanceof PolicyStop)
690
+ r = incomplete(e.reason);
691
+ else
692
+ throw e;
693
+ }
694
+ cache.set(f.value, r);
695
+ }
696
+ }
697
+ results.results[i] = { key: f.key, result: r };
698
+ if (r.state !== "safe")
699
+ results.complete = false;
700
+ }
701
+ results.usage.distinctValues = cache.size;
702
+ results.usage.workUnits = meter.work;
703
+ return results;
704
+ }
705
+ function compareNumbers(a, b) {
706
+ for (let i = 0;i < Math.min(a.length, b.length); i++)
707
+ if (a[i] !== b[i])
708
+ return a[i] - b[i];
709
+ return a.length - b.length;
710
+ }
711
+ var integer = z2.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER);
712
+ var positive = integer.min(1);
713
+ var digest = z2.string().regex(/^[a-f0-9]{64}$/);
714
+ var bytes = (n) => z2.string().refine(wellFormed, "Malformed Unicode.").refine((v) => utf8ByteLength(v) <= n, "Text byte bound exceeded.");
715
+ var plugin = z2.string().regex(/^[a-z][a-z0-9._-]{0,63}$/);
716
+ var identity = z2.strictObject({ provider: z2.string(), keys: z2.record(z2.string(), z2.string()) }).superRefine((v, c) => {
717
+ try {
718
+ canonicalizeIdentity(v);
719
+ } catch {
720
+ c.addIssue({ code: "custom", message: "Invalid resource identity." });
721
+ }
722
+ });
723
+ var briefFileSchema = z2.strictObject({ kind: z2.literal("thread-storage"), threadId: z2.string().regex(/^[A-Za-z0-9_-]{1,128}$/), path: z2.literal("BRIEF.md") });
724
+ var safeHref = SafeHrefSchema2.refine((v) => utf8ByteLength(v) <= 16384 && !hasSensitiveUrlParameter(new URL(v, "https://display-policy.invalid")), "Unsafe URL.");
725
+ var cause = z2.enum(["policy", "unclassified"]);
726
+ var withheld = (display) => z2.strictObject({ state: z2.literal("withheld"), digest, display: z2.literal(display), cause });
727
+ var briefHeadingSchema = z2.union([z2.null(), z2.strictObject({ state: z2.literal("named"), text: bytes(256) }), withheld("Heading withheld")]);
728
+ var labelText = bytes(256).refine((v) => !control(v) && v.trim().length > 0, "Invalid label.");
729
+ var briefSourceLabelSchema = z2.union([z2.strictObject({ state: z2.literal("safe"), text: labelText }), withheld("Brief")]);
730
+ var briefTargetLabelSchema = z2.union([z2.strictObject({ state: z2.literal("safe"), text: labelText }), withheld("Reference")]);
731
+ var detail = z2.union([z2.null(), z2.strictObject({ state: z2.literal("safe"), text: bytes(1024).refine((v) => !control(v) && v.trim().length > 0) }), withheld("Details withheld")]);
732
+ var presentationHref = z2.union([z2.strictObject({ state: z2.literal("absent") }), z2.strictObject({ state: z2.literal("exact"), href: safeHref.refine((v) => utf8ByteLength(v) <= 2048 && !control(v) && v.trim().length > 0) }), withheld("Destination withheld")]);
733
+ var presentation = (label) => z2.strictObject({ label, detail, url: presentationHref });
734
+ var briefSourcePresentationSchema = presentation(briefSourceLabelSchema);
735
+ var briefTargetPresentationSchema = presentation(briefTargetLabelSchema);
736
+ var span = z2.strictObject({ start: integer, end: positive }).refine((v) => v.end > v.start);
737
+ var provenanceValue = z2.strictObject({
738
+ pluginId: plugin,
739
+ origin: z2.enum(["builtin", "contributed"]),
740
+ confidence: z2.enum(["high", "medium", "low"]),
741
+ recognition: z2.strictObject({ basis: z2.enum(["explicit", "text-url", "existing-link", "git-remote", "context"]), explanation: bytes(1024).min(1), evidence: z2.strictObject({ span: span.optional(), link: integer.optional(), remote: bytes(1024).optional() }).optional() }),
742
+ source: SourceIdentitySchema2.strict(),
743
+ authoredHref: safeHref.optional(),
744
+ verifiedFile: VerifiedFileTargetSchema.optional()
745
+ });
746
+ var provenanceSummary = z2.strictObject({ pluginId: plugin, origin: z2.enum(["builtin", "contributed"]), confidence: z2.enum(["high", "medium", "low"]), basis: z2.enum(["explicit", "text-url", "existing-link", "git-remote", "context"]) });
747
+ var briefProvenanceSchema = z2.union([z2.strictObject({ state: z2.literal("safe"), value: provenanceValue }), withheld("Recognition details withheld").extend({ summary: provenanceSummary })]);
748
+ var codecProof = z2.discriminatedUnion("kind", [
749
+ z2.strictObject({ kind: z2.literal("recognition"), source: SourceIdentitySchema2.strict() }),
750
+ z2.strictObject({ kind: z2.literal("thread"), source: SourceIdentitySchema2.strict(), verified: z2.strictObject({ id: z2.string(), projectId: z2.string() }) }),
751
+ z2.strictObject({ kind: z2.literal("file"), verified: VerifiedFileTargetSchema }),
752
+ z2.strictObject({ kind: z2.literal("url"), href: safeHref })
753
+ ]);
754
+ var codec = z2.union([z2.strictObject({ state: z2.literal("available"), value: codecProof }), withheld("Identity metadata withheld")]);
755
+ var briefAuthoredUrlSchema = z2.union([z2.strictObject({ state: z2.literal("exact"), href: safeHref }), z2.strictObject({ state: z2.literal("not-url") }), z2.strictObject({ state: z2.literal("unknown") }), withheld("Destination withheld")]);
756
+ var briefFrameSchema = z2.strictObject({
757
+ codec: z2.literal("utf8-fatal-bom-consumed-v1"),
758
+ rawBytes: integer.max(1048576),
759
+ bomBytes: z2.union([z2.literal(0), z2.literal(3)]),
760
+ fileUtf16Length: integer.max(1048576),
761
+ bodyBase: z2.strictObject({ startUtf16: integer, startLine: positive, utf16Length: integer }),
762
+ lineMapping: z2.strictObject({ codec: z2.literal("native-file-lines-v1"), fileLineCount: positive })
763
+ }).superRefine((v, c) => {
764
+ if (v.rawBytes < v.bomBytes || v.bodyBase.startUtf16 + v.bodyBase.utf16Length > v.fileUtf16Length || v.bodyBase.startLine > v.lineMapping.fileLineCount)
765
+ c.addIssue({ code: "custom", message: "Invalid source frame." });
766
+ });
767
+ var briefLocatorSchema = z2.strictObject({
768
+ kind: z2.literal("thread-brief"),
769
+ threadId: z2.string().regex(/^[A-Za-z0-9_-]{1,128}$/),
770
+ file: briefFileSchema,
771
+ sourceContentRevision: digest,
772
+ section: z2.strictObject({ heading: briefHeadingSchema, line: positive }),
773
+ location: z2.strictObject({ kind: z2.literal("line"), line: positive, column: positive.nullable(), endLine: positive.nullable() }),
774
+ span: z2.strictObject({ frame: z2.enum(["file-utf16", "body-utf16"]), start: integer, end: positive }).refine((v) => v.end > v.start).optional()
775
+ });
776
+ var briefOccurrenceSchema = z2.strictObject({ occurrenceKey: digest, sourceOccurrenceId: bytes(256).regex(/^ref-(0|[1-9]\d{0,2})$/).refine((v) => Number(v.slice(4)) < 512), target: identity, locator: briefLocatorSchema, provenance: briefProvenanceSchema, authoredUrl: briefAuthoredUrlSchema });
777
+ var briefTargetDescriptorSchema = z2.strictObject({ target: identity, presentation: briefTargetPresentationSchema, codec });
778
+ var briefEvidenceSchema = z2.strictObject({
779
+ kind: z2.literal("thread-brief"),
780
+ sourceFile: briefFileSchema,
781
+ sourceState: z2.enum(["present", "absent", "empty"]),
782
+ sourceContentRevision: digest.nullable(),
783
+ completeness: z2.strictObject({ state: z2.literal("complete"), codecVersion: z2.literal(1) }),
784
+ metadataPolicyVersion: z2.literal(1),
785
+ frame: briefFrameSchema.nullable(),
786
+ sourcePresentation: briefSourcePresentationSchema,
787
+ targetDescriptors: z2.array(briefTargetDescriptorSchema).max(256),
788
+ occurrences: z2.array(briefOccurrenceSchema).max(512)
789
+ });
790
+ function briefWithheldDigest(role, original) {
791
+ if (!roles.includes(role))
792
+ throw new Error("Invalid withheld role.");
793
+ return sha256Hex(canonicalJson2(["brief-withheld", 1, role, original]));
794
+ }
795
+ function briefOccurrenceKey(rawRevision, target, locator, sourceOccurrenceId) {
796
+ return sha256Hex(canonicalJson2(["brief-occurrence", 1, rawRevision, identityValue(target), locator, sourceOccurrenceId]));
797
+ }
798
+ function identityValue(v) {
799
+ const c = canonicalizeIdentity(v);
800
+ return { provider: c.provider, keys: c.keys };
801
+ }
802
+ function briefEvidenceDigest(input) {
803
+ const e = briefEvidenceSchema.parse(input);
804
+ return sha256Hex(canonicalJson2(["brief-evidence", 1, {
805
+ ...e,
806
+ targetDescriptors: e.targetDescriptors.map((d) => ({ ...d, target: identityValue(d.target) })).sort((a, b) => canonicalJson2(a.target) < canonicalJson2(b.target) ? -1 : canonicalJson2(a.target) > canonicalJson2(b.target) ? 1 : 0),
807
+ occurrences: e.occurrences.map((o) => ({ ...o, target: identityValue(o.target) })).sort((a, b) => a.occurrenceKey < b.occurrenceKey ? -1 : a.occurrenceKey > b.occurrenceKey ? 1 : 0)
808
+ }]));
809
+ }
810
+ function briefPresentation(p) {
811
+ return { label: p.label.state === "safe" ? p.label.text : p.label.display, ...p.detail?.state === "safe" ? { detail: p.detail.text } : {}, ...p.url.state === "exact" ? { url: p.url.href } : {} };
812
+ }
813
+ function briefApplyLimitCodes(input) {
814
+ const codes = new Set;
815
+ const { evidence: e, projection: p } = input;
816
+ if (utf8ByteLength(JSON.stringify(input)) > BRIEF_LIMITS.inputBytes)
817
+ codes.add("envelope-bytes");
818
+ if (p.targets.length > 256)
819
+ codes.add("target-count");
820
+ if (e.occurrences.length > 512)
821
+ codes.add("occurrence-count");
822
+ const per = new Map;
823
+ for (const o of e.occurrences) {
824
+ const k = canonicalJson2(o.target);
825
+ per.set(k, (per.get(k) ?? 0) + 1);
826
+ if (o.locator.section.heading?.state === "named" && utf8ByteLength(o.locator.section.heading.text) > 256)
827
+ codes.add("heading-bytes");
828
+ }
829
+ if ([...per.values()].some((n) => n > 100))
830
+ codes.add("per-target-occurrences");
831
+ for (const witness of [e.sourcePresentation, ...e.targetDescriptors.map((d) => d.presentation)]) {
832
+ const v = briefPresentation(witness);
833
+ if (witness.label.state === "safe" && utf8ByteLength(witness.label.text) > 256)
834
+ codes.add("presentation-label-bytes");
835
+ if (witness.detail?.state === "safe" && utf8ByteLength(witness.detail.text) > 1024)
836
+ codes.add("presentation-detail-bytes");
837
+ if (witness.url.state === "exact" && utf8ByteLength(witness.url.href) > 2048)
838
+ codes.add("presentation-url-bytes");
839
+ if (utf8ByteLength(JSON.stringify(v)) > 4096)
840
+ codes.add("presentation-bytes");
841
+ }
842
+ for (const r of [p.source, ...p.targets]) {
843
+ const v = r.presentation;
844
+ if (typeof v.label === "string" && utf8ByteLength(v.label) > 256)
845
+ codes.add("presentation-label-bytes");
846
+ if (typeof v.detail === "string" && utf8ByteLength(v.detail) > 1024)
847
+ codes.add("presentation-detail-bytes");
848
+ if (typeof v.url === "string" && utf8ByteLength(v.url) > 2048)
849
+ codes.add("presentation-url-bytes");
850
+ if (utf8ByteLength(JSON.stringify(v)) > 4096)
851
+ codes.add("presentation-bytes");
852
+ }
853
+ if (utf8ByteLength(JSON.stringify({ protocolVersion: 1, producerPluginId: p.producerPluginId, source: p.source, tombstone: p.tombstone, targets: p.targets })) > 262144)
854
+ codes.add("projection-bytes");
855
+ return [...codes].sort();
856
+ }
857
+
858
+ class BriefAdmissionError extends Error {
859
+ code;
860
+ limits;
861
+ constructor(code, limits = []) {
862
+ super(code === "over-limit" ? "Brief references exceed admitted limits." : code === "identity-unrepresentable" ? "Brief identity cannot be represented safely." : "Invalid brief evidence.");
863
+ this.code = code;
864
+ this.limits = limits;
865
+ this.name = "BriefAdmissionError";
866
+ }
867
+ }
868
+ function assertBriefDisplaySafe(e) {
869
+ const fields = [];
870
+ let index = 0;
871
+ const strings = (v, role) => {
872
+ if (typeof v === "string")
873
+ fields.push({ key: [index++], role, value: v });
874
+ else if (Array.isArray(v))
875
+ for (const x of v)
876
+ strings(x, role);
877
+ else if (v && typeof v === "object")
878
+ for (const x of Object.values(v))
879
+ strings(x, role);
880
+ };
881
+ strings(verifiedFileIdentity(e.sourceFile), "required-identity");
882
+ for (const d of e.targetDescriptors)
883
+ strings(identityValue(d.target), "required-identity");
884
+ const p = (v, source) => {
885
+ if (v.label.state === "safe")
886
+ strings(v.label.text, source ? "source-label" : "target-label");
887
+ if (v.detail?.state === "safe")
888
+ strings(v.detail.text, "detail");
889
+ if (v.url.state === "exact")
890
+ strings(v.url.href, "presentation-href");
891
+ };
892
+ p(e.sourcePresentation, true);
893
+ for (const d of e.targetDescriptors) {
894
+ p(d.presentation, false);
895
+ if (d.codec.state === "available")
896
+ strings(d.codec.value, "codec");
897
+ }
898
+ for (const o of e.occurrences) {
899
+ if (o.locator.section.heading?.state === "named")
900
+ strings(o.locator.section.heading.text, "heading");
901
+ if (o.provenance.state === "safe")
902
+ strings(o.provenance.value, "provenance");
903
+ if (o.authoredUrl.state === "exact")
904
+ strings(o.authoredUrl.href, "authored-url");
905
+ }
906
+ const result = classifyBriefDisplayFieldsV1(fields);
907
+ if (result.state !== "classified")
908
+ throw new BriefAdmissionError("identity-unrepresentable");
909
+ for (let i = 0;i < result.results.length; i++)
910
+ if (result.results[i].result.state !== "safe")
911
+ throw new BriefAdmissionError(fields[i].role === "required-identity" ? "identity-unrepresentable" : "invalid");
912
+ }
913
+ function validateBriefCommand(projection, evidence, evidenceDigest) {
914
+ const e = briefEvidenceSchema.parse(evidence);
915
+ if (projection.producerPluginId !== "thread-brief" || canonicalJson2(identityValue({ provider: projection.source.provider, keys: projection.source.keys })) !== canonicalJson2(verifiedFileIdentity(e.sourceFile)))
916
+ throw new BriefAdmissionError("invalid");
917
+ if (canonicalJson2(projection.source.presentation) !== canonicalJson2(briefPresentation(e.sourcePresentation)))
918
+ throw new BriefAdmissionError("invalid");
919
+ const targets = new Map(projection.targets.map((t) => {
920
+ const c = canonicalizeResource(t);
921
+ return [c.identityDigest, c];
922
+ }));
923
+ if (targets.size !== projection.targets.length || targets.size !== e.targetDescriptors.length)
924
+ throw new BriefAdmissionError("invalid");
925
+ const descriptors = new Set;
926
+ for (const d of e.targetDescriptors) {
927
+ const key = canonicalizeIdentity(d.target).identityDigest, t = targets.get(key);
928
+ if (!t || descriptors.has(key) || canonicalJson2(t.presentation) !== canonicalJson2(briefPresentation(d.presentation)))
929
+ throw new BriefAdmissionError("invalid");
930
+ descriptors.add(key);
931
+ if (d.codec.state === "available") {
932
+ const p = d.codec.value;
933
+ const decoded = p.kind === "file" ? verifiedFileIdentity(p.verified) : p.kind === "url" ? { provider: "url", keys: { href: new URL(p.href).href } } : recognitionIdentity(p.source, p.kind === "thread" ? p.verified : undefined);
934
+ if (canonicalJson2(identityValue(decoded)) !== canonicalJson2(identityValue(d.target)))
935
+ throw new BriefAdmissionError("invalid");
936
+ }
937
+ }
938
+ const limits = [], keys = new Set, ids = new Set, counts = new Map;
939
+ if (e.sourceState === "absent") {
940
+ if (e.sourceContentRevision !== null || e.frame !== null || e.occurrences.length || targets.size || !projection.tombstone)
941
+ throw new BriefAdmissionError("invalid");
942
+ } else {
943
+ if (e.sourceContentRevision === null || e.frame === null || e.sourceState === "empty" && (e.occurrences.length > 0 || targets.size > 0 || !projection.tombstone) || e.sourceState === "present" && projection.tombstone)
944
+ throw new BriefAdmissionError("invalid");
945
+ }
946
+ if (e.sourceState === "empty") {
947
+ const f = e.frame;
948
+ if (f.fileUtf16Length !== 0 || f.bodyBase.startUtf16 !== 0 || f.bodyBase.utf16Length !== 0 || f.bodyBase.startLine !== 1 || f.lineMapping.fileLineCount !== 1 || f.rawBytes !== f.bomBytes || e.sourceContentRevision !== sha256Hex(f.bomBytes === 3 ? "\uFEFF" : ""))
949
+ throw new BriefAdmissionError("invalid");
950
+ }
951
+ for (const o of e.occurrences) {
952
+ const key = canonicalizeIdentity(o.target).identityDigest;
953
+ counts.set(key, (counts.get(key) ?? 0) + 1);
954
+ if (!targets.has(key) || keys.has(o.occurrenceKey) || ids.has(o.sourceOccurrenceId) || o.locator.threadId !== e.sourceFile.threadId || canonicalJson2(o.locator.file) !== canonicalJson2(e.sourceFile) || o.locator.sourceContentRevision !== e.sourceContentRevision || o.occurrenceKey !== briefOccurrenceKey(e.sourceContentRevision, o.target, o.locator, o.sourceOccurrenceId))
955
+ throw new BriefAdmissionError("invalid");
956
+ const f = e.frame;
957
+ if (o.locator.section.line > f.lineMapping.fileLineCount || o.locator.location.line > f.lineMapping.fileLineCount || o.locator.location.endLine !== null && (o.locator.location.endLine < o.locator.location.line || o.locator.location.endLine > f.lineMapping.fileLineCount) || o.locator.span && o.locator.span.end > (o.locator.span.frame === "file-utf16" ? f.fileUtf16Length : f.bodyBase.utf16Length))
958
+ throw new BriefAdmissionError("invalid");
959
+ keys.add(o.occurrenceKey);
960
+ ids.add(o.sourceOccurrenceId);
961
+ }
962
+ if (counts.size !== targets.size)
963
+ throw new BriefAdmissionError("invalid");
964
+ if ([...counts.values()].some((n) => n > 100))
965
+ limits.push("per-target-occurrences");
966
+ if (limits.length)
967
+ throw new BriefAdmissionError("over-limit", limits);
968
+ assertBriefDisplaySafe(e);
969
+ if (briefEvidenceDigest(e) !== evidenceDigest)
970
+ throw new BriefAdmissionError("invalid");
971
+ return e;
972
+ }
973
+ var limitCodes = z2.array(z2.enum(BRIEF_LIMIT_CODES)).max(10).refine((v) => new Set(v).size === v.length && v.every((x, i) => i === 0 || v[i - 1] < x));
974
+ var identityCodes = z2.array(z2.enum(["unsafe-required-identity", "unsupported-required-codec", "required-identity-bound"])).min(1).max(3).refine((v) => new Set(v).size === v.length && v.every((x, i) => i === 0 || v[i - 1] < x));
975
+ var blockedBriefStatusSchema = z2.discriminatedUnion("state", [
976
+ z2.strictObject({ state: z2.literal("over-limit"), sourceContentRevision: digest, limits: limitCodes.refine((v) => v.length > 0) }),
977
+ z2.strictObject({ state: z2.literal("identity-unrepresentable"), sourceContentRevision: digest, identityReasons: identityCodes, limits: limitCodes })
978
+ ]);
979
+ function briefStatusDigest(producerPluginId, source, sourceFile, status) {
980
+ const s = blockedBriefStatusSchema.parse(status);
981
+ return sha256Hex(canonicalJson2(["brief-status", 1, producerPluginId, identityValue(source), briefFileSchema.parse(sourceFile), { ...s, limits: [...s.limits].sort(), ..."identityReasons" in s ? { identityReasons: [...s.identityReasons].sort() } : {} }]));
982
+ }
983
+ var producerGetStateInputSchema = z2.strictObject({ version: z2.literal(1), producerPluginId: z2.literal("thread-brief"), source: identity });
984
+ var producerReportStatusInputSchema = producerGetStateInputSchema.extend({ sourceFile: briefFileSchema, attemptRevision: positive, expectedRevision: integer, statusDigest: digest, status: blockedBriefStatusSchema }).superRefine((v, c) => {
985
+ if (canonicalJson2(identityValue(v.source)) !== canonicalJson2(verifiedFileIdentity(v.sourceFile)) || briefStatusDigest(v.producerPluginId, v.source, v.sourceFile, v.status) !== v.statusDigest)
986
+ c.addIssue({ code: "custom", message: "Invalid brief status binding." });
987
+ });
988
+ var presentationOut = z2.object({ label: labelText, detail: bytes(1024).refine((v) => !control(v) && v.trim().length > 0).optional(), url: bytes(2048).optional() }).passthrough();
989
+ var resourceOut = z2.object({ provider: z2.string(), keys: z2.record(z2.string(), z2.string()), presentation: presentationOut }).passthrough();
990
+ var projectionOut = z2.object({ producerPluginId: plugin, source: resourceOut, revision: integer, mutationId: z2.string(), payloadDigest: digest, tombstone: z2.boolean(), targets: z2.array(resourceOut).max(256) }).passthrough();
991
+ var statusOut = z2.union([
992
+ blockedBriefStatusSchema.options[0].extend({ attemptRevision: positive, statusDigest: digest, sourceFile: briefFileSchema.passthrough(), applicability: z2.enum(["current", "superseded-by-graph"]) }).passthrough(),
993
+ blockedBriefStatusSchema.options[1].extend({ attemptRevision: positive, statusDigest: digest, sourceFile: briefFileSchema.passthrough(), applicability: z2.enum(["current", "superseded-by-graph"]) }).passthrough()
994
+ ]);
995
+ var producerStateSchema = z2.object({ version: z2.literal(1), projection: projectionOut.nullable(), evidence: z2.object({ kind: z2.literal("thread-brief"), graphRevision: positive, graphPayloadDigest: digest, evidenceDigest: digest, sourceContentRevision: digest.nullable(), state: z2.enum(["bound", "unconfirmed"]), sourceState: z2.enum(["present", "absent", "empty"]), occurrenceCount: integer.max(512) }).passthrough().nullable(), status: statusOut.nullable(), revisionHighWater: integer }).passthrough();
996
+ var producerDescribeInputSchema = z2.null();
997
+ var producerDescribeOutputSchema = z2.object({ protocol: z2.literal("cross-references-producer"), versions: z2.array(positive).max(16), sourceKinds: z2.array(z2.literal("thread-brief")).max(1), limits: z2.object({ inputBytes: positive, statusBytes: positive, locations: positive, perTarget: positive, headingBytes: positive, limitCodes: z2.array(z2.string()).max(32) }).passthrough() }).passthrough();
998
+ var producerDescribe = () => ({ protocol: "cross-references-producer", versions: [1], sourceKinds: ["thread-brief"], limits: { inputBytes: BRIEF_LIMITS.inputBytes, statusBytes: BRIEF_LIMITS.statusBytes, locations: 512, perTarget: 100, headingBytes: 256, limitCodes: [...BRIEF_LIMIT_CODES] } });
999
+ function projectionValue(value) {
1000
+ const resource = (r) => ({ provider: r.provider, keys: r.keys, presentation: { label: r.presentation.label, ...r.presentation.detail === undefined ? {} : { detail: r.presentation.detail }, ...r.presentation.url === undefined ? {} : { url: r.presentation.url } } });
1001
+ return { protocolVersion: value.protocolVersion, producerPluginId: value.producerPluginId, mutationId: value.mutationId, source: resource(value.source), revision: value.revision, expectedRevision: value.expectedRevision, payloadDigest: value.payloadDigest, tombstone: value.tombstone, targets: value.targets.map(resource) };
1002
+ }
1003
+ function createProducerSchemas(projection) {
1004
+ const admittedProjection = projection.transform(projectionValue);
1005
+ return {
1006
+ [PRODUCER_METHODS.describe]: { input: producerDescribeInputSchema, output: producerDescribeOutputSchema },
1007
+ [PRODUCER_METHODS.getState]: { input: producerGetStateInputSchema, output: producerStateSchema },
1008
+ [PRODUCER_METHODS.apply]: { input: z2.strictObject({ version: z2.literal(1), projection: admittedProjection, evidence: briefEvidenceSchema, evidenceDigest: digest }), output: z2.object({ version: z2.literal(1), outcome: z2.enum(["applied", "duplicate", "equal", "stale", "conflict", "cas-mismatch"]), currentRevision: integer, currentDigest: digest.nullable(), evidenceDisposition: z2.enum(["installed", "replayed", "conflict", "not-applied"]), state: producerStateSchema }).passthrough() },
1009
+ [PRODUCER_METHODS.reportStatus]: { input: producerReportStatusInputSchema, output: z2.object({ version: z2.literal(1), outcome: z2.enum(["recorded", "duplicate", "stale", "conflict", "cas-mismatch"]), state: producerStateSchema }).passthrough() }
1010
+ };
1011
+ }
1012
+ var briefNavigationInputSchema = z2.strictObject({ version: z2.literal(1), sourceFile: briefFileSchema, sourceContentRevision: digest, frame: briefFrameSchema, section: z2.strictObject({ heading: briefHeadingSchema, originalLine: positive }) });
1013
+ var briefNavigationOutputSchema = z2.discriminatedUnion("state", [
1014
+ z2.object({ version: z2.literal(1), state: z2.literal("ready"), sourceFile: briefFileSchema.passthrough(), sourceContentRevision: digest, location: z2.object({ kind: z2.literal("line"), line: positive, column: z2.null() }).passthrough(), proof: z2.object({ kind: z2.literal("accepted-revision-revalidated"), acceptedRevision: digest, selection: z2.literal("same-revision"), frame: briefFrameSchema.safeExtend({ bodyBase: briefFrameSchema.shape.bodyBase.passthrough(), lineMapping: briefFrameSchema.shape.lineMapping.passthrough() }).passthrough() }).passthrough() }).passthrough(),
1015
+ z2.object({ version: z2.literal(1), state: z2.literal("fallback"), sourceFile: briefFileSchema.passthrough(), location: z2.null(), reason: z2.enum(["stale", "no-accepted-document", "ambiguous", "heading-unavailable", "source-unavailable", "over-limit"]) }).passthrough()
1016
+ ]);
1017
+ var briefNavigationDescribeOutputSchema = z2.object({ protocol: z2.literal("thread-brief-navigation"), versions: z2.array(positive).max(16) }).passthrough();
1018
+ var briefNavigationRpcSchemas = { [BRIEF_NAVIGATION_METHODS.describe]: { input: z2.null(), output: briefNavigationDescribeOutputSchema }, [BRIEF_NAVIGATION_METHODS.resolve]: { input: briefNavigationInputSchema, output: briefNavigationOutputSchema } };
1019
+ var outWithheld = (display) => withheld(display).passthrough();
1020
+ var briefHeadingOutputSchema = z2.union([z2.null(), z2.object({ state: z2.literal("named"), text: bytes(256) }).passthrough(), outWithheld("Heading withheld")]);
1021
+ var briefFileOutputSchema = briefFileSchema.passthrough();
1022
+ var briefFrameOutputSchema = briefFrameSchema.safeExtend({ bodyBase: briefFrameSchema.shape.bodyBase.passthrough(), lineMapping: briefFrameSchema.shape.lineMapping.passthrough() }).passthrough();
1023
+ var briefLocatorOutputSchema = briefLocatorSchema.extend({ file: briefFileOutputSchema, section: z2.object({ heading: briefHeadingOutputSchema, line: positive }).passthrough(), location: briefLocatorSchema.shape.location.passthrough(), span: briefLocatorSchema.shape.span.unwrap().passthrough().optional() }).passthrough();
1024
+ var verifiedFileOutput = z2.union([VerifiedFileTargetSchema.options[0].passthrough(), VerifiedFileTargetSchema.options[1].passthrough()]);
1025
+ var provenanceValueOutput = provenanceValue.extend({ source: SourceIdentitySchema2.passthrough(), verifiedFile: verifiedFileOutput.optional(), recognition: provenanceValue.shape.recognition.extend({ evidence: provenanceValue.shape.recognition.shape.evidence.unwrap().extend({ span: span.passthrough().optional() }).passthrough().optional() }).passthrough() }).passthrough();
1026
+ var briefProvenanceOutputSchema = z2.union([z2.object({ state: z2.literal("safe"), value: provenanceValueOutput }).passthrough(), outWithheld("Recognition details withheld").extend({ summary: provenanceSummary.passthrough() })]);
1027
+ var briefAuthoredUrlOutputSchema = z2.union([z2.object({ state: z2.literal("exact"), href: safeHref }).passthrough(), z2.object({ state: z2.literal("not-url") }).passthrough(), z2.object({ state: z2.literal("unknown") }).passthrough(), outWithheld("Destination withheld")]);
1028
+ function validateBriefNavigationResultV1(input, raw) {
1029
+ const value = briefNavigationOutputSchema.parse(raw), file = value.sourceFile;
1030
+ if (file.kind !== input.sourceFile.kind || file.threadId !== input.sourceFile.threadId || file.path !== input.sourceFile.path)
1031
+ throw new Error("Brief navigation target mismatch.");
1032
+ if (value.state === "ready" && (value.sourceContentRevision !== input.sourceContentRevision || value.proof.acceptedRevision !== input.sourceContentRevision || canonicalJson2(knownFrame(value.proof.frame)) !== canonicalJson2(knownFrame(input.frame)) || value.location.line !== input.section.originalLine || value.location.line > input.frame.lineMapping.fileLineCount))
1033
+ throw new Error("Brief navigation proof mismatch.");
1034
+ return value;
1035
+ }
1036
+ function knownFrame(f) {
1037
+ return { codec: f.codec, rawBytes: f.rawBytes, bomBytes: f.bomBytes, fileUtf16Length: f.fileUtf16Length, bodyBase: { startUtf16: f.bodyBase.startUtf16, startLine: f.bodyBase.startLine, utf16Length: f.bodyBase.utf16Length }, lineMapping: { codec: f.lineMapping.codec, fileLineCount: f.lineMapping.fileLineCount } };
1038
+ }
1039
+
1040
+ // src/evidence-v2.ts
1041
+ import { z as z3 } from "zod";
1042
+ import { ContextBundleV1Schema, SafeHrefSchema as SafeHrefSchema3, CandidateV1Schema, SourceIdentitySchema as SourceIdentitySchema3 } from "@phosphorco/bb-context-recognition";
421
1043
  var MENTION_V2_LIMITS = Object.freeze({
422
1044
  responseBytes: 1048576,
423
1045
  inputBytes: 65536,
@@ -432,13 +1054,13 @@ var MENTION_V2_LIMITS = Object.freeze({
432
1054
  lookupCalls: 8
433
1055
  });
434
1056
  var MENTION_V2_METHODS = Object.freeze({ list: "crossReferencesV2ListMentions", resolve: "crossReferencesV2ResolveLookup" });
435
- var integer = () => z2.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER);
436
- var time = () => integer().max(8640000000000000);
437
- var digest = z2.string().regex(/^[a-f0-9]{64}$/);
438
- var text = (n) => z2.string().max(n).refine((v) => utf8ByteLength(v) <= n, "UTF8 byte bound exceeded.");
439
- var id = z2.string().min(1).max(256).refine((v) => !/[\p{Cc}]/u.test(v));
440
- var producer = z2.string().regex(/^[a-z][a-z0-9._-]{0,63}$/);
441
- var keys = z2.record(z2.string(), z2.string()).refine((v) => Object.keys(v).length <= 16);
1057
+ var integer2 = () => z3.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER);
1058
+ var time = () => integer2().max(8640000000000000);
1059
+ var digest2 = z3.string().regex(/^[a-f0-9]{64}$/);
1060
+ var text = (n) => z3.string().max(n).refine((v) => utf8ByteLength(v) <= n, "UTF8 byte bound exceeded.");
1061
+ var id = z3.string().min(1).max(256).refine((v) => !/[\p{Cc}]/u.test(v));
1062
+ var producer = z3.string().regex(/^[a-z][a-z0-9._-]{0,63}$/);
1063
+ var keys = z3.record(z3.string(), z3.string()).refine((v) => Object.keys(v).length <= 16);
442
1064
  function isUtf16CodePointBoundary(text2, offset) {
443
1065
  if (!Number.isSafeInteger(offset) || offset < 0 || offset > text2.length)
444
1066
  return false;
@@ -453,110 +1075,125 @@ function wellFormedUtf16(text2) {
453
1075
  }
454
1076
  return true;
455
1077
  }
456
- var identityShape = { provider: z2.string().min(1).max(64), keys };
457
- var identityInputV2Schema = z2.strictObject(identityShape).superRefine((v, c) => {
1078
+ var identityShape = { provider: z3.string().min(1).max(64), keys };
1079
+ var identityInputV2Schema = z3.strictObject(identityShape).superRefine((v, c) => {
458
1080
  try {
459
1081
  canonicalizeIdentity(v);
460
1082
  } catch {
461
1083
  c.addIssue({ code: "custom", message: "Invalid resource identity." });
462
1084
  }
463
1085
  });
464
- var presentation = z2.object({ label: text(256).min(1), url: text(2048).optional(), detail: text(1024).optional() }).passthrough();
465
- var resourceOutputV2Schema = z2.object({ ...identityShape, presentation }).passthrough().superRefine((v, c) => {
1086
+ var presentation2 = z3.object({ label: text(256).min(1), url: text(2048).optional(), detail: text(1024).optional() }).passthrough();
1087
+ var resourceOutputV2Schema = z3.object({ ...identityShape, presentation: presentation2 }).passthrough().superRefine((v, c) => {
466
1088
  try {
467
1089
  canonicalizeResource({ provider: v.provider, keys: v.keys, presentation: { label: v.presentation.label, ...v.presentation.url === undefined ? {} : { url: v.presentation.url }, ...v.presentation.detail === undefined ? {} : { detail: v.presentation.detail } } });
468
1090
  } catch {
469
1091
  c.addIssue({ code: "custom", message: "Invalid resource." });
470
1092
  }
471
1093
  });
472
- var safeAuthoredHrefSchema = SafeHrefSchema2.refine((v) => utf8ByteLength(v) <= 16384 && !hasSensitiveUrlParameter(new URL(v, "https://local.invalid")), "Unsafe destination.");
473
- var mentionQueryV2Schema = z2.discriminatedUnion("kind", [
474
- z2.strictObject({ kind: z2.literal("resource"), target: identityInputV2Schema, relation: z2.enum(["self", "github-pr-family"]) }).refine((v) => v.relation === "self" || v.target.provider === "recognition" && v.target.keys.provider === "github" && /^[a-f0-9]{64}$/.test(v.target.keys.identity ?? ""), "Expected a GitHub root identity."),
475
- z2.strictObject({ kind: z2.literal("authored-url"), href: safeAuthoredHrefSchema })
1094
+ var safeAuthoredHrefSchema = SafeHrefSchema3.refine((v) => utf8ByteLength(v) <= 16384 && !hasSensitiveUrlParameter(new URL(v, "https://local.invalid")), "Unsafe destination.");
1095
+ var mentionQueryV2Schema = z3.discriminatedUnion("kind", [
1096
+ z3.strictObject({ kind: z3.literal("resource"), target: identityInputV2Schema, relation: z3.enum(["self", "github-pr-family"]) }).refine((v) => v.relation === "self" || v.target.provider === "recognition" && v.target.keys.provider === "github" && /^[a-f0-9]{64}$/.test(v.target.keys.identity ?? ""), "Expected a GitHub root identity."),
1097
+ z3.strictObject({ kind: z3.literal("authored-url"), href: safeAuthoredHrefSchema })
476
1098
  ]);
477
- var listMentionsInputV2Schema = z2.strictObject({
478
- version: z2.literal(2),
1099
+ var listMentionsInputV2Schema = z3.strictObject({
1100
+ version: z3.literal(2),
479
1101
  query: mentionQueryV2Schema,
480
1102
  source: identityInputV2Schema.optional(),
481
1103
  producerPluginId: producer.optional(),
482
- pageSize: z2.number().int().min(1).max(100).optional(),
1104
+ pageSize: z3.number().int().min(1).max(100).optional(),
483
1105
  cursor: text(4096).optional(),
484
- ifSnapshot: digest.optional()
1106
+ ifSnapshot: digest2.optional()
485
1107
  }).refine((v) => !(v.cursor !== undefined && v.ifSnapshot !== undefined), "Cursor and conditional are exclusive.");
486
- var spanShape = { start: integer(), end: integer() };
487
- var spanOutputV2Schema = z2.object(spanShape).passthrough().refine((v) => v.end > v.start);
1108
+ var spanShape = { start: integer2(), end: integer2() };
1109
+ var spanOutputV2Schema = z3.object(spanShape).passthrough().refine((v) => v.end > v.start);
488
1110
  var readyShape = {
489
- state: z2.literal("ready"),
490
- text: z2.string().refine(wellFormedUtf16, "Excerpt text must be well-formed UTF16.").refine((v) => [...v].length <= 320 && utf8ByteLength(v) <= 1280),
1111
+ state: z3.literal("ready"),
1112
+ text: z3.string().refine(wellFormedUtf16, "Excerpt text must be well-formed UTF16.").refine((v) => [...v].length <= 320 && utf8ByteLength(v) <= 1280),
491
1113
  sourceSpan: spanOutputV2Schema,
492
1114
  matchSpan: spanOutputV2Schema,
493
- clippedBefore: z2.boolean(),
494
- clippedAfter: z2.boolean(),
495
- matchClippedBefore: z2.boolean(),
496
- matchClippedAfter: z2.boolean(),
497
- codecVersion: z2.literal(1)
1115
+ clippedBefore: z3.boolean(),
1116
+ clippedAfter: z3.boolean(),
1117
+ matchClippedBefore: z3.boolean(),
1118
+ matchClippedAfter: z3.boolean(),
1119
+ codecVersion: z3.literal(1)
498
1120
  };
499
1121
  var readyCoordinates = (v) => v.matchSpan.end <= v.text.length && v.sourceSpan.end - v.sourceSpan.start === v.text.length && isUtf16CodePointBoundary(v.text, v.matchSpan.start) && isUtf16CodePointBoundary(v.text, v.matchSpan.end);
500
- var excerptV2Schema = z2.discriminatedUnion("state", [
501
- z2.object(readyShape).passthrough().refine(readyCoordinates, "Excerpt bounds must be code-point aligned."),
502
- z2.object({ state: z2.literal("unavailable"), reason: z2.enum(["not-materialized", "indivisible-word", "no-eligible-context"]), codecVersion: z2.literal(1) }).passthrough()
1122
+ var excerptV2Schema = z3.discriminatedUnion("state", [
1123
+ z3.object(readyShape).passthrough().refine(readyCoordinates, "Excerpt bounds must be code-point aligned."),
1124
+ z3.object({ state: z3.literal("unavailable"), reason: z3.enum(["not-materialized", "indivisible-word", "no-eligible-context"]), codecVersion: z3.literal(1) }).passthrough()
503
1125
  ]);
504
- var excerptRecordV2Schema = z2.discriminatedUnion("state", [
505
- z2.strictObject({ ...readyShape, sourceSpan: z2.strictObject(spanShape).refine((v) => v.end > v.start), matchSpan: z2.strictObject(spanShape).refine((v) => v.end > v.start) }).refine(readyCoordinates, "Excerpt bounds must be code-point aligned."),
506
- z2.strictObject({ state: z2.literal("unavailable"), reason: z2.enum(["indivisible-word", "no-eligible-context"]), codecVersion: z2.literal(1) })
1126
+ var excerptRecordV2Schema = z3.discriminatedUnion("state", [
1127
+ z3.strictObject({ ...readyShape, sourceSpan: z3.strictObject(spanShape).refine((v) => v.end > v.start), matchSpan: z3.strictObject(spanShape).refine((v) => v.end > v.start) }).refine(readyCoordinates, "Excerpt bounds must be code-point aligned."),
1128
+ z3.strictObject({ state: z3.literal("unavailable"), reason: z3.enum(["indivisible-word", "no-eligible-context"]), codecVersion: z3.literal(1) })
507
1129
  ]);
508
- var locatorOutputV2Schema = z2.object({ kind: z2.literal("conversation"), threadId: id, messageId: id, messageSeq: integer(), anchorSeq: integer().nullable(), role: z2.enum(["user", "assistant"]) }).passthrough();
509
- var recognitionProvenance = z2.object({
1130
+ var locatorOutputV2Schema = z3.object({ kind: z3.literal("conversation"), threadId: id, messageId: id, messageSeq: integer2(), anchorSeq: integer2().nullable(), role: z3.enum(["user", "assistant"]) }).passthrough();
1131
+ var recognitionProvenance = z3.object({
510
1132
  pluginId: id,
511
- origin: z2.enum(["builtin", "contributed"]),
1133
+ origin: z3.enum(["builtin", "contributed"]),
512
1134
  confidence: CandidateV1Schema.shape.confidence,
513
- recognition: z2.object({
514
- basis: z2.enum(["explicit", "text-url", "existing-link", "git-remote", "context"]),
515
- explanation: z2.string().min(1).max(200),
516
- evidence: z2.object({ span: spanOutputV2Schema.optional(), link: integer().optional(), remote: id.optional() }).passthrough().optional()
1135
+ recognition: z3.object({
1136
+ basis: z3.enum(["explicit", "text-url", "existing-link", "git-remote", "context"]),
1137
+ explanation: z3.string().min(1).max(200),
1138
+ evidence: z3.object({ span: spanOutputV2Schema.optional(), link: integer2().optional(), remote: id.optional() }).passthrough().optional()
517
1139
  }).passthrough(),
518
- source: SourceIdentitySchema2.passthrough(),
1140
+ source: SourceIdentitySchema3.passthrough(),
519
1141
  authoredHref: safeAuthoredHrefSchema.optional(),
520
1142
  verifiedFile: VerifiedFileTargetSchema.optional()
521
1143
  }).passthrough();
522
- var verifiedFileOutput = z2.union([
523
- z2.object({ kind: z2.literal("workspace"), environmentId: id, path: z2.string().min(1).max(4096) }).passthrough(),
524
- z2.object({ kind: z2.literal("thread-storage"), threadId: id, path: z2.string().min(1).max(4096) }).passthrough()
1144
+ var verifiedFileOutput2 = z3.union([
1145
+ z3.object({ kind: z3.literal("workspace"), environmentId: id, path: z3.string().min(1).max(4096) }).passthrough(),
1146
+ z3.object({ kind: z3.literal("thread-storage"), threadId: id, path: z3.string().min(1).max(4096) }).passthrough()
525
1147
  ]);
526
- var provenanceOutput = recognitionProvenance.extend({ verifiedFile: verifiedFileOutput.optional() });
1148
+ var provenanceOutput = recognitionProvenance.extend({ verifiedFile: verifiedFileOutput2.optional() });
527
1149
  var claimShape = {
528
1150
  source: resourceOutputV2Schema,
529
1151
  target: resourceOutputV2Schema,
530
1152
  producerPluginId: producer,
531
- graphRevision: integer(),
532
- cap: z2.object({ state: z2.enum(["uncapped", "capped", "unknown"]), limit: z2.literal(100).nullable(), sourceHistoryUnknown: z2.boolean().nullable() }).passthrough()
1153
+ graphRevision: integer2(),
1154
+ cap: z3.object({ state: z3.enum(["uncapped", "capped", "unknown"]), limit: z3.literal(100).nullable(), sourceHistoryUnknown: z3.boolean().nullable() }).passthrough()
533
1155
  };
534
- var knownItem = z2.discriminatedUnion("kind", [
535
- z2.object({
1156
+ var knownItem = z3.discriminatedUnion("kind", [
1157
+ z3.object({
536
1158
  ...claimShape,
537
- kind: z2.literal("occurrence"),
538
- evidenceRevision: integer().min(1),
539
- occurrenceKey: digest,
1159
+ kind: z3.literal("brief-occurrence"),
1160
+ evidenceRevision: integer2().min(1),
1161
+ occurrenceKey: digest2,
1162
+ sourceOccurrenceId: text(256),
1163
+ locator: briefLocatorOutputSchema,
1164
+ sourceContentRevision: digest2,
1165
+ frame: briefFrameOutputSchema,
1166
+ excerpt: z3.object({ state: z3.literal("unavailable"), reason: z3.literal("not-materialized"), codecVersion: z3.literal(1) }).passthrough(),
1167
+ provenance: briefProvenanceOutputSchema,
1168
+ authoredUrl: briefAuthoredUrlOutputSchema,
1169
+ authoredUrlState: z3.enum(["exact", "not-url", "unknown", "withheld"]),
1170
+ confirmation: z3.enum(["producer-attested", "retained-unconfirmed"])
1171
+ }).passthrough().refine((v) => v.authoredUrlState === v.authoredUrl.state && v.sourceContentRevision === v.locator.sourceContentRevision && v.locator.threadId === v.locator.file.threadId, "Inconsistent Brief item."),
1172
+ z3.object({
1173
+ ...claimShape,
1174
+ kind: z3.literal("occurrence"),
1175
+ evidenceRevision: integer2().min(1),
1176
+ occurrenceKey: digest2,
540
1177
  locator: locatorOutputV2Schema,
541
- sourceContentRevision: digest,
1178
+ sourceContentRevision: digest2,
542
1179
  span: spanOutputV2Schema,
543
1180
  excerpt: excerptV2Schema,
544
1181
  messageCreatedAt: time(),
545
1182
  observedAt: time(),
546
- confirmation: z2.enum(["observed", "retained-unconfirmed"]),
1183
+ confirmation: z3.enum(["observed", "retained-unconfirmed"]),
547
1184
  provenance: provenanceOutput,
548
- authoredUrlState: z2.enum(["exact", "not-url", "unknown"])
1185
+ authoredUrlState: z3.enum(["exact", "not-url", "unknown"])
549
1186
  }).passthrough(),
550
- z2.object({ ...claimShape, kind: z2.literal("claim-without-evidence"), reason: z2.enum(["legacy", "producer-no-evidence", "not-yet-collected"]), matchBasis: z2.enum(["primary-resource", "primary-url-identity"]) }).passthrough(),
551
- z2.object({ ...claimShape, kind: z2.literal("unsupported"), reason: z2.literal("unsupported-format") }).passthrough()
1187
+ z3.object({ ...claimShape, kind: z3.literal("claim-without-evidence"), reason: z3.enum(["legacy", "producer-no-evidence", "not-yet-collected"]), matchBasis: z3.enum(["primary-resource", "primary-url-identity"]) }).passthrough(),
1188
+ z3.object({ ...claimShape, kind: z3.literal("unsupported"), reason: z3.literal("unsupported-format") }).passthrough()
552
1189
  ]);
553
- var mentionItemV2Schema = z2.unknown().transform((raw, ctx) => {
1190
+ var mentionItemV2Schema = z3.unknown().transform((raw, ctx) => {
554
1191
  const r = raw;
555
1192
  const unknown = (value, known) => typeof value === "string" && !known.includes(value);
556
- const future = !!r && typeof r === "object" && (unknown(r.kind, ["occurrence", "claim-without-evidence", "unsupported"]) || r.kind === "occurrence" && (unknown(r.locator?.kind, ["conversation"]) || unknown(r.excerpt?.state, ["ready", "unavailable"]) || typeof r.excerpt?.codecVersion === "number" && r.excerpt.codecVersion !== 1 || unknown(r.confirmation, ["observed", "retained-unconfirmed"]) || unknown(r.authoredUrlState, ["exact", "not-url", "unknown"]) || unknown(r.locator?.role, ["user", "assistant"]) || unknown(r.provenance?.origin, ["builtin", "contributed"]) || unknown(r.provenance?.confidence, ["high", "medium", "low"]) || unknown(r.provenance?.recognition?.basis, ["explicit", "text-url", "existing-link", "git-remote", "context"]) || r.excerpt?.state === "unavailable" && unknown(r.excerpt.reason, ["not-materialized", "indivisible-word", "no-eligible-context"])) || r.kind === "claim-without-evidence" && (unknown(r.reason, ["legacy", "producer-no-evidence", "not-yet-collected"]) || unknown(r.matchBasis, ["primary-resource", "primary-url-identity"])) || unknown(r.cap?.state, ["uncapped", "capped", "unknown"]));
557
- if (future && (!r.cap || !z2.object({ state: z2.string(), limit: z2.literal(100).nullable(), sourceHistoryUnknown: z2.boolean().nullable() }).safeParse(r.cap).success)) {
1193
+ const future = !!r && typeof r === "object" && (unknown(r.kind, ["occurrence", "brief-occurrence", "claim-without-evidence", "unsupported"]) || r.kind === "occurrence" && (unknown(r.locator?.kind, ["conversation"]) || unknown(r.excerpt?.state, ["ready", "unavailable"]) || typeof r.excerpt?.codecVersion === "number" && r.excerpt.codecVersion !== 1 || unknown(r.confirmation, ["observed", "retained-unconfirmed"]) || unknown(r.authoredUrlState, ["exact", "not-url", "unknown"]) || unknown(r.locator?.role, ["user", "assistant"]) || unknown(r.provenance?.origin, ["builtin", "contributed"]) || unknown(r.provenance?.confidence, ["high", "medium", "low"]) || unknown(r.provenance?.recognition?.basis, ["explicit", "text-url", "existing-link", "git-remote", "context"]) || r.excerpt?.state === "unavailable" && unknown(r.excerpt.reason, ["not-materialized", "indivisible-word", "no-eligible-context"])) || r.kind === "brief-occurrence" && (unknown(r.locator?.kind, ["thread-brief"]) || unknown(r.confirmation, ["producer-attested", "retained-unconfirmed"]) || unknown(r.authoredUrlState, ["exact", "not-url", "unknown", "withheld"]) || unknown(r.provenance?.state, ["safe", "withheld"]) || unknown(r.locator?.section?.heading?.state, ["named", "withheld"]) || unknown(r.locator?.section?.heading?.cause, ["policy", "unclassified"]) || unknown(r.provenance?.cause, ["policy", "unclassified"]) || unknown(r.authoredUrl?.state, ["exact", "not-url", "unknown", "withheld"]) || unknown(r.authoredUrl?.cause, ["policy", "unclassified"]) || unknown(r.frame?.codec, ["utf8-fatal-bom-consumed-v1"]) || unknown(r.frame?.lineMapping?.codec, ["native-file-lines-v1"]) || unknown(r.locator?.location?.kind, ["line"]) || unknown(r.locator?.span?.frame, ["file-utf16", "body-utf16"]) || unknown(r.excerpt?.state, ["unavailable"]) || unknown(r.excerpt?.reason, ["not-materialized"]) || typeof r.excerpt?.codecVersion === "number" && r.excerpt.codecVersion !== 1) || r.kind === "claim-without-evidence" && (unknown(r.reason, ["legacy", "producer-no-evidence", "not-yet-collected"]) || unknown(r.matchBasis, ["primary-resource", "primary-url-identity"])) || unknown(r.cap?.state, ["uncapped", "capped", "unknown"]));
1194
+ if (future && (!r.cap || !z3.object({ state: z3.string(), limit: z3.literal(100).nullable(), sourceHistoryUnknown: z3.boolean().nullable() }).safeParse(r.cap).success)) {
558
1195
  ctx.addIssue({ code: "custom", message: "Invalid required claim cap." });
559
- return z2.NEVER;
1196
+ return z3.NEVER;
560
1197
  }
561
1198
  const candidate = future ? {
562
1199
  source: r.source,
@@ -571,51 +1208,51 @@ var mentionItemV2Schema = z2.unknown().transform((raw, ctx) => {
571
1208
  if (parsed.success)
572
1209
  return parsed.data;
573
1210
  ctx.addIssue({ code: "custom", message: "Invalid mention item." });
574
- return z2.NEVER;
1211
+ return z3.NEVER;
575
1212
  });
576
- var mentionCountsV2Schema = z2.object({ retainedOccurrences: integer(), confirmedOccurrences: integer(), unconfirmedOccurrences: integer(), producerClaims: integer(), indexedSources: integer(), claimsWithoutLocations: integer(), excerptUnavailable: integer() }).passthrough().refine((v) => v.confirmedOccurrences + v.unconfirmedOccurrences === v.retainedOccurrences && v.claimsWithoutLocations <= v.producerClaims && v.indexedSources <= v.producerClaims && v.excerptUnavailable <= v.retainedOccurrences);
577
- var coverageV2Schema = z2.object({
578
- scope: z2.literal("known-sources"),
579
- collectionIncomplete: z2.boolean(),
580
- retentionLimited: z2.boolean(),
581
- capHistoryUnknown: z2.boolean(),
582
- legacyClaimsPresent: z2.boolean(),
583
- evidenceStateUnknown: z2.boolean(),
584
- authoredUrlCoverage: z2.object({ state: z2.enum(["complete-for-known-locations", "partial"]), unknownLocations: integer(), scope: z2.literal("known-locations"), watermark: digest }).passthrough(),
585
- reasons: z2.array(text(128)).max(32),
586
- reasonsClipped: z2.boolean(),
1213
+ var mentionCountsV2Schema = z3.object({ retainedOccurrences: integer2(), confirmedOccurrences: integer2(), unconfirmedOccurrences: integer2(), producerClaims: integer2(), indexedSources: integer2(), claimsWithoutLocations: integer2(), excerptUnavailable: integer2() }).passthrough().refine((v) => v.confirmedOccurrences + v.unconfirmedOccurrences === v.retainedOccurrences && v.claimsWithoutLocations <= v.producerClaims && v.indexedSources <= v.producerClaims && v.excerptUnavailable <= v.retainedOccurrences);
1214
+ var coverageV2Schema = z3.object({
1215
+ scope: z3.literal("known-sources"),
1216
+ collectionIncomplete: z3.boolean(),
1217
+ retentionLimited: z3.boolean(),
1218
+ capHistoryUnknown: z3.boolean(),
1219
+ legacyClaimsPresent: z3.boolean(),
1220
+ evidenceStateUnknown: z3.boolean(),
1221
+ authoredUrlCoverage: z3.object({ state: z3.enum(["complete-for-known-locations", "partial"]), unknownLocations: integer2(), scope: z3.literal("known-locations"), watermark: digest2 }).passthrough(),
1222
+ reasons: z3.array(text(128)).max(32),
1223
+ reasonsClipped: z3.boolean(),
587
1224
  checkedAt: time().nullable()
588
1225
  }).passthrough();
589
- var listMentionsOutputV2Schema = z2.discriminatedUnion("status", [
590
- z2.object({ version: z2.literal(2), status: z2.literal("page"), snapshot: digest, items: z2.array(mentionItemV2Schema).max(100), counts: mentionCountsV2Schema, coverage: coverageV2Schema, nextCursor: text(4096).nullable() }).passthrough(),
591
- z2.object({ version: z2.literal(2), status: z2.literal("not-modified"), snapshot: digest, coverage: coverageV2Schema }).passthrough(),
592
- z2.object({ version: z2.literal(2), status: z2.literal("restart"), reason: z2.literal("snapshot-changed"), snapshot: digest }).passthrough(),
593
- z2.object({ version: z2.literal(2), status: z2.literal("unavailable"), reason: z2.enum(["index-warming", "read-budget"]), retryable: z2.boolean() }).passthrough()
1226
+ var listMentionsOutputV2Schema = z3.discriminatedUnion("status", [
1227
+ z3.object({ version: z3.literal(2), status: z3.literal("page"), snapshot: digest2, items: z3.array(mentionItemV2Schema).max(100), counts: mentionCountsV2Schema, coverage: coverageV2Schema, nextCursor: text(4096).nullable() }).passthrough(),
1228
+ z3.object({ version: z3.literal(2), status: z3.literal("not-modified"), snapshot: digest2, coverage: coverageV2Schema }).passthrough(),
1229
+ z3.object({ version: z3.literal(2), status: z3.literal("restart"), reason: z3.literal("snapshot-changed"), snapshot: digest2 }).passthrough(),
1230
+ z3.object({ version: z3.literal(2), status: z3.literal("unavailable"), reason: z3.enum(["index-warming", "read-budget"]), retryable: z3.boolean() }).passthrough()
594
1231
  ]);
595
- var lookupContextV2Schema = ContextBundleV1Schema.omit({ consumer: true, links: true }).extend({ links: z2.array(z2.strictObject({ href: safeAuthoredHrefSchema })).max(16).optional() });
596
- var resolveLookupInputV2Schema = z2.strictObject({ version: z2.literal(2), text: z2.string().min(1).max(4096).refine((v) => utf8ByteLength(v) <= 16384), mode: z2.enum(["recognize", "exact-url"]), context: lookupContextV2Schema.optional() });
597
- var identityOutput = z2.object(identityShape).passthrough().superRefine((v, c) => {
1232
+ var lookupContextV2Schema = ContextBundleV1Schema.omit({ consumer: true, links: true }).extend({ links: z3.array(z3.strictObject({ href: safeAuthoredHrefSchema })).max(16).optional() });
1233
+ var resolveLookupInputV2Schema = z3.strictObject({ version: z3.literal(2), text: z3.string().min(1).max(4096).refine((v) => utf8ByteLength(v) <= 16384), mode: z3.enum(["recognize", "exact-url"]), context: lookupContextV2Schema.optional() });
1234
+ var identityOutput = z3.object(identityShape).passthrough().superRefine((v, c) => {
598
1235
  try {
599
1236
  canonicalizeIdentity({ provider: v.provider, keys: v.keys });
600
1237
  } catch {
601
1238
  c.addIssue({ code: "custom", message: "Invalid lookup identity." });
602
1239
  }
603
1240
  });
604
- var queryOutput = z2.discriminatedUnion("kind", [
605
- z2.object({ kind: z2.literal("resource"), target: identityOutput, relation: z2.enum(["self", "github-pr-family"]) }).passthrough(),
606
- z2.object({ kind: z2.literal("authored-url"), href: safeAuthoredHrefSchema }).passthrough()
1241
+ var queryOutput = z3.discriminatedUnion("kind", [
1242
+ z3.object({ kind: z3.literal("resource"), target: identityOutput, relation: z3.enum(["self", "github-pr-family"]) }).passthrough(),
1243
+ z3.object({ kind: z3.literal("authored-url"), href: safeAuthoredHrefSchema }).passthrough()
607
1244
  ]);
608
- var resolveLookupOutputV2Schema = z2.object({
609
- version: z2.literal(2),
610
- state: z2.enum(["ready", "ambiguous", "unrecognized", "incomplete"]),
611
- options: z2.array(z2.object({ query: queryOutput, label: text(256), inputSpan: spanOutputV2Schema, basis: z2.enum(["supplier", "native", "stored-codec"]), reasons: z2.array(text(128)).max(16) }).passthrough()).max(8),
612
- reasons: z2.array(text(128)).max(16)
1245
+ var resolveLookupOutputV2Schema = z3.object({
1246
+ version: z3.literal(2),
1247
+ state: z3.enum(["ready", "ambiguous", "unrecognized", "incomplete"]),
1248
+ options: z3.array(z3.object({ query: queryOutput, label: text(256), inputSpan: spanOutputV2Schema, basis: z3.enum(["supplier", "native", "stored-codec"]), reasons: z3.array(text(128)).max(16) }).passthrough()).max(8),
1249
+ reasons: z3.array(text(128)).max(16)
613
1250
  }).passthrough();
614
1251
  var crossReferencesV2RpcSchemas = {
615
1252
  crossReferencesV2ListMentions: { input: listMentionsInputV2Schema, output: listMentionsOutputV2Schema },
616
1253
  crossReferencesV2ResolveLookup: { input: resolveLookupInputV2Schema, output: resolveLookupOutputV2Schema }
617
1254
  };
618
- var mentionsChangedV2Schema = z2.object({ version: z2.literal(2), producerPluginId: producer, sourceIdentityDigest: digest, graphRevision: integer(), evidenceRevision: integer().nullable(), affectedIdentityDigests: z2.array(digest).max(512), scopeListClipped: z2.boolean() }).passthrough();
1255
+ var mentionsChangedV2Schema = z3.object({ version: z3.literal(2), producerPluginId: producer, sourceIdentityDigest: digest2, graphRevision: integer2(), evidenceRevision: integer2().nullable(), affectedIdentityDigests: z3.array(digest2).max(512), scopeListClipped: z3.boolean() }).passthrough();
619
1256
  var MENTIONS_V2_CHANNEL = "cross-references-mentions-v2-changed";
620
1257
  // src/lookup.ts
621
1258
  function githubLookup(value) {
@@ -636,7 +1273,6 @@ function githubLookup(value) {
636
1273
  const source = { provider: "github", id: `github.com/${repo}#${n}`, kind };
637
1274
  return { source, query: { kind: "resource", target: recognitionIdentity(source), relation: kind === "pull-request" ? "github-pr-family" : "self" }, label: `${repo}#${n}` };
638
1275
  }
639
-
640
1276
  // src/index.ts
641
1277
  var FORWARD_REFERENCE_CHECK_LIMIT = 10;
642
1278
  function assertInputRecord(value) {
@@ -711,130 +1347,130 @@ var namePattern = /^[a-z][a-z0-9._-]{0,63}$/;
711
1347
  var uuidPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
712
1348
  var digestPattern = /^[0-9a-f]{64}$/;
713
1349
  var safeInteger = (schema) => schema.refine(Number.isSafeInteger, { message: "must be a safe integer" });
714
- var presentationSchema = z3.object({
715
- label: z3.string().max(MAX_PRESENTATION_LABEL_BYTES),
716
- detail: z3.string().max(MAX_PRESENTATION_DETAIL_BYTES).optional(),
717
- url: z3.string().max(MAX_PRESENTATION_URL_BYTES).optional()
1350
+ var presentationSchema = z4.object({
1351
+ label: z4.string().max(MAX_PRESENTATION_LABEL_BYTES),
1352
+ detail: z4.string().max(MAX_PRESENTATION_DETAIL_BYTES).optional(),
1353
+ url: z4.string().max(MAX_PRESENTATION_URL_BYTES).optional()
718
1354
  }).strict().superRefine((value, context) => {
719
1355
  try {
720
1356
  canonicalizeResource({ provider: "test", keys: { resource: "placeholder" }, presentation: value });
721
- } catch (cause) {
722
- context.addIssue({ code: "custom", message: cause instanceof Error ? cause.message : String(cause) });
1357
+ } catch (cause2) {
1358
+ context.addIssue({ code: "custom", message: cause2 instanceof Error ? cause2.message : String(cause2) });
723
1359
  }
724
1360
  });
725
- var resourceSchema = z3.object({
726
- provider: z3.string().max(64).regex(namePattern),
727
- keys: z3.record(z3.string().max(64), z3.string().max(MAX_KEY_VALUE_BYTES)),
1361
+ var resourceSchema = z4.object({
1362
+ provider: z4.string().max(64).regex(namePattern),
1363
+ keys: z4.record(z4.string().max(64), z4.string().max(MAX_KEY_VALUE_BYTES)),
728
1364
  presentation: presentationSchema
729
1365
  }).strict().superRefine((value, context) => {
730
1366
  try {
731
1367
  canonicalizeResource(value);
732
- } catch (cause) {
733
- context.addIssue({ code: "custom", message: cause instanceof Error ? cause.message : String(cause) });
1368
+ } catch (cause2) {
1369
+ context.addIssue({ code: "custom", message: cause2 instanceof Error ? cause2.message : String(cause2) });
734
1370
  }
735
1371
  });
736
- var resourceIdentitySchema = z3.object({
737
- provider: z3.string().max(64).regex(namePattern),
738
- keys: z3.record(z3.string().max(64), z3.string().max(MAX_KEY_VALUE_BYTES))
1372
+ var resourceIdentitySchema = z4.object({
1373
+ provider: z4.string().max(64).regex(namePattern),
1374
+ keys: z4.record(z4.string().max(64), z4.string().max(MAX_KEY_VALUE_BYTES))
739
1375
  }).strict().superRefine((value, context) => {
740
1376
  try {
741
1377
  canonicalizeIdentity(value);
742
- } catch (cause) {
743
- context.addIssue({ code: "custom", message: cause instanceof Error ? cause.message : String(cause) });
1378
+ } catch (cause2) {
1379
+ context.addIssue({ code: "custom", message: cause2 instanceof Error ? cause2.message : String(cause2) });
744
1380
  }
745
1381
  });
746
- var producerPluginIdSchema = z3.string().max(64).regex(namePattern);
747
- var mutationIdSchema = z3.string().max(MAX_MUTATION_ID_BYTES).regex(uuidPattern);
748
- var revisionSchema = safeInteger(z3.number().int());
749
- var applyProjectionInputSchema = z3.object({
750
- protocolVersion: z3.literal(PROTOCOL_VERSION),
1382
+ var producerPluginIdSchema = z4.string().max(64).regex(namePattern);
1383
+ var mutationIdSchema = z4.string().max(MAX_MUTATION_ID_BYTES).regex(uuidPattern);
1384
+ var revisionSchema = safeInteger(z4.number().int());
1385
+ var applyProjectionInputSchema = z4.object({
1386
+ protocolVersion: z4.literal(PROTOCOL_VERSION),
751
1387
  producerPluginId: producerPluginIdSchema,
752
1388
  mutationId: mutationIdSchema,
753
1389
  source: resourceSchema,
754
1390
  revision: revisionSchema.positive(),
755
1391
  expectedRevision: revisionSchema.nonnegative(),
756
- payloadDigest: z3.string().regex(digestPattern),
757
- tombstone: z3.boolean(),
758
- targets: z3.array(resourceSchema).max(MAX_TARGETS)
1392
+ payloadDigest: z4.string().regex(digestPattern),
1393
+ tombstone: z4.boolean(),
1394
+ targets: z4.array(resourceSchema).max(MAX_TARGETS)
759
1395
  }).strict().superRefine((value, context) => {
760
1396
  try {
761
1397
  normalizeProjectionCommand(value);
762
- } catch (cause) {
763
- context.addIssue({ code: "custom", message: cause instanceof Error ? cause.message : String(cause) });
1398
+ } catch (cause2) {
1399
+ context.addIssue({ code: "custom", message: cause2 instanceof Error ? cause2.message : String(cause2) });
764
1400
  }
765
1401
  });
766
- var applyProjectionResponseSchema = z3.object({
767
- outcome: z3.enum(["applied", "duplicate", "equal", "stale", "conflict", "cas-mismatch"]),
1402
+ var applyProjectionResponseSchema = z4.object({
1403
+ outcome: z4.enum(["applied", "duplicate", "equal", "stale", "conflict", "cas-mismatch"]),
768
1404
  currentRevision: revisionSchema.nonnegative(),
769
- currentDigest: z3.string().regex(digestPattern).nullable()
1405
+ currentDigest: z4.string().regex(digestPattern).nullable()
770
1406
  }).strict();
771
- var projectionSchema = z3.object({
1407
+ var projectionSchema = z4.object({
772
1408
  producerPluginId: producerPluginIdSchema,
773
1409
  source: resourceSchema,
774
1410
  revision: revisionSchema.nonnegative(),
775
1411
  mutationId: mutationIdSchema,
776
- payloadDigest: z3.string().regex(digestPattern),
777
- tombstone: z3.boolean(),
778
- targets: z3.array(resourceSchema).max(MAX_TARGETS)
1412
+ payloadDigest: z4.string().regex(digestPattern),
1413
+ tombstone: z4.boolean(),
1414
+ targets: z4.array(resourceSchema).max(MAX_TARGETS)
779
1415
  }).strict();
780
- var getProjectionInputSchema = z3.object({
1416
+ var getProjectionInputSchema = z4.object({
781
1417
  producerPluginId: producerPluginIdSchema,
782
1418
  source: resourceIdentitySchema
783
1419
  }).strict();
784
- var getProjectionOutputSchema = z3.object({ projection: projectionSchema.nullable() }).strict();
785
- var backlinkRowSchema = z3.object({
1420
+ var getProjectionOutputSchema = z4.object({ projection: projectionSchema.nullable() }).strict();
1421
+ var backlinkRowSchema = z4.object({
786
1422
  source: resourceSchema,
787
1423
  producerPluginId: producerPluginIdSchema,
788
1424
  revision: revisionSchema.nonnegative(),
789
1425
  targetPresentation: presentationSchema,
790
- position: z3.number().int().min(0).max(MAX_TARGETS - 1).refine(Number.isSafeInteger),
1426
+ position: z4.number().int().min(0).max(MAX_TARGETS - 1).refine(Number.isSafeInteger),
791
1427
  lastSeenAt: revisionSchema.nonnegative().nullable().optional()
792
1428
  }).strict();
793
- var listBacklinksInputSchema = z3.object({
1429
+ var listBacklinksInputSchema = z4.object({
794
1430
  target: resourceIdentitySchema,
795
- pageSize: z3.number().int().min(1).max(100).refine(Number.isSafeInteger).optional(),
796
- cursor: z3.string().max(4096).optional()
1431
+ pageSize: z4.number().int().min(1).max(100).refine(Number.isSafeInteger).optional(),
1432
+ cursor: z4.string().max(4096).optional()
797
1433
  }).strict();
798
- var listBacklinksOutputSchema = z3.object({
799
- rows: z3.array(backlinkRowSchema).max(100),
1434
+ var listBacklinksOutputSchema = z4.object({
1435
+ rows: z4.array(backlinkRowSchema).max(100),
800
1436
  total: revisionSchema.nonnegative(),
801
- nextCursor: z3.string().max(4096).nullable()
1437
+ nextCursor: z4.string().max(4096).nullable()
802
1438
  }).strict();
803
- var forwardReferenceRowSchema = z3.object({
1439
+ var forwardReferenceRowSchema = z4.object({
804
1440
  target: resourceSchema,
805
1441
  producerPluginId: producerPluginIdSchema,
806
1442
  revision: revisionSchema.nonnegative(),
807
- position: z3.number().int().min(0).max(MAX_TARGETS - 1).refine(Number.isSafeInteger),
1443
+ position: z4.number().int().min(0).max(MAX_TARGETS - 1).refine(Number.isSafeInteger),
808
1444
  lastSeenAt: revisionSchema.nonnegative().nullable().optional()
809
1445
  }).strict();
810
- var listForwardReferencesInputSchema = z3.object({
1446
+ var listForwardReferencesInputSchema = z4.object({
811
1447
  source: resourceIdentitySchema,
812
1448
  producerPluginId: producerPluginIdSchema.optional(),
813
- pageSize: z3.number().int().min(1).max(100).refine(Number.isSafeInteger).optional(),
814
- cursor: z3.string().max(4096).optional()
1449
+ pageSize: z4.number().int().min(1).max(100).refine(Number.isSafeInteger).optional(),
1450
+ cursor: z4.string().max(4096).optional()
815
1451
  }).strict();
816
- var listForwardReferencesOutputSchema = z3.object({
817
- rows: z3.array(forwardReferenceRowSchema).max(100),
1452
+ var listForwardReferencesOutputSchema = z4.object({
1453
+ rows: z4.array(forwardReferenceRowSchema).max(100),
818
1454
  total: revisionSchema.nonnegative(),
819
- nextCursor: z3.string().max(4096).nullable()
1455
+ nextCursor: z4.string().max(4096).nullable()
820
1456
  }).strict();
821
- var checkForwardReferencesInputSchema = z3.object({
1457
+ var checkForwardReferencesInputSchema = z4.object({
822
1458
  source: resourceIdentitySchema,
823
1459
  producerPluginId: producerPluginIdSchema.optional()
824
1460
  }).strict();
825
- var forwardReferenceStatusSchema = z3.object({
826
- url: z3.string().max(MAX_PRESENTATION_URL_BYTES),
827
- status: z3.number().int().min(100).max(599).nullable(),
828
- label: z3.string().min(1).max(128)
1461
+ var forwardReferenceStatusSchema = z4.object({
1462
+ url: z4.string().max(MAX_PRESENTATION_URL_BYTES),
1463
+ status: z4.number().int().min(100).max(599).nullable(),
1464
+ label: z4.string().min(1).max(128)
829
1465
  }).strict();
830
- var checkForwardReferencesOutputSchema = z3.array(forwardReferenceStatusSchema).max(FORWARD_REFERENCE_CHECK_LIMIT);
1466
+ var checkForwardReferencesOutputSchema = z4.array(forwardReferenceStatusSchema).max(FORWARD_REFERENCE_CHECK_LIMIT);
831
1467
  var CROSS_REFERENCES_PLUGIN_ID = "cross-references";
832
1468
  var CROSS_REFERENCES_PROTOCOL = "cross-references";
833
1469
  var LIMITS = Object.freeze({ callMs: 5000, describeMs: 1000, responseBytes: 1024 * 1024 });
834
- var describeInputSchema = z3.null();
835
- var describeOutputSchema = z3.object({
836
- protocol: z3.literal(CROSS_REFERENCES_PROTOCOL),
837
- versions: z3.array(z3.number().int().positive().refine(Number.isSafeInteger)).max(16)
1470
+ var describeInputSchema = z4.null();
1471
+ var describeOutputSchema = z4.object({
1472
+ protocol: z4.literal(CROSS_REFERENCES_PROTOCOL),
1473
+ versions: z4.array(z4.number().int().positive().refine(Number.isSafeInteger)).max(16)
838
1474
  });
839
1475
  var crossReferencesRpcSchemas = {
840
1476
  "crossReferences.describe": { input: describeInputSchema, output: describeOutputSchema },
@@ -844,15 +1480,16 @@ var crossReferencesRpcSchemas = {
844
1480
  listForwardReferences: { input: listForwardReferencesInputSchema, output: listForwardReferencesOutputSchema },
845
1481
  checkForwardReferences: { input: checkForwardReferencesInputSchema, output: checkForwardReferencesOutputSchema }
846
1482
  };
847
- var referenceSnapshotSchema = z3.object({
1483
+ var referenceSnapshotSchema = z4.object({
848
1484
  revision: revisionSchema.nonnegative(),
849
- targets: z3.array(resourceSchema).max(MAX_TARGETS),
850
- status: z3.object({ state: z3.enum(["synced", "pending", "degraded", "blocked"]), error: z3.string().max(4096).nullable() })
1485
+ targets: z4.array(resourceSchema).max(MAX_TARGETS),
1486
+ status: z4.object({ state: z4.enum(["synced", "pending", "degraded", "blocked"]), error: z4.string().max(4096).nullable() })
851
1487
  });
1488
+ var crossReferencesProducerRpcSchemas = createProducerSchemas(applyProjectionInputSchema);
852
1489
 
853
1490
  // src/bb.ts
854
1491
  import { defineRpcContract } from "@get-bb/plugin-sdk";
855
- import { z as z4 } from "zod";
1492
+ import { z as z5 } from "zod";
856
1493
  class CrossReferencesProtocolError extends Error {
857
1494
  code = "incompatible_protocol";
858
1495
  constructor(message) {
@@ -893,7 +1530,7 @@ function createCrossReferencesClient(sdk, targetPluginId = CROSS_REFERENCES_PLUG
893
1530
  }, method === "crossReferences.describe" ? describeMs : callMs);
894
1531
  try {
895
1532
  const value = await Promise.race([
896
- sdk.plugins.callRpc({ pluginId, method, input: JSON.parse(JSON.stringify(parsedInput)), outputSchema: z4.unknown(), signal: controller.signal }),
1533
+ sdk.plugins.callRpc({ pluginId, method, input: JSON.parse(JSON.stringify(parsedInput)), outputSchema: z5.unknown(), signal: controller.signal }),
897
1534
  cancelled
898
1535
  ]);
899
1536
  const json = JSON.stringify(value);
@@ -956,7 +1593,7 @@ function createCrossReferencesV2Client(sdk, targetPluginId = CROSS_REFERENCES_PL
956
1593
  reject(e);
957
1594
  }, method === "crossReferences.describe" ? describeMs : callMs);
958
1595
  try {
959
- const value = await Promise.race([sdk.plugins.callRpc({ pluginId, method, input: JSON.parse(json), outputSchema: z4.unknown(), signal: controller.signal }), cancelled]);
1596
+ const value = await Promise.race([sdk.plugins.callRpc({ pluginId, method, input: JSON.parse(json), outputSchema: z5.unknown(), signal: controller.signal }), cancelled]);
960
1597
  const encoded = JSON.stringify(value);
961
1598
  if (encoded === undefined || utf8ByteLength(encoded) > MENTION_V2_LIMITS.responseBytes)
962
1599
  throw new CrossReferencesProtocolError("V2 response exceeds its canonical JSON byte bound.");
@@ -985,8 +1622,8 @@ function sdkSchema(schema) {
985
1622
  version: 1,
986
1623
  vendor: "bb-cross-references",
987
1624
  jsonSchema: {
988
- input: () => z4.toJSONSchema(schema, { io: "input", unrepresentable: "any" }),
989
- output: () => z4.toJSONSchema(schema, { io: "output", unrepresentable: "any" })
1625
+ input: () => z5.toJSONSchema(schema, { io: "input", unrepresentable: "any" }),
1626
+ output: () => z5.toJSONSchema(schema, { io: "output", unrepresentable: "any" })
990
1627
  },
991
1628
  validate(value) {
992
1629
  const parsed = schema.safeParse(value);
@@ -1001,10 +1638,121 @@ var crossReferencesV2RpcContract = defineRpcContract({
1001
1638
  function registerCrossReferencesV2(bb, handlers) {
1002
1639
  bb.rpc.register(crossReferencesV2RpcContract, handlers);
1003
1640
  }
1641
+ function byteSdkSchema(schema, bytes2) {
1642
+ const base = sdkSchema(schema);
1643
+ return { "~standard": { ...base["~standard"], validate(value) {
1644
+ try {
1645
+ const json = JSON.stringify(value);
1646
+ if (json === undefined || utf8ByteLength(json) > bytes2)
1647
+ return { issues: [{ message: "Protocol byte bound exceeded." }] };
1648
+ } catch {
1649
+ return { issues: [{ message: "Invalid protocol JSON." }] };
1650
+ }
1651
+ return base["~standard"].validate(value);
1652
+ } } };
1653
+ }
1654
+ var ps = crossReferencesProducerRpcSchemas;
1655
+ var ns = briefNavigationRpcSchemas;
1656
+ var crossReferencesProducerRpcContract = defineRpcContract({
1657
+ [PRODUCER_METHODS.describe]: { input: byteSdkSchema(ps[PRODUCER_METHODS.describe].input, BRIEF_LIMITS.statusBytes), output: byteSdkSchema(ps[PRODUCER_METHODS.describe].output, BRIEF_LIMITS.statusBytes) },
1658
+ [PRODUCER_METHODS.getState]: { input: byteSdkSchema(ps[PRODUCER_METHODS.getState].input, BRIEF_LIMITS.statusBytes), output: byteSdkSchema(ps[PRODUCER_METHODS.getState].output, BRIEF_LIMITS.responseBytes) },
1659
+ [PRODUCER_METHODS.apply]: { input: byteSdkSchema(ps[PRODUCER_METHODS.apply].input, BRIEF_LIMITS.inputBytes), output: byteSdkSchema(ps[PRODUCER_METHODS.apply].output, BRIEF_LIMITS.responseBytes) },
1660
+ [PRODUCER_METHODS.reportStatus]: { input: byteSdkSchema(ps[PRODUCER_METHODS.reportStatus].input, BRIEF_LIMITS.statusBytes), output: byteSdkSchema(ps[PRODUCER_METHODS.reportStatus].output, BRIEF_LIMITS.responseBytes) }
1661
+ });
1662
+ function registerCrossReferencesProducer(bb, handlers) {
1663
+ bb.rpc.register(crossReferencesProducerRpcContract, handlers);
1664
+ }
1665
+ var briefNavigationRpcContract = defineRpcContract({
1666
+ [BRIEF_NAVIGATION_METHODS.describe]: { input: byteSdkSchema(ns[BRIEF_NAVIGATION_METHODS.describe].input, 8192), output: byteSdkSchema(ns[BRIEF_NAVIGATION_METHODS.describe].output, 16384) },
1667
+ [BRIEF_NAVIGATION_METHODS.resolve]: { input: byteSdkSchema(ns[BRIEF_NAVIGATION_METHODS.resolve].input, 8192), output: byteSdkSchema(ns[BRIEF_NAVIGATION_METHODS.resolve].output, 16384) }
1668
+ });
1669
+ function registerBriefNavigation(bb, handlers) {
1670
+ bb.rpc.register(briefNavigationRpcContract, handlers);
1671
+ }
1672
+ function boundedFamilyCall(sdk, pluginId, options = {}) {
1673
+ validateProducerPluginId(pluginId);
1674
+ const callMs = budget(options.callMs, 5000), describeMs = budget(options.describeMs, 1000);
1675
+ return async function call(method, input, inputSchema, outputSchema, inputBytes, outputBytes, signal) {
1676
+ const before = JSON.stringify(input);
1677
+ if (before === undefined || utf8ByteLength(before) > inputBytes)
1678
+ throw new CrossReferencesProtocolError("Protocol input exceeds its byte bound.");
1679
+ const parsed = inputSchema.parse(input);
1680
+ signal?.throwIfAborted();
1681
+ const controller = new AbortController;
1682
+ let reject;
1683
+ const cancelled = new Promise((_, r) => {
1684
+ reject = r;
1685
+ });
1686
+ const abort = () => {
1687
+ const e = signal?.reason ?? new DOMException("Request aborted", "AbortError");
1688
+ controller.abort(e);
1689
+ reject(e);
1690
+ };
1691
+ signal?.addEventListener("abort", abort, { once: true });
1692
+ const timer = setTimeout(() => {
1693
+ const e = Object.assign(new Error("Protocol call timed out."), { name: "TimeoutError", code: "timeout" });
1694
+ controller.abort(e);
1695
+ reject(e);
1696
+ }, method.endsWith(".describe") ? describeMs : callMs);
1697
+ try {
1698
+ const value = await Promise.race([sdk.plugins.callRpc({ pluginId, method, input: JSON.parse(JSON.stringify(parsed)), outputSchema: z5.unknown(), signal: controller.signal }), cancelled]);
1699
+ const json = JSON.stringify(value);
1700
+ if (json === undefined || utf8ByteLength(json) > outputBytes)
1701
+ throw new CrossReferencesProtocolError("Protocol output exceeds its byte bound.");
1702
+ return outputSchema.parse(value);
1703
+ } finally {
1704
+ clearTimeout(timer);
1705
+ signal?.removeEventListener("abort", abort);
1706
+ controller.abort();
1707
+ }
1708
+ };
1709
+ }
1710
+ function createCrossReferencesProducerClient(sdk, pluginId = CROSS_REFERENCES_PLUGIN_ID, options = {}) {
1711
+ const call = boundedFamilyCall(sdk, pluginId, options);
1712
+ return {
1713
+ pluginId,
1714
+ async describe(signal) {
1715
+ const d = await call(PRODUCER_METHODS.describe, null, ps[PRODUCER_METHODS.describe].input, ps[PRODUCER_METHODS.describe].output, 16384, 16384, signal);
1716
+ if (!d.versions.includes(1))
1717
+ throw new CrossReferencesProtocolError("Producer protocol unavailable.");
1718
+ return d;
1719
+ },
1720
+ getState: (input, signal) => call(PRODUCER_METHODS.getState, input, ps[PRODUCER_METHODS.getState].input, ps[PRODUCER_METHODS.getState].output, 16384, 1048576, signal),
1721
+ apply(input, signal) {
1722
+ const limits = briefApplyLimitCodes(input);
1723
+ if (limits.length)
1724
+ return Promise.reject(new BriefAdmissionError("over-limit", limits));
1725
+ validateBriefCommand(input.projection, input.evidence, input.evidenceDigest);
1726
+ return call(PRODUCER_METHODS.apply, input, ps[PRODUCER_METHODS.apply].input, ps[PRODUCER_METHODS.apply].output, 1048576, 1048576, signal);
1727
+ },
1728
+ reportStatus: (input, signal) => call(PRODUCER_METHODS.reportStatus, input, ps[PRODUCER_METHODS.reportStatus].input, ps[PRODUCER_METHODS.reportStatus].output, 16384, 1048576, signal)
1729
+ };
1730
+ }
1731
+ function createBriefNavigationClient(sdk, options = {}) {
1732
+ const call = boundedFamilyCall(sdk, "thread-brief", options);
1733
+ return {
1734
+ async describe(signal) {
1735
+ const d = await call(BRIEF_NAVIGATION_METHODS.describe, null, ns[BRIEF_NAVIGATION_METHODS.describe].input, ns[BRIEF_NAVIGATION_METHODS.describe].output, 8192, 16384, signal);
1736
+ if (!d.versions.includes(1))
1737
+ throw new CrossReferencesProtocolError("Brief navigation unavailable.");
1738
+ return d;
1739
+ },
1740
+ async resolve(input, signal) {
1741
+ const value = await call(BRIEF_NAVIGATION_METHODS.resolve, input, ns[BRIEF_NAVIGATION_METHODS.resolve].input, ns[BRIEF_NAVIGATION_METHODS.resolve].output, 8192, 16384, signal);
1742
+ return validateBriefNavigationResultV1(input, value);
1743
+ }
1744
+ };
1745
+ }
1004
1746
  export {
1005
1747
  registerCrossReferencesV2,
1748
+ registerCrossReferencesProducer,
1749
+ registerBriefNavigation,
1006
1750
  crossReferencesV2RpcContract,
1751
+ crossReferencesProducerRpcContract,
1007
1752
  createCrossReferencesV2Client,
1753
+ createCrossReferencesProducerClient,
1008
1754
  createCrossReferencesClient,
1755
+ createBriefNavigationClient,
1756
+ briefNavigationRpcContract,
1009
1757
  CrossReferencesProtocolError
1010
1758
  };