mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-16 02:40:39 +09:00
Expand plugin host surface (#5205)
## Thinking Path > - Paperclip orchestrates AI agents for zero-human companies > - The plugin system is the extension boundary for optional product capabilities > - Rich plugins need more than a worker entrypoint: they need scoped database storage, local project folders, managed agents/routines, host navigation, and reusable UI components > - The LLM Wiki work exposed those missing host surfaces while keeping plugin code outside the core control plane > - This pull request expands the core plugin host, SDK, server APIs, and UI bridge so plugins can declare and use those surfaces > - The benefit is that future plugins can integrate with Paperclip through documented, validated contracts instead of bespoke server or UI imports ## What Changed - Added plugin-managed database namespaces and migration tracking, including Drizzle schema/migration files and SQL validation for namespace isolation. - Added server support for plugin local folders, managed agents, managed routines, scoped plugin APIs, and plugin operation visibility. - Expanded shared plugin manifest/types/validators and SDK host/testing/UI exports for richer plugin surfaces. - Added reusable UI pieces for file trees, managed routines, resizable sidebars, route sidebars, and plugin bridge initialization. - Updated plugin docs and example plugins to use the expanded host and SDK surface. ## Verification - `pnpm install --frozen-lockfile` - `pnpm run preflight:workspace-links && pnpm exec vitest run packages/shared/src/validators/plugin.test.ts server/src/__tests__/plugin-database.test.ts server/src/__tests__/plugin-local-folders.test.ts server/src/__tests__/plugin-managed-agents.test.ts server/src/__tests__/plugin-managed-routines.test.ts server/src/__tests__/plugin-orchestration-apis.test.ts ui/src/api/plugins.test.ts ui/src/components/FileTree.test.tsx ui/src/components/ResizableSidebarPane.test.tsx ui/src/pages/PluginPage.test.tsx ui/src/plugins/bridge.test.ts` passed: 11 files, 67 tests. - Confirmed this PR changes 89 files and does not include `pnpm-lock.yaml` or `.github/workflows/*`. ## Risks - Medium: this expands plugin host contracts across db/shared/server/ui and includes a new core migration (`0076_useful_elektra.sql`). - The plugin database namespace validator is intentionally restrictive; plugin authors may need follow-up affordances for SQL patterns that remain blocked. - Merge this before the LLM Wiki plugin PR so the plugin can resolve the new SDK and host APIs. > 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-5 coding agent, tool-enabled shell/git/GitHub workflow. Context window size was not exposed by the runtime. ## 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 --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
This commit is contained in:
parent
d6bee62f02
commit
3c73ed26b5
89 changed files with 27516 additions and 914 deletions
|
|
@ -22,6 +22,7 @@ import type {
|
|||
PluginIssueOrchestrationSummary,
|
||||
} from "@paperclipai/plugin-sdk";
|
||||
import type { CreateIssueThreadInteraction, IssueDocumentSummary } from "@paperclipai/shared";
|
||||
import { pluginOperationIssueOriginKind } from "@paperclipai/shared";
|
||||
import { companyService } from "./companies.js";
|
||||
import { agentService } from "./agents.js";
|
||||
import { projectService } from "./projects.js";
|
||||
|
|
@ -34,12 +35,27 @@ import { budgetService } from "./budgets.js";
|
|||
import { issueApprovalService } from "./issue-approvals.js";
|
||||
import { subscribeCompanyLiveEvents } from "./live-events.js";
|
||||
import { randomUUID } from "node:crypto";
|
||||
import path from "node:path";
|
||||
import { activityService } from "./activity.js";
|
||||
import { costService } from "./costs.js";
|
||||
import { assetService } from "./assets.js";
|
||||
import { pluginRegistryService } from "./plugin-registry.js";
|
||||
import { pluginStateStore } from "./plugin-state-store.js";
|
||||
import { pluginDatabaseService } from "./plugin-database.js";
|
||||
import { pluginManagedAgentService } from "./plugin-managed-agents.js";
|
||||
import { pluginManagedRoutineService } from "./plugin-managed-routines.js";
|
||||
import {
|
||||
assertConfiguredLocalFolder,
|
||||
assertWritableConfiguredLocalFolder,
|
||||
getStoredLocalFolders,
|
||||
inspectPluginLocalFolder,
|
||||
listPluginLocalFolderEntries,
|
||||
preparePluginLocalFolder,
|
||||
readPluginLocalFolderText,
|
||||
requireLocalFolderDeclaration,
|
||||
setStoredLocalFolder,
|
||||
writePluginLocalFolderTextAtomic,
|
||||
} from "./plugin-local-folders.js";
|
||||
import { createPluginSecretsHandler } from "./plugin-secrets-handler.js";
|
||||
import { logActivity } from "./activity-log.js";
|
||||
import type { PluginEventBus } from "./plugin-event-bus.js";
|
||||
|
|
@ -460,7 +476,7 @@ export function buildHostServices(
|
|||
pluginKey: string,
|
||||
eventBus: PluginEventBus,
|
||||
notifyWorker?: (method: string, params: unknown) => void,
|
||||
options: { pluginWorkerManager?: PluginWorkerManager } = {},
|
||||
options: { pluginWorkerManager?: PluginWorkerManager; manifest?: import("@paperclipai/shared").PaperclipPluginManifestV1 } = {},
|
||||
): HostServices & { dispose(): void } {
|
||||
const registry = pluginRegistryService(db);
|
||||
const stateStore = pluginStateStore(db);
|
||||
|
|
@ -468,6 +484,31 @@ export function buildHostServices(
|
|||
const secretsHandler = createPluginSecretsHandler({ db, pluginId });
|
||||
const companies = companyService(db);
|
||||
const agents = agentService(db);
|
||||
const managedAgents = pluginManagedAgentService(db, {
|
||||
pluginId,
|
||||
pluginKey,
|
||||
manifest: options.manifest,
|
||||
instructionTemplateVariables: async (companyId) => {
|
||||
const variables: Record<string, string | null | undefined> = {};
|
||||
for (const declaration of options.manifest?.localFolders ?? []) {
|
||||
const status = await inspectPluginLocalFolder({
|
||||
folderKey: declaration.folderKey,
|
||||
declaration,
|
||||
storedConfig: await getStoredLocalFolderConfig(companyId, declaration.folderKey),
|
||||
});
|
||||
const prefix = `localFolders.${declaration.folderKey}`;
|
||||
variables[`${prefix}.path`] = status.realPath ?? status.path ?? null;
|
||||
variables[`${prefix}.agentsPath`] = status.realPath ? path.join(status.realPath, "AGENTS.md") : null;
|
||||
}
|
||||
return variables;
|
||||
},
|
||||
});
|
||||
const managedRoutines = pluginManagedRoutineService(db, {
|
||||
pluginId,
|
||||
pluginKey,
|
||||
manifest: options.manifest,
|
||||
pluginWorkerManager: options.pluginWorkerManager,
|
||||
});
|
||||
const heartbeat = heartbeatService(db, {
|
||||
pluginWorkerManager: options.pluginWorkerManager,
|
||||
});
|
||||
|
|
@ -518,6 +559,23 @@ export function buildHostServices(
|
|||
*/
|
||||
const ensurePluginAvailableForCompany = async (_companyId: string) => {};
|
||||
|
||||
const getLocalFolderDeclaration = (folderKey: string) =>
|
||||
requireLocalFolderDeclaration(options.manifest?.localFolders, folderKey);
|
||||
|
||||
const getStoredLocalFolderConfig = async (companyId: string, folderKey: string) => {
|
||||
ensureCompanyId(companyId);
|
||||
await ensurePluginAvailableForCompany(companyId);
|
||||
const settings = await registry.getCompanySettings(pluginId, companyId);
|
||||
return getStoredLocalFolders(settings?.settingsJson)[folderKey] ?? null;
|
||||
};
|
||||
|
||||
const inspectStoredLocalFolder = async (companyId: string, folderKey: string) =>
|
||||
inspectPluginLocalFolder({
|
||||
folderKey,
|
||||
declaration: getLocalFolderDeclaration(folderKey),
|
||||
storedConfig: await getStoredLocalFolderConfig(companyId, folderKey),
|
||||
});
|
||||
|
||||
const inCompany = <T extends { companyId: string | null | undefined }>(
|
||||
record: T | null | undefined,
|
||||
companyId: string,
|
||||
|
|
@ -752,6 +810,86 @@ export function buildHostServices(
|
|||
},
|
||||
},
|
||||
|
||||
localFolders: {
|
||||
async declarations() {
|
||||
return options.manifest?.localFolders ?? [];
|
||||
},
|
||||
|
||||
async configure(params) {
|
||||
const companyId = ensureCompanyId(params.companyId);
|
||||
await ensurePluginAvailableForCompany(companyId);
|
||||
const declaration = getLocalFolderDeclaration(params.folderKey);
|
||||
const existing = await registry.getCompanySettings(pluginId, companyId);
|
||||
const existingConfig = getStoredLocalFolders(existing?.settingsJson)[params.folderKey] ?? null;
|
||||
await preparePluginLocalFolder({
|
||||
folderKey: params.folderKey,
|
||||
declaration,
|
||||
storedConfig: existingConfig,
|
||||
overrideConfig: {
|
||||
path: params.path,
|
||||
},
|
||||
});
|
||||
const status = await inspectPluginLocalFolder({
|
||||
folderKey: params.folderKey,
|
||||
declaration,
|
||||
storedConfig: existingConfig,
|
||||
overrideConfig: {
|
||||
path: params.path,
|
||||
},
|
||||
});
|
||||
|
||||
const nextSettings = setStoredLocalFolder(existing?.settingsJson, params.folderKey, {
|
||||
path: params.path,
|
||||
access: status.access,
|
||||
requiredDirectories: status.requiredDirectories,
|
||||
requiredFiles: status.requiredFiles,
|
||||
});
|
||||
await registry.upsertCompanySettings(pluginId, companyId, {
|
||||
enabled: existing?.enabled ?? true,
|
||||
settingsJson: nextSettings,
|
||||
lastError: status.healthy ? null : status.problems.map((item: { message: string }) => item.message).join("; "),
|
||||
});
|
||||
return status;
|
||||
},
|
||||
|
||||
async status(params) {
|
||||
return inspectStoredLocalFolder(params.companyId, params.folderKey);
|
||||
},
|
||||
|
||||
async list(params) {
|
||||
const status = await inspectStoredLocalFolder(params.companyId, params.folderKey);
|
||||
assertConfiguredLocalFolder(status);
|
||||
const listing = await listPluginLocalFolderEntries(status.realPath!, {
|
||||
relativePath: params.relativePath,
|
||||
recursive: params.recursive,
|
||||
maxEntries: params.maxEntries,
|
||||
});
|
||||
return { ...listing, folderKey: params.folderKey };
|
||||
},
|
||||
|
||||
async readText(params) {
|
||||
const status = await inspectStoredLocalFolder(params.companyId, params.folderKey);
|
||||
assertConfiguredLocalFolder(status);
|
||||
return readPluginLocalFolderText(status.realPath!, params.relativePath);
|
||||
},
|
||||
|
||||
async writeTextAtomic(params) {
|
||||
const companyId = ensureCompanyId(params.companyId);
|
||||
await preparePluginLocalFolder({
|
||||
folderKey: params.folderKey,
|
||||
declaration: getLocalFolderDeclaration(params.folderKey),
|
||||
storedConfig: await getStoredLocalFolderConfig(companyId, params.folderKey),
|
||||
});
|
||||
const status = await inspectStoredLocalFolder(companyId, params.folderKey);
|
||||
assertWritableConfiguredLocalFolder(status);
|
||||
if (status.access !== "readWrite" || !status.writable) {
|
||||
throw new Error("Local folder is not configured for writes");
|
||||
}
|
||||
await writePluginLocalFolderTextAtomic(status.realPath!, params.relativePath, params.contents);
|
||||
return inspectStoredLocalFolder(companyId, params.folderKey);
|
||||
},
|
||||
},
|
||||
|
||||
state: {
|
||||
async get(params) {
|
||||
return stateStore.get(pluginId, params.scopeKind as any, params.stateKey, {
|
||||
|
|
@ -1013,6 +1151,77 @@ export function buildHostServices(
|
|||
updatedAt: (row?.updatedAt ?? project.updatedAt).toISOString(),
|
||||
};
|
||||
},
|
||||
async getManaged(params) {
|
||||
const companyId = ensureCompanyId(params.companyId);
|
||||
await ensurePluginAvailableForCompany(companyId);
|
||||
return projects.resolveManagedProject({
|
||||
companyId,
|
||||
pluginId,
|
||||
pluginKey,
|
||||
projectKey: params.projectKey,
|
||||
createIfMissing: false,
|
||||
});
|
||||
},
|
||||
async reconcileManaged(params) {
|
||||
const companyId = ensureCompanyId(params.companyId);
|
||||
await ensurePluginAvailableForCompany(companyId);
|
||||
return projects.resolveManagedProject({
|
||||
companyId,
|
||||
pluginId,
|
||||
pluginKey,
|
||||
projectKey: params.projectKey,
|
||||
});
|
||||
},
|
||||
async resetManaged(params) {
|
||||
const companyId = ensureCompanyId(params.companyId);
|
||||
await ensurePluginAvailableForCompany(companyId);
|
||||
return projects.resolveManagedProject({
|
||||
companyId,
|
||||
pluginId,
|
||||
pluginKey,
|
||||
projectKey: params.projectKey,
|
||||
reset: true,
|
||||
});
|
||||
},
|
||||
},
|
||||
|
||||
routines: {
|
||||
async managedGet(params) {
|
||||
const companyId = ensureCompanyId(params.companyId);
|
||||
await ensurePluginAvailableForCompany(companyId);
|
||||
return managedRoutines.get(params.routineKey, companyId);
|
||||
},
|
||||
async managedReconcile(params) {
|
||||
const companyId = ensureCompanyId(params.companyId);
|
||||
await ensurePluginAvailableForCompany(companyId);
|
||||
return managedRoutines.reconcile(params.routineKey, companyId, {
|
||||
assigneeAgentId: params.assigneeAgentId,
|
||||
projectId: params.projectId,
|
||||
});
|
||||
},
|
||||
async managedReset(params) {
|
||||
const companyId = ensureCompanyId(params.companyId);
|
||||
await ensurePluginAvailableForCompany(companyId);
|
||||
return managedRoutines.reset(params.routineKey, companyId, {
|
||||
assigneeAgentId: params.assigneeAgentId,
|
||||
projectId: params.projectId,
|
||||
});
|
||||
},
|
||||
async managedUpdate(params) {
|
||||
const companyId = ensureCompanyId(params.companyId);
|
||||
await ensurePluginAvailableForCompany(companyId);
|
||||
return managedRoutines.update(params.routineKey, companyId, {
|
||||
status: params.status,
|
||||
});
|
||||
},
|
||||
async managedRun(params) {
|
||||
const companyId = ensureCompanyId(params.companyId);
|
||||
await ensurePluginAvailableForCompany(companyId);
|
||||
return managedRoutines.run(params.routineKey, companyId, {
|
||||
assigneeAgentId: params.assigneeAgentId,
|
||||
projectId: params.projectId,
|
||||
});
|
||||
},
|
||||
},
|
||||
|
||||
issues: {
|
||||
|
|
@ -1031,8 +1240,12 @@ export function buildHostServices(
|
|||
async create(params) {
|
||||
const companyId = ensureCompanyId(params.companyId);
|
||||
await ensurePluginAvailableForCompany(companyId);
|
||||
const { actorAgentId, actorUserId, actorRunId, originKind, ...issueInput } = params;
|
||||
const normalizedOriginKind = normalizePluginOriginKind(originKind);
|
||||
const { actorAgentId, actorUserId, actorRunId, originKind, surfaceVisibility, ...issueInput } = params;
|
||||
const normalizedOriginKind = normalizePluginOriginKind(
|
||||
surfaceVisibility === "plugin_operation" && !originKind
|
||||
? pluginOperationIssueOriginKind(pluginKey)
|
||||
: originKind,
|
||||
);
|
||||
const issue = (await issues.create(companyId, {
|
||||
...(issueInput as any),
|
||||
originKind: normalizedOriginKind,
|
||||
|
|
@ -1641,6 +1854,21 @@ export function buildHostServices(
|
|||
if (!run) throw new Error("Agent wakeup was skipped by heartbeat policy");
|
||||
return { runId: run.id };
|
||||
},
|
||||
async managedGet(params) {
|
||||
const companyId = ensureCompanyId(params.companyId);
|
||||
await ensurePluginAvailableForCompany(companyId);
|
||||
return managedAgents.get(params.agentKey, companyId);
|
||||
},
|
||||
async managedReconcile(params) {
|
||||
const companyId = ensureCompanyId(params.companyId);
|
||||
await ensurePluginAvailableForCompany(companyId);
|
||||
return managedAgents.reconcile(params.agentKey, companyId);
|
||||
},
|
||||
async managedReset(params) {
|
||||
const companyId = ensureCompanyId(params.companyId);
|
||||
await ensurePluginAvailableForCompany(companyId);
|
||||
return managedAgents.reset(params.agentKey, companyId);
|
||||
},
|
||||
},
|
||||
|
||||
goals: {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue