-
Notifications
You must be signed in to change notification settings - Fork 488
Sandbox auto-provision: create/adopt Conway sandbox when sandboxId is empty #164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vladimirwashere
wants to merge
3
commits into
Conway-Research:main
Choose a base branch
from
vladimirwashere:my-changes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+390
−10
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { resolveSandboxPath, SANDBOX_HOME } from "../conway/paths.js"; | ||
|
|
||
| describe("resolveSandboxPath", () => { | ||
| it("resolves relative paths under sandbox home", () => { | ||
| expect(resolveSandboxPath("notes/todo.md")).toBe(`${SANDBOX_HOME}/notes/todo.md`); | ||
| }); | ||
|
|
||
| it("resolves tilde paths under sandbox home", () => { | ||
| expect(resolveSandboxPath("~/projects/app.py")).toBe(`${SANDBOX_HOME}/projects/app.py`); | ||
| }); | ||
|
|
||
| it("leaves absolute paths absolute", () => { | ||
| expect(resolveSandboxPath("/var/log/app.log")).toBe("/var/log/app.log"); | ||
| }); | ||
|
|
||
| it("normalizes dot and parent segments", () => { | ||
| expect(resolveSandboxPath("~/a/./b/../c.txt")).toBe(`${SANDBOX_HOME}/a/c.txt`); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| import fs from "fs"; | ||
| import os from "os"; | ||
| import path from "path"; | ||
| import { afterEach, describe, expect, it, vi } from "vitest"; | ||
| import { MockConwayClient } from "./mocks.js"; | ||
| import { ensureSandbox, syncStateToSandbox } from "../conway/sandbox-provision.js"; | ||
| import type { AutomatonConfig } from "../types.js"; | ||
| import { DEFAULT_CONFIG, DEFAULT_MODEL_STRATEGY_CONFIG, DEFAULT_SOUL_CONFIG, DEFAULT_TREASURY_POLICY } from "../types.js"; | ||
|
|
||
| function makeConfig(): AutomatonConfig { | ||
| return { | ||
| name: "GENESIS", | ||
| genesisPrompt: "test", | ||
| creatorAddress: "0x0000000000000000000000000000000000000001", | ||
| registeredWithConway: true, | ||
| sandboxId: "", | ||
| conwayApiUrl: "https://api.conway.tech", | ||
| conwayApiKey: "cnwy_k_test", | ||
| inferenceModel: "gpt-5.2", | ||
| maxTokensPerTurn: 4096, | ||
| heartbeatConfigPath: "~/.automaton/heartbeat.yml", | ||
| dbPath: "~/.automaton/state.db", | ||
| logLevel: "info", | ||
| walletAddress: "0x0000000000000000000000000000000000000002", | ||
| version: "0.1.0", | ||
| skillsDir: "~/.automaton/skills", | ||
| maxChildren: 3, | ||
| socialRelayUrl: DEFAULT_CONFIG.socialRelayUrl, | ||
| treasuryPolicy: DEFAULT_TREASURY_POLICY, | ||
| modelStrategy: DEFAULT_MODEL_STRATEGY_CONFIG, | ||
| soulConfig: DEFAULT_SOUL_CONFIG, | ||
| }; | ||
| } | ||
|
|
||
| describe("ensureSandbox", () => { | ||
| it("adopts an existing running sandbox", async () => { | ||
| const conway = new MockConwayClient(); | ||
| vi.spyOn(conway, "listSandboxes").mockResolvedValue([ | ||
| { | ||
| id: "stopped-one", | ||
| status: "stopped", | ||
| region: "us-east", | ||
| vcpu: 1, | ||
| memoryMb: 512, | ||
| diskGb: 5, | ||
| createdAt: "2026-01-01T00:00:00.000Z", | ||
| }, | ||
| { | ||
| id: "running-new", | ||
| status: "running", | ||
| region: "us-east", | ||
| vcpu: 1, | ||
| memoryMb: 512, | ||
| diskGb: 5, | ||
| createdAt: "2026-02-01T00:00:00.000Z", | ||
| }, | ||
| ]); | ||
| const createSpy = vi.spyOn(conway, "createSandbox"); | ||
|
|
||
| const selected = await ensureSandbox(conway, makeConfig()); | ||
|
|
||
| expect(selected.id).toBe("running-new"); | ||
| expect(createSpy).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("creates a new sandbox when none are running", async () => { | ||
| const conway = new MockConwayClient(); | ||
| vi.spyOn(conway, "listSandboxes").mockResolvedValue([]); | ||
| const createSpy = vi.spyOn(conway, "createSandbox"); | ||
|
|
||
| const created = await ensureSandbox(conway, makeConfig()); | ||
|
|
||
| expect(created.id).toBe("new-sandbox-id"); | ||
| expect(createSpy).toHaveBeenCalledOnce(); | ||
| }); | ||
| }); | ||
|
|
||
| describe("syncStateToSandbox", () => { | ||
| const tempDirs: string[] = []; | ||
|
|
||
| afterEach(() => { | ||
| for (const dir of tempDirs) { | ||
| fs.rmSync(dir, { recursive: true, force: true }); | ||
| } | ||
| tempDirs.length = 0; | ||
| }); | ||
|
|
||
| it("syncs allowed files and skill docs, excludes sensitive files", async () => { | ||
| const base = fs.mkdtempSync(path.join(os.tmpdir(), "automaton-sync-")); | ||
| tempDirs.push(base); | ||
| fs.mkdirSync(path.join(base, "skills", "research"), { recursive: true }); | ||
|
|
||
| fs.writeFileSync(path.join(base, "constitution.md"), "const"); | ||
| fs.writeFileSync(path.join(base, "SOUL.md"), "soul"); | ||
| fs.writeFileSync(path.join(base, "WORKLOG.md"), "worklog"); | ||
| fs.writeFileSync(path.join(base, "wallet.json"), "secret-wallet"); | ||
| fs.writeFileSync(path.join(base, "automaton.json"), "secret-config"); | ||
| fs.writeFileSync(path.join(base, "skills", "research", "SKILL.md"), "skill-doc"); | ||
|
|
||
| const conway = new MockConwayClient(); | ||
| await syncStateToSandbox(conway, { localAutomatonDir: base }); | ||
|
|
||
| expect(conway.files["/root/.automaton/constitution.md"]).toBe("const"); | ||
| expect(conway.files["/root/.automaton/SOUL.md"]).toBe("soul"); | ||
| expect(conway.files["/root/.automaton/WORKLOG.md"]).toBe("worklog"); | ||
| expect(conway.files["/root/.automaton/skills/research/SKILL.md"]).toBe("skill-doc"); | ||
| expect(conway.files["/root/.automaton/wallet.json"]).toBeUndefined(); | ||
| expect(conway.files["/root/.automaton/automaton.json"]).toBeUndefined(); | ||
| expect(conway.files["/root/.automaton/.gitignore"]).toContain("wallet.json"); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import { beforeEach, describe, expect, it, vi } from "vitest"; | ||
| import type { ConwayClient, ExecResult } from "../types.js"; | ||
|
|
||
| import { initStateRepo } from "../git/state-versioning.js"; | ||
|
|
||
| function makeConway(execResult: ExecResult): ConwayClient { | ||
| return { | ||
| exec: vi.fn(async () => execResult), | ||
| writeFile: vi.fn(async () => undefined), | ||
| readFile: vi.fn(async () => ""), | ||
| exposePort: vi.fn(async () => ({ port: 0, publicUrl: "", sandboxId: "" })), | ||
| removePort: vi.fn(async () => undefined), | ||
| createSandbox: vi.fn(async () => ({ | ||
| id: "s", | ||
| status: "running", | ||
| region: "us-east", | ||
| vcpu: 1, | ||
| memoryMb: 512, | ||
| diskGb: 5, | ||
| createdAt: new Date().toISOString(), | ||
| })), | ||
| deleteSandbox: vi.fn(async () => undefined), | ||
| listSandboxes: vi.fn(async () => []), | ||
| getCreditsBalance: vi.fn(async () => 0), | ||
| getCreditsPricing: vi.fn(async () => []), | ||
| transferCredits: vi.fn(async () => ({ transferId: "", status: "", toAddress: "", amountCents: 0 })), | ||
| searchDomains: vi.fn(async () => []), | ||
| registerDomain: vi.fn(async () => ({ domain: "", status: "" })), | ||
| listDnsRecords: vi.fn(async () => []), | ||
| addDnsRecord: vi.fn(async () => ({ id: "", type: "", host: "", value: "" })), | ||
| deleteDnsRecord: vi.fn(async () => undefined), | ||
| listModels: vi.fn(async () => []), | ||
| }; | ||
| } | ||
|
|
||
| describe("initStateRepo", () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| }); | ||
|
|
||
| it("uses provided repoPath when given", async () => { | ||
| const conway = makeConway({ stdout: "exists", stderr: "", exitCode: 0 }); | ||
|
|
||
| await initStateRepo(conway, "/root/.automaton"); | ||
|
|
||
| expect(conway.exec).toHaveBeenCalledWith( | ||
| 'test -d /root/.automaton/.git && echo "exists" || echo "nope"', | ||
| 5000, | ||
| ); | ||
| }); | ||
|
|
||
| it("falls back to local ~/.automaton when repoPath is omitted", async () => { | ||
| const prevHome = process.env.HOME; | ||
| process.env.HOME = "/home/tester"; | ||
| const conway = makeConway({ stdout: "exists", stderr: "", exitCode: 0 }); | ||
|
|
||
| try { | ||
| await initStateRepo(conway); | ||
| expect(conway.exec).toHaveBeenCalledWith( | ||
| 'test -d /home/tester/.automaton/.git && echo "exists" || echo "nope"', | ||
| 5000, | ||
| ); | ||
| } finally { | ||
| process.env.HOME = prevHome; | ||
| } | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /** | ||
| * Sandbox path resolution for Conway remote sandbox. | ||
| * Single source of truth for sandbox home and path normalization. | ||
| */ | ||
|
|
||
| import path from "path"; | ||
|
|
||
| /** Default home directory inside the Conway sandbox VM. */ | ||
| export const SANDBOX_HOME = "/root"; | ||
|
|
||
| /** State directory in the sandbox: /root/.automaton */ | ||
| export const SANDBOX_AUTOMATON_DIR = path.join(SANDBOX_HOME, ".automaton"); | ||
|
|
||
| /** | ||
| * Resolve a file path to an absolute path in the sandbox. | ||
| * - ~ or ~/... -> SANDBOX_HOME + rest | ||
| * - relative path -> SANDBOX_HOME + path | ||
| * - already absolute -> normalized | ||
| */ | ||
| export function resolveSandboxPath(filePath: string): string { | ||
| const trimmed = filePath.trim(); | ||
| if (trimmed.startsWith("~")) { | ||
| const rest = trimmed.slice(1).replace(/^\//, "") || ""; | ||
| return path.normalize(path.join(SANDBOX_HOME, rest)); | ||
| } | ||
| if (!path.isAbsolute(trimmed)) { | ||
| return path.normalize(path.join(SANDBOX_HOME, trimmed)); | ||
| } | ||
| return path.normalize(trimmed); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.