Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ coverage
!.vscode/tasks.json
!.vscode/launch.json
*.code-workspace

.claude
5 changes: 4 additions & 1 deletion src/clients/wroom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,14 @@ export async function createRepository(config: {
domain: string;
name: string;
framework: string;
agent: string | undefined;
token: string | undefined;
host: string;
}): Promise<void> {
const { domain, name, framework, token, host } = config;
const { domain, name, framework, agent, token, host } = config;
const url = new URL("app/dashboard/repositories", getDashboardUrl(host));
url.searchParams.set("app", "cli");
if (agent) url.searchParams.set("agent", agent);
await request(url, {
method: "POST",
body: { domain, name, framework, plan: "personal" },
Expand Down
4 changes: 3 additions & 1 deletion src/commands/repo-create.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getAdapter } from "../adapters";
import { getHost, getToken } from "../auth";
import { checkIsDomainAvailable, createRepository } from "../clients/wroom";
import { detectAgent } from "../lib/ai";
import { CommandError, createCommand, type CommandConfig } from "../lib/command";
import { UnknownRequestError } from "../lib/request";

Expand Down Expand Up @@ -39,9 +40,10 @@ export async function createRepo(config: {

const adapter = await getAdapter().catch(() => undefined);
const framework = adapter?.id ?? "other";
const agent = await detectAgent();

try {
await createRepository({ domain, name: name ?? domain, framework, token, host });
await createRepository({ domain, name: name ?? domain, framework, agent, token, host });
} catch (error) {
if (error instanceof UnknownRequestError) {
const message = await error.text();
Expand Down
40 changes: 40 additions & 0 deletions src/lib/ai.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { exists } from "./file";

export async function detectAgent(): Promise<string | undefined> {
if (process.env.AI_AGENT) return process.env.AI_AGENT.toLowerCase();

if (process.env.CLAUDE_CODE_IS_COWORK === "1" || process.env.CLAUDE_CODE_IS_COWORK === "true") {
return "claude-cowork";
}
if (process.env.CLAUDECODE === "1" || process.env.CLAUDE_CODE) return "claude-code";
if (process.env.CODEX_CI === "1" || process.env.CODEX_SANDBOX || process.env.CODEX_THREAD_ID) {
return "codex";
}
if (process.env.CURSOR_AGENT === "1" || process.env.CURSOR_EXTENSION_HOST_ROLE === "agent-exec") {
return "cursor";
}
if (process.env.CLINE_ACTIVE === "true") return "cline";
if (process.env.ANTIGRAVITY_AGENT) return "antigravity";
if (process.env.AUGMENT_AGENT === "1") return "augment";
if (process.env.OPENCODE_CLIENT === "1") return "opencode";
if (process.env.GEMINI_CLI === "1") return "gemini-cli";
if (process.env.TRAE_AI_SHELL_ID) return "trae";
if (process.env.REPL_ID) return "replit";
if (
process.env.COPILOT_MODEL ||
process.env.COPILOT_ALLOW_ALL ||
process.env.COPILOT_GITHUB_TOKEN
) {
return "github-copilot";
}

const agent = process.env.AGENT?.toLowerCase();
if (agent === "goose" || agent === "amp") return agent;

if (process.platform === "linux") {
const isDevin = await exists(new URL("file:///opt/.devin"));
if (isDevin) return "devin";
}

if (process.env.IS_SANDBOX === "yes") return "unknown-sandbox";
}
Comment thread
angeloashmore marked this conversation as resolved.
5 changes: 5 additions & 0 deletions src/tracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as z from "zod/mini";
import type { Profile } from "./clients/user";

import { DEFAULT_PRISMIC_HOST, env } from "./env";
import { detectAgent } from "./lib/ai";
import { readJsonFile } from "./lib/file";
import { initSegment, trackEvent, trackIdentity } from "./lib/segment";
import { appendTrailingSlash } from "./lib/url";
Expand All @@ -13,13 +14,15 @@ const PROD_WRITE_KEY = "cGjidifKefYb6EPaGaqpt8rQXkv5TD6P";
const STAGING_WRITE_KEY = "Ng5oKJHCGpSWplZ9ymB7Pu7rm0sTDeiG";

let repository: string | undefined;
let agent: string | undefined;

export async function initTracking(config: { host: string }): Promise<void> {
if (env.TEST) return;
const { host } = config;
const enabled = await isTelemetryEnabled();
if (!enabled) return;
const writeKey = host === DEFAULT_PRISMIC_HOST ? PROD_WRITE_KEY : STAGING_WRITE_KEY;
agent = await detectAgent();
await initSegment({ writeKey });
}

Expand All @@ -39,6 +42,7 @@ export function trackCommandStart(command: string, config: { watch?: boolean } =
fullCommand: process.argv.join(" "),
repository,
watch,
agent,
},
groupId: repository ? { Repository: repository } : undefined,
});
Expand All @@ -58,6 +62,7 @@ export function trackCommandEnd(
repository,
watch,
error: errorMessage?.slice(0, 512),
agent,
},
groupId: repository ? { Repository: repository } : undefined,
});
Expand Down