Skip to content
safran

Type to search. Enter opens the first result.

    Local directories

    The local code host makes directories on this machine available as repositories. Nothing is cloned and nothing is written: the working trees are read where they are. It needs no token and no network, which makes it the shortest way to try code search, and the right choice when the code is checked out by something else.

    Profile entry

    - id: disk
      type: local
      path: ./code

    Every immediate subdirectory of path is a repository:

    $ safran repos --profile /work/acme/safran.yaml
    repo          host  groups  teams  cloned  indexed
    ledger        disk  –       –      yes     not indexed
    payments-api  disk  –       –      yes     not indexed
    
    2 repos, 2 not indexed → safran sync --profile /work/acme/safran.yaml

    safran sync then indexes them in place. There is no fetch step for a local repository; a second run only looks at files whose content changed:

    $ safran sync --profile /work/acme/safran.yaml
    ledger  scanning files
    ledger  indexing 1/1 files  100%
    payments-api  scanning files
    payments-api  indexing 1/1 files  100%
       repo          status  changed  unchanged  chunks   time  detail
    ✔  ledger        ok            0          1       0  16 ms  no changes
    ✔  payments-api  ok            0          1       0   9 ms  no changes
    
    2 repos: 2 ok in 29 ms
    local-repos.ts
    import { createSafran } from "@safran/core";
    
    await using safran = await createSafran({ profile: "/work/acme/safran.yaml" });
    
    for (const repo of await safran.repos.list()) console.log(repo.name, repo.dir, repo.defaultBranch);
    
    await safran.repos.sync();
    const { hits } = await safran.code.search("partial refund");
    for (const hit of hits) console.log(hit.repo, hit.path, hit.startLine);

    Individual directories

    - id: disk
      type: local
      repos:
        - path: /work/acme/code/payments-api
        - name: ledger
          path: ../checkouts/ledger-main

    repos lists single directories; name defaults to the directory name. path and repos can be combined. When a directory is reached both ways, the explicit entry (and its name) wins.

    Path rules

    • A path is absolute, or relative to the directory of the profile file. ./code in /work/acme/safran.yaml is /work/acme/code, whatever directory the command is run from.

    • ~ is not expanded. A path that starts with ~ fails validation:

      $ safran profile check --profile /work/acme/safran.yaml
      ✘ The profile has 1 configuration problem:
        - code.hosts.0.path: `~` is not expanded; write an absolute path, or a path relative to the profile file
      → Fix these entries in the profile. `safran plugins` lists the available types and their fields.
    • A relative path in a profile that was not loaded from a file (a profile object passed to createSafran) has nothing to be resolved against. The instance is still built; the first use of the host fails with INVALID_INPUT. Use absolute paths there.

    Configuration reference

    FieldTypeDefaultRequiredMeaning
    idstringyesName of this entry; the host of its repositories.
    includestring[][]noGlob patterns on repository names. Empty means all.
    excludestring[][]noGlob patterns on repository names. Exclude wins over include.
    type"local"yesSelects this plugin.
    pathstringone of the twoA directory whose immediate subdirectories are repositories.
    reposobject[]one of the twoIndividual directories. At least one when present.
    repos[].namestringthe directory namenoShort name of the repository. Two entries may not share a name (compared case-insensitively).
    repos[].pathstringyesThe directory.

    At least one of path and repos must be set.

    How repositories are listed and named

    • Under path, only directories count; files are ignored, and so are directories whose name starts with a dot (.git, .cache). A symbolic link to a directory counts.
    • A directory does not have to be a git repository.
    • The same directory reached twice (through a link, or listed both ways) appears once.
    • The name is the explicit name, else the directory name. When two directories share a name, each becomes parent/name, and the absolute path if that still collides.
    • fullName and cloneUrl are the absolute path. ManagedRepo.dir is that same path: the source itself, not a copy.
    • defaultBranch is the branch currently checked out, read from the .git directory without running git (linked worktrees and submodules included). It is LOCAL_DETACHED_HEAD (HEAD) when a commit is checked out instead of a branch, and LOCAL_NO_BRANCH (-) for a directory that is not a git repository.

    Problems are logged as warnings, not thrown: when path cannot be read, no repositories are listed from it; an explicit repos entry that is not a directory is skipped. The CLI prints the warning:

    $ safran repos --profile /work/acme/safran.yaml
    No repos. Add a code host under `code.hosts:` in the profile.
    ! local: the directory cannot be read; no repositories listed from it (path=/work/acme/missing)

    include and exclude work as for every code host, on the short name and on fullName, which here is the absolute path:

    - id: disk
      type: local
      path: ./code
      exclude: ["*-archive", "tmp-*"]

    What a local host cannot do

    It has no capabilities: no pull-requests, no remote-head, no git credentials, no fileUrl.

    No pull requests means no work history. safran links refresh reads merged pull requests from code hosts, and a local directory has none. With only local hosts in the profile:

    $ safran links refresh --profile /work/acme/safran.yaml
    No repo to refresh: none of the code hosts lists pull requests.
    → Ticket ↔ code links come from merged pull requests on azure-repos, github or gitlab hosts.

    Naming a local repository explicitly reports it as failed with UNSUPPORTED. Everything that depends on the link store (past work for a ticket, discovery, the golden set for evaluation) needs one of the hosted code hosts.

    Other consequences of reading in place:

    • Safran never fetches, pulls or checks out anything in a local directory. What is indexed is what is on disk, including uncommitted changes. Keeping it current is up to you.
    • safran sync --fetch-only skips local repositories.
    • --data-dir holds the index, but no working trees for this host.

    Known caveats

    Nothing in this connector is marked UNVERIFIED; it talks to no service. Its limits are the ones above: no work history, no freshness guarantee, and warnings instead of errors for unreadable paths.

    See also