A birth names a kernel and a config, and a later deploy builds the mind's own kernel
Misha Kaletsky, 2026-11-25 17:42 UTC · 33638e35a57f24a46567a09e30d54e7ef0ce6c49 · parent cb7627a
5 files changed
- M core/alchemy/src/config.ts
- M core/lib/src/cli/README.md
- M core/lib/src/cli/cli.ts
- M core/lib/src/cli/deploy.test.ts
- M core/lib/src/cli/deploy.ts
M core/alchemy/src/config.ts
@@ -36,17 +36,20 @@ /** Where the mind Worker runs: in the stack, or elsewhere, connecting in through the * boundary. */ topology: z.enum(["full-cloudflare", "external-mind-connects-into-cloudflare-boundary"]), - /** THE REPOS THE MIND IS BORN WITH, each directly under `/repos`. At its first wake the mind - * makes each one that it does not have yet: one with an `origin` is cloned from that public - * git URL, with its history, and one whose `origin` is null is made empty and gets its - * first commit by a push. A later deploy never touches a repo that exists. A template is - * this list: another start for a mind is another list. The stack also asks Cloudflare to - * tell the mind of every push to one of these repos. */ + /** THE REPOS THAT A DEPLOY NAMES FOR THE MIND, each directly under `/repos`: the kernel's + * and the one that holds the mind's code. At its first wake the mind makes each one that it + * does not have yet: one with an `origin` is cloned from that public git URL, with its + * history, and one whose `origin` is null is made empty and gets its first commit by a + * push. The mind's other repos are named by the entry repo's own package.json, and the mind + * clones those at its birth from beside the entry repo's origin. A later deploy never + * touches a repo that exists. The stack also asks Cloudflare to tell the mind of every push + * to one of the repos listed here; a push to any other reaches the mind through its own git + * app, which says so. */ repos: z .array(z.strictObject({ path: repoPath, origin: z.url().nullable() })) .min(1), /** THE MIND'S CODE: `module` of the repo `repo`, one of `repos`, answers every request, mail - * and event. Its relative imports may reach into the other repos, which sit beside it. */ + * and event. It names a file of another repo as `@repos/<repo>/<path>`. */ entry: z.strictObject({ repo: repoPath, module: z.string().min(1) }), alchemy: z.strictObject({ /** The Alchemy stage, and the middle of every resource's name: `iterate-<stageName>-auth`.
M core/lib/src/cli/README.md
@@ -145,17 +145,21 @@ - `mindId`: for a new mind, the id of the identity that the command makes right before the deploy ([The mind's identity key](#the-minds-identity-key)). A mind that is there already keeps its own. -7. **The kernel.** It comes from the same place as the new mind's repos: the kernel repo under - `--repos-from`, at its `main`. The mind clones that repo at birth, so the kernel that runs is - the commit that the mind's own `/repos/kernel` holds. The command fetches it into - `${XDG_CACHE_HOME:-~/.cache}/iterate/kernel` with git, sending no credential, and installs it - with pnpm (using local `pnpm` when its major version matches `packageManager`, otherwise - `npx --yes <packageManager>`), while you sign in. `--ref <branch>` takes another branch of - that repo. - `--source <folder>` deploys a checkout on this computer instead, whatever it holds: for - someone who works on the kernel, and for the mind that hosts the source, whose - `--repos-from none` names no mind to take a kernel from. The folder the command runs in is - never the kernel by itself. +7. **The kernel.** Which one a deploy builds: + - **A new mind:** the repo that `--kernel <address>` names, at its `main` (`--ref <branch>` + takes another branch). The mind clones the same repo at birth, so its own `/repos/kernel` + holds the commit that it runs. The command fetches it into + `${XDG_CACHE_HOME:-~/.cache}/iterate/kernel` with git, sending no credential. + - **A mind that is there:** its own `/repos/kernel`, read with the Cloudflare access the + command holds. Nothing is fetched from outside the mind. So a deploy for another reason + builds the same kernel again, and a new kernel arrives by a pull or a merge into that repo + first. `--kernel` and `--config` are refused here: they are for a birth. + - **`--source <folder>`:** a checkout on this computer, whatever it holds, over any mind. For + someone who works on the kernel, and for the mind that hosts the source. + + The folder the command runs in is never the kernel by itself. The kernel is installed with + pnpm (using local `pnpm` when its major version matches `packageManager`, otherwise + `npx --yes <packageManager>`). A source from before the one Alchemy script is refused, before anything changes. When the source holds `core/repos/onboarding`, the command builds the mind Worker with `ITERATE_SEED_REPOS` naming it, and one line says that a new mind starts with
M core/lib/src/cli/cli.ts
@@ -290,12 +290,18 @@ .describe( "Forward each mail to the mind there as it arrived, a verified destination address of the account's Email Routing; none stops it (default: none; for a mind that is there already: the one it has)", ), - reposFrom: z + kernel: z .string() .optional() .describe( - "Where a new mind's repos are cloned from: the address under which a mind serves its repos (https://git.<its domain>/repos); none starts the mind with empty repos, which get their code by pushes, and needs --source. The kernel that is deployed comes from the kernel repo there too (default: iterate's own repos; a mind that is there already keeps the repos it has)", + "For a new mind: the https address of the kernel repo, such as https://git.<a mind's domain>/repos/kernel. The deploy builds it, and the mind clones it at birth as its own /repos/kernel. Refused over a mind that is there, whose own /repos/kernel is what a deploy builds", ), + config: z + .string() + .optional() + .describe( + "For a new mind: the https address of the repo that its config starts as, such as https://git.<a mind's domain>/repos/config-template. The mind clones it at birth as its own /repos/config, and the repos that its package.json names from beside it. none starts the mind with empty repos, which get their code by pushes. Refused over a mind that is there", + ), traceSampling: z .string() .optional() @@ -322,12 +328,12 @@ .string() .optional() .describe( - "A checkout of iterate's kernel on this computer to deploy, whatever it holds (default: none; the kernel is fetched from the kernel repo under --repos-from)", + "A checkout of iterate's kernel on this computer to deploy, whatever it holds, over any mind (default: none; a new mind's kernel is the repo that --kernel names, and a mind that is there builds its own /repos/kernel)", ), ref: z .string() .optional() - .describe("A branch of that kernel repo to deploy (default: main)"), + .describe("A branch of the kernel repo to deploy (default: main)"), plan: z .boolean() .optional()
M core/lib/src/cli/deploy.test.ts
@@ -32,10 +32,10 @@ identityKeyLineOf, isColorEnabled, isInteractiveEnv, - kernelCheckout, - kernelOriginOf, + kernelPlanOf, mindConfigIn, onboardingUrlOf, + ownKernelRepo, parseExtraOwnerEmails, pickDomain, planArgsOf, @@ -105,17 +105,20 @@ ]); }); -/** The repos a new mind is born with: iterate's own, each cloned from the mind that hosts them. */ -const iteratesRepos = ["home", "kernel", "stdlib", "dash", "tasks", "git", "config"].map((name) => ({ - path: `/repos/${name}`, - // each from the repo of its own name, but the config, which starts as the template - origin: `https://git.mindlew.com/repos/${name === "config" ? "config-template" : name}`, -})); +/** The repos that a deploy names for a new mind: the kernel's and its config, each with where it + * comes from. */ +const iteratesRepos = [ + { path: "/repos/kernel", origin: "https://git.mindlew.com/repos/kernel" }, + { path: "/repos/config", origin: "https://git.mindlew.com/repos/config-template" }, +]; +/** What a person answers for a new mind, and the two addresses that its birth names. */ const answers = { accountId: "0".repeat(32), domain: "ada-labs.com", owner: "Ada@Example.org", + kernel: "https://git.mindlew.com/repos/kernel", + config: "https://git.mindlew.com/repos/config-template", }; test("a new mind's config is the script's one input but for its id: the zone whole, one owner, iterate.<zone>, and the stage from the zone", () => { @@ -159,40 +162,91 @@ expect(() => deployConfigOf({ ...answers, owner: undefined })).toThrow(/is an email address/); }); -test("a new mind's repos are cloned from the address that --repos-from names, its config from the template there, or start empty with none; anything else is refused", () => { - const reposOf = (reposFrom: string) => deployConfigOf({ ...answers, reposFrom }).repos; - expect(reposOf("https://git.ada-labs.com/repos/")).toContainEqual({ - path: "/repos/stdlib", - origin: "https://git.ada-labs.com/repos/stdlib", - }); - // a mind's config is its own: the new one starts as the template, never as that mind's config - expect(reposOf("https://git.ada-labs.com/repos/")).toContainEqual({ - path: "/repos/config", - origin: "https://git.ada-labs.com/repos/config-template", - }); - // the mind that hosts the source has nowhere to clone from: its repos get their code by pushes - expect(reposOf("none")).toContainEqual({ path: "/repos/stdlib", origin: null }); - expect(() => reposOf("somewhere")).toThrow("--repos-from somewhere is no address"); +test("a new mind's deploy names two repos, the kernel's and its config, each with the address it is cloned from; --config none starts the mind with empty repos", () => { + const reposOf = (flags: { kernel?: string; config?: string }) => + deployConfigOf({ accountId: "0".repeat(32), domain: "ada-labs.com", owner: "ada@example.org", ...flags }).repos; + + expect( + reposOf({ + kernel: "https://git.ada-labs.com/repos/kernel", + config: "https://git.ada-labs.com/repos/config-template/", + }), + ).toEqual([ + { path: "/repos/kernel", origin: "https://git.ada-labs.com/repos/kernel" }, + { path: "/repos/config", origin: "https://git.ada-labs.com/repos/config-template" }, + ]); + // the mind that hosts the source is deployed from a checkout, and its repos get their code by pushes + expect(reposOf({ config: "none" })).toEqual([ + { path: "/repos/kernel", origin: null }, + { path: "/repos/config", origin: null }, + ]); + expect(() => reposOf({ config: "somewhere" })).toThrow("--config somewhere is no address"); + expect(() => reposOf({ kernel: "git@ada-labs.com:kernel", config: "none" })).toThrow( + "--kernel git@ada-labs.com:kernel is no address", + ); + expect(() => reposOf({})).toThrow("A new mind needs --config"); }); -test("a deploy's kernel comes from where the new mind's repos come from: the kernel repo under --repos-from, iterate's own with no flag, and nowhere with none", () => { - expect(kernelOriginOf("https://git.ada-labs.com/repos/")).toBe( - "https://git.ada-labs.com/repos/kernel", +test("the kernel that a deploy builds: the checkout that --source names, the address that --kernel names for a new mind, and for a mind that is there its own kernel repo", () => { + const kernel = "https://git.ada-labs.com/repos/kernel"; + const newMind = { deployed: false, begunWith: null }; + const mindThatIs = { deployed: true, begunWith: kernel }; + + expect(kernelPlanOf({ source: "/work/kernel" }, newMind)).toEqual({ + kind: "checkout", + dir: "/work/kernel", + }); + expect(kernelPlanOf({ kernel, ref: "next" }, newMind)).toEqual({ + kind: "address", + origin: kernel, + ref: "next", + }); + // a deploy for any other reason builds what the mind's own kernel repo holds: nothing is fetched from outside + expect(kernelPlanOf({}, mindThatIs)).toEqual({ kind: "own", ref: "main" }); + // a deploy that stopped before the mind was there goes on with the kernel it named + expect(kernelPlanOf({}, { deployed: false, begunWith: kernel })).toEqual({ + kind: "address", + origin: kernel, + ref: "main", + }); + expect(() => kernelPlanOf({}, newMind)).toThrow( + "A new mind needs a kernel: --kernel with the address of a kernel repo, or --source with a checkout of one.", ); - expect(kernelOriginOf(undefined)).toBe("https://git.mindlew.com/repos/kernel"); - // the mind that hosts the source has no mind to take a kernel from: it is deployed with --source - expect(kernelOriginOf("none")).toBeNull(); - expect(() => kernelOriginOf("somewhere")).toThrow("--repos-from somewhere is no address"); + // the flags of a birth say where a new mind's repos come from: a mind that is there has its own + expect(() => kernelPlanOf({ kernel }, mindThatIs)).toThrow( + "--kernel is for a mind's birth. This mind has a kernel repo of its own: bring the change into /repos/kernel there, then deploy.", + ); + expect(() => kernelPlanOf({ config: "https://git.ada-labs.com/repos/config" }, mindThatIs)).toThrow( + "--config is for a mind's birth. This mind has a config repo of its own: change /repos/config there.", + ); + // a checkout is deployed over any mind: that is how a kernel is tried before it is in a repo + expect(kernelPlanOf({ source: "/work/kernel" }, mindThatIs)).toMatchObject({ kind: "checkout" }); }); -test("--source deploys a checkout on this computer as it is, and with --repos-from none and no --source there is no kernel to deploy", async () => { - const dir = mkdtempSync(join(tmpdir(), "deploy-")); - expect(await kernelCheckout({ source: dir, reposFrom: "none" })).toEqual({ - dir, - from: `the checkout ${dir}`, +test("a mind's own kernel repo is read with the Cloudflare access the deploy holds: its address, and a token that reads it for ten minutes", async () => { + const asked: string[] = []; + const cf = async (method: string, path: string, body?: unknown) => { + asked.push(`${method} ${path} ${JSON.stringify(body) || ""}`.trim()); + const result = path.endsWith("/tokens") + ? { plaintext: "art_v1_secret?expires=1795700000" } + : { remote: "https://abc.artifacts.cloudflare.net/git/iterate-ada-repos/repos--kernel.git" }; + return { status: 200, result, total: 0, error: "" }; + }; + + expect(await ownKernelRepo(cf, "0".repeat(32), "ada")).toEqual({ + origin: "https://abc.artifacts.cloudflare.net/git/iterate-ada-repos/repos--kernel.git", + authorization: "Bearer art_v1_secret?expires=1795700000", }); - await expect(kernelCheckout({ reposFrom: "none" })).rejects.toThrow( - "--repos-from none names no mind to take the kernel from: give a checkout of the kernel with --source.", + const namespace = `/accounts/${"0".repeat(32)}/artifacts/namespaces/iterate-ada-repos`; + expect(asked).toEqual([ + `GET ${namespace}/repos/repos--kernel`, + `POST ${namespace}/tokens {"repo":"repos--kernel","scope":"read","ttl":600}`, + ]); + + // a mind from before its kernel was a repo of its own: nothing to build + const none = async () => ({ status: 404, result: null, total: 0, error: "not found" }); + await expect(ownKernelRepo(none, "0".repeat(32), "ada")).rejects.toThrow( + "This mind has no /repos/kernel to build (not found). Give --source with a checkout of the kernel.", ); }); @@ -203,13 +257,15 @@ const next = upstream.commit("core/alchemy/alchemy.run.ts", "// the script on next"); const dir = join(mkdtempSync(join(tmpdir(), "deploy-")), "kernel"); const script = () => readFileSync(join(dir, "core/alchemy/alchemy.run.ts"), "utf8"); + // a repo that anyone may read: no credential goes with the fetch + const anyone = { origin: upstream.url, dir, authorization: null }; - expect(await fetchedKernel({ origin: upstream.url, ref: "main", dir })).toBe(main); + expect(await fetchedKernel({ ...anyone, ref: "main" })).toBe(main); expect(script()).toBe("// the script on main"); // the same folder takes the next kernel asked for - expect(await fetchedKernel({ origin: upstream.url, ref: "next", dir })).toBe(next); + expect(await fetchedKernel({ ...anyone, ref: "next" })).toBe(next); expect(script()).toBe("// the script on next"); - await expect(fetchedKernel({ origin: upstream.url, ref: "gone", dir })).rejects.toThrow( + await expect(fetchedKernel({ ...anyone, ref: "gone" })).rejects.toThrow( `The kernel could not be fetched from ${upstream.url} at gone`, ); }); @@ -230,7 +286,8 @@ controlPlaneHostname: "ada-labs.com", ownerEmails: ["ada@example.org", "charles@example.org"], topology: "external-mind-connects-into-cloudflare-boundary", - repos: iteratesRepos, + // a mind from before a deploy named its repos has the one repo that held its code + repos: [{ path: "/repos/config", origin: null }], entry: { repo: "/repos/config", module: "worker.ts" }, alchemy: { stageName: "ada" }, cloudflare: { accountId, zones: ["ada-labs.com", "ada.example"] }, @@ -1756,6 +1813,7 @@ domain: "ada-labs.com", owner: "cf@work.com", extraOwners: ["Personal@Gmail.com", "cf@work.com"], + config: "none", }); expect(config).toMatchObject({ ownerEmails: ["cf@work.com", "personal@gmail.com"] }); });
M core/lib/src/cli/deploy.ts
Not shown: the change is larger than this page shows. A clone has it.