@descryy/core 0.7.0 → 0.9.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 (65) hide show
  1. package/dist/contracts/index.d.ts +5 -1
  2. package/dist/contracts/index.d.ts.map +1 -1
  3. package/dist/contracts/index.js +3 -1
  4. package/dist/contracts/index.js.map +1 -1
  5. package/dist/contracts/paths.d.ts +7 -0
  6. package/dist/contracts/paths.d.ts.map +1 -1
  7. package/dist/contracts/paths.js +7 -4
  8. package/dist/contracts/paths.js.map +1 -1
  9. package/dist/contracts/shapes.d.ts +12 -1
  10. package/dist/contracts/shapes.d.ts.map +1 -1
  11. package/dist/contracts/shapes.js +68 -0
  12. package/dist/contracts/shapes.js.map +1 -1
  13. package/dist/contracts/workspace-join.d.ts +104 -0
  14. package/dist/contracts/workspace-join.d.ts.map +1 -0
  15. package/dist/contracts/workspace-join.js +208 -0
  16. package/dist/contracts/workspace-join.js.map +1 -0
  17. package/dist/contracts/workspace-table-join.d.ts +204 -0
  18. package/dist/contracts/workspace-table-join.d.ts.map +1 -0
  19. package/dist/contracts/workspace-table-join.js +316 -0
  20. package/dist/contracts/workspace-table-join.js.map +1 -0
  21. package/dist/index.d.ts +1 -0
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +4 -0
  24. package/dist/index.js.map +1 -1
  25. package/dist/query/index.d.ts +4 -2
  26. package/dist/query/index.d.ts.map +1 -1
  27. package/dist/query/index.js +2 -1
  28. package/dist/query/index.js.map +1 -1
  29. package/dist/query/queries.d.ts +5 -0
  30. package/dist/query/queries.d.ts.map +1 -1
  31. package/dist/query/queries.js +58 -0
  32. package/dist/query/queries.js.map +1 -1
  33. package/dist/query/user-chain.d.ts +89 -0
  34. package/dist/query/user-chain.d.ts.map +1 -0
  35. package/dist/query/user-chain.js +203 -0
  36. package/dist/query/user-chain.js.map +1 -0
  37. package/dist/sources/git/history.d.ts +12 -0
  38. package/dist/sources/git/history.d.ts.map +1 -1
  39. package/dist/sources/git/history.js +27 -0
  40. package/dist/sources/git/history.js.map +1 -1
  41. package/dist/sources/git/index.d.ts +1 -1
  42. package/dist/sources/git/index.d.ts.map +1 -1
  43. package/dist/sources/git/index.js +1 -1
  44. package/dist/sources/git/index.js.map +1 -1
  45. package/dist/store/incremental-cache.d.ts +120 -0
  46. package/dist/store/incremental-cache.d.ts.map +1 -0
  47. package/dist/store/incremental-cache.js +161 -0
  48. package/dist/store/incremental-cache.js.map +1 -0
  49. package/dist/store/index.d.ts +2 -0
  50. package/dist/store/index.d.ts.map +1 -1
  51. package/dist/store/index.js +1 -0
  52. package/dist/store/index.js.map +1 -1
  53. package/dist/store/schema.d.ts +4 -4
  54. package/dist/store/schema.d.ts.map +1 -1
  55. package/dist/store/schema.js +45 -1
  56. package/dist/store/schema.js.map +1 -1
  57. package/dist/workspace/graph-layout.d.ts +85 -0
  58. package/dist/workspace/graph-layout.d.ts.map +1 -0
  59. package/dist/workspace/graph-layout.js +90 -0
  60. package/dist/workspace/graph-layout.js.map +1 -0
  61. package/dist/workspace/index.d.ts +3 -0
  62. package/dist/workspace/index.d.ts.map +1 -0
  63. package/dist/workspace/index.js +2 -0
  64. package/dist/workspace/index.js.map +1 -0
  65. package/package.json +2 -2
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Where a workspace's shared graph lives, and the migration off the old
3
+ * one-graph-per-repository layout — Gap 1 of
4
+ * `documents/plans/site-claims-closure-production-plan.md`.
5
+ *
6
+ * Ported from `descry-desktop`'s `packages/session/src/indexing/graph-layout.ts`
7
+ * (H-2, "one graph per workspace, not per repository"), which solved the same
8
+ * problem for the desktop app's single, central engine root. The layout differs
9
+ * here because `descry-core` has no such root: every repository owns its own
10
+ * `.descry/` directory and its own `graph` path in `.descry/config.json`
11
+ * (`session.ts`'s `DescryConfig.graph`), so there is no `graph/${repositoryId}.db`
12
+ * convention to reuse. Two adaptations follow from that:
13
+ *
14
+ * 1. `workspaceGraphPath` keeps the desktop version's shape —
15
+ * `join(rootDir, "graph", "workspace-<id>.db")` — but `rootDir` here is a
16
+ * directory the caller chooses per invocation (the MCP `analyze_workspace`
17
+ * tool uses the initiating repository's `.descry/` directory), not a
18
+ * single app-wide engine root. That is a disclosed design choice, not an
19
+ * inferred one: the shared graph physically lives inside whichever
20
+ * repository's session first asked for it.
21
+ * 2. `migrateToWorkspaceGraph` takes each repository's *actual* existing graph
22
+ * path directly (`RepoGraphLocation.graphPath`, read from that repo's own
23
+ * config) rather than deriving one from a `repositoryId` the way the
24
+ * desktop version does — `descry-core` already knows the real path per
25
+ * repo without having to reconstruct it.
26
+ *
27
+ * The reasoning for *why* a migration is a move-and-reindex rather than a
28
+ * merge is unchanged from the desktop original: every node id in a
29
+ * pre-workspace graph was computed with `workspace` absent
30
+ * (`IdentityScope.workspace`, `packages/ir/src/identity.ts`), so
31
+ * workspace-scoped node types (`API_ENDPOINT`, `DATABASE_TABLE`,
32
+ * `DATABASE_COLUMN`, `INCIDENT`, `FIX_PATTERN`) in it carry repo-scoped ids —
33
+ * copying those rows into the shared store would populate it with ids nothing
34
+ * will ever produce again, which is worse than an empty graph because it looks
35
+ * full. So the honest handling is: move the stale database aside (never
36
+ * delete it), name the repository whose graph status must be treated as
37
+ * needing a fresh index, and let `indexWorkspace` (`../../ ../mcp/src
38
+ * /workspace-index.ts`) produce correct ids by reading the repository again.
39
+ */
40
+ import { existsSync, mkdirSync, renameSync } from "node:fs";
41
+ import { join } from "node:path";
42
+ /** Sidecars `node:sqlite` may leave next to a database. A `-wal` orphaned beside a moved db is a corrupt pair, not a leftover. */
43
+ const SQLITE_SIDECAR_SUFFIXES = ["-wal", "-shm", "-journal"];
44
+ const LEGACY_BACKUP_DIRNAME = "legacy-per-repository";
45
+ /** The one graph every repository in a workspace is indexed into. */
46
+ export function workspaceGraphPath(rootDir, workspaceId) {
47
+ return join(rootDir, "graph", `workspace-${workspaceId}.db`);
48
+ }
49
+ /**
50
+ * Move every pre-workspace graph aside and report what has to be re-indexed.
51
+ *
52
+ * Idempotent: a second call finds nothing at the recorded paths (because the
53
+ * first call already moved them) and reports `migrated: false`. A path that
54
+ * does not exist — the common case for a repository that has simply never
55
+ * been analysed yet — is skipped without comment; there is nothing stale to
56
+ * move.
57
+ */
58
+ export function migrateToWorkspaceGraph(options) {
59
+ const now = options.now ?? Date.now;
60
+ const backupDir = join(options.rootDir, "graph", LEGACY_BACKUP_DIRNAME);
61
+ const moved = [];
62
+ for (const repository of options.repositories) {
63
+ const from = repository.graphPath;
64
+ if (from === ":memory:" || !existsSync(from))
65
+ continue;
66
+ mkdirSync(backupDir, { recursive: true });
67
+ const to = join(backupDir, `${repository.repo}-${now()}.db`);
68
+ renameSync(from, to);
69
+ for (const suffix of SQLITE_SIDECAR_SUFFIXES) {
70
+ if (existsSync(`${from}${suffix}`))
71
+ renameSync(`${from}${suffix}`, `${to}${suffix}`);
72
+ }
73
+ moved.push({ repo: repository.repo, from, to });
74
+ }
75
+ if (moved.length === 0) {
76
+ return { migrated: false, movedDatabases: [], reposToReindex: [], disclosure: null };
77
+ }
78
+ return {
79
+ migrated: true,
80
+ movedDatabases: moved,
81
+ reposToReindex: moved.map((m) => m.repo),
82
+ disclosure: `This workspace now keeps one graph shared by every linked repository instead of one per ` +
83
+ `repository, so a frontend and a backend can share a map (DEC-054). ${moved.length} existing ` +
84
+ `per-repository graph database(s) were built under the old, repository-only identity scope, so ` +
85
+ `every node id in them is wrong for the shared graph and they cannot be merged into it. They ` +
86
+ `have been moved to "${backupDir}" — nothing was deleted — and the affected repositories will be ` +
87
+ "re-indexed into the workspace graph.",
88
+ };
89
+ }
90
+ //# sourceMappingURL=graph-layout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph-layout.js","sourceRoot":"","sources":["../../src/workspace/graph-layout.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM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AE,CAAC,CAAC;QACvF,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;IAClD,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,cAAc,EAAE,EAAE,EAAE,cAAc,EAAE,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;IACvF,CAAC;IAED,OAAO;QACL,QAAQ,EAAE,IAAI;QACd,cAAc,EAAE,KAAK;QACrB,cAAc,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;QACxC,UAAU,EACR,0FAA0F;YAC1F,sEAAsE,KAAK,CAAC,MAAM,YAAY;YAC9F,gGAAgG;YAChG,8FAA8F;YAC9F,uBAAuB,SAAS,kEAAkE;YAClG,sCAAsC;KACzC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { workspaceGraphPath, migrateToWorkspaceGraph } from "./graph-layout.ts";
2
+ export type { GraphLayoutMigration, MigrateToWorkspaceGraphOptions, MovedGraphDatabase, RepoGraphLocation, } from "./graph-layout.ts";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/workspace/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAChF,YAAY,EACV,oBAAoB,EACpB,8BAA8B,EAC9B,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { workspaceGraphPath, migrateToWorkspaceGraph } from "./graph-layout.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/workspace/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@descryy/core",
3
- "version": "0.7.0",
3
+ "version": "0.9.0",
4
4
  "type": "module",
5
5
  "description": "Descry graph engine: storage, graph builder, query layer, traversal, diff scoping, git source, MCP server.",
6
6
  "license": "MIT",
@@ -33,6 +33,6 @@
33
33
  "build": "tsc -b"
34
34
  },
35
35
  "dependencies": {
36
- "@descryy/ir": "0.7.0"
36
+ "@descryy/ir": "0.10.0"
37
37
  }
38
38
  }