Repository navigation
Closed
Closed
Copy link
Labels
refactorRefactoring task
Description
Summary
The command packages print through raw fmt.Print*, bypassing cmd.OutOrStdout() and cmd.ErrOrStderr(). That is 388 non-test sites, plus 6 fmt.Fprint*(os.Stdout|os.Stderr) calls and one json.NewEncoder(os.Stdout). cmd/config/userspace_test.go:99 sets SetOut(io.Discard) and still gets printed over. Five commands (reset, insights, shortcuts, debug, daemon client) already use the Cobra writers, so the change is mechanical.
Around it sit:
- four kinds of boilerplate:
--formatflags, JSON emission, write-path resolution and mcp success notes - a double write in
config set --project - commands that report failure but exit 0
Acceptance Criteria
- Output routes through
fmt.Fprint*(cmd.OutOrStdout(), ...)andcmd.ErrOrStderr(), staged per package. Start with the read-only commands (stats, traces, conversations), each with a test that captures throughSetOut.- Don't use
cmd.Print*: Cobra sends it to stderr. - Helpers with no
cmd(ValidateTool,ExecTool, theoutput.Renderermethods) take anio.Writer.
- Don't use
-
cmd/output, which today only handles styling, gainsAddFormatFlag(cmd, def, allowed...)andPrintJSON(w, v). Together they collapse the 18 flag registrations (five help-text variants, defaults of text, yaml or json) and the 15MarshalIndentsites.tools execute --format json(tools.go:210) stays compact because the approval bridge reads it. Headless keeps its ownjson-pretty/ag-uivalues. -
infer status --format json|yamleither works or loses the flag. Today it prints the text block, thenOutput format: json(status.go:59-61). - One write-path resolver plus
AddProjectFlagreplaces the six copies: agents.go:315, mcp.go:153, runtime/config.go:373 and :384, runtime/state.go:149, skills.go:409.getMCPConfigPathsilently falls back to the project path when the home dir is missing. It becomes an error like its siblings.- Plugins keep their userspace-only rule.
- Skills keep theirs: project by default,
--userflips it, and./.inferis required.
-
config set --projectwrites once, with a plain if/else (getset.go:200-206). Today it writes the full default-seeded config, then the sparse override. If the second write fails, the project file keeps the full defaults and shadows the baseline. - Flag relationships are declared to Cobra:
MarkFlagsMutuallyExclusive("tag", "oci")on agents add/update replaces the hand-rolled check inresolveTagFlag(agents.go:356).MarkFlagsOneRequiredreplaces the update check (agents.go:231-236).- cmd/export/export.go:28 uses
cobra.ExactArgs(1)instead ofRangeArgs(0, 1)plus a manuallen(args)check. Theargs[0] == ""check stays. - The unreachable
len(args) == 0at cmd/tools/tools.go:137 is deleted, sinceMinimumNArgs(1)already guards it.
- agents add/update
--environmentbecomes aStringToStringflag, deleting both parsing loops (agents.go:160 and :253). The addlen > 0gate and the updateChangedgate stay. The two-loop merge at agents.go:189-196 becomesmaps.Copy. - mcp's seven success trailers (mcp.go:448-644) share one
saved(path)helper, with the restart note applied consistently (only 5 of 7 carry it today). The enable/disable server pair and the enable/disable global pair each collapse into one function taking a bool. - Dead and duplicate code:
- Delete
Config.GetGatewayURL/GetTimeout(config/config.go:1688,1692), which have zero callers. - Merge the byte-identical
sharedRuntime()in agents.go:745 and mcp.go:342 into one. - Fold
splitListValue(getset.go:323) intoruntime.parseDelimitedList, after confirming thatconfig set key ""behaves the same with a nil slice as with an empty one.
- Delete
-
infer tools validatereturns an error for a disallowed command and when tools are disabled (tools.go:93-96 and :105-109), soinfer tools validate "$x" && eval "$x"gating works. Thefix:commit calls out the exit-code change, which the generated CHANGELOG picks up.
Activity
edenreich commentedon Oct 30, 2026
@infer can you work on this? use /ponytail:ponytail /go or any other skills you may need.
inference-gateway-maintainer commentedon Oct 30, 2026
Model:
ollama_cloud/glm-5.3-flash· Action:v0.59.2· CLI:v0.238.0· Gateway:v0.60.1· View JobTodos
Pull Request
#1648
The agent hit its time limit before finishing, so it was stopped to salvage its work. Its committed changes were pushed; the draft pull request is linked above.
The environment is fully explicit and everything is pushed. One more high-value chunk to close the issue's stderr-site line: chat and migrate
os.Stderrwarnings. Reading both regions:Model:
ollama_cloud/glm-5.3-flash· Action:v0.59.2· CLI:v0.238.0· Gateway:v0.60.1· Exit Code:3· Duration: 35m 8sTokens: 50,648,609 in · 197,024 out · 50,845,633 total (193 requests)
Tool calls: 226 total · 100% success rate
Traces
Stats
Triggered by edenreich · Infer Action · OSS
refactor(cmd): route command output and config write paths onto share…