mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-05 06:03:51 +01:00
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work.
> - Chat connections let operators set task defaults for new
conversations, including on GitHub review bot settings and repository
access views.
> - Today, task defaults render a plain native `<select>` for projects
and expose a Workspace selector for GitHub review bots.
> - Operators expect the same searchable, rich project selector used in
the task composer, and GitHub review bot tasks should always use
isolated workspaces / project defaults without a separate workspace
override.
> - This pull request replaces the native project select in
`ChatExecutionDefaults` with `InlineEntitySelector`, hides workspace
configuration for GitHub connections and repositories, and strips GitHub
workspace overrides on the server during reads, writes, and task
creation.
> - The benefit is faster, consistent project selection across chat
connections and simpler GitHub review bot settings that enforce isolated
workspace / project defaults.
## Linked Issues or Issue Description
**What existing behavior does this improve?**
Task defaults in chat connection settings (`ChatExecutionDefaults`),
specifically for GitHub review bot connection settings and
per-repository overrides.
**Subsystem affected**
Cross-cutting (`ui/` and `server/`).
**Current behavior**
`ChatExecutionDefaults` renders a plain native `<select>` for the
default project and displays a Workspace configuration selector on
GitHub review bot settings and repository defaults. Legacy workspace
overrides saved on GitHub endpoints or repositories remain visible and
apply during task creation.
**Proposed behavior**
`ChatExecutionDefaults` uses `InlineEntitySelector` with search, recent
projects, project color icons, and private-project indicators (matching
the task composer). For GitHub review bots (`allowWorkspace={false}`),
the Workspace selector is removed, the workspace choices query is
skipped, and the server strips any workspace override on read, write,
and task creation so new tasks always use isolated workspaces / project
defaults.
**Reason and benefit**
Operators can find projects quickly with the same picker they already
know from the task composer, and GitHub review bots no longer expose a
misleading workspace override that conflicts with isolated workspace /
project defaults.
**Breaking changes**
None for non-GitHub providers (Slack, Discord, Telegram, Teams,
iMessage, Email retain their Workspace selector and stored workspace
overrides). For GitHub review bots, any previously saved workspace
override is ignored so new tasks use isolated workspaces / project
defaults; saved project defaults are preserved.
## What Changed
- Updated `ui/src/components/InlineEntitySelector.tsx` to accept
optional `id` (for `<label htmlFor>`) and `contentClassName` (to match
full-width form triggers) without changing existing callers.
- Replaced the native project `<select>` in
`ui/src/pages/apps/chat/ChatExecutionDefaults.tsx` with
`InlineEntitySelector` (searchable by project name and description,
recent project ordering, colored folder icons, private lock badges,
unavailable-project handling, and stable `projectOptions` memoization).
- Added an `allowWorkspace` prop (default `true`) to
`ChatExecutionDefaults` so non-GitHub connections keep their Workspace
selector while GitHub connections
(`ui/src/pages/apps/chat/ChatEndpointDetail.tsx`) and GitHub
repositories (`ui/src/pages/apps/chat/GitHubBotManagement.tsx`) omit
workspace configuration and skip fetching workspace choices.
- Added `normalizeChatExecutionDefaultsForProvider` and provider-aware
stripping in `resolveChatExecutionDefaults`
(`server/src/services/chat-execution-defaults.ts`) and wired it through
endpoint serialization/updates
(`server/src/services/chat-channels/endpoints.ts`), resource
reads/writes
(`server/src/services/chat-channels/resource-reconciliation.ts`,
`server/src/services/chat-channels/github/resources.ts`), and inbound
task creation (`server/src/services/chat-channels.ts`).
- Added unit and realistic-size (400-project linear read budget) tests
in `ui/src/pages/apps/chat/ChatExecutionDefaults.test.tsx`, helper tests
in `server/src/__tests__/chat-execution-defaults.test.ts`, and an
embedded-Postgres integration test in
`server/src/__tests__/chat-channels/github-setup-and-access.integration.test.ts`.
## Verification
- `npx vitest run ui/src/pages/apps/chat/ChatExecutionDefaults.test.tsx`
— passed (5 tests, including 400-project resource-mode search and
recent-ordering linear read budget).
- `npx vitest run ui/src/pages/apps/chat/chat-ui-contract.test.ts` —
passed (12 tests).
- `npx vitest run server/src/__tests__/chat-execution-defaults.test.ts`
— passed (6 tests).
- `npx vitest run
server/src/__tests__/chat-channels/github-setup-and-access.integration.test.ts
-t "strips workspace overrides"` — passed (embedded Postgres integration
test verifying read, write, and inbound task creation).
- `pnpm --filter @paperclipai/ui typecheck && pnpm --filter
@paperclipai/server typecheck` — passed (exit 0).
- `node scripts/check-module-boundaries.mjs && node
scripts/check-test-budget.mjs && node
scripts/check-query-error-rendering.mjs` — passed.
- CI run on final head `d548e20a75`:
https://github.com/paperclipai/paperclip/actions/runs/47394038195 — all
66 checks passed (Build, Typecheck + Release Registry, policy, verify,
general/serialized/runner/e2e suites, security scans).
- Greptile Review on `d548e20a75`: 5/5 confidence score with zero
unresolved comments.
## Risks
- Low risk. Existing GitHub endpoints or repositories with a legacy
`workspace` entry in `executionDefaults` now ignore that entry and use
the project default / isolated workspace behavior instead. Non-GitHub
chat connections keep existing workspace configuration unchanged.
## Model Used
- Google Gemini 4 Neon (High reasoning mode, with tool use and code
execution) via Antigravity.
## 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>
87 lines
3.5 KiB
TypeScript
87 lines
3.5 KiB
TypeScript
import { chatExecutionDefaultsSchema, type ChatExecutionDefaults } from "@paperclipai/shared";
|
|
import { type Db, projects } from "@paperclipai/db";
|
|
import { and, eq } from "drizzle-orm";
|
|
import { projectReadSqlCondition, type AuthorizationActor } from "./authorization.js";
|
|
import { executionWorkspaceService } from "./execution-workspaces.js";
|
|
import { forbidden, notFound } from "../errors.js";
|
|
import { accessService } from "./access.js";
|
|
|
|
type DbTransaction = Parameters<Parameters<Db["transaction"]>[0]>[0];
|
|
type DefaultsAccessInput = {
|
|
companyId: string;
|
|
actor: AuthorizationActor;
|
|
assigneeAgentId?: string | null;
|
|
defaults: ChatExecutionDefaults | null | undefined;
|
|
};
|
|
|
|
export async function assertChatExecutionDefaultsAccess(
|
|
db: Db,
|
|
input: DefaultsAccessInput,
|
|
reader: Db | DbTransaction = db,
|
|
): Promise<void> {
|
|
const defaults = chatExecutionDefaultsSchema.parse(input.defaults ?? {});
|
|
if (defaults.projectId) {
|
|
const [project] = await reader.select({ id: projects.id }).from(projects).where(and(
|
|
eq(projects.id, defaults.projectId), eq(projects.companyId, input.companyId),
|
|
await projectReadSqlCondition(reader, input.actor),
|
|
));
|
|
if (!project) throw notFound("Default project is unavailable or inaccessible");
|
|
}
|
|
if (defaults.workspace) await executionWorkspaceService(db).validateSelection({
|
|
companyId: input.companyId, actor: input.actor, selection: defaults.workspace, assigneeAgentId: input.assigneeAgentId,
|
|
}, reader);
|
|
}
|
|
|
|
export async function assertChatTaskCreationAccess(
|
|
db: Db,
|
|
input: DefaultsAccessInput & { assigneeAgentId: string; parentIssueId?: string | null },
|
|
transaction: Db | DbTransaction,
|
|
): Promise<void> {
|
|
await assertChatExecutionDefaultsAccess(db, input, transaction);
|
|
if (!input.defaults?.projectId) return;
|
|
const scope = {
|
|
projectId: input.defaults.projectId,
|
|
parentIssueId: input.parentIssueId ?? null,
|
|
assigneeAgentId: input.assigneeAgentId,
|
|
assigneeUserId: null,
|
|
};
|
|
const decision = await accessService(transaction as Db).decide({
|
|
actor: input.actor,
|
|
action: "tasks:assign",
|
|
resource: { type: "issue", companyId: input.companyId, ...scope },
|
|
scope,
|
|
});
|
|
if (!decision.allowed) throw forbidden(decision.explanation);
|
|
}
|
|
|
|
export function normalizeChatExecutionDefaultsForProvider(
|
|
provider: string,
|
|
defaults: ChatExecutionDefaults | null | undefined,
|
|
): ChatExecutionDefaults | null {
|
|
if (defaults == null) return null;
|
|
const normalized: ChatExecutionDefaults = {
|
|
...(defaults.projectId !== undefined ? { projectId: defaults.projectId } : {}),
|
|
...(provider !== "github" && defaults.workspace !== undefined ? { workspace: defaults.workspace } : {}),
|
|
};
|
|
return Object.keys(normalized).length > 0 ? normalized : null;
|
|
}
|
|
|
|
export function resolveChatExecutionDefaults(
|
|
provider: string,
|
|
endpoint: ChatExecutionDefaults | null | undefined,
|
|
resource: ChatExecutionDefaults | null | undefined,
|
|
): ChatExecutionDefaults {
|
|
const base = chatExecutionDefaultsSchema.parse(endpoint ?? {});
|
|
const override = chatExecutionDefaultsSchema.parse(resource ?? {});
|
|
const resolved: ChatExecutionDefaults = {
|
|
...(base.projectId !== undefined ? { projectId: base.projectId } : {}),
|
|
...(base.workspace !== undefined ? { workspace: base.workspace } : {}),
|
|
...(override.projectId !== undefined ? { projectId: override.projectId } : {}),
|
|
...(override.workspace !== undefined ? { workspace: override.workspace } : {}),
|
|
};
|
|
if (provider === "github") {
|
|
delete resolved.workspace;
|
|
}
|
|
return resolved;
|
|
}
|