claude-cognitive 0.1.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.
Files changed (196) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +256 -0
  3. package/bin/claude-cognitive.js +9 -0
  4. package/dist/agents/context.d.ts +40 -0
  5. package/dist/agents/context.d.ts.map +1 -0
  6. package/dist/agents/context.js +144 -0
  7. package/dist/agents/context.js.map +1 -0
  8. package/dist/agents/index.d.ts +9 -0
  9. package/dist/agents/index.d.ts.map +1 -0
  10. package/dist/agents/index.js +11 -0
  11. package/dist/agents/index.js.map +1 -0
  12. package/dist/agents/loader.d.ts +48 -0
  13. package/dist/agents/loader.d.ts.map +1 -0
  14. package/dist/agents/loader.js +157 -0
  15. package/dist/agents/loader.js.map +1 -0
  16. package/dist/agents/templates.d.ts +51 -0
  17. package/dist/agents/templates.d.ts.map +1 -0
  18. package/dist/agents/templates.js +186 -0
  19. package/dist/agents/templates.js.map +1 -0
  20. package/dist/agents/types.d.ts +52 -0
  21. package/dist/agents/types.d.ts.map +1 -0
  22. package/dist/agents/types.js +6 -0
  23. package/dist/agents/types.js.map +1 -0
  24. package/dist/cli/commands/config.d.ts +10 -0
  25. package/dist/cli/commands/config.d.ts.map +1 -0
  26. package/dist/cli/commands/config.js +22 -0
  27. package/dist/cli/commands/config.js.map +1 -0
  28. package/dist/cli/commands/index.d.ts +17 -0
  29. package/dist/cli/commands/index.d.ts.map +1 -0
  30. package/dist/cli/commands/index.js +17 -0
  31. package/dist/cli/commands/index.js.map +1 -0
  32. package/dist/cli/commands/init.d.ts +10 -0
  33. package/dist/cli/commands/init.d.ts.map +1 -0
  34. package/dist/cli/commands/init.js +109 -0
  35. package/dist/cli/commands/init.js.map +1 -0
  36. package/dist/cli/commands/install.d.ts +10 -0
  37. package/dist/cli/commands/install.d.ts.map +1 -0
  38. package/dist/cli/commands/install.js +440 -0
  39. package/dist/cli/commands/install.js.map +1 -0
  40. package/dist/cli/commands/learn.d.ts +10 -0
  41. package/dist/cli/commands/learn.d.ts.map +1 -0
  42. package/dist/cli/commands/learn.js +33 -0
  43. package/dist/cli/commands/learn.js.map +1 -0
  44. package/dist/cli/commands/recall.d.ts +10 -0
  45. package/dist/cli/commands/recall.d.ts.map +1 -0
  46. package/dist/cli/commands/recall.js +52 -0
  47. package/dist/cli/commands/recall.js.map +1 -0
  48. package/dist/cli/commands/reflect.d.ts +10 -0
  49. package/dist/cli/commands/reflect.d.ts.map +1 -0
  50. package/dist/cli/commands/reflect.js +48 -0
  51. package/dist/cli/commands/reflect.js.map +1 -0
  52. package/dist/cli/commands/semantic.d.ts +10 -0
  53. package/dist/cli/commands/semantic.d.ts.map +1 -0
  54. package/dist/cli/commands/semantic.js +67 -0
  55. package/dist/cli/commands/semantic.js.map +1 -0
  56. package/dist/cli/commands/serve.d.ts +10 -0
  57. package/dist/cli/commands/serve.d.ts.map +1 -0
  58. package/dist/cli/commands/serve.js +61 -0
  59. package/dist/cli/commands/serve.js.map +1 -0
  60. package/dist/cli/commands/status.d.ts +10 -0
  61. package/dist/cli/commands/status.d.ts.map +1 -0
  62. package/dist/cli/commands/status.js +44 -0
  63. package/dist/cli/commands/status.js.map +1 -0
  64. package/dist/cli/commands/sync.d.ts +10 -0
  65. package/dist/cli/commands/sync.d.ts.map +1 -0
  66. package/dist/cli/commands/sync.js +260 -0
  67. package/dist/cli/commands/sync.js.map +1 -0
  68. package/dist/cli/commands/uninstall.d.ts +10 -0
  69. package/dist/cli/commands/uninstall.d.ts.map +1 -0
  70. package/dist/cli/commands/uninstall.js +205 -0
  71. package/dist/cli/commands/uninstall.js.map +1 -0
  72. package/dist/cli/commands/update-bank.d.ts +10 -0
  73. package/dist/cli/commands/update-bank.d.ts.map +1 -0
  74. package/dist/cli/commands/update-bank.js +129 -0
  75. package/dist/cli/commands/update-bank.js.map +1 -0
  76. package/dist/cli/index.d.ts +6 -0
  77. package/dist/cli/index.d.ts.map +1 -0
  78. package/dist/cli/index.js +56 -0
  79. package/dist/cli/index.js.map +1 -0
  80. package/dist/cli/utils/errors.d.ts +42 -0
  81. package/dist/cli/utils/errors.d.ts.map +1 -0
  82. package/dist/cli/utils/errors.js +78 -0
  83. package/dist/cli/utils/errors.js.map +1 -0
  84. package/dist/cli/utils/index.d.ts +9 -0
  85. package/dist/cli/utils/index.d.ts.map +1 -0
  86. package/dist/cli/utils/index.js +7 -0
  87. package/dist/cli/utils/index.js.map +1 -0
  88. package/dist/cli/utils/output.d.ts +90 -0
  89. package/dist/cli/utils/output.d.ts.map +1 -0
  90. package/dist/cli/utils/output.js +164 -0
  91. package/dist/cli/utils/output.js.map +1 -0
  92. package/dist/client.d.ts +200 -0
  93. package/dist/client.d.ts.map +1 -0
  94. package/dist/client.js +447 -0
  95. package/dist/client.js.map +1 -0
  96. package/dist/config.d.ts +44 -0
  97. package/dist/config.d.ts.map +1 -0
  98. package/dist/config.js +264 -0
  99. package/dist/config.js.map +1 -0
  100. package/dist/errors.d.ts +72 -0
  101. package/dist/errors.d.ts.map +1 -0
  102. package/dist/errors.js +188 -0
  103. package/dist/errors.js.map +1 -0
  104. package/dist/events.d.ts +148 -0
  105. package/dist/events.d.ts.map +1 -0
  106. package/dist/events.js +115 -0
  107. package/dist/events.js.map +1 -0
  108. package/dist/hooks/index.d.ts +7 -0
  109. package/dist/hooks/index.d.ts.map +1 -0
  110. package/dist/hooks/index.js +7 -0
  111. package/dist/hooks/index.js.map +1 -0
  112. package/dist/hooks/inject-context.d.ts +18 -0
  113. package/dist/hooks/inject-context.d.ts.map +1 -0
  114. package/dist/hooks/inject-context.js +57 -0
  115. package/dist/hooks/inject-context.js.map +1 -0
  116. package/dist/hooks/process-session.d.ts +18 -0
  117. package/dist/hooks/process-session.d.ts.map +1 -0
  118. package/dist/hooks/process-session.js +119 -0
  119. package/dist/hooks/process-session.js.map +1 -0
  120. package/dist/index.d.ts +63 -0
  121. package/dist/index.d.ts.map +1 -0
  122. package/dist/index.js +59 -0
  123. package/dist/index.js.map +1 -0
  124. package/dist/learn/analyzers/git.d.ts +62 -0
  125. package/dist/learn/analyzers/git.d.ts.map +1 -0
  126. package/dist/learn/analyzers/git.js +183 -0
  127. package/dist/learn/analyzers/git.js.map +1 -0
  128. package/dist/learn/analyzers/index.d.ts +15 -0
  129. package/dist/learn/analyzers/index.d.ts.map +1 -0
  130. package/dist/learn/analyzers/index.js +10 -0
  131. package/dist/learn/analyzers/index.js.map +1 -0
  132. package/dist/learn/analyzers/package.d.ts +57 -0
  133. package/dist/learn/analyzers/package.d.ts.map +1 -0
  134. package/dist/learn/analyzers/package.js +245 -0
  135. package/dist/learn/analyzers/package.js.map +1 -0
  136. package/dist/learn/analyzers/readme.d.ts +27 -0
  137. package/dist/learn/analyzers/readme.d.ts.map +1 -0
  138. package/dist/learn/analyzers/readme.js +163 -0
  139. package/dist/learn/analyzers/readme.js.map +1 -0
  140. package/dist/learn/analyzers/source.d.ts +70 -0
  141. package/dist/learn/analyzers/source.d.ts.map +1 -0
  142. package/dist/learn/analyzers/source.js +231 -0
  143. package/dist/learn/analyzers/source.js.map +1 -0
  144. package/dist/learn/analyzers/structure.d.ts +39 -0
  145. package/dist/learn/analyzers/structure.d.ts.map +1 -0
  146. package/dist/learn/analyzers/structure.js +172 -0
  147. package/dist/learn/analyzers/structure.js.map +1 -0
  148. package/dist/learn/extractor.d.ts +76 -0
  149. package/dist/learn/extractor.d.ts.map +1 -0
  150. package/dist/learn/extractor.js +302 -0
  151. package/dist/learn/extractor.js.map +1 -0
  152. package/dist/learn/index.d.ts +31 -0
  153. package/dist/learn/index.d.ts.map +1 -0
  154. package/dist/learn/index.js +165 -0
  155. package/dist/learn/index.js.map +1 -0
  156. package/dist/mcp/handlers.d.ts +23 -0
  157. package/dist/mcp/handlers.d.ts.map +1 -0
  158. package/dist/mcp/handlers.js +124 -0
  159. package/dist/mcp/handlers.js.map +1 -0
  160. package/dist/mcp/index.d.ts +32 -0
  161. package/dist/mcp/index.d.ts.map +1 -0
  162. package/dist/mcp/index.js +40 -0
  163. package/dist/mcp/index.js.map +1 -0
  164. package/dist/mcp/server.d.ts +79 -0
  165. package/dist/mcp/server.d.ts.map +1 -0
  166. package/dist/mcp/server.js +277 -0
  167. package/dist/mcp/server.js.map +1 -0
  168. package/dist/mcp/tools.d.ts +59 -0
  169. package/dist/mcp/tools.d.ts.map +1 -0
  170. package/dist/mcp/tools.js +43 -0
  171. package/dist/mcp/tools.js.map +1 -0
  172. package/dist/mcp/types.d.ts +65 -0
  173. package/dist/mcp/types.d.ts.map +1 -0
  174. package/dist/mcp/types.js +6 -0
  175. package/dist/mcp/types.js.map +1 -0
  176. package/dist/mind.d.ts +250 -0
  177. package/dist/mind.d.ts.map +1 -0
  178. package/dist/mind.js +637 -0
  179. package/dist/mind.js.map +1 -0
  180. package/dist/promotion.d.ts +112 -0
  181. package/dist/promotion.d.ts.map +1 -0
  182. package/dist/promotion.js +196 -0
  183. package/dist/promotion.js.map +1 -0
  184. package/dist/retry.d.ts +70 -0
  185. package/dist/retry.d.ts.map +1 -0
  186. package/dist/retry.js +122 -0
  187. package/dist/retry.js.map +1 -0
  188. package/dist/semantic.d.ts +202 -0
  189. package/dist/semantic.d.ts.map +1 -0
  190. package/dist/semantic.js +424 -0
  191. package/dist/semantic.js.map +1 -0
  192. package/dist/types.d.ts +363 -0
  193. package/dist/types.d.ts.map +1 -0
  194. package/dist/types.js +30 -0
  195. package/dist/types.js.map +1 -0
  196. package/package.json +70 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Claudiu Sfetancu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,256 @@
1
+ # claude-cognitive
2
+
3
+ Human-inspired memory system for Claude, powered by [Hindsight](https://github.com/vectorize-io/hindsight).
4
+
5
+ **LLM thinks. Hindsight remembers. Together = mind.**
6
+
7
+ Claude's context clears after each session. claude-cognitive gives Claude persistent memory across sessions - it remembers what it learned, what it did, and forms opinions about your codebase over time.
8
+
9
+ ---
10
+
11
+ ## Quick Start
12
+
13
+ ```bash
14
+ # Install globally
15
+ npm install -g claude-cognitive
16
+
17
+ # Interactive setup (recommended)
18
+ cd /path/to/your/project
19
+ claude-cognitive install
20
+
21
+ # Or manual setup
22
+ claude-cognitive init # Create config
23
+ claude-cognitive learn # Bootstrap memory
24
+ ```
25
+
26
+ The interactive installer will:
27
+
28
+ - Configure memory bank and disposition
29
+ - Set up MCP server for Claude Code
30
+ - Inject memory instructions into CLAUDE.md
31
+ - Optionally bootstrap from your codebase
32
+
33
+ ```bash
34
+ # Check status
35
+ claude-cognitive status
36
+
37
+ # Uninstall from a project
38
+ claude-cognitive uninstall --delete-bank
39
+ ```
40
+
41
+ ---
42
+
43
+ ## How It Works
44
+
45
+ ![Session Lifecycle](./docs/session-lifecycle.svg)
46
+
47
+ ### Core Operations
48
+
49
+ | Operation | What It Does |
50
+ | ----------- | ---------------------------------------------------------------------- |
51
+ | **retain** | Store memories with automatic extraction (what, when, where, who, why) |
52
+ | **recall** | 4-way parallel search: semantic + keyword + graph + temporal |
53
+ | **reflect** | Reason through the bank's disposition, form opinions |
54
+ | **learn** | Bootstrap memory from existing codebase (solves cold start) |
55
+
56
+ ### Memory Types
57
+
58
+ | Type | Purpose | Example |
59
+ | ------------- | ------------------------ | ------------------------------------------------ |
60
+ | `world` | Facts about the codebase | "Auth uses Supabase magic links" |
61
+ | `experience` | What Claude did | "I fixed the redirect by moving AuthProvider" |
62
+ | `opinion` | Beliefs with confidence | "This codebase prefers explicit patterns" (0.85) |
63
+ | `observation` | Cross-session insights | "Auth changes require navigation updates" |
64
+
65
+ ---
66
+
67
+ ## Architecture
68
+
69
+ ![Architecture](./docs/architecture.svg)
70
+
71
+ ### Two Memory Layers
72
+
73
+ | Layer | Storage | Purpose |
74
+ | ------------- | --------------------- | ------------------------------------------------------ |
75
+ | **Hindsight** | PostgreSQL + pgvector | All memories, entity graphs, 4-way retrieval, opinions |
76
+ | **Semantic** | `.claude/memory.md` | Human-curated knowledge, promoted observations |
77
+
78
+ ---
79
+
80
+ ## MCP Tools
81
+
82
+ When running as an MCP server, Claude has access to:
83
+
84
+ ### memory_recall
85
+
86
+ Search project memories for relevant context.
87
+
88
+ ```
89
+ Claude: "I remember we had issues with auth redirects..."
90
+ → memory_recall({ query: "auth redirect issues" })
91
+ ```
92
+
93
+ ### memory_reflect
94
+
95
+ Reason about accumulated knowledge, form opinions.
96
+
97
+ ```
98
+ Claude: "What patterns have I noticed about error handling?"
99
+ → memory_reflect({ query: "error handling patterns" })
100
+ ```
101
+
102
+ ---
103
+
104
+ ## CLI Commands
105
+
106
+ ```bash
107
+ claude-cognitive init # Initialize for project
108
+ claude-cognitive serve # Start MCP server
109
+ claude-cognitive status # Show connection status
110
+ claude-cognitive learn # Bootstrap from codebase
111
+ claude-cognitive learn --depth full # Full analysis with git history
112
+ claude-cognitive recall "query" # Search memories
113
+ claude-cognitive reflect "query" # Reason about knowledge
114
+ claude-cognitive semantic # Show semantic memory
115
+ claude-cognitive config # Show configuration
116
+ ```
117
+
118
+ ---
119
+
120
+ ## Configuration
121
+
122
+ ### .claudemindrc
123
+
124
+ ```json
125
+ {
126
+ "hindsight": {
127
+ "host": "localhost",
128
+ "port": 8888
129
+ },
130
+ "bankId": "my-project",
131
+ "disposition": {
132
+ "skepticism": 4,
133
+ "literalism": 4,
134
+ "empathy": 2
135
+ },
136
+ "background": "Developer assistant for a React Native app",
137
+ "semantic": {
138
+ "path": ".claude/memory.md"
139
+ }
140
+ }
141
+ ```
142
+
143
+ ### Disposition Traits
144
+
145
+ Each memory bank has personality traits that shape how `reflect()` reasons:
146
+
147
+ | Trait | Low (1) | High (5) |
148
+ | ---------- | ----------------------- | --------------------------- |
149
+ | skepticism | Trusting | Questions claims |
150
+ | literalism | Flexible interpretation | Precise, literal |
151
+ | empathy | Fact-focused | Considers emotional context |
152
+
153
+ ---
154
+
155
+ ## Semantic Memory
156
+
157
+ The `.claude/memory.md` file contains human-curated project knowledge:
158
+
159
+ ```markdown
160
+ ## Tech Stack
161
+
162
+ - React Native with Expo SDK 51
163
+ - Supabase for auth and database
164
+ - NativeWind for styling
165
+
166
+ ## Key Decisions
167
+
168
+ - Magic link auth for better mobile UX
169
+ - Zustand for state management
170
+
171
+ ## Critical Paths
172
+
173
+ - Auth: src/lib/supabase.ts → src/providers/AuthProvider.tsx
174
+
175
+ ## Observations
176
+
177
+ <!-- Promoted from Hindsight when confidence > 0.9 -->
178
+
179
+ - Auth changes often require navigation updates
180
+ ```
181
+
182
+ This file is always loaded at session start and takes precedence over Hindsight memories when there are conflicts.
183
+
184
+ ---
185
+
186
+ ## Graceful Degradation
187
+
188
+ When Hindsight is unavailable, claude-cognitive continues working with semantic memory only:
189
+
190
+ | Operation | With Hindsight | Without Hindsight |
191
+ | ------------- | -------------- | -------------------------- |
192
+ | Session start | Full context | Semantic only |
193
+ | recall | 4-way search | Empty results |
194
+ | reflect | LLM reasoning | Error (requires Hindsight) |
195
+ | retain | Stored | Skipped |
196
+
197
+ ---
198
+
199
+ ## API Usage
200
+
201
+ ```typescript
202
+ import { Mind } from "claude-cognitive";
203
+
204
+ const mind = new Mind({
205
+ projectPath: process.cwd(),
206
+ disposition: { skepticism: 4, literalism: 4, empathy: 2 },
207
+ });
208
+
209
+ await mind.init();
210
+
211
+ // Get context at session start
212
+ const context = await mind.onSessionStart();
213
+
214
+ // Recall relevant memories
215
+ const memories = await mind.recall("authentication flow");
216
+
217
+ // Reason about knowledge
218
+ const reflection = await mind.reflect("What patterns exist?");
219
+
220
+ // Store new memory
221
+ await mind.retain("Fixed auth by moving Provider to root");
222
+
223
+ // Bootstrap from codebase
224
+ const result = await mind.learn({ depth: "full" });
225
+ ```
226
+
227
+ ---
228
+
229
+ ## Requirements
230
+
231
+ - **Node.js 18+**
232
+ - **[Hindsight](https://github.com/vectorize-io/hindsight)** server running (for full functionality)
233
+
234
+ Without Hindsight, claude-cognitive works in degraded mode with semantic memory only.
235
+
236
+ ---
237
+
238
+ ## Documentation
239
+
240
+ - **[Getting Started](./docs/getting-started.md)** - Installation and setup guide
241
+ - **[Concepts](./docs/concepts.md)** - Memory networks, operations, architecture
242
+ - **[Configuration](./docs/configuration.md)** - Full configuration reference
243
+ - **[API Reference](./docs/api-reference.md)** - Complete API documentation
244
+ - **[Performance](./docs/performance.md)** - Benchmarks and optimization
245
+
246
+ ---
247
+
248
+ ## Example
249
+
250
+ See the [todo-app example](./examples/todo-app/) for a complete integration.
251
+
252
+ ---
253
+
254
+ ## License
255
+
256
+ MIT
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+
3
+ // CLI entry point for claude-cognitive
4
+ // This file is the bin entry that gets executed when running `claude-cognitive` or `npx claude-cognitive`
5
+
6
+ import("../dist/cli/index.js").catch((error) => {
7
+ console.error("Failed to load claude-cognitive CLI:", error.message);
8
+ process.exit(1);
9
+ });
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Agent context preparation for delegation.
3
+ * @module agents/context
4
+ */
5
+ import type { HindsightClient } from "../client.js";
6
+ import type { AgentContext, AgentTemplate, GetAgentContextOptions } from "./types.js";
7
+ /**
8
+ * Prepare context for agent delegation.
9
+ *
10
+ * This is called by the orchestrator BEFORE delegating to an agent.
11
+ * It retrieves relevant memories and formats them for the agent.
12
+ *
13
+ * @param client - HindsightClient instance
14
+ * @param bankId - Memory bank ID
15
+ * @param template - Agent template to use
16
+ * @param task - Task description for the agent
17
+ * @param options - Context preparation options
18
+ * @returns Agent context with memories and task
19
+ */
20
+ export declare function getAgentContext(client: HindsightClient, bankId: string, template: AgentTemplate, task: string, options?: GetAgentContextOptions): Promise<AgentContext>;
21
+ /**
22
+ * Format agent context as a prompt string.
23
+ *
24
+ * This creates the system prompt / context injection for the agent.
25
+ *
26
+ * @param context - Agent context to format
27
+ * @returns Formatted prompt string
28
+ */
29
+ export declare function formatAgentPrompt(context: AgentContext): string;
30
+ /**
31
+ * Create a minimal context string for quick delegation.
32
+ *
33
+ * Useful when you don't need full memory retrieval.
34
+ *
35
+ * @param template - Agent template
36
+ * @param task - Task description
37
+ * @returns Minimal context string
38
+ */
39
+ export declare function createMinimalContext(template: AgentTemplate, task: string): string;
40
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/agents/context.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAEtF;;;;;;;;;;;;GAYG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,eAAe,EACvB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,aAAa,EACvB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,YAAY,CAAC,CA+BvB;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM,CA2D/D;AAoBD;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,aAAa,EACvB,IAAI,EAAE,MAAM,GACX,MAAM,CAeR"}
@@ -0,0 +1,144 @@
1
+ /**
2
+ * Agent context preparation for delegation.
3
+ * @module agents/context
4
+ */
5
+ /**
6
+ * Prepare context for agent delegation.
7
+ *
8
+ * This is called by the orchestrator BEFORE delegating to an agent.
9
+ * It retrieves relevant memories and formats them for the agent.
10
+ *
11
+ * @param client - HindsightClient instance
12
+ * @param bankId - Memory bank ID
13
+ * @param template - Agent template to use
14
+ * @param task - Task description for the agent
15
+ * @param options - Context preparation options
16
+ * @returns Agent context with memories and task
17
+ */
18
+ export async function getAgentContext(client, bankId, template, task, options = {}) {
19
+ const { budget = "mid", additionalContext, maxMemories = 10 } = options;
20
+ // Recall memories relevant to the task
21
+ const recallOptions = {
22
+ budget,
23
+ factType: "all", // Agent benefits from all memory types
24
+ includeEntities: true,
25
+ };
26
+ let memories = [];
27
+ try {
28
+ memories = await client.recall(bankId, task, recallOptions);
29
+ // Limit to maxMemories
30
+ memories = memories.slice(0, maxMemories);
31
+ }
32
+ catch {
33
+ // If recall fails, proceed without memories
34
+ memories = [];
35
+ }
36
+ const result = {
37
+ template,
38
+ memories,
39
+ task,
40
+ };
41
+ if (additionalContext) {
42
+ result.additionalContext = additionalContext;
43
+ }
44
+ return result;
45
+ }
46
+ /**
47
+ * Format agent context as a prompt string.
48
+ *
49
+ * This creates the system prompt / context injection for the agent.
50
+ *
51
+ * @param context - Agent context to format
52
+ * @returns Formatted prompt string
53
+ */
54
+ export function formatAgentPrompt(context) {
55
+ const { template, memories, task, additionalContext } = context;
56
+ const sections = [];
57
+ // Mission and identity
58
+ sections.push(`# Agent: ${template.name}`);
59
+ sections.push("");
60
+ sections.push("## Mission");
61
+ sections.push(template.mission);
62
+ sections.push("");
63
+ // Tools
64
+ sections.push("## Tools Available");
65
+ for (const tool of template.tools) {
66
+ sections.push(`- ${tool}`);
67
+ }
68
+ sections.push("");
69
+ // Constraints (emphasized)
70
+ sections.push("## Constraints (MUST FOLLOW)");
71
+ for (const constraint of template.constraints) {
72
+ sections.push(`- ${constraint}`);
73
+ }
74
+ sections.push("");
75
+ // Relevant context from memory (provided by orchestrator)
76
+ if (memories.length > 0) {
77
+ sections.push("## Relevant Project Context");
78
+ sections.push("The orchestrator has provided the following relevant memories:");
79
+ sections.push("");
80
+ for (const memory of memories) {
81
+ const prefix = getMemoryPrefix(memory);
82
+ sections.push(`- [${prefix}] ${memory.text}`);
83
+ }
84
+ sections.push("");
85
+ }
86
+ // Additional context from orchestrator
87
+ if (additionalContext) {
88
+ sections.push("## Additional Context");
89
+ sections.push(additionalContext);
90
+ sections.push("");
91
+ }
92
+ // The task
93
+ sections.push("## Your Task");
94
+ sections.push(task);
95
+ sections.push("");
96
+ // Expected output format
97
+ sections.push("## Expected Output Format");
98
+ sections.push(template.outputFormat);
99
+ sections.push("");
100
+ return sections.join("\n");
101
+ }
102
+ /**
103
+ * Get a human-readable prefix for a memory based on its type.
104
+ * @internal
105
+ */
106
+ function getMemoryPrefix(memory) {
107
+ switch (memory.factType) {
108
+ case "experience":
109
+ return "Past experience";
110
+ case "opinion":
111
+ return `Opinion (${memory.confidence?.toFixed(2) ?? "?"})`;
112
+ case "observation":
113
+ return "Observation";
114
+ case "world":
115
+ default:
116
+ return "Fact";
117
+ }
118
+ }
119
+ /**
120
+ * Create a minimal context string for quick delegation.
121
+ *
122
+ * Useful when you don't need full memory retrieval.
123
+ *
124
+ * @param template - Agent template
125
+ * @param task - Task description
126
+ * @returns Minimal context string
127
+ */
128
+ export function createMinimalContext(template, task) {
129
+ return `# Agent: ${template.name}
130
+
131
+ ## Mission
132
+ ${template.mission}
133
+
134
+ ## Constraints
135
+ ${template.constraints.map((c) => `- ${c}`).join("\n")}
136
+
137
+ ## Your Task
138
+ ${task}
139
+
140
+ ## Expected Output Format
141
+ ${template.outputFormat}
142
+ `;
143
+ }
144
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/agents/context.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,MAAuB,EACvB,MAAc,EACd,QAAuB,EACvB,IAAY,EACZ,UAAkC,EAAE;IAEpC,MAAM,EAAE,MAAM,GAAG,KAAK,EAAE,iBAAiB,EAAE,WAAW,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC;IAExE,uCAAuC;IACvC,MAAM,aAAa,GAAkB;QACnC,MAAM;QACN,QAAQ,EAAE,KAAK,EAAE,uCAAuC;QACxD,eAAe,EAAE,IAAI;KACtB,CAAC;IAEF,IAAI,QAAQ,GAAa,EAAE,CAAC;IAC5B,IAAI,CAAC;QACH,QAAQ,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC;QAC5D,uBAAuB;QACvB,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;IAC5C,CAAC;IAAC,MAAM,CAAC;QACP,4CAA4C;QAC5C,QAAQ,GAAG,EAAE,CAAC;IAChB,CAAC;IAED,MAAM,MAAM,GAAiB;QAC3B,QAAQ;QACR,QAAQ;QACR,IAAI;KACL,CAAC;IAEF,IAAI,iBAAiB,EAAE,CAAC;QACtB,MAAM,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;IAC/C,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAqB;IACrD,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAC;IAEhE,MAAM,QAAQ,G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CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;;;EAGpD,IAAI;;;EAGJ,QAAQ,CAAC,YAAY;CACtB,CAAC;AACF,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Agent templates module.
3
+ * @module agents
4
+ */
5
+ export type { AgentTemplate, AgentContext, BuiltInAgentType, GetAgentContextOptions, } from "./types.js";
6
+ export { CODE_EXPLORER_TEMPLATE, CODE_ARCHITECT_TEMPLATE, CODE_REVIEWER_TEMPLATE, BUILT_IN_TEMPLATES, getBuiltInTemplate, getAllBuiltInTemplates, isBuiltInAgent, } from "./templates.js";
7
+ export { parseAgentMarkdown, loadCustomAgents, templateToMarkdown, } from "./loader.js";
8
+ export { getAgentContext, formatAgentPrompt, createMinimalContext, } from "./context.js";
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/agents/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,YAAY,EACV,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACvB,sBAAsB,EACtB,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,EACtB,cAAc,GACf,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,cAAc,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Agent templates module.
3
+ * @module agents
4
+ */
5
+ // Built-in templates
6
+ export { CODE_EXPLORER_TEMPLATE, CODE_ARCHITECT_TEMPLATE, CODE_REVIEWER_TEMPLATE, BUILT_IN_TEMPLATES, getBuiltInTemplate, getAllBuiltInTemplates, isBuiltInAgent, } from "./templates.js";
7
+ // Custom agent loading
8
+ export { parseAgentMarkdown, loadCustomAgents, templateToMarkdown, } from "./loader.js";
9
+ // Context preparation
10
+ export { getAgentContext, formatAgentPrompt, createMinimalContext, } from "./context.js";
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/agents/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH,qBAAqB;AACrB,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACvB,sBAAsB,EACtB,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,EACtB,cAAc,GACf,MAAM,gBAAgB,CAAC;AAExB,uBAAuB;AACvB,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAErB,sBAAsB;AACtB,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,cAAc,CAAC"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Custom agent template loading from .claude/agents/ directory.
3
+ * @module agents/loader
4
+ */
5
+ import type { AgentTemplate } from "./types.js";
6
+ /**
7
+ * Parse a markdown agent template file.
8
+ *
9
+ * Expected format:
10
+ * ```markdown
11
+ * # Agent: name
12
+ *
13
+ * ## Mission
14
+ * ...
15
+ *
16
+ * ## Tools Available
17
+ * - Tool 1
18
+ * - Tool 2
19
+ *
20
+ * ## Output Format
21
+ * ...
22
+ *
23
+ * ## Constraints
24
+ * - Constraint 1
25
+ * - Constraint 2
26
+ * ```
27
+ *
28
+ * @param content - Markdown file content
29
+ * @returns Parsed AgentTemplate, or null if parsing failed
30
+ */
31
+ export declare function parseAgentMarkdown(content: string): AgentTemplate | null;
32
+ /**
33
+ * Load custom agents from .claude/agents/ directory.
34
+ *
35
+ * @param projectPath - Project root directory
36
+ * @returns Array of custom agent templates
37
+ */
38
+ export declare function loadCustomAgents(projectPath: string): Promise<AgentTemplate[]>;
39
+ /**
40
+ * Generate markdown content from an agent template.
41
+ *
42
+ * Useful for creating template files programmatically.
43
+ *
44
+ * @param template - Agent template to convert
45
+ * @returns Markdown string
46
+ */
47
+ export declare function templateToMarkdown(template: AgentTemplate): string;
48
+ //# sourceMappingURL=loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/agents/loader.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI,CAsCxE;AAoBD;;;;;GAKG;AACH,wBAAsB,gBAAgB,CACpC,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,aAAa,EAAE,CAAC,CA8B1B;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,aAAa,GAAG,MAAM,CA+BlE"}