harnery 0.42.0 → 0.43.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/dist/commander.d.ts +16 -0
- package/dist/commander.d.ts.map +1 -1
- package/dist/commander.js +18 -0
- package/dist/commands/agents.d.ts.map +1 -1
- package/dist/commands/agents.js +54 -4
- package/dist/commands/tunnel.d.ts +65 -0
- package/dist/commands/tunnel.d.ts.map +1 -1
- package/dist/commands/tunnel.js +290 -101
- package/dist/commands/web-fetch.d.ts +3 -2
- package/dist/commands/web-fetch.d.ts.map +1 -1
- package/dist/commands/web-fetch.js +25 -19
- package/dist/commands/web.d.ts +7 -1
- package/dist/commands/web.d.ts.map +1 -1
- package/dist/commands/web.js +9 -3
- package/dist/core/agents/render/prompt-context.d.ts.map +1 -1
- package/dist/core/agents/render/prompt-context.js +11 -5
- package/dist/core/agents/render/session-context.d.ts.map +1 -1
- package/dist/core/agents/render/session-context.js +57 -13
- package/dist/core/agents/state/names.d.ts +43 -3
- package/dist/core/agents/state/names.d.ts.map +1 -1
- package/dist/core/agents/state/names.js +87 -3
- package/dist/core/events/v3/support-storage/pack-reader.d.ts.map +1 -1
- package/dist/core/events/v3/support-storage/pack-reader.js +42 -16
- package/dist/core/hooks/cli.js +87 -18
- package/dist/core/hooks/fork-lineage.d.ts +40 -0
- package/dist/core/hooks/fork-lineage.d.ts.map +1 -0
- package/dist/core/hooks/fork-lineage.js +62 -0
- package/dist/core/hooks/resolve/transcript.d.ts +16 -0
- package/dist/core/hooks/resolve/transcript.d.ts.map +1 -1
- package/dist/core/hooks/resolve/transcript.js +84 -0
- package/dist/core/hooks/shell-rm.d.ts +2 -0
- package/dist/core/hooks/shell-rm.d.ts.map +1 -0
- package/dist/core/hooks/shell-rm.js +105 -0
- package/dist/core/hooks/shell-tokens.d.ts +12 -0
- package/dist/core/hooks/shell-tokens.d.ts.map +1 -0
- package/dist/core/hooks/shell-tokens.js +97 -0
- package/dist/core/hooks/shell-waiter.d.ts.map +1 -1
- package/dist/core/hooks/shell-waiter.js +3 -93
- package/dist/core/semantic/contract.d.ts +5 -5
- package/dist/core/storage/process-log.d.ts +12 -0
- package/dist/core/storage/process-log.d.ts.map +1 -1
- package/dist/core/storage/process-log.js +10 -2
- package/dist/lib/tunnel/allowlist.d.ts +44 -0
- package/dist/lib/tunnel/allowlist.d.ts.map +1 -0
- package/dist/lib/tunnel/allowlist.js +204 -0
- package/dist/lib/tunnel/current-address.d.ts +41 -0
- package/dist/lib/tunnel/current-address.d.ts.map +1 -0
- package/dist/lib/tunnel/current-address.js +123 -0
- package/dist/lib/tunnel/gate.js +13 -6
- package/dist/lib/tunnel/processes.d.ts +39 -0
- package/dist/lib/tunnel/processes.d.ts.map +1 -0
- package/dist/lib/tunnel/processes.js +121 -0
- package/dist/lib/tunnel/state.d.ts +28 -3
- package/dist/lib/tunnel/state.d.ts.map +1 -1
- package/dist/lib/tunnel/state.js +98 -27
- package/package.json +2 -1
- package/src/commander.ts +32 -0
- package/src/commands/agents.ts +97 -11
- package/src/commands/tunnel.ts +394 -116
- package/src/commands/web-fetch.ts +30 -19
- package/src/commands/web.ts +9 -3
- package/src/core/agents/render/prompt-context.ts +25 -8
- package/src/core/agents/render/session-context.ts +83 -16
- package/src/core/agents/state/names.ts +117 -6
- package/src/core/events/v3/support-storage/pack-reader.ts +45 -19
- package/src/core/hooks/cli.ts +106 -17
- package/src/core/hooks/fork-lineage.ts +82 -0
- package/src/core/hooks/resolve/transcript.ts +88 -0
- package/src/core/hooks/shell-rm.ts +103 -0
- package/src/core/hooks/shell-tokens.ts +96 -0
- package/src/core/hooks/shell-waiter.ts +4 -91
- package/src/core/storage/process-log.ts +17 -2
- package/src/lib/tunnel/allowlist.ts +208 -0
- package/src/lib/tunnel/current-address.ts +158 -0
- package/src/lib/tunnel/gate.ts +16 -8
- package/src/lib/tunnel/processes.ts +149 -0
- package/src/lib/tunnel/state.ts +123 -27
package/dist/lib/tunnel/gate.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
// Runs detached, outside the CLI command framework; no command context is
|
|
12
12
|
// available; stdout/stderr is captured into .cache/tunnel/gate.log by the
|
|
13
13
|
// spawner.
|
|
14
|
+
import { allowlistMatches, compileAllowlist } from "./allowlist.js";
|
|
14
15
|
import { renderTunnelErrorPage } from "./error-page";
|
|
15
16
|
import { applyUpstreamHeaders } from "./forward-headers";
|
|
16
17
|
import { ALLOW_PATHS_ENV, isPathAllowed, parseAllowPathsEnv } from "./path-scope.js";
|
|
@@ -24,10 +25,8 @@ function argvFlag(flag) {
|
|
|
24
25
|
const i = process.argv.indexOf(flag);
|
|
25
26
|
return i !== -1 ? process.argv[i + 1] : undefined;
|
|
26
27
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
.map((s) => s.trim())
|
|
30
|
-
.filter(Boolean));
|
|
28
|
+
// Entries are exact addresses or CIDR ranges (`203.0.113.0/24`, `2601:db8:1:2::/64`).
|
|
29
|
+
const ALLOW = compileAllowlist((process.env.HARNERY_TUNNEL_ALLOW ?? "").split(","));
|
|
31
30
|
const TARGET = process.env.HARNERY_TUNNEL_TARGET ?? "127.0.0.1:8001";
|
|
32
31
|
const VHOST = process.env.HARNERY_TUNNEL_VHOST ?? "localhost";
|
|
33
32
|
const PORT = Number(process.env.HARNERY_TUNNEL_PORT ?? argvFlag("--port") ?? "9001");
|
|
@@ -66,7 +65,7 @@ const server = Bun.serve({
|
|
|
66
65
|
const url = new URL(req.url);
|
|
67
66
|
if (ACCESS === "cloudflare-allowlist") {
|
|
68
67
|
const ip = req.headers.get("cf-connecting-ip") ?? "";
|
|
69
|
-
if (!ALLOW
|
|
68
|
+
if (!allowlistMatches(ALLOW, ip)) {
|
|
70
69
|
const details = requestDetails(req, url);
|
|
71
70
|
// Log denials so operators can whitelist a phone/laptop that just
|
|
72
71
|
// hit 403 without asking the human to dig up their public IP.
|
|
@@ -187,4 +186,12 @@ const server = Bun.serve({
|
|
|
187
186
|
console.log(`harn-tunnel-gate :${server.port} -> ${UPSTREAM_HTTP} (Host: ${VHOST})`); // lint-ok-emission: detached worker, see file note above
|
|
188
187
|
console.log(`access: ${ACCESS}`); // lint-ok-emission: detached worker, see file note above
|
|
189
188
|
console.log(`paths: ${ALLOW_PATHS.join(", ") || "(empty, every path refused)"}`); // lint-ok-emission: detached worker, see file note above
|
|
190
|
-
console.log(
|
|
189
|
+
console.log(
|
|
190
|
+
// lint-ok-emission: detached worker, see file note above
|
|
191
|
+
`allow: ${process.env.HARNERY_TUNNEL_ALLOW?.split(",")
|
|
192
|
+
.filter((s) => s.trim())
|
|
193
|
+
.join(", ") || "(empty, not used outside allowlist mode)"}`);
|
|
194
|
+
if (ALLOW.invalid.length > 0) {
|
|
195
|
+
// lint-ok-emission: detached worker, see file note above
|
|
196
|
+
console.log(`allow: ignoring unreadable entries: ${ALLOW.invalid.join(", ")}`);
|
|
197
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
type Run = (command: string, args: string[]) => {
|
|
2
|
+
status: number | null;
|
|
3
|
+
stdout: string;
|
|
4
|
+
missing: boolean;
|
|
5
|
+
};
|
|
6
|
+
export interface ProcessRow {
|
|
7
|
+
pid: number;
|
|
8
|
+
command: string;
|
|
9
|
+
}
|
|
10
|
+
/** Parse `ps -axo pid=,command=` output (also the shape the PowerShell probe emits). */
|
|
11
|
+
export declare function parseProcessRows(output: string): ProcessRow[];
|
|
12
|
+
/** Every process with a command line, or null when the platform gives no way to list them. */
|
|
13
|
+
export declare function listProcesses(platform?: NodeJS.Platform, run?: Run): ProcessRow[] | null;
|
|
14
|
+
/**
|
|
15
|
+
* PIDs whose command line matches `pattern`, an extended regular expression
|
|
16
|
+
* (the intersection of `pgrep -f` and JavaScript syntax). Returns [] when
|
|
17
|
+
* nothing matches or no listing tool works.
|
|
18
|
+
*/
|
|
19
|
+
export declare function findPidsByCommandLine(pattern: string, platform?: NodeJS.Platform, run?: Run): number[];
|
|
20
|
+
/** Ports from `ss -tlnH`: `LISTEN 0 4096 127.0.0.1:9001 0.0.0.0:*`. */
|
|
21
|
+
export declare function parseSsPorts(output: string): number[];
|
|
22
|
+
/** Ports from `lsof -nP -iTCP -sTCP:LISTEN` rows ending `127.0.0.1:58055 (LISTEN)`. */
|
|
23
|
+
export declare function parseLsofPorts(output: string): number[];
|
|
24
|
+
/** Ports from `netstat -ano -p TCP` rows: `TCP 0.0.0.0:9001 0.0.0.0:0 LISTENING 4`. */
|
|
25
|
+
export declare function parseNetstatPorts(output: string): number[];
|
|
26
|
+
/**
|
|
27
|
+
* Ports with a LISTEN socket, or null when no discovery tool answered.
|
|
28
|
+
*
|
|
29
|
+
* Null is not "no ports": reporting every port as free would let a caller hand
|
|
30
|
+
* out an occupied port, so callers that need a real answer use `portListening`,
|
|
31
|
+
* which falls back to connecting.
|
|
32
|
+
*/
|
|
33
|
+
export declare function listeningPorts(platform?: NodeJS.Platform, run?: Run): Set<number> | null;
|
|
34
|
+
/** True when something accepts a TCP connection on 127.0.0.1:<port>. */
|
|
35
|
+
export declare function connectProbe(port: number, timeoutMs?: number): Promise<boolean>;
|
|
36
|
+
/** Whether `port` has a listener, by the platform tool when there is one, else by connecting. */
|
|
37
|
+
export declare function portListening(port: number): Promise<boolean>;
|
|
38
|
+
export {};
|
|
39
|
+
//# sourceMappingURL=processes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processes.d.ts","sourceRoot":"","sources":["../../../src/lib/tunnel/processes.ts"],"names":[],"mappings":"AAWA,KAAK,GAAG,GAAG,CACT,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EAAE,KACX;IAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC;AAQjE,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wFAAwF;AACxF,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,EAAE,CAO7D;AAMD,8FAA8F;AAC9F,wBAAgB,aAAa,CAC3B,QAAQ,GAAE,MAAM,CAAC,QAA2B,EAC5C,GAAG,GAAE,GAAa,GACjB,UAAU,EAAE,GAAG,IAAI,CAWrB;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,MAAM,EACf,QAAQ,GAAE,MAAM,CAAC,QAA2B,EAC5C,GAAG,GAAE,GAAa,GACjB,MAAM,EAAE,CAiBV;AAED,uEAAuE;AACvE,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAErD;AAED,uFAAuF;AACvF,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAEvD;AAED,uFAAuF;AACvF,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAI1D;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,GAAE,MAAM,CAAC,QAA2B,EAC5C,GAAG,GAAE,GAAa,GACjB,GAAG,CAAC,MAAM,CAAC,GAAG,IAAI,CAepB;AAED,wEAAwE;AACxE,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,SAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAW5E;AAED,iGAAiG;AACjG,wBAAsB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAGlE"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// Process and port discovery for the tunnel commands, per platform.
|
|
2
|
+
//
|
|
3
|
+
// Linux and macOS have `pgrep`/`ps`; Linux has `ss`; both have `lsof`. Windows
|
|
4
|
+
// has none of these, so it uses PowerShell for command lines and `netstat` for
|
|
5
|
+
// listening sockets. Every probe is best effort: a missing tool yields "no
|
|
6
|
+
// answer" (null or an empty list), never a thrown error, and the callers fall
|
|
7
|
+
// back to checks that need no tool (a TCP connect probe, a PID check).
|
|
8
|
+
import { spawnSync } from "node:child_process";
|
|
9
|
+
import { connect } from "node:net";
|
|
10
|
+
const runTool = (command, args) => {
|
|
11
|
+
const r = spawnSync(command, args, { encoding: "utf-8", windowsHide: true, timeout: 15_000 });
|
|
12
|
+
const missing = r.error?.code === "ENOENT";
|
|
13
|
+
return { status: r.status, stdout: typeof r.stdout === "string" ? r.stdout : "", missing };
|
|
14
|
+
};
|
|
15
|
+
/** Parse `ps -axo pid=,command=` output (also the shape the PowerShell probe emits). */
|
|
16
|
+
export function parseProcessRows(output) {
|
|
17
|
+
const rows = [];
|
|
18
|
+
for (const line of output.split(/\r?\n/)) {
|
|
19
|
+
const m = line.match(/^\s*(\d+)\s+(.*\S)\s*$/);
|
|
20
|
+
if (m)
|
|
21
|
+
rows.push({ pid: Number(m[1]), command: m[2] });
|
|
22
|
+
}
|
|
23
|
+
return rows;
|
|
24
|
+
}
|
|
25
|
+
const POWERSHELL_PROCESS_LIST = "Get-CimInstance Win32_Process | Where-Object { $_.CommandLine } | " +
|
|
26
|
+
'ForEach-Object { "$($_.ProcessId) $($_.CommandLine)" }';
|
|
27
|
+
/** Every process with a command line, or null when the platform gives no way to list them. */
|
|
28
|
+
export function listProcesses(platform = process.platform, run = runTool) {
|
|
29
|
+
if (platform === "win32") {
|
|
30
|
+
for (const shell of ["powershell.exe", "pwsh.exe", "pwsh"]) {
|
|
31
|
+
const r = run(shell, ["-NoProfile", "-NonInteractive", "-Command", POWERSHELL_PROCESS_LIST]);
|
|
32
|
+
if (r.missing)
|
|
33
|
+
continue;
|
|
34
|
+
if (r.status === 0)
|
|
35
|
+
return parseProcessRows(r.stdout);
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
const ps = run("ps", ["-axo", "pid=,command="]);
|
|
40
|
+
return ps.status === 0 ? parseProcessRows(ps.stdout) : null;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* PIDs whose command line matches `pattern`, an extended regular expression
|
|
44
|
+
* (the intersection of `pgrep -f` and JavaScript syntax). Returns [] when
|
|
45
|
+
* nothing matches or no listing tool works.
|
|
46
|
+
*/
|
|
47
|
+
export function findPidsByCommandLine(pattern, platform = process.platform, run = runTool) {
|
|
48
|
+
if (platform !== "win32") {
|
|
49
|
+
// `--` ends options: the provider pattern starts with `--url`, which pgrep
|
|
50
|
+
// would otherwise reject as an unknown flag and report as "no match".
|
|
51
|
+
const r = run("pgrep", ["-f", "--", pattern]);
|
|
52
|
+
if (!r.missing) {
|
|
53
|
+
if (r.status !== 0)
|
|
54
|
+
return [];
|
|
55
|
+
return r.stdout
|
|
56
|
+
.split("\n")
|
|
57
|
+
.map((line) => Number(line.trim()))
|
|
58
|
+
.filter((pid) => Number.isInteger(pid) && pid > 0);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const rows = listProcesses(platform, run);
|
|
62
|
+
if (!rows)
|
|
63
|
+
return [];
|
|
64
|
+
const re = new RegExp(pattern);
|
|
65
|
+
return rows.filter((row) => re.test(row.command)).map((row) => row.pid);
|
|
66
|
+
}
|
|
67
|
+
/** Ports from `ss -tlnH`: `LISTEN 0 4096 127.0.0.1:9001 0.0.0.0:*`. */
|
|
68
|
+
export function parseSsPorts(output) {
|
|
69
|
+
return [...output.matchAll(/:(\d+)\s/g)].map((m) => Number(m[1]));
|
|
70
|
+
}
|
|
71
|
+
/** Ports from `lsof -nP -iTCP -sTCP:LISTEN` rows ending `127.0.0.1:58055 (LISTEN)`. */
|
|
72
|
+
export function parseLsofPorts(output) {
|
|
73
|
+
return [...output.matchAll(/:(\d+) \(LISTEN\)\s*$/gm)].map((m) => Number(m[1]));
|
|
74
|
+
}
|
|
75
|
+
/** Ports from `netstat -ano -p TCP` rows: `TCP 0.0.0.0:9001 0.0.0.0:0 LISTENING 4`. */
|
|
76
|
+
export function parseNetstatPorts(output) {
|
|
77
|
+
return [...output.matchAll(/^\s*TCP\s+\S*:(\d+)\s+\S+\s+LISTENING\b/gim)].map((m) => Number(m[1]));
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Ports with a LISTEN socket, or null when no discovery tool answered.
|
|
81
|
+
*
|
|
82
|
+
* Null is not "no ports": reporting every port as free would let a caller hand
|
|
83
|
+
* out an occupied port, so callers that need a real answer use `portListening`,
|
|
84
|
+
* which falls back to connecting.
|
|
85
|
+
*/
|
|
86
|
+
export function listeningPorts(platform = process.platform, run = runTool) {
|
|
87
|
+
if (platform === "win32") {
|
|
88
|
+
const r = run("netstat", ["-ano", "-p", "TCP"]);
|
|
89
|
+
return !r.missing && r.status === 0 ? new Set(parseNetstatPorts(r.stdout)) : null;
|
|
90
|
+
}
|
|
91
|
+
if (platform === "linux") {
|
|
92
|
+
const ss = run("ss", ["-tlnH"]);
|
|
93
|
+
if (!ss.missing && ss.status === 0)
|
|
94
|
+
return new Set(parseSsPorts(ss.stdout));
|
|
95
|
+
}
|
|
96
|
+
// macOS and BSD, or Linux without iproute2. lsof reports a failure when any
|
|
97
|
+
// single process is unreadable while stdout still holds usable rows, so
|
|
98
|
+
// judge it on the output.
|
|
99
|
+
const lsof = run("lsof", ["-nP", "-iTCP", "-sTCP:LISTEN"]);
|
|
100
|
+
if (!lsof.missing && lsof.stdout.trim())
|
|
101
|
+
return new Set(parseLsofPorts(lsof.stdout));
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
/** True when something accepts a TCP connection on 127.0.0.1:<port>. */
|
|
105
|
+
export function connectProbe(port, timeoutMs = 400) {
|
|
106
|
+
return new Promise((resolve) => {
|
|
107
|
+
const socket = connect({ port, host: "127.0.0.1" });
|
|
108
|
+
const done = (result) => {
|
|
109
|
+
socket.destroy();
|
|
110
|
+
resolve(result);
|
|
111
|
+
};
|
|
112
|
+
socket.setTimeout(timeoutMs, () => done(false));
|
|
113
|
+
socket.once("connect", () => done(true));
|
|
114
|
+
socket.once("error", () => done(false));
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
/** Whether `port` has a listener, by the platform tool when there is one, else by connecting. */
|
|
118
|
+
export async function portListening(port) {
|
|
119
|
+
const ports = listeningPorts();
|
|
120
|
+
return ports ? ports.has(port) : connectProbe(port);
|
|
121
|
+
}
|
|
@@ -1,10 +1,29 @@
|
|
|
1
|
+
/** Overrides the directory that holds tunnel state and config (a host keeps it out of `.cache/`). */
|
|
2
|
+
export declare const TUNNEL_DIR_ENV = "HARNERY_TUNNEL_DIR";
|
|
3
|
+
/** Explicit cloudflared binary, for a host that ships a managed copy. */
|
|
4
|
+
export declare const CLOUDFLARED_ENV = "HARNERY_CLOUDFLARED";
|
|
5
|
+
/**
|
|
6
|
+
* Where tunnel state lives: `$HARNERY_TUNNEL_DIR` when set, else
|
|
7
|
+
* `<root>/.cache/tunnel/`. Root defaults to cwd for the command surface and can
|
|
8
|
+
* be supplied by callers that already resolved a repo.
|
|
9
|
+
*/
|
|
10
|
+
export declare function tunnelDir(root?: string, env?: NodeJS.ProcessEnv): string;
|
|
1
11
|
/** The default instance name when `--name` is omitted. */
|
|
2
12
|
export declare const DEFAULT_INSTANCE = "default";
|
|
3
13
|
export declare function gateLogFile(name: string): string;
|
|
4
14
|
export declare function cfdLogFile(name: string): string;
|
|
5
15
|
export declare function providerLogFile(name: string, provider: TunnelProvider): string;
|
|
6
16
|
export interface TunnelConfig {
|
|
17
|
+
/** Exact addresses and CIDR ranges the gate admits (Cloudflare provider). */
|
|
7
18
|
allowed_ips: string[];
|
|
19
|
+
/**
|
|
20
|
+
* Entries `allow add --current` added for this machine's own public
|
|
21
|
+
* addresses. They are a subset of `allowed_ips`; the next refresh replaces
|
|
22
|
+
* exactly these and never touches an entry added by hand.
|
|
23
|
+
*/
|
|
24
|
+
auto_allowed?: string[];
|
|
25
|
+
/** Explicit cloudflared binary; `$HARNERY_CLOUDFLARED` wins over this. */
|
|
26
|
+
cloudflared_path?: string;
|
|
8
27
|
}
|
|
9
28
|
export type TunnelProvider = "cloudflare" | "tailscale";
|
|
10
29
|
export type TailscaleMode = "serve" | "funnel";
|
|
@@ -57,8 +76,14 @@ export declare function findLiveTunnelForOrigin(port: number, vhost: string, roo
|
|
|
57
76
|
/** True when the tunnel's path scope forwards every one of `paths`. */
|
|
58
77
|
export declare function tunnelServesPaths(state: TunnelState, paths: readonly string[]): boolean;
|
|
59
78
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
79
|
+
* Resolve the cloudflared binary:
|
|
80
|
+
* 1. `$HARNERY_CLOUDFLARED`, then `cloudflared_path` in the tunnel config: an
|
|
81
|
+
* explicit choice, so a missing or non-runnable file is an error, never a
|
|
82
|
+
* silent fall-through to some other copy.
|
|
83
|
+
* 2. `cloudflared` on PATH.
|
|
84
|
+
* 3. `~/.local/bin/cloudflared`.
|
|
85
|
+
* 4. Linux x86-64 and arm64: download the latest release to (3).
|
|
86
|
+
* Elsewhere it throws with install guidance.
|
|
62
87
|
*/
|
|
63
|
-
export declare function ensureCloudflared(): string;
|
|
88
|
+
export declare function ensureCloudflared(env?: NodeJS.ProcessEnv, configuredPath?: string | undefined): string;
|
|
64
89
|
//# sourceMappingURL=state.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/lib/tunnel/state.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/lib/tunnel/state.ts"],"names":[],"mappings":"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"}
|
package/dist/lib/tunnel/state.js
CHANGED
|
@@ -1,13 +1,25 @@
|
|
|
1
1
|
// Tunnel config + state persistence + provider helpers. Commands default to
|
|
2
2
|
// <cwd>/.cache/tunnel/; gitignored, so the allowlist is per-machine.
|
|
3
|
-
import {
|
|
4
|
-
import { existsSync, mkdirSync, readdirSync, readFileSync, unlinkSync, writeFileSync, } from "node:fs";
|
|
5
|
-
import {
|
|
3
|
+
import { spawnSync } from "node:child_process";
|
|
4
|
+
import { accessSync, chmodSync, constants, existsSync, mkdirSync, readdirSync, readFileSync, statSync, unlinkSync, writeFileSync, } from "node:fs";
|
|
5
|
+
import { homedir } from "node:os";
|
|
6
|
+
import { delimiter, join, resolve } from "node:path";
|
|
6
7
|
import { isPathAllowed } from "./path-scope.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
/** Overrides the directory that holds tunnel state and config (a host keeps it out of `.cache/`). */
|
|
9
|
+
export const TUNNEL_DIR_ENV = "HARNERY_TUNNEL_DIR";
|
|
10
|
+
/** Explicit cloudflared binary, for a host that ships a managed copy. */
|
|
11
|
+
export const CLOUDFLARED_ENV = "HARNERY_CLOUDFLARED";
|
|
12
|
+
/**
|
|
13
|
+
* Where tunnel state lives: `$HARNERY_TUNNEL_DIR` when set, else
|
|
14
|
+
* `<root>/.cache/tunnel/`. Root defaults to cwd for the command surface and can
|
|
15
|
+
* be supplied by callers that already resolved a repo.
|
|
16
|
+
*/
|
|
17
|
+
export function tunnelDir(root = process.cwd(), env = process.env) {
|
|
18
|
+
const override = env[TUNNEL_DIR_ENV]?.trim();
|
|
19
|
+
return override ? resolve(override) : resolve(root, ".cache", "tunnel");
|
|
20
|
+
}
|
|
21
|
+
function cachePath(filename, root = process.cwd()) {
|
|
22
|
+
const dir = tunnelDir(root);
|
|
11
23
|
if (!existsSync(dir))
|
|
12
24
|
mkdirSync(dir, { recursive: true });
|
|
13
25
|
return resolve(dir, filename);
|
|
@@ -61,23 +73,27 @@ function normalizeState(raw, fallbackName) {
|
|
|
61
73
|
};
|
|
62
74
|
}
|
|
63
75
|
export function readConfig() {
|
|
64
|
-
const p = cachePath(
|
|
76
|
+
const p = cachePath(CONFIG_FILE);
|
|
65
77
|
if (!existsSync(p)) {
|
|
66
78
|
writeConfig(DEFAULT_CONFIG);
|
|
67
79
|
return { ...DEFAULT_CONFIG, allowed_ips: [...DEFAULT_CONFIG.allowed_ips] };
|
|
68
80
|
}
|
|
69
81
|
try {
|
|
70
|
-
|
|
82
|
+
const parsed = JSON.parse(readFileSync(p, "utf-8"));
|
|
83
|
+
return {
|
|
84
|
+
...parsed,
|
|
85
|
+
allowed_ips: Array.isArray(parsed.allowed_ips) ? parsed.allowed_ips : [],
|
|
86
|
+
};
|
|
71
87
|
}
|
|
72
88
|
catch {
|
|
73
89
|
return { ...DEFAULT_CONFIG, allowed_ips: [...DEFAULT_CONFIG.allowed_ips] };
|
|
74
90
|
}
|
|
75
91
|
}
|
|
76
92
|
export function writeConfig(cfg) {
|
|
77
|
-
writeFileSync(cachePath(
|
|
93
|
+
writeFileSync(cachePath(CONFIG_FILE), JSON.stringify(cfg, null, 2));
|
|
78
94
|
}
|
|
79
95
|
export function readState(name = DEFAULT_INSTANCE, root = process.cwd()) {
|
|
80
|
-
const p = cachePath(
|
|
96
|
+
const p = cachePath(stateFile(name), root);
|
|
81
97
|
if (!existsSync(p))
|
|
82
98
|
return null;
|
|
83
99
|
try {
|
|
@@ -88,10 +104,10 @@ export function readState(name = DEFAULT_INSTANCE, root = process.cwd()) {
|
|
|
88
104
|
}
|
|
89
105
|
}
|
|
90
106
|
export function writeState(state, root = process.cwd()) {
|
|
91
|
-
writeFileSync(cachePath(
|
|
107
|
+
writeFileSync(cachePath(stateFile(state.name), root), JSON.stringify(state, null, 2));
|
|
92
108
|
}
|
|
93
109
|
export function clearState(name = DEFAULT_INSTANCE, root = process.cwd()) {
|
|
94
|
-
const p = cachePath(
|
|
110
|
+
const p = cachePath(stateFile(name), root);
|
|
95
111
|
if (existsSync(p))
|
|
96
112
|
unlinkSync(p);
|
|
97
113
|
}
|
|
@@ -100,7 +116,7 @@ export function clearState(name = DEFAULT_INSTANCE, root = process.cwd()) {
|
|
|
100
116
|
* `state*.json` under `.cache/tunnel/`; tolerates missing/corrupt files.
|
|
101
117
|
*/
|
|
102
118
|
export function listStates(root = process.cwd()) {
|
|
103
|
-
const dir =
|
|
119
|
+
const dir = tunnelDir(root);
|
|
104
120
|
if (!existsSync(dir))
|
|
105
121
|
return [];
|
|
106
122
|
const out = [];
|
|
@@ -166,26 +182,81 @@ export function findLiveTunnelForOrigin(port, vhost, root = process.cwd(), proce
|
|
|
166
182
|
export function tunnelServesPaths(state, paths) {
|
|
167
183
|
return paths.every((path) => isPathAllowed(path, state.allow_paths));
|
|
168
184
|
}
|
|
169
|
-
|
|
170
|
-
* Ensure cloudflared is on PATH or installed at ~/.local/bin/cloudflared.
|
|
171
|
-
* Auto-downloads on Linux; throws on other platforms with brew hint.
|
|
172
|
-
*/
|
|
173
|
-
export function ensureCloudflared() {
|
|
185
|
+
function isRunnableFile(path) {
|
|
174
186
|
try {
|
|
175
|
-
|
|
176
|
-
|
|
187
|
+
if (!statSync(path).isFile())
|
|
188
|
+
return false;
|
|
189
|
+
if (process.platform === "win32")
|
|
190
|
+
return true;
|
|
191
|
+
accessSync(path, constants.X_OK);
|
|
192
|
+
return true;
|
|
177
193
|
}
|
|
178
194
|
catch {
|
|
179
|
-
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/** First `name` on PATH (honoring `.exe` on Windows), or null. Needs no shell. */
|
|
199
|
+
function findOnPath(name, env = process.env) {
|
|
200
|
+
const names = process.platform === "win32" ? [`${name}.exe`, name] : [name];
|
|
201
|
+
for (const dir of (env.PATH ?? env.Path ?? "").split(delimiter)) {
|
|
202
|
+
if (!dir)
|
|
203
|
+
continue;
|
|
204
|
+
for (const candidate of names) {
|
|
205
|
+
const full = join(dir, candidate);
|
|
206
|
+
if (isRunnableFile(full))
|
|
207
|
+
return full;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Resolve the cloudflared binary:
|
|
214
|
+
* 1. `$HARNERY_CLOUDFLARED`, then `cloudflared_path` in the tunnel config: an
|
|
215
|
+
* explicit choice, so a missing or non-runnable file is an error, never a
|
|
216
|
+
* silent fall-through to some other copy.
|
|
217
|
+
* 2. `cloudflared` on PATH.
|
|
218
|
+
* 3. `~/.local/bin/cloudflared`.
|
|
219
|
+
* 4. Linux x86-64 and arm64: download the latest release to (3).
|
|
220
|
+
* Elsewhere it throws with install guidance.
|
|
221
|
+
*/
|
|
222
|
+
export function ensureCloudflared(env = process.env, configuredPath = readConfig().cloudflared_path) {
|
|
223
|
+
const explicit = env[CLOUDFLARED_ENV]?.trim();
|
|
224
|
+
const fromConfig = configuredPath?.trim();
|
|
225
|
+
for (const [source, path] of [
|
|
226
|
+
[CLOUDFLARED_ENV, explicit],
|
|
227
|
+
["cloudflared_path in the tunnel config", fromConfig],
|
|
228
|
+
]) {
|
|
229
|
+
if (!path)
|
|
230
|
+
continue;
|
|
231
|
+
if (isRunnableFile(path))
|
|
232
|
+
return path;
|
|
233
|
+
throw new Error(`cloudflared is set by ${source} to ${path}, but that file is missing or not runnable.`);
|
|
180
234
|
}
|
|
181
|
-
const
|
|
182
|
-
if (
|
|
235
|
+
const onPath = findOnPath("cloudflared", env);
|
|
236
|
+
if (onPath)
|
|
237
|
+
return onPath;
|
|
238
|
+
const exe = process.platform === "win32" ? "cloudflared.exe" : "cloudflared";
|
|
239
|
+
const local = join(homedir(), ".local", "bin", exe);
|
|
240
|
+
if (isRunnableFile(local))
|
|
183
241
|
return local;
|
|
184
|
-
|
|
185
|
-
|
|
242
|
+
const asset = process.platform === "linux"
|
|
243
|
+
? { x64: "cloudflared-linux-amd64", arm64: "cloudflared-linux-arm64" }[process.arch]
|
|
244
|
+
: undefined;
|
|
245
|
+
if (!asset) {
|
|
246
|
+
throw new Error("cloudflared not installed. Install it (macOS: `brew install cloudflared`; Windows: " +
|
|
247
|
+
"`winget install Cloudflare.cloudflared`), or point `$HARNERY_CLOUDFLARED` at a binary. " +
|
|
186
248
|
"On Linux it auto-installs to ~/.local/bin/cloudflared.");
|
|
187
249
|
}
|
|
188
250
|
process.stderr.write("Installing cloudflared to ~/.local/bin/...\n"); // lint-ok-emission: sync setup phase before structured output; pairs with the inherited stdio of the curl below
|
|
189
|
-
|
|
251
|
+
mkdirSync(join(homedir(), ".local", "bin"), { recursive: true });
|
|
252
|
+
const download = spawnSync("curl", [
|
|
253
|
+
"-fsSL",
|
|
254
|
+
`https://github.com/cloudflare/cloudflared/releases/latest/download/${asset}`,
|
|
255
|
+
"-o",
|
|
256
|
+
local,
|
|
257
|
+
], { stdio: "inherit" });
|
|
258
|
+
if (download.status !== 0)
|
|
259
|
+
throw new Error("Downloading cloudflared failed; install it by hand.");
|
|
260
|
+
chmodSync(local, 0o755);
|
|
190
261
|
return local;
|
|
191
262
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "harnery",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.43.0",
|
|
4
4
|
"description": "Multi-agent coordination for AI coding agents - Claude Code, Cursor, and Codex.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Ryan Kelly",
|
|
@@ -266,6 +266,7 @@
|
|
|
266
266
|
"test:web": "cd web && bun install && bun test",
|
|
267
267
|
"test:integration": "bash tests/integration/run.sh",
|
|
268
268
|
"smoke": "node scripts/smoke-test.mjs",
|
|
269
|
+
"check:local": "node scripts/check-local.mjs",
|
|
269
270
|
"docs:dev": "bun run --cwd docs dev",
|
|
270
271
|
"docs:build": "bun run --cwd docs build",
|
|
271
272
|
"brand:showcase": "node scripts/build-brand-showcase.mjs",
|
package/src/commander.ts
CHANGED
|
@@ -280,6 +280,38 @@ export async function registerHarneryLogStorageCommands(
|
|
|
280
280
|
return parent;
|
|
281
281
|
}
|
|
282
282
|
|
|
283
|
+
export interface HarneryTunnelCommandOptions {
|
|
284
|
+
emit?: EmitContext;
|
|
285
|
+
context?: HarneryProgramContext;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Mount `tunnel` under `parent`, for a host whose own program does not come
|
|
290
|
+
* from `createHarneryProgram` (a host CLI that exposes the tunnel as one of its
|
|
291
|
+
* command families).
|
|
292
|
+
*/
|
|
293
|
+
export async function registerHarneryTunnelCommand(
|
|
294
|
+
parent: Command,
|
|
295
|
+
options: HarneryTunnelCommandOptions = {},
|
|
296
|
+
): Promise<Command> {
|
|
297
|
+
const { registerTunnelCommand } = await import("./commands/tunnel.ts");
|
|
298
|
+
registerTunnelCommand(parent, options.emit ?? defaultEmit, options.context);
|
|
299
|
+
return parent;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
export type { RefreshCurrentOptions, RefreshCurrentResult } from "./commands/tunnel.ts";
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* `tunnel allow add --current` as a function: allow this machine's public
|
|
306
|
+
* addresses and optionally reload running gates, keeping their URLs.
|
|
307
|
+
*/
|
|
308
|
+
export async function refreshTunnelCurrentAddress(
|
|
309
|
+
options: import("./commands/tunnel.ts").RefreshCurrentOptions,
|
|
310
|
+
): Promise<import("./commands/tunnel.ts").RefreshCurrentResult> {
|
|
311
|
+
const { refreshCurrentAddress } = await import("./commands/tunnel.ts");
|
|
312
|
+
return refreshCurrentAddress(options);
|
|
313
|
+
}
|
|
314
|
+
|
|
283
315
|
export function createHarneryProgram(opts: HarneryContextOpts = {}): Command {
|
|
284
316
|
const program = new Command();
|
|
285
317
|
const emit = opts.emit ?? defaultEmit;
|