camber-helper/

directory
v0.0.0-...-2228978 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2026 License: Apache-2.0

README

Camber Helper

Camber Helper is a daemon process started by the desktop app to provide common functionality to Camber Assistant clients. This directory holds packages either implementing or relating to Helper. Helper client implementors should use this README, methods/, and the generated helper API bindings in ../../ui/packages/helperapi.

Communication between the desktop app and camber-helper happens over JSON-RPC and implements the base protocol defined by LSP. While some LSP features may be implemented, the methods supported by camber-helper are a superset of the LSP base protocol. We namespace our methods with camber/ to avoid collisions.

e.g.

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "camber/exampleMethod",
  "params": {
    "uri": "file:///Users/poolie/scratch"
  }
}

Some important details about LSP:

  • As per spec, LSP clients and servers have a 1:1 correspondence, and the client manages the server's lifecycle (see the LSP lifecycle spec). This is apparently unlikely to change.
  • Therefore, we currently assume a server has a singleton relationship with a client. If this changes, look at the stateful fields of the server to determine what needs to be updated.
  • Call(ctx) doesn't check for context cancellation: it will always be sent. Don't rely on context cancellation for JSON-RPC; use the abort mechanism.

Conversations

The helper runs ACP providers, dispatches conversation commands and persists a sequenced event log in the navigation database. Desktop and paired mobile use the v2 command and subscription API. The desktop CLI uses the same executor through the control dispatcher. See Helper-owned conversations for writer election, legacy adoption, store paths, cleanup and process tests.

Startup readiness diagnostics

initialize responds after configuration, navigation schema migration and agent configuration migration/seeding. Runtime-install repair already runs in the background. Do not defer migrations past this boundary or serve partially initialized stores.

Debug logs report helper startup phase with a phase, duration and success flag. Go execution traces also include helper.initialize.*, acpnav.open and acpnav.migrations regions. BenchmarkInitializeReady covers fresh and existing stores, including 10,000 conversations; BenchmarkOpenUpgrade checks migration from a populated older schema. The benchmarks use temporary configuration and databases and do not launch agents. Their in-process timings exclude process launch, host transport and the client's subsequent navigation reads.

Release

Desktop releases consume an immutable helper/vM.m.p runtime published in this fork. Publish and verify the helper assets before packaging the desktop app; see Releasing Camber for the build and release steps.

Fresh local binary installs resolve the highest published helper/v* version; set CAMBER_HELPER_VERSION=helper/vM.m.p to reproduce an exact one. Cached desktop binary installs remain offline-safe and can be explicitly refreshed. Local binary downloads use appleton/camber, including when working in a fork. Set CAMBER_HELPER_REPOSITORY=owner/repo to resolve and download a runtime from another repository. Desktop development can opt into a local helper build with CAMBER_DESKTOP_LOCAL_HELPER=1.

Adding methods

For LSP types, use the gopls types we have vendored. For JSONRPC methods not in LSP, add types to the methods/ package. Use huma godoc comments, as then the camber-helper openapi command will allow clients to auto-generate types for their language (although Helper is not an HTTP API, huma was a convenient library which we already use).

Then:

  1. Register the methods in internal/handler/handler.go.
  2. Find an existing sub-handler, such as internal/handler/git/ for Git methods, or create a new one for a new subsystem. See below for registration.
  3. Define the methods in a file named for the snake case of the method name, or method-name prefix if you have many (small) related methods.
  4. You can either unit-test in the package or define an integration test in internal/test/.

The generated TypeScript bindings live in the @camber/helperapi package. Regenerate them with pnpm -F @camber/helperapi codegen (or codegen:up to also start the helper's OpenAPI server). See the helperapi README.

RPC standards
  1. Use camber/ as the namespace for any non-standard JSON-RPC method: do not use the LSP namespaces, as this is confusing and may create conflicts with future methods.
  2. Try to match LSP naming style, e.g. using LSP suffixes for events (...DidChange) and keeping consistent prefixes between related methods.
  3. Use camelCase for JSON keys where possible. We have some cases where we've reused deeply nested API types that use snake_case, and it was low ROI to duplicate them.
  4. Use huma tags to declaratively validate the input.
  5. Remember that we have multiple extensions, so be considerate about communicating breaking changes early and widely.
Sub-handlers

To avoid all methods living in a single package, we define sub-handlers. These reside in internal/handler/$yourpkg, e.g. internal/handler/foo. By convention put your constructors in internal/handler/$yourpkg/handler.go. Then construct your handler and register methods in the main handler package.

New sets of handlers should go in a sub-package like this rather than the main handler package; keep handler.go itself to core JSON-RPC and server state.

If your handler cannot be constructed before initialize - for example requiring workspace folders - you can allocate an address for it in internal/handler/handler.go in newHandlerBaseState, and assign into the value in initialize:

package handler

// handler.go
type CamberHandler struct {
  *foo.FooHandler
}

func newHandlerBaseState(httpClient httpClientDo) *CamberHandler {
  // ...
  h := &CamberHandler{
    // ...
    // initialize pointer we can use for registration of method addresses,
    // and we'll assign into this address when constructing Handler
    FooHandler: new(foo.Handler),
  }
}

func New(/* ... */) {
  //...
  registerExtensionMethod(handler, JSONRPCOperation{
    Method:      "camber/fooDidChange",
  }, handler.FooHandler.DidChange)
}


// initialize.go
func (h *CamberHandler) setInitializeState(params *protocol.InitializeParams) error {
  // ...

  // assign the server value to our pre-allocated address, pointed
  // to by the various method handlers
  *h.FooHandler = *foo.NewHandler()
}

Standards and Conventions

These are internal standards and conventions for the helper codebase.

Error-handling

We handle runtime errors as follows:

  1. use pkgerrors.Wrap / Errorf / WithStack to wrap errors from non-helper code, or error constants, with stack traces
  2. don't use fmt.Errorf etc for defining non-constant errors, use pkgerrors.Errorf which includes the stack
  3. don't add messages in (1) unless you're adding information that cannot be got from the stack trace
  4. don't log errors you return. Rely on our logging of errors higher up the stack
  5. conversely, if you handle an error and it adds important information, do log it

This example indicates how to handle errors:

func someMethod(...) error {
  if err := thirdparty.Something(); err != nil {
    // if you have something useful to add beyond stack + original err, use Wrap:
    // return pkgerrors.Wrap("useful info", err)
    return pkgerrors.WithStack(err)
  }

  if err := helpercode.Something(); err != nil {
    // since we rely on all helper code following the "wrap third-party err" rule, we can confidently return err unchanged
    // when calling other helper code
    return err
  }

  if badThing() {
    // when we return constant errors, we should add a runtime stacktrace to aid debugging
    return pkgerrors.WithStack(ErrTheThing)
  }
}

Never use == or err.(SomeType) to compare or cast errors, use errors.Is and errors.As.

Use panic only for API misuse stemming from programming decisions, not runtime input or behavior. i.e. in the same way as the go stdlib: context.WithTimeout(nil, time.Second) will panic, but we do not panic for validation errors or a failure to read a file.

Ensure you do not use pkgerrors.New and friends for defining constant errors, use the standard errors library. Name errors ErrBadThing. Return such errors

// good example. When _returning_ this err constant, use pkgerrors.WithStack to capture the runtime stack
var ErrGoodExample = errors.New("the bad thing")

// don't do this - adds a useless/confusing stack trace at process init
var ErrBadExample = pkgerrors.New("the bad thing")

Together this will ensure that:

  1. all errors have informative stack traces
  2. we don't have to write boilerplate error messages at each level of the stack
  3. we aim to have a single log for each error, rather than noisy re-logging of the same error throughout the stack
Paths

A filepath is a path as per filepath's POSIX normalized FP, i.e. foo/bar never C:\foo\bar (aka "filepath.ToSlash"). Name variables with POSIX-normalized paths fooFP or fooFilepath. OS paths should be fooOS or fooFSPath.

In LSP, file identifiers are URIs. Generally we adopt this, as it makes it possible to support non-local editing in the future. If your code does not support non-file: URIs, return an error.

File locations

LSPs specify locations in files in UTF-16. Go strings are UTF-8. Generally, pass around file location as byte positions for complete clarity. When we modify files, we can then be certain we're applying them in the right place, independent of encoding (which may be neither of UTF-8 or UTF-16).

Handler

JSON-RPC handlers dispatched through internal/handler/ receive a non-nil request context in (*glsp.Context).Context.

Debugging and building locally

Use CAMBER_DESKTOP_LOCAL_HELPER=1 when starting desktop development to build the helper from the current checkout. See the desktop README for launch commands and diagnostics for log locations.

Native builds require the Xcode Command Line Tools and CGO_ENABLED=1.

Profiling

For debugging memory and CPU issues, pprof profiles are exposed on a 127.0.0.1 port. Check the Camber Helper output for the exact port — because multiple helpers can run at once, it varies.

DB forward-version compatibility

Helper-owned SQLite DBs (e.g. the acpnav conversation store) run their migrations through internal/dbmigrate, which wraps golang-migrate with a "forward-version tolerance" policy: when a DB records a migration version ahead of what this binary embeds (i.e. the user downgraded), the helper logs and proceeds instead of hard-failing at startup.

Forward-version tolerance assumes that an older binary can still use a schema created by a newer binary. The repository does not currently enforce that compatibility automatically, so review downgrade compatibility before adding a migration. For a breaking schema change, bump the DB filename instead — users get a fresh DB on upgrade and the old file stays on disk for manual downgrade.

Directories

Path Synopsis
gopls
pkg/protocol
Package protocol contains the structs that map directly to the request and response messages of the Language Server Protocol.
Package protocol contains the structs that map directly to the request and response messages of the Language Server Protocol.
pkg/protocol/semtok
The semtok package provides an encoder for LSP's semantic tokens.
The semtok package provides an encoder for LSP's semantic tokens.
internal
dbmigrate
Package dbmigrate wraps golang-migrate with a "forward-version tolerance" policy: if the DB records a migration version that is ahead of what this binary knows about, we log-and-proceed instead of hard-failing.
Package dbmigrate wraps golang-migrate with a "forward-version tolerance" policy: if the DB records a migration version that is ahead of what this binary knows about, we log-and-proceed instead of hard-failing.
gopls/gotoolsinternal/diff
Package diff computes differences between text files or strings.
Package diff computes differences between text files or strings.
gopls/gotoolsinternal/diff/difftest
Package difftest supplies a set of tests that will operate on any implementation of a diff algorithm as exposed by "github.com/appleton/camber/pkg/camber-helper/gopls/gotoolsinternal/diff"
Package difftest supplies a set of tests that will operate on any implementation of a diff algorithm as exposed by "github.com/appleton/camber/pkg/camber-helper/gopls/gotoolsinternal/diff"
gopls/gotoolsinternal/diff/lcs
package lcs contains code to find longest-common-subsequences (and diffs)
package lcs contains code to find longest-common-subsequences (and diffs)
gopls/gotoolsinternal/diff/myers
Package myers implements the Myers diff algorithm.
Package myers implements the Myers diff algorithm.
gopls/gotoolsinternal/event
Package event provides a set of packages that cover the main concepts of telemetry in an implementation agnostic way.
Package event provides a set of packages that cover the main concepts of telemetry in an implementation agnostic way.
gopls/gotoolsinternal/event/core
Package core provides support for event based telemetry.
Package core provides support for event based telemetry.
gopls/gotoolsinternal/event/export/eventtest
Package eventtest supports logging events to a test.
Package eventtest supports logging events to a test.
gopls/gotoolsinternal/event/export/metric
Package metric aggregates events into metrics that can be exported.
Package metric aggregates events into metrics that can be exported.
gopls/gotoolsinternal/event/export/ocagent
Package ocagent adds the ability to export all telemetry to an ocagent.
Package ocagent adds the ability to export all telemetry to an ocagent.
gopls/gotoolsinternal/goroot
Package goroot is a copy of package internal/goroot in the main GO repot.
Package goroot is a copy of package internal/goroot in the main GO repot.
gopls/gotoolsinternal/jsonrpc2
Package jsonrpc2 is a minimal implementation of the JSON RPC 2 spec.
Package jsonrpc2 is a minimal implementation of the JSON RPC 2 spec.
gopls/gotoolsinternal/jsonrpc2/servertest
Package servertest provides utilities for running tests against a remote LSP server.
Package servertest provides utilities for running tests against a remote LSP server.
gopls/gotoolsinternal/memoize
Package memoize defines a "promise" abstraction that enables memoization of the result of calling an expensive but idempotent function.
Package memoize defines a "promise" abstraction that enables memoization of the result of calling an expensive but idempotent function.
gopls/gotoolsinternal/proxydir
Package proxydir provides functions for writing module data to a directory in proxy format, so that it can be used as a module proxy by setting GOPROXY="file://<dir>".
Package proxydir provides functions for writing module data to a directory in proxy format, so that it can be used as a module proxy by setting GOPROXY="file://<dir>".
gopls/gotoolsinternal/robustio
Package robustio wraps I/O functions that are prone to failure on Windows, transparently retrying errors up to an arbitrary timeout.
Package robustio wraps I/O functions that are prone to failure on Windows, transparently retrying errors up to an arbitrary timeout.
gopls/gotoolsinternal/stack
Package stack provides support for parsing standard goroutine stack traces.
Package stack provides support for parsing standard goroutine stack traces.
gopls/gotoolsinternal/stack/gostacks command
The gostacks command processes stdin looking for things that look like stack traces and simplifying them to make the log more readable.
The gostacks command processes stdin looking for things that look like stack traces and simplifying them to make the log more readable.
gopls/gotoolsinternal/testenv
Package testenv contains helper functions for skipping tests based on which tools are present in the environment.
Package testenv contains helper functions for skipping tests based on which tools are present in the environment.
gopls/gotoolsinternal/xcontext
Package xcontext is a package to offer the extra functionality we need from contexts that is not available from the standard context package.
Package xcontext is a package to offer the extra functionality we need from contexts that is not available from the standard context package.
gopls/pkg/file
The file package defines types used for working with LSP files.
The file package defines types used for working with LSP files.
gopls/pkg/label
Package label provides common labels used to annotate gopls log messages and events.
Package label provides common labels used to annotate gopls log messages and events.
gopls/pkg/test/integration/fake
Package fake provides a fake implementation of an LSP-enabled text editor, its LSP client plugin, and a Sandbox environment for use in integration tests.
Package fake provides a fake implementation of an LSP-enabled text editor, its LSP client plugin, and a Sandbox environment for use in integration tests.
gopls/pkg/test/integration/fake/glob
Package glob implements an LSP-compliant glob pattern matcher for testing.
Package glob implements an LSP-compliant glob pattern matcher for testing.
gopls/pkg/util/browser
Package browser provides utilities for interacting with users' browsers.
Package browser provides utilities for interacting with users' browsers.
gopls/pkg/util/bug
Package bug provides utilities for reporting internal bugs, and being notified when they occur.
Package bug provides utilities for reporting internal bugs, and being notified when they occur.
gopls/pkg/util/constraints
Package constraints defines a set of useful constraints to be used with type parameters.
Package constraints defines a set of useful constraints to be used with type parameters.
gopls/pkg/util/frob
Package frob is a fast restricted object encoder/decoder in the spirit of encoding/gob.
Package frob is a fast restricted object encoder/decoder in the spirit of encoding/gob.
gopls/pkg/util/goversion
Package goversions defines gopls's policy for which versions of Go it supports.
Package goversions defines gopls's policy for which versions of Go it supports.
gopls/pkg/util/immutable
The immutable package defines immutable wrappers around common data structures.
The immutable package defines immutable wrappers around common data structures.
gopls/pkg/util/persistent
The persistent package defines various persistent data structures; that is, data structures that can be efficiently copied and modified in sublinear time.
The persistent package defines various persistent data structures; that is, data structures that can be efficiently copied and modified in sublinear time.
gopls/release command
handler/appcontrol
Package appcontrol holds the desktop's conversation-management operations that do not need UI state, so the desktop UI (through camber/app/* helper methods) and the camber control CLI (through control actions) run the same code.
Package appcontrol holds the desktop's conversation-management operations that do not need UI state, so the desktop UI (through camber/app/* helper methods) and the camber control CLI (through control actions) run the same code.
handler/approvals
Package approvals owns pending agent approvals (permission prompts and elicitations) as helper-side state.
Package approvals owns pending agent approvals (permission prompts and elicitations) as helper-side state.
handler/control
Package control exposes desktop conversation orchestration to local clients.
Package control exposes desktop conversation orchestration to local clients.
handler/git
Package git exposes camber/git/* JSON-RPC methods backing the desktop changes view: working-tree status, per-file diffs, staging, discarding, and committing.
Package git exposes camber/git/* JSON-RPC methods backing the desktop changes view: working-tree status, per-file diffs, staging, discarding, and committing.
handler/github
Package github exposes camber/github/* JSON-RPC methods that surface pull-request status for worktrees.
Package github exposes camber/github/* JSON-RPC methods that surface pull-request status for worktrees.
handler/ownedwriter
Package ownedwriter elects the sidecar allowed to dispatch and recover owned commands for a physical navigation database.
Package ownedwriter elects the sidecar allowed to dispatch and recover owned commands for a physical navigation database.
handler/remoteaccess
Package remoteaccess serves the mobile remote-control surface: an authenticated HTTP + WebSocket endpoint that speaks the same JSON-RPC protocol as the primary stdio client, minus a small method deny list (see denylist.go).
Package remoteaccess serves the mobile remote-control surface: an authenticated HTTP + WebSocket endpoint that speaks the same JSON-RPC protocol as the primary stdio client, minus a small method deny list (see denylist.go).
handler/remoteaccess/webui
Package webui embeds the built mobile-remote UI bundle so camber-helper can serve it directly (a phone has no dev server to proxy through).
Package webui embeds the built mobile-remote UI bundle so camber-helper can serve it directly (a phone has no dev server to proxy through).
handler/remoteterminal
Package remoteterminal owns the PTYs the helper spawns on behalf of remote (mobile) clients: a plain shell (or a one-shot setup/teardown command) per worktree, with output retained for reconnect backfill.
Package remoteterminal owns the PTYs the helper spawns on behalf of remote (mobile) clients: a plain shell (or a one-shot setup/teardown command) per worktree, with output retained for reconnect backfill.
handler/workspacefiles
Package workspacefiles implements the workspace RPCs for one authenticated paired socket.
Package workspacefiles implements the workspace RPCs for one authenticated paired socket.
mcp
mcp/oauthex
Package oauthex is a vendored package coming from go-mcp sdk but without the experimental build tag.
Package oauthex is a vendored package coming from go-mcp sdk but without the experimental build tag.
shellenv
Package shellenv recovers the environment a user's login shell would provide.
Package shellenv recovers the environment a user's login shell would provide.
Package methods defines types for JSONRPC extension methods.
Package methods defines types for JSONRPC extension methods.

Jump to

Keyboard shortcuts

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