mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-01 01:24:30 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Paperclip lets operators prepare and use custom images for sandbox environments > - The custom-image overview detected drift but did not show which boot source changed > - Operators need the changed field and values to understand why a template no longer matches > - This pull request adds safe drift attribution to the overview API and the out-of-sync banner > - The benefit is faster diagnosis without exposing secrets or internal snapshot data ## Linked Issues or Issue Description **Subsystem affected** Cross-cutting (server and UI). **Problem or motivation** The custom-image overview reported drift without identifying the changed boot source. Operators had to inspect other data to find the cause. **Proposed solution** Return a classified drift summary with changed paths and their prior and current values. Show the boot-source field in the UI banner. Keep legacy templates and unclassified drift on the generic message. **Alternatives considered** The change does not expose the full snapshot or fingerprint. This keeps the overview contract small and avoids secret disclosure. **Roadmap alignment** The change supports the existing custom-image environment workflow and does not duplicate a roadmap item. ## What Changed - Add `activeTemplateDrift` to the custom-image overview response. - Classify drift as `boot_source_drift`, `knob_only`, or `unclassified`. - Return drifted paths with safe `from` and `to` values. - Show the changed boot-source field and values in the out-of-sync banner. - Keep legacy templates fail-closed and exclude secrets, fingerprints, and raw snapshots. - Add server and UI tests for the new behavior. ## Verification - `npx vitest run server/src/__tests__/environment-custom-images-service.test.ts` passes with 27 tests. - `npx vitest run ui/src/pages/CompanyEnvironments.test.tsx` passes with 27 tests. - `pnpm --filter @paperclipai/ui exec tsc --noEmit` passes. - Review the overview response and banner cases for boot-source, knob-only, and legacy drift. ## Risks The overview response gains one optional field. Legacy templates remain compatible because they return `unclassified` and keep the generic banner. The service excludes secret values, fingerprints, and raw snapshots. ## Model Used OpenAI Codex, GPT-5, tool use and code execution enabled. The model reviewed the handoff and managed the pull request. ## 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] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [ ] I will address all Greptile and reviewer comments before requesting merge Co-authored-by: Paperclip <noreply@paperclip.ing>
221 lines
8.3 KiB
TypeScript
221 lines
8.3 KiB
TypeScript
import type {
|
|
CancelEnvironmentCustomImageSetupSession,
|
|
Environment,
|
|
EnvironmentCapabilities,
|
|
EnvironmentLease,
|
|
EnvironmentProbeResult,
|
|
EnvironmentCustomImageSetupSession,
|
|
EnvironmentCustomImageTemplate,
|
|
EnvironmentCustomImageTerminalSessionToken,
|
|
FinishEnvironmentCustomImageSetupSession,
|
|
StartEnvironmentCustomImageSetupSession,
|
|
CreateEnvironmentCustomImageTerminalSessionToken,
|
|
} from "@paperclipai/shared";
|
|
import { api } from "./client";
|
|
|
|
export interface EnvironmentCustomImageOverview {
|
|
activeTemplate: EnvironmentCustomImageTemplate | null;
|
|
/**
|
|
* `false` means the environment config changed since capture and runs fall
|
|
* back to the base image until a new image is captured. `null` when unknown.
|
|
*/
|
|
activeTemplateMatchesConfig?: boolean | null;
|
|
/**
|
|
* Boot-relevant drift attribution for the active template. It names the
|
|
* classification and the drifted paths with their `from`/`to` values, so the
|
|
* banner can name the changed field. `null` or absent when there is no active
|
|
* template or the driver is not `sandbox`.
|
|
*/
|
|
activeTemplateDrift?: EnvironmentCustomImageActiveTemplateDrift | null;
|
|
activeSession: EnvironmentCustomImageSetupSession | null;
|
|
latestSession: EnvironmentCustomImageSetupSession | null;
|
|
}
|
|
|
|
export interface EnvironmentCustomImageActiveTemplateDrift {
|
|
classification: EnvironmentCustomImageRelinkClassification;
|
|
driftedPaths: EnvironmentCustomImageDriftedPath[];
|
|
}
|
|
|
|
export type EnvironmentCustomImageReconciliation =
|
|
| { action: "relinked"; template: EnvironmentCustomImageTemplate }
|
|
| { action: "detached"; template: EnvironmentCustomImageTemplate };
|
|
|
|
export type EnvironmentUpdateResult = Environment & {
|
|
customImageReconciliation?: EnvironmentCustomImageReconciliation;
|
|
};
|
|
|
|
export interface EnvironmentCustomImageConnectionPayload {
|
|
type: string;
|
|
command?: string | null;
|
|
token?: string | null;
|
|
expiresAt?: string | null;
|
|
metadata?: Record<string, unknown> | null;
|
|
}
|
|
|
|
export interface EnvironmentCustomImageSetupSessionResult {
|
|
session: EnvironmentCustomImageSetupSession;
|
|
connectionPayload: EnvironmentCustomImageConnectionPayload | null;
|
|
}
|
|
|
|
export interface EnvironmentCustomImageFinishResult extends EnvironmentCustomImageSetupSessionResult {
|
|
template: EnvironmentCustomImageTemplate;
|
|
}
|
|
|
|
export interface EnvironmentCustomImageRollbackResult {
|
|
activeTemplate: EnvironmentCustomImageTemplate;
|
|
supersededTemplate: EnvironmentCustomImageTemplate;
|
|
}
|
|
|
|
export type EnvironmentCustomImageRelinkClassification =
|
|
| "knob_only"
|
|
| "boot_source_drift"
|
|
| "unclassified";
|
|
|
|
export interface EnvironmentCustomImageRelinkResult {
|
|
template: EnvironmentCustomImageTemplate;
|
|
classification: EnvironmentCustomImageRelinkClassification;
|
|
}
|
|
|
|
export interface EnvironmentCustomImageDriftedPath {
|
|
path: string;
|
|
from?: unknown;
|
|
to?: unknown;
|
|
}
|
|
|
|
/**
|
|
* The 409 conflict body a relink returns when the server cannot re-stamp without
|
|
* an operator confirmation. `driftedPaths` carries `from`/`to` only for paths
|
|
* that passed the secret containment check; excluded paths carry the name only.
|
|
*/
|
|
export interface EnvironmentCustomImageRelinkConflict {
|
|
classification: Exclude<EnvironmentCustomImageRelinkClassification, "knob_only">;
|
|
driftedPaths: EnvironmentCustomImageDriftedPath[];
|
|
}
|
|
|
|
function companyIdQuery(companyId: string): string {
|
|
return `companyId=${encodeURIComponent(companyId)}`;
|
|
}
|
|
|
|
export interface EnvironmentSecretRefDescriptor {
|
|
configPath: string;
|
|
secretId: string;
|
|
name: string;
|
|
status: string;
|
|
companyId: string;
|
|
companyName: string | null;
|
|
}
|
|
|
|
export const environmentsApi = {
|
|
list: (companyId: string) => api.get<Environment[]>(`/companies/${companyId}/environments`),
|
|
capabilities: (companyId: string) =>
|
|
api.get<EnvironmentCapabilities>(`/companies/${companyId}/environments/capabilities`),
|
|
lease: (leaseId: string) => api.get<EnvironmentLease>(`/environment-leases/${leaseId}`),
|
|
secretRefs: (environmentId: string) =>
|
|
api.get<{ refs: EnvironmentSecretRefDescriptor[] }>(`/environments/${environmentId}/secret-refs`),
|
|
create: (companyId: string, body: {
|
|
name: string;
|
|
description?: string | null;
|
|
driver: "local" | "ssh" | "sandbox" | "plugin";
|
|
config?: Record<string, unknown>;
|
|
metadata?: Record<string, unknown> | null;
|
|
}) => api.post<Environment>(`/companies/${companyId}/environments`, body),
|
|
update: (environmentId: string, body: {
|
|
name?: string;
|
|
description?: string | null;
|
|
driver?: "local" | "ssh" | "sandbox" | "plugin";
|
|
status?: "active" | "archived";
|
|
config?: Record<string, unknown>;
|
|
// The only field accepted on platform-managed environments (the server
|
|
// write floor admits envVars-only patches there).
|
|
envVars?: Environment["envVars"];
|
|
metadata?: Record<string, unknown> | null;
|
|
// Secret-context company for env var / config writes. Without it the
|
|
// server can only infer a company from existing bindings or a
|
|
// single-membership actor, and fails closed otherwise — a fresh
|
|
// environment with no bindings needs the explicit context.
|
|
}, companyId?: string | null) =>
|
|
api.patch<EnvironmentUpdateResult>(
|
|
companyId
|
|
? `/environments/${environmentId}?${companyIdQuery(companyId)}`
|
|
: `/environments/${environmentId}`,
|
|
body,
|
|
),
|
|
probe: (environmentId: string, companyId?: string | null) =>
|
|
api.post<EnvironmentProbeResult>(
|
|
companyId
|
|
? `/environments/${environmentId}/probe?${companyIdQuery(companyId)}`
|
|
: `/environments/${environmentId}/probe`,
|
|
{},
|
|
),
|
|
probeConfig: (companyId: string, body: {
|
|
name?: string;
|
|
driver: "local" | "ssh" | "sandbox" | "plugin";
|
|
description?: string | null;
|
|
config?: Record<string, unknown>;
|
|
metadata?: Record<string, unknown> | null;
|
|
}) => api.post<EnvironmentProbeResult>(`/companies/${companyId}/environments/probe-config`, body),
|
|
customImageTemplate: (environmentId: string, companyId: string) =>
|
|
api.get<EnvironmentCustomImageOverview>(
|
|
`/environments/${environmentId}/custom-image-template?${companyIdQuery(companyId)}`,
|
|
),
|
|
startCustomImageSetupSession: (
|
|
environmentId: string,
|
|
companyId: string,
|
|
body: StartEnvironmentCustomImageSetupSession = {},
|
|
) =>
|
|
api.post<EnvironmentCustomImageSetupSessionResult>(
|
|
`/environments/${environmentId}/custom-image-setup-sessions?${companyIdQuery(companyId)}`,
|
|
body,
|
|
),
|
|
customImageSetupSession: (sessionId: string) =>
|
|
api.get<EnvironmentCustomImageSetupSessionResult>(
|
|
`/environment-custom-image-setup-sessions/${sessionId}`,
|
|
),
|
|
createCustomImageTerminalSessionToken: (
|
|
sessionId: string,
|
|
body: CreateEnvironmentCustomImageTerminalSessionToken = {},
|
|
) =>
|
|
api.post<EnvironmentCustomImageTerminalSessionToken>(
|
|
`/environment-custom-image-setup-sessions/${sessionId}/terminal-session-token`,
|
|
body,
|
|
),
|
|
finishCustomImageSetupSession: (
|
|
sessionId: string,
|
|
body: FinishEnvironmentCustomImageSetupSession = {},
|
|
) =>
|
|
api.post<EnvironmentCustomImageFinishResult>(
|
|
`/environment-custom-image-setup-sessions/${sessionId}/finish`,
|
|
body,
|
|
),
|
|
cancelCustomImageSetupSession: (
|
|
sessionId: string,
|
|
body: CancelEnvironmentCustomImageSetupSession = {},
|
|
) =>
|
|
api.post<EnvironmentCustomImageSetupSession>(
|
|
`/environment-custom-image-setup-sessions/${sessionId}/cancel`,
|
|
body,
|
|
),
|
|
rollbackCustomImageTemplate: (environmentId: string, companyId: string) =>
|
|
api.post<EnvironmentCustomImageRollbackResult>(
|
|
`/environments/${environmentId}/custom-image-template/rollback?${companyIdQuery(companyId)}`,
|
|
{},
|
|
),
|
|
relinkCustomImageTemplate: (
|
|
environmentId: string,
|
|
companyId: string,
|
|
options: { confirmBootSourceDrift?: boolean } = {},
|
|
) =>
|
|
api.post<EnvironmentCustomImageRelinkResult>(
|
|
`/environments/${environmentId}/custom-image-template/relink?${companyIdQuery(companyId)}`,
|
|
{ confirmBootSourceDrift: options.confirmBootSourceDrift === true },
|
|
),
|
|
disableCustomImageTemplate: (
|
|
environmentId: string,
|
|
companyId: string,
|
|
options: { deleteProviderTemplate?: boolean } = {},
|
|
) =>
|
|
api.delete<EnvironmentCustomImageTemplate>(
|
|
`/environments/${environmentId}/custom-image-template?${companyIdQuery(companyId)}&deleteProviderTemplate=${options.deleteProviderTemplate === true ? "true" : "false"}`,
|
|
),
|
|
};
|