From eae187663033302e8bc4ca9cf1a99a3862fc1714 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Sun, 2 Aug 2026 11:20:52 +0000
Subject: [PATCH] feat: add rig/globals with ambient call, fix pipeline null
propagation, fix tsconfig baseUrl
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
---
package.json | 1 +
skills/rig/SKILL.md | 1 +
skills/rig/globals.ts | 73 ++++++++++++++++++++++
skills/rig/references/dynamic-workflows.md | 25 ++++++--
skills/rig/rig.ts | 1 +
src/workflow.test.ts | 53 ++++++++++++++++
tsconfig.json | 3 +-
vitest.config.ts | 1 +
8 files changed, 152 insertions(+), 6 deletions(-)
create mode 100644 skills/rig/globals.ts
diff --git a/package.json b/package.json
index 8ad3af9..1b8c370 100644
--- a/package.json
+++ b/package.json
@@ -5,6 +5,7 @@
"exports": {
".": "./skills/rig/rig.ts",
"./eslint": "./skills/rig/eslint/index.js",
+ "./globals": "./skills/rig/globals.ts",
"./engines/anthropic": "./skills/rig/engines/anthropic.ts",
"./engines/codex": "./skills/rig/engines/codex.ts",
"./engines/gemini": "./skills/rig/engines/gemini.ts",
diff --git a/skills/rig/SKILL.md b/skills/rig/SKILL.md
index bd2e51e..c6596a8 100644
--- a/skills/rig/SKILL.md
+++ b/skills/rig/SKILL.md
@@ -63,6 +63,7 @@ Defaults: `name: "agent"`, `model: "small"`, `maxTurns: 4`, string input/output,
| One-off prompt inside a workflow | `call.text(prompt)` for a string, `call.json(prompt, schema)` for structured output |
| Reusable workflow step | Define an `agent({ input, output })` and `call(worker, input, { label, phase })` |
| Phase or log from an agent program | Import `phase` / `log` from `rig` and call them at top level; the launcher runs every program inside a workflow |
+| Ambient `call` outside `body` | Import `call` from `"rig/globals"`; it routes through the active workflow context automatically. Do not import from `"rig/globals"` unless you need it — this avoids polluting non-workflow code. |
| Custom model-callable operation | `defineTool(name, { description, parameters, handler })` |
| Structured-output retries | `maxTurns` on the agent plus `addons: [repair()]` |
| Retry with final-turn warning | `addons: [steering(), repair()]` in that order |
diff --git a/skills/rig/globals.ts b/skills/rig/globals.ts
new file mode 100644
index 0000000..4663fe7
--- /dev/null
+++ b/skills/rig/globals.ts
@@ -0,0 +1,73 @@
+/**
+ * Ambient workflow context helpers.
+ *
+ * Import from `"rig/globals"` to access `call`, `pipeline`, and `parallel`
+ * as module-level functions that automatically delegate to the active workflow
+ * run via `currentWorkflow()`. This keeps rig programs that port from
+ * Claude dynamic workflows readable without threading context explicitly.
+ *
+ * @example
+ * ```ts
+ * import { call, pipeline } from "rig/globals";
+ * import { agent } from "rig";
+ *
+ * const worker = agent({ name: "worker", instructions: "Do work." });
+ * const results = await pipeline(inputs, (item) => call(worker, item));
+ * ```
+ *
+ * @module rig/globals
+ */
+import type {
+ AgentFn,
+ AgentInputValue,
+ InferSchema,
+ PromptBuilder,
+ Schema,
+ Workflow,
+ WorkflowCall,
+ WorkflowCallOptions,
+ WorkflowNestedOptions,
+} from "rig";
+import { currentWorkflow, parallel, pipeline } from "rig";
+
+function requireContext(label: string): WorkflowCall {
+ const ctx = currentWorkflow();
+ if (ctx === undefined) {
+ throw new Error(`${label} requires an active workflow run (call inside runWorkflow or a launcher program).`);
+ }
+ return ctx.call;
+}
+
+function callImpl(
+ worker: AgentFn,
+ input: AgentInputValue,
+ options?: WorkflowCallOptions,
+): Promise