@peer2peer/ext-ix 0.1.0 → 0.1.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.
- package/README.md +8 -4
- package/SPEC.md +94 -4
- package/dist/extension.d.ts +17 -3
- package/dist/extension.js +77 -14
- package/dist/footprint-command.d.ts +1 -1
- package/dist/footprint-command.js +2 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/ix.d.ts +138 -0
- package/dist/ix.js +354 -10
- package/dist/listener.d.ts +48 -0
- package/dist/listener.js +203 -0
- package/dist/memory.d.ts +50 -0
- package/dist/memory.js +315 -0
- package/dist/subgraph.js +2 -2
- package/dist/text.d.ts +2 -0
- package/dist/text.js +8 -1
- package/package.json +6 -3
package/dist/ix.js
CHANGED
|
@@ -9,8 +9,10 @@
|
|
|
9
9
|
// ix --version is Ix installed
|
|
10
10
|
// ix impact <target> --format json [--kind k] [--path p] [--depth n] [--limit n]
|
|
11
11
|
// ix around <path> --format json [--limit n] callers / users / tests / importers of a file
|
|
12
|
-
// ix note
|
|
13
|
-
// ix note
|
|
12
|
+
// ix --help which `ix note` / `ix session` answer: OSS (local) or Ix Pro (cloud)
|
|
13
|
+
// ix note --json show <id> read a note (OSS: the local backend; refused when Ix Pro answers)
|
|
14
|
+
// ix note --tag=t [--session=s] [--actor=a] --json < text write a note (likewise)
|
|
15
|
+
// ix session --json create <p2p-name> --purpose=p --actor=a --ttl=h a session's record in the local graph (likewise)
|
|
14
16
|
// ix overview <file> --format llm resolve a subgraph: one file
|
|
15
17
|
// ix inventory --kind file --path <prefix> --format llm --limit n a directory
|
|
16
18
|
// ix context <symbol> --format llm [--kind k] [--path p] a symbol
|
|
@@ -20,23 +22,365 @@
|
|
|
20
22
|
// ix overview <file> --format json a file's key items (footprint, coarse fallback)
|
|
21
23
|
import { execFile } from "node:child_process";
|
|
22
24
|
import { IxExtError } from "./text.js";
|
|
25
|
+
import { delimiter, isAbsolute, resolve as resolvePath } from "node:path";
|
|
23
26
|
import { whichAbsolute } from "./which.js";
|
|
27
|
+
import { checkLoopbackListener } from "./listener.js";
|
|
24
28
|
export const IX_TIMEOUT_MS = 30_000;
|
|
25
29
|
const MAX_OUTPUT = 8 * 1024 * 1024;
|
|
26
30
|
/** Lines the CLI prints about its own plugins, not about the request. */
|
|
27
31
|
const NOISE = /^ix: failed to load [^\n]*$/gm;
|
|
32
|
+
/** `s` without trailing slashes (a loop, not a regex: linear on any input). */
|
|
33
|
+
function trimSlashes(s) {
|
|
34
|
+
let n = s.length;
|
|
35
|
+
while (n > 0 && s.charCodeAt(n - 1) === 47)
|
|
36
|
+
n--;
|
|
37
|
+
return s.slice(0, n);
|
|
38
|
+
}
|
|
39
|
+
/** Ix's own default backend (ix-cli DEFAULT_ENDPOINT). */
|
|
40
|
+
export const DEFAULT_IX_ENDPOINT = "http://localhost:8090";
|
|
41
|
+
/** http(s) to localhost, 127.0.0.0/8 or ::1, no credentials, query or fragment (as p2p's isLoopbackEndpoint). */
|
|
42
|
+
export function isLoopbackEndpoint(url) {
|
|
43
|
+
if (typeof url !== "string" || url.length > 512 || /[\s\0]/.test(url))
|
|
44
|
+
return false;
|
|
45
|
+
let u;
|
|
46
|
+
try {
|
|
47
|
+
u = new URL(url);
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
if ((u.protocol !== "http:" && u.protocol !== "https:") || u.username || u.password || u.search || u.hash)
|
|
53
|
+
return false;
|
|
54
|
+
const h = u.hostname.toLowerCase();
|
|
55
|
+
return h === "localhost" || h === "[::1]" || /^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(h);
|
|
56
|
+
}
|
|
57
|
+
/** A loopback endpoint as `origin + pathname`, trailing slashes dropped; undefined when it isn't one. */
|
|
58
|
+
export function normalizeLoopbackEndpoint(url) {
|
|
59
|
+
if (!isLoopbackEndpoint(url))
|
|
60
|
+
return undefined;
|
|
61
|
+
const u = new URL(url);
|
|
62
|
+
return trimSlashes(u.origin + u.pathname);
|
|
63
|
+
}
|
|
64
|
+
/** A shared graph's endpoint as `origin + pathname`: https, off this machine, no credentials, query or fragment. */
|
|
65
|
+
export function normalizeSharedEndpoint(url) {
|
|
66
|
+
if (typeof url !== "string" || url.length > 512 || /[\s\0]/.test(url) || isLoopbackEndpoint(url))
|
|
67
|
+
return undefined;
|
|
68
|
+
let u;
|
|
69
|
+
try {
|
|
70
|
+
u = new URL(url);
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
if (u.protocol !== "https:" || u.username || u.password || u.search || u.hash)
|
|
76
|
+
return undefined;
|
|
77
|
+
return trimSlashes(u.origin + u.pathname);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The local target a library caller (or a p2p from before graph targets) gets: Ix's default
|
|
81
|
+
* backend. Never from the environment (IX_ENDPOINT is exactly what an agent or a Pro login sets):
|
|
82
|
+
* a person's other local port comes from p2p's config.json, through the host's target.
|
|
83
|
+
*/
|
|
84
|
+
export function localTarget(_env) {
|
|
85
|
+
return { kind: "local", endpoint: DEFAULT_IX_ENDPOINT };
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* A target as given, checked again here (a buggy or older host is not trusted with it): a local
|
|
89
|
+
* one must name a loopback endpoint, a shared one an https endpoint off this machine. Anything else
|
|
90
|
+
* is the default local target.
|
|
91
|
+
*/
|
|
92
|
+
export function checkedTarget(t) {
|
|
93
|
+
const x = t;
|
|
94
|
+
const lo = x && x.kind === "local" ? normalizeLoopbackEndpoint(x.endpoint) : undefined;
|
|
95
|
+
if (lo)
|
|
96
|
+
return { kind: "local", endpoint: lo, ...(typeof x.why === "string" ? { why: x.why } : {}), ...(x.trustRootListener === true ? { trustRootListener: true } : {}) };
|
|
97
|
+
const sh = x && x.kind === "shared" && typeof x.circle === "string" ? normalizeSharedEndpoint(x.endpoint) : undefined;
|
|
98
|
+
if (sh)
|
|
99
|
+
return { kind: "shared", circle: x.circle, endpoint: sh, ...(typeof x.token === "string" && /^[\x21-\x7e]{1,4096}$/.test(x.token) ? { token: x.token } : {}) };
|
|
100
|
+
return { kind: "local", endpoint: DEFAULT_IX_ENDPOINT };
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* What an `ix` child sees of the environment: these names only (case-insensitively, as on
|
|
104
|
+
* Windows). No IX_ENDPOINT, IX_PAT, IX_ORG or any other IX_* cloud or login setting of the caller's
|
|
105
|
+
* (Ix Pro's PAT mode is driven by the environment alone), no P2P_* (the person token), no
|
|
106
|
+
* NODE_OPTIONS, proxies, LD_* or DYLD_*. IX_HOME (where Ix keeps its local state, the workspace
|
|
107
|
+
* registry) and IX_TOKEN (the local backend's token, which Ix sends to a loopback endpoint only)
|
|
108
|
+
* stay.
|
|
109
|
+
*/
|
|
110
|
+
export const IX_ENV_ALLOW = ["PATH", "PATHEXT", "HOME", "USERPROFILE", "HOMEDRIVE", "HOMEPATH", "APPDATA", "LOCALAPPDATA", "SYSTEMROOT", "WINDIR", "TMPDIR", "TEMP", "TMP", "LANG", "LC_ALL", "LC_CTYPE", "LC_MESSAGES", "TZ", "TERM", "NO_COLOR", "IX_HOME", "IX_TOKEN"];
|
|
111
|
+
/**
|
|
112
|
+
* The environment an `ix` call runs with: IX_ENV_ALLOW from `env`, then the target pinned:
|
|
113
|
+
* IX_ENDPOINT is the target's endpoint (Ix reads it before config.yaml's `endpoint`, which Ix Pro
|
|
114
|
+
* rewrites to the cloud cluster on `ix login`); a shared target's token, when it has one, goes as
|
|
115
|
+
* IX_PAT; readers never start a background `ix map` (Ix Pro routes a map to the cloud whenever an
|
|
116
|
+
* org session is active in config.yaml, whatever IX_ENDPOINT says); no update check.
|
|
117
|
+
*/
|
|
118
|
+
export function ixEnv(env, target) {
|
|
119
|
+
const allow = new Set(IX_ENV_ALLOW);
|
|
120
|
+
const out = {};
|
|
121
|
+
for (const [k, v] of Object.entries(env))
|
|
122
|
+
if (typeof v === "string" && allow.has(k.toUpperCase()))
|
|
123
|
+
out[k] = k.toUpperCase() === "PATH" ? absolutePath(v) : v;
|
|
124
|
+
out.IX_ENDPOINT = target.endpoint;
|
|
125
|
+
if (target.kind === "shared" && target.token)
|
|
126
|
+
out.IX_PAT = target.token;
|
|
127
|
+
out.IX_MAP_BACKGROUND_REFRESH = "0";
|
|
128
|
+
out.IX_NO_UPDATE_CHECK = "1";
|
|
129
|
+
return out;
|
|
130
|
+
}
|
|
131
|
+
/** PATH with its relative and empty entries dropped (they mean the current directory: a repository's own `node`). */
|
|
132
|
+
export function absolutePath(v, platform = process.platform) {
|
|
133
|
+
const sep = platform === "win32" ? ";" : delimiter;
|
|
134
|
+
return v
|
|
135
|
+
.split(sep)
|
|
136
|
+
.filter((d) => {
|
|
137
|
+
const x = d.trim().replace(/^"|"$/g, "");
|
|
138
|
+
return x !== "" && (platform === "win32" ? /^(?:[A-Za-z]:[\\/]|\\\\)/.test(x) : isAbsolute(x));
|
|
139
|
+
})
|
|
140
|
+
.join(sep);
|
|
141
|
+
}
|
|
142
|
+
/** At most this many paths one call names for its target (p2p refuses more: local). */
|
|
143
|
+
const MAX_CALL_PATHS = 32;
|
|
144
|
+
/**
|
|
145
|
+
* The paths an `ix` call names, absolute: the folder it runs in, its positional target (a file, a
|
|
146
|
+
* `file:start-end` range, a directory or a symbol, resolved against the cwd: a symbol only names
|
|
147
|
+
* the cwd's project again), and the values of `--path` and `--root`. Every one's project is
|
|
148
|
+
* intersected into the call's graph target, so a call can't reach past a private project it names.
|
|
149
|
+
*/
|
|
150
|
+
export function callPaths(call) {
|
|
151
|
+
const out = [call.cwd];
|
|
152
|
+
const add = (v) => {
|
|
153
|
+
if (typeof v !== "string" || v === "" || v.startsWith("-"))
|
|
154
|
+
return;
|
|
155
|
+
const p = v.replace(/:\d{1,9}(?:-\d{1,9})?$/, "");
|
|
156
|
+
out.push(isAbsolute(p) ? p : resolvePath(call.cwd, p));
|
|
157
|
+
};
|
|
158
|
+
const a = call.argv;
|
|
159
|
+
if (a[0] && !a[0].startsWith("-"))
|
|
160
|
+
add(a[1]);
|
|
161
|
+
for (let i = 1; i < a.length; i++) {
|
|
162
|
+
const m = /^--(path|root)(?:=(.*))?$/.exec(a[i]);
|
|
163
|
+
if (!m)
|
|
164
|
+
continue;
|
|
165
|
+
add(m[2] !== undefined ? m[2] : a[++i]);
|
|
166
|
+
}
|
|
167
|
+
return [...new Set(out)].slice(0, MAX_CALL_PATHS);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* The `ix` subcommands ext-ix may run against a local target: reads of the local graph only. Ix
|
|
171
|
+
* Pro's own commands (`ix note` writes and reads Ix-memory in the cloud, whatever IX_ENDPOINT says)
|
|
172
|
+
* and `ix map` (routed to the cloud when an org session is active) are refused, so a private
|
|
173
|
+
* project's content never reaches the cloud through ext-ix. The exceptions are the memory calls
|
|
174
|
+
* (memoryCall): exact forms of `ix note` and `ix session`, allowed against a local target only and
|
|
175
|
+
* only when the `ix` that answers is the OSS one (guardRunner, memorySupport).
|
|
176
|
+
*/
|
|
177
|
+
export const LOCAL_IX_COMMANDS = ["--version", "impact", "around", "overview", "inventory", "context", "subsystems", "status"];
|
|
178
|
+
// ---------------------------------------------------------------------------
|
|
179
|
+
// Memory calls (epic #41 piece 2): OSS `ix note` and `ix session` against the local backend
|
|
180
|
+
/** Tags `ix note --tag` takes (the OSS CLI and Ix Pro accept the same four). */
|
|
181
|
+
const MEMORY_TAGS = ["note", "finding", "decision", "reminder"];
|
|
182
|
+
/** An Ix note id (`ix note show <id>`): what --ix-note accepts. */
|
|
183
|
+
export const IX_NOTE_ID_RE = /^[A-Za-z0-9_][A-Za-z0-9_.:-]{0,127}$/;
|
|
184
|
+
/** An Ix session reference (`--session=`): a name or an id. */
|
|
185
|
+
export const IX_SESSION_REF_RE = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/;
|
|
186
|
+
/** The sessions ext-ix creates: `p2p-` and a session id (or its hash). */
|
|
187
|
+
export const IX_SESSION_NAME_RE = /^p2p-[A-Za-z0-9][A-Za-z0-9._-]{0,99}$/;
|
|
188
|
+
/** `--actor=`: `p2p`, or `p2p:` and a Peer2Peer address. A label on the OSS backend, never an identity. */
|
|
189
|
+
export const IX_ACTOR_RE = /^p2p(?::[A-Za-z0-9._@-]{1,80})?$/;
|
|
190
|
+
/** Longest `--purpose=` ext-ix sends. */
|
|
191
|
+
export const MAX_PURPOSE = 200;
|
|
192
|
+
/** Longest session TTL ext-ix asks for, in hours (a year). */
|
|
193
|
+
export const MAX_TTL_HOURS = 8760;
|
|
194
|
+
/** One line of printable text: no control or format characters, no line or paragraph separators. */
|
|
195
|
+
const isOneLine = (s) => !/[\p{Cc}\p{Cf}\u2028\u2029]/u.test(s);
|
|
196
|
+
/**
|
|
197
|
+
* Which memory call `argv` is, when it is exactly one of the forms ext-ix runs; undefined for
|
|
198
|
+
* anything else (another subcommand, an extra or repeated flag, a positional note text: the text
|
|
199
|
+
* only ever goes on stdin, never into argv where `ps` shows it):
|
|
200
|
+
* ix --help which commands answer (memorySupport)
|
|
201
|
+
* ix note --json show <id> read a note (--ix-note)
|
|
202
|
+
* ix session --json show <ref> is a remembered session still there
|
|
203
|
+
* ix note --tag=<t> [--session=<ref>] [--actor=<a>] --json write a note, text on stdin
|
|
204
|
+
* ix session --json create <p2p-name> --purpose=<p> --actor=<a> --ttl=<h> a session record
|
|
205
|
+
*/
|
|
206
|
+
export function memoryCall(argv) {
|
|
207
|
+
const a = argv;
|
|
208
|
+
if (a.length === 1 && a[0] === "--help")
|
|
209
|
+
return "help";
|
|
210
|
+
if (a[0] === "note") {
|
|
211
|
+
if (a.length === 4 && a[1] === "--json" && a[2] === "show" && IX_NOTE_ID_RE.test(a[3]))
|
|
212
|
+
return "note-show";
|
|
213
|
+
const seen = new Set();
|
|
214
|
+
for (const x of a.slice(1)) {
|
|
215
|
+
const m = /^--(tag|session|actor)=(.*)$/s.exec(x);
|
|
216
|
+
const key = x === "--json" ? "json" : m?.[1];
|
|
217
|
+
if (key === undefined || seen.has(key))
|
|
218
|
+
return undefined;
|
|
219
|
+
seen.add(key);
|
|
220
|
+
if (key === "tag" && !MEMORY_TAGS.includes(m[2]))
|
|
221
|
+
return undefined;
|
|
222
|
+
if (key === "session" && !IX_SESSION_REF_RE.test(m[2]))
|
|
223
|
+
return undefined;
|
|
224
|
+
if (key === "actor" && !IX_ACTOR_RE.test(m[2]))
|
|
225
|
+
return undefined;
|
|
226
|
+
}
|
|
227
|
+
return seen.has("json") && seen.has("tag") ? "note-create" : undefined;
|
|
228
|
+
}
|
|
229
|
+
if (a[0] === "session" && a.length === 4 && a[1] === "--json" && a[2] === "show" && IX_SESSION_REF_RE.test(a[3]))
|
|
230
|
+
return "session-show";
|
|
231
|
+
if (a[0] === "session" && a.length === 7 && a[1] === "--json" && a[2] === "create" && IX_SESSION_NAME_RE.test(a[3])) {
|
|
232
|
+
const purpose = /^--purpose=(.+)$/s.exec(a[4])?.[1];
|
|
233
|
+
const actor = /^--actor=(.+)$/s.exec(a[5])?.[1];
|
|
234
|
+
const ttl = /^--ttl=([1-9]\d{0,3})$/.exec(a[6])?.[1];
|
|
235
|
+
if (purpose === undefined || [...purpose].length > MAX_PURPOSE || !isOneLine(purpose) || purpose.trim() !== purpose)
|
|
236
|
+
return undefined;
|
|
237
|
+
if (actor === undefined || !IX_ACTOR_RE.test(actor))
|
|
238
|
+
return undefined;
|
|
239
|
+
if (ttl === undefined || Number(ttl) > MAX_TTL_HOURS)
|
|
240
|
+
return undefined;
|
|
241
|
+
return "session-create";
|
|
242
|
+
}
|
|
243
|
+
return undefined;
|
|
244
|
+
}
|
|
245
|
+
/** Calls that write to the backend: each must say on stderr that it went to the local backend. */
|
|
246
|
+
const WRITES = new Set(["note-create", "session-create"]);
|
|
247
|
+
export function parseMemorySupport(help) {
|
|
248
|
+
const lines = help.replace(/\u001b\[[0-9;]*m/g, "").split(/\r?\n/);
|
|
249
|
+
if (lines.some((l) => /^Pro:\s*$/.test(l)))
|
|
250
|
+
return "pro";
|
|
251
|
+
const at = lines.findIndex((l) => /^Memory:\s*$/.test(l));
|
|
252
|
+
if (at < 0)
|
|
253
|
+
return "none";
|
|
254
|
+
const section = [];
|
|
255
|
+
for (const l of lines.slice(at + 1)) {
|
|
256
|
+
if (!/^\s+\S/.test(l))
|
|
257
|
+
break;
|
|
258
|
+
section.push(l);
|
|
259
|
+
}
|
|
260
|
+
const has = (name) => section.some((l) => new RegExp(`^\\s+${name}\\s`).test(l));
|
|
261
|
+
return has("note") && has("session") ? "oss" : "none";
|
|
262
|
+
}
|
|
263
|
+
/** Why a memory call can't run with this Ix, for a person: what to do about it. */
|
|
264
|
+
export function memoryRefusal(support, target) {
|
|
265
|
+
const where = target.kind === "local" && target.why ? ` (${target.why})` : "";
|
|
266
|
+
if (support === "pro") {
|
|
267
|
+
return new IxExtError("graph_target", `Ix Pro is installed, and its \`ix note\` and \`ix session\` write to your Ix cloud org whatever the endpoint; this graph is local only${where}, so Peer2Peer doesn't run them (\`p2p project show\` shows the graph)`, { ix: "pro" });
|
|
268
|
+
}
|
|
269
|
+
return new IxExtError("graph_target", `this Ix has no local \`ix note\` (it came after Ix 0.13.0, ix-infrastructure/Ix#916): upgrade Ix (\`ix upgrade\`), and Peer2Peer writes notes into your local graph${where}`, { ix: "upgrade" });
|
|
270
|
+
}
|
|
271
|
+
/** `ix --help` through `ix`, read as a MemorySupport; "none" when it fails. */
|
|
272
|
+
export async function memorySupport(ix) {
|
|
273
|
+
try {
|
|
274
|
+
const r = await ix.run(["--help"], { timeoutMs: 15_000 });
|
|
275
|
+
return r.code === 0 ? parseMemorySupport(r.stdout) : "none";
|
|
276
|
+
}
|
|
277
|
+
catch {
|
|
278
|
+
return "none";
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
/** Whether a write's stderr says it went to `endpoint`, the local backend (OSS `ix note`/`ix session` print `→ local backend <origin+path>`). */
|
|
282
|
+
export function confirmsLocalWrite(stderr, endpoint) {
|
|
283
|
+
const want = `→ local backend ${endpoint}`;
|
|
284
|
+
return stderr
|
|
285
|
+
.replace(/\u001b\[[0-9;]*m/g, "")
|
|
286
|
+
.split(/\r?\n/)
|
|
287
|
+
.some((l) => l.trim() === want);
|
|
288
|
+
}
|
|
289
|
+
/** The refusal for a command a target doesn't allow. */
|
|
290
|
+
export function refuseForTarget(argv, target) {
|
|
291
|
+
const cmd = argv[0] ?? "";
|
|
292
|
+
if (LOCAL_IX_COMMANDS.includes(cmd))
|
|
293
|
+
return undefined;
|
|
294
|
+
const memory = memoryCall(argv);
|
|
295
|
+
if (memory === "help")
|
|
296
|
+
return undefined;
|
|
297
|
+
if (target.kind === "local") {
|
|
298
|
+
if (memory !== undefined)
|
|
299
|
+
return undefined;
|
|
300
|
+
if (cmd === "note" || cmd === "session") {
|
|
301
|
+
return new IxExtError("graph_target", `ext-ix runs only its own forms of \`ix ${cmd}\` (to the local graph${target.why ? `: ${target.why}` : ""}), not this one`);
|
|
302
|
+
}
|
|
303
|
+
return new IxExtError("graph_target", `\`ix ${cmd.slice(0, 40)}\` can reach Ix Pro's cloud, and this project's graph is local only${target.why ? ` (${target.why})` : ""}: Peer2Peer doesn't run it (\`p2p project show\` shows the graph)`);
|
|
304
|
+
}
|
|
305
|
+
if (cmd === "note" || cmd === "session") {
|
|
306
|
+
// Graph memory (notes, sessions) goes to the local graph only: no shared graph takes it yet.
|
|
307
|
+
return new IxExtError("graph_target", `ext-ix writes Ix notes and sessions to the local graph only, never to a shared graph (circle ${target.circle.slice(0, 64)})`);
|
|
308
|
+
}
|
|
309
|
+
return new IxExtError("graph_target", `ext-ix doesn't run \`ix ${cmd.slice(0, 40)}\` against a shared graph yet`);
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Wraps a runner so every call is checked against its target first (refuseForTarget). `cwd`: the
|
|
313
|
+
* folder a call runs in when it names none. A memory call (`ix note`, `ix session`) also needs:
|
|
314
|
+
* - the target's port to be held by this user's process only (root's too only with the person's
|
|
315
|
+
* `ixTrustRootListener`, listener.ts), checked before every write and once per guard for a read,
|
|
316
|
+
* else `ix_listener`;
|
|
317
|
+
* - the OSS commands (memorySupport): asked once per guard, and again right before every
|
|
318
|
+
* `ix session create`;
|
|
319
|
+
* - for a write, stderr saying it went to the target's local endpoint, whatever the exit code:
|
|
320
|
+
* else `ix_unconfirmed` (whatever answered was not the OSS command against that backend).
|
|
321
|
+
*/
|
|
322
|
+
export function guardRunner(inner, target, cwd = process.cwd(), opts = {}) {
|
|
323
|
+
let support;
|
|
324
|
+
const listeners = new Map();
|
|
325
|
+
const listener = opts.listener ?? ((e, o) => checkLoopbackListener(e, { trustRoot: o?.trustRoot === true }));
|
|
326
|
+
return {
|
|
327
|
+
run: async (argv, o) => {
|
|
328
|
+
const t = await target({ argv, cwd: o?.cwd ?? cwd });
|
|
329
|
+
const refused = refuseForTarget(argv, t);
|
|
330
|
+
if (refused)
|
|
331
|
+
throw refused;
|
|
332
|
+
const memory = memoryCall(argv);
|
|
333
|
+
if (memory === undefined || memory === "help")
|
|
334
|
+
return inner.run(argv, o);
|
|
335
|
+
const trustRoot = t.kind === "local" && t.trustRootListener === true;
|
|
336
|
+
const ask = () => listener(t.endpoint, { trustRoot }).catch(() => ({ ok: false, why: "couldn't tell who listens on its port" }));
|
|
337
|
+
// Every write asks again (a listener can change between writes); reads ask once per guard.
|
|
338
|
+
let held = WRITES.has(memory) ? undefined : listeners.get(`${t.endpoint}|${trustRoot}`);
|
|
339
|
+
if (!held) {
|
|
340
|
+
held = ask();
|
|
341
|
+
if (!WRITES.has(memory))
|
|
342
|
+
listeners.set(`${t.endpoint}|${trustRoot}`, held);
|
|
343
|
+
}
|
|
344
|
+
const v = await held;
|
|
345
|
+
if (!v.ok)
|
|
346
|
+
throw new IxExtError("ix_listener", `the local Ix endpoint ${t.endpoint} isn't one Peer2Peer can trust: ${v.why}; it writes nothing to Ix until it is`);
|
|
347
|
+
// Right before a session record is created, ask again: Ix Pro may have been installed since.
|
|
348
|
+
if (memory === "session-create")
|
|
349
|
+
support = memorySupport(inner);
|
|
350
|
+
support ??= memorySupport(inner);
|
|
351
|
+
const s = await support;
|
|
352
|
+
if (s !== "oss")
|
|
353
|
+
throw memoryRefusal(s, t);
|
|
354
|
+
const r = await inner.run(argv, o);
|
|
355
|
+
if (WRITES.has(memory) && !confirmsLocalWrite(r.stderr, t.endpoint)) {
|
|
356
|
+
throw new IxExtError("ix_unconfirmed", `\`ix ${argv[0]}\` didn't say it wrote to the local backend (${t.endpoint}): Peer2Peer stops writing to Ix until it does (is Ix Pro installed now, or is the backend down?)`, { exit: r.code });
|
|
357
|
+
}
|
|
358
|
+
return r;
|
|
359
|
+
},
|
|
360
|
+
};
|
|
361
|
+
}
|
|
28
362
|
export function ixRunner(opts = {}) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const name = env.IX_BIN?.trim() || "ix";
|
|
363
|
+
// The merged view is read for IX_BIN and PATH only; the child gets ixEnv's allowlist.
|
|
364
|
+
const view = { ...process.env, ...opts.env };
|
|
365
|
+
const name = view.IX_BIN?.trim() || "ix";
|
|
33
366
|
// Absolute, from PATH's absolute entries: never a program planted in the repo (cwd).
|
|
34
|
-
const bin = whichAbsolute(name,
|
|
367
|
+
const bin = whichAbsolute(name, view);
|
|
368
|
+
const target = async (call) => {
|
|
369
|
+
const t = opts.target;
|
|
370
|
+
if (t === undefined)
|
|
371
|
+
return localTarget();
|
|
372
|
+
try {
|
|
373
|
+
return checkedTarget(typeof t === "function" ? await t(call) : t);
|
|
374
|
+
}
|
|
375
|
+
catch {
|
|
376
|
+
return localTarget();
|
|
377
|
+
}
|
|
378
|
+
};
|
|
35
379
|
return {
|
|
36
|
-
run: (argv, o = {}) => new Promise((resolve, reject) => {
|
|
380
|
+
run: (argv, o = {}) => target({ argv, cwd: o.cwd ?? opts.cwd ?? process.cwd() }).then((t) => new Promise((resolve, reject) => {
|
|
37
381
|
if (!bin)
|
|
38
382
|
return reject(new IxExtError("ix_missing", `Ix isn't installed (no \`${name}\` on PATH): https://github.com/ix-infrastructure/Ix`));
|
|
39
|
-
const child = execFile(bin, [...argv], { cwd: o.cwd ?? opts.cwd, env, timeout: o.timeoutMs ?? IX_TIMEOUT_MS, killSignal: "SIGKILL", maxBuffer: MAX_OUTPUT, windowsHide: true }, (err, stdout, stderr) => {
|
|
383
|
+
const child = execFile(bin, [...argv], { cwd: o.cwd ?? opts.cwd, env: ixEnv(view, t), timeout: o.timeoutMs ?? IX_TIMEOUT_MS, killSignal: "SIGKILL", maxBuffer: MAX_OUTPUT, windowsHide: true }, (err, stdout, stderr) => {
|
|
40
384
|
const e = err;
|
|
41
385
|
if (e && e.code === "ENOENT")
|
|
42
386
|
return reject(new IxExtError("ix_missing", `Ix isn't installed (no \`${bin}\` on PATH): https://github.com/ix-infrastructure/Ix`));
|
|
@@ -49,7 +393,7 @@ export function ixRunner(opts = {}) {
|
|
|
49
393
|
child.stdin?.end(o.stdin);
|
|
50
394
|
else
|
|
51
395
|
child.stdin?.end();
|
|
52
|
-
}),
|
|
396
|
+
})),
|
|
53
397
|
};
|
|
54
398
|
}
|
|
55
399
|
/** Whether `ix` runs at all (cached per runner). */
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export type ListenerVerdict = {
|
|
2
|
+
ok: true;
|
|
3
|
+
} | {
|
|
4
|
+
ok: false;
|
|
5
|
+
why: string;
|
|
6
|
+
};
|
|
7
|
+
/** Checks the listener of a loopback endpoint (http(s) URL); `trustRoot`: a root-owned listener counts. */
|
|
8
|
+
export type ListenerCheck = (endpoint: string, opts?: {
|
|
9
|
+
trustRoot?: boolean;
|
|
10
|
+
}) => Promise<ListenerVerdict>;
|
|
11
|
+
/** What the person can do about a root-owned listener. */
|
|
12
|
+
export declare const ROOT_HINT = "root holds it: on Linux that is Docker's port proxy, whoever started the container. If this machine's Docker is only yours, set \"ixTrustRootListener\": true in p2p's config.json";
|
|
13
|
+
export interface Listener {
|
|
14
|
+
/** The local address, normalized: an IPv4 dotted quad, or IPv6 in lower-case hex groups. */
|
|
15
|
+
addr: string;
|
|
16
|
+
port: number;
|
|
17
|
+
uid?: number;
|
|
18
|
+
pid?: number;
|
|
19
|
+
}
|
|
20
|
+
/** The port of an http(s) endpoint, or undefined. */
|
|
21
|
+
export declare function endpointPort(endpoint: string): number | undefined;
|
|
22
|
+
/** Whether a connection to a loopback address could reach a socket bound to `addr`. */
|
|
23
|
+
export declare function reachesLoopback(addr: string): boolean;
|
|
24
|
+
/** One /proc/net/tcp{,6} address (hex, little-endian 32-bit words) as text. */
|
|
25
|
+
export declare function procAddr(hex: string): string | undefined;
|
|
26
|
+
/** LISTEN sockets from /proc/net/tcp or tcp6 text. */
|
|
27
|
+
export declare function parseProcNet(text: string): Listener[];
|
|
28
|
+
/** LISTEN sockets from macOS `netstat -an` (no owners). Undefined when the output isn't that. */
|
|
29
|
+
export declare function parseNetstat(text: string): Listener[] | undefined;
|
|
30
|
+
/** This user's LISTEN sockets from `lsof -nP -iTCP:<port> -sTCP:LISTEN -Fpun` (a `p`, `u`, then `n` per socket). */
|
|
31
|
+
export declare function parseLsof(text: string): Listener[];
|
|
32
|
+
/**
|
|
33
|
+
* macOS: every listener on `port` that netstat shows (all users) must be matched, address for
|
|
34
|
+
* address, by one this user's lsof shows (root's too, with trustRoot); one left over belongs to someone lsof can't see.
|
|
35
|
+
*/
|
|
36
|
+
export declare function judgeDarwin(all: readonly Listener[], mine: readonly Listener[], port: number, uid: number, trustRoot?: boolean): ListenerVerdict;
|
|
37
|
+
/** The verdict for the listeners on `port`: all owned by `uid` (or root, with `trustRoot`), and at least one. */
|
|
38
|
+
export declare function judgeListeners(listeners: readonly Listener[], port: number, uid: number, trustRoot?: boolean): ListenerVerdict;
|
|
39
|
+
export interface ListenerDeps {
|
|
40
|
+
platform?: NodeJS.Platform;
|
|
41
|
+
uid?: number;
|
|
42
|
+
readFile?: (path: string) => Promise<string>;
|
|
43
|
+
exec?: (cmd: string, args: string[]) => Promise<string>;
|
|
44
|
+
}
|
|
45
|
+
/** The real check (see the top of this file). */
|
|
46
|
+
export declare function checkLoopbackListener(endpoint: string, d?: ListenerDeps & {
|
|
47
|
+
trustRoot?: boolean;
|
|
48
|
+
}): Promise<ListenerVerdict>;
|
package/dist/listener.js
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// Copyright 2026 Ix Infrastructure Inc.
|
|
2
|
+
//
|
|
3
|
+
// Who listens on the local Ix endpoint's port. "Local" is a loopback port, and on a machine other
|
|
4
|
+
// people log in to, another user can listen on it while this user's backend is down: they would
|
|
5
|
+
// receive what `ix note` / `ix session` send (session labels, repos, branches, statuses, edited
|
|
6
|
+
// files, a peer's imported note) and the local token Ix sends to loopback. Ix's backend has no
|
|
7
|
+
// identity it can prove (only /v1/health and the opt-in local token, which a listener would just
|
|
8
|
+
// accept), so before ext-ix writes there it asks the operating system who owns every socket
|
|
9
|
+
// listening on that port on a loopback or wildcard address:
|
|
10
|
+
// - Linux: /proc/net/tcp and /proc/net/tcp6 (state 0A = LISTEN, with the owner's uid);
|
|
11
|
+
// - macOS: `netstat -an` lists every user's listening sockets (without owners), and
|
|
12
|
+
// `lsof -iTCP:<port> -sTCP:LISTEN` lists the ones this user's processes hold (a non-root lsof
|
|
13
|
+
// can't see other users'). Every listener netstat shows must be matched by one of this user's.
|
|
14
|
+
// Every such listener must be this user's, and there must be at least one. A root-owned one
|
|
15
|
+
// (Docker's port proxy on Linux runs as root whoever started the container, so on a machine whose
|
|
16
|
+
// Docker others use it may be a teammate's backend) counts only when the person said so:
|
|
17
|
+
// `ixTrustRootListener: true` in p2p's config.json (the host passes it on the graph target). Anything else, or an
|
|
18
|
+
// answer that can't be read, or another platform, means "no": graph writes stay off. This narrows
|
|
19
|
+
// the window; it can't close it (a listener can appear between the check and the write).
|
|
20
|
+
import { execFile } from "node:child_process";
|
|
21
|
+
import { readFile } from "node:fs/promises";
|
|
22
|
+
/** What the person can do about a root-owned listener. */
|
|
23
|
+
export const ROOT_HINT = 'root holds it: on Linux that is Docker\'s port proxy, whoever started the container. If this machine\'s Docker is only yours, set "ixTrustRootListener": true in p2p\'s config.json';
|
|
24
|
+
/** The port of an http(s) endpoint, or undefined. */
|
|
25
|
+
export function endpointPort(endpoint) {
|
|
26
|
+
try {
|
|
27
|
+
const u = new URL(endpoint);
|
|
28
|
+
if (u.protocol !== "http:" && u.protocol !== "https:")
|
|
29
|
+
return undefined;
|
|
30
|
+
const p = u.port ? Number(u.port) : u.protocol === "https:" ? 443 : 80;
|
|
31
|
+
return Number.isInteger(p) && p > 0 && p < 65536 ? p : undefined;
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** Whether a connection to a loopback address could reach a socket bound to `addr`. */
|
|
38
|
+
export function reachesLoopback(addr) {
|
|
39
|
+
const a = addr.toLowerCase();
|
|
40
|
+
if (a === "*" || a === "0.0.0.0" || a === "::" || a === "0:0:0:0:0:0:0:0" || a === "::1" || a === "0:0:0:0:0:0:0:1")
|
|
41
|
+
return true;
|
|
42
|
+
if (/^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(a))
|
|
43
|
+
return true;
|
|
44
|
+
const mapped = /^(?:0:0:0:0:0:ffff|::ffff):(.+)$/.exec(a)?.[1];
|
|
45
|
+
if (mapped)
|
|
46
|
+
return mapped === "0.0.0.0" || /^127\./.test(mapped) || /^7f[0-9a-f]{2}:[0-9a-f]{1,4}$/.test(mapped) || mapped === "0:0";
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
/** One /proc/net/tcp{,6} address (hex, little-endian 32-bit words) as text. */
|
|
50
|
+
export function procAddr(hex) {
|
|
51
|
+
if (/^[0-9A-Fa-f]{8}$/.test(hex)) {
|
|
52
|
+
const b = hex.match(/../g).map((x) => parseInt(x, 16)).reverse();
|
|
53
|
+
return b.join(".");
|
|
54
|
+
}
|
|
55
|
+
if (/^[0-9A-Fa-f]{32}$/.test(hex)) {
|
|
56
|
+
const bytes = [];
|
|
57
|
+
for (const w of hex.match(/.{8}/g))
|
|
58
|
+
bytes.push(...w.match(/../g).map((x) => parseInt(x, 16)).reverse());
|
|
59
|
+
const groups = [];
|
|
60
|
+
for (let i = 0; i < 16; i += 2)
|
|
61
|
+
groups.push(((bytes[i] << 8) | bytes[i + 1]).toString(16));
|
|
62
|
+
// ::ffff:a.b.c.d keeps its IPv4 tail readable.
|
|
63
|
+
if (groups.slice(0, 5).every((g) => g === "0") && groups[5] === "ffff")
|
|
64
|
+
return `::ffff:${bytes.slice(12).join(".")}`;
|
|
65
|
+
return groups.join(":");
|
|
66
|
+
}
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
/** LISTEN sockets from /proc/net/tcp or tcp6 text. */
|
|
70
|
+
export function parseProcNet(text) {
|
|
71
|
+
const out = [];
|
|
72
|
+
for (const line of text.split("\n").slice(1)) {
|
|
73
|
+
const f = line.trim().split(/\s+/);
|
|
74
|
+
if (f.length < 10 || f[3] !== "0A")
|
|
75
|
+
continue;
|
|
76
|
+
const [addrHex, portHex] = f[1].split(":");
|
|
77
|
+
const addr = procAddr(addrHex ?? "");
|
|
78
|
+
const port = parseInt(portHex ?? "", 16);
|
|
79
|
+
const uid = Number(f[7]);
|
|
80
|
+
if (addr === undefined || !Number.isInteger(port) || !Number.isInteger(uid))
|
|
81
|
+
continue;
|
|
82
|
+
out.push({ addr, port, uid });
|
|
83
|
+
}
|
|
84
|
+
return out;
|
|
85
|
+
}
|
|
86
|
+
/** An address as netstat (`127.0.0.1`, `::1`, `*`) or lsof (`[::1]`, `*`) prints it, normalized. */
|
|
87
|
+
function normAddr(a) {
|
|
88
|
+
const x = a.replace(/^\[|\]$/g, "").replace(/%.*$/, "").toLowerCase();
|
|
89
|
+
return x === "*" || x === "0.0.0.0" || x === "::" ? "*" : x;
|
|
90
|
+
}
|
|
91
|
+
/** LISTEN sockets from macOS `netstat -an` (no owners). Undefined when the output isn't that. */
|
|
92
|
+
export function parseNetstat(text) {
|
|
93
|
+
const lines = text.split("\n");
|
|
94
|
+
if (!lines.some((l) => /^Proto\s+Recv-Q\s+Send-Q\s+Local Address/.test(l)))
|
|
95
|
+
return undefined;
|
|
96
|
+
const out = [];
|
|
97
|
+
for (const line of lines) {
|
|
98
|
+
if (!/^tcp[46]{1,2}\s/.test(line) || !/\sLISTEN\s*$/.test(line))
|
|
99
|
+
continue;
|
|
100
|
+
const local = line.trim().split(/\s+/)[3] ?? "";
|
|
101
|
+
const dot = local.lastIndexOf(".");
|
|
102
|
+
const port = Number(local.slice(dot + 1));
|
|
103
|
+
if (dot < 0 || !Number.isInteger(port))
|
|
104
|
+
return undefined;
|
|
105
|
+
out.push({ addr: normAddr(local.slice(0, dot)), port });
|
|
106
|
+
}
|
|
107
|
+
return out;
|
|
108
|
+
}
|
|
109
|
+
/** This user's LISTEN sockets from `lsof -nP -iTCP:<port> -sTCP:LISTEN -Fpun` (a `p`, `u`, then `n` per socket). */
|
|
110
|
+
export function parseLsof(text) {
|
|
111
|
+
const out = [];
|
|
112
|
+
let pid;
|
|
113
|
+
let uid;
|
|
114
|
+
for (const line of text.split("\n")) {
|
|
115
|
+
const k = line[0];
|
|
116
|
+
const v = line.slice(1);
|
|
117
|
+
if (k === "p") {
|
|
118
|
+
pid = Number(v);
|
|
119
|
+
uid = undefined;
|
|
120
|
+
}
|
|
121
|
+
else if (k === "u")
|
|
122
|
+
uid = Number(v);
|
|
123
|
+
else if (k === "n") {
|
|
124
|
+
const colon = v.lastIndexOf(":");
|
|
125
|
+
const port = Number(v.slice(colon + 1));
|
|
126
|
+
if (colon < 0 || !Number.isInteger(port))
|
|
127
|
+
continue;
|
|
128
|
+
out.push({ addr: normAddr(v.slice(0, colon)), port, ...(Number.isInteger(pid) ? { pid } : {}), ...(Number.isInteger(uid) ? { uid } : {}) });
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return out;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* macOS: every listener on `port` that netstat shows (all users) must be matched, address for
|
|
135
|
+
* address, by one this user's lsof shows (root's too, with trustRoot); one left over belongs to someone lsof can't see.
|
|
136
|
+
*/
|
|
137
|
+
export function judgeDarwin(all, mine, port, uid, trustRoot = false) {
|
|
138
|
+
const want = all.filter((l) => l.port === port && reachesLoopback(l.addr));
|
|
139
|
+
if (want.length === 0)
|
|
140
|
+
return { ok: false, why: `nothing listens on port ${port} (is the Ix backend running?)` };
|
|
141
|
+
const have = mine.filter((l) => l.port === port && (l.uid === uid || (l.uid === 0 && trustRoot)));
|
|
142
|
+
const left = new Map();
|
|
143
|
+
for (const l of have)
|
|
144
|
+
left.set(l.addr, (left.get(l.addr) ?? 0) + 1);
|
|
145
|
+
for (const l of want) {
|
|
146
|
+
const n = left.get(l.addr) ?? 0;
|
|
147
|
+
if (n === 0)
|
|
148
|
+
return { ok: false, why: `port ${port} (${l.addr}) is held by a process that isn't yours, not your Ix backend` };
|
|
149
|
+
left.set(l.addr, n - 1);
|
|
150
|
+
}
|
|
151
|
+
return { ok: true };
|
|
152
|
+
}
|
|
153
|
+
/** The verdict for the listeners on `port`: all owned by `uid` (or root, with `trustRoot`), and at least one. */
|
|
154
|
+
export function judgeListeners(listeners, port, uid, trustRoot = false) {
|
|
155
|
+
const mine = listeners.filter((l) => l.port === port && reachesLoopback(l.addr));
|
|
156
|
+
if (mine.length === 0)
|
|
157
|
+
return { ok: false, why: `nothing listens on port ${port} (is the Ix backend running?)` };
|
|
158
|
+
for (const l of mine) {
|
|
159
|
+
if (typeof l.uid !== "number")
|
|
160
|
+
return { ok: false, why: `couldn't tell who listens on port ${port}` };
|
|
161
|
+
if (l.uid === 0 && uid !== 0 && !trustRoot)
|
|
162
|
+
return { ok: false, why: `port ${port}: ${ROOT_HINT}` };
|
|
163
|
+
if (l.uid !== uid && !(l.uid === 0 && trustRoot))
|
|
164
|
+
return { ok: false, why: `port ${port} is held by another user (uid ${l.uid}), not your Ix backend` };
|
|
165
|
+
}
|
|
166
|
+
return { ok: true };
|
|
167
|
+
}
|
|
168
|
+
const run = (cmd, args) => new Promise((resolve, reject) => {
|
|
169
|
+
execFile(cmd, args, { timeout: 10_000, maxBuffer: 8 * 1024 * 1024, env: { PATH: "/usr/sbin:/usr/bin:/bin:/sbin", LANG: "C" }, windowsHide: true }, (err, stdout) => (err ? reject(err) : resolve(String(stdout))));
|
|
170
|
+
});
|
|
171
|
+
/** The real check (see the top of this file). */
|
|
172
|
+
export async function checkLoopbackListener(endpoint, d = {}) {
|
|
173
|
+
const trustRoot = d.trustRoot === true;
|
|
174
|
+
const port = endpointPort(endpoint);
|
|
175
|
+
if (port === undefined)
|
|
176
|
+
return { ok: false, why: "the local endpoint has no port" };
|
|
177
|
+
const platform = d.platform ?? process.platform;
|
|
178
|
+
const uid = d.uid ?? (typeof process.getuid === "function" ? process.getuid() : undefined);
|
|
179
|
+
if (uid === undefined)
|
|
180
|
+
return { ok: false, why: "this platform can't tell who listens on a port" };
|
|
181
|
+
const read = d.readFile ?? ((p) => readFile(p, "utf8"));
|
|
182
|
+
const exec = d.exec ?? run;
|
|
183
|
+
try {
|
|
184
|
+
if (platform === "linux") {
|
|
185
|
+
const texts = await Promise.all(["/proc/net/tcp", "/proc/net/tcp6"].map((p) => read(p).catch(() => "")));
|
|
186
|
+
if (texts.every((t) => t === ""))
|
|
187
|
+
return { ok: false, why: "couldn't read /proc/net/tcp" };
|
|
188
|
+
return judgeListeners(texts.flatMap(parseProcNet), port, uid, trustRoot);
|
|
189
|
+
}
|
|
190
|
+
if (platform === "darwin") {
|
|
191
|
+
const all = parseNetstat(await exec("/usr/sbin/netstat", ["-an"]));
|
|
192
|
+
if (!all)
|
|
193
|
+
return { ok: false, why: "couldn't read netstat's sockets" };
|
|
194
|
+
// lsof exits 1 when it finds nothing: no socket of this user's.
|
|
195
|
+
const mine = parseLsof(await exec("/usr/sbin/lsof", ["-nP", "-a", `-iTCP:${port}`, "-sTCP:LISTEN", "-Fpun"]).catch(() => ""));
|
|
196
|
+
return judgeDarwin(all, mine, port, uid, trustRoot);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
return { ok: false, why: `couldn't tell who listens on port ${port}` };
|
|
201
|
+
}
|
|
202
|
+
return { ok: false, why: `can't tell who listens on a port on ${platform}` };
|
|
203
|
+
}
|