kernel

package
v1.10.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 5, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WrapToolSpan

func WrapToolSpan[In, Out any](
	tracer trace.Tracer,
	toolName string,
	fn mcpsdk.ToolHandlerFor[In, Out],
) mcpsdk.ToolHandlerFor[In, Out]

WrapToolSpan wraps an MCP tool handler so every invocation creates a kernel.tool.{name} span as a child of whatever span is active on ctx. The helper is applied at RegisterTools time so per-handler bodies stay untouched.

Per D-07: NO attributes are set on kernel spans — tool_name / profile / mode / language / outcome are the TelemetryMiddleware's responsibility. The kernel sub-span name alone provides sufficient identification.

Usage:

mcpsdk.AddTool(server.SDK(), &mcpsdk.Tool{Name: "find_references"},
    WrapToolSpan(k.Tracer(), "find_references", findReferencesHandler))

Types

type Kernel

type Kernel struct {
	// contains filtered or unexported fields
}

Kernel coordinates workspaces, the LS worker pool, and tool dispatch. It is the central entry point for code intelligence operations.

func NewKernel

func NewKernel(registry *workspace.Registry, langReg *langregistry.Registry, installer *langregistry.Installer, cfg KernelConfig, pressure lspool.MemoryPressure, logger *slog.Logger, metrics lspool.MetricsSink, tracer trace.Tracer) *Kernel

NewKernel creates a new kernel with the given workspace registry, language registry, and configuration. The installer provides three-tier LS resolution (PATH/download/error). metrics is the lspool.MetricsSink receiving worker lifecycle events; pass lspool.NoopSink{} (or nil) to disable.

func (*Kernel) ActivateWorkspace

func (k *Kernel) ActivateWorkspace(ctx context.Context, rootPath string) (*WorkspaceRuntime, error)

ActivateWorkspace detects languages and creates a WorkspaceRuntime for a project root. Per WRK-02: auto-detects languages. Per WRK-03: supports multiple projects.

func (*Kernel) GetRuntime

func (k *Kernel) GetRuntime(wsKey workspace.WorkspaceKey) (*WorkspaceRuntime, error)

GetRuntime returns the workspace runtime for the given key.

func (*Kernel) HealthStatus

func (k *Kernel) HealthStatus() *lspool.HealthReport

HealthStatus returns a health report enriched with workspace language data. The pool snapshot is taken under a single RLock; workspace data is merged afterward without holding the pool lock.

func (*Kernel) Pool

func (k *Kernel) Pool() *lspool.Pool

Pool returns the LS worker pool (for direct access if needed).

func (*Kernel) Run

func (k *Kernel) Run(ctx context.Context) error

Run starts the LS worker pool and blocks until ctx is cancelled.

func (*Kernel) Shutdown

func (k *Kernel) Shutdown(ctx context.Context) error

Shutdown stops all workers and releases all resources.

func (*Kernel) Tracer

func (k *Kernel) Tracer() trace.Tracer

Tracer returns the kernel's trace.Tracer. Never nil — the constructor falls back to a noop tracer when none is provided.

type KernelConfig

type KernelConfig struct {
	Pool lspool.PoolConfig
}

KernelConfig holds configuration for the kernel.

type WorkspaceRuntime

type WorkspaceRuntime struct {
	// contains filtered or unexported fields
}

WorkspaceRuntime extends Phase 1 workspace with LS pool integration. Per D-01: daemon owns the pool, WorkspaceRuntime coordinates language detection and document version tracking.

func NewWorkspaceRuntime

func NewWorkspaceRuntime(key workspace.WorkspaceKey, pool *lspool.Pool, langReg *langregistry.Registry) *WorkspaceRuntime

NewWorkspaceRuntime creates a new workspace runtime for the given key.

func (*WorkspaceRuntime) AcquireSession

func (w *WorkspaceRuntime) AcquireSession(ctx context.Context, sessionID string, dirty bool) (*lspool.WorkerLease, error)

AcquireSession acquires a worker lease from the pool for this workspace. The language is determined from the workspace key, falling back to the first detected language if the key's Language field is empty.

func (*WorkspaceRuntime) DetectLanguages

func (w *WorkspaceRuntime) DetectLanguages(rootPath string) []string

DetectLanguages scans the root path for language marker files (per WRK-02). Detects: Go (go.mod), Python (pyproject.toml, setup.py), TypeScript/JavaScript (tsconfig.json, package.json, jsconfig.json), Rust (Cargo.toml), C++ (compile_commands.json, CMakeLists.txt), Swift (Package.swift), Zig (build.zig).

func (*WorkspaceRuntime) Key

Key returns the workspace key.

func (*WorkspaceRuntime) Languages

func (w *WorkspaceRuntime) Languages() []string

Languages returns the detected languages.

func (*WorkspaceRuntime) NextDocVersion

func (w *WorkspaceRuntime) NextDocVersion(uri string) int32

NextDocVersion returns the next monotonically increasing version for a document URI. Per Pitfall 5: workspace owns version counters, not sessions.

Directories

Path Synopsis
Package diag implements diagnostics tools: publishDiagnostics subscription, code action forwarding, and code formatting via LSP.
Package diag implements diagnostics tools: publishDiagnostics subscription, code action forwarding, and code formatting via LSP.
Package edit implements symbol editing tools: replace body, insert before/after, rename, safe delete, and post-edit diagnostic verification.
Package edit implements symbol editing tools: replace body, insert before/after, rename, safe delete, and post-edit diagnostic verification.
Package jsonrpc implements a thin JSON-RPC 2.0 codec for communicating with Language Server child processes over Content-Length framed stdio.
Package jsonrpc implements a thin JSON-RPC 2.0 codec for communicating with Language Server child processes over Content-Length framed stdio.
Package lspool manages Language Server child processes as warm workers with lifecycle management, share-until-dirty policy, and circuit breaking.
Package lspool manages Language Server child processes as warm workers with lifecycle management, share-until-dirty policy, and circuit breaking.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL