diff --git a/com.streamdock.ai-monitor.sdPlugin/plugin/index.js b/com.streamdock.ai-monitor.sdPlugin/plugin/index.js index 9999f72..83574dc 100644 --- a/com.streamdock.ai-monitor.sdPlugin/plugin/index.js +++ b/com.streamdock.ai-monitor.sdPlugin/plugin/index.js @@ -164,11 +164,22 @@ function tailFile(filePath, ctx, agent) { function poll(ctx) { var ss = states[ctx]; if (!ss || !ss.agent) return; var detected = false; - var files = findFiles(ss.agent.scanDir, '.jsonl'); - files.sort(function(a,b) { return fs.statSync(b).mtimeMs - fs.statSync(a).mtimeMs; }); - for (var i = 0; i < Math.min(files.length, 3); i++) { if (tailFile(files[i], ctx, ss.agent)) detected = true; } + if (ss.agent.type === "process") { + // Process-based monitoring: check if the named process exists + try { + var check = childProcess.execSync("cmd /c tasklist", { timeout: 500, encoding: "utf-8" }); + if (check.indexOf(ss.agent.processName) >= 0) { + setState(ctx, "working"); + detected = true; + } + } catch (_) {} + } else { + var files = findFiles(ss.agent.scanDir, ".jsonl"); + files.sort(function(a,b) { return fs.statSync(b).mtimeMs - fs.statSync(a).mtimeMs; }); + for (var i = 0; i < Math.min(files.length, 3); i++) { if (tailFile(files[i], ctx, ss.agent)) detected = true; } + } if (detected) ss.lastActivity = Date.now(); - if (ss.currentState !== 'idle' && ss.currentState !== 'done' && Date.now() - ss.lastActivity > IDLE_TIMEOUT_MS) { setState(ctx, 'idle'); } + if (ss.currentState !== "idle" && ss.currentState !== "done" && Date.now() - ss.lastActivity > IDLE_TIMEOUT_MS) { setState(ctx, "idle"); } } function makeActionFn(agentKey) {