archctx-contracts 0.11.4 → 0.13.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.
Files changed (45) hide show
  1. package/fixtures/invalid/hook-debt-checkpoint-failed-read.json +6 -1
  2. package/fixtures/valid/archctx-capabilities.json +1 -1
  3. package/fixtures/valid/architecture-state-machine.json +158 -0
  4. package/fixtures/valid/hook-debt-checkpoint.json +6 -1
  5. package/fixtures/valid/product-version-manifest.json +5 -9
  6. package/fixtures/valid/state-machine-check.json +76 -0
  7. package/package.json +1 -1
  8. package/schemas/repo/architecture-state-machine.schema.json +153 -0
  9. package/schemas/runtime/architecture-debt.schema.json +6 -3
  10. package/schemas/runtime/product-version-manifest.schema.json +2 -6
  11. package/schemas/runtime/state-machine-check.schema.json +163 -0
  12. package/src/architecture-debt.ts +2 -2
  13. package/src/failure.ts +17 -11
  14. package/src/index.ts +2 -2
  15. package/src/ports.ts +0 -35
  16. package/src/product-version.ts +1 -9
  17. package/src/review-guards.ts +90 -0
  18. package/src/schema.ts +0 -2
  19. package/src/state-machine.ts +275 -0
  20. package/src/validator.ts +7 -0
  21. package/fixtures/boundary/attestation-v2-error.json +0 -43
  22. package/fixtures/boundary/check-delivery-dead-letter.json +0 -14
  23. package/fixtures/boundary/review-challenge-v2-organization.json +0 -15
  24. package/fixtures/boundary/runner-identity-organization-scope.json +0 -16
  25. package/fixtures/invalid/attestation-v2-finding-field.json +0 -39
  26. package/fixtures/invalid/check-delivery-legacy-check-name.json +0 -14
  27. package/fixtures/invalid/review-challenge-v2-private-field.json +0 -16
  28. package/fixtures/valid/attestation-v2.json +0 -38
  29. package/fixtures/valid/attestation.json +0 -25
  30. package/fixtures/valid/check-delivery.json +0 -14
  31. package/fixtures/valid/device-identity.json +0 -10
  32. package/fixtures/valid/governance-key-status.json +0 -11
  33. package/fixtures/valid/org-runner-identity.json +0 -10
  34. package/fixtures/valid/review-challenge-v2.json +0 -15
  35. package/fixtures/valid/runner-identity.json +0 -13
  36. package/schemas/cloud/attestation-v2.schema.json +0 -85
  37. package/schemas/cloud/attestation.schema.json +0 -49
  38. package/schemas/cloud/check-delivery.schema.json +0 -25
  39. package/schemas/cloud/device-identity.schema.json +0 -18
  40. package/schemas/cloud/governance-key-status.schema.json +0 -19
  41. package/schemas/cloud/org-runner-identity.schema.json +0 -21
  42. package/schemas/cloud/review-challenge-v2.schema.json +0 -23
  43. package/schemas/cloud/runner-identity.schema.json +0 -42
  44. package/src/control-plane-routes.ts +0 -35
  45. package/src/github-governance.ts +0 -850
@@ -0,0 +1,163 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://archcontext.dev/schemas/runtime/state-machine-check.schema.json",
4
+ "title": "StateMachineCheckV1",
5
+ "description": "The data of `archctx state-machines check`: for every declared state machine, the size of its reachable global state space, the result of each declared rule, the built-in breaks and the status of each code anchor. The same model gives the same bytes.",
6
+ "type": "object",
7
+ "additionalProperties": false,
8
+ "required": ["schemaVersion", "machines"],
9
+ "properties": {
10
+ "schemaVersion": { "const": "archcontext.state-machine-check/v1" },
11
+ "machines": {
12
+ "description": "Sorted by machine id.",
13
+ "type": "array",
14
+ "items": {
15
+ "type": "object",
16
+ "additionalProperties": false,
17
+ "required": ["id", "capabilityId", "reachableStates", "transitions", "rules", "breaks", "anchors"],
18
+ "properties": {
19
+ "id": { "type": "string", "pattern": "^state-machine\\.[a-z][a-z0-9-]*(\\.[a-z0-9][a-z0-9-]*)*$" },
20
+ "capabilityId": { "type": "string", "pattern": "^capability\\.[a-z][a-z0-9-]*(\\.[a-z0-9][a-z0-9-]*)*$" },
21
+ "reachableStates": { "type": "integer", "minimum": 1 },
22
+ "transitions": { "type": "integer", "minimum": 0, "description": "Pairs of a reachable global state and an enabled step that changes it." },
23
+ "rules": {
24
+ "description": "In declaration order.",
25
+ "type": "array",
26
+ "items": {
27
+ "type": "object",
28
+ "additionalProperties": false,
29
+ "required": ["id", "kind", "status"],
30
+ "properties": {
31
+ "id": { "$ref": "#/$defs/localId" },
32
+ "kind": { "enum": ["never", "final"] },
33
+ "status": { "enum": ["holds", "broken", "finding-open", "finding-resolved"] },
34
+ "tracking": { "type": "string", "pattern": "^https://[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?(?:\\.[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?)*(?::[0-9]{1,5})?(?:[/?#][^\\s]*)?$" },
35
+ "state": { "$ref": "#/$defs/globalState" },
36
+ "path": { "$ref": "#/$defs/path" },
37
+ "protectedBy": {
38
+ "description": "The guards whose removal breaks this holding rule, in declaration order of the guards.",
39
+ "type": "array",
40
+ "items": {
41
+ "type": "object",
42
+ "additionalProperties": false,
43
+ "required": ["event", "step", "region"],
44
+ "properties": {
45
+ "event": { "$ref": "#/$defs/localId" },
46
+ "step": { "$ref": "#/$defs/stepIndex" },
47
+ "region": { "$ref": "#/$defs/localId" }
48
+ }
49
+ }
50
+ }
51
+ },
52
+ "allOf": [
53
+ {
54
+ "if": { "properties": { "status": { "enum": ["broken", "finding-open"] } } },
55
+ "then": { "required": ["state", "path"], "not": { "required": ["protectedBy"] } },
56
+ "else": { "not": { "anyOf": [{ "required": ["state"] }, { "required": ["path"] }] } }
57
+ },
58
+ {
59
+ "if": { "properties": { "status": { "enum": ["finding-open", "finding-resolved"] } } },
60
+ "then": { "required": ["tracking"] },
61
+ "else": { "not": { "required": ["tracking"] } }
62
+ }
63
+ ]
64
+ }
65
+ },
66
+ "breaks": {
67
+ "description": "Every unreachable state, then every dead step, each in declaration order, then at most one deadlock.",
68
+ "type": "array",
69
+ "items": {
70
+ "oneOf": [
71
+ {
72
+ "type": "object",
73
+ "additionalProperties": false,
74
+ "required": ["kind", "region", "state"],
75
+ "properties": {
76
+ "kind": { "const": "unreachable-state" },
77
+ "region": { "$ref": "#/$defs/localId" },
78
+ "state": { "$ref": "#/$defs/localId" }
79
+ }
80
+ },
81
+ {
82
+ "type": "object",
83
+ "additionalProperties": false,
84
+ "required": ["kind", "event", "step"],
85
+ "properties": {
86
+ "kind": { "const": "dead-step" },
87
+ "event": { "$ref": "#/$defs/localId" },
88
+ "step": { "$ref": "#/$defs/stepIndex" }
89
+ }
90
+ },
91
+ {
92
+ "type": "object",
93
+ "additionalProperties": false,
94
+ "required": ["kind", "state", "path", "count"],
95
+ "properties": {
96
+ "kind": { "const": "deadlock" },
97
+ "state": { "$ref": "#/$defs/globalState" },
98
+ "path": { "$ref": "#/$defs/path" },
99
+ "count": { "type": "integer", "minimum": 1, "description": "The number of deadlocked reachable global states." }
100
+ }
101
+ }
102
+ ]
103
+ }
104
+ },
105
+ "anchors": {
106
+ "description": "Every code source of a region or an event, regions first, then events, each in declaration order, with its status against the current file.",
107
+ "type": "array",
108
+ "items": {
109
+ "type": "object",
110
+ "additionalProperties": false,
111
+ "required": ["owner", "ownerId", "path", "status"],
112
+ "properties": {
113
+ "owner": { "enum": ["region", "event"] },
114
+ "ownerId": { "$ref": "#/$defs/localId" },
115
+ "path": { "type": "string", "minLength": 1 },
116
+ "symbol": { "type": "string", "minLength": 1 },
117
+ "status": { "enum": ["anchor-missing-path", "anchor-language-unsupported", "anchor-missing-symbol", "anchor-ambiguous-symbol", "unchecked", "anchor-unconfirmed", "anchor-changed", "confirmed"] },
118
+ "digest": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$", "description": "The file content, or the lines of the one matching declaration, with CRLF read as LF." },
119
+ "reason": { "enum": ["index-missing", "index-open-failed"], "description": "Why the symbol reader is unavailable." }
120
+ },
121
+ "allOf": [
122
+ {
123
+ "if": { "properties": { "status": { "enum": ["anchor-unconfirmed", "anchor-changed", "confirmed"] } } },
124
+ "then": { "required": ["digest"] },
125
+ "else": { "not": { "required": ["digest"] } }
126
+ },
127
+ {
128
+ "if": { "properties": { "status": { "const": "unchecked" } } },
129
+ "then": { "required": ["reason", "symbol"] },
130
+ "else": { "not": { "required": ["reason"] } }
131
+ }
132
+ ]
133
+ }
134
+ }
135
+ }
136
+ }
137
+ }
138
+ },
139
+ "$defs": {
140
+ "localId": { "type": "string", "pattern": "^[a-z][a-z0-9]*(-[a-z0-9]+)*$" },
141
+ "stepIndex": { "type": "integer", "minimum": 1, "description": "The 1-based index of the step in its event." },
142
+ "globalState": {
143
+ "description": "One state per region, keyed by region id in declaration order.",
144
+ "type": "object",
145
+ "minProperties": 1,
146
+ "propertyNames": { "$ref": "#/$defs/localId" },
147
+ "additionalProperties": { "$ref": "#/$defs/localId" }
148
+ },
149
+ "path": {
150
+ "description": "The shortest sequence of fired steps from the initial global state.",
151
+ "type": "array",
152
+ "items": {
153
+ "type": "object",
154
+ "additionalProperties": false,
155
+ "required": ["event", "step"],
156
+ "properties": {
157
+ "event": { "$ref": "#/$defs/localId" },
158
+ "step": { "$ref": "#/$defs/stepIndex" }
159
+ }
160
+ }
161
+ }
162
+ }
163
+ }
@@ -2,9 +2,9 @@ import { digestJson, type ArchContextError, type Json } from "./schema";
2
2
 
3
3
  /** Measured architecture work, distinct from generated-file freshness and source byte stamps. */
4
4
  export const ARCHITECTURE_DEBT_SCHEMA_VERSION = "archcontext.architecture-debt/v1" as const;
5
- export const ARCHITECTURE_DEBT_KINDS = ["unowned-path", "ambiguous-owner", "undeclared-dependency", "flow-proof-failed", "stale-anchor", "practice-regression"] as const;
5
+ export const ARCHITECTURE_DEBT_KINDS = ["unowned-path", "ambiguous-owner", "undeclared-dependency", "flow-proof-failed", "stale-anchor", "practice-regression", "state-machine-rule", "state-machine-stale"] as const;
6
6
  export type ArchitectureDebtKind = typeof ARCHITECTURE_DEBT_KINDS[number];
7
- export const ARCHITECTURE_DEBT_CHECKS = ["ownership", "anchors", "dependencies", "flows", "practices"] as const;
7
+ export const ARCHITECTURE_DEBT_CHECKS = ["ownership", "anchors", "dependencies", "flows", "state-machines", "practices"] as const;
8
8
  export type ArchitectureDebtCheck = typeof ARCHITECTURE_DEBT_CHECKS[number];
9
9
 
10
10
  export interface ArchitectureDebtItemV1 {
package/src/failure.ts CHANGED
@@ -8,7 +8,7 @@ import { ERROR_CATALOG, canonicalize, isRepoRelativePosixPath, type ArchContextE
8
8
 
9
9
  /** Only selected entrypoints support transport failures; the legacy AC-only envelope is unchanged. */
10
10
  export type FailureCode = ArchContextErrorCode | "RPC_TIMEOUT" | "RPC_ABORTED";
11
- export const FAILURE_STAGES = Object.freeze(["debt", "complete", "practice-checkpoint", "cli", "mcp", "hook-checkpoint", "failure-metadata", "public-operation", "native-export", "docs-anchors", "flows-check"] as const);
11
+ export const FAILURE_STAGES = Object.freeze(["debt", "complete", "practice-checkpoint", "cli", "mcp", "hook-checkpoint", "failure-metadata", "public-operation", "native-export", "docs-anchors", "flows-check", "state-machines-check"] as const);
12
12
  export type FailureStage = typeof FAILURE_STAGES[number];
13
13
  const ERROR_CLASSES = Object.freeze(["Error", "TypeError", "RangeError", "SyntaxError", "ReferenceError", "URIError", "EvalError", "AggregateError", "NonError"]);
14
14
  export interface StrictFailure<C extends FailureCode = FailureCode> {
@@ -55,6 +55,7 @@ const policies: Record<string, Policy> = {
55
55
  "changed-path-invalid": { code: "AC_SCHEMA_INVALID", message: "Changed paths must be an array of repository-relative POSIX paths.", fields: ["checks"] },
56
56
  "debt-report-invalid": { code: "AC_SCHEMA_INVALID", message: "Architecture debt evidence violates its contract.", fields: ["checks"] },
57
57
  "projection-manifest-upgrade-required": { code: "AC_PRECONDITION_FAILED", message: `The committed projection manifest requires supported re-baselining. First restore the original model if missing; the manifest digest cannot recover it. With the reviewed model available, follow ${ARCHITECTURE_DOCS_PROJECTION_MANIFEST_MIGRATION_GUIDE} before running ${ARCHITECTURE_DOCS_PROJECTION_MANIFEST_UPGRADE_COMMAND}.`, facts: { manifestPath: "optional:projectionManifestPath", foundSchemaVersion: "optional:projectionManifestSchemaVersion", supportedSchemaVersion: "optional:projectionManifestSchemaVersion", upgradeCommand: "optional:projectionManifestUpgradeCommand", migrationGuide: "optional:projectionManifestMigrationGuide" } },
58
+ "projection-writer-base-moved": { code: "AC_PRECONDITION_FAILED", message: "The remote base no longer points at the requested commit.", retryable: true, facts: { expectedBaseSha: "head", actualBaseSha: "head" } },
58
59
  "projection-manifest-invalid": { code: "AC_PRECONDITION_FAILED", message: "The committed projection manifest violates its contract." },
59
60
  "architecture-model-ignored": { code: "AC_PRECONDITION_FAILED", action: "commit-architecture-model", message: "Git ignore rules exclude architecture model paths, so the model cannot be committed and a manifest digest cannot rebuild it. Remove or narrow the rule, commit the model, then retry adoption. The diagnostic command prints each deciding rule.", facts: { pathCount: "uint", paths: "optional:diagnosticPaths", commands: "optional:diagnosticCommands", omittedPathCount: "uint" } },
60
61
  "projection-footprint-uncovered": { code: "AC_PRECONDITION_FAILED", message: "Declared source footprints lack a projection target." },
@@ -63,6 +64,7 @@ const policies: Record<string, Policy> = {
63
64
  "checkpoint-input-invalid": { code: "AC_SCHEMA_INVALID", message: "Checkpoint arguments violate the declared input schema.", fields: ["issueCount"], action: "correct-command-arguments" },
64
65
  "cli-input-invalid": { code: "AC_SCHEMA_INVALID", message: "Command arguments violate the declared input contract.", action: "correct-command-arguments" },
65
66
  "constraint-model-invalid": { code: "AC_SCHEMA_INVALID", message: "Dependency constraint declarations are invalid.", facts: { issueCount: "uint" }, action: "repair-constraint-declarations" },
67
+ "state-machine-model-invalid": { code: "AC_SCHEMA_INVALID", message: "State machine declarations are invalid. Run archctx validate --json for the full list of issues.", facts: { issues: "stateMachineIssues", issueCount: "uint", omittedCount: "uint" }, action: "repair-state-machine-declarations" },
66
68
  "complete-input-invalid": { code: "AC_SCHEMA_INVALID", message: "Completion input violates the caller authority contract.", action: "correct-command-arguments" },
67
69
  "hook-event-invalid": { code: "AC_SCHEMA_INVALID", message: "Hook event violates the declared input contract.", action: "correct-command-arguments" },
68
70
  "egress-policy-denied": { code: "AC_POLICY_VIOLATION", message: "Local policy refused this operation." },
@@ -73,14 +75,8 @@ const policies: Record<string, Policy> = {
73
75
  };
74
76
  // C1 policies are selected at explicit producer branches, never from diagnostic text.
75
77
  Object.assign(policies, {
76
- "developer-review-run-not-owned": {code:"AC_PRECONDITION_FAILED",message:"developer-review-run-not-owned",facts:{refusal:"reviewOwnershipRefusal"}},
77
- "developer-review-attestation-input-invalid": {code:"AC_SCHEMA_INVALID",message:"Caller-provided attestation fields are forbidden.",facts:{issueCount:"uint"}},
78
78
  "init-would-overwrite-existing-model": {"code": "AC_PRECONDITION_FAILED", "message": "init-would-overwrite-existing-model: an existing architecture model must not be overwritten.", "facts": {}},
79
79
  "waiver-list-unreadable": {"code": "AC_SCHEMA_INVALID", "message": "Practice waiver list or owner registry could not be read.", "facts": {}},
80
- "developer-review-run-already-active": {"code": "AC_PRECONDITION_FAILED", "message": "developer-review-run-already-active", "facts": {"challengeId": "id"}},
81
- "developer-review-run-prepare-failed": {"code": "AC_PRECONDITION_FAILED", "message": "developer-review-run-prepare-failed", "facts": {}},
82
- "developer-review-worktree-invalid": {"code": "AC_PRECONDITION_FAILED", "message": "developer-review-worktree-invalid", "facts": {"refusal":"reviewWorktreeRefusal"}},
83
- "device-private-key-signer-unavailable": {"code": "AC_PRECONDITION_FAILED", "message": "device-private-key-signer-unavailable", "facts": {}},
84
80
 
85
81
  "ledger-worktree-claim-required": {code:"AC_PRECONDITION_FAILED", message:"Ledger write requires expectedWorktreeDigest.", facts:{}},
86
82
  "ledger-worktree-claim-changed": {code:"AC_PRECONDITION_FAILED", message:"Worktree digest changed before ledger write.", facts:{expectedWorktreeDigest:"sha256",actualWorktreeDigest:"sha256"}},
@@ -233,6 +229,7 @@ Object.assign(policies, {
233
229
  "refactor-decision-approval-required": {"code": "AC_USER_CONFIRMATION_REQUIRED","message": "Refactor decision approval required.","facts": {"recommendationId": "id"}},
234
230
  "jobs-input-invalid": {"code": "AC_SCHEMA_INVALID","message": "Jobs input invalid.","facts": {"field":"optional:jobsField"}},
235
231
  "job-running-required": {"code": "AC_PRECONDITION_FAILED","message": "Job running required.","facts": {"jobId": "id"}},
232
+ "job-transition-invalid": {"code": "AC_PRECONDITION_FAILED","message": "Job transition invalid.","facts": {"jobId": "id"}},
236
233
  "job-context-stale": {"code": "AC_CONTEXT_STALE","message": "Job context stale.","facts": {"jobId": "id","expectedHeadSha": "head","actualHeadSha": "head","expectedWorktreeDigest": "sha256","actualWorktreeDigest": "sha256"}},
237
234
  "audit-disabled": {"code": "AC_CAPABILITY_UNSUPPORTED","message": "Audit disabled.","facts": {}},
238
235
  "audit-active": {"code": "AC_PRECONDITION_FAILED","message": "Audit active.","facts": {}},
@@ -380,8 +377,6 @@ function dataRecord(value: unknown): Record<string, PropertyDescriptor> {
380
377
  return fields;
381
378
  }
382
379
  const localEnums: Readonly<Record<string, readonly string[]>> = {
383
- reviewWorktreeRefusal: ["UNKNOWN","HEAD_UNAVAILABLE","HEAD_SHA_MISMATCH","TREE_OID_MISMATCH","WORKTREE_NOT_DETACHED","WORKTREE_NOT_CLEAN"],
384
- reviewOwnershipRefusal: ["persisted-manifest-missing","persisted-manifest-identity-mismatch","run-id","manifest-path","lock-path","persisted-manifest-mismatch","persisted-lock-mismatch","run-root-name","worktree-temp-root","codegraph-temporary-state-root","run-root-not-a-directory","run-root-owner-marker-missing","run-root-owner-marker-mismatch","worktree-temporary-root","worktree-root","worktree-source-root"],
385
380
  projectionInputField: ["headSha","worktreeDigest","sourceFiles"],
386
381
  upgradeAction: ["upgrade-archctx-runtime"],
387
382
  upgradeCommand: ["archctx daemon upgrade"],
@@ -466,6 +461,17 @@ function localFactValue(rule: string, value: unknown): Json {
466
461
  return { path, code: code as string };
467
462
  });
468
463
  }
464
+ if (rule === "stateMachineIssues") {
465
+ // `<path>: <field>: <invariant or schema message>`; issueCount and omittedCount count what does not fit.
466
+ if (!Array.isArray(value)) throw new Error("State machine issues must be an own list");
467
+ const length = Object.getOwnPropertyDescriptor(value, "length")?.value;
468
+ if (!Number.isSafeInteger(length) || length > 16 || Reflect.ownKeys(value).length !== length + 1) throw new Error("State machine issues exceed their closed budget");
469
+ return Array.from({ length }, (_, index) => {
470
+ const field = Object.getOwnPropertyDescriptor(value, String(index));
471
+ if (!field || !("value" in field) || typeof field.value !== "string" || bytes(field.value) > 256) throw new Error("Invalid state machine issue");
472
+ return field.value;
473
+ });
474
+ }
469
475
  if (rule === "diagnosticPaths" || rule === "diagnosticCommands") {
470
476
  if (!Array.isArray(value)) throw new Error("Diagnostics must be an own list");
471
477
  const length=Object.getOwnPropertyDescriptor(value,"length")?.value;
@@ -752,7 +758,7 @@ export function knownFailure<C extends FailureCode>(code: C, reasonCode: string,
752
758
  return { code, message: policy.message, severity, retryable, action, reasonCode, details: projectionRecoveryDetailsSnapshot(reasonCode, details) };
753
759
  }
754
760
  const safeDetails = detailsFor(policy, details);
755
- const extendedFacts = Object.values(policy.facts ?? {}).some(rule => rule === "publicConfirmationToken" || rule === "commandSuggestion" || rule === "diagnosticCommands");
761
+ const extendedFacts = Object.values(policy.facts ?? {}).some(rule => ["publicConfirmationToken", "commandSuggestion", "diagnosticCommands"].includes(rule.replace(/^optional:/, "")));
756
762
  if (budgetIssues(safeDetails, 0, extendedFacts ? 1024 : 256).length || bytes(JSON.stringify(safeDetails)) > 8192 || bytes(policy.message) > 1024) throw new Error("Failure metadata exceeds its UTF-8 budget");
757
763
  return { code, message: policy.message, severity, retryable, action, reasonCode, details: safeDetails };
758
764
  }
@@ -853,7 +859,7 @@ export function failureIssues(value: unknown): string[] {
853
859
  if ((prototype !== Object.prototype && prototype !== null) || keys.length !== fields.length || Object.keys(value).length !== fields.length || keys.some(key => typeof key !== "string" || !fields.includes(key))) return ["failure must match its closed registered contract"];
854
860
  const data = Object.fromEntries(fields.map(key => [key, ownData(value, key)]));
855
861
  const policy = typeof data.reasonCode === "string" ? policies[data.reasonCode] : undefined;
856
- const extendedFacts = policy !== undefined && policy.code === data.code && Object.values(policy.facts ?? {}).some(rule => rule === "publicConfirmationToken" || rule === "commandSuggestion" || rule === "diagnosticCommands");
862
+ const extendedFacts = policy !== undefined && policy.code === data.code && Object.values(policy.facts ?? {}).some(rule => ["publicConfirmationToken", "commandSuggestion", "diagnosticCommands"].includes(rule.replace(/^optional:/, "")));
857
863
  data.details = policy?.journalRecovery && policy.code === data.code ? changeSetRecoveryDetailsSnapshot(data.details) : policy?.recovery && policy.code === data.code ? projectionRecoveryDetailsSnapshot(data.reasonCode as string, data.details) : jsonDataSnapshot(data.details, 0, extendedFacts ? 1024 : 256);
858
864
  if (typeof data.message !== "string" || bytes(data.message) > 1024 || bytes(JSON.stringify(data.details)) > (policy?.recovery || policy?.journalRecovery ? PROJECTION_RECOVERY_DETAILS_LIMIT_BYTES : 8192)) return ["failure exceeds byte/shape budget"];
859
865
  const expected = failureFromData(data);
package/src/index.ts CHANGED
@@ -1,10 +1,9 @@
1
- export * from "./control-plane-routes";
2
1
  export * from "./architecture";
3
2
  export * from "./architecture-history";
4
3
  export * from "./architecture-debt";
5
4
  export * from "./docs-anchors";
6
5
  export * from "./external-docs";
7
- export * from "./github-governance";
6
+ export * from "./review-guards";
8
7
  export * from "./ledger";
9
8
  export * from "./native-context";
10
9
  export * from "./ref-impact";
@@ -20,6 +19,7 @@ export * from "./product-version";
20
19
  export * from "./refactor";
21
20
  export * from "./runtime-topology";
22
21
  export * from "./schema";
22
+ export * from "./state-machine";
23
23
  export * from "./failure";
24
24
  export * from "./validator";
25
25
 
package/src/ports.ts CHANGED
@@ -247,7 +247,6 @@ export interface RendererPort {
247
247
 
248
248
  export interface CloudMetadataPort {
249
249
  verifyEntitlement(input: { repositoryVisibility: "public" | "private"; accountId?: string }): Promise<{ allowed: boolean; reason?: string }>;
250
- submitAttestation(input: unknown): Promise<{ accepted: boolean; checkRunId?: string; reason?: string }>;
251
250
  }
252
251
 
253
252
  export type NotificationResult = "pass" | "pass_with_warnings" | "fail_action_required";
@@ -800,40 +799,6 @@ export interface ChatGptGaToolContract {
800
799
  disclosure: string;
801
800
  }
802
801
 
803
- export type DetachedReviewWorktreeReason =
804
- | "HEAD_UNAVAILABLE"
805
- | "HEAD_SHA_MISMATCH"
806
- | "TREE_OID_MISMATCH"
807
- | "WORKTREE_NOT_DETACHED"
808
- | "WORKTREE_NOT_CLEAN";
809
-
810
- export interface DetachedReviewWorktreeVerification {
811
- schemaVersion: "archcontext.detached-review-worktree-verification/v1";
812
- accepted: boolean;
813
- reasonCode?: DetachedReviewWorktreeReason;
814
- expected: {
815
- headSha: string;
816
- headTreeOid?: string;
817
- };
818
- observed: {
819
- headSha?: string;
820
- headTreeOid?: string;
821
- detached?: boolean;
822
- clean?: boolean;
823
- };
824
- }
825
-
826
-
827
- export interface ReviewCheckoutGitPort {
828
- findRepositoryRoot(start: string): string;
829
- readOriginUrl(root: string): string | null;
830
- verifyDetachedWorktree(input: {
831
- worktreeRoot: string;
832
- expectedHeadSha: string;
833
- expectedHeadTreeOid?: string;
834
- }): DetachedReviewWorktreeVerification;
835
- }
836
-
837
802
  export interface NonLocalEgressChannel {
838
803
  channel: "context7" | "agent-audit" | "github-issue-publishing" | "npm-update-check" | "projection-publishing" | "codegraph-telemetry";
839
804
  destination: string;
@@ -1,5 +1,5 @@
1
1
  export const ARCHCONTEXT_PRODUCT_NAME = "archctx";
2
- export const ARCHCONTEXT_PRODUCT_VERSION = "0.11.4";
2
+ export const ARCHCONTEXT_PRODUCT_VERSION = "0.13.0";
3
3
  export const ARCHCONTEXT_PACKAGE_MANAGER = "bun@1.4.3";
4
4
  export const ARCHCONTEXT_NODE_RANGE = ">=22.22 <26";
5
5
  export const LOCAL_RUNTIME_RPC_SCHEMA_VERSION = "archcontext.runtime-rpc/v2";
@@ -28,10 +28,6 @@ export interface ProductVersionManifest {
28
28
  schemas: {
29
29
  schemaSetVersion: typeof ARCHCONTEXT_SCHEMA_SET_VERSION;
30
30
  contractsPackageVersion: typeof ARCHCONTEXT_PRODUCT_VERSION;
31
- reviewChallenge: "archcontext.review-challenge/v2";
32
- attestation: "archcontext.attestation/v2";
33
- deviceIdentity: "archcontext.device-identity/v1";
34
- runnerIdentity: "archcontext.runner-identity/v1";
35
31
  };
36
32
  runtime: {
37
33
  localRpc: {
@@ -87,10 +83,6 @@ export function productVersionManifest(): ProductVersionManifest {
87
83
  schemas: {
88
84
  schemaSetVersion: ARCHCONTEXT_SCHEMA_SET_VERSION,
89
85
  contractsPackageVersion: ARCHCONTEXT_PRODUCT_VERSION,
90
- reviewChallenge: "archcontext.review-challenge/v2",
91
- attestation: "archcontext.attestation/v2",
92
- deviceIdentity: "archcontext.device-identity/v1",
93
- runnerIdentity: "archcontext.runner-identity/v1"
94
86
  },
95
87
  runtime: {
96
88
  localRpc: {
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Guards that keep a caller from forging a review conclusion, and the envelope shape the remaining
3
+ * Cloud surfaces still record.
4
+ *
5
+ * These live here, not with the rest of the retired governance surface, because they survive ADR-0053:
6
+ * the runtime daemon's `completeTask` and the mcp-local `complete-task` tool use the attestation-field
7
+ * guards for local review, and `schemas/cloud/cloud-egress-envelope.schema.json` plus the ADR-0035
8
+ * privacy rule keep `CloudEgressEnvelope`. Keeping them in `github-governance.ts` would have made that
9
+ * file undeletable without breaking local review.
10
+ */
11
+
12
+ export const CALLER_PROVIDED_ATTESTATION_FIELDS = [
13
+ "result",
14
+ "reviewDigest",
15
+ "policyDigest",
16
+ "modelDigest",
17
+ "signature",
18
+ "practiceEnforcement",
19
+ "practiceViolations",
20
+ "waiversApplied",
21
+ "actionsRequired",
22
+ "practiceCatalogDigest",
23
+ "practicePolicyDigest",
24
+ "practiceCheckResultDigest"
25
+ ] as const;
26
+ export type CallerProvidedAttestationField = (typeof CALLER_PROVIDED_ATTESTATION_FIELDS)[number];
27
+
28
+ export const LLM_ADVISORY_FORBIDDEN_FIELDS = [
29
+ ...CALLER_PROVIDED_ATTESTATION_FIELDS,
30
+ "conclusion",
31
+ "checkConclusion",
32
+ "attestationResult"
33
+ ] as const;
34
+ export type LlmAdvisoryForbiddenField = (typeof LLM_ADVISORY_FORBIDDEN_FIELDS)[number];
35
+
36
+ function collectForbiddenFields<T extends string>(value: unknown, found: Set<T>, forbiddenFields: readonly T[]): void {
37
+ if (!value || typeof value !== "object") return;
38
+ if (Array.isArray(value)) {
39
+ for (const item of value) collectForbiddenFields(item, found, forbiddenFields);
40
+ return;
41
+ }
42
+ for (const [key, child] of Object.entries(value as Record<string, unknown>)) {
43
+ if ((forbiddenFields as readonly string[]).includes(key)) {
44
+ found.add(key as T);
45
+ }
46
+ collectForbiddenFields(child, found, forbiddenFields);
47
+ }
48
+ }
49
+
50
+ function collectCallerProvidedAttestationFields(value: unknown, found: Set<CallerProvidedAttestationField>): void {
51
+ collectForbiddenFields(value, found, CALLER_PROVIDED_ATTESTATION_FIELDS);
52
+ }
53
+
54
+ export function findCallerProvidedAttestationFields(value: unknown): CallerProvidedAttestationField[] {
55
+ const found = new Set<CallerProvidedAttestationField>();
56
+ collectCallerProvidedAttestationFields(value, found);
57
+ return CALLER_PROVIDED_ATTESTATION_FIELDS.filter((field) => found.has(field));
58
+ }
59
+
60
+ export function assertNoCallerProvidedAttestationFields(value: unknown, boundary = "review request"): void {
61
+ const fields = findCallerProvidedAttestationFields(value);
62
+ if (fields.length > 0) throw new Error(`${boundary}-caller-provided-attestation-field-forbidden: ${fields.join(",")}`);
63
+ }
64
+
65
+ export function findLlmAdvisoryForbiddenFields(value: unknown): LlmAdvisoryForbiddenField[] {
66
+ const found = new Set<LlmAdvisoryForbiddenField>();
67
+ collectForbiddenFields(value, found, LLM_ADVISORY_FORBIDDEN_FIELDS);
68
+ return LLM_ADVISORY_FORBIDDEN_FIELDS.filter((field) => found.has(field));
69
+ }
70
+
71
+ export function assertNoLlmAdvisoryConclusionFields(value: unknown): void {
72
+ const fields = findLlmAdvisoryForbiddenFields(value);
73
+ if (fields.length > 0) throw new Error(`llm-advisory-conclusion-field-forbidden: ${fields.join(",")}`);
74
+ }
75
+
76
+ /**
77
+ * What a remaining Cloud surface records when it calls the GitHub API. ADR-0035's privacy rule and
78
+ * `schemas/cloud/cloud-egress-envelope.schema.json` both depend on this shape.
79
+ */
80
+ export interface CloudEgressEnvelope {
81
+ schemaVersion: "archcontext.cloud-egress/v1";
82
+ requestId: string;
83
+ category: "github.metadata" | "github.pull-head" | "github.check-list-for-ref" | "github.check-create" | "github.check-update";
84
+ method: "GET" | "POST" | "PATCH";
85
+ host: "api.github.com";
86
+ pathTemplate: string;
87
+ statusCode: number;
88
+ latencyMs: number;
89
+ recordedAt: string;
90
+ }
package/src/schema.ts CHANGED
@@ -32,7 +32,6 @@ export type ArchContextErrorCode =
32
32
  | "AC_COMPAT_CONTRACT_REQUIRED"
33
33
  | "AC_USER_CONFIRMATION_REQUIRED"
34
34
  | "AC_ENTITLEMENT_REQUIRED"
35
- | "AC_ATTESTATION_REJECTED"
36
35
  | "AC_TUNNEL_SCOPE_DENIED"
37
36
  | "AC_MODEL_ADOPTION_REQUIRED"
38
37
  | "AC_REFACTOR_STALE"
@@ -83,7 +82,6 @@ export const ERROR_CATALOG: Record<ArchContextErrorCode, Omit<ArchContextError,
83
82
  AC_COMPAT_CONTRACT_REQUIRED: { code: "AC_COMPAT_CONTRACT_REQUIRED", severity: "error", retryable: false, action: "delete-or-contract" },
84
83
  AC_USER_CONFIRMATION_REQUIRED: { code: "AC_USER_CONFIRMATION_REQUIRED", severity: "warning", retryable: true, action: "show-human-decision" },
85
84
  AC_ENTITLEMENT_REQUIRED: { code: "AC_ENTITLEMENT_REQUIRED", severity: "error", retryable: false, action: "login-or-subscribe" },
86
- AC_ATTESTATION_REJECTED: { code: "AC_ATTESTATION_REJECTED", severity: "error", retryable: false, action: "review-again" },
87
85
  AC_TUNNEL_SCOPE_DENIED: { code: "AC_TUNNEL_SCOPE_DENIED", severity: "error", retryable: false, action: "reduce-scope" },
88
86
  AC_MODEL_ADOPTION_REQUIRED: { code: "AC_MODEL_ADOPTION_REQUIRED", severity: "error", retryable: false, action: "adopt-architecture-model" },
89
87
  AC_REFACTOR_STALE: { code: "AC_REFACTOR_STALE", severity: "warning", retryable: true, action: "rerun-refactor-scan" },