@jiyr0119/dsh-service-console 0.1.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.
@@ -0,0 +1,33 @@
1
+ import { redact } from "./redaction.js";
2
+ //#region src/host/ledger.ts
3
+ const DEV_COMMAND_RE = /(npm (run|start|dev)|pnpm (run|dev|start)|yarn (dev|start)|next dev|vite|uvicorn|gunicorn|flask run|django runserver|cargo run|node (server|app|index)|python3? -m (http.server|uvicorn)|serve|http-server|nodemon|tsx watch|deno run)/;
4
+ var SessionLedger = class {
5
+ entries = [];
6
+ get list() {
7
+ return this.entries;
8
+ }
9
+ observe(exec) {
10
+ try {
11
+ if (!exec || exec.name !== "bash") return;
12
+ const args = exec.args || {};
13
+ const command = String(args.command || "");
14
+ if (!DEV_COMMAND_RE.test(command)) return;
15
+ let sessionKey = null;
16
+ try {
17
+ sessionKey = exec.agent && (exec.agent.id || exec.agent.sessionId) || null;
18
+ } catch {
19
+ sessionKey = null;
20
+ }
21
+ this.entries.push({
22
+ at: Date.now(),
23
+ command,
24
+ cwd: typeof args.workdir === "string" ? args.workdir : null,
25
+ sessionKey,
26
+ redacted: redact(command) ?? command
27
+ });
28
+ if (this.entries.length > 200) this.entries.shift();
29
+ } catch (err) {}
30
+ }
31
+ };
32
+ //#endregion
33
+ export { DEV_COMMAND_RE, SessionLedger };
@@ -0,0 +1,59 @@
1
+ import { redact } from "./redaction.js";
2
+ import { runCommand, shellQuote } from "./process-inspector.js";
3
+ //#region src/host/lifecycle.ts
4
+ function ok(data) {
5
+ return {
6
+ ok: true,
7
+ data
8
+ };
9
+ }
10
+ function err(code, message) {
11
+ return {
12
+ ok: false,
13
+ error: {
14
+ code,
15
+ message
16
+ }
17
+ };
18
+ }
19
+ async function stopService(deps, serviceId, mode) {
20
+ const svc = (await deps.buildSnapshot()).services.find((x) => x.id === serviceId);
21
+ if (!svc) return err("TARGET_GONE", "该服务已结束,列表已刷新");
22
+ if (svc.protected) return err("PROTECTED_PROCESS", "该进程受保护,不能通过 Service Console 操作");
23
+ if (svc.ownership === "unknown") return err("UNKNOWN_OWNERSHIP", "无法确认服务来源,默认不允许控制");
24
+ const target = svc.processGroupId ? "-" + svc.processGroupId : String(svc.pid);
25
+ await (deps.commandRunner || runCommand)("kill -TERM " + target, 3e3);
26
+ const deadline = Date.now() + (deps.config.gracefulTimeout || 3e3);
27
+ while (Date.now() < deadline) {
28
+ await deps.timer.timeout(400);
29
+ if (!(await deps.buildSnapshot()).services.some((x) => x.id === serviceId)) {
30
+ deps.logAction(serviceId, "stop", "stopped");
31
+ return ok({ result: "stopped" });
32
+ }
33
+ }
34
+ if (deps.config.forceKill) {
35
+ await (deps.commandRunner || runCommand)("kill -KILL " + target, 3e3);
36
+ deps.logAction(serviceId, "stop", "force-killed");
37
+ return ok({ result: "force-killed" });
38
+ }
39
+ deps.logAction(serviceId, "stop", "timeout", "GRACEFUL_TIMEOUT");
40
+ return err("GRACEFUL_TIMEOUT", "服务未在等待时间内退出,可重试或在设置允许时强制终止");
41
+ }
42
+ async function restartService(deps, serviceId) {
43
+ const svc = (await deps.buildSnapshot()).services.find((x) => x.id === serviceId);
44
+ if (!svc) return err("TARGET_GONE", "该服务已结束,列表已刷新");
45
+ if (!svc.restartable) return err("RESTART_UNSAFE", "缺少安全复现启动所需的信息,不能重启");
46
+ const entry = deps.ledgerList().find((l) => svc.cwd && l.cwd && svc.cwd.indexOf(l.cwd) === 0);
47
+ if (!entry) return err("RESTART_UNSAFE", "缺少启动命令记录,不能重启");
48
+ const stopped = await stopService(deps, serviceId, "graceful");
49
+ if (!stopped.ok && stopped.error?.code !== "TARGET_GONE") return stopped;
50
+ const cmd = "cd " + shellQuote(entry.cwd || ".") + " && " + entry.command;
51
+ await (deps.commandRunner || runCommand)(cmd + " >/dev/null 2>&1 &", 3e3);
52
+ deps.logAction(serviceId, "restart", "started");
53
+ return ok({
54
+ result: "started",
55
+ command: redact(entry.command) ?? entry.command
56
+ });
57
+ }
58
+ //#endregion
59
+ export { restartService, stopService };
@@ -0,0 +1,36 @@
1
+ //#region src/host/ownership.ts
2
+ const SYSTEM_CWD_RE = /^(\/usr\/|\/System\/|\/Library\/|\/bin\/|\/sbin\/|\/private\/)/;
3
+ const LEDGER_WINDOW_MS = 6e5;
4
+ function classifyOwnership(proc, ledgers, workspaces) {
5
+ const cwd = proc.cwd;
6
+ proc.command;
7
+ const evidence = [];
8
+ let ownership = "unknown";
9
+ let confidence = "unknown";
10
+ let ledgerEntry = null;
11
+ if (cwd && ledgers.length > 0) ledgerEntry = ledgers.find((l) => l.cwd && cwd.indexOf(l.cwd) === 0 && proc.startedAt !== null && Math.abs(proc.startedAt - l.at) < LEDGER_WINDOW_MS) ?? null;
12
+ if (ledgerEntry) {
13
+ ownership = "conversation-confirmed";
14
+ confidence = "confirmed";
15
+ evidence.push("matched session launch ledger: " + (ledgerEntry.redacted || ledgerEntry.command).slice(0, 60));
16
+ } else if (cwd && workspaces.length > 0) {
17
+ const ws = workspaces.find((w) => w && w.path && cwd.indexOf(w.path) === 0);
18
+ if (ws) {
19
+ ownership = "workspace-inferred";
20
+ confidence = "inferred";
21
+ evidence.push("cwd under workspace: " + ws.path);
22
+ }
23
+ } else if (cwd && !SYSTEM_CWD_RE.test(cwd)) {
24
+ ownership = "other-local";
25
+ confidence = "inferred";
26
+ evidence.push("local cwd not in workspace: " + cwd);
27
+ } else evidence.push("cannot confirm origin (cwd or command unavailable)");
28
+ return {
29
+ ownership,
30
+ confidence,
31
+ evidence,
32
+ ledgerEntry
33
+ };
34
+ }
35
+ //#endregion
36
+ export { classifyOwnership };
@@ -0,0 +1,177 @@
1
+ import { execFileSync } from "node:child_process";
2
+ //#region src/host/process-inspector.ts
3
+ const MONTHS = {
4
+ Jan: 1,
5
+ Feb: 2,
6
+ Mar: 3,
7
+ Apr: 4,
8
+ May: 5,
9
+ Jun: 6,
10
+ Jul: 7,
11
+ Aug: 8,
12
+ Sep: 9,
13
+ Oct: 10,
14
+ Nov: 11,
15
+ Dec: 12
16
+ };
17
+ function runCommand(command, timeoutMs) {
18
+ try {
19
+ return {
20
+ stdout: execFileSync("/bin/sh", ["-c", command], {
21
+ encoding: "utf8",
22
+ timeout: timeoutMs || 5e3,
23
+ stdio: [
24
+ "ignore",
25
+ "pipe",
26
+ "pipe"
27
+ ],
28
+ maxBuffer: 16777216
29
+ }),
30
+ stderr: "",
31
+ code: 0
32
+ };
33
+ } catch (e) {
34
+ const err = e;
35
+ return {
36
+ stdout: typeof err.stdout === "string" ? err.stdout : err.stdout ? String(err.stdout) : "",
37
+ stderr: typeof err.stderr === "string" ? err.stderr : err.stderr ? String(err.stderr) : "",
38
+ code: err.status ?? 1
39
+ };
40
+ }
41
+ }
42
+ function parseLstart(str) {
43
+ const parts = String(str).trim().split(/\s+/);
44
+ if (parts.length < 5) return null;
45
+ const mon = MONTHS[parts[1]];
46
+ const day = parseInt(parts[2], 10);
47
+ const year = parseInt(parts[4], 10);
48
+ if (!mon || !day || !year || !parts[3]) return null;
49
+ const iso = year + "-" + String(mon).padStart(2, "0") + "-" + String(day).padStart(2, "0") + "T" + parts[3];
50
+ const t = Date.parse(iso);
51
+ return Number.isFinite(t) ? t : null;
52
+ }
53
+ function parseListenRows(stdout) {
54
+ const rows = [];
55
+ for (const line of String(stdout).split("\n")) {
56
+ const t = line.trim();
57
+ if (!t || t.startsWith("COMMAND")) continue;
58
+ const m = t.match(/^(\S+)\s+(\d+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(.+)$/);
59
+ if (!m) continue;
60
+ const name = m[9].trim();
61
+ if (!/\(LISTEN\)$/.test(name)) continue;
62
+ rows.push({
63
+ command: m[1],
64
+ pid: parseInt(m[2], 10),
65
+ user: m[3],
66
+ fd: m[4],
67
+ type: m[5],
68
+ address: name.replace(/\s*\(LISTEN\)$/, "")
69
+ });
70
+ }
71
+ return rows;
72
+ }
73
+ function parsePsRows(stdout) {
74
+ const rows = [];
75
+ for (const line of String(stdout).split("\n")) {
76
+ const t = line.trim();
77
+ if (!t) continue;
78
+ const parts = t.split(/\s+/);
79
+ const pid = parseInt(parts[0], 10);
80
+ const ppid = parseInt(parts[1], 10);
81
+ if (!Number.isFinite(pid) || !Number.isFinite(ppid)) continue;
82
+ const lstart = parts.slice(2, 7).join(" ");
83
+ rows.push({
84
+ pid,
85
+ ppid,
86
+ lstart,
87
+ startedAt: parseLstart(lstart),
88
+ command: parts.slice(7).join(" ")
89
+ });
90
+ }
91
+ return rows;
92
+ }
93
+ function parseAddress(addr) {
94
+ let host = null;
95
+ let port = null;
96
+ let m = String(addr).match(/^\[([^\]]+)\]:(.+)$/);
97
+ if (m) {
98
+ host = m[1];
99
+ port = parseInt(m[2], 10);
100
+ } else {
101
+ m = String(addr).match(/^(.+):(\d+)$/);
102
+ if (m) {
103
+ host = m[1];
104
+ port = parseInt(m[2], 10);
105
+ }
106
+ }
107
+ return {
108
+ host,
109
+ port
110
+ };
111
+ }
112
+ function shellQuote(s) {
113
+ return "'" + String(s).replace(/'/g, "'\\''") + "'";
114
+ }
115
+ async function scanRaw(commandRunner = runCommand) {
116
+ const partialWarnings = [];
117
+ const tcp = await commandRunner("lsof -nP -iTCP -sTCP:LISTEN", 5e3);
118
+ if (tcp.code !== 0 && tcp.code !== null && tcp.code !== 1) partialWarnings.push("TCP listener scan exit=" + String(tcp.code));
119
+ const rows = parseListenRows(tcp.stdout);
120
+ const pids = [...new Set(rows.map((r) => r.pid))];
121
+ const pidList = pids.join(",");
122
+ const procs = /* @__PURE__ */ new Map();
123
+ if (pids.length > 0) {
124
+ const psRes = await commandRunner("ps -o pid=,ppid=,lstart=,command= -p " + pidList, 5e3);
125
+ const psRows = parsePsRows(psRes.stdout);
126
+ if (psRes.code !== 0 && psRes.code !== null) partialWarnings.push("ps detail partial");
127
+ const pgidRes = await commandRunner("ps -o pid=,pgid= -p " + pidList, 5e3);
128
+ const pgidMap = /* @__PURE__ */ new Map();
129
+ for (const line of String(pgidRes.stdout).split("\n")) {
130
+ const parts = line.trim().split(/\s+/);
131
+ if (parts.length >= 2) {
132
+ const p = parseInt(parts[0], 10);
133
+ const g = parseInt(parts[1], 10);
134
+ if (Number.isFinite(p) && Number.isFinite(g)) pgidMap.set(p, g);
135
+ }
136
+ }
137
+ let cwdByPid = /* @__PURE__ */ new Map();
138
+ const cwdRes = await commandRunner("lsof -a -p " + pidList + " -d cwd", 5e3);
139
+ for (const line of String(cwdRes.stdout).split("\n")) {
140
+ const t = line.trim();
141
+ if (!t || t.startsWith("COMMAND")) continue;
142
+ const m = t.match(/^(\S+)\s+(\d+)\s+(\S+)\s+cwd\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(.+)$/);
143
+ if (m) cwdByPid.set(parseInt(m[2], 10), m[8].trim());
144
+ }
145
+ if (cwdRes.code !== 0 && cwdRes.code !== null) partialWarnings.push("cwd scan partial");
146
+ const nameOf = (r) => {
147
+ return String(r.command).split(/\s+/)[0] || null;
148
+ };
149
+ for (const r of psRows) procs.set(r.pid, {
150
+ pid: r.pid,
151
+ ppid: r.ppid,
152
+ startedAt: r.startedAt,
153
+ command: r.command || null,
154
+ name: nameOf(r),
155
+ pgid: pgidMap.get(r.pid) ?? null,
156
+ cwd: cwdByPid.get(r.pid) ?? null
157
+ });
158
+ }
159
+ const listeners = [];
160
+ for (const r of rows) {
161
+ const { host, port } = parseAddress(r.address);
162
+ if (host === null || port === null) continue;
163
+ listeners.push({
164
+ pid: r.pid,
165
+ host,
166
+ port,
167
+ protocol: r.type === "IPv6" ? "tcp6" : "tcp"
168
+ });
169
+ }
170
+ return {
171
+ listeners,
172
+ procs,
173
+ partialWarnings
174
+ };
175
+ }
176
+ //#endregion
177
+ export { parseAddress, parseListenRows, parseLstart, parsePsRows, runCommand, scanRaw, shellQuote };
@@ -0,0 +1,27 @@
1
+ //#region src/host/redaction.ts
2
+ const REDACT_RULES = [
3
+ {
4
+ re: /(--(?:token|password|passwd|secret|key|api[-_]?key|client[-_]?secret|cookie|session))\s*[=:]\s*(\S+)/gi,
5
+ replace: (m) => m.replace(/(?:[=:]\s*|\s+)\S+$/, "=***")
6
+ },
7
+ {
8
+ re: /((?:token|password|passwd|secret|api[-_]?key|client[-_]?secret|authorization|set-cookie|connection[-_]?string))\s*=\s*(['"]?)([^\s&'"]+)\2/gi,
9
+ replace: (_m, p1, p2) => (p1 || "") + "=" + (p2 || "") + "***"
10
+ },
11
+ {
12
+ re: /(postgres(?:ql)?|mysql|redis|mongodb)(\+s?)?:\/\/[^\s@]+@/gi,
13
+ replace: (_m, p1) => (p1 || "") + "://***@"
14
+ },
15
+ {
16
+ re: /\b(eyJ[a-zA-Z0-9_-]{10,}\.[a-zA-Z0-9_-]{10,}\.[a-zA-Z0-9_-]{10,})\b/g,
17
+ replace: () => "***"
18
+ }
19
+ ];
20
+ function redact(command) {
21
+ if (typeof command !== "string" || !command) return typeof command === "string" ? command : null;
22
+ let out = command;
23
+ for (const rule of REDACT_RULES) out = out.replace(rule.re, (match, p1, p2, p3) => rule.replace(match, p1, p2, p3));
24
+ return out;
25
+ }
26
+ //#endregion
27
+ export { redact };
@@ -0,0 +1,75 @@
1
+ import { redact } from "./redaction.js";
2
+ import { runCommand, scanRaw } from "./process-inspector.js";
3
+ import { classifyOwnership } from "./ownership.js";
4
+ import { createHash } from "node:crypto";
5
+ //#region src/host/service-registry.ts
6
+ function sha256Hex(input) {
7
+ return createHash("sha256").update(input).digest("hex");
8
+ }
9
+ function isLocalhost(host) {
10
+ return host === "127.0.0.1" || host === "::1" || host === "localhost";
11
+ }
12
+ async function buildSnapshot(ledgers, workspaces, commandRunner = runCommand) {
13
+ const raw = await scanRaw(commandRunner);
14
+ const byPid = /* @__PURE__ */ new Map();
15
+ for (const l of raw.listeners) {
16
+ if (!byPid.has(l.pid)) byPid.set(l.pid, []);
17
+ byPid.get(l.pid).push({
18
+ host: l.host,
19
+ port: l.port,
20
+ protocol: l.protocol
21
+ });
22
+ }
23
+ const services = [];
24
+ for (const [pid, listeners] of byPid) {
25
+ const proc = raw.procs.get(pid);
26
+ const command = proc ? proc.command : null;
27
+ const cwd = proc ? proc.cwd : null;
28
+ const startedAt = proc ? proc.startedAt : null;
29
+ const fpSource = [
30
+ pid,
31
+ startedAt,
32
+ command || "",
33
+ cwd || "",
34
+ listeners.map((l) => l.host + ":" + l.port).sort().join(",")
35
+ ].join("|");
36
+ const serviceId = "svc_" + sha256Hex(fpSource).slice(0, 12);
37
+ const cls = classifyOwnership({
38
+ cwd,
39
+ command,
40
+ startedAt
41
+ }, ledgers, workspaces);
42
+ const listenersFinal = listeners.map((l) => ({
43
+ ...l,
44
+ url: isLocalhost(l.host) ? "http://localhost:" + l.port : null
45
+ }));
46
+ services.push({
47
+ id: serviceId,
48
+ status: "running",
49
+ ownership: cls.ownership,
50
+ confidence: cls.confidence,
51
+ name: proc?.name || "unknown",
52
+ pid,
53
+ processGroupId: proc?.pgid ?? null,
54
+ parentPid: proc?.ppid ?? null,
55
+ commandSummary: command ? redact(command).slice(0, 200) : null,
56
+ cwd,
57
+ startedAt,
58
+ listeners: listenersFinal,
59
+ restartable: !!cls.ledgerEntry,
60
+ protected: false,
61
+ ownershipEvidence: cls.evidence,
62
+ fingerprint: "sha256:" + sha256Hex(fpSource)
63
+ });
64
+ }
65
+ services.sort((a, b) => (a.ownership === "conversation-confirmed" ? -1 : 1) - (b.ownership === "conversation-confirmed" ? -1 : 1));
66
+ return {
67
+ scannedAt: Date.now(),
68
+ count: services.length,
69
+ services,
70
+ partialWarnings: raw.partialWarnings,
71
+ ledgerCount: ledgers.length
72
+ };
73
+ }
74
+ //#endregion
75
+ export { buildSnapshot };
package/lib/index.js ADDED
@@ -0,0 +1,168 @@
1
+ import { SessionLedger } from "./host/ledger.js";
2
+ import { buildSnapshot } from "./host/service-registry.js";
3
+ import { restartService, stopService } from "./host/lifecycle.js";
4
+ import { loadConfigFromFile, saveConfigToFile, validateConfigPatch } from "./host/config.js";
5
+ //#region src/index.ts
6
+ async function readJsonBody(req) {
7
+ try {
8
+ let body = "";
9
+ const iterable = req;
10
+ if (typeof iterable[Symbol.asyncIterator] !== "function") return {};
11
+ for await (const chunk of iterable) body += String(chunk);
12
+ return body ? JSON.parse(body) : {};
13
+ } catch {
14
+ return null;
15
+ }
16
+ }
17
+ function sendJson(res, status, payload) {
18
+ const r = res;
19
+ r.statusCode = status;
20
+ r.writeHead(status, { "content-type": "application/json; charset=utf-8" });
21
+ r.end(JSON.stringify(payload));
22
+ }
23
+ var src_default = {
24
+ inject: ["timer", "webServer"],
25
+ apply(ctx) {
26
+ const workspaceRegistry = ctx.get("workspaceRegistry");
27
+ const timer = ctx.timer;
28
+ const ledger = new SessionLedger();
29
+ const on = ctx.on;
30
+ on("tools/result", (exec) => ledger.observe(exec));
31
+ let config = loadConfigFromFile();
32
+ const actionLog = [];
33
+ const logAction = (serviceId, action, result, code = null) => {
34
+ actionLog.push({
35
+ at: Date.now(),
36
+ serviceId,
37
+ action,
38
+ result,
39
+ code
40
+ });
41
+ if (actionLog.length > 200) actionLog.shift();
42
+ };
43
+ const deps = {
44
+ timer,
45
+ config,
46
+ buildSnapshot: () => buildSnapshot(ledger.list, workspaces()),
47
+ ledgerList: () => ledger.list,
48
+ logAction
49
+ };
50
+ let workspacesCache = [];
51
+ function loadWorkspaces() {
52
+ try {
53
+ if (workspaceRegistry && typeof workspaceRegistry.list === "function") return workspaceRegistry.list();
54
+ } catch {}
55
+ return [];
56
+ }
57
+ function workspaces() {
58
+ try {
59
+ workspacesCache = loadWorkspaces();
60
+ } catch {}
61
+ return workspacesCache;
62
+ }
63
+ const routes = [
64
+ {
65
+ path: "/dsh-sc/api/services/scan",
66
+ handler: async () => ({
67
+ ok: true,
68
+ data: await buildSnapshot(ledger.list, workspaces())
69
+ })
70
+ },
71
+ {
72
+ path: "/dsh-sc/api/services/detail",
73
+ handler: async (args) => {
74
+ const svc = (await buildSnapshot(ledger.list, workspaces())).services.find((x) => x.id === String(args.serviceId ?? ""));
75
+ if (!svc) return {
76
+ ok: false,
77
+ error: {
78
+ code: "TARGET_GONE",
79
+ message: "服务不存在"
80
+ }
81
+ };
82
+ return {
83
+ ok: true,
84
+ data: {
85
+ ...svc,
86
+ recentActions: actionLog.filter((a) => a.serviceId === svc.id).slice(-10)
87
+ }
88
+ };
89
+ }
90
+ },
91
+ {
92
+ path: "/dsh-sc/api/services/stop",
93
+ handler: async (args) => stopService(deps, String(args.serviceId ?? ""), String(args.mode ?? "graceful"))
94
+ },
95
+ {
96
+ path: "/dsh-sc/api/services/restart",
97
+ handler: async (args) => restartService(deps, String(args.serviceId ?? ""))
98
+ },
99
+ {
100
+ path: "/dsh-sc/api/config",
101
+ handler: async (args) => {
102
+ const a = args || {};
103
+ if (a.action === "update" && a.patch && typeof a.patch === "object") {
104
+ const v = validateConfigPatch(a.patch);
105
+ if (!v.ok) return {
106
+ ok: false,
107
+ error: {
108
+ code: "BAD_REQUEST",
109
+ message: v.message
110
+ }
111
+ };
112
+ config = {
113
+ ...config,
114
+ ...v.next
115
+ };
116
+ saveConfigToFile(config);
117
+ return {
118
+ ok: true,
119
+ data: { config }
120
+ };
121
+ }
122
+ return {
123
+ ok: true,
124
+ data: { config }
125
+ };
126
+ }
127
+ },
128
+ {
129
+ path: "/dsh-sc/api/actions",
130
+ handler: async () => ({
131
+ ok: true,
132
+ data: { actions: actionLog.slice(-50) }
133
+ })
134
+ }
135
+ ];
136
+ for (const route of routes) ctx.webServer.register({
137
+ kind: "exact",
138
+ path: route.path,
139
+ handler: async (req, res) => {
140
+ const body = await readJsonBody(req);
141
+ if (body === null) {
142
+ sendJson(res, 400, {
143
+ ok: false,
144
+ error: {
145
+ code: "BAD_REQUEST",
146
+ message: "invalid JSON body"
147
+ }
148
+ });
149
+ return;
150
+ }
151
+ try {
152
+ const result = await route.handler(body);
153
+ sendJson(res, result.ok ? 200 : 400, result);
154
+ } catch (e) {
155
+ sendJson(res, 500, {
156
+ ok: false,
157
+ error: {
158
+ code: "INTERNAL",
159
+ message: String(e?.message || e)
160
+ }
161
+ });
162
+ }
163
+ }
164
+ });
165
+ }
166
+ };
167
+ //#endregion
168
+ export { src_default as default };
@@ -0,0 +1,9 @@
1
+ import * as React from 'react';
2
+ interface TimerLike {
3
+ timeout(callback: () => void, delay: number): () => void;
4
+ interval(callback: () => void, delay: number): () => void;
5
+ }
6
+ export declare function bindTimer(t: TimerLike): void;
7
+ export declare function ServiceConsoleEntry(): React.ReactElement;
8
+ export declare function ServiceConsolePanel(): React.ReactElement | null;
9
+ export {};
@@ -0,0 +1,11 @@
1
+ declare const _default: {
2
+ inject: string[];
3
+ apply(ctx: {
4
+ get(name: string): unknown;
5
+ timer: {
6
+ timeout(cb: () => void, ms: number): () => void;
7
+ interval(cb: () => void, ms: number): () => void;
8
+ };
9
+ }): void;
10
+ };
11
+ export default _default;
@@ -0,0 +1,12 @@
1
+ import type { Config } from './types';
2
+ export declare const DEFAULT_CONFIG: Config;
3
+ export declare const CONFIG_LIMITS: Record<string, [number, number]>;
4
+ export declare function loadConfigFromFile(): Config;
5
+ export declare function saveConfigToFile(config: Config): void;
6
+ export declare function validateConfigPatch(patch: Record<string, unknown>): {
7
+ ok: true;
8
+ next: Partial<Config>;
9
+ } | {
10
+ ok: false;
11
+ message: string;
12
+ };
@@ -0,0 +1,15 @@
1
+ import type { LedgerEntry } from './types';
2
+ export declare const DEV_COMMAND_RE: RegExp;
3
+ export interface ToolExecLike {
4
+ name?: string;
5
+ args?: Record<string, unknown>;
6
+ agent?: {
7
+ id?: string;
8
+ sessionId?: string;
9
+ } | null;
10
+ }
11
+ export declare class SessionLedger {
12
+ private entries;
13
+ get list(): LedgerEntry[];
14
+ observe(exec: ToolExecLike | null): void;
15
+ }
@@ -0,0 +1,17 @@
1
+ import type { ApiResult, Config, LedgerEntry, Snapshot, TimerLike } from './types';
2
+ import { type CommandRunner } from './process-inspector';
3
+ export interface LifecycleDeps {
4
+ timer: TimerLike;
5
+ config: Config;
6
+ buildSnapshot: () => Promise<Snapshot>;
7
+ ledgerList: () => LedgerEntry[];
8
+ logAction: (serviceId: string | null, action: string, result: string, code?: string | null) => void;
9
+ commandRunner?: CommandRunner;
10
+ }
11
+ export declare function stopService(deps: LifecycleDeps, serviceId: string, mode?: string): Promise<ApiResult<{
12
+ result: string;
13
+ }>>;
14
+ export declare function restartService(deps: LifecycleDeps, serviceId: string): Promise<ApiResult<{
15
+ result: string;
16
+ command?: string;
17
+ }>>;
@@ -0,0 +1,12 @@
1
+ import type { LedgerEntry, Ownership, WorkspaceLike } from './types';
2
+ export interface OwnershipResult {
3
+ ownership: Ownership;
4
+ confidence: 'confirmed' | 'inferred' | 'unknown';
5
+ evidence: string[];
6
+ ledgerEntry: LedgerEntry | null;
7
+ }
8
+ export declare function classifyOwnership(proc: {
9
+ cwd: string | null;
10
+ command: string | null;
11
+ startedAt: number | null;
12
+ }, ledgers: LedgerEntry[], workspaces: WorkspaceLike[]): OwnershipResult;