@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.
@@ -0,0 +1,130 @@
1
+ /**
2
+ * Shared CANT context builder for all spawn providers.
3
+ *
4
+ * Extracts the Pi bridge's CANT discovery/compile/inject logic into a reusable
5
+ * module that any spawn provider (Claude Code, OpenCode, Cursor, etc.) can call
6
+ * to enrich agent prompts with:
7
+ *
8
+ * 1. Compiled CANT bundle (team topology, agent personas, tool ACLs)
9
+ * 2. Memory bridge (recent decisions, handoff notes, key patterns)
10
+ * 3. Mental model injection (validate-on-load agent-specific observations)
11
+ *
12
+ * All operations are best-effort: if any step fails (missing packages, empty
13
+ * directories, compilation errors), the base prompt is returned unchanged.
14
+ * This guarantees agents always spawn — CANT context is an enrichment, not a gate.
15
+ *
16
+ * Reference implementation: packages/cleo-os/extensions/cleo-cant-bridge.ts
17
+ * (Pi-only; this module generalizes the same logic for all providers)
18
+ *
19
+ * @task T555
20
+ */
21
+ /** Per-tier file counts for diagnostic reporting. */
22
+ export interface TierDiscoveryStats {
23
+ global: number;
24
+ user: number;
25
+ project: number;
26
+ overrides: number;
27
+ merged: number;
28
+ }
29
+ /** Minimal observation shape returned by memoryFind / searchBrainCompact. */
30
+ export interface MentalModelObservation {
31
+ id: string;
32
+ type: string;
33
+ title: string;
34
+ date?: string;
35
+ }
36
+ /** Options for the main enrichment function. */
37
+ export interface BuildCantEnrichedPromptOptions {
38
+ /** Project root directory for .cleo/cant/ discovery and brain.db access. */
39
+ projectDir: string;
40
+ /** The raw prompt to enrich. Returned unchanged if no CANT context is available. */
41
+ basePrompt: string;
42
+ /** Agent name for mental model injection. Omit to skip mental model fetch. */
43
+ agentName?: string;
44
+ }
45
+ /**
46
+ * Recursively discover `.cant` files in a directory.
47
+ *
48
+ * @param dir - The directory to scan recursively.
49
+ * @returns An array of absolute paths to `.cant` files found.
50
+ */
51
+ export declare function discoverCantFiles(dir: string): string[];
52
+ /**
53
+ * Resolve XDG-compliant paths for the 3-tier CANT hierarchy.
54
+ *
55
+ * Respects `XDG_DATA_HOME` and `XDG_CONFIG_HOME` environment variables.
56
+ * Falls back to XDG defaults (`~/.local/share/` and `~/.config/`).
57
+ *
58
+ * @param projectDir - The project root directory (for the project tier).
59
+ * @returns An object with `global`, `user`, and `project` CANT directory paths.
60
+ */
61
+ export declare function resolveThreeTierPaths(projectDir: string): {
62
+ global: string;
63
+ user: string;
64
+ project: string;
65
+ };
66
+ /**
67
+ * Discover `.cant` files across all three tiers with override semantics.
68
+ *
69
+ * Scans global, user, and project tiers. Files in higher-precedence tiers
70
+ * override files in lower-precedence tiers that share the same basename.
71
+ * The precedence order is: project > user > global.
72
+ *
73
+ * @param projectDir - The project root directory.
74
+ * @returns An object containing the merged file list and per-tier statistics.
75
+ */
76
+ export declare function discoverCantFilesMultiTier(projectDir: string): {
77
+ files: string[];
78
+ stats: TierDiscoveryStats;
79
+ };
80
+ /**
81
+ * Read the memory bridge file from a project's .cleo/ directory.
82
+ *
83
+ * @param projectDir - The project root directory.
84
+ * @returns The memory bridge content, or null if not found or empty.
85
+ */
86
+ export declare function readMemoryBridge(projectDir: string): string | null;
87
+ /**
88
+ * Build the memory-bridge system-prompt block appended to every agent.
89
+ *
90
+ * Wraps the raw memory-bridge.md content in a clearly labeled section
91
+ * so the agent knows this is the CLEO project memory context.
92
+ *
93
+ * @param content - The raw memory-bridge.md content.
94
+ * @returns The formatted memory-bridge block for system prompt injection.
95
+ */
96
+ export declare function buildMemoryBridgeBlock(content: string): string;
97
+ /**
98
+ * Build the validate-on-load mental-model injection string.
99
+ *
100
+ * Pure function — no I/O, safe to call in tests without a real DB.
101
+ *
102
+ * @param agentName - Name of the spawned agent (used in the header line).
103
+ * @param observations - Prior mental-model observations to list.
104
+ * @returns System-prompt block with preamble and numbered observations,
105
+ * or empty string when `observations` is empty.
106
+ */
107
+ export declare function buildMentalModelInjection(agentName: string, observations: MentalModelObservation[]): string;
108
+ /**
109
+ * Build an enriched prompt with CANT context, memory bridge, and mental model.
110
+ *
111
+ * This is the universal entry point for all spawn providers. It performs the
112
+ * same operations as the Pi bridge (cleo-cant-bridge.ts) but returns a string
113
+ * rather than hooking into Pi events:
114
+ *
115
+ * 1. Discovers `.cant` files across 3 tiers (global → user → project)
116
+ * 2. Compiles the CANT bundle via `@cleocode/cant`'s `compileBundle()`
117
+ * 3. Renders the compiled system prompt
118
+ * 4. Reads the memory bridge from `.cleo/memory-bridge.md`
119
+ * 5. Fetches mental model observations for the named agent
120
+ * 6. Concatenates: basePrompt + CANT bundle + memory bridge + mental model
121
+ *
122
+ * All operations are best-effort. If any step fails, the base prompt is
123
+ * returned unchanged. CANT context is an enrichment, not a gate — agents
124
+ * always spawn regardless of CANT availability.
125
+ *
126
+ * @param options - Project dir, base prompt, and optional agent name.
127
+ * @returns The enriched prompt string, or basePrompt unchanged on failure.
128
+ */
129
+ export declare function buildCantEnrichedPrompt(options: BuildCantEnrichedPromptOptions): Promise<string>;
130
+ //# sourceMappingURL=cant-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cant-context.d.ts","sourceRoot":"","sources":["../src/cant-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAUH,qDAAqD;AACrD,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,6EAA6E;AAC7E,MAAM,WAAW,sBAAsB;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,gDAAgD;AAChD,MAAM,WAAW,8BAA8B;IAC7C,4EAA4E;IAC5E,UAAU,EAAE,MAAM,CAAC;IACnB,oFAAoF;IACpF,UAAU,EAAE,MAAM,CAAC;IACnB,8EAA8E;IAC9E,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAoBD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAcvD;AAED;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,MAAM,GAAG;IACzD,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB,CAUA;AAED;;;;;;;;;GASG;AACH,wBAAgB,0BAA0B,CAAC,UAAU,EAAE,MAAM,GAAG;IAC9D,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,KAAK,EAAE,kBAAkB,CAAC;CAC3B,CAmCA;AAMD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CASlE;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAQ9D;AAMD;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CACvC,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,sBAAsB,EAAE,GACrC,MAAM,CAaR;AAyDD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,8BAA8B,GACtC,OAAO,CAAC,MAAM,CAAC,CAyDjB"}
package/dist/index.d.ts CHANGED
@@ -12,6 +12,8 @@
12
12
  * The {@link discoverProviders} function and {@link getProviderManifests}
13
13
  * registry enable dynamic adapter loading by AdapterManager.
14
14
  */
15
+ export type { BuildCantEnrichedPromptOptions, TierDiscoveryStats } from './cant-context.js';
16
+ export { buildCantEnrichedPrompt } from './cant-context.js';
15
17
  export { ClaudeCodeAdapter, ClaudeCodeContextMonitorProvider, ClaudeCodeHookProvider, ClaudeCodeInstallProvider, ClaudeCodePathProvider, ClaudeCodeSpawnProvider, ClaudeCodeTransportProvider, checkStatuslineIntegration, createAdapter as createClaudeCodeAdapter, getSetupInstructions, getStatuslineConfig, } from './providers/claude-code/index.js';
16
18
  export { CodexAdapter, CodexHookProvider, CodexInstallProvider, createAdapter as createCodexAdapter, } from './providers/codex/index.js';
17
19
  export { CursorAdapter, CursorHookProvider, CursorInstallProvider, createAdapter as createCursorAdapter, } from './providers/cursor/index.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,EACL,iBAAiB,EACjB,gCAAgC,EAChC,sBAAsB,EACtB,yBAAyB,EACzB,sBAAsB,EACtB,uBAAuB,EACvB,2BAA2B,EAC3B,0BAA0B,EAC1B,aAAa,IAAI,uBAAuB,EACxC,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,oBAAoB,EACpB,aAAa,IAAI,kBAAkB,GACpC,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,qBAAqB,EACrB,aAAa,IAAI,mBAAmB,GACrC,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,aAAa,IAAI,sBAAsB,EACvC,gBAAgB,EAChB,qBAAqB,EACrB,wBAAwB,GACzB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,aAAa,IAAI,iBAAiB,EAClC,WAAW,EACX,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,aAAa,IAAI,qBAAqB,EACtC,eAAe,EACf,oBAAoB,EACpB,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,+BAA+B,CAAC;AACvC,YAAY,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,oBAAoB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