Skip to content

Commit 0853109

Browse files
authored
Merge pull request #91 from freshtechbro/codex/package-postinstall-autostart
feat: reconcile autostart during package postinstall
2 parents 4240cc0 + 806407f commit 0853109

13 files changed

Lines changed: 997 additions & 39 deletions

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,13 @@ npx --no-install opendevbrowser help
115115

116116
Published npm consumer proof is tracked separately in [docs/RELEASE_RUNBOOK.md](docs/RELEASE_RUNBOOK.md) through `scripts/registry-consumer-smoke.mjs`.
117117

118-
Set `OPDEVBROWSER_SKIP_POSTINSTALL_SKILL_SYNC=1` before `npm install` only if you need a packaging smoke test that avoids the install-time managed-skill refresh entirely.
118+
Set `OPDEVBROWSER_SKIP_POSTINSTALL_SKILL_SYNC=1` before `npm install` only if you need a packaging smoke test that exits the legacy package lifecycle shim before built postinstall code imports. Set `OPDEVBROWSER_SKIP_INSTALL_AUTOSTART_RECONCILIATION=1` when you only want to skip install-time daemon auto-start reconciliation.
119119

120120
See [docs/FIRST_RUN_ONBOARDING.md](docs/FIRST_RUN_ONBOARDING.md) for the full onboarding checklist, [docs/DEPENDENCIES.md](docs/DEPENDENCIES.md) for runtime inventory, and [docs/SURFACE_REFERENCE.md](docs/SURFACE_REFERENCE.md) for the live CLI and tool surface.
121121

122-
Successful installs reconcile daemon auto-start on supported platforms so the relay is available on login. macOS LaunchAgents persist a stable `WorkingDirectory` under `~/.cache/opendevbrowser` so launchd does not start the daemon from `/`. If the current CLI entrypoint lives under a transient temp-root path such as a first-run `/tmp` or `/private/tmp` workspace, OpenDevBrowser refuses to persist that path as auto-start. Rerun `opendevbrowser daemon install`, or `npx --no-install opendevbrowser daemon install` from a persistent local package install, from a stable install location if you want login auto-start; remove it later with `opendevbrowser daemon uninstall`.
122+
CLI/plugin installs still reconcile daemon auto-start on supported platforms after successful install so the relay is available on login. Raw npm global package postinstall also best-effort reconciles auto-start when npm lifecycle context clearly indicates a global install. Local, ambiguous, conflicting, or non-npm package-manager contexts skip package postinstall auto-start without failing package installation.
123+
124+
Package postinstall auto-start targets the packaged CLI entrypoint `dist/cli/index.js`, not the lifecycle shim at `scripts/postinstall-sync-skills.mjs`. `src/cli/daemon-autostart.ts` owns platform safety and refuses to persist `_npx`, `/tmp`, `/private/tmp`, or onboarding workspace paths before writing LaunchAgent or Task Scheduler state. Package postinstall warnings are non-fatal; repair with `opendevbrowser daemon install`, inspect with `opendevbrowser daemon status`, or remove with `opendevbrowser daemon uninstall`.
123125

124126
Bundled skills sync to **OpenCode, Codex, ClaudeCode, and AmpCLI** targets during install. `npx opendevbrowser` manages global or project-local targets according to the selected skills mode, and package installation (`npm install -g`, local tarball install, or equivalent) best-effort syncs the canonical bundled packs into the managed global targets during package `postinstall`. See [docs/CLI.md](docs/CLI.md) for exact target paths.
125127

@@ -751,7 +753,7 @@ See [docs/SURFACE_REFERENCE.md](docs/SURFACE_REFERENCE.md) for the source-accura
751753
| `npx opendevbrowser --local` | Install to project config |
752754
| `npx opendevbrowser --with-config` | Also create opendevbrowser.jsonc |
753755
| `npx opendevbrowser --full` | Full install (config + extension assets) |
754-
| `npm install -g opendevbrowser` | Install persistent global CLI |
756+
| `npm install -g opendevbrowser` | Install persistent global CLI; npm global postinstall best-effort reconciles daemon auto-start |
755757
| `npx opendevbrowser --update` | Repair OpenCode package caches and plugin pins |
756758
| `npx opendevbrowser --uninstall` | Remove from config |
757759
| `npx opendevbrowser --version` | Show version |

docs/AGENTS.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ When command/tool/channel surface changes:
3232
- `README.md`
3333
- relevant `AGENTS.md` files
3434

35+
When install, package postinstall, or daemon auto-start behavior changes:
36+
- `README.md`
37+
- `docs/CLI.md`
38+
- `docs/FIRST_RUN_ONBOARDING.md`
39+
- `docs/ARCHITECTURE.md`
40+
- `src/cli/AGENTS.md`
41+
- `scripts/AGENTS.md`
42+
- `tests/AGENTS.md`
43+
3544
When canvas session/code-sync/projection behavior changes:
3645
- `docs/CLI.md`
3746
- `docs/SURFACE_REFERENCE.md`
@@ -85,6 +94,7 @@ When mirrored website inputs change (`docs/`, `skills/`, `assets/`, `CHANGELOG.m
8594

8695
- Do not keep stale numeric claims when source has changed.
8796
- Do not document unsupported flags/commands.
97+
- Do not conflate CLI/plugin install auto-start reconciliation with raw package postinstall. Package postinstall is best effort, uses `dist/cli/index.js`, and skips local, ambiguous, conflicting, or non-npm package-manager contexts without failing installation.
8898
- Do not describe `canvas.starter.list` or `canvas.starter.apply` as unshipped once `PUBLIC_CANVAS_COMMANDS` includes them.
8999
- Do not describe `tsx-react-v1` as the shipped adapter lane; current docs must describe it as a legacy binding that migrates to `builtin:react-tsx-v2`.
90100
- Do not imply public-repo ownership of `frontend/`; website source is private.

docs/ARCHITECTURE.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,9 @@ Daemon-backed `canvas` CLI requests inject the caller worktree as `repoRoot`; `C
4242
Canonical inventory and channel contracts: `docs/SURFACE_REFERENCE.md`.
4343
Frontend architecture and generation flow are documented in `docs/FRONTEND.md`.
4444

45-
The CLI installer reconciles daemon auto-start after every successful install
46-
(macOS LaunchAgent, Windows Task Scheduler). Existing per-user entries are rechecked and repaired when they are missing or stale on
47-
supported platforms, and when the macOS LaunchAgent is malformed or lacks the stable `~/.cache/opendevbrowser` working directory; unsupported platforms are skipped and continue without auto-start. If the current CLI entrypoint is running from a
48-
transient temp-root path, install-time reconciliation refuses to persist it and surfaces guidance to rerun `daemon install` from a
49-
stable install location. `getAutostartStatus()` remains the canonical source of auto-start truth for both install reconciliation
50-
and `daemon status`, and a stable persisted auto-start entry remains authoritative even when the current invocation is transient.
45+
Install-time daemon auto-start reconciliation has two entrypoints. CLI/plugin install still reconciles after every successful install. Raw npm global package postinstall runs `src/cli/installers/package-postinstall.ts` best effort, re-exported through `src/cli/installers/postinstall-skill-sync.ts` to keep the shipped built import path stable, and only attempts auto-start when npm lifecycle context clearly indicates a global install. Local, ambiguous, conflicting, or non-npm package-manager contexts skip package postinstall auto-start without failing package installation.
46+
47+
Both entrypoints reuse the same reconciliation and platform safety owner in `src/cli/daemon-autostart.ts` (macOS LaunchAgent, Windows Task Scheduler). Existing per-user entries are rechecked and repaired when they are missing or stale on supported platforms, and when the macOS LaunchAgent is malformed or lacks the stable `~/.cache/opendevbrowser` working directory; unsupported platforms are skipped and continue without auto-start. Package postinstall injects the packaged CLI entrypoint `dist/cli/index.js`, not the lifecycle shim at `scripts/postinstall-sync-skills.mjs`. If the current CLI entrypoint is running from a transient `_npx`, `/tmp`, `/private/tmp`, or onboarding workspace path, install-time reconciliation refuses to persist it and surfaces guidance to rerun `daemon install` from a stable install location. `getAutostartStatus()` remains the canonical source of auto-start truth for both install reconciliation and `daemon status`, and a stable persisted auto-start entry remains authoritative even when the current invocation is transient.
5148

5249
## Challenge orchestration ownership
5350

@@ -565,7 +562,7 @@ Validation script:
565562
- `src/devtools/`: console/network/exception trackers and debug bundle channels.
566563
- `src/tools/`: tool definitions and response shaping.
567564
- `src/relay/`: relay server and protocol types.
568-
- `src/cli/`: CLI commands, daemon/autostart, `DaemonClient`, `RemoteManager`, `RemoteCanvasManager`, relay status cache, and installers.
565+
- `src/cli/`: CLI commands, daemon/autostart, `DaemonClient`, `RemoteManager`, `RemoteCanvasManager`, relay status cache, and installers, including package postinstall orchestration.
569566
- `src/cli/commands/artifacts.ts`: artifact lifecycle cleanup (`artifacts cleanup --expired-only`).
570567
- `extension/`: Chrome extension UI and background logic.
571568
- `opendevbrowser-website-deploy/frontend/`: private website app and generated content pipeline.

docs/CLI.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ npx --no-install opendevbrowser help
7070
Load extension unpacked from:
7171
- `$WORKDIR/node_modules/opendevbrowser/extension`
7272

73-
Set `OPDEVBROWSER_SKIP_POSTINSTALL_SKILL_SYNC=1` before `npm install` only if you need a packaging smoke test that avoids the install-time managed-skill refresh entirely.
73+
Set `OPDEVBROWSER_SKIP_POSTINSTALL_SKILL_SYNC=1` before `npm install` only if you need a packaging smoke test that exits the legacy package lifecycle shim before built postinstall code imports. Set `OPDEVBROWSER_SKIP_INSTALL_AUTOSTART_RECONCILIATION=1` when you only want to skip install-time daemon auto-start reconciliation.
7474

75-
By default (`--skills-global`), the CLI installs bundled skills to global OpenCode/Codex/ClaudeCode/AmpCLI locations. Use `--skills-local` for project-local locations or `--no-skills` to skip CLI-managed skill installation. Package installation (`npm install -g`, local tarball install, or equivalent) also best-effort syncs the canonical bundled packs into the managed global skill targets during package `postinstall`. Use `--full` to always create `opendevbrowser.jsonc` and pre-extract extension assets.
75+
By default (`--skills-global`), the CLI installs bundled skills to global OpenCode/Codex/ClaudeCode/AmpCLI locations. Use `--skills-local` for project-local locations or `--no-skills` to skip CLI-managed skill installation. Package installation (`npm install -g`, local tarball install, or equivalent) also best-effort syncs the canonical bundled packs into the managed global skill targets during package `postinstall`. Raw npm global package postinstall best-effort reconciles daemon auto-start only when npm lifecycle context clearly indicates a global install; local, ambiguous, conflicting, or non-npm package-manager contexts skip auto-start without failing package installation. Use `--full` to always create `opendevbrowser.jsonc` and pre-extract extension assets.
7676

7777
Installer inventory:
7878
- `--skills-global` and `--skills-local` sync the 10 canonical `opendevbrowser-*` packs under `skills/` into managed global or project-local agent directories.
@@ -220,13 +220,11 @@ npx opendevbrowser --skills-local
220220
npx opendevbrowser --no-skills
221221
```
222222

223-
On successful installs, the CLI reconciles daemon auto-start on supported platforms (macOS/Windows) so the relay is available on
223+
On successful installs, the CLI/plugin installer reconciles daemon auto-start on supported platforms (macOS/Windows) so the relay is available on
224224
login. Existing installs are rechecked and repaired when the per-user auto-start entry is missing or stale on macOS and Windows,
225-
and when the macOS LaunchAgent is malformed or missing its stable non-root working directory. If the current CLI entrypoint lives under a transient temp-root path (for example a
226-
first-run `/tmp` or `/private/tmp` `npx` workspace), OpenDevBrowser refuses to persist that path as auto-start. Plugin install
227-
still succeeds, but auto-start repair warns and you must rerun `opendevbrowser daemon install` from a stable install location, or
228-
`npx --no-install opendevbrowser daemon install` from a persistent local package install. You can remove auto-start later with
229-
`opendevbrowser daemon uninstall`.
225+
and when the macOS LaunchAgent is malformed or missing its stable non-root working directory. Raw npm global package postinstall also runs the same reconciliation best effort when npm lifecycle context clearly indicates a global install. Package postinstall targets `dist/cli/index.js`, not `scripts/postinstall-sync-skills.mjs`, and all package warnings are non-fatal.
226+
227+
If the current CLI entrypoint lives under a transient temp-root path (for example a first-run `/tmp` or `/private/tmp` `npx` workspace), OpenDevBrowser refuses to persist that path as auto-start. Plugin install still succeeds, and package install still exits successfully, but auto-start repair warns or skips. Rerun `opendevbrowser daemon install` from a stable install location, or `npx --no-install opendevbrowser daemon install` from a persistent local package install. You can inspect with `opendevbrowser daemon status` and remove auto-start later with `opendevbrowser daemon uninstall`.
230228

231229
### Update
232230

@@ -382,7 +380,10 @@ Behavior:
382380
- when the current invocation is transient, a stable persisted auto-start entry can still report `health="healthy"`; `expectedCommand` is omitted instead of advertising the transient current path as the repair target.
383381
- `daemon status` returns exit code `0` when the daemon is reachable even if auto-start is missing, stale, or malformed, and `10` when the daemon is not running.
384382
- Successful plugin installs surface auto-start reconciliation through `autostartAction`; `autostartError` is included only when repair fails.
385-
- If install-time reconciliation is running from a transient temp-root CLI path, it refuses to write auto-start and reports `autostartAction="repair_failed"` with guidance to rerun `opendevbrowser daemon install` from a stable install location.
383+
- Raw npm global package postinstall best-effort reconciles auto-start only when npm lifecycle context clearly indicates a global install. Local, ambiguous, conflicting, or non-npm package-manager contexts skip auto-start without failing package installation.
384+
- Package postinstall auto-start uses `dist/cli/index.js` as the packaged CLI entrypoint and never persists `scripts/postinstall-sync-skills.mjs`.
385+
- `OPDEVBROWSER_SKIP_INSTALL_AUTOSTART_RECONCILIATION=1` skips install-time auto-start reconciliation only. `OPDEVBROWSER_SKIP_POSTINSTALL_SKILL_SYNC=1` remains the legacy full package lifecycle shim skip because the shim exits before importing built code.
386+
- If install-time reconciliation is running from a transient temp-root CLI path, it refuses to write auto-start and reports `autostartAction="repair_failed"` for plugin installs or a non-fatal package postinstall warning, with guidance to rerun `opendevbrowser daemon install` from a stable install location.
386387

387388
Exit codes align with the CLI:
388389
- `0`: success

docs/FIRST_RUN_ONBOARDING.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ Expected:
5656
- `$CODEX_HOME/skills`
5757
- `$CLAUDECODE_HOME/skills`
5858
- `$AMP_CLI_HOME/skills`
59+
- local tarball package postinstall skips daemon auto-start because the npm lifecycle context is local, not a clear global install
5960
- each populated global skill directory contains `.opendevbrowser-managed-skills.json` plus one `.opendevbrowser-managed-skill.json` sentinel per bundled canonical pack
6061

6162
## 2b) Validate the help-led quick-start path
@@ -147,15 +148,16 @@ Expected:
147148
- extension assets are extracted to `~/.config/opencode/opendevbrowser/extension`
148149
- extracted assets now include `manifest.json`, `popup.html`, `canvas.html`, `dist/`, and `icons/`
149150
- `OPENCODE_CONFIG_DIR` isolates config lookup only; it does not relocate the extracted extension asset directory
150-
- because this guide uses a temp `WORKDIR`, install-time daemon auto-start reconciliation may warn instead of persisting a background entry
151+
- because this guide uses a temp `WORKDIR`, CLI/plugin install-time daemon auto-start reconciliation may warn instead of persisting a background entry
152+
- raw package postinstall auto-start is best effort and skips local, ambiguous, conflicting, or non-npm package-manager contexts without failing package installation
151153
- if persistent login auto-start is desired after onboarding, rerun `opendevbrowser daemon install` from a stable install location outside the temp workspace; macOS should persist `WorkingDirectory=~/.cache/opendevbrowser`
152154

153155
## 3c) Stable auto-start follow-up
154156

155157
The onboarding workspace proves first-run package behavior, not long-lived daemon auto-start. Do **not** treat `$WORKDIR` as the
156158
final login-start location.
157159

158-
When you want to validate daemon auto-start, rerun from the intended persistent install location:
160+
When you want to validate daemon auto-start, rerun from the intended persistent install location. A raw `npm install -g opendevbrowser` may already reconcile auto-start during package postinstall when npm lifecycle context clearly indicates a global install, but the explicit daemon commands remain the repair and verification surface:
159161

160162
```bash
161163
# Global install

0 commit comments

Comments
 (0)