JuliusBrussee/caveman · error

repository intelligence: cwd is not a directory

Error message

repository intelligence: cwd is not a directory

What it means

repointel.Build resolves the given cwd to an absolute path and stats it; if the stat fails or the target is not a directory, it returns this error instead of walking a nonexistent or non-directory root. The repository-intelligence index requires a real directory to enumerate files and package boundaries.

Solutions

  1. Verify the cwd exists and is a directory before calling Build: stat it and check IsDir().
  2. Fix the configured working directory in the proxy/agent configuration to the actual repository root.
  3. Recreate or remount the missing workspace directory if the project should exist.
  4. Check permissions on the path (and parents) so os.Stat succeeds.

Example fix

// before
m, _, err := repointel.Build(ctx, cfg.WorkDir)
// after
if info, err := os.Stat(cfg.WorkDir); err != nil || !info.IsDir() {
    return fmt.Errorf("workspace %q missing or not a directory", cfg.WorkDir)
}
m, _, err := repointel.Build(ctx, cfg.WorkDir)
Defensive patterns

Strategy: validation

Validate before calling

abs, err := filepath.Abs(cwd)
if err != nil { return err }
info, err := os.Stat(abs)
if err != nil || !info.IsDir() {
    return fmt.Errorf("cwd %q must be an existing directory", cwd)
}

Type guard

func isDirectory(p string) bool {
    info, err := os.Stat(p)
    return err == nil && info.IsDir()
}

Try / catch

m, b, err := repointel.Build(ctx, cwd)
if err != nil && strings.Contains(err.Error(), "cwd is not a directory") {
    return fmt.Errorf("check the configured working directory: %w", err)
}

Prevention

When it happens

Trigger: Build(ctx, cwd, ...) called with a path that does not exist, was deleted after being captured, points at a file (not a directory), or is inaccessible due to permissions making os.Stat fail.

Common situations: A proxy/config points at a stale cwd after a project was moved or deleted; passing a file path instead of the repo root; running in a container where the mounted workspace path differs; symlink to a removed target.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/4b70225b7b7898fa. Report an issue: GitHub.

Appendix: source

Thrown at proxy/internal/repointel/index.go:154

	ChangedPaths   []string `json:"changed_paths"`
	AffectedTests  []string `json:"affected_tests"`
	Basis          string   `json:"basis"`
	EvidenceStatus string   `json:"evidence_status"`
	Conservative   bool     `json:"conservative"`
}

func Build(ctx context.Context, root, repositoryState string, queryTerms []string) (Map, Bundle, error) {
	resolved, err := filepath.EvalSymlinks(root)
	if err != nil {
		return Map{}, Bundle{}, err
	}
	resolved, err = filepath.Abs(resolved)
	if err != nil {
		return Map{}, Bundle{}, err
	}
	info, err := os.Stat(resolved)
	if err != nil || !info.IsDir() {
		return Map{}, Bundle{}, errors.New("repository intelligence: cwd is not a directory")
	}
	files, truncated, listingBasis, err := listFiles(ctx, resolved)
	if err != nil {
		return Map{}, Bundle{}, err
	}
	packages := packageBoundaries(files)
	activity := gitActivity(ctx, resolved)
	mapped := make([]File, 0, len(files))
	for _, relative := range files {
		entry := File{
			Path: relative, Language: languageFor(relative), Package: nearestPackage(relative, packages),
			TestFor: testTarget(relative, files), RecentChanges: activity[relative], Convention: isConvention(relative),
		}
		if entry.Language != "" && !sensitivePath(relative) {
			path := filepath.Join(resolved, filepath.FromSlash(relative))
			if raw, readErr := os.ReadFile(path); readErr == nil && len(raw) <= maxFileBytes && !containsNUL(raw) {
				entry.Imports = scanImports(entry.Language, raw)
				entry.Symbols = scanSymbols(ctx, relative, entry.Language, raw)

View on GitHub (pinned to 3ee70a1026)