maskweaver 0.9.3 → 0.9.5

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 (246) hide show
  1. package/README.ko.md +279 -325
  2. package/README.md +109 -113
  3. package/assets/commands/meta/commands.json +34 -34
  4. package/assets/commands/weave-agents.md +12 -52
  5. package/assets/commands/weave-approve.md +12 -51
  6. package/assets/commands/weave-archive.md +21 -0
  7. package/assets/commands/weave-build.md +20 -89
  8. package/assets/commands/weave-craft.md +22 -43
  9. package/assets/commands/weave-help.md +37 -106
  10. package/assets/commands/weave-init.md +26 -108
  11. package/assets/commands/weave-interview.md +13 -111
  12. package/assets/commands/weave-map.md +13 -99
  13. package/assets/commands/weave-prepare.md +23 -69
  14. package/assets/commands/weave-refine-plan.md +26 -59
  15. package/assets/commands/weave-repair.md +22 -70
  16. package/assets/commands/weave-status.md +22 -155
  17. package/assets/commands/weave-troubleshoot.md +11 -47
  18. package/assets/commands/weave-verify.md +23 -44
  19. package/assets/commands/weave-worktree.md +27 -69
  20. package/dist/cli/doctor.js +5 -21
  21. package/dist/cli/install.d.ts +0 -8
  22. package/dist/cli/install.js +0 -39
  23. package/dist/context/config.d.ts +0 -22
  24. package/dist/context/config.js +0 -28
  25. package/dist/context/feature.d.ts +0 -39
  26. package/dist/context/feature.js +0 -77
  27. package/dist/context/files.d.ts +0 -13
  28. package/dist/context/files.js +1 -24
  29. package/dist/context/index.d.ts +0 -7
  30. package/dist/context/index.js +0 -12
  31. package/dist/context/project.d.ts +0 -21
  32. package/dist/context/project.js +0 -30
  33. package/dist/context/types.d.ts +0 -48
  34. package/dist/context/types.js +0 -12
  35. package/dist/context/utils.d.ts +0 -18
  36. package/dist/context/utils.js +0 -27
  37. package/dist/core/engine/promptBuilder.d.ts +0 -17
  38. package/dist/core/engine/promptBuilder.js +0 -28
  39. package/dist/core/index.d.ts +0 -6
  40. package/dist/core/index.js +0 -9
  41. package/dist/core/loader/MaskLoader.d.ts +0 -23
  42. package/dist/core/loader/MaskLoader.js +0 -29
  43. package/dist/core/schema/types.d.ts +0 -47
  44. package/dist/core/schema/types.js +0 -6
  45. package/dist/core/schema/validator.d.ts +0 -14
  46. package/dist/core/schema/validator.js +0 -18
  47. package/dist/i18n/index.d.ts +0 -18
  48. package/dist/i18n/index.js +4 -23
  49. package/dist/index.d.ts +0 -8
  50. package/dist/index.js +0 -8
  51. package/dist/lib.d.ts +0 -5
  52. package/dist/lib.js +0 -12
  53. package/dist/memory/chunking.d.ts +0 -22
  54. package/dist/memory/chunking.js +2 -37
  55. package/dist/memory/core.d.ts +0 -29
  56. package/dist/memory/core.js +1 -52
  57. package/dist/memory/index.d.ts +0 -5
  58. package/dist/memory/index.js +0 -10
  59. package/dist/memory/indexer.d.ts +0 -21
  60. package/dist/memory/indexer.js +0 -44
  61. package/dist/memory/providers/examples.d.ts +0 -5
  62. package/dist/memory/providers/examples.js +4 -64
  63. package/dist/memory/providers/factory.d.ts +0 -44
  64. package/dist/memory/providers/factory.js +0 -46
  65. package/dist/memory/providers/index.d.ts +0 -26
  66. package/dist/memory/providers/index.js +0 -28
  67. package/dist/memory/providers/ollama.d.ts +0 -6
  68. package/dist/memory/providers/ollama.js +1 -8
  69. package/dist/memory/providers/openai.d.ts +0 -6
  70. package/dist/memory/providers/openai.js +1 -8
  71. package/dist/memory/providers/openrouter.d.ts +0 -6
  72. package/dist/memory/providers/openrouter.js +0 -8
  73. package/dist/memory/providers/text-only.d.ts +0 -13
  74. package/dist/memory/providers/text-only.js +0 -17
  75. package/dist/memory/providers/types.d.ts +0 -39
  76. package/dist/memory/providers/types.js +0 -7
  77. package/dist/memory/providers/voyage.d.ts +0 -22
  78. package/dist/memory/providers/voyage.js +1 -24
  79. package/dist/memory/search/hybrid.d.ts +0 -12
  80. package/dist/memory/search/hybrid.js +1 -22
  81. package/dist/memory/store/sqlite.d.ts +0 -72
  82. package/dist/memory/store/sqlite.js +4 -127
  83. package/dist/plugin/config/index.d.ts +0 -112
  84. package/dist/plugin/config/index.js +0 -115
  85. package/dist/plugin/index.d.ts +0 -13
  86. package/dist/plugin/index.js +1 -124
  87. package/dist/plugin/tools/command-registry.d.ts +0 -6
  88. package/dist/plugin/tools/command-registry.js +0 -14
  89. package/dist/plugin/tools/context.d.ts +0 -12
  90. package/dist/plugin/tools/context.js +0 -58
  91. package/dist/plugin/tools/maskSave.d.ts +0 -3
  92. package/dist/plugin/tools/maskSave.js +0 -3
  93. package/dist/plugin/tools/memoryGet.d.ts +0 -3
  94. package/dist/plugin/tools/memoryGet.js +0 -3
  95. package/dist/plugin/tools/memoryIndexer.d.ts +0 -3
  96. package/dist/plugin/tools/memoryIndexer.js +0 -10
  97. package/dist/plugin/tools/memorySearch.d.ts +0 -31
  98. package/dist/plugin/tools/memorySearch.js +0 -79
  99. package/dist/plugin/tools/memoryWrite.d.ts +0 -8
  100. package/dist/plugin/tools/memoryWrite.js +0 -32
  101. package/dist/plugin/tools/retrospect.d.ts +0 -3
  102. package/dist/plugin/tools/retrospect.js +0 -3
  103. package/dist/plugin/tools/slashcommand.d.ts +0 -11
  104. package/dist/plugin/tools/slashcommand.js +0 -38
  105. package/dist/plugin/tools/squad.d.ts +0 -12
  106. package/dist/plugin/tools/squad.js +11 -83
  107. package/dist/plugin/tools/weave.d.ts +0 -6
  108. package/dist/plugin/tools/weave.js +0 -78
  109. package/dist/plugin/types.d.ts +0 -20
  110. package/dist/plugin/types.js +0 -7
  111. package/dist/retrospect/index.d.ts +0 -7
  112. package/dist/retrospect/index.js +0 -9
  113. package/dist/retrospect/mask-save.d.ts +0 -12
  114. package/dist/retrospect/mask-save.js +1 -80
  115. package/dist/retrospect/retrospect.d.ts +0 -18
  116. package/dist/retrospect/retrospect.js +0 -63
  117. package/dist/retrospect/strategies/base.d.ts +0 -15
  118. package/dist/retrospect/strategies/base.js +0 -7
  119. package/dist/retrospect/strategies/deep.d.ts +0 -12
  120. package/dist/retrospect/strategies/deep.js +0 -24
  121. package/dist/retrospect/strategies/index.d.ts +0 -12
  122. package/dist/retrospect/strategies/index.js +0 -12
  123. package/dist/retrospect/strategies/quick.d.ts +0 -12
  124. package/dist/retrospect/strategies/quick.js +0 -19
  125. package/dist/retrospect/strategies/standard.d.ts +0 -12
  126. package/dist/retrospect/strategies/standard.js +0 -15
  127. package/dist/retrospect/types.d.ts +0 -7
  128. package/dist/retrospect/types.js +0 -7
  129. package/dist/shared/config.d.ts +0 -105
  130. package/dist/shared/config.js +0 -33
  131. package/dist/shared/errors.d.ts +0 -18
  132. package/dist/shared/errors.js +0 -19
  133. package/dist/shared/generate-agents.d.ts +0 -69
  134. package/dist/shared/generate-agents.js +2 -86
  135. package/dist/shared/image.d.ts +0 -67
  136. package/dist/shared/image.js +6 -104
  137. package/dist/shared/index.d.ts +0 -5
  138. package/dist/shared/index.js +0 -7
  139. package/dist/shared/model-registry.d.ts +0 -72
  140. package/dist/shared/model-registry.js +5 -95
  141. package/dist/shared/types.d.ts +0 -15
  142. package/dist/shared/types.js +0 -3
  143. package/dist/shared-context/dag.d.ts +0 -105
  144. package/dist/shared-context/dag.js +3 -114
  145. package/dist/shared-context/index.d.ts +0 -5
  146. package/dist/shared-context/index.js +0 -15
  147. package/dist/shared-context/logger.d.ts +0 -37
  148. package/dist/shared-context/logger.js +0 -41
  149. package/dist/shared-context/parallel-executor.d.ts +0 -54
  150. package/dist/shared-context/parallel-executor.js +4 -56
  151. package/dist/shared-context/session.d.ts +0 -56
  152. package/dist/shared-context/session.js +0 -47
  153. package/dist/shared-context/squad.d.ts +0 -68
  154. package/dist/shared-context/squad.js +0 -63
  155. package/dist/shared-context/storage.d.ts +0 -132
  156. package/dist/shared-context/storage.js +0 -116
  157. package/dist/shared-context/task.d.ts +0 -120
  158. package/dist/shared-context/task.js +0 -152
  159. package/dist/shared-context/test/dag.test.js +9 -14
  160. package/dist/shared-context/test/logger.test.d.ts +0 -8
  161. package/dist/shared-context/test/logger.test.js +0 -52
  162. package/dist/shared-context/test/session.test.d.ts +0 -7
  163. package/dist/shared-context/test/session.test.js +0 -63
  164. package/dist/shared-context/test/squad.test.d.ts +0 -10
  165. package/dist/shared-context/test/squad.test.js +2 -68
  166. package/dist/shared-context/test/storage.test.d.ts +0 -8
  167. package/dist/shared-context/test/storage.test.js +0 -68
  168. package/dist/shared-context/test/task.test.d.ts +0 -7
  169. package/dist/shared-context/test/task.test.js +0 -54
  170. package/dist/shared-context/test/watchdog.test.d.ts +0 -7
  171. package/dist/shared-context/test/watchdog.test.js +3 -58
  172. package/dist/shared-context/types.d.ts +0 -215
  173. package/dist/shared-context/types.js +0 -125
  174. package/dist/shared-context/watchdog.d.ts +0 -127
  175. package/dist/shared-context/watchdog.js +0 -148
  176. package/dist/shared-context/worktree.d.ts +0 -68
  177. package/dist/shared-context/worktree.js +2 -34
  178. package/dist/verify/budget.d.ts +0 -29
  179. package/dist/verify/budget.js +0 -34
  180. package/dist/verify/critical-files.d.ts +0 -17
  181. package/dist/verify/critical-files.js +0 -37
  182. package/dist/verify/escalation.d.ts +0 -20
  183. package/dist/verify/escalation.js +0 -22
  184. package/dist/verify/index.d.ts +0 -5
  185. package/dist/verify/index.js +0 -11
  186. package/dist/verify/prompts.d.ts +0 -20
  187. package/dist/verify/prompts.js +0 -20
  188. package/dist/verify/types.d.ts +0 -26
  189. package/dist/verify/types.js +1 -12
  190. package/dist/verify/verifier.d.ts +0 -29
  191. package/dist/verify/verifier.js +0 -54
  192. package/dist/version.d.ts +1 -16
  193. package/dist/version.js +1 -16
  194. package/dist/weave/bridge.d.ts +0 -35
  195. package/dist/weave/bridge.js +0 -51
  196. package/dist/weave/environment/detector.d.ts +0 -6
  197. package/dist/weave/environment/detector.js +4 -45
  198. package/dist/weave/environment/index.d.ts +0 -19
  199. package/dist/weave/environment/index.js +1 -39
  200. package/dist/weave/environment/issues.d.ts +0 -35
  201. package/dist/weave/environment/issues.js +0 -59
  202. package/dist/weave/git.d.ts +0 -8
  203. package/dist/weave/git.js +0 -8
  204. package/dist/weave/index.d.ts +0 -13
  205. package/dist/weave/index.js +2 -28
  206. package/dist/weave/knowledge/global.d.ts +0 -39
  207. package/dist/weave/knowledge/global.js +2 -78
  208. package/dist/weave/loop.js +0 -3
  209. package/dist/weave/orchestrator.d.ts +0 -69
  210. package/dist/weave/orchestrator.js +1 -101
  211. package/dist/weave/phase-manager.d.ts +0 -64
  212. package/dist/weave/phase-manager.js +0 -89
  213. package/dist/weave/security/secret-scan.d.ts +0 -14
  214. package/dist/weave/security/secret-scan.js +0 -19
  215. package/dist/weave/stages/build.js +0 -15
  216. package/dist/weave/stages/execute.d.ts +0 -42
  217. package/dist/weave/stages/execute.js +4 -86
  218. package/dist/weave/stages/handoff.d.ts +0 -7
  219. package/dist/weave/stages/handoff.js +0 -43
  220. package/dist/weave/stages/index.d.ts +0 -3
  221. package/dist/weave/stages/index.js +0 -3
  222. package/dist/weave/stages/intake.d.ts +0 -8
  223. package/dist/weave/stages/intake.js +5 -65
  224. package/dist/weave/stages/map.d.ts +0 -1
  225. package/dist/weave/stages/openspec.d.ts +0 -1
  226. package/dist/weave/stages/plan.d.ts +0 -11
  227. package/dist/weave/stages/plan.js +1 -53
  228. package/dist/weave/stages/refine.d.ts +0 -7
  229. package/dist/weave/stages/refine.js +0 -7
  230. package/dist/weave/stages/research.d.ts +0 -6
  231. package/dist/weave/stages/research.js +0 -6
  232. package/dist/weave/stages/spec.d.ts +0 -12
  233. package/dist/weave/stages/spec.js +0 -17
  234. package/dist/weave/types.d.ts +0 -20
  235. package/dist/weave/types.js +0 -5
  236. package/dist/weave/verification/commands.d.ts +0 -12
  237. package/dist/weave/verification/commands.js +0 -19
  238. package/dist/weave/verification/index.d.ts +0 -6
  239. package/dist/weave/verification/index.js +1 -19
  240. package/dist/weave/verification/playwright.d.ts +0 -47
  241. package/dist/weave/verification/playwright.js +1 -90
  242. package/dist/weave/worktree.d.ts +0 -16
  243. package/dist/weave/worktree.js +0 -23
  244. package/dist/weave/yaml-repair.d.ts +0 -39
  245. package/dist/weave/yaml-repair.js +13 -116
  246. package/package.json +1 -1
@@ -1,20 +1,10 @@
1
- /**
2
- * Embedding Provider Usage Examples
3
- *
4
- * Practical examples showing how to use the provider system.
5
- */
6
1
  import { createProvider, selectBestProvider, getDefaultConfigs } from "./index.js";
7
- // ============================================================================
8
- // Example 1: Auto-selection (Recommended)
9
- // ============================================================================
10
2
  async function example1_autoSelection() {
11
3
  console.log("Example 1: Auto-selection with graceful degradation\n");
12
- // Let the system choose the best available provider
13
4
  const provider = await selectBestProvider(getDefaultConfigs());
14
5
  console.log(`✓ Selected: ${provider.name}`);
15
6
  console.log(` Type: ${provider.type}`);
16
7
  console.log(` Dimensions: ${provider.dimensions}\n`);
17
- // Use it!
18
8
  const embeddings = await provider.embed([
19
9
  "Hello, world!",
20
10
  "TypeScript is awesome"
@@ -22,18 +12,13 @@ async function example1_autoSelection() {
22
12
  console.log(`Generated ${embeddings.length} embeddings`);
23
13
  console.log(`Each embedding has ${embeddings[0].length} dimensions\n`);
24
14
  }
25
- // ============================================================================
26
- // Example 2: Manual Provider Selection
27
- // ============================================================================
28
15
  async function example2_manualSelection() {
29
16
  console.log("Example 2: Manual provider selection\n");
30
- // For local development - privacy-first
31
17
  const localProvider = createProvider({
32
18
  type: "ollama",
33
19
  model: "nomic-embed-text"
34
20
  });
35
21
  console.log(`Using: ${localProvider.name}`);
36
- // Check health before using
37
22
  const health = await localProvider.healthCheck();
38
23
  if (!health.ok) {
39
24
  console.error(`❌ ${health.reason}`);
@@ -46,9 +31,6 @@ async function example2_manualSelection() {
46
31
  const embeddings = await localProvider.embed(["Test document"]);
47
32
  console.log(`Generated embedding with ${embeddings[0].length} dimensions\n`);
48
33
  }
49
- // ============================================================================
50
- // Example 3: Code-Specialized Embedding
51
- // ============================================================================
52
34
  async function example3_codeEmbedding() {
53
35
  console.log("Example 3: Code-specialized embedding with Voyage\n");
54
36
  const codeProvider = createProvider({
@@ -57,22 +39,17 @@ async function example3_codeEmbedding() {
57
39
  dimensions: 1024,
58
40
  apiKey: process.env.VOYAGE_API_KEY
59
41
  });
60
- // Code snippets
61
42
  const codeSnippets = [
62
43
  "function fibonacci(n: number): number { return n < 2 ? n : fibonacci(n-1) + fibonacci(n-2); }",
63
44
  "const factorial = (n: number): number => n <= 1 ? 1 : n * factorial(n - 1);",
64
45
  "class Stack<T> { private items: T[] = []; push(item: T) { this.items.push(item); } }"
65
46
  ];
66
- // Use code-specific embedding
67
47
  if (codeProvider.embedCode) {
68
48
  const embeddings = await codeProvider.embedCode(codeSnippets);
69
49
  console.log(`Generated ${embeddings.length} code embeddings`);
70
50
  console.log(`Optimized for code similarity search\n`);
71
51
  }
72
52
  }
73
- // ============================================================================
74
- // Example 4: Asymmetric Search (Query vs Document)
75
- // ============================================================================
76
53
  async function example4_asymmetricSearch() {
77
54
  console.log("Example 4: Asymmetric search with Voyage\n");
78
55
  const provider = createProvider({
@@ -80,17 +57,13 @@ async function example4_asymmetricSearch() {
80
57
  model: "voyage-4-lite",
81
58
  apiKey: process.env.VOYAGE_API_KEY
82
59
  });
83
- // Documents (what you're searching through)
84
60
  const documents = [
85
61
  "TypeScript is a strongly typed programming language that builds on JavaScript.",
86
62
  "Python is an interpreted, high-level programming language with dynamic semantics.",
87
63
  "Rust is a systems programming language focused on safety and performance."
88
64
  ];
89
- // Query (what the user is searching for)
90
65
  const query = "What is a type-safe language?";
91
- // Embed documents
92
66
  const docEmbeddings = await provider.embed(documents);
93
- // Embed query (optimized differently)
94
67
  let queryEmbedding;
95
68
  if (provider.embedQuery) {
96
69
  queryEmbedding = await provider.embedQuery(query);
@@ -100,14 +73,12 @@ async function example4_asymmetricSearch() {
100
73
  [queryEmbedding] = await provider.embed([query]);
101
74
  console.log("✓ Used standard embedding");
102
75
  }
103
- // Compute cosine similarity (simplified)
104
76
  const similarities = docEmbeddings.map((docEmb) => {
105
77
  const dotProduct = docEmb.reduce((sum, val, i) => sum + val * queryEmbedding[i], 0);
106
78
  const magnitude1 = Math.sqrt(docEmb.reduce((sum, val) => sum + val * val, 0));
107
79
  const magnitude2 = Math.sqrt(queryEmbedding.reduce((sum, val) => sum + val * val, 0));
108
80
  return dotProduct / (magnitude1 * magnitude2);
109
81
  });
110
- // Show results
111
82
  console.log("\nSearch results:");
112
83
  similarities
113
84
  .map((sim, i) => ({ doc: documents[i], similarity: sim }))
@@ -117,47 +88,35 @@ async function example4_asymmetricSearch() {
117
88
  });
118
89
  console.log();
119
90
  }
120
- // ============================================================================
121
- // Example 5: Custom Priority Order
122
- // ============================================================================
123
91
  async function example5_customPriority() {
124
92
  console.log("Example 5: Custom priority order\n");
125
- // Try local first, then cloud
126
93
  const customConfigs = [
127
- { type: "ollama" }, // Free, local
128
- { type: "openai", dimensions: 512 }, // Cheap, small dimensions
129
- { type: "text-only" } // Ultimate fallback
94
+ { type: "ollama" },
95
+ { type: "openai", dimensions: 512 },
96
+ { type: "text-only" }
130
97
  ];
131
98
  const provider = await selectBestProvider(customConfigs);
132
99
  console.log(`Selected: ${provider.name}`);
133
100
  console.log(`Strategy: Try local → Try cheap cloud → Fallback\n`);
134
101
  }
135
- // ============================================================================
136
- // Example 6: Production Configuration
137
- // ============================================================================
138
102
  async function example6_production() {
139
103
  console.log("Example 6: Production-ready configuration\n");
140
- // Production setup with redundancy
141
104
  const productionConfigs = [
142
- // Primary: High-quality embeddings
143
105
  {
144
106
  type: "openai",
145
107
  model: "text-embedding-3-large",
146
108
  dimensions: 3072
147
109
  },
148
- // Fallback 1: Smaller but still good
149
110
  {
150
111
  type: "openai",
151
112
  model: "text-embedding-3-small",
152
113
  dimensions: 1536
153
114
  },
154
- // Fallback 2: Alternative provider
155
115
  {
156
116
  type: "voyage",
157
117
  model: "voyage-4-lite",
158
118
  dimensions: 1024
159
119
  },
160
- // Fallback 3: Multi-provider gateway
161
120
  {
162
121
  type: "openrouter",
163
122
  model: "openai/text-embedding-3-small"
@@ -168,13 +127,9 @@ async function example6_production() {
168
127
  console.log(` Dimensions: ${provider.dimensions}`);
169
128
  console.log(` Type: ${provider.type}\n`);
170
129
  }
171
- // ============================================================================
172
- // Example 7: Batch Processing
173
- // ============================================================================
174
130
  async function example7_batchProcessing() {
175
131
  console.log("Example 7: Efficient batch processing\n");
176
132
  const provider = await selectBestProvider(getDefaultConfigs());
177
- // Efficient: Single API call
178
133
  const startTime = Date.now();
179
134
  const texts = Array.from({ length: 100 }, (_, i) => `Document number ${i + 1} with some content`);
180
135
  const embeddings = await provider.embed(texts);
@@ -182,16 +137,12 @@ async function example7_batchProcessing() {
182
137
  console.log(`✓ Embedded ${embeddings.length} documents in ${duration}ms`);
183
138
  console.log(` Average: ${(duration / embeddings.length).toFixed(2)}ms per document\n`);
184
139
  }
185
- // ============================================================================
186
- // Example 8: Error Handling
187
- // ============================================================================
188
140
  async function example8_errorHandling() {
189
141
  console.log("Example 8: Proper error handling\n");
190
142
  try {
191
- // Invalid configuration
192
143
  const provider = createProvider({
193
144
  type: "openai",
194
- dimensions: 999 // Invalid dimension!
145
+ dimensions: 999
195
146
  });
196
147
  await provider.embed(["test"]);
197
148
  }
@@ -200,9 +151,6 @@ async function example8_errorHandling() {
200
151
  console.log("✓ Errors are clear and actionable\n");
201
152
  }
202
153
  }
203
- // ============================================================================
204
- // Example 9: Health Monitoring
205
- // ============================================================================
206
154
  async function example9_healthMonitoring() {
207
155
  console.log("Example 9: Health monitoring\n");
208
156
  const providers = [
@@ -222,12 +170,8 @@ async function example9_healthMonitoring() {
222
170
  console.log();
223
171
  }
224
172
  }
225
- // ============================================================================
226
- // Example 10: Testing Setup
227
- // ============================================================================
228
173
  async function example10_testing() {
229
174
  console.log("Example 10: Testing setup\n");
230
- // Use text-only provider for fast tests
231
175
  const testProvider = createProvider({ type: "text-only" });
232
176
  console.log("Test provider setup:");
233
177
  console.log(` Name: ${testProvider.name}`);
@@ -237,9 +181,6 @@ async function example10_testing() {
237
181
  const embeddings = await testProvider.embed(["test1", "test2", "test3"]);
238
182
  console.log(` Generated ${embeddings.length} mock embeddings\n`);
239
183
  }
240
- // ============================================================================
241
- // Run Examples
242
- // ============================================================================
243
184
  async function runExamples() {
244
185
  const examples = [
245
186
  example1_autoSelection,
@@ -263,7 +204,6 @@ async function runExamples() {
263
204
  console.log("─".repeat(80) + "\n");
264
205
  }
265
206
  }
266
- // Run if executed directly
267
207
  if (import.meta.url === `file://${process.argv[1]}`) {
268
208
  runExamples().catch(console.error);
269
209
  }
@@ -1,48 +1,4 @@
1
- /**
2
- * Provider Factory with Graceful Degradation
3
- *
4
- * "Make the right things easy and the wrong things hard."
5
- *
6
- * This factory implements:
7
- * 1. Strategy Pattern - swappable providers
8
- * 2. Factory Pattern - centralized creation
9
- * 3. Graceful Degradation - automatic fallback to working providers
10
- */
11
1
  import type { IEmbeddingProvider, ProviderConfig } from "./types.js";
12
- /**
13
- * Create a provider from configuration
14
- *
15
- * @throws Error if provider type is invalid or required credentials are missing
16
- */
17
2
  export declare function createProvider(config: ProviderConfig): IEmbeddingProvider;
18
- /**
19
- * Select the best working provider from a list
20
- *
21
- * Implements graceful degradation:
22
- * - Tries each provider in order
23
- * - Returns first healthy provider
24
- * - Falls back to text-only if all fail
25
- *
26
- * @param configs - Array of provider configurations in priority order
27
- * @returns The first healthy provider or text-only fallback
28
- *
29
- * @example
30
- * ```typescript
31
- * const provider = await selectBestProvider([
32
- * { type: "voyage", model: "voyage-code-3" },
33
- * { type: "ollama" },
34
- * { type: "openai" }
35
- * ]);
36
- * ```
37
- */
38
3
  export declare function selectBestProvider(configs: ProviderConfig[]): Promise<IEmbeddingProvider>;
39
- /**
40
- * Get default provider configurations
41
- *
42
- * Priority order:
43
- * 1. Voyage (code-specialized)
44
- * 2. Ollama (local, free)
45
- * 3. OpenAI (reliable)
46
- * 4. OpenRouter (fallback)
47
- */
48
4
  export declare function getDefaultConfigs(): ProviderConfig[];
@@ -1,23 +1,8 @@
1
- /**
2
- * Provider Factory with Graceful Degradation
3
- *
4
- * "Make the right things easy and the wrong things hard."
5
- *
6
- * This factory implements:
7
- * 1. Strategy Pattern - swappable providers
8
- * 2. Factory Pattern - centralized creation
9
- * 3. Graceful Degradation - automatic fallback to working providers
10
- */
11
1
  import { OllamaProvider } from "./ollama.js";
12
2
  import { OpenAIProvider } from "./openai.js";
13
3
  import { VoyageProvider } from "./voyage.js";
14
4
  import { OpenRouterProvider } from "./openrouter.js";
15
5
  import { TextOnlyProvider } from "./text-only.js";
16
- /**
17
- * Create a provider from configuration
18
- *
19
- * @throws Error if provider type is invalid or required credentials are missing
20
- */
21
6
  export function createProvider(config) {
22
7
  switch (config.type) {
23
8
  case "ollama":
@@ -34,29 +19,8 @@ export function createProvider(config) {
34
19
  throw new Error(`Unknown provider type: ${config.type}`);
35
20
  }
36
21
  }
37
- /**
38
- * Select the best working provider from a list
39
- *
40
- * Implements graceful degradation:
41
- * - Tries each provider in order
42
- * - Returns first healthy provider
43
- * - Falls back to text-only if all fail
44
- *
45
- * @param configs - Array of provider configurations in priority order
46
- * @returns The first healthy provider or text-only fallback
47
- *
48
- * @example
49
- * ```typescript
50
- * const provider = await selectBestProvider([
51
- * { type: "voyage", model: "voyage-code-3" },
52
- * { type: "ollama" },
53
- * { type: "openai" }
54
- * ]);
55
- * ```
56
- */
57
22
  export async function selectBestProvider(configs) {
58
23
  const results = [];
59
- // Try each provider
60
24
  for (const config of configs) {
61
25
  try {
62
26
  const provider = createProvider(config);
@@ -72,20 +36,10 @@ export async function selectBestProvider(configs) {
72
36
  console.warn(`✗ Failed to initialize ${config.type}:`, error instanceof Error ? error.message : error);
73
37
  }
74
38
  }
75
- // Fallback to text-only
76
39
  console.warn("⚠️ All embedding providers failed. Falling back to text-only mode.");
77
40
  console.warn(" Semantic search will be limited to keyword matching.");
78
41
  return new TextOnlyProvider({ type: "text-only" });
79
42
  }
80
- /**
81
- * Get default provider configurations
82
- *
83
- * Priority order:
84
- * 1. Voyage (code-specialized)
85
- * 2. Ollama (local, free)
86
- * 3. OpenAI (reliable)
87
- * 4. OpenRouter (fallback)
88
- */
89
43
  export function getDefaultConfigs() {
90
44
  return [
91
45
  {
@@ -1,29 +1,3 @@
1
- /**
2
- * Embedding Providers Module
3
- *
4
- * Clean public API following the Dependency Inversion Principle.
5
- * Clients depend on abstractions (IEmbeddingProvider), not implementations.
6
- *
7
- * @example Basic usage
8
- * ```typescript
9
- * import { createProvider } from "./providers";
10
- *
11
- * const provider = createProvider({
12
- * type: "voyage",
13
- * model: "voyage-code-3"
14
- * });
15
- *
16
- * const embeddings = await provider.embed(["hello world"]);
17
- * ```
18
- *
19
- * @example Auto-selection with graceful degradation
20
- * ```typescript
21
- * import { selectBestProvider, getDefaultConfigs } from "./providers";
22
- *
23
- * const provider = await selectBestProvider(getDefaultConfigs());
24
- * // Will try providers in order and fallback to text-only if needed
25
- * ```
26
- */
27
1
  export type { Embedding, ProviderType, HealthCheckResult, ProviderConfig, IEmbeddingProvider } from "./types.js";
28
2
  export { OllamaProvider } from "./ollama.js";
29
3
  export { OpenAIProvider } from "./openai.js";
@@ -1,34 +1,6 @@
1
- /**
2
- * Embedding Providers Module
3
- *
4
- * Clean public API following the Dependency Inversion Principle.
5
- * Clients depend on abstractions (IEmbeddingProvider), not implementations.
6
- *
7
- * @example Basic usage
8
- * ```typescript
9
- * import { createProvider } from "./providers";
10
- *
11
- * const provider = createProvider({
12
- * type: "voyage",
13
- * model: "voyage-code-3"
14
- * });
15
- *
16
- * const embeddings = await provider.embed(["hello world"]);
17
- * ```
18
- *
19
- * @example Auto-selection with graceful degradation
20
- * ```typescript
21
- * import { selectBestProvider, getDefaultConfigs } from "./providers";
22
- *
23
- * const provider = await selectBestProvider(getDefaultConfigs());
24
- * // Will try providers in order and fallback to text-only if needed
25
- * ```
26
- */
27
- // Concrete implementations (export for advanced use cases)
28
1
  export { OllamaProvider } from "./ollama.js";
29
2
  export { OpenAIProvider } from "./openai.js";
30
3
  export { VoyageProvider } from "./voyage.js";
31
4
  export { OpenRouterProvider } from "./openrouter.js";
32
5
  export { TextOnlyProvider } from "./text-only.js";
33
- // Factory functions (recommended API)
34
6
  export { createProvider, selectBestProvider, getDefaultConfigs } from "./factory.js";
@@ -1,9 +1,3 @@
1
- /**
2
- * Ollama Embedding Provider
3
- *
4
- * Local-first embedding using Ollama's API.
5
- * Prioritizes privacy and zero-cost operation.
6
- */
7
1
  import type { Embedding, HealthCheckResult, IEmbeddingProvider, ProviderConfig } from "./types.js";
8
2
  export declare class OllamaProvider implements IEmbeddingProvider {
9
3
  readonly name = "Ollama";
@@ -1,9 +1,3 @@
1
- /**
2
- * Ollama Embedding Provider
3
- *
4
- * Local-first embedding using Ollama's API.
5
- * Prioritizes privacy and zero-cost operation.
6
- */
7
1
  export class OllamaProvider {
8
2
  name = "Ollama";
9
3
  type = "ollama";
@@ -13,7 +7,7 @@ export class OllamaProvider {
13
7
  constructor(config) {
14
8
  this.baseUrl = config.baseUrl || "http://localhost:11434";
15
9
  this.model = config.model || "nomic-embed-text";
16
- this.dimensions = config.dimensions || 768; // nomic-embed-text default
10
+ this.dimensions = config.dimensions || 768;
17
11
  }
18
12
  async healthCheck() {
19
13
  try {
@@ -46,7 +40,6 @@ export class OllamaProvider {
46
40
  }
47
41
  async embed(texts) {
48
42
  const embeddings = [];
49
- // Ollama API processes one text at a time
50
43
  for (const text of texts) {
51
44
  const response = await fetch(`${this.baseUrl}/api/embeddings`, {
52
45
  method: "POST",
@@ -1,9 +1,3 @@
1
- /**
2
- * OpenAI Embedding Provider
3
- *
4
- * Industry-standard embeddings with flexible dimensionality.
5
- * Supports text-embedding-3-small and text-embedding-3-large models.
6
- */
7
1
  import type { Embedding, HealthCheckResult, IEmbeddingProvider, ProviderConfig } from "./types.js";
8
2
  export declare class OpenAIProvider implements IEmbeddingProvider {
9
3
  readonly name = "OpenAI";
@@ -1,9 +1,3 @@
1
- /**
2
- * OpenAI Embedding Provider
3
- *
4
- * Industry-standard embeddings with flexible dimensionality.
5
- * Supports text-embedding-3-small and text-embedding-3-large models.
6
- */
7
1
  const VALID_DIMENSIONS = [256, 512, 1536, 3072];
8
2
  export class OpenAIProvider {
9
3
  name = "OpenAI";
@@ -25,7 +19,7 @@ export class OpenAIProvider {
25
19
  }
26
20
  validateDimensions(dim) {
27
21
  if (!dim)
28
- return 1536; // Default for text-embedding-3-small
22
+ return 1536;
29
23
  if (!VALID_DIMENSIONS.includes(dim)) {
30
24
  throw new Error(`Invalid dimensions ${dim}. Must be one of: ${VALID_DIMENSIONS.join(", ")}`);
31
25
  }
@@ -33,7 +27,6 @@ export class OpenAIProvider {
33
27
  }
34
28
  async healthCheck() {
35
29
  try {
36
- // Lightweight check: list models endpoint
37
30
  const response = await fetch(`${this.baseUrl}/models`, {
38
31
  headers: {
39
32
  "Authorization": `Bearer ${this.apiKey}`,
@@ -1,9 +1,3 @@
1
- /**
2
- * OpenRouter Embedding Provider
3
- *
4
- * Multi-model gateway supporting various embedding providers.
5
- * Requires HTTP-Referer and X-Title headers for API tracking.
6
- */
7
1
  import type { Embedding, HealthCheckResult, IEmbeddingProvider, ProviderConfig } from "./types.js";
8
2
  export declare class OpenRouterProvider implements IEmbeddingProvider {
9
3
  readonly name = "OpenRouter";
@@ -1,9 +1,3 @@
1
- /**
2
- * OpenRouter Embedding Provider
3
- *
4
- * Multi-model gateway supporting various embedding providers.
5
- * Requires HTTP-Referer and X-Title headers for API tracking.
6
- */
7
1
  export class OpenRouterProvider {
8
2
  name = "OpenRouter";
9
3
  type = "openrouter";
@@ -22,13 +16,11 @@ export class OpenRouterProvider {
22
16
  this.model = config.model || "openai/text-embedding-3-small";
23
17
  this.baseUrl = config.baseUrl || "https://openrouter.ai/api/v1";
24
18
  this.dimensions = config.dimensions || 1536;
25
- // OpenRouter requires these headers for tracking
26
19
  this.referer = process.env.OPENROUTER_REFERER || "https://maskweaver.dev";
27
20
  this.title = process.env.OPENROUTER_TITLE || "MaskWeaver";
28
21
  }
29
22
  async healthCheck() {
30
23
  try {
31
- // Check API key validity
32
24
  const response = await fetch(`${this.baseUrl}/auth/key`, {
33
25
  headers: {
34
26
  "Authorization": `Bearer ${this.apiKey}`,
@@ -1,21 +1,8 @@
1
- /**
2
- * Text-Only Provider (Null Object Pattern)
3
- *
4
- * Graceful degradation when no embedding service is available.
5
- * Returns empty vectors, allowing the system to function in text-only mode.
6
- * Vector search is skipped; only FTS keyword matching is used.
7
- *
8
- * Use case: Development, testing, or when embedding APIs are unavailable.
9
- */
10
1
  import type { Embedding, HealthCheckResult, IEmbeddingProvider, ProviderConfig } from "./types.js";
11
2
  export declare class TextOnlyProvider implements IEmbeddingProvider {
12
3
  readonly name = "Text-Only (No Embeddings)";
13
4
  readonly type: "text-only";
14
5
  readonly dimensions: number;
15
- /**
16
- * When true, signals that this provider cannot produce meaningful embeddings.
17
- * Consumers should skip vector search and rely on text/keyword search only.
18
- */
19
6
  readonly isTextOnly = true;
20
7
  constructor(config: ProviderConfig);
21
8
  healthCheck(): Promise<HealthCheckResult>;
@@ -1,35 +1,18 @@
1
- /**
2
- * Text-Only Provider (Null Object Pattern)
3
- *
4
- * Graceful degradation when no embedding service is available.
5
- * Returns empty vectors, allowing the system to function in text-only mode.
6
- * Vector search is skipped; only FTS keyword matching is used.
7
- *
8
- * Use case: Development, testing, or when embedding APIs are unavailable.
9
- */
10
1
  export class TextOnlyProvider {
11
2
  name = "Text-Only (No Embeddings)";
12
3
  type = "text-only";
13
4
  dimensions;
14
- /**
15
- * When true, signals that this provider cannot produce meaningful embeddings.
16
- * Consumers should skip vector search and rely on text/keyword search only.
17
- */
18
5
  isTextOnly = true;
19
6
  constructor(config) {
20
- // dimensions = 0 signals "no real embeddings" — consumers should skip vector ops.
21
- // If an explicit dimension is provided (e.g., for testing), honor it.
22
7
  this.dimensions = config.dimensions ?? 0;
23
8
  }
24
9
  async healthCheck() {
25
- // Always healthy - it's a fallback
26
10
  return {
27
11
  ok: true,
28
12
  hint: "Text-only mode: semantic search will be limited to keyword matching"
29
13
  };
30
14
  }
31
15
  async embed(texts) {
32
- // Return empty vectors — dimension 0 signals "no real embedding"
33
16
  return texts.map(() => []);
34
17
  }
35
18
  async embedQuery(text) {
@@ -1,23 +1,10 @@
1
- /**
2
- * Embedding Provider Types
3
- *
4
- * Clean interface design following Interface Segregation Principle.
5
- * Each provider implements the IEmbeddingProvider contract while maintaining
6
- * flexibility for provider-specific optimizations.
7
- */
8
1
  export type Embedding = number[];
9
2
  export type ProviderType = "ollama" | "openai" | "voyage" | "openrouter" | "text-only";
10
- /**
11
- * Health check result with actionable feedback
12
- */
13
3
  export interface HealthCheckResult {
14
4
  ok: boolean;
15
5
  reason?: string;
16
6
  hint?: string;
17
7
  }
18
- /**
19
- * Provider configuration - immutable after construction
20
- */
21
8
  export interface ProviderConfig {
22
9
  type: ProviderType;
23
10
  apiKey?: string;
@@ -25,38 +12,12 @@ export interface ProviderConfig {
25
12
  baseUrl?: string;
26
13
  dimensions?: number;
27
14
  }
28
- /**
29
- * Core embedding provider interface
30
- *
31
- * Design principle: "Program to an interface, not an implementation"
32
- * This enables Strategy Pattern for swappable embedding backends.
33
- */
34
15
  export interface IEmbeddingProvider {
35
- /** Provider identifier */
36
16
  readonly name: string;
37
- /** Provider type for factory selection */
38
17
  readonly type: ProviderType;
39
- /** Output vector dimensions */
40
18
  readonly dimensions: number;
41
- /**
42
- * Verify provider is ready and reachable
43
- * Should be fast and non-destructive
44
- */
45
19
  healthCheck(): Promise<HealthCheckResult>;
46
- /**
47
- * Generate embeddings for multiple texts
48
- * @param texts - Array of text strings to embed
49
- * @returns Array of embedding vectors
50
- */
51
20
  embed(texts: string[]): Promise<Embedding[]>;
52
- /**
53
- * Optional: Generate code-optimized embeddings
54
- * Some providers (like Voyage) have specialized code models
55
- */
56
21
  embedCode?(texts: string[]): Promise<Embedding[]>;
57
- /**
58
- * Optional: Generate query-optimized embedding
59
- * For asymmetric search (query vs document)
60
- */
61
22
  embedQuery?(text: string): Promise<Embedding>;
62
23
  }
@@ -1,8 +1 @@
1
- /**
2
- * Embedding Provider Types
3
- *
4
- * Clean interface design following Interface Segregation Principle.
5
- * Each provider implements the IEmbeddingProvider contract while maintaining
6
- * flexibility for provider-specific optimizations.
7
- */
8
1
  export {};