[codex] Add built-in Hermes adapters (#8543)

## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - Agent adapters are the boundary between the control plane and the
runtimes that actually do work.
> - Hermes support needs to be available as first-class local and
gateway adapters while still preserving the adapter-manager override
path for external packages.
> - The adapter work touches runtime execution, UI adapter metadata,
onboarding prompts, scoped credentials, release packaging, and smoke
coverage, so the handoff needs concrete verification rather than only
unit tests.
> - This pull request adds built-in Hermes local and Hermes gateway
support, keeps external adapter overrides compatible, and
documents/tests the gateway flow end to end.
> - The benefit is that operators can hire Hermes-backed agents without
a manual plugin install, while self-hosted installs can still
override/shadow the built-ins through Adapter manager packages.

## Linked Issues or Issue Description

No public GitHub issue exists for this exact Hermes built-in adapter,
gateway onboarding, and release-source work.

Problem description:
- Hermes local and gateway adapters need a public, reviewable source
path in the monorepo so package artifacts and built-in adapter behavior
match the application source.
- Operators need built-in `hermes_local` and `hermes_gateway` adapter
choices without losing the ability to install external Hermes packages
as overrides.
- Gateway onboarding needs secure defaults for API server URLs, API
keys, and generated agent setup text.
- Hermes-originated task bridge credentials need narrower API-key scope
configuration.
- Related public PRs found during duplicate search include #3027, #2363,
#7544, #7950, #8095, and #8543.

## What Changed

- Added the unified Hermes adapter package with local and gateway
server/UI/CLI exports, config schemas, transcript parsing, model
detection, and package metadata.
- Registered `hermes_local` and `hermes_gateway` as built-in adapters
across shared constants, server registries, CLI packaging, and UI
adapter registries.
- Kept the external adapter override path compatible so installed Hermes
packages can shadow built-ins and restore the built-in parser when
disabled.
- Added Hermes gateway onboarding docs, board-operator docs, Docker
smoke assets, and shell smoke harnesses for join/e2e validation.
- Added scoped task-bridge API-key support, authorization checks,
issue-origin handling, and tests for Hermes-created Paperclip tasks.
- Hardened gateway transport and redaction behavior for API keys,
headers, session data, and smoke diagnostics.
- Updated release packaging/bootstrap checks for the Hermes packages
while leaving `pnpm-lock.yaml` out of the PR per repository policy.

## Verification

Targeted local verification recorded before PR handoff:
- `pnpm --filter @paperclipai/hermes-paperclip-adapter exec vitest run
src/gateway/server/execute.test.ts` — 14/14 passed.
- `pnpm test:hermes-gateway-smoke` — 6/6 passed.
- Hermes package typecheck/build checks passed.
- Focused server/UI adapter tests passed — 31/31.
- Release helper Node tests passed — 18/18.
- `git diff --check origin/master..HEAD` passed.

Fresh Docker E2E smoke evidence:
- Ran `pnpm smoke:hermes-gateway-e2e` on 2026-06-26 with a fresh state
directory and fresh Docker container against a live Paperclip dev
server.
- Hermes direct execution reached `completed`.
- Hermes stop/cancel path reached `cancelled`.
- Hermes gateway created a Paperclip task, Paperclip ran the Hermes
agent, and the task reached `done` with the expected marker response.
- Temporary board auth keys, token files, smoke state, and Docker
containers were cleaned up after the run.

PR checks on head `b5eae40ce`:
- GitHub Actions passed: `policy`, `review`, `Typecheck + Release
Registry`, all general test shards, all serialized server shards,
`Build`, `Canary Dry Run`, `e2e`, and aggregate `verify`.
- External checks passed: Snyk and Socket Project Report.
- External Socket Pull Request Alerts remained pending after the
first-party CI matrix completed.

## Risks

- Medium risk: this spans adapter registration, package publishing,
gateway execution, onboarding docs, API-key scoping, and UI adapter
metadata.
- Migration risk is low: the scope-config migration adds a nullable
column and does not rewrite existing keys.
- Gateway execution depends on operator-provided Hermes API
configuration; the smoke covers the Docker gateway path but real
deployments may differ by network/auth setup.
- Direct Greptile review on the latest expanded diff is file-count
limited, although the commitperclip review gate passed.

> For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and
discuss it in `#dev` before opening the PR. Feature PRs that overlap
with planned core work may need to be redirected — check the roadmap
first. See `CONTRIBUTING.md`.

## Model Used

OpenAI Codex, GPT-5 coding agent, tool use enabled in a local repository
workspace. Context window size is not exposed in this 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] Commitperclip review gate is green; direct Greptile review is
file-count limited on the latest expanded diff
- [x] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
This commit is contained in:
DottaandPaperclip authored and GitHub committed 2026-06-26 16:04:58 -05:00
1 parent ef1422c23e
commit fd2f82ac5b
131 files changed
+10179 -686

No files matched your search

+164 -9
View File
@@ -83,6 +83,7 @@ import {
} from "../board-claim.js";
import { claimFirstInstanceAdmin } from "../first-admin-claim.js";
import { getStorageService } from "../storage/index.js";
import { secretService } from "../services/secrets.js";
function hashToken(token: string) {
return createHash("sha256").update(token).digest("hex");
@@ -294,8 +295,14 @@ function isPlainObject(value: unknown): value is Record<string, unknown> {
}
function isLoopbackHost(hostname: string): boolean {
const value = hostname.trim().toLowerCase();
return value === "localhost" || value === "127.0.0.1" || value === "::1";
const value = hostname.trim().toLowerCase().replace(/^\[|\]$/g, "");
return (
value === "localhost" ||
value === "::1" ||
value === "0:0:0:0:0:0:0:1" ||
value === "127.0.0.1" ||
/^127(?:\.\d{1,3}){3}$/.test(value)
);
}
function normalizeHostname(value: string | null | undefined): string | null {
@@ -474,8 +481,8 @@ function parseBooleanLike(value: unknown): boolean | null {
if (typeof value === "boolean") return value;
if (typeof value !== "string") return null;
const normalized = value.trim().toLowerCase();
if (normalized === "true" || normalized === "1") return true;
if (normalized === "false" || normalized === "0") return false;
if (["true", "1", "yes", "on"].includes(normalized)) return true;
if (["false", "0", "no", "off"].includes(normalized)) return false;
return null;
}
@@ -676,6 +683,91 @@ export function normalizeAgentDefaultsForJoin(input: {
}) {
const fatalErrors: string[] = [];
const diagnostics: JoinDiagnostic[] = [];
if (input.adapterType === "hermes_gateway") {
if (!isPlainObject(input.defaultsPayload)) {
diagnostics.push({
code: "hermes_gateway_defaults_missing",
level: "warn",
message: "No Hermes gateway config was provided in agentDefaultsPayload.",
hint: "Include agentDefaultsPayload.apiBaseUrl and agentDefaultsPayload.apiKey for Hermes gateway joins.",
});
fatalErrors.push("agentDefaultsPayload is required for adapterType=hermes_gateway");
return { normalized: null as Record<string, unknown> | null, diagnostics, fatalErrors };
}
const defaults = input.defaultsPayload as Record<string, unknown>;
const normalized = { ...defaults };
const rawApiBaseUrl = nonEmptyTrimmedString(defaults.apiBaseUrl ?? defaults.url);
if (!rawApiBaseUrl) {
diagnostics.push({
code: "hermes_gateway_api_base_url_missing",
level: "warn",
message: "Hermes gateway apiBaseUrl is missing.",
hint: "Set agentDefaultsPayload.apiBaseUrl to the Hermes API server URL.",
});
fatalErrors.push("agentDefaultsPayload.apiBaseUrl is required");
} else {
try {
const apiBaseUrl = new URL(rawApiBaseUrl);
if (apiBaseUrl.protocol !== "http:" && apiBaseUrl.protocol !== "https:") {
diagnostics.push({
code: "hermes_gateway_api_base_url_protocol",
level: "warn",
message: `Hermes gateway apiBaseUrl must use http:// or https:// (got ${apiBaseUrl.protocol}).`,
});
fatalErrors.push("agentDefaultsPayload.apiBaseUrl must use http:// or https:// for hermes_gateway");
} else if (
apiBaseUrl.protocol === "http:" &&
!isLoopbackHost(apiBaseUrl.hostname) &&
parseBooleanLike(defaults.dangerouslyAllowInsecureRemoteHttp) !== true
) {
diagnostics.push({
code: "hermes_gateway_plain_http_remote_denied",
level: "warn",
message: "Remote plain HTTP Hermes gateway traffic is denied by default.",
hint: "Use https:// or set agentDefaultsPayload.dangerouslyAllowInsecureRemoteHttp=true only for unsafe local development.",
});
fatalErrors.push(
"agentDefaultsPayload.apiBaseUrl uses remote plain HTTP; use HTTPS or set dangerouslyAllowInsecureRemoteHttp=true for unsafe local development",
);
} else {
normalized.apiBaseUrl = apiBaseUrl.toString();
if (apiBaseUrl.protocol === "http:" && !isLoopbackHost(apiBaseUrl.hostname)) {
diagnostics.push({
code: "hermes_gateway_plain_http_remote_unsafe_allowed",
level: "warn",
message: "Unsafe dev escape hatch enabled for non-loopback HTTP Hermes traffic.",
});
} else {
diagnostics.push({
code: "hermes_gateway_api_base_url_configured",
level: "info",
message: `Hermes gateway endpoint set to ${apiBaseUrl.toString()}`,
});
}
}
} catch {
diagnostics.push({
code: "hermes_gateway_api_base_url_invalid",
level: "warn",
message: `Invalid Hermes gateway apiBaseUrl: ${rawApiBaseUrl}`,
});
fatalErrors.push("agentDefaultsPayload.apiBaseUrl is not a valid URL");
}
}
if (!nonEmptyTrimmedString(defaults.apiKey)) {
diagnostics.push({
code: "hermes_gateway_api_key_missing",
level: "warn",
message: "Hermes gateway API key is missing.",
hint: "Set agentDefaultsPayload.apiKey to the Hermes API_SERVER_KEY value.",
});
fatalErrors.push("agentDefaultsPayload.apiKey is required");
}
return { normalized, diagnostics, fatalErrors };
}
if (input.adapterType !== "openclaw_gateway") {
const normalized = isPlainObject(input.defaultsPayload)
? (input.defaultsPayload as Record<string, unknown>)
@@ -919,6 +1011,24 @@ export function normalizeAgentDefaultsForJoin(input: {
return { normalized, diagnostics, fatalErrors };
}
export async function prepareAgentDefaultsPayloadForJoinPersistence(input: {
db: Db;
companyId: string;
adapterType: string | null;
normalized: Record<string, unknown> | null;
actor?: { userId?: string | null; agentId?: string | null };
}): Promise<Record<string, unknown> | null> {
if (input.adapterType !== "hermes_gateway" || !input.normalized) {
return input.normalized;
}
return secretService(input.db).normalizeAdapterConfigForPersistence(
input.companyId,
input.normalized,
{ adapterType: input.adapterType, actor: input.actor },
);
}
function toInviteSummaryResponse(
req: Request,
token: string,
@@ -1585,17 +1695,17 @@ function buildInviteOnboardingManifest(
),
onboarding: {
instructions:
"Join as an external Paperclip agent, save your one-time claim secret, wait for board approval, then claim your API key. Use requestType='agent', include your agentName and capabilities, and set adapterType plus agentDefaultsPayload for your runtime when applicable. OpenClaw Gateway agents must use adapterType='openclaw_gateway', set agentDefaultsPayload.url to a ws:// or wss:// gateway endpoint, and include agentDefaultsPayload.headers.x-openclaw-token.",
"Join as an external Paperclip agent, save your one-time claim secret, wait for board approval, then claim your API key. Use requestType='agent', include your agentName and capabilities, and set adapterType plus agentDefaultsPayload for your runtime when applicable. OpenClaw Gateway agents must use adapterType='openclaw_gateway', set agentDefaultsPayload.url to a ws:// or wss:// gateway endpoint, and include agentDefaultsPayload.headers.x-openclaw-token. Hermes Gateway agents must use adapterType='hermes_gateway', start Hermes with API_SERVER_ENABLED=true, API_SERVER_KEY, and `hermes gateway run --replace --accept-hooks`, then set agentDefaultsPayload.apiBaseUrl and agentDefaultsPayload.paperclipApiUrl.",
inviteMessage: extractInviteMessage(invite),
recommendedAdapterType: null,
requiredFields: {
requestType: "agent",
agentName: "Display name for this agent",
adapterType:
"Adapter type for this runtime. Use 'openclaw_gateway' only for OpenClaw Gateway agents.",
"Adapter type for this runtime. Use 'openclaw_gateway' only for OpenClaw Gateway agents. Use 'hermes_gateway' only for Hermes Gateway agents.",
capabilities: "Optional capability summary",
agentDefaultsPayload:
"Runtime-specific adapter config. OpenClaw Gateway agents must include url (ws:// or wss://) and headers.x-openclaw-token. Other runtimes should include the config their adapter expects."
"Runtime-specific adapter config. OpenClaw Gateway agents must include url (ws:// or wss://) and headers.x-openclaw-token. Hermes Gateway agents must include apiBaseUrl, API_SERVER_KEY-backed auth, and paperclipApiUrl. Other runtimes should include the config their adapter expects."
},
registrationEndpoint: {
method: "POST",
@@ -1744,6 +1854,37 @@ export function buildInviteOnboardingTextDocument(
For OpenClaw Gateway, include agentDefaultsPayload.headers.x-openclaw-token with your gateway token. Legacy x-openclaw-auth is also accepted, but x-openclaw-token is preferred. Do NOT use /v1/responses or /hooks/* in this gateway join flow.
Hermes Gateway setup:
- adapterType: "hermes_gateway"
- Start Hermes with API_SERVER_ENABLED=true and API_SERVER_KEY=<random-gateway-key>.
- Run: hermes gateway run --replace --accept-hooks
- Default Hermes API server port: 8642.
- Set agentDefaultsPayload.apiBaseUrl to the Hermes gateway URL Paperclip can reach.
- Set agentDefaultsPayload.paperclipApiUrl to the Paperclip base URL Hermes can reach.
- Use hermes_local when Paperclip should start Hermes on the Paperclip host.
- Use hermes_gateway when Paperclip should call an already-running Hermes API server.
- Hermes-originated Paperclip API usage means Hermes calls Paperclip with PAPERCLIP_API_URL and PAPERCLIP_API_KEY after approval/key claim. Do not confuse that with agentDefaultsPayload.apiBaseUrl, which points Paperclip to Hermes.
Hermes Gateway payload example:
{
"requestType": "agent",
"agentName": "My Hermes Gateway Agent",
"adapterType": "hermes_gateway",
"capabilities": "Hermes gateway agent",
"agentDefaultsPayload": {
"apiBaseUrl": "http://127.0.0.1:8642",
"apiKey": "<same-value-as-API_SERVER_KEY>",
"paperclipApiUrl": "http://localhost:3100"
}
}
Hermes Gateway network examples:
- Local loopback: agentDefaultsPayload.apiBaseUrl = "http://127.0.0.1:8642" and agentDefaultsPayload.paperclipApiUrl = "http://127.0.0.1:3100".
- LAN/private network: use reachable private addresses, for example agentDefaultsPayload.apiBaseUrl = "http://192.168.1.25:8642" and agentDefaultsPayload.paperclipApiUrl = "http://192.168.1.10:3100".
- Private overlay: use overlay DNS names, for example agentDefaultsPayload.apiBaseUrl = "http://hermes-host.tailnet-name.ts.net:8642" and agentDefaultsPayload.paperclipApiUrl = "http://paperclip-host.tailnet-name.ts.net:3100".
- Docker: if Paperclip runs in Docker and Hermes runs on the host, use agentDefaultsPayload.apiBaseUrl = "http://host.docker.internal:8642"; if both run in Compose, use the Hermes service name.
- Reverse proxy/TLS: use HTTPS origins, for example agentDefaultsPayload.apiBaseUrl = "https://hermes-gateway.example" and agentDefaultsPayload.paperclipApiUrl = "https://paperclip.example".
Expected response includes:
- request id
- one-time claimSecret
@@ -3565,6 +3706,20 @@ export function accessRoutes(
throw badRequest(joinDefaults.fatalErrors.join("; "));
}
const persistedJoinDefaultsPayload =
requestType === "agent"
? await prepareAgentDefaultsPayloadForJoinPersistence({
db,
companyId,
adapterType,
normalized: joinDefaults.normalized,
actor: {
userId: req.actor.userId ?? null,
agentId: req.actor.agentId ?? null
}
})
: null;
if (requestType === "agent" && adapterType === "openclaw_gateway") {
logger.info(
{
@@ -3658,7 +3813,7 @@ export function accessRoutes(
? req.body.capabilities ?? null
: null,
agentDefaultsPayload:
requestType === "agent" ? joinDefaults.normalized : null,
requestType === "agent" ? persistedJoinDefaultsPayload : null,
claimSecretHash,
claimSecretExpiresAt
})
@@ -3684,7 +3839,7 @@ export function accessRoutes(
: null,
adapterType: requestType === "agent" ? adapterType : null,
agentDefaultsPayload:
requestType === "agent" ? joinDefaults.normalized : null,
requestType === "agent" ? persistedJoinDefaultsPayload : null,
updatedAt: new Date()
})
.where(eq(joinRequests.id, replayJoinRequestId as string))
+24 -8
View File
@@ -140,7 +140,6 @@ export function agentRoutes(
codex_local: "instructionsFilePath",
droid_local: "instructionsFilePath",
gemini_local: "instructionsFilePath",
hermes_local: "instructionsFilePath",
opencode_local: "instructionsFilePath",
cursor: "instructionsFilePath",
pi_local: "instructionsFilePath",
@@ -1079,7 +1078,10 @@ export function agentRoutes(
const normalizedAdapterConfig = await secretsSvc.normalizeAdapterConfigForPersistence(
input.companyId,
input.adapterConfig,
{ strictMode: strictSecretsMode },
{
strictMode: strictSecretsMode,
adapterType: input.adapterType ?? null,
},
);
await assertAdapterConfigConstraints(
input.adapterType,
@@ -1617,11 +1619,13 @@ export function agentRoutes(
const normalizedAdapterConfig = await secretsSvc.normalizeAdapterConfigForPersistence(
companyId,
inputAdapterConfig,
{ strictMode: strictSecretsMode },
{ strictMode: strictSecretsMode, adapterType: type },
);
const { config: runtimeAdapterConfig } = await secretsSvc.resolveAdapterConfigForRuntime(
companyId,
normalizedAdapterConfig,
undefined,
{ adapterType: type },
);
const { executionTarget, environmentName, fallbackChecks, release } =
@@ -1943,6 +1947,18 @@ export function agentRoutes(
res.json(buildLowTrustSelfView(agent));
return;
}
if (req.actor.keyScope?.kind === "task_bridge") {
res.json({
id: agent.id,
companyId: agent.companyId,
name: agent.name,
role: agent.role,
title: agent.title,
status: agent.status,
keyScope: req.actor.keyScope,
});
return;
}
res.json(await buildAgentDetail(agent));
});
@@ -2572,7 +2588,7 @@ export function agentRoutes(
const normalizedAdapterConfig = await secretsSvc.normalizeAdapterConfigForPersistence(
existing.companyId,
syncedAdapterConfig,
{ strictMode: strictSecretsMode },
{ strictMode: strictSecretsMode, adapterType: existing.adapterType },
);
const actor = getActorInfo(req);
const agent = await svc.update(
@@ -2643,7 +2659,7 @@ export function agentRoutes(
const normalizedAdapterConfig = await secretsSvc.normalizeAdapterConfigForPersistence(
existing.companyId,
adapterConfig,
{ strictMode: strictSecretsMode },
{ strictMode: strictSecretsMode, adapterType: existing.adapterType },
);
await svc.update(
id,
@@ -2711,7 +2727,7 @@ export function agentRoutes(
const normalizedAdapterConfig = await secretsSvc.normalizeAdapterConfigForPersistence(
existing.companyId,
result.adapterConfig,
{ strictMode: strictSecretsMode },
{ strictMode: strictSecretsMode, adapterType: existing.adapterType },
);
await svc.update(
id,
@@ -3184,7 +3200,7 @@ export function agentRoutes(
if (!agent) {
return;
}
const key = await svc.createApiKey(id, req.body.name);
const key = await svc.createApiKey(id, req.body.name, req.body.scope);
await logActivity(db, {
companyId: agent.companyId,
@@ -3193,7 +3209,7 @@ export function agentRoutes(
action: "agent.key_created",
entityType: "agent",
entityId: agent.id,
details: { keyId: key.id, name: key.name },
details: { keyId: key.id, name: key.name, scope: key.scope },
});
res.status(201).json(key);
+52 -19
View File
@@ -1889,6 +1889,25 @@ export function issueRoutes(
throw forbidden(decision.explanation);
}
function isTaskBridgeKeyActor(req: Request) {
return req.actor.type === "agent" && req.actor.source === "agent_key" && req.actor.keyScope?.kind === "task_bridge";
}
function taskBridgeOriginForActor(req: Request) {
return isTaskBridgeKeyActor(req) && req.actor.keyId
? { originKind: "task_bridge", originId: req.actor.keyId }
: null;
}
async function assertTaskBridgeCreateAllowed(
req: Request,
companyId: string,
assignmentScope: TaskAssignmentAuthorizationScope,
) {
if (!isTaskBridgeKeyActor(req)) return;
await assertCanAssignTasks(req, companyId, assignmentScope);
}
async function decideIssueAccess(
req: Request,
issue: {
@@ -2966,6 +2985,10 @@ export function issueRoutes(
router.get("/companies/:companyId/issues", async (req, res) => {
const companyId = req.params.companyId as string;
assertCompanyAccess(req, companyId);
if (isTaskBridgeKeyActor(req)) {
res.status(403).json({ error: "Task bridge keys cannot use company-wide issue list APIs" });
return;
}
const assigneeUserFilterRaw = req.query.assigneeUserId as string | undefined;
const touchedByUserFilterRaw = req.query.touchedByUserId as string | undefined;
const inboxArchivedByUserFilterRaw = req.query.inboxArchivedByUserId as string | undefined;
@@ -3126,6 +3149,10 @@ export function issueRoutes(
router.get("/companies/:companyId/issues/count", async (req, res) => {
const companyId = req.params.companyId as string;
assertCompanyAccess(req, companyId);
if (isTaskBridgeKeyActor(req)) {
res.status(403).json({ error: "Task bridge keys cannot use company-wide issue count APIs" });
return;
}
const attention = req.query.attention as string | undefined;
const hasPlanDocument = parseOptionalBooleanQuery(req.query.hasPlanDocument);
if (attention !== "blocked") {
@@ -5050,7 +5077,7 @@ export function issueRoutes(
if (watchdogProductBugFollowUp === false) return;
const effectiveParentId = watchdogProductBugFollowUp ? null : rawCreateBody.parentId;
let createParent: Awaited<ReturnType<typeof svc.getById>> | null = null;
if (req.actor.type === "agent" && !effectiveParentId && !watchdogProductBugFollowUp) {
if (req.actor.type === "agent" && !effectiveParentId && !watchdogProductBugFollowUp && !isTaskBridgeKeyActor(req)) {
const companyScopeDecision = await access.decide({
actor: req.actor,
action: "company_scope:read",
@@ -5067,7 +5094,7 @@ export function issueRoutes(
res.status(404).json({ error: "Parent issue not found" });
return;
}
if (!(await assertIssueReadAllowed(req, res, createParent))) return;
if (!isTaskBridgeKeyActor(req) && !(await assertIssueReadAllowed(req, res, createParent))) return;
}
if (
!watchdogProductBugFollowUp &&
@@ -5113,17 +5140,19 @@ export function issueRoutes(
: {}),
};
if (!(await assertCheapRecoveryIssueAssigneeProfileAllowed(req, res, { companyId }, createBody))) return;
const createAssignmentScope = {
projectId: await resolveAssignmentProjectId({
companyId,
projectId: createBody.projectId,
parentIssueId: createBody.parentId,
}),
parentIssueId: createBody.parentId ?? null,
assigneeAgentId: createBody.assigneeAgentId ?? null,
assigneeUserId: rawCreateBody.assigneeUserId ?? null,
};
await assertTaskBridgeCreateAllowed(req, companyId, createAssignmentScope);
if (rawCreateBody.assigneeAgentId || rawCreateBody.assigneeUserId) {
await assertCanAssignTasks(req, companyId, {
projectId: await resolveAssignmentProjectId({
companyId,
projectId: createBody.projectId,
parentIssueId: createBody.parentId,
}),
parentIssueId: createBody.parentId ?? null,
assigneeAgentId: createBody.assigneeAgentId ?? null,
assigneeUserId: rawCreateBody.assigneeUserId ?? null,
});
await assertCanAssignTasks(req, companyId, createAssignmentScope);
}
await assertIssueEnvironmentSelection(companyId, createBody.executionWorkspaceSettings?.environmentId);
@@ -5141,6 +5170,7 @@ export function issueRoutes(
}, actor);
const issue = await svc.create(companyId, {
...createBody,
...(taskBridgeOriginForActor(req) ?? {}),
id: issueId,
executionPolicy,
...(sourceTrust ? { sourceTrust } : {}),
@@ -5258,7 +5288,7 @@ export function issueRoutes(
return;
}
assertCompanyAccess(req, parent.companyId);
if (!(await assertIssueReadAllowed(req, res, parent))) return;
if (!isTaskBridgeKeyActor(req) && !(await assertIssueReadAllowed(req, res, parent))) return;
if (!(await assertTaskWatchdogCreateIssueAllowed(req, res, parent.companyId, parent))) return;
if (await assertLowTrustControlPlaneDenied(req, res, parent.companyId, parent)) return;
assertNoAgentHostWorkspaceCommandMutation(req, collectIssueWorkspaceCommandPaths(req.body));
@@ -5271,13 +5301,15 @@ export function issueRoutes(
...(normalizedAssigneeAgentId !== undefined ? { assigneeAgentId: normalizedAssigneeAgentId } : {}),
};
if (!(await assertCheapRecoveryIssueAssigneeProfileAllowed(req, res, parent, createBody))) return;
const childAssignmentScope = {
projectId: createBody.projectId ?? parent.projectId ?? null,
parentIssueId: parent.id,
assigneeAgentId: createBody.assigneeAgentId ?? null,
assigneeUserId: createBody.assigneeUserId ?? null,
};
await assertTaskBridgeCreateAllowed(req, parent.companyId, childAssignmentScope);
if (req.body.assigneeAgentId || req.body.assigneeUserId) {
await assertCanAssignTasks(req, parent.companyId, {
projectId: createBody.projectId ?? parent.projectId ?? null,
parentIssueId: parent.id,
assigneeAgentId: createBody.assigneeAgentId ?? null,
assigneeUserId: createBody.assigneeUserId ?? null,
});
await assertCanAssignTasks(req, parent.companyId, childAssignmentScope);
}
await assertIssueEnvironmentSelection(parent.companyId, createBody.executionWorkspaceSettings?.environmentId);
@@ -5300,6 +5332,7 @@ export function issueRoutes(
}, actor);
const { issue, parentBlockerAdded } = await svc.createChild(parent.id, {
...createBody,
...(taskBridgeOriginForActor(req) ?? {}),
id: issueId,
executionPolicy,
...(currentSerializedChild
+19
View File
@@ -3,8 +3,13 @@ import type { Db } from "@paperclipai/db";
import { AGENT_ICON_NAMES } from "@paperclipai/shared";
import { forbidden } from "../errors.js";
import { listServerAdapters } from "../adapters/index.js";
import { hermesGatewayAgentConfigurationDoc } from "../adapters/hermes-gateway-doc.js";
import { agentService } from "../services/agents.js";
const pluginOnlyAdapterDocs = new Map<string, string>([
["hermes_gateway", hermesGatewayAgentConfigurationDoc],
]);
function hasCreatePermission(agent: { role: string; permissions: Record<string, unknown> | null | undefined }) {
if (!agent.permissions || typeof agent.permissions !== "object") return false;
return Boolean((agent.permissions as Record<string, unknown>).canCreateAgents);
@@ -34,6 +39,15 @@ export function llmRoutes(db: Db) {
"Installed adapters:",
...adapters.map((adapter) => `- ${adapter.type}: /llms/agent-configuration/${adapter.type}.txt`),
"",
"Plugin-only adapter docs:",
...Array.from(pluginOnlyAdapterDocs.keys())
.filter(
(adapterType) => !adapters.some((adapter) => adapter.type === adapterType),
)
.map(
(adapterType) => `- ${adapterType}: /llms/agent-configuration/${adapterType}.txt`,
),
"",
"Related API endpoints:",
"- GET /api/companies/:companyId/agent-configurations",
"- GET /api/agents/:id/configuration",
@@ -72,6 +86,11 @@ export function llmRoutes(db: Db) {
const adapterType = req.params.adapterType as string;
const adapter = listServerAdapters().find((entry) => entry.type === adapterType);
if (!adapter) {
const pluginOnlyDoc = pluginOnlyAdapterDocs.get(adapterType);
if (pluginOnlyDoc) {
res.type("text/plain").send(pluginOnlyDoc);
return;
}
res.status(404).type("text/plain").send(`Unknown adapter type: ${adapterType}`);
return;
}