@fro.bot/space-bus 0.7.0 → 0.7.1
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/dist/attach.js +1 -1
- package/dist/cli.js +58 -10
- package/dist/config.js +3 -3
- package/dist/contract.js +1 -1
- package/dist/core.js +1 -1
- package/dist/index.js +58 -10
- package/dist/mcp.js +59 -11
- package/dist/server.d.ts +0 -9
- package/dist/server.js +58 -10
- package/package.json +1 -1
package/dist/attach.js
CHANGED
|
@@ -103,7 +103,7 @@ var managedSpawnConfigSchema = z.object({
|
|
|
103
103
|
});
|
|
104
104
|
var discoveryFileSchema = z.object({
|
|
105
105
|
port: z.number().int().nonnegative(),
|
|
106
|
-
pid: z.number().int().
|
|
106
|
+
pid: z.number().int().min(2),
|
|
107
107
|
identity: z.string(),
|
|
108
108
|
password: z.string(),
|
|
109
109
|
spawnConfig: managedSpawnConfigSchema,
|
package/dist/cli.js
CHANGED
|
@@ -104,7 +104,7 @@ var managedSpawnConfigSchema = z.object({
|
|
|
104
104
|
});
|
|
105
105
|
var discoveryFileSchema = z.object({
|
|
106
106
|
port: z.number().int().nonnegative(),
|
|
107
|
-
pid: z.number().int().
|
|
107
|
+
pid: z.number().int().min(2),
|
|
108
108
|
identity: z.string(),
|
|
109
109
|
password: z.string(),
|
|
110
110
|
spawnConfig: managedSpawnConfigSchema,
|
|
@@ -231,7 +231,7 @@ function verifyIdentity(pid, storedIdentity) {
|
|
|
231
231
|
return current !== null && current === storedIdentity;
|
|
232
232
|
}
|
|
233
233
|
var lockFileSchema = z2.object({
|
|
234
|
-
pid: z2.number().int().
|
|
234
|
+
pid: z2.number().int().min(2),
|
|
235
235
|
startTime: z2.string(),
|
|
236
236
|
since: z2.number()
|
|
237
237
|
});
|
|
@@ -327,7 +327,7 @@ function provisionalFilePath(rosterPath) {
|
|
|
327
327
|
return join(stateDirFor(rosterPath), "spawn.provisional.json");
|
|
328
328
|
}
|
|
329
329
|
var provisionalFileSchema = z2.object({
|
|
330
|
-
pid: z2.number().int().
|
|
330
|
+
pid: z2.number().int().min(2),
|
|
331
331
|
identity: z2.string(),
|
|
332
332
|
password: z2.string(),
|
|
333
333
|
since: z2.number()
|
|
@@ -523,11 +523,34 @@ function redactedReadinessError(rosterPath, password, reason) {
|
|
|
523
523
|
return new Error(`space-bus: managed server for roster ${rosterPath} ${reason}. Log tail:
|
|
524
524
|
${tail}`);
|
|
525
525
|
}
|
|
526
|
+
function isEpermError(err) {
|
|
527
|
+
return typeof err === "object" && err !== null && "code" in err && err.code === "EPERM";
|
|
528
|
+
}
|
|
529
|
+
function signalGroup(pid, sig) {
|
|
530
|
+
if (pid <= 1) {
|
|
531
|
+
try {
|
|
532
|
+
process.kill(pid, sig);
|
|
533
|
+
} catch {}
|
|
534
|
+
return false;
|
|
535
|
+
}
|
|
536
|
+
try {
|
|
537
|
+
process.kill(-pid, sig);
|
|
538
|
+
return true;
|
|
539
|
+
} catch (err) {
|
|
540
|
+
if (err.code === "EPERM") {
|
|
541
|
+
throw err;
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
try {
|
|
545
|
+
process.kill(pid, sig);
|
|
546
|
+
} catch {}
|
|
547
|
+
return false;
|
|
548
|
+
}
|
|
526
549
|
function killIdentifiedProcess(pid, identity) {
|
|
527
550
|
try {
|
|
528
551
|
if (identity !== null && identity !== undefined && identity !== "") {
|
|
529
552
|
if (verifyIdentity(pid, identity))
|
|
530
|
-
|
|
553
|
+
signalGroup(pid, "SIGTERM");
|
|
531
554
|
return;
|
|
532
555
|
}
|
|
533
556
|
process.kill(pid, "SIGTERM");
|
|
@@ -776,23 +799,31 @@ async function stopServer(rosterPath) {
|
|
|
776
799
|
return { stopped: false };
|
|
777
800
|
}
|
|
778
801
|
const { pid } = discovery;
|
|
802
|
+
let groupSignaled;
|
|
803
|
+
const waitForCompletion = (budgetMs) => groupSignaled ? waitForGroupDeath(pid, budgetMs) : waitForDeath(pid, budgetMs);
|
|
779
804
|
try {
|
|
780
|
-
|
|
781
|
-
} catch {
|
|
805
|
+
groupSignaled = signalGroup(pid, "SIGTERM");
|
|
806
|
+
} catch (err) {
|
|
807
|
+
if (isEpermError(err)) {
|
|
808
|
+
return { stopped: false };
|
|
809
|
+
}
|
|
782
810
|
removeDiscovery(rosterPath);
|
|
783
811
|
return { stopped: true };
|
|
784
812
|
}
|
|
785
|
-
if (await
|
|
813
|
+
if (await waitForCompletion(STOP_GRACE_MS)) {
|
|
786
814
|
removeDiscovery(rosterPath);
|
|
787
815
|
return { stopped: true };
|
|
788
816
|
}
|
|
789
817
|
try {
|
|
790
|
-
|
|
791
|
-
} catch {
|
|
818
|
+
groupSignaled = signalGroup(pid, "SIGKILL");
|
|
819
|
+
} catch (err) {
|
|
820
|
+
if (isEpermError(err)) {
|
|
821
|
+
return { stopped: false };
|
|
822
|
+
}
|
|
792
823
|
removeDiscovery(rosterPath);
|
|
793
824
|
return { stopped: true };
|
|
794
825
|
}
|
|
795
|
-
if (await
|
|
826
|
+
if (await waitForCompletion(STOP_GRACE_MS)) {
|
|
796
827
|
removeDiscovery(rosterPath);
|
|
797
828
|
return { stopped: true };
|
|
798
829
|
}
|
|
@@ -807,6 +838,23 @@ async function waitForDeath(pid, budgetMs) {
|
|
|
807
838
|
}
|
|
808
839
|
return !isAlive(pid);
|
|
809
840
|
}
|
|
841
|
+
async function waitForGroupDeath(pid, budgetMs) {
|
|
842
|
+
const deadline = Date.now() + budgetMs;
|
|
843
|
+
const groupAlive = () => {
|
|
844
|
+
try {
|
|
845
|
+
process.kill(-pid, 0);
|
|
846
|
+
return true;
|
|
847
|
+
} catch {
|
|
848
|
+
return false;
|
|
849
|
+
}
|
|
850
|
+
};
|
|
851
|
+
while (Date.now() < deadline) {
|
|
852
|
+
if (!groupAlive())
|
|
853
|
+
return true;
|
|
854
|
+
await sleep(POLL_INTERVAL_MS);
|
|
855
|
+
}
|
|
856
|
+
return !groupAlive();
|
|
857
|
+
}
|
|
810
858
|
|
|
811
859
|
// src/cli.ts
|
|
812
860
|
var USAGE = `space-bus — thin CLI for the managed OpenCode bus server
|
package/dist/config.js
CHANGED
|
@@ -103,7 +103,7 @@ var managedSpawnConfigSchema = z.object({
|
|
|
103
103
|
});
|
|
104
104
|
var discoveryFileSchema = z.object({
|
|
105
105
|
port: z.number().int().nonnegative(),
|
|
106
|
-
pid: z.number().int().
|
|
106
|
+
pid: z.number().int().min(2),
|
|
107
107
|
identity: z.string(),
|
|
108
108
|
password: z.string(),
|
|
109
109
|
spawnConfig: managedSpawnConfigSchema,
|
|
@@ -230,7 +230,7 @@ function verifyIdentity(pid, storedIdentity) {
|
|
|
230
230
|
return current !== null && current === storedIdentity;
|
|
231
231
|
}
|
|
232
232
|
var lockFileSchema = z2.object({
|
|
233
|
-
pid: z2.number().int().
|
|
233
|
+
pid: z2.number().int().min(2),
|
|
234
234
|
startTime: z2.string(),
|
|
235
235
|
since: z2.number()
|
|
236
236
|
});
|
|
@@ -326,7 +326,7 @@ function provisionalFilePath(rosterPath) {
|
|
|
326
326
|
return join(stateDirFor(rosterPath), "spawn.provisional.json");
|
|
327
327
|
}
|
|
328
328
|
var provisionalFileSchema = z2.object({
|
|
329
|
-
pid: z2.number().int().
|
|
329
|
+
pid: z2.number().int().min(2),
|
|
330
330
|
identity: z2.string(),
|
|
331
331
|
password: z2.string(),
|
|
332
332
|
since: z2.number()
|
package/dist/contract.js
CHANGED
|
@@ -103,7 +103,7 @@ var managedSpawnConfigSchema = z.object({
|
|
|
103
103
|
});
|
|
104
104
|
var discoveryFileSchema = z.object({
|
|
105
105
|
port: z.number().int().nonnegative(),
|
|
106
|
-
pid: z.number().int().
|
|
106
|
+
pid: z.number().int().min(2),
|
|
107
107
|
identity: z.string(),
|
|
108
108
|
password: z.string(),
|
|
109
109
|
spawnConfig: managedSpawnConfigSchema,
|
package/dist/core.js
CHANGED
|
@@ -103,7 +103,7 @@ var managedSpawnConfigSchema = z.object({
|
|
|
103
103
|
});
|
|
104
104
|
var discoveryFileSchema = z.object({
|
|
105
105
|
port: z.number().int().nonnegative(),
|
|
106
|
-
pid: z.number().int().
|
|
106
|
+
pid: z.number().int().min(2),
|
|
107
107
|
identity: z.string(),
|
|
108
108
|
password: z.string(),
|
|
109
109
|
spawnConfig: managedSpawnConfigSchema,
|
package/dist/index.js
CHANGED
|
@@ -103,7 +103,7 @@ var managedSpawnConfigSchema = z.object({
|
|
|
103
103
|
});
|
|
104
104
|
var discoveryFileSchema = z.object({
|
|
105
105
|
port: z.number().int().nonnegative(),
|
|
106
|
-
pid: z.number().int().
|
|
106
|
+
pid: z.number().int().min(2),
|
|
107
107
|
identity: z.string(),
|
|
108
108
|
password: z.string(),
|
|
109
109
|
spawnConfig: managedSpawnConfigSchema,
|
|
@@ -815,7 +815,7 @@ function verifyIdentity(pid, storedIdentity) {
|
|
|
815
815
|
return current !== null && current === storedIdentity;
|
|
816
816
|
}
|
|
817
817
|
var lockFileSchema = z2.object({
|
|
818
|
-
pid: z2.number().int().
|
|
818
|
+
pid: z2.number().int().min(2),
|
|
819
819
|
startTime: z2.string(),
|
|
820
820
|
since: z2.number()
|
|
821
821
|
});
|
|
@@ -911,7 +911,7 @@ function provisionalFilePath(rosterPath) {
|
|
|
911
911
|
return join(stateDirFor(rosterPath), "spawn.provisional.json");
|
|
912
912
|
}
|
|
913
913
|
var provisionalFileSchema = z2.object({
|
|
914
|
-
pid: z2.number().int().
|
|
914
|
+
pid: z2.number().int().min(2),
|
|
915
915
|
identity: z2.string(),
|
|
916
916
|
password: z2.string(),
|
|
917
917
|
since: z2.number()
|
|
@@ -1107,11 +1107,34 @@ function redactedReadinessError(rosterPath, password, reason) {
|
|
|
1107
1107
|
return new Error(`space-bus: managed server for roster ${rosterPath} ${reason}. Log tail:
|
|
1108
1108
|
${tail}`);
|
|
1109
1109
|
}
|
|
1110
|
+
function isEpermError(err2) {
|
|
1111
|
+
return typeof err2 === "object" && err2 !== null && "code" in err2 && err2.code === "EPERM";
|
|
1112
|
+
}
|
|
1113
|
+
function signalGroup(pid, sig) {
|
|
1114
|
+
if (pid <= 1) {
|
|
1115
|
+
try {
|
|
1116
|
+
process.kill(pid, sig);
|
|
1117
|
+
} catch {}
|
|
1118
|
+
return false;
|
|
1119
|
+
}
|
|
1120
|
+
try {
|
|
1121
|
+
process.kill(-pid, sig);
|
|
1122
|
+
return true;
|
|
1123
|
+
} catch (err2) {
|
|
1124
|
+
if (err2.code === "EPERM") {
|
|
1125
|
+
throw err2;
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
try {
|
|
1129
|
+
process.kill(pid, sig);
|
|
1130
|
+
} catch {}
|
|
1131
|
+
return false;
|
|
1132
|
+
}
|
|
1110
1133
|
function killIdentifiedProcess(pid, identity) {
|
|
1111
1134
|
try {
|
|
1112
1135
|
if (identity !== null && identity !== undefined && identity !== "") {
|
|
1113
1136
|
if (verifyIdentity(pid, identity))
|
|
1114
|
-
|
|
1137
|
+
signalGroup(pid, "SIGTERM");
|
|
1115
1138
|
return;
|
|
1116
1139
|
}
|
|
1117
1140
|
process.kill(pid, "SIGTERM");
|
|
@@ -1360,23 +1383,31 @@ async function stopServer(rosterPath) {
|
|
|
1360
1383
|
return { stopped: false };
|
|
1361
1384
|
}
|
|
1362
1385
|
const { pid } = discovery;
|
|
1386
|
+
let groupSignaled;
|
|
1387
|
+
const waitForCompletion = (budgetMs) => groupSignaled ? waitForGroupDeath(pid, budgetMs) : waitForDeath(pid, budgetMs);
|
|
1363
1388
|
try {
|
|
1364
|
-
|
|
1365
|
-
} catch {
|
|
1389
|
+
groupSignaled = signalGroup(pid, "SIGTERM");
|
|
1390
|
+
} catch (err2) {
|
|
1391
|
+
if (isEpermError(err2)) {
|
|
1392
|
+
return { stopped: false };
|
|
1393
|
+
}
|
|
1366
1394
|
removeDiscovery(rosterPath);
|
|
1367
1395
|
return { stopped: true };
|
|
1368
1396
|
}
|
|
1369
|
-
if (await
|
|
1397
|
+
if (await waitForCompletion(STOP_GRACE_MS)) {
|
|
1370
1398
|
removeDiscovery(rosterPath);
|
|
1371
1399
|
return { stopped: true };
|
|
1372
1400
|
}
|
|
1373
1401
|
try {
|
|
1374
|
-
|
|
1375
|
-
} catch {
|
|
1402
|
+
groupSignaled = signalGroup(pid, "SIGKILL");
|
|
1403
|
+
} catch (err2) {
|
|
1404
|
+
if (isEpermError(err2)) {
|
|
1405
|
+
return { stopped: false };
|
|
1406
|
+
}
|
|
1376
1407
|
removeDiscovery(rosterPath);
|
|
1377
1408
|
return { stopped: true };
|
|
1378
1409
|
}
|
|
1379
|
-
if (await
|
|
1410
|
+
if (await waitForCompletion(STOP_GRACE_MS)) {
|
|
1380
1411
|
removeDiscovery(rosterPath);
|
|
1381
1412
|
return { stopped: true };
|
|
1382
1413
|
}
|
|
@@ -1391,6 +1422,23 @@ async function waitForDeath(pid, budgetMs) {
|
|
|
1391
1422
|
}
|
|
1392
1423
|
return !isAlive(pid);
|
|
1393
1424
|
}
|
|
1425
|
+
async function waitForGroupDeath(pid, budgetMs) {
|
|
1426
|
+
const deadline = Date.now() + budgetMs;
|
|
1427
|
+
const groupAlive = () => {
|
|
1428
|
+
try {
|
|
1429
|
+
process.kill(-pid, 0);
|
|
1430
|
+
return true;
|
|
1431
|
+
} catch {
|
|
1432
|
+
return false;
|
|
1433
|
+
}
|
|
1434
|
+
};
|
|
1435
|
+
while (Date.now() < deadline) {
|
|
1436
|
+
if (!groupAlive())
|
|
1437
|
+
return true;
|
|
1438
|
+
await sleep(POLL_INTERVAL_MS);
|
|
1439
|
+
}
|
|
1440
|
+
return !groupAlive();
|
|
1441
|
+
}
|
|
1394
1442
|
|
|
1395
1443
|
// src/tools/bus_result.ts
|
|
1396
1444
|
import { tool } from "@opencode-ai/plugin";
|
package/dist/mcp.js
CHANGED
|
@@ -104,7 +104,7 @@ var managedSpawnConfigSchema = z.object({
|
|
|
104
104
|
});
|
|
105
105
|
var discoveryFileSchema = z.object({
|
|
106
106
|
port: z.number().int().nonnegative(),
|
|
107
|
-
pid: z.number().int().
|
|
107
|
+
pid: z.number().int().min(2),
|
|
108
108
|
identity: z.string(),
|
|
109
109
|
password: z.string(),
|
|
110
110
|
spawnConfig: managedSpawnConfigSchema,
|
|
@@ -816,7 +816,7 @@ function verifyIdentity(pid, storedIdentity) {
|
|
|
816
816
|
return current !== null && current === storedIdentity;
|
|
817
817
|
}
|
|
818
818
|
var lockFileSchema = z2.object({
|
|
819
|
-
pid: z2.number().int().
|
|
819
|
+
pid: z2.number().int().min(2),
|
|
820
820
|
startTime: z2.string(),
|
|
821
821
|
since: z2.number()
|
|
822
822
|
});
|
|
@@ -912,7 +912,7 @@ function provisionalFilePath(rosterPath) {
|
|
|
912
912
|
return join(stateDirFor(rosterPath), "spawn.provisional.json");
|
|
913
913
|
}
|
|
914
914
|
var provisionalFileSchema = z2.object({
|
|
915
|
-
pid: z2.number().int().
|
|
915
|
+
pid: z2.number().int().min(2),
|
|
916
916
|
identity: z2.string(),
|
|
917
917
|
password: z2.string(),
|
|
918
918
|
since: z2.number()
|
|
@@ -1108,11 +1108,34 @@ function redactedReadinessError(rosterPath, password, reason) {
|
|
|
1108
1108
|
return new Error(`space-bus: managed server for roster ${rosterPath} ${reason}. Log tail:
|
|
1109
1109
|
${tail}`);
|
|
1110
1110
|
}
|
|
1111
|
+
function isEpermError(err2) {
|
|
1112
|
+
return typeof err2 === "object" && err2 !== null && "code" in err2 && err2.code === "EPERM";
|
|
1113
|
+
}
|
|
1114
|
+
function signalGroup(pid, sig) {
|
|
1115
|
+
if (pid <= 1) {
|
|
1116
|
+
try {
|
|
1117
|
+
process.kill(pid, sig);
|
|
1118
|
+
} catch {}
|
|
1119
|
+
return false;
|
|
1120
|
+
}
|
|
1121
|
+
try {
|
|
1122
|
+
process.kill(-pid, sig);
|
|
1123
|
+
return true;
|
|
1124
|
+
} catch (err2) {
|
|
1125
|
+
if (err2.code === "EPERM") {
|
|
1126
|
+
throw err2;
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
try {
|
|
1130
|
+
process.kill(pid, sig);
|
|
1131
|
+
} catch {}
|
|
1132
|
+
return false;
|
|
1133
|
+
}
|
|
1111
1134
|
function killIdentifiedProcess(pid, identity) {
|
|
1112
1135
|
try {
|
|
1113
1136
|
if (identity !== null && identity !== undefined && identity !== "") {
|
|
1114
1137
|
if (verifyIdentity(pid, identity))
|
|
1115
|
-
|
|
1138
|
+
signalGroup(pid, "SIGTERM");
|
|
1116
1139
|
return;
|
|
1117
1140
|
}
|
|
1118
1141
|
process.kill(pid, "SIGTERM");
|
|
@@ -1361,23 +1384,31 @@ async function stopServer(rosterPath) {
|
|
|
1361
1384
|
return { stopped: false };
|
|
1362
1385
|
}
|
|
1363
1386
|
const { pid } = discovery;
|
|
1387
|
+
let groupSignaled;
|
|
1388
|
+
const waitForCompletion = (budgetMs) => groupSignaled ? waitForGroupDeath(pid, budgetMs) : waitForDeath(pid, budgetMs);
|
|
1364
1389
|
try {
|
|
1365
|
-
|
|
1366
|
-
} catch {
|
|
1390
|
+
groupSignaled = signalGroup(pid, "SIGTERM");
|
|
1391
|
+
} catch (err2) {
|
|
1392
|
+
if (isEpermError(err2)) {
|
|
1393
|
+
return { stopped: false };
|
|
1394
|
+
}
|
|
1367
1395
|
removeDiscovery(rosterPath);
|
|
1368
1396
|
return { stopped: true };
|
|
1369
1397
|
}
|
|
1370
|
-
if (await
|
|
1398
|
+
if (await waitForCompletion(STOP_GRACE_MS)) {
|
|
1371
1399
|
removeDiscovery(rosterPath);
|
|
1372
1400
|
return { stopped: true };
|
|
1373
1401
|
}
|
|
1374
1402
|
try {
|
|
1375
|
-
|
|
1376
|
-
} catch {
|
|
1403
|
+
groupSignaled = signalGroup(pid, "SIGKILL");
|
|
1404
|
+
} catch (err2) {
|
|
1405
|
+
if (isEpermError(err2)) {
|
|
1406
|
+
return { stopped: false };
|
|
1407
|
+
}
|
|
1377
1408
|
removeDiscovery(rosterPath);
|
|
1378
1409
|
return { stopped: true };
|
|
1379
1410
|
}
|
|
1380
|
-
if (await
|
|
1411
|
+
if (await waitForCompletion(STOP_GRACE_MS)) {
|
|
1381
1412
|
removeDiscovery(rosterPath);
|
|
1382
1413
|
return { stopped: true };
|
|
1383
1414
|
}
|
|
@@ -1392,6 +1423,23 @@ async function waitForDeath(pid, budgetMs) {
|
|
|
1392
1423
|
}
|
|
1393
1424
|
return !isAlive(pid);
|
|
1394
1425
|
}
|
|
1426
|
+
async function waitForGroupDeath(pid, budgetMs) {
|
|
1427
|
+
const deadline = Date.now() + budgetMs;
|
|
1428
|
+
const groupAlive = () => {
|
|
1429
|
+
try {
|
|
1430
|
+
process.kill(-pid, 0);
|
|
1431
|
+
return true;
|
|
1432
|
+
} catch {
|
|
1433
|
+
return false;
|
|
1434
|
+
}
|
|
1435
|
+
};
|
|
1436
|
+
while (Date.now() < deadline) {
|
|
1437
|
+
if (!groupAlive())
|
|
1438
|
+
return true;
|
|
1439
|
+
await sleep(POLL_INTERVAL_MS);
|
|
1440
|
+
}
|
|
1441
|
+
return !groupAlive();
|
|
1442
|
+
}
|
|
1395
1443
|
|
|
1396
1444
|
// src/mcp.ts
|
|
1397
1445
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
@@ -1521,7 +1569,7 @@ async function mcpLoadContext() {
|
|
|
1521
1569
|
}
|
|
1522
1570
|
return loadContext();
|
|
1523
1571
|
}
|
|
1524
|
-
var version = "0.7.
|
|
1572
|
+
var version = "0.7.1";
|
|
1525
1573
|
var server = new McpServer({
|
|
1526
1574
|
name: "space-bus",
|
|
1527
1575
|
version
|
package/dist/server.d.ts
CHANGED
|
@@ -51,15 +51,6 @@ export declare function ensureServer(rosterPath: string, options?: EnsureServerO
|
|
|
51
51
|
* recorded at spawn time (R5b) — surfaced, not auto-corrected.
|
|
52
52
|
*/
|
|
53
53
|
export declare function serverStatus(rosterPath: string): ServerStatus;
|
|
54
|
-
/**
|
|
55
|
-
* Stops a managed server: identity-verified SIGTERM, then polls for actual
|
|
56
|
-
* death (bounded by STOP_GRACE_MS) before escalating to SIGKILL and polling
|
|
57
|
-
* again. The discovery file is removed ONLY once the process is confirmed
|
|
58
|
-
* dead (or was never verified-live/already gone) — a process that ignores
|
|
59
|
-
* both signals is reported as not stopped and the discovery file is left in
|
|
60
|
-
* place, so credentials aren't silently discarded while the server still
|
|
61
|
-
* holds the port. OS-authz only (R7b) — no additional permission model.
|
|
62
|
-
*/
|
|
63
54
|
export declare function stopServer(rosterPath: string): Promise<{
|
|
64
55
|
stopped: boolean;
|
|
65
56
|
}>;
|
package/dist/server.js
CHANGED
|
@@ -103,7 +103,7 @@ var managedSpawnConfigSchema = z.object({
|
|
|
103
103
|
});
|
|
104
104
|
var discoveryFileSchema = z.object({
|
|
105
105
|
port: z.number().int().nonnegative(),
|
|
106
|
-
pid: z.number().int().
|
|
106
|
+
pid: z.number().int().min(2),
|
|
107
107
|
identity: z.string(),
|
|
108
108
|
password: z.string(),
|
|
109
109
|
spawnConfig: managedSpawnConfigSchema,
|
|
@@ -230,7 +230,7 @@ function verifyIdentity(pid, storedIdentity) {
|
|
|
230
230
|
return current !== null && current === storedIdentity;
|
|
231
231
|
}
|
|
232
232
|
var lockFileSchema = z2.object({
|
|
233
|
-
pid: z2.number().int().
|
|
233
|
+
pid: z2.number().int().min(2),
|
|
234
234
|
startTime: z2.string(),
|
|
235
235
|
since: z2.number()
|
|
236
236
|
});
|
|
@@ -326,7 +326,7 @@ function provisionalFilePath(rosterPath) {
|
|
|
326
326
|
return join(stateDirFor(rosterPath), "spawn.provisional.json");
|
|
327
327
|
}
|
|
328
328
|
var provisionalFileSchema = z2.object({
|
|
329
|
-
pid: z2.number().int().
|
|
329
|
+
pid: z2.number().int().min(2),
|
|
330
330
|
identity: z2.string(),
|
|
331
331
|
password: z2.string(),
|
|
332
332
|
since: z2.number()
|
|
@@ -522,11 +522,34 @@ function redactedReadinessError(rosterPath, password, reason) {
|
|
|
522
522
|
return new Error(`space-bus: managed server for roster ${rosterPath} ${reason}. Log tail:
|
|
523
523
|
${tail}`);
|
|
524
524
|
}
|
|
525
|
+
function isEpermError(err) {
|
|
526
|
+
return typeof err === "object" && err !== null && "code" in err && err.code === "EPERM";
|
|
527
|
+
}
|
|
528
|
+
function signalGroup(pid, sig) {
|
|
529
|
+
if (pid <= 1) {
|
|
530
|
+
try {
|
|
531
|
+
process.kill(pid, sig);
|
|
532
|
+
} catch {}
|
|
533
|
+
return false;
|
|
534
|
+
}
|
|
535
|
+
try {
|
|
536
|
+
process.kill(-pid, sig);
|
|
537
|
+
return true;
|
|
538
|
+
} catch (err) {
|
|
539
|
+
if (err.code === "EPERM") {
|
|
540
|
+
throw err;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
try {
|
|
544
|
+
process.kill(pid, sig);
|
|
545
|
+
} catch {}
|
|
546
|
+
return false;
|
|
547
|
+
}
|
|
525
548
|
function killIdentifiedProcess(pid, identity) {
|
|
526
549
|
try {
|
|
527
550
|
if (identity !== null && identity !== undefined && identity !== "") {
|
|
528
551
|
if (verifyIdentity(pid, identity))
|
|
529
|
-
|
|
552
|
+
signalGroup(pid, "SIGTERM");
|
|
530
553
|
return;
|
|
531
554
|
}
|
|
532
555
|
process.kill(pid, "SIGTERM");
|
|
@@ -775,23 +798,31 @@ async function stopServer(rosterPath) {
|
|
|
775
798
|
return { stopped: false };
|
|
776
799
|
}
|
|
777
800
|
const { pid } = discovery;
|
|
801
|
+
let groupSignaled;
|
|
802
|
+
const waitForCompletion = (budgetMs) => groupSignaled ? waitForGroupDeath(pid, budgetMs) : waitForDeath(pid, budgetMs);
|
|
778
803
|
try {
|
|
779
|
-
|
|
780
|
-
} catch {
|
|
804
|
+
groupSignaled = signalGroup(pid, "SIGTERM");
|
|
805
|
+
} catch (err) {
|
|
806
|
+
if (isEpermError(err)) {
|
|
807
|
+
return { stopped: false };
|
|
808
|
+
}
|
|
781
809
|
removeDiscovery(rosterPath);
|
|
782
810
|
return { stopped: true };
|
|
783
811
|
}
|
|
784
|
-
if (await
|
|
812
|
+
if (await waitForCompletion(STOP_GRACE_MS)) {
|
|
785
813
|
removeDiscovery(rosterPath);
|
|
786
814
|
return { stopped: true };
|
|
787
815
|
}
|
|
788
816
|
try {
|
|
789
|
-
|
|
790
|
-
} catch {
|
|
817
|
+
groupSignaled = signalGroup(pid, "SIGKILL");
|
|
818
|
+
} catch (err) {
|
|
819
|
+
if (isEpermError(err)) {
|
|
820
|
+
return { stopped: false };
|
|
821
|
+
}
|
|
791
822
|
removeDiscovery(rosterPath);
|
|
792
823
|
return { stopped: true };
|
|
793
824
|
}
|
|
794
|
-
if (await
|
|
825
|
+
if (await waitForCompletion(STOP_GRACE_MS)) {
|
|
795
826
|
removeDiscovery(rosterPath);
|
|
796
827
|
return { stopped: true };
|
|
797
828
|
}
|
|
@@ -806,6 +837,23 @@ async function waitForDeath(pid, budgetMs) {
|
|
|
806
837
|
}
|
|
807
838
|
return !isAlive(pid);
|
|
808
839
|
}
|
|
840
|
+
async function waitForGroupDeath(pid, budgetMs) {
|
|
841
|
+
const deadline = Date.now() + budgetMs;
|
|
842
|
+
const groupAlive = () => {
|
|
843
|
+
try {
|
|
844
|
+
process.kill(-pid, 0);
|
|
845
|
+
return true;
|
|
846
|
+
} catch {
|
|
847
|
+
return false;
|
|
848
|
+
}
|
|
849
|
+
};
|
|
850
|
+
while (Date.now() < deadline) {
|
|
851
|
+
if (!groupAlive())
|
|
852
|
+
return true;
|
|
853
|
+
await sleep(POLL_INTERVAL_MS);
|
|
854
|
+
}
|
|
855
|
+
return !groupAlive();
|
|
856
|
+
}
|
|
809
857
|
export {
|
|
810
858
|
stopServer,
|
|
811
859
|
serverStatus,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fro.bot/space-bus",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "Space Bus — workspace agent bus for OpenCode. One control agent tasking per-project agents over the OpenCode server API, with an MCP facade for Claude Desktop.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|