An open-source, faster Devin alternative
TypeScript
computer: a workspace repository can be the knowledge repository
Igor Zalutski via Computer0ef4615b9716
diff --git a/computer/src/protocol-workspace.ts b/computer/src/protocol-workspace.tsindex fec98c32..167356a3 100644--- a/computer/src/protocol-workspace.ts+++ b/computer/src/protocol-workspace.ts@@ -21,6 +21,13 @@ export interface WorkspaceRepo {* when a session checks it out. No session ever waits on an eager clone.*/clone?: 'eager' | 'lazy';+ /**+ * `knowledge`: the organization's knowledge repository (work tracking, at+ * most one per definition). Always cloned eagerly whatever `clone` says; the+ * host installs its git hooks in the clone (knowledge-hooks.ts) and names it+ * in each fork's AGENTS.md (knowledge.ts).+ */+ role?: 'knowledge';/** For the repository index in a fork's AGENTS.md: GitHub's description, main language, last push (ISO). */description?: string;language?: string;diff --git a/computer/src/workspaces/definition.test.ts b/computer/src/workspaces/definition.test.tsindex 24faba02..1911b7df 100644--- a/computer/src/workspaces/definition.test.ts+++ b/computer/src/workspaces/definition.test.ts@@ -6,7 +6,7 @@ import { afterEach, beforeEach, describe, expect, it } from 'vitest';// HOST_DATA is read when protocol.ts loads, so SP_DATA must be set first.const data = mkdtempSync(path.join(os.tmpdir(), 'sp-def-'));process.env.SP_DATA = data;-const { definitionFile, gatewayDefinitionPath, loadDefinition, saveGatewayDefinition, validateDefinition, workspacesEnabled } = await import(+const { definitionFile, gatewayDefinitionPath, isLazy, loadDefinition, saveGatewayDefinition, validateDefinition, workspacesEnabled } = await import('./definition.js');@@ -50,6 +50,21 @@ describe('validateDefinition', () => {});});+ it('keeps the knowledge role, which is always eager', () => {+ const [k, other] = validateDefinition(+ {+ repos: [+ { name: 'notes', remote: 'https://github.com/o/notes', role: 'knowledge', clone: 'lazy' },+ { name: 'b', remote: 'https://github.com/o/b', clone: 'lazy' },+ ],+ },+ true,+ ).repos;+ expect(k).toEqual({ name: 'notes', remote: 'https://github.com/o/notes', clone: 'lazy', role: 'knowledge' });+ expect(isLazy(k)).toBe(false);+ expect(isLazy(other)).toBe(true);+ });+it.each([['not an object', null],['no repos', { name: 'x' }],@@ -57,6 +72,16 @@ describe('validateDefinition', () => {['duplicate name', { repos: [{ name: 'a', remote: 'https://github.com/o/a' }, { name: 'a', remote: 'https://github.com/o/b' }] }],['no remote', { repos: [{ name: 'a' }] }],['bad clone mode', { repos: [{ name: 'a', remote: 'https://github.com/o/a', clone: 'sometimes' }] }],+ ['bad role', { repos: [{ name: 'a', remote: 'https://github.com/o/a', role: 'notes' }] }],+ [+ 'a second knowledge repository',+ {+ repos: [+ { name: 'a', remote: 'https://github.com/o/a', role: 'knowledge' },+ { name: 'b', remote: 'https://github.com/o/b', role: 'knowledge' },+ ],+ },+ ],['non-string description', { repos: [{ name: 'a', remote: 'https://github.com/o/a', description: 3 }] }],['setup not a list', { repos: [{ name: 'a', remote: 'https://github.com/o/a', setup: 'make' }] }],['root file escaping the workspace', { repos: [], rootFiles: { '../x': 'a.md' } }],diff --git a/computer/src/workspaces/definition.ts b/computer/src/workspaces/definition.tsindex c6d2b9c4..d3812324 100644--- a/computer/src/workspaces/definition.ts+++ b/computer/src/workspaces/definition.ts@@ -60,8 +60,11 @@ export function repoSlug(remote: string) {return m ? `${m[1]}/${m[2]}` : remote;}+/** The organization's knowledge repository (work tracking): eager whatever its `clone` says. */+export const isKnowledge = (r: RepoDef) => r.role === 'knowledge';+/** Cloned only when a session checks it out (`checkout_repo`), never in the background. */-export const isLazy = (r: RepoDef) => r.clone === 'lazy';+export const isLazy = (r: RepoDef) => r.clone === 'lazy' && !isKnowledge(r);/** A relative path that stays inside its directory: no absolute paths, no `..`. */function contained(p: string) {@@ -82,6 +85,7 @@ export function validateDefinition(raw: unknown, gateway = false): WorkspaceDefiif (d.about !== undefined && typeof d.about !== 'string') fail('about is not a string');if (!Array.isArray(d.repos)) fail('repos is not an array');const seen = new Set<string>();+ let knowledge = 0;const repos = (d.repos as unknown[]).map((x): WorkspaceRepo => {const r = (x && typeof x === 'object' ? x : {}) as Record<string, unknown>;const what = `repo ${JSON.stringify(x)}`;@@ -96,6 +100,8 @@ export function validateDefinition(raw: unknown, gateway = false): WorkspaceDefiif (r.setup !== undefined && !(Array.isArray(r.setup) && r.setup.every((c) => typeof c === 'string'))) fail(`${what}: setup is not a list of commands`);if (r.unpublished !== undefined && typeof r.unpublished !== 'boolean') fail(`${what}: unpublished is not a boolean`);if (r.clone !== undefined && r.clone !== 'eager' && r.clone !== 'lazy') fail(`${what}: clone is not eager or lazy`);+ if (r.role !== undefined && r.role !== 'knowledge') fail(`${what}: role is not knowledge`);+ if (r.role === 'knowledge' && knowledge++) fail(`${what}: a second knowledge repository`);for (const k of ['description', 'language', 'pushedAt'] as const)if (r[k] !== undefined && typeof r[k] !== 'string') fail(`${what}: ${k} is not a string`);return {@@ -105,6 +111,7 @@ export function validateDefinition(raw: unknown, gateway = false): WorkspaceDefi...(r.setup !== undefined && { setup: r.setup as string[] }),...(r.unpublished !== undefined && { unpublished: r.unpublished as boolean }),...(r.clone !== undefined && { clone: r.clone as 'eager' | 'lazy' }),+ ...(r.role !== undefined && { role: r.role as 'knowledge' }),// Index text only, but it lands in AGENTS.md: one line, bounded....(typeof r.description === 'string' && r.description.trim() && { description: oneLine(r.description, 200) }),...(typeof r.language === 'string' && r.language.trim() && { language: oneLine(r.language, 40) }),diff --git a/services/managed-agents/src/computer/github.ts b/services/managed-agents/src/computer/github.tsindex 738901dd..5f6824e6 100644--- a/services/managed-agents/src/computer/github.ts+++ b/services/managed-agents/src/computer/github.ts@@ -95,15 +95,24 @@ export const EAGER_REPO_COUNT = 3;* the rest are `lazy`, cloned when a session checks them out. Description,* language and last push go to the repository index in each session's* AGENTS.md, so the model knows every repository without a clone.+ *+ * `knowledge` (`owner/name`, any case): the organization's knowledge+ * repository (work tracking, design 3.1), marked `role: "knowledge"`. It is+ * always listed and cloned eagerly, outside the cut and the eager count: the+ * host installs its hooks and every session's AGENTS.md names it.*/-export function workspaceDefinition(name: string, repositories: ComputerRepository[]): WorkspaceDefinition {- const byPush = repositories- .filter((repository) => !repository.archived && /^[^/]+\/[^/]+$/.test(repository.fullName))+export function workspaceDefinition(name: string, repositories: ComputerRepository[], knowledge?: string): WorkspaceDefinition {+ const isKnowledge = (repository: ComputerRepository) => !!knowledge && repository.fullName.toLowerCase() === knowledge.toLowerCase();+ const usable = repositories.filter((repository) => !repository.archived && /^[^/]+\/[^/]+$/.test(repository.fullName));+ const byPush = usable+ .filter((repository) => !isKnowledge(repository))// By push day, then name: the eager set and the cut stay put through a day of pushes (each change re-sends the definition)..sort((a, b) => pushDay(b).localeCompare(pushDay(a)) || a.fullName.localeCompare(b.fullName)).slice(0, DEFINITION_REPO_LIMIT);const eager = new Set(byPush.slice(0, EAGER_REPO_COUNT).map((repository) => repository.fullName));- const live = byPush.sort((a, b) => a.fullName.localeCompare(b.fullName));+ const chosen = usable.find(isKnowledge);+ if (chosen) eager.add(chosen.fullName);+ const live = [...byPush, ...(chosen ? [chosen] : [])].sort((a, b) => a.fullName.localeCompare(b.fullName));const counts = new Map<string, number>();for (const repository of live) {const repoName = repository.fullName.split("/")[1]!.toLowerCase();@@ -117,6 +126,7 @@ export function workspaceDefinition(name: string, repositories: ComputerRepositoremote: `https://github.com/${owner}/${repoName}`,...(repository.defaultBranch ? { branch: repository.defaultBranch } : {}),...(eager.has(repository.fullName) ? {} : { clone: "lazy" as const }),+ ...(repository === chosen ? { role: "knowledge" as const } : {}),...(repository.description ? { description: repository.description } : {}),...(repository.language ? { language: repository.language } : {}),// The day only: the definition changes (and the computer runs housekeeping) once a day per repository, not per push.diff --git a/services/managed-agents/src/computer/protocol.ts b/services/managed-agents/src/computer/protocol.tsindex c3566733..d25ceaca 100644--- a/services/managed-agents/src/computer/protocol.ts+++ b/services/managed-agents/src/computer/protocol.ts@@ -220,6 +220,13 @@ export interface WorkspaceRepo {* ignore it and the metadata below, which feeds the fork's repository index.*/clone?: "eager" | "lazy";+ /**+ * Work tracking: the organization's knowledge repository, at most one per+ * definition. The host clones it eagerly, installs its git hooks (Session+ * trailer, unique item numbers) and names it in each fork's AGENTS.md. Older+ * hosts ignore it and treat it as any other eager repository.+ */+ role?: "knowledge";description?: string;language?: string;pushedAt?: string;diff --git a/services/managed-agents/test/computer-units.test.ts b/services/managed-agents/test/computer-units.test.tsindex 91bba792..2e10d68d 100644--- a/services/managed-agents/test/computer-units.test.ts+++ b/services/managed-agents/test/computer-units.test.ts@@ -467,6 +467,32 @@ describe("GitHub for the computer", () => {const many = Array.from({ length: DEFINITION_REPO_LIMIT + 1 }, (_, i) => pushed(`o/r${i}`, i === 0 ? 1 : 2));expect(workspaceDefinition("organization", many).repos.map((r) => r.name)).not.toContain("r0");});++ it("marks the knowledge repository, eager and outside the cut", () => {+ const pushed = (fullName: string, day: number) => ({+ installationId: "x",+ fullName,+ defaultBranch: "main",+ archived: false,+ pushedAt: `2026-10-${String(day).padStart(2, "0")}T12:00:00Z`,+ });+ // The oldest push of all: without the role it would be cut and, kept, lazy.+ const many = [pushed("o/notes", 1), ...Array.from({ length: DEFINITION_REPO_LIMIT + 1 }, (_, i) => pushed(`o/r${i}`, 2))];+ const repos = workspaceDefinition("organization", many, "O/Notes").repos;+ expect(repos).toHaveLength(DEFINITION_REPO_LIMIT + 1);+ expect(repos.find((r) => r.name === "notes")).toEqual({+ name: "notes",+ remote: "https://github.com/o/notes",+ branch: "main",+ role: "knowledge",+ pushedAt: "2026-10-01",+ });+ expect(repos.filter((r) => r.role === "knowledge")).toHaveLength(1);+ expect(repos.filter((r) => r.clone !== "lazy")).toHaveLength(EAGER_REPO_COUNT + 1);+ // Without one, or naming a repository the connection does not reach, nothing is marked.+ expect(workspaceDefinition("organization", many).repos.some((r) => r.role)).toBe(false);+ expect(workspaceDefinition("organization", many, "o/elsewhere").repos.some((r) => r.role)).toBe(false);+ });});describe("idle park setting", () => {