qlogicagent 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (229) hide show
  1. package/dist/agent.js +1 -0
  2. package/dist/cli.js +9 -0
  3. package/dist/contracts.js +1 -0
  4. package/dist/index.js +5 -15
  5. package/dist/orchestration.js +118 -0
  6. package/package.json +56 -42
  7. package/dist/agent/agent.js +0 -113
  8. package/dist/agent/tool-loop.js +0 -575
  9. package/dist/agent/types.js +0 -14
  10. package/dist/cli/main.js +0 -23
  11. package/dist/cli/stdio-server.js +0 -463
  12. package/dist/config/config.js +0 -21
  13. package/dist/contracts/hooks.js +0 -7
  14. package/dist/contracts/index.js +0 -10
  15. package/dist/contracts/planner.js +0 -2
  16. package/dist/contracts/skill-candidate.js +0 -195
  17. package/dist/contracts/todo.js +0 -9
  18. package/dist/llm/builtin-providers.js +0 -531
  19. package/dist/llm/index.js +0 -14
  20. package/dist/llm/llm-client.js +0 -67
  21. package/dist/llm/model-catalog.js +0 -191
  22. package/dist/llm/provider-def.js +0 -12
  23. package/dist/llm/provider-registry.js +0 -147
  24. package/dist/llm/transport.js +0 -27
  25. package/dist/llm/transports/anthropic-messages.js +0 -293
  26. package/dist/llm/transports/openai-chat.js +0 -165
  27. package/dist/orchestration/agent-registry.js +0 -116
  28. package/dist/orchestration/approval-aware-tool-plan.js +0 -87
  29. package/dist/orchestration/context-compression.js +0 -583
  30. package/dist/orchestration/conversation-repair.js +0 -429
  31. package/dist/orchestration/curator-scheduler.js +0 -135
  32. package/dist/orchestration/embedded-failover-policy.js +0 -168
  33. package/dist/orchestration/error-classification.js +0 -77
  34. package/dist/orchestration/failover-classification.js +0 -381
  35. package/dist/orchestration/failover-error.js +0 -198
  36. package/dist/orchestration/fork-subagent.js +0 -98
  37. package/dist/orchestration/index.js +0 -267
  38. package/dist/orchestration/memory-flush-policy.js +0 -85
  39. package/dist/orchestration/memory-provider.js +0 -2
  40. package/dist/orchestration/parallel-tool-calls.js +0 -59
  41. package/dist/orchestration/prompt-cache-strategy.js +0 -228
  42. package/dist/orchestration/reactive-compact.js +0 -78
  43. package/dist/orchestration/retry-loop.js +0 -24
  44. package/dist/orchestration/skill-candidate.js +0 -141
  45. package/dist/orchestration/skill-consolidation.js +0 -220
  46. package/dist/orchestration/skill-improvement.js +0 -66
  47. package/dist/orchestration/skill-similarity.js +0 -131
  48. package/dist/orchestration/streaming-tool-executor.js +0 -96
  49. package/dist/orchestration/team-orchestration.js +0 -369
  50. package/dist/orchestration/team-tool-loop-wiring.js +0 -147
  51. package/dist/orchestration/tool-choice-policy.js +0 -164
  52. package/dist/orchestration/tool-loop-state.js +0 -133
  53. package/dist/orchestration/tool-schema.js +0 -297
  54. package/dist/orchestration/transcript-repair.js +0 -426
  55. package/dist/orchestration/turn-loop-guard.js +0 -92
  56. package/dist/orchestration/web-browser-policy.js +0 -39
  57. package/dist/runtime/context-compression.js +0 -274
  58. package/dist/runtime/hook-registry.js +0 -53
  59. package/dist/runtime/memory-hooks.js +0 -65
  60. package/dist/runtime/tool-eligibility.js +0 -111
  61. package/dist/skills/index.js +0 -82
  62. package/dist/skills/memory-extractor.js +0 -173
  63. package/dist/skills/memory-query-tool.js +0 -127
  64. package/dist/skills/memory-store.js +0 -228
  65. package/dist/skills/memory-tool.js +0 -192
  66. package/dist/skills/portable-tool.js +0 -14
  67. package/dist/skills/qmemory-adapter.js +0 -165
  68. package/dist/skills/skill-frontmatter.js +0 -344
  69. package/dist/skills/skill-guard.js +0 -229
  70. package/dist/skills/skill-loader.js +0 -303
  71. package/dist/skills/skill-source.js +0 -126
  72. package/dist/skills/skill-types.js +0 -6
  73. package/dist/skills/think-tool.js +0 -59
  74. package/dist/skills/todo-tool.js +0 -114
  75. package/dist/skills/tools/agent-tool.js +0 -142
  76. package/dist/skills/tools/apply-patch-tool.js +0 -184
  77. package/dist/skills/tools/ask-user-tool.js +0 -121
  78. package/dist/skills/tools/brief-tool.js +0 -95
  79. package/dist/skills/tools/browser-tool.js +0 -155
  80. package/dist/skills/tools/checkpoint-tool.js +0 -102
  81. package/dist/skills/tools/config-tool.js +0 -143
  82. package/dist/skills/tools/cron-tool.js +0 -175
  83. package/dist/skills/tools/edit-tool.js +0 -70
  84. package/dist/skills/tools/exec-tool.js +0 -133
  85. package/dist/skills/tools/image-generate-tool.js +0 -67
  86. package/dist/skills/tools/instructions-tool.js +0 -187
  87. package/dist/skills/tools/lsp-tool.js +0 -227
  88. package/dist/skills/tools/mcp-client-types.js +0 -53
  89. package/dist/skills/tools/mcp-tool.js +0 -503
  90. package/dist/skills/tools/memory-tool.js +0 -88
  91. package/dist/skills/tools/monitor-tool.js +0 -131
  92. package/dist/skills/tools/music-generate-tool.js +0 -62
  93. package/dist/skills/tools/notify-tool.js +0 -62
  94. package/dist/skills/tools/patch-tool.js +0 -505
  95. package/dist/skills/tools/pdf-tool.js +0 -88
  96. package/dist/skills/tools/plan-mode-tool.js +0 -122
  97. package/dist/skills/tools/read-tool.js +0 -84
  98. package/dist/skills/tools/repl-tool.js +0 -69
  99. package/dist/skills/tools/search-tool.js +0 -225
  100. package/dist/skills/tools/send-message-tool.js +0 -76
  101. package/dist/skills/tools/skill-list-tool.js +0 -54
  102. package/dist/skills/tools/skill-manage-tool.js +0 -153
  103. package/dist/skills/tools/skill-view-tool.js +0 -72
  104. package/dist/skills/tools/sleep-tool.js +0 -81
  105. package/dist/skills/tools/structured-output-tool.js +0 -176
  106. package/dist/skills/tools/task-tool.js +0 -161
  107. package/dist/skills/tools/team-tool.js +0 -105
  108. package/dist/skills/tools/tool-search-tool.js +0 -110
  109. package/dist/skills/tools/tts-tool.js +0 -45
  110. package/dist/skills/tools/video-edit-tool.js +0 -74
  111. package/dist/skills/tools/video-generate-tool.js +0 -66
  112. package/dist/skills/tools/video-merge-tool.js +0 -92
  113. package/dist/skills/tools/video-upscale-tool.js +0 -52
  114. package/dist/skills/tools/web-fetch-tool.js +0 -92
  115. package/dist/skills/tools/web-search-tool.js +0 -86
  116. package/dist/skills/tools/worktree-tool.js +0 -147
  117. package/dist/skills/tools/write-tool.js +0 -81
  118. /package/dist/{agent → types/agent}/agent.d.ts +0 -0
  119. /package/dist/{agent → types/agent}/tool-loop.d.ts +0 -0
  120. /package/dist/{agent → types/agent}/types.d.ts +0 -0
  121. /package/dist/{cli → types/cli}/main.d.ts +0 -0
  122. /package/dist/{cli → types/cli}/stdio-server.d.ts +0 -0
  123. /package/dist/{config → types/config}/config.d.ts +0 -0
  124. /package/dist/{contracts → types/contracts}/hooks.d.ts +0 -0
  125. /package/dist/{contracts → types/contracts}/index.d.ts +0 -0
  126. /package/dist/{contracts → types/contracts}/planner.d.ts +0 -0
  127. /package/dist/{contracts → types/contracts}/skill-candidate.d.ts +0 -0
  128. /package/dist/{contracts → types/contracts}/todo.d.ts +0 -0
  129. /package/dist/{index.d.ts → types/index.d.ts} +0 -0
  130. /package/dist/{llm → types/llm}/builtin-providers.d.ts +0 -0
  131. /package/dist/{llm → types/llm}/index.d.ts +0 -0
  132. /package/dist/{llm → types/llm}/llm-client.d.ts +0 -0
  133. /package/dist/{llm → types/llm}/model-catalog.d.ts +0 -0
  134. /package/dist/{llm → types/llm}/provider-def.d.ts +0 -0
  135. /package/dist/{llm → types/llm}/provider-registry.d.ts +0 -0
  136. /package/dist/{llm → types/llm}/transport.d.ts +0 -0
  137. /package/dist/{llm → types/llm}/transports/anthropic-messages.d.ts +0 -0
  138. /package/dist/{llm → types/llm}/transports/openai-chat.d.ts +0 -0
  139. /package/dist/{orchestration → types/orchestration}/agent-registry.d.ts +0 -0
  140. /package/dist/{orchestration → types/orchestration}/approval-aware-tool-plan.d.ts +0 -0
  141. /package/dist/{orchestration → types/orchestration}/context-compression.d.ts +0 -0
  142. /package/dist/{orchestration → types/orchestration}/conversation-repair.d.ts +0 -0
  143. /package/dist/{orchestration → types/orchestration}/curator-scheduler.d.ts +0 -0
  144. /package/dist/{orchestration → types/orchestration}/embedded-failover-policy.d.ts +0 -0
  145. /package/dist/{orchestration → types/orchestration}/error-classification.d.ts +0 -0
  146. /package/dist/{orchestration → types/orchestration}/failover-classification.d.ts +0 -0
  147. /package/dist/{orchestration → types/orchestration}/failover-error.d.ts +0 -0
  148. /package/dist/{orchestration → types/orchestration}/fork-subagent.d.ts +0 -0
  149. /package/dist/{orchestration → types/orchestration}/index.d.ts +0 -0
  150. /package/dist/{orchestration → types/orchestration}/memory-flush-policy.d.ts +0 -0
  151. /package/dist/{orchestration → types/orchestration}/memory-provider.d.ts +0 -0
  152. /package/dist/{orchestration → types/orchestration}/parallel-tool-calls.d.ts +0 -0
  153. /package/dist/{orchestration → types/orchestration}/prompt-cache-strategy.d.ts +0 -0
  154. /package/dist/{orchestration → types/orchestration}/reactive-compact.d.ts +0 -0
  155. /package/dist/{orchestration → types/orchestration}/retry-loop.d.ts +0 -0
  156. /package/dist/{orchestration → types/orchestration}/skill-candidate.d.ts +0 -0
  157. /package/dist/{orchestration → types/orchestration}/skill-consolidation.d.ts +0 -0
  158. /package/dist/{orchestration → types/orchestration}/skill-improvement.d.ts +0 -0
  159. /package/dist/{orchestration → types/orchestration}/skill-similarity.d.ts +0 -0
  160. /package/dist/{orchestration → types/orchestration}/streaming-tool-executor.d.ts +0 -0
  161. /package/dist/{orchestration → types/orchestration}/team-orchestration.d.ts +0 -0
  162. /package/dist/{orchestration → types/orchestration}/team-tool-loop-wiring.d.ts +0 -0
  163. /package/dist/{orchestration → types/orchestration}/tool-choice-policy.d.ts +0 -0
  164. /package/dist/{orchestration → types/orchestration}/tool-loop-state.d.ts +0 -0
  165. /package/dist/{orchestration → types/orchestration}/tool-schema.d.ts +0 -0
  166. /package/dist/{orchestration → types/orchestration}/transcript-repair.d.ts +0 -0
  167. /package/dist/{orchestration → types/orchestration}/turn-loop-guard.d.ts +0 -0
  168. /package/dist/{orchestration → types/orchestration}/web-browser-policy.d.ts +0 -0
  169. /package/dist/{runtime → types/runtime}/context-compression.d.ts +0 -0
  170. /package/dist/{runtime → types/runtime}/hook-registry.d.ts +0 -0
  171. /package/dist/{runtime → types/runtime}/memory-hooks.d.ts +0 -0
  172. /package/dist/{runtime → types/runtime}/tool-eligibility.d.ts +0 -0
  173. /package/dist/{skills → types/skills}/index.d.ts +0 -0
  174. /package/dist/{skills → types/skills}/memory-extractor.d.ts +0 -0
  175. /package/dist/{skills → types/skills}/memory-query-tool.d.ts +0 -0
  176. /package/dist/{skills → types/skills}/memory-store.d.ts +0 -0
  177. /package/dist/{skills → types/skills}/memory-tool.d.ts +0 -0
  178. /package/dist/{skills → types/skills}/portable-tool.d.ts +0 -0
  179. /package/dist/{skills → types/skills}/qmemory-adapter.d.ts +0 -0
  180. /package/dist/{skills → types/skills}/skill-frontmatter.d.ts +0 -0
  181. /package/dist/{skills → types/skills}/skill-guard.d.ts +0 -0
  182. /package/dist/{skills → types/skills}/skill-loader.d.ts +0 -0
  183. /package/dist/{skills → types/skills}/skill-source.d.ts +0 -0
  184. /package/dist/{skills → types/skills}/skill-types.d.ts +0 -0
  185. /package/dist/{skills → types/skills}/think-tool.d.ts +0 -0
  186. /package/dist/{skills → types/skills}/todo-tool.d.ts +0 -0
  187. /package/dist/{skills → types/skills}/tools/agent-tool.d.ts +0 -0
  188. /package/dist/{skills → types/skills}/tools/apply-patch-tool.d.ts +0 -0
  189. /package/dist/{skills → types/skills}/tools/ask-user-tool.d.ts +0 -0
  190. /package/dist/{skills → types/skills}/tools/brief-tool.d.ts +0 -0
  191. /package/dist/{skills → types/skills}/tools/browser-tool.d.ts +0 -0
  192. /package/dist/{skills → types/skills}/tools/checkpoint-tool.d.ts +0 -0
  193. /package/dist/{skills → types/skills}/tools/config-tool.d.ts +0 -0
  194. /package/dist/{skills → types/skills}/tools/cron-tool.d.ts +0 -0
  195. /package/dist/{skills → types/skills}/tools/edit-tool.d.ts +0 -0
  196. /package/dist/{skills → types/skills}/tools/exec-tool.d.ts +0 -0
  197. /package/dist/{skills → types/skills}/tools/image-generate-tool.d.ts +0 -0
  198. /package/dist/{skills → types/skills}/tools/instructions-tool.d.ts +0 -0
  199. /package/dist/{skills → types/skills}/tools/lsp-tool.d.ts +0 -0
  200. /package/dist/{skills → types/skills}/tools/mcp-client-types.d.ts +0 -0
  201. /package/dist/{skills → types/skills}/tools/mcp-tool.d.ts +0 -0
  202. /package/dist/{skills → types/skills}/tools/memory-tool.d.ts +0 -0
  203. /package/dist/{skills → types/skills}/tools/monitor-tool.d.ts +0 -0
  204. /package/dist/{skills → types/skills}/tools/music-generate-tool.d.ts +0 -0
  205. /package/dist/{skills → types/skills}/tools/notify-tool.d.ts +0 -0
  206. /package/dist/{skills → types/skills}/tools/patch-tool.d.ts +0 -0
  207. /package/dist/{skills → types/skills}/tools/pdf-tool.d.ts +0 -0
  208. /package/dist/{skills → types/skills}/tools/plan-mode-tool.d.ts +0 -0
  209. /package/dist/{skills → types/skills}/tools/read-tool.d.ts +0 -0
  210. /package/dist/{skills → types/skills}/tools/repl-tool.d.ts +0 -0
  211. /package/dist/{skills → types/skills}/tools/search-tool.d.ts +0 -0
  212. /package/dist/{skills → types/skills}/tools/send-message-tool.d.ts +0 -0
  213. /package/dist/{skills → types/skills}/tools/skill-list-tool.d.ts +0 -0
  214. /package/dist/{skills → types/skills}/tools/skill-manage-tool.d.ts +0 -0
  215. /package/dist/{skills → types/skills}/tools/skill-view-tool.d.ts +0 -0
  216. /package/dist/{skills → types/skills}/tools/sleep-tool.d.ts +0 -0
  217. /package/dist/{skills → types/skills}/tools/structured-output-tool.d.ts +0 -0
  218. /package/dist/{skills → types/skills}/tools/task-tool.d.ts +0 -0
  219. /package/dist/{skills → types/skills}/tools/team-tool.d.ts +0 -0
  220. /package/dist/{skills → types/skills}/tools/tool-search-tool.d.ts +0 -0
  221. /package/dist/{skills → types/skills}/tools/tts-tool.d.ts +0 -0
  222. /package/dist/{skills → types/skills}/tools/video-edit-tool.d.ts +0 -0
  223. /package/dist/{skills → types/skills}/tools/video-generate-tool.d.ts +0 -0
  224. /package/dist/{skills → types/skills}/tools/video-merge-tool.d.ts +0 -0
  225. /package/dist/{skills → types/skills}/tools/video-upscale-tool.d.ts +0 -0
  226. /package/dist/{skills → types/skills}/tools/web-fetch-tool.d.ts +0 -0
  227. /package/dist/{skills → types/skills}/tools/web-search-tool.d.ts +0 -0
  228. /package/dist/{skills → types/skills}/tools/worktree-tool.d.ts +0 -0
  229. /package/dist/{skills → types/skills}/tools/write-tool.d.ts +0 -0
@@ -1,220 +0,0 @@
1
- /**
2
- * Skill consolidation strategy — pure decision logic for
3
- * the Autonomous Curator's LLM-driven skill merging phase.
4
- *
5
- * This module:
6
- * 1. Detects prefix clusters among skill names.
7
- * 2. Builds the consolidation prompt for the LLM review agent.
8
- * 3. Parses structured LLM output into actionable merge/prune plans.
9
- * 4. Reconciles LLM intent against ground truth (existing skills).
10
- *
11
- * No I/O — the caller invokes the LLM and applies the results.
12
- */
13
- /**
14
- * Detect prefix clusters among skill names.
15
- *
16
- * A cluster is ≥2 skills sharing a common hyphenated prefix of ≥2 chars.
17
- * E.g. `["pr-review", "pr-merge", "pr-label"]` → cluster `"pr"`.
18
- */
19
- export function detectPrefixClusters(skillNames, minClusterSize = 2) {
20
- const prefixMap = new Map();
21
- for (const name of skillNames) {
22
- const dashIdx = name.indexOf("-");
23
- if (dashIdx < 2)
24
- continue;
25
- const prefix = name.slice(0, dashIdx);
26
- const existing = prefixMap.get(prefix);
27
- if (existing) {
28
- existing.push(name);
29
- }
30
- else {
31
- prefixMap.set(prefix, [name]);
32
- }
33
- }
34
- const clusters = [];
35
- for (const [prefix, skills] of prefixMap) {
36
- if (skills.length >= minClusterSize) {
37
- clusters.push({ prefix, skills: skills.sort() });
38
- }
39
- }
40
- return clusters.sort((a, b) => b.skills.length - a.skills.length);
41
- }
42
- // ── LLM prompt construction ────────────────────────────────────────
43
- /**
44
- * Build the consolidation review prompt for the LLM curator agent.
45
- *
46
- * The prompt instructs the model to:
47
- * 1. Identify prefix clusters and overlapping skills.
48
- * 2. Propose umbrella consolidations.
49
- * 3. Mark redundant/trivial skills for pruning (archive, not delete).
50
- * 4. Output a structured YAML block.
51
- */
52
- export function buildConsolidationPrompt(candidates, existingUmbrellas, clusters) {
53
- const candidateList = candidates.map((c) => `- **${c.name}** (${c.state}, uses: ${c.useCount}, tools: ${c.tools})${c.lastActivityAt ? ` last active: ${c.lastActivityAt}` : ""}`).join("\n");
54
- const umbrellaList = existingUmbrellas.length > 0
55
- ? existingUmbrellas.map((u) => `- ${u}`).join("\n")
56
- : "(none)";
57
- const clusterList = clusters.length > 0
58
- ? clusters.map((c) => `- **${c.prefix}-***: ${c.skills.join(", ")}`).join("\n")
59
- : "(no clusters detected)";
60
- return `You are the Autonomous Curator for a skill library.
61
-
62
- ## Goal
63
-
64
- Transform narrow, session-specific skills into a well-organized library of
65
- class-level umbrella skills. A collection of hundreds of narrow skills is FAILURE.
66
-
67
- ## Ground Rules
68
-
69
- 1. **NEVER delete** — only archive (prune). Archived skills can be restored.
70
- 2. **Do NOT touch pinned or bundled skills** — they are already filtered out.
71
- 3. **Identify prefix clusters** and merge them into umbrella skills.
72
- 4. **Move session-specific details** into the umbrella's references/ folder.
73
- 5. **Preserve unique value** — only merge if the source is genuinely redundant
74
- or a subset of the target.
75
-
76
- ## Detected Prefix Clusters
77
-
78
- ${clusterList}
79
-
80
- ## Existing Umbrella Skills
81
-
82
- ${umbrellaList}
83
-
84
- ## Candidate Skills for Review
85
-
86
- ${candidateList}
87
-
88
- ## Required Output Format
89
-
90
- Respond with EXACTLY this YAML block (no extra text outside the block):
91
-
92
- \`\`\`yaml
93
- consolidations:
94
- - source: "skill-name-a"
95
- target: "umbrella-skill"
96
- reason: "subset of umbrella functionality"
97
- - source: "skill-name-b"
98
- target: "new-umbrella-name"
99
- reason: "cluster merge"
100
-
101
- prunings:
102
- - skill: "skill-name-c"
103
- reason: "trivial single-use, no ongoing value"
104
- \`\`\`
105
-
106
- If no consolidations or prunings are warranted, use empty lists.
107
- Respond ONLY with the YAML block.`;
108
- }
109
- // ── LLM output parsing ─────────────────────────────────────────────
110
- /**
111
- * Parse the LLM's structured YAML response into a ConsolidationPlan.
112
- *
113
- * Tolerant: handles minor formatting variations, ignores unknown fields.
114
- */
115
- export function parseConsolidationOutput(llmOutput, knownSkills) {
116
- const consolidations = [];
117
- const prunings = [];
118
- const hallucinations = [];
119
- // Extract YAML block if wrapped in ```yaml ... ```
120
- const yamlMatch = llmOutput.match(/```(?:yaml)?\s*\n([\s\S]*?)```/);
121
- const yaml = yamlMatch ? yamlMatch[1] : llmOutput;
122
- // Parse consolidations
123
- const consolidationBlock = yaml.match(/consolidations:\s*\n((?:\s+-[\s\S]*?)?)(?=prunings:|$)/);
124
- if (consolidationBlock?.[1]) {
125
- const entries = consolidationBlock[1].matchAll(/- source:\s*"([^"]+)"\s*\n\s*target:\s*"([^"]+)"\s*\n\s*reason:\s*"([^"]+)"/g);
126
- for (const [, source, target, reason] of entries) {
127
- if (!knownSkills.has(source)) {
128
- hallucinations.push(source);
129
- continue;
130
- }
131
- consolidations.push({
132
- sourceSkill: source,
133
- targetUmbrella: target,
134
- targetExists: knownSkills.has(target),
135
- reason,
136
- });
137
- }
138
- }
139
- // Parse prunings
140
- const pruningBlock = yaml.match(/prunings:\s*\n([\s\S]*?)$/);
141
- if (pruningBlock?.[1]) {
142
- const entries = pruningBlock[1].matchAll(/- skill:\s*"([^"]+)"\s*\n\s*reason:\s*"([^"]+)"/g);
143
- for (const [, skill, reason] of entries) {
144
- if (!knownSkills.has(skill)) {
145
- hallucinations.push(skill);
146
- continue;
147
- }
148
- prunings.push({ skillName: skill, reason });
149
- }
150
- }
151
- return { consolidations, prunings, hallucinations };
152
- }
153
- // ── Reconciliation ─────────────────────────────────────────────────
154
- /**
155
- * Reconcile the LLM's consolidation plan against ground truth.
156
- *
157
- * Validates that:
158
- * - Source skills exist and aren't already consolidated in this plan.
159
- * - Target umbrellas either exist or are new (will be created).
160
- * - Pruning targets aren't also being consolidated.
161
- */
162
- export function reconcileConsolidationPlan(plan, knownSkills) {
163
- const validConsolidations = [];
164
- const validPrunings = [];
165
- const rejected = [];
166
- const consolidatedSources = new Set();
167
- for (const c of plan.consolidations) {
168
- if (!knownSkills.has(c.sourceSkill)) {
169
- rejected.push({
170
- action: `consolidate ${c.sourceSkill} → ${c.targetUmbrella}`,
171
- reason: `source skill "${c.sourceSkill}" not found`,
172
- });
173
- continue;
174
- }
175
- if (consolidatedSources.has(c.sourceSkill)) {
176
- rejected.push({
177
- action: `consolidate ${c.sourceSkill} → ${c.targetUmbrella}`,
178
- reason: `source skill "${c.sourceSkill}" already consolidated in this plan`,
179
- });
180
- continue;
181
- }
182
- if (c.sourceSkill === c.targetUmbrella) {
183
- rejected.push({
184
- action: `consolidate ${c.sourceSkill} → ${c.targetUmbrella}`,
185
- reason: "source and target are the same skill",
186
- });
187
- continue;
188
- }
189
- consolidatedSources.add(c.sourceSkill);
190
- validConsolidations.push(c);
191
- }
192
- for (const p of plan.prunings) {
193
- if (!knownSkills.has(p.skillName)) {
194
- rejected.push({
195
- action: `prune ${p.skillName}`,
196
- reason: `skill "${p.skillName}" not found`,
197
- });
198
- continue;
199
- }
200
- if (consolidatedSources.has(p.skillName)) {
201
- rejected.push({
202
- action: `prune ${p.skillName}`,
203
- reason: `skill "${p.skillName}" is being consolidated, not pruned`,
204
- });
205
- continue;
206
- }
207
- validPrunings.push(p);
208
- }
209
- return { validConsolidations, validPrunings, rejected };
210
- }
211
- /**
212
- * Build a human-readable summary from a curator run report.
213
- */
214
- export function buildCuratorRunSummary(report) {
215
- const parts = [];
216
- parts.push(`Curator run at ${report.runAt} (${report.durationSeconds.toFixed(1)}s)`);
217
- parts.push(`Auto: ${report.autoTransitionsChecked} checked, ${report.autoMarkedStale} stale, ${report.autoArchived} archived, ${report.autoReactivated} reactivated`);
218
- parts.push(`LLM: ${report.consolidationsAccepted} consolidated, ${report.pruningsAccepted} pruned, ${report.actionsRejected} rejected, ${report.hallucinations} hallucinated`);
219
- return parts.join("; ");
220
- }
@@ -1,66 +0,0 @@
1
- /**
2
- * Skill self-learning: decides whether a completed turn should
3
- * trigger skill creation or improvement instructions.
4
- */
5
- // ── Decision logic ─────────────────────────────────────────────────
6
- /**
7
- * Minimum tool call count to consider a turn "complex enough"
8
- * to warrant creating a reusable skill.
9
- */
10
- const MIN_TOOL_CALLS_FOR_SKILL = 3;
11
- /**
12
- * Minimum distinct tools to suggest a new skill.
13
- */
14
- const MIN_DISTINCT_TOOLS_FOR_SKILL = 2;
15
- /**
16
- * Determine whether a completed turn should produce a skill instruction.
17
- *
18
- * A new skill is suggested when:
19
- * - The turn succeeded
20
- * - It involved multi-step orchestration
21
- * - It used ≥3 tool calls across ≥2 distinct tools
22
- * - No existing skill was already applied
23
- *
24
- * An improvement is suggested when:
25
- * - The turn used an existing skill but got negative feedback
26
- */
27
- export function shouldCreateSkill(result) {
28
- if (!result.ok)
29
- return false;
30
- if (result.existingSkillName)
31
- return false;
32
- if (!result.multiStep)
33
- return false;
34
- if (result.toolCallCount < MIN_TOOL_CALLS_FOR_SKILL)
35
- return false;
36
- if (result.distinctToolCount < MIN_DISTINCT_TOOLS_FOR_SKILL)
37
- return false;
38
- return true;
39
- }
40
- export function shouldImproveSkill(result) {
41
- if (!result.existingSkillName)
42
- return false;
43
- return result.feedback === "negative";
44
- }
45
- /**
46
- * Build a skill instruction from a turn result, or null if none is warranted.
47
- */
48
- export function buildSkillInstruction(result, context) {
49
- if (shouldImproveSkill(result)) {
50
- return {
51
- type: "skill.improve",
52
- skillName: result.existingSkillName,
53
- reason: "negative user feedback on existing skill execution",
54
- };
55
- }
56
- if (shouldCreateSkill(result)) {
57
- return {
58
- type: "skill.create",
59
- suggestedName: context.suggestedName ?? `auto-skill-${context.tools.slice(0, 3).join("-")}`,
60
- description: `Multi-step orchestration using ${context.tools.join(", ")}`,
61
- tools: context.tools,
62
- stepCount: result.toolCallCount,
63
- };
64
- }
65
- return null;
66
- }
@@ -1,131 +0,0 @@
1
- /**
2
- * Skill similarity — pure strategy for detecting near-duplicate skills
3
- * before creation and during curator consolidation reviews.
4
- *
5
- * Computes multi-signal similarity between skills:
6
- * 1. Tool-set Jaccard overlap (primary signal for auto-generated skills)
7
- * 2. Title/description cosine bigram similarity (complementary signal)
8
- * 3. Step-count proximity (minor signal for workflow complexity)
9
- *
10
- * No I/O — all functions are pure.
11
- */
12
- export const DEFAULT_SKILL_SIMILARITY_POLICY = {
13
- blockCreationThreshold: 0.75,
14
- curatorReviewThreshold: 0.55,
15
- toolWeight: 0.60,
16
- titleWeight: 0.30,
17
- stepWeight: 0.10,
18
- };
19
- // ── Core similarity functions ──────────────────────────────────────
20
- /**
21
- * Compute Jaccard index between two tool sets.
22
- * Returns 0 if both sets are empty.
23
- */
24
- export function toolSetJaccard(toolsA, toolsB) {
25
- const setA = new Set(toolsA.map((t) => t.toLowerCase()));
26
- const setB = new Set(toolsB.map((t) => t.toLowerCase()));
27
- if (setA.size === 0 && setB.size === 0)
28
- return 0;
29
- let intersection = 0;
30
- for (const t of setA) {
31
- if (setB.has(t))
32
- intersection++;
33
- }
34
- const union = setA.size + setB.size - intersection;
35
- return union === 0 ? 0 : intersection / union;
36
- }
37
- /**
38
- * Compute character-bigram similarity between two strings.
39
- * Uses Dice coefficient of bigram sets.
40
- */
41
- export function bigramSimilarity(a, b) {
42
- const bigramsA = extractBigrams(a.toLowerCase());
43
- const bigramsB = extractBigrams(b.toLowerCase());
44
- if (bigramsA.size === 0 && bigramsB.size === 0)
45
- return 0;
46
- if (bigramsA.size === 0 || bigramsB.size === 0)
47
- return 0;
48
- let intersection = 0;
49
- for (const bg of bigramsA) {
50
- if (bigramsB.has(bg))
51
- intersection++;
52
- }
53
- // Dice coefficient = 2 * |intersection| / (|A| + |B|)
54
- return (2 * intersection) / (bigramsA.size + bigramsB.size);
55
- }
56
- function extractBigrams(s) {
57
- const bigrams = new Set();
58
- const normalized = s.replace(/[^a-z0-9\u4e00-\u9fff]/g, " ").trim();
59
- for (let i = 0; i < normalized.length - 1; i++) {
60
- bigrams.add(normalized.slice(i, i + 2));
61
- }
62
- return bigrams;
63
- }
64
- /**
65
- * Compute step-count proximity [0, 1].
66
- * Returns 1 when counts are identical, decreases with difference.
67
- */
68
- export function stepCountProximity(stepsA, stepsB) {
69
- if (stepsA == null || stepsB == null)
70
- return 0.5; // neutral if unknown
71
- if (stepsA === 0 && stepsB === 0)
72
- return 1;
73
- const diff = Math.abs(stepsA - stepsB);
74
- const max = Math.max(stepsA, stepsB);
75
- return 1 - diff / max;
76
- }
77
- // ── Composite similarity ───────────────────────────────────────────
78
- /**
79
- * Compute overall similarity between two skill profiles.
80
- */
81
- export function computeSimilarity(a, b, policy) {
82
- const resolved = { ...DEFAULT_SKILL_SIMILARITY_POLICY, ...policy };
83
- const toolJaccard = toolSetJaccard(a.tools, b.tools);
84
- const titleSimilarity = bigramSimilarity(a.title, b.title);
85
- const stepProximity = stepCountProximity(a.stepCount, b.stepCount);
86
- const overall = resolved.toolWeight * toolJaccard +
87
- resolved.titleWeight * titleSimilarity +
88
- resolved.stepWeight * stepProximity;
89
- return { overall, toolJaccard, titleSimilarity, stepProximity };
90
- }
91
- // ── Pre-creation duplicate check ───────────────────────────────────
92
- /**
93
- * Check a new skill candidate against existing skills for similarity.
94
- *
95
- * Returns all existing skills above curatorReviewThreshold, sorted
96
- * by descending similarity. The caller should:
97
- * - Block creation if any match ≥ blockCreationThreshold (emit improve instead)
98
- * - Tag for curator review if match ≥ curatorReviewThreshold
99
- */
100
- export function findSimilarSkills(newSkill, existingSkills, policy) {
101
- const resolved = { ...DEFAULT_SKILL_SIMILARITY_POLICY, ...policy };
102
- const matches = [];
103
- for (const existing of existingSkills) {
104
- if (existing.skillKey === newSkill.skillKey)
105
- continue; // skip self
106
- const score = computeSimilarity(newSkill, existing, resolved);
107
- if (score.overall >= resolved.curatorReviewThreshold) {
108
- matches.push({ existingSkillKey: existing.skillKey, score });
109
- }
110
- }
111
- return matches.sort((a, b) => b.score.overall - a.score.overall);
112
- }
113
- export function decideSimilarityAction(matches, policy) {
114
- const resolved = { ...DEFAULT_SKILL_SIMILARITY_POLICY, ...policy };
115
- if (matches.length === 0) {
116
- return { action: "create", reason: "no similar skills found" };
117
- }
118
- const top = matches[0];
119
- if (top.score.overall >= resolved.blockCreationThreshold) {
120
- return {
121
- action: "improve",
122
- targetSkillKey: top.existingSkillKey,
123
- reason: `similarity ${(top.score.overall * 100).toFixed(0)}% ≥ creation threshold ${(resolved.blockCreationThreshold * 100).toFixed(0)}% (tool overlap: ${(top.score.toolJaccard * 100).toFixed(0)}%)`,
124
- };
125
- }
126
- return {
127
- action: "flag-for-review",
128
- targetSkillKey: top.existingSkillKey,
129
- reason: `similarity ${(top.score.overall * 100).toFixed(0)}% between review and creation thresholds`,
130
- };
131
- }
@@ -1,96 +0,0 @@
1
- /**
2
- * StreamingToolExecutor — Executes tool calls as they arrive during LLM streaming.
3
- *
4
- * Aligned with Claude Code's StreamingToolExecutor pattern:
5
- * - As each complete tool_use block arrives during streaming, immediately dispatch execution
6
- * - Don't wait for the full LLM response to finish before starting tool execution
7
- * - Results queue up and can be collected at any time
8
- *
9
- * This reduces perceived latency by overlapping LLM generation time with tool execution time.
10
- */
11
- export function createStreamingToolExecutor(executeFn, config = {}) {
12
- const maxConcurrency = Math.max(1, config.maxConcurrency ?? 8);
13
- const abortSignal = config.abortSignal;
14
- const pending = [];
15
- const completedQueue = [];
16
- let dispatchedCount = 0;
17
- let aborted = false;
18
- if (abortSignal) {
19
- abortSignal.addEventListener("abort", () => { aborted = true; }, { once: true });
20
- }
21
- function addTool(toolCall) {
22
- if (aborted)
23
- return false;
24
- if (pending.length >= maxConcurrency)
25
- return false;
26
- dispatchedCount += 1;
27
- const startedAt = Date.now();
28
- const entry = {
29
- toolCallId: toolCall.id,
30
- toolName: toolCall.function.name,
31
- startedAt,
32
- promise: executeFn(toolCall, abortSignal)
33
- .then((result) => ({
34
- toolCallId: toolCall.id,
35
- toolName: toolCall.function.name,
36
- result,
37
- ok: true,
38
- startedAt,
39
- completedAt: Date.now(),
40
- }))
41
- .catch((err) => ({
42
- toolCallId: toolCall.id,
43
- toolName: toolCall.function.name,
44
- result: undefined,
45
- ok: false,
46
- startedAt,
47
- completedAt: Date.now(),
48
- error: err instanceof Error ? err.message : String(err),
49
- }))
50
- .then((result) => {
51
- // Move from pending to completed queue
52
- const idx = pending.indexOf(entry);
53
- if (idx >= 0)
54
- pending.splice(idx, 1);
55
- completedQueue.push(result);
56
- return result;
57
- }),
58
- };
59
- pending.push(entry);
60
- return true;
61
- }
62
- function getCompletedResults() {
63
- const results = completedQueue.splice(0);
64
- return results;
65
- }
66
- async function flush() {
67
- if (pending.length > 0) {
68
- await Promise.allSettled(pending.map((e) => e.promise));
69
- }
70
- return completedQueue.splice(0);
71
- }
72
- return {
73
- addTool,
74
- getCompletedResults,
75
- flush,
76
- get pendingCount() { return pending.length; },
77
- get dispatchedCount() { return dispatchedCount; },
78
- get aborted() { return aborted; },
79
- };
80
- }
81
- /**
82
- * Determine if a tool call can be dispatched immediately during streaming
83
- * based on its manifest properties.
84
- */
85
- export function canDispatchDuringStreaming(toolCall, manifest) {
86
- if (!manifest)
87
- return false;
88
- // Cannot dispatch during streaming if it requires user approval
89
- if (manifest.approvalMode === "user-confirm" || manifest.requiresApproval)
90
- return false;
91
- // Cannot dispatch if explicitly serial-only
92
- if (manifest.serialOnly)
93
- return false;
94
- // Safe to dispatch during streaming
95
- return true;
96
- }