@sudocode-ai/types 0.1.10 → 0.1.12

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.
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Claude to AG-UI Transformation Logic
3
+ *
4
+ * Shared transformation functions for converting raw Claude stream-json messages
5
+ * to AG-UI events. Used by both:
6
+ * - Backend: Real-time transformation for SSE streaming
7
+ * - Frontend: Historical transformation for log replay
8
+ *
9
+ * @module claude-to-ag-ui
10
+ */
11
+ /**
12
+ * Claude stream-json message format
13
+ * Based on Claude Code CLI output structure
14
+ */
15
+ export interface ClaudeStreamMessage {
16
+ type: "assistant" | "tool_result" | "result" | "error";
17
+ message?: {
18
+ id?: string;
19
+ model?: string;
20
+ role?: string;
21
+ content?: Array<{
22
+ type: "text" | "tool_use";
23
+ text?: string;
24
+ id?: string;
25
+ name?: string;
26
+ input?: any;
27
+ }>;
28
+ stop_reason?: string;
29
+ stop_sequence?: string | null;
30
+ };
31
+ result?: {
32
+ tool_use_id?: string;
33
+ content?: Array<{
34
+ type: string;
35
+ text?: string;
36
+ }>;
37
+ };
38
+ usage?: {
39
+ input_tokens?: number;
40
+ output_tokens?: number;
41
+ cache_read_input_tokens?: number;
42
+ cache_creation_input_tokens?: number;
43
+ };
44
+ error?: {
45
+ message: string;
46
+ type?: string;
47
+ };
48
+ }
49
+ /**
50
+ * AG-UI Event types
51
+ * Minimal interface needed for transformation
52
+ */
53
+ export interface AgUiEvent {
54
+ type: string;
55
+ timestamp: number;
56
+ [key: string]: any;
57
+ }
58
+ /**
59
+ * Transform a single Claude stream-json message to AG-UI events
60
+ *
61
+ * @param message - Raw Claude message from stream-json output
62
+ * @param startSequence - Starting sequence number for events
63
+ * @returns Array of AG-UI events (may be empty for unhandled message types)
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * const message = JSON.parse(line);
68
+ * const events = transformClaudeMessageToAgUi(message, 0);
69
+ * events.forEach(event => console.log(event));
70
+ * ```
71
+ */
72
+ export declare function transformClaudeMessageToAgUi(message: ClaudeStreamMessage, startSequence: number): AgUiEvent[];
73
+ /**
74
+ * Parse array of raw execution logs (NDJSON format) to AG-UI events
75
+ *
76
+ * Processes each line as a separate Claude message and transforms to AG-UI events.
77
+ * Handles parse errors gracefully by logging warnings and continuing.
78
+ *
79
+ * @param rawLogs - Array of NDJSON log lines
80
+ * @returns Promise resolving to array of AG-UI events
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * const logs = await fetch('/api/executions/123/logs').then(r => r.json());
85
+ * const events = await parseExecutionLogs(logs.logs);
86
+ * console.log(`Parsed ${events.length} events`);
87
+ * ```
88
+ */
89
+ export declare function parseExecutionLogs(rawLogs: string[]): Promise<AgUiEvent[]>;
90
+ //# sourceMappingURL=claude-to-ag-ui.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"claude-to-ag-ui.d.ts","sourceRoot":"","sources":["../src/claude-to-ag-ui.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,WAAW,GAAG,aAAa,GAAG,QAAQ,GAAG,OAAO,CAAC;IACvD,OAAO,CAAC,EAAE;QACR,EAAE,CAAC,EAAE,MAAM,CAAC;QACZ,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,OAAO,CAAC,EAAE,KAAK,CAAC;YACd,IAAI,EAAE,MAAM,GAAG,UAAU,CAAC;YAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;YACd,EAAE,CAAC,EAAE,MAAM,CAAC;YACZ,IAAI,CAAC,EAAE,MAAM,CAAC;YACd,KAAK,CAAC,EAAE,GAAG,CAAC;SACb,CAAC,CAAC;QACH,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;KAC/B,CAAC;IACF,MAAM,CAAC,EAAE;QACP,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,OAAO,CAAC,EAAE,KAAK,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,IAAI,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;KAClD,CAAC;IACF,KAAK,CAAC,EAAE;QACN,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,uBAAuB,CAAC,EAAE,MAAM,CAAC;QACjC,2BAA2B,CAAC,EAAE,MAAM,CAAC;KACtC,CAAC;IACF,KAAK,CAAC,EAAE;QACN,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,CAAC;CACH;AAED;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,mBAAmB,EAC5B,aAAa,EAAE,MAAM,GACpB,SAAS,EAAE,CAoGb;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,MAAM,EAAE,GAChB,OAAO,CAAC,SAAS,EAAE,CAAC,CAiCtB"}
@@ -0,0 +1,153 @@
1
+ /**
2
+ * Claude to AG-UI Transformation Logic
3
+ *
4
+ * Shared transformation functions for converting raw Claude stream-json messages
5
+ * to AG-UI events. Used by both:
6
+ * - Backend: Real-time transformation for SSE streaming
7
+ * - Frontend: Historical transformation for log replay
8
+ *
9
+ * @module claude-to-ag-ui
10
+ */
11
+ /**
12
+ * Transform a single Claude stream-json message to AG-UI events
13
+ *
14
+ * @param message - Raw Claude message from stream-json output
15
+ * @param startSequence - Starting sequence number for events
16
+ * @returns Array of AG-UI events (may be empty for unhandled message types)
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const message = JSON.parse(line);
21
+ * const events = transformClaudeMessageToAgUi(message, 0);
22
+ * events.forEach(event => console.log(event));
23
+ * ```
24
+ */
25
+ export function transformClaudeMessageToAgUi(message, startSequence) {
26
+ const events = [];
27
+ const timestamp = Date.now();
28
+ switch (message.type) {
29
+ case "assistant": {
30
+ // Extract content blocks from assistant message
31
+ const content = message.message?.content || [];
32
+ for (const block of content) {
33
+ if (block.type === "text" && block.text) {
34
+ // Text message → TEXT_MESSAGE_CONTENT event
35
+ events.push({
36
+ type: "CUSTOM",
37
+ timestamp,
38
+ name: "TEXT_MESSAGE_CONTENT",
39
+ value: {
40
+ content: block.text,
41
+ },
42
+ });
43
+ }
44
+ else if (block.type === "tool_use") {
45
+ // Tool use → TOOL_CALL_START + TOOL_CALL_ARGS events
46
+ const toolId = block.id || `tool-${Date.now()}`;
47
+ events.push({
48
+ type: "TOOL_CALL_START",
49
+ timestamp,
50
+ toolCallId: toolId,
51
+ toolCallName: block.name || "unknown",
52
+ }, {
53
+ type: "TOOL_CALL_ARGS",
54
+ timestamp,
55
+ toolCallId: toolId,
56
+ delta: JSON.stringify(block.input || {}),
57
+ });
58
+ }
59
+ }
60
+ break;
61
+ }
62
+ case "tool_result": {
63
+ // Tool result → TOOL_CALL_END + TOOL_CALL_RESULT events
64
+ const toolUseId = message.result?.tool_use_id || "unknown";
65
+ const resultContent = message.result?.content || [];
66
+ const resultText = resultContent.find((c) => c.type === "text")?.text || "";
67
+ events.push({
68
+ type: "TOOL_CALL_END",
69
+ timestamp,
70
+ toolCallId: toolUseId,
71
+ }, {
72
+ type: "TOOL_CALL_RESULT",
73
+ timestamp,
74
+ messageId: `msg-${toolUseId}`,
75
+ toolCallId: toolUseId,
76
+ content: resultText,
77
+ });
78
+ break;
79
+ }
80
+ case "result": {
81
+ // Result message with usage → USAGE_UPDATE event
82
+ if (message.usage) {
83
+ const usage = message.usage;
84
+ events.push({
85
+ type: "CUSTOM",
86
+ timestamp,
87
+ name: "USAGE_UPDATE",
88
+ value: {
89
+ inputTokens: usage.input_tokens || 0,
90
+ outputTokens: usage.output_tokens || 0,
91
+ cacheTokens: usage.cache_read_input_tokens || 0,
92
+ totalTokens: (usage.input_tokens || 0) + (usage.output_tokens || 0),
93
+ },
94
+ });
95
+ }
96
+ break;
97
+ }
98
+ case "error": {
99
+ // Error message → RUN_ERROR event
100
+ events.push({
101
+ type: "RUN_ERROR",
102
+ timestamp,
103
+ message: message.error?.message || "Unknown error",
104
+ errorType: message.error?.type,
105
+ });
106
+ break;
107
+ }
108
+ }
109
+ return events;
110
+ }
111
+ /**
112
+ * Parse array of raw execution logs (NDJSON format) to AG-UI events
113
+ *
114
+ * Processes each line as a separate Claude message and transforms to AG-UI events.
115
+ * Handles parse errors gracefully by logging warnings and continuing.
116
+ *
117
+ * @param rawLogs - Array of NDJSON log lines
118
+ * @returns Promise resolving to array of AG-UI events
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * const logs = await fetch('/api/executions/123/logs').then(r => r.json());
123
+ * const events = await parseExecutionLogs(logs.logs);
124
+ * console.log(`Parsed ${events.length} events`);
125
+ * ```
126
+ */
127
+ export async function parseExecutionLogs(rawLogs) {
128
+ const events = [];
129
+ let sequence = 0;
130
+ for (let i = 0; i < rawLogs.length; i++) {
131
+ const line = rawLogs[i].trim();
132
+ // Skip empty lines
133
+ if (!line) {
134
+ continue;
135
+ }
136
+ try {
137
+ // Parse JSON line
138
+ const message = JSON.parse(line);
139
+ // Transform to AG-UI events
140
+ const agUiEvents = transformClaudeMessageToAgUi(message, sequence);
141
+ // Accumulate events
142
+ events.push(...agUiEvents);
143
+ sequence += agUiEvents.length;
144
+ }
145
+ catch (error) {
146
+ // Log warning but continue processing
147
+ console.warn(`[parseExecutionLogs] Failed to parse log line ${i + 1}:`, error instanceof Error ? error.message : String(error));
148
+ // Don't throw - continue with remaining logs
149
+ }
150
+ }
151
+ return events;
152
+ }
153
+ //# sourceMappingURL=claude-to-ag-ui.js.map
@@ -0,0 +1 @@
1
+ {"version":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AAK,CAAC,CACvD,CAAC;YACF,6CAA6C;QAC/C,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
package/dist/crdt.d.ts ADDED
@@ -0,0 +1,117 @@
1
+ /**
2
+ * CRDT Type Definitions
3
+ *
4
+ * Shared type definitions for CRDT state synchronization between
5
+ * the coordinator and agents.
6
+ */
7
+ import { IssueStatus } from './index.js';
8
+ /**
9
+ * Issue state in CRDT
10
+ */
11
+ export interface IssueState {
12
+ id: string;
13
+ title: string;
14
+ content: string;
15
+ status: IssueStatus;
16
+ priority: number;
17
+ parent?: string;
18
+ archived: boolean;
19
+ createdAt: number;
20
+ updatedAt: number;
21
+ lastModifiedBy: string;
22
+ version: number;
23
+ tempStatus?: string;
24
+ tempProgress?: {
25
+ current: number;
26
+ total: number;
27
+ message?: string;
28
+ };
29
+ }
30
+ /**
31
+ * Spec state in CRDT
32
+ */
33
+ export interface SpecState {
34
+ id: string;
35
+ title: string;
36
+ content: string;
37
+ priority: number;
38
+ parent?: string;
39
+ createdAt: number;
40
+ updatedAt: number;
41
+ lastModifiedBy: string;
42
+ version: number;
43
+ tempSections?: Record<string, string>;
44
+ tempDiff?: string;
45
+ }
46
+ /**
47
+ * Execution state in CRDT
48
+ */
49
+ export interface ExecutionState {
50
+ id: string;
51
+ issueId?: string;
52
+ specId?: string;
53
+ status: 'preparing' | 'running' | 'paused' | 'completed' | 'failed' | 'cancelled';
54
+ phase?: string;
55
+ progress?: {
56
+ current: number;
57
+ total: number;
58
+ message?: string;
59
+ };
60
+ startedAt: number;
61
+ updatedAt: number;
62
+ completedAt?: number;
63
+ agentId: string;
64
+ }
65
+ /**
66
+ * Agent metadata in CRDT
67
+ */
68
+ export interface AgentMetadata {
69
+ id: string;
70
+ executionId?: string;
71
+ status: 'initializing' | 'idle' | 'working' | 'disconnected';
72
+ lastHeartbeat: number;
73
+ connectedAt: number;
74
+ disconnectedAt?: number;
75
+ worktreePath?: string;
76
+ }
77
+ /**
78
+ * Feedback state in CRDT
79
+ */
80
+ export interface FeedbackState {
81
+ id: string;
82
+ specId: string;
83
+ issueId: string;
84
+ type: 'comment' | 'suggestion' | 'request';
85
+ content: string;
86
+ anchorLine?: number;
87
+ anchorText?: string;
88
+ createdAt: number;
89
+ updatedAt: number;
90
+ lastModifiedBy: string;
91
+ }
92
+ /**
93
+ * CRDT Agent configuration
94
+ */
95
+ export interface CRDTAgentConfig {
96
+ agentId: string;
97
+ coordinatorUrl?: string;
98
+ coordinatorHost?: string;
99
+ coordinatorPort?: number;
100
+ heartbeatInterval?: number;
101
+ maxReconnectAttempts?: number;
102
+ reconnectBaseDelay?: number;
103
+ reconnectMaxDelay?: number;
104
+ connectionTimeout?: number;
105
+ }
106
+ /**
107
+ * CRDT Coordinator configuration
108
+ */
109
+ export interface CRDTCoordinatorConfig {
110
+ port?: number;
111
+ host?: string;
112
+ persistInterval?: number;
113
+ gcInterval?: number;
114
+ executionTTL?: number;
115
+ agentTTL?: number;
116
+ }
117
+ //# sourceMappingURL=crdt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crdt.d.ts","sourceRoot":"","sources":["../src/crdt.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAEhB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE;Q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type definitions for CRDT state synchronization between
5
+ * the coordinator and agents.
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=crdt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crdt.js","sourceRoot":"","sources":["../src/crdt.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * CRDT History Type Definitions
3
+ *
4
+ * Types for in-memory CRDT update history tracking.
5
+ */
6
+ /**
7
+ * Record of a single CRDT update with metadata
8
+ */
9
+ export interface CRDTUpdateRecord {
10
+ id: string;
11
+ entityType: 'issue' | 'spec' | 'feedback';
12
+ entityId: string;
13
+ updateData: Uint8Array;
14
+ clientId: string;
15
+ timestamp: number;
16
+ contentSnapshot?: {
17
+ title: string;
18
+ content: string;
19
+ [key: string]: any;
20
+ };
21
+ }
22
+ /**
23
+ * In-memory history storage structure
24
+ */
25
+ export interface UpdateHistory {
26
+ updates: CRDTUpdateRecord[];
27
+ entityIndex: Map<string, number[]>;
28
+ clientIndex: Map<string, number[]>;
29
+ oldestTimestamp: number;
30
+ newestTimestamp: number;
31
+ }
32
+ /**
33
+ * Metadata about the history state
34
+ */
35
+ export interface HistoryMetadata {
36
+ oldestTimestamp: number;
37
+ newestTimestamp: number;
38
+ totalUpdates: number;
39
+ retentionWindowMs: number;
40
+ entitiesTracked: number;
41
+ memoryUsageMB: number;
42
+ }
43
+ /**
44
+ * Document version at a specific timestamp
45
+ */
46
+ export interface VersionInfo {
47
+ timestamp: number;
48
+ title: string;
49
+ content: string;
50
+ lastModifiedBy: string;
51
+ [key: string]: any;
52
+ }
53
+ /**
54
+ * Diff chunk between two versions
55
+ */
56
+ export interface DiffChunk {
57
+ type: 'added' | 'removed' | 'unchanged';
58
+ value: string;
59
+ count: number;
60
+ }
61
+ /**
62
+ * Line-by-line blame/attribution information
63
+ */
64
+ export interface BlameInfo {
65
+ lines: Array<{
66
+ lineNumber: number;
67
+ author: string;
68
+ timestamp: number;
69
+ line: string;
70
+ }>;
71
+ }
72
+ //# sourceMappingURL=history.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../src/history.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,OAAO,GAAG,MAAM,GAAG,UAAU,CAAC;IAC1C,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,UAAU,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE;QAChB,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,EAAE,MAAM,CAAC;QAChB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,gBAAgB,EAAE,CAAC;IAC5B,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IACnC,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IACnC,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;IACvB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,OAAO,GAAG,SAAS,GAAG,WAAW,CAAC;IACxC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,KAAK,CAAC;QACX,UAAU,EAAE,MAAM,CAAC;QACnB,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,EAAE,MAAM,CAAC;QAClB,IAAI,EAAE,MAAM,CAAC;KACd,CAAC,CAAC;CACJ"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * CRDT History Type Definitions
3
+ *
4
+ * Types for in-memory CRDT update history tracking.
5
+ */
6
+ export {};
7
+ //# sourceMappingURL=history.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"history.js","sourceRoot":"","sources":["../src/history.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
package/dist/schema.d.ts CHANGED
@@ -19,6 +19,8 @@ export declare const ISSUE_FEEDBACK_TABLE = "\nCREATE TABLE IF NOT EXISTS issue_
19
19
  export declare const EXECUTIONS_TABLE = "\nCREATE TABLE IF NOT EXISTS executions (\n id TEXT PRIMARY KEY,\n issue_id TEXT,\n issue_uuid TEXT,\n\n -- Execution mode and configuration\n mode TEXT CHECK(mode IN ('worktree', 'local')),\n prompt TEXT,\n config TEXT,\n\n -- Process information (legacy + new)\n agent_type TEXT,\n session_id TEXT,\n workflow_execution_id TEXT,\n\n -- Git/branch information\n target_branch TEXT NOT NULL,\n branch_name TEXT NOT NULL,\n before_commit TEXT,\n after_commit TEXT,\n worktree_path TEXT,\n\n -- Status (unified - supports both old and new statuses)\n status TEXT NOT NULL CHECK(status IN (\n 'preparing', 'pending', 'running', 'paused',\n 'completed', 'failed', 'cancelled', 'stopped'\n )),\n\n -- Timing (consistent with other tables)\n created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,\n updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,\n started_at DATETIME,\n completed_at DATETIME,\n cancelled_at DATETIME,\n\n -- Results and metadata\n exit_code INTEGER,\n error_message TEXT,\n error TEXT,\n model TEXT,\n summary TEXT,\n files_changed TEXT,\n\n -- Relationships\n parent_execution_id TEXT,\n\n -- Multi-step workflow support (future extension)\n step_type TEXT,\n step_index INTEGER,\n step_config TEXT,\n\n FOREIGN KEY (issue_id) REFERENCES issues(id) ON DELETE SET NULL,\n FOREIGN KEY (issue_uuid) REFERENCES issues(uuid) ON DELETE SET NULL,\n FOREIGN KEY (parent_execution_id) REFERENCES executions(id) ON DELETE SET NULL\n);\n";
20
20
  export declare const PROMPT_TEMPLATES_TABLE = "\nCREATE TABLE IF NOT EXISTS prompt_templates (\n id TEXT PRIMARY KEY,\n name TEXT NOT NULL,\n description TEXT,\n type TEXT NOT NULL CHECK(type IN ('issue', 'spec', 'custom')),\n template TEXT NOT NULL,\n variables TEXT NOT NULL,\n is_default INTEGER NOT NULL DEFAULT 0 CHECK(is_default IN (0, 1)),\n created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,\n updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP\n);\n";
21
21
  export declare const EXECUTION_LOGS_TABLE = "\nCREATE TABLE IF NOT EXISTS execution_logs (\n execution_id TEXT PRIMARY KEY,\n raw_logs TEXT,\n normalized_entry TEXT,\n byte_size INTEGER NOT NULL DEFAULT 0,\n line_count INTEGER NOT NULL DEFAULT 0,\n created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,\n updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,\n FOREIGN KEY (execution_id) REFERENCES executions(id) ON DELETE CASCADE,\n CHECK (raw_logs IS NOT NULL OR normalized_entry IS NOT NULL)\n);\n";
22
+ export declare const WORKFLOWS_TABLE = "\nCREATE TABLE IF NOT EXISTS workflows (\n id TEXT PRIMARY KEY,\n title TEXT NOT NULL,\n source TEXT NOT NULL, -- JSON (WorkflowSource: spec, issues, root_issue, or goal)\n status TEXT NOT NULL DEFAULT 'pending' CHECK(status IN (\n 'pending', 'running', 'paused',\n 'completed', 'failed', 'cancelled'\n )),\n steps TEXT NOT NULL DEFAULT '[]', -- JSON array (WorkflowStep[])\n worktree_path TEXT,\n branch_name TEXT,\n base_branch TEXT NOT NULL,\n current_step_index INTEGER NOT NULL DEFAULT 0,\n orchestrator_execution_id TEXT,\n orchestrator_session_id TEXT,\n config TEXT NOT NULL, -- JSON (WorkflowConfig)\n created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,\n updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,\n started_at DATETIME,\n completed_at DATETIME,\n FOREIGN KEY (orchestrator_execution_id) REFERENCES executions(id) ON DELETE SET NULL\n);\n";
23
+ export declare const WORKFLOW_EVENTS_TABLE = "\nCREATE TABLE IF NOT EXISTS workflow_events (\n id TEXT PRIMARY KEY,\n workflow_id TEXT NOT NULL,\n type TEXT NOT NULL, -- WorkflowEventType (step_completed, workflow_paused, etc.)\n step_id TEXT,\n execution_id TEXT,\n payload TEXT NOT NULL DEFAULT '{}', -- JSON (event-specific data)\n created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,\n processed_at DATETIME, -- When orchestrator processed this event\n FOREIGN KEY (workflow_id) REFERENCES workflows(id) ON DELETE CASCADE,\n FOREIGN KEY (execution_id) REFERENCES executions(id) ON DELETE SET NULL\n);\n";
22
24
  /**
23
25
  * Index definitions
24
26
  */
@@ -31,6 +33,8 @@ export declare const ISSUE_FEEDBACK_INDEXES = "\nCREATE INDEX IF NOT EXISTS idx_
31
33
  export declare const EXECUTIONS_INDEXES = "\nCREATE INDEX IF NOT EXISTS idx_executions_issue_id ON executions(issue_id);\nCREATE INDEX IF NOT EXISTS idx_executions_issue_uuid ON executions(issue_uuid);\nCREATE INDEX IF NOT EXISTS idx_executions_status ON executions(status);\nCREATE INDEX IF NOT EXISTS idx_executions_session_id ON executions(session_id);\nCREATE INDEX IF NOT EXISTS idx_executions_parent ON executions(parent_execution_id);\nCREATE INDEX IF NOT EXISTS idx_executions_created_at ON executions(created_at);\nCREATE INDEX IF NOT EXISTS idx_executions_workflow ON executions(workflow_execution_id);\nCREATE INDEX IF NOT EXISTS idx_executions_workflow_step ON executions(workflow_execution_id, step_index);\nCREATE INDEX IF NOT EXISTS idx_executions_step_type ON executions(step_type);\n";
32
34
  export declare const PROMPT_TEMPLATES_INDEXES = "\nCREATE INDEX IF NOT EXISTS idx_templates_type ON prompt_templates(type);\nCREATE INDEX IF NOT EXISTS idx_templates_default ON prompt_templates(is_default);\n";
33
35
  export declare const EXECUTION_LOGS_INDEXES = "\nCREATE INDEX IF NOT EXISTS idx_execution_logs_updated_at ON execution_logs(updated_at);\nCREATE INDEX IF NOT EXISTS idx_execution_logs_byte_size ON execution_logs(byte_size);\nCREATE INDEX IF NOT EXISTS idx_execution_logs_line_count ON execution_logs(line_count);\n";
36
+ export declare const WORKFLOWS_INDEXES = "\nCREATE INDEX IF NOT EXISTS idx_workflows_status ON workflows(status);\nCREATE INDEX IF NOT EXISTS idx_workflows_orchestrator ON workflows(orchestrator_execution_id);\nCREATE INDEX IF NOT EXISTS idx_workflows_created_at ON workflows(created_at);\nCREATE INDEX IF NOT EXISTS idx_workflows_updated_at ON workflows(updated_at);\nCREATE INDEX IF NOT EXISTS idx_workflows_base_branch ON workflows(base_branch);\n";
37
+ export declare const WORKFLOW_EVENTS_INDEXES = "\nCREATE INDEX IF NOT EXISTS idx_workflow_events_workflow_id ON workflow_events(workflow_id);\nCREATE INDEX IF NOT EXISTS idx_workflow_events_type ON workflow_events(type);\nCREATE INDEX IF NOT EXISTS idx_workflow_events_execution_id ON workflow_events(execution_id);\nCREATE INDEX IF NOT EXISTS idx_workflow_events_processed ON workflow_events(processed_at);\nCREATE INDEX IF NOT EXISTS idx_workflow_events_created_at ON workflow_events(created_at);\nCREATE INDEX IF NOT EXISTS idx_workflow_events_unprocessed ON workflow_events(workflow_id, processed_at) WHERE processed_at IS NULL;\n";
34
38
  /**
35
39
  * View definitions
36
40
  */
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,eAAO,MAAM,cAAc,QAAQ,CAAC;AAEpC;;GAEG;AACH,eAAO,MAAM,SAAS,uSAarB,CAAC;AAEF;;GAEG;AAEH,eAAO,MAAM,WAAW,ysBAiBvB,CAAC;AAEF,eAAO,MAAM,YAAY,qwBAmBxB,CAAC;AAEF,eAAO,MAAM,mBAAmB,iaAa/B,CAAC;AAEF,eAAO,MAAM,UAAU,mNAQtB,CAAC;AAEF,eAAO,MAAM,YAAY,uZAexB,CAAC;AAEF,eAAO,MAAM,oBAAoB,2qBAiBhC,CAAC;AAEF,eAAO,MAAM,gBAAgB,0jDAwD5B,CAAC;AAGF,eAAO,MAAM,sBAAsB,ocAYlC,CAAC;AAOF,eAAO,MAAM,oBAAoB,4eAYhC,CAAC;AAEF;;GAEG;AAEH,eAAO,MAAM,aAAa,oeAQzB,CAAC;AAEF,eAAO,MAAM,cAAc,+rBAW1B,CAAC;AAEF,eAAO,MAAM,qBAAqB,seAOjC,CAAC;AAEF,eAAO,MAAM,YAAY,kOAIxB,CAAC;AAEF,eAAO,MAAM,cAAc,2cAO1B,CAAC;AAEF,eAAO,MAAM,sBAAsB,+iBAQlC,CAAC;AAEF,eAAO,MAAM,kBAAkB,0vBAU9B,CAAC;AAEF,eAAO,MAAM,wBAAwB,oKAGpC,CAAC;AAEF,eAAO,MAAM,sBAAsB,gRAIlC,CAAC;AAEF;;GAEG;AAEH,eAAO,MAAM,iBAAiB,gqBAkB7B,CAAC;AAEF,eAAO,MAAM,mBAAmB,ovBAmB/B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,UAAU,UAUtB,CAAC;AAEF,eAAO,MAAM,WAAW,UAUvB,CAAC;AAEF,eAAO,MAAM,SAAS,UAA2C,CAAC"}
1
+ {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AAEF,eAAO,MAAM,WAAW,UAYvB,CAAC;AAEF,eAAO,MAAM,SAAS,UAA2C,CAAC"}
package/dist/schema.js CHANGED
@@ -207,6 +207,47 @@ CREATE TABLE IF NOT EXISTS execution_logs (
207
207
  CHECK (raw_logs IS NOT NULL OR normalized_entry IS NOT NULL)
208
208
  );
209
209
  `;
210
+ // Workflows table - orchestrates multi-issue execution
211
+ // Supports both sequential and agent-managed workflow strategies
212
+ export const WORKFLOWS_TABLE = `
213
+ CREATE TABLE IF NOT EXISTS workflows (
214
+ id TEXT PRIMARY KEY,
215
+ title TEXT NOT NULL,
216
+ source TEXT NOT NULL, -- JSON (WorkflowSource: spec, issues, root_issue, or goal)
217
+ status TEXT NOT NULL DEFAULT 'pending' CHECK(status IN (
218
+ 'pending', 'running', 'paused',
219
+ 'completed', 'failed', 'cancelled'
220
+ )),
221
+ steps TEXT NOT NULL DEFAULT '[]', -- JSON array (WorkflowStep[])
222
+ worktree_path TEXT,
223
+ branch_name TEXT,
224
+ base_branch TEXT NOT NULL,
225
+ current_step_index INTEGER NOT NULL DEFAULT 0,
226
+ orchestrator_execution_id TEXT,
227
+ orchestrator_session_id TEXT,
228
+ config TEXT NOT NULL, -- JSON (WorkflowConfig)
229
+ created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
230
+ updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
231
+ started_at DATETIME,
232
+ completed_at DATETIME,
233
+ FOREIGN KEY (orchestrator_execution_id) REFERENCES executions(id) ON DELETE SET NULL
234
+ );
235
+ `;
236
+ // Workflow events table - tracks workflow lifecycle events for orchestrator wakeups
237
+ export const WORKFLOW_EVENTS_TABLE = `
238
+ CREATE TABLE IF NOT EXISTS workflow_events (
239
+ id TEXT PRIMARY KEY,
240
+ workflow_id TEXT NOT NULL,
241
+ type TEXT NOT NULL, -- WorkflowEventType (step_completed, workflow_paused, etc.)
242
+ step_id TEXT,
243
+ execution_id TEXT,
244
+ payload TEXT NOT NULL DEFAULT '{}', -- JSON (event-specific data)
245
+ created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
246
+ processed_at DATETIME, -- When orchestrator processed this event
247
+ FOREIGN KEY (workflow_id) REFERENCES workflows(id) ON DELETE CASCADE,
248
+ FOREIGN KEY (execution_id) REFERENCES executions(id) ON DELETE SET NULL
249
+ );
250
+ `;
210
251
  /**
211
252
  * Index definitions
212
253
  */
@@ -281,6 +322,21 @@ CREATE INDEX IF NOT EXISTS idx_execution_logs_updated_at ON execution_logs(updat
281
322
  CREATE INDEX IF NOT EXISTS idx_execution_logs_byte_size ON execution_logs(byte_size);
282
323
  CREATE INDEX IF NOT EXISTS idx_execution_logs_line_count ON execution_logs(line_count);
283
324
  `;
325
+ export const WORKFLOWS_INDEXES = `
326
+ CREATE INDEX IF NOT EXISTS idx_workflows_status ON workflows(status);
327
+ CREATE INDEX IF NOT EXISTS idx_workflows_orchestrator ON workflows(orchestrator_execution_id);
328
+ CREATE INDEX IF NOT EXISTS idx_workflows_created_at ON workflows(created_at);
329
+ CREATE INDEX IF NOT EXISTS idx_workflows_updated_at ON workflows(updated_at);
330
+ CREATE INDEX IF NOT EXISTS idx_workflows_base_branch ON workflows(base_branch);
331
+ `;
332
+ export const WORKFLOW_EVENTS_INDEXES = `
333
+ CREATE INDEX IF NOT EXISTS idx_workflow_events_workflow_id ON workflow_events(workflow_id);
334
+ CREATE INDEX IF NOT EXISTS idx_workflow_events_type ON workflow_events(type);
335
+ CREATE INDEX IF NOT EXISTS idx_workflow_events_execution_id ON workflow_events(execution_id);
336
+ CREATE INDEX IF NOT EXISTS idx_workflow_events_processed ON workflow_events(processed_at);
337
+ CREATE INDEX IF NOT EXISTS idx_workflow_events_created_at ON workflow_events(created_at);
338
+ CREATE INDEX IF NOT EXISTS idx_workflow_events_unprocessed ON workflow_events(workflow_id, processed_at) WHERE processed_at IS NULL;
339
+ `;
284
340
  /**
285
341
  * View definitions
286
342
  */
@@ -336,6 +392,8 @@ export const ALL_TABLES = [
336
392
  EXECUTIONS_TABLE,
337
393
  PROMPT_TEMPLATES_TABLE,
338
394
  EXECUTION_LOGS_TABLE,
395
+ WORKFLOWS_TABLE,
396
+ WORKFLOW_EVENTS_TABLE,
339
397
  ];
340
398
  export const ALL_INDEXES = [
341
399
  SPECS_INDEXES,
@@ -347,6 +405,8 @@ export const ALL_INDEXES = [
347
405
  EXECUTIONS_INDEXES,
348
406
  PROMPT_TEMPLATES_INDEXES,
349
407
  EXECUTION_LOGS_INDEXES,
408
+ WORKFLOWS_INDEXES,
409
+ WORKFLOW_EVENTS_INDEXES,
350
410
  ];
351
411
  export const ALL_VIEWS = [READY_ISSUES_VIEW, BLOCKED_ISSUES_VIEW];
352
412
  //# sourceMappingURL=schema.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,CAAC;AAEpC;;GAEG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG;;;;;;;;;;;;;CAaxB,CAAC;AAEF;;GAEG;AAEH,MAAM,CAAC,MAAM,WAAW,GAAG;;;;;;;;;;;;;;;;;CAiB1B,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG;;;;;;;;;;;;;;;;;;;CAmB3B,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG;;;;;;;;;;;;;CAalC,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG;;;;;;;;CAQzB,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG;;;;;;;;;;;;;;;CAe3B,CAAC;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAG;;;;;;;;;;;;;;;;;CAiBnC,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwD/B,CAAC;AAEF,yBA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,MAAM,SAAS,GAAG,CAAC,iBAAiB,EAAE,mBAAmB,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sudocode-ai/types",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
4
4
  "description": "TypeScript type definitions for sudocode",
5
5
  "types": "src/index.d.ts",
6
6
  "type": "module",
@@ -17,6 +17,10 @@
17
17
  "types": "./src/agents.d.ts",
18
18
  "default": "./src/agents.d.ts"
19
19
  },
20
+ "./workflows": {
21
+ "types": "./src/workflows.d.ts",
22
+ "default": "./src/workflows.d.ts"
23
+ },
20
24
  "./schema": {
21
25
  "types": "./dist/schema.d.ts",
22
26
  "default": "./dist/schema.js"
@@ -54,6 +58,8 @@
54
58
  "src/index.d.ts",
55
59
  "src/events.d.ts",
56
60
  "src/agents.d.ts",
61
+ "src/artifacts.d.ts",
62
+ "src/workflows.d.ts",
57
63
  "dist"
58
64
  ],
59
65
  "devDependencies": {
package/src/agents.d.ts CHANGED
@@ -135,6 +135,27 @@ export interface ClaudeCodeConfig extends BaseAgentConfig {
135
135
  };
136
136
  /** Prompt to send to Claude Code */
137
137
  prompt?: string;
138
+
139
+ // === Directory Restriction ===
140
+ /**
141
+ * Restrict file operations to the working directory
142
+ *
143
+ * When enabled, a PreToolUse hook is configured to block Read, Write, Edit,
144
+ * Glob, and Grep operations that target files outside the working directory.
145
+ *
146
+ * This provides security isolation when running agents in worktrees or
147
+ * sandboxed environments.
148
+ *
149
+ * @default false
150
+ */
151
+ restrictToWorkDir?: boolean;
152
+ /**
153
+ * Path to the directory guard hook script
154
+ *
155
+ * Only used when restrictToWorkDir is enabled. If not specified,
156
+ * the executor will use the bundled hook script from agent-execution-engine.
157
+ */
158
+ directoryGuardHookPath?: string;
138
159
  }
139
160
 
140
161
  /**
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Execution artifacts types
3
+ *
4
+ * Types for artifacts created during executions (code changes, outputs, etc.)
5
+ */
6
+
7
+ /**
8
+ * File change statistics for execution diff
9
+ */
10
+ export interface FileChangeStat {
11
+ path: string;
12
+ additions: number;
13
+ deletions: number;
14
+ status: 'A' | 'M' | 'D' | 'R'; // Added, Modified, Deleted, Renamed
15
+ }
16
+
17
+ /**
18
+ * Changes snapshot at a specific point in time
19
+ */
20
+ export interface ChangesSnapshot {
21
+ files: FileChangeStat[];
22
+ summary: {
23
+ totalFiles: number;
24
+ totalAdditions: number;
25
+ totalDeletions: number;
26
+ };
27
+ commitRange: {
28
+ before: string;
29
+ after: string;
30
+ } | null;
31
+ uncommitted: boolean;
32
+ }
33
+
34
+ /**
35
+ * Result of execution changes calculation
36
+ */
37
+ export interface ExecutionChangesResult {
38
+ available: boolean;
39
+ reason?: 'missing_commits' | 'commits_not_found' | 'incomplete_execution' | 'git_error' | 'worktree_deleted_with_uncommitted_changes' | 'branch_deleted';
40
+
41
+ // Captured state: changes at execution completion time
42
+ captured?: ChangesSnapshot;
43
+
44
+ // Uncommitted changes at execution completion time (if any)
45
+ // This allows displaying both committed and uncommitted changes separately
46
+ uncommittedSnapshot?: ChangesSnapshot;
47
+
48
+ // Current state: changes at current branch HEAD (if different from captured)
49
+ current?: ChangesSnapshot;
50
+
51
+ // Branch and worktree metadata
52
+ branchName?: string; // Branch associated with execution
53
+ branchExists?: boolean; // Whether branch still exists
54
+ worktreeExists?: boolean; // Whether worktree still exists
55
+ additionalCommits?: number; // Number of commits since execution completed (current - captured)
56
+ commitsAhead?: number; // Number of commits the branch is ahead of target branch (for merge action visibility)
57
+ executionMode?: 'worktree' | 'local' | null; // Execution mode - helps distinguish between local and worktree executions
58
+
59
+ // Legacy compatibility (deprecated - use captured instead)
60
+ changes?: ChangesSnapshot;
61
+ commitRange?: {
62
+ before: string;
63
+ after: string;
64
+ } | null;
65
+ uncommitted?: boolean;
66
+ }
package/src/index.d.ts CHANGED
@@ -291,3 +291,40 @@ export type {
291
291
  ExecutionChangesResult,
292
292
  ChangesSnapshot,
293
293
  } from './artifacts.js';
294
+
295
+ /**
296
+ * Workflow types for multi-issue orchestration
297
+ * See workflows.d.ts for detailed workflow types
298
+ */
299
+ export type {
300
+ // Status types
301
+ WorkflowStatus,
302
+ WorkflowStepStatus,
303
+ // Source types
304
+ WorkflowSource,
305
+ WorkflowSourceSpec,
306
+ WorkflowSourceIssues,
307
+ WorkflowSourceRootIssue,
308
+ WorkflowSourceGoal,
309
+ // Escalation types (Human-in-the-Loop)
310
+ EscalationStatus,
311
+ EscalationResponse,
312
+ EscalationData,
313
+ // Configuration types
314
+ WorkflowParallelism,
315
+ WorkflowFailureStrategy,
316
+ WorkflowAutonomyLevel,
317
+ WorkflowConfig,
318
+ // Core entity types
319
+ WorkflowStep,
320
+ Workflow,
321
+ // Event types
322
+ WorkflowEventType,
323
+ WorkflowEvent,
324
+ // Database row types
325
+ WorkflowRow,
326
+ WorkflowEventRow,
327
+ // Utility types
328
+ CreateWorkflowOptions,
329
+ DependencyGraph,
330
+ } from "./workflows.js";
@@ -0,0 +1,501 @@
1
+ /**
2
+ * Workflow types for sudocode
3
+ * Enables multi-issue automation with dependency-based orchestration
4
+ */
5
+
6
+ import type { AgentType } from "./agents.js";
7
+
8
+ // =============================================================================
9
+ // Status Types
10
+ // =============================================================================
11
+
12
+ /**
13
+ * Workflow lifecycle status
14
+ */
15
+ export type WorkflowStatus =
16
+ | "pending" // Created, not yet started
17
+ | "running" // Actively executing steps (includes planning phase)
18
+ | "paused" // Paused by user or orchestrator
19
+ | "completed" // All steps finished successfully
20
+ | "failed" // Workflow failed (unrecoverable)
21
+ | "cancelled"; // User cancelled
22
+
23
+ /**
24
+ * Individual workflow step status
25
+ */
26
+ export type WorkflowStepStatus =
27
+ | "pending" // Not yet ready (dependencies not met)
28
+ | "ready" // Dependencies met, can be executed
29
+ | "running" // Currently executing
30
+ | "completed" // Finished successfully
31
+ | "failed" // Execution failed
32
+ | "skipped" // Skipped by orchestrator
33
+ | "blocked"; // Blocked by failed dependency
34
+
35
+ // =============================================================================
36
+ // Source Types
37
+ // =============================================================================
38
+
39
+ /**
40
+ * Defines how a workflow's scope is determined
41
+ */
42
+ export type WorkflowSource =
43
+ | WorkflowSourceSpec
44
+ | WorkflowSourceIssues
45
+ | WorkflowSourceRootIssue
46
+ | WorkflowSourceGoal;
47
+
48
+ /**
49
+ * Workflow from issues implementing a spec
50
+ */
51
+ export interface WorkflowSourceSpec {
52
+ type: "spec";
53
+ specId: string;
54
+ }
55
+
56
+ /**
57
+ * Workflow from explicit list of issues
58
+ */
59
+ export interface WorkflowSourceIssues {
60
+ type: "issues";
61
+ issueIds: string[];
62
+ }
63
+
64
+ /**
65
+ * Workflow from a root issue and all its blockers
66
+ */
67
+ export interface WorkflowSourceRootIssue {
68
+ type: "root_issue";
69
+ issueId: string;
70
+ }
71
+
72
+ /**
73
+ * Goal-based workflow where orchestrator creates issues dynamically
74
+ */
75
+ export interface WorkflowSourceGoal {
76
+ type: "goal";
77
+ goal: string;
78
+ }
79
+
80
+ // =============================================================================
81
+ // Escalation Types (Human-in-the-Loop)
82
+ // =============================================================================
83
+
84
+ /**
85
+ * Escalation status for human-in-the-loop workflows
86
+ */
87
+ export type EscalationStatus = "pending" | "resolved" | "bypassed";
88
+
89
+ /**
90
+ * User response to an escalation request
91
+ */
92
+ export interface EscalationResponse {
93
+ /** User's action choice */
94
+ action: "approve" | "reject" | "custom";
95
+ /** Optional message from user */
96
+ message?: string;
97
+ /** When the user responded */
98
+ respondedAt: string;
99
+ }
100
+
101
+ /**
102
+ * Escalation data structure for pending or resolved escalations
103
+ */
104
+ export interface EscalationData {
105
+ /** Unique escalation request identifier */
106
+ requestId: string;
107
+ /** Message displayed to user */
108
+ message: string;
109
+ /** Optional predefined options for user to choose */
110
+ options?: string[];
111
+ /** Additional context for the escalation */
112
+ context?: Record<string, unknown>;
113
+ /** User's response (present when resolved) */
114
+ response?: EscalationResponse;
115
+ }
116
+
117
+ // =============================================================================
118
+ // Configuration Types
119
+ // =============================================================================
120
+
121
+ /**
122
+ * Workflow engine type
123
+ * - sequential: Steps are executed in order by the server, no agent orchestration
124
+ * - orchestrator: An AI agent orchestrates the workflow, making decisions dynamically
125
+ */
126
+ export type WorkflowEngineType = "sequential" | "orchestrator";
127
+
128
+ /**
129
+ * Workflow parallelism mode
130
+ */
131
+ export type WorkflowParallelism = "sequential" | "parallel";
132
+
133
+ /**
134
+ * Failure handling strategy
135
+ */
136
+ export type WorkflowFailureStrategy =
137
+ | "stop" // Stop workflow immediately
138
+ | "pause" // Pause for user intervention
139
+ | "skip_dependents" // Skip this step and all dependents
140
+ | "continue"; // Continue with other independent steps
141
+
142
+ /**
143
+ * Autonomy level for orchestrator-managed workflows
144
+ */
145
+ export type WorkflowAutonomyLevel = "full_auto" | "human_in_the_loop";
146
+
147
+ /**
148
+ * Workflow configuration options
149
+ */
150
+ export interface WorkflowConfig {
151
+ // === Engine Selection ===
152
+
153
+ /**
154
+ * Which engine to use for workflow execution
155
+ * - sequential: Server-managed step execution (default)
156
+ * - orchestrator: AI agent orchestrates the workflow
157
+ * @default "sequential"
158
+ */
159
+ engineType: WorkflowEngineType;
160
+
161
+ // === Sequential Engine Options ===
162
+
163
+ /**
164
+ * Execution mode: sequential or parallel
165
+ * @default "sequential"
166
+ */
167
+ parallelism: WorkflowParallelism;
168
+
169
+ /**
170
+ * Maximum concurrent executions (when parallelism is "parallel")
171
+ */
172
+ maxConcurrency?: number;
173
+
174
+ /**
175
+ * How to handle step failures
176
+ * @default "pause"
177
+ */
178
+ onFailure: WorkflowFailureStrategy;
179
+
180
+ /**
181
+ * Auto-commit changes after each successful step
182
+ * @default true
183
+ */
184
+ autoCommitAfterStep: boolean;
185
+
186
+ /**
187
+ * Default agent type for step executions
188
+ * @default "claude-code"
189
+ */
190
+ defaultAgentType: AgentType;
191
+
192
+ // === Orchestrator Engine Options ===
193
+
194
+ /**
195
+ * Agent type for the orchestrator (agent-managed mode)
196
+ */
197
+ orchestratorAgentType?: AgentType;
198
+
199
+ /**
200
+ * Model for the orchestrator agent
201
+ */
202
+ orchestratorModel?: string;
203
+
204
+ /**
205
+ * Autonomy level for orchestrator decisions
206
+ * - full_auto: No user intervention, escalate_to_user bypassed
207
+ * - human_in_the_loop: Pause on escalations for user input
208
+ * @default "human_in_the_loop"
209
+ */
210
+ autonomyLevel: WorkflowAutonomyLevel;
211
+
212
+ // === Timeout Options ===
213
+
214
+ /**
215
+ * Timeout for individual executions (ms)
216
+ * Orchestrator will cancel stuck executions after this time
217
+ */
218
+ executionTimeoutMs?: number;
219
+
220
+ /**
221
+ * Idle timeout (ms) - wake orchestrator if nothing happens
222
+ */
223
+ idleTimeoutMs?: number;
224
+
225
+ /**
226
+ * Batch window for wakeup events (ms)
227
+ * Multiple events within this window are batched into one wakeup
228
+ */
229
+ wakeupBatchWindowMs?: number;
230
+
231
+ // === Worktree Options ===
232
+
233
+ /**
234
+ * Base branch for worktree creation
235
+ * Defaults to current working branch if not specified
236
+ */
237
+ baseBranch?: string;
238
+
239
+ /**
240
+ * Whether to create baseBranch if it doesn't exist
241
+ * @default false
242
+ */
243
+ createBaseBranch?: boolean;
244
+
245
+ /**
246
+ * Reuse an existing worktree by path
247
+ * If set, the workflow will use this worktree instead of creating a new one
248
+ * The path must exist and be a valid git worktree
249
+ */
250
+ reuseWorktreePath?: string;
251
+
252
+ // === Metadata Options ===
253
+
254
+ /**
255
+ * Custom workflow title
256
+ * Auto-generated from source if not specified
257
+ */
258
+ title?: string;
259
+ }
260
+
261
+ // =============================================================================
262
+ // Core Entity Types
263
+ // =============================================================================
264
+
265
+ /**
266
+ * A single step in a workflow
267
+ * Each step corresponds to one issue execution
268
+ */
269
+ export interface WorkflowStep {
270
+ /** Unique step identifier */
271
+ id: string;
272
+
273
+ /** Issue ID this step executes */
274
+ issueId: string;
275
+
276
+ /** Step index in workflow (for ordering) */
277
+ index: number;
278
+
279
+ /** Step IDs this step depends on */
280
+ dependencies: string[];
281
+
282
+ /** Current step status */
283
+ status: WorkflowStepStatus;
284
+
285
+ /** Execution ID once started */
286
+ executionId?: string;
287
+
288
+ /** Git commit SHA after step completion */
289
+ commitSha?: string;
290
+
291
+ /** Error message if failed */
292
+ error?: string;
293
+
294
+ /** Agent type override for this step */
295
+ agentType?: AgentType;
296
+
297
+ /** Model override for this step */
298
+ model?: string;
299
+ }
300
+
301
+ /**
302
+ * A workflow orchestrating multiple issue executions
303
+ */
304
+ export interface Workflow {
305
+ /** Unique workflow identifier */
306
+ id: string;
307
+
308
+ /** Human-readable workflow title */
309
+ title: string;
310
+
311
+ /** How the workflow scope was defined */
312
+ source: WorkflowSource;
313
+
314
+ /** Current workflow status */
315
+ status: WorkflowStatus;
316
+
317
+ /** Steps in this workflow (empty initially for goal-based) */
318
+ steps: WorkflowStep[];
319
+
320
+ // === Worktree Information ===
321
+
322
+ /** Shared worktree path for sequential execution */
323
+ worktreePath?: string;
324
+
325
+ /** Branch name for workflow changes */
326
+ branchName?: string;
327
+
328
+ /** Base branch to create workflow branch from */
329
+ baseBranch: string;
330
+
331
+ // === Progress Tracking ===
332
+
333
+ /** Current step index (for sequential mode) */
334
+ currentStepIndex: number;
335
+
336
+ // === Orchestrator Information (agent-managed mode) ===
337
+
338
+ /** Execution ID of the orchestrator agent */
339
+ orchestratorExecutionId?: string;
340
+
341
+ /** Session ID for orchestrator (maintained across wakeups) */
342
+ orchestratorSessionId?: string;
343
+
344
+ // === Configuration ===
345
+
346
+ /** Workflow configuration */
347
+ config: WorkflowConfig;
348
+
349
+ // === Timestamps ===
350
+
351
+ /** When workflow was created */
352
+ createdAt: string;
353
+
354
+ /** When workflow was last updated */
355
+ updatedAt: string;
356
+
357
+ /** When workflow execution started */
358
+ startedAt?: string;
359
+
360
+ /** When workflow completed (success or failure) */
361
+ completedAt?: string;
362
+ }
363
+
364
+ // =============================================================================
365
+ // Event Types
366
+ // =============================================================================
367
+
368
+ /**
369
+ * Types of workflow events
370
+ */
371
+ export type WorkflowEventType =
372
+ // Step events
373
+ | "step_started"
374
+ | "step_completed"
375
+ | "step_failed"
376
+ | "step_skipped"
377
+ // Workflow lifecycle events
378
+ | "workflow_started"
379
+ | "workflow_paused"
380
+ | "workflow_resumed"
381
+ | "workflow_completed"
382
+ | "workflow_failed"
383
+ | "workflow_cancelled"
384
+ // Escalation events
385
+ | "escalation_requested"
386
+ | "escalation_resolved"
387
+ // Notification events
388
+ | "user_notification"
389
+ // Orchestrator events
390
+ | "orchestrator_wakeup"
391
+ | "user_response";
392
+
393
+ /**
394
+ * A workflow event for tracking and orchestrator wakeups
395
+ */
396
+ export interface WorkflowEvent {
397
+ /** Unique event identifier */
398
+ id: string;
399
+
400
+ /** Workflow this event belongs to */
401
+ workflowId: string;
402
+
403
+ /** Event type */
404
+ type: WorkflowEventType;
405
+
406
+ /** Related step ID (for step events) */
407
+ stepId?: string;
408
+
409
+ /** Related execution ID */
410
+ executionId?: string;
411
+
412
+ /** Event-specific payload */
413
+ payload: Record<string, unknown>;
414
+
415
+ /** When event was created */
416
+ createdAt: string;
417
+
418
+ /** When event was processed by orchestrator */
419
+ processedAt?: string;
420
+ }
421
+
422
+ // =============================================================================
423
+ // Database Row Types (snake_case for SQLite)
424
+ // =============================================================================
425
+
426
+ /**
427
+ * Workflow row as stored in SQLite
428
+ * JSON fields are serialized as TEXT
429
+ */
430
+ export interface WorkflowRow {
431
+ id: string;
432
+ title: string;
433
+ source: string; // JSON (WorkflowSource)
434
+ status: WorkflowStatus;
435
+ steps: string; // JSON (WorkflowStep[])
436
+ worktree_path: string | null;
437
+ branch_name: string | null;
438
+ base_branch: string;
439
+ current_step_index: number;
440
+ orchestrator_execution_id: string | null;
441
+ orchestrator_session_id: string | null;
442
+ config: string; // JSON (WorkflowConfig)
443
+ created_at: string;
444
+ updated_at: string;
445
+ started_at: string | null;
446
+ completed_at: string | null;
447
+ }
448
+
449
+ /**
450
+ * Workflow event row as stored in SQLite
451
+ */
452
+ export interface WorkflowEventRow {
453
+ id: string;
454
+ workflow_id: string;
455
+ type: WorkflowEventType;
456
+ step_id: string | null;
457
+ execution_id: string | null;
458
+ payload: string; // JSON
459
+ created_at: string;
460
+ processed_at: string | null;
461
+ }
462
+
463
+ // =============================================================================
464
+ // Utility Types
465
+ // =============================================================================
466
+
467
+ /**
468
+ * Options for creating a new workflow
469
+ */
470
+ export interface CreateWorkflowOptions {
471
+ title: string;
472
+ source: WorkflowSource;
473
+ config?: Partial<WorkflowConfig>;
474
+ baseBranch?: string;
475
+ }
476
+
477
+ /**
478
+ * Dependency graph analysis result
479
+ */
480
+ export interface DependencyGraph {
481
+ /** Issue IDs in the graph */
482
+ issueIds: string[];
483
+
484
+ /** Edges: [fromId, toId] pairs (from blocks to) */
485
+ edges: Array<[string, string]>;
486
+
487
+ /** Issues in topological order */
488
+ topologicalOrder: string[];
489
+
490
+ /** Detected cycles (if any) */
491
+ cycles: string[][] | null;
492
+
493
+ /** Groups of issues that can run in parallel */
494
+ parallelGroups: string[][];
495
+ }
496
+
497
+ /**
498
+ * Default workflow configuration values (type declaration)
499
+ * Actual defaults should be implemented in consuming packages
500
+ */
501
+ export declare const DEFAULT_WORKFLOW_CONFIG: Readonly<WorkflowConfig>;