melchizedek-agents 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 (111) hide show
  1. package/AGENT_SETUP.md +182 -0
  2. package/DOCUMENTATION.md +614 -0
  3. package/LICENSE +21 -0
  4. package/QUICKSTART.md +164 -0
  5. package/README.md +151 -0
  6. package/config/agents/README.md +27 -0
  7. package/config/agents/examples/ares.yaml +74 -0
  8. package/config/agents/examples/cartographers.yaml +115 -0
  9. package/config/agents/examples/claude.yaml +17 -0
  10. package/config/agents/examples/council.yaml +65 -0
  11. package/config/agents/examples/critic.yaml +74 -0
  12. package/config/agents/examples/delegation.yaml +29 -0
  13. package/config/agents/examples/hierarchical.yaml +26 -0
  14. package/config/agents/examples/image_production.yaml +112 -0
  15. package/config/agents/examples/librarian.yaml +75 -0
  16. package/config/agents/examples/model_zoo.yaml +81 -0
  17. package/config/agents/examples/patient_advocate.yaml +107 -0
  18. package/config/agents/examples/scriptorium.yaml +96 -0
  19. package/config/agents/examples/style_council.yaml +83 -0
  20. package/config/agents/examples/syndicate.yaml +34 -0
  21. package/config/agents/examples/tutor.yaml +66 -0
  22. package/config/agents/syndicateSchema.yaml +291 -0
  23. package/dist/lib/config.d.ts +108 -0
  24. package/dist/lib/config.js +110 -0
  25. package/dist/lib/dispatch.d.ts +133 -0
  26. package/dist/lib/dispatch.js +182 -0
  27. package/dist/lib/grounding.d.ts +28 -0
  28. package/dist/lib/grounding.js +61 -0
  29. package/dist/lib/index.d.ts +14 -0
  30. package/dist/lib/index.js +13 -0
  31. package/dist/lib/loadEnv.d.ts +21 -0
  32. package/dist/lib/loadEnv.js +58 -0
  33. package/dist/lib/loadSyndicate.d.ts +177 -0
  34. package/dist/lib/loadSyndicate.js +264 -0
  35. package/dist/lib/memory/supabaseMemoryService.d.ts +118 -0
  36. package/dist/lib/memory/supabaseMemoryService.js +499 -0
  37. package/dist/lib/models/claudeLlm.d.ts +93 -0
  38. package/dist/lib/models/claudeLlm.js +332 -0
  39. package/dist/lib/models/gptLlm.d.ts +110 -0
  40. package/dist/lib/models/gptLlm.js +497 -0
  41. package/dist/lib/models/grokLlm.d.ts +64 -0
  42. package/dist/lib/models/grokLlm.js +86 -0
  43. package/dist/lib/models/ollamaLlm.d.ts +105 -0
  44. package/dist/lib/models/ollamaLlm.js +134 -0
  45. package/dist/lib/models/openAiCompatibleLlm.d.ts +125 -0
  46. package/dist/lib/models/openAiCompatibleLlm.js +331 -0
  47. package/dist/lib/models/providerMap.d.ts +28 -0
  48. package/dist/lib/models/providerMap.js +45 -0
  49. package/dist/lib/models/registry.d.ts +71 -0
  50. package/dist/lib/models/registry.js +159 -0
  51. package/dist/lib/models/schemaNormalize.d.ts +22 -0
  52. package/dist/lib/models/schemaNormalize.js +58 -0
  53. package/dist/lib/observability/supabaseSpanExporter.d.ts +35 -0
  54. package/dist/lib/observability/supabaseSpanExporter.js +115 -0
  55. package/dist/lib/observability/tracer.d.ts +44 -0
  56. package/dist/lib/observability/tracer.js +242 -0
  57. package/dist/lib/persistence/supabaseProvider.d.ts +44 -0
  58. package/dist/lib/persistence/supabaseProvider.js +88 -0
  59. package/dist/lib/session/supabaseSessionService.d.ts +26 -0
  60. package/dist/lib/session/supabaseSessionService.js +193 -0
  61. package/dist/lib/session/transcript.d.ts +193 -0
  62. package/dist/lib/session/transcript.js +309 -0
  63. package/dist/lib/toolRegistry.d.ts +15 -0
  64. package/dist/lib/toolRegistry.js +58 -0
  65. package/dist/lib/tools/collectionsSearchTool.d.ts +55 -0
  66. package/dist/lib/tools/collectionsSearchTool.js +86 -0
  67. package/dist/lib/tools/generateImageTool.d.ts +16 -0
  68. package/dist/lib/tools/generateImageTool.js +119 -0
  69. package/dist/lib/tools/inspectImageTool.d.ts +21 -0
  70. package/dist/lib/tools/inspectImageTool.js +97 -0
  71. package/dist/lib/tools/mcpToolFactory.d.ts +2 -0
  72. package/dist/lib/tools/mcpToolFactory.js +116 -0
  73. package/dist/lib/tools/toolContract.d.ts +78 -0
  74. package/dist/lib/tools/toolContract.js +129 -0
  75. package/dist/lib/tools/webExtractTool.d.ts +70 -0
  76. package/dist/lib/tools/webExtractTool.js +461 -0
  77. package/dist/lib/tools/webSearchTool.d.ts +53 -0
  78. package/dist/lib/tools/webSearchTool.js +126 -0
  79. package/dist/lib/tools/wikiTools.d.ts +112 -0
  80. package/dist/lib/tools/wikiTools.js +697 -0
  81. package/dist/lib/tools/xSearchTool.d.ts +61 -0
  82. package/dist/lib/tools/xSearchTool.js +125 -0
  83. package/dist/lib/wiki/agentRun.d.ts +39 -0
  84. package/dist/lib/wiki/agentRun.js +79 -0
  85. package/dist/lib/wiki/builder.d.ts +71 -0
  86. package/dist/lib/wiki/builder.js +165 -0
  87. package/dist/lib/wiki/dive.d.ts +56 -0
  88. package/dist/lib/wiki/dive.js +208 -0
  89. package/dist/lib/wiki/entities.d.ts +220 -0
  90. package/dist/lib/wiki/entities.js +661 -0
  91. package/dist/lib/wiki/extract.d.ts +97 -0
  92. package/dist/lib/wiki/extract.js +305 -0
  93. package/dist/lib/wiki/fill.d.ts +37 -0
  94. package/dist/lib/wiki/fill.js +175 -0
  95. package/dist/lib/wiki/format.d.ts +132 -0
  96. package/dist/lib/wiki/format.js +177 -0
  97. package/dist/lib/wiki/graph.d.ts +80 -0
  98. package/dist/lib/wiki/graph.js +147 -0
  99. package/dist/lib/wiki/lint.d.ts +58 -0
  100. package/dist/lib/wiki/lint.js +267 -0
  101. package/dist/lib/wiki/markdown.d.ts +127 -0
  102. package/dist/lib/wiki/markdown.js +336 -0
  103. package/dist/lib/wiki/pipeline.d.ts +69 -0
  104. package/dist/lib/wiki/pipeline.js +119 -0
  105. package/dist/lib/wiki/vault.d.ts +84 -0
  106. package/dist/lib/wiki/vault.js +194 -0
  107. package/dist/scripts/a2a_server.d.ts +2 -0
  108. package/dist/scripts/a2a_server.js +997 -0
  109. package/dist/scripts/syndicate_chat.d.ts +2 -0
  110. package/dist/scripts/syndicate_chat.js +485 -0
  111. package/package.json +96 -0
@@ -0,0 +1,194 @@
1
+ /**
2
+ * lib/wiki/vault.ts — load an OKF bundle from disk and resolve its links.
3
+ *
4
+ * WHY this file exists:
5
+ * Every wiki operation (lint, graph, search, dive, garden) starts from the
6
+ * same picture: all documents of one bundle, parsed, with frontmatter
7
+ * validated against the profile and every link resolved to a
8
+ * bundle-absolute path. This module builds that picture once, so the
9
+ * layers above never touch the filesystem or path arithmetic themselves.
10
+ *
11
+ * Identity: a document IS its bundle-absolute path ('/memory/schema.md') —
12
+ * the OKF rule that "the file path is the concept's identity." All link
13
+ * resolution normalises to that form.
14
+ *
15
+ * The bundle root is configurable (WIKI_ROOT) so the same tooling serves
16
+ * any OKF bundle — this repo's wiki/ is merely the default. Writes are
17
+ * jailed to the bundle root: a resolved path escaping it is refused, since
18
+ * garden instructions and MCP callers are untrusted input.
19
+ */
20
+ import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync, } from 'node:fs';
21
+ import { dirname, join, posix, resolve, sep } from 'node:path';
22
+ import { conceptFrontmatterSchema, isPrivatePath, isReservedFilename, } from "./format.js";
23
+ import { parseDoc } from "./markdown.js";
24
+ // ── Bundle root ──────────────────────────────────────────────────────────────
25
+ /**
26
+ * WIKI_ROOT env var wins; default is `<cwd>/wiki`. The default used to be
27
+ * derived from this module's location (lib/wiki/ → repo root), which is
28
+ * wrong the moment the engine ships as a package (node_modules/<pkg>/wiki
29
+ * exists for no one) — and every real caller either sets WIKI_ROOT or runs
30
+ * from the repo root via npm scripts, where cwd IS the repo root.
31
+ */
32
+ export function resolveWikiRoot() {
33
+ if (process.env.WIKI_ROOT)
34
+ return resolve(process.env.WIKI_ROOT);
35
+ return resolve(process.cwd(), 'wiki');
36
+ }
37
+ // ── Loading ──────────────────────────────────────────────────────────────────
38
+ function walkMarkdownFiles(dir, out = []) {
39
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
40
+ if (entry.name.startsWith('.') || entry.name === 'node_modules')
41
+ continue;
42
+ const full = join(dir, entry.name);
43
+ if (entry.isDirectory())
44
+ walkMarkdownFiles(full, out);
45
+ else if (entry.isFile() && entry.name.endsWith('.md'))
46
+ out.push(full);
47
+ }
48
+ return out;
49
+ }
50
+ function toBundlePath(root, absPath) {
51
+ const rel = absPath.slice(root.length).split(sep).join('/');
52
+ return rel.startsWith('/') ? rel : `/${rel}`;
53
+ }
54
+ export function classifyDoc(bundlePath) {
55
+ const name = posix.basename(bundlePath);
56
+ if (name === 'index.md')
57
+ return 'index';
58
+ if (name === 'log.md')
59
+ return 'log';
60
+ return 'concept';
61
+ }
62
+ function deriveTitle(bundlePath, parsed) {
63
+ const fmTitle = parsed.frontmatter?.title;
64
+ if (typeof fmTitle === 'string' && fmTitle.trim() !== '')
65
+ return fmTitle;
66
+ const h1 = parsed.headings.find((h) => h.depth === 1);
67
+ if (h1)
68
+ return h1.text;
69
+ return posix.basename(bundlePath, '.md');
70
+ }
71
+ export function loadDoc(root, absPath) {
72
+ const raw = readFileSync(absPath, 'utf-8');
73
+ const bundlePath = toBundlePath(root, absPath);
74
+ return makeWikiDoc(bundlePath, absPath, raw);
75
+ }
76
+ /** Build a WikiDoc from raw text — also used to evaluate an unsaved draft. */
77
+ export function makeWikiDoc(bundlePath, absPath, raw) {
78
+ const kind = classifyDoc(bundlePath);
79
+ const parsed = parseDoc(raw);
80
+ let fm = null;
81
+ const fmIssues = [];
82
+ if (parsed.frontmatterError) {
83
+ fmIssues.push(`frontmatter YAML does not parse: ${parsed.frontmatterError}`);
84
+ }
85
+ else if (kind === 'concept') {
86
+ if (parsed.frontmatter === null) {
87
+ fmIssues.push('concept document has no YAML frontmatter');
88
+ }
89
+ else {
90
+ const check = conceptFrontmatterSchema.safeParse(parsed.frontmatter);
91
+ if (check.success) {
92
+ fm = check.data;
93
+ }
94
+ else {
95
+ for (const issue of check.error.issues) {
96
+ fmIssues.push(`${issue.path.join('.') || '(root)'}: ${issue.message}`);
97
+ }
98
+ }
99
+ }
100
+ }
101
+ const body = raw.split('\n').slice(parsed.bodyStartLine - 1).join('\n');
102
+ return {
103
+ bundlePath,
104
+ absPath,
105
+ kind,
106
+ parsed,
107
+ fm,
108
+ fmIssues,
109
+ title: deriveTitle(bundlePath, parsed),
110
+ wordCount: body.split(/\s+/).filter(Boolean).length,
111
+ isPrivate: isPrivatePath(bundlePath),
112
+ };
113
+ }
114
+ export function loadVault(root = resolveWikiRoot()) {
115
+ const absRoot = resolve(root);
116
+ if (!existsSync(absRoot)) {
117
+ throw new Error(`wiki bundle root not found: ${absRoot} (set WIKI_ROOT or run wiki:init)`);
118
+ }
119
+ const docs = new Map();
120
+ for (const file of walkMarkdownFiles(absRoot).sort()) {
121
+ const doc = loadDoc(absRoot, file);
122
+ docs.set(doc.bundlePath, doc);
123
+ }
124
+ return { root: absRoot, docs };
125
+ }
126
+ // ── Link resolution ──────────────────────────────────────────────────────────
127
+ const EXTERNAL_RE = /^([a-z][a-z0-9+.-]*:|\/\/)/i;
128
+ /**
129
+ * Resolve a link target as written to bundle-absolute form. Directory links
130
+ * ('/agents/' or '/agents') resolve to that directory's index.md — the OKF
131
+ * progressive-disclosure convention.
132
+ */
133
+ export function resolveLinkTarget(fromBundlePath, target) {
134
+ if (target.startsWith('#'))
135
+ return { kind: 'anchor' };
136
+ if (EXTERNAL_RE.test(target))
137
+ return { kind: 'external' };
138
+ const pathPart = target.split('#')[0].split('?')[0];
139
+ if (pathPart === '')
140
+ return { kind: 'anchor' };
141
+ const base = pathPart.startsWith('/')
142
+ ? pathPart
143
+ : posix.join(posix.dirname(fromBundlePath), pathPart);
144
+ let normalized = posix.normalize(base);
145
+ if (normalized.startsWith('..') || !normalized.startsWith('/')) {
146
+ return { kind: 'escapes-bundle' };
147
+ }
148
+ if (normalized.endsWith('/'))
149
+ normalized += 'index.md';
150
+ return { kind: 'internal', bundlePath: normalized };
151
+ }
152
+ /** Existing doc for an internal target, trying `/dir` → `/dir/index.md`. */
153
+ export function lookupTarget(vault, bundlePath) {
154
+ const direct = vault.docs.get(bundlePath);
155
+ if (direct)
156
+ return direct;
157
+ if (!bundlePath.endsWith('.md')) {
158
+ return vault.docs.get(posix.join(bundlePath, 'index.md')) ?? null;
159
+ }
160
+ return null;
161
+ }
162
+ // ── Writing (path-jailed) ────────────────────────────────────────────────────
163
+ /**
164
+ * Absolute filesystem path for a bundle path, refusing anything that
165
+ * resolves outside the bundle root. Callers pass user/agent-supplied paths.
166
+ */
167
+ export function jailedAbsPath(root, bundlePath) {
168
+ const abs = resolve(root, `.${posix.normalize(`/${bundlePath}`)}`);
169
+ const rootAbs = resolve(root);
170
+ if (abs !== rootAbs && !abs.startsWith(rootAbs + sep)) {
171
+ throw new Error(`path escapes the wiki bundle: ${bundlePath}`);
172
+ }
173
+ return abs;
174
+ }
175
+ export function writeDocFile(root, bundlePath, raw) {
176
+ const abs = jailedAbsPath(root, bundlePath);
177
+ mkdirSync(dirname(abs), { recursive: true });
178
+ writeFileSync(abs, raw.endsWith('\n') ? raw : `${raw}\n`, 'utf-8');
179
+ }
180
+ // ── Convenience views ────────────────────────────────────────────────────────
181
+ export function conceptDocs(vault) {
182
+ return [...vault.docs.values()].filter((d) => d.kind === 'concept');
183
+ }
184
+ export function indexDocs(vault) {
185
+ return [...vault.docs.values()].filter((d) => d.kind === 'index');
186
+ }
187
+ export function docsInDirectory(vault, dirBundlePath) {
188
+ const prefix = dirBundlePath.endsWith('/') ? dirBundlePath : `${dirBundlePath}/`;
189
+ return [...vault.docs.values()].filter((d) => d.bundlePath.startsWith(prefix) &&
190
+ !d.bundlePath.slice(prefix.length).includes('/'));
191
+ }
192
+ export function isReservedDoc(doc) {
193
+ return isReservedFilename(posix.basename(doc.bundlePath));
194
+ }
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export declare function startServer(syndicateName?: string): Promise<void>;