mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-10 20:46:28 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Issue interactions give agents and people a structured decision record. > - Resolver routes used different authorization rules. > - Some routes blocked valid agents, including task watchdogs with normal issue access. > - The API did not show who could resolve a pending interaction. > - This pull request gives every interaction kind one resolver policy evaluator. > - The benefit is a clear decision path with consistent governance and company isolation. ## Linked Issues or Issue Description Fixes: #8087 Refs: #7403 Related PR: #11082 proposes board-only confirmation rules. This change keeps human-only review as an explicit policy. **What happened?** Agents could create issue interactions. Some resolver routes still required board access. This left valid agent confirmations pending. Task watchdogs could see the same problem without board identity. **Expected behavior** Every interaction kind must use one resolver policy contract. The contract must support `anyone`, `not_creator`, and `human_only`. It must also apply all normal governance controls. **Steps to reproduce** 1. Create a `request_confirmation` interaction as an agent. 2. Resolve it with another authorized agent. 3. Observe the board-only denial. **Paperclip version or commit** The problem exists on `master` before this change. **Deployment mode** Local development with `pnpm dev`. ## What Changed - Add canonical policies for `anyone`, `not_creator`, and `human_only`. - Use one server evaluator for every interaction kind. - Apply named addressees, company limits, review rules, and task watchdog scope. - Charge cross-issue resolutions to the existing per-run action limit. - Return the effective resolver audience in attention and interaction data. - Show the audience, governance choices, and denial reasons in the board UI. - Add telemetry, API documents, product documents, and regression fixtures. - Add migration provenance for safe legacy behavior. - Make migration `0218` safe for complete replays and partial prior runs. ## Product Rules - An interaction records a response. It does not grant authority for the next action. - `anyone` lets any authorized issue participant respond. - `not_creator` requires a responder other than the interaction creator. - `human_only` requires an authorized person. - A named addressee, company policy, or governed action can narrow the audience. - These controls cannot widen the audience. - A task watchdog uses the same rules as an ordinary agent. - A task watchdog does not receive board authority. - An agent resolution on another issue uses the shared cross-issue action limit. - Legacy pending interactions keep their earlier restrictions. - The UI shows the effective audience and a permanent denial reason. ## Verification - `pnpm --filter @paperclipai/db check:migrations` - `pnpm --filter @paperclipai/db typecheck` - `pnpm exec vitest run packages/db/src/issue-thread-interaction-resolver-policy-migration.test.ts` - The focused PostgreSQL test applies migration `0218` twice. - The test also completes a partial prior run and preserves existing provenance. - The latest GitHub head has 29 successful checks. - The opt-in Storybook visual check skipped as expected. - Greptile reports 5/5 with no open comments. ## Risks - New interaction writes use `anyone` by default. - Callers must select `not_creator` or `human_only` when they need stricter review. - Legacy pending interactions keep the old creator and human restrictions. - Migration `0218` fills only missing provenance fields during recovery. - Cross-issue resolutions can reach the existing action limit. - The shared evaluator affects every interaction kind. - Route, service, database, shared contract, and UI tests cover these rules. > This work matches the Agent Reviews and Approvals direction in `ROADMAP.md`. It does not duplicate a planned item. ## Model Used OpenAI Codex, GPT-5. The runtime does not expose the exact deployment ID or context window. The agent used reasoning, repository tools, shell commands, 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 linked public issues or described the issue with the required labels - [x] I have not referenced internal Paperclip issues or links - [x] My branch name describes the change and contains no internal ticket id - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation - [x] I have considered and documented the risks - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open comments - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
183 lines
6.5 KiB
TypeScript
183 lines
6.5 KiB
TypeScript
import type { TelemetryClient } from "./client.js";
|
|
import type { EventDimensionsMap } from "./generated/paperclip-telemetry.js";
|
|
|
|
type RawDimension<T extends string | undefined> = T | (string & {});
|
|
|
|
function asEventDimension<T extends string>(value: RawDimension<T>): T {
|
|
return value as T;
|
|
}
|
|
|
|
export function trackInstallStarted(client: TelemetryClient): void {
|
|
client.track("install.started", {});
|
|
}
|
|
|
|
export function trackInstallCompleted(
|
|
client: TelemetryClient,
|
|
dims: { adapterType: RawDimension<EventDimensionsMap["install.completed"]["adapter_type"]> },
|
|
): void {
|
|
client.track("install.completed", {
|
|
adapter_type: asEventDimension(dims.adapterType),
|
|
});
|
|
}
|
|
|
|
export function trackCompanyImported(
|
|
client: TelemetryClient,
|
|
dims: {
|
|
sourceType: RawDimension<EventDimensionsMap["company.imported"]["source_type"]>;
|
|
sourceRef: string;
|
|
isPrivate: boolean;
|
|
},
|
|
): void {
|
|
const ref = dims.isPrivate ? client.hashPrivateRef(dims.sourceRef) : dims.sourceRef;
|
|
client.track("company.imported", {
|
|
source_type: asEventDimension(dims.sourceType),
|
|
source_ref: ref,
|
|
source_ref_hashed: dims.isPrivate,
|
|
});
|
|
}
|
|
|
|
export function trackProjectCreated(client: TelemetryClient): void {
|
|
client.track("project.created", {});
|
|
}
|
|
|
|
export function trackRoutineCreated(client: TelemetryClient): void {
|
|
client.track("routine.created", {});
|
|
}
|
|
|
|
export function trackRoutineRun(
|
|
client: TelemetryClient,
|
|
dims: {
|
|
source: RawDimension<EventDimensionsMap["routine.run"]["source"]>;
|
|
status: RawDimension<EventDimensionsMap["routine.run"]["status"]>;
|
|
},
|
|
): void {
|
|
client.track("routine.run", {
|
|
source: asEventDimension(dims.source),
|
|
status: asEventDimension(dims.status),
|
|
});
|
|
}
|
|
|
|
export function trackGoalCreated(
|
|
client: TelemetryClient,
|
|
dims?: { goalLevel?: RawDimension<EventDimensionsMap["goal.created"]["goal_level"]> | null },
|
|
): void {
|
|
client.track("goal.created", {
|
|
goal_level: dims?.goalLevel ? asEventDimension(dims.goalLevel) : "other",
|
|
});
|
|
}
|
|
|
|
export function trackAgentCreated(
|
|
client: TelemetryClient,
|
|
dims: {
|
|
agentRole: RawDimension<EventDimensionsMap["agent.created"]["agent_role"]>;
|
|
agentId: string;
|
|
},
|
|
): void {
|
|
client.track("agent.created", {
|
|
agent_role: asEventDimension(dims.agentRole),
|
|
agent_id: dims.agentId,
|
|
});
|
|
}
|
|
|
|
export function trackSkillImported(
|
|
client: TelemetryClient,
|
|
dims: {
|
|
sourceType: RawDimension<EventDimensionsMap["skill.imported"]["source_type"]>;
|
|
skillRef?: string | null;
|
|
},
|
|
): void {
|
|
client.track("skill.imported", {
|
|
source_type: asEventDimension(dims.sourceType),
|
|
...(dims.skillRef ? { skill_ref: dims.skillRef } : {}),
|
|
});
|
|
}
|
|
|
|
export function trackAgentFirstHeartbeat(
|
|
client: TelemetryClient,
|
|
dims: {
|
|
agentRole: RawDimension<EventDimensionsMap["agent.first_heartbeat"]["agent_role"]>;
|
|
agentId: string;
|
|
},
|
|
): void {
|
|
client.track("agent.first_heartbeat", {
|
|
agent_role: asEventDimension(dims.agentRole),
|
|
agent_id: dims.agentId,
|
|
});
|
|
}
|
|
|
|
export function trackAgentTaskCompleted(
|
|
client: TelemetryClient,
|
|
dims: {
|
|
agentRole: RawDimension<EventDimensionsMap["agent.task_completed"]["agent_role"]>;
|
|
agentId: string;
|
|
adapterType: RawDimension<EventDimensionsMap["agent.task_completed"]["adapter_type"]>;
|
|
model?: string;
|
|
},
|
|
): void {
|
|
client.track("agent.task_completed", {
|
|
agent_role: asEventDimension(dims.agentRole),
|
|
agent_id: dims.agentId,
|
|
adapter_type: asEventDimension(dims.adapterType),
|
|
...(dims.model ? { model: dims.model } : {}),
|
|
});
|
|
}
|
|
|
|
export function trackErrorHandlerCrash(
|
|
client: TelemetryClient,
|
|
dims: { errorCode: string },
|
|
): void {
|
|
client.track("error.handler_crash", { error_code: dims.errorCode });
|
|
}
|
|
|
|
export function trackInteractionCreated(
|
|
client: TelemetryClient,
|
|
dims: {
|
|
interactionKind: RawDimension<EventDimensionsMap["interaction.created"]["interaction_kind"]>;
|
|
usedDeprecatedResolverPolicyAlias: boolean;
|
|
},
|
|
): void {
|
|
client.track("interaction.created", {
|
|
interaction_kind: asEventDimension(dims.interactionKind),
|
|
used_deprecated_resolver_policy_alias: dims.usedDeprecatedResolverPolicyAlias,
|
|
});
|
|
}
|
|
|
|
export function trackInteractionResolved(
|
|
client: TelemetryClient,
|
|
dims: {
|
|
interactionKind: RawDimension<EventDimensionsMap["interaction.resolved"]["interaction_kind"]>;
|
|
status: RawDimension<EventDimensionsMap["interaction.resolved"]["status"]>;
|
|
resolvedByKind: RawDimension<EventDimensionsMap["interaction.resolved"]["resolved_by_kind"]>;
|
|
resolutionReason?: RawDimension<EventDimensionsMap["interaction.resolved"]["resolution_reason"]> | null;
|
|
createdByKind?: RawDimension<EventDimensionsMap["interaction.resolved"]["created_by_kind"]> | null;
|
|
creatorAgentRole?: RawDimension<EventDimensionsMap["interaction.resolved"]["creator_agent_role"]> | null;
|
|
continuationPolicy?: RawDimension<EventDimensionsMap["interaction.resolved"]["continuation_policy"]> | null;
|
|
targetType?: RawDimension<EventDimensionsMap["interaction.resolved"]["target_type"]> | null;
|
|
optionCount?: number;
|
|
selectedOptionCount?: number;
|
|
questionCount?: number;
|
|
answeredQuestionCount?: number;
|
|
createdTaskCount?: number;
|
|
skippedTaskCount?: number;
|
|
legacyInheritedRestriction: boolean;
|
|
},
|
|
): void {
|
|
client.track("interaction.resolved", {
|
|
interaction_kind: asEventDimension(dims.interactionKind),
|
|
status: asEventDimension(dims.status),
|
|
resolved_by_kind: asEventDimension(dims.resolvedByKind),
|
|
...(dims.resolutionReason ? { resolution_reason: asEventDimension(dims.resolutionReason) } : {}),
|
|
...(dims.createdByKind ? { created_by_kind: asEventDimension(dims.createdByKind) } : {}),
|
|
...(dims.creatorAgentRole ? { creator_agent_role: asEventDimension(dims.creatorAgentRole) } : {}),
|
|
...(dims.continuationPolicy ? { continuation_policy: asEventDimension(dims.continuationPolicy) } : {}),
|
|
...(dims.targetType ? { target_type: asEventDimension(dims.targetType) } : {}),
|
|
...(dims.optionCount === undefined ? {} : { option_count: dims.optionCount }),
|
|
...(dims.selectedOptionCount === undefined ? {} : { selected_option_count: dims.selectedOptionCount }),
|
|
...(dims.questionCount === undefined ? {} : { question_count: dims.questionCount }),
|
|
...(dims.answeredQuestionCount === undefined ? {} : { answered_question_count: dims.answeredQuestionCount }),
|
|
...(dims.createdTaskCount === undefined ? {} : { created_task_count: dims.createdTaskCount }),
|
|
...(dims.skippedTaskCount === undefined ? {} : { skipped_task_count: dims.skippedTaskCount }),
|
|
legacy_inherited_restriction: dims.legacyInheritedRestriction,
|
|
});
|
|
}
|