@ekkos/cli 0.2.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.
- package/dist/cache/LocalSessionStore.d.ts +129 -0
- package/dist/cache/LocalSessionStore.js +688 -0
- package/dist/cache/capture.d.ts +26 -0
- package/dist/cache/capture.js +461 -0
- package/dist/cache/index.d.ts +7 -0
- package/dist/cache/index.js +23 -0
- package/dist/cache/types.d.ts +147 -0
- package/dist/cache/types.js +40 -0
- package/dist/commands/init.d.ts +9 -0
- package/dist/commands/init.js +478 -0
- package/dist/commands/run.d.ts +12 -0
- package/dist/commands/run.js +829 -0
- package/dist/commands/setup.d.ts +6 -0
- package/dist/commands/setup.js +658 -0
- package/dist/commands/status.d.ts +1 -0
- package/dist/commands/status.js +109 -0
- package/dist/commands/test.d.ts +1 -0
- package/dist/commands/test.js +157 -0
- package/dist/deploy/agents.d.ts +15 -0
- package/dist/deploy/agents.js +72 -0
- package/dist/deploy/hooks.d.ts +16 -0
- package/dist/deploy/hooks.js +121 -0
- package/dist/deploy/index.d.ts +7 -0
- package/dist/deploy/index.js +24 -0
- package/dist/deploy/instructions.d.ts +12 -0
- package/dist/deploy/instructions.js +36 -0
- package/dist/deploy/mcp.d.ts +19 -0
- package/dist/deploy/mcp.js +109 -0
- package/dist/deploy/plugins.d.ts +19 -0
- package/dist/deploy/plugins.js +62 -0
- package/dist/deploy/settings.d.ts +8 -0
- package/dist/deploy/settings.js +84 -0
- package/dist/deploy/skills.d.ts +19 -0
- package/dist/deploy/skills.js +60 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +71 -0
- package/dist/restore/RestoreOrchestrator.d.ts +48 -0
- package/dist/restore/RestoreOrchestrator.js +481 -0
- package/dist/restore/index.d.ts +4 -0
- package/dist/restore/index.js +20 -0
- package/dist/utils/platform.d.ts +29 -0
- package/dist/utils/platform.js +65 -0
- package/dist/utils/session-words.json +119 -0
- package/dist/utils/state.d.ts +57 -0
- package/dist/utils/state.js +186 -0
- package/dist/utils/templates.d.ts +24 -0
- package/dist/utils/templates.js +118 -0
- package/package.json +48 -0
- package/templates/CLAUDE.md +287 -0
- package/templates/README.md +378 -0
- package/templates/agents/README.md +182 -0
- package/templates/agents/code-reviewer.md +166 -0
- package/templates/agents/debug-detective.md +169 -0
- package/templates/agents/ekkOS_Vercel.md +99 -0
- package/templates/agents/extension-manager.md +229 -0
- package/templates/agents/git-companion.md +185 -0
- package/templates/agents/github-test-agent.md +321 -0
- package/templates/agents/railway-manager.md +179 -0
- package/templates/claude-plugins/PHASE2_COMPLETION.md +346 -0
- package/templates/claude-plugins/PLUGIN_PROPOSALS.md +1776 -0
- package/templates/claude-plugins/README.md +587 -0
- package/templates/claude-plugins/agents/code-reviewer.json +14 -0
- package/templates/claude-plugins/agents/debug-detective.json +15 -0
- package/templates/claude-plugins/agents/git-companion.json +14 -0
- package/templates/claude-plugins/blog-manager/.claude-plugin/plugin.json +8 -0
- package/templates/claude-plugins/blog-manager/commands/blog.md +691 -0
- package/templates/claude-plugins/golden-loop-monitor/.claude-plugin/plugin.json +8 -0
- package/templates/claude-plugins/golden-loop-monitor/commands/loop-status.md +434 -0
- package/templates/claude-plugins/learning-tracker/.claude-plugin/plugin.json +8 -0
- package/templates/claude-plugins/learning-tracker/commands/my-patterns.md +282 -0
- package/templates/claude-plugins/memory-lens/.claude-plugin/plugin.json +8 -0
- package/templates/claude-plugins/memory-lens/commands/memory-search.md +181 -0
- package/templates/claude-plugins/pattern-coach/.claude-plugin/plugin.json +8 -0
- package/templates/claude-plugins/pattern-coach/commands/forge.md +365 -0
- package/templates/claude-plugins/project-schema-validator/.claude-plugin/plugin.json +8 -0
- package/templates/claude-plugins/project-schema-validator/commands/validate-schema.md +582 -0
- package/templates/claude-plugins-admin/AGENT_TEAM_PROPOSALS.md +819 -0
- package/templates/claude-plugins-admin/README.md +446 -0
- package/templates/claude-plugins-admin/autonomous-admin-agent/.claude-plugin/plugin.json +8 -0
- package/templates/claude-plugins-admin/autonomous-admin-agent/commands/agent.md +595 -0
- package/templates/claude-plugins-admin/backend-agent/.claude-plugin/plugin.json +8 -0
- package/templates/claude-plugins-admin/backend-agent/commands/backend.md +798 -0
- package/templates/claude-plugins-admin/deploy-guardian/.claude-plugin/plugin.json +8 -0
- package/templates/claude-plugins-admin/deploy-guardian/commands/deploy.md +554 -0
- package/templates/claude-plugins-admin/frontend-agent/.claude-plugin/plugin.json +8 -0
- package/templates/claude-plugins-admin/frontend-agent/commands/frontend.md +881 -0
- package/templates/claude-plugins-admin/mcp-server-manager/.claude-plugin/plugin.json +8 -0
- package/templates/claude-plugins-admin/mcp-server-manager/commands/mcp.md +85 -0
- package/templates/claude-plugins-admin/memory-system-monitor/.claude-plugin/plugin.json +8 -0
- package/templates/claude-plugins-admin/memory-system-monitor/commands/memory-health.md +569 -0
- package/templates/claude-plugins-admin/qa-agent/.claude-plugin/plugin.json +8 -0
- package/templates/claude-plugins-admin/qa-agent/commands/qa.md +863 -0
- package/templates/claude-plugins-admin/tech-lead-agent/.claude-plugin/plugin.json +8 -0
- package/templates/claude-plugins-admin/tech-lead-agent/commands/lead.md +732 -0
- package/templates/commands/continue.md +47 -0
- package/templates/cursor-hooks/after-agent-response.sh +117 -0
- package/templates/cursor-hooks/before-submit-prompt.sh +419 -0
- package/templates/cursor-hooks/hooks.json +20 -0
- package/templates/cursor-hooks/lib/contract.sh +320 -0
- package/templates/cursor-hooks/stop.sh +75 -0
- package/templates/cursor-rules/ekkos-memory.md +187 -0
- package/templates/hooks/assistant-response.sh +96 -0
- package/templates/hooks/hooks.json +28 -0
- package/templates/hooks/lib/contract.sh +320 -0
- package/templates/hooks/lib/state.sh +158 -0
- package/templates/hooks/session-start.ps1 +41 -0
- package/templates/hooks/session-start.sh +318 -0
- package/templates/hooks/stop.ps1 +16 -0
- package/templates/hooks/stop.sh +989 -0
- package/templates/hooks/user-prompt-submit.ps1 +174 -0
- package/templates/hooks/user-prompt-submit.sh +587 -0
- package/templates/hooks-node/lib/state.js +187 -0
- package/templates/hooks-node/stop.js +416 -0
- package/templates/hooks-node/user-prompt-submit.js +337 -0
- package/templates/plan-template.md +306 -0
- package/templates/rules/00-hooks-contract.mdc +89 -0
- package/templates/rules/30-ekkos-core.mdc +188 -0
- package/templates/rules/31-ekkos-messages.mdc +78 -0
- package/templates/skills/continue/SKILL.md +169 -0
- package/templates/skills/ekkOS_Deep_Recall/Skill.md +282 -0
- package/templates/skills/ekkOS_Learn/Skill.md +265 -0
- package/templates/skills/ekkOS_Memory_First/Skill.md +206 -0
- package/templates/skills/ekkOS_Plan_Assist/Skill.md +302 -0
- package/templates/skills/ekkOS_Preferences/Skill.md +247 -0
- package/templates/skills/ekkOS_Reflect/Skill.md +257 -0
- package/templates/skills/ekkOS_Safety/Skill.md +265 -0
- package/templates/skills/ekkOS_Schema/Skill.md +251 -0
- package/templates/skills/ekkOS_Summary/Skill.md +257 -0
- package/templates/skills/ekkOS_Vault/Skill.md +287 -0
- package/templates/skills/permissions/Skill.md +322 -0
- package/templates/spec-template.md +159 -0
- package/templates/windsurf-hooks/before-submit-prompt.sh +238 -0
- package/templates/windsurf-hooks/hooks.json +10 -0
- package/templates/windsurf-hooks/lib/contract.sh +320 -0
- package/templates/windsurf-rules/ekkos-memory.md +129 -0
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* ═══════════════════════════════════════════════════════════════════════════
|
|
4
|
+
* ekkOS_ Hook: UserPromptSubmit (Claude Code) - CAPTURE + RETRIEVE + INJECT
|
|
5
|
+
* Node.js version - Works on Windows, macOS, Linux without bash dependencies
|
|
6
|
+
*
|
|
7
|
+
* ARCHITECTURE: Dumb Hook, Smart Backend
|
|
8
|
+
* ═══════════════════════════════════════════════════════════════════════════
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const https = require('https');
|
|
12
|
+
const http = require('http');
|
|
13
|
+
const fs = require('fs');
|
|
14
|
+
const path = require('path');
|
|
15
|
+
const os = require('os');
|
|
16
|
+
|
|
17
|
+
// Load state management
|
|
18
|
+
const state = require('./lib/state');
|
|
19
|
+
|
|
20
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
21
|
+
// ANSI Color Codes
|
|
22
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
23
|
+
const CYAN = '\x1b[0;36m';
|
|
24
|
+
const GREEN = '\x1b[0;32m';
|
|
25
|
+
const YELLOW = '\x1b[1;33m';
|
|
26
|
+
const MAGENTA = '\x1b[0;35m';
|
|
27
|
+
const DIM = '\x1b[2m';
|
|
28
|
+
const BOLD = '\x1b[1m';
|
|
29
|
+
const RESET = '\x1b[0m';
|
|
30
|
+
|
|
31
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
32
|
+
// HTTP Request Helper (uses built-in https module)
|
|
33
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
34
|
+
function httpRequest(url, options, data) {
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
const urlObj = new URL(url);
|
|
37
|
+
const lib = urlObj.protocol === 'https:' ? https : http;
|
|
38
|
+
const timeout = options.timeout || 2000;
|
|
39
|
+
|
|
40
|
+
const req = lib.request({
|
|
41
|
+
hostname: urlObj.hostname,
|
|
42
|
+
port: urlObj.port || (urlObj.protocol === 'https:' ? 443 : 80),
|
|
43
|
+
path: urlObj.pathname + urlObj.search,
|
|
44
|
+
method: options.method || 'GET',
|
|
45
|
+
headers: options.headers || {},
|
|
46
|
+
timeout: timeout
|
|
47
|
+
}, (res) => {
|
|
48
|
+
let body = '';
|
|
49
|
+
res.on('data', chunk => body += chunk);
|
|
50
|
+
res.on('end', () => {
|
|
51
|
+
try {
|
|
52
|
+
resolve(JSON.parse(body));
|
|
53
|
+
} catch {
|
|
54
|
+
resolve({ raw: body });
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
req.on('error', (e) => resolve({ error: e.message }));
|
|
60
|
+
req.on('timeout', () => {
|
|
61
|
+
req.destroy();
|
|
62
|
+
resolve({ error: 'timeout' });
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
if (data) req.write(typeof data === 'string' ? data : JSON.stringify(data));
|
|
66
|
+
req.end();
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
71
|
+
// Load Auth Token - PORTABLE: Check 3 sources in priority order
|
|
72
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
73
|
+
function loadAuthToken() {
|
|
74
|
+
const homeDir = os.homedir();
|
|
75
|
+
const ekkosConfig = path.join(homeDir, '.ekkos', 'config.json');
|
|
76
|
+
let authToken = '';
|
|
77
|
+
let userId = '';
|
|
78
|
+
|
|
79
|
+
// 1. First try ~/.ekkos/config.json (set by VS Code extension - most portable)
|
|
80
|
+
// Prefer hookApiKey (scoped key for hooks) over apiKey (legacy)
|
|
81
|
+
if (fs.existsSync(ekkosConfig)) {
|
|
82
|
+
try {
|
|
83
|
+
const config = JSON.parse(fs.readFileSync(ekkosConfig, 'utf8'));
|
|
84
|
+
authToken = config.hookApiKey || config.apiKey || '';
|
|
85
|
+
userId = config.userId || '';
|
|
86
|
+
} catch {}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// 2. Then try project .env.local (for developers with service role key)
|
|
90
|
+
if (!authToken) {
|
|
91
|
+
const envLocal = path.join(state.PROJECT_ROOT, '.env.local');
|
|
92
|
+
if (fs.existsSync(envLocal)) {
|
|
93
|
+
try {
|
|
94
|
+
const content = fs.readFileSync(envLocal, 'utf8');
|
|
95
|
+
const match = content.match(/^SUPABASE_SECRET_KEY=(.+)$/m);
|
|
96
|
+
if (match) {
|
|
97
|
+
authToken = match[1].replace(/["']/g, '').trim();
|
|
98
|
+
}
|
|
99
|
+
} catch {}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// 3. Finally try environment variable
|
|
104
|
+
if (!authToken) {
|
|
105
|
+
authToken = process.env.SUPABASE_SECRET_KEY || '';
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return { authToken, userId };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
112
|
+
// Main Hook Logic
|
|
113
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
114
|
+
async function main() {
|
|
115
|
+
// Read JSON input from stdin
|
|
116
|
+
let inputData = '';
|
|
117
|
+
for await (const chunk of process.stdin) {
|
|
118
|
+
inputData += chunk;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
let input;
|
|
122
|
+
try {
|
|
123
|
+
input = JSON.parse(inputData);
|
|
124
|
+
} catch {
|
|
125
|
+
process.exit(0);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const userQuery = input.query || input.message || input.prompt || '';
|
|
129
|
+
const sessionId = input.session_id || 'unknown';
|
|
130
|
+
const modelInfo = input.model || 'claude-sonnet-4-5';
|
|
131
|
+
const transcriptPath = input.transcript_path || '';
|
|
132
|
+
|
|
133
|
+
// Skip if empty
|
|
134
|
+
if (!userQuery) {
|
|
135
|
+
process.exit(0);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Load auth
|
|
139
|
+
const { authToken, userId } = loadAuthToken();
|
|
140
|
+
const MEMORY_API_URL = 'https://mcp.ekkos.dev';
|
|
141
|
+
|
|
142
|
+
// Get current timestamp
|
|
143
|
+
const now = new Date();
|
|
144
|
+
const currentTime = now.toLocaleString('en-US', {
|
|
145
|
+
year: 'numeric',
|
|
146
|
+
month: '2-digit',
|
|
147
|
+
day: '2-digit',
|
|
148
|
+
hour: '2-digit',
|
|
149
|
+
minute: '2-digit',
|
|
150
|
+
hour12: true,
|
|
151
|
+
timeZoneName: 'short'
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// Visual header
|
|
155
|
+
console.log('');
|
|
156
|
+
console.log(`${CYAN}${BOLD}🧠 ekkOS Memory${RESET} ${DIM}| Claude Code (${modelInfo}) | ${currentTime}${RESET}`);
|
|
157
|
+
|
|
158
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
159
|
+
// [ekkOS_CAPTURE] Capture the PREVIOUS exchange before processing new one
|
|
160
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
161
|
+
if (state.acquireLock(sessionId)) {
|
|
162
|
+
if (transcriptPath && fs.existsSync(transcriptPath)) {
|
|
163
|
+
try {
|
|
164
|
+
const transcriptContent = fs.readFileSync(transcriptPath, 'utf8');
|
|
165
|
+
const lines = transcriptContent.split('\n').filter(Boolean).map(l => {
|
|
166
|
+
try { return JSON.parse(l); } catch { return null; }
|
|
167
|
+
}).filter(Boolean);
|
|
168
|
+
|
|
169
|
+
// Get human messages
|
|
170
|
+
const humanMsgs = lines.filter(l => l.type === 'human');
|
|
171
|
+
const assistantMsgs = lines.filter(l => l.type === 'assistant');
|
|
172
|
+
|
|
173
|
+
// Get second-to-last human message (the previous query, not current)
|
|
174
|
+
const prevUser = humanMsgs.length > 1 ? humanMsgs[humanMsgs.length - 2]?.message : null;
|
|
175
|
+
|
|
176
|
+
// Get last assistant response
|
|
177
|
+
const lastAssistant = assistantMsgs[assistantMsgs.length - 1];
|
|
178
|
+
let prevAssistant = '';
|
|
179
|
+
if (lastAssistant?.message?.content) {
|
|
180
|
+
if (Array.isArray(lastAssistant.message.content)) {
|
|
181
|
+
prevAssistant = lastAssistant.message.content
|
|
182
|
+
.filter(c => c.type === 'text')
|
|
183
|
+
.map(c => c.text)
|
|
184
|
+
.join(' ');
|
|
185
|
+
} else {
|
|
186
|
+
prevAssistant = lastAssistant.message.content;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Capture if we have both
|
|
191
|
+
if (prevUser && prevAssistant) {
|
|
192
|
+
const prevHash = state.generateTurnHash(prevUser, prevAssistant);
|
|
193
|
+
|
|
194
|
+
if (!state.wasTurnCaptured(sessionId, prevHash)) {
|
|
195
|
+
// Capture in background (don't wait)
|
|
196
|
+
httpRequest(`${MEMORY_API_URL}/api/v1/memory/capture`, {
|
|
197
|
+
method: 'POST',
|
|
198
|
+
headers: {
|
|
199
|
+
'Authorization': `Bearer ${authToken}`,
|
|
200
|
+
'Content-Type': 'application/json'
|
|
201
|
+
},
|
|
202
|
+
timeout: 5000
|
|
203
|
+
}, {
|
|
204
|
+
user_query: prevUser,
|
|
205
|
+
assistant_response: prevAssistant,
|
|
206
|
+
session_id: `claude-code-${sessionId}`,
|
|
207
|
+
metadata: {
|
|
208
|
+
source: 'claude-code-hook-node',
|
|
209
|
+
model_used: modelInfo,
|
|
210
|
+
captured_at: new Date().toISOString()
|
|
211
|
+
}
|
|
212
|
+
}).catch(() => {});
|
|
213
|
+
|
|
214
|
+
state.markTurnCaptured(sessionId, prevHash);
|
|
215
|
+
console.log(`${CYAN} 💾 Capture${RESET} ${DIM}saving previous turn${RESET}`);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
} catch {}
|
|
219
|
+
}
|
|
220
|
+
state.releaseLock(sessionId);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
224
|
+
// [ekkOS_RETRIEVE] Single API call - backend handles ALL the work
|
|
225
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
226
|
+
console.log(`${MAGENTA} 🔍 Retrieve${RESET} ${DIM}searching memory substrate...${RESET}`);
|
|
227
|
+
|
|
228
|
+
let apiResponse;
|
|
229
|
+
if (!authToken) {
|
|
230
|
+
console.log(`${DIM} ⚠️ Retrieve${RESET} ${DIM}skipped (no auth)${RESET}`);
|
|
231
|
+
apiResponse = { error: 'no_auth', formatted_context: '', layers: { patterns: [], directives: [] } };
|
|
232
|
+
} else {
|
|
233
|
+
apiResponse = await httpRequest(`${MEMORY_API_URL}/api/v1/context/retrieve`, {
|
|
234
|
+
method: 'POST',
|
|
235
|
+
headers: {
|
|
236
|
+
'Authorization': `Bearer ${authToken}`,
|
|
237
|
+
'Content-Type': 'application/json'
|
|
238
|
+
},
|
|
239
|
+
timeout: 1500
|
|
240
|
+
}, {
|
|
241
|
+
query: userQuery,
|
|
242
|
+
user_id: userId || 'system',
|
|
243
|
+
session_id: `claude-code-${sessionId}`,
|
|
244
|
+
max_per_layer: 5,
|
|
245
|
+
include_layers: ['working', 'episodic', 'semantic', 'patterns', 'procedural', 'collective', 'codebase', 'directives'],
|
|
246
|
+
metadata: {
|
|
247
|
+
source: 'claude-code-node',
|
|
248
|
+
model_used: modelInfo
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
if (!apiResponse.layers) {
|
|
253
|
+
apiResponse = { error: 'timeout', formatted_context: '', layers: { patterns: [], directives: [] } };
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// Extract counts
|
|
258
|
+
const layers = apiResponse.layers || {};
|
|
259
|
+
const patternCount = (layers.patterns || []).length;
|
|
260
|
+
const directiveCount = (layers.directives || []).length;
|
|
261
|
+
const episodicCount = (layers.episodic || []).length;
|
|
262
|
+
const proceduralCount = (layers.procedural || []).length;
|
|
263
|
+
const codebaseCount = (layers.codebase || []).length;
|
|
264
|
+
const totalCount = patternCount + directiveCount + episodicCount + proceduralCount + codebaseCount;
|
|
265
|
+
|
|
266
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
267
|
+
// [ekkOS_INJECT] Output the formatted context
|
|
268
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
269
|
+
if (totalCount > 0) {
|
|
270
|
+
console.log(`${GREEN} ✨ Inject${RESET} ${GREEN}${totalCount}${RESET} ${DIM}memories loaded (${patternCount} patterns, ${directiveCount} directives)${RESET}`);
|
|
271
|
+
console.log('');
|
|
272
|
+
|
|
273
|
+
const formatted = apiResponse.formatted_context;
|
|
274
|
+
if (formatted) {
|
|
275
|
+
console.log(formatted);
|
|
276
|
+
} else {
|
|
277
|
+
// Fallback: structured output
|
|
278
|
+
if (patternCount > 0) {
|
|
279
|
+
console.log('## Pattern Memory (Layer 4) - Directive Compliant');
|
|
280
|
+
console.log('Proven solutions:');
|
|
281
|
+
for (const p of layers.patterns.slice(0, 5)) {
|
|
282
|
+
console.log(`${p.title || 'Untitled'}`);
|
|
283
|
+
console.log(` Problem: ${(p.problem || 'N/A').substring(0, 200)}`);
|
|
284
|
+
console.log(` Solution: ${(p.solution || 'N/A').substring(0, 300)}`);
|
|
285
|
+
console.log(` Success Rate: ${p.success_rate || 0}%`);
|
|
286
|
+
console.log('');
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
if (directiveCount > 0) {
|
|
291
|
+
console.log('## Directive Memory (Layer 9) - HIGHEST PRIORITY');
|
|
292
|
+
console.log('User rules that MUST be followed:');
|
|
293
|
+
for (const d of layers.directives.slice(0, 5)) {
|
|
294
|
+
console.log(` [${d.type || 'PREFER'}] ${d.rule || d.content || 'No rule'}`);
|
|
295
|
+
}
|
|
296
|
+
console.log('');
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
if (proceduralCount > 0) {
|
|
300
|
+
console.log('## Procedural Memory (Layer 5)');
|
|
301
|
+
console.log('Multi-step workflows:');
|
|
302
|
+
for (const p of layers.procedural.slice(0, 3)) {
|
|
303
|
+
console.log(` • ${p.title || p.name || 'Workflow'}`);
|
|
304
|
+
}
|
|
305
|
+
console.log('');
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
if (episodicCount > 0) {
|
|
309
|
+
console.log('## Episodic Memory (Layer 2)');
|
|
310
|
+
console.log('Similar past conversations:');
|
|
311
|
+
for (const e of layers.episodic.slice(0, 3)) {
|
|
312
|
+
console.log(` • ${(e.query_preview || e.problem || 'Previous session').substring(0, 100)}...`);
|
|
313
|
+
}
|
|
314
|
+
console.log('');
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
if (codebaseCount > 0) {
|
|
318
|
+
console.log('## Codebase Memory (Layer 8)');
|
|
319
|
+
console.log('Project-specific knowledge:');
|
|
320
|
+
for (const c of layers.codebase.slice(0, 3)) {
|
|
321
|
+
console.log(` • ${c.file_path || c.title || 'Code pattern'}`);
|
|
322
|
+
}
|
|
323
|
+
console.log('');
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
} else {
|
|
327
|
+
console.log(`${DIM} 📭 Inject${RESET} ${DIM}no matching patterns found${RESET}`);
|
|
328
|
+
console.log('');
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// Save patterns for stop.js
|
|
332
|
+
state.savePatterns(sessionId, layers.patterns || [], modelInfo);
|
|
333
|
+
|
|
334
|
+
process.exit(0);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
main().catch(() => process.exit(0));
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
# Implementation Plan: [Feature Name]
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
**Technical implementation plan for [Feature Name] based on the specification.**
|
|
5
|
+
|
|
6
|
+
## Architecture Overview
|
|
7
|
+
|
|
8
|
+
### System Components
|
|
9
|
+
- **Frontend**: React components and state management
|
|
10
|
+
- **API Layer**: Next.js API routes and middleware
|
|
11
|
+
- **AI Services**: AI provider integration and processing
|
|
12
|
+
- **Database**: Supabase data storage and queries
|
|
13
|
+
- **External APIs**: Third-party service integrations
|
|
14
|
+
|
|
15
|
+
### Data Flow
|
|
16
|
+
```
|
|
17
|
+
User Input → Frontend → API Route → AI Processing → Database → Response
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Technical Stack
|
|
21
|
+
|
|
22
|
+
### Frontend
|
|
23
|
+
- **Framework**: Next.js 15.5.2 with React 19
|
|
24
|
+
- **Styling**: Tailwind CSS
|
|
25
|
+
- **State Management**: React hooks and context
|
|
26
|
+
- **Type Safety**: TypeScript
|
|
27
|
+
|
|
28
|
+
### Backend
|
|
29
|
+
- **Runtime**: Node.js with Next.js API routes
|
|
30
|
+
- **Database**: Supabase (PostgreSQL)
|
|
31
|
+
- **AI Providers**: OpenAI, Gemini (Google AI)
|
|
32
|
+
- **Authentication**: Supabase Auth (planned)
|
|
33
|
+
|
|
34
|
+
### External Services
|
|
35
|
+
- **YouTube API**: Content extraction
|
|
36
|
+
- **AI APIs**: OpenAI, Google AI (Gemini)
|
|
37
|
+
- **Content Processing**: Custom extraction services
|
|
38
|
+
|
|
39
|
+
## Implementation Phases
|
|
40
|
+
|
|
41
|
+
### Phase 1: Foundation Setup
|
|
42
|
+
**Duration**: 1-2 days
|
|
43
|
+
|
|
44
|
+
#### Tasks
|
|
45
|
+
- [ ] **Database Schema**: Create/modify database tables
|
|
46
|
+
- [ ] **API Contracts**: Define request/response interfaces
|
|
47
|
+
- [ ] **Type Definitions**: Create TypeScript interfaces
|
|
48
|
+
- [ ] **Environment Setup**: Configure required environment variables
|
|
49
|
+
|
|
50
|
+
#### Deliverables
|
|
51
|
+
- Database migration scripts
|
|
52
|
+
- TypeScript interface definitions
|
|
53
|
+
- API endpoint specifications
|
|
54
|
+
- Environment configuration
|
|
55
|
+
|
|
56
|
+
### Phase 2: Core Implementation
|
|
57
|
+
**Duration**: 3-5 days
|
|
58
|
+
|
|
59
|
+
#### Backend Implementation
|
|
60
|
+
- [ ] **API Routes**: Implement Next.js API endpoints
|
|
61
|
+
- [ ] **AI Integration**: Connect to AI providers
|
|
62
|
+
- [ ] **Data Processing**: Implement content processing logic
|
|
63
|
+
- [ ] **Error Handling**: Implement comprehensive error handling
|
|
64
|
+
|
|
65
|
+
#### Frontend Implementation
|
|
66
|
+
- [ ] **UI Components**: Create React components
|
|
67
|
+
- [ ] **State Management**: Implement data flow
|
|
68
|
+
- [ ] **User Interface**: Design and implement user interactions
|
|
69
|
+
- [ ] **Responsive Design**: Ensure mobile compatibility
|
|
70
|
+
|
|
71
|
+
#### Deliverables
|
|
72
|
+
- Working API endpoints
|
|
73
|
+
- Functional UI components
|
|
74
|
+
- AI integration working
|
|
75
|
+
- Basic error handling
|
|
76
|
+
|
|
77
|
+
### Phase 3: Integration and Testing
|
|
78
|
+
**Duration**: 2-3 days
|
|
79
|
+
|
|
80
|
+
#### Integration Tasks
|
|
81
|
+
- [ ] **End-to-End Testing**: Test complete user workflows
|
|
82
|
+
- [ ] **AI Provider Testing**: Validate AI accuracy and performance
|
|
83
|
+
- [ ] **Error Scenario Testing**: Test failure modes and recovery
|
|
84
|
+
- [ ] **Performance Testing**: Validate response times and throughput
|
|
85
|
+
|
|
86
|
+
#### Quality Assurance
|
|
87
|
+
- [ ] **Code Review**: Review all implementation code
|
|
88
|
+
- [ ] **Security Review**: Validate security measures
|
|
89
|
+
- [ ] **Accessibility Review**: Ensure accessibility compliance
|
|
90
|
+
- [ ] **Documentation**: Update technical documentation
|
|
91
|
+
|
|
92
|
+
#### Deliverables
|
|
93
|
+
- Fully tested feature
|
|
94
|
+
- Performance benchmarks
|
|
95
|
+
- Security validation
|
|
96
|
+
- Updated documentation
|
|
97
|
+
|
|
98
|
+
## Database Schema
|
|
99
|
+
|
|
100
|
+
### New Tables
|
|
101
|
+
```sql
|
|
102
|
+
-- Example table for new feature
|
|
103
|
+
CREATE TABLE feature_table (
|
|
104
|
+
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
|
|
105
|
+
user_id TEXT NOT NULL,
|
|
106
|
+
data JSONB NOT NULL,
|
|
107
|
+
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
|
108
|
+
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
|
|
109
|
+
);
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Modified Tables
|
|
113
|
+
- **content_items**: Add new fields if needed
|
|
114
|
+
- **users**: Add new fields if needed
|
|
115
|
+
|
|
116
|
+
## API Design
|
|
117
|
+
|
|
118
|
+
### New Endpoints
|
|
119
|
+
- **POST /api/feature**: Create new feature item
|
|
120
|
+
- **GET /api/feature**: List feature items
|
|
121
|
+
- **PUT /api/feature/[id]**: Update feature item
|
|
122
|
+
- **DELETE /api/feature/[id]**: Delete feature item
|
|
123
|
+
|
|
124
|
+
### Request/Response Examples
|
|
125
|
+
```typescript
|
|
126
|
+
// POST /api/feature
|
|
127
|
+
interface CreateFeatureRequest {
|
|
128
|
+
title: string;
|
|
129
|
+
content: string;
|
|
130
|
+
// ... other fields
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
interface CreateFeatureResponse {
|
|
134
|
+
id: string;
|
|
135
|
+
// ... response fields
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## AI Integration
|
|
140
|
+
|
|
141
|
+
### AI Provider Selection
|
|
142
|
+
- **Primary**: OpenAI (for main processing)
|
|
143
|
+
- **Fallback**: Mock provider (for development)
|
|
144
|
+
- **Future**: Anthropic (for additional capabilities)
|
|
145
|
+
|
|
146
|
+
### AI Processing Pipeline
|
|
147
|
+
1. **Content Analysis**: Analyze input content
|
|
148
|
+
2. **Feature Extraction**: Extract relevant features
|
|
149
|
+
3. **AI Processing**: Apply AI algorithms
|
|
150
|
+
4. **Result Validation**: Validate AI outputs
|
|
151
|
+
5. **Response Generation**: Format final response
|
|
152
|
+
|
|
153
|
+
### Cost Considerations
|
|
154
|
+
- **OpenAI API**: ~$0.01-0.10 per request
|
|
155
|
+
- **Gemini API**: ~$0.005-0.05 per request
|
|
156
|
+
- **Expected Volume**: 100-1000 requests/day
|
|
157
|
+
- **Monthly Cost**: $10-100 estimated
|
|
158
|
+
|
|
159
|
+
## Frontend Components
|
|
160
|
+
|
|
161
|
+
### New Components
|
|
162
|
+
- **FeatureForm**: Form for creating/editing features
|
|
163
|
+
- **FeatureList**: List view of features
|
|
164
|
+
- **FeatureDetail**: Detailed view of individual feature
|
|
165
|
+
- **FeatureCard**: Card component for feature display
|
|
166
|
+
|
|
167
|
+
### State Management
|
|
168
|
+
- **Context**: FeatureContext for global state
|
|
169
|
+
- **Hooks**: Custom hooks for data fetching
|
|
170
|
+
- **Local State**: Component-level state management
|
|
171
|
+
|
|
172
|
+
## Error Handling
|
|
173
|
+
|
|
174
|
+
### Error Types
|
|
175
|
+
- **Validation Errors**: Input validation failures
|
|
176
|
+
- **AI Errors**: AI provider failures
|
|
177
|
+
- **Network Errors**: API communication failures
|
|
178
|
+
- **Database Errors**: Data persistence failures
|
|
179
|
+
|
|
180
|
+
### Error Recovery
|
|
181
|
+
- **Retry Logic**: Automatic retry for transient failures
|
|
182
|
+
- **Fallback Strategies**: Alternative approaches when primary fails
|
|
183
|
+
- **User Feedback**: Clear error messages and recovery options
|
|
184
|
+
- **Logging**: Comprehensive error logging and monitoring
|
|
185
|
+
|
|
186
|
+
## Performance Considerations
|
|
187
|
+
|
|
188
|
+
### Optimization Strategies
|
|
189
|
+
- **Caching**: Implement appropriate caching strategies
|
|
190
|
+
- **Lazy Loading**: Load components and data on demand
|
|
191
|
+
- **Debouncing**: Prevent excessive API calls
|
|
192
|
+
- **Compression**: Compress API responses
|
|
193
|
+
|
|
194
|
+
### Monitoring
|
|
195
|
+
- **Response Times**: Track API response times
|
|
196
|
+
- **Error Rates**: Monitor error frequencies
|
|
197
|
+
- **AI Performance**: Track AI accuracy and costs
|
|
198
|
+
- **User Metrics**: Monitor user engagement
|
|
199
|
+
|
|
200
|
+
## Security Considerations
|
|
201
|
+
|
|
202
|
+
### Authentication
|
|
203
|
+
- **User Verification**: Verify user identity
|
|
204
|
+
- **Session Management**: Manage user sessions
|
|
205
|
+
- **Token Validation**: Validate authentication tokens
|
|
206
|
+
|
|
207
|
+
### Authorization
|
|
208
|
+
- **Access Control**: Control feature access
|
|
209
|
+
- **Data Isolation**: Ensure user data isolation
|
|
210
|
+
- **Permission Checks**: Validate user permissions
|
|
211
|
+
|
|
212
|
+
### Data Protection
|
|
213
|
+
- **Input Validation**: Validate all inputs
|
|
214
|
+
- **Output Sanitization**: Sanitize outputs
|
|
215
|
+
- **Privacy Compliance**: Ensure data privacy
|
|
216
|
+
- **Audit Logging**: Log security-relevant events
|
|
217
|
+
|
|
218
|
+
## Testing Strategy
|
|
219
|
+
|
|
220
|
+
### Unit Testing
|
|
221
|
+
- **Component Tests**: Test React components
|
|
222
|
+
- **API Tests**: Test API endpoints
|
|
223
|
+
- **Service Tests**: Test business logic
|
|
224
|
+
- **AI Tests**: Test AI integration
|
|
225
|
+
|
|
226
|
+
### Integration Testing
|
|
227
|
+
- **End-to-End Tests**: Test complete workflows
|
|
228
|
+
- **API Integration**: Test API interactions
|
|
229
|
+
- **Database Integration**: Test data persistence
|
|
230
|
+
- **External Service Integration**: Test third-party services
|
|
231
|
+
|
|
232
|
+
### Performance Testing
|
|
233
|
+
- **Load Testing**: Test under expected load
|
|
234
|
+
- **Stress Testing**: Test under high load
|
|
235
|
+
- **AI Performance**: Test AI response times
|
|
236
|
+
- **Database Performance**: Test query performance
|
|
237
|
+
|
|
238
|
+
## Deployment Plan
|
|
239
|
+
|
|
240
|
+
### Environment Setup
|
|
241
|
+
- **Development**: Local development environment
|
|
242
|
+
- **Staging**: Pre-production testing environment
|
|
243
|
+
- **Production**: Live production environment
|
|
244
|
+
|
|
245
|
+
### Deployment Process
|
|
246
|
+
1. **Code Review**: Review all changes
|
|
247
|
+
2. **Testing**: Run comprehensive tests
|
|
248
|
+
3. **Staging Deployment**: Deploy to staging
|
|
249
|
+
4. **Production Deployment**: Deploy to production
|
|
250
|
+
5. **Monitoring**: Monitor deployment health
|
|
251
|
+
|
|
252
|
+
### Rollback Strategy
|
|
253
|
+
- **Database Rollback**: Rollback database changes
|
|
254
|
+
- **Code Rollback**: Rollback code changes
|
|
255
|
+
- **Configuration Rollback**: Rollback configuration changes
|
|
256
|
+
- **Monitoring**: Monitor rollback success
|
|
257
|
+
|
|
258
|
+
## Success Metrics
|
|
259
|
+
|
|
260
|
+
### Technical Metrics
|
|
261
|
+
- **Response Time**: < 2 seconds for API calls
|
|
262
|
+
- **Error Rate**: < 1% error rate
|
|
263
|
+
- **Uptime**: > 99.9% uptime
|
|
264
|
+
- **AI Accuracy**: > 90% accuracy
|
|
265
|
+
|
|
266
|
+
### User Metrics
|
|
267
|
+
- **Adoption Rate**: % of users using feature
|
|
268
|
+
- **Satisfaction**: User satisfaction scores
|
|
269
|
+
- **Engagement**: Feature usage frequency
|
|
270
|
+
- **Retention**: User retention impact
|
|
271
|
+
|
|
272
|
+
### Business Metrics
|
|
273
|
+
- **Cost per Operation**: Cost efficiency
|
|
274
|
+
- **Revenue Impact**: Revenue generation
|
|
275
|
+
- **User Growth**: User acquisition impact
|
|
276
|
+
- **Competitive Advantage**: Market positioning
|
|
277
|
+
|
|
278
|
+
## Risk Mitigation
|
|
279
|
+
|
|
280
|
+
### Technical Risks
|
|
281
|
+
- **AI Provider Outage**: Implement fallback providers
|
|
282
|
+
- **Database Issues**: Implement backup and recovery
|
|
283
|
+
- **Performance Issues**: Implement monitoring and scaling
|
|
284
|
+
- **Security Vulnerabilities**: Implement security reviews
|
|
285
|
+
|
|
286
|
+
### Business Risks
|
|
287
|
+
- **User Adoption**: Implement user feedback loops
|
|
288
|
+
- **Cost Overruns**: Implement cost monitoring
|
|
289
|
+
- **Competitive Pressure**: Implement rapid iteration
|
|
290
|
+
- **Regulatory Issues**: Implement compliance monitoring
|
|
291
|
+
|
|
292
|
+
## Future Enhancements
|
|
293
|
+
|
|
294
|
+
### Planned Improvements
|
|
295
|
+
- **Advanced AI Features**: Enhanced AI capabilities
|
|
296
|
+
- **Mobile App**: Native mobile application
|
|
297
|
+
- **API Expansion**: Additional API endpoints
|
|
298
|
+
- **Integration**: Third-party integrations
|
|
299
|
+
|
|
300
|
+
### Research Areas
|
|
301
|
+
- **AI Optimization**: Improve AI accuracy and cost
|
|
302
|
+
- **User Experience**: Enhance user interface
|
|
303
|
+
- **Performance**: Optimize system performance
|
|
304
|
+
- **Scalability**: Improve system scalability
|
|
305
|
+
|
|
306
|
+
|