@tnunamak/dalan 0.6.1 → 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.
Files changed (48) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +25 -64
  3. package/bin/dalan.mjs +9 -0
  4. package/bin/dot-worker.mjs +16 -2
  5. package/docs/chatgpt-worker-onboarding.md +10 -14
  6. package/docs/claude-worker-onboarding.md +9 -8
  7. package/docs/codex-to-muse.md +21 -35
  8. package/docs/connect-chatgpt.md +10 -16
  9. package/docs/dalan-upgrade.md +4 -2
  10. package/docs/local-agent-mcp.md +24 -4
  11. package/docs/manual-setup.md +2 -2
  12. package/docs/operations.md +10 -11
  13. package/docs/pull-workers.md +1 -2
  14. package/docs/service-setup.md +99 -145
  15. package/docs/setup-reference.md +5 -5
  16. package/docs/worker-clients.md +4 -4
  17. package/package.json +2 -3
  18. package/scripts/dalan-try-selfcheck.mjs +8 -7
  19. package/scripts/worker-bridge-setup.mjs +91 -81
  20. package/src/as-store.mjs +5 -3
  21. package/src/as.mjs +35 -26
  22. package/src/auth-check.mjs +53 -0
  23. package/src/cli-help.mjs +20 -15
  24. package/src/client-approval.mjs +57 -0
  25. package/src/client-convenience.mjs +166 -0
  26. package/src/client-conveniences.json +106 -0
  27. package/src/client-conveniences.schema.json +97 -0
  28. package/src/connect-cli.mjs +5 -5
  29. package/src/default-home.mjs +36 -0
  30. package/src/follow-current.mjs +25 -0
  31. package/src/gozar-routes.mjs +314 -0
  32. package/src/redirect-policy.mjs +61 -0
  33. package/src/route-setting.mjs +71 -12
  34. package/src/server.mjs +38 -2
  35. package/src/service-auto-update.mjs +68 -0
  36. package/src/service-launchd.mjs +166 -0
  37. package/src/service-update-gate.mjs +20 -0
  38. package/src/service-update-lock.mjs +22 -0
  39. package/src/service-update-runtime.mjs +290 -0
  40. package/src/service-update.mjs +399 -0
  41. package/src/service.mjs +241 -58
  42. package/src/setup.mjs +55 -44
  43. package/src/try-exposure.mjs +7 -657
  44. package/src/try-hosted.mjs +71 -101
  45. package/src/try-selfcheck.mjs +15 -8
  46. package/src/try.mjs +9 -13
  47. package/scripts/lib/expose-tailscale.mjs +0 -408
  48. package/src/try-hosted-clients.mjs +0 -46
@@ -1,219 +1,173 @@
1
1
  # Run Dalan as a service
2
2
 
3
- Use this guide after a first job works with `dalan try`, when you want a bridge that keeps running or a worker on another computer. Built-in OAuth binds the bridge to `127.0.0.1`; a tunnel or HTTPS reverse proxy forwards worker traffic to that listener. The owner CLI uses a private Unix socket, which must never be exposed through the proxy.
3
+ Install Dalan once to keep your MCP agent connected to your Mac or Linux computer. You do not need to run the trial first.
4
4
 
5
- ## Install one bridge for several workers
5
+ Before you begin, install Node.js 24 or newer and Tailscale with Funnel enabled. Your agent's account must allow custom MCP connectors. The commands below are the same on macOS and Linux.
6
6
 
7
- The Linux-only `dalan service install` creates a systemd user service and registers its HTTPS origin as a Gozar service route. Gozar records and verifies an origin-to-target route that your reverse proxy already serves; it does not edit the proxy. The bridge uses built-in OAuth. Moving a connector to the new URL requires reauthorization and a catalog refresh. All workers use the same stable catalog. The process-wide `legacy-v46` setting remains available for other installations. Its auth keys, worker allowlists and job queue stay in one private home.
7
+ **Tailscale prerequisite.** `--route tailscale` publishes through Tailscale Funnel, which your tailnet administrator must allow (a `funnel` entry in the tailnet access controls; HTTPS and MagicDNS must be on too). If Funnel is not allowed, Dalan stops before it publishes anything and tells you which setup step is missing, or prints Tailscale's own refusal. Enable Funnel once at <https://tailscale.com/kb/1223/funnel>, then run the command again. Other routes need no Tailscale setting; `dalan setup` lists them.
8
8
 
9
- First prepare the public origin so it forwards to the address in `--target`. Preserve the public `Host` header. The bridge rejects requests with another Host, including requests that try to replace it with `X-Forwarded-Host`. The proxy must pass the secret MCP path, the OAuth discovery and authorization paths, `/signal/*` when used, and `/.well-known/gozar/service` with its query string. TLS terminates at the proxy. Keep the secret path out of proxy logs.
9
+ <a id="owner-setup"></a>
10
10
 
11
- For existing installations, create the new home and copy each worker's repository allowlist. Replace the example paths with the old bridge homes on this computer:
11
+ ## Install and connect your agent
12
+
13
+ This example names your worker `assistant`. Choose another lowercase name if you prefer, and use it in every command.
12
14
 
13
15
  ```sh
14
- dalan service migrate-workers \
15
- --home "$HOME/.local/share/dalan-service" \
16
- --source "$HOME/.config/dot-bridge/workers.json" \
17
- --source "$HOME/OLD_BRIDGE_TWO/.config/dot-bridge/workers.json" \
18
- --source "$HOME/OLD_BRIDGE_THREE/.config/dot-bridge/workers.json"
16
+ npm install -g @tnunamak/dalan
17
+ dalan service install --worker assistant --route tailscale
18
+ dalan connect start --worker assistant
19
19
  ```
20
20
 
21
- The helper reads the source files without changing them. If an older home has no `workers.json`, it can read the adjacent `workers-repos.json` migration journal. It preserves worker names and repository allowlists, and copies supported worker capabilities and guidance. It does not copy OAuth registrations, tokens, jobs or results. The new bridge starts with `default_execution: none`. Workspace access defaults to denied; add `--workspace-worker NAME` for each worker that needs an explicit workspace grant. This option records the owner's grant; it does not require an earlier audit record. Existing explicit `workspaceAllowed` and T3 capability settings are retained. Destination declarations are copied, but old destination approvals bind old jobs and connections, so each new job requires a fresh approval.
22
-
23
- Optionally pass `--source-db PATH` for each old job database. The helper opens it read-only and writes a private `service-migration.json` checklist containing active subscription counts, callback origins and destination approval counts. It omits callback paths, query strings, signing secrets and encrypted records. This checklist grants no authority. Re-enrol every connector, call `events/subscribe` with a fresh signing key, and approve each new destination revision. Without `--source-db`, the checklist still records those required steps but has no old subscription inventory. For a brand-new bridge, skip migration and pass `--worker NAME` once for each worker instead; those initial workers have empty repository allowlists, no capabilities, and no host execution.
24
-
25
- Replace `192.0.2.10` below with the address configured on this computer, then run the install after the proxy route reaches the target:
21
+ Dalan installs a background service, chooses a free port and remembers its settings. No environment variables or manual server process are needed.
26
22
 
23
+ Add the private connector URL shown by Dalan to the agent's MCP settings. Start sign-in in that client, then check the pending request:
27
24
  ```sh
28
- dalan service install \
29
- --home "$HOME/.local/share/dalan-service" \
30
- --public-url https://bridge.example.com \
31
- --port 8787 \
32
- --target 192.0.2.10:8787 \
33
- --lan-port 8787
25
+ dalan connect pending
34
26
  ```
35
27
 
36
- The Dalan process listens on `127.0.0.1:8787`. With `--lan-port`, systemd opens the address and matching port in `--target` and forwards it to that loopback listener. A separate target requires this explicit option, even when its numeric port equals the bridge port. Use a distinct non-wildcard address configured on this computer: the example binds 192.0.2.10:8787 separately from 127.0.0.1:8787. Do not use 0.0.0.0 for a same-port forwarder because it collides with loopback. Challenge verification binds the actual receiving socket port to the declared target port; its challenge path has no port override. Translating to a different numeric port is allowed only with an explicit nonempty trusted `--verify-cmd COMMAND`, not challenge verification. Add `--enable-workspace` or `--enable-t3` to enable those host capabilities; each worker must also have its own workspace or T3 grant. Without these options both host capabilities are disabled. If Gozar runs on the same computer and can reach loopback directly, set `--target 127.0.0.1:8787`. `gozar service add` runs after systemd starts the bridge; install succeeds only when Gozar returns a verified route. If the origin filters the Gozar verifier by source IP, pass the trusted host check with `--verify-cmd COMMAND`.
37
-
38
- Set `DALAN_HOME` to the selected home. The private MCP URL is stored in `$DALAN_HOME/resource-url` with mode 0600. Point the client's connector at that URL and sign in separately for each worker. Repository jobs remain blocked until their allowlists are present. `dalan service install` creates a unit named `dalan-<10 hex>.service`; use the exact unit name printed by install with `systemctl --user status UNIT`, then confirm the public origin returns 404 for `/admin` and accepts the secret MCP path with its original Host header.
39
-
40
- The service starts when the systemd user manager starts. `dalan service install` does not check or warn whether user lingering is enabled. Without lingering, the user manager may start only after the user logs in after a reboot. If the bridge must start before login, ask an administrator to run `loginctl enable-linger USER` for the account that owns the bridge.
41
-
42
- `--write-units-only` writes the systemd unit files without initializing the bridge home, starting systemd or calling Gozar. It is for offline inspection; run the normal install to finish setup.
43
-
44
- ### Restarting and backing up built-in sign-ins
45
-
46
- With compatible code, a restart using the same private home and issuer preserves an unexpired built-in OAuth access token while its grant and connection remain live. The issuer includes the public origin and secret path. Access tokens last up to one hour.
47
-
48
- Before an upgrade or restore, stop the bridge and every other writer and make a consistent SQLite backup. Preserve the complete active private config directory, including `as.json`, `as-jwks.json`, `as-cookie-keys.json`, `as.sqlite` and its sibling `as-storage.key`; the keys alone cannot restore sign-ins. Follow the [backup and rollback steps](operations.md#upgrade-and-rollback).
49
-
50
- For the built-in public-client flow, a client that loses a refresh response can recover it only by retrying the identical request within five seconds, while the successor token and connection remain live. A retry after that window can fail and require the client to pair again. This is not a promise of recovery after a longer outage or across incompatible code or storage changes.
51
-
52
- ## Legacy setup with `scripts/worker-bridge-setup.mjs`
53
-
54
- The sections below document the separate legacy setup script, not `dalan service install`. The script supports the Linux and macOS setup options shown below. In particular, its `dot-bridge-NAME.service` unit name and lingering warning do not apply to `dalan service install`.
55
-
56
- ## Keep a local trial working
57
-
58
- Setup has no local-only service mode, and it needs either `--public-url https://HOST` or `--expose tailscale` (or `--expose ngrok`, for the [ngrok](https://ngrok.com/) tunnel service), so a service always has an HTTPS origin. Dalan does not supply a launchd or systemd recipe for a bridge that serves only `127.0.0.1`, and it cannot convert the paired trial home into a service. Do not point setup at the trial home: it needs a fresh home.
59
-
60
- To go from a trial to a service:
61
-
62
- 1. Keep the trial home if you want its results. Save them first, while `dalan try` still runs: with `DALAN_HOME` set to the trial home, run `dalan inbox --all --json` to list the request IDs, then `dalan get REQUEST_ID --json > result-REQUEST_ID.json` for each result you want. Then stop `dalan try` with Ctrl-C.
63
- 2. Run setup below with a new home. It makes a new bridge, with its own keys and port.
64
- 3. Pair the worker again, as the setup steps below describe. Re-running `try` or pairing replaces the worker client's old connection. Remove the old entry first with `codex mcp remove NAME` or `claude mcp remove --scope user NAME`.
65
- 4. Run the first job again on the new bridge. Read old results from the files you saved in step 1. To read a result you did not save, the trial bridge must run again: `dalan get` asks the running bridge through the admin socket in `DALAN_HOME`, so with the trial stopped it fails with `connect ECONNREFUSED`, and setting `DALAN_HOME` does not start it. Start the retained trial bridge by hand, from the Dalan checkout or package directory, on the port that its `as.json` names (the trial home is tied to that port), then read the result from a second shell:
28
+ Compare the pending code with the code in your client. If they match, replace `CODE` with that code:
29
+ ```sh
30
+ dalan connect approve CODE --worker assistant
31
+ ```
66
32
 
67
- ```sh
68
- export DALAN_HOME=TRIAL_HOME
69
- port="$(sed -n 's#.*"public_url": *"http://127.0.0.1:\([0-9][0-9]*\)".*#\1#p' "$(dalan paths --config-root)/as.json")"
70
- HOME="$DALAN_HOME" DALAN_LOOPBACK=1 DALAN_AUTH_MODE=builtin DALAN_PORT="$port" node src/server.mjs
71
- # second shell, with DALAN_HOME set to TRIAL_HOME again:
72
- dalan get REQUEST_ID --json
73
- ```
33
+ Do not approve a code you did not request, and do not share the connector URL or codes.
74
34
 
75
- Stop it with Ctrl-C when you have read the results. Do not run `dalan try` for this, because it pairs the worker again and replaces the worker client's connection to the new bridge. If the new service already listens on the trial's port, read the old results before you start the service.
35
+ Next, [send your first job](../README.md#give-your-connected-agent-a-job), using `assistant` as the worker name. Dalan queues jobs; you must ask your agent to claim them. A new installation has no repository grants or permission to run host checks.
76
36
 
77
- If you want only a bridge on this computer that stays up, run the server in a terminal as the [manual setup](manual-setup.md#owner-and-requester-setup) describes, which is the supported local path.
37
+ ### Optional checks
78
38
 
79
- ## Owner setup
39
+ After pairing, use these if you need to diagnose the service:
40
+ ```sh
41
+ dalan status
42
+ dalan doctor --auth
43
+ ```
80
44
 
81
- You need the installed package (from `npm install -g @tnunamak/dalan`) or a checkout, a stable Node.js 24 LTS or newer executable, a fresh private bridge home, and a free port from 1024 through 65535. Use short, space-free paths without symlinks; on Linux, starting the service needs a running systemd user manager; on macOS, it needs the user's launchd domain (`user/UID`), which exists while that user has a login session. `worker-bridge-setup.mjs` does not check the Node.js version.
45
+ The authentication check tests the public route and sign-in flow, not whether an agent can complete a job.
82
46
 
83
- On macOS the service is a LaunchAgent. A LaunchAgent starts when you log in to the Mac and stops when you log out, so it does not run after a reboot until someone logs in and you cannot rely on it for unattended availability.
47
+ ### More workers and advanced setup
84
48
 
85
- **After a reboot on macOS:**
49
+ Repeat `--worker NAME` in the install command to configure several workers, and pair each separately. A worker name starts with a lowercase letter, uses lowercase letters, digits, hyphens or underscores, and is at most 32 characters; `pool` and `unknown` are reserved.
86
50
 
87
- - **Check:** log in, then run `dalan status --json` (with `DALAN_HOME` set to the service home) and send one first job to prove the worker path still works.
88
- - **Check the agent itself:** run `launchctl print user/$(id -u)/org.dalan.dot-bridge-NAME | grep -E 'state|pid|runs'`. Setup loads the agent into the `user/UID` domain, and `state = running` with a `pid` means the bridge is up.
51
+ ### Pairing details
89
52
 
90
- **Symptom: `launchctl print` prints `Could not find service`.**
53
+ A client on this computer with a loopback callback needs `--confirm-redirect` with the exact redirect that `pending` shows; see [worker pairing](manual-setup.md#worker-setup). A worker on another computer follows [Native client on a remote HTTPS bridge](worker-clients.md#native-client-on-a-remote-https-bridge). Then run [submit, finish and read the result](manual-setup.md#submit-finish-and-read-the-result) with `--worker NAME`.
91
54
 
92
- - That print only says that the agent is not in the `user/UID` domain; it does not say the service failed.
93
- - **Check:** run `dalan status --json`, and run the same `launchctl print` with `gui/$(id -u)` in place of `user/$(id -u)`. An agent that an older release loaded lives in `gui/UID`.
94
- - **Action:** if neither shows `state = running` and `dalan status --json` fails, load the agent with the `bootstrap` and `kickstart` lines in [Restart a service and check its state](operations.md#restart-a-service-and-check-its-state).
55
+ Where the README and manual setup use the trial worker `local`, use your service's `NAME`:
95
56
 
96
- The domain and label are the ones that `worker-bridge-setup.mjs` writes.
57
+ - Submission: `dalan submit --worker NAME ...` for the first job and for every repository job.
58
+ - Repository grants: `dalan worker allow NAME OWNER/REPO` and `dalan worker list NAME --json`.
97
59
 
98
- ### After a reboot
60
+ `wait`, `get` and `decide` select the job by request ID and take no worker flag.
99
61
 
100
- The bridge and the worker come back by separate rules:
62
+ The rest of this guide covers advanced routes, migration, updates and removal. None is required for the first connection.
101
63
 
102
- - **Bridge, Linux.** The generated unit is wanted by `default.target`, so it starts when your systemd user manager starts. Without lingering, that is your first login after the reboot; with lingering (an administrator runs `loginctl enable-linger USER`; the legacy setup script warns when it is off), it is the boot. Check with `systemctl --user is-active dot-bridge-NAME.service`, which must print `active`.
103
- - **Bridge, macOS.** It starts at your login, as described above.
104
- - **Worker, both systems.** Dalan has no worker scheduler, and nothing wakes the worker when the bridge returns. Jobs wait in the queue until a worker run claims them. The supported way is manual, and it takes three steps. First wait until `dalan status --json` answers, with `DALAN_HOME` set to the service home. Then prompt the worker in its own client, for example: "Use Dalan to list pending work. Claim the oldest job you may claim, read it, report progress and finish it exactly as instructed. Stop when nothing is pending." In Codex, `codex exec "PROMPT" < /dev/null` runs that without a screen (see [worker clients](worker-clients.md)). Last, check that the job moved: `dalan wait REQUEST_ID` returns `finished`, or `dalan get REQUEST_ID --json` shows the report.
64
+ ### An existing reverse proxy
105
65
 
106
- A schedule or hook in the worker's vendor tool is outside Dalan's supported path; [pull workers](pull-workers.md#ways-to-start-a-run) lists the patterns and what they cost. A queued job still expires under the [preparation-expiry rule](pull-workers.md#jobs-the-worker-never-takes) if no worker claims it in time.
66
+ If you already serve a stable HTTPS address through your own reverse proxy, register that address with Gozar instead of asking Gozar for a new route:
107
67
 
108
- Setup writes the service definition under the `HOME` (macOS: `$HOME/Library/LaunchAgents`) or `XDG_CONFIG_HOME` (Linux: `$XDG_CONFIG_HOME/systemd/user`) of the shell that runs it. The service manager reads only the real user locations, so run setup with your normal `HOME` and `XDG_CONFIG_HOME`; a different value writes a definition the manager does not see. Concurrent setup runs for one user serialize on a lock file in `/tmp/dot-bridge-setup-locks-UID`. A test run that must not wait on that lock can set `DALAN_SETUP_LOCK_DIR` to its own absolute directory.
68
+ ```sh
69
+ dalan service install --worker NAME --public-url https://HOST --port N --target HOST:PORT
70
+ ```
109
71
 
110
- Choose a worker name of up to 32 characters, starting with a lowercase letter and continuing with lowercase letters, digits, `-` or `_`. `pool` and `unknown` are reserved, and you replace `NAME`, `PORT`, `HOME_PATH` and the example hostname in the commands below.
72
+ Gozar records and verifies an origin-to-target route that your reverse proxy already serves; it does not edit the proxy. Prepare the proxy first so the public origin forwards to the address in `--target`. Preserve the public `Host` header. The bridge rejects requests with another Host, including requests that try to replace it with `X-Forwarded-Host`. TLS ends at the proxy. Keep the secret path out of proxy logs.
111
73
 
112
- ### With an existing HTTPS reverse proxy
74
+ The proxy must forward these routes without removing their prefixes, methods, query strings, authorization headers or cookies:
113
75
 
114
- 1. Configure a stable HTTPS origin that forwards to the bridge computer at `127.0.0.1:PORT`. Preserve the public `Host` header, including a non-default port. Rewriting Host to localhost returns HTTP 421; `X-Forwarded-Host` does not override this check.
76
+ | Route | Purpose |
77
+ |---|---|
78
+ | `/<secret>/mcp` | Carries worker MCP requests. |
79
+ | `/.well-known/oauth-protected-resource/<secret>/mcp` | Identifies the protected resource and authorization server. |
80
+ | `/.well-known/oauth-authorization-server/<secret>/oauth` | Publishes OAuth endpoints. |
81
+ | `/.well-known/openid-configuration/<secret>/oauth` | Provides the discovery alias. |
82
+ | `/<secret>/oauth` and `/<secret>/oauth/*` | Handle OAuth and browser pairing. |
83
+ | `/signal/*` | Answers wake hooks when configured. |
84
+ | `/.well-known/gozar/service` | Answers the Gozar check, with its query string. |
115
85
 
116
- Forward the following routes without removing their prefixes, methods, query strings, authorization headers or cookies.
86
+ An unauthenticated request to `/admin` on the public origin must return 404. The Dalan process listens on `127.0.0.1:PORT`. When the target is another address on this computer, pass `--lan-port N`; the service then opens the target address and forwards it to the loopback listener. Use a distinct non-wildcard address, not 0.0.0.0, which collides with loopback. If Gozar runs on this computer and reaches loopback directly, use `--target 127.0.0.1:PORT`. Challenge verification binds the receiving socket port to the declared target port. Translating to a different numeric port needs an explicit, trusted `--verify-cmd COMMAND`. If the origin filters the Gozar verifier by source IP, pass the same option. Install succeeds only when Gozar returns a verified route.
117
87
 
118
- | Route | Purpose |
119
- |---|---|
120
- | `/<secret>/mcp` | Carries worker MCP requests. |
121
- | `/.well-known/oauth-protected-resource/<secret>/mcp` | Identifies the protected resource and authorization server. |
122
- | `/.well-known/oauth-authorization-server/<secret>/oauth` | Publishes OAuth endpoints. |
123
- | `/.well-known/openid-configuration/<secret>/oauth` | Provides the discovery alias. |
124
- | `/<secret>/oauth` and `/<secret>/oauth/*` | Handle OAuth and browser pairing. |
125
- | `/signal/*` | Answers wake hooks when configured. |
88
+ ### Migrate an older bridge
126
89
 
127
- The proxy should terminate TLS and keep secret-bearing paths out of access logs. An unauthenticated request to `/admin` should return 404.
90
+ For existing installations, create the new home and copy each worker's repository allowlist. Replace the example paths with the old bridge homes on this computer:
128
91
 
129
- 2. Generate and start the bridge from a checkout:
92
+ ```sh
93
+ dalan service migrate-workers \
94
+ --home "$HOME/.local/share/dalan-service" \
95
+ --source "$HOME/.config/dot-bridge/workers.json" \
96
+ --source "$HOME/OLD_BRIDGE_TWO/.config/dot-bridge/workers.json" \
97
+ --source "$HOME/OLD_BRIDGE_THREE/.config/dot-bridge/workers.json"
98
+ ```
130
99
 
131
- ```sh
132
- node scripts/worker-bridge-setup.mjs --worker NAME --public-url https://bridge.example.com --port PORT --home HOME_PATH --start
133
- ```
100
+ The helper reads the source files without changing them. If an older home has no `workers.json`, it can read the adjacent `workers-repos.json` migration journal. It preserves worker names and repository allowlists, and copies supported worker capabilities and guidance. It does not copy OAuth registrations, tokens, jobs or results. The new bridge starts with `default_execution: none`. Workspace access defaults to denied; add `--workspace-worker NAME` for each worker that needs an explicit workspace grant. This option records the owner's grant; it does not require an earlier audit record. Existing explicit `workspaceAllowed` and T3 capability settings are retained. Destination declarations are copied, but old destination approvals bind old jobs and connections, so each new job requires a fresh approval.
134
101
 
135
- From an npm install (`scripts/worker-bridge-setup.mjs` ships in the package), use the installed copy with the same options:
102
+ Optionally pass `--source-db PATH` for each old job database. The helper opens it read-only and writes a private `service-migration.json` checklist containing active subscription counts, callback origins and destination approval counts. It omits callback paths, query strings, signing secrets and encrypted records. This checklist grants no authority. Re-enrol every connector, call `events/subscribe` with a fresh signing key, and approve each new destination revision. Without `--source-db`, the checklist still records those required steps but has no old subscription inventory. For a brand-new bridge, skip migration and pass `--worker NAME` once for each worker instead; those initial workers have empty repository allowlists, no capabilities, and no host execution.
136
103
 
137
- ```sh
138
- node "$(npm root -g)/@tnunamak/dalan/scripts/worker-bridge-setup.mjs" --worker NAME --public-url https://bridge.example.com --port PORT --home HOME_PATH --start
139
- ```
104
+ ### Move from a trial to a service
140
105
 
141
- Setup reports the private home and service definition. With an explicit `--public-url` it does not verify public DNS or HTTPS: before pairing, check that an unauthenticated request to `/admin` on the public origin returns 404. It enables repository tools unless you pass `--no-repo-tools`; it does not enable host checks or grant repositories. A reverse proxy on another Linux LAN computer can reach a generated forwarder by adding `--lan-forward ADDR:PORT`. Anything on that network can reach this forwarder, so retain HTTPS and OAuth at the public origin.
106
+ A service needs a fresh home; do not point it at a trial home. To keep trial results, save them first while `dalan try` still runs: with `DALAN_HOME` set to the trial home that `try` printed, run `dalan inbox --all --json` to list request IDs, then `dalan get REQUEST_ID --json > result-REQUEST_ID.json` for each result you want. Then stop the trial with Ctrl-C, install the service, and pair the worker again. Pairing replaces the worker client's old connection; remove the old entry first with `codex mcp remove NAME` or `claude mcp remove --scope user NAME`.
142
107
 
143
- 3. Set `DALAN_HOME` to the exact generated home and make `dalan` available on your PATH with the [manual setup](manual-setup.md#owner-and-requester-setup) steps (no shell helper is needed). The complete MCP URL is in the mode-0600 file `$DALAN_HOME/resource-url`. Use it only in the intended worker's connector settings.
108
+ ### Keep the service running
144
109
 
145
- ```sh
146
- dalan status --json
147
- ```
110
+ On Linux the service starts when the systemd user manager starts. Without lingering, that may be your first login after a reboot. If the bridge must start before login, ask an administrator to run `loginctl enable-linger USER` for the account that owns the bridge; install does not check or warn about it. On macOS the LaunchAgent starts when you log in and stops when you log out, so it does not run unattended after a reboot until someone logs in.
148
111
 
149
- Status returns the running bridge's state. Continue with [worker pairing](manual-setup.md#worker-setup), using this HTTPS endpoint instead of the local loopback URL. Skip the manual setup's `dalan init` and foreground `node src/server.mjs` steps: the setup script already created the profile and started the service. The `<secret>` in each route above is the `BRIDGE_PATH_SECRET` from the manual [worker setup](manual-setup.md#worker-setup).
112
+ `--write-units-only` writes the service files without initializing the bridge home, starting the service or calling Gozar. It is for offline inspection; run the normal install to finish setup.
150
113
 
151
- The README and manual setup examples use the trial worker `local`. In every command that names a worker, replace `local` with your service's `NAME`:
114
+ ### Restarting and backing up built-in sign-ins
152
115
 
153
- - Pairing: `dalan connect start --worker NAME` and `dalan connect approve CODE --worker NAME`.
154
- - Submission: `dalan submit --worker NAME ...` for the first job and for every repository job.
155
- - Repository grants: `dalan worker allow NAME OWNER/REPO` and `dalan worker list NAME --json`.
116
+ With compatible code, a restart using the same private home and issuer preserves an unexpired built-in OAuth access token while its grant and connection remain live. The issuer includes the public origin and secret path. Access tokens last up to one hour.
156
117
 
157
- `wait`, `get` and `decide` select the job by request ID and take no worker flag. Run them with `DALAN_HOME` set to this service's home; with the trial home they will not find the job.
118
+ Before an upgrade or restore, stop the bridge and every other writer and make a consistent SQLite backup. Preserve the complete active private config directory, including `as.json`, `as-jwks.json`, `as-cookie-keys.json`, `as.sqlite` and its sibling `as-storage.key`; the keys alone cannot restore sign-ins. Follow the [backup and rollback steps](operations.md#upgrade-and-rollback).
158
119
 
159
- ### With Tailscale Funnel
120
+ For the built-in public-client flow, a client that loses a refresh response can recover it only by retrying the identical request within five seconds, while the successor token and connection remain live. A retry after that window can fail and require the client to pair again. This is not a promise of recovery after a longer outage or across incompatible code or storage changes.
160
121
 
161
- A tailnet is your Tailscale private network. Check each item below before you run setup. Setup checks them too and stops with the exact next step when one is missing.
122
+ <a id="after-a-reboot"></a>
162
123
 
163
- 1. **Tailscale daemon.** On macOS, Funnel needs the open-source `tailscaled`. The App Store app and the Standalone app do not supply it, and they conflict with it. If one of them is installed, quit it and move it to the Trash. Then install the daemon with [Homebrew](https://brew.sh/) and sign in:
124
+ ## After a reboot
164
125
 
165
- ```sh
166
- brew install tailscale && sudo brew services start tailscale && sudo tailscale up
167
- ```
126
+ The bridge and the worker come back by separate rules:
168
127
 
169
- See [macOS variants](https://tailscale.com/docs/concepts/macos-variants); on Linux, use the [installation guide](https://tailscale.com/download).
170
- 2. **Signed in.** Run `tailscale version` and `tailscale status`. The host must show as signed in.
171
- 3. **MagicDNS** (Tailscale's automatic DNS names for your devices). Turn it on at the [DNS page](https://console.tailscale.com/admin/dns).
172
- 4. **HTTPS Certificates.** On the same page, choose Enable HTTPS. Your machine's name then appears in public certificate transparency logs.
173
- 5. **Funnel policy.** In [Access controls](https://console.tailscale.com/admin/acls), add Funnel to the policy (the "Add Funnel to policy" button).
174
- 6. **Your shell user.** The user who runs setup must be allowed to manage Tailscale without `sudo`. If `tailscale funnel status` asks for `sudo`, run `sudo tailscale set --operator="$USER"` once.
128
+ - **Bridge.** Linux starts it with the systemd user manager (see lingering above). macOS starts it at your login. Check with `dalan service status` and `dalan status`.
129
+ - **Your agent.** Dalan does not start or schedule the agent. Once `dalan status` answers, open the client where you connected the agent and ask it: “Use Dalan to list pending jobs, claim the oldest job within your permissions, follow its brief, report progress and finish it. Stop when no jobs remain.” Check the result with `dalan wait REQUEST_ID` or `dalan get REQUEST_ID --json`, replacing `REQUEST_ID` with your job's ID.
175
130
 
176
- Run setup with Funnel instead of an explicit public URL. From a checkout:
131
+ A schedule or hook in the worker's vendor tool is outside Dalan's supported path; [pull workers](pull-workers.md#ways-to-start-a-run) lists the patterns and what they cost. A queued job still expires under the [preparation-expiry rule](pull-workers.md#jobs-the-worker-never-takes) if no worker claims it in time.
177
132
 
178
- ```sh
179
- node scripts/worker-bridge-setup.mjs --worker NAME --port PORT --home HOME_PATH --expose tailscale --start
180
- ```
133
+ ## Service updates
181
134
 
182
- From an npm install:
135
+ New installs enable a daily update check with up to one hour of random delay: a systemd user timer on Linux and a launchd agent on macOS. A missed run can run after the user manager or login session next starts. Installation with `--no-auto-update` disables the timer; `--auto-update` explicitly enables it. Reinstalling preserves the saved choice unless you pass one of those flags. The timer needs your systemd user manager to run; it does not configure login lingering.
183
136
 
184
137
  ```sh
185
- node "$(npm root -g)/@tnunamak/dalan/scripts/worker-bridge-setup.mjs" --worker NAME --port PORT --home HOME_PATH --expose tailscale --start
138
+ dalan service update --check
139
+ dalan service update
140
+ dalan service status --json
141
+ dalan service auto-update off
142
+ dalan service auto-update on
186
143
  ```
187
144
 
188
- Setup should report the derived HTTPS origin, generated service and exposure verification. It chooses the first free Funnel port from 443, 8443 and 10000, and the origin it prints includes that port when it is not 443. Pass `--funnel-port N` only to choose one; setup refuses a port that another Funnel or Serve rule already uses and never replaces that rule. Verify the selected port with the target client.
145
+ The home defaults to `~/.local/share/dalan-service` and Dalan remembers it; pass `--home DIR` only to select a different one. `service status` shows the selected version, saved automatic-update preference and last update result. Use `systemctl --user list-timers` to inspect the actual timer schedule. Turning updates off prevents future starts; it does not cancel an update already running. Preference changes refuse while an update holds the home lock. A release that was rolled back is recorded and skipped on later runs, including the timer; `dalan service update --retry` tries it again, and a newer or republished release is attempted normally. `service status` shows it as `failed_release`.
189
146
 
190
- Setup prints a `dalan()` shell function for the owner commands; you can use it or set `DALAN_HOME` as step 1 says. Continue as follows, and skip `dalan init` and the foreground `node src/server.mjs` step, because setup already created and started this service.
147
+ `--check` queries the public npm registry for the latest stable `@tnunamak/dalan` version and reports availability without installation or restart. A normal update installs the exact release under `HOME/versions/<version>`, with npm integrity checks and install scripts disabled. The registry's integrity value binds the downloaded bytes to its metadata; it is not an independent publisher signature. The original package must remain available until the first successful update. Later starts use the selected package through `HOME/current`.
191
148
 
192
- 1. Export `DALAN_HOME="HOME_PATH"` with the exact home you passed above, and run `dalan status --json`. Make `dalan` available on your PATH with the [manual setup](manual-setup.md#owner-and-requester-setup) steps. The private MCP URL is in `$DALAN_HOME/resource-url`, as in step 3 of the reverse-proxy route.
193
- 2. A worker on this computer follows [worker pairing](manual-setup.md#worker-setup). A worker on another computer follows [Native client on a remote HTTPS bridge](worker-clients.md#native-client-on-a-remote-https-bridge). Then run [submit, finish and read the result](manual-setup.md#submit-finish-and-read-the-result), replacing `local` with `NAME` in every command.
149
+ Before switching, Dalan starts the candidate on a scratch loopback port against a private copy of the worker configuration, fresh mutable state, and synthetic keys made for that check. It never receives the service's signing, cookie, storage or operator keys. It checks initialization, ping and complete tool descriptors for every configured worker, then compares them with the running bridge. An unreachable worker, failed check or incomplete catalog stops the update. This local check does not test the public HTTPS route or hosted-client OAuth sign-in.
194
150
 
195
- ### When setup stops before verification
196
-
197
- Setup with `--expose tailscale` or `--expose ngrok` can leave the home, service and keys in place if public DNS or HTTPS is not ready. Run the exact `--retry-public-check` command it prints after fixing the public route. That checks the existing installation without replacing its keys; do not rerun a fresh install over it. DNS checks can take up to ten minutes, followed by up to two minutes for HTTPS plus request overhead.
198
-
199
- The retry has the form below. It needs the exposure record that those two modes save, so it does not work for an install made with an explicit `--public-url`.
151
+ If a descriptor changes, the candidate stays staged and the last result is `connector_refresh_required`. To authorize switching to that release, run:
200
152
 
201
153
  ```sh
202
- node "$(npm root -g)/@tnunamak/dalan/scripts/worker-bridge-setup.mjs" --retry-public-check --worker NAME --public-url EXPOSURE_URL --port PORT --home HOME_PATH
154
+ dalan service update --yes
203
155
  ```
204
156
 
205
- From a source checkout, use `node scripts/worker-bridge-setup.mjs` with the same options.
157
+ Refresh the Dalan connector in each hosted client after that switch. `--yes` allows the catalog change; it does not skip integrity, scratch checks or post-restart health checks. The timer never supplies it. Equal catalogs permit an automatic switch, but they cannot prove equal tool behavior or authorization semantics. Restarting interrupts connections and can interrupt in-progress requests.
206
158
 
207
- It should mark the existing exposure verified. A 404 from unauthenticated `/admin` proves the expected public route answers, not that OAuth pairing or a worker job works, so complete both separately.
159
+ While a switch is in progress, the restarted candidate refuses every worker call, OAuth request and owner command with a retryable 503 (`service_updating`, with `Retry-After`) and starts no background writer, until the update commits or rolls back. A rollback restores the saved state, so no change that Dalan acknowledged can be lost. Hosted clients retry after the window. For a switch, Dalan stops the bridge, saves its persistent configuration and data, selects the candidate, restarts the unit and checks local health and catalogs. On failure it attempts to stop the candidate, restore the previous selection and saved state, then restart and check the old version. A failed rollback is reported separately. An interrupted switch leaves a transaction record for recovery. Recovery runs when the service starts (an `ExecStartPre` step, `dalan service recover`) and again on the next update attempt; it does nothing while another update is running. Retention keeps three staged versions, including the active and previous versions. This is update recovery, not a replacement for your own backups.
208
160
 
209
- ## Remove a generated service
161
+ A service installed by 0.6.0 or 0.6.1 is adopted by its first `dalan service update` with no other step: Dalan reads the package path and node binary from the service unit, keeps that node binary, and leaves the original package in place until a later update succeeds. To turn on the daily timer for such a service, run `dalan service auto-update on`, or enroll it the long way: install the current Dalan package, then repeat its original `dalan service install` command with the same home, origin, port and target. Enrollment preserves keys and worker grants, changes the unit's package path and restarts it. Its timer stays off unless you pass `--auto-update` or run `service auto-update on`. A modified unit is refused for inspection. These update commands cover the service made by `dalan service install`; services from the older setup script are not enrolled automatically.
210
162
 
211
- Use the same worker and home that created it. The full list of things an uninstall must remove (service, homes, trial home, client entries, lock file) is in [operations](operations.md#remove-an-installation).
163
+ ## Remove the service
212
164
 
213
165
  ```sh
214
- node scripts/worker-bridge-setup.mjs --remove --worker NAME --home HOME_PATH
166
+ dalan service uninstall
215
167
  ```
216
168
 
217
- From an npm install, run `node "$(npm root -g)/@tnunamak/dalan/scripts/worker-bridge-setup.mjs"` with the same options.
169
+ This stops and removes the service, its update timer or agent and its public route. It never deletes data: the private home, keys and state move to `<home>.removed-<date>`, and the command prints that path. Delete that directory yourself when you want the data gone. A modified service definition may need inspection instead of automatic removal. The full list of things an uninstall must remove (homes, trial home, client entries) is in [operations](operations.md#remove-an-installation).
170
+
171
+ ## Legacy
218
172
 
219
- The script stops and removes its generated service and any unchanged recorded Funnel rule. It checks generated markers before removal and refuses to disable a Funnel rule that has changed. It retains the private home, keys and state. Add `--purge-home` only when you intend to delete those too. An interrupted copy or a modified service may require inspection instead of automatic removal.
173
+ Installations made by `scripts/worker-bridge-setup.mjs` in earlier releases keep working; that script is kept for compatibility only. See [operations](operations.md#restart-a-service-and-check-its-state) and the [upgrade guide](dalan-upgrade.md) to manage or replace one.
@@ -4,12 +4,12 @@ Use this page after the [README](../README.md) first-job path works. It lists se
4
4
 
5
5
  ## Environment and storage
6
6
 
7
- Set server variables in the process or service environment, then restart the bridge. Only the `dalan` command reads `DALAN_HOME`; it does not replace the server's `HOME`.
7
+ Set server variables in the process or service environment, then restart the bridge. Only the `dalan` command reads `DALAN_HOME`; it does not replace the server's `HOME`. A service made by `dalan service install` needs none: `dalan` remembers its home.
8
8
 
9
9
  | Setting | Effect |
10
10
  |---|---|
11
11
  | `HOME` | Selects the bridge's private configuration, state and requester receipts. The server and requester must use the same home. |
12
- | `DALAN_HOME` | The `dalan` command uses this directory as its `HOME`, so it reads the home of a server started with that `HOME`. `dalan try` uses it as the default trial home. |
12
+ | `DALAN_HOME` | The `dalan` command uses this directory as its `HOME`, so it reads the home of a server started with that `HOME`. It overrides the remembered service home. `dalan try` uses it as the default trial home. |
13
13
  | `DALAN_AUTH_MODE=builtin` | Uses the built-in OAuth authorization server. `oauth` selects an external issuer instead. |
14
14
  | `DALAN_LOOPBACK=1` | Runs authenticated HTTP on loopback only. Requires `DALAN_AUTH_MODE=builtin` and a fixed `DALAN_PORT`; the public URL must be `http://127.0.0.1:<port>`. |
15
15
  | `DALAN_PORT` | Sets the HTTP listener port; the server default is 8787. |
@@ -23,7 +23,7 @@ The corresponding old `DOT_BRIDGE_*` environment names remain readable for compa
23
23
 
24
24
  ## Requester commands
25
25
 
26
- The table lists the common commands. Run `dalan help --all` to see every command. Export `DALAN_HOME` in each shell, so that every command reads the same home and private receipts.
26
+ The table lists the common commands. Run `dalan help --all` to see every command. Every command must read the same home and private receipts: a service home is remembered; for a trial or a bridge you started by hand, export `DALAN_HOME` in each shell.
27
27
 
28
28
  | Command | Result |
29
29
  |---|---|
@@ -66,7 +66,7 @@ For upgrades, use the [changelog](../CHANGELOG.md) and [operations procedure](op
66
66
 
67
67
  ## Legacy service examples
68
68
 
69
- The `dot-bridge.service`, `dot-bridge-selfcheck.service` and `dot-bridge-selfcheck.timer` examples are in `systemd/`. Keep these filenames when installing them for an existing deployment so service dependencies and timer targets still resolve. The legacy templates retain their original checkout default for compatibility. Set each example's `WorkingDirectory` to the deployed checkout and set `PATH` to a Node.js 24 installation before installing it. Units installed as copies, and drop-ins, do not need to change. A unit installed as a symbolic link to `dot-bridge.service`, `dot-bridge-selfcheck.service` or `dot-bridge-selfcheck.timer` in the repository root breaks when you update the checkout, because 0.5.0 removes those root links: before you update, point each such link at the same file in `systemd/`, then run `systemctl --user daemon-reload`. For a new installation, prefer the generator in the [service guide](service-setup.md): `node scripts/worker-bridge-setup.mjs --worker NAME --public-url https://bridge.example.com --port PORT --home HOME_PATH --start`. The external self-check is deployment-specific; configure it before enabling its timer.
69
+ The `dot-bridge.service`, `dot-bridge-selfcheck.service` and `dot-bridge-selfcheck.timer` examples are in `systemd/`. Keep these filenames when installing them for an existing deployment so service dependencies and timer targets still resolve. The legacy templates retain their original checkout default for compatibility. Set each example's `WorkingDirectory` to the deployed checkout and set `PATH` to a Node.js 24 installation before installing it. Units installed as copies, and drop-ins, do not need to change. A unit installed as a symbolic link to `dot-bridge.service`, `dot-bridge-selfcheck.service` or `dot-bridge-selfcheck.timer` in the repository root breaks when you update the checkout, because 0.5.0 removes those root links: before you update, point each such link at the same file in `systemd/`, then run `systemctl --user daemon-reload`. For a new installation, use `dalan service install` ([service guide](service-setup.md)). The external self-check is deployment-specific; configure it before enabling its timer.
70
70
 
71
71
  <a id="names-you-may-see"></a>
72
72
 
@@ -74,7 +74,7 @@ The `dot-bridge.service`, `dot-bridge-selfcheck.service` and `dot-bridge-selfche
74
74
 
75
75
  Earlier versions of Dalan used other names. Some remain so that existing installations keep working; use `dalan` and `DALAN_*` names for anything new.
76
76
 
77
- - **`dot-bridge.service`, `dot-bridge-selfcheck.service` and `dot-bridge-selfcheck.timer`** are legacy systemd templates in `systemd/`. Do not use them for a new install; use `scripts/worker-bridge-setup.mjs`.
77
+ - **`dot-bridge.service`, `dot-bridge-selfcheck.service` and `dot-bridge-selfcheck.timer`** are legacy systemd templates in `systemd/`. Do not use them for a new install; use `dalan service install`.
78
78
  - **`.dot-bridge.json`** is the older name of a repository's check file, `.dalan.json`. Dalan still reads it when `.dalan.json` is absent.
79
79
  - **`dot-bridge.*` OAuth scopes and `DOT_BRIDGE_*` settings** are older names that still work; the `dot-worker` command is replaced by `dalan`. They do not limit which client can be a worker.
80
80
  - **T3 Code** is a separate desktop app for running coding agents. Dalan has an optional integration with it (the `t3.*` scopes, [T3 tools](t3-reverse-control.md) and [operator-registered tools](worker-clients.md#operator-registered-tools)). Ordinary jobs do not need it.
@@ -179,16 +179,16 @@ Each native attempt is approved by its own code, and a later attempt cannot take
179
179
 
180
180
  ### Worked example: Codex CLI on another computer
181
181
 
182
- This example uses a bridge from the [Tailscale Funnel setup](service-setup.md#with-tailscale-funnel), a worker named `NAME` and Codex CLI on the worker computer. No reverse proxy and no domain of your own are involved.
182
+ This example uses a bridge from `dalan service install --worker NAME --route ROUTE` ([service setup](service-setup.md)) and Codex CLI on the worker computer. No reverse proxy and no domain of your own are involved.
183
183
 
184
- 1. On the bridge computer, with `DALAN_HOME` set to the bridge home, allow the callback and open a pairing window:
184
+ 1. On the bridge computer, allow the callback and open a pairing window:
185
185
 
186
186
  ```sh
187
187
  dalan connect allow-callback 'http://127.0.0.1/callback'
188
188
  dalan connect start --worker NAME
189
189
  ```
190
190
 
191
- 2. Copy the private file `$DALAN_HOME/resource-url` to the worker computer over a trusted channel such as `scp`, and keep it at mode 0600, because it holds the bridge's secret path.
191
+ 2. Copy the private connector URL file that install printed (`resource-url` in the service home, `~/.local/share/dalan-service/resource-url` by default) to the worker computer over a trusted channel such as `scp`, and keep it at mode 0600, because it holds the bridge's secret path.
192
192
  3. On the worker computer, add the server. The command prints an authorization URL and waits:
193
193
 
194
194
  ```sh
@@ -199,7 +199,7 @@ This example uses a bridge from the [Tailscale Funnel setup](service-setup.md#wi
199
199
  5. On the bridge computer, run `dalan connect pending`. Compare the code and the redirect with the page, then run `dalan connect approve CODE --worker NAME --confirm-redirect REDIRECT`.
200
200
  6. **Check:** `codex mcp add` ends with `Successfully logged in.` Add the five tool approvals from the [Codex CLI section](#native-cli-worker-codex-cli) to the worker computer's `config.toml`. Submit the README's first job with `--worker NAME`, run `codex exec` on the worker computer, then use `dalan wait`, `get` and `decide` on the bridge computer.
201
201
 
202
- To undo it, run `codex mcp remove NAME` on the worker computer, and `node "$(npm root -g)/@tnunamak/dalan/scripts/worker-bridge-setup.mjs" --remove --worker NAME --home HOME_PATH` on the bridge computer (from a checkout, `node scripts/worker-bridge-setup.mjs` with the same options); that also turns off the Funnel rule that setup created.
202
+ To undo it, run `codex mcp remove NAME` on the worker computer, and `dalan service uninstall` on the bridge computer; that removes the service and its public route.
203
203
 
204
204
  ## Worker names and more than one worker
205
205
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tnunamak/dalan",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "An MCP job bridge for bounded agent work, durable progress, results, and owner review.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -24,7 +24,6 @@
24
24
  "scripts/monitor-targets.mjs",
25
25
  "scripts/worker-bridge-setup.mjs",
26
26
  "scripts/upgrade-drain.mjs",
27
- "scripts/lib/expose-tailscale.mjs",
28
27
  "scripts/live-trial/common.mjs",
29
28
  "docs/",
30
29
  "CONTRIBUTING.md",
@@ -54,7 +53,7 @@
54
53
  },
55
54
  "dependencies": {
56
55
  "@agentclientprotocol/sdk": "1.8.0",
57
- "@tnunamak/gozar": "0.1.0",
56
+ "@tnunamak/gozar": "^0.2.1",
58
57
  "oidc-provider": "9.13.0"
59
58
  },
60
59
  "devDependencies": {
@@ -1,26 +1,27 @@
1
1
  #!/usr/bin/env node
2
- // Run against a live `dalan try --public` trial before adding the connector in claude.ai or ChatGPT:
3
- // node scripts/dalan-try-selfcheck.mjs --home <trial home> [--client claude|chatgpt] [--wait 300]
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 { runSelfCheck } from '../src/try-selfcheck.mjs';
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'), client = option('--client') ?? 'claude', wait = Number(option('--wait') ?? 300);
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 || !['claude', 'chatgpt'].includes(client)) {
16
- process.stderr.write('usage: node scripts/dalan-try-selfcheck.mjs --home <trial home> [--client claude|chatgpt] [--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');
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, client, approveWaitMs: wait * 1000, signal: controller.signal, say: line => process.stdout.write(`${line}\n`) });
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.