tide-commander 0.52.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/README.md +364 -0
- package/dist/assets/characters/Textures/colormap.png +0 -0
- package/dist/assets/characters/character-female-a.glb +0 -0
- package/dist/assets/characters/character-female-b.glb +0 -0
- package/dist/assets/characters/character-female-c.glb +0 -0
- package/dist/assets/characters/character-female-d.glb +0 -0
- package/dist/assets/characters/character-female-e.glb +0 -0
- package/dist/assets/characters/character-female-f.glb +0 -0
- package/dist/assets/characters/character-male-a-processed.gltf +11862 -0
- package/dist/assets/characters/character-male-a.glb +0 -0
- package/dist/assets/characters/character-male-b.glb +0 -0
- package/dist/assets/characters/character-male-c.glb +0 -0
- package/dist/assets/characters/character-male-d.glb +0 -0
- package/dist/assets/characters/character-male-e.glb +0 -0
- package/dist/assets/characters/character-male-f.glb +0 -0
- package/dist/assets/icons/icon-192.png +0 -0
- package/dist/assets/icons/icon-512.png +0 -0
- package/dist/assets/landing-Cc0MDBAK.css +1 -0
- package/dist/assets/main-BIpLsrUu.css +1 -0
- package/dist/assets/main-DMTRw3br.js +276 -0
- package/dist/assets/textures/concrete_floor_worn_001_diff_1k.jpg +0 -0
- package/dist/assets/textures/logo-blanco.png +0 -0
- package/dist/assets/vendor-react-uS-d4TUT.js +17 -0
- package/dist/assets/vendor-three-4iQNXcoo.js +3828 -0
- package/dist/assets/web-BZdi2lG9.js +1 -0
- package/dist/assets/web-yHsOO1Qb.js +1 -0
- package/dist/index.html +38 -0
- package/dist/manifest.json +39 -0
- package/dist/src/packages/landing/index.html +463 -0
- package/dist/src/packages/server/app.js +87 -0
- package/dist/src/packages/server/auth/index.js +121 -0
- package/dist/src/packages/server/claude/backend.js +578 -0
- package/dist/src/packages/server/claude/index.js +8 -0
- package/dist/src/packages/server/claude/runner/internal-events.js +22 -0
- package/dist/src/packages/server/claude/runner/process-lifecycle.js +208 -0
- package/dist/src/packages/server/claude/runner/recovery-store.js +72 -0
- package/dist/src/packages/server/claude/runner/resource-monitor.js +51 -0
- package/dist/src/packages/server/claude/runner/restart-policy.js +69 -0
- package/dist/src/packages/server/claude/runner/stdout-pipeline.js +153 -0
- package/dist/src/packages/server/claude/runner/watchdog.js +114 -0
- package/dist/src/packages/server/claude/runner.js +310 -0
- package/dist/src/packages/server/claude/session-loader.js +898 -0
- package/dist/src/packages/server/claude/types.js +5 -0
- package/dist/src/packages/server/cli.js +113 -0
- package/dist/src/packages/server/codex/backend.js +119 -0
- package/dist/src/packages/server/codex/index.js +2 -0
- package/dist/src/packages/server/codex/json-event-parser.js +612 -0
- package/dist/src/packages/server/data/builtin-skills/bitbucket-pr.js +298 -0
- package/dist/src/packages/server/data/builtin-skills/full-notifications.js +49 -0
- package/dist/src/packages/server/data/builtin-skills/git-captain.js +304 -0
- package/dist/src/packages/server/data/builtin-skills/index.js +61 -0
- package/dist/src/packages/server/data/builtin-skills/pm2-logs.js +354 -0
- package/dist/src/packages/server/data/builtin-skills/send-message-to-agent.js +51 -0
- package/dist/src/packages/server/data/builtin-skills/server-logs.js +124 -0
- package/dist/src/packages/server/data/builtin-skills/streaming-exec.js +94 -0
- package/dist/src/packages/server/data/builtin-skills/types.js +4 -0
- package/dist/src/packages/server/data/builtin-skills.js +6 -0
- package/dist/src/packages/server/data/index.js +890 -0
- package/dist/src/packages/server/data/snapshots.js +371 -0
- package/dist/src/packages/server/index.js +96 -0
- package/dist/src/packages/server/prompts/tide-commander.js +13 -0
- package/dist/src/packages/server/routes/agents.js +406 -0
- package/dist/src/packages/server/routes/config.js +347 -0
- package/dist/src/packages/server/routes/custom-models.js +170 -0
- package/dist/src/packages/server/routes/exec.js +269 -0
- package/dist/src/packages/server/routes/files.js +995 -0
- package/dist/src/packages/server/routes/index.js +38 -0
- package/dist/src/packages/server/routes/notifications.js +81 -0
- package/dist/src/packages/server/routes/permissions.js +115 -0
- package/dist/src/packages/server/routes/snapshots.js +224 -0
- package/dist/src/packages/server/routes/stt.js +99 -0
- package/dist/src/packages/server/routes/tts.js +166 -0
- package/dist/src/packages/server/routes/voice-assistant.js +310 -0
- package/dist/src/packages/server/runtime/claude-runtime-provider.js +10 -0
- package/dist/src/packages/server/runtime/codex-runtime-provider.js +11 -0
- package/dist/src/packages/server/runtime/index.js +2 -0
- package/dist/src/packages/server/runtime/types.js +6 -0
- package/dist/src/packages/server/services/agent-lifecycle-service.js +82 -0
- package/dist/src/packages/server/services/agent-service.js +410 -0
- package/dist/src/packages/server/services/boss-message-service.js +430 -0
- package/dist/src/packages/server/services/boss-service.js +553 -0
- package/dist/src/packages/server/services/building-service.js +867 -0
- package/dist/src/packages/server/services/claude-service.js +5 -0
- package/dist/src/packages/server/services/custom-class-service.js +323 -0
- package/dist/src/packages/server/services/database-service.js +914 -0
- package/dist/src/packages/server/services/docker-service.js +865 -0
- package/dist/src/packages/server/services/fileTracker.js +242 -0
- package/dist/src/packages/server/services/index.js +21 -0
- package/dist/src/packages/server/services/permission-service.js +258 -0
- package/dist/src/packages/server/services/pm2-service.js +435 -0
- package/dist/src/packages/server/services/runtime-command-execution.js +168 -0
- package/dist/src/packages/server/services/runtime-events.js +357 -0
- package/dist/src/packages/server/services/runtime-service.js +308 -0
- package/dist/src/packages/server/services/runtime-status-sync.js +104 -0
- package/dist/src/packages/server/services/runtime-subagents.js +50 -0
- package/dist/src/packages/server/services/runtime-watchdog.js +74 -0
- package/dist/src/packages/server/services/secrets-service.js +206 -0
- package/dist/src/packages/server/services/skill-service.js +508 -0
- package/dist/src/packages/server/services/subordinate-context-service.js +223 -0
- package/dist/src/packages/server/services/supervisor-claude.js +132 -0
- package/dist/src/packages/server/services/supervisor-prompts.js +80 -0
- package/dist/src/packages/server/services/supervisor-service.js +659 -0
- package/dist/src/packages/server/services/work-plan-service.js +476 -0
- package/dist/src/packages/server/setup.js +86 -0
- package/dist/src/packages/server/utils/index.js +4 -0
- package/dist/src/packages/server/utils/logger.js +302 -0
- package/dist/src/packages/server/utils/string.js +39 -0
- package/dist/src/packages/server/utils/tool-formatting.js +139 -0
- package/dist/src/packages/server/utils/unicode.js +46 -0
- package/dist/src/packages/server/websocket/handler.js +290 -0
- package/dist/src/packages/server/websocket/handlers/agent-handler.js +515 -0
- package/dist/src/packages/server/websocket/handlers/boss-handler.js +116 -0
- package/dist/src/packages/server/websocket/handlers/boss-response-handler.js +250 -0
- package/dist/src/packages/server/websocket/handlers/building-handler.js +298 -0
- package/dist/src/packages/server/websocket/handlers/command-handler.js +217 -0
- package/dist/src/packages/server/websocket/handlers/custom-class-handler.js +68 -0
- package/dist/src/packages/server/websocket/handlers/database-handler.js +223 -0
- package/dist/src/packages/server/websocket/handlers/notification-handler.js +25 -0
- package/dist/src/packages/server/websocket/handlers/permission-handler.js +21 -0
- package/dist/src/packages/server/websocket/handlers/secrets-handler.js +61 -0
- package/dist/src/packages/server/websocket/handlers/skill-handler.js +148 -0
- package/dist/src/packages/server/websocket/handlers/supervisor-handler.js +44 -0
- package/dist/src/packages/server/websocket/handlers/sync-handler.js +19 -0
- package/dist/src/packages/server/websocket/handlers/types.js +4 -0
- package/dist/src/packages/server/websocket/listeners/boss-listeners.js +21 -0
- package/dist/src/packages/server/websocket/listeners/index.js +32 -0
- package/dist/src/packages/server/websocket/listeners/permission-listeners.js +19 -0
- package/dist/src/packages/server/websocket/listeners/runtime-listeners.js +196 -0
- package/dist/src/packages/server/websocket/listeners/skill-listeners.js +51 -0
- package/dist/src/packages/server/websocket/listeners/supervisor-listeners.js +37 -0
- package/dist/src/packages/shared/agent-types.js +54 -0
- package/dist/src/packages/shared/building-types.js +43 -0
- package/dist/src/packages/shared/common-types.js +1 -0
- package/dist/src/packages/shared/database-types.js +8 -0
- package/dist/src/packages/shared/types/snapshot.js +7 -0
- package/dist/src/packages/shared/types.js +12 -0
- package/dist/src/packages/shared/websocket-messages.js +1 -0
- package/dist/sw.js +37 -0
- package/package.json +90 -0
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Code Process Runner
|
|
3
|
+
* Spawns and manages Claude Code CLI processes with streaming output
|
|
4
|
+
*/
|
|
5
|
+
import { ClaudeBackend } from './backend.js';
|
|
6
|
+
import { createLogger } from '../utils/logger.js';
|
|
7
|
+
import { isProcessRunning } from '../data/index.js';
|
|
8
|
+
import { RunnerInternalEventBus } from './runner/internal-events.js';
|
|
9
|
+
import { RunnerStdoutPipeline } from './runner/stdout-pipeline.js';
|
|
10
|
+
import { RunnerProcessLifecycle } from './runner/process-lifecycle.js';
|
|
11
|
+
import { RunnerRestartPolicy } from './runner/restart-policy.js';
|
|
12
|
+
import { RunnerWatchdog } from './runner/watchdog.js';
|
|
13
|
+
import { RunnerRecoveryStore } from './runner/recovery-store.js';
|
|
14
|
+
import { RunnerResourceMonitor } from './runner/resource-monitor.js';
|
|
15
|
+
const log = createLogger('Runner');
|
|
16
|
+
const PERSIST_INTERVAL = 10000;
|
|
17
|
+
const WATCHDOG_INTERVAL = 5000;
|
|
18
|
+
export class ClaudeRunner {
|
|
19
|
+
backend;
|
|
20
|
+
callbacks;
|
|
21
|
+
activeProcesses = new Map();
|
|
22
|
+
lastStderr = new Map();
|
|
23
|
+
activityCallbacks = new Map();
|
|
24
|
+
autoRestartEnabled = true;
|
|
25
|
+
persistTimer = null;
|
|
26
|
+
watchdogTimer = null;
|
|
27
|
+
bus;
|
|
28
|
+
stdoutPipeline;
|
|
29
|
+
lifecycle;
|
|
30
|
+
restartPolicy;
|
|
31
|
+
watchdog;
|
|
32
|
+
recoveryStore;
|
|
33
|
+
resourceMonitor;
|
|
34
|
+
constructor(callbacks, backend) {
|
|
35
|
+
this.backend = backend ?? new ClaudeBackend();
|
|
36
|
+
this.callbacks = callbacks;
|
|
37
|
+
this.bus = new RunnerInternalEventBus();
|
|
38
|
+
this.stdoutPipeline = new RunnerStdoutPipeline({
|
|
39
|
+
backend: this.backend,
|
|
40
|
+
callbacks: this.callbacks,
|
|
41
|
+
bus: this.bus,
|
|
42
|
+
});
|
|
43
|
+
this.recoveryStore = new RunnerRecoveryStore({
|
|
44
|
+
backend: this.backend,
|
|
45
|
+
activeProcesses: this.activeProcesses,
|
|
46
|
+
run: (request) => this.run(request),
|
|
47
|
+
});
|
|
48
|
+
this.lifecycle = new RunnerProcessLifecycle({
|
|
49
|
+
backend: this.backend,
|
|
50
|
+
callbacks: this.callbacks,
|
|
51
|
+
activeProcesses: this.activeProcesses,
|
|
52
|
+
lastStderr: this.lastStderr,
|
|
53
|
+
activityCallbacks: this.activityCallbacks,
|
|
54
|
+
bus: this.bus,
|
|
55
|
+
stdoutPipeline: this.stdoutPipeline,
|
|
56
|
+
recoveryStore: this.recoveryStore,
|
|
57
|
+
onDisableAutoRestart: () => {
|
|
58
|
+
this.autoRestartEnabled = false;
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
this.restartPolicy = new RunnerRestartPolicy({
|
|
62
|
+
callbacks: this.callbacks,
|
|
63
|
+
activeProcesses: this.activeProcesses,
|
|
64
|
+
getAutoRestartEnabled: () => this.autoRestartEnabled,
|
|
65
|
+
run: (request) => this.run(request),
|
|
66
|
+
});
|
|
67
|
+
this.watchdog = new RunnerWatchdog({
|
|
68
|
+
activeProcesses: this.activeProcesses,
|
|
69
|
+
lastStderr: this.lastStderr,
|
|
70
|
+
bus: this.bus,
|
|
71
|
+
});
|
|
72
|
+
this.resourceMonitor = new RunnerResourceMonitor({
|
|
73
|
+
activeProcesses: this.activeProcesses,
|
|
74
|
+
});
|
|
75
|
+
this.wireInternalEvents();
|
|
76
|
+
this.persistTimer = setInterval(() => {
|
|
77
|
+
this.recoveryStore.persistRunningProcesses();
|
|
78
|
+
}, PERSIST_INTERVAL);
|
|
79
|
+
this.watchdogTimer = setInterval(() => {
|
|
80
|
+
this.watchdog.runWatchdog();
|
|
81
|
+
}, WATCHDOG_INTERVAL);
|
|
82
|
+
this.recoveryStore.recoverOrphanedProcesses();
|
|
83
|
+
log.log('🛡️ Runner initialized with auto-restart and watchdog enabled');
|
|
84
|
+
}
|
|
85
|
+
wireInternalEvents() {
|
|
86
|
+
this.bus.on('runner.activity', ({ agentId, timestamp }) => {
|
|
87
|
+
const activeProcess = this.activeProcesses.get(agentId);
|
|
88
|
+
if (activeProcess) {
|
|
89
|
+
activeProcess.lastActivityTime = timestamp;
|
|
90
|
+
}
|
|
91
|
+
const callbacks = this.activityCallbacks.get(agentId);
|
|
92
|
+
if (!callbacks || callbacks.length === 0) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
for (const callback of callbacks) {
|
|
96
|
+
try {
|
|
97
|
+
callback();
|
|
98
|
+
}
|
|
99
|
+
catch (err) {
|
|
100
|
+
log.error(`Activity callback error for ${agentId}:`, err);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
this.activityCallbacks.delete(agentId);
|
|
104
|
+
});
|
|
105
|
+
this.bus.on('runner.session_id', ({ agentId, sessionId }) => {
|
|
106
|
+
const activeProcess = this.activeProcesses.get(agentId);
|
|
107
|
+
if (!activeProcess) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
activeProcess.sessionId = sessionId;
|
|
111
|
+
if (activeProcess.lastRequest && !activeProcess.lastRequest.sessionId) {
|
|
112
|
+
activeProcess.lastRequest.sessionId = sessionId;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
this.bus.on('runner.process_spawned', ({ agentId, pid }) => {
|
|
116
|
+
log.log(`🚀 [SPAWN] Agent ${agentId}: Process started with pid ${pid}`);
|
|
117
|
+
});
|
|
118
|
+
this.bus.on('runner.process_spawn_error', ({ agentId, error }) => {
|
|
119
|
+
log.error(`❌ [SPAWN ERROR] Agent ${agentId}: Failed to spawn process: ${error.message}`);
|
|
120
|
+
this.activeProcesses.delete(agentId);
|
|
121
|
+
this.callbacks.onError(agentId, error.message);
|
|
122
|
+
});
|
|
123
|
+
this.bus.on('runner.watchdog_missing_process', ({ agentId, activeProcess }) => {
|
|
124
|
+
this.restartPolicy.maybeAutoRestart(agentId, activeProcess, null, null);
|
|
125
|
+
});
|
|
126
|
+
this.bus.on('runner.process_closed', ({ agentId, pid, code, signal }) => {
|
|
127
|
+
const wasTracked = this.activeProcesses.has(agentId);
|
|
128
|
+
const trackedProcess = this.activeProcesses.get(agentId);
|
|
129
|
+
const runtime = trackedProcess ? Date.now() - trackedProcess.startTime : 0;
|
|
130
|
+
const deathInfo = {
|
|
131
|
+
agentId,
|
|
132
|
+
pid,
|
|
133
|
+
exitCode: code,
|
|
134
|
+
signal,
|
|
135
|
+
runtime,
|
|
136
|
+
wasTracked,
|
|
137
|
+
timestamp: Date.now(),
|
|
138
|
+
stderr: this.lastStderr.get(agentId),
|
|
139
|
+
};
|
|
140
|
+
this.activeProcesses.delete(agentId);
|
|
141
|
+
this.lastStderr.delete(agentId);
|
|
142
|
+
if (signal) {
|
|
143
|
+
if (signal === 'SIGINT') {
|
|
144
|
+
log.log(`🛑 [EXIT] Agent ${agentId}: Process terminated by SIGINT (user interrupt), pid was ${pid}, runtime ${(runtime / 1000).toFixed(1)}s`);
|
|
145
|
+
}
|
|
146
|
+
else if (signal === 'SIGTERM') {
|
|
147
|
+
log.log(`🛑 [EXIT] Agent ${agentId}: Process terminated by SIGTERM (stop request), pid was ${pid}, runtime ${(runtime / 1000).toFixed(1)}s`);
|
|
148
|
+
}
|
|
149
|
+
else if (signal === 'SIGKILL') {
|
|
150
|
+
log.log(`🛑 [EXIT] Agent ${agentId}: Process force-killed by SIGKILL, pid was ${pid}, runtime ${(runtime / 1000).toFixed(1)}s`);
|
|
151
|
+
this.watchdog.recordDeath(deathInfo);
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
log.log(`⚠️ [EXIT] Agent ${agentId}: Process killed by signal ${signal}, pid was ${pid}, runtime ${(runtime / 1000).toFixed(1)}s`);
|
|
155
|
+
this.watchdog.recordDeath(deathInfo);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
else if (code === 0) {
|
|
159
|
+
log.log(`✅ [EXIT] Agent ${agentId}: Process completed successfully (exit code 0), pid was ${pid}, runtime ${(runtime / 1000).toFixed(1)}s`);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
log.error(`❌ [EXIT] Agent ${agentId}: Process exited with error code ${code}, pid was ${pid}, runtime ${(runtime / 1000).toFixed(1)}s${!wasTracked ? ' (unexpected - was not being tracked)' : ''}`);
|
|
163
|
+
this.watchdog.recordDeath(deathInfo);
|
|
164
|
+
}
|
|
165
|
+
if (!wasTracked && (signal === 'SIGINT' || signal === 'SIGTERM')) {
|
|
166
|
+
log.log(`⏭️ [EXIT] Agent ${agentId}: Skipping onComplete - process was explicitly stopped (signal=${signal})`);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
this.callbacks.onComplete(agentId, code === 0);
|
|
170
|
+
}
|
|
171
|
+
if (trackedProcess && code !== 0 && signal !== 'SIGINT' && signal !== 'SIGTERM') {
|
|
172
|
+
this.restartPolicy.maybeAutoRestart(agentId, trackedProcess, code, signal);
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
supportsStdin() {
|
|
177
|
+
return this.backend.requiresStdinInput();
|
|
178
|
+
}
|
|
179
|
+
setAutoRestart(enabled) {
|
|
180
|
+
this.autoRestartEnabled = enabled;
|
|
181
|
+
log.log(`🔄 Auto-restart ${enabled ? 'enabled' : 'disabled'}`);
|
|
182
|
+
}
|
|
183
|
+
getDeathHistory() {
|
|
184
|
+
return this.watchdog.getDeathHistory();
|
|
185
|
+
}
|
|
186
|
+
getActiveProcessesState() {
|
|
187
|
+
const now = Date.now();
|
|
188
|
+
return Array.from(this.activeProcesses.entries()).map(([agentId, proc]) => ({
|
|
189
|
+
agentId,
|
|
190
|
+
pid: proc.process.pid,
|
|
191
|
+
runtimeSec: (now - proc.startTime) / 1000,
|
|
192
|
+
lastActivitySec: proc.lastActivityTime ? (now - proc.lastActivityTime) / 1000 : -1,
|
|
193
|
+
hasError: !!proc.lastError,
|
|
194
|
+
stdinWritable: !!(proc.process.stdin && proc.process.stdin.writable),
|
|
195
|
+
}));
|
|
196
|
+
}
|
|
197
|
+
logProcessDiagnostics() {
|
|
198
|
+
const state = this.getActiveProcessesState();
|
|
199
|
+
const count = state.length;
|
|
200
|
+
if (count === 0) {
|
|
201
|
+
log.log('📊 [DIAGNOSTICS] No active processes');
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
log.log(`📊 [DIAGNOSTICS] ${count} active process(es):`);
|
|
205
|
+
for (const proc of state) {
|
|
206
|
+
const errorStr = proc.hasError ? ' ❌ERROR' : '';
|
|
207
|
+
const stdinStr = proc.stdinWritable ? ' ✅stdin' : ' ❌stdin';
|
|
208
|
+
log.log(` ${proc.agentId.slice(0, 8)}: PID=${proc.pid} runtime=${proc.runtimeSec.toFixed(1)}s activity=${proc.lastActivitySec >= 0 ? `${proc.lastActivitySec.toFixed(1)}s` : 'none'}${stdinStr}${errorStr}`);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
async run(request) {
|
|
212
|
+
await this.lifecycle.run(request);
|
|
213
|
+
}
|
|
214
|
+
sendMessage(agentId, message) {
|
|
215
|
+
const activeProcess = this.activeProcesses.get(agentId);
|
|
216
|
+
if (!activeProcess) {
|
|
217
|
+
log.error(`❌ [SEND_MESSAGE] No active process for agent ${agentId}`);
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
const stdin = activeProcess.process.stdin;
|
|
221
|
+
if (!stdin) {
|
|
222
|
+
log.error(`❌ [SEND_MESSAGE] stdin is null for agent ${agentId}`);
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
if (!stdin.writable) {
|
|
226
|
+
log.error(`❌ [SEND_MESSAGE] stdin is not writable for agent ${agentId} (destroyed: ${stdin.destroyed}, closed: ${stdin.closed})`);
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
const stdinInput = this.backend.formatStdinInput(message);
|
|
230
|
+
const messageLen = message.length;
|
|
231
|
+
stdin.write(stdinInput + '\n', 'utf8', (err) => {
|
|
232
|
+
if (err) {
|
|
233
|
+
log.error(`❌ [SEND_MESSAGE] Failed to write ${messageLen} chars to stdin for ${agentId}: ${err.message}`);
|
|
234
|
+
activeProcess.lastError = {
|
|
235
|
+
type: 'stdin_write_error',
|
|
236
|
+
message: err.message,
|
|
237
|
+
timestamp: Date.now(),
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
log.log(`✅ [SEND_MESSAGE] Successfully wrote ${messageLen} chars to ${agentId}`);
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
return true;
|
|
245
|
+
}
|
|
246
|
+
interrupt(agentId) {
|
|
247
|
+
return this.lifecycle.interrupt(agentId);
|
|
248
|
+
}
|
|
249
|
+
getActiveProcessCount() {
|
|
250
|
+
return this.activeProcesses.size;
|
|
251
|
+
}
|
|
252
|
+
async stop(agentId) {
|
|
253
|
+
await this.lifecycle.stop(agentId);
|
|
254
|
+
}
|
|
255
|
+
async stopAll(killProcesses = true) {
|
|
256
|
+
if (this.persistTimer) {
|
|
257
|
+
clearInterval(this.persistTimer);
|
|
258
|
+
this.persistTimer = null;
|
|
259
|
+
}
|
|
260
|
+
if (this.watchdogTimer) {
|
|
261
|
+
clearInterval(this.watchdogTimer);
|
|
262
|
+
this.watchdogTimer = null;
|
|
263
|
+
}
|
|
264
|
+
await this.lifecycle.stopAll(killProcesses);
|
|
265
|
+
}
|
|
266
|
+
isRunning(agentId) {
|
|
267
|
+
const activeProcess = this.activeProcesses.get(agentId);
|
|
268
|
+
if (!activeProcess) {
|
|
269
|
+
return false;
|
|
270
|
+
}
|
|
271
|
+
const pid = activeProcess.process.pid;
|
|
272
|
+
if (!pid) {
|
|
273
|
+
this.activeProcesses.delete(agentId);
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
const actuallyRunning = isProcessRunning(pid);
|
|
277
|
+
if (!actuallyRunning) {
|
|
278
|
+
this.activeProcesses.delete(agentId);
|
|
279
|
+
this.lastStderr.delete(agentId);
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
return true;
|
|
283
|
+
}
|
|
284
|
+
getSessionId(agentId) {
|
|
285
|
+
return this.activeProcesses.get(agentId)?.sessionId;
|
|
286
|
+
}
|
|
287
|
+
hasRecentActivity(agentId, withinMs) {
|
|
288
|
+
const activeProcess = this.activeProcesses.get(agentId);
|
|
289
|
+
if (!activeProcess) {
|
|
290
|
+
return false;
|
|
291
|
+
}
|
|
292
|
+
const lastActivity = activeProcess.lastActivityTime || activeProcess.startTime;
|
|
293
|
+
return Date.now() - lastActivity < withinMs;
|
|
294
|
+
}
|
|
295
|
+
onNextActivity(agentId, callback) {
|
|
296
|
+
if (!this.activityCallbacks.has(agentId)) {
|
|
297
|
+
this.activityCallbacks.set(agentId, []);
|
|
298
|
+
}
|
|
299
|
+
this.activityCallbacks.get(agentId).push(callback);
|
|
300
|
+
}
|
|
301
|
+
clearActivityCallbacks(agentId) {
|
|
302
|
+
this.activityCallbacks.delete(agentId);
|
|
303
|
+
}
|
|
304
|
+
getProcessMemoryMB(agentId) {
|
|
305
|
+
return this.resourceMonitor.getProcessMemoryMB(agentId);
|
|
306
|
+
}
|
|
307
|
+
getAllProcessMemory() {
|
|
308
|
+
return this.resourceMonitor.getAllProcessMemory();
|
|
309
|
+
}
|
|
310
|
+
}
|