brain-memory 0.1.0-beta.3 → 0.1.0-beta.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.
- package/CHANGELOG.md +339 -0
- package/README.md +400 -94
- package/SECURITY.md +61 -0
- package/assets/brand/README.md +28 -0
- package/assets/brand/icon-dark.svg +19 -0
- package/assets/brand/icon-light.svg +20 -0
- package/assets/brand/linkedin_cover.png +0 -0
- package/assets/brand/linkedin_cover_light.png +0 -0
- package/assets/brand/mark-dark.svg +19 -0
- package/assets/brand/mark-light.svg +20 -0
- package/assets/brand/png/icon-dark-1024.png +0 -0
- package/assets/brand/png/icon-dark-128.png +0 -0
- package/assets/brand/png/icon-dark-256.png +0 -0
- package/assets/brand/png/icon-dark-512.png +0 -0
- package/assets/brand/png/icon-dark-64.png +0 -0
- package/assets/brand/png/icon-light-1024.png +0 -0
- package/assets/brand/png/icon-light-128.png +0 -0
- package/assets/brand/png/icon-light-256.png +0 -0
- package/assets/brand/png/icon-light-512.png +0 -0
- package/assets/brand/png/icon-light-64.png +0 -0
- package/assets/brand/png/mark-dark-1024.png +0 -0
- package/assets/brand/png/mark-light-1024.png +0 -0
- package/assets/icon.png +0 -0
- package/assets/icon.svg +19 -0
- package/bin/brain.js +111 -0
- package/bin/cloud-sync.js +150 -0
- package/bin/forget.js +122 -0
- package/bin/install.js +229 -254
- package/bin/memorize.js +458 -0
- package/bin/pin.js +44 -0
- package/bin/recall.js +259 -0
- package/bin/reinforce.js +187 -0
- package/bin/session-start.js +298 -0
- package/bin/skill.js +67 -0
- package/bin/unpin.js +38 -0
- package/commands/brain/forget.md +245 -15
- package/commands/brain/memorize.md +76 -144
- package/commands/brain/pin.md +79 -0
- package/commands/brain/remember.md +48 -105
- package/commands/brain/skills.md +60 -0
- package/commands/brain/sleep.md +69 -28
- package/commands/brain/status.md +24 -10
- package/commands/brain/sync.md +386 -0
- package/package.json +22 -8
- package/prompts/antigravity.md +180 -0
- package/prompts/claude.md +124 -20
- package/prompts/openai.md +124 -20
- package/prompts/opencode.md +179 -0
- package/src/cloud-sync.js +534 -0
- package/src/crypto.js +130 -0
- package/src/export-import.js +200 -0
- package/src/git-sync.js +444 -0
- package/src/index-manager.js +219 -18
- package/src/installer.js +444 -0
- package/src/pinning.js +124 -0
- package/src/scorer.js +45 -11
- package/src/skills.js +208 -0
- package/src/tfidf.js +520 -0
- package/commands/brain/consolidate.md +0 -153
- package/commands/brain/explore.md +0 -79
- package/commands/brain/init.md +0 -157
- package/commands/brain/review.md +0 -130
- package/commands/brain/sunshine.md +0 -337
- package/hooks/session-end.md +0 -48
- package/hooks/session-start.md +0 -48
- package/prompts/gemini.md +0 -76
package/src/skills.js
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Brain Memory — Procedural Skills (CoALA Phase 2 + Tier B §10.3)
|
|
3
|
+
*
|
|
4
|
+
* Stores "how to do things" as `_skills/<name>/SKILL.md` folders and serves them
|
|
5
|
+
* via three-level progressive disclosure:
|
|
6
|
+
* L0 — session start advertises only name + description (skills-index.json)
|
|
7
|
+
* L1 — on a matching task, the agent reads the full SKILL.md
|
|
8
|
+
* L2 — referenced resources/ load only at execution
|
|
9
|
+
*
|
|
10
|
+
* Procedural memory strengthens with successful use and weakens on failure
|
|
11
|
+
* (Tier B §10.3), so a bad crystallized skill demotes itself out of the index.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const fs = require('fs');
|
|
15
|
+
const path = require('path');
|
|
16
|
+
|
|
17
|
+
const {
|
|
18
|
+
getBrainDir,
|
|
19
|
+
readSkillsIndex,
|
|
20
|
+
writeSkillsIndex,
|
|
21
|
+
validateBrainPath,
|
|
22
|
+
atomicWriteSync,
|
|
23
|
+
} = require('./index-manager');
|
|
24
|
+
const { setFrontmatterFields } = require('./pinning');
|
|
25
|
+
|
|
26
|
+
const SKILLS_DIR = '_skills';
|
|
27
|
+
const DEFAULT_STRENGTH = 0.6;
|
|
28
|
+
// A skill whose failure rate exceeds this drops below the L0 advertisement cut.
|
|
29
|
+
const DEMOTE_FAIL_RATIO = 0.5;
|
|
30
|
+
|
|
31
|
+
/** Normalize a skill name to a filesystem-safe slug. */
|
|
32
|
+
function slug(name) {
|
|
33
|
+
return String(name || '').toLowerCase().trim().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function skillPath(name) {
|
|
37
|
+
return `${SKILLS_DIR}/${slug(name)}/SKILL.md`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function buildSkillFile(skill) {
|
|
41
|
+
const fm = [
|
|
42
|
+
'---',
|
|
43
|
+
`name: ${slug(skill.name)}`,
|
|
44
|
+
`description: ${JSON.stringify(skill.description || '')}`,
|
|
45
|
+
`triggers: [${(skill.triggers || []).map((t) => JSON.stringify(t)).join(', ')}]`,
|
|
46
|
+
'cognitive_type: procedural',
|
|
47
|
+
`strength: ${skill.strength ?? DEFAULT_STRENGTH}`,
|
|
48
|
+
`last_used: ${skill.last_used ? JSON.stringify(skill.last_used) : 'null'}`,
|
|
49
|
+
`use_count: ${skill.use_count ?? 0}`,
|
|
50
|
+
`fail_count: ${skill.fail_count ?? 0}`,
|
|
51
|
+
'---',
|
|
52
|
+
'',
|
|
53
|
+
].join('\n');
|
|
54
|
+
return fm + (skill.body || '') + '\n';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Is this skill advertised at L0? Demoted skills stay on disk but go quiet. */
|
|
58
|
+
function isAdvertised(s) {
|
|
59
|
+
const uses = s.use_count || 0;
|
|
60
|
+
const fails = s.fail_count || 0;
|
|
61
|
+
return !(uses >= 3 && fails / uses > DEMOTE_FAIL_RATIO);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Create or replace a skill.
|
|
66
|
+
* @param {string} [projectRoot]
|
|
67
|
+
* @param {Object} skill - { name, description, triggers[], body, strength? }
|
|
68
|
+
*/
|
|
69
|
+
function addSkill(projectRoot, skill) {
|
|
70
|
+
const name = slug(skill && skill.name);
|
|
71
|
+
if (!name) return { error: 'Skill name required' };
|
|
72
|
+
|
|
73
|
+
const brainDir = getBrainDir(projectRoot);
|
|
74
|
+
const dir = path.join(brainDir, SKILLS_DIR, name);
|
|
75
|
+
validateBrainPath(dir, brainDir);
|
|
76
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
77
|
+
|
|
78
|
+
const record = {
|
|
79
|
+
name,
|
|
80
|
+
description: skill.description || '',
|
|
81
|
+
triggers: skill.triggers || [],
|
|
82
|
+
strength: skill.strength ?? DEFAULT_STRENGTH,
|
|
83
|
+
use_count: 0,
|
|
84
|
+
fail_count: 0,
|
|
85
|
+
last_used: null,
|
|
86
|
+
};
|
|
87
|
+
atomicWriteSync(path.join(dir, 'SKILL.md'), buildSkillFile({ ...record, body: skill.body }));
|
|
88
|
+
|
|
89
|
+
const idx = readSkillsIndex(projectRoot);
|
|
90
|
+
idx.skills = idx.skills.filter((s) => s.name !== name);
|
|
91
|
+
idx.skills.push({ ...record, path: skillPath(name) });
|
|
92
|
+
writeSkillsIndex(idx, projectRoot);
|
|
93
|
+
|
|
94
|
+
return { name, added: true };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Full advertised index (every stored skill, advertised or demoted). */
|
|
98
|
+
function listSkills(projectRoot) {
|
|
99
|
+
return readSkillsIndex(projectRoot).skills;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** L0 summaries (name + description) for advertised skills only. */
|
|
103
|
+
function advertisedSummaries(projectRoot) {
|
|
104
|
+
return readSkillsIndex(projectRoot).skills
|
|
105
|
+
.filter(isAdvertised)
|
|
106
|
+
.map((s) => ({ name: s.name, description: s.description, triggers: s.triggers || [] }));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** L1: the full SKILL.md body. */
|
|
110
|
+
function showSkill(projectRoot, name) {
|
|
111
|
+
const full = path.join(getBrainDir(projectRoot), skillPath(name));
|
|
112
|
+
try {
|
|
113
|
+
return { name: slug(name), content: fs.readFileSync(full, 'utf-8') };
|
|
114
|
+
} catch (_) {
|
|
115
|
+
return { error: `Skill not found: ${name}` };
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Record a use. Success strengthens; failure weakens and counts toward demotion.
|
|
121
|
+
* @param {Object} [opts] - { failed: boolean }
|
|
122
|
+
*/
|
|
123
|
+
function useSkill(projectRoot, name, opts = {}) {
|
|
124
|
+
const idx = readSkillsIndex(projectRoot);
|
|
125
|
+
const s = idx.skills.find((x) => x.name === slug(name));
|
|
126
|
+
if (!s) return { error: `Skill not found: ${name}` };
|
|
127
|
+
|
|
128
|
+
s.use_count = (s.use_count || 0) + 1;
|
|
129
|
+
if (opts.failed) {
|
|
130
|
+
s.fail_count = (s.fail_count || 0) + 1;
|
|
131
|
+
s.strength = Math.max(0, (s.strength ?? DEFAULT_STRENGTH) - 0.10);
|
|
132
|
+
} else {
|
|
133
|
+
const cur = s.strength ?? DEFAULT_STRENGTH;
|
|
134
|
+
s.strength = Math.min(1.0, cur + 0.05 * (1.0 - cur));
|
|
135
|
+
}
|
|
136
|
+
s.last_used = new Date().toISOString();
|
|
137
|
+
writeSkillsIndex(idx, projectRoot);
|
|
138
|
+
|
|
139
|
+
setFrontmatterFields(getBrainDir(projectRoot), skillPath(name), {
|
|
140
|
+
strength: Math.round(s.strength * 1000) / 1000,
|
|
141
|
+
use_count: s.use_count,
|
|
142
|
+
fail_count: s.fail_count,
|
|
143
|
+
last_used: s.last_used,
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
return {
|
|
147
|
+
name: s.name,
|
|
148
|
+
use_count: s.use_count,
|
|
149
|
+
fail_count: s.fail_count,
|
|
150
|
+
strength: Math.round(s.strength * 1000) / 1000,
|
|
151
|
+
advertised: isAdvertised(s),
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Export a stored skill into the host agent's native skill format so it becomes
|
|
157
|
+
* directly executable (CoALA Phase 4 host bridge). Brain stores/distills; the
|
|
158
|
+
* host executes.
|
|
159
|
+
*
|
|
160
|
+
* @param {string} [projectRoot] - Brain filesystem root
|
|
161
|
+
* @param {string} name - Skill name
|
|
162
|
+
* @param {string} [target='claude'] - 'claude' | 'gemini'
|
|
163
|
+
* @param {string} [destRoot=process.cwd()] - Host project root to write into
|
|
164
|
+
*/
|
|
165
|
+
function exportSkill(projectRoot, name, target = 'claude', destRoot = process.cwd()) {
|
|
166
|
+
const src = showSkill(projectRoot, name);
|
|
167
|
+
if (src.error) return src;
|
|
168
|
+
|
|
169
|
+
const dests = {
|
|
170
|
+
claude: path.join(destRoot, '.claude', 'skills', slug(name)),
|
|
171
|
+
gemini: path.join(destRoot, '.gemini', 'skills', slug(name)),
|
|
172
|
+
};
|
|
173
|
+
const dir = dests[target];
|
|
174
|
+
if (!dir) return { error: `Unknown target: ${target} (use claude|gemini)` };
|
|
175
|
+
|
|
176
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
177
|
+
const outPath = path.join(dir, 'SKILL.md');
|
|
178
|
+
fs.writeFileSync(outPath, src.content);
|
|
179
|
+
return { name: slug(name), target, path: outPath };
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function removeSkill(projectRoot, name) {
|
|
183
|
+
const n = slug(name);
|
|
184
|
+
const dir = path.join(getBrainDir(projectRoot), SKILLS_DIR, n);
|
|
185
|
+
let removedDir = false;
|
|
186
|
+
try { fs.rmSync(dir, { recursive: true, force: true }); removedDir = true; } catch (_) { /* ignore */ }
|
|
187
|
+
|
|
188
|
+
const idx = readSkillsIndex(projectRoot);
|
|
189
|
+
const before = idx.skills.length;
|
|
190
|
+
idx.skills = idx.skills.filter((s) => s.name !== n);
|
|
191
|
+
writeSkillsIndex(idx, projectRoot);
|
|
192
|
+
|
|
193
|
+
return { name: n, removed: removedDir || before !== idx.skills.length };
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
module.exports = {
|
|
197
|
+
slug,
|
|
198
|
+
skillPath,
|
|
199
|
+
isAdvertised,
|
|
200
|
+
addSkill,
|
|
201
|
+
listSkills,
|
|
202
|
+
advertisedSummaries,
|
|
203
|
+
showSkill,
|
|
204
|
+
useSkill,
|
|
205
|
+
removeSkill,
|
|
206
|
+
exportSkill,
|
|
207
|
+
DEMOTE_FAIL_RATIO,
|
|
208
|
+
};
|