agentlock-harness 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (279) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +211 -2
  3. package/README.zh-CN.md +211 -0
  4. package/RELEASE_NOTES.md +35 -0
  5. package/bin/agentlock-harness.mjs +249 -0
  6. package/harness-templates/en-US/common/CLAUDE.md.tmpl +7 -0
  7. package/harness-templates/en-US/common/GEMINI.md.tmpl +7 -0
  8. package/harness-templates/en-US/common/agentlock-harness.json.tmpl +45 -0
  9. package/harness-templates/en-US/common/claude-settings.json +36 -0
  10. package/harness-templates/en-US/common/codex-config.toml.tmpl +11 -0
  11. package/harness-templates/en-US/common/copilot-instructions.md.tmpl +3 -0
  12. package/harness-templates/en-US/common/gemini-settings.json +42 -0
  13. package/harness-templates/en-US/common/git-hooks/pre-commit +24 -0
  14. package/harness-templates/en-US/common/git-hooks/pre-push +11 -0
  15. package/harness-templates/en-US/common/harness-gitignore +3 -0
  16. package/harness-templates/en-US/common/hooks/post-edit-check.mjs +57 -0
  17. package/harness-templates/en-US/common/hooks/pre-tool-guard.mjs +122 -0
  18. package/harness-templates/en-US/common/hooks/rules-drift-check.mjs +69 -0
  19. package/harness-templates/en-US/common/hooks/staged-guard.mjs +197 -0
  20. package/harness-templates/en-US/common/hooks/stop-gate.mjs +164 -0
  21. package/harness-templates/en-US/common/rules/00-testing-integrity.md +11 -0
  22. package/harness-templates/en-US/common/rules/01-security-boundaries.md +11 -0
  23. package/harness-templates/en-US/common/skills/atomic-tdd/SKILL.md +21 -0
  24. package/harness-templates/en-US/common/skills/brainstorming/SKILL.md +24 -0
  25. package/harness-templates/en-US/common/skills/code-grounding/SKILL.md +20 -0
  26. package/harness-templates/en-US/common/skills/cross-model-review/SKILL.md +22 -0
  27. package/harness-templates/en-US/common/skills/worktree-isolation/SKILL.md +19 -0
  28. package/harness-templates/en-US/dual-core/HARNESS_GUIDE.md +19 -0
  29. package/harness-templates/en-US/dual-core/scripts/cross-review.mjs +141 -0
  30. package/harness-templates/en-US/enterprise-platform/ci/agentlock-harness-gate.yml +32 -0
  31. package/harness-templates/en-US/enterprise-platform/governance/mcp-gateway.template.json +18 -0
  32. package/harness-templates/en-US/enterprise-platform/governance/policy.json +26 -0
  33. package/harness-templates/en-US/ralph-factory/PROMPT.loop.md.tmpl +12 -0
  34. package/harness-templates/en-US/ralph-factory/SPRINT_CONTRACT.md.tmpl +25 -0
  35. package/harness-templates/en-US/ralph-factory/sandbox/Dockerfile.sandbox +13 -0
  36. package/harness-templates/en-US/ralph-factory/sandbox/docker-compose.sandbox.yml +22 -0
  37. package/harness-templates/en-US/ralph-factory/sandbox/run-sandbox-loop.sh +8 -0
  38. package/harness-templates/zh-CN/common/CLAUDE.md.tmpl +7 -0
  39. package/harness-templates/zh-CN/common/GEMINI.md.tmpl +7 -0
  40. package/harness-templates/zh-CN/common/agentlock-harness.json.tmpl +45 -0
  41. package/harness-templates/zh-CN/common/claude-settings.json +36 -0
  42. package/harness-templates/zh-CN/common/codex-config.toml.tmpl +11 -0
  43. package/harness-templates/zh-CN/common/copilot-instructions.md.tmpl +3 -0
  44. package/harness-templates/zh-CN/common/gemini-settings.json +42 -0
  45. package/harness-templates/zh-CN/common/git-hooks/pre-commit +24 -0
  46. package/harness-templates/zh-CN/common/git-hooks/pre-push +11 -0
  47. package/harness-templates/zh-CN/common/harness-gitignore +3 -0
  48. package/harness-templates/zh-CN/common/hooks/post-edit-check.mjs +57 -0
  49. package/harness-templates/zh-CN/common/hooks/pre-tool-guard.mjs +122 -0
  50. package/harness-templates/zh-CN/common/hooks/rules-drift-check.mjs +69 -0
  51. package/harness-templates/zh-CN/common/hooks/staged-guard.mjs +197 -0
  52. package/harness-templates/zh-CN/common/hooks/stop-gate.mjs +164 -0
  53. package/harness-templates/zh-CN/common/rules/00-testing-integrity.md +11 -0
  54. package/harness-templates/zh-CN/common/rules/01-security-boundaries.md +11 -0
  55. package/harness-templates/zh-CN/common/skills/atomic-tdd/SKILL.md +21 -0
  56. package/harness-templates/zh-CN/common/skills/brainstorming/SKILL.md +24 -0
  57. package/harness-templates/zh-CN/common/skills/code-grounding/SKILL.md +20 -0
  58. package/harness-templates/zh-CN/common/skills/cross-model-review/SKILL.md +22 -0
  59. package/harness-templates/zh-CN/common/skills/worktree-isolation/SKILL.md +19 -0
  60. package/harness-templates/zh-CN/dual-core/HARNESS_GUIDE.md +19 -0
  61. package/harness-templates/zh-CN/dual-core/scripts/cross-review.mjs +141 -0
  62. package/harness-templates/zh-CN/enterprise-platform/ci/agentlock-harness-gate.yml +32 -0
  63. package/harness-templates/zh-CN/enterprise-platform/governance/mcp-gateway.template.json +18 -0
  64. package/harness-templates/zh-CN/enterprise-platform/governance/policy.json +26 -0
  65. package/harness-templates/zh-CN/ralph-factory/PROMPT.loop.md.tmpl +12 -0
  66. package/harness-templates/zh-CN/ralph-factory/SPRINT_CONTRACT.md.tmpl +25 -0
  67. package/harness-templates/zh-CN/ralph-factory/sandbox/Dockerfile.sandbox +13 -0
  68. package/harness-templates/zh-CN/ralph-factory/sandbox/docker-compose.sandbox.yml +22 -0
  69. package/harness-templates/zh-CN/ralph-factory/sandbox/run-sandbox-loop.sh +8 -0
  70. package/package.json +64 -4
  71. package/scripts/bootstrap.ps1 +13 -0
  72. package/scripts/bootstrap.sh +23 -0
  73. package/src/cli/colors.mjs +42 -0
  74. package/src/cli/commands/adopt.mjs +378 -0
  75. package/src/cli/commands/change.mjs +92 -0
  76. package/src/cli/commands/doctor.mjs +56 -0
  77. package/src/cli/commands/eval.mjs +193 -0
  78. package/src/cli/commands/hooks.mjs +97 -0
  79. package/src/cli/commands/init.mjs +231 -0
  80. package/src/cli/commands/passthrough.mjs +27 -0
  81. package/src/cli/commands/ralph.mjs +208 -0
  82. package/src/cli/commands/rules.mjs +73 -0
  83. package/src/cli/commands/stats.mjs +71 -0
  84. package/src/cli/commands/task.mjs +123 -0
  85. package/src/cli/commands/ui.mjs +84 -0
  86. package/src/cli/commands/verify.mjs +267 -0
  87. package/src/cli/prompt.mjs +55 -0
  88. package/src/core/adopt.mjs +807 -0
  89. package/src/core/agent-runner.mjs +118 -0
  90. package/src/core/audit.mjs +181 -0
  91. package/src/core/catalog.mjs +160 -0
  92. package/src/core/change-flow.mjs +344 -0
  93. package/src/core/detector.mjs +141 -0
  94. package/src/core/doc-drift.mjs +94 -0
  95. package/src/core/eval-fixtures.mjs +676 -0
  96. package/src/core/eval-frontier-fixtures.mjs +657 -0
  97. package/src/core/eval-hard-fixtures.mjs +923 -0
  98. package/src/core/eval-runner.mjs +754 -0
  99. package/src/core/eval-telemetry.mjs +338 -0
  100. package/src/core/harness-writer.mjs +286 -0
  101. package/src/core/installer.mjs +42 -0
  102. package/src/core/rules-compiler.mjs +356 -0
  103. package/src/core/task-ledger.mjs +327 -0
  104. package/src/core/version.mjs +10 -0
  105. package/src/ui/public/app.mjs +2199 -0
  106. package/src/ui/public/index.html +203 -0
  107. package/src/ui/public/styles.css +1200 -0
  108. package/src/ui/server.mjs +457 -0
  109. package/src/ui/service.mjs +860 -0
  110. package/templates/en-US/AGENTS.md +38 -0
  111. package/templates/en-US/DOCS_MAINTENANCE.md +65 -0
  112. package/templates/en-US/MIGRATION.md +46 -0
  113. package/templates/en-US/NEW_PROJECT_CHECKLIST.md +46 -0
  114. package/templates/en-US/README.md +41 -0
  115. package/templates/en-US/SESSION.md +29 -0
  116. package/templates/en-US/docs/00-context.md +38 -0
  117. package/templates/en-US/docs/01-vision/README.md +36 -0
  118. package/templates/en-US/docs/02-requirements/PRD.md +24 -0
  119. package/templates/en-US/docs/02-requirements/glossary.md +20 -0
  120. package/templates/en-US/docs/02-requirements/use-cases.md +36 -0
  121. package/templates/en-US/docs/03-architecture/composite-ai-framework.md +36 -0
  122. package/templates/en-US/docs/03-architecture/integration-architecture.md +36 -0
  123. package/templates/en-US/docs/03-architecture/system-architecture.md +16 -0
  124. package/templates/en-US/docs/04-design/README.md +21 -0
  125. package/templates/en-US/docs/04-design/a2a-integration-spec.md +36 -0
  126. package/templates/en-US/docs/04-design/agent-specs.md +36 -0
  127. package/templates/en-US/docs/04-design/data-model.md +18 -0
  128. package/templates/en-US/docs/04-design/external-api-spec.md +26 -0
  129. package/templates/en-US/docs/04-design/mcp-interface-spec.md +36 -0
  130. package/templates/en-US/docs/04-design/phase1-minimal-implementation-interfaces.md +36 -0
  131. package/templates/en-US/docs/04-design/responsibility-model.md +36 -0
  132. package/templates/en-US/docs/04-design/runtime-control-plane-spec.md +36 -0
  133. package/templates/en-US/docs/04-design/safety-governance.md +18 -0
  134. package/templates/en-US/docs/04-design/sample-scenarios-architecture-refinement.md +20 -0
  135. package/templates/en-US/docs/04-design/skill-syntax-spec.md +36 -0
  136. package/templates/en-US/docs/04-design/storage-schema.md +18 -0
  137. package/templates/en-US/docs/04-design/task-capability-architecture-and-evolution.md +36 -0
  138. package/templates/en-US/docs/05-project/adr/ADR-000-template.md +32 -0
  139. package/templates/en-US/docs/05-project/adr/README.md +15 -0
  140. package/templates/en-US/docs/05-project/doc-code-map.md +17 -0
  141. package/templates/en-US/docs/05-project/evolution-backlog.md +14 -0
  142. package/templates/en-US/docs/05-project/feature-registry.md +16 -0
  143. package/templates/en-US/docs/05-project/master-delivery-tracker.md +14 -0
  144. package/templates/en-US/docs/05-project/risk-register.md +36 -0
  145. package/templates/en-US/docs/05-project/roadmap.md +36 -0
  146. package/templates/en-US/docs/05-project/stage-view.md +14 -0
  147. package/templates/en-US/docs/05-project/tech-stack.md +36 -0
  148. package/templates/en-US/docs/06-dev-guide/SPEC.md +18 -0
  149. package/templates/en-US/docs/06-dev-guide/coding-standards.md +36 -0
  150. package/templates/en-US/docs/06-dev-guide/deployment-architecture.md +20 -0
  151. package/templates/en-US/docs/06-dev-guide/project-scaffold.md +16 -0
  152. package/templates/en-US/docs/06-dev-guide/testing-strategy.md +42 -0
  153. package/templates/en-US/docs/07-frontend/README.md +36 -0
  154. package/templates/en-US/docs/07-frontend/user-personas.md +36 -0
  155. package/templates/en-US/docs/08-process/README.md +27 -0
  156. package/templates/en-US/docs/08-process/ai-collaboration-protocol.md +28 -0
  157. package/templates/en-US/docs/08-process/autopilot.md +18 -0
  158. package/templates/en-US/docs/08-process/code-grounding.md +32 -0
  159. package/templates/en-US/docs/08-process/context-loading-strategy.md +35 -0
  160. package/templates/en-US/docs/08-process/conventions.md +75 -0
  161. package/templates/en-US/docs/08-process/debugging.md +25 -0
  162. package/templates/en-US/docs/08-process/design-gate.md +22 -0
  163. package/templates/en-US/docs/08-process/git-protocol.md +20 -0
  164. package/templates/en-US/docs/08-process/multi-agent-orchestration.md +27 -0
  165. package/templates/en-US/docs/08-process/planning.md +18 -0
  166. package/templates/en-US/docs/08-process/project-intake.md +47 -0
  167. package/templates/en-US/docs/08-process/reflection.md +18 -0
  168. package/templates/en-US/docs/08-process/review.md +30 -0
  169. package/templates/en-US/docs/08-process/session-handoff.md +27 -0
  170. package/templates/en-US/docs/08-process/tdd.md +24 -0
  171. package/templates/en-US/docs/08-process/tool-execution.md +32 -0
  172. package/templates/en-US/docs/08-process/workflow-contract.md +46 -0
  173. package/templates/en-US/docs/08-process/workflow.md +23 -0
  174. package/templates/en-US/docs/README.md +58 -0
  175. package/templates/en-US/docs/design-checklist.md +36 -0
  176. package/templates/en-US/docs/discussions/README.md +13 -0
  177. package/templates/en-US/docs/plans/README.md +13 -0
  178. package/templates/en-US/docs/proposed-design/README.md +13 -0
  179. package/templates/en-US/docs/temp-reference/README.md +11 -0
  180. package/templates/en-US/docs.config.json +46 -0
  181. package/templates/en-US/profiles/README.md +23 -0
  182. package/templates/en-US/profiles/agent-platform/README.md +23 -0
  183. package/templates/en-US/profiles/cli-tool/README.md +23 -0
  184. package/templates/en-US/profiles/library-sdk/README.md +23 -0
  185. package/templates/en-US/profiles/multi-agent/README.md +23 -0
  186. package/templates/en-US/profiles/profiles.json +31 -0
  187. package/templates/en-US/profiles/software-automation/README.md +23 -0
  188. package/templates/en-US/profiles/web-saas/README.md +23 -0
  189. package/templates/en-US/scripts/README.md +89 -0
  190. package/templates/en-US/scripts/doc-find.mjs +156 -0
  191. package/templates/en-US/scripts/doc-map.mjs +50 -0
  192. package/templates/en-US/scripts/doc-tools.mjs +311 -0
  193. package/templates/en-US/scripts/init-docs.mjs +214 -0
  194. package/templates/en-US/scripts/validate-docs.mjs +141 -0
  195. package/templates/zh-CN/AGENTS.md +38 -0
  196. package/templates/zh-CN/DOCS_MAINTENANCE.md +77 -0
  197. package/templates/zh-CN/MIGRATION.md +45 -0
  198. package/templates/zh-CN/NEW_PROJECT_CHECKLIST.md +54 -0
  199. package/templates/zh-CN/README.md +55 -0
  200. package/templates/zh-CN/SESSION.md +29 -0
  201. package/templates/zh-CN/docs/00-context.md +42 -0
  202. package/templates/zh-CN/docs/01-vision/README.md +33 -0
  203. package/templates/zh-CN/docs/02-requirements/PRD.md +26 -0
  204. package/templates/zh-CN/docs/02-requirements/glossary.md +35 -0
  205. package/templates/zh-CN/docs/02-requirements/use-cases.md +31 -0
  206. package/templates/zh-CN/docs/03-architecture/composite-ai-framework.md +27 -0
  207. package/templates/zh-CN/docs/03-architecture/integration-architecture.md +30 -0
  208. package/templates/zh-CN/docs/03-architecture/system-architecture.md +26 -0
  209. package/templates/zh-CN/docs/04-design/README.md +21 -0
  210. package/templates/zh-CN/docs/04-design/a2a-integration-spec.md +45 -0
  211. package/templates/zh-CN/docs/04-design/agent-specs.md +46 -0
  212. package/templates/zh-CN/docs/04-design/data-model.md +18 -0
  213. package/templates/zh-CN/docs/04-design/external-api-spec.md +34 -0
  214. package/templates/zh-CN/docs/04-design/mcp-interface-spec.md +44 -0
  215. package/templates/zh-CN/docs/04-design/phase1-minimal-implementation-interfaces.md +38 -0
  216. package/templates/zh-CN/docs/04-design/responsibility-model.md +37 -0
  217. package/templates/zh-CN/docs/04-design/runtime-control-plane-spec.md +47 -0
  218. package/templates/zh-CN/docs/04-design/safety-governance.md +18 -0
  219. package/templates/zh-CN/docs/04-design/sample-scenarios-architecture-refinement.md +38 -0
  220. package/templates/zh-CN/docs/04-design/skill-syntax-spec.md +43 -0
  221. package/templates/zh-CN/docs/04-design/storage-schema.md +18 -0
  222. package/templates/zh-CN/docs/04-design/task-capability-architecture-and-evolution.md +46 -0
  223. package/templates/zh-CN/docs/05-project/adr/ADR-000-template.md +34 -0
  224. package/templates/zh-CN/docs/05-project/adr/README.md +35 -0
  225. package/templates/zh-CN/docs/05-project/doc-code-map.md +19 -0
  226. package/templates/zh-CN/docs/05-project/evolution-backlog.md +14 -0
  227. package/templates/zh-CN/docs/05-project/feature-registry.md +16 -0
  228. package/templates/zh-CN/docs/05-project/master-delivery-tracker.md +14 -0
  229. package/templates/zh-CN/docs/05-project/risk-register.md +21 -0
  230. package/templates/zh-CN/docs/05-project/roadmap.md +31 -0
  231. package/templates/zh-CN/docs/05-project/stage-view.md +14 -0
  232. package/templates/zh-CN/docs/05-project/tech-stack.md +36 -0
  233. package/templates/zh-CN/docs/06-dev-guide/SPEC.md +24 -0
  234. package/templates/zh-CN/docs/06-dev-guide/coding-standards.md +29 -0
  235. package/templates/zh-CN/docs/06-dev-guide/deployment-architecture.md +22 -0
  236. package/templates/zh-CN/docs/06-dev-guide/project-scaffold.md +16 -0
  237. package/templates/zh-CN/docs/06-dev-guide/testing-strategy.md +46 -0
  238. package/templates/zh-CN/docs/07-frontend/README.md +29 -0
  239. package/templates/zh-CN/docs/07-frontend/user-personas.md +27 -0
  240. package/templates/zh-CN/docs/08-process/README.md +29 -0
  241. package/templates/zh-CN/docs/08-process/ai-collaboration-protocol.md +30 -0
  242. package/templates/zh-CN/docs/08-process/autopilot.md +18 -0
  243. package/templates/zh-CN/docs/08-process/code-grounding.md +40 -0
  244. package/templates/zh-CN/docs/08-process/context-loading-strategy.md +35 -0
  245. package/templates/zh-CN/docs/08-process/conventions.md +77 -0
  246. package/templates/zh-CN/docs/08-process/debugging.md +27 -0
  247. package/templates/zh-CN/docs/08-process/design-gate.md +22 -0
  248. package/templates/zh-CN/docs/08-process/git-protocol.md +20 -0
  249. package/templates/zh-CN/docs/08-process/multi-agent-orchestration.md +27 -0
  250. package/templates/zh-CN/docs/08-process/planning.md +18 -0
  251. package/templates/zh-CN/docs/08-process/project-intake.md +53 -0
  252. package/templates/zh-CN/docs/08-process/reflection.md +18 -0
  253. package/templates/zh-CN/docs/08-process/review.md +30 -0
  254. package/templates/zh-CN/docs/08-process/session-handoff.md +29 -0
  255. package/templates/zh-CN/docs/08-process/tdd.md +24 -0
  256. package/templates/zh-CN/docs/08-process/tool-execution.md +34 -0
  257. package/templates/zh-CN/docs/08-process/workflow-contract.md +48 -0
  258. package/templates/zh-CN/docs/08-process/workflow.md +23 -0
  259. package/templates/zh-CN/docs/README.md +62 -0
  260. package/templates/zh-CN/docs/design-checklist.md +18 -0
  261. package/templates/zh-CN/docs/discussions/README.md +36 -0
  262. package/templates/zh-CN/docs/plans/README.md +15 -0
  263. package/templates/zh-CN/docs/proposed-design/README.md +41 -0
  264. package/templates/zh-CN/docs/temp-reference/README.md +13 -0
  265. package/templates/zh-CN/docs.config.json +46 -0
  266. package/templates/zh-CN/profiles/README.md +23 -0
  267. package/templates/zh-CN/profiles/agent-platform/README.md +23 -0
  268. package/templates/zh-CN/profiles/cli-tool/README.md +23 -0
  269. package/templates/zh-CN/profiles/library-sdk/README.md +23 -0
  270. package/templates/zh-CN/profiles/multi-agent/README.md +23 -0
  271. package/templates/zh-CN/profiles/profiles.json +31 -0
  272. package/templates/zh-CN/profiles/software-automation/README.md +23 -0
  273. package/templates/zh-CN/profiles/web-saas/README.md +23 -0
  274. package/templates/zh-CN/scripts/README.md +97 -0
  275. package/templates/zh-CN/scripts/doc-find.mjs +156 -0
  276. package/templates/zh-CN/scripts/doc-map.mjs +50 -0
  277. package/templates/zh-CN/scripts/doc-tools.mjs +311 -0
  278. package/templates/zh-CN/scripts/init-docs.mjs +214 -0
  279. package/templates/zh-CN/scripts/validate-docs.mjs +141 -0
@@ -0,0 +1,156 @@
1
+ #!/usr/bin/env node
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import { readConfig, documents, parseDocument, withoutCode, codeReferences, globMatcher, relative, localPath, normalize, isMain } from './doc-tools.mjs';
5
+
6
+ const MAX_BYTES = 16384, MAX_FILES = 1000, MAX_MAPPING_WORK = 5_000_000;
7
+ const notice = 'Discovery hints only; no match does not prove that constraints are absent. Check sources and active code.';
8
+ const shorten = (text, length) => Array.from(text).slice(0, length).join('');
9
+ const order = (a, b) => a < b ? -1 : a > b ? 1 : 0;
10
+ const fold = text => text.normalize('NFKC').toLowerCase();
11
+
12
+ function integer(value, fallback, min, max, name) {
13
+ const result = value === undefined ? fallback : Number(value);
14
+ if (!Number.isInteger(result) || result < min || result > max) throw new Error(name + ' must be an integer from ' + min + ' to ' + max);
15
+ return result;
16
+ }
17
+
18
+ function prefix(file) {
19
+ const fd = fs.openSync(file, fs.constants.O_RDONLY | (fs.constants.O_NOFOLLOW ?? 0));
20
+ try {
21
+ const stat = fs.fstatSync(fd);
22
+ if (!stat.isFile()) throw new Error('Not a regular document');
23
+ const buffer = Buffer.alloc(Math.min(stat.size, MAX_BYTES));
24
+ const bytes = fs.readSync(fd, buffer, 0, buffer.length, 0);
25
+ return { text: normalize(buffer.subarray(0, bytes).toString('utf8')), bytes, truncated: stat.size > bytes };
26
+ } finally { fs.closeSync(fd); }
27
+ }
28
+
29
+ export function findDocuments(root, options = {}) {
30
+ root = path.resolve(root);
31
+ if (!fs.existsSync(root) || !fs.statSync(root).isDirectory()) throw new Error('Project directory does not exist');
32
+ const topic = options.topic ?? '', changed = options.changed ?? [];
33
+ if (typeof topic !== 'string' || topic.length > 256) throw new Error('Topic must be at most 256 characters');
34
+ if (!Array.isArray(changed) || changed.length > 16 || changed.some(value => typeof value !== 'string' || !value || value.length > 512)) {
35
+ throw new Error('Use at most 16 changed paths, each at most 512 characters');
36
+ }
37
+ if (!topic.trim() && !changed.length) throw new Error('Provide --topic or --changed; there is no load-all mode');
38
+ const terms = [...new Set(fold(topic).trim().split(/\s+/).filter(Boolean))];
39
+ if (terms.length > 16) throw new Error('Use at most 16 topic terms');
40
+ const paths = [...new Set(changed.map(name => relative(root, localPath(root, name))))];
41
+ const limit = integer(options.limit, 5, 1, 20, 'limit');
42
+ const files = documents(root, readConfig(root));
43
+ const scan = { candidates: files.length, read: 0, bytes: 0, truncated: 0, invalid: 0, mappingLimited: false, partial: files.length > MAX_FILES };
44
+ const rows = [];
45
+ let mappingWork = 0;
46
+ for (const file of files.slice(0, MAX_FILES)) {
47
+ const name = relative(root, file);
48
+ let sample, parsed, headings, patterns;
49
+ try {
50
+ sample = prefix(localPath(root, name));
51
+ scan.read++; scan.bytes += sample.bytes;
52
+ if (sample.truncated) scan.truncated++;
53
+ parsed = parseDocument(sample.text);
54
+ if (parsed.errors.length) throw new Error('Unsupported metadata');
55
+ if (['Archived', 'Superseded'].includes(parsed.meta?.status)) continue;
56
+ patterns = codeReferences(parsed.meta);
57
+ const offset = sample.text.slice(0, sample.text.length - parsed.body.length).split('\n').length - 1;
58
+ headings = [];
59
+ for (const [index, line] of withoutCode(parsed.body).split('\n').entries()) {
60
+ const match = line.match(/^ {0,3}(#{1,6})\s+(.+?)\s*#*\s*$/);
61
+ if (match) headings.push({ title: match[2], line: offset + index + 1, level: match[1].length });
62
+ }
63
+ } catch { scan.invalid++; continue; }
64
+ const title = headings.find(row => row.level === 1)?.title ?? name;
65
+ const meta = parsed.meta ?? {};
66
+ const values = [title, name, typeof meta.trigger === 'string' ? meta.trigger : '',
67
+ typeof meta.scope === 'string' ? meta.scope : Array.isArray(meta.scope) ? meta.scope.join(' ') : ''].map(fold);
68
+ const headingText = headings.map(row => fold(row.title));
69
+ let score = 0;
70
+ const reasons = [];
71
+ const hits = terms.filter(term => values.some(value => value.includes(term)) || headingText.some(value => value.includes(term)));
72
+ if (hits.length) {
73
+ score += hits.length * 4;
74
+ if (hits.some(term => values[0].includes(term))) score += 3;
75
+ reasons.push('topic: ' + shorten(hits.join(', '), 64));
76
+ }
77
+ if (paths.includes(name)) { score += 20; reasons.push('document path'); }
78
+ for (const pattern of patterns) {
79
+ if (!paths.length) break;
80
+ // Bound the existing DP glob matcher's total work even for adversarial metadata.
81
+ const work = (pattern.length + 1) * paths.reduce((sum, value) => sum + value.length + 1, 0);
82
+ if (mappingWork + work > MAX_MAPPING_WORK) { scan.mappingLimited = true; continue; }
83
+ mappingWork += work;
84
+ try {
85
+ const matcher = globMatcher(pattern);
86
+ if (paths.some(value => matcher.test(value))) { score += 20; reasons.push('code_refs/code_owns'); break; }
87
+ } catch { scan.invalid++; break; }
88
+ }
89
+ if (!score) continue;
90
+ const section = headings.find((row, index) => row.level > 1 && terms.some(term => headingText[index].includes(term))) ??
91
+ headings.find(row => row.level === 1);
92
+ rows.push({ document: name, title: shorten(title, 100), status: ['Current', 'Draft', 'Unverified'].includes(meta.status) ? meta.status : 'Unverified',
93
+ reason: reasons.join('; '), ...(section ? { section: { title: shorten(section.title, 100), line: section.line } } : {}), score });
94
+ }
95
+ scan.partial ||= scan.truncated > 0 || scan.invalid > 0 || scan.mappingLimited;
96
+ rows.sort((a, b) => b.score - a.score || order(a.document, b.document));
97
+ return { matches: rows.slice(0, limit).map(({ score, ...row }) => row), omitted: Math.max(0, rows.length - limit), scan, notice };
98
+ }
99
+
100
+ export function formatFindResult(result, options = {}) {
101
+ const maxChars = integer(options.maxChars, 2400, 512, 12000, 'max-chars');
102
+ const bounded = { ...result, matches: [...result.matches] };
103
+ function render() {
104
+ if (options.json) return JSON.stringify(bounded) + '\n';
105
+ return [
106
+ ...bounded.matches.map(row => row.document + (row.section ? ':' + row.section.line : '') + ' [' + row.status + '] ' + row.title + '\n ' + row.reason),
107
+ 'omitted: ' + bounded.omitted + '; scanned: ' + bounded.scan.read + '/' + bounded.scan.candidates + '; partial: ' + bounded.scan.partial,
108
+ bounded.notice,
109
+ ].join('\n') + '\n';
110
+ }
111
+ let output = render();
112
+ while (Array.from(output).length > maxChars && bounded.matches.length) {
113
+ bounded.matches.pop(); bounded.omitted++;
114
+ output = render();
115
+ }
116
+ return output;
117
+ }
118
+
119
+ function main() {
120
+ const args = process.argv.slice(2), options = { changed: [] };
121
+ let root = '.', hasRoot = false;
122
+ for (let i = 0; i < args.length; i++) {
123
+ const arg = args[i];
124
+ if (arg === '--help') {
125
+ console.log('node scripts/doc-find.mjs [root] (--topic text | --changed path)... [--limit 1..20] [--max-chars 512..12000] [--json]');
126
+ return;
127
+ }
128
+ if (arg === '--json') options.json = true;
129
+ else if (['--topic', '--changed', '--limit', '--max-chars'].includes(arg)) {
130
+ const value = args[++i];
131
+ if (!value || value.startsWith('--')) throw new Error(arg + ' requires a value');
132
+ if (arg === '--changed') options.changed.push(value);
133
+ else options[{ '--topic': 'topic', '--limit': 'limit', '--max-chars': 'maxChars' }[arg]] = value;
134
+ } else if (!arg.startsWith('-') && !hasRoot) { root = arg; hasRoot = true; }
135
+ else throw new Error('Unknown argument: ' + shorten(arg, 100));
136
+ }
137
+ integer(options.maxChars, 2400, 512, 12000, 'max-chars');
138
+ process.stdout.write(formatFindResult(findDocuments(root, options), options));
139
+ }
140
+ if (isMain(import.meta.url)) {
141
+ try { main(); } catch (error) {
142
+ const index = process.argv.lastIndexOf('--max-chars');
143
+ const requested = index < 0 ? 2400 : Number(process.argv[index + 1]);
144
+ const maxChars = Number.isInteger(requested) && requested >= 512 && requested <= 12000 ? requested : 2400;
145
+ let message = shorten(error.message, 300);
146
+ const json = process.argv.includes('--json');
147
+ let output = json ? JSON.stringify({ error: message }) + '\n' : message + '\n';
148
+ while (Array.from(output).length > maxChars) {
149
+ message = shorten(message, Array.from(message).length - 1);
150
+ output = json ? JSON.stringify({ error: message }) + '\n' : message + '\n';
151
+ }
152
+ if (json) process.stdout.write(output);
153
+ else process.stderr.write(output);
154
+ process.exitCode = 1;
155
+ }
156
+ }
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env node
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import { readConfig, documents, parseDocument, codeReferences, globMatcher, relative, localPath, isMain } from './doc-tools.mjs';
5
+
6
+ export function documentMap(root, changed = []) {
7
+ root = path.resolve(root);
8
+ if (!fs.existsSync(root)) throw new Error('Project directory does not exist: ' + root);
9
+ const normalized = changed.map(file => relative(root, localPath(root, file)));
10
+ const rows = [];
11
+ for (const file of documents(root, readConfig(root))) {
12
+ const parsed = parseDocument(fs.readFileSync(file, 'utf8'));
13
+ if (parsed.errors.length) throw new Error(relative(root, file) + ': ' + parsed.errors.join('; '));
14
+ if (!parsed.meta || ['Superseded', 'Archived'].includes(parsed.meta.status)) continue;
15
+ for (const pattern of codeReferences(parsed.meta)) {
16
+ const matcher = globMatcher(pattern);
17
+ const matches = normalized.filter(file => matcher.test(file));
18
+ if (!changed.length || matches.length) {
19
+ rows.push({ document: relative(root, file), status: parsed.meta.status, pattern, matches });
20
+ }
21
+ }
22
+ }
23
+ return rows;
24
+ }
25
+
26
+ function main() {
27
+ const args = process.argv.slice(2);
28
+ let root = '.', json = false, hasRoot = false;
29
+ const changed = [];
30
+ for (let i = 0; i < args.length; i++) {
31
+ if (args[i] === '--help') {
32
+ console.log('node scripts/doc-map.mjs [root] [--changed path]... [--json]');
33
+ return;
34
+ }
35
+ if (args[i] === '--changed') {
36
+ const value = args[++i];
37
+ if (!value || value.startsWith('--')) throw new Error('--changed requires a path');
38
+ changed.push(value);
39
+ } else if (args[i] === '--json') json = true;
40
+ else if (!args[i].startsWith('-') && !hasRoot) { root = args[i]; hasRoot = true; }
41
+ else throw new Error('Unknown argument: ' + args[i]);
42
+ }
43
+ const rows = documentMap(root, changed);
44
+ if (json) console.log(JSON.stringify(rows, null, 2));
45
+ else if (!rows.length) console.log('No mapping hints; this does not prove documentation is unaffected.');
46
+ else for (const row of rows) console.log(row.document + ' [' + row.status + '] <- ' + row.pattern);
47
+ }
48
+ if (isMain(import.meta.url)) {
49
+ try { main(); } catch (error) { console.error(error.message); process.exitCode = 1; }
50
+ }
@@ -0,0 +1,311 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+
5
+ export function isMain(url) {
6
+ if (!process.argv[1]) return false;
7
+ try { return fs.realpathSync(process.argv[1]) === fs.realpathSync(fileURLToPath(url)); }
8
+ catch { return false; }
9
+ }
10
+
11
+ export const defaults = {
12
+ version: 1,
13
+ locale: 'en-US',
14
+ mode: 'project',
15
+ documentRoots: ['AGENTS.md', 'SESSION.md', 'DOCS_MAINTENANCE.md', 'docs'],
16
+ requiredFiles: ['AGENTS.md', 'SESSION.md', 'docs/00-context.md'],
17
+ exclude: ['.git', 'node_modules', '.cache', 'vendor', 'build', 'dist', '.worktrees', 'tmp', '99-source-archive'],
18
+ entryBudgets: {
19
+ 'AGENTS.md': { characters: 1400, lines: 50 },
20
+ 'SESSION.md': { characters: 1800, lines: 60 },
21
+ 'docs/00-context.md': { characters: 2200, lines: 80 },
22
+ },
23
+ };
24
+
25
+ export function normalize(text) {
26
+ return text.replace(/^\uFEFF/, '').replace(/\r\n?/g, '\n');
27
+ }
28
+
29
+ export function inside(root, target) {
30
+ const rel = path.relative(root, target);
31
+ return rel === '' || (!path.isAbsolute(rel) && rel !== '..' && !rel.startsWith('..' + path.sep));
32
+ }
33
+
34
+ export function localPath(root, target, base = root) {
35
+ const resolved = path.resolve(base, target);
36
+ if (!inside(path.resolve(root), resolved)) throw new Error('Path escapes project: ' + target);
37
+ if (fs.existsSync(root)) {
38
+ let ancestor = resolved;
39
+ while (ancestor !== path.dirname(ancestor)) {
40
+ try {
41
+ if (fs.lstatSync(ancestor, { throwIfNoEntry: false })) break;
42
+ } catch (error) {
43
+ if (error.code === 'ENOTDIR') throw new Error('Target parent is not a directory: ' + target);
44
+ throw error;
45
+ }
46
+ ancestor = path.dirname(ancestor);
47
+ }
48
+ if (!inside(fs.realpathSync(root), fs.realpathSync(ancestor))) {
49
+ throw new Error('Symlink escapes project: ' + target);
50
+ }
51
+ }
52
+ return resolved;
53
+ }
54
+
55
+ export function readConfig(root) {
56
+ const file = path.join(root, 'docs.config.json');
57
+ const supplied = fs.existsSync(file) ? JSON.parse(fs.readFileSync(file, 'utf8').replace(/^\uFEFF/, '')) : {};
58
+ if (!supplied || typeof supplied !== 'object' || Array.isArray(supplied)) throw new Error('Configuration must be an object');
59
+ for (const key of Object.keys(supplied)) {
60
+ if (!Object.hasOwn(defaults, key)) throw new Error('Unknown configuration field: ' + key);
61
+ }
62
+ const config = { ...defaults, ...supplied };
63
+ if (config.version !== 1) throw new Error('Unsupported configuration version');
64
+ if (!['template', 'project'].includes(config.mode)) throw new Error('mode must be template or project');
65
+ if (!['zh-CN', 'en-US'].includes(config.locale)) throw new Error('locale must be zh-CN or en-US');
66
+ for (const key of ['documentRoots', 'requiredFiles', 'exclude']) {
67
+ if (!Array.isArray(config[key]) || config[key].some(value => typeof value !== 'string' || !value)) {
68
+ throw new Error(key + ' must be an array of non-empty strings');
69
+ }
70
+ for (const name of config[key]) {
71
+ if (name !== '.' && (name.includes('\\') || path.isAbsolute(name) || /^[A-Za-z]:/.test(name) || name.split('/').some(part => !part || part === '.' || part === '..'))) {
72
+ throw new Error(key + ': Use normalized repository-relative paths: ' + name);
73
+ }
74
+ if (key !== 'exclude') localPath(root, name);
75
+ }
76
+ }
77
+ if (!config.entryBudgets || typeof config.entryBudgets !== 'object' || Array.isArray(config.entryBudgets)) {
78
+ throw new Error('entryBudgets must be an object');
79
+ }
80
+ for (const [name, budget] of Object.entries(config.entryBudgets)) {
81
+ if (!name || name.includes('\\') || path.isAbsolute(name) || /^[A-Za-z]:/.test(name) ||
82
+ name.split('/').some(part => !part || part === '.' || part === '..')) {
83
+ throw new Error('Budget keys require normalized repository-relative paths: ' + name);
84
+ }
85
+ localPath(root, name);
86
+ if (!budget || typeof budget !== 'object' || Array.isArray(budget)) throw new Error('Invalid budget: ' + name);
87
+ for (const [unit, value] of Object.entries(budget)) {
88
+ if (!['characters', 'lines'].includes(unit) || !Number.isInteger(value) || value < 1) {
89
+ throw new Error('Invalid budget: ' + name + '.' + unit);
90
+ }
91
+ }
92
+ }
93
+ return config;
94
+ }
95
+
96
+ export function documents(root, config) {
97
+ const found = new Set();
98
+ function visit(file) {
99
+ const name = relative(root, file);
100
+ if (config.exclude.some(entry => entry.includes('/')
101
+ ? name === entry || name.startsWith(entry + '/')
102
+ : name.split('/').includes(entry))) return;
103
+ if (!fs.existsSync(file)) return;
104
+ const stat = fs.lstatSync(file);
105
+ if (stat.isSymbolicLink()) return;
106
+ if (stat.isDirectory()) {
107
+ for (const item of fs.readdirSync(file).sort()) {
108
+ if (!config.exclude.includes(item)) visit(path.join(file, item));
109
+ }
110
+ } else if (stat.isFile() && file.endsWith('.md')) {
111
+ found.add(file);
112
+ }
113
+ }
114
+ for (const entry of config.documentRoots) {
115
+ const file = localPath(root, entry);
116
+ let current = file, symlink = false;
117
+ while (current !== root && inside(root, current)) {
118
+ if (fs.lstatSync(current, { throwIfNoEntry: false })?.isSymbolicLink()) { symlink = true; break; }
119
+ current = path.dirname(current);
120
+ }
121
+ if (!symlink) visit(file);
122
+ }
123
+ return [...found].sort();
124
+ }
125
+
126
+ function withoutComment(value) {
127
+ let quote = '';
128
+ const array = value.trimStart().startsWith('[');
129
+ let mayQuote = true;
130
+ for (let i = 0; i < value.length; i++) {
131
+ const c = value[i];
132
+ if (quote) {
133
+ if (c === '\\' && quote === '"') { i++; continue; }
134
+ if (c === quote) {
135
+ if (quote === "'" && value[i + 1] === "'") { i++; continue; }
136
+ quote = '';
137
+ mayQuote = false;
138
+ }
139
+ } else if ((c === '"' || c === "'") && mayQuote) quote = c;
140
+ else {
141
+ if (c === '#' && (i === 0 || /\s/.test(value[i - 1]))) return value.slice(0, i).trim();
142
+ if (!/\s/.test(c)) mayQuote = array && (c === '[' || c === ',');
143
+ }
144
+ }
145
+ return value.trim();
146
+ }
147
+
148
+ function scalar(value) {
149
+ value = withoutComment(value);
150
+ if (value.startsWith('"')) {
151
+ const parsed = JSON.parse(value);
152
+ if (typeof parsed !== 'string') throw new Error('Metadata scalars must be strings');
153
+ return parsed;
154
+ }
155
+ if (value.startsWith("'")) {
156
+ if (!/^'(?:[^']|'')*'$/.test(value)) throw new Error('Incomplete single-quoted string');
157
+ return value.slice(1, -1).replace(/''/g, "'");
158
+ }
159
+ if (/^[{[>|&*!]/.test(value)) throw new Error('Use plain scalars or string lists');
160
+ if (/^(?:-|\?)\s/.test(value)) throw new Error('Nested sequences or mappings are unsupported');
161
+ if (/:\s|:$/.test(value)) throw new Error('Nested mappings are unsupported; quote a literal string');
162
+ return value;
163
+ }
164
+
165
+ // Deliberately supports a documented flat subset, not arbitrary YAML.
166
+ export function parseDocument(input) {
167
+ const text = normalize(input);
168
+ const match = text.match(/^---\n([\s\S]*?)\n---(?:\n|$)/);
169
+ if (!match) return { meta: null, body: text, errors: text.startsWith('---\n') ? ['Unclosed front-matter'] : [] };
170
+ const meta = {};
171
+ const errors = [];
172
+ let listKey = null;
173
+ let listIndent = null;
174
+ for (const [index, raw] of match[1].split('\n').entries()) {
175
+ if (!raw.trim() || raw.trimStart().startsWith('#')) continue;
176
+ try {
177
+ const item = raw.match(/^( +)-\s+(.+)$/);
178
+ if (item) {
179
+ if (!listKey) throw new Error('List has no field');
180
+ if (listIndent !== null && item[1].length !== listIndent) throw new Error('Nested or inconsistent list indentation');
181
+ listIndent = item[1].length;
182
+ meta[listKey].push(scalar(item[2]));
183
+ continue;
184
+ }
185
+ const field = raw.match(/^([A-Za-z_][\w-]*):\s*(.*)$/);
186
+ if (!field) throw new Error('Nested or multiline metadata is unsupported; link separate evidence');
187
+ const [, key, rawValue] = field;
188
+ if (['__proto__', 'constructor', 'prototype'].includes(key)) throw new Error('Unsupported metadata field: ' + key);
189
+ if (Object.hasOwn(meta, key)) throw new Error('Duplicate field: ' + key);
190
+ const value = withoutComment(rawValue);
191
+ listKey = null;
192
+ listIndent = null;
193
+ if (!value) { meta[key] = []; listKey = key; }
194
+ else if (value.startsWith('[')) {
195
+ const list = JSON.parse(value);
196
+ if (!Array.isArray(list) || list.some(v => typeof v !== 'string')) throw new Error('Lists must use JSON string arrays');
197
+ meta[key] = list;
198
+ } else meta[key] = scalar(value);
199
+ } catch (error) { errors.push('Metadata line ' + (index + 2) + ': ' + error.message); }
200
+ }
201
+ return { meta, body: text.slice(match[0].length), errors };
202
+ }
203
+
204
+ export function withoutCode(input) {
205
+ let fence = null;
206
+ return normalize(input).split('\n').map(line => {
207
+ const marker = line.match(/^ {0,3}([\x60~])\1{2,}/);
208
+ if (marker) {
209
+ if (!fence) fence = { char: marker[1], length: marker[0].trim().length };
210
+ else if (marker[1] === fence.char && marker[0].trim().length >= fence.length &&
211
+ line.slice(marker[0].length).trim() === '') fence = null;
212
+ return '';
213
+ }
214
+ return fence ? '' : line;
215
+ }).join('\n');
216
+ }
217
+
218
+ export function markdownLinks(body) {
219
+ const text = withoutCode(body).replace(/(\x60+)[^\n]*?\1/g, '');
220
+ const results = [];
221
+ const pattern = /!?\[[^\]\n]*\]\(\s*/g;
222
+ const unescape = value => value.replace(/\\([!"#$%&'()*+,\-./:;<=>?@[\]\\^_`{|}~])/g, '$1');
223
+ for (const match of text.matchAll(pattern)) {
224
+ let start = match.index + match[0].length, end = start, suffix;
225
+ if (text[start] === '<') {
226
+ start++;
227
+ end = text.indexOf('>', start);
228
+ if (end < 0 || text.slice(start, end).includes('\n')) continue;
229
+ suffix = end + 1;
230
+ } else {
231
+ let depth = 0;
232
+ for (; end < text.length; end++) {
233
+ const char = text[end];
234
+ if (char === '\\') { end++; continue; }
235
+ if (char === '(') depth++;
236
+ else if (char === ')') {
237
+ if (depth === 0) break;
238
+ depth--;
239
+ } else if (/\s/.test(char)) break;
240
+ }
241
+ if (depth !== 0) continue;
242
+ suffix = end;
243
+ }
244
+ if (/^\s*(?:(?:"[^"\n]*"|'[^'\n]*'|\([^\n)]*\))\s*)?\)/.test(text.slice(suffix))) {
245
+ results.push(unescape(text.slice(start, end)));
246
+ }
247
+ }
248
+ for (const match of text.matchAll(/^\s{0,3}\[[^\]\n]+\]:\s*(<[^>\n]+>|\S+)/gm)) {
249
+ results.push(unescape(match[1].replace(/^<|>$/g, '')));
250
+ }
251
+ return results;
252
+ }
253
+
254
+ export function codeReferences(meta) {
255
+ const values = [];
256
+ for (const key of ['code_refs', 'code_owns']) {
257
+ if (meta?.[key] === undefined) continue;
258
+ if (!Array.isArray(meta[key]) || meta[key].some(v => typeof v !== 'string' || !v)) {
259
+ throw new Error(key + ' must be a list of path strings');
260
+ }
261
+ values.push(...meta[key]);
262
+ }
263
+ return [...new Set(values)];
264
+ }
265
+
266
+ export function globMatcher(pattern) {
267
+ if (!pattern || pattern.includes('\\') || pattern.startsWith('/') || /^[A-Za-z]:/.test(pattern) ||
268
+ pattern.split('/').some(part => !part || part === '.' || part === '..') || /[\[\]{}]/.test(pattern)) {
269
+ throw new Error('Code mappings require normalized root-relative paths with *, **, ?: ' + pattern);
270
+ }
271
+ const chars = Array.from(pattern), tokens = [];
272
+ for (let i = 0; i < chars.length; i++) {
273
+ const c = chars[i];
274
+ if (c === '*' && chars[i + 1] === '*') {
275
+ i++;
276
+ if (chars[i + 1] === '/') { i++; tokens.push({ kind: 'directories' }); }
277
+ else tokens.push({ kind: 'all' });
278
+ } else if (c === '*') tokens.push({ kind: 'segment' });
279
+ else if (c === '?') tokens.push({ kind: 'one' });
280
+ else tokens.push({ kind: 'literal', value: c });
281
+ }
282
+ // Dynamic programming bounds work by pattern length * path length;
283
+ // repeated wildcards must not cause exponential regex backtracking.
284
+ return { test(value) {
285
+ const input = Array.from(value);
286
+ let previous = new Uint8Array(input.length + 1);
287
+ previous[0] = 1;
288
+ for (const token of tokens) {
289
+ const next = new Uint8Array(input.length + 1);
290
+ if (['all', 'segment', 'directories'].includes(token.kind)) next[0] = previous[0];
291
+ let reachable = previous[0];
292
+ for (let j = 1; j <= input.length; j++) {
293
+ const char = input[j - 1];
294
+ if (token.kind === 'all' || token.kind === 'segment') {
295
+ next[j] = previous[j] || (next[j - 1] && (token.kind === 'all' || char !== '/'));
296
+ } else if (token.kind === 'directories') {
297
+ next[j] = previous[j] || (reachable && char === '/');
298
+ reachable ||= previous[j];
299
+ } else {
300
+ next[j] = previous[j - 1] && (token.kind === 'one' ? char !== '/' : char === token.value);
301
+ }
302
+ }
303
+ previous = next;
304
+ }
305
+ return Boolean(previous[input.length]);
306
+ } };
307
+ }
308
+
309
+ export function relative(root, file) {
310
+ return path.relative(root, file).split(path.sep).join('/');
311
+ }