@esotech/contextuate 2.0.0 → 2.1.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.
- package/README.md +169 -1
- package/dist/commands/claude.d.ts +21 -0
- package/dist/commands/claude.js +213 -0
- package/dist/commands/context.d.ts +1 -0
- package/dist/commands/create.d.ts +3 -0
- package/dist/commands/index.d.ts +4 -0
- package/dist/commands/init.d.ts +7 -0
- package/dist/commands/init.js +67 -6
- package/dist/commands/install.d.ts +28 -0
- package/dist/commands/install.js +100 -11
- package/dist/commands/monitor.d.ts +55 -0
- package/dist/commands/monitor.js +1007 -0
- package/dist/commands/remove.d.ts +3 -0
- package/dist/commands/run.d.ts +6 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +113 -1
- package/dist/monitor/daemon/circuit-breaker.d.ts +121 -0
- package/dist/monitor/daemon/circuit-breaker.js +552 -0
- package/dist/monitor/daemon/cli.d.ts +8 -0
- package/dist/monitor/daemon/cli.js +82 -0
- package/dist/monitor/daemon/index.d.ts +137 -0
- package/dist/monitor/daemon/index.js +695 -0
- package/dist/monitor/daemon/notifier.d.ts +25 -0
- package/dist/monitor/daemon/notifier.js +98 -0
- package/dist/monitor/daemon/processor.d.ts +89 -0
- package/dist/monitor/daemon/processor.js +455 -0
- package/dist/monitor/daemon/state.d.ts +80 -0
- package/dist/monitor/daemon/state.js +162 -0
- package/dist/monitor/daemon/watcher.d.ts +47 -0
- package/dist/monitor/daemon/watcher.js +171 -0
- package/dist/monitor/daemon/wrapper-manager.d.ts +106 -0
- package/dist/monitor/daemon/wrapper-manager.js +374 -0
- package/dist/monitor/hooks/emit-event.js +652 -0
- package/dist/monitor/persistence/file-store.d.ts +88 -0
- package/dist/monitor/persistence/file-store.js +335 -0
- package/dist/monitor/persistence/index.d.ts +7 -0
- package/dist/monitor/persistence/index.js +10 -0
- package/dist/monitor/server/adapters/redis.d.ts +38 -0
- package/dist/monitor/server/adapters/redis.js +213 -0
- package/dist/monitor/server/adapters/unix-socket.d.ts +33 -0
- package/dist/monitor/server/adapters/unix-socket.js +182 -0
- package/dist/monitor/server/broker.d.ts +135 -0
- package/dist/monitor/server/broker.js +475 -0
- package/dist/monitor/server/cli.d.ts +8 -0
- package/dist/monitor/server/cli.js +98 -0
- package/dist/monitor/server/fastify.d.ts +16 -0
- package/dist/monitor/server/fastify.js +184 -0
- package/dist/monitor/server/index.d.ts +36 -0
- package/dist/monitor/server/index.js +153 -0
- package/dist/monitor/server/websocket.d.ts +80 -0
- package/dist/monitor/server/websocket.js +453 -0
- package/dist/monitor/ui/assets/index-4IssW9On.js +59 -0
- package/dist/monitor/ui/assets/index-vo9hLe5R.css +32 -0
- package/dist/monitor/ui/favicon.png +0 -0
- package/dist/monitor/ui/index.html +14 -0
- package/dist/monitor/ui/logo.png +0 -0
- package/dist/monitor/ui/logo.svg +1 -0
- package/dist/runtime/driver.d.ts +16 -0
- package/dist/runtime/tools.d.ts +10 -0
- package/dist/templates/README.md +33 -7
- package/dist/templates/agents/aegis.md +4 -0
- package/dist/templates/agents/archon.md +13 -22
- package/dist/templates/agents/atlas.md +4 -0
- package/dist/templates/agents/canvas.md +4 -0
- package/dist/templates/agents/chronicle.md +4 -0
- package/dist/templates/agents/chronos.md +4 -0
- package/dist/templates/agents/cipher.md +4 -0
- package/dist/templates/agents/crucible.md +4 -0
- package/dist/templates/agents/echo.md +4 -0
- package/dist/templates/agents/forge.md +4 -0
- package/dist/templates/agents/ledger.md +4 -0
- package/dist/templates/agents/meridian.md +4 -0
- package/dist/templates/agents/nexus.md +4 -0
- package/dist/templates/agents/pythia.md +217 -0
- package/dist/templates/agents/scribe.md +4 -0
- package/dist/templates/agents/sentinel.md +4 -0
- package/dist/templates/agents/{oracle.md → thoth.md} +11 -7
- package/dist/templates/agents/unity.md +4 -0
- package/dist/templates/agents/vox.md +4 -0
- package/dist/templates/agents/weaver.md +4 -0
- package/dist/templates/commands/consult.md +138 -0
- package/dist/templates/commands/orchestrate.md +173 -0
- package/dist/templates/framework-agents/documentation-expert.md +3 -3
- package/dist/templates/framework-agents/tools-expert.md +8 -8
- package/dist/templates/standards/agent-roles.md +68 -21
- package/dist/templates/standards/coding-standards.md +9 -26
- package/dist/templates/templates/context.md +17 -2
- package/dist/templates/templates/contextuate.md +21 -28
- package/dist/templates/tools/{agent-creator.tool.md → agent-creator.md} +3 -3
- package/dist/types/monitor.d.ts +660 -0
- package/dist/types/monitor.js +75 -0
- package/dist/utils/git.d.ts +9 -0
- package/dist/utils/tokens.d.ts +10 -0
- package/package.json +18 -5
- package/dist/templates/version.json +0 -8
- /package/dist/templates/templates/standards/{go.standards.md → go.md} +0 -0
- /package/dist/templates/templates/standards/{java.standards.md → java.md} +0 -0
- /package/dist/templates/templates/standards/{javascript.standards.md → javascript.md} +0 -0
- /package/dist/templates/templates/standards/{php.standards.md → php.md} +0 -0
- /package/dist/templates/templates/standards/{python.standards.md → python.md} +0 -0
- /package/dist/templates/tools/{quickref.tool.md → quickref.md} +0 -0
- /package/dist/templates/tools/{spawn.tool.md → spawn.md} +0 -0
- /package/dist/templates/tools/{standards-detector.tool.md → standards-detector.md} +0 -0
|
@@ -0,0 +1,660 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contextuate Monitor - Type Definitions
|
|
3
|
+
*
|
|
4
|
+
* Shared TypeScript types for the monitor feature.
|
|
5
|
+
* Used by both server and client components.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Types of events that can be monitored
|
|
9
|
+
*/
|
|
10
|
+
export type MonitorEventType = 'session_start' | 'session_end' | 'tool_call' | 'tool_result' | 'tool_error' | 'message' | 'notification' | 'thinking' | 'error' | 'agent_spawn' | 'agent_complete' | 'subagent_start' | 'subagent_stop' | 'user_prompt' | 'pre_compact' | 'permission_request';
|
|
11
|
+
/**
|
|
12
|
+
* Claude hook types that trigger events
|
|
13
|
+
*/
|
|
14
|
+
export type ClaudeHookType = 'SessionStart' | 'SessionEnd' | 'PreToolUse' | 'PostToolUse' | 'PostToolUseFailure' | 'Notification' | 'UserPromptSubmit' | 'Stop' | 'SubagentStart' | 'SubagentStop' | 'PreCompact' | 'PermissionRequest';
|
|
15
|
+
/**
|
|
16
|
+
* Token usage metrics
|
|
17
|
+
*/
|
|
18
|
+
export interface TokenUsage {
|
|
19
|
+
input: number;
|
|
20
|
+
output: number;
|
|
21
|
+
cacheRead?: number;
|
|
22
|
+
cacheWrite?: number;
|
|
23
|
+
/** Cache creation tokens (5-minute ephemeral) */
|
|
24
|
+
cacheCreation5m?: number;
|
|
25
|
+
/** Cache creation tokens (1-hour ephemeral) */
|
|
26
|
+
cacheCreation1h?: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Thinking block from Claude's chain of thought
|
|
30
|
+
*/
|
|
31
|
+
export interface ThinkingBlock {
|
|
32
|
+
/** The thinking/reasoning content */
|
|
33
|
+
content: string;
|
|
34
|
+
/** Timestamp when this thinking occurred */
|
|
35
|
+
timestamp: number;
|
|
36
|
+
/** Request ID this thinking belongs to */
|
|
37
|
+
requestId?: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Error information in events
|
|
41
|
+
*/
|
|
42
|
+
export interface EventError {
|
|
43
|
+
code: string;
|
|
44
|
+
message: string;
|
|
45
|
+
stack?: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Subagent information
|
|
49
|
+
*/
|
|
50
|
+
export interface SubagentInfo {
|
|
51
|
+
type: string;
|
|
52
|
+
prompt: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Data payload for monitor events
|
|
56
|
+
*/
|
|
57
|
+
export interface EventData {
|
|
58
|
+
toolName?: string;
|
|
59
|
+
toolInput?: unknown;
|
|
60
|
+
toolOutput?: unknown;
|
|
61
|
+
message?: string;
|
|
62
|
+
/** Single thinking content (legacy, for backward compat) */
|
|
63
|
+
thinking?: string;
|
|
64
|
+
/** Array of thinking blocks from the session */
|
|
65
|
+
thinkingBlocks?: ThinkingBlock[];
|
|
66
|
+
tokenUsage?: TokenUsage;
|
|
67
|
+
/** Cumulative token usage for the session */
|
|
68
|
+
sessionTokenUsage?: TokenUsage;
|
|
69
|
+
error?: EventError;
|
|
70
|
+
subagent?: SubagentInfo;
|
|
71
|
+
/** Model used for this interaction */
|
|
72
|
+
model?: string;
|
|
73
|
+
/** Path to the transcript file */
|
|
74
|
+
transcriptPath?: string;
|
|
75
|
+
/** Final assistant response (from transcript parsing) */
|
|
76
|
+
assistantResponse?: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Core monitor event structure
|
|
80
|
+
*/
|
|
81
|
+
export interface MonitorEvent {
|
|
82
|
+
id: string;
|
|
83
|
+
timestamp: number;
|
|
84
|
+
sessionId: string;
|
|
85
|
+
parentSessionId?: string;
|
|
86
|
+
machineId: string;
|
|
87
|
+
workingDirectory: string;
|
|
88
|
+
eventType: MonitorEventType;
|
|
89
|
+
hookType: ClaudeHookType;
|
|
90
|
+
data: EventData;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Session status
|
|
94
|
+
*/
|
|
95
|
+
export type SessionStatus = 'active' | 'completed' | 'error';
|
|
96
|
+
/**
|
|
97
|
+
* Session metadata
|
|
98
|
+
*/
|
|
99
|
+
export interface SessionMeta {
|
|
100
|
+
sessionId: string;
|
|
101
|
+
machineId: string;
|
|
102
|
+
workingDirectory: string;
|
|
103
|
+
startTime: number;
|
|
104
|
+
endTime?: number;
|
|
105
|
+
status: SessionStatus;
|
|
106
|
+
parentSessionId?: string;
|
|
107
|
+
childSessionIds: string[];
|
|
108
|
+
tokenUsage: {
|
|
109
|
+
totalInput: number;
|
|
110
|
+
totalOutput: number;
|
|
111
|
+
totalCacheRead?: number;
|
|
112
|
+
totalCacheCreation?: number;
|
|
113
|
+
};
|
|
114
|
+
hidden?: boolean;
|
|
115
|
+
/** Agent type for sub-agents (e.g., "nexus", "canvas", "archon") */
|
|
116
|
+
agentType?: string;
|
|
117
|
+
/** Whether this session was user-initiated (not spawned by Task tool) */
|
|
118
|
+
isUserInitiated?: boolean;
|
|
119
|
+
/** Whether this session is pinned to the top of the session list */
|
|
120
|
+
isPinned?: boolean;
|
|
121
|
+
/** Manual parent override set by user via UI */
|
|
122
|
+
manualParentSessionId?: string;
|
|
123
|
+
/** Custom label/name set by user */
|
|
124
|
+
label?: string;
|
|
125
|
+
/** Model used in this session */
|
|
126
|
+
model?: string;
|
|
127
|
+
/** Path to the transcript file */
|
|
128
|
+
transcriptPath?: string;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Monitor mode - local (Unix socket) or distributed (Redis)
|
|
132
|
+
*/
|
|
133
|
+
export type MonitorMode = 'local' | 'redis';
|
|
134
|
+
/**
|
|
135
|
+
* Persistence type
|
|
136
|
+
*/
|
|
137
|
+
export type PersistenceType = 'file' | 'mysql' | 'postgresql';
|
|
138
|
+
/**
|
|
139
|
+
* Server configuration
|
|
140
|
+
*/
|
|
141
|
+
export interface ServerConfig {
|
|
142
|
+
host: string;
|
|
143
|
+
port: number;
|
|
144
|
+
wsPort: number;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Redis configuration
|
|
148
|
+
*/
|
|
149
|
+
export interface RedisConfig {
|
|
150
|
+
host: string;
|
|
151
|
+
port: number;
|
|
152
|
+
password: string | null;
|
|
153
|
+
channel: string;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Database configuration
|
|
157
|
+
*/
|
|
158
|
+
export interface DatabaseConfig {
|
|
159
|
+
host: string;
|
|
160
|
+
port: number;
|
|
161
|
+
database: string;
|
|
162
|
+
user: string;
|
|
163
|
+
password: string;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Persistence configuration
|
|
167
|
+
*/
|
|
168
|
+
export interface PersistenceConfig {
|
|
169
|
+
enabled: boolean;
|
|
170
|
+
type: PersistenceType;
|
|
171
|
+
database?: DatabaseConfig;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Complete monitor configuration
|
|
175
|
+
*/
|
|
176
|
+
export interface MonitorConfig {
|
|
177
|
+
mode: MonitorMode;
|
|
178
|
+
server: ServerConfig;
|
|
179
|
+
redis: RedisConfig;
|
|
180
|
+
persistence: PersistenceConfig;
|
|
181
|
+
socketPath: string;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Default configuration values
|
|
185
|
+
*/
|
|
186
|
+
export declare const DEFAULT_CONFIG: MonitorConfig;
|
|
187
|
+
/**
|
|
188
|
+
* Get default monitor paths
|
|
189
|
+
*
|
|
190
|
+
* @returns MonitorPaths with all default directory and file paths
|
|
191
|
+
*/
|
|
192
|
+
export declare function getDefaultMonitorPaths(): MonitorPaths;
|
|
193
|
+
/**
|
|
194
|
+
* Client to server message types
|
|
195
|
+
*/
|
|
196
|
+
export type ClientMessage = {
|
|
197
|
+
type: 'subscribe';
|
|
198
|
+
sessionIds?: string[];
|
|
199
|
+
} | {
|
|
200
|
+
type: 'unsubscribe';
|
|
201
|
+
sessionIds: string[];
|
|
202
|
+
} | {
|
|
203
|
+
type: 'get_sessions';
|
|
204
|
+
} | {
|
|
205
|
+
type: 'get_events';
|
|
206
|
+
sessionId: string;
|
|
207
|
+
limit?: number;
|
|
208
|
+
before?: number;
|
|
209
|
+
} | {
|
|
210
|
+
type: 'get_all_recent_events';
|
|
211
|
+
limit?: number;
|
|
212
|
+
} | {
|
|
213
|
+
type: 'get_event_detail';
|
|
214
|
+
eventId: string;
|
|
215
|
+
sessionId: string;
|
|
216
|
+
} | {
|
|
217
|
+
type: 'send_input';
|
|
218
|
+
sessionId: string;
|
|
219
|
+
input: string;
|
|
220
|
+
} | {
|
|
221
|
+
type: 'hide_session';
|
|
222
|
+
sessionId: string;
|
|
223
|
+
} | {
|
|
224
|
+
type: 'unhide_session';
|
|
225
|
+
sessionId: string;
|
|
226
|
+
} | {
|
|
227
|
+
type: 'delete_session';
|
|
228
|
+
sessionId: string;
|
|
229
|
+
} | {
|
|
230
|
+
type: 'hide_all_sessions';
|
|
231
|
+
} | {
|
|
232
|
+
type: 'delete_all_sessions';
|
|
233
|
+
} | {
|
|
234
|
+
type: 'set_show_hidden';
|
|
235
|
+
showHidden: boolean;
|
|
236
|
+
} | {
|
|
237
|
+
type: 'set_parent';
|
|
238
|
+
sessionId: string;
|
|
239
|
+
parentSessionId: string | null;
|
|
240
|
+
} | {
|
|
241
|
+
type: 'toggle_pin';
|
|
242
|
+
sessionId: string;
|
|
243
|
+
} | {
|
|
244
|
+
type: 'set_user_initiated';
|
|
245
|
+
sessionId: string;
|
|
246
|
+
isUserInitiated: boolean;
|
|
247
|
+
} | {
|
|
248
|
+
type: 'rename_session';
|
|
249
|
+
sessionId: string;
|
|
250
|
+
label: string;
|
|
251
|
+
} | {
|
|
252
|
+
type: 'get_wrappers';
|
|
253
|
+
} | {
|
|
254
|
+
type: 'inject_input';
|
|
255
|
+
wrapperId: string;
|
|
256
|
+
input: string;
|
|
257
|
+
} | {
|
|
258
|
+
type: 'resize_wrapper';
|
|
259
|
+
wrapperId: string;
|
|
260
|
+
cols: number;
|
|
261
|
+
rows: number;
|
|
262
|
+
} | {
|
|
263
|
+
type: 'spawn_wrapper';
|
|
264
|
+
cwd?: string;
|
|
265
|
+
args?: string[];
|
|
266
|
+
cols?: number;
|
|
267
|
+
rows?: number;
|
|
268
|
+
} | {
|
|
269
|
+
type: 'kill_wrapper';
|
|
270
|
+
wrapperId: string;
|
|
271
|
+
} | {
|
|
272
|
+
type: 'get_circuit_health';
|
|
273
|
+
} | {
|
|
274
|
+
type: 'get_session_health';
|
|
275
|
+
sessionId: string;
|
|
276
|
+
} | {
|
|
277
|
+
type: 'reset_circuit';
|
|
278
|
+
sessionId: string;
|
|
279
|
+
} | {
|
|
280
|
+
type: 'update_circuit_config';
|
|
281
|
+
config: Partial<CircuitBreakerConfig>;
|
|
282
|
+
};
|
|
283
|
+
/**
|
|
284
|
+
* Wrapper session state
|
|
285
|
+
*/
|
|
286
|
+
export type WrapperState = 'starting' | 'processing' | 'waiting_input' | 'ended';
|
|
287
|
+
/**
|
|
288
|
+
* Wrapper session info (for UI)
|
|
289
|
+
*/
|
|
290
|
+
export interface WrapperInfo {
|
|
291
|
+
wrapperId: string;
|
|
292
|
+
state: WrapperState;
|
|
293
|
+
claudeSessionId: string | null;
|
|
294
|
+
cwd?: string;
|
|
295
|
+
startTime?: number;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Wrapper terminal output chunk
|
|
299
|
+
*/
|
|
300
|
+
export interface WrapperOutput {
|
|
301
|
+
wrapperId: string;
|
|
302
|
+
data: string;
|
|
303
|
+
timestamp: number;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Server to client message types
|
|
307
|
+
*/
|
|
308
|
+
export type ServerMessage = {
|
|
309
|
+
type: 'sessions';
|
|
310
|
+
sessions: SessionMeta[];
|
|
311
|
+
} | {
|
|
312
|
+
type: 'event';
|
|
313
|
+
event: MonitorEvent;
|
|
314
|
+
} | {
|
|
315
|
+
type: 'session_update';
|
|
316
|
+
session: SessionMeta;
|
|
317
|
+
} | {
|
|
318
|
+
type: 'sessions_updated';
|
|
319
|
+
sessions: SessionMeta[];
|
|
320
|
+
} | {
|
|
321
|
+
type: 'events';
|
|
322
|
+
sessionId: string;
|
|
323
|
+
events: MonitorEvent[];
|
|
324
|
+
} | {
|
|
325
|
+
type: 'all_events';
|
|
326
|
+
events: MonitorEvent[];
|
|
327
|
+
} | {
|
|
328
|
+
type: 'event_detail';
|
|
329
|
+
event: MonitorEvent;
|
|
330
|
+
} | {
|
|
331
|
+
type: 'error';
|
|
332
|
+
message: string;
|
|
333
|
+
} | {
|
|
334
|
+
type: 'wrappers';
|
|
335
|
+
wrappers: WrapperInfo[];
|
|
336
|
+
} | {
|
|
337
|
+
type: 'wrapper_connected';
|
|
338
|
+
wrapperId: string;
|
|
339
|
+
state: WrapperState;
|
|
340
|
+
} | {
|
|
341
|
+
type: 'wrapper_disconnected';
|
|
342
|
+
wrapperId: string;
|
|
343
|
+
exitCode?: number;
|
|
344
|
+
} | {
|
|
345
|
+
type: 'wrapper_state';
|
|
346
|
+
wrapperId: string;
|
|
347
|
+
state: WrapperState;
|
|
348
|
+
claudeSessionId?: string;
|
|
349
|
+
} | {
|
|
350
|
+
type: 'wrapper_output';
|
|
351
|
+
wrapperId: string;
|
|
352
|
+
data: string;
|
|
353
|
+
timestamp: number;
|
|
354
|
+
} | {
|
|
355
|
+
type: 'wrapper_spawned';
|
|
356
|
+
wrapperId?: string;
|
|
357
|
+
success: boolean;
|
|
358
|
+
error?: string;
|
|
359
|
+
} | {
|
|
360
|
+
type: 'circuit_alert';
|
|
361
|
+
alert: CircuitAlert;
|
|
362
|
+
} | {
|
|
363
|
+
type: 'circuit_health';
|
|
364
|
+
health: SessionHealth[];
|
|
365
|
+
} | {
|
|
366
|
+
type: 'session_health';
|
|
367
|
+
health: SessionHealth;
|
|
368
|
+
} | {
|
|
369
|
+
type: 'circuit_config';
|
|
370
|
+
config: CircuitBreakerConfig;
|
|
371
|
+
};
|
|
372
|
+
/**
|
|
373
|
+
* Event handler callback
|
|
374
|
+
*/
|
|
375
|
+
export type EventHandler = (event: MonitorEvent) => void | Promise<void>;
|
|
376
|
+
/**
|
|
377
|
+
* IPC Adapter interface - implemented by Unix socket and Redis adapters
|
|
378
|
+
*/
|
|
379
|
+
export interface IPCAdapter {
|
|
380
|
+
/**
|
|
381
|
+
* Start listening for events
|
|
382
|
+
*/
|
|
383
|
+
start(): Promise<void>;
|
|
384
|
+
/**
|
|
385
|
+
* Stop listening and cleanup
|
|
386
|
+
*/
|
|
387
|
+
stop(): Promise<void>;
|
|
388
|
+
/**
|
|
389
|
+
* Register an event handler
|
|
390
|
+
*/
|
|
391
|
+
onEvent(handler: EventHandler): void;
|
|
392
|
+
/**
|
|
393
|
+
* Check if adapter is running
|
|
394
|
+
*/
|
|
395
|
+
isRunning(): boolean;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Persistence store interface
|
|
399
|
+
*/
|
|
400
|
+
export interface PersistenceStore {
|
|
401
|
+
/**
|
|
402
|
+
* Initialize the store
|
|
403
|
+
*/
|
|
404
|
+
init(): Promise<void>;
|
|
405
|
+
/**
|
|
406
|
+
* Close the store
|
|
407
|
+
*/
|
|
408
|
+
close(): Promise<void>;
|
|
409
|
+
/**
|
|
410
|
+
* Save an event
|
|
411
|
+
*/
|
|
412
|
+
saveEvent(event: MonitorEvent): Promise<void>;
|
|
413
|
+
/**
|
|
414
|
+
* Get events for a session
|
|
415
|
+
*/
|
|
416
|
+
getEvents(sessionId: string, options?: {
|
|
417
|
+
limit?: number;
|
|
418
|
+
before?: number;
|
|
419
|
+
after?: number;
|
|
420
|
+
}): Promise<MonitorEvent[]>;
|
|
421
|
+
/**
|
|
422
|
+
* Get a single event by ID
|
|
423
|
+
*/
|
|
424
|
+
getEventById(sessionId: string, eventId: string): Promise<MonitorEvent | null>;
|
|
425
|
+
/**
|
|
426
|
+
* Get all recent events across all sessions
|
|
427
|
+
*/
|
|
428
|
+
getAllRecentEvents(limit?: number): Promise<MonitorEvent[]>;
|
|
429
|
+
/**
|
|
430
|
+
* Save session metadata
|
|
431
|
+
*/
|
|
432
|
+
saveSession(session: SessionMeta): Promise<void>;
|
|
433
|
+
/**
|
|
434
|
+
* Get session metadata
|
|
435
|
+
*/
|
|
436
|
+
getSession(sessionId: string): Promise<SessionMeta | null>;
|
|
437
|
+
/**
|
|
438
|
+
* Get all sessions
|
|
439
|
+
*/
|
|
440
|
+
getSessions(options?: {
|
|
441
|
+
status?: SessionStatus;
|
|
442
|
+
limit?: number;
|
|
443
|
+
}): Promise<SessionMeta[]>;
|
|
444
|
+
/**
|
|
445
|
+
* Update session metadata
|
|
446
|
+
*/
|
|
447
|
+
updateSession(sessionId: string, updates: Partial<SessionMeta>): Promise<void>;
|
|
448
|
+
/**
|
|
449
|
+
* Delete a session
|
|
450
|
+
*/
|
|
451
|
+
deleteSession(sessionId: string): Promise<void>;
|
|
452
|
+
/**
|
|
453
|
+
* Delete all sessions
|
|
454
|
+
*/
|
|
455
|
+
deleteAllSessions(): Promise<void>;
|
|
456
|
+
/**
|
|
457
|
+
* Delete old sessions
|
|
458
|
+
*/
|
|
459
|
+
pruneOldSessions(olderThan: number): Promise<number>;
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Claude hook payload structure (received from stdin)
|
|
463
|
+
*/
|
|
464
|
+
export interface ClaudeHookPayload {
|
|
465
|
+
hook_type: ClaudeHookType;
|
|
466
|
+
session_id?: string;
|
|
467
|
+
/** Path to the transcript JSONL file */
|
|
468
|
+
transcript_path?: string;
|
|
469
|
+
/** Current working directory */
|
|
470
|
+
cwd?: string;
|
|
471
|
+
tool_name?: string;
|
|
472
|
+
tool_input?: unknown;
|
|
473
|
+
tool_output?: unknown;
|
|
474
|
+
message?: string;
|
|
475
|
+
error?: {
|
|
476
|
+
code: string;
|
|
477
|
+
message: string;
|
|
478
|
+
};
|
|
479
|
+
token_usage?: {
|
|
480
|
+
input_tokens: number;
|
|
481
|
+
output_tokens: number;
|
|
482
|
+
cache_read_tokens?: number;
|
|
483
|
+
cache_write_tokens?: number;
|
|
484
|
+
};
|
|
485
|
+
subagent?: {
|
|
486
|
+
type: string;
|
|
487
|
+
prompt: string;
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Hook script response (output to stdout)
|
|
492
|
+
*/
|
|
493
|
+
export interface HookResponse {
|
|
494
|
+
continue: boolean;
|
|
495
|
+
reason?: string;
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Monitor directory paths
|
|
499
|
+
*/
|
|
500
|
+
export interface MonitorPaths {
|
|
501
|
+
/** Base directory: ~/.contextuate/monitor */
|
|
502
|
+
baseDir: string;
|
|
503
|
+
/** Configuration file: ~/.contextuate/monitor/config.json */
|
|
504
|
+
configFile: string;
|
|
505
|
+
/** Raw events directory: ~/.contextuate/monitor/raw */
|
|
506
|
+
rawDir: string;
|
|
507
|
+
/** Processed events directory: ~/.contextuate/monitor/processed */
|
|
508
|
+
processedDir: string;
|
|
509
|
+
/** Sessions directory: ~/.contextuate/monitor/sessions */
|
|
510
|
+
sessionsDir: string;
|
|
511
|
+
/** Hooks directory: ~/.contextuate/monitor/hooks */
|
|
512
|
+
hooksDir: string;
|
|
513
|
+
/** Daemon PID file: ~/.contextuate/monitor/daemon.pid */
|
|
514
|
+
daemonPidFile: string;
|
|
515
|
+
/** Daemon log file: ~/.contextuate/monitor/daemon.log */
|
|
516
|
+
daemonLogFile: string;
|
|
517
|
+
/** Daemon state file: ~/.contextuate/monitor/daemon.state.json */
|
|
518
|
+
daemonStateFile: string;
|
|
519
|
+
/** Server PID file: ~/.contextuate/monitor/server.pid */
|
|
520
|
+
serverPidFile: string;
|
|
521
|
+
/** Server log file: ~/.contextuate/monitor/server.log */
|
|
522
|
+
serverLogFile: string;
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Pending subagent spawn information
|
|
526
|
+
*/
|
|
527
|
+
export interface PendingSubagentSpawn {
|
|
528
|
+
sessionId: string;
|
|
529
|
+
agentType: string;
|
|
530
|
+
timestamp: number;
|
|
531
|
+
prompt: string;
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* Active subagent in the stack
|
|
535
|
+
*/
|
|
536
|
+
export interface ActiveSubagent {
|
|
537
|
+
sessionId: string;
|
|
538
|
+
agentType: string;
|
|
539
|
+
prompt: string;
|
|
540
|
+
startTime: number;
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* Daemon state
|
|
544
|
+
*/
|
|
545
|
+
export interface DaemonState {
|
|
546
|
+
/** Last processed timestamp */
|
|
547
|
+
lastProcessedTimestamp: number;
|
|
548
|
+
/** Pending subagent spawns */
|
|
549
|
+
pendingSubagentSpawns: PendingSubagentSpawn[];
|
|
550
|
+
/** Active subagent stacks by parent session ID */
|
|
551
|
+
activeSubagentStacks: Record<string, ActiveSubagent[]>;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Result type for operations that can fail
|
|
555
|
+
*/
|
|
556
|
+
export type Result<T, E = Error> = {
|
|
557
|
+
ok: true;
|
|
558
|
+
value: T;
|
|
559
|
+
} | {
|
|
560
|
+
ok: false;
|
|
561
|
+
error: E;
|
|
562
|
+
};
|
|
563
|
+
/**
|
|
564
|
+
* Event subscription
|
|
565
|
+
*/
|
|
566
|
+
export interface Subscription {
|
|
567
|
+
sessionIds: Set<string>;
|
|
568
|
+
allSessions: boolean;
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* WebSocket client with subscription info
|
|
572
|
+
*/
|
|
573
|
+
export interface WSClient {
|
|
574
|
+
id: string;
|
|
575
|
+
subscription: Subscription;
|
|
576
|
+
showHidden: boolean;
|
|
577
|
+
send: (message: ServerMessage) => void;
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* Circuit breaker state
|
|
581
|
+
*/
|
|
582
|
+
export type CircuitState = 'CLOSED' | 'HALF_OPEN' | 'OPEN';
|
|
583
|
+
/**
|
|
584
|
+
* Circuit breaker configuration
|
|
585
|
+
*/
|
|
586
|
+
export interface CircuitBreakerConfig {
|
|
587
|
+
/** Enable circuit breaker monitoring (default: true) */
|
|
588
|
+
enabled: boolean;
|
|
589
|
+
/** No events at all timeout - process might be hung (default: 300 = 5 min) */
|
|
590
|
+
noEventTimeout: number;
|
|
591
|
+
/** No progress (file changes) timeout (default: 600 = 10 min) */
|
|
592
|
+
noProgressTimeout: number;
|
|
593
|
+
/** Maximum session duration hard limit (default: 7200 = 2 hrs) */
|
|
594
|
+
maxSessionDuration: number;
|
|
595
|
+
/** Loops with no file changes before warning (default: 3) */
|
|
596
|
+
noProgressLoops: number;
|
|
597
|
+
/** Same error repeated threshold (default: 5) */
|
|
598
|
+
sameErrorThreshold: number;
|
|
599
|
+
/** Cron expression for health check interval (default: every 30 seconds) */
|
|
600
|
+
healthCheckInterval: string;
|
|
601
|
+
/** Automatically inject a "you're stuck" prompt (default: true) */
|
|
602
|
+
autoInjectPrompt: boolean;
|
|
603
|
+
/** Automatically kill session on circuit open (default: false) */
|
|
604
|
+
autoKill: boolean;
|
|
605
|
+
/** Automatically restart session after kill (default: false) */
|
|
606
|
+
autoRestart: boolean;
|
|
607
|
+
/** Grace period in ms after prompt injection before kill (default: 60000 = 1 min) */
|
|
608
|
+
gracePeriodMs: number;
|
|
609
|
+
/** Base prompt to inject when stuck */
|
|
610
|
+
stuckPrompt: string;
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* Default circuit breaker configuration
|
|
614
|
+
*/
|
|
615
|
+
export declare const DEFAULT_CIRCUIT_BREAKER_CONFIG: CircuitBreakerConfig;
|
|
616
|
+
/**
|
|
617
|
+
* Health metrics for a session
|
|
618
|
+
*/
|
|
619
|
+
export interface SessionHealth {
|
|
620
|
+
sessionId: string;
|
|
621
|
+
wrapperId: string | null;
|
|
622
|
+
state: CircuitState;
|
|
623
|
+
/** Timestamp of last event received */
|
|
624
|
+
lastEventTime: number;
|
|
625
|
+
/** Timestamp of last file modification (progress) */
|
|
626
|
+
lastProgressTime: number;
|
|
627
|
+
/** Session start timestamp */
|
|
628
|
+
sessionStartTime: number;
|
|
629
|
+
/** Number of loops (Stop events) since last progress */
|
|
630
|
+
loopsSinceProgress: number;
|
|
631
|
+
/** Consecutive errors of the same type */
|
|
632
|
+
consecutiveErrors: number;
|
|
633
|
+
/** Last error message */
|
|
634
|
+
lastError: string | null;
|
|
635
|
+
/** Total events processed */
|
|
636
|
+
totalEvents: number;
|
|
637
|
+
/** Total errors encountered */
|
|
638
|
+
totalErrors: number;
|
|
639
|
+
/** Number of files modified */
|
|
640
|
+
filesModified: number;
|
|
641
|
+
recommendation: 'continue' | 'warn' | 'intervene';
|
|
642
|
+
}
|
|
643
|
+
/**
|
|
644
|
+
* Circuit breaker alert emitted when state changes
|
|
645
|
+
*/
|
|
646
|
+
export interface CircuitAlert {
|
|
647
|
+
sessionId: string;
|
|
648
|
+
wrapperId: string | null;
|
|
649
|
+
previousState: CircuitState;
|
|
650
|
+
newState: CircuitState;
|
|
651
|
+
reason: CircuitAlertReason;
|
|
652
|
+
message: string;
|
|
653
|
+
timestamp: number;
|
|
654
|
+
/** Additional context data */
|
|
655
|
+
context?: Record<string, unknown>;
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* Reasons for circuit state changes
|
|
659
|
+
*/
|
|
660
|
+
export type CircuitAlertReason = 'no_events' | 'no_progress' | 'no_progress_extended' | 'error_threshold' | 'loop_threshold' | 'max_duration' | 'recovered' | 'progress_detected' | 'manual_reset' | 'intervention_sent' | 'session_killed' | 'session_restarted';
|