@cleocode/adapters 2026.4.39 → 2026.4.40

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.
@@ -150,17 +150,18 @@ export class ClaudeCodeHookProvider implements AdapterHookProvider {
150
150
  const hooks = (settings.hooks ?? {}) as Record<string, unknown[]>;
151
151
 
152
152
  // Check if CLEO hooks already registered (look for our marker comment in commands)
153
- const alreadyRegistered = Object.values(hooks).some((entries) =>
154
- Array.isArray(entries) &&
155
- entries.some(
156
- (e) =>
157
- typeof e === 'object' &&
158
- e !== null &&
159
- Array.isArray((e as Record<string, unknown>).hooks) &&
160
- ((e as Record<string, unknown>).hooks as Array<Record<string, string>>).some(
161
- (h) => typeof h.command === 'string' && h.command.includes('# cleo-hook'),
162
- ),
163
- ),
153
+ const alreadyRegistered = Object.values(hooks).some(
154
+ (entries) =>
155
+ Array.isArray(entries) &&
156
+ entries.some(
157
+ (e) =>
158
+ typeof e === 'object' &&
159
+ e !== null &&
160
+ Array.isArray((e as Record<string, unknown>).hooks) &&
161
+ ((e as Record<string, unknown>).hooks as Array<Record<string, string>>).some(
162
+ (h) => typeof h.command === 'string' && h.command.includes('# cleo-hook'),
163
+ ),
164
+ ),
164
165
  );
165
166
 
166
167
  if (alreadyRegistered) {
@@ -74,8 +74,22 @@ export class ClaudeCodeSpawnProvider implements AdapterSpawnProvider {
74
74
  let tmpFile: string | undefined;
75
75
 
76
76
  try {
77
+ // Enrich prompt with CANT bundle, memory bridge, and mental model (T555).
78
+ // Best-effort: if CANT context is unavailable, the raw prompt is used.
79
+ let enrichedPrompt = context.prompt;
80
+ try {
81
+ const { buildCantEnrichedPrompt } = await import('../../cant-context.js');
82
+ enrichedPrompt = await buildCantEnrichedPrompt({
83
+ projectDir: context.workingDirectory ?? process.cwd(),
84
+ basePrompt: context.prompt,
85
+ agentName: (context.options?.agentName as string) ?? undefined,
86
+ });
87
+ } catch {
88
+ // CANT enrichment unavailable — use raw prompt
89
+ }
90
+
77
91
  tmpFile = `/tmp/claude-spawn-${instanceId}.txt`;
78
- await writeFile(tmpFile, context.prompt, 'utf-8');
92
+ await writeFile(tmpFile, enrichedPrompt, 'utf-8');
79
93
 
80
94
  const args = ['--allow-insecure', '--no-upgrade-check', tmpFile];
81
95
  const spawnOpts: Parameters<typeof nodeSpawn>[2] = {
@@ -80,18 +80,23 @@ export function buildOpenCodeAgentMarkdown(description: string, instructions: st
80
80
  * @param workingDirectory - Project root directory
81
81
  * @returns The agent name to use for spawning
82
82
  */
83
- async function ensureSubagentDefinition(workingDirectory: string): Promise<string> {
83
+ async function ensureSubagentDefinition(
84
+ workingDirectory: string,
85
+ enrichedInstructions?: string,
86
+ ): Promise<string> {
84
87
  const agentDir = join(workingDirectory, '.opencode', 'agent');
85
88
  const agentPath = join(agentDir, `${OPENCODE_SUBAGENT_NAME}.md`);
86
- const description = 'CLEO task executor with protocol compliance.';
87
- const instructions = [
88
- '# CLEO Subagent',
89
- '',
90
- 'You are a CLEO subagent executing a delegated task.',
91
- 'Follow the CLEO protocol and complete the assigned work.',
92
- '',
93
- '@~/.cleo/templates/CLEO-INJECTION.md',
94
- ].join('\n');
89
+ const description = 'CLEO task executor with protocol compliance and CANT context.';
90
+ const instructions =
91
+ enrichedInstructions ??
92
+ [
93
+ '# CLEO Subagent',
94
+ '',
95
+ 'You are a CLEO subagent executing a delegated task.',
96
+ 'Follow the CLEO protocol and complete the assigned work.',
97
+ '',
98
+ '@~/.cleo/templates/CLEO-INJECTION.md',
99
+ ].join('\n');
95
100
 
96
101
  const content = buildOpenCodeAgentMarkdown(description, instructions);
97
102
 
@@ -160,9 +165,23 @@ export class OpenCodeSpawnProvider implements AdapterSpawnProvider {
160
165
  const workingDirectory = context.workingDirectory ?? process.cwd();
161
166
 
162
167
  try {
168
+ // Enrich prompt with CANT bundle, memory bridge, and mental model (T555).
169
+ // Best-effort: if CANT context is unavailable, the raw prompt is used.
170
+ let enrichedInstructions: string | undefined;
171
+ try {
172
+ const { buildCantEnrichedPrompt } = await import('../../cant-context.js');
173
+ enrichedInstructions = await buildCantEnrichedPrompt({
174
+ projectDir: workingDirectory,
175
+ basePrompt: context.prompt,
176
+ agentName: (context.options?.agentName as string) ?? undefined,
177
+ });
178
+ } catch {
179
+ // CANT enrichment unavailable — use raw prompt
180
+ }
181
+
163
182
  let agentName: string;
164
183
  try {
165
- agentName = await ensureSubagentDefinition(workingDirectory);
184
+ agentName = await ensureSubagentDefinition(workingDirectory, enrichedInstructions);
166
185
  } catch {
167
186
  agentName = OPENCODE_FALLBACK_AGENT;
168
187
  }