cmp-standards 2.0.1 → 2.4.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/README.md +171 -101
- package/dist/cli/index.js +239 -7
- package/dist/cli/index.js.map +1 -1
- package/dist/dashboard/server.d.ts.map +1 -1
- package/dist/dashboard/server.js +203 -39
- package/dist/dashboard/server.js.map +1 -1
- package/dist/db/cloud.d.ts +174 -0
- package/dist/db/cloud.d.ts.map +1 -0
- package/dist/db/cloud.js +241 -0
- package/dist/db/cloud.js.map +1 -0
- package/dist/db/errors.d.ts +76 -0
- package/dist/db/errors.d.ts.map +1 -0
- package/dist/db/errors.js +135 -0
- package/dist/db/errors.js.map +1 -0
- package/dist/db/turso-client.d.ts +178 -0
- package/dist/db/turso-client.d.ts.map +1 -0
- package/dist/db/turso-client.js +455 -0
- package/dist/db/turso-client.js.map +1 -0
- package/dist/db/upstash-client.d.ts +161 -0
- package/dist/db/upstash-client.d.ts.map +1 -0
- package/dist/db/upstash-client.js +325 -0
- package/dist/db/upstash-client.js.map +1 -0
- package/dist/hooks/cloud-post-tool-use.d.ts +30 -0
- package/dist/hooks/cloud-post-tool-use.d.ts.map +1 -0
- package/dist/hooks/cloud-post-tool-use.js +116 -0
- package/dist/hooks/cloud-post-tool-use.js.map +1 -0
- package/dist/hooks/cloud-pre-tool-use.d.ts +19 -0
- package/dist/hooks/cloud-pre-tool-use.d.ts.map +1 -0
- package/dist/hooks/cloud-pre-tool-use.js +149 -0
- package/dist/hooks/cloud-pre-tool-use.js.map +1 -0
- package/dist/hooks/cloud-session-start.d.ts +20 -0
- package/dist/hooks/cloud-session-start.d.ts.map +1 -0
- package/dist/hooks/cloud-session-start.js +130 -0
- package/dist/hooks/cloud-session-start.js.map +1 -0
- package/dist/hooks/index.d.ts +3 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +5 -0
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/memory-checkpoint.d.ts.map +1 -1
- package/dist/hooks/memory-checkpoint.js +12 -20
- package/dist/hooks/memory-checkpoint.js.map +1 -1
- package/dist/hooks/pre-tool-use.d.ts +2 -8
- package/dist/hooks/pre-tool-use.d.ts.map +1 -1
- package/dist/hooks/pre-tool-use.js +7 -106
- package/dist/hooks/pre-tool-use.js.map +1 -1
- package/dist/hooks/session-start.d.ts.map +1 -1
- package/dist/hooks/session-start.js +15 -6
- package/dist/hooks/session-start.js.map +1 -1
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -1
- package/dist/index.js.map +1 -1
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +223 -0
- package/dist/mcp/server.js.map +1 -1
- package/dist/schema/tracking.d.ts +644 -0
- package/dist/schema/tracking.d.ts.map +1 -0
- package/dist/schema/tracking.js +204 -0
- package/dist/schema/tracking.js.map +1 -0
- package/dist/services/ProjectScaffold.d.ts.map +1 -1
- package/dist/services/ProjectScaffold.js +33 -5
- package/dist/services/ProjectScaffold.js.map +1 -1
- package/dist/services/TaskTracker.d.ts +1 -1
- package/dist/services/TaskTracker.d.ts.map +1 -1
- package/dist/services/TaskTracker.js +4 -8
- package/dist/services/TaskTracker.js.map +1 -1
- package/dist/services/WorkPlanManager.d.ts +1 -1
- package/dist/services/WorkPlanManager.d.ts.map +1 -1
- package/dist/services/WorkPlanManager.js +8 -14
- package/dist/services/WorkPlanManager.js.map +1 -1
- package/dist/services/auto-inject.d.ts +1 -0
- package/dist/services/auto-inject.d.ts.map +1 -1
- package/dist/services/auto-inject.js +12 -17
- package/dist/services/auto-inject.js.map +1 -1
- package/dist/services/cross-project-sync.d.ts +2 -0
- package/dist/services/cross-project-sync.d.ts.map +1 -1
- package/dist/services/cross-project-sync.js +26 -21
- package/dist/services/cross-project-sync.js.map +1 -1
- package/dist/services/memory-consolidation.d.ts.map +1 -1
- package/dist/services/memory-consolidation.js +30 -27
- package/dist/services/memory-consolidation.js.map +1 -1
- package/dist/utils/env-loader.d.ts +41 -0
- package/dist/utils/env-loader.d.ts.map +1 -0
- package/dist/utils/env-loader.js +78 -0
- package/dist/utils/env-loader.js.map +1 -0
- package/dist/utils/git.d.ts +52 -0
- package/dist/utils/git.d.ts.map +1 -0
- package/dist/utils/git.js +267 -0
- package/dist/utils/git.js.map +1 -0
- package/dist/utils/paths.d.ts +39 -5
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +88 -7
- package/dist/utils/paths.js.map +1 -1
- package/package.json +8 -2
- package/standards/README.md +50 -0
- package/standards/experts/expert-routing.md +215 -0
- package/standards/general/code-quality.md +86 -0
- package/standards/general/memory-usage.md +205 -0
- package/standards/general/sync-workflow.md +235 -0
- package/standards/general/workflow.md +82 -0
- package/standards/hooks/mandatory-tracking.md +446 -0
- package/standards/infrastructure/cloud-database.md +287 -0
- package/standards/mcp/server-design.md +243 -0
- package/standards/mcp/tool-patterns.md +354 -0
- package/standards/skills/skill-structure.md +286 -0
- package/standards/skills/workflow-design.md +323 -0
- package/standards/tools/tool-design.md +297 -0
- package/templates/claude-settings.json +72 -0
- package/templates/memory-config.json +2 -28
- package/templates/skills/continue.md +205 -0
package/dist/db/cloud.js
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Cloud Database Client
|
|
3
|
+
* @description Cliente unificado para Turso + Upstash
|
|
4
|
+
*/
|
|
5
|
+
import { turso, initTurso, setupTursoSchema, getTurso } from './turso-client.js';
|
|
6
|
+
import { upstash, initRedis, healthCheck as redisHealthCheck, initVector, vectorHealthCheck } from './upstash-client.js';
|
|
7
|
+
import { loadEnvFromAncestors, hasCloudCredentials } from '../utils/env-loader.js';
|
|
8
|
+
// =============================================================================
|
|
9
|
+
// Initialization
|
|
10
|
+
// =============================================================================
|
|
11
|
+
// Track if cloud has been initialized
|
|
12
|
+
let cloudInitialized = false;
|
|
13
|
+
let lastInitStatus = null;
|
|
14
|
+
/**
|
|
15
|
+
* Check if cloud credentials are available before operations
|
|
16
|
+
* Returns helpful error messages if not configured
|
|
17
|
+
*/
|
|
18
|
+
export function checkCloudCredentials() {
|
|
19
|
+
const creds = hasCloudCredentials();
|
|
20
|
+
const missing = [];
|
|
21
|
+
if (!creds.turso) {
|
|
22
|
+
missing.push('TURSO_DATABASE_URL and TURSO_AUTH_TOKEN');
|
|
23
|
+
}
|
|
24
|
+
if (!creds.redis) {
|
|
25
|
+
missing.push('UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN');
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
ok: creds.turso && creds.redis,
|
|
29
|
+
missing
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Ensure cloud is initialized, with helpful error if credentials missing
|
|
34
|
+
*/
|
|
35
|
+
export async function ensureCloud() {
|
|
36
|
+
// Load env from ancestors (monorepo support) - only when actually needed
|
|
37
|
+
loadEnvFromAncestors();
|
|
38
|
+
if (cloudInitialized && lastInitStatus?.turso.ok && lastInitStatus?.redis.ok) {
|
|
39
|
+
return lastInitStatus;
|
|
40
|
+
}
|
|
41
|
+
const credCheck = checkCloudCredentials();
|
|
42
|
+
if (!credCheck.ok) {
|
|
43
|
+
throw new Error(`Cloud credentials not configured. Missing: ${credCheck.missing.join(', ')}.\n` +
|
|
44
|
+
`Run 'cmp-standards cloud init' for setup instructions.`);
|
|
45
|
+
}
|
|
46
|
+
return initCloud();
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Inicializar todos los clientes cloud
|
|
50
|
+
*/
|
|
51
|
+
export async function initCloud(config) {
|
|
52
|
+
const status = {
|
|
53
|
+
turso: { ok: false, message: 'Not initialized' },
|
|
54
|
+
redis: { ok: false, message: 'Not initialized' },
|
|
55
|
+
vector: { ok: false, message: 'Not configured (optional)' }
|
|
56
|
+
};
|
|
57
|
+
// Check credentials first
|
|
58
|
+
const credCheck = checkCloudCredentials();
|
|
59
|
+
if (!credCheck.ok) {
|
|
60
|
+
status.turso = { ok: false, message: `Missing credentials: ${credCheck.missing.join(', ')}` };
|
|
61
|
+
status.redis = { ok: false, message: `Missing credentials: ${credCheck.missing.join(', ')}` };
|
|
62
|
+
lastInitStatus = status;
|
|
63
|
+
return status;
|
|
64
|
+
}
|
|
65
|
+
// Turso
|
|
66
|
+
try {
|
|
67
|
+
initTurso(config?.turso);
|
|
68
|
+
await setupTursoSchema();
|
|
69
|
+
status.turso = { ok: true, message: 'Connected and schema ready' };
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
status.turso = { ok: false, message: String(error) };
|
|
73
|
+
}
|
|
74
|
+
// Redis
|
|
75
|
+
try {
|
|
76
|
+
initRedis(config?.redis);
|
|
77
|
+
const health = await redisHealthCheck();
|
|
78
|
+
status.redis = {
|
|
79
|
+
ok: health.ok,
|
|
80
|
+
latency: health.latency,
|
|
81
|
+
message: health.ok ? `Connected (${health.latency}ms)` : 'Connection failed'
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
status.redis = { ok: false, message: String(error) };
|
|
86
|
+
}
|
|
87
|
+
// Vector (optional)
|
|
88
|
+
try {
|
|
89
|
+
initVector(config?.vector);
|
|
90
|
+
const vectorHealth = await vectorHealthCheck();
|
|
91
|
+
status.vector = {
|
|
92
|
+
ok: vectorHealth.ok,
|
|
93
|
+
message: vectorHealth.message
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
status.vector = { ok: false, message: String(error) };
|
|
98
|
+
}
|
|
99
|
+
cloudInitialized = status.turso.ok && status.redis.ok;
|
|
100
|
+
lastInitStatus = status;
|
|
101
|
+
return status;
|
|
102
|
+
}
|
|
103
|
+
// =============================================================================
|
|
104
|
+
// Unified Operations
|
|
105
|
+
// =============================================================================
|
|
106
|
+
/**
|
|
107
|
+
* Iniciar nueva sesión de trabajo
|
|
108
|
+
*/
|
|
109
|
+
export async function startWorkSession(system, options) {
|
|
110
|
+
// Crear sesión en Turso
|
|
111
|
+
const sessionId = await turso.createSession(system, options || {});
|
|
112
|
+
// Registrar en Redis para tracking rápido
|
|
113
|
+
await upstash.registerSession({
|
|
114
|
+
sessionId,
|
|
115
|
+
system,
|
|
116
|
+
startedAt: new Date().toISOString(),
|
|
117
|
+
lastActivityAt: new Date().toISOString()
|
|
118
|
+
});
|
|
119
|
+
// Cargar contexto en paralelo (performance optimization)
|
|
120
|
+
const [activeTasks, improvements] = await Promise.all([
|
|
121
|
+
turso.getActiveTasks(system),
|
|
122
|
+
turso.getPendingImprovements(system)
|
|
123
|
+
]);
|
|
124
|
+
return {
|
|
125
|
+
sessionId,
|
|
126
|
+
activeTasks,
|
|
127
|
+
pendingImprovements: improvements.length
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Registrar inicio de tarea
|
|
132
|
+
*/
|
|
133
|
+
export async function startTask(system, sessionId, options) {
|
|
134
|
+
// Crear tarea en Turso
|
|
135
|
+
const taskId = await turso.createTask(system, sessionId, options);
|
|
136
|
+
// Actualizar sesión en Redis
|
|
137
|
+
await upstash.updateSessionActivity(sessionId, {
|
|
138
|
+
activeTaskId: taskId
|
|
139
|
+
});
|
|
140
|
+
return taskId;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Actualizar progreso de tarea
|
|
144
|
+
*/
|
|
145
|
+
export async function updateProgress(taskId, updates) {
|
|
146
|
+
await turso.updateTaskProgress(taskId, updates);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Completar tarea (requiere mejoras)
|
|
150
|
+
*/
|
|
151
|
+
export async function completeTask(taskId, result) {
|
|
152
|
+
// Validar que hay al menos 1 mejora
|
|
153
|
+
if (result.improvements.length === 0) {
|
|
154
|
+
throw new Error('Debes registrar al menos 1 mejora detectada antes de completar la tarea');
|
|
155
|
+
}
|
|
156
|
+
await turso.completeTask(taskId, result);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Obtener contexto actual para sesión
|
|
160
|
+
*/
|
|
161
|
+
export async function getSessionContext(system, sessionId) {
|
|
162
|
+
// Load all context in parallel (performance optimization)
|
|
163
|
+
const [activeTasks, improvements, session] = await Promise.all([
|
|
164
|
+
turso.getActiveTasks(system),
|
|
165
|
+
turso.getPendingImprovements(system),
|
|
166
|
+
upstash.getActiveSession(sessionId)
|
|
167
|
+
]);
|
|
168
|
+
return {
|
|
169
|
+
activeTasks,
|
|
170
|
+
pendingImprovements: improvements,
|
|
171
|
+
recentActivity: session?.lastActivityAt || null
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
// =============================================================================
|
|
175
|
+
// Health Check
|
|
176
|
+
// =============================================================================
|
|
177
|
+
/**
|
|
178
|
+
* Verificar estado de todos los servicios cloud
|
|
179
|
+
*/
|
|
180
|
+
export async function healthCheck() {
|
|
181
|
+
const status = {
|
|
182
|
+
turso: { ok: false, message: 'Unknown' },
|
|
183
|
+
redis: { ok: false, message: 'Unknown' },
|
|
184
|
+
vector: { ok: false, message: 'Not configured' }
|
|
185
|
+
};
|
|
186
|
+
// Turso
|
|
187
|
+
try {
|
|
188
|
+
const db = getTurso();
|
|
189
|
+
await db.execute('SELECT 1');
|
|
190
|
+
status.turso = { ok: true, message: 'Connected' };
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
status.turso = { ok: false, message: String(error) };
|
|
194
|
+
}
|
|
195
|
+
// Redis
|
|
196
|
+
try {
|
|
197
|
+
const health = await redisHealthCheck();
|
|
198
|
+
status.redis = {
|
|
199
|
+
ok: health.ok,
|
|
200
|
+
latency: health.latency,
|
|
201
|
+
message: health.ok ? `Connected (${health.latency}ms)` : 'Failed'
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
status.redis = { ok: false, message: String(error) };
|
|
206
|
+
}
|
|
207
|
+
// Vector
|
|
208
|
+
try {
|
|
209
|
+
const vectorHealth = await vectorHealthCheck();
|
|
210
|
+
status.vector = {
|
|
211
|
+
ok: vectorHealth.ok,
|
|
212
|
+
message: vectorHealth.message
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
status.vector = { ok: false, message: String(error) };
|
|
217
|
+
}
|
|
218
|
+
return status;
|
|
219
|
+
}
|
|
220
|
+
// =============================================================================
|
|
221
|
+
// Export unified client
|
|
222
|
+
// =============================================================================
|
|
223
|
+
export const cloud = {
|
|
224
|
+
// Init
|
|
225
|
+
init: initCloud,
|
|
226
|
+
ensure: ensureCloud,
|
|
227
|
+
checkCredentials: checkCloudCredentials,
|
|
228
|
+
healthCheck,
|
|
229
|
+
// Sessions
|
|
230
|
+
startWorkSession,
|
|
231
|
+
getSessionContext,
|
|
232
|
+
// Tasks
|
|
233
|
+
startTask,
|
|
234
|
+
updateProgress,
|
|
235
|
+
completeTask,
|
|
236
|
+
// Direct access
|
|
237
|
+
turso,
|
|
238
|
+
upstash
|
|
239
|
+
};
|
|
240
|
+
export default cloud;
|
|
241
|
+
//# sourceMappingURL=cloud.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloud.js","sourceRoot":"","sources":["../../src/db/cloud.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAChF,OAAO,EAAE,OAAO,EAAE,SAAS,EAAY,WAAW,IAAI,gBAAgB,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAClI,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AA+BlF,gFAAgF;AAChF,iBAAiB;AACjB,gFAAgF;AAEhF,sCAAsC;AACtC,IAAI,gBAAgB,GAAG,KAAK,CAAA;AAC5B,IAAI,cAAc,GAAuB,IAAI,CAAA;AAE7C;;;GAGG;AACH,MAAM,UAAU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AM,CAAC,KAAK,GAAG,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAA;IACtD,CAAC;IAED,SAAS;IACT,IAAI,CAAC;QACH,MAAM,YAAY,GAAG,MAAM,iBAAiB,EAAE,CAAA;QAC9C,MAAM,CAAC,MAAM,GAAG;YACd,EAAE,EAAE,YAAY,CAAC,EAAE;YACnB,OAAO,EAAE,YAAY,CAAC,OAAO;SAC9B,CAAA;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,MAAM,GAAG,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAA;IACvD,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AAED,gFAAgF;AAChF,wBAAwB;AACxB,gFAAgF;AAEhF,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,OAAO;IACP,IAAI,EAAE,SAAS;IACf,MAAM,EAAE,WAAW;IACnB,gBAAgB,EAAE,qBAAqB;IACvC,WAAW;IACX,WAAW;IACX,gBAAgB;IAChB,iBAAiB;IACjB,QAAQ;IACR,SAAS;IACT,cAAc;IACd,YAAY;IACZ,gBAAgB;IAChB,KAAK;IACL,OAAO;CACR,CAAA;AAED,eAAe,KAAK,CAAA"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Cloud Database Errors
|
|
3
|
+
* @description Custom error classes for database operations
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Base error for all cloud operations
|
|
7
|
+
*/
|
|
8
|
+
export declare class CloudBaseError extends Error {
|
|
9
|
+
readonly cause?: unknown | undefined;
|
|
10
|
+
readonly code?: string | undefined;
|
|
11
|
+
constructor(message: string, cause?: unknown | undefined, code?: string | undefined);
|
|
12
|
+
/**
|
|
13
|
+
* Get the root cause of nested errors
|
|
14
|
+
*/
|
|
15
|
+
getRootCause(): unknown;
|
|
16
|
+
/**
|
|
17
|
+
* Format error for logging
|
|
18
|
+
*/
|
|
19
|
+
toJSON(): Record<string, unknown>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Turso (SQLite) specific errors
|
|
23
|
+
*/
|
|
24
|
+
export declare class TursoError extends CloudBaseError {
|
|
25
|
+
readonly operation?: "create" | "read" | "update" | "delete" | "query" | "init" | undefined;
|
|
26
|
+
constructor(message: string, cause?: unknown, operation?: "create" | "read" | "update" | "delete" | "query" | "init" | undefined);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Redis/Upstash specific errors
|
|
30
|
+
*/
|
|
31
|
+
export declare class UpstashError extends CloudBaseError {
|
|
32
|
+
readonly service?: "redis" | "vector" | undefined;
|
|
33
|
+
constructor(message: string, cause?: unknown, service?: "redis" | "vector" | undefined);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Cloud orchestration errors (multi-service operations)
|
|
37
|
+
*/
|
|
38
|
+
export declare class CloudError extends CloudBaseError {
|
|
39
|
+
readonly failedService?: "turso" | "redis" | "vector" | undefined;
|
|
40
|
+
constructor(message: string, cause?: unknown, failedService?: "turso" | "redis" | "vector" | undefined);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Configuration/initialization errors
|
|
44
|
+
*/
|
|
45
|
+
export declare class ConfigError extends CloudBaseError {
|
|
46
|
+
readonly missingVars?: string[] | undefined;
|
|
47
|
+
constructor(message: string, missingVars?: string[] | undefined);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Validation errors (input/schema)
|
|
51
|
+
*/
|
|
52
|
+
export declare class ValidationError extends CloudBaseError {
|
|
53
|
+
readonly field?: string | undefined;
|
|
54
|
+
constructor(message: string, field?: string | undefined, cause?: unknown);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Not found errors
|
|
58
|
+
*/
|
|
59
|
+
export declare class NotFoundError extends CloudBaseError {
|
|
60
|
+
readonly resource: string;
|
|
61
|
+
readonly resourceId: string;
|
|
62
|
+
constructor(resource: string, resourceId: string);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Wrap async function with error handling
|
|
66
|
+
*/
|
|
67
|
+
export declare function wrapTursoError<T>(operation: 'create' | 'read' | 'update' | 'delete' | 'query' | 'init', fn: () => Promise<T>): Promise<T>;
|
|
68
|
+
/**
|
|
69
|
+
* Wrap async function with Upstash error handling
|
|
70
|
+
*/
|
|
71
|
+
export declare function wrapUpstashError<T>(service: 'redis' | 'vector', fn: () => Promise<T>): Promise<T>;
|
|
72
|
+
/**
|
|
73
|
+
* Safe JSON parse with validation error
|
|
74
|
+
*/
|
|
75
|
+
export declare function safeJsonParse<T>(json: string, context?: string): T;
|
|
76
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/db/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,qBAAa,cAAe,SAAQ,KAAK;aAGrB,KAAK,CAAC,EAAE,OAAO;aACf,IAAI,CAAC,EAAE,MAAM;gBAF7B,OAAO,EAAE,MAAM,EACC,KAAK,CAAC,EAAE,OAAO,YAAA,EACf,IAAI,CAAC,EAAE,MAAM,YAAA;IAW/B;;OAEG;IACH,YAAY,IAAI,OAAO;IAOvB;;OAEG;IACH,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CASlC;AAED;;GAEG;AACH,qBAAa,UAAW,SAAQ,cAAc;aAI1B,SAAS,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM;gBAFtF,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,OAAO,EACC,SAAS,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM,YAAA;CAIzF;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AO,CAAC,CAAC,CAAC,GACnB,OAAO,CAAC,CAAC,CAAC,CAIZ;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,CAAC,CAUlE"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Cloud Database Errors
|
|
3
|
+
* @description Custom error classes for database operations
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Base error for all cloud operations
|
|
7
|
+
*/
|
|
8
|
+
export class CloudBaseError extends Error {
|
|
9
|
+
cause;
|
|
10
|
+
code;
|
|
11
|
+
constructor(message, cause, code) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.cause = cause;
|
|
14
|
+
this.code = code;
|
|
15
|
+
this.name = this.constructor.name;
|
|
16
|
+
// Capture stack trace
|
|
17
|
+
if (Error.captureStackTrace) {
|
|
18
|
+
Error.captureStackTrace(this, this.constructor);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Get the root cause of nested errors
|
|
23
|
+
*/
|
|
24
|
+
getRootCause() {
|
|
25
|
+
if (this.cause instanceof CloudBaseError) {
|
|
26
|
+
return this.cause.getRootCause();
|
|
27
|
+
}
|
|
28
|
+
return this.cause ?? this;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Format error for logging
|
|
32
|
+
*/
|
|
33
|
+
toJSON() {
|
|
34
|
+
return {
|
|
35
|
+
name: this.name,
|
|
36
|
+
message: this.message,
|
|
37
|
+
code: this.code,
|
|
38
|
+
cause: this.cause instanceof Error ? this.cause.message : this.cause,
|
|
39
|
+
stack: this.stack
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Turso (SQLite) specific errors
|
|
45
|
+
*/
|
|
46
|
+
export class TursoError extends CloudBaseError {
|
|
47
|
+
operation;
|
|
48
|
+
constructor(message, cause, operation) {
|
|
49
|
+
super(message, cause, 'TURSO_ERROR');
|
|
50
|
+
this.operation = operation;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Redis/Upstash specific errors
|
|
55
|
+
*/
|
|
56
|
+
export class UpstashError extends CloudBaseError {
|
|
57
|
+
service;
|
|
58
|
+
constructor(message, cause, service) {
|
|
59
|
+
super(message, cause, 'UPSTASH_ERROR');
|
|
60
|
+
this.service = service;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Cloud orchestration errors (multi-service operations)
|
|
65
|
+
*/
|
|
66
|
+
export class CloudError extends CloudBaseError {
|
|
67
|
+
failedService;
|
|
68
|
+
constructor(message, cause, failedService) {
|
|
69
|
+
super(message, cause, 'CLOUD_ERROR');
|
|
70
|
+
this.failedService = failedService;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Configuration/initialization errors
|
|
75
|
+
*/
|
|
76
|
+
export class ConfigError extends CloudBaseError {
|
|
77
|
+
missingVars;
|
|
78
|
+
constructor(message, missingVars) {
|
|
79
|
+
super(message, undefined, 'CONFIG_ERROR');
|
|
80
|
+
this.missingVars = missingVars;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Validation errors (input/schema)
|
|
85
|
+
*/
|
|
86
|
+
export class ValidationError extends CloudBaseError {
|
|
87
|
+
field;
|
|
88
|
+
constructor(message, field, cause) {
|
|
89
|
+
super(message, cause, 'VALIDATION_ERROR');
|
|
90
|
+
this.field = field;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Not found errors
|
|
95
|
+
*/
|
|
96
|
+
export class NotFoundError extends CloudBaseError {
|
|
97
|
+
resource;
|
|
98
|
+
resourceId;
|
|
99
|
+
constructor(resource, resourceId) {
|
|
100
|
+
super(`${resource} not found: ${resourceId}`, undefined, 'NOT_FOUND');
|
|
101
|
+
this.resource = resource;
|
|
102
|
+
this.resourceId = resourceId;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
// =============================================================================
|
|
106
|
+
// Helper functions
|
|
107
|
+
// =============================================================================
|
|
108
|
+
/**
|
|
109
|
+
* Wrap async function with error handling
|
|
110
|
+
*/
|
|
111
|
+
export function wrapTursoError(operation, fn) {
|
|
112
|
+
return fn().catch((error) => {
|
|
113
|
+
throw new TursoError(`Turso ${operation} failed: ${String(error)}`, error, operation);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Wrap async function with Upstash error handling
|
|
118
|
+
*/
|
|
119
|
+
export function wrapUpstashError(service, fn) {
|
|
120
|
+
return fn().catch((error) => {
|
|
121
|
+
throw new UpstashError(`Upstash ${service} operation failed: ${String(error)}`, error, service);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Safe JSON parse with validation error
|
|
126
|
+
*/
|
|
127
|
+
export function safeJsonParse(json, context) {
|
|
128
|
+
try {
|
|
129
|
+
return JSON.parse(json);
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
throw new ValidationError(`Invalid JSON${context ? ` in ${context}` : ''}: ${String(error)}`, context, error);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/db/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK;IAGrB;IACA;IAHlB,YACE,OAAe,EACC,KAAe,EACf,IAAa;QAE7B,KAAK,CAAC,OAAO,CAAC,CAAA;QAHE,UAAK,GAAL,KAAK,CAAU;QACf,SAAI,GAAJ,IAAI,CAAS;QAG7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAA;QAE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I,YAAY,CAAC,WAAW,OAAO,sBAAsB,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,CAAA;IACjG,CAAC,CAAC,CAAA;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAI,IAAY,EAAE,OAAgB;IAC7D,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAM,CAAA;IAC9B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,eAAe,CACvB,eAAe,OAAO,CAAC,CAAC,CAAC,OAAO,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,MAAM,CAAC,KAAK,CAAC,EAAE,EAClE,OAAO,EACP,KAAK,CACN,CAAA;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Cliente Turso (SQLite Edge)
|
|
3
|
+
* @description Cliente serverless para Turso - base de datos principal para tareas, mejoras y memorias
|
|
4
|
+
*/
|
|
5
|
+
import { type Client } from '@libsql/client';
|
|
6
|
+
import type { TaskContent, ImprovementContent } from '../schema/tracking.js';
|
|
7
|
+
export interface TursoConfig {
|
|
8
|
+
url: string;
|
|
9
|
+
authToken: string;
|
|
10
|
+
}
|
|
11
|
+
declare const ALLOWED_ORDER_COLUMNS: readonly ["created_at", "updated_at", "id", "type", "status"];
|
|
12
|
+
declare const ALLOWED_ORDER_DIRS: readonly ["ASC", "DESC"];
|
|
13
|
+
declare const ALLOWED_JSON_PATHS: readonly ["$.lastActivityAt", "$.priority", "$.createdAt", "$.detectedAt"];
|
|
14
|
+
type OrderColumn = typeof ALLOWED_ORDER_COLUMNS[number];
|
|
15
|
+
type OrderDir = typeof ALLOWED_ORDER_DIRS[number];
|
|
16
|
+
type JsonPath = typeof ALLOWED_JSON_PATHS[number];
|
|
17
|
+
export interface QueryOptions {
|
|
18
|
+
system?: string;
|
|
19
|
+
type?: string;
|
|
20
|
+
status?: string;
|
|
21
|
+
limit?: number;
|
|
22
|
+
orderBy?: OrderColumn;
|
|
23
|
+
orderDir?: OrderDir;
|
|
24
|
+
/** Order by JSON field path (safe whitelist: $.lastActivityAt, $.priority, $.createdAt, $.detectedAt) */
|
|
25
|
+
jsonOrderBy?: JsonPath;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Inicializar cliente Turso
|
|
29
|
+
* @throws {ConfigError} If credentials are not configured
|
|
30
|
+
* @throws {TursoError} If connection fails
|
|
31
|
+
*/
|
|
32
|
+
export declare function initTurso(config?: TursoConfig): Client;
|
|
33
|
+
/**
|
|
34
|
+
* Obtener cliente (inicializa si es necesario)
|
|
35
|
+
*/
|
|
36
|
+
export declare function getTurso(): Client;
|
|
37
|
+
/**
|
|
38
|
+
* Crear tablas en Turso
|
|
39
|
+
* @throws {TursoError} If schema creation fails
|
|
40
|
+
*/
|
|
41
|
+
export declare function setupTursoSchema(): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Crear un nuevo item
|
|
44
|
+
* @throws {TursoError} If insert fails
|
|
45
|
+
*/
|
|
46
|
+
export declare function create<T extends object>(type: string, system: string, content: T, status?: string): Promise<string>;
|
|
47
|
+
/**
|
|
48
|
+
* Obtener item por ID
|
|
49
|
+
* @throws {TursoError} If query fails
|
|
50
|
+
*/
|
|
51
|
+
export declare function get<T>(id: string): Promise<{
|
|
52
|
+
id: string;
|
|
53
|
+
type: string;
|
|
54
|
+
status: string;
|
|
55
|
+
system: string;
|
|
56
|
+
content: T;
|
|
57
|
+
} | null>;
|
|
58
|
+
/**
|
|
59
|
+
* Actualizar item
|
|
60
|
+
* @throws {NotFoundError} If item not found
|
|
61
|
+
* @throws {TursoError} If update fails
|
|
62
|
+
*/
|
|
63
|
+
export declare function update<T extends object>(id: string, updates: Partial<{
|
|
64
|
+
status: string;
|
|
65
|
+
content: T;
|
|
66
|
+
}>): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Buscar items
|
|
69
|
+
* @throws {TursoError} If query fails
|
|
70
|
+
*/
|
|
71
|
+
export declare function query<T>(options: QueryOptions): Promise<Array<{
|
|
72
|
+
id: string;
|
|
73
|
+
type: string;
|
|
74
|
+
status: string;
|
|
75
|
+
system: string;
|
|
76
|
+
content: T;
|
|
77
|
+
}>>;
|
|
78
|
+
/**
|
|
79
|
+
* Eliminar item
|
|
80
|
+
* @throws {TursoError} If delete fails
|
|
81
|
+
*/
|
|
82
|
+
export declare function remove(id: string): Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* Crear nueva tarea
|
|
85
|
+
*/
|
|
86
|
+
export declare function createTask(system: string, sessionId: string, options: {
|
|
87
|
+
title: string;
|
|
88
|
+
userRequest: string;
|
|
89
|
+
plan: string[];
|
|
90
|
+
domain: string;
|
|
91
|
+
description?: string;
|
|
92
|
+
agentId?: string;
|
|
93
|
+
}): Promise<string>;
|
|
94
|
+
/**
|
|
95
|
+
* Obtener tareas activas
|
|
96
|
+
*/
|
|
97
|
+
export declare function getActiveTasks(system: string): Promise<Array<{
|
|
98
|
+
id: string;
|
|
99
|
+
content: TaskContent;
|
|
100
|
+
}>>;
|
|
101
|
+
/**
|
|
102
|
+
* Actualizar progreso de tarea
|
|
103
|
+
* @throws {NotFoundError} If task not found
|
|
104
|
+
* @throws {TursoError} If update fails
|
|
105
|
+
*/
|
|
106
|
+
export declare function updateTaskProgress(taskId: string, updates: Partial<TaskContent>): Promise<void>;
|
|
107
|
+
/**
|
|
108
|
+
* Completar tarea
|
|
109
|
+
* @throws {NotFoundError} If task not found
|
|
110
|
+
* @throws {TursoError} If update fails
|
|
111
|
+
*/
|
|
112
|
+
export declare function completeTask(taskId: string, result: {
|
|
113
|
+
result: 'success' | 'partial' | 'blocked';
|
|
114
|
+
resultNotes?: string;
|
|
115
|
+
improvements: Array<{
|
|
116
|
+
area: string;
|
|
117
|
+
title: string;
|
|
118
|
+
description: string;
|
|
119
|
+
priority: 'low' | 'medium' | 'high' | 'critical';
|
|
120
|
+
effort?: 'trivial' | 'small' | 'medium' | 'large';
|
|
121
|
+
}>;
|
|
122
|
+
lessons?: string[];
|
|
123
|
+
}): Promise<void>;
|
|
124
|
+
/**
|
|
125
|
+
* Obtener mejoras pendientes por área
|
|
126
|
+
*/
|
|
127
|
+
export declare function getPendingImprovements(system: string, area?: string): Promise<Array<{
|
|
128
|
+
id: string;
|
|
129
|
+
content: ImprovementContent;
|
|
130
|
+
}>>;
|
|
131
|
+
/**
|
|
132
|
+
* Marcar mejora como implementada
|
|
133
|
+
*/
|
|
134
|
+
export declare function markImprovementDone(improvementId: string, implementedInTask: string): Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* Crear mejora standalone (fuera de una tarea)
|
|
137
|
+
*/
|
|
138
|
+
export declare function createImprovement(system: string, improvement: {
|
|
139
|
+
area: string;
|
|
140
|
+
title: string;
|
|
141
|
+
description: string;
|
|
142
|
+
priority: 'low' | 'medium' | 'high' | 'critical';
|
|
143
|
+
effort?: 'trivial' | 'small' | 'medium' | 'large';
|
|
144
|
+
taskId?: string;
|
|
145
|
+
}): Promise<string>;
|
|
146
|
+
/**
|
|
147
|
+
* Crear nueva sesión
|
|
148
|
+
*/
|
|
149
|
+
export declare function createSession(system: string, options: {
|
|
150
|
+
userId?: string;
|
|
151
|
+
projectPath?: string;
|
|
152
|
+
ide?: string;
|
|
153
|
+
}): Promise<string>;
|
|
154
|
+
/**
|
|
155
|
+
* Actualizar actividad de sesión
|
|
156
|
+
*/
|
|
157
|
+
export declare function updateSessionActivity(sessionId: string): Promise<void>;
|
|
158
|
+
export declare const turso: {
|
|
159
|
+
init: typeof initTurso;
|
|
160
|
+
getClient: typeof getTurso;
|
|
161
|
+
setup: typeof setupTursoSchema;
|
|
162
|
+
create: typeof create;
|
|
163
|
+
getItem: typeof get;
|
|
164
|
+
update: typeof update;
|
|
165
|
+
query: typeof query;
|
|
166
|
+
remove: typeof remove;
|
|
167
|
+
createTask: typeof createTask;
|
|
168
|
+
getActiveTasks: typeof getActiveTasks;
|
|
169
|
+
updateTaskProgress: typeof updateTaskProgress;
|
|
170
|
+
completeTask: typeof completeTask;
|
|
171
|
+
createImprovement: typeof createImprovement;
|
|
172
|
+
getPendingImprovements: typeof getPendingImprovements;
|
|
173
|
+
markImprovementDone: typeof markImprovementDone;
|
|
174
|
+
createSession: typeof createSession;
|
|
175
|
+
updateSessionActivity: typeof updateSessionActivity;
|
|
176
|
+
};
|
|
177
|
+
export default turso;
|
|
178
|
+
//# sourceMappingURL=turso-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"turso-client.d.ts","sourceRoot":"","sources":["../../src/db/turso-client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAgB,KAAK,MAAM,EAAgB,MAAM,gBAAgB,CAAA;AAExE,OAAO,KAAK,EAAQ,WAAW,EAAqB,kBAAkB,EAA2B,MAAM,uBAAuB,CAAA;AAO9H,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAA;IACX,SAAS,EAAE,MAAM,CAAA;CAClB;AAGD,QAAA,MAAM,qBAAqB,+DAAgE,CAAA;AAC3F,QAAA,MAAM,kBAAkB,0BAA2B,CAAA;AAEnD,QAAA,MAAM,kBAAkB,4EAA6E,CAAA;AACrG,KAAK,WAAW,GAAG,OAAO,qBAAqB,CAAC,MAAM,CAAC,CAAA;AACvD,KAAK,QAAQ,GAAG,OAAO,kBAAkB,CAAC,MAAM,CAAC,CAAA;AACjD,KAAK,QAAQ,GAAG,OAAO,kBAAkB,CAAC,MAAM,CAAC,CAAA;AAEjD,MAAM,WAAW,YAAY;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,WAAW,CAAA;IACrB,QAAQ,CAAC,EAAE,QAAQ,CA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