@omniralph/agent 0.8.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # @omniralph/agent
2
2
 
3
- `omniralph-agent` is the Omniralph agent host daemon. It pulls review jobs from an Omniralph
4
- control panel and runs them with the Claude Agent SDK. It needs Node 22 and git ≥ 2.40.
3
+ `omniralph-agent` is the Omniralph agent: the daemon that runs jobs on a machine. It pulls jobs
4
+ (reviews, queries, coding stories) from an Omniralph control panel and runs them with the Claude
5
+ Agent SDK. It needs Node 22 and git ≥ 2.40.
5
6
 
6
7
  This README covers installing and releasing the package. To set up a host (the agent's user, the
7
8
  Claude login, pm2, tmux or systemd), see
@@ -20,14 +21,20 @@ omniralph-agent --version
20
21
 
21
22
  ## Enroll
22
23
 
23
- As an admin, open **Agents › Enroll agent** in the control panel and run the command it shows on
24
+ As an admin, open **Fleet › Enroll** in the control panel and run the command it shows on
24
25
  the host, as the agent's user:
25
26
 
26
27
  ```sh
27
28
  omniralph-agent enroll --server https://omniralph.example.com --token <enrollment-token>
28
29
  ```
29
30
 
30
- This writes `~/.config/omniralph/agent.json`. Run `omniralph-agent --help` to see all the options.
31
+ This writes `~/.config/omniralph/agent.json` (`--config` or `OMNIRALPH_AGENT_CONFIG` choose
32
+ another path), which holds the agent's identity. Its machine settings (slots, accepted task types,
33
+ host tool paths, the installables allow-list, the version pin) are in `settings.json` in its data
34
+ directory (`~/.omniralph/settings.json`), which the agent applies as soon as it changes. Run
35
+ `omniralph-agent --help` to see all the options, and
36
+ [docs/deploy-agent.md](https://github.com/mcm/omniralph/blob/main/docs/deploy-agent.md#machine-settings-settingsjson)
37
+ for every key of both files.
31
38
 
32
39
  ## Start
33
40
 
@@ -38,6 +45,16 @@ omniralph-agent start --healthz-port 9310
38
45
  To run it as a service, see the systemd, tmux and pm2 sections in
39
46
  [docs/deploy-agent.md](https://github.com/mcm/omniralph/blob/main/docs/deploy-agent.md).
40
47
 
48
+ The agent logs to stderr and to `<dataDir>/logs/agent.log` (`~/.omniralph/logs/agent.log` by
49
+ default), rotated at 10 MB with five older files kept (`agent.log.1` … `agent.log.5`). See
50
+ [Logs](https://github.com/mcm/omniralph/blob/main/docs/deploy-agent.md#logs).
51
+
52
+ While it runs, the agent serves its page on 127.0.0.1 (port 7410 by default, `ui.port` in
53
+ `agent.json`). `omniralph-agent ui` prints its link, with a token that changes at every start;
54
+ `--open` also opens it in the browser. From another computer, forward the port (`ssh -L
55
+ 7410:127.0.0.1:7410`, `coder port-forward <workspace> --tcp 7410:7410`). See
56
+ [The agent page](https://github.com/mcm/omniralph/blob/main/docs/deploy-agent.md#the-agent-page).
57
+
41
58
  ## Upgrade
42
59
 
43
60
  Stop the agent, then:
@@ -48,40 +65,170 @@ omniralph-agent --version
48
65
  ```
49
66
 
50
67
  Start it again. Upgrading keeps the config and the repo cache. The version shows on the agent's
51
- row on the **Agents** page after its next heartbeat.
68
+ detail on **Fleet** after its next heartbeat.
69
+
70
+ ### From @omniralph/harness
71
+
72
+ Up to 0.13 the agent was published as `@omniralph/harness` with the `omniralph-harness` binary and
73
+ the config file `~/.config/omniralph/harness.json`. Self-update can't cross the rename, so install
74
+ `@omniralph/agent` once by hand, as the agent's user:
75
+
76
+ 1. Stop the old daemon (`pm2 delete omniralph-harness`, or however you run it).
77
+ 2. `npm install -g @omniralph/agent`.
78
+ 3. `omniralph-agent import`: it reads the old install's config and writes
79
+ `~/.config/omniralph/agent.json` (and its `acceptedTaskTypes` and `installables.allow` into
80
+ `~/.omniralph/settings.json`), so the machine comes back as the same agent without enrolling
81
+ again. It makes no network call, leaves the old install untouched and prints one line per
82
+ setting. `--dry-run` prints the same summary without writing anything; `--force` backs up and
83
+ replaces an existing `agent.json`. When pm2 runs the old daemon, it prints the commands that
84
+ replace it.
85
+ 4. Start `omniralph-agent start` under pm2, tmux or systemd as before.
86
+ 5. `npm uninstall -g @omniralph/harness` once the agent is back.
87
+
88
+ Self-update works again from then on. The full walkthrough, with what each `import` outcome means,
89
+ is in
90
+ [docs/deploy-agent.md › Moving from @omniralph/harness](https://github.com/mcm/omniralph/blob/main/docs/deploy-agent.md#moving-from-omniralphharness).
91
+
92
+ ## Releasing
93
+
94
+ Releases are automated with [changesets](https://github.com/changesets/changesets) and
95
+ `.github/workflows/publish-agent.yml`. Nobody edits `version` or pushes `agent-v*` tags by hand.
96
+ Merging the "Version Packages" pull request is the only release action.
52
97
 
53
- ### From 0.3.0 or earlier (`@iamthemcmaster/omniralph-agent`)
98
+ The `@omniralph/agent` line starts at **2.0.0**, to match Omniralph 2.0. `apps/agent/package.json`
99
+ holds `1.0.0`, which is never published, and a `major` changeset takes the first Version Packages
100
+ pull request to 2.0.0. The name's older 0.3.1–0.8.0 releases on npm are deprecated, so
101
+ `scripts/agent-release.ts status` refuses to publish anything below `AGENT_MIN_VERSION` (2.0.0,
102
+ in `packages/shared`).
54
103
 
55
- Up to 0.3.0 the package was `@iamthemcmaster/omniralph-agent`; from 0.3.1 it's `@omniralph/agent`.
56
- Agents on 0.3.0 or earlier can't self-update across the rename (they'd install the old package
57
- name), so upgrade them by hand once. Both packages install the `omniralph-agent` binary, so remove
58
- the old one first.
104
+ ### Add a changeset to your pull request
105
+
106
+ Every pull request that changes this package must add a changeset: a small Markdown file in
107
+ `.changeset/` that names the semver bump and holds the release note. To add one, run this from the
108
+ repository root, pick `@omniralph/agent` and the bump, write the note, and commit the file:
59
109
 
60
110
  ```sh
61
- npm uninstall -g @iamthemcmaster/omniralph-agent
62
- npm install -g @omniralph/agent@latest
63
- omniralph-agent --version
111
+ pnpm changeset
64
112
  ```
65
113
 
66
- Under pm2, run `pm2 restart omniralph-agent` afterwards. Self-update works again from 0.3.1 on.
114
+ The agent bundles the workspace packages `@omniralph/engine`, `@omniralph/ralph`,
115
+ `@omniralph/shared`, `@omniralph/tasks` and `@omniralph/ui` (its `workspace:*` devDependencies):
116
+ `packages/engine`, `packages/ralph`, `packages/shared`, `packages/tasks` and `packages/ui`.
117
+ Changesets doesn't release those private packages, and it doesn't bump the agent when only they
118
+ change. A pull request that changes one of them must add a changeset for `@omniralph/agent`
119
+ itself. That includes a change made only under `packages/ui`: the agent's page is built from it.
67
120
 
68
- ## Releasing
121
+ CI (`ci.yml`, `scripts/check-agent-changeset.ts`) fails a pull request that changes
122
+ `apps/agent/`, or any workspace package the agent depends on, and adds no
123
+ `@omniralph/agent` changeset. The package list comes from the workspace graph, so a new
124
+ dependency is covered automatically. If the change needs no release note (tests, an internal
125
+ refactor), add an empty changeset instead. CI accepts it as a deliberate opt-out:
126
+
127
+ ```sh
128
+ pnpm changeset --empty
129
+ ```
130
+
131
+ Pull requests that touch neither the agent nor its workspace packages need no changeset.
132
+
133
+ #### Changesets for the old name during the 2.0 freeze
134
+
135
+ Until the 2.0 cutover, other 2.0 epics still write changesets for `@omniralph/harness`, the
136
+ package's old name. The check accepts those too, and `scripts/check-harness-changeset.ts` still
137
+ runs it from the old path. Before `pnpm changeset version`, the workflow runs
138
+ `scripts/rewrite-legacy-changesets.ts`, which renames the `@omniralph/harness` key to
139
+ `@omniralph/agent` in every pending changeset (keeping the larger bump if a changeset names both),
140
+ so they release as `@omniralph/agent`. Run it yourself after rebasing onto a branch that added
141
+ one. At the cutover, the check stops accepting the old name and the old path is deleted.
142
+
143
+ ### The Version Packages pull request
144
+
145
+ When changesets reach `main`, the workflow opens a pull request titled "Version Packages" (branch
146
+ `changeset-release/main`), and updates it on every later push to `main`. The pull request runs
147
+ `scripts/rewrite-legacy-changesets.ts`, then `pnpm changeset version`, which:
69
148
 
70
- GitHub Actions (`.github/workflows/publish-agent.yml`) publishes releases through npm trusted
71
- publishing. No npm publish token is stored anywhere.
149
+ - bumps `version` in `apps/agent/package.json` by the largest bump the changesets declare;
150
+ - writes their notes to `apps/agent/CHANGELOG.md`, linking each entry's pull request and author;
151
+ - deletes the changeset files it consumed.
72
152
 
73
- 1. Bump `version` in `apps/agent/package.json` and merge the change to `main`.
74
- 2. Tag that commit `agent-v<version>` and push the tag:
153
+ Empty changesets alone don't open the pull request. CI checks the pull request like any other,
154
+ but it skips the changeset check there.
75
155
 
76
- ```sh
77
- git tag agent-v0.2.0 && git push origin agent-v0.2.0
78
- ```
156
+ ### Release by merging it
79
157
 
80
- The workflow installs and checks only this package and the workspace packages it bundles (the web
81
- app and db are left to CI), runs `scripts/smoke-agent-package.sh`, then publishes the tarball the
82
- smoke script tested. It fails if the tag version doesn't match `package.json`.
158
+ Merging the Version Packages pull request releases the new version. On that push to `main`, the
159
+ workflow finds no pending changesets and a version that isn't on npm yet, and then:
83
160
 
84
- The build (`tsup`) inlines the workspace packages (`@omniralph/engine`, `@omniralph/shared`) into
161
+ 1. installs only this package and the workspace packages it bundles (the web app and db are left
162
+ to CI, so no npm token is needed);
163
+ 2. typechecks, lints and tests them;
164
+ 3. reads the version's section of `CHANGELOG.md` with `scripts/agent-release.ts notes` (it fails
165
+ here if there is none);
166
+ 4. runs `scripts/smoke-agent-package.sh`;
167
+ 5. publishes the tarball the smoke script tested, through npm trusted publishing (OIDC). No npm
168
+ publish token is stored anywhere;
169
+ 6. pushes the tag `agent-v<version>` on the released commit and creates a GitHub Release named
170
+ after it, with that version's changelog section as its notes.
171
+
172
+ Any other push to `main` finds the version already on npm, logs that there is nothing to release,
173
+ and succeeds.
174
+
175
+ ### Re-run a failed publish
176
+
177
+ If a release fails before publishing (a check, the smoke test, npm), fix the cause on `main` if
178
+ needed. Then run the workflow again from **Actions › Publish agent › Run workflow** on `main`
179
+ (`workflow_dispatch`), or re-run the failed job. It publishes the version on `main` if that
180
+ version isn't on npm yet.
181
+
182
+ Once the version is on npm, the workflow treats it as released. If the tag or the GitHub Release
183
+ step failed after publishing, create them by hand for that version:
184
+
185
+ ```sh
186
+ git tag agent-v<version> <released commit> && git push origin agent-v<version>
187
+ gh release create agent-v<version> --verify-tag --title agent-v<version> --notes "<changelog section>"
188
+ ```
189
+
190
+ ### The `CHANGESETS_GITHUB_TOKEN` secret
191
+
192
+ GitHub runs no workflows for pull requests or pushes made with the workflow's default
193
+ `GITHUB_TOKEN`. So the Version Packages pull request is opened and updated with the repository
194
+ secret `CHANGESETS_GITHUB_TOKEN`, and `ci.yml` runs on it. The secret holds a fine-grained
195
+ personal access token, or a GitHub App installation token, scoped to `mcm/omniralph`, with:
196
+
197
+ - **Contents: Read and write**, to commit the version bump and push the `changeset-release/main`
198
+ branch. These commits must come from this token, so that CI also runs on later updates to the
199
+ pull request;
200
+ - **Pull requests: Read and write**, to open the pull request and update its title and body.
201
+ `@changesets/changelog-github` also uses it to look up each entry's pull request and author;
202
+ - **Metadata: Read-only**, which GitHub adds to every fine-grained token.
203
+
204
+ A GitHub App needs the same Contents and Pull requests permissions on its installation.
205
+
206
+ If the secret is unset, the workflow falls back to the default `GITHUB_TOKEN`. Everything still
207
+ works, except that CI doesn't run on the Version Packages pull request. To get the checks, close
208
+ and reopen the pull request, or push a commit to its branch yourself. Tags and GitHub Releases
209
+ always use the default token.
210
+
211
+ ### Bundling
212
+
213
+ The build runs `tsup`, then `vite build --config ui/vite.config.ts`.
214
+
215
+ `tsup` inlines the workspace packages (`@omniralph/engine`, `@omniralph/shared` …) into
85
216
  `dist/cli.js`. Third-party packages stay external. A third-party package that the bundle imports
86
217
  must be listed in this package's `dependencies`, or the installed binary won't start. The smoke
87
218
  script catches this.
219
+
220
+ Vite builds the agent's page (`ui/`) into `dist/ui/`: static files with hashed names, served by
221
+ the daemon. React, TanStack Query and `@omniralph/ui` are bundled into them, so they are
222
+ devDependencies and the published package gains no runtime dependency. `index.html` loads one
223
+ module script and has no inline script or style, so the page's Content Security Policy holds.
224
+ The smoke script checks that the tarball has `dist/ui/index.html` and every asset it loads, that
225
+ `dist/ui` stays under 3 MB and that no source map of it ships.
226
+
227
+ The page's code is in `ui/src`: `main.tsx` (providers), `router.tsx` (a small history router),
228
+ `shell.tsx` (the top bar, the section nav and the open page), `pages/` and `live/`. `live/` holds
229
+ the query keys, the change event map (`invalidations.ts`: each resource the daemon publishes
230
+ either appends to the cache, for `logs` and `transcript`, or invalidates queries; an unmapped
231
+ resource fails typecheck), the event stream with its polling fallback, and `useLocalMutation`
232
+ for changes (`optimistic` and `applyResult`, as `apps/web`'s `useApiMutation`). `typecheck` runs
233
+ `tsc -p ui` too, and the page's tests (`ui/src/**/*.test.tsx`, under jsdom) run with the
234
+ package's Vitest run.