bluera-knowledge 0.9.26 → 0.9.31

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 (63) hide show
  1. package/.claude/commands/commit.md +4 -7
  2. package/.claude/hooks/post-edit-check.sh +21 -24
  3. package/.claude/skills/atomic-commits/SKILL.md +6 -0
  4. package/.claude-plugin/plugin.json +1 -1
  5. package/.env.example +4 -0
  6. package/.husky/pre-push +12 -2
  7. package/.versionrc.json +0 -4
  8. package/BUGS-FOUND.md +71 -0
  9. package/CHANGELOG.md +76 -0
  10. package/README.md +55 -20
  11. package/bun.lock +35 -1
  12. package/commands/crawl.md +2 -0
  13. package/dist/{chunk-BICFAWMN.js → chunk-2SJHNRXD.js} +73 -8
  14. package/dist/chunk-2SJHNRXD.js.map +1 -0
  15. package/dist/{chunk-J7J6LXOJ.js → chunk-OGEY66FZ.js} +106 -41
  16. package/dist/chunk-OGEY66FZ.js.map +1 -0
  17. package/dist/{chunk-5QMHZUC4.js → chunk-RWSXP3PQ.js} +482 -106
  18. package/dist/chunk-RWSXP3PQ.js.map +1 -0
  19. package/dist/index.js +73 -28
  20. package/dist/index.js.map +1 -1
  21. package/dist/mcp/server.js +2 -2
  22. package/dist/workers/background-worker-cli.js +2 -2
  23. package/eslint.config.js +1 -1
  24. package/package.json +3 -1
  25. package/src/analysis/ast-parser.test.ts +46 -0
  26. package/src/cli/commands/crawl.test.ts +99 -12
  27. package/src/cli/commands/crawl.ts +76 -24
  28. package/src/cli/commands/store.test.ts +68 -1
  29. package/src/cli/commands/store.ts +9 -3
  30. package/src/crawl/article-converter.ts +36 -1
  31. package/src/crawl/bridge.ts +18 -7
  32. package/src/crawl/intelligent-crawler.ts +45 -4
  33. package/src/db/embeddings.test.ts +16 -0
  34. package/src/db/lance.test.ts +31 -0
  35. package/src/db/lance.ts +8 -0
  36. package/src/logging/index.ts +29 -0
  37. package/src/logging/logger.test.ts +75 -0
  38. package/src/logging/logger.ts +147 -0
  39. package/src/logging/payload.test.ts +152 -0
  40. package/src/logging/payload.ts +121 -0
  41. package/src/mcp/handlers/search.handler.test.ts +28 -9
  42. package/src/mcp/handlers/search.handler.ts +69 -29
  43. package/src/mcp/handlers/store.handler.test.ts +1 -0
  44. package/src/mcp/server.ts +44 -16
  45. package/src/services/chunking.service.ts +23 -0
  46. package/src/services/index.service.test.ts +921 -1
  47. package/src/services/index.service.ts +76 -1
  48. package/src/services/index.ts +20 -2
  49. package/src/services/search.service.test.ts +573 -21
  50. package/src/services/search.service.ts +257 -105
  51. package/src/services/services.test.ts +2 -2
  52. package/src/services/snippet.service.ts +28 -3
  53. package/src/services/store.service.test.ts +28 -0
  54. package/src/services/store.service.ts +4 -0
  55. package/src/services/token.service.test.ts +45 -0
  56. package/src/services/token.service.ts +33 -0
  57. package/src/types/result.test.ts +10 -0
  58. package/tests/integration/cli-consistency.test.ts +1 -4
  59. package/vitest.config.ts +4 -0
  60. package/dist/chunk-5QMHZUC4.js.map +0 -1
  61. package/dist/chunk-BICFAWMN.js.map +0 -1
  62. package/dist/chunk-J7J6LXOJ.js.map +0 -1
  63. package/scripts/readme-version-updater.cjs +0 -18
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Token estimation service using Anthropic's recommended heuristic.
3
+ * For Claude 3+ models, Anthropic recommends ~3.5 characters per token
4
+ * for English text. This varies by language.
5
+ *
6
+ * Note: The official @anthropic-ai/tokenizer package only works for
7
+ * pre-Claude 3 models. For accurate counts on Claude 3+, use the
8
+ * Token Count API. This heuristic is suitable for display purposes.
9
+ */
10
+
11
+ const CHARS_PER_TOKEN = 3.5;
12
+
13
+ /**
14
+ * Estimate token count for a string using character-based heuristic.
15
+ * @param text - The text to estimate tokens for
16
+ * @returns Estimated token count (rounded up)
17
+ */
18
+ export function estimateTokens(text: string): number {
19
+ if (!text) return 0;
20
+ return Math.ceil(text.length / CHARS_PER_TOKEN);
21
+ }
22
+
23
+ /**
24
+ * Format token count for display with appropriate suffix.
25
+ * @param tokens - Token count
26
+ * @returns Formatted string like "~1.2k" or "~847"
27
+ */
28
+ export function formatTokenCount(tokens: number): string {
29
+ if (tokens >= 1000) {
30
+ return `~${(tokens / 1000).toFixed(1)}k`;
31
+ }
32
+ return `~${String(tokens)}`;
33
+ }
@@ -28,6 +28,16 @@ describe('Result type', () => {
28
28
  const result = err(new Error('failed'));
29
29
  expect(() => unwrap(result)).toThrow('failed');
30
30
  });
31
+
32
+ it('throws wrapped error for non-Error error value', () => {
33
+ const result = err('string error message');
34
+ expect(() => unwrap(result)).toThrow('string error message');
35
+ });
36
+
37
+ it('converts non-string error to string', () => {
38
+ const result = err(404);
39
+ expect(() => unwrap(result)).toThrow('404');
40
+ });
31
41
  });
32
42
 
33
43
  describe('unwrapOr', () => {
@@ -231,10 +231,7 @@ describe('CLI Consistency', () => {
231
231
  expect(result.stderr).toMatch(/^Error: Store not found: nonexistent/m);
232
232
  });
233
233
 
234
- it('uses consistent "Error:" prefix for crawl store not found', () => {
235
- const result = runCli('crawl https://example.com nonexistent');
236
- expect(result.stderr).toMatch(/^Error: /m);
237
- });
234
+ // Note: crawl auto-creates stores when not found, so no error test needed
238
235
  });
239
236
 
240
237
  describe('store delete Confirmation', () => {
package/vitest.config.ts CHANGED
@@ -19,6 +19,8 @@ export default defineConfig({
19
19
  'src/crawl/bridge.test.ts',
20
20
  'src/plugin/git-clone.test.ts',
21
21
  'src/services/project-root.service.test.ts',
22
+ 'src/workers/spawn-worker.test.ts',
23
+ 'src/logging/payload.test.ts',
22
24
  ],
23
25
  // Use forks pool for onnxruntime-node compatibility
24
26
  pool: 'forks',
@@ -38,6 +40,8 @@ export default defineConfig({
38
40
  'src/crawl/bridge.test.ts',
39
41
  'src/plugin/git-clone.test.ts',
40
42
  'src/services/project-root.service.test.ts',
43
+ 'src/workers/spawn-worker.test.ts',
44
+ 'src/logging/payload.test.ts',
41
45
  ],
42
46
  // Use forks pool for onnxruntime-node compatibility
43
47
  pool: 'forks',