@supaku/agentfactory 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.
- package/LICENSE +21 -0
- package/dist/src/deployment/deployment-checker.d.ts +110 -0
- package/dist/src/deployment/deployment-checker.d.ts.map +1 -0
- package/dist/src/deployment/deployment-checker.js +242 -0
- package/dist/src/deployment/index.d.ts +3 -0
- package/dist/src/deployment/index.d.ts.map +1 -0
- package/dist/src/deployment/index.js +2 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +4 -0
- package/dist/src/logger.d.ts +117 -0
- package/dist/src/logger.d.ts.map +1 -0
- package/dist/src/logger.js +430 -0
- package/dist/src/orchestrator/activity-emitter.d.ts +128 -0
- package/dist/src/orchestrator/activity-emitter.d.ts.map +1 -0
- package/dist/src/orchestrator/activity-emitter.js +406 -0
- package/dist/src/orchestrator/api-activity-emitter.d.ts +167 -0
- package/dist/src/orchestrator/api-activity-emitter.d.ts.map +1 -0
- package/dist/src/orchestrator/api-activity-emitter.js +469 -0
- package/dist/src/orchestrator/heartbeat-writer.d.ts +57 -0
- package/dist/src/orchestrator/heartbeat-writer.d.ts.map +1 -0
- package/dist/src/orchestrator/heartbeat-writer.js +137 -0
- package/dist/src/orchestrator/index.d.ts +20 -0
- package/dist/src/orchestrator/index.d.ts.map +1 -0
- package/dist/src/orchestrator/index.js +22 -0
- package/dist/src/orchestrator/log-analyzer.d.ts +160 -0
- package/dist/src/orchestrator/log-analyzer.d.ts.map +1 -0
- package/dist/src/orchestrator/log-analyzer.js +572 -0
- package/dist/src/orchestrator/log-config.d.ts +39 -0
- package/dist/src/orchestrator/log-config.d.ts.map +1 -0
- package/dist/src/orchestrator/log-config.js +45 -0
- package/dist/src/orchestrator/orchestrator.d.ts +246 -0
- package/dist/src/orchestrator/orchestrator.d.ts.map +1 -0
- package/dist/src/orchestrator/orchestrator.js +2525 -0
- package/dist/src/orchestrator/parse-work-result.d.ts +16 -0
- package/dist/src/orchestrator/parse-work-result.d.ts.map +1 -0
- package/dist/src/orchestrator/parse-work-result.js +73 -0
- package/dist/src/orchestrator/progress-logger.d.ts +72 -0
- package/dist/src/orchestrator/progress-logger.d.ts.map +1 -0
- package/dist/src/orchestrator/progress-logger.js +135 -0
- package/dist/src/orchestrator/session-logger.d.ts +159 -0
- package/dist/src/orchestrator/session-logger.d.ts.map +1 -0
- package/dist/src/orchestrator/session-logger.js +275 -0
- package/dist/src/orchestrator/state-recovery.d.ts +96 -0
- package/dist/src/orchestrator/state-recovery.d.ts.map +1 -0
- package/dist/src/orchestrator/state-recovery.js +301 -0
- package/dist/src/orchestrator/state-types.d.ts +165 -0
- package/dist/src/orchestrator/state-types.d.ts.map +1 -0
- package/dist/src/orchestrator/state-types.js +7 -0
- package/dist/src/orchestrator/stream-parser.d.ts +145 -0
- package/dist/src/orchestrator/stream-parser.d.ts.map +1 -0
- package/dist/src/orchestrator/stream-parser.js +131 -0
- package/dist/src/orchestrator/types.d.ts +205 -0
- package/dist/src/orchestrator/types.d.ts.map +1 -0
- package/dist/src/orchestrator/types.js +4 -0
- package/dist/src/providers/amp-provider.d.ts +20 -0
- package/dist/src/providers/amp-provider.d.ts.map +1 -0
- package/dist/src/providers/amp-provider.js +24 -0
- package/dist/src/providers/claude-provider.d.ts +18 -0
- package/dist/src/providers/claude-provider.d.ts.map +1 -0
- package/dist/src/providers/claude-provider.js +267 -0
- package/dist/src/providers/codex-provider.d.ts +21 -0
- package/dist/src/providers/codex-provider.d.ts.map +1 -0
- package/dist/src/providers/codex-provider.js +25 -0
- package/dist/src/providers/index.d.ts +42 -0
- package/dist/src/providers/index.d.ts.map +1 -0
- package/dist/src/providers/index.js +77 -0
- package/dist/src/providers/types.d.ts +147 -0
- package/dist/src/providers/types.d.ts.map +1 -0
- package/dist/src/providers/types.js +13 -0
- package/package.json +63 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Worktree State Types
|
|
3
|
+
*
|
|
4
|
+
* Types for persisting agent state to the .agent/ directory within each worktree.
|
|
5
|
+
* This enables crash recovery, heartbeat monitoring, and progress tracking.
|
|
6
|
+
*/
|
|
7
|
+
import type { AgentWorkType } from '@supaku/agentfactory-linear';
|
|
8
|
+
/**
|
|
9
|
+
* Status of the agent's work in the worktree
|
|
10
|
+
*/
|
|
11
|
+
export type WorktreeStatus = 'initializing' | 'running' | 'completing' | 'completed' | 'failed' | 'stopped';
|
|
12
|
+
/**
|
|
13
|
+
* Primary state file for the worktree
|
|
14
|
+
* Stored at: .agent/state.json
|
|
15
|
+
*/
|
|
16
|
+
export interface WorktreeState {
|
|
17
|
+
/** Linear issue ID (UUID) */
|
|
18
|
+
issueId: string;
|
|
19
|
+
/** Human-readable issue identifier (e.g., SUP-123) */
|
|
20
|
+
issueIdentifier: string;
|
|
21
|
+
/** Linear AgentSession ID (if available) */
|
|
22
|
+
linearSessionId: string | null;
|
|
23
|
+
/** Claude CLI session ID for --resume (if available) */
|
|
24
|
+
claudeSessionId: string | null;
|
|
25
|
+
/** Type of work being performed */
|
|
26
|
+
workType: AgentWorkType;
|
|
27
|
+
/** The prompt that was given to the agent */
|
|
28
|
+
prompt: string;
|
|
29
|
+
/** Unix timestamp when work started */
|
|
30
|
+
startedAt: number;
|
|
31
|
+
/** Current status of the work */
|
|
32
|
+
status: WorktreeStatus;
|
|
33
|
+
/** Human-readable description of current activity */
|
|
34
|
+
currentPhase: string | null;
|
|
35
|
+
/** Unix timestamp of last state update */
|
|
36
|
+
lastUpdatedAt: number;
|
|
37
|
+
/** Number of times recovery has been attempted */
|
|
38
|
+
recoveryAttempts: number;
|
|
39
|
+
/** Worker ID if running on a remote worker */
|
|
40
|
+
workerId: string | null;
|
|
41
|
+
/** Process ID of the agent */
|
|
42
|
+
pid: number | null;
|
|
43
|
+
/** Error message if status is 'failed' */
|
|
44
|
+
errorMessage?: string;
|
|
45
|
+
/** PR URL if one was created */
|
|
46
|
+
pullRequestUrl?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Claude Code Task List ID for intra-session task coordination
|
|
49
|
+
* Format: {issueIdentifier}-{WORKTYPE} (e.g., "SUP-123-DEV")
|
|
50
|
+
* Enables task persistence across crashes and subagent coordination
|
|
51
|
+
*/
|
|
52
|
+
taskListId?: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Activity type for heartbeat tracking
|
|
56
|
+
*/
|
|
57
|
+
export type HeartbeatActivityType = 'tool_use' | 'thinking' | 'waiting' | 'idle';
|
|
58
|
+
/**
|
|
59
|
+
* Heartbeat state file for liveness detection
|
|
60
|
+
* Stored at: .agent/heartbeat.json
|
|
61
|
+
* Updated every 10 seconds while the agent is running
|
|
62
|
+
*/
|
|
63
|
+
export interface HeartbeatState {
|
|
64
|
+
/** Unix timestamp of this heartbeat */
|
|
65
|
+
timestamp: number;
|
|
66
|
+
/** Process ID of the agent */
|
|
67
|
+
pid: number;
|
|
68
|
+
/** Memory usage in megabytes */
|
|
69
|
+
memoryUsageMB: number;
|
|
70
|
+
/** Uptime in seconds since agent started */
|
|
71
|
+
uptime: number;
|
|
72
|
+
/** Type of last detected activity */
|
|
73
|
+
lastActivityType: HeartbeatActivityType;
|
|
74
|
+
/** Unix timestamp of last activity */
|
|
75
|
+
lastActivityTimestamp: number;
|
|
76
|
+
/** Total number of tool calls made so far */
|
|
77
|
+
toolCallsCount: number;
|
|
78
|
+
/** Current operation being performed (if any) */
|
|
79
|
+
currentOperation: string | null;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Todo item status (mirrors TodoWrite tool)
|
|
83
|
+
*/
|
|
84
|
+
export type TodoStatus = 'pending' | 'in_progress' | 'completed';
|
|
85
|
+
/**
|
|
86
|
+
* Todo item (mirrors TodoWrite tool structure)
|
|
87
|
+
*/
|
|
88
|
+
export interface TodoItem {
|
|
89
|
+
/** Task description (imperative form) */
|
|
90
|
+
content: string;
|
|
91
|
+
/** Current status */
|
|
92
|
+
status: TodoStatus;
|
|
93
|
+
/** Present continuous form for display */
|
|
94
|
+
activeForm: string;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Persisted todo list state
|
|
98
|
+
* Stored at: .agent/todos.json
|
|
99
|
+
* Synced with TodoWrite tool calls
|
|
100
|
+
*/
|
|
101
|
+
export interface TodosState {
|
|
102
|
+
/** Unix timestamp of last update */
|
|
103
|
+
updatedAt: number;
|
|
104
|
+
/** Current todo items */
|
|
105
|
+
items: TodoItem[];
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Progress log entry type
|
|
109
|
+
*/
|
|
110
|
+
export type ProgressEventType = 'start' | 'phase' | 'tool' | 'error' | 'recovery' | 'complete' | 'stop';
|
|
111
|
+
/**
|
|
112
|
+
* Progress log entry
|
|
113
|
+
* Appended to: .agent/progress.log
|
|
114
|
+
* Format: timestamp|event_type|details
|
|
115
|
+
*/
|
|
116
|
+
export interface ProgressLogEntry {
|
|
117
|
+
/** Unix timestamp */
|
|
118
|
+
timestamp: number;
|
|
119
|
+
/** Type of event */
|
|
120
|
+
eventType: ProgressEventType;
|
|
121
|
+
/** Event details (JSON stringified if object) */
|
|
122
|
+
details: string;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Result of checking for recoverable state in a worktree
|
|
126
|
+
*/
|
|
127
|
+
export interface RecoveryCheckResult {
|
|
128
|
+
/** Whether recovery is possible */
|
|
129
|
+
canRecover: boolean;
|
|
130
|
+
/** Whether an agent is currently alive (heartbeat fresh) */
|
|
131
|
+
agentAlive: boolean;
|
|
132
|
+
/** The state if found */
|
|
133
|
+
state?: WorktreeState;
|
|
134
|
+
/** The heartbeat if found */
|
|
135
|
+
heartbeat?: HeartbeatState;
|
|
136
|
+
/** The todos if found */
|
|
137
|
+
todos?: TodosState;
|
|
138
|
+
/** Reason why recovery is not possible */
|
|
139
|
+
reason?: 'no_state' | 'agent_alive' | 'max_attempts' | 'invalid_state';
|
|
140
|
+
/** Human-readable message */
|
|
141
|
+
message: string;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Configuration for heartbeat writer
|
|
145
|
+
*/
|
|
146
|
+
export interface HeartbeatWriterConfig {
|
|
147
|
+
/** Directory path to write heartbeat to */
|
|
148
|
+
agentDir: string;
|
|
149
|
+
/** Process ID of the agent */
|
|
150
|
+
pid: number;
|
|
151
|
+
/** Interval between heartbeats in milliseconds (default: 10000) */
|
|
152
|
+
intervalMs?: number;
|
|
153
|
+
/** Start time of the agent (for uptime calculation) */
|
|
154
|
+
startTime: number;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Configuration for progress logger
|
|
158
|
+
*/
|
|
159
|
+
export interface ProgressLoggerConfig {
|
|
160
|
+
/** Directory path to write progress log to */
|
|
161
|
+
agentDir: string;
|
|
162
|
+
/** Maximum log file size in bytes before rotation (default: 1MB) */
|
|
163
|
+
maxSizeBytes?: number;
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=state-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-types.d.ts","sourceRoot":"","sources":["../../../src/orchestrator/state-types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAEhE;;GAEG;AACH,MAAM,MAAM,cAAc,GACtB,cAAc,GACd,SAAS,GACT,YAAY,GACZ,WAAW,GACX,QAAQ,GACR,SAAS,CAAA;AAEb;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,6BAA6B;IAC7B,OAAO,EAAE,MAAM,CAAA;IACf,sDAAsD;IACtD,eAAe,EAAE,MAAM,CAAA;IACvB,4CAA4C;IAC5C,eAAe,EAAE,MAAM,GAAG,IAAI,CAAA;IAC9B,wDAAwD;IACxD,eAAe,EAAE,MAAM,GAAG,IAAI,CAAA;IAC9B,mCAAmC;IACnC,QAAQ,EAAE,aAAa,CAAA;IACvB,6CAA6C;I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C9C,QAAQ,EAAE,MAAM,CAAA;IAChB,oEAAoE;IACpE,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Stream-JSON Parser
|
|
3
|
+
*
|
|
4
|
+
* Parses Claude's stream-json output format and maps events to handler callbacks.
|
|
5
|
+
* The stream-json format emits newline-delimited JSON events during execution.
|
|
6
|
+
*
|
|
7
|
+
* Event types:
|
|
8
|
+
* - init: Initial message with configuration
|
|
9
|
+
* - system: System messages and prompts
|
|
10
|
+
* - assistant: Assistant text output (partial/streaming)
|
|
11
|
+
* - tool_use: Tool being invoked
|
|
12
|
+
* - tool_result: Result from tool execution
|
|
13
|
+
* - result: Final result when complete
|
|
14
|
+
* - error: Error events
|
|
15
|
+
*/
|
|
16
|
+
/** Base event structure */
|
|
17
|
+
export interface ClaudeStreamEvent {
|
|
18
|
+
type: string;
|
|
19
|
+
timestamp?: string;
|
|
20
|
+
}
|
|
21
|
+
/** Initialization event */
|
|
22
|
+
export interface ClaudeInitEvent extends ClaudeStreamEvent {
|
|
23
|
+
type: 'init';
|
|
24
|
+
message: string;
|
|
25
|
+
sessionId?: string;
|
|
26
|
+
}
|
|
27
|
+
/** System message event */
|
|
28
|
+
export interface ClaudeSystemEvent extends ClaudeStreamEvent {
|
|
29
|
+
type: 'system';
|
|
30
|
+
message: string;
|
|
31
|
+
subtype?: 'prompt' | 'info' | 'warning';
|
|
32
|
+
}
|
|
33
|
+
/** Assistant text output event */
|
|
34
|
+
export interface ClaudeAssistantEvent extends ClaudeStreamEvent {
|
|
35
|
+
type: 'assistant';
|
|
36
|
+
message: string;
|
|
37
|
+
partial?: boolean;
|
|
38
|
+
}
|
|
39
|
+
/** Tool use event - when Claude invokes a tool */
|
|
40
|
+
export interface ClaudeToolUseEvent extends ClaudeStreamEvent {
|
|
41
|
+
type: 'tool_use';
|
|
42
|
+
tool: string;
|
|
43
|
+
input: Record<string, unknown>;
|
|
44
|
+
tool_use_id?: string;
|
|
45
|
+
}
|
|
46
|
+
/** Tool result event - when tool execution completes */
|
|
47
|
+
export interface ClaudeToolResultEvent extends ClaudeStreamEvent {
|
|
48
|
+
type: 'tool_result';
|
|
49
|
+
tool: string;
|
|
50
|
+
output: string;
|
|
51
|
+
tool_use_id?: string;
|
|
52
|
+
is_error?: boolean;
|
|
53
|
+
}
|
|
54
|
+
/** Final result event */
|
|
55
|
+
export interface ClaudeResultEvent extends ClaudeStreamEvent {
|
|
56
|
+
type: 'result';
|
|
57
|
+
result: string;
|
|
58
|
+
cost?: {
|
|
59
|
+
input_tokens: number;
|
|
60
|
+
output_tokens: number;
|
|
61
|
+
};
|
|
62
|
+
duration_ms?: number;
|
|
63
|
+
}
|
|
64
|
+
/** Error event */
|
|
65
|
+
export interface ClaudeErrorEvent extends ClaudeStreamEvent {
|
|
66
|
+
type: 'error';
|
|
67
|
+
error: {
|
|
68
|
+
message: string;
|
|
69
|
+
code?: string;
|
|
70
|
+
details?: unknown;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/** Todo item in a user event */
|
|
74
|
+
export interface ClaudeTodoItem {
|
|
75
|
+
content: string;
|
|
76
|
+
status: 'pending' | 'in_progress' | 'completed';
|
|
77
|
+
activeForm: string;
|
|
78
|
+
}
|
|
79
|
+
/** User event - contains tool results including todo updates */
|
|
80
|
+
export interface ClaudeUserEvent extends ClaudeStreamEvent {
|
|
81
|
+
type: 'user';
|
|
82
|
+
message?: {
|
|
83
|
+
role: 'user';
|
|
84
|
+
content?: Array<{
|
|
85
|
+
tool_use_id?: string;
|
|
86
|
+
type?: string;
|
|
87
|
+
content?: string;
|
|
88
|
+
}>;
|
|
89
|
+
};
|
|
90
|
+
tool_use_result?: {
|
|
91
|
+
oldTodos?: ClaudeTodoItem[];
|
|
92
|
+
newTodos?: ClaudeTodoItem[];
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/** Union of all Claude stream event types */
|
|
96
|
+
export type ClaudeEvent = ClaudeInitEvent | ClaudeSystemEvent | ClaudeAssistantEvent | ClaudeToolUseEvent | ClaudeToolResultEvent | ClaudeResultEvent | ClaudeErrorEvent | ClaudeUserEvent | ClaudeStreamEvent;
|
|
97
|
+
/** Event handlers for Claude stream events */
|
|
98
|
+
export interface ClaudeStreamHandlers {
|
|
99
|
+
onInit?: (event: ClaudeInitEvent) => void | Promise<void>;
|
|
100
|
+
onSystem?: (event: ClaudeSystemEvent) => void | Promise<void>;
|
|
101
|
+
onAssistant?: (event: ClaudeAssistantEvent) => void | Promise<void>;
|
|
102
|
+
onToolUse?: (event: ClaudeToolUseEvent) => void | Promise<void>;
|
|
103
|
+
onToolResult?: (event: ClaudeToolResultEvent) => void | Promise<void>;
|
|
104
|
+
onResult?: (event: ClaudeResultEvent) => void | Promise<void>;
|
|
105
|
+
onError?: (event: ClaudeErrorEvent) => void | Promise<void>;
|
|
106
|
+
onUser?: (event: ClaudeUserEvent) => void | Promise<void>;
|
|
107
|
+
onTodo?: (newTodos: ClaudeTodoItem[], oldTodos: ClaudeTodoItem[]) => void | Promise<void>;
|
|
108
|
+
onUnknown?: (event: ClaudeStreamEvent) => void | Promise<void>;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Claude Stream Parser
|
|
112
|
+
*
|
|
113
|
+
* Handles parsing of newline-delimited JSON stream from Claude,
|
|
114
|
+
* including buffering for partial lines.
|
|
115
|
+
*/
|
|
116
|
+
export declare class ClaudeStreamParser {
|
|
117
|
+
private buffer;
|
|
118
|
+
private handlers;
|
|
119
|
+
constructor(handlers?: ClaudeStreamHandlers);
|
|
120
|
+
/**
|
|
121
|
+
* Feed raw data from stdout into the parser
|
|
122
|
+
*/
|
|
123
|
+
feed(data: Buffer | string): Promise<void>;
|
|
124
|
+
/**
|
|
125
|
+
* Flush any remaining buffered data
|
|
126
|
+
*/
|
|
127
|
+
flush(): Promise<void>;
|
|
128
|
+
/**
|
|
129
|
+
* Parse a single JSON line and dispatch to appropriate handler
|
|
130
|
+
*/
|
|
131
|
+
private parseLine;
|
|
132
|
+
/**
|
|
133
|
+
* Dispatch an event to the appropriate handler
|
|
134
|
+
*/
|
|
135
|
+
private dispatchEvent;
|
|
136
|
+
/**
|
|
137
|
+
* Handle user events, extracting todo updates if present
|
|
138
|
+
*/
|
|
139
|
+
private handleUserEvent;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Create a new Claude stream parser instance
|
|
143
|
+
*/
|
|
144
|
+
export declare function createStreamParser(handlers: ClaudeStreamHandlers): ClaudeStreamParser;
|
|
145
|
+
//# sourceMappingURL=stream-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-parser.d.ts","sourceRoot":"","sources":["../../../src/orchestrator/stream-parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,2BAA2B;AAC3B,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,2BAA2B;AAC3B,MAAM,WAAW,eAAgB,SAAQ,iBAAiB;IACxD,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,2BAA2B;AAC3B,MAAM,WAAW,iBAAkB,SAAQ,iBAAiB;IAC1D,IAAI,EAAE,QAAQ,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,SAAS,CAAA;CACxC;AAED,kCAAkC;AAClC,MAAM,WAAW,oBAAqB,SAAQ,iBAAiB;IAC7D,IAAI,EAAE,WAAW,CAAA;IACjB,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,kDAAkD;AAClD,MAAM,WAAW,kBAAmB,SAAQ,iBAAiB;IAC3D,IAAI,EAAE,UAAU,C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,EAAE,cAAc,EAAE,EAC1B,QAAQ,EAAE,cAAc,EAAE,KACvB,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACzB,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAC/D;AAED;;;;;GAKG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,MAAM,CAAK;IACnB,OAAO,CAAC,QAAQ,CAAsB;gBAE1B,QAAQ,GAAE,oBAAyB;IAI/C;;OAEG;IACG,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAehD;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAO5B;;OAEG;YACW,SAAS;IAuBvB;;OAEG;YACW,aAAa;IAmC3B;;OAEG;YACW,eAAe;CAY9B;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,oBAAoB,GAC7B,kBAAkB,CAEpB"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Stream-JSON Parser
|
|
3
|
+
*
|
|
4
|
+
* Parses Claude's stream-json output format and maps events to handler callbacks.
|
|
5
|
+
* The stream-json format emits newline-delimited JSON events during execution.
|
|
6
|
+
*
|
|
7
|
+
* Event types:
|
|
8
|
+
* - init: Initial message with configuration
|
|
9
|
+
* - system: System messages and prompts
|
|
10
|
+
* - assistant: Assistant text output (partial/streaming)
|
|
11
|
+
* - tool_use: Tool being invoked
|
|
12
|
+
* - tool_result: Result from tool execution
|
|
13
|
+
* - result: Final result when complete
|
|
14
|
+
* - error: Error events
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Claude Stream Parser
|
|
18
|
+
*
|
|
19
|
+
* Handles parsing of newline-delimited JSON stream from Claude,
|
|
20
|
+
* including buffering for partial lines.
|
|
21
|
+
*/
|
|
22
|
+
export class ClaudeStreamParser {
|
|
23
|
+
buffer = '';
|
|
24
|
+
handlers;
|
|
25
|
+
constructor(handlers = {}) {
|
|
26
|
+
this.handlers = handlers;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Feed raw data from stdout into the parser
|
|
30
|
+
*/
|
|
31
|
+
async feed(data) {
|
|
32
|
+
this.buffer += data.toString();
|
|
33
|
+
// Process complete lines
|
|
34
|
+
const lines = this.buffer.split('\n');
|
|
35
|
+
// Keep the last incomplete line in buffer
|
|
36
|
+
this.buffer = lines.pop() ?? '';
|
|
37
|
+
for (const line of lines) {
|
|
38
|
+
if (line.trim()) {
|
|
39
|
+
await this.parseLine(line);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Flush any remaining buffered data
|
|
45
|
+
*/
|
|
46
|
+
async flush() {
|
|
47
|
+
if (this.buffer.trim()) {
|
|
48
|
+
await this.parseLine(this.buffer);
|
|
49
|
+
this.buffer = '';
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Parse a single JSON line and dispatch to appropriate handler
|
|
54
|
+
*/
|
|
55
|
+
async parseLine(line) {
|
|
56
|
+
let event;
|
|
57
|
+
try {
|
|
58
|
+
event = JSON.parse(line);
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
// Log JSON parse errors with context for debugging
|
|
62
|
+
// This helps diagnose truncated or malformed messages
|
|
63
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
64
|
+
const linePreview = line.length > 200
|
|
65
|
+
? line.substring(0, 200) + `... (${line.length} chars total)`
|
|
66
|
+
: line;
|
|
67
|
+
console.warn('JSON parse error in stream', {
|
|
68
|
+
error: errorMessage,
|
|
69
|
+
lineLength: line.length,
|
|
70
|
+
linePreview,
|
|
71
|
+
});
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
await this.dispatchEvent(event);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Dispatch an event to the appropriate handler
|
|
78
|
+
*/
|
|
79
|
+
async dispatchEvent(event) {
|
|
80
|
+
try {
|
|
81
|
+
switch (event.type) {
|
|
82
|
+
case 'init':
|
|
83
|
+
await this.handlers.onInit?.(event);
|
|
84
|
+
break;
|
|
85
|
+
case 'system':
|
|
86
|
+
await this.handlers.onSystem?.(event);
|
|
87
|
+
break;
|
|
88
|
+
case 'assistant':
|
|
89
|
+
await this.handlers.onAssistant?.(event);
|
|
90
|
+
break;
|
|
91
|
+
case 'tool_use':
|
|
92
|
+
await this.handlers.onToolUse?.(event);
|
|
93
|
+
break;
|
|
94
|
+
case 'tool_result':
|
|
95
|
+
await this.handlers.onToolResult?.(event);
|
|
96
|
+
break;
|
|
97
|
+
case 'result':
|
|
98
|
+
await this.handlers.onResult?.(event);
|
|
99
|
+
break;
|
|
100
|
+
case 'error':
|
|
101
|
+
await this.handlers.onError?.(event);
|
|
102
|
+
break;
|
|
103
|
+
case 'user':
|
|
104
|
+
await this.handleUserEvent(event);
|
|
105
|
+
break;
|
|
106
|
+
default:
|
|
107
|
+
await this.handlers.onUnknown?.(event);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
console.error(`Error handling ${event.type} event:`, error);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Handle user events, extracting todo updates if present
|
|
116
|
+
*/
|
|
117
|
+
async handleUserEvent(event) {
|
|
118
|
+
// Always call onUser if registered
|
|
119
|
+
await this.handlers.onUser?.(event);
|
|
120
|
+
// Check for todo updates in tool_use_result
|
|
121
|
+
if (event.tool_use_result?.newTodos) {
|
|
122
|
+
await this.handlers.onTodo?.(event.tool_use_result.newTodos, event.tool_use_result.oldTodos ?? []);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Create a new Claude stream parser instance
|
|
128
|
+
*/
|
|
129
|
+
export function createStreamParser(handlers) {
|
|
130
|
+
return new ClaudeStreamParser(handlers);
|
|
131
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Orchestrator Types
|
|
3
|
+
*/
|
|
4
|
+
import type { AgentWorkType } from '@supaku/agentfactory-linear';
|
|
5
|
+
import type { AgentProvider } from '../providers/types';
|
|
6
|
+
/**
|
|
7
|
+
* Result of parsing an agent's output to determine pass/fail
|
|
8
|
+
* Used for QA and acceptance work types to decide status transitions
|
|
9
|
+
*/
|
|
10
|
+
export type AgentWorkResult = 'passed' | 'failed' | 'unknown';
|
|
11
|
+
/**
|
|
12
|
+
* Timeout configuration for a specific work type
|
|
13
|
+
*/
|
|
14
|
+
export interface WorkTypeTimeoutConfig {
|
|
15
|
+
/** Inactivity timeout in milliseconds for this work type */
|
|
16
|
+
inactivityTimeoutMs?: number;
|
|
17
|
+
/** Maximum session duration in milliseconds for this work type */
|
|
18
|
+
maxSessionTimeoutMs?: number;
|
|
19
|
+
}
|
|
20
|
+
export interface OrchestratorConfig {
|
|
21
|
+
/** Agent provider instance. If not provided, resolved via AGENT_PROVIDER env var (default: claude) */
|
|
22
|
+
provider?: AgentProvider;
|
|
23
|
+
/** Maximum concurrent agents (default: 3) */
|
|
24
|
+
maxConcurrent?: number;
|
|
25
|
+
/** Project name to filter backlog issues */
|
|
26
|
+
project?: string;
|
|
27
|
+
/** Base path for git worktrees (default: .worktrees) */
|
|
28
|
+
worktreePath?: string;
|
|
29
|
+
/** Linear API key (defaults to LINEAR_API_KEY env var) */
|
|
30
|
+
linearApiKey?: string;
|
|
31
|
+
/** Whether to auto-transition issue status (default: true) */
|
|
32
|
+
autoTransition?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Preserve worktree when PR creation fails for development work types (default: true).
|
|
35
|
+
* When true, worktrees are kept if:
|
|
36
|
+
* - Work type is 'development' or 'inflight' and no PR URL was detected
|
|
37
|
+
* - There are uncommitted changes in the worktree
|
|
38
|
+
* - There are unpushed commits on the branch
|
|
39
|
+
* This prevents data loss when git push or PR creation fails.
|
|
40
|
+
*/
|
|
41
|
+
preserveWorkOnPrFailure?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Enable sandbox mode for spawned agents (default: false).
|
|
44
|
+
*
|
|
45
|
+
* WARNING: Currently defaults to false due to known bugs in Claude Code's sandbox:
|
|
46
|
+
* - https://github.com/anthropics/claude-code/issues/14162 (excludedCommands doesn't bypass network)
|
|
47
|
+
* - https://github.com/anthropics/claude-code/issues/12150 (proxy set for excluded commands)
|
|
48
|
+
*
|
|
49
|
+
* Set to true to re-enable sandbox once these issues are fixed.
|
|
50
|
+
*/
|
|
51
|
+
sandboxEnabled?: boolean;
|
|
52
|
+
/** Configuration for streaming activities to Linear */
|
|
53
|
+
streamConfig?: OrchestratorStreamConfig;
|
|
54
|
+
/**
|
|
55
|
+
* Configuration for proxying activities through the agent API.
|
|
56
|
+
* When set, activities are sent to the API endpoint instead of directly to Linear.
|
|
57
|
+
* This is required for remote workers because Linear's Agent API requires OAuth tokens.
|
|
58
|
+
*/
|
|
59
|
+
apiActivityConfig?: {
|
|
60
|
+
/** Base URL of the agent API (e.g., https://agent.supaku.dev) */
|
|
61
|
+
baseUrl: string;
|
|
62
|
+
/** API authentication key for the worker */
|
|
63
|
+
apiKey: string;
|
|
64
|
+
/** Worker ID for identification */
|
|
65
|
+
workerId: string;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Inactivity timeout in milliseconds (default: 300000 = 5 minutes).
|
|
69
|
+
* Agent is stopped if no activity for this duration.
|
|
70
|
+
* Can be overridden per work type via workTypeTimeouts.
|
|
71
|
+
*/
|
|
72
|
+
inactivityTimeoutMs?: number;
|
|
73
|
+
/**
|
|
74
|
+
* Maximum session duration in milliseconds (default: unlimited).
|
|
75
|
+
* Hard cap on total agent runtime regardless of activity.
|
|
76
|
+
* Can be overridden per work type via workTypeTimeouts.
|
|
77
|
+
*/
|
|
78
|
+
maxSessionTimeoutMs?: number;
|
|
79
|
+
/**
|
|
80
|
+
* Per-work-type timeout overrides.
|
|
81
|
+
* Different work types (e.g., QA, development) can have different thresholds.
|
|
82
|
+
*/
|
|
83
|
+
workTypeTimeouts?: Partial<Record<AgentWorkType, WorkTypeTimeoutConfig>>;
|
|
84
|
+
}
|
|
85
|
+
export interface OrchestratorIssue {
|
|
86
|
+
id: string;
|
|
87
|
+
identifier: string;
|
|
88
|
+
title: string;
|
|
89
|
+
description: string | undefined;
|
|
90
|
+
url: string;
|
|
91
|
+
priority: number;
|
|
92
|
+
labels: string[];
|
|
93
|
+
}
|
|
94
|
+
export interface AgentProcess {
|
|
95
|
+
issueId: string;
|
|
96
|
+
identifier: string;
|
|
97
|
+
/** Worktree identifier includes work type suffix (e.g., "SUP-294-QA") */
|
|
98
|
+
worktreeIdentifier: string;
|
|
99
|
+
sessionId?: string;
|
|
100
|
+
/** Claude CLI session ID for resuming sessions with --resume */
|
|
101
|
+
claudeSessionId?: string;
|
|
102
|
+
worktreePath: string;
|
|
103
|
+
pid: number | undefined;
|
|
104
|
+
status: 'starting' | 'running' | 'completed' | 'failed' | 'stopped' | 'incomplete';
|
|
105
|
+
startedAt: Date;
|
|
106
|
+
completedAt?: Date;
|
|
107
|
+
exitCode?: number;
|
|
108
|
+
error?: Error;
|
|
109
|
+
/** Type of work: 'development' or 'qa' */
|
|
110
|
+
workType?: AgentWorkType;
|
|
111
|
+
/** GitHub PR URL if a pull request was created */
|
|
112
|
+
pullRequestUrl?: string;
|
|
113
|
+
/** Full completion message from Claude (stored for comment posting) */
|
|
114
|
+
resultMessage?: string;
|
|
115
|
+
/** Reason why work was marked incomplete (only set when status is 'incomplete') */
|
|
116
|
+
incompleteReason?: 'no_pr_created' | 'uncommitted_changes' | 'unpushed_commits';
|
|
117
|
+
/** Result of work for QA/acceptance agents (passed/failed/unknown) */
|
|
118
|
+
workResult?: AgentWorkResult;
|
|
119
|
+
/** Reason why agent was stopped (only set when status is 'stopped') */
|
|
120
|
+
stopReason?: 'user_request' | 'timeout';
|
|
121
|
+
/** Last activity timestamp for inactivity timeout tracking */
|
|
122
|
+
lastActivityAt: Date;
|
|
123
|
+
/** Total cost in USD (accumulated from provider result events) */
|
|
124
|
+
totalCostUsd?: number;
|
|
125
|
+
/** Total input tokens used */
|
|
126
|
+
inputTokens?: number;
|
|
127
|
+
/** Total output tokens used */
|
|
128
|
+
outputTokens?: number;
|
|
129
|
+
}
|
|
130
|
+
export interface OrchestratorEvents {
|
|
131
|
+
onAgentStart?: (agent: AgentProcess) => void;
|
|
132
|
+
onAgentComplete?: (agent: AgentProcess) => void;
|
|
133
|
+
onAgentError?: (agent: AgentProcess, error: Error) => void;
|
|
134
|
+
onAgentStopped?: (agent: AgentProcess) => void;
|
|
135
|
+
/** Called when agent work is incomplete (no PR, uncommitted changes, etc.) */
|
|
136
|
+
onAgentIncomplete?: (agent: AgentProcess) => void;
|
|
137
|
+
onIssueSelected?: (issue: OrchestratorIssue) => void;
|
|
138
|
+
/** Called when Claude session ID is captured from init event */
|
|
139
|
+
onClaudeSessionId?: (linearSessionId: string, claudeSessionId: string) => void | Promise<void>;
|
|
140
|
+
/** Called when an activity is emitted for an agent (used for timeout tracking) */
|
|
141
|
+
onActivityEmitted?: (agent: AgentProcess, activityType: string) => void;
|
|
142
|
+
}
|
|
143
|
+
export interface SpawnAgentOptions {
|
|
144
|
+
issueId: string;
|
|
145
|
+
identifier: string;
|
|
146
|
+
/** Worktree identifier with work type suffix (e.g., "SUP-294-QA") */
|
|
147
|
+
worktreeIdentifier: string;
|
|
148
|
+
sessionId?: string;
|
|
149
|
+
worktreePath: string;
|
|
150
|
+
/** Enable streaming activities to Linear (default: true when sessionId is provided) */
|
|
151
|
+
streamActivities?: boolean;
|
|
152
|
+
/** Type of work: determines prompt and agent routing (defaults to 'development') */
|
|
153
|
+
workType?: AgentWorkType;
|
|
154
|
+
/** Custom prompt override. If not provided, generates prompt based on workType */
|
|
155
|
+
prompt?: string;
|
|
156
|
+
}
|
|
157
|
+
export interface OrchestratorStreamConfig {
|
|
158
|
+
/** Minimum interval between activities in ms (default: 500ms) */
|
|
159
|
+
minInterval?: number;
|
|
160
|
+
/** Maximum length for tool outputs before truncation (default: 2000) */
|
|
161
|
+
maxOutputLength?: number;
|
|
162
|
+
/** Whether to include timestamps in activities (default: false) */
|
|
163
|
+
includeTimestamps?: boolean;
|
|
164
|
+
}
|
|
165
|
+
export interface OrchestratorResult {
|
|
166
|
+
success: boolean;
|
|
167
|
+
agents: AgentProcess[];
|
|
168
|
+
errors: Array<{
|
|
169
|
+
issueId: string;
|
|
170
|
+
error: Error;
|
|
171
|
+
}>;
|
|
172
|
+
}
|
|
173
|
+
export interface StopAgentResult {
|
|
174
|
+
stopped: boolean;
|
|
175
|
+
reason?: 'not_found' | 'already_stopped' | 'signal_failed';
|
|
176
|
+
agent?: AgentProcess;
|
|
177
|
+
}
|
|
178
|
+
export interface ForwardPromptResult {
|
|
179
|
+
forwarded: boolean;
|
|
180
|
+
resumed: boolean;
|
|
181
|
+
/** True if message was injected into running session (no restart needed) */
|
|
182
|
+
injected?: boolean;
|
|
183
|
+
reason?: 'not_found' | 'spawn_failed' | 'no_worktree';
|
|
184
|
+
agent?: AgentProcess;
|
|
185
|
+
error?: Error;
|
|
186
|
+
}
|
|
187
|
+
export interface InjectMessageResult {
|
|
188
|
+
/** True if message was successfully injected into running session */
|
|
189
|
+
injected: boolean;
|
|
190
|
+
reason?: 'not_running' | 'no_query' | 'injection_failed';
|
|
191
|
+
error?: Error;
|
|
192
|
+
}
|
|
193
|
+
export interface SpawnAgentWithResumeOptions {
|
|
194
|
+
issueId: string;
|
|
195
|
+
identifier: string;
|
|
196
|
+
/** Worktree identifier with work type suffix (e.g., "SUP-294-QA") */
|
|
197
|
+
worktreeIdentifier: string;
|
|
198
|
+
sessionId: string;
|
|
199
|
+
worktreePath: string;
|
|
200
|
+
prompt: string;
|
|
201
|
+
claudeSessionId?: string;
|
|
202
|
+
/** Type of work: determines transitions and agent behavior (defaults to 'development') */
|
|
203
|
+
workType?: AgentWorkType;
|
|
204
|
+
}
|
|
205
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/orchestrator/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAChE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAEvD;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAA;AAE7D;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,4DAA4D;IAC5D,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAC5B,kEAAkE;IAClE,mBAAmB,CAAC,EAAE,MAAM,CAAA;CAC7B;AAED,MAAM,WAAW,kBAAkB;IACjC,sGAAsG;IACtG,QAAQ,CAAC,EAAE,aAAa,CAAA;IACxB,6CAA6C;IAC7C,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,4CAA4C;IAC5C,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,wDAAwD;IACxD,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,0DAA0D;IAC1D,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,8DAA8D;IAC9D,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB;;;;;;;OAOG;IACH,uBAAuB,CAAC,EAAE,OAAO,CAAA;IACjC;;;;;;;;OAQG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,uDAAuD;IACvD,YAAY,CAAC,EAAE,wBAAwB,CAAA;IACvC;;;;OAIG;IACH,iBAAiB,CAAC,EAAE;QAClB,iEAAiE;QACjE,OAAO,EAAE,MAAM,CAAA;QACf,4CAA4C;QAC5C,MAAM,EAAE,MAAM,CAAA;QACd,mCAAmC;QACnC,QAAQ,EAAE,M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