@cachly-dev/mcp-server 0.10.65 → 0.10.66

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 (269) hide show
  1. package/dist/src/handlers/brain.js +1 -1
  2. package/dist/src/index.js +1 -1
  3. package/package.json +7 -1
  4. package/server.json +2 -2
  5. package/.env.test.example +0 -23
  6. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -50
  7. package/.github/ISSUE_TEMPLATE/config.yml +0 -8
  8. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -25
  9. package/.github/workflows/eas-build-android.yml +0 -58
  10. package/.github/workflows/eas-update.yml +0 -55
  11. package/.github/workflows/publish.yml +0 -72
  12. package/BENCH.md +0 -113
  13. package/CHANGELOG.md +0 -653
  14. package/Dockerfile +0 -16
  15. package/LAUNCH_TEXTS.md +0 -182
  16. package/PROGRESS.md +0 -141
  17. package/STRATEGY.md +0 -228
  18. package/VISION_10X.md +0 -133
  19. package/apps/travel-chaos-organizer/.env.example +0 -49
  20. package/apps/travel-chaos-organizer/DEPLOY.md +0 -328
  21. package/apps/travel-chaos-organizer/Makefile +0 -57
  22. package/apps/travel-chaos-organizer/README.md +0 -159
  23. package/apps/travel-chaos-organizer/backend/.env.example +0 -10
  24. package/apps/travel-chaos-organizer/backend/Dockerfile +0 -25
  25. package/apps/travel-chaos-organizer/backend/alembic/env.py +0 -56
  26. package/apps/travel-chaos-organizer/backend/alembic/script.py.mako +0 -24
  27. package/apps/travel-chaos-organizer/backend/alembic/versions/.gitkeep +0 -0
  28. package/apps/travel-chaos-organizer/backend/alembic/versions/0001_stripe_customer_id.py +0 -24
  29. package/apps/travel-chaos-organizer/backend/alembic/versions/0002_telegram_chat_id.py +0 -24
  30. package/apps/travel-chaos-organizer/backend/alembic.ini +0 -39
  31. package/apps/travel-chaos-organizer/backend/app/__init__.py +0 -0
  32. package/apps/travel-chaos-organizer/backend/app/auth/__init__.py +0 -0
  33. package/apps/travel-chaos-organizer/backend/app/auth/keycloak.py +0 -81
  34. package/apps/travel-chaos-organizer/backend/app/config.py +0 -66
  35. package/apps/travel-chaos-organizer/backend/app/db/__init__.py +0 -0
  36. package/apps/travel-chaos-organizer/backend/app/db/database.py +0 -20
  37. package/apps/travel-chaos-organizer/backend/app/db/migrations/001_init.sql +0 -71
  38. package/apps/travel-chaos-organizer/backend/app/db/migrations/002_telemetry_freemium.sql +0 -31
  39. package/apps/travel-chaos-organizer/backend/app/db/migrations/003_telegram_chat_id.sql +0 -4
  40. package/apps/travel-chaos-organizer/backend/app/db/migrations/004_stripe_and_email.sql +0 -5
  41. package/apps/travel-chaos-organizer/backend/app/limiter.py +0 -4
  42. package/apps/travel-chaos-organizer/backend/app/logging_config.py +0 -25
  43. package/apps/travel-chaos-organizer/backend/app/main.py +0 -77
  44. package/apps/travel-chaos-organizer/backend/app/models/__init__.py +0 -0
  45. package/apps/travel-chaos-organizer/backend/app/models/schemas.py +0 -142
  46. package/apps/travel-chaos-organizer/backend/app/routers/__init__.py +0 -0
  47. package/apps/travel-chaos-organizer/backend/app/routers/admin.py +0 -237
  48. package/apps/travel-chaos-organizer/backend/app/routers/cache.py +0 -13
  49. package/apps/travel-chaos-organizer/backend/app/routers/events.py +0 -29
  50. package/apps/travel-chaos-organizer/backend/app/routers/export.py +0 -122
  51. package/apps/travel-chaos-organizer/backend/app/routers/inbox.py +0 -122
  52. package/apps/travel-chaos-organizer/backend/app/routers/items.py +0 -130
  53. package/apps/travel-chaos-organizer/backend/app/routers/mail.py +0 -108
  54. package/apps/travel-chaos-organizer/backend/app/routers/parse.py +0 -303
  55. package/apps/travel-chaos-organizer/backend/app/routers/payments.py +0 -179
  56. package/apps/travel-chaos-organizer/backend/app/routers/trips.py +0 -134
  57. package/apps/travel-chaos-organizer/backend/app/routers/users.py +0 -169
  58. package/apps/travel-chaos-organizer/backend/app/routers/waitlist.py +0 -37
  59. package/apps/travel-chaos-organizer/backend/app/services/__init__.py +0 -0
  60. package/apps/travel-chaos-organizer/backend/app/services/cache.py +0 -131
  61. package/apps/travel-chaos-organizer/backend/app/services/drip.py +0 -128
  62. package/apps/travel-chaos-organizer/backend/app/services/email.py +0 -61
  63. package/apps/travel-chaos-organizer/backend/app/services/errors.py +0 -44
  64. package/apps/travel-chaos-organizer/backend/app/services/notifier.py +0 -10
  65. package/apps/travel-chaos-organizer/backend/app/services/ollama.py +0 -101
  66. package/apps/travel-chaos-organizer/backend/app/services/parser.py +0 -22
  67. package/apps/travel-chaos-organizer/backend/app/services/quota.py +0 -85
  68. package/apps/travel-chaos-organizer/backend/app/services/sentry.py +0 -11
  69. package/apps/travel-chaos-organizer/backend/app/services/telemetry.py +0 -35
  70. package/apps/travel-chaos-organizer/backend/pytest.ini +0 -4
  71. package/apps/travel-chaos-organizer/backend/requirements-dev.txt +0 -6
  72. package/apps/travel-chaos-organizer/backend/requirements.txt +0 -25
  73. package/apps/travel-chaos-organizer/backend/tests/__init__.py +0 -0
  74. package/apps/travel-chaos-organizer/backend/tests/conftest.py +0 -223
  75. package/apps/travel-chaos-organizer/backend/tests/test_admin.py +0 -99
  76. package/apps/travel-chaos-organizer/backend/tests/test_cache.py +0 -142
  77. package/apps/travel-chaos-organizer/backend/tests/test_drip.py +0 -32
  78. package/apps/travel-chaos-organizer/backend/tests/test_e2e_chain.py +0 -121
  79. package/apps/travel-chaos-organizer/backend/tests/test_export.py +0 -48
  80. package/apps/travel-chaos-organizer/backend/tests/test_inbox.py +0 -107
  81. package/apps/travel-chaos-organizer/backend/tests/test_items.py +0 -138
  82. package/apps/travel-chaos-organizer/backend/tests/test_mail.py +0 -113
  83. package/apps/travel-chaos-organizer/backend/tests/test_ollama.py +0 -145
  84. package/apps/travel-chaos-organizer/backend/tests/test_parse_url.py +0 -98
  85. package/apps/travel-chaos-organizer/backend/tests/test_parser.py +0 -72
  86. package/apps/travel-chaos-organizer/backend/tests/test_payments.py +0 -163
  87. package/apps/travel-chaos-organizer/backend/tests/test_quota.py +0 -46
  88. package/apps/travel-chaos-organizer/backend/tests/test_search.py +0 -67
  89. package/apps/travel-chaos-organizer/backend/tests/test_trips.py +0 -123
  90. package/apps/travel-chaos-organizer/backend/tests/test_users.py +0 -52
  91. package/apps/travel-chaos-organizer/backups/.gitkeep +0 -0
  92. package/apps/travel-chaos-organizer/caddy/Caddyfile +0 -27
  93. package/apps/travel-chaos-organizer/docker-compose.node1.yml +0 -31
  94. package/apps/travel-chaos-organizer/docker-compose.override.yml +0 -14
  95. package/apps/travel-chaos-organizer/docker-compose.yml +0 -128
  96. package/apps/travel-chaos-organizer/frontend/.env.example +0 -13
  97. package/apps/travel-chaos-organizer/frontend/app/(app)/_layout.tsx +0 -80
  98. package/apps/travel-chaos-organizer/frontend/app/(app)/inbox.tsx +0 -166
  99. package/apps/travel-chaos-organizer/frontend/app/(app)/search.tsx +0 -130
  100. package/apps/travel-chaos-organizer/frontend/app/(app)/settings.tsx +0 -381
  101. package/apps/travel-chaos-organizer/frontend/app/(app)/trips/[id].tsx +0 -346
  102. package/apps/travel-chaos-organizer/frontend/app/(app)/trips.tsx +0 -363
  103. package/apps/travel-chaos-organizer/frontend/app/(app)/upgrade/cancel.tsx +0 -34
  104. package/apps/travel-chaos-organizer/frontend/app/(app)/upgrade/success.tsx +0 -35
  105. package/apps/travel-chaos-organizer/frontend/app/(auth)/login.tsx +0 -91
  106. package/apps/travel-chaos-organizer/frontend/app/_layout.tsx +0 -71
  107. package/apps/travel-chaos-organizer/frontend/app/auth.tsx +0 -29
  108. package/apps/travel-chaos-organizer/frontend/app/index.tsx +0 -16
  109. package/apps/travel-chaos-organizer/frontend/app/onboarding.tsx +0 -119
  110. package/apps/travel-chaos-organizer/frontend/app.config.ts +0 -54
  111. package/apps/travel-chaos-organizer/frontend/assets/adaptive-icon.svg +0 -66
  112. package/apps/travel-chaos-organizer/frontend/assets/icon.svg +0 -79
  113. package/apps/travel-chaos-organizer/frontend/assets/splash.svg +0 -15
  114. package/apps/travel-chaos-organizer/frontend/components/BottomSheet.tsx +0 -102
  115. package/apps/travel-chaos-organizer/frontend/components/ConfettiCannon.tsx +0 -107
  116. package/apps/travel-chaos-organizer/frontend/components/ConfirmDialog.tsx +0 -109
  117. package/apps/travel-chaos-organizer/frontend/components/ErrorBoundary.tsx +0 -45
  118. package/apps/travel-chaos-organizer/frontend/components/FileUploadButton.tsx +0 -19
  119. package/apps/travel-chaos-organizer/frontend/components/ImportSheet.tsx +0 -155
  120. package/apps/travel-chaos-organizer/frontend/components/OfflineBadge.tsx +0 -55
  121. package/apps/travel-chaos-organizer/frontend/components/QRCodeViewer.tsx +0 -80
  122. package/apps/travel-chaos-organizer/frontend/components/ScoreRing.tsx +0 -39
  123. package/apps/travel-chaos-organizer/frontend/components/Screen.tsx +0 -39
  124. package/apps/travel-chaos-organizer/frontend/components/Skeleton.tsx +0 -70
  125. package/apps/travel-chaos-organizer/frontend/components/SwipeableInboxItem.tsx +0 -121
  126. package/apps/travel-chaos-organizer/frontend/components/SwipeableTimelineItem.tsx +0 -70
  127. package/apps/travel-chaos-organizer/frontend/components/TimelineItem.tsx +0 -73
  128. package/apps/travel-chaos-organizer/frontend/components/TimelineItemDetail.tsx +0 -130
  129. package/apps/travel-chaos-organizer/frontend/components/Toast.tsx +0 -60
  130. package/apps/travel-chaos-organizer/frontend/components/ToastContext.tsx +0 -42
  131. package/apps/travel-chaos-organizer/frontend/components/TripCard.tsx +0 -146
  132. package/apps/travel-chaos-organizer/frontend/components/TripQRModal.tsx +0 -70
  133. package/apps/travel-chaos-organizer/frontend/components/UpgradeBanner.tsx +0 -44
  134. package/apps/travel-chaos-organizer/frontend/eas.json +0 -22
  135. package/apps/travel-chaos-organizer/frontend/hooks/useInbox.ts +0 -24
  136. package/apps/travel-chaos-organizer/frontend/hooks/useNetworkSync.ts +0 -60
  137. package/apps/travel-chaos-organizer/frontend/hooks/useTrips.ts +0 -112
  138. package/apps/travel-chaos-organizer/frontend/lib/api.ts +0 -223
  139. package/apps/travel-chaos-organizer/frontend/lib/auth.ts +0 -93
  140. package/apps/travel-chaos-organizer/frontend/lib/db.ts +0 -86
  141. package/apps/travel-chaos-organizer/frontend/lib/fileCache.ts +0 -54
  142. package/apps/travel-chaos-organizer/frontend/lib/haptics.ts +0 -13
  143. package/apps/travel-chaos-organizer/frontend/lib/notifications.ts +0 -112
  144. package/apps/travel-chaos-organizer/frontend/lib/offlineQueue.ts +0 -145
  145. package/apps/travel-chaos-organizer/frontend/lib/quota.tsx +0 -43
  146. package/apps/travel-chaos-organizer/frontend/lib/sentry.ts +0 -28
  147. package/apps/travel-chaos-organizer/frontend/lib/shareIntent.ts +0 -44
  148. package/apps/travel-chaos-organizer/frontend/package-lock.json +0 -13221
  149. package/apps/travel-chaos-organizer/frontend/package.json +0 -44
  150. package/apps/travel-chaos-organizer/frontend/tsconfig.json +0 -23
  151. package/apps/travel-chaos-organizer/keycloak/realm-export.json +0 -59
  152. package/apps/travel-chaos-organizer/landing/index.html +0 -773
  153. package/apps/travel-chaos-organizer/scripts/backup.sh +0 -14
  154. package/apps/travel-chaos-organizer/scripts/configure-env.sh +0 -82
  155. package/apps/travel-chaos-organizer/scripts/deploy.sh +0 -54
  156. package/apps/travel-chaos-organizer/scripts/health-check.sh +0 -36
  157. package/apps/travel-chaos-organizer/scripts/migrate.sh +0 -7
  158. package/apps/travel-chaos-organizer/scripts/server-setup.sh +0 -85
  159. package/apps/travel-chaos-organizer/scripts/smoke-test.sh +0 -29
  160. package/apps/travel-chaos-organizer/scripts/verify-tracking.sh +0 -71
  161. package/apps/travel-chaos-organizer/telegram-bot/.env.example +0 -3
  162. package/apps/travel-chaos-organizer/telegram-bot/Dockerfile +0 -6
  163. package/apps/travel-chaos-organizer/telegram-bot/bot.py +0 -504
  164. package/apps/travel-chaos-organizer/telegram-bot/requirements.txt +0 -3
  165. package/dist/src/__tests__/auth.test.d.ts +0 -1
  166. package/dist/src/__tests__/auth.test.js +0 -107
  167. package/dist/src/__tests__/auth.test.js.map +0 -1
  168. package/dist/src/__tests__/brain-flow.test.d.ts +0 -12
  169. package/dist/src/__tests__/brain-flow.test.js +0 -1241
  170. package/dist/src/__tests__/brain-flow.test.js.map +0 -1
  171. package/dist/src/__tests__/confidence.test.d.ts +0 -13
  172. package/dist/src/__tests__/confidence.test.js +0 -233
  173. package/dist/src/__tests__/confidence.test.js.map +0 -1
  174. package/dist/src/__tests__/e2e/api-auth.test.d.ts +0 -7
  175. package/dist/src/__tests__/e2e/api-auth.test.js +0 -162
  176. package/dist/src/__tests__/e2e/api-auth.test.js.map +0 -1
  177. package/dist/src/__tests__/e2e/api-health.test.d.ts +0 -7
  178. package/dist/src/__tests__/e2e/api-health.test.js +0 -95
  179. package/dist/src/__tests__/e2e/api-health.test.js.map +0 -1
  180. package/dist/src/__tests__/e2e/cli.test.d.ts +0 -10
  181. package/dist/src/__tests__/e2e/cli.test.js +0 -204
  182. package/dist/src/__tests__/e2e/cli.test.js.map +0 -1
  183. package/dist/src/__tests__/e2e/config.d.ts +0 -35
  184. package/dist/src/__tests__/e2e/config.js +0 -53
  185. package/dist/src/__tests__/e2e/config.js.map +0 -1
  186. package/dist/src/__tests__/e2e/funnel.test.d.ts +0 -13
  187. package/dist/src/__tests__/e2e/funnel.test.js +0 -90
  188. package/dist/src/__tests__/e2e/funnel.test.js.map +0 -1
  189. package/dist/src/__tests__/e2e/mcp-tools.test.d.ts +0 -7
  190. package/dist/src/__tests__/e2e/mcp-tools.test.js +0 -129
  191. package/dist/src/__tests__/e2e/mcp-tools.test.js.map +0 -1
  192. package/dist/src/__tests__/e2e/provisioning.test.d.ts +0 -15
  193. package/dist/src/__tests__/e2e/provisioning.test.js +0 -123
  194. package/dist/src/__tests__/e2e/provisioning.test.js.map +0 -1
  195. package/dist/src/__tests__/handlers-unit.test.d.ts +0 -12
  196. package/dist/src/__tests__/handlers-unit.test.js +0 -505
  197. package/dist/src/__tests__/handlers-unit.test.js.map +0 -1
  198. package/dist/src/__tests__/namespace.test.d.ts +0 -1
  199. package/dist/src/__tests__/namespace.test.js +0 -114
  200. package/dist/src/__tests__/namespace.test.js.map +0 -1
  201. package/dist/src/__tests__/rerank.test.d.ts +0 -1
  202. package/dist/src/__tests__/rerank.test.js +0 -125
  203. package/dist/src/__tests__/rerank.test.js.map +0 -1
  204. package/dist/src/__tests__/utils.test.d.ts +0 -1
  205. package/dist/src/__tests__/utils.test.js +0 -83
  206. package/dist/src/__tests__/utils.test.js.map +0 -1
  207. package/dist/src/bench/cachly-bench.d.ts +0 -39
  208. package/dist/src/bench/cachly-bench.js +0 -223
  209. package/dist/src/bench/cachly-bench.js.map +0 -1
  210. package/dist/src/bench/fixtures.d.ts +0 -37
  211. package/dist/src/bench/fixtures.js +0 -225
  212. package/dist/src/bench/fixtures.js.map +0 -1
  213. package/dist/src/search.test.d.ts +0 -1
  214. package/dist/src/search.test.js +0 -713
  215. package/dist/src/search.test.js.map +0 -1
  216. package/eslint.config.js +0 -16
  217. package/glama.json +0 -36
  218. package/llms.txt +0 -155
  219. package/packages/telegram-notify/SPLIT_PLAN.md +0 -106
  220. package/packages/telegram-notify/client.ts +0 -88
  221. package/packages/telegram-notify/emojis.json +0 -22
  222. package/packages/telegram-notify/pyproject.toml +0 -17
  223. package/packages/telegram-notify/telegram_notify/__init__.py +0 -3
  224. package/packages/telegram-notify/telegram_notify/client.py +0 -87
  225. package/packages/telegram-notify/telegram_notify/emojis.json +0 -22
  226. package/scripts/e2e-run.sh +0 -160
  227. package/scripts/generate-icons.js +0 -28
  228. package/smithery.yaml +0 -45
  229. package/src/__tests__/auth.test.ts +0 -147
  230. package/src/__tests__/brain-flow.test.ts +0 -1472
  231. package/src/__tests__/confidence.test.ts +0 -285
  232. package/src/__tests__/e2e/api-auth.test.ts +0 -182
  233. package/src/__tests__/e2e/api-health.test.ts +0 -103
  234. package/src/__tests__/e2e/cli.test.ts +0 -228
  235. package/src/__tests__/e2e/config.ts +0 -53
  236. package/src/__tests__/e2e/funnel.test.ts +0 -99
  237. package/src/__tests__/e2e/mcp-tools.test.ts +0 -191
  238. package/src/__tests__/e2e/provisioning.test.ts +0 -128
  239. package/src/__tests__/handlers-unit.test.ts +0 -677
  240. package/src/__tests__/namespace.test.ts +0 -126
  241. package/src/__tests__/rerank.test.ts +0 -141
  242. package/src/__tests__/utils.test.ts +0 -81
  243. package/src/auth.ts +0 -46
  244. package/src/bench/cachly-bench.ts +0 -263
  245. package/src/bench/fixtures.ts +0 -256
  246. package/src/ckg.ts +0 -103
  247. package/src/confidence.ts +0 -38
  248. package/src/embeddings.ts +0 -217
  249. package/src/handlers/advanced.ts +0 -647
  250. package/src/handlers/brain.ts +0 -2622
  251. package/src/handlers/cache.ts +0 -633
  252. package/src/handlers/context.ts +0 -222
  253. package/src/handlers/fedbrain.ts +0 -1232
  254. package/src/handlers/instances.ts +0 -180
  255. package/src/handlers/roadmap.ts +0 -201
  256. package/src/handlers/syndicate.ts +0 -460
  257. package/src/handlers/tco.ts +0 -345
  258. package/src/handlers/team.ts +0 -1249
  259. package/src/index.ts +0 -2815
  260. package/src/namespace.ts +0 -128
  261. package/src/notifier.ts +0 -5
  262. package/src/rerank.ts +0 -148
  263. package/src/search.test.ts +0 -848
  264. package/src/search.ts +0 -1781
  265. package/src/tools.ts +0 -2056
  266. package/src/utils.ts +0 -90
  267. package/test-features.cjs +0 -23
  268. package/tsconfig.json +0 -16
  269. package/vitest.config.ts +0 -14
@@ -1,460 +0,0 @@
1
- import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js';
2
- import type { Redis } from 'ioredis';
3
- import { calculateConfidence } from '../confidence.js';
4
- import { ckgSlug } from '../ckg.js';
5
- import type { CKGEdge, CKGNode } from '../ckg.js';
6
- import { keywordSearch } from '../search.js';
7
- import { safeJsonParse } from '../utils.js';
8
-
9
- type GetConnection = (instanceId: string) => Promise<Redis>;
10
- type ApiFetch = <T>(path: string, options?: RequestInit) => Promise<T>;
11
-
12
- export const SYNDICATE_TOOL_NAMES = new Set([
13
- 'syndicate', 'syndicate_search', 'syndicate_stats', 'syndicate_trending',
14
- 'brain_search', 'ckg_inspect', 'brain_predict',
15
- ]);
16
-
17
- export async function handleSyndicateTool(
18
- name: string,
19
- args: Record<string, unknown>,
20
- getConnection: GetConnection,
21
- apiFetch: ApiFetch,
22
- ): Promise<string | null> {
23
- switch (name) {
24
- case 'syndicate': {
25
- const { topic, outcome = 'success', what_worked, what_failed = '', severity = 'minor', tags = [], scope = 'public' } = args as {
26
- topic: string; outcome?: string; what_worked: string; what_failed?: string; severity?: string; tags?: string[]; scope?: string;
27
- };
28
-
29
- if (!topic || !what_worked) {
30
- throw new McpError(ErrorCode.InvalidParams, 'topic and what_worked are required');
31
- }
32
-
33
- const body = { topic, outcome, what_worked, what_failed, severity, tags, scope };
34
- const res = await apiFetch<{ id: string; topic: string; outcome: string; message: string; deduped?: boolean }>(
35
- '/api/v1/syndication/contribute',
36
- { method: 'POST', body: JSON.stringify(body) }
37
- );
38
-
39
- const scopeLabel = scope === 'org' ? '🏢 org-private' : '🌐 global commons';
40
- const dedupNote = res.deduped
41
- ? `\n> ♻️ Duplicate detected — trust score incremented for the existing lesson.`
42
- : '';
43
-
44
- return [
45
- `${scope === 'org' ? '🏢' : '🌐'} **Lesson syndicated to the ${scope === 'org' ? 'org Knowledge Commons' : 'global Knowledge Commons'}**${dedupNote}`,
46
- ``,
47
- `**ID:** \`${res.id}\``,
48
- `**Topic:** \`${res.topic}\` · **Outcome:** ${res.outcome} · **Scope:** ${scopeLabel}`,
49
- ``,
50
- scope === 'org'
51
- ? `This lesson is visible only within your organisation. Use \`syndicate_search(scope="org")\` to find it.`
52
- : `Your lesson is now searchable by every AI brain in the network.`,
53
- `When another instance confirms it works, its trust score rises — and so does your contributor reputation.`,
54
- ``,
55
- `**Tip:** Use \`syndicate_search(q="${topic}")\` to see all community lessons on this topic.`,
56
- ].join('\n');
57
- }
58
-
59
- // ── v0.7 Knowledge Syndication: syndicate_search ─────────────────────────
60
- case 'syndicate_search': {
61
- const { q = '', limit = 20, category = '', scope = '' } = args as { q?: string; limit?: number; category?: string; scope?: string };
62
-
63
- const params = new URLSearchParams();
64
- if (q) params.set('q', q);
65
- if (category) params.set('category', category);
66
- if (scope) params.set('scope', scope);
67
- params.set('limit', String(Math.min(Math.max(1, limit), 50)));
68
-
69
- const res = await apiFetch<{ results: Array<{
70
- id: string; topic: string; category: string; outcome: string;
71
- what_worked: string; what_failed: string; severity: string;
72
- confirm_count: number; created_at: string;
73
- }>; count: number; query: string }>(`/api/v1/syndication/search?${params}`);
74
-
75
- if (!res.results || res.results.length === 0) {
76
- return q
77
- ? `No lessons found for "${q}" in the global Knowledge Commons yet.\n\nBe the first to contribute: \`syndicate(topic="...", what_worked="...")\``
78
- : `The global Knowledge Commons is empty. Be the first contributor:\n\`syndicate(topic="deploy:api", what_worked="...")\``;
79
- }
80
-
81
- const outcomeIcon = (o: string) => o === 'success' ? '✅' : o === 'failure' ? '❌' : '⚠️';
82
- const severityLabel = (s: string) => s === 'critical' ? '🔴' : s === 'major' ? '🟡' : '🟢';
83
- const confirmBar = (n: number) => {
84
- const filled = Math.min(10, Math.round(n / 5));
85
- return '█'.repeat(filled) + '░'.repeat(10 - filled) + ` ×${n}`;
86
- };
87
-
88
- const header = [q, category].filter(Boolean).join(' · ');
89
- const lines: string[] = [
90
- `## 🌐 Global Knowledge Commons${header ? ` — ${header}` : ' — Recent'}`,
91
- `*${res.count} lesson${res.count === 1 ? '' : 's'} found*`,
92
- ``,
93
- ];
94
-
95
- for (const lesson of res.results) {
96
- lines.push(
97
- `### ${outcomeIcon(lesson.outcome)} \`${lesson.topic}\` ${severityLabel(lesson.severity)}`,
98
- `**Trust:** ${confirmBar(lesson.confirm_count)}`,
99
- lesson.what_worked ? `**What worked:** ${lesson.what_worked}` : '',
100
- lesson.what_failed ? `**What failed:** ${lesson.what_failed}` : '',
101
- `*Contributed ${new Date(lesson.created_at).toLocaleDateString('de-DE')} · ID: \`${lesson.id}\`*`,
102
- ``,
103
- );
104
- }
105
-
106
- lines.push(
107
- `---`,
108
- `**Confirm** (this helped you): \`syndicate(topic="${res.results[0]?.topic ?? '...'}", what_worked="...")\` → auto-deduped, trust +1`,
109
- `**Contribute your own:** \`syndicate(topic="fix:...", what_worked="...")\``,
110
- `**Filter by category:** \`syndicate_search(category="fix")\``,
111
- );
112
-
113
- return lines.filter(l => l !== '').join('\n');
114
- }
115
-
116
- // ── v0.7 Knowledge Syndication: syndicate_stats ──────────────────────────
117
- case 'syndicate_stats': {
118
- const res = await apiFetch<{
119
- total_lessons: number;
120
- total_confirms: number;
121
- added_last_7_days: number;
122
- top_categories: Array<{ category: string; count: number }>;
123
- most_trusted: Array<{
124
- id: string; topic: string; outcome: string;
125
- what_worked: string; confirm_count: number; created_at: string;
126
- }>;
127
- top_contributors?: Array<{
128
- trust_score: number; lessons_count: number; confirms_received: number;
129
- }>;
130
- }>('/api/v1/syndication/stats');
131
-
132
- const confirmBar = (n: number) => {
133
- const filled = Math.min(10, Math.round(n / 5));
134
- return '█'.repeat(filled) + '░'.repeat(10 - filled) + ` ×${n}`;
135
- };
136
-
137
- const lines: string[] = [
138
- `## 🌐 Global Knowledge Commons — Stats`,
139
- ``,
140
- `| Metric | Value |`,
141
- `|---|---|`,
142
- `| Total lessons | **${res.total_lessons.toLocaleString()}** |`,
143
- `| Total confirms | **${res.total_confirms.toLocaleString()}** |`,
144
- `| Added last 7 days | **${res.added_last_7_days}** |`,
145
- ``,
146
- `### Top Categories`,
147
- ];
148
-
149
- for (const cat of res.top_categories ?? []) {
150
- lines.push(`- \`${cat.category}\` — ${cat.count} lesson${cat.count === 1 ? '' : 's'}`);
151
- }
152
-
153
- lines.push(``, `### Most Trusted Lessons`);
154
-
155
- for (const lesson of res.most_trusted ?? []) {
156
- lines.push(
157
- `**\`${lesson.topic}\`** ${confirmBar(lesson.confirm_count)}`,
158
- `> ${lesson.what_worked.slice(0, 120)}${lesson.what_worked.length > 120 ? '…' : ''}`,
159
- ``,
160
- );
161
- }
162
-
163
- lines.push(
164
- `---`,
165
- `**Contribute:** \`syndicate(topic="...", what_worked="...")\` | **Search:** \`syndicate_search(q="your problem")\``,
166
- );
167
-
168
- // Top contributors (anonymous scores)
169
- if (res.top_contributors?.length) {
170
- lines.push(``, `### 🏅 Top Contributors (anonymous)`);
171
- for (const c of res.top_contributors) {
172
- lines.push(`- Trust **${c.trust_score}** · ${c.lessons_count} lesson${c.lessons_count === 1 ? '' : 's'} · ${c.confirms_received} confirms received`);
173
- }
174
- }
175
-
176
- return lines.join('\n');
177
- }
178
-
179
- // ── v0.8 Knowledge Syndication: syndicate_trending ───────────────────────
180
- case 'syndicate_trending': {
181
- const { limit = 10 } = args as { limit?: number };
182
-
183
- const params = new URLSearchParams({ limit: String(Math.min(Math.max(1, limit), 50)) });
184
- const res = await apiFetch<{ results: Array<{
185
- id: string; topic: string; category: string; outcome: string;
186
- what_worked: string; what_failed: string; severity: string;
187
- confirm_count: number; trend_score: number; created_at: string;
188
- }>; count: number }>(`/api/v1/syndication/trending?${params}`);
189
-
190
- if (!res.results || res.results.length === 0) {
191
- return [
192
- `## 📈 Trending in the Knowledge Commons`,
193
- ``,
194
- `No trending lessons yet (need at least 2 confirms in the last 7 days).`,
195
- ``,
196
- `Contribute and confirm lessons to see them trend: \`syndicate(topic="...", what_worked="...")\``,
197
- ].join('\n');
198
- }
199
-
200
- const outcomeIcon = (o: string) => o === 'success' ? '✅' : o === 'failure' ? '❌' : '⚠️';
201
- const severityLabel = (s: string) => s === 'critical' ? '🔴' : s === 'major' ? '🟡' : '🟢';
202
- const confirmBar = (n: number) => {
203
- const filled = Math.min(10, Math.round(n / 5));
204
- return '█'.repeat(filled) + '░'.repeat(10 - filled) + ` ×${n}`;
205
- };
206
- const trendBar = (score: number) => {
207
- const filled = Math.min(10, Math.round(score * 2));
208
- return '▲'.repeat(filled) + '△'.repeat(10 - filled) + ` ${score.toFixed(2)}/day`;
209
- };
210
-
211
- const lines: string[] = [
212
- `## 📈 Trending in the Knowledge Commons`,
213
- `*Lessons with the fastest confirmation velocity in the last 7 days*`,
214
- ``,
215
- ];
216
-
217
- for (const lesson of res.results) {
218
- lines.push(
219
- `### ${outcomeIcon(lesson.outcome)} \`${lesson.topic}\` ${severityLabel(lesson.severity)}`,
220
- `**Trend:** ${trendBar(lesson.trend_score)} | **Trust:** ${confirmBar(lesson.confirm_count)}`,
221
- lesson.what_worked ? `**What worked:** ${lesson.what_worked.slice(0, 200)}${lesson.what_worked.length > 200 ? '…' : ''}` : '',
222
- `*ID: \`${lesson.id}\` · ${new Date(lesson.created_at).toLocaleDateString('de-DE')}*`,
223
- ``,
224
- );
225
- }
226
-
227
- lines.push(
228
- `---`,
229
- `**Confirm** (if this helped you): \`syndicate(topic="${res.results[0]?.topic ?? '...'}", what_worked="...")\` → auto-deduped, trust +1`,
230
- `**All trending:** \`syndicate_trending(limit=50)\` | **Search:** \`syndicate_search(q="...")\``,
231
- );
232
-
233
- return lines.filter(l => l !== '').join('\n');
234
- }
235
-
236
- // ── Layer 1: brain_search ─────────────────────────────────────────────────
237
- case 'brain_search': {
238
- const { instance_id, query, limit = 15 } = args as { instance_id: string; query: string; limit?: number };
239
- const redis = await getConnection(instance_id);
240
-
241
- // BM25+ over ALL brain key namespaces
242
- const allMatches = await keywordSearch(
243
- redis,
244
- [
245
- 'cachly:lesson:best:*',
246
- 'cachly:ctx:*',
247
- 'cachly:idx:*',
248
- 'cachly:session:last',
249
- 'cachly:session:handoff',
250
- 'cachly:roadmap:*',
251
- 'cachly:ckg:node:*',
252
- ],
253
- query,
254
- limit,
255
- );
256
-
257
- if (allMatches.length === 0) {
258
- return [`🔎 **Brain Search: "${query}"**`, '', `No results found across all brain data.`, '', `💡 Try \`smart_recall\` or check \`list_remembered\`.`].join('\n');
259
- }
260
-
261
- const lines = [`🔎 **Brain Search: "${query}"** — ${allMatches.length} result${allMatches.length !== 1 ? 's' : ''} across all brain data\n`];
262
- for (const m of allMatches.slice(0, limit)) {
263
- const ns = m.key.startsWith('cachly:lesson:') ? '💡 lesson'
264
- : m.key.startsWith('cachly:ctx:') ? '📝 context'
265
- : m.key.startsWith('cachly:idx:') ? '📂 index'
266
- : m.key.startsWith('cachly:session:') ? '🕐 session'
267
- : m.key.startsWith('cachly:roadmap:') ? '🗺️ roadmap'
268
- : m.key.startsWith('cachly:ckg:node:') ? '🕸️ ckg-node'
269
- : '🗄️ data';
270
- const preview = m.content.slice(0, 280).replace(/\n/g, ' ');
271
- lines.push(`**${ns}** \`${m.key.split(':').slice(2).join(':')}\` _(BM25: ${m.score.toFixed(2)})_`);
272
- lines.push(`> ${preview}${m.content.length > 280 ? '…' : ''}\n`);
273
- }
274
- return lines.join('\n');
275
- }
276
-
277
- // ── Layer 1: ckg_inspect ─────────────────────────────────────────────────
278
- case 'ckg_inspect': {
279
- const { instance_id, concept, max_hops = 2 } = args as { instance_id: string; concept: string; max_hops?: number };
280
- const redis = await getConnection(instance_id);
281
-
282
- const conceptId = ckgSlug(concept);
283
- const visited = new Set<string>();
284
- const allEdges: CKGEdge[] = [];
285
-
286
- // BFS traversal of CKG
287
- const queue: Array<{ id: string; hop: number }> = [{ id: conceptId, hop: 0 }];
288
- while (queue.length > 0) {
289
- const { id, hop } = queue.shift()!;
290
- if (visited.has(id) || hop > max_hops) continue;
291
- visited.add(id);
292
-
293
- const fromKeys = await redis.smembers(`cachly:ckg:idx:from:${id}`);
294
- const toKeys = await redis.smembers(`cachly:ckg:idx:to:${id}`);
295
-
296
- for (const ek of [...fromKeys, ...toKeys].slice(0, 50)) {
297
- const raw = await redis.get(ek);
298
- if (!raw) continue;
299
- const edge = safeJsonParse<CKGEdge | null>(raw, null);
300
- if (!edge) continue;
301
- allEdges.push(edge);
302
- if (hop < max_hops) {
303
- if (!visited.has(edge.from)) queue.push({ id: edge.from, hop: hop + 1 });
304
- if (!visited.has(edge.to)) queue.push({ id: edge.to, hop: hop + 1 });
305
- }
306
- }
307
- }
308
-
309
- if (allEdges.length === 0) {
310
- // Try fuzzy: scan for nodes matching the concept as substring
311
- const nodeKeys: string[] = [];
312
- const nStream = redis.scanStream({ match: `cachly:ckg:node:*${conceptId}*`, count: 100 });
313
- await new Promise<void>((res, rej) => { nStream.on('data', (b: string[]) => nodeKeys.push(...b)); nStream.on('end', res); nStream.on('error', rej); });
314
- if (nodeKeys.length === 0) {
315
- return [`🕸️ **CKG Inspect: "${concept}"**`, '', `No CKG nodes found. The graph builds automatically as you call \`learn_from_attempts\`.`, '', `💡 Once you have lessons stored, CKG edges will appear here.`].join('\n');
316
- }
317
- const nodeList = nodeKeys.slice(0, 10).map(k => ` • \`${k.replace('cachly:ckg:node:', '')}\``).join('\n');
318
- return [`🕸️ **CKG Inspect: "${concept}"**`, '', `No edges found for \`${conceptId}\`, but found similar nodes:`, nodeList, '', `Try: \`ckg_inspect(concept="<exact-node-id>")\``].join('\n');
319
- }
320
-
321
- // Sort by confidence desc, deduplicate
322
- const edgeSeen = new Set<string>();
323
- const unique = allEdges.filter(e => {
324
- const k = `${e.from}:${e.edgeType}:${e.to}`;
325
- if (edgeSeen.has(k)) return false;
326
- edgeSeen.add(k);
327
- return true;
328
- }).sort((a, b) => b.confidence - a.confidence);
329
-
330
- const EDGE_ICON: Record<string, string> = { fixes: '🔧', requires: '🔗', 'co-occurs': '🔄', causes: '⚡', contradicts: '⚠️', degrades_under: '📉' };
331
-
332
- const lines = [`🕸️ **CKG Inspect: "${concept}"** (${unique.length} edge${unique.length !== 1 ? 's' : ''}, ${visited.size} node${visited.size !== 1 ? 's' : ''} traversed)\n`];
333
-
334
- // Group by edge type
335
- const byType = new Map<string, CKGEdge[]>();
336
- for (const e of unique) {
337
- if (!byType.has(e.edgeType)) byType.set(e.edgeType, []);
338
- byType.get(e.edgeType)!.push(e);
339
- }
340
- for (const [eType, edges] of byType) {
341
- const icon = EDGE_ICON[eType] ?? '→';
342
- lines.push(`**${icon} ${eType}** (${edges.length})`);
343
- for (const e of edges.slice(0, 8)) {
344
- const confPct = Math.round(e.confidence * 100);
345
- const bar = '▓'.repeat(Math.round(confPct / 10)) + '░'.repeat(10 - Math.round(confPct / 10));
346
- lines.push(` \`${e.from}\` → \`${e.to}\` ${bar} ${confPct}% (${e.successes.toFixed(1)}/${e.trials} trials)`);
347
- }
348
- lines.push('');
349
- }
350
-
351
- lines.push(`💡 Expand: \`ckg_inspect(concept="${concept}", max_hops=3)\` | Predict: \`brain_predict(context="${concept}")\``);
352
- return lines.join('\n');
353
- }
354
-
355
- // ── Layer 4: brain_predict (PPE) ─────────────────────────────────────────
356
- case 'brain_predict': {
357
- const { instance_id, context: ctx, top_k = 5 } = args as { instance_id: string; context: string; top_k?: number };
358
- const redis = await getConnection(instance_id);
359
-
360
- const ctxTokens = ctx.toLowerCase().replace(/[^a-z0-9\s\-_:]/g, ' ').split(/\s+/).filter(t => t.length > 2);
361
-
362
- // Step 1: Find CKG nodes matching context tokens
363
- type Prediction = { concept: string; edgeType: string; target: string; confidence: number; lesson?: { what_worked?: string; topic: string } };
364
- const predictions: Prediction[] = [];
365
-
366
- for (const token of ctxTokens.slice(0, 6)) {
367
- const nodeKeys: string[] = [];
368
- const nStream = redis.scanStream({ match: `cachly:ckg:node:*${token}*`, count: 50 });
369
- await new Promise<void>((res, rej) => { nStream.on('data', (b: string[]) => nodeKeys.push(...b)); nStream.on('end', res); nStream.on('error', rej); });
370
-
371
- for (const nk of nodeKeys.slice(0, 5)) {
372
- const nodeRaw = await redis.get(nk);
373
- if (!nodeRaw) continue;
374
- const node = safeJsonParse<CKGNode | null>(nodeRaw, null);
375
- if (!node) continue;
376
- const edgeKeys = await redis.smembers(`cachly:ckg:idx:from:${node.id}`);
377
- for (const ek of edgeKeys.slice(0, 20)) {
378
- const edgeRaw = await redis.get(ek);
379
- if (!edgeRaw) continue;
380
- const edge = safeJsonParse<CKGEdge | null>(edgeRaw, null);
381
- if (!edge) continue;
382
- // Only interested in fixes and co-occurs for prediction
383
- if (edge.edgeType !== 'fixes' && edge.edgeType !== 'co-occurs' && edge.edgeType !== 'causes') continue;
384
- const lessonRaw = await redis.get(`cachly:lesson:best:${edge.from}`);
385
- const lesson = lessonRaw ? safeJsonParse<{ what_worked?: string; topic: string } | null>(lessonRaw, null) ?? undefined : undefined;
386
- predictions.push({ concept: node.id, edgeType: edge.edgeType, target: edge.to, confidence: edge.confidence, lesson });
387
- }
388
- }
389
- }
390
-
391
- // Step 2: Text-based fallback — scan lessons for matching topics
392
- const textPredictions: Array<{ topic: string; what_worked?: string; what_failed?: string; outcome: string; severity?: string; confidence: number }> = [];
393
- const lessonKeys: string[] = [];
394
- const lStream = redis.scanStream({ match: 'cachly:lesson:best:*', count: 200 });
395
- await new Promise<void>((res, rej) => { lStream.on('data', (b: string[]) => lessonKeys.push(...b)); lStream.on('end', res); lStream.on('error', rej); });
396
- for (const k of lessonKeys) {
397
- const raw = await redis.get(k);
398
- if (!raw) continue;
399
- {
400
- type PredLesson = { topic: string; what_worked?: string; what_failed?: string; outcome: string; severity?: string; ts: string; verified_at?: string; recall_count?: number };
401
- const l = safeJsonParse<PredLesson | null>(raw, null);
402
- if (!l) continue;
403
- const haystack = [l.topic, l.what_failed ?? '', l.what_worked ?? ''].join(' ').toLowerCase();
404
- const score = ctxTokens.reduce((s, t) => s + (haystack.includes(t) ? 1 : 0), 0);
405
- if (score >= 1 && l.outcome !== 'failure') {
406
- const conf = calculateConfidence(l);
407
- textPredictions.push({ ...l, confidence: conf });
408
- }
409
- }
410
- }
411
- textPredictions.sort((a, b) => b.confidence - a.confidence);
412
-
413
- if (predictions.length === 0 && textPredictions.length === 0) {
414
- return [
415
- `🔮 **Brain Predict: "${ctx}"**`,
416
- ``,
417
- `No predictions yet — the brain hasn't seen this domain.`,
418
- ``,
419
- `💡 As you solve problems in this area and call \`learn_from_attempts\`, the CKG builds up and predictions become available.`,
420
- ].join('\n');
421
- }
422
-
423
- const lines = [`🔮 **Brain Predict: "${ctx}"**\n`];
424
-
425
- // CKG-based predictions
426
- if (predictions.length > 0) {
427
- const pSeen = new Set<string>();
428
- const pUniq = predictions.filter(p => { const k = `${p.concept}:${p.edgeType}:${p.target}`; if (pSeen.has(k)) return false; pSeen.add(k); return true; })
429
- .sort((a, b) => b.confidence - a.confidence).slice(0, top_k);
430
-
431
- lines.push(`### 🕸️ CKG Predictions (based on ${pUniq.length} known edges)`);
432
- for (const p of pUniq) {
433
- const confPct = Math.round(p.confidence * 100);
434
- const icon = p.edgeType === 'fixes' ? '🔧' : p.edgeType === 'co-occurs' ? '🔄' : '⚡';
435
- lines.push(`${icon} **${confPct}%** \`${p.concept}\` _${p.edgeType}_ \`${p.target}\``);
436
- if (p.lesson?.what_worked) lines.push(` ✅ ${p.lesson.what_worked.slice(0, 120)}`);
437
- }
438
- lines.push('');
439
- }
440
-
441
- // Text-based lesson predictions
442
- if (textPredictions.length > 0) {
443
- lines.push(`### 📚 Relevant Lessons (${Math.min(textPredictions.length, top_k)} pre-loaded)`);
444
- for (const l of textPredictions.slice(0, top_k)) {
445
- const confPct = Math.round(l.confidence * 100);
446
- lines.push(` ✅ **${confPct}%** \`${l.topic}\` — ${(l.what_worked ?? '').slice(0, 120)}`);
447
- }
448
- lines.push('');
449
- }
450
-
451
- lines.push(`💡 Outcome confirmed? \`learn_from_attempts(topic="fix:...", outcome="success", ...)\` → improves future predictions`);
452
- return lines.join('\n');
453
- }
454
-
455
- // ── Layer 3: MADC ─────────────────────────────────────────────────────────
456
-
457
- default:
458
- return null;
459
- }
460
- }