@cleocode/adapters 2026.4.38 → 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.
package/dist/index.js CHANGED
@@ -8,9 +8,174 @@ var __export = (target, all) => {
8
8
  __defProp(target, name, { get: all[name], enumerable: true });
9
9
  };
10
10
 
11
- // packages/adapters/src/providers/claude-code/paths.ts
11
+ // packages/adapters/src/cant-context.ts
12
+ var cant_context_exports = {};
13
+ __export(cant_context_exports, {
14
+ buildCantEnrichedPrompt: () => buildCantEnrichedPrompt,
15
+ buildMemoryBridgeBlock: () => buildMemoryBridgeBlock,
16
+ buildMentalModelInjection: () => buildMentalModelInjection,
17
+ discoverCantFiles: () => discoverCantFiles,
18
+ discoverCantFilesMultiTier: () => discoverCantFilesMultiTier,
19
+ readMemoryBridge: () => readMemoryBridge,
20
+ resolveThreeTierPaths: () => resolveThreeTierPaths
21
+ });
22
+ import { existsSync, readdirSync, readFileSync } from "node:fs";
12
23
  import { homedir } from "node:os";
13
- import { join } from "node:path";
24
+ import { basename, join } from "node:path";
25
+ function discoverCantFiles(dir) {
26
+ try {
27
+ const entries = readdirSync(dir, { recursive: true, withFileTypes: true });
28
+ const files = [];
29
+ for (const entry of entries) {
30
+ if (entry.isFile() && entry.name.endsWith(".cant")) {
31
+ const parent = entry.parentPath ?? dir;
32
+ files.push(join(parent, entry.name));
33
+ }
34
+ }
35
+ return files;
36
+ } catch {
37
+ return [];
38
+ }
39
+ }
40
+ function resolveThreeTierPaths(projectDir) {
41
+ const home = homedir();
42
+ const xdgData = process.env["XDG_DATA_HOME"] ?? join(home, ".local", "share");
43
+ const xdgConfig = process.env["XDG_CONFIG_HOME"] ?? join(home, ".config");
44
+ return {
45
+ global: join(xdgData, "cleo", "cant"),
46
+ user: join(xdgConfig, "cleo", "cant"),
47
+ project: join(projectDir, ".cleo", "cant")
48
+ };
49
+ }
50
+ function discoverCantFilesMultiTier(projectDir) {
51
+ const paths = resolveThreeTierPaths(projectDir);
52
+ const globalFiles = discoverCantFiles(paths.global);
53
+ const userFiles = discoverCantFiles(paths.user);
54
+ const projectFiles = discoverCantFiles(paths.project);
55
+ const fileMap = /* @__PURE__ */ new Map();
56
+ for (const file of globalFiles) {
57
+ fileMap.set(basename(file), file);
58
+ }
59
+ for (const file of userFiles) {
60
+ fileMap.set(basename(file), file);
61
+ }
62
+ for (const file of projectFiles) {
63
+ fileMap.set(basename(file), file);
64
+ }
65
+ const totalUniqueInputs = globalFiles.length + userFiles.length + projectFiles.length;
66
+ const overrides = totalUniqueInputs - fileMap.size;
67
+ return {
68
+ files: Array.from(fileMap.values()),
69
+ stats: {
70
+ global: globalFiles.length,
71
+ user: userFiles.length,
72
+ project: projectFiles.length,
73
+ overrides,
74
+ merged: fileMap.size
75
+ }
76
+ };
77
+ }
78
+ function readMemoryBridge(projectDir) {
79
+ try {
80
+ const bridgePath = join(projectDir, ".cleo", "memory-bridge.md");
81
+ if (!existsSync(bridgePath)) return null;
82
+ const content = readFileSync(bridgePath, "utf-8");
83
+ return content.length > 0 ? content : null;
84
+ } catch {
85
+ return null;
86
+ }
87
+ }
88
+ function buildMemoryBridgeBlock(content) {
89
+ return "\n\n===== CLEO MEMORY BRIDGE =====\nThis is your project memory context from .cleo/memory-bridge.md.\nUse it to understand recent decisions, handoff notes, and key patterns.\n\n" + content.trim() + "\n===== END MEMORY BRIDGE =====";
90
+ }
91
+ function buildMentalModelInjection(agentName, observations) {
92
+ if (observations.length === 0) return "";
93
+ const lines = ["", `// Agent: ${agentName}`, VALIDATE_ON_LOAD_PREAMBLE, ""];
94
+ for (let i = 0; i < observations.length; i++) {
95
+ const obs = observations[i];
96
+ const datePart = obs.date ? ` [${obs.date}]` : "";
97
+ lines.push(`${i + 1}. [${obs.id}] (${obs.type})${datePart}: ${obs.title}`);
98
+ }
99
+ lines.push("===== END MENTAL MODEL =====");
100
+ return lines.join("\n");
101
+ }
102
+ async function fetchMentalModelInjection(agentName, projectRoot) {
103
+ try {
104
+ const coreModule = await import(
105
+ /* webpackIgnore: true */
106
+ "@cleocode/core"
107
+ );
108
+ if (typeof coreModule.memoryFind !== "function") return "";
109
+ const result = await coreModule.memoryFind(
110
+ {
111
+ query: agentName,
112
+ agent: agentName,
113
+ limit: 10,
114
+ tables: ["observations"]
115
+ },
116
+ projectRoot
117
+ );
118
+ if (!result.success || !result.data?.results?.length) return "";
119
+ return buildMentalModelInjection(agentName, result.data.results);
120
+ } catch {
121
+ return "";
122
+ }
123
+ }
124
+ async function buildCantEnrichedPrompt(options) {
125
+ const { projectDir, basePrompt, agentName } = options;
126
+ let appendix = "";
127
+ try {
128
+ const { files } = discoverCantFilesMultiTier(projectDir);
129
+ if (files.length > 0) {
130
+ const cantModule = await import(
131
+ /* webpackIgnore: true */
132
+ "@cleocode/cant"
133
+ );
134
+ if (typeof cantModule.compileBundle === "function") {
135
+ const bundle = cantModule.compileBundle(files);
136
+ if (bundle.valid) {
137
+ const rendered = bundle.renderSystemPrompt();
138
+ if (rendered) {
139
+ appendix += `
140
+
141
+ ${rendered}`;
142
+ }
143
+ }
144
+ }
145
+ }
146
+ } catch {
147
+ }
148
+ try {
149
+ const bridge = readMemoryBridge(projectDir);
150
+ if (bridge) {
151
+ appendix += buildMemoryBridgeBlock(bridge);
152
+ }
153
+ } catch {
154
+ }
155
+ if (agentName) {
156
+ try {
157
+ const mentalModel = await fetchMentalModelInjection(agentName, projectDir);
158
+ if (mentalModel) {
159
+ appendix += `
160
+
161
+ ${mentalModel}`;
162
+ }
163
+ } catch {
164
+ }
165
+ }
166
+ return appendix ? basePrompt + appendix : basePrompt;
167
+ }
168
+ var VALIDATE_ON_LOAD_PREAMBLE;
169
+ var init_cant_context = __esm({
170
+ "packages/adapters/src/cant-context.ts"() {
171
+ "use strict";
172
+ VALIDATE_ON_LOAD_PREAMBLE = "===== MENTAL MODEL (validate-on-load) =====\nThese are your prior observations, patterns, and learnings for this project.\nBefore acting, you MUST re-evaluate each entry against current project state.\nIf an entry is stale, note it and proceed with fresh understanding.";
173
+ }
174
+ });
175
+
176
+ // packages/adapters/src/providers/claude-code/paths.ts
177
+ import { homedir as homedir2 } from "node:os";
178
+ import { join as join2 } from "node:path";
14
179
  var ClaudeCodePathProvider;
15
180
  var init_paths = __esm({
16
181
  "packages/adapters/src/providers/claude-code/paths.ts"() {
@@ -18,29 +183,29 @@ var init_paths = __esm({
18
183
  ClaudeCodePathProvider = class {
19
184
  /** Get the provider's root configuration directory. */
20
185
  getProviderDir() {
21
- return process.env["CLAUDE_HOME"] ?? join(homedir(), ".claude");
186
+ return process.env["CLAUDE_HOME"] ?? join2(homedir2(), ".claude");
22
187
  }
23
188
  /** Get the path to the provider's settings file, or null if unavailable. */
24
189
  getSettingsPath() {
25
- return process.env["CLAUDE_SETTINGS"] ?? join(this.getProviderDir(), "settings.json");
190
+ return process.env["CLAUDE_SETTINGS"] ?? join2(this.getProviderDir(), "settings.json");
26
191
  }
27
192
  /** Get the directory where agents are installed, or null if unsupported. */
28
193
  getAgentInstallDir() {
29
- return join(this.getProviderDir(), "agents");
194
+ return join2(this.getProviderDir(), "agents");
30
195
  }
31
196
  /** Get the path to the provider's memory database, or null if unsupported. */
32
197
  getMemoryDbPath() {
33
- return process.env["CLAUDE_MEM_DB"] ?? join(homedir(), ".claude-mem", "claude-mem.db");
198
+ return process.env["CLAUDE_MEM_DB"] ?? join2(homedir2(), ".claude-mem", "claude-mem.db");
34
199
  }
35
200
  };
36
201
  }
37
202
  });
38
203
 
39
204
  // packages/adapters/src/providers/claude-code/context-monitor.ts
40
- import { existsSync, readFileSync, writeFileSync } from "node:fs";
205
+ import { existsSync as existsSync2, readFileSync as readFileSync2, writeFileSync } from "node:fs";
41
206
  import { mkdir } from "node:fs/promises";
42
- import { homedir as homedir2 } from "node:os";
43
- import { dirname, join as join2 } from "node:path";
207
+ import { homedir as homedir3 } from "node:os";
208
+ import { dirname, join as join3 } from "node:path";
44
209
  function getContextStatusFromPercentage(percentage) {
45
210
  if (percentage >= THRESHOLDS.EMERGENCY) return "emergency";
46
211
  if (percentage >= THRESHOLDS.CRITICAL) return "critical";
@@ -74,10 +239,10 @@ var init_context_monitor = __esm({
74
239
  const totalTokens = inputTokens + outputTokens + cacheCreate;
75
240
  const percentage = Math.floor(totalTokens * 100 / contextSize);
76
241
  const status = getContextStatusFromPercentage(percentage);
77
- const cleoDir = cwd ? join2(cwd, ".cleo") : ".cleo";
78
- if (existsSync(cleoDir)) {
79
- const stateDir = join2(cleoDir, "context-states");
80
- const statePath = join2(stateDir, ".context-state.json");
242
+ const cleoDir = cwd ? join3(cwd, ".cleo") : ".cleo";
243
+ if (existsSync2(cleoDir)) {
244
+ const stateDir = join3(cleoDir, "context-states");
245
+ const statePath = join3(stateDir, ".context-state.json");
81
246
  const state = {
82
247
  $schema: "https://cleo-dev.com/schemas/v1/context-state.schema.json",
83
248
  version: "1.0.0",
@@ -114,9 +279,9 @@ var init_context_monitor = __esm({
114
279
  /** Check the current statusline integration status in Claude Code settings. */
115
280
  checkStatuslineIntegration() {
116
281
  const settingsPath = this.pathProvider.getSettingsPath();
117
- if (!settingsPath || !existsSync(settingsPath)) return "no_settings";
282
+ if (!settingsPath || !existsSync2(settingsPath)) return "no_settings";
118
283
  try {
119
- const settings = JSON.parse(readFileSync(settingsPath, "utf-8"));
284
+ const settings = JSON.parse(readFileSync2(settingsPath, "utf-8"));
120
285
  const statusLine = settings.statusLine;
121
286
  if (!statusLine?.type) return "not_configured";
122
287
  if (statusLine.type !== "command") return "custom_no_cleo";
@@ -124,10 +289,10 @@ var init_context_monitor = __esm({
124
289
  if (cmd.includes("context-monitor.sh") || cmd.includes("cleo-statusline") || cmd.includes(".context-state.json") || cmd.includes("context-states")) {
125
290
  return "configured";
126
291
  }
127
- const scriptPath = cmd.startsWith("~") ? cmd.replace("~", homedir2()) : cmd;
128
- if (existsSync(scriptPath)) {
292
+ const scriptPath = cmd.startsWith("~") ? cmd.replace("~", homedir3()) : cmd;
293
+ if (existsSync2(scriptPath)) {
129
294
  try {
130
- const content = readFileSync(scriptPath, "utf-8");
295
+ const content = readFileSync2(scriptPath, "utf-8");
131
296
  if (content.includes("context-state.json")) return "configured";
132
297
  } catch {
133
298
  }
@@ -142,7 +307,7 @@ var init_context_monitor = __esm({
142
307
  return {
143
308
  statusLine: {
144
309
  type: "command",
145
- command: join2(homedir2(), ".cleo", "lib", "session", "context-monitor.sh")
310
+ command: join3(homedir3(), ".cleo", "lib", "session", "context-monitor.sh")
146
311
  }
147
312
  };
148
313
  }
@@ -163,8 +328,10 @@ var init_context_monitor = __esm({
163
328
  });
164
329
 
165
330
  // packages/adapters/src/providers/claude-code/hooks.ts
331
+ import { existsSync as existsSync3, mkdirSync, readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "node:fs";
166
332
  import { readdir, readFile } from "node:fs/promises";
167
- import { join as join3 } from "node:path";
333
+ import { homedir as homedir4 } from "node:os";
334
+ import { join as join4 } from "node:path";
168
335
  var PROVIDER_ID, CLAUDE_CODE_EVENT_MAP, ClaudeCodeHookProvider;
169
336
  var init_hooks = __esm({
170
337
  "packages/adapters/src/providers/claude-code/hooks.ts"() {
@@ -218,32 +385,112 @@ var init_hooks = __esm({
218
385
  mapProviderEvent(providerEvent) {
219
386
  return CLAUDE_CODE_EVENT_MAP[providerEvent] ?? null;
220
387
  }
388
+ /** Project directory this hook provider was registered for. */
389
+ projectDir = null;
221
390
  /**
222
391
  * Register native hooks for a project.
223
392
  *
224
- * For Claude Code, hooks are registered via the config system
225
- * (`~/.claude/settings.json`), managed by the install provider.
226
- * This method marks hooks as registered without performing filesystem operations.
393
+ * Writes CLEO hook entries to `~/.claude/settings.json` so that Claude Code's
394
+ * native event system calls cleo CLI commands when events fire. This bridges
395
+ * Claude Code's event loop to CLEO's internal hook dispatch.
227
396
  *
228
- * Iterating supported events is handled at install time using
229
- * `getSupportedCanonicalEvents()` to enumerate all 14 supported hooks.
397
+ * Idempotent: skips writing if CLEO hooks already exist in settings.json.
230
398
  *
231
- * @param _projectDir - Project directory (unused; Claude Code uses global config)
232
- * @task T164
399
+ * Hook entries registered:
400
+ * - `Stop` → `cleo session end --quiet` (triggers LLM extraction, reflector, consolidation)
401
+ * - `PostToolUse` (Write|Edit) → brain observation for file modifications
402
+ * - `SubagentStop` → brain observation for agent completion
403
+ *
404
+ * @param projectDir - Project directory for context-scoped hook commands
405
+ * @task T164 @task T555
233
406
  */
234
- async registerNativeHooks(_projectDir) {
407
+ async registerNativeHooks(projectDir) {
408
+ this.projectDir = projectDir;
235
409
  this.registered = true;
410
+ try {
411
+ const home = homedir4();
412
+ const settingsPath = join4(home, ".claude", "settings.json");
413
+ let settings = {};
414
+ if (existsSync3(settingsPath)) {
415
+ try {
416
+ settings = JSON.parse(readFileSync3(settingsPath, "utf-8"));
417
+ } catch {
418
+ }
419
+ }
420
+ const hooks = settings.hooks ?? {};
421
+ const alreadyRegistered = Object.values(hooks).some(
422
+ (entries) => Array.isArray(entries) && entries.some(
423
+ (e) => typeof e === "object" && e !== null && Array.isArray(e.hooks) && e.hooks.some(
424
+ (h) => typeof h.command === "string" && h.command.includes("# cleo-hook")
425
+ )
426
+ )
427
+ );
428
+ if (alreadyRegistered) {
429
+ return;
430
+ }
431
+ if (!hooks.Stop) hooks.Stop = [];
432
+ hooks.Stop.push({
433
+ matcher: "",
434
+ hooks: [
435
+ {
436
+ type: "command",
437
+ command: `cleo session end --quiet # cleo-hook`
438
+ }
439
+ ]
440
+ });
441
+ if (!hooks.PostToolUse) hooks.PostToolUse = [];
442
+ hooks.PostToolUse.push({
443
+ matcher: "Write|Edit",
444
+ hooks: [
445
+ {
446
+ type: "command",
447
+ command: `cleo observe "File modified via $TOOL_NAME" --title "tool-use" --quiet # cleo-hook`
448
+ }
449
+ ]
450
+ });
451
+ settings.hooks = hooks;
452
+ mkdirSync(join4(home, ".claude"), { recursive: true });
453
+ writeFileSync2(settingsPath, JSON.stringify(settings, null, 2) + "\n", "utf-8");
454
+ } catch {
455
+ }
236
456
  }
237
457
  /**
238
458
  * Unregister native hooks.
239
459
  *
240
- * For Claude Code, this is a no-op since hooks are managed through the config
241
- * system. Unregistration happens via the install provider's uninstall method.
460
+ * Removes CLEO hook entries from `~/.claude/settings.json` by filtering out
461
+ * entries containing the `# cleo-hook` marker.
242
462
  *
243
- * @task T164
463
+ * @task T164 @task T555
244
464
  */
245
465
  async unregisterNativeHooks() {
246
466
  this.registered = false;
467
+ this.projectDir = null;
468
+ try {
469
+ const home = homedir4();
470
+ const settingsPath = join4(home, ".claude", "settings.json");
471
+ if (!existsSync3(settingsPath)) return;
472
+ const settings = JSON.parse(readFileSync3(settingsPath, "utf-8"));
473
+ const hooks = settings.hooks;
474
+ if (!hooks) return;
475
+ let changed = false;
476
+ for (const [event, entries] of Object.entries(hooks)) {
477
+ if (!Array.isArray(entries)) continue;
478
+ const filtered = entries.filter(
479
+ (e) => !(typeof e === "object" && e !== null && Array.isArray(e.hooks) && e.hooks.some(
480
+ (h) => typeof h.command === "string" && h.command.includes("# cleo-hook")
481
+ ))
482
+ );
483
+ if (filtered.length !== entries.length) {
484
+ hooks[event] = filtered;
485
+ changed = true;
486
+ }
487
+ }
488
+ if (changed) {
489
+ settings.hooks = hooks;
490
+ writeFileSync2(settingsPath, JSON.stringify(settings, null, 2) + "\n", "utf-8");
491
+ }
492
+ } catch {
493
+ }
247
494
  }
248
495
  /**
249
496
  * Check whether hooks have been registered via `registerNativeHooks`.
@@ -251,6 +498,14 @@ var init_hooks = __esm({
251
498
  isRegistered() {
252
499
  return this.registered;
253
500
  }
501
+ /**
502
+ * Get the project directory this hook provider was registered for.
503
+ *
504
+ * Returns null if hooks have not been registered yet.
505
+ */
506
+ getProjectDir() {
507
+ return this.projectDir;
508
+ }
254
509
  /**
255
510
  * Get the native→canonical event mapping for introspection and debugging.
256
511
  *
@@ -337,18 +592,18 @@ var init_hooks = __esm({
337
592
  async getTranscript(_sessionId, _projectDir) {
338
593
  try {
339
594
  const homeDir = process.env.HOME ?? process.env.USERPROFILE ?? "/root";
340
- const projectsDir = join3(homeDir, ".claude", "projects");
595
+ const projectsDir = join4(homeDir, ".claude", "projects");
341
596
  let allFiles = [];
342
597
  try {
343
598
  const projectDirs = await readdir(projectsDir, { withFileTypes: true });
344
599
  for (const entry of projectDirs) {
345
600
  if (!entry.isDirectory()) continue;
346
- const subDir = join3(projectsDir, entry.name);
601
+ const subDir = join4(projectsDir, entry.name);
347
602
  try {
348
603
  const files = await readdir(subDir);
349
604
  for (const file of files) {
350
605
  if (!file.endsWith(".jsonl")) continue;
351
- const filePath = join3(subDir, file);
606
+ const filePath = join4(subDir, file);
352
607
  allFiles.push({ path: filePath, mtime: 0 });
353
608
  }
354
609
  } catch {
@@ -389,18 +644,18 @@ var init_hooks = __esm({
389
644
  // packages/adapters/src/providers/claude-code/install.ts
390
645
  import {
391
646
  copyFileSync,
392
- existsSync as existsSync2,
393
- mkdirSync,
394
- readdirSync,
395
- readFileSync as readFileSync2,
396
- writeFileSync as writeFileSync2
647
+ existsSync as existsSync4,
648
+ mkdirSync as mkdirSync2,
649
+ readdirSync as readdirSync2,
650
+ readFileSync as readFileSync4,
651
+ writeFileSync as writeFileSync3
397
652
  } from "node:fs";
398
- import { homedir as homedir3 } from "node:os";
399
- import { dirname as dirname2, join as join4 } from "node:path";
653
+ import { homedir as homedir5 } from "node:os";
654
+ import { dirname as dirname2, join as join5 } from "node:path";
400
655
  import { fileURLToPath } from "node:url";
401
656
  function getAdapterCommandsDir() {
402
657
  const thisDir = dirname2(fileURLToPath(import.meta.url));
403
- return join4(thisDir, "commands");
658
+ return join5(thisDir, "commands");
404
659
  }
405
660
  var INSTRUCTION_REFERENCES, ClaudeCodeInstallProvider;
406
661
  var init_install = __esm({
@@ -421,7 +676,7 @@ var init_install = __esm({
421
676
  const details = {};
422
677
  instructionFileUpdated = this.updateInstructionFile(projectDir);
423
678
  if (instructionFileUpdated) {
424
- details.instructionFile = join4(projectDir, "CLAUDE.md");
679
+ details.instructionFile = join5(projectDir, "CLAUDE.md");
425
680
  }
426
681
  const commandsInstalled = this.installCommands(projectDir);
427
682
  if (commandsInstalled.length > 0) {
@@ -451,10 +706,10 @@ var init_install = __esm({
451
706
  * Checks for plugin enabled in ~/.claude/settings.json.
452
707
  */
453
708
  async isInstalled() {
454
- const settingsPath = join4(homedir3(), ".claude", "settings.json");
455
- if (existsSync2(settingsPath)) {
709
+ const settingsPath = join5(homedir5(), ".claude", "settings.json");
710
+ if (existsSync4(settingsPath)) {
456
711
  try {
457
- const settings = JSON.parse(readFileSync2(settingsPath, "utf-8"));
712
+ const settings = JSON.parse(readFileSync4(settingsPath, "utf-8"));
458
713
  const plugins = settings.enabledPlugins;
459
714
  if (plugins && plugins["cleo@cleocode"] === true) {
460
715
  return true;
@@ -480,11 +735,11 @@ var init_install = __esm({
480
735
  * @returns true if the file was created or modified
481
736
  */
482
737
  updateInstructionFile(projectDir) {
483
- const claudeMdPath = join4(projectDir, "CLAUDE.md");
738
+ const claudeMdPath = join5(projectDir, "CLAUDE.md");
484
739
  let content = "";
485
740
  let existed = false;
486
- if (existsSync2(claudeMdPath)) {
487
- content = readFileSync2(claudeMdPath, "utf-8");
741
+ if (existsSync4(claudeMdPath)) {
742
+ content = readFileSync4(claudeMdPath, "utf-8");
488
743
  existed = true;
489
744
  }
490
745
  const missingRefs = INSTRUCTION_REFERENCES.filter((ref) => !content.includes(ref));
@@ -498,7 +753,7 @@ var init_install = __esm({
498
753
  } else {
499
754
  content = refsBlock + "\n";
500
755
  }
501
- writeFileSync2(claudeMdPath, content, "utf-8");
756
+ writeFileSync3(claudeMdPath, content, "utf-8");
502
757
  return true;
503
758
  }
504
759
  /**
@@ -512,16 +767,16 @@ var init_install = __esm({
512
767
  */
513
768
  installCommands(projectDir) {
514
769
  const adapterCommandsDir = getAdapterCommandsDir();
515
- if (!existsSync2(adapterCommandsDir)) {
770
+ if (!existsSync4(adapterCommandsDir)) {
516
771
  return [];
517
772
  }
518
- const targetDir = join4(projectDir, ".claude", "commands");
519
- mkdirSync(targetDir, { recursive: true });
773
+ const targetDir = join5(projectDir, ".claude", "commands");
774
+ mkdirSync2(targetDir, { recursive: true });
520
775
  const installed = [];
521
- const files = readdirSync(adapterCommandsDir).filter((f) => f.endsWith(".md"));
776
+ const files = readdirSync2(adapterCommandsDir).filter((f) => f.endsWith(".md"));
522
777
  for (const file of files) {
523
- const src = join4(adapterCommandsDir, file);
524
- const dest = join4(targetDir, file);
778
+ const src = join5(adapterCommandsDir, file);
779
+ const dest = join5(targetDir, file);
525
780
  copyFileSync(src, dest);
526
781
  installed.push(file);
527
782
  }
@@ -533,12 +788,12 @@ var init_install = __esm({
533
788
  * @returns Description of what was registered, or null if no change needed
534
789
  */
535
790
  registerPlugin() {
536
- const home = homedir3();
537
- const settingsPath = join4(home, ".claude", "settings.json");
791
+ const home = homedir5();
792
+ const settingsPath = join5(home, ".claude", "settings.json");
538
793
  let settings = {};
539
- if (existsSync2(settingsPath)) {
794
+ if (existsSync4(settingsPath)) {
540
795
  try {
541
- settings = JSON.parse(readFileSync2(settingsPath, "utf-8"));
796
+ settings = JSON.parse(readFileSync4(settingsPath, "utf-8"));
542
797
  } catch {
543
798
  }
544
799
  }
@@ -552,8 +807,8 @@ var init_install = __esm({
552
807
  }
553
808
  enabledPlugins[pluginKey] = true;
554
809
  settings.enabledPlugins = enabledPlugins;
555
- mkdirSync(join4(home, ".claude"), { recursive: true });
556
- writeFileSync2(settingsPath, JSON.stringify(settings, null, 2) + "\n", "utf-8");
810
+ mkdirSync2(join5(home, ".claude"), { recursive: true });
811
+ writeFileSync3(settingsPath, JSON.stringify(settings, null, 2) + "\n", "utf-8");
557
812
  return `Enabled ${pluginKey} in ~/.claude/settings.json`;
558
813
  }
559
814
  };
@@ -762,8 +1017,18 @@ var init_spawn = __esm({
762
1017
  const startTime = (/* @__PURE__ */ new Date()).toISOString();
763
1018
  let tmpFile;
764
1019
  try {
1020
+ let enrichedPrompt = context.prompt;
1021
+ try {
1022
+ const { buildCantEnrichedPrompt: buildCantEnrichedPrompt2 } = await Promise.resolve().then(() => (init_cant_context(), cant_context_exports));
1023
+ enrichedPrompt = await buildCantEnrichedPrompt2({
1024
+ projectDir: context.workingDirectory ?? process.cwd(),
1025
+ basePrompt: context.prompt,
1026
+ agentName: context.options?.agentName ?? void 0
1027
+ });
1028
+ } catch {
1029
+ }
765
1030
  tmpFile = `/tmp/claude-spawn-${instanceId}.txt`;
766
- await writeFile(tmpFile, context.prompt, "utf-8");
1031
+ await writeFile(tmpFile, enrichedPrompt, "utf-8");
767
1032
  const args = ["--allow-insecure", "--no-upgrade-check", tmpFile];
768
1033
  const spawnOpts = {
769
1034
  detached: true,
@@ -864,7 +1129,7 @@ var init_spawn = __esm({
864
1129
 
865
1130
  // packages/adapters/src/providers/claude-code/task-sync.ts
866
1131
  import { readFile as readFile2, stat } from "node:fs/promises";
867
- import { join as join5 } from "node:path";
1132
+ import { join as join6 } from "node:path";
868
1133
  function parseTaskId(content) {
869
1134
  const match = content.match(/^\[T(\d+)\]/);
870
1135
  return match ? `T${match[1]}` : null;
@@ -885,7 +1150,7 @@ function mapStatus(twStatus) {
885
1150
  }
886
1151
  }
887
1152
  function getTodoWriteFilePath(projectDir) {
888
- return join5(projectDir, ".cleo", "sync", "todowrite-state.json");
1153
+ return join6(projectDir, ".cleo", "sync", "todowrite-state.json");
889
1154
  }
890
1155
  var ClaudeCodeTaskSyncProvider;
891
1156
  var init_task_sync = __esm({
@@ -957,9 +1222,9 @@ var init_transport = __esm({
957
1222
 
958
1223
  // packages/adapters/src/providers/claude-code/adapter.ts
959
1224
  import { exec as exec2 } from "node:child_process";
960
- import { existsSync as existsSync3 } from "node:fs";
961
- import { homedir as homedir4 } from "node:os";
962
- import { join as join6 } from "node:path";
1225
+ import { existsSync as existsSync5 } from "node:fs";
1226
+ import { homedir as homedir6 } from "node:os";
1227
+ import { join as join7 } from "node:path";
963
1228
  import { promisify as promisify2 } from "node:util";
964
1229
  var execAsync2, ClaudeCodeAdapter;
965
1230
  var init_adapter = __esm({
@@ -1049,6 +1314,7 @@ var init_adapter = __esm({
1049
1314
  async initialize(projectDir) {
1050
1315
  this.projectDir = projectDir;
1051
1316
  this.initialized = true;
1317
+ await this.hooks.registerNativeHooks(projectDir);
1052
1318
  }
1053
1319
  /**
1054
1320
  * Dispose the adapter and clean up resources.
@@ -1089,8 +1355,8 @@ var init_adapter = __esm({
1089
1355
  } catch {
1090
1356
  details.cliAvailable = false;
1091
1357
  }
1092
- const claudeConfigDir = join6(homedir4(), ".claude");
1093
- const configExists = existsSync3(claudeConfigDir);
1358
+ const claudeConfigDir = join7(homedir6(), ".claude");
1359
+ const configExists = existsSync5(claudeConfigDir);
1094
1360
  details.configDirExists = configExists;
1095
1361
  const entrypointSet = process.env.CLAUDE_CODE_ENTRYPOINT !== void 0;
1096
1362
  details.entrypointEnvSet = entrypointSet;
@@ -1119,17 +1385,17 @@ var init_adapter = __esm({
1119
1385
  });
1120
1386
 
1121
1387
  // packages/adapters/src/providers/claude-code/statusline.ts
1122
- import { existsSync as existsSync4, readFileSync as readFileSync3 } from "node:fs";
1123
- import { homedir as homedir5 } from "node:os";
1124
- import { join as join7 } from "node:path";
1388
+ import { existsSync as existsSync6, readFileSync as readFileSync5 } from "node:fs";
1389
+ import { homedir as homedir7 } from "node:os";
1390
+ import { join as join8 } from "node:path";
1125
1391
  function getClaudeSettingsPath() {
1126
- return process.env["CLAUDE_SETTINGS"] ?? join7(process.env["CLAUDE_HOME"] ?? join7(homedir5(), ".claude"), "settings.json");
1392
+ return process.env["CLAUDE_SETTINGS"] ?? join8(process.env["CLAUDE_HOME"] ?? join8(homedir7(), ".claude"), "settings.json");
1127
1393
  }
1128
1394
  function checkStatuslineIntegration() {
1129
1395
  const settingsPath = getClaudeSettingsPath();
1130
- if (!existsSync4(settingsPath)) return "no_settings";
1396
+ if (!existsSync6(settingsPath)) return "no_settings";
1131
1397
  try {
1132
- const settings = JSON.parse(readFileSync3(settingsPath, "utf-8"));
1398
+ const settings = JSON.parse(readFileSync5(settingsPath, "utf-8"));
1133
1399
  const statusLine = settings.statusLine;
1134
1400
  if (!statusLine?.type) return "not_configured";
1135
1401
  if (statusLine.type !== "command") return "custom_no_cleo";
@@ -1137,10 +1403,10 @@ function checkStatuslineIntegration() {
1137
1403
  if (cmd.includes("context-monitor.sh") || cmd.includes("cleo-statusline") || cmd.includes(".context-state.json") || cmd.includes("context-states")) {
1138
1404
  return "configured";
1139
1405
  }
1140
- const scriptPath = cmd.startsWith("~") ? cmd.replace("~", homedir5()) : cmd;
1141
- if (existsSync4(scriptPath)) {
1406
+ const scriptPath = cmd.startsWith("~") ? cmd.replace("~", homedir7()) : cmd;
1407
+ if (existsSync6(scriptPath)) {
1142
1408
  try {
1143
- const content = readFileSync3(scriptPath, "utf-8");
1409
+ const content = readFileSync5(scriptPath, "utf-8");
1144
1410
  if (content.includes("context-state.json")) return "configured";
1145
1411
  } catch {
1146
1412
  }
@@ -1154,7 +1420,7 @@ function getStatuslineConfig(cleoHome) {
1154
1420
  return {
1155
1421
  statusLine: {
1156
1422
  type: "command",
1157
- command: join7(cleoHome, "lib", "session", "context-monitor.sh")
1423
+ command: join8(cleoHome, "lib", "session", "context-monitor.sh")
1158
1424
  }
1159
1425
  };
1160
1426
  }
@@ -1365,8 +1631,8 @@ var init_hooks2 = __esm({
1365
1631
  });
1366
1632
 
1367
1633
  // packages/adapters/src/providers/cursor/install.ts
1368
- import { existsSync as existsSync7, mkdirSync as mkdirSync2, readFileSync as readFileSync5, writeFileSync as writeFileSync4 } from "node:fs";
1369
- import { join as join12 } from "node:path";
1634
+ import { existsSync as existsSync9, mkdirSync as mkdirSync3, readFileSync as readFileSync7, writeFileSync as writeFileSync5 } from "node:fs";
1635
+ import { join as join13 } from "node:path";
1370
1636
  var INSTRUCTION_REFERENCES3, CursorInstallProvider;
1371
1637
  var init_install2 = __esm({
1372
1638
  "packages/adapters/src/providers/cursor/install.ts"() {
@@ -1408,14 +1674,14 @@ var init_install2 = __esm({
1408
1674
  * Checks for .cursor/rules/cleo.mdc or .cursorrules with CLEO references.
1409
1675
  */
1410
1676
  async isInstalled() {
1411
- const mdcPath = join12(process.cwd(), ".cursor", "rules", "cleo.mdc");
1412
- if (existsSync7(mdcPath)) {
1677
+ const mdcPath = join13(process.cwd(), ".cursor", "rules", "cleo.mdc");
1678
+ if (existsSync9(mdcPath)) {
1413
1679
  return true;
1414
1680
  }
1415
- const rulesPath = join12(process.cwd(), ".cursorrules");
1416
- if (existsSync7(rulesPath)) {
1681
+ const rulesPath = join13(process.cwd(), ".cursorrules");
1682
+ if (existsSync9(rulesPath)) {
1417
1683
  try {
1418
- const content = readFileSync5(rulesPath, "utf-8");
1684
+ const content = readFileSync7(rulesPath, "utf-8");
1419
1685
  if (INSTRUCTION_REFERENCES3.some((ref) => content.includes(ref))) {
1420
1686
  return true;
1421
1687
  }
@@ -1458,18 +1724,18 @@ var init_install2 = __esm({
1458
1724
  * @returns true if the file was modified
1459
1725
  */
1460
1726
  updateLegacyRules(projectDir) {
1461
- const rulesPath = join12(projectDir, ".cursorrules");
1462
- if (!existsSync7(rulesPath)) {
1727
+ const rulesPath = join13(projectDir, ".cursorrules");
1728
+ if (!existsSync9(rulesPath)) {
1463
1729
  return false;
1464
1730
  }
1465
- let content = readFileSync5(rulesPath, "utf-8");
1731
+ let content = readFileSync7(rulesPath, "utf-8");
1466
1732
  const missingRefs = INSTRUCTION_REFERENCES3.filter((ref) => !content.includes(ref));
1467
1733
  if (missingRefs.length === 0) {
1468
1734
  return false;
1469
1735
  }
1470
1736
  const separator = content.endsWith("\n") ? "" : "\n";
1471
1737
  content = content + separator + missingRefs.join("\n") + "\n";
1472
- writeFileSync4(rulesPath, content, "utf-8");
1738
+ writeFileSync5(rulesPath, content, "utf-8");
1473
1739
  return true;
1474
1740
  }
1475
1741
  /**
@@ -1481,8 +1747,8 @@ var init_install2 = __esm({
1481
1747
  * @returns true if the file was created or modified
1482
1748
  */
1483
1749
  updateModernRules(projectDir) {
1484
- const rulesDir = join12(projectDir, ".cursor", "rules");
1485
- const mdcPath = join12(rulesDir, "cleo.mdc");
1750
+ const rulesDir = join13(projectDir, ".cursor", "rules");
1751
+ const mdcPath = join13(rulesDir, "cleo.mdc");
1486
1752
  const expectedContent = [
1487
1753
  "---",
1488
1754
  "description: CLEO task management protocol references",
@@ -1493,14 +1759,14 @@ var init_install2 = __esm({
1493
1759
  ...INSTRUCTION_REFERENCES3,
1494
1760
  ""
1495
1761
  ].join("\n");
1496
- if (existsSync7(mdcPath)) {
1497
- const existing = readFileSync5(mdcPath, "utf-8");
1762
+ if (existsSync9(mdcPath)) {
1763
+ const existing = readFileSync7(mdcPath, "utf-8");
1498
1764
  if (existing === expectedContent) {
1499
1765
  return false;
1500
1766
  }
1501
1767
  }
1502
- mkdirSync2(rulesDir, { recursive: true });
1503
- writeFileSync4(mdcPath, expectedContent, "utf-8");
1768
+ mkdirSync3(rulesDir, { recursive: true });
1769
+ writeFileSync5(mdcPath, expectedContent, "utf-8");
1504
1770
  return true;
1505
1771
  }
1506
1772
  /**
@@ -1508,10 +1774,10 @@ var init_install2 = __esm({
1508
1774
  */
1509
1775
  getUpdatedFileList(projectDir) {
1510
1776
  const files = [];
1511
- if (existsSync7(join12(projectDir, ".cursorrules"))) {
1512
- files.push(join12(projectDir, ".cursorrules"));
1777
+ if (existsSync9(join13(projectDir, ".cursorrules"))) {
1778
+ files.push(join13(projectDir, ".cursorrules"));
1513
1779
  }
1514
- files.push(join12(projectDir, ".cursor", "rules", "cleo.mdc"));
1780
+ files.push(join13(projectDir, ".cursor", "rules", "cleo.mdc"));
1515
1781
  return files;
1516
1782
  }
1517
1783
  };
@@ -1519,8 +1785,8 @@ var init_install2 = __esm({
1519
1785
  });
1520
1786
 
1521
1787
  // packages/adapters/src/providers/cursor/adapter.ts
1522
- import { existsSync as existsSync8 } from "node:fs";
1523
- import { join as join13 } from "node:path";
1788
+ import { existsSync as existsSync10 } from "node:fs";
1789
+ import { join as join14 } from "node:path";
1524
1790
  var CursorAdapter;
1525
1791
  var init_adapter2 = __esm({
1526
1792
  "packages/adapters/src/providers/cursor/adapter.ts"() {
@@ -1614,14 +1880,14 @@ var init_adapter2 = __esm({
1614
1880
  }
1615
1881
  let configExists = false;
1616
1882
  if (this.projectDir) {
1617
- const cursorConfigDir = join13(this.projectDir, ".cursor");
1618
- configExists = existsSync8(cursorConfigDir);
1883
+ const cursorConfigDir = join14(this.projectDir, ".cursor");
1884
+ configExists = existsSync10(cursorConfigDir);
1619
1885
  details.configDirExists = configExists;
1620
1886
  }
1621
1887
  const editorEnvSet = process.env.CURSOR_EDITOR !== void 0;
1622
1888
  details.editorEnvSet = editorEnvSet;
1623
1889
  if (this.projectDir) {
1624
- const legacyRulesExist = existsSync8(join13(this.projectDir, ".cursorrules"));
1890
+ const legacyRulesExist = existsSync10(join14(this.projectDir, ".cursorrules"));
1625
1891
  details.legacyRulesExist = legacyRulesExist;
1626
1892
  }
1627
1893
  const healthy = configExists || editorEnvSet;
@@ -1825,8 +2091,8 @@ var init_hooks3 = __esm({
1825
2091
  });
1826
2092
 
1827
2093
  // packages/adapters/src/providers/opencode/install.ts
1828
- import { existsSync as existsSync13, readFileSync as readFileSync8, writeFileSync as writeFileSync7 } from "node:fs";
1829
- import { join as join19 } from "node:path";
2094
+ import { existsSync as existsSync15, readFileSync as readFileSync10, writeFileSync as writeFileSync8 } from "node:fs";
2095
+ import { join as join20 } from "node:path";
1830
2096
  var INSTRUCTION_REFERENCES6, OpenCodeInstallProvider;
1831
2097
  var init_install3 = __esm({
1832
2098
  "packages/adapters/src/providers/opencode/install.ts"() {
@@ -1846,7 +2112,7 @@ var init_install3 = __esm({
1846
2112
  const details = {};
1847
2113
  instructionFileUpdated = this.updateInstructionFile(projectDir);
1848
2114
  if (instructionFileUpdated) {
1849
- details.instructionFile = join19(projectDir, "AGENTS.md");
2115
+ details.instructionFile = join20(projectDir, "AGENTS.md");
1850
2116
  }
1851
2117
  return {
1852
2118
  success: true,
@@ -1868,10 +2134,10 @@ var init_install3 = __esm({
1868
2134
  * Checks for CLEO references in AGENTS.md.
1869
2135
  */
1870
2136
  async isInstalled() {
1871
- const agentsMdPath = join19(process.cwd(), "AGENTS.md");
1872
- if (existsSync13(agentsMdPath)) {
2137
+ const agentsMdPath = join20(process.cwd(), "AGENTS.md");
2138
+ if (existsSync15(agentsMdPath)) {
1873
2139
  try {
1874
- const content = readFileSync8(agentsMdPath, "utf-8");
2140
+ const content = readFileSync10(agentsMdPath, "utf-8");
1875
2141
  if (INSTRUCTION_REFERENCES6.some((ref) => content.includes(ref))) {
1876
2142
  return true;
1877
2143
  }
@@ -1896,11 +2162,11 @@ var init_install3 = __esm({
1896
2162
  * @returns true if the file was created or modified
1897
2163
  */
1898
2164
  updateInstructionFile(projectDir) {
1899
- const agentsMdPath = join19(projectDir, "AGENTS.md");
2165
+ const agentsMdPath = join20(projectDir, "AGENTS.md");
1900
2166
  let content = "";
1901
2167
  let existed = false;
1902
- if (existsSync13(agentsMdPath)) {
1903
- content = readFileSync8(agentsMdPath, "utf-8");
2168
+ if (existsSync15(agentsMdPath)) {
2169
+ content = readFileSync10(agentsMdPath, "utf-8");
1904
2170
  existed = true;
1905
2171
  }
1906
2172
  const missingRefs = INSTRUCTION_REFERENCES6.filter((ref) => !content.includes(ref));
@@ -1914,7 +2180,7 @@ var init_install3 = __esm({
1914
2180
  } else {
1915
2181
  content = refsBlock + "\n";
1916
2182
  }
1917
- writeFileSync7(agentsMdPath, content, "utf-8");
2183
+ writeFileSync8(agentsMdPath, content, "utf-8");
1918
2184
  return true;
1919
2185
  }
1920
2186
  };
@@ -1924,7 +2190,7 @@ var init_install3 = __esm({
1924
2190
  // packages/adapters/src/providers/opencode/spawn.ts
1925
2191
  import { exec as exec6, spawn as nodeSpawn2 } from "node:child_process";
1926
2192
  import { mkdir as mkdir2, readFile as readFile4, writeFile as writeFile2 } from "node:fs/promises";
1927
- import { join as join20 } from "node:path";
2193
+ import { join as join21 } from "node:path";
1928
2194
  import { promisify as promisify6 } from "node:util";
1929
2195
  function buildOpenCodeAgentMarkdown(description, instructions) {
1930
2196
  const normalizedDesc = description.replace(/\s+/g, " ").trim();
@@ -1939,11 +2205,11 @@ function buildOpenCodeAgentMarkdown(description, instructions) {
1939
2205
  ""
1940
2206
  ].join("\n");
1941
2207
  }
1942
- async function ensureSubagentDefinition(workingDirectory) {
1943
- const agentDir = join20(workingDirectory, ".opencode", "agent");
1944
- const agentPath = join20(agentDir, `${OPENCODE_SUBAGENT_NAME}.md`);
1945
- const description = "CLEO task executor with protocol compliance.";
1946
- const instructions = [
2208
+ async function ensureSubagentDefinition(workingDirectory, enrichedInstructions) {
2209
+ const agentDir = join21(workingDirectory, ".opencode", "agent");
2210
+ const agentPath = join21(agentDir, `${OPENCODE_SUBAGENT_NAME}.md`);
2211
+ const description = "CLEO task executor with protocol compliance and CANT context.";
2212
+ const instructions = enrichedInstructions ?? [
1947
2213
  "# CLEO Subagent",
1948
2214
  "",
1949
2215
  "You are a CLEO subagent executing a delegated task.",
@@ -2002,9 +2268,19 @@ var init_spawn2 = __esm({
2002
2268
  const startTime = (/* @__PURE__ */ new Date()).toISOString();
2003
2269
  const workingDirectory = context.workingDirectory ?? process.cwd();
2004
2270
  try {
2271
+ let enrichedInstructions;
2272
+ try {
2273
+ const { buildCantEnrichedPrompt: buildCantEnrichedPrompt2 } = await Promise.resolve().then(() => (init_cant_context(), cant_context_exports));
2274
+ enrichedInstructions = await buildCantEnrichedPrompt2({
2275
+ projectDir: workingDirectory,
2276
+ basePrompt: context.prompt,
2277
+ agentName: context.options?.agentName ?? void 0
2278
+ });
2279
+ } catch {
2280
+ }
2005
2281
  let agentName;
2006
2282
  try {
2007
- agentName = await ensureSubagentDefinition(workingDirectory);
2283
+ agentName = await ensureSubagentDefinition(workingDirectory, enrichedInstructions);
2008
2284
  } catch {
2009
2285
  agentName = OPENCODE_FALLBACK_AGENT;
2010
2286
  }
@@ -2104,8 +2380,8 @@ var init_spawn2 = __esm({
2104
2380
 
2105
2381
  // packages/adapters/src/providers/opencode/adapter.ts
2106
2382
  import { exec as exec7 } from "node:child_process";
2107
- import { existsSync as existsSync14 } from "node:fs";
2108
- import { join as join21 } from "node:path";
2383
+ import { existsSync as existsSync16 } from "node:fs";
2384
+ import { join as join22 } from "node:path";
2109
2385
  import { promisify as promisify7 } from "node:util";
2110
2386
  var execAsync7, OpenCodeAdapter;
2111
2387
  var init_adapter3 = __esm({
@@ -2217,8 +2493,8 @@ var init_adapter3 = __esm({
2217
2493
  details.cliAvailable = false;
2218
2494
  }
2219
2495
  if (this.projectDir) {
2220
- const openCodeConfigDir = join21(this.projectDir, ".opencode");
2221
- const configExists = existsSync14(openCodeConfigDir);
2496
+ const openCodeConfigDir = join22(this.projectDir, ".opencode");
2497
+ const configExists = existsSync16(openCodeConfigDir);
2222
2498
  details.configDirExists = configExists;
2223
2499
  }
2224
2500
  const versionEnvSet = process.env.OPENCODE_VERSION !== void 0;
@@ -2427,21 +2703,21 @@ var init_hooks4 = __esm({
2427
2703
  });
2428
2704
 
2429
2705
  // packages/adapters/src/providers/pi/install.ts
2430
- import { existsSync as existsSync15, mkdirSync as mkdirSync3, readFileSync as readFileSync9, writeFileSync as writeFileSync8 } from "node:fs";
2431
- import { homedir as homedir11 } from "node:os";
2432
- import { join as join22 } from "node:path";
2706
+ import { existsSync as existsSync17, mkdirSync as mkdirSync4, readFileSync as readFileSync11, writeFileSync as writeFileSync9 } from "node:fs";
2707
+ import { homedir as homedir13 } from "node:os";
2708
+ import { join as join23 } from "node:path";
2433
2709
  function getPiAgentDir() {
2434
2710
  const env = process.env["PI_CODING_AGENT_DIR"];
2435
2711
  if (env !== void 0 && env.length > 0) {
2436
- if (env === "~") return homedir11();
2437
- if (env.startsWith("~/")) return join22(homedir11(), env.slice(2));
2712
+ if (env === "~") return homedir13();
2713
+ if (env.startsWith("~/")) return join23(homedir13(), env.slice(2));
2438
2714
  return env;
2439
2715
  }
2440
2716
  const piHome = process.env["PI_HOME"];
2441
2717
  if (piHome !== void 0 && piHome.length > 0) {
2442
- return join22(piHome, "agent");
2718
+ return join23(piHome, "agent");
2443
2719
  }
2444
- return join22(homedir11(), ".pi", "agent");
2720
+ return join23(homedir13(), ".pi", "agent");
2445
2721
  }
2446
2722
  var INSTRUCTION_REFERENCES7, PiInstallProvider;
2447
2723
  var init_install4 = __esm({
@@ -2461,14 +2737,14 @@ var init_install4 = __esm({
2461
2737
  const details = {};
2462
2738
  const projectUpdated = this.updateInstructionFile(projectDir, "AGENTS.md");
2463
2739
  if (projectUpdated) {
2464
- details.instructionFile = join22(projectDir, "AGENTS.md");
2740
+ details.instructionFile = join23(projectDir, "AGENTS.md");
2465
2741
  }
2466
2742
  let globalUpdated = false;
2467
2743
  try {
2468
2744
  const globalDir = getPiAgentDir();
2469
2745
  globalUpdated = this.updateInstructionFile(globalDir, "AGENTS.md");
2470
2746
  if (globalUpdated) {
2471
- details.globalInstructionFile = join22(globalDir, "AGENTS.md");
2747
+ details.globalInstructionFile = join23(globalDir, "AGENTS.md");
2472
2748
  }
2473
2749
  } catch {
2474
2750
  }
@@ -2493,10 +2769,10 @@ var init_install4 = __esm({
2493
2769
  * Checks for CLEO references in the project AGENTS.md.
2494
2770
  */
2495
2771
  async isInstalled() {
2496
- const agentsMdPath = join22(process.cwd(), "AGENTS.md");
2497
- if (existsSync15(agentsMdPath)) {
2772
+ const agentsMdPath = join23(process.cwd(), "AGENTS.md");
2773
+ if (existsSync17(agentsMdPath)) {
2498
2774
  try {
2499
- const content = readFileSync9(agentsMdPath, "utf-8");
2775
+ const content = readFileSync11(agentsMdPath, "utf-8");
2500
2776
  if (INSTRUCTION_REFERENCES7.some((ref) => content.includes(ref))) {
2501
2777
  return true;
2502
2778
  }
@@ -2504,9 +2780,9 @@ var init_install4 = __esm({
2504
2780
  }
2505
2781
  }
2506
2782
  try {
2507
- const globalPath = join22(getPiAgentDir(), "AGENTS.md");
2508
- if (existsSync15(globalPath)) {
2509
- const content = readFileSync9(globalPath, "utf-8");
2783
+ const globalPath = join23(getPiAgentDir(), "AGENTS.md");
2784
+ if (existsSync17(globalPath)) {
2785
+ const content = readFileSync11(globalPath, "utf-8");
2510
2786
  if (INSTRUCTION_REFERENCES7.some((ref) => content.includes(ref))) {
2511
2787
  return true;
2512
2788
  }
@@ -2533,11 +2809,11 @@ var init_install4 = __esm({
2533
2809
  * @returns true if the file was created or modified
2534
2810
  */
2535
2811
  updateInstructionFile(dir, filename) {
2536
- const filePath = join22(dir, filename);
2812
+ const filePath = join23(dir, filename);
2537
2813
  let content = "";
2538
2814
  let existed = false;
2539
- if (existsSync15(filePath)) {
2540
- content = readFileSync9(filePath, "utf-8");
2815
+ if (existsSync17(filePath)) {
2816
+ content = readFileSync11(filePath, "utf-8");
2541
2817
  existed = true;
2542
2818
  }
2543
2819
  const missingRefs = INSTRUCTION_REFERENCES7.filter((ref) => !content.includes(ref));
@@ -2549,10 +2825,10 @@ var init_install4 = __esm({
2549
2825
  const separator = content.endsWith("\n") ? "" : "\n";
2550
2826
  content = content + separator + refsBlock + "\n";
2551
2827
  } else {
2552
- mkdirSync3(dir, { recursive: true });
2828
+ mkdirSync4(dir, { recursive: true });
2553
2829
  content = refsBlock + "\n";
2554
2830
  }
2555
- writeFileSync8(filePath, content, "utf-8");
2831
+ writeFileSync9(filePath, content, "utf-8");
2556
2832
  return true;
2557
2833
  }
2558
2834
  };
@@ -2712,22 +2988,22 @@ var init_spawn3 = __esm({
2712
2988
 
2713
2989
  // packages/adapters/src/providers/pi/adapter.ts
2714
2990
  import { exec as exec9 } from "node:child_process";
2715
- import { existsSync as existsSync16 } from "node:fs";
2716
- import { homedir as homedir12 } from "node:os";
2717
- import { join as join23 } from "node:path";
2991
+ import { existsSync as existsSync18 } from "node:fs";
2992
+ import { homedir as homedir14 } from "node:os";
2993
+ import { join as join24 } from "node:path";
2718
2994
  import { promisify as promisify9 } from "node:util";
2719
2995
  function getPiAgentDir2() {
2720
2996
  const env = process.env["PI_CODING_AGENT_DIR"];
2721
2997
  if (env !== void 0 && env.length > 0) {
2722
- if (env === "~") return homedir12();
2723
- if (env.startsWith("~/")) return join23(homedir12(), env.slice(2));
2998
+ if (env === "~") return homedir14();
2999
+ if (env.startsWith("~/")) return join24(homedir14(), env.slice(2));
2724
3000
  return env;
2725
3001
  }
2726
3002
  const piHome = process.env["PI_HOME"];
2727
3003
  if (piHome !== void 0 && piHome.length > 0) {
2728
- return join23(piHome, "agent");
3004
+ return join24(piHome, "agent");
2729
3005
  }
2730
- return join23(homedir12(), ".pi", "agent");
3006
+ return join24(homedir14(), ".pi", "agent");
2731
3007
  }
2732
3008
  var execAsync9, PiAdapter;
2733
3009
  var init_adapter4 = __esm({
@@ -2845,12 +3121,12 @@ var init_adapter4 = __esm({
2845
3121
  details.cliAvailable = false;
2846
3122
  }
2847
3123
  const agentDir = getPiAgentDir2();
2848
- const agentDirExists = existsSync16(agentDir);
3124
+ const agentDirExists = existsSync18(agentDir);
2849
3125
  details.agentDirExists = agentDirExists;
2850
3126
  details.agentDir = agentDir;
2851
3127
  if (this.projectDir) {
2852
- const projectPiDir = join23(this.projectDir, ".pi");
2853
- details.projectPiDirExists = existsSync16(projectPiDir);
3128
+ const projectPiDir = join24(this.projectDir, ".pi");
3129
+ details.projectPiDirExists = existsSync18(projectPiDir);
2854
3130
  }
2855
3131
  details.piCodingAgentDirSet = process.env["PI_CODING_AGENT_DIR"] !== void 0;
2856
3132
  details.piHomeSet = process.env["PI_HOME"] !== void 0;
@@ -2906,22 +3182,23 @@ var init_pi = __esm({
2906
3182
  });
2907
3183
 
2908
3184
  // packages/adapters/src/index.ts
3185
+ init_cant_context();
2909
3186
  init_claude_code();
2910
3187
 
2911
3188
  // packages/adapters/src/providers/codex/adapter.ts
2912
3189
  import { exec as exec3 } from "node:child_process";
2913
- import { existsSync as existsSync6 } from "node:fs";
2914
- import { homedir as homedir7 } from "node:os";
2915
- import { join as join11 } from "node:path";
3190
+ import { existsSync as existsSync8 } from "node:fs";
3191
+ import { homedir as homedir9 } from "node:os";
3192
+ import { join as join12 } from "node:path";
2916
3193
  import { promisify as promisify3 } from "node:util";
2917
3194
 
2918
3195
  // packages/adapters/src/providers/codex/hooks.ts
2919
- import { homedir as homedir6 } from "node:os";
2920
- import { join as join9 } from "node:path";
3196
+ import { homedir as homedir8 } from "node:os";
3197
+ import { join as join10 } from "node:path";
2921
3198
 
2922
3199
  // packages/adapters/src/providers/shared/transcript-reader.ts
2923
3200
  import { readdir as readdir2, readFile as readFile3 } from "node:fs/promises";
2924
- import { join as join8 } from "node:path";
3201
+ import { join as join9 } from "node:path";
2925
3202
  function parseTranscriptLines(raw) {
2926
3203
  const turns = [];
2927
3204
  const lines = raw.split("\n").filter((l) => l.trim());
@@ -2946,7 +3223,7 @@ async function readLatestTranscript(providerDir) {
2946
3223
  if (!entry.isFile()) continue;
2947
3224
  const name = entry.name;
2948
3225
  if (name.endsWith(".json") || name.endsWith(".jsonl")) {
2949
- allFiles.push(join8(providerDir, name));
3226
+ allFiles.push(join9(providerDir, name));
2950
3227
  }
2951
3228
  }
2952
3229
  } catch {
@@ -3036,13 +3313,13 @@ var CodexHookProvider = class {
3036
3313
  * @task T162 @epic T134
3037
3314
  */
3038
3315
  async getTranscript(_sessionId, _projectDir) {
3039
- return readLatestTranscript(join9(homedir6(), ".codex"));
3316
+ return readLatestTranscript(join10(homedir8(), ".codex"));
3040
3317
  }
3041
3318
  };
3042
3319
 
3043
3320
  // packages/adapters/src/providers/codex/install.ts
3044
- import { existsSync as existsSync5, readFileSync as readFileSync4, writeFileSync as writeFileSync3 } from "node:fs";
3045
- import { join as join10 } from "node:path";
3321
+ import { existsSync as existsSync7, readFileSync as readFileSync6, writeFileSync as writeFileSync4 } from "node:fs";
3322
+ import { join as join11 } from "node:path";
3046
3323
  var INSTRUCTION_REFERENCES2 = ["@~/.cleo/templates/CLEO-INJECTION.md", "@.cleo/memory-bridge.md"];
3047
3324
  var CodexInstallProvider = class {
3048
3325
  /**
@@ -3059,7 +3336,7 @@ var CodexInstallProvider = class {
3059
3336
  const details = {};
3060
3337
  instructionFileUpdated = this.updateInstructionFile(projectDir);
3061
3338
  if (instructionFileUpdated) {
3062
- details.instructionFile = join10(projectDir, "AGENTS.md");
3339
+ details.instructionFile = join11(projectDir, "AGENTS.md");
3063
3340
  }
3064
3341
  return {
3065
3342
  success: true,
@@ -3083,10 +3360,10 @@ var CodexInstallProvider = class {
3083
3360
  * @task T162
3084
3361
  */
3085
3362
  async isInstalled() {
3086
- const agentsMdPath = join10(process.cwd(), "AGENTS.md");
3087
- if (existsSync5(agentsMdPath)) {
3363
+ const agentsMdPath = join11(process.cwd(), "AGENTS.md");
3364
+ if (existsSync7(agentsMdPath)) {
3088
3365
  try {
3089
- const content = readFileSync4(agentsMdPath, "utf-8");
3366
+ const content = readFileSync6(agentsMdPath, "utf-8");
3090
3367
  if (INSTRUCTION_REFERENCES2.some((ref) => content.includes(ref))) {
3091
3368
  return true;
3092
3369
  }
@@ -3113,11 +3390,11 @@ var CodexInstallProvider = class {
3113
3390
  * @returns true if the file was created or modified
3114
3391
  */
3115
3392
  updateInstructionFile(projectDir) {
3116
- const agentsMdPath = join10(projectDir, "AGENTS.md");
3393
+ const agentsMdPath = join11(projectDir, "AGENTS.md");
3117
3394
  let content = "";
3118
3395
  let existed = false;
3119
- if (existsSync5(agentsMdPath)) {
3120
- content = readFileSync4(agentsMdPath, "utf-8");
3396
+ if (existsSync7(agentsMdPath)) {
3397
+ content = readFileSync6(agentsMdPath, "utf-8");
3121
3398
  existed = true;
3122
3399
  }
3123
3400
  const missingRefs = INSTRUCTION_REFERENCES2.filter((ref) => !content.includes(ref));
@@ -3131,7 +3408,7 @@ var CodexInstallProvider = class {
3131
3408
  } else {
3132
3409
  content = refsBlock + "\n";
3133
3410
  }
3134
- writeFileSync3(agentsMdPath, content, "utf-8");
3411
+ writeFileSync4(agentsMdPath, content, "utf-8");
3135
3412
  return true;
3136
3413
  }
3137
3414
  };
@@ -3221,8 +3498,8 @@ var CodexAdapter = class {
3221
3498
  } catch {
3222
3499
  details.cliAvailable = false;
3223
3500
  }
3224
- const codexConfigDir = join11(homedir7(), ".codex");
3225
- const configExists = existsSync6(codexConfigDir);
3501
+ const codexConfigDir = join12(homedir9(), ".codex");
3502
+ const configExists = existsSync8(codexConfigDir);
3226
3503
  details.configDirExists = configExists;
3227
3504
  const healthy = cliAvailable;
3228
3505
  details.cliAvailable = cliAvailable;
@@ -3258,14 +3535,14 @@ init_cursor();
3258
3535
 
3259
3536
  // packages/adapters/src/providers/gemini-cli/adapter.ts
3260
3537
  import { exec as exec4 } from "node:child_process";
3261
- import { existsSync as existsSync10 } from "node:fs";
3262
- import { homedir as homedir9 } from "node:os";
3263
- import { join as join16 } from "node:path";
3538
+ import { existsSync as existsSync12 } from "node:fs";
3539
+ import { homedir as homedir11 } from "node:os";
3540
+ import { join as join17 } from "node:path";
3264
3541
  import { promisify as promisify4 } from "node:util";
3265
3542
 
3266
3543
  // packages/adapters/src/providers/gemini-cli/hooks.ts
3267
- import { homedir as homedir8 } from "node:os";
3268
- import { join as join14 } from "node:path";
3544
+ import { homedir as homedir10 } from "node:os";
3545
+ import { join as join15 } from "node:path";
3269
3546
  var GEMINI_CLI_EVENT_MAP = {
3270
3547
  SessionStart: "SessionStart",
3271
3548
  SessionEnd: "SessionEnd",
@@ -3343,13 +3620,13 @@ var GeminiCliHookProvider = class {
3343
3620
  * @task T161 @epic T134
3344
3621
  */
3345
3622
  async getTranscript(_sessionId, _projectDir) {
3346
- return readLatestTranscript(join14(homedir8(), ".gemini"));
3623
+ return readLatestTranscript(join15(homedir10(), ".gemini"));
3347
3624
  }
3348
3625
  };
3349
3626
 
3350
3627
  // packages/adapters/src/providers/gemini-cli/install.ts
3351
- import { existsSync as existsSync9, readFileSync as readFileSync6, writeFileSync as writeFileSync5 } from "node:fs";
3352
- import { join as join15 } from "node:path";
3628
+ import { existsSync as existsSync11, readFileSync as readFileSync8, writeFileSync as writeFileSync6 } from "node:fs";
3629
+ import { join as join16 } from "node:path";
3353
3630
  var INSTRUCTION_REFERENCES4 = ["@~/.cleo/templates/CLEO-INJECTION.md", "@.cleo/memory-bridge.md"];
3354
3631
  var GeminiCliInstallProvider = class {
3355
3632
  /**
@@ -3366,7 +3643,7 @@ var GeminiCliInstallProvider = class {
3366
3643
  const details = {};
3367
3644
  instructionFileUpdated = this.updateInstructionFile(projectDir);
3368
3645
  if (instructionFileUpdated) {
3369
- details.instructionFile = join15(projectDir, "AGENTS.md");
3646
+ details.instructionFile = join16(projectDir, "AGENTS.md");
3370
3647
  }
3371
3648
  return {
3372
3649
  success: true,
@@ -3390,10 +3667,10 @@ var GeminiCliInstallProvider = class {
3390
3667
  * @task T161
3391
3668
  */
3392
3669
  async isInstalled() {
3393
- const agentsMdPath = join15(process.cwd(), "AGENTS.md");
3394
- if (existsSync9(agentsMdPath)) {
3670
+ const agentsMdPath = join16(process.cwd(), "AGENTS.md");
3671
+ if (existsSync11(agentsMdPath)) {
3395
3672
  try {
3396
- const content = readFileSync6(agentsMdPath, "utf-8");
3673
+ const content = readFileSync8(agentsMdPath, "utf-8");
3397
3674
  if (INSTRUCTION_REFERENCES4.some((ref) => content.includes(ref))) {
3398
3675
  return true;
3399
3676
  }
@@ -3420,11 +3697,11 @@ var GeminiCliInstallProvider = class {
3420
3697
  * @returns true if the file was created or modified
3421
3698
  */
3422
3699
  updateInstructionFile(projectDir) {
3423
- const agentsMdPath = join15(projectDir, "AGENTS.md");
3700
+ const agentsMdPath = join16(projectDir, "AGENTS.md");
3424
3701
  let content = "";
3425
3702
  let existed = false;
3426
- if (existsSync9(agentsMdPath)) {
3427
- content = readFileSync6(agentsMdPath, "utf-8");
3703
+ if (existsSync11(agentsMdPath)) {
3704
+ content = readFileSync8(agentsMdPath, "utf-8");
3428
3705
  existed = true;
3429
3706
  }
3430
3707
  const missingRefs = INSTRUCTION_REFERENCES4.filter((ref) => !content.includes(ref));
@@ -3438,7 +3715,7 @@ var GeminiCliInstallProvider = class {
3438
3715
  } else {
3439
3716
  content = refsBlock + "\n";
3440
3717
  }
3441
- writeFileSync5(agentsMdPath, content, "utf-8");
3718
+ writeFileSync6(agentsMdPath, content, "utf-8");
3442
3719
  return true;
3443
3720
  }
3444
3721
  };
@@ -3539,8 +3816,8 @@ var GeminiCliAdapter = class {
3539
3816
  } catch {
3540
3817
  details.cliAvailable = false;
3541
3818
  }
3542
- const geminiConfigDir = join16(homedir9(), ".gemini");
3543
- const configExists = existsSync10(geminiConfigDir);
3819
+ const geminiConfigDir = join17(homedir11(), ".gemini");
3820
+ const configExists = existsSync12(geminiConfigDir);
3544
3821
  details.configDirExists = configExists;
3545
3822
  const healthy = cliAvailable;
3546
3823
  details.cliAvailable = cliAvailable;
@@ -3573,9 +3850,9 @@ function createAdapter4() {
3573
3850
 
3574
3851
  // packages/adapters/src/providers/kimi/adapter.ts
3575
3852
  import { exec as exec5 } from "node:child_process";
3576
- import { existsSync as existsSync12 } from "node:fs";
3577
- import { homedir as homedir10 } from "node:os";
3578
- import { join as join18 } from "node:path";
3853
+ import { existsSync as existsSync14 } from "node:fs";
3854
+ import { homedir as homedir12 } from "node:os";
3855
+ import { join as join19 } from "node:path";
3579
3856
  import { promisify as promisify5 } from "node:util";
3580
3857
 
3581
3858
  // packages/adapters/src/providers/kimi/hooks.ts
@@ -3634,8 +3911,8 @@ var KimiHookProvider = class {
3634
3911
  };
3635
3912
 
3636
3913
  // packages/adapters/src/providers/kimi/install.ts
3637
- import { existsSync as existsSync11, readFileSync as readFileSync7, writeFileSync as writeFileSync6 } from "node:fs";
3638
- import { join as join17 } from "node:path";
3914
+ import { existsSync as existsSync13, readFileSync as readFileSync9, writeFileSync as writeFileSync7 } from "node:fs";
3915
+ import { join as join18 } from "node:path";
3639
3916
  var INSTRUCTION_REFERENCES5 = ["@~/.cleo/templates/CLEO-INJECTION.md", "@.cleo/memory-bridge.md"];
3640
3917
  var KimiInstallProvider = class {
3641
3918
  /**
@@ -3652,7 +3929,7 @@ var KimiInstallProvider = class {
3652
3929
  const details = {};
3653
3930
  instructionFileUpdated = this.updateInstructionFile(projectDir);
3654
3931
  if (instructionFileUpdated) {
3655
- details.instructionFile = join17(projectDir, "AGENTS.md");
3932
+ details.instructionFile = join18(projectDir, "AGENTS.md");
3656
3933
  }
3657
3934
  return {
3658
3935
  success: true,
@@ -3676,10 +3953,10 @@ var KimiInstallProvider = class {
3676
3953
  * @task T163
3677
3954
  */
3678
3955
  async isInstalled() {
3679
- const agentsMdPath = join17(process.cwd(), "AGENTS.md");
3680
- if (existsSync11(agentsMdPath)) {
3956
+ const agentsMdPath = join18(process.cwd(), "AGENTS.md");
3957
+ if (existsSync13(agentsMdPath)) {
3681
3958
  try {
3682
- const content = readFileSync7(agentsMdPath, "utf-8");
3959
+ const content = readFileSync9(agentsMdPath, "utf-8");
3683
3960
  if (INSTRUCTION_REFERENCES5.some((ref) => content.includes(ref))) {
3684
3961
  return true;
3685
3962
  }
@@ -3706,11 +3983,11 @@ var KimiInstallProvider = class {
3706
3983
  * @returns true if the file was created or modified
3707
3984
  */
3708
3985
  updateInstructionFile(projectDir) {
3709
- const agentsMdPath = join17(projectDir, "AGENTS.md");
3986
+ const agentsMdPath = join18(projectDir, "AGENTS.md");
3710
3987
  let content = "";
3711
3988
  let existed = false;
3712
- if (existsSync11(agentsMdPath)) {
3713
- content = readFileSync7(agentsMdPath, "utf-8");
3989
+ if (existsSync13(agentsMdPath)) {
3990
+ content = readFileSync9(agentsMdPath, "utf-8");
3714
3991
  existed = true;
3715
3992
  }
3716
3993
  const missingRefs = INSTRUCTION_REFERENCES5.filter((ref) => !content.includes(ref));
@@ -3724,7 +4001,7 @@ var KimiInstallProvider = class {
3724
4001
  } else {
3725
4002
  content = refsBlock + "\n";
3726
4003
  }
3727
- writeFileSync6(agentsMdPath, content, "utf-8");
4004
+ writeFileSync7(agentsMdPath, content, "utf-8");
3728
4005
  return true;
3729
4006
  }
3730
4007
  };
@@ -3812,8 +4089,8 @@ var KimiAdapter = class {
3812
4089
  } catch {
3813
4090
  details.cliAvailable = false;
3814
4091
  }
3815
- const kimiConfigDir = join18(homedir10(), ".kimi");
3816
- const configExists = existsSync12(kimiConfigDir);
4092
+ const kimiConfigDir = join19(homedir12(), ".kimi");
4093
+ const configExists = existsSync14(kimiConfigDir);
3817
4094
  details.configDirExists = configExists;
3818
4095
  const healthy = cliAvailable;
3819
4096
  details.cliAvailable = cliAvailable;
@@ -3848,8 +4125,8 @@ function createAdapter5() {
3848
4125
  init_opencode();
3849
4126
 
3850
4127
  // packages/adapters/src/registry.ts
3851
- import { readFileSync as readFileSync10 } from "node:fs";
3852
- import { dirname as dirname3, join as join24, resolve } from "node:path";
4128
+ import { readFileSync as readFileSync12 } from "node:fs";
4129
+ import { dirname as dirname3, join as join25, resolve } from "node:path";
3853
4130
  import { fileURLToPath as fileURLToPath2 } from "node:url";
3854
4131
  var PROVIDER_IDS = ["claude-code", "opencode", "cursor", "pi"];
3855
4132
  function getProviderManifests() {
@@ -3857,8 +4134,8 @@ function getProviderManifests() {
3857
4134
  const baseDir = resolve(dirname3(fileURLToPath2(import.meta.url)), "providers");
3858
4135
  for (const providerId of PROVIDER_IDS) {
3859
4136
  try {
3860
- const manifestPath = join24(baseDir, providerId, "manifest.json");
3861
- const raw = readFileSync10(manifestPath, "utf-8");
4137
+ const manifestPath = join25(baseDir, providerId, "manifest.json");
4138
+ const raw = readFileSync12(manifestPath, "utf-8");
3862
4139
  manifests.push(JSON.parse(raw));
3863
4140
  } catch {
3864
4141
  }
@@ -3909,6 +4186,7 @@ export {
3909
4186
  OpenCodeHookProvider,
3910
4187
  OpenCodeInstallProvider,
3911
4188
  OpenCodeSpawnProvider,
4189
+ buildCantEnrichedPrompt,
3912
4190
  checkStatuslineIntegration,
3913
4191
  createAdapter as createClaudeCodeAdapter,
3914
4192
  createAdapter2 as createCodexAdapter,