diff --git a/packages/shared/src/connection-intent-guidance.ts b/packages/shared/src/connection-intent-guidance.ts index 7178d4afddd..7ddd678e951 100644 --- a/packages/shared/src/connection-intent-guidance.ts +++ b/packages/shared/src/connection-intent-guidance.ts @@ -7,6 +7,7 @@ */ export const CONNECTION_INTENT_AGENT_GUIDANCE = [ "Connection tools:", + "- Storing a company or personal credential in Paperclip Secrets is distinct from connecting an external service. Use `search_api` to discover secret metadata and secure human-entry guidance; do not require an external provider choice merely to store an already-requested credential. Values stay in the human's secure entry surface, never in comments; personal values belong to the signed-in person.", "- When the user asks to connect a service, call `connections_search` before any service tool, even if already installed. Also search when a task needs a service and usable access is uncertain. Search by its name or capability and follow the returned `instruction`.", "- Distinguish tool, chat/channel, and AI account purposes. Use `search_api` and `call_api` for authorized connection configuration requested by the user. Standard agents can manage connections under their responsible user's authority; inspect the returned capabilities and respect explicit restrictions. Reuse saved accounts and setup drafts.", "- Suggest a relevant connection when it would help the task and usable access is missing. Respect recorded declines and provider choices. Ask only for missing decisions, consent, credentials, or authority; never ask for credentials in comments. Hand off the exact required human action at the saved setup link, then inspect status and continue through the API.", @@ -16,7 +17,7 @@ export const CONNECTION_INTENT_AGENT_GUIDANCE = [ "- Do not use connection tools for arbitrary MCP URLs or unrelated work.", ].join("\n"); -export const CONNECTIONS_SEARCH_TOOL_DESCRIPTION = "Search connections across tool, channel/email, and AI purposes with a service name or natural-language description (up to 4000 characters). Choose the relevant method and inspect its management capabilities. For user-requested configuration, discover and call the existing REST operation with search_api/call_api; reuse saved drafts and hand off only required human authentication or consent. Use connection_request for missing access or required user input. Also discovers verified external aggregator apps. Use first when asked to connect a service or usable access is uncertain; respect the returned instruction, recorded declines, and exact providerQuestion. Do not use for arbitrary MCP URLs. Search is read-only."; +export const CONNECTIONS_SEARCH_TOOL_DESCRIPTION = "Search connections across tool, channel/email, and AI purposes with a service name or natural-language description (up to 4000 characters). Storing a company or personal credential in Paperclip Secrets is a separate operation: use search_api for secret metadata and secure human-entry guidance, not external provider discovery. Choose the relevant method and inspect its management capabilities. For user-requested configuration, discover and call the existing REST operation with search_api/call_api; reuse saved drafts and hand off only required human authentication or consent. Use connection_request for missing access or required user input. Also discovers verified external aggregator apps. Use first when asked to connect a service or usable access is uncertain; respect the returned instruction, recorded declines, and exact providerQuestion. Do not use for arbitrary MCP URLs. Search is read-only."; export const CONNECTION_REQUEST_TOOL_DESCRIPTION = "Request the service identifier returned by connections_search. For an existing connection with missing agent access, pass connectionId and the exact required toolNames to create an embedded Grant access card; only the human can approve it. Follow the search instruction; aggregator routes require the saved provider-selection interaction ID. Only this tool creates the real setup card. If user action is needed, finish independent work, then yield without retrying or asking for credentials in comments."; diff --git a/server/src/__tests__/secret-entry-guidance.test.ts b/server/src/__tests__/secret-entry-guidance.test.ts new file mode 100644 index 00000000000..8b242ee68cd --- /dev/null +++ b/server/src/__tests__/secret-entry-guidance.test.ts @@ -0,0 +1,37 @@ +import { expect, it } from "vitest"; +import { searchRunnerApi } from "../services/native-runtime/runner-api-catalog.js"; +import { startOpenCodeMcpBridge } from "../../../packages/paperclip-runner/src/drivers/opencode/mcp-bridge.js"; +import { searchApiAction } from "../../../packages/paperclip-runner/src/protocol-actions/search-api.js"; + +it("discovers the existing secure human entry surface through native API search", async () => { + const descriptor = searchApiAction.live.descriptor; + const bridge = await startOpenCodeMcpBridge({ + tools: [{ name: descriptor.operationId, description: descriptor.description, inputSchema: descriptor.inputSchema }], + handler: async call => ({ type: "inputText", text: JSON.stringify(searchRunnerApi(call.arguments)) }), + }); + try { + for (const query of ["company credential secret", "personal publishing credential"]) { + const response = await fetch(bridge.url, { method: "POST", headers: { + Authorization: `Bearer ${bridge.secret}`, "Content-Type": "application/json", Accept: "application/json, text/event-stream", + }, body: JSON.stringify({ jsonrpc: "2.0", id: query, method: "tools/call", + params: { name: "paperclip_search_api", arguments: { query } } }) }); + expect(response.status).toBe(200); + const wire = await response.json() as { result: { isError?: boolean; content: Array<{ text: string }> } }; + expect(wire.result.isError).not.toBe(true); + const controller = JSON.parse(wire.result.content[0]!.text) as { text: string }; + const discovered = JSON.parse(controller.text) as ReturnType; + const operations = discovered.results.filter(operation => operation.description.includes("/company/settings/secrets")); + expect(operations.length, query).toBeGreaterThan(0); + expect(operations.some(operation => /human|signed-in person/.test(operation.description))).toBe(true); + expect(operations.some(operation => /never.*chat/i.test(operation.description))).toBe(true); + if (query.startsWith("personal")) { + const definitions = operations.find(operation => operation.path.endsWith("user-secret-definitions")); + expect(definitions?.description).toContain("Set my value"); + expect(definitions?.description).toContain("current person"); + expect(definitions?.description).toContain("Company admins can also open definition details"); + expect(definitions?.description).toContain("other members use My secrets and Set my value"); + expect(definitions?.authorization.actor).toBe("board"); + } + } + } finally { await bridge.close(); } +}); diff --git a/server/src/__tests__/secrets-routes.test.ts b/server/src/__tests__/secrets-routes.test.ts index ffd4c3893f6..73d37996bdf 100644 --- a/server/src/__tests__/secrets-routes.test.ts +++ b/server/src/__tests__/secrets-routes.test.ts @@ -303,6 +303,17 @@ describe("secret routes", () => { ); }); + it("does not turn agent discovery of personal entry into human identity authority", async () => { + const app = createApp({ type: "agent", agentId: "agent-1", companyId: "company-1" }); + expect((await request(app).get("/api/companies/company-1/user-secret-definitions")).status).toBe(403); + expect((await request(app).get("/api/companies/company-1/me/user-secrets")).status).toBe(403); + expect((await request(app).post("/api/companies/company-1/me/user-secrets").send({ + definitionKey: "github_token", value: "synthetic-value", + })).status).toBe(403); + expect(mockSecretService.listUserSecretDefinitions).not.toHaveBeenCalled(); + expect(mockSecretService.createCurrentUserSecretValue).not.toHaveBeenCalled(); + }); + it("creates current-user secret values for the authenticated user only", async () => { mockSecretService.createCurrentUserSecretValue.mockResolvedValue({ id: "secret-1", diff --git a/server/src/routes/openapi.ts b/server/src/routes/openapi.ts index 4a9edbfd568..b20abbaabde 100644 --- a/server/src/routes/openapi.ts +++ b/server/src/routes/openapi.ts @@ -5419,6 +5419,7 @@ registry.registerPath({ tags: ["secrets"], summary: "List secret metadata (id, name, key, status) — accessible to agents", + description: "Discover stored company credential metadata, never values. To add a company credential, direct the human to the company-prefixed /company/settings/secrets page and New secret, then bind only the intended agent's environment reference in its configuration. Secure storage of an already-requested key does not require connecting a new external service. Never request the value in chat or claim it is saved or bound before observing the authorized changes.", request: { params: z.object({ companyId: z.string() }) }, responses: { 200: r.ok(), 401: r.unauthorized, 403: r.forbidden }, }); @@ -5436,7 +5437,8 @@ registry.registerPath({ method: "post", path: "/api/companies/{companyId}/secrets", tags: ["secrets"], - summary: "Create a secret", + summary: "Create a company secret credential", + description: "Board-only secure credential entry. An agent cannot create the value on behalf of the human. Direct the human to New secret on the company-prefixed /company/settings/secrets page; never request the value in chat. After entry, use only the intended consumer's secret reference, not plaintext or a grant to every agent. A saved credential is not proof of runtime delivery.", request: { params: z.object({ companyId: z.string() }), body: jsonBody(createSecretSchema), @@ -5537,7 +5539,8 @@ registry.registerPath({ method: "get", path: "/api/companies/{companyId}/user-secret-definitions", tags: ["secrets"], - summary: "List user secret definitions", + summary: "List personal credential definitions (user secrets)", + description: "Board-only company-admin metadata for personal credential definitions, not their values. Agents cannot read this list using the human's identity. For an existing required personal credential, direct the current person to the company-prefixed /company/settings/secrets page, My secrets, then Set my value for the matching definition. Company admins can also open definition details with ?definition= when its ID is already known; other members use My secrets and Set my value. Only that signed-in person's value is set; another person's value cannot satisfy it. Never request values in chat. Storing a credential for an existing definition does not require choosing or connecting a new external provider.", request: { params: z.object({ companyId: z.string() }) }, responses: { 200: r.ok(), 401: r.unauthorized, 403: r.forbidden }, }); @@ -5613,7 +5616,8 @@ registry.registerPath({ method: "get", path: "/api/companies/{companyId}/me/user-secrets", tags: ["secrets"], - summary: "List my user secret values", + summary: "List my personal credential definitions and value metadata", + description: "Board-only current-person metadata. An agent cannot impersonate the person or list another owner's values. The signed-in person uses My secrets on the company-prefixed /company/settings/secrets page and Set my value for an existing definition; never send the value in chat. This secure entry is separate from connecting an external service. Confirm availability only after authorized entry and the intended task's required delivery have been observed.", request: { params: z.object({ companyId: z.string() }) }, responses: { 200: r.ok(), 401: r.unauthorized, 403: r.forbidden }, }); diff --git a/ui/src/pages/Secrets.render.test.tsx b/ui/src/pages/Secrets.render.test.tsx index ec834c7533c..0fd4be63427 100644 --- a/ui/src/pages/Secrets.render.test.tsx +++ b/ui/src/pages/Secrets.render.test.tsx @@ -814,18 +814,18 @@ describe("Secrets page layout", () => { }); }); - it("opens the each-user detail sheet with coverage and set-my-value actions", async () => { + it.each([false, true])("opens the admin-visible each-user secure-entry surface (definition link: %s)", async (fromLink) => { const definition = makeUserSecretDefinition(); mockSecretsApi.listUserSecretDefinitions.mockResolvedValue([definition]); mockSecretsApi.listMyUserSecrets.mockResolvedValue([{ definition, secret: null }]); - const root = await renderSecrets(container); + const root = await renderSecrets(container, { + path: fromLink ? `/company/settings/secrets?definition=${definition.id}` : "/company/settings/secrets", + }); const definitionRow = Array.from(container.querySelectorAll("[role='row']")).find( (row) => row.textContent?.includes("Personal GitHub token"), ) as HTMLElement | undefined; - await act(async () => { - definitionRow?.click(); - }); + if (!fromLink) await act(async () => { definitionRow?.click(); }); await waitForReact(() => document.body.textContent?.includes("Details") ?? false); expect(document.body.textContent).toContain("Personal GitHub token");