agentosity 0.1.3 → 0.1.4
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/package.json +1 -1
- package/src/probes.js +19 -6
package/package.json
CHANGED
package/src/probes.js
CHANGED
|
@@ -70,6 +70,7 @@ export function createProbe(harness, processStartMs) {
|
|
|
70
70
|
tail: target?.tail ?? false,
|
|
71
71
|
lastMtimeMs: 0,
|
|
72
72
|
lastWriteAt: 0,
|
|
73
|
+
baselineChildren: null, // harness 的常驻子进程基线(其他 MCP server 等),它们在 ≠ 在干活
|
|
73
74
|
};
|
|
74
75
|
|
|
75
76
|
function bindFile() {
|
|
@@ -149,18 +150,30 @@ export function createProbe(harness, processStartMs) {
|
|
|
149
150
|
}
|
|
150
151
|
}
|
|
151
152
|
|
|
152
|
-
/** 信号 3:harness(父进程)
|
|
153
|
+
/** 信号 3:harness(父进程)出现了基线之外的新子进程(= 工具调用在跑)。
|
|
154
|
+
* 基线 = 探针启动时已存在的子进程(自己和其他常驻 MCP server),它们一直在,不代表在干活。 */
|
|
153
155
|
function childActive() {
|
|
154
156
|
try {
|
|
155
157
|
const out = execFileSync("pgrep", ["-P", String(process.ppid)], {
|
|
156
158
|
encoding: "utf8",
|
|
157
159
|
timeout: 3000,
|
|
158
160
|
});
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
161
|
+
const current = new Set(
|
|
162
|
+
out
|
|
163
|
+
.split("\n")
|
|
164
|
+
.map((s) => parseInt(s, 10))
|
|
165
|
+
.filter((pid) => pid && pid !== process.pid)
|
|
166
|
+
);
|
|
167
|
+
if (state.baselineChildren === null) {
|
|
168
|
+
state.baselineChildren = current;
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
// 死掉的移出基线;有基线外的新面孔才算干活
|
|
172
|
+
state.baselineChildren = new Set([...state.baselineChildren].filter((p) => current.has(p)));
|
|
173
|
+
for (const p of current) {
|
|
174
|
+
if (!state.baselineChildren.has(p)) return true;
|
|
175
|
+
}
|
|
176
|
+
return false;
|
|
164
177
|
} catch {
|
|
165
178
|
return false; // pgrep 无匹配时 exit 1,也走这里 → 视为无子进程
|
|
166
179
|
}
|