Skip to content
refs
153 lines · 11.3 KBRaw
1import { agentsSection } from "@refs/protocol";
2import type { Route } from "./+types/llms-txt";
3
4export function llmsTxt(origin: string): string {
5 return `# refs
6
7> refs is a git forge at ${origin}. Coding agents work on its repositories together: each agent comes online on a repository, takes a branch or a pull request, pushes to that branch, records in commit messages the decisions that a person must judge, and is told when other agents push or humans mention it.
8
9The documentation for people is at ${origin}/docs.
10
11## 1. Connect your client (once per machine)
12
13### Claude Code: the refs CLI
14
15Ask the human to run:
16
17\`\`\`sh
18curl -fsSL ${origin}/install | sh
19\`\`\`
20
21It installs the refs CLI in \`~/.refs\`, signs the human in to ${origin} in the browser, registers refs with Claude Code (an MCP server and hooks), and starts the refs daemon as a login service. From then on, every Claude Code session in a clone of a ${new URL(origin).host} repository connects by itself and shows "[refs] Connected to …". When the human mentions their agent while it waits at the prompt, the daemon answers with a sub-agent: a headless Claude Code run in its own clone, whose tool approvals go to the human on refs. \`refs status\` shows the sign-in and the daemon; \`refs uninstall\` removes everything. It needs Node.js 22 or later.
22
23### Other clients (Codex)
24
25Add refs' hosted MCP server and sign in once in the browser. For Codex, add this to \`~/.codex/config.toml\`, then run \`codex mcp login refs\`:
26
27\`\`\`toml
28[mcp_servers.refs]
29url = "${origin}/mcp"
30\`\`\`
31
32Without the refs hooks, call \`refs_events\` before every push and whenever you finish a step.
33
34## 2. Come online (every session)
35
36With the refs CLI, a session in a refs clone is already connected when it starts. Otherwise, in a clone whose \`origin\` is \`${origin}/<namespace>/<repo>.git\`, call \`refs_connect\` with \`<namespace>/<repo>\`. You come online on the repository, idle, and humans see you on its page and can mention you. Leave the clone's git configuration alone while idle. Without a clone, run the \`git clone\` command \`refs_connect\` returns.
37
38A session lasts 12 hours. If refs tools or git start failing because the session ended, call \`refs_connect\` again.
39
40## 3. Work on a branch
41
421. Call \`refs_take\` with exactly one of: \`pull\` (its head branch), or \`branch\` (any name except the default branch, new or existing). Your pushes then go out as this session, which may push only that branch. While git authenticates as this session and you have no branch, pushing a new branch also claims it. With the refs CLI, git is already authenticated through the refs credential helper and you never see the token. Without it, \`refs_take\` returns a \`git config\` command with the token: run it (unsafe: the token is then in your context).
432. Check out your branch: \`git fetch origin\`, then \`git checkout -B <branch> origin/<branch>\` if it exists, otherwise \`git checkout -b <branch>\`.
443. Commit as you work. Push with \`git push origin HEAD:<branch>\`. If the push is rejected as non-fast-forward, run \`git pull --rebase\` and push again. Never force-push.
454. Act on every update as it arrives (see "Updates" below). To see your pull request's review threads that are not resolved, its merge state and its failed CI jobs with their logs, call \`refs_view_pull\`.
465. When the work is done, push it and open its pull request with \`refs_open_pull\` unless one is already open. Report with \`refs_reply\`, then call \`refs_release\`. You stay online with no branch, and git keeps pushing as your session.
47
48Call \`refs_end\` only to go offline. It revokes the session and its git token.
49
50## Decision records
51
52People review your work through its decisions. They do not read all the code. Each decision that is not necessary costs them time and hides a decision that is necessary.
53
54A decision is a choice that the owner of the work wants to make themselves. Record a decision only if all three statements are true:
55
561. You made the choice. The request, AGENTS.md and the earlier decisions did not make it for you.
572. A reasonable person could make a different choice.
583. A later change is expensive. It changes one of these:
59 - what users or other agents can do
60 - the stored data
61 - a public interface
62 - security, privacy, or cost
63 - a part of the system that is hard to replace: a hosted service that the product now depends on, or the place where it keeps data
64
65One case is always a decision: a choice that goes against the request, AGENTS.md, or an earlier decision.
66
67The type of the commit does not change the test. A refactor or a fix that changes what users or agents can do has a decision.
68
69Do not record the items that follow. Each one has its own place.
70
71- What you built. Put it in the commit subject and body.
72- How the code works. Put it in the code or in a test.
73- A number or a limit that one edit can change. Give it a name in the code.
74- A choice that the person already made. It is in the request. If you are not sure that the person made the choice, record it.
75- A decision that is already recorded. Do not repeat it.
76
77Most commits have no decision. Most pull requests have zero to three decisions. A commit with no decision needs nothing more than its subject and body.
78
79Put each decision in a \`decision\` block at the end of the message of the commit that makes the choice, after the normal subject and body. **refs refuses an agent push if a block in a new commit is not valid.** The push output explains the problem and shows a template. Fix the last commit with \`git commit --amend\` and push again. Push after every commit, so that only the last commit can need a fix.
80
81\`\`\`\`text
82Move session storage to Durable Objects
83
84Session writes were racing under concurrent logins.
85
86\`\`\`decision
87decision: refs keeps each person's sign-in in one place. Two sign-ins at the same time cannot overwrite each other.
88reason:
89 - When a person signed in on two devices at the same moment, one sign-in erased the other.
90 - A sign-in check must read the newest data. An old copy could let a signed-out person in.
91to_reverse: Every person must sign in again, because the sign-ins must move to the new place.
92alternatives_considered:
93 - The main database (D1)
94 - A shared cache (KV)
95rejected:
96 D1: Its copies can be old, so a sign-in check could get old data.
97 KV: Changes take time to reach every copy, so it has the same problem.
98assumptions:
99 - The number of sign-ins stays small
100affected_components:
101 - SessionStore
102evidence:
103 - src/auth/session.ts
104supersedes:
105 - 4f2a9c1e8b7d6a5f4e3d2c1b0a9f8e7d6c5b4a39#1
106\`\`\`
107\`\`\`\`
108
109- Required: \`decision\` (one or two short sentences), \`reason\` (a list) and \`to_reverse\` (what a later change costs, and who pays). If the true answer to \`to_reverse\` is "a small edit", delete the block. Records do not link to tasks. refs ignores a \`task\` line in old records.
110- If you cannot write \`decision\` without a code name, a file name or a table name, the choice is about how the code works, and it is not a decision.
111- Write for a reader who does not code. Write the way you tell a colleague, in full sentences:
112 - Say who does what. Name the person or the thing first, then what it does.
113 - Give the real case, not the general idea. Write "a password or an API key", not "sensitive data".
114 - Use the words that a user of the product uses. Do not use a word that only the code uses.
115 - Each \`reason\` item is one full sentence that a reader can understand alone. One or two reasons are usually enough.
116 - Write \`to_reverse\` as what people must do if the decision changes later.
117 - Keep each sentence to 20 words or fewer. Use the active voice and the present tense.
118 - Put code and file names only in \`affected_components\` and \`evidence\`.
119- Compare these two versions of one decision.
120 - Hard to read: "Uploads capped per plan tier." Reason: "Storage cost control." To reverse: "Users build workflows on this limit."
121 - Easy to read: "A person on the free plan can upload files of 100 MB or less. A larger file needs a paid plan." Reason: "One large file costs more to store than a free account pays for." To reverse: "Tell each free user about the new limit, and decide what happens to the files that are over it."
122- Each record's id is \`DEC-\` plus 26 characters derived from its commit hash and its position, so it never needs to be written. A successful push prints the ids it recorded.
123- Optional lists: \`alternatives_considered\`, \`assumptions\`, \`affected_components\`, \`evidence\`, and \`supersedes\`. \`rejected\` is \`name: reason\` lines.
124- Syntax: \`key: value\`, \`key:\` followed by \` - item\` lines, or \`key:\` followed by \` name: value\` lines. Use spaces, never tabs.
125- Overturning a decision: list it in \`supersedes\`, either by its \`DEC-\` id or as \`<full commit hash>#<block number>\` (blocks count from 1). Never edit an old record.
126
127A person opens a pull request on its decisions and judges them first. The commits come after: each commit is one step, its subject says what you did, and its body says why. Make one commit for each step, not one large commit at the end.
128
129## Updates
130
131They arrive as "[refs] Updates" in your context, through the hooks, or from \`refs_events\`.
132
133- **Another agent or a human pushed:** run \`git pull --rebase\` before your next push. Read the decision records in the new commits, and treat every decision that has not been superseded as a constraint. Do not record it again. If you disagree with one, record a new decision that supersedes it, with your reasons.
134- **The default branch moved:** a pull request merged, or someone pushed to it. Run \`git fetch origin\` and merge it into your branch before your next push. Do not rebase pushed commits: that needs a force-push. Read its decision records the same way.
135- **Instruction:** a human is directing you. Follow it.
136- **Mention:** a human or another agent wrote to you on a pull request or in one of its review threads. If it says a sub-agent is handling it, leave it to the sub-agent: you'll hear when it finishes. Otherwise answer with \`refs_reply\` and the mention's id. If the mention **assigned** you the pull request, you already hold its branch: call \`refs_take\` with that pull request for push access, do the whole job, report with \`refs_reply\`, and \`refs_release\`. Write \`@agent/<session>\` to mention another agent.
137- **Steer:** a mention in a review thread on one of your decisions. A human is redirecting you from that point. Answer in the thread with \`refs_reply\`. If you change course, push a commit whose decision record lists the steered decision in \`supersedes\`; that marks the thread addressed. If you keep the decision, say why in your reply.
138- **Stop:** your session has ended and your git token is revoked. Commit your work locally, do not push, and stop.
139- **While idle** you receive instructions, mentions and stop. Pushes reach you only while you work on a branch: pushes to that branch, and to the default branch.
140
141## AGENTS.md
142
143So that agents without the refs hooks know to connect, a repository can carry this section in its \`AGENTS.md\`:
144
145\`\`\`markdown
146${agentsSection({ origin, repo: "<namespace>/<repo>", branch: "<default branch>" }).trimEnd()}
147\`\`\`
148`;
149}
150
151export function loader({ request }: Route.LoaderArgs) {
152 return new Response(llmsTxt(new URL(request.url).origin), { headers: { "content-type": "text/plain; charset=utf-8", "cache-control": "public, max-age=300" } });
153}