@tnunamak/dalan 0.5.2 → 0.6.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 (62) hide show
  1. package/CHANGELOG.md +29 -25
  2. package/PROTOCOL.md +16 -4
  3. package/README.md +127 -260
  4. package/SECURITY.md +1 -1
  5. package/bin/dalan.mjs +5 -0
  6. package/bin/dot-worker.mjs +35 -26
  7. package/docs/chatgpt-worker-onboarding.md +5 -5
  8. package/docs/claude-worker-onboarding.md +5 -5
  9. package/docs/codex-to-muse.md +175 -0
  10. package/docs/connect-chatgpt.md +9 -4
  11. package/docs/connection-longevity.md +7 -1
  12. package/docs/dalan-upgrade.md +17 -13
  13. package/docs/deadman.md +5 -3
  14. package/docs/local-agent-mcp.md +8 -6
  15. package/docs/manual-setup.md +8 -8
  16. package/docs/mirror-fetch.md +1 -2
  17. package/docs/operations.md +90 -42
  18. package/docs/operator-duties.md +1 -1
  19. package/docs/owner-integrator.md +2 -2
  20. package/docs/portable-auth-profile.md +12 -14
  21. package/docs/pr-head-reviewer.md +21 -5
  22. package/docs/pr-preflight.md +2 -0
  23. package/docs/pull-queue.md +131 -0
  24. package/docs/pull-workers.md +7 -10
  25. package/docs/redaction.md +1 -1
  26. package/docs/service-setup.md +56 -3
  27. package/docs/setup-reference.md +1 -1
  28. package/docs/t3-integration.md +2 -0
  29. package/docs/t3-result-retry-delivery.md +2 -2
  30. package/docs/t3-reverse-control.md +7 -7
  31. package/docs/usage.md +19 -15
  32. package/docs/worker-clients.md +18 -13
  33. package/package.json +3 -1
  34. package/scripts/dalan-try-selfcheck.mjs +29 -0
  35. package/scripts/worker-bridge-setup.mjs +1 -1
  36. package/src/acp-bridge.mjs +18 -12
  37. package/src/as.mjs +41 -0
  38. package/src/child-exit.mjs +18 -0
  39. package/src/child-registry.mjs +94 -0
  40. package/src/cli-help.mjs +25 -11
  41. package/src/demo-worker.mjs +2 -2
  42. package/src/drained-owner.mjs +26 -0
  43. package/src/drained-slot.mjs +20 -3
  44. package/src/mcp-outcome.mjs +10 -1
  45. package/src/mcp-sse.mjs +62 -0
  46. package/src/pr-head-reviewer.mjs +3 -3
  47. package/src/process-inspection.mjs +36 -0
  48. package/src/pull-queue.mjs +159 -0
  49. package/src/route-setting.mjs +24 -0
  50. package/src/server.mjs +157 -29
  51. package/src/service-migrate-workers.mjs +113 -0
  52. package/src/service.mjs +388 -0
  53. package/src/setup.mjs +63 -0
  54. package/src/store.mjs +21 -9
  55. package/src/tool-registry.mjs +3 -1
  56. package/src/try-exposure.mjs +908 -0
  57. package/src/try-hosted-clients.mjs +46 -0
  58. package/src/try-hosted.mjs +444 -0
  59. package/src/try-selfcheck.mjs +168 -0
  60. package/src/try.mjs +63 -17
  61. package/src/workers.mjs +33 -23
  62. package/src/workspace.mjs +10 -3
package/README.md CHANGED
@@ -1,349 +1,216 @@
1
1
  # Dalan
2
2
 
3
- Dalan is a job queue between your shell or coding agent and a separate AI worker. A small local service, the *bridge*, holds the jobs; the worker connects to it over MCP. You submit a bounded task, follow its progress, and review the worker's report or patch before you accept it. Start with a local demo that needs no account, then connect your own worker.
3
+ Give a coding agent in ChatGPT, Claude on the web, or another MCP client a job from your computer, then review its report.
4
4
 
5
- Use it when you want a second agent, a second account or another computer to do a job while you keep the accept or reject decision: for example, your coding agent hands a code review to an agent signed in to another account, and you read its report before you accept it.
6
-
7
- - **Repository access starts denied.** A new worker can read no repository until you grant one, and a finished job counts as accepted only after you run `dalan decide` or answer `y`.
8
- - **Any MCP client can be the worker.** Claude Code, Codex CLI, ChatGPT, Muse Spark (Meta) or your own agent connect over MCP (Model Context Protocol) with OAuth sign-in. Dalan does not run a model itself. See [Connect any MCP worker](#connect-any-mcp-worker) and [Connect ChatGPT](docs/connect-chatgpt.md). [T3 Code](docs/t3-integration.md#use-dalan-from-t3-code) can delegate to any of them.
9
- - **The bridge listens only on your computer** until you choose to expose it.
10
-
11
- **Not for:** Dalan does not run, schedule or start agents for you, and it does not merge code. It queues work and returns reports for you to review.
5
+ ```sh
6
+ npx -y @tnunamak/dalan try
7
+ ```
12
8
 
13
- **Help:** see [Still stuck?](#still-stuck) for the recovery steps and how to open an issue.
9
+ **Success:** Dalan prints a connector URL and a prompt. Add the connector to your hosted client, compare the sign-in code with the one in your terminal, approve the match, then paste the prompt into a chat with the connector enabled. The agent's report returns to your terminal.
14
10
 
15
11
  <a id="quickstart"></a>
16
12
 
17
- ## Quick start
18
-
19
- You need:
13
+ ## Try it with your MCP client
20
14
 
21
- - **Linux or macOS.** On Windows, [install WSL](https://learn.microsoft.com/windows/wsl/install) and run every command in the WSL shell.
22
- - **Node.js 24 or newer.** Run `node --version`; it must print `v24` or higher. If it does not, install Node.js from the [official download page](https://nodejs.org/en/download) and open a new shell.
23
- - **Optional: Git and Python 3.8 or newer**, for the repository part of the demo. Run `git --version` and `python3 --version`. Without them, the demo skips that part and says so.
15
+ You need Node.js 24 or newer, Linux or macOS (or WSL), and a hosted client account or workspace that permits custom MCP connectors.
24
16
 
25
- The demo needs no AI account and no MCP client. The shell examples in this README use POSIX shell syntax (bash or zsh). Start the demo with one command:
17
+ Start Dalan in an interactive terminal:
26
18
 
27
19
  ```sh
28
- npx @tnunamak/dalan try
20
+ npx -y @tnunamak/dalan try
29
21
  ```
30
22
 
31
- To run from a checkout instead, see [Install from source](#from-source).
32
-
33
- `try` starts a bridge on `127.0.0.1` and runs a built-in demo worker against it. The first run takes about half a minute. npx asks once to install the package; answer `y`. A first run prints this (the request ID is shortened):
34
-
35
- ```text
36
- $ npx @tnunamak/dalan try
37
- Need to install the following packages:
38
- @tnunamak/dalan@0.5.2
39
- Ok to proceed? (y) y
40
- npm notice run npx
41
- npm notice run 'dalan' try
42
- Dalan trial. Home: /home/you/.local/share/dalan-trial
43
- ✔ Bridge up on http://127.0.0.1:8799. Loopback only. Log: /home/you/.local/share/dalan-trial/server.log
44
- ✔ Self-check passed in 2.6 s: a demo worker, approved by this command, finished a job; the repository grant works and a second repository is refused.
45
-
46
- Connect your worker as an HTTP MCP server with OAuth:
47
- MCP URL file: /home/you/.local/share/dalan-trial/resource-url
48
- MCP URL (secret hidden): http://127.0.0.1:8799/<secret>/mcp
49
- Keep the URL private.
50
- How to connect Claude Code, Codex or another client: https://github.com/tnunamak/dalan/blob/v0.5.2/README.md#connect-your-own-worker
51
- Callbacks: http://127.0.0.1/callback, http://localhost/callback. To add one, restart with:
52
- npx @tnunamak/dalan try --home '/home/you/.local/share/dalan-trial' --callback PATTERN
53
- Job req_01234567… is queued for your worker. When it is connected, send it:
54
- "Request req_01234567… is your only job: claim it with Dalan, do what its brief asks, report progress and finish it with the claim_id. Stop if it is missing or cancelled. Claim no other job."
55
- Waiting for your worker. Ctrl-C stops the bridge.
56
- ```
57
-
58
- **Check:** look for the `✔ Self-check passed` line. The demo worker signed in through OAuth, finished a text job, read the one demo repository that it was granted and was refused another. The demo repository is local, so no network or GitHub login is used.
59
-
60
- `try` now keeps the bridge running and has queued a second job for your own worker. Leave this terminal open and continue below. Ctrl-C stops the bridge and keeps the trial home for the next run ([The trial home](#the-trial-home)).
61
-
62
- <a id="connect-your-own-worker"></a>
63
-
64
- ## Connect your own worker
65
-
66
- This step proves that your own client can do a job. You need a worker client installed and signed in on this computer, such as [Claude Code](https://code.claude.com/docs/en/quickstart), [Codex CLI](https://developers.openai.com/codex/cli/) or [opencode](docs/worker-clients.md#cli-worker-opencode). A client that runs on its provider's servers (ChatGPT, Claude on the web) cannot reach `127.0.0.1`; see [Expose the bridge](#expose-your-bridge) instead.
23
+ Choose ChatGPT or Claude on the web. In `auto` mode, a saved Gozar choice or an older saved localhost.run choice selects Gozar. Otherwise Dalan uses Tailscale when a route is usable, and Gozar when Tailscale is not usable.
67
24
 
68
- **Cost.** The built-in demo uses no AI model or account. Your own worker runs on the account signed in to Claude Code or Codex CLI, and is subject to that provider's access rules, usage limits and charges. Dalan runs no model and adds no charge.
25
+ When Dalan selects Gozar, it names tunnl.gg, links its [terms](https://tunnl.gg/terms) and [privacy notice](https://tunnl.gg/privacy), and asks for consent before exposure. After you consent, Gozar creates a key for this installation and opens a route through its key-bound `tunnl-gg` relay. Dalan does not use or pass your SSH keys. The relay terminates TLS and can see the connector URL and traffic. Keep private code and secrets out of the demo.
69
26
 
70
- **Who can connect.** The bridge listens only on `127.0.0.1`. A client needs the secret URL from the private file and your `y` at sign-in before it can act as a worker. These checks do not separate programs that run as your own Unix user: such a program can read the bridge's private files and use its admin socket. Connect only clients that you trust with your account, and run untrusted workers as a different Unix user or on another computer (see [Operations](docs/operations.md)).
27
+ A temporary demo link can change or stop without warning, including within minutes. Dalan checks the original address and ends the trial when it detects a route change or loss. The trial ends after three hours at most; that is a limit on the trial, not a promise about the link. If the address changes or the route stops, start a fresh trial and replace the connector URL.
71
28
 
72
- 1. **Add the bridge to your client.** In a second terminal, register the MCP URL from the private file that `try` printed, under the name `local`. The URL contains a secret. The commands read it from the file, so it does not go into your shell history, but the client may print it: keep that output private. If you passed `--home DIR` to `try`, use that directory in place of `~/.local/share/dalan-trial`.
29
+ 1. **Add the connector.** Follow Dalan's instructions to add the complete connector URL in your hosted client and start sign-in. Keep the URL private.
30
+ 2. **Approve the sign-in.** Compare the code in the browser with the code in your terminal. Approve only when they match.
31
+ 3. **Send the prompt.** Paste Dalan's prompt into a chat with the connector enabled. Dalan queues the demo job; it does not start the hosted chat for you.
32
+ 4. **Review the report.** Read the report in your terminal before you accept or reject it.
73
33
 
74
- With Claude Code, register the server and sign in:
34
+ The hosted demo is a text job, not a repository review. It grants no repository access. Your agent uses its own account, limits and billing; Dalan does not run a model.
75
35
 
76
- ```sh
77
- claude mcp add --transport http --scope user local "$(cat ~/.local/share/dalan-trial/resource-url)"
78
- claude mcp login local
79
- ```
36
+ ### Stop a trial
80
37
 
81
- `claude mcp login` opens the sign-in page and waits until you approve it in step 3. In an interactive `claude` session, `/mcp`, then `local`, then **Authenticate** does the same.
38
+ Ctrl-C stops the trial. It also cancels a route that is still starting. Dalan closes its forwarding gate and attempts to remove its route. If it cannot confirm cleanup, it reports that. When Gozar cannot confirm route ownership, Dalan leaves the route alone and gives no stop command; use a different port and home for another trial.
82
39
 
83
- With Codex CLI, register the server; Codex starts the sign-in at once and waits until it is approved:
40
+ If Gozar returns a cleanup-pending status for this trial, Dalan provides a recovery command that stops by port. Gozar does not bind that command to a session ID, so the route can change before the command runs. Inspect the current route before using it.
84
41
 
85
- ```sh
86
- codex mcp add local --url "$(cat ~/.local/share/dalan-trial/resource-url)"
87
- ```
42
+ On stop, Dalan removes the connector URL file. It also removes the bridge's secret file for temporary routes. It keeps the bridge configuration when a Tailscale route reuses the same home.
88
43
 
89
- 2. **Open the sign-in page.** The client opens a browser tab, or prints a URL for you to open once in a browser on this computer. Leave the tab open. It is titled "Connect to Dalan" and shows a pairing code such as `ABCD-1234`. The page also shows a `dalan connect approve` command: you do not need it, because `try` asks you instead.
44
+ ### Try without a public route
90
45
 
91
- 3. **Approve in the `try` terminal.** A block of lines appears there with `code`, `client_name`, `redirect` and `scopes`. Check that `code` is the code in the browser tab and that `scopes` are `dalan.read dalan.work`. (Claude Code also asks for `t3.read t3.write`, optional integration scopes that give no extra access in this version.) Then answer `y` to `Approve this connection for worker "local"? [y/N]`.
46
+ ```sh
47
+ npx -y @tnunamak/dalan try --local
48
+ ```
92
49
 
93
- **Check:** `try` prints `Approved. Waiting for the worker to finish the job.` `claude mcp login` prints `Authenticated with "local". Its tools are now available in Claude Code.`; `codex mcp add` returns with `Successfully logged in.`
50
+ This runs a self-check with a built-in demo worker and then lets you connect a client on this computer. It does not open a public route. To connect a worker client by hand, see [manual setup](docs/manual-setup.md#worker-setup).
94
51
 
95
- 4. **Give the worker its job.** Queuing a job does not start a worker, so you start it. Open an interactive session (`claude` or `codex`), paste the prompt that `try` printed, and allow the Dalan tool calls when the client asks. To run it without an interactive session, Claude Code takes `claude -p "PROMPT" --allowedTools mcp__local`, which approves this server's tool calls in advance; in this mode Claude Code does not prompt, so it does not use tools that need approval.
52
+ ## Use a Tailscale route
96
53
 
97
- **Check:** `try` prints `✔ Your worker finished req_…. Report:` with the worker's report, then asks `Accept this result? [y/N]`. Answer `y`; `try` prints `Recorded as accepted.`
54
+ `npx -y @tnunamak/dalan setup` saves a route choice for public trials. If Tailscale is ready for Funnel, setup asks whether to save Tailscale or Gozar for temporary links. If Tailscale is not ready, setup prints Tailscale installation instructions or lets you save Gozar. It does not install a background service or move a connector to a new address.
98
55
 
99
- You have now done the whole loop: a job was queued, your worker claimed and finished it, and you reviewed and accepted the result.
56
+ Use Tailscale explicitly:
100
57
 
101
- If a step fails, look for its message here:
58
+ ```sh
59
+ npx -y @tnunamak/dalan setup
60
+ npx -y @tnunamak/dalan try --public --route tailscale --client chatgpt
61
+ ```
102
62
 
103
- - **The browser shows `Connection attempt invalid or expired`.** Each visit to the sign-in URL starts a new attempt with a new code, and only a live attempt can be approved. Start the sign-in again in the client and approve the new code.
104
- - **No approval block appears in the `try` terminal.** After a while, `try` prints the `dalan connect pending` and `dalan status` commands to run in another terminal, and it shows each new attempt as it arrives.
105
- - **`npx @tnunamak/dalan try` fails with an npm error such as `ECONNREFUSED`, `ETIMEDOUT` or `ENOTFOUND`.** npm cannot reach the registry. Check the network or proxy with `npm config get registry` and `npm config get proxy`, then run the command again.
106
- - **Your client uses a different callback.** `try` allows `http://127.0.0.1/callback` and `http://localhost/callback` on any port. Stop `try` and start it again with `--callback PATTERN` ([pattern rules](docs/setup-reference.md#callback-patterns)).
63
+ Use `--client claude` for claude.ai. Tailscale login, client sign-in and approval may still be required. An explicit `--route tailscale` does not fall back to a trial link: if the route cannot start, Dalan stops and explains why.
107
64
 
108
- <a id="still-stuck"></a>
65
+ An explicit `--route tailscale` trial uses HTTPS port 443. When the port is available, Dalan opens its own Funnel rule for the trial and attempts to remove only that rule when it stops. If another rule already holds port 443, Dalan can start an isolated, temporary Tailscale node instead. It does not reuse or change the other rule. That node uses a new address and may need a one-time sign-in. A new address needs a new client sign-in.
109
66
 
110
- **Still stuck?** With `DALAN_HOME` set as in [Next steps](#next-steps), run `dalan status` and `dalan doctor`, and match their messages against the list above. If that does not help, [open an issue](https://github.com/tnunamak/dalan/issues) with the Dalan version, your OS, your worker client and its version, the command that you ran and the error with private values removed. Never include the private MCP URL, tokens or sign-in links. Report a vulnerability through the [security policy](SECURITY.md), not in an issue.
67
+ If the public address does not answer, the trial prints `TLS certificate: ok` or `TLS certificate: error (...)`. The trial keeps a masked copy of the temporary node's log as `tailscaled.log` in the trial home.
111
68
 
112
- The [worker guide](docs/worker-clients.md) has the full Claude Code and Codex CLI recipes, including running Codex without a screen (`codex exec`).
69
+ ### Choose another relay
113
70
 
114
- ## Next steps
71
+ `--route gozar` explicitly selects the Gozar relay. Dalan still asks for consent before it exposes the route.
115
72
 
116
- Each row starts from a working trial.
73
+ `--route localhost.run` remains available as an explicit option. It uses OpenSSH and a temporary third-party relay. The relay terminates TLS and can inspect the connector URL and forwarded traffic. Dalan prints this notice before it starts the route. The address can change or stop without warning. Dalan attempts to close the route and reports cleanup it cannot confirm.
117
74
 
118
- | To do this | Go to |
119
- |---|---|
120
- | Run `dalan` commands against the trial bridge | Run `npm install -g @tnunamak/dalan`, then `export DALAN_HOME=~/.local/share/dalan-trial` in each shell. Try `dalan status` and `dalan inbox --all`. |
121
- | Give your worker a task of your own, with no file to write | [Your own first job](#your-own-first-job) |
122
- | Give your worker a job on a real repository | [Give a worker a repository job](#separate-repository-assignment) |
123
- | Let a coding agent submit and read jobs as tool calls | [`dalan mcp`](docs/local-agent-mcp.md) |
124
- | Connect a worker on another computer, or a hosted client such as ChatGPT | [Expose the bridge](#expose-your-bridge), then [Connect any MCP worker](#connect-any-mcp-worker) |
125
- | Keep a bridge running as a service | [Run Dalan as a service](docs/service-setup.md) |
126
- | Delegate T3 Code tasks to your worker, or give a worker T3 tools | [T3 and orchestration integration](docs/t3-integration.md#use-dalan-from-t3-code) and [T3 tools](docs/t3-reverse-control.md) |
127
- | See every command | `dalan help --all` |
75
+ In `auto` mode, a saved Gozar choice or an older saved localhost.run choice selects Gozar. Otherwise, auto uses a usable Tailscale route and selects Gozar when Tailscale is unavailable.
128
76
 
129
- <a id="your-own-first-job"></a>
77
+ <a id="expose-your-bridge"></a>
130
78
 
131
- ### Your own first job
79
+ ## Install a long-running bridge
132
80
 
133
- This gives your connected worker a task of your own, with no file to write and no JSON. Leave `try` running, and use a second shell. First install the CLI, select the trial home and type your task:
81
+ Install the CLI:
134
82
 
135
83
  ```sh
136
84
  npm install -g @tnunamak/dalan
137
- export DALAN_HOME=~/.local/share/dalan-trial
138
- printf 'Your task, on one line: '; IFS= read -r task
139
85
  ```
140
86
 
141
- If `npm install -g @tnunamak/dalan` fails with `EACCES`, your global npm directory belongs to root. Do not use `sudo`; [change npm's default directory](https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally), or skip the install and write `npx @tnunamak/dalan` wherever this section says `dalan`.
87
+ For a bridge that runs in the background on Linux, follow [Run Dalan as a service](docs/service-setup.md). `dalan service install` installs a systemd user service and registers an existing HTTPS origin with Gozar. It does not configure your reverse proxy. One bridge can serve several workers with built-in sign-in and a stable tool catalog.
142
88
 
143
- Type the task and press Enter. The shell stores it as plain text, so quotes, `$` and backticks in it are safe. Then submit it:
89
+ For an existing bridge, migrate worker settings into a new home before you install the service. Repeat `--source` for each old workers file. Use `--workspace-worker` for each worker that needs workspace access:
144
90
 
145
91
  ```sh
146
- dalan submit --worker local --execution none --deliver none --brief "$task Do not read files, run commands or call external services."
92
+ dalan service migrate-workers \
93
+ --home "$HOME/.local/share/dalan-service" \
94
+ --source "$HOME/OLD_BRIDGE/.config/dot-bridge/workers.json" \
95
+ --source-db "$HOME/OLD_BRIDGE/.local/share/dot-bridge/bridge.db" \
96
+ --workspace-worker WORKER
147
97
  ```
148
98
 
149
- `--brief` makes a read-only job from the text. `submit` prints a `Request ID:` line and a `Send your worker:` line. Paste that prompt into your worker's session, then wait for the result in the same shell. Replace `REQUEST_ID` with the ID that `submit` printed:
99
+ Migration reads source files without changing them. It copies only repository grants backed by validated audit records. If a checkpoint fails, all source grants are denied until the owner re-approves them. It denies and reports unaudited additions. It preserves supported worker settings, but does not copy OAuth connections, tokens, jobs, results or old destination approvals. The new service defaults execution to `none`. It preserves explicit `workspaceAllowed` settings. Workspace access stays denied by default; pass `--workspace-worker NAME` to grant it to each worker that needs it. Pair every connector again, create new subscriptions with fresh signing keys, and approve each new destination revision. See [service setup](docs/service-setup.md#install-one-bridge-for-several-workers) for details.
100
+
101
+ For a new service home, pass `--worker NAME` once for each worker instead of migrating. See `dalan help service` for the install options.
102
+
103
+ ## Give your connected agent a job
104
+
105
+ In another terminal, replace `WORKER` with the name of your connected worker:
150
106
 
151
107
  ```sh
152
- dalan wait REQUEST_ID --timeout 3600 && dalan get REQUEST_ID
108
+ dalan submit --worker WORKER --execution none --deliver none --brief "Explain what a database index does. Do not read files, run commands or call external services."
153
109
  ```
154
110
 
155
- **Check:** `dalan get` prints `Job REQUEST_ID: finished`, then `Summary:` and your worker's answer. It then prints `Next: dalan decide REQUEST_ID accepted`, and its last line is `Full record: dalan get REQUEST_ID --json`. It may also print an `Outcome:` line. Review the answer, then run the `Next:` command to record your decision. If `wait` times out, the job is still open: check it with `dalan get REQUEST_ID` and ask the worker to check Dalan again. If you passed `--home DIR` to `try`, export that directory as `DALAN_HOME` instead.
111
+ Send the agent the request ID that Dalan prints. Ask it to claim that job, follow its brief and return a report. Queuing a job does not start the agent.
156
112
 
157
- <a id="what-dalan-is"></a>
113
+ Replace `REQUEST_ID` with that ID, then wait and read the result:
158
114
 
159
- ## How Dalan works
115
+ ```sh
116
+ dalan wait REQUEST_ID
117
+ dalan get REQUEST_ID --json
118
+ ```
160
119
 
161
- Dalan has three roles, and one person can hold all three:
120
+ Read the report before recording your decision:
162
121
 
163
- - The **owner** runs the bridge, a small Node.js service that stores jobs and results in SQLite. The owner decides which workers may connect and which repositories each worker may use.
164
- - The **requester** submits jobs with the `dalan` command and reads the results. A requester can be you in a shell, a script, or a coding agent.
165
- - The **worker** is an MCP client that signs in to the bridge with OAuth. It calls `list_pending` to find work, `claim` to take a job, `progress` to report, and `finish` to send the result.
122
+ ```sh
123
+ dalan decide REQUEST_ID accepted
124
+ ```
166
125
 
167
- Workers pull jobs; Dalan never starts a worker. You prompt or schedule the worker in its own client. The [pull-worker guide](docs/pull-workers.md) describes schedules and wake signals once the first job works.
126
+ A finished job and an accepted result are separate steps. Acceptance does not apply a patch. After review, apply a finished job's patch with:
168
127
 
169
- A worker name, such as `local` or `chatgpt`, is a label that you choose for a connection. It does not select a vendor adapter: every worker uses the same job tools. A finished job and an accepted job are separate facts. Dalan returns reports and patches; it never pushes or merges them.
128
+ ```sh
129
+ dalan apply REQUEST_ID --dir PATH
130
+ ```
170
131
 
171
132
  <a id="separate-repository-assignment"></a>
172
133
 
173
134
  ## Give a worker a repository job
174
135
 
175
- The first job needs no repository. A repository job needs Git and Python 3.8 or newer on the bridge computer, because the bridge fetches the repository with them. The bridge also needs workspaces turned on, the worker needs a grant for that one repository, and the bridge needs a way to fetch it.
176
-
177
- A bridge started by `dalan try` already has workspaces on. Leave `try` running and use a second shell with `DALAN_HOME` set ([Next steps](#next-steps)). For a bridge you started by hand, add `DALAN_ENABLE_WORKSPACE=1` to the server command from [step 3 of the manual setup](docs/manual-setup.md#owner-and-requester-setup) and restart it. Without that setting, repository calls fail with `capability_not_enabled`.
178
-
179
- The repository can come from GitHub or from a clone on this computer:
180
-
181
- - **A GitHub repository.** The bridge fetches with `gh auth token`. Install the [GitHub CLI](https://cli.github.com/) and run `gh auth login` as the user who runs the bridge. A service with its own home needs its own [GitHub access](docs/operations.md#service-github-access).
182
- - **A clone on this computer (no GitHub login).** Pick a name `OWNER/REPO` for it, for example `local/my-project`. Start the bridge with a variable named `DALAN_GITHUB_URL_` plus that name in capitals, with every other character replaced by `_`, set to the clone's absolute path. For `local/my-project` the variable is `DALAN_GITHUB_URL_LOCAL_MY_PROJECT`. To use the trial bridge, stop `try` with Ctrl-C and start it again with the variable:
183
-
184
- ```sh
185
- DALAN_GITHUB_URL_LOCAL_MY_PROJECT=/path/to/my-project npx @tnunamak/dalan try
186
- ```
187
-
188
- The restart replaces your worker's connection with the demo worker again, so sign your worker in again as in [Connect your own worker](#connect-your-own-worker). For a bridge you started by hand, add the same variable to the server command instead. Use `local/my-project` wherever the steps below say `OWNER/REPO`. The clone needs at least one commit.
189
-
190
- 1. As owner, grant the worker one exact repository, then check the grant.
191
-
192
- ```sh
193
- dalan worker allow local OWNER/REPO
194
- dalan worker list local --json
195
- ```
196
-
197
- **Check:** the list contains only the repositories that you intend to allow. A new worker can use no repository; a grant for one repository does not grant its owner's other repositories. Grants take effect without a restart.
198
-
199
- 2. As requester, find the commit to pin. For a GitHub repository, `git ls-remote https://github.com/OWNER/REPO HEAD` prints it in the first column; for a local clone, run `git -C /path/to/my-project rev-parse HEAD`. Make a new request ID with `node -e "console.log(require('node:crypto').randomUUID())"`.
200
-
201
- 3. Save this job as `repository-job.json`, with your repository, commit and request ID. The job reads `README.md`; if the repository has none in its top directory, name another file.
202
-
203
- ```json
204
- {
205
- "schema_version": 1,
206
- "request_id": "req_<new UUID>",
207
- "brief": "Read README.md at the pinned commit and report its title. Do not run checks or change files.",
208
- "inputs": [{"github_repo": "OWNER/REPO", "base_sha": "<full 40-character commit SHA>"}],
209
- "expected_output": "README title and pinned revision; no patch or check claim.",
210
- "scope_paths": ["README.md"],
211
- "execution_scope": "read-only"
212
- }
213
- ```
214
-
215
- 4. Submit the job.
216
-
217
- ```sh
218
- dalan submit --worker local --execution none --deliver none --file repository-job.json --json
219
- ```
136
+ The first job needs no repository. Repository jobs need Git and Python 3.8 or newer on the bridge computer, workspaces enabled, and an exact repository grant for the worker. The hosted demo does not enable repository work. A repository grant and a job's read/write scope are separate limits; host checks are another capability.
220
137
 
221
- 5. In your worker's client, send this prompt with your request ID:
222
-
223
- > Request REQUEST_ID is your only job: claim it with Dalan, do what its brief asks, report progress and finish it with the claim_id. Stop if it is missing or cancelled. Claim no other job.
224
-
225
- Then wait for the result, read it and record your decision:
226
-
227
- ```sh
228
- dalan wait REQUEST_ID
229
- dalan get REQUEST_ID
230
- dalan decide REQUEST_ID accepted
231
- ```
232
-
233
- **Check:** the report names the file's title and the exact commit that you pinned. Each repository job takes one repository; submit separate jobs for more.
234
-
235
- If submission or claim says the repository is not allowed, run `dalan paths --json` to confirm that you are in the bridge's home, then `dalan worker list local --json`, and grant the exact repository. A queued job that loses its grant stays queued until the grant returns or you cancel the job. A GitHub authentication error means the bridge's home has no working GitHub credential.
236
-
237
- Repository workspaces and host checks (tests that the bridge runs) are separate capabilities. `try` does not turn on host checks. They need Linux, explicit owner opt-in, an allowlisted repository and check, and resource budgets; see [execution and evidence](docs/operations.md#execution-capability-and-check-evidence). A finished job or a passing check never authorizes a merge.
238
-
239
- <a id="expose-your-bridge"></a>
240
-
241
- ## Expose the bridge to other machines
242
-
243
- A worker connects from wherever its MCP client runs. `127.0.0.1` reaches only the bridge computer. A worker on another computer needs a network route to the bridge, and a hosted client such as ChatGPT needs a public HTTPS address.
138
+ ```sh
139
+ dalan worker allow WORKER OWNER/REPO
140
+ dalan worker list WORKER --json
141
+ ```
244
142
 
245
- For this, set up a separate, long-running bridge with a stable HTTPS address. The setup script writes a systemd user service (Linux) or a launchd agent (macOS). The default route is [Tailscale Funnel](https://tailscale.com/kb/1223/funnel), which needs no reverse proxy and no domain of your own:
143
+ Revoke access when the worker no longer needs it:
246
144
 
247
- 1. Complete the [Tailscale Funnel prerequisites](docs/service-setup.md#with-tailscale-funnel).
248
- 2. Run the setup script from the installed package (`npm install -g @tnunamak/dalan`):
145
+ ```sh
146
+ dalan worker deny WORKER OWNER/REPO
147
+ ```
249
148
 
250
- ```sh
251
- node "$(npm root -g)/@tnunamak/dalan/scripts/worker-bridge-setup.mjs" --worker NAME --port PORT --home HOME_PATH --expose tailscale --start
252
- ```
149
+ For a read-only repository job, replace the request ID, repository and full commit SHA below. Choose a file that exists at that commit:
150
+
151
+ ```json
152
+ {
153
+ "schema_version": 1,
154
+ "request_id": "req_<new UUID>",
155
+ "brief": "Read README.md at the pinned commit and report its title. Do not run checks or change files.",
156
+ "inputs": [{"github_repo": "OWNER/REPO", "base_sha": "<full 40-character commit SHA>"}],
157
+ "expected_output": "README title and pinned revision; no patch or check claim.",
158
+ "scope_paths": ["README.md"],
159
+ "execution_scope": "read-only"
160
+ }
161
+ ```
253
162
 
254
- From a checkout, run `node scripts/worker-bridge-setup.mjs` with the same options.
163
+ Save it as `repository-job.json`, then submit, wait, read the report and record your decision:
255
164
 
256
- Setup picks the first free Funnel port (443, 8443 or 10000); add `--funnel-port N` to choose one.
257
- 3. Connect the worker: a native client on another computer follows [Native client on a remote HTTPS bridge](docs/worker-clients.md#native-client-on-a-remote-https-bridge); a hosted client follows its recipe in [Connect any MCP worker](#connect-any-mcp-worker).
165
+ ```sh
166
+ dalan submit --worker WORKER --execution none --deliver none --file repository-job.json --json
167
+ dalan wait REQUEST_ID
168
+ dalan get REQUEST_ID
169
+ dalan decide REQUEST_ID accepted
170
+ ```
258
171
 
259
- If you already run an HTTPS reverse proxy, pass `--public-url https://bridge.example.com` instead of `--expose tailscale`; the [service guide](docs/service-setup.md) lists the routes to forward. A successful network check only shows that the address answers: run a first job through the new connection to prove that the worker can work.
172
+ The host's GitHub credential must be able to read the repository. For local clones, manual bridge setup and workspace configuration, see [manual setup](docs/manual-setup.md#owner-and-requester-setup) and the [setup reference](docs/setup-reference.md). Keep private repository credentials out of the job brief.
260
173
 
261
174
  <a id="support-matrix"></a>
175
+ <a id="connect-your-own-worker"></a>
262
176
 
263
177
  ## Connect any MCP worker
264
178
 
265
- Any client that speaks HTTP MCP and completes the bridge's OAuth sign-in can be a worker. Start with the [worker guide](docs/worker-clients.md); it applies to Claude Code, Codex CLI, a script or a hosted chat client. The recipes add only the registration details of one client; the job tools and grant rules stay the same.
179
+ Any client that speaks HTTP MCP and completes the bridge's OAuth sign-in can be a worker. Start with the [worker guide](docs/worker-clients.md); client recipes add registration details, while job tools and grant rules stay the same.
266
180
 
267
181
  | Client | Guide |
268
182
  |---|---|
269
- | Any MCP client | [Connect a worker client](docs/worker-clients.md): the common protocol and client requirements |
183
+ | Any MCP client | [Connect a worker client](docs/worker-clients.md) |
270
184
  | Codex CLI | [Native CLI worker: Codex CLI](docs/worker-clients.md#native-cli-worker-codex-cli) |
271
185
  | Claude Code | [Native CLI worker: Claude Code](docs/worker-clients.md#native-cli-worker-claude-code) |
272
- | opencode | [CLI worker: opencode](docs/worker-clients.md#cli-worker-opencode), with a model that supports tool calls |
186
+ | opencode | [CLI worker: opencode](docs/worker-clients.md#cli-worker-opencode) |
273
187
  | ChatGPT | [Connect ChatGPT](docs/connect-chatgpt.md) |
274
- | Muse Spark (Meta) | Connects like any remote MCP client: follow [Expose the bridge](#expose-your-bridge) and the [worker guide](docs/worker-clients.md); there is no client-specific recipe. |
275
- | Claude on the web (hosted) | [Claude cloud worker](docs/claude-worker-onboarding.md); separate from Claude Code |
276
-
277
- Start each new worker by hand for its first job. Dalan never starts a worker, including after a reboot.
278
-
279
- <a id="the-trial-home"></a>
188
+ | Claude on the web | [Claude cloud worker](docs/claude-worker-onboarding.md) |
280
189
 
281
- ## The trial home
190
+ ## Upgrade
282
191
 
283
- `try` keeps everything in one private directory, the trial home: `--home DIR` if you pass it, else `DALAN_HOME` if it is set, else `~/.local/share/dalan-trial`.
192
+ Read the release notes and follow the ordered [upgrade guide](docs/dalan-upgrade.md) before an upgrade. This release changes the worker tool list. After you upgrade, refresh the Dalan connection once in each worker client.
284
193
 
285
- - **What `try` refuses.** It refuses your real home directory and any non-empty directory without a `.dalan-trial` marker file, so it cannot take over an existing bridge home.
286
- - **Keep it dedicated.** A directory that has the marker is reused without checking its other files. On exit, `try` deletes `demo/` and every `req_*.json` request file in the home, revokes the demo grant and deletes the demo repository. A run that was killed is cleaned up at the next start.
287
- - **Use a short path on a local disk.** The bridge's admin socket path has a length limit, and network or FUSE file systems are not supported. If a home is too long or not on a local disk, use a new short directory: `npx @tnunamak/dalan try --home /short/local/path`. Do not use an existing bridge home.
288
- - **A second run reuses the home**, its worker profile, job history and port. It first replaces the worker's connection with the demo worker, so sign in again in your client and approve it again after the demo.
289
- - **To start over**, stop `try` and delete the trial home.
290
- - **For scripts**, run `dalan try < /dev/null`: with standard input closed, `try` runs the self-check and stops.
194
+ For a compatible-code restart, built-in OAuth keeps an unexpired access token only when the bridge uses the same private home and issuer and its grant and connection remain live. Access tokens last up to one hour. Before an upgrade or restore, stop the bridge and every other writer, then 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](docs/operations.md#upgrade-and-rollback).
291
195
 
292
- `try` takes three options:
196
+ 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.
293
197
 
294
- - `--home DIR`: the trial home.
295
- - `--port N`: the bridge port. The default is the port that the home used before, otherwise 8799 or the next free port. A home keeps its port; for another port, start a separate trial with `--home NEW_DIR --port N`.
296
- - `--callback PATTERN`: allow one more OAuth callback pattern; repeatable.
297
-
298
- `try` turns repository workspaces on (with at least 256 MiB of free disk) and makes only the demo repository available locally. Every other repository stays denied until you grant it. `try` does not turn on host checks.
299
-
300
- **Commands against the trial.** Set `DALAN_HOME` as in [Next steps](#next-steps). While the default trial home `~/.local/share/dalan-trial` exists and `DALAN_HOME` is unset, every command except `dalan help`, `dalan paths`, `dalan doctor`, `dalan try`, `dalan mcp`, `dalan --version` and `dalan -v` stops with `DALAN_HOME is not set` and prints the `export` line to run, so it cannot use your normal home by mistake. `dalan doctor` runs instead, reports that no bridge home is selected and prints the `export` line to run. Without that trial home, an unset `DALAN_HOME` means your normal home.
301
-
302
- **If the bridge does not start or stops.** `try` prints the path of `server.log` and three commands: one to read the log, one to retry the same home and port, and one to start in a new home with a free port. Read the log before you retry. `--port` alone cannot move an existing trial to another port.
303
-
304
- <a id="step-by-step"></a>
305
-
306
- ## Advanced: the same setup by hand
307
-
308
- `try` runs ordinary `dalan` commands in a private trial home. To run each piece yourself (a foreground bridge, your own worker name, or a client that `try` does not cover), follow [Manual setup](docs/manual-setup.md).
309
-
310
- <a id="owner-and-requester-setup"></a>
311
- <a id="worker-setup"></a>
312
- <a id="submit-finish-and-read-the-result"></a>
313
-
314
- It has three parts: [owner and requester setup](docs/manual-setup.md#owner-and-requester-setup), [worker setup](docs/manual-setup.md#worker-setup), and [submit, finish and read the result](docs/manual-setup.md#submit-finish-and-read-the-result), which has a complete first job in `first-job.json`. To give a job to the trial bridge with no file, see [Your own first job](#your-own-first-job).
315
-
316
- <a id="commands-that-matter"></a>
317
-
318
- ## Operate and recover
319
-
320
- - **Settings and commands.** The [setup reference](docs/setup-reference.md) lists environment settings and requester commands. The [protocol](PROTOCOL.md) defines the worker tools and lease rules.
321
- - **Before you change a deployed bridge**, read [operations](docs/operations.md). Before an upgrade, read the [release notes](CHANGELOG.md) and follow [upgrade and rollback](docs/operations.md#upgrade-and-rollback): older code can refuse an upgraded database.
322
- - **Backups.** Stop every process that writes to the bridge, then follow the [backup checklist](docs/dalan-upgrade.md#pre-upgrade-checklist). Back up receipts, artifacts and encryption keys with the databases. After a restore of older authorization state, a worker's newer token can fail with `invalid_grant`; connect that worker again.
323
- - **Optional integrations.** Besides [T3 Code](docs/t3-integration.md#use-dalan-from-t3-code), the [setup reference](docs/setup-reference.md) lists the other optional integrations, and ordinary jobs need none of them.
324
- - **Uninstall a trial.** Stop `dalan try` (Ctrl-C) and remove the connection from your client: `claude mcp remove --scope user local` or `codex mcp remove local`. Remove the `dalan` command as the [removal table](docs/operations.md#remove-an-installation) describes. The trial home holds private keys, connections and receipts: delete it only when you no longer need them. For a generated service, follow [service removal](docs/service-setup.md#remove-a-generated-service).
325
-
326
- <a id="repository-layout"></a>
327
-
328
- ## Names you may see
329
-
330
- Earlier versions of Dalan used other names, and some remain so that existing installations keep working. Use `dalan` and `DALAN_*` names for anything new. The [setup reference](docs/setup-reference.md#names-you-may-see) lists the older names and the optional integrations.
331
-
332
- <a id="from-source"></a>
333
-
334
- ## Install from source
335
-
336
- To work on Dalan, or to run the bridge by hand from a checkout:
337
-
338
- ```sh
339
- git clone https://github.com/tnunamak/dalan.git
340
- cd dalan
341
- npm ci
342
- node bin/dalan.mjs try
343
- ```
198
+ ## Reference
344
199
 
345
- To put `dalan` on your PATH from the checkout, run `npm link` once (undo it with `npm unlink -g @tnunamak/dalan`). Without it, write `node bin/dalan.mjs` wherever this README says `dalan`. Installing from npm instead: `npm install -g @tnunamak/dalan` (remove it with `npm uninstall -g @tnunamak/dalan`).
200
+ | Need | Command or guide |
201
+ | --- | --- |
202
+ | Command help | `dalan help --all` |
203
+ | Trial options | `dalan help try` |
204
+ | Bridge and queue state | `dalan status --json` |
205
+ | Results needing attention | `dalan inbox --all` |
206
+ | A full job record | `dalan get REQUEST_ID --json` |
207
+ | Host diagnostics | `dalan doctor --json` |
208
+ | File locations | `dalan paths --json` |
209
+ | Cancel a job | `dalan cancel REQUEST_ID` |
210
+ | Run a bridge in the background | [Service setup](docs/service-setup.md) |
211
+ | Upgrade or remove an installation | [Operations](docs/operations.md) |
212
+ | Release changes | [Changelog](CHANGELOG.md) |
346
213
 
347
- Read the [contributing guide](CONTRIBUTING.md) before you open a pull request, and the [security policy](SECURITY.md) to report a vulnerability.
214
+ When asking for help, share the failing step and error. Do not share private connector URLs, pairing codes or credentials.
348
215
 
349
- Licensed under the [Apache License 2.0](LICENSE).
216
+ Licensed under Apache-2.0.
package/SECURITY.md CHANGED
@@ -12,7 +12,7 @@ Include the affected revision, impact, and steps to reproduce with sanitized exa
12
12
 
13
13
  ## Secret redaction
14
14
 
15
- The bridge masks credentials in logs, alerts, errors, in the report text and progress notes it shows the owner, and in stored report artifacts. The local database keeps the exact text a worker sent, so protect the database and its backups. Redaction catches accidental leaks of registered secrets and known formats, including JSON-escaped spellings such as a `\u0073` escape inside a JSON string or key. It cannot stop a worker that deliberately encodes a secret it knows. Two cases pass unmasked: base64-embedded secrets and secrets split across log lines. See [docs/redaction.md](docs/redaction.md).
15
+ The bridge masks credentials in logs, alerts, errors, in the report text and progress notes it shows the owner, and in stored report artifacts. The local database keeps the exact text a worker sent, so protect the database and its backups. Redaction catches accidental leaks of registered secrets and known formats, including JSON-escaped spellings such as a `\u0073` escape inside a JSON string or key. It cannot stop a worker that deliberately encodes a secret it knows. Examples that can pass unmasked include base64-encoded unregistered secrets and secrets split across log lines. See [docs/redaction.md](docs/redaction.md).
16
16
 
17
17
  ## Known limits
18
18
 
package/bin/dalan.mjs CHANGED
@@ -22,6 +22,11 @@ if (help) {
22
22
  } else if (process.argv[2] === 'mcp') {
23
23
  // stdout is the protocol channel: nothing else may print to it. The tools run the CLI, which applies the DALAN_HOME rules.
24
24
  await (await import('../src/mcp-stdio.mjs')).main();
25
+ } else if (process.argv[2] === 'setup') {
26
+ await (await import('../src/setup.mjs')).main();
27
+ } else if (process.argv[2] === 'service') {
28
+ try { await (await import('../src/service.mjs')).serviceMain(process.argv.slice(3)); }
29
+ catch (error) { process.stderr.write(`dalan: service: ${error.message}\n`); process.exitCode = 1; }
25
30
  } else if (process.argv[2] === 'try') {
26
31
  await (await import('../src/try.mjs')).main();
27
32
  } else {