@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,338 @@
1
+ export const PORTABLE_LEXICAL_SHAPE_PROFILE_V1 = 'tiinex.lexical.shape.v1';
2
+
3
+ const RESERVED_IDENTIFIERS = new Set(['SPACE', 'TAB', 'CR', 'LF', 'DIGIT', 'ASCII-LETTER', 'ANY', 'ANY-EXCEPT']);
4
+ const SIMPLE_BUILTINS = new Set(['SPACE', 'TAB', 'CR', 'LF', 'DIGIT', 'ASCII-LETTER', 'ANY']);
5
+
6
+ export function compileLexicalShapeV1(input = {}) {
7
+ const startRule = exact(input.startRule);
8
+ const grammarRules = Array.isArray(input.grammarRules) ? input.grammarRules.map(String) : [];
9
+ const findings = [];
10
+ const rules = [];
11
+ const byName = new Map();
12
+
13
+ if (!grammarRules.length) findings.push('At least one Grammar Rule is required.');
14
+ for (let index = 0; index < grammarRules.length; index += 1) {
15
+ const source = grammarRules[index];
16
+ try {
17
+ const parsed = parseGrammarRule(source);
18
+ if (RESERVED_IDENTIFIERS.has(parsed.name)) throw new GrammarError(`Grammar Rule identifier is reserved: ${parsed.name}.`);
19
+ if (byName.has(parsed.name)) throw new GrammarError(`Duplicate Grammar Rule identifier: ${parsed.name}.`);
20
+ const rule = { name: parsed.name, source, expression: parsed.expression };
21
+ byName.set(parsed.name, rule);
22
+ rules.push(rule);
23
+ } catch (error) {
24
+ findings.push(`Grammar Rule ${index + 1}: ${messageOf(error)}`);
25
+ }
26
+ }
27
+
28
+ if (!startRule) findings.push('Start Rule is required.');
29
+ else if (!byName.has(startRule)) findings.push(`Start Rule does not resolve to a declared Grammar Rule: ${startRule}.`);
30
+
31
+ if (!findings.length) {
32
+ for (const rule of rules) {
33
+ for (const reference of collectReferences(rule.expression)) {
34
+ if (!byName.has(reference)) findings.push(`Undefined local Grammar Rule reference: ${reference}.`);
35
+ }
36
+ }
37
+ }
38
+ if (!findings.length) findings.push(...detectCycles(rules));
39
+
40
+ const frozenRules = Object.freeze(rules.map((rule) => Object.freeze({
41
+ name: rule.name,
42
+ source: rule.source,
43
+ expression: freezeNode(rule.expression)
44
+ })));
45
+ return Object.freeze({
46
+ profile: PORTABLE_LEXICAL_SHAPE_PROFILE_V1,
47
+ qualification: findings.length ? 'structurally-invalid' : 'valid',
48
+ startRule,
49
+ grammarRules: frozenRules,
50
+ findings: Object.freeze(findings)
51
+ });
52
+ }
53
+
54
+ export function qualifyLexicalShapeV1(compiled = {}, value = '') {
55
+ if (compiled?.qualification !== 'valid') return Object.freeze({ qualification: 'unresolved' });
56
+ const rules = new Map((compiled.grammarRules || []).map((rule) => [rule.name, rule.expression]));
57
+ const start = rules.get(compiled.startRule);
58
+ if (!start) return Object.freeze({ qualification: 'unresolved' });
59
+ const scalars = [...String(value ?? '')];
60
+ const memo = new WeakMap();
61
+ const positions = matchNode(start, 0, scalars, rules, memo);
62
+ return Object.freeze({ qualification: positions.has(scalars.length) ? 'matched' : 'not-matched' });
63
+ }
64
+
65
+ function parseGrammarRule(source = '') {
66
+ const tokens = tokenizeGrammar(source);
67
+ const parser = new Parser(tokens);
68
+ const name = parser.takeIdentifier('Grammar Rule identifier');
69
+ parser.expect('=');
70
+ const expression = parser.parseExpression(new Set(['eof']));
71
+ parser.expect('eof');
72
+ return { name, expression };
73
+ }
74
+
75
+ function tokenizeGrammar(source = '') {
76
+ const text = String(source ?? '');
77
+ const tokens = [];
78
+ let index = 0;
79
+ while (index < text.length) {
80
+ const ch = text[index];
81
+ if (ch === ' ' || ch === '\t') { index += 1; continue; }
82
+ if (isForbiddenMetaWhitespace(ch)) throw new GrammarError(`Unsupported grammar-source whitespace U+${ch.codePointAt(0).toString(16).toUpperCase().padStart(4, '0')}.`);
83
+ if (ch === '"') {
84
+ const parsed = readQuotedLiteral(text, index);
85
+ tokens.push({ type: 'literal', value: parsed.value });
86
+ index = parsed.next;
87
+ continue;
88
+ }
89
+ if (/[A-Za-z]/.test(ch)) {
90
+ let end = index + 1;
91
+ while (end < text.length && /[A-Za-z0-9-]/.test(text[end])) end += 1;
92
+ tokens.push({ type: 'identifier', value: text.slice(index, end) });
93
+ index = end;
94
+ continue;
95
+ }
96
+ if ('?*+|(),='.includes(ch)) {
97
+ tokens.push({ type: ch, value: ch });
98
+ index += 1;
99
+ continue;
100
+ }
101
+ throw new GrammarError(`Unsupported grammar token: ${ch}.`);
102
+ }
103
+ tokens.push({ type: 'eof', value: '' });
104
+ return tokens;
105
+ }
106
+
107
+ function readQuotedLiteral(text, start) {
108
+ let index = start + 1;
109
+ let value = '';
110
+ while (index < text.length) {
111
+ const ch = text[index];
112
+ if (ch === '"') return { value, next: index + 1 };
113
+ if (ch !== '\\') {
114
+ value += ch;
115
+ index += 1;
116
+ continue;
117
+ }
118
+ if (index + 1 >= text.length) throw new GrammarError('Unterminated quoted-literal escape.');
119
+ const escaped = text[index + 1];
120
+ if (escaped === '"') value += '"';
121
+ else if (escaped === '\\') value += '\\';
122
+ else if (escaped === 't') value += '\t';
123
+ else if (escaped === 'r') value += '\r';
124
+ else if (escaped === 'n') value += '\n';
125
+ else throw new GrammarError(`Invalid quoted-literal escape: \\${escaped}.`);
126
+ index += 2;
127
+ }
128
+ throw new GrammarError('Unterminated quoted literal.');
129
+ }
130
+
131
+ class Parser {
132
+ constructor(tokens) { this.tokens = tokens; this.index = 0; }
133
+ peek() { return this.tokens[this.index] || { type: 'eof', value: '' }; }
134
+ take() { const token = this.peek(); this.index += 1; return token; }
135
+ expect(type) {
136
+ const token = this.peek();
137
+ if (token.type !== type) throw new GrammarError(`Expected ${display(type)} but found ${display(token.type)}.`);
138
+ return this.take();
139
+ }
140
+ takeIdentifier(label = 'identifier') {
141
+ const token = this.peek();
142
+ if (token.type !== 'identifier') throw new GrammarError(`Expected ${label}.`);
143
+ return this.take().value;
144
+ }
145
+ parseExpression(stops = new Set(['eof'])) {
146
+ if (stops.has(this.peek().type) || this.peek().type === '|') throw new GrammarError('Expression must not be empty.');
147
+ const alternatives = [this.parseConcatenation(stops)];
148
+ while (this.peek().type === '|') {
149
+ this.take();
150
+ if (stops.has(this.peek().type) || this.peek().type === '|') throw new GrammarError('Alternation sides must not be empty.');
151
+ alternatives.push(this.parseConcatenation(stops));
152
+ }
153
+ return alternatives.length === 1 ? alternatives[0] : { type: 'alternation', alternatives };
154
+ }
155
+ parseConcatenation(stops) {
156
+ const parts = [];
157
+ while (!stops.has(this.peek().type) && this.peek().type !== '|') parts.push(this.parsePostfix());
158
+ if (!parts.length) throw new GrammarError('Concatenation must not be empty.');
159
+ return parts.length === 1 ? parts[0] : { type: 'concatenation', parts };
160
+ }
161
+ parsePostfix() {
162
+ const atom = this.parseAtom();
163
+ let quantifier = '';
164
+ if (['?', '*', '+'].includes(this.peek().type)) quantifier = this.take().type;
165
+ if (['?', '*', '+'].includes(this.peek().type)) throw new GrammarError('A postfix-expression permits at most one postfix quantifier.');
166
+ return quantifier ? { type: 'repeat', quantifier, expression: atom } : atom;
167
+ }
168
+ parseAtom() {
169
+ const token = this.peek();
170
+ if (token.type === 'literal') { this.take(); return { type: 'literal', value: token.value }; }
171
+ if (token.type === '(') {
172
+ this.take();
173
+ if (this.peek().type === ')') throw new GrammarError('Parenthesized expression must not be empty.');
174
+ const expression = this.parseExpression(new Set([')']));
175
+ this.expect(')');
176
+ return expression;
177
+ }
178
+ if (token.type !== 'identifier') throw new GrammarError(`Expected expression atom but found ${display(token.type)}.`);
179
+ const name = this.take().value;
180
+ if (name === 'ANY-EXCEPT') return this.parseAnyExcept();
181
+ if (SIMPLE_BUILTINS.has(name)) return { type: 'builtin', name };
182
+ return { type: 'reference', name };
183
+ }
184
+ parseAnyExcept() {
185
+ this.expect('(');
186
+ const exclusions = [];
187
+ if (this.peek().type === ')') throw new GrammarError('ANY-EXCEPT requires one or more exclusions.');
188
+ while (true) {
189
+ const token = this.peek();
190
+ if (token.type === 'literal') {
191
+ this.take();
192
+ if ([...token.value].length !== 1) throw new GrammarError('ANY-EXCEPT quoted exclusions must contain exactly one Unicode scalar.');
193
+ exclusions.push(token.value);
194
+ } else if (token.type === 'identifier' && ['SPACE', 'TAB', 'CR', 'LF'].includes(token.value)) {
195
+ this.take();
196
+ exclusions.push(builtinScalar(token.value));
197
+ } else {
198
+ throw new GrammarError('ANY-EXCEPT exclusion must be a one-scalar quoted literal or SPACE/TAB/CR/LF.');
199
+ }
200
+ if (this.peek().type === ',') { this.take(); continue; }
201
+ break;
202
+ }
203
+ this.expect(')');
204
+ return { type: 'any-except', exclusions };
205
+ }
206
+ }
207
+
208
+ function matchNode(node, pos, scalars, rules, memo) {
209
+ let perNode = memo.get(node);
210
+ if (!perNode) { perNode = new Map(); memo.set(node, perNode); }
211
+ if (perNode.has(pos)) return perNode.get(pos);
212
+ const out = new Set();
213
+ perNode.set(pos, out);
214
+
215
+ if (node.type === 'literal') {
216
+ const literal = [...node.value];
217
+ if (matchesAt(scalars, pos, literal)) out.add(pos + literal.length);
218
+ } else if (node.type === 'builtin') {
219
+ if (pos < scalars.length && builtinMatches(node.name, scalars[pos])) out.add(pos + 1);
220
+ } else if (node.type === 'any-except') {
221
+ if (pos < scalars.length && !node.exclusions.includes(scalars[pos])) out.add(pos + 1);
222
+ } else if (node.type === 'reference') {
223
+ const target = rules.get(node.name);
224
+ if (target) addAll(out, matchNode(target, pos, scalars, rules, memo));
225
+ } else if (node.type === 'alternation') {
226
+ for (const alternative of node.alternatives) addAll(out, matchNode(alternative, pos, scalars, rules, memo));
227
+ } else if (node.type === 'concatenation') {
228
+ let positions = new Set([pos]);
229
+ for (const part of node.parts) {
230
+ const next = new Set();
231
+ for (const current of positions) addAll(next, matchNode(part, current, scalars, rules, memo));
232
+ positions = next;
233
+ if (!positions.size) break;
234
+ }
235
+ addAll(out, positions);
236
+ } else if (node.type === 'repeat') {
237
+ if (node.quantifier === '?') {
238
+ out.add(pos);
239
+ addAll(out, matchNode(node.expression, pos, scalars, rules, memo));
240
+ } else if (node.quantifier === '*') {
241
+ addAll(out, repetitionClosure(node.expression, new Set([pos]), scalars, rules, memo));
242
+ } else if (node.quantifier === '+') {
243
+ const first = matchNode(node.expression, pos, scalars, rules, memo);
244
+ addAll(out, repetitionClosure(node.expression, first, scalars, rules, memo));
245
+ }
246
+ }
247
+ return out;
248
+ }
249
+
250
+ function repetitionClosure(expression, seeds, scalars, rules, memo) {
251
+ const seen = new Set(seeds);
252
+ const queue = [...seeds];
253
+ while (queue.length) {
254
+ const pos = queue.shift();
255
+ for (const next of matchNode(expression, pos, scalars, rules, memo)) {
256
+ if (seen.has(next)) continue;
257
+ seen.add(next);
258
+ queue.push(next);
259
+ }
260
+ }
261
+ return seen;
262
+ }
263
+
264
+ function builtinMatches(name, scalar) {
265
+ if (name === 'SPACE') return scalar === ' ';
266
+ if (name === 'TAB') return scalar === '\t';
267
+ if (name === 'CR') return scalar === '\r';
268
+ if (name === 'LF') return scalar === '\n';
269
+ if (name === 'DIGIT') return /^[0-9]$/.test(scalar);
270
+ if (name === 'ASCII-LETTER') return /^[A-Za-z]$/.test(scalar);
271
+ if (name === 'ANY') return true;
272
+ return false;
273
+ }
274
+
275
+ function builtinScalar(name) {
276
+ if (name === 'SPACE') return ' ';
277
+ if (name === 'TAB') return '\t';
278
+ if (name === 'CR') return '\r';
279
+ if (name === 'LF') return '\n';
280
+ return '';
281
+ }
282
+
283
+ function matchesAt(scalars, pos, literal) {
284
+ if (pos + literal.length > scalars.length) return false;
285
+ for (let index = 0; index < literal.length; index += 1) if (scalars[pos + index] !== literal[index]) return false;
286
+ return true;
287
+ }
288
+
289
+ function collectReferences(node, out = new Set()) {
290
+ if (!node) return out;
291
+ if (node.type === 'reference') out.add(node.name);
292
+ else if (node.type === 'alternation') for (const child of node.alternatives) collectReferences(child, out);
293
+ else if (node.type === 'concatenation') for (const child of node.parts) collectReferences(child, out);
294
+ else if (node.type === 'repeat') collectReferences(node.expression, out);
295
+ return out;
296
+ }
297
+
298
+ function detectCycles(rules = []) {
299
+ const graph = new Map(rules.map((rule) => [rule.name, [...collectReferences(rule.expression)]]));
300
+ const visiting = new Set();
301
+ const visited = new Set();
302
+ const findings = [];
303
+ function visit(name, stack = []) {
304
+ if (visiting.has(name)) {
305
+ findings.push(`Cyclic Grammar Rule reference: ${[...stack, name].join(' -> ')}.`);
306
+ return;
307
+ }
308
+ if (visited.has(name)) return;
309
+ visiting.add(name);
310
+ for (const next of graph.get(name) || []) if (graph.has(next)) visit(next, [...stack, name]);
311
+ visiting.delete(name);
312
+ visited.add(name);
313
+ }
314
+ for (const name of graph.keys()) visit(name, []);
315
+ return unique(findings);
316
+ }
317
+
318
+ function freezeNode(node = {}) {
319
+ if (!node || typeof node !== 'object') return node;
320
+ if (node.type === 'alternation') return Object.freeze({ type: node.type, alternatives: Object.freeze(node.alternatives.map(freezeNode)) });
321
+ if (node.type === 'concatenation') return Object.freeze({ type: node.type, parts: Object.freeze(node.parts.map(freezeNode)) });
322
+ if (node.type === 'repeat') return Object.freeze({ type: node.type, quantifier: node.quantifier, expression: freezeNode(node.expression) });
323
+ if (node.type === 'any-except') return Object.freeze({ type: node.type, exclusions: Object.freeze([...node.exclusions]) });
324
+ return Object.freeze({ ...node });
325
+ }
326
+
327
+ function isForbiddenMetaWhitespace(ch) {
328
+ if (ch === '\r' || ch === '\n') return true;
329
+ if (ch === ' ' || ch === '\t') return false;
330
+ return /^\s$/u.test(ch);
331
+ }
332
+
333
+ function addAll(target, source) { for (const item of source || []) target.add(item); }
334
+ function exact(value = '') { return String(value || '').trim(); }
335
+ function display(type = '') { return type === 'eof' ? 'end of grammar rule' : `token ${type}`; }
336
+ function messageOf(error) { return error instanceof Error ? error.message : String(error); }
337
+ function unique(values = []) { return [...new Set(values)]; }
338
+ class GrammarError extends Error {}
@@ -0,0 +1,108 @@
1
+ import { portableFinding } from '../findings.js';
2
+
3
+ export const PORTABLE_LLM_SCHEMA_COMPANION_SCHEMA_ID = 'tiinex.llm.schema-companion.v1';
4
+
5
+ export function resolvePortableLlmCompanion({ schemaId = '', task = 'read', module = null, input = {}, options = {} } = {}) {
6
+ const findings = [];
7
+ const direct = input.llmCompanion || options.llmCompanion || null;
8
+ const collection = input.llmCompanions || options.llmCompanions || null;
9
+ const fromCollection = companionFromCollection(collection, schemaId);
10
+ const materialResult = companionFromMaterial(input.materials || input, schemaId);
11
+ findings.push(...materialResult.findings);
12
+ const raw = direct || fromCollection || materialResult.companion || module?.llmCompanion || module?.llm || null;
13
+ if (!raw) return Object.freeze({ companion: emptyCompanion(task), findings: Object.freeze(findings) });
14
+
15
+ const declaredSchemaId = String(raw.schemaId || '').trim();
16
+ if (declaredSchemaId && declaredSchemaId !== schemaId) {
17
+ findings.push(portableFinding('error', 'portable.schema-guide.llm-companion.schema-mismatch', 'Schema-specific LLM companion does not match the requested schema.', {
18
+ requestedSchemaId: schemaId,
19
+ companionSchemaId: declaredSchemaId
20
+ }));
21
+ }
22
+
23
+ const taskHints = raw.tasks?.[task] || raw[task] || {};
24
+ const companion = Object.freeze({
25
+ schema: String(raw.schema || PORTABLE_LLM_SCHEMA_COMPANION_SCHEMA_ID),
26
+ schemaId: declaredSchemaId || schemaId,
27
+ task,
28
+ available: true,
29
+ source: direct ? 'direct-request' : fromCollection ? 'supplied-collection' : materialResult.companion ? 'supplied-companion-data' : 'registered-schema-module',
30
+ version: String(raw.version || taskHints.version || '1'),
31
+ purpose: String(taskHints.purpose || raw.purpose || ''),
32
+ authoringSteps: normalizeList(taskHints.authoringSteps || taskHints.steps || []),
33
+ hardRules: normalizeList(taskHints.hardRules || taskHints.emphasis || raw.hardRules || []),
34
+ questions: normalizeList(taskHints.questions || []),
35
+ commonFailures: normalizeList(taskHints.commonFailures || []),
36
+ prioritySections: normalizeList(taskHints.prioritySections || taskHints.readFirst || []),
37
+ retrievalHints: normalizeList(taskHints.retrievalHints || taskHints.retrieve || [])
38
+ });
39
+
40
+ if (companion.schema !== PORTABLE_LLM_SCHEMA_COMPANION_SCHEMA_ID) {
41
+ findings.push(portableFinding('warning', 'portable.schema-guide.llm-companion.schema-unknown', 'LLM companion uses an unrecognized companion schema id; hints were preserved but not treated as canonical rules.', {
42
+ schemaId,
43
+ companionSchema: companion.schema
44
+ }));
45
+ }
46
+
47
+ return Object.freeze({ companion, findings: Object.freeze(findings) });
48
+ }
49
+
50
+ function companionFromMaterial(input = {}, schemaId = '') {
51
+ const findings = [];
52
+ const files = [
53
+ ...(Array.isArray(input.files) ? input.files : []),
54
+ ...(Array.isArray(input.records) ? input.records.map((record) => ({ path: record.path, content: record.markdown })) : [])
55
+ ];
56
+ const exactName = `${schemaId}.llm.json`.toLowerCase();
57
+ const candidates = files.filter((file) => {
58
+ const path = String(file?.path || file?.name || '').replace(/\\/g, '/').toLowerCase();
59
+ return path.endsWith(exactName) || path.endsWith('.llm.json') || path.endsWith('.llm-companion.json');
60
+ });
61
+ for (const file of candidates) {
62
+ const content = typeof file?.content === 'string' ? file.content : typeof file?.markdown === 'string' ? file.markdown : '';
63
+ if (!content) continue;
64
+ let parsed;
65
+ try { parsed = JSON.parse(content); }
66
+ catch (error) {
67
+ findings.push(portableFinding('warning', 'portable.schema-guide.llm-companion.invalid-json', 'Supplied LLM companion data could not be parsed as JSON and was ignored.', {
68
+ ref: file.path || file.name || '',
69
+ detail: String(error?.message || error)
70
+ }));
71
+ continue;
72
+ }
73
+ if (String(parsed?.schemaId || '').trim() !== schemaId) continue;
74
+ return Object.freeze({ companion: parsed, findings: Object.freeze(findings) });
75
+ }
76
+ return Object.freeze({ companion: null, findings: Object.freeze(findings) });
77
+ }
78
+
79
+ function companionFromCollection(collection, schemaId) {
80
+ if (!collection) return null;
81
+ if (Array.isArray(collection)) return collection.find((entry) => String(entry?.schemaId || '').trim() === schemaId) || null;
82
+ if (collection instanceof Map) return collection.get(schemaId) || null;
83
+ if (typeof collection === 'object') return collection[schemaId] || null;
84
+ return null;
85
+ }
86
+
87
+ function emptyCompanion(task) {
88
+ return Object.freeze({
89
+ schema: PORTABLE_LLM_SCHEMA_COMPANION_SCHEMA_ID,
90
+ schemaId: '',
91
+ task,
92
+ available: false,
93
+ source: 'generic-compiler',
94
+ version: 'generic',
95
+ purpose: '',
96
+ authoringSteps: Object.freeze([]),
97
+ hardRules: Object.freeze([]),
98
+ questions: Object.freeze([]),
99
+ commonFailures: Object.freeze([]),
100
+ prioritySections: Object.freeze([]),
101
+ retrievalHints: Object.freeze([])
102
+ });
103
+ }
104
+
105
+ function normalizeList(value) {
106
+ const list = Array.isArray(value) ? value : value ? [value] : [];
107
+ return Object.freeze([...new Set(list.map((item) => String(item || '').trim()).filter(Boolean))]);
108
+ }
@@ -0,0 +1,162 @@
1
+ function normalizeKey(value = '') {
2
+ return String(value || '').toLowerCase().replace(/[`*_#]/g, '').replace(/[^a-z0-9]+/g, ' ').trim();
3
+ }
4
+
5
+ function cleanToken(value = '') {
6
+ return String(value || '').trim().replace(/^`|`$/g, '').trim();
7
+ }
8
+
9
+ function categoryItems(group = {}, names = []) {
10
+ const wanted = new Set(names.map((name) => String(name || '').trim()));
11
+ return (group.categories || []).flatMap((category) => wanted.has(String(category.name || '').trim()) ? category.items : []);
12
+ }
13
+
14
+ function unique(values = []) {
15
+ return [...new Set(values.map((value) => String(value || '').trim()).filter(Boolean))];
16
+ }
17
+
18
+ function headingTargetsFromRules(rules = []) {
19
+ const targets = [];
20
+ for (const rule of rules) {
21
+ const text = String(rule || '');
22
+ for (const match of text.matchAll(/(?:Entries|entry|declarations?|names)\s+under\s+`(#{2,6}\s+[^`]+)`/gi)) targets.push(match[1].trim());
23
+ for (const match of text.matchAll(/unique\s+within\s+`(#{2,6}\s+[^`]+)`/gi)) targets.push(match[1].trim());
24
+ }
25
+ return unique(targets);
26
+ }
27
+
28
+ export function compileNamedDeclarationContracts(contract = {}) {
29
+ const out = [];
30
+ for (const group of contract.groups || []) {
31
+ const entryShape = categoryItems(group, ['Entry Shape']).map(cleanToken);
32
+ const requiredFields = categoryItems(group, ['Required Fields']).map(cleanToken);
33
+ const optionalFields = categoryItems(group, ['Optional Fields']).map(cleanToken);
34
+ const declarationFields = categoryItems(group, ['Declaration Fields', 'Fields']).map(cleanToken);
35
+ const rules = categoryItems(group, ['Rules']);
36
+ const namedEntry = entryShape.some((item) => normalizeKey(item) === 'first level hyphen list item' || normalizeKey(item) === 'named declaration');
37
+ if (!namedEntry || !(requiredFields.length || optionalFields.length || declarationFields.length)) continue;
38
+ const targetHeadings = headingTargetsFromRules(rules);
39
+ out.push(Object.freeze({
40
+ group: group.name,
41
+ entryShape: Object.freeze(entryShape),
42
+ requiredFields: Object.freeze(unique(requiredFields.length ? requiredFields : declarationFields)),
43
+ optionalFields: Object.freeze(unique(optionalFields)),
44
+ declarationFields: Object.freeze(unique(declarationFields)),
45
+ allowedLabels: Object.freeze(unique(categoryItems(group, ['Allowed Labels']).map(cleanToken))),
46
+ allowedShapes: Object.freeze(unique(categoryItems(group, ['Allowed Shapes']).map(cleanToken))),
47
+ targetHeadings: Object.freeze(targetHeadings),
48
+ allowLiteralNone: rules.some((rule) => /literal(?:\s+first-level)?\s+entry\s+`none`|literal\s+`none`/i.test(rule)),
49
+ rules: Object.freeze(rules)
50
+ }));
51
+ }
52
+ return Object.freeze(out);
53
+ }
54
+
55
+ export function parseNamedDeclarationSection(markdown = '', heading = '', declarationContract = {}) {
56
+ const section = findExactSection(markdown, heading);
57
+ if (!section) return Object.freeze({ heading, present: false, entries: Object.freeze([]), findings: Object.freeze([]) });
58
+ const entries = [];
59
+ const findings = [];
60
+ let current = null;
61
+ let fenced = false;
62
+ for (let offset = 0; offset < section.lines.length; offset += 1) {
63
+ const rawLine = section.lines[offset];
64
+ const line = section.startIndex + offset + 1;
65
+ if (/^\s*```/.test(rawLine)) { fenced = !fenced; continue; }
66
+ if (fenced || !rawLine.trim()) continue;
67
+ const first = rawLine.match(/^-\s+(.+?)\s*$/);
68
+ if (first) {
69
+ current = { name: first[1].trim(), fields: {}, fieldOrder: [], raw: [rawLine], startLine: line, endLine: line };
70
+ entries.push(current);
71
+ continue;
72
+ }
73
+ const nested = rawLine.match(/^\s+-\s+([^:]+):\s*(.*?)\s*$/);
74
+ if (nested && current) {
75
+ const field = nested[1].trim();
76
+ const value = nested[2];
77
+ current.raw.push(rawLine);
78
+ current.endLine = line;
79
+ if (Object.prototype.hasOwnProperty.call(current.fields, field)) {
80
+ findings.push(Object.freeze({ code: 'portable.contract.declaration.field.duplicate', entry: current.name, field }));
81
+ } else {
82
+ current.fields[field] = value;
83
+ current.fieldOrder.push(field);
84
+ }
85
+ continue;
86
+ }
87
+ if (current && /^\s+\S/.test(rawLine)) {
88
+ current.raw.push(rawLine);
89
+ current.endLine = line;
90
+ }
91
+ }
92
+ const frozen = entries.map((entry) => Object.freeze({
93
+ name: entry.name,
94
+ fields: Object.freeze({ ...entry.fields }),
95
+ fieldOrder: Object.freeze([...entry.fieldOrder]),
96
+ raw: Object.freeze([...entry.raw]),
97
+ source: Object.freeze({ line: entry.startLine, endLine: entry.endLine })
98
+ }));
99
+ return Object.freeze({ heading, present: true, entries: Object.freeze(frozen), findings: Object.freeze(findings) });
100
+ }
101
+
102
+ export function parseDeclarationsAgainstContract(markdown = '', declarationContracts = []) {
103
+ const groups = [];
104
+ for (const contract of declarationContracts || []) {
105
+ const sections = contract.targetHeadings.map((heading) => parseNamedDeclarationSection(markdown, heading, contract));
106
+ groups.push(Object.freeze({ contract, sections: Object.freeze(sections) }));
107
+ }
108
+ return Object.freeze(groups);
109
+ }
110
+
111
+ export function declarationOwnershipRanges(parsedDeclarations = []) {
112
+ const ranges = [];
113
+ for (const parsedGroup of parsedDeclarations || []) {
114
+ for (const section of parsedGroup.sections || []) {
115
+ for (const entry of section.entries || []) {
116
+ const line = Number(entry.source?.line || 0);
117
+ const endLine = Number(entry.source?.endLine || line);
118
+ if (!line || endLine < line) continue;
119
+ ranges.push(Object.freeze({
120
+ line,
121
+ endLine,
122
+ group: String(parsedGroup.contract?.group || ''),
123
+ heading: String(section.heading || ''),
124
+ entry: String(entry.name || '')
125
+ }));
126
+ }
127
+ }
128
+ }
129
+ return Object.freeze(ranges);
130
+ }
131
+
132
+ function findExactSection(markdown = '', heading = '') {
133
+ const target = String(heading || '').trim();
134
+ const explicit = target.match(/^(#{1,6})\s+(.+)$/);
135
+ const wantedLevel = explicit ? explicit[1].length : null;
136
+ const wantedTitle = explicit ? explicit[2].trim() : target;
137
+ if (!wantedTitle) return null;
138
+ const lines = String(markdown || '').replace(/\r\n?/g, '\n').split('\n');
139
+ let fenced = false;
140
+ let start = -1;
141
+ let matchedLevel = wantedLevel;
142
+ for (let index = 0; index < lines.length; index += 1) {
143
+ const line = lines[index];
144
+ if (/^\s*```/.test(line)) { fenced = !fenced; continue; }
145
+ if (fenced) continue;
146
+ const match = line.match(/^(#{1,6})\s+(.+?)\s*$/);
147
+ if (!match) continue;
148
+ const level = match[1].length;
149
+ const title = match[2].trim();
150
+ if (start < 0 && (wantedLevel === null || level === wantedLevel) && title === wantedTitle) { start = index + 1; matchedLevel = level; continue; }
151
+ if (start >= 0 && level <= matchedLevel) return { lines: lines.slice(start, index), line: start + 1, endLine: index, startIndex: start, endIndex: index };
152
+ }
153
+ return start >= 0 ? { lines: lines.slice(start), line: start + 1, endLine: lines.length, startIndex: start, endIndex: lines.length } : null;
154
+ }
155
+
156
+ export function declarationTargetKey(value = '') {
157
+ return normalizeKey(String(value || '').replace(/^#{1,6}\s+/, ''))
158
+ .replace(/\broles\b/g, 'role')
159
+ .replace(/\bbindings\b/g, 'binding')
160
+ .replace(/\beffects\b/g, 'effect')
161
+ .replace(/\bplacements\b/g, 'placement');
162
+ }