@scp-dev/cli 0.2.0 → 0.2.2

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.
Files changed (31) hide show
  1. package/README.md +1 -0
  2. package/dist/chunk-E7JG5PJB.js +806 -0
  3. package/dist/{chunk-5DYFYLAQ.js → chunk-F5QVHJIT.js} +3 -5
  4. package/dist/{chunk-GH7AXFUL.js → chunk-G2SQPY6E.js} +8 -10
  5. package/dist/{chunk-M2DCR2J4.js → chunk-MNTIEWKF.js} +13 -3
  6. package/dist/{chunk-WV5FINTW.js → chunk-NOYMSD4F.js} +20 -10
  7. package/dist/{chunk-RXKBND3T.js → chunk-OTO6DBU6.js} +229 -13
  8. package/dist/{chunk-U2RSSTNW.js → chunk-ZDU53ZRF.js} +3 -5
  9. package/dist/{claude-YJLGFQ2P.js → claude-CVWECMRQ.js} +21 -11
  10. package/dist/cli.js +1 -1
  11. package/dist/codex-Y7SGLZ64.js +565 -0
  12. package/dist/{daemon-SUTLTY5U.js → daemon-OMJY7T2F.js} +1 -1
  13. package/dist/{hooks-EI7M3YKY.js → hooks-EKGY5O5N.js} +19 -3
  14. package/dist/install-4VBSX6RI.js +14 -0
  15. package/dist/join-RGFHOSLE.js +48 -0
  16. package/dist/{login-V2WT7QX5.js → login-IPS75GLQ.js} +4 -7
  17. package/dist/{main-HPBTO3JK.js → main-YN3J6MGW.js} +116 -32
  18. package/dist/{mcp-DGAQNFKO.js → mcp-BVC4PLZ7.js} +11 -11
  19. package/dist/mesh-VNZV3POO.js +28 -0
  20. package/dist/{peek-WLG3ZROU.js → peek-4D4VGKOW.js} +2 -3
  21. package/dist/{pi-HMESQA64.js → pi-R23XR4AC.js} +2 -3
  22. package/dist/{relay-5Z7IEXKD.js → relay-U634RHIJ.js} +6 -4
  23. package/dist/{remote-FYN5ZXE4.js → remote-NTHRHVEP.js} +3 -5
  24. package/dist/{setup-LXG346FJ.js → setup-H7GGUID2.js} +5 -6
  25. package/dist/{spawn-DLPMAS5M.js → spawn-AJAYD6CW.js} +6 -7
  26. package/dist/{up-GPM4LWY3.js → up-HZKGURPI.js} +6 -9
  27. package/package.json +8 -5
  28. package/dist/chunk-3RRPUYTE.js +0 -147
  29. package/dist/chunk-3V3DRXB2.js +0 -340
  30. package/dist/chunk-E53YHYEP.js +0 -305
  31. package/dist/install-MYHVFKT4.js +0 -15
@@ -1,305 +0,0 @@
1
- import {
2
- capture
3
- } from "./chunk-M2DCR2J4.js";
4
-
5
- // src/identity.ts
6
- import { existsSync, realpathSync } from "fs";
7
- import { tmpdir } from "os";
8
- import { basename, dirname, isAbsolute, join, resolve } from "path";
9
- import { shortHostname } from "@scp-dev/broker";
10
- import { LIMITS, validHandle, validHarness } from "@scp-dev/core";
11
- var SHORT = { "claude-code": "claude" };
12
- var SHELLS = /* @__PURE__ */ new Set(["sh", "bash", "zsh", "dash", "fish"]);
13
- var LABEL_KEY = /^[a-z0-9][a-z0-9._-]{0,31}$/;
14
- function detectHarness(env) {
15
- if (env.GROK_SESSION_ID || env.GROK_HOOK_EVENT) return "grok";
16
- if (env.MUSE_SESSION_ID) return "muse";
17
- if (env.OPENCODE === "1") return "opencode";
18
- if (env.ANTIGRAVITY_AGENT === "1" || env.ANTIGRAVITY_CONVERSATION_ID) return "agy";
19
- if (env.CLAUDECODE === "1") return "claude-code";
20
- if (env.CODEX_THREAD_ID) return "codex";
21
- return void 0;
22
- }
23
- function normalizeHarness(raw, fallback) {
24
- const name = (raw ?? "").toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/^-+/, "").slice(0, 32).replace(/-+$/, "");
25
- if (name === "claude") return "claude-code";
26
- return validHarness(name) ? name : fallback;
27
- }
28
- function hookHarness(argument, env) {
29
- if (!argument) return detectHarness(env) ?? "hook";
30
- const named = normalizeHarness(argument, "hook");
31
- return named === "claude-code" && (env.GROK_SESSION_ID || env.GROK_HOOK_EVENT) ? "grok" : named;
32
- }
33
- function resolveHarness(explicit, env, fallback) {
34
- const named = explicit ?? env.SCP_HARNESS;
35
- return named ? normalizeHarness(named, fallback) : detectHarness(env) ?? normalizeHarness(fallback, "mcp");
36
- }
37
- function gitToplevel(cwd) {
38
- for (let dir = resolve(cwd); ; dir = dirname(dir)) {
39
- if (existsSync(join(dir, ".git"))) return dir;
40
- if (dirname(dir) === dir) return void 0;
41
- }
42
- }
43
- function toHandle(raw) {
44
- let handle = raw.toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^[^a-z0-9]+/, "").slice(0, 63).replace(/[-.]+$/, "");
45
- if (!handle) handle = "agent";
46
- if (!validHandle(handle)) handle = `${handle.slice(0, 56)}-agent`;
47
- return handle;
48
- }
49
- function deriveHandle(harness, cwd) {
50
- const top = gitToplevel(cwd) ?? resolve(cwd);
51
- return toHandle(`${SHORT[harness] ?? harness}-${basename(top) || "root"}`);
52
- }
53
- function parseLabels(value) {
54
- const labels = {};
55
- for (const pair of (value ?? "").split(",")) {
56
- const eq = pair.indexOf("=");
57
- const key = pair.slice(0, eq).trim();
58
- if (eq > 0 && LABEL_KEY.test(key)) labels[key] = pair.slice(eq + 1).trim();
59
- }
60
- return labels;
61
- }
62
- function labelsFor(env, host = shortHostname()) {
63
- const labels = parseLabels(env.SCP_LABELS);
64
- labels.machine ??= host;
65
- return labels;
66
- }
67
- function processKey(harnessPid2, startOf = psStart) {
68
- const started = startOf(harnessPid2);
69
- return started ? `pid:${harnessPid2}:${started}` : `pid:${harnessPid2}`;
70
- }
71
- function sessionKey(env, harnessProcess) {
72
- return env.SCP_SESSION ? `env:${env.SCP_SESSION}` : harnessProcess;
73
- }
74
- function psStart(pid) {
75
- try {
76
- const started = (capture(["ps", "-o", "lstart=", "-p", String(pid)], { PATH: process.env.PATH ?? "/usr/bin:/bin", LC_ALL: "C" }) ?? "").trim().replace(/\s+/g, "-");
77
- return /^[A-Za-z0-9:-]{1,64}$/.test(started) ? started : void 0;
78
- } catch {
79
- return void 0;
80
- }
81
- }
82
- function parsePsCommTable(text) {
83
- const table = /* @__PURE__ */ new Map();
84
- for (const line of text.split("\n")) {
85
- const match = /^\s*(\d+)\s+(\d+)\s+(\S+\s+\S+\s+\S+\s+\S+\s+\S+)\s+(\S.*?)\s*$/.exec(line);
86
- if (match) table.set(Number(match[1]), { ppid: Number(match[2]), start: match[3].replace(/\s+/g, "-"), args: match[4] });
87
- }
88
- return table;
89
- }
90
- function readPsTable() {
91
- try {
92
- const table = capture(["ps", "-ww", "-axo", "pid=,ppid=,lstart=,args="], { PATH: process.env.PATH ?? "/usr/bin:/bin", LC_ALL: "C" });
93
- return table === void 0 ? void 0 : parsePsCommTable(table);
94
- } catch {
95
- return void 0;
96
- }
97
- }
98
- var PASS_THROUGH = /* @__PURE__ */ new Set([
99
- ...SHELLS,
100
- "ash",
101
- "ksh",
102
- "env",
103
- "timeout",
104
- "nohup",
105
- "nice",
106
- "time",
107
- "stdbuf",
108
- "xargs",
109
- "script",
110
- "caffeinate",
111
- "flock",
112
- "sandbox-exec",
113
- "bwrap",
114
- "codex-linux-sandbox",
115
- "codex-linux-san"
116
- ]);
117
- var INTERPRETERS = /* @__PURE__ */ new Set(["node", "nodejs", "bun", "deno", "ruby", "perl"]);
118
- var RUNNERS = /* @__PURE__ */ new Set(["npm", "pnpm", "yarn"]);
119
- var FETCHERS = /* @__PURE__ */ new Set(["npx", "bunx", "pnpx", "uvx"]);
120
- var SCRIPT_RUNNERS = /* @__PURE__ */ new Set(["tsx", "ts-node", "vite-node", "esno"]);
121
- var INLINE = /* @__PURE__ */ new Set(["-c", "-e", "--eval", "-p", "--print", "-"]);
122
- var VALUED = /* @__PURE__ */ new Set(["-r", "--require", "--import", "--loader", "--experimental-loader", "-I", "-M", "-W", "-X", "-C", "--conditions", "--preload"]);
123
- var HARNESSES = /* @__PURE__ */ new Set([
124
- "claude",
125
- "claude-code",
126
- "codex",
127
- "opencode",
128
- "opencode-ai",
129
- "grok",
130
- "grok-cli",
131
- "muse",
132
- "agy",
133
- "antigravity",
134
- "gemini",
135
- "gemini-cli",
136
- "pi-coding-agent"
137
- ]);
138
- var INSTALLED = /(^|\/)(node_modules|site-packages|dist-packages|\.npm|\.bun|\.cache|\.local|\.cargo|\.volta|\.nvm|\.pyenv|\.rbenv|Cellar|Applications)(\/|$)|^\/(opt|usr|Library|nix)\//;
139
- function command(args) {
140
- return basename(args.split(/\s+/)[0].replace(/^-/, "")).toLowerCase();
141
- }
142
- var namesHarness = (words) => words.some((word) => !word.startsWith("-") && word.split("/").some((part) => HARNESSES.has(part.toLowerCase().replace(/\..*$/, ""))));
143
- var roots;
144
- function workspaceRoots() {
145
- if (roots) return roots;
146
- const real = (path) => {
147
- try {
148
- return realpathSync(path);
149
- } catch {
150
- return path;
151
- }
152
- };
153
- const found = [process.cwd(), tmpdir(), "/tmp", "/private/tmp", "/var/folders", "/private/var/folders"];
154
- try {
155
- const top = capture(["git", "rev-parse", "--show-toplevel"]);
156
- if (top !== void 0) found.push(top.trim());
157
- } catch {
158
- }
159
- roots = [...new Set(found.filter(Boolean).map(real))];
160
- return roots;
161
- }
162
- function ownScript(operand) {
163
- if (operand === void 0 || operand === "-") return true;
164
- if (/^[a-z][a-z0-9+.-]*:/i.test(operand) || operand.startsWith("~") || INSTALLED.test(operand)) return false;
165
- if (!isAbsolute(operand)) return !operand.split("/").includes("..");
166
- let path = operand;
167
- try {
168
- path = realpathSync(operand);
169
- } catch {
170
- }
171
- if (INSTALLED.test(path)) return false;
172
- return workspaceRoots().some((root) => path === root || path.startsWith(`${root}/`));
173
- }
174
- function helper(args) {
175
- const words = args.split(/\s+/);
176
- if (namesHarness(words.slice(1))) return false;
177
- const name = command(args);
178
- let rest = words.slice(1);
179
- if (FETCHERS.has(name)) {
180
- while (rest[0]?.startsWith("-")) rest = rest.slice(1);
181
- return SCRIPT_RUNNERS.has(rest[0] ?? "") && rest.slice(1).every((word) => word.startsWith("-") || ownScript(word));
182
- }
183
- if (name === "uv" || RUNNERS.has(name)) {
184
- if (rest[0] !== "run") return false;
185
- if (name === "uv") {
186
- rest = rest.slice(1);
187
- while (rest[0]?.startsWith("-")) rest = rest.slice(1);
188
- if (rest[0] === void 0) return true;
189
- const inner = rest.join(" ");
190
- return /^python[0-9.]*$/.test(command(inner)) || INTERPRETERS.has(command(inner)) ? helper(inner) : ownScript(rest[0]);
191
- }
192
- return true;
193
- }
194
- if (!INTERPRETERS.has(name) && !/^python[0-9.]*$/.test(name)) return false;
195
- if (name === "bun" && rest[0] === "x") return false;
196
- if ((name === "bun" || name === "deno") && rest[0] === "run") {
197
- rest = rest.slice(1);
198
- if (name === "deno") while (rest[0]?.startsWith("-")) rest = rest.slice(1);
199
- const target = rest.find((word) => !word.startsWith("-"));
200
- if (target !== void 0 && !/[/.]/.test(target)) return false;
201
- }
202
- for (let i = 0; i < rest.length; i++) {
203
- const word = rest[i];
204
- if (word === "-m") return false;
205
- if (INLINE.has(word)) return true;
206
- if (VALUED.has(word)) {
207
- if (!ownScript(rest[++i])) return false;
208
- continue;
209
- }
210
- if (!word.startsWith("-")) return ownScript(word);
211
- }
212
- return true;
213
- }
214
- function harnessLineage(pid, table = readPsTable()) {
215
- const keys = lineage(pid, table);
216
- let first = -1;
217
- for (let i = 0, at = pid; i < keys.length; i++, at = table.get(at).ppid) {
218
- const args = table.get(at).args;
219
- if (PASS_THROUGH.has(command(args))) continue;
220
- if (!helper(args)) return keys.slice(0, i + 1);
221
- if (first < 0) first = i;
222
- }
223
- return first < 0 ? [] : keys;
224
- }
225
- var INITS = /* @__PURE__ */ new Set(["init", "systemd", "launchd"]);
226
- function hiddenHarness(pid, table = readPsTable()) {
227
- if (!table || harnessLineage(pid, table).length) return false;
228
- const seen = /* @__PURE__ */ new Set();
229
- let at = pid;
230
- while (at > 1 && !seen.has(at)) {
231
- seen.add(at);
232
- const entry = table.get(at);
233
- if (!entry) return false;
234
- at = entry.ppid;
235
- }
236
- const init = table.get(1);
237
- return at === 1 && init !== void 0 && !INITS.has(command(init.args));
238
- }
239
- function lineage(harnessPid2, table = readPsTable()) {
240
- const keys = [];
241
- const seen = /* @__PURE__ */ new Set();
242
- for (let pid = harnessPid2; pid > 1 && keys.length < LIMITS.lineageMax && !seen.has(pid); ) {
243
- const entry = table?.get(pid);
244
- if (!entry) break;
245
- seen.add(pid);
246
- keys.push(/^[A-Za-z0-9:-]{1,64}$/.test(entry.start) ? `pid:${pid}:${entry.start}` : `pid:${pid}`);
247
- pid = entry.ppid;
248
- }
249
- return keys;
250
- }
251
- function spawnerKey(pid = process.pid, table = readPsTable()) {
252
- const key = lineage(pid, table)[0];
253
- return key?.startsWith(`pid:${pid}:`) ? key : void 0;
254
- }
255
- function psParent(pid) {
256
- const match = /^\s*(\d+)\s+(.+?)\s*$/.exec(capture(["ps", "-o", "ppid=,comm=", "-p", String(pid)], { PATH: process.env.PATH ?? "/usr/bin:/bin" }) ?? "");
257
- return match ? { ppid: Number(match[1]), comm: match[2] } : void 0;
258
- }
259
- function harnessPid(ppid = process.ppid, parentOf = psParent) {
260
- const parent = parentOf(ppid);
261
- if (parent && parent.ppid > 1 && SHELLS.has(basename(parent.comm.replace(/^-/, "")))) return parent.ppid;
262
- return ppid;
263
- }
264
- function hookHarnessPid(env, harness, ppid = process.ppid, parentOf = psParent) {
265
- const named = harness === "claude-code" ? env.CLAUDE_PID : harness === "opencode" ? env.OPENCODE_PID : void 0;
266
- const pid = Number(named);
267
- if (Number.isInteger(pid) && pid > 1) return pid;
268
- return harnessPid(ppid, parentOf);
269
- }
270
- function relayIdentity(input) {
271
- const harness = resolveHarness(input.harness, input.env, input.fallbackHarness);
272
- const cwd = isAbsolute(input.cwd) ? input.cwd : resolve(input.cwd);
273
- const handle = input.as ?? input.env.SCP_NAME ?? deriveHandle(harness, cwd);
274
- const pid = input.harnessPid(harness);
275
- const harnessProcess = processKey(pid, input.startOf);
276
- const keys = input.lineageOf ? input.lineageOf(pid) : lineage(pid);
277
- return {
278
- handle,
279
- harness,
280
- cwd,
281
- session: sessionKey(input.env, harnessProcess),
282
- process: harnessProcess,
283
- labels: labelsFor(input.env),
284
- ...input.env.SCP_PARENT ? { parent: input.env.SCP_PARENT } : {},
285
- ...keys.length ? { lineage: keys } : {},
286
- ...input.env.SCP_GRANT ? { grant: input.env.SCP_GRANT } : {}
287
- };
288
- }
289
-
290
- export {
291
- shortHostname,
292
- detectHarness,
293
- hookHarness,
294
- gitToplevel,
295
- labelsFor,
296
- readPsTable,
297
- harnessLineage,
298
- hiddenHarness,
299
- lineage,
300
- spawnerKey,
301
- psParent,
302
- harnessPid,
303
- hookHarnessPid,
304
- relayIdentity
305
- };
@@ -1,15 +0,0 @@
1
- import {
2
- hooksTarget,
3
- installHooks,
4
- mcpInstall
5
- } from "./chunk-5DYFYLAQ.js";
6
- import "./chunk-3V3DRXB2.js";
7
- import "./chunk-RXKBND3T.js";
8
- import "./chunk-YYSLYVNZ.js";
9
- import "./chunk-E53YHYEP.js";
10
- import "./chunk-M2DCR2J4.js";
11
- export {
12
- hooksTarget,
13
- installHooks,
14
- mcpInstall
15
- };