opencastle 1.9.0 → 1.10.1
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/README.md +28 -14
- package/bin/cli.mjs +2 -2
- package/dist/cli/adapters/claude-code.d.ts +7 -2
- package/dist/cli/adapters/claude-code.d.ts.map +1 -1
- package/dist/cli/adapters/claude-code.js +13 -2
- package/dist/cli/adapters/claude-code.js.map +1 -1
- package/dist/cli/adapters/rules-dir-base.d.ts.map +1 -1
- package/dist/cli/adapters/rules-dir-base.js +12 -2
- package/dist/cli/adapters/rules-dir-base.js.map +1 -1
- package/dist/cli/adapters/rules-dir-base.test.js +3 -1
- package/dist/cli/adapters/rules-dir-base.test.js.map +1 -1
- package/dist/cli/adapters/vscode.d.ts.map +1 -1
- package/dist/cli/adapters/vscode.js +12 -2
- package/dist/cli/adapters/vscode.js.map +1 -1
- package/dist/cli/ci.d.ts +8 -0
- package/dist/cli/ci.d.ts.map +1 -1
- package/dist/cli/ci.js +24 -17
- package/dist/cli/ci.js.map +1 -1
- package/dist/cli/convoy/findings.js +3 -2
- package/dist/cli/convoy/findings.js.map +1 -1
- package/dist/cli/docs-accuracy.test.js +4 -4
- package/dist/cli/docs-accuracy.test.js.map +1 -1
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +9 -0
- package/dist/cli/init.js.map +1 -1
- package/dist/cli/lesson.js +3 -2
- package/dist/cli/lesson.js.map +1 -1
- package/dist/cli/lessons-rules.d.ts +45 -0
- package/dist/cli/lessons-rules.d.ts.map +1 -0
- package/dist/cli/lessons-rules.js +130 -0
- package/dist/cli/lessons-rules.js.map +1 -0
- package/dist/cli/lessons-rules.test.d.ts +2 -0
- package/dist/cli/lessons-rules.test.d.ts.map +1 -0
- package/dist/cli/lessons-rules.test.js +65 -0
- package/dist/cli/lessons-rules.test.js.map +1 -0
- package/dist/cli/memory-hooks.d.ts +51 -0
- package/dist/cli/memory-hooks.d.ts.map +1 -0
- package/dist/cli/memory-hooks.js +200 -0
- package/dist/cli/memory-hooks.js.map +1 -0
- package/dist/cli/memory-hooks.test.d.ts +2 -0
- package/dist/cli/memory-hooks.test.d.ts.map +1 -0
- package/dist/cli/memory-hooks.test.js +83 -0
- package/dist/cli/memory-hooks.test.js.map +1 -0
- package/dist/cli/memory-sources.d.ts.map +1 -1
- package/dist/cli/memory-sources.js +3 -2
- package/dist/cli/memory-sources.js.map +1 -1
- package/dist/cli/promote-command.test.js +40 -10
- package/dist/cli/promote-command.test.js.map +1 -1
- package/dist/cli/promote.d.ts.map +1 -1
- package/dist/cli/promote.js +41 -11
- package/dist/cli/promote.js.map +1 -1
- package/dist/cli/remove.d.ts.map +1 -1
- package/dist/cli/remove.js +27 -0
- package/dist/cli/remove.js.map +1 -1
- package/dist/cli/status.d.ts +0 -5
- package/dist/cli/status.d.ts.map +1 -1
- package/dist/cli/status.js +2 -24
- package/dist/cli/status.js.map +1 -1
- package/dist/cli/sync-check.d.ts +1 -1
- package/dist/cli/sync-check.d.ts.map +1 -1
- package/dist/cli/sync-check.js +27 -2
- package/dist/cli/sync-check.js.map +1 -1
- package/dist/cli/update.d.ts.map +1 -1
- package/dist/cli/update.js +17 -0
- package/dist/cli/update.js.map +1 -1
- package/package.json +2 -2
- package/src/cli/adapters/claude-code.ts +15 -2
- package/src/cli/adapters/rules-dir-base.test.ts +3 -1
- package/src/cli/adapters/rules-dir-base.ts +11 -2
- package/src/cli/adapters/vscode.ts +11 -2
- package/src/cli/ci.ts +23 -16
- package/src/cli/convoy/findings.ts +2 -2
- package/src/cli/docs-accuracy.test.ts +4 -4
- package/src/cli/init.ts +10 -0
- package/src/cli/lesson.ts +2 -2
- package/src/cli/lessons-rules.test.ts +71 -0
- package/src/cli/lessons-rules.ts +128 -0
- package/src/cli/memory-hooks.test.ts +102 -0
- package/src/cli/memory-hooks.ts +207 -0
- package/src/cli/memory-sources.ts +3 -2
- package/src/cli/promote-command.test.ts +43 -10
- package/src/cli/promote.ts +37 -11
- package/src/cli/remove.ts +22 -0
- package/src/cli/status.ts +2 -28
- package/src/cli/sync-check.ts +30 -3
- package/src/cli/update.ts +17 -0
- package/src/orchestrator/instructions/general.instructions.md +1 -1
- package/src/orchestrator/prompts/implement-feature.prompt.md +1 -1
- package/src/orchestrator/skills/self-improvement/SKILL.md +14 -13
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
2
|
+
import { dirname, join } from 'node:path'
|
|
3
|
+
import { opencastleRunner } from './ci.js'
|
|
4
|
+
import { cliVersionOf } from './layers.js'
|
|
5
|
+
import { writeLessonRules } from './lessons-rules.js'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The team's memory, shared by the assistant's own hook.
|
|
9
|
+
*
|
|
10
|
+
* Every earlier way to share what agents learn asked an agent, or a person, to
|
|
11
|
+
* do something extra: write a lesson when a retry worked, log a session, run a
|
|
12
|
+
* command later and pick memories. The record shows how that went — 25 lessons
|
|
13
|
+
* in 794 pull requests on the one project that used them, against 72 memories
|
|
14
|
+
* Claude Code wrote by itself on the same project, nearly all about the
|
|
15
|
+
* project and none about the person.
|
|
16
|
+
*
|
|
17
|
+
* So agents keep writing their own memory, which they already do reliably, and
|
|
18
|
+
* the assistant runs `promote memory` when an agent stops: Claude Code on
|
|
19
|
+
* SessionEnd, from the project's `.claude/settings.json`; VS Code on Stop,
|
|
20
|
+
* from `.github/hooks/opencastle.json`. It copies what is about the project
|
|
21
|
+
* into lessons and leaves what is about the person, and the lessons go into
|
|
22
|
+
* the pull request with the work, where the team reviews them.
|
|
23
|
+
*
|
|
24
|
+
* Both files are the project's, committed, so every teammate's assistant runs
|
|
25
|
+
* the hook once they trust the folder. The settings file is the user's too:
|
|
26
|
+
* only OpenCastle's own entry is ever added, replaced or removed.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
export const CLAUDE_SETTINGS = '.claude/settings.json'
|
|
30
|
+
export const VSCODE_HOOK_FILE = '.github/hooks/opencastle.json'
|
|
31
|
+
|
|
32
|
+
/** Recognises OpenCastle's entry whatever runner or version it was written with. */
|
|
33
|
+
const OURS = /\bopencastle(?:@\S+)?\s+promote\s+memory\b/
|
|
34
|
+
|
|
35
|
+
/** The command the hook runs. `--json` keeps it quiet and always exits 0. */
|
|
36
|
+
export function memoryHookCommand(projectRoot: string, cliVersion: string): string {
|
|
37
|
+
return `${opencastleRunner(projectRoot, cliVersion)} promote memory --json`
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
type Json = Record<string, unknown>
|
|
41
|
+
|
|
42
|
+
function hookEntry(command: string): Json {
|
|
43
|
+
return { type: 'command', command, timeout: 30 }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function isOurs(entry: unknown): boolean {
|
|
47
|
+
return Boolean(entry && typeof entry === 'object' && typeof (entry as Json).command === 'string' && OURS.test((entry as Json).command as string))
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Settings with OpenCastle's SessionEnd entry taken out, and nothing else changed. */
|
|
51
|
+
function withoutOurs(settings: Json): Json {
|
|
52
|
+
const hooks = settings.hooks && typeof settings.hooks === 'object' ? { ...(settings.hooks as Json) } : null
|
|
53
|
+
if (!hooks || !Array.isArray(hooks.SessionEnd)) return settings
|
|
54
|
+
const groups = (hooks.SessionEnd as unknown[])
|
|
55
|
+
.map((g) => {
|
|
56
|
+
if (!g || typeof g !== 'object' || !Array.isArray((g as Json).hooks)) return g
|
|
57
|
+
const kept = ((g as Json).hooks as unknown[]).filter((h) => !isOurs(h))
|
|
58
|
+
return kept.length === 0 ? null : { ...(g as Json), hooks: kept }
|
|
59
|
+
})
|
|
60
|
+
.filter((g) => g !== null)
|
|
61
|
+
if (groups.length > 0) hooks.SessionEnd = groups
|
|
62
|
+
else delete hooks.SessionEnd
|
|
63
|
+
const out = { ...settings }
|
|
64
|
+
if (Object.keys(hooks).length > 0) out.hooks = hooks
|
|
65
|
+
else delete out.hooks
|
|
66
|
+
return out
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function readJson(abs: string): Json | null | 'unreadable' {
|
|
70
|
+
if (!existsSync(abs)) return null
|
|
71
|
+
try {
|
|
72
|
+
const value = JSON.parse(readFileSync(abs, 'utf8')) as unknown
|
|
73
|
+
return value && typeof value === 'object' && !Array.isArray(value) ? (value as Json) : 'unreadable'
|
|
74
|
+
} catch {
|
|
75
|
+
return 'unreadable'
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function expectedClaudeSettings(current: Json | null, command: string): Json {
|
|
80
|
+
const base = withoutOurs(current ?? {})
|
|
81
|
+
const hooks = base.hooks && typeof base.hooks === 'object' ? { ...(base.hooks as Json) } : {}
|
|
82
|
+
const groups = Array.isArray(hooks.SessionEnd) ? [...(hooks.SessionEnd as unknown[])] : []
|
|
83
|
+
hooks.SessionEnd = [...groups, { hooks: [hookEntry(command)] }]
|
|
84
|
+
return { ...base, hooks }
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function hasOurEntry(settings: Json, command: string): boolean {
|
|
88
|
+
const groups = (settings.hooks as Json | undefined)?.SessionEnd
|
|
89
|
+
if (!Array.isArray(groups)) return false
|
|
90
|
+
const want = JSON.stringify(hookEntry(command))
|
|
91
|
+
return groups.some((g) => Array.isArray((g as Json)?.hooks) && ((g as Json).hooks as unknown[]).some((h) => JSON.stringify(h) === want))
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function vscodeHookText(command: string): string {
|
|
95
|
+
return `${JSON.stringify({ hooks: { Stop: [hookEntry(command)] } }, null, 2)}\n`
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface HookWrite {
|
|
99
|
+
path: string
|
|
100
|
+
outcome: 'created' | 'updated' | 'unchanged' | 'unreadable'
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Add or update OpenCastle's hook for each assistant that has one. */
|
|
104
|
+
export function writeMemoryHooks(projectRoot: string, ides: readonly string[], cliVersion: string): HookWrite[] {
|
|
105
|
+
const command = memoryHookCommand(projectRoot, cliVersion)
|
|
106
|
+
const out: HookWrite[] = []
|
|
107
|
+
if (ides.includes('claude-code')) {
|
|
108
|
+
const abs = join(projectRoot, CLAUDE_SETTINGS)
|
|
109
|
+
const current = readJson(abs)
|
|
110
|
+
if (current === 'unreadable') out.push({ path: CLAUDE_SETTINGS, outcome: 'unreadable' })
|
|
111
|
+
else if (current && hasOurEntry(current, command)) out.push({ path: CLAUDE_SETTINGS, outcome: 'unchanged' })
|
|
112
|
+
else {
|
|
113
|
+
mkdirSync(dirname(abs), { recursive: true })
|
|
114
|
+
writeFileSync(abs, `${JSON.stringify(expectedClaudeSettings(current, command), null, 2)}\n`)
|
|
115
|
+
out.push({ path: CLAUDE_SETTINGS, outcome: current ? 'updated' : 'created' })
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (ides.includes('vscode')) {
|
|
119
|
+
const abs = join(projectRoot, VSCODE_HOOK_FILE)
|
|
120
|
+
const text = vscodeHookText(command)
|
|
121
|
+
let current: string | null = null
|
|
122
|
+
try {
|
|
123
|
+
current = readFileSync(abs, 'utf8')
|
|
124
|
+
} catch {
|
|
125
|
+
current = null
|
|
126
|
+
}
|
|
127
|
+
if (current === text) out.push({ path: VSCODE_HOOK_FILE, outcome: 'unchanged' })
|
|
128
|
+
else {
|
|
129
|
+
mkdirSync(dirname(abs), { recursive: true })
|
|
130
|
+
writeFileSync(abs, text)
|
|
131
|
+
out.push({ path: VSCODE_HOOK_FILE, outcome: current === null ? 'created' : 'updated' })
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return out
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Hooks that are missing or no longer run the command this release writes. */
|
|
138
|
+
export function memoryHooksDrift(
|
|
139
|
+
projectRoot: string,
|
|
140
|
+
ides: readonly string[],
|
|
141
|
+
cliVersion: string,
|
|
142
|
+
): Array<{ ide: string; path: string; detail: string; unreadable?: boolean }> {
|
|
143
|
+
const command = memoryHookCommand(projectRoot, cliVersion)
|
|
144
|
+
const out: Array<{ ide: string; path: string; detail: string; unreadable?: boolean }> = []
|
|
145
|
+
if (ides.includes('claude-code')) {
|
|
146
|
+
const current = readJson(join(projectRoot, CLAUDE_SETTINGS))
|
|
147
|
+
if (current === 'unreadable') {
|
|
148
|
+
out.push({ ide: 'claude-code', path: CLAUDE_SETTINGS, detail: 'is not valid JSON, so the memory hook cannot be checked', unreadable: true })
|
|
149
|
+
} else if (!current || !hasOurEntry(current, command)) {
|
|
150
|
+
out.push({ ide: 'claude-code', path: CLAUDE_SETTINGS, detail: `has no SessionEnd hook running ${command}` })
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (ides.includes('vscode')) {
|
|
154
|
+
let current: string | null = null
|
|
155
|
+
try {
|
|
156
|
+
current = readFileSync(join(projectRoot, VSCODE_HOOK_FILE), 'utf8')
|
|
157
|
+
} catch {
|
|
158
|
+
current = null
|
|
159
|
+
}
|
|
160
|
+
if (current !== vscodeHookText(command)) {
|
|
161
|
+
out.push({ ide: 'vscode', path: VSCODE_HOOK_FILE, detail: current === null ? 'the memory hook is missing' : `no longer runs ${command}` })
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return out
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* What every compile of an assistant ends with, so a project is never
|
|
169
|
+
* compiled without it: the lessons it loads and, for Claude Code and VS Code,
|
|
170
|
+
* the hook that shares what its agents remember. Run by each adapter, so
|
|
171
|
+
* `init`, `sync` and anything else that compiles a target agree with
|
|
172
|
+
* `sync --check` by construction.
|
|
173
|
+
*/
|
|
174
|
+
export function compileTeamMemory(pkgRoot: string, projectRoot: string, ide: string): HookWrite[] {
|
|
175
|
+
writeLessonRules(projectRoot, [ide])
|
|
176
|
+
return writeMemoryHooks(projectRoot, [ide], cliVersionOf(pkgRoot))
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** The files that hold an OpenCastle memory hook now. */
|
|
180
|
+
export function memoryHookPaths(projectRoot: string): string[] {
|
|
181
|
+
const out: string[] = []
|
|
182
|
+
const settings = readJson(join(projectRoot, CLAUDE_SETTINGS))
|
|
183
|
+
if (settings && settings !== 'unreadable' && JSON.stringify(withoutOurs(settings)) !== JSON.stringify(settings)) out.push(CLAUDE_SETTINGS)
|
|
184
|
+
if (existsSync(join(projectRoot, VSCODE_HOOK_FILE))) out.push(VSCODE_HOOK_FILE)
|
|
185
|
+
return out
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** Take OpenCastle's hooks out: its entry from the settings, and its own hook file. */
|
|
189
|
+
export function stripMemoryHooks(projectRoot: string): string[] {
|
|
190
|
+
const removed: string[] = []
|
|
191
|
+
const settingsPath = join(projectRoot, CLAUDE_SETTINGS)
|
|
192
|
+
const current = readJson(settingsPath)
|
|
193
|
+
if (current && current !== 'unreadable') {
|
|
194
|
+
const next = withoutOurs(current)
|
|
195
|
+
if (JSON.stringify(next) !== JSON.stringify(current)) {
|
|
196
|
+
if (Object.keys(next).length === 0) rmSync(settingsPath)
|
|
197
|
+
else writeFileSync(settingsPath, `${JSON.stringify(next, null, 2)}\n`)
|
|
198
|
+
removed.push(CLAUDE_SETTINGS)
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
const hookFile = join(projectRoot, VSCODE_HOOK_FILE)
|
|
202
|
+
if (existsSync(hookFile)) {
|
|
203
|
+
rmSync(hookFile)
|
|
204
|
+
removed.push(VSCODE_HOOK_FILE)
|
|
205
|
+
}
|
|
206
|
+
return removed
|
|
207
|
+
}
|
|
@@ -208,8 +208,9 @@ function readMemoryFiles(dir: string): MemoryFile[] {
|
|
|
208
208
|
function fromMemoryFiles(dir: string, prefix: string, skipped: Array<[string, string]>): MemoryCandidate[] {
|
|
209
209
|
const out: MemoryCandidate[] = []
|
|
210
210
|
for (const memory of readMemoryFiles(dir)) {
|
|
211
|
-
// Corrections
|
|
212
|
-
|
|
211
|
+
// Corrections, project notes and pointers to where things live are the
|
|
212
|
+
// team's; a `user` memory is about one person, and stays theirs.
|
|
213
|
+
if (memory.type && !['feedback', 'project', 'reference'].includes(memory.type)) {
|
|
213
214
|
skipped.push([memory.file, memory.type === 'user' ? 'about you, not the project' : `a ${memory.type} memory`])
|
|
214
215
|
continue
|
|
215
216
|
}
|
|
@@ -265,16 +265,49 @@ describe.skipIf(!built)('opencastle promote', () => {
|
|
|
265
265
|
expect(text).toMatch(/source: "codex-memory:app test runs#[0-9a-f]{12}"/)
|
|
266
266
|
})
|
|
267
267
|
|
|
268
|
-
it('the
|
|
269
|
-
write(memoryDir(), {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
268
|
+
it('as the hook runs it: shares the project’s memory, keeps the user’s, refreshes what agents load, exits 0', () => {
|
|
269
|
+
write(memoryDir(), {
|
|
270
|
+
'build.md': memory('build', 'project', 'Set CI=1 before pnpm build.'),
|
|
271
|
+
'dashboards.md': memory('dashboards', 'reference', 'Errors are in the Sentry project acme-web.'),
|
|
272
|
+
'terse.md': memory('terse', 'user', 'Keep answers short.'),
|
|
273
|
+
})
|
|
274
|
+
const out = spawnSync('node', [cli, 'promote', 'memory', '--json'], {
|
|
275
|
+
cwd: project,
|
|
276
|
+
encoding: 'utf8',
|
|
277
|
+
env: env(),
|
|
278
|
+
input: '{"hook_event_name":"SessionEnd","reason":"exit"}',
|
|
279
|
+
})
|
|
280
|
+
expect(out.status).toBe(0)
|
|
281
|
+
const report = JSON.parse(out.stdout) as { shared: Array<{ lesson: string }>; left: Array<{ memory: string; why: string }> }
|
|
282
|
+
expect(report.shared).toHaveLength(2)
|
|
283
|
+
expect(report.left).toEqual([{ assistant: 'Claude Code', memory: 'terse.md', why: 'about you, not the project' }])
|
|
284
|
+
const rule = readFileSync(join(project, '.claude', 'rules', 'opencastle-lessons.md'), 'utf8')
|
|
285
|
+
expect(rule).toContain('**Build**')
|
|
286
|
+
expect(rule).toContain('**Dashboards**')
|
|
287
|
+
expect(rule).not.toContain('Terse')
|
|
288
|
+
expect(run(project, 'sync', '--check').status).toBe(0)
|
|
289
|
+
|
|
290
|
+
const again = spawnSync('node', [cli, 'promote', 'memory', '--json'], { cwd: project, encoding: 'utf8', env: env(), input: '{}' })
|
|
291
|
+
expect(JSON.parse(again.stdout).shared).toEqual([])
|
|
292
|
+
|
|
293
|
+
const nowhere = spawnSync('node', [cli, 'promote', 'memory', '--json'], { cwd: root, encoding: 'utf8', env: env(), input: '{}' })
|
|
294
|
+
expect(nowhere.status).toBe(0)
|
|
295
|
+
expect(JSON.parse(nowhere.stdout).note).toContain('no .opencastle/ here')
|
|
296
|
+
})
|
|
297
|
+
|
|
298
|
+
it('init adds the memory hook beside the project’s own settings, and sync --check holds it', () => {
|
|
299
|
+
const settings = JSON.parse(readFileSync(join(project, '.claude', 'settings.json'), 'utf8')) as { hooks: { SessionEnd: Array<{ hooks: Array<{ command: string; timeout: number }> }> } }
|
|
300
|
+
const ours = settings.hooks.SessionEnd.flatMap((g) => g.hooks).find((h) => h.command.includes('promote memory --json'))
|
|
301
|
+
expect(ours?.timeout).toBe(30)
|
|
302
|
+
writeFileSync(join(project, '.claude', 'settings.json'), JSON.stringify({ permissions: { allow: ['Bash(npm test)'] } }))
|
|
303
|
+
const check = run(project, 'sync', '--check')
|
|
304
|
+
expect(check.status).toBe(1)
|
|
305
|
+
expect(check.stdout + check.stderr).toContain('.claude/settings.json')
|
|
306
|
+
expect(run(project, 'sync', '--yes').status).toBe(0)
|
|
307
|
+
const merged = JSON.parse(readFileSync(join(project, '.claude', 'settings.json'), 'utf8')) as { permissions: unknown; hooks: unknown }
|
|
308
|
+
expect(merged.permissions).toEqual({ allow: ['Bash(npm test)'] })
|
|
309
|
+
expect(JSON.stringify(merged.hooks)).toContain('promote memory --json')
|
|
310
|
+
expect(run(project, 'sync', '--check').status).toBe(0)
|
|
278
311
|
})
|
|
279
312
|
})
|
|
280
313
|
})
|
package/src/cli/promote.ts
CHANGED
|
@@ -3,7 +3,8 @@ import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync
|
|
|
3
3
|
import { homedir } from 'node:os'
|
|
4
4
|
import { basename, dirname, join, relative, resolve } from 'node:path'
|
|
5
5
|
import { checkSkill } from './agent-plugin.js'
|
|
6
|
-
import { LESSONS_DIR, newLessonId, readLessons, renderLesson,
|
|
6
|
+
import { LESSONS_DIR, newLessonId, readLessons, renderLesson, today, type Lesson } from './lessons.js'
|
|
7
|
+
import { refreshLessons } from './lessons-rules.js'
|
|
7
8
|
import { readMemoryDir, readRepositoryMemory, type MemorySource } from './memory-sources.js'
|
|
8
9
|
import { scanForSecrets } from './secret-scan.js'
|
|
9
10
|
import { getOrchestratorRoot } from './copy.js'
|
|
@@ -56,6 +57,8 @@ const HELP = `
|
|
|
56
57
|
--from <dir> memory: read memory files from this directory instead
|
|
57
58
|
--force skill: replace a team skill with the same name
|
|
58
59
|
--dry-run Say what would be written, and write nothing
|
|
60
|
+
--json memory: one line of JSON and exit 0, as the assistants'
|
|
61
|
+
memory hooks run it
|
|
59
62
|
--help, -h Show this help
|
|
60
63
|
`
|
|
61
64
|
|
|
@@ -217,20 +220,29 @@ function promoteSkill(pkgRoot: string, args: string[], dryRun: boolean): void {
|
|
|
217
220
|
export { claudeMemoryDir } from './memory-sources.js'
|
|
218
221
|
|
|
219
222
|
function promoteMemory(args: string[], dryRun: boolean): void {
|
|
223
|
+
// --json is how the assistants' hooks run it: one line of JSON, no prose,
|
|
224
|
+
// and exit 0 whatever happens, because a hook's exit code means something to
|
|
225
|
+
// the assistant (on Stop, 2 tells the agent to keep going) and a session
|
|
226
|
+
// ending is no time to report a missing memory directory.
|
|
227
|
+
const json = args.includes('--json')
|
|
228
|
+
const stop = (message: string): void => {
|
|
229
|
+
if (!json) fail(message)
|
|
230
|
+
console.log(JSON.stringify({ shared: [], left: [], note: message }))
|
|
231
|
+
}
|
|
220
232
|
const projectRoot = projectRootFrom(process.cwd())
|
|
221
233
|
const customizations = join(projectRoot, '.opencastle')
|
|
222
|
-
if (!existsSync(customizations))
|
|
234
|
+
if (!existsSync(customizations)) return stop('no .opencastle/ here — run npx opencastle init first')
|
|
223
235
|
const from = flag(args, '--from')
|
|
224
236
|
let sources: MemorySource[]
|
|
225
237
|
if (from) {
|
|
226
238
|
const dir = resolve(process.cwd(), from.replace(/^~(?=\/|$)/, home()))
|
|
227
|
-
if (!existsSync(dir))
|
|
239
|
+
if (!existsSync(dir)) return stop(`no memory at ${tilde(dir)}`)
|
|
228
240
|
sources = [readMemoryDir(dir, 'Memory')]
|
|
229
241
|
} else {
|
|
230
242
|
const found = readRepositoryMemory(projectRoot)
|
|
231
243
|
sources = found.sources
|
|
232
244
|
if (sources.length === 0) {
|
|
233
|
-
|
|
245
|
+
return stop(
|
|
234
246
|
`no memory at ${tilde(found.looked[0])}, in VS Code's storage for this folder, or in ${tilde(dirname(found.looked[found.looked.length - 1]))}/memories — ` +
|
|
235
247
|
'each assistant writes it once it has saved one for this repository; --from <dir> reads another. ' +
|
|
236
248
|
'Cursor keeps its memories on its servers and Copilot Memory lives on GitHub, so neither can be read here.',
|
|
@@ -238,13 +250,15 @@ function promoteMemory(args: string[], dryRun: boolean): void {
|
|
|
238
250
|
}
|
|
239
251
|
}
|
|
240
252
|
|
|
241
|
-
|
|
253
|
+
refreshLessons(customizations)
|
|
242
254
|
const { lessons } = readLessons(customizations)
|
|
243
255
|
const promoted = new Set(lessons.map((l) => l.source).filter((s): s is string => Boolean(s)))
|
|
244
256
|
const taken = new Set(lessons.map((l) => l.id))
|
|
245
257
|
const written: string[] = []
|
|
258
|
+
const shared: Array<{ assistant: string; lesson: string }> = []
|
|
259
|
+
const left: Array<{ assistant: string; memory: string; why: string }> = []
|
|
246
260
|
|
|
247
|
-
console.log(`\n 🏰 ${c.bold('Promote memory')}`)
|
|
261
|
+
if (!json) console.log(`\n 🏰 ${c.bold('Promote memory')}`)
|
|
248
262
|
for (const source of sources) {
|
|
249
263
|
const wrote: string[] = []
|
|
250
264
|
const skipped = [...source.skipped]
|
|
@@ -274,17 +288,24 @@ function promoteMemory(args: string[], dryRun: boolean): void {
|
|
|
274
288
|
}
|
|
275
289
|
}
|
|
276
290
|
written.push(...wrote)
|
|
291
|
+
shared.push(...wrote.map((w) => ({ assistant: source.assistant, lesson: `.opencastle/${w}` })))
|
|
292
|
+
left.push(...skipped.filter(([, why]) => why !== 'already a lesson').map(([memory, why]) => ({ assistant: source.assistant, memory, why })))
|
|
293
|
+
if (json) continue
|
|
277
294
|
console.log(`\n ${c.bold(source.assistant)} ${c.dim(`from ${tilde(source.where)}`)}`)
|
|
278
295
|
for (const w of wrote) console.log(` ${c.green(dryRun ? '+' : '✓')} ${dryRun ? 'Would write' : 'Wrote'} .opencastle/${w}`)
|
|
279
296
|
for (const [file, why] of skipped) console.log(` ${c.dim(`- ${file}: ${why}`)}`)
|
|
280
297
|
}
|
|
281
|
-
if (!dryRun && written.length > 0)
|
|
298
|
+
if (!dryRun && written.length > 0) refreshLessons(customizations)
|
|
282
299
|
|
|
300
|
+
if (json) {
|
|
301
|
+
console.log(JSON.stringify({ shared, left }))
|
|
302
|
+
return
|
|
303
|
+
}
|
|
283
304
|
if (written.length === 0) console.log(`\n ${c.dim('Nothing new to promote.')}\n`)
|
|
284
305
|
else if (!dryRun) {
|
|
285
306
|
console.log(
|
|
286
|
-
`\n ${c.dim('Each is category general, severity medium: set them, add --cite where a lesson is about code
|
|
287
|
-
`\n ${c.dim('
|
|
307
|
+
`\n ${c.dim('Each is category general, severity medium: set them, and add --cite where a lesson is about code.')}` +
|
|
308
|
+
`\n ${c.dim('The pull request that commits them is where the team agrees.')}\n`,
|
|
288
309
|
)
|
|
289
310
|
} else {
|
|
290
311
|
console.log('')
|
|
@@ -299,7 +320,12 @@ export default async function promote({ pkgRoot, args }: CliContext): Promise<vo
|
|
|
299
320
|
return
|
|
300
321
|
}
|
|
301
322
|
const dryRun = rest.includes('--dry-run')
|
|
302
|
-
if (sub === 'skill') promoteSkill(pkgRoot, rest, dryRun)
|
|
303
|
-
|
|
323
|
+
if (sub === 'skill') return promoteSkill(pkgRoot, rest, dryRun)
|
|
324
|
+
if (!rest.includes('--json')) return promoteMemory(rest, dryRun)
|
|
325
|
+
try {
|
|
326
|
+
promoteMemory(rest, dryRun)
|
|
327
|
+
} catch (err) {
|
|
328
|
+
console.log(JSON.stringify({ shared: [], left: [], note: (err as Error).message }))
|
|
329
|
+
}
|
|
304
330
|
}
|
|
305
331
|
|
package/src/cli/remove.ts
CHANGED
|
@@ -5,6 +5,8 @@ import { readManifest } from './manifest.js'
|
|
|
5
5
|
import { removeDirIfExists } from './copy.js'
|
|
6
6
|
import { removeGitignoreBlock, predictGitignoreStrip, LOCAL_DIRS } from './gitignore.js'
|
|
7
7
|
import { confirm, select, closePrompts, c } from './prompt.js'
|
|
8
|
+
import { memoryHookPaths, stripMemoryHooks } from './memory-hooks.js'
|
|
9
|
+
import { LESSON_RULES } from './lessons-rules.js'
|
|
8
10
|
import { stripManagedBlockFromFile, predictStripFile } from './managed-block.js'
|
|
9
11
|
import { resolveManagedPaths, ownerOf, removeOwnedFiles } from './managed-paths.js'
|
|
10
12
|
import { stripManagedMcpServers, getMcpConfigRelPath, willKeepSomethingAfterStrip, retireLegacyMcpConfig, LEGACY_MCP_CONFIGS } from './mcp.js'
|
|
@@ -248,9 +250,14 @@ export default async function remove({ args }: CliContext): Promise<void> {
|
|
|
248
250
|
|
|
249
251
|
console.log(`\n 🏰 ${c.bold('OpenCastle remove')}\n`)
|
|
250
252
|
|
|
253
|
+
// The memory hook runs OpenCastle, which this is the step before uninstalling,
|
|
254
|
+
// so it goes in both modes; the lessons rules are text, and stay with the files.
|
|
255
|
+
const hookPaths = memoryHookPaths(projectRoot)
|
|
256
|
+
const lessonRulePaths = Object.values(LESSON_RULES).map((r) => r.path).filter((p) => existsSync(resolve(projectRoot, p)))
|
|
251
257
|
if (mode === 'keep-files') {
|
|
252
258
|
console.log(' Will remove:')
|
|
253
259
|
console.log(` ${c.dim('.opencastle/manifest.json')}`)
|
|
260
|
+
for (const p of hookPaths) console.log(` ${c.dim(`the memory hook in ${p}`)}`)
|
|
254
261
|
console.log('\n Every generated file stays exactly where it is.')
|
|
255
262
|
console.log(` Afterwards: ${c.bold('npm uninstall opencastle')}\n`)
|
|
256
263
|
} else {
|
|
@@ -267,6 +274,8 @@ export default async function remove({ args }: CliContext): Promise<void> {
|
|
|
267
274
|
` ${c.yellow('→')} ${c.dim('.opencastle/')} ${c.yellow(`moved to ${relative(projectRoot, parkedDirFor(projectRoot))}/ — your conventions and lessons`)}`,
|
|
268
275
|
)
|
|
269
276
|
if (hasLegacy) console.log(` ${c.red('-')} ${c.dim('.opencastle.json')}`)
|
|
277
|
+
for (const p of hookPaths) console.log(` ${c.red('-')} ${c.dim(`the memory hook in ${p}`)}`)
|
|
278
|
+
for (const p of lessonRulePaths) console.log(` ${c.red('-')} ${c.dim(p)}`)
|
|
270
279
|
|
|
271
280
|
// Co-owned files are only *sometimes* kept: one holding nothing but our
|
|
272
281
|
// block is deleted. Announcing "your own writing stays" over a file about to
|
|
@@ -329,6 +338,7 @@ export default async function remove({ args }: CliContext): Promise<void> {
|
|
|
329
338
|
// `readManifest`, so dropping only the new path left the project still
|
|
330
339
|
// reporting as installed under a heading that said otherwise.
|
|
331
340
|
if (hasLegacy) await unlink(legacyManifestPath).catch(() => {})
|
|
341
|
+
stripMemoryHooks(projectRoot)
|
|
332
342
|
console.log(`\n ${c.green('✓')} Files are now standalone.`)
|
|
333
343
|
console.log(` You can uninstall: ${c.bold('npm uninstall opencastle')}\n`)
|
|
334
344
|
closePrompts()
|
|
@@ -400,6 +410,18 @@ export default async function remove({ args }: CliContext): Promise<void> {
|
|
|
400
410
|
}
|
|
401
411
|
}
|
|
402
412
|
|
|
413
|
+
for (const p of stripMemoryHooks(projectRoot)) {
|
|
414
|
+
if (existsSync(resolve(projectRoot, p))) stripped++
|
|
415
|
+
else removed++
|
|
416
|
+
parents.add(dirname(resolve(projectRoot, p)))
|
|
417
|
+
}
|
|
418
|
+
for (const p of lessonRulePaths) {
|
|
419
|
+
if (!existsSync(resolve(projectRoot, p))) continue
|
|
420
|
+
await unlink(resolve(projectRoot, p))
|
|
421
|
+
removed++
|
|
422
|
+
parents.add(dirname(resolve(projectRoot, p)))
|
|
423
|
+
}
|
|
424
|
+
|
|
403
425
|
// The containers our own directories lived in. `.claude/agents/`, `skills/`
|
|
404
426
|
// and `commands/` were each removed by name and `.claude/` itself was left
|
|
405
427
|
// behind — an empty directory the user has to notice and delete, after a
|
package/src/cli/status.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { resolve } from 'node:path'
|
|
2
2
|
import { existsSync, statSync } from 'node:fs'
|
|
3
3
|
import { readdir, stat } from 'node:fs/promises'
|
|
4
4
|
import { readManifest } from './manifest.js'
|
|
@@ -21,8 +21,7 @@ import type { CliContext, IdeAdapter, Manifest } from './types.js'
|
|
|
21
21
|
const STATUS_HELP = `
|
|
22
22
|
opencastle
|
|
23
23
|
|
|
24
|
-
Show what is installed, whether generated files are current, what to run next
|
|
25
|
-
and how many of your assistant's memories the team has not got yet.
|
|
24
|
+
Show what is installed, whether generated files are current, and what to run next.
|
|
26
25
|
|
|
27
26
|
Options:
|
|
28
27
|
--json Machine-readable output
|
|
@@ -54,8 +53,6 @@ export interface StatusReport {
|
|
|
54
53
|
nextReason?: string
|
|
55
54
|
/** The baselines the committed lock records, as `name version`. */
|
|
56
55
|
baselines?: string[]
|
|
57
|
-
/** Memories this machine's assistants keep about the repository that no lesson holds yet. */
|
|
58
|
-
unsharedMemories?: Array<{ assistant: string; count: number }>
|
|
59
56
|
}
|
|
60
57
|
|
|
61
58
|
/** Newest mtime under a directory tree, or 0 when absent. */
|
|
@@ -337,23 +334,10 @@ export async function buildStatusReport(pkgRoot: string, projectRoot: string): P
|
|
|
337
334
|
baselines = []
|
|
338
335
|
}
|
|
339
336
|
|
|
340
|
-
// What this person's assistants learned here and the team has not seen.
|
|
341
|
-
// Not a fault, so it never becomes the next command: it only says so.
|
|
342
|
-
let unsharedMemories: Array<{ assistant: string; count: number }> = []
|
|
343
|
-
try {
|
|
344
|
-
const { readLessons } = await import('./lessons.js')
|
|
345
|
-
const { unsharedMemory } = await import('./memory-sources.js')
|
|
346
|
-
const { lessons } = readLessons(join(projectRoot, '.opencastle'))
|
|
347
|
-
unsharedMemories = unsharedMemory(projectRoot, new Set(lessons.map((l) => l.source).filter((s): s is string => Boolean(s))))
|
|
348
|
-
} catch {
|
|
349
|
-
unsharedMemories = []
|
|
350
|
-
}
|
|
351
|
-
|
|
352
337
|
return {
|
|
353
338
|
installed: true,
|
|
354
339
|
missingRequired,
|
|
355
340
|
...(baselines.length > 0 && { baselines }),
|
|
356
|
-
...(unsharedMemories.length > 0 && { unsharedMemories }),
|
|
357
341
|
version: manifest.version,
|
|
358
342
|
ides: adapters.map((a) => a.ide),
|
|
359
343
|
targets,
|
|
@@ -418,16 +402,6 @@ function render(report: StatusReport): void {
|
|
|
418
402
|
console.log(` ${c.dim('Not compiled:')} ${report.unmanaged.join(', ')}`)
|
|
419
403
|
}
|
|
420
404
|
|
|
421
|
-
const unshared = report.unsharedMemories ?? []
|
|
422
|
-
if (unshared.length > 0) {
|
|
423
|
-
const n = unshared.reduce((sum, u) => sum + u.count, 0)
|
|
424
|
-
console.log('')
|
|
425
|
-
console.log(
|
|
426
|
-
` ${c.dim('Memory')} ${n} ${n === 1 ? 'memory' : 'memories'} on this machine the team has not got yet ` +
|
|
427
|
-
c.dim(`(${unshared.map((u) => `${u.assistant} ${u.count}`).join(', ')})`),
|
|
428
|
-
)
|
|
429
|
-
console.log(` ${c.cyan('npx opencastle promote memory')} ${c.dim(n === 1 ? 'makes it a lesson for everyone' : 'makes them lessons for everyone')}`)
|
|
430
|
-
}
|
|
431
405
|
|
|
432
406
|
console.log('')
|
|
433
407
|
if (report.nextCommand) {
|
package/src/cli/sync-check.ts
CHANGED
|
@@ -7,6 +7,8 @@ import { detectRepoInfo, mergeStackIntoRepoInfo } from './detect.js'
|
|
|
7
7
|
import { getMcpConfigRelPath, expectedTeamEntries, containerKeyFor } from './mcp.js'
|
|
8
8
|
import { parseMcpConfigText } from './mcp-file.js'
|
|
9
9
|
import { lessonsIndexDrift, LESSONS_INDEX } from './lessons.js'
|
|
10
|
+
import { isLessonRule, lessonRulesDrift } from './lessons-rules.js'
|
|
11
|
+
import { memoryHooksDrift } from './memory-hooks.js'
|
|
10
12
|
import { resolveStack, getIncludedMcpServers } from './stack-config.js'
|
|
11
13
|
import { auditMcpConfig, describeFindingUnder, remedyFor, isFailure, type TeamAuditContext } from './mcp-audit.js'
|
|
12
14
|
import { resolveSources, materialize, hasErrors, cliVersionOf, type CompileSource } from './layers.js'
|
|
@@ -63,7 +65,7 @@ export interface Drift {
|
|
|
63
65
|
* parse, a baseline that is not installed, a policy the sources break. The
|
|
64
66
|
* comparison cannot run until it is fixed, and `sync` refuses to compile.
|
|
65
67
|
*/
|
|
66
|
-
origin?: 'mcp' | 'team' | 'version'
|
|
68
|
+
origin?: 'mcp' | 'team' | 'version' | 'memory'
|
|
67
69
|
/** The classifier's own words, so the checker and `doctor` cannot diverge. */
|
|
68
70
|
detail?: string
|
|
69
71
|
/** What resolves it, per entry — these do not share a remedy. */
|
|
@@ -215,6 +217,9 @@ function comparePath(
|
|
|
215
217
|
// A file the target shares the directory with someone over — their own
|
|
216
218
|
// prompt beside ours in `.github/prompts/` — is not drift.
|
|
217
219
|
if (owns && !owns(shown)) continue
|
|
220
|
+
// The lessons rule sits among compiled rules but is derived from the
|
|
221
|
+
// lessons, and checked against them below.
|
|
222
|
+
if (isLessonRule(shown)) continue
|
|
218
223
|
drift.push({ ide, path: shown, kind: 'extra' })
|
|
219
224
|
}
|
|
220
225
|
return checked
|
|
@@ -661,6 +666,19 @@ async function compareProject(
|
|
|
661
666
|
if (why) drift.push({ ide: 'all', path: `.opencastle/${LESSONS_INDEX}`, kind: 'outdated', detail: why, fix: 'npx opencastle sync' })
|
|
662
667
|
}
|
|
663
668
|
|
|
669
|
+
// The team's memory: the lessons rule each assistant loads, derived from the
|
|
670
|
+
// lessons like the index, and the hook that shares what agents remember.
|
|
671
|
+
for (const d of lessonRulesDrift(projectRoot, ides)) {
|
|
672
|
+
drift.push({ ide: d.ide, path: d.path, kind: 'outdated', detail: d.detail, fix: 'npx opencastle sync', origin: 'memory' })
|
|
673
|
+
}
|
|
674
|
+
for (const d of memoryHooksDrift(projectRoot, ides, cliVersionOf(pkgRoot))) {
|
|
675
|
+
drift.push(
|
|
676
|
+
d.unreadable
|
|
677
|
+
? { ide: d.ide, path: d.path, kind: 'unreducible', detail: d.detail, fix: 'fix the JSON, then run npx opencastle sync; this one needs a person', origin: 'memory' }
|
|
678
|
+
: { ide: d.ide, path: d.path, kind: 'outdated', detail: d.detail, fix: 'npx opencastle sync', origin: 'memory' },
|
|
679
|
+
)
|
|
680
|
+
}
|
|
681
|
+
|
|
664
682
|
// A manifest that parses but names no target this release knows is not a
|
|
665
683
|
// clean project — `sync` exits 1 on it. Reporting "0 generated files match
|
|
666
684
|
// their sources across 0 targets" is an assertion that cannot fail, and it
|
|
@@ -723,11 +741,14 @@ function render(report: CheckReport): void {
|
|
|
723
741
|
// `.opencastle/lessons/` and stale until `sync` runs. It was filed under "MCP
|
|
724
742
|
// servers sync would change", which it has nothing to do with.
|
|
725
743
|
const lessonsIndex = `.opencastle/${LESSONS_INDEX}`
|
|
744
|
+
// The lessons each assistant loads follow the index; the memory hook is
|
|
745
|
+
// neither a source nor an MCP server, and says so.
|
|
726
746
|
const lockDrift = [
|
|
727
747
|
...[...changed, ...missing].filter((d) => d.path === LOCK_REL),
|
|
728
|
-
...outdated.filter((d) => d.path === lessonsIndex),
|
|
748
|
+
...outdated.filter((d) => d.path === lessonsIndex || isLessonRule(d.path)),
|
|
729
749
|
]
|
|
730
|
-
const
|
|
750
|
+
const hookDrift = outdated.filter((d) => d.origin === 'memory' && !isLessonRule(d.path))
|
|
751
|
+
const outdatedMcp = outdated.filter((d) => d.path !== lessonsIndex && d.origin !== 'memory')
|
|
731
752
|
const changedFiles = changed.filter((d) => d.path !== LOCK_REL)
|
|
732
753
|
const missingFiles = missing.filter((d) => d.path !== LOCK_REL)
|
|
733
754
|
if (lockDrift.length > 0) {
|
|
@@ -751,6 +772,12 @@ function render(report: CheckReport): void {
|
|
|
751
772
|
console.log('')
|
|
752
773
|
}
|
|
753
774
|
|
|
775
|
+
if (hookDrift.length > 0) {
|
|
776
|
+
console.log(` ${c.bold('The memory hook')} ${c.dim('(it shares what agents remember about the project when a session ends)')}`)
|
|
777
|
+
for (const d of hookDrift) console.log(` ${c.yellow('~')} ${d.path} ${c.dim(`(${d.detail})`)}`)
|
|
778
|
+
console.log('')
|
|
779
|
+
}
|
|
780
|
+
|
|
754
781
|
if (outdatedMcp.length > 0) {
|
|
755
782
|
console.log(
|
|
756
783
|
` ${c.bold('MCP servers sync would change')} ${c.dim('(integration defaults move forward, team servers are written as defined; entries you added or edited stay yours)')}`,
|
package/src/cli/update.ts
CHANGED
|
@@ -32,6 +32,8 @@ import { buildLock, writeLock, readLock, LOCK_REL, priorTeam } from './lock.js'
|
|
|
32
32
|
import { parseVersion, compareVersions } from './version-range.js'
|
|
33
33
|
import { COMMAND_NAMESPACE } from './command-namespace.js'
|
|
34
34
|
import { parseMcpConfigText } from './mcp-file.js'
|
|
35
|
+
import { writeLessonRules } from './lessons-rules.js'
|
|
36
|
+
import { memoryHooksDrift } from './memory-hooks.js'
|
|
35
37
|
import { syncLessons, LESSONS_DIR, LESSONS_INDEX } from './lessons.js'
|
|
36
38
|
|
|
37
39
|
/** The config that replaced a legacy one, for the sentence that reports it. */
|
|
@@ -558,6 +560,7 @@ export default async function update({
|
|
|
558
560
|
}
|
|
559
561
|
|
|
560
562
|
// ── Update each IDE ─────────────────────────────────────────────
|
|
563
|
+
const hooksBefore = memoryHooksDrift(projectRoot, ides, pkg.version)
|
|
561
564
|
// Generated config that exists but will not parse. Filled from two places —
|
|
562
565
|
// the adapters' own scaffold step and the rebuild pass below — and reported
|
|
563
566
|
// once at the end, because the user needs the filename either way.
|
|
@@ -722,6 +725,13 @@ export default async function update({
|
|
|
722
725
|
// but compiled all the same, and `sync --check` holds it to its sources.
|
|
723
726
|
const lessons = syncLessons(resolve(projectRoot, '.opencastle'))
|
|
724
727
|
|
|
728
|
+
// ── The team's memory ───────────────────────────────────────────
|
|
729
|
+
// Each target's compile wrote the lessons it loads and its memory hook;
|
|
730
|
+
// what changed is the difference from before the targets ran. The lessons
|
|
731
|
+
// rules follow the index just rebuilt above.
|
|
732
|
+
writeLessonRules(projectRoot, ides)
|
|
733
|
+
const hooksAfter = memoryHooksDrift(projectRoot, ides, pkg.version)
|
|
734
|
+
|
|
725
735
|
// ── Update manifest ─────────────────────────────────────────────
|
|
726
736
|
const before = manifestMeaning(manifest as unknown as Record<string, unknown>)
|
|
727
737
|
manifest.version = pkg.version
|
|
@@ -784,6 +794,13 @@ export default async function update({
|
|
|
784
794
|
if (lessons.index === 'updated' && lessons.migrated === 0 && !lessons.backup) {
|
|
785
795
|
console.log(` ${c.green('✓')} Updated .opencastle/${LESSONS_INDEX} from .opencastle/${LESSONS_DIR}/`)
|
|
786
796
|
}
|
|
797
|
+
for (const before of hooksBefore) {
|
|
798
|
+
if (hooksAfter.some((a) => a.path === before.path)) continue
|
|
799
|
+
console.log(` ${c.green('✓')} ${before.detail.includes('missing') || before.detail.startsWith('has no') ? 'Added' : 'Updated'} the memory hook in ${before.path}`)
|
|
800
|
+
}
|
|
801
|
+
for (const after of hooksAfter.filter((a) => a.unreadable)) {
|
|
802
|
+
console.log(` ${c.yellow('!')} ${after.path} is not valid JSON, so the memory hook was not added — fix it and run sync again`)
|
|
803
|
+
}
|
|
787
804
|
for (const problem of lessons.problems) {
|
|
788
805
|
console.log(` ${c.yellow('!')} Left .opencastle/${problem.split(' ')[0]} out of the lessons index — ${problem.slice(problem.indexOf(' ') + 1)}`)
|
|
789
806
|
}
|
|
@@ -15,6 +15,6 @@ The project's own instructions win: the Project Context loaded with these, the r
|
|
|
15
15
|
- **Fail visibly** — surface errors; never swallow an exception.
|
|
16
16
|
- **Comments say why**, not what.
|
|
17
17
|
- **Git.** Never push to `main`: every change goes through a branch and a pull request (**git-workflow**).
|
|
18
|
-
- **Memory: the team's or the user's.**
|
|
18
|
+
- **Memory: the team's or the user's.** The team's lessons load with these instructions (if they did not, read `.opencastle/LESSONS-LEARNED.md`); open the ones that touch your task. Save what you learn in your own memory, as you normally do: in Claude Code and VS Code, OpenCastle shares what is about the project with the team when the session ends, and leaves what is about the user. So save what is about the user (their preferences, role, habits, machine) as about the user. In any other assistant, record what you confirm about the project as a lesson (**self-improvement**).
|
|
19
19
|
|
|
20
20
|
<!-- End of Coding Standards -->
|