clementine-agent 1.0.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 (190) hide show
  1. package/.env.example +44 -0
  2. package/LICENSE +21 -0
  3. package/README.md +795 -0
  4. package/dist/agent/agent-manager.d.ts +69 -0
  5. package/dist/agent/agent-manager.js +441 -0
  6. package/dist/agent/assistant.d.ts +225 -0
  7. package/dist/agent/assistant.js +3888 -0
  8. package/dist/agent/auto-update.d.ts +32 -0
  9. package/dist/agent/auto-update.js +186 -0
  10. package/dist/agent/daily-planner.d.ts +24 -0
  11. package/dist/agent/daily-planner.js +379 -0
  12. package/dist/agent/execution-advisor.d.ts +10 -0
  13. package/dist/agent/execution-advisor.js +272 -0
  14. package/dist/agent/hooks.d.ts +45 -0
  15. package/dist/agent/hooks.js +564 -0
  16. package/dist/agent/insight-engine.d.ts +66 -0
  17. package/dist/agent/insight-engine.js +225 -0
  18. package/dist/agent/intent-classifier.d.ts +48 -0
  19. package/dist/agent/intent-classifier.js +214 -0
  20. package/dist/agent/link-extractor.d.ts +19 -0
  21. package/dist/agent/link-extractor.js +90 -0
  22. package/dist/agent/mcp-bridge.d.ts +62 -0
  23. package/dist/agent/mcp-bridge.js +435 -0
  24. package/dist/agent/metacognition.d.ts +66 -0
  25. package/dist/agent/metacognition.js +221 -0
  26. package/dist/agent/orchestrator.d.ts +81 -0
  27. package/dist/agent/orchestrator.js +790 -0
  28. package/dist/agent/profiles.d.ts +22 -0
  29. package/dist/agent/profiles.js +91 -0
  30. package/dist/agent/prompt-cache.d.ts +24 -0
  31. package/dist/agent/prompt-cache.js +68 -0
  32. package/dist/agent/prompt-evolver.d.ts +28 -0
  33. package/dist/agent/prompt-evolver.js +279 -0
  34. package/dist/agent/role-scaffolds.d.ts +28 -0
  35. package/dist/agent/role-scaffolds.js +433 -0
  36. package/dist/agent/safe-restart.d.ts +41 -0
  37. package/dist/agent/safe-restart.js +150 -0
  38. package/dist/agent/self-improve.d.ts +66 -0
  39. package/dist/agent/self-improve.js +1706 -0
  40. package/dist/agent/session-event-log.d.ts +114 -0
  41. package/dist/agent/session-event-log.js +233 -0
  42. package/dist/agent/skill-extractor.d.ts +72 -0
  43. package/dist/agent/skill-extractor.js +435 -0
  44. package/dist/agent/source-mods.d.ts +61 -0
  45. package/dist/agent/source-mods.js +230 -0
  46. package/dist/agent/source-preflight.d.ts +25 -0
  47. package/dist/agent/source-preflight.js +100 -0
  48. package/dist/agent/stall-guard.d.ts +62 -0
  49. package/dist/agent/stall-guard.js +109 -0
  50. package/dist/agent/strategic-planner.d.ts +60 -0
  51. package/dist/agent/strategic-planner.js +352 -0
  52. package/dist/agent/team-bus.d.ts +89 -0
  53. package/dist/agent/team-bus.js +556 -0
  54. package/dist/agent/team-router.d.ts +26 -0
  55. package/dist/agent/team-router.js +37 -0
  56. package/dist/agent/tool-loop-detector.d.ts +59 -0
  57. package/dist/agent/tool-loop-detector.js +242 -0
  58. package/dist/agent/workflow-runner.d.ts +36 -0
  59. package/dist/agent/workflow-runner.js +317 -0
  60. package/dist/agent/workflow-variables.d.ts +16 -0
  61. package/dist/agent/workflow-variables.js +62 -0
  62. package/dist/channels/discord-agent-bot.d.ts +101 -0
  63. package/dist/channels/discord-agent-bot.js +881 -0
  64. package/dist/channels/discord-bot-manager.d.ts +80 -0
  65. package/dist/channels/discord-bot-manager.js +262 -0
  66. package/dist/channels/discord-utils.d.ts +51 -0
  67. package/dist/channels/discord-utils.js +293 -0
  68. package/dist/channels/discord.d.ts +12 -0
  69. package/dist/channels/discord.js +1832 -0
  70. package/dist/channels/slack-agent-bot.d.ts +73 -0
  71. package/dist/channels/slack-agent-bot.js +320 -0
  72. package/dist/channels/slack-bot-manager.d.ts +66 -0
  73. package/dist/channels/slack-bot-manager.js +236 -0
  74. package/dist/channels/slack-utils.d.ts +39 -0
  75. package/dist/channels/slack-utils.js +189 -0
  76. package/dist/channels/slack.d.ts +11 -0
  77. package/dist/channels/slack.js +196 -0
  78. package/dist/channels/telegram.d.ts +10 -0
  79. package/dist/channels/telegram.js +235 -0
  80. package/dist/channels/webhook.d.ts +9 -0
  81. package/dist/channels/webhook.js +78 -0
  82. package/dist/channels/whatsapp.d.ts +11 -0
  83. package/dist/channels/whatsapp.js +181 -0
  84. package/dist/cli/chat.d.ts +14 -0
  85. package/dist/cli/chat.js +220 -0
  86. package/dist/cli/cron.d.ts +17 -0
  87. package/dist/cli/cron.js +552 -0
  88. package/dist/cli/dashboard.d.ts +15 -0
  89. package/dist/cli/dashboard.js +17677 -0
  90. package/dist/cli/index.d.ts +3 -0
  91. package/dist/cli/index.js +2474 -0
  92. package/dist/cli/routes/delegations.d.ts +19 -0
  93. package/dist/cli/routes/delegations.js +154 -0
  94. package/dist/cli/routes/digest.d.ts +17 -0
  95. package/dist/cli/routes/digest.js +375 -0
  96. package/dist/cli/routes/goals.d.ts +14 -0
  97. package/dist/cli/routes/goals.js +258 -0
  98. package/dist/cli/routes/workflows.d.ts +18 -0
  99. package/dist/cli/routes/workflows.js +97 -0
  100. package/dist/cli/setup.d.ts +8 -0
  101. package/dist/cli/setup.js +619 -0
  102. package/dist/cli/tunnel.d.ts +35 -0
  103. package/dist/cli/tunnel.js +141 -0
  104. package/dist/config.d.ts +145 -0
  105. package/dist/config.js +278 -0
  106. package/dist/events/bus.d.ts +43 -0
  107. package/dist/events/bus.js +136 -0
  108. package/dist/gateway/cron-scheduler.d.ts +166 -0
  109. package/dist/gateway/cron-scheduler.js +1767 -0
  110. package/dist/gateway/delivery-queue.d.ts +30 -0
  111. package/dist/gateway/delivery-queue.js +110 -0
  112. package/dist/gateway/heartbeat-scheduler.d.ts +99 -0
  113. package/dist/gateway/heartbeat-scheduler.js +1298 -0
  114. package/dist/gateway/heartbeat.d.ts +3 -0
  115. package/dist/gateway/heartbeat.js +3 -0
  116. package/dist/gateway/lanes.d.ts +24 -0
  117. package/dist/gateway/lanes.js +76 -0
  118. package/dist/gateway/notifications.d.ts +29 -0
  119. package/dist/gateway/notifications.js +75 -0
  120. package/dist/gateway/router.d.ts +210 -0
  121. package/dist/gateway/router.js +1330 -0
  122. package/dist/index.d.ts +12 -0
  123. package/dist/index.js +1015 -0
  124. package/dist/memory/chunker.d.ts +28 -0
  125. package/dist/memory/chunker.js +226 -0
  126. package/dist/memory/consolidation.d.ts +44 -0
  127. package/dist/memory/consolidation.js +171 -0
  128. package/dist/memory/context-assembler.d.ts +50 -0
  129. package/dist/memory/context-assembler.js +149 -0
  130. package/dist/memory/embeddings.d.ts +38 -0
  131. package/dist/memory/embeddings.js +180 -0
  132. package/dist/memory/graph-store.d.ts +66 -0
  133. package/dist/memory/graph-store.js +613 -0
  134. package/dist/memory/mmr.d.ts +21 -0
  135. package/dist/memory/mmr.js +75 -0
  136. package/dist/memory/search.d.ts +26 -0
  137. package/dist/memory/search.js +67 -0
  138. package/dist/memory/store.d.ts +530 -0
  139. package/dist/memory/store.js +2022 -0
  140. package/dist/security/integrity.d.ts +24 -0
  141. package/dist/security/integrity.js +58 -0
  142. package/dist/security/patterns.d.ts +34 -0
  143. package/dist/security/patterns.js +110 -0
  144. package/dist/security/scanner.d.ts +32 -0
  145. package/dist/security/scanner.js +263 -0
  146. package/dist/tools/admin-tools.d.ts +12 -0
  147. package/dist/tools/admin-tools.js +1278 -0
  148. package/dist/tools/external-tools.d.ts +11 -0
  149. package/dist/tools/external-tools.js +1327 -0
  150. package/dist/tools/goal-tools.d.ts +9 -0
  151. package/dist/tools/goal-tools.js +159 -0
  152. package/dist/tools/mcp-server.d.ts +13 -0
  153. package/dist/tools/mcp-server.js +141 -0
  154. package/dist/tools/memory-tools.d.ts +10 -0
  155. package/dist/tools/memory-tools.js +568 -0
  156. package/dist/tools/session-tools.d.ts +6 -0
  157. package/dist/tools/session-tools.js +146 -0
  158. package/dist/tools/shared.d.ts +216 -0
  159. package/dist/tools/shared.js +340 -0
  160. package/dist/tools/team-tools.d.ts +6 -0
  161. package/dist/tools/team-tools.js +447 -0
  162. package/dist/tools/tool-meta.d.ts +34 -0
  163. package/dist/tools/tool-meta.js +133 -0
  164. package/dist/tools/vault-tools.d.ts +8 -0
  165. package/dist/tools/vault-tools.js +457 -0
  166. package/dist/types.d.ts +716 -0
  167. package/dist/types.js +16 -0
  168. package/dist/vault-migrations/0001-add-execution-framework.d.ts +10 -0
  169. package/dist/vault-migrations/0001-add-execution-framework.js +47 -0
  170. package/dist/vault-migrations/0002-add-agentic-communication.d.ts +12 -0
  171. package/dist/vault-migrations/0002-add-agentic-communication.js +79 -0
  172. package/dist/vault-migrations/0003-update-execution-pipeline-narration.d.ts +11 -0
  173. package/dist/vault-migrations/0003-update-execution-pipeline-narration.js +73 -0
  174. package/dist/vault-migrations/helpers.d.ts +14 -0
  175. package/dist/vault-migrations/helpers.js +44 -0
  176. package/dist/vault-migrations/runner.d.ts +14 -0
  177. package/dist/vault-migrations/runner.js +139 -0
  178. package/dist/vault-migrations/types.d.ts +42 -0
  179. package/dist/vault-migrations/types.js +9 -0
  180. package/install.sh +320 -0
  181. package/package.json +84 -0
  182. package/scripts/postinstall.js +125 -0
  183. package/vault/00-System/AGENTS.md +66 -0
  184. package/vault/00-System/CRON.md +71 -0
  185. package/vault/00-System/HEARTBEAT.md +58 -0
  186. package/vault/00-System/MEMORY.md +16 -0
  187. package/vault/00-System/SOUL.md +96 -0
  188. package/vault/05-Tasks/TASKS.md +19 -0
  189. package/vault/06-Templates/_Daily-Template.md +28 -0
  190. package/vault/06-Templates/_People-Template.md +22 -0
@@ -0,0 +1,225 @@
1
+ /**
2
+ * Clementine TypeScript — Core assistant (Agent Layer).
3
+ *
4
+ * Uses @anthropic-ai/claude-agent-sdk query() with built-in tools + external MCP stdio server.
5
+ * Features:
6
+ * - canUseTool: SDK-level security enforcement (blocks dangerous operations)
7
+ * - Auto-memory: background Haiku pass extracts facts after every exchange
8
+ * - Session rotation: auto-clears sessions before hitting context limits
9
+ * - Session expiry: sessions expire after 24 hours of inactivity
10
+ * - Env isolation: Claude subprocess doesn't see credential env vars
11
+ */
12
+ import type { AgentProfile, OnTextCallback, OnToolActivityCallback, VerboseLevel } from '../types.js';
13
+ import { AgentManager } from './agent-manager.js';
14
+ /**
15
+ * Estimate token count using a weighted heuristic.
16
+ * BPE tokenizers average ~4 chars/token for prose, but code, punctuation,
17
+ * and whitespace-heavy content tokenize differently.
18
+ */
19
+ export declare function estimateTokens(text: string): number;
20
+ export interface ProjectMeta {
21
+ path: string;
22
+ description?: string;
23
+ keywords?: string[];
24
+ }
25
+ /** Find a linked project by name (case-insensitive, supports partial match). */
26
+ export declare function findProjectByName(query: string): ProjectMeta | null;
27
+ /** Get all linked projects. */
28
+ export declare function getLinkedProjects(): ProjectMeta[];
29
+ export declare class PersonalAssistant {
30
+ static readonly MAX_SESSION_EXCHANGES = 40;
31
+ private sessions;
32
+ private exchangeCounts;
33
+ private sessionTimestamps;
34
+ private lastExchanges;
35
+ private pendingContext;
36
+ private restoredSessions;
37
+ private profileManager;
38
+ private promptCache;
39
+ private _lastDailyNotePath;
40
+ private memoryStore;
41
+ private _lastUserMessage?;
42
+ private onUnleashedComplete;
43
+ private onPhaseComplete;
44
+ private onPhaseProgress;
45
+ onSkillProposed: ((skill: import('../types.js').SkillDocument) => void) | null;
46
+ private _lastMcpStatus;
47
+ private _lastMcpStatusTime;
48
+ /** Terminal reason from the last SDK query — consumed by cron scheduler for precise error classification. */
49
+ private _lastTerminalReason?;
50
+ /** Per-session stall nudge — set after a query shows stall signals, consumed on the next query. */
51
+ private stallNudges;
52
+ private _compactedSessions;
53
+ /** Hot correction buffer — explicit behavioral corrections applied before nightly SI. */
54
+ private hotCorrections;
55
+ constructor();
56
+ private initPromptWatchers;
57
+ /** Log SDK result metrics and store usage. Shared across all query methods. */
58
+ private logQueryResult;
59
+ /** Capture MCP server status from system init messages. */
60
+ private captureMcpStatus;
61
+ setUnleashedCompleteCallback(cb: (jobName: string, result: string) => void): void;
62
+ setPhaseCompleteCallback(cb: (jobName: string, phase: number, totalPhases: number, output: string) => void): void;
63
+ setPhaseProgressCallback(cb: (jobName: string, phase: number, summary: string) => void): void;
64
+ setSkillProposedCallback(cb: (skill: import('../types.js').SkillDocument) => void): void;
65
+ getMcpStatus(): {
66
+ servers: Array<{
67
+ name: string;
68
+ status: string;
69
+ }>;
70
+ updatedAt: string;
71
+ };
72
+ /** Inject a background work result into the session so the next chat naturally references it. */
73
+ injectPendingContext(sessionKey: string, userPrompt: string, result: string): void;
74
+ private initMemoryStore;
75
+ private loadSessions;
76
+ private saveSessions;
77
+ getExchangeCount(sessionKey: string): number;
78
+ getMemoryChunkCount(): number;
79
+ private buildSystemPrompt;
80
+ private buildOptions;
81
+ private retrieveContext;
82
+ /** Cached active goals — avoids N file reads per query. Refreshes every 30s. */
83
+ private _goalCache;
84
+ private static readonly GOAL_CACHE_TTL_MS;
85
+ private loadGoalsFromCache;
86
+ /**
87
+ * Match a user message against active goals by keyword overlap.
88
+ * Returns formatted goal status block for injection into system prompt,
89
+ * or empty string if no goals match.
90
+ */
91
+ private matchGoals;
92
+ chat(text: string, sessionKey?: string | null, options?: {
93
+ onText?: OnTextCallback;
94
+ onToolActivity?: OnToolActivityCallback;
95
+ model?: string;
96
+ maxTurns?: number;
97
+ profile?: AgentProfile;
98
+ securityAnnotation?: string;
99
+ projectOverride?: ProjectMeta;
100
+ verboseLevel?: VerboseLevel;
101
+ abortController?: AbortController;
102
+ }): Promise<[string, string]>;
103
+ private static readonly RATE_LIMIT_MAX_RETRIES;
104
+ private static readonly RATE_LIMIT_BACKOFF;
105
+ private runQuery;
106
+ /**
107
+ * Compact a session's context when nearing the context window limit.
108
+ *
109
+ * Inspired by Anthropic's context compaction pattern: summarize what happened,
110
+ * write to working memory (which is injected into every new system prompt),
111
+ * and rotate the session so the next message starts fresh with the summary.
112
+ *
113
+ * No LLM call — uses buildLocalSummary for instant summarization.
114
+ */
115
+ private compactContext;
116
+ /**
117
+ * Build an instant local summary from in-memory exchange history.
118
+ * No LLM call — returns immediately. Used during session rotation
119
+ * to avoid blocking the user's query.
120
+ */
121
+ private buildLocalSummary;
122
+ /**
123
+ * Auto-save a lightweight handoff file when a session rotates.
124
+ * Uses in-memory exchange history — no LLM call.
125
+ */
126
+ private saveAutoHandoff;
127
+ /**
128
+ * Load a handoff file for a session if one exists.
129
+ * Returns formatted context string or empty string.
130
+ */
131
+ private loadHandoff;
132
+ /**
133
+ * Run an LLM summary in the background and save to memoryStore.
134
+ * Does not block the caller — for future retrieval context only.
135
+ */
136
+ private summarizeSessionAsync;
137
+ private summarizeSession;
138
+ /**
139
+ * Parse a structured checkpoint from an unleashed phase's STATUS SUMMARY output.
140
+ * Returns null if no recognizable structure is found.
141
+ */
142
+ static parseUnleashedCheckpoint(output: string): {
143
+ summary: string;
144
+ completed: string[];
145
+ remaining: string[];
146
+ artifacts: string[];
147
+ nextAction?: string;
148
+ } | null;
149
+ /** Fire-and-forget: extract a reusable skill from a successful execution. */
150
+ private extractSkillFromExecution;
151
+ private preRotationFlush;
152
+ private lastExtractionTime;
153
+ private worthExtracting;
154
+ private spawnMemoryExtraction;
155
+ private static readonly MEMORY_TOOL_NAMES;
156
+ private extractMemory;
157
+ heartbeat(standingInstructions: string, changesSummary?: string, timeContext?: string, dedupContext?: string, profile?: AgentProfile | null): Promise<string>;
158
+ runPlanStep(stepId: string, prompt: string, opts?: {
159
+ tier?: number;
160
+ maxTurns?: number;
161
+ model?: string;
162
+ disableTools?: boolean;
163
+ outputFormat?: {
164
+ type: 'json_schema';
165
+ schema: Record<string, unknown>;
166
+ };
167
+ delegateProfile?: AgentProfile;
168
+ }): Promise<string>;
169
+ runCronJob(jobName: string, jobPrompt: string, tier?: number, maxTurns?: number, model?: string, workDir?: string, timeoutMs?: number, successCriteria?: string[]): Promise<string>;
170
+ /**
171
+ * Goal-backward verification pass using Haiku after cron job execution.
172
+ * Instead of vague quality ratings, verifies actual outcomes:
173
+ * 1. Did the output address the task? (existence)
174
+ * 2. Is it substantive, not a stub/placeholder? (substance)
175
+ * 3. Does it connect to the goal / produce actionable results? (wired)
176
+ */
177
+ private runCronReflection;
178
+ runUnleashedTask(jobName: string, jobPrompt: string, tier?: number, maxTurns?: number, model?: string, workDir?: string, maxHours?: number): Promise<string>;
179
+ /**
180
+ * Run a team message as an unleashed-style autonomous task.
181
+ * Gives team agents the same multi-phase execution as cron jobs,
182
+ * instead of being killed by the 5-minute interactive chat timeout.
183
+ *
184
+ * @param onText Streaming callback for real-time progress updates
185
+ */
186
+ runTeamTask(fromName: string, fromSlug: string, content: string, profile: AgentProfile, onText?: (token: string) => void): Promise<string>;
187
+ /**
188
+ * Inject a user/assistant exchange into a session's context without running
189
+ * a query. Used to give the DM session visibility of cron/heartbeat outputs
190
+ * so follow-up conversation has context.
191
+ */
192
+ injectContext(sessionKey: string, userText: string, assistantText: string): void;
193
+ getRecentActivity(sinceIso: string): Array<{
194
+ sessionKey: string;
195
+ role: string;
196
+ content: string;
197
+ createdAt: string;
198
+ }>;
199
+ searchMemory(query: string, limit?: number): Array<{
200
+ sourceFile: string;
201
+ section: string;
202
+ content: string;
203
+ score: number;
204
+ }>;
205
+ /** Expose memory store for direct operations (consolidation, etc.). */
206
+ getMemoryStore(): any;
207
+ /** Get the terminal reason from the last SDK query (consumed after read). */
208
+ consumeLastTerminalReason(): string | undefined;
209
+ /**
210
+ * List subagent IDs for a given session.
211
+ * Uses the new SDK listSubagents() API for cross-agent introspection.
212
+ */
213
+ getSubagentList(sessionId: string): Promise<string[]>;
214
+ /**
215
+ * Get conversation messages from a subagent's transcript.
216
+ * Enables cross-agent learning — feed into memory extraction.
217
+ */
218
+ getSubagentHistory(sessionId: string, agentId: string, limit?: number): Promise<Array<{
219
+ type: string;
220
+ content: string;
221
+ }>>;
222
+ clearSession(sessionKey: string): void;
223
+ getProfileManager(): AgentManager;
224
+ }
225
+ //# sourceMappingURL=assistant.d.ts.map