vibecodepilot 0.0.0-stage → 1.0.1

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 (157) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +181 -2
  3. package/apps/dashboard/dist/assets/index-CqhDXwBX.css +1 -0
  4. package/apps/dashboard/dist/assets/index-DB7dE_Nn.js +493 -0
  5. package/apps/dashboard/dist/index.html +31 -0
  6. package/apps/dashboard/dist-server/serve-dashboard.cjs +99 -0
  7. package/apps/dashboard/package.json +23 -0
  8. package/apps/server/dist/db/database.d.ts +91 -0
  9. package/apps/server/dist/db/database.d.ts.map +1 -0
  10. package/apps/server/dist/db/database.js +902 -0
  11. package/apps/server/dist/db/database.js.map +1 -0
  12. package/apps/server/dist/index.d.ts +2 -0
  13. package/apps/server/dist/index.d.ts.map +1 -0
  14. package/apps/server/dist/index.js +2262 -0
  15. package/apps/server/dist/index.js.map +1 -0
  16. package/apps/server/dist/services/agentWorkspaceService.d.ts +89 -0
  17. package/apps/server/dist/services/agentWorkspaceService.d.ts.map +1 -0
  18. package/apps/server/dist/services/agentWorkspaceService.js +243 -0
  19. package/apps/server/dist/services/agentWorkspaceService.js.map +1 -0
  20. package/apps/server/dist/services/monitorService.d.ts +118 -0
  21. package/apps/server/dist/services/monitorService.d.ts.map +1 -0
  22. package/apps/server/dist/services/monitorService.js +497 -0
  23. package/apps/server/dist/services/monitorService.js.map +1 -0
  24. package/apps/server/dist/services/projectFlowGraph.d.ts +70 -0
  25. package/apps/server/dist/services/projectFlowGraph.d.ts.map +1 -0
  26. package/apps/server/dist/services/projectFlowGraph.js +254 -0
  27. package/apps/server/dist/services/projectFlowGraph.js.map +1 -0
  28. package/apps/server/dist/tech-detector.d.ts +2 -0
  29. package/apps/server/dist/tech-detector.d.ts.map +1 -0
  30. package/apps/server/dist/tech-detector.js +154 -0
  31. package/apps/server/dist/tech-detector.js.map +1 -0
  32. package/apps/server/dist/workspace-tools.d.ts +43 -0
  33. package/apps/server/dist/workspace-tools.d.ts.map +1 -0
  34. package/apps/server/dist/workspace-tools.js +160 -0
  35. package/apps/server/dist/workspace-tools.js.map +1 -0
  36. package/apps/server/package.json +24 -0
  37. package/node_modules/@VibeCodePilot/agent-registry/dist/index.d.ts +21 -0
  38. package/node_modules/@VibeCodePilot/agent-registry/dist/index.d.ts.map +1 -0
  39. package/node_modules/@VibeCodePilot/agent-registry/dist/index.js +194 -0
  40. package/node_modules/@VibeCodePilot/agent-registry/dist/index.js.map +1 -0
  41. package/node_modules/@VibeCodePilot/agent-registry/package.json +18 -0
  42. package/node_modules/@VibeCodePilot/git-worktrees/dist/index.d.ts +48 -0
  43. package/node_modules/@VibeCodePilot/git-worktrees/dist/index.d.ts.map +1 -0
  44. package/node_modules/@VibeCodePilot/git-worktrees/dist/index.js +121 -0
  45. package/node_modules/@VibeCodePilot/git-worktrees/dist/index.js.map +1 -0
  46. package/node_modules/@VibeCodePilot/git-worktrees/package.json +18 -0
  47. package/node_modules/@VibeCodePilot/inference-gateway/dist/index.d.ts +54 -0
  48. package/node_modules/@VibeCodePilot/inference-gateway/dist/index.d.ts.map +1 -0
  49. package/node_modules/@VibeCodePilot/inference-gateway/dist/index.js +157 -0
  50. package/node_modules/@VibeCodePilot/inference-gateway/dist/index.js.map +1 -0
  51. package/node_modules/@VibeCodePilot/inference-gateway/package.json +19 -0
  52. package/node_modules/@VibeCodePilot/integration/dist/index.d.ts +13 -0
  53. package/node_modules/@VibeCodePilot/integration/dist/index.d.ts.map +1 -0
  54. package/node_modules/@VibeCodePilot/integration/dist/index.js +83 -0
  55. package/node_modules/@VibeCodePilot/integration/dist/index.js.map +1 -0
  56. package/node_modules/@VibeCodePilot/integration/package.json +20 -0
  57. package/node_modules/@VibeCodePilot/model-manager/dist/index.d.ts +44 -0
  58. package/node_modules/@VibeCodePilot/model-manager/dist/index.d.ts.map +1 -0
  59. package/node_modules/@VibeCodePilot/model-manager/dist/index.js +192 -0
  60. package/node_modules/@VibeCodePilot/model-manager/dist/index.js.map +1 -0
  61. package/node_modules/@VibeCodePilot/model-manager/package.json +19 -0
  62. package/node_modules/@VibeCodePilot/permissions/dist/engine.d.ts +95 -0
  63. package/node_modules/@VibeCodePilot/permissions/dist/engine.d.ts.map +1 -0
  64. package/node_modules/@VibeCodePilot/permissions/dist/engine.js +294 -0
  65. package/node_modules/@VibeCodePilot/permissions/dist/engine.js.map +1 -0
  66. package/node_modules/@VibeCodePilot/permissions/dist/index.d.ts +4 -0
  67. package/node_modules/@VibeCodePilot/permissions/dist/index.d.ts.map +1 -0
  68. package/node_modules/@VibeCodePilot/permissions/dist/index.js +20 -0
  69. package/node_modules/@VibeCodePilot/permissions/dist/index.js.map +1 -0
  70. package/node_modules/@VibeCodePilot/permissions/dist/security.d.ts +31 -0
  71. package/node_modules/@VibeCodePilot/permissions/dist/security.d.ts.map +1 -0
  72. package/node_modules/@VibeCodePilot/permissions/dist/security.js +129 -0
  73. package/node_modules/@VibeCodePilot/permissions/dist/security.js.map +1 -0
  74. package/node_modules/@VibeCodePilot/permissions/dist/types.d.ts +108 -0
  75. package/node_modules/@VibeCodePilot/permissions/dist/types.d.ts.map +1 -0
  76. package/node_modules/@VibeCodePilot/permissions/dist/types.js +3 -0
  77. package/node_modules/@VibeCodePilot/permissions/dist/types.js.map +1 -0
  78. package/node_modules/@VibeCodePilot/permissions/package.json +20 -0
  79. package/node_modules/@VibeCodePilot/planner/dist/index.d.ts +35 -0
  80. package/node_modules/@VibeCodePilot/planner/dist/index.d.ts.map +1 -0
  81. package/node_modules/@VibeCodePilot/planner/dist/index.js +592 -0
  82. package/node_modules/@VibeCodePilot/planner/dist/index.js.map +1 -0
  83. package/node_modules/@VibeCodePilot/planner/package.json +19 -0
  84. package/node_modules/@VibeCodePilot/promoter/dist/index.d.ts +11 -0
  85. package/node_modules/@VibeCodePilot/promoter/dist/index.d.ts.map +1 -0
  86. package/node_modules/@VibeCodePilot/promoter/dist/index.js +117 -0
  87. package/node_modules/@VibeCodePilot/promoter/dist/index.js.map +1 -0
  88. package/node_modules/@VibeCodePilot/promoter/package.json +19 -0
  89. package/node_modules/@VibeCodePilot/prompter/dist/index.d.ts +17 -0
  90. package/node_modules/@VibeCodePilot/prompter/dist/index.d.ts.map +1 -0
  91. package/node_modules/@VibeCodePilot/prompter/dist/index.js +216 -0
  92. package/node_modules/@VibeCodePilot/prompter/dist/index.js.map +1 -0
  93. package/node_modules/@VibeCodePilot/prompter/package.json +20 -0
  94. package/node_modules/@VibeCodePilot/provider-ollama/dist/index.d.ts +58 -0
  95. package/node_modules/@VibeCodePilot/provider-ollama/dist/index.d.ts.map +1 -0
  96. package/node_modules/@VibeCodePilot/provider-ollama/dist/index.js +384 -0
  97. package/node_modules/@VibeCodePilot/provider-ollama/dist/index.js.map +1 -0
  98. package/node_modules/@VibeCodePilot/provider-ollama/package.json +18 -0
  99. package/node_modules/@VibeCodePilot/shared/dist/index.d.ts +595 -0
  100. package/node_modules/@VibeCodePilot/shared/dist/index.d.ts.map +1 -0
  101. package/node_modules/@VibeCodePilot/shared/dist/index.js +24 -0
  102. package/node_modules/@VibeCodePilot/shared/dist/index.js.map +1 -0
  103. package/node_modules/@VibeCodePilot/shared/dist/version.d.ts +14 -0
  104. package/node_modules/@VibeCodePilot/shared/dist/version.d.ts.map +1 -0
  105. package/node_modules/@VibeCodePilot/shared/dist/version.js +17 -0
  106. package/node_modules/@VibeCodePilot/shared/dist/version.js.map +1 -0
  107. package/node_modules/@VibeCodePilot/shared/package.json +24 -0
  108. package/node_modules/@VibeCodePilot/skill-registry/dist/index.d.ts +15 -0
  109. package/node_modules/@VibeCodePilot/skill-registry/dist/index.d.ts.map +1 -0
  110. package/node_modules/@VibeCodePilot/skill-registry/dist/index.js +126 -0
  111. package/node_modules/@VibeCodePilot/skill-registry/dist/index.js.map +1 -0
  112. package/node_modules/@VibeCodePilot/skill-registry/package.json +18 -0
  113. package/node_modules/@VibeCodePilot/supervisor/dist/index.d.ts +31 -0
  114. package/node_modules/@VibeCodePilot/supervisor/dist/index.d.ts.map +1 -0
  115. package/node_modules/@VibeCodePilot/supervisor/dist/index.js +219 -0
  116. package/node_modules/@VibeCodePilot/supervisor/dist/index.js.map +1 -0
  117. package/node_modules/@VibeCodePilot/supervisor/package.json +19 -0
  118. package/node_modules/@VibeCodePilot/task-scheduler/dist/index.d.ts +29 -0
  119. package/node_modules/@VibeCodePilot/task-scheduler/dist/index.d.ts.map +1 -0
  120. package/node_modules/@VibeCodePilot/task-scheduler/dist/index.js +128 -0
  121. package/node_modules/@VibeCodePilot/task-scheduler/dist/index.js.map +1 -0
  122. package/node_modules/@VibeCodePilot/task-scheduler/package.json +20 -0
  123. package/package.json +114 -4
  124. package/packages/agent-registry/package.json +18 -0
  125. package/packages/cli/bin/vibecodepilot.js +28 -0
  126. package/packages/cli/dist/config.js +143 -0
  127. package/packages/cli/dist/doctor.js +64 -0
  128. package/packages/cli/dist/index.js +260 -0
  129. package/packages/cli/dist/ollama.js +39 -0
  130. package/packages/cli/dist/pidmanager.js +153 -0
  131. package/packages/cli/dist/runtime.js +97 -0
  132. package/packages/cli/dist/servicemanager.js +227 -0
  133. package/packages/cli/package.json +25 -0
  134. package/packages/git-worktrees/package.json +18 -0
  135. package/packages/inference-gateway/package.json +19 -0
  136. package/packages/integration/package.json +20 -0
  137. package/packages/model-manager/package.json +19 -0
  138. package/packages/permissions/package.json +20 -0
  139. package/packages/planner/package.json +19 -0
  140. package/packages/promoter/package.json +19 -0
  141. package/packages/prompter/package.json +20 -0
  142. package/packages/providers/ollama/package.json +18 -0
  143. package/packages/shared/package.json +24 -0
  144. package/packages/skill-registry/package.json +18 -0
  145. package/packages/supervisor/package.json +19 -0
  146. package/packages/task-scheduler/package.json +20 -0
  147. package/skills/ai-ml/aiml-planning.json +22 -0
  148. package/skills/ai-ml/backend-planning.json +31 -0
  149. package/skills/ai-ml/frontend-planning.json +19 -0
  150. package/skills/ai-ml/ollama-local.json +11 -0
  151. package/skills/ai-ml/prompt-engineering.json +31 -0
  152. package/skills/ai-ml/task-planning.json +30 -0
  153. package/skills/backend/python-fastapi.json +11 -0
  154. package/skills/backend/ruby-rails.json +11 -0
  155. package/skills/backend/typescript-nodejs.json +11 -0
  156. package/skills/frontend/react-typescript.json +11 -0
  157. package/tsconfig.base.json +16 -0
@@ -0,0 +1,902 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.DatabaseService = void 0;
37
+ const node_sqlite_1 = require("node:sqlite");
38
+ const fs = __importStar(require("node:fs"));
39
+ const path = __importStar(require("node:path"));
40
+ class DatabaseService {
41
+ db;
42
+ constructor(dbPath) {
43
+ const dir = path.dirname(dbPath);
44
+ if (!fs.existsSync(dir)) {
45
+ fs.mkdirSync(dir, { recursive: true });
46
+ }
47
+ this.db = new node_sqlite_1.DatabaseSync(dbPath);
48
+ this.initSchema();
49
+ }
50
+ initSchema() {
51
+ this.db.exec(`
52
+ CREATE TABLE IF NOT EXISTS projects (
53
+ id TEXT PRIMARY KEY,
54
+ name TEXT NOT NULL,
55
+ path TEXT NOT NULL,
56
+ description TEXT,
57
+ detected_technologies TEXT,
58
+ assigned_specialists TEXT,
59
+ created_at TEXT NOT NULL,
60
+ updated_at TEXT NOT NULL
61
+ );
62
+
63
+ CREATE TABLE IF NOT EXISTS agents (
64
+ id TEXT PRIMARY KEY,
65
+ name TEXT NOT NULL,
66
+ role TEXT NOT NULL,
67
+ description TEXT,
68
+ skills TEXT,
69
+ tools TEXT,
70
+ system_prompt TEXT NOT NULL,
71
+ model_config TEXT NOT NULL,
72
+ permissions TEXT NOT NULL,
73
+ created_at TEXT NOT NULL
74
+ );
75
+
76
+ CREATE TABLE IF NOT EXISTS skills (
77
+ id TEXT PRIMARY KEY,
78
+ name TEXT NOT NULL,
79
+ category TEXT NOT NULL,
80
+ description TEXT,
81
+ instructions TEXT NOT NULL,
82
+ compatible_technologies TEXT,
83
+ related_skills TEXT,
84
+ version TEXT NOT NULL,
85
+ requirements TEXT
86
+ );
87
+
88
+ CREATE TABLE IF NOT EXISTS tasks (
89
+ id TEXT PRIMARY KEY,
90
+ project_id TEXT NOT NULL,
91
+ session_id TEXT,
92
+ title TEXT NOT NULL,
93
+ description TEXT NOT NULL,
94
+ priority TEXT NOT NULL DEFAULT 'medium',
95
+ assigned_agent_id TEXT,
96
+ required_skills TEXT,
97
+ scope TEXT,
98
+ dependencies TEXT,
99
+ acceptance_criteria TEXT,
100
+ status TEXT NOT NULL,
101
+ worktree_path TEXT,
102
+ git_branch TEXT,
103
+ generated_prompt_id TEXT,
104
+ completion_summary TEXT,
105
+ started_at TEXT,
106
+ completed_at TEXT,
107
+ error TEXT,
108
+ related_files TEXT,
109
+ execution_logs TEXT,
110
+ created_at TEXT NOT NULL,
111
+ updated_at TEXT NOT NULL
112
+ );
113
+
114
+ -- Migration: archived flag for tasks (added separately below, idempotently)
115
+
116
+ CREATE TABLE IF NOT EXISTS prompts (
117
+ id TEXT PRIMARY KEY,
118
+ task_id TEXT NOT NULL,
119
+ project_id TEXT NOT NULL,
120
+ assigned_agent_id TEXT NOT NULL,
121
+ target_technology_stack TEXT,
122
+ loaded_skills TEXT,
123
+ status TEXT NOT NULL,
124
+ system_context TEXT,
125
+ task_objective TEXT,
126
+ detailed_requirements TEXT,
127
+ affected_files TEXT,
128
+ api_contracts TEXT,
129
+ coding_conventions TEXT,
130
+ acceptance_criteria TEXT,
131
+ deliverables TEXT,
132
+ full_prompt_text TEXT NOT NULL,
133
+ validation_results TEXT,
134
+ human_approval_required INTEGER NOT NULL,
135
+ is_approved INTEGER NOT NULL,
136
+ execution_feedback TEXT,
137
+ created_at TEXT NOT NULL,
138
+ updated_at TEXT NOT NULL
139
+ );
140
+
141
+ CREATE TABLE IF NOT EXISTS approvals (
142
+ id TEXT PRIMARY KEY,
143
+ project_id TEXT NOT NULL,
144
+ action_type TEXT NOT NULL,
145
+ title TEXT NOT NULL,
146
+ description TEXT NOT NULL,
147
+ payload TEXT,
148
+ status TEXT NOT NULL,
149
+ requested_by TEXT NOT NULL,
150
+ reviewed_at TEXT,
151
+ comments TEXT,
152
+ created_at TEXT NOT NULL
153
+ );
154
+
155
+ CREATE TABLE IF NOT EXISTS integrations (
156
+ id TEXT PRIMARY KEY,
157
+ project_id TEXT NOT NULL,
158
+ task_ids TEXT NOT NULL,
159
+ source_branches TEXT NOT NULL,
160
+ target_branch TEXT NOT NULL,
161
+ merge_status TEXT NOT NULL,
162
+ conflicts TEXT,
163
+ changelog_summary TEXT,
164
+ release_notes TEXT,
165
+ pull_request_title TEXT,
166
+ pull_request_body TEXT,
167
+ created_at TEXT NOT NULL
168
+ );
169
+
170
+ CREATE TABLE IF NOT EXISTS promotions (
171
+ id TEXT PRIMARY KEY,
172
+ project_id TEXT NOT NULL,
173
+ mode TEXT NOT NULL,
174
+ title TEXT NOT NULL,
175
+ target_audience TEXT,
176
+ channels TEXT,
177
+ body TEXT NOT NULL,
178
+ asset_suggestions TEXT,
179
+ approved_for_publish INTEGER NOT NULL,
180
+ created_at TEXT NOT NULL
181
+ );
182
+
183
+ CREATE TABLE IF NOT EXISTS settings (
184
+ key TEXT PRIMARY KEY,
185
+ value TEXT NOT NULL
186
+ );
187
+
188
+ CREATE TABLE IF NOT EXISTS events (
189
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
190
+ type TEXT NOT NULL,
191
+ payload TEXT NOT NULL,
192
+ created_at TEXT NOT NULL
193
+ );
194
+
195
+ CREATE TABLE IF NOT EXISTS chat_sessions (
196
+ id TEXT PRIMARY KEY,
197
+ project_id TEXT,
198
+ title TEXT NOT NULL,
199
+ created_at TEXT NOT NULL,
200
+ updated_at TEXT NOT NULL
201
+ );
202
+
203
+ CREATE TABLE IF NOT EXISTS chat_messages (
204
+ id TEXT PRIMARY KEY,
205
+ session_id TEXT NOT NULL,
206
+ sender TEXT NOT NULL,
207
+ text TEXT NOT NULL,
208
+ thinking TEXT,
209
+ plan_created INTEGER DEFAULT 0,
210
+ created_tasks_count INTEGER DEFAULT 0,
211
+ timestamp TEXT NOT NULL
212
+ );
213
+
214
+ CREATE TABLE IF NOT EXISTS permission_requests (
215
+ id TEXT PRIMARY KEY,
216
+ project_id TEXT NOT NULL,
217
+ task_id TEXT NOT NULL,
218
+ session_id TEXT,
219
+ agent_id TEXT NOT NULL,
220
+ operation TEXT NOT NULL,
221
+ title TEXT NOT NULL,
222
+ target_path TEXT,
223
+ detail TEXT,
224
+ reason TEXT NOT NULL,
225
+ risk_level TEXT NOT NULL,
226
+ planned_scope TEXT NOT NULL,
227
+ requested_scope TEXT NOT NULL,
228
+ status TEXT NOT NULL,
229
+ decision TEXT,
230
+ execution_state TEXT NOT NULL,
231
+ approval_capable INTEGER NOT NULL DEFAULT 1,
232
+ hard_restriction TEXT,
233
+ requested_at TEXT NOT NULL,
234
+ resolved_at TEXT,
235
+ expires_at TEXT,
236
+ execution_result TEXT
237
+ );
238
+
239
+ CREATE TABLE IF NOT EXISTS permission_grants (
240
+ id TEXT PRIMARY KEY,
241
+ project_id TEXT NOT NULL,
242
+ task_id TEXT,
243
+ session_id TEXT,
244
+ operation TEXT NOT NULL,
245
+ scope TEXT NOT NULL,
246
+ pattern TEXT NOT NULL,
247
+ created_at TEXT NOT NULL,
248
+ expires_at TEXT
249
+ );
250
+
251
+ CREATE TABLE IF NOT EXISTS permission_audit (
252
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
253
+ permission_request_id TEXT NOT NULL,
254
+ user_decision TEXT,
255
+ requested_operation TEXT NOT NULL,
256
+ target_resource TEXT NOT NULL,
257
+ request_timestamp TEXT NOT NULL,
258
+ approval_timestamp TEXT,
259
+ task_id TEXT NOT NULL,
260
+ session_id TEXT,
261
+ execution_result TEXT,
262
+ created_at TEXT NOT NULL
263
+ );
264
+ `);
265
+ // Initialize default settings if not exists
266
+ const defaultSettings = {
267
+ ollamaEndpoint: 'http://localhost:11434',
268
+ defaultModel: 'gemma4:12b',
269
+ maxConcurrentInferences: 1,
270
+ stream: true,
271
+ modelThinkingLevels: {},
272
+ autoApproveRoutinePrompts: true,
273
+ requireApprovalForProtectedMerge: true,
274
+ requireApprovalForPublishing: true,
275
+ defaultProjectDirectory: process.env.VibeCodePilot_DATA_DIR
276
+ ? path.join(process.env.VibeCodePilot_DATA_DIR, 'projects')
277
+ : path.resolve(process.cwd(), 'data/projects')
278
+ };
279
+ for (const [key, value] of Object.entries(defaultSettings)) {
280
+ const exists = this.db.prepare('SELECT key FROM settings WHERE key = ?').get(key);
281
+ if (!exists) {
282
+ this.db.prepare('INSERT INTO settings (key, value) VALUES (?, ?)').run(key, JSON.stringify(value));
283
+ }
284
+ }
285
+ // Idempotent migration: archived flag on tasks
286
+ try {
287
+ this.db.exec('ALTER TABLE tasks ADD COLUMN archived INTEGER DEFAULT 0;');
288
+ }
289
+ catch {
290
+ // column already exists
291
+ }
292
+ for (const migration of [
293
+ 'ALTER TABLE tasks ADD COLUMN session_id TEXT;',
294
+ "ALTER TABLE tasks ADD COLUMN priority TEXT NOT NULL DEFAULT 'medium';",
295
+ 'ALTER TABLE tasks ADD COLUMN started_at TEXT;',
296
+ 'ALTER TABLE tasks ADD COLUMN completed_at TEXT;',
297
+ 'ALTER TABLE tasks ADD COLUMN error TEXT;',
298
+ 'ALTER TABLE tasks ADD COLUMN related_files TEXT;',
299
+ 'ALTER TABLE tasks ADD COLUMN execution_logs TEXT;',
300
+ 'ALTER TABLE tasks ADD COLUMN status_history TEXT;'
301
+ ]) {
302
+ try {
303
+ this.db.exec(migration);
304
+ }
305
+ catch { /* column already exists */ }
306
+ }
307
+ }
308
+ // Projects CRUD
309
+ getProjects() {
310
+ const rows = this.db.prepare('SELECT * FROM projects ORDER BY created_at DESC').all();
311
+ return rows.map(r => ({
312
+ id: r.id,
313
+ name: r.name,
314
+ path: r.path,
315
+ description: r.description || undefined,
316
+ detectedTechnologies: JSON.parse(r.detected_technologies || '[]'),
317
+ assignedSpecialists: JSON.parse(r.assigned_specialists || '[]'),
318
+ createdAt: r.created_at,
319
+ updatedAt: r.updated_at
320
+ }));
321
+ }
322
+ getProject(id) {
323
+ const r = this.db.prepare('SELECT * FROM projects WHERE id = ?').get(id);
324
+ if (!r)
325
+ return null;
326
+ return {
327
+ id: r.id,
328
+ name: r.name,
329
+ path: r.path,
330
+ description: r.description || undefined,
331
+ detectedTechnologies: JSON.parse(r.detected_technologies || '[]'),
332
+ assignedSpecialists: JSON.parse(r.assigned_specialists || '[]'),
333
+ createdAt: r.created_at,
334
+ updatedAt: r.updated_at
335
+ };
336
+ }
337
+ saveProject(p) {
338
+ this.db.prepare(`
339
+ INSERT INTO projects (id, name, path, description, detected_technologies, assigned_specialists, created_at, updated_at)
340
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?)
341
+ ON CONFLICT(id) DO UPDATE SET
342
+ name = excluded.name,
343
+ path = excluded.path,
344
+ description = excluded.description,
345
+ detected_technologies = excluded.detected_technologies,
346
+ assigned_specialists = excluded.assigned_specialists,
347
+ updated_at = excluded.updated_at
348
+ `).run(p.id, p.name, p.path, p.description || null, JSON.stringify(p.detectedTechnologies || []), JSON.stringify(p.assignedSpecialists || []), p.createdAt, p.updatedAt);
349
+ }
350
+ deleteProject(id) {
351
+ this.db.prepare('DELETE FROM projects WHERE id = ?').run(id);
352
+ }
353
+ deleteChatSession(id) {
354
+ this.db.prepare('DELETE FROM chat_messages WHERE session_id = ?').run(id);
355
+ this.db.prepare('DELETE FROM chat_sessions WHERE id = ?').run(id);
356
+ }
357
+ deleteTask(id) {
358
+ this.db.prepare('DELETE FROM tasks WHERE id = ?').run(id);
359
+ this.db.prepare('DELETE FROM prompts WHERE task_id = ?').run(id);
360
+ }
361
+ // Tasks CRUD
362
+ getTasks(projectId) {
363
+ const query = projectId
364
+ ? 'SELECT * FROM tasks WHERE project_id = ? ORDER BY created_at ASC'
365
+ : 'SELECT * FROM tasks ORDER BY created_at ASC';
366
+ const rows = (projectId
367
+ ? this.db.prepare(query).all(projectId)
368
+ : this.db.prepare(query).all());
369
+ return rows.map(r => ({
370
+ id: r.id,
371
+ projectId: r.project_id,
372
+ sessionId: r.session_id || undefined,
373
+ title: r.title,
374
+ description: r.description,
375
+ priority: r.priority || 'medium',
376
+ assignedAgentId: r.assigned_agent_id,
377
+ requiredSkills: JSON.parse(r.required_skills || '[]'),
378
+ scope: JSON.parse(r.scope || '{"affectedFiles":[],"outOfScope":[]}'),
379
+ dependencies: JSON.parse(r.dependencies || '[]'),
380
+ acceptanceCriteria: JSON.parse(r.acceptance_criteria || '[]'),
381
+ status: r.status,
382
+ worktreePath: r.worktree_path || undefined,
383
+ archived: Boolean(r.archived),
384
+ gitBranch: r.git_branch || undefined,
385
+ generatedPromptId: r.generated_prompt_id || undefined,
386
+ completionSummary: r.completion_summary || undefined,
387
+ startedAt: r.started_at || undefined,
388
+ completedAt: r.completed_at || undefined,
389
+ error: r.error || undefined,
390
+ relatedFiles: JSON.parse(r.related_files || '[]'),
391
+ executionLogs: JSON.parse(r.execution_logs || '[]'),
392
+ statusHistory: JSON.parse(r.status_history || '[]'),
393
+ createdAt: r.created_at,
394
+ updatedAt: r.updated_at
395
+ }));
396
+ }
397
+ getTask(id) {
398
+ const r = this.db.prepare('SELECT * FROM tasks WHERE id = ?').get(id);
399
+ if (!r)
400
+ return null;
401
+ return {
402
+ id: r.id,
403
+ projectId: r.project_id,
404
+ sessionId: r.session_id || undefined,
405
+ title: r.title,
406
+ description: r.description,
407
+ priority: r.priority || 'medium',
408
+ assignedAgentId: r.assigned_agent_id,
409
+ requiredSkills: JSON.parse(r.required_skills || '[]'),
410
+ scope: JSON.parse(r.scope || '{"affectedFiles":[],"outOfScope":[]}'),
411
+ dependencies: JSON.parse(r.dependencies || '[]'),
412
+ acceptanceCriteria: JSON.parse(r.acceptance_criteria || '[]'),
413
+ status: r.status,
414
+ worktreePath: r.worktree_path || undefined,
415
+ gitBranch: r.git_branch || undefined,
416
+ archived: Boolean(r.archived),
417
+ generatedPromptId: r.generated_prompt_id || undefined,
418
+ completionSummary: r.completion_summary || undefined,
419
+ startedAt: r.started_at || undefined,
420
+ completedAt: r.completed_at || undefined,
421
+ error: r.error || undefined,
422
+ relatedFiles: JSON.parse(r.related_files || '[]'),
423
+ executionLogs: JSON.parse(r.execution_logs || '[]'),
424
+ statusHistory: JSON.parse(r.status_history || '[]'),
425
+ createdAt: r.created_at,
426
+ updatedAt: r.updated_at
427
+ };
428
+ }
429
+ saveTask(t) {
430
+ this.db.prepare(`
431
+ INSERT INTO tasks (
432
+ id, project_id, session_id, title, description, priority, assigned_agent_id, required_skills, scope,
433
+ dependencies, acceptance_criteria, status, worktree_path, git_branch, archived,
434
+ generated_prompt_id, completion_summary, started_at, completed_at, error, related_files, execution_logs, status_history, created_at, updated_at
435
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
436
+ ON CONFLICT(id) DO UPDATE SET
437
+ title = excluded.title,
438
+ session_id = excluded.session_id,
439
+ description = excluded.description,
440
+ priority = excluded.priority,
441
+ assigned_agent_id = excluded.assigned_agent_id,
442
+ required_skills = excluded.required_skills,
443
+ scope = excluded.scope,
444
+ dependencies = excluded.dependencies,
445
+ acceptance_criteria = excluded.acceptance_criteria,
446
+ status = excluded.status,
447
+ worktree_path = excluded.worktree_path,
448
+ git_branch = excluded.git_branch,
449
+ archived = excluded.archived,
450
+ generated_prompt_id = excluded.generated_prompt_id,
451
+ completion_summary = excluded.completion_summary,
452
+ started_at = excluded.started_at,
453
+ completed_at = excluded.completed_at,
454
+ error = excluded.error,
455
+ related_files = excluded.related_files,
456
+ execution_logs = excluded.execution_logs,
457
+ status_history = excluded.status_history,
458
+ updated_at = excluded.updated_at
459
+ `).run(t.id, t.projectId, t.sessionId || null, t.title, t.description, t.priority || 'medium', t.assignedAgentId || null, JSON.stringify(t.requiredSkills || []), JSON.stringify(t.scope || { affectedFiles: [] }), JSON.stringify(t.dependencies || []), JSON.stringify(t.acceptanceCriteria || []), t.status, t.worktreePath || null, t.gitBranch || null, t.archived ? 1 : 0, t.generatedPromptId || null, t.completionSummary || null, t.startedAt || null, t.completedAt || null, t.error || null, JSON.stringify(t.relatedFiles || []), JSON.stringify(t.executionLogs || []), JSON.stringify(t.statusHistory || []), t.createdAt, t.updatedAt);
460
+ }
461
+ // Prompts CRUD
462
+ getPrompts(projectId) {
463
+ const query = projectId
464
+ ? 'SELECT * FROM prompts WHERE project_id = ? ORDER BY created_at DESC'
465
+ : 'SELECT * FROM prompts ORDER BY created_at DESC';
466
+ const rows = (projectId
467
+ ? this.db.prepare(query).all(projectId)
468
+ : this.db.prepare(query).all());
469
+ return rows.map(r => ({
470
+ id: r.id,
471
+ taskId: r.task_id,
472
+ projectId: r.project_id,
473
+ assignedAgentId: r.assigned_agent_id,
474
+ targetTechnologyStack: JSON.parse(r.target_technology_stack || '[]'),
475
+ loadedSkills: JSON.parse(r.loaded_skills || '[]'),
476
+ status: r.status,
477
+ systemContext: r.system_context || '',
478
+ taskObjective: r.task_objective || '',
479
+ detailedRequirements: JSON.parse(r.detailed_requirements || '[]'),
480
+ affectedFiles: JSON.parse(r.affected_files || '[]'),
481
+ apiContracts: r.api_contracts || '',
482
+ codingConventions: r.coding_conventions || '',
483
+ acceptanceCriteria: JSON.parse(r.acceptance_criteria || '[]'),
484
+ deliverables: JSON.parse(r.deliverables || '[]'),
485
+ fullPromptText: r.full_prompt_text,
486
+ validationResults: JSON.parse(r.validation_results || '{"isValid":true,"warnings":[],"errors":[]}'),
487
+ humanApprovalRequired: Boolean(r.human_approval_required),
488
+ isApproved: Boolean(r.is_approved),
489
+ executionFeedback: r.execution_feedback || undefined,
490
+ createdAt: r.created_at,
491
+ updatedAt: r.updated_at
492
+ }));
493
+ }
494
+ savePrompt(p) {
495
+ this.db.prepare(`
496
+ INSERT INTO prompts (
497
+ id, task_id, project_id, assigned_agent_id, target_technology_stack, loaded_skills,
498
+ status, system_context, task_objective, detailed_requirements, affected_files,
499
+ api_contracts, coding_conventions, acceptance_criteria, deliverables,
500
+ full_prompt_text, validation_results, human_approval_required, is_approved,
501
+ execution_feedback, created_at, updated_at
502
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
503
+ ON CONFLICT(id) DO UPDATE SET
504
+ status = excluded.status,
505
+ system_context = excluded.system_context,
506
+ task_objective = excluded.task_objective,
507
+ detailed_requirements = excluded.detailed_requirements,
508
+ affected_files = excluded.affected_files,
509
+ api_contracts = excluded.api_contracts,
510
+ coding_conventions = excluded.coding_conventions,
511
+ acceptance_criteria = excluded.acceptance_criteria,
512
+ deliverables = excluded.deliverables,
513
+ full_prompt_text = excluded.full_prompt_text,
514
+ validation_results = excluded.validation_results,
515
+ human_approval_required = excluded.human_approval_required,
516
+ is_approved = excluded.is_approved,
517
+ execution_feedback = excluded.execution_feedback,
518
+ updated_at = excluded.updated_at
519
+ `).run(p.id, p.taskId, p.projectId, p.assignedAgentId, JSON.stringify(p.targetTechnologyStack || []), JSON.stringify(p.loadedSkills || []), p.status, p.systemContext, p.taskObjective, JSON.stringify(p.detailedRequirements || []), JSON.stringify(p.affectedFiles || []), p.apiContracts, p.codingConventions, JSON.stringify(p.acceptanceCriteria || []), JSON.stringify(p.deliverables || []), p.fullPromptText, JSON.stringify(p.validationResults || { isValid: true, warnings: [], errors: [] }), p.humanApprovalRequired ? 1 : 0, p.isApproved ? 1 : 0, p.executionFeedback || null, p.createdAt, p.updatedAt);
520
+ }
521
+ // Agents CRUD
522
+ getAgents() {
523
+ const rows = this.db.prepare('SELECT * FROM agents').all();
524
+ return rows.map(r => ({
525
+ id: r.id,
526
+ name: r.name,
527
+ role: r.role,
528
+ description: r.description || '',
529
+ skills: JSON.parse(r.skills || '[]'),
530
+ tools: JSON.parse(r.tools || '[]'),
531
+ systemPrompt: r.system_prompt,
532
+ modelConfig: JSON.parse(r.model_config),
533
+ permissions: JSON.parse(r.permissions)
534
+ }));
535
+ }
536
+ saveAgent(a) {
537
+ this.db.prepare(`
538
+ INSERT INTO agents (id, name, role, description, skills, tools, system_prompt, model_config, permissions, created_at)
539
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
540
+ ON CONFLICT(id) DO UPDATE SET
541
+ name = excluded.name,
542
+ role = excluded.role,
543
+ description = excluded.description,
544
+ skills = excluded.skills,
545
+ tools = excluded.tools,
546
+ system_prompt = excluded.system_prompt,
547
+ model_config = excluded.model_config,
548
+ permissions = excluded.permissions
549
+ `).run(a.id, a.name, a.role, a.description, JSON.stringify(a.skills || []), JSON.stringify(a.tools || []), a.systemPrompt, JSON.stringify(a.modelConfig), JSON.stringify(a.permissions), new Date().toISOString());
550
+ }
551
+ // Skills CRUD
552
+ getSkills() {
553
+ const rows = this.db.prepare('SELECT * FROM skills').all();
554
+ return rows.map(r => ({
555
+ id: r.id,
556
+ name: r.name,
557
+ category: r.category,
558
+ description: r.description || '',
559
+ instructions: r.instructions,
560
+ compatibleTechnologies: JSON.parse(r.compatible_technologies || '[]'),
561
+ relatedSkills: JSON.parse(r.related_skills || '[]'),
562
+ version: r.version,
563
+ requirements: JSON.parse(r.requirements || '[]')
564
+ }));
565
+ }
566
+ saveSkill(s) {
567
+ this.db.prepare(`
568
+ INSERT INTO skills (id, name, category, description, instructions, compatible_technologies, related_skills, version, requirements)
569
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
570
+ ON CONFLICT(id) DO UPDATE SET
571
+ name = excluded.name,
572
+ category = excluded.category,
573
+ description = excluded.description,
574
+ instructions = excluded.instructions,
575
+ compatible_technologies = excluded.compatible_technologies,
576
+ related_skills = excluded.related_skills,
577
+ version = excluded.version,
578
+ requirements = excluded.requirements
579
+ `).run(s.id, s.name, s.category, s.description, s.instructions, JSON.stringify(s.compatibleTechnologies || []), JSON.stringify(s.relatedSkills || []), s.version, JSON.stringify(s.requirements || []));
580
+ }
581
+ // Approvals CRUD
582
+ getApprovals(projectId) {
583
+ const query = projectId
584
+ ? 'SELECT * FROM approvals WHERE project_id = ? ORDER BY created_at DESC'
585
+ : 'SELECT * FROM approvals ORDER BY created_at DESC';
586
+ const rows = (projectId
587
+ ? this.db.prepare(query).all(projectId)
588
+ : this.db.prepare(query).all());
589
+ return rows.map(r => ({
590
+ id: r.id,
591
+ projectId: r.project_id,
592
+ actionType: r.action_type,
593
+ title: r.title,
594
+ description: r.description,
595
+ payload: JSON.parse(r.payload || '{}'),
596
+ status: r.status,
597
+ requestedBy: r.requested_by,
598
+ reviewedAt: r.reviewed_at || undefined,
599
+ comments: r.comments || undefined,
600
+ createdAt: r.created_at
601
+ }));
602
+ }
603
+ saveApproval(app) {
604
+ this.db.prepare(`
605
+ INSERT INTO approvals (id, project_id, action_type, title, description, payload, status, requested_by, reviewed_at, comments, created_at)
606
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
607
+ ON CONFLICT(id) DO UPDATE SET
608
+ status = excluded.status,
609
+ reviewed_at = excluded.reviewed_at,
610
+ comments = excluded.comments
611
+ `).run(app.id, app.projectId, app.actionType, app.title, app.description, JSON.stringify(app.payload || {}), app.status, app.requestedBy, app.reviewedAt || null, app.comments || null, app.createdAt);
612
+ }
613
+ // Integrations CRUD
614
+ getIntegrations(projectId) {
615
+ const query = projectId
616
+ ? 'SELECT * FROM integrations WHERE project_id = ? ORDER BY created_at DESC'
617
+ : 'SELECT * FROM integrations ORDER BY created_at DESC';
618
+ const rows = (projectId
619
+ ? this.db.prepare(query).all(projectId)
620
+ : this.db.prepare(query).all());
621
+ return rows.map(r => ({
622
+ id: r.id,
623
+ projectId: r.project_id,
624
+ taskIds: JSON.parse(r.task_ids || '[]'),
625
+ sourceBranches: JSON.parse(r.source_branches || '[]'),
626
+ targetBranch: r.target_branch,
627
+ mergeStatus: r.merge_status,
628
+ conflicts: JSON.parse(r.conflicts || '[]'),
629
+ changelogSummary: r.changelog_summary || '',
630
+ releaseNotes: r.release_notes || '',
631
+ pullRequestTitle: r.pull_request_title || undefined,
632
+ pullRequestBody: r.pull_request_body || undefined,
633
+ createdAt: r.created_at
634
+ }));
635
+ }
636
+ saveIntegration(res) {
637
+ this.db.prepare(`
638
+ INSERT INTO integrations (id, project_id, task_ids, source_branches, target_branch, merge_status, conflicts, changelog_summary, release_notes, pull_request_title, pull_request_body, created_at)
639
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
640
+ ON CONFLICT(id) DO UPDATE SET
641
+ merge_status = excluded.merge_status,
642
+ conflicts = excluded.conflicts,
643
+ changelog_summary = excluded.changelog_summary,
644
+ release_notes = excluded.release_notes
645
+ `).run(res.id, res.projectId, JSON.stringify(res.taskIds), JSON.stringify(res.sourceBranches), res.targetBranch, res.mergeStatus, JSON.stringify(res.conflicts || []), res.changelogSummary, res.releaseNotes, res.pullRequestTitle || null, res.pullRequestBody || null, res.createdAt);
646
+ }
647
+ // Promotions CRUD
648
+ getPromotions(projectId) {
649
+ const query = projectId
650
+ ? 'SELECT * FROM promotions WHERE project_id = ? ORDER BY created_at DESC'
651
+ : 'SELECT * FROM promotions ORDER BY created_at DESC';
652
+ const rows = (projectId
653
+ ? this.db.prepare(query).all(projectId)
654
+ : this.db.prepare(query).all());
655
+ return rows.map(r => ({
656
+ id: r.id,
657
+ projectId: r.project_id,
658
+ mode: r.mode,
659
+ title: r.title,
660
+ targetAudience: r.target_audience || '',
661
+ channels: JSON.parse(r.channels || '[]'),
662
+ body: r.body,
663
+ assetSuggestions: JSON.parse(r.asset_suggestions || '[]'),
664
+ approvedForPublish: Boolean(r.approved_for_publish),
665
+ createdAt: r.created_at
666
+ }));
667
+ }
668
+ savePromotion(promo) {
669
+ this.db.prepare(`
670
+ INSERT INTO promotions (id, project_id, mode, title, target_audience, channels, body, asset_suggestions, approved_for_publish, created_at)
671
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
672
+ ON CONFLICT(id) DO UPDATE SET
673
+ title = excluded.title,
674
+ target_audience = excluded.target_audience,
675
+ channels = excluded.channels,
676
+ body = excluded.body,
677
+ asset_suggestions = excluded.asset_suggestions,
678
+ approved_for_publish = excluded.approved_for_publish
679
+ `).run(promo.id, promo.projectId, promo.mode, promo.title, promo.targetAudience, JSON.stringify(promo.channels), promo.body, JSON.stringify(promo.assetSuggestions), promo.approvedForPublish ? 1 : 0, promo.createdAt);
680
+ }
681
+ // Settings
682
+ getSettings() {
683
+ const rows = this.db.prepare('SELECT key, value FROM settings').all();
684
+ const result = {};
685
+ for (const r of rows) {
686
+ result[r.key] = JSON.parse(r.value);
687
+ }
688
+ return result;
689
+ }
690
+ updateSettings(settings) {
691
+ for (const [key, value] of Object.entries(settings)) {
692
+ this.db.prepare(`
693
+ INSERT INTO settings (key, value) VALUES (?, ?)
694
+ ON CONFLICT(key) DO UPDATE SET value = excluded.value
695
+ `).run(key, JSON.stringify(value));
696
+ }
697
+ }
698
+ // Events
699
+ logEvent(event) {
700
+ this.db.prepare(`
701
+ INSERT INTO events (type, payload, created_at)
702
+ VALUES (?, ?, ?)
703
+ `).run(event.type, JSON.stringify(event), new Date().toISOString());
704
+ }
705
+ getRecentEvents(limit = 50) {
706
+ const rows = this.db.prepare(`
707
+ SELECT payload FROM events ORDER BY id DESC LIMIT ?
708
+ `).all(limit);
709
+ return rows.map(r => JSON.parse(r.payload));
710
+ }
711
+ // Chat sessions & messages
712
+ getChatSessions(projectId) {
713
+ const rows = projectId
714
+ ? this.db.prepare('SELECT * FROM chat_sessions WHERE project_id = ? ORDER BY updated_at DESC').all(projectId)
715
+ : this.db.prepare('SELECT * FROM chat_sessions ORDER BY updated_at DESC').all();
716
+ return rows.map(r => ({
717
+ id: r.id,
718
+ projectId: r.project_id || undefined,
719
+ title: r.title,
720
+ createdAt: r.created_at,
721
+ updatedAt: r.updated_at
722
+ }));
723
+ }
724
+ getChatSession(id) {
725
+ const r = this.db.prepare('SELECT * FROM chat_sessions WHERE id = ?').get(id);
726
+ if (!r)
727
+ return null;
728
+ return {
729
+ id: r.id,
730
+ projectId: r.project_id || undefined,
731
+ title: r.title,
732
+ createdAt: r.created_at,
733
+ updatedAt: r.updated_at
734
+ };
735
+ }
736
+ saveChatSession(session) {
737
+ this.db.prepare(`
738
+ INSERT INTO chat_sessions (id, project_id, title, created_at, updated_at)
739
+ VALUES (?, ?, ?, ?, ?)
740
+ ON CONFLICT(id) DO UPDATE SET
741
+ title = excluded.title,
742
+ updated_at = excluded.updated_at
743
+ `).run(session.id, session.projectId || null, session.title, session.createdAt, session.updatedAt);
744
+ }
745
+ getChatMessages(sessionId) {
746
+ const rows = this.db.prepare('SELECT * FROM chat_messages WHERE session_id = ? ORDER BY timestamp ASC').all(sessionId);
747
+ return rows.map(r => ({
748
+ id: r.id,
749
+ sessionId: r.session_id,
750
+ sender: r.sender,
751
+ text: r.text,
752
+ thinking: r.thinking || undefined,
753
+ planCreated: !!r.plan_created,
754
+ createdTasksCount: r.created_tasks_count || undefined,
755
+ timestamp: r.timestamp
756
+ }));
757
+ }
758
+ // Permission requests CRUD (user-controlled task execution permissions)
759
+ getPermissionRequests(filter = {}) {
760
+ const clauses = [];
761
+ const params = [];
762
+ if (filter.projectId) {
763
+ clauses.push('project_id = ?');
764
+ params.push(filter.projectId);
765
+ }
766
+ if (filter.taskId) {
767
+ clauses.push('task_id = ?');
768
+ params.push(filter.taskId);
769
+ }
770
+ if (filter.status) {
771
+ clauses.push('status = ?');
772
+ params.push(filter.status);
773
+ }
774
+ const where = clauses.length ? `WHERE ${clauses.join(' AND ')}` : '';
775
+ const rows = this.db.prepare(`SELECT * FROM permission_requests ${where} ORDER BY requested_at DESC`).all(...params);
776
+ return rows.map(r => ({
777
+ id: r.id,
778
+ projectId: r.project_id,
779
+ taskId: r.task_id,
780
+ sessionId: r.session_id || undefined,
781
+ agentId: r.agent_id,
782
+ operation: r.operation,
783
+ title: r.title,
784
+ targetPath: r.target_path || undefined,
785
+ detail: r.detail || undefined,
786
+ reason: r.reason,
787
+ riskLevel: r.risk_level,
788
+ plannedScope: JSON.parse(r.planned_scope || '[]'),
789
+ requestedScope: r.requested_scope,
790
+ status: r.status,
791
+ decision: r.decision || null,
792
+ executionState: r.execution_state,
793
+ approvalCapable: Boolean(r.approval_capable),
794
+ hardRestriction: r.hard_restriction || undefined,
795
+ requestedAt: r.requested_at,
796
+ resolvedAt: r.resolved_at || undefined,
797
+ expiresAt: r.expires_at || undefined,
798
+ executionResult: r.execution_result || undefined
799
+ }));
800
+ }
801
+ getPermissionRequest(id) {
802
+ const found = this.getPermissionRequests({});
803
+ return found.find(r => r.id === id) || null;
804
+ }
805
+ savePermissionRequest(p) {
806
+ this.db.prepare(`
807
+ INSERT INTO permission_requests (
808
+ id, project_id, task_id, session_id, agent_id, operation, title, target_path, detail, reason,
809
+ risk_level, planned_scope, requested_scope, status, decision, execution_state,
810
+ approval_capable, hard_restriction, requested_at, resolved_at, expires_at, execution_result
811
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
812
+ ON CONFLICT(id) DO UPDATE SET
813
+ status = excluded.status,
814
+ decision = excluded.decision,
815
+ execution_state = excluded.execution_state,
816
+ resolved_at = excluded.resolved_at,
817
+ expires_at = excluded.expires_at,
818
+ execution_result = excluded.execution_result
819
+ `).run(p.id, p.projectId, p.taskId, p.sessionId || null, p.agentId, p.operation, p.title, p.targetPath || null, p.detail || null, p.reason, p.riskLevel, JSON.stringify(p.plannedScope || []), p.requestedScope, p.status, p.decision || null, p.executionState, p.approvalCapable === false ? 0 : 1, p.hardRestriction || null, p.requestedAt, p.resolvedAt || null, p.expiresAt || null, p.executionResult || null);
820
+ }
821
+ savePermissionGrant(g) {
822
+ this.db.prepare(`
823
+ INSERT INTO permission_grants (id, project_id, task_id, session_id, operation, scope, pattern, created_at, expires_at)
824
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
825
+ ON CONFLICT(id) DO UPDATE SET expires_at = excluded.expires_at
826
+ `).run(g.id, g.projectId, g.taskId || null, g.sessionId || null, g.operation, g.scope, g.pattern, g.createdAt, g.expiresAt || null);
827
+ }
828
+ getPermissionGrants(filter = {}) {
829
+ const clauses = [];
830
+ const params = [];
831
+ if (filter.projectId) {
832
+ clauses.push('project_id = ?');
833
+ params.push(filter.projectId);
834
+ }
835
+ if (filter.taskId) {
836
+ clauses.push('(task_id = ? OR task_id IS NULL)');
837
+ params.push(filter.taskId);
838
+ }
839
+ if (filter.sessionId) {
840
+ clauses.push('(session_id = ? OR session_id IS NULL)');
841
+ params.push(filter.sessionId);
842
+ }
843
+ const where = clauses.length ? `WHERE ${clauses.join(' AND ')}` : '';
844
+ const rows = this.db.prepare(`SELECT * FROM permission_grants ${where} ORDER BY created_at DESC`).all(...params);
845
+ return rows.map(r => ({
846
+ id: r.id,
847
+ projectId: r.project_id,
848
+ taskId: r.task_id || undefined,
849
+ sessionId: r.session_id || undefined,
850
+ operation: r.operation,
851
+ scope: r.scope,
852
+ pattern: r.pattern,
853
+ createdAt: r.created_at,
854
+ expiresAt: r.expires_at || undefined
855
+ }));
856
+ }
857
+ savePermissionAudit(e) {
858
+ this.db.prepare(`
859
+ INSERT INTO permission_audit (
860
+ permission_request_id, user_decision, requested_operation, target_resource,
861
+ request_timestamp, approval_timestamp, task_id, session_id, execution_result, created_at
862
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
863
+ `).run(e.permissionRequestId, e.userDecision || null, e.requestedOperation, e.targetResource, e.requestTimestamp, e.approvalTimestamp || null, e.taskId, e.sessionId || null, e.executionResult || null, new Date().toISOString());
864
+ }
865
+ getPermissionAudit(filter = {}) {
866
+ // Join against permission_requests to support project filtering.
867
+ const clauses = [];
868
+ const params = [];
869
+ let sql = `SELECT a.* FROM permission_audit a`;
870
+ if (filter.projectId) {
871
+ sql += ' JOIN permission_requests pr ON pr.id = a.permission_request_id AND pr.project_id = ?';
872
+ params.push(filter.projectId);
873
+ }
874
+ if (filter.taskId) {
875
+ clauses.push('a.task_id = ?');
876
+ params.push(filter.taskId);
877
+ }
878
+ if (clauses.length)
879
+ sql += ` WHERE ${clauses.join(' AND ')}`;
880
+ sql += ' ORDER BY a.id DESC';
881
+ const rows = this.db.prepare(sql).all(...params);
882
+ return rows.map(r => ({
883
+ permissionRequestId: r.permission_request_id,
884
+ userDecision: r.user_decision || null,
885
+ requestedOperation: r.requested_operation,
886
+ targetResource: r.target_resource,
887
+ requestTimestamp: r.request_timestamp,
888
+ approvalTimestamp: r.approval_timestamp || undefined,
889
+ taskId: r.task_id,
890
+ sessionId: r.session_id || undefined,
891
+ executionResult: r.execution_result || undefined
892
+ }));
893
+ }
894
+ saveChatMessage(m) {
895
+ this.db.prepare(`
896
+ INSERT INTO chat_messages (id, session_id, sender, text, thinking, plan_created, created_tasks_count, timestamp)
897
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?)
898
+ `).run(m.id, m.sessionId, m.sender, m.text, m.thinking || null, m.planCreated ? 1 : 0, m.createdTasksCount || 0, m.timestamp);
899
+ }
900
+ }
901
+ exports.DatabaseService = DatabaseService;
902
+ //# sourceMappingURL=database.js.map