cognova 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (205) hide show
  1. package/.env.example +58 -0
  2. package/Claude/CLAUDE.md +92 -0
  3. package/Claude/hooks/lib/__init__.py +1 -0
  4. package/Claude/hooks/lib/hook_client.py +207 -0
  5. package/Claude/hooks/log-event.py +97 -0
  6. package/Claude/hooks/pre-compact.py +46 -0
  7. package/Claude/hooks/session-end.py +26 -0
  8. package/Claude/hooks/session-start.py +35 -0
  9. package/Claude/hooks/stop-extract.py +40 -0
  10. package/Claude/rules/frontmatter.md +54 -0
  11. package/Claude/rules/markdown.md +43 -0
  12. package/Claude/rules/note-organization.md +33 -0
  13. package/Claude/settings.json +54 -0
  14. package/Claude/skills/README.md +136 -0
  15. package/Claude/skills/_lib/__init__.py +1 -0
  16. package/Claude/skills/_lib/api.py +164 -0
  17. package/Claude/skills/_lib/output.py +95 -0
  18. package/Claude/skills/environment/SKILL.md +73 -0
  19. package/Claude/skills/environment/environment.py +239 -0
  20. package/Claude/skills/memory/SKILL.md +153 -0
  21. package/Claude/skills/memory/memory.py +270 -0
  22. package/Claude/skills/project/SKILL.md +105 -0
  23. package/Claude/skills/project/project.py +203 -0
  24. package/Claude/skills/skill-creator/SKILL.md +261 -0
  25. package/Claude/skills/task/SKILL.md +135 -0
  26. package/Claude/skills/task/task.py +310 -0
  27. package/LICENSE +21 -0
  28. package/README.md +176 -0
  29. package/app/app.config.ts +8 -0
  30. package/app/app.vue +39 -0
  31. package/app/assets/css/main.css +10 -0
  32. package/app/components/AppLogo.vue +40 -0
  33. package/app/components/AssistantPanel.client.vue +518 -0
  34. package/app/components/ConfirmModal.vue +84 -0
  35. package/app/components/TemplateMenu.vue +49 -0
  36. package/app/components/agents/AgentActivityChart.client.vue +105 -0
  37. package/app/components/agents/AgentActivityChart.server.vue +25 -0
  38. package/app/components/agents/AgentForm.vue +304 -0
  39. package/app/components/agents/AgentRunModal.vue +154 -0
  40. package/app/components/agents/AgentStatsCards.vue +98 -0
  41. package/app/components/chat/ChatInput.vue +85 -0
  42. package/app/components/chat/ConversationList.vue +78 -0
  43. package/app/components/chat/MessageBubble.vue +81 -0
  44. package/app/components/chat/StreamingMessage.vue +36 -0
  45. package/app/components/chat/ToolCallBlock.vue +77 -0
  46. package/app/components/editor/CodeEditor.client.vue +212 -0
  47. package/app/components/editor/CodeEditorFallback.vue +12 -0
  48. package/app/components/editor/DocumentEditor.vue +326 -0
  49. package/app/components/editor/DocumentMetadata.vue +140 -0
  50. package/app/components/editor/MarkdownEditor.vue +146 -0
  51. package/app/components/files/FileTree.vue +436 -0
  52. package/app/components/hooks/HookActivityChart.client.vue +117 -0
  53. package/app/components/hooks/HookActivityChart.server.vue +25 -0
  54. package/app/components/hooks/HookStatsCards.vue +63 -0
  55. package/app/components/hooks/RecentEventsTable.vue +123 -0
  56. package/app/components/hooks/ToolBreakdownTable.vue +72 -0
  57. package/app/components/search/DashboardSearch.vue +122 -0
  58. package/app/components/tasks/ProjectSelect.vue +35 -0
  59. package/app/components/tasks/TaskCard.vue +182 -0
  60. package/app/components/tasks/TaskDetail.vue +160 -0
  61. package/app/components/tasks/TaskForm.vue +280 -0
  62. package/app/components/tasks/TaskList.vue +69 -0
  63. package/app/components/view/ViewToc.vue +85 -0
  64. package/app/composables/useAgents.ts +153 -0
  65. package/app/composables/useAuth.ts +73 -0
  66. package/app/composables/useChat.ts +298 -0
  67. package/app/composables/useDocument.ts +141 -0
  68. package/app/composables/useEditor.ts +100 -0
  69. package/app/composables/useFileTree.ts +220 -0
  70. package/app/composables/useHookEvents.ts +68 -0
  71. package/app/composables/useMemories.ts +83 -0
  72. package/app/composables/useNotificationBus.ts +154 -0
  73. package/app/composables/usePreferences.ts +131 -0
  74. package/app/composables/useProjects.ts +97 -0
  75. package/app/composables/useSearch.ts +52 -0
  76. package/app/composables/useTasks.ts +201 -0
  77. package/app/composables/useTerminal.ts +135 -0
  78. package/app/layouts/auth.vue +20 -0
  79. package/app/layouts/dashboard.vue +186 -0
  80. package/app/layouts/view.vue +60 -0
  81. package/app/middleware/auth.ts +9 -0
  82. package/app/pages/agents/[id].vue +602 -0
  83. package/app/pages/agents/index.vue +412 -0
  84. package/app/pages/chat.vue +146 -0
  85. package/app/pages/dashboard.vue +80 -0
  86. package/app/pages/docs.vue +131 -0
  87. package/app/pages/hooks.vue +163 -0
  88. package/app/pages/index.vue +249 -0
  89. package/app/pages/login.vue +60 -0
  90. package/app/pages/memories.vue +282 -0
  91. package/app/pages/settings.vue +625 -0
  92. package/app/pages/tasks.vue +312 -0
  93. package/app/pages/view/[uuid].vue +376 -0
  94. package/dist/cli/index.js +2711 -0
  95. package/drizzle.config.ts +10 -0
  96. package/nuxt.config.ts +98 -0
  97. package/package.json +107 -0
  98. package/server/api/agents/[id]/cancel.post.ts +27 -0
  99. package/server/api/agents/[id]/run.post.ts +34 -0
  100. package/server/api/agents/[id]/runs.get.ts +45 -0
  101. package/server/api/agents/[id]/stats.get.ts +94 -0
  102. package/server/api/agents/[id].delete.ts +29 -0
  103. package/server/api/agents/[id].get.ts +25 -0
  104. package/server/api/agents/[id].patch.ts +55 -0
  105. package/server/api/agents/index.get.ts +15 -0
  106. package/server/api/agents/index.post.ts +48 -0
  107. package/server/api/agents/stats.get.ts +86 -0
  108. package/server/api/auth/[...all].ts +5 -0
  109. package/server/api/conversations/[id].delete.ts +16 -0
  110. package/server/api/conversations/[id].get.ts +34 -0
  111. package/server/api/conversations/index.get.ts +17 -0
  112. package/server/api/documents/[id]/index.delete.ts +47 -0
  113. package/server/api/documents/[id]/index.put.ts +102 -0
  114. package/server/api/documents/[id]/public.get.ts +60 -0
  115. package/server/api/documents/[id]/restore.post.ts +65 -0
  116. package/server/api/documents/by-path.post.ts +168 -0
  117. package/server/api/documents/index.get.ts +48 -0
  118. package/server/api/fs/delete.post.ts +41 -0
  119. package/server/api/fs/list.get.ts +99 -0
  120. package/server/api/fs/mkdir.post.ts +44 -0
  121. package/server/api/fs/move.post.ts +68 -0
  122. package/server/api/fs/read.post.ts +48 -0
  123. package/server/api/fs/rename.post.ts +55 -0
  124. package/server/api/fs/write.post.ts +51 -0
  125. package/server/api/health.get.ts +40 -0
  126. package/server/api/home.get.ts +26 -0
  127. package/server/api/hooks/events/index.get.ts +56 -0
  128. package/server/api/hooks/events/index.post.ts +36 -0
  129. package/server/api/hooks/stats.get.ts +99 -0
  130. package/server/api/memory/[id].delete.ts +26 -0
  131. package/server/api/memory/context.get.ts +83 -0
  132. package/server/api/memory/extract.post.ts +42 -0
  133. package/server/api/memory/search.get.ts +70 -0
  134. package/server/api/memory/store.post.ts +31 -0
  135. package/server/api/projects/[id]/index.delete.ts +40 -0
  136. package/server/api/projects/[id]/index.get.ts +25 -0
  137. package/server/api/projects/[id]/index.put.ts +50 -0
  138. package/server/api/projects/index.get.ts +20 -0
  139. package/server/api/projects/index.post.ts +34 -0
  140. package/server/api/secrets/[key].delete.ts +31 -0
  141. package/server/api/secrets/[key].get.ts +30 -0
  142. package/server/api/secrets/[key].put.ts +52 -0
  143. package/server/api/secrets/index.get.ts +20 -0
  144. package/server/api/secrets/index.post.ts +58 -0
  145. package/server/api/tasks/[id]/index.delete.ts +46 -0
  146. package/server/api/tasks/[id]/index.get.ts +24 -0
  147. package/server/api/tasks/[id]/index.put.ts +70 -0
  148. package/server/api/tasks/[id]/restore.post.ts +49 -0
  149. package/server/api/tasks/index.get.ts +53 -0
  150. package/server/api/tasks/index.post.ts +47 -0
  151. package/server/api/tasks/tags.get.ts +21 -0
  152. package/server/api/user/email.patch.ts +56 -0
  153. package/server/db/index.ts +76 -0
  154. package/server/db/migrate.ts +41 -0
  155. package/server/db/schema.ts +345 -0
  156. package/server/db/seed.ts +46 -0
  157. package/server/db/types.ts +28 -0
  158. package/server/drizzle/migrations/0000_brown_george_stacy.sql +34 -0
  159. package/server/drizzle/migrations/0001_stormy_pyro.sql +16 -0
  160. package/server/drizzle/migrations/0002_clean_colossus.sql +50 -0
  161. package/server/drizzle/migrations/0003_fine_joystick.sql +12 -0
  162. package/server/drizzle/migrations/0004_tan_groot.sql +26 -0
  163. package/server/drizzle/migrations/0005_cloudy_lilith.sql +33 -0
  164. package/server/drizzle/migrations/0006_ordinary_retro_girl.sql +13 -0
  165. package/server/drizzle/migrations/0007_flowery_venus.sql +15 -0
  166. package/server/drizzle/migrations/0008_talented_zombie.sql +13 -0
  167. package/server/drizzle/migrations/0009_gray_shen.sql +15 -0
  168. package/server/drizzle/migrations/meta/0000_snapshot.json +230 -0
  169. package/server/drizzle/migrations/meta/0001_snapshot.json +306 -0
  170. package/server/drizzle/migrations/meta/0002_snapshot.json +615 -0
  171. package/server/drizzle/migrations/meta/0003_snapshot.json +730 -0
  172. package/server/drizzle/migrations/meta/0004_snapshot.json +916 -0
  173. package/server/drizzle/migrations/meta/0005_snapshot.json +1127 -0
  174. package/server/drizzle/migrations/meta/0006_snapshot.json +1213 -0
  175. package/server/drizzle/migrations/meta/0007_snapshot.json +1307 -0
  176. package/server/drizzle/migrations/meta/0008_snapshot.json +1390 -0
  177. package/server/drizzle/migrations/meta/0009_snapshot.json +1487 -0
  178. package/server/drizzle/migrations/meta/_journal.json +76 -0
  179. package/server/middleware/auth.ts +79 -0
  180. package/server/plugins/00.env-validate.ts +38 -0
  181. package/server/plugins/01.api-token.ts +31 -0
  182. package/server/plugins/02.database.ts +54 -0
  183. package/server/plugins/03.file-watcher.ts +65 -0
  184. package/server/plugins/04.cron-agents.ts +26 -0
  185. package/server/routes/_ws/chat.ts +252 -0
  186. package/server/routes/notifications.ts +47 -0
  187. package/server/routes/terminal.ts +98 -0
  188. package/server/services/agent-executor.ts +218 -0
  189. package/server/services/cron-scheduler.ts +78 -0
  190. package/server/services/memory-extractor.ts +120 -0
  191. package/server/utils/agent-cleanup.ts +91 -0
  192. package/server/utils/agent-registry.ts +95 -0
  193. package/server/utils/auth.ts +33 -0
  194. package/server/utils/chat-session-manager.ts +59 -0
  195. package/server/utils/crypto.ts +40 -0
  196. package/server/utils/db-guard.ts +12 -0
  197. package/server/utils/db-state.ts +63 -0
  198. package/server/utils/document-sync.ts +207 -0
  199. package/server/utils/frontmatter.ts +84 -0
  200. package/server/utils/notification-bus.ts +60 -0
  201. package/server/utils/path-validator.ts +55 -0
  202. package/server/utils/pty-manager.ts +130 -0
  203. package/shared/types/index.ts +604 -0
  204. package/shared/utils/language-detection.ts +87 -0
  205. package/tsconfig.json +10 -0
@@ -0,0 +1,130 @@
1
+ import { createRequire } from 'module'
2
+ import { resolve } from 'path'
3
+ import type { IPty } from 'node-pty'
4
+ import { getVaultRoot } from './path-validator'
5
+
6
+ // Use createRequire for node-pty to avoid ESM issues with native modules
7
+ // For bundled builds, we need to resolve from a known location
8
+ const requireFromCwd = createRequire(resolve(process.cwd(), 'package.json'))
9
+ const pty = requireFromCwd('node-pty')
10
+
11
+ interface PtySession {
12
+ pty: IPty
13
+ outputBuffer: string[]
14
+ maxBufferSize: number
15
+ lastActivity: number
16
+ }
17
+
18
+ const sessions = new Map<string, PtySession>()
19
+ const MAX_BUFFER_SIZE = 10000 // Lines to keep in buffer
20
+ const SESSION_TIMEOUT = 30 * 60 * 1000 // 30 minutes
21
+
22
+ export function createPtySession(sessionId: string, cols = 80, rows = 24): IPty {
23
+ const shell = process.env.SHELL || '/bin/bash'
24
+ const cwd = getVaultRoot()
25
+
26
+ console.log(`[PTY] Creating session: shell=${shell}, cwd=${cwd}, cols=${cols}, rows=${rows}`)
27
+
28
+ const ptyProcess = pty.spawn(shell, [], {
29
+ name: 'xterm-256color',
30
+ cols,
31
+ rows,
32
+ cwd,
33
+ env: {
34
+ ...process.env,
35
+ TERM: 'xterm-256color',
36
+ COLORTERM: 'truecolor'
37
+ }
38
+ }) as IPty
39
+
40
+ const session: PtySession = {
41
+ pty: ptyProcess,
42
+ outputBuffer: [],
43
+ maxBufferSize: MAX_BUFFER_SIZE,
44
+ lastActivity: Date.now()
45
+ }
46
+
47
+ // Buffer output for replay on reconnect
48
+ ptyProcess.onData((data: string) => {
49
+ session.lastActivity = Date.now()
50
+ session.outputBuffer.push(data)
51
+
52
+ // Trim buffer if too large
53
+ if (session.outputBuffer.length > session.maxBufferSize) {
54
+ session.outputBuffer = session.outputBuffer.slice(-session.maxBufferSize / 2)
55
+ }
56
+ })
57
+
58
+ ptyProcess.onExit(() => {
59
+ sessions.delete(sessionId)
60
+ })
61
+
62
+ sessions.set(sessionId, session)
63
+ return ptyProcess
64
+ }
65
+
66
+ export function getPtySession(sessionId: string): PtySession | undefined {
67
+ const session = sessions.get(sessionId)
68
+ if (session) {
69
+ session.lastActivity = Date.now()
70
+ }
71
+ return session
72
+ }
73
+
74
+ export function getOrCreatePtySession(sessionId: string, cols = 80, rows = 24): { pty: IPty, isNew: boolean } {
75
+ const existing = sessions.get(sessionId)
76
+ if (existing) {
77
+ existing.lastActivity = Date.now()
78
+ return { pty: existing.pty, isNew: false }
79
+ }
80
+
81
+ const pty = createPtySession(sessionId, cols, rows)
82
+ return { pty, isNew: true }
83
+ }
84
+
85
+ export function getOutputBuffer(sessionId: string): string[] {
86
+ const session = sessions.get(sessionId)
87
+ return session?.outputBuffer || []
88
+ }
89
+
90
+ export function resizePty(sessionId: string, cols: number, rows: number): boolean {
91
+ const session = sessions.get(sessionId)
92
+ if (session) {
93
+ session.pty.resize(cols, rows)
94
+ session.lastActivity = Date.now()
95
+ return true
96
+ }
97
+ return false
98
+ }
99
+
100
+ export function writeToPty(sessionId: string, data: string): boolean {
101
+ const session = sessions.get(sessionId)
102
+ if (session) {
103
+ session.pty.write(data)
104
+ session.lastActivity = Date.now()
105
+ return true
106
+ }
107
+ return false
108
+ }
109
+
110
+ export function destroyPtySession(sessionId: string): boolean {
111
+ const session = sessions.get(sessionId)
112
+ if (session) {
113
+ session.pty.kill()
114
+ sessions.delete(sessionId)
115
+ return true
116
+ }
117
+ return false
118
+ }
119
+
120
+ // Cleanup inactive sessions periodically
121
+ setInterval(() => {
122
+ const now = Date.now()
123
+ for (const [sessionId, session] of sessions) {
124
+ if (now - session.lastActivity > SESSION_TIMEOUT) {
125
+ console.log(`Cleaning up inactive PTY session: ${sessionId}`)
126
+ session.pty.kill()
127
+ sessions.delete(sessionId)
128
+ }
129
+ }
130
+ }, 60000) // Check every minute
@@ -0,0 +1,604 @@
1
+ // === Users ===
2
+
3
+ export interface User {
4
+ id: string
5
+ name: string
6
+ email: string
7
+ image?: string
8
+ }
9
+
10
+ // === Projects ===
11
+
12
+ export interface Project {
13
+ id: string
14
+ name: string
15
+ color: string
16
+ description?: string
17
+ createdAt: Date
18
+ modifiedAt?: Date
19
+ deletedAt?: Date
20
+ createdBy?: string
21
+ modifiedBy?: string
22
+ deletedBy?: string
23
+ creator?: User
24
+ }
25
+
26
+ export interface CreateProjectInput {
27
+ name: string
28
+ color: string
29
+ description?: string
30
+ }
31
+
32
+ export interface UpdateProjectInput {
33
+ name?: string
34
+ color?: string
35
+ description?: string
36
+ }
37
+
38
+ // === Tasks ===
39
+
40
+ export type TaskStatus = 'todo' | 'in_progress' | 'done' | 'blocked'
41
+
42
+ export interface Task {
43
+ id: string
44
+ title: string
45
+ description?: string
46
+ status: TaskStatus
47
+ priority: number // 1=Low, 2=Medium, 3=High
48
+ projectId?: string
49
+ project?: Project // Populated on fetch
50
+ dueDate?: Date
51
+ tags: string[]
52
+ createdAt: Date
53
+ modifiedAt?: Date
54
+ completedAt?: Date
55
+ deletedAt?: Date
56
+ createdBy?: string
57
+ modifiedBy?: string
58
+ deletedBy?: string
59
+ creator?: User // Populated on fetch
60
+ }
61
+
62
+ export interface CreateTaskInput {
63
+ title: string
64
+ description?: string
65
+ status?: TaskStatus
66
+ priority?: number // 1-3, defaults to 2
67
+ projectId?: string
68
+ dueDate?: string
69
+ tags?: string[]
70
+ }
71
+
72
+ export interface UpdateTaskInput {
73
+ title?: string
74
+ description?: string
75
+ status?: TaskStatus
76
+ priority?: number
77
+ projectId?: string | null
78
+ dueDate?: string | null
79
+ tags?: string[]
80
+ }
81
+
82
+ export interface TaskFilters {
83
+ status?: TaskStatus | TaskStatus[]
84
+ projectId?: string
85
+ search?: string
86
+ includeDeleted?: boolean
87
+ }
88
+
89
+ // === Reminders ===
90
+
91
+ export interface Reminder {
92
+ id: string
93
+ taskId?: string
94
+ message: string
95
+ remindAt: Date
96
+ notified: boolean
97
+ createdAt: Date
98
+ }
99
+
100
+ // === Files ===
101
+
102
+ export interface FileEntry {
103
+ name: string
104
+ path: string
105
+ type: 'file' | 'directory'
106
+ size?: number
107
+ modifiedAt?: Date
108
+ children?: FileEntry[]
109
+ }
110
+
111
+ export interface FileContent {
112
+ path: string
113
+ content: string
114
+ modifiedAt: Date
115
+ }
116
+
117
+ // === Documents ===
118
+
119
+ export type ShareType = 'public' | 'private'
120
+ export type FileType = 'markdown' | 'text' | 'binary'
121
+
122
+ export type CodeLanguage
123
+ = 'markdown'
124
+ | 'javascript'
125
+ | 'typescript'
126
+ | 'json'
127
+ | 'html'
128
+ | 'css'
129
+ | 'vue'
130
+ | 'python'
131
+ | 'sql'
132
+ | 'yaml'
133
+ | 'bash'
134
+ | 'go'
135
+ | 'rust'
136
+ | 'dockerfile'
137
+ | 'java'
138
+ | 'cpp'
139
+ | 'xml'
140
+ | 'plaintext'
141
+
142
+ export interface Document {
143
+ id: string
144
+ title: string
145
+ path: string
146
+ content?: string
147
+ contentHash?: string
148
+ tags: string[]
149
+ projectId?: string
150
+ project?: Project
151
+ shared: boolean
152
+ shareType?: ShareType
153
+ fileType: FileType
154
+ mimeType?: string
155
+ syncedAt?: Date
156
+ createdAt: Date
157
+ createdBy?: string
158
+ creator?: User
159
+ modifiedAt?: Date
160
+ modifiedBy?: string
161
+ deletedAt?: Date
162
+ deletedBy?: string
163
+ }
164
+
165
+ export interface DocumentMetadata {
166
+ title: string
167
+ tags: string[]
168
+ projectId?: string
169
+ shared: boolean
170
+ shareType?: ShareType
171
+ [key: string]: unknown
172
+ }
173
+
174
+ export interface DocumentWithContent {
175
+ document: Document
176
+ metadata: DocumentMetadata
177
+ body: string
178
+ }
179
+
180
+ export interface UpdateDocumentInput {
181
+ title?: string
182
+ tags?: string[]
183
+ projectId?: string | null
184
+ shared?: boolean
185
+ shareType?: ShareType | null
186
+ body?: string
187
+ }
188
+
189
+ // TOC types for MDC parseMarkdown output
190
+ export interface TocLink {
191
+ id: string
192
+ text: string
193
+ depth: number
194
+ children?: TocLink[]
195
+ }
196
+
197
+ // Public document viewer API response
198
+ export interface PublicDocumentResponse {
199
+ document: Pick<Document, 'id' | 'title' | 'path' | 'fileType' | 'shared' | 'shareType' | 'tags' | 'createdAt' | 'modifiedAt'> & {
200
+ creatorName: string | null
201
+ }
202
+ content: string | null
203
+ isOwner: boolean
204
+ }
205
+
206
+ // === Conversations ===
207
+
208
+ export interface Conversation {
209
+ id: string
210
+ startedAt: Date
211
+ endedAt?: Date
212
+ messageCount: number
213
+ summary?: string
214
+ }
215
+
216
+ export interface ConversationDetail extends Conversation {
217
+ messages: ConversationMessage[]
218
+ }
219
+
220
+ export interface ConversationMessage {
221
+ role: 'user' | 'assistant'
222
+ content: string
223
+ timestamp: Date
224
+ }
225
+
226
+ // === API ===
227
+
228
+ export interface ApiResponse<T> {
229
+ data?: T
230
+ error?: string
231
+ }
232
+
233
+ // === Editor ===
234
+
235
+ export type SaveStatus = 'idle' | 'saving' | 'saved' | 'error'
236
+
237
+ // === Cron Agents ===
238
+
239
+ export type AgentStatus = 'success' | 'error' | 'budget_exceeded' | 'cancelled'
240
+ export type RunStatus = 'running' | 'success' | 'error' | 'budget_exceeded' | 'cancelled'
241
+
242
+ export interface CronAgent {
243
+ id: string
244
+ name: string
245
+ description?: string
246
+ schedule: string
247
+ prompt: string
248
+ enabled: boolean
249
+ maxTurns?: number
250
+ maxBudgetUsd?: number
251
+ lastRunAt?: Date
252
+ lastStatus?: AgentStatus
253
+ createdAt: Date
254
+ updatedAt: Date
255
+ createdBy?: string
256
+ creator?: User
257
+ }
258
+
259
+ export interface CronAgentRun {
260
+ id: string
261
+ agentId: string
262
+ status: RunStatus
263
+ output?: string
264
+ error?: string
265
+ costUsd?: number
266
+ inputTokens?: number
267
+ outputTokens?: number
268
+ numTurns?: number
269
+ startedAt: Date
270
+ completedAt?: Date
271
+ durationMs?: number
272
+ }
273
+
274
+ export interface CreateAgentInput {
275
+ name: string
276
+ description?: string
277
+ schedule: string
278
+ prompt: string
279
+ enabled?: boolean
280
+ maxTurns?: number
281
+ maxBudgetUsd?: number
282
+ }
283
+
284
+ export interface UpdateAgentInput {
285
+ name?: string
286
+ description?: string
287
+ schedule?: string
288
+ prompt?: string
289
+ enabled?: boolean
290
+ maxTurns?: number
291
+ maxBudgetUsd?: number | null
292
+ }
293
+
294
+ // === Notification Bus ===
295
+
296
+ export type NotificationType
297
+ = 'agent:started'
298
+ | 'agent:completed'
299
+ | 'agent:failed'
300
+ | 'toast'
301
+
302
+ export interface NotificationPayload {
303
+ type: NotificationType
304
+ agentId?: string
305
+ agentName?: string
306
+ runId?: string
307
+ status?: string
308
+ message?: string
309
+ title?: string
310
+ color?: 'success' | 'error' | 'warning' | 'info'
311
+ timestamp?: string
312
+ }
313
+
314
+ // === Agent Stats ===
315
+
316
+ export type StatsPeriod = '24h' | '7d' | '30d'
317
+
318
+ export interface DailyRunData {
319
+ date: string
320
+ success: number
321
+ error: number
322
+ total: number
323
+ costUsd: number
324
+ }
325
+
326
+ export interface AgentGlobalStats {
327
+ totalAgents: number
328
+ activeAgents: number
329
+ runsInPeriod: number
330
+ successRate: number
331
+ totalCostUsd: number
332
+ runningAgentIds: string[]
333
+ dailyRuns: DailyRunData[]
334
+ }
335
+
336
+ export interface AgentDetailStats {
337
+ totalRuns: number
338
+ successRate: number
339
+ avgDurationMs: number
340
+ totalCostUsd: number
341
+ lastRunAt: string | null
342
+ dailyRuns: DailyRunData[]
343
+ }
344
+
345
+ // === Hook Events ===
346
+
347
+ export type HookEventType
348
+ = | 'SessionStart'
349
+ | 'SessionEnd'
350
+ | 'PreToolUse'
351
+ | 'PostToolUse'
352
+ | 'PostToolUseFailure'
353
+ | 'UserPromptSubmit'
354
+
355
+ export interface HookEvent {
356
+ id: string
357
+ eventType: HookEventType
358
+ sessionId?: string
359
+ projectDir?: string
360
+ toolName?: string
361
+ toolMatcher?: string
362
+ eventData?: Record<string, unknown>
363
+ exitCode?: number
364
+ blocked: boolean
365
+ blockReason?: string
366
+ durationMs?: number
367
+ hookScript?: string
368
+ createdAt: Date
369
+ }
370
+
371
+ export interface CreateHookEventInput {
372
+ eventType: HookEventType
373
+ sessionId?: string
374
+ projectDir?: string
375
+ toolName?: string
376
+ toolMatcher?: string
377
+ eventData?: Record<string, unknown>
378
+ exitCode?: number
379
+ blocked?: boolean
380
+ blockReason?: string
381
+ durationMs?: number
382
+ hookScript?: string
383
+ }
384
+
385
+ export interface HookEventFilters {
386
+ eventType?: HookEventType | HookEventType[]
387
+ sessionId?: string
388
+ toolName?: string
389
+ blocked?: boolean | string // Query params can be string 'true'/'false'
390
+ since?: string
391
+ limit?: number
392
+ }
393
+
394
+ // === Hook Analytics Stats ===
395
+
396
+ export interface HookDailyData {
397
+ date: string
398
+ total: number
399
+ blocked: number
400
+ allowed: number
401
+ avgDurationMs: number
402
+ }
403
+
404
+ export interface HookToolBreakdown {
405
+ toolName: string
406
+ total: number
407
+ blocked: number
408
+ avgDurationMs: number
409
+ }
410
+
411
+ export interface HookEventStats {
412
+ totalEvents: number
413
+ blockedEvents: number
414
+ blockRate: number
415
+ avgDurationMs: number
416
+ eventsByType: Partial<Record<HookEventType, number>>
417
+ toolBreakdown: HookToolBreakdown[]
418
+ dailyActivity: HookDailyData[]
419
+ recentSessions: string[]
420
+ }
421
+
422
+ // === Memory System ===
423
+
424
+ export type MemoryChunkType
425
+ = | 'decision'
426
+ | 'fact'
427
+ | 'solution'
428
+ | 'pattern'
429
+ | 'preference'
430
+ | 'summary'
431
+
432
+ export interface MemoryChunk {
433
+ id: string
434
+ sessionId?: string
435
+ projectPath?: string
436
+ chunkType: MemoryChunkType
437
+ content: string
438
+ sourceExcerpt?: string
439
+ relevanceScore: number
440
+ accessCount: number
441
+ lastAccessedAt?: Date
442
+ createdAt: Date
443
+ expiresAt?: Date
444
+ }
445
+
446
+ export interface CreateMemoryInput {
447
+ sessionId?: string
448
+ projectPath?: string
449
+ chunkType: MemoryChunkType
450
+ content: string
451
+ sourceExcerpt?: string
452
+ relevanceScore?: number
453
+ }
454
+
455
+ export interface MemorySearchFilters {
456
+ query?: string
457
+ projectPath?: string
458
+ chunkType?: MemoryChunkType | MemoryChunkType[]
459
+ minRelevance?: number
460
+ limit?: number
461
+ }
462
+
463
+ export interface ExtractMemoryInput {
464
+ transcript: string
465
+ sessionId?: string
466
+ projectPath?: string
467
+ }
468
+
469
+ export interface ExtractedMemory {
470
+ type: MemoryChunkType
471
+ content: string
472
+ relevance: number
473
+ }
474
+
475
+ export interface MemoryContextResponse {
476
+ memories: MemoryChunk[]
477
+ formatted: string
478
+ }
479
+
480
+ // === Chat System ===
481
+
482
+ export type ChatSessionStatus = 'idle' | 'streaming' | 'interrupted' | 'error'
483
+ export type ChatConnectionStatus = 'disconnected' | 'connecting' | 'connected' | 'error'
484
+
485
+ // Content blocks (maps to SDK content structure)
486
+ export interface ChatTextBlock {
487
+ type: 'text'
488
+ text: string
489
+ }
490
+
491
+ export interface ChatToolUseBlock {
492
+ type: 'tool_use'
493
+ id: string
494
+ name: string
495
+ input: Record<string, unknown>
496
+ }
497
+
498
+ export interface ChatToolResultBlock {
499
+ type: 'tool_result'
500
+ tool_use_id: string
501
+ content: string
502
+ is_error?: boolean
503
+ }
504
+
505
+ export type ChatContentBlock = ChatTextBlock | ChatToolUseBlock | ChatToolResultBlock
506
+
507
+ // Persisted message
508
+ export interface ChatMessage {
509
+ id: string
510
+ conversationId: string
511
+ role: 'user' | 'assistant'
512
+ content: ChatContentBlock[]
513
+ costUsd?: number
514
+ durationMs?: number
515
+ createdAt: Date
516
+ }
517
+
518
+ // Conversation metadata
519
+ export interface ChatConversation {
520
+ id: string
521
+ sessionId: string
522
+ sdkSessionId?: string
523
+ title?: string
524
+ summary?: string
525
+ status: ChatSessionStatus
526
+ totalCostUsd: number
527
+ messageCount: number
528
+ startedAt: Date
529
+ endedAt?: Date
530
+ }
531
+
532
+ // WebSocket protocol: Client -> Server
533
+ export interface ChatSendMessage {
534
+ type: 'chat:send'
535
+ message: string
536
+ conversationId?: string
537
+ }
538
+
539
+ export interface ChatInterruptMessage {
540
+ type: 'chat:interrupt'
541
+ conversationId: string
542
+ }
543
+
544
+ export type ChatClientMessage = ChatSendMessage | ChatInterruptMessage
545
+
546
+ // WebSocket protocol: Server -> Client
547
+ export interface ChatSessionCreated {
548
+ type: 'chat:session_created'
549
+ conversationId: string
550
+ }
551
+
552
+ export interface ChatStreamStart {
553
+ type: 'chat:stream_start'
554
+ conversationId: string
555
+ }
556
+
557
+ export interface ChatTextDelta {
558
+ type: 'chat:text_delta'
559
+ conversationId: string
560
+ delta: string
561
+ }
562
+
563
+ export interface ChatToolStart {
564
+ type: 'chat:tool_start'
565
+ conversationId: string
566
+ toolUseId: string
567
+ toolName: string
568
+ }
569
+
570
+ export interface ChatToolEnd {
571
+ type: 'chat:tool_end'
572
+ conversationId: string
573
+ toolUseId: string
574
+ result: string
575
+ isError: boolean
576
+ }
577
+
578
+ export interface ChatStreamEnd {
579
+ type: 'chat:stream_end'
580
+ conversationId: string
581
+ costUsd: number
582
+ durationMs: number
583
+ }
584
+
585
+ export interface ChatError {
586
+ type: 'chat:error'
587
+ conversationId?: string
588
+ message: string
589
+ }
590
+
591
+ export interface ChatInterrupted {
592
+ type: 'chat:interrupted'
593
+ conversationId: string
594
+ }
595
+
596
+ export type ChatServerMessage
597
+ = ChatSessionCreated
598
+ | ChatStreamStart
599
+ | ChatTextDelta
600
+ | ChatToolStart
601
+ | ChatToolEnd
602
+ | ChatStreamEnd
603
+ | ChatError
604
+ | ChatInterrupted