mrplex 0.0.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 (319) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +284 -0
  3. package/dist/cli/config.d.ts +28 -0
  4. package/dist/cli/config.js +48 -0
  5. package/dist/cli/config.js.map +1 -0
  6. package/dist/cli/exit-codes.d.ts +13 -0
  7. package/dist/cli/exit-codes.js +39 -0
  8. package/dist/cli/exit-codes.js.map +1 -0
  9. package/dist/cli/format.d.ts +22 -0
  10. package/dist/cli/format.js +148 -0
  11. package/dist/cli/format.js.map +1 -0
  12. package/dist/cli/main.d.ts +16 -0
  13. package/dist/cli/main.js +1518 -0
  14. package/dist/cli/main.js.map +1 -0
  15. package/dist/client/kernel-client.d.ts +97 -0
  16. package/dist/client/kernel-client.js +14 -0
  17. package/dist/client/kernel-client.js.map +1 -0
  18. package/dist/client/local.d.ts +26 -0
  19. package/dist/client/local.js +103 -0
  20. package/dist/client/local.js.map +1 -0
  21. package/dist/client/remote-mcp.d.ts +35 -0
  22. package/dist/client/remote-mcp.js +174 -0
  23. package/dist/client/remote-mcp.js.map +1 -0
  24. package/dist/embed/backfill.d.ts +24 -0
  25. package/dist/embed/backfill.js +33 -0
  26. package/dist/embed/backfill.js.map +1 -0
  27. package/dist/embed/chunker.d.ts +31 -0
  28. package/dist/embed/chunker.js +121 -0
  29. package/dist/embed/chunker.js.map +1 -0
  30. package/dist/embed/cmd-hook.d.ts +21 -0
  31. package/dist/embed/cmd-hook.js +100 -0
  32. package/dist/embed/cmd-hook.js.map +1 -0
  33. package/dist/embed/config.d.ts +61 -0
  34. package/dist/embed/config.js +109 -0
  35. package/dist/embed/config.js.map +1 -0
  36. package/dist/embed/hook.d.ts +38 -0
  37. package/dist/embed/hook.js +56 -0
  38. package/dist/embed/hook.js.map +1 -0
  39. package/dist/embed/http-hook.d.ts +13 -0
  40. package/dist/embed/http-hook.js +39 -0
  41. package/dist/embed/http-hook.js.map +1 -0
  42. package/dist/embed/worker.d.ts +62 -0
  43. package/dist/embed/worker.js +228 -0
  44. package/dist/embed/worker.js.map +1 -0
  45. package/dist/fixtures/hwe/characters/albion-ever.md +12 -0
  46. package/dist/fixtures/hwe/characters/cent.md +11 -0
  47. package/dist/fixtures/hwe/concepts/cent-demiurge-resonance.md +10 -0
  48. package/dist/fixtures/hwe/concepts/phase-looper.md +10 -0
  49. package/dist/fixtures/hwe/entities/demiurge.md +11 -0
  50. package/dist/fixtures/hwe/entities/monad.md +11 -0
  51. package/dist/fixtures/hwe/moc/globocorp-network.md +19 -0
  52. package/dist/fixtures/hwe/organizations/globocorp.md +11 -0
  53. package/dist/fixtures/hwe/readme.md +24 -0
  54. package/dist/fixtures/starship/crew/aria-okonkwo.md +14 -0
  55. package/dist/fixtures/starship/crew/bexley-orr.md +14 -0
  56. package/dist/fixtures/starship/crew/dax-thorne.md +14 -0
  57. package/dist/fixtures/starship/crew/isolde-marsh.md +16 -0
  58. package/dist/fixtures/starship/crew/kestrel-vance.md +15 -0
  59. package/dist/fixtures/starship/crew/quill-vasquez.md +14 -0
  60. package/dist/fixtures/starship/crew/soren-halloway.md +16 -0
  61. package/dist/fixtures/starship/encounters/the-drift-choir.md +14 -0
  62. package/dist/fixtures/starship/encounters/the-hollow-signal.md +16 -0
  63. package/dist/fixtures/starship/encounters/the-wandering-buoy.md +14 -0
  64. package/dist/fixtures/starship/equipment/coolant-loop-b.md +13 -0
  65. package/dist/fixtures/starship/equipment/emergency-ration-bars.md +12 -0
  66. package/dist/fixtures/starship/equipment/long-range-sensors.md +13 -0
  67. package/dist/fixtures/starship/equipment/plasma-manifold-3.md +15 -0
  68. package/dist/fixtures/starship/equipment/shuttle-corvid.md +13 -0
  69. package/dist/fixtures/starship/logs/marsh-4419-1.md +13 -0
  70. package/dist/fixtures/starship/logs/okonkwo-4415-1.md +13 -0
  71. package/dist/fixtures/starship/logs/orr-4413-1.md +13 -0
  72. package/dist/fixtures/starship/logs/orr-4420-1.md +12 -0
  73. package/dist/fixtures/starship/logs/thorne-4413-2.md +13 -0
  74. package/dist/fixtures/starship/logs/vance-4419-2.md +13 -0
  75. package/dist/fixtures/starship/misc/the-galley-ficus.md +11 -0
  76. package/dist/fixtures/starship/missions/the-cinder-run.md +17 -0
  77. package/dist/fixtures/starship/missions/the-drift-choir.md +17 -0
  78. package/dist/fixtures/starship/missions/the-hollow-signal.md +17 -0
  79. package/dist/fixtures/starship/missions/the-silent-beacon.md +17 -0
  80. package/dist/fixtures/starship/moc/crew.md +19 -0
  81. package/dist/fixtures/starship/moc/encounters.md +14 -0
  82. package/dist/fixtures/starship/moc/missions.md +15 -0
  83. package/dist/fixtures/starship/readme.md +60 -0
  84. package/dist/index.d.ts +1 -0
  85. package/dist/index.js +3 -0
  86. package/dist/index.js.map +1 -0
  87. package/dist/kernel/auth/glob.d.ts +46 -0
  88. package/dist/kernel/auth/glob.js +112 -0
  89. package/dist/kernel/auth/glob.js.map +1 -0
  90. package/dist/kernel/auth/scope.d.ts +53 -0
  91. package/dist/kernel/auth/scope.js +83 -0
  92. package/dist/kernel/auth/scope.js.map +1 -0
  93. package/dist/kernel/casefold.d.ts +37 -0
  94. package/dist/kernel/casefold.js +44 -0
  95. package/dist/kernel/casefold.js.map +1 -0
  96. package/dist/kernel/constants.d.ts +21 -0
  97. package/dist/kernel/constants.js +22 -0
  98. package/dist/kernel/constants.js.map +1 -0
  99. package/dist/kernel/context.d.ts +70 -0
  100. package/dist/kernel/context.js +114 -0
  101. package/dist/kernel/context.js.map +1 -0
  102. package/dist/kernel/deletion.d.ts +50 -0
  103. package/dist/kernel/deletion.js +83 -0
  104. package/dist/kernel/deletion.js.map +1 -0
  105. package/dist/kernel/diff.d.ts +36 -0
  106. package/dist/kernel/diff.js +61 -0
  107. package/dist/kernel/diff.js.map +1 -0
  108. package/dist/kernel/errors.d.ts +37 -0
  109. package/dist/kernel/errors.js +55 -0
  110. package/dist/kernel/errors.js.map +1 -0
  111. package/dist/kernel/frontmatter-input.d.ts +32 -0
  112. package/dist/kernel/frontmatter-input.js +85 -0
  113. package/dist/kernel/frontmatter-input.js.map +1 -0
  114. package/dist/kernel/graph.d.ts +34 -0
  115. package/dist/kernel/graph.js +559 -0
  116. package/dist/kernel/graph.js.map +1 -0
  117. package/dist/kernel/history.d.ts +74 -0
  118. package/dist/kernel/history.js +143 -0
  119. package/dist/kernel/history.js.map +1 -0
  120. package/dist/kernel/kernel.d.ts +162 -0
  121. package/dist/kernel/kernel.js +675 -0
  122. package/dist/kernel/kernel.js.map +1 -0
  123. package/dist/kernel/path-config.d.ts +101 -0
  124. package/dist/kernel/path-config.js +171 -0
  125. package/dist/kernel/path-config.js.map +1 -0
  126. package/dist/kernel/query/ast.d.ts +24 -0
  127. package/dist/kernel/query/ast.js +52 -0
  128. package/dist/kernel/query/ast.js.map +1 -0
  129. package/dist/kernel/query/cel-parse.d.ts +37 -0
  130. package/dist/kernel/query/cel-parse.js +88 -0
  131. package/dist/kernel/query/cel-parse.js.map +1 -0
  132. package/dist/kernel/query/degrees.d.ts +31 -0
  133. package/dist/kernel/query/degrees.js +135 -0
  134. package/dist/kernel/query/degrees.js.map +1 -0
  135. package/dist/kernel/query/graph-ast.d.ts +51 -0
  136. package/dist/kernel/query/graph-ast.js +139 -0
  137. package/dist/kernel/query/graph-ast.js.map +1 -0
  138. package/dist/kernel/query/query.d.ts +56 -0
  139. package/dist/kernel/query/query.js +276 -0
  140. package/dist/kernel/query/query.js.map +1 -0
  141. package/dist/kernel/validation.d.ts +64 -0
  142. package/dist/kernel/validation.js +183 -0
  143. package/dist/kernel/validation.js.map +1 -0
  144. package/dist/kernel/version-id.d.ts +10 -0
  145. package/dist/kernel/version-id.js +21 -0
  146. package/dist/kernel/version-id.js.map +1 -0
  147. package/dist/kernel/wire.d.ts +148 -0
  148. package/dist/kernel/wire.js +6 -0
  149. package/dist/kernel/wire.js.map +1 -0
  150. package/dist/links/backfill.d.ts +28 -0
  151. package/dist/links/backfill.js +33 -0
  152. package/dist/links/backfill.js.map +1 -0
  153. package/dist/links/extract.d.ts +29 -0
  154. package/dist/links/extract.js +233 -0
  155. package/dist/links/extract.js.map +1 -0
  156. package/dist/links/link-config.d.ts +70 -0
  157. package/dist/links/link-config.js +107 -0
  158. package/dist/links/link-config.js.map +1 -0
  159. package/dist/links/maintain.d.ts +37 -0
  160. package/dist/links/maintain.js +91 -0
  161. package/dist/links/maintain.js.map +1 -0
  162. package/dist/links/repair.d.ts +46 -0
  163. package/dist/links/repair.js +96 -0
  164. package/dist/links/repair.js.map +1 -0
  165. package/dist/links/resolve.d.ts +41 -0
  166. package/dist/links/resolve.js +121 -0
  167. package/dist/links/resolve.js.map +1 -0
  168. package/dist/links/stale.d.ts +32 -0
  169. package/dist/links/stale.js +73 -0
  170. package/dist/links/stale.js.map +1 -0
  171. package/dist/markdown/content-hash.d.ts +34 -0
  172. package/dist/markdown/content-hash.js +46 -0
  173. package/dist/markdown/content-hash.js.map +1 -0
  174. package/dist/markdown/frontmatter.d.ts +69 -0
  175. package/dist/markdown/frontmatter.js +147 -0
  176. package/dist/markdown/frontmatter.js.map +1 -0
  177. package/dist/markdown/hash-backfill.d.ts +22 -0
  178. package/dist/markdown/hash-backfill.js +43 -0
  179. package/dist/markdown/hash-backfill.js.map +1 -0
  180. package/dist/mcp/query-syntax.d.ts +20 -0
  181. package/dist/mcp/query-syntax.js +194 -0
  182. package/dist/mcp/query-syntax.js.map +1 -0
  183. package/dist/mcp/render.d.ts +31 -0
  184. package/dist/mcp/render.js +110 -0
  185. package/dist/mcp/render.js.map +1 -0
  186. package/dist/mcp/server.d.ts +60 -0
  187. package/dist/mcp/server.js +170 -0
  188. package/dist/mcp/server.js.map +1 -0
  189. package/dist/mcp/tools.d.ts +93 -0
  190. package/dist/mcp/tools.js +1218 -0
  191. package/dist/mcp/tools.js.map +1 -0
  192. package/dist/rest/conditional.d.ts +37 -0
  193. package/dist/rest/conditional.js +58 -0
  194. package/dist/rest/conditional.js.map +1 -0
  195. package/dist/rest/negotiate.d.ts +33 -0
  196. package/dist/rest/negotiate.js +54 -0
  197. package/dist/rest/negotiate.js.map +1 -0
  198. package/dist/rest/routes.d.ts +37 -0
  199. package/dist/rest/routes.js +744 -0
  200. package/dist/rest/routes.js.map +1 -0
  201. package/dist/seed/fixture-seed.d.ts +35 -0
  202. package/dist/seed/fixture-seed.js +75 -0
  203. package/dist/seed/fixture-seed.js.map +1 -0
  204. package/dist/seed/starship-config.d.ts +3 -0
  205. package/dist/seed/starship-config.js +5 -0
  206. package/dist/seed/starship-config.js.map +1 -0
  207. package/dist/server/headers.d.ts +36 -0
  208. package/dist/server/headers.js +30 -0
  209. package/dist/server/headers.js.map +1 -0
  210. package/dist/server/http-error.d.ts +53 -0
  211. package/dist/server/http-error.js +104 -0
  212. package/dist/server/http-error.js.map +1 -0
  213. package/dist/server/serve.d.ts +56 -0
  214. package/dist/server/serve.js +135 -0
  215. package/dist/server/serve.js.map +1 -0
  216. package/dist/shell/audit.d.ts +32 -0
  217. package/dist/shell/audit.js +28 -0
  218. package/dist/shell/audit.js.map +1 -0
  219. package/dist/shell/guard.d.ts +50 -0
  220. package/dist/shell/guard.js +176 -0
  221. package/dist/shell/guard.js.map +1 -0
  222. package/dist/shell/keys.d.ts +36 -0
  223. package/dist/shell/keys.js +64 -0
  224. package/dist/shell/keys.js.map +1 -0
  225. package/dist/shell/login.d.ts +56 -0
  226. package/dist/shell/login.js +130 -0
  227. package/dist/shell/login.js.map +1 -0
  228. package/dist/shell/oidc.d.ts +62 -0
  229. package/dist/shell/oidc.js +102 -0
  230. package/dist/shell/oidc.js.map +1 -0
  231. package/dist/shell/policy.d.ts +100 -0
  232. package/dist/shell/policy.js +232 -0
  233. package/dist/shell/policy.js.map +1 -0
  234. package/dist/shell/proxy-policy.d.ts +34 -0
  235. package/dist/shell/proxy-policy.js +120 -0
  236. package/dist/shell/proxy-policy.js.map +1 -0
  237. package/dist/shell/proxy.d.ts +47 -0
  238. package/dist/shell/proxy.js +253 -0
  239. package/dist/shell/proxy.js.map +1 -0
  240. package/dist/shell/serve.d.ts +86 -0
  241. package/dist/shell/serve.js +0 -0
  242. package/dist/shell/serve.js.map +1 -0
  243. package/dist/shell/stdio.d.ts +55 -0
  244. package/dist/shell/stdio.js +63 -0
  245. package/dist/shell/stdio.js.map +1 -0
  246. package/dist/storage/registry.d.ts +20 -0
  247. package/dist/storage/registry.js +38 -0
  248. package/dist/storage/registry.js.map +1 -0
  249. package/dist/storage/search-plan.d.ts +93 -0
  250. package/dist/storage/search-plan.js +15 -0
  251. package/dist/storage/search-plan.js.map +1 -0
  252. package/dist/storage/types.d.ts +448 -0
  253. package/dist/storage/types.js +14 -0
  254. package/dist/storage/types.js.map +1 -0
  255. package/dist/storage/versions-since.d.ts +72 -0
  256. package/dist/storage/versions-since.js +92 -0
  257. package/dist/storage/versions-since.js.map +1 -0
  258. package/dist/storage-postgres/adapter.d.ts +17 -0
  259. package/dist/storage-postgres/adapter.js +782 -0
  260. package/dist/storage-postgres/adapter.js.map +1 -0
  261. package/dist/storage-postgres/compile-postgres.d.ts +22 -0
  262. package/dist/storage-postgres/compile-postgres.js +830 -0
  263. package/dist/storage-postgres/compile-postgres.js.map +1 -0
  264. package/dist/storage-postgres/errors.d.ts +34 -0
  265. package/dist/storage-postgres/errors.js +50 -0
  266. package/dist/storage-postgres/errors.js.map +1 -0
  267. package/dist/storage-postgres/migrations/0001_init.sql +113 -0
  268. package/dist/storage-postgres/migrations/0002_content_hash.sql +7 -0
  269. package/dist/storage-postgres/migrations/index.d.ts +22 -0
  270. package/dist/storage-postgres/migrations/index.js +70 -0
  271. package/dist/storage-postgres/migrations/index.js.map +1 -0
  272. package/dist/storage-sqlite/adapter.d.ts +2 -0
  273. package/dist/storage-sqlite/adapter.js +688 -0
  274. package/dist/storage-sqlite/adapter.js.map +1 -0
  275. package/dist/storage-sqlite/compile-filter.d.ts +41 -0
  276. package/dist/storage-sqlite/compile-filter.js +881 -0
  277. package/dist/storage-sqlite/compile-filter.js.map +1 -0
  278. package/dist/storage-sqlite/compile-sqlite.d.ts +19 -0
  279. package/dist/storage-sqlite/compile-sqlite.js +176 -0
  280. package/dist/storage-sqlite/compile-sqlite.js.map +1 -0
  281. package/dist/storage-sqlite/migrations/0001_init.sql +123 -0
  282. package/dist/storage-sqlite/migrations/0002_content_hash.sql +7 -0
  283. package/dist/storage-sqlite/migrations/index.d.ts +6 -0
  284. package/dist/storage-sqlite/migrations/index.js +41 -0
  285. package/dist/storage-sqlite/migrations/index.js.map +1 -0
  286. package/dist/storage-sqlite/vec.d.ts +40 -0
  287. package/dist/storage-sqlite/vec.js +62 -0
  288. package/dist/storage-sqlite/vec.js.map +1 -0
  289. package/dist/sync/cursor.d.ts +36 -0
  290. package/dist/sync/cursor.js +66 -0
  291. package/dist/sync/cursor.js.map +1 -0
  292. package/dist/sync/daemon.d.ts +40 -0
  293. package/dist/sync/daemon.js +202 -0
  294. package/dist/sync/daemon.js.map +1 -0
  295. package/dist/sync/feed.d.ts +38 -0
  296. package/dist/sync/feed.js +125 -0
  297. package/dist/sync/feed.js.map +1 -0
  298. package/dist/sync/fs-store.d.ts +8 -0
  299. package/dist/sync/fs-store.js +76 -0
  300. package/dist/sync/fs-store.js.map +1 -0
  301. package/dist/sync/intrinsics.d.ts +52 -0
  302. package/dist/sync/intrinsics.js +76 -0
  303. package/dist/sync/intrinsics.js.map +1 -0
  304. package/dist/sync/paths.d.ts +38 -0
  305. package/dist/sync/paths.js +56 -0
  306. package/dist/sync/paths.js.map +1 -0
  307. package/dist/sync/push.d.ts +48 -0
  308. package/dist/sync/push.js +328 -0
  309. package/dist/sync/push.js.map +1 -0
  310. package/dist/sync/reconcile.d.ts +54 -0
  311. package/dist/sync/reconcile.js +252 -0
  312. package/dist/sync/reconcile.js.map +1 -0
  313. package/dist/sync/run.d.ts +27 -0
  314. package/dist/sync/run.js +46 -0
  315. package/dist/sync/run.js.map +1 -0
  316. package/dist/version.d.ts +2 -0
  317. package/dist/version.js +5 -0
  318. package/dist/version.js.map +1 -0
  319. package/package.json +80 -0
@@ -0,0 +1,63 @@
1
+ /**
2
+ * stdio launcher — auth-shell plan §1 "Launcher mode: stdio", WS4.
3
+ *
4
+ * `mrplex mcp-stdio` runs an in-process stdio MCP session over a GUARDED
5
+ * kernel. stdio has no HTTP layer, so the credential arrives one of three ways
6
+ * (the MCP spec's own guidance for stdio is credentials-from-environment):
7
+ *
8
+ * 1. `--principal <id>` — trust-by-spawn, no credential: the parent chose to
9
+ * spawn us (local dev, or a gateway that already authenticated).
10
+ * 2. `MRPLEX_SHELL_KEY` env / `--key` — an API key, verified against the
11
+ * policy file exactly as the HTTP front does.
12
+ * 3. `MRPLEX_SHELL_TOKEN` env / `--token` — an OAuth access token (WS5).
13
+ *
14
+ * All three converge on the same `credential → principal → compile() →
15
+ * guardKernel` pipeline; stdio is only special in how the credential arrives.
16
+ */
17
+ import { startMcpStdio } from "../mcp/server.js";
18
+ import { guardKernel } from "./guard.js";
19
+ import { principalForKey } from "./keys.js";
20
+ import { resolvePrincipalFromClaims } from "./oidc.js";
21
+ import { compile } from "./policy.js";
22
+ /**
23
+ * Resolve a stdio credential to a principal against the policy, or throw a
24
+ * clear error. `--principal` is trust-by-spawn (the id must exist, no secret
25
+ * checked); a key is verified by hash; a token is verified as a JWT (requires
26
+ * an OIDC verifier) and matched to a principal by its oidc binding.
27
+ */
28
+ export async function resolveCredential(policy, cred, oidc) {
29
+ if (cred.kind === "principal") {
30
+ if (!(cred.id in policy.principals)) {
31
+ throw new Error(`--principal "${cred.id}" is not defined in the policy file`);
32
+ }
33
+ return { principalId: cred.id };
34
+ }
35
+ if (cred.kind === "key") {
36
+ const id = principalForKey(policy, cred.key);
37
+ if (id === null)
38
+ throw new Error("MRPLEX_SHELL_KEY / --key does not match any principal");
39
+ return { principalId: id };
40
+ }
41
+ // token
42
+ if (oidc === undefined) {
43
+ throw new Error("a token credential requires OIDC configuration (issuer/audience)");
44
+ }
45
+ const claims = await oidc.verify(cred.token);
46
+ const { principalId, author } = resolvePrincipalFromClaims(policy, claims);
47
+ return { principalId, derivedAuthor: author };
48
+ }
49
+ /**
50
+ * Start a guarded stdio MCP session. Resolves the credential to a principal,
51
+ * compiles its entitlement, wraps the kernel in the guard (+ optional audit),
52
+ * and hands the guarded kernel to the shared stdio transport.
53
+ */
54
+ export async function startShellStdio(config) {
55
+ const { principalId, derivedAuthor } = await resolveCredential(config.policy, config.credential, config.oidc);
56
+ const entitlement = compile(config.policy, principalId, derivedAuthor);
57
+ const audit = config.auditSinkFor?.(principalId);
58
+ const guarded = guardKernel(config.kernel, entitlement, audit);
59
+ // The guard derives author + read scope from the entitlement, so no launch-
60
+ // time CallContext is needed — pass none.
61
+ return startMcpStdio({ kernel: guarded });
62
+ }
63
+ //# sourceMappingURL=stdio.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stdio.js","sourceRoot":"","sources":["../../src/shell/stdio.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,EAAmB,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAkB,WAAW,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAqB,0BAA0B,EAAE,MAAM,WAAW,CAAC;AAC1E,OAAO,EAAe,OAAO,EAAE,MAAM,aAAa,CAAC;AAUnD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,MAAc,EACd,IAAqB,EACrB,IAAmB;IAEnB,IAAI,IAAI,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;QAC9B,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,IAAI,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;YACpC,MAAM,IAAI,KAAK,CAAC,gBAAgB,IAAI,CAAC,EAAE,qCAAqC,CAAC,CAAC;QAChF,CAAC;QACD,OAAO,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC;IAClC,CAAC;IACD,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;QACxB,MAAM,EAAE,GAAG,eAAe,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;QAC7C,IAAI,EAAE,KAAK,IAAI;YAAE,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;QAC1F,OAAO,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC;IAC7B,CAAC;IACD,QAAQ;IACR,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,kEAAkE,CAAC,CAAC;IACtF,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC7C,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,0BAA0B,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3E,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,EAAE,CAAC;AAChD,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,MAMrC;IACC,MAAM,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,MAAM,iBAAiB,CAC5D,MAAM,CAAC,MAAM,EACb,MAAM,CAAC,UAAU,EACjB,MAAM,CAAC,IAAI,CACZ,CAAC;IACF,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,aAAa,CAAC,CAAC;IACvE,MAAM,KAAK,GAAG,MAAM,CAAC,YAAY,EAAE,CAAC,WAAW,CAAC,CAAC;IACjD,MAAM,OAAO,GAAG,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;IAC/D,4EAA4E;IAC5E,0CAA0C;IAC1C,OAAO,aAAa,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;AAC5C,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Storage scheme registry (m5-plan WS6).
3
+ *
4
+ * Single source of truth for "database url → open Storage". Callers pass
5
+ * a raw url (possibly a bare path) and get back a live Storage. The
6
+ * SQLite and Postgres adapters register their schemes here; adding a
7
+ * third is a one-liner.
8
+ */
9
+ import type { Storage } from "./types.js";
10
+ /**
11
+ * Normalize a `--database` value. A bare path is treated as SQLite for
12
+ * ergonomics; a scheme (`sqlite:`, `postgres:`, `postgresql:`) passes
13
+ * through unchanged.
14
+ */
15
+ export declare function normalizeDatabaseUrl(url: string): string;
16
+ /**
17
+ * Open storage by url. Dispatches on the scheme and delegates to the
18
+ * matching adapter. Throws on unknown scheme.
19
+ */
20
+ export declare function openStorage(url: string): Promise<Storage>;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Storage scheme registry (m5-plan WS6).
3
+ *
4
+ * Single source of truth for "database url → open Storage". Callers pass
5
+ * a raw url (possibly a bare path) and get back a live Storage. The
6
+ * SQLite and Postgres adapters register their schemes here; adding a
7
+ * third is a one-liner.
8
+ */
9
+ import { postgresAdapter } from "../storage-postgres/adapter.js";
10
+ import { sqliteAdapter } from "../storage-sqlite/adapter.js";
11
+ const ADAPTERS = [sqliteAdapter, postgresAdapter];
12
+ /**
13
+ * Normalize a `--database` value. A bare path is treated as SQLite for
14
+ * ergonomics; a scheme (`sqlite:`, `postgres:`, `postgresql:`) passes
15
+ * through unchanged.
16
+ */
17
+ export function normalizeDatabaseUrl(url) {
18
+ if (url.startsWith("sqlite:") || url.startsWith("postgres:") || url.startsWith("postgresql:")) {
19
+ return url;
20
+ }
21
+ return `sqlite:${url}`;
22
+ }
23
+ /**
24
+ * Open storage by url. Dispatches on the scheme and delegates to the
25
+ * matching adapter. Throws on unknown scheme.
26
+ */
27
+ export async function openStorage(url) {
28
+ const normalized = normalizeDatabaseUrl(url);
29
+ const scheme = normalized.split(":", 1)[0] ?? "";
30
+ // postgresql: is an alias for postgres:
31
+ const canonical = scheme === "postgresql" ? "postgres" : scheme;
32
+ const adapter = ADAPTERS.find((a) => a.scheme === canonical);
33
+ if (!adapter) {
34
+ throw new Error(`unknown database scheme: ${scheme}`);
35
+ }
36
+ return adapter.open({ database: normalized });
37
+ }
38
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/storage/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAG7D,MAAM,QAAQ,GAA8B,CAAC,aAAa,EAAE,eAAe,CAAC,CAAC;AAE7E;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,GAAW;IAC9C,IAAI,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE,CAAC;QAC9F,OAAO,GAAG,CAAC;IACb,CAAC;IACD,OAAO,UAAU,GAAG,EAAE,CAAC;AACzB,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,GAAW;IAC3C,MAAM,UAAU,GAAG,oBAAoB,CAAC,GAAG,CAAC,CAAC;IAC7C,MAAM,MAAM,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IACjD,wCAAwC;IACxC,MAAM,SAAS,GAAG,MAAM,KAAK,YAAY,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC;IAChE,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC;IAC7D,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,4BAA4B,MAAM,EAAE,CAAC,CAAC;IACxD,CAAC;IACD,OAAO,OAAO,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC;AAChD,CAAC"}
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Structured search plan — the kernel/adapter seam for versions_search
3
+ * (design §7.2, m5-plan WS2).
4
+ *
5
+ * The kernel builds a `SearchPlan` from a validated QuerySpec — it
6
+ * parses CEL eagerly (so `filter_invalid` surfaces before storage),
7
+ * resolves per-repo sigils to a list of exclusion sub-clauses, and
8
+ * flattens the actor's read scopes into engine-agnostic regex sources.
9
+ * The adapter compiles this plan into its dialect's SQL: SQLite uses
10
+ * `regexp()` and json_extract; Postgres uses `~` and jsonb operators.
11
+ *
12
+ * Kernel emits no SQL strings.
13
+ */
14
+ import type { CelExpr } from "../kernel/query/ast.js";
15
+ /**
16
+ * A per-repo-group sigil-exclusion sub-clause (§3.5.5). Each entry
17
+ * says: for versions in `repo_ids`, hide paths whose first path
18
+ * segment starts with any of `sigils`. Empty `sigils` = no exclusion
19
+ * for that group; the adapter can skip it.
20
+ */
21
+ export type SigilExclusion = {
22
+ repo_ids: readonly number[];
23
+ sigils: readonly string[];
24
+ };
25
+ /**
26
+ * A per-scope-entry pattern for the read-scope filter (§8.2).
27
+ * `repos` is either the literal `"*"` (dynamic all-repos wildcard) or
28
+ * a resolved list of repo ids the scope binds. `globs` is the
29
+ * gitignore-style pattern list; each pattern is prefixed with `!` for
30
+ * negation (last-match-wins on the resulting list). The compiler
31
+ * turns each pattern into a regex source via kernel/auth/glob.
32
+ */
33
+ export type ScopeGroup = {
34
+ repos: "*" | readonly number[];
35
+ globs: readonly string[];
36
+ };
37
+ /**
38
+ * SearchPlan — the structured input to versions_search.
39
+ *
40
+ * The adapter is responsible for compiling this into engine-specific
41
+ * SQL. Ordering: if `rank` candidate ids are present, adapter must
42
+ * preserve caller-provided order for the intersection; otherwise
43
+ * text-score (if `text`) else `created_at DESC, id DESC`.
44
+ */
45
+ export type SearchPlan = {
46
+ /** Repos to search. Empty → adapter returns []. */
47
+ repo_ids: readonly number[];
48
+ /** Result cap. Adapter enforces LIMIT. */
49
+ limit: number;
50
+ /**
51
+ * Optional FTS text. Adapter applies its dialect's syntax
52
+ * (SQLite: FTS5 MATCH; Postgres: websearch_to_tsquery). Kernel
53
+ * passes the raw user string — the portable subset (bare terms +
54
+ * quoted phrases) is the parity target.
55
+ */
56
+ text?: string;
57
+ /**
58
+ * Parsed CEL AST for the filter, if any. Kernel-side eager parse
59
+ * surfaces `filter_invalid` before it reaches the adapter.
60
+ */
61
+ filter_ast?: CelExpr;
62
+ /** Per-repo sigil exclusion groups. Empty list = no exclusions. */
63
+ sigils: readonly SigilExclusion[];
64
+ /**
65
+ * Read-scope filter (§8.2). One of three modes:
66
+ * • `allow_all` — actor is admin, no filter.
67
+ * • `deny_all` — actor has no scopes at all; adapter must return [].
68
+ * • `groups` — one or more scope entries; adapter ORs them together.
69
+ */
70
+ scope: {
71
+ kind: "allow_all";
72
+ } | {
73
+ kind: "deny_all";
74
+ } | {
75
+ kind: "groups";
76
+ groups: ScopeGroup[];
77
+ };
78
+ /**
79
+ * Optional candidate id whitelist (rank branch, m4-plan §5.1).
80
+ * When present, adapter restricts results to these ids AND returns
81
+ * them in the order given so the kernel's semantic-score sort is stable.
82
+ */
83
+ candidate_ids?: readonly number[];
84
+ /**
85
+ * Optional candidate DOCUMENT-id whitelist (graph read surface,
86
+ * docs/graph-plan.md WS2). When present, the adapter restricts results to
87
+ * live versions whose `document_id` is in this set — the kernel uses it to
88
+ * evaluate scope∧filter visibility over a BFS round's candidate documents
89
+ * in one pass. Unlike `candidate_ids` (version ids, order-significant for
90
+ * rank), this imposes no ordering.
91
+ */
92
+ candidate_document_ids?: readonly number[];
93
+ };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Structured search plan — the kernel/adapter seam for versions_search
3
+ * (design §7.2, m5-plan WS2).
4
+ *
5
+ * The kernel builds a `SearchPlan` from a validated QuerySpec — it
6
+ * parses CEL eagerly (so `filter_invalid` surfaces before storage),
7
+ * resolves per-repo sigils to a list of exclusion sub-clauses, and
8
+ * flattens the actor's read scopes into engine-agnostic regex sources.
9
+ * The adapter compiles this plan into its dialect's SQL: SQLite uses
10
+ * `regexp()` and json_extract; Postgres uses `~` and jsonb operators.
11
+ *
12
+ * Kernel emits no SQL strings.
13
+ */
14
+ export {};
15
+ //# sourceMappingURL=search-plan.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search-plan.js","sourceRoot":"","sources":["../../src/storage/search-plan.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG"}