everything-dev 0.2.0 → 0.3.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/package.json +80 -79
- package/src/cli.ts +1491 -1198
- package/src/components/monitor-view.tsx +423 -419
- package/src/config.ts +530 -243
- package/src/contract.ts +381 -364
- package/src/lib/env.ts +83 -65
- package/src/lib/nova.ts +207 -195
- package/src/lib/orchestrator.ts +232 -199
- package/src/lib/process-registry.ts +141 -132
- package/src/lib/process.ts +499 -409
- package/src/lib/resource-monitor/diff.ts +27 -9
- package/src/lib/resource-monitor/platform/darwin.ts +31 -18
- package/src/lib/resource-monitor/snapshot.ts +164 -151
- package/src/plugin.ts +2281 -1841
- package/src/types.ts +182 -83
- package/src/ui/head.ts +37 -26
- package/src/utils/banner.ts +7 -9
- package/src/utils/run.ts +27 -16
- package/src/lib/secrets.ts +0 -29
|
@@ -2,156 +2,165 @@ import { existsSync } from "node:fs";
|
|
|
2
2
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
3
3
|
import { dirname, join } from "node:path";
|
|
4
4
|
import { Context, Effect, Layer, Ref } from "every-plugin/effect";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
const getPidFilePath = () =>
|
|
5
|
+
import { getProjectRoot } from "../config";
|
|
6
|
+
|
|
7
|
+
const getPidFilePath = () => {
|
|
8
|
+
try {
|
|
9
|
+
return join(getProjectRoot(), ".bos", "pids.json");
|
|
10
|
+
} catch {
|
|
11
|
+
// Fallback to cwd if config not loaded
|
|
12
|
+
return join(process.cwd(), ".bos", "pids.json");
|
|
13
|
+
}
|
|
14
|
+
};
|
|
8
15
|
|
|
9
16
|
export interface TrackedProcess {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
17
|
+
pid: number;
|
|
18
|
+
name: string;
|
|
19
|
+
port: number;
|
|
20
|
+
startedAt: number;
|
|
21
|
+
command: string;
|
|
15
22
|
}
|
|
16
23
|
|
|
17
24
|
export interface ProcessRegistry {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
readonly tracked: Ref.Ref<Map<number, TrackedProcess>>;
|
|
26
|
+
track: (proc: TrackedProcess) => Effect.Effect<void>;
|
|
27
|
+
untrack: (pid: number) => Effect.Effect<void>;
|
|
28
|
+
getAll: () => Effect.Effect<TrackedProcess[]>;
|
|
29
|
+
killAll: (
|
|
30
|
+
force?: boolean,
|
|
31
|
+
) => Effect.Effect<{ killed: number[]; failed: number[] }>;
|
|
32
|
+
persist: () => Effect.Effect<void>;
|
|
33
|
+
restore: () => Effect.Effect<void>;
|
|
25
34
|
}
|
|
26
35
|
|
|
27
36
|
const isProcessAlive = (pid: number): boolean => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
37
|
+
try {
|
|
38
|
+
process.kill(pid, 0);
|
|
39
|
+
return true;
|
|
40
|
+
} catch {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
34
43
|
};
|
|
35
44
|
|
|
36
45
|
const killProcess = (pid: number, signal: NodeJS.Signals): boolean => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
46
|
+
try {
|
|
47
|
+
process.kill(pid, signal);
|
|
48
|
+
return true;
|
|
49
|
+
} catch {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
43
52
|
};
|
|
44
53
|
|
|
45
54
|
const make = Effect.gen(function* () {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
55
|
+
const tracked = yield* Ref.make(new Map<number, TrackedProcess>());
|
|
56
|
+
const pidFile = getPidFilePath();
|
|
57
|
+
|
|
58
|
+
const track: ProcessRegistry["track"] = (proc) =>
|
|
59
|
+
Effect.gen(function* () {
|
|
60
|
+
yield* Ref.update(tracked, (m) => new Map(m).set(proc.pid, proc));
|
|
61
|
+
yield* persist();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const untrack: ProcessRegistry["untrack"] = (pid) =>
|
|
65
|
+
Effect.gen(function* () {
|
|
66
|
+
yield* Ref.update(tracked, (m) => {
|
|
67
|
+
const copy = new Map(m);
|
|
68
|
+
copy.delete(pid);
|
|
69
|
+
return copy;
|
|
70
|
+
});
|
|
71
|
+
yield* persist();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const getAll: ProcessRegistry["getAll"] = () =>
|
|
75
|
+
Ref.get(tracked).pipe(Effect.map((m) => Array.from(m.values())));
|
|
76
|
+
|
|
77
|
+
const killAll: ProcessRegistry["killAll"] = (force = false) =>
|
|
78
|
+
Effect.gen(function* () {
|
|
79
|
+
const procs = yield* getAll();
|
|
80
|
+
const killed: number[] = [];
|
|
81
|
+
const failed: number[] = [];
|
|
82
|
+
|
|
83
|
+
for (const proc of procs) {
|
|
84
|
+
if (!isProcessAlive(proc.pid)) {
|
|
85
|
+
yield* untrack(proc.pid);
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const signal = force ? "SIGKILL" : "SIGTERM";
|
|
90
|
+
if (killProcess(proc.pid, signal)) {
|
|
91
|
+
killed.push(proc.pid);
|
|
92
|
+
yield* untrack(proc.pid);
|
|
93
|
+
} else {
|
|
94
|
+
failed.push(proc.pid);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (!force && failed.length > 0) {
|
|
99
|
+
yield* Effect.sleep("500 millis");
|
|
100
|
+
for (const pid of [...failed]) {
|
|
101
|
+
if (killProcess(pid, "SIGKILL")) {
|
|
102
|
+
const idx = failed.indexOf(pid);
|
|
103
|
+
if (idx !== -1) {
|
|
104
|
+
failed.splice(idx, 1);
|
|
105
|
+
killed.push(pid);
|
|
106
|
+
}
|
|
107
|
+
yield* untrack(pid);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
yield* persist();
|
|
113
|
+
return { killed, failed };
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
const persist: ProcessRegistry["persist"] = () =>
|
|
117
|
+
Effect.gen(function* () {
|
|
118
|
+
const procs = yield* getAll();
|
|
119
|
+
const dir = dirname(pidFile);
|
|
120
|
+
|
|
121
|
+
yield* Effect.tryPromise({
|
|
122
|
+
try: async () => {
|
|
123
|
+
if (!existsSync(dir)) {
|
|
124
|
+
await mkdir(dir, { recursive: true });
|
|
125
|
+
}
|
|
126
|
+
await writeFile(pidFile, JSON.stringify(procs, null, 2));
|
|
127
|
+
},
|
|
128
|
+
catch: () => new Error("Failed to persist PIDs"),
|
|
129
|
+
}).pipe(Effect.catchAll(() => Effect.void));
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const restore: ProcessRegistry["restore"] = () =>
|
|
133
|
+
Effect.gen(function* () {
|
|
134
|
+
if (!existsSync(pidFile)) return;
|
|
135
|
+
|
|
136
|
+
const content = yield* Effect.tryPromise({
|
|
137
|
+
try: () => readFile(pidFile, "utf8"),
|
|
138
|
+
catch: () => new Error("Failed to read PID file"),
|
|
139
|
+
}).pipe(Effect.catchAll(() => Effect.succeed("")));
|
|
140
|
+
|
|
141
|
+
if (!content) return;
|
|
142
|
+
|
|
143
|
+
let procs: TrackedProcess[];
|
|
144
|
+
try {
|
|
145
|
+
procs = JSON.parse(content) as TrackedProcess[];
|
|
146
|
+
} catch {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const alive = procs.filter((p) => isProcessAlive(p.pid));
|
|
151
|
+
yield* Ref.set(tracked, new Map(alive.map((p) => [p.pid, p])));
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
yield* restore();
|
|
155
|
+
|
|
156
|
+
return { tracked, track, untrack, getAll, killAll, persist, restore };
|
|
148
157
|
});
|
|
149
158
|
|
|
150
159
|
export class ProcessRegistryService extends Context.Tag("bos/ProcessRegistry")<
|
|
151
|
-
|
|
152
|
-
|
|
160
|
+
ProcessRegistryService,
|
|
161
|
+
ProcessRegistry
|
|
153
162
|
>() {
|
|
154
|
-
|
|
163
|
+
static Live = Layer.effect(ProcessRegistryService, make);
|
|
155
164
|
}
|
|
156
165
|
|
|
157
166
|
export const createProcessRegistry = (): Effect.Effect<ProcessRegistry> => make;
|