@omgbase/core 0.6.0 → 0.6.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.
@@ -25,8 +25,16 @@ export interface DiffEntry {
25
25
  after?: string;
26
26
  }
27
27
  export declare function diffBlocks(store: Store, docId: string, fromRev: string, toRev: string): DiffEntry[];
28
- /** `diff_unified` (spec/surface §3): a unified diff of two revisions' rendered
29
- * texts — each revision's live raws joined by `\n` — via {@link unifiedDiff}. */
28
+ /**
29
+ * `diff_unified` (spec/surface §3): a unified diff of the two revisions'
30
+ * **reconstructed file text** — exactly the bytes `docs_read_at` returns for
31
+ * each revision ({@link readDocumentAtRevision}: frontmatter, trivia and
32
+ * top-level order included) — via {@link unifiedDiff}, so hunk line numbers
33
+ * are real file lines. Until 1.4.x this diffed the Merkle-tree walk (every
34
+ * live raw at every depth joined by `\n`), which repeated each nested block
35
+ * after its container's raw and put an appended list item before the list's
36
+ * first item (§9). An unknown revision is {@link RevisionNotFound}.
37
+ */
30
38
  export declare function diffUnified(store: Store, docId: string, fromRev: string, toRev: string): string;
31
39
  /** The `diff_unified` tool's result (spec/surface §3): the resolved revision pair and the diff. */
32
40
  export interface DocDiffUnified {
@@ -1,4 +1,5 @@
1
1
  import { findDocByRef } from "../core/read/reader.js";
2
+ import { readDocumentAtRevision } from "../core/read/document.js";
2
3
  import { isValidId } from "../core/ids.js";
3
4
  import { EngineError } from "../mcp/errors.js";
4
5
  /** history_node: a block's biography from block_changes + commits (06 §3). */
@@ -50,7 +51,9 @@ export function diffBlocks(store, docId, fromRev, toRev) {
50
51
  // core/hash.ts serializeTreeEntries): [blockId, rawHashHex, childTreeHashHex,
51
52
  // type, attrs, triviaHashHex]. Diff needs only the first three; whole-document
52
53
  // byte-faithful reconstruction (which also needs trivia + top-level order) lives
53
- // in core/read/document.ts readDocumentAtRevision.
54
+ // in core/read/document.ts readDocumentAtRevision. This map is NOT a rendering
55
+ // of the document: a container's raw already holds its children's text, so
56
+ // joining the values would repeat every nested block (spec/surface §9).
54
57
  function blocksAtRevision(store, docId, revId) {
55
58
  const rev = store.db.prepare("SELECT root_tree FROM revisions WHERE rev_id = ? AND doc_id = ?").get(revId, docId);
56
59
  if (!rev)
@@ -73,10 +76,23 @@ function blocksAtRevision(store, docId, revId) {
73
76
  walk(rev.root_tree.toString("hex"));
74
77
  return out;
75
78
  }
76
- /** `diff_unified` (spec/surface §3): a unified diff of two revisions' rendered
77
- * texts — each revision's live raws joined by `\n` — via {@link unifiedDiff}. */
79
+ /**
80
+ * `diff_unified` (spec/surface §3): a unified diff of the two revisions'
81
+ * **reconstructed file text** — exactly the bytes `docs_read_at` returns for
82
+ * each revision ({@link readDocumentAtRevision}: frontmatter, trivia and
83
+ * top-level order included) — via {@link unifiedDiff}, so hunk line numbers
84
+ * are real file lines. Until 1.4.x this diffed the Merkle-tree walk (every
85
+ * live raw at every depth joined by `\n`), which repeated each nested block
86
+ * after its container's raw and put an appended list item before the list's
87
+ * first item (§9). An unknown revision is {@link RevisionNotFound}.
88
+ */
78
89
  export function diffUnified(store, docId, fromRev, toRev) {
79
- const rendered = (rev) => [...blocksAtRevision(store, docId, rev).values()].join("\n");
90
+ const rendered = (rev) => {
91
+ const at = readDocumentAtRevision(store, docId, rev);
92
+ if (!at)
93
+ throw new RevisionNotFound(docId, rev);
94
+ return at.content;
95
+ };
80
96
  return unifiedDiff(rendered(fromRev), rendered(toRev));
81
97
  }
82
98
  /**
@@ -940,7 +940,7 @@ export function buildServer(ctx) {
940
940
  }
941
941
  });
942
942
  server.registerTool("diff_unified", {
943
- description: "Unified diff between two revisions of a document (the `omg diff` rendering): returns `{ doc, path, from, to, diff }` where `diff` is a unified diff of the two rendered texts (Myers shortest edit script; `@@ -a,b +c,d @@` hunks with 3 lines of context; lines prefixed `-`, `+` or a space; no file header; identical texts → \"\"). `from_rev`/`to_rev` default to the previous and current revisions ('what did the last commit change here'). Contrast `diff`, which returns block-grain added/removed/changed entries.",
943
+ description: "Unified diff between two revisions of a document (the `omg diff` rendering): returns `{ doc, path, from, to, diff }` where `diff` is a unified diff of the two revisions' file texts — for each revision exactly the bytes docs_read_at returns, so hunk line numbers are real file lines (Myers shortest edit script; `@@ -a,b +c,d @@` hunks with 3 lines of context; lines prefixed `-`, `+` or a space; no file header; identical texts → \"\"). `from_rev`/`to_rev` default to the previous and current revisions ('what did the last commit change here'). Contrast `diff`, which returns block-grain added/removed/changed entries.",
944
944
  inputSchema: { doc: z.string(), from_rev: z.string().optional(), to_rev: z.string().optional(), ...REPO_ARG },
945
945
  }, async (args) => {
946
946
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omgbase/core",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "Open Markdown Graph Base — embedded engine",
5
5
  "license": "MIT",
6
6
  "repository": {