@tiinex/core 0.1.1

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 (517) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +31 -0
  3. package/README.md +45 -0
  4. package/package.json +176 -0
  5. package/src/actions/record.actions.js +312 -0
  6. package/src/adapters/adapter.contracts.js +143 -0
  7. package/src/adapters/archive/archive.adapter.js +502 -0
  8. package/src/adapters/archive/archive.portableChangeset.js +141 -0
  9. package/src/adapters/archive/archive.transport.js +124 -0
  10. package/src/artifacts/artifact.localDraft.js +27 -0
  11. package/src/artifacts/artifact.normalize.js +28 -0
  12. package/src/artifacts/artifact.parse.js +207 -0
  13. package/src/artifacts/artifact.record.js +83 -0
  14. package/src/audit/audit.run.js +103 -0
  15. package/src/audit/audit.summary.js +7 -0
  16. package/src/diagnostics/sourceBoundary.report.js +112 -0
  17. package/src/export/package.apply.js +349 -0
  18. package/src/export/package.builder.js +366 -0
  19. package/src/export/package.bytes.js +164 -0
  20. package/src/export/package.controlIntegrity.js +42 -0
  21. package/src/export/package.controlTopology.js +97 -0
  22. package/src/export/package.fileMap.js +174 -0
  23. package/src/export/package.manifest.js +401 -0
  24. package/src/export/package.preflight.js +204 -0
  25. package/src/export/package.sourceReference.js +81 -0
  26. package/src/export/package.workspaceContext.js +144 -0
  27. package/src/export/package.zip.js +128 -0
  28. package/src/export/tree.bundle.js +278 -0
  29. package/src/governance/governance.boundary.js +196 -0
  30. package/src/integrity/integrity.c14nV2.js +190 -0
  31. package/src/integrity/integrity.methodReference.js +73 -0
  32. package/src/integrity/integrity.validate.js +56 -0
  33. package/src/lineage/lineage.candidateResolution.js +46 -0
  34. package/src/lineage/lineage.githubIssueComment.js +106 -0
  35. package/src/lineage/lineage.githubIssueLocal.js +196 -0
  36. package/src/lineage/lineage.githubIssueTarget.js +89 -0
  37. package/src/lineage/lineage.integrity.js +133 -0
  38. package/src/lineage/lineage.materialPreference.js +26 -0
  39. package/src/lineage/lineage.model.js +63 -0
  40. package/src/lineage/lineage.parentAuthority.js +5 -0
  41. package/src/lineage/lineage.parentBinding.js +104 -0
  42. package/src/lineage/lineage.pathBasis.js +47 -0
  43. package/src/lineage/lineage.resolve.js +388 -0
  44. package/src/lineage/lineage.sourceScope.js +74 -0
  45. package/src/lineage/lineage.targetKeys.js +80 -0
  46. package/src/lineage/lineage.traverse.js +132 -0
  47. package/src/public/applicationProjection.js +236 -0
  48. package/src/public/companionResources.js +246 -0
  49. package/src/public/index.js +16 -0
  50. package/src/public/node.js +2 -0
  51. package/src/public/schemaAncestry.js +26 -0
  52. package/src/publication/publication.contract.js +196 -0
  53. package/src/publication/publication.preflight.js +159 -0
  54. package/src/publication/publication.targetContract.js +241 -0
  55. package/src/reingest/reingest.plan.js +162 -0
  56. package/src/release/plan.mjs +28 -0
  57. package/src/release/policy.mjs +100 -0
  58. package/src/release/run.mjs +74 -0
  59. package/src/schemas/capability.registry.js +226 -0
  60. package/src/schemas/companion.js +245 -0
  61. package/src/schemas/contracts.js +6 -0
  62. package/src/schemas/coordination/handoff/tiinex.handoff.v1.schema.js +14 -0
  63. package/src/schemas/coordination/handoff/tiinex.handoff.v1.schema.json +23 -0
  64. package/src/schemas/coordination/handoff/tiinex.handoff.v1.schema.runtime.json +4283 -0
  65. package/src/schemas/coordination/handoff/tiinex.handoff.v1.schema.source.js +9 -0
  66. package/src/schemas/coordination/project/tiinex.project.v1.schema.js +26 -0
  67. package/src/schemas/coordination/project/tiinex.project.v1.schema.json +23 -0
  68. package/src/schemas/coordination/project/tiinex.project.v1.schema.runtime.json +1985 -0
  69. package/src/schemas/coordination/project/tiinex.project.v1.schema.source.js +9 -0
  70. package/src/schemas/core/decision/tiinex.decision.v1.schema.js +14 -0
  71. package/src/schemas/core/decision/tiinex.decision.v1.schema.json +24 -0
  72. package/src/schemas/core/decision/tiinex.decision.v1.schema.runtime.json +1700 -0
  73. package/src/schemas/core/decision/tiinex.decision.v1.schema.source.js +9 -0
  74. package/src/schemas/core/evidence/tiinex.evidence.v1.capabilities.js +14 -0
  75. package/src/schemas/core/evidence/tiinex.evidence.v1.en.i18n.json +6 -0
  76. package/src/schemas/core/evidence/tiinex.evidence.v1.findings.js +9 -0
  77. package/src/schemas/core/evidence/tiinex.evidence.v1.presenter.js +1 -0
  78. package/src/schemas/core/evidence/tiinex.evidence.v1.schema.js +32 -0
  79. package/src/schemas/core/evidence/tiinex.evidence.v1.schema.json +24 -0
  80. package/src/schemas/core/evidence/tiinex.evidence.v1.schema.runtime.json +2184 -0
  81. package/src/schemas/core/evidence/tiinex.evidence.v1.schema.source.js +9 -0
  82. package/src/schemas/core/evidence/tiinex.evidence.v1.sv.i18n.json +6 -0
  83. package/src/schemas/core/evidence/tiinex.evidence.v1.transitions.js +1 -0
  84. package/src/schemas/core/evidence/tiinex.evidence.v1.validate.js +10 -0
  85. package/src/schemas/core/feedback/tiinex.feedback.v1.schema.js +14 -0
  86. package/src/schemas/core/feedback/tiinex.feedback.v1.schema.json +23 -0
  87. package/src/schemas/core/feedback/tiinex.feedback.v1.schema.runtime.json +1773 -0
  88. package/src/schemas/core/feedback/tiinex.feedback.v1.schema.source.js +9 -0
  89. package/src/schemas/core/interpretation/tiinex.interpretation.v1.capabilities.js +11 -0
  90. package/src/schemas/core/interpretation/tiinex.interpretation.v1.contract.js +40 -0
  91. package/src/schemas/core/interpretation/tiinex.interpretation.v1.en.i18n.json +9 -0
  92. package/src/schemas/core/interpretation/tiinex.interpretation.v1.findings.js +12 -0
  93. package/src/schemas/core/interpretation/tiinex.interpretation.v1.localMaterialization.js +89 -0
  94. package/src/schemas/core/interpretation/tiinex.interpretation.v1.presenter.js +8 -0
  95. package/src/schemas/core/interpretation/tiinex.interpretation.v1.schema.js +34 -0
  96. package/src/schemas/core/interpretation/tiinex.interpretation.v1.schema.json +23 -0
  97. package/src/schemas/core/interpretation/tiinex.interpretation.v1.schema.runtime.json +2029 -0
  98. package/src/schemas/core/interpretation/tiinex.interpretation.v1.schema.source.js +9 -0
  99. package/src/schemas/core/interpretation/tiinex.interpretation.v1.sv.i18n.json +9 -0
  100. package/src/schemas/core/interpretation/tiinex.interpretation.v1.transitions.js +1 -0
  101. package/src/schemas/core/interpretation/tiinex.interpretation.v1.validate.js +25 -0
  102. package/src/schemas/core/preservation/tiinex.preservation.v1.capabilities.js +14 -0
  103. package/src/schemas/core/preservation/tiinex.preservation.v1.en.i18n.json +6 -0
  104. package/src/schemas/core/preservation/tiinex.preservation.v1.findings.js +9 -0
  105. package/src/schemas/core/preservation/tiinex.preservation.v1.presenter.js +1 -0
  106. package/src/schemas/core/preservation/tiinex.preservation.v1.schema.js +31 -0
  107. package/src/schemas/core/preservation/tiinex.preservation.v1.schema.json +23 -0
  108. package/src/schemas/core/preservation/tiinex.preservation.v1.schema.runtime.json +2033 -0
  109. package/src/schemas/core/preservation/tiinex.preservation.v1.schema.source.js +9 -0
  110. package/src/schemas/core/preservation/tiinex.preservation.v1.sv.i18n.json +6 -0
  111. package/src/schemas/core/preservation/tiinex.preservation.v1.transitions.js +1 -0
  112. package/src/schemas/core/preservation/tiinex.preservation.v1.validate.js +10 -0
  113. package/src/schemas/core/relation/tiinex.relation.v1.capabilities.js +7 -0
  114. package/src/schemas/core/relation/tiinex.relation.v1.contract.js +3 -0
  115. package/src/schemas/core/relation/tiinex.relation.v1.en.i18n.json +4 -0
  116. package/src/schemas/core/relation/tiinex.relation.v1.findings.js +9 -0
  117. package/src/schemas/core/relation/tiinex.relation.v1.localMaterialization.js +153 -0
  118. package/src/schemas/core/relation/tiinex.relation.v1.presenter.js +3 -0
  119. package/src/schemas/core/relation/tiinex.relation.v1.schema.js +20 -0
  120. package/src/schemas/core/relation/tiinex.relation.v1.schema.json +23 -0
  121. package/src/schemas/core/relation/tiinex.relation.v1.schema.runtime.json +1668 -0
  122. package/src/schemas/core/relation/tiinex.relation.v1.schema.source.js +9 -0
  123. package/src/schemas/core/relation/tiinex.relation.v1.sv.i18n.json +4 -0
  124. package/src/schemas/core/relation/tiinex.relation.v1.transitions.js +1 -0
  125. package/src/schemas/core/relation/tiinex.relation.v1.validate.js +36 -0
  126. package/src/schemas/core/relation/workspace/representation/tiinex.workspace.representation.v1.capabilities.js +14 -0
  127. package/src/schemas/core/relation/workspace/representation/tiinex.workspace.representation.v1.contract.js +57 -0
  128. package/src/schemas/core/relation/workspace/representation/tiinex.workspace.representation.v1.en.i18n.json +4 -0
  129. package/src/schemas/core/relation/workspace/representation/tiinex.workspace.representation.v1.findings.js +13 -0
  130. package/src/schemas/core/relation/workspace/representation/tiinex.workspace.representation.v1.presenter.js +3 -0
  131. package/src/schemas/core/relation/workspace/representation/tiinex.workspace.representation.v1.schema.js +20 -0
  132. package/src/schemas/core/relation/workspace/representation/tiinex.workspace.representation.v1.schema.json +24 -0
  133. package/src/schemas/core/relation/workspace/representation/tiinex.workspace.representation.v1.schema.runtime.json +3315 -0
  134. package/src/schemas/core/relation/workspace/representation/tiinex.workspace.representation.v1.schema.source.js +9 -0
  135. package/src/schemas/core/relation/workspace/representation/tiinex.workspace.representation.v1.sv.i18n.json +4 -0
  136. package/src/schemas/core/relation/workspace/representation/tiinex.workspace.representation.v1.transitions.js +1 -0
  137. package/src/schemas/core/relation/workspace/representation/tiinex.workspace.representation.v1.validate.js +78 -0
  138. package/src/schemas/core/signal/tiinex.signal.v1.schema.js +14 -0
  139. package/src/schemas/core/signal/tiinex.signal.v1.schema.json +23 -0
  140. package/src/schemas/core/signal/tiinex.signal.v1.schema.runtime.json +1733 -0
  141. package/src/schemas/core/signal/tiinex.signal.v1.schema.source.js +9 -0
  142. package/src/schemas/core/task/tiinex.task.v1.capabilities.js +11 -0
  143. package/src/schemas/core/task/tiinex.task.v1.contract.js +3 -0
  144. package/src/schemas/core/task/tiinex.task.v1.en.i18n.json +15 -0
  145. package/src/schemas/core/task/tiinex.task.v1.findings.js +18 -0
  146. package/src/schemas/core/task/tiinex.task.v1.localMaterialization.js +148 -0
  147. package/src/schemas/core/task/tiinex.task.v1.presenter.js +8 -0
  148. package/src/schemas/core/task/tiinex.task.v1.schema.js +35 -0
  149. package/src/schemas/core/task/tiinex.task.v1.schema.json +23 -0
  150. package/src/schemas/core/task/tiinex.task.v1.schema.runtime.json +1708 -0
  151. package/src/schemas/core/task/tiinex.task.v1.schema.source.js +9 -0
  152. package/src/schemas/core/task/tiinex.task.v1.sv.i18n.json +15 -0
  153. package/src/schemas/core/task/tiinex.task.v1.transitions.js +3 -0
  154. package/src/schemas/core/task/tiinex.task.v1.validate.js +41 -0
  155. package/src/schemas/core/topic/tiinex.topic.v1.capabilities.js +14 -0
  156. package/src/schemas/core/topic/tiinex.topic.v1.creation.js +46 -0
  157. package/src/schemas/core/topic/tiinex.topic.v1.en.i18n.json +8 -0
  158. package/src/schemas/core/topic/tiinex.topic.v1.findings.js +11 -0
  159. package/src/schemas/core/topic/tiinex.topic.v1.localMaterialization.js +135 -0
  160. package/src/schemas/core/topic/tiinex.topic.v1.presenter.js +1 -0
  161. package/src/schemas/core/topic/tiinex.topic.v1.schema.js +34 -0
  162. package/src/schemas/core/topic/tiinex.topic.v1.schema.json +23 -0
  163. package/src/schemas/core/topic/tiinex.topic.v1.schema.runtime.json +1699 -0
  164. package/src/schemas/core/topic/tiinex.topic.v1.schema.source.js +9 -0
  165. package/src/schemas/core/topic/tiinex.topic.v1.sv.i18n.json +8 -0
  166. package/src/schemas/core/topic/tiinex.topic.v1.transitions.js +31 -0
  167. package/src/schemas/core/topic/tiinex.topic.v1.validate.js +11 -0
  168. package/src/schemas/creation.capability.js +289 -0
  169. package/src/schemas/creation.contracts.js +334 -0
  170. package/src/schemas/creation.executionSnapshot.js +79 -0
  171. package/src/schemas/creation.factoryQualification.js +73 -0
  172. package/src/schemas/creation.renderer.js +244 -0
  173. package/src/schemas/creation.representation.js +279 -0
  174. package/src/schemas/creation.rootMetadata.js +6 -0
  175. package/src/schemas/creation.schemaReferences.js +65 -0
  176. package/src/schemas/discovery/finding/tiinex.discovery.finding.v1.schema.js +14 -0
  177. package/src/schemas/discovery/finding/tiinex.discovery.finding.v1.schema.json +23 -0
  178. package/src/schemas/discovery/finding/tiinex.discovery.finding.v1.schema.runtime.json +1873 -0
  179. package/src/schemas/discovery/finding/tiinex.discovery.finding.v1.schema.source.js +9 -0
  180. package/src/schemas/discovery/tiinex.discovery.v1.schema.js +14 -0
  181. package/src/schemas/discovery/tiinex.discovery.v1.schema.json +23 -0
  182. package/src/schemas/discovery/tiinex.discovery.v1.schema.runtime.json +1839 -0
  183. package/src/schemas/discovery/tiinex.discovery.v1.schema.source.js +9 -0
  184. package/src/schemas/generic.artifact.module.js +25 -0
  185. package/src/schemas/party/organization/tiinex.party.organization.v1.schema.js +26 -0
  186. package/src/schemas/party/organization/tiinex.party.organization.v1.schema.json +23 -0
  187. package/src/schemas/party/organization/tiinex.party.organization.v1.schema.runtime.json +2249 -0
  188. package/src/schemas/party/organization/tiinex.party.organization.v1.schema.source.js +9 -0
  189. package/src/schemas/party/role/tiinex.party.role.v1.schema.js +26 -0
  190. package/src/schemas/party/role/tiinex.party.role.v1.schema.json +24 -0
  191. package/src/schemas/party/role/tiinex.party.role.v1.schema.runtime.json +2091 -0
  192. package/src/schemas/party/role/tiinex.party.role.v1.schema.source.js +9 -0
  193. package/src/schemas/presentation/surface/tiinex.presentation.surface.v1.capabilities.js +14 -0
  194. package/src/schemas/presentation/surface/tiinex.presentation.surface.v1.en.i18n.json +4 -0
  195. package/src/schemas/presentation/surface/tiinex.presentation.surface.v1.findings.js +1 -0
  196. package/src/schemas/presentation/surface/tiinex.presentation.surface.v1.presenter.js +1 -0
  197. package/src/schemas/presentation/surface/tiinex.presentation.surface.v1.schema.js +29 -0
  198. package/src/schemas/presentation/surface/tiinex.presentation.surface.v1.schema.json +21 -0
  199. package/src/schemas/presentation/surface/tiinex.presentation.surface.v1.schema.runtime.json +2180 -0
  200. package/src/schemas/presentation/surface/tiinex.presentation.surface.v1.schema.source.js +9 -0
  201. package/src/schemas/presentation/surface/tiinex.presentation.surface.v1.sv.i18n.json +4 -0
  202. package/src/schemas/presentation/surface/tiinex.presentation.surface.v1.transitions.js +1 -0
  203. package/src/schemas/presentation/surface/tiinex.presentation.surface.v1.validate.js +1 -0
  204. package/src/schemas/reduction/tiinex.reduction.v1.schema.js +26 -0
  205. package/src/schemas/reduction/tiinex.reduction.v1.schema.json +23 -0
  206. package/src/schemas/reduction/tiinex.reduction.v1.schema.runtime.json +1733 -0
  207. package/src/schemas/reduction/tiinex.reduction.v1.schema.source.js +9 -0
  208. package/src/schemas/reference.shapes.js +33 -0
  209. package/src/schemas/registry.js +36 -0
  210. package/src/schemas/resolver.js +13 -0
  211. package/src/schemas/schema/module/tiinex.schema.module.v1.capabilities.js +14 -0
  212. package/src/schemas/schema/module/tiinex.schema.module.v1.en.i18n.json +4 -0
  213. package/src/schemas/schema/module/tiinex.schema.module.v1.findings.js +1 -0
  214. package/src/schemas/schema/module/tiinex.schema.module.v1.presenter.js +1 -0
  215. package/src/schemas/schema/module/tiinex.schema.module.v1.schema.js +29 -0
  216. package/src/schemas/schema/module/tiinex.schema.module.v1.schema.json +21 -0
  217. package/src/schemas/schema/module/tiinex.schema.module.v1.schema.runtime.json +2093 -0
  218. package/src/schemas/schema/module/tiinex.schema.module.v1.schema.source.js +9 -0
  219. package/src/schemas/schema/module/tiinex.schema.module.v1.sv.i18n.json +4 -0
  220. package/src/schemas/schema/module/tiinex.schema.module.v1.transitions.js +1 -0
  221. package/src/schemas/schema/module/tiinex.schema.module.v1.validate.js +1 -0
  222. package/src/schemas/schema.factory.descriptor.js +104 -0
  223. package/src/schemas/schema.githubSourceTarget.js +131 -0
  224. package/src/schemas/schema.identity.js +10 -0
  225. package/src/schemas/schema.reference.js +133 -0
  226. package/src/schemas/schema.source.js +239 -0
  227. package/src/schemas/tiinex.root.v1.capabilities.js +14 -0
  228. package/src/schemas/tiinex.root.v1.classify.js +55 -0
  229. package/src/schemas/tiinex.root.v1.en.i18n.json +24 -0
  230. package/src/schemas/tiinex.root.v1.fallback.js +84 -0
  231. package/src/schemas/tiinex.root.v1.findings.js +19 -0
  232. package/src/schemas/tiinex.root.v1.presenter.js +5 -0
  233. package/src/schemas/tiinex.root.v1.schema.js +29 -0
  234. package/src/schemas/tiinex.root.v1.schema.json +24 -0
  235. package/src/schemas/tiinex.root.v1.schema.runtime.json +1574 -0
  236. package/src/schemas/tiinex.root.v1.schema.source.js +9 -0
  237. package/src/schemas/tiinex.root.v1.sv.i18n.json +24 -0
  238. package/src/schemas/tiinex.root.v1.transitions.js +1 -0
  239. package/src/schemas/tiinex.root.v1.validate.js +36 -0
  240. package/src/schemas/validation/finding/tiinex.validation.finding.v1.schema.js +14 -0
  241. package/src/schemas/validation/finding/tiinex.validation.finding.v1.schema.json +23 -0
  242. package/src/schemas/validation/finding/tiinex.validation.finding.v1.schema.runtime.json +2027 -0
  243. package/src/schemas/validation/finding/tiinex.validation.finding.v1.schema.source.js +9 -0
  244. package/src/schemas/validation/method/tiinex.validation.method.v1.schema.js +14 -0
  245. package/src/schemas/validation/method/tiinex.validation.method.v1.schema.json +23 -0
  246. package/src/schemas/validation/method/tiinex.validation.method.v1.schema.runtime.json +1848 -0
  247. package/src/schemas/validation/method/tiinex.validation.method.v1.schema.source.js +9 -0
  248. package/src/schemas/validation/report/tiinex.validation.report.v1.schema.js +14 -0
  249. package/src/schemas/validation/report/tiinex.validation.report.v1.schema.json +23 -0
  250. package/src/schemas/validation/report/tiinex.validation.report.v1.schema.runtime.json +2015 -0
  251. package/src/schemas/validation/report/tiinex.validation.report.v1.schema.source.js +9 -0
  252. package/src/schemas/workspace/tiinex.workspace.v1.capabilities.js +12 -0
  253. package/src/schemas/workspace/tiinex.workspace.v1.en.i18n.json +7 -0
  254. package/src/schemas/workspace/tiinex.workspace.v1.findings.js +5 -0
  255. package/src/schemas/workspace/tiinex.workspace.v1.presenter.js +27 -0
  256. package/src/schemas/workspace/tiinex.workspace.v1.schema.js +30 -0
  257. package/src/schemas/workspace/tiinex.workspace.v1.schema.json +23 -0
  258. package/src/schemas/workspace/tiinex.workspace.v1.schema.runtime.json +1596 -0
  259. package/src/schemas/workspace/tiinex.workspace.v1.schema.source.js +9 -0
  260. package/src/schemas/workspace/tiinex.workspace.v1.sv.i18n.json +7 -0
  261. package/src/schemas/workspace/tiinex.workspace.v1.transitions.js +10 -0
  262. package/src/schemas/workspace/tiinex.workspace.v1.validate.js +10 -0
  263. package/src/sources/github/github.issueTarget.js +127 -0
  264. package/src/sources/origin.references.js +249 -0
  265. package/src/sources/source.explicitTargets.js +49 -0
  266. package/src/sources/transport.levels.js +107 -0
  267. package/src/tooling/portable/adapters/cli/cli.cold-start-input.js +34 -0
  268. package/src/tooling/portable/adapters/cli/cli.command-input.js +455 -0
  269. package/src/tooling/portable/adapters/cli/cli.common-author.js +249 -0
  270. package/src/tooling/portable/adapters/cli/cli.common-output.js +330 -0
  271. package/src/tooling/portable/adapters/cli/cli.editor-assistance.js +13 -0
  272. package/src/tooling/portable/adapters/cli/cli.ground-materialize.js +96 -0
  273. package/src/tooling/portable/adapters/cli/cli.ground-recovery.js +99 -0
  274. package/src/tooling/portable/adapters/cli/cli.handoff-manufacture.js +345 -0
  275. package/src/tooling/portable/adapters/cli/cli.handoff-sibling-allocation.js +31 -0
  276. package/src/tooling/portable/adapters/cli/cli.help.js +80 -0
  277. package/src/tooling/portable/adapters/cli/cli.land.js +13 -0
  278. package/src/tooling/portable/adapters/cli/cli.local-output.js +72 -0
  279. package/src/tooling/portable/adapters/cli/cli.material-policy.js +6 -0
  280. package/src/tooling/portable/adapters/cli/cli.operator-bridge.js +18 -0
  281. package/src/tooling/portable/adapters/cli/cli.reduction-input.js +14 -0
  282. package/src/tooling/portable/adapters/cli/cli.run.js +434 -0
  283. package/src/tooling/portable/adapters/llm/llm.entrypoint.js +34 -0
  284. package/src/tooling/portable/adapters/node/checkpoint.verify.js +267 -0
  285. package/src/tooling/portable/adapters/node/handoff.manufacture.bootstrap.js +109 -0
  286. package/src/tooling/portable/adapters/node/handoff.manufacture.enumeration.js +94 -0
  287. package/src/tooling/portable/adapters/node/handoff.manufacture.js +193 -0
  288. package/src/tooling/portable/adapters/node/handoff.manufacture.multiRoot.js +49 -0
  289. package/src/tooling/portable/adapters/node/handoff.manufacture.packageParent.js +130 -0
  290. package/src/tooling/portable/adapters/node/handoff.manufacture.requirements.js +353 -0
  291. package/src/tooling/portable/adapters/node/handoff.manufacture.scope.js +147 -0
  292. package/src/tooling/portable/adapters/node/workspaceCarrier.manufacture.js +62 -0
  293. package/src/tooling/portable/assets/asset.operations.js +170 -0
  294. package/src/tooling/portable/audit/audit.capability.js +119 -0
  295. package/src/tooling/portable/bootstrap/artifact.result.selfverify.mjs +109 -0
  296. package/src/tooling/portable/bootstrap/bootstrap.case.mjs +43 -0
  297. package/src/tooling/portable/bootstrap/tiinex.llm.bootstrap.md +814 -0
  298. package/src/tooling/portable/bootstrap/tiinex.llm.bootstrap.pointer.json +25 -0
  299. package/src/tooling/portable/checkpoint/portable.checkpoint.js +89 -0
  300. package/src/tooling/portable/conformance/checkpoint.qualification.js +271 -0
  301. package/src/tooling/portable/draft/draft.create.js +389 -0
  302. package/src/tooling/portable/draft/draft.crud.js +175 -0
  303. package/src/tooling/portable/draft/draft.exact.js +173 -0
  304. package/src/tooling/portable/draft/draft.operations.js +265 -0
  305. package/src/tooling/portable/draft/draft.qualification.js +45 -0
  306. package/src/tooling/portable/draft/draft.set.js +193 -0
  307. package/src/tooling/portable/draft/draft.validation-context.js +7 -0
  308. package/src/tooling/portable/editor/authoring.parent.js +37 -0
  309. package/src/tooling/portable/editor/editor.assistance.js +221 -0
  310. package/src/tooling/portable/editor/staged.validation.js +96 -0
  311. package/src/tooling/portable/engine.facade.js +468 -0
  312. package/src/tooling/portable/findings.js +92 -0
  313. package/src/tooling/portable/grounding/grounding.capsule.js +128 -0
  314. package/src/tooling/portable/grounding/grounding.continuity.js +283 -0
  315. package/src/tooling/portable/grounding/grounding.participantAuthority.js +20 -0
  316. package/src/tooling/portable/grounding/grounding.planningContext.js +34 -0
  317. package/src/tooling/portable/grounding/grounding.readiness.authority.js +17 -0
  318. package/src/tooling/portable/grounding/grounding.readiness.js +316 -0
  319. package/src/tooling/portable/grounding/grounding.readiness.support.js +245 -0
  320. package/src/tooling/portable/grounding/grounding.sourceEvidence.js +71 -0
  321. package/src/tooling/portable/grounding/grounding.workContext.js +72 -0
  322. package/src/tooling/portable/grounding/grounding.workProvenance.js +153 -0
  323. package/src/tooling/portable/handoff/carrierLineage.js +214 -0
  324. package/src/tooling/portable/handoff/carrierProfile.js +54 -0
  325. package/src/tooling/portable/handoff/carrierProjection.js +193 -0
  326. package/src/tooling/portable/handoff/carrierProjection.routeQualification.js +228 -0
  327. package/src/tooling/portable/handoff/carrierProjection.shared.js +7 -0
  328. package/src/tooling/portable/handoff/carrierProjection.workspaces.js +54 -0
  329. package/src/tooling/portable/handoff/coldConsumerEntrypoint.js +185 -0
  330. package/src/tooling/portable/handoff/coldStartQualification.contract.js +184 -0
  331. package/src/tooling/portable/handoff/coldStartQualification.grounding.js +392 -0
  332. package/src/tooling/portable/handoff/coldStartQualification.js +22 -0
  333. package/src/tooling/portable/handoff/coldStartQualification.materials.js +364 -0
  334. package/src/tooling/portable/handoff/coldStartQualification.observation.js +220 -0
  335. package/src/tooling/portable/handoff/coldStartQualification.run.js +81 -0
  336. package/src/tooling/portable/handoff/coldStartQualification.shared.js +57 -0
  337. package/src/tooling/portable/handoff/coldStartRolePointers.js +39 -0
  338. package/src/tooling/portable/handoff/contextAudit.js +247 -0
  339. package/src/tooling/portable/handoff/contracts/tiinex.handoff.package.v1.schema.md +409 -0
  340. package/src/tooling/portable/handoff/handoffAuthoringPlan.js +35 -0
  341. package/src/tooling/portable/handoff/handoffEndpointProjection.js +61 -0
  342. package/src/tooling/portable/handoff/handoffLeafProjection.js +91 -0
  343. package/src/tooling/portable/handoff/humanOutputPresentation.js +21 -0
  344. package/src/tooling/portable/handoff/manufacture.js +84 -0
  345. package/src/tooling/portable/handoff/materialClosure.archiveV2.binding.js +72 -0
  346. package/src/tooling/portable/handoff/materialClosure.archiveV2.direct.js +160 -0
  347. package/src/tooling/portable/handoff/materialClosure.archiveV2.indexes.js +36 -0
  348. package/src/tooling/portable/handoff/materialClosure.archiveV2.js +247 -0
  349. package/src/tooling/portable/handoff/materialClosure.archiveV2.projectionProvider.js +44 -0
  350. package/src/tooling/portable/handoff/materialClosure.archiveV2.workspace.js +226 -0
  351. package/src/tooling/portable/handoff/materialClosure.descriptor.js +169 -0
  352. package/src/tooling/portable/handoff/materialClosure.inputBinding.js +372 -0
  353. package/src/tooling/portable/handoff/materialClosure.inputBinding.support.js +62 -0
  354. package/src/tooling/portable/handoff/materialClosure.materialized.js +143 -0
  355. package/src/tooling/portable/handoff/materialClosure.materials.js +116 -0
  356. package/src/tooling/portable/handoff/materialClosure.package.js +181 -0
  357. package/src/tooling/portable/handoff/materialClosure.plan.js +204 -0
  358. package/src/tooling/portable/handoff/materialClosure.readiness.js +36 -0
  359. package/src/tooling/portable/handoff/materialClosure.requirements.js +137 -0
  360. package/src/tooling/portable/handoff/operatorContextProjection.js +105 -0
  361. package/src/tooling/portable/handoff/pointerEntrypoint.js +138 -0
  362. package/src/tooling/portable/handoff/qualifiedHandoffFixture.js +34 -0
  363. package/src/tooling/portable/handoff/recipientV2.artifactFirst.build.js +321 -0
  364. package/src/tooling/portable/handoff/recipientV2.artifactFirst.closure.js +126 -0
  365. package/src/tooling/portable/handoff/recipientV2.artifactFirst.inspect.js +194 -0
  366. package/src/tooling/portable/handoff/recipientV2.artifactFirst.materials.js +207 -0
  367. package/src/tooling/portable/handoff/recipientV2.artifactFirst.projection.js +69 -0
  368. package/src/tooling/portable/handoff/recipientV2.artifactFirst.roles.js +166 -0
  369. package/src/tooling/portable/handoff/recipientV2.artifactFirst.routes.js +113 -0
  370. package/src/tooling/portable/handoff/recipientV2.artifactFirst.shared.js +87 -0
  371. package/src/tooling/portable/handoff/recipientV2.artifactFirst.workspaces.js +160 -0
  372. package/src/tooling/portable/handoff/recipientV2.artifactFirstPhase1.js +44 -0
  373. package/src/tooling/portable/handoff/recipientV2.artifactInspection.js +55 -0
  374. package/src/tooling/portable/handoff/recipientV2.artifacts.js +174 -0
  375. package/src/tooling/portable/handoff/recipientV2.coldProjection.js +24 -0
  376. package/src/tooling/portable/handoff/recipientV2.delivery.js +48 -0
  377. package/src/tooling/portable/handoff/recipientV2.endpointRolePointers.js +179 -0
  378. package/src/tooling/portable/handoff/recipientV2.entryContract.js +28 -0
  379. package/src/tooling/portable/handoff/recipientV2.humanOutput.js +78 -0
  380. package/src/tooling/portable/handoff/recipientV2.inspect.helpers.js +218 -0
  381. package/src/tooling/portable/handoff/recipientV2.inspect.js +194 -0
  382. package/src/tooling/portable/handoff/recipientV2.inspect.pathToken.js +9 -0
  383. package/src/tooling/portable/handoff/recipientV2.inspect.projection.js +58 -0
  384. package/src/tooling/portable/handoff/recipientV2.inspect.workspaces.js +177 -0
  385. package/src/tooling/portable/handoff/recipientV2.lineage.js +142 -0
  386. package/src/tooling/portable/handoff/recipientV2.packageV1.build.js +147 -0
  387. package/src/tooling/portable/handoff/recipientV2.packageV1.constants.js +4 -0
  388. package/src/tooling/portable/handoff/recipientV2.packageV1.contract.js +101 -0
  389. package/src/tooling/portable/handoff/recipientV2.packageV1.inspect.helpers.js +126 -0
  390. package/src/tooling/portable/handoff/recipientV2.packageV1.inspect.js +185 -0
  391. package/src/tooling/portable/handoff/recipientV2.packageV1.js +12 -0
  392. package/src/tooling/portable/handoff/recipientV2.packageV1.shared.js +24 -0
  393. package/src/tooling/portable/handoff/recipientV2.packageV1.workspaceProjection.js +22 -0
  394. package/src/tooling/portable/handoff/recipientV2.pointer.js +40 -0
  395. package/src/tooling/portable/handoff/recipientV2.routeSelection.js +16 -0
  396. package/src/tooling/portable/handoff/recipientV2.topology.helpers.js +20 -0
  397. package/src/tooling/portable/handoff/recipientV2.topology.js +320 -0
  398. package/src/tooling/portable/handoff/recipientV2.topology.materials.js +70 -0
  399. package/src/tooling/portable/handoff/recipientV2.topology.workspaces.js +193 -0
  400. package/src/tooling/portable/handoff/recipientV2.transportManifest.js +123 -0
  401. package/src/tooling/portable/handoff/recipientV2.workspaceRepresentation.js +163 -0
  402. package/src/tooling/portable/handoff/routeArtifactConformance.js +130 -0
  403. package/src/tooling/portable/handoff/toolingBootstrap.js +67 -0
  404. package/src/tooling/portable/handoff/transportCompanion.js +175 -0
  405. package/src/tooling/portable/handoff/workspaceByteProvider.archive.js +95 -0
  406. package/src/tooling/portable/handoff/workspaceByteProvider.js +271 -0
  407. package/src/tooling/portable/handoff/workspaceCarrier.manufacture.js +93 -0
  408. package/src/tooling/portable/handoff/workspaceLandingPlan.js +142 -0
  409. package/src/tooling/portable/handoff/workspacePackageSources.js +105 -0
  410. package/src/tooling/portable/handoff/workspaceQualifiedReference.js +10 -0
  411. package/src/tooling/portable/handoff/workspaceSourceIdentity.js +52 -0
  412. package/src/tooling/portable/handoff/workspaceTargetConformance.js +134 -0
  413. package/src/tooling/portable/host/host.capabilities.js +181 -0
  414. package/src/tooling/portable/host/tool.bindings.js +357 -0
  415. package/src/tooling/portable/host/tool.receiptNormalization.js +141 -0
  416. package/src/tooling/portable/index.js +52 -0
  417. package/src/tooling/portable/input/node.input.js +184 -0
  418. package/src/tooling/portable/input/portable.input.js +249 -0
  419. package/src/tooling/portable/lifecycle/lifecycle.action.js +11 -0
  420. package/src/tooling/portable/lifecycle/lifecycle.material.js +173 -0
  421. package/src/tooling/portable/lifecycle/lifecycle.operations.js +34 -0
  422. package/src/tooling/portable/lifecycle/lifecycle.readiness.js +247 -0
  423. package/src/tooling/portable/lineage/lineage.integrity.apply.audit.js +22 -0
  424. package/src/tooling/portable/lineage/lineage.integrity.apply.evidence.js +36 -0
  425. package/src/tooling/portable/lineage/lineage.integrity.apply.js +306 -0
  426. package/src/tooling/portable/lineage/lineage.integrity.apply.structure.js +178 -0
  427. package/src/tooling/portable/lineage/lineage.integrity.plan.js +377 -0
  428. package/src/tooling/portable/lineage/lineage.integrity.projection.human.js +82 -0
  429. package/src/tooling/portable/lineage/lineage.integrity.projection.js +349 -0
  430. package/src/tooling/portable/lineage/lineage.operations.js +32 -0
  431. package/src/tooling/portable/lineage/lineage.print.js +398 -0
  432. package/src/tooling/portable/lineage/lineage.print.render.js +88 -0
  433. package/src/tooling/portable/lineage/lineage.print.utils.js +58 -0
  434. package/src/tooling/portable/lineage/lineage.publicationProviderReceipts.js +141 -0
  435. package/src/tooling/portable/lineage/lineage.publicationQualification.js +183 -0
  436. package/src/tooling/portable/lineage/lineage.search.js +301 -0
  437. package/src/tooling/portable/live/live.artifact.js +192 -0
  438. package/src/tooling/portable/live/live.export.js +107 -0
  439. package/src/tooling/portable/live/live.lineage.closure.js +71 -0
  440. package/src/tooling/portable/live/live.lineage.js +338 -0
  441. package/src/tooling/portable/live/live.protocol.js +181 -0
  442. package/src/tooling/portable/materialization/durable.materialize.js +162 -0
  443. package/src/tooling/portable/materialization/epistemic.plan.js +239 -0
  444. package/src/tooling/portable/materialization/loaded.parent.js +54 -0
  445. package/src/tooling/portable/materialization/materialization.facade.js +30 -0
  446. package/src/tooling/portable/operation.catalog.js +393 -0
  447. package/src/tooling/portable/operation.catalog.package.js +183 -0
  448. package/src/tooling/portable/operation.result.js +25 -0
  449. package/src/tooling/portable/orchestration/task.prepare.js +191 -0
  450. package/src/tooling/portable/output/artifact.result.package.js +308 -0
  451. package/src/tooling/portable/output/deterministic.zip.js +88 -0
  452. package/src/tooling/portable/output/node.artifact-set.js +223 -0
  453. package/src/tooling/portable/output/node.draft.js +41 -0
  454. package/src/tooling/portable/output/node.zip.js +39 -0
  455. package/src/tooling/portable/output/recipientV2.zip.js +59 -0
  456. package/src/tooling/portable/overview/blockingCue.js +16 -0
  457. package/src/tooling/portable/overview/operatingOverview.js +413 -0
  458. package/src/tooling/portable/package/generation.binding.js +314 -0
  459. package/src/tooling/portable/package/generation.binding.projection.js +128 -0
  460. package/src/tooling/portable/package/material.graph.js +236 -0
  461. package/src/tooling/portable/package/runtime.package.js +321 -0
  462. package/src/tooling/portable/package/schema.transition.companion.js +196 -0
  463. package/src/tooling/portable/package/semantic.package.graph.js +272 -0
  464. package/src/tooling/portable/package/semantic.package.js +203 -0
  465. package/src/tooling/portable/package/semantic.package.schema-resolution.js +158 -0
  466. package/src/tooling/portable/package/semantic.package.transition-registry.js +189 -0
  467. package/src/tooling/portable/package/semantic.package.types.js +18 -0
  468. package/src/tooling/portable/providers/schema.bootstrap.provenance.js +10 -0
  469. package/src/tooling/portable/providers/schema.provider.qualification.js +52 -0
  470. package/src/tooling/portable/providers/schema.providers.js +458 -0
  471. package/src/tooling/portable/publication/runtime.publication.js +53 -0
  472. package/src/tooling/portable/qualification.js +150 -0
  473. package/src/tooling/portable/reduction/reduction.composition.js +229 -0
  474. package/src/tooling/portable/reduction/reduction.eligibility.helpers.js +258 -0
  475. package/src/tooling/portable/reduction/reduction.eligibility.js +191 -0
  476. package/src/tooling/portable/reduction/reduction.operations.js +30 -0
  477. package/src/tooling/portable/reduction/reduction.preflight.js +85 -0
  478. package/src/tooling/portable/reduction/reduction.shared.js +173 -0
  479. package/src/tooling/portable/schema/bootstrap/canonical.pack.js +24 -0
  480. package/src/tooling/portable/schema/bootstrap/docs-3988951208eb9a8926e84ab42625d4b42fa00c2d/party/role/tiinex.party.role.v1.schema.md +289 -0
  481. package/src/tooling/portable/schema/bootstrap/docs-3988951208eb9a8926e84ab42625d4b42fa00c2d/validation/report/tiinex.validation.report.v1.schema.md +300 -0
  482. package/src/tooling/portable/schema/bootstrap/qualified-local-root/tiinex.root.v1.runtime-projection.json +48 -0
  483. package/src/tooling/portable/schema/bootstrap/qualified-local-root/tiinex.root.v1.schema.md +865 -0
  484. package/src/tooling/portable/schema/contract.compile.js +406 -0
  485. package/src/tooling/portable/schema/contract.compile.utils.js +9 -0
  486. package/src/tooling/portable/schema/contract.constraints.js +117 -0
  487. package/src/tooling/portable/schema/contract.envelope.validate.js +177 -0
  488. package/src/tooling/portable/schema/contract.field-domain.compile.js +399 -0
  489. package/src/tooling/portable/schema/contract.field-domain.js +247 -0
  490. package/src/tooling/portable/schema/contract.field-shape.compile.js +34 -0
  491. package/src/tooling/portable/schema/contract.inheritance.inline.js +103 -0
  492. package/src/tooling/portable/schema/contract.inheritance.js +210 -0
  493. package/src/tooling/portable/schema/contract.inheritance.record.js +76 -0
  494. package/src/tooling/portable/schema/contract.machine-shape.js +309 -0
  495. package/src/tooling/portable/schema/contract.project.js +81 -0
  496. package/src/tooling/portable/schema/contract.semantic-resolution.js +82 -0
  497. package/src/tooling/portable/schema/contract.validate.js +0 -0
  498. package/src/tooling/portable/schema/lexical.shape.v1.js +338 -0
  499. package/src/tooling/portable/schema/llm.companion.js +108 -0
  500. package/src/tooling/portable/schema/named.declarations.js +162 -0
  501. package/src/tooling/portable/schema/ordinary.contract.js +193 -0
  502. package/src/tooling/portable/schema/ordinary.fields.js +205 -0
  503. package/src/tooling/portable/schema/qualifiedLocalRoot.projection.js +70 -0
  504. package/src/tooling/portable/schema/qualifiedLocalRoot.runtime.js +170 -0
  505. package/src/tooling/portable/schema/schema.contract.js +465 -0
  506. package/src/tooling/portable/schema/schema.guide.js +326 -0
  507. package/src/tooling/portable/schema/schema.snapshot.js +119 -0
  508. package/src/tooling/portable/session/portable.session.js +145 -0
  509. package/src/tooling/portable/transfer/transfer.plan.js +102 -0
  510. package/src/transitions/record.transitions.js +484 -0
  511. package/src/transitions/transition.validate.js +129 -0
  512. package/src/validation/findings.js +76 -0
  513. package/src/validation/validateArtifact.js +216 -0
  514. package/src/workspaces/workspace.entrypointCapability.js +44 -0
  515. package/src/workspaces/workspace.materialRole.js +242 -0
  516. package/src/workspaces/workspace.recordPaths.js +426 -0
  517. package/tools/tiinex-portable.mjs +6 -0
@@ -0,0 +1,306 @@
1
+ import { parseArtifactMarkdown } from '../../../artifacts/artifact.parse.js';
2
+ import { canonicalC14nV2SelfState, validatedC14nV2PrimarySelfDigest } from '../../../integrity/integrity.c14nV2.js';
3
+ import { C14N_V2_METHOD_ID } from '../../../integrity/integrity.methodReference.js';
4
+ import { resolveLineage } from '../../../lineage/lineage.resolve.js';
5
+ import { normalizePortableInput } from '../input/portable.input.js';
6
+ import { portableFinding } from '../findings.js';
7
+ import { buildLineagePostRepairAudit } from './lineage.integrity.apply.audit.js';
8
+ import { normalizePublicationProviderReceipts } from './lineage.publicationProviderReceipts.js';
9
+ import { applyStructureAwareLineageMutation } from './lineage.integrity.apply.structure.js';
10
+ import { providerMaterialMatches, targetAuthorizedByDeclaredParent } from './lineage.integrity.apply.evidence.js';
11
+
12
+ export const PORTABLE_LINEAGE_INTEGRITY_APPLY_SCHEMA_ID = 'tiinex.portable.lineage-integrity-repair-application.v1';
13
+ export const PORTABLE_LINEAGE_INTEGRITY_RECEIPT_SCHEMA_ID = 'tiinex.portable.lineage-integrity-repair-receipt.v1';
14
+
15
+ const APPROVED = new Set(['approved', 'accepted']);
16
+ const SEMANTIC_DISPOSITIONS = new Set(['representation-only', 'harmless-representation-only', 'qualified-semantic-decision']);
17
+ const PLAN_ACTIONS = new Set(['backfill-parent-target-v2', 'review-parent-target-mismatch', 'update-parent-origin-permalink', 'no-change', 'resolve-lineage-integrity-blocker']);
18
+
19
+ export function applyPortableLineageIntegrityRepair(input = {}, options = {}) {
20
+ const material = normalizePortableInput(input.materials || input);
21
+ const records = (material.records || []).filter((record) => record?.path && typeof record.markdown === 'string');
22
+ const repairPlan = input.repairPlan || input.plan || null;
23
+ const providerEvidence = normalizePublicationProviderReceipts(input);
24
+ const findings = [...(material.findings || []), ...(providerEvidence.findings || [])];
25
+ const planValidation = validatePlan(repairPlan);
26
+ if (!planValidation.ok) return resultEnvelope({ status: 'blocked', records, receipts: [blockedReceipt('', '', 'plan-validation', planValidation.reasons)], findings: findingsWith(findings, 'error', 'portable.lineage-integrity-apply.plan-invalid', planValidation.reasons.join(', ')) });
27
+
28
+ const approvals = normalizeApprovals(input.approvals || input.artifactApprovals || input.dispositions || []);
29
+ const recordByPath = new Map(records.map((record) => [normalizePath(record.path), Object.freeze({ ...record, path: normalizePath(record.path) })]));
30
+ const stepByPath = new Map((repairPlan.steps || []).map((step) => [normalizePath(step?.artifact?.path), step]));
31
+ const lineage = resolveLineage(records, { depth: options.depth || 'portable-lineage-integrity-repair-application' });
32
+ const graph = buildParentGraph(lineage, recordByPath);
33
+ const order = topologicalPaths(recordByPath, graph.parentByChild, graph.childrenByParent);
34
+ const working = new Map(recordByPath);
35
+ const changedPaths = new Set();
36
+ const receipts = [];
37
+ const branchStops = new Set();
38
+
39
+ for (const path of order) {
40
+ const record = working.get(path);
41
+ if (!record) continue;
42
+ const step = stepByPath.get(path) || null;
43
+ const approval = approvals.get(path) || null;
44
+ const parentPath = graph.parentByChild.get(path) || '';
45
+ const parentChanged = Boolean(parentPath && changedPaths.has(parentPath));
46
+ const parentBranchStopped = Boolean(parentPath && branchStops.has(parentPath));
47
+ const directAction = Boolean(step && step.action && step.action !== 'no-change' && step.action !== 'resolve-lineage-integrity-blocker');
48
+
49
+ if (parentBranchStopped) {
50
+ branchStops.add(path);
51
+ continue;
52
+ }
53
+ if (!directAction && !parentChanged) continue;
54
+
55
+ const classification = classifyRepair({ path, record, step, approval, parentPath, parentChanged, working, providerEvidence });
56
+ if (!classification.ok) {
57
+ receipts.push(blockedReceipt(path, record.id || '', classification.repairClass, classification.blockers, { descendantsConsidered: descendantPaths(path, graph.childrenByParent) }));
58
+ if (parentChanged) branchStops.add(path);
59
+ findings.push(portableFinding('warning', 'portable.lineage-integrity-apply.blocked', `Lineage repair application blocked for ${path}.`, { ref: path, reason: classification.blockers.join(', ') }));
60
+ continue;
61
+ }
62
+
63
+ const parentRecord = parentPath ? working.get(parentPath) : null;
64
+ const applied = applyOne({ record, parentRecord, step, approval, repairClass: classification.repairClass, desiredTarget: classification.desiredTarget, parentChanged });
65
+ receipts.push(applied.receipt);
66
+ if (applied.status === 'blocked') {
67
+ if (parentChanged) branchStops.add(path);
68
+ findings.push(portableFinding('error', 'portable.lineage-integrity-apply.representation-guard', `Representation-preserving repair failed closed for ${path}.`, { ref: path, reason: applied.receipt.remainingBlockers.join(', ') }));
69
+ continue;
70
+ }
71
+ if (applied.status === 'changed') {
72
+ changedPaths.add(path);
73
+ working.set(path, Object.freeze({ ...record, markdown: applied.markdown }));
74
+ }
75
+ }
76
+
77
+ const resultingRecords = [...working.values()];
78
+ const changedRecords = [...changedPaths].map((path) => working.get(path)).filter(Boolean);
79
+ const blocked = receipts.some((receipt) => receipt.status === 'blocked');
80
+ const changed = changedRecords.length > 0;
81
+ const status = blocked ? (changed ? 'partial-blocked' : 'blocked') : changed ? 'changed' : 'no-op';
82
+ return resultEnvelope({ status, records: resultingRecords, changedRecords, receipts, findings });
83
+ }
84
+
85
+ function classifyRepair({ path, record, step, approval, parentPath, parentChanged, working, providerEvidence }) {
86
+ const repairClass = directRepairClass(step, parentChanged);
87
+ const blockers = [];
88
+ if (!approval || !APPROVED.has(String(approval.state || approval.disposition || '').toLowerCase())) blockers.push('per-artifact-approval-required');
89
+ if (step && !PLAN_ACTIONS.has(String(step.action || ''))) blockers.push(`unsupported-plan-action:${step.action || ''}`);
90
+ if (step?.approval?.disposition === 'blocked' && !canQualifyBlockedPlan(step, approval)) blockers.push(...(step.approval.blockers || ['plan-step-blocked']));
91
+ if (step?.action === 'review-parent-target-mismatch') {
92
+ if (!SEMANTIC_DISPOSITIONS.has(String(approval?.semanticDisposition || ''))) blockers.push('qualified-semantic-disposition-required');
93
+ if (!String(approval?.semanticAuthority || '').trim()) blockers.push('semantic-authority-reference-required');
94
+ for (const blocker of step?.approval?.blockers || []) if (!blockerSatisfied(blocker, approval)) blockers.push(blocker);
95
+ }
96
+ if (step?.action === 'backfill-parent-target-v2' && step?.approval?.disposition !== 'proposed') blockers.push(`backfill-plan-disposition-not-proposed:${step?.approval?.disposition || 'missing'}`);
97
+ if (step?.action === 'update-parent-origin-permalink') {
98
+ if (!Array.from(step?.expectedMutation?.headerFields || []).includes('Parent.Origin.browse+git')) blockers.push('plan-header-origin-update-not-authorized');
99
+ if (!String(step?.candidateParentOrigin || '').trim()) blockers.push('plan-candidate-parent-origin-missing');
100
+ if (approval?.publicationDisposition !== 'qualified-exact-publication') blockers.push('qualified-exact-publication-disposition-required');
101
+ }
102
+ if (parentChanged && !parentPath) blockers.push('cascade-parent-unresolved');
103
+ if (parentChanged && step?.action === 'resolve-lineage-integrity-blocker') blockers.push('blocked-descendant-cannot-cascade');
104
+ const currentSelf = canonicalC14nV2SelfState(record.markdown || '');
105
+ if (currentSelf.state !== 'verified') blockers.push(`child-self-${currentSelf.state || 'unavailable'}`);
106
+ const parentRecord = parentPath ? working.get(parentPath) : null;
107
+ if ((directNeedsParent(step) || parentChanged) && !parentRecord) blockers.push('exact-parent-material-required');
108
+ let parentSelf = null;
109
+ if (parentRecord) {
110
+ parentSelf = validatedC14nV2PrimarySelfDigest(parentRecord.markdown || '');
111
+ if (parentSelf.state !== 'verified') blockers.push(`parent-self-${parentSelf.state || 'unavailable'}`);
112
+ if (directNeedsParent(step) && !parentChanged && step?.candidateTargetDigest && parentSelf.state === 'verified' && step.candidateTargetDigest !== parentSelf.value) blockers.push('plan-candidate-parent-digest-stale');
113
+ }
114
+ const desiredTarget = desiredParentTarget(step, approval, record);
115
+ if ((directNeedsParent(step) || parentChanged) && !desiredTarget) blockers.push('parent-target-locator-unavailable');
116
+ if (directNeedsParent(step) && desiredTarget && !targetAuthorizedByDeclaredParent(record, step, approval, desiredTarget)) blockers.push('desired-parent-target-not-authorized-by-declared-parent');
117
+ if (parentRecord && step?.action === 'backfill-parent-target-v2') {
118
+ const evidenceTarget = String(step?.publicationLocator || step?.exactParentTarget?.publicationLocator || desiredTarget || '');
119
+ if (!providerMaterialMatches(providerEvidence, evidenceTarget, parentRecord.markdown || '', false)) blockers.push('accepted-exact-provider-material-required');
120
+ }
121
+ if (parentRecord && step?.action === 'review-parent-target-mismatch') {
122
+ const evidenceTarget = String(step?.publicationLocator || step?.exactParentTarget?.publicationLocator || '');
123
+ const historical = approval?.targetDisposition === 'repaired-local-parent' && approval?.originDisposition === 'historical-pre-repair-origin-retained';
124
+ if (!providerMaterialMatches(providerEvidence, evidenceTarget, parentRecord.markdown || '', historical)) blockers.push(historical ? 'accepted-historical-provider-material-required' : 'accepted-exact-provider-material-required');
125
+ }
126
+ if (parentRecord && step?.action === 'update-parent-origin-permalink') {
127
+ if (!providerMaterialMatches(providerEvidence, desiredTarget, parentRecord.markdown || '', false)) blockers.push('accepted-exact-provider-material-required');
128
+ }
129
+ return Object.freeze({ ok: blockers.length === 0, repairClass, desiredTarget, blockers: Object.freeze(unique(blockers)) });
130
+ }
131
+
132
+ function canQualifyBlockedPlan(step, approval) {
133
+ if (step?.action !== 'review-parent-target-mismatch') return false;
134
+ return (step?.approval?.blockers || []).every((blocker) => blockerSatisfied(blocker, approval));
135
+ }
136
+
137
+ function blockerSatisfied(blocker, approval = {}) {
138
+ if (blocker === 'existing-target-mismatch-is-not-refresh-authority') return SEMANTIC_DISPOSITIONS.has(String(approval.semanticDisposition || '')) && Boolean(String(approval.semanticAuthority || '').trim());
139
+ if (blocker === 'publication-origin-stale' || blocker === 'publication-origin-contradictory') return approval.targetDisposition === 'repaired-local-parent' && approval.originDisposition === 'historical-pre-repair-origin-retained' && SEMANTIC_DISPOSITIONS.has(String(approval.semanticDisposition || ''));
140
+ return false;
141
+ }
142
+
143
+ function directNeedsParent(step) { return ['backfill-parent-target-v2', 'review-parent-target-mismatch', 'update-parent-origin-permalink'].includes(step?.action); }
144
+ function directRepairClass(step, parentChanged) {
145
+ if (step?.action === 'backfill-parent-target-v2') return 'missing-parent-target-backfill';
146
+ if (step?.action === 'review-parent-target-mismatch') return 'mismatching-parent-target-refresh';
147
+ if (step?.action === 'update-parent-origin-permalink') return 'qualified-parent-origin-update';
148
+ return parentChanged ? 'descendant-cascade-reseal' : 'no-change';
149
+ }
150
+ function desiredParentTarget(step, approval, record) {
151
+ if (step?.action === 'review-parent-target-mismatch' && approval?.targetDisposition === 'repaired-local-parent') return String(step?.exactParentTarget?.trace || '').trim();
152
+ if (step?.action === 'update-parent-origin-permalink') return String(step?.candidateParentOrigin || '').trim();
153
+ if (step?.exactParentTarget?.expectedIntegrityTarget) return String(step.exactParentTarget.expectedIntegrityTarget).trim();
154
+ const parsed = safeParse(record?.markdown || '');
155
+ const existing = (parsed?.integrity?.entries || []).find((entry) => entry?.method === C14N_V2_METHOD_ID && String(entry?.towards || '') !== 'self');
156
+ return String(existing?.towards || '').trim();
157
+ }
158
+
159
+
160
+ function applyOne({ record, parentRecord, step, approval, repairClass, desiredTarget }) {
161
+ const original = String(record.markdown || '');
162
+ const oldParsed = safeParse(original);
163
+ if (!oldParsed) return blockedApply(record, repairClass, ['artifact-parse-failed']);
164
+ const oldSelf = canonicalC14nV2SelfState(original);
165
+ if (oldSelf.state !== 'verified') return blockedApply(record, repairClass, [`child-self-${oldSelf.state || 'unavailable'}`]);
166
+ const oldParentEntries = (oldParsed?.integrity?.entries || []).filter((entry) => entry?.method === C14N_V2_METHOD_ID && String(entry?.towards || '') !== 'self');
167
+ const oldParentEntry = oldParentEntries.length === 1 ? oldParentEntries[0] : null;
168
+ const oldHeaderTarget = browseGitOrigin(oldParsed);
169
+ const parentSelf = parentRecord ? validatedC14nV2PrimarySelfDigest(parentRecord.markdown || '') : null;
170
+ const desiredDigest = parentSelf?.state === 'verified' ? parentSelf.value : String(step?.candidateTargetDigest || '');
171
+ if (!desiredDigest) return blockedApply(record, repairClass, ['candidate-parent-digest-unavailable']);
172
+
173
+ const desiredHeaderTarget = step?.action === 'update-parent-origin-permalink' ? String(step.candidateParentOrigin || '') : oldHeaderTarget;
174
+ const alreadyDesired = oldParentEntries.length === 1 && oldParentEntry && oldParentEntry.towards === desiredTarget && oldParentEntry.value === desiredDigest && oldHeaderTarget === desiredHeaderTarget;
175
+ if (alreadyDesired) return noOpApply(record, repairClass, oldHeaderTarget, oldParentEntry, oldSelf, descendantList(step));
176
+
177
+ const structured = applyStructureAwareLineageMutation({
178
+ markdown: original,
179
+ target: desiredTarget,
180
+ digest: desiredDigest,
181
+ parentPath: parentRecord?.path || step?.exactParentTarget?.path || '',
182
+ parentOriginTarget: step?.action === 'update-parent-origin-permalink' && oldHeaderTarget !== desiredHeaderTarget ? desiredHeaderTarget : ''
183
+ });
184
+ if (!structured.ok) return blockedApply(record, repairClass, structured.blockers);
185
+ const next = structured.markdown;
186
+ const newParsed = safeParse(next);
187
+ const newSelf = canonicalC14nV2SelfState(next);
188
+ if (!newParsed || newSelf.state !== 'verified') return blockedApply(record, repairClass, [`post-repair-self-${newSelf.state || 'unavailable'}`]);
189
+ const newParentEntry = parentIntegrityEntry(newParsed);
190
+ if (!newParentEntry || newParentEntry.towards !== desiredTarget || newParentEntry.value !== desiredDigest) return blockedApply(record, repairClass, ['post-repair-parent-target-verification-failed']);
191
+
192
+ const receipt = repairReceipt({
193
+ status: next === original ? 'no-op' : 'changed', record, repairClass,
194
+ reason: String(approval?.reason || approval?.semanticDisposition || step?.currentState || repairClass),
195
+ oldHeaderTarget, newHeaderTarget: browseGitOrigin(newParsed),
196
+ oldParentTarget: oldParentEntry, newParentTarget: newParentEntry,
197
+ oldSelfDigest: oldSelf.declaredValue || '', newSelfDigest: newSelf.declaredValue || '',
198
+ descendantsConsidered: descendantList(step), mutationSurfaces: structured.mutationSurfaces,
199
+ bodyPreserved: structured.bodyPreserved,
200
+ siblingFooterEntriesPreserved: structured.siblingFooterEntriesPreserved,
201
+ remainingBlockers: []
202
+ });
203
+ return Object.freeze({ status: receipt.status, markdown: next, receipt });
204
+ }
205
+
206
+ function buildParentGraph(lineage, recordByPath) {
207
+ const pathById = new Map((lineage.nodes || []).map((node) => [String(node.id || ''), normalizePath(node.path || node.record?.path || '')]));
208
+ const parentByChild = new Map();
209
+ const childrenByParent = new Map();
210
+ for (const edge of lineage.edges || []) {
211
+ if (edge.kind !== 'parent' || !edge.from || !edge.to || edge.status === 'missing') continue;
212
+ const parent = pathById.get(String(edge.from)) || '';
213
+ const child = pathById.get(String(edge.to)) || '';
214
+ if (!parent || !child || !recordByPath.has(parent) || !recordByPath.has(child)) continue;
215
+ if (parentByChild.has(child) && parentByChild.get(child) !== parent) continue;
216
+ parentByChild.set(child, parent);
217
+ const children = childrenByParent.get(parent) || [];
218
+ children.push(child);
219
+ childrenByParent.set(parent, unique(children).sort());
220
+ }
221
+ return Object.freeze({ parentByChild, childrenByParent });
222
+ }
223
+
224
+ function topologicalPaths(recordByPath, parentByChild, childrenByParent) {
225
+ const indegree = new Map([...recordByPath.keys()].map((path) => [path, parentByChild.has(path) ? 1 : 0]));
226
+ const queue = [...indegree].filter(([, degree]) => degree === 0).map(([path]) => path).sort();
227
+ const out = [];
228
+ while (queue.length) {
229
+ const path = queue.shift();
230
+ out.push(path);
231
+ for (const child of childrenByParent.get(path) || []) {
232
+ indegree.set(child, Math.max(0, (indegree.get(child) || 0) - 1));
233
+ if (indegree.get(child) === 0) { queue.push(child); queue.sort(); }
234
+ }
235
+ }
236
+ for (const path of [...recordByPath.keys()].sort()) if (!out.includes(path)) out.push(path);
237
+ return out;
238
+ }
239
+
240
+ function descendantPaths(path, childrenByParent) {
241
+ const out = [];
242
+ const queue = [...(childrenByParent.get(path) || [])].map((child) => ({ path: child, depth: 1 }));
243
+ const seen = new Set();
244
+ while (queue.length) {
245
+ const current = queue.shift();
246
+ if (!current || seen.has(current.path)) continue;
247
+ seen.add(current.path);
248
+ out.push(Object.freeze({ path: current.path, depth: current.depth }));
249
+ for (const child of childrenByParent.get(current.path) || []) queue.push({ path: child, depth: current.depth + 1 });
250
+ }
251
+ return Object.freeze(out);
252
+ }
253
+
254
+ function validatePlan(plan) {
255
+ const reasons = [];
256
+ if (!plan || typeof plan !== 'object') reasons.push('explicit-repair-plan-required');
257
+ if (plan?.schema !== 'tiinex.portable.repair-plan.v1') reasons.push(`repair-plan-schema-unsupported:${plan?.schema || 'missing'}`);
258
+ if (plan?.mode !== 'lineage-integrity-inspection') reasons.push(`repair-plan-mode-unsupported:${plan?.mode || 'missing'}`);
259
+ if (!Array.isArray(plan?.steps)) reasons.push('repair-plan-steps-required');
260
+ if (plan?.boundary?.automaticRewrite !== false) reasons.push('repair-plan-automatic-rewrite-boundary-invalid');
261
+ return Object.freeze({ ok: reasons.length === 0, reasons: Object.freeze(reasons) });
262
+ }
263
+
264
+ function normalizeApprovals(value) {
265
+ const out = new Map();
266
+ if (Array.isArray(value)) {
267
+ for (const item of value) { const path = normalizePath(item?.path || item?.artifact?.path || ''); if (path) out.set(path, Object.freeze({ ...item, path })); }
268
+ } else if (value && typeof value === 'object') {
269
+ for (const [key, item] of Object.entries(value)) { const path = normalizePath(item?.path || key); if (path) out.set(path, Object.freeze({ ...(item || {}), path })); }
270
+ }
271
+ return out;
272
+ }
273
+
274
+ function resultEnvelope({ status, records, changedRecords = [], receipts = [], findings = [] }) {
275
+ const frozenReceipts = Object.freeze(receipts.map((receipt) => Object.freeze(receipt)));
276
+ const humanReceipt = frozenReceipts.map((receipt) => humanReceiptLine(receipt)).join('\n');
277
+ const reAudit = buildLineagePostRepairAudit(records, changedRecords);
278
+ return Object.freeze({
279
+ schema: PORTABLE_LINEAGE_INTEGRITY_APPLY_SCHEMA_ID,
280
+ status,
281
+ changeset: Object.freeze({ schema: 'tiinex.portable.local-lineage-repair-changeset.v1', records: Object.freeze(changedRecords.map((record) => Object.freeze({ ...record }))), changedPaths: Object.freeze(changedRecords.map((record) => record.path)), sourceMutation: false, remoteWrite: false, publicationMutation: false }),
282
+ receipts: frozenReceipts,
283
+ humanReceipt,
284
+ reAudit,
285
+ boundary: Object.freeze({ explicitRepairPlanRequired: true, perArtifactApprovalRequired: true, structureAwareEditing: true, bodyMutationAuthorized: false, sourceMutation: false, remoteWrite: false, publicationMutation: false, representationDiffFailClosed: true, postRepairReAuditRequired: true, sharedAuditCapability: true }),
286
+ inputRecordCount: records.length,
287
+ findings: Object.freeze(findings)
288
+ });
289
+ }
290
+
291
+ function repairReceipt({ status, record, repairClass, reason, oldHeaderTarget, newHeaderTarget, oldParentTarget, newParentTarget, oldSelfDigest, newSelfDigest, descendantsConsidered, mutationSurfaces, bodyPreserved, siblingFooterEntriesPreserved, remainingBlockers }) {
292
+ return Object.freeze({ schema: PORTABLE_LINEAGE_INTEGRITY_RECEIPT_SCHEMA_ID, status, artifact: Object.freeze({ id: String(record.id || ''), path: normalizePath(record.path || '') }), repairClass, reason, oldHeaderTargets: Object.freeze({ parentOriginBrowseGit: oldHeaderTarget || '' }), newHeaderTargets: Object.freeze({ parentOriginBrowseGit: newHeaderTarget || '' }), oldParentTarget: Object.freeze({ locator: oldParentTarget?.towards || '', digest: oldParentTarget?.value || '' }), newParentTarget: Object.freeze({ locator: newParentTarget?.towards || '', digest: newParentTarget?.value || '' }), oldSelfDigest: oldSelfDigest || '', newSelfDigest: newSelfDigest || '', descendantsConsidered: Object.freeze([...(descendantsConsidered || [])]), mutationSurface: Object.freeze([...(mutationSurfaces || [])]), bodyPreservationCheck: bodyPreserved ? 'byte-identical' : 'failed', siblingFooterPreservationCheck: siblingFooterEntriesPreserved ? 'byte-identical' : 'failed', remainingBlockers: Object.freeze([...(remainingBlockers || [])]) });
293
+ }
294
+ function blockedReceipt(path, id, repairClass, blockers, extra = {}) { return repairReceipt({ status: 'blocked', record: { path, id }, repairClass, reason: 'blocked', oldHeaderTarget: '', newHeaderTarget: '', oldParentTarget: null, newParentTarget: null, oldSelfDigest: '', newSelfDigest: '', descendantsConsidered: extra.descendantsConsidered || [], mutationSurfaces: [], bodyPreserved: true, siblingFooterEntriesPreserved: true, remainingBlockers: unique(blockers) }); }
295
+ function blockedApply(record, repairClass, blockers) { return Object.freeze({ status: 'blocked', markdown: record.markdown || '', receipt: blockedReceipt(record.path || '', record.id || '', repairClass, blockers) }); }
296
+ function noOpApply(record, repairClass, header, parentEntry, self, descendants) { return Object.freeze({ status: 'no-op', markdown: record.markdown || '', receipt: repairReceipt({ status: 'no-op', record, repairClass, reason: 'already-repaired', oldHeaderTarget: header, newHeaderTarget: header, oldParentTarget: parentEntry, newParentTarget: parentEntry, oldSelfDigest: self.declaredValue || '', newSelfDigest: self.declaredValue || '', descendantsConsidered: descendants, mutationSurfaces: [], bodyPreserved: true, siblingFooterEntriesPreserved: true, remainingBlockers: [] }) }); }
297
+ function humanReceiptLine(receipt) { const path = receipt.artifact?.path || '(plan)'; const blockers = receipt.remainingBlockers?.length ? ` blockers=${receipt.remainingBlockers.join(',')}` : ''; return `${receipt.status.toUpperCase()} ${path} ${receipt.repairClass}${blockers}`; }
298
+ function findingsWith(findings, severity, code, message) { return [...findings, portableFinding(severity, code, message, {})]; }
299
+
300
+ function parentIntegrityEntry(parsed) { return (parsed?.integrity?.entries || []).find((entry) => entry?.method === C14N_V2_METHOD_ID && String(entry?.towards || '') !== 'self') || null; }
301
+ function browseGitOrigin(parsed) { return String((parsed?.envelope?.parent?.originEntries || []).find((entry) => entry.label === 'browse + git')?.target || ''); }
302
+ function descendantList(step) { return Object.freeze([...(step?.descendantImpact || [])]); }
303
+ function safeParse(markdown) { try { return parseArtifactMarkdown(markdown); } catch { return null; } }
304
+
305
+ function normalizePath(value) { return String(value || '').replace(/\\/g, '/').replace(/^\.\//, '').replace(/^\/+|\/+$/g, ''); }
306
+ function unique(values) { return [...new Set((values || []).map(String).filter(Boolean))]; }
@@ -0,0 +1,178 @@
1
+ import { canonicalC14nV2SelfState } from '../../../integrity/integrity.c14nV2.js';
2
+ import { C14N_V2_METHOD_ID } from '../../../integrity/integrity.methodReference.js';
3
+
4
+ export function applyStructureAwareLineageMutation({ markdown = '', target = '', digest = '', parentPath = '', parentOriginTarget = '' } = {}) {
5
+ const before = structuralSnapshots(markdown);
6
+ if (!before.ok) return before;
7
+ let next = String(markdown || '');
8
+ const mutationSurfaces = [];
9
+ if (parentOriginTarget) {
10
+ const header = updateParentBrowseGit(next, parentOriginTarget);
11
+ if (!header.ok) return header;
12
+ next = header.markdown;
13
+ mutationSurfaces.push('Continuity Context/Parent/Origin/browse + git');
14
+ }
15
+ const footer = upsertParentIntegrity(next, { target, digest, parentPath });
16
+ if (!footer.ok) return footer;
17
+ next = footer.markdown;
18
+ mutationSurfaces.push('Continuity Integrity/Parent-target c14n-v2');
19
+ const resealed = resealSelfPreservingRepresentation(next);
20
+ if (!resealed.ok) return resealed;
21
+ next = resealed.markdown;
22
+ mutationSurfaces.push('Continuity Integrity/primary self Value');
23
+ const after = structuralSnapshots(next);
24
+ const guard = representationGuard(before, after, { headerUpdate: Boolean(parentOriginTarget) });
25
+ if (!guard.ok) return guard;
26
+ return Object.freeze({ ok: true, markdown: next, mutationSurfaces: Object.freeze(mutationSurfaces), bodyPreserved: before.body === after.body, siblingFooterEntriesPreserved: guard.siblingFooterEntriesPreserved });
27
+ }
28
+
29
+ function upsertParentIntegrity(markdown, { target, digest, parentPath }) {
30
+ const model = scanIntegrity(markdown);
31
+ if (!model.ok) return model;
32
+ if (model.selfEntries.length !== 1) return fail('primary-self-entry-not-exactly-one');
33
+ if (model.parentEntries.length > 1) return fail('parent-target-entry-ambiguous');
34
+ const lines = model.lines.slice();
35
+ if (model.parentEntries.length === 1) {
36
+ const entry = model.parentEntries[0];
37
+ if (entry.towardsLine < 0 || entry.valueLine < 0) return fail('parent-target-entry-malformed');
38
+ lines[entry.towardsLine] = replaceFieldLine(lines[entry.towardsLine], 'Towards', renderTowards(entry.towardsRaw, target));
39
+ lines[entry.valueLine] = replaceFieldLine(lines[entry.valueLine], 'Value', digest);
40
+ return Object.freeze({ ok: true, markdown: joinLines(lines) });
41
+ }
42
+ const self = model.selfEntries[0];
43
+ const methodRaw = self.methodRaw || C14N_V2_METHOD_ID;
44
+ const eol = model.preferredEol;
45
+ const label = basename(parentPath) || basename(target) || 'parent';
46
+ const insert = [
47
+ makeLine(`- ${methodRaw}`, eol),
48
+ makeLine(` - Towards: [${label}](${target})`, eol),
49
+ makeLine(` - Value: ${digest}`, eol),
50
+ makeLine('', eol)
51
+ ];
52
+ lines.splice(self.start, 0, ...insert);
53
+ return Object.freeze({ ok: true, markdown: joinLines(lines) });
54
+ }
55
+
56
+ function resealSelfPreservingRepresentation(markdown) {
57
+ const state = canonicalC14nV2SelfState(markdown);
58
+ if (!['verified', 'mismatch', 'prepared'].includes(state.state)) return fail(`self-seal-${state.reason || state.state}`);
59
+ const model = scanIntegrity(markdown);
60
+ if (!model.ok || model.selfEntries.length !== 1) return fail('primary-self-entry-not-exactly-one');
61
+ const self = model.selfEntries[0];
62
+ if (self.valueLine < 0) return fail('self-value-field-missing');
63
+ const lines = model.lines.slice();
64
+ lines[self.valueLine] = replaceFieldLine(lines[self.valueLine], 'Value', state.computedValue);
65
+ const next = joinLines(lines);
66
+ const verified = canonicalC14nV2SelfState(next);
67
+ if (verified.state !== 'verified') return fail(`self-seal-postcondition-${verified.state}`);
68
+ return Object.freeze({ ok: true, markdown: next, value: verified.declaredValue });
69
+ }
70
+
71
+ function updateParentBrowseGit(markdown, target) {
72
+ if (!/^https:\/\/github\.com\/[^/]+\/[^/]+\/blob\/[0-9a-f]{40}\//.test(String(target || ''))) return fail('parent-origin-target-not-immutable-github-blob');
73
+ const lines = splitLines(markdown);
74
+ const rule = firstRuleIndex(lines);
75
+ if (rule < 0) return fail('continuity-envelope-divider-missing');
76
+ const parent = topLevelBlock(lines, '- Parent', rule);
77
+ if (!parent) return fail('parent-envelope-block-missing');
78
+ const originIndex = findInRange(lines, parent.start + 1, parent.end, /^\s{2}-\s+Origin:\s*$/);
79
+ if (originIndex < 0) return fail('parent-origin-block-missing');
80
+ const nestedEnd = nestedListEnd(lines, originIndex + 1, parent.end, 2);
81
+ const browse = findInRange(lines, originIndex + 1, nestedEnd, /^\s{4}-\s+\[browse \+ git\]\([^)]+\)\s*$/);
82
+ if (browse >= 0) {
83
+ const raw = lines[browse].content;
84
+ lines[browse] = { ...lines[browse], content: raw.replace(/\[browse \+ git\]\([^)]+\)/, `[browse + git](${target})`) };
85
+ } else {
86
+ const eol = preferredEol(lines);
87
+ lines.splice(nestedEnd, 0, makeLine(` - [browse + git](${target})`, eol));
88
+ }
89
+ return Object.freeze({ ok: true, markdown: joinLines(lines) });
90
+ }
91
+
92
+ function scanIntegrity(markdown) {
93
+ const lines = splitLines(markdown);
94
+ const headings = [];
95
+ for (let i = 0; i < lines.length; i += 1) if (/^# Continuity Integrity[ \t]*$/.test(lines[i].content)) headings.push(i);
96
+ if (headings.length !== 1) return fail(headings.length ? 'multiple-integrity-footers' : 'integrity-footer-missing');
97
+ const heading = headings[0];
98
+ const entries = [];
99
+ let current = null;
100
+ const finish = (end) => { if (current) { current.end = end; entries.push(Object.freeze(current)); current = null; } };
101
+ for (let i = heading + 1; i < lines.length; i += 1) {
102
+ const line = lines[i].content;
103
+ if (/^#\s+/.test(line)) { finish(i); break; }
104
+ const top = line.match(/^-\s+(.+?)\s*$/);
105
+ if (top) {
106
+ finish(i);
107
+ current = { start: i, end: lines.length, methodRaw: top[1].trim(), method: stripLink(top[1].trim()), towards: '', towardsRaw: '', towardsLine: -1, value: '', valueLine: -1 };
108
+ continue;
109
+ }
110
+ if (!current) continue;
111
+ const towards = line.match(/^\s+-\s+Towards:\s*(.*?)\s*$/);
112
+ if (towards) { current.towardsRaw = towards[1].trim(); current.towards = linkTargetOrText(current.towardsRaw); current.towardsLine = i; }
113
+ const value = line.match(/^\s+-\s+Value:\s*(.*?)\s*$/);
114
+ if (value) { current.value = value[1].trim(); current.valueLine = i; }
115
+ }
116
+ finish(lines.length);
117
+ const c14n = entries.filter((entry) => entry.method === C14N_V2_METHOD_ID);
118
+ return Object.freeze({ ok: true, lines, heading, entries: Object.freeze(entries), selfEntries: Object.freeze(c14n.filter((entry) => entry.towards === 'self')), parentEntries: Object.freeze(c14n.filter((entry) => entry.towards && entry.towards !== 'self')), preferredEol: preferredEol(lines) });
119
+ }
120
+
121
+ function structuralSnapshots(markdown) {
122
+ const lines = splitLines(markdown);
123
+ const rule = firstRuleIndex(lines);
124
+ const footer = lines.findIndex((line) => /^# Continuity Integrity[ \t]*$/.test(line.content));
125
+ if (rule < 0 || footer < 0 || footer <= rule) return Object.freeze({ ok: false, blockers: Object.freeze(['artifact-structure-boundaries-unavailable']) });
126
+ const envelope = joinLines(lines.slice(0, rule));
127
+ const body = joinLines(lines.slice(rule, footer));
128
+ const integrity = scanIntegrity(markdown);
129
+ if (!integrity.ok) return Object.freeze({ ok: false, blockers: integrity.blockers });
130
+ const siblingEntries = integrity.entries.filter((entry) => entry.method !== C14N_V2_METHOD_ID).map((entry) => joinLines(lines.slice(entry.start, entry.end)));
131
+ const repairs = envelopeBlockRaw(lines, rule, '- Repairs:');
132
+ return Object.freeze({ ok: true, envelope, body, repairs, siblingEntries: Object.freeze(siblingEntries) });
133
+ }
134
+
135
+ function representationGuard(before, after, { headerUpdate = false } = {}) {
136
+ const blockers = [];
137
+ if (!after.ok) blockers.push(...(after.blockers || ['post-repair-structure-unavailable']));
138
+ if (before.body !== after.body) blockers.push('body-representation-changed');
139
+ if (!headerUpdate && before.envelope !== after.envelope) blockers.push('unapproved-header-representation-changed');
140
+ if (before.repairs !== after.repairs) blockers.push('repairs-provenance-changed');
141
+ const siblingFooterEntriesPreserved = JSON.stringify(before.siblingEntries) === JSON.stringify(after.siblingEntries);
142
+ if (!siblingFooterEntriesPreserved) blockers.push('unapproved-sibling-footer-entry-changed');
143
+ return Object.freeze({ ok: blockers.length === 0, blockers: Object.freeze(unique(blockers)), siblingFooterEntriesPreserved });
144
+ }
145
+
146
+ function splitLines(text) {
147
+ const out = [];
148
+ const source = String(text || '');
149
+ const re = /([^\r\n]*)(\r\n|\n|\r|$)/g;
150
+ let match;
151
+ while ((match = re.exec(source)) && (match[0] || re.lastIndex === 0)) {
152
+ if (match[0] === '' && re.lastIndex >= source.length) break;
153
+ out.push({ content: match[1], eol: match[2] });
154
+ if (!match[2]) break;
155
+ }
156
+ if (!out.length) out.push({ content: '', eol: '' });
157
+ return out;
158
+ }
159
+ function joinLines(lines) { return lines.map((line) => `${line.content}${line.eol}`).join(''); }
160
+ function makeLine(content, eol) { return { content, eol }; }
161
+ function preferredEol(lines) { return lines.find((line) => line.eol)?.eol || '\n'; }
162
+ function replaceFieldLine(line, label, value) {
163
+ const match = line.content.match(new RegExp(`^(\\s+-\\s+${escapeRegExp(label)}:)([ \\t]*)(.*)$`));
164
+ if (!match) return line;
165
+ return { ...line, content: `${match[1]}${match[2]}${value}` };
166
+ }
167
+ function renderTowards(raw, target) { const match = String(raw || '').match(/^\[([^\]]+)\]\([^)]+\)$/); return match ? `[${match[1]}](${target})` : target; }
168
+ function stripLink(value) { const match = String(value || '').match(/^\[([^\]]+)\]\([^)]+\)$/); return (match ? match[1] : String(value || '')).trim(); }
169
+ function linkTargetOrText(value) { const match = String(value || '').match(/^\[[^\]]+\]\(([^)]+)\)$/); return (match ? match[1] : String(value || '')).trim(); }
170
+ function firstRuleIndex(lines) { return lines.findIndex((line) => /^---[ \t]*$/.test(line.content)); }
171
+ function topLevelBlock(lines, marker, limit) { const start = lines.findIndex((line, index) => index < limit && line.content === marker); if (start < 0) return null; let end = limit; for (let i = start + 1; i < limit; i += 1) if (/^-\s+\S/.test(lines[i].content)) { end = i; break; } return { start, end }; }
172
+ function findInRange(lines, start, end, regex) { for (let i = start; i < end; i += 1) if (regex.test(lines[i].content)) return i; return -1; }
173
+ function nestedListEnd(lines, start, end, parentIndent) { for (let i = start; i < end; i += 1) { const indent = (lines[i].content.match(/^\s*/) || [''])[0].length; if (/^\s*-\s+\S/.test(lines[i].content) && indent <= parentIndent) return i; } return end; }
174
+ function envelopeBlockRaw(lines, rule, marker) { const start = lines.findIndex((line, index) => index < rule && line.content === marker); if (start < 0) return ''; let end = rule; for (let i = start + 1; i < rule; i += 1) if (/^-\s+\S/.test(lines[i].content)) { end = i; break; } return joinLines(lines.slice(start, end)); }
175
+ function basename(value) { const clean = String(value || '').replace(/[?#].*$/, '').replace(/\/+$/, ''); return clean.split('/').pop() || ''; }
176
+ function unique(values) { return [...new Set((values || []).map(String).filter(Boolean))]; }
177
+ function escapeRegExp(value) { return String(value || '').replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); }
178
+ function fail(...blockers) { return Object.freeze({ ok: false, blockers: Object.freeze(unique(blockers.flat())) }); }