Skip to content

The open-source app everyone uses to manage agents at work

Merge public-gh/master into paperclip-company-import-export

dottad07d86f7783c
diff --cc packages/shared/src/index.ts
index f2c5987564,98850f9ed1..eccfdec9a0
--- a/packages/shared/src/index.ts
+++ b/packages/shared/src/index.ts
@@@ -148,11 -123,10 +148,14 @@@ export type
InstanceExperimentalSettings,
InstanceSettings,
Agent,
+ AgentAccessState,
+ AgentChainOfCommandEntry,
+ AgentDetail,
AgentPermissions,
+ AgentInstructionsBundleMode,
+ AgentInstructionsFileSummary,
+ AgentInstructionsFileDetail,
+ AgentInstructionsBundle,
AgentKeyCreated,
AgentConfigRevision,
AdapterEnvironmentCheckLevel,
diff --cc packages/shared/src/types/agent.ts
index 61fe62fc00,550e34aa7f..e938ad4a18
--- a/packages/shared/src/types/agent.ts
+++ b/packages/shared/src/types/agent.ts
@@@ -9,38 -13,20 +13,52 @@@ export interface AgentPermissions
canCreateAgents: boolean;
}
+export type AgentInstructionsBundleMode = "managed" | "external";
+
+export interface AgentInstructionsFileSummary {
+ path: string;
+ size: number;
+ language: string;
+ markdown: boolean;
+ isEntryFile: boolean;
+ editable: boolean;
+ deprecated: boolean;
+ virtual: boolean;
+}
+
+export interface AgentInstructionsFileDetail extends AgentInstructionsFileSummary {
+ content: string;
+}
+
+export interface AgentInstructionsBundle {
+ agentId: string;
+ companyId: string;
+ mode: AgentInstructionsBundleMode | null;
+ rootPath: string | null;
+ managedRootPath: string;
+ entryFile: string;
+ resolvedEntryPath: string | null;
+ editable: boolean;
+ warnings: string[];
+ legacyPromptTemplateActive: boolean;
+ legacyBootstrapPromptTemplateActive: boolean;
+ files: AgentInstructionsFileSummary[];
+}
+
+ export interface AgentAccessState {
+ canAssignTasks: boolean;
+ taskAssignSource: "explicit_grant" | "agent_creator" | "ceo_role" | "none";
+ membership: CompanyMembership | null;
+ grants: PrincipalPermissionGrant[];
+ }
+
+ export interface AgentChainOfCommandEntry {
+ id: string;
+ name: string;
+ role: AgentRole;
+ title: string | null;
+ }
+
export interface Agent {
id: string;
companyId: string;
diff --cc packages/shared/src/types/index.ts
index 957e915856,f573db4d9f..d7e249d6b5
--- a/packages/shared/src/types/index.ts
+++ b/packages/shared/src/types/index.ts
@@@ -1,41 -1,11 +1,44 @@@
export type { Company } from "./company.js";
export type { InstanceExperimentalSettings, InstanceSettings } from "./instance.js";
+export type {
+ CompanySkillSourceType,
+ CompanySkillTrustLevel,
+ CompanySkillCompatibility,
+ CompanySkillSourceBadge,
+ CompanySkillFileInventoryEntry,
+ CompanySkill,
+ CompanySkillListItem,
+ CompanySkillUsageAgent,
+ CompanySkillDetail,
+ CompanySkillUpdateStatus,
+ CompanySkillImportRequest,
+ CompanySkillImportResult,
+ CompanySkillProjectScanRequest,
+ CompanySkillProjectScanSkipped,
+ CompanySkillProjectScanConflict,
+ CompanySkillProjectScanResult,
+ CompanySkillCreateRequest,
+ CompanySkillFileDetail,
+ CompanySkillFileUpdateRequest,
+} from "./company-skill.js";
+export type {
+ AgentSkillSyncMode,
+ AgentSkillState,
+ AgentSkillOrigin,
+ AgentSkillEntry,
+ AgentSkillSnapshot,
+ AgentSkillSyncRequest,
+} from "./adapter-skills.js";
export type {
Agent,
+ AgentAccessState,
+ AgentChainOfCommandEntry,
+ AgentDetail,
AgentPermissions,
+ AgentInstructionsBundleMode,
+ AgentInstructionsFileSummary,
+ AgentInstructionsFileDetail,
+ AgentInstructionsBundle,
AgentKeyCreated,
AgentConfigRevision,
AdapterEnvironmentCheckLevel,
diff --cc packages/shared/src/validators/company.ts
index 7e91a61bd7,d3e77af321..e3a1a2084c
--- a/packages/shared/src/validators/company.ts
+++ b/packages/shared/src/validators/company.ts
@@@ -24,15 -23,12 +24,21 @@@ export const updateCompanySchema = crea
export type UpdateCompany = z.infer<typeof updateCompanySchema>;
-/** Branding-only subset that CEO agents may update. */
-export const updateCompanyBrandingSchema = z.object({
- name: z.string().min(1).optional(),
- description: z.string().nullable().optional(),
- brandColor: z.string().regex(/^#[0-9a-fA-F]{6}$/).nullable().optional(),
- logoAssetId: logoAssetIdSchema,
-});
+export const updateCompanyBrandingSchema = z
+ .object({
++ name: z.string().min(1).optional(),
++ description: z.string().nullable().optional(),
+ brandColor: brandColorSchema,
+ logoAssetId: logoAssetIdSchema,
+ })
+ .strict()
+ .refine(
- (value) => value.brandColor !== undefined || value.logoAssetId !== undefined,
++ (value) =>
++ value.name !== undefined
++ || value.description !== undefined
++ || value.brandColor !== undefined
++ || value.logoAssetId !== undefined,
+ "At least one branding field must be provided",
+ );
export type UpdateCompanyBranding = z.infer<typeof updateCompanyBrandingSchema>;
diff --cc server/src/routes/agents.ts
index 45051bf556,2c6b12b499..cc16806682
--- a/server/src/routes/agents.ts
+++ b/server/src/routes/agents.ts
@@@ -1254,13 -1019,15 +1331,19 @@@ export function agentRoutes(db: Db)
action: "agent.created",
entityType: "agent",
entityId: agent.id,
- details: { name: agent.name, role: agent.role },
+ details: {
+ name: agent.name,
+ role: agent.role,
+ desiredSkills: desiredSkillAssignment.desiredSkills,
+ },
});
+ await applyDefaultAgentTaskAssignGrant(
+ companyId,
+ agent.id,
+ req.actor.type === "board" ? (req.actor.userId ?? null) : null,
+ );
+
if (agent.budgetMonthlyCents > 0) {
await budgets.upsertPolicy(
companyId,
diff --cc server/src/routes/companies.ts
index a86655bc18,f11e7cae9f..4c2d480769
--- a/server/src/routes/companies.ts
+++ b/server/src/routes/companies.ts
@@@ -5,8 -5,8 +5,9 @@@ import
companyPortabilityImportSchema,
companyPortabilityPreviewSchema,
createCompanySchema,
+ updateCompanyBrandingSchema,
updateCompanySchema,
+ updateCompanyBrandingSchema,
} from "@paperclipai/shared";
import { forbidden } from "../errors.js";
import { validate } from "../middleware/validate.js";
diff --cc server/src/services/access.ts
index 0ba74d3b16,e02b36d723..3e30e1ab3b
--- a/server/src/services/access.ts
+++ b/server/src/services/access.ts
@@@ -265,20 -251,86 +265,100 @@@ export function accessService(db: Db)
});
}
+ async function copyActiveUserMemberships(sourceCompanyId: string, targetCompanyId: string) {
+ const sourceMemberships = await listActiveUserMemberships(sourceCompanyId);
+ for (const membership of sourceMemberships) {
+ await ensureMembership(
+ targetCompanyId,
+ "user",
+ membership.principalId,
+ membership.membershipRole,
+ "active",
+ );
+ }
+ return sourceMemberships;
+ }
+
+ async function listPrincipalGrants(
+ companyId: string,
+ principalType: PrincipalType,
+ principalId: string,
+ ) {
+ return db
+ .select()
+ .from(principalPermissionGrants)
+ .where(
+ and(
+ eq(principalPermissionGrants.companyId, companyId),
+ eq(principalPermissionGrants.principalType, principalType),
+ eq(principalPermissionGrants.principalId, principalId),
+ ),
+ )
+ .orderBy(principalPermissionGrants.permissionKey);
+ }
+
+ async function setPrincipalPermission(
+ companyId: string,
+ principalType: PrincipalType,
+ principalId: string,
+ permissionKey: PermissionKey,
+ enabled: boolean,
+ grantedByUserId: string | null,
+ scope: Record<string, unknown> | null = null,
+ ) {
+ if (!enabled) {
+ await db
+ .delete(principalPermissionGrants)
+ .where(
+ and(
+ eq(principalPermissionGrants.companyId, companyId),
+ eq(principalPermissionGrants.principalType, principalType),
+ eq(principalPermissionGrants.principalId, principalId),
+ eq(principalPermissionGrants.permissionKey, permissionKey),
+ ),
+ );
+ return;
+ }
+
+ await ensureMembership(companyId, principalType, principalId, "member", "active");
+
+ const existing = await db
+ .select()
+ .from(principalPermissionGrants)
+ .where(
+ and(
+ eq(principalPermissionGrants.companyId, companyId),
+ eq(principalPermissionGrants.principalType, principalType),
+ eq(principalPermissionGrants.principalId, principalId),
+ eq(principalPermissionGrants.permissionKey, permissionKey),
+ ),
+ )
+ .then((rows) => rows[0] ?? null);
+
+ if (existing) {
+ await db
+ .update(principalPermissionGrants)
+ .set({
+ scope,
+ grantedByUserId,
+ updatedAt: new Date(),
+ })
+ .where(eq(principalPermissionGrants.id, existing.id));
+ return;
+ }
+
+ await db.insert(principalPermissionGrants).values({
+ companyId,
+ principalType,
+ principalId,
+ permissionKey,
+ scope,
+ grantedByUserId,
+ createdAt: new Date(),
+ updatedAt: new Date(),
+ });
+ }
+
return {
isInstanceAdmin,
canUser,
diff --cc server/src/services/company-portability.ts
index 6ae4c43102,7afdb3812b..380658f53c
--- a/server/src/services/company-portability.ts
+++ b/server/src/services/company-portability.ts
@@@ -3142,16 -954,16 +3142,25 @@@ export function companyPortabilityServi
continue;
}
- const created = await agents.create(targetCompany.id, patch);
+ let created = await agents.create(targetCompany.id, patch);
+ try {
+ const materialized = await instructions.materializeManagedBundle(created, bundleFiles, {
+ clearLegacyPromptTemplate: true,
+ replaceExisting: true,
+ });
+ created = await agents.update(created.id, { adapterConfig: materialized.adapterConfig }) ?? created;
+ } catch (err) {
+ warnings.push(`Failed to materialize instructions bundle for ${manifestAgent.slug}: ${err instanceof Error ? err.message : String(err)}`);
+ }
+ await access.ensureMembership(targetCompany.id, "agent", created.id, "member", "active");
+ await access.setPrincipalPermission(
+ targetCompany.id,
+ "agent",
+ created.id,
+ "tasks:assign",
+ true,
+ actorUserId ?? null,
+ );
importedSlugToAgentId.set(planAgent.slug, created.id);
existingSlugToAgentId.set(normalizeAgentUrlKey(created.name) ?? created.id, created.id);
resultAgents.push({
diff --cc ui/src/api/agents.ts
index f7bcdc5a81,1f4a642e75..0fd82c4f09
--- a/ui/src/api/agents.ts
+++ b/ui/src/api/agents.ts
@@@ -1,8 -1,6 +1,9 @@@
import type {
Agent,
+ AgentInstructionsBundle,
+ AgentInstructionsFileDetail,
+ AgentSkillSnapshot,
+ AgentDetail,
AdapterEnvironmentTestResult,
AgentKeyCreated,
AgentRuntimeState,
@@@ -103,33 -106,8 +109,33 @@@ export const agentsApi =
api.post<AgentHireResponse>(`/companies/${companyId}/agent-hires`, data),
update: (id: string, data: Record<string, unknown>, companyId?: string) =>
api.patch<Agent>(agentPath(id, companyId), data),
- updatePermissions: (id: string, data: { canCreateAgents: boolean }, companyId?: string) =>
- api.patch<Agent>(agentPath(id, companyId, "/permissions"), data),
+ updatePermissions: (id: string, data: AgentPermissionUpdate, companyId?: string) =>
+ api.patch<AgentDetail>(agentPath(id, companyId, "/permissions"), data),
+ instructionsBundle: (id: string, companyId?: string) =>
+ api.get<AgentInstructionsBundle>(agentPath(id, companyId, "/instructions-bundle")),
+ updateInstructionsBundle: (
+ id: string,
+ data: {
+ mode?: "managed" | "external";
+ rootPath?: string | null;
+ entryFile?: string;
+ clearLegacyPromptTemplate?: boolean;
+ },
+ companyId?: string,
+ ) => api.patch<AgentInstructionsBundle>(agentPath(id, companyId, "/instructions-bundle"), data),
+ instructionsFile: (id: string, relativePath: string, companyId?: string) =>
+ api.get<AgentInstructionsFileDetail>(
+ agentPath(id, companyId, `/instructions-bundle/file?path=${encodeURIComponent(relativePath)}`),
+ ),
+ saveInstructionsFile: (
+ id: string,
+ data: { path: string; content: string; clearLegacyPromptTemplate?: boolean },
+ companyId?: string,
+ ) => api.put<AgentInstructionsFileDetail>(agentPath(id, companyId, "/instructions-bundle/file"), data),
+ deleteInstructionsFile: (id: string, relativePath: string, companyId?: string) =>
+ api.delete<AgentInstructionsBundle>(
+ agentPath(id, companyId, `/instructions-bundle/file?path=${encodeURIComponent(relativePath)}`),
+ ),
pause: (id: string, companyId?: string) => api.post<Agent>(agentPath(id, companyId, "/pause"), {}),
resume: (id: string, companyId?: string) => api.post<Agent>(agentPath(id, companyId, "/resume"), {}),
terminate: (id: string, companyId?: string) => api.post<Agent>(agentPath(id, companyId, "/terminate"), {}),
diff --cc ui/src/pages/AgentDetail.tsx
index fa3d05b994,3e238e5e1c..ca7c823d4a
--- a/ui/src/pages/AgentDetail.tsx
+++ b/ui/src/pages/AgentDetail.tsx
@@@ -1,8 -1,13 +1,14 @@@
import { useCallback, useEffect, useMemo, useState, useRef } from "react";
import { useParams, useNavigate, Link, Navigate, useBeforeUnload } from "@/lib/router";
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
- import { agentsApi, type AgentKey, type ClaudeLoginResult } from "../api/agents";
+ import {
+ agentsApi,
+ type AgentKey,
+ type ClaudeLoginResult,
+ type AvailableSkill,
+ type AgentPermissionUpdate,
+ } from "../api/agents";
+import { companySkillsApi } from "../api/companySkills";
import { budgetsApi } from "../api/budgets";
import { heartbeatsApi } from "../api/heartbeats";
import { ApiError } from "../api/client";
@@@ -72,8 -70,7 +78,9 @@@ import { RunTranscriptView, type Transc
import {
isUuidLike,
type Agent,
+ type AgentSkillEntry,
+ type AgentSkillSnapshot,
+ type AgentDetail as AgentDetailRecord,
type BudgetPolicySummary,
type HeartbeatRun,
type HeartbeatRunEvent,
@@@ -1394,18 -1346,14 +1401,18 @@@ function ConfigurationTab(
onCancelActionChange,
onSavingChange,
updatePermissions,
+ hidePromptTemplate,
+ hideInstructionsFile,
}: {
- agent: Agent;
+ agent: AgentDetailRecord;
companyId?: string;
onDirtyChange: (dirty: boolean) => void;
onSaveActionChange: (save: (() => void) | null) => void;
onCancelActionChange: (cancel: (() => void) | null) => void;
onSavingChange: (saving: boolean) => void;
- updatePermissions: { mutate: (canCreate: boolean) => void; isPending: boolean };
+ updatePermissions: { mutate: (permissions: AgentPermissionUpdate) => void; isPending: boolean };
+ hidePromptTemplate?: boolean;
+ hideInstructionsFile?: boolean;
}) {
const queryClient = useQueryClient();
const [awaitingRefreshAfterSave, setAwaitingRefreshAfterSave] = useState(false);