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,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `history` namespace (sync/history plan §3) — a top-level read surface
|
|
3
|
+
* keyed by position in the version log, spanning documents. `history.since` is
|
|
4
|
+
* the global change feed: it wraps `Storage.versions_since` (the gap-aware
|
|
5
|
+
* walk, §3.2) and enriches each settled row into a `VersionRef` — deriving
|
|
6
|
+
* `op` and resolving `prev_path` — so consumers never parse path sigils.
|
|
7
|
+
*/
|
|
8
|
+
import { decodeVersionId, encodeVersionId } from "./version-id.js";
|
|
9
|
+
/** Default feed page size when a caller omits `limit` (§3.3). */
|
|
10
|
+
export const HISTORY_SINCE_DEFAULT_LIMIT = 500;
|
|
11
|
+
/** Default `history.index` page size when a caller omits `limit` (§3.4). */
|
|
12
|
+
export const HISTORY_INDEX_DEFAULT_LIMIT = 1000;
|
|
13
|
+
/**
|
|
14
|
+
* Safety-window duration (§3.2): a gap's successor visible longer than this is
|
|
15
|
+
* treated as settled (the hole is burned, cross it); younger means the hole may
|
|
16
|
+
* still be committing (truncate before it). ~30s dwarfs any real write-tx.
|
|
17
|
+
*/
|
|
18
|
+
export const HISTORY_SAFETY_WINDOW_MS = 30_000;
|
|
19
|
+
/**
|
|
20
|
+
* Derive the operation a version row represents (§3.3): no prev → create; same
|
|
21
|
+
* path → update; a new path in the system namespace (a `:deleted/…` tombstone)
|
|
22
|
+
* → delete; any other new path → move.
|
|
23
|
+
*/
|
|
24
|
+
export function deriveOp(hasPrev, path, prevPath, isSystemPath) {
|
|
25
|
+
if (!hasPrev)
|
|
26
|
+
return "create";
|
|
27
|
+
if (prevPath === path)
|
|
28
|
+
return "update";
|
|
29
|
+
if (isSystemPath(path))
|
|
30
|
+
return "delete";
|
|
31
|
+
return "move";
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The global change feed. Advances the cursor to the storage safe frontier
|
|
35
|
+
* regardless of how many refs survive the visibility filter, so a caller with
|
|
36
|
+
* narrow scope still makes progress rather than stalling on hidden rows.
|
|
37
|
+
*/
|
|
38
|
+
export async function runHistorySince(input, deps) {
|
|
39
|
+
// "" (or any unparseable cursor) means "from the beginning" → after_id 0.
|
|
40
|
+
const afterId = input.after_version === "" ? 0 : (decodeVersionId(input.after_version) ?? 0);
|
|
41
|
+
const { rows, next_id } = await deps.storage.versions_since({
|
|
42
|
+
after_id: afterId,
|
|
43
|
+
repo_id: input.repo_id,
|
|
44
|
+
limit: input.limit,
|
|
45
|
+
now_ms: input.now_ms,
|
|
46
|
+
window_ms: input.window_ms,
|
|
47
|
+
});
|
|
48
|
+
// Batch-resolve prev paths (both ends of moves/deletes) in one lookup.
|
|
49
|
+
const prevIds = rows.map((r) => r.prev_id).filter((id) => id !== null);
|
|
50
|
+
const prevPaths = prevIds.length > 0
|
|
51
|
+
? await deps.storage.versions_paths_by_ids(prevIds)
|
|
52
|
+
: new Map();
|
|
53
|
+
const refs = [];
|
|
54
|
+
for (const row of rows) {
|
|
55
|
+
const prevPath = row.prev_id === null ? null : (prevPaths.get(row.prev_id) ?? null);
|
|
56
|
+
// Visibility: deliver when the caller can read either endpoint — a delete's
|
|
57
|
+
// tombstone path may be hidden while its prior path is readable, and vice
|
|
58
|
+
// versa. Absent scope (canRead always true) sees everything.
|
|
59
|
+
const visible = deps.canRead(row.repo_id, row.path) ||
|
|
60
|
+
(prevPath !== null && deps.canRead(row.repo_id, prevPath));
|
|
61
|
+
if (!visible)
|
|
62
|
+
continue;
|
|
63
|
+
refs.push(toRef(row, prevPath, deps));
|
|
64
|
+
}
|
|
65
|
+
const nextSince = next_id > afterId ? encodeVersionId(next_id) : input.after_version;
|
|
66
|
+
return { refs, next_since: nextSince };
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Page the live set as of a safe head `R` (§3.4). On the first call (no
|
|
70
|
+
* `through_version`) the server captures `R = versions_safe_head(...)` and
|
|
71
|
+
* echoes it; subsequent pages pass it back. Keyset over current-version id in
|
|
72
|
+
* `(after, R]`, never offset — a document updated mid-pagination gets a new id
|
|
73
|
+
* > R, drops out of the remaining pages, and is delivered by
|
|
74
|
+
* `history.since(R)` afterward. System/hidden paths and out-of-scope rows are
|
|
75
|
+
* dropped here (the storage page is lightweight and unfiltered), so a raw page
|
|
76
|
+
* may yield fewer visible items than `limit`; we keep pulling storage pages
|
|
77
|
+
* until we fill `limit` or reach R.
|
|
78
|
+
*/
|
|
79
|
+
export async function runHistoryIndex(input, deps) {
|
|
80
|
+
const through = input.through_version !== undefined && input.through_version !== ""
|
|
81
|
+
? (decodeVersionId(input.through_version) ?? 0)
|
|
82
|
+
: await deps.storage.versions_safe_head(input.now_ms, input.window_ms);
|
|
83
|
+
const throughVersion = encodeVersionId(through);
|
|
84
|
+
let afterId = input.after_version !== undefined && input.after_version !== ""
|
|
85
|
+
? (decodeVersionId(input.after_version) ?? 0)
|
|
86
|
+
: 0;
|
|
87
|
+
const items = [];
|
|
88
|
+
let exhausted = false;
|
|
89
|
+
while (items.length < input.limit && !exhausted) {
|
|
90
|
+
const rows = await deps.storage.versions_live_index({
|
|
91
|
+
repo_id: input.repo_id,
|
|
92
|
+
through_id: through,
|
|
93
|
+
after_id: afterId,
|
|
94
|
+
// Over-fetch a little so heavy exclusion doesn't cause many round-trips.
|
|
95
|
+
limit: input.limit,
|
|
96
|
+
});
|
|
97
|
+
if (rows.length === 0) {
|
|
98
|
+
exhausted = true;
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
for (const r of rows) {
|
|
102
|
+
afterId = r.id;
|
|
103
|
+
if (deps.isExcluded(r.path))
|
|
104
|
+
continue;
|
|
105
|
+
if (!deps.canRead(r.path))
|
|
106
|
+
continue;
|
|
107
|
+
items.push({
|
|
108
|
+
path: r.path,
|
|
109
|
+
version_id: encodeVersionId(r.id),
|
|
110
|
+
content_hash: r.content_hash ?? "",
|
|
111
|
+
});
|
|
112
|
+
if (items.length === input.limit)
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
// A short storage page means we've reached R's boundary.
|
|
116
|
+
if (rows.length < input.limit)
|
|
117
|
+
exhausted = true;
|
|
118
|
+
}
|
|
119
|
+
// More live rows may remain ≤ R only if the page filled AND we haven't yet
|
|
120
|
+
// consumed up to R itself. Reaching R (afterId === through) means the keyset
|
|
121
|
+
// window is exhausted even when the visible page happened to fill exactly.
|
|
122
|
+
const hasMore = !exhausted && items.length === input.limit && afterId < through;
|
|
123
|
+
return {
|
|
124
|
+
items,
|
|
125
|
+
through_version: throughVersion,
|
|
126
|
+
...(hasMore ? { next_after_version: encodeVersionId(afterId) } : {}),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function toRef(row, prevPath, deps) {
|
|
130
|
+
return {
|
|
131
|
+
version_id: encodeVersionId(row.id),
|
|
132
|
+
prev_version_id: row.prev_id === null ? null : encodeVersionId(row.prev_id),
|
|
133
|
+
repo: deps.repoSlug(row.repo_id),
|
|
134
|
+
path: row.path,
|
|
135
|
+
prev_path: prevPath,
|
|
136
|
+
// content_hash is always populated post-M1; pre-backfill rows (null) would
|
|
137
|
+
// read as an empty string, which a consumer treats as "unknown, fetch".
|
|
138
|
+
content_hash: row.content_hash ?? "",
|
|
139
|
+
op: deriveOp(row.prev_id !== null, row.path, prevPath, deps.isSystemPath),
|
|
140
|
+
created_at: row.created_at,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=history.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history.js","sourceRoot":"","sources":["../../src/kernel/history.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AASnE,iEAAiE;AACjE,MAAM,CAAC,MAAM,2BAA2B,GAAG,GAAG,CAAC;AAE/C,4EAA4E;AAC5E,MAAM,CAAC,MAAM,2BAA2B,GAAG,IAAI,CAAC;AAEhD;;;;GAIG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAC;AAE/C;;;;GAIG;AACH,MAAM,UAAU,QAAQ,CACtB,OAAgB,EAChB,IAAY,EACZ,QAAuB,EACvB,YAAoC;IAEpC,IAAI,CAAC,OAAO;QAAE,OAAO,QAAQ,CAAC;IAC9B,IAAI,QAAQ,KAAK,IAAI;QAAE,OAAO,QAAQ,CAAC;IACvC,IAAI,YAAY,CAAC,IAAI,CAAC;QAAE,OAAO,QAAQ,CAAC;IACxC,OAAO,MAAM,CAAC;AAChB,CAAC;AAoBD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,KAAwB,EACxB,IAAsB;IAEtB,0EAA0E;IAC1E,MAAM,OAAO,GAAG,KAAK,CAAC,aAAa,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;IAE7F,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC;QAC1D,QAAQ,EAAE,OAAO;QACjB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,KAAK,EAAE,KAAK,CAAC,K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GAAG,CAAC,OAAO,CAAC;QAChC,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,SAAS,EAAE,QAAQ;QACnB,2EAA2E;QAC3E,wEAAwE;QACxE,YAAY,EAAE,GAAG,CAAC,YAAY,IAAI,EAAE;QACpC,EAAE,EAAE,QAAQ,CAAC,GAAG,CAAC,OAAO,KAAK,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,YAAY,CAAC;QACzE,UAAU,EAAE,GAAG,CAAC,UAAU;KAC3B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kernel — the only place the read model, error catalog, and slug↔id
|
|
3
|
+
* translation live. Surfaces (CLI, MCP, REST) call these methods and never
|
|
4
|
+
* touch the storage layer directly.
|
|
5
|
+
*
|
|
6
|
+
* No-auth model (design §8, noauth plan): the kernel trusts every caller.
|
|
7
|
+
* Every op takes a uniform `ctx: CallContext` first parameter — a plain
|
|
8
|
+
* caller-supplied value, not a resolved identity. Writes stamp `ctx.author`
|
|
9
|
+
* (default "mrplex"); reads narrow visibility through `ctx.scope` when present.
|
|
10
|
+
*
|
|
11
|
+
* All kernel methods are async (m5-plan WS1). SQLite adapter is
|
|
12
|
+
* internally synchronous so calls resolve on the next microtask; the
|
|
13
|
+
* async signature is honesty about the Postgres adapter and the
|
|
14
|
+
* embedding hook.
|
|
15
|
+
*/
|
|
16
|
+
import { type LinkConfig, type LinkConfigOverride } from "../links/link-config.js";
|
|
17
|
+
import type { Storage } from "../storage/types.js";
|
|
18
|
+
import { type CallContext } from "./context.js";
|
|
19
|
+
import { type UnifiedDiff } from "./diff.js";
|
|
20
|
+
import { type FrontmatterInput } from "./frontmatter-input.js";
|
|
21
|
+
import { type PathConfig, type PathConfigOverride } from "./path-config.js";
|
|
22
|
+
import { type QuerySpec } from "./query/query.js";
|
|
23
|
+
import type { DocGetManyResult, GraphResult, GraphSpec, HistoryIndexPage, HistorySincePage, PathWarning, QueryHit, Repo, Version } from "./wire.js";
|
|
24
|
+
export type HistoryOptions = {
|
|
25
|
+
limit?: number;
|
|
26
|
+
before?: string;
|
|
27
|
+
};
|
|
28
|
+
export type SetPathConfigResult = {
|
|
29
|
+
repo: Repo;
|
|
30
|
+
warnings: PathWarning[];
|
|
31
|
+
};
|
|
32
|
+
export type LinksBackfillResult = {
|
|
33
|
+
documents: number;
|
|
34
|
+
edges: number;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Result of `repos.set_link_config`: the updated repo plus the re-extraction
|
|
38
|
+
* report. A config change makes the link index stale, so the op re-extracts
|
|
39
|
+
* the whole repo under the new config in the same call (§11.2 "Config change
|
|
40
|
+
* ⇒ re-extraction") — the returned `reindexed` counts document it.
|
|
41
|
+
*/
|
|
42
|
+
export type SetLinkConfigResult = {
|
|
43
|
+
repo: Repo;
|
|
44
|
+
reindexed: LinksBackfillResult;
|
|
45
|
+
};
|
|
46
|
+
/** A stale link on the wire — paths, never internal document ids. */
|
|
47
|
+
export type StaleLinkWire = {
|
|
48
|
+
repo: string;
|
|
49
|
+
source_path: string;
|
|
50
|
+
ord: number;
|
|
51
|
+
written: string;
|
|
52
|
+
current: string;
|
|
53
|
+
};
|
|
54
|
+
export type RepairResult = {
|
|
55
|
+
dry_run: boolean;
|
|
56
|
+
repaired: {
|
|
57
|
+
path: string;
|
|
58
|
+
edges: number;
|
|
59
|
+
}[];
|
|
60
|
+
skipped: {
|
|
61
|
+
path: string;
|
|
62
|
+
reason: string;
|
|
63
|
+
}[];
|
|
64
|
+
};
|
|
65
|
+
/** Hard cap on named paths per `docs.get_many` call (after dedupe). */
|
|
66
|
+
export declare const GET_MANY_MAX_PATHS = 50;
|
|
67
|
+
export type Kernel = {
|
|
68
|
+
repos: {
|
|
69
|
+
list(ctx: CallContext, opts?: {
|
|
70
|
+
include_system?: boolean;
|
|
71
|
+
}): Promise<Repo[]>;
|
|
72
|
+
get(ctx: CallContext, slug: string): Promise<Repo>;
|
|
73
|
+
create(ctx: CallContext, slug: string): Promise<Repo>;
|
|
74
|
+
rename(ctx: CallContext, slug: string, new_slug: string): Promise<Repo>;
|
|
75
|
+
delete(ctx: CallContext, slug: string): Promise<Repo>;
|
|
76
|
+
set_path_config(ctx: CallContext, slug: string, config: PathConfigOverride | null): Promise<SetPathConfigResult>;
|
|
77
|
+
set_link_config(ctx: CallContext, slug: string, config: LinkConfigOverride | null): Promise<SetLinkConfigResult>;
|
|
78
|
+
};
|
|
79
|
+
docs: {
|
|
80
|
+
get(ctx: CallContext, repo: string, path: string): Promise<Version>;
|
|
81
|
+
get_many(ctx: CallContext, repo: string, paths: string[]): Promise<DocGetManyResult>;
|
|
82
|
+
get_version(ctx: CallContext, repo: string, version_id: string): Promise<Version>;
|
|
83
|
+
history(ctx: CallContext, repo: string, path: string, opts?: HistoryOptions): Promise<Version[]>;
|
|
84
|
+
diff(ctx: CallContext, repo: string, path: string, from_version_id: string, to_version_id: string): Promise<UnifiedDiff>;
|
|
85
|
+
create(ctx: CallContext, repo: string, path: string, input: FrontmatterInput & {
|
|
86
|
+
body: string;
|
|
87
|
+
}): Promise<Version>;
|
|
88
|
+
put(ctx: CallContext, repo: string, prev_version_id: string, path: string, input: Partial<FrontmatterInput> & {
|
|
89
|
+
body?: string;
|
|
90
|
+
}): Promise<Version>;
|
|
91
|
+
delete(ctx: CallContext, repo: string, prev_version_id: string): Promise<Version>;
|
|
92
|
+
};
|
|
93
|
+
links: {
|
|
94
|
+
/** Rebuild the link index for a repo (backfill / config-change). */
|
|
95
|
+
backfill(ctx: CallContext, repo: string): Promise<LinksBackfillResult>;
|
|
96
|
+
/** List live docs whose written link text is stale vs. the target's path. */
|
|
97
|
+
stale(ctx: CallContext, repo: string): Promise<StaleLinkWire[]>;
|
|
98
|
+
/** Rewrite stale link text as optimistic docs.put; dry_run plans only. */
|
|
99
|
+
repair(ctx: CallContext, repo: string, opts?: {
|
|
100
|
+
dry_run?: boolean;
|
|
101
|
+
}): Promise<RepairResult>;
|
|
102
|
+
};
|
|
103
|
+
query(ctx: CallContext, spec: QuerySpec): Promise<QueryHit[]>;
|
|
104
|
+
/** Neighborhood expansion over the links index (docs/graph-plan.md). */
|
|
105
|
+
graph(ctx: CallContext, spec: GraphSpec): Promise<GraphResult>;
|
|
106
|
+
/** Change-log read surface keyed by version-log position (sync/history §3). */
|
|
107
|
+
history: {
|
|
108
|
+
/** The global change feed — the longest gap-free run after the cursor. */
|
|
109
|
+
since(ctx: CallContext, input: HistorySinceQuery): Promise<HistorySincePage>;
|
|
110
|
+
/** Page the live set as of a safe head R (startup reconciliation). */
|
|
111
|
+
index(ctx: CallContext, input: HistoryIndexQuery): Promise<HistoryIndexPage>;
|
|
112
|
+
/** Scoped, document-spanning history walk — subsumes docs.history (§3.5). */
|
|
113
|
+
list(ctx: CallContext, input: HistoryListQuery): Promise<Version[]>;
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
/** Public input to `history.since` (§3.3). `repo` is an optional slug filter. */
|
|
117
|
+
export type HistorySinceQuery = {
|
|
118
|
+
after_version: string;
|
|
119
|
+
repo?: string;
|
|
120
|
+
limit?: number;
|
|
121
|
+
};
|
|
122
|
+
/** Public input to `history.index` (§3.4). `repo` is required (per-repo scan). */
|
|
123
|
+
export type HistoryIndexQuery = {
|
|
124
|
+
repo: string;
|
|
125
|
+
through_version?: string;
|
|
126
|
+
after_version?: string;
|
|
127
|
+
limit?: number;
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Public input to `history.list` (§3.5). `path` is a glob (a single literal
|
|
131
|
+
* path is the old `docs.history`); omitted = the whole repo. `ever` includes
|
|
132
|
+
* documents that once matched (moved-away / deleted). `since`/`until` are
|
|
133
|
+
* opaque version-id bounds; `order` defaults to newest-first (presentation).
|
|
134
|
+
*/
|
|
135
|
+
export type HistoryListQuery = {
|
|
136
|
+
repo: string;
|
|
137
|
+
path?: string;
|
|
138
|
+
ever?: boolean;
|
|
139
|
+
since?: string;
|
|
140
|
+
until?: string;
|
|
141
|
+
order?: "asc" | "desc";
|
|
142
|
+
limit?: number;
|
|
143
|
+
};
|
|
144
|
+
export type KernelConfig = {
|
|
145
|
+
storage: Storage;
|
|
146
|
+
serverPathConfig?: PathConfig;
|
|
147
|
+
/** Server-level link-extraction config (§11.2). Defaults to hardcoded. */
|
|
148
|
+
serverLinkConfig?: LinkConfig;
|
|
149
|
+
/**
|
|
150
|
+
* M4 write-time hook: called with the new version's storage id after
|
|
151
|
+
* every committed create / put / delete. Awaited in-line so a throw
|
|
152
|
+
* from the enqueue path fails the kernel call. In practice the
|
|
153
|
+
* worker's backlog_enqueue is one cheap UPSERT and doesn't throw.
|
|
154
|
+
*/
|
|
155
|
+
onVersionCommitted?: (version_id: number) => Promise<void> | void;
|
|
156
|
+
queryEmbed?: (semantic: string) => Promise<{
|
|
157
|
+
vector: number[];
|
|
158
|
+
model: string;
|
|
159
|
+
dim: number;
|
|
160
|
+
}>;
|
|
161
|
+
};
|
|
162
|
+
export declare function createKernel(config: KernelConfig | Storage): Kernel;
|