opencastle 1.7.3 → 1.9.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.
@@ -0,0 +1,388 @@
1
+ import { createHash } from 'node:crypto'
2
+ import { execFileSync } from 'node:child_process'
3
+ import { existsSync, readFileSync, readdirSync, realpathSync, statSync } from 'node:fs'
4
+ import { homedir } from 'node:os'
5
+ import { basename, dirname, join, sep } from 'node:path'
6
+ import { fileURLToPath } from 'node:url'
7
+ import { parse as parseYaml } from 'yaml'
8
+ import { scanForSecrets } from './secret-scan.js'
9
+
10
+ /**
11
+ * What each assistant remembered about one repository, read from where it
12
+ * keeps it on this machine.
13
+ *
14
+ * Every assistant now has a memory, and almost none of it reaches a teammate:
15
+ * Claude Code's auto memory, VS Code's repository memory and Codex's memories
16
+ * are files in one person's home directory. These readers find the ones that
17
+ * belong to this repository so `promote memory` can turn them into lessons the
18
+ * team reviews, and the status screen can say how many are not shared yet.
19
+ *
20
+ * Cursor keeps its memories on its own servers, and Copilot Memory lives on
21
+ * GitHub; neither is on disk, so neither has a reader.
22
+ */
23
+
24
+ export interface MemoryCandidate {
25
+ /** The file, or the file and block, the memory came from — for messages. */
26
+ label: string
27
+ title: string
28
+ /** The lesson body: home directory written as ~, checked for credentials. */
29
+ body: string
30
+ /** Recorded on the lesson, so the same memory is never promoted twice. */
31
+ source: string
32
+ }
33
+
34
+ export interface MemorySource {
35
+ assistant: string
36
+ /** Where it was read, for the reader of the output. */
37
+ where: string
38
+ candidates: MemoryCandidate[]
39
+ skipped: Array<[string, string]>
40
+ }
41
+
42
+ function home(): string {
43
+ return process.env.HOME || homedir()
44
+ }
45
+
46
+ function expandHome(path: string): string {
47
+ return path.replace(/^~(?=\/|\\|$)/, home())
48
+ }
49
+
50
+ function digest(text: string): string {
51
+ return createHash('sha256').update(text).digest('hex').slice(0, 12)
52
+ }
53
+
54
+ /** One title line from free text, capitalised. */
55
+ function asTitle(raw: string): string {
56
+ const one = raw.replace(/[\r\n]+/g, ' ').trim()
57
+ return one.charAt(0).toUpperCase() + one.slice(1)
58
+ }
59
+
60
+ /**
61
+ * The checkout every worktree of this repository belongs to: assistants that
62
+ * key memory by repository share one store across worktrees.
63
+ */
64
+ const checkouts = new Map<string, string>()
65
+
66
+ export function mainCheckout(projectRoot: string): string {
67
+ const known = checkouts.get(projectRoot)
68
+ if (known) return known
69
+ const found = findMainCheckout(projectRoot)
70
+ checkouts.set(projectRoot, found)
71
+ return found
72
+ }
73
+
74
+ function findMainCheckout(projectRoot: string): string {
75
+ try {
76
+ const common = execFileSync('git', ['rev-parse', '--path-format=absolute', '--git-common-dir'], {
77
+ cwd: projectRoot,
78
+ encoding: 'utf8',
79
+ stdio: ['ignore', 'pipe', 'ignore'],
80
+ }).trim()
81
+ return basename(common) === '.git' ? dirname(common) : projectRoot
82
+ } catch {
83
+ return projectRoot
84
+ }
85
+ }
86
+
87
+ /**
88
+ * A path as given and as resolved, so a symlinked checkout still matches. A
89
+ * path that no longer exists, such as a memory's directory since deleted, is
90
+ * resolved through its nearest existing parent.
91
+ */
92
+ function forms(path: string): string[] {
93
+ const given = path.replace(/[\\/]+$/, '')
94
+ const out = new Set([given])
95
+ let existing = given
96
+ let rest = ''
97
+ for (;;) {
98
+ try {
99
+ out.add(join(realpathSync(existing), rest))
100
+ break
101
+ } catch {
102
+ const parent = dirname(existing)
103
+ if (parent === existing) break
104
+ rest = join(basename(existing), rest)
105
+ existing = parent
106
+ }
107
+ }
108
+ return [...out]
109
+ }
110
+
111
+ /** True when `path` is the repository or a directory inside it. */
112
+ function within(path: string, roots: string[]): boolean {
113
+ const p = forms(path)
114
+ return roots.some((r) => p.some((x) => x === r || x.startsWith(r + sep)))
115
+ }
116
+
117
+ /**
118
+ * The text of a memory, ready to be a lesson: paths on its author's machine
119
+ * written as ~, and nothing that looks like a credential.
120
+ */
121
+ function prepare(label: string, body: string, skipped: Array<[string, string]>): string | null {
122
+ if (!body.trim()) {
123
+ skipped.push([label, 'empty'])
124
+ return null
125
+ }
126
+ const shared = body.split(home()).join('~').trim()
127
+ const scan = scanForSecrets(shared, label)
128
+ if (!scan.clean) {
129
+ skipped.push([label, `holds what looks like a ${scan.findings[0].pattern} (line ${scan.findings[0].line})`])
130
+ return null
131
+ }
132
+ return shared
133
+ }
134
+
135
+ // ── Claude Code ───────────────────────────────────────────────
136
+
137
+ /** The directory Claude Code's settings point auto memory at, if any of them does. */
138
+ function configuredMemoryDir(projectRoot: string, configDir: string): string | null {
139
+ for (const file of [
140
+ join(projectRoot, '.claude', 'settings.local.json'),
141
+ join(projectRoot, '.claude', 'settings.json'),
142
+ join(configDir, 'settings.json'),
143
+ ]) {
144
+ try {
145
+ const value = (JSON.parse(readFileSync(file, 'utf8')) as { autoMemoryDirectory?: unknown }).autoMemoryDirectory
146
+ if (typeof value === 'string' && value) return expandHome(value)
147
+ } catch {
148
+ // Absent or unreadable: the next one, or the default.
149
+ }
150
+ }
151
+ return null
152
+ }
153
+
154
+ /**
155
+ * Where Claude Code keeps this repository's auto memory:
156
+ * `<config>/projects/<repository path, every other character a hyphen>/memory/`.
157
+ * Every worktree of one repository shares it, so the path is the main
158
+ * checkout's, which git names as the common directory's parent.
159
+ */
160
+ export function claudeMemoryDir(projectRoot: string): string {
161
+ const configDir = process.env.CLAUDE_CONFIG_DIR || join(home(), '.claude')
162
+ const configured = configuredMemoryDir(projectRoot, configDir)
163
+ if (configured) return configured
164
+ const slug = process.env.CLAUDE_CODE_PROJECT_DIR_NAME || mainCheckout(projectRoot).replace(/[^A-Za-z0-9]/g, '-')
165
+ return join(configDir, 'projects', slug, 'memory')
166
+ }
167
+
168
+ interface MemoryFile {
169
+ file: string
170
+ name: string
171
+ description?: string
172
+ type?: string
173
+ body: string
174
+ }
175
+
176
+ /** Markdown memory files, with or without frontmatter; MEMORY.md is an index. */
177
+ function readMemoryFiles(dir: string): MemoryFile[] {
178
+ const out: MemoryFile[] = []
179
+ for (const file of readdirSync(dir).sort()) {
180
+ if (!file.endsWith('.md') || file === 'MEMORY.md') continue
181
+ const abs = join(dir, file)
182
+ if (!statSync(abs).isFile()) continue
183
+ const text = readFileSync(abs, 'utf8').replace(/^/, '')
184
+ const m = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/.exec(text)
185
+ let meta: Record<string, unknown> = {}
186
+ try {
187
+ meta = m ? ((parseYaml(m[1]) ?? {}) as Record<string, unknown>) : {}
188
+ } catch {
189
+ meta = {}
190
+ }
191
+ const nested = meta.metadata && typeof meta.metadata === 'object' ? (meta.metadata as Record<string, unknown>) : {}
192
+ const type = typeof meta.type === 'string' ? meta.type : typeof nested.type === 'string' ? nested.type : undefined
193
+ out.push({
194
+ file,
195
+ name: typeof meta.name === 'string' ? meta.name : file.replace(/\.md$/, ''),
196
+ description: typeof meta.description === 'string' ? meta.description : undefined,
197
+ type,
198
+ body: (m ? m[2] : text).trim(),
199
+ })
200
+ }
201
+ return out
202
+ }
203
+
204
+ /**
205
+ * Memory files as lessons. A file's own `# heading` is its title when it has
206
+ * no description, and leaves the body so the lesson does not say it twice.
207
+ */
208
+ function fromMemoryFiles(dir: string, prefix: string, skipped: Array<[string, string]>): MemoryCandidate[] {
209
+ const out: MemoryCandidate[] = []
210
+ for (const memory of readMemoryFiles(dir)) {
211
+ // Corrections and project notes are the team's; the rest are about one person.
212
+ if (memory.type && !['feedback', 'project'].includes(memory.type)) {
213
+ skipped.push([memory.file, memory.type === 'user' ? 'about you, not the project' : `a ${memory.type} memory`])
214
+ continue
215
+ }
216
+ const heading = /^#\s+(.+)\r?\n?/.exec(memory.body)
217
+ const title = asTitle(memory.description ?? heading?.[1] ?? memory.name.replace(/[-_]+/g, ' '))
218
+ const raw = !memory.description && heading ? memory.body.slice(heading[0].length) : memory.body
219
+ const body = prepare(memory.file, raw, skipped)
220
+ if (body === null) continue
221
+ out.push({ label: memory.file, title, body, source: `${prefix}:${memory.file}#${digest(memory.body)}` })
222
+ }
223
+ return out
224
+ }
225
+
226
+ /** Claude Code's auto memory, or a directory of memory files given with --from. */
227
+ export function readMemoryDir(dir: string, assistant: string): MemorySource {
228
+ const skipped: Array<[string, string]> = []
229
+ // The prefix stays Claude Code's for --from too: lessons promoted that way
230
+ // before this reader existed carry it, and must still count as promoted.
231
+ const candidates = fromMemoryFiles(dir, 'claude-code-memory', skipped)
232
+ return { assistant, where: dir, candidates, skipped }
233
+ }
234
+
235
+ // ── VS Code (GitHub Copilot Chat) ─────────────────────────────
236
+
237
+ /**
238
+ * VS Code's user data directories on this machine, stable and Insiders, the
239
+ * way VS Code itself finds them: VSCODE_PORTABLE, then VSCODE_APPDATA, then
240
+ * the platform's application data directory.
241
+ */
242
+ export function vscodeUserDirs(): string[] {
243
+ const portable = process.env.VSCODE_PORTABLE
244
+ if (portable) return [join(portable, 'user-data', 'User')]
245
+ const h = home()
246
+ const appData =
247
+ process.env.VSCODE_APPDATA ||
248
+ (process.platform === 'win32'
249
+ ? process.env.APPDATA || join(h, 'AppData', 'Roaming')
250
+ : process.platform === 'darwin'
251
+ ? join(h, 'Library', 'Application Support')
252
+ : process.env.XDG_CONFIG_HOME || join(h, '.config'))
253
+ return ['Code', 'Code - Insiders'].map((product) => join(appData, product, 'User'))
254
+ }
255
+
256
+ /**
257
+ * The repository memory directories VS Code's agents keep for this folder:
258
+ * `workspaceStorage/<hash>/GitHub.copilot-chat/memory-tool/memories/repo/`,
259
+ * where `<hash>/workspace.json` names the folder. A folder opened more than
260
+ * once can have more than one store; a worktree has its own.
261
+ */
262
+ export function vscodeRepoMemoryDirs(projectRoot: string): string[] {
263
+ const roots = [...new Set([projectRoot, mainCheckout(projectRoot)].flatMap(forms))]
264
+ const out: string[] = []
265
+ for (const user of vscodeUserDirs()) {
266
+ const storage = join(user, 'workspaceStorage')
267
+ let hashes: string[]
268
+ try {
269
+ hashes = readdirSync(storage)
270
+ } catch {
271
+ continue
272
+ }
273
+ for (const hash of hashes.sort()) {
274
+ let folder: unknown
275
+ try {
276
+ folder = (JSON.parse(readFileSync(join(storage, hash, 'workspace.json'), 'utf8')) as { folder?: unknown }).folder
277
+ } catch {
278
+ continue
279
+ }
280
+ if (typeof folder !== 'string' || !folder.startsWith('file:')) continue
281
+ let path: string
282
+ try {
283
+ path = fileURLToPath(folder)
284
+ } catch {
285
+ continue
286
+ }
287
+ if (!forms(path).some((p) => roots.includes(p))) continue
288
+ for (const ext of ['GitHub.copilot-chat', 'github.copilot-chat']) {
289
+ const dir = join(storage, hash, ext, 'memory-tool', 'memories', 'repo')
290
+ if (existsSync(dir) && !out.includes(dir)) out.push(dir)
291
+ }
292
+ }
293
+ }
294
+ return out
295
+ }
296
+
297
+ function readVscode(projectRoot: string): MemorySource[] {
298
+ return vscodeRepoMemoryDirs(projectRoot).map((dir) => {
299
+ const skipped: Array<[string, string]> = []
300
+ return { assistant: 'VS Code', where: dir, candidates: fromMemoryFiles(dir, 'vscode-memory', skipped), skipped }
301
+ })
302
+ }
303
+
304
+ // ── Codex ─────────────────────────────────────────────────────
305
+
306
+ /** Codex's consolidated memory files: `memories/MEMORY.md`, and v2's. */
307
+ export function codexMemoryFiles(): string[] {
308
+ const codexHome = process.env.CODEX_HOME || join(home(), '.codex')
309
+ return ['memories', 'memories_v2'].map((d) => join(codexHome, d, 'MEMORY.md')).filter((f) => existsSync(f))
310
+ }
311
+
312
+ /** The `## <name>` section of a block, without its heading. */
313
+ function section(block: string, name: RegExp): string {
314
+ const lines = block.split(/\r?\n/)
315
+ const start = lines.findIndex((l) => /^##\s+/.test(l) && name.test(l.replace(/^##\s+/, '')))
316
+ if (start === -1) return ''
317
+ const end = lines.findIndex((l, i) => i > start && /^##?\s+/.test(l))
318
+ return lines.slice(start + 1, end === -1 ? undefined : end).join('\n').trim()
319
+ }
320
+
321
+ /**
322
+ * Codex keeps one memory for every directory a person works in. Its
323
+ * consolidation writes `# Task Group:` blocks, each with an
324
+ * `applies_to: cwd=<path>` line; a block whose path is this repository, or a
325
+ * directory in it, is this repository's. Of each block, the reusable knowledge
326
+ * and the failures are the team's. The task list points at session logs on
327
+ * one machine, and the user preferences are about one person.
328
+ */
329
+ function readCodexFile(file: string, projectRoot: string): MemorySource {
330
+ const skipped: Array<[string, string]> = []
331
+ const candidates: MemoryCandidate[] = []
332
+ const roots = [...new Set([projectRoot, mainCheckout(projectRoot)].flatMap(forms))]
333
+ const text = readFileSync(file, 'utf8').replace(/^/, '')
334
+ const blocks = text.split(/^(?=# Task Group:)/m).filter((b) => b.startsWith('# Task Group:'))
335
+ for (const block of blocks) {
336
+ const group = /^# Task Group:\s*(.+)$/m.exec(block)?.[1]?.trim() ?? 'Codex memory'
337
+ const appliesTo = /^applies_to:\s*(.*)$/m.exec(block)?.[1] ?? ''
338
+ const cwd = /cwd=\s*((?:~|[A-Za-z]:[\\/]|\/)[^\s;,)]*)/.exec(appliesTo)?.[1]
339
+ if (!cwd || !within(expandHome(cwd), roots)) continue
340
+ const label = `MEMORY.md: ${group}`
341
+ const parts = [
342
+ ['Reusable knowledge', section(block, /^reusable knowledge/i)],
343
+ ['Failures and how to do differently', section(block, /^failures/i)],
344
+ ]
345
+ .map(([heading, body]) => [heading, body.replace(/\s*(?:\[Task \d+\])+/g, '')] as const)
346
+ .filter(([, body]) => body.trim())
347
+ if (parts.length === 0) {
348
+ skipped.push([label, 'no reusable knowledge or failures, only tasks and preferences'])
349
+ continue
350
+ }
351
+ const body = prepare(label, parts.map(([h, b]) => `## ${h}\n\n${b}`).join('\n\n'), skipped)
352
+ if (body === null) continue
353
+ candidates.push({ label, title: asTitle(group), body, source: `codex-memory:${group}#${digest(body)}` })
354
+ }
355
+ return { assistant: 'Codex', where: file, candidates, skipped }
356
+ }
357
+
358
+ function readCodex(projectRoot: string): MemorySource[] {
359
+ return codexMemoryFiles()
360
+ .map((file) => readCodexFile(file, projectRoot))
361
+ .filter((s) => s.candidates.length > 0 || s.skipped.length > 0)
362
+ }
363
+
364
+ // ── All of them ───────────────────────────────────────────────
365
+
366
+ /**
367
+ * Every memory this machine's assistants keep about the repository. Claude
368
+ * Code's is listed even when it is absent, so the caller can say where it
369
+ * looked; the others only when they hold something for this repository.
370
+ */
371
+ export function readRepositoryMemory(projectRoot: string): { sources: MemorySource[]; looked: string[] } {
372
+ const sources: MemorySource[] = []
373
+ const claude = claudeMemoryDir(projectRoot)
374
+ if (existsSync(claude)) sources.push(readMemoryDir(claude, 'Claude Code'))
375
+ sources.push(...readVscode(projectRoot), ...readCodex(projectRoot))
376
+ const looked = [claude, ...vscodeUserDirs().map((d) => join(d, 'workspaceStorage')), ...['memories', 'memories_v2'].map((d) => join(process.env.CODEX_HOME || join(home(), '.codex'), d))]
377
+ return { sources, looked }
378
+ }
379
+
380
+ /** Memories on this machine not yet promoted, by assistant. */
381
+ export function unsharedMemory(projectRoot: string, promoted: Set<string>): Array<{ assistant: string; count: number }> {
382
+ const counts = new Map<string, number>()
383
+ for (const s of readRepositoryMemory(projectRoot).sources) {
384
+ const n = s.candidates.filter((c) => !promoted.has(c.source)).length
385
+ if (n > 0) counts.set(s.assistant, (counts.get(s.assistant) ?? 0) + n)
386
+ }
387
+ return [...counts].map(([assistant, count]) => ({ assistant, count }))
388
+ }
@@ -5,6 +5,7 @@
5
5
  import { execFileSync, spawnSync } from 'node:child_process'
6
6
  import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs'
7
7
  import { tmpdir } from 'node:os'
8
+ import { pathToFileURL } from 'node:url'
8
9
  import { dirname, join, resolve } from 'node:path'
9
10
  import { describe, it, expect, beforeEach, afterEach } from 'vitest'
10
11
  import { claudeMemoryDir } from './promote.js'
@@ -31,7 +32,14 @@ describe.skipIf(!built)('opencastle promote', () => {
31
32
  let home: string
32
33
  let config: string
33
34
  let project: string
34
- const env = (): NodeJS.ProcessEnv => ({ ...process.env, HOME: home, CLAUDE_CONFIG_DIR: config })
35
+ // Every assistant's memory store is the test's own: none of this machine's is read.
36
+ const env = (): NodeJS.ProcessEnv => ({
37
+ ...process.env,
38
+ HOME: home,
39
+ CLAUDE_CONFIG_DIR: config,
40
+ VSCODE_APPDATA: join(home, 'vscode'),
41
+ CODEX_HOME: join(home, '.codex'),
42
+ })
35
43
  const run = (cwd: string, ...args: string[]) => {
36
44
  const r = spawnSync('node', [cli, ...args], { cwd, encoding: 'utf8', env: env() })
37
45
  // eslint-disable-next-line no-control-regex
@@ -169,10 +177,104 @@ describe.skipIf(!built)('opencastle promote', () => {
169
177
  expect(out.stdout).toContain('from ~/my-memory')
170
178
  })
171
179
 
172
- it('says where it looked when there is none', () => {
180
+ it('says where it looked when there is none, and why Cursor and Copilot Memory are not among them', () => {
173
181
  const out = run(project, 'promote', 'memory')
174
182
  expect(out.status).toBe(1)
175
183
  expect(out.stderr).toMatch(/no memory at ~\/\.claude\/projects\/.*\/memory/)
184
+ expect(out.stderr).toContain('Cursor keeps its memories on its servers')
185
+ })
186
+
187
+ it('reads VS Code’s repository memory for this folder, and no other folder’s or the user’s', () => {
188
+ const storage = join(home, 'vscode', 'Code', 'User', 'workspaceStorage')
189
+ write(join(storage, 'a1b2c3'), {
190
+ 'workspace.json': JSON.stringify({ folder: pathToFileURL(project).href }),
191
+ 'GitHub.copilot-chat/memory-tool/memories/repo/build.md': '# Build with pnpm\n\n- `pnpm build`, never `npm run build`: the lockfile is pnpm’s.\n',
192
+ 'GitHub.copilot-chat/memory-tool/memories/c2Vzc2lvbg==/scratch.md': '# This conversation only\n',
193
+ })
194
+ write(join(storage, 'ffffff'), {
195
+ 'workspace.json': JSON.stringify({ folder: pathToFileURL(join(root, 'other')).href }),
196
+ 'GitHub.copilot-chat/memory-tool/memories/repo/other.md': '# Another repository\n',
197
+ })
198
+ write(join(home, 'vscode', 'Code', 'User', 'globalStorage', 'github.copilot-chat', 'memory-tool', 'memories'), {
199
+ 'me.md': '# I like short answers\n',
200
+ })
201
+ const out = run(project, 'promote', 'memory')
202
+ expect(out.status, out.stderr).toBe(0)
203
+ expect(out.stdout).toMatch(/VS Code from .*a1b2c3/)
204
+ const files = readdirSync(join(project, '.opencastle', 'lessons'))
205
+ expect(files).toHaveLength(1)
206
+ const text = readFileSync(join(project, '.opencastle', 'lessons', files[0]), 'utf8')
207
+ expect(text).toContain('title: "Build with pnpm"')
208
+ expect(text).toContain('`pnpm build`, never `npm run build`')
209
+ expect(text).not.toContain('# Build with pnpm')
210
+ expect(text).toMatch(/source: "vscode-memory:build\.md#[0-9a-f]{12}"/)
211
+ expect(run(project, 'promote', 'memory').stdout).toContain('build.md: already a lesson')
212
+ })
213
+
214
+ it('takes from Codex only the blocks whose directory is this repository, and only what the team can use', () => {
215
+ write(join(home, '.codex', 'memories'), {
216
+ 'MEMORY.md': [
217
+ '# Task Group: app test runs',
218
+ '',
219
+ `scope: running the app's tests`,
220
+ `applies_to: cwd=${project}/src; reuse_rule=safe while the test runner is vitest`,
221
+ '',
222
+ '## Task 1: ran the tests, passed',
223
+ '',
224
+ '### rollout_summary_files',
225
+ '',
226
+ `- rollout_summaries/2026-10-01-ab12-tests.md (cwd=${project}, rollout_path=${home}/.codex/sessions/x.jsonl)`,
227
+ '',
228
+ '## User preferences',
229
+ '',
230
+ '- the user asked for terse answers [Task 1]',
231
+ '',
232
+ '## Reusable knowledge',
233
+ '',
234
+ '- Run `npx vitest run --pool=forks`; threads hang on the native module [Task 1]',
235
+ '',
236
+ '## Failures and how to do differently',
237
+ '',
238
+ '- `npm test` without a build fails on missing dist/ -> build first [Task 1]',
239
+ '',
240
+ '# Task Group: another repository',
241
+ '',
242
+ 'scope: elsewhere',
243
+ 'applies_to: cwd=/srv/elsewhere; reuse_rule=never here',
244
+ '',
245
+ '## Reusable knowledge',
246
+ '',
247
+ '- Not this repository',
248
+ '',
249
+ ].join('\n'),
250
+ })
251
+ const out = run(project, 'promote', 'memory')
252
+ expect(out.status, out.stderr).toBe(0)
253
+ expect(out.stdout).toMatch(/Codex from ~\/\.codex\/memories\/MEMORY\.md/)
254
+ const files = readdirSync(join(project, '.opencastle', 'lessons'))
255
+ expect(files).toHaveLength(1)
256
+ const text = readFileSync(join(project, '.opencastle', 'lessons', files[0]), 'utf8')
257
+ expect(text).toContain('title: "App test runs"')
258
+ expect(text).toContain('## Reusable knowledge')
259
+ expect(text).toContain('threads hang on the native module')
260
+ expect(text).toContain('## Failures and how to do differently')
261
+ expect(text).not.toContain('terse answers')
262
+ expect(text).not.toContain('rollout_summary_files')
263
+ expect(text).not.toContain('[Task 1]')
264
+ expect(text).not.toContain('Not this repository')
265
+ expect(text).toMatch(/source: "codex-memory:app test runs#[0-9a-f]{12}"/)
266
+ })
267
+
268
+ it('the status screen says how much this machine has not shared, until it is promoted', () => {
269
+ write(memoryDir(), { 'a.md': memory('quote-paths', 'feedback', 'Quote paths with spaces.') })
270
+ const before = run(project)
271
+ expect(before.stdout).toContain('1 memory on this machine the team has not got yet (Claude Code 1)')
272
+ expect(before.stdout).toContain('npx opencastle promote memory')
273
+ expect(before.stdout).toContain('Everything is current')
274
+ expect(JSON.parse(run(project, '--json').stdout).unsharedMemories).toEqual([{ assistant: 'Claude Code', count: 1 }])
275
+ expect(run(project, 'promote', 'memory').status).toBe(0)
276
+ const after = run(project)
277
+ expect(after.stdout).not.toContain('the team has not got yet')
176
278
  })
177
279
  })
178
280
  })