@tnunamak/dalan 0.8.1 → 0.8.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 (124) hide show
  1. package/CHANGELOG.md +59 -2
  2. package/CONTRIBUTING.md +2 -0
  3. package/README.md +8 -12
  4. package/bin/dalan.mjs +25 -4
  5. package/bin/dot-acp-agent.mjs +572 -76
  6. package/bin/dot-alert.mjs +9 -3
  7. package/bin/dot-deadman.mjs +3 -1
  8. package/bin/dot-heartbeat.mjs +14 -7
  9. package/bin/dot-pr-reviewer.mjs +3 -31
  10. package/bin/dot-worker.mjs +121 -34
  11. package/contracts/adapter-qualification.schema.json +94 -7
  12. package/docs/chatgpt-worker-onboarding.md +1 -1
  13. package/docs/codex-to-muse.md +2 -2
  14. package/docs/connect-chatgpt.md +1 -1
  15. package/docs/connection-longevity.md +2 -2
  16. package/docs/dalan-upgrade.md +8 -5
  17. package/docs/deadman.md +4 -0
  18. package/docs/design/authority-matrix.md +18 -0
  19. package/docs/design/failure-table.md +87 -0
  20. package/docs/design/identities.md +22 -0
  21. package/docs/design/pnpm-prepared-dependencies.md +64 -0
  22. package/docs/design/reuse-ledger.md +75 -0
  23. package/docs/design/target-architecture-v2.md +434 -0
  24. package/docs/local-agent-mcp.md +14 -0
  25. package/docs/local-agent-requester.md +2 -1
  26. package/docs/manual-setup.md +1 -1
  27. package/docs/operations.md +77 -14
  28. package/docs/pull-workers.md +11 -1
  29. package/docs/service-setup.md +10 -10
  30. package/docs/t3-integration.md +4 -2
  31. package/docs/t3-reverse-control.md +5 -5
  32. package/docs/test-suite-isolation.md +7 -6
  33. package/docs/trials/chatgpt-agent.md +47 -0
  34. package/docs/trials/claude-code-requester.md +68 -0
  35. package/docs/trials/muse.md +46 -0
  36. package/docs/usage.md +21 -7
  37. package/docs/worker-clients.md +1 -1
  38. package/integrations/t3/acp-kit/src/errors.mjs +6 -2
  39. package/integrations/t3/acp-kit/src/lock.mjs +46 -17
  40. package/integrations/t3/acp-kit/src/session-store.mjs +15 -3
  41. package/integrations/t3/acp-kit/src/t3-envelope.mjs +10 -2
  42. package/package.json +4 -3
  43. package/packages/job-core/protocol/canonical.mjs +45 -7
  44. package/packages/job-core/transitions.mjs +4 -2
  45. package/scripts/upgrade-drain.mjs +96 -8
  46. package/scripts/worker-bridge-setup.mjs +215 -120
  47. package/src/ack-ledger.mjs +7 -1
  48. package/src/acp-bridge.mjs +256 -28
  49. package/src/admin-socket.mjs +32 -3
  50. package/src/alerts.mjs +17 -8
  51. package/src/answer-journal-retention.mjs +82 -0
  52. package/src/answer-journal.mjs +6 -4
  53. package/src/as-store.mjs +51 -6
  54. package/src/as.mjs +27 -5
  55. package/src/catalog-switch-inventory.mjs +70 -0
  56. package/src/check-response.mjs +4 -1
  57. package/src/cli-help.mjs +14 -3
  58. package/src/cli-name.mjs +13 -1
  59. package/src/connect-cli.mjs +159 -4
  60. package/src/deadman.mjs +8 -5
  61. package/src/delivery.mjs +2 -19
  62. package/src/destinations/index.mjs +75 -14
  63. package/src/drain-runner.mjs +5 -1
  64. package/src/follow-current.mjs +3 -1
  65. package/src/get-summary.mjs +11 -2
  66. package/src/git-env.mjs +1 -1
  67. package/src/gozar-routes.mjs +313 -94
  68. package/src/host-budget-storage.py +56 -6
  69. package/src/host-budget.mjs +98 -15
  70. package/src/host-execution-policy.mjs +17 -6
  71. package/src/legacy-names.mjs +0 -2
  72. package/src/lifecycle.mjs +44 -9
  73. package/src/loopback-probe.mjs +46 -0
  74. package/src/mcp-outcome.mjs +3 -1
  75. package/src/mcp-sse.mjs +2 -1
  76. package/src/mcp-stdio.mjs +192 -30
  77. package/src/patch-apply.mjs +212 -7
  78. package/src/phase-trace.mjs +73 -0
  79. package/src/prepared-go-modules.mjs +127 -0
  80. package/src/prepared-node-modules.mjs +225 -38
  81. package/src/prepared-pnpm.mjs +276 -0
  82. package/src/prepared-store-prune.mjs +52 -0
  83. package/src/projects.mjs +59 -7
  84. package/src/protocol-artifact-commands.mjs +28 -0
  85. package/src/protocol-finish.mjs +3 -2
  86. package/src/publication-authority.mjs +22 -0
  87. package/src/publish-plan.mjs +2 -2
  88. package/src/pull-queue.mjs +55 -20
  89. package/src/read-api.mjs +127 -0
  90. package/src/redaction.mjs +173 -0
  91. package/src/rejections.mjs +19 -3
  92. package/src/route-custody.mjs +90 -0
  93. package/src/route-publication.mjs +50 -0
  94. package/src/route-setup.mjs +184 -0
  95. package/src/schema-subset.mjs +5 -3
  96. package/src/server.mjs +503 -98
  97. package/src/service-launchd.mjs +5 -1
  98. package/src/service-update-lock.mjs +7 -4
  99. package/src/service-update-runtime.mjs +64 -19
  100. package/src/service-update.mjs +193 -48
  101. package/src/service.mjs +276 -77
  102. package/src/setup.mjs +48 -25
  103. package/src/signal.mjs +1 -1
  104. package/src/status-evidence.mjs +18 -5
  105. package/src/store.mjs +876 -120
  106. package/src/submission-policy.mjs +257 -56
  107. package/src/t3-control.mjs +1 -1
  108. package/src/t3.mjs +14 -8
  109. package/src/terminal-safe.mjs +9 -7
  110. package/src/tool-registry.mjs +134 -41
  111. package/src/try-exposure.mjs +53 -86
  112. package/src/try-hosted.mjs +257 -70
  113. package/src/try.mjs +48 -22
  114. package/src/work-order.mjs +11 -6
  115. package/src/worker-instructions.mjs +26 -4
  116. package/src/worker-runs.mjs +35 -0
  117. package/src/workers.mjs +34 -7
  118. package/src/workspace.mjs +354 -54
  119. package/systemd/dot-deadman.service +3 -1
  120. package/docs/dot-pr-reviewer.config.example.json +0 -9
  121. package/docs/pr-head-reviewer.md +0 -70
  122. package/src/pr-head-reviewer.mjs +0 -596
  123. package/systemd/dot-pr-reviewer.service +0 -11
  124. package/systemd/dot-pr-reviewer.timer +0 -10
@@ -2,6 +2,8 @@
2
2
  Description=Dalan external heartbeat dead-man monitor
3
3
  Wants=network-online.target
4
4
  After=network-online.target
5
+ # Keep retrying the independent alerter; RestartSec bounds crash-loop frequency.
6
+ StartLimitIntervalSec=0
5
7
 
6
8
  [Service]
7
9
  Type=simple
@@ -18,7 +20,7 @@ StateDirectory=dot-deadman
18
20
  StateDirectoryMode=0700
19
21
  UMask=0077
20
22
  ExecStart=/usr/bin/env node /opt/dot-bridge/bin/dot-deadman.mjs serve
21
- Restart=on-failure
23
+ Restart=always
22
24
  RestartSec=3s
23
25
  NoNewPrivileges=true
24
26
  PrivateTmp=true
@@ -1,9 +0,0 @@
1
- {
2
- "report_thread_id": "mcp:00000000-0000-0000-0000-000000000000",
3
- "owners": ["example-org"],
4
- "repos": ["example-org/example-repo", "example-org/example-docs"],
5
- "exclude_owners": ["example-user", "example-bot"],
6
- "exclude_repos": [],
7
- "headroom": 6,
8
- "max_submits_per_run": 10
9
- }
@@ -1,70 +0,0 @@
1
- # PR-head reviewer
2
-
3
- `dalan-pr-reviewer` submits one scoped, read-only review to the default worker for every open pull request that passes the gates below and whose current head SHA has no worker review. It makes no model calls. A systemd user timer runs it every 10 minutes.
4
-
5
- ## What one run does
6
-
7
- 0. Before the capacity gate (skipped with `--only`): for each PR that a queued or claimed assignment targets (objective key `pr:<owner>/<repo>#<n>`, or `inputs[0].github_repo` plus `pr_number`), at most `max_closed_checks` (40) per run, one REST `pulls/<n>` call (ETag-conditional, so an unchanged PR is a 304). A PR with `state` `closed` (merged or not) gets every such request cancelled with `dalan cancel ID --reason pr_closed`; the bridge stores it as `cancelled_reason`. Open PRs are untouched. A failure is logged as `error` with stage `pr-closed-check` and does not stop the run; a rate limit sets the usual backoff.
8
- 1. `dalan status --json`. Stop when the pool is paused, when an owner-confirmed `worker_break` is active (`active` and `source === "owner"`), or when `claim_denied.capacity_hold_until` is in the future.
9
- 2. Free slots = `max(0, max_claimed_outer_assignments + headroom - claimed - live queued)`. Submit at most `min(slots, max_submits_per_run)`. Defaults are 6 headroom slots and 10 submissions per run. With no free slot, skip discovery.
10
- 3. Discover open PRs with one REST-backed `gh search prs` per distinct configured owner and one per extra repo not covered by those owners. Apply case-insensitive exact `exclude_owners` and `exclude_repos`, and skip archived/fork repositories when the search or PR detail response identifies them. Bot PRs are skipped. A draft counts only if updated in the last 7 days; any other PR only if updated in the last 30 days. Ready PRs go first, newest first.
11
- 4. Dedupe against `bridge.db` (read-only): any non-cancelled assignment for the same repository whose `inputs[0].head_sha` (or lone `base_sha`) is this head, or whose `objective_key` + `revision` is this PR at this head. This includes reviews that other owners submitted themselves. Cancelled assignments do not cover.
12
- 5. Build the assignment so that `validateSubmission` accepts it: `scope_paths` are the PR's changed files still present at the head (deleted files are omitted), collapsed to directories only when over `max_scope_paths` (150) paths or `max_scope_bytes` (8000) bytes; `inputs` pin `{github_repo, base_sha: head}` in head-only mode (REST pull details provide a base tip, not a merge base); `execution_scope` is `read-only`; the brief names no path. A changed file the lint calls sensitive leaves the scope and the PR is then reviewed at its head without the diff (`inputs: [{github_repo, base_sha: head}]`). A PR whose files are all sensitive, a deletion-only PR, and a PR with more than `max_changed_files` (200) changed files, counting deletions, are skipped.
13
- 6. Submit with `dalan submit --stdin --json --background --exclude-sensitive --allow-scope-prune --deliver <dest> --objective-key pr:<owner>/<repo>#<n> --revision <head> --task-kind review --source agent`. (`--source` accepts only `drainer`, `fix-loop`, `agent`, `unknown`.) Request id: `prh-<owner>-<repo>-<n>-<head12>`.
14
- 7. A refusal that survives the CLI's `--allow-scope-prune` fix is logged and remembered for 6 hours. It is not retried in the same run. A bridge or transport failure (HTTP 5xx, timeout) is also remembered for the cooldown and ends the run.
15
-
16
- ## Delivery
17
-
18
- The T3 thread linked to the PR (read-only from `~/.t3/userdata/statev2.sqlite`, `orchestration_v2_projection_threads.payload_json.pullRequests`; a live thread beats an archived one, then the newest link wins) receives the result. If that link points to a delegated child, the reviewer follows its `lineage.parentThreadId`, then `lineage.rootThreadId`, and delivers to the nearest owner that is not archived, deleted, or settled. It never delivers to the delegated child. If no owner can receive it, `report_thread_id` from the config is used; with neither, delivery is `none`. A refused protected T3 destination logs `delivery-fallback` and retries with the report thread if different, then `none`. Other refusals do not trigger a delivery retry. The dry run prints the resolved destination without submitting or writing state.
19
-
20
- ## GitHub API budget
21
-
22
- No `gh pr list`, `gh pr view`, repository enumeration or GraphQL is used. Per run the nominal budget is owners + extra repositories + changed PRs × 3 REST calls + one `pulls` call per PR with queued or claimed work (step 0, mostly 304s): one search per owner/extra repository (limit 200), then pull details (head/base SHA), changed files and pull details again (to confirm the head did not move) for each eligible result. Covered/refused heads need only the first detail call. Files use `gh api --paginate`; each additional page costs an additional REST request even though it is one gh invocation. Because calls are sequential, a rate-limit failure stops further requests immediately.
23
-
24
- After a complete successful scan, state records the run's start time in `last_successful_run`. Later searches include `updated:>=<last_successful_run minus 10 minutes>`; first runs have no date filter. The overlap catches updates made during a run. `--only` ignores and does not advance this scan watermark. Capacity truncation, a 200-result search, errors and retryable refusals retain the previous watermark rather than lose unseen work. A search capped at 200 still requires operator attention or narrower configured coverage to guarantee full discovery.
25
-
26
- REST responses are read with `gh api -i`; body and ETag are cached per endpoint in `state.json` under the state directory. A later fetch sends `If-None-Match` and a 304 returns the cached body (authenticated conditional 304s do not consume the primary REST rate-limit budget). Multi-page file collections are cached without a validator: one page's ETag cannot validate the entire collection, and gh would otherwise send that same conditional header to every page. Search responses are not conditionally cached.
27
-
28
- Every run logs `gh-calls` with invocation counts by `search`, `pull`, and `files`, plus a separate `not_modified` count. The counts describe gh invocations, not hidden pagination requests. HTTP 429, HTTP 403 with `x-ratelimit-remaining: 0`, or gh stderr reporting `rate limit exceeded` or `secondary rate limit` immediately ends the run, logs `rate-limit`, and persists `backoff_until` using the reset/Retry-After headers. Other 403 responses are ordinary errors. If no reset is available (for example search stderr omits headers), back off for an hour; never retry sooner than one minute. Subsequent runs make no gh calls while backoff is active. Dry runs report these decisions without persisting caches, watermarks, backoff or logs.
29
-
30
- ## Configuration
31
-
32
- `~/.config/dot-pr-reviewer/config.json` (optional; see [dot-pr-reviewer.config.example.json](dot-pr-reviewer.config.example.json)). Keys: `owners`, `repos`, `exclude_owners`, `exclude_repos`, `include_forks`, `skip_bots`, `max_submits_per_run`, `headroom`, `draft_days`, `max_age_days`, `max_changed_files`, `max_scope_paths`, `max_scope_bytes`, `ttl_hours`, `refusal_cooldown_hours`, `report_thread_id`, `dot_worker`, `gh_concurrency`, `bridge_db`, `t3_db`. `gh_concurrency` is accepted for config compatibility, but GitHub calls are sequential. Unknown keys are an error. No thread id is built in.
33
-
34
- ## Use
35
-
36
- Before any run, configure the repository coverage and `bridge_db` and `t3_db` paths. Both databases must exist, and `t3_db` must contain `orchestration_v2_projection_threads`, even with delivery `none`. Install Node.js 24+, authenticate `gh`, and put `dalan` on `PATH`. See [Install on Linux](#install-on-linux) before enabling the timer.
37
-
38
- ```
39
- dalan-pr-reviewer --dry-run # inspect candidates without submitting
40
- dalan-pr-reviewer --dry-run --ignore-capacity # also inspect candidates when capacity is full
41
- dalan-pr-reviewer --only OWNER/REPO#N # one PR, if in the repo's first 200 open search results (still gated and deduped)
42
- dalan-pr-reviewer --max N
43
- ```
44
-
45
- State and log: `~/.local/state/dot-pr-reviewer/{state.json,log.jsonl}` (one JSON line per decision).
46
-
47
- ## Install on Linux
48
-
49
- Run from the Dalan checkout or installed package directory, where `docs/` and `systemd/` exist. Install Node.js 24+, authenticate `gh`, and make `dalan` available on the unit's `PATH`. Disable any previous PR feeder before enabling this timer.
50
-
51
- Create the directories and copy the example only if you have no configuration yet:
52
-
53
- ```sh
54
- mkdir -p ~/.config/dot-pr-reviewer ~/.config/systemd/user
55
- if [ ! -e ~/.config/dot-pr-reviewer/config.json ]; then
56
- cp docs/dot-pr-reviewer.config.example.json ~/.config/dot-pr-reviewer/config.json
57
- fi
58
- ```
59
-
60
- Edit `config.json` before continuing: replace the example repository coverage, set `bridge_db` and `t3_db` to the intended existing databases, and replace `report_thread_id` with a verified destination or remove that key for quiet delivery. The T3 database must contain `orchestration_v2_projection_threads`, even with quiet delivery. Check the unit's checkout path and `PATH` as well.
61
-
62
- Run `dalan-pr-reviewer --dry-run`. Confirm that it succeeds and shows only the intended repositories and destinations. Only then install and enable the timer:
63
-
64
- ```sh
65
- ln -sf "$PWD"/systemd/dot-pr-reviewer.{service,timer} ~/.config/systemd/user/
66
- systemctl --user daemon-reload
67
- systemctl --user enable --now dot-pr-reviewer.timer
68
- ```
69
-
70
- It needs `gh` (authenticated), `node` 24 and `dalan` on the unit's `PATH`. It also opens the bridge database and the T3 database read-only (`bridge_db`, `t3_db`). Both must exist, and the T3 database needs the `orchestration_v2_projection_threads` table, even when delivery uses `report_thread_id` or `none`; otherwise the run aborts. Disable any previous PR feeder before enabling this timer.