An open-source, faster Devin alternative
TypeScript
computer: a Work tracking section in AGENTS.md for the knowledge repository
Igor Zalutski via Computerb39e5deb43fc
diff --git a/computer/README.md b/computer/README.mdindex 945fa472..409b5ac5 100644--- a/computer/README.md+++ b/computer/README.md@@ -426,6 +426,18 @@ then on. When a fork lacks some of the definition's repositories, its`AGENTS.md` gains a "Repositories in this workspace" index of all of them,using the optional `description`, `language` and `pushedAt` fields.+At most one repository may carry `"role": "knowledge"`: the organization's+knowledge repository, where work items live (`work/NN-slug.md`, closed ones+in `done/`). It is always cloned eagerly. Every fork's `AGENTS.md` gains a+"Work tracking" section naming it, with the conventions for items+(`src/workspaces/knowledge.ts`). On every sync the host installs the+`hooks/knowledge/` git hooks in its clone, and so in every session's+worktree of it; it removes them from any other clone. `prepare-commit-msg`+adds a `Session: <id>` trailer from `SP_SESSION_ID`. `pre-push` refuses a+push that gives two items one number, names the number to take instead, and+warns about malformed items. A hook of the same name that is not ours is+left in place and reported as a housekeeping problem.+A gateway may send the definition instead, in `welcome.definition` (anorganization's computer, work 052): the host validates it, keeps it in`<SP_DATA>/definition.json` and from then on uses it in place of@@ -443,6 +455,8 @@ git config --global credential.https://github.com.useHttpPath trueand put `bin/` first on runners' `PATH` for the `gh` shim (set `SP_REAL_GH` ifthe real `gh` is not on `PATH`). Runners need `SP_RUN` and `SP_SESSION_KEY`.+The agent's shell commands get `SP_SESSION_KEY` and `SP_SESSION_ID` (the+session's id, else its key) with the session's secrets, on both harnesses.## Configuration@@ -584,5 +598,6 @@ src/scripts/ `npm run check` helpers: file-size ratchet, import boundariesbin/ git credential helper and gh shim for hostsdefinitions/ workspace definitions (computer.json + its root AGENTS.md)+hooks/knowledge/ git hooks the host installs in the knowledge repository's clonedeploy/ gateway image entrypoint, VM provisioning, runbook```diff --git a/computer/src/workspaces/fork.ts b/computer/src/workspaces/fork.tsindex 5ab3d876..4af57272 100644--- a/computer/src/workspaces/fork.ts+++ b/computer/src/workspaces/fork.ts@@ -16,7 +16,8 @@ import { realpath } from 'node:fs/promises';import path from 'node:path';import { log } from '../log.js';import type { CheckoutResult, Person } from '../protocol.js';-import { isLazy, loadDefinition, type RepoDef, repoSlug } from './definition.js';+import { isKnowledge, isLazy, loadDefinition, type RepoDef, repoSlug } from './definition.js';+import { knowledgeSection } from './knowledge.js';import { repoIndex } from './repo-index.js';import { appendFile, mkdir, rm, touch, writeFile } from './as-runner.js';import {@@ -71,7 +72,11 @@ export async function forkSession(person: Person, sessionKey: string): Promise<sms: Date.now() - t0,repos: Object.fromEntries(forked.filter((f) => f !== undefined)),};- const index = repoIndex(def.repos, new Set(Object.keys(info.repos)));+ const here = new Set(Object.keys(info.repos));+ const knowledge = def.repos.find(isKnowledge);+ const tracking = knowledgeSection(def.repos, here, knowledge && info.repos[knowledge.name]?.from.replace(/^origin\//, ''));+ if (tracking) await appendFile(path.join(fork, 'AGENTS.md'), `\n${tracking}`);+ const index = repoIndex(def.repos, here);if (index) await appendFile(path.join(fork, 'AGENTS.md'), `\n${index}`);await writeFile(path.join(fork, FORK_FILE), JSON.stringify(info, null, 2) + '\n');const stale = Object.entries(info.repos).filter(([, r]) => r.fetchError);diff --git a/computer/src/workspaces/knowledge.test.ts b/computer/src/workspaces/knowledge.test.tsnew file mode 100644index 00000000..ab1b712f--- /dev/null+++ b/computer/src/workspaces/knowledge.test.ts@@ -0,0 +1,33 @@+import { describe, expect, it } from 'vitest';+import type { RepoDef } from './definition.js';+import { KNOWLEDGE_HEADING, knowledgeSection } from './knowledge.js';++const repo = (name: string, extra: Partial<RepoDef> = {}): RepoDef => ({ name, remote: `https://github.com/acme/${name}`, ...extra });++describe('knowledgeSection', () => {+ it('is omitted without a published knowledge repository', () => {+ expect(knowledgeSection([repo('api'), repo('web')], new Set(['api', 'web']))).toBeUndefined();+ expect(knowledgeSection([repo('notes', { role: 'knowledge', unpublished: true })], new Set(['notes']))).toBeUndefined();+ expect(knowledgeSection([], new Set())).toBeUndefined();+ });++ it('names the repository, where it is and its default branch', () => {+ const md = knowledgeSection([repo('api'), repo('notes', { role: 'knowledge' })], new Set(['api', 'notes']), 'trunk')!;+ expect(md.startsWith(`${KNOWLEDGE_HEADING}\n`)).toBe(true);+ expect(md).toContain("`notes` (acme/notes) is this organization's knowledge repository");+ expect(md).toContain('checked out here as `notes`');+ expect(md).toContain('git push origin HEAD:trunk');+ expect(md).toContain('`work/NN-slug.md`');+ expect(md).toContain('Never move an item to `done/`');+ expect(md).toContain('`Session:` trailer');+ expect(md).not.toContain('api');+ });++ it('points at checkout_repo when it is not checked out, and prefers the branch the definition names', () => {+ const md = knowledgeSection([repo('notes', { role: 'knowledge', branch: 'live' })], new Set(), 'trunk')!;+ expect(md).toContain('`checkout_repo`');+ expect(md).not.toContain('checked out here');+ expect(md).toContain('git pull --rebase origin live');+ expect(knowledgeSection([repo('notes', { role: 'knowledge' })], new Set())).toContain('HEAD:main');+ });+});diff --git a/computer/src/workspaces/knowledge.ts b/computer/src/workspaces/knowledge.tsnew file mode 100644index 00000000..6237bce9--- /dev/null+++ b/computer/src/workspaces/knowledge.ts@@ -0,0 +1,45 @@+// The work-tracking section of a fork's AGENTS.md (design 3.3): which+// repository is the organization's knowledge repository and the conventions+// for its items. Pure.+//+// Invariants: present only when the definition has a `role: "knowledge"`+// repository (definition.ts allows at most one); it comes from the release,+// never from the repository, so a session cannot rewrite what the next one is+// told about work tracking (design 5). The rules a hook enforces (the Session+// trailer, unique numbers) are stated as what happens, not asked of the agent.++import { isKnowledge, type RepoDef, repoSlug } from './definition.js';++export const KNOWLEDGE_HEADING = '## Work tracking';++/**+ * Markdown for the section, or undefined when the definition has no knowledge+ * repository. `branch`: its default branch as the clone knows it, when the+ * definition does not name one.+ */+export function knowledgeSection(repos: RepoDef[], checkedOut: Set<string>, branch?: string): string | undefined {+ const repo = repos.find((r) => isKnowledge(r) && !r.unpublished);+ if (!repo) return undefined;+ const dir = `\`${repo.name}\``;+ const main = repo.branch ?? branch ?? 'main';+ const lines = [+ KNOWLEDGE_HEADING,+ '',+ `${dir} (${repoSlug(repo.remote)}) is this organization's knowledge repository: its \`work/\` holds the open work items, ` ++ `\`done/\` the closed ones, and everything else in it is documents. ${checkedOut.has(repo.name) ? `It is checked out here as ${dir}.` : `Check it out with \`checkout_repo\` when you need it.`}`,+ '',+ `- It is the exception to "never push to a default branch": changes to it go straight to \`${main}\`, never through ` ++ `a pull request. \`git pull --rebase origin ${main}\`, edit, commit, \`git push origin HEAD:${main}\`; when the push ` ++ 'is refused, pull with rebase and push again. Push promptly: unpushed work is invisible to everyone else.',+ '- An item is `work/NN-slug.md`, about work that outlives this session. When a person asks to track something, or ' ++ 'your work will outlast this sitting, look for an existing item first and keep it current; otherwise create one ' ++ 'and say "Now tracked as NN". A new item takes one more than the highest number in `work/` and `done/` after a ' ++ 'fetch; the push is refused, with the number to take instead, if another session took it first.',+ '- The file: optional frontmatter `owner:` (one email) and `tags:` (comma-separated), a `# ` title, then one line on ' ++ 'where it stands. Pull requests on lines starting `PR:`. What is left as `- [ ]` checkboxes under `## Left`: keep ' ++ 'it true, and check items off as they are done.',+ '- Never move an item to `done/` unless a person tells you to; when nothing is left, say so and let its owner close it.',+ '- Commits get a `Session:` trailer on their own; it is how an item finds the sessions that worked on it. Keep it.',+ ];+ return `${lines.join('\n')}\n`;+}