wyrm-mcp 7.2.0 → 7.2.2
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/LICENSE +26 -667
- package/NOTICE +14 -33
- package/dist/activation.d.ts.map +1 -1
- package/dist/activation.js +1 -44
- package/dist/activation.js.map +1 -1
- package/dist/agent-daemon.js +4 -281
- package/dist/agent-loop.js +7 -332
- package/dist/analytics.js +13 -236
- package/dist/attribution.js +1 -49
- package/dist/audit.js +2 -457
- package/dist/auto-capture.js +3 -138
- package/dist/auto-orchestrator.js +1 -325
- package/dist/autoconfig.js +39 -840
- package/dist/buddy-runner.js +1 -109
- package/dist/buddy.js +14 -564
- package/dist/build-flags.js +1 -17
- package/dist/capabilities.js +3 -183
- package/dist/capture.js +1 -56
- package/dist/causality.js +6 -107
- package/dist/cli.js +20 -281
- package/dist/cloud/cli.js +5 -541
- package/dist/cloud/client.js +1 -221
- package/dist/cloud/crypto.js +1 -85
- package/dist/cloud/machine-id.js +2 -113
- package/dist/cloud/recovery.js +1 -60
- package/dist/cloud/sync-engine.js +7 -543
- package/dist/cloud-backup.js +5 -579
- package/dist/cloud-profile.js +1 -138
- package/dist/cloud-sync-entrypoint.js +1 -47
- package/dist/cloud-sync.js +2 -309
- package/dist/constellation.js +12 -168
- package/dist/context-build-budgeted.js +4 -144
- package/dist/context-ranking.js +1 -69
- package/dist/crypto.js +1 -179
- package/dist/daemon-write-endpoint.js +1 -290
- package/dist/daemon-writer.js +2 -406
- package/dist/database.js +43 -1110
- package/dist/deprecations.js +2 -162
- package/dist/design.js +13 -141
- package/dist/event-replication.js +1 -112
- package/dist/events-sse.js +7 -43
- package/dist/events.js +6 -238
- package/dist/failure-patterns.js +42 -659
- package/dist/federation.js +12 -236
- package/dist/goals.js +13 -101
- package/dist/golden.js +3 -355
- package/dist/handlers/agent.js +4 -165
- package/dist/handlers/alias-adapters.js +1 -129
- package/dist/handlers/aliases.js +1 -171
- package/dist/handlers/audit.js +1 -87
- package/dist/handlers/boundary.js +1 -221
- package/dist/handlers/capture.js +73 -1109
- package/dist/handlers/causality.js +7 -114
- package/dist/handlers/cloud.js +85 -382
- package/dist/handlers/companion.js +28 -459
- package/dist/handlers/datalake.js +7 -187
- package/dist/handlers/dispatch-context.js +0 -22
- package/dist/handlers/entity.js +25 -256
- package/dist/handlers/events.js +16 -335
- package/dist/handlers/failure.js +13 -340
- package/dist/handlers/goals.js +4 -296
- package/dist/handlers/intelligence.js +126 -674
- package/dist/handlers/invoicing.js +1 -70
- package/dist/handlers/mcpclient.js +6 -137
- package/dist/handlers/orchestration.js +40 -125
- package/dist/handlers/output-schemas.js +1 -24
- package/dist/handlers/presence.js +3 -99
- package/dist/handlers/project.js +28 -182
- package/dist/handlers/prompts.js +6 -157
- package/dist/handlers/quest.js +4 -224
- package/dist/handlers/recall.js +11 -218
- package/dist/handlers/registry.js +1 -167
- package/dist/handlers/resources.js +1 -288
- package/dist/handlers/review.js +11 -74
- package/dist/handlers/run.js +17 -487
- package/dist/handlers/search.js +15 -326
- package/dist/handlers/session.js +28 -615
- package/dist/handlers/share.js +8 -184
- package/dist/handlers/shims.js +1 -464
- package/dist/handlers/skill.js +67 -449
- package/dist/handlers/survivors.js +1 -120
- package/dist/handlers/symbols.js +8 -109
- package/dist/handlers/syncops.js +4 -302
- package/dist/handlers/types.js +1 -27
- package/dist/harvest.js +5 -191
- package/dist/hours.js +7 -156
- package/dist/http-auth.js +3 -321
- package/dist/http-fast.js +21 -1137
- package/dist/icons.js +1 -47
- package/dist/index.js +2 -924
- package/dist/indexer.js +4 -145
- package/dist/intelligence.js +31 -261
- package/dist/internal-dispatch.js +3 -212
- package/dist/keyset.js +1 -110
- package/dist/knowledge-graph.js +12 -176
- package/dist/license.d.ts +11 -0
- package/dist/license.d.ts.map +1 -1
- package/dist/license.js +2 -414
- package/dist/license.js.map +1 -1
- package/dist/logger.js +2 -199
- package/dist/maintenance.js +2 -148
- package/dist/mcp-client.js +6 -262
- package/dist/memory-artifacts.js +30 -449
- package/dist/migrate-prompt.js +2 -124
- package/dist/migrations.js +40 -655
- package/dist/performance.js +1 -228
- package/dist/presence.js +11 -140
- package/dist/priority-embed.js +5 -164
- package/dist/providers/embedding-provider.js +1 -196
- package/dist/readonly-gate.js +1 -29
- package/dist/rehydration.js +9 -157
- package/dist/reindex.js +1 -88
- package/dist/render-target.js +21 -514
- package/dist/render.js +4 -280
- package/dist/repl-guard.js +1 -173
- package/dist/replication-daemon-entrypoint.js +1 -31
- package/dist/replication-daemon.js +2 -262
- package/dist/resilience.js +1 -591
- package/dist/reverse-bridge.js +5 -360
- package/dist/security.js +1 -244
- package/dist/session-seen.js +3 -51
- package/dist/setup.js +1 -260
- package/dist/skill-author.js +5 -168
- package/dist/spec-kit.js +1 -191
- package/dist/sqlite-busy.js +1 -154
- package/dist/statusline.js +11 -315
- package/dist/sub-agent.js +13 -262
- package/dist/summarizer.js +13 -139
- package/dist/symbols.js +7 -283
- package/dist/sync.js +5 -359
- package/dist/tasks-dispatch.js +1 -84
- package/dist/tasks.js +1 -282
- package/dist/token-budget.js +1 -143
- package/dist/tool-analytics.js +7 -129
- package/dist/tool-annotations.js +1 -365
- package/dist/tool-manifest-v2.json +1 -1
- package/dist/tool-manifest.json +1 -1
- package/dist/tool-profiles.js +1 -75
- package/dist/trace-harvest.js +6 -244
- package/dist/types.js +1 -30
- package/dist/ui-dashboard.js +41 -50
- package/dist/ulid.js +1 -81
- package/dist/validate.js +1 -129
- package/dist/vault.js +1 -534
- package/dist/vectors.js +3 -184
- package/dist/version-check.js +4 -136
- package/dist/visibility.js +19 -155
- package/dist/wyrm-cli.js +98 -2451
- package/dist/wyrm-cli.js.map +1 -1
- package/dist/wyrm-guard.js +14 -424
- package/dist/wyrm-loop.js +3 -150
- package/dist/wyrm-manifest.json +1 -1
- package/dist/wyrm-statusline-daemon.js +1 -11
- package/dist/wyrm-statusline.js +4 -56
- package/dist/wyrm-ui.js +9 -77
- package/package.json +4 -2
package/dist/sync.js
CHANGED
|
@@ -1,359 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
* Wyrm
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
* - Watches for changes to markdown files
|
|
8
|
-
* - Syncs changes to SQLite database
|
|
9
|
-
* - Exports database state back to markdown
|
|
10
|
-
*/
|
|
11
|
-
import { watch, existsSync, readFileSync, writeFileSync, mkdirSync, statSync } from 'fs';
|
|
12
|
-
import { join, basename, resolve, normalize, relative, sep } from 'path';
|
|
13
|
-
// ==================== PATH SECURITY ====================
|
|
14
|
-
/**
|
|
15
|
-
* SECURITY: Validate path is within the base directory
|
|
16
|
-
*/
|
|
17
|
-
function validatePath(basePath, targetPath) {
|
|
18
|
-
const normalizedBase = normalize(resolve(basePath));
|
|
19
|
-
const normalizedTarget = normalize(resolve(basePath, targetPath));
|
|
20
|
-
// Check if target is within base
|
|
21
|
-
const rel = relative(normalizedBase, normalizedTarget);
|
|
22
|
-
if (rel.startsWith('..') || rel.startsWith(sep)) {
|
|
23
|
-
throw new Error('SECURITY: Path traversal detected');
|
|
24
|
-
}
|
|
25
|
-
if (!normalizedTarget.startsWith(normalizedBase)) {
|
|
26
|
-
throw new Error('SECURITY: Path traversal detected');
|
|
27
|
-
}
|
|
28
|
-
return normalizedTarget;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* SECURITY: Validate project path is a real directory
|
|
32
|
-
*/
|
|
33
|
-
function validateProjectPath(projectPath) {
|
|
34
|
-
const normalizedPath = normalize(resolve(projectPath));
|
|
35
|
-
if (!existsSync(normalizedPath)) {
|
|
36
|
-
throw new Error(`Project path does not exist: ${projectPath}`);
|
|
37
|
-
}
|
|
38
|
-
if (!statSync(normalizedPath).isDirectory()) {
|
|
39
|
-
throw new Error(`Project path is not a directory: ${projectPath}`);
|
|
40
|
-
}
|
|
41
|
-
return normalizedPath;
|
|
42
|
-
}
|
|
43
|
-
export class WyrmSync {
|
|
44
|
-
db;
|
|
45
|
-
watchers = new Map();
|
|
46
|
-
constructor(db) {
|
|
47
|
-
this.db = db;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Import markdown files from .wyrm folder into database
|
|
51
|
-
*/
|
|
52
|
-
importFromFolder(projectPath) {
|
|
53
|
-
// SECURITY: Validate project path
|
|
54
|
-
const validatedPath = validateProjectPath(projectPath);
|
|
55
|
-
const wyrmPath = validatePath(validatedPath, '.wyrm');
|
|
56
|
-
if (!existsSync(wyrmPath)) {
|
|
57
|
-
throw new Error(`No .wyrm folder found at ${validatedPath}`);
|
|
58
|
-
}
|
|
59
|
-
// Get or create project
|
|
60
|
-
const projectName = basename(validatedPath);
|
|
61
|
-
let project = this.db.getProject(validatedPath);
|
|
62
|
-
if (!project) {
|
|
63
|
-
project = this.db.registerProject(projectName, validatedPath);
|
|
64
|
-
}
|
|
65
|
-
// Import hoard.md - SECURITY: validatePath ensures no traversal
|
|
66
|
-
const hoardPath = validatePath(wyrmPath, 'hoard.md');
|
|
67
|
-
if (existsSync(hoardPath)) {
|
|
68
|
-
const content = readFileSync(hoardPath, 'utf-8');
|
|
69
|
-
this.parseHoard(project.id, content);
|
|
70
|
-
}
|
|
71
|
-
// Import chronicles.md
|
|
72
|
-
const chroniclesPath = validatePath(wyrmPath, 'chronicles.md');
|
|
73
|
-
if (existsSync(chroniclesPath)) {
|
|
74
|
-
const content = readFileSync(chroniclesPath, 'utf-8');
|
|
75
|
-
this.parseChronicles(project.id, content);
|
|
76
|
-
}
|
|
77
|
-
// Import quests.md
|
|
78
|
-
const questsPath = validatePath(wyrmPath, 'quests.md');
|
|
79
|
-
if (existsSync(questsPath)) {
|
|
80
|
-
const content = readFileSync(questsPath, 'utf-8');
|
|
81
|
-
this.parseQuests(project.id, content);
|
|
82
|
-
}
|
|
83
|
-
return project;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Export database state to .wyrm folder
|
|
87
|
-
*/
|
|
88
|
-
exportToFolder(projectPath) {
|
|
89
|
-
// SECURITY: Validate project path
|
|
90
|
-
const validatedPath = validateProjectPath(projectPath);
|
|
91
|
-
const project = this.db.getProject(validatedPath);
|
|
92
|
-
if (!project) {
|
|
93
|
-
throw new Error(`Project not found: ${validatedPath}`);
|
|
94
|
-
}
|
|
95
|
-
const wyrmPath = validatePath(validatedPath, '.wyrm');
|
|
96
|
-
if (!existsSync(wyrmPath)) {
|
|
97
|
-
mkdirSync(wyrmPath, { recursive: true });
|
|
98
|
-
}
|
|
99
|
-
// Export hoard.md - SECURITY: validatePath ensures no traversal
|
|
100
|
-
const hoardContent = this.generateHoard(project);
|
|
101
|
-
writeFileSync(validatePath(wyrmPath, 'hoard.md'), hoardContent);
|
|
102
|
-
// Export chronicles.md
|
|
103
|
-
const chroniclesContent = this.generateChronicles(project.id);
|
|
104
|
-
writeFileSync(validatePath(wyrmPath, 'chronicles.md'), chroniclesContent);
|
|
105
|
-
// Export quests.md
|
|
106
|
-
const questsContent = this.generateQuests(project.id);
|
|
107
|
-
writeFileSync(validatePath(wyrmPath, 'quests.md'), questsContent);
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Watch .wyrm folder for changes
|
|
111
|
-
*/
|
|
112
|
-
watchFolder(projectPath) {
|
|
113
|
-
const wyrmPath = join(projectPath, '.wyrm');
|
|
114
|
-
if (!existsSync(wyrmPath))
|
|
115
|
-
return;
|
|
116
|
-
if (this.watchers.has(projectPath)) {
|
|
117
|
-
this.watchers.get(projectPath).close();
|
|
118
|
-
}
|
|
119
|
-
const watcher = watch(wyrmPath, { recursive: true }, (eventType, filename) => {
|
|
120
|
-
if (filename && filename.endsWith('.md')) {
|
|
121
|
-
console.log(`[Wyrm] File changed: ${filename}`);
|
|
122
|
-
this.importFromFolder(projectPath);
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
this.watchers.set(projectPath, watcher);
|
|
126
|
-
}
|
|
127
|
-
stopWatching(projectPath) {
|
|
128
|
-
const watcher = this.watchers.get(projectPath);
|
|
129
|
-
if (watcher) {
|
|
130
|
-
watcher.close();
|
|
131
|
-
this.watchers.delete(projectPath);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
// Parse hoard.md
|
|
135
|
-
parseHoard(projectId, content) {
|
|
136
|
-
const sections = this.splitSections(content);
|
|
137
|
-
for (const [title, body] of Object.entries(sections)) {
|
|
138
|
-
const key = title.toLowerCase().replace(/[^a-z0-9]+/g, '_');
|
|
139
|
-
this.db.setContext(projectId, key, body);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
// Parse chronicles.md
|
|
143
|
-
parseChronicles(projectId, content) {
|
|
144
|
-
const sessionRegex = /## Session:\s*(\d{4}-\d{2}-\d{2})([\s\S]*?)(?=## Session:|$)/g;
|
|
145
|
-
let match;
|
|
146
|
-
while ((match = sessionRegex.exec(content)) !== null) {
|
|
147
|
-
const date = match[1];
|
|
148
|
-
const body = match[2];
|
|
149
|
-
// Check if session exists
|
|
150
|
-
const existing = this.db.getTodaySession(projectId);
|
|
151
|
-
if (existing && existing.date === date) {
|
|
152
|
-
// Update existing
|
|
153
|
-
this.db.updateSession(existing.id, this.parseSessionBody(body));
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
156
|
-
// Create new
|
|
157
|
-
this.db.createSession(projectId, {
|
|
158
|
-
date,
|
|
159
|
-
...this.parseSessionBody(body)
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
parseSessionBody(body) {
|
|
165
|
-
const result = {};
|
|
166
|
-
const objectives = this.extractSection(body, 'Objectives', 'Mission');
|
|
167
|
-
if (objectives)
|
|
168
|
-
result.objectives = objectives;
|
|
169
|
-
const completed = this.extractSection(body, 'Completed', 'Done', 'Quests Completed');
|
|
170
|
-
if (completed)
|
|
171
|
-
result.completed = completed;
|
|
172
|
-
const issues = this.extractSection(body, 'Issues', 'Problems', 'Battles', 'Fixed');
|
|
173
|
-
if (issues)
|
|
174
|
-
result.issues = issues;
|
|
175
|
-
const commits = this.extractSection(body, 'Commits');
|
|
176
|
-
if (commits)
|
|
177
|
-
result.commits = commits;
|
|
178
|
-
const files = this.extractSection(body, 'Files', 'Changed');
|
|
179
|
-
if (files)
|
|
180
|
-
result.files_changed = files;
|
|
181
|
-
const notes = this.extractSection(body, 'Notes', 'Wisdom');
|
|
182
|
-
if (notes)
|
|
183
|
-
result.notes = notes;
|
|
184
|
-
return result;
|
|
185
|
-
}
|
|
186
|
-
// Parse quests.md
|
|
187
|
-
parseQuests(projectId, content) {
|
|
188
|
-
const lines = content.split('\n');
|
|
189
|
-
let currentPriority = 'medium';
|
|
190
|
-
// Hoist the dedup lookup out of the per-line loop — re-querying every pending
|
|
191
|
-
// quest for every markdown line is O(lines × quests). Build the title set once.
|
|
192
|
-
const existingTitles = new Set(this.db.getPendingQuests(projectId).map((q) => q.title));
|
|
193
|
-
for (const line of lines) {
|
|
194
|
-
// Check for priority headers
|
|
195
|
-
if (line.match(/critical|urgent/i))
|
|
196
|
-
currentPriority = 'critical';
|
|
197
|
-
else if (line.match(/high/i))
|
|
198
|
-
currentPriority = 'high';
|
|
199
|
-
else if (line.match(/medium/i))
|
|
200
|
-
currentPriority = 'medium';
|
|
201
|
-
else if (line.match(/low|future|backlog/i))
|
|
202
|
-
currentPriority = 'low';
|
|
203
|
-
// Check for task items
|
|
204
|
-
const taskMatch = line.match(/^[\s]*[-*]\s*\[([x\s])\]\s*\*?\*?(.+?)\*?\*?\s*$/i);
|
|
205
|
-
if (taskMatch) {
|
|
206
|
-
const isCompleted = taskMatch[1].toLowerCase() === 'x';
|
|
207
|
-
const title = taskMatch[2].trim();
|
|
208
|
-
// Add quest (avoid duplicates by title)
|
|
209
|
-
if (!existingTitles.has(title)) {
|
|
210
|
-
const quest = this.db.addQuest(projectId, title, '', currentPriority);
|
|
211
|
-
if (isCompleted) {
|
|
212
|
-
this.db.updateQuest(quest.id, 'completed');
|
|
213
|
-
}
|
|
214
|
-
existingTitles.add(title);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
// Generate hoard.md from database
|
|
220
|
-
generateHoard(project) {
|
|
221
|
-
const context = this.db.getAllContext(project.id);
|
|
222
|
-
const lines = [
|
|
223
|
-
`# Wyrm Hoard // ${project.name}`,
|
|
224
|
-
'',
|
|
225
|
-
`> **Last Updated:** ${new Date().toISOString().split('T')[0]}`,
|
|
226
|
-
`> **Project:** ${project.name}`,
|
|
227
|
-
project.repo ? `> **Repo:** ${project.repo}` : '',
|
|
228
|
-
'',
|
|
229
|
-
'---',
|
|
230
|
-
''
|
|
231
|
-
];
|
|
232
|
-
// Add all context sections
|
|
233
|
-
for (const [key, value] of Object.entries(context)) {
|
|
234
|
-
const title = key.replace(/_/g, ' ').replace(/\b\w/g, c => c.toUpperCase());
|
|
235
|
-
lines.push(`## ${title}`, '', value, '');
|
|
236
|
-
}
|
|
237
|
-
return lines.filter(l => l !== undefined).join('\n');
|
|
238
|
-
}
|
|
239
|
-
// Generate chronicles.md from database
|
|
240
|
-
generateChronicles(projectId) {
|
|
241
|
-
const sessions = this.db.getRecentSessions(projectId, 20);
|
|
242
|
-
const lines = [
|
|
243
|
-
'# Wyrm Chronicles',
|
|
244
|
-
'',
|
|
245
|
-
'> Session history',
|
|
246
|
-
'',
|
|
247
|
-
'---',
|
|
248
|
-
''
|
|
249
|
-
];
|
|
250
|
-
for (const session of sessions) {
|
|
251
|
-
lines.push(`## Session: ${session.date}`, '');
|
|
252
|
-
if (session.objectives) {
|
|
253
|
-
lines.push('### Objectives', session.objectives, '');
|
|
254
|
-
}
|
|
255
|
-
if (session.completed) {
|
|
256
|
-
lines.push('### Completed', session.completed, '');
|
|
257
|
-
}
|
|
258
|
-
if (session.issues) {
|
|
259
|
-
lines.push('### Issues Solved', session.issues, '');
|
|
260
|
-
}
|
|
261
|
-
if (session.commits) {
|
|
262
|
-
lines.push('### Commits', session.commits, '');
|
|
263
|
-
}
|
|
264
|
-
if (session.files_changed) {
|
|
265
|
-
lines.push('### Files Changed', session.files_changed, '');
|
|
266
|
-
}
|
|
267
|
-
if (session.notes) {
|
|
268
|
-
lines.push('### Notes', session.notes, '');
|
|
269
|
-
}
|
|
270
|
-
lines.push('---', '');
|
|
271
|
-
}
|
|
272
|
-
return lines.join('\n');
|
|
273
|
-
}
|
|
274
|
-
// Generate quests.md from database
|
|
275
|
-
generateQuests(projectId) {
|
|
276
|
-
const pending = this.db.getPendingQuests(projectId);
|
|
277
|
-
const completed = this.db.getRecentlyCompleted(projectId, 10);
|
|
278
|
-
const lines = [
|
|
279
|
-
'# Wyrm Quests',
|
|
280
|
-
'',
|
|
281
|
-
'> Task queue',
|
|
282
|
-
'',
|
|
283
|
-
'---',
|
|
284
|
-
''
|
|
285
|
-
];
|
|
286
|
-
const byPriority = {
|
|
287
|
-
critical: pending.filter(q => q.priority === 'critical'),
|
|
288
|
-
high: pending.filter(q => q.priority === 'high'),
|
|
289
|
-
medium: pending.filter(q => q.priority === 'medium'),
|
|
290
|
-
low: pending.filter(q => q.priority === 'low')
|
|
291
|
-
};
|
|
292
|
-
if (byPriority.critical.length > 0) {
|
|
293
|
-
lines.push('## Critical', '');
|
|
294
|
-
for (const q of byPriority.critical) {
|
|
295
|
-
lines.push(`- [ ] **${q.title}**${q.description ? ` - ${q.description}` : ''}`);
|
|
296
|
-
}
|
|
297
|
-
lines.push('');
|
|
298
|
-
}
|
|
299
|
-
if (byPriority.high.length > 0) {
|
|
300
|
-
lines.push('## High Priority', '');
|
|
301
|
-
for (const q of byPriority.high) {
|
|
302
|
-
lines.push(`- [ ] **${q.title}**${q.description ? ` - ${q.description}` : ''}`);
|
|
303
|
-
}
|
|
304
|
-
lines.push('');
|
|
305
|
-
}
|
|
306
|
-
if (byPriority.medium.length > 0) {
|
|
307
|
-
lines.push('## Medium Priority', '');
|
|
308
|
-
for (const q of byPriority.medium) {
|
|
309
|
-
lines.push(`- [ ] ${q.title}${q.description ? ` - ${q.description}` : ''}`);
|
|
310
|
-
}
|
|
311
|
-
lines.push('');
|
|
312
|
-
}
|
|
313
|
-
if (byPriority.low.length > 0) {
|
|
314
|
-
lines.push('## Low Priority / Future', '');
|
|
315
|
-
for (const q of byPriority.low) {
|
|
316
|
-
lines.push(`- [ ] ${q.title}`);
|
|
317
|
-
}
|
|
318
|
-
lines.push('');
|
|
319
|
-
}
|
|
320
|
-
if (completed.length > 0) {
|
|
321
|
-
lines.push('## Completed', '');
|
|
322
|
-
for (const q of completed) {
|
|
323
|
-
lines.push(`- [x] ${q.title} (${q.completed_at?.split('T')[0]})`);
|
|
324
|
-
}
|
|
325
|
-
lines.push('');
|
|
326
|
-
}
|
|
327
|
-
return lines.join('\n');
|
|
328
|
-
}
|
|
329
|
-
// Helpers
|
|
330
|
-
splitSections(content) {
|
|
331
|
-
const sections = {};
|
|
332
|
-
const regex = /^##\s+(.+?)$/gm;
|
|
333
|
-
let lastTitle = '';
|
|
334
|
-
let lastIndex = 0;
|
|
335
|
-
let match;
|
|
336
|
-
while ((match = regex.exec(content)) !== null) {
|
|
337
|
-
if (lastTitle) {
|
|
338
|
-
sections[lastTitle] = content.slice(lastIndex, match.index).trim();
|
|
339
|
-
}
|
|
340
|
-
lastTitle = match[1];
|
|
341
|
-
lastIndex = match.index + match[0].length;
|
|
342
|
-
}
|
|
343
|
-
if (lastTitle) {
|
|
344
|
-
sections[lastTitle] = content.slice(lastIndex).trim();
|
|
345
|
-
}
|
|
346
|
-
return sections;
|
|
347
|
-
}
|
|
348
|
-
extractSection(body, ...titles) {
|
|
349
|
-
for (const title of titles) {
|
|
350
|
-
const regex = new RegExp(`###?\\s*${title}[^\\n]*\\n([\\s\\S]*?)(?=###|$)`, 'i');
|
|
351
|
-
const match = body.match(regex);
|
|
352
|
-
if (match) {
|
|
353
|
-
return match[1].trim();
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
return undefined;
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
//# sourceMappingURL=sync.js.map
|
|
1
|
+
import{watch as y,existsSync as d,readFileSync as u,writeFileSync as m,mkdirSync as S,statSync as x}from"fs";import{join as $,basename as C,resolve as f,normalize as p,relative as b,sep as P}from"path";function h(a,s){const i=p(f(a)),o=p(f(a,s)),t=b(i,o);if(t.startsWith("..")||t.startsWith(P))throw new Error("SECURITY: Path traversal detected");if(!o.startsWith(i))throw new Error("SECURITY: Path traversal detected");return o}function g(a){const s=p(f(a));if(!d(s))throw new Error(`Project path does not exist: ${a}`);if(!x(s).isDirectory())throw new Error(`Project path is not a directory: ${a}`);return s}class q{db;watchers=new Map;constructor(s){this.db=s}importFromFolder(s){const i=g(s),o=h(i,".wyrm");if(!d(o))throw new Error(`No .wyrm folder found at ${i}`);const t=C(i);let n=this.db.getProject(i);n||(n=this.db.registerProject(t,i));const e=h(o,"hoard.md");if(d(e)){const c=u(e,"utf-8");this.parseHoard(n.id,c)}const r=h(o,"chronicles.md");if(d(r)){const c=u(r,"utf-8");this.parseChronicles(n.id,c)}const l=h(o,"quests.md");if(d(l)){const c=u(l,"utf-8");this.parseQuests(n.id,c)}return n}exportToFolder(s){const i=g(s),o=this.db.getProject(i);if(!o)throw new Error(`Project not found: ${i}`);const t=h(i,".wyrm");d(t)||S(t,{recursive:!0});const n=this.generateHoard(o);m(h(t,"hoard.md"),n);const e=this.generateChronicles(o.id);m(h(t,"chronicles.md"),e);const r=this.generateQuests(o.id);m(h(t,"quests.md"),r)}watchFolder(s){const i=$(s,".wyrm");if(!d(i))return;this.watchers.has(s)&&this.watchers.get(s).close();const o=y(i,{recursive:!0},(t,n)=>{n&&n.endsWith(".md")&&(console.log(`[Wyrm] File changed: ${n}`),this.importFromFolder(s))});this.watchers.set(s,o)}stopWatching(s){const i=this.watchers.get(s);i&&(i.close(),this.watchers.delete(s))}parseHoard(s,i){const o=this.splitSections(i);for(const[t,n]of Object.entries(o)){const e=t.toLowerCase().replace(/[^a-z0-9]+/g,"_");this.db.setContext(s,e,n)}}parseChronicles(s,i){const o=/## Session:\s*(\d{4}-\d{2}-\d{2})([\s\S]*?)(?=## Session:|$)/g;let t;for(;(t=o.exec(i))!==null;){const n=t[1],e=t[2],r=this.db.getTodaySession(s);r&&r.date===n?this.db.updateSession(r.id,this.parseSessionBody(e)):this.db.createSession(s,{date:n,...this.parseSessionBody(e)})}}parseSessionBody(s){const i={},o=this.extractSection(s,"Objectives","Mission");o&&(i.objectives=o);const t=this.extractSection(s,"Completed","Done","Quests Completed");t&&(i.completed=t);const n=this.extractSection(s,"Issues","Problems","Battles","Fixed");n&&(i.issues=n);const e=this.extractSection(s,"Commits");e&&(i.commits=e);const r=this.extractSection(s,"Files","Changed");r&&(i.files_changed=r);const l=this.extractSection(s,"Notes","Wisdom");return l&&(i.notes=l),i}parseQuests(s,i){const o=i.split(`
|
|
2
|
+
`);let t="medium";const n=new Set(this.db.getPendingQuests(s).map(e=>e.title));for(const e of o){e.match(/critical|urgent/i)?t="critical":e.match(/high/i)?t="high":e.match(/medium/i)?t="medium":e.match(/low|future|backlog/i)&&(t="low");const r=e.match(/^[\s]*[-*]\s*\[([x\s])\]\s*\*?\*?(.+?)\*?\*?\s*$/i);if(r){const l=r[1].toLowerCase()==="x",c=r[2].trim();if(!n.has(c)){const w=this.db.addQuest(s,c,"",t);l&&this.db.updateQuest(w.id,"completed"),n.add(c)}}}}generateHoard(s){const i=this.db.getAllContext(s.id),o=[`# Wyrm Hoard // ${s.name}`,"",`> **Last Updated:** ${new Date().toISOString().split("T")[0]}`,`> **Project:** ${s.name}`,s.repo?`> **Repo:** ${s.repo}`:"","","---",""];for(const[t,n]of Object.entries(i)){const e=t.replace(/_/g," ").replace(/\b\w/g,r=>r.toUpperCase());o.push(`## ${e}`,"",n,"")}return o.filter(t=>t!==void 0).join(`
|
|
3
|
+
`)}generateChronicles(s){const i=this.db.getRecentSessions(s,20),o=["# Wyrm Chronicles","","> Session history","","---",""];for(const t of i)o.push(`## Session: ${t.date}`,""),t.objectives&&o.push("### Objectives",t.objectives,""),t.completed&&o.push("### Completed",t.completed,""),t.issues&&o.push("### Issues Solved",t.issues,""),t.commits&&o.push("### Commits",t.commits,""),t.files_changed&&o.push("### Files Changed",t.files_changed,""),t.notes&&o.push("### Notes",t.notes,""),o.push("---","");return o.join(`
|
|
4
|
+
`)}generateQuests(s){const i=this.db.getPendingQuests(s),o=this.db.getRecentlyCompleted(s,10),t=["# Wyrm Quests","","> Task queue","","---",""],n={critical:i.filter(e=>e.priority==="critical"),high:i.filter(e=>e.priority==="high"),medium:i.filter(e=>e.priority==="medium"),low:i.filter(e=>e.priority==="low")};if(n.critical.length>0){t.push("## Critical","");for(const e of n.critical)t.push(`- [ ] **${e.title}**${e.description?` - ${e.description}`:""}`);t.push("")}if(n.high.length>0){t.push("## High Priority","");for(const e of n.high)t.push(`- [ ] **${e.title}**${e.description?` - ${e.description}`:""}`);t.push("")}if(n.medium.length>0){t.push("## Medium Priority","");for(const e of n.medium)t.push(`- [ ] ${e.title}${e.description?` - ${e.description}`:""}`);t.push("")}if(n.low.length>0){t.push("## Low Priority / Future","");for(const e of n.low)t.push(`- [ ] ${e.title}`);t.push("")}if(o.length>0){t.push("## Completed","");for(const e of o)t.push(`- [x] ${e.title} (${e.completed_at?.split("T")[0]})`);t.push("")}return t.join(`
|
|
5
|
+
`)}splitSections(s){const i={},o=/^##\s+(.+?)$/gm;let t="",n=0,e;for(;(e=o.exec(s))!==null;)t&&(i[t]=s.slice(n,e.index).trim()),t=e[1],n=e.index+e[0].length;return t&&(i[t]=s.slice(n).trim()),i}extractSection(s,...i){for(const o of i){const t=new RegExp(`###?\\s*${o}[^\\n]*\\n([\\s\\S]*?)(?=###|$)`,"i"),n=s.match(t);if(n)return n[1].trim()}}}export{q as WyrmSync};
|
package/dist/tasks-dispatch.js
CHANGED
|
@@ -1,84 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { toWireTask, taskPayload, adminGateBlocks, adminDeniedResponse, } from './tasks.js';
|
|
3
|
-
/**
|
|
4
|
-
* Register the MCP Tasks RC handlers (tasks/get|result|list|cancel) backed by
|
|
5
|
-
* the local TaskStore. On a task-augmented CallTool the op ran SYNCHRONOUSLY
|
|
6
|
-
* and the completed CallToolResult was stored; these serve the lifecycle so a
|
|
7
|
-
* Tasks-aware client can fetch status / payload / list / cancel. A client that
|
|
8
|
-
* ignores tasks gets the synchronous fallback (the payload inline on the
|
|
9
|
-
* original CallTool). Unknown/expired ids surface a clean JSON-RPC error.
|
|
10
|
-
*/
|
|
11
|
-
export function registerTaskHandlers(server, taskStore) {
|
|
12
|
-
server.setRequestHandler(ListTasksRequestSchema, async () => {
|
|
13
|
-
return { tasks: taskStore.list().map(toWireTask) };
|
|
14
|
-
});
|
|
15
|
-
server.setRequestHandler(GetTaskRequestSchema, async (request) => {
|
|
16
|
-
const record = taskStore.get(request.params.taskId);
|
|
17
|
-
if (!record)
|
|
18
|
-
throw new Error(`Task not found: ${request.params.taskId}`);
|
|
19
|
-
return toWireTask(record);
|
|
20
|
-
});
|
|
21
|
-
server.setRequestHandler(GetTaskPayloadRequestSchema, async (request) => {
|
|
22
|
-
// The stored CallToolResult for a completed task — the deferred payload the
|
|
23
|
-
// task path withheld from the CreateTaskResult envelope. Its shape matches
|
|
24
|
-
// the result of the original tools/call (CallToolResult).
|
|
25
|
-
const payload = taskPayload(taskStore, request.params.taskId);
|
|
26
|
-
if (!payload)
|
|
27
|
-
throw new Error(`Task result not available: ${request.params.taskId}`);
|
|
28
|
-
return payload;
|
|
29
|
-
});
|
|
30
|
-
server.setRequestHandler(CancelTaskRequestSchema, async (request) => {
|
|
31
|
-
// Wyrm tasks complete synchronously, so a cancel almost always races a
|
|
32
|
-
// terminal record (no-op). We still honor the verb: a still-working record
|
|
33
|
-
// (only possible for a concurrent in-flight op) flips to 'cancelled'.
|
|
34
|
-
taskStore.cancel(request.params.taskId);
|
|
35
|
-
const record = taskStore.get(request.params.taskId);
|
|
36
|
-
if (!record)
|
|
37
|
-
throw new Error(`Task not found: ${request.params.taskId}`);
|
|
38
|
-
return toWireTask(record);
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Finalize an EARLY (pre-dispatch) ToolResult — admin denial, cache hit, etc. —
|
|
43
|
-
* for the wire. Under a `task` augmentation the MCP SDK demands a
|
|
44
|
-
* CreateTaskResult even for these (returning a plain result is a -32602), so we
|
|
45
|
-
* record a settled task (completed, or failed for an isError body) and return
|
|
46
|
-
* its envelope; otherwise the result rides inline unchanged. Keeps every
|
|
47
|
-
* early-return path crash-free for a task-augmenting client.
|
|
48
|
-
*/
|
|
49
|
-
export function finalizeEarly(taskStore, gate, tool, early) {
|
|
50
|
-
if (!gate.asTask)
|
|
51
|
-
return early;
|
|
52
|
-
const rec = taskStore.create(tool, gate.ttlMs);
|
|
53
|
-
taskStore.settle(rec.taskId, early.isError ? 'failed' : 'completed', early);
|
|
54
|
-
return { task: toWireTask(taskStore.get(rec.taskId) ?? rec) };
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Apply the admin gate (T037, Article VII). When `name` is an admin-gated long
|
|
58
|
-
* op and WYRM_ADMIN is not set, returns the wire value for a deterministic,
|
|
59
|
-
* non-retryable SEP-1303 denial (task-wrapped when params.task is present, via
|
|
60
|
-
* finalizeEarly), after firing the supplied telemetry callback. Returns null
|
|
61
|
-
* when the call is allowed (the dispatcher proceeds). Keeps the admin-gate
|
|
62
|
-
* branch out of index.ts to hold the quest #80 line ceiling.
|
|
63
|
-
*/
|
|
64
|
-
export function applyAdminGate(taskStore, gate, name, onDenied) {
|
|
65
|
-
if (!adminGateBlocks(name))
|
|
66
|
-
return null;
|
|
67
|
-
const denied = adminDeniedResponse(name);
|
|
68
|
-
onDenied(denied);
|
|
69
|
-
return finalizeEarly(taskStore, gate, name, denied);
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Unwrap a {@link LongOpOutcome} for the dispatcher: `payload` is the real
|
|
73
|
-
* CallToolResult (telemetry/golden use it); `wireValue` is what the SDK
|
|
74
|
-
* receives — the CreateTaskResult on the task path, the payload on the inline
|
|
75
|
-
* path. On the task path the payload is read back from the store under its id.
|
|
76
|
-
*/
|
|
77
|
-
export function unwrapOutcome(taskStore, outcome) {
|
|
78
|
-
if (outcome.kind === 'task') {
|
|
79
|
-
const payload = taskPayload(taskStore, outcome.createTask.task.taskId) ?? { content: [{ type: 'text', text: '' }] };
|
|
80
|
-
return { wireValue: outcome.createTask, payload };
|
|
81
|
-
}
|
|
82
|
-
return { wireValue: outcome.result, payload: outcome.result };
|
|
83
|
-
}
|
|
84
|
-
//# sourceMappingURL=tasks-dispatch.js.map
|
|
1
|
+
import{GetTaskRequestSchema as i,GetTaskPayloadRequestSchema as o,ListTasksRequestSchema as l,CancelTaskRequestSchema as c}from"@modelcontextprotocol/sdk/types.js";import{toWireTask as n,taskPayload as d,adminGateBlocks as u,adminDeniedResponse as k}from"./tasks.js";function T(s,t){s.setRequestHandler(l,async()=>({tasks:t.list().map(n)})),s.setRequestHandler(i,async a=>{const e=t.get(a.params.taskId);if(!e)throw new Error(`Task not found: ${a.params.taskId}`);return n(e)}),s.setRequestHandler(o,async a=>{const e=d(t,a.params.taskId);if(!e)throw new Error(`Task result not available: ${a.params.taskId}`);return e}),s.setRequestHandler(c,async a=>{t.cancel(a.params.taskId);const e=t.get(a.params.taskId);if(!e)throw new Error(`Task not found: ${a.params.taskId}`);return n(e)})}function p(s,t,a,e){if(!t.asTask)return e;const r=s.create(a,t.ttlMs);return s.settle(r.taskId,e.isError?"failed":"completed",e),{task:n(s.get(r.taskId)??r)}}function y(s,t,a,e){if(!u(a))return null;const r=k(a);return e(r),p(s,t,a,r)}function I(s,t){if(t.kind==="task"){const a=d(s,t.createTask.task.taskId)??{content:[{type:"text",text:""}]};return{wireValue:t.createTask,payload:a}}return{wireValue:t.result,payload:t.result}}export{y as applyAdminGate,p as finalizeEarly,T as registerTaskHandlers,I as unwrapOutcome};
|