@@ -300,57 +300,60 @@ char *cbm_client_adapter_opencode(const char *binary_path) {
300300 " });\n"
301301 "}\n\n" );
302302
303- sb_append (& sb ,
304- "export const CodebaseMemory = async (ctx) => {\n"
305- " const dir = ctx?.directory;\n"
306- " const seen = new Set();\n"
307- " const lifecycle = () =>\n"
308- " augment({ hook_event_name: 'SessionStart', cwd: dir });\n"
309- " return {\n"
310- " 'tool.execute.after': async (input, output) => {\n"
311- " if (typeof output?.output !== 'string') return;\n"
312- " const pieces = [];\n"
313- " const sid = input?.sessionID;\n"
314- " if (typeof sid === 'string' && !seen.has(sid)) {\n"
315- " seen.add(sid);\n"
316- " pieces.push(await lifecycle());\n"
317- " }\n"
318- " const args = input?.args ?? {};\n"
319- " const search =\n"
320- " input?.tool === 'grep' ? 'Grep' : input?.tool === 'glob' ? 'Glob' : null;\n"
321- " if (search) {\n"
322- " pieces.push(await augment({\n"
323- " hook_event_name: 'PreToolUse',\n"
324- " tool_name: search,\n"
325- " tool_input: args,\n"
326- " cwd: dir,\n"
327- " }));\n"
328- " } else if (input?.tool === 'read') {\n"
329- " const filePath = args.filePath ?? args.file_path ?? args.path;\n"
330- " if (typeof filePath === 'string' && filePath) {\n"
331- " pieces.push(await augment({\n"
332- " hook_event_name: 'PostToolUse',\n"
333- " tool_name: 'Read',\n"
334- " tool_input: { file_path: filePath },\n"
335- " cwd: dir,\n"
336- " }));\n"
337- " }\n"
338- " }\n"
339- " const extra = pieces.filter(Boolean).join('\\n');\n"
340- " if (extra) {\n"
341- " output.output += '\\n' + extra;\n"
342- " }\n"
343- " },\n"
344- " // Documented (experimental) compaction surface: output.context is the\n"
345- " // mutable array of context strings for the rebuilt session.\n"
346- " 'experimental.session.compacting': async (_input, output) => {\n"
347- " const note = await lifecycle();\n"
348- " if (note && Array.isArray(output?.context)) {\n"
349- " output.context.push(note);\n"
350- " }\n"
351- " },\n"
352- " };\n"
353- "};\n" );
303+ sb_append (
304+ & sb , "export default {\n"
305+ " id: 'codebase-memory-augment',\n"
306+ " async setup(ctx) {\n"
307+ " const dir = ctx?.directory;\n"
308+ " const seen = new Set();\n"
309+ " const lifecycle = () =>\n"
310+ " augment({ hook_event_name: 'SessionStart', cwd: dir });\n"
311+ " return {\n"
312+ " 'tool.execute.after': async (input, output) => {\n"
313+ " if (typeof output?.output !== 'string') return;\n"
314+ " const pieces = [];\n"
315+ " const sid = input?.sessionID;\n"
316+ " if (typeof sid === 'string' && !seen.has(sid)) {\n"
317+ " seen.add(sid);\n"
318+ " pieces.push(await lifecycle());\n"
319+ " }\n"
320+ " const args = input?.args ?? {};\n"
321+ " const search =\n"
322+ " input?.tool === 'grep' ? 'Grep' : input?.tool === 'glob' ? 'Glob' : null;\n"
323+ " if (search) {\n"
324+ " pieces.push(await augment({\n"
325+ " hook_event_name: 'PreToolUse',\n"
326+ " tool_name: search,\n"
327+ " tool_input: args,\n"
328+ " cwd: dir,\n"
329+ " }));\n"
330+ " } else if (input?.tool === 'read') {\n"
331+ " const filePath = args.filePath ?? args.file_path ?? args.path;\n"
332+ " if (typeof filePath === 'string' && filePath) {\n"
333+ " pieces.push(await augment({\n"
334+ " hook_event_name: 'PostToolUse',\n"
335+ " tool_name: 'Read',\n"
336+ " tool_input: { file_path: filePath },\n"
337+ " cwd: dir,\n"
338+ " }));\n"
339+ " }\n"
340+ " }\n"
341+ " const extra = pieces.filter(Boolean).join('\\n');\n"
342+ " if (extra) {\n"
343+ " output.output += '\\n' + extra;\n"
344+ " }\n"
345+ " },\n"
346+ " // Documented (experimental) compaction surface: output.context is the\n"
347+ " // mutable array of context strings for the rebuilt session.\n"
348+ " 'experimental.session.compacting': async (_input, output) => {\n"
349+ " const note = await lifecycle();\n"
350+ " if (note && Array.isArray(output?.context)) {\n"
351+ " output.context.push(note);\n"
352+ " }\n"
353+ " },\n"
354+ " };\n"
355+ " },\n"
356+ "};\n" );
354357
355358 if (sb .failed ) {
356359 free (sb .buf );
0 commit comments