Terminal
Terminal/Skill
Scaffolds a Temporal TypeScript worker where each activity is checked against Ory permissions and logged, for you to run yourself.
By Ory
Works with
npx skills add ory/claude-plugins --skill ory-temporal-workerYou are helping the user scaffold a Temporal TypeScript worker where every Activity execution is gated by Ory: the user is authenticated, the worker's agent identity is resolved via OAuth2 Dynamic Client Registration, each Activity invocation runs an Ory Permission check, and the full lifecycle emits structured activity events. Workflows stay deterministic — only Activities call out to Ory.
This skill carries the workflow. You generate the files in the user's repo; the user runs the Temporal CLI and the worker.
Precondition: Node.js 20+ is installed, and the user has installed (or will install) the Temporal CLI. On macOS:
brew install temporal. On Linux/Windows: download from https://temporal.download and puttemporalonPATH. If the binary is missing, point the user at the docs and stop — do not fabricate it.
Before writing files, confirm with the user:
temporal-worker/ at the repo
root unless the user says otherwise.agent-tools. The worker and the workflow
starter must agree on this string./ory-agent-plugin:local-up) on http://localhost:4000. For Ory Network, the user
plumbs their project URL through the worker's env. Either way the worker
needs network reachability to the Ory APIs at runtime.Run the official Temporal scaffold and select the hello-world sample when
prompted. Then add the Ory agent client:
npx @temporalio/create@latest temporal-worker
cd temporal-worker
npm install @ory/argus
The scaffold lays down src/{activities.ts, workflows.ts, worker.ts, client.ts}
and pre-configures the Worker to connect to the Temporal dev server at
localhost:7233. The Web UI lives at http://localhost:8233 once the dev
server is running.
Activities are where side effects happen, so they are the right place to put the permission check. Never call Ory from inside a Workflow — Workflows are deterministic and replayed; a live Ory call would break replay safety.
Replace the scaffold's src/activities.ts with:
import { Context } from "@temporalio/activity";
import {
OryAgentClient,
ensureUserAuthenticated,
ensureAgentIdentity,
checkAndDecide,
resolveUserSubject,
subjectLabel,
} from "@ory/argus";
// One client per worker process. `harness` is a label that shows up on
// every activity event so worker-originated audit lives in its own namespace
// alongside the CLI plugins.
const ory = OryAgentClient.fromEnv("temporal");
// Run the user + agent gates exactly once per process. Activities call
// `bootstrap()` lazily and await the same promise on subsequent calls.
let bootstrapped: Promise<void> | undefined;
function bootstrap(): Promise<void> {
if (!bootstrapped) {
bootstrapped = (async () => {
await ensureUserAuthenticated(ory, {
binName: "temporal-worker",
harness: "temporal",
// The user gate runs every invocation and never blocks: it refreshes
// tokens and emits the audit event, but the worker proceeds even if the
// user is unauthenticated. Enforcement happens at the per-Activity
// permission check (permissionMode).
});
await ensureAgentIdentity(ory, {
projectUrl: process.env.ORY_PROJECT_URL,
});
})();
}
return bootstrapped;
}
async function gate(toolName: string, userSubject: string): Promise<void> {
await bootstrap();
const subject = resolveUserSubject(ory, userSubject);
const decision = await checkAndDecide(
ory,
{
namespace: process.env.ORY_PERMISSION_NAMESPACE ?? "AgentTool",
object: toolName,
relation: "use",
...subject,
},
{
activityAttributes: {
toolName,
workflowId: Context.current().info.workflowExecution.workflowId,
activityId: Context.current().info.activityId,
},
}
);
switch (decision.kind) {
case "allow":
case "observe":
case "fail_open":
return;
case "deny":
throw new Error(
`Ory denied use of ${toolName} for ${subjectLabel(subject)}`
);
}
}
export async function sendEmail(input: {
user: string;
to: string;
subject: string;
}): Promise<string> {
await gate("send_email", input.user);
// …real side effect here…
return `sent to ${input.to}`;
}
Key choices:
harness: "temporal". Distinguishes worker-originated events in the
unified activity log.Workflows must be deterministic, so they cannot read process.env or call out
to Ory. The user subject travels as Workflow input. Update src/workflows.ts:
import { proxyActivities } from "@temporalio/workflow";
import type * as activities from "./activities";
const { sendEmail } = proxyActivities<typeof activities>({
startToCloseTimeout: "1 minute",
});
export async function notifyUser(input: {
user: string;
to: string;
}): Promise<string> {
return sendEmail({
user: input.user,
to: input.to,
subject: "hello",
});
}
And src/client.ts:
import { Connection, Client } from "@temporalio/client";
import { nanoid } from "nanoid";
import { notifyUser } from "./workflows";
const client = new Client({ connection: await Connection.connect() });
const handle = await client.workflow.start(notifyUser, {
taskQueue: "agent-tools",
workflowId: `notify-${nanoid()}`,
args: [{ user: "user@example.com", to: "alice@example.com" }],
});
console.log("workflow started:", handle.workflowId);
console.log("result:", await handle.result());
src/worker.ts stays as the scaffold writes it — Worker.create already
registers Workflows and Activities together and listens on the task queue.
Three terminals. See /ory-agent-plugin:local-up for the Ory side; the Temporal side uses
the Temporal CLI's bundled dev server (Postgres + Temporal Server + Web UI in
one process):
# Terminal 1 — local Ory stack (Kratos, Keto, Hydra, gateway)
`/ory-agent-plugin:local-up`
# Terminal 2 — local Temporal dev server (Web UI at http://localhost:8233)
temporal server start-dev
# Terminal 3 — the worker, pointed at both
cd temporal-worker
export ORY_PROJECT_URL=http://localhost:4000
export ORY_AUTH_GATE=1
export ORY_AGENT_DEBUG=true
export ORY_AGENT_LOG_FILE=$PWD/ory-agent-debug.log
npm run start # boots the worker, polls task queue
In a fourth terminal, kick the workflow once:
cd temporal-worker
npm run workflow
Tail the activity log to confirm the gates fired:
tail -f ory-agent-debug.log | jq .
You should see:
user.auth activity event (the worker's first Activity triggered
bootstrap()),agent.auth activity event,tool.invoke (allow) or tool.block (deny) event per Activity
execution.The Workflow itself produces no Ory activity — only its Activities do.
The worker starts in observe mode by default: explicit blocks pass through but
each is recorded as a permission.block_observed activity event. Once the user
has confirmed the block set is what they expect, an admin promotes the posture to enforce in
the Ory Console (Agent Security). It is a permission on the project, read on
every session, so the worker picks it up on its next run with no redeploy.
Activities are allowed by default. Add blockedSubjects relations for Activity
names that must not run, then review them before promoting the posture. See
/project:ory-permissions-onboarding.
To exercise the deny path locally, add a blockedSubjects relation for an
Activity name, kick the Workflow, and watch the explicit-block error in the
Temporal Web UI.
This skill stops at the local dev server. For production:
ORY_AGENT_CLIENT_ID + ORY_AGENT_CLIENT_SECRET (client_credentials) so the worker doesn't
re-register on every cold start.temporal server start-dev; the worker code does not change./project:ory-auth-setup for that.temporal server start-dev and
npm run start locally; production deployment is out of scope.@ory/argus versions. For reproducibility, pin
both in the generated package.json before committing.