@pella-labs/pinakes 0.1.10 → 0.3.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.
- package/README.md +20 -20
- package/dist/cli/audit.d.ts +5 -3
- package/dist/cli/audit.d.ts.map +1 -1
- package/dist/cli/audit.js +3 -24
- package/dist/cli/audit.js.map +1 -1
- package/dist/cli/contradiction-cli.d.ts +12 -0
- package/dist/cli/contradiction-cli.d.ts.map +1 -0
- package/dist/cli/contradiction-cli.js +35 -0
- package/dist/cli/contradiction-cli.js.map +1 -0
- package/dist/cli/contradiction.d.ts +59 -0
- package/dist/cli/contradiction.d.ts.map +1 -0
- package/dist/cli/contradiction.js +172 -0
- package/dist/cli/contradiction.js.map +1 -0
- package/dist/cli/export.d.ts +1 -1
- package/dist/cli/export.d.ts.map +1 -1
- package/dist/cli/export.js +7 -28
- package/dist/cli/export.js.map +1 -1
- package/dist/cli/import.d.ts +2 -2
- package/dist/cli/import.d.ts.map +1 -1
- package/dist/cli/import.js +5 -26
- package/dist/cli/import.js.map +1 -1
- package/dist/cli/index.js +39 -11
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/purge.d.ts +2 -2
- package/dist/cli/purge.d.ts.map +1 -1
- package/dist/cli/purge.js +2 -23
- package/dist/cli/purge.js.map +1 -1
- package/dist/cli/rebuild.d.ts +8 -6
- package/dist/cli/rebuild.d.ts.map +1 -1
- package/dist/cli/rebuild.js +9 -31
- package/dist/cli/rebuild.js.map +1 -1
- package/dist/cli/serve.d.ts +9 -7
- package/dist/cli/serve.d.ts.map +1 -1
- package/dist/cli/serve.js +71 -41
- package/dist/cli/serve.js.map +1 -1
- package/dist/cli/status.d.ts +7 -5
- package/dist/cli/status.d.ts.map +1 -1
- package/dist/cli/status.js +10 -29
- package/dist/cli/status.js.map +1 -1
- package/dist/db/client.d.ts +4 -4
- package/dist/db/client.js +3 -3
- package/dist/db/client.js.map +1 -1
- package/dist/db/migrations/migrations/0002_rename_kg_to_pinakes.sql +49 -0
- package/dist/db/migrations/migrations/meta/0002_snapshot.json +504 -0
- package/dist/db/migrations/migrations/meta/_journal.json +7 -0
- package/dist/db/repository.js +5 -5
- package/dist/db/repository.js.map +1 -1
- package/dist/db/schema.d.ts +84 -84
- package/dist/db/schema.d.ts.map +1 -1
- package/dist/db/schema.js +49 -49
- package/dist/db/schema.js.map +1 -1
- package/dist/db/types.d.ts +2 -2
- package/dist/db/types.js +1 -1
- package/dist/gaps/detector.d.ts +5 -5
- package/dist/gaps/detector.js +15 -15
- package/dist/gaps/detector.js.map +1 -1
- package/dist/ingest/chokidar.js +1 -1
- package/dist/ingest/ingester.d.ts +9 -4
- package/dist/ingest/ingester.d.ts.map +1 -1
- package/dist/ingest/ingester.js +82 -17
- package/dist/ingest/ingester.js.map +1 -1
- package/dist/ingest/manifest.d.ts +5 -3
- package/dist/ingest/manifest.d.ts.map +1 -1
- package/dist/ingest/manifest.js +23 -14
- package/dist/ingest/manifest.js.map +1 -1
- package/dist/ingest/parse/chunk.js +1 -1
- package/dist/ingest/parse/markdown.d.ts +2 -2
- package/dist/ingest/queue.d.ts +1 -1
- package/dist/ingest/queue.js +1 -1
- package/dist/ingest/source.d.ts +2 -2
- package/dist/ingest/source.d.ts.map +1 -1
- package/dist/ingest/source.js +1 -1
- package/dist/llm/provider.d.ts +70 -0
- package/dist/llm/provider.d.ts.map +1 -0
- package/dist/llm/provider.js +235 -0
- package/dist/llm/provider.js.map +1 -0
- package/dist/mcp/envelope.d.ts +1 -1
- package/dist/mcp/tools/execute.d.ts +7 -7
- package/dist/mcp/tools/execute.d.ts.map +1 -1
- package/dist/mcp/tools/execute.js +41 -59
- package/dist/mcp/tools/execute.js.map +1 -1
- package/dist/mcp/tools/search.d.ts +13 -8
- package/dist/mcp/tools/search.d.ts.map +1 -1
- package/dist/mcp/tools/search.js +53 -28
- package/dist/mcp/tools/search.js.map +1 -1
- package/dist/observability/audit.d.ts +2 -2
- package/dist/observability/audit.js +3 -3
- package/dist/observability/audit.js.map +1 -1
- package/dist/observability/logger.js +4 -4
- package/dist/observability/logger.js.map +1 -1
- package/dist/observability/metrics.js +1 -1
- package/dist/observability/metrics.js.map +1 -1
- package/dist/paths.d.ts +61 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +106 -0
- package/dist/paths.js.map +1 -0
- package/dist/retrieval/dedup.d.ts +25 -0
- package/dist/retrieval/dedup.d.ts.map +1 -0
- package/dist/retrieval/dedup.js +97 -0
- package/dist/retrieval/dedup.js.map +1 -0
- package/dist/retrieval/embedder.d.ts +9 -9
- package/dist/retrieval/embedder.d.ts.map +1 -1
- package/dist/retrieval/embedder.js +17 -17
- package/dist/retrieval/embedder.js.map +1 -1
- package/dist/retrieval/expand.d.ts +18 -0
- package/dist/retrieval/expand.d.ts.map +1 -0
- package/dist/retrieval/expand.js +89 -0
- package/dist/retrieval/expand.js.map +1 -0
- package/dist/retrieval/fts.d.ts +3 -3
- package/dist/retrieval/fts.js +8 -8
- package/dist/retrieval/graph.d.ts +47 -0
- package/dist/retrieval/graph.d.ts.map +1 -0
- package/dist/retrieval/graph.js +144 -0
- package/dist/retrieval/graph.js.map +1 -0
- package/dist/retrieval/hybrid.d.ts +10 -0
- package/dist/retrieval/hybrid.d.ts.map +1 -1
- package/dist/retrieval/hybrid.js +57 -2
- package/dist/retrieval/hybrid.js.map +1 -1
- package/dist/retrieval/vec.d.ts +2 -2
- package/dist/retrieval/vec.js +3 -3
- package/dist/sandbox/bindings/install.d.ts +5 -5
- package/dist/sandbox/bindings/install.d.ts.map +1 -1
- package/dist/sandbox/bindings/install.js +3 -3
- package/dist/sandbox/bindings/install.js.map +1 -1
- package/dist/sandbox/bindings/kg.d.ts.map +1 -1
- package/dist/sandbox/bindings/kg.js +10 -0
- package/dist/sandbox/bindings/kg.js.map +1 -1
- package/dist/sandbox/bindings/pinakes.d.ts +29 -0
- package/dist/sandbox/bindings/pinakes.d.ts.map +1 -0
- package/dist/sandbox/bindings/pinakes.js +333 -0
- package/dist/sandbox/bindings/pinakes.js.map +1 -0
- package/dist/sandbox/bindings/write.d.ts +1 -1
- package/dist/sandbox/bindings/write.d.ts.map +1 -1
- package/dist/sandbox/bindings/write.js +9 -9
- package/dist/sandbox/bindings/write.js.map +1 -1
- package/dist/sandbox/executor.d.ts +3 -3
- package/dist/sandbox/executor.js +6 -6
- package/dist/sandbox/executor.js.map +1 -1
- package/dist/sandbox/helpers.d.ts +1 -1
- package/dist/sandbox/helpers.d.ts.map +1 -1
- package/dist/sandbox/helpers.js +2 -2
- package/dist/sandbox/vendored-codemode.d.ts +1 -1
- package/dist/sandbox/vendored-codemode.js +1 -1
- package/dist/server.js +15 -6
- package/dist/server.js.map +1 -1
- package/package.json +22 -27
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { logger } from '../observability/logger.js';
|
|
3
|
+
/**
|
|
4
|
+
* Create the best available LLM provider by probing the environment.
|
|
5
|
+
* First available provider in the cascade wins.
|
|
6
|
+
*/
|
|
7
|
+
export function createLlmProvider(mcpServer) {
|
|
8
|
+
// 1. MCP Sampling
|
|
9
|
+
if (mcpServer) {
|
|
10
|
+
const sampling = mcpServer.getClientCapabilities?.()?.sampling;
|
|
11
|
+
if (sampling && mcpServer.createMessage) {
|
|
12
|
+
return new McpSamplingProvider(mcpServer);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
// 2. Ollama
|
|
16
|
+
const ollamaUrl = process.env['PINAKES_OLLAMA_URL'];
|
|
17
|
+
if (ollamaUrl) {
|
|
18
|
+
return new OllamaProvider(ollamaUrl);
|
|
19
|
+
}
|
|
20
|
+
// 3. API key (Anthropic or OpenAI)
|
|
21
|
+
const anthropicKey = process.env['ANTHROPIC_API_KEY'];
|
|
22
|
+
if (anthropicKey) {
|
|
23
|
+
return new AnthropicApiProvider(anthropicKey);
|
|
24
|
+
}
|
|
25
|
+
const openaiKey = process.env['OPENAI_API_KEY'];
|
|
26
|
+
if (openaiKey) {
|
|
27
|
+
return new OpenAiApiProvider(openaiKey);
|
|
28
|
+
}
|
|
29
|
+
// 4. claude -p subprocess
|
|
30
|
+
if (whichSync('claude')) {
|
|
31
|
+
return new ClaudeSubprocessProvider();
|
|
32
|
+
}
|
|
33
|
+
// 5. codex exec subprocess
|
|
34
|
+
if (whichSync('codex')) {
|
|
35
|
+
return new CodexSubprocessProvider();
|
|
36
|
+
}
|
|
37
|
+
// 6. Disabled
|
|
38
|
+
return new DisabledProvider();
|
|
39
|
+
}
|
|
40
|
+
// ---------------------------------------------------------------------------
|
|
41
|
+
// Provider implementations
|
|
42
|
+
// ---------------------------------------------------------------------------
|
|
43
|
+
class McpSamplingProvider {
|
|
44
|
+
server;
|
|
45
|
+
name = 'mcp-sampling';
|
|
46
|
+
constructor(server) {
|
|
47
|
+
this.server = server;
|
|
48
|
+
}
|
|
49
|
+
available() {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
async complete(opts) {
|
|
53
|
+
const result = await this.server.createMessage({
|
|
54
|
+
messages: [{ role: 'user', content: { type: 'text', text: opts.prompt } }],
|
|
55
|
+
systemPrompt: opts.system,
|
|
56
|
+
maxTokens: opts.maxTokens,
|
|
57
|
+
modelPreferences: {
|
|
58
|
+
hints: [{ name: 'haiku' }],
|
|
59
|
+
costPriority: 0.8,
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
return result.content.text ?? '';
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
class OllamaProvider {
|
|
66
|
+
baseUrl;
|
|
67
|
+
name = 'ollama';
|
|
68
|
+
constructor(baseUrl) {
|
|
69
|
+
this.baseUrl = baseUrl;
|
|
70
|
+
}
|
|
71
|
+
available() {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
async complete(opts) {
|
|
75
|
+
const model = process.env['PINAKES_OLLAMA_MODEL'] ?? 'llama3.2';
|
|
76
|
+
const url = `${this.baseUrl.replace(/\/$/, '')}/api/chat`;
|
|
77
|
+
const res = await fetch(url, {
|
|
78
|
+
method: 'POST',
|
|
79
|
+
headers: { 'Content-Type': 'application/json' },
|
|
80
|
+
body: JSON.stringify({
|
|
81
|
+
model,
|
|
82
|
+
messages: [
|
|
83
|
+
{ role: 'system', content: opts.system },
|
|
84
|
+
{ role: 'user', content: opts.prompt },
|
|
85
|
+
],
|
|
86
|
+
stream: false,
|
|
87
|
+
options: { num_predict: opts.maxTokens },
|
|
88
|
+
}),
|
|
89
|
+
});
|
|
90
|
+
if (!res.ok)
|
|
91
|
+
throw new Error(`Ollama ${res.status}: ${await res.text()}`);
|
|
92
|
+
const data = (await res.json());
|
|
93
|
+
return data.message?.content ?? '';
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
class AnthropicApiProvider {
|
|
97
|
+
apiKey;
|
|
98
|
+
name = 'anthropic-api';
|
|
99
|
+
constructor(apiKey) {
|
|
100
|
+
this.apiKey = apiKey;
|
|
101
|
+
}
|
|
102
|
+
available() {
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
async complete(opts) {
|
|
106
|
+
const res = await fetch('https://api.anthropic.com/v1/messages', {
|
|
107
|
+
method: 'POST',
|
|
108
|
+
headers: {
|
|
109
|
+
'Content-Type': 'application/json',
|
|
110
|
+
'x-api-key': this.apiKey,
|
|
111
|
+
'anthropic-version': '2023-06-01',
|
|
112
|
+
},
|
|
113
|
+
body: JSON.stringify({
|
|
114
|
+
model: 'claude-haiku-4-5-20251001',
|
|
115
|
+
max_tokens: opts.maxTokens,
|
|
116
|
+
system: opts.system,
|
|
117
|
+
messages: [{ role: 'user', content: opts.prompt }],
|
|
118
|
+
}),
|
|
119
|
+
});
|
|
120
|
+
if (!res.ok)
|
|
121
|
+
throw new Error(`Anthropic API ${res.status}: ${await res.text()}`);
|
|
122
|
+
const data = (await res.json());
|
|
123
|
+
return data.content?.[0]?.text ?? '';
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
class OpenAiApiProvider {
|
|
127
|
+
apiKey;
|
|
128
|
+
name = 'openai-api';
|
|
129
|
+
constructor(apiKey) {
|
|
130
|
+
this.apiKey = apiKey;
|
|
131
|
+
}
|
|
132
|
+
available() {
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
async complete(opts) {
|
|
136
|
+
const res = await fetch('https://api.openai.com/v1/chat/completions', {
|
|
137
|
+
method: 'POST',
|
|
138
|
+
headers: {
|
|
139
|
+
'Content-Type': 'application/json',
|
|
140
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
141
|
+
},
|
|
142
|
+
body: JSON.stringify({
|
|
143
|
+
model: 'gpt-4o-mini',
|
|
144
|
+
max_tokens: opts.maxTokens,
|
|
145
|
+
messages: [
|
|
146
|
+
{ role: 'system', content: opts.system },
|
|
147
|
+
{ role: 'user', content: opts.prompt },
|
|
148
|
+
],
|
|
149
|
+
}),
|
|
150
|
+
});
|
|
151
|
+
if (!res.ok)
|
|
152
|
+
throw new Error(`OpenAI API ${res.status}: ${await res.text()}`);
|
|
153
|
+
const data = (await res.json());
|
|
154
|
+
return data.choices?.[0]?.message?.content ?? '';
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
class ClaudeSubprocessProvider {
|
|
158
|
+
name = 'claude-subprocess';
|
|
159
|
+
available() {
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
async complete(opts) {
|
|
163
|
+
return runSubprocess('claude', [
|
|
164
|
+
'-p', opts.prompt,
|
|
165
|
+
'--bare',
|
|
166
|
+
'--tools', '',
|
|
167
|
+
'--model', 'haiku',
|
|
168
|
+
'--system-prompt', opts.system,
|
|
169
|
+
'--output-format', 'text',
|
|
170
|
+
'--max-tokens', String(opts.maxTokens),
|
|
171
|
+
]);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
class CodexSubprocessProvider {
|
|
175
|
+
name = 'codex-subprocess';
|
|
176
|
+
available() {
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
async complete(opts) {
|
|
180
|
+
return runSubprocess('codex', [
|
|
181
|
+
'exec',
|
|
182
|
+
`${opts.system}\n\n${opts.prompt}`,
|
|
183
|
+
'--ephemeral',
|
|
184
|
+
'--skip-git-repo-check',
|
|
185
|
+
'--sandbox', 'read-only',
|
|
186
|
+
]);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
class DisabledProvider {
|
|
190
|
+
name = 'disabled';
|
|
191
|
+
available() {
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
async complete() {
|
|
195
|
+
throw new Error('No LLM provider available. Set PINAKES_OLLAMA_URL, ANTHROPIC_API_KEY, or ' +
|
|
196
|
+
'OPENAI_API_KEY, or install claude/codex CLI.');
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
// ---------------------------------------------------------------------------
|
|
200
|
+
// Helpers
|
|
201
|
+
// ---------------------------------------------------------------------------
|
|
202
|
+
/** Check if a binary exists in PATH (synchronous, cached). */
|
|
203
|
+
const binaryCache = new Map();
|
|
204
|
+
function whichSync(name) {
|
|
205
|
+
const cached = binaryCache.get(name);
|
|
206
|
+
if (cached !== undefined)
|
|
207
|
+
return cached;
|
|
208
|
+
try {
|
|
209
|
+
const { execFileSync } = require('node:child_process');
|
|
210
|
+
execFileSync('which', [name], { stdio: 'ignore' });
|
|
211
|
+
binaryCache.set(name, true);
|
|
212
|
+
return true;
|
|
213
|
+
}
|
|
214
|
+
catch {
|
|
215
|
+
binaryCache.set(name, false);
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
/** Run a CLI tool and return its stdout. Timeout: 30s. */
|
|
220
|
+
function runSubprocess(cmd, args) {
|
|
221
|
+
return new Promise((resolve, reject) => {
|
|
222
|
+
execFile(cmd, args, { timeout: 30_000, maxBuffer: 1024 * 1024 }, (err, stdout, stderr) => {
|
|
223
|
+
if (err) {
|
|
224
|
+
logger.warn({ err, cmd, stderr: stderr?.slice(0, 200) }, 'subprocess LLM call failed');
|
|
225
|
+
reject(new Error(`${cmd} failed: ${err.message}`));
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
resolve(stdout.trim());
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
// Export for testing
|
|
233
|
+
export { DisabledProvider as _DisabledProvider };
|
|
234
|
+
export { whichSync as _whichSync };
|
|
235
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/llm/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AA2CpD;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,SAAyB;IACzD,kBAAkB;IAClB,IAAI,SAAS,EAAE,CAAC;QACd,MAAM,QAAQ,GAAG,SAAS,CAAC,qBAAqB,EAAE,EAAE,EAAE,QAAQ,CAAC;QAC/D,IAAI,QAAQ,IAAI,SAAS,CAAC,aAAa,EAAE,CAAC;YACxC,OAAO,IAAI,mBAAmB,CAAC,SAAS,CAAC,CAAC;QAC5C,CAAC;IACH,CAAC;IAED,YAAY;IACZ,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;IACpD,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,IAAI,cAAc,CAAC,SAAS,CAAC,CAAC;IACvC,CAAC;IAED,mCAAmC;IACnC,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IACtD,IAAI,YAAY,EAAE,CAAC;QACjB,OAAO,IAAI,oBAAoB,CAAC,YAAY,CAAC,CAAC;IAChD,CAAC;IACD,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;IAChD,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,IAAI,iBAAiB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CAAC;gBACR,MAAM,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,EAAE,4BAA4B,CAAC,CAAC;gBACvF,MAAM,CAAC,IAAI,KAAK,CAAC,GAAG,GAAG,YAAY,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;gBACnD,OAAO;YACT,CAAC;YACD,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;QACzB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED,qBAAqB;AACrB,OAAO,EAAE,gBAAgB,IAAI,iBAAiB,EAAE,CAAC;AACjD,OAAO,EAAE,SAAS,IAAI,UAAU,EAAE,CAAC"}
|
package/dist/mcp/envelope.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export interface EnvelopeMeta {
|
|
|
25
25
|
stale_files: string[];
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
|
-
* The canonical response wrapper for both `
|
|
28
|
+
* The canonical response wrapper for both `search` and `execute`.
|
|
29
29
|
*
|
|
30
30
|
* `result` is the tool-specific payload. `meta` is always present and
|
|
31
31
|
* always has every field populated. `logs` is optional — present when the
|
|
@@ -3,7 +3,7 @@ import type { Repository } from '../../db/repository.js';
|
|
|
3
3
|
import type { DbBundle } from '../../db/client.js';
|
|
4
4
|
import type { QuickJSExecutor } from '../../sandbox/executor.js';
|
|
5
5
|
import type { Embedder } from '../../retrieval/embedder.js';
|
|
6
|
-
export declare const
|
|
6
|
+
export declare const executeInputShape: {
|
|
7
7
|
code: z.ZodString;
|
|
8
8
|
max_tokens: z.ZodOptional<z.ZodNumber>;
|
|
9
9
|
timeout_ms: z.ZodOptional<z.ZodNumber>;
|
|
@@ -13,8 +13,8 @@ export declare const kgExecuteInputShape: {
|
|
|
13
13
|
both: "both";
|
|
14
14
|
}>>;
|
|
15
15
|
};
|
|
16
|
-
export declare const
|
|
17
|
-
readonly title: "
|
|
16
|
+
export declare const executeToolConfig: {
|
|
17
|
+
readonly title: "Query or update the project knowledge base";
|
|
18
18
|
readonly description: string;
|
|
19
19
|
readonly inputSchema: {
|
|
20
20
|
code: z.ZodString;
|
|
@@ -27,7 +27,7 @@ export declare const kgExecuteToolConfig: {
|
|
|
27
27
|
}>>;
|
|
28
28
|
};
|
|
29
29
|
};
|
|
30
|
-
export interface
|
|
30
|
+
export interface ExecuteDeps {
|
|
31
31
|
repository: Repository;
|
|
32
32
|
executor: QuickJSExecutor;
|
|
33
33
|
bundle: DbBundle;
|
|
@@ -37,10 +37,10 @@ export interface KgExecuteDeps {
|
|
|
37
37
|
personalWikiRoot?: string;
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
|
-
* Build the `
|
|
41
|
-
* with the full `
|
|
40
|
+
* Build the `execute` handler. Phase 3 path: uses `executeWithBindings`
|
|
41
|
+
* with the full `pinakes.project.*` surface via the warm pool.
|
|
42
42
|
*/
|
|
43
|
-
export declare function
|
|
43
|
+
export declare function makeExecuteHandler(deps: ExecuteDeps): (args: {
|
|
44
44
|
code: string;
|
|
45
45
|
max_tokens?: number;
|
|
46
46
|
timeout_ms?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../../src/mcp/tools/execute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../../src/mcp/tools/execute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAwC5D,eAAO,MAAM,iBAAiB;;;;;;;;;CAuC7B,CAAC;AAEF,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;CAYpB,CAAC;AAEX,MAAM,WAAW,WAAW;IAC1B,UAAU,EAAE,UAAU,CAAC;IACvB,QAAQ,EAAE,eAAe,CAAC;IAC1B,MAAM,EAAE,QAAQ,CAAC;IACjB,QAAQ,EAAE,QAAQ,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,QAAQ,CAAC;IAC1B,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,WAAW,IACpC,MAAM;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,SAAS,GAAG,UAAU,GAAG,MAAM,CAAC;CACzC,KAAG,OAAO,CAAC;IAAE,OAAO,EAAE,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC,CA8F9E"}
|
|
@@ -2,60 +2,49 @@ import { z } from 'zod';
|
|
|
2
2
|
import { countEnvelopeTokens, countTokens, computeInternalBudget, fitResults } from '../../gate/budget.js';
|
|
3
3
|
import { buildEnvelope, QueryTimer } from '../envelope.js';
|
|
4
4
|
/**
|
|
5
|
-
* `
|
|
6
|
-
* it inside the QuickJS sandbox against the `
|
|
5
|
+
* `execute` — code-mode tool. The LLM writes a short JS snippet, we run
|
|
6
|
+
* it inside the QuickJS sandbox against the `pinakes` bindings, and return the
|
|
7
7
|
* (budget-shaped) result.
|
|
8
8
|
*
|
|
9
|
-
* Phase 3: full `
|
|
10
|
-
* `
|
|
9
|
+
* Phase 3: full `pinakes.project.*` binding surface via warm pool. Backward-compat
|
|
10
|
+
* `pinakes.search()`/`pinakes.get()` aliases remain.
|
|
11
11
|
*/
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
get(id: string):
|
|
12
|
+
const EXECUTE_TYPES = `
|
|
13
|
+
type Node = { id: string; source_uri: string; title: string | null; section_path: string };
|
|
14
|
+
type Chunk = Node & { text: string; node_id: string };
|
|
15
|
+
declare const pinakes: {
|
|
16
|
+
search(query: string): Chunk[];
|
|
17
|
+
get(id: string): Chunk | null;
|
|
18
18
|
project: {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
/** Node lookup by id — full section content. */
|
|
28
|
-
get(id: string): { id: string; source_uri: string; section_path: string; kind: string; title: string | null; content: string; token_count: number } | null;
|
|
29
|
-
/** K-hop graph traversal. */
|
|
30
|
-
neighbors(id: string, opts?: { depth?: number; edge_kinds?: string[] }): Array<{ id: string; source_uri: string; kind: string; title: string | null; depth: number }>;
|
|
31
|
-
log: {
|
|
32
|
-
/** Recent log entries. */
|
|
33
|
-
recent(n?: number, opts?: { kind?: string }): Array<{ id: number; ts: number; kind: string; source_uri: string | null; payload: unknown }>;
|
|
34
|
-
};
|
|
35
|
-
/** Concept gaps — topics mentioned ≥3 times with no dedicated wiki page. Check these to find what the wiki is missing, then write() to fill them. */
|
|
36
|
-
gaps(opts?: { resolved?: boolean }): Array<{ id: number; topic: string; first_seen_at: number; mentions_count: number; resolved_at: number | null }>;
|
|
37
|
-
/** Create or overwrite a wiki page. Path is relative to wiki root, .md extension enforced. */
|
|
19
|
+
fts(query: string, opts?: { limit?: number }): (Chunk & { rank: number })[];
|
|
20
|
+
vec(query: string, opts?: { limit?: number }): (Chunk & { distance: number })[];
|
|
21
|
+
hybrid(query: string, opts?: { limit?: number; rrf_k?: number }): (Chunk & { score: number; snippet?: string })[];
|
|
22
|
+
index(opts?: { kind?: string; source_uri?: string; limit?: number }): (Node & { kind: string; token_count: number })[];
|
|
23
|
+
get(id: string): (Node & { kind: string; content: string; token_count: number }) | null;
|
|
24
|
+
neighbors(id: string, opts?: { depth?: number; edge_kinds?: string[] }): (Node & { depth: number })[];
|
|
25
|
+
log: { recent(n?: number, opts?: { kind?: string }): Array<{ id: number; ts: number; kind: string; source_uri: string | null; payload: unknown }> };
|
|
26
|
+
gaps(opts?: { resolved?: boolean }): Array<{ id: number; topic: string; mentions_count: number; resolved_at: number | null }>;
|
|
38
27
|
write(path: string, content: string): { path: string; bytes: number };
|
|
39
|
-
/** Append a timestamped entry to log.md. */
|
|
40
28
|
append(entry: string): { path: string; bytes: number };
|
|
41
|
-
/** Delete a wiki page. Path is relative to wiki root. */
|
|
42
29
|
remove(path: string): { path: string; removed: true };
|
|
30
|
+
pagerank(opts?: { limit?: number }): (Node & { score: number })[];
|
|
31
|
+
components(): Array<{ component_id: number; nodes: Node[] }>;
|
|
43
32
|
};
|
|
44
33
|
};
|
|
45
34
|
declare const budget: { fit(items: unknown[], maxTokens?: number): unknown[] };
|
|
46
35
|
declare const logger: { log(...args: unknown[]): void };
|
|
47
36
|
`.trim();
|
|
48
|
-
export const
|
|
37
|
+
export const executeInputShape = {
|
|
49
38
|
code: z
|
|
50
39
|
.string()
|
|
51
40
|
.min(1)
|
|
52
41
|
.describe('JavaScript to run inside the sandbox. The sandbox is QuickJS with ' +
|
|
53
42
|
'`eval`, `Function`, `fetch`, `require`, `process`, and `constructor` ' +
|
|
54
|
-
'removed. You have `
|
|
43
|
+
'removed. You have `pinakes.project.*` for FTS, graph traversal, log ' +
|
|
55
44
|
'queries, and wiki writes (write/append/remove), plus `budget.fit()` ' +
|
|
56
45
|
'for token-aware truncation and `logger.log()` captured into ' +
|
|
57
46
|
'`response.logs`. Return a value.\n' +
|
|
58
|
-
|
|
47
|
+
EXECUTE_TYPES),
|
|
59
48
|
max_tokens: z
|
|
60
49
|
.number()
|
|
61
50
|
.int()
|
|
@@ -74,33 +63,26 @@ export const kgExecuteInputShape = {
|
|
|
74
63
|
scope: z
|
|
75
64
|
.enum(['project', 'personal', 'both'])
|
|
76
65
|
.optional()
|
|
77
|
-
.describe('Which
|
|
78
|
-
'"personal" installs
|
|
66
|
+
.describe('Which bindings to inject. "project" (default) installs pinakes.project, ' +
|
|
67
|
+
'"personal" installs pinakes.personal, "both" installs both namespaces.'),
|
|
79
68
|
};
|
|
80
|
-
export const
|
|
81
|
-
title: '
|
|
82
|
-
description: 'Run
|
|
83
|
-
'
|
|
84
|
-
'
|
|
85
|
-
'
|
|
86
|
-
'
|
|
87
|
-
'
|
|
88
|
-
'
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
'to delete.\n\n' +
|
|
92
|
-
'Gaps: `kg.project.gaps()` returns concepts mentioned ≥3 times in the wiki ' +
|
|
93
|
-
'that have no dedicated page — use this to discover what knowledge is missing ' +
|
|
94
|
-
'and fill it with write().\n\n' +
|
|
95
|
-
'64MB memory cap, 2s default timeout. No network, no eval.\n\n' +
|
|
96
|
-
KG_EXECUTE_TYPES,
|
|
97
|
-
inputSchema: kgExecuteInputShape,
|
|
69
|
+
export const executeToolConfig = {
|
|
70
|
+
title: 'Query or update the project knowledge base',
|
|
71
|
+
description: 'Run JS against the project knowledge base for advanced operations.\n\n' +
|
|
72
|
+
'Read: index() for TOC, get(id) for full content, hybrid() for semantic search, ' +
|
|
73
|
+
'neighbors() for related topics, pagerank() for key concepts, components() for topic clusters.\n' +
|
|
74
|
+
'Write: write(path, content), append(entry), remove(path) to capture new knowledge.\n' +
|
|
75
|
+
'Gaps: gaps() finds under-documented areas.\n\n' +
|
|
76
|
+
'Use this over `search` when you need to chain queries, browse the knowledge graph, ' +
|
|
77
|
+
'or write back what you learn. 64MB memory, 2s timeout. No network/eval.\n\n' +
|
|
78
|
+
EXECUTE_TYPES,
|
|
79
|
+
inputSchema: executeInputShape,
|
|
98
80
|
};
|
|
99
81
|
/**
|
|
100
|
-
* Build the `
|
|
101
|
-
* with the full `
|
|
82
|
+
* Build the `execute` handler. Phase 3 path: uses `executeWithBindings`
|
|
83
|
+
* with the full `pinakes.project.*` surface via the warm pool.
|
|
102
84
|
*/
|
|
103
|
-
export function
|
|
85
|
+
export function makeExecuteHandler(deps) {
|
|
104
86
|
return async (args) => {
|
|
105
87
|
const timer = new QueryTimer();
|
|
106
88
|
const maxTokens = args.max_tokens ?? 5000;
|
|
@@ -109,8 +91,8 @@ export function makeKgExecuteHandler(deps) {
|
|
|
109
91
|
if ((scope === 'personal' || scope === 'both') && !deps.personalBundle) {
|
|
110
92
|
const envelope = buildEnvelope({
|
|
111
93
|
result: {
|
|
112
|
-
error: 'personal scope requested but no personal
|
|
113
|
-
'
|
|
94
|
+
error: 'personal scope requested but no personal wiki is configured — ' +
|
|
95
|
+
'create a personal wiki at ~/.pinakes/wiki/ or pass --profile-path',
|
|
114
96
|
},
|
|
115
97
|
tokensBudgeted: maxTokens,
|
|
116
98
|
tokensUsed: 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execute.js","sourceRoot":"","sources":["../../../src/mcp/tools/execute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,qBAAqB,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC3G,OAAO,EAAE,aAAa,EAAE,UAAU,EAAc,MAAM,gBAAgB,CAAC;AAGvE;;;;;;;GAOG;AA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DbBundle } from '../../db/client.js';
|
|
4
4
|
import type { Embedder } from '../../retrieval/embedder.js';
|
|
5
|
+
import type { LlmProvider } from '../../llm/provider.js';
|
|
5
6
|
/**
|
|
6
|
-
* `
|
|
7
|
+
* `search` — fast-path hybrid search against the project knowledge base.
|
|
7
8
|
*
|
|
8
9
|
* Phase 5: supports all three scopes. For `scope='both'`, results from
|
|
9
|
-
* both
|
|
10
|
+
* both knowledge bases are merged and tagged with `source_scope`.
|
|
10
11
|
*/
|
|
11
|
-
export declare const
|
|
12
|
+
export declare const searchInputShape: {
|
|
12
13
|
query: z.ZodString;
|
|
13
14
|
max_tokens: z.ZodOptional<z.ZodNumber>;
|
|
14
15
|
scope: z.ZodOptional<z.ZodEnum<{
|
|
@@ -16,9 +17,10 @@ export declare const kgSearchInputShape: {
|
|
|
16
17
|
personal: "personal";
|
|
17
18
|
both: "both";
|
|
18
19
|
}>>;
|
|
20
|
+
expand: z.ZodOptional<z.ZodBoolean>;
|
|
19
21
|
};
|
|
20
|
-
export declare const
|
|
21
|
-
readonly title: "Search
|
|
22
|
+
export declare const searchToolConfig: {
|
|
23
|
+
readonly title: "Search project knowledge base";
|
|
22
24
|
readonly description: string;
|
|
23
25
|
readonly inputSchema: {
|
|
24
26
|
query: z.ZodString;
|
|
@@ -28,21 +30,24 @@ export declare const kgSearchToolConfig: {
|
|
|
28
30
|
personal: "personal";
|
|
29
31
|
both: "both";
|
|
30
32
|
}>>;
|
|
33
|
+
expand: z.ZodOptional<z.ZodBoolean>;
|
|
31
34
|
};
|
|
32
35
|
};
|
|
33
|
-
export interface
|
|
36
|
+
export interface SearchDeps {
|
|
34
37
|
repository: Repository;
|
|
35
38
|
embedder: Embedder;
|
|
36
39
|
bundle: DbBundle;
|
|
37
40
|
personalBundle?: DbBundle;
|
|
41
|
+
llmProvider?: LlmProvider;
|
|
38
42
|
}
|
|
39
43
|
/**
|
|
40
|
-
* Build the `
|
|
44
|
+
* Build the `search` handler. Supports project, personal, and both scopes.
|
|
41
45
|
*/
|
|
42
|
-
export declare function
|
|
46
|
+
export declare function makeSearchHandler(deps: SearchDeps): (args: {
|
|
43
47
|
query: string;
|
|
44
48
|
max_tokens?: number;
|
|
45
49
|
scope?: "project" | "personal" | "both";
|
|
50
|
+
expand?: boolean;
|
|
46
51
|
}) => Promise<{
|
|
47
52
|
content: [{
|
|
48
53
|
type: "text";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../../src/mcp/tools/search.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../../src/mcp/tools/search.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAQzD;;;;;GAKG;AAEH,eAAO,MAAM,gBAAgB;;;;;;;;;CAqC5B,CAAC;AAEF,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;CAYnB,CAAC;AAEX,MAAM,WAAW,UAAU;IACzB,UAAU,EAAE,UAAU,CAAC;IACvB,QAAQ,EAAE,QAAQ,CAAC;IACnB,MAAM,EAAE,QAAQ,CAAC;IACjB,cAAc,CAAC,EAAE,QAAQ,CAAC;IAC1B,WAAW,CAAC,EAAE,WAAW,CA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