2026-03-08 16:43:34 +05:30
|
|
|
import path from "node:path";
|
|
|
|
|
import type {
|
|
|
|
|
AdapterEnvironmentCheck,
|
|
|
|
|
AdapterEnvironmentTestContext,
|
|
|
|
|
AdapterEnvironmentTestResult,
|
|
|
|
|
} from "@paperclipai/adapter-utils";
|
|
|
|
|
import {
|
|
|
|
|
asBoolean,
|
2026-03-14 21:36:05 -05:00
|
|
|
asNumber,
|
2026-03-08 16:43:34 +05:30
|
|
|
asString,
|
|
|
|
|
asStringArray,
|
|
|
|
|
ensurePathInEnv,
|
|
|
|
|
parseObject,
|
|
|
|
|
} from "@paperclipai/adapter-utils/server-utils";
|
Add dedicated environment settings page and test-in-environment (#4798)
## Thinking Path
> - Paperclip orchestrates AI agents for zero-human companies
> - Agents run inside environments (local, SSH, E2B sandbox)
> - Operators need to configure and manage these environments
> - But environment settings were buried inside the general company
settings page, making them hard to find
> - Additionally, when testing an agent from the configuration form, the
test always ran locally regardless of which environment was selected
> - This PR moves environments into a dedicated top-level company
settings section and wires the "Test Environment" button to run inside
the selected environment
> - The benefit is operators can find and manage environments more
easily, and the test button now validates the actual environment the
agent will use
## What Changed
- Added a dedicated `CompanyEnvironments` settings page with its own
route and sidebar entry
- Updated `CompanySettingsSidebar` and `CompanySettingsNav` to include
the new environments section
- Modified the agent test route (`POST /agents/:id/test`) to accept an
optional `environmentId` parameter
- Updated all adapter `test.ts` handlers to resolve and use the
specified execution target environment
- Added `resolveTestExecutionTarget` to `execution-target.ts` for remote
environment test resolution with cwd fallback
- Moved the "Test Environment" button and its feedback display into the
`NewAgent` page footer for better UX flow
## Verification
- `pnpm test` — all existing and new tests pass
- `pnpm typecheck` — clean
- Manual: navigate to Company Settings, confirm "Environments" appears
as a top-level section
- Manual: configure an agent with a non-local environment, click "Test
Environment", confirm the test runs inside that environment
## Risks
- Low risk. UI-only routing change for the settings page. The
test-in-environment change adds an optional parameter with a local
fallback, so existing behavior is preserved when no environment is
specified.
## Model Used
Codex GPT 5.4 high via Paperclip.
## Checklist
- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] If this change affects the UI, I have included before/after
screenshots
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] I will address all Greptile and reviewer comments before
requesting merge
2026-04-29 15:56:13 -07:00
|
|
|
import {
|
|
|
|
|
ensureAdapterExecutionTargetCommandResolvable,
|
|
|
|
|
ensureAdapterExecutionTargetDirectory,
|
|
|
|
|
runAdapterExecutionTargetProcess,
|
|
|
|
|
describeAdapterExecutionTarget,
|
|
|
|
|
resolveAdapterExecutionTargetCwd,
|
|
|
|
|
} from "@paperclipai/adapter-utils/execution-target";
|
2026-03-08 16:43:34 +05:30
|
|
|
import { DEFAULT_GEMINI_LOCAL_MODEL } from "../index.js";
|
2026-03-14 21:36:05 -05:00
|
|
|
import { detectGeminiAuthRequired, detectGeminiQuotaExhausted, parseGeminiJsonl } from "./parse.js";
|
2026-03-08 19:20:43 +05:30
|
|
|
import { firstNonEmptyLine } from "./utils.js";
|
2026-03-08 16:43:34 +05:30
|
|
|
|
|
|
|
|
function summarizeStatus(checks: AdapterEnvironmentCheck[]): AdapterEnvironmentTestResult["status"] {
|
|
|
|
|
if (checks.some((check) => check.level === "error")) return "fail";
|
|
|
|
|
if (checks.some((check) => check.level === "warn")) return "warn";
|
|
|
|
|
return "pass";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function isNonEmpty(value: unknown): value is string {
|
|
|
|
|
return typeof value === "string" && value.trim().length > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function commandLooksLike(command: string, expected: string): boolean {
|
|
|
|
|
const base = path.basename(command).toLowerCase();
|
|
|
|
|
return base === expected || base === `${expected}.cmd` || base === `${expected}.exe`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function summarizeProbeDetail(stdout: string, stderr: string, parsedError: string | null): string | null {
|
|
|
|
|
const raw = parsedError?.trim() || firstNonEmptyLine(stderr) || firstNonEmptyLine(stdout);
|
|
|
|
|
if (!raw) return null;
|
|
|
|
|
const clean = raw.replace(/\s+/g, " ").trim();
|
|
|
|
|
const max = 240;
|
|
|
|
|
return clean.length > max ? `${clean.slice(0, max - 1)}…` : clean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function testEnvironment(
|
|
|
|
|
ctx: AdapterEnvironmentTestContext,
|
|
|
|
|
): Promise<AdapterEnvironmentTestResult> {
|
|
|
|
|
const checks: AdapterEnvironmentCheck[] = [];
|
|
|
|
|
const config = parseObject(ctx.config);
|
|
|
|
|
const command = asString(config.command, "gemini");
|
Add dedicated environment settings page and test-in-environment (#4798)
## Thinking Path
> - Paperclip orchestrates AI agents for zero-human companies
> - Agents run inside environments (local, SSH, E2B sandbox)
> - Operators need to configure and manage these environments
> - But environment settings were buried inside the general company
settings page, making them hard to find
> - Additionally, when testing an agent from the configuration form, the
test always ran locally regardless of which environment was selected
> - This PR moves environments into a dedicated top-level company
settings section and wires the "Test Environment" button to run inside
the selected environment
> - The benefit is operators can find and manage environments more
easily, and the test button now validates the actual environment the
agent will use
## What Changed
- Added a dedicated `CompanyEnvironments` settings page with its own
route and sidebar entry
- Updated `CompanySettingsSidebar` and `CompanySettingsNav` to include
the new environments section
- Modified the agent test route (`POST /agents/:id/test`) to accept an
optional `environmentId` parameter
- Updated all adapter `test.ts` handlers to resolve and use the
specified execution target environment
- Added `resolveTestExecutionTarget` to `execution-target.ts` for remote
environment test resolution with cwd fallback
- Moved the "Test Environment" button and its feedback display into the
`NewAgent` page footer for better UX flow
## Verification
- `pnpm test` — all existing and new tests pass
- `pnpm typecheck` — clean
- Manual: navigate to Company Settings, confirm "Environments" appears
as a top-level section
- Manual: configure an agent with a non-local environment, click "Test
Environment", confirm the test runs inside that environment
## Risks
- Low risk. UI-only routing change for the settings page. The
test-in-environment change adds an optional parameter with a local
fallback, so existing behavior is preserved when no environment is
specified.
## Model Used
Codex GPT 5.4 high via Paperclip.
## Checklist
- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] If this change affects the UI, I have included before/after
screenshots
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] I will address all Greptile and reviewer comments before
requesting merge
2026-04-29 15:56:13 -07:00
|
|
|
const target = ctx.executionTarget ?? null;
|
|
|
|
|
const targetIsRemote = target?.kind === "remote";
|
|
|
|
|
const cwd = resolveAdapterExecutionTargetCwd(target, asString(config.cwd, ""), process.cwd());
|
|
|
|
|
const targetLabel = targetIsRemote
|
Add cursor sandbox support and fix SSH workspace sync (#4803)
## Thinking Path
> - Paperclip orchestrates AI agents for zero-human companies
> - Agents can run inside sandboxed environments like E2B, or on remote
hosts via SSH
> - The cursor adapter needs to resolve `cursor-agent` inside sandbox
environments where it's installed in `~/.local/bin`
> - But when using the default `agent` command on a sandbox target, the
adapter didn't know to look in `~/.local/bin/cursor-agent`, causing
"command not found" failures
> - Additionally, repeated SSH runs failed because `git checkout` during
workspace sync conflicted with leftover `.paperclip-runtime` files from
previous runs
> - This PR adds sandbox-aware command resolution for cursor and fixes
the SSH workspace sync conflict
> - The benefit is cursor works in E2B sandboxes out of the box, and
repeated SSH runs don't fail on workspace sync
## What Changed
- `cursor-local`: Added `prepareCursorSandboxCommand` — on sandbox
targets, reads the remote `$HOME`, prepends `~/.local/bin` to PATH, and
prefers `~/.local/bin/cursor-agent` when the default command is
requested; tightened the sandbox command probe to validate the binary
exists before launching; preserves explicit custom command overrides
- `adapter-utils/ssh.ts`: Added `--force` to git checkout in SSH
workspace sync to handle `.paperclip-runtime` untracked file conflicts
from previous runs
## Verification
- `pnpm test` — all existing and new tests pass, including cursor
sandbox probe, sandbox execution, and custom command override tests
- `pnpm typecheck` — clean
- Manual: configure an E2B environment, run a cursor-local task, verify
it resolves cursor-agent from the sandbox install path
## Risks
- Low-medium. The `--force` flag on git checkout could discard
uncommitted changes in the remote workspace, but the workspace is
managed by Paperclip and should not contain user edits.
## Model Used
Codex GPT 5.4 high via Paperclip.
## Checklist
- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [ ] If this change affects the UI, I have included before/after
screenshots
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] I will address all Greptile and reviewer comments before
requesting merge
2026-04-29 16:12:06 -07:00
|
|
|
? ctx.environmentName ?? describeAdapterExecutionTarget(target)
|
Add dedicated environment settings page and test-in-environment (#4798)
## Thinking Path
> - Paperclip orchestrates AI agents for zero-human companies
> - Agents run inside environments (local, SSH, E2B sandbox)
> - Operators need to configure and manage these environments
> - But environment settings were buried inside the general company
settings page, making them hard to find
> - Additionally, when testing an agent from the configuration form, the
test always ran locally regardless of which environment was selected
> - This PR moves environments into a dedicated top-level company
settings section and wires the "Test Environment" button to run inside
the selected environment
> - The benefit is operators can find and manage environments more
easily, and the test button now validates the actual environment the
agent will use
## What Changed
- Added a dedicated `CompanyEnvironments` settings page with its own
route and sidebar entry
- Updated `CompanySettingsSidebar` and `CompanySettingsNav` to include
the new environments section
- Modified the agent test route (`POST /agents/:id/test`) to accept an
optional `environmentId` parameter
- Updated all adapter `test.ts` handlers to resolve and use the
specified execution target environment
- Added `resolveTestExecutionTarget` to `execution-target.ts` for remote
environment test resolution with cwd fallback
- Moved the "Test Environment" button and its feedback display into the
`NewAgent` page footer for better UX flow
## Verification
- `pnpm test` — all existing and new tests pass
- `pnpm typecheck` — clean
- Manual: navigate to Company Settings, confirm "Environments" appears
as a top-level section
- Manual: configure an agent with a non-local environment, click "Test
Environment", confirm the test runs inside that environment
## Risks
- Low risk. UI-only routing change for the settings page. The
test-in-environment change adds an optional parameter with a local
fallback, so existing behavior is preserved when no environment is
specified.
## Model Used
Codex GPT 5.4 high via Paperclip.
## Checklist
- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] If this change affects the UI, I have included before/after
screenshots
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] I will address all Greptile and reviewer comments before
requesting merge
2026-04-29 15:56:13 -07:00
|
|
|
: null;
|
|
|
|
|
const runId = `gemini-envtest-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
|
|
|
|
|
|
|
|
if (targetLabel) {
|
|
|
|
|
checks.push({
|
|
|
|
|
code: "gemini_environment_target",
|
|
|
|
|
level: "info",
|
|
|
|
|
message: `Probing inside environment: ${targetLabel}`,
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-03-08 16:43:34 +05:30
|
|
|
|
|
|
|
|
try {
|
Add dedicated environment settings page and test-in-environment (#4798)
## Thinking Path
> - Paperclip orchestrates AI agents for zero-human companies
> - Agents run inside environments (local, SSH, E2B sandbox)
> - Operators need to configure and manage these environments
> - But environment settings were buried inside the general company
settings page, making them hard to find
> - Additionally, when testing an agent from the configuration form, the
test always ran locally regardless of which environment was selected
> - This PR moves environments into a dedicated top-level company
settings section and wires the "Test Environment" button to run inside
the selected environment
> - The benefit is operators can find and manage environments more
easily, and the test button now validates the actual environment the
agent will use
## What Changed
- Added a dedicated `CompanyEnvironments` settings page with its own
route and sidebar entry
- Updated `CompanySettingsSidebar` and `CompanySettingsNav` to include
the new environments section
- Modified the agent test route (`POST /agents/:id/test`) to accept an
optional `environmentId` parameter
- Updated all adapter `test.ts` handlers to resolve and use the
specified execution target environment
- Added `resolveTestExecutionTarget` to `execution-target.ts` for remote
environment test resolution with cwd fallback
- Moved the "Test Environment" button and its feedback display into the
`NewAgent` page footer for better UX flow
## Verification
- `pnpm test` — all existing and new tests pass
- `pnpm typecheck` — clean
- Manual: navigate to Company Settings, confirm "Environments" appears
as a top-level section
- Manual: configure an agent with a non-local environment, click "Test
Environment", confirm the test runs inside that environment
## Risks
- Low risk. UI-only routing change for the settings page. The
test-in-environment change adds an optional parameter with a local
fallback, so existing behavior is preserved when no environment is
specified.
## Model Used
Codex GPT 5.4 high via Paperclip.
## Checklist
- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] If this change affects the UI, I have included before/after
screenshots
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] I will address all Greptile and reviewer comments before
requesting merge
2026-04-29 15:56:13 -07:00
|
|
|
await ensureAdapterExecutionTargetDirectory(runId, target, cwd, {
|
|
|
|
|
cwd,
|
|
|
|
|
env: {},
|
|
|
|
|
createIfMissing: true,
|
|
|
|
|
});
|
2026-03-08 16:43:34 +05:30
|
|
|
checks.push({
|
|
|
|
|
code: "gemini_cwd_valid",
|
|
|
|
|
level: "info",
|
|
|
|
|
message: `Working directory is valid: ${cwd}`,
|
|
|
|
|
});
|
|
|
|
|
} catch (err) {
|
|
|
|
|
checks.push({
|
|
|
|
|
code: "gemini_cwd_invalid",
|
|
|
|
|
level: "error",
|
|
|
|
|
message: err instanceof Error ? err.message : "Invalid working directory",
|
|
|
|
|
detail: cwd,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const envConfig = parseObject(config.env);
|
|
|
|
|
const env: Record<string, string> = {};
|
|
|
|
|
for (const [key, value] of Object.entries(envConfig)) {
|
|
|
|
|
if (typeof value === "string") env[key] = value;
|
|
|
|
|
}
|
|
|
|
|
const runtimeEnv = ensurePathInEnv({ ...process.env, ...env });
|
|
|
|
|
try {
|
Add dedicated environment settings page and test-in-environment (#4798)
## Thinking Path
> - Paperclip orchestrates AI agents for zero-human companies
> - Agents run inside environments (local, SSH, E2B sandbox)
> - Operators need to configure and manage these environments
> - But environment settings were buried inside the general company
settings page, making them hard to find
> - Additionally, when testing an agent from the configuration form, the
test always ran locally regardless of which environment was selected
> - This PR moves environments into a dedicated top-level company
settings section and wires the "Test Environment" button to run inside
the selected environment
> - The benefit is operators can find and manage environments more
easily, and the test button now validates the actual environment the
agent will use
## What Changed
- Added a dedicated `CompanyEnvironments` settings page with its own
route and sidebar entry
- Updated `CompanySettingsSidebar` and `CompanySettingsNav` to include
the new environments section
- Modified the agent test route (`POST /agents/:id/test`) to accept an
optional `environmentId` parameter
- Updated all adapter `test.ts` handlers to resolve and use the
specified execution target environment
- Added `resolveTestExecutionTarget` to `execution-target.ts` for remote
environment test resolution with cwd fallback
- Moved the "Test Environment" button and its feedback display into the
`NewAgent` page footer for better UX flow
## Verification
- `pnpm test` — all existing and new tests pass
- `pnpm typecheck` — clean
- Manual: navigate to Company Settings, confirm "Environments" appears
as a top-level section
- Manual: configure an agent with a non-local environment, click "Test
Environment", confirm the test runs inside that environment
## Risks
- Low risk. UI-only routing change for the settings page. The
test-in-environment change adds an optional parameter with a local
fallback, so existing behavior is preserved when no environment is
specified.
## Model Used
Codex GPT 5.4 high via Paperclip.
## Checklist
- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] If this change affects the UI, I have included before/after
screenshots
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] I will address all Greptile and reviewer comments before
requesting merge
2026-04-29 15:56:13 -07:00
|
|
|
await ensureAdapterExecutionTargetCommandResolvable(command, target, cwd, runtimeEnv);
|
2026-03-08 16:43:34 +05:30
|
|
|
checks.push({
|
|
|
|
|
code: "gemini_command_resolvable",
|
|
|
|
|
level: "info",
|
|
|
|
|
message: `Command is executable: ${command}`,
|
|
|
|
|
});
|
|
|
|
|
} catch (err) {
|
|
|
|
|
checks.push({
|
|
|
|
|
code: "gemini_command_unresolvable",
|
|
|
|
|
level: "error",
|
|
|
|
|
message: err instanceof Error ? err.message : "Command is not executable",
|
|
|
|
|
detail: command,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const configGeminiApiKey = env.GEMINI_API_KEY;
|
Add dedicated environment settings page and test-in-environment (#4798)
## Thinking Path
> - Paperclip orchestrates AI agents for zero-human companies
> - Agents run inside environments (local, SSH, E2B sandbox)
> - Operators need to configure and manage these environments
> - But environment settings were buried inside the general company
settings page, making them hard to find
> - Additionally, when testing an agent from the configuration form, the
test always ran locally regardless of which environment was selected
> - This PR moves environments into a dedicated top-level company
settings section and wires the "Test Environment" button to run inside
the selected environment
> - The benefit is operators can find and manage environments more
easily, and the test button now validates the actual environment the
agent will use
## What Changed
- Added a dedicated `CompanyEnvironments` settings page with its own
route and sidebar entry
- Updated `CompanySettingsSidebar` and `CompanySettingsNav` to include
the new environments section
- Modified the agent test route (`POST /agents/:id/test`) to accept an
optional `environmentId` parameter
- Updated all adapter `test.ts` handlers to resolve and use the
specified execution target environment
- Added `resolveTestExecutionTarget` to `execution-target.ts` for remote
environment test resolution with cwd fallback
- Moved the "Test Environment" button and its feedback display into the
`NewAgent` page footer for better UX flow
## Verification
- `pnpm test` — all existing and new tests pass
- `pnpm typecheck` — clean
- Manual: navigate to Company Settings, confirm "Environments" appears
as a top-level section
- Manual: configure an agent with a non-local environment, click "Test
Environment", confirm the test runs inside that environment
## Risks
- Low risk. UI-only routing change for the settings page. The
test-in-environment change adds an optional parameter with a local
fallback, so existing behavior is preserved when no environment is
specified.
## Model Used
Codex GPT 5.4 high via Paperclip.
## Checklist
- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] If this change affects the UI, I have included before/after
screenshots
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] I will address all Greptile and reviewer comments before
requesting merge
2026-04-29 15:56:13 -07:00
|
|
|
const hostGeminiApiKey = targetIsRemote ? undefined : process.env.GEMINI_API_KEY;
|
2026-03-08 16:43:34 +05:30
|
|
|
const configGoogleApiKey = env.GOOGLE_API_KEY;
|
Add dedicated environment settings page and test-in-environment (#4798)
## Thinking Path
> - Paperclip orchestrates AI agents for zero-human companies
> - Agents run inside environments (local, SSH, E2B sandbox)
> - Operators need to configure and manage these environments
> - But environment settings were buried inside the general company
settings page, making them hard to find
> - Additionally, when testing an agent from the configuration form, the
test always ran locally regardless of which environment was selected
> - This PR moves environments into a dedicated top-level company
settings section and wires the "Test Environment" button to run inside
the selected environment
> - The benefit is operators can find and manage environments more
easily, and the test button now validates the actual environment the
agent will use
## What Changed
- Added a dedicated `CompanyEnvironments` settings page with its own
route and sidebar entry
- Updated `CompanySettingsSidebar` and `CompanySettingsNav` to include
the new environments section
- Modified the agent test route (`POST /agents/:id/test`) to accept an
optional `environmentId` parameter
- Updated all adapter `test.ts` handlers to resolve and use the
specified execution target environment
- Added `resolveTestExecutionTarget` to `execution-target.ts` for remote
environment test resolution with cwd fallback
- Moved the "Test Environment" button and its feedback display into the
`NewAgent` page footer for better UX flow
## Verification
- `pnpm test` — all existing and new tests pass
- `pnpm typecheck` — clean
- Manual: navigate to Company Settings, confirm "Environments" appears
as a top-level section
- Manual: configure an agent with a non-local environment, click "Test
Environment", confirm the test runs inside that environment
## Risks
- Low risk. UI-only routing change for the settings page. The
test-in-environment change adds an optional parameter with a local
fallback, so existing behavior is preserved when no environment is
specified.
## Model Used
Codex GPT 5.4 high via Paperclip.
## Checklist
- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] If this change affects the UI, I have included before/after
screenshots
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] I will address all Greptile and reviewer comments before
requesting merge
2026-04-29 15:56:13 -07:00
|
|
|
const hostGoogleApiKey = targetIsRemote ? undefined : process.env.GOOGLE_API_KEY;
|
|
|
|
|
const hasGca = env.GOOGLE_GENAI_USE_GCA === "true" || (!targetIsRemote && process.env.GOOGLE_GENAI_USE_GCA === "true");
|
2026-03-08 16:43:34 +05:30
|
|
|
if (
|
|
|
|
|
isNonEmpty(configGeminiApiKey) ||
|
|
|
|
|
isNonEmpty(hostGeminiApiKey) ||
|
|
|
|
|
isNonEmpty(configGoogleApiKey) ||
|
2026-03-09 15:16:15 +00:00
|
|
|
isNonEmpty(hostGoogleApiKey) ||
|
|
|
|
|
hasGca
|
2026-03-08 16:43:34 +05:30
|
|
|
) {
|
2026-03-09 15:16:15 +00:00
|
|
|
const source = hasGca
|
|
|
|
|
? "Google account login (GCA)"
|
|
|
|
|
: isNonEmpty(configGeminiApiKey) || isNonEmpty(configGoogleApiKey)
|
|
|
|
|
? "adapter config env"
|
|
|
|
|
: "server environment";
|
2026-03-08 16:43:34 +05:30
|
|
|
checks.push({
|
|
|
|
|
code: "gemini_api_key_present",
|
|
|
|
|
level: "info",
|
|
|
|
|
message: "Gemini API credentials are set for CLI authentication.",
|
|
|
|
|
detail: `Detected in ${source}.`,
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
checks.push({
|
|
|
|
|
code: "gemini_api_key_missing",
|
2026-03-09 17:31:38 +00:00
|
|
|
level: "info",
|
|
|
|
|
message: "No explicit API key detected. Gemini CLI may still authenticate via `gemini auth login` (OAuth).",
|
|
|
|
|
hint: "If the hello probe fails with an auth error, set GEMINI_API_KEY or GOOGLE_API_KEY in adapter env, or run `gemini auth login`.",
|
2026-03-08 16:43:34 +05:30
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const canRunProbe =
|
|
|
|
|
checks.every((check) => check.code !== "gemini_cwd_invalid" && check.code !== "gemini_command_unresolvable");
|
|
|
|
|
if (canRunProbe) {
|
|
|
|
|
if (!commandLooksLike(command, "gemini")) {
|
|
|
|
|
checks.push({
|
|
|
|
|
code: "gemini_hello_probe_skipped_custom_command",
|
|
|
|
|
level: "info",
|
|
|
|
|
message: "Skipped hello probe because command is not `gemini`.",
|
|
|
|
|
detail: command,
|
|
|
|
|
hint: "Use the `gemini` CLI command to run the automatic installation and auth probe.",
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
const model = asString(config.model, DEFAULT_GEMINI_LOCAL_MODEL).trim();
|
2026-03-10 01:15:20 +00:00
|
|
|
const approvalMode = asString(config.approvalMode, asBoolean(config.yolo, false) ? "yolo" : "default");
|
|
|
|
|
const sandbox = asBoolean(config.sandbox, false);
|
2026-03-14 21:36:05 -05:00
|
|
|
const helloProbeTimeoutSec = Math.max(1, asNumber(config.helloProbeTimeoutSec, 10));
|
2026-03-08 16:43:34 +05:30
|
|
|
const extraArgs = (() => {
|
|
|
|
|
const fromExtraArgs = asStringArray(config.extraArgs);
|
|
|
|
|
if (fromExtraArgs.length > 0) return fromExtraArgs;
|
|
|
|
|
return asStringArray(config.args);
|
|
|
|
|
})();
|
|
|
|
|
|
2026-03-14 21:36:05 -05:00
|
|
|
const args = ["--output-format", "stream-json", "--prompt", "Respond with hello."];
|
2026-03-08 16:43:34 +05:30
|
|
|
if (model && model !== DEFAULT_GEMINI_LOCAL_MODEL) args.push("--model", model);
|
2026-03-10 01:15:20 +00:00
|
|
|
if (approvalMode !== "default") args.push("--approval-mode", approvalMode);
|
|
|
|
|
if (sandbox) {
|
|
|
|
|
args.push("--sandbox");
|
|
|
|
|
} else {
|
|
|
|
|
args.push("--sandbox=none");
|
|
|
|
|
}
|
2026-03-08 16:43:34 +05:30
|
|
|
if (extraArgs.length > 0) args.push(...extraArgs);
|
|
|
|
|
|
Add dedicated environment settings page and test-in-environment (#4798)
## Thinking Path
> - Paperclip orchestrates AI agents for zero-human companies
> - Agents run inside environments (local, SSH, E2B sandbox)
> - Operators need to configure and manage these environments
> - But environment settings were buried inside the general company
settings page, making them hard to find
> - Additionally, when testing an agent from the configuration form, the
test always ran locally regardless of which environment was selected
> - This PR moves environments into a dedicated top-level company
settings section and wires the "Test Environment" button to run inside
the selected environment
> - The benefit is operators can find and manage environments more
easily, and the test button now validates the actual environment the
agent will use
## What Changed
- Added a dedicated `CompanyEnvironments` settings page with its own
route and sidebar entry
- Updated `CompanySettingsSidebar` and `CompanySettingsNav` to include
the new environments section
- Modified the agent test route (`POST /agents/:id/test`) to accept an
optional `environmentId` parameter
- Updated all adapter `test.ts` handlers to resolve and use the
specified execution target environment
- Added `resolveTestExecutionTarget` to `execution-target.ts` for remote
environment test resolution with cwd fallback
- Moved the "Test Environment" button and its feedback display into the
`NewAgent` page footer for better UX flow
## Verification
- `pnpm test` — all existing and new tests pass
- `pnpm typecheck` — clean
- Manual: navigate to Company Settings, confirm "Environments" appears
as a top-level section
- Manual: configure an agent with a non-local environment, click "Test
Environment", confirm the test runs inside that environment
## Risks
- Low risk. UI-only routing change for the settings page. The
test-in-environment change adds an optional parameter with a local
fallback, so existing behavior is preserved when no environment is
specified.
## Model Used
Codex GPT 5.4 high via Paperclip.
## Checklist
- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] If this change affects the UI, I have included before/after
screenshots
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] I will address all Greptile and reviewer comments before
requesting merge
2026-04-29 15:56:13 -07:00
|
|
|
const probe = await runAdapterExecutionTargetProcess(
|
|
|
|
|
runId,
|
|
|
|
|
target,
|
2026-03-08 16:43:34 +05:30
|
|
|
command,
|
|
|
|
|
args,
|
|
|
|
|
{
|
|
|
|
|
cwd,
|
|
|
|
|
env,
|
2026-03-14 21:36:05 -05:00
|
|
|
timeoutSec: helloProbeTimeoutSec,
|
2026-03-08 16:43:34 +05:30
|
|
|
graceSec: 5,
|
2026-03-08 19:20:43 +05:30
|
|
|
onLog: async () => { },
|
2026-03-08 16:43:34 +05:30
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
const parsed = parseGeminiJsonl(probe.stdout);
|
|
|
|
|
const detail = summarizeProbeDetail(probe.stdout, probe.stderr, parsed.errorMessage);
|
2026-03-09 15:16:15 +00:00
|
|
|
const authMeta = detectGeminiAuthRequired({
|
|
|
|
|
parsed: parsed.resultEvent,
|
|
|
|
|
stdout: probe.stdout,
|
|
|
|
|
stderr: probe.stderr,
|
|
|
|
|
});
|
2026-03-14 21:36:05 -05:00
|
|
|
const quotaMeta = detectGeminiQuotaExhausted({
|
|
|
|
|
parsed: parsed.resultEvent,
|
|
|
|
|
stdout: probe.stdout,
|
|
|
|
|
stderr: probe.stderr,
|
|
|
|
|
});
|
2026-03-08 16:43:34 +05:30
|
|
|
|
2026-03-14 21:36:05 -05:00
|
|
|
if (quotaMeta.exhausted) {
|
|
|
|
|
checks.push({
|
|
|
|
|
code: "gemini_hello_probe_quota_exhausted",
|
|
|
|
|
level: "warn",
|
|
|
|
|
message: probe.timedOut
|
|
|
|
|
? "Gemini CLI is retrying after quota exhaustion."
|
|
|
|
|
: "Gemini CLI authentication is configured, but the current account or API key is over quota.",
|
|
|
|
|
...(detail ? { detail } : {}),
|
|
|
|
|
hint: "The configured Gemini account or API key is over quota. Check ai.google.dev usage/billing, then retry the probe.",
|
|
|
|
|
});
|
|
|
|
|
} else if (probe.timedOut) {
|
2026-03-08 16:43:34 +05:30
|
|
|
checks.push({
|
|
|
|
|
code: "gemini_hello_probe_timed_out",
|
|
|
|
|
level: "warn",
|
|
|
|
|
message: "Gemini hello probe timed out.",
|
|
|
|
|
hint: "Retry the probe. If this persists, verify Gemini can run `Respond with hello.` from this directory manually.",
|
|
|
|
|
});
|
|
|
|
|
} else if ((probe.exitCode ?? 1) === 0) {
|
|
|
|
|
const summary = parsed.summary.trim();
|
|
|
|
|
const hasHello = /\bhello\b/i.test(summary);
|
|
|
|
|
checks.push({
|
|
|
|
|
code: hasHello ? "gemini_hello_probe_passed" : "gemini_hello_probe_unexpected_output",
|
|
|
|
|
level: hasHello ? "info" : "warn",
|
|
|
|
|
message: hasHello
|
|
|
|
|
? "Gemini hello probe succeeded."
|
|
|
|
|
: "Gemini probe ran but did not return `hello` as expected.",
|
|
|
|
|
...(summary ? { detail: summary.replace(/\s+/g, " ").trim().slice(0, 240) } : {}),
|
|
|
|
|
...(hasHello
|
|
|
|
|
? {}
|
|
|
|
|
: {
|
2026-03-08 19:20:43 +05:30
|
|
|
hint: "Try `gemini --output-format json \"Respond with hello.\"` manually to inspect full output.",
|
|
|
|
|
}),
|
2026-03-08 16:43:34 +05:30
|
|
|
});
|
2026-03-09 15:16:15 +00:00
|
|
|
} else if (authMeta.requiresAuth) {
|
2026-03-08 16:43:34 +05:30
|
|
|
checks.push({
|
|
|
|
|
code: "gemini_hello_probe_auth_required",
|
|
|
|
|
level: "warn",
|
|
|
|
|
message: "Gemini CLI is installed, but authentication is not ready.",
|
|
|
|
|
...(detail ? { detail } : {}),
|
|
|
|
|
hint: "Run `gemini auth` or configure GEMINI_API_KEY / GOOGLE_API_KEY in adapter env/shell, then retry the probe.",
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
checks.push({
|
|
|
|
|
code: "gemini_hello_probe_failed",
|
|
|
|
|
level: "error",
|
|
|
|
|
message: "Gemini hello probe failed.",
|
|
|
|
|
...(detail ? { detail } : {}),
|
|
|
|
|
hint: "Run `gemini --output-format json \"Respond with hello.\"` manually in this working directory to debug.",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
adapterType: ctx.adapterType,
|
|
|
|
|
status: summarizeStatus(checks),
|
|
|
|
|
checks,
|
|
|
|
|
testedAt: new Date().toISOString(),
|
|
|
|
|
};
|
|
|
|
|
}
|