@northflare/runner 0.0.13 → 0.0.16

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 (119) hide show
  1. package/README.md +8 -5
  2. package/bin/northflare-runner +44 -16
  3. package/dist/components/claude-sdk-manager.d.ts +3 -3
  4. package/dist/components/claude-sdk-manager.d.ts.map +1 -1
  5. package/dist/components/claude-sdk-manager.js +80 -111
  6. package/dist/components/claude-sdk-manager.js.map +1 -1
  7. package/dist/components/codex-sdk-manager.d.ts +15 -6
  8. package/dist/components/codex-sdk-manager.d.ts.map +1 -1
  9. package/dist/components/codex-sdk-manager.js +128 -97
  10. package/dist/components/codex-sdk-manager.js.map +1 -1
  11. package/dist/components/enhanced-repository-manager.d.ts +2 -2
  12. package/dist/components/enhanced-repository-manager.d.ts.map +1 -1
  13. package/dist/components/enhanced-repository-manager.js +68 -75
  14. package/dist/components/enhanced-repository-manager.js.map +1 -1
  15. package/dist/components/message-handler-sse.d.ts +1 -1
  16. package/dist/components/message-handler-sse.d.ts.map +1 -1
  17. package/dist/components/message-handler-sse.js +205 -97
  18. package/dist/components/message-handler-sse.js.map +1 -1
  19. package/dist/components/{claude-manager.d.ts → northflare-agent-sdk-manager.d.ts} +17 -14
  20. package/dist/components/northflare-agent-sdk-manager.d.ts.map +1 -0
  21. package/dist/components/northflare-agent-sdk-manager.js +1456 -0
  22. package/dist/components/northflare-agent-sdk-manager.js.map +1 -0
  23. package/dist/components/repository-manager.d.ts +2 -2
  24. package/dist/components/repository-manager.d.ts.map +1 -1
  25. package/dist/components/repository-manager.js +34 -74
  26. package/dist/components/repository-manager.js.map +1 -1
  27. package/dist/index.d.ts +3 -3
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +115 -79
  30. package/dist/index.js.map +1 -1
  31. package/dist/runner-sse.d.ts +22 -5
  32. package/dist/runner-sse.d.ts.map +1 -1
  33. package/dist/runner-sse.js +95 -74
  34. package/dist/runner-sse.js.map +1 -1
  35. package/dist/services/RunnerAPIClient.d.ts +1 -1
  36. package/dist/services/RunnerAPIClient.d.ts.map +1 -1
  37. package/dist/services/RunnerAPIClient.js +3 -7
  38. package/dist/services/RunnerAPIClient.js.map +1 -1
  39. package/dist/services/SSEClient.js +5 -9
  40. package/dist/services/SSEClient.js.map +1 -1
  41. package/dist/types/claude.d.ts +16 -2
  42. package/dist/types/claude.d.ts.map +1 -1
  43. package/dist/types/claude.js +1 -2
  44. package/dist/types/claude.js.map +1 -1
  45. package/dist/types/index.d.ts +5 -3
  46. package/dist/types/index.d.ts.map +1 -1
  47. package/dist/types/index.js +3 -19
  48. package/dist/types/index.js.map +1 -1
  49. package/dist/types/messages.js +1 -2
  50. package/dist/types/messages.js.map +1 -1
  51. package/dist/types/runner-interface.d.ts +8 -4
  52. package/dist/types/runner-interface.d.ts.map +1 -1
  53. package/dist/types/runner-interface.js +1 -2
  54. package/dist/types/runner-interface.js.map +1 -1
  55. package/dist/utils/StateManager.js +12 -19
  56. package/dist/utils/StateManager.js.map +1 -1
  57. package/dist/utils/config.d.ts +1 -1
  58. package/dist/utils/config.d.ts.map +1 -1
  59. package/dist/utils/config.js +19 -26
  60. package/dist/utils/config.js.map +1 -1
  61. package/dist/utils/console.js +3 -6
  62. package/dist/utils/console.js.map +1 -1
  63. package/dist/utils/debug.js +1 -4
  64. package/dist/utils/debug.js.map +1 -1
  65. package/dist/utils/expand-env.js +1 -4
  66. package/dist/utils/expand-env.js.map +1 -1
  67. package/dist/utils/inactivity-timeout.d.ts +19 -0
  68. package/dist/utils/inactivity-timeout.d.ts.map +1 -0
  69. package/dist/utils/inactivity-timeout.js +72 -0
  70. package/dist/utils/inactivity-timeout.js.map +1 -0
  71. package/dist/utils/logger.d.ts.map +1 -1
  72. package/dist/utils/logger.js +24 -35
  73. package/dist/utils/logger.js.map +1 -1
  74. package/dist/utils/model.d.ts +3 -1
  75. package/dist/utils/model.d.ts.map +1 -1
  76. package/dist/utils/model.js +18 -4
  77. package/dist/utils/model.js.map +1 -1
  78. package/dist/utils/status-line.d.ts +1 -0
  79. package/dist/utils/status-line.d.ts.map +1 -1
  80. package/dist/utils/status-line.js +25 -18
  81. package/dist/utils/status-line.js.map +1 -1
  82. package/dist/utils/tool-response-sanitizer.js +6 -10
  83. package/dist/utils/tool-response-sanitizer.js.map +1 -1
  84. package/lib/codex-sdk/dist/index.d.ts +1 -1
  85. package/lib/codex-sdk/dist/samples/basic_streaming.d.ts +3 -0
  86. package/lib/codex-sdk/dist/samples/basic_streaming.d.ts.map +1 -0
  87. package/lib/codex-sdk/dist/samples/basic_streaming.js +81 -0
  88. package/lib/codex-sdk/dist/samples/basic_streaming.js.map +1 -0
  89. package/lib/codex-sdk/dist/samples/helpers.d.ts +2 -0
  90. package/lib/codex-sdk/dist/samples/helpers.d.ts.map +1 -0
  91. package/lib/codex-sdk/dist/samples/helpers.js +6 -0
  92. package/lib/codex-sdk/dist/samples/helpers.js.map +1 -0
  93. package/lib/codex-sdk/dist/samples/structured_output.d.ts +3 -0
  94. package/lib/codex-sdk/dist/samples/structured_output.d.ts.map +1 -0
  95. package/lib/codex-sdk/dist/samples/structured_output.js +17 -0
  96. package/lib/codex-sdk/dist/samples/structured_output.js.map +1 -0
  97. package/lib/codex-sdk/dist/samples/structured_output_zod.d.ts +3 -0
  98. package/lib/codex-sdk/dist/samples/structured_output_zod.d.ts.map +1 -0
  99. package/lib/codex-sdk/dist/samples/structured_output_zod.js +16 -0
  100. package/lib/codex-sdk/dist/samples/structured_output_zod.js.map +1 -0
  101. package/lib/codex-sdk/dist/tsup.config.d.ts +3 -0
  102. package/lib/codex-sdk/dist/tsup.config.js +12 -0
  103. package/package.json +9 -4
  104. package/scripts/verify-openrouter-agent.ts +163 -0
  105. package/dist/collections/runner-messages.d.ts +0 -52
  106. package/dist/collections/runner-messages.d.ts.map +0 -1
  107. package/dist/collections/runner-messages.js +0 -161
  108. package/dist/collections/runner-messages.js.map +0 -1
  109. package/dist/components/claude-manager.d.ts.map +0 -1
  110. package/dist/components/claude-manager.js +0 -783
  111. package/dist/components/claude-manager.js.map +0 -1
  112. package/dist/components/message-handler.d.ts +0 -35
  113. package/dist/components/message-handler.d.ts.map +0 -1
  114. package/dist/components/message-handler.js +0 -689
  115. package/dist/components/message-handler.js.map +0 -1
  116. package/dist/runner.d.ts +0 -51
  117. package/dist/runner.d.ts.map +0 -1
  118. package/dist/runner.js +0 -530
  119. package/dist/runner.js.map +0 -1
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * ClaudeManager - Manages Claude conversations using SDK-native patterns
4
3
  *
@@ -14,56 +13,21 @@
14
13
  * - SDK's onProcessComplete() for proper cleanup
15
14
  * - Simplified error handling while maintaining compatibility
16
15
  */
17
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
- if (k2 === undefined) k2 = k;
19
- var desc = Object.getOwnPropertyDescriptor(m, k);
20
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
- desc = { enumerable: true, get: function() { return m[k]; } };
22
- }
23
- Object.defineProperty(o, k2, desc);
24
- }) : (function(o, m, k, k2) {
25
- if (k2 === undefined) k2 = k;
26
- o[k2] = m[k];
27
- }));
28
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
29
- Object.defineProperty(o, "default", { enumerable: true, value: v });
30
- }) : function(o, v) {
31
- o["default"] = v;
32
- });
33
- var __importStar = (this && this.__importStar) || (function () {
34
- var ownKeys = function(o) {
35
- ownKeys = Object.getOwnPropertyNames || function (o) {
36
- var ar = [];
37
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
38
- return ar;
39
- };
40
- return ownKeys(o);
41
- };
42
- return function (mod) {
43
- if (mod && mod.__esModule) return mod;
44
- var result = {};
45
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
46
- __setModuleDefault(result, mod);
47
- return result;
48
- };
49
- })();
50
- Object.defineProperty(exports, "__esModule", { value: true });
51
- exports.ClaudeManager = void 0;
52
- const claude_agent_sdk_1 = require("@anthropic-ai/claude-agent-sdk");
53
- const status_line_1 = require("../utils/status-line");
54
- const console_1 = require("../utils/console");
55
- const expand_env_1 = require("../utils/expand-env");
56
- const debug_1 = require("../utils/debug");
57
- const jwt = __importStar(require("jsonwebtoken"));
58
- class ClaudeManager {
16
+ import { query as sdkQuery } from "@anthropic-ai/claude-agent-sdk";
17
+ import { statusLineManager } from '../utils/status-line.js';
18
+ import { console } from '../utils/console.js';
19
+ import { expandEnv } from '../utils/expand-env.js';
20
+ import { isRunnerDebugEnabled } from '../utils/debug.js';
21
+ import jwt from "jsonwebtoken";
22
+ export class ClaudeManager {
59
23
  runner;
60
24
  repositoryManager;
61
25
  constructor(runner, repositoryManager) {
62
26
  this.runner = runner;
63
27
  this.repositoryManager = repositoryManager;
64
28
  // Log debug mode status
65
- if ((0, debug_1.isRunnerDebugEnabled)()) {
66
- console_1.console.log("[ClaudeManager] DEBUG MODE ENABLED - Claude SDK will log verbose output");
29
+ if (isRunnerDebugEnabled()) {
30
+ console.log("[ClaudeManager] DEBUG MODE ENABLED - Claude SDK will log verbose output");
67
31
  }
68
32
  // Note: MCP host configuration is passed from orchestrator
69
33
  // Runner does not define its own MCP tools
@@ -101,7 +65,7 @@ class ClaudeManager {
101
65
  };
102
66
  // Store with conversation.id as the key
103
67
  this.runner.activeConversations_.set(conversationId, context);
104
- console_1.console.log(`[ClaudeManager] Stored conversation context:`, {
68
+ console.log(`[ClaudeManager] Stored conversation context:`, {
105
69
  conversationId,
106
70
  agentSessionId: context.agentSessionId,
107
71
  conversationObjectType: context.conversationObjectType,
@@ -116,7 +80,7 @@ class ClaudeManager {
116
80
  if (config.runnerRepoPath) {
117
81
  // Local workspace - use the provided path directly
118
82
  workspacePath = config.runnerRepoPath;
119
- console_1.console.log(`Using local workspace path: ${workspacePath}`);
83
+ console.log(`Using local workspace path: ${workspacePath}`);
120
84
  // For task conversations in local workspaces, create a local task handle
121
85
  if (conversationObjectType === "Task") {
122
86
  const taskHandle = await this.repositoryManager.createLocalTaskHandle(conversationObjectId, workspacePath);
@@ -128,7 +92,7 @@ class ClaudeManager {
128
92
  config.repository &&
129
93
  workspaceId) {
130
94
  // Use task-specific worktree for task conversations
131
- console_1.console.log(`[ClaudeManager] Creating task worktree with repository config:`, {
95
+ console.log(`[ClaudeManager] Creating task worktree with repository config:`, {
132
96
  conversationObjectId,
133
97
  workspaceId,
134
98
  repository: config.repository,
@@ -151,7 +115,7 @@ class ClaudeManager {
151
115
  if (config.repository.type === "local" && config.repository.localPath) {
152
116
  // Use the local path directly
153
117
  workspacePath = config.repository.localPath;
154
- console_1.console.log(`Using local repository path: ${workspacePath}`);
118
+ console.log(`Using local repository path: ${workspacePath}`);
155
119
  }
156
120
  else {
157
121
  // Fall back to workspace-based checkout for non-task conversations
@@ -159,7 +123,8 @@ class ClaudeManager {
159
123
  }
160
124
  }
161
125
  else if (workspaceId) {
162
- workspacePath = await this.repositoryManager.getWorkspacePath(workspaceId);
126
+ workspacePath =
127
+ await this.repositoryManager.getWorkspacePath(workspaceId);
163
128
  }
164
129
  else {
165
130
  // Default workspace path when no workspaceId is provided
@@ -182,10 +147,10 @@ class ClaudeManager {
182
147
  }, runnerToken, {
183
148
  expiresIn: "60m", // 60 minutes expiry
184
149
  });
185
- console_1.console.log("[ClaudeManager] Generated TOOL_TOKEN for MCP authentication");
150
+ console.log("[ClaudeManager] Generated TOOL_TOKEN for MCP authentication");
186
151
  }
187
152
  else {
188
- console_1.console.warn("[ClaudeManager] Unable to generate TOOL_TOKEN - missing required data");
153
+ console.warn("[ClaudeManager] Unable to generate TOOL_TOKEN - missing required data");
189
154
  }
190
155
  }
191
156
  // Simplified SDK configuration - using native query API with streamlined options
@@ -208,7 +173,7 @@ class ClaudeManager {
208
173
  if (githubToken) {
209
174
  envVars["GITHUB_TOKEN"] = githubToken;
210
175
  }
211
- if ((0, debug_1.isRunnerDebugEnabled)()) {
176
+ if (isRunnerDebugEnabled()) {
212
177
  envVars["DEBUG"] = "1";
213
178
  }
214
179
  // Simplified system prompt handling
@@ -219,7 +184,7 @@ class ClaudeManager {
219
184
  .filter(Boolean)
220
185
  .join("\n\n");
221
186
  // Debug log the appendSystemPrompt being sent to Claude SDK
222
- console_1.console.log(`[ClaudeManager] Building appendSystemPrompt for conversation ${context.conversationId}:`, {
187
+ console.log(`[ClaudeManager] Building appendSystemPrompt for conversation ${context.conversationId}:`, {
223
188
  hasGlobalInstructions: !!context.globalInstructions,
224
189
  globalInstructionsLength: context.globalInstructions?.length ?? 0,
225
190
  hasWorkspaceInstructions: !!context.workspaceInstructions,
@@ -240,18 +205,18 @@ class ClaudeManager {
240
205
  ]
241
206
  : [];
242
207
  if (disallowedTools.length) {
243
- console_1.console.log("[ClaudeManager] Applied read-only mode tool restrictions");
208
+ console.log("[ClaudeManager] Applied read-only mode tool restrictions");
244
209
  }
245
210
  // Simplified MCP server configuration
246
211
  let mcpServers;
247
212
  if (config.mcpServers) {
248
- mcpServers = (0, expand_env_1.expandEnv)(config.mcpServers, { TOOL_TOKEN: toolToken });
249
- console_1.console.log("[ClaudeManager] MCP servers configuration:", JSON.stringify(mcpServers, null, 2));
213
+ mcpServers = expandEnv(config.mcpServers, { TOOL_TOKEN: toolToken });
214
+ console.log("[ClaudeManager] MCP servers configuration:", JSON.stringify(mcpServers, null, 2));
250
215
  }
251
216
  // Create input stream for user messages (simplified message queueing)
252
217
  const input = createUserMessageStream();
253
218
  // Launch SDK with simplified configuration
254
- const sdk = (0, claude_agent_sdk_1.query)({
219
+ const sdk = sdkQuery({
255
220
  prompt: input.iterable,
256
221
  options: {
257
222
  //pathToClaudeCodeExecutable: cliPath,
@@ -271,11 +236,11 @@ class ClaudeManager {
271
236
  : {}),
272
237
  ...(disallowedTools.length ? { disallowedTools } : {}),
273
238
  ...(mcpServers ? { mcpServers } : {}),
274
- ...((0, debug_1.isRunnerDebugEnabled)()
239
+ ...(isRunnerDebugEnabled()
275
240
  ? {
276
241
  stderr: (data) => {
277
242
  try {
278
- console_1.console.log(`[Claude SDK] ${data}`);
243
+ console.log(`[Claude SDK] ${data}`);
279
244
  }
280
245
  catch { }
281
246
  },
@@ -331,18 +296,18 @@ class ClaudeManager {
331
296
  // Treat 'result' as an end-of-conversation signal for the SDK
332
297
  try {
333
298
  await this._finalizeConversation(context, false);
334
- console_1.console.log("[ClaudeManager] Finalized conversation due to SDK 'result' message", {
299
+ console.log("[ClaudeManager] Finalized conversation due to SDK 'result' message", {
335
300
  conversationId: context.conversationId,
336
301
  agentSessionId: context.agentSessionId,
337
302
  });
338
303
  }
339
304
  catch (e) {
340
- console_1.console.warn("[ClaudeManager] Error finalizing on 'result' message:", e);
305
+ console.warn("[ClaudeManager] Error finalizing on 'result' message:", e);
341
306
  }
342
307
  }
343
308
  }
344
309
  catch (e) {
345
- console_1.console.warn("[ClaudeManager] finalize-on-system heuristic error:", e);
310
+ console.warn("[ClaudeManager] finalize-on-system heuristic error:", e);
346
311
  }
347
312
  };
348
313
  conversation.stream(messageHandler);
@@ -357,7 +322,7 @@ class ClaudeManager {
357
322
  text: initialText,
358
323
  });
359
324
  }
360
- console_1.console.log(`Started conversation for ${conversationObjectType} ${conversationObjectId} in workspace ${workspacePath}`);
325
+ console.log(`Started conversation for ${conversationObjectType} ${conversationObjectId} in workspace ${workspacePath}`);
361
326
  // Return the conversation context directly
362
327
  return context;
363
328
  }
@@ -383,15 +348,15 @@ class ClaudeManager {
383
348
  }
384
349
  }
385
350
  catch (error) {
386
- console_1.console.error(`Error ending conversation ${agentSessionId}:`, error);
351
+ console.error(`Error ending conversation ${agentSessionId}:`, error);
387
352
  }
388
353
  // Clean up conversation reference
389
354
  delete context.conversation;
390
355
  }
391
- console_1.console.log(`Stopped conversation ${agentSessionId} for ${context.conversationObjectType} ${context.conversationObjectId}`);
356
+ console.log(`Stopped conversation ${agentSessionId} for ${context.conversationObjectType} ${context.conversationObjectId}`);
392
357
  }
393
358
  async resumeConversation(conversationObjectType, conversationObjectId, agentSessionId, config, conversationData, resumeMessage) {
394
- console_1.console.log(`[ClaudeManager] Resuming conversation ${agentSessionId}`);
359
+ console.log(`[ClaudeManager] Resuming conversation ${agentSessionId}`);
395
360
  // Resume is handled by starting a new conversation with the existing session ID
396
361
  const context = await this.startConversation(conversationObjectType, conversationObjectId, { ...config, sessionId: agentSessionId }, [], // Don't send initial messages
397
362
  conversationData);
@@ -402,26 +367,41 @@ class ClaudeManager {
402
367
  // Use the provided resume message or default to system instruction
403
368
  const messageToSend = resumeMessage ||
404
369
  "<system-instructions>Please continue</system-instructions>";
405
- console_1.console.log(`[ClaudeManager] Sending resume message to conversation ${agentSessionId}`);
370
+ console.log(`[ClaudeManager] Sending resume message to conversation ${agentSessionId}`);
406
371
  context.conversation.send({
407
372
  type: "text",
408
373
  text: messageToSend,
409
374
  });
410
375
  }
411
376
  catch (error) {
412
- console_1.console.error(`[ClaudeManager] Error sending resume message:`, error);
377
+ console.error(`[ClaudeManager] Error sending resume message:`, error);
413
378
  }
414
379
  }
415
380
  else {
416
- console_1.console.warn("[ClaudeManager] Resume requested but conversation instance missing or incompatible");
381
+ console.warn("[ClaudeManager] Resume requested but conversation instance missing or incompatible");
417
382
  }
418
383
  return context.agentSessionId;
419
384
  }
420
385
  async _finalizeConversation(context, hadError, error, reason) {
421
- // Ensure idempotency
386
+ // Synchronous idempotency check - must happen before any async operations
422
387
  if (context._finalized)
423
388
  return;
424
389
  context._finalized = true;
390
+ // Mark as completed immediately to prevent restart on catch-up
391
+ // This is synchronous and happens before any async operations
392
+ this.runner.markConversationCompleted(context.conversationId);
393
+ // Clean up conversation from active conversations (synchronous)
394
+ try {
395
+ console.log(`[ClaudeManager] Removing conversation from active map:`, {
396
+ conversationId: context.conversationId,
397
+ agentSessionId: context.agentSessionId,
398
+ mapSizeBefore: this.runner.activeConversations_.size,
399
+ });
400
+ this.runner.activeConversations_.delete(context.conversationId);
401
+ statusLineManager.updateActiveCount(this.runner.activeConversations_.size);
402
+ }
403
+ catch { }
404
+ // Now do async notification (after all sync cleanup)
425
405
  try {
426
406
  await this.runner.notify("conversation.end", {
427
407
  conversationId: context.conversationId,
@@ -434,22 +414,11 @@ class ClaudeManager {
434
414
  });
435
415
  }
436
416
  catch (e) {
437
- console_1.console.error("[ClaudeManager] Failed to notify conversation.end:", e);
438
- }
439
- // Clean up conversation from active conversations
440
- try {
441
- console_1.console.log(`[ClaudeManager] Removing conversation from active map:`, {
442
- conversationId: context.conversationId,
443
- agentSessionId: context.agentSessionId,
444
- mapSizeBefore: this.runner.activeConversations_.size,
445
- });
446
- this.runner.activeConversations_.delete(context.conversationId);
447
- status_line_1.statusLineManager.updateActiveCount(this.runner.activeConversations_.size);
417
+ console.error("[ClaudeManager] Failed to notify conversation.end:", e);
448
418
  }
449
- catch { }
450
419
  }
451
420
  async sendUserMessage(conversationId, content, config, conversationObjectType, conversationObjectId, conversation, _agentSessionIdOverride) {
452
- console_1.console.log(`[ClaudeManager] sendUserMessage called with:`, {
421
+ console.log(`[ClaudeManager] sendUserMessage called with:`, {
453
422
  conversationId,
454
423
  conversationObjectType,
455
424
  conversationObjectId,
@@ -459,7 +428,7 @@ class ClaudeManager {
459
428
  });
460
429
  // Find by conversationId only
461
430
  let context = this.runner.getConversationContext(conversationId);
462
- console_1.console.log(`[ClaudeManager] Lookup by conversationId result:`, {
431
+ console.log(`[ClaudeManager] Lookup by conversationId result:`, {
463
432
  found: !!context,
464
433
  conversationId: context?.conversationId,
465
434
  agentSessionId: context?.agentSessionId,
@@ -468,7 +437,7 @@ class ClaudeManager {
468
437
  // Use provided conversation details
469
438
  try {
470
439
  const conversationDetails = conversation;
471
- console_1.console.log(`[ClaudeManager] Using provided config from RunnerMessage:`, {
440
+ console.log(`[ClaudeManager] Using provided config from RunnerMessage:`, {
472
441
  hasConfig: !!config,
473
442
  hasRepository: !!config?.repository,
474
443
  repositoryType: config?.repository?.type,
@@ -492,7 +461,7 @@ class ClaudeManager {
492
461
  context = this.runner.getConversationContext(conversationId);
493
462
  }
494
463
  catch (error) {
495
- console_1.console.error(`Failed to fetch conversation ${conversationId}:`, error);
464
+ console.error(`Failed to fetch conversation ${conversationId}:`, error);
496
465
  }
497
466
  }
498
467
  if (!context) {
@@ -500,14 +469,15 @@ class ClaudeManager {
500
469
  }
501
470
  try {
502
471
  // Send immediately when a conversation instance exists; no need to wait for "active"
503
- if (!context.conversation || !isClaudeConversation(context.conversation)) {
472
+ if (!context.conversation ||
473
+ !isClaudeConversation(context.conversation)) {
504
474
  throw new Error(`No conversation instance found for conversation ${context.conversationId}`);
505
475
  }
506
476
  // Guard: Don't send messages if conversation is stopped or stopping
507
477
  const conversationStatus = context.status;
508
478
  if (conversationStatus === "stopped" ||
509
479
  conversationStatus === "stopping") {
510
- console_1.console.warn(`Attempted to send message to stopped/stopping conversation ${context.conversationId}`, {
480
+ console.warn(`Attempted to send message to stopped/stopping conversation ${context.conversationId}`, {
511
481
  status: context.status,
512
482
  conversationObjectType: context.conversationObjectType,
513
483
  conversationObjectId: context.conversationObjectId,
@@ -516,8 +486,8 @@ class ClaudeManager {
516
486
  }
517
487
  // Native message injection - SDK handles queueing and delivery
518
488
  const normalizedText = this.normalizeToText(content);
519
- if ((0, debug_1.isRunnerDebugEnabled)()) {
520
- console_1.console.log("[ClaudeManager] Normalized follow-up content", {
489
+ if (isRunnerDebugEnabled()) {
490
+ console.log("[ClaudeManager] Normalized follow-up content", {
521
491
  originalType: typeof content,
522
492
  isArray: Array.isArray(content) || undefined,
523
493
  normalizedPreview: typeof normalizedText === "string"
@@ -531,7 +501,7 @@ class ClaudeManager {
531
501
  });
532
502
  // Update last activity timestamp
533
503
  context.lastActivityAt = new Date();
534
- console_1.console.log(`Sent user message to conversation ${context.conversationId} (agentSessionId: ${context.agentSessionId}, status: ${context.status})`);
504
+ console.log(`Sent user message to conversation ${context.conversationId} (agentSessionId: ${context.agentSessionId}, status: ${context.status})`);
535
505
  }
536
506
  catch (error) {
537
507
  // Handle errors properly
@@ -548,14 +518,14 @@ class ClaudeManager {
548
518
  },
549
519
  });
550
520
  if (!response.ok) {
551
- console_1.console.error(`Failed to fetch GitHub tokens: ${response.status}`);
521
+ console.error(`Failed to fetch GitHub tokens: ${response.status}`);
552
522
  return undefined;
553
523
  }
554
524
  const data = (await response.json());
555
525
  return data.githubToken;
556
526
  }
557
527
  catch (error) {
558
- console_1.console.error("Error fetching GitHub tokens:", error);
528
+ console.error("Error fetching GitHub tokens:", error);
559
529
  return undefined;
560
530
  }
561
531
  }
@@ -575,7 +545,7 @@ class ClaudeManager {
575
545
  },
576
546
  });
577
547
  // Conversation continues on error - no automatic cleanup
578
- console_1.console.error(`Conversation error for ${context.conversationObjectType} ${context.conversationObjectId}:`, error);
548
+ console.error(`Conversation error for ${context.conversationObjectType} ${context.conversationObjectId}:`, error);
579
549
  }
580
550
  classifyError(error) {
581
551
  if (error.message.includes("process exited")) {
@@ -678,7 +648,7 @@ class ClaudeManager {
678
648
  // Guard: Don't process messages if conversation is stopped or stopping
679
649
  const status = context.status;
680
650
  if (status === "stopped" || status === "stopping") {
681
- console_1.console.log(`Ignoring message for stopped/stopping conversation ${context.conversationId}`, {
651
+ console.log(`Ignoring message for stopped/stopping conversation ${context.conversationId}`, {
682
652
  status: context.status,
683
653
  messageType: message.type,
684
654
  });
@@ -686,7 +656,7 @@ class ClaudeManager {
686
656
  }
687
657
  try {
688
658
  // High-level receipt log
689
- console_1.console.log(`Received streamed message for ${context.conversationObjectType} ${context.conversationObjectId}`, {
659
+ console.log(`Received streamed message for ${context.conversationObjectType} ${context.conversationObjectId}`, {
690
660
  type: message?.type,
691
661
  });
692
662
  // Raw SDK message diagnostics
@@ -707,7 +677,7 @@ class ClaudeManager {
707
677
  return value;
708
678
  }, 2);
709
679
  };
710
- console_1.console.log("[ClaudeManager] RAW SDK message FULL:", safeStringify(message));
680
+ console.log("[ClaudeManager] RAW SDK message FULL:", safeStringify(message));
711
681
  const summary = {
712
682
  keys: Object.keys(message || {}),
713
683
  hasMessage: !!message?.message,
@@ -715,16 +685,16 @@ class ClaudeManager {
715
685
  messageContentType: typeof message?.message?.content,
716
686
  sessionId: message?.session_id || message?.sessionId || null,
717
687
  };
718
- console_1.console.log("[ClaudeManager] RAW SDK message summary:", summary);
688
+ console.log("[ClaudeManager] RAW SDK message summary:", summary);
719
689
  if (message?.content !== undefined) {
720
- console_1.console.log("[ClaudeManager] RAW SDK content:", message.content);
690
+ console.log("[ClaudeManager] RAW SDK content:", message.content);
721
691
  }
722
692
  if (message?.message?.content !== undefined) {
723
- console_1.console.log("[ClaudeManager] RAW SDK nested content:", message.message.content);
693
+ console.log("[ClaudeManager] RAW SDK nested content:", message.message.content);
724
694
  }
725
695
  }
726
696
  catch (e) {
727
- console_1.console.warn("[ClaudeManager] Failed to log raw SDK message:", e);
697
+ console.warn("[ClaudeManager] Failed to log raw SDK message:", e);
728
698
  }
729
699
  // Build structured content based on message type
730
700
  let messageType = message.type;
@@ -857,7 +827,7 @@ class ClaudeManager {
857
827
  // Check if this is a subagent prompt (Task tool input being sent to subagent)
858
828
  // These have parent_tool_use_id but are NOT tool_result messages
859
829
  if (userMsg.parent_tool_use_id) {
860
- console_1.console.log("[ClaudeManager] Detected subagent prompt message (parent_tool_use_id present, no tool_result)", {
830
+ console.log("[ClaudeManager] Detected subagent prompt message (parent_tool_use_id present, no tool_result)", {
861
831
  parent_tool_use_id: userMsg.parent_tool_use_id,
862
832
  });
863
833
  messageType = "assistant"; // Change from "user" to "assistant"
@@ -869,7 +839,7 @@ class ClaudeManager {
869
839
  if (Array.isArray(structuredContent) &&
870
840
  structuredContent.length > 0 &&
871
841
  structuredContent.every((it) => !it || typeof it !== "object" || Object.keys(it).length === 0)) {
872
- console_1.console.log("[ClaudeManager] Skipping empty 'user' message with only empty objects from SDK");
842
+ console.log("[ClaudeManager] Skipping empty 'user' message with only empty objects from SDK");
873
843
  skipSend = true;
874
844
  }
875
845
  }
@@ -950,7 +920,7 @@ class ClaudeManager {
950
920
  default: {
951
921
  // Unknown message type - log and send as assistant
952
922
  const unknownMsg = message;
953
- console_1.console.warn(`Unknown message type: ${unknownMsg.type}`, message);
923
+ console.warn(`Unknown message type: ${unknownMsg.type}`, message);
954
924
  messageType = "assistant";
955
925
  structuredContent = {
956
926
  text: JSON.stringify(message),
@@ -967,7 +937,7 @@ class ClaudeManager {
967
937
  const currentStatus = context.status;
968
938
  if (currentStatus !== "stopped" && currentStatus !== "stopping") {
969
939
  if (skipSend) {
970
- console_1.console.log("[ClaudeManager] Not sending message.agent due to skipSend=true");
940
+ console.log("[ClaudeManager] Not sending message.agent due to skipSend=true");
971
941
  return;
972
942
  }
973
943
  const payload = {
@@ -988,7 +958,7 @@ class ClaudeManager {
988
958
  payload.metadata = metadata;
989
959
  }
990
960
  try {
991
- console_1.console.log("[ClaudeManager] Sending message.agent payload:", {
961
+ console.log("[ClaudeManager] Sending message.agent payload:", {
992
962
  type: payload.type,
993
963
  subtype: payload.subtype,
994
964
  contentPreview: Array.isArray(payload.content)
@@ -1003,7 +973,7 @@ class ClaudeManager {
1003
973
  // We just log that we saw them but don't intercept or process them
1004
974
  if (structuredContent.toolCalls &&
1005
975
  structuredContent.toolCalls.length > 0) {
1006
- console_1.console.log(`Claude is making ${structuredContent.toolCalls.length} tool call(s) via MCP`, {
976
+ console.log(`Claude is making ${structuredContent.toolCalls.length} tool call(s) via MCP`, {
1007
977
  conversationObjectId: context.conversationObjectId,
1008
978
  toolNames: structuredContent.toolCalls.map((tc) => tc.name),
1009
979
  });
@@ -1019,15 +989,14 @@ class ClaudeManager {
1019
989
  if (isTransportError &&
1020
990
  (statusCheck === "stopped" || statusCheck === "stopping")) {
1021
991
  // This is expected when conversation is stopped - just log it
1022
- console_1.console.log(`Transport error for stopped/stopping conversation ${context.conversationId} (expected):`, errorMessage);
992
+ console.log(`Transport error for stopped/stopping conversation ${context.conversationId} (expected):`, errorMessage);
1023
993
  return;
1024
994
  }
1025
- console_1.console.error(`Error handling streamed message for ${context.conversationObjectType} ${context.conversationObjectId}:`, error);
995
+ console.error(`Error handling streamed message for ${context.conversationObjectType} ${context.conversationObjectId}:`, error);
1026
996
  await this._handleConversationError(context, error);
1027
997
  }
1028
998
  }
1029
999
  }
1030
- exports.ClaudeManager = ClaudeManager;
1031
1000
  function createUserMessageStream() {
1032
1001
  const queue = [];
1033
1002
  let resolver = null;