mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-05 06:03:51 +01:00
## Thinking Path > - People use Paperclip to manage agents and the accounts they use. > - A harness can sign in on an environment supplied by a plugin. > - Some plugins offer several environments with different login requirements. > - Today the task environment also determines where sign-in runs. > - This change lets the plugin declare its preferred login drivers. > - A company can use a temporary environment for sign-in and keep running tasks on its chosen computer. ## Linked Issues or Issue Description **Subsystem affected** Plugin manifests, login target selection, and the harness sign-in UI. **Current behavior** A plugin with several environments cannot direct sign-in to a preferred driver. Selecting an agent computer for tasks can require an agent even when a temporary environment is available for login. **Proposed behavior** Allow the manifest to declare an ordered list of login drivers. Select the first eligible environment for the company and harness before starting a login. **Reason and benefit** A plugin can offer agentless sign-in first and keep an agent-targeted computer as a fallback. The choice applies only to sign-in. **Additional context** This builds on the agentless login capability in #23392. ## What Changed - Validate ordered login driver keys in the manifest and expose the eligible environments to the company. - Use the same selection rule for device login, setup-token login, onboarding, agent configuration, and AI Connections. - Bind the session and lease to the selected environment. Existing agent eligibility checks apply when the target needs an agent. ## Verification - Server and UI typechecks passed. Focused Vitest runs covered shared manifest validation, driver order, the company access boundary, lease checks, both HTTP login flows, and the UI helpers. - The public SDK source input registry was regenerated. The registry change requires broad CI coverage under `pnpm verify`. - Regression tests cover skipping an environment without an eligible computer, using a newly prepared draft computer, and holding the selected host across capability and readiness updates during sign-in. The UI typecheck and all 16 focused login tests passed on the final commit. - No external provider credentials were used. ## Risks A plugin that opts in must declare at least one usable driver for the user's harness and company. If none qualifies, the start fails before acquisition. Manifests that omit the field keep their existing routing. There is no database migration. > 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, TypeScript checks, 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>
266 lines
11 KiB
TypeScript
266 lines
11 KiB
TypeScript
import { adapterLoginCommandKey } from "./adapter-login.js";
|
|
import type { AgentAdapterType, EnvironmentDriver } from "./constants.js";
|
|
import type { Environment, SandboxEnvironmentProvider } from "./types/environment.js";
|
|
import type {
|
|
JsonSchema,
|
|
PluginEnvironmentTemplateConfigBinding,
|
|
SandboxProviderCapabilities,
|
|
} from "./types/plugin.js";
|
|
|
|
/**
|
|
* Resolve the DECLARED sandbox capabilities of a provider driver, with the
|
|
* legacy `supportsReusableLeases` flag folded in for compatibility.
|
|
*
|
|
* The result is a partial: a key is present only when the driver declared it,
|
|
* so a caller can tell a declared `false` from an absent key. The nested
|
|
* `sandboxCapabilities.reusableLeases` wins over the legacy flag when both are
|
|
* present. This is the DECLARATION only; the runtime still intersects it with
|
|
* the verified worker methods and any narrowing before it grants a capability.
|
|
*/
|
|
export function resolveDeclaredSandboxCapabilities(
|
|
driver: {
|
|
supportsReusableLeases?: boolean;
|
|
sandboxCapabilities?: SandboxProviderCapabilities;
|
|
},
|
|
): SandboxProviderCapabilities {
|
|
const declared: SandboxProviderCapabilities = { ...(driver.sandboxCapabilities ?? {}) };
|
|
if (declared.reusableLeases === undefined && driver.supportsReusableLeases !== undefined) {
|
|
declared.reusableLeases = driver.supportsReusableLeases;
|
|
}
|
|
return declared;
|
|
}
|
|
|
|
export type EnvironmentSupportStatus = "supported" | "unsupported";
|
|
|
|
export interface AdapterEnvironmentSupport {
|
|
adapterType: AgentAdapterType;
|
|
drivers: Record<EnvironmentDriver, EnvironmentSupportStatus>;
|
|
sandboxProviders: Record<SandboxEnvironmentProvider, EnvironmentSupportStatus>;
|
|
}
|
|
|
|
export interface EnvironmentProviderCapability {
|
|
status: EnvironmentSupportStatus;
|
|
supportsSavedProbe: boolean;
|
|
supportsUnsavedProbe: boolean;
|
|
supportsRunExecution: boolean;
|
|
supportsReusableLeases: boolean;
|
|
supportsInteractiveSetup: boolean;
|
|
interactiveSetupConnectionTypes: string[];
|
|
supportsTemplateCapture: boolean;
|
|
templateRefKind?: string;
|
|
templateConfigBinding?: PluginEnvironmentTemplateConfigBinding;
|
|
supportsTemplateDelete: boolean;
|
|
supportsLoginPty: boolean;
|
|
displayName?: string;
|
|
description?: string;
|
|
source?: "builtin" | "plugin";
|
|
pluginKey?: string;
|
|
pluginId?: string;
|
|
configSchema?: JsonSchema;
|
|
}
|
|
|
|
export interface PluginLoginTarget {
|
|
environmentId: string;
|
|
/** Present only for computer targets. Direct sign-in can instead use the agent's own environment. */
|
|
automaticComputerAvailable?: boolean;
|
|
driverKey: string;
|
|
loginAdapters: string[];
|
|
}
|
|
|
|
export interface EnvironmentCapabilities {
|
|
/** Company-visible login environments in manifest preference order, keyed by plugin. */
|
|
pluginLoginTargets?: Record<string, PluginLoginTarget[]>;
|
|
/** Namespaced plugin driver keys that can host a login on a saved agent. */
|
|
loginPtyDrivers?: Record<string, { supportsLoginPty: boolean; supportsAgentlessLogin?: boolean; loginAdapters: string[] }>;
|
|
adapters: AdapterEnvironmentSupport[];
|
|
drivers: Record<EnvironmentDriver, EnvironmentSupportStatus>;
|
|
sandboxProviders: Record<SandboxEnvironmentProvider, EnvironmentProviderCapability>;
|
|
}
|
|
|
|
const REMOTE_MANAGED_ADAPTERS = new Set<AgentAdapterType>([
|
|
"claude_local",
|
|
"codex_local",
|
|
"paperclip_runner",
|
|
"cursor",
|
|
"gemini_local",
|
|
"grok_local",
|
|
"kimi_local",
|
|
"opencode_local",
|
|
"pi_local",
|
|
]);
|
|
|
|
export function adapterSupportsRemoteManagedEnvironments(adapterType: string): boolean {
|
|
return REMOTE_MANAGED_ADAPTERS.has(adapterType as AgentAdapterType);
|
|
}
|
|
|
|
export function supportedEnvironmentDriversForAdapter(adapterType: string): EnvironmentDriver[] {
|
|
if (adapterType === "paperclip_runner") return ["local", "ssh", "sandbox", "plugin"];
|
|
return adapterSupportsRemoteManagedEnvironments(adapterType)
|
|
? ["local", "ssh", "sandbox"]
|
|
: ["local"];
|
|
}
|
|
|
|
export function supportedSandboxProvidersForAdapter(
|
|
adapterType: string,
|
|
additionalProviders: readonly string[] = [],
|
|
): SandboxEnvironmentProvider[] {
|
|
return adapterSupportsRemoteManagedEnvironments(adapterType)
|
|
? Array.from(new Set(additionalProviders)) as SandboxEnvironmentProvider[]
|
|
: [];
|
|
}
|
|
|
|
export function isEnvironmentDriverSupportedForAdapter(
|
|
adapterType: string,
|
|
driver: string,
|
|
): boolean {
|
|
return supportedEnvironmentDriversForAdapter(adapterType).includes(driver as EnvironmentDriver);
|
|
}
|
|
|
|
export function isSandboxProviderSupportedForAdapter(
|
|
adapterType: string,
|
|
provider: string | null | undefined,
|
|
additionalProviders: readonly string[] = [],
|
|
): boolean {
|
|
if (!provider) return false;
|
|
return supportedSandboxProvidersForAdapter(adapterType, additionalProviders).includes(
|
|
provider as SandboxEnvironmentProvider,
|
|
);
|
|
}
|
|
|
|
export function getAdapterEnvironmentSupport(
|
|
adapterType: AgentAdapterType,
|
|
additionalSandboxProviders: readonly string[] = [],
|
|
): AdapterEnvironmentSupport {
|
|
const supportedDrivers = new Set(supportedEnvironmentDriversForAdapter(adapterType));
|
|
const supportedProviders = new Set(supportedSandboxProvidersForAdapter(adapterType, additionalSandboxProviders));
|
|
const sandboxProviders: Record<SandboxEnvironmentProvider, EnvironmentSupportStatus> = {
|
|
fake: "unsupported",
|
|
};
|
|
for (const provider of additionalSandboxProviders) {
|
|
sandboxProviders[provider as SandboxEnvironmentProvider] = supportedProviders.has(provider as SandboxEnvironmentProvider)
|
|
? "supported"
|
|
: "unsupported";
|
|
}
|
|
return {
|
|
adapterType,
|
|
drivers: {
|
|
local: supportedDrivers.has("local") ? "supported" : "unsupported",
|
|
ssh: supportedDrivers.has("ssh") ? "supported" : "unsupported",
|
|
sandbox: supportedDrivers.has("sandbox") ? "supported" : "unsupported",
|
|
plugin: supportedDrivers.has("plugin") ? "supported" : "unsupported",
|
|
},
|
|
sandboxProviders,
|
|
};
|
|
}
|
|
|
|
export function getEnvironmentCapabilities(
|
|
adapterTypes: readonly AgentAdapterType[],
|
|
options: {
|
|
sandboxProviders?: Record<string, Partial<EnvironmentProviderCapability>>;
|
|
} = {},
|
|
): EnvironmentCapabilities {
|
|
const pluginProviderKeys = Object.keys(options.sandboxProviders ?? {});
|
|
const sandboxProviders: Record<SandboxEnvironmentProvider, EnvironmentProviderCapability> = {
|
|
fake: {
|
|
status: "unsupported",
|
|
supportsSavedProbe: true,
|
|
supportsUnsavedProbe: true,
|
|
supportsRunExecution: false,
|
|
// The fake provider runtime declares false. The presentation must match
|
|
// it, so execution and presentation agree.
|
|
supportsReusableLeases: false,
|
|
supportsInteractiveSetup: false,
|
|
interactiveSetupConnectionTypes: [],
|
|
supportsTemplateCapture: false,
|
|
supportsTemplateDelete: false,
|
|
supportsLoginPty: false,
|
|
displayName: "Fake",
|
|
source: "builtin",
|
|
},
|
|
};
|
|
for (const [provider, capability] of Object.entries(options.sandboxProviders ?? {})) {
|
|
sandboxProviders[provider as SandboxEnvironmentProvider] = {
|
|
status: capability.status ?? "supported",
|
|
supportsSavedProbe: capability.supportsSavedProbe ?? true,
|
|
supportsUnsavedProbe: capability.supportsUnsavedProbe ?? true,
|
|
supportsRunExecution: capability.supportsRunExecution ?? true,
|
|
// Default absent to false. A manifest that does not declare reusable
|
|
// leases must present as false, so execution (=== true) agrees.
|
|
supportsReusableLeases: capability.supportsReusableLeases ?? false,
|
|
supportsInteractiveSetup: capability.supportsInteractiveSetup ?? false,
|
|
interactiveSetupConnectionTypes: capability.interactiveSetupConnectionTypes ?? [],
|
|
supportsTemplateCapture: capability.supportsTemplateCapture ?? false,
|
|
templateRefKind: capability.templateRefKind,
|
|
templateConfigBinding: capability.templateConfigBinding,
|
|
supportsTemplateDelete: capability.supportsTemplateDelete ?? false,
|
|
supportsLoginPty: capability.supportsLoginPty ?? false,
|
|
displayName: capability.displayName,
|
|
description: capability.description,
|
|
source: capability.source ?? "plugin",
|
|
pluginKey: capability.pluginKey,
|
|
pluginId: capability.pluginId,
|
|
configSchema: capability.configSchema,
|
|
};
|
|
}
|
|
return {
|
|
adapters: adapterTypes.map((adapterType) => getAdapterEnvironmentSupport(adapterType, pluginProviderKeys)),
|
|
drivers: {
|
|
local: "supported",
|
|
ssh: "supported",
|
|
sandbox: "supported",
|
|
plugin: adapterTypes.includes("paperclip_runner") ? "supported" : "unsupported",
|
|
},
|
|
sandboxProviders,
|
|
};
|
|
}
|
|
|
|
type LoginComputerChoice = { ownEnvironmentId?: string | null; allowAutomatic?: boolean };
|
|
|
|
/** Eligible environments of the first usable driver, indexed for environment pickers. */
|
|
export function pluginLoginChoices(targets: PluginLoginTarget[], adapter: string, computer?: LoginComputerChoice): Set<string> {
|
|
const choices = new Set<string>();
|
|
let driver: string | undefined;
|
|
for (const target of targets) {
|
|
if (driver && target.driverKey !== driver) break;
|
|
if (!target.loginAdapters.includes(adapter)) continue;
|
|
if (target.automaticComputerAvailable !== undefined &&
|
|
target.environmentId !== computer?.ownEnvironmentId && (computer?.allowAutomatic === false || !target.automaticComputerAvailable)) continue;
|
|
driver = target.driverKey;
|
|
choices.add(target.environmentId);
|
|
}
|
|
return choices;
|
|
}
|
|
|
|
/** Resolve only the login transport. Keep the selected environment on ties within one driver. */
|
|
export function preferredLoginEnvironmentId(
|
|
environment: { id: string; driver: string; config: Record<string, unknown> } & Pick<Environment, "pluginDriver"> | null | undefined,
|
|
adapter: string, preferences?: EnvironmentCapabilities["pluginLoginTargets"], computer?: LoginComputerChoice,
|
|
): string | null {
|
|
if (!environment) return null;
|
|
if (environment.driver !== "plugin" || !adapterLoginCommandKey(adapter)) return environment.id;
|
|
const key = (environment.pluginDriver ?? environment.config)?.pluginKey;
|
|
const targets = typeof key === "string" ? preferences?.[key] : undefined;
|
|
if (!Array.isArray(targets)) return environment.id;
|
|
const choices = pluginLoginChoices(targets, adapter, computer);
|
|
return choices.has(environment.id) ? environment.id : choices.values().next().value ?? null;
|
|
}
|
|
|
|
export function environmentLoginRequiresAgent(environment: { driver: string; config?: Record<string, unknown> | null; pluginDriver?: Environment["pluginDriver"] } | null | undefined, capabilities?: EnvironmentCapabilities | null): boolean {
|
|
if (environment?.driver !== "plugin") return false;
|
|
const config = environment.pluginDriver ?? environment.config;
|
|
return capabilities?.loginPtyDrivers?.[`${config?.pluginKey}:${config?.driverKey}`]?.supportsAgentlessLogin !== true;
|
|
}
|
|
|
|
/** Shared presentation rule for both temporary sandboxes and existing computers. */
|
|
export function environmentSupportsLoginPty(environment: { driver: string; config: Record<string, unknown>; pluginDriver?: Environment["pluginDriver"] } | null | undefined, capabilities: EnvironmentCapabilities | null | undefined, adapterType?: string): boolean {
|
|
if (!environment || !capabilities) return false;
|
|
if (environment.driver === "sandbox") return typeof environment.config.provider === "string" && capabilities.sandboxProviders[environment.config.provider]?.supportsLoginPty === true;
|
|
if (environment.driver === "plugin") {
|
|
const config = environment.pluginDriver ?? environment.config;
|
|
const driver = capabilities.loginPtyDrivers?.[`${config.pluginKey}:${config.driverKey}`];
|
|
return driver?.supportsLoginPty === true
|
|
&& (adapterType === undefined ? driver.loginAdapters.length > 0 : driver.loginAdapters.includes(adapterType));
|
|
}
|
|
return false;
|
|
}
|