wyrm-mcp 7.3.2 → 7.4.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 (200) hide show
  1. package/README.md +12 -18
  2. package/dist/activation.js +59 -1
  3. package/dist/agent-daemon.js +281 -4
  4. package/dist/agent-loop.js +332 -7
  5. package/dist/analytics.js +236 -13
  6. package/dist/attribution.js +49 -1
  7. package/dist/audit.js +457 -2
  8. package/dist/auto-capture.js +138 -3
  9. package/dist/auto-orchestrator.js +325 -1
  10. package/dist/autoconfig.d.ts +51 -0
  11. package/dist/autoconfig.d.ts.map +1 -1
  12. package/dist/autoconfig.js +1121 -39
  13. package/dist/autoconfig.js.map +1 -1
  14. package/dist/buddy-runner.js +109 -1
  15. package/dist/buddy.js +564 -14
  16. package/dist/build-flags.js +15 -1
  17. package/dist/capabilities.js +183 -3
  18. package/dist/capture.js +56 -1
  19. package/dist/causality.js +148 -8
  20. package/dist/cli.js +281 -20
  21. package/dist/cloud/cli.js +541 -5
  22. package/dist/cloud/client.js +221 -1
  23. package/dist/cloud/crypto.js +85 -1
  24. package/dist/cloud/machine-id.js +113 -2
  25. package/dist/cloud/recovery.js +60 -1
  26. package/dist/cloud/sync-engine.js +543 -7
  27. package/dist/cloud-backup.js +579 -5
  28. package/dist/cloud-profile.js +138 -1
  29. package/dist/cloud-sync-entrypoint.js +47 -1
  30. package/dist/cloud-sync.js +309 -2
  31. package/dist/connectors/bridge-source.d.ts +46 -0
  32. package/dist/connectors/bridge-source.d.ts.map +1 -0
  33. package/dist/connectors/bridge-source.js +77 -0
  34. package/dist/connectors/bridge-source.js.map +1 -0
  35. package/dist/connectors/index.d.ts +24 -0
  36. package/dist/connectors/index.d.ts.map +1 -0
  37. package/dist/connectors/index.js +69 -0
  38. package/dist/connectors/index.js.map +1 -0
  39. package/dist/connectors/ingest.d.ts +16 -0
  40. package/dist/connectors/ingest.d.ts.map +1 -0
  41. package/dist/connectors/ingest.js +116 -0
  42. package/dist/connectors/ingest.js.map +1 -0
  43. package/dist/connectors/types.d.ts +99 -0
  44. package/dist/connectors/types.d.ts.map +1 -0
  45. package/dist/connectors/types.js +17 -0
  46. package/dist/connectors/types.js.map +1 -0
  47. package/dist/constellation.js +168 -12
  48. package/dist/content-signature.js +45 -1
  49. package/dist/context-build-budgeted.js +144 -4
  50. package/dist/context-ranking.js +69 -1
  51. package/dist/crypto.js +179 -1
  52. package/dist/daemon-write-endpoint.js +290 -1
  53. package/dist/daemon-writer.js +406 -2
  54. package/dist/database.js +1278 -53
  55. package/dist/deprecations.js +162 -2
  56. package/dist/design.js +141 -13
  57. package/dist/event-replication.js +112 -1
  58. package/dist/events-sse.js +43 -7
  59. package/dist/events.js +238 -6
  60. package/dist/failure-patterns.d.ts +107 -0
  61. package/dist/failure-patterns.d.ts.map +1 -1
  62. package/dist/failure-patterns.js +924 -43
  63. package/dist/failure-patterns.js.map +1 -1
  64. package/dist/federation.js +236 -12
  65. package/dist/goals.js +101 -13
  66. package/dist/golden.js +355 -3
  67. package/dist/handlers/agent.js +165 -4
  68. package/dist/handlers/alias-adapters.js +129 -1
  69. package/dist/handlers/aliases.js +171 -1
  70. package/dist/handlers/audit.js +87 -1
  71. package/dist/handlers/boundary.js +221 -1
  72. package/dist/handlers/capture.js +1114 -73
  73. package/dist/handlers/causality.js +119 -9
  74. package/dist/handlers/cloud.js +382 -85
  75. package/dist/handlers/companion.js +459 -28
  76. package/dist/handlers/datalake.js +187 -7
  77. package/dist/handlers/dispatch-context.js +22 -0
  78. package/dist/handlers/entity.js +256 -25
  79. package/dist/handlers/events.js +335 -16
  80. package/dist/handlers/failure.d.ts +1 -0
  81. package/dist/handlers/failure.d.ts.map +1 -1
  82. package/dist/handlers/failure.js +458 -13
  83. package/dist/handlers/failure.js.map +1 -1
  84. package/dist/handlers/goals.js +296 -4
  85. package/dist/handlers/intelligence.d.ts.map +1 -1
  86. package/dist/handlers/intelligence.js +690 -126
  87. package/dist/handlers/intelligence.js.map +1 -1
  88. package/dist/handlers/invoicing.js +70 -1
  89. package/dist/handlers/mcpclient.js +137 -6
  90. package/dist/handlers/orchestration.js +125 -40
  91. package/dist/handlers/output-schemas.js +24 -1
  92. package/dist/handlers/presence.js +99 -3
  93. package/dist/handlers/project.js +182 -28
  94. package/dist/handlers/prompts.js +157 -6
  95. package/dist/handlers/quest.js +224 -4
  96. package/dist/handlers/recall.js +237 -13
  97. package/dist/handlers/registry.js +167 -1
  98. package/dist/handlers/resources.js +288 -1
  99. package/dist/handlers/review.js +74 -11
  100. package/dist/handlers/run.js +498 -16
  101. package/dist/handlers/search.js +338 -15
  102. package/dist/handlers/session.js +643 -31
  103. package/dist/handlers/share.js +184 -8
  104. package/dist/handlers/shims.js +464 -1
  105. package/dist/handlers/skill.js +449 -67
  106. package/dist/handlers/survivors.js +120 -1
  107. package/dist/handlers/symbols.js +109 -8
  108. package/dist/handlers/syncops.js +302 -4
  109. package/dist/handlers/types.js +27 -1
  110. package/dist/harvest.js +191 -5
  111. package/dist/hours.js +156 -7
  112. package/dist/http-auth.js +321 -3
  113. package/dist/http-fast.d.ts.map +1 -1
  114. package/dist/http-fast.js +1308 -22
  115. package/dist/http-fast.js.map +1 -1
  116. package/dist/icons.js +47 -1
  117. package/dist/importers.js +268 -1
  118. package/dist/index.js +844 -2
  119. package/dist/index.js.map +1 -1
  120. package/dist/indexer.js +145 -4
  121. package/dist/intelligence.d.ts +16 -0
  122. package/dist/intelligence.d.ts.map +1 -1
  123. package/dist/intelligence.js +283 -31
  124. package/dist/intelligence.js.map +1 -1
  125. package/dist/internal-dispatch.js +212 -3
  126. package/dist/keyset.js +110 -1
  127. package/dist/knowledge-graph.js +176 -12
  128. package/dist/license.js +441 -2
  129. package/dist/logger.js +199 -2
  130. package/dist/maintenance.js +148 -2
  131. package/dist/mcp-client.js +262 -6
  132. package/dist/memory-artifacts.js +596 -32
  133. package/dist/migrate-prompt.js +124 -2
  134. package/dist/migrations.d.ts.map +1 -1
  135. package/dist/migrations.js +799 -42
  136. package/dist/migrations.js.map +1 -1
  137. package/dist/performance.js +228 -1
  138. package/dist/presence.js +140 -11
  139. package/dist/priority-embed.js +164 -5
  140. package/dist/providers/embedding-provider.js +196 -1
  141. package/dist/readonly-gate.js +29 -1
  142. package/dist/receipt.js +43 -1
  143. package/dist/rehydration.js +157 -9
  144. package/dist/reindex.js +88 -1
  145. package/dist/render-target.js +544 -21
  146. package/dist/render.js +280 -4
  147. package/dist/repl-guard.js +173 -1
  148. package/dist/replication-daemon-entrypoint.js +31 -1
  149. package/dist/replication-daemon.js +262 -2
  150. package/dist/rerank.js +142 -1
  151. package/dist/resilience.js +591 -1
  152. package/dist/reverse-bridge.js +360 -5
  153. package/dist/security.js +244 -1
  154. package/dist/session-seen.js +51 -3
  155. package/dist/setup.js +260 -1
  156. package/dist/skill-author.js +168 -5
  157. package/dist/spec-kit.js +191 -1
  158. package/dist/sqlite-busy.js +154 -1
  159. package/dist/statusline.js +315 -11
  160. package/dist/sub-agent.js +262 -13
  161. package/dist/summarizer.js +139 -13
  162. package/dist/symbols.js +283 -7
  163. package/dist/sync.js +359 -5
  164. package/dist/tasks-dispatch.js +84 -1
  165. package/dist/tasks.js +282 -1
  166. package/dist/token-budget.js +143 -1
  167. package/dist/tool-analytics.js +129 -7
  168. package/dist/tool-annotations.js +365 -1
  169. package/dist/tool-manifest-v2.json +1 -1
  170. package/dist/tool-manifest.json +1 -1
  171. package/dist/tool-profiles.js +75 -1
  172. package/dist/trace-harvest.js +244 -6
  173. package/dist/truth-cascade.d.ts +13 -0
  174. package/dist/truth-cascade.d.ts.map +1 -0
  175. package/dist/truth-cascade.js +4 -0
  176. package/dist/truth-cascade.js.map +1 -0
  177. package/dist/types.js +30 -1
  178. package/dist/ui-dashboard.js +50 -41
  179. package/dist/ulid.js +81 -1
  180. package/dist/usage-tracker.js +66 -1
  181. package/dist/validate.js +129 -1
  182. package/dist/vault.js +534 -1
  183. package/dist/vector-init.js +67 -1
  184. package/dist/vectors.js +184 -3
  185. package/dist/version-check.d.ts.map +1 -1
  186. package/dist/version-check.js +145 -4
  187. package/dist/version-check.js.map +1 -1
  188. package/dist/visibility.js +155 -19
  189. package/dist/wyrm-cli.js +2849 -101
  190. package/dist/wyrm-cli.js.map +1 -1
  191. package/dist/wyrm-guard.d.ts.map +1 -1
  192. package/dist/wyrm-guard.js +475 -14
  193. package/dist/wyrm-guard.js.map +1 -1
  194. package/dist/wyrm-loop.js +174 -3
  195. package/dist/wyrm-loop.js.map +1 -1
  196. package/dist/wyrm-manifest.json +1 -1
  197. package/dist/wyrm-statusline-daemon.js +11 -1
  198. package/dist/wyrm-statusline.js +56 -4
  199. package/dist/wyrm-ui.js +77 -9
  200. package/package.json +3 -2
package/dist/sync.js CHANGED
@@ -1,5 +1,359 @@
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};
1
+ /**
2
+ * Wyrm File Sync - Watches and syncs .wyrm folder with database
3
+ *
4
+ * @copyright 2026 Ghost Protocol (Pvt) Ltd.
5
+ * @license Proprietary — (c) 2026 Ghost Protocol (Pvt) Ltd. All rights reserved. See LICENSE.
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 +1,84 @@
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};
1
+ import { GetTaskRequestSchema, GetTaskPayloadRequestSchema, ListTasksRequestSchema, CancelTaskRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
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