mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-29 23:56:43 +01:00
External object references across issue surfaces (#8512)
## Thinking Path > - Paperclip is the open source control plane people use to coordinate AI agents, issues, approvals, comments, and work products. > - The involved subsystem is issue context: markdown links, issue properties, related work, lists, filters, inbox/sidebar status, and plugin-provided external context. > - The gap is that URLs to external systems currently remain mostly plain links, so humans and agents must manually open them to understand status, identity, and liveness. > - This matters because external work objects such as GitHub issues and pull requests are part of the operational state of a Paperclip company. > - The implementation keeps core provider-neutral: shared contracts, storage, sync, routes, and UI surfaces live in core while providers can contribute detection and status resolution. > - This pull request adds the external object reference foundation, GitHub provider support, issue-surface rendering, filters, sidebar/list/inbox signals, and test/story coverage. > - The benefit is that linked external work becomes inspectable Paperclip context without hardcoding every provider directly into the UI. ## Linked Issues or Issue Description No public GitHub issue exists for this work. Feature request: - Problem: URLs in Paperclip issues, comments, documents, and related surfaces do not expose provider status or object identity inline. - Proposed behavior: detect supported external object URLs, persist normalized references, refresh provider status, and render concise status-aware links across issue surfaces. - Users affected: board users, agents, and maintainers who triage issues containing external work links. - Acceptance: external object references are company-scoped, provider-extensible, visible in key issue surfaces, filterable where relevant, and covered by focused shared/server/UI tests. Related PR search: - No open duplicate PRs found for `external object references`. - Closed related prior attempt: #4556. ## What Changed - Added shared external-object contracts, validators, status/liveness helpers, and plugin protocol declarations. - Added database schema and additive migrations for external objects, source mentions, and display metadata. - Added server services/routes for detecting, syncing, summarizing, refreshing, and resolving external objects across issues, documents, comments, projects, and plugins. - Added a GitHub external-object provider plus plugin SDK authoring docs. - Wired UI presentation across markdown links, comments, issue chat, documents, properties, related work, issue rows, filters, inbox/sidebar badges, and Storybook stories. - Rebasing cleanup: moved the branch onto current `master`, repaired stale worktree provision config, hardened environment-sensitive tests/mocks, and removed committed screenshot artifacts from the PR branch to keep the reviewable file set below tool limits. ## Verification - `pnpm exec vitest run packages/shared/src/external-objects.test.ts server/src/__tests__/external-object-routes.test.ts server/src/__tests__/external-objects-service.test.ts ui/src/components/ExternalObjectPill.test.tsx ui/src/lib/external-objects.test.ts` passed after rebasing: 5 files, 56 tests. - Historical branch verification before this PR creation included `pnpm test:run`, `pnpm -r typecheck`, and `pnpm build`; this PR body does not claim those were rerun after the final rebase. ## Risks - Medium: this adds a new cross-surface sync path on issue/document/comment writes. The implementation uses safe sync wrappers so external-object failures warn instead of blocking core mutations. - Medium: the migrations introduce new tables and indexes. They are additive and company-scoped. - Medium: provider-specific URL parsing can miss or misclassify edge cases. Shared canonicalization tests and provider tests cover current GitHub shapes. - Low: UI badge/filter behavior could add visual noise for object-heavy issues; component tests and Storybook stories cover the intended surfaces. > Roadmap checked: `ROADMAP.md` references the plugin system as the current extension path and does not list a duplicate core feature. Related long-range docs discuss external references, work products, preview URLs, and plugin extension points; this PR implements the scoped external-object reference foundation. ## Model Used OpenAI Codex, GPT-5 coding-agent runtime, with shell and GitHub CLI tool use. Reasoning mode: medium. Exact deployed runtime model ID and context window were not exposed in the environment. ## 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:
1 parent
cd38c150b0
commit
2dbaf4a7fa
97 files changed
+8217
-84
No files matched your search
@@ -341,6 +341,10 @@ Declare in `manifest.capabilities`. Grouped by scope:
|
||||
| | `telemetry.track` |
|
||||
| | `database.namespace.migrate` |
|
||||
| | `database.namespace.write` |
|
||||
| | `external.objects.detect` |
|
||||
| | `external.objects.read` |
|
||||
| | `external.objects.write` |
|
||||
| | `external.objects.refresh` |
|
||||
| **Instance** | `instance.settings.register` |
|
||||
| | `plugin.state.read` |
|
||||
| | `plugin.state.write` |
|
||||
@@ -372,6 +376,42 @@ Declare in `manifest.capabilities`. Grouped by scope:
|
||||
|
||||
Full list in code: import `PLUGIN_CAPABILITIES` from `@paperclipai/plugin-sdk`.
|
||||
|
||||
### External Object Reference Providers
|
||||
|
||||
Trusted connector plugins can declare generic external object providers in the
|
||||
manifest. The host owns URL scanning, sanitized canonical URLs, core storage,
|
||||
normalized status rendering, and issue/comment/document write durability. The
|
||||
plugin only identifies provider-owned objects and resolves board-safe status
|
||||
metadata.
|
||||
|
||||
```ts
|
||||
objectReferences: [
|
||||
{
|
||||
providerKey: "mocktracker",
|
||||
displayName: "Mock Tracker",
|
||||
objectTypes: ["ticket"],
|
||||
urlPatterns: ["https://mock.example/tickets/:id"],
|
||||
refreshPolicy: { defaultTtlSeconds: 300, staleAfterSeconds: 1800 },
|
||||
},
|
||||
],
|
||||
capabilities: ["external.objects.detect", "external.objects.read"],
|
||||
```
|
||||
|
||||
Implement `onDetectExternalObjects()` to map sanitized URL candidates to
|
||||
`providerKey`, `objectType`, provider-stable `externalId`, and optional display
|
||||
metadata such as `displayKey`/`iconKey`. Implement `onResolveExternalObject()`
|
||||
to return a normalized snapshot with `statusCategory`, `statusTone`,
|
||||
`statusLabel`, optional `statusIconKey`, board-safe `data`, and freshness
|
||||
metadata. Slow or failing plugins are isolated: Paperclip logs the failure and
|
||||
continues saving the source issue, comment, or document.
|
||||
|
||||
MVP security posture: provider plugins are trusted installs. Manifest
|
||||
capabilities gate host APIs and provider invocation paths, but they are not a
|
||||
sandbox boundary for untrusted marketplace code. Plugin UI is same-origin
|
||||
JavaScript and must not be mounted inline in markdown; inline external-object
|
||||
rendering uses host-owned metadata only. Treat untrusted providers as future work
|
||||
that requires worker sandboxing plus isolated plugin UI.
|
||||
|
||||
### Restricted Database Namespace
|
||||
|
||||
Trusted orchestration plugins can declare a host-owned PostgreSQL namespace:
|
||||
|
||||
@@ -62,6 +62,12 @@ import type {
|
||||
PluginEnvironmentResumeLeaseParams,
|
||||
PluginEnvironmentValidateConfigParams,
|
||||
PluginEnvironmentValidationResult,
|
||||
DetectExternalObjectsParams,
|
||||
DetectExternalObjectsResult,
|
||||
ResolveExternalObjectParams,
|
||||
PluginExternalObjectResolveResult,
|
||||
RefreshExternalObjectsParams,
|
||||
RefreshExternalObjectsResult,
|
||||
} from "./protocol.js";
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -243,6 +249,39 @@ export interface PluginDefinition {
|
||||
* access, capabilities, and checkout policy.
|
||||
*/
|
||||
onApiRequest?(input: PluginApiRequestInput): Promise<PluginApiResponse>;
|
||||
|
||||
/**
|
||||
* Called when Paperclip scans issue/comment/document content and asks this
|
||||
* plugin whether any sanitized URL candidates belong to its external object
|
||||
* providers. The host has already stripped URL userinfo, query strings, and
|
||||
* fragments unless provider-safe identity components were explicitly hashed.
|
||||
*
|
||||
* Requires `external.objects.detect`.
|
||||
*/
|
||||
onDetectExternalObjects?(
|
||||
params: DetectExternalObjectsParams,
|
||||
): Promise<DetectExternalObjectsResult>;
|
||||
|
||||
/**
|
||||
* Called when Paperclip needs the current normalized status for one external
|
||||
* object owned by a manifest-declared provider.
|
||||
*
|
||||
* Requires `external.objects.read`.
|
||||
*/
|
||||
onResolveExternalObject?(
|
||||
params: ResolveExternalObjectParams,
|
||||
): Promise<PluginExternalObjectResolveResult>;
|
||||
|
||||
/**
|
||||
* Optional batch resolver used by providers that can refresh many objects
|
||||
* more efficiently than individual `onResolveExternalObject` calls.
|
||||
*
|
||||
* Requires `external.objects.refresh`.
|
||||
*/
|
||||
onRefreshExternalObjects?(
|
||||
params: RefreshExternalObjectsParams,
|
||||
): Promise<RefreshExternalObjectsResult>;
|
||||
|
||||
/**
|
||||
* Called to validate provider-specific configuration for a plugin-hosted
|
||||
* environment driver.
|
||||
|
||||
@@ -155,6 +155,17 @@ export type {
|
||||
PluginPerformActionActorContext,
|
||||
PluginPerformActionContext,
|
||||
ExecuteToolParams,
|
||||
PluginExternalObjectUrlCandidate,
|
||||
PluginExternalObjectSourceContext,
|
||||
DetectExternalObjectsParams,
|
||||
PluginExternalObjectDetection,
|
||||
DetectExternalObjectsResult,
|
||||
PluginExternalObjectRecordSnapshot,
|
||||
ResolveExternalObjectParams,
|
||||
PluginExternalObjectResolvedSnapshot,
|
||||
PluginExternalObjectResolveResult,
|
||||
RefreshExternalObjectsParams,
|
||||
RefreshExternalObjectsResult,
|
||||
PluginEnvironmentDiagnostic,
|
||||
PluginEnvironmentDriverBaseParams,
|
||||
PluginEnvironmentValidateConfigParams,
|
||||
@@ -313,6 +324,8 @@ export type {
|
||||
PluginApiRouteDeclaration,
|
||||
PluginLocalFolderDeclaration,
|
||||
PluginCompanySettings,
|
||||
PluginObjectReferenceRefreshPolicy,
|
||||
PluginObjectReferenceProviderDeclaration,
|
||||
PluginRecord,
|
||||
PluginDatabaseNamespaceRecord,
|
||||
PluginMigrationRecord,
|
||||
|
||||
@@ -40,6 +40,11 @@ import type {
|
||||
Goal,
|
||||
PluginLocalFolderDeclaration,
|
||||
PrincipalPermissionGrant,
|
||||
ExternalObjectStatusCategory,
|
||||
ExternalObjectStatusTone,
|
||||
ExternalObjectLivenessState,
|
||||
ExternalObjectMentionConfidence,
|
||||
ExternalObjectMentionSourceKind,
|
||||
} from "@paperclipai/shared";
|
||||
export type { PluginLauncherRenderContextSnapshot } from "@paperclipai/shared";
|
||||
|
||||
@@ -432,6 +437,113 @@ export interface ExecuteToolParams {
|
||||
runContext: ToolRunContext;
|
||||
}
|
||||
|
||||
export interface PluginExternalObjectUrlCandidate {
|
||||
sanitizedCanonicalUrl: string;
|
||||
sanitizedDisplayUrl: string;
|
||||
canonicalIdentityHash: string;
|
||||
canonicalIdentity: Record<string, unknown>;
|
||||
redactedMatchedText: string;
|
||||
}
|
||||
|
||||
export interface PluginExternalObjectSourceContext {
|
||||
companyId: string;
|
||||
sourceIssueId: string;
|
||||
sourceKind: ExternalObjectMentionSourceKind;
|
||||
sourceRecordId: string | null;
|
||||
documentKey: string | null;
|
||||
propertyKey: string | null;
|
||||
}
|
||||
|
||||
export interface DetectExternalObjectsParams {
|
||||
companyId: string;
|
||||
urls: PluginExternalObjectUrlCandidate[];
|
||||
sourceContext: PluginExternalObjectSourceContext;
|
||||
}
|
||||
|
||||
export interface PluginExternalObjectDetection {
|
||||
urlIdentityHash: string;
|
||||
providerKey: string;
|
||||
objectType: string;
|
||||
externalId: string;
|
||||
displayKey?: string | null;
|
||||
iconKey?: string | null;
|
||||
displayTitle?: string | null;
|
||||
confidence?: ExternalObjectMentionConfidence;
|
||||
}
|
||||
|
||||
export interface DetectExternalObjectsResult {
|
||||
detections: PluginExternalObjectDetection[];
|
||||
}
|
||||
|
||||
export interface PluginExternalObjectRecordSnapshot {
|
||||
id: string;
|
||||
companyId: string;
|
||||
providerKey: string;
|
||||
objectType: string;
|
||||
externalId: string;
|
||||
sanitizedCanonicalUrl: string | null;
|
||||
canonicalIdentityHash: string | null;
|
||||
displayKey: string | null;
|
||||
iconKey: string | null;
|
||||
displayTitle: string | null;
|
||||
statusKey: string | null;
|
||||
statusLabel: string | null;
|
||||
statusIconKey: string | null;
|
||||
statusCategory: ExternalObjectStatusCategory;
|
||||
statusTone: ExternalObjectStatusTone;
|
||||
liveness: ExternalObjectLivenessState;
|
||||
isTerminal: boolean;
|
||||
data: Record<string, unknown>;
|
||||
remoteVersion: string | null;
|
||||
etag: string | null;
|
||||
}
|
||||
|
||||
export interface ResolveExternalObjectParams {
|
||||
companyId: string;
|
||||
providerKey: string;
|
||||
objectType: string;
|
||||
externalId: string;
|
||||
object: PluginExternalObjectRecordSnapshot;
|
||||
}
|
||||
|
||||
export interface PluginExternalObjectResolvedSnapshot {
|
||||
displayKey?: string | null;
|
||||
iconKey?: string | null;
|
||||
displayTitle?: string | null;
|
||||
statusKey?: string | null;
|
||||
statusLabel?: string | null;
|
||||
statusIconKey?: string | null;
|
||||
statusCategory: ExternalObjectStatusCategory;
|
||||
statusTone: ExternalObjectStatusTone;
|
||||
isTerminal?: boolean;
|
||||
data?: Record<string, unknown>;
|
||||
remoteVersion?: string | null;
|
||||
etag?: string | null;
|
||||
ttlSeconds?: number;
|
||||
}
|
||||
|
||||
export type PluginExternalObjectResolveResult =
|
||||
| { ok: true; snapshot: PluginExternalObjectResolvedSnapshot }
|
||||
| {
|
||||
ok: false;
|
||||
liveness: Extract<ExternalObjectLivenessState, "auth_required" | "unreachable">;
|
||||
errorCode: string;
|
||||
errorMessage?: string | null;
|
||||
retryAfterSeconds?: number;
|
||||
};
|
||||
|
||||
export interface RefreshExternalObjectsParams {
|
||||
companyId: string;
|
||||
objects: PluginExternalObjectRecordSnapshot[];
|
||||
}
|
||||
|
||||
export interface RefreshExternalObjectsResult {
|
||||
results: Array<{
|
||||
objectId: string;
|
||||
result: PluginExternalObjectResolveResult;
|
||||
}>;
|
||||
}
|
||||
|
||||
export interface PluginEnvironmentDiagnostic {
|
||||
severity: "info" | "warning" | "error";
|
||||
message: string;
|
||||
@@ -604,6 +716,18 @@ export interface HostToWorkerMethods {
|
||||
performAction: [params: PerformActionParams, result: unknown];
|
||||
/** @see PLUGIN_SPEC.md §13.10 */
|
||||
executeTool: [params: ExecuteToolParams, result: ToolResult];
|
||||
detectExternalObjects: [
|
||||
params: DetectExternalObjectsParams,
|
||||
result: DetectExternalObjectsResult,
|
||||
];
|
||||
resolveExternalObject: [
|
||||
params: ResolveExternalObjectParams,
|
||||
result: PluginExternalObjectResolveResult,
|
||||
];
|
||||
refreshExternalObjects: [
|
||||
params: RefreshExternalObjectsParams,
|
||||
result: RefreshExternalObjectsResult,
|
||||
];
|
||||
environmentValidateConfig: [
|
||||
params: PluginEnvironmentValidateConfigParams,
|
||||
result: PluginEnvironmentValidationResult,
|
||||
@@ -659,6 +783,9 @@ export const HOST_TO_WORKER_OPTIONAL_METHODS: readonly HostToWorkerMethodName[]
|
||||
"getData",
|
||||
"performAction",
|
||||
"executeTool",
|
||||
"detectExternalObjects",
|
||||
"resolveExternalObject",
|
||||
"refreshExternalObjects",
|
||||
"environmentValidateConfig",
|
||||
"environmentProbe",
|
||||
"environmentAcquireLease",
|
||||
|
||||
@@ -84,6 +84,8 @@ export type {
|
||||
PluginDatabaseDeclaration,
|
||||
PluginApiRouteDeclaration,
|
||||
PluginApiRouteCompanyResolution,
|
||||
PluginObjectReferenceRefreshPolicy,
|
||||
PluginObjectReferenceProviderDeclaration,
|
||||
PluginRecord,
|
||||
PluginDatabaseNamespaceRecord,
|
||||
PluginMigrationRecord,
|
||||
|
||||
@@ -82,6 +82,9 @@ import type {
|
||||
PluginPerformActionActorContext,
|
||||
PluginPerformActionContext,
|
||||
ExecuteToolParams,
|
||||
DetectExternalObjectsParams,
|
||||
ResolveExternalObjectParams,
|
||||
RefreshExternalObjectsParams,
|
||||
PluginEnvironmentAcquireLeaseParams,
|
||||
PluginEnvironmentDestroyLeaseParams,
|
||||
PluginEnvironmentExecuteParams,
|
||||
@@ -1351,6 +1354,12 @@ export function startWorkerRpcHost(options: WorkerRpcHostOptions): WorkerRpcHost
|
||||
|
||||
case "executeTool":
|
||||
return handleExecuteTool(params as ExecuteToolParams);
|
||||
case "detectExternalObjects":
|
||||
return handleDetectExternalObjects(params as DetectExternalObjectsParams);
|
||||
case "resolveExternalObject":
|
||||
return handleResolveExternalObject(params as ResolveExternalObjectParams);
|
||||
case "refreshExternalObjects":
|
||||
return handleRefreshExternalObjects(params as RefreshExternalObjectsParams);
|
||||
|
||||
case "environmentValidateConfig":
|
||||
return handleEnvironmentValidateConfig(params as PluginEnvironmentValidateConfigParams);
|
||||
@@ -1409,6 +1418,9 @@ export function startWorkerRpcHost(options: WorkerRpcHostOptions): WorkerRpcHost
|
||||
if (plugin.definition.onHealth) supportedMethods.push("health");
|
||||
if (plugin.definition.onShutdown) supportedMethods.push("shutdown");
|
||||
if (plugin.definition.onApiRequest) supportedMethods.push("handleApiRequest");
|
||||
if (plugin.definition.onDetectExternalObjects) supportedMethods.push("detectExternalObjects");
|
||||
if (plugin.definition.onResolveExternalObject) supportedMethods.push("resolveExternalObject");
|
||||
if (plugin.definition.onRefreshExternalObjects) supportedMethods.push("refreshExternalObjects");
|
||||
if (plugin.definition.onEnvironmentValidateConfig) supportedMethods.push("environmentValidateConfig");
|
||||
if (plugin.definition.onEnvironmentProbe) supportedMethods.push("environmentProbe");
|
||||
if (plugin.definition.onEnvironmentAcquireLease) supportedMethods.push("environmentAcquireLease");
|
||||
@@ -1588,6 +1600,27 @@ export function startWorkerRpcHost(options: WorkerRpcHostOptions): WorkerRpcHost
|
||||
return entry.fn(params.parameters, params.runContext);
|
||||
}
|
||||
|
||||
async function handleDetectExternalObjects(params: DetectExternalObjectsParams) {
|
||||
if (!plugin.definition.onDetectExternalObjects) {
|
||||
throw methodNotImplemented("detectExternalObjects");
|
||||
}
|
||||
return plugin.definition.onDetectExternalObjects(params);
|
||||
}
|
||||
|
||||
async function handleResolveExternalObject(params: ResolveExternalObjectParams) {
|
||||
if (!plugin.definition.onResolveExternalObject) {
|
||||
throw methodNotImplemented("resolveExternalObject");
|
||||
}
|
||||
return plugin.definition.onResolveExternalObject(params);
|
||||
}
|
||||
|
||||
async function handleRefreshExternalObjects(params: RefreshExternalObjectsParams) {
|
||||
if (!plugin.definition.onRefreshExternalObjects) {
|
||||
throw methodNotImplemented("refreshExternalObjects");
|
||||
}
|
||||
return plugin.definition.onRefreshExternalObjects(params);
|
||||
}
|
||||
|
||||
function methodNotImplemented(method: string): Error & { code: number } {
|
||||
return Object.assign(
|
||||
new Error(`${method} is not implemented by this plugin`),
|
||||
|
||||
Reference in new issue
Block a user