Skip to content

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

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

Dottacca086b863d5
diff --cc packages/adapters/claude-local/src/server/execute.ts
index eb7d89e300,cd1f0f1560..6b174dd22c
--- a/packages/adapters/claude-local/src/server/execute.ts
+++ b/packages/adapters/claude-local/src/server/execute.ts
@@@ -333,8 -340,13 +333,13 @@@ export async function execute(ctx: Adap
graceSec,
extraArgs,
} = runtimeConfig;
- const billingType = resolveClaudeBillingType(env);
+ const effectiveEnv = Object.fromEntries(
+ Object.entries({ ...process.env, ...env }).filter(
+ (entry): entry is [string, string] => typeof entry[1] === "string",
+ ),
+ );
+ const billingType = resolveClaudeBillingType(effectiveEnv);
- const skillsDir = await buildSkillsDir();
+ const skillsDir = await buildSkillsDir(config);
// When instructionsFilePath is configured, create a combined temp file that
// includes both the file content and the path directive, so we only need
diff --cc packages/adapters/codex-local/src/server/index.ts
index bbae3fb453,5d3d8ea2bc..d31816f769
--- a/packages/adapters/codex-local/src/server/index.ts
+++ b/packages/adapters/codex-local/src/server/index.ts
@@@ -1,7 -1,17 +1,18 @@@
export { execute, ensureCodexSkillsInjected } from "./execute.js";
+export { listCodexSkills, syncCodexSkills } from "./skills.js";
export { testEnvironment } from "./test.js";
export { parseCodexJsonl, isCodexUnknownSessionError } from "./parse.js";
+ export {
+ getQuotaWindows,
+ readCodexAuthInfo,
+ readCodexToken,
+ fetchCodexQuota,
+ fetchCodexRpcQuota,
+ mapCodexRpcQuota,
+ secondsToWindowLabel,
+ fetchWithTimeout,
+ codexHomeDir,
+ } from "./quota.js";
import type { AdapterSessionCodec } from "@paperclipai/adapter-utils";
function readNonEmptyString(value: unknown): string | null {
diff --cc packages/adapters/pi-local/src/server/execute.ts
index efc81222a9,27dce5475f..a91987c3dc
--- a/packages/adapters/pi-local/src/server/execute.ts
+++ b/packages/adapters/pi-local/src/server/execute.ts
@@@ -51,15 -50,14 +51,14 @@@ function parseModelId(model: string | n
return trimmed.slice(trimmed.indexOf("/") + 1).trim() || null;
}
-function resolvePiBiller(env: Record<string, string>, provider: string | null): string {
- return inferOpenAiCompatibleBiller(env, null) ?? provider ?? "unknown";
-}
-
-async function ensurePiSkillsInjected(onLog: AdapterExecutionContext["onLog"]) {
- const skillsEntries = await listPaperclipSkillEntries(__moduleDir);
- if (skillsEntries.length === 0) return;
-
+async function ensurePiSkillsInjected(
+ onLog: AdapterExecutionContext["onLog"],
+ skillsEntries: Array<{ name: string; source: string }>,
+ desiredSkillNames?: string[],
+) {
+ const desiredSet = new Set(desiredSkillNames ?? skillsEntries.map((entry) => entry.name));
+ const selectedEntries = skillsEntries.filter((entry) => desiredSet.has(entry.name));
+ if (selectedEntries.length === 0) return;
-
const piSkillsHome = path.join(os.homedir(), ".pi", "agent", "skills");
await fs.mkdir(piSkillsHome, { recursive: true });
const removedSkills = await removeMaintainerOnlySkillSymlinks(
@@@ -92,6 -90,6 +91,10 @@@
}
}
++function resolvePiBiller(env: Record<string, string>, provider: string | null): string {
++ return inferOpenAiCompatibleBiller(env, null) ?? provider ?? "unknown";
++}
++
async function ensureSessionsDir(): Promise<string> {
await fs.mkdir(PAPERCLIP_SESSIONS_DIR, { recursive: true });
return PAPERCLIP_SESSIONS_DIR;
diff --cc packages/shared/src/types/index.ts
index 79e9876e04,ce8050e4f2..0472fee68a
--- a/packages/shared/src/types/index.ts
+++ b/packages/shared/src/types/index.ts
@@@ -90,14 -75,12 +99,15 @@@ export type
JoinRequest,
InstanceUserRoleGrant,
} from "./access.js";
+ export type { QuotaWindow, ProviderQuotaResult } from "./quota.js";
export type {
CompanyPortabilityInclude,
- CompanyPortabilitySecretRequirement,
+ CompanyPortabilityEnvInput,
CompanyPortabilityCompanyManifestEntry,
CompanyPortabilityAgentManifestEntry,
+ CompanyPortabilitySkillManifestEntry,
+ CompanyPortabilityProjectManifestEntry,
+ CompanyPortabilityIssueManifestEntry,
CompanyPortabilityManifest,
CompanyPortabilityExportResult,
CompanyPortabilitySource,
diff --cc server/src/adapters/registry.ts
index 3e49e4507a,e644900e0f..a25ebf7e7e
--- a/server/src/adapters/registry.ts
+++ b/server/src/adapters/registry.ts
@@@ -1,18 -1,16 +1,20 @@@
import type { ServerAdapterModule } from "./types.js";
import {
execute as claudeExecute,
+ listClaudeSkills,
+ syncClaudeSkills,
testEnvironment as claudeTestEnvironment,
sessionCodec as claudeSessionCodec,
+ getQuotaWindows as claudeGetQuotaWindows,
} from "@paperclipai/adapter-claude-local/server";
import { agentConfigurationDoc as claudeAgentConfigurationDoc, models as claudeModels } from "@paperclipai/adapter-claude-local";
import {
execute as codexExecute,
+ listCodexSkills,
+ syncCodexSkills,
testEnvironment as codexTestEnvironment,
sessionCodec as codexSessionCodec,
+ getQuotaWindows as codexGetQuotaWindows,
} from "@paperclipai/adapter-codex-local/server";
import { agentConfigurationDoc as codexAgentConfigurationDoc, models as codexModels } from "@paperclipai/adapter-codex-local";
import {
diff --cc server/src/routes/agents.ts
index a64ca04280,46b2af5158..549cef60c5
--- a/server/src/routes/agents.ts
+++ b/server/src/routes/agents.ts
@@@ -29,7 -23,7 +29,8 @@@ import
agentService,
accessService,
approvalService,
+ companySkillService,
+ budgetService,
heartbeatService,
issueApprovalService,
issueService,
diff --cc server/src/services/heartbeat.ts
index 3f751e7a29,1f67e5e6a8..a7758e39fb
--- a/server/src/services/heartbeat.ts
+++ b/server/src/services/heartbeat.ts
@@@ -22,7 -23,7 +23,8 @@@ import type { AdapterExecutionResult, A
import { createLocalAgentJwt } from "../agent-auth-jwt.js";
import { parseObject, asBoolean, asNumber, appendWithCap, MAX_EXCERPT_BYTES } from "../adapters/utils.js";
import { costService } from "./costs.js";
+import { companySkillService } from "./company-skills.js";
+ import { budgetService, type BudgetEnforcementScope } from "./budgets.js";
import { secretService } from "./secrets.js";
import { resolveDefaultAgentWorkspaceDir } from "../home-paths.js";
import { summarizeHeartbeatRunResultJson } from "./heartbeat-run-summary.js";
@@@ -556,9 -618,12 +619,13 @@@ function resolveNextSessionState(input
export function heartbeatService(db: Db) {
const runLogStore = getRunLogStore();
const secretsSvc = secretService(db);
+ const companySkills = companySkillService(db);
const issuesSvc = issueService(db);
const activeRunExecutions = new Set<string>();
+ const budgetHooks = {
+ cancelWorkForScope: cancelBudgetScopeWork,
+ };
+ const budgets = budgetService(db, budgetHooks);
async function getAgent(agentId: string) {
return db
diff --cc ui/src/pages/AgentDetail.tsx
index 83ffcee7ce,ba56e29e91..c891d6c367
--- a/ui/src/pages/AgentDetail.tsx
+++ b/ui/src/pages/AgentDetail.tsx
@@@ -2,7 -2,7 +2,8 @@@ import { useCallback, useEffect, useMem
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 { companySkillsApi } from "../api/companySkills";
+ import { budgetsApi } from "../api/budgets";
import { heartbeatsApi } from "../api/heartbeats";
import { ApiError } from "../api/client";
import { ChartCard, RunActivityChart, PriorityChart, IssueStatusChart, SuccessRateChart } from "../components/ActivityCharts";
@@@ -60,7 -60,15 +62,16 @@@ import
import { Input } from "@/components/ui/input";
import { AgentIcon, AgentIconPicker } from "../components/AgentIconPicker";
import { RunTranscriptView, type TranscriptMode } from "../components/transcript/RunTranscriptView";
- import { isUuidLike, type Agent, type AgentRuntimeState, type AgentSkillSnapshot, type HeartbeatRun, type HeartbeatRunEvent, type LiveEvent } from "@paperclipai/shared";
+ import {
+ isUuidLike,
+ type Agent,
++ type AgentSkillSnapshot,
+ type BudgetPolicySummary,
+ type HeartbeatRun,
+ type HeartbeatRunEvent,
+ type AgentRuntimeState,
+ type LiveEvent,
+ } from "@paperclipai/shared";
import { redactHomePathUserSegments, redactHomePathUserSegmentsInValue } from "@paperclipai/adapter-utils";
import { agentRouteRef } from "../lib/utils";
@@@ -183,11 -185,11 +194,12 @@@ function scrollToContainerBottom(contai
container.scrollTo({ top: container.scrollHeight, behavior });
}
- type AgentDetailView = "dashboard" | "configuration" | "skills" | "runs";
-type AgentDetailView = "dashboard" | "configuration" | "runs" | "budget";
++type AgentDetailView = "dashboard" | "configuration" | "skills" | "runs" | "budget";
function parseAgentDetailView(value: string | null): AgentDetailView {
if (value === "configure" || value === "configuration") return "configuration";
+ if (value === "skills") return "skills";
+ if (value === "budget") return "budget";
if (value === "runs") return value;
return "dashboard";
}
@@@ -303,9 -301,17 +314,17 @@@ export function AgentDetail()
const { data: allAgents } = useQuery({
queryKey: queryKeys.agents.list(resolvedCompanyId!),
queryFn: () => agentsApi.list(resolvedCompanyId!),
- enabled: !!resolvedCompanyId,
+ enabled: !!resolvedCompanyId && needsDashboardData,
});
+ const { data: budgetOverview } = useQuery({
+ queryKey: queryKeys.budgets.overview(resolvedCompanyId ?? "__none__"),
+ queryFn: () => budgetsApi.overview(resolvedCompanyId!),
+ enabled: !!resolvedCompanyId,
+ refetchInterval: 30_000,
+ staleTime: 5_000,
+ });
+
const assignedIssues = (allIssues ?? [])
.filter((i) => i.assigneeAgentId === agent?.id)
.sort((a, b) => new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime());
@@@ -327,11 -364,11 +377,13 @@@
const canonicalTab =
activeView === "configuration"
? "configuration"
+ : activeView === "skills"
+ ? "skills"
: activeView === "runs"
? "runs"
- : "dashboard";
+ : activeView === "budget"
+ ? "budget"
+ : "dashboard";
if (routeAgentRef !== canonicalAgentRef || urlTab !== canonicalTab) {
navigate(`/agents/${canonicalAgentRef}/${canonicalTab}`, { replace: true });
return;
@@@ -428,10 -483,10 +498,12 @@@
crumbs.push({ label: `Run ${urlRunId.slice(0, 8)}` });
} else if (activeView === "configuration") {
crumbs.push({ label: "Configuration" });
+ } else if (activeView === "skills") {
+ crumbs.push({ label: "Skills" });
} else if (activeView === "runs") {
crumbs.push({ label: "Runs" });
+ } else if (activeView === "budget") {
+ crumbs.push({ label: "Budget" });
} else {
crumbs.push({ label: "Dashboard" });
}
@@@ -587,8 -642,8 +659,9 @@@
items={[
{ value: "dashboard", label: "Dashboard" },
{ value: "configuration", label: "Configuration" },
+ { value: "skills", label: "Skills" },
{ value: "runs", label: "Runs" },
+ { value: "budget", label: "Budget" },
]}
value={activeView}
onValueChange={(value) => navigate(`/agents/${canonicalAgentRef}/${value}`)}
diff --cc ui/src/pages/CompanySettings.tsx
index 9aca6ca7ec,225b73988a..e09f67c79d
--- a/ui/src/pages/CompanySettings.tsx
+++ b/ui/src/pages/CompanySettings.tsx
@@@ -2,12 -2,12 +2,13 @@@ import { ChangeEvent, useEffect, useSta
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { useCompany } from "../context/CompanyContext";
import { useBreadcrumbs } from "../context/BreadcrumbContext";
+import { useToast } from "../context/ToastContext";
import { companiesApi } from "../api/companies";
import { accessApi } from "../api/access";
+ import { assetsApi } from "../api/assets";
import { queryKeys } from "../lib/queryKeys";
import { Button } from "@/components/ui/button";
-import { Settings, Check } from "lucide-react";
+import { Settings, Check, Download, Upload } from "lucide-react";
import { CompanyPatternIcon } from "../components/CompanyPatternIcon";
import {
Field,