@opum-ai/lore 0.1.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 (91) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +306 -0
  3. package/bin/lore.cjs +109 -0
  4. package/package.json +67 -0
  5. package/src/adapters/backlog.ts +1084 -0
  6. package/src/adapters/git.ts +221 -0
  7. package/src/cli.ts +667 -0
  8. package/src/commands/agent.ts +301 -0
  9. package/src/commands/agents.ts +302 -0
  10. package/src/commands/args.ts +209 -0
  11. package/src/commands/changed.ts +70 -0
  12. package/src/commands/check.ts +1031 -0
  13. package/src/commands/codex-bridge.ts +49 -0
  14. package/src/commands/concurrency.ts +48 -0
  15. package/src/commands/context.ts +292 -0
  16. package/src/commands/discover.ts +89 -0
  17. package/src/commands/explorer.ts +253 -0
  18. package/src/commands/export.ts +93 -0
  19. package/src/commands/fswrite.ts +928 -0
  20. package/src/commands/graph.ts +291 -0
  21. package/src/commands/help.ts +151 -0
  22. package/src/commands/impact.ts +59 -0
  23. package/src/commands/init.ts +583 -0
  24. package/src/commands/instructions.ts +91 -0
  25. package/src/commands/link.ts +929 -0
  26. package/src/commands/new.ts +476 -0
  27. package/src/commands/orphans.ts +457 -0
  28. package/src/commands/path.ts +67 -0
  29. package/src/commands/provenance.ts +68 -0
  30. package/src/commands/query.ts +312 -0
  31. package/src/commands/reconcile-shared.ts +280 -0
  32. package/src/commands/rename.ts +585 -0
  33. package/src/commands/replace.ts +320 -0
  34. package/src/commands/scaffold.ts +346 -0
  35. package/src/commands/schema.ts +293 -0
  36. package/src/commands/snapshot.ts +130 -0
  37. package/src/commands/supersede.ts +400 -0
  38. package/src/commands/sync.ts +371 -0
  39. package/src/commands/tasks.ts +271 -0
  40. package/src/commands/traversal.ts +151 -0
  41. package/src/commands/validate.ts +226 -0
  42. package/src/config.ts +598 -0
  43. package/src/core/agent-bridge.ts +287 -0
  44. package/src/core/agent-context.ts +498 -0
  45. package/src/core/agent-profile.ts +447 -0
  46. package/src/core/bundle.ts +893 -0
  47. package/src/core/check.ts +853 -0
  48. package/src/core/codex-bridge.ts +100 -0
  49. package/src/core/concept.ts +597 -0
  50. package/src/core/consumer-scaffold.ts +433 -0
  51. package/src/core/context.ts +271 -0
  52. package/src/core/explorer-contract.ts +441 -0
  53. package/src/core/explorer-qualification.ts +58 -0
  54. package/src/core/explorer.ts +518 -0
  55. package/src/core/finding.ts +31 -0
  56. package/src/core/graph.ts +201 -0
  57. package/src/core/indexes.ts +436 -0
  58. package/src/core/instructions.ts +209 -0
  59. package/src/core/ladybug-driver.ts +1795 -0
  60. package/src/core/ladybug-lifecycle.ts +1178 -0
  61. package/src/core/ladybug-native.ts +95 -0
  62. package/src/core/ladybug-source.ts +667 -0
  63. package/src/core/links.ts +681 -0
  64. package/src/core/log.ts +253 -0
  65. package/src/core/managed-block.ts +540 -0
  66. package/src/core/manifest.ts +718 -0
  67. package/src/core/order.ts +13 -0
  68. package/src/core/profile.ts +1007 -0
  69. package/src/core/projection.ts +195 -0
  70. package/src/core/query.ts +542 -0
  71. package/src/core/reconcile.ts +236 -0
  72. package/src/core/replace.ts +419 -0
  73. package/src/core/retrieval.ts +213 -0
  74. package/src/core/rewrite.ts +940 -0
  75. package/src/core/scaffold.ts +255 -0
  76. package/src/core/schema.ts +366 -0
  77. package/src/core/snapshot-runtime.ts +52 -0
  78. package/src/core/snapshot-store.ts +287 -0
  79. package/src/core/snapshot.ts +711 -0
  80. package/src/core/template.ts +429 -0
  81. package/src/core/traversal.ts +487 -0
  82. package/src/core/validate.ts +517 -0
  83. package/src/core/workspace-contract.ts +473 -0
  84. package/src/core/workspace-projection.ts +365 -0
  85. package/src/core/workspace-retrieval.ts +196 -0
  86. package/src/core/workspace-source.ts +174 -0
  87. package/src/errors.ts +697 -0
  88. package/src/meta.ts +7 -0
  89. package/src/output.ts +589 -0
  90. package/src/scripts/upstream-backlog-watch.ts +288 -0
  91. package/src/state.ts +390 -0
@@ -0,0 +1,213 @@
1
+ /**
2
+ * Backend selection for Lore's existing graph/query/context contracts.
3
+ *
4
+ * The indexed path reads one completely verified immutable Ladybug generation
5
+ * into the same BundleGraph model the reference filesystem loader produces.
6
+ * Selection and fallback complete before a command renders or writes output.
7
+ */
8
+
9
+ import { join } from "node:path";
10
+ import type { BacklogAdapter } from "../adapters/backlog";
11
+ import { LoreError, WarningCollector } from "../errors";
12
+ import { type BundleGraph, loadBundle } from "./bundle";
13
+ import { reconcileLadybugProjection } from "./ladybug-lifecycle";
14
+ import {
15
+ EXPECTED_LADYBUG_STORAGE_VERSION,
16
+ EXPECTED_LADYBUG_VERSION,
17
+ type LadybugIndexedReader,
18
+ type LadybugNativeLoader,
19
+ loadLadybugNativeDriver,
20
+ memoizeLadybugNativeLoader,
21
+ supportsLadybugNative,
22
+ } from "./ladybug-native";
23
+ import { loadLadybugProjectionFreshness, loadLadybugProjectionSource } from "./ladybug-source";
24
+ import { loadProfile } from "./profile";
25
+ import { DOCS_DIR } from "./scaffold";
26
+ import { buildTraversalSnapshot, type TraversalSnapshot } from "./traversal";
27
+ import {
28
+ loadWorkspaceRetrievalGraph,
29
+ type WorkspaceRetrievalContext,
30
+ type WorkspaceRetrievalSelection,
31
+ } from "./workspace-retrieval";
32
+
33
+ export type RetrievalBackend = "indexed" | "reference";
34
+ export type RetrievalPolicy = "auto" | RetrievalBackend;
35
+
36
+ /** Internal provenance proving which verified snapshot supplied an indexed graph. */
37
+ export interface IndexedRetrievalProvenance {
38
+ readonly repositoryScopeKey: string;
39
+ readonly snapshotKey: string;
40
+ readonly sourceFingerprint: string;
41
+ readonly exportDigest: string;
42
+ readonly gitCommit: string | null;
43
+ }
44
+
45
+ export interface RetrievalGraph {
46
+ readonly graph: BundleGraph;
47
+ /** Bounded persisted operations available only for a verified indexed generation. */
48
+ readonly indexed?: LadybugIndexedReader;
49
+ /** Release native resources owned by this retrieval load. */
50
+ readonly dispose?: () => Promise<void>;
51
+ readonly backend: RetrievalBackend;
52
+ readonly provenance?: IndexedRetrievalProvenance;
53
+ /** Explicit multi-repository scope; absent for byte-compatible repository-local retrieval. */
54
+ readonly workspace?: WorkspaceRetrievalContext;
55
+ /** Exact typed authored facts for bounded path and impact operations. */
56
+ readonly traversal?: TraversalSnapshot;
57
+ }
58
+
59
+ export interface RetrievalGraphOptions {
60
+ readonly root: string;
61
+ readonly warnings?: WarningCollector;
62
+ readonly adapter?: BacklogAdapter;
63
+ readonly resolveGitCommit?: (root: string) => string | null;
64
+ /** Internal test/conformance control; never exposed as a public CLI flag. */
65
+ readonly policy?: RetrievalPolicy;
66
+ /** Injectable platform fact for objective Windows-safe fallback coverage. */
67
+ readonly platform?: NodeJS.Platform;
68
+ /** Injectable lazy native boundary for load-order and failure tests. */
69
+ readonly loadNativeDriver?: LadybugNativeLoader;
70
+ /** Explicit workspace selection; absence preserves the repository-local M6 path. */
71
+ readonly workspace?: WorkspaceRetrievalSelection;
72
+ /** Load the typed authored-edge traversal snapshot beside the concept graph. */
73
+ readonly includeTraversal?: boolean;
74
+ }
75
+
76
+ export type RetrievalGraphLoader = (options: RetrievalGraphOptions) => Promise<RetrievalGraph>;
77
+
78
+ /**
79
+ * Select a verified indexed graph when supported and usable, otherwise load the
80
+ * existing in-memory graph. Failed indexed warnings and data are discarded so a
81
+ * fallback run has exactly the reference path's observable stderr/stdout.
82
+ */
83
+ export async function loadRetrievalGraph(options: RetrievalGraphOptions): Promise<RetrievalGraph> {
84
+ if (options.workspace !== undefined) {
85
+ return loadWorkspaceRetrievalGraph({
86
+ root: options.root,
87
+ selection: options.workspace,
88
+ warnings: options.warnings,
89
+ adapter: options.adapter,
90
+ policy: options.policy,
91
+ platform: options.platform,
92
+ loadNativeDriver: options.loadNativeDriver,
93
+ sourceOptions: {
94
+ adapterForRoot: (root) => (root === options.root ? options.adapter : undefined),
95
+ },
96
+ includeTraversal: options.includeTraversal,
97
+ });
98
+ }
99
+ const policy = options.policy ?? "auto";
100
+ if (policy === "reference") {
101
+ return loadReferenceGraph(options);
102
+ }
103
+ if (!supportsLadybugNative(options.platform)) {
104
+ if (policy === "indexed") {
105
+ throw indexedUnavailable();
106
+ }
107
+ return loadReferenceGraph(options);
108
+ }
109
+
110
+ let indexedWarnings = new WarningCollector();
111
+ const loadNative = memoizeLadybugNativeLoader(options.loadNativeDriver ?? loadLadybugNativeDriver);
112
+ const loadSource = async () => {
113
+ const attemptWarnings = new WarningCollector();
114
+ const source = await loadLadybugProjectionSource({
115
+ root: options.root,
116
+ ladybugVersion: EXPECTED_LADYBUG_VERSION,
117
+ ladybugStorageVersion: EXPECTED_LADYBUG_STORAGE_VERSION,
118
+ adapter: options.adapter,
119
+ resolveGitCommit: options.resolveGitCommit,
120
+ warnings: attemptWarnings,
121
+ });
122
+ indexedWarnings = attemptWarnings;
123
+ return source;
124
+ };
125
+ const loadFreshness = () =>
126
+ loadLadybugProjectionFreshness({
127
+ root: options.root,
128
+ ladybugVersion: EXPECTED_LADYBUG_VERSION,
129
+ ladybugStorageVersion: EXPECTED_LADYBUG_STORAGE_VERSION,
130
+ adapter: options.adapter,
131
+ resolveGitCommit: options.resolveGitCommit,
132
+ });
133
+ try {
134
+ const lifecycle = await reconcileLadybugProjection({
135
+ root: options.root,
136
+ loadSource,
137
+ loadFreshness,
138
+ loadNativeDriver: loadNative,
139
+ });
140
+ if (lifecycle.generation === undefined) {
141
+ if (policy === "indexed") throw indexedUnavailable();
142
+ return loadReferenceGraph(options);
143
+ }
144
+ const native = await loadNative();
145
+ indexedWarnings = new WarningCollector();
146
+ for (const warning of lifecycle.source.warnings) indexedWarnings.add(warning);
147
+ const indexed = native.openLadybugIndexedReader(lifecycle.generation.databasePath, lifecycle.source);
148
+ const graph = await indexed.readBundleGraph();
149
+ const traversal = options.includeTraversal
150
+ ? buildTraversalSnapshot(lifecycle.source, (await indexed.readTraversalRecords?.()) ?? lifecycle.source)
151
+ : undefined;
152
+ copyWarnings(indexedWarnings, options.warnings);
153
+ return {
154
+ graph,
155
+ indexed,
156
+ dispose: () => indexed.close(),
157
+ backend: "indexed",
158
+ provenance: {
159
+ repositoryScopeKey: lifecycle.source.repositoryScopeKey,
160
+ snapshotKey: lifecycle.source.snapshotKey,
161
+ sourceFingerprint: lifecycle.source.sourceFingerprint,
162
+ exportDigest: lifecycle.source.exportDigest,
163
+ gitCommit: lifecycle.source.manifest.bundle.gitCommit,
164
+ },
165
+ ...(traversal !== undefined ? { traversal } : {}),
166
+ };
167
+ } catch {
168
+ if (policy === "indexed") throw indexedUnavailable();
169
+ return loadReferenceGraph(options);
170
+ }
171
+ }
172
+
173
+ /** The retained filesystem/in-memory conformance oracle and fallback. */
174
+ export async function loadReferenceRetrievalGraph(options: RetrievalGraphOptions): Promise<RetrievalGraph> {
175
+ return loadReferenceGraph(options);
176
+ }
177
+
178
+ async function loadReferenceGraph(options: RetrievalGraphOptions): Promise<RetrievalGraph> {
179
+ const profile = loadProfile({ root: options.root });
180
+ const graph = loadBundle(join(options.root, DOCS_DIR), {
181
+ warnings: options.warnings,
182
+ profile,
183
+ });
184
+ const traversal = options.includeTraversal
185
+ ? buildTraversalSnapshot(
186
+ await loadLadybugProjectionSource({
187
+ root: options.root,
188
+ ladybugVersion: EXPECTED_LADYBUG_VERSION,
189
+ ladybugStorageVersion: EXPECTED_LADYBUG_STORAGE_VERSION,
190
+ adapter: options.adapter,
191
+ resolveGitCommit: options.resolveGitCommit,
192
+ }),
193
+ )
194
+ : undefined;
195
+ return {
196
+ graph,
197
+ backend: "reference",
198
+ ...(traversal !== undefined ? { traversal } : {}),
199
+ };
200
+ }
201
+
202
+ function copyWarnings(from: WarningCollector, to?: WarningCollector): void {
203
+ if (to === undefined) return;
204
+ for (const message of from.list()) to.add(message);
205
+ }
206
+
207
+ function indexedUnavailable(): LoreError {
208
+ return new LoreError(
209
+ "validation",
210
+ "verified indexed retrieval is unavailable",
211
+ "retry after the local projection can be rebuilt, or use Lore's automatic in-memory fallback",
212
+ );
213
+ }