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.
- package/LICENSE +21 -0
- package/README.md +284 -0
- package/dist/cli/config.d.ts +28 -0
- package/dist/cli/config.js +48 -0
- package/dist/cli/config.js.map +1 -0
- package/dist/cli/exit-codes.d.ts +13 -0
- package/dist/cli/exit-codes.js +39 -0
- package/dist/cli/exit-codes.js.map +1 -0
- package/dist/cli/format.d.ts +22 -0
- package/dist/cli/format.js +148 -0
- package/dist/cli/format.js.map +1 -0
- package/dist/cli/main.d.ts +16 -0
- package/dist/cli/main.js +1518 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/client/kernel-client.d.ts +97 -0
- package/dist/client/kernel-client.js +14 -0
- package/dist/client/kernel-client.js.map +1 -0
- package/dist/client/local.d.ts +26 -0
- package/dist/client/local.js +103 -0
- package/dist/client/local.js.map +1 -0
- package/dist/client/remote-mcp.d.ts +35 -0
- package/dist/client/remote-mcp.js +174 -0
- package/dist/client/remote-mcp.js.map +1 -0
- package/dist/embed/backfill.d.ts +24 -0
- package/dist/embed/backfill.js +33 -0
- package/dist/embed/backfill.js.map +1 -0
- package/dist/embed/chunker.d.ts +31 -0
- package/dist/embed/chunker.js +121 -0
- package/dist/embed/chunker.js.map +1 -0
- package/dist/embed/cmd-hook.d.ts +21 -0
- package/dist/embed/cmd-hook.js +100 -0
- package/dist/embed/cmd-hook.js.map +1 -0
- package/dist/embed/config.d.ts +61 -0
- package/dist/embed/config.js +109 -0
- package/dist/embed/config.js.map +1 -0
- package/dist/embed/hook.d.ts +38 -0
- package/dist/embed/hook.js +56 -0
- package/dist/embed/hook.js.map +1 -0
- package/dist/embed/http-hook.d.ts +13 -0
- package/dist/embed/http-hook.js +39 -0
- package/dist/embed/http-hook.js.map +1 -0
- package/dist/embed/worker.d.ts +62 -0
- package/dist/embed/worker.js +228 -0
- package/dist/embed/worker.js.map +1 -0
- package/dist/fixtures/hwe/characters/albion-ever.md +12 -0
- package/dist/fixtures/hwe/characters/cent.md +11 -0
- package/dist/fixtures/hwe/concepts/cent-demiurge-resonance.md +10 -0
- package/dist/fixtures/hwe/concepts/phase-looper.md +10 -0
- package/dist/fixtures/hwe/entities/demiurge.md +11 -0
- package/dist/fixtures/hwe/entities/monad.md +11 -0
- package/dist/fixtures/hwe/moc/globocorp-network.md +19 -0
- package/dist/fixtures/hwe/organizations/globocorp.md +11 -0
- package/dist/fixtures/hwe/readme.md +24 -0
- package/dist/fixtures/starship/crew/aria-okonkwo.md +14 -0
- package/dist/fixtures/starship/crew/bexley-orr.md +14 -0
- package/dist/fixtures/starship/crew/dax-thorne.md +14 -0
- package/dist/fixtures/starship/crew/isolde-marsh.md +16 -0
- package/dist/fixtures/starship/crew/kestrel-vance.md +15 -0
- package/dist/fixtures/starship/crew/quill-vasquez.md +14 -0
- package/dist/fixtures/starship/crew/soren-halloway.md +16 -0
- package/dist/fixtures/starship/encounters/the-drift-choir.md +14 -0
- package/dist/fixtures/starship/encounters/the-hollow-signal.md +16 -0
- package/dist/fixtures/starship/encounters/the-wandering-buoy.md +14 -0
- package/dist/fixtures/starship/equipment/coolant-loop-b.md +13 -0
- package/dist/fixtures/starship/equipment/emergency-ration-bars.md +12 -0
- package/dist/fixtures/starship/equipment/long-range-sensors.md +13 -0
- package/dist/fixtures/starship/equipment/plasma-manifold-3.md +15 -0
- package/dist/fixtures/starship/equipment/shuttle-corvid.md +13 -0
- package/dist/fixtures/starship/logs/marsh-4419-1.md +13 -0
- package/dist/fixtures/starship/logs/okonkwo-4415-1.md +13 -0
- package/dist/fixtures/starship/logs/orr-4413-1.md +13 -0
- package/dist/fixtures/starship/logs/orr-4420-1.md +12 -0
- package/dist/fixtures/starship/logs/thorne-4413-2.md +13 -0
- package/dist/fixtures/starship/logs/vance-4419-2.md +13 -0
- package/dist/fixtures/starship/misc/the-galley-ficus.md +11 -0
- package/dist/fixtures/starship/missions/the-cinder-run.md +17 -0
- package/dist/fixtures/starship/missions/the-drift-choir.md +17 -0
- package/dist/fixtures/starship/missions/the-hollow-signal.md +17 -0
- package/dist/fixtures/starship/missions/the-silent-beacon.md +17 -0
- package/dist/fixtures/starship/moc/crew.md +19 -0
- package/dist/fixtures/starship/moc/encounters.md +14 -0
- package/dist/fixtures/starship/moc/missions.md +15 -0
- package/dist/fixtures/starship/readme.md +60 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/kernel/auth/glob.d.ts +46 -0
- package/dist/kernel/auth/glob.js +112 -0
- package/dist/kernel/auth/glob.js.map +1 -0
- package/dist/kernel/auth/scope.d.ts +53 -0
- package/dist/kernel/auth/scope.js +83 -0
- package/dist/kernel/auth/scope.js.map +1 -0
- package/dist/kernel/casefold.d.ts +37 -0
- package/dist/kernel/casefold.js +44 -0
- package/dist/kernel/casefold.js.map +1 -0
- package/dist/kernel/constants.d.ts +21 -0
- package/dist/kernel/constants.js +22 -0
- package/dist/kernel/constants.js.map +1 -0
- package/dist/kernel/context.d.ts +70 -0
- package/dist/kernel/context.js +114 -0
- package/dist/kernel/context.js.map +1 -0
- package/dist/kernel/deletion.d.ts +50 -0
- package/dist/kernel/deletion.js +83 -0
- package/dist/kernel/deletion.js.map +1 -0
- package/dist/kernel/diff.d.ts +36 -0
- package/dist/kernel/diff.js +61 -0
- package/dist/kernel/diff.js.map +1 -0
- package/dist/kernel/errors.d.ts +37 -0
- package/dist/kernel/errors.js +55 -0
- package/dist/kernel/errors.js.map +1 -0
- package/dist/kernel/frontmatter-input.d.ts +32 -0
- package/dist/kernel/frontmatter-input.js +85 -0
- package/dist/kernel/frontmatter-input.js.map +1 -0
- package/dist/kernel/graph.d.ts +34 -0
- package/dist/kernel/graph.js +559 -0
- package/dist/kernel/graph.js.map +1 -0
- package/dist/kernel/history.d.ts +74 -0
- package/dist/kernel/history.js +143 -0
- package/dist/kernel/history.js.map +1 -0
- package/dist/kernel/kernel.d.ts +162 -0
- package/dist/kernel/kernel.js +675 -0
- package/dist/kernel/kernel.js.map +1 -0
- package/dist/kernel/path-config.d.ts +101 -0
- package/dist/kernel/path-config.js +171 -0
- package/dist/kernel/path-config.js.map +1 -0
- package/dist/kernel/query/ast.d.ts +24 -0
- package/dist/kernel/query/ast.js +52 -0
- package/dist/kernel/query/ast.js.map +1 -0
- package/dist/kernel/query/cel-parse.d.ts +37 -0
- package/dist/kernel/query/cel-parse.js +88 -0
- package/dist/kernel/query/cel-parse.js.map +1 -0
- package/dist/kernel/query/degrees.d.ts +31 -0
- package/dist/kernel/query/degrees.js +135 -0
- package/dist/kernel/query/degrees.js.map +1 -0
- package/dist/kernel/query/graph-ast.d.ts +51 -0
- package/dist/kernel/query/graph-ast.js +139 -0
- package/dist/kernel/query/graph-ast.js.map +1 -0
- package/dist/kernel/query/query.d.ts +56 -0
- package/dist/kernel/query/query.js +276 -0
- package/dist/kernel/query/query.js.map +1 -0
- package/dist/kernel/validation.d.ts +64 -0
- package/dist/kernel/validation.js +183 -0
- package/dist/kernel/validation.js.map +1 -0
- package/dist/kernel/version-id.d.ts +10 -0
- package/dist/kernel/version-id.js +21 -0
- package/dist/kernel/version-id.js.map +1 -0
- package/dist/kernel/wire.d.ts +148 -0
- package/dist/kernel/wire.js +6 -0
- package/dist/kernel/wire.js.map +1 -0
- package/dist/links/backfill.d.ts +28 -0
- package/dist/links/backfill.js +33 -0
- package/dist/links/backfill.js.map +1 -0
- package/dist/links/extract.d.ts +29 -0
- package/dist/links/extract.js +233 -0
- package/dist/links/extract.js.map +1 -0
- package/dist/links/link-config.d.ts +70 -0
- package/dist/links/link-config.js +107 -0
- package/dist/links/link-config.js.map +1 -0
- package/dist/links/maintain.d.ts +37 -0
- package/dist/links/maintain.js +91 -0
- package/dist/links/maintain.js.map +1 -0
- package/dist/links/repair.d.ts +46 -0
- package/dist/links/repair.js +96 -0
- package/dist/links/repair.js.map +1 -0
- package/dist/links/resolve.d.ts +41 -0
- package/dist/links/resolve.js +121 -0
- package/dist/links/resolve.js.map +1 -0
- package/dist/links/stale.d.ts +32 -0
- package/dist/links/stale.js +73 -0
- package/dist/links/stale.js.map +1 -0
- package/dist/markdown/content-hash.d.ts +34 -0
- package/dist/markdown/content-hash.js +46 -0
- package/dist/markdown/content-hash.js.map +1 -0
- package/dist/markdown/frontmatter.d.ts +69 -0
- package/dist/markdown/frontmatter.js +147 -0
- package/dist/markdown/frontmatter.js.map +1 -0
- package/dist/markdown/hash-backfill.d.ts +22 -0
- package/dist/markdown/hash-backfill.js +43 -0
- package/dist/markdown/hash-backfill.js.map +1 -0
- package/dist/mcp/query-syntax.d.ts +20 -0
- package/dist/mcp/query-syntax.js +194 -0
- package/dist/mcp/query-syntax.js.map +1 -0
- package/dist/mcp/render.d.ts +31 -0
- package/dist/mcp/render.js +110 -0
- package/dist/mcp/render.js.map +1 -0
- package/dist/mcp/server.d.ts +60 -0
- package/dist/mcp/server.js +170 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/tools.d.ts +93 -0
- package/dist/mcp/tools.js +1218 -0
- package/dist/mcp/tools.js.map +1 -0
- package/dist/rest/conditional.d.ts +37 -0
- package/dist/rest/conditional.js +58 -0
- package/dist/rest/conditional.js.map +1 -0
- package/dist/rest/negotiate.d.ts +33 -0
- package/dist/rest/negotiate.js +54 -0
- package/dist/rest/negotiate.js.map +1 -0
- package/dist/rest/routes.d.ts +37 -0
- package/dist/rest/routes.js +744 -0
- package/dist/rest/routes.js.map +1 -0
- package/dist/seed/fixture-seed.d.ts +35 -0
- package/dist/seed/fixture-seed.js +75 -0
- package/dist/seed/fixture-seed.js.map +1 -0
- package/dist/seed/starship-config.d.ts +3 -0
- package/dist/seed/starship-config.js +5 -0
- package/dist/seed/starship-config.js.map +1 -0
- package/dist/server/headers.d.ts +36 -0
- package/dist/server/headers.js +30 -0
- package/dist/server/headers.js.map +1 -0
- package/dist/server/http-error.d.ts +53 -0
- package/dist/server/http-error.js +104 -0
- package/dist/server/http-error.js.map +1 -0
- package/dist/server/serve.d.ts +56 -0
- package/dist/server/serve.js +135 -0
- package/dist/server/serve.js.map +1 -0
- package/dist/shell/audit.d.ts +32 -0
- package/dist/shell/audit.js +28 -0
- package/dist/shell/audit.js.map +1 -0
- package/dist/shell/guard.d.ts +50 -0
- package/dist/shell/guard.js +176 -0
- package/dist/shell/guard.js.map +1 -0
- package/dist/shell/keys.d.ts +36 -0
- package/dist/shell/keys.js +64 -0
- package/dist/shell/keys.js.map +1 -0
- package/dist/shell/login.d.ts +56 -0
- package/dist/shell/login.js +130 -0
- package/dist/shell/login.js.map +1 -0
- package/dist/shell/oidc.d.ts +62 -0
- package/dist/shell/oidc.js +102 -0
- package/dist/shell/oidc.js.map +1 -0
- package/dist/shell/policy.d.ts +100 -0
- package/dist/shell/policy.js +232 -0
- package/dist/shell/policy.js.map +1 -0
- package/dist/shell/proxy-policy.d.ts +34 -0
- package/dist/shell/proxy-policy.js +120 -0
- package/dist/shell/proxy-policy.js.map +1 -0
- package/dist/shell/proxy.d.ts +47 -0
- package/dist/shell/proxy.js +253 -0
- package/dist/shell/proxy.js.map +1 -0
- package/dist/shell/serve.d.ts +86 -0
- package/dist/shell/serve.js +0 -0
- package/dist/shell/serve.js.map +1 -0
- package/dist/shell/stdio.d.ts +55 -0
- package/dist/shell/stdio.js +63 -0
- package/dist/shell/stdio.js.map +1 -0
- package/dist/storage/registry.d.ts +20 -0
- package/dist/storage/registry.js +38 -0
- package/dist/storage/registry.js.map +1 -0
- package/dist/storage/search-plan.d.ts +93 -0
- package/dist/storage/search-plan.js +15 -0
- package/dist/storage/search-plan.js.map +1 -0
- package/dist/storage/types.d.ts +448 -0
- package/dist/storage/types.js +14 -0
- package/dist/storage/types.js.map +1 -0
- package/dist/storage/versions-since.d.ts +72 -0
- package/dist/storage/versions-since.js +92 -0
- package/dist/storage/versions-since.js.map +1 -0
- package/dist/storage-postgres/adapter.d.ts +17 -0
- package/dist/storage-postgres/adapter.js +782 -0
- package/dist/storage-postgres/adapter.js.map +1 -0
- package/dist/storage-postgres/compile-postgres.d.ts +22 -0
- package/dist/storage-postgres/compile-postgres.js +830 -0
- package/dist/storage-postgres/compile-postgres.js.map +1 -0
- package/dist/storage-postgres/errors.d.ts +34 -0
- package/dist/storage-postgres/errors.js +50 -0
- package/dist/storage-postgres/errors.js.map +1 -0
- package/dist/storage-postgres/migrations/0001_init.sql +113 -0
- package/dist/storage-postgres/migrations/0002_content_hash.sql +7 -0
- package/dist/storage-postgres/migrations/index.d.ts +22 -0
- package/dist/storage-postgres/migrations/index.js +70 -0
- package/dist/storage-postgres/migrations/index.js.map +1 -0
- package/dist/storage-sqlite/adapter.d.ts +2 -0
- package/dist/storage-sqlite/adapter.js +688 -0
- package/dist/storage-sqlite/adapter.js.map +1 -0
- package/dist/storage-sqlite/compile-filter.d.ts +41 -0
- package/dist/storage-sqlite/compile-filter.js +881 -0
- package/dist/storage-sqlite/compile-filter.js.map +1 -0
- package/dist/storage-sqlite/compile-sqlite.d.ts +19 -0
- package/dist/storage-sqlite/compile-sqlite.js +176 -0
- package/dist/storage-sqlite/compile-sqlite.js.map +1 -0
- package/dist/storage-sqlite/migrations/0001_init.sql +123 -0
- package/dist/storage-sqlite/migrations/0002_content_hash.sql +7 -0
- package/dist/storage-sqlite/migrations/index.d.ts +6 -0
- package/dist/storage-sqlite/migrations/index.js +41 -0
- package/dist/storage-sqlite/migrations/index.js.map +1 -0
- package/dist/storage-sqlite/vec.d.ts +40 -0
- package/dist/storage-sqlite/vec.js +62 -0
- package/dist/storage-sqlite/vec.js.map +1 -0
- package/dist/sync/cursor.d.ts +36 -0
- package/dist/sync/cursor.js +66 -0
- package/dist/sync/cursor.js.map +1 -0
- package/dist/sync/daemon.d.ts +40 -0
- package/dist/sync/daemon.js +202 -0
- package/dist/sync/daemon.js.map +1 -0
- package/dist/sync/feed.d.ts +38 -0
- package/dist/sync/feed.js +125 -0
- package/dist/sync/feed.js.map +1 -0
- package/dist/sync/fs-store.d.ts +8 -0
- package/dist/sync/fs-store.js +76 -0
- package/dist/sync/fs-store.js.map +1 -0
- package/dist/sync/intrinsics.d.ts +52 -0
- package/dist/sync/intrinsics.js +76 -0
- package/dist/sync/intrinsics.js.map +1 -0
- package/dist/sync/paths.d.ts +38 -0
- package/dist/sync/paths.js +56 -0
- package/dist/sync/paths.js.map +1 -0
- package/dist/sync/push.d.ts +48 -0
- package/dist/sync/push.js +328 -0
- package/dist/sync/push.js.map +1 -0
- package/dist/sync/reconcile.d.ts +54 -0
- package/dist/sync/reconcile.js +252 -0
- package/dist/sync/reconcile.js.map +1 -0
- package/dist/sync/run.d.ts +27 -0
- package/dist/sync/run.js +46 -0
- package/dist/sync/run.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +5 -0
- package/dist/version.js.map +1 -0
- 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"}
|