claude-mem-lite 4.0.4 → 5.1.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 (64) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +18 -72
  4. package/README.zh-CN.md +24 -74
  5. package/adopt-content.mjs +0 -1
  6. package/cli/common.mjs +0 -17
  7. package/cli.mjs +19 -3
  8. package/commands/mem.md +3 -3
  9. package/commands/update.md +5 -12
  10. package/format-utils.mjs +0 -21
  11. package/haiku-client.mjs +36 -5
  12. package/hash-utils.mjs +21 -0
  13. package/hook-episode.mjs +7 -1
  14. package/hook-optimize.mjs +103 -50
  15. package/hook-shared.mjs +8 -2
  16. package/hook-update.mjs +56 -14
  17. package/hook.mjs +21 -29
  18. package/hooks/hooks.json +0 -10
  19. package/install.mjs +100 -678
  20. package/lib/atomic-write.mjs +16 -0
  21. package/lib/deferred-work.mjs +7 -3
  22. package/lib/doctor-drift.mjs +0 -1
  23. package/lib/frontmatter.mjs +1 -2
  24. package/lib/get-core.mjs +27 -1
  25. package/lib/hook-prune.mjs +133 -0
  26. package/lib/hook-stdin.mjs +1 -1
  27. package/lib/hook-telemetry.mjs +1 -1
  28. package/lib/install-shape.mjs +45 -4
  29. package/lib/maintain-core.mjs +9 -0
  30. package/lib/metrics.mjs +2 -2
  31. package/lib/proc-lock.mjs +111 -13
  32. package/lib/proxy-fetch.mjs +26 -2
  33. package/lib/scrub-record.mjs +8 -0
  34. package/lib/shard-gc.mjs +11 -7
  35. package/lib/tmp-fixture-sweep.mjs +9 -0
  36. package/mem-cli.mjs +46 -434
  37. package/nlp.mjs +1 -1
  38. package/npm-shrinkwrap.json +6 -2
  39. package/package.json +9 -16
  40. package/project-utils.mjs +43 -15
  41. package/schema.mjs +112 -50
  42. package/scripts/hook-launcher.mjs +9 -3
  43. package/scripts/prompt-search-utils.mjs +0 -30
  44. package/scripts/setup.sh +5 -0
  45. package/scripts/user-prompt-search.js +3 -125
  46. package/secret-scrub.mjs +32 -3
  47. package/server.mjs +19 -451
  48. package/source-files.mjs +12 -29
  49. package/synonyms.mjs +2 -1
  50. package/tool-schemas.mjs +23 -91
  51. package/utils.mjs +5 -13
  52. package/commands/tools.md +0 -67
  53. package/install-metadata.mjs +0 -2193
  54. package/lib/registry-core.mjs +0 -264
  55. package/registry/preinstalled.json +0 -2419
  56. package/registry-enricher.mjs +0 -124
  57. package/registry-github.mjs +0 -86
  58. package/registry-importer.mjs +0 -569
  59. package/registry-recommend.mjs +0 -503
  60. package/registry-retriever.mjs +0 -611
  61. package/registry-scanner.mjs +0 -261
  62. package/registry.mjs +0 -665
  63. package/resource-discovery.mjs +0 -199
  64. package/scripts/pre-skill-bridge.js +0 -146
@@ -1,124 +0,0 @@
1
- // claude-mem-lite: LLM enrichment for registry resources (Stage 2)
2
- // Sends resource content to Haiku for semantic metadata generation
3
- // Graceful degradation: failure preserves existing data
4
-
5
- // Async dispatcher: enrichResource is reached from the MCP handlers for
6
- // mem_registry `enrich` and `import_url`, where a blocking CLI leg would freeze
7
- // the server event loop for the whole BG_LLM_TIMEOUT_MS budget (D#138 MEDIUM-3).
8
- import { callHaikuJSONAsync, BG_LLM_TIMEOUT_MS } from './haiku-client.mjs';
9
- import { truncate, debugCatch } from './utils.mjs';
10
-
11
- /**
12
- * Build the enrichment prompt for Haiku.
13
- * @param {string} name Resource name
14
- * @param {string} content SKILL.md/AGENT.md content
15
- * @param {object} existingMeta Existing metadata from DB
16
- * @returns {string} Prompt string
17
- */
18
- export function buildEnrichPrompt(name, content, existingMeta) {
19
- const truncated = truncate(content, 3000);
20
- const existing = existingMeta.intent_tags
21
- ? `\n<existing-metadata>\ncurrent_tags: ${existingMeta.intent_tags}\n</existing-metadata>`
22
- : '';
23
-
24
- return `You are a tool classification expert. Analyze this Claude Code skill and extract structured metadata.
25
-
26
- <skill-name>${name}</skill-name>
27
- <skill-content>
28
- ${truncated}
29
- </skill-content>
30
- ${existing}
31
- Return JSON only:
32
- {"capability_summary":"One sentence (<80 chars)","intent_tags":"comma-separated intents","domain_tags":"comma-separated domains","trigger_patterns":"when to recommend","use_cases":"comma-separated scenarios","tech_stack":"comma-separated tech","quality_assessment":{"has_clear_instructions":true,"has_examples":false,"specificity":"high","estimated_utility":"high"}}`;
33
- }
34
-
35
- /**
36
- * Apply LLM enrichment results to a resource.
37
- * Only fills empty fields — never overwrites existing non-empty data.
38
- * @param {Database} db Registry database
39
- * @param {string} name Resource name
40
- * @param {string} type Resource type
41
- * @param {object} enrichResult LLM result JSON
42
- */
43
- export function applyEnrichment(db, name, type, enrichResult) {
44
- const row = db.prepare('SELECT * FROM resources WHERE name = ? AND type = ?').get(name, type);
45
- if (!row) return;
46
-
47
- const updates = [];
48
- const params = [];
49
-
50
- // Only fill empty fields
51
- const fields = [
52
- 'capability_summary',
53
- 'intent_tags',
54
- 'domain_tags',
55
- 'trigger_patterns',
56
- 'use_cases',
57
- 'tech_stack',
58
- ];
59
- for (const f of fields) {
60
- if ((!row[f] || row[f].trim() === '') && enrichResult[f]) {
61
- updates.push(`${f} = ?`);
62
- params.push(enrichResult[f]);
63
- }
64
- }
65
-
66
- // Always update enrichment status
67
- updates.push("enrichment_status = 'done'");
68
- updates.push('enriched_at = ?');
69
- params.push(Date.now());
70
-
71
- // Quality tier upgrade based on assessment
72
- const qa = enrichResult.quality_assessment;
73
- if (qa && row.quality_tier === 'community') {
74
- if (qa.has_clear_instructions && (qa.specificity === 'high' || qa.specificity === 'medium')) {
75
- updates.push("quality_tier = 'verified'");
76
- }
77
- }
78
-
79
- params.push(name, type);
80
- db.prepare(`UPDATE resources SET ${updates.join(', ')} WHERE name = ? AND type = ?`).run(...params);
81
- }
82
-
83
- /**
84
- * Enrich a single resource via Haiku LLM.
85
- * @param {Database} db Registry database
86
- * @param {string} name Resource name
87
- * @param {string} type Resource type
88
- * @param {string} content SKILL.md/AGENT.md content
89
- * @returns {Promise<boolean>} true if enriched successfully
90
- */
91
- export async function enrichResource(db, name, type, content) {
92
- const existing = db
93
- .prepare('SELECT intent_tags, capability_summary FROM resources WHERE name = ? AND type = ?')
94
- .get(name, type);
95
- if (!existing) return false;
96
-
97
- db.prepare("UPDATE resources SET enrichment_status = 'pending' WHERE name = ? AND type = ?").run(
98
- name,
99
- type,
100
- );
101
-
102
- try {
103
- const prompt = buildEnrichPrompt(name, content, existing);
104
- const result = await callHaikuJSONAsync(prompt, { timeout: BG_LLM_TIMEOUT_MS, maxTokens: 500 });
105
-
106
- if (!result || !result.capability_summary) {
107
- db.prepare("UPDATE resources SET enrichment_status = 'failed' WHERE name = ? AND type = ?").run(
108
- name,
109
- type,
110
- );
111
- return false;
112
- }
113
-
114
- applyEnrichment(db, name, type, result);
115
- return true;
116
- } catch (e) {
117
- debugCatch(e, 'enricher');
118
- db.prepare("UPDATE resources SET enrichment_status = 'failed' WHERE name = ? AND type = ?").run(
119
- name,
120
- type,
121
- );
122
- return false;
123
- }
124
- }
@@ -1,86 +0,0 @@
1
- // claude-mem-lite: GitHub API helpers for smart import
2
- // Pure functions for URL parsing and API URL construction
3
- // Actual HTTP calls are in registry-importer.mjs
4
-
5
- /**
6
- * Parse a GitHub URL into owner, repo, branch, path.
7
- * @param {string} url GitHub URL
8
- * @returns {{ owner: string, repo: string, branch: string, path: string } | null}
9
- */
10
- export function parseGitHubUrl(url) {
11
- if (!url || typeof url !== 'string') return null;
12
- // Drop any query string / fragment (a copy-pasted "?tab=readme" or "#section"
13
- // browser anchor) before matching. Otherwise it leaks into the captured branch
14
- // ("main?x#y") and corrupts the GitHub API URL built from it, so the import
15
- // fails with a confusing 404 on a URL that opens fine in the browser.
16
- const clean = url.split(/[?#]/)[0];
17
- // RFC 3986: scheme + host are case-insensitive, but the path (owner/repo/branch/dir)
18
- // is NOT. Lowercase ONLY the scheme://github.com prefix — and only when github.com is
19
- // the real host (followed by '/' or end, never as a substring of github.com.evil.com)
20
- // — so a pasted "HTTPS://GitHub.com/…" (valid, opens in the browser) isn't rejected as
21
- // "Invalid GitHub URL". The structural host check in the match below is unchanged, so
22
- // github.com.evil.com / github.com@evil.com still fail.
23
- const normalized = clean.replace(/^https?:\/\/github\.com(?=\/|$)/i, (m) => m.toLowerCase());
24
- const match = normalized.match(
25
- /^https?:\/\/github\.com\/([^/]+)\/([^/]+?)(?:\.git)?\/?(?:\/tree\/([^/]+)(\/.*)?)?$/,
26
- );
27
- if (!match) return null;
28
- const [, owner, repo, branch, pathRaw] = match;
29
- return {
30
- owner,
31
- repo,
32
- branch: branch || 'main',
33
- path: pathRaw ? pathRaw.replace(/^\//, '') : '',
34
- };
35
- }
36
-
37
- // Percent-encode ONE path segment. Git ref names may legally contain `#` (git forbids `?`,
38
- // not `#`), and so may file names — interpolated raw, that `#` opens a URL FRAGMENT and
39
- // swallows the rest: `…/git/trees/feat#x?recursive=1` parses as hash `#x?recursive=1` with an
40
- // EMPTY query, so GitHub answered a NON-recursive tree and every nested skills/*/SKILL.md went
41
- // silently undiscovered; the raw content URL lost its whole path the same way (audit
42
- // 2026-09-05 R6 Q2, measured). encodeURIComponent leaves the unreserved set — including the
43
- // `.`, `-`, `_` and `~` that ordinary owners/repos/branches are made of — untouched.
44
- const seg = (s) => encodeURIComponent(String(s ?? ''));
45
-
46
- // A repo-relative file path is MANY segments: encode each one but keep the `/` separators.
47
- // encodeURIComponent on the whole path would emit `skills%2Ffoo%2FSKILL.md` and 404 every
48
- // ordinary import — the counter-case pinned in tests/registry-github.test.mjs.
49
- const segPath = (p) =>
50
- String(p ?? '')
51
- .split('/')
52
- .map(seg)
53
- .join('/');
54
-
55
- /**
56
- * Build GitHub API tree URL (recursive).
57
- */
58
- export function buildTreeUrl(owner, repo, branch) {
59
- return `https://api.github.com/repos/${seg(owner)}/${seg(repo)}/git/trees/${seg(branch)}?recursive=1`;
60
- }
61
-
62
- /**
63
- * Build raw content URL for a file.
64
- */
65
- export function buildContentUrl(owner, repo, branch, path) {
66
- return `https://raw.githubusercontent.com/${seg(owner)}/${seg(repo)}/${seg(branch)}/${segPath(path)}`;
67
- }
68
-
69
- /**
70
- * Build GitHub API repo metadata URL.
71
- */
72
- export function buildRepoUrl(owner, repo) {
73
- return `https://api.github.com/repos/${seg(owner)}/${seg(repo)}`;
74
- }
75
-
76
- /**
77
- * Build headers for GitHub API requests.
78
- * Uses GITHUB_TOKEN env var if available.
79
- * @returns {Record<string, string>}
80
- */
81
- export function buildHeaders() {
82
- const headers = { 'User-Agent': 'claude-mem-lite', Accept: 'application/vnd.github.v3+json' };
83
- const token = process.env.GITHUB_TOKEN;
84
- if (token) headers.Authorization = `token ${token}`;
85
- return headers;
86
- }