feat(plugins): support agentless harness sign-in (#23392)

## Thinking Path

> - Paperclip manages agents and the AI accounts they use.
> - A company can connect an account before creating its first agent.
> - Some plugin drivers can run sign-in in a dedicated sandbox.
> - Core currently selects a saved agent for every plugin login.
> - This change lets each driver declare that it can sign in without an
agent.

## Linked Issues or Issue Description

**Subsystem affected**

Environment drivers, managed AI connections, and the agent setup UI.

**Current behavior**

A company with zero agents cannot start a provider login on a plugin
environment, even when that driver can provision a temporary
environment.

**Proposed behavior**

A driver can declare `supportsAgentlessLogin`. Core uses this capability
when it selects a login target and acquires the lease. Drivers that omit
it retain the existing agent selection.

**Reason and benefit**

Operators can finish connecting the account before they configure its
first agent.

**Additional context**

The driver capability follows the per-driver adapter declaration in
#22827. The onboarding flow keeps the agent readiness check from #23383.

## What Changed

- Added the optional capability to the manifest, capabilities response,
and login UI.
- Kept company and driver validation at sign-in and lease acquisition.
- Applied the plugin device-login deadline to sessions with no agent.
Ordinary task provisioning keeps its existing contract.

## Verification

- 122 tests passed across shared capabilities, environment target
resolution, lease construction, device-login HTTP routes, and session
lifecycle.
- The server typecheck passed.
- The SDK input registry matches the source revision. `pnpm verify`
requests broader CI coverage for that registry.
- After merging the current base, 82 focused tests passed, including the
onboarding tests. The UI typecheck passed. All required GitHub checks
passed.

## Risks

Drivers must advertise this capability only when they can run and clean
up a login without an agent. Existing manifests retain their previous
behavior. No database migration is required.

> For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and
discuss it in `#dev` before opening the PR. Feature PRs that overlap
with planned core work may need to be redirected — check the roadmap
first. See `CONTRIBUTING.md`.

## Model Used

OpenAI Codex, GPT-6, with local code inspection and test execution.

## 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 searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Nicky LeachandPaperclip authored and GitHub committed 2026-12-01 10:22:32 -08:00
1 parent ce2e6ccc00
commit 07af22c57f
18 files changed
+88 -32

No files matched your search

@@ -1285,7 +1285,8 @@ describe("device login service", () => {
}
});
it("holds the session active until exactly five minutes, then times out and deletes", async () => {
it.each([{}, { environmentDriver: "plugin", ttlSeconds: 3_600 }])(
"holds the session until five minutes and bounds agentless plugin leases %j", async options => {
vi.useFakeTimers();
try {
const store = createMemoryStore();
@@ -1293,6 +1294,7 @@ describe("device login service", () => {
const service = makeService({ store, runtime });
const companyId = randomUUID();
const { session, completed } = await service.start({
...options,
companyId,
environmentId: randomUUID(),
adapterType: ADAPTER_TYPE,
@@ -1,6 +1,8 @@
import type { Request, Response } from "express";
import type { z } from "zod";
type LoginTarget = { agentId: string | undefined; environment: { driver: string } };
/**
* The result of the shared adapter login start-route spine. The spine returns it
* when every guard passes. `ownerUserId` is the immutable session owner from the
@@ -9,7 +11,7 @@ import type { z } from "zod";
export interface AdapterLoginStartResolution<TData> {
ownerUserId: string;
data: TData;
targetAgentId: string | undefined;
target: LoginTarget;
}
/**
@@ -57,7 +59,7 @@ export interface AdapterLoginStartSpineInput<TData extends { environmentId: stri
/**
* Checks the sign-in environment and resolves its computer target, when required.
*/
resolveTargetAgentId: (data: TData) => Promise<string | undefined>;
resolveTarget: (data: TData) => Promise<LoginTarget>;
}
/**
@@ -102,6 +104,6 @@ export async function runAdapterLoginStartSpine<TData extends { environmentId: s
if (stop) return null;
}
const targetAgentId = await input.resolveTargetAgentId(data);
return { ownerUserId, data, targetAgentId };
const target = await input.resolveTarget(data);
return { ownerUserId, data, target };
}
+13 -12
View File
@@ -15,7 +15,7 @@ import { connectionManagementService, continuingConnectionManagement } from "../
import { connectionManagementGuard, connectionRequestContext, connectionRequestUserId, aiLoginUserAction } from "./connection-management-authz.js";
import { cancellationRequestId } from "../services/native-runtime/native-cancellation-request.js";
import { NATIVE_CLEANUP_SETTLING_MESSAGE } from "../services/native-runtime/completed-turn-cleanup.js";
import { agentHarnessType, environmentLoginRequiresAgent, isEnvironmentDriverSupportedForAdapter, normalizeClaudeRunnerOptions, type AgentConfigurationWarning, type AgentRunnerChoice } from "@paperclipai/shared";
import { agentHarnessType, isEnvironmentDriverSupportedForAdapter, normalizeClaudeRunnerOptions, type AgentConfigurationWarning, type AgentRunnerChoice } from "@paperclipai/shared";
import { assertRunnerTaskEnvironmentSupportsHarness, resolveNewAgentRunnerForCompany } from "../services/agent-runner-selection.js";
import { PLUGIN_RUNNER_AI_CONNECTION_REQUIRED, pluginEnvironmentRunnerTaskDriver, pluginRunnerAiConnectionRequiredMessage, pluginRunnerAiConnectionRequiredTestResult } from "../services/plugin-runner-ai-connection.js";
import { agentEnvironmentTestService } from "../services/agent-environment-test.js";
@@ -1581,7 +1581,7 @@ export function agentRoutes(
companyId: string,
environmentId: string,
options: { requireSetupTokenLoginProvider?: boolean; agentId?: string; adapterType?: string; selectComputer?: boolean },
): Promise<string | undefined> {
) {
const target = await resolveLoginEnvironmentTarget(db, { companyId, environmentId, ...options });
// Gate the Claude setup-token login on the provider capability. Only a
// sandbox provider that advertises the setup-token login capability
@@ -1593,7 +1593,7 @@ export function agentRoutes(
if (options.requireSetupTokenLoginProvider) {
await assertSetupTokenLoginProviderCapability(environmentId);
}
return target.agentId;
return target;
}
/**
@@ -1612,7 +1612,7 @@ export function agentRoutes(
environment?.config && typeof environment.config === "object"
? (environment.config as Record<string, unknown>)
: {};
if (environmentLoginRequiresAgent(environment)) {
if (environment?.driver === "plugin") {
if (!options.pluginWorkerManager || typeof config.pluginKey !== "string" || typeof config.driverKey !== "string") return false;
try {
const resolved = await resolvePluginEnvironmentDriver({ db, workerManager: options.pluginWorkerManager, config: config as unknown as import("@paperclipai/shared").PluginEnvironmentConfig });
@@ -3816,21 +3816,21 @@ export function agentRoutes(
requestSchema: startAdapterAuthSessionRequestSchema,
invalidRequestError: "The device login start request is invalid.",
requestOverrides: { adapterType: type },
resolveTargetAgentId: async (data) => {
resolveTarget: async (data) => {
// The device login runs on a real pseudo-terminal, so it needs a
// provider that advertises the login pseudo-terminal capability. Gate
// the route on the current provider capability before any session or
// lease state. The lease-acquisition path re-checks it from current
// runtime state before the provider lease.
const targetAgentId = await resolveSandboxLoginTarget(companyId, data.environmentId, {
const target = await resolveSandboxLoginTarget(companyId, data.environmentId, {
agentId: data.agentId, adapterType: data.adapterType, selectComputer: Boolean(data.aiConnection),
});
await assertDeviceLoginProviderCapability(data.environmentId, data.adapterType);
return targetAgentId;
return target;
},
});
if (!resolved) return;
const { ownerUserId: startedByUserId, data, targetAgentId } = resolved;
const { ownerUserId: startedByUserId, data, target } = resolved;
if (req.actor.type === "agent" && !data.aiConnection) throw forbidden("Agent logins must save a managed AI account");
if (data.aiConnection) {
@@ -3843,7 +3843,8 @@ export function agentRoutes(
result = await adapterLoginService.start({
companyId,
environmentId: data.environmentId,
agentId: targetAgentId,
agentId: target.agentId,
environmentDriver: target.environment.driver,
adapterType: type,
startedByUserId,
ttlSeconds: data.ttlSeconds,
@@ -7052,7 +7053,7 @@ export function agentRoutes(
}
return false;
},
resolveTargetAgentId: (data) =>
resolveTarget: (data) =>
resolveSandboxLoginTarget(companyId, data.environmentId, {
requireSetupTokenLoginProvider: true,
agentId: data.agentId,
@@ -7061,7 +7062,7 @@ export function agentRoutes(
}),
});
if (!resolved) return;
const { ownerUserId, data, targetAgentId } = resolved;
const { ownerUserId, data, target } = resolved;
const { environmentId, adapterType } = data;
if (req.actor.type === "agent" && !data.aiConnection) throw forbidden("Agent logins must save a managed AI account");
if (data.aiConnection) {
@@ -7075,7 +7076,7 @@ export function agentRoutes(
ownerUserId,
adapterType,
environmentId,
agentId: targetAgentId,
agentId: target.agentId,
confirmedOverwrite,
aiConnection: data.aiConnection,
managementContext: continuingConnectionManagement(connectionRequestContext(req)),
+1
View File
@@ -824,6 +824,7 @@ export function environmentRoutes(
`${driver.pluginKey}:${driver.driverKey}`, {
supportsLoginPty: driver.supportsLoginPty === true,
loginAdapters: driver.loginAdapters,
...(driver.supportsAgentlessLogin ? { supportsAgentlessLogin: true } : {}),
},
])) });
});
+2 -1
View File
@@ -215,6 +215,7 @@ export interface LoginSessionActivityEvent {
export type LoginSessionActivityRecorder = (event: LoginSessionActivityEvent) => void;
export interface StartDeviceLoginInput {
environmentDriver?: string;
agentId?: string;
managementContext?: ConnectionManagementContext;
aiConnection?: import("@paperclipai/shared").AiConnectionLoginIntent;
@@ -939,7 +940,7 @@ export function createDeviceLoginService(deps: DeviceLoginServiceDeps) {
const publicSessionId = randomUUID();
const startedAt = now();
const requestedTtlSeconds = input.ttlSeconds ?? resolveProfile(input.adapterType).timeoutMs / 1000;
const ttlSeconds = input.agentId ? Math.min(requestedTtlSeconds, DEVICE_LOGIN_TIMEOUT_MS / 1000) : requestedTtlSeconds;
const ttlSeconds = input.environmentDriver === "plugin" || input.agentId ? Math.min(requestedTtlSeconds, DEVICE_LOGIN_TIMEOUT_MS / 1000) : requestedTtlSeconds;
const expiresAt = new Date(startedAt.getTime() + ttlSeconds * 1000);
const base = {
sessionId,
@@ -8,9 +8,23 @@ const fixtures = vi.hoisted(() => ({ environment: { id: "environment", driver: "
vi.mock("./environments.js", () => ({ environmentService: () => ({ getById: async () => fixtures.environment, listBoundCompanyIds: async () => fixtures.companies }) }));
vi.mock("./instance-settings.js", () => ({ instanceSettingsService: () => ({ get: async () => ({ defaultEnvironmentId: fixtures.instanceDefault }) }) }));
vi.mock("./environment-selection.js", () => ({ assertEnvironmentSelectionForCompany: vi.fn(async () => {}) }));
const { getByKey } = vi.hoisted(() => ({ getByKey: vi.fn() }));
vi.mock("./plugin-registry.js", () => ({ pluginRegistryService: () => ({ getByKey }) }));
const db = { select: () => ({ from: () => ({ where: () => ({ limit: async () => fixtures.agent ? [fixtures.agent] : [] }) }) }) } as unknown as Db;
beforeEach(() => { fixtures.instanceDefault = "environment"; fixtures.environment = { id: "environment", driver: "plugin" }; fixtures.companies = ["company"]; fixtures.agent = { id: "agent", companyId: "company", adapterType: "paperclip_runner", lifecycleState: "verifying", defaultEnvironmentId: "environment" }; });
describe("login environment transport target", () => {
it("acquires an opted-in plugin login without selecting an agent", async () => {
Object.assign(fixtures.environment, { config: { pluginKey: "computers", driverKey: "temporary" } });
getByKey.mockResolvedValue({ status: "ready", manifestJson: { environmentDrivers: [
{ kind: "environment_driver", driverKey: "temporary", supportsLoginPty: true, supportsAgentlessLogin: true },
] } });
fixtures.agent = undefined;
const input = { companyId: "company", environmentId: "environment", adapterType: "codex_local" };
await expect(resolveLoginEnvironmentTarget(db, { ...input, selectComputer: true })).resolves.toEqual({ environment: fixtures.environment, agentId: undefined });
await expect(assertLoginEnvironmentTarget(db, input)).resolves.toEqual(fixtures.environment);
Object.assign(fixtures.environment, { config: { pluginKey: "computers", driverKey: "persistent" } });
await expect(assertLoginEnvironmentTarget(db, input)).rejects.toMatchObject({ status: 400 });
});
it("permits a verifying saved agent on its own computer", async () => { await expect(assertLoginEnvironmentTarget(db, { companyId: "company", environmentId: "environment", agentId: "agent" })).resolves.toEqual(fixtures.environment); });
it("leaves which adapters a computer signs in to its driver's declared support", async () => { await expect(assertLoginEnvironmentTarget(db, { companyId: "company", environmentId: "environment", agentId: "agent", adapterType: "grok_local" })).resolves.toEqual(fixtures.environment); });
it("rejects an adapter that has no Paperclip sign-in", async () => { await expect(assertLoginEnvironmentTarget(db, { companyId: "company", environmentId: "environment", agentId: "agent", adapterType: "copilot_runtime" })).rejects.toMatchObject({ status: 400 }); });
+11 -2
View File
@@ -1,9 +1,10 @@
import { agents, environmentLeases, type Db } from "@paperclipai/db";
import { adapterLoginCommandKey, environmentLoginRequiresAgent } from "@paperclipai/shared";
import { adapterLoginCommandKey } from "@paperclipai/shared";
import { and, asc, eq, isNull, notExists, notInArray, or, sql } from "drizzle-orm";
import { badRequest, forbidden, notFound } from "../errors.js";
import { assertEnvironmentSelectionForCompany } from "./environment-selection.js";
import { environmentService } from "./environments.js";
import { pluginRegistryService } from "./plugin-registry.js";
import { instanceSettingsService } from "./instance-settings.js";
type LoginEnvironmentTarget = { companyId: string; environmentId: string; agentId?: string; adapterType?: string };
@@ -25,12 +26,20 @@ export async function resolveLoginEnvironmentTarget(
if (!environment) throw notFound("Environment not found");
const companies = await environments.listBoundCompanyIds(environment.id);
if (companies.length && !companies.includes(input.companyId)) throw forbidden("The selected environment belongs to another company.", { code: "environment_company_mismatch" });
if (!environmentLoginRequiresAgent(environment)) {
if (environment.driver !== "plugin") {
if (input.agentId) throw badRequest("A temporary sandbox login does not take an agent computer target.");
return { environment, agentId: undefined };
}
if (input.adapterType && !adapterLoginCommandKey(input.adapterType)) throw badRequest("This provider login is not supported on agent computers.", { code: "login_adapter_unsupported" });
if (!input.agentId) {
const config = environment.config;
if (typeof config?.pluginKey === "string" && typeof config.driverKey === "string") {
const plugin = await pluginRegistryService(db).getByKey(config.pluginKey);
const driver = plugin?.manifestJson.environmentDrivers?.find(item => item.driverKey === config.driverKey);
if (plugin?.status === "ready" && driver?.kind !== "sandbox_provider" && driver?.supportsLoginPty && driver.supportsAgentlessLogin) {
return { environment, agentId: undefined };
}
}
if (!input.selectComputer) throw badRequest("Select an agent computer for sign-in.", { code: "login_agent_required" });
const settings = await instanceSettingsService(db).get();
const matchesEnvironment = eq(agents.defaultEnvironmentId, environment.id);
@@ -211,6 +211,7 @@ export interface ReadyPluginEnvironmentDriver {
reusableLeaseMethodsVerified: boolean;
supportedAdapters?: string[];
loginAdapters: string[];
supportsAgentlessLogin?: boolean;
supportsInteractiveSetup?: PluginEnvironmentDriverDeclaration["supportsInteractiveSetup"];
interactiveSetupConnectionTypes?: PluginEnvironmentDriverDeclaration["interactiveSetupConnectionTypes"];
supportsTemplateCapture?: PluginEnvironmentDriverDeclaration["supportsTemplateCapture"];
@@ -471,6 +472,7 @@ export async function listReadyPluginEnvironmentDrivers(input: {
templateConfigBinding: driver.templateConfigBinding,
supportsTemplateDelete: driver.supportsTemplateDelete,
supportsLoginPty: driver.kind === "environment_driver" ? pluginSupportsLoginPty(driver, [...workerMethods]) : sandboxProviderSupportsLoginPty(driver),
...(driver.supportsAgentlessLogin ? { supportsAgentlessLogin: true } : {}),
...supportedAdapterFields(plugin.pluginKey, driver, [...workerMethods]),
})),
);