Discovery explained
safran discover turns a seed profile (connectors only) into a draft profile with tracker projects, repo groups, teams, glossary candidates, conventions and languages filled in. This page explains what it reads, how every proposal is computed, which numbers decide it, and how to read the result. Discovery is counting and heuristics, not a language model: it needs history to say anything, and everything it writes is a draft that a person must review.
A complete run
The seed profile below has a tracker, a code host and an embedder, and nothing else. safran sync has run once, so the repositories are cloned and indexed (discovery works without that, with less to go on: see what it reads).
$ safran discover --profile /work/acme/safran.yaml
Safran discovery — draft for review (statistics and heuristics, no language model)
6 repos (6 cloned), 69 merged PRs read, 65 used, 63 with a ticket (3% without), 63 ticket titles
sampled.
Ignored PRs: 2 by bots, 1 merge/revert, 1 mass changes.
Legend: + added to the draft, · observation only; [high] [med ] [low ] = confidence.
Coverage (2)
· [high] pull requests ignored as noise
4 of 69 merged PRs were ignored: 2 by bot accounts, 1 merge/revert PRs, 1 mass changes, 0
naming many tickets at once, 0 repeats of the same change to another branch.
· [high] ticket references in merged PRs
3% of merged PRs (2 of 65) reference no ticket — the team mapping is based on the other
63.
Tracker projects (1)
+ [med ] tracker jira
Tracker "jira" lists 3 projects; all were added. Merged pull requests reference 3 of them
(PRs per project: PAY 34, WEB 20, MOB 9). Remove the ones no team here works on.
Repo groups (6)
+ [high] acme-android → mobile
build.gradle.kts + AndroidManifest.xml; name contains "android".
+ [high] acme-ios → mobile
podfile; name contains "ios".
+ [high] admin-panel → frontend
package.json depends on react; name contains "panel".
+ [med ] ledger → backend
go.mod.
+ [high] payments-api → backend
package.json depends on fastify; name contains "api".
+ [high] web-app → frontend
package.json depends on react; name contains "web".
Teams (6)
+ [low ] Mobile ↔ acme-android
Mobile ↔ acme-android: 4 of 4 ticket-linked PRs in this repo reference MOB tickets
(recency-weighted share 100%).
+ [low ] Mobile ↔ acme-ios
Mobile ↔ acme-ios: 5 of 5 ticket-linked PRs in this repo reference MOB tickets
(recency-weighted share 100%).
+ [med ] Payments ↔ ledger
Payments ↔ ledger: 9 of 9 ticket-linked PRs in this repo reference PAY tickets
(recency-weighted share 100%).
+ [high] Payments ↔ payments-api
Payments ↔ payments-api: 24 of 24 ticket-linked PRs in this repo reference PAY tickets
(recency-weighted share 100%).
+ [med ] Web ↔ admin-panel
Web ↔ admin-panel: 8 of 9 ticket-linked PRs in this repo reference WEB tickets
(recency-weighted share 91%).
+ [med ] Web ↔ web-app
Web ↔ web-app: 12 of 12 ticket-linked PRs in this repo reference WEB tickets
(recency-weighted share 100%).
Glossary candidates (9)
+ [med ] iade → refund
"iade" appears in 8 sampled ticket titles; "refund" is in the changed paths of 8 of their
8 PRs, against 0 of 16 other PRs in the same repos. The term was not found in the code
index. Co-occurrence, not translation: confirm before trusting it.
+ [low ] sepet → basket
"sepet" appears in 5 sampled ticket titles; "basket" is in the changed paths of 5 of
their 5 PRs, against 0 of 7 other PRs in the same repos. The term was not found in the
code index. Co-occurrence, not translation: confirm before trusting it.
+ [low ] kapanı → close
"kapanı" appears in 5 sampled ticket titles; "close" is in the changed paths of 3 of
their 5 PRs, against 0 of 41 other PRs in the same repos. The term was not found in the
code index. Co-occurrence, not translation: confirm before trusting it.
+ [low ] fatura → invoice
"fatura" appears in 4 sampled ticket titles; "invoice" is in the changed paths of 4 of
their 4 PRs, against 0 of 20 other PRs in the same repos. The term was not found in the
code index. Co-occurrence, not translation: confirm before trusting it.
+ [low ] bildirim → push
"bildirim" appears in 4 sampled ticket titles; "push" is in the changed paths of 3 of
their 4 PRs, against 0 of 29 other PRs in the same repos. The term was not found in the
code index. Co-occurrence, not translation: confirm before trusting it.
+ [low ] arama → search
"arama" appears in 3 sampled ticket titles; "search" is in the changed paths of 3 of
their 3 PRs, against 0 of 18 other PRs in the same repos. The term was not found in the
code index. Co-occurrence, not translation: confirm before trusting it.
+ [low ] bakiye → balance
"bakiye" appears in 3 sampled ticket titles; "balance" is in the changed paths of 3 of
their 3 PRs, against 0 of 30 other PRs in the same repos. The term was not found in the
code index. Co-occurrence, not translation: confirm before trusting it.
+ [low ] mutabakat → settlement
"mutabakat" appears in 3 sampled ticket titles; "settlement" is in the changed paths of 3
of their 3 PRs, against 0 of 30 other PRs in the same repos. The term was not found in
the code index. Co-occurrence, not translation: confirm before trusting it.
· [low ] glossary candidates
17 recurring terms in 63 sampled ticket titles: 0 already appear in code or changed
paths, 0 have too few focused PRs to compare, 8 have no path word that stands out, 1
point at a code word a commoner term already took; 8 proposed. Single words only; expect
misses and some wrong pairs.
Conventions (4)
+ [high] ticket title language
63 of 63 sampled ticket titles look Turkish, 0 English, 0 another language, 0 undecided
(100% of the classified ones). Language detection is a heuristic (Turkish-only letters
and small word lists for tr/en).
+ [med ] pull request title language
1 of 65 pull request titles look Turkish, 44 English, 0 another language, 20 undecided
(98% of the classified ones). Language detection is a heuristic (Turkish-only letters and
small word lists for tr/en).
+ [high] branch naming
63 of 65 source branches (97%) have the shape type/key.
+ [high] pull request titles
63 of 65 PR titles (97%) have the shape "key: text".
Languages (1)
+ [high] languages.tickets = tr
63 of 63 sampled ticket titles look Turkish, 0 English, 0 another language, 0 undecided
(100% of the classified ones). Language detection is a heuristic (Turkish-only letters
and small word lists for tr/en). `languages.code` is set to "en" by default; it was not
measured.
Added to the draft: 3 project key(s), 6 grouped repo(s), 3 team(s), 0 repo(s) on existing teams, 8
glossary candidate(s), 4 convention(s), languages.
Findings by confidence: 12 high, 7 medium, 10 low.
✔ Wrote the draft to /work/acme/safran.draft.yaml
→ It is a draft, not your profile. Review it (start with the items marked low),
then rename it over /work/acme/safran.yaml and run `safran profile check --profile /work/acme/safran.yaml`.This is real output of the CLI, run against an in-memory tracker and code host that carry a small fictional acme history (63 finished tickets with Turkish titles, 69 merged pull requests). Progress lines, which go to stderr, are left out. Two things in it are worth a second look before reading on:
kapanı → closeis a wrong pair. The titles behind it mix "kapanıyor" (an app that shuts down, a session that ends) with "kapanış" (the month-end close of the ledger); three of those five pull requests happen to touchclosepaths. Nothing in the statistics can tell that apart from a real term. This is whatlowis for.iade → refundismedium, nothigh. No glossary candidate is everhigh.
What discovery reads
Discovery works through one Safran instance built from your seed profile, so it sees exactly what your tokens can see. All of its reading happens in five places:
| Source | What is read | Used for |
|---|---|---|
| Code hosts | The repository list (repos.list) | Groups; the repos merged pull requests are read for |
| Cloned repos on disk | Names of the entries in the repository root (the first 400, DEFAULT_MAX_ROOT_ENTRIES), whether an Android manifest exists at app/src/main/AndroidManifest.xml or src/main/AndroidManifest.xml, and the dependencies names of a root package.json | Groups |
| Trackers | The project list of every tracker entry (listProjects) | Tracker projects, team names, finding ticket keys in pull requests |
| Link store | Merged pull requests of the window: title, source branch, description, author, merge date, linked ticket keys, changed file paths. Refreshed from the code hosts first unless you pass --no-refresh | Teams, glossary, conventions |
| Trackers, again | Titles of up to 200 tickets (DEFAULT_SAMPLE_TICKETS) that those pull requests reference, four requests at a time (DEFAULT_TICKET_CONCURRENCY) | Ticket language, glossary |
It also asks the code index whether a glossary candidate already occurs in code (one exact search per candidate). No file content is read beyond the root package.json, and no source text is sent anywhere by discovery itself.
Details that change what you get:
- The window. Pull requests merged in the last 12 months (
DEFAULT_LOOKBACK_MONTHS) are used, or since--since. Without--sincethe refresh itself resumes where the link store stopped (see links); with--sinceit reads back to that date. At most 50,000 stored records are read (DEFAULT_MAX_RECORDS). - Ticket keys are looked for again. A seed profile has no project keys yet, so the link store only holds the links the code host itself reports. Discovery takes the project keys from the trackers' listings and searches each pull request's title and source branch for them; the description is searched only when title and branch name no ticket, because descriptions mention other people's tickets. Tokens that only look like keys (
UTF-8,SHA-256,ISO-8601and the rest ofDEFAULT_KEY_LOOKALIKES) are never counted. This is done only for trackers whose keys have thePROJECT-123shape. - The ticket sample is spread over repos. The newest unseen key of each repo is taken in turn, so one busy repo does not fill the 200. If the first 10 reads all fail (
DEFAULT_TICKET_FAILURE_LIMIT, typically a rejected token), sampling stops and a problem is reported. - Not cloned is not fatal. A repo that has not been synced is grouped from its name and primary language only, and its finding says "Not cloned, so manifests were not read." An empty code index means glossary candidates are not checked against code and all stay
low. Runsafran syncbeforesafran discoverwhen you can. - Archived repos are left out of the groups and listed in one finding.
A failing step does not fail the run. A tracker that cannot list projects, a repo whose pull requests cannot be read, tickets that cannot be fetched: each becomes a finding under Problems and the rest goes on. Only cancellation and invalid options stop the command.
Pull requests that are dropped
Before anything is counted, pull requests that would mislead the statistics are removed, in this order:
| Dropped | Rule | Counted as |
|---|---|---|
| Bot authors | The author's name, id or e-mail contains [bot] or the word bot, starts with dependabot, renovate, greenkeeper, snyk, mergify, github-actions or semantic-release, or contains build service. The SDK option botAuthors adds exact names. | bot |
| Merge and revert titles | The title starts with revert, reverts, merge, merged, backmerge or back-merge | noiseTitle |
| Mass changes | More than 50 changed files (DEFAULT_MASS_CHANGE_FILES) | massChange |
| Many-ticket pull requests | More than 5 ticket keys (DEFAULT_MAX_TICKETS_PER_PULL): a release or branch merge, not work for one team | manyTickets |
| Repeats | Same repo, same title and same tickets as a newer pull request (one change opened to several target branches) | duplicate |
The counts are in the summary line (Ignored PRs: …), in the first coverage finding and in stats.dropped.
What is inferred, and how
Six steps run over the same filtered pull requests. Each one is a pure function you can also call on its own (they are listed in the @safran/discover reference).
Tracker projects
A tracker entry that already lists projects is left alone. For the others, the tracker's own listing decides:
- Up to 25 projects (
DEFAULT_MAX_PROJECTS_PER_TRACKER): all are added, most-referenced first. The finding says how many merged pull requests reference each, so you can remove the ones nobody here works on. - More than 25: only projects that at least 2 pull requests reference (
DEFAULT_MIN_PROJECT_REFERENCES) are added, up to 25, and the finding counts the rest. A tracker lists every project its token can see; that is not a profile. - A project key that another tracker in the profile already owns is not added a second time: a key must map to one tracker (see multiple sources).
Confidence: low when no pull request references any added project, high when every added project has at least 20 references (DEFAULT_PROJECT_HIGH_REFERENCES), otherwise medium.
Repo groups
Every repo that is not already in a group gets one of backend, frontend, mobile, infra, libraries or other. Three kinds of signal vote, and the heaviest group wins:
| Signal | Weight | Examples |
|---|---|---|
| Manifest in the repo root (cloned repos only) | 3 | Podfile or an Xcode project → mobile; Gradle with an Android manifest → mobile, without → backend; go.mod, pom.xml, *.csproj, Cargo.toml, pyproject.toml → backend; a package.json depending on react, vue, next → frontend, on express, fastify, @nestjs/core → backend, on react-native, expo → mobile; Terraform or Helm files with no application manifest → infra |
A word of the repo name (the last matching word counts: admin-api is an API) | 2 | api, service, worker → backend; web, admin, panel, portal → frontend; ios, android, mobile → mobile; infra, terraform, helm, deploy → infra; lib, sdk, common, shared → libraries |
| Primary language reported by the code host | 1 | Swift, Kotlin, Dart → mobile; C#, Java, Go, Python → backend; Vue, Svelte, CSS → frontend; HCL, Shell → infra |
Confidence here means agreement, not weight: high needs a manifest plus one other kind with nothing pointing elsewhere; a manifest alone, or name and language together, is medium; a single name or language signal, a tie, or any signal pointing at another group is low. A repo with no signal goes to other at low.
Discovery never edits a group you wrote. A repo that looks like backend when your profile already defines backend is reported, not added. With more than 60 repos to classify (DEFAULT_MAX_GROUP_FINDINGS) the findings are summarised per group and confidence instead of one per repo.
Teams and repo ownership
A team is inferred as "the people who work on one tracker project", and ownership as "the project most of a repo's ticket-linked pull requests reference".
- Every used pull request with at least one ticket of a known project counts as one link for its repo. Its weight halves for every 180 days of age (
DEFAULT_RECENCY_HALF_LIFE_DAYS), measured from the newest pull request in the data, not from today, so the same data always gives the same answer. A pull request naming tickets of two projects counts for both and splits its weight between them. - A project's share in a repo is its weight divided by the repo's total weight.
- A project owns the repo when it has at least 3 links there (
DEFAULT_MIN_LINKS) and a share of at least 60% (DEFAULT_OWNER_SHARE). - Otherwise, up to 2 projects (
DEFAULT_MAX_CO_OWNERS) with at least 3 links and a 30% share each (DEFAULT_SHARED_SHARE) become co-owners: the repo is listed under each team, always atlow. - A repo spread thinner than that gets a "shared repository" finding and is not assigned. A repo where no project reaches 3 links is listed under "repos with too little history" and not assigned.
Confidence of an owned repo:
| Confidence | Condition |
|---|---|
high | At least 20 links (DEFAULT_HIGH_MIN_LINKS) and a share of at least 80% (DEFAULT_HIGH_SHARE) |
medium | At least 8 links (DEFAULT_MEDIUM_MIN_LINKS) |
low | Everything else; also when the project with the most links over the whole period is not the recency-weighted leader ("ownership seems to have moved recently"), and when the tracker project is the repository itself (issues kept in the code host: the repo's own issues closed by its own pull requests say nothing about who the team is) |
What ends up in the draft depends on what the seed already says:
- No teams in the profile. One team per project that owns or co-owns a repo, named after the project's display name in the tracker (
PaymentsforPAY). The team'sconfidenceis the lowest of its repos, so one guessed repo marks the whole entry for review, andsourcecarries the link count (33 ticket-PR links across 2 repos). - Teams in the profile. No team is invented. A repo is appended to the one team that lists the project. A repo you already gave to a team is never moved or shared out; when history disagrees with the profile, the finding says so and the profile stays as written. A project that no team lists gets a "project PAY has no team" finding.
Glossary candidates
This step looks for business words of ticket titles that the code does not use, and for the path word their pull requests keep touching. It runs only when the ticket language differs from the code language; with both en it reports that there is nothing to map.
- Terms. Titles are lower-cased with the ticket language's casing rules (so
İadeandiadeare one word), ticket keys are removed, and words shorter than 4 letters or in the stop lists are dropped. Inflected forms are grouped without a stemmer: a word joins the shortest shorter word that is its prefix (iadeler,iadenin→iade; the stem has at least 4 letters and the suffix at most 6), and words without one are grouped on a shared prefix of 5 letters or more. - Frequency. A term must occur in at least 3 sampled tickets (
DEFAULT_GLOSSARY_MIN_TICKETS) and, once the sample has 10 tickets, in no more than 40% of them (DEFAULT_GLOSSARY_MAX_TICKET_SHARE). - Already in code. A term that is the start of a word in any changed path, or that the code index finds (case-insensitive exact search for the term, its stem and its folded form), is dropped: the code already speaks that word.
- Focused pull requests. Only pull requests of sampled tickets that change at most 20 files (
DEFAULT_GLOSSARY_MAX_FILES) are used. The term needs at least 3 of them (DEFAULT_GLOSSARY_MIN_SUPPORT). - Comparison inside each repo. The term's pull requests are compared with the other focused pull requests of the same repo, never across repos; a repo with fewer than 3 others (
DEFAULT_GLOSSARY_MIN_CONTRAST) is left out. - Path words. Changed paths are split into words (generic ones such as
srcortestare ignored). A word is suggested when at least 3 and at least half of the term's pull requests touch it, and its share there exceeds its share in the comparison set by at least 0.4 (DEFAULT_GLOSSARY_MIN_LIFT). At most 3 code words per term (DEFAULT_GLOSSARY_MAX_CODE_WORDS). - One term per code word. When two terms point at the same first code word (words that travel together, like "kısmi" and "iade"), the more frequent one is kept. At most 20 candidates are proposed (
DEFAULT_GLOSSARY_MAX_TERMS).
A candidate is medium only when it was checked against the code index and not found there, at least 8 of its pull requests touch the code word, the lift is at least 0.6 and the term occurs in at least 5 tickets. Everything else is low. The last glossary finding (· [low ] glossary candidates) is the tally: how many recurring terms there were and why the others were not proposed.
Each candidate is written with a note that starts with discovered and carries the evidence, so it stays recognisable after you merge the draft. How the glossary is then used at search time is on the glossary page; the Turkish case end to end is in non-English tickets.
Conventions
A sentence is proposed only for a habit that at least 70% of the samples follow (DEFAULT_CONVENTION_MAJORITY), from at least 10 samples (DEFAULT_CONVENTION_MIN_SAMPLES):
| Convention | Sample | Shapes recognised |
|---|---|---|
| Ticket title language | Sampled ticket titles | Turkish or English |
| Pull request title language | Titles of the used pull requests | Turkish or English |
| Branch naming | Source branches, without trunk and release branches | type/key, key, type/number, type/text. A prefix counts as a type when it is a usual one (feature, fix, hotfix, chore, … in KNOWN_BRANCH_TYPES) or at least 3 authors use it (DEFAULT_BRANCH_TYPE_MIN_AUTHORS), so a personal prefix is not reported as a type |
| Pull request titles | Titles of the used pull requests | key: text, key - text, [key] text, key text, text (key), Conventional Commits. When no single shape reaches the majority but titles starting with the key do, the plainer sentence "Pull request titles start with the ticket key." is proposed |
Confidence: high from 50 samples with 90% agreeing, medium from 20 samples with 80%, otherwise low. A convention is never added on a topic your profile already has a sentence about (a second, slightly different sentence about branch names would contradict yours); the finding then shows what the data says.
Languages
languages is proposed only when the profile does not have it and the ticket titles are clear: tickets is the detected language and code is set to en without being measured (nothing in discovery reads source text). When the profile already has languages, the finding only says whether the titles agree.
Confidence, and what low means for you
Every finding carries one of three levels. They describe how much evidence there is, not how likely the item is to be right in your company.
| Level | Read it as |
|---|---|
high | Enough evidence and nothing pointing elsewhere. Skim it. |
medium | Plausible. Check it against what you know. |
low | A guess. Do not let agents rely on it until a person has confirmed, corrected or deleted it. |
low is not a soft "probably". A team with confidence: low reaches agents with that label through get_company_profile, and the skills are written to treat it as unconfirmed, but a wrong glossary pair has no such label at search time: it silently adds the wrong code words to queries. Review low items before the draft becomes your profile, and measure glossary changes with evaluation.
In the draft, guesses are marked where they sit:
# DRAFT profile written by `safran discover`. Review it before use.
#
# What you wrote was kept as it was. Everything else was inferred from tracker and code-host
# data with counting and heuristics (no language model), so some of it is wrong.
# Added: 3 tracker project key(s), 6 repo(s) in new groups, 3 team(s), 8 glossary candidate(s), 4 convention(s), languages.
#
# How to review:
# 1. Lines ending in `# discovered`, teams with `confidence:` / `source:` and glossary entries
# whose `note:` starts with "discovered" are guesses. `low` means: do not trust until checked.
# 2. `safran discover` printed 29 finding(s) with the numbers behind every guess; read the
# low-confidence ones first. Glossary candidates are co-occurrence, not translation.
# 3. Fix or delete what is wrong. Once a team is confirmed, remove its `confidence` and `source`.
# 4. Run `safran profile check`.
version: 1
company: acmeFurther down the same file (the draft of the run above; the connector entries between these parts are your seed, unchanged):
groups:
backend:
- ledger # discovered (medium)
- payments-api # discovered (high)
frontend:
- admin-panel # discovered (high)
- web-app # discovered (high)
mobile:
- acme-android # discovered (high)
- acme-ios # discovered (high)languages:
tickets: tr # discovered from ticket titles
code: en # default, not measured
teams:
- name: Mobile
projects:
- MOB
repos:
- acme-android
- acme-ios
confidence: low
source: 9 ticket-PR links across 2 repos
- name: Payments
projects:
- PAY
repos:
- ledger
- payments-api
confidence: medium
source: 33 ticket-PR links across 2 repos
- name: Web
projects:
- WEB
repos:
- admin-panel
- web-app
confidence: medium
source: 20 ticket-PR links across 2 repos
glossary:
- term: iade
code:
- refund
note: "discovered, medium confidence: seen in 8 ticket titles as iade, iadeler, iadenin; 8 of 8 of their PRs change \"refund\" paths"
- term: sepet
code:
- basket
note: "discovered, low confidence: seen in 5 ticket titles as sepet, sepete, sepetteki; 5 of 5 of their PRs change \"basket\" paths"
- term: kapanı
code:
- close
note: "discovered, low confidence: seen in 5 ticket titles as kapanıyor, kapanış, kapanışı; 3 of 5 of their PRs change \"close\" paths"The glossary list continues with the other five candidates, then conventions: with four sentences, each ending in # discovered.
Reviewing the draft
- Read Problems and Coverage first. They say what discovery could not see: a tracker that did not answer, the share of pull requests without a ticket, how many were dropped. A team mapping built on 40% of the pull requests deserves less trust than one built on 97%.
- Go through every
lowfinding. For teams: is this really the team, or just the project whose tickets happened to land here? For co-owned repos: is it shared, or did ownership move? For glossary pairs: is the code word what a developer would search for when a ticket says the term? - Fix the draft. Delete wrong glossary entries (
kapanıabove), correct the term's spelling where the stem was cut short, add the code words you know and discovery could not see (it proposes single path words only). Once a team is confirmed, remove itsconfidenceandsource. - Bring the result into your profile and run
safran profile check. The draft is written from the parsed seed, so it has your values but not the comments or layout of your file; if you care about those, copy the discovered parts into your own file instead of renaming the draft over it. - If groups changed, run
safran syncagain, then measure: evaluation.
Running discovery again on the merged profile is safe: what you wrote is kept, groups you defined are not edited, teams you wrote are not re-invented, and glossary terms you already have are not proposed again.
Findings and stats
The printed list is findings grouped by kind, in this order: problem, coverage, project, group, team, glossary, convention, language. + marks a finding that added something to the draft (detail.applied is true); · is an observation that changed nothing. With --json the same findings come as data, with the numbers behind each sentence in detail:
$ safran discover --no-refresh --no-glossary --json --profile /work/acme/safran.yaml{
"kind": "group",
"subject": "payments-api → backend",
"confidence": "high",
"evidence": "package.json depends on fastify; name contains \"api\".",
"detail": {
"applied": true,
"repo": "payments-api",
"group": "backend",
"reasons": [
"package.json depends on fastify",
"name contains \"api\""
],
"against": []
}
}That is one element of findings from the JSON document, whose top-level keys are draft_file, replaced, wrote_profile, stats, findings and profile. In the SDK a finding has this shape:
| Field | Meaning |
|---|---|
kind | One of the eight kinds above |
subject | What it is about: Payments ↔ payments-api, iade → refund, tracker jira |
confidence | low, medium or high |
evidence | The reasoning as a sentence, with its numbers |
detail | The same numbers as data. Always has applied: whether the finding changed the draft |
stats describes the run as a whole. In the SDK the names are camelCase; --json prints them in snake_case.
| Field | Meaning |
|---|---|
repos | Repositories the code hosts list |
clonedRepos | Of those, how many are on disk (only these have their manifests read) |
pullRequests | Merged pull requests read from the link store for the window |
pullRequestsUsed | What is left after the drop rules |
dropped | Counts per drop rule: bot, noiseTitle, massChange, manyTickets, duplicate |
linkedPullRequests | Used pull requests that reference at least one ticket |
unlinkedShare | Share of used pull requests without any ticket key, 0 to 1 |
ticketsSampled | Ticket titles that were read |
ticketsFailed | Sampled tickets that could not be read |
added | What went into the draft: projects, groupedRepos, teams, teamRepos, glossary, conventions (counts) and languages (boolean) |
findings | Number of findings per confidence level |
Command flags
| Flag | Effect |
|---|---|
--out <file> | Where to write the draft. Default: safran.draft.yaml next to the profile. Pointing it at the profile itself is refused |
--write | Write over the profile itself instead of a draft file. Refused without --force, and cannot be combined with --out |
--force | Allows --write to replace the profile |
--since <date> | How far back to read merged pull requests (an ISO date). Default: 12 months |
--no-glossary | Skip glossary candidates |
--no-refresh | Use the local link store as it is; fetch no pull requests. Tracker projects and ticket titles are still read |
An existing draft file is replaced without asking; the last line says "Replaced the draft at" when it was. --write without --force stops before anything is read:
$ safran discover --write
✘ --write replaces your profile with the draft
→ Pass --write --force if that is what you want; without --write the draft goes to safran.draft.yaml for review.The flags of every setup command are in the CLI reference.
From the SDK
discoverProfile takes a Safran instance and returns the draft as data and as YAML. It writes nothing to disk; what to do with result.yaml is yours to decide. The example runs over in-memory connectors from @safran/kit/testing, so it needs no network:
import { mkdtemp } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { createSafran } from "@safran/core";
import { discoverProfile } from "@safran/discover";
import { FakeCodeHost, FakeTracker, fakePlugins } from "@safran/kit/testing";
// A tracker and a code host held in memory: three finished tickets, three merged pull requests.
const work = [
{ key: "PAY-1423", title: "Kısmi iade işlemi İstanbul şubesinde başarısız oluyor", file: "src/refund/service.ts", mergedAt: "2026-10-30T09:00:00Z" },
{ key: "PAY-1500", title: "Refund webhook retries are not idempotent", file: "src/webhook/retry.ts", mergedAt: "2026-11-12T09:00:00Z" },
{ key: "PAY-1501", title: "Checkout basket total ignores the campaign discount", file: "src/refund/policy.ts", mergedAt: "2026-11-16T09:00:00Z" },
];
const tracker = new FakeTracker({
id: "jira",
projects: [{ key: "PAY", name: "Payments" }],
tickets: work.map(({ key, title }) => ({ key, title })),
});
const host = new FakeCodeHost({
id: "azure",
repos: [{ name: "payments-api" }],
pullRequests: work.map(({ key, file, mergedAt }, index) => ({
id: String(101 + index),
repo: "payments-api",
title: `${key}: fix`,
description: "",
sourceBranch: `feature/${key}-fix`,
mergedAt,
linkedTicketKeys: [key],
changedFiles: [file],
})),
});
await using safran = await createSafran({
profile: {
version: 1,
company: "acme",
trackers: [{ id: "jira", type: "fake" }],
code: { hosts: [{ id: "azure", type: "fake" }] },
embeddings: { type: "fake" },
},
builtinPlugins: false,
plugins: fakePlugins({ trackers: [tracker], hosts: [host] }),
dataDir: await mkdtemp(join(tmpdir(), "acme-discover-")),
});
const result = await discoverProfile(safran, {
since: "2026-01-01",
glossary: { enabled: false },
onProgress: ({ step, message }) => console.error(`${step}: ${message}`),
});
for (const finding of result.findings) {
console.log(`${finding.detail.applied ? "+" : "·"} ${finding.confidence.padEnd(6)} ${finding.kind.padEnd(10)} ${finding.subject}`);
}
console.log(result.profile.teams);
console.log(result.stats.added);Its output (stdout), with three links in one repo, which is exactly the minimum:
$ bun discover.ts
· low coverage ticket references in merged PRs
+ medium project tracker jira
+ low group payments-api → backend
+ low team Payments ↔ payments-api
· low language languages.tickets
[
{
name: "Payments",
projects: [ "PAY" ],
repos: [ "payments-api" ],
confidence: "low",
source: "3 ticket-PR links",
}
]
{
projects: 1,
groupedRepos: 1,
teams: 1,
teamRepos: 0,
glossary: 0,
conventions: 0,
languages: false,
}Three pull requests are enough for a low team and nothing else: no convention (10 samples needed), no language (too few titles to classify).
Options
| Option | Default | Meaning |
|---|---|---|
signal | none | Cancels the run; it ends with ABORTED |
onProgress | none | Called with a step (repos, projects, links, tickets, groups, teams, glossary, conventions, profile), a message and, where known, done and total |
since | 12 months before now | ISO date: how far back merged pull requests are read. An invalid date is INVALID_INPUT |
maxPerRepo | The link store's default (500) | Cap on pull requests fetched per repo, newest first |
refreshLinks | true | false uses the link store as it is and fetches no pull requests |
sampleTickets | 200 | Tickets fetched at most for their titles; 0 fetches none |
glossary | enabled, 20 terms, detected language | enabled, maxTerms, and language (ISO 639-1) to state the ticket language instead of detecting it |
thresholds | The table below | Any subset of the tunable numbers |
botAuthors | none | Author names (case-insensitive) treated as bots on top of the built-in patterns |
seed | The profile file the instance was loaded from, else safran.profile | The profile exactly as the human wrote it. Pass it when the instance was built from an inline profile and you want "not written" told apart from "written as the default" |
now | The current time | Only used to compute the default since |
The CLI exposes since, refreshLinks and glossary.enabled as flags. Everything else, thresholds included, is SDK-only.
Thresholds
Every tunable number, with the constant that holds its default (all exported from @safran/discover):
| Threshold | Default | Constant | Decides |
|---|---|---|---|
maxProjectsPerTracker | 25 | DEFAULT_MAX_PROJECTS_PER_TRACKER | Tracker projects proposed per tracker at most |
massChangeFiles | 50 | DEFAULT_MASS_CHANGE_FILES | A pull request changing more files is a mass change and is dropped |
maxTicketsPerPull | 5 | DEFAULT_MAX_TICKETS_PER_PULL | A pull request naming more tickets is dropped |
minLinks | 3 | DEFAULT_MIN_LINKS | Ticket-linked pull requests a repo ↔ project pair needs before anything is proposed |
ownerShare | 0.6 | DEFAULT_OWNER_SHARE | Recency-weighted share one project needs to own a repo |
sharedShare | 0.3 | DEFAULT_SHARED_SHARE | Share at which a project co-owns a repo nobody owns outright |
maxCoOwners | 2 | DEFAULT_MAX_CO_OWNERS | Co-owners listed at most; with more, the repo is reported as shared and left unassigned |
recencyHalfLifeDays | 180 | DEFAULT_RECENCY_HALF_LIFE_DAYS | Days after which a link counts half |
mediumMinLinks | 8 | DEFAULT_MEDIUM_MIN_LINKS | Links for medium team confidence |
highMinLinks | 20 | DEFAULT_HIGH_MIN_LINKS | Links for high team confidence |
highShare | 0.8 | DEFAULT_HIGH_SHARE | Share for high team confidence |
glossaryMinTickets | 3 | DEFAULT_GLOSSARY_MIN_TICKETS | Tickets a term must appear in |
glossaryMaxTicketShare | 0.4 | DEFAULT_GLOSSARY_MAX_TICKET_SHARE | A term in a larger share of tickets is too generic |
glossaryMaxFiles | 20 | DEFAULT_GLOSSARY_MAX_FILES | Wider pull requests are not used for the glossary |
glossaryMinSupport | 3 | DEFAULT_GLOSSARY_MIN_SUPPORT | Pull requests of a term that must touch a path word |
glossaryMinContrast | 3 | DEFAULT_GLOSSARY_MIN_CONTRAST | Other pull requests in the same repo needed to compare against |
glossaryMinLift | 0.4 | DEFAULT_GLOSSARY_MIN_LIFT | Minimum difference between the path word's share in the term's pull requests and in the others |
glossaryMaxCodeWords | 3 | DEFAULT_GLOSSARY_MAX_CODE_WORDS | Code words per glossary candidate at most |
conventionMinSamples | 10 | DEFAULT_CONVENTION_MIN_SAMPLES | Samples needed before a convention or a language is proposed |
conventionMajority | 0.7 | DEFAULT_CONVENTION_MAJORITY | Share of samples that must agree |
The defaults are starting points chosen by the authors, not values tuned on your company. If you change one, read the findings again: a lower minLinks produces more teams and more wrong ones.
The full declarations are in the @safran/discover reference:
/**
* Drafts a company profile from what the trackers and code hosts of a Safran instance
* reveal. The instance is built from a seed profile that has the connectors configured;
* the result is that seed plus proposals, each explained by a finding. Nothing is written
* to disk and no language model is involved.
*/
export async function discoverProfile(safran: Safran, options: DiscoverOptions = {}): Promise<DiscoveryResult>;
export interface DiscoveryResult {
/** The seed profile plus what discovery added. Validates with `parseProfile`. */
profile: ProfileInput;
/** `profile` as YAML with a review header, ready to write. */
yaml: string;
findings: Finding[];
stats: DiscoveryStats;
}defined in packages/discover/src/discover.ts, packages/discover/src/types.ts
Honest limits
-
It needs history. With no code host that lists merged pull requests (a
localhost has none) and no tracker, discovery can still group repos, and says so for the rest. This profile has only alocalhost:$ safran discover --profile /work/acme/local/safran.yaml Safran discovery — draft for review (statistics and heuristics, no language model) 6 repos (6 cloned), 0 merged PRs read, 0 used, 0 with a ticket, 0 ticket titles sampled. Legend: + added to the draft, · observation only; [high] [med ] [low ] = confidence. Coverage (2) · [high] pull request history Not enough history: no code host in the profile can list pull requests, so teams, glossary and PR conventions cannot be inferred from this instance. · [high] ticket titles The profile has no tracker, so no ticket titles were read: ticket language and glossary candidates cannot be inferred.The same happens, per repo, below 3 ticket-linked pull requests per project, and for conventions below 10 samples.
-
It only sees linked work. Teams and glossary come from pull requests that name a ticket. If people do not write ticket keys in titles or branch names and the code host links nothing itself, the coverage finding will show a high share without a ticket and the mapping rests on the remainder.
-
A team is a tracker project. Discovery cannot see an org chart. Two teams sharing one project come out as one team; one team working across three projects comes out as three.
-
Glossary candidates are co-occurrence, not translation. A pair is found only when the same word recurs in titles and its pull requests keep touching one path word that other pull requests in the same repo do not. Expect a minority of your real terms, some wrong pairs, single words only, and no handling of consonant softening (
kitap/kitabıare two words to it). -
Languages: Turkish and English only, by a small heuristic.
languages.codeis never measured. -
Groups are a fixed vocabulary. Six names, chosen from manifests, name words and the primary language. A monorepo gets one group.
-
Conventions are habits, not rules. "97% of branches look like this" says what people do, not what your team decided.
Common mistakes
- Running it before
safran sync. Nothing breaks, but repos are grouped without their manifests and glossary candidates are not checked against the code index, so all of them staylow. - Running it with a
localcode host and expecting teams. There is no pull request history to learn from; see the local connector. - Renaming the draft over the profile unread. The draft validates, and that says nothing about whether it is true.
- Leaving
confidence: lowon a team you have confirmed. Agents keep treating it as unconfirmed. Removeconfidenceandsourceonce you have checked it. - Tuning thresholds until the output looks right. The output looking right on the repos you know is not evidence for the ones you do not. Fix the draft by hand instead.
Where discovery sits in the whole setup is in Setting up at a new company; errors you may meet on the way are in troubleshooting.