Skip to content

Commit cf5e12c

Browse files
committed
Register global plugin on package installation and simplify setup docs
1 parent efc8a56 commit cf5e12c

10 files changed

Lines changed: 702 additions & 362 deletions

File tree

‎README.md‎

Lines changed: 159 additions & 352 deletions
Large diffs are not rendered by default.

‎docs/configuration.md‎

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# Configuration reference
2+
3+
For source installations, replace `"$HOME/.local/bin/opencode2-automation"`
4+
with `node "$HOME/opencode2-github-automation/dist/setup.js"` in the commands below.
5+
6+
## Configuration files and Git branches
7+
8+
- `.opencode/automation.json` is a **file in the target checkout**, not in the
9+
plugin's source repository. Creating it does not automatically upload it.
10+
- With the global installation, `init` does **not** add a Git ignore rule.
11+
An ordinary `git add .` can therefore stage it unless your repository already
12+
ignores it. The alternative `install-local.sh` installer does add local
13+
exclusions automatically.
14+
- Keep machine-specific configuration untracked. From the target checkout,
15+
add a local ignore rule that is not itself committed:
16+
17+
```bash
18+
cd /absolute/path/to/your-project
19+
printf '\n/.opencode/automation.json\n' >> "$(git rev-parse --git-path info/exclude)"
20+
```
21+
22+
- Check whether Git already tracks it:
23+
24+
```bash
25+
git ls-files -- .opencode/automation.json
26+
```
27+
28+
No output means it is untracked. If the path appears, ignoring it is not
29+
enough: use `git rm --cached -- .opencode/automation.json` and commit that
30+
removal to stop versioning it on the current branch. The local file stays.
31+
- An untracked, ignored file normally stays in place during branch switches.
32+
If another branch tracks that same path, Git can replace it; keep a backup
33+
before switching to such branches. A tracked file follows branch contents
34+
and can change or disappear when you switch. OpenCode does not restore it.
35+
`git clean -fdx` also deletes ignored files.
36+
- A separate clone or worktree does not automatically inherit an untracked
37+
configuration. The scheduler only activates in the primary checkout.
38+
Bot-created worktrees are used for implementation, without starting another
39+
scheduler. Queue data lives under the shared Git directory in
40+
`opencode2-automation/` and is not uploaded by Git push.
41+
42+
## Configuration
43+
44+
A minimal configuration is:
45+
46+
```json
47+
{
48+
"model": "provider/model"
49+
}
50+
```
51+
52+
Use a model available in your own OpenCode 2 installation. Optional fields:
53+
54+
| Field | Purpose |
55+
| --- | --- |
56+
| `baseBranch` | Base for new worktrees and PRs; defaults to the GitHub default branch. |
57+
| `capabilities` | Main model support: `text`, `vision`, `audio`; defaults to `["text"]`. |
58+
| `mediaModel` | Separate helper model and its capabilities; example below. |
59+
| `systemPromptFile` | Optional Markdown instructions appended to the bundled bot prompt; path relative to the primary checkout, or absolute. |
60+
| `trigger` | Mention that starts work; defaults to `@opencodebot`. |
61+
| `everySeconds` | Polling interval; defaults to 60 seconds. |
62+
| `check` | Test command as an argument array, such as `["npm", "test"]`; `false` skips tests. |
63+
| `authors` | GitHub usernames allowed to request work and authorize merging (merge also requires repository write access). |
64+
| `signature` | Signature appended to every posted comment and PR description; defaults to `your-github-login[OpenCode2]`. |
65+
| `autoMerge` | Automatic merge settings: `enabled` (default `true`), `method` (default `squash`), and exact approval `comments`. |
66+
67+
When tests are skipped, the PR explicitly reports that automated tests were not
68+
run. Git consistency checks and the requirement for an actual change remain.
69+
Restart the service while idle after changing configuration.
70+
71+
For noninteractive setup, use `--yes` to accept defaults for omitted options.
72+
Provide the model and a test command (or explicitly skip tests):
73+
74+
```bash
75+
cd /absolute/path/to/your-project
76+
"$HOME/.local/bin/opencode2-automation" init --model provider/model --skip-tests --yes
77+
```
78+
79+
Optional flags: `--base-branch develop`, `--capabilities text`,
80+
`--media-model provider/vision-model`, `--media-capabilities text,vision`,
81+
`--system-prompt .opencode/bot.md`. With `--yes`, supply a helper explicitly
82+
if you want media support with a text-only main model.
83+
84+
## Questions, branches, media, and bot instructions
85+
86+
- **Questions:** reply in the issue as an account in `authors`; no repeated
87+
mention is needed. The bot enters `waiting` and resumes after the next scan.
88+
Questions in the first analysis block worktree and session creation. Unclear
89+
replies prompt another question. You may use the same account as the bot;
90+
its marked comments are excluded from replies.
91+
Permission questions require the exact `/allow QUESTION_ID` or
92+
`/deny QUESTION_ID` shown in the comment. Explicit OpenCode deny rules remain.
93+
- **Base branch:** write naturally, such as "use branch develop" or "work from
94+
release/next", in the issue or an authorized comment. The configured model
95+
interprets the request, including languages such as Polish. Unclear or missing
96+
branches trigger a question in the issue before work starts. `baseBranch` is
97+
only the default; `/base` remains an optional shortcut. Existing tasks keep
98+
their pinned base.
99+
- **Media:** declare actual model capabilities and a helper if needed:
100+
101+
```json
102+
{
103+
"model": "provider/text-model",
104+
"capabilities": ["text"],
105+
"mediaModel": {
106+
"model": "provider/vision-model",
107+
"capabilities": ["text", "vision"]
108+
}
109+
}
110+
```
111+
112+
Add these fields to your existing JSON using your installed model IDs. The
113+
helper analyzes attachments in a separate session; the main model stays
114+
unchanged. Add `audio` if the helper also accepts audio files.
115+
- **Instructions:** [prompts/bot.md](../prompts/bot.md) is bundled and always loaded.
116+
For project-specific instructions, create `.opencode/bot.md` in the primary
117+
checkout and set `"systemPromptFile": ".opencode/bot.md"`. It is appended
118+
to the baseline and reread on each use, including from worker branches.
119+
120+
See [runtime behavior and examples](runtime.md) for reply handling, branch
121+
selection, supported media inputs, and prompt persistence.
122+
123+
## Automatic merge and message signatures
124+
125+
Example project configuration:
126+
127+
```json
128+
{
129+
"model": "provider/model",
130+
"check": false,
131+
"signature": "YOUR_LOGIN[OpenCode2]",
132+
"autoMerge": {
133+
"enabled": true,
134+
"method": "squash",
135+
"comments": ["/merge", "lgtm, merge", "approved, merge"]
136+
}
137+
}
138+
```
139+
140+
For a PR created by this bot, either approve the current published commit using
141+
GitHub's **Approve** review, or post one of the configured full-message phrases
142+
in the PR conversation. Matching ignores case, repeated whitespace, and final
143+
periods/exclamation marks. Arbitrary positive prose, quoted commands, negations,
144+
and inline code review comments are not interpreted as merge instructions.
145+
146+
The approving account must be in `authors` (by default, the authenticated user)
147+
and have write, maintain, or admin permission on the repository. GitHub does not
148+
allow authors to approve their own PRs; use a configured comment in that case.
149+
Outstanding change requests block merge. The PR must be open, non-draft, and
150+
reported as clean and mergeable by GitHub. The merge request includes the exact
151+
verified head SHA; a changed branch cannot be merged using an older approval.
152+
The bot does not request a protection bypass. Configure required checks and review
153+
rules on GitHub for your repository's policy.
154+
155+
Approvals must be newer than the bot's latest publication. On upgrade, old tasks
156+
start watching for new approvals; historical approvals do not cause a merge.
157+
Pending issue feedback is processed before attempting a merge. Merge failures
158+
are retried at intervals of at least 60 seconds and appear as `mergeError` in
159+
`status` and in `/bot`. Successful merges receive a signed PR comment.
160+
161+
Signatures are appended to issue comments, PR descriptions, and merge
162+
acknowledgements. They identify the message in its text; GitHub still attributes
163+
posts to the account authenticated by your token. Existing posts are not rewritten.
164+
Set `"autoMerge": { "enabled": false }` to disable automatic merging.
165+

‎docs/installation.md‎

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,36 @@
11
# Installation on another machine
22

3-
Use the numbered [README installation, configuration, and update steps](../README.md).
4-
They cover global installation before choosing a target repository, configuring
5-
projects later, updating, removal, and keeping local configuration out of Git.
3+
Start with the [README](../README.md) for `.tgz` or source installation, updates,
4+
project configuration, headless startup, and removal. This page covers details
5+
and troubleshooting.
6+
7+
## Package registration
8+
9+
`npm install --global` runs the bundled `postinstall` script. It writes two small
10+
loaders under the OpenCode config directory, pointing to the installed package's
11+
server and TUI entrypoints. OpenCode discovers these without changes to
12+
`opencode.json`. Config path precedence is `OPENCODE_CONFIG_DIR`, then
13+
`$XDG_CONFIG_HOME/opencode`, then `$HOME/.config/opencode`.
14+
15+
Registration creates no project settings, asks no questions, and does not restart
16+
OpenCode. Normal `npm ci` in a source checkout and project-local npm installs skip
17+
global registration. Source installs register explicitly with `setup.js install`.
18+
19+
Updates reuse an existing recognized loader directory, including older names,
20+
and repoint both loaders when changing between source and `.tgz` installations.
21+
Customized files and duplicate registrations cause a clear error instead of being
22+
overwritten. Back up and resolve the reported loaders, then rerun installation.
23+
The installer does not modify other plugins or project configurations.
24+
25+
If npm was configured to skip lifecycle scripts, register manually after install:
26+
27+
```bash
28+
"$HOME/.local/bin/opencode2-automation" install
29+
```
30+
31+
Use the same command to repair registration after moving the installed package.
32+
Keep the same npm prefix for updates. `npm uninstall` does not run an uninstall
33+
hook; remove the OpenCode loaders first as described in the README.
634

735
## Prerequisites
836

@@ -30,7 +58,8 @@ cd "$HOME/opencode2-github-automation"
3058
npm ci && npm run build
3159
```
3260

33-
Continue with global registration in the README. The plugin source and the
61+
Run `node "$HOME/opencode2-github-automation/dist/setup.js" install`, then follow
62+
the README's restart and project configuration steps. The plugin source and the
3463
repository the bot works on are separate directories. A global installation
3564
remains inactive in projects without `.opencode/automation.json`.
3665

‎docs/runtime.md‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,41 @@ checkout, not the worker branch. Absolute paths are also accepted. The file is
125125
reread on every use; missing or empty configured files stop execution with an
126126
error. The plugin never overwrites your file. Version it with the project, or
127127
ignore it locally for machine-specific instructions.
128+
129+
## Follow progress and continue work
130+
131+
Starting a session shows a notification and opens a background tab when tabs
132+
are enabled. Use `/bot` to list tasks and open a session.
133+
134+
Closing or merging the PR automatically closes its known bot session tabs,
135+
including earlier rounds and media helpers. This also works for manual GitHub
136+
actions with `autoMerge` disabled. Closure is detected on the next repository
137+
scan; connected TUIs also refresh every 10 seconds. Busy tabs wait until their
138+
work finishes. Session history is preserved, and `/bot` can reopen a session.
139+
Reopening it manually keeps it open for the current TUI instance. No additional
140+
configuration is required.
141+
142+
A new comment from an authorized author on a tracked issue starts another round:
143+
acknowledgement, implementation, and a push to the same open PR. The mention does
144+
not need to be repeated. Comments received during execution wait for the next
145+
round. A mention in an authorized comment can also start work on an untracked issue.
146+
147+
Edits to existing comments and PR review comments are not supported. Closing the
148+
issue or closing/merging the PR blocks further rounds.
149+
150+
Management commands run from the target repository:
151+
152+
For source installations, replace `"$HOME/.local/bin/opencode2-automation"` with
153+
`node "$HOME/opencode2-github-automation/dist/setup.js"`.
154+
155+
```bash
156+
cd /absolute/path/to/your-project
157+
"$HOME/.local/bin/opencode2-automation" status
158+
"$HOME/.local/bin/opencode2-automation" scan
159+
"$HOME/.local/bin/opencode2-automation" pause
160+
"$HOME/.local/bin/opencode2-automation" resume
161+
```
162+
163+
Pausing stops scheduled scans; it does not cancel accepted tasks or active sessions.
164+
Do not run independent bots on two machines against the same issues: they do not
165+
share queue ownership across machines.

‎package-lock.json‎

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"name": "opencode2-automation",
3-
"version": "0.5.0-beta.4",
3+
"version": "0.5.0-beta.5",
44
"description": "Issue-to-PR automation for OpenCode 2 with a scheduler and GitHub dispatcher",
55
"main": "./dist/index.js",
66
"files": [
77
"dist",
88
"README.md",
99
"docs",
10-
"prompts"
10+
"prompts",
11+
"scripts/postinstall.mjs"
1112
],
1213
"bin": {
1314
"opencode2-automation": "./dist/setup.js"
@@ -24,6 +25,7 @@
2425
"./rpc": "./dist/rpc.js"
2526
},
2627
"scripts": {
28+
"postinstall": "node scripts/postinstall.mjs",
2729
"prepack": "npm run build",
2830
"build": "tsc -p tsconfig.json",
2931
"typecheck": "tsc -p tsconfig.test.json",

‎scripts/postinstall.mjs‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { fileURLToPath } from "node:url";
2+
3+
// Source npm ci and project-local installs must not change global registration.
4+
// dist is already included in the tarball; consumers do not need TypeScript.
5+
if (process.env.npm_config_global === "true") {
6+
try {
7+
const { installGlobalEntrypoints } = await import("../dist/install.js");
8+
const directory = await installGlobalEntrypoints(fileURLToPath(new URL("..", import.meta.url)));
9+
console.log(`Registered OpenCode 2 automation and TUI in ${directory}. Run opencode2-automation init in a project when ready. Restart the OpenCode 2 service when its sessions are idle.`);
10+
} catch (error) {
11+
console.error(`OpenCode 2 registration failed: ${error instanceof Error ? error.message : "Unknown error"}`);
12+
process.exitCode = 1;
13+
}
14+
}

0 commit comments

Comments
 (0)