@tafrahq/wt-tunnel-client 0.0.0-stage → 0.7.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/LICENSE +21 -0
- package/README.md +166 -2
- package/dist/bin.js +15 -0
- package/dist/bin.js.map +1 -0
- package/dist/cli-commands.js +27 -0
- package/dist/cli-commands.js.map +1 -0
- package/dist/cli-provision.js +25 -0
- package/dist/cli-provision.js.map +1 -0
- package/dist/cli-status.js +19 -0
- package/dist/cli-status.js.map +1 -0
- package/dist/cli-workspace.js +38 -0
- package/dist/cli-workspace.js.map +1 -0
- package/dist/cli-worktree.js +40 -0
- package/dist/cli-worktree.js.map +1 -0
- package/dist/cli.js +9 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.js +70 -0
- package/dist/config.js.map +1 -0
- package/dist/domain.js +26 -0
- package/dist/domain.js.map +1 -0
- package/dist/errno.js +6 -0
- package/dist/errno.js.map +1 -0
- package/dist/errors.js +7 -0
- package/dist/errors.js.map +1 -0
- package/dist/exec.js +18 -0
- package/dist/exec.js.map +1 -0
- package/dist/files.js +18 -0
- package/dist/files.js.map +1 -0
- package/dist/frpc-binary.js +16 -0
- package/dist/frpc-binary.js.map +1 -0
- package/dist/frpc-config.js +47 -0
- package/dist/frpc-config.js.map +1 -0
- package/dist/packages/binaries/src/frp.js +45 -0
- package/dist/packages/binaries/src/frp.js.map +1 -0
- package/dist/packages/binaries/src/install.js +110 -0
- package/dist/packages/binaries/src/install.js.map +1 -0
- package/dist/packages/contract/src/index.js +12 -0
- package/dist/packages/contract/src/index.js.map +1 -0
- package/dist/ports.js +121 -0
- package/dist/ports.js.map +1 -0
- package/dist/processes.js +118 -0
- package/dist/processes.js.map +1 -0
- package/dist/provision-frpc.js +100 -0
- package/dist/provision-frpc.js.map +1 -0
- package/dist/provision-ports.js +75 -0
- package/dist/provision-ports.js.map +1 -0
- package/dist/provision.js +28 -0
- package/dist/provision.js.map +1 -0
- package/dist/state.js +53 -0
- package/dist/state.js.map +1 -0
- package/dist/worktree.js +25 -0
- package/dist/worktree.js.map +1 -0
- package/llms.txt +33 -0
- package/package.json +63 -3
- package/src/bin.ts +28 -0
- package/src/cli-commands.ts +40 -0
- package/src/cli-provision.ts +34 -0
- package/src/cli-status.ts +29 -0
- package/src/cli-workspace.ts +78 -0
- package/src/cli-worktree.ts +62 -0
- package/src/cli.ts +15 -0
- package/src/config.ts +101 -0
- package/src/domain.ts +51 -0
- package/src/errno.ts +5 -0
- package/src/errors.ts +13 -0
- package/src/exec.ts +18 -0
- package/src/files.ts +20 -0
- package/src/frpc-binary.ts +27 -0
- package/src/frpc-config.ts +69 -0
- package/src/ports.ts +177 -0
- package/src/processes.ts +163 -0
- package/src/provision-frpc.ts +152 -0
- package/src/provision-ports.ts +116 -0
- package/src/provision.ts +41 -0
- package/src/resource.ts +28 -0
- package/src/state.ts +87 -0
- package/src/worktree.ts +52 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { WtTunnelError } from "./errors.js";
|
|
2
|
+
import { readTextIfExists } from "./files.js";
|
|
3
|
+
import { routedApps } from "./provision-ports.js";
|
|
4
|
+
import { renderFrpcConfig, serverToken, tokenEnvironment } from "./frpc-config.js";
|
|
5
|
+
import { frpcBinary } from "./frpc-binary.js";
|
|
6
|
+
import { processLogFile, processStatus, startProcess, stopProcess } from "./processes.js";
|
|
7
|
+
import { Effect } from "effect";
|
|
8
|
+
import { rm, stat, writeFile } from "node:fs/promises";
|
|
9
|
+
// src/provision-frpc.ts
|
|
10
|
+
/**
|
|
11
|
+
* The token first, so a missing one fails before the download. `up` runs this before it creates
|
|
12
|
+
* anything, so a missing prerequisite changes nothing.
|
|
13
|
+
*/
|
|
14
|
+
const frpcLaunch = Effect.gen(function* tokenThenBinary() {
|
|
15
|
+
const token = yield* serverToken;
|
|
16
|
+
return {
|
|
17
|
+
binary: yield* frpcBinary,
|
|
18
|
+
token
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
const confirmPolls = 75;
|
|
22
|
+
const confirmPollInterval = "200 millis";
|
|
23
|
+
/** Frpc logs one line per proxy once the server has answered its registration. */
|
|
24
|
+
const proxyOutcome = (lines, app) => {
|
|
25
|
+
if (lines.some((line) => line.includes(`[${app}] start proxy success`))) return { _tag: "started" };
|
|
26
|
+
const marker = `[${app}] start error: `;
|
|
27
|
+
const line = lines.find((candidate) => candidate.includes(marker));
|
|
28
|
+
return line === void 0 ? { _tag: "pending" } : {
|
|
29
|
+
_tag: "rejected",
|
|
30
|
+
reason: line.slice(line.indexOf(marker) + marker.length)
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
const logSize = (file) => Effect.promise(async () => {
|
|
34
|
+
try {
|
|
35
|
+
return (await stat(file)).size;
|
|
36
|
+
} catch {
|
|
37
|
+
return 0;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
/** The log lines written since `offset`: what this frpc instance has said so far. */
|
|
41
|
+
const linesSince = (file, offset) => Effect.promise(() => readTextIfExists(file)).pipe(Effect.map((text) => Buffer.from(text ?? "").subarray(offset).toString("utf8").split("\n")));
|
|
42
|
+
/** Frps's reason when another frpc already serves the host. */
|
|
43
|
+
const hostTaken = "router config conflict";
|
|
44
|
+
const rejectedMessage = (rejected) => ["The tunnel server refused these hosts:", ...rejected.map(([{ hostname }, reason]) => ` ${hostname}: ${reason === hostTaken ? "another worktree already serves it" : reason}`)].join("\n");
|
|
45
|
+
/** One look at the log: true once every proxy started, a failure once any was refused. */
|
|
46
|
+
const proxiesStarted = (stateDir, apps, offset) => Effect.gen(function* readOutcomes() {
|
|
47
|
+
const lines = yield* linesSince(processLogFile(stateDir, "frpc"), offset);
|
|
48
|
+
const outcomes = apps.map((app) => [app, proxyOutcome(lines, app.app)]);
|
|
49
|
+
const rejected = outcomes.flatMap(([app, outcome]) => outcome._tag === "rejected" ? [[app, outcome.reason]] : []);
|
|
50
|
+
if (rejected.length > 0) {
|
|
51
|
+
yield* stopProcess(stateDir, "frpc");
|
|
52
|
+
return yield* new WtTunnelError({ message: rejectedMessage(rejected) });
|
|
53
|
+
}
|
|
54
|
+
return outcomes.every(([, outcome]) => outcome._tag === "started");
|
|
55
|
+
});
|
|
56
|
+
/**
|
|
57
|
+
* Starting frpc only proves it logged in; the server can still refuse a proxy, for example when
|
|
58
|
+
* another worktree already serves that host. Waits until every proxy has an answer.
|
|
59
|
+
*/
|
|
60
|
+
const confirmProxies = (stateDir, apps, offset) => Effect.gen(function* pollLog() {
|
|
61
|
+
const log = processLogFile(stateDir, "frpc");
|
|
62
|
+
for (let poll = 0; poll < confirmPolls; poll++) {
|
|
63
|
+
if (yield* proxiesStarted(stateDir, apps, offset)) return yield* Effect.void;
|
|
64
|
+
if ((yield* processStatus(stateDir, "frpc"))._tag !== "running") return yield* new WtTunnelError({ message: `frpc stopped before the server accepted its hosts. See ${log}` });
|
|
65
|
+
yield* Effect.sleep(confirmPollInterval);
|
|
66
|
+
}
|
|
67
|
+
return yield* new WtTunnelError({ message: `The tunnel server did not confirm every host in time. See ${log}` });
|
|
68
|
+
});
|
|
69
|
+
/** A running frpc read its config at start, so a changed config means a restart. */
|
|
70
|
+
const writeConfig = (stateDir, file, wanted) => Effect.gen(function* replaceIfChanged() {
|
|
71
|
+
if ((yield* Effect.promise(() => readTextIfExists(file))) !== wanted) {
|
|
72
|
+
yield* stopProcess(stateDir, "frpc");
|
|
73
|
+
yield* Effect.promise(() => writeFile(file, wanted));
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
/** One frpc per worktree, with one HTTP proxy per routed app. */
|
|
77
|
+
const frpc = {
|
|
78
|
+
ensure: (context, state) => Effect.gen(function* writeConfigThenStart() {
|
|
79
|
+
const { binary, token } = yield* frpcLaunch;
|
|
80
|
+
const { stateDir, frpcConfigFile } = context.worktree;
|
|
81
|
+
const apps = routedApps(context, state.ports);
|
|
82
|
+
yield* writeConfig(stateDir, frpcConfigFile, renderFrpcConfig(context.config.server, context.worktree, apps));
|
|
83
|
+
if ((yield* processStatus(stateDir, "frpc"))._tag !== "running") {
|
|
84
|
+
const offset = yield* logSize(processLogFile(stateDir, "frpc"));
|
|
85
|
+
yield* startProcess(stateDir, {
|
|
86
|
+
args: ["-c", frpcConfigFile],
|
|
87
|
+
command: binary,
|
|
88
|
+
name: "frpc",
|
|
89
|
+
env: tokenEnvironment(token)
|
|
90
|
+
});
|
|
91
|
+
yield* confirmProxies(stateDir, apps, offset);
|
|
92
|
+
}
|
|
93
|
+
return state;
|
|
94
|
+
}),
|
|
95
|
+
name: "frpc",
|
|
96
|
+
remove: ({ worktree }, state) => stopProcess(worktree.stateDir, "frpc").pipe(Effect.andThen(Effect.promise(() => rm(worktree.frpcConfigFile, { force: true }))), Effect.as(state))
|
|
97
|
+
};
|
|
98
|
+
export { frpc, frpcLaunch };
|
|
99
|
+
|
|
100
|
+
//# sourceMappingURL=provision-frpc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provision-frpc.js","names":[],"sources":["../src/provision-frpc.ts"],"sourcesContent":["import { rm, stat, writeFile } from 'node:fs/promises';\n\nimport { Effect } from 'effect';\n\nimport { WtTunnelError } from './errors.ts';\nimport { readTextIfExists } from './files.ts';\nimport { frpcBinary } from './frpc-binary.ts';\nimport { renderFrpcConfig, serverToken, tokenEnvironment } from './frpc-config.ts';\nimport { processLogFile, processStatus, startProcess, stopProcess } from './processes.ts';\nimport { routedApps } from './provision-ports.ts';\nimport type { RoutedApp } from './provision-ports.ts';\nimport type { Resource } from './resource.ts';\n\n/**\n * The token first, so a missing one fails before the download. `up` runs this before it creates\n * anything, so a missing prerequisite changes nothing.\n */\nconst frpcLaunch = Effect.gen(function* tokenThenBinary() {\n const token = yield* serverToken;\n const binary = yield* frpcBinary;\n return { binary, token };\n});\n\nconst confirmPolls = 75;\nconst confirmPollInterval = '200 millis';\n\ntype ProxyOutcome =\n | { readonly _tag: 'pending' }\n | { readonly _tag: 'rejected'; readonly reason: string }\n | { readonly _tag: 'started' };\n\n/** Frpc logs one line per proxy once the server has answered its registration. */\nconst proxyOutcome = (lines: readonly string[], app: string): ProxyOutcome => {\n if (lines.some((line) => line.includes(`[${app}] start proxy success`))) {\n return { _tag: 'started' };\n }\n const marker = `[${app}] start error: `;\n const line = lines.find((candidate) => candidate.includes(marker));\n return line === undefined\n ? { _tag: 'pending' }\n : { _tag: 'rejected', reason: line.slice(line.indexOf(marker) + marker.length) };\n};\n\nconst logSize = (file: string) =>\n Effect.promise(async () => {\n try {\n const info = await stat(file);\n return info.size;\n } catch {\n return 0;\n }\n });\n\n/** The log lines written since `offset`: what this frpc instance has said so far. */\nconst linesSince = (file: string, offset: number) =>\n Effect.promise(() => readTextIfExists(file)).pipe(\n Effect.map((text) =>\n Buffer.from(text ?? '')\n .subarray(offset)\n .toString('utf8')\n .split('\\n'),\n ),\n );\n\n/** Frps's reason when another frpc already serves the host. */\nconst hostTaken = 'router config conflict';\n\nconst rejectedMessage = (rejected: readonly (readonly [RoutedApp, string])[]) =>\n [\n 'The tunnel server refused these hosts:',\n ...rejected.map(\n ([{ hostname }, reason]) =>\n ` ${hostname}: ${reason === hostTaken ? 'another worktree already serves it' : reason}`,\n ),\n ].join('\\n');\n\n/** One look at the log: true once every proxy started, a failure once any was refused. */\nconst proxiesStarted = (stateDir: string, apps: readonly RoutedApp[], offset: number) =>\n Effect.gen(function* readOutcomes() {\n const lines = yield* linesSince(processLogFile(stateDir, 'frpc'), offset);\n const outcomes = apps.map((app) => [app, proxyOutcome(lines, app.app)] as const);\n const rejected = outcomes.flatMap(([app, outcome]) =>\n outcome._tag === 'rejected' ? [[app, outcome.reason] as const] : [],\n );\n if (rejected.length > 0) {\n yield* stopProcess(stateDir, 'frpc');\n return yield* new WtTunnelError({ message: rejectedMessage(rejected) });\n }\n return outcomes.every(([, outcome]) => outcome._tag === 'started');\n });\n\n/**\n * Starting frpc only proves it logged in; the server can still refuse a proxy, for example when\n * another worktree already serves that host. Waits until every proxy has an answer.\n */\nconst confirmProxies = (stateDir: string, apps: readonly RoutedApp[], offset: number) =>\n Effect.gen(function* pollLog() {\n const log = processLogFile(stateDir, 'frpc');\n for (let poll = 0; poll < confirmPolls; poll++) {\n if (yield* proxiesStarted(stateDir, apps, offset)) {\n return yield* Effect.void;\n }\n if ((yield* processStatus(stateDir, 'frpc'))._tag !== 'running') {\n return yield* new WtTunnelError({\n message: `frpc stopped before the server accepted its hosts. See ${log}`,\n });\n }\n yield* Effect.sleep(confirmPollInterval);\n }\n return yield* new WtTunnelError({\n message: `The tunnel server did not confirm every host in time. See ${log}`,\n });\n });\n\n/** A running frpc read its config at start, so a changed config means a restart. */\nconst writeConfig = (stateDir: string, file: string, wanted: string) =>\n Effect.gen(function* replaceIfChanged() {\n if ((yield* Effect.promise(() => readTextIfExists(file))) !== wanted) {\n yield* stopProcess(stateDir, 'frpc');\n yield* Effect.promise(() => writeFile(file, wanted));\n }\n });\n\n/** One frpc per worktree, with one HTTP proxy per routed app. */\nconst frpc: Resource = {\n ensure: (context, state) =>\n Effect.gen(function* writeConfigThenStart() {\n const { binary, token } = yield* frpcLaunch;\n const { stateDir, frpcConfigFile } = context.worktree;\n const apps = routedApps(context, state.ports);\n yield* writeConfig(\n stateDir,\n frpcConfigFile,\n renderFrpcConfig(context.config.server, context.worktree, apps),\n );\n if ((yield* processStatus(stateDir, 'frpc'))._tag !== 'running') {\n const offset = yield* logSize(processLogFile(stateDir, 'frpc'));\n const spec = { args: ['-c', frpcConfigFile], command: binary, name: 'frpc' } as const;\n yield* startProcess(stateDir, { ...spec, env: tokenEnvironment(token) });\n yield* confirmProxies(stateDir, apps, offset);\n }\n return state;\n }),\n name: 'frpc',\n remove: ({ worktree }, state) =>\n stopProcess(worktree.stateDir, 'frpc').pipe(\n Effect.andThen(Effect.promise(() => rm(worktree.frpcConfigFile, { force: true }))),\n Effect.as(state),\n ),\n};\n\nexport { frpc, frpcLaunch };\n"],"mappings":";;;;;;;;;;;;;AAiBA,MAAM,aAAa,OAAO,IAAI,UAAU,k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QAAQ,QAAQ,UAAU,IAAI,CAChE;EACA,KAAK,OAAO,cAAc,UAAU,MAAM,EAAA,CAAG,SAAS,WAAW;GAC/D,MAAM,SAAS,OAAO,QAAQ,eAAe,UAAU,MAAM,CAAC;GAE9D,OAAO,aAAa,UAAU;IADf,MAAM,CAAC,MAAM,cAAc;IAAG,SAAS;IAAQ,MAAM;IAC3B,KAAK,iBAAiB,KAAK;GAAE,CAAC;GACvE,OAAO,eAAe,UAAU,MAAM,MAAM;EAC9C;EACA,OAAO;CACT,CAAC;CACH,MAAM;CACN,SAAS,EAAE,YAAY,UACrB,YAAY,SAAS,UAAU,MAAM,CAAC,CAAC,KACrC,OAAO,QAAQ,OAAO,cAAc,GAAG,SAAS,gBAAgB,EAAE,OAAO,KAAK,CAAC,CAAC,CAAC,GACjF,OAAO,GAAG,KAAK,CACjB;AACJ"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { hostnameFor, worktreeZone } from "./domain.js";
|
|
2
|
+
import { WtTunnelError } from "./errors.js";
|
|
3
|
+
import { allocate, claim, release, reservationsDir } from "./ports.js";
|
|
4
|
+
import { Console, Effect, Record } from "effect";
|
|
5
|
+
import { writeFile } from "node:fs/promises";
|
|
6
|
+
// src/provision-ports.ts
|
|
7
|
+
const claimPinned = (request, pinned) => Effect.gen(function* failIfTaken() {
|
|
8
|
+
const result = yield* claim(request.dir, pinned, request.owner);
|
|
9
|
+
if (result._tag === "taken") return yield* new WtTunnelError({ message: `Port ${pinned} for ${request.app} is reserved by the worktree at ${result.owner}` });
|
|
10
|
+
return pinned;
|
|
11
|
+
});
|
|
12
|
+
/** The saved port while this worktree still holds it, else a newly allocated one. */
|
|
13
|
+
const keepOrAllocate = (request, saved) => Effect.gen(function* reuseSavedPort() {
|
|
14
|
+
if (saved !== void 0 && !request.used.includes(saved)) {
|
|
15
|
+
const result = yield* claim(request.dir, saved, request.owner);
|
|
16
|
+
if (result._tag !== "taken") return saved;
|
|
17
|
+
yield* Console.log(` port ${saved} for ${request.app} now belongs to ${result.owner}; picking a new one`);
|
|
18
|
+
}
|
|
19
|
+
return yield* allocate(request.dir, request.owner, request.used);
|
|
20
|
+
});
|
|
21
|
+
const reservePorts = (context, state, dir) => Effect.gen(function* reserveEachApp() {
|
|
22
|
+
const assigned = /* @__PURE__ */ new Map();
|
|
23
|
+
for (const [app, { port: pinned }] of Record.toEntries(context.config.apps)) {
|
|
24
|
+
const request = {
|
|
25
|
+
app,
|
|
26
|
+
dir,
|
|
27
|
+
owner: context.worktree.dir,
|
|
28
|
+
used: [...assigned.values()]
|
|
29
|
+
};
|
|
30
|
+
const port = pinned === void 0 ? yield* keepOrAllocate(request, state.ports[app]) : yield* claimPinned(request, pinned);
|
|
31
|
+
assigned.set(app, port);
|
|
32
|
+
}
|
|
33
|
+
return Object.fromEntries(assigned);
|
|
34
|
+
});
|
|
35
|
+
const envFileContents = (context, ports) => {
|
|
36
|
+
const lines = Record.collect(context.config.apps, (app, { portEnv }) => `${portEnv}=${ports[app]}`);
|
|
37
|
+
const host = worktreeZone(context.worktree.name, context.config.domain);
|
|
38
|
+
return `${[...lines, `WT_TUNNEL_HOST=${host}`].join("\n")}\n`;
|
|
39
|
+
};
|
|
40
|
+
/** The app labelled `root` is served at the bare `<worktree>.<domain>`; others get a label in front. */
|
|
41
|
+
const rootAppLabel = "root";
|
|
42
|
+
const appHostname = (context, app) => app === rootAppLabel ? worktreeZone(context.worktree.name, context.config.domain) : hostnameFor(app, context.worktree.name, context.config.domain);
|
|
43
|
+
/** The apps with a route and a reserved port, each with the host name it is served at. */
|
|
44
|
+
const routedApps = (context, ports) => Record.collect(context.config.apps, (app, { route }) => {
|
|
45
|
+
const port = ports[app];
|
|
46
|
+
return route === false || port === void 0 ? [] : [{
|
|
47
|
+
app,
|
|
48
|
+
hostname: appHostname(context, app),
|
|
49
|
+
port
|
|
50
|
+
}];
|
|
51
|
+
}).flat();
|
|
52
|
+
/**
|
|
53
|
+
* Ports are reserved per user in files (see ports.ts), so a stopped worktree keeps its ports and no
|
|
54
|
+
* other worktree can be handed them.
|
|
55
|
+
*/
|
|
56
|
+
const ports = {
|
|
57
|
+
ensure: (context, state) => Effect.gen(function* reserveAndWriteEnv() {
|
|
58
|
+
const dir = reservationsDir();
|
|
59
|
+
const assigned = yield* reservePorts(context, state, dir);
|
|
60
|
+
yield* release(dir, context.worktree.dir, Object.values(assigned));
|
|
61
|
+
yield* Effect.promise(() => writeFile(context.worktree.envFile, envFileContents(context, assigned)));
|
|
62
|
+
return {
|
|
63
|
+
...state,
|
|
64
|
+
ports: assigned
|
|
65
|
+
};
|
|
66
|
+
}),
|
|
67
|
+
name: "ports",
|
|
68
|
+
remove: (context, state) => release(reservationsDir(), context.worktree.dir).pipe(Effect.as({
|
|
69
|
+
...state,
|
|
70
|
+
ports: {}
|
|
71
|
+
}))
|
|
72
|
+
};
|
|
73
|
+
export { ports, routedApps };
|
|
74
|
+
|
|
75
|
+
//# sourceMappingURL=provision-ports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provision-ports.js","names":[],"sources":["../src/provision-ports.ts"],"sourcesContent":["import { writeFile } from 'node:fs/promises';\n\nimport type { Hostname } from '@tafrahq/wt-tunnel-contract';\nimport { Console, Effect, Record } from 'effect';\n\nimport { hostnameFor, worktreeZone } from './domain.ts';\nimport type { AppLabel, Port } from './domain.ts';\nimport { WtTunnelError } from './errors.ts';\nimport { allocate, claim, release, reservationsDir } from './ports.ts';\nimport type { ProvisionContext, Resource } from './resource.ts';\nimport type { WorktreeState } from './state.ts';\n\ntype PortsByApp = Record.ReadonlyRecord<AppLabel, Port>;\n\ninterface PortRequest {\n readonly app: AppLabel;\n readonly dir: string;\n readonly owner: string;\n /** Ports already given to other apps of this worktree. */\n readonly used: readonly number[];\n}\n\nconst claimPinned = (request: PortRequest, pinned: Port) =>\n Effect.gen(function* failIfTaken() {\n const result = yield* claim(request.dir, pinned, request.owner);\n if (result._tag === 'taken') {\n return yield* new WtTunnelError({\n message: `Port ${pinned} for ${request.app} is reserved by the worktree at ${result.owner}`,\n });\n }\n return pinned;\n });\n\n/** The saved port while this worktree still holds it, else a newly allocated one. */\nconst keepOrAllocate = (request: PortRequest, saved: Port | undefined) =>\n Effect.gen(function* reuseSavedPort() {\n if (saved !== undefined && !request.used.includes(saved)) {\n const result = yield* claim(request.dir, saved, request.owner);\n if (result._tag !== 'taken') {\n return saved;\n }\n yield* Console.log(\n ` port ${saved} for ${request.app} now belongs to ${result.owner}; picking a new one`,\n );\n }\n return yield* allocate(request.dir, request.owner, request.used);\n });\n\nconst reservePorts = (context: ProvisionContext, state: WorktreeState, dir: string) =>\n Effect.gen(function* reserveEachApp() {\n const assigned = new Map<AppLabel, Port>();\n for (const [app, { port: pinned }] of Record.toEntries(context.config.apps)) {\n const request = { app, dir, owner: context.worktree.dir, used: [...assigned.values()] };\n const port =\n pinned === undefined\n ? yield* keepOrAllocate(request, state.ports[app])\n : yield* claimPinned(request, pinned);\n assigned.set(app, port);\n }\n return Object.fromEntries(assigned);\n });\n\nconst envFileContents = (context: ProvisionContext, ports: PortsByApp) => {\n const lines = Record.collect(\n context.config.apps,\n (app, { portEnv }) => `${portEnv}=${ports[app]}`,\n );\n const host = worktreeZone(context.worktree.name, context.config.domain);\n return `${[...lines, `WT_TUNNEL_HOST=${host}`].join('\\n')}\\n`;\n};\n\n/** The app labelled `root` is served at the bare `<worktree>.<domain>`; others get a label in front. */\nconst rootAppLabel = 'root';\n\nconst appHostname = (context: ProvisionContext, app: AppLabel): Hostname =>\n app === rootAppLabel\n ? worktreeZone(context.worktree.name, context.config.domain)\n : hostnameFor(app, context.worktree.name, context.config.domain);\n\ninterface RoutedApp {\n readonly app: AppLabel;\n readonly hostname: Hostname;\n readonly port: Port;\n}\n\n/** The apps with a route and a reserved port, each with the host name it is served at. */\nconst routedApps = (context: ProvisionContext, ports: PortsByApp): readonly RoutedApp[] =>\n Record.collect(context.config.apps, (app, { route }): readonly RoutedApp[] => {\n const port = ports[app];\n return route === false || port === undefined\n ? []\n : [{ app, hostname: appHostname(context, app), port }];\n }).flat();\n\n/**\n * Ports are reserved per user in files (see ports.ts), so a stopped worktree keeps its ports and no\n * other worktree can be handed them.\n */\nconst ports: Resource = {\n ensure: (context, state) =>\n Effect.gen(function* reserveAndWriteEnv() {\n const dir = reservationsDir();\n const assigned = yield* reservePorts(context, state, dir);\n yield* release(dir, context.worktree.dir, Object.values(assigned));\n yield* Effect.promise(() =>\n writeFile(context.worktree.envFile, envFileContents(context, assigned)),\n );\n return { ...state, ports: assigned };\n }),\n name: 'ports',\n remove: (context, state) =>\n release(reservationsDir(), context.worktree.dir).pipe(Effect.as({ ...state, ports: {} })),\n};\n\nexport { ports, routedApps };\nexport type { RoutedApp };\n"],"mappings":";;;;;;AAsBA,MAAM,eAAe,SAAsB,WACzC,OAAO,IAAI,UAAU,cAAc;CACjC,MAAM,SAAS,OAAO,MAAM,QAAQ,KAAK,QAAQ,QAAQ,KAAK;CAC9D,IAAI,OAAO,SAAS,SAClB,OAAO,OAAO,IAAI,cAAc,EAC9B,SAAS,QAAQ,OAAO,OAAO,QAAQ,IAAI,kCAAkC,OAAO,QACtF,CAAC;CAEH,OAAO;AACT,CAAC;;AAGH,MAAM,kBAAkB,SAAsB,UAC5C,OAAO,IAAI,UAAU,iBAAiB;CACpC,IAAI,UAAU,KAAA,KAAa,CAAC,QAAQ,KAAK,SAAS,KAAK,GAAG;EACxD,MAAM,SAAS,OAAO,MAAM,QAAQ,KAAK,OAAO,QAAQ,KAAK;EAC7D,IAAI,OAAO,SAAS,SAClB,OAAO;EAET,OAAO,QAAQ,IACb,UAAU,MAAM,OAAO,QAAQ,IAAI,kBAAkB,OAAO,MAAM,oBACpE;CACF;CACA,OAAO,OAAO,SAAS,QAAQ,KAAK,QAAQ,OAAO,QAAQ,IAAI;AACjE,CAAC;AAEH,MAAM,gBAAgB,SAA2B,OAAsB,QACrE,OAAO,IAAI,UAAU,iBAAiB;CACpC,MAAM,2BAAW,IAAI,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;EACxD,OAAO,QAAQ,KAAK,QAAQ,SAAS,KAAK,OAAO,OAAO,QAAQ,CAAC;EACjE,OAAO,OAAO,cACZ,UAAU,QAAQ,SAAS,SAAS,gBAAgB,SAAS,QAAQ,CAAC,CACxE;EACA,OAAO;GAAE,GAAG;GAAO,OAAO;EAAS;CACrC,CAAC;CACH,MAAM;CACN,SAAS,SAAS,UAChB,QAAQ,gBAAgB,GAAG,QAAQ,SAAS,GAAG,CAAC,CAAC,KAAK,OAAO,GAAG;EAAE,GAAG;EAAO,OAAO,CAAC;CAAE,CAAC,CAAC;AAC5F"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ports } from "./provision-ports.js";
|
|
2
|
+
import { writeState } from "./state.js";
|
|
3
|
+
import { frpc } from "./provision-frpc.js";
|
|
4
|
+
import { Console, Effect } from "effect";
|
|
5
|
+
// src/provision.ts
|
|
6
|
+
/** What a worktree is made of, in creation order. */
|
|
7
|
+
const worktreeResources = [ports, frpc];
|
|
8
|
+
/** Applies one step per resource, saving the state after each so a crash loses no progress. */
|
|
9
|
+
const applyPass = (context, initial, pass) => Effect.gen(function* stepThroughResources() {
|
|
10
|
+
let state = initial;
|
|
11
|
+
for (const resource of pass.order) {
|
|
12
|
+
yield* Console.log(` ${pass.verb} ${resource.name}`);
|
|
13
|
+
state = yield* resource[pass.verb](context, state);
|
|
14
|
+
yield* writeState(context.worktree.stateFile, state);
|
|
15
|
+
}
|
|
16
|
+
return state;
|
|
17
|
+
});
|
|
18
|
+
const ensureAll = (context, initial, list = worktreeResources) => applyPass(context, initial, {
|
|
19
|
+
order: list,
|
|
20
|
+
verb: "ensure"
|
|
21
|
+
});
|
|
22
|
+
const removeAll = (context, initial, list = worktreeResources) => applyPass(context, initial, {
|
|
23
|
+
order: list.toReversed(),
|
|
24
|
+
verb: "remove"
|
|
25
|
+
});
|
|
26
|
+
export { ensureAll, removeAll, worktreeResources };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=provision.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provision.js","names":[],"sources":["../src/provision.ts"],"sourcesContent":["import { Console, Effect } from 'effect';\n\nimport { frpc } from './provision-frpc.ts';\nimport { ports } from './provision-ports.ts';\nimport type { ProvisionContext, Resource } from './resource.ts';\nimport { writeState } from './state.ts';\nimport type { WorktreeState } from './state.ts';\n\n/** What a worktree is made of, in creation order. */\nconst worktreeResources: readonly Resource[] = [ports, frpc];\n\ninterface Pass {\n readonly verb: 'ensure' | 'remove';\n readonly order: readonly Resource[];\n}\n\n/** Applies one step per resource, saving the state after each so a crash loses no progress. */\nconst applyPass = (context: ProvisionContext, initial: WorktreeState, pass: Pass) =>\n Effect.gen(function* stepThroughResources() {\n let state = initial;\n for (const resource of pass.order) {\n yield* Console.log(` ${pass.verb} ${resource.name}`);\n state = yield* resource[pass.verb](context, state);\n yield* writeState(context.worktree.stateFile, state);\n }\n return state;\n });\n\nconst ensureAll = (\n context: ProvisionContext,\n initial: WorktreeState,\n list: readonly Resource[] = worktreeResources,\n) => applyPass(context, initial, { order: list, verb: 'ensure' });\n\nconst removeAll = (\n context: ProvisionContext,\n initial: WorktreeState,\n list: readonly Resource[] = worktreeResources,\n) => applyPass(context, initial, { order: list.toReversed(), verb: 'remove' });\n\nexport { ensureAll, removeAll, worktreeResources };\n"],"mappings":";;;;;;AASA,MAAM,oBAAyC,CAAC,OAAO,IAAI;;AAQ3D,MAAM,aAAa,SAA2B,SAAwB,SACpE,OAAO,IAAI,UAAU,uBAAuB;CAC1C,IAAI,QAAQ;CACZ,KAAK,MAAM,YAAY,KAAK,OAAO;EACjC,OAAO,QAAQ,IAAI,KAAK,KAAK,KAAK,GAAG,SAAS,MAAM;EACpD,QAAQ,OAAO,SAAS,KAAK,KAAK,CAAC,SAAS,KAAK;EACjD,OAAO,WAAW,QAAQ,SAAS,WAAW,KAAK;CACrD;CACA,OAAO;AACT,CAAC;AAEH,MAAM,aACJ,SACA,SACA,OAA4B,sBACzB,UAAU,SAAS,SAAS;CAAE,OAAO;CAAM,MAAM;AAAS,CAAC;AAEhE,MAAM,aACJ,SACA,SACA,OAA4B,sBACzB,UAAU,SAAS,SAAS;CAAE,OAAO,KAAK,WAAW;CAAG,MAAM;AAAS,CAAC"}
|
package/dist/state.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Hostname } from "./packages/contract/src/index.js";
|
|
2
|
+
import { AppLabel, Port, ProjectName, WorktreeName } from "./domain.js";
|
|
3
|
+
import { WtTunnelError } from "./errors.js";
|
|
4
|
+
import { Effect, FileSystem, Schema } from "effect";
|
|
5
|
+
import { dirname } from "node:path";
|
|
6
|
+
// src/state.ts
|
|
7
|
+
const stateVersion = 4;
|
|
8
|
+
const jsonIndent = 2;
|
|
9
|
+
const WorktreeState = Schema.Struct({
|
|
10
|
+
domain: Hostname,
|
|
11
|
+
ports: Schema.Record(AppLabel, Port),
|
|
12
|
+
project: ProjectName,
|
|
13
|
+
version: Schema.Literal(stateVersion),
|
|
14
|
+
worktree: WorktreeName
|
|
15
|
+
});
|
|
16
|
+
const StateJson = Schema.fromJsonString(WorktreeState);
|
|
17
|
+
const initialState = (project, worktree, domain) => ({
|
|
18
|
+
domain,
|
|
19
|
+
ports: {},
|
|
20
|
+
project,
|
|
21
|
+
version: stateVersion,
|
|
22
|
+
worktree
|
|
23
|
+
});
|
|
24
|
+
const VersionJson = Schema.fromJsonString(Schema.Struct({ version: Schema.Unknown }));
|
|
25
|
+
/** Names the version mismatch when that is the problem, since the schema error would not. */
|
|
26
|
+
const invalidState = (file, text, schemaMessage) => {
|
|
27
|
+
const found = Schema.decodeUnknownOption(VersionJson)(text);
|
|
28
|
+
const version = found._tag === "Some" ? found.value.version : void 0;
|
|
29
|
+
if (version !== void 0 && version !== stateVersion) return new WtTunnelError({ message: `${file} was written by an older wt-tunnel-client (state version ${JSON.stringify(version)}, this one reads ${stateVersion}). Stop the processes named by the pid files in ${dirname(file)}, delete that directory, and run wt-tunnel-client worktree add again.` });
|
|
30
|
+
return new WtTunnelError({ message: `${file} is not valid state: ${schemaMessage}` });
|
|
31
|
+
};
|
|
32
|
+
const decodeState = (file, text) => Schema.decodeUnknownEffect(StateJson)(text).pipe(Effect.mapError((schemaError) => invalidState(file, text, schemaError.message)));
|
|
33
|
+
const readState = (file) => Effect.gen(function* readIfPresent() {
|
|
34
|
+
const fs = yield* FileSystem.FileSystem;
|
|
35
|
+
return (yield* fs.exists(file)) ? yield* decodeState(file, yield* fs.readFileString(file)) : void 0;
|
|
36
|
+
});
|
|
37
|
+
/** The saved state when it is for the same names (a rerun), else a fresh one; other names fail. */
|
|
38
|
+
const startingState = (worktree, domain) => Effect.gen(function* readOrCreate() {
|
|
39
|
+
const existing = yield* readState(worktree.stateFile);
|
|
40
|
+
if (existing === void 0) return initialState(worktree.project, worktree.name, domain);
|
|
41
|
+
if (existing.project !== worktree.project || existing.worktree !== worktree.name) return yield* new WtTunnelError({ message: `${worktree.dir} is already provisioned as ${existing.project} ${existing.worktree}. Run \`wt-tunnel-client worktree remove\` first.` });
|
|
42
|
+
return existing;
|
|
43
|
+
});
|
|
44
|
+
const writeState = (file, state) => Effect.gen(function* writeAtomically() {
|
|
45
|
+
const fs = yield* FileSystem.FileSystem;
|
|
46
|
+
const encoded = yield* Schema.encodeEffect(WorktreeState)(state).pipe(Effect.orDie);
|
|
47
|
+
const temp = `${file}.${process.pid}.tmp`;
|
|
48
|
+
yield* fs.writeFileString(temp, `${JSON.stringify(encoded, void 0, jsonIndent)}\n`);
|
|
49
|
+
yield* fs.rename(temp, file);
|
|
50
|
+
});
|
|
51
|
+
export { initialState, readState, startingState, writeState };
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.js","names":[],"sources":["../src/state.ts"],"sourcesContent":["import { dirname } from 'node:path';\n\nimport { Hostname } from '@tafrahq/wt-tunnel-contract';\nimport { Effect, FileSystem, Schema } from 'effect';\n\nimport { AppLabel, Port, ProjectName, WorktreeName } from './domain.ts';\nimport { WtTunnelError } from './errors.ts';\nimport type { Worktree } from './worktree.ts';\n\nconst stateVersion = 4;\nconst jsonIndent = 2;\n\nconst WorktreeState = Schema.Struct({\n domain: Hostname,\n ports: Schema.Record(AppLabel, Port),\n project: ProjectName,\n version: Schema.Literal(stateVersion),\n worktree: WorktreeName,\n});\ntype WorktreeState = typeof WorktreeState.Type;\n\nconst StateJson = Schema.fromJsonString(WorktreeState);\n\nconst initialState = (\n project: ProjectName,\n worktree: WorktreeName,\n domain: Hostname,\n): WorktreeState => ({\n domain,\n ports: {},\n project,\n version: stateVersion,\n worktree,\n});\n\nconst VersionJson = Schema.fromJsonString(Schema.Struct({ version: Schema.Unknown }));\n\n/** Names the version mismatch when that is the problem, since the schema error would not. */\nconst invalidState = (file: string, text: string, schemaMessage: string) => {\n const found = Schema.decodeUnknownOption(VersionJson)(text);\n const version = found._tag === 'Some' ? found.value.version : undefined;\n if (version !== undefined && version !== stateVersion) {\n return new WtTunnelError({\n message: `${file} was written by an older wt-tunnel-client (state version ${JSON.stringify(version)}, this one reads ${stateVersion}). Stop the processes named by the pid files in ${dirname(file)}, delete that directory, and run wt-tunnel-client worktree add again.`,\n });\n }\n return new WtTunnelError({ message: `${file} is not valid state: ${schemaMessage}` });\n};\n\nconst decodeState = (file: string, text: string) =>\n Schema.decodeUnknownEffect(StateJson)(text).pipe(\n Effect.mapError((schemaError) => invalidState(file, text, schemaError.message)),\n );\n\nconst readState = (file: string) =>\n Effect.gen(function* readIfPresent() {\n const fs = yield* FileSystem.FileSystem;\n const exists = yield* fs.exists(file);\n return exists ? yield* decodeState(file, yield* fs.readFileString(file)) : undefined;\n });\n\n/** The saved state when it is for the same names (a rerun), else a fresh one; other names fail. */\nconst startingState = (worktree: Worktree, domain: Hostname) =>\n Effect.gen(function* readOrCreate() {\n const existing = yield* readState(worktree.stateFile);\n if (existing === undefined) {\n return initialState(worktree.project, worktree.name, domain);\n }\n if (existing.project !== worktree.project || existing.worktree !== worktree.name) {\n return yield* new WtTunnelError({\n message: `${worktree.dir} is already provisioned as ${existing.project} ${existing.worktree}. Run \\`wt-tunnel-client worktree remove\\` first.`,\n });\n }\n return existing;\n });\n\nconst writeState = (file: string, state: WorktreeState) =>\n Effect.gen(function* writeAtomically() {\n const fs = yield* FileSystem.FileSystem;\n const encoded = yield* Schema.encodeEffect(WorktreeState)(state).pipe(Effect.orDie);\n const temp = `${file}.${process.pid}.tmp`;\n yield* fs.writeFileString(temp, `${JSON.stringify(encoded, undefined, jsonIndent)}\\n`);\n yield* fs.rename(temp, file);\n });\n\nexport { initialState, readState, startingState, writeState };\nexport type { WorktreeState };\n"],"mappings":";;;;;;AASA,MAAM,eAAe;AACrB,MAAM,aAAa;AAEnB,MAAM,gBAAgB,OAAO,OAAO;CAClC,QAAQ;CACR,OAAO,OAAO,OAAO,UAAU,IAAI;CACnC,SAAS;CACT,SAAS,OAAO,QAAQ,YAAY;CACpC,UAAU;AACZ,CAAC;AAGD,MAAM,YAAY,OAAO,eAAe,aAAa;AAErD,MAAM,gBACJ,SACA,UACA,YACmB;CACnB;CACA,OAAO,CAAC;CACR;CACA,SAAS;CACT;AACF;AAEA,MAAM,cAAc,OAAO,eAAe,OAAO,OAAO,EAAE,SAAS,OAAO,QAAQ,CAAC,CAAC;;AAGpF,MAAM,gBAAgB,MAAc,MAAc,kBAA0B;CAC1E,MAAM,QAAQ,OAAO,oBAAoB,WAAW,CAAC,CAAC,IAAI;CAC1D,MAAM,UAAU,MAAM,SAAS,SAAS,MAAM,MAAM,UAAU,KAAA;CAC9D,IAAI,YAAY,KAAA,KAAa,YAAY,cACvC,OAAO,IAAI,cAAc,EACvB,SAAS,GAAG,KAAK,2DAA2D,KAAK,UAAU,OAAO,EAAE,mBAAmB,aAAa,kDAAkD,QAAQ,IAAI,EAAE,uEACtM,CAAC;CAEH,OAAO,IAAI,cAAc,EAAE,SAAS,GAAG,KAAK,uBAAuB,gBAAgB,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Schema } from "effect";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
// src/worktree.ts
|
|
6
|
+
const stateDirOf = (root) => join(root, ".wt-tunnel");
|
|
7
|
+
const stateFileOf = (root) => join(stateDirOf(root), "state.json");
|
|
8
|
+
const invalidName = (kind, value) => new WtTunnelError({ message: `"${value}" is not a valid ${kind} name. Use lowercase letters, digits and interior hyphens, at most 63 characters (a DNS label).` });
|
|
9
|
+
const parseProjectName = (value) => Schema.decodeUnknownEffect(ProjectName)(value).pipe(Effect.mapError(() => invalidName("project", value)));
|
|
10
|
+
const parseWorktreeName = (value) => Schema.decodeUnknownEffect(WorktreeName)(value).pipe(Effect.mapError(() => invalidName("worktree", value)));
|
|
11
|
+
const worktreeAt = (root, project, name) => {
|
|
12
|
+
const stateDir = stateDirOf(root);
|
|
13
|
+
return {
|
|
14
|
+
dir: root,
|
|
15
|
+
envFile: join(stateDir, "env"),
|
|
16
|
+
frpcConfigFile: join(stateDir, "frpc.toml"),
|
|
17
|
+
name,
|
|
18
|
+
project,
|
|
19
|
+
stateDir,
|
|
20
|
+
stateFile: stateFileOf(root)
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
export { parseProjectName, parseWorktreeName, stateFileOf, worktreeAt };
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=worktree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worktree.js","names":[],"sources":["../src/worktree.ts"],"sourcesContent":["import { join } from 'node:path';\n\nimport { Effect, Schema } from 'effect';\n\nimport { ProjectName, WorktreeName } from './domain.ts';\nimport { WtTunnelError } from './errors.ts';\n\n/** The directory being served (the worktree root) and the names it was provisioned under. */\ninterface Worktree {\n readonly dir: string;\n readonly envFile: string;\n readonly frpcConfigFile: string;\n readonly name: WorktreeName;\n readonly project: ProjectName;\n readonly stateDir: string;\n readonly stateFile: string;\n}\n\nconst stateDirOf = (root: string) => join(root, '.wt-tunnel');\n\nconst stateFileOf = (root: string) => join(stateDirOf(root), 'state.json');\n\nconst invalidName = (kind: string, value: string) =>\n new WtTunnelError({\n message: `\"${value}\" is not a valid ${kind} name. Use lowercase letters, digits and interior hyphens, at most 63 characters (a DNS label).`,\n });\n\nconst parseProjectName = (value: string) =>\n Schema.decodeUnknownEffect(ProjectName)(value).pipe(\n Effect.mapError(() => invalidName('project', value)),\n );\n\nconst parseWorktreeName = (value: string) =>\n Schema.decodeUnknownEffect(WorktreeName)(value).pipe(\n Effect.mapError(() => invalidName('worktree', value)),\n );\n\nconst worktreeAt = (root: string, project: ProjectName, name: WorktreeName): Worktree => {\n const stateDir = stateDirOf(root);\n return {\n dir: root,\n envFile: join(stateDir, 'env'),\n frpcConfigFile: join(stateDir, 'frpc.toml'),\n name,\n project,\n stateDir,\n stateFile: stateFileOf(root),\n };\n};\n\nexport { parseProjectName, parseWorktreeName, stateFileOf, worktreeAt };\nexport type { Worktree };\n"],"mappings":";;;;;AAkBA,MAAM,cAAc,SAAiB,KAAK,MAAM,YAAY;AAE5D,MAAM,eAAe,SAAiB,KAAK,WAAW,IAAI,GAAG,YAAY;AAEzE,MAAM,eAAe,MAAc,UACjC,IAAI,cAAc,EAChB,SAAS,IAAI,MAAM,mBAAmB,KAAK,iGAC7C,CAAC;AAEH,MAAM,oBAAoB,UACxB,OAAO,oBAAoB,WAAW,CAAC,CAAC,KAAK,CAAC,CAAC,KAC7C,OAAO,eAAe,YAAY,WAAW,KAAK,CAAC,CACrD;AAEF,MAAM,qBAAqB,UACzB,OAAO,oBAAoB,YAAY,CAAC,CAAC,KAAK,CAAC,CAAC,KAC9C,OAAO,eAAe,YAAY,YAAY,KAAK,CAAC,CACtD;AAEF,MAAM,cAAc,MAAc,SAAsB,SAAiC;CACvF,MAAM,WAAW,WAAW,IAAI;CAChC,OAAO;EACL,KAAK;EACL,SAAS,KAAK,UAAU,KAAK;EAC7B,gBAAgB,KAAK,UAAU,WAAW;EAC1C;EACA;EACA;EACA,WAAW,YAAY,IAAI;CAC7B;AACF"}
|
package/llms.txt
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# wt-tunnel-client
|
|
2
|
+
|
|
3
|
+
> Command-line tool (`@tafrahq/wt-tunnel-client`, Node 22+) that gives each git worktree private HTTPS URLs, such as `https://app.feat-x.dev.example.com`, through a self-hosted tunnel server (frps behind Caddy and a sign-in with Google, GitHub, Microsoft or Cloudflare Access). One frpc per worktree; no ports in URLs; no root and no open port on the dev machine.
|
|
4
|
+
|
|
5
|
+
Key facts:
|
|
6
|
+
|
|
7
|
+
- Config lives in `wt-tunnel.json` at the repository root: `domain`, `server` (`host`, a host name such as `wt-tunnel.example.com` or an IP address; `port`, default 7000), and `apps` (`portEnv`, optional `route: false`, optional fixed `port`). The app labelled `root` is served at the bare `<worktree>.<domain>`; every other app at `<app>.<worktree>.<domain>`. The worktree root is the nearest directory at or above the current one that holds the file; state lives in `<root>/.wt-tunnel/`.
|
|
8
|
+
- The tunnel token comes from `WT_TUNNEL_SERVER_TOKEN`. It reaches frpc only through its environment (`{{ .Envs.WT_TUNNEL_SERVER_TOKEN }}` in `frpc.toml`) and is never written to disk.
|
|
9
|
+
- `up` reserves ports, writes `.wt-tunnel/frpc.toml` (one `http` proxy per routed app, frp user `<project>.<worktree>`), starts frpc, and waits until the server has accepted every host. A refused host (for example one another worktree already serves) stops frpc and fails with the host and reason.
|
|
10
|
+
- Ports are reserved per user in `~/.local/state/wt-tunnel/ports/` (range 20000-29999) and written to `.wt-tunnel/env` with `WT_TUNNEL_HOST`.
|
|
11
|
+
- frpc v0.71.1 is downloaded on first use for Linux or macOS (amd64, arm64), checked against pinned SHA-256 sums, into `$XDG_CACHE_HOME/wt-tunnel/frp/0.71.1/`. `WT_TUNNEL_FRPC` overrides it.
|
|
12
|
+
- The server signs certificates with its deployment's own name-constrained root CA, which each device that opens the URLs must trust once. The server's sign-in host serves it at `https://<authHost>/ca`.
|
|
13
|
+
- wt-tunnel-client never runs git and never picks names. The user creates the git worktree, then runs `wt-tunnel-client worktree add <project> <worktree>` in it.
|
|
14
|
+
|
|
15
|
+
## Docs
|
|
16
|
+
|
|
17
|
+
- [README](README.md): install, configuration, trusting the CA, commands.
|
|
18
|
+
- [docs/server-mode.md](https://github.com/tafrahq/wt-tunnel/blob/main/docs/server-mode.md): the design, the server config and the sign-in flow.
|
|
19
|
+
- [apps/cli/README.md](https://github.com/tafrahq/wt-tunnel/blob/main/apps/cli/README.md): deploying the server to Fly.io.
|
|
20
|
+
- [apps/server/README.md](https://github.com/tafrahq/wt-tunnel/blob/main/apps/server/README.md): running the server anywhere else, and building its image.
|
|
21
|
+
|
|
22
|
+
## Commands
|
|
23
|
+
|
|
24
|
+
- `wt-tunnel-client worktree add <project> <worktree>`: give the current worktree root its private URLs. Names must be DNS labels.
|
|
25
|
+
- `wt-tunnel-client worktree remove`: stop frpc, release the ports, delete `.wt-tunnel/`. The user then runs `git worktree remove`.
|
|
26
|
+
- `wt-tunnel-client up | down | status | env`: manage the current worktree. They fail until `worktree add` has run.
|
|
27
|
+
|
|
28
|
+
## Source
|
|
29
|
+
|
|
30
|
+
- [src/cli.ts](src/cli.ts): commands.
|
|
31
|
+
- [src/provision.ts](src/provision.ts): the worktree's idempotent resources, ports then frpc.
|
|
32
|
+
- [src/provision-frpc.ts](src/provision-frpc.ts): starting frpc and confirming that the server accepted every host.
|
|
33
|
+
- [src/frpc-config.ts](src/frpc-config.ts): `frpc.toml`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,66 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tafrahq/wt-tunnel-client",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.7.0",
|
|
4
|
+
"description": "Private HTTPS URLs for every git worktree, through a self-hosted frp tunnel server behind a sign-in (Google, GitHub, Microsoft or Cloudflare Access): one frpc per worktree, no ports in the URLs, no root on the dev machine.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"cli",
|
|
7
|
+
"dev-server",
|
|
8
|
+
"effect",
|
|
9
|
+
"frp",
|
|
10
|
+
"frpc",
|
|
11
|
+
"git-worktree",
|
|
12
|
+
"https",
|
|
13
|
+
"localhost",
|
|
14
|
+
"preview-urls",
|
|
15
|
+
"reverse-tunnel",
|
|
16
|
+
"self-hosted",
|
|
17
|
+
"tunnel",
|
|
18
|
+
"vite",
|
|
19
|
+
"worktree",
|
|
20
|
+
"wt-tunnel"
|
|
21
|
+
],
|
|
22
|
+
"homepage": "https://github.com/tafrahq/wt-tunnel/tree/main/apps/client#readme",
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/tafrahq/wt-tunnel/issues"
|
|
25
|
+
},
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"author": "Tafra (https://github.com/tafrahq)",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/tafrahq/wt-tunnel.git",
|
|
31
|
+
"directory": "apps/client"
|
|
32
|
+
},
|
|
33
|
+
"bin": {
|
|
34
|
+
"wt-tunnel-client": "dist/bin.js"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist",
|
|
38
|
+
"src",
|
|
39
|
+
"!src/**/*.test.ts",
|
|
40
|
+
"llms.txt"
|
|
41
|
+
],
|
|
42
|
+
"type": "module",
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@effect/platform-node": "4.0.6",
|
|
48
|
+
"effect": "4.0.6"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@effect/vitest": "^4.0.6",
|
|
52
|
+
"@tafrahq/wt-tunnel-binaries": "0.0.0",
|
|
53
|
+
"@tafrahq/wt-tunnel-contract": "0.0.0",
|
|
54
|
+
"@types/node": "^22.20.5",
|
|
55
|
+
"tsdown": "0.23.2",
|
|
56
|
+
"vitest": "^5.0.5"
|
|
57
|
+
},
|
|
58
|
+
"engines": {
|
|
59
|
+
"node": ">=22"
|
|
60
|
+
},
|
|
61
|
+
"scripts": {
|
|
62
|
+
"build": "tsdown && node dist/bin.js --version",
|
|
63
|
+
"typecheck": "tsc --noEmit",
|
|
64
|
+
"test": "vitest run"
|
|
65
|
+
}
|
|
6
66
|
}
|
package/src/bin.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
|
|
4
|
+
import { NodeRuntime, NodeServices } from '@effect/platform-node';
|
|
5
|
+
import { Console, Effect, Schema } from 'effect';
|
|
6
|
+
|
|
7
|
+
import { run } from './cli.ts';
|
|
8
|
+
|
|
9
|
+
const PackageJson = Schema.Struct({ version: Schema.String });
|
|
10
|
+
const packageJson: unknown = createRequire(import.meta.url)('../package.json');
|
|
11
|
+
|
|
12
|
+
const program = Schema.decodeUnknownEffect(PackageJson)(packageJson).pipe(
|
|
13
|
+
Effect.orDie,
|
|
14
|
+
Effect.flatMap(({ version }) => run(version)),
|
|
15
|
+
// Expected failures carry a message written for the user; skip the stack trace.
|
|
16
|
+
Effect.catchTag('WtTunnelError', ({ message }: { readonly message: string }) =>
|
|
17
|
+
Console.error(`wt-tunnel-client: ${message}`).pipe(
|
|
18
|
+
Effect.andThen(
|
|
19
|
+
Effect.sync(() => {
|
|
20
|
+
process.exitCode = 1;
|
|
21
|
+
}),
|
|
22
|
+
),
|
|
23
|
+
),
|
|
24
|
+
),
|
|
25
|
+
Effect.provide(NodeServices.layer),
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
NodeRuntime.runMain(program);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Console, Effect } from 'effect';
|
|
2
|
+
|
|
3
|
+
import { provisionUp } from './cli-provision.ts';
|
|
4
|
+
import { status } from './cli-status.ts';
|
|
5
|
+
import { currentWorktreeCommand, envLines } from './cli-workspace.ts';
|
|
6
|
+
import { WtTunnelError } from './errors.ts';
|
|
7
|
+
import { pathExists } from './files.ts';
|
|
8
|
+
import { stopProcess } from './processes.ts';
|
|
9
|
+
|
|
10
|
+
const up = currentWorktreeCommand(
|
|
11
|
+
'up',
|
|
12
|
+
'Provision and start this worktree (for example after a reboot)',
|
|
13
|
+
({ config, state, worktree }) => provisionUp({ config, worktree }, state),
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
const down = currentWorktreeCommand(
|
|
17
|
+
'down',
|
|
18
|
+
"Stop this worktree's frpc, keep its ports",
|
|
19
|
+
({ worktree }) =>
|
|
20
|
+
stopProcess(worktree.stateDir, 'frpc').pipe(
|
|
21
|
+
Effect.andThen(Console.log('Stopped frpc. Run wt-tunnel-client up to start again.')),
|
|
22
|
+
),
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
const env = currentWorktreeCommand(
|
|
26
|
+
'env',
|
|
27
|
+
'Print shell exports for the allocated ports: eval "$(wt-tunnel-client env)"',
|
|
28
|
+
({ worktree }) =>
|
|
29
|
+
Effect.gen(function* printExports() {
|
|
30
|
+
if (!(yield* Effect.promise(() => pathExists(worktree.envFile)))) {
|
|
31
|
+
yield* new WtTunnelError({ message: 'No ports allocated yet. Run wt-tunnel-client up.' });
|
|
32
|
+
}
|
|
33
|
+
const lines = yield* envLines(worktree);
|
|
34
|
+
yield* Effect.all(lines.map((line) => Console.log(`export ${line}`)));
|
|
35
|
+
}),
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const worktreeCommands = [up, down, status, env] as const;
|
|
39
|
+
|
|
40
|
+
export { worktreeCommands };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Console, Effect } from 'effect';
|
|
2
|
+
|
|
3
|
+
import { envLines, prepareStateDir, urls } from './cli-workspace.ts';
|
|
4
|
+
import { serverEndpoint } from './frpc-config.ts';
|
|
5
|
+
import { frpcLaunch } from './provision-frpc.ts';
|
|
6
|
+
import { ensureAll } from './provision.ts';
|
|
7
|
+
import type { ProvisionContext } from './resource.ts';
|
|
8
|
+
import { writeState } from './state.ts';
|
|
9
|
+
import type { WorktreeState } from './state.ts';
|
|
10
|
+
|
|
11
|
+
const printSummary = (context: ProvisionContext, state: WorktreeState) =>
|
|
12
|
+
Effect.gen(function* printUrlsAndPorts() {
|
|
13
|
+
const { config, worktree } = context;
|
|
14
|
+
yield* Console.log(`\nWorktree ${state.worktree}, frpc to ${serverEndpoint(config.server)}`);
|
|
15
|
+
yield* Effect.all(
|
|
16
|
+
urls(context, state).map(({ url, port }) =>
|
|
17
|
+
Console.log(` ${url} → http://127.0.0.1:${port}`),
|
|
18
|
+
),
|
|
19
|
+
);
|
|
20
|
+
yield* Console.log(`\nStart your dev servers with these ports (also in ${worktree.envFile}):`);
|
|
21
|
+
const lines = yield* envLines(worktree);
|
|
22
|
+
yield* Effect.all(lines.map((line) => Console.log(` ${line}`)));
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
/** Checks for the token and frpc before anything of the worktree is created. */
|
|
26
|
+
const provisionUp = (context: ProvisionContext, initial: WorktreeState) =>
|
|
27
|
+
Effect.gen(function* checkProvisionPrint() {
|
|
28
|
+
yield* frpcLaunch;
|
|
29
|
+
yield* prepareStateDir(context.worktree);
|
|
30
|
+
yield* writeState(context.worktree.stateFile, initial);
|
|
31
|
+
yield* printSummary(context, yield* ensureAll(context, initial));
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
export { provisionUp };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Console, Effect } from 'effect';
|
|
2
|
+
|
|
3
|
+
import { currentWorktreeCommand, urls } from './cli-workspace.ts';
|
|
4
|
+
import type { CurrentWorktree } from './cli-workspace.ts';
|
|
5
|
+
import { serverEndpoint } from './frpc-config.ts';
|
|
6
|
+
import { processStatus } from './processes.ts';
|
|
7
|
+
|
|
8
|
+
const printStatus = ({ config, worktree, state }: CurrentWorktree) =>
|
|
9
|
+
Effect.gen(function* printEndpointProcessUrls() {
|
|
10
|
+
yield* Console.log(
|
|
11
|
+
`${state.project} ${state.worktree}, frpc to ${serverEndpoint(config.server)}`,
|
|
12
|
+
);
|
|
13
|
+
const frpc = yield* processStatus(worktree.stateDir, 'frpc');
|
|
14
|
+
const pid = frpc._tag === 'stopped' ? '' : ` (pid ${frpc.pid})`;
|
|
15
|
+
yield* Console.log(` frpc ${frpc._tag}${pid}`);
|
|
16
|
+
yield* Effect.all(
|
|
17
|
+
urls({ config, worktree }, state).map(({ url, port }) =>
|
|
18
|
+
Console.log(` ${url} → :${port}`),
|
|
19
|
+
),
|
|
20
|
+
);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const status = currentWorktreeCommand(
|
|
24
|
+
'status',
|
|
25
|
+
"Show this worktree's tunnel server, frpc and URLs",
|
|
26
|
+
printStatus,
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
export { status };
|