@omgbase/core 0.28.0 → 0.29.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 (71) hide show
  1. package/dist/src/core/read/document.d.ts +11 -10
  2. package/dist/src/core/read/document.js +12 -11
  3. package/dist/src/core/read/nodes.d.ts +10 -10
  4. package/dist/src/core/read/nodes.js +11 -11
  5. package/dist/src/core/read/reader.d.ts +37 -24
  6. package/dist/src/core/read/reader.js +44 -31
  7. package/dist/src/graph/history.d.ts +25 -22
  8. package/dist/src/graph/history.js +17 -17
  9. package/dist/src/graph/inbound-links.d.ts +7 -7
  10. package/dist/src/graph/inbound-links.js +7 -7
  11. package/dist/src/graph/link-health.d.ts +9 -9
  12. package/dist/src/graph/link-health.js +9 -9
  13. package/dist/src/graph/links.d.ts +3 -3
  14. package/dist/src/graph/links.js +4 -4
  15. package/dist/src/mcp/arguments.d.ts +10 -3
  16. package/dist/src/mcp/arguments.js +32 -9
  17. package/dist/src/mcp/errors.d.ts +1 -1
  18. package/dist/src/mcp/graph.d.ts +22 -22
  19. package/dist/src/mcp/graph.js +53 -46
  20. package/dist/src/mcp/reference.d.ts +29 -1
  21. package/dist/src/mcp/reference.js +350 -222
  22. package/dist/src/mcp/server.d.ts +9 -0
  23. package/dist/src/mcp/server.js +169 -107
  24. package/dist/src/mutate/apply.d.ts +6 -6
  25. package/dist/src/mutate/apply.js +1 -1
  26. package/dist/src/mutate/canonical.d.ts +1 -1
  27. package/dist/src/mutate/canonical.js +2 -2
  28. package/dist/src/mutate/commit.d.ts +3 -3
  29. package/dist/src/mutate/commit.js +4 -4
  30. package/dist/src/mutate/docs.d.ts +1 -1
  31. package/dist/src/mutate/docs.js +8 -8
  32. package/dist/src/mutate/effects.d.ts +17 -17
  33. package/dist/src/mutate/effects.js +113 -113
  34. package/dist/src/mutate/macros.d.ts +5 -5
  35. package/dist/src/mutate/macros.js +1 -1
  36. package/dist/src/mutate/materialize.js +2 -2
  37. package/dist/src/mutate/ops.js +2 -2
  38. package/dist/src/mutate/opset.d.ts +7 -7
  39. package/dist/src/mutate/plan-update.js +2 -2
  40. package/dist/src/mutate/plan.d.ts +8 -8
  41. package/dist/src/mutate/plan.js +25 -25
  42. package/dist/src/mutate/select.d.ts +4 -4
  43. package/dist/src/mutate/select.js +52 -52
  44. package/dist/src/mutate/sugar.d.ts +10 -10
  45. package/dist/src/mutate/sugar.js +21 -21
  46. package/dist/src/oqx-js/context.d.ts +8 -4
  47. package/dist/src/oqx-js/context.js +206 -189
  48. package/dist/src/oqx-js/names.d.ts +28 -17
  49. package/dist/src/oqx-js/names.js +115 -78
  50. package/dist/src/oqx-js/planner.d.ts +4 -8
  51. package/dist/src/oqx-js/planner.js +6 -10
  52. package/dist/src/oqx-js/root-row.d.ts +6 -5
  53. package/dist/src/oqx-js/root-row.js +15 -16
  54. package/dist/src/oqx-js/run.d.ts +18 -17
  55. package/dist/src/oqx-js/run.js +57 -54
  56. package/dist/src/oqx-js/sql/translate.d.ts +5 -5
  57. package/dist/src/oqx-js/sql/translate.js +162 -161
  58. package/dist/src/oqx-js/store-index.d.ts +1 -1
  59. package/dist/src/oqx-js/store-index.js +28 -30
  60. package/dist/src/search/resolve.d.ts +2 -2
  61. package/dist/src/search/resolve.js +1 -1
  62. package/dist/src/search/rrf.js +2 -2
  63. package/dist/src/search/text.d.ts +5 -5
  64. package/dist/src/search/text.js +2 -2
  65. package/dist/src/spec-versions.d.ts +6 -6
  66. package/dist/src/spec-versions.js +6 -6
  67. package/dist/src/surface-paths.d.ts +18 -17
  68. package/dist/src/surface-paths.js +23 -21
  69. package/dist/src/sync/admin.d.ts +2 -2
  70. package/dist/src/sync/admin.js +1 -1
  71. package/package.json +1 -1
@@ -68,15 +68,15 @@ export interface ApplyRequest {
68
68
  export interface OpResult {
69
69
  ids: string[];
70
70
  }
71
- /** One touched document in an apply result (spec/mutate §4, 2.0): its row
72
- * attributes `id`, `path` (the storage form here; the surface roots it) and
73
- * `hash` — the hex sha256 of the rendered bytes, i.e. the hash the committed
71
+ /** One touched document in an apply result (spec/mutate §4, 2.0; 4.0 "underscore = engine"): its row
72
+ * attributes `_id`, `_path` (the storage form here; the surface roots it) and
73
+ * `_hash` — the hex sha256 of the rendered bytes, i.e. the hash the committed
74
74
  * revision carries (a dry run reports the hash it would carry). The same
75
75
  * three keys a `changes_since` revision carries. */
76
76
  export interface ApplyRevision {
77
- id: string;
78
- path: string;
79
- hash: string;
77
+ _id: string;
78
+ _path: string;
79
+ _hash: string;
80
80
  }
81
81
  export interface ApplyResult {
82
82
  results: OpResult[];
@@ -265,7 +265,7 @@ export class ChangesetPlanner {
265
265
  // preconditions and its ingest is guarded by `path_taken` (`base: null`).
266
266
  const base = this.bases.get(docId) ?? null;
267
267
  diffs[d.path] = { before: this.before.get(docId) ?? "", after };
268
- revisions.push({ id: docId, path: d.path, hash: sha256(after).toString("hex") });
268
+ revisions.push({ _id: docId, _path: d.path, _hash: sha256(after).toString("hex") });
269
269
  if (base)
270
270
  preconditions.push({ id: docId, ...base });
271
271
  effects.push({ kind: "ingest_known", docId, path: d.path, rendered: after, mutDoc: d, priorIds: this.priorIds.get(docId) ?? new Set(), base });
@@ -19,7 +19,7 @@ export interface FixRequest {
19
19
  export declare function fixRequest(req: FixRequest): string;
20
20
  /** The `fix` naming another tool: `<tool> <canonical args>`. */
21
21
  export declare function fixTool(tool: string, args: unknown): string;
22
- /** The selector that names exactly one row: the request narrowed to `from <root> where id == "<id>"` with `expect.max: 1` (the fix of a cross-hit collision or an ambiguous target under a selector). */
22
+ /** The selector that names exactly one row: the request narrowed to `from <root> where _id == "<id>"` with `expect.max: 1` (the fix of a cross-hit collision or an ambiguous target under a selector). */
23
23
  export declare function narrowedTo(root: "docs" | "blocks" | "nodes", id: string): string;
24
24
  /** The root a row id belongs to, by its prefix (`d_` / `b_` / `n_`). */
25
25
  export declare function rootOfId(id: string): "docs" | "blocks" | "nodes";
@@ -110,9 +110,9 @@ export function fixRequest(req) {
110
110
  export function fixTool(tool, args) {
111
111
  return `${tool} ${canonicalJson(args)}`;
112
112
  }
113
- /** The selector that names exactly one row: the request narrowed to `from <root> where id == "<id>"` with `expect.max: 1` (the fix of a cross-hit collision or an ambiguous target under a selector). */
113
+ /** The selector that names exactly one row: the request narrowed to `from <root> where _id == "<id>"` with `expect.max: 1` (the fix of a cross-hit collision or an ambiguous target under a selector). */
114
114
  export function narrowedTo(root, id) {
115
- return `from ${root} where id == ${JSON.stringify(id)}`;
115
+ return `from ${root} where _id == ${JSON.stringify(id)}`;
116
116
  }
117
117
  /** The root a row id belongs to, by its prefix (`d_` / `b_` / `n_`). */
118
118
  export function rootOfId(id) {
@@ -9,8 +9,8 @@ import { type MutDoc } from "./tree.js";
9
9
  * when the row has none) as one `SELECT` read them at plan time. Invariant I3
10
10
  * (spec/store §8) makes `current_rev` the version vector of every live block,
11
11
  * so the commit need not re-read blocks: a block cannot change without a new
12
- * revision. The same triple the opset precondition `{ id, path, base_revision,
13
- * hash }` freezes. */
12
+ * revision. The same triple the opset precondition `{ _id, _path, base_revision,
13
+ * _hash }` freezes. */
14
14
  export interface DocBase {
15
15
  path: string;
16
16
  currentRev: string | null;
@@ -140,7 +140,7 @@ export interface CommitTargets {
140
140
  * Commit `effects` as one request under `head` at `ts`. Throws `sync_conflict`
141
141
  * (retriable) when a document changed on disk — after ingesting those bytes as
142
142
  * an `observed` commit so a retry sees them — `stale_plan` (retriable, `{ doc,
143
- * expected_revision, current: { revision, hash } }`) when a document's row
143
+ * expected_revision, current: { revision, _hash } }`) when a document's row
144
144
  * moved since the plan, `doc_missing` / `path_taken` per effect, and otherwise
145
145
  * returns the shared commit id with the ingest results. The caller holds the
146
146
  * writer lock when it has a workspace.
@@ -17,7 +17,7 @@ export function readDocBase(db, docId) {
17
17
  * Commit `effects` as one request under `head` at `ts`. Throws `sync_conflict`
18
18
  * (retriable) when a document changed on disk — after ingesting those bytes as
19
19
  * an `observed` commit so a retry sees them — `stale_plan` (retriable, `{ doc,
20
- * expected_revision, current: { revision, hash } }`) when a document's row
20
+ * expected_revision, current: { revision, _hash } }`) when a document's row
21
21
  * moved since the plan, `doc_missing` / `path_taken` per effect, and otherwise
22
22
  * returns the shared commit id with the ingest results. The caller holds the
23
23
  * writer lock when it has a workspace.
@@ -261,7 +261,7 @@ function validate(db, repoId, effects, onDisk) {
261
261
  throw new MutationError("stale_plan", `document ${docId} changed since the request was planned; re-plan`, {
262
262
  doc: docId,
263
263
  expected_revision: expected.currentRev,
264
- current: { revision: row.currentRev, hash: row.fileHash },
264
+ current: { revision: row.currentRev, _hash: row.fileHash },
265
265
  retriable: true,
266
266
  });
267
267
  }
@@ -323,9 +323,9 @@ function movePath(db, e) {
323
323
  db.prepare("UPDATE edges SET dst_node = ? WHERE dst_node = ? AND to_commit IS NULL AND src_doc != ?").run(phantom, e.docId, e.docId);
324
324
  const selfEdge = db.prepare("UPDATE edges SET dst_node = ? WHERE dst_node = ? AND to_commit IS NULL AND src_doc = ? AND src_block = ? AND anchor IS ?");
325
325
  for (const l of e.inbound) {
326
- if (l.doc_id !== e.docId || l.block_id === null)
326
+ if (l._doc_id !== e.docId || l._block_id === null)
327
327
  continue;
328
- selfEdge.run(phantom, e.docId, e.docId, l.block_id, l.anchor);
328
+ selfEdge.run(phantom, e.docId, e.docId, l._block_id, l._anchor);
329
329
  affected.add(e.docId);
330
330
  }
331
331
  for (const d of affected)
@@ -8,7 +8,7 @@ export declare function canonicalDocPath(path: string): string;
8
8
  * (spec/mutate §6 `docs_create`): the body with a trailing `\n` ensured; a
9
9
  * non-empty frontmatter mapping becomes `---\n<yaml>\n---\n` followed by a
10
10
  * blank line unless the body already starts with one. The effect planner's
11
- * `set frontmatter.<k>` composes through this same function (§11.3), so its
11
+ * `set _frontmatter.<k>` composes through this same function (§11.3), so its
12
12
  * bytes equal `docs_set_meta`'s for the same patch. */
13
13
  export declare function composeFile(markdown: string, frontmatter?: Record<string, unknown>): string;
14
14
  /**
@@ -7,7 +7,7 @@ import { retargetLinksInRaw } from "../graph/inbound-links.js";
7
7
  // module held `docsCreate` / `docsMove` / `docsDelete` / `docsSetMeta`, library
8
8
  // functions that composed the internal commit effects themselves; since 3.0 the
9
9
  // operations are the effect builders of `sugar.ts` (`create`, `move document`,
10
- // `remove document`, `set`/`unset frontmatter.<k>`) planned and executed by the
10
+ // `remove document`, `set`/`unset _frontmatter.<k>`) planned and executed by the
11
11
  // Effect layer (`plan.ts`), and what remains here is what the planner's
12
12
  // lowerings share with them: the path canonicalization, the file composition,
13
13
  // the parse of a created document, the inbound-link retarget plan and the
@@ -23,7 +23,7 @@ export function canonicalDocPath(path) {
23
23
  * (spec/mutate §6 `docs_create`): the body with a trailing `\n` ensured; a
24
24
  * non-empty frontmatter mapping becomes `---\n<yaml>\n---\n` followed by a
25
25
  * blank line unless the body already starts with one. The effect planner's
26
- * `set frontmatter.<k>` composes through this same function (§11.3), so its
26
+ * `set _frontmatter.<k>` composes through this same function (§11.3), so its
27
27
  * bytes equal `docs_set_meta`'s for the same patch. */
28
28
  export function composeFile(markdown, frontmatter) {
29
29
  const body = markdown.endsWith("\n") || markdown.length === 0 ? markdown : markdown + "\n";
@@ -69,8 +69,8 @@ export function parseNewDoc(symbol, path, source) {
69
69
  export function planInboundRetarget(store, docId, fromPath, toRel, inbound) {
70
70
  const byBlock = new Map();
71
71
  for (const l of inbound)
72
- if (l.block_id !== null && !byBlock.has(l.block_id))
73
- byBlock.set(l.block_id, l);
72
+ if (l._block_id !== null && !byBlock.has(l._block_id))
73
+ byBlock.set(l._block_id, l);
74
74
  // A container's raw includes its children's raw, so a link inside a list item
75
75
  // is reported for BOTH the list and the item. Rewrite the deepest block only:
76
76
  // updating the container would re-parse (and re-identify) its children, and
@@ -99,17 +99,17 @@ export function planInboundRetarget(store, docId, fromPath, toRel, inbound) {
99
99
  // Match against the directory the link was RESOLVED in (the source's path at
100
100
  // extraction time); write relative forms against the source's CURRENT
101
101
  // directory — they differ only for links inside the moved doc itself.
102
- const writeDir = src.doc_id === docId ? dirOf(toRel) : dirOf(src.path);
103
- const newRaw = retargetLinksInRaw(row.bytes.toString("utf8"), dirOf(src.path), writeDir, fromPath, toRel);
102
+ const writeDir = src._doc_id === docId ? dirOf(toRel) : dirOf(src._path);
103
+ const newRaw = retargetLinksInRaw(row.bytes.toString("utf8"), dirOf(src._path), writeDir, fromPath, toRel);
104
104
  if (newRaw === null)
105
105
  continue;
106
106
  ops.push({ op: "update", block: blockId, markdown: newRaw, expect: { content_hash: row.raw_hash.toString("hex") } });
107
107
  blocks.push(blockId);
108
- docs.add(src.doc_id);
108
+ docs.add(src._doc_id);
109
109
  }
110
110
  // Containers whose rewritten child covered them count as rewritten too.
111
111
  const rewritten = new Set([...blocks, ...containers]);
112
- const dangling = inbound.filter((l) => l.block_id === null || !rewritten.has(l.block_id));
112
+ const dangling = inbound.filter((l) => l._block_id === null || !rewritten.has(l._block_id));
113
113
  return { ops, blocks, docs: [...docs], dangling };
114
114
  }
115
115
  /** Split a file's bytes into (frontmatter object, body markdown) with
@@ -14,20 +14,20 @@ import { type FixRequest } from "./canonical.js";
14
14
  * symbol table decides when the effect is resolved; it never reaches a resolved effect. */
15
15
  export type EffectTarget = {
16
16
  kind: "document";
17
- id?: string;
18
- path?: string;
17
+ _id?: string;
18
+ _path?: string;
19
19
  } | {
20
20
  kind: "block";
21
- id: string;
21
+ _id: string;
22
22
  } | {
23
23
  kind: "node";
24
- id: string;
24
+ _id: string;
25
25
  } | {
26
26
  kind: "section";
27
27
  heading_id: string;
28
28
  } | {
29
29
  kind: "symbol";
30
- id: string;
30
+ _id: string;
31
31
  };
32
32
  export type EffectAt = At;
33
33
  /** Guards: the kernel's two CAS fields plus the document's `current_rev` at plan time. */
@@ -100,17 +100,17 @@ export declare const EFFECT_OPS: readonly ["create", "insert", "set", "unset", "
100
100
  /** `$new.<n>`: an identity an earlier effect of the same request creates (§11.1). */
101
101
  export declare const NEW_SYMBOL_RE: RegExp;
102
102
  export declare function isNewSymbol(s: string): boolean;
103
- /** A target with its document resolved to `{ id, path }` (path in the storage form; a `$new.n` document keeps its symbol). */
103
+ /** A target with its document resolved to `{ _id, _path }` (path in the storage form; a `$new.n` document keeps its symbol). */
104
104
  export type ResolvedTarget = {
105
105
  kind: "document";
106
- id: string;
107
- path: string;
106
+ _id: string;
107
+ _path: string;
108
108
  } | {
109
109
  kind: "block";
110
- id: string;
110
+ _id: string;
111
111
  } | {
112
112
  kind: "node";
113
- id: string;
113
+ _id: string;
114
114
  } | {
115
115
  kind: "section";
116
116
  heading_id: string;
@@ -200,8 +200,8 @@ export declare function looksLikePath(s: string): boolean;
200
200
  export declare function isTargetId(s: string): boolean;
201
201
  /**
202
202
  * A bare string where a target object is expected (3.2, §11.8 "Sugar"): a
203
- * path-looking string → `{ kind: "document", path }`; a `b_`/`d_`/`n_` id →
204
- * that kind; `$new.n` → `{ kind: "symbol", id }` (its kind is the symbol
203
+ * path-looking string → `{ kind: "document", _path }`; a `b_`/`d_`/`n_` id →
204
+ * that kind; `$new.n` → `{ kind: "symbol", _id }` (its kind is the symbol
205
205
  * table's at resolution); a `#` locator → `filter_invalid` with a `fix`;
206
206
  * anything else is no target. A `-> ` leader never reaches here from the
207
207
  * planner (`select.ts` desugars it first); as a library input it is refused
@@ -219,8 +219,8 @@ export interface Focus {
219
219
  kind: "scalar" | "positional" | "identity";
220
220
  target: {
221
221
  kind: "document" | "block" | "node" | "path";
222
- id?: string;
223
- path?: string;
222
+ _id?: string;
223
+ _path?: string;
224
224
  };
225
225
  field?: string;
226
226
  }
@@ -347,13 +347,13 @@ export interface LoweringContext {
347
347
  /** `preview.summary` (3.3, §11.9): one line in words per resolved effect, in order */
348
348
  summary: string[];
349
349
  }
350
- /** Resolve a document target: an existing document's `{ id, path }`, or a `$new.n` document this plan creates. */
350
+ /** Resolve a document target: an existing document's `{ _id, _path }`, or a `$new.n` document this plan creates. */
351
351
  export declare function resolveDocumentTarget(ctx: LoweringContext, t: Extract<EffectTarget, {
352
352
  kind: "document";
353
353
  }>): Extract<ResolvedTarget, {
354
354
  kind: "document";
355
355
  }>;
356
- /** An existing document's `{ id, path }` for a literal document target (`doc_missing`; `filter_invalid` when `id` and `path` disagree). */
356
+ /** An existing document's `{ _id, _path }` for a literal document target (`doc_missing`; `filter_invalid` when `_id` and `_path` disagree). */
357
357
  export declare function findDocumentTarget(store: Store, repoId: string, t: Extract<EffectTarget, {
358
358
  kind: "document";
359
359
  }>): Extract<ResolvedTarget, {
@@ -361,7 +361,7 @@ export declare function findDocumentTarget(store: Store, repoId: string, t: Extr
361
361
  }>;
362
362
  /** `1 block` / `2 blocks` (an `s` on every noun of the table). */
363
363
  export declare function plural(n: number, noun: string): string;
364
- /** Resolve one validated effect's targets (§11.4): documents to `{ id, path }`, defaults made explicit; `i` names the effect in messages. */
364
+ /** Resolve one validated effect's targets (§11.4): documents to `{ _id, _path }`, defaults made explicit; `i` names the effect in messages. */
365
365
  export declare function resolveEffect(ctx: LoweringContext, e: Effect, i?: number): ResolvedEffect;
366
366
  /** Shift a kernel op's `$n.ids[i]` placeholders by `offset` (an opset planned alone, spliced into a longer op list). */
367
367
  export declare function shiftPlaceholders(op: Op, offset: number): Op;