oh-my-second-brain 0.1.5

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 (90) hide show
  1. package/adapters/README.md +98 -0
  2. package/adapters/claude-code/.claude-plugin/plugin.json +24 -0
  3. package/adapters/claude-code/CLAUDE.md +26 -0
  4. package/adapters/claude-code/skills/capture/SKILL.md +50 -0
  5. package/adapters/claude-code/skills/define/SKILL.md +51 -0
  6. package/adapters/claude-code/skills/doctor/SKILL.md +58 -0
  7. package/adapters/claude-code/skills/retrieve/SKILL.md +55 -0
  8. package/adapters/claude-code/skills/setup/SKILL.md +71 -0
  9. package/adapters/claude-code/skills/uninstall/SKILL.md +34 -0
  10. package/adapters/codex/.codex-plugin/plugin.json +8 -0
  11. package/adapters/codex/.mcp.json +14 -0
  12. package/adapters/codex/AGENTS.md +16 -0
  13. package/adapters/codex/rules/oms.md +25 -0
  14. package/adapters/codex/skills/oms-capture/SKILL.md +16 -0
  15. package/adapters/codex/skills/oms-doctor/SKILL.md +14 -0
  16. package/adapters/codex/skills/oms-install/SKILL.md +19 -0
  17. package/adapters/codex/skills/oms-retrieve/SKILL.md +10 -0
  18. package/adapters/codex/skills/oms-setup/SKILL.md +22 -0
  19. package/adapters/codex/skills/oms-uninstall/SKILL.md +20 -0
  20. package/adapters/hermes/README.md +8 -0
  21. package/adapters/hermes/SOUL.md +19 -0
  22. package/adapters/hermes/manifest.json +7 -0
  23. package/adapters/hermes/skills/capture/SKILL.md +16 -0
  24. package/adapters/hermes/skills/doctor/SKILL.md +14 -0
  25. package/adapters/hermes/skills/install/SKILL.md +19 -0
  26. package/adapters/hermes/skills/retrieve/SKILL.md +10 -0
  27. package/adapters/hermes/skills/setup/SKILL.md +22 -0
  28. package/adapters/hermes/skills/uninstall/SKILL.md +20 -0
  29. package/core/AGENTS.md +110 -0
  30. package/core/agents/librarian.md +43 -0
  31. package/core/agents/retriever.md +62 -0
  32. package/core/ontology/concepts/inbox.yaml +4 -0
  33. package/core/ontology/concepts/literature.yaml +27 -0
  34. package/core/ontology/taxonomy.yaml +11 -0
  35. package/core/skills/capture/SKILL.md +48 -0
  36. package/core/skills/define/SKILL.md +59 -0
  37. package/core/skills/doctor/SKILL.md +49 -0
  38. package/core/skills/retrieve/SKILL.md +56 -0
  39. package/core/skills/setup/SKILL.md +44 -0
  40. package/core/skills/uninstall/SKILL.md +34 -0
  41. package/dist/adapt/HostAdapter.d.ts +21 -0
  42. package/dist/adapt/HostAdapter.js +10 -0
  43. package/dist/adapt/HostAdapter.js.map +1 -0
  44. package/dist/adapt/claudeCode.d.ts +9 -0
  45. package/dist/adapt/claudeCode.js +15 -0
  46. package/dist/adapt/claudeCode.js.map +1 -0
  47. package/dist/adapt/codex.d.ts +9 -0
  48. package/dist/adapt/codex.js +15 -0
  49. package/dist/adapt/codex.js.map +1 -0
  50. package/dist/adapt/hermes.d.ts +9 -0
  51. package/dist/adapt/hermes.js +15 -0
  52. package/dist/adapt/hermes.js.map +1 -0
  53. package/dist/capture/safe.d.ts +36 -0
  54. package/dist/capture/safe.js +167 -0
  55. package/dist/capture/safe.js.map +1 -0
  56. package/dist/cli/oms.d.ts +18 -0
  57. package/dist/cli/oms.js +401 -0
  58. package/dist/cli/oms.js.map +1 -0
  59. package/dist/conventions/frontmatter.d.ts +15 -0
  60. package/dist/conventions/frontmatter.js +23 -0
  61. package/dist/conventions/frontmatter.js.map +1 -0
  62. package/dist/conventions/validate.d.ts +24 -0
  63. package/dist/conventions/validate.js +88 -0
  64. package/dist/conventions/validate.js.map +1 -0
  65. package/dist/graph/cache.d.ts +98 -0
  66. package/dist/graph/cache.js +347 -0
  67. package/dist/graph/cache.js.map +1 -0
  68. package/dist/index.d.ts +7 -0
  69. package/dist/index.js +8 -0
  70. package/dist/index.js.map +1 -0
  71. package/dist/install/hosts.d.ts +27 -0
  72. package/dist/install/hosts.js +465 -0
  73. package/dist/install/hosts.js.map +1 -0
  74. package/dist/mcp/server.d.ts +8 -0
  75. package/dist/mcp/server.js +461 -0
  76. package/dist/mcp/server.js.map +1 -0
  77. package/dist/ontology/loader.d.ts +13 -0
  78. package/dist/ontology/loader.js +63 -0
  79. package/dist/ontology/loader.js.map +1 -0
  80. package/dist/ontology/resolver.d.ts +13 -0
  81. package/dist/ontology/resolver.js +37 -0
  82. package/dist/ontology/resolver.js.map +1 -0
  83. package/dist/ontology/types.d.ts +72 -0
  84. package/dist/ontology/types.js +12 -0
  85. package/dist/ontology/types.js.map +1 -0
  86. package/docs/install.md +115 -0
  87. package/docs/release.md +91 -0
  88. package/package.json +64 -0
  89. package/scripts/install.sh +49 -0
  90. package/scripts/uninstall.sh +57 -0
@@ -0,0 +1,461 @@
1
+ import { readFile, stat } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
5
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
6
+ import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
7
+ import { parseNote } from "../conventions/frontmatter.js";
8
+ import { validateFrontmatter } from "../conventions/validate.js";
9
+ import { commitCapture, prepareCapture, safeVaultNotePath, } from "../capture/safe.js";
10
+ import { buildGraphCache, graphCachePath, graphCacheStatus, lazyLoadNoteBody, retrieveByAxis, } from "../graph/cache.js";
11
+ import { loadOntology } from "../ontology/loader.js";
12
+ import { resolveConcept } from "../ontology/resolver.js";
13
+ const SERVER_VERSION = "0.0.0";
14
+ function bundledOntologyDir() {
15
+ const __filename = fileURLToPath(import.meta.url);
16
+ const __dirname = path.dirname(__filename);
17
+ return path.resolve(__dirname, "../../core/ontology");
18
+ }
19
+ async function activeOntology(vault) {
20
+ const localOntologyDir = path.join(vault, ".oms");
21
+ const omsKind = await pathKind(localOntologyDir);
22
+ if (omsKind === "missing") {
23
+ return { ontology: await loadOntology(bundledOntologyDir()), source: "bundled" };
24
+ }
25
+ if (omsKind !== "directory") {
26
+ throw new Error("Local .oms exists but is not a directory.");
27
+ }
28
+ const taxonomyKind = await pathKind(path.join(localOntologyDir, "taxonomy.yaml"));
29
+ const conceptsKind = await pathKind(path.join(localOntologyDir, "concepts"));
30
+ if (taxonomyKind === "missing" && conceptsKind === "missing") {
31
+ return { ontology: await loadOntology(bundledOntologyDir()), source: "bundled" };
32
+ }
33
+ if (taxonomyKind !== "file" || conceptsKind !== "directory") {
34
+ throw new Error("Local .oms ontology is incomplete; expected .oms/taxonomy.yaml and .oms/concepts/.");
35
+ }
36
+ return { ontology: await loadOntology(localOntologyDir), source: "vault" };
37
+ }
38
+ async function pathKind(target) {
39
+ try {
40
+ const info = await stat(target);
41
+ if (info.isFile())
42
+ return "file";
43
+ if (info.isDirectory())
44
+ return "directory";
45
+ return "other";
46
+ }
47
+ catch (error) {
48
+ if (error instanceof Error && "code" in error && error.code === "ENOENT") {
49
+ return "missing";
50
+ }
51
+ throw error;
52
+ }
53
+ }
54
+ function jsonText(value) {
55
+ return {
56
+ content: [
57
+ {
58
+ type: "text",
59
+ text: JSON.stringify(value, null, 2),
60
+ },
61
+ ],
62
+ };
63
+ }
64
+ function errorText(message) {
65
+ return {
66
+ isError: true,
67
+ content: [
68
+ {
69
+ type: "text",
70
+ text: message,
71
+ },
72
+ ],
73
+ };
74
+ }
75
+ function isRecord(value) {
76
+ return typeof value === "object" && value !== null && !Array.isArray(value);
77
+ }
78
+ function stringArg(args, key) {
79
+ const value = args?.[key];
80
+ return typeof value === "string" ? value : undefined;
81
+ }
82
+ function conceptSummary(concept) {
83
+ return {
84
+ concept: concept.concept,
85
+ intent: concept.intent,
86
+ folder: concept.folder,
87
+ fields: concept.fields.map((field) => ({
88
+ name: field.name,
89
+ type: field.type,
90
+ required: field.required,
91
+ intent: field.intent,
92
+ })),
93
+ retrievalViews: (concept.lenses ?? []).map((lens) => ({
94
+ name: lens.name,
95
+ intent: lens.intent,
96
+ fields: lens.fields,
97
+ })),
98
+ };
99
+ }
100
+ export const omsMcpTools = [
101
+ {
102
+ name: "oms_graph_status",
103
+ title: "Oh My Second Brain graph/status",
104
+ description: "Read-only status for the active Oh My Second Brain ontology, graph/search cache phase, and gated write-tool posture.",
105
+ inputSchema: {
106
+ type: "object",
107
+ properties: {},
108
+ },
109
+ annotations: {
110
+ readOnlyHint: true,
111
+ destructiveHint: false,
112
+ idempotentHint: true,
113
+ openWorldHint: false,
114
+ },
115
+ },
116
+ {
117
+ name: "oms_graph_build",
118
+ title: "Oh My Second Brain graph build",
119
+ description: "Build the derived graph/search cache from markdown, frontmatter, folders, and wikilinks.",
120
+ inputSchema: {
121
+ type: "object",
122
+ properties: {},
123
+ },
124
+ annotations: {
125
+ readOnlyHint: false,
126
+ destructiveHint: false,
127
+ idempotentHint: true,
128
+ openWorldHint: false,
129
+ },
130
+ },
131
+ {
132
+ name: "oms_list_concepts",
133
+ title: "Oh My Second Brain list concepts",
134
+ description: "Read the active ontology concepts, frontmatter axes, folder bindings, and retrieval views.",
135
+ inputSchema: {
136
+ type: "object",
137
+ properties: {},
138
+ },
139
+ annotations: {
140
+ readOnlyHint: true,
141
+ destructiveHint: false,
142
+ idempotentHint: true,
143
+ openWorldHint: false,
144
+ },
145
+ },
146
+ {
147
+ name: "oms_retrieve_by_axis",
148
+ title: "Oh My Second Brain retrieve by axis",
149
+ description: "Axis-first retrieval over the derived cache; optional lexical query only ranks inside the narrowed candidate set.",
150
+ inputSchema: {
151
+ type: "object",
152
+ properties: {
153
+ concept: { type: "string" },
154
+ folder: { type: "string" },
155
+ property: { type: "string" },
156
+ value: { type: "string" },
157
+ wikilink: { type: "string" },
158
+ query: { type: "string" },
159
+ limit: { type: "number" },
160
+ },
161
+ },
162
+ annotations: {
163
+ readOnlyHint: true,
164
+ destructiveHint: false,
165
+ idempotentHint: true,
166
+ openWorldHint: false,
167
+ },
168
+ },
169
+ {
170
+ name: "oms_lazy_load_note",
171
+ title: "Oh My Second Brain lazy-load note body",
172
+ description: "Load a selected note body only after axis/search narrowing has selected the note.",
173
+ inputSchema: {
174
+ type: "object",
175
+ properties: {
176
+ notePath: {
177
+ type: "string",
178
+ description: "Vault-relative markdown note path.",
179
+ },
180
+ },
181
+ required: ["notePath"],
182
+ },
183
+ annotations: {
184
+ readOnlyHint: true,
185
+ destructiveHint: false,
186
+ idempotentHint: true,
187
+ openWorldHint: false,
188
+ },
189
+ },
190
+ {
191
+ name: "oms_validate_contract",
192
+ title: "Oh My Second Brain validate contract",
193
+ description: "Read one vault note and validate its frontmatter against the active folder/concept contract.",
194
+ inputSchema: {
195
+ type: "object",
196
+ properties: {
197
+ notePath: {
198
+ type: "string",
199
+ description: "Vault-relative markdown note path, for example references/book.md.",
200
+ },
201
+ },
202
+ required: ["notePath"],
203
+ },
204
+ annotations: {
205
+ readOnlyHint: true,
206
+ destructiveHint: false,
207
+ idempotentHint: true,
208
+ openWorldHint: false,
209
+ },
210
+ },
211
+ {
212
+ name: "oms_capture_prepare",
213
+ title: "Oh My Second Brain capture prepare",
214
+ description: "Plan a safe capture: choose folder/concept, surface missing fields, or route ambiguous input to inbox without writing.",
215
+ inputSchema: {
216
+ type: "object",
217
+ properties: {
218
+ concept: { type: "string" },
219
+ folder: { type: "string" },
220
+ filename: { type: "string" },
221
+ frontmatter: { type: "object" },
222
+ },
223
+ },
224
+ annotations: {
225
+ readOnlyHint: true,
226
+ destructiveHint: false,
227
+ idempotentHint: true,
228
+ openWorldHint: false,
229
+ },
230
+ },
231
+ {
232
+ name: "oms_capture_commit",
233
+ title: "Oh My Second Brain capture commit",
234
+ description: "Write or append a note only after vault path confinement and contract validation pass.",
235
+ inputSchema: {
236
+ type: "object",
237
+ properties: {
238
+ notePath: { type: "string" },
239
+ frontmatter: { type: "object" },
240
+ body: { type: "string" },
241
+ mode: { type: "string", enum: ["create", "append"] },
242
+ },
243
+ required: ["notePath", "frontmatter", "body", "mode"],
244
+ },
245
+ annotations: {
246
+ readOnlyHint: false,
247
+ destructiveHint: false,
248
+ idempotentHint: false,
249
+ openWorldHint: false,
250
+ },
251
+ },
252
+ ];
253
+ export function createOMSMcpServer(opts) {
254
+ const vault = path.resolve(opts.vault);
255
+ const server = new Server({ name: "oms", version: SERVER_VERSION }, {
256
+ capabilities: { tools: {} },
257
+ instructions: "Oh My Second Brain exposes ontology/status/cache/retrieval tools and safe capture tools. Capture commit is gated by vault confinement and contract validation.",
258
+ });
259
+ server.setRequestHandler(ListToolsRequestSchema, async () => ({
260
+ tools: omsMcpTools,
261
+ }));
262
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
263
+ const args = isRecord(request.params.arguments) ? request.params.arguments : undefined;
264
+ if (request.params.name === "oms_graph_status") {
265
+ try {
266
+ const { ontology, source } = await activeOntology(vault);
267
+ const cacheStatus = await graphCacheStatus(vault, ontology);
268
+ return jsonText({
269
+ vault,
270
+ ontologySource: source,
271
+ sourceOfTruth: ["markdown notes", ".oms/taxonomy.yaml", ".oms/concepts/*.yaml"],
272
+ counts: {
273
+ concepts: ontology.concepts.size,
274
+ folders: Object.keys(ontology.taxonomy.folders).length,
275
+ },
276
+ derivedState: cacheStatus,
277
+ writeTools: "capture-commit-gated-by-vault-confinement-and-contract-validation",
278
+ readTools: omsMcpTools.map((tool) => tool.name),
279
+ });
280
+ }
281
+ catch (error) {
282
+ return jsonText({
283
+ vault,
284
+ ontologySource: "vault-invalid",
285
+ sourceOfTruth: ["markdown notes", ".oms/taxonomy.yaml", ".oms/concepts/*.yaml"],
286
+ error: error instanceof Error ? error.message : String(error),
287
+ counts: null,
288
+ derivedState: {
289
+ exists: false,
290
+ staleness: {
291
+ schemaStale: true,
292
+ graphStale: true,
293
+ searchStale: true,
294
+ embeddingStale: "not-configured",
295
+ validationStale: true,
296
+ reasons: ["local .oms exists but could not be loaded"],
297
+ },
298
+ },
299
+ writeTools: "disabled-invalid-ontology",
300
+ readTools: ["oms_graph_status"],
301
+ });
302
+ }
303
+ }
304
+ try {
305
+ if (request.params.name === "oms_graph_build") {
306
+ const { ontology, source } = await activeOntology(vault);
307
+ const cache = await buildGraphCache({ vault, ontology, write: true });
308
+ return jsonText({
309
+ vault,
310
+ ontologySource: source,
311
+ cachePath: graphCachePath(vault),
312
+ generatedAt: cache.generatedAt,
313
+ notes: cache.notes.length,
314
+ edges: cache.edges.length,
315
+ searchDocuments: cache.search.length,
316
+ sourceOfTruth: cache.sourceOfTruth,
317
+ });
318
+ }
319
+ if (request.params.name === "oms_list_concepts") {
320
+ const { ontology, source } = await activeOntology(vault);
321
+ return jsonText({
322
+ vault,
323
+ ontologySource: source,
324
+ folders: ontology.taxonomy.folders,
325
+ concepts: Array.from(ontology.concepts.values()).map(conceptSummary),
326
+ });
327
+ }
328
+ if (request.params.name === "oms_retrieve_by_axis") {
329
+ const { ontology, source } = await activeOntology(vault);
330
+ const limitValue = args?.["limit"];
331
+ const hits = await retrieveByAxis({
332
+ vault,
333
+ ontology,
334
+ concept: stringArg(args, "concept"),
335
+ folder: stringArg(args, "folder"),
336
+ property: stringArg(args, "property"),
337
+ value: stringArg(args, "value"),
338
+ wikilink: stringArg(args, "wikilink"),
339
+ query: stringArg(args, "query"),
340
+ limit: typeof limitValue === "number" ? limitValue : undefined,
341
+ });
342
+ return jsonText({
343
+ vault,
344
+ ontologySource: source,
345
+ mode: "axis-first-search-second",
346
+ bodyPolicy: "lazy-load",
347
+ hits,
348
+ });
349
+ }
350
+ if (request.params.name === "oms_lazy_load_note") {
351
+ const notePath = stringArg(args, "notePath");
352
+ if (!notePath) {
353
+ return errorText('Missing required string argument "notePath".');
354
+ }
355
+ return jsonText(await lazyLoadNoteBody(vault, notePath));
356
+ }
357
+ if (request.params.name === "oms_validate_contract") {
358
+ const notePath = stringArg(args, "notePath");
359
+ if (!notePath) {
360
+ return errorText('Missing required string argument "notePath".');
361
+ }
362
+ let fullPath;
363
+ try {
364
+ fullPath = safeVaultNotePath(vault, notePath);
365
+ }
366
+ catch (error) {
367
+ return errorText(error instanceof Error ? error.message : String(error));
368
+ }
369
+ const { ontology, source } = await activeOntology(vault);
370
+ const normalizedNotePath = path.relative(vault, fullPath).replace(/\\/g, "/");
371
+ const concept = resolveConcept(ontology, normalizedNotePath);
372
+ if (!concept) {
373
+ return jsonText({
374
+ vault,
375
+ ontologySource: source,
376
+ notePath: normalizedNotePath,
377
+ concept: null,
378
+ valid: false,
379
+ violations: [
380
+ {
381
+ field: "path",
382
+ rule: "folder-binding",
383
+ message: "No concept binding resolves for this note path.",
384
+ },
385
+ ],
386
+ });
387
+ }
388
+ const raw = await readFile(fullPath, "utf-8");
389
+ const { frontmatter, hasFrontmatter } = parseNote(raw);
390
+ const result = validateFrontmatter(frontmatter, concept);
391
+ return jsonText({
392
+ vault,
393
+ ontologySource: source,
394
+ notePath: normalizedNotePath,
395
+ concept: concept.concept,
396
+ hasFrontmatter,
397
+ valid: result.valid,
398
+ violations: result.violations,
399
+ });
400
+ }
401
+ if (request.params.name === "oms_capture_prepare") {
402
+ const { ontology, source } = await activeOntology(vault);
403
+ const frontmatterArg = args?.["frontmatter"];
404
+ const frontmatter = isRecord(frontmatterArg) ? frontmatterArg : {};
405
+ return jsonText({
406
+ vault,
407
+ ontologySource: source,
408
+ plan: prepareCapture({
409
+ vault,
410
+ ontology,
411
+ concept: stringArg(args, "concept"),
412
+ folder: stringArg(args, "folder"),
413
+ filename: stringArg(args, "filename"),
414
+ frontmatter,
415
+ }),
416
+ });
417
+ }
418
+ if (request.params.name === "oms_capture_commit") {
419
+ const { ontology, source } = await activeOntology(vault);
420
+ const notePath = stringArg(args, "notePath");
421
+ const body = stringArg(args, "body");
422
+ const mode = stringArg(args, "mode");
423
+ const frontmatterArg = args?.["frontmatter"];
424
+ if (!notePath || !body || !isCaptureMode(mode) || !isRecord(frontmatterArg)) {
425
+ return errorText('Missing required arguments: notePath:string, frontmatter:object, body:string, mode:"create"|"append".');
426
+ }
427
+ try {
428
+ return jsonText({
429
+ vault,
430
+ ontologySource: source,
431
+ result: await commitCapture({
432
+ vault,
433
+ ontology,
434
+ notePath,
435
+ frontmatter: frontmatterArg,
436
+ body,
437
+ mode,
438
+ }),
439
+ });
440
+ }
441
+ catch (error) {
442
+ return errorText(error instanceof Error ? error.message : String(error));
443
+ }
444
+ }
445
+ return errorText(`Unknown Oh My Second Brain tool: ${request.params.name}`);
446
+ }
447
+ catch (error) {
448
+ return errorText(`Oh My Second Brain MCP error: ${error instanceof Error ? error.message : String(error)}`);
449
+ }
450
+ });
451
+ return server;
452
+ }
453
+ export async function runMcpServer(opts) {
454
+ const server = createOMSMcpServer(opts);
455
+ const transport = new StdioServerTransport();
456
+ await server.connect(transport);
457
+ }
458
+ function isCaptureMode(value) {
459
+ return value === "create" || value === "append";
460
+ }
461
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/mcp/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAW,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GAGvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EACL,aAAa,EACb,cAAc,EACd,iBAAiB,GAElB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,GACf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAGzD,MAAM,cAAc,GAAG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AC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAClC,CAAC;AAED,SAAS,aAAa,CAAC,KAAyB;IAC9C,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,QAAQ,CAAC;AAClD,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { Ontology } from "./types.js";
2
+ /**
3
+ * Load an Oh My Second Brain ontology from a directory that contains:
4
+ * <ontologyDir>/taxonomy.yaml
5
+ * <ontologyDir>/concepts/*.yaml
6
+ *
7
+ * Lenient:
8
+ * - Missing `taxonomy.version` defaults to 0.
9
+ * - A taxonomy folder that references an unknown concept name is warned and skipped.
10
+ * - Missing optional concept keys default sensibly.
11
+ * - Never throws (barring genuine I/O errors).
12
+ */
13
+ export declare function loadOntology(ontologyDir: string): Promise<Ontology>;
@@ -0,0 +1,63 @@
1
+ import { readFile, readdir } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { parse as parseYaml } from "yaml";
4
+ /**
5
+ * Load an Oh My Second Brain ontology from a directory that contains:
6
+ * <ontologyDir>/taxonomy.yaml
7
+ * <ontologyDir>/concepts/*.yaml
8
+ *
9
+ * Lenient:
10
+ * - Missing `taxonomy.version` defaults to 0.
11
+ * - A taxonomy folder that references an unknown concept name is warned and skipped.
12
+ * - Missing optional concept keys default sensibly.
13
+ * - Never throws (barring genuine I/O errors).
14
+ */
15
+ export async function loadOntology(ontologyDir) {
16
+ // ── taxonomy ──────────────────────────────────────────────────────────────
17
+ const taxonomyPath = path.join(ontologyDir, "taxonomy.yaml");
18
+ const taxonomyRaw = await readFile(taxonomyPath, "utf-8");
19
+ const taxonomyParsed = parseYaml(taxonomyRaw);
20
+ const taxonomy = {
21
+ version: typeof taxonomyParsed["version"] === "number"
22
+ ? taxonomyParsed["version"]
23
+ : 0,
24
+ folders: taxonomyParsed["folders"] != null &&
25
+ typeof taxonomyParsed["folders"] === "object" &&
26
+ !Array.isArray(taxonomyParsed["folders"])
27
+ ? taxonomyParsed["folders"]
28
+ : {},
29
+ };
30
+ // ── concepts ──────────────────────────────────────────────────────────────
31
+ const conceptsDir = path.join(ontologyDir, "concepts");
32
+ const entries = await readdir(conceptsDir);
33
+ const yamlFiles = entries.filter((e) => e.endsWith(".yaml") || e.endsWith(".yml"));
34
+ const concepts = new Map();
35
+ for (const file of yamlFiles) {
36
+ const filePath = path.join(conceptsDir, file);
37
+ const raw = await readFile(filePath, "utf-8");
38
+ const parsed = parseYaml(raw);
39
+ const concept = {
40
+ concept: typeof parsed["concept"] === "string" ? parsed["concept"] : path.basename(file, path.extname(file)),
41
+ intent: typeof parsed["intent"] === "string" ? parsed["intent"] : "",
42
+ folder: typeof parsed["folder"] === "string" ? parsed["folder"] : "",
43
+ fields: Array.isArray(parsed["fields"]) ? parsed["fields"] : [],
44
+ lenses: Array.isArray(parsed["lenses"]) ? parsed["lenses"] : [],
45
+ };
46
+ concepts.set(concept.concept, concept);
47
+ }
48
+ // Warn if a taxonomy folder references a concept name not in the map.
49
+ for (const [folder, binding] of Object.entries(taxonomy.folders)) {
50
+ const names = binding.concept == null
51
+ ? []
52
+ : Array.isArray(binding.concept)
53
+ ? binding.concept
54
+ : [binding.concept];
55
+ for (const name of names) {
56
+ if (!concepts.has(name)) {
57
+ console.warn(`[oms] taxonomy folder "${folder}" references unknown concept "${name}" — skipping.`);
58
+ }
59
+ }
60
+ }
61
+ return { taxonomy, concepts };
62
+ }
63
+ //# sourceMappingURL=loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.js","sourceRoot":"","sources":["../../src/ontology/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,MAAM,CAAC;AAG1C;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,WAAmB;IACpD,6EAA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AO,CAAC,OAAO,CAAC,CAAC;QAExB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBACxB,OAAO,CAAC,IAAI,CACV,0BAA0B,MAAM,iCAAiC,IAAI,eAAe,CACrF,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC;AAChC,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { Concept, Ontology } from "./types.js";
2
+ /**
3
+ * Resolve the Concept for a note given its path relative to the vault root.
4
+ *
5
+ * Pure function. Takes the FIRST path segment as the folder key, looks it up
6
+ * in the taxonomy, then resolves the concept by name from the ontology map.
7
+ *
8
+ * Returns `undefined` when:
9
+ * - the folder is not declared in the taxonomy, or
10
+ * - the binding's concept is null, or
11
+ * - no matching concept exists in the ontology.
12
+ */
13
+ export declare function resolveConcept(ontology: Ontology, notePath: string): Concept | undefined;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Resolve the Concept for a note given its path relative to the vault root.
3
+ *
4
+ * Pure function. Takes the FIRST path segment as the folder key, looks it up
5
+ * in the taxonomy, then resolves the concept by name from the ontology map.
6
+ *
7
+ * Returns `undefined` when:
8
+ * - the folder is not declared in the taxonomy, or
9
+ * - the binding's concept is null, or
10
+ * - no matching concept exists in the ontology.
11
+ */
12
+ export function resolveConcept(ontology, notePath) {
13
+ // Normalize backslashes to forward slashes.
14
+ const normalized = notePath.replace(/\\/g, "/");
15
+ // Take the first path segment as the folder name.
16
+ const slash = normalized.indexOf("/");
17
+ const folder = slash === -1 ? normalized : normalized.slice(0, slash);
18
+ if (!folder)
19
+ return undefined;
20
+ const binding = ontology.taxonomy.folders[folder];
21
+ if (!binding)
22
+ return undefined;
23
+ const conceptRef = binding.concept;
24
+ if (conceptRef === null || conceptRef === undefined)
25
+ return undefined;
26
+ if (Array.isArray(conceptRef)) {
27
+ // Return the first resolvable concept name.
28
+ for (const name of conceptRef) {
29
+ const concept = ontology.concepts.get(name);
30
+ if (concept)
31
+ return concept;
32
+ }
33
+ return undefined;
34
+ }
35
+ return ontology.concepts.get(conceptRef);
36
+ }
37
+ //# sourceMappingURL=resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolver.js","sourceRoot":"","sources":["../../src/ontology/resolver.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,MAAM,UAAU,cAAc,CAC5B,QAAkB,EAClB,QAAgB;IAEhB,4CAA4C;IAC5C,MAAM,UAAU,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAEhD,kDAAkD;IAClD,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACtC,MAAM,MAAM,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IAEtE,IAAI,CAAC,MAAM;QAAE,OAAO,SAAS,CAAC;IAE9B,MAAM,OAAO,GAAG,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAClD,IAAI,CAAC,OAAO;QAAE,OAAO,SAAS,CAAC;IAE/B,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC;IACnC,IAAI,UAAU,KAAK,IAAI,IAAI,UAAU,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAEtE,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QAC9B,4CAA4C;QAC5C,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;YAC9B,MAAM,OAAO,GAAG,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAC5C,IAAI,OAAO;gBAAE,OAAO,OAAO,CAAC;QAC9B,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;AAC3C,CAAC"}