clinkx 1.2.0 → 1.3.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/CHANGELOG.md +32 -0
- package/README.md +4 -2
- package/clinkx-workflows/dist/architecture-arena/admission.d.ts +16 -0
- package/clinkx-workflows/dist/architecture-arena/admission.js +107 -0
- package/clinkx-workflows/dist/architecture-arena/admission.js.map +1 -0
- package/clinkx-workflows/dist/architecture-arena/contract.d.ts +1368 -0
- package/clinkx-workflows/dist/architecture-arena/contract.js +254 -0
- package/clinkx-workflows/dist/architecture-arena/contract.js.map +1 -0
- package/clinkx-workflows/dist/architecture-arena/runtime.d.ts +53 -0
- package/clinkx-workflows/dist/architecture-arena/runtime.js +511 -0
- package/clinkx-workflows/dist/architecture-arena/runtime.js.map +1 -0
- package/clinkx-workflows/dist/architecture-comparison/admission.d.ts +17 -1
- package/clinkx-workflows/dist/architecture-comparison/admission.js +27 -4
- package/clinkx-workflows/dist/architecture-comparison/admission.js.map +1 -1
- package/clinkx-workflows/dist/architecture-comparison/contract.d.ts +59 -62
- package/clinkx-workflows/dist/architecture-comparison/contract.js +4 -21
- package/clinkx-workflows/dist/architecture-comparison/contract.js.map +1 -1
- package/clinkx-workflows/dist/architecture-comparison/runtime.d.ts +4 -3
- package/clinkx-workflows/dist/architecture-comparison/runtime.js +22 -67
- package/clinkx-workflows/dist/architecture-comparison/runtime.js.map +1 -1
- package/clinkx-workflows/dist/artifacts.d.ts +19 -4
- package/clinkx-workflows/dist/artifacts.js +16 -7
- package/clinkx-workflows/dist/artifacts.js.map +1 -1
- package/clinkx-workflows/dist/backend.d.ts +30 -0
- package/clinkx-workflows/dist/clink-client.d.ts +8 -2
- package/clinkx-workflows/dist/clink-client.js +4 -2
- package/clinkx-workflows/dist/clink-client.js.map +1 -1
- package/clinkx-workflows/dist/context-preflight.d.ts +6 -0
- package/clinkx-workflows/dist/context-preflight.js.map +1 -1
- package/clinkx-workflows/dist/council-execution-policy.d.ts +3 -1
- package/clinkx-workflows/dist/council-execution-policy.js +4 -0
- package/clinkx-workflows/dist/council-execution-policy.js.map +1 -1
- package/clinkx-workflows/dist/dashboard/contracts.d.ts +586 -586
- package/clinkx-workflows/dist/dashboard/progress-report-contract.d.ts +28 -28
- package/clinkx-workflows/dist/dashboard/session-log-contract.d.ts +32 -32
- package/clinkx-workflows/dist/dashboard-ui/assets/index-DRId2DVA.js +119 -0
- package/clinkx-workflows/dist/dashboard-ui/assets/style-CHAw57y5.css +1 -0
- package/clinkx-workflows/dist/dashboard-ui/index.html +2 -2
- package/clinkx-workflows/dist/delegate-signature.d.ts +4 -3
- package/clinkx-workflows/dist/delegate-signature.js +4 -3
- package/clinkx-workflows/dist/delegate-signature.js.map +1 -1
- package/clinkx-workflows/dist/durable-file.d.ts +69 -0
- package/clinkx-workflows/dist/durable-file.js +145 -0
- package/clinkx-workflows/dist/durable-file.js.map +1 -0
- package/clinkx-workflows/dist/engine.d.ts +42 -7
- package/clinkx-workflows/dist/engine.js +196 -24
- package/clinkx-workflows/dist/engine.js.map +1 -1
- package/clinkx-workflows/dist/ping-pong/admission.d.ts +127 -0
- package/clinkx-workflows/dist/ping-pong/admission.js +522 -0
- package/clinkx-workflows/dist/ping-pong/admission.js.map +1 -0
- package/clinkx-workflows/dist/ping-pong/contract.d.ts +2539 -0
- package/clinkx-workflows/dist/ping-pong/contract.js +819 -0
- package/clinkx-workflows/dist/ping-pong/contract.js.map +1 -0
- package/clinkx-workflows/dist/ping-pong/control.d.ts +67 -0
- package/clinkx-workflows/dist/ping-pong/control.js +12 -0
- package/clinkx-workflows/dist/ping-pong/control.js.map +1 -0
- package/clinkx-workflows/dist/ping-pong/runtime-handle.d.ts +24 -0
- package/clinkx-workflows/dist/ping-pong/runtime-handle.js +55 -0
- package/clinkx-workflows/dist/ping-pong/runtime-handle.js.map +1 -0
- package/clinkx-workflows/dist/ping-pong/runtime.d.ts +235 -0
- package/clinkx-workflows/dist/ping-pong/runtime.js +1183 -0
- package/clinkx-workflows/dist/ping-pong/runtime.js.map +1 -0
- package/clinkx-workflows/dist/ping-pong/settle.d.ts +57 -0
- package/clinkx-workflows/dist/ping-pong/settle.js +58 -0
- package/clinkx-workflows/dist/ping-pong/settle.js.map +1 -0
- package/clinkx-workflows/dist/ping-pong/sidecar.d.ts +65 -0
- package/clinkx-workflows/dist/ping-pong/sidecar.js +138 -0
- package/clinkx-workflows/dist/ping-pong/sidecar.js.map +1 -0
- package/clinkx-workflows/dist/plan-review/publication.d.ts +2 -1
- package/clinkx-workflows/dist/plan-review/publication.js +5 -6
- package/clinkx-workflows/dist/plan-review/publication.js.map +1 -1
- package/clinkx-workflows/dist/plan-review/snapshot.d.ts +3 -2
- package/clinkx-workflows/dist/plan-review/snapshot.js +8 -8
- package/clinkx-workflows/dist/plan-review/snapshot.js.map +1 -1
- package/clinkx-workflows/dist/recipe-host.d.ts +315 -0
- package/clinkx-workflows/dist/recipe-host.js +183 -0
- package/clinkx-workflows/dist/recipe-host.js.map +1 -0
- package/clinkx-workflows/dist/recipe-seats.d.ts +96 -0
- package/clinkx-workflows/dist/recipe-seats.js +163 -0
- package/clinkx-workflows/dist/recipe-seats.js.map +1 -0
- package/clinkx-workflows/dist/recipe-shared/evidence.d.ts +67 -0
- package/clinkx-workflows/dist/recipe-shared/evidence.js +111 -0
- package/clinkx-workflows/dist/recipe-shared/evidence.js.map +1 -0
- package/clinkx-workflows/dist/reducers/index.d.ts +9 -1
- package/clinkx-workflows/dist/reducers/index.js +30 -0
- package/clinkx-workflows/dist/reducers/index.js.map +1 -1
- package/clinkx-workflows/dist/run-lock-reclaim.d.ts +44 -0
- package/clinkx-workflows/dist/run-lock-reclaim.js +86 -0
- package/clinkx-workflows/dist/run-lock-reclaim.js.map +1 -0
- package/clinkx-workflows/dist/state-schema.d.ts +11 -0
- package/clinkx-workflows/dist/state-schema.js +4 -1
- package/clinkx-workflows/dist/state-schema.js.map +1 -1
- package/clinkx-workflows/dist/state.d.ts +178 -3
- package/clinkx-workflows/dist/state.js +618 -83
- package/clinkx-workflows/dist/state.js.map +1 -1
- package/clinkx-workflows/dist/transport.d.ts +2 -1
- package/clinkx-workflows/dist/transport.js +5 -0
- package/clinkx-workflows/dist/transport.js.map +1 -1
- package/clinkx-workflows/dist/validators/architecture-arena.d.ts +6 -0
- package/clinkx-workflows/dist/validators/architecture-arena.js +16 -0
- package/clinkx-workflows/dist/validators/architecture-arena.js.map +1 -0
- package/clinkx-workflows/dist/validators/index.js +4 -0
- package/clinkx-workflows/dist/validators/index.js.map +1 -1
- package/clinkx-workflows/dist/validators/ping-pong.d.ts +6 -0
- package/clinkx-workflows/dist/validators/ping-pong.js +10 -0
- package/clinkx-workflows/dist/validators/ping-pong.js.map +1 -0
- package/clinkx-workflows/dist/workflow-tools.d.ts +51 -5
- package/clinkx-workflows/dist/workflow-tools.js +785 -34
- package/clinkx-workflows/dist/workflow-tools.js.map +1 -1
- package/clinkx-workflows/dist/workflow-verification-contract.d.ts +4 -4
- package/clinkx-workflows/templates/architecture-arena/candidate.txt +39 -0
- package/clinkx-workflows/templates/architecture-arena/judge.txt +34 -0
- package/clinkx-workflows/templates/ping-pong/implement.txt +14 -0
- package/clinkx-workflows/templates/ping-pong/remediate.txt +14 -0
- package/clinkx-workflows/templates/ping-pong/review.txt +27 -0
- package/clinkx-workflows/workflows/architecture-arena.yaml +127 -0
- package/clinkx-workflows/workflows/ping-pong.yaml +158 -0
- package/dist/context-builder/bundle.js +4 -3
- package/dist/context-builder/bundle.js.map +1 -1
- package/dist/context-builder/delegate-packet.d.ts +1 -0
- package/dist/context-builder/delegate-packet.js +66 -7
- package/dist/context-builder/delegate-packet.js.map +1 -1
- package/dist/context-builder/delegate-validation.d.ts +12 -3
- package/dist/context-builder/delegate-validation.js +23 -13
- package/dist/context-builder/delegate-validation.js.map +1 -1
- package/dist/context-builder/external-gaps.d.ts +14 -3
- package/dist/context-builder/external-gaps.js +124 -18
- package/dist/context-builder/external-gaps.js.map +1 -1
- package/dist/context-builder/handler.js +108 -191
- package/dist/context-builder/handler.js.map +1 -1
- package/dist/context-builder/review-coverage.js +27 -1
- package/dist/context-builder/review-coverage.js.map +1 -1
- package/dist/context-builder/secrets.js +1 -1
- package/dist/context-builder/secrets.js.map +1 -1
- package/dist/context-builder/versions.d.ts +10 -4
- package/dist/context-builder/versions.js +10 -4
- package/dist/context-builder/versions.js.map +1 -1
- package/dist/context-builder/workflow-runner.js +33 -24
- package/dist/context-builder/workflow-runner.js.map +1 -1
- package/dist/dashboard-cli.d.ts +2 -0
- package/dist/dashboard-cli.js +147 -57
- package/dist/dashboard-cli.js.map +1 -1
- package/dist/dashboard-companion/client.d.ts +10 -0
- package/dist/dashboard-companion/client.js +43 -1
- package/dist/dashboard-companion/client.js.map +1 -1
- package/dist/dashboard-companion/config.d.ts +19 -1
- package/dist/dashboard-companion/config.js +104 -3
- package/dist/dashboard-companion/config.js.map +1 -1
- package/dist/dashboard-companion/protocol.d.ts +16 -0
- package/dist/dashboard-companion/protocol.js +38 -1
- package/dist/dashboard-companion/protocol.js.map +1 -1
- package/dist/dashboard-companion/workstation-binding.d.ts +69 -0
- package/dist/dashboard-companion/workstation-binding.js +192 -0
- package/dist/dashboard-companion/workstation-binding.js.map +1 -0
- package/dist/dashboard-gateway/admin-cli.d.ts +10 -0
- package/dist/dashboard-gateway/admin-cli.js +266 -0
- package/dist/dashboard-gateway/admin-cli.js.map +1 -0
- package/dist/dashboard-gateway/config.d.ts +50 -0
- package/dist/dashboard-gateway/config.js +235 -1
- package/dist/dashboard-gateway/config.js.map +1 -1
- package/dist/dashboard-gateway/connection-registry.d.ts +100 -0
- package/dist/dashboard-gateway/connection-registry.js +228 -0
- package/dist/dashboard-gateway/connection-registry.js.map +1 -0
- package/dist/dashboard-gateway/control-plane/account-auth.d.ts +78 -0
- package/dist/dashboard-gateway/control-plane/account-auth.js +198 -0
- package/dist/dashboard-gateway/control-plane/account-auth.js.map +1 -0
- package/dist/dashboard-gateway/control-plane/billing.d.ts +264 -0
- package/dist/dashboard-gateway/control-plane/billing.js +787 -0
- package/dist/dashboard-gateway/control-plane/billing.js.map +1 -0
- package/dist/dashboard-gateway/control-plane/contracts.d.ts +1293 -0
- package/dist/dashboard-gateway/control-plane/contracts.js +280 -0
- package/dist/dashboard-gateway/control-plane/contracts.js.map +1 -0
- package/dist/dashboard-gateway/control-plane/cookies.d.ts +13 -0
- package/dist/dashboard-gateway/control-plane/cookies.js +46 -0
- package/dist/dashboard-gateway/control-plane/cookies.js.map +1 -0
- package/dist/dashboard-gateway/control-plane/credentials.d.ts +63 -0
- package/dist/dashboard-gateway/control-plane/credentials.js +66 -0
- package/dist/dashboard-gateway/control-plane/credentials.js.map +1 -0
- package/dist/dashboard-gateway/control-plane/entitlements.d.ts +118 -0
- package/dist/dashboard-gateway/control-plane/entitlements.js +329 -0
- package/dist/dashboard-gateway/control-plane/entitlements.js.map +1 -0
- package/dist/dashboard-gateway/control-plane/errors.d.ts +17 -0
- package/dist/dashboard-gateway/control-plane/errors.js +23 -0
- package/dist/dashboard-gateway/control-plane/errors.js.map +1 -0
- package/dist/dashboard-gateway/control-plane/hosts.d.ts +6 -0
- package/dist/dashboard-gateway/control-plane/hosts.js +16 -0
- package/dist/dashboard-gateway/control-plane/hosts.js.map +1 -0
- package/dist/dashboard-gateway/control-plane/http.d.ts +34 -0
- package/dist/dashboard-gateway/control-plane/http.js +331 -0
- package/dist/dashboard-gateway/control-plane/http.js.map +1 -0
- package/dist/dashboard-gateway/control-plane/schema.d.ts +9 -0
- package/dist/dashboard-gateway/control-plane/schema.js +247 -0
- package/dist/dashboard-gateway/control-plane/schema.js.map +1 -0
- package/dist/dashboard-gateway/control-plane/secrets.d.ts +20 -0
- package/dist/dashboard-gateway/control-plane/secrets.js +39 -0
- package/dist/dashboard-gateway/control-plane/secrets.js.map +1 -0
- package/dist/dashboard-gateway/control-plane/store.d.ts +579 -0
- package/dist/dashboard-gateway/control-plane/store.js +1115 -0
- package/dist/dashboard-gateway/control-plane/store.js.map +1 -0
- package/dist/dashboard-gateway/cookie-boundary.d.ts +60 -0
- package/dist/dashboard-gateway/cookie-boundary.js +205 -0
- package/dist/dashboard-gateway/cookie-boundary.js.map +1 -0
- package/dist/dashboard-gateway/index.js +271 -494
- package/dist/dashboard-gateway/index.js.map +1 -1
- package/dist/dashboard-gateway/main.js +7 -2
- package/dist/dashboard-gateway/main.js.map +1 -1
- package/dist/dashboard-gateway/routing.d.ts +43 -0
- package/dist/dashboard-gateway/routing.js +65 -0
- package/dist/dashboard-gateway/routing.js.map +1 -0
- package/dist/dashboard-gateway/tenant-gateway.d.ts +56 -0
- package/dist/dashboard-gateway/tenant-gateway.js +989 -0
- package/dist/dashboard-gateway/tenant-gateway.js.map +1 -0
- package/dist/dashboard-gateway/tenant-main.d.ts +41 -0
- package/dist/dashboard-gateway/tenant-main.js +303 -0
- package/dist/dashboard-gateway/tenant-main.js.map +1 -0
- package/dist/dashboard-gateway/tunnel-errors.d.ts +16 -0
- package/dist/dashboard-gateway/tunnel-errors.js +22 -0
- package/dist/dashboard-gateway/tunnel-errors.js.map +1 -0
- package/dist/dashboard-gateway/tunnel-http.d.ts +21 -0
- package/dist/dashboard-gateway/tunnel-http.js +175 -0
- package/dist/dashboard-gateway/tunnel-http.js.map +1 -0
- package/dist/handler.d.ts +6 -0
- package/dist/handler.js +17 -1
- package/dist/handler.js.map +1 -1
- package/dist/local-clink-backend.d.ts +2 -1
- package/dist/local-clink-backend.js +28 -4
- package/dist/local-clink-backend.js.map +1 -1
- package/dist/parsers/extract.d.ts +19 -1
- package/dist/parsers/extract.js +68 -3
- package/dist/parsers/extract.js.map +1 -1
- package/dist/pipeline.d.ts +17 -1
- package/dist/pipeline.js +34 -6
- package/dist/pipeline.js.map +1 -1
- package/dist/process-group.d.ts +65 -0
- package/dist/process-group.js +153 -0
- package/dist/process-group.js.map +1 -0
- package/dist/progress-report/schema.d.ts +23 -23
- package/dist/project-verification/files.js +1 -1
- package/dist/project-verification/files.js.map +1 -1
- package/dist/project-verification/process.js +23 -44
- package/dist/project-verification/process.js.map +1 -1
- package/dist/project-verification/service.js +9 -1
- package/dist/project-verification/service.js.map +1 -1
- package/dist/prompt.d.ts +7 -0
- package/dist/prompt.js +18 -1
- package/dist/prompt.js.map +1 -1
- package/dist/recipe-host/git-trust.d.ts +43 -0
- package/dist/recipe-host/git-trust.js +360 -0
- package/dist/recipe-host/git-trust.js.map +1 -0
- package/dist/recipe-host/git.d.ts +42 -0
- package/dist/recipe-host/git.js +207 -0
- package/dist/recipe-host/git.js.map +1 -0
- package/dist/recipe-host/native-recipe-host.d.ts +127 -0
- package/dist/recipe-host/native-recipe-host.js +880 -0
- package/dist/recipe-host/native-recipe-host.js.map +1 -0
- package/dist/recipe-host/seat-cwd.d.ts +16 -0
- package/dist/recipe-host/seat-cwd.js +170 -0
- package/dist/recipe-host/seat-cwd.js.map +1 -0
- package/dist/runner.d.ts +43 -1
- package/dist/runner.js +234 -35
- package/dist/runner.js.map +1 -1
- package/dist/server.js +9 -1
- package/dist/server.js.map +1 -1
- package/docs/configuration.md +24 -3
- package/docs/engineering-recipes.md +291 -0
- package/docs/security.md +84 -0
- package/docs/verification/project-checks.md +24 -2
- package/package.json +5 -1
- package/clinkx-workflows/dist/dashboard-ui/assets/index-BdpmbPps.js +0 -115
- package/clinkx-workflows/dist/dashboard-ui/assets/style-Im5i1iAs.css +0 -1
|
@@ -0,0 +1,819 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ping-pong recipe contracts (PLAN 3-3, 3-6; CONTRACTS revision 2: 0-2, 0-4,
|
|
3
|
+
* 0-7, "Reviewer output pp-review-v1").
|
|
4
|
+
*
|
|
5
|
+
* Pure schemas, bounds, and transition rules. No I/O lives here: the sidecar
|
|
6
|
+
* file helpers are in `./sidecar.ts`, the store methods in `../state.ts`, and
|
|
7
|
+
* the tool handlers in `../workflow-tools.ts`. Every byte bound below is the
|
|
8
|
+
* CONTRACTS 0-4 value; change them only with a contract revision.
|
|
9
|
+
*/
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
import { canonicalJson, digest } from "../recipe-shared/evidence.js";
|
|
12
|
+
import { PING_PONG_WORKFLOW } from "../recipe-seats.js";
|
|
13
|
+
export { PING_PONG_WORKFLOW };
|
|
14
|
+
export const RECIPE_STATE_SCHEMA = "recipe-state-v1";
|
|
15
|
+
export const PP_REVIEW_SCHEMA = "pp-review-v1";
|
|
16
|
+
export const RECIPE_DECIDE_TOOL = "workflow_recipe_decide";
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
// 0-4 bounds
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
export const PP_MIN_ROUNDS = 1;
|
|
21
|
+
export const PP_MAX_ROUNDS = 8;
|
|
22
|
+
export const PP_DEFAULT_ROUNDS = 3;
|
|
23
|
+
export const PP_MIN_REVIEWERS = 1;
|
|
24
|
+
/** CONTRACTS 0-4: k = 1..4 reviewers (members 2..5). */
|
|
25
|
+
export const PP_MAX_REVIEWERS = 4;
|
|
26
|
+
export const PP_DEFAULT_SIGN_OFF_THRESHOLD = 9;
|
|
27
|
+
export const PP_MAX_FINDINGS_PER_ROUND = 24;
|
|
28
|
+
export const PP_MAX_FINDING_SUMMARY_CHARS = 240;
|
|
29
|
+
export const PP_MAX_FINDING_DETAIL_BYTES = 2 * 1024;
|
|
30
|
+
export const PP_MAX_REVIEW_OUTPUT_BYTES = 64 * 1024;
|
|
31
|
+
export const PP_MAX_IMPLEMENTER_SUMMARY_BYTES = 16 * 1024;
|
|
32
|
+
export const PP_MAX_SEAT_PACKET_BYTES = 96 * 1024;
|
|
33
|
+
export const PP_MAX_INLINE_DELTA_BYTES = 48 * 1024;
|
|
34
|
+
export const PP_MAX_USER_REQUEST_BYTES = 16 * 1024;
|
|
35
|
+
export const PP_MAX_DECISION_RECORDS = 16;
|
|
36
|
+
export const PP_MAX_DECISION_RECORD_BYTES = 16 * 1024;
|
|
37
|
+
/** Canonical decision body; the remaining 2 KiB of a record is its envelope. */
|
|
38
|
+
export const PP_MAX_DECISION_BYTES = 14 * 1024;
|
|
39
|
+
export const PP_MAX_NOTE_CHARS = 300;
|
|
40
|
+
export const PP_MAX_STOP_DETAIL_CHARS = 600;
|
|
41
|
+
export const PP_MAX_AUDIT_REQUESTS = 3;
|
|
42
|
+
export const PP_MAX_RECIPE_STATE_BYTES = 1024 * 1024;
|
|
43
|
+
export const PP_TERMINAL_RESERVE_BYTES = 64 * 1024;
|
|
44
|
+
/** Largest non-terminal sidecar; the rest is reserved for the terminal write. */
|
|
45
|
+
export const PP_MAX_NONTERMINAL_RECIPE_STATE_BYTES = PP_MAX_RECIPE_STATE_BYTES - PP_TERMINAL_RESERVE_BYTES;
|
|
46
|
+
export const PP_DEFAULT_ACTIVE_BUDGET_SECONDS = 2 * 60 * 60;
|
|
47
|
+
export const PP_MAX_ACTIVE_BUDGET_SECONDS = 8 * 60 * 60;
|
|
48
|
+
export const PP_DEFAULT_DEADLINE_SECONDS = 24 * 60 * 60;
|
|
49
|
+
export const PP_MAX_DEADLINE_SECONDS = 72 * 60 * 60;
|
|
50
|
+
/** Upper bound on recorded operations (writer, reviewers, verifications per round + final). */
|
|
51
|
+
export const PP_MAX_OPERATIONS = 256;
|
|
52
|
+
export const PP_MAX_WORKTREES = 1 + PP_MAX_REVIEWERS;
|
|
53
|
+
/** Reviewer seats are 1-based in finding ids (`S1`..`S4`); seat 0 is the implementer. */
|
|
54
|
+
export const PP_REVIEWER_SEATS = [1, 2, 3, 4];
|
|
55
|
+
// ---------------------------------------------------------------------------
|
|
56
|
+
// Enums
|
|
57
|
+
// ---------------------------------------------------------------------------
|
|
58
|
+
export const RECIPE_PHASES = [
|
|
59
|
+
"admitted",
|
|
60
|
+
"implementing",
|
|
61
|
+
"verifying",
|
|
62
|
+
"reviewing",
|
|
63
|
+
"awaiting_decision",
|
|
64
|
+
"remediating",
|
|
65
|
+
"final_verifying",
|
|
66
|
+
"stopped",
|
|
67
|
+
"qualified",
|
|
68
|
+
];
|
|
69
|
+
export const RecipePhaseSchema = z.enum(RECIPE_PHASES);
|
|
70
|
+
export const TERMINAL_RECIPE_PHASES = new Set(["stopped", "qualified"]);
|
|
71
|
+
export const RECIPE_OUTCOMES = ["qualified", "stopped", "failed", "cancelled"];
|
|
72
|
+
export const RecipeOutcomeSchema = z.enum(RECIPE_OUTCOMES);
|
|
73
|
+
/** CONTRACTS 0-2 closed enum. */
|
|
74
|
+
export const STOP_REASONS = [
|
|
75
|
+
"main_agent_stop",
|
|
76
|
+
"round_budget_exhausted",
|
|
77
|
+
"no_sign_off",
|
|
78
|
+
"seat_unavailable",
|
|
79
|
+
"no_progress",
|
|
80
|
+
"final_verification_failed",
|
|
81
|
+
"acceptance_input_changed",
|
|
82
|
+
"target_changed_during_review",
|
|
83
|
+
"recovery_required",
|
|
84
|
+
"permission_failure",
|
|
85
|
+
"deadline_exceeded",
|
|
86
|
+
"active_budget_exhausted",
|
|
87
|
+
"evidence_capacity",
|
|
88
|
+
"cancelled",
|
|
89
|
+
];
|
|
90
|
+
export const StopReasonSchema = z.enum(STOP_REASONS);
|
|
91
|
+
export const OPERATION_STATUSES = ["intent_recorded", "result_recorded", "uncertain"];
|
|
92
|
+
export const OperationStatusSchema = z.enum(OPERATION_STATUSES);
|
|
93
|
+
export const OPERATION_KINDS = ["writer", "reviewer", "verification", "identity", "control"];
|
|
94
|
+
export const FINDING_SEVERITIES = ["blocker", "major", "minor", "nit"];
|
|
95
|
+
export const FindingSeveritySchema = z.enum(FINDING_SEVERITIES);
|
|
96
|
+
export const REVIEWER_OUTCOMES = ["signed_off", "withheld", "failed"];
|
|
97
|
+
export const ReviewerOutcomeSchema = z.enum(REVIEWER_OUTCOMES);
|
|
98
|
+
/**
|
|
99
|
+
* Legal phase moves. Same-phase writes (operation bookkeeping, budget use) are
|
|
100
|
+
* always allowed for a non-terminal phase; every non-terminal phase may stop.
|
|
101
|
+
*/
|
|
102
|
+
const PHASE_TRANSITIONS = {
|
|
103
|
+
admitted: ["implementing"],
|
|
104
|
+
implementing: ["verifying"],
|
|
105
|
+
verifying: ["reviewing"],
|
|
106
|
+
reviewing: ["awaiting_decision"],
|
|
107
|
+
awaiting_decision: ["remediating", "final_verifying"],
|
|
108
|
+
remediating: ["verifying"],
|
|
109
|
+
final_verifying: ["qualified"],
|
|
110
|
+
stopped: [],
|
|
111
|
+
qualified: [],
|
|
112
|
+
};
|
|
113
|
+
export function isTerminalRecipePhase(phase) {
|
|
114
|
+
return TERMINAL_RECIPE_PHASES.has(phase);
|
|
115
|
+
}
|
|
116
|
+
export function isLegalPhaseTransition(from, to) {
|
|
117
|
+
if (from === undefined)
|
|
118
|
+
return to === "admitted";
|
|
119
|
+
if (isTerminalRecipePhase(from))
|
|
120
|
+
return false;
|
|
121
|
+
if (from === to)
|
|
122
|
+
return true;
|
|
123
|
+
return to === "stopped" || PHASE_TRANSITIONS[from].includes(to);
|
|
124
|
+
}
|
|
125
|
+
/** Terminal outcome -> `state.json` status (CONTRACTS 0-7). */
|
|
126
|
+
export function runStatusForOutcome(outcome) {
|
|
127
|
+
switch (outcome) {
|
|
128
|
+
case "qualified":
|
|
129
|
+
case "stopped":
|
|
130
|
+
return "succeeded";
|
|
131
|
+
case "failed":
|
|
132
|
+
return "failed";
|
|
133
|
+
case "cancelled":
|
|
134
|
+
return "cancelled";
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// ---------------------------------------------------------------------------
|
|
138
|
+
// Primitive schemas
|
|
139
|
+
// ---------------------------------------------------------------------------
|
|
140
|
+
/** `R{round}-S{seat}-{n}`: round 1..8, reviewer seat 1..4, n 1..24. */
|
|
141
|
+
export const FINDING_ID_PATTERN = /^R([1-8])-S([1-4])-([1-9]|1[0-9]|2[0-4])$/;
|
|
142
|
+
export function formatFindingId(round, seat, n) {
|
|
143
|
+
const id = `R${round}-S${seat}-${n}`;
|
|
144
|
+
if (!FINDING_ID_PATTERN.test(id)) {
|
|
145
|
+
throw new Error(`finding id ${id} is outside R1..8-S1..4-1..24`);
|
|
146
|
+
}
|
|
147
|
+
return id;
|
|
148
|
+
}
|
|
149
|
+
export function parseFindingId(id) {
|
|
150
|
+
const match = FINDING_ID_PATTERN.exec(id);
|
|
151
|
+
if (match === null)
|
|
152
|
+
return undefined;
|
|
153
|
+
return { round: Number(match[1]), seat: Number(match[2]), n: Number(match[3]) };
|
|
154
|
+
}
|
|
155
|
+
const utf8Bytes = (value) => Buffer.byteLength(value, "utf8");
|
|
156
|
+
export const FindingIdSchema = z.string().regex(FINDING_ID_PATTERN, "finding id must match R{round}-S{seat}-{n}");
|
|
157
|
+
const ExecutionIdSchema = z.string().min(1).max(128);
|
|
158
|
+
const RunIdSchema = z.string().regex(/^[A-Za-z0-9_-]{1,64}$/);
|
|
159
|
+
const IsoTimestampSchema = z.string().min(1).max(64).refine((value) => Number.isFinite(Date.parse(value)), "must be an ISO timestamp");
|
|
160
|
+
const Sha256Schema = z.string().regex(/^[0-9a-f]{64}$/);
|
|
161
|
+
/** Git object id (sha1 or sha256 repositories). */
|
|
162
|
+
const GitObjectIdSchema = z.string().regex(/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/);
|
|
163
|
+
const NoteSchema = z.string().trim().min(1).max(PP_MAX_NOTE_CHARS);
|
|
164
|
+
const RoundSchema = z.number().int().min(PP_MIN_ROUNDS).max(PP_MAX_ROUNDS);
|
|
165
|
+
const ReviewerSeatSchema = z.number().int().min(1).max(PP_MAX_REVIEWERS);
|
|
166
|
+
const RelPathSchema = z.string().min(1).max(4096);
|
|
167
|
+
const AbsPathSchema = z.string().min(1).max(4096).refine((value) => value.startsWith("/"), "must be an absolute path");
|
|
168
|
+
const FindingDetailSchema = z.string().max(PP_MAX_FINDING_DETAIL_BYTES).refine((value) => utf8Bytes(value) <= PP_MAX_FINDING_DETAIL_BYTES, `detail must be at most ${PP_MAX_FINDING_DETAIL_BYTES} UTF-8 bytes`);
|
|
169
|
+
const FindingSummarySchema = z.string().trim().min(1).max(PP_MAX_FINDING_SUMMARY_CHARS);
|
|
170
|
+
// ---------------------------------------------------------------------------
|
|
171
|
+
// pp-review-v1 (reviewer output)
|
|
172
|
+
// ---------------------------------------------------------------------------
|
|
173
|
+
export const PpReviewFindingSchema = z.object({
|
|
174
|
+
severity: FindingSeveritySchema,
|
|
175
|
+
path: RelPathSchema.optional(),
|
|
176
|
+
line: z.number().int().min(1).optional(),
|
|
177
|
+
summary: FindingSummarySchema,
|
|
178
|
+
detail: FindingDetailSchema,
|
|
179
|
+
}).strict();
|
|
180
|
+
/**
|
|
181
|
+
* Raw reviewer JSON. Round/seat/echo binding and the 24-per-round budget are
|
|
182
|
+
* checked against the dispatched packet by `validatePpReview`, not here.
|
|
183
|
+
*/
|
|
184
|
+
export const PpReviewSchema = z.object({
|
|
185
|
+
schema: z.literal(PP_REVIEW_SCHEMA),
|
|
186
|
+
round: RoundSchema,
|
|
187
|
+
seat: ReviewerSeatSchema,
|
|
188
|
+
packet_digest: Sha256Schema,
|
|
189
|
+
candidate_identity: GitObjectIdSchema,
|
|
190
|
+
sign_off: z.object({
|
|
191
|
+
approved: z.boolean(),
|
|
192
|
+
score: z.number().int().min(0).max(10),
|
|
193
|
+
/** Rejected finding ids (from the packet's `rejected` list) this reviewer still considers blocking. */
|
|
194
|
+
blocking_rejected: z.array(FindingIdSchema).max(PP_MAX_FINDINGS_PER_ROUND).optional(),
|
|
195
|
+
}).strict(),
|
|
196
|
+
findings: z.array(PpReviewFindingSchema).max(PP_MAX_FINDINGS_PER_ROUND),
|
|
197
|
+
}).strict();
|
|
198
|
+
/** The packet's `findings_budget_remaining`: what this seat may still report this round. */
|
|
199
|
+
export function findingsBudgetRemaining(findingsFromEarlierSeatsThisRound) {
|
|
200
|
+
return Math.max(0, PP_MAX_FINDINGS_PER_ROUND - findingsFromEarlierSeatsThisRound);
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Validate one reviewer's raw output against its dispatched packet. Any
|
|
204
|
+
* failure makes the seat `failed` (never `withheld`), and a failed seat
|
|
205
|
+
* produces no findings.
|
|
206
|
+
*/
|
|
207
|
+
export function validatePpReview(raw, binding) {
|
|
208
|
+
if (utf8Bytes(raw) > PP_MAX_REVIEW_OUTPUT_BYTES) {
|
|
209
|
+
return { ok: false, reason: "oversize", detail: `reviewer output exceeds ${PP_MAX_REVIEW_OUTPUT_BYTES} bytes` };
|
|
210
|
+
}
|
|
211
|
+
let parsedJson;
|
|
212
|
+
try {
|
|
213
|
+
parsedJson = JSON.parse(raw);
|
|
214
|
+
}
|
|
215
|
+
catch {
|
|
216
|
+
return { ok: false, reason: "invalid_json", detail: "reviewer output is not valid JSON" };
|
|
217
|
+
}
|
|
218
|
+
const parsed = PpReviewSchema.safeParse(parsedJson);
|
|
219
|
+
if (!parsed.success) {
|
|
220
|
+
return { ok: false, reason: "schema", detail: parsed.error.issues.map((issue) => `${issue.path.join(".")}: ${issue.message}`).join("; ").slice(0, 600) };
|
|
221
|
+
}
|
|
222
|
+
const review = parsed.data;
|
|
223
|
+
if (review.round !== binding.round ||
|
|
224
|
+
review.seat !== binding.seat ||
|
|
225
|
+
review.packet_digest !== binding.packetDigest ||
|
|
226
|
+
review.candidate_identity !== binding.candidateIdentity) {
|
|
227
|
+
return { ok: false, reason: "echo_mismatch", detail: "round, seat, packet_digest or candidate_identity does not match the dispatched packet" };
|
|
228
|
+
}
|
|
229
|
+
const blockingRejected = review.sign_off.blocking_rejected ?? [];
|
|
230
|
+
const rejectedIds = new Set(binding.rejectedIds);
|
|
231
|
+
const unknownBlocking = blockingRejected.filter((id) => !rejectedIds.has(id));
|
|
232
|
+
if (unknownBlocking.length > 0) {
|
|
233
|
+
return { ok: false, reason: "schema", detail: `sign_off.blocking_rejected names ids outside the packet's rejected list: ${unknownBlocking.slice(0, 4).join(", ")}` };
|
|
234
|
+
}
|
|
235
|
+
if (review.sign_off.approved && review.findings.some((finding) => finding.severity === "blocker" || finding.severity === "major")) {
|
|
236
|
+
return { ok: false, reason: "self_contradictory", detail: "approved:true with an own blocker or major finding" };
|
|
237
|
+
}
|
|
238
|
+
if (binding.findingsFromEarlierSeatsThisRound + review.findings.length > PP_MAX_FINDINGS_PER_ROUND) {
|
|
239
|
+
return { ok: false, reason: "finding_overflow", detail: `round ${binding.round} would exceed ${PP_MAX_FINDINGS_PER_ROUND} findings` };
|
|
240
|
+
}
|
|
241
|
+
const signedOff = review.sign_off.approved && review.sign_off.score >= binding.signOffThreshold;
|
|
242
|
+
// D-A: a withhold must name what blocks sign-off, unless the round's
|
|
243
|
+
// finding budget is already spent and the reviewer cannot report anything.
|
|
244
|
+
if (!signedOff && review.findings.length === 0 && blockingRejected.length === 0 &&
|
|
245
|
+
findingsBudgetRemaining(binding.findingsFromEarlierSeatsThisRound) > 0) {
|
|
246
|
+
return { ok: false, reason: "unjustified_withhold", detail: "a withheld sign-off cites no finding and no blocking rejected id" };
|
|
247
|
+
}
|
|
248
|
+
const findings = review.findings.map((finding, index) => ({
|
|
249
|
+
id: formatFindingId(binding.round, binding.seat, index + 1),
|
|
250
|
+
round: binding.round,
|
|
251
|
+
seat: binding.seat,
|
|
252
|
+
severity: finding.severity,
|
|
253
|
+
...(finding.path !== undefined ? { path: finding.path } : {}),
|
|
254
|
+
...(finding.line !== undefined ? { line: finding.line } : {}),
|
|
255
|
+
summary: finding.summary,
|
|
256
|
+
detail: finding.detail,
|
|
257
|
+
}));
|
|
258
|
+
return { ok: true, review, outcome: signedOff ? "signed_off" : "withheld", findings };
|
|
259
|
+
}
|
|
260
|
+
// ---------------------------------------------------------------------------
|
|
261
|
+
// Decision input / record / receipt (0-2)
|
|
262
|
+
// ---------------------------------------------------------------------------
|
|
263
|
+
export const PpDecisionSchema = z.object({
|
|
264
|
+
admit: z.array(z.object({ id: FindingIdSchema, rationale: NoteSchema }).strict()).max(PP_MAX_FINDINGS_PER_ROUND).default([]),
|
|
265
|
+
reject: z.array(z.object({ id: FindingIdSchema, reason: NoteSchema }).strict()).max(PP_MAX_FINDINGS_PER_ROUND).default([]),
|
|
266
|
+
audit_requests: z.array(NoteSchema).max(PP_MAX_AUDIT_REQUESTS).default([]),
|
|
267
|
+
stop: z.boolean().default(false),
|
|
268
|
+
}).strict().superRefine((decision, ctx) => {
|
|
269
|
+
if (decision.admit.length + decision.reject.length > PP_MAX_FINDINGS_PER_ROUND) {
|
|
270
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, message: `admit + reject must list at most ${PP_MAX_FINDINGS_PER_ROUND} ids` });
|
|
271
|
+
}
|
|
272
|
+
if (utf8Bytes(canonicalJson(decision)) > PP_MAX_DECISION_BYTES) {
|
|
273
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, message: `decision exceeds ${PP_MAX_DECISION_BYTES} canonical bytes` });
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
export const PpDecisionInputSchema = z.object({
|
|
277
|
+
run_id: RunIdSchema,
|
|
278
|
+
execution_id: ExecutionIdSchema,
|
|
279
|
+
revision: z.number().int().min(1),
|
|
280
|
+
decision: PpDecisionSchema,
|
|
281
|
+
}).strict();
|
|
282
|
+
/** sha256 over the canonical JSON of the parsed (defaults applied) decision. */
|
|
283
|
+
export function decisionDigest(decision) {
|
|
284
|
+
return digest(decision);
|
|
285
|
+
}
|
|
286
|
+
export const PpDecisionReceiptSchema = z.object({
|
|
287
|
+
run_id: RunIdSchema,
|
|
288
|
+
execution_id: ExecutionIdSchema,
|
|
289
|
+
revision: z.number().int().min(1),
|
|
290
|
+
phase: RecipePhaseSchema,
|
|
291
|
+
outcome: RecipeOutcomeSchema.optional(),
|
|
292
|
+
stop_reason: StopReasonSchema.optional(),
|
|
293
|
+
replayed: z.boolean(),
|
|
294
|
+
}).strict();
|
|
295
|
+
export const PpDecisionRecordSchema = z.object({
|
|
296
|
+
source_execution_id: ExecutionIdSchema,
|
|
297
|
+
source_revision: z.number().int().min(1),
|
|
298
|
+
decision_digest: Sha256Schema,
|
|
299
|
+
decision: PpDecisionSchema,
|
|
300
|
+
new_execution_id: ExecutionIdSchema,
|
|
301
|
+
new_revision: z.number().int().min(2),
|
|
302
|
+
next_phase: RecipePhaseSchema,
|
|
303
|
+
stop_reason: StopReasonSchema.optional(),
|
|
304
|
+
recorded_at: IsoTimestampSchema,
|
|
305
|
+
receipt: PpDecisionReceiptSchema,
|
|
306
|
+
}).strict().superRefine((record, ctx) => {
|
|
307
|
+
if (utf8Bytes(canonicalJson(record)) > PP_MAX_DECISION_RECORD_BYTES) {
|
|
308
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, message: `decision record exceeds ${PP_MAX_DECISION_RECORD_BYTES} canonical bytes` });
|
|
309
|
+
}
|
|
310
|
+
if (record.receipt.replayed) {
|
|
311
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, message: "stored receipt must have replayed:false" });
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
// ---------------------------------------------------------------------------
|
|
315
|
+
// recipe-state-v1 sidecar
|
|
316
|
+
// ---------------------------------------------------------------------------
|
|
317
|
+
export const RecipeFindingSchema = z.object({
|
|
318
|
+
id: FindingIdSchema,
|
|
319
|
+
round: RoundSchema,
|
|
320
|
+
seat: ReviewerSeatSchema,
|
|
321
|
+
severity: FindingSeveritySchema,
|
|
322
|
+
path: RelPathSchema.optional(),
|
|
323
|
+
line: z.number().int().min(1).optional(),
|
|
324
|
+
summary: FindingSummarySchema,
|
|
325
|
+
detail: FindingDetailSchema,
|
|
326
|
+
}).strict().superRefine((finding, ctx) => {
|
|
327
|
+
const parsed = parseFindingId(finding.id);
|
|
328
|
+
if (parsed !== undefined && (parsed.round !== finding.round || parsed.seat !== finding.seat)) {
|
|
329
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, message: `finding ${finding.id} does not match round ${finding.round} seat ${finding.seat}` });
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
export const AdmittedFindingSchema = z.object({
|
|
333
|
+
finding: RecipeFindingSchema,
|
|
334
|
+
rationale: NoteSchema,
|
|
335
|
+
decided_revision: z.number().int().min(1),
|
|
336
|
+
}).strict();
|
|
337
|
+
export const RejectedFindingSchema = z.object({
|
|
338
|
+
id: FindingIdSchema,
|
|
339
|
+
reason: NoteSchema,
|
|
340
|
+
decided_revision: z.number().int().min(1),
|
|
341
|
+
/** The rejected finding's summary, so later packets can say what was rejected. Absent on older sidecars. */
|
|
342
|
+
summary: FindingSummarySchema.optional(),
|
|
343
|
+
}).strict();
|
|
344
|
+
export const ReviewerResultSchema = z.object({
|
|
345
|
+
seat: ReviewerSeatSchema,
|
|
346
|
+
outcome: ReviewerOutcomeSchema,
|
|
347
|
+
reason: NoteSchema.optional(),
|
|
348
|
+
score: z.number().int().min(0).max(10).optional(),
|
|
349
|
+
}).strict();
|
|
350
|
+
/** Machine codes a reviewer retry may carry (D-C); never provider text. */
|
|
351
|
+
export const PP_REVIEWER_RETRY_REASONS = [
|
|
352
|
+
"oversize",
|
|
353
|
+
"invalid_json",
|
|
354
|
+
"schema",
|
|
355
|
+
"echo_mismatch",
|
|
356
|
+
"self_contradictory",
|
|
357
|
+
"finding_overflow",
|
|
358
|
+
"unjustified_withhold",
|
|
359
|
+
"provider_error",
|
|
360
|
+
];
|
|
361
|
+
export const RecipeOperationSchema = z.object({
|
|
362
|
+
id: z.string().regex(/^[A-Za-z0-9_.:-]{1,96}$/),
|
|
363
|
+
kind: z.enum(OPERATION_KINDS),
|
|
364
|
+
round: z.number().int().min(0).max(PP_MAX_ROUNDS),
|
|
365
|
+
/** 0 = implementer, 1..4 = reviewer seat; absent for host-only operations. */
|
|
366
|
+
seat: z.number().int().min(0).max(PP_MAX_REVIEWERS).optional(),
|
|
367
|
+
stage_id: z.string().min(1).max(128).optional(),
|
|
368
|
+
call_id: z.string().min(1).max(128).optional(),
|
|
369
|
+
execution_id: ExecutionIdSchema,
|
|
370
|
+
status: OperationStatusSchema,
|
|
371
|
+
intent_at: IsoTimestampSchema,
|
|
372
|
+
result_at: IsoTimestampSchema.optional(),
|
|
373
|
+
/** Bounded, non-sensitive note (for example why an operation is uncertain). */
|
|
374
|
+
note: NoteSchema.optional(),
|
|
375
|
+
/**
|
|
376
|
+
* Reviewer dispatches (rev. 3), recorded with the intent before dispatch:
|
|
377
|
+
* the packet's `packet_digest`, the attempt (2 = the D-C retry) and its
|
|
378
|
+
* retry reason, and the dispatched packet bytes as immutable evidence
|
|
379
|
+
* (`packet_file`, relative to the run dir; `packet_sha256` over its bytes).
|
|
380
|
+
*/
|
|
381
|
+
attempt: z.number().int().min(1).max(2).optional(),
|
|
382
|
+
retry_reason: z.enum(PP_REVIEWER_RETRY_REASONS).optional(),
|
|
383
|
+
packet_digest: Sha256Schema.optional(),
|
|
384
|
+
packet_file: z.string().regex(/^recipe-evidence\/round-[1-9][0-9]?\/review-[A-Za-z0-9_.:-]{1,96}\.json$/).optional(),
|
|
385
|
+
packet_sha256: Sha256Schema.optional(),
|
|
386
|
+
}).strict().superRefine((operation, ctx) => {
|
|
387
|
+
if ((operation.status === "result_recorded") !== (operation.result_at !== undefined)) {
|
|
388
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, message: `operation ${operation.id}: result_at is present exactly when status is result_recorded` });
|
|
389
|
+
}
|
|
390
|
+
const packetFields = [operation.attempt, operation.packet_digest, operation.packet_file, operation.packet_sha256];
|
|
391
|
+
if (packetFields.some((field) => field !== undefined) &&
|
|
392
|
+
(operation.kind !== "reviewer" || packetFields.some((field) => field === undefined))) {
|
|
393
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, message: `operation ${operation.id}: packet evidence is all-or-nothing and reviewer-only` });
|
|
394
|
+
}
|
|
395
|
+
if ((operation.retry_reason !== undefined) !== (operation.attempt === 2)) {
|
|
396
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, message: `operation ${operation.id}: retry_reason is present exactly on attempt 2` });
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
export const RecipeWorktreeSchema = z.object({
|
|
400
|
+
/** `implementer` or `author-<i>` (CONTRACTS C5). */
|
|
401
|
+
seat: z.string().regex(/^(?:implementer|author-[1-9][0-9]?)$/),
|
|
402
|
+
path: AbsPathSchema,
|
|
403
|
+
}).strict();
|
|
404
|
+
export const RoundHistoryEntrySchema = z.object({
|
|
405
|
+
round: RoundSchema,
|
|
406
|
+
/** Candidate identity at the writer's confirmed exit (0-3). */
|
|
407
|
+
candidate_identity: GitObjectIdSchema.optional(),
|
|
408
|
+
/** Byte witness at the same exit; decides whether the next round left the candidate unchanged. */
|
|
409
|
+
candidate_witness: Sha256Schema.optional(),
|
|
410
|
+
/** Normalized digest of the findings (severity, path, summary) the decision on this round admitted, written at decide (no_progress). */
|
|
411
|
+
admitted_findings_digest: Sha256Schema.optional(),
|
|
412
|
+
}).strict();
|
|
413
|
+
/** Bound on recorded per-key digests per config file (the host omits `keys` above it). */
|
|
414
|
+
export const PP_MAX_GIT_METADATA_KEYS = 256;
|
|
415
|
+
const GitMetadataFileSchema = z.object({
|
|
416
|
+
name: z.string().regex(/^(?:common|worktree)\/[a-z./]{1,48}$/),
|
|
417
|
+
path: AbsPathSchema,
|
|
418
|
+
kind: z.enum(["config", "raw"]),
|
|
419
|
+
state: z.enum(["absent", "file", "symlink", "other"]),
|
|
420
|
+
sha256: Sha256Schema.optional(),
|
|
421
|
+
entries_sha256: Sha256Schema.optional(),
|
|
422
|
+
keys: z.record(z.string().min(1).max(1024), Sha256Schema)
|
|
423
|
+
.refine((keys) => Object.keys(keys).length <= PP_MAX_GIT_METADATA_KEYS, `at most ${PP_MAX_GIT_METADATA_KEYS} keys`)
|
|
424
|
+
.optional(),
|
|
425
|
+
}).strict();
|
|
426
|
+
/**
|
|
427
|
+
* D4c shared git-metadata snapshot, taken once at worktree creation and
|
|
428
|
+
* passed back to the host on every later call (never re-taken on resume).
|
|
429
|
+
* Digests only; never config values.
|
|
430
|
+
*/
|
|
431
|
+
export const RecipeGitMetadataSnapshotSchema = z.object({
|
|
432
|
+
version: z.literal(1),
|
|
433
|
+
digest: Sha256Schema,
|
|
434
|
+
files: z.array(GitMetadataFileSchema).max(16),
|
|
435
|
+
}).strict();
|
|
436
|
+
export const AcceptancePinSchema = z.object({
|
|
437
|
+
path: RelPathSchema,
|
|
438
|
+
sha256: Sha256Schema,
|
|
439
|
+
}).strict();
|
|
440
|
+
export const RecipeStateV1Schema = z.object({
|
|
441
|
+
schema: z.literal(RECIPE_STATE_SCHEMA),
|
|
442
|
+
workflow: z.literal(PING_PONG_WORKFLOW),
|
|
443
|
+
run_id: RunIdSchema,
|
|
444
|
+
execution_id: ExecutionIdSchema,
|
|
445
|
+
revision: z.number().int().min(1),
|
|
446
|
+
updated_at: IsoTimestampSchema,
|
|
447
|
+
phase: RecipePhaseSchema,
|
|
448
|
+
outcome: RecipeOutcomeSchema.optional(),
|
|
449
|
+
stop_reason: StopReasonSchema.optional(),
|
|
450
|
+
/**
|
|
451
|
+
* Value-free cause of a stop, e.g. the drifted git metadata file, key
|
|
452
|
+
* names and a remediation hint. Never config values.
|
|
453
|
+
*/
|
|
454
|
+
stop_detail: z.string().min(1).max(PP_MAX_STOP_DETAIL_CHARS).optional(),
|
|
455
|
+
rounds_used: z.number().int().min(0).max(PP_MAX_ROUNDS),
|
|
456
|
+
round_cap: RoundSchema,
|
|
457
|
+
sign_off_threshold: z.number().int().min(0).max(10),
|
|
458
|
+
reviewer_count: z.number().int().min(PP_MIN_REVIEWERS).max(PP_MAX_REVIEWERS),
|
|
459
|
+
active_budget: z.object({
|
|
460
|
+
used_seconds: z.number().finite().min(0),
|
|
461
|
+
limit_seconds: z.number().int().min(1).max(PP_MAX_ACTIVE_BUDGET_SECONDS),
|
|
462
|
+
}).strict(),
|
|
463
|
+
admitted_at: IsoTimestampSchema,
|
|
464
|
+
deadline_at: IsoTimestampSchema,
|
|
465
|
+
awaiting_since: IsoTimestampSchema.optional(),
|
|
466
|
+
baseline: z.object({
|
|
467
|
+
repo_root: AbsPathSchema,
|
|
468
|
+
commit: GitObjectIdSchema,
|
|
469
|
+
uncommitted_changes_excluded: z.boolean().optional(),
|
|
470
|
+
}).strict(),
|
|
471
|
+
/** Tree id of the candidate; reviewers echo it and the delta is computed from it. */
|
|
472
|
+
candidate_identity: GitObjectIdSchema.optional(),
|
|
473
|
+
/**
|
|
474
|
+
* Raw-byte witness of the same snapshot. Sign-off binds to it: any later
|
|
475
|
+
* capture with a different witness voids the round even under an
|
|
476
|
+
* identical tree id. Absent on sidecars written before it existed.
|
|
477
|
+
*/
|
|
478
|
+
candidate_witness: Sha256Schema.optional(),
|
|
479
|
+
worktrees: z.array(RecipeWorktreeSchema).max(PP_MAX_WORKTREES),
|
|
480
|
+
/** Absent on sidecars written before the drift check (no recheck then). */
|
|
481
|
+
git_metadata_snapshot: RecipeGitMetadataSnapshotSchema.optional(),
|
|
482
|
+
acceptance_pins: z.array(AcceptancePinSchema).max(32).default([]),
|
|
483
|
+
operations: z.array(RecipeOperationSchema).max(PP_MAX_OPERATIONS),
|
|
484
|
+
/** Findings awaiting the main agent's decision; kept (undecided) by a stop while awaiting. */
|
|
485
|
+
pending_findings: z.array(RecipeFindingSchema).max(PP_MAX_FINDINGS_PER_ROUND),
|
|
486
|
+
/** Reviewer outcomes of the most recent review round. */
|
|
487
|
+
reviewers: z.array(ReviewerResultSchema).max(PP_MAX_REVIEWERS),
|
|
488
|
+
admitted_findings: z.array(AdmittedFindingSchema).max(PP_MAX_FINDINGS_PER_ROUND * PP_MAX_ROUNDS).default([]),
|
|
489
|
+
rejected_findings: z.array(RejectedFindingSchema).max(PP_MAX_FINDINGS_PER_ROUND * PP_MAX_ROUNDS).default([]),
|
|
490
|
+
/** Findings left unresolved by a terminal stop (round_budget_exhausted, no_progress). */
|
|
491
|
+
unresolved_findings: z.array(FindingIdSchema).max(PP_MAX_FINDINGS_PER_ROUND * PP_MAX_ROUNDS).default([]),
|
|
492
|
+
/** Carried into the next review packet (D4). */
|
|
493
|
+
pending_audit_requests: z.array(NoteSchema).max(PP_MAX_AUDIT_REQUESTS).default([]),
|
|
494
|
+
round_history: z.array(RoundHistoryEntrySchema).max(PP_MAX_ROUNDS).default([]),
|
|
495
|
+
decisions: z.array(PpDecisionRecordSchema).max(PP_MAX_DECISION_RECORDS),
|
|
496
|
+
/** Count of operations without a recorded result; always written. */
|
|
497
|
+
unresolved_operations: z.number().int().min(0),
|
|
498
|
+
/** True only when every seat exit is confirmed (set by cancel paths). */
|
|
499
|
+
effects_stopped: z.boolean().optional(),
|
|
500
|
+
}).strict().superRefine((state, ctx) => {
|
|
501
|
+
const issue = (message) => { ctx.addIssue({ code: z.ZodIssueCode.custom, message }); };
|
|
502
|
+
const unresolved = countUnresolvedOperations(state.operations);
|
|
503
|
+
if (state.unresolved_operations !== unresolved) {
|
|
504
|
+
issue(`unresolved_operations ${state.unresolved_operations} does not match ${unresolved} operations without a result`);
|
|
505
|
+
}
|
|
506
|
+
const terminal = isTerminalRecipePhase(state.phase);
|
|
507
|
+
if (terminal !== (state.outcome !== undefined))
|
|
508
|
+
issue("outcome is present exactly when phase is stopped or qualified");
|
|
509
|
+
if ((state.phase === "qualified") !== (state.outcome === "qualified"))
|
|
510
|
+
issue("phase qualified requires outcome qualified and vice versa");
|
|
511
|
+
if (state.outcome === "cancelled" && state.stop_reason !== "cancelled")
|
|
512
|
+
issue("outcome cancelled requires stop_reason cancelled");
|
|
513
|
+
if (state.outcome === "stopped" && (state.stop_reason === undefined || state.stop_reason === "cancelled")) {
|
|
514
|
+
issue("outcome stopped requires a non-cancel stop_reason");
|
|
515
|
+
}
|
|
516
|
+
if (state.outcome === "qualified" && state.stop_reason !== undefined)
|
|
517
|
+
issue("outcome qualified carries no stop_reason");
|
|
518
|
+
if (state.outcome === undefined && state.stop_reason !== undefined)
|
|
519
|
+
issue("stop_reason requires a terminal outcome");
|
|
520
|
+
if (state.stop_detail !== undefined && state.outcome !== "stopped")
|
|
521
|
+
issue("stop_detail requires outcome stopped");
|
|
522
|
+
if ((state.phase === "awaiting_decision") !== (state.awaiting_since !== undefined)) {
|
|
523
|
+
issue("awaiting_since is present exactly when phase is awaiting_decision");
|
|
524
|
+
}
|
|
525
|
+
// A stop while awaiting (deadline, cancel, capacity) keeps the undecided findings as evidence.
|
|
526
|
+
if (state.phase !== "awaiting_decision" && state.phase !== "stopped" && state.pending_findings.length > 0) {
|
|
527
|
+
issue("pending_findings must be empty outside awaiting_decision and stopped");
|
|
528
|
+
}
|
|
529
|
+
if (state.rounds_used > state.round_cap)
|
|
530
|
+
issue("rounds_used exceeds round_cap");
|
|
531
|
+
if (state.reviewers.some((reviewer) => reviewer.seat > state.reviewer_count))
|
|
532
|
+
issue("reviewer seat exceeds reviewer_count");
|
|
533
|
+
if (new Set(state.reviewers.map((reviewer) => reviewer.seat)).size !== state.reviewers.length)
|
|
534
|
+
issue("reviewer seats must be unique");
|
|
535
|
+
if (new Set(state.pending_findings.map((finding) => finding.id)).size !== state.pending_findings.length) {
|
|
536
|
+
issue("pending finding ids must be unique");
|
|
537
|
+
}
|
|
538
|
+
if (new Set(state.operations.map((operation) => operation.id)).size !== state.operations.length)
|
|
539
|
+
issue("operation ids must be unique");
|
|
540
|
+
const decisionKeys = state.decisions.map((record) => `${record.source_execution_id}\u0000${record.source_revision}`);
|
|
541
|
+
if (new Set(decisionKeys).size !== decisionKeys.length)
|
|
542
|
+
issue("decision records must be unique per (execution_id, revision)");
|
|
543
|
+
if (Date.parse(state.deadline_at) < Date.parse(state.admitted_at))
|
|
544
|
+
issue("deadline_at precedes admitted_at");
|
|
545
|
+
});
|
|
546
|
+
export function countUnresolvedOperations(operations) {
|
|
547
|
+
return operations.filter((operation) => operation.status !== "result_recorded").length;
|
|
548
|
+
}
|
|
549
|
+
/** The fields of a state the store stamps; strip them to edit a committed state as a draft. */
|
|
550
|
+
export function toRecipeStateDraft(state) {
|
|
551
|
+
const { schema: _schema, workflow: _workflow, run_id: _runId, execution_id: _executionId, revision: _revision, updated_at: _updatedAt, unresolved_operations: _unresolved, ...draft } = state;
|
|
552
|
+
return draft;
|
|
553
|
+
}
|
|
554
|
+
/** Every operation without a recorded result becomes `uncertain` (lost response / dead worker). */
|
|
555
|
+
export function markUnresolvedOperationsUncertain(operations, note) {
|
|
556
|
+
return operations.map((operation) => operation.status === "intent_recorded"
|
|
557
|
+
? { ...operation, status: "uncertain", ...(note !== undefined && operation.note === undefined ? { note } : {}) }
|
|
558
|
+
: operation);
|
|
559
|
+
}
|
|
560
|
+
/** A complete `awaiting_decision` checkpoint for this execution with nothing uncertain (reconcile roll-forward). */
|
|
561
|
+
export function isCompleteAwaitingCheckpoint(state, executionId) {
|
|
562
|
+
return executionId !== undefined &&
|
|
563
|
+
state.execution_id === executionId &&
|
|
564
|
+
state.phase === "awaiting_decision" &&
|
|
565
|
+
state.unresolved_operations === 0;
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* Every pending id exactly once across admit/reject; nothing else. A stop
|
|
569
|
+
* may leave pending ids unlisted (they are recorded unresolved), but unknown
|
|
570
|
+
* and duplicate ids are still rejected.
|
|
571
|
+
*/
|
|
572
|
+
export function checkDecisionCompleteness(pending, decision) {
|
|
573
|
+
const pendingIds = new Set(pending.map((finding) => finding.id));
|
|
574
|
+
const listed = [...decision.admit.map((entry) => entry.id), ...decision.reject.map((entry) => entry.id)];
|
|
575
|
+
const seen = new Set();
|
|
576
|
+
const duplicate = new Set();
|
|
577
|
+
const unknown = new Set();
|
|
578
|
+
for (const id of listed) {
|
|
579
|
+
if (seen.has(id))
|
|
580
|
+
duplicate.add(id);
|
|
581
|
+
seen.add(id);
|
|
582
|
+
if (!pendingIds.has(id))
|
|
583
|
+
unknown.add(id);
|
|
584
|
+
}
|
|
585
|
+
const missing = decision.stop ? [] : [...pendingIds].filter((id) => !seen.has(id));
|
|
586
|
+
if (duplicate.size === 0 && unknown.size === 0 && missing.length === 0)
|
|
587
|
+
return { ok: true };
|
|
588
|
+
return { ok: false, unknown: [...unknown].sort(), duplicate: [...duplicate].sort(), missing: missing.sort() };
|
|
589
|
+
}
|
|
590
|
+
/**
|
|
591
|
+
* Order-free digest of a finding multiset over severity, path (as given) and
|
|
592
|
+
* the case- and whitespace-normalized summary, so the same summary on another
|
|
593
|
+
* file or at another severity is a different finding.
|
|
594
|
+
*/
|
|
595
|
+
export function normalizedFindingsDigest(findings) {
|
|
596
|
+
return digest(findings.map((finding) => canonicalJson([
|
|
597
|
+
finding.severity,
|
|
598
|
+
finding.path ?? null,
|
|
599
|
+
finding.summary.toLowerCase().replace(/\s+/g, " ").trim(),
|
|
600
|
+
])).sort());
|
|
601
|
+
}
|
|
602
|
+
/** Digest of the findings this decision admits; undefined when it admits nothing. */
|
|
603
|
+
function admittedFindingsDigest(state, decision) {
|
|
604
|
+
if (decision.admit.length === 0)
|
|
605
|
+
return undefined;
|
|
606
|
+
const pendingById = new Map(state.pending_findings.map((finding) => [finding.id, finding]));
|
|
607
|
+
return normalizedFindingsDigest(decision.admit.map((entry) => pendingById.get(entry.id)));
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* The legal next phase from `awaiting_decision` (CONTRACTS 0-2 table). The
|
|
611
|
+
* caller has already checked completeness, so every admitted id is pending.
|
|
612
|
+
*/
|
|
613
|
+
export function nextPhaseForDecision(state, decision) {
|
|
614
|
+
if (decision.stop)
|
|
615
|
+
return { phase: "stopped", stopReason: "main_agent_stop" };
|
|
616
|
+
if (decision.admit.length > 0) {
|
|
617
|
+
// [3-2] Admitting the same findings as the previous decision (the digest
|
|
618
|
+
// covers severity, path and normalized summary) means the last
|
|
619
|
+
// remediation round fixed nothing the main agent still cares about.
|
|
620
|
+
const previous = state.round_history.find((entry) => entry.round === state.rounds_used - 1)?.admitted_findings_digest;
|
|
621
|
+
if (previous !== undefined && previous === admittedFindingsDigest(state, decision)) {
|
|
622
|
+
return { phase: "stopped", stopReason: "no_progress" };
|
|
623
|
+
}
|
|
624
|
+
return state.rounds_used < state.round_cap
|
|
625
|
+
? { phase: "remediating" }
|
|
626
|
+
: { phase: "stopped", stopReason: "round_budget_exhausted" };
|
|
627
|
+
}
|
|
628
|
+
if (state.reviewers.length === state.reviewer_count && state.reviewers.every((reviewer) => reviewer.outcome === "signed_off")) {
|
|
629
|
+
return { phase: "final_verifying" };
|
|
630
|
+
}
|
|
631
|
+
if (state.reviewers.some((reviewer) => reviewer.outcome === "failed") || state.reviewers.length < state.reviewer_count) {
|
|
632
|
+
return { phase: "stopped", stopReason: "seat_unavailable" };
|
|
633
|
+
}
|
|
634
|
+
return { phase: "stopped", stopReason: "no_sign_off" };
|
|
635
|
+
}
|
|
636
|
+
/**
|
|
637
|
+
* Apply a validated decision to an `awaiting_decision` state: findings move to
|
|
638
|
+
* admitted/rejected, audit requests are queued, and the phase advances. A stop
|
|
639
|
+
* produces a terminal draft (outcome `stopped`).
|
|
640
|
+
*/
|
|
641
|
+
export function applyDecisionToDraft(state, decision, transition) {
|
|
642
|
+
const pendingById = new Map(state.pending_findings.map((finding) => [finding.id, finding]));
|
|
643
|
+
const admitted = decision.admit.map((entry) => ({
|
|
644
|
+
finding: pendingById.get(entry.id),
|
|
645
|
+
rationale: entry.rationale,
|
|
646
|
+
decided_revision: state.revision,
|
|
647
|
+
}));
|
|
648
|
+
const rejected = decision.reject.map((entry) => {
|
|
649
|
+
const summary = pendingById.get(entry.id)?.summary;
|
|
650
|
+
return {
|
|
651
|
+
id: entry.id,
|
|
652
|
+
reason: entry.reason,
|
|
653
|
+
decided_revision: state.revision,
|
|
654
|
+
...(summary !== undefined ? { summary } : {}),
|
|
655
|
+
};
|
|
656
|
+
});
|
|
657
|
+
const draft = toRecipeStateDraft(state);
|
|
658
|
+
const { awaiting_since: _awaitingSince, ...rest } = draft;
|
|
659
|
+
const admittedDigest = admittedFindingsDigest(state, decision);
|
|
660
|
+
const decidedRound = state.round_history.find((entry) => entry.round === state.rounds_used) ?? { round: state.rounds_used };
|
|
661
|
+
const next = {
|
|
662
|
+
...rest,
|
|
663
|
+
phase: transition.phase,
|
|
664
|
+
pending_findings: [],
|
|
665
|
+
admitted_findings: [...(state.admitted_findings ?? []), ...admitted],
|
|
666
|
+
rejected_findings: [...(state.rejected_findings ?? []), ...rejected],
|
|
667
|
+
pending_audit_requests: transition.phase === "stopped" ? [] : decision.audit_requests,
|
|
668
|
+
// The next decision compares its admitted set against this one ([3-2]).
|
|
669
|
+
...(admittedDigest !== undefined && state.rounds_used >= 1
|
|
670
|
+
? {
|
|
671
|
+
round_history: [
|
|
672
|
+
...state.round_history.filter((entry) => entry.round !== state.rounds_used),
|
|
673
|
+
{ ...decidedRound, admitted_findings_digest: admittedDigest },
|
|
674
|
+
].sort((a, b) => a.round - b.round),
|
|
675
|
+
}
|
|
676
|
+
: {}),
|
|
677
|
+
};
|
|
678
|
+
if (transition.phase === "stopped") {
|
|
679
|
+
next.outcome = "stopped";
|
|
680
|
+
next.stop_reason = transition.stopReason;
|
|
681
|
+
if (transition.stopReason === "round_budget_exhausted" || transition.stopReason === "no_progress") {
|
|
682
|
+
next.unresolved_findings = [...(state.unresolved_findings ?? []), ...admitted.map((entry) => entry.finding.id)];
|
|
683
|
+
}
|
|
684
|
+
if (transition.stopReason === "main_agent_stop") {
|
|
685
|
+
// A stop need not adjudicate every finding; the unlisted ones stay
|
|
686
|
+
// unresolved and keep their bodies as evidence (as a deadline stop
|
|
687
|
+
// does). They were already in the awaiting state, so the terminal
|
|
688
|
+
// write grows only by ids, rationales and reasons.
|
|
689
|
+
const listed = new Set([...decision.admit.map((entry) => entry.id), ...decision.reject.map((entry) => entry.id)]);
|
|
690
|
+
const unlisted = state.pending_findings.filter((finding) => !listed.has(finding.id));
|
|
691
|
+
next.pending_findings = unlisted;
|
|
692
|
+
if (unlisted.length > 0)
|
|
693
|
+
next.unresolved_findings = [...(state.unresolved_findings ?? []), ...unlisted.map((finding) => finding.id)];
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
return next;
|
|
697
|
+
}
|
|
698
|
+
/** Terminal stop draft from any non-terminal state (control executions: deadline, cancel, capacity). */
|
|
699
|
+
export function terminalStopDraft(state, stopReason, options = {}) {
|
|
700
|
+
// A detail explains its own stop only; never carry it onto another reason.
|
|
701
|
+
const { awaiting_since: _awaitingSince, stop_detail: _stopDetail, ...rest } = toRecipeStateDraft(state);
|
|
702
|
+
const outcome = options.outcome ?? (stopReason === "cancelled" ? "cancelled" : "stopped");
|
|
703
|
+
return {
|
|
704
|
+
...rest,
|
|
705
|
+
phase: "stopped",
|
|
706
|
+
outcome,
|
|
707
|
+
stop_reason: stopReason,
|
|
708
|
+
pending_audit_requests: [],
|
|
709
|
+
...(options.effectsStopped !== undefined ? { effects_stopped: options.effectsStopped } : {}),
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
export function projectRecipeStatusBlock(state, now = Date.now()) {
|
|
713
|
+
const awaiting = state.phase === "awaiting_decision";
|
|
714
|
+
const deadlineExpired = awaiting && now >= Date.parse(state.deadline_at);
|
|
715
|
+
return {
|
|
716
|
+
execution_id: state.execution_id,
|
|
717
|
+
revision: state.revision,
|
|
718
|
+
phase: state.phase,
|
|
719
|
+
...(state.outcome !== undefined ? { outcome: state.outcome } : {}),
|
|
720
|
+
...(state.stop_reason !== undefined ? { stop_reason: state.stop_reason } : {}),
|
|
721
|
+
...(state.stop_detail !== undefined ? { stop_detail: state.stop_detail } : {}),
|
|
722
|
+
rounds_used: state.rounds_used,
|
|
723
|
+
round_cap: state.round_cap,
|
|
724
|
+
active_budget_remaining_seconds: Math.max(0, Math.floor(state.active_budget.limit_seconds - state.active_budget.used_seconds)),
|
|
725
|
+
deadline_at: state.deadline_at,
|
|
726
|
+
...(deadlineExpired ? { deadline_expired: true } : {}),
|
|
727
|
+
awaiting_decision: awaiting,
|
|
728
|
+
...(state.awaiting_since !== undefined ? { awaiting_since: state.awaiting_since } : {}),
|
|
729
|
+
...(awaiting
|
|
730
|
+
? {
|
|
731
|
+
pending_findings: state.pending_findings.map((finding) => ({
|
|
732
|
+
id: finding.id,
|
|
733
|
+
seat: finding.seat,
|
|
734
|
+
severity: finding.severity,
|
|
735
|
+
...(finding.path !== undefined ? { path: finding.path } : {}),
|
|
736
|
+
...(finding.line !== undefined ? { line: finding.line } : {}),
|
|
737
|
+
summary: finding.summary,
|
|
738
|
+
detail: finding.detail,
|
|
739
|
+
})),
|
|
740
|
+
}
|
|
741
|
+
: {}),
|
|
742
|
+
reviewers: state.reviewers.map((reviewer) => ({
|
|
743
|
+
seat: reviewer.seat,
|
|
744
|
+
outcome: reviewer.outcome,
|
|
745
|
+
...(reviewer.reason !== undefined ? { reason: reviewer.reason } : {}),
|
|
746
|
+
...(reviewer.score !== undefined ? { score: reviewer.score } : {}),
|
|
747
|
+
})),
|
|
748
|
+
sign_off_threshold: state.sign_off_threshold,
|
|
749
|
+
unresolved_operations: state.unresolved_operations,
|
|
750
|
+
...(state.effects_stopped !== undefined ? { effects_stopped: state.effects_stopped } : {}),
|
|
751
|
+
...(state.candidate_identity !== undefined ? { candidate_identity: state.candidate_identity } : {}),
|
|
752
|
+
...(state.baseline.uncommitted_changes_excluded !== undefined
|
|
753
|
+
? { baseline_uncommitted_changes_excluded: state.baseline.uncommitted_changes_excluded }
|
|
754
|
+
: {}),
|
|
755
|
+
worktrees: state.worktrees.map((worktree) => ({ seat: worktree.seat, path: worktree.path })),
|
|
756
|
+
};
|
|
757
|
+
}
|
|
758
|
+
// ---------------------------------------------------------------------------
|
|
759
|
+
// Admission facts and seat plan (3-1, 3-12, D1)
|
|
760
|
+
// ---------------------------------------------------------------------------
|
|
761
|
+
/** Server-materialized variables; covered by the inputs snapshot hash, never caller-supplied. */
|
|
762
|
+
export const PP_SEAT_PLAN_VARIABLE = "pp_seat_plan";
|
|
763
|
+
export const PP_ADMISSION_VARIABLE = "pp_admission";
|
|
764
|
+
const PpRouteSchema = z.object({
|
|
765
|
+
cli_name: z.string().min(1).max(64),
|
|
766
|
+
model: z.string().min(1).max(256).optional(),
|
|
767
|
+
effort: z.string().min(1).max(64).optional(),
|
|
768
|
+
}).strict();
|
|
769
|
+
export const PpSeatPlanSchema = z.object({
|
|
770
|
+
schema_version: z.literal("pp-seats-v1"),
|
|
771
|
+
implementer: PpRouteSchema,
|
|
772
|
+
reviewers: z.array(PpRouteSchema).min(PP_MIN_REVIEWERS).max(PP_MAX_REVIEWERS),
|
|
773
|
+
}).strict();
|
|
774
|
+
/** Repository-relative path without traversal (the verifier's RelativeFile rule). */
|
|
775
|
+
export const PpRelativeFileSchema = z.string().min(1).max(512).refine((value) => !value.includes("\\") && !value.startsWith("/") && !/[\u0000-\u001f\u007f]/.test(value) &&
|
|
776
|
+
value.split("/").every((part) => part !== "" && part !== "." && part !== ".."), "expected a repository-relative path without traversal");
|
|
777
|
+
export const PpAdmissionSchema = z.object({
|
|
778
|
+
schema_version: z.literal("pp-admission-v1"),
|
|
779
|
+
repo_root: AbsPathSchema,
|
|
780
|
+
baseline_commit: GitObjectIdSchema,
|
|
781
|
+
/** HEAD was pinned; uncommitted changes in the source checkout are not in the candidate. */
|
|
782
|
+
baseline_uncommitted_changes_excluded: z.boolean(),
|
|
783
|
+
rounds: RoundSchema,
|
|
784
|
+
sign_off_threshold: z.number().int().min(0).max(10),
|
|
785
|
+
active_budget_seconds: z.number().int().min(1).max(PP_MAX_ACTIVE_BUDGET_SECONDS),
|
|
786
|
+
admitted_at: IsoTimestampSchema,
|
|
787
|
+
deadline_at: IsoTimestampSchema,
|
|
788
|
+
acceptance_manifest: PpRelativeFileSchema,
|
|
789
|
+
copy_preparation_manifest: PpRelativeFileSchema.optional(),
|
|
790
|
+
acceptance_inputs: z.array(PpRelativeFileSchema).max(30),
|
|
791
|
+
/**
|
|
792
|
+
* D-B: preflight reads the implementer worktree (the baseline), never the
|
|
793
|
+
* live checkout. `worktree` is the path `createWorkspace` must produce;
|
|
794
|
+
* each caller anchor under the repository is recorded with its rebased
|
|
795
|
+
* path (`original` is absent for the default root).
|
|
796
|
+
*/
|
|
797
|
+
context_roots: z.object({
|
|
798
|
+
worktree: AbsPathSchema,
|
|
799
|
+
roots: z.array(z.object({ original: z.string().min(1).max(4096).optional(), rebased: AbsPathSchema }).strict()).min(1).max(8),
|
|
800
|
+
focus_paths: z.array(z.object({ original: AbsPathSchema, rebased: AbsPathSchema }).strict()).max(200),
|
|
801
|
+
}).strict().optional(),
|
|
802
|
+
}).strict();
|
|
803
|
+
/** Terminal record output (`record` reducer); advisory projection of the sidecar. */
|
|
804
|
+
export const PpRecordSchema = z.object({
|
|
805
|
+
schema: z.literal("pp-record-v1"),
|
|
806
|
+
run_id: RunIdSchema,
|
|
807
|
+
outcome: RecipeOutcomeSchema,
|
|
808
|
+
stop_reason: StopReasonSchema.optional(),
|
|
809
|
+
rounds_used: z.number().int().min(0).max(PP_MAX_ROUNDS),
|
|
810
|
+
round_cap: RoundSchema,
|
|
811
|
+
baseline_commit: GitObjectIdSchema,
|
|
812
|
+
candidate_identity: GitObjectIdSchema.optional(),
|
|
813
|
+
worktree: AbsPathSchema,
|
|
814
|
+
unresolved_operations: z.number().int().min(0),
|
|
815
|
+
unresolved_findings: z.array(FindingIdSchema).max(PP_MAX_FINDINGS_PER_ROUND * PP_MAX_ROUNDS),
|
|
816
|
+
final_verification: z.enum(["passed", "failed", "not_run"]),
|
|
817
|
+
}).strict();
|
|
818
|
+
export const PP_MAX_RECORD_BYTES = 32 * 1024;
|
|
819
|
+
//# sourceMappingURL=contract.js.map
|