Repository navigation
factory: one repository's facts counted from every job it keeps - #2143
Merged
Merged
Conversation
A job read and every job on the queue now carry area: the repository's
declared area most of the job's changed files fall under, or else the
top-level directory most of them sit under, written with a trailing slash
("cli/"). A job that changed no file, or only files at the root, carries
none. factory.JobArea is the one pure rule; the queue and the job's own read
apply the repository's declared areas, which they have at hand.
Hello announces factory.job_area.
GET /v1/spend/repos?from=&to= folds the factory's job documents into
{from, to, repos:[{repo, spent_usd, jobs}], total_usd} for the
repositories the caller can read. A job's whole spend is placed on the
day its run started, in the factory's zone, or on its creation day when
it never ran. factory.spend_by_repo carries it over the app wire; hello
announces factory.spend_by_repo and capabilities say spend_by_repo.
The live lane writes its file under greet/ and checks that the queue and the job's read both say area greet/ and that the write step's recorded model is the pinned one. factory.local_start now turns the runner on itself, so the lane no longer expects it off before the explicit run.
# Conflicts: # docs/design/app-v3/PROTOCOL.md
time_zone is the IANA name of the factory's clock zone. A process on its Local zone names it from TZ (empty is UTC) or the /etc/localtime link, and leaves the field off when neither names one.
…32/engine-repo-facts
…er everywhere Under a container directory (src, internal, pkg, lib, app, apps, packages, crates, cmd; factory.AreaContainers) a job's area is the first two segments, such as internal/factory/; a file directly inside one counts as the container. Every job the server sends is judged once, in withVersion, by api.AreaIn against the areas repositories declared as of the handler's last floor read, so a verb's job and the queue never name different areas.
…again FromItem and FromSnapshot keep saying area through api.AreaIn, so a queue encoded on its own matches the one the server sends; the server's withVersion says it again with the declarations of its last floor read.
factory.repo_facts {factory, repo, days?, months?} reads the factory's
GET /v1/repos/{owner}/{repo}/facts: jobs finished and pull requests merged
in the window and this month, spend by calendar month by the spend-by-repo
placement rule, jobs, rounds and questions by area by the job-area rule, and
jobs stuck on one step for a day or more, each with its own phrase. Bounded
to 20 areas and 20 stuck steps (97 facts); hello word factory.repo_facts and
capabilities repo_facts.
The app test reads the facts at the fixture factory's own clock.
…32/engine-repo-facts
…r on local_start turns the runner on by design, so the lane now fails when it is left off, and it reads the recorder's call count under the recorder's lock.
Spend by repository keeps one placement rule, factory.SpentIn, which the landed spend read now calls. Area facts say area through api.AreaIn, the landed one function, and the change-area helper is gone. Capabilities, hello and the protocol document carry repo_read and repo_facts together.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Depends on #2131 (
job.area,factory.JobArea) and #2132 (factory.spend_by_repo). Both are merged into this branch with merge commits; review only the commits after them.Summary
A desk can now ask the factory for one repository's facts. The factory counts them over every job document it keeps, not only the recent jobs that
factory.queueholds. Each fact has its own phrase, and a number never appears without its noun. A desk can use these facts to write about a repository without counting anything itself.daysis 1–366 calendar days ending today (default 30).monthsis 1–12 calendar months of spend, this one included (default 3). On the app wire, an absent or zero value means the default.truncatedcounts what the bound left out.factory.JobAreanames it:area:webhooksfor a declared area,area:cli/for a top-level fallback.Example answer:
{"factory":"f1","repo":"acme/api","as_of":"2026-11-20T12:00:00Z","time_zone":"UTC","days":30,"months":2,"facts":[ {"id":"n.finished.30d","kind":"count","value":2,"phrase":"2 jobs finished in the last 30 days","about":"jobs shipped, by the day their run ended, 2026-10-22 to 2026-11-20","source":"engine:repo_facts.finished"}, {"id":"n.merged.month","kind":"count","value":1,"phrase":"1 pull request merged in November 2026","about":"pull requests the factory opened that merged, 2026-11-01 to 2026-11-20","source":"engine:repo_facts.merged"}, {"id":"usd.month:2026-10","kind":"usd","value":3.5,"phrase":"$3.50 spent on 2 jobs in October 2026","about":"each job's whole spend on the day its run started","source":"engine:repo_facts.spend"}, {"id":"n.stuck.review","kind":"count","value":1,"phrase":"1 job stuck in review for a day or more","about":"open jobs whose current step began 24 hours or more ago","source":"engine:repo_facts.stuck"}, {"id":"area:webhooks","kind":"area","value":2,"phrase":"webhooks: 2 jobs in the last 30 days","about":"jobs whose run started in the window, by the area their change touched most","source":"engine:repo_facts.area"}, {"id":"area:webhooks.rounds","kind":"rounds","value":7,"phrase":"7 rounds in webhooks in the last 30 days","about":"rounds every step of those jobs ran","source":"engine:repo_facts.area"}, {"id":"area:webhooks.asks","kind":"count","value":2,"phrase":"2 questions asked in webhooks in the last 30 days","about":"questions those jobs asked a person, answered or open","source":"engine:repo_facts.area"}]}A fact is
{id, kind, value, phrase, about?, source}.valueis always present and can be 0.time_zoneis absent when the factory cannot name its zone.truncatedis absent when nothing was cut.Evidence
repo_facts_test.go:114:9: undefined: RepoFactsOf … [build failed].FAIL internal/factory/api.repo_facts_test.go:53: GET /v1/repos/acme/api/facts = 404 … "error":"factory endpoint not found".make test-focuson./internal/factory/api,./internal/factory/serve,./internal/appwireand./cmd/codeafpassed. It coveredTestRepoFacts*,TestAppFactoryRepoFacts…, the spend-by-repo regressions, the protocol-document test and the schema test.make test-touched BASE=origin/app/v3passed. In cmd/codeaf,TestCopiedChatDoorsKeepDistinctStableDraftKeysfailed once and passed on rerun; the harness marked it flaky.CODEAF_LIVE_FACTORY=1 go test -tags e2e -run '^TestLiveLocalRunReachesTheApproveGateOnOneModel$' ./cmd/codeafwith every role on OpenRouterdeepseek/deepseek-v4.1-flash.factory.repo_factsfor the job's repository after the job ran. That extension is not in this PR.deepseek/deepseek-v4.1-flashas the write step's model. The request models and the response models were alldeepseek/deepseek-v4.1-flash(one_model true).factory.repo_factsansweredarea:greet/"greet/: 1 job in the last day",area:greet/.rounds"2 rounds in greet/ in the last day", andusd.month:2026-11"$0.01 spent on 1 job in November 2026" for a $0.0053 run. It also answeredtime_zone.test-laws:internal/taxonomyflagsinternal/factory/serve/idempotency.go;internal/sessionreports the task-engine and memory-engine complexity ceilings.changelog-check: entries already indocs/changes/unreleasedfail the check.Merge Danger
Door: two-way
This is a new read method, a new route and a new hello word. An older desk ignores them. A newer desk sees no word from an older engine, and an older factory answers the route not found.
Blast Radius: small
There are two small reuse refactors.
spend_by_reponow places spend throughfactory.SpentIn, with the same rule.api.AreaInnow uses the sharedchangeArea, with the same rule. Their existing tests still pass. No manual page changes: this is an app-wire read with no chat or resident surface.🤖 Generated with Claude Code