@tnunamak/dalan 0.6.2 → 0.8.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/CHANGELOG.md +53 -0
- package/CONTRIBUTING.md +4 -0
- package/PROTOCOL.md +2 -0
- package/README.md +81 -84
- package/bin/dalan.mjs +9 -0
- package/bin/dot-worker.mjs +29 -4
- package/contracts/adapter-qualification.schema.json +170 -0
- package/docs/chatgpt-worker-onboarding.md +10 -14
- package/docs/claude-worker-onboarding.md +9 -8
- package/docs/codex-to-muse.md +21 -35
- package/docs/connect-chatgpt.md +10 -16
- package/docs/dalan-upgrade.md +4 -2
- package/docs/local-agent-mcp.md +24 -4
- package/docs/local-agent-requester.md +46 -0
- package/docs/manual-setup.md +2 -2
- package/docs/operations.md +12 -13
- package/docs/pull-workers.md +1 -2
- package/docs/service-setup.md +110 -163
- package/docs/setup-reference.md +6 -6
- package/docs/t3-question-relationship.md +43 -0
- package/docs/t3-reverse-control.md +12 -8
- package/docs/t3-wake-fence-r4.md +42 -0
- package/docs/test-suite-isolation.md +204 -0
- package/docs/worker-clients.md +6 -4
- package/package.json +5 -3
- package/qualification/README.md +13 -0
- package/qualification/mcp.json +121 -0
- package/qualification/protocol-v0.json +127 -0
- package/scripts/dalan-try-selfcheck.mjs +8 -7
- package/scripts/worker-bridge-setup.mjs +91 -81
- package/src/admin-socket.mjs +2 -1
- package/src/answer-journal.mjs +200 -0
- package/src/as-store.mjs +5 -3
- package/src/as.mjs +35 -26
- package/src/auth-check.mjs +59 -0
- package/src/cli-help.mjs +16 -16
- package/src/client-approval.mjs +57 -0
- package/src/client-convenience.mjs +166 -0
- package/src/client-conveniences.json +106 -0
- package/src/client-conveniences.schema.json +97 -0
- package/src/connect-cli.mjs +5 -5
- package/src/default-home.mjs +36 -0
- package/src/destinations/index.mjs +6 -0
- package/src/destinations/none.mjs +3 -0
- package/src/destinations/t3.mjs +63 -6
- package/src/execution.mjs +20 -2
- package/src/follow-current.mjs +27 -0
- package/src/gozar-routes.mjs +315 -0
- package/src/host-budget.mjs +17 -11
- package/src/host-execution-policy.mjs +2 -2
- package/src/host-stop-reverify.mjs +6 -4
- package/src/integrator.mjs +3 -1
- package/src/redirect-policy.mjs +61 -0
- package/src/route-setting.mjs +71 -12
- package/src/server.mjs +64 -12
- package/src/service-auto-update.mjs +8 -1
- package/src/service-launchd.mjs +186 -0
- package/src/service-migrate-workers.mjs +12 -2
- package/src/service-update-runtime.mjs +40 -6
- package/src/service-update.mjs +20 -14
- package/src/service.mjs +211 -63
- package/src/setup.mjs +55 -44
- package/src/store.mjs +77 -14
- package/src/submission-policy.mjs +8 -4
- package/src/t3.mjs +21 -2
- package/src/tool-registry.mjs +54 -8
- package/src/try-exposure.mjs +7 -657
- package/src/try-hosted.mjs +71 -101
- package/src/try-selfcheck.mjs +15 -8
- package/src/try.mjs +9 -13
- package/src/workers.mjs +4 -3
- package/src/workspace.mjs +94 -15
- package/scripts/lib/expose-tailscale.mjs +0 -408
- package/src/try-hosted-clients.mjs +0 -46
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schema_version": 1,
|
|
3
|
+
"record_kind": "draft_internal_qualification_record_not_wire_protocol",
|
|
4
|
+
"adapter_id": "protocol-v0",
|
|
5
|
+
"observed_on": "2026-11-15",
|
|
6
|
+
"pins": {
|
|
7
|
+
"dalan_commit": "cf23cceed3ada4ffda321966f616a55b1696e447",
|
|
8
|
+
"requester_ref": "private admin HTTP",
|
|
9
|
+
"worker_host_ref": "local OAuth protocol fixture; not a live hosted worker",
|
|
10
|
+
"protocol": "protocol-v0",
|
|
11
|
+
"sdk": null,
|
|
12
|
+
"catalog_fingerprint": "a7dff975bf96b3cb6fb0436ae3c597db5543e6cb4cca5b9874f551f2e88f0b12"
|
|
13
|
+
},
|
|
14
|
+
"roles": [
|
|
15
|
+
"worker"
|
|
16
|
+
],
|
|
17
|
+
"continuity": "unknown",
|
|
18
|
+
"activation": "unknown",
|
|
19
|
+
"capabilities": [
|
|
20
|
+
{
|
|
21
|
+
"name": "private_loopback",
|
|
22
|
+
"declared": "unknown",
|
|
23
|
+
"observed": "not_tested",
|
|
24
|
+
"required": false
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"name": "host_loopback_denied",
|
|
28
|
+
"declared": "unknown",
|
|
29
|
+
"observed": "not_tested",
|
|
30
|
+
"required": false
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"name": "lan_denied",
|
|
34
|
+
"declared": "unknown",
|
|
35
|
+
"observed": "not_tested",
|
|
36
|
+
"required": false
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"name": "unix_sockets_denied",
|
|
40
|
+
"declared": "unknown",
|
|
41
|
+
"observed": "not_tested",
|
|
42
|
+
"required": false
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"name": "credential_services_denied",
|
|
46
|
+
"declared": "unknown",
|
|
47
|
+
"observed": "not_tested",
|
|
48
|
+
"required": false
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"name": "closed_inherited_fds",
|
|
52
|
+
"declared": "unknown",
|
|
53
|
+
"observed": "not_tested",
|
|
54
|
+
"required": false
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"name": "read_scope_enforced",
|
|
58
|
+
"declared": "unknown",
|
|
59
|
+
"observed": "not_tested",
|
|
60
|
+
"required": false
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"name": "write_scope_enforced",
|
|
64
|
+
"declared": "unknown",
|
|
65
|
+
"observed": "not_tested",
|
|
66
|
+
"required": false
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"name": "full_tree_cancel_verified",
|
|
70
|
+
"declared": "unknown",
|
|
71
|
+
"observed": "not_tested",
|
|
72
|
+
"required": false
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"name": "offline_transition_revokes_connections",
|
|
76
|
+
"declared": "unknown",
|
|
77
|
+
"observed": "not_tested",
|
|
78
|
+
"required": false
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"name": "artifact_export_no_follow",
|
|
82
|
+
"declared": "unknown",
|
|
83
|
+
"observed": "not_tested",
|
|
84
|
+
"required": false
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"name": "runner_observed_evidence",
|
|
88
|
+
"declared": "unknown",
|
|
89
|
+
"observed": "not_tested",
|
|
90
|
+
"required": false
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"name": "native_darwin_execution",
|
|
94
|
+
"declared": "unknown",
|
|
95
|
+
"observed": "not_tested",
|
|
96
|
+
"required": false
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"name": "immutable_input_snapshot",
|
|
100
|
+
"declared": "unknown",
|
|
101
|
+
"observed": "not_tested",
|
|
102
|
+
"required": false
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
"name": "identified_questions",
|
|
106
|
+
"declared": "yes",
|
|
107
|
+
"observed": "passed",
|
|
108
|
+
"required": false,
|
|
109
|
+
"evidence_refs": [
|
|
110
|
+
"scripts/question-lifecycle-http-e2e.mjs"
|
|
111
|
+
]
|
|
112
|
+
}
|
|
113
|
+
],
|
|
114
|
+
"qualification": {
|
|
115
|
+
"state": "passed_for_declared_scope",
|
|
116
|
+
"evidence_level": "actual_store_integration",
|
|
117
|
+
"run_refs": [
|
|
118
|
+
"scripts/question-lifecycle-http-e2e.mjs",
|
|
119
|
+
"scripts/pull-catalog-hash-test.mjs"
|
|
120
|
+
]
|
|
121
|
+
},
|
|
122
|
+
"limits": [
|
|
123
|
+
"No live hosted-worker qualification.",
|
|
124
|
+
"No native session continuity or activation guarantee.",
|
|
125
|
+
"Sandbox capabilities remain unknown; host execution keeps its separate backend admission."
|
|
126
|
+
]
|
|
127
|
+
}
|
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// Run against a live `dalan try --public` trial before adding the connector in
|
|
3
|
-
// node scripts/dalan-try-selfcheck.mjs --home <trial home> [--
|
|
2
|
+
// Run against a live `dalan try --public` trial before adding the connector in an MCP client:
|
|
3
|
+
// node scripts/dalan-try-selfcheck.mjs --home <trial home> [--redirect HTTPS_URI] [--wait 300]
|
|
4
4
|
// The trial's authorization server must be on its public origin: a constraint of the trial, not of OAuth.
|
|
5
5
|
// It acts as a real OAuth client and waits for you to approve the connection (y) in the trial terminal.
|
|
6
6
|
import fs from 'node:fs';
|
|
7
7
|
import path from 'node:path';
|
|
8
|
-
import {
|
|
8
|
+
import { validateRedirectUri } from '../src/redirect-policy.mjs';
|
|
9
|
+
import { runSelfCheck, SELFCHECK_REDIRECT } from '../src/try-selfcheck.mjs';
|
|
9
10
|
|
|
10
11
|
const args = process.argv.slice(2);
|
|
11
12
|
const option = name => { const i = args.indexOf(name); return i >= 0 ? args[i + 1] : undefined; };
|
|
12
|
-
const home = option('--home'),
|
|
13
|
+
const home = option('--home'), redirect = option('--redirect') ?? SELFCHECK_REDIRECT, wait = Number(option('--wait') ?? 300);
|
|
13
14
|
let url = process.env.DALAN_TRY_URL;
|
|
14
15
|
if (!url && home) { try { url = fs.readFileSync(path.join(home, 'resource-url'), 'utf8').trim(); } catch { /* reported below */ } }
|
|
15
|
-
if (!url || !
|
|
16
|
-
process.stderr.write('usage: node scripts/dalan-try-selfcheck.mjs --home <trial home> [--
|
|
16
|
+
if (!url || !validateRedirectUri(redirect).ok) {
|
|
17
|
+
process.stderr.write('usage: node scripts/dalan-try-selfcheck.mjs --home <trial home> [--redirect HTTPS_URI] [--wait seconds]\n(or set DALAN_TRY_URL to the trial\'s MCP URL; it is a credential, so it is never taken from an argument)\n');
|
|
17
18
|
process.exit(2);
|
|
18
19
|
}
|
|
19
20
|
const controller = new AbortController();
|
|
20
21
|
process.once('SIGINT', () => controller.abort());
|
|
21
22
|
process.once('SIGTERM', () => controller.abort());
|
|
22
23
|
try {
|
|
23
|
-
const { ok } = await runSelfCheck({ url,
|
|
24
|
+
const { ok } = await runSelfCheck({ url, redirect, approveWaitMs: wait * 1000, signal: controller.signal, say: line => process.stdout.write(`${line}\n`) });
|
|
24
25
|
process.exit(ok ? 0 : 1);
|
|
25
26
|
} catch {
|
|
26
27
|
// The error text can hold the credential URL, so none of it is printed.
|
|
@@ -15,10 +15,59 @@ import { fileURLToPath } from 'node:url';
|
|
|
15
15
|
import { parseArgs } from './live-trial/common.mjs';
|
|
16
16
|
import { loadKeys } from '../src/as-files.mjs';
|
|
17
17
|
import { writeWorkerInstructions } from '../src/worker-instructions.mjs';
|
|
18
|
-
|
|
19
|
-
import
|
|
18
|
+
import https from 'node:https';
|
|
19
|
+
import { Resolver } from 'node:dns/promises';
|
|
20
|
+
import { buildQuery, ensureDurableRoute, gozarHomeFor, resolveGozar, describeCandidate, describeDisclosure } from '../src/gozar-routes.mjs';
|
|
21
|
+
|
|
22
|
+
// ---- checking the public address ---------------------------------------------------------------------------------------------------
|
|
23
|
+
// Public DNS through three resolvers in parallel (one can keep a negative-cached NXDOMAIN for a new name for >10 min).
|
|
24
|
+
const PUBLIC_DNS_SERVERS = ['1.1.1.1', '8.8.8.8', '9.9.9.9'];
|
|
25
|
+
const DNS_WAIT_MS = 600_000, DNS_PROGRESS_MS = 30_000, HTTPS_WAIT_MS = 120_000;
|
|
26
|
+
function makePublicResolver(resolvers = PUBLIC_DNS_SERVERS.map(server => { const resolver = new Resolver({ timeout: 3000, tries: 1 }); resolver.setServers([server]); return { server, resolver }; })) {
|
|
27
|
+
return name => new Promise(resolve => {
|
|
28
|
+
let pending = resolvers.length;
|
|
29
|
+
const settle = () => { if (--pending === 0) resolve(null); };
|
|
30
|
+
for (const { server, resolver } of resolvers) resolver.resolve4(name).then(addresses => (addresses[0] ? resolve({ address: addresses[0], server }) : settle()), settle);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
// GET /admin pinned to the address DNS returned. The bridge answers 404 on its unauthenticated path.
|
|
34
|
+
function fetchPinned(url, address, { timeoutMs = 15_000 } = {}) {
|
|
35
|
+
const u = new URL(url);
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
const req = https.request({ hostname: u.hostname, port: u.port || 443, path: '/admin', method: 'GET', timeout: timeoutMs,
|
|
38
|
+
lookup: (_host, options, cb) => (options?.all ? cb(null, [{ address, family: 4 }]) : cb(null, address, 4)) }, res => { res.resume(); resolve(res.statusCode); });
|
|
39
|
+
req.on('timeout', () => req.destroy(new Error('timeout')));
|
|
40
|
+
req.on('error', reject);
|
|
41
|
+
req.end();
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
export async function verifyPublic({ url, dnsName, resolve4, request = fetchPinned, sleep = ms => new Promise(r => setTimeout(r, ms)), now = Date.now, timeoutMs = DNS_WAIT_MS, intervalMs = 5_000, progressMs = DNS_PROGRESS_MS, log = console.log }) {
|
|
45
|
+
const secs = ms => Math.round(ms / 1000);
|
|
46
|
+
const start = now(), end = start + timeoutMs;
|
|
47
|
+
let nextProgress = progressMs, found = null;
|
|
48
|
+
while (!found) {
|
|
49
|
+
found = await resolve4(dnsName);
|
|
50
|
+
if (found) break;
|
|
51
|
+
const elapsed = now() - start;
|
|
52
|
+
if (elapsed >= nextProgress && elapsed < timeoutMs) { log(`waiting for public DNS of ${dnsName} … ${secs(elapsed)} s / ${secs(timeoutMs)} s`); nextProgress += progressMs; }
|
|
53
|
+
if (now() >= end) break;
|
|
54
|
+
await sleep(intervalMs);
|
|
55
|
+
}
|
|
56
|
+
if (!found) { log(`FAIL public DNS: no A record for ${dnsName} from 1.1.1.1, 8.8.8.8 or 9.9.9.9 after ${secs(timeoutMs)} s. Next: run \`dig @8.8.8.8 ${dnsName} A\` (also try @1.1.1.1 and @9.9.9.9), check the route's state with Gozar, then retry.`); return false; }
|
|
57
|
+
log(`PASS public DNS: ${dnsName} -> ${found.address} (via ${found.server})`);
|
|
58
|
+
const httpsEnd = now() + HTTPS_WAIT_MS;
|
|
59
|
+
let nextHttpsProgress = now() + progressMs, last;
|
|
60
|
+
for (;;) {
|
|
61
|
+
try { const code = await request(url, found.address); if (code === 404) break; last = `GET /admin returned ${code}, expected 404 from the bridge`; } catch (e) { last = e.message; }
|
|
62
|
+
if (now() >= httpsEnd) { log(`FAIL public HTTPS: ${last} (still failing after ${secs(HTTPS_WAIT_MS)} s). Likely cause: the route is not active yet, or a different service answers on this address. Next: check the route's state with Gozar and the local port, then retry.`); return false; }
|
|
63
|
+
if (now() >= nextHttpsProgress) { log(`waiting for public HTTPS of ${dnsName} … last result: ${last}`); nextHttpsProgress += progressMs; }
|
|
64
|
+
await sleep(intervalMs);
|
|
65
|
+
}
|
|
66
|
+
log('PASS public HTTPS: GET /admin returned 404 from the bridge');
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
20
69
|
|
|
21
|
-
const REPO = fileURLToPath(new URL('..', import.meta.url));
|
|
70
|
+
const REPO = path.resolve(fileURLToPath(new URL('..', import.meta.url)));
|
|
22
71
|
const SAFE_PATH = /^[A-Za-z0-9_@+=:,./-]+$/; // no space, quote, %, $ or newline: the value goes into a unit or plist as is
|
|
23
72
|
const PROXYD = ['/usr/lib/systemd/systemd-socket-proxyd', '/lib/systemd/systemd-socket-proxyd'];
|
|
24
73
|
const MARKER = 'Generated by scripts/worker-bridge-setup.mjs'; // --remove only deletes files that carry this text
|
|
@@ -46,7 +95,7 @@ function stableNode(execPath) {
|
|
|
46
95
|
|
|
47
96
|
function parseOptions(argv, platform) {
|
|
48
97
|
const args = parseArgs(argv, {
|
|
49
|
-
values: ['--worker', '--public-url', '--port', '--home', '--lan-forward', '--
|
|
98
|
+
values: ['--worker', '--public-url', '--port', '--home', '--lan-forward', '--route'],
|
|
50
99
|
flags: ['--persistent', '--write-units-only', '--no-repo-tools', '--start', '--help', '--remove', '--purge-home', '--retry-public-check', '--repoint'],
|
|
51
100
|
});
|
|
52
101
|
if (args._.length) fail(`unexpected argument ${args._[0]}`);
|
|
@@ -56,7 +105,7 @@ function parseOptions(argv, platform) {
|
|
|
56
105
|
const home = path.resolve(args['--home'] ?? path.join(os.homedir(), '.local/share/dbm'));
|
|
57
106
|
if (args['--retry-public-check'] && args['--remove']) fail('--retry-public-check cannot be combined with --remove');
|
|
58
107
|
if (args['--repoint']) {
|
|
59
|
-
const others = ['--remove', '--retry-public-check', '--start', '--write-units-only', '--public-url', '--port', '--home', '--lan-forward', '--
|
|
108
|
+
const others = ['--remove', '--retry-public-check', '--start', '--write-units-only', '--public-url', '--port', '--home', '--lan-forward', '--route', '--purge-home', '--no-repo-tools', '--persistent'].filter(flag => args[flag] !== undefined && args[flag] !== false);
|
|
60
109
|
if (others.length) fail(`--repoint takes only --worker; remove ${others.join(' ')}`);
|
|
61
110
|
const repo = REPO.replace(/\/$/, '');
|
|
62
111
|
if (!SAFE_PATH.test(repo)) fail(`repo path contains a character that is not safe in a unit file: ${JSON.stringify(repo)}`);
|
|
@@ -64,23 +113,16 @@ function parseOptions(argv, platform) {
|
|
|
64
113
|
}
|
|
65
114
|
if (args['--remove']) {
|
|
66
115
|
// Users rerun their install command with --remove appended, so install-only flags are ignored, not refused.
|
|
67
|
-
const ignored = ['--public-url', '--port', '--lan-forward', '--write-units-only', '--start', '--no-repo-tools', '--
|
|
116
|
+
const ignored = ['--public-url', '--port', '--lan-forward', '--write-units-only', '--start', '--no-repo-tools', '--route'].filter(flag => args[flag] !== undefined && args[flag] !== false);
|
|
68
117
|
if (ignored.length) console.error(`worker-bridge-setup: ignoring install-only flags with --remove: ${ignored.join(' ')}`);
|
|
69
118
|
return { remove: true, worker, home, purge: !!args['--purge-home'] };
|
|
70
119
|
}
|
|
71
120
|
if (args['--purge-home']) fail('--purge-home is only valid with --remove');
|
|
72
|
-
const
|
|
73
|
-
if (
|
|
74
|
-
if (
|
|
75
|
-
if (args['--
|
|
76
|
-
|
|
77
|
-
if (mode === 'ngrok' && args['--ngrok-domain'] === undefined) fail('--expose ngrok needs --ngrok-domain <assigned-domain> (the static domain from your ngrok dashboard)');
|
|
78
|
-
const ngrokDomain = args['--ngrok-domain'];
|
|
79
|
-
if (ngrokDomain !== undefined && !/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)+$/.test(ngrokDomain)) fail('--ngrok-domain must be a bare host name such as your-name.ngrok-free.app (no https:// and no path)');
|
|
80
|
-
if (mode && args['--public-url'] !== undefined) fail(`--public-url is derived with --expose ${mode}; do not pass both`);
|
|
81
|
-
const funnelPort = args['--funnel-port'] === undefined ? undefined : Number(args['--funnel-port']);
|
|
82
|
-
if (funnelPort !== undefined && (!Number.isInteger(funnelPort) || funnelPort < 1 || funnelPort > 65535)) fail('--funnel-port must be a port number');
|
|
83
|
-
const publicUrl = mode ? null : parsePublicUrl(args['--public-url']);
|
|
121
|
+
const route = args['--route'];
|
|
122
|
+
if (route !== undefined && (!route || route.startsWith('-'))) fail('--route needs the name of a Gozar route');
|
|
123
|
+
if (args['--retry-public-check'] && (route || args['--start'] || args['--write-units-only'] || args['--remove'])) fail('--retry-public-check takes --public-url and checks an existing service; omit --route, --start, --write-units-only and --remove');
|
|
124
|
+
if (route !== undefined && args['--public-url'] !== undefined) fail('--public-url comes from the Gozar route with --route; do not pass both');
|
|
125
|
+
const publicUrl = route !== undefined ? null : parsePublicUrl(args['--public-url']);
|
|
84
126
|
const port = Number(args['--port']);
|
|
85
127
|
if (!Number.isInteger(port) || port < 1024 || port > 65535) fail('--port N is required (1024-65535)');
|
|
86
128
|
const node = stableNode(process.execPath);
|
|
@@ -104,7 +146,7 @@ function parseOptions(argv, platform) {
|
|
|
104
146
|
return {
|
|
105
147
|
worker, publicUrl, port, home, socketPath, node, repo, lan, writeUnitsOnly: !!args['--write-units-only'], start: !!args['--start'],
|
|
106
148
|
repoTools: !args['--no-repo-tools'], retryPublicCheck: !!args['--retry-public-check'],
|
|
107
|
-
|
|
149
|
+
route,
|
|
108
150
|
};
|
|
109
151
|
}
|
|
110
152
|
|
|
@@ -712,17 +754,6 @@ function verifyRetryTarget(o, { platform, env }) {
|
|
|
712
754
|
if(saved.origin!==o.publicUrl||saved.pathname!==`/${saved.pathname.split('/')[1]}/mcp`||!/^\/[a-f0-9]{64}\/mcp$/.test(saved.pathname)) fail('--retry-public-check refused: --public-url does not match this home resource URL');
|
|
713
755
|
if(saved.pathname!==`/${secretMatch[1]}/mcp`) fail('--retry-public-check refused: the saved resource URL does not match this home path secret');
|
|
714
756
|
if(as.public_url!==o.publicUrl) fail('--retry-public-check refused: --public-url does not match this home issuer');
|
|
715
|
-
const exposureFile=expose.recordPath(o.home,o.worker);
|
|
716
|
-
const exposure=JSON.parse(readOwnedFile(o.home,exposureFile,'exposure record'));
|
|
717
|
-
const publicPort=Number(new URL(o.publicUrl).port||443);
|
|
718
|
-
if(exposure.worker!==o.worker||exposure.public_url!==o.publicUrl||exposure.local_port!==o.port) fail('--retry-public-check refused: --public-url or --port does not match this worker exposure record');
|
|
719
|
-
if (exposure.mode === 'tailscale') {
|
|
720
|
-
if(exposure.dns_name!==saved.hostname||exposure.public_port!==publicPort) fail('--retry-public-check refused: --public-url or --port does not match this worker exposure record');
|
|
721
|
-
} else if (exposure.mode === 'ngrok') {
|
|
722
|
-
const configFile=expose.ngrokConfigPath(o.home,o.worker);
|
|
723
|
-
const config=readOwnedFile(o.home,configFile,'ngrok config');
|
|
724
|
-
if(exposure.domain!==saved.hostname||exposure.ngrok_config!==configFile||config!==expose.ngrokConfigText({worker:o.worker,domain:exposure.domain,localPort:o.port})) fail('--retry-public-check refused: ngrok domain or config does not match this worker exposure record');
|
|
725
|
-
} else fail('--retry-public-check refused: exposure record has an unsupported mode');
|
|
726
757
|
const dir=unitDirFor(platform,env), unit=platform==='darwin'?path.join(dir,`${launchLabel(o.worker)}.plist`):path.join(dir,`dot-bridge-${o.worker}.service`);
|
|
727
758
|
const configRoot=platform==='darwin'?(env.HOME||os.homedir()):(env.XDG_CONFIG_HOME&&path.isAbsolute(env.XDG_CONFIG_HOME)?env.XDG_CONFIG_HOME:path.join(os.homedir(),'.config'));
|
|
728
759
|
assertOwnedPath(configRoot,dir,'directory','service unit directory');
|
|
@@ -760,22 +791,19 @@ function waitForStartedBridge(o, env, platform, waitForSocket) {
|
|
|
760
791
|
fail(`the service was started but the bridge did not answer on its admin socket ${o.socketPath} within ${Math.round(budget / 1000)} s. Read the service log with ${where}. Generated state is left in place; remove this install with: ${recoveryCommand(o)}`);
|
|
761
792
|
}
|
|
762
793
|
|
|
763
|
-
function runUnlocked(argv, { platform = process.platform, env = process.env, log = console.log, verifyPublic =
|
|
794
|
+
function runUnlocked(argv, { platform = process.platform, env = process.env, log = console.log, verifyPublic: verify = verifyPublic, resolve4 = makePublicResolver(), initHome, spawn = spawnSync, waitForSocket = waitForAdminSocket, holderProbe } = {}, parsed = null) {
|
|
764
795
|
const o = parsed ?? parseOptions(argv, platform);
|
|
765
796
|
if (o.help) {
|
|
766
797
|
log('usage: node scripts/worker-bridge-setup.mjs --worker NAME --public-url https://HOST --port N [--home DIR] [--lan-forward ADDR:PORT] [--write-units-only] [--start] [--no-repo-tools]');
|
|
767
|
-
log(' or: node scripts/worker-bridge-setup.mjs --worker NAME --port N --
|
|
768
|
-
log(' or: node scripts/worker-bridge-setup.mjs --worker NAME --port N --expose ngrok --ngrok-domain ASSIGNED-DOMAIN [--start]');
|
|
798
|
+
log(' or: node scripts/worker-bridge-setup.mjs --worker NAME --port N --route GOZAR-ROUTE-NAME [--start]');
|
|
769
799
|
log(' node scripts/worker-bridge-setup.mjs --retry-public-check --worker NAME --public-url https://HOST --port N [--home DIR]');
|
|
770
800
|
log(' node scripts/worker-bridge-setup.mjs --repoint --worker NAME (point an existing service at this copy of the code)');
|
|
771
|
-
log(' node scripts/worker-bridge-setup.mjs --remove --worker NAME [--home DIR] [--purge-home]
|
|
801
|
+
log(' node scripts/worker-bridge-setup.mjs --remove --worker NAME [--home DIR] [--purge-home]');
|
|
772
802
|
return;
|
|
773
803
|
}
|
|
774
804
|
if (o.repoint) return repointUnit(o, { platform, env, log });
|
|
775
805
|
if (o.remove) {
|
|
776
|
-
//
|
|
777
|
-
const record = expose.recordPath(o.home, o.worker);
|
|
778
|
-
if (fs.existsSync(record)) expose.removeExposure({ file: record, log, ...(tailscale ? { tailscale } : {}) });
|
|
806
|
+
// A durable Gozar route is the owner's; removing a worker never closes it.
|
|
779
807
|
return removeUnit(o, { platform, env, log, spawn, ...(holderProbe ? { holderProbe } : {}) });
|
|
780
808
|
}
|
|
781
809
|
const linux = platform === 'linux', darwin = platform === 'darwin';
|
|
@@ -786,13 +814,8 @@ function runUnlocked(argv, { platform = process.platform, env = process.env, log
|
|
|
786
814
|
if(o.retryPublicCheck) {
|
|
787
815
|
const {url,dnsName}=verifyRetryTarget(o,{platform,env});
|
|
788
816
|
if(readEnv('DALAN_EXPOSE_SKIP_PUBLIC_CHECK',env)==='1') { log('SKIPPED public check (DALAN_EXPOSE_SKIP_PUBLIC_CHECK=1; tests only)'); return; }
|
|
789
|
-
|
|
790
|
-
const retryRecord=JSON.parse(readOwnedFile(o.home,exposureFile,'exposure record'));
|
|
791
|
-
if(retryRecord.mode==='ngrok') expose.updateExposureState(exposureFile,'unverified');
|
|
792
|
-
return verifyPublic({url,dnsName,resolve4,log}).then(ok=>{
|
|
817
|
+
return verify({url,dnsName,resolve4,log}).then(ok=>{
|
|
793
818
|
if(!ok) fail(`public verification failed; the service, home and keys were left in place. Retry after the public route is ready with: ${publicRetryCommand(o,url)}. To remove this install: ${recoveryCommand(o)}`);
|
|
794
|
-
const record=JSON.parse(readOwnedFile(o.home,exposureFile,'exposure record'));
|
|
795
|
-
if(record.mode==='ngrok') expose.updateExposureState(exposureFile,'verified');
|
|
796
819
|
});
|
|
797
820
|
}
|
|
798
821
|
|
|
@@ -805,19 +828,8 @@ function runUnlocked(argv, { platform = process.platform, env = process.env, log
|
|
|
805
828
|
}
|
|
806
829
|
if (unitDir) for (const f of Object.keys(files)) if (fs.existsSync(path.join(unitDir, f))) fail(`${path.join(unitDir, f)} already exists; refusing to overwrite it`);
|
|
807
830
|
if (darwin && !lintPlist(files[`${launchLabel(o.worker)}.plist`], env)) log('plutil not found: skipped the plist lint');
|
|
808
|
-
// --
|
|
809
|
-
|
|
810
|
-
if (o.expose?.mode === 'tailscale') {
|
|
811
|
-
const pf = preflight({ platform });
|
|
812
|
-
for (const w of pf.warnings) log(`WARN ${w}`);
|
|
813
|
-
const port = expose.choosePort({ requested: o.expose.funnelPort, allowed: pf.allowed, occupied: pf.occupied });
|
|
814
|
-
o.publicUrl = expose.publicUrl(pf.dnsName, port);
|
|
815
|
-
exposure = { mode: 'tailscale', dnsName: pf.dnsName, port, url: o.publicUrl, file: expose.recordPath(o.home, o.worker) };
|
|
816
|
-
} else if (o.expose?.mode === 'ngrok') {
|
|
817
|
-
// Nothing is run here. The URL is derived from the assigned domain; the config and commands come after the units.
|
|
818
|
-
o.publicUrl = `https://${o.expose.domain}`;
|
|
819
|
-
exposure = { mode: 'ngrok', domain: o.expose.domain, url: o.publicUrl, file: expose.recordPath(o.home, o.worker) };
|
|
820
|
-
}
|
|
831
|
+
// --route: Gozar allocated or adopted the route before this point (see run()); only the public address is used here.
|
|
832
|
+
const exposure = o.route !== undefined ? { route: o.route, url: o.publicUrl, dnsName: new URL(o.publicUrl).hostname } : null;
|
|
821
833
|
|
|
822
834
|
if (o.start) checkStartReadiness(platform, env);
|
|
823
835
|
if (o.start) warnIfLingeringDisabled(platform, env, log, spawn);
|
|
@@ -853,26 +865,7 @@ function runUnlocked(argv, { platform = process.platform, env = process.env, log
|
|
|
853
865
|
log(`To stop: ${stop}`);
|
|
854
866
|
} else log(`Not started. To start:\n launchctl bootstrap ${domain} ${plist}\nTo stop:\n ${stop}`);
|
|
855
867
|
}
|
|
856
|
-
|
|
857
|
-
if (exposure?.mode === 'tailscale') {
|
|
858
|
-
try { expose.writeExposureRecord({ file: exposure.file, worker: o.worker, dnsName: exposure.dnsName, port: exposure.port, localPort: o.port, url: exposure.url }); }
|
|
859
|
-
catch (error) { throw new Error(`${error.message}. Generated state is left in place; remove this install with: ${recoveryCommand(o)}`); }
|
|
860
|
-
try {
|
|
861
|
-
applyFunnel({ dnsName: exposure.dnsName, port: exposure.port, localPort: o.port });
|
|
862
|
-
expose.updateExposureState(exposure.file, 'active');
|
|
863
|
-
} catch (error) {
|
|
864
|
-
throw new Error(`${error.message}. Funnel intent is recorded; remove this exact owned rule and install with: ${recoveryCommand(o)}`);
|
|
865
|
-
}
|
|
866
|
-
log(`Funnel: ${exposure.url} -> http://127.0.0.1:${o.port} (tailscale funnel --https=${exposure.port}); record ${exposure.file}`);
|
|
867
|
-
} else if (exposure?.mode === 'ngrok') {
|
|
868
|
-
let configFile;
|
|
869
|
-
try { configFile = expose.writeNgrokExposure({ home: o.home, worker: o.worker, domain: exposure.domain, localPort: o.port, file: exposure.file }); }
|
|
870
|
-
catch (error) { throw new Error(`${error.message}. Generated state is left in place; remove this install with: ${recoveryCommand(o)}`); }
|
|
871
|
-
log(`ngrok config: ${configFile} (mode 0600, no authtoken in it); record ${exposure.file}`);
|
|
872
|
-
log(`Public URL: ${exposure.url} -> http://127.0.0.1:${o.port}. ngrok was NOT run. Run these yourself:`);
|
|
873
|
-
for (const c of expose.ngrokCommands(configFile)) log(` ${c}`);
|
|
874
|
-
log(`QUOTA WARNING: ${expose.NGROK_QUOTA_WARNING}`);
|
|
875
|
-
}
|
|
868
|
+
if (exposure) log(`Route: ${exposure.url} -> http://127.0.0.1:${o.port} (Gozar route ${exposure.route})`);
|
|
876
869
|
if (o.lan) log(`LAN forwarder: ${o.lan.address}:${o.lan.port} -> 127.0.0.1:${o.port}. Point the reverse proxy there; anything on that network can reach it.`);
|
|
877
870
|
log(`Resource URL file (private, mode 0600): ${urlFile}`);
|
|
878
871
|
const dw = `dalan() { HOME=${shellQuote(o.home)} ${shellQuote(o.node)} ${shellQuote(path.join(o.repo, 'bin/dalan.mjs'))} "$@"; }`;
|
|
@@ -883,10 +876,6 @@ function runUnlocked(argv, { platform = process.platform, env = process.env, log
|
|
|
883
876
|
log(` dalan connect approve CODE --worker ${o.worker}`);
|
|
884
877
|
log(' dalan connect signal-token # save wake URL privately for hook-driven workers; print path; --rotate replaces it');
|
|
885
878
|
if (!exposure) return undefined;
|
|
886
|
-
if (exposure.mode === 'ngrok') {
|
|
887
|
-
log(`Public status: unverified until the ngrok service is started and --retry-public-check succeeds. ngrok was not started. After starting it, verify with: ${publicRetryCommand(o, exposure.url)}`);
|
|
888
|
-
return undefined;
|
|
889
|
-
}
|
|
890
879
|
// Public check only after the bridge starts. Returns a promise; the entry point awaits it and exits 1 on failure.
|
|
891
880
|
const { dnsName, url } = exposure;
|
|
892
881
|
if (!o.start) {
|
|
@@ -894,15 +883,36 @@ function runUnlocked(argv, { platform = process.platform, env = process.env, log
|
|
|
894
883
|
return undefined;
|
|
895
884
|
}
|
|
896
885
|
if (readEnv('DALAN_EXPOSE_SKIP_PUBLIC_CHECK',env) === '1') { log('SKIPPED public check (DALAN_EXPOSE_SKIP_PUBLIC_CHECK=1; tests only)'); return undefined; }
|
|
897
|
-
return
|
|
886
|
+
return verify({ url, dnsName, resolve4, log }).then(ok => {
|
|
898
887
|
if (!ok) fail(`public verification failed; the service, home and keys were left in place. Retry the check with: ${publicRetryCommand(o,url)}. To remove this install: ${recoveryCommand(o)}`);
|
|
899
888
|
});
|
|
900
889
|
}
|
|
901
890
|
|
|
891
|
+
// With --route, Gozar allocates (or finds) the durable route first; its origin is the bridge's public address. Nothing is written
|
|
892
|
+
// before Gozar answers, and an owner who declines leaves nothing behind.
|
|
893
|
+
async function allocateRoute(parsed, seams) {
|
|
894
|
+
const env = seams.env ?? process.env;
|
|
895
|
+
const gozar = seams.gozar ?? await resolveGozar();
|
|
896
|
+
const query = buildQuery({ home: gozarHomeFor(env), target: `127.0.0.1:${parsed.port}`, route: parsed.route, address: 'stable', usage: { kind: 'durable', routeId: `dalan-${parsed.worker}` } });
|
|
897
|
+
const consent = seams.consent ?? (async candidate => {
|
|
898
|
+
if (!process.stdin.isTTY) fail('this route needs your approval; run this in a terminal, or run `dalan setup --route NAME` first');
|
|
899
|
+
for (const line of [...describeCandidate(candidate), ...describeDisclosure(candidate)]) console.log(line);
|
|
900
|
+
const rl = (await import('node:readline')).createInterface({ input: process.stdin, output: process.stdout });
|
|
901
|
+
const answer = await new Promise(resolve => rl.question('Use this route? [y/N] ', resolve)); rl.close();
|
|
902
|
+
return ['y', 'yes'].includes(answer.trim().toLowerCase());
|
|
903
|
+
});
|
|
904
|
+
parsed.publicUrl = (await ensureDurableRoute({ gozar, query, consent })).origin;
|
|
905
|
+
}
|
|
906
|
+
|
|
902
907
|
export function run(argv, seams = {}) {
|
|
903
908
|
if (argv.includes('--help')) return runUnlocked(argv, seams);
|
|
904
909
|
// Reject malformed arguments before creating the per-home lock directory.
|
|
905
910
|
const parsed = parseOptions(argv, seams.platform ?? process.platform);
|
|
911
|
+
if (parsed.route !== undefined) return allocateRoute(parsed, seams).then(() => runLocked(argv, seams, parsed));
|
|
912
|
+
return runLocked(argv, seams, parsed);
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
function runLocked(argv, seams, parsed) {
|
|
906
916
|
// The lock is per user and host-wide by default, so installers with different HOME values still serialize on one unit directory.
|
|
907
917
|
// DALAN_SETUP_LOCK_DIR (an absolute path) moves it, for example so concurrent test runs do not collide.
|
|
908
918
|
const envRoot = (seams.env ?? process.env).DALAN_SETUP_LOCK_DIR;
|
package/src/admin-socket.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// The bridge's admin socket lives in the bridge home. A Unix socket path has a fixed size limit (108 bytes on Linux and
|
|
2
2
|
// 104 on macOS, including the terminating NUL), so a long bridge home cannot hold it. The server and every client check
|
|
3
3
|
// the path first and say so, in place of the system's bare EINVAL.
|
|
4
|
-
export const
|
|
4
|
+
export const socketPathLimit = platform => platform === 'darwin' ? 103 : 107; // usable bytes, excluding the terminating NUL
|
|
5
|
+
export const SOCKET_PATH_LIMIT = socketPathLimit(process.platform);
|
|
5
6
|
|
|
6
7
|
// Null when the path fits; otherwise the error to report.
|
|
7
8
|
export function adminSocketPathError(socket) {
|