archctx-contracts 0.1.5

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 (100) hide show
  1. package/fixtures/boundary/agent-job-expired.json +33 -0
  2. package/fixtures/boundary/architecture-event-extension.json +41 -0
  3. package/fixtures/boundary/architecture-node-extension.json +13 -0
  4. package/fixtures/boundary/attestation-v2-error.json +43 -0
  5. package/fixtures/boundary/check-delivery-dead-letter.json +14 -0
  6. package/fixtures/boundary/evidence-binding-context-only.json +20 -0
  7. package/fixtures/boundary/practice-disabled-overlay.json +59 -0
  8. package/fixtures/boundary/recommendation-deferred.json +19 -0
  9. package/fixtures/boundary/review-challenge-v2-organization.json +15 -0
  10. package/fixtures/boundary/runner-identity-organization-scope.json +16 -0
  11. package/fixtures/invalid/adapter-fidelity-reverse-sync.json +9 -0
  12. package/fixtures/invalid/agent-job-direct-mutation.json +32 -0
  13. package/fixtures/invalid/architecture-event-source-body-field.json +39 -0
  14. package/fixtures/invalid/architecture-snapshot-unknown-mode.json +29 -0
  15. package/fixtures/invalid/attestation-v2-finding-field.json +39 -0
  16. package/fixtures/invalid/check-delivery-legacy-check-name.json +14 -0
  17. package/fixtures/invalid/cloud-egress-envelope-private-field.json +12 -0
  18. package/fixtures/invalid/compatibility-illegal-reason.json +17 -0
  19. package/fixtures/invalid/evidence-binding-summary-substring-authority.json +17 -0
  20. package/fixtures/invalid/evidence-item-source-body-field.json +27 -0
  21. package/fixtures/invalid/explorer-projection-write-field.json +21 -0
  22. package/fixtures/invalid/investigation-report-direct-mutation.json +38 -0
  23. package/fixtures/invalid/investigation-report-missing-proposed-delta.json +19 -0
  24. package/fixtures/invalid/node-unknown-field.json +10 -0
  25. package/fixtures/invalid/notification-event-code-field.json +11 -0
  26. package/fixtures/invalid/practice-policy-empty-test-evidence.json +15 -0
  27. package/fixtures/invalid/practice-policy-negative-recommendation-budget.json +10 -0
  28. package/fixtures/invalid/practice-unknown-field.json +56 -0
  29. package/fixtures/invalid/projection-target-invalid-ownership.json +18 -0
  30. package/fixtures/invalid/recommendation-feedback-implicit-acceptance.json +29 -0
  31. package/fixtures/invalid/recommendation-run-raw-input-field.json +33 -0
  32. package/fixtures/invalid/recommendation-source-body-field.json +17 -0
  33. package/fixtures/invalid/review-challenge-v2-private-field.json +16 -0
  34. package/fixtures/valid/adapter-fidelity.json +9 -0
  35. package/fixtures/valid/agent-job.json +33 -0
  36. package/fixtures/valid/architecture-candidate-delta-policy.json +45 -0
  37. package/fixtures/valid/architecture-candidate-delta.json +188 -0
  38. package/fixtures/valid/architecture-event.json +39 -0
  39. package/fixtures/valid/architecture-intervention.json +36 -0
  40. package/fixtures/valid/architecture-node.json +25 -0
  41. package/fixtures/valid/architecture-relation.json +14 -0
  42. package/fixtures/valid/architecture-snapshot.json +31 -0
  43. package/fixtures/valid/architecture-subject-selector.json +9 -0
  44. package/fixtures/valid/attestation-v2.json +38 -0
  45. package/fixtures/valid/attestation.json +25 -0
  46. package/fixtures/valid/changeset.json +30 -0
  47. package/fixtures/valid/chatgpt-ga-tool.json +9 -0
  48. package/fixtures/valid/check-delivery.json +14 -0
  49. package/fixtures/valid/cloud-egress-envelope.json +11 -0
  50. package/fixtures/valid/compatibility-contract.json +19 -0
  51. package/fixtures/valid/constraint.json +22 -0
  52. package/fixtures/valid/cross-repo-relation.json +23 -0
  53. package/fixtures/valid/device-identity.json +10 -0
  54. package/fixtures/valid/entitlement.json +12 -0
  55. package/fixtures/valid/evidence-binding.json +17 -0
  56. package/fixtures/valid/evidence-item.json +29 -0
  57. package/fixtures/valid/explorer-projection.json +53 -0
  58. package/fixtures/valid/explorer-service.json +11 -0
  59. package/fixtures/valid/external-document-resource.json +29 -0
  60. package/fixtures/valid/governance-key-status.json +11 -0
  61. package/fixtures/valid/investigation-report.json +38 -0
  62. package/fixtures/valid/landscape.json +36 -0
  63. package/fixtures/valid/likec4-mapping.json +14 -0
  64. package/fixtures/valid/notification-event.json +10 -0
  65. package/fixtures/valid/notification-provider.json +12 -0
  66. package/fixtures/valid/org-runner-identity.json +10 -0
  67. package/fixtures/valid/practice-catalog-manifest.json +16 -0
  68. package/fixtures/valid/practice-check-result.json +17 -0
  69. package/fixtures/valid/practice-checkpoint.json +94 -0
  70. package/fixtures/valid/practice-guidance.json +42 -0
  71. package/fixtures/valid/practice-match.json +23 -0
  72. package/fixtures/valid/practice-policy.json +33 -0
  73. package/fixtures/valid/practice-profile.json +22 -0
  74. package/fixtures/valid/practice-source.json +19 -0
  75. package/fixtures/valid/practice-waiver.json +14 -0
  76. package/fixtures/valid/practice.json +93 -0
  77. package/fixtures/valid/product-version-manifest.json +51 -0
  78. package/fixtures/valid/projection-target.json +18 -0
  79. package/fixtures/valid/recommendation-feedback.json +29 -0
  80. package/fixtures/valid/recommendation-run.json +33 -0
  81. package/fixtures/valid/recommendation.json +17 -0
  82. package/fixtures/valid/retrieval-config.json +20 -0
  83. package/fixtures/valid/retrieval-decision.json +26 -0
  84. package/fixtures/valid/retrieval-eval.json +14 -0
  85. package/fixtures/valid/review-challenge-v2.json +15 -0
  86. package/fixtures/valid/review-result.json +32 -0
  87. package/fixtures/valid/runner-identity.json +13 -0
  88. package/fixtures/valid/structurizr-mapping.json +15 -0
  89. package/fixtures/valid/task-context.json +23 -0
  90. package/package.json +17 -0
  91. package/src/control-plane-routes.ts +35 -0
  92. package/src/external-docs.ts +137 -0
  93. package/src/github-governance.ts +850 -0
  94. package/src/index.ts +9 -0
  95. package/src/ledger.ts +649 -0
  96. package/src/ports.ts +385 -0
  97. package/src/practices.ts +433 -0
  98. package/src/product-version.ts +108 -0
  99. package/src/schema.ts +145 -0
  100. package/src/validator.ts +95 -0
@@ -0,0 +1,433 @@
1
+ import type { Json } from "./schema";
2
+
3
+ export const PRACTICE_SCHEMA_VERSION = "archcontext.practice/v1" as const;
4
+ export const PRACTICE_PROFILE_SCHEMA_VERSION = "archcontext.practice-profile/v1" as const;
5
+ export const PRACTICE_SOURCE_SCHEMA_VERSION = "archcontext.practice-source/v1" as const;
6
+ export const PRACTICE_CATALOG_MANIFEST_SCHEMA_VERSION = "archcontext.practice-catalog-manifest/v1" as const;
7
+ export const PRACTICE_ENFORCEMENT_POLICY_SCHEMA_VERSION = "archcontext.practice-enforcement-policy/v1" as const;
8
+ export const PRACTICE_WAIVER_SCHEMA_VERSION = "archcontext.practice-waiver/v1" as const;
9
+ export const PRACTICE_CHECK_RESULT_SCHEMA_VERSION = "archcontext.practice-check-result/v1" as const;
10
+
11
+ export type PracticeStatus = "active" | "deprecated" | "disabled";
12
+ export type PracticeOverlayMode = "add" | "replace" | "disable";
13
+ export type PracticeEvidenceStrength = "heuristic" | "declared" | "observed" | "verified";
14
+ export type PracticeEvidenceKind =
15
+ | "task-text"
16
+ | "path"
17
+ | "package-manifest"
18
+ | "architecture-model"
19
+ | "symbol"
20
+ | "import-edge"
21
+ | "call-edge"
22
+ | "data-edge"
23
+ | "diff"
24
+ | "test"
25
+ | "runtime-check"
26
+ | "human-attestation";
27
+ export type PracticeEnforcementLevel = "advisory" | "checkpoint" | "complete";
28
+ export type PracticeSourceTrust = "repo-authored" | "curated-static" | "external-dynamic";
29
+ export type PracticeSourceLicenseLevel = "A" | "B" | "C" | "D" | "E";
30
+ export type PracticeMatchConfidence = "low" | "medium" | "high";
31
+ export type PracticeMatchReason = "retrieval" | "scope" | "signal" | "predicate" | "repo-policy";
32
+ export type PracticeCheckpointEvent = "manual" | "post-edit" | "post-write" | "pre-complete";
33
+ export type PracticeCheckpointReasonCode =
34
+ | "fresh"
35
+ | "stale-head"
36
+ | "stale-worktree"
37
+ | "stale-catalog"
38
+ | "no-baseline"
39
+ | "no-op";
40
+ export type PracticeCheckStatus = "pass" | "fail" | "waived" | "not_applicable";
41
+ export type PracticeEnforcementPolicyMode = "advisory" | "active" | "fail-open" | "fail-closed";
42
+ export type PracticeEnforcementEvaluationMode = "advisory" | "fail-open" | "fail-closed";
43
+ export type PracticeCheckReasonCode =
44
+ | "policy-disabled"
45
+ | "not-opted-in"
46
+ | "not-registered"
47
+ | "fixture-gate-missing"
48
+ | "heuristic-only"
49
+ | "no-baseline"
50
+ | "no-violation"
51
+ | "violation"
52
+ | "waived"
53
+ | "invalid-waiver";
54
+
55
+ export interface PracticeScopeV1 {
56
+ repositoryKinds: string[];
57
+ languages: string[];
58
+ frameworks: string[];
59
+ pathGlobs: string[];
60
+ nodeKinds: string[];
61
+ negativePathGlobs?: string[];
62
+ negativeNodeKinds?: string[];
63
+ }
64
+
65
+ export interface PracticeTriggersV1 {
66
+ candidateTerms: string[];
67
+ pressureSignals: string[];
68
+ structuralPredicates: string[];
69
+ }
70
+
71
+ export interface PracticeEvidencePolicyV1 {
72
+ minimumStrengthForRecommendation: PracticeEvidenceStrength;
73
+ minimumStrengthForCheckpoint: PracticeEvidenceStrength;
74
+ minimumStrengthForEnforcement: PracticeEvidenceStrength;
75
+ requiredKindsForEnforcement: PracticeEvidenceKind[];
76
+ maxEnforcementWhenOnlyHeuristic: "advisory";
77
+ }
78
+
79
+ export interface PracticeGuidanceV1 {
80
+ questions: string[];
81
+ preferred: string[];
82
+ avoid: string[];
83
+ }
84
+
85
+ export interface PracticeCheckV1 {
86
+ checkId: string;
87
+ mode: "deterministic";
88
+ parameters: Record<string, Json>;
89
+ }
90
+
91
+ export interface PracticeCheckDefinitionV1 extends PracticeCheckV1 {
92
+ schemaVersion: "archcontext.practice-check-definition/v1";
93
+ practiceId: string;
94
+ }
95
+
96
+ export interface PracticeEnforcementV1 {
97
+ default: PracticeEnforcementLevel;
98
+ promotableTo: PracticeEnforcementLevel;
99
+ repoOptInRequired: boolean;
100
+ fixtureGate?: PracticeEnforcementFixtureGateV1;
101
+ }
102
+
103
+ export interface PracticeEnforcementFixtureRefV1 {
104
+ id: string;
105
+ path: string;
106
+ description: string;
107
+ digest?: string;
108
+ }
109
+
110
+ export interface PracticeEnforcementFixtureGateV1 {
111
+ positive: PracticeEnforcementFixtureRefV1[];
112
+ nearNegative: PracticeEnforcementFixtureRefV1[];
113
+ mixedChange: PracticeEnforcementFixtureRefV1[];
114
+ baseline: PracticeEnforcementFixtureRefV1[];
115
+ }
116
+
117
+ export interface PracticeSourceRefV1 {
118
+ sourceId: string;
119
+ sourceRevision?: string;
120
+ licenseSpdx?: string;
121
+ }
122
+
123
+ export interface PracticeProvenanceV1 {
124
+ sourceKind: "archcontext-native" | "curated-open-source" | "curated-reference";
125
+ sourceRefs: PracticeSourceRefV1[];
126
+ curator: string;
127
+ reviewedAt: string;
128
+ }
129
+
130
+ export interface PracticeLifecycleV1 {
131
+ introducedAt: string;
132
+ reviewAfter: string;
133
+ supersedes: string[];
134
+ disabledWithReason?: string;
135
+ }
136
+
137
+ export interface PracticeOverlayV1 {
138
+ mode: PracticeOverlayMode;
139
+ extends?: string;
140
+ expiresAt?: string;
141
+ }
142
+
143
+ export interface PracticeAssetV1 {
144
+ schemaVersion: typeof PRACTICE_SCHEMA_VERSION;
145
+ id: string;
146
+ revision: number;
147
+ status: PracticeStatus;
148
+ title: string;
149
+ summary: string;
150
+ category: string;
151
+ tags: string[];
152
+ appliesTo: PracticeScopeV1;
153
+ triggers: PracticeTriggersV1;
154
+ evidencePolicy: PracticeEvidencePolicyV1;
155
+ guidance: PracticeGuidanceV1;
156
+ checks: PracticeCheckV1[];
157
+ enforcement: PracticeEnforcementV1;
158
+ provenance: PracticeProvenanceV1;
159
+ lifecycle: PracticeLifecycleV1;
160
+ overlay?: PracticeOverlayV1;
161
+ }
162
+
163
+ export interface PracticeProfileV1 {
164
+ schemaVersion: typeof PRACTICE_PROFILE_SCHEMA_VERSION;
165
+ id: string;
166
+ revision: number;
167
+ status: "active" | "deprecated";
168
+ title: string;
169
+ repositoryKinds: string[];
170
+ languages: string[];
171
+ frameworks: string[];
172
+ includePracticeIds: string[];
173
+ excludePracticeIds: string[];
174
+ provenance: PracticeProvenanceV1;
175
+ }
176
+
177
+ export interface PracticePolicyScopeV1 {
178
+ pathGlobs?: string[];
179
+ subjects?: string[];
180
+ }
181
+
182
+ export interface PracticePolicyTestEvidenceV1 {
183
+ commands?: string[];
184
+ subjects?: string[];
185
+ }
186
+
187
+ export interface PracticePolicyRuleV1 {
188
+ practiceId: string;
189
+ enforcement: PracticeEnforcementLevel;
190
+ checkIds?: string[];
191
+ scope?: PracticePolicyScopeV1;
192
+ testEvidence?: PracticePolicyTestEvidenceV1;
193
+ }
194
+
195
+ export interface PracticeRecommendationSchedulerPolicyV1 {
196
+ enabled?: boolean;
197
+ policyMode?: "advisory" | "checkpoint" | "complete";
198
+ frequency?: {
199
+ minIntervalMs?: number;
200
+ cooldownMs?: number;
201
+ };
202
+ budgets?: {
203
+ maxRecommendationsPerRun?: number;
204
+ maxL3InvestigationsPerRun?: number;
205
+ maxRunsPerTask?: number;
206
+ maxRunsPerRepositoryPerDay?: number;
207
+ maxRunsPerDay?: number;
208
+ };
209
+ }
210
+
211
+ export interface PracticeEnforcementPolicyV1 {
212
+ schemaVersion: typeof PRACTICE_ENFORCEMENT_POLICY_SCHEMA_VERSION;
213
+ mode: PracticeEnforcementPolicyMode;
214
+ rules: PracticePolicyRuleV1[];
215
+ recommendations?: PracticeRecommendationSchedulerPolicyV1;
216
+ }
217
+
218
+ export interface PracticeWaiverV1 {
219
+ schemaVersion: typeof PRACTICE_WAIVER_SCHEMA_VERSION;
220
+ practiceId: string;
221
+ checkId?: string;
222
+ scope: PracticePolicyScopeV1;
223
+ owner: string;
224
+ reason: string;
225
+ createdAt: string;
226
+ reviewAt: string;
227
+ expiresAt: string;
228
+ evidenceDigest: string;
229
+ }
230
+
231
+ export interface PracticeSourceRecordV1 {
232
+ schemaVersion: typeof PRACTICE_SOURCE_SCHEMA_VERSION;
233
+ id: string;
234
+ name: string;
235
+ sourceType: "archcontext" | "git" | "website" | "standard" | "reference";
236
+ uri: string;
237
+ revision: string;
238
+ licenseSpdx: string;
239
+ licenseLevel: PracticeSourceLicenseLevel;
240
+ usagePolicy: "builtin-with-attribution" | "reference-only" | "repo-authored";
241
+ retrievedAt: string;
242
+ contentDigest: string;
243
+ attribution: string;
244
+ review: {
245
+ status: "approved" | "reference-only" | "blocked";
246
+ reviewer: string;
247
+ reviewedAt: string;
248
+ };
249
+ }
250
+
251
+ export interface PracticeCatalogManifestEntryV1 {
252
+ id: string;
253
+ revision: number;
254
+ digest: string;
255
+ sourceIds: string[];
256
+ }
257
+
258
+ export interface PracticeCatalogManifestV1 {
259
+ schemaVersion: typeof PRACTICE_CATALOG_MANIFEST_SCHEMA_VERSION;
260
+ catalogVersion: string;
261
+ productVersion: string;
262
+ generatedAt: string;
263
+ entries: PracticeCatalogManifestEntryV1[];
264
+ sourceIds: string[];
265
+ catalogDigest: string;
266
+ }
267
+
268
+ export interface EffectivePracticeAssetV1 {
269
+ asset: PracticeAssetV1;
270
+ assetDigest: string;
271
+ sourceTrust: PracticeSourceTrust;
272
+ originPath: string;
273
+ overrideChain: string[];
274
+ }
275
+
276
+ export interface PracticeEvidenceV1 {
277
+ kind: PracticeEvidenceKind;
278
+ strength: PracticeEvidenceStrength;
279
+ subject: string;
280
+ digest?: string;
281
+ observedAt?: string;
282
+ }
283
+
284
+ export interface PracticeMatchV1 {
285
+ schemaVersion: "archcontext.practice-match/v1";
286
+ practiceId: string;
287
+ assetRevision: number;
288
+ assetDigest: string;
289
+ title: string;
290
+ category: string;
291
+ score: number;
292
+ confidence: PracticeMatchConfidence;
293
+ enforcement: PracticeEnforcementLevel;
294
+ matchedBy: PracticeMatchReason[];
295
+ evidence: PracticeEvidenceV1[];
296
+ explanation: string[];
297
+ sourceTrust: PracticeSourceTrust;
298
+ suppressedReason?: string;
299
+ }
300
+
301
+ export interface PracticeCheckRemediationV1 {
302
+ action: string;
303
+ paths: string[];
304
+ }
305
+
306
+ export interface PracticeWaiverApplicationV1 {
307
+ waiverDigest: string;
308
+ practiceId: string;
309
+ checkId?: string;
310
+ owner: string;
311
+ reviewAt: string;
312
+ expiresAt: string;
313
+ }
314
+
315
+ export interface PracticeCheckResultV1 {
316
+ schemaVersion: typeof PRACTICE_CHECK_RESULT_SCHEMA_VERSION;
317
+ practiceId: string;
318
+ checkId: string;
319
+ assetDigest: string;
320
+ enforcement: PracticeEnforcementLevel;
321
+ status: PracticeCheckStatus;
322
+ reasonCode: PracticeCheckReasonCode;
323
+ deterministic: true;
324
+ subjects: string[];
325
+ subjectDigests: string[];
326
+ message: string;
327
+ remediation: PracticeCheckRemediationV1;
328
+ waiver?: PracticeWaiverApplicationV1;
329
+ }
330
+
331
+ export interface PracticeEnforcementEvaluationV1 {
332
+ schemaVersion: "archcontext.practice-enforcement-evaluation/v1";
333
+ catalogDigest: string;
334
+ policyDigest: string;
335
+ policyMode: PracticeEnforcementEvaluationMode;
336
+ blocking: boolean;
337
+ checkResultDigest: string;
338
+ results: PracticeCheckResultV1[];
339
+ violations: PracticeCheckResultV1[];
340
+ nonBlockingViolations: PracticeCheckResultV1[];
341
+ waiversApplied: PracticeWaiverApplicationV1[];
342
+ actionsRequired: string[];
343
+ }
344
+
345
+ export interface PracticeGuidanceResultV1 {
346
+ schemaVersion: "archcontext.practice-guidance/v1";
347
+ catalogDigest: string;
348
+ overlayDigest: string;
349
+ matches: PracticeMatchV1[];
350
+ constraints: string[];
351
+ decisions: string[];
352
+ realConstraints: string[];
353
+ unknowns: string[];
354
+ requiredCheckpoints: string[];
355
+ resources: { type: "practice"; uri: string; digest: string }[];
356
+ }
357
+
358
+ export interface CheckpointInputV2 {
359
+ schemaVersion: "archcontext.checkpoint-input/v2";
360
+ taskSessionId: string;
361
+ task?: string;
362
+ headSha?: string;
363
+ expectedWorktreeDigest?: string;
364
+ event: PracticeCheckpointEvent;
365
+ changedPaths: string[];
366
+ toolCallId?: string;
367
+ }
368
+
369
+ export interface PracticeCheckpointSnapshotV1 {
370
+ schemaVersion: "archcontext.practice-checkpoint-snapshot/v1";
371
+ task: string;
372
+ headSha: string;
373
+ worktreeDigest: string;
374
+ contextDigest: string;
375
+ practiceGuidanceDigest: string;
376
+ catalogDigest: string;
377
+ matches: PracticeMatchV1[];
378
+ }
379
+
380
+ export interface PracticeDeltaV1 {
381
+ schemaVersion: "archcontext.practice-delta/v1";
382
+ added: PracticeMatchV1[];
383
+ removed: PracticeMatchV1[];
384
+ upgraded: PracticeMatchV1[];
385
+ downgraded: PracticeMatchV1[];
386
+ unchanged: PracticeMatchV1[];
387
+ requiresProof: PracticeMatchV1[];
388
+ }
389
+
390
+ export interface PracticeCheckpointResultV1 {
391
+ schemaVersion: "archcontext.practice-checkpoint/v1";
392
+ taskSessionId: string;
393
+ event: PracticeCheckpointEvent;
394
+ headSha: string;
395
+ expectedHeadSha?: string;
396
+ worktreeDigest: string;
397
+ expectedWorktreeDigest?: string;
398
+ fresh: boolean;
399
+ reasonCode: PracticeCheckpointReasonCode;
400
+ staleReasons: PracticeCheckpointReasonCode[];
401
+ changedPaths: string[];
402
+ toolCallId?: string;
403
+ catalogDigest: string;
404
+ previousCatalogDigest?: string;
405
+ contextDigest: string;
406
+ previousContextDigest?: string;
407
+ practiceGuidanceDigest: string;
408
+ previousPracticeGuidanceDigest?: string;
409
+ delta: PracticeDeltaV1;
410
+ noOpDigest: string;
411
+ resultDigest: string;
412
+ hook: {
413
+ egress: "none";
414
+ failOpen: true;
415
+ pathCount: number;
416
+ network: "forbidden";
417
+ pathSummary?: {
418
+ schemaVersion: "archcontext.checkpoint-path-summary/v1";
419
+ total: number;
420
+ source: number;
421
+ generated: number;
422
+ ignored: number;
423
+ binary: number;
424
+ deleted: number;
425
+ renameHints: number;
426
+ };
427
+ coalesced?: boolean;
428
+ skippedAnalysis?: boolean;
429
+ coalescedEventCount?: number;
430
+ coalesceKey?: string;
431
+ };
432
+ nextSnapshot: PracticeCheckpointSnapshotV1;
433
+ }
@@ -0,0 +1,108 @@
1
+ export const ARCHCONTEXT_PRODUCT_NAME = "archctx";
2
+ export const ARCHCONTEXT_PRODUCT_VERSION = "0.1.5";
3
+ export const ARCHCONTEXT_PACKAGE_MANAGER = "bun@1.3.10";
4
+ export const ARCHCONTEXT_NODE_RANGE = ">=24 <26";
5
+ export const LOCAL_RUNTIME_RPC_SCHEMA_VERSION = "archcontext.runtime-rpc/v1";
6
+ export const ARCHCONTEXT_SCHEMA_SET_VERSION = "2026-06-25.al0-ledger";
7
+
8
+ export interface ProductVersionManifest {
9
+ schemaVersion: "archcontext.product-version-manifest/v1";
10
+ product: {
11
+ name: typeof ARCHCONTEXT_PRODUCT_NAME;
12
+ version: typeof ARCHCONTEXT_PRODUCT_VERSION;
13
+ distribution: "one-package";
14
+ };
15
+ packageManager: typeof ARCHCONTEXT_PACKAGE_MANAGER;
16
+ engines: {
17
+ node: typeof ARCHCONTEXT_NODE_RANGE;
18
+ };
19
+ surfaces: {
20
+ cli: ProductSurfaceVersion;
21
+ daemon: ProductSurfaceVersion & {
22
+ rpcSchemaVersion: typeof LOCAL_RUNTIME_RPC_SCHEMA_VERSION;
23
+ };
24
+ mcp: ProductSurfaceVersion & {
25
+ transport: "stdio";
26
+ };
27
+ };
28
+ schemas: {
29
+ schemaSetVersion: typeof ARCHCONTEXT_SCHEMA_SET_VERSION;
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
+ };
36
+ runtime: {
37
+ localRpc: {
38
+ schemaVersion: typeof LOCAL_RUNTIME_RPC_SCHEMA_VERSION;
39
+ protocol: "http-loopback";
40
+ };
41
+ sqliteMigrations: string;
42
+ codeGraph: {
43
+ packageName: "@colbymchenry/codegraph";
44
+ requiredVersion: "1.0.1";
45
+ adapter: "codegraph-cli";
46
+ };
47
+ };
48
+ }
49
+
50
+ interface ProductSurfaceVersion {
51
+ packageName: string;
52
+ version: typeof ARCHCONTEXT_PRODUCT_VERSION;
53
+ entrypoint: string;
54
+ }
55
+
56
+ export function productVersionManifest(): ProductVersionManifest {
57
+ return {
58
+ schemaVersion: "archcontext.product-version-manifest/v1",
59
+ product: {
60
+ name: ARCHCONTEXT_PRODUCT_NAME,
61
+ version: ARCHCONTEXT_PRODUCT_VERSION,
62
+ distribution: "one-package"
63
+ },
64
+ packageManager: ARCHCONTEXT_PACKAGE_MANAGER,
65
+ engines: {
66
+ node: ARCHCONTEXT_NODE_RANGE
67
+ },
68
+ surfaces: {
69
+ cli: {
70
+ packageName: "@archcontext/surfaces",
71
+ version: ARCHCONTEXT_PRODUCT_VERSION,
72
+ entrypoint: "archctx"
73
+ },
74
+ daemon: {
75
+ packageName: "@archcontext/local-runtime",
76
+ version: ARCHCONTEXT_PRODUCT_VERSION,
77
+ entrypoint: "archctx daemon start",
78
+ rpcSchemaVersion: LOCAL_RUNTIME_RPC_SCHEMA_VERSION
79
+ },
80
+ mcp: {
81
+ packageName: "@archcontext/surfaces",
82
+ version: ARCHCONTEXT_PRODUCT_VERSION,
83
+ entrypoint: "archctx mcp",
84
+ transport: "stdio"
85
+ }
86
+ },
87
+ schemas: {
88
+ schemaSetVersion: ARCHCONTEXT_SCHEMA_SET_VERSION,
89
+ 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
+ },
95
+ runtime: {
96
+ localRpc: {
97
+ schemaVersion: LOCAL_RUNTIME_RPC_SCHEMA_VERSION,
98
+ protocol: "http-loopback"
99
+ },
100
+ sqliteMigrations: "0001_runtime_state..0004_changeset_journal",
101
+ codeGraph: {
102
+ packageName: "@colbymchenry/codegraph",
103
+ requiredVersion: "1.0.1",
104
+ adapter: "codegraph-cli"
105
+ }
106
+ }
107
+ };
108
+ }
package/src/schema.ts ADDED
@@ -0,0 +1,145 @@
1
+ import { createHash } from "node:crypto";
2
+
3
+ export type Json =
4
+ | null
5
+ | boolean
6
+ | number
7
+ | string
8
+ | Json[]
9
+ | { [key: string]: Json };
10
+
11
+ export type Severity = "notice" | "warning" | "error" | "critical";
12
+
13
+ export type ArchContextErrorCode =
14
+ | "AC_REPO_NOT_FOUND"
15
+ | "AC_RUNTIME_UNAVAILABLE"
16
+ | "AC_RUNTIME_VERSION_UNSUPPORTED"
17
+ | "AC_CODEGRAPH_UNAVAILABLE"
18
+ | "AC_INDEX_STALE"
19
+ | "AC_CONTEXT_STALE"
20
+ | "AC_SCHEMA_INVALID"
21
+ | "AC_POLICY_VIOLATION"
22
+ | "AC_PATH_DENIED"
23
+ | "AC_PRECONDITION_FAILED"
24
+ | "AC_CAPABILITY_UNSUPPORTED"
25
+ | "AC_INTERVENTION_REQUIRED"
26
+ | "AC_PROOF_REQUIRED"
27
+ | "AC_COMPAT_CONTRACT_REQUIRED"
28
+ | "AC_USER_CONFIRMATION_REQUIRED"
29
+ | "AC_ENTITLEMENT_REQUIRED"
30
+ | "AC_ATTESTATION_REJECTED"
31
+ | "AC_TUNNEL_SCOPE_DENIED";
32
+
33
+ export interface ArchContextError {
34
+ code: ArchContextErrorCode;
35
+ message: string;
36
+ severity: Severity;
37
+ retryable: boolean;
38
+ action: string;
39
+ }
40
+
41
+ export interface JsonEnvelope<T extends Json = Json> {
42
+ schemaVersion: "archcontext.envelope/v1";
43
+ ok: boolean;
44
+ requestId: string;
45
+ data?: T;
46
+ error?: ArchContextError;
47
+ }
48
+
49
+ export const ERROR_CATALOG: Record<ArchContextErrorCode, Omit<ArchContextError, "message">> = {
50
+ AC_REPO_NOT_FOUND: { code: "AC_REPO_NOT_FOUND", severity: "error", retryable: false, action: "open-correct-repository" },
51
+ AC_RUNTIME_UNAVAILABLE: { code: "AC_RUNTIME_UNAVAILABLE", severity: "error", retryable: true, action: "start-or-reconnect-runtime" },
52
+ AC_RUNTIME_VERSION_UNSUPPORTED: { code: "AC_RUNTIME_VERSION_UNSUPPORTED", severity: "error", retryable: true, action: "upgrade-archctx-runtime" },
53
+ AC_CODEGRAPH_UNAVAILABLE: { code: "AC_CODEGRAPH_UNAVAILABLE", severity: "error", retryable: true, action: "run-diagnostics" },
54
+ AC_INDEX_STALE: { code: "AC_INDEX_STALE", severity: "warning", retryable: true, action: "sync-codefacts" },
55
+ AC_CONTEXT_STALE: { code: "AC_CONTEXT_STALE", severity: "warning", retryable: true, action: "prepare-task-again" },
56
+ AC_SCHEMA_INVALID: { code: "AC_SCHEMA_INVALID", severity: "error", retryable: false, action: "repair-model" },
57
+ AC_POLICY_VIOLATION: { code: "AC_POLICY_VIOLATION", severity: "error", retryable: false, action: "revise-plan" },
58
+ AC_PATH_DENIED: { code: "AC_PATH_DENIED", severity: "critical", retryable: false, action: "do-not-bypass" },
59
+ AC_PRECONDITION_FAILED: { code: "AC_PRECONDITION_FAILED", severity: "warning", retryable: true, action: "rebuild-plan" },
60
+ AC_CAPABILITY_UNSUPPORTED: { code: "AC_CAPABILITY_UNSUPPORTED", severity: "error", retryable: false, action: "stay-within-single-repository" },
61
+ AC_INTERVENTION_REQUIRED: { code: "AC_INTERVENTION_REQUIRED", severity: "error", retryable: false, action: "enter-intervention-sop" },
62
+ AC_PROOF_REQUIRED: { code: "AC_PROOF_REQUIRED", severity: "warning", retryable: false, action: "execute-proof-point" },
63
+ AC_COMPAT_CONTRACT_REQUIRED: { code: "AC_COMPAT_CONTRACT_REQUIRED", severity: "error", retryable: false, action: "delete-or-contract" },
64
+ AC_USER_CONFIRMATION_REQUIRED: { code: "AC_USER_CONFIRMATION_REQUIRED", severity: "warning", retryable: true, action: "show-human-decision" },
65
+ AC_ENTITLEMENT_REQUIRED: { code: "AC_ENTITLEMENT_REQUIRED", severity: "error", retryable: false, action: "login-or-subscribe" },
66
+ AC_ATTESTATION_REJECTED: { code: "AC_ATTESTATION_REJECTED", severity: "error", retryable: false, action: "review-again" },
67
+ AC_TUNNEL_SCOPE_DENIED: { code: "AC_TUNNEL_SCOPE_DENIED", severity: "error", retryable: false, action: "reduce-scope" }
68
+ };
69
+
70
+ export function okEnvelope<T extends Json>(requestId: string, data: T): JsonEnvelope<T> {
71
+ return { schemaVersion: "archcontext.envelope/v1", ok: true, requestId, data };
72
+ }
73
+
74
+ export function errorEnvelope(requestId: string, code: ArchContextErrorCode, message: string): JsonEnvelope {
75
+ return {
76
+ schemaVersion: "archcontext.envelope/v1",
77
+ ok: false,
78
+ requestId,
79
+ error: { ...ERROR_CATALOG[code], message }
80
+ };
81
+ }
82
+
83
+ export function canonicalize(value: Json): string {
84
+ return JSON.stringify(sortJson(value));
85
+ }
86
+
87
+ export function digestJson(value: Json): string {
88
+ return `sha256:${createHash("sha256").update(canonicalize(value), "utf8").digest("hex")}`;
89
+ }
90
+
91
+ export function stableId(...parts: string[]): string {
92
+ return parts
93
+ .map((part) =>
94
+ part
95
+ .trim()
96
+ .toLowerCase()
97
+ .replace(/[^a-z0-9]+/g, "-")
98
+ .replace(/^-+|-+$/g, "")
99
+ )
100
+ .filter(Boolean)
101
+ .join(".");
102
+ }
103
+
104
+ export function isRepoRelativePosixPath(path: string): boolean {
105
+ return path.length > 0 && !path.startsWith("/") && !path.includes("\\") && !path.split("/").includes("..");
106
+ }
107
+
108
+ export function stableYaml(value: Json, indent = 0): string {
109
+ const pad = " ".repeat(indent);
110
+ if (value === null) return "null\n";
111
+ if (typeof value !== "object") return `${formatScalar(value)}\n`;
112
+ if (Array.isArray(value)) {
113
+ if (value.length === 0) return "[]\n";
114
+ return value
115
+ .map((item) => {
116
+ if (item !== null && typeof item === "object") {
117
+ return `${pad}- ${stableYaml(item, indent + 2).trimStart()}`;
118
+ }
119
+ return `${pad}- ${formatScalar(item)}\n`;
120
+ })
121
+ .join("");
122
+ }
123
+ const keys = Object.keys(value).sort();
124
+ if (keys.length === 0) return "{}\n";
125
+ return keys
126
+ .map((key) => {
127
+ const entry = value[key];
128
+ if (entry !== null && typeof entry === "object") {
129
+ return `${pad}${key}:\n${stableYaml(entry, indent + 2)}`;
130
+ }
131
+ return `${pad}${key}: ${formatScalar(entry)}\n`;
132
+ })
133
+ .join("");
134
+ }
135
+
136
+ function sortJson(value: Json): Json {
137
+ if (value === null || typeof value !== "object") return value;
138
+ if (Array.isArray(value)) return value.map(sortJson);
139
+ return Object.fromEntries(Object.keys(value).sort().map((key) => [key, sortJson(value[key])]));
140
+ }
141
+
142
+ function formatScalar(value: Json): string {
143
+ if (typeof value === "string") return JSON.stringify(value);
144
+ return JSON.stringify(value);
145
+ }