mirai-graph 1.3.0 → 2.1.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 (555) hide show
  1. package/cli.js +6 -0
  2. package/index.js +1 -0
  3. package/package.json +9 -121
  4. package/.github/workflows/ci.yml +0 -48
  5. package/.github/workflows/mirai-graph-validate.yml +0 -30
  6. package/CHANGELOG.md +0 -702
  7. package/CITATION.cff +0 -21
  8. package/LICENSE +0 -21
  9. package/LICENSE-DOCS +0 -26
  10. package/README.md +0 -351
  11. package/ROADMAP.md +0 -241
  12. package/benchmarks/protocols/measure-convert-optimize.md +0 -131
  13. package/benchmarks/synthetic-context-reduction-v0/README.md +0 -70
  14. package/benchmarks/synthetic-context-reduction-v0/RESULT.md +0 -52
  15. package/benchmarks/synthetic-context-reduction-v0/expected/context-pack-compact.md +0 -31
  16. package/benchmarks/synthetic-context-reduction-v0/gates/results.json +0 -12
  17. package/benchmarks/synthetic-context-reduction-v0/graph/objects.json +0 -114
  18. package/benchmarks/synthetic-context-reduction-v0/graph/relations.json +0 -74
  19. package/benchmarks/synthetic-context-reduction-v0/graph.json +0 -37
  20. package/benchmarks/synthetic-context-reduction-v0/metrics/example-metrics.json +0 -22
  21. package/benchmarks/synthetic-context-reduction-v0/results/baseline-comparison-result.json +0 -42
  22. package/benchmarks/synthetic-context-reduction-v0/results/context-pack.json +0 -181
  23. package/benchmarks/synthetic-context-reduction-v0/results/context-reduction-result.json +0 -8
  24. package/benchmarks/synthetic-context-reduction-v0/results/profile-conformance-result.json +0 -28
  25. package/benchmarks/synthetic-context-reduction-v0/results/readiness-score.json +0 -24
  26. package/benchmarks/synthetic-context-reduction-v0/reviews/semantic-completeness-review.json +0 -78
  27. package/benchmarks/synthetic-context-reduction-v0/scripts/calculate-context-reduction.js +0 -42
  28. package/benchmarks/synthetic-context-reduction-v0/source-corpus/audit-events.md +0 -8
  29. package/benchmarks/synthetic-context-reduction-v0/source-corpus/content-workflow.md +0 -8
  30. package/benchmarks/synthetic-context-reduction-v0/source-corpus/identity-access.md +0 -8
  31. package/benchmarks/synthetic-context-reduction-v0/source-corpus/notification-delivery.md +0 -8
  32. package/benchmarks/synthetic-context-reduction-v0/tasks/tasks.json +0 -31
  33. package/docs/README.md +0 -130
  34. package/docs/adoption/adopter-kit.md +0 -187
  35. package/docs/adoption/ai-employee-graph.md +0 -151
  36. package/docs/adoption/character-layer.md +0 -196
  37. package/docs/adoption/choose-profile.md +0 -106
  38. package/docs/adoption/cli.md +0 -134
  39. package/docs/adoption/connect-project-15-minutes.md +0 -122
  40. package/docs/adoption/developer-integration-guide.md +0 -122
  41. package/docs/adoption/end-to-end-control-loop.md +0 -168
  42. package/docs/adoption/for-developers.md +0 -210
  43. package/docs/adoption/getting-started.md +0 -192
  44. package/docs/adoption/mirai-graph-transition.md +0 -67
  45. package/docs/adoption/profile-conformance-fixtures.md +0 -112
  46. package/docs/adoption/seed-to-validated-package.md +0 -121
  47. package/docs/concept.md +0 -109
  48. package/docs/repository-purpose.md +0 -422
  49. package/docs/research/ai-work-field-instrumentation-bridge.md +0 -126
  50. package/docs/research/baseline-comparison-protocol.md +0 -79
  51. package/docs/research/evidence-package-v0.1.md +0 -99
  52. package/docs/research/evidence-package-v0.2.md +0 -150
  53. package/docs/research/evidence-package-v0.3.md +0 -256
  54. package/docs/research/independent-implementation-pilot-plan.md +0 -74
  55. package/docs/research/limitations-and-threats.md +0 -40
  56. package/docs/research/practice-science-program.md +0 -232
  57. package/docs/research/scientific-evidence-package.md +0 -188
  58. package/docs/research/semantic-completeness-review-protocol.md +0 -70
  59. package/docs/terminology.md +0 -119
  60. package/docs/transfer/ai-employee-profile-proposal.md +0 -119
  61. package/docs/transfer/federation-routing-control-loop-2026-05-31.md +0 -28
  62. package/docs/transfer/graph-capability-map-2026-05-29.md +0 -126
  63. package/docs/transfer/graph-skill-to-mirai-graph.md +0 -128
  64. package/docs/transfer/project-management-standard-harvest-2026-06-02.md +0 -322
  65. package/docs/transfer/skill-graph-standard-harvest-2026-05-31.md +0 -113
  66. package/docs/transfer/standard-gap-report-2026-05-28.md +0 -208
  67. package/examples/ai-employee-minimal/README.md +0 -53
  68. package/examples/ai-employee-minimal/gates/results.json +0 -35
  69. package/examples/ai-employee-minimal/graph/objects.json +0 -187
  70. package/examples/ai-employee-minimal/graph/relations.json +0 -167
  71. package/examples/ai-employee-minimal/graph.json +0 -37
  72. package/examples/ai-employee-minimal/results/profile-conformance-result.json +0 -28
  73. package/examples/character-layer-integration-minimal/README.md +0 -25
  74. package/examples/character-layer-integration-minimal/results/character-layer-integration.json +0 -53
  75. package/examples/character-layer-minimal/README.md +0 -29
  76. package/examples/character-layer-minimal/gates/results.json +0 -57
  77. package/examples/character-layer-minimal/graph/objects.json +0 -165
  78. package/examples/character-layer-minimal/graph/relations.json +0 -178
  79. package/examples/character-layer-minimal/graph.json +0 -37
  80. package/examples/character-layer-readiness-1-0/README.md +0 -27
  81. package/examples/character-layer-readiness-1-0/results/character-layer-readiness.json +0 -90
  82. package/examples/dynamic-episode-minimal/README.md +0 -34
  83. package/examples/dynamic-episode-minimal/gates/results.json +0 -12
  84. package/examples/dynamic-episode-minimal/graph/objects.json +0 -92
  85. package/examples/dynamic-episode-minimal/graph/relations.json +0 -29
  86. package/examples/dynamic-episode-minimal/graph.json +0 -47
  87. package/examples/dynamic-episode-minimal/invalid-canonical-write-allowed.json +0 -40
  88. package/examples/dynamic-episode-minimal/invalid-evidence-as-authorization.json +0 -46
  89. package/examples/dynamic-episode-minimal/invalid-missing-event.json +0 -35
  90. package/examples/dynamic-episode-minimal/invalid-missing-selected-path.json +0 -40
  91. package/examples/dynamic-episode-minimal/invalid-unclassified-finding.json +0 -50
  92. package/examples/dynamic-episode-minimal/results/dynamic-episode-trace.json +0 -149
  93. package/examples/federation-routing-smoke/README.md +0 -19
  94. package/examples/federation-routing-smoke/federation-health-dashboard.json +0 -42
  95. package/examples/federation-routing-smoke/route-explanation.json +0 -32
  96. package/examples/federation-routing-smoke/route-regression-result.json +0 -35
  97. package/examples/federation-routing-smoke/routes/production-deploy-execution-evidence.json +0 -17
  98. package/examples/federation-routing-smoke/routes/production-deploy-route-result.json +0 -12
  99. package/examples/federation-routing-smoke/routes/production-deploy-runtime-preflight.json +0 -8
  100. package/examples/federation-routing-smoke/routes/production-deploy-stderr.txt +0 -1
  101. package/examples/federation-routing-smoke/routes/production-deploy-stdout.txt +0 -1
  102. package/examples/federation-routing-smoke/routes/search-page-execution-evidence.json +0 -17
  103. package/examples/federation-routing-smoke/routes/search-page-route-result.json +0 -12
  104. package/examples/federation-routing-smoke/routes/search-page-stderr.txt +0 -1
  105. package/examples/federation-routing-smoke/routes/search-page-stdout.txt +0 -1
  106. package/examples/federation-routing-smoke/routing-fixture-run.json +0 -66
  107. package/examples/federation-routing-smoke/routing-fixtures.json +0 -44
  108. package/examples/goal-vector-quality-control-minimal/README.md +0 -22
  109. package/examples/goal-vector-quality-control-minimal/gates/results.json +0 -22
  110. package/examples/goal-vector-quality-control-minimal/graph/objects.json +0 -56
  111. package/examples/goal-vector-quality-control-minimal/graph/relations.json +0 -29
  112. package/examples/goal-vector-quality-control-minimal/graph.json +0 -41
  113. package/examples/goal-vector-quality-control-minimal/invalid-complete-without-evidence.json +0 -77
  114. package/examples/goal-vector-quality-control-minimal/invalid-correction-without-route.json +0 -86
  115. package/examples/goal-vector-quality-control-minimal/invalid-missing-reverse-audit.json +0 -77
  116. package/examples/goal-vector-quality-control-minimal/invalid-missing-vector-link.json +0 -62
  117. package/examples/goal-vector-quality-control-minimal/invalid-tests-as-acceptance.json +0 -72
  118. package/examples/goal-vector-quality-control-minimal/results/goal-vector-quality-control.json +0 -130
  119. package/examples/graph-dna-alignment-minimal/README.md +0 -16
  120. package/examples/graph-dna-alignment-minimal/graph/objects.json +0 -38
  121. package/examples/graph-dna-alignment-minimal/graph/relations.json +0 -20
  122. package/examples/graph-dna-alignment-minimal/graph.json +0 -37
  123. package/examples/graph-dna-alignment-minimal/results/graph-dna-alignment.json +0 -32
  124. package/examples/graph-seed-minimal/README.md +0 -9
  125. package/examples/graph-seed-minimal/graph-embryo.json +0 -63
  126. package/examples/graph-seed-minimal/graph-seed.json +0 -60
  127. package/examples/implementation-control-cycles/README.md +0 -47
  128. package/examples/implementation-control-cycles/gates/results.json +0 -22
  129. package/examples/implementation-control-cycles/graph/objects.json +0 -119
  130. package/examples/implementation-control-cycles/graph/relations.json +0 -200
  131. package/examples/implementation-control-cycles/graph.json +0 -37
  132. package/examples/implementation-control-cycles/results/implementation-control-cycles.json +0 -456
  133. package/examples/implementation-control-minimal/README.md +0 -39
  134. package/examples/implementation-control-minimal/gates/results.json +0 -42
  135. package/examples/implementation-control-minimal/graph/objects.json +0 -128
  136. package/examples/implementation-control-minimal/graph/relations.json +0 -128
  137. package/examples/implementation-control-minimal/graph.json +0 -37
  138. package/examples/implementation-control-minimal/results/implementation-control-loop.json +0 -21
  139. package/examples/instrumentation-layer-minimal/README.md +0 -32
  140. package/examples/instrumentation-layer-minimal/gates/results.json +0 -11
  141. package/examples/instrumentation-layer-minimal/graph/objects.json +0 -74
  142. package/examples/instrumentation-layer-minimal/graph/relations.json +0 -56
  143. package/examples/instrumentation-layer-minimal/graph.json +0 -37
  144. package/examples/instrumentation-layer-minimal/invalid-cockpit-missing-gates.json +0 -40
  145. package/examples/instrumentation-layer-minimal/invalid-feedback-accepted-with-blocking.json +0 -38
  146. package/examples/instrumentation-layer-minimal/invalid-feedback-process-improvement-without-kaizen.json +0 -38
  147. package/examples/instrumentation-layer-minimal/invalid-traceability-missing-evidence.json +0 -43
  148. package/examples/instrumentation-layer-minimal/results/development-cockpit.json +0 -68
  149. package/examples/instrumentation-layer-minimal/results/feature-implementation-traceability.json +0 -56
  150. package/examples/instrumentation-layer-minimal/results/multi-source-quality-feedback.json +0 -72
  151. package/examples/invalid-character-layer-context-authorization/graph/objects.json +0 -22
  152. package/examples/invalid-character-layer-context-authorization/graph/relations.json +0 -1
  153. package/examples/invalid-character-layer-context-authorization/graph.json +0 -35
  154. package/examples/invalid-character-layer-correction-loop-no-review/graph/objects.json +0 -22
  155. package/examples/invalid-character-layer-correction-loop-no-review/graph/relations.json +0 -1
  156. package/examples/invalid-character-layer-correction-loop-no-review/graph.json +0 -35
  157. package/examples/invalid-character-layer-feedback-auto-update/graph/objects.json +0 -22
  158. package/examples/invalid-character-layer-feedback-auto-update/graph/relations.json +0 -1
  159. package/examples/invalid-character-layer-feedback-auto-update/graph.json +0 -35
  160. package/examples/invalid-character-layer-object-kind/graph/objects.json +0 -22
  161. package/examples/invalid-character-layer-object-kind/graph/relations.json +0 -1
  162. package/examples/invalid-character-layer-object-kind/graph.json +0 -35
  163. package/examples/invalid-character-layer-relation-direction/graph/objects.json +0 -33
  164. package/examples/invalid-character-layer-relation-direction/graph/relations.json +0 -13
  165. package/examples/invalid-character-layer-relation-direction/graph.json +0 -35
  166. package/examples/invalid-character-layer-relation-type/graph/objects.json +0 -33
  167. package/examples/invalid-character-layer-relation-type/graph/relations.json +0 -13
  168. package/examples/invalid-character-layer-relation-type/graph.json +0 -35
  169. package/examples/invalid-character-layer-role-permission/graph/objects.json +0 -22
  170. package/examples/invalid-character-layer-role-permission/graph/relations.json +0 -1
  171. package/examples/invalid-character-layer-role-permission/graph.json +0 -35
  172. package/examples/invalid-context-pack-missing-explanation/context-pack.json +0 -25
  173. package/examples/invalid-missing-relation-target/graph/objects.json +0 -11
  174. package/examples/invalid-missing-relation-target/graph/relations.json +0 -11
  175. package/examples/invalid-missing-relation-target/graph.json +0 -32
  176. package/examples/invalid-profile-object-kind/graph/objects.json +0 -20
  177. package/examples/invalid-profile-object-kind/graph/relations.json +0 -1
  178. package/examples/invalid-profile-object-kind/graph.json +0 -32
  179. package/examples/invalid-profile-relation-type/graph/objects.json +0 -29
  180. package/examples/invalid-profile-relation-type/graph/relations.json +0 -11
  181. package/examples/invalid-profile-relation-type/graph.json +0 -32
  182. package/examples/invalid-relation-id-mismatch/graph/objects.json +0 -29
  183. package/examples/invalid-relation-id-mismatch/graph/relations.json +0 -11
  184. package/examples/invalid-relation-id-mismatch/graph.json +0 -32
  185. package/examples/invalid-seed-unsafe-write/graph-seed.json +0 -27
  186. package/examples/invalid-societal-governance-auto-learning-update/graph/objects.json +0 -29
  187. package/examples/invalid-societal-governance-auto-learning-update/graph/relations.json +0 -11
  188. package/examples/invalid-societal-governance-auto-learning-update/graph.json +0 -35
  189. package/examples/invalid-societal-governance-avatar-no-consent/graph/objects.json +0 -29
  190. package/examples/invalid-societal-governance-avatar-no-consent/graph/relations.json +0 -11
  191. package/examples/invalid-societal-governance-avatar-no-consent/graph.json +0 -35
  192. package/examples/invalid-societal-governance-generated-context-authorization/graph/objects.json +0 -38
  193. package/examples/invalid-societal-governance-generated-context-authorization/graph/relations.json +0 -20
  194. package/examples/invalid-societal-governance-generated-context-authorization/graph.json +0 -35
  195. package/examples/invalid-societal-governance-missing-appeal-path/graph/objects.json +0 -29
  196. package/examples/invalid-societal-governance-missing-appeal-path/graph/relations.json +0 -11
  197. package/examples/invalid-societal-governance-missing-appeal-path/graph.json +0 -35
  198. package/examples/invalid-societal-governance-private-trace-exposed/graph/objects.json +0 -29
  199. package/examples/invalid-societal-governance-private-trace-exposed/graph/relations.json +0 -11
  200. package/examples/invalid-societal-governance-private-trace-exposed/graph.json +0 -35
  201. package/examples/invalid-societal-governance-rights-overridden/graph/objects.json +0 -29
  202. package/examples/invalid-societal-governance-rights-overridden/graph/relations.json +0 -11
  203. package/examples/invalid-societal-governance-rights-overridden/graph.json +0 -35
  204. package/examples/launch-record-minimal/README.md +0 -29
  205. package/examples/launch-record-minimal/gates/results.json +0 -12
  206. package/examples/launch-record-minimal/graph/objects.json +0 -47
  207. package/examples/launch-record-minimal/graph/relations.json +0 -38
  208. package/examples/launch-record-minimal/graph.json +0 -34
  209. package/examples/launch-record-minimal/results/launch-record.json +0 -51
  210. package/examples/managed-project-control-loop/README.md +0 -43
  211. package/examples/managed-project-control-loop/gates/results.json +0 -22
  212. package/examples/managed-project-control-loop/graph/objects.json +0 -119
  213. package/examples/managed-project-control-loop/graph/relations.json +0 -110
  214. package/examples/managed-project-control-loop/graph.json +0 -37
  215. package/examples/managed-project-control-loop/results/managed-loop-result.json +0 -21
  216. package/examples/minimal-graph/README.md +0 -15
  217. package/examples/minimal-graph/gates/results.json +0 -12
  218. package/examples/minimal-graph/graph/objects.json +0 -24
  219. package/examples/minimal-graph/graph/relations.json +0 -11
  220. package/examples/minimal-graph/graph.json +0 -37
  221. package/examples/minimal-graph/results/profile-conformance-result.json +0 -26
  222. package/examples/model-portability-minimal/README.md +0 -15
  223. package/examples/model-portability-minimal/results/model-portability-evidence.json +0 -55
  224. package/examples/organization-governance-minimal/README.md +0 -29
  225. package/examples/organization-governance-minimal/gates/results.json +0 -21
  226. package/examples/organization-governance-minimal/graph/objects.json +0 -147
  227. package/examples/organization-governance-minimal/graph/relations.json +0 -147
  228. package/examples/organization-governance-minimal/graph.json +0 -37
  229. package/examples/organization-governance-minimal/results/profile-conformance-result.json +0 -31
  230. package/examples/process-control-contract-minimal/README.md +0 -19
  231. package/examples/process-control-contract-minimal/graph/objects.json +0 -38
  232. package/examples/process-control-contract-minimal/graph/relations.json +0 -29
  233. package/examples/process-control-contract-minimal/graph.json +0 -34
  234. package/examples/process-control-contract-minimal/results/process-control-contract.json +0 -58
  235. package/examples/process-transition-minimal/README.md +0 -25
  236. package/examples/process-transition-minimal/invalid-missing-launch-record.json +0 -14
  237. package/examples/process-transition-minimal/invalid-ready-to-written.json +0 -14
  238. package/examples/process-transition-minimal/invalid-release-missing-evidence.json +0 -14
  239. package/examples/process-transition-minimal/invalid-sync-to-update.json +0 -14
  240. package/examples/process-transition-minimal/invalid-terminal-missing-kaizen.json +0 -14
  241. package/examples/process-transition-minimal/invalid-tests-to-approved.json +0 -14
  242. package/examples/process-transition-minimal/results/transition-explanation-invalid-ready-to-written.json +0 -35
  243. package/examples/process-transition-minimal/results/transition-explanation-valid.json +0 -34
  244. package/examples/process-transition-minimal/state-machine.json +0 -79
  245. package/examples/process-transition-minimal/transition-request-skip-kaizen.json +0 -14
  246. package/examples/process-transition-minimal/transition-request.json +0 -14
  247. package/examples/project-technology-context-traversal/README.md +0 -17
  248. package/examples/project-technology-context-traversal/graph/objects.json +0 -78
  249. package/examples/project-technology-context-traversal/graph/relations.json +0 -47
  250. package/examples/project-technology-context-traversal/graph.json +0 -30
  251. package/examples/project-technology-context-traversal/selection.example.json +0 -29
  252. package/examples/project-technology-context-traversal/sources/announcement.md +0 -3
  253. package/examples/project-technology-context-traversal/sources/release-guide.md +0 -3
  254. package/examples/project-technology-context-traversal/sources/release-smoke.md +0 -3
  255. package/examples/project-technology-context-traversal/sources/rollback-policy.md +0 -3
  256. package/examples/risk-and-coordination-minimal/README.md +0 -16
  257. package/examples/risk-and-coordination-minimal/graph/objects.json +0 -47
  258. package/examples/risk-and-coordination-minimal/graph/relations.json +0 -29
  259. package/examples/risk-and-coordination-minimal/graph.json +0 -37
  260. package/examples/risk-and-coordination-minimal/results/multi-agent-coordination.json +0 -25
  261. package/examples/risk-and-coordination-minimal/results/risk-control-matrix.json +0 -34
  262. package/examples/self-service-onboarding/bootstrap-proposal/bootstrap-proposal.json +0 -20
  263. package/examples/self-service-onboarding/existing-graph/README.md +0 -4
  264. package/examples/self-service-onboarding/existing-graph/gates/results.json +0 -11
  265. package/examples/self-service-onboarding/existing-graph/graph/objects.json +0 -11
  266. package/examples/self-service-onboarding/existing-graph/graph/relations.json +0 -1
  267. package/examples/self-service-onboarding/existing-graph/graph.json +0 -36
  268. package/examples/self-service-onboarding/no-graph/README.md +0 -6
  269. package/examples/self-service-onboarding/no-graph/package.json +0 -6
  270. package/examples/self-service-onboarding/no-graph/src/index.js +0 -3
  271. package/examples/self-service-onboarding/stale-graph/README.md +0 -4
  272. package/examples/self-service-onboarding/stale-graph/graph.json +0 -36
  273. package/examples/semantic-intent-resolution-minimal/README.md +0 -13
  274. package/examples/semantic-intent-resolution-minimal/invalid-low-confidence-executes.json +0 -26
  275. package/examples/semantic-intent-resolution-minimal/invalid-proposal-canonical-update.json +0 -27
  276. package/examples/semantic-intent-resolution-minimal/results/semantic-intent-resolution.json +0 -45
  277. package/examples/skill-runtime-minimal/README.md +0 -29
  278. package/examples/skill-runtime-minimal/gates/results.json +0 -35
  279. package/examples/skill-runtime-minimal/graph/objects.json +0 -209
  280. package/examples/skill-runtime-minimal/graph/relations.json +0 -178
  281. package/examples/skill-runtime-minimal/graph.json +0 -37
  282. package/examples/skill-runtime-minimal/results/profile-conformance-result.json +0 -27
  283. package/examples/societal-governance-minimal/README.md +0 -37
  284. package/examples/societal-governance-minimal/graph/objects.json +0 -218
  285. package/examples/societal-governance-minimal/graph/relations.json +0 -209
  286. package/examples/societal-governance-minimal/graph.json +0 -37
  287. package/examples/source-boundary-minimal/README.md +0 -16
  288. package/examples/source-boundary-minimal/graph/objects.json +0 -38
  289. package/examples/source-boundary-minimal/graph/relations.json +0 -20
  290. package/examples/source-boundary-minimal/graph.json +0 -37
  291. package/examples/source-boundary-minimal/results/source-boundary-contract.json +0 -37
  292. package/examples/technology-quality-feedback-minimal/README.md +0 -33
  293. package/examples/technology-quality-feedback-minimal/graph/objects.json +0 -56
  294. package/examples/technology-quality-feedback-minimal/graph/relations.json +0 -47
  295. package/examples/technology-quality-feedback-minimal/graph.json +0 -34
  296. package/examples/technology-quality-feedback-minimal/invalid-accepted-with-blocking.json +0 -33
  297. package/examples/technology-quality-feedback-minimal/invalid-evidence-as-authorization.json +0 -22
  298. package/examples/technology-quality-feedback-minimal/invalid-missing-required-step.json +0 -22
  299. package/examples/technology-quality-feedback-minimal/invalid-process-improvement-without-kaizen.json +0 -33
  300. package/examples/technology-quality-feedback-minimal/invalid-spec-gap-without-route.json +0 -33
  301. package/examples/technology-quality-feedback-minimal/invalid-unclassified-finding.json +0 -33
  302. package/examples/technology-quality-feedback-minimal/results/technology-quality-feedback.json +0 -80
  303. package/examples/work-recovery-minimal/README.md +0 -15
  304. package/examples/work-recovery-minimal/graph/objects.json +0 -47
  305. package/examples/work-recovery-minimal/graph/relations.json +0 -20
  306. package/examples/work-recovery-minimal/graph.json +0 -37
  307. package/examples/work-recovery-minimal/results/recovery-resume-record.json +0 -17
  308. package/examples/work-recovery-minimal/results/work-state-machine.json +0 -21
  309. package/packages/cli/adopter-workflow.js +0 -228
  310. package/packages/cli/context-pack.js +0 -269
  311. package/packages/cli/graph-manifest.js +0 -367
  312. package/packages/cli/instrumentation-report.js +0 -97
  313. package/packages/cli/migrate-graph-manifest.js +0 -33
  314. package/packages/cli/mirai-graph.js +0 -154
  315. package/packages/cli/mirai_graph.js +0 -3
  316. package/packages/cli/playground-demo.js +0 -114
  317. package/packages/cli/project-technology.js +0 -129
  318. package/packages/cli/readiness-score.js +0 -164
  319. package/packages/cli/release-state.js +0 -329
  320. package/packages/cli/seed-preview.js +0 -78
  321. package/packages/cli/self-service-onboarding.js +0 -386
  322. package/packages/cli/validate-adopter-workflow.js +0 -63
  323. package/packages/cli/validate-artifact-releases.js +0 -282
  324. package/packages/cli/validate-baseline-comparison.js +0 -105
  325. package/packages/cli/validate-context-traversal.js +0 -292
  326. package/packages/cli/validate-graph-manifest-migration.js +0 -64
  327. package/packages/cli/validate-mirai-graph.js +0 -3245
  328. package/packages/cli/validate-process-transition-report.js +0 -105
  329. package/packages/cli/validate-profile-results.js +0 -64
  330. package/packages/cli/validate-project-continuity.js +0 -173
  331. package/packages/cli/validate-project-technology.js +0 -296
  332. package/packages/cli/validate-release-state.js +0 -100
  333. package/packages/cli/validate-routing-control-examples.js +0 -79
  334. package/packages/cli/validate-self-service-onboarding.js +0 -159
  335. package/packages/project-technology/artifact-release.js +0 -738
  336. package/packages/project-technology/context-traversal.js +0 -684
  337. package/packages/project-technology/continuity.js +0 -414
  338. package/packages/project-technology/index.js +0 -835
  339. package/pilots/independent-implementation-001-conference-planning/README.md +0 -40
  340. package/pilots/independent-implementation-001-conference-planning/gates/results.json +0 -12
  341. package/pilots/independent-implementation-001-conference-planning/graph/objects.json +0 -74
  342. package/pilots/independent-implementation-001-conference-planning/graph/relations.json +0 -56
  343. package/pilots/independent-implementation-001-conference-planning/graph-seed.json +0 -65
  344. package/pilots/independent-implementation-001-conference-planning/graph.json +0 -37
  345. package/pilots/independent-implementation-001-conference-planning/reports/pilot-report.md +0 -120
  346. package/pilots/independent-implementation-001-conference-planning/results/context-pack.json +0 -35
  347. package/pilots/independent-implementation-001-conference-planning/results/graph-embryo.json +0 -81
  348. package/pilots/independent-implementation-001-conference-planning/results/package-validation.json +0 -7
  349. package/pilots/independent-implementation-001-conference-planning/results/profile-conformance-result.json +0 -28
  350. package/pilots/independent-implementation-001-conference-planning/results/readiness-score.json +0 -26
  351. package/pilots/independent-implementation-001-conference-planning/results/seed-validation.json +0 -7
  352. package/pilots/independent-implementation-002-software-specification/README.md +0 -40
  353. package/pilots/independent-implementation-002-software-specification/gates/results.json +0 -22
  354. package/pilots/independent-implementation-002-software-specification/graph/objects.json +0 -101
  355. package/pilots/independent-implementation-002-software-specification/graph/relations.json +0 -92
  356. package/pilots/independent-implementation-002-software-specification/graph-seed.json +0 -72
  357. package/pilots/independent-implementation-002-software-specification/graph.json +0 -37
  358. package/pilots/independent-implementation-002-software-specification/reports/pilot-report.md +0 -142
  359. package/pilots/independent-implementation-002-software-specification/results/context-pack.json +0 -184
  360. package/pilots/independent-implementation-002-software-specification/results/graph-embryo.json +0 -90
  361. package/pilots/independent-implementation-002-software-specification/results/package-validation.json +0 -7
  362. package/pilots/independent-implementation-002-software-specification/results/profile-conformance-result.json +0 -28
  363. package/pilots/independent-implementation-002-software-specification/results/readiness-score.json +0 -26
  364. package/pilots/independent-implementation-002-software-specification/results/seed-validation.json +0 -7
  365. package/pilots/independent-implementation-002-software-specification/reviews/semantic-completeness-review.json +0 -81
  366. package/pilots/independent-implementation-003-ai-employee-workflow/README.md +0 -42
  367. package/pilots/independent-implementation-003-ai-employee-workflow/gates/results.json +0 -30
  368. package/pilots/independent-implementation-003-ai-employee-workflow/graph/objects.json +0 -156
  369. package/pilots/independent-implementation-003-ai-employee-workflow/graph/relations.json +0 -147
  370. package/pilots/independent-implementation-003-ai-employee-workflow/graph-seed.json +0 -90
  371. package/pilots/independent-implementation-003-ai-employee-workflow/graph.json +0 -37
  372. package/pilots/independent-implementation-003-ai-employee-workflow/reports/pilot-report.md +0 -49
  373. package/pilots/independent-implementation-003-ai-employee-workflow/results/profile-conformance-result.json +0 -30
  374. package/pilots/independent-implementation-004-research-program/README.md +0 -41
  375. package/pilots/independent-implementation-004-research-program/gates/results.json +0 -21
  376. package/pilots/independent-implementation-004-research-program/graph/objects.json +0 -102
  377. package/pilots/independent-implementation-004-research-program/graph/relations.json +0 -84
  378. package/pilots/independent-implementation-004-research-program/graph-seed.json +0 -76
  379. package/pilots/independent-implementation-004-research-program/graph.json +0 -37
  380. package/pilots/independent-implementation-004-research-program/reports/pilot-report.md +0 -50
  381. package/pilots/independent-implementation-004-research-program/results/profile-conformance-result.json +0 -30
  382. package/pilots/independent-implementation-005-organization-governance/README.md +0 -42
  383. package/pilots/independent-implementation-005-organization-governance/gates/results.json +0 -20
  384. package/pilots/independent-implementation-005-organization-governance/graph/objects.json +0 -137
  385. package/pilots/independent-implementation-005-organization-governance/graph/relations.json +0 -110
  386. package/pilots/independent-implementation-005-organization-governance/graph-seed.json +0 -97
  387. package/pilots/independent-implementation-005-organization-governance/graph.json +0 -37
  388. package/pilots/independent-implementation-005-organization-governance/reports/pilot-report.md +0 -47
  389. package/pilots/independent-implementation-005-organization-governance/results/profile-conformance-result.json +0 -29
  390. package/playground/README.md +0 -78
  391. package/playground/demo-report.md +0 -84
  392. package/profiles/README.md +0 -28
  393. package/profiles/ai-employee/README.md +0 -132
  394. package/profiles/ai-employee/profile.json +0 -58
  395. package/profiles/character-layer/README.md +0 -143
  396. package/profiles/character-layer/profile.json +0 -46
  397. package/profiles/implementation-control/README.md +0 -174
  398. package/profiles/implementation-control/profile.json +0 -108
  399. package/profiles/organization-governance/README.md +0 -60
  400. package/profiles/organization-governance/profile.json +0 -56
  401. package/profiles/project-management/README.md +0 -119
  402. package/profiles/project-management/profile.json +0 -38
  403. package/profiles/skill-runtime/README.md +0 -99
  404. package/profiles/skill-runtime/profile.json +0 -58
  405. package/profiles/societal-governance/README.md +0 -129
  406. package/profiles/societal-governance/profile.json +0 -121
  407. package/profiles/software-specification/README.md +0 -142
  408. package/profiles/software-specification/profile.json +0 -31
  409. package/publications/README.md +0 -39
  410. package/publications/observable-self-correcting-ai-workflows/README.md +0 -105
  411. package/publications/preprint-note.md +0 -11
  412. package/publications/preprint-outline.md +0 -45
  413. package/publications/semantic-intent-goal-vector-control/README.md +0 -99
  414. package/releases/0.1.0-alpha.0.md +0 -45
  415. package/releases/0.1.0-alpha.1.md +0 -63
  416. package/releases/0.1.0-alpha.10.md +0 -93
  417. package/releases/0.1.0-alpha.11.md +0 -114
  418. package/releases/0.1.0-alpha.2.md +0 -37
  419. package/releases/0.1.0-alpha.3.md +0 -61
  420. package/releases/0.1.0-alpha.4.md +0 -53
  421. package/releases/0.1.0-alpha.5.md +0 -48
  422. package/releases/0.1.0-alpha.6.md +0 -96
  423. package/releases/0.1.0-alpha.7.md +0 -114
  424. package/releases/0.1.0-alpha.8.md +0 -92
  425. package/releases/0.1.0-alpha.9.md +0 -80
  426. package/releases/1.0.0-rc.1.md +0 -121
  427. package/releases/1.0.0-rc.10.md +0 -14
  428. package/releases/1.0.0-rc.11.md +0 -14
  429. package/releases/1.0.0-rc.2.md +0 -79
  430. package/releases/1.0.0-rc.3.md +0 -51
  431. package/releases/1.0.0-rc.4.md +0 -70
  432. package/releases/1.0.0-rc.5.md +0 -88
  433. package/releases/1.0.0-rc.6.md +0 -76
  434. package/releases/1.0.0-rc.8.md +0 -17
  435. package/releases/1.0.0-rc.9.md +0 -14
  436. package/releases/1.0.0.md +0 -23
  437. package/releases/1.1.0.md +0 -36
  438. package/releases/1.1.1.md +0 -25
  439. package/releases/1.2.0.md +0 -19
  440. package/releases/1.3.0.md +0 -16
  441. package/releases/README.md +0 -135
  442. package/releases/societal-governance-profile-proposal.md +0 -45
  443. package/schemas/baseline-comparison-result.schema.json +0 -87
  444. package/schemas/character-layer-integration.schema.json +0 -112
  445. package/schemas/character-layer-readiness.schema.json +0 -73
  446. package/schemas/context-pack.schema.json +0 -190
  447. package/schemas/context-traversal-receipt.schema.json +0 -64
  448. package/schemas/development-cockpit.schema.json +0 -74
  449. package/schemas/dynamic-episode-trace.schema.json +0 -153
  450. package/schemas/feature-implementation-traceability.schema.json +0 -80
  451. package/schemas/federation-health-dashboard.schema.json +0 -47
  452. package/schemas/gate-result.schema.json +0 -44
  453. package/schemas/goal-vector-quality-control.schema.json +0 -131
  454. package/schemas/graph-dna-alignment.schema.json +0 -49
  455. package/schemas/graph-embryo.schema.json +0 -51
  456. package/schemas/graph-lock.schema.json +0 -28
  457. package/schemas/graph-manifest.schema.json +0 -154
  458. package/schemas/graph-seed.schema.json +0 -137
  459. package/schemas/implementation-control-cycle.schema.json +0 -265
  460. package/schemas/implementation-control-loop.schema.json +0 -84
  461. package/schemas/launch-record.schema.json +0 -78
  462. package/schemas/model-portability-evidence.schema.json +0 -93
  463. package/schemas/multi-agent-coordination.schema.json +0 -35
  464. package/schemas/multi-source-quality-feedback.schema.json +0 -54
  465. package/schemas/object.schema.json +0 -49
  466. package/schemas/package-manifest.schema.json +0 -53
  467. package/schemas/process-control-contract.schema.json +0 -100
  468. package/schemas/process-transition-request.schema.json +0 -41
  469. package/schemas/profile.schema.json +0 -56
  470. package/schemas/project-technology-extension.schema.json +0 -15
  471. package/schemas/project-technology-target-export.schema.json +0 -35
  472. package/schemas/readiness-score.schema.json +0 -43
  473. package/schemas/recovery-resume-record.schema.json +0 -25
  474. package/schemas/relation.schema.json +0 -43
  475. package/schemas/risk-control-matrix.schema.json +0 -36
  476. package/schemas/route-explanation.schema.json +0 -51
  477. package/schemas/route-regression-result.schema.json +0 -33
  478. package/schemas/routing-fixture-run.schema.json +0 -45
  479. package/schemas/routing-fixtures.schema.json +0 -59
  480. package/schemas/semantic-intent-resolution.schema.json +0 -151
  481. package/schemas/source-boundary-contract.schema.json +0 -31
  482. package/schemas/technology-quality-feedback.schema.json +0 -116
  483. package/schemas/work-state-machine.schema.json +0 -34
  484. package/standard/action-runtime-boundary.md +0 -99
  485. package/standard/adoption-levels.md +0 -69
  486. package/standard/conformance-levels.md +0 -133
  487. package/standard/context-pack-generation.md +0 -184
  488. package/standard/development-cockpit.md +0 -67
  489. package/standard/dynamic-episode-layer.md +0 -113
  490. package/standard/dynamic-layer-code-generation.md +0 -87
  491. package/standard/episode-trace.md +0 -97
  492. package/standard/evidence-provenance.md +0 -128
  493. package/standard/feature-implementation-traceability.md +0 -68
  494. package/standard/federation-health.md +0 -42
  495. package/standard/feedback-learning-gate.md +0 -101
  496. package/standard/goal-vector-quality-control.md +0 -128
  497. package/standard/governance.md +0 -137
  498. package/standard/graph-as-ai-brain.md +0 -81
  499. package/standard/graph-dna-alignment.md +0 -50
  500. package/standard/graph-dna.md +0 -70
  501. package/standard/graph-embryo.md +0 -69
  502. package/standard/graph-seed.md +0 -122
  503. package/standard/hybrid-source-of-truth.md +0 -91
  504. package/standard/implementation-control-cycles.md +0 -194
  505. package/standard/implementation-control.md +0 -102
  506. package/standard/launch-record.md +0 -53
  507. package/standard/lifecycle-readiness.md +0 -159
  508. package/standard/multi-agent-coordination.md +0 -50
  509. package/standard/multi-source-quality-feedback.md +0 -71
  510. package/standard/object-model.md +0 -167
  511. package/standard/organization-governance.md +0 -83
  512. package/standard/process-control-contract.md +0 -53
  513. package/standard/profile-boundaries.md +0 -225
  514. package/standard/profiles.md +0 -253
  515. package/standard/project-technology.md +0 -186
  516. package/standard/projection-views.md +0 -69
  517. package/standard/recovery-resume.md +0 -49
  518. package/standard/relation-model.md +0 -149
  519. package/standard/risk-control-matrix.md +0 -53
  520. package/standard/route-explanation.md +0 -35
  521. package/standard/route-regression.md +0 -33
  522. package/standard/routing-fixtures.md +0 -54
  523. package/standard/runtime-enablement.md +0 -85
  524. package/standard/semantic-intent-resolution.md +0 -91
  525. package/standard/source-boundary-contract.md +0 -49
  526. package/standard/standard-v0.1.md +0 -132
  527. package/standard/technology-quality-feedback.md +0 -97
  528. package/standard/test-suite.md +0 -159
  529. package/standard/work-state-machine.md +0 -62
  530. package/templates/README.md +0 -77
  531. package/templates/ai-employee-starter/README.md +0 -9
  532. package/templates/ai-employee-starter/gates/results.json +0 -12
  533. package/templates/ai-employee-starter/graph/objects.json +0 -90
  534. package/templates/ai-employee-starter/graph/relations.json +0 -47
  535. package/templates/ai-employee-starter/graph.json +0 -37
  536. package/templates/character-layer-starter/README.md +0 -39
  537. package/templates/character-layer-starter/gates/results.json +0 -20
  538. package/templates/character-layer-starter/graph/objects.json +0 -308
  539. package/templates/character-layer-starter/graph/relations.json +0 -344
  540. package/templates/character-layer-starter/graph.json +0 -37
  541. package/templates/organization-governance-starter/README.md +0 -9
  542. package/templates/organization-governance-starter/gates/results.json +0 -12
  543. package/templates/organization-governance-starter/graph/objects.json +0 -112
  544. package/templates/organization-governance-starter/graph/relations.json +0 -65
  545. package/templates/organization-governance-starter/graph.json +0 -37
  546. package/templates/research-program-starter/README.md +0 -9
  547. package/templates/research-program-starter/gates/results.json +0 -12
  548. package/templates/research-program-starter/graph/objects.json +0 -79
  549. package/templates/research-program-starter/graph/relations.json +0 -47
  550. package/templates/research-program-starter/graph.json +0 -37
  551. package/templates/software-project-starter/README.md +0 -9
  552. package/templates/software-project-starter/gates/results.json +0 -12
  553. package/templates/software-project-starter/graph/objects.json +0 -79
  554. package/templates/software-project-starter/graph/relations.json +0 -47
  555. package/templates/software-project-starter/graph.json +0 -37
@@ -1,684 +0,0 @@
1
- "use strict";
2
-
3
- const crypto = require("crypto");
4
- const fs = require("fs");
5
- const path = require("path");
6
- const { spawnSync } = require("child_process");
7
- const { readJson, validateManifest } = require("../cli/graph-manifest");
8
-
9
- const RECEIPT_CONTRACT = "context-traversal-receipt";
10
- const RECEIPT_VERSION = "1.0.0";
11
- const REQUIRED_RELATIONS = new Set(["requires", "governed_by", "validated_by"]);
12
- const STRUCTURAL_RELATIONS = new Set(["contains", "specializes"]);
13
- const SOURCE_RELATIONS = new Set(["documented_by", "implemented_by"]);
14
- const SUPPORTED_RELATIONS = new Set([
15
- ...STRUCTURAL_RELATIONS,
16
- ...REQUIRED_RELATIONS,
17
- ...SOURCE_RELATIONS,
18
- "hands_off_to",
19
- "conflicts_with",
20
- ]);
21
- const TERMINAL_KINDS = new Set(["resource", "source", "check", "gate", "constraint"]);
22
- const ACTIVE_READINESS = new Set(["ready", "accepted", "implemented", "validated", "operating", "evolving", "pilot"]);
23
- const LEGACY_ACTIVE_READINESS = new Set([
24
- "r3_structured", "r3_specified", "r4_integrated", "r4_validated",
25
- "r4_executable", "r4_evidence_ready", "a4_validated_projection",
26
- "a6_accepted_local_candidate", "t5_implementation_ready",
27
- "active_controlled_paid_test",
28
- ]);
29
- const BLOCKING_READINESS = new Set(["blocked", "deprecated", "stale", "retired", "superseded"]);
30
- const SECRET_PARTS = [".env", "credential", "secret", "token", "password", "cookie", "private-key", "id_rsa", ".pem", ".p12"];
31
-
32
- function sortValue(value) {
33
- if (Array.isArray(value)) return value.map(sortValue);
34
- if (!value || typeof value !== "object") return value;
35
- return Object.fromEntries(Object.keys(value).sort().map((key) => [key, sortValue(value[key])]));
36
- }
37
-
38
- function canonicalBytes(value) {
39
- return `${JSON.stringify(sortValue(value), null, 2)}\n`;
40
- }
41
-
42
- function digest(value) {
43
- const bytes = Buffer.isBuffer(value) ? value : Buffer.from(typeof value === "string" ? value : canonicalBytes(value));
44
- return `sha256:${crypto.createHash("sha256").update(bytes).digest("hex")}`;
45
- }
46
-
47
- function unique(values) {
48
- return [...new Set(values.filter((value) => typeof value === "string" && value.trim()).map((value) => value.trim()))].sort();
49
- }
50
-
51
- function git(repo, ...args) {
52
- const completed = spawnSync("git", args, { cwd: repo, encoding: "utf8", maxBuffer: 64 * 1024 * 1024 });
53
- return completed.status === 0 ? completed.stdout.trim() : "";
54
- }
55
-
56
- function gitBlob(repo, relative) {
57
- if (!relative || !git(repo, "ls-files", "--error-unmatch", "--", relative)) return null;
58
- const completed = spawnSync("git", ["show", `HEAD:${relative}`], { cwd: repo, encoding: null, maxBuffer: 64 * 1024 * 1024 });
59
- return completed.status === 0 ? completed.stdout : null;
60
- }
61
-
62
- function trackedState(repo) {
63
- const trackedRun = spawnSync("git", ["ls-files", "-z"], { cwd: repo, encoding: "utf8", maxBuffer: 64 * 1024 * 1024 });
64
- const dirtyRun = spawnSync("git", ["diff", "--name-only", "-z", "HEAD", "--"], { cwd: repo, encoding: "utf8", maxBuffer: 64 * 1024 * 1024 });
65
- return {
66
- hasGit: Boolean(git(repo, "rev-parse", "--is-inside-work-tree")),
67
- tracked: new Set(trackedRun.status === 0 ? trackedRun.stdout.split("\0").filter(Boolean) : []),
68
- dirty: new Set(dirtyRun.status === 0 ? dirtyRun.stdout.split("\0").filter(Boolean) : []),
69
- };
70
- }
71
-
72
- function graphBlob(graph, relative) {
73
- if (!graph.hasGit) {
74
- const absolute = path.join(graph.repo, relative);
75
- return fs.existsSync(absolute) && !fs.lstatSync(absolute).isSymbolicLink() && fs.statSync(absolute).isFile() ? fs.readFileSync(absolute) : null;
76
- }
77
- if (!graph.tracked?.has(relative) || graph.dirty?.has(relative)) return null;
78
- if (!graph.blobCache.has(relative)) graph.blobCache.set(relative, gitBlob(graph.repo, relative));
79
- return graph.blobCache.get(relative);
80
- }
81
-
82
- function revisionBound(repo, relative) {
83
- if (!git(repo, "rev-parse", "--is-inside-work-tree")) {
84
- const absolute = path.join(repo, relative);
85
- return fs.existsSync(absolute) && !fs.lstatSync(absolute).isSymbolicLink() && fs.statSync(absolute).isFile();
86
- }
87
- if (!gitBlob(repo, relative)) return false;
88
- return spawnSync("git", ["diff", "--quiet", "HEAD", "--", relative], { cwd: repo }).status === 0;
89
- }
90
-
91
- function safeRelative(value) {
92
- if (typeof value !== "string" || !value.trim() || path.isAbsolute(value)) return false;
93
- const lowered = value.toLowerCase();
94
- if (value.split(/[\\/]+/).includes("..")) return false;
95
- if (lowered.startsWith("source/private/") || lowered.includes("/source/private/")) return false;
96
- return !SECRET_PARTS.some((part) => lowered.includes(part));
97
- }
98
-
99
- function safeRef(value) {
100
- if (typeof value !== "string" || !value.trim() || value.length > 512) return false;
101
- if (/^(repo|https):\/\//.test(value)) return !SECRET_PARTS.some((part) => value.toLowerCase().includes(part));
102
- return safeRelative(value);
103
- }
104
-
105
- const LEGACY_RELATION_TYPES = new Map([
106
- ["implements", { type: "contains" }],
107
- ["has_capability", { type: "contains" }],
108
- ["uses_process", { type: "contains" }],
109
- ["includes", { type: "contains" }],
110
- ["member_of", { type: "contains", reverse: true }],
111
- ["refines", { type: "specializes" }],
112
- ["depends_on", { type: "requires" }],
113
- ["requires_current_source_check", { type: "requires" }],
114
- ["requires_gate", { type: "validated_by" }],
115
- ["requires_quality_gate", { type: "validated_by" }],
116
- ["tested_by_scenario", { type: "validated_by" }],
117
- ["validates", { type: "validated_by", reverse: true }],
118
- ["assessed_by", { type: "validated_by" }],
119
- ["blocked_without_gate", { type: "validated_by" }],
120
- ["conforms_to", { type: "governed_by" }],
121
- ["constrained_by", { type: "governed_by" }],
122
- ["evidenced_by", { type: "documented_by" }],
123
- ]);
124
-
125
- function normalizeObject(value) {
126
- const normalized = { ...value };
127
- if (!normalized.kind && normalized.type) normalized.kind = normalized.type;
128
- if (!normalized.readiness) normalized.readiness = normalized.lifecycle || normalized.status || "accepted";
129
- if (!value.kind) delete normalized.type;
130
- return normalized;
131
- }
132
-
133
- function normalizeRelation(value) {
134
- const legacyType = value.type || value.relation_type;
135
- const mapping = LEGACY_RELATION_TYPES.get(legacyType) || { type: legacyType };
136
- let source = value.source || value.from;
137
- let target = value.target || value.to;
138
- if (mapping.reverse) [source, target] = [target, source];
139
- const normalized = {
140
- ...value,
141
- type: mapping.type,
142
- source,
143
- target,
144
- readiness: value.readiness || value.status || value.lifecycle || "accepted",
145
- };
146
- delete normalized.from;
147
- delete normalized.to;
148
- delete normalized.relation_type;
149
- delete normalized.status;
150
- return normalized;
151
- }
152
-
153
- function loadEntry(repo, relative, kind, output, visited = new Set()) {
154
- if (!safeRelative(relative) || visited.has(relative)) return;
155
- visited.add(relative);
156
- const absolute = path.join(repo, relative);
157
- if (!fs.existsSync(absolute) || fs.lstatSync(absolute).isSymbolicLink() || !fs.statSync(absolute).isFile()) return;
158
- let payload;
159
- try { payload = readJson(absolute); } catch (_) { output.blockers.push(`invalid_${kind}_entry`); return; }
160
- const add = (item) => {
161
- if (!item || typeof item !== "object" || Array.isArray(item)) return;
162
- output[kind].push({ value: item, relative, sha256: digest(fs.readFileSync(absolute)) });
163
- };
164
- if (Array.isArray(payload)) payload.forEach(add);
165
- else if (Array.isArray(payload[kind])) payload[kind].forEach(add);
166
- else {
167
- const files = kind === "objects" ? payload.object_files : payload.relation_files;
168
- if (Array.isArray(files)) {
169
- for (const child of files) {
170
- const next = child.startsWith("graph/") ? child : path.posix.join(path.posix.dirname(relative), child);
171
- loadEntry(repo, next, kind, output, visited);
172
- }
173
- } else add(payload);
174
- }
175
- }
176
-
177
- function readGraph(repoArg) {
178
- const repo = path.resolve(repoArg || ".");
179
- const manifestPath = path.join(repo, "graph.json");
180
- const output = { objects: [], relations: [], blockers: [] };
181
- if (!fs.existsSync(manifestPath) || fs.lstatSync(manifestPath).isSymbolicLink()) {
182
- return { repo, manifest: null, revision: null, graphDigest: null, ...output, blockers: ["graph_manifest_missing_or_unsafe"] };
183
- }
184
- let manifest;
185
- try { manifest = readJson(manifestPath); } catch (_) {
186
- return { repo, manifest: null, revision: null, graphDigest: null, ...output, blockers: ["graph_manifest_invalid"] };
187
- }
188
- output.blockers.push(...validateManifest(manifest, repo));
189
- for (const relative of manifest.graph?.objects || []) loadEntry(repo, relative, "objects", output);
190
- for (const relative of manifest.graph?.relations || []) loadEntry(repo, relative, "relations", output);
191
- const objects = new Map();
192
- for (const record of output.objects) {
193
- const normalized = normalizeObject(record.value);
194
- const id = String(normalized.id || "").trim();
195
- if (!id || objects.has(id)) { output.blockers.push(id ? "duplicate_object_id" : "object_id_missing"); continue; }
196
- objects.set(id, { ...record, value: normalized });
197
- }
198
- const relations = [];
199
- const relationIds = new Set();
200
- for (const record of output.relations) {
201
- const relation = normalizeRelation(record.value);
202
- const id = String(relation.id || "").trim();
203
- if (!id || relationIds.has(id)) { output.blockers.push(id ? "duplicate_relation_id" : "relation_id_missing"); continue; }
204
- relationIds.add(id);
205
- if (!SUPPORTED_RELATIONS.has(relation.type)) continue;
206
- if (!objects.has(relation.source) || !objects.has(relation.target)) { output.blockers.push("relation_endpoint_missing"); continue; }
207
- relations.push({ ...relation, _record: record });
208
- }
209
- const state = trackedState(repo);
210
- const graphSources = unique([
211
- "graph.json",
212
- ...[...objects.values()].map((record) => record.relative),
213
- ...relations.map((relation) => relation._record.relative),
214
- ]);
215
- const newContentBoundGraph = state.hasGit
216
- && graphSources.length > 0
217
- && graphSources.every((relative) => !state.tracked.has(relative))
218
- && graphSources.every((relative) => !state.dirty.has(relative));
219
- for (const relative of graphSources) if (state.hasGit && !newContentBoundGraph && (!state.tracked.has(relative) || state.dirty.has(relative))) output.blockers.push("graph_source_not_revision_bound");
220
- const gitRevision = !newContentBoundGraph ? git(repo, "rev-parse", "HEAD") || null : null;
221
- const graphPayloadBase = {
222
- manifest: { id: manifest.id, scope: manifest.scope, profiles: manifest.profiles, graph: manifest.graph },
223
- objects: [...objects.values()].map((record) => record.value).sort((a, b) => a.id.localeCompare(b.id)),
224
- relations: relations.map(({ _record, ...relation }) => relation).sort((a, b) => a.id.localeCompare(b.id)),
225
- };
226
- const revision = gitRevision || `content:${digest(graphPayloadBase).slice(7)}`;
227
- const graphPayload = { ...graphPayloadBase, revision };
228
- return {
229
- repo,
230
- manifest,
231
- revision,
232
- graphDigest: digest(graphPayload),
233
- objects,
234
- relations,
235
- tracked: state.tracked,
236
- dirty: state.dirty,
237
- hasGit: state.hasGit,
238
- blobCache: new Map(),
239
- blockers: unique(output.blockers),
240
- };
241
- }
242
-
243
- function tokenize(value) {
244
- return unique(String(value || "").toLowerCase().split(/[^a-zа-я0-9_]+/i).filter((item) => item.length > 2));
245
- }
246
-
247
- function readinessOf(object) {
248
- return String(object.readiness || object.lifecycle || object.status || "unknown").toLowerCase();
249
- }
250
-
251
- function activeReadiness(value) {
252
- const normalized = String(value || "").toLowerCase();
253
- return ACTIVE_READINESS.has(normalized) || LEGACY_ACTIVE_READINESS.has(normalized);
254
- }
255
-
256
- function outgoing(graph, id) {
257
- return graph.relations.filter((relation) => relation.source === id);
258
- }
259
-
260
- function sourcePassport(graph, record, value) {
261
- const raw = [...(Array.isArray(value.source_refs) ? value.source_refs : []), ...(Array.isArray(value.evidence) ? value.evidence : [])];
262
- const declared = new Map();
263
- for (const item of raw) {
264
- const ref = typeof item === "string" ? item : item?.ref;
265
- if (!safeRef(ref) || declared.has(ref)) continue;
266
- declared.set(ref, typeof item === "object" && item ? item : { ref });
267
- }
268
- return [...declared].sort(([left], [right]) => left.localeCompare(right)).map(([ref, metadata]) => {
269
- if (/^(repo|https):\/\//.test(ref)) return {
270
- ref,
271
- availability: metadata.availability || "declared",
272
- revision: metadata.revision || graph.revision,
273
- sha256: metadata.sha256 || metadata.digest || null,
274
- };
275
- const absolute = path.join(graph.repo, ref);
276
- if (!fs.existsSync(absolute) || fs.lstatSync(absolute).isSymbolicLink() || !fs.statSync(absolute).isFile()) {
277
- return { ref, availability: "unavailable", revision: graph.revision, sha256: null };
278
- }
279
- const blob = graphBlob(graph, ref);
280
- return { ref, availability: blob ? "available" : "unbound", revision: graph.revision, sha256: digest(blob || fs.readFileSync(absolute)) };
281
- }).concat([{ ref: record.relative, availability: "available", revision: graph.revision, sha256: record.sha256 }]);
282
- }
283
-
284
- function nodePassport(graph, id) {
285
- const record = graph.objects.get(id);
286
- if (!record) return null;
287
- const value = record.value;
288
- const children = outgoing(graph, id);
289
- const computedExpandable = children.length > 0;
290
- const policy = value.expansion_policy || (TERMINAL_KINDS.has(value.kind) ? "terminal" : "conditional");
291
- const declaredSourceCount = [...(Array.isArray(value.source_refs) ? value.source_refs : []), ...(Array.isArray(value.evidence) ? value.evidence : [])].length;
292
- const sources = sourcePassport(graph, record, value);
293
- const sensitiveMetadata = secretLike({ title: value.title, summary: value.summary, negative_boundaries: value.negative_boundaries, non_goals: value.non_goals });
294
- return {
295
- id,
296
- kind: value.kind || "unknown",
297
- title: sensitiveMetadata ? "[redacted]" : (value.title || id),
298
- summary: sensitiveMetadata ? "[redacted]" : (value.summary || ""),
299
- owner: value.owner || value.owner_id || graph.manifest.owner || null,
300
- readiness: readinessOf(value),
301
- authority: value.authority || value.tz_role || "reference",
302
- expandable: computedExpandable,
303
- child_kinds: unique(children.map((relation) => graph.objects.get(relation.target)?.value.kind).filter(Boolean)),
304
- expansion_policy: policy,
305
- applicability: value.applicability || null,
306
- negative_boundaries: unique(value.negative_boundaries || value.non_goals || []),
307
- source_refs: sources,
308
- omitted_source_ref_count: Math.max(0, declaredSourceCount - (sources.length - 1)),
309
- sensitive_metadata_detected: sensitiveMetadata,
310
- access_requirements: (Array.isArray(value.access_requirements) ? value.access_requirements : []).map((item) => ({
311
- ref: typeof item === "string" ? item : item.ref,
312
- status: typeof item === "object" && item ? (item.status || "unknown") : "unknown",
313
- permission: typeof item === "object" && item ? (item.permission || null) : null,
314
- })).filter((item) => safeRef(item.ref)),
315
- required_relations: unique(children.filter((relation) => REQUIRED_RELATIONS.has(relation.type)).map((relation) => relation.id)),
316
- optional_relations: unique(children.filter((relation) => !REQUIRED_RELATIONS.has(relation.type)).map((relation) => relation.id)),
317
- };
318
- }
319
-
320
- function relationPassport(relation) {
321
- return {
322
- id: relation.id,
323
- type: relation.type,
324
- source: relation.source,
325
- target: relation.target,
326
- readiness: relation.readiness || "unknown",
327
- required: REQUIRED_RELATIONS.has(relation.type),
328
- };
329
- }
330
-
331
- function scoreObject(object, taskTokens) {
332
- const tokens = tokenize([object.id, object.kind, object.title, object.summary, ...(object.tags || []), ...(object.aliases || [])].join(" "));
333
- const overlap = taskTokens.filter((token) => tokens.includes(token)).length;
334
- return Math.min(1, overlap * 0.2 + (object.priority === "required" ? 0.1 : 0));
335
- }
336
-
337
- function receiptDigest(receipt) {
338
- const clone = { ...receipt };
339
- delete clone.traversal_digest;
340
- return digest(clone);
341
- }
342
-
343
- function result(phase, status, extra = {}) {
344
- return {
345
- schema_version: RECEIPT_VERSION,
346
- operation_id: `mirai.project_technology.context.${phase}`,
347
- operation_mode: "read_only",
348
- status,
349
- changed: false,
350
- blockers: [],
351
- warnings: [],
352
- next_action: "none",
353
- ...extra,
354
- };
355
- }
356
-
357
- function baseReceipt(graph, task) {
358
- return {
359
- contract: RECEIPT_CONTRACT,
360
- contract_version: RECEIPT_VERSION,
361
- repository_id: graph.manifest?.id || path.basename(graph.repo),
362
- task: { text: task, digest: digest(task) },
363
- graph: { revision: graph.revision, digest: graph.graphDigest },
364
- visited_ids: [],
365
- expanded_ids: [],
366
- frontier_ids: [],
367
- candidates: [],
368
- nodes: [],
369
- relations: [],
370
- selection_history: [],
371
- blockers: [],
372
- warnings: [],
373
- };
374
- }
375
-
376
- function discoverContext(repository, task, options = {}) {
377
- const graph = readGraph(repository);
378
- const text = String(task || "").trim();
379
- const receipt = baseReceipt(graph, text);
380
- const taskTokens = tokenize(text);
381
- const incomingNavigational = new Set(graph.relations.filter((relation) => !["hands_off_to", "conflicts_with"].includes(relation.type)).map((relation) => relation.target));
382
- let roots = [...graph.objects.keys()].filter((id) => !incomingNavigational.has(id));
383
- if (roots.length === 0) roots = [...graph.objects.keys()];
384
- const directScores = new Map([...graph.objects.entries()].map(([id, record]) => [id, scoreObject(record.value, taskTokens)]));
385
- const descendantScore = (root) => {
386
- const queue = [root]; const seen = new Set(); let best = 0;
387
- while (queue.length) {
388
- const id = queue.shift(); if (seen.has(id)) continue; seen.add(id);
389
- best = Math.max(best, directScores.get(id) || 0);
390
- for (const relation of outgoing(graph, id)) if (STRUCTURAL_RELATIONS.has(relation.type)) queue.push(relation.target);
391
- }
392
- return best;
393
- };
394
- const limit = Math.max(1, Math.min(50, Number(options.maxObjects || options.maxCandidates || 12)));
395
- const allRanked = roots.map((id) => ({ id, score: Math.max(directScores.get(id) || 0, descendantScore(id)) }))
396
- .sort((a, b) => b.score - a.score || a.id.localeCompare(b.id));
397
- const positive = allRanked.filter((item) => item.score > 0);
398
- const ranked = (positive.length ? positive : allRanked).slice(0, limit);
399
- if (!positive.length && ranked.length) receipt.warnings.push("no_lexical_match_candidates_unranked");
400
- receipt.candidates = ranked.map((item) => ({ id: item.id, score: item.score }));
401
- receipt.visited_ids = ranked.map((item) => item.id).sort();
402
- receipt.frontier_ids = receipt.visited_ids.filter((id) => nodePassport(graph, id)?.expandable);
403
- receipt.nodes = receipt.visited_ids.map((id) => nodePassport(graph, id));
404
- const extension = graph.manifest?.extensions?.["mirai.project_technology"];
405
- const extensionReady = extension?.enabled === true && extension.contract_version === "1.0.0" && extension.context_policy === "task_scoped" && extension.source_boundary === "hybrid_sot";
406
- receipt.blockers = unique([...graph.blockers, ...(extensionReady ? [] : ["project_technology_not_enabled"]), ...(ranked.length ? [] : ["no_verifiable_runtime_objects"])]);
407
- receipt.traversal_digest = receiptDigest(receipt);
408
- return result("discover", receipt.blockers.length ? "blocked" : "success", {
409
- repository_id: receipt.repository_id,
410
- traversal_receipt: receipt,
411
- blockers: receipt.blockers,
412
- next_action: receipt.blockers.length ? "repair the graph blockers" : "select and expand relevant candidates",
413
- });
414
- }
415
-
416
- function validateReceipt(graph, receipt) {
417
- const blockers = [];
418
- if (!receipt || receipt.contract !== RECEIPT_CONTRACT || receipt.contract_version !== RECEIPT_VERSION) blockers.push("context_traversal_receipt_invalid");
419
- if (receipt?.repository_id !== graph.manifest?.id) blockers.push("context_repository_mismatch");
420
- if (receipt?.graph?.revision !== graph.revision) blockers.push("context_graph_revision_mismatch");
421
- if (receipt?.graph?.digest !== graph.graphDigest) blockers.push("context_graph_digest_mismatch");
422
- if (receipt?.traversal_digest !== receiptDigest(receipt || {})) blockers.push("context_traversal_digest_mismatch");
423
- return unique([...graph.blockers, ...blockers]);
424
- }
425
-
426
- function expandContext(repository, traversalReceipt, selectedIds, options = {}) {
427
- const graph = readGraph(repository);
428
- const receipt = JSON.parse(JSON.stringify(traversalReceipt || {}));
429
- const blockers = validateReceipt(graph, receipt);
430
- const selected = unique(Array.isArray(selectedIds) ? selectedIds : [selectedIds]);
431
- for (const id of selected) {
432
- if (!graph.objects.has(id)) { blockers.push("selected_context_node_missing"); continue; }
433
- if (!(receipt.visited_ids || []).includes(id)) { blockers.push("selected_context_node_not_discovered"); continue; }
434
- const children = outgoing(graph, id);
435
- const alreadyExpanded = (receipt.expanded_ids || []).includes(id);
436
- receipt.expanded_ids = unique([...(receipt.expanded_ids || []), id]);
437
- receipt.visited_ids = unique([...(receipt.visited_ids || []), ...children.map((relation) => relation.target)]);
438
- if (!alreadyExpanded) receipt.selection_history = [...(receipt.selection_history || []), {
439
- selector: options.selector || "ai",
440
- selected_ids: [id],
441
- reason: options.reason || "selected for deeper context",
442
- confidence: Number(options.confidence ?? 1),
443
- }];
444
- }
445
- receipt.nodes = receipt.visited_ids.map((id) => nodePassport(graph, id)).filter(Boolean);
446
- const visible = new Set(receipt.visited_ids);
447
- receipt.relations = graph.relations.filter((relation) => visible.has(relation.source) && visible.has(relation.target)).map(relationPassport).sort((a, b) => a.id.localeCompare(b.id));
448
- receipt.frontier_ids = receipt.visited_ids.filter((id) => nodePassport(graph, id)?.expandable && !receipt.expanded_ids.includes(id));
449
- receipt.blockers = unique(blockers);
450
- receipt.traversal_digest = receiptDigest(receipt);
451
- return result("expand", receipt.blockers.length ? "blocked" : "success", {
452
- repository_id: receipt.repository_id,
453
- traversal_receipt: receipt,
454
- blockers: receipt.blockers,
455
- next_action: receipt.blockers.length ? "repair the traversal blockers" : "expand remaining selected branches or compile a selection",
456
- });
457
- }
458
-
459
- function normalizeSelection(selection, receipt) {
460
- const source = selection && typeof selection === "object" ? selection : {};
461
- return {
462
- selector: ["ai", "human", "rule"].includes(source.selector) ? source.selector : "ai",
463
- task_digest: source.task_digest || receipt.task?.digest || null,
464
- graph_digest: source.graph_digest || receipt.graph?.digest || null,
465
- result_owner_id: source.result_owner_id || null,
466
- selected: (Array.isArray(source.selected) ? source.selected : []).map((item) => typeof item === "string" ? { id: item, reason: "selected", confidence: 1 } : item)
467
- .filter((item) => item && typeof item.id === "string").sort((a, b) => a.id.localeCompare(b.id)),
468
- rejected: (Array.isArray(source.rejected) ? source.rejected : []).map((item) => typeof item === "string" ? { id: item, reason: "not applicable" } : item)
469
- .filter((item) => item && typeof item.id === "string").sort((a, b) => a.id.localeCompare(b.id)),
470
- };
471
- }
472
-
473
- function requiredClosure(graph, initial) {
474
- const closure = new Set(initial); const queue = [...initial]; const relations = [];
475
- while (queue.length) {
476
- const id = queue.shift();
477
- for (const relation of outgoing(graph, id)) {
478
- if (!REQUIRED_RELATIONS.has(relation.type)) continue;
479
- relations.push(relation.id);
480
- if (!closure.has(relation.target)) { closure.add(relation.target); queue.push(relation.target); }
481
- }
482
- }
483
- return { ids: [...closure].sort(), relationIds: unique(relations) };
484
- }
485
-
486
- function sourceClosure(graph, initial) {
487
- const closure = new Set(initial); const queue = [...initial]; const relations = [];
488
- while (queue.length) {
489
- const id = queue.shift();
490
- for (const relation of outgoing(graph, id)) {
491
- const targetKind = graph.objects.get(relation.target)?.value.kind;
492
- const structuralSource = STRUCTURAL_RELATIONS.has(relation.type) && ["resource", "source"].includes(targetKind);
493
- if (!SOURCE_RELATIONS.has(relation.type) && !structuralSource) continue;
494
- relations.push(relation.id);
495
- if (!closure.has(relation.target)) { closure.add(relation.target); queue.push(relation.target); }
496
- }
497
- }
498
- return { ids: [...closure].sort(), relationIds: unique(relations) };
499
- }
500
-
501
- function requiredCycle(graph, ids) {
502
- const allowed = new Set(ids); const visiting = new Set(); const visited = new Set();
503
- function visit(id) {
504
- if (visiting.has(id)) return true;
505
- if (visited.has(id)) return false;
506
- visiting.add(id);
507
- for (const relation of outgoing(graph, id)) if (REQUIRED_RELATIONS.has(relation.type) && allowed.has(relation.target) && visit(relation.target)) return true;
508
- visiting.delete(id); visited.add(id); return false;
509
- }
510
- return ids.some(visit);
511
- }
512
-
513
- function compileContext(repository, traversalReceipt, selectionInput, options = {}) {
514
- const graph = readGraph(repository);
515
- const receipt = traversalReceipt || {};
516
- const blockers = validateReceipt(graph, receipt);
517
- const selection = normalizeSelection(selectionInput, receipt);
518
- const selectedIds = unique(selection.selected.map((item) => item.id));
519
- const rejectedIds = new Set(selection.rejected.map((item) => item.id));
520
- if (selection.task_digest !== receipt.task?.digest) blockers.push("selection_task_digest_mismatch");
521
- if (selection.graph_digest !== graph.graphDigest) blockers.push("selection_graph_digest_mismatch");
522
- if (!selectedIds.length) blockers.push("context_selection_empty");
523
- if (!selection.result_owner_id) blockers.push("result_owner_missing");
524
- for (const item of selection.selected) {
525
- if (!graph.objects.has(item.id) || !receipt.visited_ids?.includes(item.id)) blockers.push("selected_context_node_not_discovered");
526
- if (!item.reason || !Number.isFinite(Number(item.confidence))) blockers.push("selected_context_reason_or_confidence_missing");
527
- }
528
- for (const item of selection.rejected) if (!item.reason) blockers.push("rejected_context_reason_missing");
529
- const required = requiredClosure(graph, selectedIds);
530
- const sources = sourceClosure(graph, required.ids);
531
- const closure = { ids: sources.ids, relationIds: unique([...required.relationIds, ...sources.relationIds]) };
532
- const missingRequired = closure.ids.filter((id) => !receipt.visited_ids?.includes(id));
533
- if (missingRequired.length) blockers.push("required_context_not_discovered");
534
- if (requiredCycle(graph, required.ids)) blockers.push("required_context_cycle");
535
- const included = new Set(closure.ids);
536
- if (selection.result_owner_id && !closure.ids.some((id) => {
537
- const node = nodePassport(graph, id);
538
- return id === selection.result_owner_id || node?.owner === selection.result_owner_id;
539
- })) blockers.push("result_owner_not_in_selected_context");
540
- const unresolvedBranches = [];
541
- for (const id of closure.ids) {
542
- const passport = nodePassport(graph, id);
543
- if (!passport) continue;
544
- if (!activeReadiness(passport.readiness)) blockers.push(`context_node_${passport.readiness}`);
545
- if (passport.omitted_source_ref_count > 0) blockers.push("unsafe_source_reference_omitted");
546
- if (passport.sensitive_metadata_detected) blockers.push("context_node_sensitive_metadata");
547
- if (passport.expansion_policy === "terminal" && passport.expandable) blockers.push("terminal_node_has_children");
548
- if (passport.expansion_policy === "expandable" && !passport.expandable) blockers.push("expandable_node_has_no_children");
549
- for (const source of passport.source_refs) if (source.availability === "unavailable") blockers.push("required_source_unavailable");
550
- for (const source of passport.source_refs) if (source.availability === "unbound") blockers.push("required_source_not_revision_bound");
551
- for (const access of passport.access_requirements) if (!["available", "granted", "not_required"].includes(access.status)) blockers.push("context_access_not_available");
552
- if (!passport.expandable) continue;
553
- if (!receipt.expanded_ids?.includes(id)) { unresolvedBranches.push(id); continue; }
554
- for (const relation of outgoing(graph, id).filter((item) => STRUCTURAL_RELATIONS.has(item.type))) {
555
- if (included.has(relation.target) || rejectedIds.has(relation.target)) continue;
556
- unresolvedBranches.push(relation.target);
557
- }
558
- }
559
- if (unresolvedBranches.length) blockers.push("context_branch_decision_incomplete");
560
- for (const relation of graph.relations) {
561
- if (relation.type === "conflicts_with" && included.has(relation.source) && included.has(relation.target)) blockers.push("context_selection_conflict");
562
- }
563
- const includedIds = [...included].sort();
564
- const includedNodes = includedIds.map((id) => nodePassport(graph, id)).filter(Boolean);
565
- const includedRelations = graph.relations.filter((relation) => included.has(relation.source) && included.has(relation.target)).map(relationPassport).sort((a, b) => a.id.localeCompare(b.id));
566
- for (const relation of includedRelations) if (!activeReadiness(relation.readiness)) blockers.push(`context_relation_${String(relation.readiness).toLowerCase()}`);
567
- const terminalSourceMap = new Map();
568
- for (const node of includedNodes.filter((item) => !item.expandable || ["resource", "source"].includes(item.kind))) {
569
- for (const source of node.source_refs) {
570
- const key = `${source.ref}:${source.sha256 || ""}:${source.revision || ""}`;
571
- const current = terminalSourceMap.get(key) || { ...source, node_ids: [] };
572
- current.node_ids = unique([...current.node_ids, node.id]);
573
- terminalSourceMap.set(key, current);
574
- }
575
- }
576
- const terminalSources = [...terminalSourceMap.values()].sort((a, b) => a.ref.localeCompare(b.ref) || String(a.sha256).localeCompare(String(b.sha256)));
577
- for (const source of terminalSources) if (!source.sha256 || !source.revision) blockers.push("required_source_not_hash_bound");
578
- const contextBudget = Number(options.contextBudget || options.maxBytes || 256 * 1024);
579
- const base = {
580
- id: `context_pack.${digest(`${receipt.task?.digest}:${graph.graphDigest}`).slice(7, 23)}`,
581
- task_id: receipt.task?.digest,
582
- task_digest: receipt.task?.digest,
583
- graph_digest: graph.graphDigest,
584
- graph_revision: graph.revision,
585
- source_graph: graph.manifest?.id,
586
- generated_at: graph.revision ? `revision:${graph.revision}` : "revision:unavailable",
587
- selected_paths: selection.selected,
588
- rejected_paths: selection.rejected,
589
- visited_nodes: unique(receipt.visited_ids || []),
590
- stop_reasons: includedNodes.filter((node) => !node.expandable).map((node) => ({ id: node.id, reason: "terminal" })),
591
- required_closure: { object_ids: includedIds, relation_ids: closure.relationIds },
592
- terminal_sources: terminalSources,
593
- processes: includedNodes.filter((node) => node.kind === "process").map((node) => node.id),
594
- constraints: includedNodes.filter((node) => node.kind === "constraint").map((node) => node.id),
595
- validators: includedNodes.filter((node) => ["check", "gate", "validator"].includes(node.kind)).map((node) => node.id),
596
- included_objects: includedIds,
597
- included_relations: includedRelations.map((relation) => relation.id),
598
- evidence: unique(terminalSources.map((source) => source.ref)),
599
- selection: { method: "client_selection_with_required_closure", selector: selection.selector, result_owner_id: selection.result_owner_id, task_tokens: tokenize(receipt.task?.text), object_explanations: selection.selected.map((item) => ({ id: item.id, relevance_score: Number(item.confidence), reasons: [item.reason] })), relation_explanations: includedRelations.map((relation) => ({ id: relation.id, reason: relation.required ? "required closure" : "selected path", source: relation.source, target: relation.target })) },
600
- completeness: { status: "ready", unresolved_required_ids: unique(missingRequired), unresolved_branch_ids: unique(unresolvedBranches) },
601
- omissions: selection.rejected.map((item) => ({ id: item.id, reason: item.reason })),
602
- limitations: [],
603
- runtime_contract: { generated_context_authorizes_write: false, raw_source_authoritative: true },
604
- };
605
- if (Buffer.byteLength(canonicalBytes(base)) > contextBudget) blockers.push("context_budget_insufficient_for_required_closure");
606
- const uniqueBlockers = unique(blockers);
607
- const decisionBlockers = new Set(["context_selection_empty", "result_owner_missing", "context_branch_decision_incomplete", "selected_context_reason_or_confidence_missing", "rejected_context_reason_missing"]);
608
- const discoveryBlockers = new Set(["required_context_not_discovered"]);
609
- let status = "ready";
610
- if (uniqueBlockers.some((item) => discoveryBlockers.has(item))) status = "needs_more_discovery";
611
- else if (uniqueBlockers.some((item) => decisionBlockers.has(item))) status = "needs_decision";
612
- else if (uniqueBlockers.length) status = "blocked";
613
- base.completeness.status = status;
614
- base.limitations = uniqueBlockers;
615
- base.context_pack_digest = digest(base);
616
- return result("compile", status, {
617
- repository_id: graph.manifest?.id,
618
- context_pack: base,
619
- blockers: uniqueBlockers,
620
- next_action: status === "ready" ? "use the immutable context pack and record usage evidence" : status === "needs_more_discovery" ? "expand the missing required branches" : status === "needs_decision" ? "complete the bounded selection" : "repair the blocking graph or source condition",
621
- });
622
- }
623
-
624
- function secretLike(value) {
625
- const text = JSON.stringify(value || {});
626
- return /(?:ghp_|github_pat_|bearer\s+)[a-z0-9_-]{12,}/i.test(text)
627
- || /-----BEGIN (?:RSA |EC |OPENSSH )?PRIVATE KEY-----/.test(text)
628
- || /(?:^|["'\s/])\.env(?:["'\s/]|$)/i.test(text);
629
- }
630
-
631
- function verifyContext(repository, contextPack, usageEvidence, options = {}) {
632
- const graph = readGraph(repository);
633
- const blockers = [...graph.blockers];
634
- if (!contextPack || contextPack.context_pack_digest !== digest(Object.fromEntries(Object.entries(contextPack || {}).filter(([key]) => key !== "context_pack_digest")))) blockers.push("context_pack_digest_mismatch");
635
- if (contextPack?.graph_digest !== graph.graphDigest || contextPack?.graph_revision !== graph.revision) blockers.push("context_pack_graph_mismatch");
636
- if (contextPack?.completeness?.status !== "ready") blockers.push("context_pack_not_ready");
637
- if (contextPack?.runtime_contract?.generated_context_authorizes_write !== false) blockers.push("generated_context_write_authority_forbidden");
638
- const evidence = Array.isArray(usageEvidence) ? usageEvidence : usageEvidence?.usage || [];
639
- if (!Array.isArray(evidence) || evidence.length === 0) blockers.push("usage_evidence_missing");
640
- const coveredSources = new Set(); const coveredValidators = new Set(); const coveredProcesses = new Set();
641
- for (const item of Array.isArray(evidence) ? evidence : []) {
642
- if (!item || typeof item !== "object" || item.context_pack_digest !== contextPack?.context_pack_digest) { blockers.push("usage_evidence_context_pack_mismatch"); continue; }
643
- for (const field of ["source", "applied_rule", "decision", "surface", "validator", "outcome"]) if (!item[field]) blockers.push(`usage_evidence_${field}_missing`);
644
- if (item.source) coveredSources.add(item.source);
645
- if (item.validator) coveredValidators.add(item.validator);
646
- if (item.process) coveredProcesses.add(item.process);
647
- if (item.applied_rule) coveredProcesses.add(item.applied_rule);
648
- if (secretLike(item)) blockers.push("usage_evidence_contains_sensitive_data");
649
- }
650
- for (const source of contextPack?.terminal_sources || []) if (!coveredSources.has(source.ref)) blockers.push("mandatory_source_not_applied");
651
- for (const source of contextPack?.terminal_sources || []) {
652
- if (!safeRef(source.ref)) { blockers.push("context_pack_source_ref_unsafe"); continue; }
653
- if (/^(repo|https):\/\//.test(source.ref)) continue;
654
- const absolute = path.join(graph.repo, source.ref);
655
- if (!fs.existsSync(absolute) || fs.lstatSync(absolute).isSymbolicLink() || !fs.statSync(absolute).isFile()) blockers.push("context_pack_source_unavailable");
656
- else {
657
- const blob = graphBlob(graph, source.ref);
658
- if (!blob || !revisionBound(graph.repo, source.ref) || digest(blob) !== source.sha256 || source.revision !== graph.revision) blockers.push("context_pack_source_revision_or_digest_mismatch");
659
- }
660
- }
661
- for (const process of contextPack?.processes || []) if (!coveredProcesses.has(process)) blockers.push("mandatory_process_not_applied");
662
- for (const validator of contextPack?.validators || []) if (!coveredValidators.has(validator)) blockers.push("mandatory_validator_not_applied");
663
- if (secretLike(contextPack)) blockers.push("context_pack_contains_sensitive_data");
664
- const uniqueBlockers = unique(blockers);
665
- return result("verify", uniqueBlockers.length ? "blocked" : "success", {
666
- repository_id: graph.manifest?.id,
667
- context_pack_digest: contextPack?.context_pack_digest || null,
668
- usage_evidence_digest: evidence.length ? digest(evidence) : null,
669
- blockers: uniqueBlockers,
670
- next_action: uniqueBlockers.length ? "repair the context or usage evidence" : "none",
671
- });
672
- }
673
-
674
- module.exports = {
675
- RECEIPT_CONTRACT,
676
- REQUIRED_RELATIONS,
677
- SUPPORTED_RELATIONS,
678
- compileContext,
679
- digest,
680
- discoverContext,
681
- expandContext,
682
- readGraph,
683
- verifyContext,
684
- };