@patronage/software-factory 1.0.0-alpha.35 → 1.0.0-alpha.37

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.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { Command } from "commander";
2
- import { z } from "zod";
3
2
  import { existsSync, readFileSync, rmSync } from "node:fs";
3
+ import { z } from "zod";
4
4
  import { PreviewProofRegistration } from "@patronage/factory-ci";
5
+ import { JsonValue, Questions, SystemOneRequest, choice, noul, score } from "@typesafe-ai/sdk";
5
6
 
6
7
  //#region src/review-rungs.d.ts
7
8
  declare const EVIDENCE_REVIEW_RUNGS: readonly ["independent-model", "oracle", "human"];
@@ -947,10 +948,18 @@ declare const blockedReasonSchema: z.ZodObject<{
947
948
  type BlockedReason = z.infer<typeof blockedReasonSchema>;
948
949
  //#endregion
949
950
  //#region src/arm-auto-merge.d.ts
951
+ /**
952
+ * How GitHub merges the candidate. `pr:ready` chooses `merge` for a
953
+ * recognized faithful catch-up merge (ADR 0028), because a squash drops the
954
+ * second parent and the target loses the merged base as an ancestor (#829).
955
+ * Every other candidate is squashed.
956
+ */
957
+ type AutoMergeMethod = "merge" | "squash";
950
958
  interface ArmAutoMergeInput {
951
959
  cwd: string;
952
960
  /** The validated PR head this arming is a compare-and-set against. */
953
961
  headSha: string;
962
+ mergeMethod: AutoMergeMethod;
954
963
  owner: string;
955
964
  pr: number;
956
965
  repo: string;
@@ -1668,9 +1677,9 @@ declare const mergeFreezeStateSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1668
1677
  verification: z.ZodOptional<z.ZodObject<{
1669
1678
  jobs: z.ZodRecord<z.ZodString, z.ZodEnum<{
1670
1679
  success: "success";
1680
+ skipped: "skipped";
1671
1681
  failure: "failure";
1672
1682
  cancelled: "cancelled";
1673
- skipped: "skipped";
1674
1683
  }>>;
1675
1684
  runAttempt: z.ZodNumber;
1676
1685
  runId: z.ZodNumber;
@@ -1687,9 +1696,9 @@ declare const mergeFreezeStateSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1687
1696
  verification: z.ZodOptional<z.ZodObject<{
1688
1697
  jobs: z.ZodRecord<z.ZodString, z.ZodEnum<{
1689
1698
  success: "success";
1699
+ skipped: "skipped";
1690
1700
  failure: "failure";
1691
1701
  cancelled: "cancelled";
1692
- skipped: "skipped";
1693
1702
  }>>;
1694
1703
  runAttempt: z.ZodNumber;
1695
1704
  runId: z.ZodNumber;
@@ -1948,8 +1957,8 @@ declare const managedReadinessLedgerSchema: z.ZodObject<{
1948
1957
  reviewedHeadSha: z.ZodOptional<z.ZodString>;
1949
1958
  reviewedPatchId: z.ZodOptional<z.ZodString>;
1950
1959
  status: z.ZodEnum<{
1951
- stale: "stale";
1952
1960
  "not-required": "not-required";
1961
+ stale: "stale";
1953
1962
  blocked: "blocked";
1954
1963
  current: "current";
1955
1964
  missing: "missing";
@@ -1960,8 +1969,8 @@ declare const managedReadinessLedgerSchema: z.ZodObject<{
1960
1969
  reviewedHeadSha: z.ZodOptional<z.ZodString>;
1961
1970
  reviewedPatchId: z.ZodOptional<z.ZodString>;
1962
1971
  status: z.ZodEnum<{
1963
- stale: "stale";
1964
1972
  "not-required": "not-required";
1973
+ stale: "stale";
1965
1974
  blocked: "blocked";
1966
1975
  current: "current";
1967
1976
  missing: "missing";
@@ -2610,11 +2619,13 @@ interface PrReadyProof {
2610
2619
  schemaVersion: 3;
2611
2620
  /**
2612
2621
  * What GitHub actually did when this run armed native auto-merge (#477).
2613
- * Present exactly when a ready wave authorizes machine merge and arming ran;
2614
- * read back from the PR rather than inferred from the invocation, because `gh pr merge
2615
- * --auto` arms, merges, or does nothing with the same exit code and the same
2616
- * empty output. `not-armed` means the candidate is admitted but nothing will
2617
- * merge it, and `followUp` carries the re-dispatch.
2622
+ * Present exactly when a ready run called the arming module (#1299): not
2623
+ * for an `autoMerge: false` wave, and not when a notice names why the run
2624
+ * did not arm. Read back from the PR rather than inferred from the
2625
+ * invocation, because `gh pr merge --auto` arms, merges, or does nothing
2626
+ * with the same exit code and the same empty output. `not-armed` means the
2627
+ * candidate is admitted but nothing will merge it, and `followUp` carries
2628
+ * the re-dispatch.
2618
2629
  */
2619
2630
  arming?: {
2620
2631
  detail?: string;
@@ -2686,13 +2697,61 @@ interface PrReadyProof {
2686
2697
  */
2687
2698
  waivedDemands?: WaivedDemand[];
2688
2699
  }
2700
+ /** An issue's sub-issue parent, as the membership rule reads it (#1299). */
2701
+ interface IssueParent {
2702
+ labels: string[];
2703
+ number: number;
2704
+ state: string;
2705
+ }
2706
+ /** What `pr:ready` reads about one pull request before it arms (#1299). */
2707
+ interface PullRequestArmingFacts {
2708
+ /** GitHub's per-repository "Allow auto-merge" setting. */
2709
+ autoMergeAllowed: boolean;
2710
+ /**
2711
+ * GitHub's closing references for the pull request to issues in its own
2712
+ * repository, with their parents.
2713
+ */
2714
+ closingIssues: {
2715
+ number: number;
2716
+ parent: IssueParent | null;
2717
+ }[];
2718
+ /**
2719
+ * GitHub has more closing references than the one page `pr:ready` reads,
2720
+ * so `closingIssues` is not the whole set.
2721
+ */
2722
+ closingIssuesIncomplete: boolean;
2723
+ labels: string[];
2724
+ }
2725
+ /**
2726
+ * The GitHub reads behind the reasons not to arm an admitted candidate
2727
+ * (#1299). A read throws when GitHub cannot answer; `pr:ready` then does not
2728
+ * arm, and its notice says which read failed.
2729
+ */
2730
+ interface ArmingPolicyReads {
2731
+ /** One issue's sub-issue parent, or `null` when it has none. */
2732
+ readIssueParent: (input: {
2733
+ issue: number;
2734
+ owner: string;
2735
+ repo: string;
2736
+ }) => IssueParent | null;
2737
+ readPullRequest: (input: {
2738
+ owner: string;
2739
+ pr: number;
2740
+ repo: string;
2741
+ }) => PullRequestArmingFacts;
2742
+ }
2689
2743
  interface PrReadyDependencies {
2690
2744
  /**
2691
- * Arms GitHub native auto-merge only for a passing boundary wave that
2692
- * authorizes machine merge (#477). Defaults to the real `gh pr merge --auto`
2693
- * call plus the read-back that says what actually happened.
2745
+ * Arms GitHub native auto-merge for an admitted candidate (#477, #1299).
2746
+ * Defaults to the real `gh pr merge --auto` call plus the read-back that
2747
+ * says what actually happened.
2694
2748
  */
2695
2749
  armAutoMerge?: (input: ArmAutoMergeInput) => ArmAutoMergeOutcome;
2750
+ /**
2751
+ * The GitHub reads behind the reasons not to arm (#1299). Defaults to the
2752
+ * real GraphQL reads.
2753
+ */
2754
+ armingPolicy?: ArmingPolicyReads;
2696
2755
  /**
2697
2756
  * Reads the authoritative base review policy (#922): the profile committed at
2698
2757
  * the live tip of the PR's own base ref. Defaults to the real GitHub reads,
@@ -2933,8 +2992,8 @@ declare const loadEvidenceEnvelopes: (cwd: string) => LoadedEvidenceEnvelope[];
2933
2992
  //#region src/review-proof-applicability.d.ts
2934
2993
  declare const REVIEW_STATUS_VALUES: readonly ["not-required", "current", "stale", "missing", "blocked"];
2935
2994
  declare const reviewStatusSchema: z.ZodEnum<{
2936
- stale: "stale";
2937
2995
  "not-required": "not-required";
2996
+ stale: "stale";
2938
2997
  blocked: "blocked";
2939
2998
  current: "current";
2940
2999
  missing: "missing";
@@ -3444,11 +3503,12 @@ interface PrPublishHandoff {
3444
3503
  routeOwnedRepairs: ReadinessRepair[];
3445
3504
  /**
3446
3505
  * Whether the merge is actually on GitHub's schedule (#477, #515 review).
3447
- * An admitted candidate is not a handed-off one: `pr:ready` arms only when a
3448
- * boundary wave authorized it, and the arming can fail to take effect. A
3506
+ * An admitted candidate is not a handed-off one: `pr:ready` does not arm
3507
+ * when the repository does not allow auto-merge, the pull request carries
3508
+ * `factory:hold`, a boundary wave keeps it attended, or it is an epic member
3509
+ * run without `--epic` (#1299), and the arming can fail to take effect. A
3449
3510
  * readiness status of `ready` says the candidate passed, never that anything
3450
- * will merge it — only an auto-merge-authorized boundary wave can schedule
3451
- * one — so publish reads this before claiming nothing is owed.
3511
+ * will merge it, so publish reads this before claiming nothing is owed.
3452
3512
  */
3453
3513
  scheduled: boolean;
3454
3514
  status: PrReadyProof["status"];
@@ -3715,18 +3775,18 @@ declare const LegacyWorkerCloseoutStatusTraceEventSchema: z.ZodObject<{
3715
3775
  threadId: z.ZodOptional<z.ZodString>;
3716
3776
  workerId: z.ZodOptional<z.ZodString>;
3717
3777
  archiveStatus: z.ZodOptional<z.ZodEnum<{
3718
- skipped: "skipped";
3719
3778
  unavailable: "unavailable";
3720
3779
  archived: "archived";
3780
+ skipped: "skipped";
3721
3781
  "not-applicable": "not-applicable";
3722
3782
  pending: "pending";
3723
3783
  }>>;
3724
3784
  closeoutReason: z.ZodOptional<z.ZodString>;
3725
3785
  eventType: z.ZodLiteral<"worker-closeout-lessons">;
3726
3786
  lessonStatus: z.ZodOptional<z.ZodEnum<{
3727
- skipped: "skipped";
3728
3787
  captured: "captured";
3729
3788
  unavailable: "unavailable";
3789
+ skipped: "skipped";
3730
3790
  }>>;
3731
3791
  lessonSummary: z.ZodOptional<z.ZodString>;
3732
3792
  typeVersion: z.ZodLiteral<2>;
@@ -4113,18 +4173,18 @@ declare const FACTORY_TRACE_EVENT_DEFINITIONS: readonly [DefinedTraceEvent<"revi
4113
4173
  threadId: z.ZodOptional<z.ZodString>;
4114
4174
  workerId: z.ZodOptional<z.ZodString>;
4115
4175
  archiveStatus: z.ZodOptional<z.ZodEnum<{
4116
- skipped: "skipped";
4117
4176
  unavailable: "unavailable";
4118
4177
  archived: "archived";
4178
+ skipped: "skipped";
4119
4179
  "not-applicable": "not-applicable";
4120
4180
  pending: "pending";
4121
4181
  }>>;
4122
4182
  closeoutReason: z.ZodOptional<z.ZodString>;
4123
4183
  eventType: z.ZodLiteral<"worker-closeout-lessons">;
4124
4184
  lessonStatus: z.ZodOptional<z.ZodEnum<{
4125
- skipped: "skipped";
4126
4185
  captured: "captured";
4127
4186
  unavailable: "unavailable";
4187
+ skipped: "skipped";
4128
4188
  }>>;
4129
4189
  lessonSummary: z.ZodOptional<z.ZodString>;
4130
4190
  typeVersion: z.ZodLiteral<2>;
@@ -4154,17 +4214,17 @@ declare const FACTORY_TRACE_EVENT_DEFINITIONS: readonly [DefinedTraceEvent<"revi
4154
4214
  }, z.core.$strict>], "lessonStatus">;
4155
4215
  readonly 2: z.ZodObject<{
4156
4216
  archiveStatus: z.ZodOptional<z.ZodEnum<{
4157
- skipped: "skipped";
4158
4217
  unavailable: "unavailable";
4159
4218
  archived: "archived";
4219
+ skipped: "skipped";
4160
4220
  "not-applicable": "not-applicable";
4161
4221
  pending: "pending";
4162
4222
  }>>;
4163
4223
  closeoutReason: z.ZodOptional<z.ZodString>;
4164
4224
  lessonStatus: z.ZodOptional<z.ZodEnum<{
4165
- skipped: "skipped";
4166
4225
  captured: "captured";
4167
4226
  unavailable: "unavailable";
4227
+ skipped: "skipped";
4168
4228
  }>>;
4169
4229
  lessonSummary: z.ZodOptional<z.ZodString>;
4170
4230
  observedAt: z.ZodString;
@@ -4823,11 +4883,125 @@ interface EvaluationInput {
4823
4883
  waivers?: DemandWaiver[];
4824
4884
  }
4825
4885
  declare const evaluateReadiness: (input: EvaluationInput) => {
4886
+ humanBlockingReasons: string[];
4887
+ ledger: {
4888
+ baseSha: string;
4889
+ blockingReasons: string[];
4890
+ classification: "docs/process-only" | "trivial" | "non-trivial";
4891
+ github: {
4892
+ draft: boolean;
4893
+ mergeStateStatus: string;
4894
+ mergeable: string;
4895
+ requiredChecks: "unknown" | "pending" | "passed" | "failed" | "none";
4896
+ unresolvedReviewThreads: number;
4897
+ reviewDecision?: string | null | undefined;
4898
+ };
4899
+ headSha: string;
4900
+ patchId: string;
4901
+ pr: number;
4902
+ repairs: {
4903
+ action: string;
4904
+ code: "undraft-pr" | "await-post-undraft-checks";
4905
+ command: string;
4906
+ }[];
4907
+ reviews: {
4908
+ correctness: {
4909
+ required: boolean;
4910
+ status: "not-required" | "stale" | "blocked" | "current" | "missing";
4911
+ reviewedHeadSha?: string | undefined;
4912
+ reviewedPatchId?: string | undefined;
4913
+ };
4914
+ security?: {
4915
+ required: boolean;
4916
+ status: "not-required" | "stale" | "blocked" | "current" | "missing";
4917
+ reviewedHeadSha?: string | undefined;
4918
+ reviewedPatchId?: string | undefined;
4919
+ } | undefined;
4920
+ };
4921
+ schemaVersion: 2;
4922
+ verification: {
4923
+ command: "patronage-factory pr:verify";
4924
+ prVerify: "missing";
4925
+ } | {
4926
+ command: "patronage-factory pr:verify";
4927
+ prVerify: "stale";
4928
+ verifiedHeadSha: string;
4929
+ } | {
4930
+ command: "patronage-factory pr:verify";
4931
+ prVerify: "passed-via-head";
4932
+ verifiedHeadSha: string;
4933
+ } | {
4934
+ command: "patronage-factory pr:verify";
4935
+ docsOnlyVerifiedHeadSha: string;
4936
+ prVerify: "docs-only-delta";
4937
+ verifiedHeadSha?: string | undefined;
4938
+ } | {
4939
+ command: "patronage-factory pr:verify";
4940
+ prVerify: "trivial-delta";
4941
+ trivialVerifiedHeadSha: string;
4942
+ verifiedHeadSha?: string | undefined;
4943
+ };
4944
+ externalChecks?: {
4945
+ checkType: "review" | "verify";
4946
+ name: string;
4947
+ scopeReason: string;
4948
+ status: "satisfied" | "unmet" | "out-of-scope";
4949
+ reason?: string | undefined;
4950
+ scope?: {
4951
+ classifications: ("docs/process-only" | "trivial" | "non-trivial")[];
4952
+ } | undefined;
4953
+ }[] | undefined;
4954
+ mergeBaseSha?: string | undefined;
4955
+ reviewCycleState?: {
4956
+ autoBlockingFindings: number;
4957
+ countsBySeverity: {
4958
+ critical: number;
4959
+ high: number;
4960
+ low: number;
4961
+ medium: number;
4962
+ unknown: number;
4963
+ };
4964
+ nonBlockingFindings: number;
4965
+ openFindings: number;
4966
+ windowExhausted: boolean;
4967
+ highestBlockingSeverity?: "unknown" | "critical" | "high" | "low" | "medium" | undefined;
4968
+ highestOpenSeverity?: "unknown" | "critical" | "high" | "low" | "medium" | undefined;
4969
+ maxReviewCycles?: number | undefined;
4970
+ reviewCycle?: number | undefined;
4971
+ staleRepeatFindings?: number | undefined;
4972
+ } | undefined;
4973
+ reviewLadder?: {
4974
+ cycleCounts: {
4975
+ gate: number;
4976
+ interior: number;
4977
+ };
4978
+ nextAction: "run-interior-cycle" | "advance-to-gate" | "run-gate-cycle" | "accept-nonblocking-findings" | "escalate-to-triage" | "ready-for-human";
4979
+ stage: "interior" | "gate" | "interior-complete";
4980
+ forcedTransition?: "gate-cap-exhausted" | "interior-cap-reached" | undefined;
4981
+ } | undefined;
4982
+ reviewRuns?: PrReviewResult[] | undefined;
4983
+ reviewTerminalState?: "blocked" | "accepted-with-findings" | "clean" | undefined;
4984
+ };
4985
+ /**
4986
+ * Facts a reader needs that are not refusals (#477): the settle-window
4987
+ * arming notice, and every waived demand rendered so it can never read as
4988
+ * a met one.
4989
+ */
4990
+ notices: string[];
4991
+ repairs: {
4992
+ action: string;
4993
+ code: "undraft-pr" | "await-post-undraft-checks";
4994
+ command: string;
4995
+ }[];
4996
+ status: ReadinessStatus; /** Demands that were in force, were NOT met, and the operator waived. */
4997
+ waivedDemands: WaivedDemand[];
4998
+ catchUpRecognition: CatchUpRecognition;
4826
4999
  blockedReasons: {
4827
5000
  code: string;
4828
5001
  detail: string;
4829
5002
  }[];
4830
5003
  blockingReasons: string[];
5004
+ } | {
4831
5005
  humanBlockingReasons: string[];
4832
5006
  ledger: {
4833
5007
  baseSha: string;
@@ -4852,13 +5026,13 @@ declare const evaluateReadiness: (input: EvaluationInput) => {
4852
5026
  reviews: {
4853
5027
  correctness: {
4854
5028
  required: boolean;
4855
- status: "stale" | "not-required" | "blocked" | "current" | "missing";
5029
+ status: "not-required" | "stale" | "blocked" | "current" | "missing";
4856
5030
  reviewedHeadSha?: string | undefined;
4857
5031
  reviewedPatchId?: string | undefined;
4858
5032
  };
4859
5033
  security?: {
4860
5034
  required: boolean;
4861
- status: "stale" | "not-required" | "blocked" | "current" | "missing";
5035
+ status: "not-required" | "stale" | "blocked" | "current" | "missing";
4862
5036
  reviewedHeadSha?: string | undefined;
4863
5037
  reviewedPatchId?: string | undefined;
4864
5038
  } | undefined;
@@ -4940,6 +5114,12 @@ declare const evaluateReadiness: (input: EvaluationInput) => {
4940
5114
  }[];
4941
5115
  status: ReadinessStatus; /** Demands that were in force, were NOT met, and the operator waived. */
4942
5116
  waivedDemands: WaivedDemand[];
5117
+ catchUpRecognition?: undefined;
5118
+ blockedReasons: {
5119
+ code: string;
5120
+ detail: string;
5121
+ }[];
5122
+ blockingReasons: string[];
4943
5123
  };
4944
5124
  //#endregion
4945
5125
  //#region src/evidence-emit.d.ts
@@ -5334,6 +5514,275 @@ declare function assertWorkerCheckoutAllowed({
5334
5514
  probe?: CheckoutDirsProbe;
5335
5515
  }): void;
5336
5516
  //#endregion
5517
+ //#region src/jev/schema.d.ts
5518
+ /** The request body this package sends. No `model` field, ever: HQ names it. */
5519
+ type JevRequestBody = Pick<SystemOneRequest, "state" | "questions">;
5520
+ /**
5521
+ * One answer, discriminated exactly as Jev discriminates it.
5522
+ *
5523
+ * Every member is a *stripping* object: an unknown key inside one answer is
5524
+ * dropped, not an error. Erroring would let a single surprising field sink a
5525
+ * whole response, and keeping it would put an upstream-named field into a
5526
+ * record. Dropping is the only behavior that is both safe and non-destructive.
5527
+ */
5528
+ declare const jevAnswerSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
5529
+ noul: z.ZodNumber;
5530
+ type: z.ZodLiteral<"noul">;
5531
+ }, z.core.$strip>, z.ZodObject<{
5532
+ choice: z.ZodString;
5533
+ confidence: z.ZodNumber;
5534
+ probabilities: z.ZodRecord<z.ZodString, z.ZodNumber>;
5535
+ type: z.ZodLiteral<"choice">;
5536
+ }, z.core.$strip>, z.ZodObject<{
5537
+ confidence: z.ZodNumber;
5538
+ probabilities: z.ZodRecord<z.ZodString, z.ZodNumber>;
5539
+ score: z.ZodNumber;
5540
+ type: z.ZodLiteral<"score">;
5541
+ }, z.core.$strip>], "type">;
5542
+ type JevAnswer = z.infer<typeof jevAnswerSchema>;
5543
+ interface JevUsage {
5544
+ input_tokens?: number;
5545
+ output_tokens?: number;
5546
+ }
5547
+ interface JevResponse {
5548
+ answers: Record<string, JevAnswer>;
5549
+ /** The model HQ ran, or `unknown` when what it returned is not an id. */
5550
+ model: string;
5551
+ usage?: JevUsage;
5552
+ }
5553
+ /** What a report says when HQ names its model in something other than an id. */
5554
+ declare const UNKNOWN_MODEL = "unknown";
5555
+ /**
5556
+ * A question set keyed by the names its answers come back under. Re-stated as a
5557
+ * value type so adapters can build one incrementally without importing the
5558
+ * SDK.
5559
+ */
5560
+ type JevQuestions = Questions;
5561
+ type JevJsonValue = JsonValue;
5562
+ //#endregion
5563
+ //#region src/jev/cache.d.ts
5564
+ /**
5565
+ * The request-hash cache: the same request bytes against the same endpoint
5566
+ * answer from disk instead of from HQ.
5567
+ *
5568
+ * The key is the endpoint plus the exact serialized request, and nothing else.
5569
+ * That is the whole design: a changed snippet, a reworded question, a
5570
+ * different reference file and a different HQ all move the bytes, so they all
5571
+ * move the key. There is no key schema to keep in step with the request
5572
+ * builder, and no way to grow one that forgets a field.
5573
+ *
5574
+ * It lives under `node_modules/.cache`, which is disposable by convention and
5575
+ * already ignored everywhere — a Jev answer is a session diagnostic (ADR
5576
+ * 0034), not a build input and not evidence.
5577
+ *
5578
+ * An entry that exists but cannot be used — unreadable, not JSON, not Jev's
5579
+ * response shape — is an error, not a miss, and so is a write that fails. Only
5580
+ * `ENOENT` means "nothing is stored". Repairing any of the others silently and
5581
+ * calling HQ anyway would be a second behavior for one failure, and a paid
5582
+ * one; the run names the entry and its cause, and the operator removes it.
5583
+ */
5584
+ /** A cache entry that could not be used, or could not be written. */
5585
+ declare class JevCacheError extends Error {
5586
+ readonly path: string;
5587
+ constructor(entryPath: string, detail: string);
5588
+ }
5589
+ /** Where a repository's Jev answers are kept. */
5590
+ declare const defaultJevCacheDirectory: (cwd: string) => string;
5591
+ interface JevCache {
5592
+ /** The entry key for these request bytes: endpoint plus the bytes, hashed. */
5593
+ keyFor: (serialized: string) => string;
5594
+ /** The stored answer, or `undefined` when nothing is stored. */
5595
+ read: (serialized: string) => JevResponse | undefined;
5596
+ write: (serialized: string, response: JevResponse) => void;
5597
+ }
5598
+ interface OpenJevCacheInput {
5599
+ /** Defaults to `node_modules/.cache/patronage-jev` under `cwd`. */
5600
+ directory?: string;
5601
+ /** The HQ Jev endpoint these answers came from. Part of every key. */
5602
+ endpoint: string;
5603
+ }
5604
+ /**
5605
+ * Opens the cache, creating its directory now so a directory that cannot be
5606
+ * written fails here — at the one place that names it — rather than midway
5607
+ * through a run as an unexplained request failure.
5608
+ */
5609
+ declare const openJevCache: ({
5610
+ directory,
5611
+ endpoint
5612
+ }: OpenJevCacheInput) => JevCache;
5613
+ //#endregion
5614
+ //#region src/jev/client.d.ts
5615
+ /** Sends one prepared packet and returns Jev's body, plus the model HQ ran. */
5616
+ type JevEvaluate = (serializedBody: string) => Promise<JevResponse>;
5617
+ /**
5618
+ * Either a reachable HQ Jev route, or the one sentence saying why there is
5619
+ * none. A run takes this union rather than a bare `evaluate`, so "there are no
5620
+ * credentials" arrives at the caller in the same shape as "HQ refused": one
5621
+ * typed unavailable result naming its cause, never a throw and never a
5622
+ * silently skipped run.
5623
+ */
5624
+ type JevGateway = {
5625
+ evaluate: JevEvaluate;
5626
+ endpoint: string;
5627
+ status: "ready";
5628
+ } /** No call is possible. Every match is unavailable with this reason. */ | {
5629
+ reason: string;
5630
+ status: "unavailable";
5631
+ };
5632
+ /**
5633
+ * An upstream refusal, carried with the code HQ passed through rather than
5634
+ * flattened into prose. `max_tokens_exceeded` is the one a caller acts on: it
5635
+ * means the packet was too large despite the local budget.
5636
+ */
5637
+ declare class JevRequestError extends Error {
5638
+ readonly code: string | undefined;
5639
+ readonly httpStatus: number;
5640
+ constructor(httpStatus: number, code: string | undefined, message: string);
5641
+ }
5642
+ interface ResolveJevGatewayInput {
5643
+ env: NodeJS.ProcessEnv;
5644
+ fetchImpl?: typeof fetch;
5645
+ }
5646
+ /**
5647
+ * Resolves the gateway, or says why there isn't one. Every `unavailable`
5648
+ * reason is an operator-facing sentence naming a remedy that applies to this
5649
+ * command, and none of them can carry a credential: nothing here reads a
5650
+ * resolved value into a message.
5651
+ *
5652
+ * The order is the policy. The origin is checked against HQ ingest's protocol
5653
+ * rule and the operator's `hqAllowedOrigins` first, and only an authorized
5654
+ * origin gets as far as reading credentials. An unauthorized origin never sees
5655
+ * a request.
5656
+ */
5657
+ declare const resolveJevGateway: ({
5658
+ env,
5659
+ fetchImpl
5660
+ }: ResolveJevGatewayInput) => Promise<JevGateway>;
5661
+ //#endregion
5662
+ //#region src/jev/request.d.ts
5663
+ interface JevMatch {
5664
+ /**
5665
+ * Stable across splitting. Question names must already namespace it, so
5666
+ * moving a match into a later split never rewrites a question or an answer
5667
+ * name.
5668
+ */
5669
+ key: string;
5670
+ /** Answer-name-keyed questions about this match. */
5671
+ questions: JevQuestions;
5672
+ /** Match-local state, published at `matches.<key>` of the request. */
5673
+ state: JevJsonValue;
5674
+ }
5675
+ interface JevFile {
5676
+ matches: readonly JevMatch[];
5677
+ /** Repository-relative path. Identity of the shared state, and sent with it. */
5678
+ path: string;
5679
+ /** State every match in this file is read against, sent once per request. */
5680
+ shared: JevJsonValue;
5681
+ }
5682
+ interface JevRequest {
5683
+ /** The parsed body, for a caller that records a request without sending it. */
5684
+ body: JevRequestBody;
5685
+ estimatedTokens: number;
5686
+ /** SHA-256 of `serialized` — the exact bytes that would be sent. */
5687
+ hash: string;
5688
+ matchKeys: string[];
5689
+ /** The file this request asks about. */
5690
+ path: string;
5691
+ /** The bytes to POST. Serialized once so the hash cannot drift from them. */
5692
+ serialized: string;
5693
+ }
5694
+ interface JevUnavailableMatch {
5695
+ key: string;
5696
+ reason: string;
5697
+ }
5698
+ interface JevRequestPlan {
5699
+ requests: JevRequest[];
5700
+ unavailable: JevUnavailableMatch[];
5701
+ }
5702
+ interface BuildJevRequestsInput {
5703
+ /** Per-request ceiling override, in tokens. Defaults to the budget above. */
5704
+ budgetTokens?: number;
5705
+ files: readonly JevFile[];
5706
+ }
5707
+ /**
5708
+ * Turns files into the requests that will be sent, plus the matches that
5709
+ * cannot be sent and why. Pure: it performs no I/O and decides nothing about
5710
+ * transport.
5711
+ */
5712
+ declare const buildJevRequests: ({
5713
+ budgetTokens,
5714
+ files
5715
+ }: BuildJevRequestsInput) => JevRequestPlan;
5716
+ //#endregion
5717
+ //#region src/jev/run.d.ts
5718
+ /**
5719
+ * Sending a file's requests and recording exactly what happened.
5720
+ *
5721
+ * A Jev run is a session diagnostic (ADR 0034): it owns no gate and no demand,
5722
+ * so a failed request is data, not a stop. One request failing never erases
5723
+ * the answers a sibling request already returned, and every match that did not
5724
+ * get an answer says why — including when the failure was that there was no
5725
+ * gateway to call at all.
5726
+ *
5727
+ * Every failure has exactly one behavior: the affected matches become
5728
+ * unavailable, named with their cause. Nothing is retried, nothing is
5729
+ * truncated to fit, and no result is dropped to keep a run tidy.
5730
+ */
5731
+ /** What one request did. Recorded whether it succeeded, failed, or was cached. */
5732
+ interface JevRequestRecord {
5733
+ /** True when the answer came from the request-hash cache; no HQ call was made. */
5734
+ cached: boolean;
5735
+ elapsedMs: number;
5736
+ /** Set when the request failed; the reason, in operator-facing prose. */
5737
+ error?: string;
5738
+ /** The upstream code, when HQ passed one through (`max_tokens_exceeded`). */
5739
+ errorCode?: string;
5740
+ estimatedTokens: number;
5741
+ matchKeys: string[];
5742
+ /** The model HQ reported actually running. Absent on a failed request. */
5743
+ model?: string;
5744
+ /** The file this request asked about. */
5745
+ path: string;
5746
+ /** SHA-256 of the exact request bytes. */
5747
+ requestHash: string;
5748
+ usage?: JevUsage;
5749
+ }
5750
+ /** Whether the run got answers for everything it set out to ask about. */
5751
+ type JevCompletion = "complete" | "partial" | "unavailable";
5752
+ interface JevRunResult {
5753
+ /** Answers per match, keyed by that match's own question names. */
5754
+ answersByMatchKey: Record<string, Record<string, JevAnswer>>;
5755
+ completion: JevCompletion;
5756
+ /** Wall-clock time spent on requests, including cache reads. */
5757
+ elapsedMs: number;
5758
+ /** Distinct models HQ reported, in first-seen order. */
5759
+ models: string[];
5760
+ requests: JevRequestRecord[];
5761
+ /** Why a match has no answers. Every unanswered match appears here. */
5762
+ unavailableByMatchKey: Record<string, string>;
5763
+ }
5764
+ interface RunJevFilesInput {
5765
+ budgetTokens?: number;
5766
+ /** Omitted means every request is sent live. */
5767
+ cache?: JevCache;
5768
+ files: readonly JevFile[];
5769
+ gateway: JevGateway;
5770
+ }
5771
+ /**
5772
+ * Builds the requests, sends the ones the cache does not already answer, and
5773
+ * routes answers back to the matches that asked for them.
5774
+ *
5775
+ * Requests go one at a time. Bounded load is the point: a repository-wide run
5776
+ * would otherwise open dozens of concurrent 32k-token requests against one HQ
5777
+ * route for a diagnostic nothing is waiting on.
5778
+ */
5779
+ declare const runJevFiles: ({
5780
+ budgetTokens,
5781
+ cache,
5782
+ files,
5783
+ gateway
5784
+ }: RunJevFilesInput) => Promise<JevRunResult>;
5785
+ //#endregion
5337
5786
  //#region src/index.d.ts
5338
5787
  interface CreateProgramOptions {
5339
5788
  actions?: {
@@ -5356,4 +5805,4 @@ declare function createProgram(options?: CreateProgramOptions): Command;
5356
5805
  */
5357
5806
  declare function run(argv?: string[], cliEntry?: string): Promise<void>;
5358
5807
  //#endregion
5359
- export { type AppendFactoryTraceEventResult, type AssembledReviewPrompt, type BatteryCommandDisposition, type BatteryDisposition, type BoundaryCheckArgs, type BoundaryCheckDependencies, type BoundaryCheckProofRecord, type BuildEpicStructureEventInput, type CloudflareAccessServiceToken, type CompletedFactoryCheckSnapshot, CreateProgramOptions, DEFAULT_DEMAND_WAIVER_PATH, DEFAULT_FACTORY_REPOSITORY, DEFAULT_ROOT_SHARED_GLOBS, type DagDocument, type DemandWaiveArgs, type DemandWaiveDependencies, DemandWaiveRefusalError, type DemandWaiver, type DemandWaiverStore, EMPTY_TREE_OBJECT_HASH, EPIC_STRUCTURE_NODE_STATUSES, EPIC_STRUCTURE_SCHEMA_VERSION, type EpicStructureEvent, type EpicStructureGraphPayload, type EpicStructureNodeStatus, EpicStructureValidationError, type EvidenceEmitArgs, type EvidenceEmitDependencies, type EvidenceEmitResult, FACTORY_BASE_REF_ENV, FACTORY_CHANGED_FILES_ENV, FACTORY_CHANGED_FILES_FILE_ENV, type FactoryCliInvocation, FactoryCliInvocationSchema, type FactoryPrStatusCheckName, type FactoryPrStatusSources, type FactoryProjectProfile, type FactoryTraceDiagnostic, type FactoryTraceEnvelope, type FactoryTraceEvent, type FollowUpAction, FollowUpActionSchema, type GitHubCheckRunMergeFreezeApi, type ImpactScopeDecision, type ImpactScopeSurface, type IssueReviewFocus, MERGE_FREEZE_APP_SLUG, MERGE_FREEZE_CHECK_NAME, type MergeFreezeAuthority, type MergeFreezeGeneration, type MergeFreezeState, type MergeFreezeStoreInput, type PlanFactoryPrStatusHudInput, type PrPublishArgs, type PrPublishDependencies, PrPublishFollowUpError, type PrPublishFollowUpOutcome, type PrPublishHandoff, type PrPublishResult, type PrReadyArgs, type PrReadyProof, type PrVerifyProof, type PresentFactoryPrStatusHudDependencies, type PresentFactoryPrStatusHudInput, type PreviewDisposition, type PreviewLifecyclePlan, type PreviewTargetPlan, type PublishEpicStructureArgs, type PublishEpicStructureResult, type PublishFollowUpPlan, REVIEW_FOCUS_SECTION, type ReadFactoryPrStatusSourcesDependencies, type ReadFactoryPrStatusSourcesInput, type RefreshFactoryPrStatusHudInput, type RenderFactoryPrStatusHudInput, type ReviewGateNotRequiredProof, type ReviewGateTraceIdentity, type ReviewPromptSection, type ReviewPromptSectionProvenance, type ScanFactoryTraceDiagnosticsOptions, type ScanFactoryTraceOptions, type ScanFactoryTraceResult, type ScopedOutCommand, type TraceMirrorDiagnostic, type TraceSink, type TraceWriteResult, type TraceWriteSinks, type VerificationBatteryPlan, type VerificationReuse, type VerificationRunContext, type VerificationRunContextInput, type WaivedDemand, WorkerCheckoutGuardError, type WorkerCloseoutLessonsTraceEvent, appendWithTraceSinks, applyDemandWaiver, assembleReviewPrompt, assertFactoryPrStatusIdentity, assertWorkerCheckoutAllowed, authorizeDemandWaiver, batteryScopeSummaryLines, boundary_manifest_d_exports as boundaryManifest, boundary_review_proof_d_exports as boundaryReviewProof, buildEpicStructureEvent, buildEpicStructurePayload, buildEvidenceEnvelope, buildReviewGateNotRequiredTraceEvent, comment_provenance_d_exports as commentProvenance, createGitHubCheckRunMergeFreezeStore, createLocalJsonlTraceSink, createProgram, createVerificationRunContext, doctorProjectProfile, epicStructureEventId, evidenceEnvelopeFilename, followUpFromArgv, impactStampScopeDecision, isProductionHqUrl, loadProjectProfile, normalizeIssueComments, planFactoryPrStatusHud, planPreviewLifecycle, planPublishFollowUp, planVerificationBattery, readiness_evaluation_d_exports as prReadinessEvaluation, external_evidence_d_exports as prReadinessExternalEvidence, pr_body_renderer_d_exports as prReadinessPrBodyRenderer, proof_identity_d_exports as prReadinessProofIdentity, review_proof_d_exports as prReadinessReviewProof, status_check_rollup_d_exports as prReadinessStatusChecks, verification_proof_d_exports as prReadinessVerificationProof, presentFactoryPrStatusHud, previewLifecycleTargets, publishEpicStructure, readDemandWaivers, readFactoryPrStatusSources, readPrReadyProof, refreshFactoryPrStatusHud, refreshFactoryPrStatusHudSafely, renderFactoryPrStatusHud, resolveFactoryRepository, resolveTraceWriteSinks, reviewFocusFromIssueBody, reviewPromptSectionSchema, reviewPromptSectionsSchema, run, runBoundaryCheck, runDemandWaive, runEvidenceEmit, runPrPublish, runPrReady, runPrReview, runPrVerify, scanFactoryTraceDiagnostics, scanFactoryTraceEvents, selectWaiversForCandidate, toFactoryTraceEnvelope, tryAppendReviewGateNotRequiredTraceEvent, validateBoundaryCheckProof, validateDagDocument, validateDemandWaiverStore, validateFactoryTraceEvent, validateMergeFreezeState, validatePrReadyProof, validatePrVerifyProof, validatePreviewLifecyclePlan, waivedDemandNotice, waivedDemandSchema, worktree_scratch_files_d_exports as worktreeScratchFiles };
5808
+ export { type AppendFactoryTraceEventResult, type AssembledReviewPrompt, type BatteryCommandDisposition, type BatteryDisposition, type BoundaryCheckArgs, type BoundaryCheckDependencies, type BoundaryCheckProofRecord, type BuildEpicStructureEventInput, type CloudflareAccessServiceToken, type CompletedFactoryCheckSnapshot, CreateProgramOptions, DEFAULT_DEMAND_WAIVER_PATH, DEFAULT_FACTORY_REPOSITORY, DEFAULT_ROOT_SHARED_GLOBS, type DagDocument, type DemandWaiveArgs, type DemandWaiveDependencies, DemandWaiveRefusalError, type DemandWaiver, type DemandWaiverStore, EMPTY_TREE_OBJECT_HASH, EPIC_STRUCTURE_NODE_STATUSES, EPIC_STRUCTURE_SCHEMA_VERSION, type EpicStructureEvent, type EpicStructureGraphPayload, type EpicStructureNodeStatus, EpicStructureValidationError, type EvidenceEmitArgs, type EvidenceEmitDependencies, type EvidenceEmitResult, FACTORY_BASE_REF_ENV, FACTORY_CHANGED_FILES_ENV, FACTORY_CHANGED_FILES_FILE_ENV, type FactoryCliInvocation, FactoryCliInvocationSchema, type FactoryPrStatusCheckName, type FactoryPrStatusSources, type FactoryProjectProfile, type FactoryTraceDiagnostic, type FactoryTraceEnvelope, type FactoryTraceEvent, type FollowUpAction, FollowUpActionSchema, type GitHubCheckRunMergeFreezeApi, type ImpactScopeDecision, type ImpactScopeSurface, type IssueReviewFocus, type JevAnswer, type JevCache, JevCacheError, type JevCompletion, type JevEvaluate, type JevFile, type JevGateway, type JevJsonValue, type JevMatch, type JevQuestions, type JevRequest, JevRequestError, type JevRequestPlan, type JevRequestRecord, type JevResponse, type JevRunResult, type JevUnavailableMatch, type JevUsage, MERGE_FREEZE_APP_SLUG, MERGE_FREEZE_CHECK_NAME, type MergeFreezeAuthority, type MergeFreezeGeneration, type MergeFreezeState, type MergeFreezeStoreInput, type PlanFactoryPrStatusHudInput, type PrPublishArgs, type PrPublishDependencies, PrPublishFollowUpError, type PrPublishFollowUpOutcome, type PrPublishHandoff, type PrPublishResult, type PrReadyArgs, type PrReadyProof, type PrVerifyProof, type PresentFactoryPrStatusHudDependencies, type PresentFactoryPrStatusHudInput, type PreviewDisposition, type PreviewLifecyclePlan, type PreviewTargetPlan, type PublishEpicStructureArgs, type PublishEpicStructureResult, type PublishFollowUpPlan, REVIEW_FOCUS_SECTION, type ReadFactoryPrStatusSourcesDependencies, type ReadFactoryPrStatusSourcesInput, type RefreshFactoryPrStatusHudInput, type RenderFactoryPrStatusHudInput, type ReviewGateNotRequiredProof, type ReviewGateTraceIdentity, type ReviewPromptSection, type ReviewPromptSectionProvenance, type ScanFactoryTraceDiagnosticsOptions, type ScanFactoryTraceOptions, type ScanFactoryTraceResult, type ScopedOutCommand, type TraceMirrorDiagnostic, type TraceSink, type TraceWriteResult, type TraceWriteSinks, UNKNOWN_MODEL, type VerificationBatteryPlan, type VerificationReuse, type VerificationRunContext, type VerificationRunContextInput, type WaivedDemand, WorkerCheckoutGuardError, type WorkerCloseoutLessonsTraceEvent, appendWithTraceSinks, applyDemandWaiver, assembleReviewPrompt, assertFactoryPrStatusIdentity, assertWorkerCheckoutAllowed, authorizeDemandWaiver, batteryScopeSummaryLines, boundary_manifest_d_exports as boundaryManifest, boundary_review_proof_d_exports as boundaryReviewProof, buildEpicStructureEvent, buildEpicStructurePayload, buildEvidenceEnvelope, buildJevRequests, buildReviewGateNotRequiredTraceEvent, choice, comment_provenance_d_exports as commentProvenance, createGitHubCheckRunMergeFreezeStore, createLocalJsonlTraceSink, createProgram, createVerificationRunContext, defaultJevCacheDirectory, doctorProjectProfile, epicStructureEventId, evidenceEnvelopeFilename, followUpFromArgv, impactStampScopeDecision, isProductionHqUrl, loadProjectProfile, normalizeIssueComments, noul, openJevCache, planFactoryPrStatusHud, planPreviewLifecycle, planPublishFollowUp, planVerificationBattery, readiness_evaluation_d_exports as prReadinessEvaluation, external_evidence_d_exports as prReadinessExternalEvidence, pr_body_renderer_d_exports as prReadinessPrBodyRenderer, proof_identity_d_exports as prReadinessProofIdentity, review_proof_d_exports as prReadinessReviewProof, status_check_rollup_d_exports as prReadinessStatusChecks, verification_proof_d_exports as prReadinessVerificationProof, presentFactoryPrStatusHud, previewLifecycleTargets, publishEpicStructure, readDemandWaivers, readFactoryPrStatusSources, readPrReadyProof, refreshFactoryPrStatusHud, refreshFactoryPrStatusHudSafely, renderFactoryPrStatusHud, resolveFactoryRepository, resolveJevGateway, resolveTraceWriteSinks, reviewFocusFromIssueBody, reviewPromptSectionSchema, reviewPromptSectionsSchema, run, runBoundaryCheck, runDemandWaive, runEvidenceEmit, runJevFiles, runPrPublish, runPrReady, runPrReview, runPrVerify, scanFactoryTraceDiagnostics, scanFactoryTraceEvents, score, selectWaiversForCandidate, toFactoryTraceEnvelope, tryAppendReviewGateNotRequiredTraceEvent, validateBoundaryCheckProof, validateDagDocument, validateDemandWaiverStore, validateFactoryTraceEvent, validateMergeFreezeState, validatePrReadyProof, validatePrVerifyProof, validatePreviewLifecyclePlan, waivedDemandNotice, waivedDemandSchema, worktree_scratch_files_d_exports as worktreeScratchFiles };