TypeScript
feat(server): agents ask for secrets through request_secret instead of chat (#30257)
Gabriel De Andrade9e85538535c8
diff --git a/apps/server/src/mcp/OrchestratorMcpService.activity.test.ts b/apps/server/src/mcp/OrchestratorMcpService.activity.test.tsindex f260093f3f1..c35b605dca4 100644--- a/apps/server/src/mcp/OrchestratorMcpService.activity.test.ts+++ b/apps/server/src/mcp/OrchestratorMcpService.activity.test.ts@@ -8,12 +8,16 @@ import {ProviderInstanceId,RunId,ScheduledTaskId,+ SECRET_REQUEST_UNSAVED_NOTE,ThreadId,TurnItemId,} from "@t3tools/contracts";import * as DateTime from "effect/DateTime";import * as Effect from "effect/Effect";+import * as Fiber from "effect/Fiber";import * as Layer from "effect/Layer";+import * as Metric from "effect/Metric";+import * as TestClock from "effect/testing/TestClock";import * as NodeCrypto from "@effect/platform-node/NodeCrypto";import { expect, it } from "vite-plus/test";@@ -655,3 +659,185 @@ it("readThread and sendToThread reach threads in other projects", async () => {expect(stopped.code).toBe("parent_not_active");}).pipe(Effect.provide(layer), Effect.runPromise);});++it("requestSecret saves a pasted value to a file without opening a card", async () => {+ const projection = {+ thread: baseThread({+ threadId: parentThreadId,+ title: "Parent",+ instanceId: parentInstanceId,+ model: "gpt-5.4",+ }),+ runs: [{ ...makeRun({ id: activeRunId, ordinal: 1, status: "running" }), rootNodeId: taskId }],+ visibleTurnItems: [],+ runtimeRequests: [],+ messages: [],+ contextTransfers: [],+ subagents: [],+ updatedAt: now,+ } as unknown as OrchestrationV2ThreadProjection;+ const dispatched: Array<unknown> = [];+ const saved: Array<{+ readonly requestNamespace: string;+ readonly requestKey: string;+ readonly value: string;+ }> = [];+ const file = "/home/user/.t3/userdata/secrets/files/0123456789abcdef0123456789abcdef";++ const layer = layerOrchestratorService.pipe(+ Layer.provide(+ Layer.mergeAll(+ Layer.mock(ThreadManagementService.ThreadManagementService)({+ getThreadRecords: (threadId) =>+ threadId === parentThreadId+ ? Effect.succeed(projection)+ : Effect.die(`unexpected thread ${threadId}`),+ getThreadShell: (threadId) =>+ Effect.succeed(+ threadId === parentThreadId+ ? (projection.thread as unknown as OrchestrationV2ThreadShell)+ : null,+ ),+ dispatch: (command) => Effect.sync(() => void dispatched.push(command) as never),+ } satisfies Partial<ThreadManagementService.ThreadManagementService["Service"]>),+ ServerSettings.layerTest(),+ Layer.mock(ProviderRegistry.ProviderRegistry)({+ getProviders: Effect.succeed([]),+ } satisfies Partial<ProviderRegistry.ProviderRegistry["Service"]>),+ Layer.mock(ProjectService.ProjectService)({}),+ Layer.mock(SecretRequests.SecretRequests)({+ savePasted: (input) =>+ Effect.sync(() => {+ saved.push({+ requestNamespace: input.requestNamespace,+ requestKey: input.requestKey,+ value: input.value,+ });+ return file;+ }),+ }),+ Layer.mock(RemoteDelegation.RemoteDelegation)({}),+ Layer.mock(ScheduledTaskService.ScheduledTaskService)({}),+ Layer.mock(ProviderAdapterRegistry.ProviderAdapterRegistryV2)({}),+ NodeCrypto.layer,+ ),+ ),+ );+ const counted = Metric.snapshot.pipe(+ Effect.map((snapshots) => {+ const found = snapshots.find(+ (snapshot) =>+ snapshot.id === "t3_secret_requests_total" &&+ snapshot.attributes?.status === "saved_pasted",+ );+ return found?.type === "Counter" ? Number(found.state.count) : 0;+ }),+ );++ await Effect.gen(function* () {+ const service = yield* OrchestratorMcpService.OrchestratorMcpService;+ const before = yield* counted;+ const result = yield* service.requestSecret(makeScope(), {+ label: "Pixel PIN",+ reason: "Unlocks the test phone.",+ value: "482916",+ clientRequestId: "pin-1",+ });+ expect(result).toEqual({ status: "saved", file });+ expect(JSON.stringify(result)).not.toContain("482916");+ expect(saved).toEqual([+ {+ requestNamespace: "provider-session-mcp-orchestrator-detail",+ requestKey: "pin-1",+ value: "482916",+ },+ ]);+ expect(dispatched).toEqual([]);+ expect((yield* counted) - before).toBe(1);++ const asRef = yield* service+ .requestSecret(makeScope(), {+ label: "Pixel PIN",+ reason: "Unlocks the test phone.",+ value: "482916",+ delivery: "secretRef",+ })+ .pipe(Effect.flip);+ expect(asRef.code).toBe("invalid_request");+ expect(asRef.message).not.toContain("482916");+ expect(saved).toHaveLength(1);+ expect(dispatched).toEqual([]);+ }).pipe(Effect.provide(layer), Effect.runPromise);+});++it("requestSecret returns the unsaved note for a declined, cancelled or timed-out card", async () => {+ const outcomes = ["declined", "cancelled", "pending"] as const;+ const results = await Effect.forEach(outcomes, (outcome) => {+ const dispatched: Array<{ readonly type: string; readonly turnItemId?: string }> = [];+ const projection = () => {+ const card = dispatched.find((command) => command.type === "secret_request.record");+ return {+ thread: baseThread({+ threadId: parentThreadId,+ title: "Parent",+ instanceId: parentInstanceId,+ model: "gpt-5.4",+ }),+ runs: [+ { ...makeRun({ id: activeRunId, ordinal: 1, status: "running" }), rootNodeId: taskId },+ ],+ visibleTurnItems: [],+ turnItems:+ card === undefined+ ? []+ : [{ type: "secret_request", id: card.turnItemId, secretStatus: outcome }],+ runtimeRequests: [],+ messages: [],+ contextTransfers: [],+ subagents: [],+ updatedAt: now,+ } as unknown as OrchestrationV2ThreadProjection;+ };+ const layer = layerOrchestratorService.pipe(+ Layer.provide(+ Layer.mergeAll(+ Layer.mock(ThreadManagementService.ThreadManagementService)({+ getThreadRecords: () => Effect.sync(projection),+ getThreadShell: () =>+ Effect.sync(() => projection().thread as unknown as OrchestrationV2ThreadShell),+ dispatch: (command) => Effect.sync(() => void dispatched.push(command) as never),+ } satisfies Partial<ThreadManagementService.ThreadManagementService["Service"]>),+ ServerSettings.layerTest(),+ Layer.mock(ProviderRegistry.ProviderRegistry)({+ getProviders: Effect.succeed([]),+ } satisfies Partial<ProviderRegistry.ProviderRegistry["Service"]>),+ Layer.mock(ProjectService.ProjectService)({}),+ Layer.mock(SecretRequests.SecretRequests)({}),+ Layer.mock(RemoteDelegation.RemoteDelegation)({}),+ Layer.mock(ScheduledTaskService.ScheduledTaskService)({}),+ Layer.mock(ProviderAdapterRegistry.ProviderAdapterRegistryV2)({}),+ NodeCrypto.layer,+ ),+ ),+ );+ return Effect.gen(function* () {+ const service = yield* OrchestratorMcpService.OrchestratorMcpService;+ const request = yield* service+ .requestSecret(makeScope(), {+ label: "Staging password",+ reason: "Signs in the QA account.",+ delivery: "file",+ timeoutMs: 1_000,+ })+ .pipe(Effect.forkChild({ startImmediately: true }));+ yield* TestClock.adjust("2 seconds");+ return yield* Fiber.join(request);+ }).pipe(Effect.provide(Layer.merge(layer, TestClock.layer())));+ }).pipe(Effect.runPromise);++ expect(results).toEqual([+ { status: "declined", note: SECRET_REQUEST_UNSAVED_NOTE.declined },+ { status: "cancelled", note: SECRET_REQUEST_UNSAVED_NOTE.cancelled },+ { status: "timed_out", note: SECRET_REQUEST_UNSAVED_NOTE.timed_out },+ ]);+});diff --git a/apps/server/src/mcp/OrchestratorMcpService.ts b/apps/server/src/mcp/OrchestratorMcpService.tsindex e84212cab00..e53ed03a7c6 100644--- a/apps/server/src/mcp/OrchestratorMcpService.ts+++ b/apps/server/src/mcp/OrchestratorMcpService.ts@@ -63,6 +63,7 @@ import {ThreadId,isOrchestrationV2WorkActive,resolveProjectProviderInstanceEnabled,+ SECRET_REQUEST_UNSAVED_NOTE,} from "@t3tools/contracts";import { getProviderOptionCurrentValue } from "@t3tools/shared/model";import { runRanAfter } from "@t3tools/shared/orchestrationV2ThreadError";@@ -2135,6 +2136,26 @@ const make = Effect.gen(function* () {"Asking for a secret requires an active run owned by this MCP provider session.",);}+ // A secret the user already pasted needs no card: it goes straight to a file.+ if (input.value !== undefined) {+ if (input.delivery === "secretRef") {+ return yield* failure(+ "invalid_request",+ 'A pasted `value` is saved as a file. Leave out `delivery: "secretRef"`.',+ );+ }+ const file = yield* secretRequests+ .savePasted({+ threadId,+ requestNamespace: scope.requestNamespace,+ requestKey: yield* requestKey(input.clientRequestId),+ value: input.value,+ })+ .pipe(Effect.mapError((error) => failure("orchestration_error", error.message)));+ yield* Effect.annotateCurrentSpan({ "secret_request.status": "saved_pasted" });+ yield* Metrics.increment(Metrics.secretRequestsTotal, { status: "saved_pasted" });+ return { status: "saved" as const, file };+ }const runId = run.id;const nodeId = run.rootNodeId;const key = yield* requestKey(input.clientRequestId);@@ -2235,7 +2256,7 @@ const make = Effect.gen(function* () {);yield* Effect.annotateCurrentSpan({ "secret_request.status": status });yield* Metrics.increment(Metrics.secretRequestsTotal, { status });- if (status !== "saved") return { status };+ if (status !== "saved") return { status, note: SECRET_REQUEST_UNSAVED_NOTE[status] };if (input.delivery === "file") {const file = yield* secretRequests.saveToFile({ threadId, turnItemId })diff --git a/apps/server/src/mcp/toolkits/orchestrator/tools.ts b/apps/server/src/mcp/toolkits/orchestrator/tools.tsindex 7c05f5c8d8e..150962e232a 100644--- a/apps/server/src/mcp/toolkits/orchestrator/tools.ts+++ b/apps/server/src/mcp/toolkits/orchestrator/tools.ts@@ -85,7 +85,7 @@ const OrchestratorCapabilitiesTool = Tool.make("orchestrator_capabilities", {const DelegateTaskTool = Tool.make("delegate_task", {description:- "Start one child agent with only `task`. No parent history. Separate checkout or PR per child: `isolation:'worktree'`. Keep `taskId` for `task_status` and `task_cancel`.",+ "Start one child agent with only `task`. No parent history. Separate checkout or PR per child: `isolation:'worktree'`. Keep `taskId` for `task_status` and `task_cancel`. No secrets in `task`.",parameters: OrchestratorMcpDelegateTaskInput,success: OrchestratorMcpDelegateTaskResult,failure: OrchestratorMcpFailure,@@ -197,7 +197,7 @@ const DeleteScheduledTaskTool = Tool.make("delete_scheduled_task", {const RequestSecretTool = Tool.make("request_secret", {description:- 'Ask the user to enter a secret in a private card and wait. You never see the value. Returns a one-use `secretRef` for a tool that accepts it, or with `delivery: "file"` a private file path to read inside a shell command. Asked how to provide a secret: call this now, do not explain instead.',+ 'Ask for a secret in a private card and wait; open it, don\'t offer it. Returns a one-use `secretRef`, or with `delivery: "file"` a file to read only in its command, e.g. `adb pair <ip:port> "$(cat <file>)"`. Asked how to give one: call now. Pasted secret for child or script: `value`. Not one from an old thread.',parameters: OrchestratorMcpRequestSecretInput,success: OrchestratorMcpRequestSecretResult,failure: OrchestratorMcpFailure,@@ -205,7 +205,9 @@ const RequestSecretTool = Tool.make("request_secret", {dependencies,}).annotate(Tool.Title, "Request a secret from the user")- .annotate(Tool.Destructive, false);+ .annotate(Tool.Destructive, false)+ // Claude Code defers MCP tools behind ToolSearch; agents that never load this one ask in chat.+ .annotate(Tool.Meta, { "anthropic/alwaysLoad": true });const CreateThreadsTool = Tool.make("create_threads", {description:diff --git a/apps/server/src/provider/AgentContextBudget.test.ts b/apps/server/src/provider/AgentContextBudget.test.tsindex c4e3b812408..08bfd011514 100644--- a/apps/server/src/provider/AgentContextBudget.test.ts+++ b/apps/server/src/provider/AgentContextBudget.test.ts@@ -106,6 +106,22 @@ const codexAdditionalContext = () =>.map((entry) => entry.value).join("");+const layerAdvertisedTools = McpHttpServer.layerTools.pipe(+ Layer.provideMerge(McpHttpServer.layerInProcessMcpServer),+ Layer.provide(toolHandlerServices),+);++// Claude Code loads these tools up front instead of behind ToolSearch, outside this budget.+it.effect("only request_secret asks Claude Code to load it up front", () =>+ Effect.gen(function* () {+ const mcp = yield* McpServer.McpServer;+ const alwaysLoad = mcp.tools+ .filter(({ tool }) => tool._meta?.["anthropic/alwaysLoad"] !== undefined)+ .map(({ tool }) => [tool.name, tool._meta]);+ expect(alwaysLoad).toEqual([["request_secret", { "anthropic/alwaysLoad": true }]]);+ }).pipe(Effect.provide(layerAdvertisedTools)),+);+// CI rejects a PR that raises any value above main's agentContextBudget.json, so growth// needs the agent-context-increase label. Lower the values when the text shrinks.it.effect("agent context matches the committed budget", () =>@@ -130,12 +146,5 @@ it.effect("agent context matches the committed budget", () =>measured,"Set agentContextBudget.json to the measured values. Before you cut text to fit, run the evals that cover it (evals/README.md).",).toEqual(budget);- }).pipe(- Effect.provide(- McpHttpServer.layerTools.pipe(- Layer.provideMerge(McpHttpServer.layerInProcessMcpServer),- Layer.provide(toolHandlerServices),- ),- ),- ),+ }).pipe(Effect.provide(layerAdvertisedTools)),);diff --git a/apps/server/src/provider/agentContextBudget.json b/apps/server/src/provider/agentContextBudget.jsonindex 1719d3ca6bd..bb586d5b9f4 100644--- a/apps/server/src/provider/agentContextBudget.json+++ b/apps/server/src/provider/agentContextBudget.json@@ -1,5 +1,5 @@{- "claudeSystemAppendBytes": 5153,- "codexAdditionalContextBytes": 6883,- "mcpToolListJsonBytes": 47538+ "claudeSystemAppendBytes": 5133,+ "codexAdditionalContextBytes": 6863,+ "mcpToolListJsonBytes": 47498}diff --git a/apps/server/src/secrets/SecretRequests.test.ts b/apps/server/src/secrets/SecretRequests.test.tsindex 8962e5d4103..c362a1b0ed7 100644--- a/apps/server/src/secrets/SecretRequests.test.ts+++ b/apps/server/src/secrets/SecretRequests.test.ts@@ -3,6 +3,7 @@ import * as NodeServices from "@effect/platform-node/NodeServices";import { assert, it } from "@effect/vitest";import * as HostProcess from "@t3tools/shared/HostProcess";import {+ OrchestratorMcpRequestSecretInput,ProjectId,type OrchestrationV2ServerCommand,SecretRef,@@ -10,6 +11,7 @@ import {TurnItemId,} from "@t3tools/contracts";import * as Effect from "effect/Effect";+import * as Exit from "effect/Exit";import * as FileSystem from "effect/FileSystem";import * as Layer from "effect/Layer";import * as Metric from "effect/Metric";@@ -17,6 +19,7 @@ import * as Tracer from "effect/Tracer";import * as Option from "effect/Option";import * as Path from "effect/Path";import * as PlatformError from "effect/PlatformError";+import * as Schema from "effect/Schema";import * as TestClock from "effect/testing/TestClock";import * as ServerSecretStore from "../auth/ServerSecretStore.ts";@@ -26,6 +29,8 @@ import * as SecretRequests from "./SecretRequests.ts";const threadId = ThreadId.make("thread-orchestrator");const turnItemId = TurnItemId.make("turn-item:secret-request:1");const projectId = ProjectId.make("project-1");+const decodeSecretInput = Schema.decodeUnknownEffect(OrchestratorMcpRequestSecretInput);+const decodeSecretInputExit = Schema.decodeUnknownExit(OrchestratorMcpRequestSecretInput);const withService = <A, E>(body: (input: {@@ -456,3 +461,130 @@ it.effect("a secret the card promised to keep from the agent is never written to}),),);++it.effect("a pasted secret goes straight to an owner-only file, with no card", () =>+ Effect.gen(function* () {+ const fs = yield* FileSystem.FileSystem;+ const path = yield* Path.Path;+ const directory = yield* fs.makeTempDirectoryScoped({ prefix: "secret-files-test-" });+ const spans: Array<Tracer.NativeSpan> = [];+ const tracer = Tracer.make({+ span: (options) => {+ const span = new Tracer.NativeSpan(options);+ spans.push(span);+ return span;+ },+ });+ const pasted = "4829'$(id) 16";+ const file = yield* withService(+ ({ service, stored, dispatched }) =>+ Effect.gen(function* () {+ const file = yield* service.savePasted({+ threadId,+ requestNamespace: "session-a",+ requestKey: "key-1",+ value: pasted,+ });+ assert.equal(path.dirname(file), path.join(directory, "files"));+ assert.match(path.basename(file), /^[0-9a-f]{32}$/);+ assert.equal(yield* fs.readFileString(file), pasted);+ if ((yield* HostProcess.Platform) !== "win32") {+ assert.equal((yield* fs.stat(file)).mode & 0o777, 0o600);+ assert.equal((yield* fs.stat(path.dirname(file))).mode & 0o777, 0o700);+ }+ // No card and no stored copy: the thread never hears of it.+ assert.deepEqual(dispatched, []);+ assert.deepEqual(valuesOf(stored), []);+ // A retry with the same key gets the same file, unchanged even if the value differs.+ assert.equal(+ yield* service.savePasted({+ threadId,+ requestNamespace: "session-a",+ requestKey: "key-1",+ value: "other",+ }),+ file,+ );+ assert.equal(yield* fs.readFileString(file), pasted);+ // Another key, or the same key from another provider session, gets its own file.+ const other = yield* service.savePasted({+ threadId,+ requestNamespace: "session-a",+ requestKey: "key-2",+ value: "x",+ });+ assert.notEqual(other, file);+ const otherSession = yield* service.savePasted({+ threadId,+ requestNamespace: "session-b",+ requestKey: "key-1",+ value: "y",+ });+ assert.notEqual(otherSession, file);+ assert.equal(yield* fs.readFileString(file), pasted);+ // Its name is not a ref to the value.+ const ref = SecretRef.make(`secret-ref:${path.basename(file)}`);+ const reused = yield* service.consume({ ref, projectId }).pipe(Effect.flip);+ assert.equal(reused.reason, "ref_unavailable");+ return file;+ }).pipe(Effect.withTracer(tracer)),+ { directory },+ );+ const recorded = spans.flatMap((span) => [+ span.name,+ ...Array.from(span.attributes.values(), String),+ ]);+ assert.include(recorded, "SecretRequests.savePasted");+ assert.isFalse(recorded.some((value) => value.includes("4829")));++ const { mtime } = yield* fs.stat(file);+ yield* TestClock.setTime(Option.getOrThrow(mtime).getTime() + SECRET_FILE_TTL_MS);+ yield* withService(() => Effect.void, { directory });+ assert.isTrue(yield* fs.exists(file));+ yield* TestClock.setTime(Option.getOrThrow(mtime).getTime() + SECRET_FILE_TTL_MS + 1);+ yield* withService(() => Effect.void, { directory });+ assert.isFalse(yield* fs.exists(file));+ }).pipe(Effect.provide(NodeServices.layer)),+);++it.effect("a pasted secret keeps its exact bytes from the tool input to the file", () =>+ Effect.gen(function* () {+ const fs = yield* FileSystem.FileSystem;+ const directory = yield* fs.makeTempDirectoryScoped({ prefix: "secret-files-test-" });+ const pasted = " pa ss\tword\t ";+ const input = yield* decodeSecretInput({+ label: "Staging password",+ reason: "Signs in the QA account.",+ value: pasted,+ });+ assert.equal(input.value, pasted);+ const empty = decodeSecretInputExit({+ label: "Staging password",+ reason: "Signs in the QA account.",+ value: "",+ });+ assert.isTrue(Exit.isFailure(empty));+ const file = yield* withService(+ ({ service }) =>+ service.savePasted({+ threadId,+ requestNamespace: "session-a",+ requestKey: "key-1",+ value: input.value!,+ }),+ { directory },+ );+ assert.equal(yield* fs.readFileString(file), pasted);+ }).pipe(Effect.provide(NodeServices.layer)),+);++it.effect("a pasted secret is refused without a secrets directory", () =>+ withService(({ service }) =>+ Effect.gen(function* () {+ const failed = yield* service+ .savePasted({ threadId, requestNamespace: "session-a", requestKey: "key-1", value: "4829" })+ .pipe(Effect.flip);+ assert.equal(failed.reason, "store_failed");+ }),+ ),+);diff --git a/apps/server/src/secrets/SecretRequests.ts b/apps/server/src/secrets/SecretRequests.tsindex 9e3a7c033c2..4d713f9bf7e 100644--- a/apps/server/src/secrets/SecretRequests.ts+++ b/apps/server/src/secrets/SecretRequests.ts@@ -1,6 +1,7 @@// Answers stay in the secret store behind one-use refs; orchestration records only request status.// Consuming tools keep values out of transcripts, projections, clients and model context.// A `file` request instead moves its value to an owner-only file for the agent's own shell.+// A secret the user pasted in chat goes straight to such a file, with no card.import { pipe } from "effect/Function";import {CommandId,@@ -66,6 +67,14 @@ export class SecretRequests extends Context.Service<readonly threadId: ThreadId;readonly turnItemId: string;}) => Effect.Effect<string, SecretRequestError>;+ /** Writes a secret the user pasted in chat to an owner-only file and returns its path. */+ readonly savePasted: (input: {+ readonly threadId: ThreadId;+ /** The provider session's namespace, so two sessions' keys never share a file. */+ readonly requestNamespace: string;+ readonly requestKey: string;+ readonly value: string;+ }) => Effect.Effect<string, SecretRequestError>;}>()("t3/secrets/SecretRequests") {}@@ -232,6 +241,23 @@ const make = Effect.gen(function* () {return value;});+ const writeSecretFile = (dir: string, file: string, value: string) => {+ const partial = `${file}.partial`;+ return fileSystem.makeDirectory(dir, { recursive: true, mode: 0o700 }).pipe(+ Effect.andThen(fileSystem.chmod(dir, 0o700)),+ Effect.andThen(fileSystem.remove(partial, { force: true })),+ // `wx` never follows or replaces an existing path.+ Effect.andThen(+ fileSystem.writeFile(partial, new TextEncoder().encode(value), {+ flag: "wx",+ mode: 0o600,+ }),+ ),+ Effect.andThen(fileSystem.rename(partial, file)),+ Effect.mapError((cause) => new SecretRequestError({ reason: "store_failed", cause })),+ );+ };+const saveToFile: SecretRequests["Service"]["saveToFile"] = Effect.fn("SecretRequests.saveToFile",)(function* (input) {@@ -266,24 +292,30 @@ const make = Effect.gen(function* () {}// The stored value goes only after the file is complete, so a failed write can retry.const value = yield* readRef({ ref, projectId: records.thread.projectId });- const partial = `${file}.partial`;- yield* fileSystem.makeDirectory(filesDir, { recursive: true, mode: 0o700 }).pipe(- Effect.andThen(fileSystem.chmod(filesDir, 0o700)),- Effect.andThen(fileSystem.remove(partial, { force: true })),- // `wx` never follows or replaces an existing path.- Effect.andThen(- fileSystem.writeFile(partial, new TextEncoder().encode(value), {- flag: "wx",- mode: 0o600,- }),- ),- Effect.andThen(fileSystem.rename(partial, file)),- Effect.mapError((cause) => new SecretRequestError({ reason: "store_failed", cause })),- );+ yield* writeSecretFile(filesDir, file, value);return yield* removeStored;}).pipe(consumeLock.withPermits(1));});+ const savePasted: SecretRequests["Service"]["savePasted"] = Effect.fn(+ "SecretRequests.savePasted",+ )(function* (input) {+ if (filesDir === undefined) return yield* new SecretRequestError({ reason: "store_failed" });+ const ref = refFor(+ salt,+ input.threadId,+ `pasted\u0000${input.requestNamespace}\u0000${input.requestKey}`,+ );+ const file = path.join(filesDir, ref.slice(SECRET_REF_PREFIX.length));+ // A retry with the same clientRequestId gets the file the first call wrote, unchanged, so a+ // command already holding that path never reads another value.+ return yield* Effect.gen(function* () {+ if (yield* fileSystem.exists(file).pipe(Effect.orElseSucceed(() => false))) return file;+ yield* writeSecretFile(filesDir, file, input.value);+ return file;+ }).pipe(consumeLock.withPermits(1));+ });+const sweepExpired = Effect.gen(function* () {if (store.directory === undefined) return;const now = yield* Clock.currentTimeMillis;@@ -330,7 +362,7 @@ const make = Effect.gen(function* () {Effect.forkScoped,);- return SecretRequests.of({ answer, savedRef, consume, saveToFile });+ return SecretRequests.of({ answer, savedRef, consume, saveToFile, savePasted });});export const layer = Layer.effect(SecretRequests, make);diff --git a/packages/contracts/src/orchestratorMcp.ts b/packages/contracts/src/orchestratorMcp.tsindex 1d6d7f3d679..6756225666f 100644--- a/packages/contracts/src/orchestratorMcp.ts+++ b/packages/contracts/src/orchestratorMcp.ts@@ -728,6 +728,11 @@ export const OrchestratorMcpUpdateScheduledTaskInput = Schema.Struct({export type OrchestratorMcpUpdateScheduledTaskInput =typeof OrchestratorMcpUpdateScheduledTaskInput.Type;+// Not trimmed: whitespace in a password matters. The check stays out of the advertised schema.+const PastedSecretValue = Schema.String.check(+ Schema.makeFilter((value: string) => value.length > 0, { expected: "a non-empty string" }),+);+export const OrchestratorMcpRequestSecretInput = Schema.Struct({label: TrimmedNonEmptyString.annotate({description: "Card title, such as 'GitHub webhook secret'.",@@ -737,14 +742,17 @@ export const OrchestratorMcpRequestSecretInput = Schema.Struct({}),placeholder: Schema.optional(TrimmedNonEmptyString),delivery: Schema.optional(Schema.Literals(["secretRef", "file"])).annotate({- description:- 'secretRef (default) for a T3 tool. file for a shell CLI: read the path in your command, e.g. TOKEN="$(cat <file>)" wrangler whoami.',+ description: "secretRef (default) for a T3 tool; file for a command.",}),+ value: Schema.optional(PastedSecretValue).annotate({+ description: "Pasted in this thread; no card.",+ }),+ /** Default 10 minutes. */timeoutMs: Schema.optional(Schema.Int.check(Schema.isBetween({ minimum: 1_000, maximum: 60 * 60 * 1_000 })),- ).annotate({ description: "Default 10 min." }),+ ),clientRequestId: Schema.optional(OrchestratorMcpClientRequestId).annotate({- description: "Retry key for this ask. New key after a timeout or cancel.",+ description: "Retry key.",}),});export type OrchestratorMcpRequestSecretInput = typeof OrchestratorMcpRequestSecretInput.Type;@@ -766,8 +774,9 @@ export const OrchestratorMcpRequestSecretResult = Schema.Union([Schema.Struct({status: Schema.Literals(["declined", "cancelled", "timed_out"]).annotate({description:- "declined: user chose not to. cancelled: ended with the run. timed_out: no answer in time. Ask again with a new `clientRequestId` if still needed.",+ "declined: user chose not to; don't ask again. cancelled: ended with the run. timed_out: no answer in time. After cancelled or timed_out, ask again with a new `clientRequestId` only if still needed.",}),+ note: Schema.optional(Schema.String).annotate({ description: "What to do next." }),}),]);export type OrchestratorMcpRequestSecretResult = typeof OrchestratorMcpRequestSecretResult.Type;diff --git a/packages/contracts/src/secretRequest.ts b/packages/contracts/src/secretRequest.tsindex 2506d064b53..b449a17643d 100644--- a/packages/contracts/src/secretRequest.ts+++ b/packages/contracts/src/secretRequest.ts@@ -13,6 +13,16 @@ export const SecretRequestAnswerInput = Schema.Struct({});export type SecretRequestAnswerInput = typeof SecretRequestAnswerInput.Type;+/** What the agent reads when its card ends without a secret. */+export const SECRET_REQUEST_UNSAVED_NOTE = {+ declined:+ "The user declined. Don't ask for it in chat or another way; say what's blocked and go on without it.",+ cancelled:+ "The card closed with the run. Ask again with a new clientRequestId only if the secret is still needed.",+ timed_out:+ "No answer in time. Don't ask in chat; ask again with a new clientRequestId only if it is still needed.",+} as const;+const SECRET_REQUEST_FAILURE_MESSAGES = {load_failed: "Could not load the secret request.",not_found: "This secret request no longer exists.",diff --git a/packages/provider-core/src/server/orchestrationInstructions.ts b/packages/provider-core/src/server/orchestrationInstructions.tsindex 90ed18e9b33..efe3fc242d9 100644--- a/packages/provider-core/src/server/orchestrationInstructions.ts+++ b/packages/provider-core/src/server/orchestrationInstructions.ts@@ -16,7 +16,7 @@ Ordinary coding tasks need no T3 tools.- Another machine: \`t3_environment_links\` lists linked ones. Pass its \`environmentId\` to a T3 tool to act there. Ids are then that machine's, so pass \`threadId\`.- A machine the user names that is not linked ("delegate this to my vps"): call \`t3_environment_link\` with a \`hint\` from their words. Never ask for a pairing code in chat.- In your reply, mention a thread by its \`link\`, verbatim. Never a plain title or bare id.-- A secret: call \`request_secret\` yourself. Pass its \`secretRef\` to a T3 tool, or use \`delivery: "file"\` for a shell command. Never ask in chat or invent one. When asked only to schedule, \`schedule_task\` without running its prompt.+- A login, token, PIN or pairing code only the user can give: call \`request_secret\`, not a chat ask or a handoff. Not for access you have. When asked only to schedule, \`schedule_task\` without running its prompt.- T3 tools may load late. Try the name once before you call it absent.`,`### Visuals and preview