Documentation
¶
Overview ¶
Daemon lifecycle: a per-project unix socket serving MCP over each accepted connection, with an idle reaper and auto-shutdown. Contract in docs/spec/code-intel-surfaces.md.
Client side of `atomic code mcp`: connect-or-start the singleton daemon under an flock, then pipe stdio to its socket. Daemon mode is the same `mcp` verb with --daemon, an unadvertised flag existing only for the auto-start path.
Package mcp serves the code-intelligence index as MCP tools.
Small repos get only explore/search/node; graph-traversal tools are withheld below tinyRepoThreshold, where a whole-repo read is cheaper than a traversal.
Index ¶
- Constants
- func ApplyCeiling(output string, ceiling int) string
- func DaemonArgv(sourceRoot, dbPath string, opts WatchOptions) []string
- func DefaultSpawn(sourceRoot, dbPath string, opts WatchOptions) error
- func EnsureRunning(ctx context.Context, sourceRoot, dbPath string, spawn SpawnFunc) error
- func GetExploreBudget(fileCount int) int
- func IsLive(socketPath string) bool
- func LockPath(projectRoot string) stringdeprecated
- func LockPathFromDB(dbPath string) string
- func NewRegistry(now func() time.Time) *registry
- func NewServer(eng *engine.Engine, fileCount int) *sdk.Server
- func RunAcceptLoop(ctx context.Context, ln net.Listener, srv *sdk.Server, sockPath string) error
- func RunDaemon(ctx context.Context, sourceRoot, dbPath string, now func() time.Time, ...) error
- func RunProxy(ctx context.Context, sourceRoot, dbPath string, opts WatchOptions, ...) error
- func RunStdio(ctx context.Context, projectRoot string) error
- func SocketPath(projectRoot string) stringdeprecated
- func SocketPathFromDB(dbPath string) string
- type Daemon
- type ExploreOutputBudget
- type SpawnFunc
- type SyncFunc
- type WatchOptions
Constants ¶
const ( ConnIdleTTL = 30 * time.Minute ServerIdleTTL = 30 * time.Minute ReapTick = 60 * time.Second // SyncInterval re-syncs the served graph against the working tree; 0 disables. SyncInterval = 10 * time.Second )
Exported so tests can assert the literal values.
Variables ¶
This section is empty.
Functions ¶
func ApplyCeiling ¶
ApplyCeiling truncates at the last section boundary in the back half, so the output ends on a whole section rather than mid-sentence. Exported for tests.
func DaemonArgv ¶
func DaemonArgv(sourceRoot, dbPath string, opts WatchOptions) []string
DaemonArgv spawns through the registered `code mcp` verb rather than a separate internal one, so the spawned command can never drift out of the Cobra tree. Exported so tests can assert the exact argv.
func DefaultSpawn ¶
func DefaultSpawn(sourceRoot, dbPath string, opts WatchOptions) error
DefaultSpawn starts the daemon detached with no stdio, so the parent can exit immediately. Explicit paths keep the daemon from re-resolving scope from cwd.
func EnsureRunning ¶
EnsureRunning starts the daemon if it is not already up, serialising concurrent starters behind an flock so a burst of clients spawns one daemon rather than a herd. Exported so tests can drive the auto-start path.
func GetExploreBudget ¶
GetExploreBudget returns how many explore calls a repo of this size allows.
func IsLive ¶
IsLive dials the socket; a leftover socket file with no daemon behind it gives ECONNREFUSED and so reads as not live.
func LockPathFromDB ¶
LockPathFromDB mirrors SocketPathFromDB with a .mcp.lock extension.
func NewRegistry ¶
func NewServer ¶
NewServer builds a transport-agnostic server whose registered tool set depends on fileCount. Call RunStdio, or srv.Connect for another transport.
func RunAcceptLoop ¶
RunAcceptLoop serves connections with no reaper and no idle shutdown, so an e2e test can drive a real socket session without the daemon lifecycle.
func RunDaemon ¶
func RunDaemon(ctx context.Context, sourceRoot, dbPath string, now func() time.Time, watchInterval time.Duration) error
RunDaemon binds the socket next to dbPath and serves until auto-shutdown.
Taking sourceRoot and dbPath explicitly is what makes the daemon cwd-independent: it consults neither the working directory nor the realm resolver, so it survives being spawned from a realm root or any non-git directory. Pass nil for now to use real time; watchInterval 0 disables sync.
func RunProxy ¶
func RunProxy(ctx context.Context, sourceRoot, dbPath string, opts WatchOptions, spawn SpawnFunc, stdin io.Reader, stdout io.Writer) error
RunProxy pipes stdio to the daemon's socket, which is derived from dbPath so proxy and daemon always agree on the path. On client disconnect the proxy exits but the daemon stays up, so the next invocation reuses a warm engine.
func SocketPath
deprecated
func SocketPathFromDB ¶
SocketPathFromDB places the socket beside the db rather than in the source tree, so a realm member's socket lands in the realm's .atomic directory instead of inside the checked-out repo.
Types ¶
type Daemon ¶
type Daemon struct {
// contains filtered or unexported fields
}
Daemon is the per-project unix-socket MCP singleton. Start it with RunDaemon; NewTestDaemon builds one with short, injectable durations.
func NewTestDaemon ¶
func NewTestDaemon(sockPath string, srv *sdk.Server, now func() time.Time, idleDuration, reapDuration, syncDuration time.Duration, syncFn SyncFunc) *Daemon
NewTestDaemon binds the listener before returning, so a caller can poll IsLive immediately instead of racing a goroutine that has yet to start. Nil now means real time; nil syncFn means a no-op.
func (*Daemon) RegistryCount ¶
RegistryCount is a test seam: polling IsLive instead would open a connection and so perturb the very idle-shutdown behaviour under test.
type ExploreOutputBudget ¶
type ExploreOutputBudget struct {
MaxOutputChars int
DefaultMaxFiles int
MaxCharsPerFile int
GapThreshold int
ExcludeLowValueFiles bool
}
ExploreOutputBudget caps one explore call's output. Every literal below is pinned by a table-driven test, including the invariant that MaxCharsPerFile never decreases as repos grow.
func GetExploreOutputBudget ¶
func GetExploreOutputBudget(fileCount int) ExploreOutputBudget
GetExploreOutputBudget returns the output budget for the given file count.
type SpawnFunc ¶
type SpawnFunc func(sourceRoot, dbPath string, opts WatchOptions) error
SpawnFunc starts the daemon when the socket is absent or dead. Production forks a detached subprocess; tests inject an in-process goroutine instead.
type SyncFunc ¶
SyncFunc is a field rather than a call to eng.Sync so tests can spy on it without standing up a real engine. RunDaemon wires it to eng.Sync.
type WatchOptions ¶
type WatchOptions struct {
// Disable turns the poller off entirely (--no-watch).
Disable bool
// Interval overrides SyncInterval when non-zero (--watch-interval).
Interval time.Duration
}
WatchOptions carries the sync-poller flags forwarded to the daemon on spawn.