codekin 0.5.4 → 0.6.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 (88) hide show
  1. package/README.md +1 -0
  2. package/dist/assets/index-BvKzbtKg.css +1 -0
  3. package/dist/assets/index-D59Xr9pK.js +182 -0
  4. package/dist/index.html +2 -2
  5. package/package.json +1 -1
  6. package/server/dist/approval-manager.js +2 -3
  7. package/server/dist/approval-manager.js.map +1 -1
  8. package/server/dist/claude-process.d.ts +17 -5
  9. package/server/dist/claude-process.js +56 -66
  10. package/server/dist/claude-process.js.map +1 -1
  11. package/server/dist/coding-process.d.ts +83 -0
  12. package/server/dist/coding-process.js +32 -0
  13. package/server/dist/coding-process.js.map +1 -0
  14. package/server/dist/commit-event-handler.js +1 -0
  15. package/server/dist/commit-event-handler.js.map +1 -1
  16. package/server/dist/config.js +2 -1
  17. package/server/dist/config.js.map +1 -1
  18. package/server/dist/docs-routes.js +22 -1
  19. package/server/dist/docs-routes.js.map +1 -1
  20. package/server/dist/native-permissions.js +3 -2
  21. package/server/dist/native-permissions.js.map +1 -1
  22. package/server/dist/opencode-process.d.ts +104 -0
  23. package/server/dist/opencode-process.js +657 -0
  24. package/server/dist/opencode-process.js.map +1 -0
  25. package/server/dist/orchestrator-children.d.ts +9 -0
  26. package/server/dist/orchestrator-children.js +50 -7
  27. package/server/dist/orchestrator-children.js.map +1 -1
  28. package/server/dist/orchestrator-manager.js +17 -0
  29. package/server/dist/orchestrator-manager.js.map +1 -1
  30. package/server/dist/orchestrator-reports.d.ts +0 -4
  31. package/server/dist/orchestrator-reports.js +6 -12
  32. package/server/dist/orchestrator-reports.js.map +1 -1
  33. package/server/dist/orchestrator-routes.js +8 -1
  34. package/server/dist/orchestrator-routes.js.map +1 -1
  35. package/server/dist/prompt-router.d.ts +95 -0
  36. package/server/dist/prompt-router.js +589 -0
  37. package/server/dist/prompt-router.js.map +1 -0
  38. package/server/dist/session-lifecycle.d.ts +73 -0
  39. package/server/dist/session-lifecycle.js +408 -0
  40. package/server/dist/session-lifecycle.js.map +1 -0
  41. package/server/dist/session-manager.d.ts +42 -60
  42. package/server/dist/session-manager.js +310 -835
  43. package/server/dist/session-manager.js.map +1 -1
  44. package/server/dist/session-persistence.d.ts +1 -0
  45. package/server/dist/session-persistence.js +24 -4
  46. package/server/dist/session-persistence.js.map +1 -1
  47. package/server/dist/session-routes.js +15 -1
  48. package/server/dist/session-routes.js.map +1 -1
  49. package/server/dist/stepflow-handler.d.ts +2 -2
  50. package/server/dist/stepflow-handler.js +4 -4
  51. package/server/dist/stepflow-handler.js.map +1 -1
  52. package/server/dist/tool-labels.d.ts +8 -0
  53. package/server/dist/tool-labels.js +51 -0
  54. package/server/dist/tool-labels.js.map +1 -0
  55. package/server/dist/tsconfig.tsbuildinfo +1 -1
  56. package/server/dist/types.d.ts +27 -8
  57. package/server/dist/types.js +4 -1
  58. package/server/dist/types.js.map +1 -1
  59. package/server/dist/webhook-dedup.d.ts +11 -0
  60. package/server/dist/webhook-dedup.js +23 -0
  61. package/server/dist/webhook-dedup.js.map +1 -1
  62. package/server/dist/webhook-handler.d.ts +20 -4
  63. package/server/dist/webhook-handler.js +256 -20
  64. package/server/dist/webhook-handler.js.map +1 -1
  65. package/server/dist/webhook-pr-cache.d.ts +57 -0
  66. package/server/dist/webhook-pr-cache.js +95 -0
  67. package/server/dist/webhook-pr-cache.js.map +1 -0
  68. package/server/dist/webhook-pr-github.d.ts +68 -0
  69. package/server/dist/webhook-pr-github.js +202 -0
  70. package/server/dist/webhook-pr-github.js.map +1 -0
  71. package/server/dist/webhook-pr-prompt.d.ts +27 -0
  72. package/server/dist/webhook-pr-prompt.js +251 -0
  73. package/server/dist/webhook-pr-prompt.js.map +1 -0
  74. package/server/dist/webhook-types.d.ts +70 -1
  75. package/server/dist/webhook-workspace.js +20 -1
  76. package/server/dist/webhook-workspace.js.map +1 -1
  77. package/server/dist/workflow-config.d.ts +2 -0
  78. package/server/dist/workflow-config.js.map +1 -1
  79. package/server/dist/workflow-loader.js +3 -0
  80. package/server/dist/workflow-loader.js.map +1 -1
  81. package/server/dist/workflow-routes.js +6 -2
  82. package/server/dist/workflow-routes.js.map +1 -1
  83. package/server/dist/ws-message-handler.js +24 -4
  84. package/server/dist/ws-message-handler.js.map +1 -1
  85. package/server/dist/ws-server.js +10 -2
  86. package/server/dist/ws-server.js.map +1 -1
  87. package/dist/assets/index-COGLICp9.js +0 -178
  88. package/dist/assets/index-CjEQkT2b.css +0 -1
@@ -15,12 +15,15 @@
15
15
  * - SessionNaming: AI-powered session name generation with retry logic
16
16
  * - SessionPersistence: disk I/O for session state
17
17
  * - DiffManager: stateless git-diff operations
18
- * - evaluateRestart: pure restart-decision logic
18
+ * - SessionLifecycle: Claude process start/stop/restart and event wiring
19
+ * - evaluateRestart: pure restart-decision logic (used by SessionLifecycle)
19
20
  */
20
21
  import type { WebSocket } from 'ws';
22
+ import type { CodingProvider } from './coding-process.js';
21
23
  import { SessionArchive } from './session-archive.js';
22
24
  import type { DiffFileStatus, DiffScope, Session, SessionInfo, WsServerMessage } from './types.js';
23
25
  import { ApprovalManager } from './approval-manager.js';
26
+ import { SessionLifecycle } from './session-lifecycle.js';
24
27
  export interface CreateSessionOptions {
25
28
  source?: 'manual' | 'webhook' | 'workflow' | 'stepflow' | 'orchestrator' | 'agent';
26
29
  id?: string;
@@ -32,6 +35,10 @@ export interface CreateSessionOptions {
32
35
  permissionMode?: import('./types.js').PermissionMode;
33
36
  /** Additional tools to pre-approve via --allowedTools (e.g. 'Bash(curl:*)', 'WebFetch'). */
34
37
  allowedTools?: string[];
38
+ /** Extra directories to grant Claude access to via --add-dir. */
39
+ addDirs?: string[];
40
+ /** AI provider to use for this session. Defaults to 'claude'. */
41
+ provider?: import('./coding-process.js').CodingProvider;
35
42
  }
36
43
  export declare class SessionManager {
37
44
  /** All active (non-archived) sessions, keyed by session UUID. */
@@ -60,6 +67,10 @@ export declare class SessionManager {
60
67
  private sessionPersistence;
61
68
  /** Delegated diff operations (git diff, discard changes). */
62
69
  private diffManager;
70
+ /** Delegated prompt routing and tool approval logic. */
71
+ private promptRouter;
72
+ /** Delegated Claude process lifecycle (start, stop, restart, event wiring). */
73
+ private sessionLifecycle;
63
74
  /** Interval handle for the idle session reaper. */
64
75
  private _idleReaperInterval;
65
76
  constructor();
@@ -86,8 +97,16 @@ export declare class SessionManager {
86
97
  * Create a git worktree for a session. Creates a new branch and worktree
87
98
  * as a sibling directory of the project root.
88
99
  * Returns the worktree path on success, or null on failure.
100
+ *
101
+ * @param targetBranch — use this as the worktree branch name instead of
102
+ * the default `wt/{shortId}`. The orchestrator uses this to create the
103
+ * worktree directly on the desired feature branch so Claude doesn't
104
+ * need to create a second branch.
105
+ * @param baseBranch — create the worktree branch from this ref (e.g.
106
+ * 'main'). Defaults to auto-detecting the default branch. Prevents
107
+ * worktrees from accidentally branching off a random HEAD.
89
108
  */
90
- createWorktree(sessionId: string, workingDir: string): Promise<string | null>;
109
+ createWorktree(sessionId: string, workingDir: string, targetBranch?: string, baseBranch?: string): Promise<string | null>;
91
110
  /**
92
111
  * Resolve the Claude CLI project storage directory for a given working dir.
93
112
  * Claude encodes the absolute path by replacing `/` with `-`.
@@ -106,8 +125,15 @@ export declare class SessionManager {
106
125
  /**
107
126
  * Clean up a git worktree and its branch. Runs asynchronously and logs errors
108
127
  * but never throws — session deletion must not be blocked by cleanup failures.
128
+ * Retries once on failure after a short delay.
109
129
  */
110
130
  private cleanupWorktree;
131
+ /**
132
+ * Detect the default branch of a repository (main, master, etc.).
133
+ * Tries `git symbolic-ref refs/remotes/origin/HEAD` first, then checks
134
+ * for common branch names. Returns null if detection fails.
135
+ */
136
+ private detectDefaultBranch;
111
137
  /** Get the configured worktree branch prefix (defaults to 'wt/'). */
112
138
  getWorktreeBranchPrefix(): string;
113
139
  /** Set the worktree branch prefix. */
@@ -134,6 +160,7 @@ export declare class SessionManager {
134
160
  }>;
135
161
  /** Clear the isProcessing flag for a session and broadcast the update. */
136
162
  clearProcessingFlag(sessionId: string): void;
163
+ private serializeSession;
137
164
  list(): SessionInfo[];
138
165
  /** List ALL sessions including orchestrator — used by orchestrator cleanup endpoints. */
139
166
  listAll(): SessionInfo[];
@@ -152,21 +179,14 @@ export declare class SessionManager {
152
179
  private archiveSessionIfWorthSaving;
153
180
  /**
154
181
  * Spawn (or re-spawn) a Claude CLI process for a session.
155
- * Wires up all event handlers for streaming text, tools, prompts, and auto-restart.
182
+ * Delegates to SessionLifecycle.
156
183
  */
157
184
  startClaude(sessionId: string): boolean;
158
185
  /**
159
- * Wait for a session's Claude process to emit its system_init event,
160
- * indicating it is ready to accept input. Resolves immediately if the
161
- * session already has a claudeSessionId (process previously initialized).
162
- * Times out after `timeoutMs` (default 30s) to avoid hanging indefinitely.
186
+ * Wait for a session's Claude process to emit its system_init event.
187
+ * Delegates to SessionLifecycle.
163
188
  */
164
189
  waitForReady(sessionId: string, timeoutMs?: number): Promise<void>;
165
- /**
166
- * Attach all ClaudeProcess event listeners for a session.
167
- * Extracted from startClaude() to keep that method focused on process setup.
168
- */
169
- private wireClaudeEvents;
170
190
  /** Broadcast a message and add it to the session's output history. */
171
191
  private broadcastAndHistory;
172
192
  /**
@@ -182,8 +202,6 @@ export declare class SessionManager {
182
202
  private onImageEvent;
183
203
  private onToolActiveEvent;
184
204
  private onToolDoneEvent;
185
- private onPromptEvent;
186
- private onControlRequestEvent;
187
205
  /**
188
206
  * Handle a Claude process 'result' event: update session state, apply API
189
207
  * retry logic for transient errors, broadcast result to clients, and trigger
@@ -206,76 +224,40 @@ export declare class SessionManager {
206
224
  * and trigger session naming if needed.
207
225
  */
208
226
  private finalizeResult;
209
- /**
210
- * Handle a Claude process 'exit' event: clean up state, notify exit listeners,
211
- * and either auto-restart (within limits) or broadcast the final exit message.
212
- *
213
- * Uses evaluateRestart() for the restart decision, keeping this method focused
214
- * on state updates, listener notification, and message broadcasting.
215
- */
216
- private handleClaudeExit;
227
+ /** Handle Claude process exit. Delegates to SessionLifecycle. @internal — used by tests. */
228
+ handleClaudeExit(...args: Parameters<SessionLifecycle['handleClaudeExit']>): void;
217
229
  /**
218
230
  * Send user input to a session's Claude process.
219
231
  * Auto-starts Claude if not running, with session context for continuity.
220
232
  */
221
233
  sendInput(sessionId: string, data: string): void;
222
234
  /**
223
- * Route a user's prompt response to the correct handler: pending tool approval
224
- * (from PermissionRequest hook), pending control request (from control_request
225
- * fallback path), or plain message fallback.
235
+ * Route a user's prompt response to the correct handler.
236
+ * Delegates to PromptRouter.
226
237
  */
227
238
  sendPromptResponse(sessionId: string, value: string | string[], requestId?: string): void;
228
- /** Decode the allow/deny/always/pattern intent from a prompt response value. */
229
- private decodeApprovalValue;
230
- /** Resolve a pending PreToolUse hook approval and update auto-approval registries. */
231
- private resolveToolApproval;
232
- /**
233
- * Send an AskUserQuestion control response, mapping the user's answer(s) into
234
- * the structured answers map the tool expects.
235
- */
236
- private handleAskUserQuestion;
237
- /** Send a permission control response (allow/always_allow/approve_pattern/deny). */
238
- private sendControlResponseForRequest;
239
239
  /**
240
240
  * Called by the PermissionRequest hook HTTP endpoint. Sends a prompt to clients
241
241
  * and returns a Promise that resolves when the user approves/denies.
242
+ * Delegates to PromptRouter.
242
243
  */
243
244
  requestToolApproval(sessionId: string, toolName: string, toolInput: Record<string, unknown>): Promise<{
244
245
  allow: boolean;
245
246
  always: boolean;
246
247
  answer?: string;
247
248
  }>;
248
- /**
249
- * Handle ExitPlanMode approval through PlanManager.
250
- * Shows a plan-specific approval prompt (Approve/Reject) and blocks the hook
251
- * until the user responds. On approve, returns allow:true (the hook will use
252
- * the deny-with-approval-message workaround). On deny, returns allow:false.
253
- */
254
- private handleExitPlanModeApproval;
255
- /**
256
- * Check if a tool invocation can be auto-approved without prompting the user.
257
- * Returns 'registry' if matched by auto-approval rules, 'session' if matched
258
- * by the session's allowedTools list, 'headless' if the session has no clients
259
- * and is a non-interactive source, or 'prompt' if the user needs to decide.
260
- */
261
- private resolveAutoApproval;
262
- /**
263
- * Check if a tool invocation matches any of the session's allowedTools patterns.
264
- * Patterns follow Claude CLI format: 'ToolName' or 'ToolName(prefix:*)'.
265
- * Examples: 'WebFetch', 'Bash(curl:*)', 'Bash(git:*)'.
266
- */
267
- private matchesAllowedTools;
268
- /** Build a human-readable prompt string for a tool permission dialog. */
269
- private summarizeToolPermission;
249
+ getSessionProvider(sessionId: string): string;
250
+ /** Update the provider for a session and restart with the new provider process. */
251
+ setProvider(sessionId: string, provider: CodingProvider): boolean;
270
252
  /** Update the model for a session and restart Claude with the new model. */
271
253
  setModel(sessionId: string, model: string): boolean;
272
254
  /** Update the permission mode for a session and restart Claude with the new mode. */
273
255
  setPermissionMode(sessionId: string, permissionMode: import('./types.js').PermissionMode): boolean;
256
+ /** Stop the Claude process for a session. Delegates to SessionLifecycle. */
274
257
  stopClaude(sessionId: string): void;
275
258
  /**
276
259
  * Stop the Claude process and wait for it to fully exit before resolving.
277
- * This prevents race conditions when restarting with the same session ID
278
- * (e.g. during mid-session worktree migration).
260
+ * Delegates to SessionLifecycle.
279
261
  */
280
262
  stopClaudeAndWait(sessionId: string): Promise<void>;
281
263
  /** Check if an error result text matches a transient API error worth retrying. */