@lincoln504/pi-research 0.1.13 → 1.0.1

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 (248) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +55 -138
  3. package/dist/cli.mjs +23375 -0
  4. package/dist/prompts/research-knowledge-relevance-triage.md +35 -0
  5. package/dist/prompts/research-knowledge-search-extractor.md +41 -0
  6. package/dist/prompts/research-tool-usage.md +92 -0
  7. package/dist/prompts/researcher.md +89 -0
  8. package/dist/prompts/system-coordinator.md +75 -0
  9. package/dist/prompts/system-lead-evaluator.md +118 -0
  10. package/dist/thread-worker.mjs +2611 -0
  11. package/dist/webgpu-probe.mjs +80 -0
  12. package/docs/AGENT-SKILL.md +130 -0
  13. package/docs/ARCHITECTURE.md +306 -80
  14. package/docs/CONFIGURATION.md +249 -0
  15. package/docs/KNOWLEDGE-STORE.md +211 -0
  16. package/docs/PI-EXTENSION.md +91 -0
  17. package/docs/SDK.md +122 -0
  18. package/docs/THIRD-PARTY-NOTICES.md +66 -0
  19. package/package.json +102 -36
  20. package/scripts/build.cjs +140 -0
  21. package/scripts/cleanup.cjs +149 -0
  22. package/scripts/prepare.cjs +28 -0
  23. package/scripts/setup.cjs +134 -0
  24. package/skills/pi-research/README.md +90 -0
  25. package/skills/pi-research/SKILL.md +102 -0
  26. package/skills/pi-research/references/configuration.md +77 -0
  27. package/skills/pi-research/scripts/run.mjs +237 -0
  28. package/src/cleanup/research-cleanup.ts +140 -0
  29. package/src/cli.ts +1195 -0
  30. package/src/config.ts +1032 -155
  31. package/src/constants.ts +115 -84
  32. package/src/core/health-check-service.ts +265 -0
  33. package/src/core/interfaces/health-check-interfaces.ts +50 -0
  34. package/src/core/interfaces/knowledge-interfaces.ts +190 -0
  35. package/src/core/interfaces/observer-interfaces.ts +67 -0
  36. package/src/core/interfaces/orchestration-interfaces.ts +86 -0
  37. package/src/core/interfaces/planning-interfaces.ts +100 -0
  38. package/src/core/interfaces/process-interfaces.ts +37 -0
  39. package/src/core/interfaces/research-plan-types.ts +52 -0
  40. package/src/core/interfaces/scheduler-interfaces.ts +91 -0
  41. package/src/core/interfaces/service-names.ts +39 -0
  42. package/src/core/interfaces/state-manager-interfaces.ts +29 -0
  43. package/src/core/interfaces/steering-interfaces.ts +31 -0
  44. package/src/core/llm/agentic-repair.ts +169 -0
  45. package/src/core/llm/inject-date.ts +52 -0
  46. package/src/core/llm/llm-timeout.ts +64 -0
  47. package/src/core/llm/llm-utils.ts +86 -0
  48. package/src/core/llm/model-registry-factory.ts +287 -0
  49. package/src/core/llm/pi-ai-completion.ts +29 -0
  50. package/src/core/llm/prompts.ts +50 -0
  51. package/src/core/llm/research-model-resolver.ts +91 -0
  52. package/src/core/planning-constants.ts +13 -0
  53. package/src/core/planning-service.ts +649 -0
  54. package/src/core/planning-utils.ts +299 -0
  55. package/src/core/scheduler-factory.ts +48 -0
  56. package/src/core/scheduler-service.ts +123 -0
  57. package/src/core/service-initialization.ts +194 -0
  58. package/src/core/service-interfaces.ts +48 -0
  59. package/src/core/service-registry.ts +659 -0
  60. package/src/healthcheck/index.ts +271 -265
  61. package/src/healthcheck/registry.ts +130 -0
  62. package/src/index.ts +639 -50
  63. package/src/infrastructure/browser/browser-cleanup.ts +309 -0
  64. package/src/infrastructure/browser/browser-client.ts +199 -0
  65. package/src/infrastructure/browser/browser-error-utils.ts +160 -0
  66. package/src/infrastructure/browser/browser-lifecycle.ts +120 -0
  67. package/src/infrastructure/browser/browser-server.ts +174 -0
  68. package/src/infrastructure/browser/browser-task-scheduler.ts +461 -0
  69. package/src/infrastructure/browser/cleanup-utils.ts +155 -0
  70. package/src/infrastructure/browser/client-agent.ts +31 -0
  71. package/src/infrastructure/browser/config.ts +288 -0
  72. package/src/infrastructure/browser/ensure-browser.ts +205 -0
  73. package/src/infrastructure/browser/index.ts +37 -0
  74. package/src/infrastructure/browser/priority-task-queue.ts +226 -0
  75. package/src/infrastructure/browser/scheduler-factory.ts +354 -0
  76. package/src/infrastructure/browser/task-execution-service.ts +209 -0
  77. package/src/infrastructure/browser/thread-worker-browser.ts +282 -0
  78. package/src/infrastructure/browser/thread-worker-lifecycle.ts +323 -0
  79. package/src/infrastructure/browser/thread-worker-messaging.ts +662 -0
  80. package/src/infrastructure/browser/thread-worker-types.ts +25 -0
  81. package/src/infrastructure/browser/thread-worker.mjs +2611 -0
  82. package/src/infrastructure/browser/thread-worker.ts +168 -0
  83. package/src/infrastructure/browser/worker-pool-manager.ts +449 -0
  84. package/src/infrastructure/embedding/embedding-client.ts +205 -0
  85. package/src/infrastructure/embedding/embedding-factory.ts +324 -0
  86. package/src/infrastructure/embedding/embedding-server.ts +535 -0
  87. package/src/infrastructure/file-lock-service.ts +592 -0
  88. package/src/infrastructure/gpu-resource-service.ts +191 -0
  89. package/src/infrastructure/knowledge-store-service.ts +475 -0
  90. package/src/infrastructure/metrics-service.ts +129 -0
  91. package/src/infrastructure/process-lifecycle-service.ts +253 -0
  92. package/src/infrastructure/scheduler-factory-service.ts +58 -0
  93. package/src/infrastructure/service-initialization.ts +292 -0
  94. package/src/infrastructure/state/state-backup-manager.ts +290 -0
  95. package/src/infrastructure/state/state-browser-api.ts +62 -0
  96. package/src/infrastructure/state/state-browser-manager.ts +70 -0
  97. package/src/infrastructure/state/state-manager-service.ts +264 -0
  98. package/src/infrastructure/state/state-manager.ts +547 -0
  99. package/src/infrastructure/state/state-metrics.ts +92 -0
  100. package/src/infrastructure/state/state-migration.ts +103 -0
  101. package/src/infrastructure/state/state-path-configuration.ts +119 -0
  102. package/src/infrastructure/state/state-session-api.ts +94 -0
  103. package/src/infrastructure/state/state-session-manager.ts +127 -0
  104. package/src/infrastructure/state/state-validator.ts +93 -0
  105. package/src/infrastructure/types/state-types.ts +85 -0
  106. package/src/knowledge/chunker.ts +157 -0
  107. package/src/knowledge/embedder-init.ts +413 -0
  108. package/src/knowledge/embedder-utils.ts +296 -0
  109. package/src/knowledge/embedder.ts +592 -0
  110. package/src/knowledge/index.ts +126 -0
  111. package/src/knowledge/lancedb-loader.ts +35 -0
  112. package/src/knowledge/migration.ts +17 -0
  113. package/src/knowledge/model-config.ts +132 -0
  114. package/src/knowledge/onnx-env.ts +48 -0
  115. package/src/knowledge/store-operations.ts +291 -0
  116. package/src/knowledge/store-schema.ts +79 -0
  117. package/src/knowledge/store.ts +1251 -0
  118. package/src/knowledge/transformers-loader.ts +31 -0
  119. package/src/knowledge/webgpu-probe.mjs +80 -0
  120. package/src/knowledge/webgpu-viability.ts +255 -0
  121. package/src/knowledge/writer-queue.ts +252 -0
  122. package/src/logger.ts +316 -122
  123. package/src/observers/research-observer-impl.ts +459 -0
  124. package/src/orchestration/deep-research-orchestrator.ts +524 -773
  125. package/src/orchestration/deep-research-types.ts +47 -35
  126. package/src/orchestration/headless-observer.ts +114 -0
  127. package/src/orchestration/orchestration-types.ts +33 -0
  128. package/src/orchestration/quick-research-orchestrator.ts +463 -0
  129. package/src/orchestration/research-orchestration-service.ts +549 -0
  130. package/src/orchestration/research-session-service.ts +178 -0
  131. package/src/orchestration/research-synthesis-service.ts +348 -0
  132. package/src/orchestration/researcher-executor.ts +394 -0
  133. package/src/orchestration/researcher.ts +115 -42
  134. package/src/orchestration/service-initialization.ts +109 -0
  135. package/src/orchestration/session-context.ts +7 -3
  136. package/src/orchestration/session-state.ts +672 -0
  137. package/src/prompts/research-knowledge-relevance-triage.md +35 -0
  138. package/src/prompts/research-knowledge-search-extractor.md +41 -0
  139. package/src/prompts/research-tool-usage.md +63 -16
  140. package/src/prompts/researcher.md +59 -136
  141. package/src/prompts/system-coordinator.md +64 -13
  142. package/src/prompts/system-lead-evaluator.md +82 -189
  143. package/src/research-config.ts +872 -0
  144. package/src/sdk.ts +847 -0
  145. package/src/security/cisa-kev.ts +72 -9
  146. package/src/security/cvss.ts +92 -0
  147. package/src/security/ecosystem.ts +45 -0
  148. package/src/security/github-advisories.ts +168 -428
  149. package/src/security/github-advisory-types.ts +282 -0
  150. package/src/security/index.ts +63 -177
  151. package/src/security/nvd-client.ts +550 -0
  152. package/src/security/nvd-types.ts +179 -0
  153. package/src/security/osv-client.ts +246 -0
  154. package/src/security/osv-types.ts +285 -0
  155. package/src/security/types.ts +67 -53
  156. package/src/skill-install/skill-installer.ts +519 -0
  157. package/src/stackexchange/index.ts +81 -27
  158. package/src/stackexchange/output/compact.ts +7 -6
  159. package/src/stackexchange/output/table.ts +11 -7
  160. package/src/stackexchange/queries.ts +0 -10
  161. package/src/stackexchange/rest-client.ts +141 -66
  162. package/src/stackexchange/types.ts +0 -17
  163. package/src/tool.ts +15 -423
  164. package/src/tools/grep.ts +32 -310
  165. package/src/tools/health-tool-definition.ts +101 -0
  166. package/src/tools/index.ts +38 -9
  167. package/src/tools/research-knowledge-search.ts +974 -0
  168. package/src/tools/research-knowledge-types.ts +77 -0
  169. package/src/tools/research-tool-definition.ts +494 -0
  170. package/src/tools/scrape.ts +286 -388
  171. package/src/tools/search.ts +98 -153
  172. package/src/tools/security.ts +107 -80
  173. package/src/tools/stackexchange.ts +58 -35
  174. package/src/tools/youtube-transcript.ts +163 -0
  175. package/src/tui/knowledge-search-panel.ts +86 -0
  176. package/src/tui/pulse.ts +86 -0
  177. package/src/tui/research-health.ts +124 -0
  178. package/src/tui/research-panel-color-utils.ts +340 -0
  179. package/src/tui/research-panel-format.ts +54 -0
  180. package/src/tui/research-panel-state.ts +404 -0
  181. package/src/tui/research-panel-wave.ts +280 -0
  182. package/src/tui/research-panel.ts +339 -435
  183. package/src/tui/research-tui-manager.ts +233 -0
  184. package/src/tui/tui-controller.ts +137 -0
  185. package/src/types/extension-context.ts +18 -49
  186. package/src/types/index.ts +61 -0
  187. package/src/types/llm.ts +68 -29
  188. package/src/types/research-panel-types.ts +61 -0
  189. package/src/utils/circuit-breaker.ts +146 -0
  190. package/src/utils/citation-utils.ts +97 -0
  191. package/src/utils/disk-space-checker.ts +55 -0
  192. package/src/utils/error-tracker.ts +265 -0
  193. package/src/utils/host-config.ts +45 -0
  194. package/src/utils/input-validation.ts +8 -10
  195. package/src/utils/json-utils.ts +150 -16
  196. package/src/utils/llm-usage.ts +54 -0
  197. package/src/utils/log-rotation.ts +125 -0
  198. package/src/utils/log-utils.ts +159 -0
  199. package/src/utils/make-resource-loader.ts +3 -1
  200. package/src/utils/metrics-summary.ts +459 -0
  201. package/src/utils/metrics.ts +302 -0
  202. package/src/utils/research-export.ts +28 -12
  203. package/src/utils/safe-unref.ts +31 -0
  204. package/src/utils/shared-links.ts +195 -90
  205. package/src/utils/shutdown-manager.ts +65 -0
  206. package/src/utils/stdio-capture.ts +407 -0
  207. package/src/utils/text-utils.ts +258 -11
  208. package/src/utils/tool-usage-tracker.ts +83 -16
  209. package/src/utils/url-utils.ts +255 -0
  210. package/src/utils/user-agent.ts +28 -0
  211. package/src/web-research/browser-search.ts +179 -0
  212. package/src/web-research/retry-utils.ts +173 -77
  213. package/src/web-research/scraper-types.ts +72 -0
  214. package/src/web-research/scraper-utils.ts +434 -0
  215. package/src/web-research/search.ts +78 -218
  216. package/src/web-research/types.ts +9 -24
  217. package/src/web-research/utils.ts +2 -143
  218. package/src/web-research/web-scraper.ts +477 -0
  219. package/src/youtube/index.ts +154 -0
  220. package/src/youtube/potoken.ts +259 -0
  221. package/src/youtube/transcript-client.ts +390 -0
  222. package/src/youtube/video-id.ts +118 -0
  223. package/config/searxng/default-settings.yml +0 -189
  224. package/config/searxng/limiter.toml +0 -34
  225. package/config/tooling/eslint.config.js +0 -73
  226. package/config/tooling/vitest.config.integration.ts +0 -17
  227. package/config/tooling/vitest.config.ts +0 -40
  228. package/config/tooling/vitest.config.unit.ts +0 -12
  229. package/docs/assets/README-banner.jpg +0 -0
  230. package/scripts/setup.js +0 -212
  231. package/src/infrastructure/searxng-lifecycle.ts +0 -644
  232. package/src/infrastructure/searxng-manager.ts +0 -1183
  233. package/src/infrastructure/state-manager.ts +0 -918
  234. package/src/orchestration/deep-research-reducer.ts +0 -129
  235. package/src/orchestration/id-utils.ts +0 -63
  236. package/src/security/nvd.ts +0 -532
  237. package/src/security/osv.ts +0 -487
  238. package/src/stackexchange/cache.ts +0 -111
  239. package/src/stackexchange/output/index.ts +0 -7
  240. package/src/stackexchange/output/json.ts +0 -21
  241. package/src/tui/searxng-status.ts +0 -80
  242. package/src/utils/inject-date.ts +0 -29
  243. package/src/utils/research-error.ts +0 -205
  244. package/src/utils/searxng-config.ts +0 -94
  245. package/src/utils/session-state.ts +0 -295
  246. package/src/web-research/dependencies.ts +0 -20
  247. package/src/web-research/scrapers.ts +0 -935
  248. package/tsconfig.json +0 -40
@@ -3,223 +3,116 @@
3
3
  You orchestrate the next phase of research.
4
4
 
5
5
  ## Your Context
6
+ - **ROOT QUERY**: {{root_query}}
7
+ - **Current round**: {{round_number}} / {{max_rounds}}
8
+ - **Complexity Level**: {{complexity_label}}
9
+ {{initial_agenda_section}}
10
+ {{previous_queries_section}}
11
+ {{additional_considerations}}
6
12
 
7
- - **ROOT QUERY**: {ROOT_QUERY}
8
- - **ORIGINAL AGENDA**: {ORIGINAL_AGENDA}
9
- - **Current round**: {ROUND_NUMBER}
10
- - **Target rounds**: {MAX_ROUNDS}
13
+ ## CRITICAL: Steering Compliance Checkpoint
14
+ - **STRICT STEERING**: If there is an "ADDITIONAL USER GUIDANCE" section above, you MUST treat every point in it as a **mandatory rule and instruction** for your decisions, next round goals, and queries. Do not ignore them. They are directional requirements.
15
+ - **STEERING SATISFACTION**: Before deciding to SYNTHESIZE, you MUST explicitly verify that ALL user steering requirements have been satisfied by the existing findings. If ANY steering requirement remains unaddressed or only superficially covered, you MUST DELEGATE — do NOT synthesize. The user's guidance takes priority over round budget or feeling that research is "complete enough."
11
16
 
12
- You have reports from all researchers in this round. Some reports may contain errors (see Step 0).
13
-
14
- ### Transition from Researcher to Lead Evaluator
15
-
16
- You were the final researcher to finish. **Your research task is CLOSED.** Your findings are recorded. Your responsibility is to evaluate ALL findings and determine the next step.
17
+ {{disabled_tools_section}}
17
18
 
18
19
  ---
19
20
 
20
- ## Decision Framework
21
-
22
- ### Step 0: Check for Researcher Errors
23
-
24
- **Check if any researchers encountered errors:**
25
-
26
- - Review all researcher reports for those starting with `ERROR:`
27
- - Identify specific error messages and which researchers failed
28
- - Determine if this represents a systemic issue (e.g., search service down, network problems)
29
-
30
- **If ALL researchers failed with errors:**
21
+ ## Complexity-Aware Decision Thresholds
31
22
 
32
- You MUST quit and report the errors. Do not attempt synthesis or delegation.
23
+ {{complexity_guidance}}
33
24
 
34
- Output the errors in this format:
25
+ {{round_phase_guidance}}
35
26
 
36
- ```markdown
37
- # Research Failed: Critical Errors
27
+ ---
38
28
 
39
- ## Error Summary
40
- Research cannot proceed. All researchers encountered errors.
29
+ ## Decision Framework
41
30
 
42
- ## Individual Researcher Failures
31
+ **SYNTHESIZE if:** Research meets the complexity-specific synthesis criteria above.
32
+ **DELEGATE if:** Research meets the complexity-specific delegation criteria above.
33
+ **Note on Guidance**: If the user provides additional guidance mid-research (via Alt+Enter or direct follow-up), those messages will be provided to you. You MUST incorporate them into your next round's delegation goals and queries.
43
34
 
44
- ### Researcher 1
45
- [Report the exact error from Researcher 1's report]
35
+ **STAY IN SCOPE (every delegation):**
36
+ - Going deeper on in-scope material is always welcome. Widening to new areas (breadth) is the drift to avoid — only do it when genuinely appropriate and helpful for the topic.
37
+ - A gap is missing depth on what was asked — not a broader topic next to it. Don't add anything the query didn't ask for, even if it came up in earlier findings.
38
+ - Match the query's scope-bounding constraints exactly — don't broaden them, don't narrow them.
46
39
 
47
- ### Researcher 2
48
- [Report the exact error from Researcher 2's report]
40
+ **COMMON MISTAKES TO AVOID:**
41
+ - Do NOT synthesize early just because you've done "enough" rounds. Synthesis should only occur when you have comprehensive, high-quality findings across all major topics.
42
+ - Do NOT synthesize with gaps remaining, hoping they can be "filled in later". Complete the research first.
43
+ - Do NOT invent a gap outside the query's scope just to keep going or fill the budget. Finish what was asked; don't add what wasn't.
49
44
 
50
- [Continue for all failed researchers...]
45
+ Use unique, targeted queries for any new researchers.
51
46
 
52
- ## Systemic Issue Analysis
53
- [Analyze if errors indicate a pattern: search service unavailable, network timeout, all engines blocked, etc.]
47
+ **Decision**: Return valid JSON in a code block:
54
48
 
55
- ## Recommended Actions
56
- [Suggest what user should do: check network, try again later, use different query, etc.]
49
+ **If synthesizing**:
50
+ ```json
51
+ {
52
+ "action": "synthesize",
53
+ "content": "<Plain prose report with [N] citations, organized by topic. No markdown headings, bullets, or bold text. Followed by the mandatory CITED LINKS section.>"
54
+ }
57
55
  ```
58
56
 
59
- **If SOME researchers succeeded but others failed:**
57
+ **If delegating**:
58
+ ```json
59
+ {
60
+ "action": "delegate",
61
+ "researchers": [
62
+ {
63
+ "id": "{{round_number}}.1",
64
+ "name": "<Researcher Specialty>",
65
+ "goal": "<Focused gap or new angle to investigate>",
66
+ "queries": ["<query_1>", "<query_2>", "<query_3>", "..."]
67
+ }
68
+ ],
69
+ "allQueries": ["<flat_list_of_all_queries_from_all_new_researchers>"]
70
+ }
71
+ ```
60
72
 
61
- Proceed with synthesis but include a section acknowledging the failures:
62
- - Note which researchers failed and why
63
- - Explain how partial failures affected comprehensiveness
64
- - Identify areas that may need future research
73
+ **DELEGATION REQUIREMENTS**:
74
+ - **CRITICAL — Queries are mandatory**: Every researcher MUST have at least one query. Never plan a researcher without queries. Researchers receive ONLY the search results you delegate to them.
75
+ - **Maximize queries**: For EACH researcher, generate the maximum number of targeted, specific queries within the budget. Do not plan fewer than needed — fill the budget. Queries should target primary sources and authoritative evidence.
76
+ - **YouTube discovery**: For roughly one in {{youtube_query_every_n}} queries, append the word `youtube` to the query text (e.g. `"<topic> analysis youtube"`). DuckDuckGo rarely surfaces YouTube on its own, and YouTube links let researchers read video transcripts. Skip only when the gap is clearly unsuited to video.
77
+ - **Temporal anchoring**: Anchor every new time-sensitive query to the current month and year shown at the top of this prompt. Use that exact year (and month where relevant); never default to an older year such as 2024 or 2025 unless the user explicitly asks about the past.
78
+ - **Flexible coverage**: Use up to {{max_team_size}} researchers to cover distinct angles in parallel. Scale based on research gaps — a single well-targeted researcher is often sufficient for focused gaps.
79
+ - **Source diversity**: Encourage researchers to find multiple authoritative sources per topic area to enable comprehensive citations in the final synthesis.
65
80
 
66
81
  ---
67
82
 
68
- ### Step 1: Assess Information Completeness
69
-
70
- Evaluate cumulative findings against ROOT QUERY and ORIGINAL AGENDA.
83
+ ## Quality Standards for Delegation
71
84
 
72
- **For each agenda item**:
73
- - Is it covered in depth with specific, actionable information?
74
- - Are claims backed by multiple corroborating sources?
75
- - Are there significant gaps or superficial coverage?
76
- - Is information contradicted without resolution?
77
-
78
- **SYNTHESIZE NOW if:**
79
- - Every agenda item substantively addressed with depth
80
- - Root query answerable with high confidence
81
- - Findings corroborated by multiple sources
82
- - Remaining gaps trivial, academic, or beyond reasonable scope
83
- - Information high-quality, specific, actionable
84
-
85
- **DELEGATE FURTHER RESEARCH if:**
86
- - One or more agenda items missing or barely explored
87
- - Critical aspects of root query unaddressed
88
- - Findings superficial, generic, lack specificity
89
- - Claims lack adequate evidence or corroboration
90
- - High-value scrape candidates would fill gaps
91
- - Contradictions exist requiring targeted resolution
92
-
93
- ### Step 2: Consider Depth Budget
94
-
95
- **If current round < Target rounds**: You have capacity. Prioritize fulfilling all agenda items before synthesizing.
96
-
97
- **If current round == Target rounds**: At intended depth. Synthesize if the agenda is substantially covered. Only delegate if CRITICAL GAPS remain unexplored — limit to 1-2 high-impact queries.
98
-
99
- **If current round > Target rounds**: Extended territory (bonus rounds). Synthesize NOW unless a catastrophic coverage failure occurred. Do NOT delegate for minor gaps.
100
-
101
- ### Step 3: Make Strategic Decision
102
-
103
- **If synthesizing**: Provide comprehensive synthesis. Be exhaustive. Integrate findings from all researchers. Resolve conflicts where possible. Acknowledge limitations.
104
-
105
- **If delegating**: Formulate targeted queries for remaining gaps. Focus on unaddressed agenda items. Limit to 1-2 high-impact queries.
85
+ When delegating, ensure:
86
+ - **Query Specificity**: Each new query targets distinct, unexplored territory
87
+ - **No Redundancy**: Do not repeat queries from previous rounds
88
+ - **Specialized Focus**: Each new researcher has a clear, distinct angle
89
+ - **Gap-Driven**: Only delegate when gaps cannot be resolved from existing findings
90
+ - **Progressive Depth**: New queries go deeper, or to a new angle still inside the query's scope — never outside it, and never repeating surface-level coverage
106
91
 
107
92
  ---
108
93
 
109
- ## Researcher Scrape Protocol
110
-
111
- Each researcher followed a context-aware up-to-4-call scrape protocol:
112
- 1. **Handshake**: Check for already-scraped links (no network)
113
- 2. **Batch 1**: Up to 3 URLs — primary broad scraping
114
- 3. **Batch 2**: Up to 2 URLs — targeted follow-up (auto-deduplicated)
115
- 4. **Batch 3**: Up to 3 URLs — deep-dive
94
+ ## Synthesis Protocol (action = synthesize)
116
95
 
117
- Batches automatically skipped when researcher's context exceeds 55%. Fewer sources than maximum is expected and not a failure.
96
+ 1. **Organization**: Organize the report logically **BY TOPIC**. Do NOT structure it by researcher or round.
97
+ 2. **Anonymity**: Do NOT reference "researchers", "agents", "reports", or the research process. Present the findings as a direct, unified knowledge base.
98
+ 3. **Master Links List**: A **Global Source List** has been provided to you. Use these sequential numbers [1], [2], [3], etc., for all inline citations. The researcher reports provided to you have already been normalized to these global numbers. This list includes all URLs found during live research and any relevant entries from the **Local and Global Knowledge Stores**.
99
+ 4. **Exhaustive Synthesis**: Use ALL findings from ALL reports. Include every fact, date, name, and statistic verbatim. Longer is better.
100
+ 5. **Strict Grounding**: Every sentence must come from a report. Use [N] inline citations. No prior knowledge.
101
+ 6. **CRITICAL — Links at Bottom Only**:
102
+ - Write all topic sections first with inline citations [1], [2], etc., using the numbers from the **Global Source List**.
103
+ - Place exactly ONE `CITED LINKS` section at the VERY END of the entire synthesis.
104
+ - This section must contain the complete master list of all unique URLs exactly as provided in the **Global Source List**.
105
+ - Do NOT include any links within topic sections or subsections.
106
+ - Format: `[1] https://url.com [Source: ...] — brief description` on each line.
118
107
 
119
- **When evaluating findings**:
120
- - **Corroborating**: Multiple researchers found similar information — strong confidence
121
- - **Complementary**: Different researchers covered different aspects — integrate both
122
- - **Conflicting**: Sources disagree — identify conflict, explain evidence, suggest resolution or acknowledge uncertainty
108
+ > **MANDATORY TERMINATION RULE**: Your synthesis is not complete until it ends with `CITED LINKS`. Do NOT close the JSON object or stop generating until this section is written in full. A synthesis without `CITED LINKS` is a failed output.
123
109
 
124
110
  ---
125
111
 
126
- ## Synthesis Output Format
127
-
128
- Provide **full breadth, depth, nuance** of information from all sources. This is the final result — be thorough.
129
-
130
- ```markdown
131
- # Research Synthesis: [Comprehensive Topic Title]
132
-
133
- ## Executive Summary
134
- [High-level analytical overview. Identify most critical insights, patterns, conclusions. Comprehensive summary that stands alone.]
135
-
136
- ## Detailed Key Findings
137
-
138
- ### [Major Theme/Category 1]
139
- - **In-Depth Analysis**: [Exhaustive explanation. Incorporate multiple sources and perspectives. Cite researchers where relevant. Provide context.]
140
- - **Sub-Finding 1**: [Specific detail with citations]
141
- - **Sub-Finding 2**: [Specific detail with citations]
142
- - **Context & Implications**: [What do findings mean? Why significant? How relate to broader topic?]
143
-
144
- ### [Major Theme/Category 2]
145
- - **In-Depth Analysis**: [Continue for all major themes...]
146
-
147
- ## Critical Nuance and Conflicting Perspectives
148
-
149
- [Identify areas where:
150
- - Sources provided different or contradictory information
151
- - Topic inherently complex or ambiguous
152
- - Findings require interpretation or multiple perspectives
153
- - Uncertainty or lack of consensus
154
-
155
- For each: describe conflicting information, explain evidence, provide synthesis or acknowledge ambiguity, suggest resolution or additional research needs]
156
-
157
- ## Coverage & Agenda Assessment
158
-
159
- [Address specifically:
160
- - Which initial agenda items fully resolved
161
- - Which items partially explored or unaddressed
162
- - Why certain areas incomplete (sources unavailable, complexity, etc.)
163
- - Overall comprehensiveness relative to original query]
164
-
165
- ## Final Conclusions & Strategic Recommendations
166
-
167
- [Synthesize key takeaways:
168
- - Most important conclusions
169
- - Practical implications
170
- - Actions/decisions informed by findings
171
- - Research limitations
172
- - Most valuable additional information if further research conducted]
173
-
174
- ## CITED LINKS
175
-
176
- [List every URL cited in synthesis, deduplicated. For each:]
177
- * [URL] — Brief description of contribution and significance
178
-
179
- ## Research Limitations
180
-
181
- [Only include if there are material gaps that significantly constrain the findings — omit if coverage is adequate. Do NOT list scrape candidates as raw URLs. Instead describe what remains unknown and why it matters:]
182
- - [Topic/area] — What is unknown and its relevance to the root query
183
- ```
184
-
185
- ---
186
-
187
- ## Delegation Output Format
188
-
189
- Provide a JSON object with `action` and `queries` fields:
190
-
191
- ```json
192
- {"action": "delegate", "queries": ["Targeted research question addressing critical gap", "Another specific research direction for remaining gaps"]}
193
- ```
194
-
195
- **CRITICAL REQUIREMENTS FOR DELEGATION**:
196
- - `action` must be exactly the string `"delegate"` (not `delegate` without quotes)
197
- - `queries` must be an array of strings (not objects, not numbers)
198
- - Each query string must be non-empty after trimming
199
- - Do not include nested objects like `{"query": "text"}` — use plain strings only
200
-
201
- **Delegation Guidance**:
202
- - Each query addresses specific, high-impact gap
203
- - Queries distinct and complementary, not overlapping
204
- - **For unfulfilled agenda items: copy the exact query string from the "Unfulfilled Agenda Items" list** — do not rephrase. This ensures the system can track coverage.
205
- - For new gaps not in the original agenda, formulate targeted queries
206
- - Consider what information would most transform understanding
207
- - Avoid duplicating already-researched topics
208
- - Ensure queries specific enough to yield actionable results
209
-
210
- ---
112
+ ## Output Requirements
211
113
 
212
- ## Critical Rules
213
-
214
- - **CHECK FOR ERRORS FIRST**: If all researchers failed with `ERROR:` reports, output error report format.
215
- - **ONE DECISION ONLY**: Either synthesize OR delegate. Do not provide both.
216
- - **OUTPUT FORMAT DETERMINES ACTION**:
217
- - JSON object `{"action": "delegate", "queries": [...]}` → Delegating additional research
218
- - Any other output (markdown, prose) → Treated as final synthesis
219
- - **IMPORTANT**: The JSON must be valid, properly formatted, with string values in the `queries` array
220
- - **NO DECISION MEMOS**: Never output text explaining decision (e.g., "# Decision: NO"). Provide ONLY synthesis, error report, or JSON array.
221
- - **BE EXHAUSTIVE IN SYNTHESIS**: Provide full depth and breadth. Do not truncate excessively.
222
- - **NO SCRAPE CANDIDATE LISTS**: Do not enumerate URLs from researcher SCRAPE CANDIDATES sections — these are internal scaffolding. Mention material gaps in prose under Research Limitations only if they affect the findings.
223
- - **BE TARGETED IN DELEGATION**: Provide specific, high-impact queries addressing genuine gaps.
224
- - **USE PLAIN STRINGS IN QUERIES**: Do not use objects like `{"query": "text"}` in the queries array — use plain strings only.
225
- - **SUBMIT AND STOP**: After providing decision, stop. System handles next steps.
114
+ - **Researcher IDs**: Use Round.Index format (e.g. **{{round_number}}.1**, **{{round_number}}.2**).
115
+ - **Query Budget**: Use the complexity-specific budget ({{query_budget}} per researcher). Fill each researcher's query budget completely.
116
+ - **Team Size**: Scale researcher count to match the gaps. Use up to {{max_team_size}} researchers when delegating, but a single well-targeted researcher is often sufficient for focused gaps. Don't pad the team when fewer researchers will cover the remaining gaps efficiently.
117
+ - **Synthesis Quality**: Logical topic-based structure in plain prose, maximal detail, NO mention of researchers, NO markdown headings or bullets.
118
+ - **Format**: ONLY return valid JSON in a code block.