codeintel

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package codeintel provides a shell-out bridge to the TypeScript @renseiai/agentfactory-code-intelligence CLI (pnpm af-code).

Architectural choice: shell-out bridge (Phase D parity)

The tree-sitter Go bindings (go-tree-sitter) were evaluated but rejected for this phase because:

  1. CGo + native deps make CI slower and cross-compilation fragile.
  2. The AC requires byte-identical index format with TS readers — easiest to guarantee when TS owns the indexing entirely.
  3. Phase D goal is parity, not re-implementation.

This package shells out to `pnpm af-code` (resolving via PATH or DONMAI_CODE_BIN env var) and returns the parsed JSON output.

A future issue (post-Wave 4) can replace the shell-out with native Go tree-sitter after parity is verified end-to-end.

Binary resolution (PATH portability)

The binary is resolved in this order:

  1. DONMAI_CODE_BIN env var (legacy: AGENTFACTORY_CODE_BIN) — explicit override for non-monorepo users
  2. `af-code` on PATH (installed via `npm install -g @renseiai/agentfactory-cli`)
  3. `pnpm af-code` via pnpm run in the current working directory (monorepo dev)

If none of those resolve, every command returns an ErrNotAvailable error with clear installation instructions. The caller surfaces this gracefully rather than crashing.

Index

Constants

This section is empty.

Variables

View Source
var ErrArchNotAvailable = errors.New(
	"af-arch binary not found — install @renseiai/agentfactory-cli globally " +
		"(`npm install -g @renseiai/agentfactory-cli`) or set DONMAI_ARCH_BIN",
)

ErrArchNotAvailable is returned when the af-arch binary cannot be found.

View Source
var ErrNotAvailable = errors.New(
	"af-code binary not found — install @renseiai/agentfactory-cli globally " +
		"(`npm install -g @renseiai/agentfactory-cli`) or set DONMAI_CODE_BIN",
)

ErrNotAvailable is returned when the af-code binary cannot be found. Callers should surface this with instructions rather than treating it as a fatal error.

Functions

This section is empty.

Types

type ArchAssessOptions

type ArchAssessOptions struct {
	// PrURL is the full GitHub PR URL (e.g. https://github.com/org/repo/pull/123).
	// Takes precedence over Repository+PrNumber when both are provided.
	PrURL string

	// Repository is the repo identifier (e.g. github.com/org/repo).
	Repository string

	// PrNumber is the PR number within the repository.
	PrNumber int

	// GatePolicy overrides RENSEI_DRIFT_GATE: none | no-severity-high | zero-deviations | max:N
	GatePolicy string

	// ScopeLevel is the scope level for the baseline query.
	// Valid values: project | org | tenant | global
	ScopeLevel string

	// ProjectID is the project ID for scope.
	ProjectID string

	// DB is the SQLite DB path (overrides RENSEI_ARCH_DB).
	DB string

	// Summary outputs human-readable text instead of JSON.
	Summary bool
}

ArchAssessOptions holds the flags for af-arch assess.

type CheckDuplicateOptions

type CheckDuplicateOptions struct {
	Content     string
	ContentFile string
}

CheckDuplicateOptions holds the flags for check-duplicate.

type FindTypeUsagesOptions

type FindTypeUsagesOptions struct {
	TypeName   string
	MaxResults int
}

FindTypeUsagesOptions holds the flags for find-type-usages.

type GetRepoMapOptions

type GetRepoMapOptions struct {
	MaxFiles     int
	FilePatterns []string
}

GetRepoMapOptions holds the flags for get-repo-map.

type Runner

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

Runner wraps the af-code / af-arch CLI binaries and exposes each command as a typed Go function. All public methods return raw JSON-decoded output as map[string]any or []any, matching the TS CLI's JSON-to-stdout contract.

func New

func New(cwd string) *Runner

New creates a Runner that invokes commands relative to cwd. cwd should be the repository root (the directory where .agentfactory/ resides or will reside).

func (*Runner) ArchAssess

func (r *Runner) ArchAssess(opts ArchAssessOptions) (any, error)

ArchAssess runs `af-arch assess`. Exit code 1 from the subprocess means the gate was triggered — this is mapped to an ErrGateTriggered sentinel rather than a generic error so callers can handle it without parsing stderr.

func (*Runner) CheckDuplicate

func (r *Runner) CheckDuplicate(opts CheckDuplicateOptions) (any, error)

CheckDuplicate runs `af-code check-duplicate`.

func (*Runner) FindTypeUsages

func (r *Runner) FindTypeUsages(opts FindTypeUsagesOptions) (any, error)

FindTypeUsages runs `af-code find-type-usages <TypeName>`.

func (*Runner) GetRepoMap

func (r *Runner) GetRepoMap(opts GetRepoMapOptions) (any, error)

GetRepoMap runs `af-code get-repo-map`.

func (*Runner) IsArchAvailable

func (r *Runner) IsArchAvailable() bool

IsArchAvailable returns true if the af-arch binary can be found.

func (*Runner) IsCodeAvailable

func (r *Runner) IsCodeAvailable() bool

IsCodeAvailable returns true if the af-code binary can be found.

func (*Runner) SearchCode

func (r *Runner) SearchCode(opts SearchCodeOptions) (any, error)

SearchCode runs `af-code search-code <query>`.

func (*Runner) SearchSymbols

func (r *Runner) SearchSymbols(opts SearchSymbolsOptions) (any, error)

SearchSymbols runs `af-code search-symbols <query>`.

func (*Runner) ValidateCrossDeps

func (r *Runner) ValidateCrossDeps(opts ValidateCrossDepsOptions) (any, error)

ValidateCrossDeps runs `af-code validate-cross-deps [path]`.

type SearchCodeOptions

type SearchCodeOptions struct {
	Query      string
	MaxResults int
	Language   string
}

SearchCodeOptions holds the flags for search-code.

type SearchSymbolsOptions

type SearchSymbolsOptions struct {
	Query       string
	MaxResults  int
	Kinds       []string
	FilePattern string
}

SearchSymbolsOptions holds the flags for search-symbols.

type ValidateCrossDepsOptions

type ValidateCrossDepsOptions struct {
	Path string // Optional scoping path
}

ValidateCrossDepsOptions holds the flags for validate-cross-deps.

Jump to

Keyboard shortcuts

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