Revert "feat(home,agents): herdr workspaces connect to shared opencode serve (ADR-0006, T34)"
test-runner / smoke (push) Canceled after 0s

This reverts commit 3e85307361.
This commit is contained in:
oqyude committed 2026-10-15 20:15:39 +03:00
1 parent 158f08d14a
commit 574ec2719c
6 files changed
+10 -335

No files matched your search

+9 -68
View File
@@ -24,21 +24,15 @@
# parallel/automated herdr workloads land on the user's live server.)
#
# Children OpenCode instances (integration-managed, see integrations docs):
# - herdr launches the built-in opencode agent by typing the bare token
# `opencode` into the pane's shell. Left alone, every workspace tab hence
# starts a full opencode process with its own in-process server
# (~0.8 GiB per tab).
# - This module instead puts a PATH shim (`opencodeAttachShim` below) first
# in the unit's PATH, so each pane becomes a thin client of the single
# long-running shared server (opencode-web.service, 127.0.0.1:4096). See
# .agent/decisions/0006-herdr-shared-opencode-serve.md.
# - Children inherit the parent env, so EnvironmentFile below covers both
# herdr and its opencode clients — including OPENCODE_SERVER_USERNAME /
# OPENCODE_SERVER_PASSWORD, which `opencode attach` reads automatically
# for the server's basic auth.
# - RISK (opencode #55076): the shared server may resume killed sessions
# without their original permissions/step limits. That mitigation lives
# with the server (opencode-web), not here; see ADR-0006 "Risks".
# - herdr spawns `opencode serve` per worktree on demand via the built-in
# opencode integration. Those children inherit the parent env, so
# EnvironmentFile below covers both herdr and its opencode children.
# - This deliberately bypasses the shared background `opencode serve`
# service that the existing opencode-web systemd user unit uses. Per
# opencode issue #55076 (severity:high, reproduced, ~$24 runaway),
# the shared background service resumes killed sessions without their
# original permissions or step limits. herdr-managed opencode children
# are scoped to herdr's lifetime, so a herdr restart cleanly drops them.
#
# Credentials:
# - herdr stores NO secrets. Per herdr docs/integrations/, each agent
@@ -56,51 +50,6 @@
xlib,
...
}:
let
# Address of the shared `opencode serve` provided by programs.opencode.web
# (home/modules/opencode.nix:361-370). opencode's built-in default port for
# `opencode web` is 4096; this literal must match that service.
sharedServeUrl = "http://127.0.0.1:4096";
# Only hosts that actually run the shared server get the shim (sapphira).
# rydiwo (home/secondary.nix) does not import opencode.nix, so there the
# option is at its default `false` and herdr keeps its stock behaviour.
sharedServeEnabled = config.programs.opencode.web.enable;
# A `PATH` entry named `opencode` that redirects herdr's launch to the shared
# server instead of letting every pane spawn its own full opencode instance.
#
# Why a PATH shim (and not a plugin or daemon patch): herdr's daemon builds
# the pane command as the bare token `opencode`
# (src/detect/mod.rs: `Agent::OpenCode => "opencode"`) and types it into the
# pane's shell (src/app/agents.rs: `start_agent`). `$PATH` is therefore the
# only interception point that neither forks herdr nor patches the
# herdr-web-ui plugin — and it survives `herdr plugin update`, which would
# clobber a plugin-side patch (cf. ADR-0005 maintenance debt).
#
# On daemon restart herdr resumes an agent as `opencode --session <id>`
# (src/agent_resume.rs). The shim forwards argv, so that path becomes
# `opencode attach <url> --dir $PWD --session <id>` against the same server.
#
# Real subcommands (if the user ever runs `opencode serve` etc. inside a
# herdr pane) are passed through untouched.
opencodeAttachShim = pkgs.writeShellScriptBin "opencode" ''
set -eu
case "''${1:-}" in
serve|web|attach|run|acp|mcp|providers|auth|agent|models|debug|session|export|import|plugin|plug|db|github|pr|completion|upgrade|uninstall|stats)
exec ${pkgs.opencode}/bin/opencode "$@"
;;
esac
exec ${pkgs.opencode}/bin/opencode attach ${sharedServeUrl} --dir "$PWD" "$@"
'';
# Base PATH for the herdr unit. systemd does NOT expand variables inside
# `Environment=` (verified on sapphira 2026-10-15: `PATH=/x:$PATH` is stored
# literally), so the full PATH must be spelled out. Only directories that
# actually resolve are kept — `~/.nix-profile/bin` and
# `/nix/var/nix/profiles/default/bin` are dangling symlinks on sapphira.
basePath = "/run/wrappers/bin:${config.home.profileDirectory}/bin:/run/current-system/sw/bin";
in
{
# Install herdr binary. nixpkgs already installs bash/fish/zsh shell
# completions via installShellCompletion in the package's postInstall
@@ -146,14 +95,6 @@ in
# both the orchestrator and its integration-managed OpenCode
# instances. herdr itself stores NO secrets.
EnvironmentFile = xlib.dirs.opencode-server-env;
# Only set where the shared server exists: prepend the `opencode` shim so
# herdr panes attach to it instead of spawning their own instance. On
# hosts without the server the option stays unset and herdr's children
# inherit the manager PATH unchanged.
Environment = lib.mkIf sharedServeEnabled [
"OPENCODE_ATTACH_URL=${sharedServeUrl}"
"PATH=${lib.makeBinPath [ opencodeAttachShim ]}:${basePath}"
];
# Memory protection, same pattern as opencode-web
# (home/modules/opencode.nix:407-412). sapphira has 5.6 GiB RAM
# with ~1 GiB baseline; herdr's cgroup covers itself AND its