mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-14 01:50:39 +09:00
[codex] Add LLM Wiki plugin host support (#5597)
## Thinking Path > - Paperclip orchestrates AI agents for zero-human companies. > - The plugin system needs host contracts and runtime support before large plugins can integrate cleanly. > - The source branch mixed the LLM Wiki package with supporting host/runtime work, managed plugin skills, root-level storage spaces, and a bookmarks reference plugin. > - [PAP-9173](/PAP/issues/PAP-9173) asked for the current branch to be split by file boundary: plugin package separately from everything else. > - [PAP-9188](/PAP/issues/PAP-9188) clarified that LLM Wiki may have plugin-local spaces, but Paperclip core should not reorganize top-level local storage into spaces. > - Follow-up review clarified that the bookmarks example should not ship in this PR either. > - This pull request contains the non-`packages/plugins/plugin-llm-wiki/` host/runtime work, keeps runtime state under the selected Paperclip instance root, and no longer includes the bookmarks example. ## What Changed - Added/updated plugin host contracts, SDK types, worker RPC plumbing, managed plugin skill support, and related server tests. - Removed the bookmarks example plugin package and its bundled-example/workspace references. - Removed the root-level local spaces CLI/migration surface and restored instance-root runtime defaults for config, db, logs, storage, secrets, workspaces, projects, and adapter homes. - Replaced shared root `space-paths` helpers with `home-paths` helpers for core runtime storage. - Tightened stranded recovery unique-conflict detection so concurrent recovery scans reuse the raced recovery issue when Postgres errors are wrapped. - Kept `packages/plugins/plugin-llm-wiki/` out of this PR diff; plugin-local spaces remain in the stacked plugin-only PR. ## Verification - `pnpm exec vitest run cli/src/__tests__/data-dir.test.ts cli/src/__tests__/home-paths.test.ts cli/src/__tests__/onboard.test.ts packages/shared/src/home-paths.test.ts packages/db/src/runtime-config.test.ts server/src/__tests__/agent-instructions-service.test.ts server/src/__tests__/claude-local-execute.test.ts server/src/__tests__/codex-local-execute.test.ts` - `pnpm exec vitest run packages/db/src/runtime-config.test.ts` - `pnpm exec vitest run server/src/__tests__/plugin-routes-authz.test.ts` - `pnpm --filter @paperclipai/server typecheck` - `pnpm exec vitest run server/src/__tests__/heartbeat-process-recovery.test.ts -t "reuses the raced stranded recovery issue"` skipped locally because embedded Postgres did not initialize on this macOS temp host; the code path was typechecked and is covered by Linux CI. - Boundary check: no core references remain for `PAPERCLIP_SPACE_ID`, `spaces migrate-default`, `@paperclipai/shared/space-paths`, `registerSpacesCommands`, or the removed bookmarks example. - Previous PR head `4f23e034` had green GitHub checks: `verify`, all four serialized server shards, `e2e`, `Canary Dry Run`, `policy`, Snyk, and `Greptile Review`. Current head `582f466d` is re-running checks after the bookmarks deletion. ## Risks - Plugin host changes touch shared runtime paths, so regressions would most likely appear in adapter startup, plugin loading, or local dev path defaults. - Removing the bookmarks example also removes one demonstration of plugin database namespaces plus local-folder persistence; remaining plugin examples still cover bundled example discovery and plugin host flows. - The plugin package itself is intentionally deferred to the stacked plugin-only PR, where LLM Wiki plugin-local spaces live. - Existing installs that tested the transient root-level spaces CLI should stop using it; this PR intentionally removes that unsupported migration surface before merge. > 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 GPT-5 Codex via Codex CLI, tool use and local code execution enabled; context window not exposed. ## 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, except where noted above for host-specific embedded Postgres initialization - [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 Stacked follow-up: PR #5592 contains only `packages/plugins/plugin-llm-wiki/` and targets this branch. --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
This commit is contained in:
parent
eb12c42009
commit
0096b56a1c
40 changed files with 1892 additions and 224 deletions
|
|
@ -98,6 +98,7 @@ export interface HostServices {
|
|||
list(params: WorkerToHostMethods["localFolders.list"][0]): Promise<WorkerToHostMethods["localFolders.list"][1]>;
|
||||
readText(params: WorkerToHostMethods["localFolders.readText"][0]): Promise<WorkerToHostMethods["localFolders.readText"][1]>;
|
||||
writeTextAtomic(params: WorkerToHostMethods["localFolders.writeTextAtomic"][0]): Promise<WorkerToHostMethods["localFolders.writeTextAtomic"][1]>;
|
||||
deleteFile(params: WorkerToHostMethods["localFolders.deleteFile"][0]): Promise<WorkerToHostMethods["localFolders.deleteFile"][1]>;
|
||||
};
|
||||
|
||||
/** Provides `state.get`, `state.set`, `state.delete`. */
|
||||
|
|
@ -189,6 +190,13 @@ export interface HostServices {
|
|||
managedRun(params: WorkerToHostMethods["routines.managed.run"][0]): Promise<WorkerToHostMethods["routines.managed.run"][1]>;
|
||||
};
|
||||
|
||||
/** Provides `skills.managed.*`. */
|
||||
skills: {
|
||||
managedGet(params: WorkerToHostMethods["skills.managed.get"][0]): Promise<WorkerToHostMethods["skills.managed.get"][1]>;
|
||||
managedReconcile(params: WorkerToHostMethods["skills.managed.reconcile"][0]): Promise<WorkerToHostMethods["skills.managed.reconcile"][1]>;
|
||||
managedReset(params: WorkerToHostMethods["skills.managed.reset"][0]): Promise<WorkerToHostMethods["skills.managed.reset"][1]>;
|
||||
};
|
||||
|
||||
/** Provides issue read/write, relation, checkout, wakeup, summary, comment methods. */
|
||||
issues: {
|
||||
list(params: WorkerToHostMethods["issues.list"][0]): Promise<WorkerToHostMethods["issues.list"][1]>;
|
||||
|
|
@ -313,6 +321,7 @@ const METHOD_CAPABILITY_MAP: Record<WorkerToHostMethodName, PluginCapability | n
|
|||
"localFolders.list": "local.folders",
|
||||
"localFolders.readText": "local.folders",
|
||||
"localFolders.writeTextAtomic": "local.folders",
|
||||
"localFolders.deleteFile": "local.folders",
|
||||
|
||||
// State
|
||||
"state.get": "plugin.state.read",
|
||||
|
|
@ -367,6 +376,9 @@ const METHOD_CAPABILITY_MAP: Record<WorkerToHostMethodName, PluginCapability | n
|
|||
"routines.managed.reset": "routines.managed",
|
||||
"routines.managed.update": "routines.managed",
|
||||
"routines.managed.run": "routines.managed",
|
||||
"skills.managed.get": "skills.managed",
|
||||
"skills.managed.reconcile": "skills.managed",
|
||||
"skills.managed.reset": "skills.managed",
|
||||
|
||||
// Issues
|
||||
"issues.list": "issues.read",
|
||||
|
|
@ -501,6 +513,9 @@ export function createHostClientHandlers(
|
|||
"localFolders.writeTextAtomic": gated("localFolders.writeTextAtomic", async (params) => {
|
||||
return services.localFolders.writeTextAtomic(params);
|
||||
}),
|
||||
"localFolders.deleteFile": gated("localFolders.deleteFile", async (params) => {
|
||||
return services.localFolders.deleteFile(params);
|
||||
}),
|
||||
|
||||
// State
|
||||
"state.get": gated("state.get", async (params) => {
|
||||
|
|
@ -620,6 +635,17 @@ export function createHostClientHandlers(
|
|||
return services.routines.managedRun(params);
|
||||
}),
|
||||
|
||||
// Skills
|
||||
"skills.managed.get": gated("skills.managed.get", async (params) => {
|
||||
return services.skills.managedGet(params);
|
||||
}),
|
||||
"skills.managed.reconcile": gated("skills.managed.reconcile", async (params) => {
|
||||
return services.skills.managedReconcile(params);
|
||||
}),
|
||||
"skills.managed.reset": gated("skills.managed.reset", async (params) => {
|
||||
return services.skills.managedReset(params);
|
||||
}),
|
||||
|
||||
// Issues
|
||||
"issues.list": gated("issues.list", async (params) => {
|
||||
return services.issues.list(params);
|
||||
|
|
|
|||
|
|
@ -197,6 +197,7 @@ export type {
|
|||
PluginStateClient,
|
||||
PluginEntitiesClient,
|
||||
PluginProjectsClient,
|
||||
PluginSkillsClient,
|
||||
PluginCompaniesClient,
|
||||
PluginIssuesClient,
|
||||
PluginIssueMutationActor,
|
||||
|
|
@ -268,6 +269,10 @@ export type {
|
|||
PluginManagedProjectResolution,
|
||||
PluginManagedRoutineDeclaration,
|
||||
PluginManagedRoutineResolution,
|
||||
PluginManagedSkillDeclaration,
|
||||
PluginManagedSkillFileDeclaration,
|
||||
PluginManagedSkillResolution,
|
||||
CompanySkill,
|
||||
PluginManagedResourceKind,
|
||||
PluginManagedResourceRef,
|
||||
PluginUiSlotDeclaration,
|
||||
|
|
|
|||
|
|
@ -27,11 +27,13 @@ import type {
|
|||
IssueComment,
|
||||
IssueDocument,
|
||||
IssueDocumentSummary,
|
||||
IssueAssigneeAdapterOverrides,
|
||||
IssueThreadInteraction,
|
||||
CreateIssueThreadInteraction,
|
||||
PluginManagedAgentResolution,
|
||||
PluginManagedProjectResolution,
|
||||
PluginManagedRoutineResolution,
|
||||
PluginManagedSkillResolution,
|
||||
Routine,
|
||||
RoutineRun,
|
||||
Agent,
|
||||
|
|
@ -611,6 +613,10 @@ export interface WorkerToHostMethods {
|
|||
},
|
||||
result: PluginLocalFolderStatus,
|
||||
];
|
||||
"localFolders.deleteFile": [
|
||||
params: { companyId: string; folderKey: string; relativePath: string },
|
||||
result: PluginLocalFolderStatus,
|
||||
];
|
||||
|
||||
// State
|
||||
"state.get": [
|
||||
|
|
@ -821,6 +827,18 @@ export interface WorkerToHostMethods {
|
|||
},
|
||||
result: RoutineRun,
|
||||
];
|
||||
"skills.managed.get": [
|
||||
params: { skillKey: string; companyId: string },
|
||||
result: PluginManagedSkillResolution,
|
||||
];
|
||||
"skills.managed.reconcile": [
|
||||
params: { skillKey: string; companyId: string },
|
||||
result: PluginManagedSkillResolution,
|
||||
];
|
||||
"skills.managed.reset": [
|
||||
params: { skillKey: string; companyId: string },
|
||||
result: PluginManagedSkillResolution,
|
||||
];
|
||||
|
||||
// Issues
|
||||
"issues.list": [
|
||||
|
|
@ -852,12 +870,12 @@ export interface WorkerToHostMethods {
|
|||
title: string;
|
||||
description?: string;
|
||||
status?: string;
|
||||
workMode?: string;
|
||||
priority?: string;
|
||||
assigneeAgentId?: string;
|
||||
assigneeUserId?: string | null;
|
||||
requestDepth?: number;
|
||||
billingCode?: string | null;
|
||||
assigneeAdapterOverrides?: IssueAssigneeAdapterOverrides | null;
|
||||
surfaceVisibility?: string | null;
|
||||
originKind?: string | null;
|
||||
originId?: string | null;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import type {
|
|||
PluginIssueOriginKind,
|
||||
PluginManagedAgentResolution,
|
||||
PluginManagedRoutineResolution,
|
||||
PluginManagedSkillResolution,
|
||||
CompanySkill,
|
||||
Company,
|
||||
Project,
|
||||
Routine,
|
||||
|
|
@ -33,6 +35,8 @@ import type {
|
|||
PluginWorkspace,
|
||||
AgentSession,
|
||||
AgentSessionEvent,
|
||||
PluginLocalFolderEntry,
|
||||
PluginLocalFolderStatus,
|
||||
} from "./types.js";
|
||||
import type {
|
||||
PluginEnvironmentValidateConfigParams,
|
||||
|
|
@ -434,6 +438,8 @@ export function createTestHarness(options: TestHarnessOptions): TestHarness {
|
|||
const agents = new Map<string, Agent>();
|
||||
const goals = new Map<string, Goal>();
|
||||
const projectWorkspaces = new Map<string, PluginWorkspace[]>();
|
||||
const localFolderStatuses = new Map<string, PluginLocalFolderStatus>();
|
||||
const localFolderFiles = new Map<string, string>();
|
||||
|
||||
const sessions = new Map<string, AgentSession>();
|
||||
const sessionEventCallbacks = new Map<string, (event: AgentSessionEvent) => void>();
|
||||
|
|
@ -445,6 +451,43 @@ export function createTestHarness(options: TestHarnessOptions): TestHarness {
|
|||
const actionHandlers = new Map<string, (params: Record<string, unknown>) => Promise<unknown>>();
|
||||
const toolHandlers = new Map<string, (params: unknown, runCtx: ToolRunContext) => Promise<ToolResult>>();
|
||||
|
||||
function localFolderKey(companyId: string, folderKey: string): string {
|
||||
return `${companyId}:${folderKey}`;
|
||||
}
|
||||
|
||||
function localFolderFileKey(companyId: string, folderKey: string, relativePath: string): string {
|
||||
return `${localFolderKey(companyId, folderKey)}:${relativePath}`;
|
||||
}
|
||||
|
||||
function normalizeLocalFolderRelativePath(relativePath: string): string {
|
||||
const parts: string[] = [];
|
||||
for (const segment of relativePath.split(/[\\/]+/)) {
|
||||
if (!segment || segment === ".") continue;
|
||||
if (segment === "..") throw new Error("Local folder path traversal is not allowed");
|
||||
parts.push(segment);
|
||||
}
|
||||
return parts.join("/");
|
||||
}
|
||||
|
||||
function notConfiguredLocalFolderStatus(folderKey: string): PluginLocalFolderStatus {
|
||||
return {
|
||||
folderKey,
|
||||
configured: false,
|
||||
path: null,
|
||||
realPath: null,
|
||||
access: "readWrite",
|
||||
readable: false,
|
||||
writable: false,
|
||||
requiredDirectories: [],
|
||||
requiredFiles: [],
|
||||
missingDirectories: [],
|
||||
missingFiles: [],
|
||||
healthy: false,
|
||||
problems: [{ code: "not_configured", message: "No local folder path is configured." }],
|
||||
checkedAt: new Date().toISOString(),
|
||||
};
|
||||
}
|
||||
|
||||
function issueRelationSummary(issueId: string) {
|
||||
const issue = issues.get(issueId);
|
||||
if (!issue) throw new Error(`Issue not found: ${issueId}`);
|
||||
|
|
@ -541,7 +584,7 @@ export function createTestHarness(options: TestHarnessOptions): TestHarness {
|
|||
},
|
||||
async configure(input) {
|
||||
requireCapability(manifest, capabilitySet, "local.folders");
|
||||
return {
|
||||
const status = {
|
||||
folderKey: input.folderKey,
|
||||
configured: true,
|
||||
path: input.path,
|
||||
|
|
@ -556,58 +599,98 @@ export function createTestHarness(options: TestHarnessOptions): TestHarness {
|
|||
healthy: true,
|
||||
problems: [],
|
||||
checkedAt: new Date().toISOString(),
|
||||
};
|
||||
} satisfies PluginLocalFolderStatus;
|
||||
localFolderStatuses.set(localFolderKey(input.companyId, input.folderKey), status);
|
||||
return status;
|
||||
},
|
||||
async status(_companyId, folderKey) {
|
||||
async status(companyId, folderKey) {
|
||||
requireCapability(manifest, capabilitySet, "local.folders");
|
||||
return {
|
||||
folderKey,
|
||||
configured: false,
|
||||
path: null,
|
||||
realPath: null,
|
||||
access: "readWrite",
|
||||
readable: false,
|
||||
writable: false,
|
||||
requiredDirectories: [],
|
||||
requiredFiles: [],
|
||||
missingDirectories: [],
|
||||
missingFiles: [],
|
||||
healthy: false,
|
||||
problems: [{ code: "not_configured", message: "No local folder path is configured." }],
|
||||
checkedAt: new Date().toISOString(),
|
||||
};
|
||||
return localFolderStatuses.get(localFolderKey(companyId, folderKey)) ?? notConfiguredLocalFolderStatus(folderKey);
|
||||
},
|
||||
async list(_companyId, folderKey, options) {
|
||||
async list(companyId, folderKey, options) {
|
||||
requireCapability(manifest, capabilitySet, "local.folders");
|
||||
const status = localFolderStatuses.get(localFolderKey(companyId, folderKey));
|
||||
if (!status?.configured) throw new Error("Local folder is not configured");
|
||||
const prefix = normalizeLocalFolderRelativePath(options?.relativePath ?? "");
|
||||
const prefixWithSlash = prefix ? `${prefix}/` : "";
|
||||
const entries = new Map<string, PluginLocalFolderEntry>();
|
||||
for (const [key, contents] of localFolderFiles) {
|
||||
const filePrefix = `${localFolderKey(companyId, folderKey)}:`;
|
||||
if (!key.startsWith(filePrefix)) continue;
|
||||
const filePath = key.slice(filePrefix.length);
|
||||
if (prefix && filePath !== prefix && !filePath.startsWith(prefixWithSlash)) continue;
|
||||
const remainder = prefix ? filePath.slice(prefixWithSlash.length) : filePath;
|
||||
const [name] = remainder.split("/");
|
||||
if (!name) continue;
|
||||
const entryPath = prefix ? `${prefix}/${name}` : name;
|
||||
const isNested = remainder.includes("/");
|
||||
if (!options?.recursive && isNested) {
|
||||
entries.set(entryPath, {
|
||||
path: entryPath,
|
||||
name,
|
||||
kind: "directory",
|
||||
size: null,
|
||||
modifiedAt: null,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
entries.set(filePath, {
|
||||
path: filePath,
|
||||
name: filePath.split("/").pop() ?? filePath,
|
||||
kind: "file",
|
||||
size: Buffer.byteLength(contents, "utf8"),
|
||||
modifiedAt: null,
|
||||
});
|
||||
}
|
||||
const maxEntries = options?.maxEntries && options.maxEntries > 0 ? options.maxEntries : entries.size;
|
||||
const allEntries = [...entries.values()].sort((a, b) => a.path.localeCompare(b.path));
|
||||
return {
|
||||
folderKey,
|
||||
relativePath: options?.relativePath ?? null,
|
||||
entries: [],
|
||||
truncated: false,
|
||||
entries: allEntries.slice(0, maxEntries),
|
||||
truncated: allEntries.length > maxEntries,
|
||||
};
|
||||
},
|
||||
async readText() {
|
||||
async readText(companyId, folderKey, relativePath) {
|
||||
requireCapability(manifest, capabilitySet, "local.folders");
|
||||
throw new Error("Test harness local folder readText is not implemented");
|
||||
const normalizedPath = normalizeLocalFolderRelativePath(relativePath);
|
||||
const contents = localFolderFiles.get(localFolderFileKey(companyId, folderKey, normalizedPath));
|
||||
if (contents === undefined) throw new Error(`Local folder file not found: ${relativePath}`);
|
||||
return contents;
|
||||
},
|
||||
async writeTextAtomic(_companyId, folderKey) {
|
||||
async writeTextAtomic(companyId, folderKey, relativePath, contents) {
|
||||
requireCapability(manifest, capabilitySet, "local.folders");
|
||||
return {
|
||||
const status = localFolderStatuses.get(localFolderKey(companyId, folderKey)) ?? {
|
||||
folderKey,
|
||||
configured: false,
|
||||
path: null,
|
||||
realPath: null,
|
||||
configured: true,
|
||||
path: `memory://${manifest.id}/${companyId}/${folderKey}`,
|
||||
realPath: `memory://${manifest.id}/${companyId}/${folderKey}`,
|
||||
access: "readWrite",
|
||||
readable: false,
|
||||
writable: false,
|
||||
readable: true,
|
||||
writable: true,
|
||||
requiredDirectories: [],
|
||||
requiredFiles: [],
|
||||
missingDirectories: [],
|
||||
missingFiles: [],
|
||||
healthy: false,
|
||||
problems: [{ code: "not_configured", message: "No local folder path is configured." }],
|
||||
healthy: true,
|
||||
problems: [],
|
||||
checkedAt: new Date().toISOString(),
|
||||
};
|
||||
} satisfies PluginLocalFolderStatus;
|
||||
if (status.access !== "readWrite" || !status.writable) {
|
||||
throw new Error("Local folder is not configured for writes");
|
||||
}
|
||||
localFolderStatuses.set(localFolderKey(companyId, folderKey), status);
|
||||
localFolderFiles.set(localFolderFileKey(companyId, folderKey, normalizeLocalFolderRelativePath(relativePath)), contents);
|
||||
return status;
|
||||
},
|
||||
async deleteFile(companyId, folderKey, relativePath) {
|
||||
requireCapability(manifest, capabilitySet, "local.folders");
|
||||
const status = localFolderStatuses.get(localFolderKey(companyId, folderKey)) ?? notConfiguredLocalFolderStatus(folderKey);
|
||||
if (status.configured && (status.access !== "readWrite" || !status.writable)) {
|
||||
throw new Error("Local folder is not configured for writes");
|
||||
}
|
||||
localFolderFiles.delete(localFolderFileKey(companyId, folderKey, normalizeLocalFolderRelativePath(relativePath)));
|
||||
return status;
|
||||
},
|
||||
},
|
||||
events: {
|
||||
|
|
@ -991,14 +1074,14 @@ export function createTestHarness(options: TestHarnessOptions): TestHarness {
|
|||
concurrencyPolicy: declaration.concurrencyPolicy ?? "coalesce_if_active",
|
||||
catchUpPolicy: declaration.catchUpPolicy ?? "skip_missed",
|
||||
variables: declaration.variables ?? [],
|
||||
latestRevisionId: null,
|
||||
latestRevisionNumber: 1,
|
||||
createdByAgentId: null,
|
||||
createdByUserId: null,
|
||||
updatedByAgentId: null,
|
||||
updatedByUserId: null,
|
||||
lastTriggeredAt: null,
|
||||
lastEnqueuedAt: null,
|
||||
latestRevisionId: null,
|
||||
latestRevisionNumber: 1,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
managedByPlugin: {
|
||||
|
|
@ -1087,6 +1170,174 @@ export function createTestHarness(options: TestHarnessOptions): TestHarness {
|
|||
},
|
||||
},
|
||||
},
|
||||
skills: {
|
||||
managed: {
|
||||
async get(skillKey, companyId) {
|
||||
requireCapability(manifest, capabilitySet, "skills.managed");
|
||||
const declaration = manifest.skills?.find((skill) => skill.skillKey === skillKey);
|
||||
if (!declaration) {
|
||||
return {
|
||||
pluginKey: manifest.id,
|
||||
resourceKind: "skill",
|
||||
resourceKey: skillKey,
|
||||
companyId,
|
||||
skillId: null,
|
||||
skill: null,
|
||||
status: "missing",
|
||||
defaultDrift: null,
|
||||
} satisfies PluginManagedSkillResolution;
|
||||
}
|
||||
const externalId = `${manifest.id}:skill:${skillKey}`;
|
||||
const existingEntity = [...entities.values()].find((entity) =>
|
||||
entity.entityType === "managed_resource"
|
||||
&& entity.scopeKind === "company"
|
||||
&& entity.scopeId === companyId
|
||||
&& entity.externalId === externalId
|
||||
);
|
||||
const existingSkill = existingEntity?.data?.skill as CompanySkill | undefined;
|
||||
if (existingSkill && existingSkill.companyId === companyId) {
|
||||
return {
|
||||
pluginKey: manifest.id,
|
||||
resourceKind: "skill",
|
||||
resourceKey: skillKey,
|
||||
companyId,
|
||||
skillId: existingSkill.id,
|
||||
skill: existingSkill,
|
||||
status: "resolved",
|
||||
defaultDrift: null,
|
||||
} satisfies PluginManagedSkillResolution;
|
||||
}
|
||||
return {
|
||||
pluginKey: manifest.id,
|
||||
resourceKind: "skill",
|
||||
resourceKey: skillKey,
|
||||
companyId,
|
||||
skillId: null,
|
||||
skill: null,
|
||||
status: "missing",
|
||||
defaultDrift: null,
|
||||
} satisfies PluginManagedSkillResolution;
|
||||
},
|
||||
async reconcile(skillKey, companyId) {
|
||||
const existing = await this.get(skillKey, companyId);
|
||||
if (existing.skill) return existing;
|
||||
const declaration = manifest.skills?.find((skill) => skill.skillKey === skillKey);
|
||||
if (!declaration) return existing;
|
||||
const now = new Date();
|
||||
const skill = {
|
||||
id: randomUUID(),
|
||||
companyId,
|
||||
key: `plugin/${manifest.id.replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "")}/${skillKey}`,
|
||||
slug: declaration.slug ?? skillKey,
|
||||
name: declaration.displayName,
|
||||
description: declaration.description ?? null,
|
||||
markdown: declaration.markdown ?? `# ${declaration.displayName}\n`,
|
||||
sourceType: "catalog",
|
||||
sourceLocator: null,
|
||||
sourceRef: null,
|
||||
trustLevel: "markdown_only",
|
||||
compatibility: "compatible",
|
||||
fileInventory: [{ path: "SKILL.md", kind: "skill" }],
|
||||
metadata: {
|
||||
sourceKind: "catalog",
|
||||
pluginManagedResource: {
|
||||
pluginKey: manifest.id,
|
||||
resourceKind: "skill",
|
||||
resourceKey: skillKey,
|
||||
},
|
||||
},
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
} satisfies CompanySkill;
|
||||
const nowIso = now.toISOString();
|
||||
const record: PluginEntityRecord = {
|
||||
id: randomUUID(),
|
||||
entityType: "managed_resource",
|
||||
scopeKind: "company",
|
||||
scopeId: companyId,
|
||||
externalId: `${manifest.id}:skill:${skillKey}`,
|
||||
title: declaration.displayName,
|
||||
status: null,
|
||||
data: { resourceKind: "skill", resourceKey: skillKey, skillId: skill.id, skill },
|
||||
createdAt: nowIso,
|
||||
updatedAt: nowIso,
|
||||
};
|
||||
entities.set(record.id, record);
|
||||
return {
|
||||
pluginKey: manifest.id,
|
||||
resourceKind: "skill",
|
||||
resourceKey: skillKey,
|
||||
companyId,
|
||||
skillId: skill.id,
|
||||
skill,
|
||||
status: "created",
|
||||
defaultDrift: null,
|
||||
} satisfies PluginManagedSkillResolution;
|
||||
},
|
||||
async reset(skillKey, companyId) {
|
||||
requireCapability(manifest, capabilitySet, "skills.managed");
|
||||
const existing = await this.get(skillKey, companyId);
|
||||
const declaration = manifest.skills?.find((skill) => skill.skillKey === skillKey);
|
||||
if (!declaration) return existing;
|
||||
const now = new Date();
|
||||
const skill = {
|
||||
id: existing.skill?.id ?? randomUUID(),
|
||||
companyId,
|
||||
key: `plugin/${manifest.id.replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "")}/${skillKey}`,
|
||||
slug: declaration.slug ?? skillKey,
|
||||
name: declaration.displayName,
|
||||
description: declaration.description ?? null,
|
||||
markdown: declaration.markdown ?? `# ${declaration.displayName}\n`,
|
||||
sourceType: "catalog",
|
||||
sourceLocator: null,
|
||||
sourceRef: null,
|
||||
trustLevel: "markdown_only",
|
||||
compatibility: "compatible",
|
||||
fileInventory: [{ path: "SKILL.md", kind: "skill" }],
|
||||
metadata: {
|
||||
sourceKind: "catalog",
|
||||
pluginManagedResource: {
|
||||
pluginKey: manifest.id,
|
||||
resourceKind: "skill",
|
||||
resourceKey: skillKey,
|
||||
},
|
||||
},
|
||||
createdAt: existing.skill?.createdAt ?? now,
|
||||
updatedAt: now,
|
||||
} satisfies CompanySkill;
|
||||
const nowIso = now.toISOString();
|
||||
const existingEntity = [...entities.values()].find((entity) =>
|
||||
entity.entityType === "managed_resource" &&
|
||||
entity.scopeKind === "company" &&
|
||||
entity.scopeId === companyId &&
|
||||
entity.externalId === `${manifest.id}:skill:${skillKey}`,
|
||||
);
|
||||
const record: PluginEntityRecord = {
|
||||
id: existingEntity?.id ?? randomUUID(),
|
||||
entityType: "managed_resource",
|
||||
scopeKind: "company",
|
||||
scopeId: companyId,
|
||||
externalId: `${manifest.id}:skill:${skillKey}`,
|
||||
title: declaration.displayName,
|
||||
status: null,
|
||||
data: { resourceKind: "skill", resourceKey: skillKey, skillId: skill.id, skill },
|
||||
createdAt: existingEntity?.createdAt ?? nowIso,
|
||||
updatedAt: nowIso,
|
||||
};
|
||||
entities.set(record.id, record);
|
||||
return {
|
||||
pluginKey: manifest.id,
|
||||
resourceKind: "skill",
|
||||
resourceKey: skillKey,
|
||||
companyId,
|
||||
skillId: skill.id,
|
||||
skill,
|
||||
status: "reset",
|
||||
defaultDrift: null,
|
||||
} satisfies PluginManagedSkillResolution;
|
||||
},
|
||||
},
|
||||
},
|
||||
companies: {
|
||||
async list(input) {
|
||||
requireCapability(manifest, capabilitySet, "companies.read");
|
||||
|
|
@ -1147,7 +1398,7 @@ export function createTestHarness(options: TestHarnessOptions): TestHarness {
|
|||
title: input.title,
|
||||
description: input.description ?? null,
|
||||
status: input.status ?? "todo",
|
||||
workMode: input.workMode ?? "standard",
|
||||
workMode: "standard",
|
||||
priority: input.priority ?? "medium",
|
||||
assigneeAgentId: input.assigneeAgentId ?? null,
|
||||
assigneeUserId: input.assigneeUserId ?? null,
|
||||
|
|
@ -1164,7 +1415,7 @@ export function createTestHarness(options: TestHarnessOptions): TestHarness {
|
|||
originRunId: input.originRunId ?? null,
|
||||
requestDepth: input.requestDepth ?? 0,
|
||||
billingCode: input.billingCode ?? null,
|
||||
assigneeAdapterOverrides: null,
|
||||
assigneeAdapterOverrides: input.assigneeAdapterOverrides ?? null,
|
||||
executionWorkspaceId: input.executionWorkspaceId ?? null,
|
||||
executionWorkspacePreference: input.executionWorkspacePreference ?? null,
|
||||
executionWorkspaceSettings: input.executionWorkspaceSettings ?? null,
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import type {
|
|||
IssueDocument,
|
||||
IssueDocumentSummary,
|
||||
IssueRelationIssueSummary,
|
||||
IssueAssigneeAdapterOverrides,
|
||||
IssueThreadInteraction,
|
||||
SuggestTasksInteraction,
|
||||
AskUserQuestionsInteraction,
|
||||
|
|
@ -32,6 +33,8 @@ import type {
|
|||
PluginManagedAgentResolution,
|
||||
PluginManagedProjectResolution,
|
||||
PluginManagedRoutineResolution,
|
||||
PluginManagedSkillResolution,
|
||||
CompanySkill,
|
||||
Routine,
|
||||
RoutineRun,
|
||||
Agent,
|
||||
|
|
@ -54,6 +57,10 @@ export type {
|
|||
PluginManagedProjectResolution,
|
||||
PluginManagedRoutineDeclaration,
|
||||
PluginManagedRoutineResolution,
|
||||
PluginManagedSkillDeclaration,
|
||||
PluginManagedSkillFileDeclaration,
|
||||
PluginManagedSkillResolution,
|
||||
CompanySkill,
|
||||
Routine,
|
||||
RoutineRun,
|
||||
PluginLocalFolderDeclaration,
|
||||
|
|
@ -450,6 +457,8 @@ export interface PluginLocalFoldersClient {
|
|||
relativePath: string,
|
||||
contents: string,
|
||||
): Promise<PluginLocalFolderStatus>;
|
||||
/** Delete a file below a configured folder after containment checks. Missing files are treated as already deleted. */
|
||||
deleteFile(companyId: string, folderKey: string, relativePath: string): Promise<PluginLocalFolderStatus>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -840,6 +849,19 @@ export interface PluginRoutinesClient {
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* `ctx.skills` — resolve and reconcile plugin-managed company skills.
|
||||
*
|
||||
* Requires `skills.managed` capability.
|
||||
*/
|
||||
export interface PluginSkillsClient {
|
||||
managed: {
|
||||
get(skillKey: string, companyId: string): Promise<PluginManagedSkillResolution>;
|
||||
reconcile(skillKey: string, companyId: string): Promise<PluginManagedSkillResolution>;
|
||||
reset(skillKey: string, companyId: string): Promise<PluginManagedSkillResolution>;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* `ctx.data` — register `getData` handlers that back `usePluginData()` in the
|
||||
* plugin's frontend components.
|
||||
|
|
@ -1257,12 +1279,12 @@ export interface PluginIssuesClient {
|
|||
title: string;
|
||||
description?: string;
|
||||
status?: Issue["status"];
|
||||
workMode?: Issue["workMode"];
|
||||
priority?: Issue["priority"];
|
||||
assigneeAgentId?: string;
|
||||
assigneeUserId?: string | null;
|
||||
requestDepth?: number;
|
||||
billingCode?: string | null;
|
||||
assigneeAdapterOverrides?: IssueAssigneeAdapterOverrides | null;
|
||||
surfaceVisibility?: IssueSurfaceVisibility;
|
||||
originKind?: PluginIssueOriginKind;
|
||||
originId?: string | null;
|
||||
|
|
@ -1281,7 +1303,6 @@ export interface PluginIssuesClient {
|
|||
| "title"
|
||||
| "description"
|
||||
| "status"
|
||||
| "workMode"
|
||||
| "priority"
|
||||
| "assigneeAgentId"
|
||||
| "assigneeUserId"
|
||||
|
|
@ -1624,6 +1645,9 @@ export interface PluginContext {
|
|||
/** Resolve and reconcile plugin-managed routines. Requires `routines.managed`. */
|
||||
routines: PluginRoutinesClient;
|
||||
|
||||
/** Resolve and reconcile plugin-managed company skills. Requires `skills.managed`. */
|
||||
skills: PluginSkillsClient;
|
||||
|
||||
/** Read company metadata. Requires `companies.read`. */
|
||||
companies: PluginCompaniesClient;
|
||||
|
||||
|
|
|
|||
|
|
@ -430,6 +430,10 @@ export function startWorkerRpcHost(options: WorkerRpcHostOptions): WorkerRpcHost
|
|||
contents,
|
||||
});
|
||||
},
|
||||
|
||||
async deleteFile(companyId: string, folderKey: string, relativePath: string) {
|
||||
return callHost("localFolders.deleteFile", { companyId, folderKey, relativePath });
|
||||
},
|
||||
},
|
||||
|
||||
events: {
|
||||
|
|
@ -671,6 +675,20 @@ export function startWorkerRpcHost(options: WorkerRpcHostOptions): WorkerRpcHost
|
|||
},
|
||||
},
|
||||
|
||||
skills: {
|
||||
managed: {
|
||||
async get(skillKey: string, companyId: string) {
|
||||
return callHost("skills.managed.get", { skillKey, companyId });
|
||||
},
|
||||
async reconcile(skillKey: string, companyId: string) {
|
||||
return callHost("skills.managed.reconcile", { skillKey, companyId });
|
||||
},
|
||||
async reset(skillKey: string, companyId: string) {
|
||||
return callHost("skills.managed.reset", { skillKey, companyId });
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
companies: {
|
||||
async list(input) {
|
||||
return callHost("companies.list", {
|
||||
|
|
@ -714,12 +732,12 @@ export function startWorkerRpcHost(options: WorkerRpcHostOptions): WorkerRpcHost
|
|||
title: input.title,
|
||||
description: input.description,
|
||||
status: input.status,
|
||||
workMode: input.workMode,
|
||||
priority: input.priority,
|
||||
assigneeAgentId: input.assigneeAgentId,
|
||||
assigneeUserId: input.assigneeUserId,
|
||||
requestDepth: input.requestDepth,
|
||||
billingCode: input.billingCode,
|
||||
assigneeAdapterOverrides: input.assigneeAdapterOverrides,
|
||||
surfaceVisibility: input.surfaceVisibility,
|
||||
originKind: input.originKind,
|
||||
originId: input.originId,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue