Skip to content

An open-source, faster Devin alternative

TypeScript

CLI: build output out of the source tree; doctor and deploy say what they resolved

Igor Zalutski8bd10f961ecb
diff --git a/cli/README.md b/cli/README.md
index 16c52161..f7712e31 100644
--- a/cli/README.md
+++ b/cli/README.md
@@ -22,7 +22,10 @@ npm run deploy -- --watch
`opencomputer link --project <id|slug>` links an existing project;
`opencomputer link --create-project <name>` creates and links one. Later
commands reuse that local binding without prompting. An unlinked command fails
-with the exact link command needed to proceed.
+with the exact link command needed to proceed. `opencomputer doctor` and
+`opencomputer deploy` print the project they resolved and the cloud id each
+local agent deploys as before acting. Compiled bundles are cached under
+`node_modules/.cache/opencomputer/`, never inside `opencomputer/`.
The production cloud API (`https://app.opencomputer.dev`) is the default.
Override it only with `--api-url` or `OPENCOMPUTER_API_URL`.
diff --git a/cli/package-lock.json b/cli/package-lock.json
index dea6d87f..bd24d212 100644
--- a/cli/package-lock.json
+++ b/cli/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "@opencomputer/cli",
- "version": "0.7.5",
+ "version": "0.7.6",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@opencomputer/cli",
- "version": "0.7.5",
+ "version": "0.7.6",
"dependencies": {
"@opencode-ai/sdk": "1.18.4",
"ai": "^7.0.45",
diff --git a/cli/package.json b/cli/package.json
index 03741463..69d14e7f 100644
--- a/cli/package.json
+++ b/cli/package.json
@@ -1,6 +1,6 @@
{
"name": "@opencomputer/cli",
- "version": "0.7.5",
+ "version": "0.7.6",
"description": "Build, test, deploy, and share OpenComputer agents as code.",
"type": "module",
"bin": {
diff --git a/cli/src/binding.test.ts b/cli/src/binding.test.ts
index 1fe5fa94..17bd0c76 100644
--- a/cli/src/binding.test.ts
+++ b/cli/src/binding.test.ts
@@ -121,3 +121,23 @@ test("explicit project creation reuses the existing slug on retry", async () =>
await rm(root, { recursive: true, force: true });
}
});
+
+test("cloud agent ids and the resolution a command prints", async () => {
+ const { cloudAgentId, describeResolution } = await import("./binding.js");
+ const binding = {
+ version: 1 as const,
+ apiUrl: "https://app.opencomputer.dev",
+ projectId: "prj_1",
+ projectName: "Workbench",
+ agentId: "workbench",
+ };
+ assert.equal(cloudAgentId(binding, "worker", 0), "workbench");
+ assert.equal(cloudAgentId(binding, "reviewer", 1), "workbench--reviewer");
+ assert.equal(
+ describeResolution({ binding, localIds: ["worker", "reviewer"], alias: "development" }),
+ "Project: Workbench (prj_1) at https://app.opencomputer.dev, alias development\n" +
+ "Agent: worker -> workbench\n" +
+ "Agent: reviewer -> workbench--reviewer\n",
+ );
+ assert.match(describeResolution({ binding: null, localIds: ["worker"] }), /not linked/);
+});
diff --git a/cli/src/binding.ts b/cli/src/binding.ts
index 7bcf260e..af685d89 100644
--- a/cli/src/binding.ts
+++ b/cli/src/binding.ts
@@ -29,6 +29,61 @@ async function exists(path: string): Promise<boolean> {
}
}
+/** The cloud agent id a local agent deploys as: the bound id for the first, `<bound>--<local>` for the rest. */
+export function cloudAgentId(
+ binding: Pick<ProjectBinding, "agentId">,
+ localId: string,
+ index: number,
+): string {
+ return index === 0 ? binding.agentId : `${binding.agentId}--${localId}`;
+}
+
+/** The link this checkout carries, if any, read without an API origin check; for tools that only report it. */
+export async function readLinkedProject(
+ projectRoot: string,
+): Promise<ProjectBinding | null> {
+ try {
+ const value = JSON.parse(
+ await readFile(bindingPath(projectRoot), "utf8"),
+ ) as Partial<ProjectBinding>;
+ return value.version === 1 &&
+ typeof value.apiUrl === "string" &&
+ typeof value.projectId === "string" &&
+ typeof value.projectName === "string" &&
+ typeof value.agentId === "string"
+ ? (value as ProjectBinding)
+ : null;
+ } catch {
+ return null;
+ }
+}
+
+/**
+ * What a command resolved, printed before it acts: the project and where it
+ * lives, and each local agent with the cloud id it deploys as.
+ */
+export function describeResolution(input: {
+ binding: ProjectBinding | null;
+ localIds: readonly string[];
+ alias?: string;
+}): string {
+ const { binding, localIds, alias } = input;
+ if (!binding) {
+ return (
+ "Project: not linked. Run `opencomputer link --project <id|slug>` " +
+ "or `opencomputer link --create-project <name>`.\n"
+ );
+ }
+ const lines = [
+ `Project: ${binding.projectName} (${binding.projectId}) at ${binding.apiUrl}` +
+ (alias ? `, alias ${alias}` : ""),
+ ];
+ for (const [index, localId] of localIds.entries()) {
+ lines.push(`Agent: ${localId} -> ${cloudAgentId(binding, localId, index)}`);
+ }
+ return `${lines.join("\n")}\n`;
+}
+
export async function findOpenComputerProjectRoot(
agentRoot: string,
): Promise<string> {
diff --git a/cli/src/commands.ts b/cli/src/commands.ts
index 11e9c8c1..6d11b508 100644
--- a/cli/src/commands.ts
+++ b/cli/src/commands.ts
@@ -17,6 +17,7 @@ import {
runDeploymentWatch,
} from "./dev.js";
import {
+ describeResolution,
ensureProjectBinding,
findOpenComputerProjectRoot,
} from "./binding.js";
@@ -197,6 +198,17 @@ function printDoctor(result: DoctorResult, json: boolean): void {
` ${item.message}\n fix: ${item.hint}\n`,
);
}
+ const { project, agents } = result.resolution;
+ process.stdout.write(
+ project
+ ? `Project: ${project.name} (${project.id}) at ${project.apiUrl}\n`
+ : "Project: not linked. Run `opencomputer link --project <id|slug>` or `opencomputer link --create-project <name>`.\n",
+ );
+ for (const agent of agents) {
+ process.stdout.write(
+ `Agent: ${agent.localId}${agent.agentId ? ` -> ${agent.agentId}` : ""}\n`,
+ );
+ }
process.stdout.write(
`${result.ok ? "Doctor passed" : "Doctor failed"}: ${result.summary.errors} errors, ` +
`${result.summary.warnings} warnings in ${result.durationMs}ms.\n`,
@@ -1149,6 +1161,13 @@ export async function runCommand(
}
const alias = deploymentAlias(requestedAlias);
const binding = await ensureProjectBinding(client, config, root);
+ process.stderr.write(
+ describeResolution({
+ binding,
+ localIds: diagnosis.resolution.agents.map((agent) => agent.localId),
+ alias,
+ }),
+ );
const results = await publishProjectDeployment(
client,
root,
diff --git a/cli/src/dev.ts b/cli/src/dev.ts
index 369cac80..2feec0e2 100644
--- a/cli/src/dev.ts
+++ b/cli/src/dev.ts
@@ -7,6 +7,8 @@ import { resolve } from "node:path";
import type { OpenComputerClient } from "./api.js";
import type { ResolvedConfig } from "./config.js";
import {
+ cloudAgentId,
+ describeResolution,
ensureProjectBinding,
findOpenComputerProjectRoot,
type ProjectBinding,
@@ -79,13 +81,7 @@ async function registerBuiltDeployment(
return { built, deployment };
}
-export function cloudAgentId(
- binding: ProjectBinding,
- localId: string,
- index: number,
-) {
- return index === 0 ? binding.agentId : `${binding.agentId}--${localId}`;
-}
+export { cloudAgentId };
export async function publishProjectDevelopment(
client: Pick<OpenComputerClient, "registerDeployment">,
@@ -255,6 +251,15 @@ export async function runDeploymentWatch(
projectRoot,
options,
);
+ process.stdout.write(
+ describeResolution({
+ binding,
+ localIds: (await readProjectAgents(projectRoot)).map(
+ (agent) => agent.localId,
+ ),
+ alias: DEVELOPMENT_ALIAS,
+ }),
+ );
const gateway = await startGateway(config);
const stateDirectory = resolve(projectRoot, ".opencomputer");
const stateFile = resolve(stateDirectory, "dev.json");
diff --git a/cli/src/doctor.test.ts b/cli/src/doctor.test.ts
index 4805c5d6..236d0f1a 100644
--- a/cli/src/doctor.test.ts
+++ b/cli/src/doctor.test.ts
@@ -107,3 +107,57 @@ export default defineConnection({ id: "inline", origin: "https://api.example.com
await rm(root, { recursive: true, force: true });
}
});
+
+test("doctor scans only source and reports what the checkout resolves to", async () => {
+ const root = await mkdtemp(resolve(tmpdir(), "opencomputer-doctor-"));
+ try {
+ const initialized = await initializeAgentProject(root);
+ const tool = (name: string) =>
+ `import { defineTool } from "@opencomputer/agent";
+export const ${name} = defineTool({ name: "${name}", description: "Echo", async run({ input }) { return input; } });
+`;
+ await mkdir(resolve(initialized.agentRoot, "tools"), { recursive: true });
+ await writeFile(resolve(initialized.agentRoot, "tools", "echo.ts"), tool("echo"));
+ // Build output an earlier release wrote inside the source tree, a dependency, and a workspace:
+ // none of them is source, so none of them may count as a second declaration.
+ for (const directory of [
+ resolve(initialized.agentRoot, ".opencomputer", "runtime", "tools"),
+ resolve(initialized.agentRoot, "node_modules", "dep"),
+ resolve(initialized.agentRoot, "workspace", "tools"),
+ ]) {
+ await mkdir(directory, { recursive: true });
+ await writeFile(resolve(directory, "echo.ts"), tool("echo"));
+ }
+
+ let result = await doctorProject(root);
+ assert.deepEqual(
+ result.diagnostics.filter((diagnostic) =>
+ ["tool_name_duplicate", "tool_location_invalid"].includes(diagnostic.code),
+ ),
+ [],
+ );
+ assert.deepEqual(result.resolution, {
+ project: null,
+ agents: [{ localId: "hello-world", agentId: null }],
+ });
+
+ await mkdir(resolve(root, ".opencomputer"), { recursive: true });
+ await writeFile(
+ resolve(root, ".opencomputer", "project.json"),
+ JSON.stringify({
+ version: 1,
+ apiUrl: "https://app.opencomputer.dev",
+ projectId: "prj_1",
+ projectName: "Workbench",
+ agentId: "workbench",
+ }),
+ );
+ result = await doctorProject(root);
+ assert.deepEqual(result.resolution, {
+ project: { id: "prj_1", name: "Workbench", apiUrl: "https://app.opencomputer.dev" },
+ agents: [{ localId: "hello-world", agentId: "workbench" }],
+ });
+ } finally {
+ await rm(root, { recursive: true, force: true });
+ }
+});
diff --git a/cli/src/doctor.ts b/cli/src/doctor.ts
index 7da738ce..1a681ed0 100644
--- a/cli/src/doctor.ts
+++ b/cli/src/doctor.ts
@@ -2,8 +2,12 @@ import { access, readFile, readdir } from "node:fs/promises";
import { relative, resolve } from "node:path";
import ts from "typescript";
+import { cloudAgentId, readLinkedProject } from "./binding.js";
import { readProjectAgents, readProjectResources } from "./project.js";
+/** Directories that are never source: the CLI's own state and build output, dependencies, workspaces. */
+const NOT_SOURCE = new Set([".opencomputer", "node_modules", "workspace", ".git", "dist"]);
+
export interface DoctorDiagnostic {
code: string;
severity: "error" | "warning";
@@ -13,11 +17,18 @@ export interface DoctorDiagnostic {
hint: string;
}
+/** What the checkout resolves to: the linked project, if any, and each local agent's cloud id. */
+export interface DoctorResolution {
+ project: { id: string; name: string; apiUrl: string } | null;
+ agents: Array<{ localId: string; agentId: string | null }>;
+}
+
export interface DoctorResult {
ok: boolean;
durationMs: number;
diagnostics: DoctorDiagnostic[];
summary: { errors: number; warnings: number; files: number };
+ resolution: DoctorResolution;
}
async function exists(path: string): Promise<boolean> {
@@ -34,7 +45,10 @@ async function sourceFiles(directory: string): Promise<string[]> {
const files: string[] = [];
for (const entry of await readdir(directory, { withFileTypes: true })) {
const path = resolve(directory, entry.name);
- if (entry.isDirectory()) files.push(...(await sourceFiles(path)));
+ if (entry.isDirectory()) {
+ if (NOT_SOURCE.has(entry.name)) continue;
+ files.push(...(await sourceFiles(path)));
+ }
else if (entry.isFile() && /\.[cm]?[jt]sx?$/.test(entry.name)) files.push(path);
}
return files.sort();
@@ -207,8 +221,9 @@ export async function doctorProject(projectRoot: string): Promise<DoctorResult>
hint: "Give every tool in the project a unique literal name.",
});
}
+ let localIds: string[] = [];
try {
- await readProjectAgents(projectRoot);
+ localIds = (await readProjectAgents(projectRoot)).map((agent) => agent.localId);
await readProjectResources(projectRoot);
} catch (error) {
diagnostics.push({
@@ -249,6 +264,16 @@ export async function doctorProject(projectRoot: string): Promise<DoctorResult>
});
}
}
+ const linked = await readLinkedProject(projectRoot);
+ const resolution: DoctorResolution = {
+ project: linked
+ ? { id: linked.projectId, name: linked.projectName, apiUrl: linked.apiUrl }
+ : null,
+ agents: localIds.map((localId, index) => ({
+ localId,
+ agentId: linked ? cloudAgentId(linked, localId, index) : null,
+ })),
+ };
const errors = diagnostics.filter((item) => item.severity === "error").length;
const warnings = diagnostics.length - errors;
return {
@@ -256,5 +281,6 @@ export async function doctorProject(projectRoot: string): Promise<DoctorResult>
durationMs: Math.round((performance.now() - started) * 100) / 100,
diagnostics,
summary: { errors, warnings, files: files.length },
+ resolution,
};
}
diff --git a/cli/src/project.test.ts b/cli/src/project.test.ts
index e7a7b694..3f31ebb8 100644
--- a/cli/src/project.test.ts
+++ b/cli/src/project.test.ts
@@ -1,4 +1,5 @@
import assert from "node:assert/strict";
+import { existsSync } from "node:fs";
import {
mkdir,
mkdtemp,
@@ -16,6 +17,7 @@ import {
buildAgentArtifact,
findAgentRoot,
initializeAgentProject,
+ agentRuntimeDirectory,
prepareAgent,
readProjectResources,
} from "./project.js";
@@ -526,7 +528,7 @@ export default function Agent() {
// exactly how this shipped broken the first time. A syntax error here is
// invisible to tsc and only shows up at build or import.
const runtime = await import(
- `${pathToFileURL(resolve(initialized.agentRoot, ".opencomputer", "runtime", "opencomputer-agent.js")).href}?test=${crypto.randomUUID()}`
+ `${pathToFileURL(resolve(await agentRuntimeDirectory(initialized.agentRoot), "opencomputer-agent.js")).href}?test=${crypto.randomUUID()}`
);
assert.equal(typeof runtime.callService, "function");
@@ -783,7 +785,7 @@ export default function Agent() {
const built = await buildAgentArtifact(initialized.agentRoot);
await assert.doesNotReject(
import(
- `${pathToFileURL(resolve(initialized.agentRoot, ".opencomputer", "runtime", "opencomputer-agent.js")).href}?test=${crypto.randomUUID()}`
+ `${pathToFileURL(resolve(await agentRuntimeDirectory(initialized.agentRoot), "opencomputer-agent.js")).href}?test=${crypto.randomUUID()}`
),
);
assert.deepEqual(built.httpConnections, [
@@ -868,7 +870,7 @@ export default function Agent() {
]);
const manifest = JSON.parse(
await readFile(
- resolve(initialized.agentRoot, ".opencomputer", "runtime", ".opencomputer", "reactive.json"),
+ resolve(await agentRuntimeDirectory(initialized.agentRoot), ".opencomputer", "reactive.json"),
"utf8",
),
) as { githubConnections: unknown[] };
@@ -1528,7 +1530,7 @@ test("the compiler reads the result tool's output schema from a const in the mod
};
const manifestOf = async (agentRoot: string) =>
JSON.parse(
- await readFile(resolve(agentRoot, ".opencomputer", "runtime", ".opencomputer", "reactive.json"), "utf8"),
+ await readFile(resolve(await agentRuntimeDirectory(agentRoot), ".opencomputer", "reactive.json"), "utf8"),
) as { resultTool?: { id: string; output: Record<string, unknown> } };
try {
const initialized = await initializeAgentProject(root);
@@ -1681,7 +1683,7 @@ export default function Agent() {
assert.ok(artifact.files.some((file) => file.path === "agent.js"));
assert.ok(built.connections.includes("fixture-github"));
const packaged = await import(
- `${pathToFileURL(resolve(initialized.agentRoot, ".opencomputer", "runtime", "agent.js")).href}?test=${crypto.randomUUID()}`
+ `${pathToFileURL(resolve(await agentRuntimeDirectory(initialized.agentRoot), "agent.js")).href}?test=${crypto.randomUUID()}`
) as { default(): string };
assert.equal(
packaged.default(),
@@ -1936,7 +1938,7 @@ export default function Agent() {
const built = await buildAgentArtifact(initialized.agentRoot);
assert.deepEqual(built.memory, [KNOWLEDGE_DECLARATION, REQUIREMENTS_DECLARATION]);
assert.ok(built.connections.includes("memory-service"));
- const runtime = resolve(initialized.agentRoot, ".opencomputer", "runtime");
+ const runtime = await agentRuntimeDirectory(initialized.agentRoot);
const manifest = JSON.parse(
await readFile(resolve(runtime, ".opencomputer", "reactive.json"), "utf8"),
) as { memory: unknown; tools: string[] };
@@ -2440,7 +2442,7 @@ export default function Agent() {
`,
);
const built = await buildAgentArtifact(initialized.agentRoot);
- const runtime = resolve(initialized.agentRoot, ".opencomputer", "runtime");
+ const runtime = await agentRuntimeDirectory(initialized.agentRoot);
const module = (await import(
`${pathToFileURL(resolve(runtime, "agent.js")).href}?test=${crypto.randomUUID()}`
)) as Record<string, { kind: string; version: number; id: string; description: string; provider: unknown }>;
@@ -2523,3 +2525,19 @@ test("the CLI's memory contract is the agent package's module", async () => {
"cli/src/memory.ts must stay byte-identical to agent/src/memory.ts; the compiler, the runtime shim and @opencomputer/agent share it",
);
});
+
+test("prepareAgent builds into a cache under node_modules, never into the agent's source directory", async () => {
+ const root = await mkdtemp(resolve(tmpdir(), "opencomputer-runtime-"));
+ try {
+ const initialized = await initializeAgentProject(root);
+ const runtime = await prepareAgent(initialized.agentRoot);
+ assert.equal(
+ runtime,
+ resolve(root, "node_modules", ".cache", "opencomputer", "agents", "hello-world", "runtime"),
+ );
+ assert.equal(existsSync(resolve(initialized.agentRoot, ".opencomputer")), false);
+ assert.equal(existsSync(resolve(runtime, "AGENTS.md")), true);
+ } finally {
+ await rm(root, { recursive: true, force: true });
+ }
+});
diff --git a/cli/src/project.ts b/cli/src/project.ts
index 1b81e5eb..e91ab2ba 100644
--- a/cli/src/project.ts
+++ b/cli/src/project.ts
@@ -3396,8 +3396,39 @@ function compiledModulePath(path: string): string {
return path === "agent.ts" ? "agent.js" : path.replace(/\.[^.]+$/, ".js");
}
+/**
+ * Where an agent's compiled bundle goes: a cache under the app's
+ * `node_modules`, never inside the agent's source directory, so the source
+ * tree holds only what the user wrote and `doctor` never rescans a build.
+ * An agent outside an app (no `opencomputer/project.ts` above it) caches
+ * under its own directory.
+ */
+export async function agentRuntimeDirectory(agentRoot: string): Promise<string> {
+ const root = resolve(agentRoot);
+ let directory = root;
+ let projectRoot: string | undefined;
+ for (;;) {
+ if (await exists(resolve(directory, "opencomputer", "project.ts"))) {
+ projectRoot = directory;
+ break;
+ }
+ const parent = dirname(directory);
+ if (parent === directory) break;
+ directory = parent;
+ }
+ return resolve(
+ projectRoot ?? root,
+ "node_modules",
+ ".cache",
+ "opencomputer",
+ "agents",
+ basename(root),
+ "runtime",
+ );
+}
+
export async function prepareAgent(root: string): Promise<string> {
- const runtime = resolve(root, ".opencomputer", "runtime");
+ const runtime = await agentRuntimeDirectory(root);
await rm(runtime, { recursive: true, force: true });
await mkdir(runtime, { recursive: true });
const agentSource = await readFile(resolve(root, "agent.ts"), "utf8");
diff --git a/create-start/package.json b/create-start/package.json
index 9137f656..460b7106 100644
--- a/create-start/package.json
+++ b/create-start/package.json
@@ -1,6 +1,6 @@
{
"name": "@opencomputer/create-start",
- "version": "0.7.5",
+ "version": "0.7.6",
"description": "Create a hello-world OpenComputer agent application.",
"type": "module",
"bin": {
@@ -18,7 +18,7 @@
"node": ">=22.0.0"
},
"dependencies": {
- "@opencomputer/cli": "0.7.5"
+ "@opencomputer/cli": "0.7.6"
},
"publishConfig": {
"access": "public"
diff --git a/docs/agents/deployments.mdx b/docs/agents/deployments.mdx
index e1e11fb6..404bb228 100644
--- a/docs/agents/deployments.mdx
+++ b/docs/agents/deployments.mdx
@@ -26,8 +26,10 @@ npm run deploy -- --alias production
Every deploy first runs `opencomputer doctor`, a local static scan for invalid
connection origins, misplaced tools, inconsistent channel declarations, and
-missing secret declarations. Run `opencomputer doctor --json` directly to get
-structured diagnostics before invoking a deployment agent.
+missing secret declarations, and then prints the project it resolved and the
+cloud id each local agent deploys as. Run `opencomputer doctor --json` directly
+to get structured diagnostics, with the same resolution under `resolution`,
+before invoking a deployment agent.
The CLI builds the current source, creates an immutable deployment, and moves
the `production` alias to it. Development remains available for further work.
diff --git a/docs/agents/projects.mdx b/docs/agents/projects.mdx
index 758cfa37..00e371e8 100644
--- a/docs/agents/projects.mdx
+++ b/docs/agents/projects.mdx
@@ -33,7 +33,9 @@ my-agent/
- `opencomputer/channels/` and `opencomputer/outboxes/` define shared project
resources; registrations under an agent authorize that agent to use them.
- `opencomputer/.env.local` optionally holds ignored development secrets.
-- `.opencomputer/` is ignored local state created by the CLI.
+- `.opencomputer/project.json` records the linked cloud project; the CLI's
+ build output is cached under `node_modules/.cache/opencomputer/` and never
+ lands in `opencomputer/`.
Add source files only when the project uses them. The starter does not generate
placeholder capability directories.