Repository navigation
Move the server-less subcommands from server to trajecta - #11
Merged
Merged
Conversation
`server` carried eleven command groups that never needed the proxy process. Move them to the `trajecta` CLI, so `server` is only about running the binary: `serve` (also the bare invocation), `version` and `completion`. Migrated to `trajecta`: analyze, audit, auth, config, db, doctor, migrate, models, provider, schema, tools. - `internal/cli` now holds the shared CLI contract (exit codes, JSON envelope, the viper-backed Runtime owning `-c/--config` and `--format`, the `Execute` top-level error path) together with the migrated command bodies. `cmd/server` imports the contract for its own three commands and registers none of the migrated ones; `cmd/trajecta` binds the same two flags and calls `cli.Register`. - `internal/appdb` collects the application-database entry points serve startup and the `db`/`auth` commands share (driver normalization, migration mode, MigrateUp/OptimizeIndexes, Open/Initialize, auth store opener). `NormalizeMCPPath`/`ValidateServe` moved to `internal/config` and the provider-probe target helpers to `internal/providerprobe`. - `trajecta` now reports failures through the shared contract: error envelopes go to stderr and internal failures exit 8. Commands that write an `ok: false` envelope and then return an error still emit exactly one JSON object per stream. - Tests split with the commands: serve-side tests stay in `cmd/server` (`serve_commands_test.go`), the app-db helper tests moved to `internal/appdb`, and the rest run against the shared runtime in `internal/cli`. - Taskfile, docs, README/README_EN and AGENTS describe the split; the `test:e2e` package list covers `./cmd/trajecta`. Verified end to end against SQLite: `trajecta db migrate up/status`, `config inspect`, `doctor`, `tools status`, `db secret status/export/rotate`, `auth init-user/create-token`, `models codex-config`, `provider probe`, `schema`, `audit query`, `analyze scan/reparse/repair-usage/refresh/ backfill-exchanges` and `migrate`, with a real `server` recording streaming and non-streaming chat completions plus a local-Responses request, and `trajecta audit query` reading back the rows that serve wrote.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
servercarried eleven command groups that never needed the proxy process. This moves them to thetrajectaCLI, soserveris only about running the binary.Stays in
server:serve(also the bareserver -c config.yamlinvocation),version,completion.Migrated to
trajecta:analyze,audit,auth,config,db,doctor,migrate,models,provider,schema,tools.A command that used to be
server db migrate statusis nowtrajecta db migrate statuswith the same subcommands, flags, exit codes and JSON shape.How
internal/clinow holds the shared CLI contract (exit-code table, JSON envelope, the viper-backedRuntimeowning-c/--configand--format, theExecutetop-level error path) together with the migrated command bodies, because the command bodies were already written against that contract.cmd/serverimports the contract for its own three commands and registers none of the migrated ones;cmd/trajectabinds the same two flags and callscli.Register.internal/appdbcollects the application-database entry points that serve startup and thedb/authcommands share — driver normalization, migration mode,MigrateUp/OptimizeIndexes,Open/Initializeand the auth store opener — so the startup path and the commands can no longer drift apart.NormalizeMCPPath/ValidateServemoved tointernal/config, the provider-probe target helpers tointernal/providerprobe.trajectanow reports failures through the shared contract. Error envelopes go to stderr (they used to go to stdout, which is what letstrajecta ... --format json > state.jsonstay parseable) and internal failures exit 8 instead of1. Commands that emit anok: falseenvelope and then return an error still write exactly one JSON object per stream.cmd/server(serve_commands_test.go), the app-db helper tests moved tointernal/appdb, and the rest run against the shared runtime ininternal/cli.Taskfile.ymlrunsmigrate,migrate:db:up,auth:init-userandauth:create-tokenthroughgo run ./cmd/trajecta, andtask test:e2ecovers./cmd/trajecta.README.md/README_EN.md,AGENTS.mdandCHANGELOG.mddescribe the split.Verification
task fmt,golangci-lint run ./...(0 issues),go vet ./...,go test -short ./...andtask test:e2eare green.End-to-end against SQLite with both binaries built from this branch:
server --helplists onlycompletion,serve,version;server db …exits 3 withunknown command "db" for "server".trajecta db migrate status/up --check-db,db migrate optimize-indexes,config inspect,doctor,tools status,db secret status/export/rotate,auth init-user,auth create-token,auth migrate status,models codex-config,provider probe,provider probe-report,schema,schema auth create-token,audit query,audit tool-calls,db summary rebuild sessions,analyze scan/reparse/repair-usage/refresh/backfill-exchangesandmigrateall succeed against a config the server owns.serverrecorded streaming and non-streaming/v1/chat/completionsround trips plus a/v1/responsesrequest through the local Responses runtime, andtrajecta audit query --response-id …read back the audit rows serve wrote.--format→ 3,db migrate down→ 3, failingdoctor→ 1.