@tnunamak/dalan 0.0.0-stage → 0.5.2

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 (182) hide show
  1. package/CHANGELOG.md +172 -0
  2. package/CONTRIBUTING.md +26 -0
  3. package/LICENSE +204 -0
  4. package/PROTOCOL.md +339 -0
  5. package/README.md +348 -2
  6. package/SECURITY.md +30 -0
  7. package/bin/dalan.mjs +38 -0
  8. package/bin/dot-acp-agent.mjs +377 -0
  9. package/bin/dot-alert.mjs +9 -0
  10. package/bin/dot-deadman.mjs +82 -0
  11. package/bin/dot-heartbeat.mjs +29 -0
  12. package/bin/dot-pr-reviewer.mjs +32 -0
  13. package/bin/dot-worker.mjs +755 -0
  14. package/docs/chatgpt-worker-onboarding.md +112 -0
  15. package/docs/claude-worker-onboarding.md +113 -0
  16. package/docs/connect-chatgpt.md +78 -0
  17. package/docs/connection-longevity.md +37 -0
  18. package/docs/dalan-upgrade.md +242 -0
  19. package/docs/deadman.md +59 -0
  20. package/docs/dot-pr-reviewer.config.example.json +9 -0
  21. package/docs/durability-audit.md +27 -0
  22. package/docs/keycloak-client-chatgpt-dot-bridge.json +59 -0
  23. package/docs/keycloak-oauth-setup.md +30 -0
  24. package/docs/local-agent-mcp.md +39 -0
  25. package/docs/manual-setup.md +135 -0
  26. package/docs/mirror-fetch.md +98 -0
  27. package/docs/operations.md +751 -0
  28. package/docs/operator-duties.md +68 -0
  29. package/docs/owner-integrator.md +27 -0
  30. package/docs/portable-auth-profile.md +109 -0
  31. package/docs/pr-head-reviewer.md +54 -0
  32. package/docs/pr-preflight.md +26 -0
  33. package/docs/pull-workers.md +97 -0
  34. package/docs/redaction.md +27 -0
  35. package/docs/service-setup.md +166 -0
  36. package/docs/setup-reference.md +80 -0
  37. package/docs/t3-connector-icon.png +0 -0
  38. package/docs/t3-integration.md +49 -0
  39. package/docs/t3-result-retry-delivery.md +41 -0
  40. package/docs/t3-reverse-control.md +107 -0
  41. package/docs/usage.md +439 -0
  42. package/docs/worker-clients.md +285 -0
  43. package/integrations/t3/acp-kit/src/capability.mjs +25 -0
  44. package/integrations/t3/acp-kit/src/errors.mjs +13 -0
  45. package/integrations/t3/acp-kit/src/index.mjs +5 -0
  46. package/integrations/t3/acp-kit/src/lock.mjs +155 -0
  47. package/integrations/t3/acp-kit/src/session-store.mjs +36 -0
  48. package/integrations/t3/acp-kit/src/t3-envelope.mjs +62 -0
  49. package/package.json +65 -4
  50. package/packages/job-core/README.md +18 -0
  51. package/packages/job-core/index.mjs +2 -0
  52. package/packages/job-core/package.json +8 -0
  53. package/packages/job-core/protocol/canonical.mjs +11 -0
  54. package/packages/job-core/protocol/v0/command.schema.json +1154 -0
  55. package/packages/job-core/protocol/v0/event.schema.json +77 -0
  56. package/packages/job-core/protocol/v0/reply.schema.json +59 -0
  57. package/packages/job-core/transitions.mjs +25 -0
  58. package/scripts/daily-selfcheck.mjs +135 -0
  59. package/scripts/lib/expose-tailscale.mjs +408 -0
  60. package/scripts/live-trial/common.mjs +272 -0
  61. package/scripts/monitor-targets.mjs +44 -0
  62. package/scripts/upgrade-drain.mjs +39 -0
  63. package/scripts/worker-bridge-setup.mjs +925 -0
  64. package/src/ack-ledger.mjs +37 -0
  65. package/src/acp-bridge.mjs +412 -0
  66. package/src/acp-context.mjs +138 -0
  67. package/src/admin-socket.mjs +14 -0
  68. package/src/alerts.mjs +147 -0
  69. package/src/artifact-journal.mjs +75 -0
  70. package/src/as-files.mjs +347 -0
  71. package/src/as-store.mjs +456 -0
  72. package/src/as.mjs +497 -0
  73. package/src/auth.mjs +166 -0
  74. package/src/builtin-http.mjs +22 -0
  75. package/src/check-coverage.mjs +38 -0
  76. package/src/check-lint.mjs +88 -0
  77. package/src/check-readiness.mjs +112 -0
  78. package/src/check-response.mjs +19 -0
  79. package/src/claim-command-ledger.mjs +51 -0
  80. package/src/cli-help.mjs +172 -0
  81. package/src/cli-name.mjs +16 -0
  82. package/src/connect-cli.mjs +126 -0
  83. package/src/consumers.mjs +61 -0
  84. package/src/deadman.mjs +329 -0
  85. package/src/delivery.mjs +19 -0
  86. package/src/demo-worker.mjs +150 -0
  87. package/src/destinations/index.mjs +23 -0
  88. package/src/destinations/none.mjs +15 -0
  89. package/src/destinations/t3.mjs +109 -0
  90. package/src/diagnostic.mjs +78 -0
  91. package/src/docs-url.mjs +9 -0
  92. package/src/drain-runner.mjs +9 -0
  93. package/src/drained-slot.mjs +53 -0
  94. package/src/drained.mjs +40 -0
  95. package/src/durable-waiters.mjs +236 -0
  96. package/src/env.mjs +19 -0
  97. package/src/execution.mjs +112 -0
  98. package/src/failure-type.mjs +28 -0
  99. package/src/get-summary.mjs +32 -0
  100. package/src/git-env.mjs +15 -0
  101. package/src/host-budget-receipts.mjs +154 -0
  102. package/src/host-budget-seccomp.py +33 -0
  103. package/src/host-budget-service.mjs +54 -0
  104. package/src/host-budget-stop.mjs +26 -0
  105. package/src/host-budget-storage.py +259 -0
  106. package/src/host-budget.mjs +149 -0
  107. package/src/host-cgroup.mjs +23 -0
  108. package/src/host-check-allowlist.mjs +42 -0
  109. package/src/host-execution-policy.mjs +38 -0
  110. package/src/host-health.mjs +34 -0
  111. package/src/host-stop-reverify.mjs +44 -0
  112. package/src/inbox.mjs +55 -0
  113. package/src/integrator.mjs +322 -0
  114. package/src/job-retention.mjs +69 -0
  115. package/src/legacy-names.mjs +8 -0
  116. package/src/lifecycle.mjs +291 -0
  117. package/src/limits.mjs +31 -0
  118. package/src/loopback.mjs +9 -0
  119. package/src/mcp-outcome.mjs +70 -0
  120. package/src/mcp-stdio.mjs +191 -0
  121. package/src/mirror-fetch-lock.py +164 -0
  122. package/src/mirror-fetch.mjs +174 -0
  123. package/src/notify-ledger.mjs +82 -0
  124. package/src/objectives.mjs +129 -0
  125. package/src/owner-report-artifact.mjs +66 -0
  126. package/src/patch-apply.mjs +84 -0
  127. package/src/path-syntax.mjs +16 -0
  128. package/src/paths.mjs +67 -0
  129. package/src/pr-head-reviewer.mjs +596 -0
  130. package/src/pr-preflight.mjs +51 -0
  131. package/src/prepared-node-modules.mjs +129 -0
  132. package/src/projects.mjs +480 -0
  133. package/src/protocol-artifact-commands.mjs +52 -0
  134. package/src/protocol-delivery-driver.mjs +167 -0
  135. package/src/protocol-finish.mjs +100 -0
  136. package/src/protocol-owner-command.mjs +35 -0
  137. package/src/protocol-owner-mutations.mjs +22 -0
  138. package/src/protocol-owner-waiters.mjs +67 -0
  139. package/src/protocol-retention.mjs +52 -0
  140. package/src/protocol-services.mjs +61 -0
  141. package/src/protocol-stop-observer.mjs +131 -0
  142. package/src/publish-plan.mjs +245 -0
  143. package/src/redaction.mjs +763 -0
  144. package/src/rejections.mjs +18 -0
  145. package/src/request-log.mjs +102 -0
  146. package/src/restore-check.mjs +90 -0
  147. package/src/result-binding.mjs +65 -0
  148. package/src/runtime-check.mjs +13 -0
  149. package/src/sandbox-supervisor.mjs +105 -0
  150. package/src/schema-subset.mjs +186 -0
  151. package/src/scopes.mjs +15 -0
  152. package/src/server.mjs +1340 -0
  153. package/src/shutdown-signal.mjs +12 -0
  154. package/src/signal-sandbox-processes.py +56 -0
  155. package/src/signal.mjs +119 -0
  156. package/src/status-evidence.mjs +47 -0
  157. package/src/status-summary.mjs +54 -0
  158. package/src/store.mjs +3057 -0
  159. package/src/submission-policy.mjs +623 -0
  160. package/src/subscription-storage.mjs +64 -0
  161. package/src/t3-audit.mjs +120 -0
  162. package/src/t3-control.mjs +102 -0
  163. package/src/t3-transport.mjs +158 -0
  164. package/src/t3.mjs +209 -0
  165. package/src/terminal-safe.mjs +19 -0
  166. package/src/tool-registry.mjs +451 -0
  167. package/src/try-command.mjs +11 -0
  168. package/src/try.mjs +589 -0
  169. package/src/webhooks.mjs +86 -0
  170. package/src/work-order.mjs +265 -0
  171. package/src/worker-instructions.mjs +26 -0
  172. package/src/worker-prompt.mjs +4 -0
  173. package/src/workers.mjs +622 -0
  174. package/src/workspace.mjs +1058 -0
  175. package/systemd/dot-bridge-heartbeat.service +18 -0
  176. package/systemd/dot-bridge-heartbeat.timer +10 -0
  177. package/systemd/dot-bridge-selfcheck.service +12 -0
  178. package/systemd/dot-bridge-selfcheck.timer +11 -0
  179. package/systemd/dot-bridge.service +17 -0
  180. package/systemd/dot-deadman.service +30 -0
  181. package/systemd/dot-pr-reviewer.service +11 -0
  182. package/systemd/dot-pr-reviewer.timer +10 -0
@@ -0,0 +1,166 @@
1
+ # Run Dalan as a service
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.
4
+
5
+ ## Keep a local trial working
6
+
7
+ 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.
8
+
9
+ To go from a trial to a service:
10
+
11
+ 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.
12
+ 2. Run setup below with a new home. It makes a new bridge, with its own keys and port.
13
+ 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`.
14
+ 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:
15
+
16
+ ```sh
17
+ export DALAN_HOME=TRIAL_HOME
18
+ port="$(sed -n 's#.*"public_url": *"http://127.0.0.1:\([0-9][0-9]*\)".*#\1#p' "$(dalan paths --config-root)/as.json")"
19
+ HOME="$DALAN_HOME" DALAN_LOOPBACK=1 DALAN_AUTH_MODE=builtin DALAN_PORT="$port" node src/server.mjs
20
+ # second shell, with DALAN_HOME set to TRIAL_HOME again:
21
+ dalan get REQUEST_ID --json
22
+ ```
23
+
24
+ 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.
25
+
26
+ 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.
27
+
28
+ ## Owner setup
29
+
30
+ 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. The script checks those before writing a service with `--start`.
31
+
32
+ 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.
33
+
34
+ **After a reboot on macOS:**
35
+
36
+ - **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.
37
+ - **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.
38
+
39
+ **Symptom: `launchctl print` prints `Could not find service`.**
40
+
41
+ - That print only says that the agent is not in the `user/UID` domain; it does not say the service failed.
42
+ - **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`.
43
+ - **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).
44
+
45
+ The domain and label are the ones that `worker-bridge-setup.mjs` writes.
46
+
47
+ ### After a reboot
48
+
49
+ The bridge and the worker come back by separate rules:
50
+
51
+ - **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`; setup warns when it is off), it is the boot. Check with `systemctl --user is-active dot-bridge-NAME.service`, which must print `active`.
52
+ - **Bridge, macOS.** It starts at your login, as described above.
53
+ - **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.
54
+
55
+ 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.
56
+
57
+ 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.
58
+
59
+ 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.
60
+
61
+ ### With an existing HTTPS reverse proxy
62
+
63
+ 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.
64
+
65
+ Forward the following routes without removing their prefixes, methods, query strings, authorization headers or cookies.
66
+
67
+ | Route | Purpose |
68
+ |---|---|
69
+ | `/<secret>/mcp` | Carries worker MCP requests. |
70
+ | `/.well-known/oauth-protected-resource/<secret>/mcp` | Identifies the protected resource and authorization server. |
71
+ | `/.well-known/oauth-authorization-server/<secret>/oauth` | Publishes OAuth endpoints. |
72
+ | `/.well-known/openid-configuration/<secret>/oauth` | Provides the discovery alias. |
73
+ | `/<secret>/oauth` and `/<secret>/oauth/*` | Handle OAuth and browser pairing. |
74
+ | `/signal/*` | Answers wake hooks when configured. |
75
+
76
+ The proxy should terminate TLS and keep secret-bearing paths out of access logs. An unauthenticated request to `/admin` should return 404.
77
+
78
+ 2. Generate and start the bridge from a checkout:
79
+
80
+ ```sh
81
+ node scripts/worker-bridge-setup.mjs --worker NAME --public-url https://bridge.example.com --port PORT --home HOME_PATH --start
82
+ ```
83
+
84
+ From an npm install (`scripts/worker-bridge-setup.mjs` ships in the package), use the installed copy with the same options:
85
+
86
+ ```sh
87
+ 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
88
+ ```
89
+
90
+ 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.
91
+
92
+ 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.
93
+
94
+ ```sh
95
+ dalan status --json
96
+ ```
97
+
98
+ 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).
99
+
100
+ 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`:
101
+
102
+ - Pairing: `dalan connect start --worker NAME` and `dalan connect approve CODE --worker NAME`.
103
+ - Submission: `dalan submit --worker NAME ...` for the first job and for every repository job.
104
+ - Repository grants: `dalan worker allow NAME OWNER/REPO` and `dalan worker list NAME --json`.
105
+
106
+ `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.
107
+
108
+ ### With Tailscale Funnel
109
+
110
+ 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.
111
+
112
+ 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:
113
+
114
+ ```sh
115
+ brew install tailscale && sudo brew services start tailscale && sudo tailscale up
116
+ ```
117
+
118
+ See [macOS variants](https://tailscale.com/docs/concepts/macos-variants); on Linux, use the [installation guide](https://tailscale.com/download).
119
+ 2. **Signed in.** Run `tailscale version` and `tailscale status`. The host must show as signed in.
120
+ 3. **MagicDNS** (Tailscale's automatic DNS names for your devices). Turn it on at the [DNS page](https://console.tailscale.com/admin/dns).
121
+ 4. **HTTPS Certificates.** On the same page, choose Enable HTTPS. Your machine's name then appears in public certificate transparency logs.
122
+ 5. **Funnel policy.** In [Access controls](https://console.tailscale.com/admin/acls), add Funnel to the policy (the "Add Funnel to policy" button).
123
+ 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.
124
+
125
+ Run setup with Funnel instead of an explicit public URL. From a checkout:
126
+
127
+ ```sh
128
+ node scripts/worker-bridge-setup.mjs --worker NAME --port PORT --home HOME_PATH --expose tailscale --start
129
+ ```
130
+
131
+ From an npm install:
132
+
133
+ ```sh
134
+ node "$(npm root -g)/@tnunamak/dalan/scripts/worker-bridge-setup.mjs" --worker NAME --port PORT --home HOME_PATH --expose tailscale --start
135
+ ```
136
+
137
+ 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.
138
+
139
+ 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.
140
+
141
+ 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.
142
+ 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.
143
+
144
+ ### When setup stops before verification
145
+
146
+ 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.
147
+
148
+ 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`.
149
+
150
+ ```sh
151
+ node scripts/worker-bridge-setup.mjs --retry-public-check --worker NAME --public-url EXPOSURE_URL --port PORT --home HOME_PATH
152
+ ```
153
+
154
+ 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.
155
+
156
+ ## Remove a generated service
157
+
158
+ 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).
159
+
160
+ ```sh
161
+ node scripts/worker-bridge-setup.mjs --remove --worker NAME --home HOME_PATH
162
+ ```
163
+
164
+ From an npm install, run `node "$(npm root -g)/@tnunamak/dalan/scripts/worker-bridge-setup.mjs"` with the same options.
165
+
166
+ 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.
@@ -0,0 +1,80 @@
1
+ # Dalan setup reference
2
+
3
+ Use this page after the [README](../README.md) first-job path works. It lists server settings, requester commands, worker tools and legacy service files. The package and CLI are named `dalan`; the command names of the `dot-bridge` package are not installed.
4
+
5
+ ## Environment and storage
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`.
8
+
9
+ | Setting | Effect |
10
+ |---|---|
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. |
13
+ | `DALAN_AUTH_MODE=builtin` | Uses the built-in OAuth authorization server. `oauth` selects an external issuer instead. |
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
+ | `DALAN_PORT` | Sets the HTTP listener port; the server default is 8787. |
16
+ | `DALAN_ENABLE_WORKSPACE=1` | Enables repository and artifact tools. It does not authorize host checks. |
17
+ | `DALAN_TEST_OAUTH=1` | Allows HTTP for the existing isolated OAuth trial when `NODE_ENV` is not `production`. This is not a production setting. |
18
+ | `DALAN_DEV_ALLOW_UNAUTHENTICATED=1` | Allows the public route to run unauthenticated when `NODE_ENV` is not `production`, but only on a loopback bind (`DALAN_BIND_HOST=127.0.0.1`, `::1` or `localhost`); on a non-loopback bind the server refuses to start. For non-production fixtures only. |
19
+ | `DALAN_ALLOW_INSECURE_PUBLIC=1` | Same loopback-only unauthenticated allowance; it never bypasses the TLS reverse proxy requirement on a non-loopback bind. For non-production fixtures only. |
20
+ | `DALAN_CATALOG_PROFILE` | Selects `stable` by default, or an opt-in `questions-v1`, `protocol-v0` or compatibility `legacy-v46` catalog. Review the protocol before changing it. |
21
+
22
+ The corresponding old `DOT_BRIDGE_*` environment names remain readable for compatibility. Existing storage paths such as `.config/dot-bridge` are technical compatibility names, not worker identities. Startup never moves or merges data. To change roots, stop every component and follow the [explicit path migration](dalan-upgrade.md#existing-homes-and-explicit-path-migration) steps; do not rename state directories ad hoc. A service setup writes its private resource URL to `<bridge home>/resource-url`; manual init creates the OAuth files and the server creates the secret path configuration.
23
+
24
+ ## Requester commands
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.
27
+
28
+ | Command | Result |
29
+ |---|---|
30
+ | `dalan status --explain` | Explains queue depth and active claims. |
31
+ | `dalan doctor --json` | Reports local execution readiness and configuration warnings. |
32
+ | `dalan submit --worker NAME --execution none --deliver none --file job.json --json` | Queues a job without requesting host checks or automatic owner delivery. |
33
+ | `dalan wait REQUEST_ID` | Waits for completion, a question, a blocker, cancellation or timeout. The default timeout is 300 seconds. |
34
+ | `dalan get REQUEST_ID --json` | Reads progress, report, artifacts and evidence; marks the result read. |
35
+ | `dalan inbox --all --json` | Finds receipts across requester sessions without marking results read. Covers the last 72 hours unless you pass `--since`. |
36
+ | `dalan note REQUEST_ID "text"` | Appends a job-specific message. |
37
+ | `dalan questions REQUEST_ID --json` | Lists identified questions when the selected catalog supports them. |
38
+ | `dalan answer REQUEST_ID QUESTION_ID "text"` | Answers an identified question; an ordinary note does not answer it. |
39
+ | `dalan artifact ARTIFACT_ID --output PATH` | Downloads a sealed artifact after get or wait records its owning request. PATH must not exist; its directory must. |
40
+ | `dalan decide REQUEST_ID accepted` | Records a review decision. Other choices are `applied`, `useful_no_change`, `useful_negative` and `not_useful`. |
41
+ | `dalan apply REQUEST_ID --dir CHECKOUT` | Verifies and applies a returned patch, then records `applied`. |
42
+ | `dalan cancel REQUEST_ID` | Withdraws a job. It does not prove that worker compute has stopped. |
43
+ | `dalan worker list NAME --json` | Shows a worker's exact repository grants and retained policy changes. |
44
+
45
+ Wait exits with 0 for a finished job, 1 for a command or transport error, 3 for a question or blocker, 4 for cancellation, 5 for a usage break, or 124 for timeout. Its summary need not contain the full report; use get before deciding.
46
+
47
+ A fresh shell with no session ID lists receipts across this bridge home. A resumed requester may have a different session label: use `dalan inbox --producer SAVED_ID --json` for the saved label, or `--all` to recover without it.
48
+
49
+ <a id="callback-patterns"></a>
50
+
51
+ ## Callback patterns
52
+
53
+ `dalan connect allow-callback PATTERN` and `dalan try --callback PATTERN` take a pattern for the OAuth callback URI of a worker client. Allow the narrowest pattern for the client: its exact host and path. A callback pattern follows these rules:
54
+
55
+ - A loopback pattern is `http://HOST/PATH` with no port. It admits that exact host and path on any port. `127.0.0.1`, `localhost` and `[::1]` are the only HTTP hosts allowed, and `127.0.0.1` does not match `localhost`.
56
+ - An HTTPS pattern is `https://HOST[:PORT]/PATH`. Scheme, host and port match exactly. In the path, a whole `*` segment stands for one segment of letters, digits, `_` and `-`; use it only for a callback with a varying segment.
57
+ - A pattern may not contain a query or fragment, and a callback URI that has one never matches.
58
+
59
+ ## Worker tools and optional authority
60
+
61
+ The [protocol](../PROTOCOL.md) defines the full tool list, inputs, outputs, catalogs and lease behavior. The worker uses `list_pending`, `claim`, `progress` and `finish` for the basic job lifecycle. Repository tools require a workspace grant and respect the job's pinned revision and paths.
62
+
63
+ T3 reverse control is opt-in. Its thread tools and `notify_owner` act outside a job claim. Review [T3 authority and audit](t3-reverse-control.md) before granting it. A worker does not need T3 to finish an ordinary job. The six `t3_thread_*` tools (`list`, `read` and `wait`, which read, and `create`, `send` and `set`, which start turns, send messages and change thread settings) are off unless the operator sets `DALAN_ENABLE_T3_TOOLS=1`, and then only a worker whose profile has the `t3` capability can call them. A fresh `dalan init` profile has no `t3` capability. The legacy `dot` profile, used when the workers file does not exist, has it. Granting it gives that worker the owner's full authority over every thread on the local T3: it can read, start, message and reconfigure any thread, because the bridge does not check which thread the caller owns. Cancelling a job does not revoke it. Grant it only to a fully trusted worker.
64
+
65
+ For upgrades, use the [changelog](../CHANGELOG.md) and [operations procedure](operations.md#upgrade-and-rollback). Package versions, database schema numbers and worker catalogs have different compatibility boundaries; replacing an executable is not a rollback of migrated state.
66
+
67
+ ## Legacy service examples
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.
70
+
71
+ <a id="names-you-may-see"></a>
72
+
73
+ ## Names you may see
74
+
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
+
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`.
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
+ - **`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
+ - **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.
Binary file
@@ -0,0 +1,49 @@
1
+ # T3 and orchestration integration
2
+
3
+ This page is for installations where an orchestrator, such as the T3 Code desktop app or an automated producer, submits jobs and receives results. Ordinary jobs from a shell or a coding agent do not need it; see the [requester reference](usage.md).
4
+
5
+ The T3 tools themselves (thread create, send, wait and set) are described in [T3 tools](t3-reverse-control.md).
6
+
7
+ <a id="use-dalan-from-t3-code"></a>
8
+
9
+ ## Use Dalan from T3 Code
10
+
11
+ T3 Code can delegate a task to your worker as if the worker were a model. The package installs `dalan-acp-agent`, an ACP (Agent Client Protocol) agent. In T3 Code, add a custom ACP agent that runs this command with the environment below; T3 starts one process per thread, and the adapter sends each new prompt in the thread to Dalan as a job (a prompt that repeats an earlier one reuses that job); the worker's report comes back as the reply and ends with the `dalan decide` line.
12
+
13
+ ```text
14
+ command: dalan-acp-agent
15
+ DOT_ACP_WORKER=chatgpt # the worker name; unset uses the bridge's default worker
16
+ DOT_ACP_MODEL=chatgpt # the model id T3 shows
17
+ DOT_ACP_LABEL="ChatGPT worker" # the label T3 shows
18
+ DOT_ACP_SOCKET=/path/to/admin.sock # the bridge's admin socket; the default is the default Dalan home, not DALAN_HOME
19
+ ```
20
+
21
+ Add one entry for each worker, so a ChatGPT worker and a Muse Spark worker each appear as a model. These adapter settings keep the `DOT_ACP_*` names. Builds also need `DALAN_ACP_BUILD_OWNERS`: see [Builds through the T3 worker provider](#builds-through-the-t3-worker-provider).
22
+
23
+ A separate, opt-in feature lets a worker list, read and write T3 threads. It gives the worker write and control access to your T3 threads, so read [T3 tools](t3-reverse-control.md) before you enable it.
24
+
25
+ <a id="t3-task-thread-delivery"></a>
26
+
27
+ ## T3 task-thread delivery
28
+
29
+ Quiet delivery (`none`) is the default. Only for an explicit visible task-thread notice, obtain the exact owner thread ID from `t3_thread_configuration` (current thread). A delegated child returning to its parent may use `orchestrator_capabilities.parentThreadId`. Verify the chosen ID and its environment with `t3code --json threads inspect --thread ID`. T3 delivery requires a CLI that supports `threads inspect`; metadata lookup fails closed if that command fails, without falling back to a transcript read, and quiet delivery needs no T3 CLI. Do not guess the ID from cwd or a recent thread. Protected top-level threads retain notices quietly.
30
+
31
+ <a id="main-thread-guard"></a>
32
+
33
+ ## Main-thread guard
34
+
35
+ `~/.config/dalan/limits.json` accepts `main_thread_ids`, an array of non-empty strings (default `[]`), next to `max_claimed_outer_assignments`. Example: `{"max_claimed_outer_assignments": 6, "main_thread_ids": ["00000000-0000-4000-8000-000000000001"]}`. Every key in the file is optional and has a default. It accepts the bounded ASCII forms T3 emits, including UUID, `mcp:UUID`, delegated-task, and provider-native IDs (8–1024 characters; letters, digits, `.`, `_`, `:`, `%`, and `-`). The service validates the file at start and rereads `main_thread_ids` on every T3 submit, so edits apply without a restart. The admin `/submit` endpoint rejects a thread in that list unless `allow_main:true` is authenticated with the operator key; the CLI reads that key for `--allow-main`. This applies to retries too. Delivery checks the protected list again and suppresses results and blockers even for previously submitted assignments or operator-admitted bindings. Stored legacy mute facts also quiet an individual binding; no current command or admin mutation route creates watch or mute facts. Results and questions remain available through `wait`/`get`; retained legacy watch rows remain visible through `get` and do not wake `wait` when suppressed.
36
+
37
+ <a id="objective-identity"></a>
38
+
39
+ ## Objective identity
40
+
41
+ `dalan submit` takes optional `--objective-key KEY --revision REV --task-kind KIND` (each at most 512 bytes) and `--source drainer|fix-loop|agent|unknown` (default `agent`; `drainer` and `fix-loop` must be proven by the request id, see [Consumers are assigned by code](#consumers-are-assigned-by-code)). They are stored beside the assignment, not in it, and recorded in the local receipt; a retry that omits a flag reuses the receipt's value, and a retry that changes one is a conflict. Metrics use them to count rework (same objective, new revision) and duplicates (same objective and revision, new request). `dalan backfill-objectives --dry-run --json` (operator key) shows how many older rows the receipts, manifests and legacy fix ledger can prove; without `--dry-run` it fills them. See [operations](operations.md#objective-identity).
42
+
43
+ ## Builds through the T3 worker provider
44
+
45
+ A `delegate_task` to the worker provider whose task starts with `[dot-build] <path> ...` (after an optional `[dot-decision:ID]` line; T3's role preamble is removed first) is a build. The adapter submits it with `execution_scope: "implementation"`, `scope_paths` set to the listed paths, and meta `task_kind: "build"`, using the requester's HEAD. A build is refused unless `DALAN_ACP_BUILD_OWNERS` (or the legacy `DOT_ACP_BUILD_OWNERS`) is set to a comma-separated list of authorized repository owners. An empty, missing or malformed list fails closed. `DALAN_ACP_REPO_CONFIG` (or the legacy `DOT_ACP_REPO_CONFIG`) can select the local repository policy file; otherwise the adapter reads the Dalan producer configuration, with legacy path fallback. That file must provide valid `repo_selection.exclude` and `deny_path_terms` arrays; missing or malformed policy also fails closed. A brief must name no path outside its list, and at most five files may be named. Optional: `DALAN_ACP_PROSE_CHECK_OWNERS` lists the owners whose added prose is checked by an external prose linter. `DALAN_ACP_PROSE_CHECK` names its executable, which the adapter runs as `COMMAND check --stdin --kind doc --json` with the added lines on stdin; when the owner list is unset or empty, no prose check runs; an enabled check without an executable reports an error; a malformed non-empty list returns an error. The result includes the base, check results, patch preview, fetch command and verdict commands. `dalan get`, `artifact`, `accept` and `reject` work on adapter rows: with no CLI receipt, the CLI derives the owner token from `~/.config/dalan/acp-secret`.
46
+
47
+ ## Consumers are assigned by code
48
+
49
+ Who a result is for comes from the code path that produced the request, never from what the submitter writes. A submit request, its `meta` or its assignment that sets `value_tier` or `tier`, or names a system consumer (`consumer` as `fix_pipeline`, `ledger` or `reserve`, or one that is not a string or `{type}`), is refused (`assignment declares tier; the bridge assigns the consumer and tier from the code path...`). A drainer manifest, or a submit whose source is `drainer` or `fix-loop`, may not declare `severity` either; an agent's `severity` hint passes, since agent work is already the first tier. Naming a requester (`consumer: {type: 'thread', id}`) is not refused, and nothing reads it yet. `--source drainer` and `--source fix-loop` must be proven by the request id of their own code (`drainerRequestId`, `fixLoopRequestId`); a forged claim is refused. Drainer work is always background priority, so no manifest can place itself ahead of agent-requested work. The consumer types are `agent` (tier 0), `fix_pipeline` (tier 1) and `reserve` (tier 5, work nobody asked for). `ledger` has no code path yet, so nothing can hold it. The rules live in `src/consumers.mjs`. Nothing orders the queue by tier yet; only the `normal` and `background` priority does.
@@ -0,0 +1,41 @@
1
+ # Retry-stable T3 job results
2
+
3
+ JOB-RESULT delivery derives receiver IDs from `sha256(JSON.stringify([job_id, effect_id]))`. The job ID is the immutable request ID and the effect ID is the durable T3 outbox event ID. Epoch is not an input. The bridge sends both a deterministic command ID and message ID through `orchestration.dispatchCommand`; receiver command receipts therefore remain stable across fresh T3 auth and WebSocket sessions.
4
+
5
+ The adapter uses the `t3 auth session issue/revoke` commands, the local T3 runtime descriptor, the authenticated `/api/auth/websocket-ticket` endpoint, and the T3 orchestration WebSocket RPC. It imports no private `@bvdm/t3code-cli` modules. Tokens and tickets stay in memory and are not included in errors or output. The RPC request matches the installed CLI transport: `{_tag:"Request",id,tag:"orchestration.dispatchCommand",payload,headers:[]}` and the response is its matching `Exit` message. T3 requires protocol 2 and a loopback origin.
6
+
7
+ The bridge process must be able to resolve both `t3code` (submit and delivery run `threads inspect` against `http://127.0.0.1:3773` through it) and the matching `t3` auth command on `PATH`. Set `DALAN_T3_COMMAND` to the auth command's executable path when it is not on the service `PATH`; it does not configure `t3code`; set `T3CODE_HOME` if T3 uses a non-default data directory.
8
+
9
+ By default, result delivery selects `steer_active` for the latest active run; if no active run exists, it selects `queue_after_active` when a queued run exists and `start_immediately` otherwise. The ordinary delivery path verifies the stored thread and environment binding before dispatch. The pinned receiver implementation does not reject a same-key payload mismatch, so the bridge relies on the immutable job/effect body staying unchanged.
10
+
11
+ ## Focused mock check
12
+
13
+ Run `node scripts/t3-result-delivery-test.mjs`. The mock persists a receiver receipt, message, run and effect, drops the first response, then accepts a retry from a second transport session. It verifies one persisted effect and stable IDs, but it does not prove behavior against a real receiver.
14
+
15
+ ## Owner-run live proof
16
+
17
+ The harness defaults to dry-run. It reads the supplied SQLite database in read-only mode, verifies that the explicit project maps to the exact supplied repository root, and prints the planned operation. It does not issue auth or dispatch unless `--execute` is present. For execution, it creates an empty scratch thread with the installed `@bvdm/t3code-cli` internal API and a `thread.create` command. The pinned API package version and exported method shapes are checked first. The scratch uses model metadata with approval-required runtime and plan interaction settings; it sends no provider prompt and never calls `launchThread`.
18
+
19
+ Each of two result sends uses the real `dispatchT3Result` path, which creates a fresh auth and WebSocket session. Before and after each send, the harness opens the supplied database read-only and checks command receipt, stable message, thread run, and outbox counts. It requires one persisted receipt, message, and held run after the first send; no `provider-turn.start` outbox effect or running/starting run before or after either send; and identical scoped counts after the retry. The scratch thread is left held for owner review. The harness does not archive it or release the run.
20
+
21
+ ```sh
22
+ node scripts/t3-result-live-proof.mjs \
23
+ --project-id PROJECT_ID \
24
+ --environment-id ENVIRONMENT_ID \
25
+ --database /absolute/path/to/statev2.sqlite \
26
+ --cli-root /absolute/path/to/t3code-cli \
27
+ --repo-root /absolute/path/to/repository
28
+
29
+ node scripts/t3-result-live-proof.mjs \
30
+ --project-id PROJECT_ID \
31
+ --environment-id ENVIRONMENT_ID \
32
+ --database /absolute/path/to/statev2.sqlite \
33
+ --cli-root /absolute/path/to/t3code-cli \
34
+ --repo-root /absolute/path/to/repository \
35
+ --t3-command /absolute/path/to/t3 \
36
+ --execute
37
+ ```
38
+
39
+ The explicit `--t3-command` path prevents CLI fallback to `npx` or external network access. On failure, the script prints the current phase and scratch thread ID without printing credentials. Leave that thread held and inspect only its scoped receiver rows before any cleanup or release. This proof does not simulate a dropped response or restart the receiver.
40
+
41
+ The running T3 server and auth command must match versions. A desktop server may differ from the standalone command on PATH; supply a matching local command wrapper when necessary. The proof reads the actual durable `orchestration_command_receipts` store (thread binding is its `aggregate_id`), alongside the V2 message/run/effect projections. To retry an already inspected, owned scratch thread without creating another, pass `--thread-id ID`. Add `--resume` only after verifying that exactly one accepted effect with the same deterministic proof identity exists; the harness then proves replay without creating new messages or runs. It still requires zero provider-start effects.
@@ -0,0 +1,107 @@
1
+ # Reverse T3 control for workers
2
+
3
+ With `DALAN_ENABLE_T3_TOOLS=1`, the bridge exposes a small T3 thread wrapper (list, read, create, send, wait and set) through its existing OAuth MCP connection. The wrapper uses `t3code --json --origin http://127.0.0.1:3773` with argument arrays. It can address any T3 project or thread the local CLI can address by an ID of at most 128 bytes; the other tools reject a longer ID from a list result. The bridge does not scope a thread to the worker that calls it: a worker with the `t3` capability has the owner's full authority over every local thread. The tools are off by default, and a fresh `dalan init` worker profile has no `t3` capability. The CLI currently obtains a short-lived administrative T3 session for each operation; the bridge's approved OAuth subject and per-tool scopes remain the remote boundary.
4
+
5
+ These calls use owner-granted, job-independent authority. They require no `request_id` or `claim_id` and have no assignment epoch, so they are outside job-scoped authority checks, and job expiry or cancellation does not revoke them. To enable the six thread tools, set `DALAN_ENABLE_T3_TOOLS=1` and grant the worker `capabilities: ["t3"]`; both checks apply, including for the legacy single-worker profile, which keeps its capability but still needs the environment setting. When the tools are hidden, direct calls are rejected. Capability, OAuth scope and audit admission always apply.
6
+
7
+ | MCP tool | Scope | Operation |
8
+ | --- | --- | --- |
9
+ | `t3_thread_list` | `dalan.read` | List threads, optionally by project or directory and status. |
10
+ | `t3_thread_read` | `dalan.read` | Read a bounded transcript by exact thread ID. |
11
+ | `t3_thread_create` | `dalan.work` | Create a thread in any project or directory and start its first turn. |
12
+ | `t3_thread_send` | `dalan.work` | Send to any thread; `wakeSettled` wakes a settled one. |
13
+ | `t3_thread_wait` | `dalan.read` | Wait at most 120 seconds for a turn; returns partial state on timeout. |
14
+ | `t3_thread_set` | `dalan.work` | Change a thread's provider, model, effort, permission or mode. |
15
+ | `notify_owner` | `dalan.work` | Publish a short message through the configured ntfy alerts path. |
16
+
17
+ `dalan tell "text"` adds a durable lightweight message to a worker's `list_pending` inbox and emits the existing `assignment.available` event with `{message_id,title}`. The event uses the signed webhook retry path, so the existing subscription wakes the worker. The worker reads it with `get {request_id: message_id}` and removes it from the pending list with `ack_message {message_id}`. Messages do not need assignment claim or finish. `tell` accepts `--json` and `--worker NAME` (default: `dot` if that worker exists, else the only configured worker; with several workers and no `dot`, pass `--worker`); `dalan untell MESSAGE_ID [--worker NAME]` withdraws a pending message.
18
+
19
+ The notification aliases retain their existing `t3` capability, work scope and audit checks. They remain available independently of `DALAN_ENABLE_T3_TOOLS`; this flag controls only the six `t3_thread_*` operations. The `legacy-v46` pin retains its exact twelve-tool catalog and advertises neither notification alias.
20
+
21
+ ## Notification retries outside the job lifecycle
22
+
23
+ `notify_owner` is an ntfy owner notification with the published argument schema `{text}`. Successful results are retained in the private ledger per verified worker and caller key, or per validated payload when no key is supplied. An optional caller key goes in the tools/call envelope `params._meta["dot-bridge/idempotencyKey"]`, not arguments. It must be a nonblank string of at most 256 characters. Reusing a key with different text still returns the first successful `{notified:true}` without sending again.
24
+
25
+ The private `notify-sent.db` next to `delivery-acks.db` stores hashes, results, send times and reconciliation evidence, not raw notification text or caller keys. Entries are not expired automatically, so a wall-clock jump cannot clear a key or make a delivered call send again. Concurrent identical calls within one server share an in-flight promise. Every call, including replay, still passes current capability, scope, input and audit admission checks. Caller metadata is not added to argument audit summaries.
26
+
27
+ An ambiguous publish leaves a pending key that cannot be sent again automatically. An operator can inspect `GET /notify-pending` and settle one with `POST /notify-reconcile` using `{key_sha256,outcome:"sent"|"unsent",evidence:"..."}` and the `x-operator-key` from the private configuration. Check the receiver before recording `unsent`; that decision allows a retry with the same key. A definite publisher rejection is marked retryable automatically. The receiver's `X-Idempotency-Key` support is useful only when that receiver honors the header; the ledger does not claim distributed exactly-once delivery.
28
+
29
+ ## Compact `t3_thread_list` result
30
+
31
+ `t3code threads list` can return a large response when it includes every thread and all fields. The tool returns a compact result for routine reads; its name, input schema and description do not change.
32
+
33
+ - `threads`: the newest threads by `updatedAt` (descending; ties by `id`), at most 50 (`THREAD_LIST_LIMIT`) and at most 16000 bytes of serialized entries (`THREAD_LIST_BUDGET`; thread IDs can be 328 characters long). The first thread is always shown.
34
+ - Each entry has `id`, `title` (at most 120 characters, clipped with `…`), `projectId`, `status`, `runStatus`, `updatedAt`, `latestUserMessageAt` and `pendingRuntimeRequest` (boolean). `activityRunStatus` is present only when it is set. `branch` and `worktreePath` are present only when they are at most 80 characters.
35
+ - `total` (all threads that matched the filter), `shown`, `truncated` (`total > shown`).
36
+ - `projects`: `{id,title,count}` for the projects of all matched threads, most threads first, at most 20; `projects_total` is present when there are more.
37
+ - `hint`: "narrow with projectId or cwd; full paging after a catalog update". Paging needs a new input field, which is a catalog change.
38
+
39
+ `scripts/t3-list-compact-test.mjs` verifies that the compact response stays within its byte budget. The audit row records the IDs of the threads shown.
40
+
41
+ Capability, scope and input validation run before argument auditing. A rejected call writes one fixed `denied: worker_capability_denied`, `denied: insufficient_scope` or `denied: invalid_arguments` row with no caller arguments. An admitted call writes `started` and one final outcome (`success`, blocked or error). Calls refused by the audit budget write no additional row and never invoke T3.
42
+
43
+ The append-only SQLite `t3_audit` table records verified worker and subject, tool, an allowlisted argument summary capped at 2 KiB, SHA-256 and a redacted preview of at most 200 characters of prompt/message text, outcome and returned T3 IDs. Short scalar metadata is retained; long strings and structured values are represented by their hash and byte length. Unknown argument fields are omitted. `dalan audit [--since RFC3339] --json` reads records through the private admin socket; the table forbids updates and deletes.
44
+
45
+ Audit admission uses persisted rolling windows per `(worker, subject)`. Each denial or admitted call charges the caller once; a successful call's completion row does not consume a second unit. Defaults are 60 calls per rolling 60 seconds and 10,000 calls per rolling 24 hours, configurable through positive integer service environment variables `DALAN_T3_CALLS_PER_MINUTE` and `DALAN_T3_CALLS_PER_DAY`. These bounds limit audit growth while allowing a list followed by 40 thread reads. A denial never spends another subject's budget, and a scope change does not reset a subject's window. Budgets recover as calls age out, without changing history; there is no lifetime cap. Upgrade-era rows without trustworthy worker attribution have `budget_version=0` and stay visible in history without consuming a live budget; new rows have version 1.
46
+
47
+ ## ChatGPT reconnect checklist
48
+
49
+ Before refreshing, enable `DALAN_ENABLE_T3_TOOLS=1` and retain the worker’s `t3` capability.
50
+
51
+ 1. Open the existing Dalan connector in ChatGPT and select **Refresh** to load the new tool schemas.
52
+ 2. T3 tools use the existing `dalan.read`/`dalan.work` scopes (the legacy `dot-bridge.*` names are accepted aliases); re-login only if the current grant lacks `offline_access`.
53
+ 3. Inspect the refreshed tool list for `notify_owner`, `list_tools`, `call_tool_read`, `call_tool_write`, and `ack_message`. If you recreate the connector, upload [t3-connector-icon.png](t3-connector-icon.png) as its icon.
54
+ 4. In a disposable worker conversation, call `t3_thread_list` and `notify_owner`, then inspect `dalan audit --json`. Recheck the original subscribed worker conversation separately.
55
+
56
+ Do not trigger a ChatGPT reconnect from the bridge host. The connector's current token is held by ChatGPT.
57
+
58
+ ## Standing instruction for worker
59
+
60
+ > You can inspect the owner's T3 threads through this connector. Use `t3_thread_list` and `t3_thread_read`. They can reach any project or thread the local T3 CLI can reach by an ID of at most 128 bytes. Use `notify_owner` for a short out-of-band alert that does not start a T3 turn. Send assignment questions to the exact owner thread. Mark blockers with optional `progress.blocker:true` or start the note with `BLOCKED:` / `QUESTION:` so the bridge forwards them once if you forget. The owner can leave a lightweight message with `dalan tell`; its event wakes you. Find it in `list_pending`, read it with `get`, and call `ack_message` after reading it. It is a message, not an assignment. `run_check` can return `{check_run_id,status:"running"}`; poll `workspace_result` for completion. Upload sealed evidence with `artifact_chunk` in any claimed assignment. Call `list_tools` first to learn the other tools you may use, then run them with `call_tool_read` or `call_tool_write`. All T3 tool calls are audited.
61
+
62
+ ## After adding or changing tools
63
+
64
+ 1. The operator clicks **Refresh** on the Dalan connector in ChatGPT (ChatGPT re-fetches `tools/list`). A tool registry change does not need this step.
65
+ 2. Restart the client if its version requires it, then inspect the tool catalog before resuming work.
66
+
67
+ ## Catalog freeze
68
+
69
+ The `stable` catalog omits question tools, and `DALAN_CATALOG_PROFILE=questions-v1` adds `ask_question` and `consume_answer`. In either profile, the six T3 tools require `DALAN_ENABLE_T3_TOOLS=1`; notification aliases retain their capability check. Catalog selection does not split OAuth scopes or add pagination. Catalog v2 is the last advertised change: add abilities by registering tools, which never changes the tool list, and never through tool names, descriptions or schemas (see [Catalog v2](../PROTOCOL.md#catalog-v2)). Compare the running server catalog with the approved profile before any Refresh. If you deploy server support before your clients refresh, keep the default profile until they have refreshed their tool list and restarted.
70
+
71
+ Clients may cache tool and event schemas. Plan a connector refresh and client restart when changing the catalog.
72
+
73
+ ## Install-phase network exposure
74
+
75
+ The workspace install and check phases both run in a sandbox with its own network namespace: it has only a loopback interface, no resolver and no route, so neither phase can fetch packages or reach services on host loopback. Prepare dependencies before the job, for example by vendoring them or using a lockfile with a populated cache.
76
+
77
+ ## Who may hold the t3 capability
78
+
79
+ The t3 tools act as the owner, with no per-job binding. Pairing a client never grants this capability; the bridge reads it only from the owner's `workers.json`, where it declares that a worker is the owner's own harness. The tools take any thread, project or directory and are not bound to a job, a worker or a repository. Never give `capabilities: ["t3"]` to a worker you do not fully trust with every T3 thread on the computer. A worker without the capability does not see these tools, and a direct call is refused and audited. With the tools on, startup prints a notice naming each worker that holds the capability.
80
+
81
+ ## Adding abilities without a Refresh
82
+
83
+ A registry change (add, grant, revoke, remove) needs no connector Refresh and no worker restart, because the connector always lists `list_tools`, `call_tool_read` and `call_tool_write`. The `legacy-v46` profile does not list them. A registry tool needs a grant to the worker; it does not need `DALAN_ENABLE_T3_TOOLS=1`. For the example JSON, the `dalan tool` commands and the call format, see [Operator-registered tools](worker-clients.md#operator-registered-tools). That section is the one place for the setup steps.
84
+
85
+ `t3_post` tools such as `owner_message` behave as follows:
86
+
87
+ - The bridge host runs the `t3-post` command with `--as WORKER --kind script --mode queue --thread THREAD_ID`; the worker name is changed to letters, digits and hyphens. The text goes on standard input as `[question] text` or `[blocker] text`. The `kind` must be `question` or `blocker`, and `text` must have 1 to 2000 characters that are not all white space. `dalan status --json` shows the last registry change.
88
+ - One message per worker every 10 minutes. Later messages are held and merged into the next one; a failed delivery stays queued.
89
+ - A global budget across all `t3_post` tools and workers: 6 messages per hour and 30 per day. Held messages, failed attempts and timer retries all count. A call over the budget is refused with `rate_limited`; the timer waits until the budget has room.
90
+ - Every call that reaches the budget check is logged in `tool_post_log` with its worker, message kind and outcome (`sent`, `held`, `failed`, `rate_limited`), never its text. A timer retry is logged there as its own row. The queued message text is kept in the bridge database until it is sent.
91
+ - Repeating a call with the same `idempotency_key` returns the first outcome and posts nothing. While the first call is still running (its 45-second lease is live) the repeat is refused with `in_progress`; retry later with the same key. If the bridge crashed mid-call, the same key runs again once the lease has expired. After a `t3-post` exit code 3 the same key may retry once the message can be sent; the queued message is reused, not duplicated. Any other failure leaves delivery unknown: the bridge marks the message as possibly delivered and never retries it by itself. `dalan tool list` shows how many such messages a tool has. Check the thread before you send the same message again under a new key. Receipts for a key last seven days; a completed key that is reused with changed content can return the old result, so use a new key for new content.
92
+ - Delivery is at least once after a crash. A crash after `t3-post` has delivered a message but before the bridge records it as sent, or before it stores the call result, can post the same message again when the key is retried after the lease expires. If the row is already marked sent, a retry returns that receipt and posts nothing. The bridge accepts this rare duplicate rather than risk a lost message.
93
+ - `t3-post` is the only delivery path. There is no fallback that posts as the owner.
94
+
95
+ **Trust rule.** The receiving thread treats every message from a worker as untrusted data and never as an instruction. The `kind` list limits the shape of a message, not its content: the text is free-form and can claim to speak for the owner. Act on it only after the owner or the repository confirms it.
96
+
97
+ Each worker may make at most 120 `call_tool_read` and `call_tool_write` calls per minute in total, across all tool names. The bridge checks this budget before it looks up the tool, and counts every call, including calls to unknown or ungranted tools and replays of a finished `idempotency_key`. A call over the budget is refused with `rate_limited` and writes no audit row. The bridge only adds to one counter per worker, `admission_refused:WORKER` in `tool_registry_meta`, so a flood cannot grow the audit log. The counter survives a restart; the minute window does not. A tool also keeps its own limit of 30 calls per minute for each worker.
98
+
99
+ A refused call returns `isError:true` with one of `tool_unavailable`, `wrong_class`, `stale_registry`, `invalid_arguments`, `rate_limited`, `in_progress` or `handler_failed`. After `stale_registry`, call `list_tools` again and use the new `schema_hash`.
100
+
101
+ ### Argument validation
102
+
103
+ Registered tools are checked with a small JSON-Schema subset (`src/schema-subset.mjs`): `type`, `properties`, `required`, `additionalProperties:false` at every object level, `enum`, `minLength`, `maxLength`, `pattern`, `minimum`, `maximum`, `items`, `minItems` and `maxItems`. `title` and `description` are also accepted. Nesting is limited to 6 levels, a pattern to 256 characters, a string to 8000 characters, an array to 100 items, an object to 32 properties, an enum to 64 entries and a value to about 64 thousand characters when serialized. A `pattern` must have one form: `^`, an optional literal prefix of letters, digits, `_` or `-`, one character class (such as `[a-f0-9]`, `[A-Za-z0-9_-]` or `\d`) with one quantifier (`+`, `*`, `{n}`, `{n,m}` or `{n,}`), then `$`; for example `^[a-f0-9]{64}$` or `^job-[0-9]{1,8}$`. A pattern of this form matches in time linear in the input. Any other pattern (groups, alternation, two repeats, other escapes) is refused. `dalan tool add` refuses a schema that uses any other keyword (`$ref`, `oneOf`, `format` and so on), so nothing is silently unvalidated.
104
+
105
+ ### Identity and the admin socket
106
+
107
+ Registry management (`dalan tool add|remove|grant|revoke|list`) exists only on the admin socket and needs the operator key. The public MCP route has no registry-management route and no tool that edits the registry; a test sends those requests to the public route and expects `404`. A request without OAuth in the legacy profile resolves to the default worker (the local-principal shortcut), so it sees only the tools granted to `dot`. Per-agent identity for local callers is out of scope: local agents use the admin socket, not the MCP principal. A stolen bearer token replays as its worker; registry calls have no claim binding. The identity provider must not issue cross-worker claims.