Skip to content
safran

Type to search. Enter opens the first result.

    Glossary, teams and conventions

    Four parts of the profile carry what people at the company know and the code does not say: the glossary, teams, groups and conventions. This page explains exactly how each one is used, with acme's Turkish tickets and English code as the example.

    version: 1
    company: acme
    languages:
      tickets: tr
      code: en
    
    trackers:
      - id: jira
        type: jira
        url: https://acme.atlassian.net
        email_env: JIRA_EMAIL
        token_env: JIRA_TOKEN
        projects: [PAY, MOB, WEB]
    
    code:
      groups:
        backend: [payments-api, ledger]
        mobile: [acme-ios, acme-android]
        frontend: [web-app, admin-panel]
    
    teams:
      - name: Payments
        projects: [PAY]
        repos: [payments-api, ledger]
      - name: Mobile
        projects: [MOB]
        repos: [acme-ios, acme-android]
        confidence: low
        source: 9 ticket-PR links
    
    glossary:
      - term: Sepet
        code: [basket, cart]
      - term: İade
        code: [refund, chargeback]
    
    conventions:
      - Task titles are written in English.
      - Branch names follow feature/<TICKET-KEY>-short-description.

    The glossary

    A glossary entry says: when a ticket says this word, the code says these.

    FieldWhat it is
    termThe word as people write it in tickets.
    codeOne or more identifiers or words the code uses for it.
    noteOptional remark. It is returned with the entry; it does not affect matching.

    The ticket for acme's bug reads "Kısmi iade işlemi İstanbul şubesinde başarısız oluyor". The code never says "iade"; it says refund. With the entry above, a search for the ticket's words also searches for the code's words:

    $ safran search "kısmi iade" --limit 2
    glossary: İade → refund, chargeback
    
    1  payments-api  README.md:1-3
       doc · markdown · score 0.567 (dense 0.630, lexical 0.000)
       1 │ # payments-api
       2 │
       3 │ Captures, refunds and chargebacks for acme. Refund rules live in `src/refund/policy.ts`.
    
    2  payments-api  src/refund/service.ts:1-21
       api-service · RefundResult, refundPayment, postLedger… · typescript · score 0.516 (dense 0.574, lexical 0.000)
        1 │ import { assertRefundable, type RefundRequest } from "./policy";
        2 │
        3 │ export interface RefundResult {
        4 │   refundId: string;
        5 │   amount: number;
        6 │   partial: boolean;
        7 │ }
        8 │
       … 13 more lines (--full, or: safran read payments-api src/refund/service.ts --lines 1-21)
    
    2 hits (limit 2; raise it with --limit)

    The first line reports which entries fired. The query that reached the index was kısmi iade refund chargeback.

    How a term is matched

    A term matches when it occurs in the text at the start of a word. What comes after it does not matter.

    1. Both the term and the text are case-folded (see below).
    2. The term is looked for anywhere in the text.
    3. An occurrence counts when it is at the very start of the text, or when the character before it is not a letter and not a digit (in any script).

    So the term is a whole word or the stem a word starts with. That is on purpose: Turkish and many other languages attach suffixes, and "iadeler", "iadenin" and "iadesi" should all find the entry for İade.

    TextMatches İade?Why
    Kısmi iade işlemiyesA whole word.
    iadeler sepette görünmüyoryes (and Sepet)Both terms start a word; suffixes follow.
    IADE talebiyesCase folding, typed without the dotted capital.
    kısmi-iadeyesA dash is not a letter or a digit.
    tedarikçiadesinoThe occurrence is in the middle of a word.

    Case folding, including Turkish İ/I/ı/i

    Matching does not use the machine's locale. It uses one folding for every language:

    /**
     * Case folding for matching, the same in every process locale and for every language of the
     * text. `I`, `İ`, `ı` and `i` all become `i`, so an English term matches however it was typed
     * (`INVOICE` ↔ `invoice`) and a Turkish one does too (`İADE` ↔ `iade` ↔ `IADE`, the last being
     * how it is typed on a keyboard without the dotted capital). Locale-aware lower-casing cannot do
     * both: with `tr` rules `I` becomes `ı` and `INVOICE` stops matching `invoice`.
     *
     * Only for comparing: the result is not for display and its length can differ from the input's.
     */
    export function foldCase(text: string): string;

    defined in packages/kit/src/text.ts

    I, İ, ı and i all become i, and everything else is lower-cased. A Turkish term therefore matches however it was typed (İADE, iade, IADE), and an English term in the same glossary still matches too (INVOICE and invoice), which locale-aware Turkish lower-casing would break.

    The same folding decides duplicates: İade and IADE are one term, and a profile that lists both is rejected.

    Which words are added

    For every entry that matched, in the order the glossary lists them, each of its code words is appended to the query, separated by spaces, unless:

    • the folded query already contains that word (as a substring: a query with "refunded" already contains refund), or
    • the word was already added by an earlier entry.

    The original query is never changed or reordered; words are only added at the end. When nothing is added, the query goes to the index as written.

    QueryEffective query
    kısmi iadekısmi iade refund chargeback
    kısmi iade refundkısmi iade refund chargeback
    iadeler sepette görünmüyoriadeler sepette görünmüyor basket cart refund chargeback
    retry policy for webhooksretry policy for webhooks

    The added English words help both halves of search: the lexical channel can now match the identifiers, and the dense channel gets a query closer to the code. How much that changes results for your company is something to measure, not assume; see Evaluation.

    Turning it off

    Expansion is on by default. Turn it off for one search to see what the glossary contributes:

    safran search "kısmi iade" --no-glossary

    In the SDK, expandGlossary: false turns it off and leaving the option out means the default, on. The search_code tool has the same switch as expand_glossary, and safran eval retrieval can measure a configuration with and without it.

    Expansion applies to semantic search only. grep looks for exactly what you give it.

    Using the glossary directly

    The matching functions are exported from @safran/profile and do no I/O, so you can use them on any text, for example to see which entries a ticket title triggers:

    glossary.ts
    import { expandWithGlossary, matchGlossary, parseProfile } from "@safran/profile";
    
    const profile = parseProfile({
      version: 1,
      company: "acme",
      languages: { tickets: "tr", code: "en" },
      glossary: [
        { term: "Sepet", code: ["basket", "cart"] },
        { term: "İade", code: ["refund", "chargeback"] },
      ],
    });
    
    const title = "Kısmi iade işlemi İstanbul şubesinde başarısız oluyor";
    
    console.log(matchGlossary(profile, title).map((entry) => entry.term)); // ["İade"]
    console.log(expandWithGlossary(profile, title)); // ["refund", "chargeback"]
    console.log(expandWithGlossary(profile, "iadeler sepette görünmüyor")); // ["basket", "cart", "refund", "chargeback"]
    /**
     * Glossary entries whose term occurs in the text as a whole word (or word stem prefix,
     * since Turkish and many other languages attach suffixes: "iadeler", "iadenin").
     *
     * Case is folded with `foldCase` on both sides, not with a locale. Turkish lower-casing turns
     * `I` into `ı`, so under it the English term "invoice" never matched "INVOICE", and a profile
     * usually holds terms in both languages.
     */
    export function matchGlossary(profile: Profile, text: string): GlossaryEntry[];
    
    /** Code-side words for every glossary term found in the text, de-duplicated. */
    export function expandWithGlossary(profile: Profile, text: string): string[];

    defined in packages/profile/src/queries.ts

    On an instance, safran.company.glossary() returns the entries and safran.company.expand(text) is expandWithGlossary bound to its profile. Note the difference from search: expand returns every code word of the matched entries, also the ones the text already contains.

    Writing a good glossary

    • Add an entry when tickets and code use different words for the same thing. Words that are already the same in both need no entry.
    • List the words that really appear in identifiers and file names (refund, chargeback), not a dictionary translation.
    • safran discover proposes glossary candidates from merged pull requests: words that recur in ticket titles while their pull requests keep touching paths with a common word. This is co-occurrence counting, not translation, so expect it to find a minority of the real terms and some wrong pairs. They arrive in a draft for you to review. See Discovery.
    • Changing the glossary needs no re-index. It changes queries, not the index.

    Teams and ownership

    A team entry declares which tracker projects and which repositories a team owns.

    whoOwns answers for a repository or for a project, and says how it knows:

    owners.ts
    import { createSafran } from "@safran/core";
    
    await using safran = await createSafran({ profile: "/work/acme/safran.yaml" });
    
    const byRepo = await safran.company.whoOwns({ repo: "payments-api" });
    console.log(byRepo.basis, byRepo.teams.map((team) => team.name)); // "profile" ["Payments"]
    
    const byProject = await safran.company.whoOwns({ project: "MOB" });
    for (const team of byProject.teams) {
      if (team.confidence === "low") console.log(`${team.name}: confirm this mapping (${team.source ?? "no source"})`);
    }
    export interface Ownership {
      teams: Team[];
      /** How the answer was reached: "profile" when declared, "history" when inferred from past work. */
      basis: "profile" | "history" | "none";
    }

    defined in packages/core/src/api.ts

    basisMeaning
    profileA team in the profile lists the repository or the project.
    historyRepositories only. No team lists the repository, so the answer was inferred from merged pull requests: each pull request of the repository votes for the teams that own the projects of its tickets, and the teams with the most votes are returned.
    noneNobody is declared and nothing could be inferred. teams is empty. This is an answer, not an error.

    Details that matter:

    • A repository is matched by its exact name. A project key is matched without regard to case.
    • More than one team may own the same repository or project; all of them are returned.
    • A project's owners can only be declared. History links tickets to code, not to teams.
    • The inference needs work history: run safran links refresh first.

    The same question from the terminal:

    $ safran owns --repo payments-api
    Payments  owns repo payments-api — declared in the profile
      Payments  projects PAY · repos payments-api, ledger
    $ safran owns --project MOB
    Mobile  owns project MOB — declared in the profile
      Mobile  projects MOB · repos acme-ios, acme-android · confidence low · 9 ticket-PR links
      ! Mobile is a low-confidence mapping; confirm it in the profile.

    The agent asks it through the who_owns tool, and gets the team list from get_company_profile.

    confidence and source

    safran discover infers team mappings from which tickets' pull requests touched which repositories, and writes how sure it is. confidence: low means a person must check the entry. Until you do, safran profile check and safran owns point at it, and unconfirmedTeams(profile) from @safran/profile returns the names. To confirm an entry, check its projects and repos and delete the confidence line.

    Groups

    code.groups names sets of repositories. A group has no behaviour of its own; it is a filter you can name.

    safran search "kısmi iade" --group backend
    • Several groups in one search widen the scope to the repositories of all of them.
    • A group together with an explicit repository list narrows the scope to the repositories that are in both.
    • An unknown group name is an INVALID_INPUT error whose hint lists the known groups.
    • reposInGroups(profile, groups) and groupsOfRepo(profile, repo) from @safran/profile answer the two directions without an instance.

    The skills scope a search with a group when the concept they are looking for belongs to one.

    Conventions

    Conventions are sentences. Safran stores and returns them (safran.company.conventions(), the conventions field of get_company_profile) and does not interpret them. The skills read them and follow them: text drafted for a ticket follows what the conventions say about titles and format, and the ticket-readiness skill reports a ticket that breaks one.

    Write conventions as rules a new colleague could follow without asking: one rule per line, specific, checkable. safran discover proposes some from habits it can see in past branch names and pull request titles.

    Next