Proposal mode: technical design¶
Storage¶
There is one git repository for each project:
<AF_HOME>/repos/<repoID>/
proposals/ the work tree: docs only
auth-rework/
goals.md technical.md api.md
search-v2/
goals.md
proposals.git/ the git dir (git init on first use)
proposals.lock flock for every write and commit
- Agents edit
proposals/with their own file tools, so af treats everything in it as untrusted: - The git dir and the lock live beside the work tree, never in it. Every
git command passes
--git-dirand--work-tree, so a.gitfolder orgitdir:file that an agent plants inproposals/is ignored. A.gitattributesthere cannot name a filter or diff driver, because drivers are defined only in config, and no config that git reads is in the work tree. As a second guard, every command pinscore.hooksPath,core.fsmonitorandcore.attributesFile, and diffs run with--no-ext-diff --no-textconv. - git never scans
proposals/. af reads each doc (<slug>/<name>.md) itself, writes it withhash-object --no-filters, and commits withupdate-index,write-tree,commit-treeandupdate-ref. A.gitignore,.gitattributesor nested repository in the folder cannot hide a doc, change it, or get into the history. Patches are made with--text. - af does not follow a symlink inside
proposals/. Each read and write opens the store, slug and doc through directory fds withO_NOFOLLOW, and a doc must be a regular file. -
Builds before this layout kept the git dir at
proposals/.git. On first use, af imports its history once intoproposals.git. It copies onlyobjects/(without alternates),refs/andpacked-refs, and it does not copy the config, hooks or attributes. If a symlink or special file is in those folders, the import stops. When the import is done, af deletes the old.git. -
<AF_HOME>isconfig.GetConfigDir().<repoID>is the project's ID. All worktrees of a repo share that ID (config.ResolveMainRepoRoot), so all sessions of a project see the same proposals. - A slug must match
^[a-z0-9][a-z0-9-]{0,62}$. A doc name must match the same pattern, and the file on disk gets a.mdextension. - The repository is internal state. Users do not see it, and it never gets a remote.
Templates¶
afembeds built-in templates:goals,technical,api,ui,stepsandfuture.futurelists what later features or additions may need, so that the current design does not block them.- The user can override a template, or add a new one, at
<AF_HOME>/templates/proposal/<name>.md. A user file overrides the built-in template that has the same name. - A template can use
{{title}}. This is the slug with dashes changed to spaces. Do not add other template features.
Commits and attribution¶
Every change goes into a commit. Each commit carries trailers:
- agent commits come from
af proposal checkpoint, which the calling session runs. - human commits come from Docs tab saves (step 2). The daemon knows that these writes come from the user.
- external commits snapshot changes that are on disk but not yet
committed, when the author is not known. For example, an edit in some other
editor.
changesandcheckpointboth take this snapshot first, before they do anything else.
Commits disable hooks and set a fixed committer identity, so the user's global git config cannot break them or change them.
Attachment and cursors¶
When a session is attached to a proposal, a ref exists in the proposals repo:
refs/af/cursor/<session id> → the last commit this session has seen
refs/af/attach/<session id> → a blob that holds the slug
refs/af/brief/<session id> → a blob that holds the slug and briefing state (owed|done|unconfirmed); only with deliver_rules
- A session is attached to at most one proposal. When it attaches to a second proposal, it detaches from the first.
changesreturns every commit between the cursor andHEADthat touches<slug>/and is not an agent commit by this session. Then it moves the cursor toHEAD.checkpointtakes the snapshot, commits the agent's own edits, and moves the cursor toHEAD. Thenchangesdoes not show the agent its own edits.
Limit of step 1¶
Before the Docs tab exists, user edits and agent edits both arrive as
uncommitted files on disk. Suppose the agent edits a file and does not run
checkpoint. Then the next snapshot records the agent's edit as external, and
changes shows the agent its own edit. This only adds noise; no edit is lost.
The rules that af prints tell the agent to run checkpoint after each round
of edits. From step 2, Docs tab saves commit as human immediately, so files
that are not committed come only from agents.
Session and project resolution¶
- Inside a session: commands use
resolveSelfSession()(api/sessions.go). The session record gives the session ID and the repo. - Outside a session:
list,path,catandwritefollow the shared project rules:--repofirst, then the current directory's project, and if there is neither, an error that asks for--repo. start,attach,detach,changesandcheckpointneed a session. A user in a normal shell can pass--session <title>.
Transport¶
- Step 1 read and wrote the local disk directly.
- Step 2 moves the store behind daemon HTTP routes (see
api.md). The CLI and the Docs tab both use them, so--daemon-urlworks. The daemon is the only process that writes the store.
Three-way merge (step 2)¶
A Docs tab save sends the new text together with the commit it started from.
If HEAD changed that file since that commit, the daemon runs
git merge-file with the base, theirs (HEAD) and ours (the save).
- The merge is clean: the daemon commits the result as
humanand sends the merged text back. - The merge has a conflict: the daemon does not commit. It sends both versions back, and the tab shows a conflict banner.
File watching (step 2)¶
The daemon checks the watched proposals in its existing poll loop. A proposal
is watched when a session is attached to it or has a Docs tab for it. For each
watched proposal, the daemon reads the folder and compares the mtime and size
of each doc with the last values it saw. A change publishes a
proposal.changed event on the existing events WebSocket, so open tabs reload
clean buffers immediately. For a buffer that has edits, the tab merges on its
next save.
- This uses no new dependency. A stat of a few files on each tick costs less than fsnotify, which needs a watch for each folder and its own goroutine.
- The check does not commit. The next read, save,
changesorcheckpointsnapshots the change as before. - The list of attachments is read again only when the attach refs change.
Code layout¶
proposal/is a new package for the store, templates, git operations, cursors and the rules text. It must not importdaemonorapp.api/proposals.goholds theaf proposalCobra commands.- The agent usage text in
session/systemprompt.gogets a short "Proposals" section. The plugins and the CLI reference are generated from it (scripts/gen-docs.sh).