society-protocol 1.0.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 (271) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +111 -0
  3. package/dist/adapters.d.ts +101 -0
  4. package/dist/adapters.d.ts.map +1 -0
  5. package/dist/adapters.js +764 -0
  6. package/dist/adapters.js.map +1 -0
  7. package/dist/agents-md.d.ts +59 -0
  8. package/dist/agents-md.d.ts.map +1 -0
  9. package/dist/agents-md.js +204 -0
  10. package/dist/agents-md.js.map +1 -0
  11. package/dist/autoconfig.d.ts +137 -0
  12. package/dist/autoconfig.d.ts.map +1 -0
  13. package/dist/autoconfig.js +452 -0
  14. package/dist/autoconfig.js.map +1 -0
  15. package/dist/bootstrap.d.ts +68 -0
  16. package/dist/bootstrap.d.ts.map +1 -0
  17. package/dist/bootstrap.js +304 -0
  18. package/dist/bootstrap.js.map +1 -0
  19. package/dist/bridges/a2a-bridge.d.ts +156 -0
  20. package/dist/bridges/a2a-bridge.d.ts.map +1 -0
  21. package/dist/bridges/a2a-bridge.js +337 -0
  22. package/dist/bridges/a2a-bridge.js.map +1 -0
  23. package/dist/bridges/mcp-bridge.d.ts +87 -0
  24. package/dist/bridges/mcp-bridge.d.ts.map +1 -0
  25. package/dist/bridges/mcp-bridge.js +332 -0
  26. package/dist/bridges/mcp-bridge.js.map +1 -0
  27. package/dist/cache.d.ts +130 -0
  28. package/dist/cache.d.ts.map +1 -0
  29. package/dist/cache.js +257 -0
  30. package/dist/cache.js.map +1 -0
  31. package/dist/capsules.d.ts +23 -0
  32. package/dist/capsules.d.ts.map +1 -0
  33. package/dist/capsules.js +75 -0
  34. package/dist/capsules.js.map +1 -0
  35. package/dist/cli/commands.d.ts +8 -0
  36. package/dist/cli/commands.d.ts.map +1 -0
  37. package/dist/cli/commands.js +263 -0
  38. package/dist/cli/commands.js.map +1 -0
  39. package/dist/coc.d.ts +121 -0
  40. package/dist/coc.d.ts.map +1 -0
  41. package/dist/coc.js +629 -0
  42. package/dist/coc.js.map +1 -0
  43. package/dist/coc.test.d.ts +2 -0
  44. package/dist/coc.test.d.ts.map +1 -0
  45. package/dist/coc.test.js +80 -0
  46. package/dist/coc.test.js.map +1 -0
  47. package/dist/compression.d.ts +125 -0
  48. package/dist/compression.d.ts.map +1 -0
  49. package/dist/compression.js +573 -0
  50. package/dist/compression.js.map +1 -0
  51. package/dist/cot-stream.d.ts +220 -0
  52. package/dist/cot-stream.d.ts.map +1 -0
  53. package/dist/cot-stream.js +673 -0
  54. package/dist/cot-stream.js.map +1 -0
  55. package/dist/crypto-wasm.d.ts +100 -0
  56. package/dist/crypto-wasm.d.ts.map +1 -0
  57. package/dist/crypto-wasm.js +229 -0
  58. package/dist/crypto-wasm.js.map +1 -0
  59. package/dist/federation.d.ts +200 -0
  60. package/dist/federation.d.ts.map +1 -0
  61. package/dist/federation.js +691 -0
  62. package/dist/federation.js.map +1 -0
  63. package/dist/federation.test.d.ts +2 -0
  64. package/dist/federation.test.d.ts.map +1 -0
  65. package/dist/federation.test.js +71 -0
  66. package/dist/federation.test.js.map +1 -0
  67. package/dist/gateway/capability-router.d.ts +77 -0
  68. package/dist/gateway/capability-router.d.ts.map +1 -0
  69. package/dist/gateway/capability-router.js +222 -0
  70. package/dist/gateway/capability-router.js.map +1 -0
  71. package/dist/gateway/demand-spawner.d.ts +155 -0
  72. package/dist/gateway/demand-spawner.d.ts.map +1 -0
  73. package/dist/gateway/demand-spawner.js +426 -0
  74. package/dist/gateway/demand-spawner.js.map +1 -0
  75. package/dist/identity.d.ts +46 -0
  76. package/dist/identity.d.ts.map +1 -0
  77. package/dist/identity.js +102 -0
  78. package/dist/identity.js.map +1 -0
  79. package/dist/identity.test.d.ts +2 -0
  80. package/dist/identity.test.d.ts.map +1 -0
  81. package/dist/identity.test.js +45 -0
  82. package/dist/identity.test.js.map +1 -0
  83. package/dist/index.d.ts +36 -0
  84. package/dist/index.d.ts.map +1 -0
  85. package/dist/index.js +1572 -0
  86. package/dist/index.js.map +1 -0
  87. package/dist/integration.d.ts +210 -0
  88. package/dist/integration.d.ts.map +1 -0
  89. package/dist/integration.js +1105 -0
  90. package/dist/integration.js.map +1 -0
  91. package/dist/integration.test.d.ts +2 -0
  92. package/dist/integration.test.d.ts.map +1 -0
  93. package/dist/integration.test.js +155 -0
  94. package/dist/integration.test.js.map +1 -0
  95. package/dist/knowledge.d.ts +219 -0
  96. package/dist/knowledge.d.ts.map +1 -0
  97. package/dist/knowledge.js +543 -0
  98. package/dist/knowledge.js.map +1 -0
  99. package/dist/knowledge.test.d.ts +2 -0
  100. package/dist/knowledge.test.d.ts.map +1 -0
  101. package/dist/knowledge.test.js +72 -0
  102. package/dist/knowledge.test.js.map +1 -0
  103. package/dist/latent-space.d.ts +178 -0
  104. package/dist/latent-space.d.ts.map +1 -0
  105. package/dist/latent-space.js +385 -0
  106. package/dist/latent-space.js.map +1 -0
  107. package/dist/lib.d.ts +30 -0
  108. package/dist/lib.d.ts.map +1 -0
  109. package/dist/lib.js +30 -0
  110. package/dist/lib.js.map +1 -0
  111. package/dist/mcp/server.d.ts +74 -0
  112. package/dist/mcp/server.d.ts.map +1 -0
  113. package/dist/mcp/server.js +1392 -0
  114. package/dist/mcp/server.js.map +1 -0
  115. package/dist/metrics.d.ts +98 -0
  116. package/dist/metrics.d.ts.map +1 -0
  117. package/dist/metrics.js +222 -0
  118. package/dist/metrics.js.map +1 -0
  119. package/dist/p2p.d.ts +87 -0
  120. package/dist/p2p.d.ts.map +1 -0
  121. package/dist/p2p.js +606 -0
  122. package/dist/p2p.js.map +1 -0
  123. package/dist/persona/capabilities.d.ts +17 -0
  124. package/dist/persona/capabilities.d.ts.map +1 -0
  125. package/dist/persona/capabilities.js +224 -0
  126. package/dist/persona/capabilities.js.map +1 -0
  127. package/dist/persona/domains.d.ts +22 -0
  128. package/dist/persona/domains.d.ts.map +1 -0
  129. package/dist/persona/domains.js +176 -0
  130. package/dist/persona/domains.js.map +1 -0
  131. package/dist/persona/embeddings.d.ts +40 -0
  132. package/dist/persona/embeddings.d.ts.map +1 -0
  133. package/dist/persona/embeddings.js +265 -0
  134. package/dist/persona/embeddings.js.map +1 -0
  135. package/dist/persona/engine.d.ts +79 -0
  136. package/dist/persona/engine.d.ts.map +1 -0
  137. package/dist/persona/engine.js +1087 -0
  138. package/dist/persona/engine.js.map +1 -0
  139. package/dist/persona/index.d.ts +11 -0
  140. package/dist/persona/index.d.ts.map +1 -0
  141. package/dist/persona/index.js +11 -0
  142. package/dist/persona/index.js.map +1 -0
  143. package/dist/persona/lifecycle.d.ts +17 -0
  144. package/dist/persona/lifecycle.d.ts.map +1 -0
  145. package/dist/persona/lifecycle.js +36 -0
  146. package/dist/persona/lifecycle.js.map +1 -0
  147. package/dist/persona/retrieval.d.ts +6 -0
  148. package/dist/persona/retrieval.d.ts.map +1 -0
  149. package/dist/persona/retrieval.js +122 -0
  150. package/dist/persona/retrieval.js.map +1 -0
  151. package/dist/persona/sync.d.ts +15 -0
  152. package/dist/persona/sync.d.ts.map +1 -0
  153. package/dist/persona/sync.js +92 -0
  154. package/dist/persona/sync.js.map +1 -0
  155. package/dist/persona/types.d.ts +283 -0
  156. package/dist/persona/types.d.ts.map +1 -0
  157. package/dist/persona/types.js +2 -0
  158. package/dist/persona/types.js.map +1 -0
  159. package/dist/persona/zkp/engine.d.ts +26 -0
  160. package/dist/persona/zkp/engine.d.ts.map +1 -0
  161. package/dist/persona/zkp/engine.js +370 -0
  162. package/dist/persona/zkp/engine.js.map +1 -0
  163. package/dist/persona/zkp/types.d.ts +39 -0
  164. package/dist/persona/zkp/types.d.ts.map +1 -0
  165. package/dist/persona/zkp/types.js +2 -0
  166. package/dist/persona/zkp/types.js.map +1 -0
  167. package/dist/planner.d.ts +114 -0
  168. package/dist/planner.d.ts.map +1 -0
  169. package/dist/planner.js +522 -0
  170. package/dist/planner.js.map +1 -0
  171. package/dist/proactive/checkpoints.d.ts +9 -0
  172. package/dist/proactive/checkpoints.d.ts.map +1 -0
  173. package/dist/proactive/checkpoints.js +20 -0
  174. package/dist/proactive/checkpoints.js.map +1 -0
  175. package/dist/proactive/engine.d.ts +59 -0
  176. package/dist/proactive/engine.d.ts.map +1 -0
  177. package/dist/proactive/engine.js +406 -0
  178. package/dist/proactive/engine.js.map +1 -0
  179. package/dist/proactive/scheduler.d.ts +11 -0
  180. package/dist/proactive/scheduler.d.ts.map +1 -0
  181. package/dist/proactive/scheduler.js +45 -0
  182. package/dist/proactive/scheduler.js.map +1 -0
  183. package/dist/proactive/swarm-controller.d.ts +189 -0
  184. package/dist/proactive/swarm-controller.d.ts.map +1 -0
  185. package/dist/proactive/swarm-controller.js +477 -0
  186. package/dist/proactive/swarm-controller.js.map +1 -0
  187. package/dist/proactive/swarm-registry.d.ts +13 -0
  188. package/dist/proactive/swarm-registry.d.ts.map +1 -0
  189. package/dist/proactive/swarm-registry.js +122 -0
  190. package/dist/proactive/swarm-registry.js.map +1 -0
  191. package/dist/proactive/types.d.ts +145 -0
  192. package/dist/proactive/types.d.ts.map +1 -0
  193. package/dist/proactive/types.js +25 -0
  194. package/dist/proactive/types.js.map +1 -0
  195. package/dist/registry.d.ts +35 -0
  196. package/dist/registry.d.ts.map +1 -0
  197. package/dist/registry.js +88 -0
  198. package/dist/registry.js.map +1 -0
  199. package/dist/reputation.d.ts +123 -0
  200. package/dist/reputation.d.ts.map +1 -0
  201. package/dist/reputation.js +366 -0
  202. package/dist/reputation.js.map +1 -0
  203. package/dist/reputation.test.d.ts +5 -0
  204. package/dist/reputation.test.d.ts.map +1 -0
  205. package/dist/reputation.test.js +265 -0
  206. package/dist/reputation.test.js.map +1 -0
  207. package/dist/rooms.d.ts +96 -0
  208. package/dist/rooms.d.ts.map +1 -0
  209. package/dist/rooms.js +410 -0
  210. package/dist/rooms.js.map +1 -0
  211. package/dist/sdk/client.d.ts +290 -0
  212. package/dist/sdk/client.d.ts.map +1 -0
  213. package/dist/sdk/client.js +1287 -0
  214. package/dist/sdk/client.js.map +1 -0
  215. package/dist/sdk/index.d.ts +32 -0
  216. package/dist/sdk/index.d.ts.map +1 -0
  217. package/dist/sdk/index.js +70 -0
  218. package/dist/sdk/index.js.map +1 -0
  219. package/dist/security.d.ts +230 -0
  220. package/dist/security.d.ts.map +1 -0
  221. package/dist/security.js +652 -0
  222. package/dist/security.js.map +1 -0
  223. package/dist/skills/engine.d.ts +262 -0
  224. package/dist/skills/engine.d.ts.map +1 -0
  225. package/dist/skills/engine.js +788 -0
  226. package/dist/skills/engine.js.map +1 -0
  227. package/dist/skills/engine.test.d.ts +2 -0
  228. package/dist/skills/engine.test.d.ts.map +1 -0
  229. package/dist/skills/engine.test.js +134 -0
  230. package/dist/skills/engine.test.js.map +1 -0
  231. package/dist/skills/parser.d.ts +129 -0
  232. package/dist/skills/parser.d.ts.map +1 -0
  233. package/dist/skills/parser.js +318 -0
  234. package/dist/skills/parser.js.map +1 -0
  235. package/dist/social.d.ts +149 -0
  236. package/dist/social.d.ts.map +1 -0
  237. package/dist/social.js +401 -0
  238. package/dist/social.js.map +1 -0
  239. package/dist/storage-optimized.d.ts +116 -0
  240. package/dist/storage-optimized.d.ts.map +1 -0
  241. package/dist/storage-optimized.js +264 -0
  242. package/dist/storage-optimized.js.map +1 -0
  243. package/dist/storage.d.ts +584 -0
  244. package/dist/storage.d.ts.map +1 -0
  245. package/dist/storage.js +2703 -0
  246. package/dist/storage.js.map +1 -0
  247. package/dist/storage.test.d.ts +2 -0
  248. package/dist/storage.test.d.ts.map +1 -0
  249. package/dist/storage.test.js +78 -0
  250. package/dist/storage.test.js.map +1 -0
  251. package/dist/swp.d.ts +443 -0
  252. package/dist/swp.d.ts.map +1 -0
  253. package/dist/swp.js +223 -0
  254. package/dist/swp.js.map +1 -0
  255. package/dist/swp.test.d.ts +5 -0
  256. package/dist/swp.test.d.ts.map +1 -0
  257. package/dist/swp.test.js +127 -0
  258. package/dist/swp.test.js.map +1 -0
  259. package/dist/templates.d.ts +25 -0
  260. package/dist/templates.d.ts.map +1 -0
  261. package/dist/templates.js +1048 -0
  262. package/dist/templates.js.map +1 -0
  263. package/dist/test-e2e.d.ts +14 -0
  264. package/dist/test-e2e.d.ts.map +1 -0
  265. package/dist/test-e2e.js +266 -0
  266. package/dist/test-e2e.js.map +1 -0
  267. package/dist/workers/research-worker.d.ts +19 -0
  268. package/dist/workers/research-worker.d.ts.map +1 -0
  269. package/dist/workers/research-worker.js +141 -0
  270. package/dist/workers/research-worker.js.map +1 -0
  271. package/package.json +110 -0
@@ -0,0 +1,1048 @@
1
+ /**
2
+ * Society Protocol — Templates Module v1.0
3
+ *
4
+ * Predefined, battle-tested DAG templates for common collaborative tasks.
5
+ * These provide deterministic execution paths without requiring AI planning.
6
+ */
7
+ // ─── Template Definitions ───────────────────────────────────────
8
+ export const TEMPLATES = {
9
+ // ─── Software Development ───────────────────────────────────
10
+ 'software_feature': {
11
+ id: 'software_feature',
12
+ name: 'Software Feature Development',
13
+ description: 'Complete SDLC: Design → Implement (FE/BE) → Review → Test → Deploy',
14
+ category: 'software',
15
+ tags: ['development', 'full-stack', 'ci/cd'],
16
+ generate: (goal) => [
17
+ {
18
+ step_id: 'design_architecture',
19
+ kind: 'task',
20
+ title: 'Architecture & Design',
21
+ description: `Design system architecture for: ${goal}. Define APIs, data models, and component structure.`,
22
+ depends_on: [],
23
+ requirements: { capabilities: ['architecture', 'system-design'] },
24
+ },
25
+ {
26
+ step_id: 'implement_backend',
27
+ kind: 'task',
28
+ title: 'Backend Implementation',
29
+ description: 'Implement server-side logic, APIs, and database integration.',
30
+ depends_on: ['design_architecture'],
31
+ requirements: { capabilities: ['backend', 'api-design'] },
32
+ },
33
+ {
34
+ step_id: 'implement_frontend',
35
+ kind: 'task',
36
+ title: 'Frontend Implementation',
37
+ description: 'Implement UI components, state management, and API integration.',
38
+ depends_on: ['design_architecture'],
39
+ requirements: { capabilities: ['frontend', 'ui-design'] },
40
+ },
41
+ {
42
+ step_id: 'code_review',
43
+ kind: 'review',
44
+ title: 'Code Review',
45
+ description: 'Review both frontend and backend implementations for quality, security, and best practices.',
46
+ depends_on: ['implement_backend', 'implement_frontend'],
47
+ requirements: { capabilities: ['code-review', 'security'] },
48
+ },
49
+ {
50
+ step_id: 'integration_testing',
51
+ kind: 'task',
52
+ title: 'Integration Testing',
53
+ description: 'Write and run integration tests for end-to-end flows.',
54
+ depends_on: ['code_review'],
55
+ requirements: { capabilities: ['testing', 'qa'] },
56
+ },
57
+ {
58
+ step_id: 'deploy',
59
+ kind: 'merge',
60
+ title: 'Deploy to Production',
61
+ description: 'Merge code, run CI/CD pipeline, and deploy to production.',
62
+ depends_on: ['integration_testing'],
63
+ requirements: { capabilities: ['devops', 'deployment'] },
64
+ },
65
+ ],
66
+ },
67
+ 'bug_fix': {
68
+ id: 'bug_fix',
69
+ name: 'Bug Fix Pipeline',
70
+ description: 'Investigate → Reproduce → Fix → Verify → Deploy',
71
+ category: 'software',
72
+ tags: ['bugfix', 'debugging', 'hotfix'],
73
+ generate: (goal) => [
74
+ {
75
+ step_id: 'investigate',
76
+ kind: 'task',
77
+ title: 'Bug Investigation',
78
+ description: `Investigate root cause of: ${goal}. Analyze logs, traces, and code.`,
79
+ depends_on: [],
80
+ requirements: { capabilities: ['debugging', 'analysis'] },
81
+ },
82
+ {
83
+ step_id: 'reproduce',
84
+ kind: 'task',
85
+ title: 'Create Reproduction',
86
+ description: 'Create minimal reproduction case or test that demonstrates the bug.',
87
+ depends_on: ['investigate'],
88
+ requirements: { capabilities: ['testing'] },
89
+ },
90
+ {
91
+ step_id: 'implement_fix',
92
+ kind: 'task',
93
+ title: 'Implement Fix',
94
+ description: 'Implement the fix with proper error handling.',
95
+ depends_on: ['reproduce'],
96
+ requirements: { capabilities: ['coding'] },
97
+ },
98
+ {
99
+ step_id: 'review_fix',
100
+ kind: 'review',
101
+ title: 'Review Fix',
102
+ description: 'Review fix for correctness and edge cases.',
103
+ depends_on: ['implement_fix'],
104
+ requirements: { capabilities: ['code-review'] },
105
+ },
106
+ {
107
+ step_id: 'verify_fix',
108
+ kind: 'verification',
109
+ title: 'Verify Resolution',
110
+ description: 'Confirm bug is fixed and no regressions introduced.',
111
+ depends_on: ['review_fix'],
112
+ requirements: { capabilities: ['qa'] },
113
+ },
114
+ {
115
+ step_id: 'deploy_fix',
116
+ kind: 'merge',
117
+ title: 'Deploy Fix',
118
+ description: 'Deploy the fix to production.',
119
+ depends_on: ['verify_fix'],
120
+ requirements: { capabilities: ['deployment'] },
121
+ },
122
+ ],
123
+ },
124
+ // ─── Research & Analysis ────────────────────────────────────
125
+ 'research_swarm': {
126
+ id: 'research_swarm',
127
+ name: 'Parallel Research Investigation',
128
+ description: 'Divide topic into sub-domains, investigate in parallel, synthesize findings',
129
+ category: 'research',
130
+ tags: ['research', 'synthesis', 'parallel'],
131
+ generate: (goal, options) => {
132
+ const numDomains = options?.domains || 3;
133
+ const dag = [
134
+ {
135
+ step_id: 'scope_research',
136
+ kind: 'task',
137
+ title: 'Define Research Scope',
138
+ description: `Break down "${goal}" into ${numDomains} distinct investigation areas.`,
139
+ depends_on: [],
140
+ requirements: { capabilities: ['research', 'analysis'] },
141
+ },
142
+ ];
143
+ // Generate parallel investigation tasks
144
+ for (let i = 1; i <= numDomains; i++) {
145
+ dag.push({
146
+ step_id: `investigate_domain_${i}`,
147
+ kind: 'task',
148
+ title: `Investigate Area ${i}`,
149
+ description: `Deep research on sub-domain ${i} of the topic.`,
150
+ depends_on: ['scope_research'],
151
+ requirements: { capabilities: ['research'] },
152
+ });
153
+ }
154
+ const domainSteps = Array.from({ length: numDomains }, (_, i) => `investigate_domain_${i + 1}`);
155
+ dag.push({
156
+ step_id: 'cross_review',
157
+ kind: 'review',
158
+ title: 'Cross-Domain Review',
159
+ description: 'Review findings for consistency and gaps across all domains.',
160
+ depends_on: domainSteps,
161
+ requirements: { capabilities: ['research', 'review'] },
162
+ });
163
+ dag.push({
164
+ step_id: 'synthesize_findings',
165
+ kind: 'synthesis',
166
+ title: 'Synthesize Final Report',
167
+ description: 'Combine all research into comprehensive, actionable report.',
168
+ depends_on: ['cross_review'],
169
+ requirements: { capabilities: ['writing', 'synthesis'] },
170
+ });
171
+ return dag;
172
+ },
173
+ },
174
+ 'literature_review': {
175
+ id: 'literature_review',
176
+ name: 'Academic Literature Review',
177
+ description: 'Search → Screen → Extract → Synthesize → Report',
178
+ category: 'research',
179
+ tags: ['academic', 'papers', 'review'],
180
+ generate: (goal) => [
181
+ {
182
+ step_id: 'search_papers',
183
+ kind: 'task',
184
+ title: 'Literature Search',
185
+ description: `Search academic databases for papers on: ${goal}`,
186
+ depends_on: [],
187
+ requirements: { capabilities: ['research', 'academic-search'] },
188
+ },
189
+ {
190
+ step_id: 'screen_papers',
191
+ kind: 'task',
192
+ title: 'Screen & Select',
193
+ description: 'Apply inclusion/exclusion criteria to select relevant papers.',
194
+ depends_on: ['search_papers'],
195
+ requirements: { capabilities: ['analysis'] },
196
+ },
197
+ {
198
+ step_id: 'extract_data',
199
+ kind: 'task',
200
+ title: 'Data Extraction',
201
+ description: 'Extract key findings, methodologies, and data from selected papers.',
202
+ depends_on: ['screen_papers'],
203
+ requirements: { capabilities: ['analysis'] },
204
+ },
205
+ {
206
+ step_id: 'quality_assessment',
207
+ kind: 'review',
208
+ title: 'Quality Assessment',
209
+ description: 'Assess quality and bias risk of included studies.',
210
+ depends_on: ['extract_data'],
211
+ requirements: { capabilities: ['research', 'critical-analysis'] },
212
+ },
213
+ {
214
+ step_id: 'synthesize_evidence',
215
+ kind: 'synthesis',
216
+ title: 'Evidence Synthesis',
217
+ description: 'Synthesize findings across studies, identify patterns and gaps.',
218
+ depends_on: ['quality_assessment'],
219
+ requirements: { capabilities: ['synthesis', 'statistics'] },
220
+ },
221
+ {
222
+ step_id: 'write_report',
223
+ kind: 'merge',
224
+ title: 'Write Review Paper',
225
+ description: 'Write comprehensive literature review with citations.',
226
+ depends_on: ['synthesize_evidence'],
227
+ requirements: { capabilities: ['academic-writing'] },
228
+ },
229
+ ],
230
+ },
231
+ 'literature_review_continuous': {
232
+ id: 'literature_review_continuous',
233
+ name: 'Continuous Scientific Literature Review',
234
+ description: 'Scope update → Parallel search → Screening → Extraction → Contradiction scan → Dual review → Synthesis → Knowledge checkpoint',
235
+ category: 'research',
236
+ tags: ['academic', 'continuous', 'literature', 'scientific'],
237
+ generate: (goal, options) => {
238
+ const domains = options?.domains || 4;
239
+ const steps = [
240
+ {
241
+ step_id: 'scope_update',
242
+ kind: 'task',
243
+ title: 'Scope Update',
244
+ description: `Refine current scientific question, subdomains, and watchlist for: ${goal}`,
245
+ depends_on: [],
246
+ requirements: { capabilities: ['research', 'analysis'] },
247
+ },
248
+ ];
249
+ for (let i = 1; i <= domains; i++) {
250
+ steps.push({
251
+ step_id: `search_sources_parallel_${i}`,
252
+ kind: 'task',
253
+ title: `Search Sources ${i}`,
254
+ description: `Search scientific sources for subdomain ${i}.`,
255
+ depends_on: ['scope_update'],
256
+ requirements: { capabilities: ['research', 'academic-search'] },
257
+ }, {
258
+ step_id: `screen_relevance_parallel_${i}`,
259
+ kind: 'task',
260
+ title: `Screen Relevance ${i}`,
261
+ description: `Screen relevance and quality for subdomain ${i}.`,
262
+ depends_on: [`search_sources_parallel_${i}`],
263
+ requirements: { capabilities: ['analysis', 'triage'] },
264
+ }, {
265
+ step_id: `extract_evidence_parallel_${i}`,
266
+ kind: 'task',
267
+ title: `Extract Evidence ${i}`,
268
+ description: `Extract claims, methods, outcomes, and limitations for subdomain ${i}.`,
269
+ depends_on: [`screen_relevance_parallel_${i}`],
270
+ requirements: { capabilities: ['evidence-extraction', 'research'] },
271
+ });
272
+ }
273
+ const extractionSteps = Array.from({ length: domains }, (_, index) => `extract_evidence_parallel_${index + 1}`);
274
+ steps.push({
275
+ step_id: 'contradiction_scan',
276
+ kind: 'task',
277
+ title: 'Contradiction Scan',
278
+ description: 'Identify conflicting claims and unresolved evidence across the corpus.',
279
+ depends_on: extractionSteps,
280
+ requirements: { capabilities: ['critical-analysis', 'research'] },
281
+ }, {
282
+ step_id: 'dual_review',
283
+ kind: 'review',
284
+ title: 'Dual Review',
285
+ description: 'Cross-review extracted evidence and contradiction analysis.',
286
+ depends_on: ['contradiction_scan'],
287
+ requirements: { capabilities: ['review', 'research'] },
288
+ }, {
289
+ step_id: 'synthesize_findings',
290
+ kind: 'synthesis',
291
+ title: 'Synthesize Findings',
292
+ description: 'Produce updated state-of-the-art synthesis with citations and gaps.',
293
+ depends_on: ['dual_review'],
294
+ requirements: { capabilities: ['synthesis', 'academic-writing'] },
295
+ }, {
296
+ step_id: 'knowledge_checkpoint',
297
+ kind: 'verification',
298
+ title: 'Knowledge Checkpoint',
299
+ description: 'Store cards, provenance, contradictions, and next watch triggers.',
300
+ depends_on: ['synthesize_findings'],
301
+ requirements: { capabilities: ['knowledge-management', 'verification'] },
302
+ }, {
303
+ step_id: 'monitor_triggers',
304
+ kind: 'merge',
305
+ title: 'Monitor Triggers',
306
+ description: 'Finalize the cycle and define what to monitor next.',
307
+ depends_on: ['knowledge_checkpoint'],
308
+ requirements: { capabilities: ['monitoring', 'synthesis'] },
309
+ });
310
+ return steps;
311
+ },
312
+ },
313
+ 'hypothesis_swarm': {
314
+ id: 'hypothesis_swarm',
315
+ name: 'Scientific Hypothesis Swarm',
316
+ description: 'Generate, attack, validate, and synthesize competing hypotheses in parallel',
317
+ category: 'research',
318
+ tags: ['hypothesis', 'scientific', 'parallel'],
319
+ generate: (goal, options) => {
320
+ const branches = options?.domains || 4;
321
+ const steps = [
322
+ {
323
+ step_id: 'frame_question',
324
+ kind: 'task',
325
+ title: 'Frame Research Question',
326
+ description: `Frame the core research question and evaluation criteria for: ${goal}`,
327
+ depends_on: [],
328
+ requirements: { capabilities: ['research', 'analysis'] },
329
+ },
330
+ ];
331
+ for (let i = 1; i <= branches; i++) {
332
+ steps.push({
333
+ step_id: `propose_hypothesis_${i}`,
334
+ kind: 'task',
335
+ title: `Propose Hypothesis ${i}`,
336
+ description: `Propose and motivate hypothesis branch ${i}.`,
337
+ depends_on: ['frame_question'],
338
+ requirements: { capabilities: ['hypothesis-generation', 'research'] },
339
+ }, {
340
+ step_id: `attack_hypothesis_${i}`,
341
+ kind: 'review',
342
+ title: `Attack Hypothesis ${i}`,
343
+ description: `Stress test hypothesis branch ${i} against contrary evidence.`,
344
+ depends_on: [`propose_hypothesis_${i}`],
345
+ requirements: { capabilities: ['critical-analysis', 'review'] },
346
+ });
347
+ }
348
+ steps.push({
349
+ step_id: 'synthesize_hypotheses',
350
+ kind: 'merge',
351
+ title: 'Synthesize Hypotheses',
352
+ description: 'Rank competing hypotheses and identify best-supported paths.',
353
+ depends_on: Array.from({ length: branches }, (_, index) => `attack_hypothesis_${index + 1}`),
354
+ requirements: { capabilities: ['synthesis', 'research'] },
355
+ });
356
+ return steps;
357
+ },
358
+ },
359
+ 'research_monitor': {
360
+ id: 'research_monitor',
361
+ name: 'Scientific Research Monitor',
362
+ description: 'Watch new papers, datasets, and evidence deltas over time',
363
+ category: 'research',
364
+ tags: ['monitoring', 'scientific', 'watchlist'],
365
+ generate: (goal) => [
366
+ {
367
+ step_id: 'refresh_watchlist',
368
+ kind: 'task',
369
+ title: 'Refresh Watchlist',
370
+ description: `Refresh source watchlist and alert criteria for: ${goal}`,
371
+ depends_on: [],
372
+ requirements: { capabilities: ['research', 'monitoring'] },
373
+ },
374
+ {
375
+ step_id: 'scan_new_material',
376
+ kind: 'task',
377
+ title: 'Scan New Material',
378
+ description: 'Scan for new papers, preprints, datasets, and major updates.',
379
+ depends_on: ['refresh_watchlist'],
380
+ requirements: { capabilities: ['research', 'monitoring'] },
381
+ },
382
+ {
383
+ step_id: 'evaluate_delta',
384
+ kind: 'review',
385
+ title: 'Evaluate Delta',
386
+ description: 'Decide what materially changes the state of the art.',
387
+ depends_on: ['scan_new_material'],
388
+ requirements: { capabilities: ['analysis', 'review'] },
389
+ },
390
+ {
391
+ step_id: 'synthesize_delta',
392
+ kind: 'merge',
393
+ title: 'Synthesize Delta',
394
+ description: 'Summarize changes, contradictions, and new opportunities for investigation.',
395
+ depends_on: ['evaluate_delta'],
396
+ requirements: { capabilities: ['synthesis', 'writing'] },
397
+ },
398
+ ],
399
+ },
400
+ // ─── Content Creation ───────────────────────────────────────
401
+ 'content_creation': {
402
+ id: 'content_creation',
403
+ name: 'Multi-Stage Content Pipeline',
404
+ description: 'Outline → Draft → Review → Edit → Polish → Publish',
405
+ category: 'creative',
406
+ tags: ['writing', 'content', 'editorial'],
407
+ generate: (goal) => [
408
+ {
409
+ step_id: 'create_outline',
410
+ kind: 'task',
411
+ title: 'Create Outline',
412
+ description: `Develop detailed outline and structure for: ${goal}`,
413
+ depends_on: [],
414
+ requirements: { capabilities: ['planning', 'writing'] },
415
+ },
416
+ {
417
+ step_id: 'write_draft',
418
+ kind: 'task',
419
+ title: 'Write First Draft',
420
+ description: 'Write complete first draft based on outline.',
421
+ depends_on: ['create_outline'],
422
+ requirements: { capabilities: ['writing'] },
423
+ },
424
+ {
425
+ step_id: 'content_review',
426
+ kind: 'review',
427
+ title: 'Content Review',
428
+ description: 'Review for accuracy, clarity, and audience fit.',
429
+ depends_on: ['write_draft'],
430
+ requirements: { capabilities: ['editing', 'review'] },
431
+ },
432
+ {
433
+ step_id: 'revise_content',
434
+ kind: 'task',
435
+ title: 'Revise & Improve',
436
+ description: 'Incorporate feedback and improve the content.',
437
+ depends_on: ['content_review'],
438
+ requirements: { capabilities: ['writing', 'editing'] },
439
+ },
440
+ {
441
+ step_id: 'copyedit',
442
+ kind: 'review',
443
+ title: 'Copy Editing',
444
+ description: 'Fix grammar, style, and formatting issues.',
445
+ depends_on: ['revise_content'],
446
+ requirements: { capabilities: ['copyediting'] },
447
+ },
448
+ {
449
+ step_id: 'final_polish',
450
+ kind: 'merge',
451
+ title: 'Final Polish & Publish',
452
+ description: 'Final formatting and publish.',
453
+ depends_on: ['copyedit'],
454
+ requirements: { capabilities: ['publishing'] },
455
+ },
456
+ ],
457
+ },
458
+ // ─── Business & Strategy ────────────────────────────────────
459
+ 'strategic_analysis': {
460
+ id: 'strategic_analysis',
461
+ name: 'Strategic Business Analysis',
462
+ description: 'Market → Competition → Capabilities → Strategy → Plan',
463
+ category: 'business',
464
+ tags: ['strategy', 'business', 'analysis'],
465
+ generate: (goal) => [
466
+ {
467
+ step_id: 'market_analysis',
468
+ kind: 'task',
469
+ title: 'Market Analysis',
470
+ description: `Analyze market size, trends, and dynamics for: ${goal}`,
471
+ depends_on: [],
472
+ requirements: { capabilities: ['market-research'] },
473
+ },
474
+ {
475
+ step_id: 'competitive_analysis',
476
+ kind: 'task',
477
+ title: 'Competitive Analysis',
478
+ description: 'Analyze competitors, their strengths and weaknesses.',
479
+ depends_on: [],
480
+ requirements: { capabilities: ['competitive-analysis'] },
481
+ },
482
+ {
483
+ step_id: 'capability_assessment',
484
+ kind: 'task',
485
+ title: 'Internal Capabilities',
486
+ description: 'Assess internal capabilities and gaps.',
487
+ depends_on: [],
488
+ requirements: { capabilities: ['business-analysis'] },
489
+ },
490
+ {
491
+ step_id: 'synthesize_strategy',
492
+ kind: 'synthesis',
493
+ title: 'Strategy Formulation',
494
+ description: 'Synthesize insights into strategic options.',
495
+ depends_on: ['market_analysis', 'competitive_analysis', 'capability_assessment'],
496
+ requirements: { capabilities: ['strategy'] },
497
+ },
498
+ {
499
+ step_id: 'strategy_review',
500
+ kind: 'review',
501
+ title: 'Strategy Review',
502
+ description: 'Review strategy for feasibility and risks.',
503
+ depends_on: ['synthesize_strategy'],
504
+ requirements: { capabilities: ['strategy', 'risk-analysis'] },
505
+ },
506
+ {
507
+ step_id: 'implementation_plan',
508
+ kind: 'merge',
509
+ title: 'Implementation Roadmap',
510
+ description: 'Create detailed implementation plan with milestones.',
511
+ depends_on: ['strategy_review'],
512
+ requirements: { capabilities: ['project-management'] },
513
+ },
514
+ ],
515
+ },
516
+ // ─── Medical / Healthcare ───────────────────────────────────
517
+ 'second_opinion': {
518
+ id: 'second_opinion',
519
+ name: 'Medical Second Opinion',
520
+ description: 'Case Review → Differential Diagnosis → Recommendation',
521
+ category: 'medical',
522
+ tags: ['medical', 'diagnosis', 'healthcare'],
523
+ generate: (goal) => [
524
+ {
525
+ step_id: 'extract_clinical_data',
526
+ kind: 'task',
527
+ title: 'Extract Clinical Data',
528
+ description: `Extract structured clinical data from case: ${goal}`,
529
+ depends_on: [],
530
+ requirements: { capabilities: ['medical', 'data-extraction'] },
531
+ },
532
+ {
533
+ step_id: 'literature_search',
534
+ kind: 'task',
535
+ title: 'Medical Literature Search',
536
+ description: 'Search for relevant medical literature and guidelines.',
537
+ depends_on: ['extract_clinical_data'],
538
+ requirements: { capabilities: ['medical-research'] },
539
+ },
540
+ {
541
+ step_id: 'differential_diagnosis',
542
+ kind: 'task',
543
+ title: 'Differential Diagnosis',
544
+ description: 'Develop ranked differential diagnoses with reasoning.',
545
+ depends_on: ['extract_clinical_data', 'literature_search'],
546
+ requirements: { capabilities: ['diagnosis', 'medical'] },
547
+ },
548
+ {
549
+ step_id: 'expert_review',
550
+ kind: 'review',
551
+ title: 'Expert Review',
552
+ description: 'Review differential and recommendations for accuracy.',
553
+ depends_on: ['differential_diagnosis'],
554
+ requirements: { capabilities: ['medical', 'expert-review'], min_reputation: 0.8 },
555
+ },
556
+ {
557
+ step_id: 'recommendations',
558
+ kind: 'synthesis',
559
+ title: 'Treatment Recommendations',
560
+ description: 'Synthesize evidence-based treatment recommendations.',
561
+ depends_on: ['expert_review'],
562
+ requirements: { capabilities: ['medical', 'treatment-planning'] },
563
+ },
564
+ {
565
+ step_id: 'final_report',
566
+ kind: 'merge',
567
+ title: 'Second Opinion Report',
568
+ description: 'Compile comprehensive second opinion report.',
569
+ depends_on: ['recommendations'],
570
+ requirements: { capabilities: ['medical-reporting'] },
571
+ },
572
+ ],
573
+ },
574
+ // ─── Medical / Scientific ─────────────────────────────────
575
+ 'rare_disease_diagnosis': {
576
+ id: 'rare_disease_diagnosis',
577
+ name: 'Rare Disease Multi-Specialist Diagnosis',
578
+ description: 'Parallel specialist analysis (genetics, neurology, immunology, metabolism) → cross-correlation → consensus diagnosis',
579
+ category: 'medical',
580
+ tags: ['rare-disease', 'diagnosis', 'multi-specialist', 'genetics', 'parallel'],
581
+ generate: (goal, options) => {
582
+ const specialists = options?.specialists || [
583
+ 'genetics',
584
+ 'neurology',
585
+ 'immunology',
586
+ 'metabolic',
587
+ ];
588
+ const steps = [
589
+ {
590
+ step_id: 'intake_structured',
591
+ kind: 'task',
592
+ title: 'Structured Case Intake',
593
+ description: `Extract structured clinical data, phenotype ontology (HPO terms), family history, lab results, imaging, and prior workup for: ${goal}`,
594
+ depends_on: [],
595
+ requirements: { capabilities: ['medical', 'data-extraction', 'phenotyping'] },
596
+ },
597
+ {
598
+ step_id: 'literature_scan',
599
+ kind: 'task',
600
+ title: 'Rare Disease Literature Scan',
601
+ description: 'Search OMIM, Orphanet, PubMed, ClinVar, and DECIPHER for matching phenotype/genotype patterns.',
602
+ depends_on: ['intake_structured'],
603
+ requirements: { capabilities: ['medical-research', 'rare-disease'] },
604
+ },
605
+ ];
606
+ // Parallel specialist analysis
607
+ for (const spec of specialists) {
608
+ steps.push({
609
+ step_id: `specialist_${spec}`,
610
+ kind: 'task',
611
+ title: `${spec.charAt(0).toUpperCase() + spec.slice(1)} Specialist Analysis`,
612
+ description: `${spec} domain analysis: differential diagnosis from ${spec} perspective, relevant biomarkers, recommended tests.`,
613
+ depends_on: ['intake_structured', 'literature_scan'],
614
+ requirements: {
615
+ capabilities: ['medical', spec, 'diagnosis'],
616
+ min_reputation: 0.7,
617
+ },
618
+ });
619
+ }
620
+ const specialistSteps = specialists.map(s => `specialist_${s}`);
621
+ steps.push({
622
+ step_id: 'cross_correlation',
623
+ kind: 'task',
624
+ title: 'Cross-Specialist Correlation',
625
+ description: 'Correlate findings across specialties. Identify overlapping differential diagnoses, contradictions, and synergistic evidence.',
626
+ depends_on: specialistSteps,
627
+ requirements: { capabilities: ['medical', 'cross-domain-analysis'] },
628
+ }, {
629
+ step_id: 'genetic_variant_analysis',
630
+ kind: 'task',
631
+ title: 'Genetic Variant Prioritization',
632
+ description: 'If genomic data available, prioritize candidate variants using ACMG criteria, phenotype match scores, and allele frequency.',
633
+ depends_on: ['cross_correlation'],
634
+ requirements: { capabilities: ['genetics', 'bioinformatics', 'variant-analysis'] },
635
+ }, {
636
+ step_id: 'consensus_review',
637
+ kind: 'review',
638
+ title: 'Multi-Disciplinary Consensus Review',
639
+ description: 'Virtual tumor-board style review: rank differential diagnoses by evidence strength, propose confirmatory tests.',
640
+ depends_on: ['genetic_variant_analysis'],
641
+ requirements: {
642
+ capabilities: ['medical', 'consensus-building'],
643
+ min_reputation: 0.8,
644
+ },
645
+ }, {
646
+ step_id: 'diagnostic_report',
647
+ kind: 'synthesis',
648
+ title: 'Diagnostic Report',
649
+ description: 'Synthesize evidence-based diagnostic report with ranked differentials, recommended next steps, and management considerations.',
650
+ depends_on: ['consensus_review'],
651
+ requirements: { capabilities: ['medical-reporting', 'synthesis'] },
652
+ }, {
653
+ step_id: 'knowledge_capture',
654
+ kind: 'merge',
655
+ title: 'Knowledge Capture & Provenance',
656
+ description: 'Store diagnostic reasoning chain as knowledge cards with full provenance for future case matching.',
657
+ depends_on: ['diagnostic_report'],
658
+ requirements: { capabilities: ['knowledge-management'] },
659
+ });
660
+ return steps;
661
+ },
662
+ },
663
+ 'clinical_trial_monitor': {
664
+ id: 'clinical_trial_monitor',
665
+ name: 'Distributed Clinical Trial Monitor',
666
+ description: 'Multi-site safety surveillance → efficacy tracking → adverse event detection → regulatory reporting',
667
+ category: 'medical',
668
+ tags: ['clinical-trial', 'monitoring', 'safety', 'pharmacovigilance', 'distributed'],
669
+ generate: (goal, options) => {
670
+ const sites = options?.sites || 3;
671
+ const steps = [
672
+ {
673
+ step_id: 'protocol_ingest',
674
+ kind: 'task',
675
+ title: 'Protocol Ingestion',
676
+ description: `Ingest and parse clinical trial protocol, endpoints, and safety criteria for: ${goal}`,
677
+ depends_on: [],
678
+ requirements: { capabilities: ['clinical-trial', 'protocol-analysis'] },
679
+ },
680
+ ];
681
+ // Parallel per-site monitoring
682
+ for (let i = 1; i <= sites; i++) {
683
+ steps.push({
684
+ step_id: `site_${i}_data_collection`,
685
+ kind: 'task',
686
+ title: `Site ${i} Data Collection`,
687
+ description: `Collect and validate data from trial site ${i}: enrollment, dosing, labs, AEs.`,
688
+ depends_on: ['protocol_ingest'],
689
+ requirements: { capabilities: ['data-collection', 'clinical-trial'] },
690
+ }, {
691
+ step_id: `site_${i}_safety_scan`,
692
+ kind: 'task',
693
+ title: `Site ${i} Safety Scan`,
694
+ description: `Screen site ${i} data for adverse events, protocol deviations, and safety signals.`,
695
+ depends_on: [`site_${i}_data_collection`],
696
+ requirements: { capabilities: ['pharmacovigilance', 'safety-monitoring'] },
697
+ });
698
+ }
699
+ const safetySteps = Array.from({ length: sites }, (_, i) => `site_${i + 1}_safety_scan`);
700
+ steps.push({
701
+ step_id: 'aggregate_safety',
702
+ kind: 'task',
703
+ title: 'Aggregate Safety Analysis',
704
+ description: 'Aggregate cross-site safety data. Run signal detection algorithms (PRR, ROR, BCPNN).',
705
+ depends_on: safetySteps,
706
+ requirements: { capabilities: ['pharmacovigilance', 'statistics', 'signal-detection'] },
707
+ }, {
708
+ step_id: 'efficacy_interim',
709
+ kind: 'task',
710
+ title: 'Interim Efficacy Assessment',
711
+ description: 'Assess primary and secondary endpoints against statistical analysis plan.',
712
+ depends_on: safetySteps,
713
+ requirements: { capabilities: ['biostatistics', 'clinical-trial'] },
714
+ }, {
715
+ step_id: 'dsmb_review',
716
+ kind: 'review',
717
+ title: 'DSMB Review Package',
718
+ description: 'Prepare Data Safety Monitoring Board review: safety tables, Kaplan-Meier, futility analysis.',
719
+ depends_on: ['aggregate_safety', 'efficacy_interim'],
720
+ requirements: {
721
+ capabilities: ['dsmb', 'biostatistics', 'regulatory'],
722
+ min_reputation: 0.85,
723
+ },
724
+ }, {
725
+ step_id: 'regulatory_report',
726
+ kind: 'synthesis',
727
+ title: 'Regulatory Report',
728
+ description: 'Generate CIOMS/MedWatch-compatible safety report and IND safety update.',
729
+ depends_on: ['dsmb_review'],
730
+ requirements: { capabilities: ['regulatory-writing', 'pharmacovigilance'] },
731
+ }, {
732
+ step_id: 'trial_checkpoint',
733
+ kind: 'merge',
734
+ title: 'Trial Monitoring Checkpoint',
735
+ description: 'Finalize monitoring cycle: archive data, update risk assessment, schedule next review.',
736
+ depends_on: ['regulatory_report'],
737
+ requirements: { capabilities: ['clinical-trial', 'project-management'] },
738
+ });
739
+ return steps;
740
+ },
741
+ },
742
+ 'drug_interaction_analysis': {
743
+ id: 'drug_interaction_analysis',
744
+ name: 'Multi-Agent Drug Interaction Analysis',
745
+ description: 'Parallel pharmacology analysis → interaction matrix → clinical risk assessment → patient-specific recommendations',
746
+ category: 'medical',
747
+ tags: ['pharmacology', 'drug-interaction', 'polypharmacy', 'patient-safety'],
748
+ generate: (goal) => [
749
+ {
750
+ step_id: 'medication_extraction',
751
+ kind: 'task',
752
+ title: 'Medication Profile Extraction',
753
+ description: `Extract complete medication list, dosages, routes, and schedules for: ${goal}`,
754
+ depends_on: [],
755
+ requirements: { capabilities: ['medical', 'pharmacology'] },
756
+ },
757
+ {
758
+ step_id: 'pk_analysis',
759
+ kind: 'task',
760
+ title: 'Pharmacokinetic Analysis',
761
+ description: 'Analyze CYP450 metabolism pathways, inhibitors/inducers, and PK interactions for each drug pair.',
762
+ depends_on: ['medication_extraction'],
763
+ requirements: { capabilities: ['pharmacokinetics', 'cyp450'] },
764
+ },
765
+ {
766
+ step_id: 'pd_analysis',
767
+ kind: 'task',
768
+ title: 'Pharmacodynamic Analysis',
769
+ description: 'Analyze receptor-level interactions, additive/synergistic/antagonistic effects.',
770
+ depends_on: ['medication_extraction'],
771
+ requirements: { capabilities: ['pharmacodynamics', 'pharmacology'] },
772
+ },
773
+ {
774
+ step_id: 'literature_evidence',
775
+ kind: 'task',
776
+ title: 'Literature Evidence Search',
777
+ description: 'Search DrugBank, Lexicomp, and PubMed for reported interaction evidence and case reports.',
778
+ depends_on: ['medication_extraction'],
779
+ requirements: { capabilities: ['medical-research', 'pharmacology'] },
780
+ },
781
+ {
782
+ step_id: 'interaction_matrix',
783
+ kind: 'task',
784
+ title: 'Build Interaction Matrix',
785
+ description: 'Combine PK, PD, and literature evidence into a scored interaction matrix with severity levels.',
786
+ depends_on: ['pk_analysis', 'pd_analysis', 'literature_evidence'],
787
+ requirements: { capabilities: ['pharmacology', 'analysis'] },
788
+ },
789
+ {
790
+ step_id: 'clinical_risk_review',
791
+ kind: 'review',
792
+ title: 'Clinical Risk Assessment',
793
+ description: 'Review interactions for clinical significance. Factor in patient comorbidities, renal/hepatic function, and age.',
794
+ depends_on: ['interaction_matrix'],
795
+ requirements: {
796
+ capabilities: ['clinical-pharmacology', 'risk-assessment'],
797
+ min_reputation: 0.75,
798
+ },
799
+ },
800
+ {
801
+ step_id: 'recommendations',
802
+ kind: 'synthesis',
803
+ title: 'Intervention Recommendations',
804
+ description: 'Propose dose adjustments, alternative agents, monitoring plans, and deprescribing opportunities.',
805
+ depends_on: ['clinical_risk_review'],
806
+ requirements: { capabilities: ['pharmacology', 'treatment-planning'] },
807
+ },
808
+ {
809
+ step_id: 'final_report',
810
+ kind: 'merge',
811
+ title: 'Interaction Analysis Report',
812
+ description: 'Compile patient-friendly and clinician-facing interaction reports with evidence levels.',
813
+ depends_on: ['recommendations'],
814
+ requirements: { capabilities: ['medical-reporting'] },
815
+ },
816
+ ],
817
+ },
818
+ 'epidemiological_investigation': {
819
+ id: 'epidemiological_investigation',
820
+ name: 'Epidemiological Outbreak Investigation',
821
+ description: 'Surveillance → case identification → contact tracing → statistical analysis → public health response',
822
+ category: 'medical',
823
+ tags: ['epidemiology', 'outbreak', 'public-health', 'surveillance', 'investigation'],
824
+ generate: (goal) => [
825
+ {
826
+ step_id: 'initial_surveillance',
827
+ kind: 'task',
828
+ title: 'Surveillance Data Collection',
829
+ description: `Collect epidemiological surveillance data, case reports, and syndromic data for: ${goal}`,
830
+ depends_on: [],
831
+ requirements: { capabilities: ['epidemiology', 'surveillance'] },
832
+ },
833
+ {
834
+ step_id: 'case_definition',
835
+ kind: 'task',
836
+ title: 'Case Definition & Identification',
837
+ description: 'Establish confirmed/probable/suspected case definitions. Identify and classify cases.',
838
+ depends_on: ['initial_surveillance'],
839
+ requirements: { capabilities: ['epidemiology', 'case-definition'] },
840
+ },
841
+ {
842
+ step_id: 'descriptive_epi',
843
+ kind: 'task',
844
+ title: 'Descriptive Epidemiology',
845
+ description: 'Characterize outbreak by person, place, time. Create epidemic curve, attack rate, and spatial distribution.',
846
+ depends_on: ['case_definition'],
847
+ requirements: { capabilities: ['epidemiology', 'biostatistics'] },
848
+ },
849
+ {
850
+ step_id: 'hypothesis_generation',
851
+ kind: 'task',
852
+ title: 'Hypothesis Generation',
853
+ description: 'Generate hypotheses about source, mode of transmission, and risk factors.',
854
+ depends_on: ['descriptive_epi'],
855
+ requirements: { capabilities: ['epidemiology', 'hypothesis-generation'] },
856
+ },
857
+ {
858
+ step_id: 'analytical_study',
859
+ kind: 'task',
860
+ title: 'Analytical Study Design',
861
+ description: 'Design case-control or cohort study to test hypotheses. Calculate sample size and power.',
862
+ depends_on: ['hypothesis_generation'],
863
+ requirements: { capabilities: ['epidemiology', 'study-design', 'biostatistics'] },
864
+ },
865
+ {
866
+ step_id: 'lab_investigation',
867
+ kind: 'task',
868
+ title: 'Laboratory Investigation',
869
+ description: 'Coordinate specimen collection, molecular typing, and environmental sampling.',
870
+ depends_on: ['case_definition'],
871
+ requirements: { capabilities: ['microbiology', 'laboratory'] },
872
+ },
873
+ {
874
+ step_id: 'epi_review',
875
+ kind: 'review',
876
+ title: 'Epidemiological Review',
877
+ description: 'Review analytical results, lab findings, and assess evidence strength for each hypothesis.',
878
+ depends_on: ['analytical_study', 'lab_investigation'],
879
+ requirements: {
880
+ capabilities: ['epidemiology', 'review'],
881
+ min_reputation: 0.8,
882
+ },
883
+ },
884
+ {
885
+ step_id: 'response_plan',
886
+ kind: 'synthesis',
887
+ title: 'Public Health Response Plan',
888
+ description: 'Synthesize control measures, communication plan, and ongoing surveillance strategy.',
889
+ depends_on: ['epi_review'],
890
+ requirements: { capabilities: ['public-health', 'response-planning'] },
891
+ },
892
+ {
893
+ step_id: 'situation_report',
894
+ kind: 'merge',
895
+ title: 'Situation Report',
896
+ description: 'Compile situation report with findings, response actions, and recommendations for stakeholders.',
897
+ depends_on: ['response_plan'],
898
+ requirements: { capabilities: ['reporting', 'public-health'] },
899
+ },
900
+ ],
901
+ },
902
+ // ─── Generic ────────────────────────────────────────────────
903
+ 'simple_task': {
904
+ id: 'simple_task',
905
+ name: 'Simple Task with Review',
906
+ description: 'Execute → Review → Finalize',
907
+ category: 'generic',
908
+ tags: ['simple', 'basic'],
909
+ generate: (goal) => [
910
+ {
911
+ step_id: 'execute',
912
+ kind: 'task',
913
+ title: 'Execute Task',
914
+ description: goal,
915
+ depends_on: [],
916
+ },
917
+ {
918
+ step_id: 'review',
919
+ kind: 'review',
920
+ title: 'Review Output',
921
+ description: 'Review the output for quality and correctness.',
922
+ depends_on: ['execute'],
923
+ },
924
+ {
925
+ step_id: 'finalize',
926
+ kind: 'merge',
927
+ title: 'Finalize',
928
+ description: 'Incorporate feedback and finalize.',
929
+ depends_on: ['review'],
930
+ },
931
+ ],
932
+ },
933
+ 'parallel_execution': {
934
+ id: 'parallel_execution',
935
+ name: 'Parallel Task Execution',
936
+ description: 'Split → Execute in parallel → Merge results',
937
+ category: 'generic',
938
+ tags: ['parallel', 'divide-and-conquer'],
939
+ generate: (goal, options) => {
940
+ const numSubtasks = options?.subtasks || 3;
941
+ const dag = [];
942
+ // Create parallel tasks
943
+ for (let i = 1; i <= numSubtasks; i++) {
944
+ dag.push({
945
+ step_id: `subtask_${i}`,
946
+ kind: 'task',
947
+ title: `Subtask ${i}`,
948
+ description: `Part ${i} of: ${goal}`,
949
+ depends_on: [],
950
+ });
951
+ }
952
+ const subtaskIds = Array.from({ length: numSubtasks }, (_, i) => `subtask_${i + 1}`);
953
+ dag.push({
954
+ step_id: 'merge_results',
955
+ kind: 'merge',
956
+ title: 'Merge Results',
957
+ description: 'Combine all partial results into final output.',
958
+ depends_on: subtaskIds,
959
+ });
960
+ return dag;
961
+ },
962
+ },
963
+ };
964
+ // ─── Helper Functions ───────────────────────────────────────────
965
+ export function getTemplate(id) {
966
+ const template = TEMPLATES[id];
967
+ if (!template) {
968
+ throw new Error(`Unknown template: "${id}". ` +
969
+ `Available: ${Object.keys(TEMPLATES).join(', ')}`);
970
+ }
971
+ return template;
972
+ }
973
+ export function listTemplates(category) {
974
+ const templates = Object.values(TEMPLATES);
975
+ if (category) {
976
+ return templates.filter(t => t.category === category);
977
+ }
978
+ return templates;
979
+ }
980
+ export function searchTemplates(query) {
981
+ const lowerQuery = query.toLowerCase();
982
+ return Object.values(TEMPLATES).filter(t => t.id.includes(lowerQuery) ||
983
+ t.name.toLowerCase().includes(lowerQuery) ||
984
+ t.description.toLowerCase().includes(lowerQuery) ||
985
+ t.tags.some(tag => tag.includes(lowerQuery)));
986
+ }
987
+ export function getTemplateCategories() {
988
+ const categories = new Set();
989
+ Object.values(TEMPLATES).forEach(t => categories.add(t.category));
990
+ return Array.from(categories);
991
+ }
992
+ export function validateTemplateDag(templateId, dag) {
993
+ // Check for duplicate IDs
994
+ const ids = new Set();
995
+ for (const step of dag) {
996
+ if (ids.has(step.step_id)) {
997
+ console.error(`Template ${templateId}: Duplicate step_id ${step.step_id}`);
998
+ return false;
999
+ }
1000
+ ids.add(step.step_id);
1001
+ }
1002
+ // Check dependencies exist
1003
+ for (const step of dag) {
1004
+ for (const dep of step.depends_on) {
1005
+ if (!ids.has(dep)) {
1006
+ console.error(`Template ${templateId}: Step ${step.step_id} depends on unknown ${dep}`);
1007
+ return false;
1008
+ }
1009
+ }
1010
+ }
1011
+ // Check for cycles using DFS
1012
+ const visiting = new Set();
1013
+ const visited = new Set();
1014
+ const nodeMap = new Map(dag.map(n => [n.step_id, n]));
1015
+ const visit = (nodeId) => {
1016
+ if (visiting.has(nodeId))
1017
+ return false;
1018
+ if (visited.has(nodeId))
1019
+ return true;
1020
+ visiting.add(nodeId);
1021
+ const node = nodeMap.get(nodeId);
1022
+ if (node) {
1023
+ for (const dep of node.depends_on) {
1024
+ if (!visit(dep))
1025
+ return false;
1026
+ }
1027
+ }
1028
+ visiting.delete(nodeId);
1029
+ visited.add(nodeId);
1030
+ return true;
1031
+ };
1032
+ for (const node of dag) {
1033
+ if (!visit(node.step_id)) {
1034
+ console.error(`Template ${templateId}: Cycle detected`);
1035
+ return false;
1036
+ }
1037
+ }
1038
+ return true;
1039
+ }
1040
+ // Validate all templates on load
1041
+ for (const [id, template] of Object.entries(TEMPLATES)) {
1042
+ // Test with a dummy goal
1043
+ const testDag = template.generate('test goal');
1044
+ if (!validateTemplateDag(id, testDag)) {
1045
+ console.error(`Template validation failed: ${id}`);
1046
+ }
1047
+ }
1048
+ //# sourceMappingURL=templates.js.map