@renseiai/agentfactory 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (246) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +125 -0
  3. package/dist/src/config/index.d.ts +3 -0
  4. package/dist/src/config/index.d.ts.map +1 -0
  5. package/dist/src/config/index.js +1 -0
  6. package/dist/src/config/repository-config.d.ts +44 -0
  7. package/dist/src/config/repository-config.d.ts.map +1 -0
  8. package/dist/src/config/repository-config.js +88 -0
  9. package/dist/src/config/repository-config.test.d.ts +2 -0
  10. package/dist/src/config/repository-config.test.d.ts.map +1 -0
  11. package/dist/src/config/repository-config.test.js +249 -0
  12. package/dist/src/deployment/deployment-checker.d.ts +110 -0
  13. package/dist/src/deployment/deployment-checker.d.ts.map +1 -0
  14. package/dist/src/deployment/deployment-checker.js +242 -0
  15. package/dist/src/deployment/index.d.ts +3 -0
  16. package/dist/src/deployment/index.d.ts.map +1 -0
  17. package/dist/src/deployment/index.js +2 -0
  18. package/dist/src/frontend/index.d.ts +2 -0
  19. package/dist/src/frontend/index.d.ts.map +1 -0
  20. package/dist/src/frontend/index.js +1 -0
  21. package/dist/src/frontend/types.d.ts +106 -0
  22. package/dist/src/frontend/types.d.ts.map +1 -0
  23. package/dist/src/frontend/types.js +11 -0
  24. package/dist/src/governor/decision-engine.d.ts +52 -0
  25. package/dist/src/governor/decision-engine.d.ts.map +1 -0
  26. package/dist/src/governor/decision-engine.js +220 -0
  27. package/dist/src/governor/decision-engine.test.d.ts +2 -0
  28. package/dist/src/governor/decision-engine.test.d.ts.map +1 -0
  29. package/dist/src/governor/decision-engine.test.js +629 -0
  30. package/dist/src/governor/event-bus.d.ts +43 -0
  31. package/dist/src/governor/event-bus.d.ts.map +1 -0
  32. package/dist/src/governor/event-bus.js +8 -0
  33. package/dist/src/governor/event-deduplicator.d.ts +43 -0
  34. package/dist/src/governor/event-deduplicator.d.ts.map +1 -0
  35. package/dist/src/governor/event-deduplicator.js +53 -0
  36. package/dist/src/governor/event-driven-governor.d.ts +131 -0
  37. package/dist/src/governor/event-driven-governor.d.ts.map +1 -0
  38. package/dist/src/governor/event-driven-governor.js +379 -0
  39. package/dist/src/governor/event-driven-governor.test.d.ts +2 -0
  40. package/dist/src/governor/event-driven-governor.test.d.ts.map +1 -0
  41. package/dist/src/governor/event-driven-governor.test.js +673 -0
  42. package/dist/src/governor/event-types.d.ts +78 -0
  43. package/dist/src/governor/event-types.d.ts.map +1 -0
  44. package/dist/src/governor/event-types.js +32 -0
  45. package/dist/src/governor/governor-types.d.ts +82 -0
  46. package/dist/src/governor/governor-types.d.ts.map +1 -0
  47. package/dist/src/governor/governor-types.js +21 -0
  48. package/dist/src/governor/governor.d.ts +100 -0
  49. package/dist/src/governor/governor.d.ts.map +1 -0
  50. package/dist/src/governor/governor.js +262 -0
  51. package/dist/src/governor/governor.test.d.ts +2 -0
  52. package/dist/src/governor/governor.test.d.ts.map +1 -0
  53. package/dist/src/governor/governor.test.js +514 -0
  54. package/dist/src/governor/human-touchpoints.d.ts +131 -0
  55. package/dist/src/governor/human-touchpoints.d.ts.map +1 -0
  56. package/dist/src/governor/human-touchpoints.js +251 -0
  57. package/dist/src/governor/human-touchpoints.test.d.ts +2 -0
  58. package/dist/src/governor/human-touchpoints.test.d.ts.map +1 -0
  59. package/dist/src/governor/human-touchpoints.test.js +366 -0
  60. package/dist/src/governor/in-memory-event-bus.d.ts +29 -0
  61. package/dist/src/governor/in-memory-event-bus.d.ts.map +1 -0
  62. package/dist/src/governor/in-memory-event-bus.js +79 -0
  63. package/dist/src/governor/index.d.ts +14 -0
  64. package/dist/src/governor/index.d.ts.map +1 -0
  65. package/dist/src/governor/index.js +13 -0
  66. package/dist/src/governor/override-parser.d.ts +60 -0
  67. package/dist/src/governor/override-parser.d.ts.map +1 -0
  68. package/dist/src/governor/override-parser.js +98 -0
  69. package/dist/src/governor/override-parser.test.d.ts +2 -0
  70. package/dist/src/governor/override-parser.test.d.ts.map +1 -0
  71. package/dist/src/governor/override-parser.test.js +312 -0
  72. package/dist/src/governor/platform-adapter.d.ts +69 -0
  73. package/dist/src/governor/platform-adapter.d.ts.map +1 -0
  74. package/dist/src/governor/platform-adapter.js +11 -0
  75. package/dist/src/governor/processing-state.d.ts +66 -0
  76. package/dist/src/governor/processing-state.d.ts.map +1 -0
  77. package/dist/src/governor/processing-state.js +43 -0
  78. package/dist/src/governor/processing-state.test.d.ts +2 -0
  79. package/dist/src/governor/processing-state.test.d.ts.map +1 -0
  80. package/dist/src/governor/processing-state.test.js +96 -0
  81. package/dist/src/governor/top-of-funnel.d.ts +118 -0
  82. package/dist/src/governor/top-of-funnel.d.ts.map +1 -0
  83. package/dist/src/governor/top-of-funnel.js +168 -0
  84. package/dist/src/governor/top-of-funnel.test.d.ts +2 -0
  85. package/dist/src/governor/top-of-funnel.test.d.ts.map +1 -0
  86. package/dist/src/governor/top-of-funnel.test.js +331 -0
  87. package/dist/src/index.d.ts +11 -0
  88. package/dist/src/index.d.ts.map +1 -0
  89. package/dist/src/index.js +10 -0
  90. package/dist/src/linear-cli.d.ts +38 -0
  91. package/dist/src/linear-cli.d.ts.map +1 -0
  92. package/dist/src/linear-cli.js +674 -0
  93. package/dist/src/logger.d.ts +117 -0
  94. package/dist/src/logger.d.ts.map +1 -0
  95. package/dist/src/logger.js +430 -0
  96. package/dist/src/manifest/generate.d.ts +20 -0
  97. package/dist/src/manifest/generate.d.ts.map +1 -0
  98. package/dist/src/manifest/generate.js +65 -0
  99. package/dist/src/manifest/index.d.ts +4 -0
  100. package/dist/src/manifest/index.d.ts.map +1 -0
  101. package/dist/src/manifest/index.js +2 -0
  102. package/dist/src/manifest/route-manifest.d.ts +34 -0
  103. package/dist/src/manifest/route-manifest.d.ts.map +1 -0
  104. package/dist/src/manifest/route-manifest.js +148 -0
  105. package/dist/src/orchestrator/activity-emitter.d.ts +119 -0
  106. package/dist/src/orchestrator/activity-emitter.d.ts.map +1 -0
  107. package/dist/src/orchestrator/activity-emitter.js +306 -0
  108. package/dist/src/orchestrator/api-activity-emitter.d.ts +167 -0
  109. package/dist/src/orchestrator/api-activity-emitter.d.ts.map +1 -0
  110. package/dist/src/orchestrator/api-activity-emitter.js +417 -0
  111. package/dist/src/orchestrator/heartbeat-writer.d.ts +57 -0
  112. package/dist/src/orchestrator/heartbeat-writer.d.ts.map +1 -0
  113. package/dist/src/orchestrator/heartbeat-writer.js +137 -0
  114. package/dist/src/orchestrator/index.d.ts +20 -0
  115. package/dist/src/orchestrator/index.d.ts.map +1 -0
  116. package/dist/src/orchestrator/index.js +22 -0
  117. package/dist/src/orchestrator/log-analyzer.d.ts +160 -0
  118. package/dist/src/orchestrator/log-analyzer.d.ts.map +1 -0
  119. package/dist/src/orchestrator/log-analyzer.js +572 -0
  120. package/dist/src/orchestrator/log-config.d.ts +39 -0
  121. package/dist/src/orchestrator/log-config.d.ts.map +1 -0
  122. package/dist/src/orchestrator/log-config.js +45 -0
  123. package/dist/src/orchestrator/orchestrator.d.ts +316 -0
  124. package/dist/src/orchestrator/orchestrator.d.ts.map +1 -0
  125. package/dist/src/orchestrator/orchestrator.js +3290 -0
  126. package/dist/src/orchestrator/parse-work-result.d.ts +16 -0
  127. package/dist/src/orchestrator/parse-work-result.d.ts.map +1 -0
  128. package/dist/src/orchestrator/parse-work-result.js +135 -0
  129. package/dist/src/orchestrator/parse-work-result.test.d.ts +2 -0
  130. package/dist/src/orchestrator/parse-work-result.test.d.ts.map +1 -0
  131. package/dist/src/orchestrator/parse-work-result.test.js +234 -0
  132. package/dist/src/orchestrator/progress-logger.d.ts +72 -0
  133. package/dist/src/orchestrator/progress-logger.d.ts.map +1 -0
  134. package/dist/src/orchestrator/progress-logger.js +135 -0
  135. package/dist/src/orchestrator/session-logger.d.ts +159 -0
  136. package/dist/src/orchestrator/session-logger.d.ts.map +1 -0
  137. package/dist/src/orchestrator/session-logger.js +275 -0
  138. package/dist/src/orchestrator/state-recovery.d.ts +96 -0
  139. package/dist/src/orchestrator/state-recovery.d.ts.map +1 -0
  140. package/dist/src/orchestrator/state-recovery.js +302 -0
  141. package/dist/src/orchestrator/state-types.d.ts +165 -0
  142. package/dist/src/orchestrator/state-types.d.ts.map +1 -0
  143. package/dist/src/orchestrator/state-types.js +7 -0
  144. package/dist/src/orchestrator/stream-parser.d.ts +151 -0
  145. package/dist/src/orchestrator/stream-parser.d.ts.map +1 -0
  146. package/dist/src/orchestrator/stream-parser.js +137 -0
  147. package/dist/src/orchestrator/types.d.ts +232 -0
  148. package/dist/src/orchestrator/types.d.ts.map +1 -0
  149. package/dist/src/orchestrator/types.js +4 -0
  150. package/dist/src/orchestrator/validate-git-remote.test.d.ts +2 -0
  151. package/dist/src/orchestrator/validate-git-remote.test.d.ts.map +1 -0
  152. package/dist/src/orchestrator/validate-git-remote.test.js +61 -0
  153. package/dist/src/providers/a2a-auth.d.ts +81 -0
  154. package/dist/src/providers/a2a-auth.d.ts.map +1 -0
  155. package/dist/src/providers/a2a-auth.js +188 -0
  156. package/dist/src/providers/a2a-auth.test.d.ts +2 -0
  157. package/dist/src/providers/a2a-auth.test.d.ts.map +1 -0
  158. package/dist/src/providers/a2a-auth.test.js +232 -0
  159. package/dist/src/providers/a2a-provider.d.ts +254 -0
  160. package/dist/src/providers/a2a-provider.d.ts.map +1 -0
  161. package/dist/src/providers/a2a-provider.integration.test.d.ts +9 -0
  162. package/dist/src/providers/a2a-provider.integration.test.d.ts.map +1 -0
  163. package/dist/src/providers/a2a-provider.integration.test.js +665 -0
  164. package/dist/src/providers/a2a-provider.js +811 -0
  165. package/dist/src/providers/a2a-provider.test.d.ts +2 -0
  166. package/dist/src/providers/a2a-provider.test.d.ts.map +1 -0
  167. package/dist/src/providers/a2a-provider.test.js +681 -0
  168. package/dist/src/providers/amp-provider.d.ts +20 -0
  169. package/dist/src/providers/amp-provider.d.ts.map +1 -0
  170. package/dist/src/providers/amp-provider.js +24 -0
  171. package/dist/src/providers/claude-provider.d.ts +18 -0
  172. package/dist/src/providers/claude-provider.d.ts.map +1 -0
  173. package/dist/src/providers/claude-provider.js +437 -0
  174. package/dist/src/providers/codex-provider.d.ts +133 -0
  175. package/dist/src/providers/codex-provider.d.ts.map +1 -0
  176. package/dist/src/providers/codex-provider.js +381 -0
  177. package/dist/src/providers/codex-provider.test.d.ts +2 -0
  178. package/dist/src/providers/codex-provider.test.d.ts.map +1 -0
  179. package/dist/src/providers/codex-provider.test.js +387 -0
  180. package/dist/src/providers/index.d.ts +44 -0
  181. package/dist/src/providers/index.d.ts.map +1 -0
  182. package/dist/src/providers/index.js +85 -0
  183. package/dist/src/providers/spring-ai-provider.d.ts +90 -0
  184. package/dist/src/providers/spring-ai-provider.d.ts.map +1 -0
  185. package/dist/src/providers/spring-ai-provider.integration.test.d.ts +13 -0
  186. package/dist/src/providers/spring-ai-provider.integration.test.d.ts.map +1 -0
  187. package/dist/src/providers/spring-ai-provider.integration.test.js +351 -0
  188. package/dist/src/providers/spring-ai-provider.js +317 -0
  189. package/dist/src/providers/spring-ai-provider.test.d.ts +2 -0
  190. package/dist/src/providers/spring-ai-provider.test.d.ts.map +1 -0
  191. package/dist/src/providers/spring-ai-provider.test.js +200 -0
  192. package/dist/src/providers/types.d.ts +165 -0
  193. package/dist/src/providers/types.d.ts.map +1 -0
  194. package/dist/src/providers/types.js +13 -0
  195. package/dist/src/templates/adapters.d.ts +51 -0
  196. package/dist/src/templates/adapters.d.ts.map +1 -0
  197. package/dist/src/templates/adapters.js +104 -0
  198. package/dist/src/templates/adapters.test.d.ts +2 -0
  199. package/dist/src/templates/adapters.test.d.ts.map +1 -0
  200. package/dist/src/templates/adapters.test.js +165 -0
  201. package/dist/src/templates/agent-definition.d.ts +85 -0
  202. package/dist/src/templates/agent-definition.d.ts.map +1 -0
  203. package/dist/src/templates/agent-definition.js +97 -0
  204. package/dist/src/templates/agent-definition.test.d.ts +2 -0
  205. package/dist/src/templates/agent-definition.test.d.ts.map +1 -0
  206. package/dist/src/templates/agent-definition.test.js +209 -0
  207. package/dist/src/templates/index.d.ts +14 -0
  208. package/dist/src/templates/index.d.ts.map +1 -0
  209. package/dist/src/templates/index.js +11 -0
  210. package/dist/src/templates/loader.d.ts +41 -0
  211. package/dist/src/templates/loader.d.ts.map +1 -0
  212. package/dist/src/templates/loader.js +114 -0
  213. package/dist/src/templates/registry.d.ts +80 -0
  214. package/dist/src/templates/registry.d.ts.map +1 -0
  215. package/dist/src/templates/registry.js +177 -0
  216. package/dist/src/templates/registry.test.d.ts +2 -0
  217. package/dist/src/templates/registry.test.d.ts.map +1 -0
  218. package/dist/src/templates/registry.test.js +198 -0
  219. package/dist/src/templates/renderer.d.ts +29 -0
  220. package/dist/src/templates/renderer.d.ts.map +1 -0
  221. package/dist/src/templates/renderer.js +35 -0
  222. package/dist/src/templates/strategy-templates.test.d.ts +2 -0
  223. package/dist/src/templates/strategy-templates.test.d.ts.map +1 -0
  224. package/dist/src/templates/strategy-templates.test.js +619 -0
  225. package/dist/src/templates/types.d.ts +233 -0
  226. package/dist/src/templates/types.d.ts.map +1 -0
  227. package/dist/src/templates/types.js +127 -0
  228. package/dist/src/templates/types.test.d.ts +2 -0
  229. package/dist/src/templates/types.test.d.ts.map +1 -0
  230. package/dist/src/templates/types.test.js +232 -0
  231. package/dist/src/tools/index.d.ts +6 -0
  232. package/dist/src/tools/index.d.ts.map +1 -0
  233. package/dist/src/tools/index.js +3 -0
  234. package/dist/src/tools/linear-runner.d.ts +34 -0
  235. package/dist/src/tools/linear-runner.d.ts.map +1 -0
  236. package/dist/src/tools/linear-runner.js +700 -0
  237. package/dist/src/tools/plugins/linear.d.ts +9 -0
  238. package/dist/src/tools/plugins/linear.d.ts.map +1 -0
  239. package/dist/src/tools/plugins/linear.js +138 -0
  240. package/dist/src/tools/registry.d.ts +9 -0
  241. package/dist/src/tools/registry.d.ts.map +1 -0
  242. package/dist/src/tools/registry.js +18 -0
  243. package/dist/src/tools/types.d.ts +18 -0
  244. package/dist/src/tools/types.d.ts.map +1 -0
  245. package/dist/src/tools/types.js +1 -0
  246. package/package.json +78 -0
@@ -0,0 +1,316 @@
1
+ /**
2
+ * Agent Orchestrator
3
+ * Spawns concurrent Claude agents to work on Linear backlog issues
4
+ * Uses the Claude Agent SDK for programmatic control
5
+ */
6
+ import { type AgentWorkType } from '@renseiai/agentfactory-linear';
7
+ import type { OrchestratorConfig, OrchestratorIssue, AgentProcess, OrchestratorEvents, SpawnAgentOptions, OrchestratorResult, StopAgentResult, ForwardPromptResult, InjectMessageResult, SpawnAgentWithResumeOptions } from './types.js';
8
+ /**
9
+ * Validate that the git remote origin URL contains the expected repository pattern.
10
+ * Supports both HTTPS (github.com/org/repo) and SSH (git@github.com:org/repo) formats.
11
+ *
12
+ * @param expectedRepo - The expected repository pattern (e.g. 'github.com/renseiai/agentfactory')
13
+ * @param cwd - Working directory to run git commands in
14
+ * @throws Error if the git remote does not match the expected repository
15
+ */
16
+ export declare function validateGitRemote(expectedRepo: string, cwd?: string): void;
17
+ /**
18
+ * Generate a worktree identifier that includes the work type suffix
19
+ *
20
+ * @param issueIdentifier - Issue identifier (e.g., "SUP-294")
21
+ * @param workType - Type of work being performed
22
+ * @returns Worktree identifier with suffix (e.g., "SUP-294-QA")
23
+ */
24
+ export declare function getWorktreeIdentifier(issueIdentifier: string, workType: AgentWorkType): string;
25
+ export declare class AgentOrchestrator {
26
+ private readonly config;
27
+ private readonly client;
28
+ private readonly events;
29
+ private readonly activeAgents;
30
+ private readonly agentHandles;
31
+ private provider;
32
+ private readonly agentSessions;
33
+ private readonly activityEmitters;
34
+ private readonly sessionToIssue;
35
+ private readonly abortControllers;
36
+ private readonly agentLoggers;
37
+ private readonly heartbeatWriters;
38
+ private readonly progressLoggers;
39
+ private readonly sessionLoggers;
40
+ private readonly templateRegistry;
41
+ private allowedProjects?;
42
+ private projectPaths?;
43
+ private sharedPaths?;
44
+ private linearCli?;
45
+ private packageManager?;
46
+ private buildCommand?;
47
+ private testCommand?;
48
+ private validateCommand?;
49
+ private readonly toolRegistry;
50
+ constructor(config?: OrchestratorConfig, events?: OrchestratorEvents);
51
+ /**
52
+ * Update the last activity timestamp for an agent (for inactivity timeout tracking)
53
+ * @param issueId - The issue ID of the agent
54
+ * @param activityType - Optional description of the activity type
55
+ */
56
+ private updateLastActivity;
57
+ /**
58
+ * Get timeout configuration for a specific work type
59
+ * @param workType - The work type to get timeout config for
60
+ * @returns Timeout configuration with inactivity and max session values
61
+ */
62
+ private getTimeoutConfig;
63
+ /**
64
+ * Get backlog issues for the configured project
65
+ */
66
+ getBacklogIssues(limit?: number): Promise<OrchestratorIssue[]>;
67
+ /**
68
+ * Validate that a path is a valid git worktree
69
+ */
70
+ private validateWorktree;
71
+ /**
72
+ * Extract the full error message from an execSync error.
73
+ *
74
+ * Node's execSync throws an Error where .message only contains
75
+ * "Command failed: <command>", but the actual git error output
76
+ * is in .stderr. This helper combines both for reliable pattern matching.
77
+ */
78
+ private getExecSyncErrorMessage;
79
+ /**
80
+ * Check if a git error indicates a branch/worktree conflict.
81
+ *
82
+ * Git uses different error messages depending on the situation:
83
+ * - "is already checked out at '/path'" - branch checked out in another worktree
84
+ * - "is already used by worktree at '/path'" - branch associated with another worktree
85
+ *
86
+ * Both mean the same thing: the branch is occupied by another worktree.
87
+ */
88
+ private isBranchConflictError;
89
+ /**
90
+ * Extract the conflicting worktree path from a git branch conflict error.
91
+ *
92
+ * Parses paths like:
93
+ * - "fatal: 'SUP-402' is already checked out at '/path/to/.worktrees/SUP-402-DEV'"
94
+ * - "fatal: 'SUP-402' is already used by worktree at '/path/to/.worktrees/SUP-402-DEV'"
95
+ */
96
+ private parseConflictingWorktreePath;
97
+ /**
98
+ * Check if a path is the main git working tree (not a worktree).
99
+ *
100
+ * The main working tree has a `.git` directory, while worktrees have a
101
+ * `.git` file containing a `gitdir:` pointer. This is the primary safeguard
102
+ * against accidentally destroying the main repository.
103
+ */
104
+ private isMainWorktree;
105
+ /**
106
+ * Check if a path is inside the configured .worktrees/ directory.
107
+ *
108
+ * Only paths within the worktrees directory should ever be candidates for
109
+ * automated cleanup. This prevents the main repo or other directories from
110
+ * being targeted.
111
+ */
112
+ private isInsideWorktreesDir;
113
+ /**
114
+ * Attempt to clean up a stale worktree that is blocking branch creation.
115
+ *
116
+ * During dev\u2192qa\u2192acceptance handoffs, the prior work type's worktree may still
117
+ * exist after its agent has finished (the orchestrator cleans up externally,
118
+ * but there's a race window). This method checks if the blocking worktree's
119
+ * agent is still alive via heartbeat. If not, it removes the stale worktree
120
+ * so the new work type can proceed.
121
+ *
122
+ * SAFETY: This method will NEVER clean up the main working tree. It only
123
+ * operates on paths inside the .worktrees/ directory. This prevents
124
+ * catastrophic data loss when a branch is checked out in the main tree
125
+ * (e.g., by a user in their IDE).
126
+ *
127
+ * @returns true if the conflicting worktree was cleaned up
128
+ */
129
+ private tryCleanupConflictingWorktree;
130
+ /**
131
+ * Handle a branch conflict error by attempting to clean up the stale worktree
132
+ * and retrying, or throwing a retriable error for the worker's retry loop.
133
+ */
134
+ private handleBranchConflict;
135
+ /**
136
+ * Create a git worktree for an issue with work type suffix
137
+ *
138
+ * @param issueIdentifier - Issue identifier (e.g., "SUP-294")
139
+ * @param workType - Type of work being performed
140
+ * @returns Object containing worktreePath and worktreeIdentifier
141
+ */
142
+ createWorktree(issueIdentifier: string, workType: AgentWorkType): {
143
+ worktreePath: string;
144
+ worktreeIdentifier: string;
145
+ };
146
+ /**
147
+ * Clean up a git worktree
148
+ *
149
+ * @param worktreeIdentifier - Worktree identifier with work type suffix (e.g., "SUP-294-QA")
150
+ */
151
+ removeWorktree(worktreeIdentifier: string): void;
152
+ /**
153
+ * Write helper scripts into the worktree's .agent/ directory.
154
+ *
155
+ * Currently writes:
156
+ * - .agent/add-dep.sh: Safely adds a new dependency by removing symlinked
157
+ * node_modules first, then running `pnpm add` with the guard bypass.
158
+ */
159
+ private writeWorktreeHelpers;
160
+ /**
161
+ * Link dependencies from the main repo into a worktree via symlinks.
162
+ *
163
+ * Creates a REAL node_modules directory in the worktree and symlinks each
164
+ * entry (packages, .pnpm, .bin) individually. This prevents pnpm from
165
+ * resolving through a directory-level symlink and corrupting the main
166
+ * repo's node_modules when an agent accidentally runs `pnpm install`.
167
+ *
168
+ * For non-Node repos (no node_modules in main repo), this is a no-op.
169
+ *
170
+ * Falls back to `pnpm install --frozen-lockfile` if symlinking fails.
171
+ */
172
+ linkDependencies(worktreePath: string, identifier: string): void;
173
+ /**
174
+ * Create a real node_modules directory and symlink each entry from the source.
175
+ *
176
+ * Instead of symlinking the entire node_modules directory (which lets pnpm
177
+ * resolve through the symlink and corrupt the original), we create a real
178
+ * directory and symlink each entry individually. If pnpm "recreates" this
179
+ * directory, it only destroys the worktree's symlinks — not the originals.
180
+ */
181
+ private linkNodeModulesContents;
182
+ /**
183
+ * Fallback: install dependencies via pnpm install.
184
+ * Only called when symlinking fails.
185
+ */
186
+ private installDependencies;
187
+ /**
188
+ * @deprecated Use linkDependencies() instead. This now delegates to linkDependencies.
189
+ */
190
+ preInstallDependencies(worktreePath: string, identifier: string): void;
191
+ /**
192
+ * Spawn a Claude agent for a specific issue using the Agent SDK
193
+ */
194
+ spawnAgent(options: SpawnAgentOptions): AgentProcess;
195
+ /**
196
+ * Process the provider event stream and emit activities
197
+ */
198
+ private processEventStream;
199
+ /**
200
+ * Handle a single normalized agent event from any provider
201
+ */
202
+ private handleAgentEvent;
203
+ /**
204
+ * Extract GitHub PR URL from text (typically from gh pr create output)
205
+ */
206
+ private extractPullRequestUrl;
207
+ /**
208
+ * Update the Linear session with the PR URL
209
+ */
210
+ private updateSessionPullRequest;
211
+ /**
212
+ * Post completion comment with full result message
213
+ * Uses multi-comment splitting for long messages (up to 10 comments, 10k chars each)
214
+ */
215
+ private postCompletionComment;
216
+ /**
217
+ * Clean up agent resources
218
+ */
219
+ private cleanupAgent;
220
+ /**
221
+ * Finalize the session logger with final status
222
+ */
223
+ private finalizeSessionLogger;
224
+ /**
225
+ * Run the orchestrator - spawn agents for backlog issues
226
+ */
227
+ run(): Promise<OrchestratorResult>;
228
+ /**
229
+ * Spawn agent for a single issue (webhook-triggered or CLI)
230
+ * Generates a session ID if not provided to enable autonomous mode
231
+ *
232
+ * This method includes crash recovery support:
233
+ * - If a worktree exists with valid state and stale heartbeat, triggers recovery
234
+ * - If a worktree exists with fresh heartbeat (agent alive), throws error to prevent duplicates
235
+ *
236
+ * @param issueIdOrIdentifier - Issue ID or identifier (e.g., SUP-123)
237
+ * @param sessionId - Optional Linear session ID
238
+ * @param workType - Optional work type (auto-detected from issue status if not provided)
239
+ * @param prompt - Optional custom prompt override
240
+ */
241
+ spawnAgentForIssue(issueIdOrIdentifier: string, sessionId?: string, workType?: AgentWorkType, prompt?: string): Promise<AgentProcess>;
242
+ /**
243
+ * Get all active agents
244
+ */
245
+ getActiveAgents(): AgentProcess[];
246
+ /**
247
+ * Stop a running agent by issue ID
248
+ * @param issueId - The Linear issue ID
249
+ * @param cleanupWorktree - Whether to remove the git worktree
250
+ * @param stopReason - Why the agent is being stopped: 'user_request' or 'timeout'
251
+ */
252
+ stopAgent(issueId: string, cleanupWorktree?: boolean, stopReason?: 'user_request' | 'timeout'): Promise<StopAgentResult>;
253
+ /**
254
+ * Stop a running agent by session ID
255
+ */
256
+ stopAgentBySession(sessionId: string, cleanupWorktree?: boolean): Promise<StopAgentResult>;
257
+ /**
258
+ * Get agent by session ID
259
+ */
260
+ getAgentBySession(sessionId: string): AgentProcess | undefined;
261
+ /**
262
+ * Update the worker ID for all active activity emitters.
263
+ * Called after worker re-registration to ensure activities are attributed
264
+ * to the new worker ID and pass ownership checks.
265
+ *
266
+ * @param newWorkerId - The new worker ID after re-registration
267
+ */
268
+ updateWorkerId(newWorkerId: string): void;
269
+ /**
270
+ * Forward a follow-up prompt to an existing or new agent
271
+ *
272
+ * If the agent is running, attempts to inject the message into the running session
273
+ * without stopping it. If injection fails or agent isn't running, it will be
274
+ * stopped gracefully and resumed with the new prompt.
275
+ *
276
+ * @param workType - Optional work type. If not provided, inherits from existing agent or defaults to 'development'.
277
+ */
278
+ forwardPrompt(issueId: string, sessionId: string, prompt: string, providerSessionId?: string, workType?: AgentWorkType): Promise<ForwardPromptResult>;
279
+ /**
280
+ * Inject a user message into a running agent session without stopping it.
281
+ *
282
+ * Uses the SDK's streamInput() method to send follow-up messages to a running session.
283
+ * This is the preferred method for user follow-ups as it doesn't interrupt agent work.
284
+ *
285
+ * @param issueId - The issue ID the agent is working on
286
+ * @param sessionId - The Linear session ID
287
+ * @param message - The user message to inject
288
+ * @returns Result indicating if injection was successful
289
+ */
290
+ injectMessage(issueId: string, sessionId: string, message: string): Promise<InjectMessageResult>;
291
+ /**
292
+ * Spawn an agent with resume capability for continuing a previous session
293
+ * If autoTransition is enabled, also transitions the issue status to the appropriate working state
294
+ */
295
+ spawnAgentWithResume(options: SpawnAgentWithResumeOptions): Promise<AgentProcess>;
296
+ /**
297
+ * Stop all running agents
298
+ */
299
+ stopAll(): void;
300
+ /**
301
+ * Wait for all agents to complete with inactivity-based timeout
302
+ *
303
+ * Unlike a simple session timeout, this method monitors each agent's activity
304
+ * and only stops agents that have been inactive for longer than the inactivity
305
+ * timeout. Active agents are allowed to run indefinitely (unless maxSessionTimeoutMs
306
+ * is set as a hard cap).
307
+ *
308
+ * @param inactivityTimeoutMsOverride - Override inactivity timeout from config (for backwards compatibility)
309
+ */
310
+ waitForAll(inactivityTimeoutMsOverride?: number): Promise<AgentProcess[]>;
311
+ }
312
+ /**
313
+ * Create an orchestrator instance
314
+ */
315
+ export declare function createOrchestrator(config?: OrchestratorConfig, events?: OrchestratorEvents): AgentOrchestrator;
316
+ //# sourceMappingURL=orchestrator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orchestrator.d.ts","sourceRoot":"","sources":["../../../src/orchestrator/orchestrator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA+BH,OAAO,EAML,KAAK,aAAa,EAQnB,MAAM,+BAA+B,CAAA;AAStC,OAAO,KAAK,EACV,kBAAkB,EAClB,iBAAiB,EACjB,Y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