Skip to content

Refactor: Separate agentop's install logic from its prompts - #1227

Merged
huang195 merged 7 commits into
rossoctl:mainfrom
huang195:refactor/agentop-install-seams
Oct 2, 2026
Merged

huang195 merged 7 commits into
rossoctl:mainfrom
huang195:refactor/agentop-install-seams

Conversation

@huang195

@huang195 huang195 commented Oct 1, 2026

Copy link
Copy Markdown
Member

Summary

Splits agentop service install|uninstall and agentop configure claude-code enable|disable, so that the next PR's agentop setup can run them behind its own consent screen and read the outcome without parsing text. There is no behaviour change.

  • claude-code enable / disable:

    • planClaudeCodeEnable and applyClaudeCodeEnable, plus printTrustFileNotes;
    • planClaudeCodeDisable and applyClaudeCodeDisable.

    The plan functions only read; the apply functions write.

  • service install / uninstall:

    • runServiceInstall runs install from the point of consent onward and returns installResult{exit, alreadyCurrent, healthy}.
    • removeService is uninstall's action.

    runServiceInstall still writes the command's own text to the writers it is given.

  • Prompt seams: serviceConfirm and claudeCodeConfirm follow the bobConfirm pattern, so tests can answer a prompt without /dev/tty.

This is the first of four PRs toward agentop setup: one consent screen, a checklist, and rollback for the laptop install.

How "no behaviour change" is shown

Characterization tests land first, in their own commits, and pass on the code before any of it moves. They pin stdout, stderr, the exit code and the effects on disk exactly.

configure claude-code enable:

  • fresh enable;
  • partial enable (some keys already Cortex's);
  • CA files present;
  • trust bundle missing;
  • declined, and accepted;
  • already enabled;
  • a config that will not load;
  • the refusals.

configure claude-code disable:

  • after an enable;
  • restoring a value the user had;
  • nothing to do;
  • declined, and accepted.

service install:

  • no config, no supervisor, no binary, a config that will not load;
  • declined, and accepted;
  • a fresh install with something already serving, and with nothing serving yet;
  • already current;
  • --restart over a current install.

service uninstall:

  • --yes, accepted, declined;
  • nothing to do.

Also pinned: the macOS login-home warning.

Not pinned:

  • adopting a hand-started proxy;
  • the health-check timeout;
  • the supervisor not reporting the job as running;
  • a failed launchd or systemd load;
  • migration failures;
  • loginctl enable-linger failing;
  • the warnings for reading and writing the state record;
  • the decline text shown when there is no terminal.

The code for those paths moves unchanged apart from its return statements, and git diff --color-moved on cmd_service.go shows that.

One scenario runs on both platforms: the fake supervisor stubs both launchctl and systemctl. The macOS-only output (where the Go keychain note appears, and the login-home warning) was checked on macOS only, because CI runs on Ubuntu.

The strings scripts/install.sh filters on stay in cmd_service.go, which is the file install_test.sh checks for them.

Test plan

  • go test -race ./... in cmd/agentop
  • sh scripts/install_test.sh
  • git diff --color-moved on cmd_service.go and cmd_claudecode.go

Assisted-By: Claude Code

The prompts open /dev/tty, so a test that reaches one hangs on a developer's
machine and declines in CI. bob and bobshell already route theirs through a
package var for this reason; service and claude-code now do the same, which is
what lets the next commits pin the interactive output byte for byte.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
Pins enable and disable byte for byte as they print today, before either is
split. Enable: fresh, partial (some keys already hold Cortex's values, so
only the rest are listed), with the CA files present, with ca.crt but no
trust bundle, declined, accepted at the prompt, already enabled, a config
that will not load, and the refusals. Disable: after an enable, restoring a
value the user had, nothing to do, declined, and accepted.

The accept path matters most: it is where the coming plan/apply split joins
its two halves, so each accept test also checks that the settings file
changed. The macOS keychain note is built with darwinGoNote rather than
spelled out, so its text and position are pinned on macOS only.

Not pinned: an unreadable or foreign state record, and a failed state write.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
Pins install and uninstall as they print today, after normalizing $HOME, the
supervisor's name and the macOS crash-recovery note. Install: the no-config,
no-supervisor, no-binary and unloadable-config refusals; declined and
accepted at the prompt (accepted is the one path that prints "Wrote
<unit>"); a fresh --yes install, both with something already answering
health checks and with nothing serving yet; the already-current re-run; and
--restart over a current install. Uninstall: --yes, accepted, declined, and
nothing installed. The unload is asserted through the fake job's state,
because a successful unload prints nothing. The macOS login-home warning is
checked in raw stderr, since normalizing strips it.

One scenario runs on darwin and linux: the fake supervisor stubs launchctl,
systemctl, loginctl and lsof together, so CI covers systemd and a Mac covers
launchd. Every stub goes through installStub, because the fakes answer for
the real io.rossoctl.cortex label, and a test that fell through to the real
launchctl would boot out the Cortex the machine is running.

Not pinned: adopting a hand-started proxy (it needs a live process named
cortex), a health-check timeout, the supervisor not reporting the job
running, a failed load, migration failures, and loginctl enable-linger
failing.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
planClaudeCodeEnable runs the checks that can refuse an enable, in the order
enable made them, and touches nothing on disk. applyClaudeCodeEnable records
the prior values and writes the settings. printTrustFileNotes keeps the
CA-file notes in the command, out of both halves. agentop setup needs the
halves separately: it shows the change on one consent screen alongside the
rest of what it will do, then applies it without a prompt of its own.

The two refusals that printed their own text now return it as errors, which
the command prints through the same "agentop: %v" it uses for the others, so
the bytes are unchanged. The characterization tests pass unchanged.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
The same split as enable, for the other direction: setup's rollback and
agentop uninstall both need to undo the Claude Code wiring without the
command's prompt and summary. planClaudeCodeDisable lists the managed keys
that are present and touches nothing; applyClaudeCodeDisable restores what
enable recorded, removes what it added, and deletes the record. Output is
unchanged.

The tests seed a stale Cortex HTTPS_PROXY that enable replaces, because a
prior value equal to what enable writes cannot tell a restored value from a
leftover one. The enable apply test now fails, rather than panicking, when
no state record was written. Two doc comments added by the enable split are
narrowed to what the code does today.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
runServiceInstall is install from the point of consent onward. Its body is
the old one, left in place, with three kinds of edit. Each return now
reports an installResult, so a caller can tell started-and-healthy,
started-but-unprobed and already-current apart without parsing text. The
--yes check that hid the unit path became an announceUnit parameter. And
the hand-started proxy that the preview names is passed in as adopt, so the
preview and the action agree on it. runServiceInstall still writes the
command's own text to the writers it is given.

removeService is uninstall's action without its preview and summary. One of
its comments now names serviceUninstall's message instead of "the message
below", since the two no longer share a function.

Every string stays in cmd_service.go, where install_test.sh looks for the
ones install.sh filters on, and the exit codes install.sh branches on are
unchanged. The new tests pin each installResult outcome, including an
install with no health URL to probe, and removeService's answer when the
unit goes but the stamp will not.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
printTrustFileNotes's doc comment said a caller that applies and then
starts the proxy has nothing to warn about because the files appear on
that start; the trust bundle never appears on a host with no system root
store, so the comment now says only that a caller applying before the
start should check the files after it. The comment on
TestRunServiceInstall_UnprobedInstallIsNotHealthy said only the result
tells a healthy install from an unprobed one, but stdout differs too; it
now says so short of parsing stdout.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Hai Huang <[email protected]>
@huang195
huang195 requested a review from a team as a code owner October 1, 2026 22:50
@coderabbitai

coderabbitai Bot commented Oct 1, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 48 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 01c6c81d-4d65-4e23-95d1-de19ec548533

📥 Commits

Reviewing files that changed from the base of the PR and between 39cb3de and 7cc705a.

📒 Files selected for processing (7)
  • cmd/agentop/cmd_claudecode.go
  • cmd/agentop/cmd_claudecode_characterize_test.go
  • cmd/agentop/cmd_claudecode_plan_test.go
  • cmd/agentop/cmd_service.go
  • cmd/agentop/cmd_service_characterize_test.go
  • cmd/agentop/cmd_service_core_test.go
  • cmd/agentop/prompt_seam_test.go
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pdettori pdettori left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified the pure-refactor claim against the base files: exit codes (exitDeclined/exitNoSupervisor at the same points), output text and ordering (the \n-terminated Fprintf messages became fmt.Errorf wrapped by the unchanged agentop: %v\n — same bytes), --yes/announceUnit semantics, and the consent flow are all preserved. Plan functions are read-only (planClaudeCodeEnable never receives statePath, so it structurally cannot write the state file), and apply writes everything the old code wrote. Two suggestions (#1, #2) are best addressed before the setup PR builds on these seams. Test quality is genuinely strong — byte-exact stdout/stderr/exit-code pins plus disk-effect assertions that guard against vacuous passes.


Review summary

  • Author: huang195 (MEMBER — maintainer)
  • Areas reviewed: Go CLI refactor with line-by-line behavior-change audit, characterization tests
  • Agent/IDE config (.claude/.vscode): none
  • Commits: 7, all signed-off
  • CI status: all green (CodeRabbit rate-limited, non-blocking)

" Nothing to change. Use `agentop service restart` to restart it anyway.\n",
filepath.Base(p.binary), supervisorName(runtime.GOOS))
return 0
return installResult{alreadyCurrent: true}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: The already-current path prints "Already current: ... and healthy." but returns installResult{alreadyCurrent: true} with healthy: false. Fine for the CLI (.exit is 0 either way), but a latent trap for the follow-up setup PR: a caller that branches on healthy before alreadyCurrent will report an already-running, healthy service as not healthy. Either set healthy: true here — the message asserts it — or spell out the precedence in the struct comment.

// applyClaudeCodeEnable records what the managed keys held, then writes the plan's
// values. Failing to record is a warning on stderr, as it always was: the write still
// happens, and disable then deletes the keys rather than restoring them.
func applyClaudeCodeEnable(pl claudeCodePlan, statePath string, stderr io.Writer) error {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: The plan carries the doc map read at plan time, and apply mutates and writes it. The old code had the same read-confirm-write window internally, so this is not a behavior change — but the split exports that window, and the setup PR will widen it (plan -> its own consent screen -> apply). Worth a comment here now, and possibly an mtime/size re-check in the follow-up PR, so apply doesn't silently clobber a settings.json the user or another tool edited in between.

}

// caCertNote is the note enable prints while ca.crt does not exist yet.
func caCertNote(caDir string) string {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: caCertNote/bundleNote/enablePreviewOf mirror the implementation's format strings rather than being independent golden literals, so the claude-code characterization is partially self-referential — a wording change made alongside a helper update would pass unnoticed. The service-side tests use hardcoded literals and are stronger. The "tests pass before the code moves" commit ordering is the real guarantee here; fine to keep, just noting the asymmetry.

// while the fake job is loaded, so newServiceSceneServing can follow it.
//
// The four stubs go through installStub, whose reachability check is load-bearing here:
// the label is the REAL io.rossoctl.cortex, so a test that fell through to the real

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: The fakeSupervisor stub uses the real io.rossoctl.cortex label, so if installStub ever fails to install its fake (PATH or permission problem), the test falls through to the real launchctl and boots out the Cortex running on the dev machine. Consider having installStub fail the test hard on any installation error.

@huang195
huang195 merged commit d22a9f7 into rossoctl:main Oct 2, 2026
27 checks passed
@huang195
huang195 deleted the refactor/agentop-install-seams branch October 2, 2026 02:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants