Documentation
¶
Overview ¶
Package daemon implements a long-lived krit process that keeps parse trees, the cross-file index, oracle state, and typeinfer caches resident in memory. CLI verbs in the build-integration cluster prefer the daemon when a socket is reachable and fall back to in-process execution otherwise.
The protocol is line-delimited JSON over a Unix socket. Each request is a single JSON object terminated by a newline; each response is a single JSON object terminated by a newline.
Index ¶
- Constants
- func Available(socketPath string) bool
- func Call(socketPath, verb string, args any, out any) error
- func DefaultSocketPath(root string) string
- type AbiHashArgs
- type AbiHashResult
- type AnalyzeBufferArgs
- type AnalyzeBufferEntry
- type AnalyzeBufferResult
- type AnalyzeBuffersArgs
- type AnalyzeBuffersResult
- type Handler
- type Request
- type Response
- type Server
- type StatusResult
Constants ¶
const ( VerbStatus = "status" VerbShutdown = "shutdown" VerbAbiHash = "abi-hash" VerbAnalyzeBuffer = "analyze-buffer" VerbAnalyzeBuffers = "analyze-buffers" )
Built-in verb names.
Variables ¶
This section is empty.
Functions ¶
func Available ¶
Available reports whether a daemon appears reachable at socketPath. It performs a short-timeout dial; absence is not an error from the caller's perspective, just "fall back to in-process".
func Call ¶
Call sends a single Request to the daemon at socketPath and decodes the Data field of the Response into out (which may be nil). It returns the daemon's error string as a Go error when OK=false.
func DefaultSocketPath ¶
DefaultSocketPath returns the conventional socket path for a project rooted at root (.krit/daemon.sock under the project root).
Types ¶
type AbiHashArgs ¶
type AbiHashArgs struct {
Target string `json:"target"`
}
AbiHashArgs is the argument shape for the abi-hash verb.
type AbiHashResult ¶
type AbiHashResult struct {
Target string `json:"target"`
Module string `json:"module,omitempty"`
File string `json:"file,omitempty"`
Hash string `json:"hash"`
Inputs int `json:"inputs"`
}
AbiHashResult is the response payload for the abi-hash verb.
type AnalyzeBufferArgs ¶
type AnalyzeBufferArgs struct {
// Path is the filesystem path the buffer represents. Used as the
// cache key and as the file label in findings. Empty paths default
// to "input.kt".
Path string `json:"path"`
// Content is the buffer body. UTF-8 Kotlin source.
Content string `json:"content"`
}
AnalyzeBufferArgs carries an in-memory file body for single-buffer per-file rule dispatch. The daemon parses the buffer (or reuses a cached parse when content is identical) and runs the same per-file rule pass the LSP / MCP single-file paths use.
type AnalyzeBufferEntry ¶
type AnalyzeBufferEntry struct {
Findings json.RawMessage `json:"findings,omitempty"`
CacheHit bool `json:"cache_hit"`
Error string `json:"error,omitempty"`
}
AnalyzeBufferEntry is one slot in AnalyzeBuffersResult.Results.
type AnalyzeBufferResult ¶
type AnalyzeBufferResult struct {
Findings json.RawMessage `json:"findings"`
CacheHit bool `json:"cache_hit"`
}
AnalyzeBufferResult carries the per-file findings for an analyze-buffer call. Findings is the canonical JSON form of scanner.FindingColumns so the wire shape matches `krit -f json` output. CacheHit is true when the daemon's WorkspaceState served this buffer from a prior parse.
type AnalyzeBuffersArgs ¶
type AnalyzeBuffersArgs struct {
Buffers []AnalyzeBufferArgs `json:"buffers"`
}
AnalyzeBuffersArgs is the batched form of AnalyzeBufferArgs. The daemon processes Buffers in order and returns one result per buffer. Clients with N staged files trade N dial+RTT cycles for one.
type AnalyzeBuffersResult ¶
type AnalyzeBuffersResult struct {
Results []AnalyzeBufferEntry `json:"results"`
}
AnalyzeBuffersResult mirrors AnalyzeBuffersArgs: one result per input buffer in matching order. A buffer-level error (e.g. parse failure) populates Error and leaves Findings empty for that entry, so the caller still gets dispositive results for the rest of the batch instead of one bad file failing the whole call.
type Handler ¶
Handler runs a single verb. It receives the raw JSON args and returns a JSON-marshalable result or an error. Handlers may be invoked concurrently; the verb implementation is responsible for any internal locking.
type Request ¶
type Request struct {
Verb string `json:"verb"`
Args json.RawMessage `json:"args,omitempty"`
}
Request names a verb and carries its arguments as opaque JSON.
type Response ¶
type Response struct {
OK bool `json:"ok"`
Error string `json:"error,omitempty"`
Data json.RawMessage `json:"data,omitempty"`
}
Response is the wire form of a verb result. OK=false carries an Error message and an empty Data; OK=true carries the verb-specific Data.
type Server ¶
type Server struct {
// Reporter, when non-nil, receives accept-loop warnings. Nil falls
// back to a default warnings-only stderr Reporter so library code
// never panics.
Reporter *diag.Reporter
// IdleTimeout, when > 0, makes the server self-stop after no
// requests have been seen for the given duration. Updated on every
// dispatch. Zero (the default) disables auto-shutdown.
IdleTimeout time.Duration
// contains filtered or unexported fields
}
Server is a long-lived process that accepts daemon Requests on a Unix socket and dispatches each to a registered Handler.
func NewServer ¶
NewServer returns a Server bound to socketPath. The socket file is created with mode 0600 when Start is called.
func (*Server) Register ¶
Register attaches a Handler for verb. Registering the same verb twice replaces the prior handler.
func (*Server) SocketPath ¶
SocketPath returns the configured socket path.
func (*Server) Start ¶
Start begins listening. It returns once the listener is ready (or an error if it could not bind). Connection accept and dispatch run in background goroutines until Stop is called or the listener errors.
type StatusResult ¶
type StatusResult struct {
Ready bool `json:"ready"`
Root string `json:"root"`
Modules int `json:"modules"`
Files int `json:"files"`
WarmSeconds float64 `json:"warm_seconds"`
// KritVersion is the daemon binary's compile-time version
// string (e.g. "v0.42.0", "dev").
KritVersion string `json:"krit_version,omitempty"`
// BinaryHash is the SHA-256 of the daemon's running krit
// binary. Clients with a different binary hash should restart
// the daemon to avoid stale-protocol-or-rule-set drift.
BinaryHash string `json:"binary_hash,omitempty"`
// HasLibraryFacts reports whether the daemon's WorkspaceState
// holds a cached *librarymodel.Facts. Useful for clients that
// want to confirm cross-file warm state is populated before
// running cross-file rules.
HasLibraryFacts bool `json:"has_library_facts,omitempty"`
// HasCodeIndex reports the same for *scanner.CodeIndex.
HasCodeIndex bool `json:"has_code_index,omitempty"`
}
StatusResult reports daemon readiness and basic warm-up stats.